fix(reply): prefer provider over surface for run channel fallback

This commit is contained in:
liuxiaopai-ai
2026-03-03 00:14:59 +08:00
committed by Peter Steinberger
parent 63734df3b0
commit 740bb77c8c
3 changed files with 36 additions and 1 deletions

View File

@@ -281,6 +281,37 @@ describe("runPreparedReply media-only handling", () => {
expect(call?.followupRun.run.messageProvider).toBe("webchat");
});
it("prefers Provider over Surface when origin channel is missing", async () => {
await runPreparedReply(
baseParams({
ctx: {
Body: "",
RawBody: "",
CommandBody: "",
ThreadHistoryBody: "Earlier message in this thread",
OriginatingChannel: undefined,
OriginatingTo: undefined,
Provider: "feishu",
Surface: "webchat",
ChatType: "group",
},
sessionCtx: {
Body: "",
BodyStripped: "",
ThreadHistoryBody: "Earlier message in this thread",
MediaPath: "/tmp/input.png",
Provider: "webchat",
ChatType: "group",
OriginatingChannel: undefined,
OriginatingTo: undefined,
},
}),
);
const call = vi.mocked(runReplyAgent).mock.calls[0]?.[0];
expect(call?.followupRun.run.messageProvider).toBe("feishu");
});
it("passes suppressTyping through typing mode resolution", async () => {
await runPreparedReply(
baseParams({

View File

@@ -477,7 +477,10 @@ export async function runPreparedReply(
sessionKey,
messageProvider: resolveOriginMessageProvider({
originatingChannel: ctx.OriginatingChannel ?? sessionCtx.OriginatingChannel,
provider: ctx.Surface ?? ctx.Provider ?? sessionCtx.Provider,
// Prefer Provider over Surface for fallback channel identity.
// Surface can carry relayed metadata (for example "webchat") while Provider
// still reflects the active channel that should own tool routing.
provider: ctx.Provider ?? ctx.Surface ?? sessionCtx.Provider,
}),
agentAccountId: sessionCtx.AccountId,
groupId: resolveGroupSessionKey(sessionCtx)?.id ?? undefined,