Skip to content

Commit 0cd5cbd

Browse files
committed
fix(gateway): activate source-reply delivery for direct webchat turns (#96840)
1 parent 9c95abd commit 0cd5cbd

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/gateway/tool-resolution.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ describe("resolveGatewayScopedTools", () => {
4343
expect(result.tools.some((tool) => tool.name === "message")).toBe(false);
4444
});
4545

46+
it("force-allows the message tool for direct webchat turns so targetless send projects to the same chat (#96840)", () => {
47+
const result = resolveGatewayScopedTools({
48+
cfg: { tools: { profile: "minimal" } } as OpenClawConfig,
49+
sessionKey: "agent:main:webchat:forge-main",
50+
messageProvider: "webchat",
51+
inboundEventKind: "user_request",
52+
surface: "loopback",
53+
});
54+
55+
const messageTool = result.tools.find((tool) => tool.name === "message");
56+
expect(messageTool?.description).toContain(
57+
"visible replies to the current source conversation",
58+
);
59+
});
60+
4661
it("force-allows the message tool for routed webchat room-event turns", () => {
4762
const result = resolveGatewayScopedTools({
4863
cfg: { tools: { profile: "minimal" } } as OpenClawConfig,

src/gateway/tool-resolution.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,18 @@ export function resolveGatewayScopedTools(params: {
8181
const providerProfilePolicy = resolveToolProfilePolicy(providerProfile);
8282
const gatewayRequestedTools = params.gatewayRequestedTools ?? [];
8383
const messageProvider = params.messageProvider?.trim().toLowerCase();
84+
// Activate source-reply delivery for:
85+
// - non-webchat room-event turns (existing), or
86+
// - direct WebChat turns (`message(action="send")` without a target should
87+
// project into the same chat rather than fail). WebChat room-event turns
88+
// keep automatic delivery because the WebChat harness already projects
89+
// those — see the "keeps webchat room-event turns on automatic source
90+
// delivery" regression test.
91+
const isWebchatSession = messageProvider === "webchat";
92+
const isRoomEvent = params.inboundEventKind === "room_event";
8493
const sourceReplyDeliveryMode: SourceReplyDeliveryMode | undefined =
8594
params.sourceReplyDeliveryMode ??
86-
(params.inboundEventKind === "room_event" && messageProvider !== "webchat"
95+
((isRoomEvent && !isWebchatSession) || (isWebchatSession && !isRoomEvent)
8796
? "message_tool_only"
8897
: undefined);
8998
const runtimeAlsoAllow = sourceReplyDeliveryMode === "message_tool_only" ? ["message"] : [];

0 commit comments

Comments
 (0)