fix: use session origin provider in chat delivery routing

This commit is contained in:
Tak Hoffman
2026-03-26 21:15:35 -05:00
parent 8e4115947b
commit 6e5bc5647a
2 changed files with 51 additions and 2 deletions

View File

@@ -854,6 +854,46 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
);
});
it("chat.send falls back to origin provider metadata for configured main CLI delivery inheritance", async () => {
createTranscriptFixture("openclaw-chat-send-config-main-origin-provider-routes-");
mockState.mainSessionKey = "work";
mockState.finalText = "ok";
mockState.sessionEntry = {
origin: {
provider: "whatsapp",
accountId: "default",
},
lastTo: "whatsapp:+8613800138000",
};
const respond = vi.fn();
const context = createChatContext();
await runNonStreamingChatSend({
context,
respond,
idempotencyKey: "idem-config-main-origin-provider-routes",
client: {
connect: {
client: {
mode: GATEWAY_CLIENT_MODES.CLI,
id: "cli",
},
},
} as unknown,
sessionKey: "agent:main:work",
deliver: true,
expectBroadcast: false,
});
expect(mockState.lastDispatchCtx).toEqual(
expect.objectContaining({
OriginatingChannel: "whatsapp",
OriginatingTo: "whatsapp:+8613800138000",
AccountId: "default",
}),
);
});
it("chat.send keeps configured main delivery inheritance when connect metadata omits client details", async () => {
createTranscriptFixture("openclaw-chat-send-config-main-connect-no-client-");
mockState.mainSessionKey = "work";

View File

@@ -121,6 +121,10 @@ type ChatSendDeliveryEntry = {
accountId?: string;
threadId?: string | number;
};
origin?: {
provider?: string;
accountId?: string;
};
lastChannel?: string;
lastTo?: string;
lastAccountId?: string;
@@ -162,11 +166,16 @@ function resolveChatSendOriginatingRoute(params: {
}
const routeChannelCandidate = normalizeMessageChannel(
params.entry?.deliveryContext?.channel ?? params.entry?.lastChannel,
params.entry?.deliveryContext?.channel ??
params.entry?.lastChannel ??
params.entry?.origin?.provider,
);
const routeToCandidate = params.entry?.deliveryContext?.to ?? params.entry?.lastTo;
const routeAccountIdCandidate =
params.entry?.deliveryContext?.accountId ?? params.entry?.lastAccountId ?? undefined;
params.entry?.deliveryContext?.accountId ??
params.entry?.lastAccountId ??
params.entry?.origin?.accountId ??
undefined;
const routeThreadIdCandidate =
params.entry?.deliveryContext?.threadId ?? params.entry?.lastThreadId;
if (params.sessionKey.length > CHAT_SEND_SESSION_KEY_MAX_LENGTH) {