ai 3.0.19 → 3.0.21

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.
Files changed (67) hide show
  1. package/anthropic/dist/index.d.mts +1 -319
  2. package/anthropic/dist/index.d.ts +1 -319
  3. package/anthropic/dist/index.js +44 -216
  4. package/anthropic/dist/index.js.map +1 -1
  5. package/anthropic/dist/index.mjs +32 -200
  6. package/anthropic/dist/index.mjs.map +1 -1
  7. package/dist/index.d.mts +60 -333
  8. package/dist/index.d.ts +60 -333
  9. package/dist/index.js +152 -441
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +127 -412
  12. package/dist/index.mjs.map +1 -1
  13. package/google/dist/index.d.mts +1 -319
  14. package/google/dist/index.d.ts +1 -319
  15. package/google/dist/index.js +75 -229
  16. package/google/dist/index.js.map +1 -1
  17. package/google/dist/index.mjs +63 -213
  18. package/google/dist/index.mjs.map +1 -1
  19. package/mistral/dist/index.d.mts +1 -319
  20. package/mistral/dist/index.d.ts +1 -319
  21. package/mistral/dist/index.js +32 -205
  22. package/mistral/dist/index.js.map +1 -1
  23. package/mistral/dist/index.mjs +20 -189
  24. package/mistral/dist/index.mjs.map +1 -1
  25. package/openai/dist/index.d.mts +2 -320
  26. package/openai/dist/index.d.ts +2 -320
  27. package/openai/dist/index.js +69 -280
  28. package/openai/dist/index.js.map +1 -1
  29. package/openai/dist/index.mjs +57 -260
  30. package/openai/dist/index.mjs.map +1 -1
  31. package/package.json +4 -10
  32. package/react/dist/index.d.mts +8 -4
  33. package/react/dist/index.d.ts +12 -6
  34. package/react/dist/index.js +23 -105
  35. package/react/dist/index.js.map +1 -1
  36. package/react/dist/index.mjs +22 -105
  37. package/react/dist/index.mjs.map +1 -1
  38. package/react/dist/index.server.d.mts +4 -2
  39. package/react/dist/index.server.d.ts +4 -2
  40. package/react/dist/index.server.js.map +1 -1
  41. package/react/dist/index.server.mjs.map +1 -1
  42. package/rsc/dist/rsc-server.mjs +6 -16
  43. package/rsc/dist/rsc-server.mjs.map +1 -1
  44. package/solid/dist/index.d.mts +1 -1
  45. package/solid/dist/index.d.ts +1 -1
  46. package/solid/dist/index.js +19 -104
  47. package/solid/dist/index.js.map +1 -1
  48. package/solid/dist/index.mjs +19 -104
  49. package/solid/dist/index.mjs.map +1 -1
  50. package/svelte/dist/index.d.mts +1 -1
  51. package/svelte/dist/index.d.ts +1 -1
  52. package/svelte/dist/index.js +19 -104
  53. package/svelte/dist/index.js.map +1 -1
  54. package/svelte/dist/index.mjs +19 -104
  55. package/svelte/dist/index.mjs.map +1 -1
  56. package/vue/dist/index.d.mts +1 -1
  57. package/vue/dist/index.d.ts +1 -1
  58. package/vue/dist/index.js +19 -104
  59. package/vue/dist/index.js.map +1 -1
  60. package/vue/dist/index.mjs +19 -104
  61. package/vue/dist/index.mjs.map +1 -1
  62. package/spec/dist/index.d.mts +0 -752
  63. package/spec/dist/index.d.ts +0 -752
  64. package/spec/dist/index.js +0 -873
  65. package/spec/dist/index.js.map +0 -1
  66. package/spec/dist/index.mjs +0 -807
  67. package/spec/dist/index.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ __export(streams_exports, {
37
37
  AWSBedrockLlama2Stream: () => AWSBedrockLlama2Stream,
38
38
  AWSBedrockStream: () => AWSBedrockStream,
39
39
  AnthropicStream: () => AnthropicStream,
40
- COMPLEX_HEADER: () => COMPLEX_HEADER,
40
+ AssistantResponse: () => AssistantResponse,
41
41
  CohereStream: () => CohereStream,
42
42
  GenerateObjectResult: () => GenerateObjectResult,
43
43
  GenerateTextResult: () => GenerateTextResult,
@@ -48,6 +48,7 @@ __export(streams_exports, {
48
48
  MistralStream: () => MistralStream,
49
49
  OpenAIStream: () => OpenAIStream,
50
50
  ReplicateStream: () => ReplicateStream,
51
+ StreamData: () => StreamData,
51
52
  StreamObjectResult: () => StreamObjectResult,
52
53
  StreamTextResult: () => StreamTextResult,
53
54
  StreamingTextResponse: () => StreamingTextResponse,
@@ -74,118 +75,8 @@ __export(streams_exports, {
74
75
  });
75
76
  module.exports = __toCommonJS(streams_exports);
76
77
 
77
- // spec/errors/api-call-error.ts
78
- var APICallError = class extends Error {
79
- constructor({
80
- message,
81
- url,
82
- requestBodyValues,
83
- statusCode,
84
- responseBody,
85
- cause,
86
- isRetryable = statusCode != null && (statusCode === 408 || // request timeout
87
- statusCode === 409 || // conflict
88
- statusCode === 429 || // too many requests
89
- statusCode >= 500),
90
- // server error
91
- data
92
- }) {
93
- super(message);
94
- this.name = "AI_APICallError";
95
- this.url = url;
96
- this.requestBodyValues = requestBodyValues;
97
- this.statusCode = statusCode;
98
- this.responseBody = responseBody;
99
- this.cause = cause;
100
- this.isRetryable = isRetryable;
101
- this.data = data;
102
- }
103
- static isAPICallError(error) {
104
- return error instanceof Error && error.name === "AI_APICallError" && typeof error.url === "string" && typeof error.requestBodyValues === "object" && (error.statusCode == null || typeof error.statusCode === "number") && (error.responseBody == null || typeof error.responseBody === "string") && (error.cause == null || typeof error.cause === "object") && typeof error.isRetryable === "boolean" && (error.data == null || typeof error.data === "object");
105
- }
106
- toJSON() {
107
- return {
108
- name: this.name,
109
- message: this.message,
110
- url: this.url,
111
- requestBodyValues: this.requestBodyValues,
112
- statusCode: this.statusCode,
113
- responseBody: this.responseBody,
114
- cause: this.cause,
115
- isRetryable: this.isRetryable,
116
- data: this.data
117
- };
118
- }
119
- };
120
-
121
- // spec/errors/invalid-argument-error.ts
122
- var InvalidArgumentError = class extends Error {
123
- constructor({
124
- parameter,
125
- value,
126
- message
127
- }) {
128
- super(`Invalid argument for parameter ${parameter}: ${message}`);
129
- this.name = "AI_InvalidArgumentError";
130
- this.parameter = parameter;
131
- this.value = value;
132
- }
133
- static isInvalidArgumentError(error) {
134
- return error instanceof Error && error.name === "AI_InvalidArgumentError" && typeof error.parameter === "string" && typeof error.value === "string";
135
- }
136
- toJSON() {
137
- return {
138
- name: this.name,
139
- message: this.message,
140
- stack: this.stack,
141
- parameter: this.parameter,
142
- value: this.value
143
- };
144
- }
145
- };
146
-
147
- // spec/errors/invalid-data-content-error.ts
148
- var InvalidDataContentError = class extends Error {
149
- constructor({
150
- content,
151
- message = `Invalid data content. Expected a string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
152
- }) {
153
- super(message);
154
- this.name = "AI_InvalidDataContentError";
155
- this.content = content;
156
- }
157
- static isInvalidDataContentError(error) {
158
- return error instanceof Error && error.name === "AI_InvalidDataContentError" && error.content != null;
159
- }
160
- toJSON() {
161
- return {
162
- name: this.name,
163
- message: this.message,
164
- stack: this.stack,
165
- content: this.content
166
- };
167
- }
168
- };
169
-
170
- // spec/errors/invalid-prompt-error.ts
171
- var InvalidPromptError = class extends Error {
172
- constructor({ prompt: prompt2, message }) {
173
- super(`Invalid prompt: ${message}`);
174
- this.name = "AI_InvalidPromptError";
175
- this.prompt = prompt2;
176
- }
177
- static isInvalidPromptError(error) {
178
- return error instanceof Error && error.name === "AI_InvalidPromptError" && prompt != null;
179
- }
180
- toJSON() {
181
- return {
182
- name: this.name,
183
- message: this.message,
184
- stack: this.stack,
185
- prompt: this.prompt
186
- };
187
- }
188
- };
78
+ // core/generate-object/generate-object.ts
79
+ var import_provider7 = require("@ai-sdk/provider");
189
80
 
190
81
  // spec/util/get-error-message.ts
191
82
  function getErrorMessage(error) {
@@ -202,59 +93,11 @@ function getErrorMessage(error) {
202
93
  }
203
94
 
204
95
  // spec/util/parse-json.ts
96
+ var import_provider2 = require("@ai-sdk/provider");
205
97
  var import_secure_json_parse = __toESM(require("secure-json-parse"));
206
98
 
207
- // spec/errors/json-parse-error.ts
208
- var JSONParseError = class extends Error {
209
- constructor({ text, cause }) {
210
- super(
211
- `JSON parsing failed: Text: ${text}.
212
- Error message: ${getErrorMessage(cause)}`
213
- );
214
- this.name = "AI_JSONParseError";
215
- this.cause = cause;
216
- this.text = text;
217
- }
218
- static isJSONParseError(error) {
219
- return error instanceof Error && error.name === "AI_JSONParseError" && typeof error.text === "string" && typeof error.cause === "string";
220
- }
221
- toJSON() {
222
- return {
223
- name: this.name,
224
- message: this.message,
225
- cause: this.cause,
226
- stack: this.stack,
227
- valueText: this.text
228
- };
229
- }
230
- };
231
-
232
- // spec/errors/type-validation-error.ts
233
- var TypeValidationError = class extends Error {
234
- constructor({ value, cause }) {
235
- super(
236
- `Type validation failed: Value: ${JSON.stringify(value)}.
237
- Error message: ${getErrorMessage(cause)}`
238
- );
239
- this.name = "AI_TypeValidationError";
240
- this.cause = cause;
241
- this.value = value;
242
- }
243
- static isTypeValidationError(error) {
244
- return error instanceof Error && error.name === "AI_TypeValidationError" && typeof error.value === "string" && typeof error.cause === "string";
245
- }
246
- toJSON() {
247
- return {
248
- name: this.name,
249
- message: this.message,
250
- cause: this.cause,
251
- stack: this.stack,
252
- value: this.value
253
- };
254
- }
255
- };
256
-
257
99
  // spec/util/validate-types.ts
100
+ var import_provider = require("@ai-sdk/provider");
258
101
  function safeValidateTypes({
259
102
  value,
260
103
  schema
@@ -269,7 +112,7 @@ function safeValidateTypes({
269
112
  }
270
113
  return {
271
114
  success: false,
272
- error: new TypeValidationError({
115
+ error: new import_provider.TypeValidationError({
273
116
  value,
274
117
  cause: validationResult.error
275
118
  })
@@ -277,7 +120,7 @@ function safeValidateTypes({
277
120
  } catch (error) {
278
121
  return {
279
122
  success: false,
280
- error: TypeValidationError.isTypeValidationError(error) ? error : new TypeValidationError({ value, cause: error })
123
+ error: import_provider.TypeValidationError.isTypeValidationError(error) ? error : new import_provider.TypeValidationError({ value, cause: error })
281
124
  };
282
125
  }
283
126
  }
@@ -299,7 +142,7 @@ function safeParseJSON({
299
142
  } catch (error) {
300
143
  return {
301
144
  success: false,
302
- error: JSONParseError.isJSONParseError(error) ? error : new JSONParseError({ text, cause: error })
145
+ error: import_provider2.JSONParseError.isJSONParseError(error) ? error : new import_provider2.JSONParseError({ text, cause: error })
303
146
  };
304
147
  }
305
148
  }
@@ -318,109 +161,6 @@ function convertUint8ArrayToBase64(array) {
318
161
  return globalThis.btoa(latin1string);
319
162
  }
320
163
 
321
- // spec/errors/invalid-tool-arguments-error.ts
322
- var InvalidToolArgumentsError = class extends Error {
323
- constructor({
324
- toolArgs,
325
- toolName,
326
- cause,
327
- message = `Invalid arguments for tool ${toolName}: ${getErrorMessage(
328
- cause
329
- )}`
330
- }) {
331
- super(message);
332
- this.name = "AI_InvalidToolArgumentsError";
333
- this.toolArgs = toolArgs;
334
- this.toolName = toolName;
335
- this.cause = cause;
336
- }
337
- static isInvalidToolArgumentsError(error) {
338
- return error instanceof Error && error.name === "AI_InvalidToolArgumentsError" && typeof error.toolName === "string" && typeof error.toolArgs === "string";
339
- }
340
- toJSON() {
341
- return {
342
- name: this.name,
343
- message: this.message,
344
- cause: this.cause,
345
- stack: this.stack,
346
- toolName: this.toolName,
347
- toolArgs: this.toolArgs
348
- };
349
- }
350
- };
351
-
352
- // spec/errors/no-object-generated-error.ts
353
- var NoTextGeneratedError = class extends Error {
354
- constructor() {
355
- super(`No text generated.`);
356
- this.name = "AI_NoTextGeneratedError";
357
- }
358
- static isNoTextGeneratedError(error) {
359
- return error instanceof Error && error.name === "AI_NoTextGeneratedError";
360
- }
361
- toJSON() {
362
- return {
363
- name: this.name,
364
- cause: this.cause,
365
- message: this.message,
366
- stack: this.stack
367
- };
368
- }
369
- };
370
-
371
- // spec/errors/no-such-tool-error.ts
372
- var NoSuchToolError = class extends Error {
373
- constructor({
374
- toolName,
375
- availableTools = void 0,
376
- message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
377
- }) {
378
- super(message);
379
- this.name = "AI_NoSuchToolError";
380
- this.toolName = toolName;
381
- this.availableTools = availableTools;
382
- }
383
- static isNoSuchToolError(error) {
384
- return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
385
- }
386
- toJSON() {
387
- return {
388
- name: this.name,
389
- message: this.message,
390
- stack: this.stack,
391
- toolName: this.toolName,
392
- availableTools: this.availableTools
393
- };
394
- }
395
- };
396
-
397
- // spec/errors/retry-error.ts
398
- var RetryError = class extends Error {
399
- constructor({
400
- message,
401
- reason,
402
- errors
403
- }) {
404
- super(message);
405
- this.name = "AI_RetryError";
406
- this.reason = reason;
407
- this.errors = errors;
408
- this.lastError = errors[errors.length - 1];
409
- }
410
- static isRetryError(error) {
411
- return error instanceof Error && error.name === "AI_RetryError" && typeof error.reason === "string" && Array.isArray(error.errors);
412
- }
413
- toJSON() {
414
- return {
415
- name: this.name,
416
- message: this.message,
417
- reason: this.reason,
418
- lastError: this.lastError,
419
- errors: this.errors
420
- };
421
- }
422
- };
423
-
424
164
  // core/generate-text/token-usage.ts
425
165
  function calculateTokenUsage(usage) {
426
166
  return {
@@ -447,6 +187,7 @@ function detectImageMimeType(image) {
447
187
  }
448
188
 
449
189
  // core/prompt/data-content.ts
190
+ var import_provider3 = require("@ai-sdk/provider");
450
191
  function convertDataContentToBase64String(content) {
451
192
  if (typeof content === "string") {
452
193
  return content;
@@ -466,26 +207,26 @@ function convertDataContentToUint8Array(content) {
466
207
  if (content instanceof ArrayBuffer) {
467
208
  return new Uint8Array(content);
468
209
  }
469
- throw new InvalidDataContentError({ content });
210
+ throw new import_provider3.InvalidDataContentError({ content });
470
211
  }
471
212
 
472
213
  // core/prompt/convert-to-language-model-prompt.ts
473
- function convertToLanguageModelPrompt(prompt2) {
214
+ function convertToLanguageModelPrompt(prompt) {
474
215
  const languageModelMessages = [];
475
- if (prompt2.system != null) {
476
- languageModelMessages.push({ role: "system", content: prompt2.system });
216
+ if (prompt.system != null) {
217
+ languageModelMessages.push({ role: "system", content: prompt.system });
477
218
  }
478
- switch (prompt2.type) {
219
+ switch (prompt.type) {
479
220
  case "prompt": {
480
221
  languageModelMessages.push({
481
222
  role: "user",
482
- content: [{ type: "text", text: prompt2.prompt }]
223
+ content: [{ type: "text", text: prompt.prompt }]
483
224
  });
484
225
  break;
485
226
  }
486
227
  case "messages": {
487
228
  languageModelMessages.push(
488
- ...prompt2.messages.map((message) => {
229
+ ...prompt.messages.map((message) => {
489
230
  switch (message.role) {
490
231
  case "user": {
491
232
  if (typeof message.content === "string") {
@@ -543,7 +284,7 @@ function convertToLanguageModelPrompt(prompt2) {
543
284
  break;
544
285
  }
545
286
  default: {
546
- const _exhaustiveCheck = prompt2;
287
+ const _exhaustiveCheck = prompt;
547
288
  throw new Error(`Unsupported prompt type: ${_exhaustiveCheck}`);
548
289
  }
549
290
  }
@@ -551,34 +292,36 @@ function convertToLanguageModelPrompt(prompt2) {
551
292
  }
552
293
 
553
294
  // core/prompt/get-validated-prompt.ts
554
- function getValidatedPrompt(prompt2) {
555
- if (prompt2.prompt == null && prompt2.messages == null) {
556
- throw new InvalidPromptError({
557
- prompt: prompt2,
295
+ var import_provider4 = require("@ai-sdk/provider");
296
+ function getValidatedPrompt(prompt) {
297
+ if (prompt.prompt == null && prompt.messages == null) {
298
+ throw new import_provider4.InvalidPromptError({
299
+ prompt,
558
300
  message: "prompt or messages must be defined"
559
301
  });
560
302
  }
561
- if (prompt2.prompt != null && prompt2.messages != null) {
562
- throw new InvalidPromptError({
563
- prompt: prompt2,
303
+ if (prompt.prompt != null && prompt.messages != null) {
304
+ throw new import_provider4.InvalidPromptError({
305
+ prompt,
564
306
  message: "prompt and messages cannot be defined at the same time"
565
307
  });
566
308
  }
567
- return prompt2.prompt != null ? {
309
+ return prompt.prompt != null ? {
568
310
  type: "prompt",
569
- prompt: prompt2.prompt,
311
+ prompt: prompt.prompt,
570
312
  messages: void 0,
571
- system: prompt2.system
313
+ system: prompt.system
572
314
  } : {
573
315
  type: "messages",
574
316
  prompt: void 0,
575
- messages: prompt2.messages,
317
+ messages: prompt.messages,
576
318
  // only possible case bc of checks above
577
- system: prompt2.system
319
+ system: prompt.system
578
320
  };
579
321
  }
580
322
 
581
323
  // core/prompt/prepare-call-settings.ts
324
+ var import_provider5 = require("@ai-sdk/provider");
582
325
  function prepareCallSettings({
583
326
  maxTokens,
584
327
  temperature,
@@ -590,14 +333,14 @@ function prepareCallSettings({
590
333
  }) {
591
334
  if (maxTokens != null) {
592
335
  if (!Number.isInteger(maxTokens)) {
593
- throw new InvalidArgumentError({
336
+ throw new import_provider5.InvalidArgumentError({
594
337
  parameter: "maxTokens",
595
338
  value: maxTokens,
596
339
  message: "maxTokens must be an integer"
597
340
  });
598
341
  }
599
342
  if (maxTokens < 1) {
600
- throw new InvalidArgumentError({
343
+ throw new import_provider5.InvalidArgumentError({
601
344
  parameter: "maxTokens",
602
345
  value: maxTokens,
603
346
  message: "maxTokens must be >= 1"
@@ -606,14 +349,14 @@ function prepareCallSettings({
606
349
  }
607
350
  if (temperature != null) {
608
351
  if (typeof temperature !== "number") {
609
- throw new InvalidArgumentError({
352
+ throw new import_provider5.InvalidArgumentError({
610
353
  parameter: "temperature",
611
354
  value: temperature,
612
355
  message: "temperature must be a number"
613
356
  });
614
357
  }
615
358
  if (temperature < 0 || temperature > 1) {
616
- throw new InvalidArgumentError({
359
+ throw new import_provider5.InvalidArgumentError({
617
360
  parameter: "temperature",
618
361
  value: temperature,
619
362
  message: "temperature must be between 0 and 1 (inclusive)"
@@ -622,14 +365,14 @@ function prepareCallSettings({
622
365
  }
623
366
  if (topP != null) {
624
367
  if (typeof topP !== "number") {
625
- throw new InvalidArgumentError({
368
+ throw new import_provider5.InvalidArgumentError({
626
369
  parameter: "topP",
627
370
  value: topP,
628
371
  message: "topP must be a number"
629
372
  });
630
373
  }
631
374
  if (topP < 0 || topP > 1) {
632
- throw new InvalidArgumentError({
375
+ throw new import_provider5.InvalidArgumentError({
633
376
  parameter: "topP",
634
377
  value: topP,
635
378
  message: "topP must be between 0 and 1 (inclusive)"
@@ -638,14 +381,14 @@ function prepareCallSettings({
638
381
  }
639
382
  if (presencePenalty != null) {
640
383
  if (typeof presencePenalty !== "number") {
641
- throw new InvalidArgumentError({
384
+ throw new import_provider5.InvalidArgumentError({
642
385
  parameter: "presencePenalty",
643
386
  value: presencePenalty,
644
387
  message: "presencePenalty must be a number"
645
388
  });
646
389
  }
647
390
  if (presencePenalty < -1 || presencePenalty > 1) {
648
- throw new InvalidArgumentError({
391
+ throw new import_provider5.InvalidArgumentError({
649
392
  parameter: "presencePenalty",
650
393
  value: presencePenalty,
651
394
  message: "presencePenalty must be between -1 and 1 (inclusive)"
@@ -654,14 +397,14 @@ function prepareCallSettings({
654
397
  }
655
398
  if (frequencyPenalty != null) {
656
399
  if (typeof frequencyPenalty !== "number") {
657
- throw new InvalidArgumentError({
400
+ throw new import_provider5.InvalidArgumentError({
658
401
  parameter: "frequencyPenalty",
659
402
  value: frequencyPenalty,
660
403
  message: "frequencyPenalty must be a number"
661
404
  });
662
405
  }
663
406
  if (frequencyPenalty < -1 || frequencyPenalty > 1) {
664
- throw new InvalidArgumentError({
407
+ throw new import_provider5.InvalidArgumentError({
665
408
  parameter: "frequencyPenalty",
666
409
  value: frequencyPenalty,
667
410
  message: "frequencyPenalty must be between -1 and 1 (inclusive)"
@@ -670,7 +413,7 @@ function prepareCallSettings({
670
413
  }
671
414
  if (seed != null) {
672
415
  if (!Number.isInteger(seed)) {
673
- throw new InvalidArgumentError({
416
+ throw new import_provider5.InvalidArgumentError({
674
417
  parameter: "seed",
675
418
  value: seed,
676
419
  message: "seed must be an integer"
@@ -679,14 +422,14 @@ function prepareCallSettings({
679
422
  }
680
423
  if (maxRetries != null) {
681
424
  if (!Number.isInteger(maxRetries)) {
682
- throw new InvalidArgumentError({
425
+ throw new import_provider5.InvalidArgumentError({
683
426
  parameter: "maxRetries",
684
427
  value: maxRetries,
685
428
  message: "maxRetries must be an integer"
686
429
  });
687
430
  }
688
431
  if (maxRetries < 0) {
689
- throw new InvalidArgumentError({
432
+ throw new import_provider5.InvalidArgumentError({
690
433
  parameter: "maxRetries",
691
434
  value: maxRetries,
692
435
  message: "maxRetries must be >= 0"
@@ -710,6 +453,9 @@ function convertZodToJSONSchema(zodSchema) {
710
453
  return (0, import_zod_to_json_schema.default)(zodSchema);
711
454
  }
712
455
 
456
+ // core/util/retry-with-exponential-backoff.ts
457
+ var import_provider6 = require("@ai-sdk/provider");
458
+
713
459
  // core/util/delay.ts
714
460
  async function delay(delayInMs) {
715
461
  return new Promise((resolve) => setTimeout(resolve, delayInMs));
@@ -743,13 +489,13 @@ async function _retryWithExponentialBackoff(f, {
743
489
  const newErrors = [...errors, error];
744
490
  const tryNumber = newErrors.length;
745
491
  if (tryNumber > maxRetries) {
746
- throw new RetryError({
492
+ throw new import_provider6.RetryError({
747
493
  message: `Failed after ${tryNumber} attemps. Last error: ${errorMessage}`,
748
494
  reason: "maxRetriesExceeded",
749
495
  errors: newErrors
750
496
  });
751
497
  }
752
- if (error instanceof Error && APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
498
+ if (error instanceof Error && import_provider6.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
753
499
  await delay(delayInMs);
754
500
  return _retryWithExponentialBackoff(
755
501
  f,
@@ -760,7 +506,7 @@ async function _retryWithExponentialBackoff(f, {
760
506
  if (tryNumber === 1) {
761
507
  throw error;
762
508
  }
763
- throw new RetryError({
509
+ throw new import_provider6.RetryError({
764
510
  message: `Failed after ${tryNumber} attemps with non-retryable error: '${errorMessage}'`,
765
511
  reason: "errorNotRetryable",
766
512
  errors: newErrors
@@ -793,7 +539,7 @@ async function experimental_generateObject({
793
539
  schema,
794
540
  mode,
795
541
  system,
796
- prompt: prompt2,
542
+ prompt,
797
543
  messages,
798
544
  maxRetries,
799
545
  abortSignal,
@@ -813,7 +559,7 @@ async function experimental_generateObject({
813
559
  case "json": {
814
560
  const validatedPrompt = getValidatedPrompt({
815
561
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
816
- prompt: prompt2,
562
+ prompt,
817
563
  messages
818
564
  });
819
565
  const generateResult = await retry(() => {
@@ -826,7 +572,7 @@ async function experimental_generateObject({
826
572
  });
827
573
  });
828
574
  if (generateResult.text === void 0) {
829
- throw new NoTextGeneratedError();
575
+ throw new import_provider7.NoTextGeneratedError();
830
576
  }
831
577
  result = generateResult.text;
832
578
  finishReason = generateResult.finishReason;
@@ -837,7 +583,7 @@ async function experimental_generateObject({
837
583
  case "grammar": {
838
584
  const validatedPrompt = getValidatedPrompt({
839
585
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
840
- prompt: prompt2,
586
+ prompt,
841
587
  messages
842
588
  });
843
589
  const generateResult = await retry(
@@ -850,7 +596,7 @@ async function experimental_generateObject({
850
596
  })
851
597
  );
852
598
  if (generateResult.text === void 0) {
853
- throw new NoTextGeneratedError();
599
+ throw new import_provider7.NoTextGeneratedError();
854
600
  }
855
601
  result = generateResult.text;
856
602
  finishReason = generateResult.finishReason;
@@ -861,7 +607,7 @@ async function experimental_generateObject({
861
607
  case "tool": {
862
608
  const validatedPrompt = getValidatedPrompt({
863
609
  system,
864
- prompt: prompt2,
610
+ prompt,
865
611
  messages
866
612
  });
867
613
  const generateResult = await retry(
@@ -883,7 +629,7 @@ async function experimental_generateObject({
883
629
  );
884
630
  const functionArgs = (_b = (_a = generateResult.toolCalls) == null ? void 0 : _a[0]) == null ? void 0 : _b.args;
885
631
  if (functionArgs === void 0) {
886
- throw new NoTextGeneratedError();
632
+ throw new import_provider7.NoTextGeneratedError();
887
633
  }
888
634
  result = functionArgs;
889
635
  finishReason = generateResult.finishReason;
@@ -1314,7 +1060,7 @@ async function experimental_streamObject({
1314
1060
  schema,
1315
1061
  mode,
1316
1062
  system,
1317
- prompt: prompt2,
1063
+ prompt,
1318
1064
  messages,
1319
1065
  maxRetries,
1320
1066
  abortSignal,
@@ -1331,7 +1077,7 @@ async function experimental_streamObject({
1331
1077
  case "json": {
1332
1078
  const validatedPrompt = getValidatedPrompt({
1333
1079
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
1334
- prompt: prompt2,
1080
+ prompt,
1335
1081
  messages
1336
1082
  });
1337
1083
  callOptions = {
@@ -1358,7 +1104,7 @@ async function experimental_streamObject({
1358
1104
  case "grammar": {
1359
1105
  const validatedPrompt = getValidatedPrompt({
1360
1106
  system: injectJsonSchemaIntoSystem({ system, schema: jsonSchema }),
1361
- prompt: prompt2,
1107
+ prompt,
1362
1108
  messages
1363
1109
  });
1364
1110
  callOptions = {
@@ -1385,7 +1131,7 @@ async function experimental_streamObject({
1385
1131
  case "tool": {
1386
1132
  const validatedPrompt = getValidatedPrompt({
1387
1133
  system,
1388
- prompt: prompt2,
1134
+ prompt,
1389
1135
  messages
1390
1136
  });
1391
1137
  callOptions = {
@@ -1463,17 +1209,18 @@ var StreamObjectResult = class {
1463
1209
  };
1464
1210
 
1465
1211
  // core/generate-text/tool-call.ts
1212
+ var import_provider8 = require("@ai-sdk/provider");
1466
1213
  function parseToolCall({
1467
1214
  toolCall,
1468
1215
  tools
1469
1216
  }) {
1470
1217
  const toolName = toolCall.toolName;
1471
1218
  if (tools == null) {
1472
- throw new NoSuchToolError({ toolName: toolCall.toolName });
1219
+ throw new import_provider8.NoSuchToolError({ toolName: toolCall.toolName });
1473
1220
  }
1474
1221
  const tool2 = tools[toolName];
1475
1222
  if (tool2 == null) {
1476
- throw new NoSuchToolError({
1223
+ throw new import_provider8.NoSuchToolError({
1477
1224
  toolName: toolCall.toolName,
1478
1225
  availableTools: Object.keys(tools)
1479
1226
  });
@@ -1483,7 +1230,7 @@ function parseToolCall({
1483
1230
  schema: tool2.parameters
1484
1231
  });
1485
1232
  if (parseResult.success === false) {
1486
- throw new InvalidToolArgumentsError({
1233
+ throw new import_provider8.InvalidToolArgumentsError({
1487
1234
  toolName,
1488
1235
  toolArgs: toolCall.args,
1489
1236
  cause: parseResult.error
@@ -1502,7 +1249,7 @@ async function experimental_generateText({
1502
1249
  model,
1503
1250
  tools,
1504
1251
  system,
1505
- prompt: prompt2,
1252
+ prompt,
1506
1253
  messages,
1507
1254
  maxRetries,
1508
1255
  abortSignal,
@@ -1510,7 +1257,7 @@ async function experimental_generateText({
1510
1257
  }) {
1511
1258
  var _a, _b;
1512
1259
  const retry = retryWithExponentialBackoff({ maxRetries });
1513
- const validatedPrompt = getValidatedPrompt({ system, prompt: prompt2, messages });
1260
+ const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
1514
1261
  const modelResponse = await retry(() => {
1515
1262
  return model.doGenerate({
1516
1263
  mode: {
@@ -1579,6 +1326,9 @@ var GenerateTextResult = class {
1579
1326
  }
1580
1327
  };
1581
1328
 
1329
+ // core/generate-text/run-tools-transformation.ts
1330
+ var import_provider9 = require("@ai-sdk/provider");
1331
+
1582
1332
  // shared/generate-id.ts
1583
1333
  var import_non_secure = require("nanoid/non-secure");
1584
1334
  var generateId = (0, import_non_secure.customAlphabet)(
@@ -1613,7 +1363,7 @@ function runToolsTransformation({
1613
1363
  if (tools == null) {
1614
1364
  toolResultsStreamController.enqueue({
1615
1365
  type: "error",
1616
- error: new NoSuchToolError({ toolName: chunk.toolName })
1366
+ error: new import_provider9.NoSuchToolError({ toolName: chunk.toolName })
1617
1367
  });
1618
1368
  break;
1619
1369
  }
@@ -1621,7 +1371,7 @@ function runToolsTransformation({
1621
1371
  if (tool2 == null) {
1622
1372
  toolResultsStreamController.enqueue({
1623
1373
  type: "error",
1624
- error: new NoSuchToolError({
1374
+ error: new import_provider9.NoSuchToolError({
1625
1375
  toolName: chunk.toolName,
1626
1376
  availableTools: Object.keys(tools)
1627
1377
  })
@@ -1727,14 +1477,14 @@ async function experimental_streamText({
1727
1477
  model,
1728
1478
  tools,
1729
1479
  system,
1730
- prompt: prompt2,
1480
+ prompt,
1731
1481
  messages,
1732
1482
  maxRetries,
1733
1483
  abortSignal,
1734
1484
  ...settings
1735
1485
  }) {
1736
1486
  const retry = retryWithExponentialBackoff({ maxRetries });
1737
- const validatedPrompt = getValidatedPrompt({ system, prompt: prompt2, messages });
1487
+ const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
1738
1488
  const { stream, warnings } = await retry(
1739
1489
  () => model.doStream({
1740
1490
  mode: {
@@ -1815,8 +1565,31 @@ var StreamTextResult = class {
1815
1565
  @returns an `AIStream` object.
1816
1566
  */
1817
1567
  toAIStream(callbacks) {
1818
- return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
1819
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
1568
+ return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
1569
+ }
1570
+ /**
1571
+ Creates a simple text stream response.
1572
+ Each text delta is encoded as UTF-8 and sent as a separate chunk.
1573
+ Non-text-delta events are ignored.
1574
+ */
1575
+ toTextStreamResponse(init) {
1576
+ const encoder = new TextEncoder();
1577
+ return new Response(
1578
+ this.textStream.pipeThrough(
1579
+ new TransformStream({
1580
+ transform(chunk, controller) {
1581
+ controller.enqueue(encoder.encode(chunk));
1582
+ }
1583
+ })
1584
+ ),
1585
+ {
1586
+ ...init,
1587
+ status: 200,
1588
+ headers: {
1589
+ "Content-Type": "text/plain; charset=utf-8",
1590
+ ...init == null ? void 0 : init.headers
1591
+ }
1592
+ }
1820
1593
  );
1821
1594
  }
1822
1595
  };
@@ -2022,7 +1795,6 @@ function createChunkDecoder(complex) {
2022
1795
  };
2023
1796
  }
2024
1797
  var isStreamStringEqualToType = (type, value) => value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
2025
- var COMPLEX_HEADER = "X-Experimental-Stream-Data";
2026
1798
 
2027
1799
  // streams/ai-stream.ts
2028
1800
  var import_eventsource_parser = require("eventsource-parser");
@@ -2147,7 +1919,7 @@ function readableFromAsyncIterable(iterable) {
2147
1919
  }
2148
1920
 
2149
1921
  // streams/stream-data.ts
2150
- var experimental_StreamData = class {
1922
+ var StreamData = class {
2151
1923
  constructor() {
2152
1924
  this.encoder = new TextEncoder();
2153
1925
  this.controller = null;
@@ -2233,14 +2005,7 @@ var experimental_StreamData = class {
2233
2005
  this.messageAnnotations.push(value);
2234
2006
  }
2235
2007
  };
2236
- function createStreamDataTransformer(experimental_streamData) {
2237
- if (!experimental_streamData) {
2238
- return new TransformStream({
2239
- transform: async (chunk, controller) => {
2240
- controller.enqueue(chunk);
2241
- }
2242
- });
2243
- }
2008
+ function createStreamDataTransformer() {
2244
2009
  const encoder = new TextEncoder();
2245
2010
  const decoder = new TextDecoder();
2246
2011
  return new TransformStream({
@@ -2250,6 +2015,8 @@ function createStreamDataTransformer(experimental_streamData) {
2250
2015
  }
2251
2016
  });
2252
2017
  }
2018
+ var experimental_StreamData = class extends StreamData {
2019
+ };
2253
2020
 
2254
2021
  // streams/anthropic-stream.ts
2255
2022
  function parseAnthropicStream() {
@@ -2289,16 +2056,16 @@ async function* streamable(stream) {
2289
2056
  }
2290
2057
  function AnthropicStream(res, cb) {
2291
2058
  if (Symbol.asyncIterator in res) {
2292
- return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData));
2059
+ return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
2293
2060
  } else {
2294
2061
  return AIStream(res, parseAnthropicStream(), cb).pipeThrough(
2295
- createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
2062
+ createStreamDataTransformer()
2296
2063
  );
2297
2064
  }
2298
2065
  }
2299
2066
 
2300
2067
  // streams/assistant-response.ts
2301
- function experimental_AssistantResponse({ threadId, messageId }, process2) {
2068
+ function AssistantResponse({ threadId, messageId }, process2) {
2302
2069
  const stream = new ReadableStream({
2303
2070
  async start(controller) {
2304
2071
  var _a;
@@ -2389,6 +2156,7 @@ function experimental_AssistantResponse({ threadId, messageId }, process2) {
2389
2156
  }
2390
2157
  });
2391
2158
  }
2159
+ var experimental_AssistantResponse = AssistantResponse;
2392
2160
 
2393
2161
  // streams/aws-bedrock-stream.ts
2394
2162
  async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
@@ -2416,16 +2184,7 @@ function AWSBedrockAnthropicStream(response, callbacks) {
2416
2184
  return AWSBedrockStream(response, callbacks, (chunk) => chunk.completion);
2417
2185
  }
2418
2186
  function AWSBedrockCohereStream(response, callbacks) {
2419
- return AWSBedrockStream(
2420
- response,
2421
- callbacks,
2422
- // As of 2023-11-17, Bedrock does not support streaming for Cohere,
2423
- // so we take the full generation:
2424
- (chunk) => {
2425
- var _a, _b;
2426
- return (_b = (_a = chunk.generations) == null ? void 0 : _a[0]) == null ? void 0 : _b.text;
2427
- }
2428
- );
2187
+ return AWSBedrockStream(response, callbacks, (chunk) => chunk == null ? void 0 : chunk.text);
2429
2188
  }
2430
2189
  function AWSBedrockLlama2Stream(response, callbacks) {
2431
2190
  return AWSBedrockStream(response, callbacks, (chunk) => chunk.generation);
@@ -2433,9 +2192,7 @@ function AWSBedrockLlama2Stream(response, callbacks) {
2433
2192
  function AWSBedrockStream(response, callbacks, extractTextDeltaFromChunk) {
2434
2193
  return readableFromAsyncIterable(
2435
2194
  asDeltaIterable(response, extractTextDeltaFromChunk)
2436
- ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2437
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2438
- );
2195
+ ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2439
2196
  }
2440
2197
 
2441
2198
  // streams/cohere-stream.ts
@@ -2490,13 +2247,9 @@ async function* streamable2(stream) {
2490
2247
  }
2491
2248
  function CohereStream(reader, callbacks) {
2492
2249
  if (Symbol.asyncIterator in reader) {
2493
- return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2494
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2495
- );
2250
+ return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2496
2251
  } else {
2497
- return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2498
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2499
- );
2252
+ return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2500
2253
  }
2501
2254
  }
2502
2255
 
@@ -2515,7 +2268,7 @@ async function* streamable3(response) {
2515
2268
  }
2516
2269
  }
2517
2270
  function GoogleGenerativeAIStream(response, cb) {
2518
- return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData));
2271
+ return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
2519
2272
  }
2520
2273
 
2521
2274
  // streams/huggingface-stream.ts
@@ -2543,9 +2296,7 @@ function createParser3(res) {
2543
2296
  });
2544
2297
  }
2545
2298
  function HuggingFaceStream(res, callbacks) {
2546
- return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2547
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2548
- );
2299
+ return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2549
2300
  }
2550
2301
 
2551
2302
  // streams/inkeep-stream.ts
@@ -2582,7 +2333,7 @@ function InkeepStream(res, callbacks) {
2582
2333
  }
2583
2334
  };
2584
2335
  return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
2585
- createStreamDataTransformer(passThroughCallbacks == null ? void 0 : passThroughCallbacks.experimental_streamData)
2336
+ createStreamDataTransformer()
2586
2337
  );
2587
2338
  }
2588
2339
 
@@ -2607,9 +2358,7 @@ function LangChainStream(callbacks) {
2607
2358
  }
2608
2359
  };
2609
2360
  return {
2610
- stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2611
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2612
- ),
2361
+ stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer()),
2613
2362
  writer,
2614
2363
  handlers: {
2615
2364
  handleLLMNewToken: async (token) => {
@@ -2660,9 +2409,7 @@ async function* streamable4(stream) {
2660
2409
  }
2661
2410
  function MistralStream(response, callbacks) {
2662
2411
  const stream = readableFromAsyncIterable(streamable4(response));
2663
- return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2664
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2665
- );
2412
+ return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2666
2413
  }
2667
2414
 
2668
2415
  // streams/openai-stream.ts
@@ -2806,9 +2553,7 @@ function OpenAIStream(res, callbacks) {
2806
2553
  const functionCallTransformer = createFunctionCallTransformer(cb);
2807
2554
  return stream.pipeThrough(functionCallTransformer);
2808
2555
  } else {
2809
- return stream.pipeThrough(
2810
- createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
2811
- );
2556
+ return stream.pipeThrough(createStreamDataTransformer());
2812
2557
  }
2813
2558
  }
2814
2559
  function createFunctionCallTransformer(callbacks) {
@@ -2818,7 +2563,6 @@ function createFunctionCallTransformer(callbacks) {
2818
2563
  let aggregatedFinalCompletionResponse = "";
2819
2564
  let isFunctionStreamingIn = false;
2820
2565
  let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
2821
- const isComplexMode = callbacks == null ? void 0 : callbacks.experimental_streamData;
2822
2566
  const decode = createChunkDecoder();
2823
2567
  return new TransformStream({
2824
2568
  async transform(chunk, controller) {
@@ -2833,7 +2577,7 @@ function createFunctionCallTransformer(callbacks) {
2833
2577
  }
2834
2578
  if (!isFunctionStreamingIn) {
2835
2579
  controller.enqueue(
2836
- isComplexMode ? textEncoder.encode(formatStreamPart("text", message)) : chunk
2580
+ textEncoder.encode(formatStreamPart("text", message))
2837
2581
  );
2838
2582
  return;
2839
2583
  } else {
@@ -2944,17 +2688,17 @@ function createFunctionCallTransformer(callbacks) {
2944
2688
  if (!functionResponse) {
2945
2689
  controller.enqueue(
2946
2690
  textEncoder.encode(
2947
- isComplexMode ? formatStreamPart(
2691
+ formatStreamPart(
2948
2692
  payload.function_call ? "function_call" : "tool_calls",
2949
2693
  // parse to prevent double-encoding:
2950
2694
  JSON.parse(aggregatedResponse)
2951
- ) : aggregatedResponse
2695
+ )
2952
2696
  )
2953
2697
  );
2954
2698
  return;
2955
2699
  } else if (typeof functionResponse === "string") {
2956
2700
  controller.enqueue(
2957
- isComplexMode ? textEncoder.encode(formatStreamPart("text", functionResponse)) : textEncoder.encode(functionResponse)
2701
+ textEncoder.encode(formatStreamPart("text", functionResponse))
2958
2702
  );
2959
2703
  aggregatedFinalCompletionResponse = functionResponse;
2960
2704
  return;
@@ -3004,7 +2748,7 @@ async function ReplicateStream(res, cb, options) {
3004
2748
  }
3005
2749
  });
3006
2750
  return AIStream(eventStream, void 0, cb).pipeThrough(
3007
- createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
2751
+ createStreamDataTransformer()
3008
2752
  );
3009
2753
  }
3010
2754
 
@@ -3165,74 +2909,41 @@ async function parseComplexResponse({
3165
2909
  // streams/streaming-react-response.ts
3166
2910
  var experimental_StreamingReactResponse = class {
3167
2911
  constructor(res, options) {
3168
- var _a;
2912
+ var _a, _b;
3169
2913
  let resolveFunc = () => {
3170
2914
  };
3171
2915
  let next = new Promise((resolve) => {
3172
2916
  resolveFunc = resolve;
3173
2917
  });
3174
- if (options == null ? void 0 : options.data) {
3175
- const processedStream = res.pipeThrough(
3176
- options.data.stream
3177
- );
3178
- let lastPayload = void 0;
3179
- parseComplexResponse({
3180
- reader: processedStream.getReader(),
3181
- update: (merged, data) => {
3182
- var _a2, _b, _c;
3183
- const content2 = (_b = (_a2 = merged[0]) == null ? void 0 : _a2.content) != null ? _b : "";
3184
- const ui = ((_c = options == null ? void 0 : options.ui) == null ? void 0 : _c.call(options, { content: content2, data })) || content2;
3185
- const payload = { ui, content: content2 };
3186
- const resolvePrevious = resolveFunc;
3187
- const nextRow = new Promise((resolve) => {
3188
- resolveFunc = resolve;
3189
- });
3190
- resolvePrevious({
3191
- next: nextRow,
3192
- ...payload
2918
+ const processedStream = (options == null ? void 0 : options.data) != null ? res.pipeThrough((_a = options == null ? void 0 : options.data) == null ? void 0 : _a.stream) : res;
2919
+ let lastPayload = void 0;
2920
+ parseComplexResponse({
2921
+ reader: processedStream.getReader(),
2922
+ update: (merged, data) => {
2923
+ var _a2, _b2, _c;
2924
+ const content = (_b2 = (_a2 = merged[0]) == null ? void 0 : _a2.content) != null ? _b2 : "";
2925
+ const ui = ((_c = options == null ? void 0 : options.ui) == null ? void 0 : _c.call(options, { content, data })) || content;
2926
+ const payload = { ui, content };
2927
+ const resolvePrevious = resolveFunc;
2928
+ const nextRow = new Promise((resolve) => {
2929
+ resolveFunc = resolve;
2930
+ });
2931
+ resolvePrevious({
2932
+ next: nextRow,
2933
+ ...payload
2934
+ });
2935
+ lastPayload = payload;
2936
+ },
2937
+ generateId: (_b = options == null ? void 0 : options.generateId) != null ? _b : generateId,
2938
+ onFinish: () => {
2939
+ if (lastPayload !== void 0) {
2940
+ resolveFunc({
2941
+ next: null,
2942
+ ...lastPayload
3193
2943
  });
3194
- lastPayload = payload;
3195
- },
3196
- generateId: (_a = options.generateId) != null ? _a : generateId,
3197
- onFinish: () => {
3198
- if (lastPayload !== void 0) {
3199
- resolveFunc({
3200
- next: null,
3201
- ...lastPayload
3202
- });
3203
- }
3204
2944
  }
3205
- });
3206
- return next;
3207
- }
3208
- let content = "";
3209
- const decode = createChunkDecoder();
3210
- const reader = res.getReader();
3211
- async function readChunk() {
3212
- var _a2;
3213
- const { done, value } = await reader.read();
3214
- if (!done) {
3215
- content += decode(value);
3216
2945
  }
3217
- const ui = ((_a2 = options == null ? void 0 : options.ui) == null ? void 0 : _a2.call(options, { content })) || content;
3218
- const payload = {
3219
- ui,
3220
- content
3221
- };
3222
- const resolvePrevious = resolveFunc;
3223
- const nextRow = done ? null : new Promise((resolve) => {
3224
- resolveFunc = resolve;
3225
- });
3226
- resolvePrevious({
3227
- next: nextRow,
3228
- ...payload
3229
- });
3230
- if (done) {
3231
- return;
3232
- }
3233
- await readChunk();
3234
- }
3235
- readChunk();
2946
+ });
3236
2947
  return next;
3237
2948
  }
3238
2949
  };
@@ -3249,7 +2960,6 @@ var StreamingTextResponse = class extends Response {
3249
2960
  status: 200,
3250
2961
  headers: {
3251
2962
  "Content-Type": "text/plain; charset=utf-8",
3252
- [COMPLEX_HEADER]: data ? "true" : "false",
3253
2963
  ...init == null ? void 0 : init.headers
3254
2964
  }
3255
2965
  });
@@ -3282,7 +2992,7 @@ function streamToResponse(res, response, init) {
3282
2992
  AWSBedrockLlama2Stream,
3283
2993
  AWSBedrockStream,
3284
2994
  AnthropicStream,
3285
- COMPLEX_HEADER,
2995
+ AssistantResponse,
3286
2996
  CohereStream,
3287
2997
  GenerateObjectResult,
3288
2998
  GenerateTextResult,
@@ -3293,6 +3003,7 @@ function streamToResponse(res, response, init) {
3293
3003
  MistralStream,
3294
3004
  OpenAIStream,
3295
3005
  ReplicateStream,
3006
+ StreamData,
3296
3007
  StreamObjectResult,
3297
3008
  StreamTextResult,
3298
3009
  StreamingTextResponse,