Compare commits

...

1 Commits

Author SHA1 Message Date
Peter Steinberger
872e822410 Avoid media completion double posts 2026-05-02 04:39:41 +01:00
2 changed files with 64 additions and 4 deletions

View File

@@ -829,6 +829,45 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
);
});
it("does not fallback when announce-agent delivered media through the message tool", async () => {
const callGateway = createGatewayMock({
result: {
payloads: [],
didSendViaMessagingTool: true,
messagingToolSentMediaUrls: ["/tmp/generated-night-drive.mp3"],
},
});
const sendMessage = createSendMessageMock();
const result = await deliverDiscordDirectMessageCompletion({
callGateway,
sendMessage,
internalEvents: [
{
type: "task_completion",
source: "music_generation",
childSessionKey: "music_generate:task-123",
childSessionId: "task-123",
announceType: "music generation task",
taskLabel: "night-drive synthwave",
status: "ok",
statusLabel: "completed successfully",
result: "Generated 1 track.\nMEDIA:/tmp/generated-night-drive.mp3",
mediaUrls: ["/tmp/generated-night-drive.mp3"],
replyInstruction: "Deliver the generated music through the message tool.",
},
],
});
expect(result).toEqual(
expect.objectContaining({
delivered: true,
path: "direct",
}),
);
expect(callGateway).toHaveBeenCalled();
expect(sendMessage).not.toHaveBeenCalled();
});
it("uses a direct channel fallback when announce-agent returns no visible output", async () => {
const callGateway = createGatewayMock({
result: {

View File

@@ -558,10 +558,31 @@ function hasVisibleGatewayAgentPayload(response: unknown): boolean {
response && typeof response === "object" && "result" in response
? (response as { result?: unknown }).result
: undefined;
const payloads =
result && typeof result === "object" && "payloads" in result
? (result as { payloads?: unknown }).payloads
: undefined;
if (!result || typeof result !== "object") {
return false;
}
const resultRecord = result as {
didSendViaMessagingTool?: unknown;
messagingToolSentTexts?: unknown;
messagingToolSentMediaUrls?: unknown;
payloads?: unknown;
};
if (resultRecord.didSendViaMessagingTool === true) {
return true;
}
if (
Array.isArray(resultRecord.messagingToolSentTexts) &&
resultRecord.messagingToolSentTexts.some((item) => typeof item === "string" && item.trim())
) {
return true;
}
if (
Array.isArray(resultRecord.messagingToolSentMediaUrls) &&
resultRecord.messagingToolSentMediaUrls.some((item) => typeof item === "string" && item.trim())
) {
return true;
}
const payloads = "payloads" in resultRecord ? resultRecord.payloads : undefined;
if (!Array.isArray(payloads)) {
return false;
}