ai 3.3.0 → 3.3.1

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
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
9
+ for (var name9 in all)
10
+ __defProp(target, name9, { get: all[name9], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
13
  if (from && typeof from === "object" || typeof from === "function") {
@@ -30,8 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // streams/index.ts
31
31
  var streams_exports = {};
32
32
  __export(streams_exports, {
33
+ AISDKError: () => import_provider11.AISDKError,
33
34
  AIStream: () => AIStream,
34
- APICallError: () => import_provider9.APICallError,
35
+ APICallError: () => import_provider11.APICallError,
35
36
  AWSBedrockAnthropicMessagesStream: () => AWSBedrockAnthropicMessagesStream,
36
37
  AWSBedrockAnthropicStream: () => AWSBedrockAnthropicStream,
37
38
  AWSBedrockCohereStream: () => AWSBedrockCohereStream,
@@ -40,35 +41,34 @@ __export(streams_exports, {
40
41
  AnthropicStream: () => AnthropicStream,
41
42
  AssistantResponse: () => AssistantResponse,
42
43
  CohereStream: () => CohereStream,
43
- EmptyResponseBodyError: () => import_provider9.EmptyResponseBodyError,
44
+ DownloadError: () => DownloadError,
45
+ EmptyResponseBodyError: () => import_provider11.EmptyResponseBodyError,
44
46
  GoogleGenerativeAIStream: () => GoogleGenerativeAIStream,
45
47
  HuggingFaceStream: () => HuggingFaceStream,
46
48
  InkeepStream: () => InkeepStream,
47
- InvalidArgumentError: () => import_provider9.InvalidArgumentError,
48
- InvalidDataContentError: () => import_provider9.InvalidDataContentError,
49
+ InvalidArgumentError: () => InvalidArgumentError,
50
+ InvalidDataContentError: () => InvalidDataContentError,
49
51
  InvalidMessageRoleError: () => InvalidMessageRoleError,
50
52
  InvalidModelIdError: () => InvalidModelIdError,
51
- InvalidPromptError: () => import_provider9.InvalidPromptError,
52
- InvalidResponseDataError: () => import_provider9.InvalidResponseDataError,
53
- InvalidToolArgumentsError: () => import_provider9.InvalidToolArgumentsError,
54
- JSONParseError: () => import_provider9.JSONParseError,
53
+ InvalidPromptError: () => import_provider11.InvalidPromptError,
54
+ InvalidResponseDataError: () => import_provider11.InvalidResponseDataError,
55
+ InvalidToolArgumentsError: () => InvalidToolArgumentsError,
56
+ JSONParseError: () => import_provider11.JSONParseError,
55
57
  LangChainAdapter: () => langchain_adapter_exports,
56
58
  LangChainStream: () => LangChainStream,
57
- LoadAPIKeyError: () => import_provider9.LoadAPIKeyError,
59
+ LoadAPIKeyError: () => import_provider11.LoadAPIKeyError,
58
60
  MistralStream: () => MistralStream,
59
- NoObjectGeneratedError: () => import_provider9.NoObjectGeneratedError,
61
+ NoObjectGeneratedError: () => NoObjectGeneratedError,
60
62
  NoSuchModelError: () => NoSuchModelError,
61
63
  NoSuchProviderError: () => NoSuchProviderError,
62
- NoSuchToolError: () => import_provider9.NoSuchToolError,
64
+ NoSuchToolError: () => NoSuchToolError,
63
65
  OpenAIStream: () => OpenAIStream,
64
66
  ReplicateStream: () => ReplicateStream,
65
- RetryError: () => import_provider9.RetryError,
67
+ RetryError: () => RetryError,
66
68
  StreamData: () => StreamData2,
67
69
  StreamingTextResponse: () => StreamingTextResponse,
68
- ToolCallParseError: () => import_provider9.ToolCallParseError,
69
- TypeValidationError: () => import_provider9.TypeValidationError,
70
- UnsupportedFunctionalityError: () => import_provider9.UnsupportedFunctionalityError,
71
- UnsupportedJSONSchemaError: () => import_provider9.UnsupportedJSONSchemaError,
70
+ TypeValidationError: () => import_provider11.TypeValidationError,
71
+ UnsupportedFunctionalityError: () => import_provider11.UnsupportedFunctionalityError,
72
72
  convertDataContentToBase64String: () => convertDataContentToBase64String,
73
73
  convertDataContentToUint8Array: () => convertDataContentToUint8Array,
74
74
  convertToCoreMessages: () => convertToCoreMessages,
@@ -107,6 +107,110 @@ module.exports = __toCommonJS(streams_exports);
107
107
  var import_ui_utils6 = require("@ai-sdk/ui-utils");
108
108
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
109
109
 
110
+ // util/retry-with-exponential-backoff.ts
111
+ var import_provider2 = require("@ai-sdk/provider");
112
+ var import_provider_utils = require("@ai-sdk/provider-utils");
113
+
114
+ // util/delay.ts
115
+ async function delay(delayInMs) {
116
+ return new Promise((resolve) => setTimeout(resolve, delayInMs));
117
+ }
118
+
119
+ // util/retry-error.ts
120
+ var import_provider = require("@ai-sdk/provider");
121
+ var name = "AI_RetryError";
122
+ var marker = `vercel.ai.error.${name}`;
123
+ var symbol = Symbol.for(marker);
124
+ var _a;
125
+ var RetryError = class extends import_provider.AISDKError {
126
+ constructor({
127
+ message,
128
+ reason,
129
+ errors
130
+ }) {
131
+ super({ name, message });
132
+ this[_a] = true;
133
+ this.reason = reason;
134
+ this.errors = errors;
135
+ this.lastError = errors[errors.length - 1];
136
+ }
137
+ static isInstance(error) {
138
+ return import_provider.AISDKError.hasMarker(error, marker);
139
+ }
140
+ /**
141
+ * @deprecated use `isInstance` instead
142
+ */
143
+ static isRetryError(error) {
144
+ return error instanceof Error && error.name === name && typeof error.reason === "string" && Array.isArray(error.errors);
145
+ }
146
+ /**
147
+ * @deprecated Do not use this method. It will be removed in the next major version.
148
+ */
149
+ toJSON() {
150
+ return {
151
+ name: this.name,
152
+ message: this.message,
153
+ reason: this.reason,
154
+ lastError: this.lastError,
155
+ errors: this.errors
156
+ };
157
+ }
158
+ };
159
+ _a = symbol;
160
+
161
+ // util/retry-with-exponential-backoff.ts
162
+ var retryWithExponentialBackoff = ({
163
+ maxRetries = 2,
164
+ initialDelayInMs = 2e3,
165
+ backoffFactor = 2
166
+ } = {}) => async (f) => _retryWithExponentialBackoff(f, {
167
+ maxRetries,
168
+ delayInMs: initialDelayInMs,
169
+ backoffFactor
170
+ });
171
+ async function _retryWithExponentialBackoff(f, {
172
+ maxRetries,
173
+ delayInMs,
174
+ backoffFactor
175
+ }, errors = []) {
176
+ try {
177
+ return await f();
178
+ } catch (error) {
179
+ if ((0, import_provider_utils.isAbortError)(error)) {
180
+ throw error;
181
+ }
182
+ if (maxRetries === 0) {
183
+ throw error;
184
+ }
185
+ const errorMessage = (0, import_provider_utils.getErrorMessage)(error);
186
+ const newErrors = [...errors, error];
187
+ const tryNumber = newErrors.length;
188
+ if (tryNumber > maxRetries) {
189
+ throw new RetryError({
190
+ message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
191
+ reason: "maxRetriesExceeded",
192
+ errors: newErrors
193
+ });
194
+ }
195
+ if (error instanceof Error && import_provider2.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
196
+ await delay(delayInMs);
197
+ return _retryWithExponentialBackoff(
198
+ f,
199
+ { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
200
+ newErrors
201
+ );
202
+ }
203
+ if (tryNumber === 1) {
204
+ throw error;
205
+ }
206
+ throw new RetryError({
207
+ message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
208
+ reason: "errorNotRetryable",
209
+ errors: newErrors
210
+ });
211
+ }
212
+ }
213
+
110
214
  // core/telemetry/assemble-operation-name.ts
111
215
  function assembleOperationName({
112
216
  operationName,
@@ -124,7 +228,7 @@ function getBaseTelemetryAttributes({
124
228
  telemetry,
125
229
  headers
126
230
  }) {
127
- var _a;
231
+ var _a9;
128
232
  return {
129
233
  "ai.model.provider": model.provider,
130
234
  "ai.model.id": model.modelId,
@@ -137,7 +241,7 @@ function getBaseTelemetryAttributes({
137
241
  "resource.name": telemetry == null ? void 0 : telemetry.functionId,
138
242
  "ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
139
243
  // add metadata as attributes:
140
- ...Object.entries((_a = telemetry == null ? void 0 : telemetry.metadata) != null ? _a : {}).reduce(
244
+ ...Object.entries((_a9 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a9 : {}).reduce(
141
245
  (attributes, [key, value]) => {
142
246
  attributes[`ai.telemetry.metadata.${key}`] = value;
143
247
  return attributes;
@@ -162,7 +266,7 @@ var noopTracer = {
162
266
  startSpan() {
163
267
  return noopSpan;
164
268
  },
165
- startActiveSpan(name, arg1, arg2, arg3) {
269
+ startActiveSpan(name9, arg1, arg2, arg3) {
166
270
  if (typeof arg1 === "function") {
167
271
  return arg1(noopSpan);
168
272
  }
@@ -230,13 +334,13 @@ function getTracer({ isEnabled }) {
230
334
  // core/telemetry/record-span.ts
231
335
  var import_api2 = require("@opentelemetry/api");
232
336
  function recordSpan({
233
- name,
337
+ name: name9,
234
338
  tracer,
235
339
  attributes,
236
340
  fn,
237
341
  endWhenDone = true
238
342
  }) {
239
- return tracer.startActiveSpan(name, { attributes }, async (span) => {
343
+ return tracer.startActiveSpan(name9, { attributes }, async (span) => {
240
344
  try {
241
345
  const result = await fn(span);
242
346
  if (endWhenDone) {
@@ -293,68 +397,6 @@ function selectTelemetryAttributes({
293
397
  }, {});
294
398
  }
295
399
 
296
- // core/util/retry-with-exponential-backoff.ts
297
- var import_provider = require("@ai-sdk/provider");
298
- var import_provider_utils = require("@ai-sdk/provider-utils");
299
-
300
- // core/util/delay.ts
301
- async function delay(delayInMs) {
302
- return new Promise((resolve) => setTimeout(resolve, delayInMs));
303
- }
304
-
305
- // core/util/retry-with-exponential-backoff.ts
306
- var retryWithExponentialBackoff = ({
307
- maxRetries = 2,
308
- initialDelayInMs = 2e3,
309
- backoffFactor = 2
310
- } = {}) => async (f) => _retryWithExponentialBackoff(f, {
311
- maxRetries,
312
- delayInMs: initialDelayInMs,
313
- backoffFactor
314
- });
315
- async function _retryWithExponentialBackoff(f, {
316
- maxRetries,
317
- delayInMs,
318
- backoffFactor
319
- }, errors = []) {
320
- try {
321
- return await f();
322
- } catch (error) {
323
- if ((0, import_provider_utils.isAbortError)(error)) {
324
- throw error;
325
- }
326
- if (maxRetries === 0) {
327
- throw error;
328
- }
329
- const errorMessage = (0, import_provider_utils.getErrorMessage)(error);
330
- const newErrors = [...errors, error];
331
- const tryNumber = newErrors.length;
332
- if (tryNumber > maxRetries) {
333
- throw new import_provider.RetryError({
334
- message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
335
- reason: "maxRetriesExceeded",
336
- errors: newErrors
337
- });
338
- }
339
- if (error instanceof Error && import_provider.APICallError.isAPICallError(error) && error.isRetryable === true && tryNumber <= maxRetries) {
340
- await delay(delayInMs);
341
- return _retryWithExponentialBackoff(
342
- f,
343
- { maxRetries, delayInMs: backoffFactor * delayInMs, backoffFactor },
344
- newErrors
345
- );
346
- }
347
- if (tryNumber === 1) {
348
- throw error;
349
- }
350
- throw new import_provider.RetryError({
351
- message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
352
- reason: "errorNotRetryable",
353
- errors: newErrors
354
- });
355
- }
356
- }
357
-
358
400
  // core/embed/embed.ts
359
401
  async function embed({
360
402
  model,
@@ -364,14 +406,14 @@ async function embed({
364
406
  headers,
365
407
  experimental_telemetry: telemetry
366
408
  }) {
367
- var _a;
409
+ var _a9;
368
410
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
369
411
  model,
370
412
  telemetry,
371
413
  headers,
372
414
  settings: { maxRetries }
373
415
  });
374
- const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
416
+ const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
375
417
  return recordSpan({
376
418
  name: "ai.embed",
377
419
  attributes: selectTelemetryAttributes({
@@ -404,14 +446,14 @@ async function embed({
404
446
  }),
405
447
  tracer,
406
448
  fn: async (doEmbedSpan) => {
407
- var _a2;
449
+ var _a10;
408
450
  const modelResponse = await model.doEmbed({
409
451
  values: [value],
410
452
  abortSignal,
411
453
  headers
412
454
  });
413
455
  const embedding2 = modelResponse.embeddings[0];
414
- const usage2 = (_a2 = modelResponse.usage) != null ? _a2 : { tokens: NaN };
456
+ const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
415
457
  doEmbedSpan.setAttributes(
416
458
  selectTelemetryAttributes({
417
459
  telemetry,
@@ -477,14 +519,14 @@ async function embedMany({
477
519
  headers,
478
520
  experimental_telemetry: telemetry
479
521
  }) {
480
- var _a;
522
+ var _a9;
481
523
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
482
524
  model,
483
525
  telemetry,
484
526
  headers,
485
527
  settings: { maxRetries }
486
528
  });
487
- const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
529
+ const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
488
530
  return recordSpan({
489
531
  name: "ai.embedMany",
490
532
  attributes: selectTelemetryAttributes({
@@ -522,14 +564,14 @@ async function embedMany({
522
564
  }),
523
565
  tracer,
524
566
  fn: async (doEmbedSpan) => {
525
- var _a2;
567
+ var _a10;
526
568
  const modelResponse = await model.doEmbed({
527
569
  values,
528
570
  abortSignal,
529
571
  headers
530
572
  });
531
573
  const embeddings3 = modelResponse.embeddings;
532
- const usage2 = (_a2 = modelResponse.usage) != null ? _a2 : { tokens: NaN };
574
+ const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
533
575
  doEmbedSpan.setAttributes(
534
576
  selectTelemetryAttributes({
535
577
  telemetry,
@@ -581,14 +623,14 @@ async function embedMany({
581
623
  }),
582
624
  tracer,
583
625
  fn: async (doEmbedSpan) => {
584
- var _a2;
626
+ var _a10;
585
627
  const modelResponse = await model.doEmbed({
586
628
  values: chunk,
587
629
  abortSignal,
588
630
  headers
589
631
  });
590
632
  const embeddings2 = modelResponse.embeddings;
591
- const usage2 = (_a2 = modelResponse.usage) != null ? _a2 : { tokens: NaN };
633
+ const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
592
634
  doEmbedSpan.setAttributes(
593
635
  selectTelemetryAttributes({
594
636
  telemetry,
@@ -635,40 +677,67 @@ var DefaultEmbedManyResult = class {
635
677
  };
636
678
 
637
679
  // core/generate-object/generate-object.ts
638
- var import_provider6 = require("@ai-sdk/provider");
639
680
  var import_provider_utils5 = require("@ai-sdk/provider-utils");
640
681
 
641
682
  // core/prompt/convert-to-language-model-prompt.ts
642
683
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
643
684
 
644
- // core/util/detect-image-mimetype.ts
645
- var mimeTypeSignatures = [
646
- { mimeType: "image/gif", bytes: [71, 73, 70] },
647
- { mimeType: "image/png", bytes: [137, 80, 78, 71] },
648
- { mimeType: "image/jpeg", bytes: [255, 216] },
649
- { mimeType: "image/webp", bytes: [82, 73, 70, 70] }
650
- ];
651
- function detectImageMimeType(image) {
652
- for (const { bytes, mimeType } of mimeTypeSignatures) {
653
- if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
654
- return mimeType;
655
- }
685
+ // util/download-error.ts
686
+ var import_provider3 = require("@ai-sdk/provider");
687
+ var name2 = "AI_DownloadError";
688
+ var marker2 = `vercel.ai.error.${name2}`;
689
+ var symbol2 = Symbol.for(marker2);
690
+ var _a2;
691
+ var DownloadError = class extends import_provider3.AISDKError {
692
+ constructor({
693
+ url,
694
+ statusCode,
695
+ statusText,
696
+ cause,
697
+ message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
698
+ }) {
699
+ super({ name: name2, message, cause });
700
+ this[_a2] = true;
701
+ this.url = url;
702
+ this.statusCode = statusCode;
703
+ this.statusText = statusText;
656
704
  }
657
- return void 0;
658
- }
705
+ static isInstance(error) {
706
+ return import_provider3.AISDKError.hasMarker(error, marker2);
707
+ }
708
+ /**
709
+ * @deprecated use `isInstance` instead
710
+ */
711
+ static isDownloadError(error) {
712
+ return error instanceof Error && error.name === name2 && typeof error.url === "string" && (error.statusCode == null || typeof error.statusCode === "number") && (error.statusText == null || typeof error.statusText === "string");
713
+ }
714
+ /**
715
+ * @deprecated Do not use this method. It will be removed in the next major version.
716
+ */
717
+ toJSON() {
718
+ return {
719
+ name: this.name,
720
+ message: this.message,
721
+ url: this.url,
722
+ statusCode: this.statusCode,
723
+ statusText: this.statusText,
724
+ cause: this.cause
725
+ };
726
+ }
727
+ };
728
+ _a2 = symbol2;
659
729
 
660
- // core/util/download.ts
661
- var import_provider2 = require("@ai-sdk/provider");
730
+ // util/download.ts
662
731
  async function download({
663
732
  url,
664
733
  fetchImplementation = fetch
665
734
  }) {
666
- var _a;
735
+ var _a9;
667
736
  const urlText = url.toString();
668
737
  try {
669
738
  const response = await fetchImplementation(urlText);
670
739
  if (!response.ok) {
671
- throw new import_provider2.DownloadError({
740
+ throw new DownloadError({
672
741
  url: urlText,
673
742
  statusCode: response.status,
674
743
  statusText: response.statusText
@@ -676,19 +745,76 @@ async function download({
676
745
  }
677
746
  return {
678
747
  data: new Uint8Array(await response.arrayBuffer()),
679
- mimeType: (_a = response.headers.get("content-type")) != null ? _a : void 0
748
+ mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
680
749
  };
681
750
  } catch (error) {
682
- if (import_provider2.DownloadError.isDownloadError(error)) {
751
+ if (DownloadError.isInstance(error)) {
683
752
  throw error;
684
753
  }
685
- throw new import_provider2.DownloadError({ url: urlText, cause: error });
754
+ throw new DownloadError({ url: urlText, cause: error });
686
755
  }
687
756
  }
688
757
 
758
+ // core/util/detect-image-mimetype.ts
759
+ var mimeTypeSignatures = [
760
+ { mimeType: "image/gif", bytes: [71, 73, 70] },
761
+ { mimeType: "image/png", bytes: [137, 80, 78, 71] },
762
+ { mimeType: "image/jpeg", bytes: [255, 216] },
763
+ { mimeType: "image/webp", bytes: [82, 73, 70, 70] }
764
+ ];
765
+ function detectImageMimeType(image) {
766
+ for (const { bytes, mimeType } of mimeTypeSignatures) {
767
+ if (image.length >= bytes.length && bytes.every((byte, index) => image[index] === byte)) {
768
+ return mimeType;
769
+ }
770
+ }
771
+ return void 0;
772
+ }
773
+
689
774
  // core/prompt/data-content.ts
690
- var import_provider3 = require("@ai-sdk/provider");
691
775
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
776
+
777
+ // core/prompt/invalid-data-content-error.ts
778
+ var import_provider4 = require("@ai-sdk/provider");
779
+ var name3 = "AI_InvalidDataContentError";
780
+ var marker3 = `vercel.ai.error.${name3}`;
781
+ var symbol3 = Symbol.for(marker3);
782
+ var _a3;
783
+ var InvalidDataContentError = class extends import_provider4.AISDKError {
784
+ constructor({
785
+ content,
786
+ cause,
787
+ message = `Invalid data content. Expected a base64 string, Uint8Array, ArrayBuffer, or Buffer, but got ${typeof content}.`
788
+ }) {
789
+ super({ name: name3, message, cause });
790
+ this[_a3] = true;
791
+ this.content = content;
792
+ }
793
+ static isInstance(error) {
794
+ return import_provider4.AISDKError.hasMarker(error, marker3);
795
+ }
796
+ /**
797
+ * @deprecated use `isInstance` instead
798
+ */
799
+ static isInvalidDataContentError(error) {
800
+ return error instanceof Error && error.name === name3 && error.content != null;
801
+ }
802
+ /**
803
+ * @deprecated Do not use this method. It will be removed in the next major version.
804
+ */
805
+ toJSON() {
806
+ return {
807
+ name: this.name,
808
+ message: this.message,
809
+ stack: this.stack,
810
+ cause: this.cause,
811
+ content: this.content
812
+ };
813
+ }
814
+ };
815
+ _a3 = symbol3;
816
+
817
+ // core/prompt/data-content.ts
692
818
  function convertDataContentToBase64String(content) {
693
819
  if (typeof content === "string") {
694
820
  return content;
@@ -706,7 +832,7 @@ function convertDataContentToUint8Array(content) {
706
832
  try {
707
833
  return (0, import_provider_utils2.convertBase64ToUint8Array)(content);
708
834
  } catch (error) {
709
- throw new import_provider3.InvalidDataContentError({
835
+ throw new InvalidDataContentError({
710
836
  message: "Invalid data content. Content string is not a base64-encoded media.",
711
837
  content,
712
838
  cause: error
@@ -716,7 +842,7 @@ function convertDataContentToUint8Array(content) {
716
842
  if (content instanceof ArrayBuffer) {
717
843
  return new Uint8Array(content);
718
844
  }
719
- throw new import_provider3.InvalidDataContentError({ content });
845
+ throw new InvalidDataContentError({ content });
720
846
  }
721
847
  function convertUint8ArrayToText(uint8Array) {
722
848
  try {
@@ -727,18 +853,32 @@ function convertUint8ArrayToText(uint8Array) {
727
853
  }
728
854
 
729
855
  // core/prompt/invalid-message-role-error.ts
730
- var InvalidMessageRoleError = class extends Error {
856
+ var import_provider5 = require("@ai-sdk/provider");
857
+ var name4 = "AI_InvalidMessageRoleError";
858
+ var marker4 = `vercel.ai.error.${name4}`;
859
+ var symbol4 = Symbol.for(marker4);
860
+ var _a4;
861
+ var InvalidMessageRoleError = class extends import_provider5.AISDKError {
731
862
  constructor({
732
863
  role,
733
864
  message = `Invalid message role: '${role}'. Must be one of: "system", "user", "assistant", "tool".`
734
865
  }) {
735
- super(message);
736
- this.name = "AI_InvalidMessageRoleError";
866
+ super({ name: name4, message });
867
+ this[_a4] = true;
737
868
  this.role = role;
738
869
  }
870
+ static isInstance(error) {
871
+ return import_provider5.AISDKError.hasMarker(error, marker4);
872
+ }
873
+ /**
874
+ * @deprecated use `isInstance` instead
875
+ */
739
876
  static isInvalidMessageRoleError(error) {
740
- return error instanceof Error && error.name === "AI_InvalidMessageRoleError" && typeof error.role === "string";
877
+ return error instanceof Error && error.name === name4 && typeof error.role === "string";
741
878
  }
879
+ /**
880
+ * @deprecated Do not use this method. It will be removed in the next major version.
881
+ */
742
882
  toJSON() {
743
883
  return {
744
884
  name: this.name,
@@ -748,6 +888,7 @@ var InvalidMessageRoleError = class extends Error {
748
888
  };
749
889
  }
750
890
  };
891
+ _a4 = symbol4;
751
892
 
752
893
  // core/prompt/convert-to-language-model-prompt.ts
753
894
  async function convertToLanguageModelPrompt({
@@ -801,7 +942,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
801
942
  role: "user",
802
943
  content: message.content.map(
803
944
  (part) => {
804
- var _a, _b, _c;
945
+ var _a9, _b, _c;
805
946
  switch (part.type) {
806
947
  case "text": {
807
948
  return part;
@@ -819,7 +960,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
819
960
  return {
820
961
  type: "image",
821
962
  image: downloadedImage.data,
822
- mimeType: (_a = part.mimeType) != null ? _a : downloadedImage.mimeType
963
+ mimeType: (_a9 = part.mimeType) != null ? _a9 : downloadedImage.mimeType
823
964
  };
824
965
  }
825
966
  }
@@ -930,16 +1071,16 @@ async function downloadImages(messages, downloadImplementation) {
930
1071
  }
931
1072
 
932
1073
  // core/prompt/get-validated-prompt.ts
933
- var import_provider4 = require("@ai-sdk/provider");
1074
+ var import_provider6 = require("@ai-sdk/provider");
934
1075
  function getValidatedPrompt(prompt) {
935
1076
  if (prompt.prompt == null && prompt.messages == null) {
936
- throw new import_provider4.InvalidPromptError({
1077
+ throw new import_provider6.InvalidPromptError({
937
1078
  prompt,
938
1079
  message: "prompt or messages must be defined"
939
1080
  });
940
1081
  }
941
1082
  if (prompt.prompt != null && prompt.messages != null) {
942
- throw new import_provider4.InvalidPromptError({
1083
+ throw new import_provider6.InvalidPromptError({
943
1084
  prompt,
944
1085
  message: "prompt and messages cannot be defined at the same time"
945
1086
  });
@@ -947,7 +1088,7 @@ function getValidatedPrompt(prompt) {
947
1088
  if (prompt.messages != null) {
948
1089
  for (const message of prompt.messages) {
949
1090
  if (message.role === "system" && typeof message.content !== "string") {
950
- throw new import_provider4.InvalidPromptError({
1091
+ throw new import_provider6.InvalidPromptError({
951
1092
  prompt,
952
1093
  message: "system message content must be a string"
953
1094
  });
@@ -968,8 +1109,48 @@ function getValidatedPrompt(prompt) {
968
1109
  };
969
1110
  }
970
1111
 
1112
+ // errors/invalid-argument-error.ts
1113
+ var import_provider7 = require("@ai-sdk/provider");
1114
+ var name5 = "AI_InvalidArgumentError";
1115
+ var marker5 = `vercel.ai.error.${name5}`;
1116
+ var symbol5 = Symbol.for(marker5);
1117
+ var _a5;
1118
+ var InvalidArgumentError = class extends import_provider7.AISDKError {
1119
+ constructor({
1120
+ parameter,
1121
+ value,
1122
+ message
1123
+ }) {
1124
+ super({
1125
+ name: name5,
1126
+ message: `Invalid argument for parameter ${parameter}: ${message}`
1127
+ });
1128
+ this[_a5] = true;
1129
+ this.parameter = parameter;
1130
+ this.value = value;
1131
+ }
1132
+ static isInstance(error) {
1133
+ return import_provider7.AISDKError.hasMarker(error, marker5);
1134
+ }
1135
+ /**
1136
+ * @deprecated use `isInstance` instead
1137
+ */
1138
+ static isInvalidArgumentError(error) {
1139
+ return error instanceof Error && error.name === name5 && typeof error.parameter === "string" && typeof error.value === "string";
1140
+ }
1141
+ toJSON() {
1142
+ return {
1143
+ name: this.name,
1144
+ message: this.message,
1145
+ stack: this.stack,
1146
+ parameter: this.parameter,
1147
+ value: this.value
1148
+ };
1149
+ }
1150
+ };
1151
+ _a5 = symbol5;
1152
+
971
1153
  // core/prompt/prepare-call-settings.ts
972
- var import_provider5 = require("@ai-sdk/provider");
973
1154
  function prepareCallSettings({
974
1155
  maxTokens,
975
1156
  temperature,
@@ -982,14 +1163,14 @@ function prepareCallSettings({
982
1163
  }) {
983
1164
  if (maxTokens != null) {
984
1165
  if (!Number.isInteger(maxTokens)) {
985
- throw new import_provider5.InvalidArgumentError({
1166
+ throw new InvalidArgumentError({
986
1167
  parameter: "maxTokens",
987
1168
  value: maxTokens,
988
1169
  message: "maxTokens must be an integer"
989
1170
  });
990
1171
  }
991
1172
  if (maxTokens < 1) {
992
- throw new import_provider5.InvalidArgumentError({
1173
+ throw new InvalidArgumentError({
993
1174
  parameter: "maxTokens",
994
1175
  value: maxTokens,
995
1176
  message: "maxTokens must be >= 1"
@@ -998,7 +1179,7 @@ function prepareCallSettings({
998
1179
  }
999
1180
  if (temperature != null) {
1000
1181
  if (typeof temperature !== "number") {
1001
- throw new import_provider5.InvalidArgumentError({
1182
+ throw new InvalidArgumentError({
1002
1183
  parameter: "temperature",
1003
1184
  value: temperature,
1004
1185
  message: "temperature must be a number"
@@ -1007,7 +1188,7 @@ function prepareCallSettings({
1007
1188
  }
1008
1189
  if (topP != null) {
1009
1190
  if (typeof topP !== "number") {
1010
- throw new import_provider5.InvalidArgumentError({
1191
+ throw new InvalidArgumentError({
1011
1192
  parameter: "topP",
1012
1193
  value: topP,
1013
1194
  message: "topP must be a number"
@@ -1016,7 +1197,7 @@ function prepareCallSettings({
1016
1197
  }
1017
1198
  if (presencePenalty != null) {
1018
1199
  if (typeof presencePenalty !== "number") {
1019
- throw new import_provider5.InvalidArgumentError({
1200
+ throw new InvalidArgumentError({
1020
1201
  parameter: "presencePenalty",
1021
1202
  value: presencePenalty,
1022
1203
  message: "presencePenalty must be a number"
@@ -1025,7 +1206,7 @@ function prepareCallSettings({
1025
1206
  }
1026
1207
  if (frequencyPenalty != null) {
1027
1208
  if (typeof frequencyPenalty !== "number") {
1028
- throw new import_provider5.InvalidArgumentError({
1209
+ throw new InvalidArgumentError({
1029
1210
  parameter: "frequencyPenalty",
1030
1211
  value: frequencyPenalty,
1031
1212
  message: "frequencyPenalty must be a number"
@@ -1034,7 +1215,7 @@ function prepareCallSettings({
1034
1215
  }
1035
1216
  if (seed != null) {
1036
1217
  if (!Number.isInteger(seed)) {
1037
- throw new import_provider5.InvalidArgumentError({
1218
+ throw new InvalidArgumentError({
1038
1219
  parameter: "seed",
1039
1220
  value: seed,
1040
1221
  message: "seed must be an integer"
@@ -1043,14 +1224,14 @@ function prepareCallSettings({
1043
1224
  }
1044
1225
  if (maxRetries != null) {
1045
1226
  if (!Number.isInteger(maxRetries)) {
1046
- throw new import_provider5.InvalidArgumentError({
1227
+ throw new InvalidArgumentError({
1047
1228
  parameter: "maxRetries",
1048
1229
  value: maxRetries,
1049
1230
  message: "maxRetries must be an integer"
1050
1231
  });
1051
1232
  }
1052
1233
  if (maxRetries < 0) {
1053
- throw new import_provider5.InvalidArgumentError({
1234
+ throw new InvalidArgumentError({
1054
1235
  parameter: "maxRetries",
1055
1236
  value: maxRetries,
1056
1237
  message: "maxRetries must be >= 0"
@@ -1083,8 +1264,8 @@ function prepareResponseHeaders(init, {
1083
1264
  contentType,
1084
1265
  dataStreamVersion
1085
1266
  }) {
1086
- var _a;
1087
- const headers = new Headers((_a = init == null ? void 0 : init.headers) != null ? _a : {});
1267
+ var _a9;
1268
+ const headers = new Headers((_a9 = init == null ? void 0 : init.headers) != null ? _a9 : {});
1088
1269
  if (!headers.has("Content-Type")) {
1089
1270
  headers.set("Content-Type", contentType);
1090
1271
  }
@@ -1097,7 +1278,7 @@ function prepareResponseHeaders(init, {
1097
1278
  // core/util/schema.ts
1098
1279
  var import_provider_utils4 = require("@ai-sdk/provider-utils");
1099
1280
  var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
1100
- var schemaSymbol = Symbol("vercel.ai.schema");
1281
+ var schemaSymbol = Symbol.for("vercel.ai.schema");
1101
1282
  function jsonSchema(jsonSchema2, {
1102
1283
  validate
1103
1284
  } = {}) {
@@ -1148,6 +1329,41 @@ function injectJsonSchemaIntoSystem({
1148
1329
  ].filter((line) => line != null).join("\n");
1149
1330
  }
1150
1331
 
1332
+ // core/generate-object/no-object-generated-error.ts
1333
+ var import_provider8 = require("@ai-sdk/provider");
1334
+ var name6 = "AI_NoObjectGeneratedError";
1335
+ var marker6 = `vercel.ai.error.${name6}`;
1336
+ var symbol6 = Symbol.for(marker6);
1337
+ var _a6;
1338
+ var NoObjectGeneratedError = class extends import_provider8.AISDKError {
1339
+ // used in isInstance
1340
+ constructor({ message = "No object generated." } = {}) {
1341
+ super({ name: name6, message });
1342
+ this[_a6] = true;
1343
+ }
1344
+ static isInstance(error) {
1345
+ return import_provider8.AISDKError.hasMarker(error, marker6);
1346
+ }
1347
+ /**
1348
+ * @deprecated Use isInstance instead.
1349
+ */
1350
+ static isNoObjectGeneratedError(error) {
1351
+ return error instanceof Error && error.name === name6;
1352
+ }
1353
+ /**
1354
+ * @deprecated Do not use this method. It will be removed in the next major version.
1355
+ */
1356
+ toJSON() {
1357
+ return {
1358
+ name: this.name,
1359
+ cause: this.cause,
1360
+ message: this.message,
1361
+ stack: this.stack
1362
+ };
1363
+ }
1364
+ };
1365
+ _a6 = symbol6;
1366
+
1151
1367
  // core/generate-object/generate-object.ts
1152
1368
  async function generateObject({
1153
1369
  model,
@@ -1162,7 +1378,7 @@ async function generateObject({
1162
1378
  experimental_telemetry: telemetry,
1163
1379
  ...settings
1164
1380
  }) {
1165
- var _a;
1381
+ var _a9;
1166
1382
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
1167
1383
  model,
1168
1384
  telemetry,
@@ -1170,7 +1386,7 @@ async function generateObject({
1170
1386
  settings: { ...settings, maxRetries }
1171
1387
  });
1172
1388
  const schema = asSchema(inputSchema);
1173
- const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
1389
+ const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
1174
1390
  return recordSpan({
1175
1391
  name: "ai.generateObject",
1176
1392
  attributes: selectTelemetryAttributes({
@@ -1255,7 +1471,7 @@ async function generateObject({
1255
1471
  headers
1256
1472
  });
1257
1473
  if (result2.text === void 0) {
1258
- throw new import_provider6.NoObjectGeneratedError();
1474
+ throw new NoObjectGeneratedError();
1259
1475
  }
1260
1476
  span2.setAttributes(
1261
1477
  selectTelemetryAttributes({
@@ -1323,7 +1539,7 @@ async function generateObject({
1323
1539
  }),
1324
1540
  tracer,
1325
1541
  fn: async (span2) => {
1326
- var _a2, _b;
1542
+ var _a10, _b;
1327
1543
  const result2 = await model.doGenerate({
1328
1544
  mode: {
1329
1545
  type: "object-tool",
@@ -1340,9 +1556,9 @@ async function generateObject({
1340
1556
  abortSignal,
1341
1557
  headers
1342
1558
  });
1343
- const objectText = (_b = (_a2 = result2.toolCalls) == null ? void 0 : _a2[0]) == null ? void 0 : _b.args;
1559
+ const objectText = (_b = (_a10 = result2.toolCalls) == null ? void 0 : _a10[0]) == null ? void 0 : _b.args;
1344
1560
  if (objectText === void 0) {
1345
- throw new import_provider6.NoObjectGeneratedError();
1561
+ throw new NoObjectGeneratedError();
1346
1562
  }
1347
1563
  span2.setAttributes(
1348
1564
  selectTelemetryAttributes({
@@ -1419,9 +1635,9 @@ var DefaultGenerateObjectResult = class {
1419
1635
  this.logprobs = options.logprobs;
1420
1636
  }
1421
1637
  toJsonResponse(init) {
1422
- var _a;
1638
+ var _a9;
1423
1639
  return new Response(JSON.stringify(this.object), {
1424
- status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
1640
+ status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
1425
1641
  headers: prepareResponseHeaders(init, {
1426
1642
  contentType: "application/json; charset=utf-8"
1427
1643
  })
@@ -1434,24 +1650,22 @@ var experimental_generateObject = generateObject;
1434
1650
  var import_provider_utils6 = require("@ai-sdk/provider-utils");
1435
1651
  var import_ui_utils = require("@ai-sdk/ui-utils");
1436
1652
 
1437
- // core/util/async-iterable-stream.ts
1438
- function createAsyncIterableStream(source, transformer) {
1439
- const transformedStream = source.pipeThrough(
1440
- new TransformStream(transformer)
1441
- );
1442
- transformedStream[Symbol.asyncIterator] = () => {
1443
- const reader = transformedStream.getReader();
1444
- return {
1445
- async next() {
1446
- const { done, value } = await reader.read();
1447
- return done ? { done: true, value: void 0 } : { done: false, value };
1448
- }
1449
- };
1653
+ // util/create-resolvable-promise.ts
1654
+ function createResolvablePromise() {
1655
+ let resolve;
1656
+ let reject;
1657
+ const promise = new Promise((res, rej) => {
1658
+ resolve = res;
1659
+ reject = rej;
1660
+ });
1661
+ return {
1662
+ promise,
1663
+ resolve,
1664
+ reject
1450
1665
  };
1451
- return transformedStream;
1452
1666
  }
1453
1667
 
1454
- // core/util/delayed-promise.ts
1668
+ // util/delayed-promise.ts
1455
1669
  var DelayedPromise = class {
1456
1670
  constructor() {
1457
1671
  this.status = { type: "pending" };
@@ -1474,21 +1688,38 @@ var DelayedPromise = class {
1474
1688
  return this.promise;
1475
1689
  }
1476
1690
  resolve(value) {
1477
- var _a;
1691
+ var _a9;
1478
1692
  this.status = { type: "resolved", value };
1479
1693
  if (this.promise) {
1480
- (_a = this._resolve) == null ? void 0 : _a.call(this, value);
1694
+ (_a9 = this._resolve) == null ? void 0 : _a9.call(this, value);
1481
1695
  }
1482
1696
  }
1483
1697
  reject(error) {
1484
- var _a;
1698
+ var _a9;
1485
1699
  this.status = { type: "rejected", error };
1486
1700
  if (this.promise) {
1487
- (_a = this._reject) == null ? void 0 : _a.call(this, error);
1701
+ (_a9 = this._reject) == null ? void 0 : _a9.call(this, error);
1488
1702
  }
1489
1703
  }
1490
1704
  };
1491
1705
 
1706
+ // core/util/async-iterable-stream.ts
1707
+ function createAsyncIterableStream(source, transformer) {
1708
+ const transformedStream = source.pipeThrough(
1709
+ new TransformStream(transformer)
1710
+ );
1711
+ transformedStream[Symbol.asyncIterator] = () => {
1712
+ const reader = transformedStream.getReader();
1713
+ return {
1714
+ async next() {
1715
+ const { done, value } = await reader.read();
1716
+ return done ? { done: true, value: void 0 } : { done: false, value };
1717
+ }
1718
+ };
1719
+ };
1720
+ return transformedStream;
1721
+ }
1722
+
1492
1723
  // core/generate-object/stream-object.ts
1493
1724
  async function streamObject({
1494
1725
  model,
@@ -1504,14 +1735,14 @@ async function streamObject({
1504
1735
  onFinish,
1505
1736
  ...settings
1506
1737
  }) {
1507
- var _a;
1738
+ var _a9;
1508
1739
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
1509
1740
  model,
1510
1741
  telemetry,
1511
1742
  headers,
1512
1743
  settings: { ...settings, maxRetries }
1513
1744
  });
1514
- const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
1745
+ const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
1515
1746
  const retry = retryWithExponentialBackoff({ maxRetries });
1516
1747
  const schema = asSchema(inputSchema);
1517
1748
  return recordSpan({
@@ -1690,10 +1921,8 @@ var DefaultStreamObjectResult = class {
1690
1921
  this.warnings = warnings;
1691
1922
  this.rawResponse = rawResponse;
1692
1923
  this.objectPromise = new DelayedPromise();
1693
- let resolveUsage;
1694
- this.usage = new Promise((resolve) => {
1695
- resolveUsage = resolve;
1696
- });
1924
+ const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
1925
+ this.usage = usagePromise;
1697
1926
  let usage;
1698
1927
  let finishReason;
1699
1928
  let object;
@@ -1868,8 +2097,8 @@ var DefaultStreamObjectResult = class {
1868
2097
  });
1869
2098
  }
1870
2099
  pipeTextStreamToResponse(response, init) {
1871
- var _a;
1872
- response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
2100
+ var _a9;
2101
+ response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
1873
2102
  "Content-Type": "text/plain; charset=utf-8",
1874
2103
  ...init == null ? void 0 : init.headers
1875
2104
  });
@@ -1891,9 +2120,9 @@ var DefaultStreamObjectResult = class {
1891
2120
  read();
1892
2121
  }
1893
2122
  toTextStreamResponse(init) {
1894
- var _a;
2123
+ var _a9;
1895
2124
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
1896
- status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
2125
+ status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
1897
2126
  headers: prepareResponseHeaders(init, {
1898
2127
  contentType: "text/plain; charset=utf-8"
1899
2128
  })
@@ -1919,9 +2148,9 @@ function prepareToolsAndToolChoice({
1919
2148
  };
1920
2149
  }
1921
2150
  return {
1922
- tools: Object.entries(tools).map(([name, tool2]) => ({
2151
+ tools: Object.entries(tools).map(([name9, tool2]) => ({
1923
2152
  type: "function",
1924
- name,
2153
+ name: name9,
1925
2154
  description: tool2.description,
1926
2155
  parameters: asSchema(tool2.parameters).jsonSchema
1927
2156
  })),
@@ -1930,19 +2159,106 @@ function prepareToolsAndToolChoice({
1930
2159
  }
1931
2160
 
1932
2161
  // core/generate-text/tool-call.ts
1933
- var import_provider7 = require("@ai-sdk/provider");
1934
2162
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
2163
+
2164
+ // errors/invalid-tool-arguments-error.ts
2165
+ var import_provider9 = require("@ai-sdk/provider");
2166
+ var name7 = "AI_InvalidToolArgumentsError";
2167
+ var marker7 = `vercel.ai.error.${name7}`;
2168
+ var symbol7 = Symbol.for(marker7);
2169
+ var _a7;
2170
+ var InvalidToolArgumentsError = class extends import_provider9.AISDKError {
2171
+ constructor({
2172
+ toolArgs,
2173
+ toolName,
2174
+ cause,
2175
+ message = `Invalid arguments for tool ${toolName}: ${(0, import_provider9.getErrorMessage)(
2176
+ cause
2177
+ )}`
2178
+ }) {
2179
+ super({ name: name7, message, cause });
2180
+ this[_a7] = true;
2181
+ this.toolArgs = toolArgs;
2182
+ this.toolName = toolName;
2183
+ }
2184
+ static isInstance(error) {
2185
+ return import_provider9.AISDKError.hasMarker(error, marker7);
2186
+ }
2187
+ /**
2188
+ * @deprecated use `isInstance` instead
2189
+ */
2190
+ static isInvalidToolArgumentsError(error) {
2191
+ return error instanceof Error && error.name === name7 && typeof error.toolName === "string" && typeof error.toolArgs === "string";
2192
+ }
2193
+ /**
2194
+ * @deprecated Do not use this method. It will be removed in the next major version.
2195
+ */
2196
+ toJSON() {
2197
+ return {
2198
+ name: this.name,
2199
+ message: this.message,
2200
+ cause: this.cause,
2201
+ stack: this.stack,
2202
+ toolName: this.toolName,
2203
+ toolArgs: this.toolArgs
2204
+ };
2205
+ }
2206
+ };
2207
+ _a7 = symbol7;
2208
+
2209
+ // errors/no-such-tool-error.ts
2210
+ var import_provider10 = require("@ai-sdk/provider");
2211
+ var name8 = "AI_NoSuchToolError";
2212
+ var marker8 = `vercel.ai.error.${name8}`;
2213
+ var symbol8 = Symbol.for(marker8);
2214
+ var _a8;
2215
+ var NoSuchToolError = class extends import_provider10.AISDKError {
2216
+ constructor({
2217
+ toolName,
2218
+ availableTools = void 0,
2219
+ message = `Model tried to call unavailable tool '${toolName}'. ${availableTools === void 0 ? "No tools are available." : `Available tools: ${availableTools.join(", ")}.`}`
2220
+ }) {
2221
+ super({ name: name8, message });
2222
+ this[_a8] = true;
2223
+ this.toolName = toolName;
2224
+ this.availableTools = availableTools;
2225
+ }
2226
+ static isInstance(error) {
2227
+ return import_provider10.AISDKError.hasMarker(error, marker8);
2228
+ }
2229
+ /**
2230
+ * @deprecated use `isInstance` instead
2231
+ */
2232
+ static isNoSuchToolError(error) {
2233
+ return error instanceof Error && error.name === name8 && "toolName" in error && error.toolName != void 0 && typeof error.name === "string";
2234
+ }
2235
+ /**
2236
+ * @deprecated Do not use this method. It will be removed in the next major version.
2237
+ */
2238
+ toJSON() {
2239
+ return {
2240
+ name: this.name,
2241
+ message: this.message,
2242
+ stack: this.stack,
2243
+ toolName: this.toolName,
2244
+ availableTools: this.availableTools
2245
+ };
2246
+ }
2247
+ };
2248
+ _a8 = symbol8;
2249
+
2250
+ // core/generate-text/tool-call.ts
1935
2251
  function parseToolCall({
1936
2252
  toolCall,
1937
2253
  tools
1938
2254
  }) {
1939
2255
  const toolName = toolCall.toolName;
1940
2256
  if (tools == null) {
1941
- throw new import_provider7.NoSuchToolError({ toolName: toolCall.toolName });
2257
+ throw new NoSuchToolError({ toolName: toolCall.toolName });
1942
2258
  }
1943
2259
  const tool2 = tools[toolName];
1944
2260
  if (tool2 == null) {
1945
- throw new import_provider7.NoSuchToolError({
2261
+ throw new NoSuchToolError({
1946
2262
  toolName: toolCall.toolName,
1947
2263
  availableTools: Object.keys(tools)
1948
2264
  });
@@ -1952,7 +2268,7 @@ function parseToolCall({
1952
2268
  schema: asSchema(tool2.parameters)
1953
2269
  });
1954
2270
  if (parseResult.success === false) {
1955
- throw new import_provider7.InvalidToolArgumentsError({
2271
+ throw new InvalidToolArgumentsError({
1956
2272
  toolName,
1957
2273
  toolArgs: toolCall.args,
1958
2274
  cause: parseResult.error
@@ -1982,14 +2298,14 @@ async function generateText({
1982
2298
  experimental_telemetry: telemetry,
1983
2299
  ...settings
1984
2300
  }) {
1985
- var _a;
2301
+ var _a9;
1986
2302
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
1987
2303
  model,
1988
2304
  telemetry,
1989
2305
  headers,
1990
2306
  settings: { ...settings, maxRetries }
1991
2307
  });
1992
- const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
2308
+ const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
1993
2309
  return recordSpan({
1994
2310
  name: "ai.generateText",
1995
2311
  attributes: selectTelemetryAttributes({
@@ -2009,7 +2325,7 @@ async function generateText({
2009
2325
  }),
2010
2326
  tracer,
2011
2327
  fn: async (span) => {
2012
- var _a2, _b, _c, _d;
2328
+ var _a10, _b, _c, _d;
2013
2329
  const retry = retryWithExponentialBackoff({ maxRetries });
2014
2330
  const validatedPrompt = getValidatedPrompt({
2015
2331
  system,
@@ -2095,7 +2411,7 @@ async function generateText({
2095
2411
  }
2096
2412
  })
2097
2413
  );
2098
- currentToolCalls = ((_a2 = currentModelResponse.toolCalls) != null ? _a2 : []).map(
2414
+ currentToolCalls = ((_a10 = currentModelResponse.toolCalls) != null ? _a10 : []).map(
2099
2415
  (modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
2100
2416
  );
2101
2417
  currentToolResults = tools == null ? [] : await executeTools({
@@ -2357,7 +2673,6 @@ function mergeStreams(stream1, stream2) {
2357
2673
  }
2358
2674
 
2359
2675
  // core/generate-text/run-tools-transformation.ts
2360
- var import_provider8 = require("@ai-sdk/provider");
2361
2676
  var import_ui_utils2 = require("@ai-sdk/ui-utils");
2362
2677
  function runToolsTransformation({
2363
2678
  tools,
@@ -2408,7 +2723,7 @@ function runToolsTransformation({
2408
2723
  if (tools == null) {
2409
2724
  toolResultsStreamController.enqueue({
2410
2725
  type: "error",
2411
- error: new import_provider8.NoSuchToolError({ toolName: chunk.toolName })
2726
+ error: new NoSuchToolError({ toolName: chunk.toolName })
2412
2727
  });
2413
2728
  break;
2414
2729
  }
@@ -2416,7 +2731,7 @@ function runToolsTransformation({
2416
2731
  if (tool2 == null) {
2417
2732
  toolResultsStreamController.enqueue({
2418
2733
  type: "error",
2419
- error: new import_provider8.NoSuchToolError({
2734
+ error: new NoSuchToolError({
2420
2735
  toolName: chunk.toolName,
2421
2736
  availableTools: Object.keys(tools)
2422
2737
  })
@@ -2560,14 +2875,14 @@ async function streamText({
2560
2875
  onFinish,
2561
2876
  ...settings
2562
2877
  }) {
2563
- var _a;
2878
+ var _a9;
2564
2879
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
2565
2880
  model,
2566
2881
  telemetry,
2567
2882
  headers,
2568
2883
  settings: { ...settings, maxRetries }
2569
2884
  });
2570
- const tracer = getTracer({ isEnabled: (_a = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a : false });
2885
+ const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
2571
2886
  return recordSpan({
2572
2887
  name: "ai.streamText",
2573
2888
  attributes: selectTelemetryAttributes({
@@ -2669,26 +2984,16 @@ var DefaultStreamTextResult = class {
2669
2984
  this.warnings = warnings;
2670
2985
  this.rawResponse = rawResponse;
2671
2986
  this.onFinish = onFinish;
2672
- let resolveUsage;
2673
- this.usage = new Promise((resolve) => {
2674
- resolveUsage = resolve;
2675
- });
2676
- let resolveFinishReason;
2677
- this.finishReason = new Promise((resolve) => {
2678
- resolveFinishReason = resolve;
2679
- });
2680
- let resolveText;
2681
- this.text = new Promise((resolve) => {
2682
- resolveText = resolve;
2683
- });
2684
- let resolveToolCalls;
2685
- this.toolCalls = new Promise((resolve) => {
2686
- resolveToolCalls = resolve;
2687
- });
2688
- let resolveToolResults;
2689
- this.toolResults = new Promise((resolve) => {
2690
- resolveToolResults = resolve;
2691
- });
2987
+ const { resolve: resolveUsage, promise: usagePromise } = createResolvablePromise();
2988
+ this.usage = usagePromise;
2989
+ const { resolve: resolveFinishReason, promise: finishReasonPromise } = createResolvablePromise();
2990
+ this.finishReason = finishReasonPromise;
2991
+ const { resolve: resolveText, promise: textPromise } = createResolvablePromise();
2992
+ this.text = textPromise;
2993
+ const { resolve: resolveToolCalls, promise: toolCallsPromise } = createResolvablePromise();
2994
+ this.toolCalls = toolCallsPromise;
2995
+ const { resolve: resolveToolResults, promise: toolResultsPromise } = createResolvablePromise();
2996
+ this.toolResults = toolResultsPromise;
2692
2997
  let finishReason;
2693
2998
  let usage;
2694
2999
  let text = "";
@@ -2735,7 +3040,7 @@ var DefaultStreamTextResult = class {
2735
3040
  },
2736
3041
  // invoke onFinish callback and resolve toolResults promise when the stream is about to close:
2737
3042
  async flush(controller) {
2738
- var _a;
3043
+ var _a9;
2739
3044
  try {
2740
3045
  const finalUsage = usage != null ? usage : {
2741
3046
  promptTokens: NaN,
@@ -2774,7 +3079,7 @@ var DefaultStreamTextResult = class {
2774
3079
  })
2775
3080
  );
2776
3081
  resolveToolResults(toolResults);
2777
- await ((_a = self.onFinish) == null ? void 0 : _a.call(self, {
3082
+ await ((_a9 = self.onFinish) == null ? void 0 : _a9.call(self, {
2778
3083
  finishReason: finalFinishReason,
2779
3084
  usage: finalUsage,
2780
3085
  text,
@@ -2929,8 +3234,8 @@ var DefaultStreamTextResult = class {
2929
3234
  return this.pipeDataStreamToResponse(response, init);
2930
3235
  }
2931
3236
  pipeDataStreamToResponse(response, init) {
2932
- var _a;
2933
- response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
3237
+ var _a9;
3238
+ response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
2934
3239
  "Content-Type": "text/plain; charset=utf-8",
2935
3240
  ...init == null ? void 0 : init.headers
2936
3241
  });
@@ -2952,8 +3257,8 @@ var DefaultStreamTextResult = class {
2952
3257
  read();
2953
3258
  }
2954
3259
  pipeTextStreamToResponse(response, init) {
2955
- var _a;
2956
- response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
3260
+ var _a9;
3261
+ response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
2957
3262
  "Content-Type": "text/plain; charset=utf-8",
2958
3263
  ...init == null ? void 0 : init.headers
2959
3264
  });
@@ -2978,7 +3283,7 @@ var DefaultStreamTextResult = class {
2978
3283
  return this.toDataStreamResponse(options);
2979
3284
  }
2980
3285
  toDataStreamResponse(options) {
2981
- var _a;
3286
+ var _a9;
2982
3287
  const init = options == null ? void 0 : "init" in options ? options.init : {
2983
3288
  headers: "headers" in options ? options.headers : void 0,
2984
3289
  status: "status" in options ? options.status : void 0,
@@ -2987,7 +3292,7 @@ var DefaultStreamTextResult = class {
2987
3292
  const data = options == null ? void 0 : "data" in options ? options.data : void 0;
2988
3293
  const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
2989
3294
  return new Response(stream, {
2990
- status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
3295
+ status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
2991
3296
  statusText: init == null ? void 0 : init.statusText,
2992
3297
  headers: prepareResponseHeaders(init, {
2993
3298
  contentType: "text/plain; charset=utf-8",
@@ -2996,9 +3301,9 @@ var DefaultStreamTextResult = class {
2996
3301
  });
2997
3302
  }
2998
3303
  toTextStreamResponse(init) {
2999
- var _a;
3304
+ var _a9;
3000
3305
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
3001
- status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
3306
+ status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
3002
3307
  headers: prepareResponseHeaders(init, {
3003
3308
  contentType: "text/plain; charset=utf-8"
3004
3309
  })
@@ -3009,7 +3314,7 @@ var experimental_streamText = streamText;
3009
3314
 
3010
3315
  // core/prompt/attachments-to-parts.ts
3011
3316
  function attachmentsToParts(attachments) {
3012
- var _a, _b, _c;
3317
+ var _a9, _b, _c;
3013
3318
  const parts = [];
3014
3319
  for (const attachment of attachments) {
3015
3320
  let url;
@@ -3021,7 +3326,7 @@ function attachmentsToParts(attachments) {
3021
3326
  switch (url.protocol) {
3022
3327
  case "http:":
3023
3328
  case "https:": {
3024
- if ((_a = attachment.contentType) == null ? void 0 : _a.startsWith("image/")) {
3329
+ if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
3025
3330
  parts.push({ type: "image", image: url });
3026
3331
  }
3027
3332
  break;
@@ -3238,18 +3543,18 @@ var DefaultProviderRegistry = class {
3238
3543
  return [id.slice(0, index), id.slice(index + 1)];
3239
3544
  }
3240
3545
  languageModel(id) {
3241
- var _a, _b;
3546
+ var _a9, _b;
3242
3547
  const [providerId, modelId] = this.splitId(id);
3243
- const model = (_b = (_a = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a, modelId);
3548
+ const model = (_b = (_a9 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a9, modelId);
3244
3549
  if (model == null) {
3245
3550
  throw new NoSuchModelError({ modelId: id, modelType: "language model" });
3246
3551
  }
3247
3552
  return model;
3248
3553
  }
3249
3554
  textEmbeddingModel(id) {
3250
- var _a, _b;
3555
+ var _a9, _b;
3251
3556
  const [providerId, modelId] = this.splitId(id);
3252
- const model = (_b = (_a = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a, modelId);
3557
+ const model = (_b = (_a9 = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a9, modelId);
3253
3558
  if (model == null) {
3254
3559
  throw new NoSuchModelError({
3255
3560
  modelId: id,
@@ -3265,9 +3570,6 @@ function tool(tool2) {
3265
3570
  return tool2;
3266
3571
  }
3267
3572
 
3268
- // core/types/errors.ts
3269
- var import_provider9 = require("@ai-sdk/provider");
3270
-
3271
3573
  // core/util/cosine-similarity.ts
3272
3574
  function cosineSimilarity(vector1, vector2) {
3273
3575
  if (vector1.length !== vector2.length) {
@@ -3287,6 +3589,9 @@ function magnitude(vector) {
3287
3589
  return Math.sqrt(dotProduct(vector, vector));
3288
3590
  }
3289
3591
 
3592
+ // errors/index.ts
3593
+ var import_provider11 = require("@ai-sdk/provider");
3594
+
3290
3595
  // streams/ai-stream.ts
3291
3596
  var import_eventsource_parser = require("eventsource-parser");
3292
3597
  function createEventStreamTransformer(customParser) {
@@ -3403,8 +3708,8 @@ function readableFromAsyncIterable(iterable) {
3403
3708
  controller.enqueue(value);
3404
3709
  },
3405
3710
  async cancel(reason) {
3406
- var _a;
3407
- await ((_a = it.return) == null ? void 0 : _a.call(it, reason));
3711
+ var _a9;
3712
+ await ((_a9 = it.return) == null ? void 0 : _a9.call(it, reason));
3408
3713
  }
3409
3714
  });
3410
3715
  }
@@ -3536,7 +3841,7 @@ var import_ui_utils4 = require("@ai-sdk/ui-utils");
3536
3841
  function AssistantResponse({ threadId, messageId }, process2) {
3537
3842
  const stream = new ReadableStream({
3538
3843
  async start(controller) {
3539
- var _a;
3844
+ var _a9;
3540
3845
  const textEncoder = new TextEncoder();
3541
3846
  const sendMessage = (message) => {
3542
3847
  controller.enqueue(
@@ -3554,7 +3859,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
3554
3859
  );
3555
3860
  };
3556
3861
  const forwardStream = async (stream2) => {
3557
- var _a2, _b;
3862
+ var _a10, _b;
3558
3863
  let result = void 0;
3559
3864
  for await (const value of stream2) {
3560
3865
  switch (value.event) {
@@ -3571,7 +3876,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
3571
3876
  break;
3572
3877
  }
3573
3878
  case "thread.message.delta": {
3574
- const content = (_a2 = value.data.delta.content) == null ? void 0 : _a2[0];
3879
+ const content = (_a10 = value.data.delta.content) == null ? void 0 : _a10[0];
3575
3880
  if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
3576
3881
  controller.enqueue(
3577
3882
  textEncoder.encode(
@@ -3607,7 +3912,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
3607
3912
  forwardStream
3608
3913
  });
3609
3914
  } catch (error) {
3610
- sendError((_a = error.message) != null ? _a : `${error}`);
3915
+ sendError((_a9 = error.message) != null ? _a9 : `${error}`);
3611
3916
  } finally {
3612
3917
  controller.close();
3613
3918
  }
@@ -3628,9 +3933,9 @@ var experimental_AssistantResponse = AssistantResponse;
3628
3933
 
3629
3934
  // streams/aws-bedrock-stream.ts
3630
3935
  async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
3631
- var _a, _b;
3936
+ var _a9, _b;
3632
3937
  const decoder = new TextDecoder();
3633
- for await (const chunk of (_a = response.body) != null ? _a : []) {
3938
+ for await (const chunk of (_a9 = response.body) != null ? _a9 : []) {
3634
3939
  const bytes = (_b = chunk.chunk) == null ? void 0 : _b.bytes;
3635
3940
  if (bytes != null) {
3636
3941
  const chunkText = decoder.decode(bytes);
@@ -3644,8 +3949,8 @@ async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
3644
3949
  }
3645
3950
  function AWSBedrockAnthropicMessagesStream(response, callbacks) {
3646
3951
  return AWSBedrockStream(response, callbacks, (chunk) => {
3647
- var _a;
3648
- return (_a = chunk.delta) == null ? void 0 : _a.text;
3952
+ var _a9;
3953
+ return (_a9 = chunk.delta) == null ? void 0 : _a9.text;
3649
3954
  });
3650
3955
  }
3651
3956
  function AWSBedrockAnthropicStream(response, callbacks) {
@@ -3692,8 +3997,8 @@ async function readAndProcessLines(reader, controller) {
3692
3997
  controller.close();
3693
3998
  }
3694
3999
  function createParser2(res) {
3695
- var _a;
3696
- const reader = (_a = res.body) == null ? void 0 : _a.getReader();
4000
+ var _a9;
4001
+ const reader = (_a9 = res.body) == null ? void 0 : _a9.getReader();
3697
4002
  return new ReadableStream({
3698
4003
  async start(controller) {
3699
4004
  if (!reader) {
@@ -3723,9 +4028,9 @@ function CohereStream(reader, callbacks) {
3723
4028
 
3724
4029
  // streams/google-generative-ai-stream.ts
3725
4030
  async function* streamable3(response) {
3726
- var _a, _b, _c;
4031
+ var _a9, _b, _c;
3727
4032
  for await (const chunk of response.stream) {
3728
- const parts = (_c = (_b = (_a = chunk.candidates) == null ? void 0 : _a[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
4033
+ const parts = (_c = (_b = (_a9 = chunk.candidates) == null ? void 0 : _a9[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
3729
4034
  if (parts === void 0) {
3730
4035
  continue;
3731
4036
  }
@@ -3744,13 +4049,13 @@ function createParser3(res) {
3744
4049
  const trimStartOfStream = trimStartOfStreamHelper();
3745
4050
  return new ReadableStream({
3746
4051
  async pull(controller) {
3747
- var _a, _b;
4052
+ var _a9, _b;
3748
4053
  const { value, done } = await res.next();
3749
4054
  if (done) {
3750
4055
  controller.close();
3751
4056
  return;
3752
4057
  }
3753
- const text = trimStartOfStream((_b = (_a = value.token) == null ? void 0 : _a.text) != null ? _b : "");
4058
+ const text = trimStartOfStream((_b = (_a9 = value.token) == null ? void 0 : _a9.text) != null ? _b : "");
3754
4059
  if (!text)
3755
4060
  return;
3756
4061
  if (value.generated_text != null && value.generated_text.length > 0) {
@@ -3775,11 +4080,11 @@ function InkeepStream(res, callbacks) {
3775
4080
  let chat_session_id = "";
3776
4081
  let records_cited;
3777
4082
  const inkeepEventParser = (data, options) => {
3778
- var _a, _b;
4083
+ var _a9, _b;
3779
4084
  const { event } = options;
3780
4085
  if (event === "records_cited") {
3781
4086
  records_cited = JSON.parse(data);
3782
- (_a = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a.call(callbacks, records_cited);
4087
+ (_a9 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a9.call(callbacks, records_cited);
3783
4088
  }
3784
4089
  if (event === "message_chunk") {
3785
4090
  const inkeepMessageChunk = JSON.parse(data);
@@ -3792,12 +4097,12 @@ function InkeepStream(res, callbacks) {
3792
4097
  passThroughCallbacks = {
3793
4098
  ...passThroughCallbacks,
3794
4099
  onFinal: (completion) => {
3795
- var _a;
4100
+ var _a9;
3796
4101
  const inkeepOnFinalMetadata = {
3797
4102
  chat_session_id,
3798
4103
  records_cited
3799
4104
  };
3800
- (_a = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a.call(callbacks, completion, inkeepOnFinalMetadata);
4105
+ (_a9 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a9.call(callbacks, completion, inkeepOnFinalMetadata);
3801
4106
  }
3802
4107
  };
3803
4108
  return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
@@ -3819,7 +4124,7 @@ function toDataStream(stream, callbacks) {
3819
4124
  return stream.pipeThrough(
3820
4125
  new TransformStream({
3821
4126
  transform: async (value, controller) => {
3822
- var _a;
4127
+ var _a9;
3823
4128
  if (typeof value === "string") {
3824
4129
  controller.enqueue(value);
3825
4130
  return;
@@ -3827,7 +4132,7 @@ function toDataStream(stream, callbacks) {
3827
4132
  if ("event" in value) {
3828
4133
  if (value.event === "on_chat_model_stream") {
3829
4134
  forwardAIMessageChunk(
3830
- (_a = value.data) == null ? void 0 : _a.chunk,
4135
+ (_a9 = value.data) == null ? void 0 : _a9.chunk,
3831
4136
  controller
3832
4137
  );
3833
4138
  }
@@ -3839,13 +4144,13 @@ function toDataStream(stream, callbacks) {
3839
4144
  ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
3840
4145
  }
3841
4146
  function toDataStreamResponse(stream, options) {
3842
- var _a;
4147
+ var _a9;
3843
4148
  const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
3844
4149
  const data = options == null ? void 0 : options.data;
3845
4150
  const init = options == null ? void 0 : options.init;
3846
4151
  const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
3847
4152
  return new Response(responseStream, {
3848
- status: (_a = init == null ? void 0 : init.status) != null ? _a : 200,
4153
+ status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
3849
4154
  statusText: init == null ? void 0 : init.statusText,
3850
4155
  headers: prepareResponseHeaders(init, {
3851
4156
  contentType: "text/plain; charset=utf-8",
@@ -3927,9 +4232,9 @@ function LangChainStream(callbacks) {
3927
4232
 
3928
4233
  // streams/mistral-stream.ts
3929
4234
  async function* streamable4(stream) {
3930
- var _a, _b;
4235
+ var _a9, _b;
3931
4236
  for await (const chunk of stream) {
3932
- const content = (_b = (_a = chunk.choices[0]) == null ? void 0 : _a.delta) == null ? void 0 : _b.content;
4237
+ const content = (_b = (_a9 = chunk.choices[0]) == null ? void 0 : _a9.delta) == null ? void 0 : _b.content;
3933
4238
  if (content === void 0 || content === "") {
3934
4239
  continue;
3935
4240
  }
@@ -3959,10 +4264,10 @@ async function* streamable5(stream) {
3959
4264
  model: chunk.model,
3960
4265
  // not exposed by Azure API
3961
4266
  choices: chunk.choices.map((choice) => {
3962
- var _a, _b, _c, _d, _e, _f, _g;
4267
+ var _a9, _b, _c, _d, _e, _f, _g;
3963
4268
  return {
3964
4269
  delta: {
3965
- content: (_a = choice.delta) == null ? void 0 : _a.content,
4270
+ content: (_a9 = choice.delta) == null ? void 0 : _a9.content,
3966
4271
  function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
3967
4272
  role: (_c = choice.delta) == null ? void 0 : _c.role,
3968
4273
  tool_calls: ((_e = (_d = choice.delta) == null ? void 0 : _d.toolCalls) == null ? void 0 : _e.length) ? (_g = (_f = choice.delta) == null ? void 0 : _f.toolCalls) == null ? void 0 : _g.map((toolCall, index) => ({
@@ -3987,9 +4292,9 @@ function chunkToText() {
3987
4292
  const trimStartOfStream = trimStartOfStreamHelper();
3988
4293
  let isFunctionStreamingIn;
3989
4294
  return (json) => {
3990
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
4295
+ var _a9, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
3991
4296
  if (isChatCompletionChunk(json)) {
3992
- const delta = (_a = json.choices[0]) == null ? void 0 : _a.delta;
4297
+ const delta = (_a9 = json.choices[0]) == null ? void 0 : _a9.delta;
3993
4298
  if ((_b = delta.function_call) == null ? void 0 : _b.name) {
3994
4299
  isFunctionStreamingIn = true;
3995
4300
  return {
@@ -4262,8 +4567,8 @@ function createFunctionCallTransformer(callbacks) {
4262
4567
 
4263
4568
  // streams/replicate-stream.ts
4264
4569
  async function ReplicateStream(res, cb, options) {
4265
- var _a;
4266
- const url = (_a = res.urls) == null ? void 0 : _a.stream;
4570
+ var _a9;
4571
+ const url = (_a9 = res.urls) == null ? void 0 : _a9.stream;
4267
4572
  if (!url) {
4268
4573
  if (res.error)
4269
4574
  throw new Error(res.error);
@@ -4284,8 +4589,8 @@ async function ReplicateStream(res, cb, options) {
4284
4589
 
4285
4590
  // streams/stream-to-response.ts
4286
4591
  function streamToResponse(res, response, init, data) {
4287
- var _a;
4288
- response.writeHead((_a = init == null ? void 0 : init.status) != null ? _a : 200, {
4592
+ var _a9;
4593
+ response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
4289
4594
  "Content-Type": "text/plain; charset=utf-8",
4290
4595
  ...init == null ? void 0 : init.headers
4291
4596
  });
@@ -4329,6 +4634,7 @@ var generateId2 = import_provider_utils8.generateId;
4329
4634
  var nanoid = import_provider_utils8.generateId;
4330
4635
  // Annotate the CommonJS export names for ESM import in node:
4331
4636
  0 && (module.exports = {
4637
+ AISDKError,
4332
4638
  AIStream,
4333
4639
  APICallError,
4334
4640
  AWSBedrockAnthropicMessagesStream,
@@ -4339,6 +4645,7 @@ var nanoid = import_provider_utils8.generateId;
4339
4645
  AnthropicStream,
4340
4646
  AssistantResponse,
4341
4647
  CohereStream,
4648
+ DownloadError,
4342
4649
  EmptyResponseBodyError,
4343
4650
  GoogleGenerativeAIStream,
4344
4651
  HuggingFaceStream,
@@ -4364,10 +4671,8 @@ var nanoid = import_provider_utils8.generateId;
4364
4671
  RetryError,
4365
4672
  StreamData,
4366
4673
  StreamingTextResponse,
4367
- ToolCallParseError,
4368
4674
  TypeValidationError,
4369
4675
  UnsupportedFunctionalityError,
4370
- UnsupportedJSONSchemaError,
4371
4676
  convertDataContentToBase64String,
4372
4677
  convertDataContentToUint8Array,
4373
4678
  convertToCoreMessages,