refactor(messages): centralize per-agent prefixes

This commit is contained in:
Peter Steinberger
2026-01-09 16:52:25 +01:00
parent 8341b662af
commit 36bdec0f2c
14 changed files with 144 additions and 48 deletions

View File

@@ -29,6 +29,22 @@ export function resolveIdentityNamePrefix(
return `[${name}]`;
}
export function resolveMessagePrefix(
cfg: ClawdbotConfig,
agentId: string,
opts?: { hasAllowFrom?: boolean; fallback?: string },
): string {
const configured = cfg.messages?.messagePrefix;
if (configured !== undefined) return configured;
const hasAllowFrom = opts?.hasAllowFrom === true;
if (hasAllowFrom) return "";
return (
resolveIdentityNamePrefix(cfg, agentId) ?? opts?.fallback ?? "[clawdbot]"
);
}
export function resolveResponsePrefix(
cfg: ClawdbotConfig,
agentId: string,
@@ -37,3 +53,17 @@ export function resolveResponsePrefix(
if (configured !== undefined) return configured;
return resolveIdentityNamePrefix(cfg, agentId);
}
export function resolveEffectiveMessagesConfig(
cfg: ClawdbotConfig,
agentId: string,
opts?: { hasAllowFrom?: boolean; fallbackMessagePrefix?: string },
): { messagePrefix: string; responsePrefix?: string } {
return {
messagePrefix: resolveMessagePrefix(cfg, agentId, {
hasAllowFrom: opts?.hasAllowFrom,
fallback: opts?.fallbackMessagePrefix,
}),
responsePrefix: resolveResponsePrefix(cfg, agentId),
};
}