ai 3.3.10 → 3.3.12

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
@@ -59,10 +59,7 @@ __export(streams_exports, {
59
59
  StreamingTextResponse: () => StreamingTextResponse,
60
60
  TypeValidationError: () => import_provider14.TypeValidationError,
61
61
  UnsupportedFunctionalityError: () => import_provider14.UnsupportedFunctionalityError,
62
- convertDataContentToBase64String: () => convertDataContentToBase64String,
63
- convertDataContentToUint8Array: () => convertDataContentToUint8Array,
64
62
  convertToCoreMessages: () => convertToCoreMessages,
65
- convertUint8ArrayToText: () => convertUint8ArrayToText,
66
63
  cosineSimilarity: () => cosineSimilarity,
67
64
  createCallbacksTransformer: () => createCallbacksTransformer,
68
65
  createEventStreamTransformer: () => createEventStreamTransformer,
@@ -95,7 +92,7 @@ __export(streams_exports, {
95
92
  });
96
93
  module.exports = __toCommonJS(streams_exports);
97
94
  var import_ui_utils10 = require("@ai-sdk/ui-utils");
98
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
95
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
99
96
 
100
97
  // core/index.ts
101
98
  var import_ui_utils6 = require("@ai-sdk/ui-utils");
@@ -206,11 +203,16 @@ async function _retryWithExponentialBackoff(f, {
206
203
 
207
204
  // core/telemetry/assemble-operation-name.ts
208
205
  function assembleOperationName({
209
- operationName,
206
+ operationId,
210
207
  telemetry
211
208
  }) {
212
209
  return {
213
- "operation.name": `${operationName}${(telemetry == null ? void 0 : telemetry.functionId) != null ? ` ${telemetry.functionId}` : ""}`
210
+ // standardized operation and resource name:
211
+ "operation.name": `${operationId}${(telemetry == null ? void 0 : telemetry.functionId) != null ? ` ${telemetry.functionId}` : ""}`,
212
+ "resource.name": telemetry == null ? void 0 : telemetry.functionId,
213
+ // detailed, AI SDK specific data:
214
+ "ai.operationId": operationId,
215
+ "ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId
214
216
  };
215
217
  }
216
218
 
@@ -230,9 +232,6 @@ function getBaseTelemetryAttributes({
230
232
  attributes[`ai.settings.${key}`] = value;
231
233
  return attributes;
232
234
  }, {}),
233
- // special telemetry information
234
- "resource.name": telemetry == null ? void 0 : telemetry.functionId,
235
- "ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
236
235
  // add metadata as attributes:
237
236
  ...Object.entries((_a12 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a12 : {}).reduce(
238
237
  (attributes, [key, value]) => {
@@ -412,7 +411,7 @@ async function embed({
412
411
  attributes: selectTelemetryAttributes({
413
412
  telemetry,
414
413
  attributes: {
415
- ...assembleOperationName({ operationName: "ai.embed", telemetry }),
414
+ ...assembleOperationName({ operationId: "ai.embed", telemetry }),
416
415
  ...baseTelemetryAttributes,
417
416
  "ai.value": { input: () => JSON.stringify(value) }
418
417
  }
@@ -429,7 +428,7 @@ async function embed({
429
428
  telemetry,
430
429
  attributes: {
431
430
  ...assembleOperationName({
432
- operationName: "ai.embed.doEmbed",
431
+ operationId: "ai.embed.doEmbed",
433
432
  telemetry
434
433
  }),
435
434
  ...baseTelemetryAttributes,
@@ -525,7 +524,7 @@ async function embedMany({
525
524
  attributes: selectTelemetryAttributes({
526
525
  telemetry,
527
526
  attributes: {
528
- ...assembleOperationName({ operationName: "ai.embedMany", telemetry }),
527
+ ...assembleOperationName({ operationId: "ai.embedMany", telemetry }),
529
528
  ...baseTelemetryAttributes,
530
529
  // specific settings that only make sense on the outer level:
531
530
  "ai.values": {
@@ -545,7 +544,7 @@ async function embedMany({
545
544
  telemetry,
546
545
  attributes: {
547
546
  ...assembleOperationName({
548
- operationName: "ai.embedMany.doEmbed",
547
+ operationId: "ai.embedMany.doEmbed",
549
548
  telemetry
550
549
  }),
551
550
  ...baseTelemetryAttributes,
@@ -604,7 +603,7 @@ async function embedMany({
604
603
  telemetry,
605
604
  attributes: {
606
605
  ...assembleOperationName({
607
- operationName: "ai.embedMany.doEmbed",
606
+ operationId: "ai.embedMany.doEmbed",
608
607
  telemetry
609
608
  }),
610
609
  ...baseTelemetryAttributes,
@@ -670,7 +669,7 @@ var DefaultEmbedManyResult = class {
670
669
  };
671
670
 
672
671
  // core/generate-object/generate-object.ts
673
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
672
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
674
673
  var import_ui_utils = require("@ai-sdk/ui-utils");
675
674
 
676
675
  // core/prompt/convert-to-language-model-prompt.ts
@@ -809,15 +808,13 @@ var InvalidDataContentError = class extends import_provider4.AISDKError {
809
808
  _a3 = symbol3;
810
809
 
811
810
  // core/prompt/data-content.ts
812
- function convertDataContentToBase64String(content) {
813
- if (typeof content === "string") {
814
- return content;
815
- }
816
- if (content instanceof ArrayBuffer) {
817
- return (0, import_provider_utils2.convertUint8ArrayToBase64)(new Uint8Array(content));
818
- }
819
- return (0, import_provider_utils2.convertUint8ArrayToBase64)(content);
820
- }
811
+ var import_zod = require("zod");
812
+ var dataContentSchema = import_zod.z.union([
813
+ import_zod.z.string(),
814
+ import_zod.z.instanceof(Uint8Array),
815
+ import_zod.z.instanceof(ArrayBuffer),
816
+ import_zod.z.instanceof(Buffer)
817
+ ]);
821
818
  function convertDataContentToUint8Array(content) {
822
819
  if (content instanceof Uint8Array) {
823
820
  return content;
@@ -1092,52 +1089,13 @@ async function downloadImages(messages, downloadImplementation) {
1092
1089
  );
1093
1090
  }
1094
1091
 
1095
- // core/prompt/get-validated-prompt.ts
1096
- var import_provider6 = require("@ai-sdk/provider");
1097
- function getValidatedPrompt(prompt) {
1098
- if (prompt.prompt == null && prompt.messages == null) {
1099
- throw new import_provider6.InvalidPromptError({
1100
- prompt,
1101
- message: "prompt or messages must be defined"
1102
- });
1103
- }
1104
- if (prompt.prompt != null && prompt.messages != null) {
1105
- throw new import_provider6.InvalidPromptError({
1106
- prompt,
1107
- message: "prompt and messages cannot be defined at the same time"
1108
- });
1109
- }
1110
- if (prompt.messages != null) {
1111
- for (const message of prompt.messages) {
1112
- if (message.role === "system" && typeof message.content !== "string") {
1113
- throw new import_provider6.InvalidPromptError({
1114
- prompt,
1115
- message: "system message content must be a string"
1116
- });
1117
- }
1118
- }
1119
- }
1120
- return prompt.prompt != null ? {
1121
- type: "prompt",
1122
- prompt: prompt.prompt,
1123
- messages: void 0,
1124
- system: prompt.system
1125
- } : {
1126
- type: "messages",
1127
- prompt: void 0,
1128
- messages: prompt.messages,
1129
- // only possible case bc of checks above
1130
- system: prompt.system
1131
- };
1132
- }
1133
-
1134
1092
  // errors/invalid-argument-error.ts
1135
- var import_provider7 = require("@ai-sdk/provider");
1093
+ var import_provider6 = require("@ai-sdk/provider");
1136
1094
  var name5 = "AI_InvalidArgumentError";
1137
1095
  var marker5 = `vercel.ai.error.${name5}`;
1138
1096
  var symbol5 = Symbol.for(marker5);
1139
1097
  var _a5;
1140
- var InvalidArgumentError = class extends import_provider7.AISDKError {
1098
+ var InvalidArgumentError = class extends import_provider6.AISDKError {
1141
1099
  constructor({
1142
1100
  parameter,
1143
1101
  value,
@@ -1152,7 +1110,7 @@ var InvalidArgumentError = class extends import_provider7.AISDKError {
1152
1110
  this.value = value;
1153
1111
  }
1154
1112
  static isInstance(error) {
1155
- return import_provider7.AISDKError.hasMarker(error, marker5);
1113
+ return import_provider6.AISDKError.hasMarker(error, marker5);
1156
1114
  }
1157
1115
  /**
1158
1116
  * @deprecated use `isInstance` instead
@@ -1272,6 +1230,155 @@ function prepareCallSettings({
1272
1230
  };
1273
1231
  }
1274
1232
 
1233
+ // core/prompt/validate-prompt.ts
1234
+ var import_provider7 = require("@ai-sdk/provider");
1235
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
1236
+ var import_zod6 = require("zod");
1237
+
1238
+ // core/prompt/message.ts
1239
+ var import_zod5 = require("zod");
1240
+
1241
+ // core/types/provider-metadata.ts
1242
+ var import_zod3 = require("zod");
1243
+
1244
+ // core/types/json-value.ts
1245
+ var import_zod2 = require("zod");
1246
+ var jsonValueSchema = import_zod2.z.lazy(
1247
+ () => import_zod2.z.union([
1248
+ import_zod2.z.null(),
1249
+ import_zod2.z.string(),
1250
+ import_zod2.z.number(),
1251
+ import_zod2.z.boolean(),
1252
+ import_zod2.z.record(import_zod2.z.string(), jsonValueSchema),
1253
+ import_zod2.z.array(jsonValueSchema)
1254
+ ])
1255
+ );
1256
+
1257
+ // core/types/provider-metadata.ts
1258
+ var providerMetadataSchema = import_zod3.z.record(
1259
+ import_zod3.z.string(),
1260
+ import_zod3.z.record(import_zod3.z.string(), jsonValueSchema)
1261
+ );
1262
+
1263
+ // core/prompt/content-part.ts
1264
+ var import_zod4 = require("zod");
1265
+ var textPartSchema = import_zod4.z.object({
1266
+ type: import_zod4.z.literal("text"),
1267
+ text: import_zod4.z.string(),
1268
+ experimental_providerMetadata: providerMetadataSchema.optional()
1269
+ });
1270
+ var imagePartSchema = import_zod4.z.object({
1271
+ type: import_zod4.z.literal("image"),
1272
+ image: import_zod4.z.union([dataContentSchema, import_zod4.z.instanceof(URL)]),
1273
+ mimeType: import_zod4.z.string().optional(),
1274
+ experimental_providerMetadata: providerMetadataSchema.optional()
1275
+ });
1276
+ var toolCallPartSchema = import_zod4.z.object({
1277
+ type: import_zod4.z.literal("tool-call"),
1278
+ toolCallId: import_zod4.z.string(),
1279
+ toolName: import_zod4.z.string(),
1280
+ args: import_zod4.z.unknown()
1281
+ });
1282
+ var toolResultPartSchema = import_zod4.z.object({
1283
+ type: import_zod4.z.literal("tool-result"),
1284
+ toolCallId: import_zod4.z.string(),
1285
+ toolName: import_zod4.z.string(),
1286
+ result: import_zod4.z.unknown(),
1287
+ isError: import_zod4.z.boolean().optional(),
1288
+ experimental_providerMetadata: providerMetadataSchema.optional()
1289
+ });
1290
+
1291
+ // core/prompt/message.ts
1292
+ var coreSystemMessageSchema = import_zod5.z.object({
1293
+ role: import_zod5.z.literal("system"),
1294
+ content: import_zod5.z.string(),
1295
+ experimental_providerMetadata: providerMetadataSchema.optional()
1296
+ });
1297
+ var coreUserMessageSchema = import_zod5.z.object({
1298
+ role: import_zod5.z.literal("user"),
1299
+ content: import_zod5.z.union([
1300
+ import_zod5.z.string(),
1301
+ import_zod5.z.array(import_zod5.z.union([textPartSchema, imagePartSchema]))
1302
+ ]),
1303
+ experimental_providerMetadata: providerMetadataSchema.optional()
1304
+ });
1305
+ var coreAssistantMessageSchema = import_zod5.z.object({
1306
+ role: import_zod5.z.literal("assistant"),
1307
+ content: import_zod5.z.union([
1308
+ import_zod5.z.string(),
1309
+ import_zod5.z.array(import_zod5.z.union([textPartSchema, toolCallPartSchema]))
1310
+ ]),
1311
+ experimental_providerMetadata: providerMetadataSchema.optional()
1312
+ });
1313
+ var coreToolMessageSchema = import_zod5.z.object({
1314
+ role: import_zod5.z.literal("tool"),
1315
+ content: import_zod5.z.array(toolResultPartSchema),
1316
+ experimental_providerMetadata: providerMetadataSchema.optional()
1317
+ });
1318
+ var coreMessageSchema = import_zod5.z.union([
1319
+ coreSystemMessageSchema,
1320
+ coreUserMessageSchema,
1321
+ coreAssistantMessageSchema,
1322
+ coreToolMessageSchema
1323
+ ]);
1324
+
1325
+ // core/prompt/validate-prompt.ts
1326
+ function validatePrompt(prompt) {
1327
+ if (prompt.prompt == null && prompt.messages == null) {
1328
+ throw new import_provider7.InvalidPromptError({
1329
+ prompt,
1330
+ message: "prompt or messages must be defined"
1331
+ });
1332
+ }
1333
+ if (prompt.prompt != null && prompt.messages != null) {
1334
+ throw new import_provider7.InvalidPromptError({
1335
+ prompt,
1336
+ message: "prompt and messages cannot be defined at the same time"
1337
+ });
1338
+ }
1339
+ if (prompt.system != null && typeof prompt.system !== "string") {
1340
+ throw new import_provider7.InvalidPromptError({
1341
+ prompt,
1342
+ message: "system must be a string"
1343
+ });
1344
+ }
1345
+ if (prompt.prompt != null) {
1346
+ if (typeof prompt.prompt !== "string") {
1347
+ throw new import_provider7.InvalidPromptError({
1348
+ prompt,
1349
+ message: "prompt must be a string"
1350
+ });
1351
+ }
1352
+ return {
1353
+ type: "prompt",
1354
+ prompt: prompt.prompt,
1355
+ messages: void 0,
1356
+ system: prompt.system
1357
+ };
1358
+ }
1359
+ if (prompt.messages != null) {
1360
+ const validationResult = (0, import_provider_utils4.safeValidateTypes)({
1361
+ value: prompt.messages,
1362
+ schema: import_zod6.z.array(coreMessageSchema)
1363
+ });
1364
+ if (!validationResult.success) {
1365
+ throw new import_provider7.InvalidPromptError({
1366
+ prompt,
1367
+ message: "messages must be an array of CoreMessage",
1368
+ cause: validationResult.error
1369
+ });
1370
+ }
1371
+ return {
1372
+ type: "messages",
1373
+ prompt: void 0,
1374
+ messages: prompt.messages,
1375
+ // only possible case bc of checks above
1376
+ system: prompt.system
1377
+ };
1378
+ }
1379
+ throw new Error("unreachable");
1380
+ }
1381
+
1275
1382
  // core/types/token-usage.ts
1276
1383
  function calculateCompletionTokenUsage(usage) {
1277
1384
  return {
@@ -1382,7 +1489,7 @@ async function generateObject({
1382
1489
  telemetry,
1383
1490
  attributes: {
1384
1491
  ...assembleOperationName({
1385
- operationName: "ai.generateObject",
1492
+ operationId: "ai.generateObject",
1386
1493
  telemetry
1387
1494
  }),
1388
1495
  ...baseTelemetryAttributes,
@@ -1413,7 +1520,7 @@ async function generateObject({
1413
1520
  let providerMetadata;
1414
1521
  switch (mode) {
1415
1522
  case "json": {
1416
- const validatedPrompt = getValidatedPrompt({
1523
+ const validatedPrompt = validatePrompt({
1417
1524
  system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
1418
1525
  system,
1419
1526
  schema: schema.jsonSchema
@@ -1433,7 +1540,7 @@ async function generateObject({
1433
1540
  telemetry,
1434
1541
  attributes: {
1435
1542
  ...assembleOperationName({
1436
- operationName: "ai.generateObject.doGenerate",
1543
+ operationId: "ai.generateObject.doGenerate",
1437
1544
  telemetry
1438
1545
  }),
1439
1546
  ...baseTelemetryAttributes,
@@ -1499,7 +1606,7 @@ async function generateObject({
1499
1606
  break;
1500
1607
  }
1501
1608
  case "tool": {
1502
- const validatedPrompt = getValidatedPrompt({
1609
+ const validatedPrompt = validatePrompt({
1503
1610
  system,
1504
1611
  prompt,
1505
1612
  messages
@@ -1516,7 +1623,7 @@ async function generateObject({
1516
1623
  telemetry,
1517
1624
  attributes: {
1518
1625
  ...assembleOperationName({
1519
- operationName: "ai.generateObject.doGenerate",
1626
+ operationId: "ai.generateObject.doGenerate",
1520
1627
  telemetry
1521
1628
  }),
1522
1629
  ...baseTelemetryAttributes,
@@ -1596,7 +1703,7 @@ async function generateObject({
1596
1703
  throw new Error(`Unsupported mode: ${_exhaustiveCheck}`);
1597
1704
  }
1598
1705
  }
1599
- const parseResult = (0, import_provider_utils4.safeParseJSON)({ text: result, schema });
1706
+ const parseResult = (0, import_provider_utils5.safeParseJSON)({ text: result, schema });
1600
1707
  if (!parseResult.success) {
1601
1708
  throw parseResult.error;
1602
1709
  }
@@ -1648,7 +1755,7 @@ var DefaultGenerateObjectResult = class {
1648
1755
  var experimental_generateObject = generateObject;
1649
1756
 
1650
1757
  // core/generate-object/stream-object.ts
1651
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1758
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1652
1759
  var import_ui_utils2 = require("@ai-sdk/ui-utils");
1653
1760
 
1654
1761
  // util/create-resolvable-promise.ts
@@ -1754,7 +1861,7 @@ async function streamObject({
1754
1861
  telemetry,
1755
1862
  attributes: {
1756
1863
  ...assembleOperationName({
1757
- operationName: "ai.streamObject",
1864
+ operationId: "ai.streamObject",
1758
1865
  telemetry
1759
1866
  }),
1760
1867
  ...baseTelemetryAttributes,
@@ -1778,7 +1885,7 @@ async function streamObject({
1778
1885
  let transformer;
1779
1886
  switch (mode) {
1780
1887
  case "json": {
1781
- const validatedPrompt = getValidatedPrompt({
1888
+ const validatedPrompt = validatePrompt({
1782
1889
  system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
1783
1890
  system,
1784
1891
  schema: schema.jsonSchema
@@ -1818,7 +1925,7 @@ async function streamObject({
1818
1925
  break;
1819
1926
  }
1820
1927
  case "tool": {
1821
- const validatedPrompt = getValidatedPrompt({
1928
+ const validatedPrompt = validatePrompt({
1822
1929
  system,
1823
1930
  prompt,
1824
1931
  messages
@@ -1869,7 +1976,8 @@ async function streamObject({
1869
1976
  }
1870
1977
  const {
1871
1978
  result: { stream, warnings, rawResponse },
1872
- doStreamSpan
1979
+ doStreamSpan,
1980
+ startTimestamp
1873
1981
  } = await retry(
1874
1982
  () => recordSpan({
1875
1983
  name: "ai.streamObject.doStream",
@@ -1877,7 +1985,7 @@ async function streamObject({
1877
1985
  telemetry,
1878
1986
  attributes: {
1879
1987
  ...assembleOperationName({
1880
- operationName: "ai.streamObject.doStream",
1988
+ operationId: "ai.streamObject.doStream",
1881
1989
  telemetry
1882
1990
  }),
1883
1991
  ...baseTelemetryAttributes,
@@ -1899,8 +2007,10 @@ async function streamObject({
1899
2007
  tracer,
1900
2008
  endWhenDone: false,
1901
2009
  fn: async (doStreamSpan2) => ({
1902
- result: await model.doStream(callOptions),
1903
- doStreamSpan: doStreamSpan2
2010
+ startTimestamp: performance.now(),
2011
+ // get before the call
2012
+ doStreamSpan: doStreamSpan2,
2013
+ result: await model.doStream(callOptions)
1904
2014
  })
1905
2015
  })
1906
2016
  );
@@ -1912,7 +2022,8 @@ async function streamObject({
1912
2022
  onFinish,
1913
2023
  rootSpan,
1914
2024
  doStreamSpan,
1915
- telemetry
2025
+ telemetry,
2026
+ startTimestamp
1916
2027
  });
1917
2028
  }
1918
2029
  });
@@ -1926,7 +2037,8 @@ var DefaultStreamObjectResult = class {
1926
2037
  onFinish,
1927
2038
  rootSpan,
1928
2039
  doStreamSpan,
1929
- telemetry
2040
+ telemetry,
2041
+ startTimestamp
1930
2042
  }) {
1931
2043
  this.warnings = warnings;
1932
2044
  this.rawResponse = rawResponse;
@@ -1952,8 +2064,14 @@ var DefaultStreamObjectResult = class {
1952
2064
  new TransformStream({
1953
2065
  async transform(chunk, controller) {
1954
2066
  if (firstChunk) {
2067
+ const msToFirstChunk = performance.now() - startTimestamp;
1955
2068
  firstChunk = false;
1956
- doStreamSpan.addEvent("ai.stream.firstChunk");
2069
+ doStreamSpan.addEvent("ai.stream.firstChunk", {
2070
+ "ai.stream.msToFirstChunk": msToFirstChunk
2071
+ });
2072
+ doStreamSpan.setAttributes({
2073
+ "ai.stream.msToFirstChunk": msToFirstChunk
2074
+ });
1957
2075
  }
1958
2076
  if (typeof chunk === "string") {
1959
2077
  accumulatedText += chunk;
@@ -1989,7 +2107,7 @@ var DefaultStreamObjectResult = class {
1989
2107
  controller.enqueue({ ...chunk, usage });
1990
2108
  resolveUsage(usage);
1991
2109
  resolveProviderMetadata(providerMetadata);
1992
- const validationResult = (0, import_provider_utils5.safeValidateTypes)({
2110
+ const validationResult = (0, import_provider_utils6.safeValidateTypes)({
1993
2111
  value: latestObject,
1994
2112
  schema
1995
2113
  });
@@ -2181,7 +2299,7 @@ function prepareToolsAndToolChoice({
2181
2299
  }
2182
2300
 
2183
2301
  // core/generate-text/tool-call.ts
2184
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
2302
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
2185
2303
  var import_ui_utils4 = require("@ai-sdk/ui-utils");
2186
2304
 
2187
2305
  // errors/invalid-tool-arguments-error.ts
@@ -2286,7 +2404,7 @@ function parseToolCall({
2286
2404
  availableTools: Object.keys(tools)
2287
2405
  });
2288
2406
  }
2289
- const parseResult = (0, import_provider_utils6.safeParseJSON)({
2407
+ const parseResult = (0, import_provider_utils7.safeParseJSON)({
2290
2408
  text: toolCall.args,
2291
2409
  schema: (0, import_ui_utils4.asSchema)(tool2.parameters)
2292
2410
  });
@@ -2335,7 +2453,7 @@ async function generateText({
2335
2453
  telemetry,
2336
2454
  attributes: {
2337
2455
  ...assembleOperationName({
2338
- operationName: "ai.generateText",
2456
+ operationId: "ai.generateText",
2339
2457
  telemetry
2340
2458
  }),
2341
2459
  ...baseTelemetryAttributes,
@@ -2350,7 +2468,7 @@ async function generateText({
2350
2468
  fn: async (span) => {
2351
2469
  var _a13, _b, _c, _d;
2352
2470
  const retry = retryWithExponentialBackoff({ maxRetries });
2353
- const validatedPrompt = getValidatedPrompt({
2471
+ const validatedPrompt = validatePrompt({
2354
2472
  system,
2355
2473
  prompt,
2356
2474
  messages
@@ -2384,7 +2502,7 @@ async function generateText({
2384
2502
  telemetry,
2385
2503
  attributes: {
2386
2504
  ...assembleOperationName({
2387
- operationName: "ai.generateText.doGenerate",
2505
+ operationId: "ai.generateText.doGenerate",
2388
2506
  telemetry
2389
2507
  }),
2390
2508
  ...baseTelemetryAttributes,
@@ -2528,7 +2646,7 @@ async function executeTools({
2528
2646
  telemetry,
2529
2647
  attributes: {
2530
2648
  ...assembleOperationName({
2531
- operationName: "ai.toolCall",
2649
+ operationId: "ai.toolCall",
2532
2650
  telemetry
2533
2651
  }),
2534
2652
  "ai.toolCall.name": toolCall.toolName,
@@ -2778,7 +2896,7 @@ function runToolsTransformation({
2778
2896
  telemetry,
2779
2897
  attributes: {
2780
2898
  ...assembleOperationName({
2781
- operationName: "ai.toolCall",
2899
+ operationId: "ai.toolCall",
2782
2900
  telemetry
2783
2901
  }),
2784
2902
  "ai.toolCall.name": toolCall.toolName,
@@ -2915,7 +3033,7 @@ async function streamText({
2915
3033
  attributes: selectTelemetryAttributes({
2916
3034
  telemetry,
2917
3035
  attributes: {
2918
- ...assembleOperationName({ operationName: "ai.streamText", telemetry }),
3036
+ ...assembleOperationName({ operationId: "ai.streamText", telemetry }),
2919
3037
  ...baseTelemetryAttributes,
2920
3038
  // specific settings that only make sense on the outer level:
2921
3039
  "ai.prompt": {
@@ -2927,14 +3045,15 @@ async function streamText({
2927
3045
  endWhenDone: false,
2928
3046
  fn: async (rootSpan) => {
2929
3047
  const retry = retryWithExponentialBackoff({ maxRetries });
2930
- const validatedPrompt = getValidatedPrompt({ system, prompt, messages });
3048
+ const validatedPrompt = validatePrompt({ system, prompt, messages });
2931
3049
  const promptMessages = await convertToLanguageModelPrompt({
2932
3050
  prompt: validatedPrompt,
2933
3051
  modelSupportsImageUrls: model.supportsImageUrls
2934
3052
  });
2935
3053
  const {
2936
3054
  result: { stream, warnings, rawResponse },
2937
- doStreamSpan
3055
+ doStreamSpan,
3056
+ startTimestamp
2938
3057
  } = await retry(
2939
3058
  () => recordSpan({
2940
3059
  name: "ai.streamText.doStream",
@@ -2942,7 +3061,7 @@ async function streamText({
2942
3061
  telemetry,
2943
3062
  attributes: {
2944
3063
  ...assembleOperationName({
2945
- operationName: "ai.streamText.doStream",
3064
+ operationId: "ai.streamText.doStream",
2946
3065
  telemetry
2947
3066
  }),
2948
3067
  ...baseTelemetryAttributes,
@@ -2962,22 +3081,22 @@ async function streamText({
2962
3081
  }),
2963
3082
  tracer,
2964
3083
  endWhenDone: false,
2965
- fn: async (doStreamSpan2) => {
2966
- return {
2967
- result: await model.doStream({
2968
- mode: {
2969
- type: "regular",
2970
- ...prepareToolsAndToolChoice({ tools, toolChoice })
2971
- },
2972
- ...prepareCallSettings(settings),
2973
- inputFormat: validatedPrompt.type,
2974
- prompt: promptMessages,
2975
- abortSignal,
2976
- headers
2977
- }),
2978
- doStreamSpan: doStreamSpan2
2979
- };
2980
- }
3084
+ fn: async (doStreamSpan2) => ({
3085
+ startTimestamp: performance.now(),
3086
+ // get before the call
3087
+ doStreamSpan: doStreamSpan2,
3088
+ result: await model.doStream({
3089
+ mode: {
3090
+ type: "regular",
3091
+ ...prepareToolsAndToolChoice({ tools, toolChoice })
3092
+ },
3093
+ ...prepareCallSettings(settings),
3094
+ inputFormat: validatedPrompt.type,
3095
+ prompt: promptMessages,
3096
+ abortSignal,
3097
+ headers
3098
+ })
3099
+ })
2981
3100
  })
2982
3101
  );
2983
3102
  return new DefaultStreamTextResult({
@@ -2994,7 +3113,8 @@ async function streamText({
2994
3113
  onFinish,
2995
3114
  rootSpan,
2996
3115
  doStreamSpan,
2997
- telemetry
3116
+ telemetry,
3117
+ startTimestamp
2998
3118
  });
2999
3119
  }
3000
3120
  });
@@ -3008,7 +3128,8 @@ var DefaultStreamTextResult = class {
3008
3128
  onFinish,
3009
3129
  rootSpan,
3010
3130
  doStreamSpan,
3011
- telemetry
3131
+ telemetry,
3132
+ startTimestamp
3012
3133
  }) {
3013
3134
  this.warnings = warnings;
3014
3135
  this.rawResponse = rawResponse;
@@ -3038,8 +3159,14 @@ var DefaultStreamTextResult = class {
3038
3159
  new TransformStream({
3039
3160
  async transform(chunk, controller) {
3040
3161
  if (firstChunk) {
3162
+ const msToFirstChunk = performance.now() - startTimestamp;
3041
3163
  firstChunk = false;
3042
- doStreamSpan.addEvent("ai.stream.firstChunk");
3164
+ doStreamSpan.addEvent("ai.stream.firstChunk", {
3165
+ "ai.stream.msToFirstChunk": msToFirstChunk
3166
+ });
3167
+ doStreamSpan.setAttributes({
3168
+ "ai.stream.msToFirstChunk": msToFirstChunk
3169
+ });
3043
3170
  }
3044
3171
  if (chunk.type === "text-delta" && chunk.textDelta.length === 0) {
3045
3172
  return;
@@ -4734,8 +4861,8 @@ var StreamingTextResponse = class extends Response {
4734
4861
  };
4735
4862
 
4736
4863
  // streams/index.ts
4737
- var generateId2 = import_provider_utils7.generateId;
4738
- var nanoid = import_provider_utils7.generateId;
4864
+ var generateId2 = import_provider_utils8.generateId;
4865
+ var nanoid = import_provider_utils8.generateId;
4739
4866
  // Annotate the CommonJS export names for ESM import in node:
4740
4867
  0 && (module.exports = {
4741
4868
  AISDKError,
@@ -4777,10 +4904,7 @@ var nanoid = import_provider_utils7.generateId;
4777
4904
  StreamingTextResponse,
4778
4905
  TypeValidationError,
4779
4906
  UnsupportedFunctionalityError,
4780
- convertDataContentToBase64String,
4781
- convertDataContentToUint8Array,
4782
4907
  convertToCoreMessages,
4783
- convertUint8ArrayToText,
4784
4908
  cosineSimilarity,
4785
4909
  createCallbacksTransformer,
4786
4910
  createEventStreamTransformer,