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.d.mts +17 -35
- package/dist/index.d.ts +17 -35
- package/dist/index.js +243 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/rsc/dist/index.d.ts +12 -11
- package/rsc/dist/rsc-server.d.mts +12 -11
- package/rsc/dist/rsc-server.mjs +157 -40
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -122,11 +122,16 @@ async function _retryWithExponentialBackoff(f, {
|
|
122
122
|
|
123
123
|
// core/telemetry/assemble-operation-name.ts
|
124
124
|
function assembleOperationName({
|
125
|
-
|
125
|
+
operationId,
|
126
126
|
telemetry
|
127
127
|
}) {
|
128
128
|
return {
|
129
|
-
|
129
|
+
// standardized operation and resource name:
|
130
|
+
"operation.name": `${operationId}${(telemetry == null ? void 0 : telemetry.functionId) != null ? ` ${telemetry.functionId}` : ""}`,
|
131
|
+
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
132
|
+
// detailed, AI SDK specific data:
|
133
|
+
"ai.operationId": operationId,
|
134
|
+
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId
|
130
135
|
};
|
131
136
|
}
|
132
137
|
|
@@ -146,9 +151,6 @@ function getBaseTelemetryAttributes({
|
|
146
151
|
attributes[`ai.settings.${key}`] = value;
|
147
152
|
return attributes;
|
148
153
|
}, {}),
|
149
|
-
// special telemetry information
|
150
|
-
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
151
|
-
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
152
154
|
// add metadata as attributes:
|
153
155
|
...Object.entries((_a12 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a12 : {}).reduce(
|
154
156
|
(attributes, [key, value]) => {
|
@@ -328,7 +330,7 @@ async function embed({
|
|
328
330
|
attributes: selectTelemetryAttributes({
|
329
331
|
telemetry,
|
330
332
|
attributes: {
|
331
|
-
...assembleOperationName({
|
333
|
+
...assembleOperationName({ operationId: "ai.embed", telemetry }),
|
332
334
|
...baseTelemetryAttributes,
|
333
335
|
"ai.value": { input: () => JSON.stringify(value) }
|
334
336
|
}
|
@@ -345,7 +347,7 @@ async function embed({
|
|
345
347
|
telemetry,
|
346
348
|
attributes: {
|
347
349
|
...assembleOperationName({
|
348
|
-
|
350
|
+
operationId: "ai.embed.doEmbed",
|
349
351
|
telemetry
|
350
352
|
}),
|
351
353
|
...baseTelemetryAttributes,
|
@@ -441,7 +443,7 @@ async function embedMany({
|
|
441
443
|
attributes: selectTelemetryAttributes({
|
442
444
|
telemetry,
|
443
445
|
attributes: {
|
444
|
-
...assembleOperationName({
|
446
|
+
...assembleOperationName({ operationId: "ai.embedMany", telemetry }),
|
445
447
|
...baseTelemetryAttributes,
|
446
448
|
// specific settings that only make sense on the outer level:
|
447
449
|
"ai.values": {
|
@@ -461,7 +463,7 @@ async function embedMany({
|
|
461
463
|
telemetry,
|
462
464
|
attributes: {
|
463
465
|
...assembleOperationName({
|
464
|
-
|
466
|
+
operationId: "ai.embedMany.doEmbed",
|
465
467
|
telemetry
|
466
468
|
}),
|
467
469
|
...baseTelemetryAttributes,
|
@@ -520,7 +522,7 @@ async function embedMany({
|
|
520
522
|
telemetry,
|
521
523
|
attributes: {
|
522
524
|
...assembleOperationName({
|
523
|
-
|
525
|
+
operationId: "ai.embedMany.doEmbed",
|
524
526
|
telemetry
|
525
527
|
}),
|
526
528
|
...baseTelemetryAttributes,
|
@@ -728,15 +730,13 @@ var InvalidDataContentError = class extends AISDKError3 {
|
|
728
730
|
_a3 = symbol3;
|
729
731
|
|
730
732
|
// core/prompt/data-content.ts
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
return convertUint8ArrayToBase64(content);
|
739
|
-
}
|
733
|
+
import { z } from "zod";
|
734
|
+
var dataContentSchema = z.union([
|
735
|
+
z.string(),
|
736
|
+
z.instanceof(Uint8Array),
|
737
|
+
z.instanceof(ArrayBuffer),
|
738
|
+
z.instanceof(Buffer)
|
739
|
+
]);
|
740
740
|
function convertDataContentToUint8Array(content) {
|
741
741
|
if (content instanceof Uint8Array) {
|
742
742
|
return content;
|
@@ -1011,45 +1011,6 @@ async function downloadImages(messages, downloadImplementation) {
|
|
1011
1011
|
);
|
1012
1012
|
}
|
1013
1013
|
|
1014
|
-
// core/prompt/get-validated-prompt.ts
|
1015
|
-
import { InvalidPromptError } from "@ai-sdk/provider";
|
1016
|
-
function getValidatedPrompt(prompt) {
|
1017
|
-
if (prompt.prompt == null && prompt.messages == null) {
|
1018
|
-
throw new InvalidPromptError({
|
1019
|
-
prompt,
|
1020
|
-
message: "prompt or messages must be defined"
|
1021
|
-
});
|
1022
|
-
}
|
1023
|
-
if (prompt.prompt != null && prompt.messages != null) {
|
1024
|
-
throw new InvalidPromptError({
|
1025
|
-
prompt,
|
1026
|
-
message: "prompt and messages cannot be defined at the same time"
|
1027
|
-
});
|
1028
|
-
}
|
1029
|
-
if (prompt.messages != null) {
|
1030
|
-
for (const message of prompt.messages) {
|
1031
|
-
if (message.role === "system" && typeof message.content !== "string") {
|
1032
|
-
throw new InvalidPromptError({
|
1033
|
-
prompt,
|
1034
|
-
message: "system message content must be a string"
|
1035
|
-
});
|
1036
|
-
}
|
1037
|
-
}
|
1038
|
-
}
|
1039
|
-
return prompt.prompt != null ? {
|
1040
|
-
type: "prompt",
|
1041
|
-
prompt: prompt.prompt,
|
1042
|
-
messages: void 0,
|
1043
|
-
system: prompt.system
|
1044
|
-
} : {
|
1045
|
-
type: "messages",
|
1046
|
-
prompt: void 0,
|
1047
|
-
messages: prompt.messages,
|
1048
|
-
// only possible case bc of checks above
|
1049
|
-
system: prompt.system
|
1050
|
-
};
|
1051
|
-
}
|
1052
|
-
|
1053
1014
|
// errors/invalid-argument-error.ts
|
1054
1015
|
import { AISDKError as AISDKError5 } from "@ai-sdk/provider";
|
1055
1016
|
var name5 = "AI_InvalidArgumentError";
|
@@ -1191,6 +1152,155 @@ function prepareCallSettings({
|
|
1191
1152
|
};
|
1192
1153
|
}
|
1193
1154
|
|
1155
|
+
// core/prompt/validate-prompt.ts
|
1156
|
+
import { InvalidPromptError } from "@ai-sdk/provider";
|
1157
|
+
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
1158
|
+
import { z as z6 } from "zod";
|
1159
|
+
|
1160
|
+
// core/prompt/message.ts
|
1161
|
+
import { z as z5 } from "zod";
|
1162
|
+
|
1163
|
+
// core/types/provider-metadata.ts
|
1164
|
+
import { z as z3 } from "zod";
|
1165
|
+
|
1166
|
+
// core/types/json-value.ts
|
1167
|
+
import { z as z2 } from "zod";
|
1168
|
+
var jsonValueSchema = z2.lazy(
|
1169
|
+
() => z2.union([
|
1170
|
+
z2.null(),
|
1171
|
+
z2.string(),
|
1172
|
+
z2.number(),
|
1173
|
+
z2.boolean(),
|
1174
|
+
z2.record(z2.string(), jsonValueSchema),
|
1175
|
+
z2.array(jsonValueSchema)
|
1176
|
+
])
|
1177
|
+
);
|
1178
|
+
|
1179
|
+
// core/types/provider-metadata.ts
|
1180
|
+
var providerMetadataSchema = z3.record(
|
1181
|
+
z3.string(),
|
1182
|
+
z3.record(z3.string(), jsonValueSchema)
|
1183
|
+
);
|
1184
|
+
|
1185
|
+
// core/prompt/content-part.ts
|
1186
|
+
import { z as z4 } from "zod";
|
1187
|
+
var textPartSchema = z4.object({
|
1188
|
+
type: z4.literal("text"),
|
1189
|
+
text: z4.string(),
|
1190
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1191
|
+
});
|
1192
|
+
var imagePartSchema = z4.object({
|
1193
|
+
type: z4.literal("image"),
|
1194
|
+
image: z4.union([dataContentSchema, z4.instanceof(URL)]),
|
1195
|
+
mimeType: z4.string().optional(),
|
1196
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1197
|
+
});
|
1198
|
+
var toolCallPartSchema = z4.object({
|
1199
|
+
type: z4.literal("tool-call"),
|
1200
|
+
toolCallId: z4.string(),
|
1201
|
+
toolName: z4.string(),
|
1202
|
+
args: z4.unknown()
|
1203
|
+
});
|
1204
|
+
var toolResultPartSchema = z4.object({
|
1205
|
+
type: z4.literal("tool-result"),
|
1206
|
+
toolCallId: z4.string(),
|
1207
|
+
toolName: z4.string(),
|
1208
|
+
result: z4.unknown(),
|
1209
|
+
isError: z4.boolean().optional(),
|
1210
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1211
|
+
});
|
1212
|
+
|
1213
|
+
// core/prompt/message.ts
|
1214
|
+
var coreSystemMessageSchema = z5.object({
|
1215
|
+
role: z5.literal("system"),
|
1216
|
+
content: z5.string(),
|
1217
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1218
|
+
});
|
1219
|
+
var coreUserMessageSchema = z5.object({
|
1220
|
+
role: z5.literal("user"),
|
1221
|
+
content: z5.union([
|
1222
|
+
z5.string(),
|
1223
|
+
z5.array(z5.union([textPartSchema, imagePartSchema]))
|
1224
|
+
]),
|
1225
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1226
|
+
});
|
1227
|
+
var coreAssistantMessageSchema = z5.object({
|
1228
|
+
role: z5.literal("assistant"),
|
1229
|
+
content: z5.union([
|
1230
|
+
z5.string(),
|
1231
|
+
z5.array(z5.union([textPartSchema, toolCallPartSchema]))
|
1232
|
+
]),
|
1233
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1234
|
+
});
|
1235
|
+
var coreToolMessageSchema = z5.object({
|
1236
|
+
role: z5.literal("tool"),
|
1237
|
+
content: z5.array(toolResultPartSchema),
|
1238
|
+
experimental_providerMetadata: providerMetadataSchema.optional()
|
1239
|
+
});
|
1240
|
+
var coreMessageSchema = z5.union([
|
1241
|
+
coreSystemMessageSchema,
|
1242
|
+
coreUserMessageSchema,
|
1243
|
+
coreAssistantMessageSchema,
|
1244
|
+
coreToolMessageSchema
|
1245
|
+
]);
|
1246
|
+
|
1247
|
+
// core/prompt/validate-prompt.ts
|
1248
|
+
function validatePrompt(prompt) {
|
1249
|
+
if (prompt.prompt == null && prompt.messages == null) {
|
1250
|
+
throw new InvalidPromptError({
|
1251
|
+
prompt,
|
1252
|
+
message: "prompt or messages must be defined"
|
1253
|
+
});
|
1254
|
+
}
|
1255
|
+
if (prompt.prompt != null && prompt.messages != null) {
|
1256
|
+
throw new InvalidPromptError({
|
1257
|
+
prompt,
|
1258
|
+
message: "prompt and messages cannot be defined at the same time"
|
1259
|
+
});
|
1260
|
+
}
|
1261
|
+
if (prompt.system != null && typeof prompt.system !== "string") {
|
1262
|
+
throw new InvalidPromptError({
|
1263
|
+
prompt,
|
1264
|
+
message: "system must be a string"
|
1265
|
+
});
|
1266
|
+
}
|
1267
|
+
if (prompt.prompt != null) {
|
1268
|
+
if (typeof prompt.prompt !== "string") {
|
1269
|
+
throw new InvalidPromptError({
|
1270
|
+
prompt,
|
1271
|
+
message: "prompt must be a string"
|
1272
|
+
});
|
1273
|
+
}
|
1274
|
+
return {
|
1275
|
+
type: "prompt",
|
1276
|
+
prompt: prompt.prompt,
|
1277
|
+
messages: void 0,
|
1278
|
+
system: prompt.system
|
1279
|
+
};
|
1280
|
+
}
|
1281
|
+
if (prompt.messages != null) {
|
1282
|
+
const validationResult = safeValidateTypes({
|
1283
|
+
value: prompt.messages,
|
1284
|
+
schema: z6.array(coreMessageSchema)
|
1285
|
+
});
|
1286
|
+
if (!validationResult.success) {
|
1287
|
+
throw new InvalidPromptError({
|
1288
|
+
prompt,
|
1289
|
+
message: "messages must be an array of CoreMessage",
|
1290
|
+
cause: validationResult.error
|
1291
|
+
});
|
1292
|
+
}
|
1293
|
+
return {
|
1294
|
+
type: "messages",
|
1295
|
+
prompt: void 0,
|
1296
|
+
messages: prompt.messages,
|
1297
|
+
// only possible case bc of checks above
|
1298
|
+
system: prompt.system
|
1299
|
+
};
|
1300
|
+
}
|
1301
|
+
throw new Error("unreachable");
|
1302
|
+
}
|
1303
|
+
|
1194
1304
|
// core/types/token-usage.ts
|
1195
1305
|
function calculateCompletionTokenUsage(usage) {
|
1196
1306
|
return {
|
@@ -1301,7 +1411,7 @@ async function generateObject({
|
|
1301
1411
|
telemetry,
|
1302
1412
|
attributes: {
|
1303
1413
|
...assembleOperationName({
|
1304
|
-
|
1414
|
+
operationId: "ai.generateObject",
|
1305
1415
|
telemetry
|
1306
1416
|
}),
|
1307
1417
|
...baseTelemetryAttributes,
|
@@ -1332,7 +1442,7 @@ async function generateObject({
|
|
1332
1442
|
let providerMetadata;
|
1333
1443
|
switch (mode) {
|
1334
1444
|
case "json": {
|
1335
|
-
const validatedPrompt =
|
1445
|
+
const validatedPrompt = validatePrompt({
|
1336
1446
|
system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
|
1337
1447
|
system,
|
1338
1448
|
schema: schema.jsonSchema
|
@@ -1352,7 +1462,7 @@ async function generateObject({
|
|
1352
1462
|
telemetry,
|
1353
1463
|
attributes: {
|
1354
1464
|
...assembleOperationName({
|
1355
|
-
|
1465
|
+
operationId: "ai.generateObject.doGenerate",
|
1356
1466
|
telemetry
|
1357
1467
|
}),
|
1358
1468
|
...baseTelemetryAttributes,
|
@@ -1418,7 +1528,7 @@ async function generateObject({
|
|
1418
1528
|
break;
|
1419
1529
|
}
|
1420
1530
|
case "tool": {
|
1421
|
-
const validatedPrompt =
|
1531
|
+
const validatedPrompt = validatePrompt({
|
1422
1532
|
system,
|
1423
1533
|
prompt,
|
1424
1534
|
messages
|
@@ -1435,7 +1545,7 @@ async function generateObject({
|
|
1435
1545
|
telemetry,
|
1436
1546
|
attributes: {
|
1437
1547
|
...assembleOperationName({
|
1438
|
-
|
1548
|
+
operationId: "ai.generateObject.doGenerate",
|
1439
1549
|
telemetry
|
1440
1550
|
}),
|
1441
1551
|
...baseTelemetryAttributes,
|
@@ -1567,7 +1677,7 @@ var DefaultGenerateObjectResult = class {
|
|
1567
1677
|
var experimental_generateObject = generateObject;
|
1568
1678
|
|
1569
1679
|
// core/generate-object/stream-object.ts
|
1570
|
-
import { safeValidateTypes } from "@ai-sdk/provider-utils";
|
1680
|
+
import { safeValidateTypes as safeValidateTypes2 } from "@ai-sdk/provider-utils";
|
1571
1681
|
import {
|
1572
1682
|
asSchema as asSchema2,
|
1573
1683
|
isDeepEqualData,
|
@@ -1677,7 +1787,7 @@ async function streamObject({
|
|
1677
1787
|
telemetry,
|
1678
1788
|
attributes: {
|
1679
1789
|
...assembleOperationName({
|
1680
|
-
|
1790
|
+
operationId: "ai.streamObject",
|
1681
1791
|
telemetry
|
1682
1792
|
}),
|
1683
1793
|
...baseTelemetryAttributes,
|
@@ -1701,7 +1811,7 @@ async function streamObject({
|
|
1701
1811
|
let transformer;
|
1702
1812
|
switch (mode) {
|
1703
1813
|
case "json": {
|
1704
|
-
const validatedPrompt =
|
1814
|
+
const validatedPrompt = validatePrompt({
|
1705
1815
|
system: model.supportsStructuredOutputs ? system : injectJsonSchemaIntoSystem({
|
1706
1816
|
system,
|
1707
1817
|
schema: schema.jsonSchema
|
@@ -1741,7 +1851,7 @@ async function streamObject({
|
|
1741
1851
|
break;
|
1742
1852
|
}
|
1743
1853
|
case "tool": {
|
1744
|
-
const validatedPrompt =
|
1854
|
+
const validatedPrompt = validatePrompt({
|
1745
1855
|
system,
|
1746
1856
|
prompt,
|
1747
1857
|
messages
|
@@ -1792,7 +1902,8 @@ async function streamObject({
|
|
1792
1902
|
}
|
1793
1903
|
const {
|
1794
1904
|
result: { stream, warnings, rawResponse },
|
1795
|
-
doStreamSpan
|
1905
|
+
doStreamSpan,
|
1906
|
+
startTimestamp
|
1796
1907
|
} = await retry(
|
1797
1908
|
() => recordSpan({
|
1798
1909
|
name: "ai.streamObject.doStream",
|
@@ -1800,7 +1911,7 @@ async function streamObject({
|
|
1800
1911
|
telemetry,
|
1801
1912
|
attributes: {
|
1802
1913
|
...assembleOperationName({
|
1803
|
-
|
1914
|
+
operationId: "ai.streamObject.doStream",
|
1804
1915
|
telemetry
|
1805
1916
|
}),
|
1806
1917
|
...baseTelemetryAttributes,
|
@@ -1822,8 +1933,10 @@ async function streamObject({
|
|
1822
1933
|
tracer,
|
1823
1934
|
endWhenDone: false,
|
1824
1935
|
fn: async (doStreamSpan2) => ({
|
1825
|
-
|
1826
|
-
|
1936
|
+
startTimestamp: performance.now(),
|
1937
|
+
// get before the call
|
1938
|
+
doStreamSpan: doStreamSpan2,
|
1939
|
+
result: await model.doStream(callOptions)
|
1827
1940
|
})
|
1828
1941
|
})
|
1829
1942
|
);
|
@@ -1835,7 +1948,8 @@ async function streamObject({
|
|
1835
1948
|
onFinish,
|
1836
1949
|
rootSpan,
|
1837
1950
|
doStreamSpan,
|
1838
|
-
telemetry
|
1951
|
+
telemetry,
|
1952
|
+
startTimestamp
|
1839
1953
|
});
|
1840
1954
|
}
|
1841
1955
|
});
|
@@ -1849,7 +1963,8 @@ var DefaultStreamObjectResult = class {
|
|
1849
1963
|
onFinish,
|
1850
1964
|
rootSpan,
|
1851
1965
|
doStreamSpan,
|
1852
|
-
telemetry
|
1966
|
+
telemetry,
|
1967
|
+
startTimestamp
|
1853
1968
|
}) {
|
1854
1969
|
this.warnings = warnings;
|
1855
1970
|
this.rawResponse = rawResponse;
|
@@ -1875,8 +1990,14 @@ var DefaultStreamObjectResult = class {
|
|
1875
1990
|
new TransformStream({
|
1876
1991
|
async transform(chunk, controller) {
|
1877
1992
|
if (firstChunk) {
|
1993
|
+
const msToFirstChunk = performance.now() - startTimestamp;
|
1878
1994
|
firstChunk = false;
|
1879
|
-
doStreamSpan.addEvent("ai.stream.firstChunk"
|
1995
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
1996
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
1997
|
+
});
|
1998
|
+
doStreamSpan.setAttributes({
|
1999
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
2000
|
+
});
|
1880
2001
|
}
|
1881
2002
|
if (typeof chunk === "string") {
|
1882
2003
|
accumulatedText += chunk;
|
@@ -1912,7 +2033,7 @@ var DefaultStreamObjectResult = class {
|
|
1912
2033
|
controller.enqueue({ ...chunk, usage });
|
1913
2034
|
resolveUsage(usage);
|
1914
2035
|
resolveProviderMetadata(providerMetadata);
|
1915
|
-
const validationResult =
|
2036
|
+
const validationResult = safeValidateTypes2({
|
1916
2037
|
value: latestObject,
|
1917
2038
|
schema
|
1918
2039
|
});
|
@@ -2258,7 +2379,7 @@ async function generateText({
|
|
2258
2379
|
telemetry,
|
2259
2380
|
attributes: {
|
2260
2381
|
...assembleOperationName({
|
2261
|
-
|
2382
|
+
operationId: "ai.generateText",
|
2262
2383
|
telemetry
|
2263
2384
|
}),
|
2264
2385
|
...baseTelemetryAttributes,
|
@@ -2273,7 +2394,7 @@ async function generateText({
|
|
2273
2394
|
fn: async (span) => {
|
2274
2395
|
var _a13, _b, _c, _d;
|
2275
2396
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2276
|
-
const validatedPrompt =
|
2397
|
+
const validatedPrompt = validatePrompt({
|
2277
2398
|
system,
|
2278
2399
|
prompt,
|
2279
2400
|
messages
|
@@ -2307,7 +2428,7 @@ async function generateText({
|
|
2307
2428
|
telemetry,
|
2308
2429
|
attributes: {
|
2309
2430
|
...assembleOperationName({
|
2310
|
-
|
2431
|
+
operationId: "ai.generateText.doGenerate",
|
2311
2432
|
telemetry
|
2312
2433
|
}),
|
2313
2434
|
...baseTelemetryAttributes,
|
@@ -2451,7 +2572,7 @@ async function executeTools({
|
|
2451
2572
|
telemetry,
|
2452
2573
|
attributes: {
|
2453
2574
|
...assembleOperationName({
|
2454
|
-
|
2575
|
+
operationId: "ai.toolCall",
|
2455
2576
|
telemetry
|
2456
2577
|
}),
|
2457
2578
|
"ai.toolCall.name": toolCall.toolName,
|
@@ -2701,7 +2822,7 @@ function runToolsTransformation({
|
|
2701
2822
|
telemetry,
|
2702
2823
|
attributes: {
|
2703
2824
|
...assembleOperationName({
|
2704
|
-
|
2825
|
+
operationId: "ai.toolCall",
|
2705
2826
|
telemetry
|
2706
2827
|
}),
|
2707
2828
|
"ai.toolCall.name": toolCall.toolName,
|
@@ -2838,7 +2959,7 @@ async function streamText({
|
|
2838
2959
|
attributes: selectTelemetryAttributes({
|
2839
2960
|
telemetry,
|
2840
2961
|
attributes: {
|
2841
|
-
...assembleOperationName({
|
2962
|
+
...assembleOperationName({ operationId: "ai.streamText", telemetry }),
|
2842
2963
|
...baseTelemetryAttributes,
|
2843
2964
|
// specific settings that only make sense on the outer level:
|
2844
2965
|
"ai.prompt": {
|
@@ -2850,14 +2971,15 @@ async function streamText({
|
|
2850
2971
|
endWhenDone: false,
|
2851
2972
|
fn: async (rootSpan) => {
|
2852
2973
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2853
|
-
const validatedPrompt =
|
2974
|
+
const validatedPrompt = validatePrompt({ system, prompt, messages });
|
2854
2975
|
const promptMessages = await convertToLanguageModelPrompt({
|
2855
2976
|
prompt: validatedPrompt,
|
2856
2977
|
modelSupportsImageUrls: model.supportsImageUrls
|
2857
2978
|
});
|
2858
2979
|
const {
|
2859
2980
|
result: { stream, warnings, rawResponse },
|
2860
|
-
doStreamSpan
|
2981
|
+
doStreamSpan,
|
2982
|
+
startTimestamp
|
2861
2983
|
} = await retry(
|
2862
2984
|
() => recordSpan({
|
2863
2985
|
name: "ai.streamText.doStream",
|
@@ -2865,7 +2987,7 @@ async function streamText({
|
|
2865
2987
|
telemetry,
|
2866
2988
|
attributes: {
|
2867
2989
|
...assembleOperationName({
|
2868
|
-
|
2990
|
+
operationId: "ai.streamText.doStream",
|
2869
2991
|
telemetry
|
2870
2992
|
}),
|
2871
2993
|
...baseTelemetryAttributes,
|
@@ -2885,22 +3007,22 @@ async function streamText({
|
|
2885
3007
|
}),
|
2886
3008
|
tracer,
|
2887
3009
|
endWhenDone: false,
|
2888
|
-
fn: async (doStreamSpan2) => {
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
...
|
2896
|
-
|
2897
|
-
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2901
|
-
|
2902
|
-
}
|
2903
|
-
}
|
3010
|
+
fn: async (doStreamSpan2) => ({
|
3011
|
+
startTimestamp: performance.now(),
|
3012
|
+
// get before the call
|
3013
|
+
doStreamSpan: doStreamSpan2,
|
3014
|
+
result: await model.doStream({
|
3015
|
+
mode: {
|
3016
|
+
type: "regular",
|
3017
|
+
...prepareToolsAndToolChoice({ tools, toolChoice })
|
3018
|
+
},
|
3019
|
+
...prepareCallSettings(settings),
|
3020
|
+
inputFormat: validatedPrompt.type,
|
3021
|
+
prompt: promptMessages,
|
3022
|
+
abortSignal,
|
3023
|
+
headers
|
3024
|
+
})
|
3025
|
+
})
|
2904
3026
|
})
|
2905
3027
|
);
|
2906
3028
|
return new DefaultStreamTextResult({
|
@@ -2917,7 +3039,8 @@ async function streamText({
|
|
2917
3039
|
onFinish,
|
2918
3040
|
rootSpan,
|
2919
3041
|
doStreamSpan,
|
2920
|
-
telemetry
|
3042
|
+
telemetry,
|
3043
|
+
startTimestamp
|
2921
3044
|
});
|
2922
3045
|
}
|
2923
3046
|
});
|
@@ -2931,7 +3054,8 @@ var DefaultStreamTextResult = class {
|
|
2931
3054
|
onFinish,
|
2932
3055
|
rootSpan,
|
2933
3056
|
doStreamSpan,
|
2934
|
-
telemetry
|
3057
|
+
telemetry,
|
3058
|
+
startTimestamp
|
2935
3059
|
}) {
|
2936
3060
|
this.warnings = warnings;
|
2937
3061
|
this.rawResponse = rawResponse;
|
@@ -2961,8 +3085,14 @@ var DefaultStreamTextResult = class {
|
|
2961
3085
|
new TransformStream({
|
2962
3086
|
async transform(chunk, controller) {
|
2963
3087
|
if (firstChunk) {
|
3088
|
+
const msToFirstChunk = performance.now() - startTimestamp;
|
2964
3089
|
firstChunk = false;
|
2965
|
-
doStreamSpan.addEvent("ai.stream.firstChunk"
|
3090
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
3091
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
3092
|
+
});
|
3093
|
+
doStreamSpan.setAttributes({
|
3094
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
3095
|
+
});
|
2966
3096
|
}
|
2967
3097
|
if (chunk.type === "text-delta" && chunk.textDelta.length === 0) {
|
2968
3098
|
return;
|
@@ -4716,10 +4846,7 @@ export {
|
|
4716
4846
|
StreamingTextResponse,
|
4717
4847
|
TypeValidationError,
|
4718
4848
|
UnsupportedFunctionalityError,
|
4719
|
-
convertDataContentToBase64String,
|
4720
|
-
convertDataContentToUint8Array,
|
4721
4849
|
convertToCoreMessages,
|
4722
|
-
convertUint8ArrayToText,
|
4723
4850
|
cosineSimilarity,
|
4724
4851
|
createCallbacksTransformer,
|
4725
4852
|
createEventStreamTransformer,
|