ai 6.0.35 → 6.0.37
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 +21 -0
- package/dist/index.js +48 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -48
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/02-foundations/02-providers-and-models.mdx +1 -0
- package/docs/02-foundations/04-tools.mdx +1 -1
- package/package.json +3 -3
- package/src/telemetry/record-span.test.ts +132 -0
- package/src/telemetry/record-span.ts +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.37
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b5dab9b: fix(ai): maintain OpenTelemetry context across async generator yields
|
|
8
|
+
|
|
9
|
+
Fixes an issue where OpenTelemetry context was lost at async generator yield boundaries, causing nested ToolLoopAgent spans to escape to the parent agent's level in observability platforms.
|
|
10
|
+
|
|
11
|
+
The fix ensures that when `recordSpan` is used with async generators (e.g., in tool execution), the active context is explicitly maintained using `context.with()`, preventing span hierarchy corruption in nested agent scenarios.
|
|
12
|
+
|
|
13
|
+
Closes #11720
|
|
14
|
+
|
|
15
|
+
## 6.0.36
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 46f46e4: fix(provider-utils): improve tool type inference when using `inputExamples` with Zod schemas that use `.optional().default()` or `.refine()`.
|
|
20
|
+
- Updated dependencies [46f46e4]
|
|
21
|
+
- @ai-sdk/provider-utils@4.0.7
|
|
22
|
+
- @ai-sdk/gateway@3.0.15
|
|
23
|
+
|
|
3
24
|
## 6.0.35
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1049,7 +1049,7 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
1049
1049
|
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1050
1050
|
|
|
1051
1051
|
// src/version.ts
|
|
1052
|
-
var VERSION = true ? "6.0.
|
|
1052
|
+
var VERSION = true ? "6.0.37" : "0.0.0-test";
|
|
1053
1053
|
|
|
1054
1054
|
// src/util/download/download.ts
|
|
1055
1055
|
var download = async ({ url }) => {
|
|
@@ -2093,8 +2093,9 @@ async function recordSpan({
|
|
|
2093
2093
|
name17,
|
|
2094
2094
|
{ attributes: await attributes },
|
|
2095
2095
|
async (span) => {
|
|
2096
|
+
const ctx = import_api2.context.active();
|
|
2096
2097
|
try {
|
|
2097
|
-
const result = await fn(span);
|
|
2098
|
+
const result = await import_api2.context.with(ctx, () => fn(span));
|
|
2098
2099
|
if (endWhenDone) {
|
|
2099
2100
|
span.end();
|
|
2100
2101
|
}
|
|
@@ -3046,16 +3047,16 @@ var object = ({
|
|
|
3046
3047
|
...name17 != null && { name: name17 },
|
|
3047
3048
|
...description != null && { description }
|
|
3048
3049
|
})),
|
|
3049
|
-
async parseCompleteOutput({ text: text2 },
|
|
3050
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3050
3051
|
const parseResult = await (0, import_provider_utils13.safeParseJSON)({ text: text2 });
|
|
3051
3052
|
if (!parseResult.success) {
|
|
3052
3053
|
throw new NoObjectGeneratedError({
|
|
3053
3054
|
message: "No object generated: could not parse the response.",
|
|
3054
3055
|
cause: parseResult.error,
|
|
3055
3056
|
text: text2,
|
|
3056
|
-
response:
|
|
3057
|
-
usage:
|
|
3058
|
-
finishReason:
|
|
3057
|
+
response: context2.response,
|
|
3058
|
+
usage: context2.usage,
|
|
3059
|
+
finishReason: context2.finishReason
|
|
3059
3060
|
});
|
|
3060
3061
|
}
|
|
3061
3062
|
const validationResult = await (0, import_provider_utils13.safeValidateTypes)({
|
|
@@ -3067,9 +3068,9 @@ var object = ({
|
|
|
3067
3068
|
message: "No object generated: response did not match schema.",
|
|
3068
3069
|
cause: validationResult.error,
|
|
3069
3070
|
text: text2,
|
|
3070
|
-
response:
|
|
3071
|
-
usage:
|
|
3072
|
-
finishReason:
|
|
3071
|
+
response: context2.response,
|
|
3072
|
+
usage: context2.usage,
|
|
3073
|
+
finishReason: context2.finishReason
|
|
3073
3074
|
});
|
|
3074
3075
|
}
|
|
3075
3076
|
return validationResult.value;
|
|
@@ -3121,16 +3122,16 @@ var array = ({
|
|
|
3121
3122
|
...description != null && { description }
|
|
3122
3123
|
};
|
|
3123
3124
|
}),
|
|
3124
|
-
async parseCompleteOutput({ text: text2 },
|
|
3125
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3125
3126
|
const parseResult = await (0, import_provider_utils13.safeParseJSON)({ text: text2 });
|
|
3126
3127
|
if (!parseResult.success) {
|
|
3127
3128
|
throw new NoObjectGeneratedError({
|
|
3128
3129
|
message: "No object generated: could not parse the response.",
|
|
3129
3130
|
cause: parseResult.error,
|
|
3130
3131
|
text: text2,
|
|
3131
|
-
response:
|
|
3132
|
-
usage:
|
|
3133
|
-
finishReason:
|
|
3132
|
+
response: context2.response,
|
|
3133
|
+
usage: context2.usage,
|
|
3134
|
+
finishReason: context2.finishReason
|
|
3134
3135
|
});
|
|
3135
3136
|
}
|
|
3136
3137
|
const outerValue = parseResult.value;
|
|
@@ -3142,9 +3143,9 @@ var array = ({
|
|
|
3142
3143
|
cause: "response must be an object with an elements array"
|
|
3143
3144
|
}),
|
|
3144
3145
|
text: text2,
|
|
3145
|
-
response:
|
|
3146
|
-
usage:
|
|
3147
|
-
finishReason:
|
|
3146
|
+
response: context2.response,
|
|
3147
|
+
usage: context2.usage,
|
|
3148
|
+
finishReason: context2.finishReason
|
|
3148
3149
|
});
|
|
3149
3150
|
}
|
|
3150
3151
|
for (const element of outerValue.elements) {
|
|
@@ -3157,9 +3158,9 @@ var array = ({
|
|
|
3157
3158
|
message: "No object generated: response did not match schema.",
|
|
3158
3159
|
cause: validationResult.error,
|
|
3159
3160
|
text: text2,
|
|
3160
|
-
response:
|
|
3161
|
-
usage:
|
|
3162
|
-
finishReason:
|
|
3161
|
+
response: context2.response,
|
|
3162
|
+
usage: context2.usage,
|
|
3163
|
+
finishReason: context2.finishReason
|
|
3163
3164
|
});
|
|
3164
3165
|
}
|
|
3165
3166
|
}
|
|
@@ -3229,16 +3230,16 @@ var choice = ({
|
|
|
3229
3230
|
...name17 != null && { name: name17 },
|
|
3230
3231
|
...description != null && { description }
|
|
3231
3232
|
}),
|
|
3232
|
-
async parseCompleteOutput({ text: text2 },
|
|
3233
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3233
3234
|
const parseResult = await (0, import_provider_utils13.safeParseJSON)({ text: text2 });
|
|
3234
3235
|
if (!parseResult.success) {
|
|
3235
3236
|
throw new NoObjectGeneratedError({
|
|
3236
3237
|
message: "No object generated: could not parse the response.",
|
|
3237
3238
|
cause: parseResult.error,
|
|
3238
3239
|
text: text2,
|
|
3239
|
-
response:
|
|
3240
|
-
usage:
|
|
3241
|
-
finishReason:
|
|
3240
|
+
response: context2.response,
|
|
3241
|
+
usage: context2.usage,
|
|
3242
|
+
finishReason: context2.finishReason
|
|
3242
3243
|
});
|
|
3243
3244
|
}
|
|
3244
3245
|
const outerValue = parseResult.value;
|
|
@@ -3250,9 +3251,9 @@ var choice = ({
|
|
|
3250
3251
|
cause: "response must be an object that contains a choice value."
|
|
3251
3252
|
}),
|
|
3252
3253
|
text: text2,
|
|
3253
|
-
response:
|
|
3254
|
-
usage:
|
|
3255
|
-
finishReason:
|
|
3254
|
+
response: context2.response,
|
|
3255
|
+
usage: context2.usage,
|
|
3256
|
+
finishReason: context2.finishReason
|
|
3256
3257
|
});
|
|
3257
3258
|
}
|
|
3258
3259
|
return outerValue.result;
|
|
@@ -3297,16 +3298,16 @@ var json = ({
|
|
|
3297
3298
|
...name17 != null && { name: name17 },
|
|
3298
3299
|
...description != null && { description }
|
|
3299
3300
|
}),
|
|
3300
|
-
async parseCompleteOutput({ text: text2 },
|
|
3301
|
+
async parseCompleteOutput({ text: text2 }, context2) {
|
|
3301
3302
|
const parseResult = await (0, import_provider_utils13.safeParseJSON)({ text: text2 });
|
|
3302
3303
|
if (!parseResult.success) {
|
|
3303
3304
|
throw new NoObjectGeneratedError({
|
|
3304
3305
|
message: "No object generated: could not parse the response.",
|
|
3305
3306
|
cause: parseResult.error,
|
|
3306
3307
|
text: text2,
|
|
3307
|
-
response:
|
|
3308
|
-
usage:
|
|
3309
|
-
finishReason:
|
|
3308
|
+
response: context2.response,
|
|
3309
|
+
usage: context2.usage,
|
|
3310
|
+
finishReason: context2.finishReason
|
|
3310
3311
|
});
|
|
3311
3312
|
}
|
|
3312
3313
|
return parseResult.value;
|
|
@@ -8853,15 +8854,15 @@ var noSchemaOutputStrategy = {
|
|
|
8853
8854
|
async validatePartialResult({ value, textDelta }) {
|
|
8854
8855
|
return { success: true, value: { partial: value, textDelta } };
|
|
8855
8856
|
},
|
|
8856
|
-
async validateFinalResult(value,
|
|
8857
|
+
async validateFinalResult(value, context2) {
|
|
8857
8858
|
return value === void 0 ? {
|
|
8858
8859
|
success: false,
|
|
8859
8860
|
error: new NoObjectGeneratedError({
|
|
8860
8861
|
message: "No object generated: response did not match schema.",
|
|
8861
|
-
text:
|
|
8862
|
-
response:
|
|
8863
|
-
usage:
|
|
8864
|
-
finishReason:
|
|
8862
|
+
text: context2.text,
|
|
8863
|
+
response: context2.response,
|
|
8864
|
+
usage: context2.usage,
|
|
8865
|
+
finishReason: context2.finishReason
|
|
8865
8866
|
})
|
|
8866
8867
|
} : { success: true, value };
|
|
8867
8868
|
},
|
|
@@ -9107,24 +9108,24 @@ function getOutputStrategy({
|
|
|
9107
9108
|
// src/generate-object/parse-and-validate-object-result.ts
|
|
9108
9109
|
var import_provider28 = require("@ai-sdk/provider");
|
|
9109
9110
|
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
9110
|
-
async function parseAndValidateObjectResult(result, outputStrategy,
|
|
9111
|
+
async function parseAndValidateObjectResult(result, outputStrategy, context2) {
|
|
9111
9112
|
const parseResult = await (0, import_provider_utils27.safeParseJSON)({ text: result });
|
|
9112
9113
|
if (!parseResult.success) {
|
|
9113
9114
|
throw new NoObjectGeneratedError({
|
|
9114
9115
|
message: "No object generated: could not parse the response.",
|
|
9115
9116
|
cause: parseResult.error,
|
|
9116
9117
|
text: result,
|
|
9117
|
-
response:
|
|
9118
|
-
usage:
|
|
9119
|
-
finishReason:
|
|
9118
|
+
response: context2.response,
|
|
9119
|
+
usage: context2.usage,
|
|
9120
|
+
finishReason: context2.finishReason
|
|
9120
9121
|
});
|
|
9121
9122
|
}
|
|
9122
9123
|
const validationResult = await outputStrategy.validateFinalResult(
|
|
9123
9124
|
parseResult.value,
|
|
9124
9125
|
{
|
|
9125
9126
|
text: result,
|
|
9126
|
-
response:
|
|
9127
|
-
usage:
|
|
9127
|
+
response: context2.response,
|
|
9128
|
+
usage: context2.usage
|
|
9128
9129
|
}
|
|
9129
9130
|
);
|
|
9130
9131
|
if (!validationResult.success) {
|
|
@@ -9132,16 +9133,16 @@ async function parseAndValidateObjectResult(result, outputStrategy, context) {
|
|
|
9132
9133
|
message: "No object generated: response did not match schema.",
|
|
9133
9134
|
cause: validationResult.error,
|
|
9134
9135
|
text: result,
|
|
9135
|
-
response:
|
|
9136
|
-
usage:
|
|
9137
|
-
finishReason:
|
|
9136
|
+
response: context2.response,
|
|
9137
|
+
usage: context2.usage,
|
|
9138
|
+
finishReason: context2.finishReason
|
|
9138
9139
|
});
|
|
9139
9140
|
}
|
|
9140
9141
|
return validationResult.value;
|
|
9141
9142
|
}
|
|
9142
|
-
async function parseAndValidateObjectResultWithRepair(result, outputStrategy, repairText,
|
|
9143
|
+
async function parseAndValidateObjectResultWithRepair(result, outputStrategy, repairText, context2) {
|
|
9143
9144
|
try {
|
|
9144
|
-
return await parseAndValidateObjectResult(result, outputStrategy,
|
|
9145
|
+
return await parseAndValidateObjectResult(result, outputStrategy, context2);
|
|
9145
9146
|
} catch (error) {
|
|
9146
9147
|
if (repairText != null && NoObjectGeneratedError.isInstance(error) && (import_provider28.JSONParseError.isInstance(error.cause) || import_provider28.TypeValidationError.isInstance(error.cause))) {
|
|
9147
9148
|
const repairedText = await repairText({
|
|
@@ -9154,7 +9155,7 @@ async function parseAndValidateObjectResultWithRepair(result, outputStrategy, re
|
|
|
9154
9155
|
return await parseAndValidateObjectResult(
|
|
9155
9156
|
repairedText,
|
|
9156
9157
|
outputStrategy,
|
|
9157
|
-
|
|
9158
|
+
context2
|
|
9158
9159
|
);
|
|
9159
9160
|
}
|
|
9160
9161
|
throw error;
|