Skip to content

Commit b9b6ca4

Browse files
authored
fix(discord): upload-file with a base64 buffer fails without pointing at send (#123748)
* fix(discord): reject upload-file buffer attachments with send guidance The flat message tool schema advertises buffer for every action, so callers reasonably infer upload-file + buffer is valid on Discord. The Discord handler only reads filePath/path/media for upload-file and failed with an error that never mentioned the supported path. Scope the buffer schema description to action="send" and make Discord upload-file reject a buffer-only call with guidance to use send instead of duplicating the send buffer pipeline under a second action. * review: keep the shared buffer description channel-neutral iMessage's upload-file deliberately consumes a buffer, so scoping the shared schema text to send would teach models away from a supported path. Keep the guidance owner-local: Discord's rejection carries it.
1 parent 2107d1e commit b9b6ca4

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎extensions/discord/src/actions/handle-action.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,25 @@ describe("handleDiscordMessageAction", () => {
607607
expect(handleDiscordActionMock).not.toHaveBeenCalled();
608608
});
609609

610+
it("rejects upload-file with a buffer and points at send", async () => {
611+
await expect(
612+
handleDiscordMessageAction({
613+
action: "upload-file",
614+
params: {
615+
to: "channel:123",
616+
filename: "report.pdf",
617+
contentType: "application/pdf",
618+
buffer: Buffer.from("report").toString("base64"),
619+
},
620+
cfg: discordConfig(),
621+
}),
622+
).rejects.toThrow(
623+
'Use action: "send" for base64 buffer attachments; upload-file requires filePath, path, or media.',
624+
);
625+
626+
expect(handleDiscordActionMock).not.toHaveBeenCalled();
627+
});
628+
610629
it("maps thread-reply filePath to Discord threadReply with media read context", async () => {
611630
const mediaReadFile = vi.fn(async () => Buffer.from("report"));
612631
const cfg = discordConfig({ threads: true });

‎extensions/discord/src/actions/handle-action.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ export async function handleDiscordMessageAction(
275275
readStringParam(params, "path", { trim: false }) ??
276276
readStringParam(params, "media", { trim: false });
277277
if (!mediaUrl) {
278+
// Buffer attachments are send-only; upload-file covers existing file/media sources.
279+
if (readStringParam(params, "buffer", { trim: false })) {
280+
throw new Error(
281+
'Use action: "send" for base64 buffer attachments; upload-file requires filePath, path, or media.',
282+
);
283+
}
278284
throw new Error("upload-file requires filePath, path, or media.");
279285
}
280286
const content =

0 commit comments

Comments
 (0)