ai 3.3.4 → 3.3.6

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
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
- for (var name9 in all)
10
- __defProp(target, name9, { get: all[name9], enumerable: true });
7
+ for (var name12 in all)
8
+ __defProp(target, name12, { get: all[name12], enumerable: true });
11
9
  };
12
10
  var __copyProps = (to, from, except, desc) => {
13
11
  if (from && typeof from === "object" || typeof from === "function") {
@@ -17,22 +15,14 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // streams/index.ts
31
21
  var streams_exports = {};
32
22
  __export(streams_exports, {
33
- AISDKError: () => import_provider11.AISDKError,
23
+ AISDKError: () => import_provider14.AISDKError,
34
24
  AIStream: () => AIStream,
35
- APICallError: () => import_provider11.APICallError,
25
+ APICallError: () => import_provider14.APICallError,
36
26
  AWSBedrockAnthropicMessagesStream: () => AWSBedrockAnthropicMessagesStream,
37
27
  AWSBedrockAnthropicStream: () => AWSBedrockAnthropicStream,
38
28
  AWSBedrockCohereStream: () => AWSBedrockCohereStream,
@@ -42,7 +32,7 @@ __export(streams_exports, {
42
32
  AssistantResponse: () => AssistantResponse,
43
33
  CohereStream: () => CohereStream,
44
34
  DownloadError: () => DownloadError,
45
- EmptyResponseBodyError: () => import_provider11.EmptyResponseBodyError,
35
+ EmptyResponseBodyError: () => import_provider14.EmptyResponseBodyError,
46
36
  GoogleGenerativeAIStream: () => GoogleGenerativeAIStream,
47
37
  HuggingFaceStream: () => HuggingFaceStream,
48
38
  InkeepStream: () => InkeepStream,
@@ -50,13 +40,13 @@ __export(streams_exports, {
50
40
  InvalidDataContentError: () => InvalidDataContentError,
51
41
  InvalidMessageRoleError: () => InvalidMessageRoleError,
52
42
  InvalidModelIdError: () => InvalidModelIdError,
53
- InvalidPromptError: () => import_provider11.InvalidPromptError,
54
- InvalidResponseDataError: () => import_provider11.InvalidResponseDataError,
43
+ InvalidPromptError: () => import_provider14.InvalidPromptError,
44
+ InvalidResponseDataError: () => import_provider14.InvalidResponseDataError,
55
45
  InvalidToolArgumentsError: () => InvalidToolArgumentsError,
56
- JSONParseError: () => import_provider11.JSONParseError,
46
+ JSONParseError: () => import_provider14.JSONParseError,
57
47
  LangChainAdapter: () => langchain_adapter_exports,
58
48
  LangChainStream: () => LangChainStream,
59
- LoadAPIKeyError: () => import_provider11.LoadAPIKeyError,
49
+ LoadAPIKeyError: () => import_provider14.LoadAPIKeyError,
60
50
  MistralStream: () => MistralStream,
61
51
  NoObjectGeneratedError: () => NoObjectGeneratedError,
62
52
  NoSuchModelError: () => NoSuchModelError,
@@ -67,8 +57,8 @@ __export(streams_exports, {
67
57
  RetryError: () => RetryError,
68
58
  StreamData: () => StreamData2,
69
59
  StreamingTextResponse: () => StreamingTextResponse,
70
- TypeValidationError: () => import_provider11.TypeValidationError,
71
- UnsupportedFunctionalityError: () => import_provider11.UnsupportedFunctionalityError,
60
+ TypeValidationError: () => import_provider14.TypeValidationError,
61
+ UnsupportedFunctionalityError: () => import_provider14.UnsupportedFunctionalityError,
72
62
  convertDataContentToBase64String: () => convertDataContentToBase64String,
73
63
  convertDataContentToUint8Array: () => convertDataContentToUint8Array,
74
64
  convertToCoreMessages: () => convertToCoreMessages,
@@ -87,15 +77,15 @@ __export(streams_exports, {
87
77
  experimental_generateText: () => experimental_generateText,
88
78
  experimental_streamObject: () => experimental_streamObject,
89
79
  experimental_streamText: () => experimental_streamText,
90
- formatStreamPart: () => import_ui_utils6.formatStreamPart,
80
+ formatStreamPart: () => import_ui_utils10.formatStreamPart,
91
81
  generateId: () => generateId2,
92
82
  generateObject: () => generateObject,
93
83
  generateText: () => generateText,
94
- jsonSchema: () => jsonSchema,
84
+ jsonSchema: () => import_ui_utils6.jsonSchema,
95
85
  nanoid: () => nanoid,
96
- parseComplexResponse: () => import_ui_utils6.parseComplexResponse,
97
- parseStreamPart: () => import_ui_utils6.parseStreamPart,
98
- readDataStream: () => import_ui_utils6.readDataStream,
86
+ parseComplexResponse: () => import_ui_utils10.parseComplexResponse,
87
+ parseStreamPart: () => import_ui_utils10.parseStreamPart,
88
+ readDataStream: () => import_ui_utils10.readDataStream,
99
89
  readableFromAsyncIterable: () => readableFromAsyncIterable,
100
90
  streamObject: () => streamObject,
101
91
  streamText: () => streamText,
@@ -104,8 +94,11 @@ __export(streams_exports, {
104
94
  trimStartOfStreamHelper: () => trimStartOfStreamHelper
105
95
  });
106
96
  module.exports = __toCommonJS(streams_exports);
97
+ var import_ui_utils10 = require("@ai-sdk/ui-utils");
98
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
99
+
100
+ // core/index.ts
107
101
  var import_ui_utils6 = require("@ai-sdk/ui-utils");
108
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
109
102
 
110
103
  // util/retry-with-exponential-backoff.ts
111
104
  var import_provider2 = require("@ai-sdk/provider");
@@ -228,7 +221,7 @@ function getBaseTelemetryAttributes({
228
221
  telemetry,
229
222
  headers
230
223
  }) {
231
- var _a9;
224
+ var _a12;
232
225
  return {
233
226
  "ai.model.provider": model.provider,
234
227
  "ai.model.id": model.modelId,
@@ -241,7 +234,7 @@ function getBaseTelemetryAttributes({
241
234
  "resource.name": telemetry == null ? void 0 : telemetry.functionId,
242
235
  "ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
243
236
  // add metadata as attributes:
244
- ...Object.entries((_a9 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a9 : {}).reduce(
237
+ ...Object.entries((_a12 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a12 : {}).reduce(
245
238
  (attributes, [key, value]) => {
246
239
  attributes[`ai.telemetry.metadata.${key}`] = value;
247
240
  return attributes;
@@ -266,7 +259,7 @@ var noopTracer = {
266
259
  startSpan() {
267
260
  return noopSpan;
268
261
  },
269
- startActiveSpan(name9, arg1, arg2, arg3) {
262
+ startActiveSpan(name12, arg1, arg2, arg3) {
270
263
  if (typeof arg1 === "function") {
271
264
  return arg1(noopSpan);
272
265
  }
@@ -334,13 +327,13 @@ function getTracer({ isEnabled }) {
334
327
  // core/telemetry/record-span.ts
335
328
  var import_api2 = require("@opentelemetry/api");
336
329
  function recordSpan({
337
- name: name9,
330
+ name: name12,
338
331
  tracer,
339
332
  attributes,
340
333
  fn,
341
334
  endWhenDone = true
342
335
  }) {
343
- return tracer.startActiveSpan(name9, { attributes }, async (span) => {
336
+ return tracer.startActiveSpan(name12, { attributes }, async (span) => {
344
337
  try {
345
338
  const result = await fn(span);
346
339
  if (endWhenDone) {
@@ -406,14 +399,14 @@ async function embed({
406
399
  headers,
407
400
  experimental_telemetry: telemetry
408
401
  }) {
409
- var _a9;
402
+ var _a12;
410
403
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
411
404
  model,
412
405
  telemetry,
413
406
  headers,
414
407
  settings: { maxRetries }
415
408
  });
416
- const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
409
+ const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
417
410
  return recordSpan({
418
411
  name: "ai.embed",
419
412
  attributes: selectTelemetryAttributes({
@@ -446,14 +439,14 @@ async function embed({
446
439
  }),
447
440
  tracer,
448
441
  fn: async (doEmbedSpan) => {
449
- var _a10;
442
+ var _a13;
450
443
  const modelResponse = await model.doEmbed({
451
444
  values: [value],
452
445
  abortSignal,
453
446
  headers
454
447
  });
455
448
  const embedding2 = modelResponse.embeddings[0];
456
- const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
449
+ const usage2 = (_a13 = modelResponse.usage) != null ? _a13 : { tokens: NaN };
457
450
  doEmbedSpan.setAttributes(
458
451
  selectTelemetryAttributes({
459
452
  telemetry,
@@ -519,14 +512,14 @@ async function embedMany({
519
512
  headers,
520
513
  experimental_telemetry: telemetry
521
514
  }) {
522
- var _a9;
515
+ var _a12;
523
516
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
524
517
  model,
525
518
  telemetry,
526
519
  headers,
527
520
  settings: { maxRetries }
528
521
  });
529
- const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
522
+ const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
530
523
  return recordSpan({
531
524
  name: "ai.embedMany",
532
525
  attributes: selectTelemetryAttributes({
@@ -564,14 +557,14 @@ async function embedMany({
564
557
  }),
565
558
  tracer,
566
559
  fn: async (doEmbedSpan) => {
567
- var _a10;
560
+ var _a13;
568
561
  const modelResponse = await model.doEmbed({
569
562
  values,
570
563
  abortSignal,
571
564
  headers
572
565
  });
573
566
  const embeddings3 = modelResponse.embeddings;
574
- const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
567
+ const usage2 = (_a13 = modelResponse.usage) != null ? _a13 : { tokens: NaN };
575
568
  doEmbedSpan.setAttributes(
576
569
  selectTelemetryAttributes({
577
570
  telemetry,
@@ -623,14 +616,14 @@ async function embedMany({
623
616
  }),
624
617
  tracer,
625
618
  fn: async (doEmbedSpan) => {
626
- var _a10;
619
+ var _a13;
627
620
  const modelResponse = await model.doEmbed({
628
621
  values: chunk,
629
622
  abortSignal,
630
623
  headers
631
624
  });
632
625
  const embeddings2 = modelResponse.embeddings;
633
- const usage2 = (_a10 = modelResponse.usage) != null ? _a10 : { tokens: NaN };
626
+ const usage2 = (_a13 = modelResponse.usage) != null ? _a13 : { tokens: NaN };
634
627
  doEmbedSpan.setAttributes(
635
628
  selectTelemetryAttributes({
636
629
  telemetry,
@@ -677,7 +670,8 @@ var DefaultEmbedManyResult = class {
677
670
  };
678
671
 
679
672
  // core/generate-object/generate-object.ts
680
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
673
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
674
+ var import_ui_utils = require("@ai-sdk/ui-utils");
681
675
 
682
676
  // core/prompt/convert-to-language-model-prompt.ts
683
677
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
@@ -732,7 +726,7 @@ async function download({
732
726
  url,
733
727
  fetchImplementation = fetch
734
728
  }) {
735
- var _a9;
729
+ var _a12;
736
730
  const urlText = url.toString();
737
731
  try {
738
732
  const response = await fetchImplementation(urlText);
@@ -745,7 +739,7 @@ async function download({
745
739
  }
746
740
  return {
747
741
  data: new Uint8Array(await response.arrayBuffer()),
748
- mimeType: (_a9 = response.headers.get("content-type")) != null ? _a9 : void 0
742
+ mimeType: (_a12 = response.headers.get("content-type")) != null ? _a12 : void 0
749
743
  };
750
744
  } catch (error) {
751
745
  if (DownloadError.isInstance(error)) {
@@ -942,7 +936,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
942
936
  role: "user",
943
937
  content: message.content.map(
944
938
  (part) => {
945
- var _a9, _b, _c;
939
+ var _a12, _b, _c;
946
940
  switch (part.type) {
947
941
  case "text": {
948
942
  return part;
@@ -960,7 +954,7 @@ function convertToLanguageModelMessage(message, downloadedImages) {
960
954
  return {
961
955
  type: "image",
962
956
  image: downloadedImage.data,
963
- mimeType: (_a9 = part.mimeType) != null ? _a9 : downloadedImage.mimeType
957
+ mimeType: (_a12 = part.mimeType) != null ? _a12 : downloadedImage.mimeType
964
958
  };
965
959
  }
966
960
  }
@@ -1264,8 +1258,8 @@ function prepareResponseHeaders(init, {
1264
1258
  contentType,
1265
1259
  dataStreamVersion
1266
1260
  }) {
1267
- var _a9;
1268
- const headers = new Headers((_a9 = init == null ? void 0 : init.headers) != null ? _a9 : {});
1261
+ var _a12;
1262
+ const headers = new Headers((_a12 = init == null ? void 0 : init.headers) != null ? _a12 : {});
1269
1263
  if (!headers.has("Content-Type")) {
1270
1264
  headers.set("Content-Type", contentType);
1271
1265
  }
@@ -1275,41 +1269,6 @@ function prepareResponseHeaders(init, {
1275
1269
  return headers;
1276
1270
  }
1277
1271
 
1278
- // core/util/schema.ts
1279
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
1280
- var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
1281
- var schemaSymbol = Symbol.for("vercel.ai.schema");
1282
- function jsonSchema(jsonSchema2, {
1283
- validate
1284
- } = {}) {
1285
- return {
1286
- [schemaSymbol]: true,
1287
- _type: void 0,
1288
- // should never be used directly
1289
- [import_provider_utils4.validatorSymbol]: true,
1290
- jsonSchema: jsonSchema2,
1291
- validate
1292
- };
1293
- }
1294
- function isSchema(value) {
1295
- return typeof value === "object" && value !== null && schemaSymbol in value && value[schemaSymbol] === true && "jsonSchema" in value && "validate" in value;
1296
- }
1297
- function asSchema(schema) {
1298
- return isSchema(schema) ? schema : zodSchema(schema);
1299
- }
1300
- function zodSchema(zodSchema2) {
1301
- return jsonSchema(
1302
- // we assume that zodToJsonSchema will return a valid JSONSchema7:
1303
- (0, import_zod_to_json_schema.default)(zodSchema2),
1304
- {
1305
- validate: (value) => {
1306
- const result = zodSchema2.safeParse(value);
1307
- return result.success ? { success: true, value: result.data } : { success: false, error: result.error };
1308
- }
1309
- }
1310
- );
1311
- }
1312
-
1313
1272
  // core/generate-object/inject-json-schema-into-system.ts
1314
1273
  var DEFAULT_SCHEMA_PREFIX = "JSON schema:";
1315
1274
  var DEFAULT_SCHEMA_SUFFIX = "You MUST answer with a JSON object that matches the JSON schema above.";
@@ -1380,15 +1339,15 @@ async function generateObject({
1380
1339
  experimental_telemetry: telemetry,
1381
1340
  ...settings
1382
1341
  }) {
1383
- var _a9;
1342
+ var _a12;
1384
1343
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
1385
1344
  model,
1386
1345
  telemetry,
1387
1346
  headers,
1388
1347
  settings: { ...settings, maxRetries }
1389
1348
  });
1390
- const schema = asSchema(inputSchema);
1391
- const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
1349
+ const schema = (0, import_ui_utils.asSchema)(inputSchema);
1350
+ const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
1392
1351
  return recordSpan({
1393
1352
  name: "ai.generateObject",
1394
1353
  attributes: selectTelemetryAttributes({
@@ -1548,7 +1507,7 @@ async function generateObject({
1548
1507
  }),
1549
1508
  tracer,
1550
1509
  fn: async (span2) => {
1551
- var _a10, _b;
1510
+ var _a13, _b;
1552
1511
  const result2 = await model.doGenerate({
1553
1512
  mode: {
1554
1513
  type: "object-tool",
@@ -1565,7 +1524,7 @@ async function generateObject({
1565
1524
  abortSignal,
1566
1525
  headers
1567
1526
  });
1568
- const objectText = (_b = (_a10 = result2.toolCalls) == null ? void 0 : _a10[0]) == null ? void 0 : _b.args;
1527
+ const objectText = (_b = (_a13 = result2.toolCalls) == null ? void 0 : _a13[0]) == null ? void 0 : _b.args;
1569
1528
  if (objectText === void 0) {
1570
1529
  throw new NoObjectGeneratedError();
1571
1530
  }
@@ -1606,7 +1565,7 @@ async function generateObject({
1606
1565
  throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
1607
1566
  }
1608
1567
  }
1609
- const parseResult = (0, import_provider_utils5.safeParseJSON)({ text: result, schema });
1568
+ const parseResult = (0, import_provider_utils4.safeParseJSON)({ text: result, schema });
1610
1569
  if (!parseResult.success) {
1611
1570
  throw parseResult.error;
1612
1571
  }
@@ -1644,9 +1603,9 @@ var DefaultGenerateObjectResult = class {
1644
1603
  this.logprobs = options.logprobs;
1645
1604
  }
1646
1605
  toJsonResponse(init) {
1647
- var _a9;
1606
+ var _a12;
1648
1607
  return new Response(JSON.stringify(this.object), {
1649
- status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
1608
+ status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
1650
1609
  headers: prepareResponseHeaders(init, {
1651
1610
  contentType: "application/json; charset=utf-8"
1652
1611
  })
@@ -1656,8 +1615,8 @@ var DefaultGenerateObjectResult = class {
1656
1615
  var experimental_generateObject = generateObject;
1657
1616
 
1658
1617
  // core/generate-object/stream-object.ts
1659
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1660
- var import_ui_utils = require("@ai-sdk/ui-utils");
1618
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
1619
+ var import_ui_utils2 = require("@ai-sdk/ui-utils");
1661
1620
 
1662
1621
  // util/create-resolvable-promise.ts
1663
1622
  function createResolvablePromise() {
@@ -1697,17 +1656,17 @@ var DelayedPromise = class {
1697
1656
  return this.promise;
1698
1657
  }
1699
1658
  resolve(value) {
1700
- var _a9;
1659
+ var _a12;
1701
1660
  this.status = { type: "resolved", value };
1702
1661
  if (this.promise) {
1703
- (_a9 = this._resolve) == null ? void 0 : _a9.call(this, value);
1662
+ (_a12 = this._resolve) == null ? void 0 : _a12.call(this, value);
1704
1663
  }
1705
1664
  }
1706
1665
  reject(error) {
1707
- var _a9;
1666
+ var _a12;
1708
1667
  this.status = { type: "rejected", error };
1709
1668
  if (this.promise) {
1710
- (_a9 = this._reject) == null ? void 0 : _a9.call(this, error);
1669
+ (_a12 = this._reject) == null ? void 0 : _a12.call(this, error);
1711
1670
  }
1712
1671
  }
1713
1672
  };
@@ -1746,16 +1705,16 @@ async function streamObject({
1746
1705
  onFinish,
1747
1706
  ...settings
1748
1707
  }) {
1749
- var _a9;
1708
+ var _a12;
1750
1709
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
1751
1710
  model,
1752
1711
  telemetry,
1753
1712
  headers,
1754
1713
  settings: { ...settings, maxRetries }
1755
1714
  });
1756
- const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
1715
+ const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
1757
1716
  const retry = retryWithExponentialBackoff({ maxRetries });
1758
- const schema = asSchema(inputSchema);
1717
+ const schema = (0, import_ui_utils2.asSchema)(inputSchema);
1759
1718
  return recordSpan({
1760
1719
  name: "ai.streamObject",
1761
1720
  attributes: selectTelemetryAttributes({
@@ -1960,10 +1919,10 @@ var DefaultStreamObjectResult = class {
1960
1919
  if (typeof chunk === "string") {
1961
1920
  accumulatedText += chunk;
1962
1921
  delta += chunk;
1963
- const currentObject = (0, import_ui_utils.parsePartialJson)(
1922
+ const currentObject = (0, import_ui_utils2.parsePartialJson)(
1964
1923
  accumulatedText
1965
1924
  );
1966
- if (!(0, import_ui_utils.isDeepEqualData)(latestObject, currentObject)) {
1925
+ if (!(0, import_ui_utils2.isDeepEqualData)(latestObject, currentObject)) {
1967
1926
  latestObject = currentObject;
1968
1927
  controller.enqueue({
1969
1928
  type: "object",
@@ -1989,7 +1948,7 @@ var DefaultStreamObjectResult = class {
1989
1948
  usage = calculateCompletionTokenUsage(chunk.usage);
1990
1949
  controller.enqueue({ ...chunk, usage });
1991
1950
  resolveUsage(usage);
1992
- const validationResult = (0, import_provider_utils6.safeValidateTypes)({
1951
+ const validationResult = (0, import_provider_utils5.safeValidateTypes)({
1993
1952
  value: latestObject,
1994
1953
  schema
1995
1954
  });
@@ -2115,8 +2074,8 @@ var DefaultStreamObjectResult = class {
2115
2074
  });
2116
2075
  }
2117
2076
  pipeTextStreamToResponse(response, init) {
2118
- var _a9;
2119
- response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
2077
+ var _a12;
2078
+ response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
2120
2079
  "Content-Type": "text/plain; charset=utf-8",
2121
2080
  ...init == null ? void 0 : init.headers
2122
2081
  });
@@ -2138,9 +2097,9 @@ var DefaultStreamObjectResult = class {
2138
2097
  read();
2139
2098
  }
2140
2099
  toTextStreamResponse(init) {
2141
- var _a9;
2100
+ var _a12;
2142
2101
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
2143
- status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
2102
+ status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
2144
2103
  headers: prepareResponseHeaders(init, {
2145
2104
  contentType: "text/plain; charset=utf-8"
2146
2105
  })
@@ -2149,6 +2108,9 @@ var DefaultStreamObjectResult = class {
2149
2108
  };
2150
2109
  var experimental_streamObject = streamObject;
2151
2110
 
2111
+ // core/prompt/prepare-tools-and-tool-choice.ts
2112
+ var import_ui_utils3 = require("@ai-sdk/ui-utils");
2113
+
2152
2114
  // core/util/is-non-empty-object.ts
2153
2115
  function isNonEmptyObject(object) {
2154
2116
  return object != null && Object.keys(object).length > 0;
@@ -2166,18 +2128,19 @@ function prepareToolsAndToolChoice({
2166
2128
  };
2167
2129
  }
2168
2130
  return {
2169
- tools: Object.entries(tools).map(([name9, tool2]) => ({
2131
+ tools: Object.entries(tools).map(([name12, tool2]) => ({
2170
2132
  type: "function",
2171
- name: name9,
2133
+ name: name12,
2172
2134
  description: tool2.description,
2173
- parameters: asSchema(tool2.parameters).jsonSchema
2135
+ parameters: (0, import_ui_utils3.asSchema)(tool2.parameters).jsonSchema
2174
2136
  })),
2175
2137
  toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
2176
2138
  };
2177
2139
  }
2178
2140
 
2179
2141
  // core/generate-text/tool-call.ts
2180
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
2142
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
2143
+ var import_ui_utils4 = require("@ai-sdk/ui-utils");
2181
2144
 
2182
2145
  // errors/invalid-tool-arguments-error.ts
2183
2146
  var import_provider9 = require("@ai-sdk/provider");
@@ -2281,9 +2244,9 @@ function parseToolCall({
2281
2244
  availableTools: Object.keys(tools)
2282
2245
  });
2283
2246
  }
2284
- const parseResult = (0, import_provider_utils7.safeParseJSON)({
2247
+ const parseResult = (0, import_provider_utils6.safeParseJSON)({
2285
2248
  text: toolCall.args,
2286
- schema: asSchema(tool2.parameters)
2249
+ schema: (0, import_ui_utils4.asSchema)(tool2.parameters)
2287
2250
  });
2288
2251
  if (parseResult.success === false) {
2289
2252
  throw new InvalidToolArgumentsError({
@@ -2316,14 +2279,14 @@ async function generateText({
2316
2279
  experimental_telemetry: telemetry,
2317
2280
  ...settings
2318
2281
  }) {
2319
- var _a9;
2282
+ var _a12;
2320
2283
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
2321
2284
  model,
2322
2285
  telemetry,
2323
2286
  headers,
2324
2287
  settings: { ...settings, maxRetries }
2325
2288
  });
2326
- const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
2289
+ const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
2327
2290
  return recordSpan({
2328
2291
  name: "ai.generateText",
2329
2292
  attributes: selectTelemetryAttributes({
@@ -2343,7 +2306,7 @@ async function generateText({
2343
2306
  }),
2344
2307
  tracer,
2345
2308
  fn: async (span) => {
2346
- var _a10, _b, _c, _d;
2309
+ var _a13, _b, _c, _d;
2347
2310
  const retry = retryWithExponentialBackoff({ maxRetries });
2348
2311
  const validatedPrompt = getValidatedPrompt({
2349
2312
  system,
@@ -2429,7 +2392,7 @@ async function generateText({
2429
2392
  }
2430
2393
  })
2431
2394
  );
2432
- currentToolCalls = ((_a10 = currentModelResponse.toolCalls) != null ? _a10 : []).map(
2395
+ currentToolCalls = ((_a13 = currentModelResponse.toolCalls) != null ? _a13 : []).map(
2433
2396
  (modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
2434
2397
  );
2435
2398
  currentToolResults = tools == null ? [] : await executeTools({
@@ -2691,7 +2654,7 @@ function mergeStreams(stream1, stream2) {
2691
2654
  }
2692
2655
 
2693
2656
  // core/generate-text/run-tools-transformation.ts
2694
- var import_ui_utils2 = require("@ai-sdk/ui-utils");
2657
+ var import_ui_utils5 = require("@ai-sdk/ui-utils");
2695
2658
  function runToolsTransformation({
2696
2659
  tools,
2697
2660
  generatorStream,
@@ -2763,7 +2726,7 @@ function runToolsTransformation({
2763
2726
  });
2764
2727
  controller.enqueue(toolCall);
2765
2728
  if (tool2.execute != null) {
2766
- const toolExecutionId = (0, import_ui_utils2.generateId)();
2729
+ const toolExecutionId = (0, import_ui_utils5.generateId)();
2767
2730
  outstandingToolCalls.add(toolExecutionId);
2768
2731
  recordSpan({
2769
2732
  name: "ai.toolCall",
@@ -2893,14 +2856,14 @@ async function streamText({
2893
2856
  onFinish,
2894
2857
  ...settings
2895
2858
  }) {
2896
- var _a9;
2859
+ var _a12;
2897
2860
  const baseTelemetryAttributes = getBaseTelemetryAttributes({
2898
2861
  model,
2899
2862
  telemetry,
2900
2863
  headers,
2901
2864
  settings: { ...settings, maxRetries }
2902
2865
  });
2903
- const tracer = getTracer({ isEnabled: (_a9 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a9 : false });
2866
+ const tracer = getTracer({ isEnabled: (_a12 = telemetry == null ? void 0 : telemetry.isEnabled) != null ? _a12 : false });
2904
2867
  return recordSpan({
2905
2868
  name: "ai.streamText",
2906
2869
  attributes: selectTelemetryAttributes({
@@ -3058,7 +3021,7 @@ var DefaultStreamTextResult = class {
3058
3021
  },
3059
3022
  // invoke onFinish callback and resolve toolResults promise when the stream is about to close:
3060
3023
  async flush(controller) {
3061
- var _a9;
3024
+ var _a12;
3062
3025
  try {
3063
3026
  const finalUsage = usage != null ? usage : {
3064
3027
  promptTokens: NaN,
@@ -3097,7 +3060,7 @@ var DefaultStreamTextResult = class {
3097
3060
  })
3098
3061
  );
3099
3062
  resolveToolResults(toolResults);
3100
- await ((_a9 = self.onFinish) == null ? void 0 : _a9.call(self, {
3063
+ await ((_a12 = self.onFinish) == null ? void 0 : _a12.call(self, {
3101
3064
  finishReason: finalFinishReason,
3102
3065
  usage: finalUsage,
3103
3066
  text,
@@ -3159,6 +3122,13 @@ var DefaultStreamTextResult = class {
3159
3122
  });
3160
3123
  }
3161
3124
  toAIStream(callbacks = {}) {
3125
+ return this.toDataStream({ callbacks });
3126
+ }
3127
+ toDataStream({
3128
+ callbacks = {},
3129
+ getErrorMessage: getErrorMessage4 = () => ""
3130
+ // mask error messages for safety by default
3131
+ } = {}) {
3162
3132
  let aggregatedResponse = "";
3163
3133
  const callbackTransformer = new TransformStream({
3164
3134
  async start() {
@@ -3188,11 +3158,11 @@ var DefaultStreamTextResult = class {
3188
3158
  const chunkType = chunk.type;
3189
3159
  switch (chunkType) {
3190
3160
  case "text-delta":
3191
- controller.enqueue((0, import_ui_utils6.formatStreamPart)("text", chunk.textDelta));
3161
+ controller.enqueue((0, import_ui_utils10.formatStreamPart)("text", chunk.textDelta));
3192
3162
  break;
3193
3163
  case "tool-call-streaming-start":
3194
3164
  controller.enqueue(
3195
- (0, import_ui_utils6.formatStreamPart)("tool_call_streaming_start", {
3165
+ (0, import_ui_utils10.formatStreamPart)("tool_call_streaming_start", {
3196
3166
  toolCallId: chunk.toolCallId,
3197
3167
  toolName: chunk.toolName
3198
3168
  })
@@ -3200,7 +3170,7 @@ var DefaultStreamTextResult = class {
3200
3170
  break;
3201
3171
  case "tool-call-delta":
3202
3172
  controller.enqueue(
3203
- (0, import_ui_utils6.formatStreamPart)("tool_call_delta", {
3173
+ (0, import_ui_utils10.formatStreamPart)("tool_call_delta", {
3204
3174
  toolCallId: chunk.toolCallId,
3205
3175
  argsTextDelta: chunk.argsTextDelta
3206
3176
  })
@@ -3208,7 +3178,7 @@ var DefaultStreamTextResult = class {
3208
3178
  break;
3209
3179
  case "tool-call":
3210
3180
  controller.enqueue(
3211
- (0, import_ui_utils6.formatStreamPart)("tool_call", {
3181
+ (0, import_ui_utils10.formatStreamPart)("tool_call", {
3212
3182
  toolCallId: chunk.toolCallId,
3213
3183
  toolName: chunk.toolName,
3214
3184
  args: chunk.args
@@ -3217,7 +3187,7 @@ var DefaultStreamTextResult = class {
3217
3187
  break;
3218
3188
  case "tool-result":
3219
3189
  controller.enqueue(
3220
- (0, import_ui_utils6.formatStreamPart)("tool_result", {
3190
+ (0, import_ui_utils10.formatStreamPart)("tool_result", {
3221
3191
  toolCallId: chunk.toolCallId,
3222
3192
  result: chunk.result
3223
3193
  })
@@ -3225,12 +3195,12 @@ var DefaultStreamTextResult = class {
3225
3195
  break;
3226
3196
  case "error":
3227
3197
  controller.enqueue(
3228
- (0, import_ui_utils6.formatStreamPart)("error", JSON.stringify(chunk.error))
3198
+ (0, import_ui_utils10.formatStreamPart)("error", getErrorMessage4(chunk.error))
3229
3199
  );
3230
3200
  break;
3231
3201
  case "finish":
3232
3202
  controller.enqueue(
3233
- (0, import_ui_utils6.formatStreamPart)("finish_message", {
3203
+ (0, import_ui_utils10.formatStreamPart)("finish_message", {
3234
3204
  finishReason: chunk.finishReason,
3235
3205
  usage: {
3236
3206
  promptTokens: chunk.usage.promptTokens,
@@ -3252,12 +3222,12 @@ var DefaultStreamTextResult = class {
3252
3222
  return this.pipeDataStreamToResponse(response, init);
3253
3223
  }
3254
3224
  pipeDataStreamToResponse(response, init) {
3255
- var _a9;
3256
- response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
3225
+ var _a12;
3226
+ response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
3257
3227
  "Content-Type": "text/plain; charset=utf-8",
3258
3228
  ...init == null ? void 0 : init.headers
3259
3229
  });
3260
- const reader = this.toAIStream().getReader();
3230
+ const reader = this.toDataStream().getReader();
3261
3231
  const read = async () => {
3262
3232
  try {
3263
3233
  while (true) {
@@ -3275,8 +3245,8 @@ var DefaultStreamTextResult = class {
3275
3245
  read();
3276
3246
  }
3277
3247
  pipeTextStreamToResponse(response, init) {
3278
- var _a9;
3279
- response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
3248
+ var _a12;
3249
+ response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
3280
3250
  "Content-Type": "text/plain; charset=utf-8",
3281
3251
  ...init == null ? void 0 : init.headers
3282
3252
  });
@@ -3301,16 +3271,17 @@ var DefaultStreamTextResult = class {
3301
3271
  return this.toDataStreamResponse(options);
3302
3272
  }
3303
3273
  toDataStreamResponse(options) {
3304
- var _a9;
3274
+ var _a12;
3305
3275
  const init = options == null ? void 0 : "init" in options ? options.init : {
3306
3276
  headers: "headers" in options ? options.headers : void 0,
3307
3277
  status: "status" in options ? options.status : void 0,
3308
3278
  statusText: "statusText" in options ? options.statusText : void 0
3309
3279
  };
3310
3280
  const data = options == null ? void 0 : "data" in options ? options.data : void 0;
3311
- const stream = data ? mergeStreams(data.stream, this.toAIStream()) : this.toAIStream();
3281
+ const getErrorMessage4 = options == null ? void 0 : "getErrorMessage" in options ? options.getErrorMessage : void 0;
3282
+ const stream = data ? mergeStreams(data.stream, this.toDataStream({ getErrorMessage: getErrorMessage4 })) : this.toDataStream({ getErrorMessage: getErrorMessage4 });
3312
3283
  return new Response(stream, {
3313
- status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
3284
+ status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
3314
3285
  statusText: init == null ? void 0 : init.statusText,
3315
3286
  headers: prepareResponseHeaders(init, {
3316
3287
  contentType: "text/plain; charset=utf-8",
@@ -3319,9 +3290,9 @@ var DefaultStreamTextResult = class {
3319
3290
  });
3320
3291
  }
3321
3292
  toTextStreamResponse(init) {
3322
- var _a9;
3293
+ var _a12;
3323
3294
  return new Response(this.textStream.pipeThrough(new TextEncoderStream()), {
3324
- status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
3295
+ status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
3325
3296
  headers: prepareResponseHeaders(init, {
3326
3297
  contentType: "text/plain; charset=utf-8"
3327
3298
  })
@@ -3332,7 +3303,7 @@ var experimental_streamText = streamText;
3332
3303
 
3333
3304
  // core/prompt/attachments-to-parts.ts
3334
3305
  function attachmentsToParts(attachments) {
3335
- var _a9, _b, _c;
3306
+ var _a12, _b, _c;
3336
3307
  const parts = [];
3337
3308
  for (const attachment of attachments) {
3338
3309
  let url;
@@ -3344,7 +3315,7 @@ function attachmentsToParts(attachments) {
3344
3315
  switch (url.protocol) {
3345
3316
  case "http:":
3346
3317
  case "https:": {
3347
- if ((_a9 = attachment.contentType) == null ? void 0 : _a9.startsWith("image/")) {
3318
+ if ((_a12 = attachment.contentType) == null ? void 0 : _a12.startsWith("image/")) {
3348
3319
  parts.push({ type: "image", image: url });
3349
3320
  }
3350
3321
  break;
@@ -3453,18 +3424,32 @@ function convertToCoreMessages(messages) {
3453
3424
  }
3454
3425
 
3455
3426
  // core/registry/invalid-model-id-error.ts
3456
- var InvalidModelIdError = class extends Error {
3427
+ var import_provider11 = require("@ai-sdk/provider");
3428
+ var name9 = "AI_InvalidModelIdError";
3429
+ var marker9 = `vercel.ai.error.${name9}`;
3430
+ var symbol9 = Symbol.for(marker9);
3431
+ var _a9;
3432
+ var InvalidModelIdError = class extends import_provider11.AISDKError {
3457
3433
  constructor({
3458
3434
  id,
3459
3435
  message = `Invalid model id: ${id}`
3460
3436
  }) {
3461
- super(message);
3462
- this.name = "AI_InvalidModelIdError";
3437
+ super({ name: name9, message });
3438
+ this[_a9] = true;
3463
3439
  this.id = id;
3464
3440
  }
3441
+ static isInstance(error) {
3442
+ return import_provider11.AISDKError.hasMarker(error, marker9);
3443
+ }
3444
+ /**
3445
+ * @deprecated use `isInstance` instead
3446
+ */
3465
3447
  static isInvalidModelIdError(error) {
3466
- return error instanceof Error && error.name === "AI_InvalidModelIdError" && typeof error.id === "string";
3448
+ return error instanceof Error && error.name === name9 && typeof error.id === "string";
3467
3449
  }
3450
+ /**
3451
+ * @deprecated Do not use this method. It will be removed in the next major version.
3452
+ */
3468
3453
  toJSON() {
3469
3454
  return {
3470
3455
  name: this.name,
@@ -3474,22 +3459,37 @@ var InvalidModelIdError = class extends Error {
3474
3459
  };
3475
3460
  }
3476
3461
  };
3462
+ _a9 = symbol9;
3477
3463
 
3478
3464
  // core/registry/no-such-model-error.ts
3479
- var NoSuchModelError = class extends Error {
3465
+ var import_provider12 = require("@ai-sdk/provider");
3466
+ var name10 = "AI_NoSuchModelError";
3467
+ var marker10 = `vercel.ai.error.${name10}`;
3468
+ var symbol10 = Symbol.for(marker10);
3469
+ var _a10;
3470
+ var NoSuchModelError = class extends import_provider12.AISDKError {
3480
3471
  constructor({
3481
3472
  modelId,
3482
3473
  modelType,
3483
3474
  message = `No such ${modelType}: ${modelId}`
3484
3475
  }) {
3485
- super(message);
3486
- this.name = "AI_NoSuchModelError";
3476
+ super({ name: name10, message });
3477
+ this[_a10] = true;
3487
3478
  this.modelId = modelId;
3488
3479
  this.modelType = modelType;
3489
3480
  }
3481
+ static isInstance(error) {
3482
+ return import_provider12.AISDKError.hasMarker(error, marker10);
3483
+ }
3484
+ /**
3485
+ * @deprecated use `isInstance` instead
3486
+ */
3490
3487
  static isNoSuchModelError(error) {
3491
- return error instanceof Error && error.name === "AI_NoSuchModelError" && typeof error.modelId === "string" && typeof error.modelType === "string";
3488
+ return error instanceof Error && error.name === name10 && typeof error.modelId === "string" && typeof error.modelType === "string";
3492
3489
  }
3490
+ /**
3491
+ * @deprecated Do not use this method. It will be removed in the next major version.
3492
+ */
3493
3493
  toJSON() {
3494
3494
  return {
3495
3495
  name: this.name,
@@ -3500,22 +3500,37 @@ var NoSuchModelError = class extends Error {
3500
3500
  };
3501
3501
  }
3502
3502
  };
3503
+ _a10 = symbol10;
3503
3504
 
3504
3505
  // core/registry/no-such-provider-error.ts
3505
- var NoSuchProviderError = class extends Error {
3506
+ var import_provider13 = require("@ai-sdk/provider");
3507
+ var name11 = "AI_NoSuchProviderError";
3508
+ var marker11 = `vercel.ai.error.${name11}`;
3509
+ var symbol11 = Symbol.for(marker11);
3510
+ var _a11;
3511
+ var NoSuchProviderError = class extends import_provider13.AISDKError {
3506
3512
  constructor({
3507
3513
  providerId,
3508
3514
  availableProviders,
3509
3515
  message = `No such provider: ${providerId} (available providers: ${availableProviders.join()})`
3510
3516
  }) {
3511
- super(message);
3512
- this.name = "AI_NoSuchProviderError";
3517
+ super({ name: name11, message });
3518
+ this[_a11] = true;
3513
3519
  this.providerId = providerId;
3514
3520
  this.availableProviders = availableProviders;
3515
3521
  }
3522
+ static isInstance(error) {
3523
+ return import_provider13.AISDKError.hasMarker(error, marker11);
3524
+ }
3525
+ /**
3526
+ * @deprecated use `isInstance` instead
3527
+ */
3516
3528
  static isNoSuchProviderError(error) {
3517
- return error instanceof Error && error.name === "AI_NoSuchProviderError" && typeof error.providerId === "string" && Array.isArray(error.availableProviders);
3529
+ return error instanceof Error && error.name === name11 && typeof error.providerId === "string" && Array.isArray(error.availableProviders);
3518
3530
  }
3531
+ /**
3532
+ * @deprecated Do not use this method. It will be removed in the next major version.
3533
+ */
3519
3534
  toJSON() {
3520
3535
  return {
3521
3536
  name: this.name,
@@ -3526,6 +3541,7 @@ var NoSuchProviderError = class extends Error {
3526
3541
  };
3527
3542
  }
3528
3543
  };
3544
+ _a11 = symbol11;
3529
3545
 
3530
3546
  // core/registry/provider-registry.ts
3531
3547
  function experimental_createProviderRegistry(providers) {
@@ -3540,7 +3556,10 @@ var DefaultProviderRegistry = class {
3540
3556
  constructor() {
3541
3557
  this.providers = {};
3542
3558
  }
3543
- registerProvider({ id, provider }) {
3559
+ registerProvider({
3560
+ id,
3561
+ provider
3562
+ }) {
3544
3563
  this.providers[id] = provider;
3545
3564
  }
3546
3565
  getProvider(id) {
@@ -3561,26 +3580,33 @@ var DefaultProviderRegistry = class {
3561
3580
  return [id.slice(0, index), id.slice(index + 1)];
3562
3581
  }
3563
3582
  languageModel(id) {
3564
- var _a9, _b;
3583
+ var _a12, _b;
3565
3584
  const [providerId, modelId] = this.splitId(id);
3566
- const model = (_b = (_a9 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a9, modelId);
3585
+ const model = (_b = (_a12 = this.getProvider(providerId)).languageModel) == null ? void 0 : _b.call(_a12, modelId);
3567
3586
  if (model == null) {
3568
- throw new NoSuchModelError({ modelId: id, modelType: "language model" });
3587
+ throw new NoSuchModelError({ modelId: id, modelType: "languageModel" });
3569
3588
  }
3570
3589
  return model;
3571
3590
  }
3572
3591
  textEmbeddingModel(id) {
3573
- var _a9, _b;
3592
+ var _a12, _b, _c;
3574
3593
  const [providerId, modelId] = this.splitId(id);
3575
- const model = (_b = (_a9 = this.getProvider(providerId)).textEmbedding) == null ? void 0 : _b.call(_a9, modelId);
3594
+ const provider = this.getProvider(providerId);
3595
+ const model = (_c = (_a12 = provider.textEmbeddingModel) == null ? void 0 : _a12.call(provider, modelId)) != null ? _c : (_b = provider.textEmbedding) == null ? void 0 : _b.call(provider, modelId);
3576
3596
  if (model == null) {
3577
3597
  throw new NoSuchModelError({
3578
3598
  modelId: id,
3579
- modelType: "text embedding model"
3599
+ modelType: "textEmbeddingModel"
3580
3600
  });
3581
3601
  }
3582
3602
  return model;
3583
3603
  }
3604
+ /**
3605
+ * @deprecated Use `textEmbeddingModel` instead.
3606
+ */
3607
+ textEmbedding(id) {
3608
+ return this.textEmbeddingModel(id);
3609
+ }
3584
3610
  };
3585
3611
 
3586
3612
  // core/tool/tool.ts
@@ -3608,7 +3634,7 @@ function magnitude(vector) {
3608
3634
  }
3609
3635
 
3610
3636
  // errors/index.ts
3611
- var import_provider11 = require("@ai-sdk/provider");
3637
+ var import_provider14 = require("@ai-sdk/provider");
3612
3638
 
3613
3639
  // streams/ai-stream.ts
3614
3640
  var import_eventsource_parser = require("eventsource-parser");
@@ -3726,14 +3752,14 @@ function readableFromAsyncIterable(iterable) {
3726
3752
  controller.enqueue(value);
3727
3753
  },
3728
3754
  async cancel(reason) {
3729
- var _a9;
3730
- await ((_a9 = it.return) == null ? void 0 : _a9.call(it, reason));
3755
+ var _a12;
3756
+ await ((_a12 = it.return) == null ? void 0 : _a12.call(it, reason));
3731
3757
  }
3732
3758
  });
3733
3759
  }
3734
3760
 
3735
3761
  // streams/stream-data.ts
3736
- var import_ui_utils3 = require("@ai-sdk/ui-utils");
3762
+ var import_ui_utils7 = require("@ai-sdk/ui-utils");
3737
3763
  var STREAM_DATA_WARNING_TIME_MS = 15 * 1e3;
3738
3764
  var StreamData2 = class {
3739
3765
  constructor() {
@@ -3781,7 +3807,7 @@ var StreamData2 = class {
3781
3807
  throw new Error("Stream controller is not initialized.");
3782
3808
  }
3783
3809
  this.controller.enqueue(
3784
- this.encoder.encode((0, import_ui_utils3.formatStreamPart)("data", [value]))
3810
+ this.encoder.encode((0, import_ui_utils7.formatStreamPart)("data", [value]))
3785
3811
  );
3786
3812
  }
3787
3813
  appendMessageAnnotation(value) {
@@ -3792,7 +3818,7 @@ var StreamData2 = class {
3792
3818
  throw new Error("Stream controller is not initialized.");
3793
3819
  }
3794
3820
  this.controller.enqueue(
3795
- this.encoder.encode((0, import_ui_utils3.formatStreamPart)("message_annotations", [value]))
3821
+ this.encoder.encode((0, import_ui_utils7.formatStreamPart)("message_annotations", [value]))
3796
3822
  );
3797
3823
  }
3798
3824
  };
@@ -3802,7 +3828,7 @@ function createStreamDataTransformer() {
3802
3828
  return new TransformStream({
3803
3829
  transform: async (chunk, controller) => {
3804
3830
  const message = decoder.decode(chunk);
3805
- controller.enqueue(encoder.encode((0, import_ui_utils3.formatStreamPart)("text", message)));
3831
+ controller.enqueue(encoder.encode((0, import_ui_utils7.formatStreamPart)("text", message)));
3806
3832
  }
3807
3833
  });
3808
3834
  }
@@ -3856,36 +3882,36 @@ function AnthropicStream(res, cb) {
3856
3882
  }
3857
3883
 
3858
3884
  // streams/assistant-response.ts
3859
- var import_ui_utils4 = require("@ai-sdk/ui-utils");
3885
+ var import_ui_utils8 = require("@ai-sdk/ui-utils");
3860
3886
  function AssistantResponse({ threadId, messageId }, process2) {
3861
3887
  const stream = new ReadableStream({
3862
3888
  async start(controller) {
3863
- var _a9;
3889
+ var _a12;
3864
3890
  const textEncoder = new TextEncoder();
3865
3891
  const sendMessage = (message) => {
3866
3892
  controller.enqueue(
3867
- textEncoder.encode((0, import_ui_utils4.formatStreamPart)("assistant_message", message))
3893
+ textEncoder.encode((0, import_ui_utils8.formatStreamPart)("assistant_message", message))
3868
3894
  );
3869
3895
  };
3870
3896
  const sendDataMessage = (message) => {
3871
3897
  controller.enqueue(
3872
- textEncoder.encode((0, import_ui_utils4.formatStreamPart)("data_message", message))
3898
+ textEncoder.encode((0, import_ui_utils8.formatStreamPart)("data_message", message))
3873
3899
  );
3874
3900
  };
3875
3901
  const sendError = (errorMessage) => {
3876
3902
  controller.enqueue(
3877
- textEncoder.encode((0, import_ui_utils4.formatStreamPart)("error", errorMessage))
3903
+ textEncoder.encode((0, import_ui_utils8.formatStreamPart)("error", errorMessage))
3878
3904
  );
3879
3905
  };
3880
3906
  const forwardStream = async (stream2) => {
3881
- var _a10, _b;
3907
+ var _a13, _b;
3882
3908
  let result = void 0;
3883
3909
  for await (const value of stream2) {
3884
3910
  switch (value.event) {
3885
3911
  case "thread.message.created": {
3886
3912
  controller.enqueue(
3887
3913
  textEncoder.encode(
3888
- (0, import_ui_utils4.formatStreamPart)("assistant_message", {
3914
+ (0, import_ui_utils8.formatStreamPart)("assistant_message", {
3889
3915
  id: value.data.id,
3890
3916
  role: "assistant",
3891
3917
  content: [{ type: "text", text: { value: "" } }]
@@ -3895,11 +3921,11 @@ function AssistantResponse({ threadId, messageId }, process2) {
3895
3921
  break;
3896
3922
  }
3897
3923
  case "thread.message.delta": {
3898
- const content = (_a10 = value.data.delta.content) == null ? void 0 : _a10[0];
3924
+ const content = (_a13 = value.data.delta.content) == null ? void 0 : _a13[0];
3899
3925
  if ((content == null ? void 0 : content.type) === "text" && ((_b = content.text) == null ? void 0 : _b.value) != null) {
3900
3926
  controller.enqueue(
3901
3927
  textEncoder.encode(
3902
- (0, import_ui_utils4.formatStreamPart)("text", content.text.value)
3928
+ (0, import_ui_utils8.formatStreamPart)("text", content.text.value)
3903
3929
  )
3904
3930
  );
3905
3931
  }
@@ -3916,7 +3942,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
3916
3942
  };
3917
3943
  controller.enqueue(
3918
3944
  textEncoder.encode(
3919
- (0, import_ui_utils4.formatStreamPart)("assistant_control_data", {
3945
+ (0, import_ui_utils8.formatStreamPart)("assistant_control_data", {
3920
3946
  threadId,
3921
3947
  messageId
3922
3948
  })
@@ -3931,7 +3957,7 @@ function AssistantResponse({ threadId, messageId }, process2) {
3931
3957
  forwardStream
3932
3958
  });
3933
3959
  } catch (error) {
3934
- sendError((_a9 = error.message) != null ? _a9 : `${error}`);
3960
+ sendError((_a12 = error.message) != null ? _a12 : `${error}`);
3935
3961
  } finally {
3936
3962
  controller.close();
3937
3963
  }
@@ -3952,9 +3978,9 @@ var experimental_AssistantResponse = AssistantResponse;
3952
3978
 
3953
3979
  // streams/aws-bedrock-stream.ts
3954
3980
  async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
3955
- var _a9, _b;
3981
+ var _a12, _b;
3956
3982
  const decoder = new TextDecoder();
3957
- for await (const chunk of (_a9 = response.body) != null ? _a9 : []) {
3983
+ for await (const chunk of (_a12 = response.body) != null ? _a12 : []) {
3958
3984
  const bytes = (_b = chunk.chunk) == null ? void 0 : _b.bytes;
3959
3985
  if (bytes != null) {
3960
3986
  const chunkText = decoder.decode(bytes);
@@ -3968,8 +3994,8 @@ async function* asDeltaIterable(response, extractTextDeltaFromChunk) {
3968
3994
  }
3969
3995
  function AWSBedrockAnthropicMessagesStream(response, callbacks) {
3970
3996
  return AWSBedrockStream(response, callbacks, (chunk) => {
3971
- var _a9;
3972
- return (_a9 = chunk.delta) == null ? void 0 : _a9.text;
3997
+ var _a12;
3998
+ return (_a12 = chunk.delta) == null ? void 0 : _a12.text;
3973
3999
  });
3974
4000
  }
3975
4001
  function AWSBedrockAnthropicStream(response, callbacks) {
@@ -4016,8 +4042,8 @@ async function readAndProcessLines(reader, controller) {
4016
4042
  controller.close();
4017
4043
  }
4018
4044
  function createParser2(res) {
4019
- var _a9;
4020
- const reader = (_a9 = res.body) == null ? void 0 : _a9.getReader();
4045
+ var _a12;
4046
+ const reader = (_a12 = res.body) == null ? void 0 : _a12.getReader();
4021
4047
  return new ReadableStream({
4022
4048
  async start(controller) {
4023
4049
  if (!reader) {
@@ -4047,9 +4073,9 @@ function CohereStream(reader, callbacks) {
4047
4073
 
4048
4074
  // streams/google-generative-ai-stream.ts
4049
4075
  async function* streamable3(response) {
4050
- var _a9, _b, _c;
4076
+ var _a12, _b, _c;
4051
4077
  for await (const chunk of response.stream) {
4052
- const parts = (_c = (_b = (_a9 = chunk.candidates) == null ? void 0 : _a9[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
4078
+ const parts = (_c = (_b = (_a12 = chunk.candidates) == null ? void 0 : _a12[0]) == null ? void 0 : _b.content) == null ? void 0 : _c.parts;
4053
4079
  if (parts === void 0) {
4054
4080
  continue;
4055
4081
  }
@@ -4068,13 +4094,13 @@ function createParser3(res) {
4068
4094
  const trimStartOfStream = trimStartOfStreamHelper();
4069
4095
  return new ReadableStream({
4070
4096
  async pull(controller) {
4071
- var _a9, _b;
4097
+ var _a12, _b;
4072
4098
  const { value, done } = await res.next();
4073
4099
  if (done) {
4074
4100
  controller.close();
4075
4101
  return;
4076
4102
  }
4077
- const text = trimStartOfStream((_b = (_a9 = value.token) == null ? void 0 : _a9.text) != null ? _b : "");
4103
+ const text = trimStartOfStream((_b = (_a12 = value.token) == null ? void 0 : _a12.text) != null ? _b : "");
4078
4104
  if (!text)
4079
4105
  return;
4080
4106
  if (value.generated_text != null && value.generated_text.length > 0) {
@@ -4099,11 +4125,11 @@ function InkeepStream(res, callbacks) {
4099
4125
  let chat_session_id = "";
4100
4126
  let records_cited;
4101
4127
  const inkeepEventParser = (data, options) => {
4102
- var _a9, _b;
4128
+ var _a12, _b;
4103
4129
  const { event } = options;
4104
4130
  if (event === "records_cited") {
4105
4131
  records_cited = JSON.parse(data);
4106
- (_a9 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a9.call(callbacks, records_cited);
4132
+ (_a12 = callbacks == null ? void 0 : callbacks.onRecordsCited) == null ? void 0 : _a12.call(callbacks, records_cited);
4107
4133
  }
4108
4134
  if (event === "message_chunk") {
4109
4135
  const inkeepMessageChunk = JSON.parse(data);
@@ -4116,12 +4142,12 @@ function InkeepStream(res, callbacks) {
4116
4142
  passThroughCallbacks = {
4117
4143
  ...passThroughCallbacks,
4118
4144
  onFinal: (completion) => {
4119
- var _a9;
4145
+ var _a12;
4120
4146
  const inkeepOnFinalMetadata = {
4121
4147
  chat_session_id,
4122
4148
  records_cited
4123
4149
  };
4124
- (_a9 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a9.call(callbacks, completion, inkeepOnFinalMetadata);
4150
+ (_a12 = callbacks == null ? void 0 : callbacks.onFinal) == null ? void 0 : _a12.call(callbacks, completion, inkeepOnFinalMetadata);
4125
4151
  }
4126
4152
  };
4127
4153
  return AIStream(res, inkeepEventParser, passThroughCallbacks).pipeThrough(
@@ -4143,7 +4169,7 @@ function toDataStream(stream, callbacks) {
4143
4169
  return stream.pipeThrough(
4144
4170
  new TransformStream({
4145
4171
  transform: async (value, controller) => {
4146
- var _a9;
4172
+ var _a12;
4147
4173
  if (typeof value === "string") {
4148
4174
  controller.enqueue(value);
4149
4175
  return;
@@ -4151,7 +4177,7 @@ function toDataStream(stream, callbacks) {
4151
4177
  if ("event" in value) {
4152
4178
  if (value.event === "on_chat_model_stream") {
4153
4179
  forwardAIMessageChunk(
4154
- (_a9 = value.data) == null ? void 0 : _a9.chunk,
4180
+ (_a12 = value.data) == null ? void 0 : _a12.chunk,
4155
4181
  controller
4156
4182
  );
4157
4183
  }
@@ -4163,13 +4189,13 @@ function toDataStream(stream, callbacks) {
4163
4189
  ).pipeThrough(createCallbacksTransformer(callbacks)).pipeThrough(createStreamDataTransformer());
4164
4190
  }
4165
4191
  function toDataStreamResponse(stream, options) {
4166
- var _a9;
4192
+ var _a12;
4167
4193
  const dataStream = toDataStream(stream, options == null ? void 0 : options.callbacks);
4168
4194
  const data = options == null ? void 0 : options.data;
4169
4195
  const init = options == null ? void 0 : options.init;
4170
4196
  const responseStream = data ? mergeStreams(data.stream, dataStream) : dataStream;
4171
4197
  return new Response(responseStream, {
4172
- status: (_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200,
4198
+ status: (_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200,
4173
4199
  statusText: init == null ? void 0 : init.statusText,
4174
4200
  headers: prepareResponseHeaders(init, {
4175
4201
  contentType: "text/plain; charset=utf-8",
@@ -4251,9 +4277,9 @@ function LangChainStream(callbacks) {
4251
4277
 
4252
4278
  // streams/mistral-stream.ts
4253
4279
  async function* streamable4(stream) {
4254
- var _a9, _b;
4280
+ var _a12, _b;
4255
4281
  for await (const chunk of stream) {
4256
- const content = (_b = (_a9 = chunk.choices[0]) == null ? void 0 : _a9.delta) == null ? void 0 : _b.content;
4282
+ const content = (_b = (_a12 = chunk.choices[0]) == null ? void 0 : _a12.delta) == null ? void 0 : _b.content;
4257
4283
  if (content === void 0 || content === "") {
4258
4284
  continue;
4259
4285
  }
@@ -4266,7 +4292,7 @@ function MistralStream(response, callbacks) {
4266
4292
  }
4267
4293
 
4268
4294
  // streams/openai-stream.ts
4269
- var import_ui_utils5 = require("@ai-sdk/ui-utils");
4295
+ var import_ui_utils9 = require("@ai-sdk/ui-utils");
4270
4296
  function parseOpenAIStream() {
4271
4297
  const extract = chunkToText();
4272
4298
  return (data) => extract(JSON.parse(data));
@@ -4283,10 +4309,10 @@ async function* streamable5(stream) {
4283
4309
  model: chunk.model,
4284
4310
  // not exposed by Azure API
4285
4311
  choices: chunk.choices.map((choice) => {
4286
- var _a9, _b, _c, _d, _e, _f, _g;
4312
+ var _a12, _b, _c, _d, _e, _f, _g;
4287
4313
  return {
4288
4314
  delta: {
4289
- content: (_a9 = choice.delta) == null ? void 0 : _a9.content,
4315
+ content: (_a12 = choice.delta) == null ? void 0 : _a12.content,
4290
4316
  function_call: (_b = choice.delta) == null ? void 0 : _b.functionCall,
4291
4317
  role: (_c = choice.delta) == null ? void 0 : _c.role,
4292
4318
  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) => ({
@@ -4311,9 +4337,9 @@ function chunkToText() {
4311
4337
  const trimStartOfStream = trimStartOfStreamHelper();
4312
4338
  let isFunctionStreamingIn;
4313
4339
  return (json) => {
4314
- var _a9, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
4340
+ var _a12, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
4315
4341
  if (isChatCompletionChunk(json)) {
4316
- const delta = (_a9 = json.choices[0]) == null ? void 0 : _a9.delta;
4342
+ const delta = (_a12 = json.choices[0]) == null ? void 0 : _a12.delta;
4317
4343
  if ((_b = delta.function_call) == null ? void 0 : _b.name) {
4318
4344
  isFunctionStreamingIn = true;
4319
4345
  return {
@@ -4417,7 +4443,7 @@ function createFunctionCallTransformer(callbacks) {
4417
4443
  let aggregatedFinalCompletionResponse = "";
4418
4444
  let isFunctionStreamingIn = false;
4419
4445
  let functionCallMessages = callbacks[__internal__OpenAIFnMessagesSymbol] || [];
4420
- const decode = (0, import_ui_utils5.createChunkDecoder)();
4446
+ const decode = (0, import_ui_utils9.createChunkDecoder)();
4421
4447
  return new TransformStream({
4422
4448
  async transform(chunk, controller) {
4423
4449
  const message = decode(chunk);
@@ -4431,7 +4457,7 @@ function createFunctionCallTransformer(callbacks) {
4431
4457
  }
4432
4458
  if (!isFunctionStreamingIn) {
4433
4459
  controller.enqueue(
4434
- textEncoder.encode((0, import_ui_utils5.formatStreamPart)("text", message))
4460
+ textEncoder.encode((0, import_ui_utils9.formatStreamPart)("text", message))
4435
4461
  );
4436
4462
  return;
4437
4463
  } else {
@@ -4542,7 +4568,7 @@ function createFunctionCallTransformer(callbacks) {
4542
4568
  if (!functionResponse) {
4543
4569
  controller.enqueue(
4544
4570
  textEncoder.encode(
4545
- (0, import_ui_utils5.formatStreamPart)(
4571
+ (0, import_ui_utils9.formatStreamPart)(
4546
4572
  payload.function_call ? "function_call" : "tool_calls",
4547
4573
  // parse to prevent double-encoding:
4548
4574
  JSON.parse(aggregatedResponse)
@@ -4552,7 +4578,7 @@ function createFunctionCallTransformer(callbacks) {
4552
4578
  return;
4553
4579
  } else if (typeof functionResponse === "string") {
4554
4580
  controller.enqueue(
4555
- textEncoder.encode((0, import_ui_utils5.formatStreamPart)("text", functionResponse))
4581
+ textEncoder.encode((0, import_ui_utils9.formatStreamPart)("text", functionResponse))
4556
4582
  );
4557
4583
  aggregatedFinalCompletionResponse = functionResponse;
4558
4584
  return;
@@ -4586,8 +4612,8 @@ function createFunctionCallTransformer(callbacks) {
4586
4612
 
4587
4613
  // streams/replicate-stream.ts
4588
4614
  async function ReplicateStream(res, cb, options) {
4589
- var _a9;
4590
- const url = (_a9 = res.urls) == null ? void 0 : _a9.stream;
4615
+ var _a12;
4616
+ const url = (_a12 = res.urls) == null ? void 0 : _a12.stream;
4591
4617
  if (!url) {
4592
4618
  if (res.error)
4593
4619
  throw new Error(res.error);
@@ -4608,8 +4634,8 @@ async function ReplicateStream(res, cb, options) {
4608
4634
 
4609
4635
  // streams/stream-to-response.ts
4610
4636
  function streamToResponse(res, response, init, data) {
4611
- var _a9;
4612
- response.writeHead((_a9 = init == null ? void 0 : init.status) != null ? _a9 : 200, {
4637
+ var _a12;
4638
+ response.writeHead((_a12 = init == null ? void 0 : init.status) != null ? _a12 : 200, {
4613
4639
  "Content-Type": "text/plain; charset=utf-8",
4614
4640
  ...init == null ? void 0 : init.headers
4615
4641
  });
@@ -4649,8 +4675,8 @@ var StreamingTextResponse = class extends Response {
4649
4675
  };
4650
4676
 
4651
4677
  // streams/index.ts
4652
- var generateId2 = import_provider_utils8.generateId;
4653
- var nanoid = import_provider_utils8.generateId;
4678
+ var generateId2 = import_provider_utils7.generateId;
4679
+ var nanoid = import_provider_utils7.generateId;
4654
4680
  // Annotate the CommonJS export names for ESM import in node:
4655
4681
  0 && (module.exports = {
4656
4682
  AISDKError,