

























@@ -1411,6 +1411,80 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
14111411accountId: "acct-1",
14121412to: "channel:C123",
14131413threadId: undefined,
1414+sourceReplyDeliveryMode: "message_tool_only",
1415+});
1416+expect(sendMessage).not.toHaveBeenCalled();
1417+});
1418+1419+it("falls back to a forced message-tool handoff when the active requester run cannot accept one", async () => {
1420+const callGateway = createGatewayMock({
1421+result: {
1422+payloads: [],
1423+messagingToolSentTargets: [
1424+{
1425+tool: "message",
1426+provider: "slack",
1427+accountId: "acct-1",
1428+to: "channel:C123",
1429+text: "The track is ready.",
1430+mediaUrls: ["/tmp/generated-night-drive.mp3"],
1431+},
1432+],
1433+},
1434+});
1435+const queueEmbeddedPiMessageWithOutcome = vi.fn((sessionId: string) => ({
1436+queued: false as const,
1437+ sessionId,
1438+reason: "source_reply_delivery_mode_mismatch" as const,
1439+gatewayHealth: "live" as const,
1440+}));
1441+const sendMessage = createSendMessageMock();
1442+const result = await deliverSlackChannelAnnouncement({
1443+ callGateway,
1444+ sendMessage,
1445+sessionId: "requester-session-channel",
1446+isActive: true,
1447+expectsCompletionMessage: true,
1448+directIdempotencyKey: "announce-channel-media-message-tool-active-mismatch",
1449+sourceTool: "music_generate",
1450+ queueEmbeddedPiMessageWithOutcome,
1451+internalEvents: [
1452+{
1453+type: "task_completion",
1454+source: "music_generation",
1455+childSessionKey: "music_generate:task-123",
1456+childSessionId: "task-123",
1457+announceType: "music generation task",
1458+taskLabel: "night-drive synthwave",
1459+status: "ok",
1460+statusLabel: "completed successfully",
1461+result: "Generated 1 track.\nMEDIA:/tmp/generated-night-drive.mp3",
1462+mediaUrls: ["/tmp/generated-night-drive.mp3"],
1463+replyInstruction:
1464+"Tell the user the music is ready. If visible source delivery requires the message tool, send it there with the generated media attached.",
1465+},
1466+],
1467+});
1468+1469+expectRecordFields(result, {
1470+delivered: true,
1471+path: "direct",
1472+});
1473+expect(queueEmbeddedPiMessageWithOutcome).toHaveBeenCalledWith(
1474+"requester-session-channel",
1475+"child done",
1476+expect.objectContaining({
1477+steeringMode: "all",
1478+sourceReplyDeliveryMode: "message_tool_only",
1479+}),
1480+);
1481+expectGatewayAgentParams(callGateway, {
1482+deliver: false,
1483+channel: "slack",
1484+accountId: "acct-1",
1485+to: "channel:C123",
1486+threadId: undefined,
1487+sourceReplyDeliveryMode: "message_tool_only",
14141488});
14151489expect(sendMessage).not.toHaveBeenCalled();
14161490});
@@ -1478,6 +1552,7 @@ describe("deliverSubagentAnnouncement completion delivery", () => {
14781552accountId: "acct-1",
14791553to: origin.to,
14801554threadId: undefined,
1555+sourceReplyDeliveryMode: "message_tool_only",
14811556});
14821557expect(sendMessage).not.toHaveBeenCalled();
14831558},
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。