@cuylabs/agent-core 0.7.0 → 0.9.0
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/{builder-BRvqCcIk.d.ts → builder-BgZ_j4Vs.d.ts} +3 -2
- package/dist/chunk-4QFNWPIF.js +202 -0
- package/dist/chunk-5ARZJWD2.js +259 -0
- package/dist/chunk-DXFBQMXP.js +53 -0
- package/dist/chunk-EKR6PKXU.js +180 -0
- package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
- package/dist/{chunk-IEFIQENH.js → chunk-H3FUYU52.js} +15 -7
- package/dist/chunk-I6PKJ7XQ.js +292 -0
- package/dist/chunk-IYWQOJMQ.js +102 -0
- package/dist/{chunk-3HNO5SVI.js → chunk-J4QDGZIA.js} +20 -4
- package/dist/{chunk-7MUFEN4K.js → chunk-JLXG2SH7.js} +349 -3
- package/dist/{chunk-CDTV2UYU.js → chunk-MAZ5DY5B.js} +64 -276
- package/dist/{chunk-P6YF7USR.js → chunk-MHKK374K.js} +12 -11
- package/dist/{chunk-VBWWUHWI.js → chunk-OFDKHNCX.js} +4 -1
- package/dist/{chunk-YUUJK53A.js → chunk-RKEW5WXI.js} +1 -1
- package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
- package/dist/{chunk-QGOGIP7T.js → chunk-UDCZ673N.js} +385 -233
- package/dist/{chunk-BDBZ3SLK.js → chunk-UHCJEM2E.js} +39 -2
- package/dist/chunk-WGZAPU6N.js +929 -0
- package/dist/{chunk-5K7AQVOU.js → chunk-WKHDSSXG.js} +130 -209
- package/dist/{chunk-BNSHUWCV.js → chunk-WWYYNWEW.js} +1 -1
- package/dist/context/index.js +1 -1
- package/dist/events-CE72w8W4.d.ts +149 -0
- package/dist/index-BCqEGzBj.d.ts +251 -0
- package/dist/{index-C33hlD6H.d.ts → index-DQuTZ8xL.d.ts} +319 -56
- package/dist/index.d.ts +42 -121
- package/dist/index.js +951 -848
- package/dist/inference/errors/index.d.ts +11 -0
- package/dist/inference/errors/index.js +16 -0
- package/dist/inference/index.d.ts +12 -8
- package/dist/inference/index.js +35 -7
- package/dist/llm-error-D93FNNLY.d.ts +32 -0
- package/dist/middleware/index.d.ts +246 -7
- package/dist/middleware/index.js +3 -1
- package/dist/models/index.d.ts +132 -9
- package/dist/models/index.js +48 -8
- package/dist/models/reasoning/index.d.ts +4 -0
- package/dist/{reasoning → models/reasoning}/index.js +2 -7
- package/dist/plugin/index.d.ts +414 -0
- package/dist/plugin/index.js +32 -0
- package/dist/presets/index.d.ts +53 -0
- package/dist/presets/index.js +30 -0
- package/dist/prompt/index.d.ts +11 -8
- package/dist/prompt/index.js +3 -2
- package/dist/{registry-BDLIHOQB.d.ts → registry-DwYqsQkX.d.ts} +1 -1
- package/dist/runner-CI-XeR16.d.ts +91 -0
- package/dist/runtime/index.d.ts +12 -8
- package/dist/runtime/index.js +8 -7
- package/dist/safety/index.d.ts +38 -0
- package/dist/safety/index.js +12 -0
- package/dist/scope/index.d.ts +2 -2
- package/dist/{session-manager-B_CWGTsl.d.ts → session-manager-KbYt2WUh.d.ts} +8 -0
- package/dist/signal/index.d.ts +28 -0
- package/dist/signal/index.js +6 -0
- package/dist/skill/index.d.ts +7 -6
- package/dist/skill/index.js +3 -3
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/sub-agent/index.d.ts +16 -10
- package/dist/sub-agent/index.js +21 -4
- package/dist/tool/index.d.ts +22 -6
- package/dist/tool/index.js +3 -3
- package/dist/tool-CZWN3KbO.d.ts +141 -0
- package/dist/{tool-HUtkiVBx.d.ts → tool-DkhSCV2Y.d.ts} +2 -2
- package/dist/tracking/index.d.ts +2 -2
- package/dist/tracking/index.js +1 -1
- package/dist/{tool-Db1Ue-1U.d.ts → types-BfNpU8NS.d.ts} +1 -150
- package/dist/{types-FRpzzg_9.d.ts → types-BlOKk-Bb.d.ts} +10 -35
- package/dist/types-BlZwmnuW.d.ts +50 -0
- package/dist/{types-9jGQUjqW.d.ts → types-CQL-SvTn.d.ts} +1 -1
- package/dist/types-CWm-7rvB.d.ts +55 -0
- package/dist/{runner-DSKaEz3z.d.ts → types-DTSkxakL.d.ts} +7 -235
- package/dist/{types-CqDZTh4d.d.ts → types-DmDwi2zI.d.ts} +8 -4
- package/dist/types-YuWV4ag7.d.ts +72 -0
- package/package.json +67 -6
- package/dist/capability-resolver-CgRGsWVX.d.ts +0 -254
- package/dist/chunk-ZPMACVZK.js +0 -305
- package/dist/index-CfBGYrpd.d.ts +0 -317
- package/dist/reasoning/index.d.ts +0 -117
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildReasoningOptionsSync
|
|
3
|
-
} from "./chunk-ZPMACVZK.js";
|
|
4
1
|
import {
|
|
5
2
|
executeAgentToolCall
|
|
6
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-H3FUYU52.js";
|
|
4
|
+
import {
|
|
5
|
+
LLMError,
|
|
6
|
+
isRetryable
|
|
7
|
+
} from "./chunk-4QFNWPIF.js";
|
|
7
8
|
import {
|
|
8
9
|
snapshotScope
|
|
9
10
|
} from "./chunk-N7P4PN3O.js";
|
|
11
|
+
import {
|
|
12
|
+
buildReasoningOptionsSync
|
|
13
|
+
} from "./chunk-UDCZ673N.js";
|
|
10
14
|
|
|
11
15
|
// src/inference/toolset.ts
|
|
12
16
|
import { tool, zodSchema } from "ai";
|
|
@@ -21,6 +25,7 @@ async function buildToolSet(options) {
|
|
|
21
25
|
execute: async (params) => (await executeAgentToolCall({
|
|
22
26
|
toolName: id,
|
|
23
27
|
tool: info,
|
|
28
|
+
initialized,
|
|
24
29
|
params,
|
|
25
30
|
cwd: options.cwd,
|
|
26
31
|
abort: options.abort,
|
|
@@ -44,201 +49,114 @@ import {
|
|
|
44
49
|
streamText
|
|
45
50
|
} from "ai";
|
|
46
51
|
|
|
47
|
-
// src/
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
case "rate_limit":
|
|
51
|
-
case "overloaded":
|
|
52
|
-
case "network":
|
|
53
|
-
case "timeout":
|
|
54
|
-
return true;
|
|
55
|
-
case "auth":
|
|
56
|
-
case "invalid_request":
|
|
57
|
-
case "context_overflow":
|
|
58
|
-
case "content_filter":
|
|
59
|
-
case "cancelled":
|
|
60
|
-
case "unknown":
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
52
|
+
// src/inference/middleware-support.ts
|
|
53
|
+
function isPlainObject(value) {
|
|
54
|
+
return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
63
55
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
if (status) {
|
|
67
|
-
if (status === 429) return "rate_limit";
|
|
68
|
-
if (status === 401 || status === 403) return "auth";
|
|
69
|
-
if (status === 400) {
|
|
70
|
-
if (lowerMessage.includes("context") || lowerMessage.includes("token")) {
|
|
71
|
-
return "context_overflow";
|
|
72
|
-
}
|
|
73
|
-
return "invalid_request";
|
|
74
|
-
}
|
|
75
|
-
if (status === 503 || status === 502) return "overloaded";
|
|
76
|
-
if (status >= 500) return "network";
|
|
77
|
-
}
|
|
78
|
-
if (lowerMessage.includes("rate") && lowerMessage.includes("limit")) {
|
|
79
|
-
return "rate_limit";
|
|
80
|
-
}
|
|
81
|
-
if (lowerMessage.includes("overload") || lowerMessage.includes("capacity")) {
|
|
82
|
-
return "overloaded";
|
|
83
|
-
}
|
|
84
|
-
if (lowerMessage.includes("too_many_requests")) {
|
|
85
|
-
return "rate_limit";
|
|
86
|
-
}
|
|
87
|
-
if (lowerMessage.includes("unauthorized") || lowerMessage.includes("invalid api key")) {
|
|
88
|
-
return "auth";
|
|
89
|
-
}
|
|
90
|
-
if (lowerMessage.includes("context") && lowerMessage.includes("length")) {
|
|
91
|
-
return "context_overflow";
|
|
92
|
-
}
|
|
93
|
-
if (lowerMessage.includes("content") && lowerMessage.includes("filter")) {
|
|
94
|
-
return "content_filter";
|
|
95
|
-
}
|
|
96
|
-
if (lowerMessage.includes("timeout") || lowerMessage.includes("timed out")) {
|
|
97
|
-
return "timeout";
|
|
98
|
-
}
|
|
99
|
-
if (lowerMessage.includes("network") || lowerMessage.includes("econnrefused") || lowerMessage.includes("econnreset")) {
|
|
100
|
-
return "network";
|
|
101
|
-
}
|
|
102
|
-
return "unknown";
|
|
56
|
+
function isAsyncIterable(value) {
|
|
57
|
+
return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
|
|
103
58
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const parsed = parseFloat(retryAfterMs);
|
|
108
|
-
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
109
|
-
return parsed;
|
|
110
|
-
}
|
|
59
|
+
function stringifyToolOutput(output) {
|
|
60
|
+
if (typeof output === "string") {
|
|
61
|
+
return output;
|
|
111
62
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
const dateMs = Date.parse(retryAfter);
|
|
119
|
-
if (!Number.isNaN(dateMs)) {
|
|
120
|
-
const delayMs = dateMs - Date.now();
|
|
121
|
-
if (delayMs > 0) {
|
|
122
|
-
return Math.ceil(delayMs);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
63
|
+
try {
|
|
64
|
+
const serialized = JSON.stringify(output);
|
|
65
|
+
return serialized ?? String(output);
|
|
66
|
+
} catch {
|
|
67
|
+
return String(output);
|
|
125
68
|
}
|
|
126
|
-
return void 0;
|
|
127
69
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
result.headers = anyError.headers;
|
|
142
|
-
}
|
|
143
|
-
if (anyError.data && typeof anyError.data === "object") {
|
|
144
|
-
const data = anyError.data;
|
|
145
|
-
if (data.type === "error" && typeof data.error === "object") {
|
|
146
|
-
const innerError = data.error;
|
|
147
|
-
if (innerError.type === "too_many_requests") {
|
|
148
|
-
result.category = "rate_limit";
|
|
149
|
-
} else if (innerError.type === "overloaded") {
|
|
150
|
-
result.category = "overloaded";
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (typeof data.isRetryable === "boolean" && !data.isRetryable && !result.category) {
|
|
154
|
-
result.category = "invalid_request";
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return result;
|
|
70
|
+
async function runAfterToolCall(options) {
|
|
71
|
+
const { middleware, toolName, params, output, ctx } = options;
|
|
72
|
+
const transformed = await middleware.runAfterToolCall(
|
|
73
|
+
toolName,
|
|
74
|
+
params,
|
|
75
|
+
{
|
|
76
|
+
title: toolName,
|
|
77
|
+
output: stringifyToolOutput(output),
|
|
78
|
+
metadata: {}
|
|
79
|
+
},
|
|
80
|
+
ctx
|
|
81
|
+
);
|
|
82
|
+
return typeof output === "string" ? transformed.output : output;
|
|
158
83
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
static from(error, context) {
|
|
184
|
-
if (error instanceof _LLMError) {
|
|
185
|
-
return error;
|
|
84
|
+
function mergeProviderOptions(base, override) {
|
|
85
|
+
if (!base) return override;
|
|
86
|
+
if (!override) return base;
|
|
87
|
+
const merged = { ...base };
|
|
88
|
+
for (const [key, value] of Object.entries(override)) {
|
|
89
|
+
const current = merged[key];
|
|
90
|
+
merged[key] = isPlainObject(current) && isPlainObject(value) ? mergeProviderOptions(
|
|
91
|
+
current,
|
|
92
|
+
value
|
|
93
|
+
) : value;
|
|
94
|
+
}
|
|
95
|
+
return merged;
|
|
96
|
+
}
|
|
97
|
+
function wrapMcpToolsForMiddleware(options) {
|
|
98
|
+
const { tools, middleware, cwd, sessionID, abort, agent } = options;
|
|
99
|
+
if (!middleware?.hasMiddleware) {
|
|
100
|
+
return tools;
|
|
101
|
+
}
|
|
102
|
+
const wrapped = {};
|
|
103
|
+
for (const [toolName, tool2] of Object.entries(tools)) {
|
|
104
|
+
if (!tool2.execute) {
|
|
105
|
+
wrapped[toolName] = tool2;
|
|
106
|
+
continue;
|
|
186
107
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
108
|
+
wrapped[toolName] = {
|
|
109
|
+
...tool2,
|
|
110
|
+
execute: async (params, execOptions) => {
|
|
111
|
+
const ctx = {
|
|
112
|
+
cwd,
|
|
113
|
+
abort: execOptions.abortSignal ?? abort,
|
|
114
|
+
sessionID,
|
|
115
|
+
messageID: execOptions.toolCallId,
|
|
116
|
+
agent: agent ?? "default",
|
|
117
|
+
scope: snapshotScope(),
|
|
118
|
+
extra: {
|
|
119
|
+
toolCallId: execOptions.toolCallId,
|
|
120
|
+
messages: execOptions.messages,
|
|
121
|
+
experimentalContext: execOptions.experimental_context
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const decision = await middleware.runBeforeToolCall(
|
|
125
|
+
toolName,
|
|
126
|
+
params,
|
|
127
|
+
ctx
|
|
128
|
+
);
|
|
129
|
+
if (decision.action === "deny") {
|
|
130
|
+
return decision.reason ?? `Tool call denied: ${toolName}`;
|
|
131
|
+
}
|
|
132
|
+
const result = tool2.execute(params, execOptions);
|
|
133
|
+
if (isAsyncIterable(result)) {
|
|
134
|
+
let lastOutput;
|
|
135
|
+
for await (const chunk of result) {
|
|
136
|
+
lastOutput = chunk;
|
|
137
|
+
}
|
|
138
|
+
return await runAfterToolCall({
|
|
139
|
+
middleware,
|
|
140
|
+
toolName,
|
|
141
|
+
params,
|
|
142
|
+
output: lastOutput,
|
|
143
|
+
ctx
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return await runAfterToolCall({
|
|
147
|
+
middleware,
|
|
148
|
+
toolName,
|
|
149
|
+
params,
|
|
150
|
+
output: await result,
|
|
151
|
+
ctx
|
|
194
152
|
});
|
|
195
153
|
}
|
|
196
|
-
|
|
197
|
-
message: error.message,
|
|
198
|
-
cause: error,
|
|
199
|
-
...extractFromAISDKError(error),
|
|
200
|
-
...context
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
return new _LLMError({
|
|
204
|
-
message: String(error),
|
|
205
|
-
category: "unknown",
|
|
206
|
-
...context
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
get description() {
|
|
210
|
-
const parts = [this.message];
|
|
211
|
-
if (this.provider) parts.unshift(`[${this.provider}]`);
|
|
212
|
-
if (this.status) parts.push(`(HTTP ${this.status})`);
|
|
213
|
-
if (this.isRetryable && this.retryDelayMs) {
|
|
214
|
-
parts.push(`retry in ${Math.ceil(this.retryDelayMs / 1e3)}s`);
|
|
215
|
-
}
|
|
216
|
-
return parts.join(" ");
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
// src/errors/utils.ts
|
|
221
|
-
function isRetryable(error) {
|
|
222
|
-
if (error instanceof LLMError) {
|
|
223
|
-
return error.isRetryable;
|
|
224
|
-
}
|
|
225
|
-
return LLMError.from(error).isRetryable;
|
|
226
|
-
}
|
|
227
|
-
function getRetryDelay(error) {
|
|
228
|
-
if (error instanceof LLMError) {
|
|
229
|
-
return error.isRetryable ? error.retryDelayMs : void 0;
|
|
230
|
-
}
|
|
231
|
-
const llmError = LLMError.from(error);
|
|
232
|
-
return llmError.isRetryable ? llmError.retryDelayMs : void 0;
|
|
233
|
-
}
|
|
234
|
-
function getErrorCategory(error) {
|
|
235
|
-
if (error instanceof LLMError) {
|
|
236
|
-
return error.category;
|
|
154
|
+
};
|
|
237
155
|
}
|
|
238
|
-
return
|
|
156
|
+
return wrapped;
|
|
239
157
|
}
|
|
240
158
|
|
|
241
|
-
// src/retry.ts
|
|
159
|
+
// src/inference/retry.ts
|
|
242
160
|
var DEFAULT_RETRY_CONFIG = {
|
|
243
161
|
maxAttempts: 3,
|
|
244
162
|
initialDelayMs: 2e3,
|
|
@@ -377,11 +295,6 @@ function applyModelCallInput(target, modelCall) {
|
|
|
377
295
|
target.toolExecutionMode = modelCall.toolExecutionMode;
|
|
378
296
|
target.activeModelCall = modelCall;
|
|
379
297
|
}
|
|
380
|
-
function mergeProviderOptions(base, override) {
|
|
381
|
-
if (!base) return override;
|
|
382
|
-
if (!override) return base;
|
|
383
|
-
return { ...base, ...override };
|
|
384
|
-
}
|
|
385
298
|
function isBlockedModelCall(value) {
|
|
386
299
|
return "block" in value && value.block === true;
|
|
387
300
|
}
|
|
@@ -471,6 +384,11 @@ async function callStreamTextWithOtelContext(options) {
|
|
|
471
384
|
abortSignal: input.abort,
|
|
472
385
|
providerOptions: mergedProviderOptions,
|
|
473
386
|
experimental_telemetry: input.telemetry,
|
|
387
|
+
// The AI SDK defaults to console.error(error) for stream failures.
|
|
388
|
+
// We normalize and surface these errors through our own runtime events,
|
|
389
|
+
// so suppress the duplicate raw dump here.
|
|
390
|
+
onError: () => {
|
|
391
|
+
},
|
|
474
392
|
prepareStep: input.intervention ? async ({ messages }) => {
|
|
475
393
|
const pending = input.intervention.drainImmediate();
|
|
476
394
|
if (pending.length === 0) {
|
|
@@ -532,11 +450,14 @@ async function stream(input) {
|
|
|
532
450
|
if (!input.retry || input.retry.maxAttempts === 0) {
|
|
533
451
|
return wrapModelStream(await runCustomStream(), input);
|
|
534
452
|
}
|
|
535
|
-
return wrapModelStream(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
453
|
+
return wrapModelStream(
|
|
454
|
+
await withRetry(
|
|
455
|
+
async () => await runCustomStream(),
|
|
456
|
+
input.retry,
|
|
457
|
+
input.abort
|
|
458
|
+
),
|
|
459
|
+
input
|
|
460
|
+
);
|
|
540
461
|
}
|
|
541
462
|
const toolSet = await buildToolSet({
|
|
542
463
|
tools: input.tools,
|
|
@@ -549,9 +470,16 @@ async function stream(input) {
|
|
|
549
470
|
middleware: input.middleware,
|
|
550
471
|
executionMode: input.toolExecutionMode
|
|
551
472
|
});
|
|
473
|
+
const mcpToolSet = wrapMcpToolsForMiddleware({
|
|
474
|
+
tools: input.mcpTools ?? {},
|
|
475
|
+
middleware: input.middleware,
|
|
476
|
+
cwd: input.cwd,
|
|
477
|
+
sessionID: input.sessionID,
|
|
478
|
+
abort: input.abort
|
|
479
|
+
});
|
|
552
480
|
const allTools = {
|
|
553
481
|
...toolSet,
|
|
554
|
-
...
|
|
482
|
+
...mcpToolSet
|
|
555
483
|
};
|
|
556
484
|
const providerOptions = input.reasoningLevel ? buildReasoningOptionsSync(input.model, input.reasoningLevel) : void 0;
|
|
557
485
|
const createStream = async () => {
|
|
@@ -569,11 +497,10 @@ async function stream(input) {
|
|
|
569
497
|
if (!input.retry || input.retry.maxAttempts === 0) {
|
|
570
498
|
return wrapModelStream(await createStream(), input);
|
|
571
499
|
}
|
|
572
|
-
return wrapModelStream(
|
|
573
|
-
async () => await createStream(),
|
|
574
|
-
input
|
|
575
|
-
|
|
576
|
-
), input);
|
|
500
|
+
return wrapModelStream(
|
|
501
|
+
await withRetry(async () => await createStream(), input.retry, input.abort),
|
|
502
|
+
input
|
|
503
|
+
);
|
|
577
504
|
}
|
|
578
505
|
async function streamOnce(input) {
|
|
579
506
|
return await stream({ ...input, retry: void 0 });
|
|
@@ -596,12 +523,6 @@ var LLM = Inference;
|
|
|
596
523
|
|
|
597
524
|
export {
|
|
598
525
|
buildToolSet,
|
|
599
|
-
isRetryableCategory,
|
|
600
|
-
parseRetryDelay,
|
|
601
|
-
LLMError,
|
|
602
|
-
isRetryable,
|
|
603
|
-
getRetryDelay,
|
|
604
|
-
getErrorCategory,
|
|
605
526
|
DEFAULT_RETRY_CONFIG,
|
|
606
527
|
createRetryState,
|
|
607
528
|
calculateDelay,
|
package/dist/context/index.js
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
import { T as TokenUsage, M as Message } from './messages-BYWGn8TY.js';
|
|
3
|
+
|
|
4
|
+
/** Agent status for UI display */
|
|
5
|
+
type AgentStatus = "idle" | "processing" | "thinking" | "reasoning" | "calling-tool" | "waiting-approval" | "error";
|
|
6
|
+
/** Approval request for UI */
|
|
7
|
+
interface ApprovalEvent {
|
|
8
|
+
id: string;
|
|
9
|
+
tool: string;
|
|
10
|
+
args: unknown;
|
|
11
|
+
description: string;
|
|
12
|
+
risk: "safe" | "moderate" | "dangerous";
|
|
13
|
+
}
|
|
14
|
+
/** Neutral turn-commit boundaries for runtime/durability integrations */
|
|
15
|
+
type AgentTurnBoundaryKind = "input-commit-start" | "input-commit-finish" | "intervention-commit-start" | "intervention-commit-finish" | "step-commit-start" | "step-commit-finish" | "output-commit-start" | "output-commit-finish";
|
|
16
|
+
/**
|
|
17
|
+
* Events emitted during agent execution
|
|
18
|
+
*
|
|
19
|
+
* These events are designed for UI consumption:
|
|
20
|
+
* - status: Overall agent state for status indicators
|
|
21
|
+
* - approval-request: User confirmation needed
|
|
22
|
+
* - progress: Step counts for progress bars
|
|
23
|
+
*/
|
|
24
|
+
type AgentEvent = {
|
|
25
|
+
type: "status";
|
|
26
|
+
status: AgentStatus;
|
|
27
|
+
} | {
|
|
28
|
+
type: "approval-request";
|
|
29
|
+
request: ApprovalEvent;
|
|
30
|
+
} | {
|
|
31
|
+
type: "approval-resolved";
|
|
32
|
+
id: string;
|
|
33
|
+
action: "allow" | "deny" | "remember";
|
|
34
|
+
} | {
|
|
35
|
+
type: "step-start";
|
|
36
|
+
step: number;
|
|
37
|
+
maxSteps: number;
|
|
38
|
+
} | {
|
|
39
|
+
type: "step-finish";
|
|
40
|
+
step: number;
|
|
41
|
+
usage?: TokenUsage;
|
|
42
|
+
finishReason?: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: "turn-boundary";
|
|
45
|
+
boundary: AgentTurnBoundaryKind;
|
|
46
|
+
step?: number;
|
|
47
|
+
messageRole?: Message["role"];
|
|
48
|
+
pendingToolCallCount?: number;
|
|
49
|
+
} | {
|
|
50
|
+
type: "message";
|
|
51
|
+
message: Message;
|
|
52
|
+
} | {
|
|
53
|
+
type: "text-start";
|
|
54
|
+
} | {
|
|
55
|
+
type: "text-delta";
|
|
56
|
+
text: string;
|
|
57
|
+
} | {
|
|
58
|
+
type: "text-end";
|
|
59
|
+
} | {
|
|
60
|
+
type: "reasoning-start";
|
|
61
|
+
id: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: "reasoning-delta";
|
|
64
|
+
id: string;
|
|
65
|
+
text: string;
|
|
66
|
+
} | {
|
|
67
|
+
type: "reasoning-end";
|
|
68
|
+
id: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: "tool-start";
|
|
71
|
+
toolName: string;
|
|
72
|
+
toolCallId: string;
|
|
73
|
+
input: unknown;
|
|
74
|
+
} | {
|
|
75
|
+
type: "tool-result";
|
|
76
|
+
toolName: string;
|
|
77
|
+
toolCallId: string;
|
|
78
|
+
result: unknown;
|
|
79
|
+
} | {
|
|
80
|
+
type: "tool-error";
|
|
81
|
+
toolName: string;
|
|
82
|
+
toolCallId: string;
|
|
83
|
+
error: string;
|
|
84
|
+
} | {
|
|
85
|
+
type: "computer-call";
|
|
86
|
+
callId: string;
|
|
87
|
+
action: unknown;
|
|
88
|
+
pendingSafetyChecks?: unknown[];
|
|
89
|
+
} | {
|
|
90
|
+
type: "computer-result";
|
|
91
|
+
callId: string;
|
|
92
|
+
result: unknown;
|
|
93
|
+
} | {
|
|
94
|
+
type: "intervention-applied";
|
|
95
|
+
id: string;
|
|
96
|
+
message: string;
|
|
97
|
+
} | {
|
|
98
|
+
type: "doom-loop";
|
|
99
|
+
toolName: string;
|
|
100
|
+
repeatCount: number;
|
|
101
|
+
} | {
|
|
102
|
+
type: "context-overflow";
|
|
103
|
+
inputTokens: number;
|
|
104
|
+
limit: number;
|
|
105
|
+
} | {
|
|
106
|
+
type: "turn-summary";
|
|
107
|
+
turnId: string;
|
|
108
|
+
files: Array<{
|
|
109
|
+
path: string;
|
|
110
|
+
type: "created" | "modified" | "deleted" | "unchanged";
|
|
111
|
+
additions: number;
|
|
112
|
+
deletions: number;
|
|
113
|
+
}>;
|
|
114
|
+
additions: number;
|
|
115
|
+
deletions: number;
|
|
116
|
+
} | {
|
|
117
|
+
type: "retry";
|
|
118
|
+
attempt: number;
|
|
119
|
+
delayMs: number;
|
|
120
|
+
error: Error;
|
|
121
|
+
} | {
|
|
122
|
+
type: "error";
|
|
123
|
+
error: Error;
|
|
124
|
+
} | {
|
|
125
|
+
type: "complete";
|
|
126
|
+
usage?: TokenUsage;
|
|
127
|
+
output?: string;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Step-processing result - what happens after reducing one streamed step
|
|
131
|
+
*/
|
|
132
|
+
type StepProcessingResult = "continue" | "stop" | "compact";
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated Use `StepProcessingResult`.
|
|
135
|
+
*/
|
|
136
|
+
type ProcessorResult = StepProcessingResult;
|
|
137
|
+
/**
|
|
138
|
+
* Stream input for model inference
|
|
139
|
+
*/
|
|
140
|
+
interface StreamInput {
|
|
141
|
+
sessionID: string;
|
|
142
|
+
model: ai.LanguageModel;
|
|
143
|
+
system: string[];
|
|
144
|
+
messages: ai.ModelMessage[];
|
|
145
|
+
abort: AbortSignal;
|
|
146
|
+
tools: Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export type { AgentEvent as A, ProcessorResult as P, StepProcessingResult as S, AgentStatus as a, AgentTurnBoundaryKind as b, ApprovalEvent as c, StreamInput as d };
|