assistant-stream 0.0.21 → 0.0.22

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/ai-sdk.js CHANGED
@@ -20,11 +20,289 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/ai-sdk.ts
21
21
  var ai_sdk_exports = {};
22
22
  __export(ai_sdk_exports, {
23
+ LanguageModelV1StreamDecoder: () => LanguageModelV1StreamDecoder,
23
24
  fromStreamObject: () => fromStreamObject,
24
25
  fromStreamText: () => fromStreamText
25
26
  });
26
27
  module.exports = __toCommonJS(ai_sdk_exports);
27
28
 
29
+ // src/core/utils/stream/merge.ts
30
+ var promiseWithResolvers = () => {
31
+ let resolve;
32
+ let reject;
33
+ const promise = new Promise((res, rej) => {
34
+ resolve = res;
35
+ reject = rej;
36
+ });
37
+ return { promise, resolve, reject };
38
+ };
39
+ var createMergeStream = () => {
40
+ const list = [];
41
+ let sealed = false;
42
+ let controller;
43
+ let currentPull;
44
+ const handlePull = (item) => {
45
+ if (!item.promise) {
46
+ item.promise = item.reader.read().then(({ done, value }) => {
47
+ item.promise = void 0;
48
+ if (done) {
49
+ list.splice(list.indexOf(item), 1);
50
+ if (sealed && list.length === 0) {
51
+ controller.close();
52
+ }
53
+ } else {
54
+ controller.enqueue(value);
55
+ }
56
+ currentPull?.resolve();
57
+ currentPull = void 0;
58
+ }).catch((e) => {
59
+ console.error(e);
60
+ list.forEach((item2) => {
61
+ item2.reader.cancel();
62
+ });
63
+ list.length = 0;
64
+ controller.error(e);
65
+ currentPull?.reject(e);
66
+ currentPull = void 0;
67
+ });
68
+ }
69
+ };
70
+ const readable = new ReadableStream({
71
+ start(c) {
72
+ controller = c;
73
+ },
74
+ pull() {
75
+ currentPull = promiseWithResolvers();
76
+ list.forEach((item) => {
77
+ handlePull(item);
78
+ });
79
+ return currentPull.promise;
80
+ },
81
+ cancel() {
82
+ list.forEach((item) => {
83
+ item.reader.cancel();
84
+ });
85
+ list.length = 0;
86
+ }
87
+ });
88
+ return {
89
+ readable,
90
+ isSealed() {
91
+ return sealed;
92
+ },
93
+ seal() {
94
+ sealed = true;
95
+ if (list.length === 0) controller.close();
96
+ },
97
+ addStream(stream) {
98
+ if (sealed)
99
+ throw new Error(
100
+ "Cannot add streams after the run callback has settled."
101
+ );
102
+ const item = { reader: stream.getReader() };
103
+ list.push(item);
104
+ handlePull(item);
105
+ },
106
+ enqueue(chunk) {
107
+ this.addStream(
108
+ new ReadableStream({
109
+ start(c) {
110
+ c.enqueue(chunk);
111
+ c.close();
112
+ }
113
+ })
114
+ );
115
+ }
116
+ };
117
+ };
118
+
119
+ // src/core/modules/text.ts
120
+ var TextStreamControllerImpl = class {
121
+ _controller;
122
+ _isClosed = false;
123
+ constructor(controller) {
124
+ this._controller = controller;
125
+ }
126
+ append(textDelta) {
127
+ this._controller.enqueue({
128
+ type: "text-delta",
129
+ path: [],
130
+ textDelta
131
+ });
132
+ return this;
133
+ }
134
+ close() {
135
+ if (this._isClosed) return;
136
+ this._isClosed = true;
137
+ this._controller.enqueue({
138
+ type: "part-finish",
139
+ path: []
140
+ });
141
+ this._controller.close();
142
+ }
143
+ };
144
+ var createTextStream = (readable) => {
145
+ return new ReadableStream({
146
+ start(c) {
147
+ return readable.start?.(new TextStreamControllerImpl(c));
148
+ },
149
+ pull(c) {
150
+ return readable.pull?.(new TextStreamControllerImpl(c));
151
+ },
152
+ cancel(c) {
153
+ return readable.cancel?.(c);
154
+ }
155
+ });
156
+ };
157
+ var createTextStreamController = () => {
158
+ let controller;
159
+ const stream = createTextStream({
160
+ start(c) {
161
+ controller = c;
162
+ }
163
+ });
164
+ return [stream, controller];
165
+ };
166
+
167
+ // src/core/modules/tool-call.ts
168
+ var ToolCallStreamControllerImpl = class {
169
+ constructor(_controller) {
170
+ this._controller = _controller;
171
+ const stream = createTextStream({
172
+ start: (c) => {
173
+ this._argsTextController = c;
174
+ }
175
+ });
176
+ stream.pipeTo(
177
+ new WritableStream({
178
+ write: (chunk) => {
179
+ switch (chunk.type) {
180
+ case "text-delta":
181
+ this._controller.enqueue(chunk);
182
+ break;
183
+ case "part-finish":
184
+ this._controller.enqueue({
185
+ type: "tool-call-args-text-finish",
186
+ path: []
187
+ });
188
+ break;
189
+ default:
190
+ throw new Error(`Unexpected chunk type: ${chunk.type}`);
191
+ }
192
+ }
193
+ })
194
+ );
195
+ }
196
+ _isClosed = false;
197
+ get argsText() {
198
+ return this._argsTextController;
199
+ }
200
+ _argsTextController;
201
+ setResult(result, isError) {
202
+ this._controller.enqueue({
203
+ type: "result",
204
+ path: [],
205
+ result,
206
+ isError: isError ?? false
207
+ });
208
+ }
209
+ close() {
210
+ if (this._isClosed) return;
211
+ this._isClosed = true;
212
+ this._argsTextController.close();
213
+ this._controller.enqueue({
214
+ type: "part-finish",
215
+ path: []
216
+ });
217
+ this._controller.close();
218
+ }
219
+ };
220
+ var createToolCallStream = (readable) => {
221
+ return new ReadableStream({
222
+ start(c) {
223
+ return readable.start?.(new ToolCallStreamControllerImpl(c));
224
+ },
225
+ pull(c) {
226
+ return readable.pull?.(new ToolCallStreamControllerImpl(c));
227
+ },
228
+ cancel(c) {
229
+ return readable.cancel?.(c);
230
+ }
231
+ });
232
+ };
233
+ var createToolCallStreamController = () => {
234
+ let controller;
235
+ const stream = createToolCallStream({
236
+ start(c) {
237
+ controller = c;
238
+ }
239
+ });
240
+ return [stream, controller];
241
+ };
242
+
243
+ // src/core/utils/Counter.ts
244
+ var Counter = class {
245
+ value = -1;
246
+ up() {
247
+ return ++this.value;
248
+ }
249
+ };
250
+
251
+ // src/core/utils/stream/path-utils.ts
252
+ var PathAppendEncoder = class extends TransformStream {
253
+ constructor(idx) {
254
+ super({
255
+ transform(chunk, controller) {
256
+ controller.enqueue({
257
+ ...chunk,
258
+ path: [idx, ...chunk.path]
259
+ });
260
+ }
261
+ });
262
+ }
263
+ };
264
+ var PathAppendDecoder = class extends TransformStream {
265
+ constructor(idx) {
266
+ super({
267
+ transform(chunk, controller) {
268
+ const {
269
+ path: [idx2, ...path]
270
+ } = chunk;
271
+ if (idx !== idx2)
272
+ throw new Error(`Path mismatch: expected ${idx}, got ${idx2}`);
273
+ controller.enqueue({
274
+ ...chunk,
275
+ path
276
+ });
277
+ }
278
+ });
279
+ }
280
+ };
281
+ var PathMergeEncoder = class extends TransformStream {
282
+ constructor(counter) {
283
+ const innerCounter = new Counter();
284
+ const mapping = /* @__PURE__ */ new Map();
285
+ super({
286
+ transform(chunk, controller) {
287
+ if (chunk.type === "part-start" && chunk.path.length === 0) {
288
+ mapping.set(innerCounter.up(), counter.up());
289
+ }
290
+ const [idx, ...path] = chunk.path;
291
+ if (idx === void 0) {
292
+ controller.enqueue(chunk);
293
+ return;
294
+ }
295
+ const mappedIdx = mapping.get(idx);
296
+ if (mappedIdx === void 0) throw new Error("Path not found");
297
+ controller.enqueue({
298
+ ...chunk,
299
+ path: [mappedIdx, ...path]
300
+ });
301
+ }
302
+ });
303
+ }
304
+ };
305
+
28
306
  // src/core/utils/generateId.tsx
29
307
  var import_non_secure = require("nanoid/non-secure");
30
308
  var generateId = (0, import_non_secure.customAlphabet)(
@@ -32,109 +310,383 @@ var generateId = (0, import_non_secure.customAlphabet)(
32
310
  7
33
311
  );
34
312
 
313
+ // src/core/modules/assistant-stream.ts
314
+ var AssistantStreamControllerImpl = class {
315
+ _merger = createMergeStream();
316
+ _append;
317
+ _contentCounter = new Counter();
318
+ get __internal_isClosed() {
319
+ return this._merger.isSealed();
320
+ }
321
+ __internal_getReadable() {
322
+ return this._merger.readable;
323
+ }
324
+ _closeSubscriber;
325
+ __internal_subscribeToClose(callback) {
326
+ this._closeSubscriber = callback;
327
+ }
328
+ _addPart(part, stream) {
329
+ this.enqueue({
330
+ type: "part-start",
331
+ part,
332
+ path: []
333
+ });
334
+ this._merger.addStream(
335
+ stream.pipeThrough(new PathAppendEncoder(this._contentCounter.value))
336
+ );
337
+ }
338
+ merge(stream) {
339
+ this._merger.addStream(
340
+ stream.pipeThrough(new PathMergeEncoder(this._contentCounter))
341
+ );
342
+ }
343
+ appendText(textDelta) {
344
+ if (this._append?.kind !== "text") {
345
+ if (this._append) {
346
+ this._append.controller.close();
347
+ }
348
+ this._append = {
349
+ kind: "text",
350
+ controller: this.addTextPart()
351
+ };
352
+ }
353
+ this._append.controller.append(textDelta);
354
+ }
355
+ appendReasoning(textDelta) {
356
+ if (this._append?.kind !== "reasoning") {
357
+ if (this._append) {
358
+ this._append.controller.close();
359
+ }
360
+ this._append = {
361
+ kind: "reasoning",
362
+ controller: this.addReasoningPart()
363
+ };
364
+ }
365
+ this._append.controller.append(textDelta);
366
+ }
367
+ addTextPart() {
368
+ const [stream, controller] = createTextStreamController();
369
+ this._addPart({ type: "text" }, stream);
370
+ return controller;
371
+ }
372
+ addReasoningPart() {
373
+ const [stream, controller] = createTextStreamController();
374
+ this._addPart({ type: "reasoning" }, stream);
375
+ return controller;
376
+ }
377
+ addToolCallPart(options) {
378
+ const opt = typeof options === "string" ? { toolName: options } : options;
379
+ const toolName = opt.toolName;
380
+ const toolCallId = opt.toolCallId ?? generateId();
381
+ const [stream, controller] = createToolCallStreamController();
382
+ this._addPart({ type: "tool-call", toolName, toolCallId }, stream);
383
+ if (opt.args !== void 0) {
384
+ controller.argsText.append(JSON.stringify(opt.args));
385
+ controller.argsText.close();
386
+ }
387
+ if (opt.result !== void 0) {
388
+ controller.setResult(opt.result, opt.isError);
389
+ }
390
+ return controller;
391
+ }
392
+ appendSource(options) {
393
+ this._addPart(
394
+ options,
395
+ new ReadableStream({
396
+ start(controller) {
397
+ controller.enqueue({
398
+ type: "part-finish",
399
+ path: []
400
+ });
401
+ controller.close();
402
+ }
403
+ })
404
+ );
405
+ }
406
+ appendFile(options) {
407
+ this._addPart(
408
+ options,
409
+ new ReadableStream({
410
+ start(controller) {
411
+ controller.enqueue({
412
+ type: "part-finish",
413
+ path: []
414
+ });
415
+ controller.close();
416
+ }
417
+ })
418
+ );
419
+ }
420
+ enqueue(chunk) {
421
+ this._merger.enqueue(chunk);
422
+ if (chunk.type === "part-start" && chunk.path.length === 0) {
423
+ this._contentCounter.up();
424
+ }
425
+ }
426
+ close() {
427
+ this._merger.seal();
428
+ this._append?.controller?.close();
429
+ this._closeSubscriber?.();
430
+ }
431
+ };
432
+ function createAssistantStream(callback) {
433
+ const controller = new AssistantStreamControllerImpl();
434
+ let promiseOrVoid;
435
+ try {
436
+ promiseOrVoid = callback(controller);
437
+ } catch (e) {
438
+ if (!controller.__internal_isClosed) {
439
+ controller.enqueue({
440
+ type: "error",
441
+ path: [],
442
+ error: String(e)
443
+ });
444
+ controller.close();
445
+ }
446
+ throw e;
447
+ }
448
+ if (promiseOrVoid instanceof Promise) {
449
+ const runTask = async () => {
450
+ try {
451
+ await promiseOrVoid;
452
+ } catch (e) {
453
+ if (!controller.__internal_isClosed) {
454
+ controller.enqueue({
455
+ type: "error",
456
+ path: [],
457
+ error: String(e)
458
+ });
459
+ }
460
+ throw e;
461
+ } finally {
462
+ if (!controller.__internal_isClosed) {
463
+ controller.close();
464
+ }
465
+ }
466
+ };
467
+ runTask();
468
+ } else {
469
+ if (!controller.__internal_isClosed) {
470
+ controller.close();
471
+ }
472
+ }
473
+ return controller.__internal_getReadable();
474
+ }
475
+ var promiseWithResolvers2 = function() {
476
+ let resolve;
477
+ let reject;
478
+ const promise = new Promise((res, rej) => {
479
+ resolve = res;
480
+ reject = rej;
481
+ });
482
+ if (!resolve || !reject) throw new Error("Failed to create promise");
483
+ return { promise, resolve, reject };
484
+ };
485
+ function createAssistantStreamController() {
486
+ const { resolve, promise } = promiseWithResolvers2();
487
+ let controller;
488
+ const stream = createAssistantStream((c) => {
489
+ controller = c;
490
+ controller.__internal_subscribeToClose(
491
+ resolve
492
+ );
493
+ return promise;
494
+ });
495
+ return [stream, controller];
496
+ }
497
+
498
+ // src/core/utils/stream/AssistantTransformStream.ts
499
+ var AssistantTransformStream = class extends TransformStream {
500
+ constructor(transformer, writableStrategy, readableStrategy) {
501
+ const [stream, runController] = createAssistantStreamController();
502
+ let runPipeTask;
503
+ super(
504
+ {
505
+ start(controller) {
506
+ runPipeTask = stream.pipeTo(
507
+ new WritableStream({
508
+ write(chunk) {
509
+ controller.enqueue(chunk);
510
+ },
511
+ abort(reason) {
512
+ controller.error(reason);
513
+ },
514
+ close() {
515
+ controller.terminate();
516
+ }
517
+ })
518
+ ).catch((error) => {
519
+ controller.error(error);
520
+ });
521
+ return transformer.start?.(runController);
522
+ },
523
+ transform(chunk) {
524
+ return transformer.transform?.(chunk, runController);
525
+ },
526
+ async flush() {
527
+ await transformer.flush?.(runController);
528
+ runController.close();
529
+ await runPipeTask;
530
+ }
531
+ },
532
+ writableStrategy,
533
+ readableStrategy
534
+ );
535
+ }
536
+ };
537
+
35
538
  // src/ai-sdk/index.ts
36
539
  var fromStreamText = (stream) => {
37
- const transformer = new TransformStream({
540
+ const toolControllers = /* @__PURE__ */ new Map();
541
+ let currentToolCallArgsText;
542
+ const endCurrentToolCallArgsText = () => {
543
+ if (!currentToolCallArgsText) return;
544
+ currentToolCallArgsText.argsText.close();
545
+ currentToolCallArgsText = void 0;
546
+ };
547
+ const transformer = new AssistantTransformStream({
38
548
  transform(chunk, controller) {
39
549
  const { type } = chunk;
550
+ if (type !== "tool-call-delta" && type !== "error") {
551
+ endCurrentToolCallArgsText();
552
+ }
40
553
  switch (type) {
41
554
  case "text-delta": {
42
555
  const { textDelta } = chunk;
43
- controller.enqueue({
44
- type: "text-delta",
45
- textDelta
46
- });
556
+ controller.appendText(textDelta);
557
+ break;
558
+ }
559
+ case "reasoning": {
560
+ const { textDelta } = chunk;
561
+ controller.appendReasoning(textDelta);
47
562
  break;
48
563
  }
49
564
  case "tool-call-streaming-start": {
50
565
  const { toolCallId, toolName } = chunk;
51
- controller.enqueue({
52
- type: "tool-call-begin",
566
+ currentToolCallArgsText = controller.addToolCallPart({
53
567
  toolCallId,
54
568
  toolName
55
569
  });
570
+ toolControllers.set(toolCallId, currentToolCallArgsText);
56
571
  break;
57
572
  }
58
573
  case "tool-call-delta": {
59
574
  const { toolCallId, argsTextDelta } = chunk;
60
- controller.enqueue({
61
- type: "tool-call-delta",
62
- toolCallId,
63
- argsTextDelta
64
- });
575
+ const toolController = toolControllers.get(toolCallId);
576
+ if (!toolController) throw new Error("Tool call not found");
577
+ toolController.argsText.append(argsTextDelta);
65
578
  break;
66
579
  }
67
580
  case "tool-result": {
68
581
  const { toolCallId, result } = chunk;
69
- controller.enqueue({
70
- type: "tool-result",
71
- toolCallId,
72
- result
73
- });
582
+ const toolController = toolControllers.get(toolCallId);
583
+ if (!toolController) throw new Error("Tool call not found");
584
+ toolController.setResult(result);
585
+ toolController.close();
586
+ toolControllers.delete(toolCallId);
74
587
  break;
75
588
  }
76
589
  case "tool-call": {
77
590
  const { toolCallId, toolName, args } = chunk;
78
- controller.enqueue({
79
- type: "tool-call-begin",
591
+ const toolController = controller.addToolCallPart({
80
592
  toolCallId,
81
593
  toolName
82
594
  });
83
- controller.enqueue({
84
- type: "tool-call-delta",
85
- toolCallId,
86
- argsTextDelta: JSON.stringify(args)
87
- });
595
+ toolController.argsText.append(JSON.stringify(args));
596
+ toolController.argsText.close();
597
+ toolControllers.set(toolCallId, toolController);
88
598
  break;
89
599
  }
90
- case "reasoning":
91
600
  case "step-start":
601
+ controller.enqueue({
602
+ type: "step-start",
603
+ path: [],
604
+ messageId: chunk.messageId
605
+ });
606
+ break;
92
607
  case "step-finish":
608
+ controller.enqueue({
609
+ type: "step-finish",
610
+ path: [],
611
+ finishReason: chunk.finishReason,
612
+ usage: chunk.usage,
613
+ isContinued: chunk.isContinued
614
+ });
615
+ break;
93
616
  case "error":
617
+ controller.enqueue({
618
+ type: "error",
619
+ path: [],
620
+ error: String(chunk.error)
621
+ });
622
+ break;
94
623
  case "finish": {
624
+ controller.enqueue({
625
+ type: "message-finish",
626
+ path: [],
627
+ finishReason: chunk.finishReason,
628
+ usage: chunk.usage
629
+ });
95
630
  break;
96
631
  }
632
+ case "source":
633
+ controller.appendSource({
634
+ type: "source",
635
+ ...chunk.source
636
+ });
637
+ break;
638
+ case "file":
639
+ controller.appendFile({
640
+ type: "file",
641
+ mimeType: chunk.mimeType,
642
+ data: chunk.base64
643
+ });
644
+ break;
645
+ case "reasoning-signature":
646
+ case "redacted-reasoning":
647
+ break;
97
648
  default: {
98
649
  const unhandledType = type;
99
650
  throw new Error(`Unhandled chunk type: ${unhandledType}`);
100
651
  }
101
652
  }
653
+ },
654
+ flush() {
655
+ for (const toolController of toolControllers.values()) {
656
+ toolController.close();
657
+ }
658
+ toolControllers.clear();
102
659
  }
103
660
  });
104
661
  return stream.pipeThrough(transformer);
105
662
  };
106
663
  var fromStreamObject = (stream, toolName) => {
107
- const toolCallId = generateId();
108
- const transformer = new TransformStream({
664
+ let toolCall;
665
+ const transformer = new AssistantTransformStream({
109
666
  start(controller) {
110
- controller.enqueue({
111
- type: "tool-call-begin",
112
- toolName,
113
- toolCallId
114
- });
667
+ toolCall = controller.addToolCallPart(toolName);
115
668
  },
116
669
  transform(chunk, controller) {
117
670
  const { type } = chunk;
118
671
  switch (type) {
119
672
  case "text-delta": {
120
673
  const { textDelta } = chunk;
121
- controller.enqueue({
122
- type: "tool-call-delta",
123
- toolCallId,
124
- argsTextDelta: textDelta
125
- });
674
+ toolCall.argsText.append(textDelta);
126
675
  break;
127
676
  }
128
677
  case "finish": {
129
- controller.enqueue({
130
- type: "tool-result",
131
- toolCallId,
132
- result: ""
133
- });
678
+ toolCall.argsText.close();
679
+ toolCall.setResult("");
134
680
  break;
135
681
  }
136
682
  case "object":
683
+ break;
137
684
  case "error": {
685
+ controller.enqueue({
686
+ type: "error",
687
+ path: [],
688
+ error: String(chunk.error)
689
+ });
138
690
  break;
139
691
  }
140
692
  default: {
@@ -146,8 +698,105 @@ var fromStreamObject = (stream, toolName) => {
146
698
  });
147
699
  return stream.pipeThrough(transformer);
148
700
  };
701
+
702
+ // src/ai-sdk/language-model.ts
703
+ function bufferToBase64(buffer) {
704
+ return btoa(String.fromCharCode(...buffer));
705
+ }
706
+ var LanguageModelV1StreamDecoder = class extends AssistantTransformStream {
707
+ constructor() {
708
+ let currentToolCall;
709
+ const endCurrentToolCall = () => {
710
+ if (!currentToolCall) return;
711
+ currentToolCall.controller.argsText.close();
712
+ currentToolCall.controller.close();
713
+ currentToolCall = void 0;
714
+ };
715
+ super({
716
+ transform(chunk, controller) {
717
+ const { type } = chunk;
718
+ if (type !== "tool-call-delta" && type !== "error") {
719
+ endCurrentToolCall();
720
+ }
721
+ switch (type) {
722
+ case "text-delta": {
723
+ controller.appendText(chunk.textDelta);
724
+ break;
725
+ }
726
+ case "reasoning": {
727
+ controller.appendReasoning(chunk.textDelta);
728
+ break;
729
+ }
730
+ case "source": {
731
+ controller.appendSource({
732
+ type: "source",
733
+ ...chunk.source
734
+ });
735
+ break;
736
+ }
737
+ case "file": {
738
+ controller.appendFile({
739
+ type: "file",
740
+ mimeType: chunk.mimeType,
741
+ data: typeof chunk.data === "string" ? chunk.data : bufferToBase64(chunk.data)
742
+ });
743
+ break;
744
+ }
745
+ case "tool-call-delta": {
746
+ const { toolCallId, toolName, argsTextDelta } = chunk;
747
+ if (currentToolCall?.toolCallId === toolCallId) {
748
+ currentToolCall.controller.argsText.append(argsTextDelta);
749
+ } else {
750
+ endCurrentToolCall();
751
+ currentToolCall = {
752
+ toolCallId,
753
+ controller: controller.addToolCallPart({
754
+ toolCallId,
755
+ toolName
756
+ })
757
+ };
758
+ currentToolCall.controller.argsText.append(argsTextDelta);
759
+ }
760
+ break;
761
+ }
762
+ case "tool-call": {
763
+ const { toolCallId, toolName, args } = chunk;
764
+ const toolController = controller.addToolCallPart({
765
+ toolCallId,
766
+ toolName
767
+ });
768
+ toolController.argsText.append(JSON.stringify(args));
769
+ toolController.argsText.close();
770
+ toolController.close();
771
+ break;
772
+ }
773
+ case "finish": {
774
+ controller.enqueue({
775
+ type: "message-finish",
776
+ finishReason: chunk.finishReason,
777
+ usage: chunk.usage,
778
+ path: []
779
+ });
780
+ controller.close();
781
+ break;
782
+ }
783
+ case "error":
784
+ case "response-metadata":
785
+ case "reasoning-signature":
786
+ case "redacted-reasoning":
787
+ break;
788
+ default: {
789
+ const unhandledType = type;
790
+ throw new Error(`Unhandled chunk type: ${unhandledType}`);
791
+ }
792
+ }
793
+ }
794
+ });
795
+ }
796
+ };
149
797
  // Annotate the CommonJS export names for ESM import in node:
150
798
  0 && (module.exports = {
799
+ LanguageModelV1StreamDecoder,
151
800
  fromStreamObject,
152
801
  fromStreamText
153
802
  });