@cuylabs/agent-core 0.6.0 → 0.8.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/README.md +5 -1
- package/dist/{builder-BKkipazh.d.ts → builder-UpOWQMW3.d.ts} +2 -2
- package/dist/{chunk-3C4VKG4P.js → chunk-4BDA7DQY.js} +273 -807
- package/dist/chunk-7VKQ4WPB.js +73 -0
- package/dist/chunk-BFM2YHNM.js +222 -0
- package/dist/chunk-CAA7FHIH.js +280 -0
- package/dist/chunk-KUVSERLJ.js +50 -0
- package/dist/chunk-N6HWIEEA.js +423 -0
- package/dist/chunk-N7P4PN3O.js +84 -0
- package/dist/{chunk-QWFMX226.js → chunk-RFEKJKTO.js} +252 -13
- package/dist/chunk-RZITT45F.js +202 -0
- package/dist/{chunk-X635CM2F.js → chunk-SQU2AJHO.js} +1 -1
- package/dist/chunk-VNQBHPCT.js +398 -0
- package/dist/{chunk-QAQADS4X.js → chunk-WWYYNWEW.js} +2 -1
- package/dist/{chunk-O2ZCFQL6.js → chunk-YSLSEQ6B.js} +105 -220
- package/dist/context/index.js +1 -1
- package/dist/errors/index.d.ts +11 -0
- package/dist/errors/index.js +16 -0
- package/dist/events-CE72w8W4.d.ts +149 -0
- package/dist/host/index.d.ts +45 -0
- package/dist/host/index.js +8 -0
- package/dist/{index-DZQJD_hp.d.ts → index-CWSchSql.d.ts} +42 -51
- package/dist/index.d.ts +98 -190
- package/dist/index.js +476 -939
- package/dist/inference/index.d.ts +62 -0
- package/dist/inference/index.js +27 -0
- package/dist/llm-error-D93FNNLY.d.ts +32 -0
- package/dist/middleware/index.d.ts +246 -5
- package/dist/middleware/index.js +7 -3
- package/dist/models/index.d.ts +226 -3
- package/dist/models/index.js +41 -3
- package/dist/presets/index.d.ts +53 -0
- package/dist/presets/index.js +28 -0
- package/dist/prompt/index.d.ts +12 -7
- package/dist/reasoning/index.d.ts +53 -8
- package/dist/reasoning/index.js +2 -7
- package/dist/{registry-CuRWWtcT.d.ts → registry-DwYqsQkX.d.ts} +1 -1
- package/dist/{runner-G1wxEgac.d.ts → runner-e2YRcUoX.d.ts} +82 -148
- package/dist/runtime/index.d.ts +44 -7
- package/dist/runtime/index.js +16 -5
- package/dist/safety/index.d.ts +38 -0
- package/dist/safety/index.js +12 -0
- package/dist/scope/index.d.ts +10 -0
- package/dist/scope/index.js +14 -0
- package/dist/{session-manager-Uawm2Le7.d.ts → session-manager-B_CWGTsl.d.ts} +1 -1
- package/dist/signal/index.d.ts +28 -0
- package/dist/signal/index.js +6 -0
- package/dist/skill/index.d.ts +8 -5
- package/dist/storage/index.d.ts +2 -2
- package/dist/sub-agent/index.d.ts +17 -8
- package/dist/tool/index.d.ts +9 -4
- package/dist/tool/index.js +4 -3
- package/dist/tool-BHbyUAy3.d.ts +150 -0
- package/dist/{tool-DYp6-cC3.d.ts → tool-DLXAR9Ce.d.ts} +5 -99
- package/dist/tracking/index.d.ts +3 -1
- package/dist/{tool-pFAnJc5Y.d.ts → types-BfNpU8NS.d.ts} +1 -150
- package/dist/types-BnpEOYV-.d.ts +50 -0
- package/dist/types-CHiPh8U2.d.ts +100 -0
- package/dist/types-CQL-SvTn.d.ts +29 -0
- package/dist/types-CWm-7rvB.d.ts +55 -0
- package/dist/types-KKDrdU9Y.d.ts +325 -0
- package/dist/{resolver-DOfZ-xuk.d.ts → types-QA4WhEfz.d.ts} +1 -117
- package/dist/types-QKHHQLLq.d.ts +336 -0
- package/dist/types-YuWV4ag7.d.ts +72 -0
- package/package.json +74 -8
- package/dist/capabilities/index.d.ts +0 -97
- package/dist/capabilities/index.js +0 -46
- package/dist/chunk-6TDTQJ4P.js +0 -116
- package/dist/chunk-FG4MD5MU.js +0 -54
- package/dist/config-D2xeGEHK.d.ts +0 -52
- package/dist/identifiers-BLUxFqV_.d.ts +0 -12
- package/dist/index-ipP3_ztp.d.ts +0 -198
- package/dist/network-D76DS5ot.d.ts +0 -5
- package/dist/types-BWo810L_.d.ts +0 -648
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApprovalHandler
|
|
3
|
+
} from "./chunk-BFM2YHNM.js";
|
|
4
|
+
import {
|
|
5
|
+
getModelId,
|
|
6
|
+
getProviderId
|
|
7
|
+
} from "./chunk-DWYX7ASF.js";
|
|
8
|
+
|
|
1
9
|
// src/middleware/runner.ts
|
|
2
10
|
function isBlockedModelCall(value) {
|
|
3
11
|
return "block" in value && value.block === true;
|
|
@@ -249,221 +257,6 @@ var MiddlewareRunner = class {
|
|
|
249
257
|
}
|
|
250
258
|
};
|
|
251
259
|
|
|
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
260
|
// src/middleware/approval.ts
|
|
468
261
|
function approvalMiddleware(config = {}) {
|
|
469
262
|
const handler = createApprovalHandler(config);
|
|
@@ -752,13 +545,105 @@ async function createAndRegisterProvider(spanProcessor, serviceName) {
|
|
|
752
545
|
return provider;
|
|
753
546
|
}
|
|
754
547
|
|
|
548
|
+
// src/middleware/prompt-cache/cache.ts
|
|
549
|
+
function detectCacheProvider(input) {
|
|
550
|
+
const provider = getProviderId(input.model);
|
|
551
|
+
if (provider) {
|
|
552
|
+
const p = provider.toLowerCase();
|
|
553
|
+
if (p === "anthropic") return "anthropic";
|
|
554
|
+
if (p === "openai") return "openai";
|
|
555
|
+
if (p === "google") return "google";
|
|
556
|
+
}
|
|
557
|
+
const modelId = getModelId(input.model);
|
|
558
|
+
if (/claude/i.test(modelId)) return "anthropic";
|
|
559
|
+
return "unknown";
|
|
560
|
+
}
|
|
561
|
+
var MAX_ANTHROPIC_BREAKPOINTS = 4;
|
|
562
|
+
function applyAnthropicCache(input, ttl, maxMsgBreakpoints) {
|
|
563
|
+
const hasSystem = input.system.some((s) => s.length > 0);
|
|
564
|
+
if (hasSystem) {
|
|
565
|
+
input.systemMessages = buildAnthropicSystemMessages(input.system, ttl);
|
|
566
|
+
}
|
|
567
|
+
if (maxMsgBreakpoints > 0) {
|
|
568
|
+
const breakpointIndices = findMessageBreakpointIndices(
|
|
569
|
+
input.messages,
|
|
570
|
+
maxMsgBreakpoints
|
|
571
|
+
);
|
|
572
|
+
const cacheControl = buildAnthropicCacheControl(ttl);
|
|
573
|
+
for (const idx of breakpointIndices) {
|
|
574
|
+
const msg = input.messages[idx];
|
|
575
|
+
msg.providerOptions = {
|
|
576
|
+
...msg.providerOptions,
|
|
577
|
+
...cacheControl
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return input;
|
|
582
|
+
}
|
|
583
|
+
function buildAnthropicCacheControl(ttl) {
|
|
584
|
+
return {
|
|
585
|
+
anthropic: {
|
|
586
|
+
cacheControl: { type: "ephemeral", ttl }
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function buildAnthropicSystemMessages(system, ttl) {
|
|
591
|
+
const filtered = system.filter(Boolean);
|
|
592
|
+
if (filtered.length === 0) return [];
|
|
593
|
+
return filtered.map((content, i) => {
|
|
594
|
+
const isLast = i === filtered.length - 1;
|
|
595
|
+
const msg = {
|
|
596
|
+
role: "system",
|
|
597
|
+
content
|
|
598
|
+
};
|
|
599
|
+
if (isLast) {
|
|
600
|
+
msg.providerOptions = buildAnthropicCacheControl(ttl);
|
|
601
|
+
}
|
|
602
|
+
return msg;
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function findMessageBreakpointIndices(messages, count) {
|
|
606
|
+
if (count <= 0 || messages.length < 2) return [];
|
|
607
|
+
const indices = [];
|
|
608
|
+
for (let i = messages.length - 2; i >= 0 && indices.length < count; i--) {
|
|
609
|
+
const msg = messages[i];
|
|
610
|
+
if (msg.role === "user" || msg.role === "assistant") {
|
|
611
|
+
indices.push(i);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return indices;
|
|
615
|
+
}
|
|
616
|
+
var DEFAULT_TTL = "5m";
|
|
617
|
+
var DEFAULT_MESSAGE_BREAKPOINTS = 1;
|
|
618
|
+
function promptCacheMiddleware(config) {
|
|
619
|
+
const ttl = config?.ttl ?? DEFAULT_TTL;
|
|
620
|
+
const maxMsgBreakpoints = Math.min(
|
|
621
|
+
config?.messageBreakpoints ?? DEFAULT_MESSAGE_BREAKPOINTS,
|
|
622
|
+
MAX_ANTHROPIC_BREAKPOINTS - 1
|
|
623
|
+
);
|
|
624
|
+
return {
|
|
625
|
+
name: "prompt-cache",
|
|
626
|
+
model: {
|
|
627
|
+
async input(input, _ctx) {
|
|
628
|
+
const provider = detectCacheProvider(input);
|
|
629
|
+
switch (provider) {
|
|
630
|
+
case "anthropic":
|
|
631
|
+
return applyAnthropicCache(input, ttl, maxMsgBreakpoints);
|
|
632
|
+
// OpenAI caches prefixes automatically — no client action needed.
|
|
633
|
+
// case "openai":
|
|
634
|
+
// return applyOpenAICache(input);
|
|
635
|
+
default:
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
755
643
|
export {
|
|
756
644
|
MiddlewareRunner,
|
|
757
645
|
otelMiddleware,
|
|
758
646
|
createTelemetryConfig,
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
ApprovalTimeoutError,
|
|
762
|
-
createApprovalHandler,
|
|
763
|
-
approvalMiddleware
|
|
647
|
+
approvalMiddleware,
|
|
648
|
+
promptCacheMiddleware
|
|
764
649
|
};
|
package/dist/context/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { E as ErrorCategory, R as ResponseHeaders } from '../llm-error-D93FNNLY.js';
|
|
2
|
+
export { L as LLMError, a as LLMErrorOptions } from '../llm-error-D93FNNLY.js';
|
|
3
|
+
|
|
4
|
+
declare function isRetryableCategory(category: ErrorCategory): boolean;
|
|
5
|
+
declare function parseRetryDelay(headers: ResponseHeaders): number | undefined;
|
|
6
|
+
|
|
7
|
+
declare function isRetryable(error: unknown): boolean;
|
|
8
|
+
declare function getRetryDelay(error: unknown): number | undefined;
|
|
9
|
+
declare function getErrorCategory(error: unknown): ErrorCategory;
|
|
10
|
+
|
|
11
|
+
export { ErrorCategory, ResponseHeaders, getErrorCategory, getRetryDelay, isRetryable, isRetryableCategory, parseRetryDelay };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LLMError,
|
|
3
|
+
getErrorCategory,
|
|
4
|
+
getRetryDelay,
|
|
5
|
+
isRetryable,
|
|
6
|
+
isRetryableCategory,
|
|
7
|
+
parseRetryDelay
|
|
8
|
+
} from "../chunk-RZITT45F.js";
|
|
9
|
+
export {
|
|
10
|
+
LLMError,
|
|
11
|
+
getErrorCategory,
|
|
12
|
+
getRetryDelay,
|
|
13
|
+
isRetryable,
|
|
14
|
+
isRetryableCategory,
|
|
15
|
+
parseRetryDelay
|
|
16
|
+
};
|
|
@@ -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 };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { T as ToolHost } from '../types-CHiPh8U2.js';
|
|
2
|
+
export { D as DirEntry, E as ExecOptions, a as ExecResult, F as FileStat } from '../types-CHiPh8U2.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* LocalHost — executes tools on the local machine.
|
|
6
|
+
*
|
|
7
|
+
* Default ToolHost implementation. Uses Node's `child_process.spawn`
|
|
8
|
+
* for commands and `node:fs/promises` for file operations.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create a ToolHost that runs everything on the local machine.
|
|
13
|
+
*
|
|
14
|
+
* @param defaultCwd Working directory for commands when none is specified.
|
|
15
|
+
* Defaults to `process.cwd()`.
|
|
16
|
+
*/
|
|
17
|
+
declare function localHost(defaultCwd?: string): ToolHost;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for creating a Docker-backed `ToolHost`.
|
|
21
|
+
*/
|
|
22
|
+
interface DockerHostOptions {
|
|
23
|
+
/**
|
|
24
|
+
* The container to connect to. Either:
|
|
25
|
+
* - A string container name or ID
|
|
26
|
+
* - A Dockerode `Container`-like object
|
|
27
|
+
*/
|
|
28
|
+
container: string | {
|
|
29
|
+
id: string;
|
|
30
|
+
modem?: unknown;
|
|
31
|
+
};
|
|
32
|
+
/** User to run commands as inside the container. */
|
|
33
|
+
user?: string;
|
|
34
|
+
/** Default working directory inside the container. */
|
|
35
|
+
workdir?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Dockerode constructor options.
|
|
38
|
+
* Only used when `container` is a string.
|
|
39
|
+
*/
|
|
40
|
+
dockerOptions?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare function dockerHost(options: DockerHostOptions): Promise<ToolHost>;
|
|
44
|
+
|
|
45
|
+
export { type DockerHostOptions, ToolHost, dockerHost, localHost };
|