ai 6.0.219 → 6.0.221
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 +36 -0
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +95 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -26
- 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 -1
- package/docs/03-agents/06-memory.mdx +49 -0
- package/docs/03-ai-sdk-core/40-middleware.mdx +12 -4
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +11 -2
- package/docs/06-advanced/10-vercel-deployment-guide.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +1 -1
- package/package.json +3 -3
- package/src/agent/tool-loop-agent-settings.ts +10 -0
- package/src/generate-text/generate-text.ts +6 -4
- package/src/generate-text/output.ts +4 -1
- package/src/generate-text/run-tools-transformation.ts +3 -7
- package/src/generate-text/stream-text.ts +24 -13
- package/src/generate-text/to-response-messages.ts +45 -1
- package/src/middleware/extract-json-middleware.ts +12 -3
- package/src/ui/chat.ts +1 -1
- package/src/ui/convert-to-model-messages.ts +7 -5
- package/src/ui/index.ts +1 -0
- package/src/util/set-abort-timeout.ts +37 -0
package/dist/index.mjs
CHANGED
|
@@ -1171,7 +1171,7 @@ import {
|
|
|
1171
1171
|
} from "@ai-sdk/provider-utils";
|
|
1172
1172
|
|
|
1173
1173
|
// src/version.ts
|
|
1174
|
-
var VERSION = true ? "6.0.
|
|
1174
|
+
var VERSION = true ? "6.0.221" : "0.0.0-test";
|
|
1175
1175
|
|
|
1176
1176
|
// src/util/download/download.ts
|
|
1177
1177
|
var download = async ({
|
|
@@ -2756,6 +2756,26 @@ function prepareRetries({
|
|
|
2756
2756
|
};
|
|
2757
2757
|
}
|
|
2758
2758
|
|
|
2759
|
+
// src/util/set-abort-timeout.ts
|
|
2760
|
+
function setAbortTimeout({
|
|
2761
|
+
abortController,
|
|
2762
|
+
label,
|
|
2763
|
+
timeoutMs
|
|
2764
|
+
}) {
|
|
2765
|
+
if (abortController == null || timeoutMs == null) {
|
|
2766
|
+
return void 0;
|
|
2767
|
+
}
|
|
2768
|
+
return setTimeout(
|
|
2769
|
+
() => abortController.abort(
|
|
2770
|
+
new DOMException(
|
|
2771
|
+
`${label} timeout of ${timeoutMs}ms exceeded`,
|
|
2772
|
+
"TimeoutError"
|
|
2773
|
+
)
|
|
2774
|
+
),
|
|
2775
|
+
timeoutMs
|
|
2776
|
+
);
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2759
2779
|
// src/generate-text/collect-tool-approvals.ts
|
|
2760
2780
|
function collectToolApprovals({
|
|
2761
2781
|
messages
|
|
@@ -3724,6 +3744,7 @@ var array = ({
|
|
|
3724
3744
|
finishReason: context2.finishReason
|
|
3725
3745
|
});
|
|
3726
3746
|
}
|
|
3747
|
+
const validatedElements = [];
|
|
3727
3748
|
for (const element of outerValue.elements) {
|
|
3728
3749
|
const validationResult = await safeValidateTypes3({
|
|
3729
3750
|
value: element,
|
|
@@ -3739,8 +3760,9 @@ var array = ({
|
|
|
3739
3760
|
finishReason: context2.finishReason
|
|
3740
3761
|
});
|
|
3741
3762
|
}
|
|
3763
|
+
validatedElements.push(validationResult.value);
|
|
3742
3764
|
}
|
|
3743
|
-
return
|
|
3765
|
+
return validatedElements;
|
|
3744
3766
|
},
|
|
3745
3767
|
async parsePartialOutput({ text: text2 }) {
|
|
3746
3768
|
const result = await parsePartialJson(text2);
|
|
@@ -4143,6 +4165,7 @@ async function toResponseMessages({
|
|
|
4143
4165
|
tools
|
|
4144
4166
|
}) {
|
|
4145
4167
|
const responseMessages = [];
|
|
4168
|
+
const toolCallOrder = /* @__PURE__ */ new Map();
|
|
4146
4169
|
const content = [];
|
|
4147
4170
|
for (const part of inputContent) {
|
|
4148
4171
|
if (part.type === "source") {
|
|
@@ -4178,6 +4201,9 @@ async function toResponseMessages({
|
|
|
4178
4201
|
});
|
|
4179
4202
|
break;
|
|
4180
4203
|
case "tool-call":
|
|
4204
|
+
if (!toolCallOrder.has(part.toolCallId)) {
|
|
4205
|
+
toolCallOrder.set(part.toolCallId, toolCallOrder.size);
|
|
4206
|
+
}
|
|
4181
4207
|
content.push({
|
|
4182
4208
|
type: "tool-call",
|
|
4183
4209
|
toolCallId: part.toolCallId,
|
|
@@ -4260,11 +4286,37 @@ async function toResponseMessages({
|
|
|
4260
4286
|
if (toolResultContent.length > 0) {
|
|
4261
4287
|
responseMessages.push({
|
|
4262
4288
|
role: "tool",
|
|
4263
|
-
content:
|
|
4289
|
+
content: sortToolResultContentByToolCallOrder({
|
|
4290
|
+
toolResultContent,
|
|
4291
|
+
toolCallOrder
|
|
4292
|
+
})
|
|
4264
4293
|
});
|
|
4265
4294
|
}
|
|
4266
4295
|
return responseMessages;
|
|
4267
4296
|
}
|
|
4297
|
+
function sortToolResultContentByToolCallOrder({
|
|
4298
|
+
toolResultContent,
|
|
4299
|
+
toolCallOrder
|
|
4300
|
+
}) {
|
|
4301
|
+
const sortedToolResults = toolResultContent.filter((part) => part.type === "tool-result").map((part, index) => ({ part, index })).sort((a, b) => {
|
|
4302
|
+
const aOrder = toolCallOrder.get(a.part.toolCallId);
|
|
4303
|
+
const bOrder = toolCallOrder.get(b.part.toolCallId);
|
|
4304
|
+
if (aOrder == null && bOrder == null) {
|
|
4305
|
+
return a.index - b.index;
|
|
4306
|
+
}
|
|
4307
|
+
if (aOrder == null) {
|
|
4308
|
+
return 1;
|
|
4309
|
+
}
|
|
4310
|
+
if (bOrder == null) {
|
|
4311
|
+
return -1;
|
|
4312
|
+
}
|
|
4313
|
+
return aOrder - bOrder || a.index - b.index;
|
|
4314
|
+
}).map(({ part }) => part);
|
|
4315
|
+
let toolResultIndex = 0;
|
|
4316
|
+
return toolResultContent.map(
|
|
4317
|
+
(part) => part.type === "tool-result" ? sortedToolResults[toolResultIndex++] : part
|
|
4318
|
+
);
|
|
4319
|
+
}
|
|
4268
4320
|
|
|
4269
4321
|
// src/util/merge-abort-signals.ts
|
|
4270
4322
|
function mergeAbortSignals(...signals) {
|
|
@@ -4517,7 +4569,11 @@ async function generateText({
|
|
|
4517
4569
|
const steps = [];
|
|
4518
4570
|
const pendingDeferredToolCalls = /* @__PURE__ */ new Map();
|
|
4519
4571
|
do {
|
|
4520
|
-
const stepTimeoutId =
|
|
4572
|
+
const stepTimeoutId = setAbortTimeout({
|
|
4573
|
+
abortController: stepAbortController,
|
|
4574
|
+
label: "Step",
|
|
4575
|
+
timeoutMs: stepTimeoutMs
|
|
4576
|
+
});
|
|
4521
4577
|
try {
|
|
4522
4578
|
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
4523
4579
|
const prepareStepResult = await (prepareStep == null ? void 0 : prepareStep({
|
|
@@ -6489,7 +6545,6 @@ function runToolsTransformation({
|
|
|
6489
6545
|
}
|
|
6490
6546
|
});
|
|
6491
6547
|
const outstandingToolResults = /* @__PURE__ */ new Set();
|
|
6492
|
-
const toolInputs = /* @__PURE__ */ new Map();
|
|
6493
6548
|
const toolCallsByToolCallId = /* @__PURE__ */ new Map();
|
|
6494
6549
|
let canClose = false;
|
|
6495
6550
|
let finishChunk = void 0;
|
|
@@ -6621,7 +6676,6 @@ function runToolsTransformation({
|
|
|
6621
6676
|
});
|
|
6622
6677
|
break;
|
|
6623
6678
|
}
|
|
6624
|
-
toolInputs.set(toolCall.toolCallId, toolCall.input);
|
|
6625
6679
|
if (tool2.execute != null && toolCall.providerExecuted !== true) {
|
|
6626
6680
|
const toolExecutionId = generateId2();
|
|
6627
6681
|
outstandingToolResults.add(toolExecutionId);
|
|
@@ -6665,7 +6719,7 @@ function runToolsTransformation({
|
|
|
6665
6719
|
type: "tool-error",
|
|
6666
6720
|
toolCallId: chunk.toolCallId,
|
|
6667
6721
|
toolName,
|
|
6668
|
-
input:
|
|
6722
|
+
input: toolCall == null ? void 0 : toolCall.input,
|
|
6669
6723
|
providerExecuted: true,
|
|
6670
6724
|
error: chunk.result,
|
|
6671
6725
|
dynamic: chunk.dynamic,
|
|
@@ -6677,7 +6731,7 @@ function runToolsTransformation({
|
|
|
6677
6731
|
type: "tool-result",
|
|
6678
6732
|
toolCallId: chunk.toolCallId,
|
|
6679
6733
|
toolName,
|
|
6680
|
-
input:
|
|
6734
|
+
input: toolCall == null ? void 0 : toolCall.input,
|
|
6681
6735
|
output: chunk.result,
|
|
6682
6736
|
providerExecuted: true,
|
|
6683
6737
|
dynamic: chunk.dynamic,
|
|
@@ -7477,18 +7531,21 @@ var DefaultStreamTextResult = class {
|
|
|
7477
7531
|
}) {
|
|
7478
7532
|
var _a22, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
7479
7533
|
const includeRawChunks2 = self.includeRawChunks;
|
|
7480
|
-
const stepTimeoutId =
|
|
7534
|
+
const stepTimeoutId = setAbortTimeout({
|
|
7535
|
+
abortController: stepAbortController,
|
|
7536
|
+
label: "Step",
|
|
7537
|
+
timeoutMs: stepTimeoutMs
|
|
7538
|
+
});
|
|
7481
7539
|
let chunkTimeoutId = void 0;
|
|
7482
7540
|
function resetChunkTimeout() {
|
|
7483
|
-
if (
|
|
7484
|
-
|
|
7485
|
-
clearTimeout(chunkTimeoutId);
|
|
7486
|
-
}
|
|
7487
|
-
chunkTimeoutId = setTimeout(
|
|
7488
|
-
() => chunkAbortController.abort(),
|
|
7489
|
-
chunkTimeoutMs
|
|
7490
|
-
);
|
|
7541
|
+
if (chunkTimeoutId != null) {
|
|
7542
|
+
clearTimeout(chunkTimeoutId);
|
|
7491
7543
|
}
|
|
7544
|
+
chunkTimeoutId = setAbortTimeout({
|
|
7545
|
+
abortController: chunkAbortController,
|
|
7546
|
+
label: "Chunk",
|
|
7547
|
+
timeoutMs: chunkTimeoutMs
|
|
7548
|
+
});
|
|
7492
7549
|
}
|
|
7493
7550
|
function clearChunkTimeout() {
|
|
7494
7551
|
if (chunkTimeoutId != null) {
|
|
@@ -7501,6 +7558,8 @@ var DefaultStreamTextResult = class {
|
|
|
7501
7558
|
clearTimeout(stepTimeoutId);
|
|
7502
7559
|
}
|
|
7503
7560
|
}
|
|
7561
|
+
abortSignal == null ? void 0 : abortSignal.addEventListener("abort", clearStepTimeout);
|
|
7562
|
+
abortSignal == null ? void 0 : abortSignal.addEventListener("abort", clearChunkTimeout);
|
|
7504
7563
|
try {
|
|
7505
7564
|
stepFinish = new DelayedPromise();
|
|
7506
7565
|
const stepInputMessages = [...initialMessages, ...responseMessages];
|
|
@@ -7996,9 +8055,10 @@ var DefaultStreamTextResult = class {
|
|
|
7996
8055
|
})
|
|
7997
8056
|
)
|
|
7998
8057
|
);
|
|
7999
|
-
}
|
|
8058
|
+
} catch (error) {
|
|
8000
8059
|
clearStepTimeout();
|
|
8001
8060
|
clearChunkTimeout();
|
|
8061
|
+
throw error;
|
|
8002
8062
|
}
|
|
8003
8063
|
}
|
|
8004
8064
|
await streamStep({
|
|
@@ -8920,10 +8980,12 @@ async function convertToModelMessages(messages, options) {
|
|
|
8920
8980
|
throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
|
|
8921
8981
|
}
|
|
8922
8982
|
}
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8983
|
+
if (content.length > 0) {
|
|
8984
|
+
modelMessages.push({
|
|
8985
|
+
role: "assistant",
|
|
8986
|
+
content
|
|
8987
|
+
});
|
|
8988
|
+
}
|
|
8927
8989
|
const toolParts = block.filter(
|
|
8928
8990
|
(part) => {
|
|
8929
8991
|
var _a23;
|
|
@@ -8954,7 +9016,7 @@ async function convertToModelMessages(messages, options) {
|
|
|
8954
9016
|
toolName: getToolName(toolPart),
|
|
8955
9017
|
output: {
|
|
8956
9018
|
type: "error-text",
|
|
8957
|
-
value: (_g = (_f = toolPart.approval) == null ? void 0 : _f.reason) != null ? _g : "Tool execution denied."
|
|
9019
|
+
value: (_g = (_f = toolPart.approval) == null ? void 0 : _f.reason) != null ? _g : "Tool call execution denied."
|
|
8958
9020
|
},
|
|
8959
9021
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
8960
9022
|
});
|
|
@@ -12060,6 +12122,9 @@ function defaultSettingsMiddleware({
|
|
|
12060
12122
|
function defaultTransform(text2) {
|
|
12061
12123
|
return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
|
|
12062
12124
|
}
|
|
12125
|
+
function stripMarkdownCodeFenceSuffix(text2) {
|
|
12126
|
+
return text2.replace(/\n?```\s*$/, "").trimEnd();
|
|
12127
|
+
}
|
|
12063
12128
|
function extractJsonMiddleware(options) {
|
|
12064
12129
|
var _a22;
|
|
12065
12130
|
const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
|
|
@@ -12154,9 +12219,11 @@ function extractJsonMiddleware(options) {
|
|
|
12154
12219
|
if (block.phase === "buffering") {
|
|
12155
12220
|
remaining = transform(remaining);
|
|
12156
12221
|
} else if (block.prefixStripped) {
|
|
12157
|
-
remaining = remaining
|
|
12158
|
-
} else {
|
|
12222
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
12223
|
+
} else if (block.phase === "prefix") {
|
|
12159
12224
|
remaining = transform(remaining);
|
|
12225
|
+
} else {
|
|
12226
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
12160
12227
|
}
|
|
12161
12228
|
if (remaining.length > 0) {
|
|
12162
12229
|
controller.enqueue({
|
|
@@ -13564,7 +13631,7 @@ var AbstractChat = class {
|
|
|
13564
13631
|
const updatePart = (part) => isToolUIPart(part) && part.state === "approval-requested" && part.approval.id === id ? {
|
|
13565
13632
|
...part,
|
|
13566
13633
|
state: "approval-responded",
|
|
13567
|
-
approval: { id, approved, reason }
|
|
13634
|
+
approval: { ...part.approval, id, approved, reason }
|
|
13568
13635
|
} : part;
|
|
13569
13636
|
this.state.replaceMessage(messages.length - 1, {
|
|
13570
13637
|
...lastMessage,
|
|
@@ -14035,6 +14102,7 @@ export {
|
|
|
14035
14102
|
hasToolCall,
|
|
14036
14103
|
isDataUIPart,
|
|
14037
14104
|
isDeepEqualData,
|
|
14105
|
+
isDynamicToolUIPart,
|
|
14038
14106
|
isFileUIPart,
|
|
14039
14107
|
isLoopFinished,
|
|
14040
14108
|
isReasoningUIPart,
|