ai 3.3.9 → 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 +3 -3
package/dist/index.d.mts
CHANGED
@@ -932,7 +932,7 @@ declare class DefaultStreamObjectResult<T> implements StreamObjectResult<T> {
|
|
932
932
|
readonly usage: StreamObjectResult<T>['usage'];
|
933
933
|
readonly experimental_providerMetadata: StreamObjectResult<T>['experimental_providerMetadata'];
|
934
934
|
readonly rawResponse: StreamObjectResult<T>['rawResponse'];
|
935
|
-
constructor({ stream, warnings, rawResponse, schema, onFinish, rootSpan, doStreamSpan, telemetry, }: {
|
935
|
+
constructor({ stream, warnings, rawResponse, schema, onFinish, rootSpan, doStreamSpan, telemetry, startTimestamp, }: {
|
936
936
|
stream: ReadableStream<string | Omit<LanguageModelV1StreamPart, 'text-delta'>>;
|
937
937
|
warnings: StreamObjectResult<T>['warnings'];
|
938
938
|
rawResponse?: StreamObjectResult<T>['rawResponse'];
|
@@ -941,6 +941,7 @@ declare class DefaultStreamObjectResult<T> implements StreamObjectResult<T> {
|
|
941
941
|
rootSpan: Span;
|
942
942
|
doStreamSpan: Span;
|
943
943
|
telemetry: TelemetrySettings | undefined;
|
944
|
+
startTimestamp: number;
|
944
945
|
});
|
945
946
|
get object(): Promise<T>;
|
946
947
|
get partialObjectStream(): AsyncIterableStream<DeepPartial<T>>;
|
@@ -1595,7 +1596,7 @@ declare class DefaultStreamTextResult<TOOLS extends Record<string, CoreTool>> im
|
|
1595
1596
|
readonly toolCalls: StreamTextResult<TOOLS>['toolCalls'];
|
1596
1597
|
readonly toolResults: StreamTextResult<TOOLS>['toolResults'];
|
1597
1598
|
readonly rawResponse: StreamTextResult<TOOLS>['rawResponse'];
|
1598
|
-
constructor({ stream, warnings, rawResponse, onChunk, onFinish, rootSpan, doStreamSpan, telemetry, }: {
|
1599
|
+
constructor({ stream, warnings, rawResponse, onChunk, onFinish, rootSpan, doStreamSpan, telemetry, startTimestamp, }: {
|
1599
1600
|
stream: ReadableStream<TextStreamPart<TOOLS>>;
|
1600
1601
|
warnings: StreamTextResult<TOOLS>['warnings'];
|
1601
1602
|
rawResponse: StreamTextResult<TOOLS>['rawResponse'];
|
@@ -1604,6 +1605,7 @@ declare class DefaultStreamTextResult<TOOLS extends Record<string, CoreTool>> im
|
|
1604
1605
|
rootSpan: Span;
|
1605
1606
|
doStreamSpan: Span;
|
1606
1607
|
telemetry: TelemetrySettings | undefined;
|
1608
|
+
startTimestamp: number;
|
1607
1609
|
});
|
1608
1610
|
/**
|
1609
1611
|
Split out a new stream from the original stream.
|
package/dist/index.d.ts
CHANGED
@@ -932,7 +932,7 @@ declare class DefaultStreamObjectResult<T> implements StreamObjectResult<T> {
|
|
932
932
|
readonly usage: StreamObjectResult<T>['usage'];
|
933
933
|
readonly experimental_providerMetadata: StreamObjectResult<T>['experimental_providerMetadata'];
|
934
934
|
readonly rawResponse: StreamObjectResult<T>['rawResponse'];
|
935
|
-
constructor({ stream, warnings, rawResponse, schema, onFinish, rootSpan, doStreamSpan, telemetry, }: {
|
935
|
+
constructor({ stream, warnings, rawResponse, schema, onFinish, rootSpan, doStreamSpan, telemetry, startTimestamp, }: {
|
936
936
|
stream: ReadableStream<string | Omit<LanguageModelV1StreamPart, 'text-delta'>>;
|
937
937
|
warnings: StreamObjectResult<T>['warnings'];
|
938
938
|
rawResponse?: StreamObjectResult<T>['rawResponse'];
|
@@ -941,6 +941,7 @@ declare class DefaultStreamObjectResult<T> implements StreamObjectResult<T> {
|
|
941
941
|
rootSpan: Span;
|
942
942
|
doStreamSpan: Span;
|
943
943
|
telemetry: TelemetrySettings | undefined;
|
944
|
+
startTimestamp: number;
|
944
945
|
});
|
945
946
|
get object(): Promise<T>;
|
946
947
|
get partialObjectStream(): AsyncIterableStream<DeepPartial<T>>;
|
@@ -1595,7 +1596,7 @@ declare class DefaultStreamTextResult<TOOLS extends Record<string, CoreTool>> im
|
|
1595
1596
|
readonly toolCalls: StreamTextResult<TOOLS>['toolCalls'];
|
1596
1597
|
readonly toolResults: StreamTextResult<TOOLS>['toolResults'];
|
1597
1598
|
readonly rawResponse: StreamTextResult<TOOLS>['rawResponse'];
|
1598
|
-
constructor({ stream, warnings, rawResponse, onChunk, onFinish, rootSpan, doStreamSpan, telemetry, }: {
|
1599
|
+
constructor({ stream, warnings, rawResponse, onChunk, onFinish, rootSpan, doStreamSpan, telemetry, startTimestamp, }: {
|
1599
1600
|
stream: ReadableStream<TextStreamPart<TOOLS>>;
|
1600
1601
|
warnings: StreamTextResult<TOOLS>['warnings'];
|
1601
1602
|
rawResponse: StreamTextResult<TOOLS>['rawResponse'];
|
@@ -1604,6 +1605,7 @@ declare class DefaultStreamTextResult<TOOLS extends Record<string, CoreTool>> im
|
|
1604
1605
|
rootSpan: Span;
|
1605
1606
|
doStreamSpan: Span;
|
1606
1607
|
telemetry: TelemetrySettings | undefined;
|
1608
|
+
startTimestamp: number;
|
1607
1609
|
});
|
1608
1610
|
/**
|
1609
1611
|
Split out a new stream from the original stream.
|
package/dist/index.js
CHANGED
@@ -206,11 +206,16 @@ async function _retryWithExponentialBackoff(f, {
|
|
206
206
|
|
207
207
|
// core/telemetry/assemble-operation-name.ts
|
208
208
|
function assembleOperationName({
|
209
|
-
|
209
|
+
operationId,
|
210
210
|
telemetry
|
211
211
|
}) {
|
212
212
|
return {
|
213
|
-
|
213
|
+
// standardized operation and resource name:
|
214
|
+
"operation.name": `${operationId}${(telemetry == null ? void 0 : telemetry.functionId) != null ? ` ${telemetry.functionId}` : ""}`,
|
215
|
+
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
216
|
+
// detailed, AI SDK specific data:
|
217
|
+
"ai.operationId": operationId,
|
218
|
+
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId
|
214
219
|
};
|
215
220
|
}
|
216
221
|
|
@@ -230,9 +235,6 @@ function getBaseTelemetryAttributes({
|
|
230
235
|
attributes[`ai.settings.${key}`] = value;
|
231
236
|
return attributes;
|
232
237
|
}, {}),
|
233
|
-
// special telemetry information
|
234
|
-
"resource.name": telemetry == null ? void 0 : telemetry.functionId,
|
235
|
-
"ai.telemetry.functionId": telemetry == null ? void 0 : telemetry.functionId,
|
236
238
|
// add metadata as attributes:
|
237
239
|
...Object.entries((_a12 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a12 : {}).reduce(
|
238
240
|
(attributes, [key, value]) => {
|
@@ -412,7 +414,7 @@ async function embed({
|
|
412
414
|
attributes: selectTelemetryAttributes({
|
413
415
|
telemetry,
|
414
416
|
attributes: {
|
415
|
-
...assembleOperationName({
|
417
|
+
...assembleOperationName({ operationId: "ai.embed", telemetry }),
|
416
418
|
...baseTelemetryAttributes,
|
417
419
|
"ai.value": { input: () => JSON.stringify(value) }
|
418
420
|
}
|
@@ -429,7 +431,7 @@ async function embed({
|
|
429
431
|
telemetry,
|
430
432
|
attributes: {
|
431
433
|
...assembleOperationName({
|
432
|
-
|
434
|
+
operationId: "ai.embed.doEmbed",
|
433
435
|
telemetry
|
434
436
|
}),
|
435
437
|
...baseTelemetryAttributes,
|
@@ -525,7 +527,7 @@ async function embedMany({
|
|
525
527
|
attributes: selectTelemetryAttributes({
|
526
528
|
telemetry,
|
527
529
|
attributes: {
|
528
|
-
...assembleOperationName({
|
530
|
+
...assembleOperationName({ operationId: "ai.embedMany", telemetry }),
|
529
531
|
...baseTelemetryAttributes,
|
530
532
|
// specific settings that only make sense on the outer level:
|
531
533
|
"ai.values": {
|
@@ -545,7 +547,7 @@ async function embedMany({
|
|
545
547
|
telemetry,
|
546
548
|
attributes: {
|
547
549
|
...assembleOperationName({
|
548
|
-
|
550
|
+
operationId: "ai.embedMany.doEmbed",
|
549
551
|
telemetry
|
550
552
|
}),
|
551
553
|
...baseTelemetryAttributes,
|
@@ -604,7 +606,7 @@ async function embedMany({
|
|
604
606
|
telemetry,
|
605
607
|
attributes: {
|
606
608
|
...assembleOperationName({
|
607
|
-
|
609
|
+
operationId: "ai.embedMany.doEmbed",
|
608
610
|
telemetry
|
609
611
|
}),
|
610
612
|
...baseTelemetryAttributes,
|
@@ -1382,7 +1384,7 @@ async function generateObject({
|
|
1382
1384
|
telemetry,
|
1383
1385
|
attributes: {
|
1384
1386
|
...assembleOperationName({
|
1385
|
-
|
1387
|
+
operationId: "ai.generateObject",
|
1386
1388
|
telemetry
|
1387
1389
|
}),
|
1388
1390
|
...baseTelemetryAttributes,
|
@@ -1433,7 +1435,7 @@ async function generateObject({
|
|
1433
1435
|
telemetry,
|
1434
1436
|
attributes: {
|
1435
1437
|
...assembleOperationName({
|
1436
|
-
|
1438
|
+
operationId: "ai.generateObject.doGenerate",
|
1437
1439
|
telemetry
|
1438
1440
|
}),
|
1439
1441
|
...baseTelemetryAttributes,
|
@@ -1516,7 +1518,7 @@ async function generateObject({
|
|
1516
1518
|
telemetry,
|
1517
1519
|
attributes: {
|
1518
1520
|
...assembleOperationName({
|
1519
|
-
|
1521
|
+
operationId: "ai.generateObject.doGenerate",
|
1520
1522
|
telemetry
|
1521
1523
|
}),
|
1522
1524
|
...baseTelemetryAttributes,
|
@@ -1754,7 +1756,7 @@ async function streamObject({
|
|
1754
1756
|
telemetry,
|
1755
1757
|
attributes: {
|
1756
1758
|
...assembleOperationName({
|
1757
|
-
|
1759
|
+
operationId: "ai.streamObject",
|
1758
1760
|
telemetry
|
1759
1761
|
}),
|
1760
1762
|
...baseTelemetryAttributes,
|
@@ -1869,7 +1871,8 @@ async function streamObject({
|
|
1869
1871
|
}
|
1870
1872
|
const {
|
1871
1873
|
result: { stream, warnings, rawResponse },
|
1872
|
-
doStreamSpan
|
1874
|
+
doStreamSpan,
|
1875
|
+
startTimestamp
|
1873
1876
|
} = await retry(
|
1874
1877
|
() => recordSpan({
|
1875
1878
|
name: "ai.streamObject.doStream",
|
@@ -1877,7 +1880,7 @@ async function streamObject({
|
|
1877
1880
|
telemetry,
|
1878
1881
|
attributes: {
|
1879
1882
|
...assembleOperationName({
|
1880
|
-
|
1883
|
+
operationId: "ai.streamObject.doStream",
|
1881
1884
|
telemetry
|
1882
1885
|
}),
|
1883
1886
|
...baseTelemetryAttributes,
|
@@ -1899,8 +1902,10 @@ async function streamObject({
|
|
1899
1902
|
tracer,
|
1900
1903
|
endWhenDone: false,
|
1901
1904
|
fn: async (doStreamSpan2) => ({
|
1902
|
-
|
1903
|
-
|
1905
|
+
startTimestamp: performance.now(),
|
1906
|
+
// get before the call
|
1907
|
+
doStreamSpan: doStreamSpan2,
|
1908
|
+
result: await model.doStream(callOptions)
|
1904
1909
|
})
|
1905
1910
|
})
|
1906
1911
|
);
|
@@ -1912,7 +1917,8 @@ async function streamObject({
|
|
1912
1917
|
onFinish,
|
1913
1918
|
rootSpan,
|
1914
1919
|
doStreamSpan,
|
1915
|
-
telemetry
|
1920
|
+
telemetry,
|
1921
|
+
startTimestamp
|
1916
1922
|
});
|
1917
1923
|
}
|
1918
1924
|
});
|
@@ -1926,7 +1932,8 @@ var DefaultStreamObjectResult = class {
|
|
1926
1932
|
onFinish,
|
1927
1933
|
rootSpan,
|
1928
1934
|
doStreamSpan,
|
1929
|
-
telemetry
|
1935
|
+
telemetry,
|
1936
|
+
startTimestamp
|
1930
1937
|
}) {
|
1931
1938
|
this.warnings = warnings;
|
1932
1939
|
this.rawResponse = rawResponse;
|
@@ -1952,8 +1959,14 @@ var DefaultStreamObjectResult = class {
|
|
1952
1959
|
new TransformStream({
|
1953
1960
|
async transform(chunk, controller) {
|
1954
1961
|
if (firstChunk) {
|
1962
|
+
const msToFirstChunk = performance.now() - startTimestamp;
|
1955
1963
|
firstChunk = false;
|
1956
|
-
doStreamSpan.addEvent("ai.stream.firstChunk"
|
1964
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
1965
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
1966
|
+
});
|
1967
|
+
doStreamSpan.setAttributes({
|
1968
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
1969
|
+
});
|
1957
1970
|
}
|
1958
1971
|
if (typeof chunk === "string") {
|
1959
1972
|
accumulatedText += chunk;
|
@@ -2335,7 +2348,7 @@ async function generateText({
|
|
2335
2348
|
telemetry,
|
2336
2349
|
attributes: {
|
2337
2350
|
...assembleOperationName({
|
2338
|
-
|
2351
|
+
operationId: "ai.generateText",
|
2339
2352
|
telemetry
|
2340
2353
|
}),
|
2341
2354
|
...baseTelemetryAttributes,
|
@@ -2384,7 +2397,7 @@ async function generateText({
|
|
2384
2397
|
telemetry,
|
2385
2398
|
attributes: {
|
2386
2399
|
...assembleOperationName({
|
2387
|
-
|
2400
|
+
operationId: "ai.generateText.doGenerate",
|
2388
2401
|
telemetry
|
2389
2402
|
}),
|
2390
2403
|
...baseTelemetryAttributes,
|
@@ -2528,7 +2541,7 @@ async function executeTools({
|
|
2528
2541
|
telemetry,
|
2529
2542
|
attributes: {
|
2530
2543
|
...assembleOperationName({
|
2531
|
-
|
2544
|
+
operationId: "ai.toolCall",
|
2532
2545
|
telemetry
|
2533
2546
|
}),
|
2534
2547
|
"ai.toolCall.name": toolCall.toolName,
|
@@ -2778,7 +2791,7 @@ function runToolsTransformation({
|
|
2778
2791
|
telemetry,
|
2779
2792
|
attributes: {
|
2780
2793
|
...assembleOperationName({
|
2781
|
-
|
2794
|
+
operationId: "ai.toolCall",
|
2782
2795
|
telemetry
|
2783
2796
|
}),
|
2784
2797
|
"ai.toolCall.name": toolCall.toolName,
|
@@ -2915,7 +2928,7 @@ async function streamText({
|
|
2915
2928
|
attributes: selectTelemetryAttributes({
|
2916
2929
|
telemetry,
|
2917
2930
|
attributes: {
|
2918
|
-
...assembleOperationName({
|
2931
|
+
...assembleOperationName({ operationId: "ai.streamText", telemetry }),
|
2919
2932
|
...baseTelemetryAttributes,
|
2920
2933
|
// specific settings that only make sense on the outer level:
|
2921
2934
|
"ai.prompt": {
|
@@ -2934,7 +2947,8 @@ async function streamText({
|
|
2934
2947
|
});
|
2935
2948
|
const {
|
2936
2949
|
result: { stream, warnings, rawResponse },
|
2937
|
-
doStreamSpan
|
2950
|
+
doStreamSpan,
|
2951
|
+
startTimestamp
|
2938
2952
|
} = await retry(
|
2939
2953
|
() => recordSpan({
|
2940
2954
|
name: "ai.streamText.doStream",
|
@@ -2942,7 +2956,7 @@ async function streamText({
|
|
2942
2956
|
telemetry,
|
2943
2957
|
attributes: {
|
2944
2958
|
...assembleOperationName({
|
2945
|
-
|
2959
|
+
operationId: "ai.streamText.doStream",
|
2946
2960
|
telemetry
|
2947
2961
|
}),
|
2948
2962
|
...baseTelemetryAttributes,
|
@@ -2962,22 +2976,22 @@ async function streamText({
|
|
2962
2976
|
}),
|
2963
2977
|
tracer,
|
2964
2978
|
endWhenDone: false,
|
2965
|
-
fn: async (doStreamSpan2) => {
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2972
|
-
...
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
2979
|
-
}
|
2980
|
-
}
|
2979
|
+
fn: async (doStreamSpan2) => ({
|
2980
|
+
startTimestamp: performance.now(),
|
2981
|
+
// get before the call
|
2982
|
+
doStreamSpan: doStreamSpan2,
|
2983
|
+
result: await model.doStream({
|
2984
|
+
mode: {
|
2985
|
+
type: "regular",
|
2986
|
+
...prepareToolsAndToolChoice({ tools, toolChoice })
|
2987
|
+
},
|
2988
|
+
...prepareCallSettings(settings),
|
2989
|
+
inputFormat: validatedPrompt.type,
|
2990
|
+
prompt: promptMessages,
|
2991
|
+
abortSignal,
|
2992
|
+
headers
|
2993
|
+
})
|
2994
|
+
})
|
2981
2995
|
})
|
2982
2996
|
);
|
2983
2997
|
return new DefaultStreamTextResult({
|
@@ -2994,7 +3008,8 @@ async function streamText({
|
|
2994
3008
|
onFinish,
|
2995
3009
|
rootSpan,
|
2996
3010
|
doStreamSpan,
|
2997
|
-
telemetry
|
3011
|
+
telemetry,
|
3012
|
+
startTimestamp
|
2998
3013
|
});
|
2999
3014
|
}
|
3000
3015
|
});
|
@@ -3008,7 +3023,8 @@ var DefaultStreamTextResult = class {
|
|
3008
3023
|
onFinish,
|
3009
3024
|
rootSpan,
|
3010
3025
|
doStreamSpan,
|
3011
|
-
telemetry
|
3026
|
+
telemetry,
|
3027
|
+
startTimestamp
|
3012
3028
|
}) {
|
3013
3029
|
this.warnings = warnings;
|
3014
3030
|
this.rawResponse = rawResponse;
|
@@ -3038,8 +3054,14 @@ var DefaultStreamTextResult = class {
|
|
3038
3054
|
new TransformStream({
|
3039
3055
|
async transform(chunk, controller) {
|
3040
3056
|
if (firstChunk) {
|
3057
|
+
const msToFirstChunk = performance.now() - startTimestamp;
|
3041
3058
|
firstChunk = false;
|
3042
|
-
doStreamSpan.addEvent("ai.stream.firstChunk"
|
3059
|
+
doStreamSpan.addEvent("ai.stream.firstChunk", {
|
3060
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
3061
|
+
});
|
3062
|
+
doStreamSpan.setAttributes({
|
3063
|
+
"ai.stream.msToFirstChunk": msToFirstChunk
|
3064
|
+
});
|
3043
3065
|
}
|
3044
3066
|
if (chunk.type === "text-delta" && chunk.textDelta.length === 0) {
|
3045
3067
|
return;
|