refactor(messages): centralize per-agent prefixes
This commit is contained in:
@@ -3,14 +3,12 @@ import path from "node:path";
|
|||||||
|
|
||||||
import type { ClawdbotConfig } from "../config/config.js";
|
import type { ClawdbotConfig } from "../config/config.js";
|
||||||
import { resolveStateDir } from "../config/paths.js";
|
import { resolveStateDir } from "../config/paths.js";
|
||||||
import {
|
import { DEFAULT_AGENT_ID, normalizeAgentId } from "../routing/session-key.js";
|
||||||
DEFAULT_AGENT_ID,
|
|
||||||
normalizeAgentId,
|
|
||||||
parseAgentSessionKey,
|
|
||||||
} from "../routing/session-key.js";
|
|
||||||
import { resolveUserPath } from "../utils.js";
|
import { resolveUserPath } from "../utils.js";
|
||||||
import { DEFAULT_AGENT_WORKSPACE_DIR } from "./workspace.js";
|
import { DEFAULT_AGENT_WORKSPACE_DIR } from "./workspace.js";
|
||||||
|
|
||||||
|
export { resolveAgentIdFromSessionKey } from "../routing/session-key.js";
|
||||||
|
|
||||||
type AgentEntry = NonNullable<
|
type AgentEntry = NonNullable<
|
||||||
NonNullable<ClawdbotConfig["agents"]>["list"]
|
NonNullable<ClawdbotConfig["agents"]>["list"]
|
||||||
>[number];
|
>[number];
|
||||||
@@ -29,13 +27,6 @@ type ResolvedAgentConfig = {
|
|||||||
|
|
||||||
let defaultAgentWarned = false;
|
let defaultAgentWarned = false;
|
||||||
|
|
||||||
export function resolveAgentIdFromSessionKey(
|
|
||||||
sessionKey?: string | null,
|
|
||||||
): string {
|
|
||||||
const parsed = parseAgentSessionKey(sessionKey);
|
|
||||||
return normalizeAgentId(parsed?.agentId ?? DEFAULT_AGENT_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
function listAgents(cfg: ClawdbotConfig): AgentEntry[] {
|
function listAgents(cfg: ClawdbotConfig): AgentEntry[] {
|
||||||
const list = cfg.agents?.list;
|
const list = cfg.agents?.list;
|
||||||
if (!Array.isArray(list)) return [];
|
if (!Array.isArray(list)) return [];
|
||||||
|
|||||||
@@ -29,6 +29,22 @@ export function resolveIdentityNamePrefix(
|
|||||||
return `[${name}]`;
|
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(
|
export function resolveResponsePrefix(
|
||||||
cfg: ClawdbotConfig,
|
cfg: ClawdbotConfig,
|
||||||
agentId: string,
|
agentId: string,
|
||||||
@@ -37,3 +53,17 @@ export function resolveResponsePrefix(
|
|||||||
if (configured !== undefined) return configured;
|
if (configured !== undefined) return configured;
|
||||||
return resolveIdentityNamePrefix(cfg, agentId);
|
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),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,12 +7,12 @@
|
|||||||
* across multiple providers.
|
* across multiple providers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { resolveAgentIdFromSessionKey } from "../../agents/agent-scope.js";
|
import { resolveEffectiveMessagesConfig } from "../../agents/identity.js";
|
||||||
import { resolveResponsePrefix } from "../../agents/identity.js";
|
|
||||||
import type { ClawdbotConfig } from "../../config/config.js";
|
import type { ClawdbotConfig } from "../../config/config.js";
|
||||||
import { sendMessageDiscord } from "../../discord/send.js";
|
import { sendMessageDiscord } from "../../discord/send.js";
|
||||||
import { sendMessageIMessage } from "../../imessage/send.js";
|
import { sendMessageIMessage } from "../../imessage/send.js";
|
||||||
import { sendMessageMSTeams } from "../../msteams/send.js";
|
import { sendMessageMSTeams } from "../../msteams/send.js";
|
||||||
|
import { resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
|
||||||
import { sendMessageSignal } from "../../signal/send.js";
|
import { sendMessageSignal } from "../../signal/send.js";
|
||||||
import { sendMessageSlack } from "../../slack/send.js";
|
import { sendMessageSlack } from "../../slack/send.js";
|
||||||
import { sendMessageTelegram } from "../../telegram/send.js";
|
import { sendMessageTelegram } from "../../telegram/send.js";
|
||||||
@@ -65,10 +65,10 @@ export async function routeReply(
|
|||||||
|
|
||||||
// Debug: `pnpm test src/auto-reply/reply/route-reply.test.ts`
|
// Debug: `pnpm test src/auto-reply/reply/route-reply.test.ts`
|
||||||
const responsePrefix = params.sessionKey
|
const responsePrefix = params.sessionKey
|
||||||
? resolveResponsePrefix(
|
? resolveEffectiveMessagesConfig(
|
||||||
cfg,
|
cfg,
|
||||||
resolveAgentIdFromSessionKey(params.sessionKey),
|
resolveAgentIdFromSessionKey(params.sessionKey),
|
||||||
)
|
).responsePrefix
|
||||||
: cfg.messages?.responsePrefix;
|
: cfg.messages?.responsePrefix;
|
||||||
const normalized = normalizeReplyPayload(payload, {
|
const normalized = normalizeReplyPayload(payload, {
|
||||||
responsePrefix,
|
responsePrefix,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
DEFAULT_AGENT_ID,
|
DEFAULT_AGENT_ID,
|
||||||
DEFAULT_MAIN_KEY,
|
DEFAULT_MAIN_KEY,
|
||||||
normalizeAgentId,
|
normalizeAgentId,
|
||||||
parseAgentSessionKey,
|
resolveAgentIdFromSessionKey,
|
||||||
} from "../routing/session-key.js";
|
} from "../routing/session-key.js";
|
||||||
import { normalizeE164 } from "../utils.js";
|
import { normalizeE164 } from "../utils.js";
|
||||||
import {
|
import {
|
||||||
@@ -232,12 +232,7 @@ export function resolveMainSessionKey(cfg?: {
|
|||||||
return buildAgentMainSessionKey({ agentId, mainKey });
|
return buildAgentMainSessionKey({ agentId, mainKey });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveAgentIdFromSessionKey(
|
export { resolveAgentIdFromSessionKey };
|
||||||
sessionKey?: string | null,
|
|
||||||
): string {
|
|
||||||
const parsed = parseAgentSessionKey(sessionKey);
|
|
||||||
return normalizeAgentId(parsed?.agentId ?? DEFAULT_AGENT_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveAgentMainSessionKey(params: {
|
export function resolveAgentMainSessionKey(params: {
|
||||||
cfg?: { session?: { mainKey?: string } };
|
cfg?: { session?: { mainKey?: string } };
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { ApplicationCommandOptionType, Routes } from "discord-api-types/v10";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
resolveAckReaction,
|
resolveAckReaction,
|
||||||
resolveResponsePrefix,
|
resolveEffectiveMessagesConfig,
|
||||||
} from "../agents/identity.js";
|
} from "../agents/identity.js";
|
||||||
import { resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
import { resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
||||||
import { hasControlCommand } from "../auto-reply/command-detection.js";
|
import { hasControlCommand } from "../auto-reply/command-detection.js";
|
||||||
@@ -1033,7 +1033,8 @@ export function createDiscordMessageHandler(params: {
|
|||||||
let didSendReply = false;
|
let didSendReply = false;
|
||||||
const { dispatcher, replyOptions, markDispatchIdle } =
|
const { dispatcher, replyOptions, markDispatchIdle } =
|
||||||
createReplyDispatcherWithTyping({
|
createReplyDispatcherWithTyping({
|
||||||
responsePrefix: resolveResponsePrefix(cfg, route.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload) => {
|
deliver: async (payload) => {
|
||||||
await deliverDiscordReply({
|
await deliverDiscordReply({
|
||||||
replies: [payload],
|
replies: [payload],
|
||||||
@@ -1513,7 +1514,8 @@ function createDiscordNativeCommand(params: {
|
|||||||
|
|
||||||
let didReply = false;
|
let didReply = false;
|
||||||
const dispatcher = createReplyDispatcher({
|
const dispatcher = createReplyDispatcher({
|
||||||
responsePrefix: resolveResponsePrefix(cfg, route.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload, _info) => {
|
deliver: async (payload, _info) => {
|
||||||
await deliverDiscordInteractionReply({
|
await deliverDiscordInteractionReply({
|
||||||
interaction,
|
interaction,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { resolveResponsePrefix } from "../agents/identity.js";
|
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
||||||
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
||||||
import { hasControlCommand } from "../auto-reply/command-detection.js";
|
import { hasControlCommand } from "../auto-reply/command-detection.js";
|
||||||
import { formatAgentEnvelope } from "../auto-reply/envelope.js";
|
import { formatAgentEnvelope } from "../auto-reply/envelope.js";
|
||||||
@@ -422,7 +422,8 @@ export async function monitorIMessageProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dispatcher = createReplyDispatcher({
|
const dispatcher = createReplyDispatcher({
|
||||||
responsePrefix: resolveResponsePrefix(cfg, route.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload) => {
|
deliver: async (payload) => {
|
||||||
await deliverReplies({
|
await deliverReplies({
|
||||||
replies: [payload],
|
replies: [payload],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { resolveResponsePrefix } from "../agents/identity.js";
|
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
||||||
import {
|
import {
|
||||||
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
|
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
|
||||||
DEFAULT_HEARTBEAT_EVERY,
|
DEFAULT_HEARTBEAT_EVERY,
|
||||||
@@ -269,7 +269,10 @@ export async function runHeartbeatOnce(opts: {
|
|||||||
const ackMaxChars = resolveHeartbeatAckMaxChars(cfg);
|
const ackMaxChars = resolveHeartbeatAckMaxChars(cfg);
|
||||||
const normalized = normalizeHeartbeatReply(
|
const normalized = normalizeHeartbeatReply(
|
||||||
replyPayload,
|
replyPayload,
|
||||||
resolveResponsePrefix(cfg, resolveAgentIdFromSessionKey(sessionKey)),
|
resolveEffectiveMessagesConfig(
|
||||||
|
cfg,
|
||||||
|
resolveAgentIdFromSessionKey(sessionKey),
|
||||||
|
).responsePrefix,
|
||||||
ackMaxChars,
|
ackMaxChars,
|
||||||
);
|
);
|
||||||
if (normalized.shouldSkip && !normalized.hasMedia) {
|
if (normalized.shouldSkip && !normalized.hasMedia) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { resolveResponsePrefix } from "../agents/identity.js";
|
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
||||||
import { createReplyDispatcherWithTyping } from "../auto-reply/reply/reply-dispatcher.js";
|
import { createReplyDispatcherWithTyping } from "../auto-reply/reply/reply-dispatcher.js";
|
||||||
import type { ClawdbotConfig, MSTeamsReplyStyle } from "../config/types.js";
|
import type { ClawdbotConfig, MSTeamsReplyStyle } from "../config/types.js";
|
||||||
import { danger } from "../globals.js";
|
import { danger } from "../globals.js";
|
||||||
@@ -38,7 +38,8 @@ export function createMSTeamsReplyDispatcher(params: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return createReplyDispatcherWithTyping({
|
return createReplyDispatcherWithTyping({
|
||||||
responsePrefix: resolveResponsePrefix(params.cfg, params.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(params.cfg, params.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload) => {
|
deliver: async (payload) => {
|
||||||
const messages = renderReplyPayloadsToMessages([payload], {
|
const messages = renderReplyPayloadsToMessages([payload], {
|
||||||
textChunkLimit: params.textLimit,
|
textChunkLimit: params.textLimit,
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ export type ParsedAgentSessionKey = {
|
|||||||
rest: string;
|
rest: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function resolveAgentIdFromSessionKey(
|
||||||
|
sessionKey: string | undefined | null,
|
||||||
|
): string {
|
||||||
|
const parsed = parseAgentSessionKey(sessionKey);
|
||||||
|
return normalizeAgentId(parsed?.agentId ?? DEFAULT_AGENT_ID);
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizeAgentId(value: string | undefined | null): string {
|
export function normalizeAgentId(value: string | undefined | null): string {
|
||||||
const trimmed = (value ?? "").trim();
|
const trimmed = (value ?? "").trim();
|
||||||
if (!trimmed) return DEFAULT_AGENT_ID;
|
if (!trimmed) return DEFAULT_AGENT_ID;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { resolveResponsePrefix } from "../agents/identity.js";
|
import { resolveEffectiveMessagesConfig } from "../agents/identity.js";
|
||||||
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
|
||||||
import { formatAgentEnvelope } from "../auto-reply/envelope.js";
|
import { formatAgentEnvelope } from "../auto-reply/envelope.js";
|
||||||
import { dispatchReplyFromConfig } from "../auto-reply/reply/dispatch-from-config.js";
|
import { dispatchReplyFromConfig } from "../auto-reply/reply/dispatch-from-config.js";
|
||||||
@@ -508,7 +508,8 @@ export async function monitorSignalProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dispatcher = createReplyDispatcher({
|
const dispatcher = createReplyDispatcher({
|
||||||
responsePrefix: resolveResponsePrefix(cfg, route.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload) => {
|
deliver: async (payload) => {
|
||||||
await deliverReplies({
|
await deliverReplies({
|
||||||
replies: [payload],
|
replies: [payload],
|
||||||
|
|||||||
@@ -154,6 +154,70 @@ describe("monitorSlackProvider tool results", () => {
|
|||||||
expect(sendMock.mock.calls[1][1]).toBe("PFX final reply");
|
expect(sendMock.mock.calls[1][1]).toBe("PFX final reply");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("derives responsePrefix from routed agent identity when unset", async () => {
|
||||||
|
config = {
|
||||||
|
agents: {
|
||||||
|
list: [
|
||||||
|
{
|
||||||
|
id: "main",
|
||||||
|
default: true,
|
||||||
|
identity: { name: "Mainbot", theme: "space lobster", emoji: "🦞" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "rich",
|
||||||
|
identity: { name: "Richbot", theme: "lion bot", emoji: "🦁" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
bindings: [
|
||||||
|
{
|
||||||
|
agentId: "rich",
|
||||||
|
match: { provider: "slack", peer: { kind: "dm", id: "U1" } },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
messages: {
|
||||||
|
ackReaction: "👀",
|
||||||
|
ackReactionScope: "group-mentions",
|
||||||
|
},
|
||||||
|
slack: { dm: { enabled: true, policy: "open", allowFrom: ["*"] } },
|
||||||
|
};
|
||||||
|
|
||||||
|
replyMock.mockImplementation(async (_ctx, opts) => {
|
||||||
|
await opts?.onToolResult?.({ text: "tool update" });
|
||||||
|
return { text: "final reply" };
|
||||||
|
});
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
const run = monitorSlackProvider({
|
||||||
|
botToken: "bot-token",
|
||||||
|
appToken: "app-token",
|
||||||
|
abortSignal: controller.signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitForEvent("message");
|
||||||
|
const handler = getSlackHandlers()?.get("message");
|
||||||
|
if (!handler) throw new Error("Slack message handler not registered");
|
||||||
|
|
||||||
|
await handler({
|
||||||
|
event: {
|
||||||
|
type: "message",
|
||||||
|
user: "U1",
|
||||||
|
text: "hello",
|
||||||
|
ts: "123",
|
||||||
|
channel: "C1",
|
||||||
|
channel_type: "im",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await flush();
|
||||||
|
controller.abort();
|
||||||
|
await run;
|
||||||
|
|
||||||
|
expect(sendMock).toHaveBeenCalledTimes(2);
|
||||||
|
expect(sendMock.mock.calls[0][1]).toBe("[Richbot] tool update");
|
||||||
|
expect(sendMock.mock.calls[1][1]).toBe("[Richbot] final reply");
|
||||||
|
});
|
||||||
|
|
||||||
it("updates assistant thread status when replies start", async () => {
|
it("updates assistant thread status when replies start", async () => {
|
||||||
replyMock.mockImplementation(async (_ctx, opts) => {
|
replyMock.mockImplementation(async (_ctx, opts) => {
|
||||||
await opts?.onReplyStart?.();
|
await opts?.onReplyStart?.();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
import type { WebClient as SlackWebClient } from "@slack/web-api";
|
import type { WebClient as SlackWebClient } from "@slack/web-api";
|
||||||
import {
|
import {
|
||||||
resolveAckReaction,
|
resolveAckReaction,
|
||||||
resolveResponsePrefix,
|
resolveEffectiveMessagesConfig,
|
||||||
} from "../agents/identity.js";
|
} from "../agents/identity.js";
|
||||||
import {
|
import {
|
||||||
chunkMarkdownText,
|
chunkMarkdownText,
|
||||||
@@ -1119,7 +1119,8 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
|||||||
};
|
};
|
||||||
const { dispatcher, replyOptions, markDispatchIdle } =
|
const { dispatcher, replyOptions, markDispatchIdle } =
|
||||||
createReplyDispatcherWithTyping({
|
createReplyDispatcherWithTyping({
|
||||||
responsePrefix: resolveResponsePrefix(cfg, route.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload) => {
|
deliver: async (payload) => {
|
||||||
await deliverReplies({
|
await deliverReplies({
|
||||||
replies: [payload],
|
replies: [payload],
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Bot, InputFile, webhookCallback } from "grammy";
|
|||||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||||
import {
|
import {
|
||||||
resolveAckReaction,
|
resolveAckReaction,
|
||||||
resolveResponsePrefix,
|
resolveEffectiveMessagesConfig,
|
||||||
} from "../agents/identity.js";
|
} from "../agents/identity.js";
|
||||||
import { EmbeddedBlockChunker } from "../agents/pi-embedded-block-chunker.js";
|
import { EmbeddedBlockChunker } from "../agents/pi-embedded-block-chunker.js";
|
||||||
import {
|
import {
|
||||||
@@ -729,7 +729,8 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
|||||||
|
|
||||||
const { dispatcher, replyOptions, markDispatchIdle } =
|
const { dispatcher, replyOptions, markDispatchIdle } =
|
||||||
createReplyDispatcherWithTyping({
|
createReplyDispatcherWithTyping({
|
||||||
responsePrefix: resolveResponsePrefix(cfg, route.agentId),
|
responsePrefix: resolveEffectiveMessagesConfig(cfg, route.agentId)
|
||||||
|
.responsePrefix,
|
||||||
deliver: async (payload, info) => {
|
deliver: async (payload, info) => {
|
||||||
if (info.kind === "final") {
|
if (info.kind === "final") {
|
||||||
await flushDraft();
|
await flushDraft();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
resolveIdentityNamePrefix,
|
resolveEffectiveMessagesConfig,
|
||||||
resolveResponsePrefix,
|
resolveMessagePrefix,
|
||||||
} from "../agents/identity.js";
|
} from "../agents/identity.js";
|
||||||
import {
|
import {
|
||||||
chunkMarkdownText,
|
chunkMarkdownText,
|
||||||
@@ -1038,13 +1038,9 @@ export async function monitorWebProvider(
|
|||||||
|
|
||||||
const buildLine = (msg: WebInboundMsg, agentId: string) => {
|
const buildLine = (msg: WebInboundMsg, agentId: string) => {
|
||||||
// Build message prefix: explicit config > identity name > default based on allowFrom
|
// Build message prefix: explicit config > identity name > default based on allowFrom
|
||||||
let messagePrefix = cfg.messages?.messagePrefix;
|
const messagePrefix = resolveMessagePrefix(cfg, agentId, {
|
||||||
if (messagePrefix === undefined) {
|
hasAllowFrom: (cfg.whatsapp?.allowFrom?.length ?? 0) > 0,
|
||||||
const hasAllowFrom = (cfg.whatsapp?.allowFrom?.length ?? 0) > 0;
|
});
|
||||||
messagePrefix = hasAllowFrom
|
|
||||||
? ""
|
|
||||||
: (resolveIdentityNamePrefix(cfg, agentId) ?? "[clawdbot]");
|
|
||||||
}
|
|
||||||
const prefixStr = messagePrefix ? `${messagePrefix} ` : "";
|
const prefixStr = messagePrefix ? `${messagePrefix} ` : "";
|
||||||
const senderLabel =
|
const senderLabel =
|
||||||
msg.chatType === "group"
|
msg.chatType === "group"
|
||||||
@@ -1178,7 +1174,10 @@ export async function monitorWebProvider(
|
|||||||
const textLimit = resolveTextChunkLimit(cfg, "whatsapp");
|
const textLimit = resolveTextChunkLimit(cfg, "whatsapp");
|
||||||
let didLogHeartbeatStrip = false;
|
let didLogHeartbeatStrip = false;
|
||||||
let didSendReply = false;
|
let didSendReply = false;
|
||||||
const responsePrefix = resolveResponsePrefix(cfg, route.agentId);
|
const responsePrefix = resolveEffectiveMessagesConfig(
|
||||||
|
cfg,
|
||||||
|
route.agentId,
|
||||||
|
).responsePrefix;
|
||||||
const { dispatcher, replyOptions, markDispatchIdle } =
|
const { dispatcher, replyOptions, markDispatchIdle } =
|
||||||
createReplyDispatcherWithTyping({
|
createReplyDispatcherWithTyping({
|
||||||
responsePrefix,
|
responsePrefix,
|
||||||
|
|||||||
Reference in New Issue
Block a user