ai 3.0.18 → 3.0.20

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 (61) hide show
  1. package/anthropic/dist/index.d.mts +66 -34
  2. package/anthropic/dist/index.d.ts +66 -34
  3. package/anthropic/dist/index.js +98 -94
  4. package/anthropic/dist/index.js.map +1 -1
  5. package/anthropic/dist/index.mjs +98 -94
  6. package/anthropic/dist/index.mjs.map +1 -1
  7. package/dist/index.d.mts +119 -45
  8. package/dist/index.d.ts +119 -45
  9. package/dist/index.js +83 -154
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +81 -153
  12. package/dist/index.mjs.map +1 -1
  13. package/google/dist/index.d.mts +65 -31
  14. package/google/dist/index.d.ts +65 -31
  15. package/google/dist/index.js +47 -43
  16. package/google/dist/index.js.map +1 -1
  17. package/google/dist/index.mjs +47 -43
  18. package/google/dist/index.mjs.map +1 -1
  19. package/mistral/dist/index.d.mts +65 -31
  20. package/mistral/dist/index.d.ts +65 -31
  21. package/mistral/dist/index.js +6 -21
  22. package/mistral/dist/index.js.map +1 -1
  23. package/mistral/dist/index.mjs +6 -21
  24. package/mistral/dist/index.mjs.map +1 -1
  25. package/openai/dist/index.d.mts +65 -31
  26. package/openai/dist/index.d.ts +65 -31
  27. package/openai/dist/index.js +9 -29
  28. package/openai/dist/index.js.map +1 -1
  29. package/openai/dist/index.mjs +9 -29
  30. package/openai/dist/index.mjs.map +1 -1
  31. package/package.json +5 -3
  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.js +19 -104
  45. package/solid/dist/index.js.map +1 -1
  46. package/solid/dist/index.mjs +19 -104
  47. package/solid/dist/index.mjs.map +1 -1
  48. package/spec/dist/index.d.mts +112 -40
  49. package/spec/dist/index.d.ts +112 -40
  50. package/spec/dist/index.js +71 -13
  51. package/spec/dist/index.js.map +1 -1
  52. package/spec/dist/index.mjs +69 -13
  53. package/spec/dist/index.mjs.map +1 -1
  54. package/svelte/dist/index.js +19 -104
  55. package/svelte/dist/index.js.map +1 -1
  56. package/svelte/dist/index.mjs +19 -104
  57. package/svelte/dist/index.mjs.map +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
package/dist/index.mjs CHANGED
@@ -1,6 +1,3 @@
1
- // core/generate-object/generate-object.ts
2
- import zodToJsonSchema from "zod-to-json-schema";
3
-
4
1
  // spec/errors/api-call-error.ts
5
2
  var APICallError = class extends Error {
6
3
  constructor({
@@ -297,20 +294,26 @@ var NoTextGeneratedError = class extends Error {
297
294
 
298
295
  // spec/errors/no-such-tool-error.ts
299
296
  var NoSuchToolError = class extends Error {
300
- constructor({ message, toolName }) {
297
+ constructor({
298
+ toolName,
299
+ availableTools = void 0,
300
+ message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
301
+ }) {
301
302
  super(message);
302
303
  this.name = "AI_NoSuchToolError";
303
304
  this.toolName = toolName;
305
+ this.availableTools = availableTools;
304
306
  }
305
307
  static isNoSuchToolError(error) {
306
- return error instanceof Error && error.name === "AI_NoSuchToolError" && typeof error.toolName === "string";
308
+ return error instanceof Error && error.name === "AI_NoSuchToolError" && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
307
309
  }
308
310
  toJSON() {
309
311
  return {
310
312
  name: this.name,
311
313
  message: this.message,
312
314
  stack: this.stack,
313
- toolName: this.toolName
315
+ toolName: this.toolName,
316
+ availableTools: this.availableTools
314
317
  };
315
318
  }
316
319
  };
@@ -625,6 +628,12 @@ function prepareCallSettings({
625
628
  };
626
629
  }
627
630
 
631
+ // core/util/convert-zod-to-json-schema.ts
632
+ import zodToJsonSchema from "zod-to-json-schema";
633
+ function convertZodToJSONSchema(zodSchema) {
634
+ return zodToJsonSchema(zodSchema);
635
+ }
636
+
628
637
  // core/util/delay.ts
629
638
  async function delay(delayInMs) {
630
639
  return new Promise((resolve) => setTimeout(resolve, delayInMs));
@@ -716,7 +725,7 @@ async function experimental_generateObject({
716
725
  }) {
717
726
  var _a, _b;
718
727
  const retry = retryWithExponentialBackoff({ maxRetries });
719
- const jsonSchema = zodToJsonSchema(schema);
728
+ const jsonSchema = convertZodToJSONSchema(schema);
720
729
  if (mode === "auto" || mode == null) {
721
730
  mode = model.defaultObjectGenerationMode;
722
731
  }
@@ -834,9 +843,6 @@ var GenerateObjectResult = class {
834
843
  }
835
844
  };
836
845
 
837
- // core/generate-object/stream-object.ts
838
- import zodToJsonSchema2 from "zod-to-json-schema";
839
-
840
846
  // core/util/async-iterable-stream.ts
841
847
  function createAsyncIterableStream(source, transformer) {
842
848
  const transformedStream = source.pipeThrough(
@@ -1239,7 +1245,7 @@ async function experimental_streamObject({
1239
1245
  ...settings
1240
1246
  }) {
1241
1247
  const retry = retryWithExponentialBackoff({ maxRetries });
1242
- const jsonSchema = zodToJsonSchema2(schema);
1248
+ const jsonSchema = convertZodToJSONSchema(schema);
1243
1249
  if (mode === "auto" || mode == null) {
1244
1250
  mode = model.defaultObjectGenerationMode;
1245
1251
  }
@@ -1380,9 +1386,6 @@ var StreamObjectResult = class {
1380
1386
  }
1381
1387
  };
1382
1388
 
1383
- // core/generate-text/generate-text.ts
1384
- import zodToJsonSchema3 from "zod-to-json-schema";
1385
-
1386
1389
  // core/generate-text/tool-call.ts
1387
1390
  function parseToolCall({
1388
1391
  toolCall,
@@ -1390,16 +1393,13 @@ function parseToolCall({
1390
1393
  }) {
1391
1394
  const toolName = toolCall.toolName;
1392
1395
  if (tools == null) {
1393
- throw new NoSuchToolError({
1394
- message: `Tool ${toolCall.toolName} not found (no tools provided).`,
1395
- toolName: toolCall.toolName
1396
- });
1396
+ throw new NoSuchToolError({ toolName: toolCall.toolName });
1397
1397
  }
1398
1398
  const tool2 = tools[toolName];
1399
1399
  if (tool2 == null) {
1400
1400
  throw new NoSuchToolError({
1401
- message: `Tool ${toolCall.toolName} not found.`,
1402
- toolName: toolCall.toolName
1401
+ toolName: toolCall.toolName,
1402
+ availableTools: Object.keys(tools)
1403
1403
  });
1404
1404
  }
1405
1405
  const parseResult = safeParseJSON({
@@ -1414,6 +1414,7 @@ function parseToolCall({
1414
1414
  });
1415
1415
  }
1416
1416
  return {
1417
+ type: "tool-call",
1417
1418
  toolCallId: toolCall.toolCallId,
1418
1419
  toolName,
1419
1420
  args: parseResult.value
@@ -1442,7 +1443,7 @@ async function experimental_generateText({
1442
1443
  type: "function",
1443
1444
  name,
1444
1445
  description: tool2.description,
1445
- parameters: zodToJsonSchema3(tool2.parameters)
1446
+ parameters: convertZodToJSONSchema(tool2.parameters)
1446
1447
  }))
1447
1448
  },
1448
1449
  ...prepareCallSettings(settings),
@@ -1502,9 +1503,6 @@ var GenerateTextResult = class {
1502
1503
  }
1503
1504
  };
1504
1505
 
1505
- // core/generate-text/stream-text.ts
1506
- import zodToJsonSchema4 from "zod-to-json-schema";
1507
-
1508
1506
  // shared/generate-id.ts
1509
1507
  import { customAlphabet } from "nanoid/non-secure";
1510
1508
  var generateId = customAlphabet(
@@ -1539,10 +1537,7 @@ function runToolsTransformation({
1539
1537
  if (tools == null) {
1540
1538
  toolResultsStreamController.enqueue({
1541
1539
  type: "error",
1542
- error: new NoSuchToolError({
1543
- message: `Tool ${chunk.toolName} not found (no tools provided).`,
1544
- toolName: chunk.toolName
1545
- })
1540
+ error: new NoSuchToolError({ toolName: chunk.toolName })
1546
1541
  });
1547
1542
  break;
1548
1543
  }
@@ -1551,8 +1546,8 @@ function runToolsTransformation({
1551
1546
  toolResultsStreamController.enqueue({
1552
1547
  type: "error",
1553
1548
  error: new NoSuchToolError({
1554
- message: `Tool ${chunk.toolName} not found.`,
1555
- toolName: chunk.toolName
1549
+ toolName: chunk.toolName,
1550
+ availableTools: Object.keys(tools)
1556
1551
  })
1557
1552
  });
1558
1553
  break;
@@ -1562,18 +1557,15 @@ function runToolsTransformation({
1562
1557
  toolCall: chunk,
1563
1558
  tools
1564
1559
  });
1565
- controller.enqueue({
1566
- type: "tool-call",
1567
- ...toolCall
1568
- });
1560
+ controller.enqueue(toolCall);
1569
1561
  if (tool2.execute != null) {
1570
1562
  const toolExecutionId = generateId();
1571
1563
  outstandingToolCalls.add(toolExecutionId);
1572
1564
  tool2.execute(toolCall.args).then(
1573
1565
  (result) => {
1574
1566
  toolResultsStreamController.enqueue({
1575
- type: "tool-result",
1576
1567
  ...toolCall,
1568
+ type: "tool-result",
1577
1569
  result
1578
1570
  });
1579
1571
  outstandingToolCalls.delete(toolExecutionId);
@@ -1675,7 +1667,7 @@ async function experimental_streamText({
1675
1667
  type: "function",
1676
1668
  name,
1677
1669
  description: tool2.description,
1678
- parameters: zodToJsonSchema4(tool2.parameters)
1670
+ parameters: convertZodToJSONSchema(tool2.parameters)
1679
1671
  }))
1680
1672
  },
1681
1673
  ...prepareCallSettings(settings),
@@ -1747,9 +1739,7 @@ var StreamTextResult = class {
1747
1739
  @returns an `AIStream` object.
1748
1740
  */
1749
1741
  toAIStream(callbacks) {
1750
- return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
1751
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
1752
- );
1742
+ return readableFromAsyncIterable(this.textStream).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
1753
1743
  }
1754
1744
  };
1755
1745
 
@@ -1954,7 +1944,6 @@ function createChunkDecoder(complex) {
1954
1944
  };
1955
1945
  }
1956
1946
  var isStreamStringEqualToType = (type, value) => value.startsWith(`${StreamStringPrefixes[type]}:`) && value.endsWith("\n");
1957
- var COMPLEX_HEADER = "X-Experimental-Stream-Data";
1958
1947
 
1959
1948
  // streams/ai-stream.ts
1960
1949
  import {
@@ -2081,7 +2070,7 @@ function readableFromAsyncIterable(iterable) {
2081
2070
  }
2082
2071
 
2083
2072
  // streams/stream-data.ts
2084
- var experimental_StreamData = class {
2073
+ var StreamData = class {
2085
2074
  constructor() {
2086
2075
  this.encoder = new TextEncoder();
2087
2076
  this.controller = null;
@@ -2167,14 +2156,7 @@ var experimental_StreamData = class {
2167
2156
  this.messageAnnotations.push(value);
2168
2157
  }
2169
2158
  };
2170
- function createStreamDataTransformer(experimental_streamData) {
2171
- if (!experimental_streamData) {
2172
- return new TransformStream({
2173
- transform: async (chunk, controller) => {
2174
- controller.enqueue(chunk);
2175
- }
2176
- });
2177
- }
2159
+ function createStreamDataTransformer() {
2178
2160
  const encoder = new TextEncoder();
2179
2161
  const decoder = new TextDecoder();
2180
2162
  return new TransformStream({
@@ -2184,6 +2166,8 @@ function createStreamDataTransformer(experimental_streamData) {
2184
2166
  }
2185
2167
  });
2186
2168
  }
2169
+ var experimental_StreamData = class extends StreamData {
2170
+ };
2187
2171
 
2188
2172
  // streams/anthropic-stream.ts
2189
2173
  function parseAnthropicStream() {
@@ -2223,16 +2207,16 @@ async function* streamable(stream) {
2223
2207
  }
2224
2208
  function AnthropicStream(res, cb) {
2225
2209
  if (Symbol.asyncIterator in res) {
2226
- return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData));
2210
+ return readableFromAsyncIterable(streamable(res)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
2227
2211
  } else {
2228
2212
  return AIStream(res, parseAnthropicStream(), cb).pipeThrough(
2229
- createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
2213
+ createStreamDataTransformer()
2230
2214
  );
2231
2215
  }
2232
2216
  }
2233
2217
 
2234
2218
  // streams/assistant-response.ts
2235
- function experimental_AssistantResponse({ threadId, messageId }, process2) {
2219
+ function AssistantResponse({ threadId, messageId }, process2) {
2236
2220
  const stream = new ReadableStream({
2237
2221
  async start(controller) {
2238
2222
  var _a;
@@ -2323,6 +2307,7 @@ function experimental_AssistantResponse({ threadId, messageId }, process2) {
2323
2307
  }
2324
2308
  });
2325
2309
  }
2310
+ var experimental_AssistantResponse = AssistantResponse;
2326
2311
 
2327
2312
  // streams/aws-bedrock-stream.ts
2328
2313
  async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
@@ -2350,16 +2335,7 @@ function AWSBedrockAnthropicStream(response, callbacks) {
2350
2335
  return AWSBedrockStream(response, callbacks, (chunk) => chunk.completion);
2351
2336
  }
2352
2337
  function AWSBedrockCohereStream(response, callbacks) {
2353
- return AWSBedrockStream(
2354
- response,
2355
- callbacks,
2356
- // As of 2023-11-17, Bedrock does not support streaming for Cohere,
2357
- // so we take the full generation:
2358
- (chunk) => {
2359
- var _a, _b;
2360
- return (_b = (_a = chunk.generations) == null ? void 0 : _a[0]) == null ? void 0 : _b.text;
2361
- }
2362
- );
2338
+ return AWSBedrockStream(response, callbacks, (chunk) => chunk == null ? void 0 : chunk.text);
2363
2339
  }
2364
2340
  function AWSBedrockLlama2Stream(response, callbacks) {
2365
2341
  return AWSBedrockStream(response, callbacks, (chunk) => chunk.generation);
@@ -2367,9 +2343,7 @@ function AWSBedrockLlama2Stream(response, callbacks) {
2367
2343
  function AWSBedrockStream(response, callbacks, extractTextDeltaFromChunk) {
2368
2344
  return readableFromAsyncIterable(
2369
2345
  asDeltaIterable(response, extractTextDeltaFromChunk)
2370
- ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2371
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2372
- );
2346
+ ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2373
2347
  }
2374
2348
 
2375
2349
  // streams/cohere-stream.ts
@@ -2424,13 +2398,9 @@ async function* streamable2(stream) {
2424
2398
  }
2425
2399
  function CohereStream(reader, callbacks) {
2426
2400
  if (Symbol.asyncIterator in reader) {
2427
- return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2428
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2429
- );
2401
+ return readableFromAsyncIterable(streamable2(reader)).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2430
2402
  } else {
2431
- return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2432
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2433
- );
2403
+ return createParser2(reader).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2434
2404
  }
2435
2405
  }
2436
2406
 
@@ -2449,7 +2419,7 @@ async function* streamable3(response) {
2449
2419
  }
2450
2420
  }
2451
2421
  function GoogleGenerativeAIStream(response, cb) {
2452
- return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData));
2422
+ return readableFromAsyncIterable(streamable3(response)).pipeThrough(createCallbacksTransformer(cb)).pipeThrough(createStreamDataTransformer());
2453
2423
  }
2454
2424
 
2455
2425
  // streams/huggingface-stream.ts
@@ -2477,9 +2447,7 @@ function createParser3(res) {
2477
2447
  });
2478
2448
  }
2479
2449
  function HuggingFaceStream(res, callbacks) {
2480
- return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2481
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2482
- );
2450
+ return createParser3(res).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2483
2451
  }
2484
2452
 
2485
2453
  // streams/inkeep-stream.ts
@@ -2516,7 +2484,7 @@ function InkeepStream(res, callbacks) {
2516
2484
  }
2517
2485
  };
2518
2486
  return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
2519
- createStreamDataTransformer(passThroughCallbacks == null ? void 0 : passThroughCallbacks.experimental_streamData)
2487
+ createStreamDataTransformer()
2520
2488
  );
2521
2489
  }
2522
2490
 
@@ -2541,9 +2509,7 @@ function LangChainStream(callbacks) {
2541
2509
  }
2542
2510
  };
2543
2511
  return {
2544
- stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2545
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2546
- ),
2512
+ stream: stream.readable.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer()),
2547
2513
  writer,
2548
2514
  handlers: {
2549
2515
  handleLLMNewToken: async (token) => {
@@ -2594,9 +2560,7 @@ async function* streamable4(stream) {
2594
2560
  }
2595
2561
  function MistralStream(response, callbacks) {
2596
2562
  const stream = readableFromAsyncIterable(streamable4(response));
2597
- return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(
2598
- createStreamDataTransformer(callbacks == null ? void 0 : callbacks.experimental_streamData)
2599
- );
2563
+ return stream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
2600
2564
  }
2601
2565
 
2602
2566
  // streams/openai-stream.ts
@@ -2740,9 +2704,7 @@ function OpenAIStream(res, callbacks) {
2740
2704
  const functionCallTransformer = createFunctionCallTransformer(cb);
2741
2705
  return stream.pipeThrough(functionCallTransformer);
2742
2706
  } else {
2743
- return stream.pipeThrough(
2744
- createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
2745
- );
2707
+ return stream.pipeThrough(createStreamDataTransformer());
2746
2708
  }
2747
2709
  }
2748
2710
  function createFunctionCallTransformer(callbacks) {
@@ -2752,7 +2714,6 @@ function createFunctionCallTransformer(callbacks) {
2752
2714
  let aggregatedFinalCompletionResponse = "";
2753
2715
  let isFunctionStreamingIn = false;
2754
2716
  let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
2755
- const isComplexMode = callbacks == null ? void 0 : callbacks.experimental_streamData;
2756
2717
  const decode = createChunkDecoder();
2757
2718
  return new TransformStream({
2758
2719
  async transform(chunk, controller) {
@@ -2767,7 +2728,7 @@ function createFunctionCallTransformer(callbacks) {
2767
2728
  }
2768
2729
  if (!isFunctionStreamingIn) {
2769
2730
  controller.enqueue(
2770
- isComplexMode ? textEncoder.encode(formatStreamPart("text", message)) : chunk
2731
+ textEncoder.encode(formatStreamPart("text", message))
2771
2732
  );
2772
2733
  return;
2773
2734
  } else {
@@ -2878,17 +2839,17 @@ function createFunctionCallTransformer(callbacks) {
2878
2839
  if (!functionResponse) {
2879
2840
  controller.enqueue(
2880
2841
  textEncoder.encode(
2881
- isComplexMode ? formatStreamPart(
2842
+ formatStreamPart(
2882
2843
  payload.function_call ? "function_call" : "tool_calls",
2883
2844
  // parse to prevent double-encoding:
2884
2845
  JSON.parse(aggregatedResponse)
2885
- ) : aggregatedResponse
2846
+ )
2886
2847
  )
2887
2848
  );
2888
2849
  return;
2889
2850
  } else if (typeof functionResponse === "string") {
2890
2851
  controller.enqueue(
2891
- isComplexMode ? textEncoder.encode(formatStreamPart("text", functionResponse)) : textEncoder.encode(functionResponse)
2852
+ textEncoder.encode(formatStreamPart("text", functionResponse))
2892
2853
  );
2893
2854
  aggregatedFinalCompletionResponse = functionResponse;
2894
2855
  return;
@@ -2938,7 +2899,7 @@ async function ReplicateStream(res, cb, options) {
2938
2899
  }
2939
2900
  });
2940
2901
  return AIStream(eventStream, void 0, cb).pipeThrough(
2941
- createStreamDataTransformer(cb == null ? void 0 : cb.experimental_streamData)
2902
+ createStreamDataTransformer()
2942
2903
  );
2943
2904
  }
2944
2905
 
@@ -3099,74 +3060,41 @@ async function parseComplexResponse({
3099
3060
  // streams/streaming-react-response.ts
3100
3061
  var experimental_StreamingReactResponse = class {
3101
3062
  constructor(res, options) {
3102
- var _a;
3063
+ var _a, _b;
3103
3064
  let resolveFunc = () => {
3104
3065
  };
3105
3066
  let next = new Promise((resolve) => {
3106
3067
  resolveFunc = resolve;
3107
3068
  });
3108
- if (options == null ? void 0 : options.data) {
3109
- const processedStream = res.pipeThrough(
3110
- options.data.stream
3111
- );
3112
- let lastPayload = void 0;
3113
- parseComplexResponse({
3114
- reader: processedStream.getReader(),
3115
- update: (merged, data) => {
3116
- var _a2, _b, _c;
3117
- const content2 = (_b = (_a2 = merged[0]) == null ? void 0 : _a2.content) != null ? _b : "";
3118
- const ui = ((_c = options == null ? void 0 : options.ui) == null ? void 0 : _c.call(options, { content: content2, data })) || content2;
3119
- const payload = { ui, content: content2 };
3120
- const resolvePrevious = resolveFunc;
3121
- const nextRow = new Promise((resolve) => {
3122
- resolveFunc = resolve;
3123
- });
3124
- resolvePrevious({
3125
- next: nextRow,
3126
- ...payload
3069
+ const processedStream = (options == null ? void 0 : options.data) != null ? res.pipeThrough((_a = options == null ? void 0 : options.data) == null ? void 0 : _a.stream) : res;
3070
+ let lastPayload = void 0;
3071
+ parseComplexResponse({
3072
+ reader: processedStream.getReader(),
3073
+ update: (merged, data) => {
3074
+ var _a2, _b2, _c;
3075
+ const content = (_b2 = (_a2 = merged[0]) == null ? void 0 : _a2.content) != null ? _b2 : "";
3076
+ const ui = ((_c = options == null ? void 0 : options.ui) == null ? void 0 : _c.call(options, { content, data })) || content;
3077
+ const payload = { ui, content };
3078
+ const resolvePrevious = resolveFunc;
3079
+ const nextRow = new Promise((resolve) => {
3080
+ resolveFunc = resolve;
3081
+ });
3082
+ resolvePrevious({
3083
+ next: nextRow,
3084
+ ...payload
3085
+ });
3086
+ lastPayload = payload;
3087
+ },
3088
+ generateId: (_b = options == null ? void 0 : options.generateId) != null ? _b : generateId,
3089
+ onFinish: () => {
3090
+ if (lastPayload !== void 0) {
3091
+ resolveFunc({
3092
+ next: null,
3093
+ ...lastPayload
3127
3094
  });
3128
- lastPayload = payload;
3129
- },
3130
- generateId: (_a = options.generateId) != null ? _a : generateId,
3131
- onFinish: () => {
3132
- if (lastPayload !== void 0) {
3133
- resolveFunc({
3134
- next: null,
3135
- ...lastPayload
3136
- });
3137
- }
3138
3095
  }
3139
- });
3140
- return next;
3141
- }
3142
- let content = "";
3143
- const decode = createChunkDecoder();
3144
- const reader = res.getReader();
3145
- async function readChunk() {
3146
- var _a2;
3147
- const { done, value } = await reader.read();
3148
- if (!done) {
3149
- content += decode(value);
3150
- }
3151
- const ui = ((_a2 = options == null ? void 0 : options.ui) == null ? void 0 : _a2.call(options, { content })) || content;
3152
- const payload = {
3153
- ui,
3154
- content
3155
- };
3156
- const resolvePrevious = resolveFunc;
3157
- const nextRow = done ? null : new Promise((resolve) => {
3158
- resolveFunc = resolve;
3159
- });
3160
- resolvePrevious({
3161
- next: nextRow,
3162
- ...payload
3163
- });
3164
- if (done) {
3165
- return;
3166
3096
  }
3167
- await readChunk();
3168
- }
3169
- readChunk();
3097
+ });
3170
3098
  return next;
3171
3099
  }
3172
3100
  };
@@ -3183,7 +3111,6 @@ var StreamingTextResponse = class extends Response {
3183
3111
  status: 200,
3184
3112
  headers: {
3185
3113
  "Content-Type": "text/plain; charset=utf-8",
3186
- [COMPLEX_HEADER]: data ? "true" : "false",
3187
3114
  ...init == null ? void 0 : init.headers
3188
3115
  }
3189
3116
  });
@@ -3215,7 +3142,7 @@ export {
3215
3142
  AWSBedrockLlama2Stream,
3216
3143
  AWSBedrockStream,
3217
3144
  AnthropicStream,
3218
- COMPLEX_HEADER,
3145
+ AssistantResponse,
3219
3146
  CohereStream,
3220
3147
  GenerateObjectResult,
3221
3148
  GenerateTextResult,
@@ -3226,6 +3153,7 @@ export {
3226
3153
  MistralStream,
3227
3154
  OpenAIStream,
3228
3155
  ReplicateStream,
3156
+ StreamData,
3229
3157
  StreamObjectResult,
3230
3158
  StreamTextResult,
3231
3159
  StreamingTextResponse,