ai 3.3.10 → 3.3.11
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 +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +69 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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,
|
@@ -1301,7 +1303,7 @@ async function generateObject({
|
|
1301
1303
|
telemetry,
|
1302
1304
|
attributes: {
|
1303
1305
|
...assembleOperationName({
|
1304
|
-
|
1306
|
+
operationId: "ai.generateObject",
|
1305
1307
|
telemetry
|
1306
1308
|
}),
|
1307
1309
|
...baseTelemetryAttributes,
|
@@ -1352,7 +1354,7 @@ async function generateObject({
|
|
1352
1354
|
telemetry,
|
1353
1355
|
attributes: {
|
1354
1356
|
...assembleOperationName({
|
1355
|
-
|
1357
|
+
operationId: "ai.generateObject.doGenerate",
|
1356
1358
|
telemetry
|
1357
1359
|
}),
|
1358
1360
|
...baseTelemetryAttributes,
|
@@ -1435,7 +1437,7 @@ async function generateObject({
|
|
1435
1437
|
telemetry,
|
1436
1438
|
attributes: {
|
1437
1439
|
...assembleOperationName({
|
1438
|
-
|
1440
|
+
operationId: "ai.generateObject.doGenerate",
|
1439
1441
|
telemetry
|
1440
1442
|
}),
|
1441
1443
|
...baseTelemetryAttributes,
|
@@ -1677,7 +1679,7 @@ async function streamObject({
|
|
1677
1679
|
telemetry,
|
1678
1680
|
attributes: {
|
1679
1681
|
...assembleOperationName({
|
1680
|
-
|
1682
|
+
operationId: "ai.streamObject",
|
1681
1683
|
telemetry
|
1682
1684
|
}),
|
1683
1685
|
...baseTelemetryAttributes,
|
@@ -1792,7 +1794,8 @@ async function streamObject({
|
|
1792
1794
|
}
|
1793
1795
|
const {
|
1794
1796
|
result: { stream, warnings, rawResponse },
|
1795
|
-
doStreamSpan
|
1797
|
+
doStreamSpan,
|
1798
|
+
startTimestamp
|
1796
1799
|
} = await retry(
|
1797
1800
|
() => recordSpan({
|
1798
1801
|
name: "ai.streamObject.doStream",
|
@@ -1800,7 +1803,7 @@ async function streamObject({
|
|
1800
1803
|
telemetry,
|
1801
1804
|
attributes: {
|
1802
1805
|
...assembleOperationName({
|
1803
|
-
|
1806
|
+
operationId: "ai.streamObject.doStream",
|
1804
1807
|
telemetry
|
1805
1808
|
}),
|
1806
1809
|
...baseTelemetryAttributes,
|
@@ -1822,8 +1825,10 @@ async function streamObject({
|
|
1822
1825
|
tracer,
|
1823
1826
|
endWhenDone: false,
|
1824
1827
|
fn: async (doStreamSpan2) => ({
|
1825
|
-
|
1826
|
-
|
1828
|
+
startTimestamp: performance.now(),
|
1829
|
+
// get before the call
|
1830
|
+
doStreamSpan: doStreamSpan2,
|
1831
|
+
result: await model.doStream(callOptions)
|
1827
1832
|
})
|
1828
1833
|
})
|
1829
1834
|
);
|
@@ -1835,7 +1840,8 @@ async function streamObject({
|
|
1835
1840
|
onFinish,
|
1836
1841
|
rootSpan,
|
1837
1842
|
doStreamSpan,
|
1838
|
-
telemetry
|
1843
|
+
telemetry,
|
1844
|
+
startTimestamp
|
1839
1845
|
});
|
1840
1846
|
}
|
1841
1847
|
});
|
@@ -1849,7 +1855,8 @@ var DefaultStreamObjectResult = class {
|
|
1849
1855
|
onFinish,
|
1850
1856
|
rootSpan,
|
1851
1857
|
doStreamSpan,
|
1852
|
-
telemetry
|
1858
|
+
telemetry,
|
1859
|
+
startTimestamp
|
1853
1860
|
}) {
|
1854
1861
|
this.warnings = warnings;
|
1855
1862
|
this.rawResponse = rawResponse;
|
@@ -1875,8 +1882,14 @@ var DefaultStreamObjectResult = class {
|
|
1875
1882
|
new TransformStream({
|
1876
1883
|
async transform(chunk, controller) {
|
1877
1884
|
if (firstChunk) {
|
1885
|
+
const msToFirstChunk = performance.now() - startTimestamp;
|
1878
1886
|
firstChunk = false;
|
1879
|
-
doStreamSpan.addEvent("ai.stream.firstChunk"
|
1887
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
1888
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
1889
|
+
});
|
1890
|
+
doStreamSpan.setAttributes({
|
1891
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
1892
|
+
});
|
1880
1893
|
}
|
1881
1894
|
if (typeof chunk === "string") {
|
1882
1895
|
accumulatedText += chunk;
|
@@ -2258,7 +2271,7 @@ async function generateText({
|
|
2258
2271
|
telemetry,
|
2259
2272
|
attributes: {
|
2260
2273
|
...assembleOperationName({
|
2261
|
-
|
2274
|
+
operationId: "ai.generateText",
|
2262
2275
|
telemetry
|
2263
2276
|
}),
|
2264
2277
|
...baseTelemetryAttributes,
|
@@ -2307,7 +2320,7 @@ async function generateText({
|
|
2307
2320
|
telemetry,
|
2308
2321
|
attributes: {
|
2309
2322
|
...assembleOperationName({
|
2310
|
-
|
2323
|
+
operationId: "ai.generateText.doGenerate",
|
2311
2324
|
telemetry
|
2312
2325
|
}),
|
2313
2326
|
...baseTelemetryAttributes,
|
@@ -2451,7 +2464,7 @@ async function executeTools({
|
|
2451
2464
|
telemetry,
|
2452
2465
|
attributes: {
|
2453
2466
|
...assembleOperationName({
|
2454
|
-
|
2467
|
+
operationId: "ai.toolCall",
|
2455
2468
|
telemetry
|
2456
2469
|
}),
|
2457
2470
|
"ai.toolCall.name": toolCall.toolName,
|
@@ -2701,7 +2714,7 @@ function runToolsTransformation({
|
|
2701
2714
|
telemetry,
|
2702
2715
|
attributes: {
|
2703
2716
|
...assembleOperationName({
|
2704
|
-
|
2717
|
+
operationId: "ai.toolCall",
|
2705
2718
|
telemetry
|
2706
2719
|
}),
|
2707
2720
|
"ai.toolCall.name": toolCall.toolName,
|
@@ -2838,7 +2851,7 @@ async function streamText({
|
|
2838
2851
|
attributes: selectTelemetryAttributes({
|
2839
2852
|
telemetry,
|
2840
2853
|
attributes: {
|
2841
|
-
...assembleOperationName({
|
2854
|
+
...assembleOperationName({ operationId: "ai.streamText", telemetry }),
|
2842
2855
|
...baseTelemetryAttributes,
|
2843
2856
|
// specific settings that only make sense on the outer level:
|
2844
2857
|
"ai.prompt": {
|
@@ -2857,7 +2870,8 @@ async function streamText({
|
|
2857
2870
|
});
|
2858
2871
|
const {
|
2859
2872
|
result: { stream, warnings, rawResponse },
|
2860
|
-
doStreamSpan
|
2873
|
+
doStreamSpan,
|
2874
|
+
startTimestamp
|
2861
2875
|
} = await retry(
|
2862
2876
|
() => recordSpan({
|
2863
2877
|
name: "ai.streamText.doStream",
|
@@ -2865,7 +2879,7 @@ async function streamText({
|
|
2865
2879
|
telemetry,
|
2866
2880
|
attributes: {
|
2867
2881
|
...assembleOperationName({
|
2868
|
-
|
2882
|
+
operationId: "ai.streamText.doStream",
|
2869
2883
|
telemetry
|
2870
2884
|
}),
|
2871
2885
|
...baseTelemetryAttributes,
|
@@ -2885,22 +2899,22 @@ async function streamText({
|
|
2885
2899
|
}),
|
2886
2900
|
tracer,
|
2887
2901
|
endWhenDone: false,
|
2888
|
-
fn: async (doStreamSpan2) => {
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
...
|
2896
|
-
|
2897
|
-
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2901
|
-
|
2902
|
-
}
|
2903
|
-
}
|
2902
|
+
fn: async (doStreamSpan2) => ({
|
2903
|
+
startTimestamp: performance.now(),
|
2904
|
+
// get before the call
|
2905
|
+
doStreamSpan: doStreamSpan2,
|
2906
|
+
result: await model.doStream({
|
2907
|
+
mode: {
|
2908
|
+
type: "regular",
|
2909
|
+
...prepareToolsAndToolChoice({ tools, toolChoice })
|
2910
|
+
},
|
2911
|
+
...prepareCallSettings(settings),
|
2912
|
+
inputFormat: validatedPrompt.type,
|
2913
|
+
prompt: promptMessages,
|
2914
|
+
abortSignal,
|
2915
|
+
headers
|
2916
|
+
})
|
2917
|
+
})
|
2904
2918
|
})
|
2905
2919
|
);
|
2906
2920
|
return new DefaultStreamTextResult({
|
@@ -2917,7 +2931,8 @@ async function streamText({
|
|
2917
2931
|
onFinish,
|
2918
2932
|
rootSpan,
|
2919
2933
|
doStreamSpan,
|
2920
|
-
telemetry
|
2934
|
+
telemetry,
|
2935
|
+
startTimestamp
|
2921
2936
|
});
|
2922
2937
|
}
|
2923
2938
|
});
|
@@ -2931,7 +2946,8 @@ var DefaultStreamTextResult = class {
|
|
2931
2946
|
onFinish,
|
2932
2947
|
rootSpan,
|
2933
2948
|
doStreamSpan,
|
2934
|
-
telemetry
|
2949
|
+
telemetry,
|
2950
|
+
startTimestamp
|
2935
2951
|
}) {
|
2936
2952
|
this.warnings = warnings;
|
2937
2953
|
this.rawResponse = rawResponse;
|
@@ -2961,8 +2977,14 @@ var DefaultStreamTextResult = class {
|
|
2961
2977
|
new TransformStream({
|
2962
2978
|
async transform(chunk, controller) {
|
2963
2979
|
if (firstChunk) {
|
2980
|
+
const msToFirstChunk = performance.now() - startTimestamp;
|
2964
2981
|
firstChunk = false;
|
2965
|
-
doStreamSpan.addEvent("ai.stream.firstChunk"
|
2982
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
2983
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
2984
|
+
});
|
2985
|
+
doStreamSpan.setAttributes({
|
2986
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
2987
|
+
});
|
2966
2988
|
}
|
2967
2989
|
if (chunk.type === "text-delta" && chunk.textDelta.length === 0) {
|
2968
2990
|
return;
|