fix(gateway): preserve agentId through gateway send path

Landed from #23249 by @Sid-Qin.
Includes extra regression tests for agentId precedence + blank fallback.

Co-authored-by: Sid <201593046+Sid-Qin@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-02-25 23:30:40 +00:00
parent 125f4071bc
commit 2011edc9e5
8 changed files with 146 additions and 8 deletions

View File

@@ -194,6 +194,35 @@ describe("gateway url override hardening", () => {
}),
);
});
it("forwards explicit agentId in gateway send params", async () => {
setRegistry(
createTestRegistry([
{
pluginId: "mattermost",
source: "test",
plugin: {
...createMattermostLikePlugin({ onSendText: () => {} }),
outbound: { deliveryMode: "gateway" },
},
},
]),
);
callGatewayMock.mockResolvedValueOnce({ messageId: "m-agent" });
await sendMessage({
cfg: {},
to: "channel:town-square",
content: "hi",
channel: "mattermost",
agentId: "work",
});
const call = callGatewayMock.mock.calls[0]?.[0] as {
params?: Record<string, unknown>;
};
expect(call.params?.agentId).toBe("work");
});
});
const emptyRegistry = createTestRegistry([]);

View File

@@ -251,6 +251,7 @@ export async function sendMessage(params: MessageSendParams): Promise<MessageSen
mediaUrls: mirrorMediaUrls.length ? mirrorMediaUrls : params.mediaUrls,
gifPlayback: params.gifPlayback,
accountId: params.accountId,
agentId: params.agentId,
channel,
sessionKey: params.mirror?.sessionKey,
idempotencyKey: params.idempotencyKey ?? randomIdempotencyKey(),