ai 7.0.179 → 7.0.181
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 +18 -0
- package/dist/{default-stop-condition-wtuJTiTo.js → default-stop-condition-D8PwkeWe.js} +52 -27
- package/dist/default-stop-condition-D8PwkeWe.js.map +1 -0
- package/dist/{index-CM_8u8gB.d.ts → index-CKEJqCzY.d.ts} +69 -4
- package/dist/index-CKEJqCzY.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +192 -119
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +8 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-agents/04-loop-control.mdx +35 -1
- package/docs/03-agents/06-policy-tool-approvals.mdx +5 -2
- package/docs/03-agents/08-terminal-ui.mdx +10 -0
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +59 -0
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +6 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +21 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +19 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +25 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/25-create-mcp-tools.mdx +65 -0
- package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +3 -0
- package/package.json +4 -4
- package/src/agent/default-stop-condition.ts +12 -3
- package/src/agent/tool-loop-agent-settings.ts +11 -0
- package/src/agent/tool-loop-agent.ts +3 -1
- package/src/extract/restricted-telemetry-dispatcher.ts +9 -5
- package/src/generate-text/default-generate-text-result.ts +4 -0
- package/src/generate-text/generate-text-events.ts +7 -0
- package/src/generate-text/generate-text-result.ts +9 -0
- package/src/generate-text/generate-text.ts +37 -5
- package/src/generate-text/index.ts +1 -0
- package/src/generate-text/steering.ts +19 -5
- package/src/generate-text/stopped-by.ts +43 -0
- package/src/generate-text/stream-language-model-call.ts +21 -2
- package/src/generate-text/stream-text-result.ts +18 -0
- package/src/generate-text/stream-text.ts +59 -6
- package/src/logger/create-log-warnings.ts +17 -0
- package/src/model/as-language-model-v3.ts +3 -0
- package/src/model/as-language-model-v4.ts +5 -1
- package/src/model/resolve-model.ts +8 -3
- package/src/prompt/convert-to-language-model-prompt.ts +15 -6
- package/src/util/log-v2-compatibility-warning.ts +5 -2
- package/dist/default-stop-condition-wtuJTiTo.js.map +0 -1
- package/dist/index-CM_8u8gB.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 7.0.181
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d834c5b: add per-call `onWarning` callback and include prompt conversion warnings in the step warnings
|
|
8
|
+
- 7760e33: add stoppedBy to generateText and streamText results, onEnd, and the finish part to tell why the tool loop stopped
|
|
9
|
+
- 28d17e6: report why the run ended for steering messages sent after it, and count steering messages as delivered when prepareStep turns their text into parts or adds provider options
|
|
10
|
+
- 797dc02: Strip provider options from text and file parts in extraction telemetry while preserving arbitrary JSON state and the options sent to the provider.
|
|
11
|
+
- Updated dependencies [f2732a6]
|
|
12
|
+
- @ai-sdk/gateway@4.0.154
|
|
13
|
+
|
|
14
|
+
## 7.0.180
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [83026e8]
|
|
19
|
+
- @ai-sdk/gateway@4.0.153
|
|
20
|
+
|
|
3
21
|
## 7.0.179
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -246,6 +246,19 @@ var RetryError = class extends AISDKError {
|
|
|
246
246
|
}
|
|
247
247
|
};
|
|
248
248
|
//#endregion
|
|
249
|
+
//#region src/util/notify.ts
|
|
250
|
+
/**
|
|
251
|
+
* Notifies all provided callbacks with the given event in parallel.
|
|
252
|
+
* Errors in callbacks do not break the generation flow.
|
|
253
|
+
*/
|
|
254
|
+
async function notify(options) {
|
|
255
|
+
await Promise.all(asArray(options.callbacks).map(async (callback) => {
|
|
256
|
+
try {
|
|
257
|
+
await callback?.(options.event);
|
|
258
|
+
} catch {}
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
249
262
|
//#region src/logger/deprecations.ts
|
|
250
263
|
const deprecationCodes = /* @__PURE__ */ new Map([
|
|
251
264
|
["generateObject", "AISDK_DEP_GENERATE_OBJECT"],
|
|
@@ -364,9 +377,20 @@ const logWarnings = (options) => {
|
|
|
364
377
|
}
|
|
365
378
|
};
|
|
366
379
|
//#endregion
|
|
380
|
+
//#region src/logger/create-log-warnings.ts
|
|
381
|
+
function createLogWarnings(onWarning) {
|
|
382
|
+
if (onWarning == null) return logWarnings;
|
|
383
|
+
return (options) => {
|
|
384
|
+
if (options.warnings.length > 0) notify({
|
|
385
|
+
event: options,
|
|
386
|
+
callbacks: onWarning
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
367
391
|
//#region src/util/log-v2-compatibility-warning.ts
|
|
368
|
-
function logV2CompatibilityWarning({ provider, modelId }) {
|
|
369
|
-
|
|
392
|
+
function logV2CompatibilityWarning({ provider, modelId, onWarning }) {
|
|
393
|
+
createLogWarnings(onWarning)({
|
|
370
394
|
warnings: [{
|
|
371
395
|
type: "compatibility",
|
|
372
396
|
feature: "specificationVersion",
|
|
@@ -424,11 +448,12 @@ function asImageModelV4(model) {
|
|
|
424
448
|
}
|
|
425
449
|
//#endregion
|
|
426
450
|
//#region src/model/as-language-model-v3.ts
|
|
427
|
-
function asLanguageModelV3(model) {
|
|
451
|
+
function asLanguageModelV3(model, onWarning) {
|
|
428
452
|
if (model.specificationVersion === "v3") return model;
|
|
429
453
|
logV2CompatibilityWarning({
|
|
430
454
|
provider: model.provider,
|
|
431
|
-
modelId: model.modelId
|
|
455
|
+
modelId: model.modelId,
|
|
456
|
+
onWarning
|
|
432
457
|
});
|
|
433
458
|
return new Proxy(model, { get(target, prop) {
|
|
434
459
|
switch (prop) {
|
|
@@ -490,9 +515,9 @@ function convertV2UsageToV3(usage) {
|
|
|
490
515
|
}
|
|
491
516
|
//#endregion
|
|
492
517
|
//#region src/model/as-language-model-v4.ts
|
|
493
|
-
function asLanguageModelV4(model) {
|
|
518
|
+
function asLanguageModelV4(model, onWarning) {
|
|
494
519
|
if (model.specificationVersion === "v4") return model;
|
|
495
|
-
const v3Model = model.specificationVersion === "v2" ? asLanguageModelV3(model) : model;
|
|
520
|
+
const v3Model = model.specificationVersion === "v2" ? asLanguageModelV3(model, onWarning) : model;
|
|
496
521
|
return new Proxy(v3Model, { get(target, prop) {
|
|
497
522
|
switch (prop) {
|
|
498
523
|
case "specificationVersion": return "v4";
|
|
@@ -706,8 +731,8 @@ function asProviderV4(provider) {
|
|
|
706
731
|
}
|
|
707
732
|
//#endregion
|
|
708
733
|
//#region src/model/resolve-model.ts
|
|
709
|
-
function resolveLanguageModel(model) {
|
|
710
|
-
if (typeof model === "string") return
|
|
734
|
+
function resolveLanguageModel(model, onWarning) {
|
|
735
|
+
if (typeof model === "string") return asLanguageModelV4((globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway).languageModel(model), onWarning);
|
|
711
736
|
if (![
|
|
712
737
|
"v4",
|
|
713
738
|
"v3",
|
|
@@ -720,7 +745,7 @@ function resolveLanguageModel(model) {
|
|
|
720
745
|
modelId: unsupportedModel.modelId
|
|
721
746
|
});
|
|
722
747
|
}
|
|
723
|
-
return asLanguageModelV4(model);
|
|
748
|
+
return asLanguageModelV4(model, onWarning);
|
|
724
749
|
}
|
|
725
750
|
function resolveEmbeddingModel(model) {
|
|
726
751
|
if (typeof model === "string") return getGlobalProvider().embeddingModel(model);
|
|
@@ -905,7 +930,7 @@ function asEvaluationModel(model) {
|
|
|
905
930
|
}
|
|
906
931
|
//#endregion
|
|
907
932
|
//#region src/version.ts
|
|
908
|
-
const VERSION = "7.0.
|
|
933
|
+
const VERSION = "7.0.181";
|
|
909
934
|
//#endregion
|
|
910
935
|
//#region src/util/download/download.ts
|
|
911
936
|
/**
|
|
@@ -1157,7 +1182,7 @@ function convertToLanguageModelV4FilePart(content) {
|
|
|
1157
1182
|
}
|
|
1158
1183
|
//#endregion
|
|
1159
1184
|
//#region src/prompt/convert-to-language-model-prompt.ts
|
|
1160
|
-
async function convertToLanguageModelPrompt({ prompt, supportedUrls, download, abortSignal, provider }) {
|
|
1185
|
+
async function convertToLanguageModelPrompt({ prompt, supportedUrls, download, abortSignal, provider, warnings }) {
|
|
1161
1186
|
const downloadedAssets = await downloadAssets(prompt.messages, download ?? createDefaultDownloadFunction(void 0, abortSignal), supportedUrls, abortSignal);
|
|
1162
1187
|
const messages = [...prompt.instructions != null ? typeof prompt.instructions === "string" ? [{
|
|
1163
1188
|
role: "system",
|
|
@@ -1169,7 +1194,8 @@ async function convertToLanguageModelPrompt({ prompt, supportedUrls, download, a
|
|
|
1169
1194
|
})) : [], ...prompt.messages.map((message) => convertToLanguageModelMessage({
|
|
1170
1195
|
message,
|
|
1171
1196
|
downloadedAssets,
|
|
1172
|
-
provider
|
|
1197
|
+
provider,
|
|
1198
|
+
warnings
|
|
1173
1199
|
}))];
|
|
1174
1200
|
const combinedMessages = [];
|
|
1175
1201
|
for (const message of messages) {
|
|
@@ -1206,8 +1232,8 @@ async function convertToLanguageModelPrompt({ prompt, supportedUrls, download, a
|
|
|
1206
1232
|
* @param downloadedAssets - A map of URLs to their downloaded data. Only
|
|
1207
1233
|
* available if the model does not support URLs, null otherwise.
|
|
1208
1234
|
*/
|
|
1209
|
-
function convertToLanguageModelMessage({ message, downloadedAssets, provider }) {
|
|
1210
|
-
const warnings = [];
|
|
1235
|
+
function convertToLanguageModelMessage({ message, downloadedAssets, provider, warnings: collectedWarnings }) {
|
|
1236
|
+
const warnings = collectedWarnings ?? [];
|
|
1211
1237
|
const role = message.role;
|
|
1212
1238
|
switch (role) {
|
|
1213
1239
|
case "system": return {
|
|
@@ -1236,7 +1262,7 @@ function convertToLanguageModelMessage({ message, downloadedAssets, provider })
|
|
|
1236
1262
|
}).map((part) => convertPartToLanguageModelPart(part, downloadedAssets)).filter((part) => part.type !== "text" || part.text !== ""),
|
|
1237
1263
|
providerOptions: message.providerOptions
|
|
1238
1264
|
};
|
|
1239
|
-
if (warnings.length > 0) logWarnings({ warnings });
|
|
1265
|
+
if (collectedWarnings == null && warnings.length > 0) logWarnings({ warnings });
|
|
1240
1266
|
return converted;
|
|
1241
1267
|
}
|
|
1242
1268
|
case "assistant": {
|
|
@@ -1312,7 +1338,7 @@ function convertToLanguageModelMessage({ message, downloadedAssets, provider })
|
|
|
1312
1338
|
}),
|
|
1313
1339
|
providerOptions: message.providerOptions
|
|
1314
1340
|
};
|
|
1315
|
-
if (warnings.length > 0) logWarnings({ warnings });
|
|
1341
|
+
if (collectedWarnings == null && warnings.length > 0) logWarnings({ warnings });
|
|
1316
1342
|
return converted;
|
|
1317
1343
|
}
|
|
1318
1344
|
case "tool": {
|
|
@@ -1342,7 +1368,7 @@ function convertToLanguageModelMessage({ message, downloadedAssets, provider })
|
|
|
1342
1368
|
}),
|
|
1343
1369
|
providerOptions: message.providerOptions
|
|
1344
1370
|
};
|
|
1345
|
-
if (warnings.length > 0) logWarnings({ warnings });
|
|
1371
|
+
if (collectedWarnings == null && warnings.length > 0) logWarnings({ warnings });
|
|
1346
1372
|
return converted;
|
|
1347
1373
|
}
|
|
1348
1374
|
default: throw new InvalidMessageRoleError({ role });
|
|
@@ -1531,10 +1557,7 @@ function mapToolResultOutput({ output, provider, warnings = [], downloadedAssets
|
|
|
1531
1557
|
const mediaType = item.mediaType ?? getMediaTypeFromUrl(item.url);
|
|
1532
1558
|
const url = new URL(item.url);
|
|
1533
1559
|
let message = `The "file-url" type for tool result content is deprecated. Use the "file" type with mediaType and { type: 'url', url } instead.`;
|
|
1534
|
-
if (!item.mediaType) {
|
|
1535
|
-
const inferenceSuffix = mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`;
|
|
1536
|
-
message = `The "file-url" tool result content part with URL "${item.url}" is missing a "mediaType". ${inferenceSuffix} ${message}`;
|
|
1537
|
-
}
|
|
1560
|
+
if (!item.mediaType) message = `A "file-url" tool result content part is missing a "mediaType". ${mediaType === "application/octet-stream" ? `Unable to infer media type from URL. Defaulting to 'application/octet-stream'.` : `Inferred media type '${mediaType}' from URL.`} ${message}`;
|
|
1538
1561
|
warnings.push({
|
|
1539
1562
|
type: "deprecated",
|
|
1540
1563
|
setting: "\"tool-result\" content of type \"file-url\"",
|
|
@@ -2580,6 +2603,7 @@ var DefaultGenerateTextResult = class {
|
|
|
2580
2603
|
this.steps = options.steps;
|
|
2581
2604
|
this._output = options.output;
|
|
2582
2605
|
this.totalUsage = options.totalUsage;
|
|
2606
|
+
this.stoppedBy = options.stoppedBy;
|
|
2583
2607
|
}
|
|
2584
2608
|
get finalStep() {
|
|
2585
2609
|
return this.steps.at(-1);
|
|
@@ -4181,8 +4205,8 @@ function isOutputChunk(chunk) {
|
|
|
4181
4205
|
/**
|
|
4182
4206
|
* Logs the warning for the default stopWhen condition.
|
|
4183
4207
|
*/
|
|
4184
|
-
function logDefaultStopConditionWarning({ stepCount, provider, modelId }) {
|
|
4185
|
-
|
|
4208
|
+
function logDefaultStopConditionWarning({ stepCount, provider, modelId, onWarning }) {
|
|
4209
|
+
createLogWarnings(onWarning)({
|
|
4186
4210
|
provider,
|
|
4187
4211
|
model: modelId,
|
|
4188
4212
|
warnings: [{
|
|
@@ -4195,19 +4219,20 @@ function logDefaultStopConditionWarning({ stepCount, provider, modelId }) {
|
|
|
4195
4219
|
* Stop conditions are only evaluated when the tool loop can otherwise continue,
|
|
4196
4220
|
* so logging here avoids warning when a call finishes naturally at the limit.
|
|
4197
4221
|
*/
|
|
4198
|
-
function createDefaultStopCondition(stepCount) {
|
|
4222
|
+
function createDefaultStopCondition(stepCount, onWarning) {
|
|
4199
4223
|
return ({ steps }) => {
|
|
4200
4224
|
if (steps.length !== stepCount) return false;
|
|
4201
4225
|
const { provider, modelId } = steps[steps.length - 1].model;
|
|
4202
4226
|
logDefaultStopConditionWarning({
|
|
4203
4227
|
stepCount,
|
|
4204
4228
|
provider,
|
|
4205
|
-
modelId
|
|
4229
|
+
modelId,
|
|
4230
|
+
onWarning
|
|
4206
4231
|
});
|
|
4207
4232
|
return true;
|
|
4208
4233
|
};
|
|
4209
4234
|
}
|
|
4210
4235
|
//#endregion
|
|
4211
|
-
export { convertToLanguageModelPrompt as $, toolSearch as A,
|
|
4236
|
+
export { convertToLanguageModelPrompt as $, toolSearch as A, InvalidMessageRoleError as At, setAbortTimeout as B, InvalidToolApprovalError as Bt, resolveToolApproval as C, asLanguageModelV4 as Ct, convertToReasoningOutputs as D, logWarnings as Dt, DefaultGenerateTextResult as E, createLogWarnings as Et, resolveGeneratedFileData as F, NoOutputGeneratedError as Ft, addLanguageModelUsage as G, mergeAbortSignals as H, DefaultGeneratedFile as I, MissingToolResultsError as It, standardizePrompt as J, asLanguageModelUsage as K, DefaultGeneratedFileWithType as L, ToolCallNotFoundForApprovalError as Lt, prepareToolsForToolCallers as M, UnsupportedModelVersionError as Mt, resolveToolCallerConfiguration as N, ToolCallRepairError as Nt, validateToolContext as O, notify as Ot, convertLanguageModelContent as P, NoSuchToolError as Pt, createToolModelOutput as Q, collectToolApprovals as R, InvalidToolInputError as Rt, filterIncludedContext as S, asVideoModelV4 as St, getToolCallInputSchemaInput as T, asEmbeddingModelV4 as Tt, getOwn as U, prepareRetries as V, InvalidArgumentError as Vt, addImageModelUsage as W, prepareToolChoice as X, prepareTools as Y, prepareLanguageModelCallOptions as Z, createTelemetryDispatcher as _, resolveSpeechModel as _t, createAsyncIterableStream as a, convertDataContentToUint8Array as at, AI_SDK_TELEMETRY_TRACING_CHANNEL as b, resolveVideoModel as bt, validateApprovedToolApprovals as c, download as ct, verifyToolApprovalSignature as d, resolveDecisionModel as dt, downloadAssets as et, hashCanonical as f, resolveEmbeddingModel as ft, DefaultStepResult as g, resolveRerankingModel as gt, createRestrictedTelemetryDispatcher as h, resolveLanguageModel as ht, asAsyncIterableStream as i, convertDataContentToBase64String as it, appendToolCallerMessages as j, InvalidDataContentError as jt, createToolSearchState as k, RetryError as kt, maybeSignApproval as l, VERSION as lt, isDeepEqualData as m, resolveImageModel as mt, logDefaultStopConditionWarning as n, convertToLanguageModelV4FilePart as nt, mapWithConcurrency as o, mergeObjects as ot, toResponseMessages as p, resolveExtractionModel as pt, createNullLanguageModelUsage as q, isOutputChunk as r, splitDataUrl as rt, prepareToolCallConcurrency as s, createDefaultDownloadFunction as st, createDefaultStopCondition as t, mapToolResultOutput as tt, signToolApproval as u, asEvaluationModel as ut, getGlobalTelemetryIntegrations as v, resolveSpeechTranslationModel as vt, parseToolCall as w, asImageModelV4 as wt, mergeCallbacks as x, asProviderV4 as xt, registerTelemetry as y, resolveTranscriptionModel as yt, calculateTokensPerSecond as z, InvalidToolApprovalSignatureError as zt };
|
|
4212
4237
|
|
|
4213
|
-
//# sourceMappingURL=default-stop-condition-
|
|
4238
|
+
//# sourceMappingURL=default-stop-condition-D8PwkeWe.js.map
|