ai 6.0.218 → 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 +19 -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/36-transcription.mdx +2 -2
- 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/docs/07-reference/01-ai-sdk-core/index.mdx +5 -0
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.220
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 158d027: Sort tool results by their tool call order when converting generation output to response messages.
|
|
8
|
+
- eb3cdd9: Fix `extractJsonMiddleware` preserving leading whitespace in the final streamed text suffix when no markdown fence prefix was stripped.
|
|
9
|
+
- Updated dependencies [7dea716]
|
|
10
|
+
- Updated dependencies [4f7fe37]
|
|
11
|
+
- Updated dependencies [0952964]
|
|
12
|
+
- @ai-sdk/gateway@3.0.144
|
|
13
|
+
- @ai-sdk/provider-utils@4.0.36
|
|
14
|
+
|
|
15
|
+
## 6.0.219
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [8fbadac]
|
|
20
|
+
- @ai-sdk/gateway@3.0.143
|
|
21
|
+
|
|
3
22
|
## 6.0.218
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3459,6 +3459,16 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
3459
3459
|
* Prepare the parameters for the generateText or streamText call.
|
|
3460
3460
|
*
|
|
3461
3461
|
* You can use this to have templates based on call options.
|
|
3462
|
+
*
|
|
3463
|
+
* The design requires you to pass call parameters as follows to
|
|
3464
|
+
* allow for the removal of parameters from the original settings
|
|
3465
|
+
* by setting them to `undefined`:
|
|
3466
|
+
*
|
|
3467
|
+
* ```
|
|
3468
|
+
* prepareCall: ({ options, ...rest }) => ({
|
|
3469
|
+
* ...rest,
|
|
3470
|
+
* }),
|
|
3471
|
+
* ```
|
|
3462
3472
|
*/
|
|
3463
3473
|
prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>>, 'onStepFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
|
|
3464
3474
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -3459,6 +3459,16 @@ type ToolLoopAgentSettings<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUT
|
|
|
3459
3459
|
* Prepare the parameters for the generateText or streamText call.
|
|
3460
3460
|
*
|
|
3461
3461
|
* You can use this to have templates based on call options.
|
|
3462
|
+
*
|
|
3463
|
+
* The design requires you to pass call parameters as follows to
|
|
3464
|
+
* allow for the removal of parameters from the original settings
|
|
3465
|
+
* by setting them to `undefined`:
|
|
3466
|
+
*
|
|
3467
|
+
* ```
|
|
3468
|
+
* prepareCall: ({ options, ...rest }) => ({
|
|
3469
|
+
* ...rest,
|
|
3470
|
+
* }),
|
|
3471
|
+
* ```
|
|
3462
3472
|
*/
|
|
3463
3473
|
prepareCall?: (options: Omit<AgentCallParameters<CALL_OPTIONS, NoInfer<TOOLS>>, 'onStepFinish'> & Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'>) => MaybePromiseLike<Pick<ToolLoopAgentSettings<CALL_OPTIONS, TOOLS, OUTPUT>, 'model' | 'tools' | 'maxOutputTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'headers' | 'instructions' | 'allowSystemInMessages' | 'stopWhen' | 'experimental_telemetry' | 'activeTools' | 'providerOptions' | 'experimental_context' | 'experimental_download'> & Omit<Prompt, 'system'>>;
|
|
3464
3474
|
};
|
package/dist/index.js
CHANGED
|
@@ -1281,7 +1281,7 @@ function detectMediaType({
|
|
|
1281
1281
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1282
1282
|
|
|
1283
1283
|
// src/version.ts
|
|
1284
|
-
var VERSION = true ? "6.0.
|
|
1284
|
+
var VERSION = true ? "6.0.220" : "0.0.0-test";
|
|
1285
1285
|
|
|
1286
1286
|
// src/util/download/download.ts
|
|
1287
1287
|
var download = async ({
|
|
@@ -4223,6 +4223,7 @@ async function toResponseMessages({
|
|
|
4223
4223
|
tools
|
|
4224
4224
|
}) {
|
|
4225
4225
|
const responseMessages = [];
|
|
4226
|
+
const toolCallOrder = /* @__PURE__ */ new Map();
|
|
4226
4227
|
const content = [];
|
|
4227
4228
|
for (const part of inputContent) {
|
|
4228
4229
|
if (part.type === "source") {
|
|
@@ -4258,6 +4259,9 @@ async function toResponseMessages({
|
|
|
4258
4259
|
});
|
|
4259
4260
|
break;
|
|
4260
4261
|
case "tool-call":
|
|
4262
|
+
if (!toolCallOrder.has(part.toolCallId)) {
|
|
4263
|
+
toolCallOrder.set(part.toolCallId, toolCallOrder.size);
|
|
4264
|
+
}
|
|
4261
4265
|
content.push({
|
|
4262
4266
|
type: "tool-call",
|
|
4263
4267
|
toolCallId: part.toolCallId,
|
|
@@ -4340,11 +4344,37 @@ async function toResponseMessages({
|
|
|
4340
4344
|
if (toolResultContent.length > 0) {
|
|
4341
4345
|
responseMessages.push({
|
|
4342
4346
|
role: "tool",
|
|
4343
|
-
content:
|
|
4347
|
+
content: sortToolResultContentByToolCallOrder({
|
|
4348
|
+
toolResultContent,
|
|
4349
|
+
toolCallOrder
|
|
4350
|
+
})
|
|
4344
4351
|
});
|
|
4345
4352
|
}
|
|
4346
4353
|
return responseMessages;
|
|
4347
4354
|
}
|
|
4355
|
+
function sortToolResultContentByToolCallOrder({
|
|
4356
|
+
toolResultContent,
|
|
4357
|
+
toolCallOrder
|
|
4358
|
+
}) {
|
|
4359
|
+
const sortedToolResults = toolResultContent.filter((part) => part.type === "tool-result").map((part, index) => ({ part, index })).sort((a, b) => {
|
|
4360
|
+
const aOrder = toolCallOrder.get(a.part.toolCallId);
|
|
4361
|
+
const bOrder = toolCallOrder.get(b.part.toolCallId);
|
|
4362
|
+
if (aOrder == null && bOrder == null) {
|
|
4363
|
+
return a.index - b.index;
|
|
4364
|
+
}
|
|
4365
|
+
if (aOrder == null) {
|
|
4366
|
+
return 1;
|
|
4367
|
+
}
|
|
4368
|
+
if (bOrder == null) {
|
|
4369
|
+
return -1;
|
|
4370
|
+
}
|
|
4371
|
+
return aOrder - bOrder || a.index - b.index;
|
|
4372
|
+
}).map(({ part }) => part);
|
|
4373
|
+
let toolResultIndex = 0;
|
|
4374
|
+
return toolResultContent.map(
|
|
4375
|
+
(part) => part.type === "tool-result" ? sortedToolResults[toolResultIndex++] : part
|
|
4376
|
+
);
|
|
4377
|
+
}
|
|
4348
4378
|
|
|
4349
4379
|
// src/util/merge-abort-signals.ts
|
|
4350
4380
|
function mergeAbortSignals(...signals) {
|
|
@@ -12093,6 +12123,9 @@ function defaultSettingsMiddleware({
|
|
|
12093
12123
|
function defaultTransform(text2) {
|
|
12094
12124
|
return text2.replace(/^```(?:json)?\s*\n?/, "").replace(/\n?```\s*$/, "").trim();
|
|
12095
12125
|
}
|
|
12126
|
+
function stripMarkdownCodeFenceSuffix(text2) {
|
|
12127
|
+
return text2.replace(/\n?```\s*$/, "").trimEnd();
|
|
12128
|
+
}
|
|
12096
12129
|
function extractJsonMiddleware(options) {
|
|
12097
12130
|
var _a22;
|
|
12098
12131
|
const transform = (_a22 = options == null ? void 0 : options.transform) != null ? _a22 : defaultTransform;
|
|
@@ -12187,9 +12220,11 @@ function extractJsonMiddleware(options) {
|
|
|
12187
12220
|
if (block.phase === "buffering") {
|
|
12188
12221
|
remaining = transform(remaining);
|
|
12189
12222
|
} else if (block.prefixStripped) {
|
|
12190
|
-
remaining = remaining
|
|
12191
|
-
} else {
|
|
12223
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
12224
|
+
} else if (block.phase === "prefix") {
|
|
12192
12225
|
remaining = transform(remaining);
|
|
12226
|
+
} else {
|
|
12227
|
+
remaining = stripMarkdownCodeFenceSuffix(remaining);
|
|
12193
12228
|
}
|
|
12194
12229
|
if (remaining.length > 0) {
|
|
12195
12230
|
controller.enqueue({
|