ai 3.4.9 → 3.4.10
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/CHANGELOG.md +7 -0
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +27 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -231,13 +231,15 @@ var noopSpanContext = {
|
|
231
231
|
};
|
232
232
|
|
233
233
|
// core/telemetry/get-tracer.ts
|
234
|
-
|
235
|
-
|
234
|
+
function getTracer({
|
235
|
+
isEnabled = false,
|
236
|
+
tracer
|
237
|
+
} = {}) {
|
236
238
|
if (!isEnabled) {
|
237
239
|
return noopTracer;
|
238
240
|
}
|
239
|
-
if (
|
240
|
-
return
|
241
|
+
if (tracer) {
|
242
|
+
return tracer;
|
241
243
|
}
|
242
244
|
return trace.getTracer("ai");
|
243
245
|
}
|
@@ -317,14 +319,13 @@ async function embed({
|
|
317
319
|
headers,
|
318
320
|
experimental_telemetry: telemetry
|
319
321
|
}) {
|
320
|
-
var _a11;
|
321
322
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
322
323
|
model,
|
323
324
|
telemetry,
|
324
325
|
headers,
|
325
326
|
settings: { maxRetries }
|
326
327
|
});
|
327
|
-
const tracer = getTracer(
|
328
|
+
const tracer = getTracer(telemetry);
|
328
329
|
return recordSpan({
|
329
330
|
name: "ai.embed",
|
330
331
|
attributes: selectTelemetryAttributes({
|
@@ -357,14 +358,14 @@ async function embed({
|
|
357
358
|
}),
|
358
359
|
tracer,
|
359
360
|
fn: async (doEmbedSpan) => {
|
360
|
-
var
|
361
|
+
var _a11;
|
361
362
|
const modelResponse = await model.doEmbed({
|
362
363
|
values: [value],
|
363
364
|
abortSignal,
|
364
365
|
headers
|
365
366
|
});
|
366
367
|
const embedding2 = modelResponse.embeddings[0];
|
367
|
-
const usage2 = (
|
368
|
+
const usage2 = (_a11 = modelResponse.usage) != null ? _a11 : { tokens: NaN };
|
368
369
|
doEmbedSpan.setAttributes(
|
369
370
|
selectTelemetryAttributes({
|
370
371
|
telemetry,
|
@@ -430,14 +431,13 @@ async function embedMany({
|
|
430
431
|
headers,
|
431
432
|
experimental_telemetry: telemetry
|
432
433
|
}) {
|
433
|
-
var _a11;
|
434
434
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
435
435
|
model,
|
436
436
|
telemetry,
|
437
437
|
headers,
|
438
438
|
settings: { maxRetries }
|
439
439
|
});
|
440
|
-
const tracer = getTracer(
|
440
|
+
const tracer = getTracer(telemetry);
|
441
441
|
return recordSpan({
|
442
442
|
name: "ai.embedMany",
|
443
443
|
attributes: selectTelemetryAttributes({
|
@@ -475,14 +475,14 @@ async function embedMany({
|
|
475
475
|
}),
|
476
476
|
tracer,
|
477
477
|
fn: async (doEmbedSpan) => {
|
478
|
-
var
|
478
|
+
var _a11;
|
479
479
|
const modelResponse = await model.doEmbed({
|
480
480
|
values,
|
481
481
|
abortSignal,
|
482
482
|
headers
|
483
483
|
});
|
484
484
|
const embeddings3 = modelResponse.embeddings;
|
485
|
-
const usage2 = (
|
485
|
+
const usage2 = (_a11 = modelResponse.usage) != null ? _a11 : { tokens: NaN };
|
486
486
|
doEmbedSpan.setAttributes(
|
487
487
|
selectTelemetryAttributes({
|
488
488
|
telemetry,
|
@@ -534,14 +534,14 @@ async function embedMany({
|
|
534
534
|
}),
|
535
535
|
tracer,
|
536
536
|
fn: async (doEmbedSpan) => {
|
537
|
-
var
|
537
|
+
var _a11;
|
538
538
|
const modelResponse = await model.doEmbed({
|
539
539
|
values: chunk,
|
540
540
|
abortSignal,
|
541
541
|
headers
|
542
542
|
});
|
543
543
|
const embeddings2 = modelResponse.embeddings;
|
544
|
-
const usage2 = (
|
544
|
+
const usage2 = (_a11 = modelResponse.usage) != null ? _a11 : { tokens: NaN };
|
545
545
|
doEmbedSpan.setAttributes(
|
546
546
|
selectTelemetryAttributes({
|
547
547
|
telemetry,
|
@@ -1908,7 +1908,6 @@ async function generateObject({
|
|
1908
1908
|
} = {},
|
1909
1909
|
...settings
|
1910
1910
|
}) {
|
1911
|
-
var _a11;
|
1912
1911
|
validateObjectGenerationInput({
|
1913
1912
|
output,
|
1914
1913
|
mode,
|
@@ -1931,7 +1930,7 @@ async function generateObject({
|
|
1931
1930
|
headers,
|
1932
1931
|
settings: { ...settings, maxRetries }
|
1933
1932
|
});
|
1934
|
-
const tracer = getTracer(
|
1933
|
+
const tracer = getTracer(telemetry);
|
1935
1934
|
return recordSpan({
|
1936
1935
|
name: "ai.generateObject",
|
1937
1936
|
attributes: selectTelemetryAttributes({
|
@@ -2013,7 +2012,7 @@ async function generateObject({
|
|
2013
2012
|
}),
|
2014
2013
|
tracer,
|
2015
2014
|
fn: async (span2) => {
|
2016
|
-
var
|
2015
|
+
var _a11, _b, _c, _d, _e, _f;
|
2017
2016
|
const result2 = await model.doGenerate({
|
2018
2017
|
mode: {
|
2019
2018
|
type: "object-json",
|
@@ -2032,7 +2031,7 @@ async function generateObject({
|
|
2032
2031
|
throw new NoObjectGeneratedError();
|
2033
2032
|
}
|
2034
2033
|
const responseData = {
|
2035
|
-
id: (_b = (
|
2034
|
+
id: (_b = (_a11 = result2.response) == null ? void 0 : _a11.id) != null ? _b : generateId3(),
|
2036
2035
|
timestamp: (_d = (_c = result2.response) == null ? void 0 : _c.timestamp) != null ? _d : currentDate(),
|
2037
2036
|
modelId: (_f = (_e = result2.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
2038
2037
|
};
|
@@ -2115,7 +2114,7 @@ async function generateObject({
|
|
2115
2114
|
}),
|
2116
2115
|
tracer,
|
2117
2116
|
fn: async (span2) => {
|
2118
|
-
var
|
2117
|
+
var _a11, _b, _c, _d, _e, _f, _g, _h;
|
2119
2118
|
const result2 = await model.doGenerate({
|
2120
2119
|
mode: {
|
2121
2120
|
type: "object-tool",
|
@@ -2133,7 +2132,7 @@ async function generateObject({
|
|
2133
2132
|
abortSignal,
|
2134
2133
|
headers
|
2135
2134
|
});
|
2136
|
-
const objectText = (_b = (
|
2135
|
+
const objectText = (_b = (_a11 = result2.toolCalls) == null ? void 0 : _a11[0]) == null ? void 0 : _b.args;
|
2137
2136
|
if (objectText === void 0) {
|
2138
2137
|
throw new NoObjectGeneratedError();
|
2139
2138
|
}
|
@@ -2258,6 +2257,7 @@ var DefaultGenerateObjectResult = class {
|
|
2258
2257
|
var experimental_generateObject = generateObject;
|
2259
2258
|
|
2260
2259
|
// core/generate-object/stream-object.ts
|
2260
|
+
import { createIdGenerator as createIdGenerator2 } from "@ai-sdk/provider-utils";
|
2261
2261
|
import {
|
2262
2262
|
isDeepEqualData,
|
2263
2263
|
parsePartialJson
|
@@ -2322,9 +2322,6 @@ function now() {
|
|
2322
2322
|
return (_b = (_a11 = globalThis == null ? void 0 : globalThis.performance) == null ? void 0 : _a11.now()) != null ? _b : Date.now();
|
2323
2323
|
}
|
2324
2324
|
|
2325
|
-
// core/generate-object/stream-object.ts
|
2326
|
-
import { createIdGenerator as createIdGenerator2 } from "@ai-sdk/provider-utils";
|
2327
|
-
|
2328
2325
|
// core/util/prepare-outgoing-http-headers.ts
|
2329
2326
|
function prepareOutgoingHttpHeaders(init, {
|
2330
2327
|
contentType,
|
@@ -2397,7 +2394,6 @@ async function streamObject({
|
|
2397
2394
|
} = {},
|
2398
2395
|
...settings
|
2399
2396
|
}) {
|
2400
|
-
var _a11;
|
2401
2397
|
validateObjectGenerationInput({
|
2402
2398
|
output,
|
2403
2399
|
mode,
|
@@ -2415,7 +2411,7 @@ async function streamObject({
|
|
2415
2411
|
headers,
|
2416
2412
|
settings: { ...settings, maxRetries }
|
2417
2413
|
});
|
2418
|
-
const tracer = getTracer(
|
2414
|
+
const tracer = getTracer(telemetry);
|
2419
2415
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
2420
2416
|
return recordSpan({
|
2421
2417
|
name: "ai.streamObject",
|
@@ -3130,7 +3126,6 @@ async function generateText({
|
|
3130
3126
|
onStepFinish,
|
3131
3127
|
...settings
|
3132
3128
|
}) {
|
3133
|
-
var _a11;
|
3134
3129
|
if (maxSteps < 1) {
|
3135
3130
|
throw new InvalidArgumentError({
|
3136
3131
|
parameter: "maxSteps",
|
@@ -3144,7 +3139,7 @@ async function generateText({
|
|
3144
3139
|
headers,
|
3145
3140
|
settings: { ...settings, maxRetries }
|
3146
3141
|
});
|
3147
|
-
const tracer = getTracer(
|
3142
|
+
const tracer = getTracer(telemetry);
|
3148
3143
|
return recordSpan({
|
3149
3144
|
name: "ai.generateText",
|
3150
3145
|
attributes: selectTelemetryAttributes({
|
@@ -3164,7 +3159,7 @@ async function generateText({
|
|
3164
3159
|
}),
|
3165
3160
|
tracer,
|
3166
3161
|
fn: async (span) => {
|
3167
|
-
var
|
3162
|
+
var _a11, _b, _c, _d, _e;
|
3168
3163
|
const retry = retryWithExponentialBackoff({ maxRetries });
|
3169
3164
|
const validatedPrompt = validatePrompt({
|
3170
3165
|
system,
|
@@ -3224,7 +3219,7 @@ async function generateText({
|
|
3224
3219
|
}),
|
3225
3220
|
tracer,
|
3226
3221
|
fn: async (span2) => {
|
3227
|
-
var
|
3222
|
+
var _a12, _b2, _c2, _d2, _e2, _f;
|
3228
3223
|
const result = await model.doGenerate({
|
3229
3224
|
mode,
|
3230
3225
|
...callSettings,
|
@@ -3235,7 +3230,7 @@ async function generateText({
|
|
3235
3230
|
headers
|
3236
3231
|
});
|
3237
3232
|
const responseData = {
|
3238
|
-
id: (_b2 = (
|
3233
|
+
id: (_b2 = (_a12 = result.response) == null ? void 0 : _a12.id) != null ? _b2 : generateId3(),
|
3239
3234
|
timestamp: (_d2 = (_c2 = result.response) == null ? void 0 : _c2.timestamp) != null ? _d2 : currentDate(),
|
3240
3235
|
modelId: (_f = (_e2 = result.response) == null ? void 0 : _e2.modelId) != null ? _f : model.modelId
|
3241
3236
|
};
|
@@ -3276,7 +3271,7 @@ async function generateText({
|
|
3276
3271
|
}
|
3277
3272
|
})
|
3278
3273
|
);
|
3279
|
-
currentToolCalls = ((
|
3274
|
+
currentToolCalls = ((_a11 = currentModelResponse.toolCalls) != null ? _a11 : []).map(
|
3280
3275
|
(modelToolCall) => parseToolCall({ toolCall: modelToolCall, tools })
|
3281
3276
|
);
|
3282
3277
|
currentToolResults = tools == null ? [] : await executeTools({
|
@@ -3859,7 +3854,6 @@ async function streamText({
|
|
3859
3854
|
} = {},
|
3860
3855
|
...settings
|
3861
3856
|
}) {
|
3862
|
-
var _a11;
|
3863
3857
|
if (maxSteps < 1) {
|
3864
3858
|
throw new InvalidArgumentError({
|
3865
3859
|
parameter: "maxSteps",
|
@@ -3873,7 +3867,7 @@ async function streamText({
|
|
3873
3867
|
headers,
|
3874
3868
|
settings: { ...settings, maxRetries }
|
3875
3869
|
});
|
3876
|
-
const tracer = getTracer(
|
3870
|
+
const tracer = getTracer(telemetry);
|
3877
3871
|
return recordSpan({
|
3878
3872
|
name: "ai.streamText",
|
3879
3873
|
attributes: selectTelemetryAttributes({
|