ai 3.1.6 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ __export(streams_exports, {
40
40
  AnthropicStream: () => AnthropicStream,
41
41
  AssistantResponse: () => AssistantResponse,
42
42
  CohereStream: () => CohereStream,
43
+ EmbedResult: () => EmbedResult,
43
44
  EmptyResponseBodyError: () => import_provider8.EmptyResponseBodyError,
44
45
  GenerateObjectResult: () => GenerateObjectResult,
45
46
  GenerateTextResult: () => GenerateTextResult,
@@ -71,10 +72,12 @@ __export(streams_exports, {
71
72
  UnsupportedJSONSchemaError: () => import_provider8.UnsupportedJSONSchemaError,
72
73
  convertDataContentToBase64String: () => convertDataContentToBase64String,
73
74
  convertDataContentToUint8Array: () => convertDataContentToUint8Array,
75
+ convertToCoreMessages: () => convertToCoreMessages,
74
76
  createCallbacksTransformer: () => createCallbacksTransformer,
75
77
  createChunkDecoder: () => createChunkDecoder,
76
78
  createEventStreamTransformer: () => createEventStreamTransformer,
77
79
  createStreamDataTransformer: () => createStreamDataTransformer,
80
+ embed: () => embed,
78
81
  experimental_AssistantResponse: () => experimental_AssistantResponse,
79
82
  experimental_StreamData: () => experimental_StreamData,
80
83
  experimental_StreamingReactResponse: () => experimental_StreamingReactResponse,
@@ -99,6 +102,96 @@ __export(streams_exports, {
99
102
  });
100
103
  module.exports = __toCommonJS(streams_exports);
101
104
 
105
+ // core/util/retry-with-exponential-backoff.ts
106
+ var import_provider = require("@ai-sdk/provider");
107
+ var import_provider_utils = require("@ai-sdk/provider-utils");
108
+
109
+ // core/util/delay.ts
110
+ async function delay(delayInMs) {
111
+ return new Promise((resolve) => setTimeout(resolve, delayInMs));
112
+ }
113
+
114
+ // core/util/retry-with-exponential-backoff.ts
115
+ var retryWithExponentialBackoff = ({
116
+ maxRetries = 2,
117
+ initialDelayInMs = 2e3,
118
+ backoffFactor = 2
119
+ } = {}) => async (f) => _retryWithExponentialBackoff(f, {
120
+ maxRetries,
121
+ delayInMs: initialDelayInMs,
122
+ backoffFactor
123
+ });
124
+ async function _retryWithExponentialBackoff(f, {
125
+ maxRetries,
126
+ delayInMs,
127
+ backoffFactor
128
+ }, errors = []) {
129
+ try {
130
+ return await f();
131
+ } catch (error) {
132
+ if ((0, import_provider_utils.isAbortError)(error)) {
133
+ throw error;
134
+ }
135
+ if (maxRetries === 0) {
136
+ throw error;
137
+ }
138
+ const errorMessage = (0, import_provider_utils.getErrorMessage)(error);
139
+ const newErrors = [...errors, error];
140
+ const tryNumber = newErrors.length;
141
+ if (tryNumber > maxRetries) {
142
+ throw new import_provider.RetryError({
143
+ message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
144
+ reason: "maxRetriesExceeded",
145
+ errors: newErrors
146
+ });
147
+ }
148
+ if (error instanceof Error && import_provider.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
149
+ await delay(delayInMs);
150
+ return _retryWithExponentialBackoff(
151
+ f,
152
+ { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
153
+ newErrors
154
+ );
155
+ }
156
+ if (tryNumber === 1) {
157
+ throw error;
158
+ }
159
+ throw new import_provider.RetryError({
160
+ message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
161
+ reason: "errorNotRetryable",
162
+ errors: newErrors
163
+ });
164
+ }
165
+ }
166
+
167
+ // core/embed/embed.ts
168
+ async function embed({
169
+ model,
170
+ value,
171
+ maxRetries,
172
+ abortSignal
173
+ }) {
174
+ const retry = retryWithExponentialBackoff({ maxRetries });
175
+ const modelResponse = await retry(
176
+ () => model.doEmbed({
177
+ values: [value],
178
+ abortSignal
179
+ })
180
+ );
181
+ return new EmbedResult({
182
+ value,
183
+ embedding: modelResponse.embeddings[0],
184
+ rawResponse: modelResponse.rawResponse
185
+ });
186
+ }
187
+ var EmbedResult = class {
188
+ constructor(options) {
189
+ this.value = options.value;
190
+ this.embedding = options.embedding;
191
+ this.rawResponse = options.rawResponse;
192
+ }
193
+ };
194
+
102
195
  // core/generate-object/generate-object.ts
103
196
  var import_provider5 = require("@ai-sdk/provider");
104
197
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
@@ -129,16 +222,16 @@ function detectImageMimeType(image) {
129
222
  }
130
223
 
131
224
  // core/prompt/data-content.ts
132
- var import_provider = require("@ai-sdk/provider");
133
- var import_provider_utils = require("@ai-sdk/provider-utils");
225
+ var import_provider2 = require("@ai-sdk/provider");
226
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
134
227
  function convertDataContentToBase64String(content) {
135
228
  if (typeof content === "string") {
136
229
  return content;
137
230
  }
138
231
  if (content instanceof ArrayBuffer) {
139
- return (0, import_provider_utils.convertUint8ArrayToBase64)(new Uint8Array(content));
232
+ return (0, import_provider_utils2.convertUint8ArrayToBase64)(new Uint8Array(content));
140
233
  }
141
- return (0, import_provider_utils.convertUint8ArrayToBase64)(content);
234
+ return (0, import_provider_utils2.convertUint8ArrayToBase64)(content);
142
235
  }
143
236
  function convertDataContentToUint8Array(content) {
144
237
  if (content instanceof Uint8Array) {
@@ -146,9 +239,9 @@ function convertDataContentToUint8Array(content) {
146
239
  }
147
240
  if (typeof content === "string") {
148
241
  try {
149
- return (0, import_provider_utils.convertBase64ToUint8Array)(content);
242
+ return (0, import_provider_utils2.convertBase64ToUint8Array)(content);
150
243
  } catch (error) {
151
- throw new import_provider.InvalidDataContentError({
244
+ throw new import_provider2.InvalidDataContentError({
152
245
  message: "Invalid data content. Content string is not a base64-encoded image.",
153
246
  content,
154
247
  cause: error
@@ -158,7 +251,7 @@ function convertDataContentToUint8Array(content) {
158
251
  if (content instanceof ArrayBuffer) {
159
252
  return new Uint8Array(content);
160
253
  }
161
- throw new import_provider.InvalidDataContentError({ content });
254
+ throw new import_provider2.InvalidDataContentError({ content });
162
255
  }
163
256
 
164
257
  // core/prompt/convert-to-language-model-prompt.ts
@@ -246,16 +339,16 @@ function convertToLanguageModelPrompt(prompt) {
246
339
  }
247
340
 
248
341
  // core/prompt/get-validated-prompt.ts
249
- var import_provider2 = require("@ai-sdk/provider");
342
+ var import_provider3 = require("@ai-sdk/provider");
250
343
  function getValidatedPrompt(prompt) {
251
344
  if (prompt.prompt == null && prompt.messages == null) {
252
- throw new import_provider2.InvalidPromptError({
345
+ throw new import_provider3.InvalidPromptError({
253
346
  prompt,
254
347
  message: "prompt or messages must be defined"
255
348
  });
256
349
  }
257
350
  if (prompt.prompt != null && prompt.messages != null) {
258
- throw new import_provider2.InvalidPromptError({
351
+ throw new import_provider3.InvalidPromptError({
259
352
  prompt,
260
353
  message: "prompt and messages cannot be defined at the same time"
261
354
  });
@@ -275,7 +368,7 @@ function getValidatedPrompt(prompt) {
275
368
  }
276
369
 
277
370
  // core/prompt/prepare-call-settings.ts
278
- var import_provider3 = require("@ai-sdk/provider");
371
+ var import_provider4 = require("@ai-sdk/provider");
279
372
  function prepareCallSettings({
280
373
  maxTokens,
281
374
  temperature,
@@ -287,14 +380,14 @@ function prepareCallSettings({
287
380
  }) {
288
381
  if (maxTokens != null) {
289
382
  if (!Number.isInteger(maxTokens)) {
290
- throw new import_provider3.InvalidArgumentError({
383
+ throw new import_provider4.InvalidArgumentError({
291
384
  parameter: "maxTokens",
292
385
  value: maxTokens,
293
386
  message: "maxTokens must be an integer"
294
387
  });
295
388
  }
296
389
  if (maxTokens < 1) {
297
- throw new import_provider3.InvalidArgumentError({
390
+ throw new import_provider4.InvalidArgumentError({
298
391
  parameter: "maxTokens",
299
392
  value: maxTokens,
300
393
  message: "maxTokens must be >= 1"
@@ -303,7 +396,7 @@ function prepareCallSettings({
303
396
  }
304
397
  if (temperature != null) {
305
398
  if (typeof temperature !== "number") {
306
- throw new import_provider3.InvalidArgumentError({
399
+ throw new import_provider4.InvalidArgumentError({
307
400
  parameter: "temperature",
308
401
  value: temperature,
309
402
  message: "temperature must be a number"
@@ -312,7 +405,7 @@ function prepareCallSettings({
312
405
  }
313
406
  if (topP != null) {
314
407
  if (typeof topP !== "number") {
315
- throw new import_provider3.InvalidArgumentError({
408
+ throw new import_provider4.InvalidArgumentError({
316
409
  parameter: "topP",
317
410
  value: topP,
318
411
  message: "topP must be a number"
@@ -321,7 +414,7 @@ function prepareCallSettings({
321
414
  }
322
415
  if (presencePenalty != null) {
323
416
  if (typeof presencePenalty !== "number") {
324
- throw new import_provider3.InvalidArgumentError({
417
+ throw new import_provider4.InvalidArgumentError({
325
418
  parameter: "presencePenalty",
326
419
  value: presencePenalty,
327
420
  message: "presencePenalty must be a number"
@@ -330,7 +423,7 @@ function prepareCallSettings({
330
423
  }
331
424
  if (frequencyPenalty != null) {
332
425
  if (typeof frequencyPenalty !== "number") {
333
- throw new import_provider3.InvalidArgumentError({
426
+ throw new import_provider4.InvalidArgumentError({
334
427
  parameter: "frequencyPenalty",
335
428
  value: frequencyPenalty,
336
429
  message: "frequencyPenalty must be a number"
@@ -339,7 +432,7 @@ function prepareCallSettings({
339
432
  }
340
433
  if (seed != null) {
341
434
  if (!Number.isInteger(seed)) {
342
- throw new import_provider3.InvalidArgumentError({
435
+ throw new import_provider4.InvalidArgumentError({
343
436
  parameter: "seed",
344
437
  value: seed,
345
438
  message: "seed must be an integer"
@@ -348,14 +441,14 @@ function prepareCallSettings({
348
441
  }
349
442
  if (maxRetries != null) {
350
443
  if (!Number.isInteger(maxRetries)) {
351
- throw new import_provider3.InvalidArgumentError({
444
+ throw new import_provider4.InvalidArgumentError({
352
445
  parameter: "maxRetries",
353
446
  value: maxRetries,
354
447
  message: "maxRetries must be an integer"
355
448
  });
356
449
  }
357
450
  if (maxRetries < 0) {
358
- throw new import_provider3.InvalidArgumentError({
451
+ throw new import_provider4.InvalidArgumentError({
359
452
  parameter: "maxRetries",
360
453
  value: maxRetries,
361
454
  message: "maxRetries must be >= 0"
@@ -379,68 +472,6 @@ function convertZodToJSONSchema(zodSchema) {
379
472
  return (0, import_zod_to_json_schema.default)(zodSchema);
380
473
  }
381
474
 
382
- // core/util/retry-with-exponential-backoff.ts
383
- var import_provider4 = require("@ai-sdk/provider");
384
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
385
-
386
- // core/util/delay.ts
387
- async function delay(delayInMs) {
388
- return new Promise((resolve) => setTimeout(resolve, delayInMs));
389
- }
390
-
391
- // core/util/retry-with-exponential-backoff.ts
392
- var retryWithExponentialBackoff = ({
393
- maxRetries = 2,
394
- initialDelayInMs = 2e3,
395
- backoffFactor = 2
396
- } = {}) => async (f) => _retryWithExponentialBackoff(f, {
397
- maxRetries,
398
- delayInMs: initialDelayInMs,
399
- backoffFactor
400
- });
401
- async function _retryWithExponentialBackoff(f, {
402
- maxRetries,
403
- delayInMs,
404
- backoffFactor
405
- }, errors = []) {
406
- try {
407
- return await f();
408
- } catch (error) {
409
- if ((0, import_provider_utils2.isAbortError)(error)) {
410
- throw error;
411
- }
412
- if (maxRetries === 0) {
413
- throw error;
414
- }
415
- const errorMessage = (0, import_provider_utils2.getErrorMessage)(error);
416
- const newErrors = [...errors, error];
417
- const tryNumber = newErrors.length;
418
- if (tryNumber > maxRetries) {
419
- throw new import_provider4.RetryError({
420
- message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
421
- reason: "maxRetriesExceeded",
422
- errors: newErrors
423
- });
424
- }
425
- if (error instanceof Error && import_provider4.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
426
- await delay(delayInMs);
427
- return _retryWithExponentialBackoff(
428
- f,
429
- { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
430
- newErrors
431
- );
432
- }
433
- if (tryNumber === 1) {
434
- throw error;
435
- }
436
- throw new import_provider4.RetryError({
437
- message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
438
- reason: "errorNotRetryable",
439
- errors: newErrors
440
- });
441
- }
442
- }
443
-
444
475
  // core/generate-object/inject-json-schema-into-system.ts
445
476
  var DEFAULT_SCHEMA_PREFIX = "JSON schema:";
446
477
  var DEFAULT_SCHEMA_SUFFIX = "You MUST answer with a JSON object that matches the JSON schema above.";
@@ -1580,8 +1611,65 @@ var StreamTextResult = class {
1580
1611
 
1581
1612
  @returns an `AIStream` object.
1582
1613
  */
1583
- toAIStream(callbacks) {
1584
- return this.textStream.pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
1614
+ toAIStream(callbacks = {}) {
1615
+ let aggregatedResponse = "";
1616
+ const callbackTransformer = new TransformStream({
1617
+ async start() {
1618
+ if (callbacks.onStart)
1619
+ await callbacks.onStart();
1620
+ },
1621
+ async transform(chunk, controller) {
1622
+ controller.enqueue(chunk);
1623
+ if (chunk.type === "text-delta") {
1624
+ const textDelta = chunk.textDelta;
1625
+ aggregatedResponse += textDelta;
1626
+ if (callbacks.onToken)
1627
+ await callbacks.onToken(textDelta);
1628
+ if (callbacks.onText)
1629
+ await callbacks.onText(textDelta);
1630
+ }
1631
+ },
1632
+ async flush() {
1633
+ if (callbacks.onCompletion)
1634
+ await callbacks.onCompletion(aggregatedResponse);
1635
+ if (callbacks.onFinal)
1636
+ await callbacks.onFinal(aggregatedResponse);
1637
+ }
1638
+ });
1639
+ const streamDataTransformer = new TransformStream({
1640
+ transform: async (chunk, controller) => {
1641
+ switch (chunk.type) {
1642
+ case "text-delta":
1643
+ controller.enqueue(formatStreamPart("text", chunk.textDelta));
1644
+ break;
1645
+ case "tool-call":
1646
+ controller.enqueue(
1647
+ formatStreamPart("tool_call", {
1648
+ toolCallId: chunk.toolCallId,
1649
+ toolName: chunk.toolName,
1650
+ args: chunk.args
1651
+ })
1652
+ );
1653
+ break;
1654
+ case "tool-result":
1655
+ controller.enqueue(
1656
+ formatStreamPart("tool_result", {
1657
+ toolCallId: chunk.toolCallId,
1658
+ toolName: chunk.toolName,
1659
+ args: chunk.args,
1660
+ result: chunk.result
1661
+ })
1662
+ );
1663
+ break;
1664
+ case "error":
1665
+ controller.enqueue(
1666
+ formatStreamPart("error", JSON.stringify(chunk.error))
1667
+ );
1668
+ break;
1669
+ }
1670
+ }
1671
+ });
1672
+ return this.fullStream.pipeThrough(callbackTransformer).pipeThrough(streamDataTransformer).pipeThrough(new TextEncoderStream());
1585
1673
  }
1586
1674
  /**
1587
1675
  Writes stream data output to a Node.js response-like object.
@@ -1687,6 +1775,55 @@ var StreamTextResult = class {
1687
1775
  };
1688
1776
  var experimental_streamText = streamText;
1689
1777
 
1778
+ // core/prompt/convert-to-core-messages.ts
1779
+ function convertToCoreMessages(messages) {
1780
+ const coreMessages = [];
1781
+ for (const { role, content, toolInvocations } of messages) {
1782
+ switch (role) {
1783
+ case "user": {
1784
+ coreMessages.push({ role: "user", content });
1785
+ break;
1786
+ }
1787
+ case "assistant": {
1788
+ if (toolInvocations == null) {
1789
+ coreMessages.push({ role: "assistant", content });
1790
+ break;
1791
+ }
1792
+ coreMessages.push({
1793
+ role: "assistant",
1794
+ content: [
1795
+ { type: "text", text: content },
1796
+ ...toolInvocations.map(({ toolCallId, toolName, args }) => ({
1797
+ type: "tool-call",
1798
+ toolCallId,
1799
+ toolName,
1800
+ args
1801
+ }))
1802
+ ]
1803
+ });
1804
+ coreMessages.push({
1805
+ role: "tool",
1806
+ content: toolInvocations.map(
1807
+ ({ toolCallId, toolName, args, result }) => ({
1808
+ type: "tool-result",
1809
+ toolCallId,
1810
+ toolName,
1811
+ args,
1812
+ result
1813
+ })
1814
+ )
1815
+ });
1816
+ break;
1817
+ }
1818
+ default: {
1819
+ const _exhaustiveCheck = role;
1820
+ throw new Error(`Unhandled role: ${_exhaustiveCheck}`);
1821
+ }
1822
+ }
1823
+ }
1824
+ return coreMessages;
1825
+ }
1826
+
1690
1827
  // core/tool/tool.ts
1691
1828
  function tool(tool2) {
1692
1829
  return tool2;
@@ -1791,7 +1928,7 @@ var dataMessageStreamPart = {
1791
1928
  };
1792
1929
  }
1793
1930
  };
1794
- var toolCallStreamPart = {
1931
+ var toolCallsStreamPart = {
1795
1932
  code: "7",
1796
1933
  name: "tool_calls",
1797
1934
  parse: (value) => {
@@ -1818,6 +1955,36 @@ var messageAnnotationsStreamPart = {
1818
1955
  return { type: "message_annotations", value };
1819
1956
  }
1820
1957
  };
1958
+ var toolCallStreamPart = {
1959
+ code: "9",
1960
+ name: "tool_call",
1961
+ parse: (value) => {
1962
+ if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object") {
1963
+ throw new Error(
1964
+ '"tool_call" parts expect an object with a "toolCallId", "toolName", and "args" property.'
1965
+ );
1966
+ }
1967
+ return {
1968
+ type: "tool_call",
1969
+ value
1970
+ };
1971
+ }
1972
+ };
1973
+ var toolResultStreamPart = {
1974
+ code: "a",
1975
+ name: "tool_result",
1976
+ parse: (value) => {
1977
+ if (value == null || typeof value !== "object" || !("toolCallId" in value) || typeof value.toolCallId !== "string" || !("toolName" in value) || typeof value.toolName !== "string" || !("args" in value) || typeof value.args !== "object" || !("result" in value)) {
1978
+ throw new Error(
1979
+ '"tool_result" parts expect an object with a "toolCallId", "toolName", "args", and "result" property.'
1980
+ );
1981
+ }
1982
+ return {
1983
+ type: "tool_result",
1984
+ value
1985
+ };
1986
+ }
1987
+ };
1821
1988
  var streamParts = [
1822
1989
  textStreamPart,
1823
1990
  functionCallStreamPart,
@@ -1826,8 +1993,10 @@ var streamParts = [
1826
1993
  assistantMessageStreamPart,
1827
1994
  assistantControlDataStreamPart,
1828
1995
  dataMessageStreamPart,
1996
+ toolCallsStreamPart,
1997
+ messageAnnotationsStreamPart,
1829
1998
  toolCallStreamPart,
1830
- messageAnnotationsStreamPart
1999
+ toolResultStreamPart
1831
2000
  ];
1832
2001
  var streamPartsByCode = {
1833
2002
  [textStreamPart.code]: textStreamPart,
@@ -1837,8 +2006,10 @@ var streamPartsByCode = {
1837
2006
  [assistantMessageStreamPart.code]: assistantMessageStreamPart,
1838
2007
  [assistantControlDataStreamPart.code]: assistantControlDataStreamPart,
1839
2008
  [dataMessageStreamPart.code]: dataMessageStreamPart,
2009
+ [toolCallsStreamPart.code]: toolCallsStreamPart,
2010
+ [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart,
1840
2011
  [toolCallStreamPart.code]: toolCallStreamPart,
1841
- [messageAnnotationsStreamPart.code]: messageAnnotationsStreamPart
2012
+ [toolResultStreamPart.code]: toolResultStreamPart
1842
2013
  };
1843
2014
  var StreamStringPrefixes = {
1844
2015
  [textStreamPart.name]: textStreamPart.code,
@@ -1848,8 +2019,10 @@ var StreamStringPrefixes = {
1848
2019
  [assistantMessageStreamPart.name]: assistantMessageStreamPart.code,
1849
2020
  [assistantControlDataStreamPart.name]: assistantControlDataStreamPart.code,
1850
2021
  [dataMessageStreamPart.name]: dataMessageStreamPart.code,
2022
+ [toolCallsStreamPart.name]: toolCallsStreamPart.code,
2023
+ [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code,
1851
2024
  [toolCallStreamPart.name]: toolCallStreamPart.code,
1852
- [messageAnnotationsStreamPart.name]: messageAnnotationsStreamPart.code
2025
+ [toolResultStreamPart.name]: toolResultStreamPart.code
1853
2026
  };
1854
2027
  var validCodes = streamParts.map((part) => part.code);
1855
2028
  var parseStreamPart = (line) => {
@@ -2952,6 +3125,40 @@ async function parseComplexResponse({
2952
3125
  };
2953
3126
  }
2954
3127
  }
3128
+ if (type === "tool_call") {
3129
+ if (prefixMap.text == null) {
3130
+ prefixMap.text = {
3131
+ id: generateId2(),
3132
+ role: "assistant",
3133
+ content: "",
3134
+ createdAt
3135
+ };
3136
+ }
3137
+ if (prefixMap.text.toolInvocations == null) {
3138
+ prefixMap.text.toolInvocations = [];
3139
+ }
3140
+ prefixMap.text.toolInvocations.push(value);
3141
+ } else if (type === "tool_result") {
3142
+ if (prefixMap.text == null) {
3143
+ prefixMap.text = {
3144
+ id: generateId2(),
3145
+ role: "assistant",
3146
+ content: "",
3147
+ createdAt
3148
+ };
3149
+ }
3150
+ if (prefixMap.text.toolInvocations == null) {
3151
+ prefixMap.text.toolInvocations = [];
3152
+ }
3153
+ const toolInvocationIndex = prefixMap.text.toolInvocations.findIndex(
3154
+ (invocation) => invocation.toolCallId === value.toolCallId
3155
+ );
3156
+ if (toolInvocationIndex !== -1) {
3157
+ prefixMap.text.toolInvocations[toolInvocationIndex] = value;
3158
+ } else {
3159
+ prefixMap.text.toolInvocations.push(value);
3160
+ }
3161
+ }
2955
3162
  let functionCallMessage = null;
2956
3163
  if (type === "function_call") {
2957
3164
  prefixMap["function_call"] = {
@@ -3115,6 +3322,7 @@ function streamToResponse(res, response, init) {
3115
3322
  AnthropicStream,
3116
3323
  AssistantResponse,
3117
3324
  CohereStream,
3325
+ EmbedResult,
3118
3326
  EmptyResponseBodyError,
3119
3327
  GenerateObjectResult,
3120
3328
  GenerateTextResult,
@@ -3146,10 +3354,12 @@ function streamToResponse(res, response, init) {
3146
3354
  UnsupportedJSONSchemaError,
3147
3355
  convertDataContentToBase64String,
3148
3356
  convertDataContentToUint8Array,
3357
+ convertToCoreMessages,
3149
3358
  createCallbacksTransformer,
3150
3359
  createChunkDecoder,
3151
3360
  createEventStreamTransformer,
3152
3361
  createStreamDataTransformer,
3362
+ embed,
3153
3363
  experimental_AssistantResponse,
3154
3364
  experimental_StreamData,
3155
3365
  experimental_StreamingReactResponse,