|
| 1 | +// Integration coverage for targetless WebChat tool sends through the internal |
| 2 | +// source-reply sink and embedded-run payload projection. |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | +import { getReplyPayloadMetadata } from "../../auto-reply/reply-payload.js"; |
| 5 | +import { buildReplyPayloads } from "../../auto-reply/reply/agent-runner-payloads.js"; |
| 6 | +import { buildEmbeddedRunPayloads } from "../embedded-agent-runner/run/payloads.js"; |
| 7 | +import { extractMessagingToolSourceReplyPayload } from "../embedded-agent-subscribe.tools.js"; |
| 8 | +import { createMessageTool } from "./message-tool.js"; |
| 9 | + |
| 10 | +describe("WebChat message tool internal source reply", () => { |
| 11 | + it("projects a real targetless send and preserves the automatic final reply", async () => { |
| 12 | + const tool = createMessageTool({ |
| 13 | + config: {}, |
| 14 | + currentChannelProvider: "webchat", |
| 15 | + sourceReplyDeliveryMode: "automatic", |
| 16 | + agentSessionKey: "agent:main:webchat:dm:dashboard", |
| 17 | + runId: "webchat-run", |
| 18 | + getScopedChannelsCommandSecretTargets: () => ({ targetIds: new Set<string>() }), |
| 19 | + resolveCommandSecretRefsViaGateway: async ({ config }) => ({ |
| 20 | + resolvedConfig: config, |
| 21 | + diagnostics: [], |
| 22 | + targetStatesByPath: {}, |
| 23 | + hadUnresolvedTargets: false, |
| 24 | + }), |
| 25 | + }); |
| 26 | + |
| 27 | + const toolResult = await tool.execute("message-call", { |
| 28 | + action: "send", |
| 29 | + message: "Visible progress from the message tool.", |
| 30 | + }); |
| 31 | + expect(toolResult.details).toMatchObject({ |
| 32 | + channel: "webchat", |
| 33 | + target: "current-run", |
| 34 | + sourceReplyDeliveryMode: "message_tool_only", |
| 35 | + sourceReplySink: "internal-ui", |
| 36 | + sourceReply: { text: "Visible progress from the message tool." }, |
| 37 | + }); |
| 38 | + |
| 39 | + const sourceReply = extractMessagingToolSourceReplyPayload(toolResult); |
| 40 | + expect(sourceReply).toMatchObject({ text: "Visible progress from the message tool." }); |
| 41 | + |
| 42 | + const embeddedPayloads = buildEmbeddedRunPayloads({ |
| 43 | + assistantTexts: ["Visible automatic final reply."], |
| 44 | + toolMetas: [], |
| 45 | + lastAssistant: undefined, |
| 46 | + currentAssistant: undefined, |
| 47 | + sessionKey: "agent:main:webchat:dm:dashboard", |
| 48 | + sourceReplyDeliveryMode: "automatic", |
| 49 | + messagingToolSourceReplyPayloads: sourceReply ? [sourceReply] : [], |
| 50 | + runId: "webchat-run", |
| 51 | + inlineToolResultsAllowed: false, |
| 52 | + verboseLevel: "off", |
| 53 | + reasoningLevel: "off", |
| 54 | + toolResultFormat: "plain", |
| 55 | + }); |
| 56 | + const { replyPayloads: payloads } = await buildReplyPayloads({ |
| 57 | + payloads: embeddedPayloads, |
| 58 | + isHeartbeat: false, |
| 59 | + didLogHeartbeatStrip: false, |
| 60 | + blockStreamingEnabled: false, |
| 61 | + blockReplyPipeline: null, |
| 62 | + replyToMode: "off", |
| 63 | + messagingToolSentTexts: ["Visible progress from the message tool."], |
| 64 | + }); |
| 65 | + |
| 66 | + expect(payloads.map((payload) => payload.text)).toEqual([ |
| 67 | + "Visible progress from the message tool.", |
| 68 | + "Visible automatic final reply.", |
| 69 | + ]); |
| 70 | + expect(getReplyPayloadMetadata(payloads[0] as object)).toMatchObject({ |
| 71 | + deliverDespiteSourceReplySuppression: true, |
| 72 | + sourceReplyTranscriptMirror: { |
| 73 | + sessionKey: "agent:main:webchat:dm:dashboard", |
| 74 | + text: "Visible progress from the message tool.", |
| 75 | + idempotencyKey: "webchat-run:internal-source-reply:0", |
| 76 | + }, |
| 77 | + }); |
| 78 | + expect(getReplyPayloadMetadata(payloads[1] as object)?.sourceReplyTranscriptMirror).toBe( |
| 79 | + undefined, |
| 80 | + ); |
| 81 | + }); |
| 82 | +}); |
0 commit comments