@arbidocs/sdk 0.4.167 → 0.4.169

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,816 @@
1
+ 'use strict';
2
+
3
+ // src/testing/sse-frames.ts
4
+ function frame(event, data) {
5
+ return `event: ${event}
6
+ data: ${JSON.stringify(data)}
7
+
8
+ `;
9
+ }
10
+ var isoAt = (at) => at ?? (/* @__PURE__ */ new Date()).toISOString();
11
+ var epochAt = (at) => Math.floor(Date.parse(isoAt(at)) / 1e3);
12
+ function toolItem(id, name, arbi = {}) {
13
+ return {
14
+ type: "function_call",
15
+ id,
16
+ call_id: id,
17
+ name,
18
+ arguments: "{}",
19
+ status: "completed",
20
+ arbi: { detail: [{ tool: name }], ...arbi }
21
+ };
22
+ }
23
+ function reasoningItem(id, arbi = {}, summary) {
24
+ return {
25
+ type: "reasoning",
26
+ id,
27
+ status: "completed",
28
+ summary: summary ? [{ type: "output_text", text: summary, annotations: [] }] : [],
29
+ arbi
30
+ };
31
+ }
32
+ function answerItem(id, text, arbi = {}) {
33
+ return {
34
+ type: "message",
35
+ id,
36
+ status: "completed",
37
+ role: "assistant",
38
+ content: [{ type: "output_text", text, annotations: [] }],
39
+ arbi: { label: "Answered", step: "answering", ...arbi }
40
+ };
41
+ }
42
+ function narrationItem(id, text) {
43
+ return {
44
+ type: "message",
45
+ id,
46
+ status: "completed",
47
+ role: "assistant",
48
+ content: [{ type: "output_text", text, annotations: [] }],
49
+ arbi: { label: "Narration" }
50
+ };
51
+ }
52
+ function userMessage(opts) {
53
+ return {
54
+ type: "user_message",
55
+ role: "user",
56
+ content: opts.content,
57
+ shared: false,
58
+ tokens: 0,
59
+ status: opts.status ?? "completed",
60
+ external_id: opts.externalId ?? "msg-e2e-user",
61
+ created_at: isoAt(opts.at),
62
+ created_by_ext_id: opts.createdBy ?? "usr-e2e",
63
+ conversation_ext_id: opts.conversationId,
64
+ ...opts.parentMessageId !== void 0 ? { parent_message_ext_id: opts.parentMessageId } : {}
65
+ };
66
+ }
67
+ function userMessageFrame(opts) {
68
+ return frame("arbi.user_message", userMessage(opts));
69
+ }
70
+ function messageQueuedFrame(opts) {
71
+ return frame("arbi.message_queued", {
72
+ type: "arbi.message_queued",
73
+ response_id: opts.responseId,
74
+ input: opts.input,
75
+ queue_action: "created",
76
+ previous_response_id: opts.previousResponseId ?? null,
77
+ user_message_id: opts.user.externalId ?? "msg-e2e-user",
78
+ user_message: userMessage({ ...opts.user, status: opts.user.status ?? "queued" })
79
+ });
80
+ }
81
+ function responseCreatedFrame(id, t, at) {
82
+ return frame("response.created", {
83
+ type: "response.created",
84
+ sequence_number: 1,
85
+ ...t != null ? { t } : {},
86
+ response: {
87
+ id,
88
+ object: "response",
89
+ status: "in_progress",
90
+ created_at: epochAt(at),
91
+ model: "e2e-mock",
92
+ output: []
93
+ }
94
+ });
95
+ }
96
+ function textDeltaFrame(itemId, delta) {
97
+ return frame("response.output_text.delta", {
98
+ type: "response.output_text.delta",
99
+ item_id: itemId,
100
+ output_index: 0,
101
+ content_index: 0,
102
+ delta
103
+ });
104
+ }
105
+ function itemDoneFrame(item, opts = {}) {
106
+ return frame("response.output_item.done", {
107
+ type: "response.output_item.done",
108
+ sequence_number: (opts.index ?? 0) + 2,
109
+ output_index: opts.index ?? 0,
110
+ item,
111
+ ...opts.t != null ? { t: opts.t } : {}
112
+ });
113
+ }
114
+ function completedFrame(opts) {
115
+ return frame("response.completed", {
116
+ type: "response.completed",
117
+ sequence_number: 99,
118
+ ...opts.t != null ? { t: opts.t } : {},
119
+ ...opts.context ? { context: opts.context } : {},
120
+ response: {
121
+ id: opts.assistantId,
122
+ object: "response",
123
+ status: "completed",
124
+ created_at: epochAt(opts.at),
125
+ model: "e2e-mock",
126
+ output: [],
127
+ usage: { input_tokens: 0, output_tokens: 0, total_tokens: 0 },
128
+ metadata: {
129
+ type: "message_metadata",
130
+ external_id: opts.assistantId,
131
+ role: "assistant",
132
+ content: opts.content,
133
+ conversation_ext_id: opts.conversationId,
134
+ created_at: isoAt(opts.at),
135
+ created_by_ext_id: "usr-e2e",
136
+ shared: false,
137
+ tokens: 0,
138
+ status: opts.status ?? "completed",
139
+ ...opts.tools ? { tools: opts.tools } : {},
140
+ ...opts.suggestedQuery ? { suggested_query: opts.suggestedQuery } : {}
141
+ }
142
+ }
143
+ });
144
+ }
145
+ function failedFrame(message) {
146
+ return frame("response.failed", {
147
+ type: "response.failed",
148
+ sequence_number: 99,
149
+ response: { id: "failed", object: "response", status: "failed", error: { message } }
150
+ });
151
+ }
152
+ function arbiErrorFrame(opts) {
153
+ return frame("arbi.error", {
154
+ type: "arbi.error",
155
+ code: opts.code,
156
+ message: opts.message,
157
+ ...opts.spend != null ? { spend: opts.spend } : {},
158
+ ...opts.budget != null ? { budget: opts.budget } : {},
159
+ ...opts.projectExtId ? { project_ext_id: opts.projectExtId } : {}
160
+ });
161
+ }
162
+ function artifactFrame(event) {
163
+ return frame("arbi.artifact", { type: "arbi.artifact", ...event });
164
+ }
165
+ function mailDraftFrame(event) {
166
+ return frame("arbi.mail_draft", { type: "arbi.mail_draft", ...event });
167
+ }
168
+ function deferredInterjectionFrame(message) {
169
+ return frame("arbi.deferred_interjection", { type: "arbi.deferred_interjection", message });
170
+ }
171
+ function agentControlStateFrame(state) {
172
+ return frame("arbi.agent_control_state", { type: "arbi.agent_control_state", state });
173
+ }
174
+ function probeAnswerFrame(event) {
175
+ return frame("arbi.probe_answer", { type: "arbi.probe_answer", ...event });
176
+ }
177
+ function userInputRequestFrame(event) {
178
+ return frame("arbi.user_input_request", { type: "arbi.user_input_request", ...event });
179
+ }
180
+ function agentStream({
181
+ assistantId,
182
+ items,
183
+ conversationId = "cnv-e2e",
184
+ userContent,
185
+ userMessageId = "msg-e2e-user",
186
+ answer = "",
187
+ step = 1
188
+ }) {
189
+ let body = "";
190
+ if (userContent) {
191
+ body += userMessageFrame({ content: userContent, conversationId, externalId: userMessageId });
192
+ }
193
+ body += responseCreatedFrame(assistantId);
194
+ items.forEach((item, i) => {
195
+ body += itemDoneFrame(item, { index: i, t: Number(((i + 1) * step).toFixed(2)) });
196
+ });
197
+ body += completedFrame({
198
+ assistantId,
199
+ conversationId,
200
+ content: answer,
201
+ t: Number(((items.length + 2) * step).toFixed(2))
202
+ });
203
+ return body;
204
+ }
205
+
206
+ // src/testing/sse-fake.ts
207
+ var QUERY_PATH = /\/v1\/assistant\/query$/;
208
+ var ATTACH_PATH = /\/v1\/assistant\/run\/[^/]+\/stream$/;
209
+ function abortError() {
210
+ const error = new Error("The operation was aborted.");
211
+ error.name = "AbortError";
212
+ return error;
213
+ }
214
+ function json(reply) {
215
+ return new Response(reply.body === void 0 ? null : JSON.stringify(reply.body), {
216
+ status: reply.status,
217
+ headers: { "content-type": "application/json" }
218
+ });
219
+ }
220
+ function parseBody(body) {
221
+ if (body === "" || body === void 0) return null;
222
+ if (typeof body !== "string") return body;
223
+ try {
224
+ return JSON.parse(body);
225
+ } catch {
226
+ return body;
227
+ }
228
+ }
229
+ function createSseFake() {
230
+ const requests = [];
231
+ const streams = [];
232
+ const queryReplies = [];
233
+ let attachStreams = 0;
234
+ let fallback = () => ({ status: 200, body: {} });
235
+ const encoder = new TextEncoder();
236
+ const openStream = (request, signal) => {
237
+ let controller;
238
+ let ended = false;
239
+ const end = (fn) => {
240
+ if (ended) return;
241
+ ended = true;
242
+ try {
243
+ fn();
244
+ } catch {
245
+ }
246
+ };
247
+ const body = new ReadableStream({
248
+ start(c) {
249
+ controller = c;
250
+ },
251
+ cancel() {
252
+ ended = true;
253
+ }
254
+ });
255
+ const stream = {
256
+ request,
257
+ push: (...frames) => {
258
+ if (ended) throw new Error(`stream for ${request.path} has ended`);
259
+ for (const f of frames) controller.enqueue(encoder.encode(f));
260
+ },
261
+ close: () => end(() => controller.close()),
262
+ drop: (error = new TypeError("network error")) => end(() => controller.error(error)),
263
+ get ended() {
264
+ return ended;
265
+ }
266
+ };
267
+ signal?.addEventListener("abort", () => end(() => controller.error(abortError())));
268
+ streams.push(stream);
269
+ return new Response(body, {
270
+ status: 200,
271
+ headers: { "content-type": "text/event-stream; charset=utf-8" }
272
+ });
273
+ };
274
+ const fakeFetch = async (input, init) => {
275
+ const request = typeof input === "object" && "url" in input ? input : null;
276
+ const url = request ? request.url : String(input);
277
+ const method = (init?.method ?? request?.method ?? "GET").toUpperCase();
278
+ const signal = init?.signal ?? request?.signal;
279
+ const rawBody = init?.body ?? (request && method !== "GET" ? await request.clone().text() : null);
280
+ const parsed = new URL(url, "http://localhost");
281
+ const recorded = {
282
+ method,
283
+ path: parsed.pathname + parsed.search,
284
+ body: parseBody(rawBody)
285
+ };
286
+ requests.push(recorded);
287
+ if (signal?.aborted) throw abortError();
288
+ if (method === "POST" && QUERY_PATH.test(parsed.pathname)) {
289
+ const reply = queryReplies.shift();
290
+ return reply ? json(reply) : openStream(recorded, signal);
291
+ }
292
+ if (method === "GET" && ATTACH_PATH.test(parsed.pathname)) {
293
+ if (attachStreams === 0) return json({ status: 404, body: { detail: "not active" } });
294
+ attachStreams -= 1;
295
+ return openStream(recorded, signal);
296
+ }
297
+ return json(fallback(recorded));
298
+ };
299
+ return {
300
+ fetch: fakeFetch,
301
+ requests,
302
+ streams,
303
+ current: () => [...streams].reverse().find((s) => !s.ended),
304
+ replyNextQuery: (reply) => {
305
+ queryReplies.push(reply);
306
+ },
307
+ streamNextAttach: () => {
308
+ attachStreams += 1;
309
+ },
310
+ setFallback: (handler) => {
311
+ fallback = handler;
312
+ }
313
+ };
314
+ }
315
+
316
+ // src/testing/chat-scenarios.ts
317
+ var AT = "2026-01-01T00:00:00.000Z";
318
+ var SEED_CONVERSATION = "cnv-seeded";
319
+ var seededThread = {
320
+ conversationId: SEED_CONVERSATION,
321
+ history: [
322
+ { id: "msg-u0", role: "user", content: "Earlier question", parent: null },
323
+ { id: "msg-a0", role: "assistant", content: "Earlier answer", parent: "msg-u0" }
324
+ ]
325
+ };
326
+ var user = (content, externalId, parent = "msg-a0") => userMessageFrame({
327
+ content,
328
+ conversationId: SEED_CONVERSATION,
329
+ externalId,
330
+ parentMessageId: parent,
331
+ at: AT
332
+ });
333
+ var created = (assistantId, t) => responseCreatedFrame(assistantId, t, AT);
334
+ var done = (assistantId, content, extra = {}) => completedFrame({ assistantId, conversationId: SEED_CONVERSATION, content, at: AT, ...extra });
335
+ var CONTEXT = {
336
+ context_window: 2e5,
337
+ budget: 18e4,
338
+ system: 2e3,
339
+ history: 300,
340
+ compaction: 0,
341
+ retrieval: 1200,
342
+ query: 40,
343
+ output: 500,
344
+ total_input: 3540,
345
+ truncated: false,
346
+ reasoning: 0,
347
+ total_output: 500
348
+ };
349
+ var CHAT_SCENARIOS = [
350
+ {
351
+ name: "plain-answer",
352
+ description: 'A new chat with a document and a fact: the first turn moves "new" to the server id and the answer streams, then resolves with its context and a suggested follow-up.',
353
+ context: { documents: ["doc-1"], facts: ["fact-1"] },
354
+ steps: [
355
+ { send: "What does the contract say about termination?" },
356
+ {
357
+ push: [
358
+ userMessageFrame({
359
+ content: "What does the contract say about termination?",
360
+ conversationId: "cnv-new-1",
361
+ externalId: "msg-u1",
362
+ parentMessageId: null,
363
+ at: AT
364
+ }),
365
+ created("msg-a1", 0.2),
366
+ textDeltaFrame("it-answer", "Either party may ")
367
+ ]
368
+ },
369
+ { snapshot: "streaming" },
370
+ {
371
+ push: [
372
+ textDeltaFrame("it-answer", "terminate on 30 days notice."),
373
+ itemDoneFrame(answerItem("it-answer", "Either party may terminate on 30 days notice."), {
374
+ t: 1.4
375
+ }),
376
+ completedFrame({
377
+ assistantId: "msg-a1",
378
+ conversationId: "cnv-new-1",
379
+ content: "Either party may terminate on 30 days notice.",
380
+ suggestedQuery: "What notice period applies?",
381
+ context: CONTEXT,
382
+ t: 1.6,
383
+ at: AT
384
+ })
385
+ ]
386
+ },
387
+ { close: true }
388
+ ]
389
+ },
390
+ {
391
+ name: "agent-steps",
392
+ description: "A follow-up in an existing thread that works through tools: steps fold into the trace, narration leaves the body, and the answer resolves after the narration dwell.",
393
+ seed: seededThread,
394
+ steps: [
395
+ { send: "Find the liability cap" },
396
+ {
397
+ push: [
398
+ user("Find the liability cap", "msg-u1"),
399
+ created("msg-a1", 0.1),
400
+ itemDoneFrame(reasoningItem("rs-1", { step: "goal", label: "Thinking\u2026" }, "Find it"), {
401
+ index: 0,
402
+ t: 0.5
403
+ }),
404
+ textDeltaFrame("it-n1", "Let me search the documents."),
405
+ itemDoneFrame(toolItem("fc-2", "search_inside_documents", { label: "Searching" }), {
406
+ index: 1,
407
+ t: 1.5
408
+ }),
409
+ textDeltaFrame("it-n2", "Now reading the clause. "),
410
+ itemDoneFrame(narrationItem("it-n2", "Now reading the clause. "), { index: 2, t: 2 }),
411
+ itemDoneFrame(toolItem("fc-3", "get_document_passages", { label: "Reading" }), {
412
+ index: 3,
413
+ t: 2.5
414
+ }),
415
+ textDeltaFrame("it-answer", "The cap is \xA31m."),
416
+ itemDoneFrame(answerItem("it-answer", "The cap is \xA31m."), { index: 4, t: 3 })
417
+ ]
418
+ },
419
+ { snapshot: "before-completed" },
420
+ { push: [done("msg-a1", "The cap is \xA31m.", { t: 3.2 })] },
421
+ { close: true },
422
+ { wait: 5e3 }
423
+ ]
424
+ },
425
+ {
426
+ name: "subagents",
427
+ description: "A run_skill sub-agent whose relayed child steps nest under the parent step.",
428
+ seed: seededThread,
429
+ steps: [
430
+ { send: "Run the research-helper skill" },
431
+ {
432
+ push: [
433
+ user("Run the research-helper skill", "msg-u1"),
434
+ created("msg-a1"),
435
+ itemDoneFrame(
436
+ toolItem("fc-1", "run_skill", {
437
+ label: "Skill",
438
+ focus: "Invoking the research-helper skill",
439
+ detail: [{ tool: "run_skill", summary: "research-helper" }]
440
+ }),
441
+ { index: 0, t: 1 }
442
+ ),
443
+ itemDoneFrame(
444
+ toolItem("fc-2", "search_inside_documents", {
445
+ label: "Searching documents",
446
+ parent_id: "fc-1"
447
+ }),
448
+ { index: 1, t: 2 }
449
+ ),
450
+ itemDoneFrame(
451
+ toolItem("fc-3", "goal_progress", { label: "Goal check", parent_id: "fc-1" }),
452
+ { index: 2, t: 3 }
453
+ ),
454
+ textDeltaFrame("msg-4", "The skill found the clauses."),
455
+ itemDoneFrame(answerItem("msg-4", "The skill found the clauses."), { index: 3, t: 4 }),
456
+ done("msg-a1", "The skill found the clauses.", { t: 4.2 })
457
+ ]
458
+ },
459
+ { close: true }
460
+ ]
461
+ },
462
+ {
463
+ name: "interjection",
464
+ description: "A message sent while the agent works is queued, steered into the running turn at the next tool boundary, and settled by the interjection step.",
465
+ seed: seededThread,
466
+ steps: [
467
+ { send: "Research the company financials" },
468
+ {
469
+ push: [
470
+ user("Research the company financials", "msg-u1"),
471
+ created("msg-a1"),
472
+ itemDoneFrame(toolItem("fc-1", "web_search", { label: "Searching the web" }), {
473
+ index: 0,
474
+ t: 1
475
+ })
476
+ ]
477
+ },
478
+ { send: "Focus on 2026" },
479
+ { snapshot: "queued" },
480
+ {
481
+ stream: 1,
482
+ push: [
483
+ messageQueuedFrame({
484
+ responseId: "resp-steer",
485
+ input: "Focus on 2026",
486
+ previousResponseId: "msg-a1",
487
+ user: {
488
+ content: "Focus on 2026",
489
+ conversationId: SEED_CONVERSATION,
490
+ externalId: "msg-u2",
491
+ parentMessageId: "msg-a1",
492
+ at: AT
493
+ }
494
+ })
495
+ ]
496
+ },
497
+ { close: true, stream: 1 },
498
+ { snapshot: "acknowledged" },
499
+ {
500
+ stream: 0,
501
+ push: [
502
+ itemDoneFrame(
503
+ reasoningItem("rs-2", { step: "interjection", label: "Your message" }, "Focus on 2026"),
504
+ { index: 1, t: 2 }
505
+ ),
506
+ textDeltaFrame("msg-3", "Focusing on 2026."),
507
+ itemDoneFrame(answerItem("msg-3", "Focusing on 2026."), { index: 2, t: 3 }),
508
+ done("msg-a1", "Focusing on 2026.", { t: 3.1 })
509
+ ]
510
+ },
511
+ { close: true, stream: 0 },
512
+ { wait: 1e3 }
513
+ ]
514
+ },
515
+ {
516
+ name: "queued-followup",
517
+ description: "A follow-up the server queues behind the running turn: shown in the agent bar, moved to the next turn when it starts, and answered in its own turn.",
518
+ seed: seededThread,
519
+ steps: [
520
+ { send: "Summarise the report" },
521
+ {
522
+ push: [
523
+ user("Summarise the report", "msg-u1"),
524
+ created("msg-a1"),
525
+ textDeltaFrame("msg-x", "The report covers")
526
+ ]
527
+ },
528
+ { send: "Then list the risks" },
529
+ {
530
+ stream: 1,
531
+ push: [
532
+ messageQueuedFrame({
533
+ responseId: "resp-queued",
534
+ input: "Then list the risks",
535
+ previousResponseId: "msg-a1",
536
+ user: {
537
+ content: "Then list the risks",
538
+ conversationId: SEED_CONVERSATION,
539
+ externalId: "msg-u2",
540
+ parentMessageId: "msg-a1",
541
+ at: AT
542
+ }
543
+ })
544
+ ]
545
+ },
546
+ { snapshot: "queued" },
547
+ {
548
+ stream: 0,
549
+ push: [
550
+ textDeltaFrame("msg-x", " three areas."),
551
+ itemDoneFrame(answerItem("msg-x", "The report covers three areas."), { t: 2 }),
552
+ done("msg-a1", "The report covers three areas.", { t: 2.1 })
553
+ ]
554
+ },
555
+ { close: true, stream: 0 },
556
+ {
557
+ stream: 1,
558
+ push: [user("Then list the risks", "msg-u2", "msg-a1"), created("msg-a2")]
559
+ },
560
+ { snapshot: "second-turn" },
561
+ { wait: 1e3 },
562
+ {
563
+ stream: 1,
564
+ push: [
565
+ textDeltaFrame("msg-y", "Risks: delay and cost."),
566
+ itemDoneFrame(answerItem("msg-y", "Risks: delay and cost."), { t: 1 }),
567
+ done("msg-a2", "Risks: delay and cost.", { t: 1.1 })
568
+ ]
569
+ },
570
+ { close: true, stream: 1 }
571
+ ]
572
+ },
573
+ {
574
+ name: "deferred-interjection",
575
+ description: "Steering that reached the agent after it committed to its answer is resubmitted as a new turn once the turn completes.",
576
+ seed: seededThread,
577
+ steps: [
578
+ { send: "Draft the summary" },
579
+ {
580
+ push: [
581
+ user("Draft the summary", "msg-u1"),
582
+ created("msg-a1"),
583
+ deferredInterjectionFrame("Also mention the dates"),
584
+ textDeltaFrame("msg-x", "Summary drafted."),
585
+ itemDoneFrame(answerItem("msg-x", "Summary drafted."), { t: 1 }),
586
+ done("msg-a1", "Summary drafted.", { t: 1.1 })
587
+ ]
588
+ },
589
+ { close: true, stream: 0 },
590
+ { snapshot: "resubmitted" },
591
+ {
592
+ stream: 1,
593
+ push: [
594
+ user("Also mention the dates", "msg-u2", "msg-a1"),
595
+ created("msg-a2"),
596
+ done("msg-a2", "Dates: 1 May and 1 June.")
597
+ ]
598
+ },
599
+ { close: true, stream: 1 }
600
+ ]
601
+ },
602
+ {
603
+ name: "agent-control",
604
+ description: "Pause, report and resume while the agent works: optimistic state, the server confirmation and the probe answer, cleared when the turn ends.",
605
+ seed: seededThread,
606
+ steps: [
607
+ { send: "Audit every contract" },
608
+ {
609
+ push: [
610
+ user("Audit every contract", "msg-u1"),
611
+ created("msg-a1"),
612
+ itemDoneFrame(toolItem("fc-1", "search_inside_documents"), { t: 1 })
613
+ ]
614
+ },
615
+ { send: "/pause" },
616
+ { snapshot: "pausing" },
617
+ { push: [agentControlStateFrame("paused")] },
618
+ { send: "/report" },
619
+ { push: [probeAnswerFrame({ question: "/report", answer: "Two of five contracts read." })] },
620
+ { snapshot: "paused-with-report" },
621
+ { send: "/resume" },
622
+ {
623
+ push: [
624
+ agentControlStateFrame("running"),
625
+ userInputRequestFrame({
626
+ question: "Include expired contracts?",
627
+ options: ["Yes", "No"],
628
+ timeout_seconds: 120
629
+ })
630
+ ]
631
+ },
632
+ { snapshot: "asking" },
633
+ { push: [done("msg-a1", "Audit complete.")] },
634
+ { close: true }
635
+ ]
636
+ },
637
+ {
638
+ name: "stop",
639
+ description: "Stop cancels the run on the server first, then closes the stream; the stopped turn is never shown as failed.",
640
+ seed: seededThread,
641
+ steps: [
642
+ { send: "Write a long essay" },
643
+ {
644
+ push: [
645
+ user("Write a long essay", "msg-u1"),
646
+ created("msg-a1"),
647
+ textDeltaFrame("msg-x", "Once upon a time")
648
+ ]
649
+ },
650
+ { stop: true },
651
+ { wait: 100 }
652
+ ]
653
+ },
654
+ {
655
+ name: "drop",
656
+ description: "The connection drops after the server stored the question: the turn is not failed, the thread is re-read and generation is held while it is.",
657
+ seed: seededThread,
658
+ steps: [
659
+ { send: "Explain clause 4" },
660
+ {
661
+ push: [
662
+ user("Explain clause 4", "msg-u1"),
663
+ created("msg-a1"),
664
+ textDeltaFrame("msg-x", "Clause 4")
665
+ ]
666
+ },
667
+ { drop: true },
668
+ { wait: 6e3 }
669
+ ]
670
+ },
671
+ {
672
+ name: "server-failed",
673
+ description: "The server fails the answer (`response.failed`): it is marked failed.",
674
+ seed: seededThread,
675
+ steps: [
676
+ { send: "Explain clause 5" },
677
+ {
678
+ push: [
679
+ user("Explain clause 5", "msg-u1"),
680
+ created("msg-a1"),
681
+ failedFrame("This answer stopped making progress.")
682
+ ]
683
+ },
684
+ { close: true }
685
+ ]
686
+ },
687
+ {
688
+ name: "artifact",
689
+ description: "A streamed html artifact opens in the viewer, joins the chat documents and becomes the pinned document once complete.",
690
+ seed: seededThread,
691
+ steps: [
692
+ { send: "Make a landing page" },
693
+ {
694
+ push: [
695
+ user("Make a landing page", "msg-u1"),
696
+ created("msg-a1"),
697
+ artifactFrame({
698
+ doc_ext_id: "doc-art",
699
+ title: "Landing page",
700
+ mode: "html",
701
+ content: "<h1>Hi",
702
+ file_type: "text/html",
703
+ is_complete: false,
704
+ version: 1,
705
+ message_ext_id: "msg-a1"
706
+ })
707
+ ]
708
+ },
709
+ { snapshot: "streaming-artifact" },
710
+ {
711
+ push: [
712
+ artifactFrame({
713
+ doc_ext_id: "doc-art",
714
+ title: "Landing page",
715
+ mode: "html",
716
+ content: "<h1>Hi</h1>",
717
+ file_type: "text/html",
718
+ is_complete: true,
719
+ version: 1,
720
+ message_ext_id: "msg-a1"
721
+ }),
722
+ done("msg-a1", "I made the landing page.")
723
+ ]
724
+ },
725
+ { close: true }
726
+ ]
727
+ },
728
+ {
729
+ name: "mail-draft",
730
+ description: "A mail draft the assistant saved opens the mail side beside the chat.",
731
+ seed: seededThread,
732
+ steps: [
733
+ { send: "Draft a reply to Sam" },
734
+ {
735
+ push: [
736
+ user("Draft a reply to Sam", "msg-u1"),
737
+ created("msg-a1"),
738
+ mailDraftFrame({ draft_id: "draft-1", message_ext_id: "msg-a1" }),
739
+ done("msg-a1", "The reply is drafted.")
740
+ ]
741
+ },
742
+ { close: true }
743
+ ]
744
+ },
745
+ {
746
+ name: "quota-402",
747
+ description: "The project's AI usage is used up: the query is refused with a 402 and the quota modal opens.",
748
+ seed: seededThread,
749
+ steps: [
750
+ {
751
+ replyNextQuery: {
752
+ status: 402,
753
+ body: {
754
+ detail: {
755
+ code: "QUOTA_EXCEEDED",
756
+ spend: 10,
757
+ budget: 10,
758
+ project_ext_id: "prj-1",
759
+ message: "AI usage for this month is used up."
760
+ }
761
+ }
762
+ }
763
+ },
764
+ { send: "Summarise everything" }
765
+ ]
766
+ },
767
+ {
768
+ name: "quota-stream",
769
+ description: "The AI usage runs out mid-turn (`arbi.error` QUOTA_EXCEEDED).",
770
+ seed: seededThread,
771
+ steps: [
772
+ { send: "Summarise everything again" },
773
+ {
774
+ push: [
775
+ user("Summarise everything again", "msg-u1"),
776
+ created("msg-a1"),
777
+ arbiErrorFrame({
778
+ code: "QUOTA_EXCEEDED",
779
+ message: "AI usage for this month is used up.",
780
+ spend: 10,
781
+ budget: 10,
782
+ projectExtId: "prj-1"
783
+ }),
784
+ failedFrame("AI usage for this month is used up.")
785
+ ]
786
+ },
787
+ { close: true }
788
+ ]
789
+ }
790
+ ];
791
+
792
+ exports.CHAT_SCENARIOS = CHAT_SCENARIOS;
793
+ exports.agentControlStateFrame = agentControlStateFrame;
794
+ exports.agentStream = agentStream;
795
+ exports.answerItem = answerItem;
796
+ exports.arbiErrorFrame = arbiErrorFrame;
797
+ exports.artifactFrame = artifactFrame;
798
+ exports.completedFrame = completedFrame;
799
+ exports.createSseFake = createSseFake;
800
+ exports.deferredInterjectionFrame = deferredInterjectionFrame;
801
+ exports.failedFrame = failedFrame;
802
+ exports.frame = frame;
803
+ exports.itemDoneFrame = itemDoneFrame;
804
+ exports.mailDraftFrame = mailDraftFrame;
805
+ exports.messageQueuedFrame = messageQueuedFrame;
806
+ exports.narrationItem = narrationItem;
807
+ exports.probeAnswerFrame = probeAnswerFrame;
808
+ exports.reasoningItem = reasoningItem;
809
+ exports.responseCreatedFrame = responseCreatedFrame;
810
+ exports.textDeltaFrame = textDeltaFrame;
811
+ exports.toolItem = toolItem;
812
+ exports.userInputRequestFrame = userInputRequestFrame;
813
+ exports.userMessage = userMessage;
814
+ exports.userMessageFrame = userMessageFrame;
815
+ //# sourceMappingURL=testing.cjs.map
816
+ //# sourceMappingURL=testing.cjs.map