fix(gateway): mark chat slash commands as text

This commit is contained in:
Vincent Koc
2026-05-06 02:06:40 -07:00
parent e4b629c6d3
commit 7fd7f6f355
2 changed files with 24 additions and 0 deletions

View File

@@ -1173,6 +1173,28 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
);
});
it("chat.send marks user slash commands as text command sources", async () => {
createTranscriptFixture("openclaw-chat-send-text-command-source-");
mockState.finalText = "ok";
const respond = vi.fn();
const context = createChatContext();
await runNonStreamingChatSend({
context,
respond,
idempotencyKey: "idem-text-command-source",
message: "/codex status",
expectBroadcast: false,
});
expect(mockState.lastDispatchCtx).toEqual(
expect.objectContaining({
BodyForCommands: "/codex status",
CommandSource: "text",
}),
);
});
it("chat.send keeps explicit delivery routes for Feishu channel-scoped sessions", async () => {
createTranscriptFixture("openclaw-chat-send-feishu-origin-routing-");
mockState.finalText = "ok";

View File

@@ -2195,6 +2195,7 @@ export const chatHandlers: GatewayRequestHandlers = {
p.thinking && trimmedMessage && !trimmedMessage.startsWith("/"),
);
const commandBody = injectThinking ? `/think ${p.thinking} ${parsedMessage}` : parsedMessage;
const commandSource = trimmedMessage.startsWith("/") ? "text" : undefined;
const messageForAgent = systemProvenanceReceipt
? [systemProvenanceReceipt, parsedMessage].filter(Boolean).join("\n\n")
: parsedMessage;
@@ -2226,6 +2227,7 @@ export const chatHandlers: GatewayRequestHandlers = {
AccountId: accountId,
MessageThreadId: messageThreadId,
ChatType: "direct",
...(commandSource ? { CommandSource: commandSource } : {}),
CommandAuthorized: true,
MessageSid: clientRunId,
SenderId: clientInfo?.id,