ai 6.0.219 → 6.0.220
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 +12 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +39 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -4
- 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/to-response-messages.ts +45 -1
- package/src/middleware/extract-json-middleware.ts +12 -3
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.220" : "0.0.0-test";
|
|
1175
1175
|
|
|
1176
1176
|
// src/util/download/download.ts
|
|
1177
1177
|
var download = async ({
|
|
@@ -4143,6 +4143,7 @@ async function toResponseMessages({
|
|
|
4143
4143
|
tools
|
|
4144
4144
|
}) {
|
|
4145
4145
|
const responseMessages = [];
|
|
4146
|
+
const toolCallOrder = /* @__PURE__ */ new Map();
|
|
4146
4147
|
const content = [];
|
|
4147
4148
|
for (const part of inputContent) {
|
|
4148
4149
|
if (part.type === "source") {
|
|
@@ -4178,6 +4179,9 @@ async function toResponseMessages({
|
|
|
4178
4179
|
});
|
|
4179
4180
|
break;
|
|
4180
4181
|
case "tool-call":
|
|
4182
|
+
if (!toolCallOrder.has(part.toolCallId)) {
|
|
4183
|
+
toolCallOrder.set(part.toolCallId, toolCallOrder.size);
|
|
4184
|
+
}
|
|
4181
4185
|
content.push({
|
|
4182
4186
|
type: "tool-call",
|
|
4183
4187
|
toolCallId: part.toolCallId,
|
|
@@ -4260,11 +4264,37 @@ async function toResponseMessages({
|
|
|
4260
4264
|
if (toolResultContent.length > 0) {
|
|
4261
4265
|
responseMessages.push({
|
|
4262
4266
|
role: "tool",
|
|
4263
|
-
content:
|
|
4267
|
+
content: sortToolResultContentByToolCallOrder({
|
|
4268
|
+
toolResultContent,
|
|
4269
|
+
toolCallOrder
|
|
4270
|
+
})
|
|
4264
4271
|
});
|
|
4265
4272
|
}
|
|
4266
4273
|
return responseMessages;
|
|
4267
4274
|
}
|
|
4275
|
+
function sortToolResultContentByToolCallOrder({
|
|
4276
|
+
toolResultContent,
|
|
4277
|
+
toolCallOrder
|
|
4278
|
+
}) {
|
|
4279
|
+
const sortedToolResults = toolResultContent.filter((part) => part.type === "tool-result").map((part, index) => ({ part, index })).sort((a, b) => {
|
|
4280
|
+
const aOrder = toolCallOrder.get(a.part.toolCallId);
|
|
4281
|
+
const bOrder = toolCallOrder.get(b.part.toolCallId);
|
|
4282
|
+
if (aOrder == null && bOrder == null) {
|
|
4283
|
+
return a.index - b.index;
|
|
4284
|
+
}
|
|
4285
|
+
if (aOrder == null) {
|
|
4286
|
+
return 1;
|
|
4287
|
+
}
|
|
4288
|
+
if (bOrder == null) {
|
|
4289
|
+
return -1;
|
|
4290
|
+
}
|
|
4291
|
+
return aOrder - bOrder || a.index - b.index;
|
|
4292
|
+
}).map(({ part }) => part);
|
|
4293
|
+
let toolResultIndex = 0;
|
|
4294
|
+
return toolResultContent.map(
|
|
4295
|
+
(part) => part.type === "tool-result" ? sortedToolResults[toolResultIndex++] : part
|
|
4296
|
+
);
|
|
4297
|
+
}
|
|
4268
4298
|
|
|
4269
4299
|
// src/util/merge-abort-signals.ts
|
|
4270
4300
|
function mergeAbortSignals(...signals) {
|
|
@@ -12060,6 +12090,9 @@ function defaultSettingsMiddleware({
|
|
|
12060
12090
|
function defaultTransform(text2) {
|
|
12061
12091
|
return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
|
|
12062
12092
|
}
|
|
12093
|
+
function stripMarkdownCodeFenceSuffix(text2) {
|
|
12094
|
+
return text2.replace(/\n?```\s*$/, "").trimEnd();
|
|
12095
|
+
}
|
|
12063
12096
|
function extractJsonMiddleware(options) {
|
|
12064
12097
|
var _a22;
|
|
12065
12098
|
const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
|
|
@@ -12154,9 +12187,11 @@ function extractJsonMiddleware(options) {
|
|
|
12154
12187
|
if (block.phase === "buffering") {
|
|
12155
12188
|
remaining = transform(remaining);
|
|
12156
12189
|
} else if (block.prefixStripped) {
|
|
12157
|
-
remaining = remaining
|
|
12158
|
-
} else {
|
|
12190
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
12191
|
+
} else if (block.phase === "prefix") {
|
|
12159
12192
|
remaining = transform(remaining);
|
|
12193
|
+
} else {
|
|
12194
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
12160
12195
|
}
|
|
12161
12196
|
if (remaining.length > 0) {
|
|
12162
12197
|
controller.enqueue({
|