Skip to content

Commit 6c80752

Browse files
committed
fix(message): route webchat sends to source sink
1 parent 1aa7caf commit 6c80752

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/agents/tools/message-tool.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,37 @@ describe("message tool secret scoping", () => {
526526
expect(input?.toolContext?.currentChannelProvider).toBe("webchat");
527527
});
528528

529+
it("defaults webchat message tools to the internal source-reply sink", async () => {
530+
mockSendResult();
531+
532+
const input = await executeSend({
533+
action: { message: "hi" },
534+
toolOptions: {
535+
currentChannelProvider: "webchat",
536+
agentSessionKey: "agent:main:webchat:dm:dashboard",
537+
},
538+
});
539+
540+
expect(input?.sourceReplyDeliveryMode).toBe("message_tool_only");
541+
expect(input?.toolContext?.currentChannelProvider).toBe("webchat");
542+
});
543+
544+
it("preserves explicit automatic source delivery for webchat message tools", async () => {
545+
mockSendResult();
546+
547+
const input = await executeSend({
548+
action: { message: "hi" },
549+
toolOptions: {
550+
currentChannelProvider: "webchat",
551+
sourceReplyDeliveryMode: "automatic",
552+
agentSessionKey: "agent:main:webchat:dm:dashboard",
553+
},
554+
});
555+
556+
expect(input?.sourceReplyDeliveryMode).toBe("automatic");
557+
expect(input?.toolContext?.currentChannelProvider).toBe("webchat");
558+
});
559+
529560
it("passes current inbound audio to the outbound runner", async () => {
530561
mockSendResult();
531562

src/agents/tools/message-tool.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ import {
6363
parseThreadSessionSuffix,
6464
} from "../../routing/session-key.js";
6565
import { stripFormattedReasoningMessage } from "../../shared/text/formatted-reasoning-message.js";
66-
import { normalizeMessageChannel } from "../../utils/message-channel.js";
66+
import {
67+
INTERNAL_MESSAGE_CHANNEL,
68+
normalizeMessageChannel,
69+
} from "../../utils/message-channel.js";
6770
import { resolveSessionAgentId } from "../agent-scope.js";
6871
import { listAllChannelSupportedActions, listChannelSupportedActions } from "../channel-tools.js";
6972
import { stripInternalRuntimeContext } from "../internal-runtime-context.js";
@@ -1175,6 +1178,12 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
11751178
const replyToMode = options?.replyToMode ?? (currentThreadTs ? "all" : undefined);
11761179
const agentAccountId =
11771180
resolveAgentAccountId(options?.agentAccountId) ?? effectiveCurrentChannel.accountId;
1181+
const currentChannelIsInternal =
1182+
normalizeMessageChannel(effectiveCurrentChannel.currentChannelProvider) ===
1183+
INTERNAL_MESSAGE_CHANNEL;
1184+
const sourceReplyDeliveryMode =
1185+
options?.sourceReplyDeliveryMode ??
1186+
(currentChannelIsInternal ? "message_tool_only" : undefined);
11781187
const resolvedAgentId =
11791188
options?.agentId ??
11801189
(options?.agentSessionKey
@@ -1209,7 +1218,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
12091218
sessionId: options?.sessionId,
12101219
agentId: resolvedAgentId,
12111220
requireExplicitTarget: options?.requireExplicitTarget,
1212-
sourceReplyDeliveryMode: options?.sourceReplyDeliveryMode,
1221+
sourceReplyDeliveryMode,
12131222
requesterSenderId: options?.requesterSenderId,
12141223
senderIsOwner: options?.senderIsOwner,
12151224
});
@@ -1415,7 +1424,7 @@ export function createMessageTool(options?: MessageToolOptions): AnyAgentTool {
14151424
sessionId: options?.sessionId,
14161425
agentId: resolvedAgentId,
14171426
sandboxRoot: options?.sandboxRoot,
1418-
sourceReplyDeliveryMode: options?.sourceReplyDeliveryMode,
1427+
sourceReplyDeliveryMode,
14191428
inboundEventKind: options?.inboundEventKind,
14201429
inboundAudio: options?.currentInboundAudio,
14211430
abortSignal: signal,

0 commit comments

Comments
 (0)