@theokit/presenter 0.6.0 → 0.8.0

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.
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-Z4QWC7IK.js";
4
+
1
5
  // src/agent-output-event.ts
2
6
  var AGENT_OUTPUT_EVENT_TYPES = [
3
7
  "text",
@@ -9,25 +13,29 @@ var AGENT_OUTPUT_EVENT_TYPES = [
9
13
  "finish",
10
14
  "status"
11
15
  ];
12
- var isTextEvent = (e) => e.type === "text";
13
- var isReasoningEvent = (e) => e.type === "reasoning";
14
- var isToolCallEvent = (e) => e.type === "tool-call";
15
- var isPartialToolCallEvent = (e) => e.type === "partial-tool-call";
16
- var isToolResultEvent = (e) => e.type === "tool-result";
17
- var isErrorEvent = (e) => e.type === "error";
18
- var isFinishEvent = (e) => e.type === "finish";
19
- var isStatusEvent = (e) => e.type === "status";
16
+ var isTextEvent = /* @__PURE__ */ __name((e) => e.type === "text", "isTextEvent");
17
+ var isReasoningEvent = /* @__PURE__ */ __name((e) => e.type === "reasoning", "isReasoningEvent");
18
+ var isToolCallEvent = /* @__PURE__ */ __name((e) => e.type === "tool-call", "isToolCallEvent");
19
+ var isPartialToolCallEvent = /* @__PURE__ */ __name((e) => e.type === "partial-tool-call", "isPartialToolCallEvent");
20
+ var isToolResultEvent = /* @__PURE__ */ __name((e) => e.type === "tool-result", "isToolResultEvent");
21
+ var isErrorEvent = /* @__PURE__ */ __name((e) => e.type === "error", "isErrorEvent");
22
+ var isFinishEvent = /* @__PURE__ */ __name((e) => e.type === "finish", "isFinishEvent");
23
+ var isStatusEvent = /* @__PURE__ */ __name((e) => e.type === "status", "isStatusEvent");
20
24
 
21
25
  // src/presenter.ts
22
26
  var UnknownPresenterError = class extends Error {
27
+ static {
28
+ __name(this, "UnknownPresenterError");
29
+ }
23
30
  name = "UnknownPresenterError";
24
31
  constructor(surface, known) {
25
- super(
26
- `No presenter registered for surface "${surface}". Known: ${known.join(", ") || "(none)"}.`
27
- );
32
+ super(`No presenter registered for surface "${surface}". Known: ${known.join(", ") || "(none)"}.`);
28
33
  }
29
34
  };
30
35
  var PresenterRegistry = class {
36
+ static {
37
+ __name(this, "PresenterRegistry");
38
+ }
31
39
  #presenters = /* @__PURE__ */ new Map();
32
40
  /** Register (or replace) the presenter for its surface. Returns `this` for fluent wiring. */
33
41
  register(presenter) {
@@ -40,7 +48,9 @@ var PresenterRegistry = class {
40
48
  }
41
49
  /** The registered surface keys. */
42
50
  surfaces() {
43
- return [...this.#presenters.keys()];
51
+ return [
52
+ ...this.#presenters.keys()
53
+ ];
44
54
  }
45
55
  /** Resolve the presenter for `surface`, or throw {@link UnknownPresenterError} (never returns undefined). */
46
56
  resolve(surface) {
@@ -54,6 +64,7 @@ var PresenterRegistry = class {
54
64
  function asString(value, fallback) {
55
65
  return typeof value === "string" ? value : fallback;
56
66
  }
67
+ __name(asString, "asString");
57
68
  function serializeToolResult(value, fallback) {
58
69
  if (typeof value === "string") return value;
59
70
  if (value === void 0 || value === null) return fallback;
@@ -63,13 +74,17 @@ function serializeToolResult(value, fallback) {
63
74
  return typeof value === "bigint" ? value.toString() : fallback;
64
75
  }
65
76
  }
77
+ __name(serializeToolResult, "serializeToolResult");
66
78
  function fromAssistant(msg) {
67
79
  const events = [];
68
80
  const content = msg.message?.content;
69
81
  if (!Array.isArray(content)) return events;
70
82
  for (const block of content) {
71
83
  const b = block;
72
- if (b.type === "text" && b.text) events.push({ type: "text", text: b.text });
84
+ if (b.type === "text" && b.text) events.push({
85
+ type: "text",
86
+ text: b.text
87
+ });
73
88
  if (b.type === "tool_use") {
74
89
  events.push({
75
90
  type: "tool-call",
@@ -81,6 +96,7 @@ function fromAssistant(msg) {
81
96
  }
82
97
  return events;
83
98
  }
99
+ __name(fromAssistant, "fromAssistant");
84
100
  function fromToolUse(msg) {
85
101
  const status = msg.status;
86
102
  const callId = asString(msg.call_id, `tc-${Date.now()}`);
@@ -109,19 +125,37 @@ function fromToolUse(msg) {
109
125
  }
110
126
  if (status === "running") {
111
127
  return [
112
- { type: "tool-call", callId, name, input: msg.args ?? msg.input ?? msg.arguments ?? {} }
128
+ {
129
+ type: "tool-call",
130
+ callId,
131
+ name,
132
+ input: msg.args ?? msg.input ?? msg.arguments ?? {}
133
+ }
113
134
  ];
114
135
  }
115
136
  return [];
116
137
  }
138
+ __name(fromToolUse, "fromToolUse");
117
139
  function fromStatus(msg) {
118
140
  const s = msg.status;
119
- if (s === "FINISHED" || s === "CANCELLED") return [{ type: "finish", reason: s.toLowerCase() }];
141
+ if (s === "FINISHED" || s === "CANCELLED") return [
142
+ {
143
+ type: "finish",
144
+ reason: s.toLowerCase()
145
+ }
146
+ ];
120
147
  if (s === "ERROR" || s === "EXPIRED") {
121
- return [{ type: "error", message: asString(msg.message, "Agent error"), code: "AGENT_ERROR" }];
148
+ return [
149
+ {
150
+ type: "error",
151
+ message: asString(msg.message, "Agent error"),
152
+ code: "AGENT_ERROR"
153
+ }
154
+ ];
122
155
  }
123
156
  return [];
124
157
  }
158
+ __name(fromStatus, "fromStatus");
125
159
  function fromSdkMessage(msg) {
126
160
  switch (msg.type) {
127
161
  case "assistant":
@@ -129,7 +163,12 @@ function fromSdkMessage(msg) {
129
163
  case "tool_call":
130
164
  return fromToolUse(msg);
131
165
  case "thinking":
132
- return [{ type: "reasoning", text: asString(msg.text, "") }];
166
+ return [
167
+ {
168
+ type: "reasoning",
169
+ text: asString(msg.text, "")
170
+ }
171
+ ];
133
172
  case "status":
134
173
  return fromStatus(msg);
135
174
  // `system` / run-lifecycle is framework framing, not pure output — intentionally skipped (ADR-4).
@@ -137,12 +176,23 @@ function fromSdkMessage(msg) {
137
176
  return [];
138
177
  }
139
178
  }
179
+ __name(fromSdkMessage, "fromSdkMessage");
140
180
  function fromInteractionUpdate(update) {
141
181
  switch (update.type) {
142
182
  case "text-delta":
143
- return update.text ? [{ type: "text", text: update.text }] : [];
183
+ return update.text ? [
184
+ {
185
+ type: "text",
186
+ text: update.text
187
+ }
188
+ ] : [];
144
189
  case "thinking-delta":
145
- return update.text ? [{ type: "reasoning", text: update.text }] : [];
190
+ return update.text ? [
191
+ {
192
+ type: "reasoning",
193
+ text: update.text
194
+ }
195
+ ] : [];
146
196
  case "tool-call-started":
147
197
  return [
148
198
  {
@@ -175,20 +225,114 @@ function fromInteractionUpdate(update) {
175
225
  return [];
176
226
  }
177
227
  }
228
+ __name(fromInteractionUpdate, "fromInteractionUpdate");
229
+
230
+ // src/source/from-wire-chunk.ts
231
+ var UNKNOWN_TOOL_NAME = "unknown tool";
232
+ var FRAMING_CHUNK_TYPES = /* @__PURE__ */ new Set([
233
+ "start",
234
+ "text-start",
235
+ "text-end",
236
+ "reasoning-start",
237
+ "reasoning-end"
238
+ ]);
239
+ function fromWireChunk(chunk, toolNames) {
240
+ if (FRAMING_CHUNK_TYPES.has(chunk.type)) return [];
241
+ switch (chunk.type) {
242
+ case "text-delta":
243
+ return [
244
+ {
245
+ type: "text",
246
+ text: chunk.delta
247
+ }
248
+ ];
249
+ case "reasoning-delta":
250
+ return [
251
+ {
252
+ type: "reasoning",
253
+ text: chunk.delta
254
+ }
255
+ ];
256
+ case "tool-input-available":
257
+ return [
258
+ {
259
+ type: "tool-call",
260
+ callId: chunk.toolCallId,
261
+ name: chunk.toolName,
262
+ input: chunk.input
263
+ }
264
+ ];
265
+ case "tool-output-available":
266
+ return [
267
+ {
268
+ type: "tool-result",
269
+ callId: chunk.toolCallId,
270
+ name: toolNames?.get(chunk.toolCallId) ?? UNKNOWN_TOOL_NAME,
271
+ result: chunk.output
272
+ }
273
+ ];
274
+ // A failed tool is still a TOOL RESULT keyed by its call, never a run-level `error`. Collapsing
275
+ // the two would lose which call failed — the one thing the operator needs to act on.
276
+ case "tool-output-error":
277
+ return [
278
+ {
279
+ type: "tool-result",
280
+ callId: chunk.toolCallId,
281
+ name: toolNames?.get(chunk.toolCallId) ?? UNKNOWN_TOOL_NAME,
282
+ result: chunk.errorText,
283
+ isError: true
284
+ }
285
+ ];
286
+ // HITL is a FRAMEWORK concern, not pure agent output. The forward mapping composed approvals
287
+ // inline rather than routing them through the canonical event (ADR-4); the inverse draws the
288
+ // line in the same place, or the two disagree about what the canonical event means.
289
+ case "tool-approval-request":
290
+ return [];
291
+ case "error":
292
+ return [
293
+ {
294
+ type: "error",
295
+ message: chunk.errorText ?? "unknown error"
296
+ }
297
+ ];
298
+ case "finish":
299
+ return [
300
+ {
301
+ type: "finish"
302
+ }
303
+ ];
304
+ // `data-*` is an open family carrying transport concerns. It is also the arm that catches a
305
+ // frame this build does not recognise — the wire is validated upstream, so an unmapped type
306
+ // here means the schema grew and this switch did not. `tests/from-wire-chunk.test.ts`
307
+ // enumerates `WIRE_CHUNK_TYPES` precisely to fail before that reaches a consumer.
308
+ default:
309
+ return [];
310
+ }
311
+ }
312
+ __name(fromWireChunk, "fromWireChunk");
178
313
 
179
314
  // src/presenters/ui-message-stream.ts
180
315
  var UIMessageStreamPresenter = class {
316
+ static {
317
+ __name(this, "UIMessageStreamPresenter");
318
+ }
181
319
  surface = "ui-message-stream";
182
320
  #textId;
321
+ #onError;
183
322
  #openBlock = null;
184
323
  #reasoningId = null;
185
324
  #seen = /* @__PURE__ */ new Set();
186
325
  constructor(options) {
187
326
  this.#textId = options.textId;
327
+ this.#onError = options.onError ?? (() => "An error occurred.");
188
328
  }
189
329
  /** Emit the opening `start` chunk (exactly once, before any event). */
190
330
  start() {
191
- return [{ type: "start" }];
331
+ return [
332
+ {
333
+ type: "start"
334
+ }
335
+ ];
192
336
  }
193
337
  present(event) {
194
338
  switch (event.type) {
@@ -207,7 +351,14 @@ var UIMessageStreamPresenter = class {
207
351
  ...this.#emitToolResult(event.callId, event.name, event.result, event.isError ?? false)
208
352
  ];
209
353
  case "error":
210
- return [{ type: "error", errorText: event.message }];
354
+ return [
355
+ {
356
+ type: "error",
357
+ errorText: this.#onError({
358
+ message: event.message
359
+ })
360
+ }
361
+ ];
211
362
  // `partial-tool-call` streams incremental args — the current web path emits no chunk for it
212
363
  // (args are shown on the committed `tool-call`); `finish` / `status` are handled by finish()/host.
213
364
  default:
@@ -215,27 +366,32 @@ var UIMessageStreamPresenter = class {
215
366
  }
216
367
  }
217
368
  /**
218
- * Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given
219
- * (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the
220
- * finish is bare (error/abort turns), byte-identical to the original translator.
221
- */
369
+ * Close any open text/reasoning block and emit the terminal `finish` chunk. When `metadata` is given
370
+ * (a clean run's turn totals from the framework `done`), it rides `messageMetadata`; otherwise the
371
+ * finish is bare (error/abort turns), byte-identical to the original translator.
372
+ */
222
373
  finish(metadata) {
223
374
  const out = this.#closeOpenBlock();
224
- out.push(metadata ? { type: "finish", messageMetadata: metadata } : { type: "finish" });
375
+ out.push(metadata ? {
376
+ type: "finish",
377
+ messageMetadata: metadata
378
+ } : {
379
+ type: "finish"
380
+ });
225
381
  return out;
226
382
  }
227
383
  /**
228
- * Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before
229
- * interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text
230
- * block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.
231
- */
384
+ * Close any open text/reasoning block WITHOUT finishing the stream. The host calls this before
385
+ * interleaving a framework chunk (HITL approval / checkpoint) that must not appear inside an open text
386
+ * block — mirroring the original translator's `closeOpenBlock` before those chunks. Idempotent.
387
+ */
232
388
  closeBlock() {
233
389
  return this.#closeOpenBlock();
234
390
  }
235
391
  /**
236
- * Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host
237
- * uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.
238
- */
392
+ * Whether a `callId` has already been introduced (a `tool-call` or a synthesized `tool-input`). The host
393
+ * uses this so a framework `approval_required` reuses the EC-1 synthesize-input-first rule exactly once.
394
+ */
239
395
  hasSeen(callId) {
240
396
  return this.#seen.has(callId);
241
397
  }
@@ -247,9 +403,15 @@ var UIMessageStreamPresenter = class {
247
403
  #closeOpenBlock() {
248
404
  const out = [];
249
405
  if (this.#openBlock === "text") {
250
- out.push({ type: "text-end", id: this.#textId });
406
+ out.push({
407
+ type: "text-end",
408
+ id: this.#textId
409
+ });
251
410
  } else if (this.#openBlock === "reasoning" && this.#reasoningId) {
252
- out.push({ type: "reasoning-end", id: this.#reasoningId });
411
+ out.push({
412
+ type: "reasoning-end",
413
+ id: this.#reasoningId
414
+ });
253
415
  }
254
416
  this.#openBlock = null;
255
417
  this.#reasoningId = null;
@@ -258,10 +420,17 @@ var UIMessageStreamPresenter = class {
258
420
  #emitTextDelta(content) {
259
421
  const out = [];
260
422
  if (this.#openBlock !== "text") {
261
- out.push(...this.#closeOpenBlock(), { type: "text-start", id: this.#textId });
423
+ out.push(...this.#closeOpenBlock(), {
424
+ type: "text-start",
425
+ id: this.#textId
426
+ });
262
427
  this.#openBlock = "text";
263
428
  }
264
- out.push({ type: "text-delta", id: this.#textId, delta: content });
429
+ out.push({
430
+ type: "text-delta",
431
+ id: this.#textId,
432
+ delta: content
433
+ });
265
434
  return out;
266
435
  }
267
436
  #emitReasoningDelta(content) {
@@ -271,16 +440,29 @@ var UIMessageStreamPresenter = class {
271
440
  out.push(...this.#closeOpenBlock());
272
441
  reasoningId = crypto.randomUUID();
273
442
  this.#reasoningId = reasoningId;
274
- out.push({ type: "reasoning-start", id: reasoningId });
443
+ out.push({
444
+ type: "reasoning-start",
445
+ id: reasoningId
446
+ });
275
447
  this.#openBlock = "reasoning";
276
448
  }
277
- out.push({ type: "reasoning-delta", id: reasoningId, delta: content });
449
+ out.push({
450
+ type: "reasoning-delta",
451
+ id: reasoningId,
452
+ delta: content
453
+ });
278
454
  return out;
279
455
  }
280
456
  #emitToolCall(callId, name, input) {
281
457
  this.#seen.add(callId);
282
458
  return [
283
- { type: "tool-input-available", toolCallId: callId, toolName: name, input, dynamic: true }
459
+ {
460
+ type: "tool-input-available",
461
+ toolCallId: callId,
462
+ toolName: name,
463
+ input,
464
+ dynamic: true
465
+ }
284
466
  ];
285
467
  }
286
468
  #emitToolResult(callId, name, result, isError) {
@@ -297,9 +479,19 @@ var UIMessageStreamPresenter = class {
297
479
  }
298
480
  const output = typeof result === "string" ? result : "";
299
481
  if (isError) {
300
- out.push({ type: "tool-output-error", toolCallId: callId, errorText: output });
482
+ out.push({
483
+ type: "tool-output-error",
484
+ toolCallId: callId,
485
+ errorText: this.#onError({
486
+ message: output
487
+ })
488
+ });
301
489
  } else {
302
- out.push({ type: "tool-output-available", toolCallId: callId, output });
490
+ out.push({
491
+ type: "tool-output-available",
492
+ toolCallId: callId,
493
+ output
494
+ });
303
495
  }
304
496
  return out;
305
497
  }
@@ -309,15 +501,11 @@ var UIMessageStreamPresenter = class {
309
501
  var ANSI = {
310
502
  text: "",
311
503
  reasoning: "\x1B[2m",
312
- // dim
313
504
  tool: "\x1B[36m",
314
- // cyan
315
505
  "tool-result": "\x1B[2m",
316
506
  "tool-error": "\x1B[31m",
317
- // red
318
507
  error: "\x1B[31m",
319
508
  status: "\x1B[35m",
320
- // magenta
321
509
  finish: "\x1B[2m"
322
510
  };
323
511
  var RESET = "\x1B[0m";
@@ -326,6 +514,7 @@ function preview(value, max) {
326
514
  const flat = raw.replace(/\s+/g, " ").trim();
327
515
  return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
328
516
  }
517
+ __name(preview, "preview");
329
518
  function safeJson(value) {
330
519
  if (value === void 0 || value === null) return "";
331
520
  try {
@@ -334,10 +523,15 @@ function safeJson(value) {
334
523
  return typeof value === "bigint" ? value.toString() : "";
335
524
  }
336
525
  }
526
+ __name(safeJson, "safeJson");
337
527
  function suffix(open, value, close) {
338
528
  return value === void 0 ? "" : open + value + close;
339
529
  }
530
+ __name(suffix, "suffix");
340
531
  var TerminalPresenter = class {
532
+ static {
533
+ __name(this, "TerminalPresenter");
534
+ }
341
535
  surface = "terminal";
342
536
  #ansi;
343
537
  #max;
@@ -348,21 +542,33 @@ var TerminalPresenter = class {
348
542
  present(event) {
349
543
  switch (event.type) {
350
544
  case "text":
351
- return event.text.length > 0 ? [this.#row("text", event.text)] : [];
545
+ return event.text.length > 0 ? [
546
+ this.#row("text", event.text)
547
+ ] : [];
352
548
  case "reasoning":
353
- return event.text.length > 0 ? [this.#row("reasoning", `\xB7 ${event.text}`)] : [];
549
+ return event.text.length > 0 ? [
550
+ this.#row("reasoning", `\xB7 ${event.text}`)
551
+ ] : [];
354
552
  case "tool-call":
355
- return [this.#row("tool", `\u23FA ${event.name}(${preview(event.input, this.#max)})`)];
553
+ return [
554
+ this.#row("tool", `\u23FA ${event.name}(${preview(event.input, this.#max)})`)
555
+ ];
356
556
  case "tool-result":
357
- return [this.#toolResult(event.isError === true, preview(event.result, this.#max))];
557
+ return [
558
+ this.#toolResult(event.isError === true, preview(event.result, this.#max))
559
+ ];
358
560
  case "error":
359
- return [this.#row("error", `\u2716 ${event.message}${suffix(" (", event.code, ")")}`)];
561
+ return [
562
+ this.#row("error", `\u2716 ${event.message}${suffix(" (", event.code, ")")}`)
563
+ ];
360
564
  case "status":
361
565
  return [
362
566
  this.#row("status", `\u25CF ${event.status}${suffix(" \u2014 ", event.detail, "")}`)
363
567
  ];
364
568
  case "finish":
365
- return [this.#row("finish", this.#finishText(event.reason, event.usage?.totalTokens))];
569
+ return [
570
+ this.#row("finish", this.#finishText(event.reason, event.usage?.totalTokens))
571
+ ];
366
572
  // `partial-tool-call` streams incremental args — the committed `tool-call` renders them.
367
573
  default:
368
574
  return [];
@@ -377,12 +583,18 @@ var TerminalPresenter = class {
377
583
  return `<<${r}${t} >>`;
378
584
  }
379
585
  #row(kind, text) {
380
- return { kind, text: this.#ansi && ANSI[kind] !== "" ? `${ANSI[kind]}${text}${RESET}` : text };
586
+ return {
587
+ kind,
588
+ text: this.#ansi && ANSI[kind] !== "" ? `${ANSI[kind]}${text}${RESET}` : text
589
+ };
381
590
  }
382
591
  };
383
592
 
384
593
  // src/presenters/json.ts
385
594
  var JsonPresenter = class {
595
+ static {
596
+ __name(this, "JsonPresenter");
597
+ }
386
598
  surface = "json";
387
599
  #ns;
388
600
  constructor(options = {}) {
@@ -390,7 +602,12 @@ var JsonPresenter = class {
390
602
  }
391
603
  present(event) {
392
604
  const { type, ...payload } = event;
393
- return [{ type: `${this.#ns}${type}`, ...payload }];
605
+ return [
606
+ {
607
+ type: `${this.#ns}${type}`,
608
+ ...payload
609
+ }
610
+ ];
394
611
  }
395
612
  };
396
613
 
@@ -400,19 +617,29 @@ function foldTurnLifecycle(vocabulary, threadId) {
400
617
  let text = "";
401
618
  let failure;
402
619
  let nextItem = 0;
403
- const idOf = (chunk) => chunk.id ?? `item_${nextItem}`;
404
- const observe = (chunk) => {
620
+ const idOf = /* @__PURE__ */ __name((chunk) => chunk.id ?? `item_${nextItem}`, "idOf");
621
+ const observe = /* @__PURE__ */ __name((chunk) => {
405
622
  if (!open) return [];
406
623
  switch (chunk.kind) {
407
624
  case "text":
408
625
  text += chunk.delta;
409
626
  return [];
410
627
  case "tool-call":
411
- return [vocabulary.itemStarted({ id: idOf(chunk), kind: chunk.name })];
628
+ return [
629
+ vocabulary.itemStarted({
630
+ id: idOf(chunk),
631
+ kind: chunk.name
632
+ })
633
+ ];
412
634
  case "tool-result": {
413
- const closing = vocabulary.itemCompleted({ id: idOf(chunk), kind: chunk.name });
635
+ const closing = vocabulary.itemCompleted({
636
+ id: idOf(chunk),
637
+ kind: chunk.name
638
+ });
414
639
  nextItem += 1;
415
- return [closing];
640
+ return [
641
+ closing
642
+ ];
416
643
  }
417
644
  case "error":
418
645
  failure ??= chunk.message;
@@ -420,23 +647,29 @@ function foldTurnLifecycle(vocabulary, threadId) {
420
647
  default:
421
648
  return [];
422
649
  }
423
- };
424
- const finish = (outcome) => {
650
+ }, "observe");
651
+ const finish = /* @__PURE__ */ __name((outcome) => {
425
652
  if (!open) return [];
426
653
  open = false;
427
654
  const events = [];
428
655
  const message = text.trim();
429
656
  if (message.length > 0) {
430
- events.push(vocabulary.itemCompleted({ id: "message", kind: message }));
657
+ events.push(vocabulary.itemCompleted({
658
+ id: "message",
659
+ kind: message
660
+ }));
431
661
  }
432
662
  const reason = failure ?? (outcome.status === "error" ? outcome.error ?? "turn failed" : void 0);
433
- events.push(
434
- reason === void 0 ? vocabulary.turnCompleted(outcome.usage) : vocabulary.turnFailed({ message: reason })
435
- );
663
+ events.push(reason === void 0 ? vocabulary.turnCompleted(outcome.usage) : vocabulary.turnFailed({
664
+ message: reason
665
+ }));
436
666
  return events;
437
- };
667
+ }, "finish");
438
668
  return {
439
- opened: [vocabulary.threadStarted(threadId), vocabulary.turnStarted()],
669
+ opened: [
670
+ vocabulary.threadStarted(threadId),
671
+ vocabulary.turnStarted()
672
+ ],
440
673
  get isOpen() {
441
674
  return open;
442
675
  },
@@ -444,6 +677,7 @@ function foldTurnLifecycle(vocabulary, threadId) {
444
677
  finish
445
678
  };
446
679
  }
680
+ __name(foldTurnLifecycle, "foldTurnLifecycle");
447
681
  export {
448
682
  AGENT_OUTPUT_EVENT_TYPES,
449
683
  JsonPresenter,
@@ -454,6 +688,7 @@ export {
454
688
  foldTurnLifecycle,
455
689
  fromInteractionUpdate,
456
690
  fromSdkMessage,
691
+ fromWireChunk,
457
692
  isErrorEvent,
458
693
  isFinishEvent,
459
694
  isPartialToolCallEvent,