@trigger.dev/sdk 4.8.6 → 4.8.8
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/dist/commonjs/v3/ai.d.ts +5 -3
- package/dist/commonjs/v3/ai.js +144 -54
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/steeringContext.js +53 -4
- package/dist/commonjs/v3/steeringContext.js.map +1 -1
- package/dist/commonjs/v3/toolOutputJson.d.ts +17 -0
- package/dist/commonjs/v3/toolOutputJson.js +241 -0
- package/dist/commonjs/v3/toolOutputJson.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +5 -3
- package/dist/esm/v3/ai.js +144 -54
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/steeringContext.js +53 -4
- package/dist/esm/v3/steeringContext.js.map +1 -1
- package/dist/esm/v3/toolOutputJson.d.ts +17 -0
- package/dist/esm/v3/toolOutputJson.js +238 -0
- package/dist/esm/v3/toolOutputJson.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/docs/ai-chat/compaction.mdx +9 -3
- package/docs/apikeys.mdx +4 -3
- package/docs/github-integration.mdx +11 -1
- package/docs/mcp-remote.mdx +6 -4
- package/docs/mcp-tools.mdx +96 -2
- package/package.json +2 -2
|
@@ -6,7 +6,27 @@ exports.withoutInjectionMarkers = withoutInjectionMarkers;
|
|
|
6
6
|
exports.steeringMarkers = steeringMarkers;
|
|
7
7
|
exports.convertSteeredMessages = convertSteeredMessages;
|
|
8
8
|
const ai_shared_js_1 = require("./ai-shared.js");
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A message as JSON text, or null when JSON cannot hold it. The input an override
|
|
11
|
+
* is retained from is the AI SDK's own, so a tool result in it can still hold a
|
|
12
|
+
* BigInt or a circular reference. Plain `JSON.stringify` is tried first, since a
|
|
13
|
+
* replacer function takes it off V8's fast path and tool results can be large;
|
|
14
|
+
* only a BigInt (a TypeError) retries with the BigInt encoded by value, as an
|
|
15
|
+
* object a string cannot equal. Anything still unserializable is null.
|
|
16
|
+
*/
|
|
17
|
+
function serializeMessage(message) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.stringify(message);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
try {
|
|
23
|
+
return JSON.stringify(message, (_key, value) => typeof value === "bigint" ? { $bigint: value.toString() } : value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
10
30
|
/**
|
|
11
31
|
* Every response message of the generation so far, oldest first, taken from
|
|
12
32
|
* what the AI SDK hands prepareStep rather than inferred from the steps.
|
|
@@ -66,11 +86,40 @@ function retainStepMessages(prepare) {
|
|
|
66
86
|
return retained ? { ...result, messages: retained } : result;
|
|
67
87
|
};
|
|
68
88
|
}
|
|
69
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* How many of `next` already end `input`, as the longest overlap.
|
|
91
|
+
*
|
|
92
|
+
* A message is the same as another when it is the same object or both serialize
|
|
93
|
+
* to the same JSON. One that JSON cannot hold counts as different, so it is not
|
|
94
|
+
* de-duplicated: a head-start tool result with a circular reference is sent
|
|
95
|
+
* twice, which is rare and better than a failed step. Each message is
|
|
96
|
+
* serialized at most once, so the cost is linear in the messages' size rather
|
|
97
|
+
* than once per overlap length tried.
|
|
98
|
+
*/
|
|
70
99
|
function alreadyIncluded(input, next) {
|
|
100
|
+
const serialized = new Map();
|
|
101
|
+
const json = (message) => {
|
|
102
|
+
let text = serialized.get(message);
|
|
103
|
+
if (text === undefined) {
|
|
104
|
+
text = serializeMessage(message);
|
|
105
|
+
serialized.set(message, text);
|
|
106
|
+
}
|
|
107
|
+
return text;
|
|
108
|
+
};
|
|
109
|
+
const same = (a, b) => {
|
|
110
|
+
if (a === b)
|
|
111
|
+
return true;
|
|
112
|
+
if (a.role !== b.role)
|
|
113
|
+
return false;
|
|
114
|
+
const text = json(a);
|
|
115
|
+
return text !== null && text === json(b);
|
|
116
|
+
};
|
|
71
117
|
for (let count = Math.min(input.length, next.length); count > 0; count--) {
|
|
72
|
-
const
|
|
73
|
-
|
|
118
|
+
const start = input.length - count;
|
|
119
|
+
let matches = true;
|
|
120
|
+
for (let i = 0; i < count && matches; i++)
|
|
121
|
+
matches = same(input[start + i], next[i]);
|
|
122
|
+
if (matches)
|
|
74
123
|
return count;
|
|
75
124
|
}
|
|
76
125
|
return 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steeringContext.js","sourceRoot":"","sources":["../../../src/v3/steeringContext.ts"],"names":[],"mappings":";;;;;;;AACA,iDAA0F;AA2B1F,MAAM,
|
|
1
|
+
{"version":3,"file":"steeringContext.js","sourceRoot":"","sources":["../../../src/v3/steeringContext.ts"],"names":[],"mappings":";;;;;;;AACA,iDAA0F;AA2B1F;;;;;;;GAOG;AACH,SAAS,gBAAgB,CAAC,OAAqB;IAC7C,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAC7C,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAClE,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,oCAA2C,KAAsB;IAC/D,OAAO,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;AAC/E,CAAC;AA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ChF,CAAC,CAAC,CAAC;gBACH,IAAI,KAAK,CAAC,MAAM;oBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;QACD,IAAI,KAAK,CAAC,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,KAAK,EAAE,CAAC;IACd,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ModelMessage } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* Makes every JSON tool result in `messages` plain JSON, the shape the AI SDK
|
|
4
|
+
* validates a prompt against. Applied to the stored history between calls and,
|
|
5
|
+
* through the managed `prepareStep`, to each step's messages.
|
|
6
|
+
*
|
|
7
|
+
* From 7.0.101 the AI SDK converts a tool's output itself; earlier versions keep
|
|
8
|
+
* what `execute` returned. A `Date` from an ORM row then fails the next model
|
|
9
|
+
* call (AI SDK 6), or the next step of the same call (AI SDK 7 before 7.0.101),
|
|
10
|
+
* with a schema error naming only a message index. A value JSON can carry is
|
|
11
|
+
* converted the way the newer SDK does it, including a `BigInt` when the app
|
|
12
|
+
* defines `BigInt.prototype.toJSON`. One it cannot (a `BigInt` otherwise, a
|
|
13
|
+
* circular reference) becomes an error result naming the tool and the field, logged once,
|
|
14
|
+
* so the rest of the history stays valid. On an AI SDK that converts tool outputs
|
|
15
|
+
* itself this does nothing. Returns the same array when nothing changed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withJsonToolResults(messages: ModelMessage[]): Promise<ModelMessage[]>;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withJsonToolResults = withJsonToolResults;
|
|
4
|
+
const v3_1 = require("@trigger.dev/core/v3");
|
|
5
|
+
const ai_1 = require("ai");
|
|
6
|
+
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
7
|
+
const formatPath = (keys) => keys.reduce((path, key) => typeof key === "number"
|
|
8
|
+
? `${path}[${key}]`
|
|
9
|
+
: IDENTIFIER.test(key)
|
|
10
|
+
? path
|
|
11
|
+
? `${path}.${key}`
|
|
12
|
+
: key
|
|
13
|
+
: `${path}[${JSON.stringify(key)}]`, "") || "the top level";
|
|
14
|
+
/**
|
|
15
|
+
* Walks a value once, without copying it. Returns the first value JSON cannot
|
|
16
|
+
* hold with the keys leading to it, and sets `convert` when a JSON round trip
|
|
17
|
+
* would change the value (a `Date`, anything with `toJSON`, `undefined`, a
|
|
18
|
+
* non-finite number, a class instance, a sparse array).
|
|
19
|
+
*
|
|
20
|
+
* Kept lean: keys are pushed and popped and only joined into a path on failure,
|
|
21
|
+
* and only the chain of ancestors is kept, so an object referenced twice is not
|
|
22
|
+
* taken for a cycle.
|
|
23
|
+
*/
|
|
24
|
+
function inspect(root) {
|
|
25
|
+
const ancestors = [];
|
|
26
|
+
const keys = [];
|
|
27
|
+
let convert = false;
|
|
28
|
+
const visit = (value) => {
|
|
29
|
+
switch (typeof value) {
|
|
30
|
+
case "string":
|
|
31
|
+
case "boolean":
|
|
32
|
+
return undefined;
|
|
33
|
+
case "number":
|
|
34
|
+
if (!Number.isFinite(value))
|
|
35
|
+
convert = true;
|
|
36
|
+
return undefined;
|
|
37
|
+
case "bigint":
|
|
38
|
+
// An app can give BigInt a `toJSON` (an ORM's BigInt ids), which
|
|
39
|
+
// `JSON.stringify`, and so the AI SDK, then honours.
|
|
40
|
+
if (typeof BigInt.prototype.toJSON === "function") {
|
|
41
|
+
convert = true;
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return "BigInt";
|
|
45
|
+
case "undefined":
|
|
46
|
+
case "function":
|
|
47
|
+
case "symbol":
|
|
48
|
+
convert = true;
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
if (value === null)
|
|
52
|
+
return undefined;
|
|
53
|
+
const object = value;
|
|
54
|
+
if (ancestors.includes(object))
|
|
55
|
+
return "circular reference";
|
|
56
|
+
if (typeof object.toJSON === "function") {
|
|
57
|
+
convert = true;
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
ancestors.push(object);
|
|
61
|
+
if (Array.isArray(object)) {
|
|
62
|
+
for (let index = 0; index < object.length; index++) {
|
|
63
|
+
if (!(index in object))
|
|
64
|
+
convert = true;
|
|
65
|
+
keys.push(index);
|
|
66
|
+
const kind = visit(object[index]);
|
|
67
|
+
if (kind)
|
|
68
|
+
return kind;
|
|
69
|
+
keys.pop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const prototype = Object.getPrototypeOf(object);
|
|
74
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
75
|
+
convert = true;
|
|
76
|
+
for (const key in object) {
|
|
77
|
+
if (!Object.hasOwn(object, key))
|
|
78
|
+
continue;
|
|
79
|
+
keys.push(key);
|
|
80
|
+
const kind = visit(object[key]);
|
|
81
|
+
if (kind)
|
|
82
|
+
return kind;
|
|
83
|
+
keys.pop();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
ancestors.pop();
|
|
87
|
+
return undefined;
|
|
88
|
+
};
|
|
89
|
+
const kind = visit(root);
|
|
90
|
+
return kind ? { convert, issue: { kind, keys } } : { convert };
|
|
91
|
+
}
|
|
92
|
+
function check(value) {
|
|
93
|
+
const { issue, convert } = inspect(value);
|
|
94
|
+
let problem;
|
|
95
|
+
if (issue) {
|
|
96
|
+
problem = `${issue.kind} at ${formatPath(issue.keys)}`;
|
|
97
|
+
}
|
|
98
|
+
else if (convert) {
|
|
99
|
+
try {
|
|
100
|
+
// Same conversion as the AI SDK's own from 7.0.101: a Date becomes its ISO string.
|
|
101
|
+
const serialized = JSON.stringify(value);
|
|
102
|
+
return { value: serialized === undefined ? null : JSON.parse(serialized) };
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
problem = error instanceof Error ? error.message : String(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return { value };
|
|
110
|
+
}
|
|
111
|
+
return { problem };
|
|
112
|
+
}
|
|
113
|
+
const unserializableMessage = (toolName, problem) => `Tool "${toolName}" returned a value that cannot be sent to the model as JSON: ${problem}. ` +
|
|
114
|
+
"Convert it in the tool's execute before returning it, for example to a string or a number.";
|
|
115
|
+
/**
|
|
116
|
+
* Tool outputs already checked, and what each became, per tool call. AI SDK
|
|
117
|
+
* versions that keep the raw output pass the same object on every later
|
|
118
|
+
* conversion and step, so each result is walked, and converted, once per run
|
|
119
|
+
* however often the history is rebuilt. The tool call is part of the key because
|
|
120
|
+
* a tool can return the same object from several calls, changed in between (a
|
|
121
|
+
* shared state object): each call keeps the value it returned, as the AI SDK's
|
|
122
|
+
* own conversion from 7.0.101 does. Outputs are held weakly: entries go with them.
|
|
123
|
+
*/
|
|
124
|
+
const checked = new WeakMap();
|
|
125
|
+
/**
|
|
126
|
+
* Calls remembered per output, oldest dropped first. Bounds what an object that
|
|
127
|
+
* outlives its run (a module-level value returned by every call, in a reused
|
|
128
|
+
* process) keeps; a dropped call is only checked again.
|
|
129
|
+
*/
|
|
130
|
+
const MAX_CALLS_PER_OUTPUT = 64;
|
|
131
|
+
/**
|
|
132
|
+
* The cached verdict for one call's output, logging a problem the first time it
|
|
133
|
+
* is found. A bare value such as a top-level `BigInt` cannot be cached, so it is
|
|
134
|
+
* checked, and logged, on every conversion.
|
|
135
|
+
*/
|
|
136
|
+
function checkedOutput(value, part) {
|
|
137
|
+
if (typeof value !== "object" || value === null)
|
|
138
|
+
return reported(check(value), part);
|
|
139
|
+
let calls = checked.get(value);
|
|
140
|
+
if (!calls)
|
|
141
|
+
checked.set(value, (calls = new Map()));
|
|
142
|
+
let result = calls.get(part.toolCallId);
|
|
143
|
+
if (!result) {
|
|
144
|
+
calls.set(part.toolCallId, (result = reported(check(value), part)));
|
|
145
|
+
if (calls.size > MAX_CALLS_PER_OUTPUT)
|
|
146
|
+
calls.delete(calls.keys().next().value);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
function reported(result, part) {
|
|
151
|
+
if ("problem" in result)
|
|
152
|
+
v3_1.logger.error(unserializableMessage(part.toolName, result.problem));
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
let sdkConvertsToolOutputs;
|
|
156
|
+
/**
|
|
157
|
+
* Whether the installed AI SDK turns tool outputs into plain JSON itself, as it
|
|
158
|
+
* does from 7.0.101. Asked once per process by converting one tool part holding a
|
|
159
|
+
* `Date`, so it follows what the SDK does rather than its version number. Where
|
|
160
|
+
* it does, a `toModelOutput` returning `{ type: "json" }` is left as the tool
|
|
161
|
+
* built it, as the SDK itself leaves it.
|
|
162
|
+
*/
|
|
163
|
+
function aiSdkConvertsToolOutputs() {
|
|
164
|
+
sdkConvertsToolOutputs ??= (async () => {
|
|
165
|
+
const probe = {
|
|
166
|
+
id: "probe",
|
|
167
|
+
role: "assistant",
|
|
168
|
+
parts: [
|
|
169
|
+
{
|
|
170
|
+
type: "dynamic-tool",
|
|
171
|
+
toolName: "probe",
|
|
172
|
+
toolCallId: "probe",
|
|
173
|
+
state: "output-available",
|
|
174
|
+
input: {},
|
|
175
|
+
output: new Date(0),
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
try {
|
|
180
|
+
const converted = await (0, ai_1.convertToModelMessages)([probe]);
|
|
181
|
+
const result = converted
|
|
182
|
+
.flatMap((message) => (Array.isArray(message.content) ? message.content : []))
|
|
183
|
+
.find((part) => isJsonToolResult(part));
|
|
184
|
+
return typeof result?.output.value === "string";
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
})();
|
|
190
|
+
return sdkConvertsToolOutputs;
|
|
191
|
+
}
|
|
192
|
+
const isJsonToolResult = (part) => {
|
|
193
|
+
const candidate = part;
|
|
194
|
+
return (candidate?.type === "tool-result" &&
|
|
195
|
+
(candidate.output?.type === "json" || candidate.output?.type === "error-json"));
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Makes every JSON tool result in `messages` plain JSON, the shape the AI SDK
|
|
199
|
+
* validates a prompt against. Applied to the stored history between calls and,
|
|
200
|
+
* through the managed `prepareStep`, to each step's messages.
|
|
201
|
+
*
|
|
202
|
+
* From 7.0.101 the AI SDK converts a tool's output itself; earlier versions keep
|
|
203
|
+
* what `execute` returned. A `Date` from an ORM row then fails the next model
|
|
204
|
+
* call (AI SDK 6), or the next step of the same call (AI SDK 7 before 7.0.101),
|
|
205
|
+
* with a schema error naming only a message index. A value JSON can carry is
|
|
206
|
+
* converted the way the newer SDK does it, including a `BigInt` when the app
|
|
207
|
+
* defines `BigInt.prototype.toJSON`. One it cannot (a `BigInt` otherwise, a
|
|
208
|
+
* circular reference) becomes an error result naming the tool and the field, logged once,
|
|
209
|
+
* so the rest of the history stays valid. On an AI SDK that converts tool outputs
|
|
210
|
+
* itself this does nothing. Returns the same array when nothing changed.
|
|
211
|
+
*/
|
|
212
|
+
async function withJsonToolResults(messages) {
|
|
213
|
+
if (await aiSdkConvertsToolOutputs())
|
|
214
|
+
return messages;
|
|
215
|
+
let result;
|
|
216
|
+
messages.forEach((message, index) => {
|
|
217
|
+
if (!Array.isArray(message.content))
|
|
218
|
+
return;
|
|
219
|
+
let content;
|
|
220
|
+
message.content.forEach((part, partIndex) => {
|
|
221
|
+
if (!isJsonToolResult(part))
|
|
222
|
+
return;
|
|
223
|
+
const outcome = checkedOutput(part.output.value, part);
|
|
224
|
+
if ("value" in outcome && outcome.value === part.output.value)
|
|
225
|
+
return;
|
|
226
|
+
content ??= [...message.content];
|
|
227
|
+
content[partIndex] = {
|
|
228
|
+
...part,
|
|
229
|
+
output: "value" in outcome
|
|
230
|
+
? { ...part.output, value: outcome.value }
|
|
231
|
+
: { type: "error-text", value: unserializableMessage(part.toolName, outcome.problem) },
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
if (!content)
|
|
235
|
+
return;
|
|
236
|
+
result ??= [...messages];
|
|
237
|
+
result[index] = { ...message, content };
|
|
238
|
+
});
|
|
239
|
+
return result ?? messages;
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=toolOutputJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolOutputJson.js","sourceRoot":"","sources":["../../../src/v3/toolOutputJson.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAC9C,2BAA+E;AAM/E,MAAM,UAAU,GAAG,oBAAoB,CAAC;AACxC,MAAM,UAAU,GAAG,CAAC,IAAyB,EAAE,EAAE,CAC/C,IAAI,CAAC,MAAM,CACT,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CACZ,OAAO,GAAG,KAAK,QAAQ;IACrB,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,GAAG;IACnB,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;QACpB,CAAC,CAAC,IAAI;YACJ,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE;YAClB,CAAC,CAAC,GAAG;QACP,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EACzC,EAAE,CACH,IAAI,eAAe,CAAC;AAEvB;;;;;;;;;GASG;AACH,SAAS,OAAO,CAAC,IAAa;IAC5B,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,KAAK,GAAG,CAAC,KAAc,EAAsB,EAAE;QACnD,QAAQ,OAAO,KAAK,EAAE,CAAC;YACrB,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS;gBACZ,OAAO,SAAS,CAAC;YACnB,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,GAAI,OAAO,CAAC,OAAqB,CAAC,CAAC;YAChD,OAAO,CAAC,SAAS,CAAC,GAAG;gBACnB,GAAG,IAAI;gBACP,MAAM,EACJ,OAAO,IAAI,OAAO;oBAChB,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE;oBAC1C,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;aAC3F,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,OAAO,EAAkB,CAAC;IAC1D,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,IAAI,QAAQ,CAAC;AAC5B,CAAC"}
|
package/dist/commonjs/version.js
CHANGED
package/dist/esm/v3/ai.d.ts
CHANGED
|
@@ -3694,9 +3694,11 @@ declare class ChatMessageAccumulator {
|
|
|
3694
3694
|
} | undefined>) | undefined;
|
|
3695
3695
|
/**
|
|
3696
3696
|
* Run outer-loop compaction if needed. Call after adding the response
|
|
3697
|
-
* and capturing usage. Pass the LAST step's usage
|
|
3698
|
-
* the context the model held on
|
|
3699
|
-
*
|
|
3697
|
+
* and capturing usage. Pass the LAST step's usage
|
|
3698
|
+
* (`(await result.steps).at(-1)?.usage`), which is the context the model held on
|
|
3699
|
+
* its final call. `result.usage` is that on AI SDK 6 but the turn's sum on AI SDK 7,
|
|
3700
|
+
* so read `steps`. The turn's sum (`result.totalUsage` on AI SDK 6, `result.usage`
|
|
3701
|
+
* on AI SDK 7) belongs in `context.turnUsage`. Applies
|
|
3700
3702
|
* `compactModelMessages` and `compactUIMessages` callbacks if configured.
|
|
3701
3703
|
*
|
|
3702
3704
|
* @returns `true` if compaction was performed, `false` otherwise.
|