|
1 | 1 | import type { AssistantMessage } from "@earendil-works/pi-ai"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import { getReplyPayloadMetadata } from "../../../auto-reply/reply-payload.js"; |
| 4 | +import type { InteractiveReply, MessagePresentation } from "../../../interactive/payload.js"; |
4 | 5 | import { |
5 | 6 | buildPayloads, |
6 | 7 | expectSinglePayloadText, |
@@ -172,6 +173,64 @@ describe("buildEmbeddedRunPayloads tool-error warnings", () => { |
172 | 173 | }); |
173 | 174 | }); |
174 | 175 |
|
| 176 | + it("preserves rich-only internal message-tool source replies", () => { |
| 177 | + const presentation = { |
| 178 | + blocks: [ |
| 179 | + { |
| 180 | + type: "buttons", |
| 181 | + buttons: [{ label: "Approve", value: "approve" }], |
| 182 | + }, |
| 183 | + ], |
| 184 | + } satisfies MessagePresentation; |
| 185 | + const interactive = { |
| 186 | + blocks: [ |
| 187 | + { |
| 188 | + type: "buttons", |
| 189 | + buttons: [{ label: "Open", value: "open" }], |
| 190 | + }, |
| 191 | + ], |
| 192 | + } satisfies InteractiveReply; |
| 193 | + |
| 194 | + const payloads = buildPayloads({ |
| 195 | + assistantTexts: ["ordinary final should stay private"], |
| 196 | + didSendViaMessagingTool: true, |
| 197 | + messagingToolSourceReplyPayloads: [ |
| 198 | + { |
| 199 | + presentation, |
| 200 | + }, |
| 201 | + { |
| 202 | + interactive, |
| 203 | + }, |
| 204 | + ], |
| 205 | + sourceReplyDeliveryMode: "message_tool_only", |
| 206 | + sessionKey: "agent:main", |
| 207 | + agentId: "main", |
| 208 | + runId: "run-1", |
| 209 | + }); |
| 210 | + |
| 211 | + expect(payloads).toHaveLength(2); |
| 212 | + expect(payloads[0]).toMatchObject({ presentation }); |
| 213 | + expect(payloads[0]?.text).toBeUndefined(); |
| 214 | + expect(payloads[1]).toMatchObject({ interactive }); |
| 215 | + expect(payloads[1]?.text).toBeUndefined(); |
| 216 | + expect(getReplyPayloadMetadata(payloads[0] as object)).toMatchObject({ |
| 217 | + deliverDespiteSourceReplySuppression: true, |
| 218 | + sourceReplyTranscriptMirror: { |
| 219 | + sessionKey: "agent:main", |
| 220 | + agentId: "main", |
| 221 | + idempotencyKey: "run-1:internal-source-reply:0", |
| 222 | + }, |
| 223 | + }); |
| 224 | + expect(getReplyPayloadMetadata(payloads[1] as object)).toMatchObject({ |
| 225 | + deliverDespiteSourceReplySuppression: true, |
| 226 | + sourceReplyTranscriptMirror: { |
| 227 | + sessionKey: "agent:main", |
| 228 | + agentId: "main", |
| 229 | + idempotencyKey: "run-1:internal-source-reply:1", |
| 230 | + }, |
| 231 | + }); |
| 232 | + }); |
| 233 | + |
175 | 234 | it("ignores accumulated internal/status text after the final answer", () => { |
176 | 235 | const payloads = buildPayloads({ |
177 | 236 | assistantTexts: [ |
|
0 commit comments