@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,7 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApprovalHandler
|
|
3
|
+
} from "./chunk-5ARZJWD2.js";
|
|
4
|
+
import {
|
|
5
|
+
extractModelId,
|
|
6
|
+
extractProvider
|
|
7
|
+
} from "./chunk-I6PKJ7XQ.js";
|
|
8
|
+
|
|
1
9
|
// src/middleware/runner.ts
|
|
2
10
|
function isBlockedModelCall(value) {
|
|
3
11
|
return "block" in value && value.block === true;
|
|
4
12
|
}
|
|
13
|
+
function logMiddlewareWarning(middlewareName, hook, error) {
|
|
14
|
+
console.warn(
|
|
15
|
+
`[middleware] "${middlewareName}" ${hook} error:`,
|
|
16
|
+
error instanceof Error ? error.message : String(error)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
5
19
|
var MiddlewareRunner = class {
|
|
6
20
|
stack;
|
|
7
21
|
constructor(middleware = []) {
|
|
@@ -59,10 +73,7 @@ var MiddlewareRunner = class {
|
|
|
59
73
|
current = next;
|
|
60
74
|
}
|
|
61
75
|
} catch (err) {
|
|
62
|
-
|
|
63
|
-
`[middleware] "${mw.name}" model.chunk error:`,
|
|
64
|
-
err instanceof Error ? err.message : String(err)
|
|
65
|
-
);
|
|
76
|
+
logMiddlewareWarning(mw.name, "model.chunk", err);
|
|
66
77
|
}
|
|
67
78
|
}
|
|
68
79
|
return current ?? void 0;
|
|
@@ -81,10 +92,7 @@ var MiddlewareRunner = class {
|
|
|
81
92
|
current = next;
|
|
82
93
|
}
|
|
83
94
|
} catch (err) {
|
|
84
|
-
|
|
85
|
-
`[middleware] "${mw.name}" model.output error:`,
|
|
86
|
-
err instanceof Error ? err.message : String(err)
|
|
87
|
-
);
|
|
95
|
+
logMiddlewareWarning(mw.name, "model.output", err);
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
return current;
|
|
@@ -134,10 +142,7 @@ var MiddlewareRunner = class {
|
|
|
134
142
|
try {
|
|
135
143
|
current = await mw.afterToolCall(tool, args, current, ctx);
|
|
136
144
|
} catch (err) {
|
|
137
|
-
|
|
138
|
-
`[middleware] "${mw.name}" afterToolCall error:`,
|
|
139
|
-
err instanceof Error ? err.message : String(err)
|
|
140
|
-
);
|
|
145
|
+
logMiddlewareWarning(mw.name, "afterToolCall", err);
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
return current;
|
|
@@ -164,10 +169,7 @@ var MiddlewareRunner = class {
|
|
|
164
169
|
sections.push(result);
|
|
165
170
|
}
|
|
166
171
|
} catch (err) {
|
|
167
|
-
|
|
168
|
-
`[middleware] "${mw.name}" promptSections error:`,
|
|
169
|
-
err instanceof Error ? err.message : String(err)
|
|
170
|
-
);
|
|
172
|
+
logMiddlewareWarning(mw.name, "promptSections", err);
|
|
171
173
|
}
|
|
172
174
|
}
|
|
173
175
|
return sections;
|
|
@@ -218,10 +220,7 @@ var MiddlewareRunner = class {
|
|
|
218
220
|
try {
|
|
219
221
|
await mw.onChatStart(sessionId, message);
|
|
220
222
|
} catch (err) {
|
|
221
|
-
|
|
222
|
-
`[middleware] "${mw.name}" onChatStart error:`,
|
|
223
|
-
err instanceof Error ? err.message : String(err)
|
|
224
|
-
);
|
|
223
|
+
logMiddlewareWarning(mw.name, "onChatStart", err);
|
|
225
224
|
}
|
|
226
225
|
}
|
|
227
226
|
}
|
|
@@ -240,230 +239,12 @@ var MiddlewareRunner = class {
|
|
|
240
239
|
try {
|
|
241
240
|
await mw.onChatEnd(sessionId, result);
|
|
242
241
|
} catch (err) {
|
|
243
|
-
|
|
244
|
-
`[middleware] "${mw.name}" onChatEnd error:`,
|
|
245
|
-
err instanceof Error ? err.message : String(err)
|
|
246
|
-
);
|
|
242
|
+
logMiddlewareWarning(mw.name, "onChatEnd", err);
|
|
247
243
|
}
|
|
248
244
|
}
|
|
249
245
|
}
|
|
250
246
|
};
|
|
251
247
|
|
|
252
|
-
// src/safety/approval/risk.ts
|
|
253
|
-
var DEFAULT_TOOL_RISKS = {
|
|
254
|
-
read: "safe",
|
|
255
|
-
read_file: "safe",
|
|
256
|
-
grep: "safe",
|
|
257
|
-
glob: "safe",
|
|
258
|
-
list_dir: "safe",
|
|
259
|
-
invoke_agent: "safe",
|
|
260
|
-
wait_agent: "safe",
|
|
261
|
-
close_agent: "safe",
|
|
262
|
-
skill: "safe",
|
|
263
|
-
skill_resource: "safe",
|
|
264
|
-
write: "moderate",
|
|
265
|
-
write_file: "moderate",
|
|
266
|
-
edit: "moderate",
|
|
267
|
-
edit_file: "moderate",
|
|
268
|
-
create_file: "moderate",
|
|
269
|
-
bash: "dangerous",
|
|
270
|
-
shell: "dangerous",
|
|
271
|
-
delete_file: "dangerous",
|
|
272
|
-
remove: "dangerous"
|
|
273
|
-
};
|
|
274
|
-
function getToolRisk(tool, customRisks) {
|
|
275
|
-
if (customRisks?.[tool]) {
|
|
276
|
-
return customRisks[tool];
|
|
277
|
-
}
|
|
278
|
-
if (DEFAULT_TOOL_RISKS[tool]) {
|
|
279
|
-
return DEFAULT_TOOL_RISKS[tool];
|
|
280
|
-
}
|
|
281
|
-
return "moderate";
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// src/safety/approval/errors.ts
|
|
285
|
-
var ApprovalDeniedError = class extends Error {
|
|
286
|
-
constructor(tool, args, message) {
|
|
287
|
-
super(message || `Operation denied: ${tool}`);
|
|
288
|
-
this.tool = tool;
|
|
289
|
-
this.args = args;
|
|
290
|
-
this.name = "ApprovalDeniedError";
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
var ApprovalTimeoutError = class extends Error {
|
|
294
|
-
constructor(tool, timeoutMs) {
|
|
295
|
-
super(`Approval timeout after ${timeoutMs}ms for: ${tool}`);
|
|
296
|
-
this.tool = tool;
|
|
297
|
-
this.timeoutMs = timeoutMs;
|
|
298
|
-
this.name = "ApprovalTimeoutError";
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
// src/safety/approval/patterns.ts
|
|
303
|
-
function matchApprovalPattern(pattern, value) {
|
|
304
|
-
const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
305
|
-
return new RegExp(`^${regex}$`, "i").test(value);
|
|
306
|
-
}
|
|
307
|
-
function extractApprovalPatterns(tool, args) {
|
|
308
|
-
if (!args || typeof args !== "object") {
|
|
309
|
-
return [tool];
|
|
310
|
-
}
|
|
311
|
-
const record = args;
|
|
312
|
-
if ("path" in record && typeof record.path === "string" || "filePath" in record && typeof record.filePath === "string") {
|
|
313
|
-
const path = record.path ?? record.filePath;
|
|
314
|
-
const dir = path.substring(0, path.lastIndexOf("/") + 1);
|
|
315
|
-
return [dir ? `${dir}*` : path];
|
|
316
|
-
}
|
|
317
|
-
if ("command" in record && typeof record.command === "string") {
|
|
318
|
-
const command = record.command.split(/\s+/)[0];
|
|
319
|
-
return [command];
|
|
320
|
-
}
|
|
321
|
-
if ("pattern" in record && typeof record.pattern === "string") {
|
|
322
|
-
return [record.pattern];
|
|
323
|
-
}
|
|
324
|
-
return [tool];
|
|
325
|
-
}
|
|
326
|
-
function describeApprovalOperation(tool, args) {
|
|
327
|
-
if (!args || typeof args !== "object") {
|
|
328
|
-
return `Execute ${tool}`;
|
|
329
|
-
}
|
|
330
|
-
const record = args;
|
|
331
|
-
switch (tool) {
|
|
332
|
-
case "read":
|
|
333
|
-
case "read_file":
|
|
334
|
-
return `Read file: ${record.path ?? record.filePath}`;
|
|
335
|
-
case "write":
|
|
336
|
-
case "write_file":
|
|
337
|
-
case "create_file":
|
|
338
|
-
return `Write file: ${record.path ?? record.filePath}`;
|
|
339
|
-
case "edit":
|
|
340
|
-
case "edit_file":
|
|
341
|
-
return `Edit file: ${record.path ?? record.filePath}`;
|
|
342
|
-
case "delete_file":
|
|
343
|
-
case "remove":
|
|
344
|
-
return `Delete: ${record.path}`;
|
|
345
|
-
case "bash":
|
|
346
|
-
case "shell": {
|
|
347
|
-
const command = String(record.command);
|
|
348
|
-
return `Run command: ${command.slice(0, 100)}${command.length > 100 ? "..." : ""}`;
|
|
349
|
-
}
|
|
350
|
-
case "grep":
|
|
351
|
-
return `Search for: ${record.pattern}`;
|
|
352
|
-
case "glob":
|
|
353
|
-
return `Find files: ${record.pattern}`;
|
|
354
|
-
default:
|
|
355
|
-
return `${tool}(${JSON.stringify(args).slice(0, 50)}...)`;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// src/safety/approval/handler.ts
|
|
360
|
-
var requestCounter = 0;
|
|
361
|
-
function findMatchingRule(rules, tool, patterns) {
|
|
362
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
363
|
-
const rule = rules[index];
|
|
364
|
-
const toolMatches = rule.tool === "*" || matchApprovalPattern(rule.tool, tool);
|
|
365
|
-
const patternMatches = patterns.some(
|
|
366
|
-
(pattern) => matchApprovalPattern(rule.pattern, pattern)
|
|
367
|
-
);
|
|
368
|
-
if (toolMatches && patternMatches) {
|
|
369
|
-
return rule;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return void 0;
|
|
373
|
-
}
|
|
374
|
-
function createApprovalHandler(config = {}) {
|
|
375
|
-
const {
|
|
376
|
-
defaultAction = "ask",
|
|
377
|
-
timeout = 5 * 60 * 1e3,
|
|
378
|
-
onRequest
|
|
379
|
-
} = config;
|
|
380
|
-
const rules = [...config.rules ?? []];
|
|
381
|
-
const pending = /* @__PURE__ */ new Map();
|
|
382
|
-
async function request(sessionId, tool, args, customRisks) {
|
|
383
|
-
const risk = getToolRisk(tool, customRisks);
|
|
384
|
-
const patterns = extractApprovalPatterns(tool, args);
|
|
385
|
-
const matchingRule = findMatchingRule(rules, tool, patterns);
|
|
386
|
-
if (matchingRule) {
|
|
387
|
-
if (matchingRule.action === "allow") {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
throw new ApprovalDeniedError(
|
|
391
|
-
tool,
|
|
392
|
-
args,
|
|
393
|
-
`Denied by rule: ${matchingRule.pattern}`
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
if (risk === "safe" && defaultAction !== "deny") {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (!onRequest) {
|
|
400
|
-
if (defaultAction === "allow") {
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
if (defaultAction === "deny") {
|
|
404
|
-
throw new ApprovalDeniedError(tool, args);
|
|
405
|
-
}
|
|
406
|
-
throw new ApprovalDeniedError(tool, args, "No approval handler configured");
|
|
407
|
-
}
|
|
408
|
-
const id = `approval-${++requestCounter}-${Date.now()}`;
|
|
409
|
-
const requestData = {
|
|
410
|
-
id,
|
|
411
|
-
sessionId,
|
|
412
|
-
tool,
|
|
413
|
-
args,
|
|
414
|
-
description: describeApprovalOperation(tool, args),
|
|
415
|
-
risk,
|
|
416
|
-
patterns,
|
|
417
|
-
timestamp: Date.now()
|
|
418
|
-
};
|
|
419
|
-
const action = await Promise.race([
|
|
420
|
-
new Promise((resolve, reject) => {
|
|
421
|
-
pending.set(id, { resolve, reject });
|
|
422
|
-
onRequest(requestData).then(resolve).catch(reject).finally(() => pending.delete(id));
|
|
423
|
-
}),
|
|
424
|
-
new Promise((_, reject) => {
|
|
425
|
-
setTimeout(() => {
|
|
426
|
-
pending.delete(id);
|
|
427
|
-
reject(new ApprovalTimeoutError(tool, timeout));
|
|
428
|
-
}, timeout);
|
|
429
|
-
})
|
|
430
|
-
]);
|
|
431
|
-
switch (action) {
|
|
432
|
-
case "allow":
|
|
433
|
-
return;
|
|
434
|
-
case "deny":
|
|
435
|
-
throw new ApprovalDeniedError(tool, args);
|
|
436
|
-
case "remember":
|
|
437
|
-
for (const pattern of patterns) {
|
|
438
|
-
rules.push({ pattern, tool, action: "allow" });
|
|
439
|
-
}
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function cancelAll(reason) {
|
|
444
|
-
for (const [id, { reject }] of pending) {
|
|
445
|
-
reject(new Error(reason ?? "Cancelled"));
|
|
446
|
-
pending.delete(id);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
function addRule(rule) {
|
|
450
|
-
rules.push(rule);
|
|
451
|
-
}
|
|
452
|
-
function getRules() {
|
|
453
|
-
return rules;
|
|
454
|
-
}
|
|
455
|
-
function clearSessionRules() {
|
|
456
|
-
rules.length = config.rules?.length ?? 0;
|
|
457
|
-
}
|
|
458
|
-
return {
|
|
459
|
-
request,
|
|
460
|
-
cancelAll,
|
|
461
|
-
addRule,
|
|
462
|
-
getRules,
|
|
463
|
-
clearSessionRules
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
|
|
467
248
|
// src/middleware/approval.ts
|
|
468
249
|
function approvalMiddleware(config = {}) {
|
|
469
250
|
const handler = createApprovalHandler(config);
|
|
@@ -753,28 +534,48 @@ async function createAndRegisterProvider(spanProcessor, serviceName) {
|
|
|
753
534
|
}
|
|
754
535
|
|
|
755
536
|
// src/middleware/prompt-cache/cache.ts
|
|
537
|
+
function detectCacheProvider(input) {
|
|
538
|
+
const provider = extractProvider(input.model);
|
|
539
|
+
if (provider) {
|
|
540
|
+
const p = provider.toLowerCase();
|
|
541
|
+
if (p === "anthropic") return "anthropic";
|
|
542
|
+
if (p === "openai") return "openai";
|
|
543
|
+
if (p === "google") return "google";
|
|
544
|
+
}
|
|
545
|
+
const modelId = extractModelId(input.model);
|
|
546
|
+
if (/claude/i.test(modelId)) return "anthropic";
|
|
547
|
+
return "unknown";
|
|
548
|
+
}
|
|
756
549
|
var MAX_ANTHROPIC_BREAKPOINTS = 4;
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
550
|
+
function applyAnthropicCache(input, ttl, maxMsgBreakpoints) {
|
|
551
|
+
const hasSystem = input.system.some((s) => s.length > 0);
|
|
552
|
+
if (hasSystem) {
|
|
553
|
+
input.systemMessages = buildAnthropicSystemMessages(input.system, ttl);
|
|
554
|
+
}
|
|
555
|
+
if (maxMsgBreakpoints > 0) {
|
|
556
|
+
const breakpointIndices = findMessageBreakpointIndices(
|
|
557
|
+
input.messages,
|
|
558
|
+
maxMsgBreakpoints
|
|
559
|
+
);
|
|
560
|
+
const cacheControl = buildAnthropicCacheControl(ttl);
|
|
561
|
+
for (const idx of breakpointIndices) {
|
|
562
|
+
const msg = input.messages[idx];
|
|
563
|
+
msg.providerOptions = {
|
|
564
|
+
...msg.providerOptions,
|
|
565
|
+
...cacheControl
|
|
566
|
+
};
|
|
766
567
|
}
|
|
767
568
|
}
|
|
768
|
-
return
|
|
569
|
+
return input;
|
|
769
570
|
}
|
|
770
|
-
function
|
|
571
|
+
function buildAnthropicCacheControl(ttl) {
|
|
771
572
|
return {
|
|
772
573
|
anthropic: {
|
|
773
574
|
cacheControl: { type: "ephemeral", ttl }
|
|
774
575
|
}
|
|
775
576
|
};
|
|
776
577
|
}
|
|
777
|
-
function
|
|
578
|
+
function buildAnthropicSystemMessages(system, ttl) {
|
|
778
579
|
const filtered = system.filter(Boolean);
|
|
779
580
|
if (filtered.length === 0) return [];
|
|
780
581
|
return filtered.map((content, i) => {
|
|
@@ -784,7 +585,7 @@ function buildCachedSystemMessages(system, ttl) {
|
|
|
784
585
|
content
|
|
785
586
|
};
|
|
786
587
|
if (isLast) {
|
|
787
|
-
msg.providerOptions =
|
|
588
|
+
msg.providerOptions = buildAnthropicCacheControl(ttl);
|
|
788
589
|
}
|
|
789
590
|
return msg;
|
|
790
591
|
});
|
|
@@ -800,37 +601,28 @@ function findMessageBreakpointIndices(messages, count) {
|
|
|
800
601
|
}
|
|
801
602
|
return indices;
|
|
802
603
|
}
|
|
604
|
+
var DEFAULT_TTL = "5m";
|
|
605
|
+
var DEFAULT_MESSAGE_BREAKPOINTS = 1;
|
|
803
606
|
function promptCacheMiddleware(config) {
|
|
804
607
|
const ttl = config?.ttl ?? DEFAULT_TTL;
|
|
805
608
|
const maxMsgBreakpoints = Math.min(
|
|
806
609
|
config?.messageBreakpoints ?? DEFAULT_MESSAGE_BREAKPOINTS,
|
|
807
610
|
MAX_ANTHROPIC_BREAKPOINTS - 1
|
|
808
|
-
// Reserve 1 for system
|
|
809
611
|
);
|
|
810
612
|
return {
|
|
811
613
|
name: "prompt-cache",
|
|
812
614
|
model: {
|
|
813
615
|
async input(input, _ctx) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
);
|
|
824
|
-
const cacheControl = buildCacheControl(ttl);
|
|
825
|
-
for (const idx of breakpointIndices) {
|
|
826
|
-
const msg = input.messages[idx];
|
|
827
|
-
msg.providerOptions = {
|
|
828
|
-
...msg.providerOptions,
|
|
829
|
-
...cacheControl
|
|
830
|
-
};
|
|
831
|
-
}
|
|
616
|
+
const provider = detectCacheProvider(input);
|
|
617
|
+
switch (provider) {
|
|
618
|
+
case "anthropic":
|
|
619
|
+
return applyAnthropicCache(input, ttl, maxMsgBreakpoints);
|
|
620
|
+
// OpenAI caches prefixes automatically — no client action needed.
|
|
621
|
+
// case "openai":
|
|
622
|
+
// return applyOpenAICache(input);
|
|
623
|
+
default:
|
|
624
|
+
return;
|
|
832
625
|
}
|
|
833
|
-
return input;
|
|
834
626
|
}
|
|
835
627
|
}
|
|
836
628
|
};
|
|
@@ -840,10 +632,6 @@ export {
|
|
|
840
632
|
MiddlewareRunner,
|
|
841
633
|
otelMiddleware,
|
|
842
634
|
createTelemetryConfig,
|
|
843
|
-
getToolRisk,
|
|
844
|
-
ApprovalDeniedError,
|
|
845
|
-
ApprovalTimeoutError,
|
|
846
|
-
createApprovalHandler,
|
|
847
635
|
approvalMiddleware,
|
|
848
636
|
promptCacheMiddleware
|
|
849
637
|
};
|
|
@@ -34,7 +34,7 @@ function normalizeToolReplayPolicy(policy, fileOps) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// src/tool/truncation.ts
|
|
37
|
-
import * as
|
|
37
|
+
import * as fsSync from "fs";
|
|
38
38
|
import * as path from "path";
|
|
39
39
|
import * as os from "os";
|
|
40
40
|
import * as crypto from "crypto";
|
|
@@ -55,8 +55,11 @@ function truncateOutput(output, options = {}) {
|
|
|
55
55
|
}
|
|
56
56
|
const hash = crypto.createHash("sha256").update(output).digest("hex").slice(0, 16);
|
|
57
57
|
const outputPath = path.join(TRUNCATE_DIR, `output-${hash}.txt`);
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
try {
|
|
59
|
+
fsSync.mkdirSync(TRUNCATE_DIR, { recursive: true });
|
|
60
|
+
fsSync.writeFileSync(outputPath, output, "utf-8");
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
60
63
|
let truncated;
|
|
61
64
|
if (lines.length > maxLines) {
|
|
62
65
|
const keepLines = Math.floor(maxLines / 2);
|
|
@@ -71,9 +74,10 @@ function truncateOutput(output, options = {}) {
|
|
|
71
74
|
...lastPart
|
|
72
75
|
].join("\n");
|
|
73
76
|
} else {
|
|
77
|
+
const buf = Buffer.from(output, "utf-8");
|
|
74
78
|
const keepBytes = Math.floor(maxBytes / 2);
|
|
75
|
-
const start =
|
|
76
|
-
const end =
|
|
79
|
+
const start = buf.subarray(0, keepBytes).toString("utf-8");
|
|
80
|
+
const end = buf.subarray(buf.length - keepBytes).toString("utf-8");
|
|
77
81
|
const omittedBytes = bytes - keepBytes * 2;
|
|
78
82
|
truncated = `${start}
|
|
79
83
|
... (${omittedBytes} bytes omitted, full output saved to ${outputPath}) ...
|
|
@@ -111,8 +115,9 @@ var Tool;
|
|
|
111
115
|
);
|
|
112
116
|
const originalExecute = toolInfo.execute;
|
|
113
117
|
const execute = async (params, ctx) => {
|
|
118
|
+
let validated;
|
|
114
119
|
try {
|
|
115
|
-
toolInfo.parameters.parse(params);
|
|
120
|
+
validated = toolInfo.parameters.parse(params);
|
|
116
121
|
} catch (error) {
|
|
117
122
|
if (error instanceof z.ZodError && toolInfo.formatValidationError) {
|
|
118
123
|
throw new Error(toolInfo.formatValidationError(error), {
|
|
@@ -125,7 +130,7 @@ Please rewrite the input so it satisfies the expected schema.`,
|
|
|
125
130
|
{ cause: error }
|
|
126
131
|
);
|
|
127
132
|
}
|
|
128
|
-
const result = await originalExecute(
|
|
133
|
+
const result = await originalExecute(validated, ctx);
|
|
129
134
|
if (result.metadata.truncated !== void 0) {
|
|
130
135
|
return result;
|
|
131
136
|
}
|
|
@@ -149,10 +154,6 @@ Please rewrite the input so it satisfies the expected schema.`,
|
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
156
|
Tool2.define = define;
|
|
152
|
-
function defineSimple(id, config) {
|
|
153
|
-
return define(id, config);
|
|
154
|
-
}
|
|
155
|
-
Tool2.defineSimple = defineSimple;
|
|
156
157
|
})(Tool || (Tool = {}));
|
|
157
158
|
function defineTool(definition) {
|
|
158
159
|
return Tool.define(definition.id, {
|
|
@@ -508,6 +508,9 @@ async function createGitStyleDiffPlaceholder() {
|
|
|
508
508
|
}
|
|
509
509
|
|
|
510
510
|
// src/tracking/turn-tracker/tracker.ts
|
|
511
|
+
function logTurnTrackerWarning(message) {
|
|
512
|
+
console.warn(message);
|
|
513
|
+
}
|
|
511
514
|
var TurnChangeTracker = class {
|
|
512
515
|
config;
|
|
513
516
|
currentTurn = null;
|
|
@@ -584,7 +587,7 @@ var TurnChangeTracker = class {
|
|
|
584
587
|
return false;
|
|
585
588
|
}
|
|
586
589
|
if (this.currentTurn.baselines.size >= this.config.maxTrackedFiles) {
|
|
587
|
-
|
|
590
|
+
logTurnTrackerWarning(
|
|
588
591
|
`[TurnTracker] Max tracked files (${this.config.maxTrackedFiles}) reached, skipping: ${filePath}`
|
|
589
592
|
);
|
|
590
593
|
return false;
|
|
@@ -487,9 +487,10 @@ var SkillRegistry = class {
|
|
|
487
487
|
for (const skill of this.skills.values()) {
|
|
488
488
|
lines.push("");
|
|
489
489
|
lines.push(`<skill name="${skill.name}" scope="${skill.scope}">`);
|
|
490
|
-
lines.push(skill.description);
|
|
490
|
+
lines.push(` <description>${skill.description}</description>`);
|
|
491
|
+
lines.push(` <file>${skill.filePath}</file>`);
|
|
491
492
|
if (skill.dependencies && skill.dependencies.length > 0) {
|
|
492
|
-
lines.push(`
|
|
493
|
+
lines.push(` <depends-on>${skill.dependencies.join(", ")}</depends-on>`);
|
|
493
494
|
}
|
|
494
495
|
lines.push("</skill>");
|
|
495
496
|
}
|