@cuylabs/agent-core 0.9.0 → 0.10.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 +33 -17
- package/dist/chunk-2O4MCSQS.js +780 -0
- package/dist/chunk-2TTOLHBT.js +198 -0
- package/dist/chunk-5FMSGQVX.js +281 -0
- package/dist/chunk-5NVVNXPQ.js +288 -0
- package/dist/{chunk-EKR6PKXU.js → chunk-6HZBHFOL.js} +3 -3
- package/dist/chunk-CJI7PVS2.js +58 -0
- package/dist/{chunk-WKHDSSXG.js → chunk-CMYN2RCB.js} +146 -46
- package/dist/chunk-FII65CN7.js +117 -0
- package/dist/{chunk-UHCJEM2E.js → chunk-ICZ66572.js} +13 -6
- package/dist/chunk-KYLPMBHD.js +316 -0
- package/dist/chunk-MXAP4UG6.js +2956 -0
- package/dist/{chunk-4QFNWPIF.js → chunk-N3VX7FEE.js} +35 -2
- package/dist/{chunk-MAZ5DY5B.js → chunk-NDZWXCBZ.js} +213 -78
- package/dist/{chunk-MHKK374K.js → chunk-Q742PSH3.js} +11 -27
- package/dist/{chunk-WGZAPU6N.js → chunk-QAL3OMI3.js} +15 -1
- package/dist/{chunk-UDCZ673N.js → chunk-RN6WZEUF.js} +27 -23
- package/dist/{chunk-ZXAKHMWH.js → chunk-ROTGCYDW.js} +22 -84
- package/dist/chunk-SPBFQXOT.js +0 -0
- package/dist/chunk-SSFBF3US.js +602 -0
- package/dist/chunk-SZ2XBPTW.js +8 -0
- package/dist/chunk-T4UIX5D7.js +115 -0
- package/dist/{chunk-IYWQOJMQ.js → chunk-TIHPYVAJ.js} +34 -34
- package/dist/{chunk-RKEW5WXI.js → chunk-TOTDGK3P.js} +1 -1
- package/dist/chunk-V4RFNEET.js +563 -0
- package/dist/chunk-VOUEJSW6.js +0 -0
- package/dist/{chunk-J4QDGZIA.js → chunk-WBPOZ7CL.js} +659 -275
- package/dist/chunk-X4VN4GIJ.js +185 -0
- package/dist/dispatch/index.d.ts +93 -0
- package/dist/dispatch/index.js +37 -0
- package/dist/events/index.d.ts +93 -0
- package/dist/events/index.js +6 -0
- package/dist/{runtime → execution}/index.d.ts +120 -35
- package/dist/{runtime → execution}/index.js +17 -11
- package/dist/index.d.ts +489 -115
- package/dist/index.js +1665 -462
- package/dist/inference/errors/index.js +1 -1
- package/dist/inference/index.d.ts +13 -21
- package/dist/inference/index.js +15 -12
- package/dist/instance-BqV2D5pc.d.ts +5723 -0
- package/dist/logger/index.d.ts +50 -0
- package/dist/logger/index.js +11 -0
- package/dist/mcp/index.d.ts +5 -9
- package/dist/mcp/index.js +2 -3
- package/dist/middleware/index.d.ts +10 -150
- package/dist/middleware/index.js +10 -2
- package/dist/model-messages-B4nK9D1-.d.ts +13 -0
- package/dist/models/index.d.ts +5 -2
- package/dist/models/index.js +2 -1
- package/dist/models/reasoning/index.js +2 -1
- package/dist/plugin/index.d.ts +55 -11
- package/dist/plugin/index.js +1 -1
- package/dist/profiles/index.d.ts +55 -0
- package/dist/{presets → profiles}/index.js +10 -10
- package/dist/prompt/index.d.ts +8 -13
- package/dist/safety/index.d.ts +109 -14
- package/dist/safety/index.js +59 -3
- package/dist/sandbox/index.d.ts +81 -0
- package/dist/sandbox/index.js +1 -0
- package/dist/skill/index.d.ts +10 -8
- package/dist/skill/index.js +2 -2
- package/dist/storage/index.d.ts +12 -4
- package/dist/storage/index.js +1 -1
- package/dist/subagents/index.d.ts +177 -0
- package/dist/subagents/index.js +78 -0
- package/dist/team/index.d.ts +544 -0
- package/dist/team/index.js +41 -0
- package/dist/tool/host/index.d.ts +41 -0
- package/dist/tool/host/index.js +10 -0
- package/dist/tool/index.d.ts +111 -21
- package/dist/tool/index.js +20 -13
- package/dist/{types-VQgymC1N.d.ts → types-Bj_J8u_W.d.ts} +44 -64
- package/dist/{types-CHiPh8U2.d.ts → types-C_LCeYNg.d.ts} +7 -7
- package/dist/types-RSCv7nQ4.d.ts +59 -0
- package/package.json +46 -47
- package/dist/builder-BgZ_j4Vs.d.ts +0 -35
- package/dist/chunk-5ARZJWD2.js +0 -259
- package/dist/chunk-DXFBQMXP.js +0 -53
- package/dist/chunk-H3FUYU52.js +0 -81
- package/dist/chunk-JLXG2SH7.js +0 -905
- package/dist/chunk-N7P4PN3O.js +0 -84
- package/dist/chunk-OFDKHNCX.js +0 -727
- package/dist/chunk-SDSBEQXG.js +0 -157
- package/dist/chunk-VEKUXUVF.js +0 -41
- package/dist/chunk-VNQBHPCT.js +0 -398
- package/dist/chunk-WWYYNWEW.js +0 -259
- package/dist/context/index.d.ts +0 -259
- package/dist/context/index.js +0 -26
- package/dist/events-CE72w8W4.d.ts +0 -149
- package/dist/host/index.d.ts +0 -45
- package/dist/host/index.js +0 -8
- package/dist/index-DQuTZ8xL.d.ts +0 -1335
- package/dist/messages-BYWGn8TY.d.ts +0 -110
- package/dist/presets/index.d.ts +0 -53
- package/dist/registry-DwYqsQkX.d.ts +0 -164
- package/dist/runner-CI-XeR16.d.ts +0 -91
- package/dist/scope/index.d.ts +0 -10
- package/dist/scope/index.js +0 -14
- package/dist/session-manager-KbYt2WUh.d.ts +0 -282
- package/dist/signal/index.d.ts +0 -28
- package/dist/signal/index.js +0 -6
- package/dist/sub-agent/index.d.ts +0 -24
- package/dist/sub-agent/index.js +0 -32
- package/dist/tool-CZWN3KbO.d.ts +0 -141
- package/dist/tool-DkhSCV2Y.d.ts +0 -145
- package/dist/tracker-DClqYqTj.d.ts +0 -96
- package/dist/tracking/index.d.ts +0 -111
- package/dist/tracking/index.js +0 -20
- package/dist/types-BfNpU8NS.d.ts +0 -270
- package/dist/types-BlOKk-Bb.d.ts +0 -330
- package/dist/types-BlZwmnuW.d.ts +0 -50
- package/dist/types-CQL-SvTn.d.ts +0 -29
- package/dist/types-CWm-7rvB.d.ts +0 -55
- package/dist/types-DTSkxakL.d.ts +0 -651
- package/dist/types-DmDwi2zI.d.ts +0 -339
- package/dist/types-YuWV4ag7.d.ts +0 -72
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuylabs/agent-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Embeddable AI agent infrastructure — execution, sessions, tools, skills,
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Embeddable AI agent infrastructure — execution, sessions, tools, skills, dispatch, tracing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -16,21 +16,16 @@
|
|
|
16
16
|
"import": "./dist/tool/index.js",
|
|
17
17
|
"default": "./dist/tool/index.js"
|
|
18
18
|
},
|
|
19
|
-
"./
|
|
20
|
-
"types": "./dist/
|
|
21
|
-
"import": "./dist/
|
|
22
|
-
"default": "./dist/
|
|
19
|
+
"./execution": {
|
|
20
|
+
"types": "./dist/execution/index.d.ts",
|
|
21
|
+
"import": "./dist/execution/index.js",
|
|
22
|
+
"default": "./dist/execution/index.js"
|
|
23
23
|
},
|
|
24
24
|
"./inference": {
|
|
25
25
|
"types": "./dist/inference/index.d.ts",
|
|
26
26
|
"import": "./dist/inference/index.js",
|
|
27
27
|
"default": "./dist/inference/index.js"
|
|
28
28
|
},
|
|
29
|
-
"./tracking": {
|
|
30
|
-
"types": "./dist/tracking/index.d.ts",
|
|
31
|
-
"import": "./dist/tracking/index.js",
|
|
32
|
-
"default": "./dist/tracking/index.js"
|
|
33
|
-
},
|
|
34
29
|
"./middleware": {
|
|
35
30
|
"types": "./dist/middleware/index.d.ts",
|
|
36
31
|
"import": "./dist/middleware/index.js",
|
|
@@ -46,21 +41,21 @@
|
|
|
46
41
|
"import": "./dist/skill/index.js",
|
|
47
42
|
"default": "./dist/skill/index.js"
|
|
48
43
|
},
|
|
49
|
-
"./
|
|
50
|
-
"types": "./dist/
|
|
51
|
-
"import": "./dist/
|
|
52
|
-
"default": "./dist/
|
|
44
|
+
"./dispatch": {
|
|
45
|
+
"types": "./dist/dispatch/index.d.ts",
|
|
46
|
+
"import": "./dist/dispatch/index.js",
|
|
47
|
+
"default": "./dist/dispatch/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./subagents": {
|
|
50
|
+
"types": "./dist/subagents/index.d.ts",
|
|
51
|
+
"import": "./dist/subagents/index.js",
|
|
52
|
+
"default": "./dist/subagents/index.js"
|
|
53
53
|
},
|
|
54
54
|
"./storage": {
|
|
55
55
|
"types": "./dist/storage/index.d.ts",
|
|
56
56
|
"import": "./dist/storage/index.js",
|
|
57
57
|
"default": "./dist/storage/index.js"
|
|
58
58
|
},
|
|
59
|
-
"./context": {
|
|
60
|
-
"types": "./dist/context/index.d.ts",
|
|
61
|
-
"import": "./dist/context/index.js",
|
|
62
|
-
"default": "./dist/context/index.js"
|
|
63
|
-
},
|
|
64
59
|
"./reasoning": {
|
|
65
60
|
"types": "./dist/models/reasoning/index.d.ts",
|
|
66
61
|
"import": "./dist/models/reasoning/index.js",
|
|
@@ -76,30 +71,25 @@
|
|
|
76
71
|
"import": "./dist/mcp/index.js",
|
|
77
72
|
"default": "./dist/mcp/index.js"
|
|
78
73
|
},
|
|
79
|
-
"./host": {
|
|
80
|
-
"types": "./dist/host/index.d.ts",
|
|
81
|
-
"import": "./dist/host/index.js",
|
|
82
|
-
"default": "./dist/host/index.js"
|
|
74
|
+
"./tool/host": {
|
|
75
|
+
"types": "./dist/tool/host/index.d.ts",
|
|
76
|
+
"import": "./dist/tool/host/index.js",
|
|
77
|
+
"default": "./dist/tool/host/index.js"
|
|
83
78
|
},
|
|
84
|
-
"./
|
|
85
|
-
"types": "./dist/
|
|
86
|
-
"import": "./dist/
|
|
87
|
-
"default": "./dist/
|
|
88
|
-
},
|
|
89
|
-
"./signal": {
|
|
90
|
-
"types": "./dist/signal/index.d.ts",
|
|
91
|
-
"import": "./dist/signal/index.js",
|
|
92
|
-
"default": "./dist/signal/index.js"
|
|
79
|
+
"./sandbox": {
|
|
80
|
+
"types": "./dist/sandbox/index.d.ts",
|
|
81
|
+
"import": "./dist/sandbox/index.js",
|
|
82
|
+
"default": "./dist/sandbox/index.js"
|
|
93
83
|
},
|
|
94
84
|
"./errors": {
|
|
95
85
|
"types": "./dist/inference/errors/index.d.ts",
|
|
96
86
|
"import": "./dist/inference/errors/index.js",
|
|
97
87
|
"default": "./dist/inference/errors/index.js"
|
|
98
88
|
},
|
|
99
|
-
"./
|
|
100
|
-
"types": "./dist/
|
|
101
|
-
"import": "./dist/
|
|
102
|
-
"default": "./dist/
|
|
89
|
+
"./profiles": {
|
|
90
|
+
"types": "./dist/profiles/index.d.ts",
|
|
91
|
+
"import": "./dist/profiles/index.js",
|
|
92
|
+
"default": "./dist/profiles/index.js"
|
|
103
93
|
},
|
|
104
94
|
"./safety": {
|
|
105
95
|
"types": "./dist/safety/index.d.ts",
|
|
@@ -110,6 +100,21 @@
|
|
|
110
100
|
"types": "./dist/plugin/index.d.ts",
|
|
111
101
|
"import": "./dist/plugin/index.js",
|
|
112
102
|
"default": "./dist/plugin/index.js"
|
|
103
|
+
},
|
|
104
|
+
"./events": {
|
|
105
|
+
"types": "./dist/events/index.d.ts",
|
|
106
|
+
"import": "./dist/events/index.js",
|
|
107
|
+
"default": "./dist/events/index.js"
|
|
108
|
+
},
|
|
109
|
+
"./team": {
|
|
110
|
+
"types": "./dist/team/index.d.ts",
|
|
111
|
+
"import": "./dist/team/index.js",
|
|
112
|
+
"default": "./dist/team/index.js"
|
|
113
|
+
},
|
|
114
|
+
"./logger": {
|
|
115
|
+
"types": "./dist/logger/index.d.ts",
|
|
116
|
+
"import": "./dist/logger/index.js",
|
|
117
|
+
"default": "./dist/logger/index.js"
|
|
113
118
|
}
|
|
114
119
|
},
|
|
115
120
|
"files": [
|
|
@@ -135,12 +140,11 @@
|
|
|
135
140
|
"@ai-sdk/openai-compatible": "^2.0.0",
|
|
136
141
|
"@ai-sdk/xai": "^3.0.0",
|
|
137
142
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
138
|
-
"@openrouter/ai-sdk-provider": "^
|
|
143
|
+
"@openrouter/ai-sdk-provider": "^2.5.0",
|
|
139
144
|
"@opentelemetry/api": "^1.9.0",
|
|
140
145
|
"@opentelemetry/resources": "^2.0.0",
|
|
141
146
|
"@opentelemetry/sdk-trace-node": "^2.0.0",
|
|
142
|
-
"@opentelemetry/semantic-conventions": "^1.30.0"
|
|
143
|
-
"dockerode": "^4.0.9"
|
|
147
|
+
"@opentelemetry/semantic-conventions": "^1.30.0"
|
|
144
148
|
},
|
|
145
149
|
"peerDependenciesMeta": {
|
|
146
150
|
"@ai-sdk/amazon-bedrock": {
|
|
@@ -182,9 +186,6 @@
|
|
|
182
186
|
"@openrouter/ai-sdk-provider": {
|
|
183
187
|
"optional": true
|
|
184
188
|
},
|
|
185
|
-
"dockerode": {
|
|
186
|
-
"optional": true
|
|
187
|
-
},
|
|
188
189
|
"@opentelemetry/api": {
|
|
189
190
|
"optional": true
|
|
190
191
|
},
|
|
@@ -213,7 +214,6 @@
|
|
|
213
214
|
"@ai-sdk/xai": "^3.0.67",
|
|
214
215
|
"@arizeai/openinference-vercel": "^2.7.1",
|
|
215
216
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
216
|
-
"@openrouter/ai-sdk-provider": "^1.0.0",
|
|
217
217
|
"@opentelemetry/api": "^1.9.0",
|
|
218
218
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.213.0",
|
|
219
219
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
@@ -221,7 +221,6 @@
|
|
|
221
221
|
"@opentelemetry/resources": "^2.6.0",
|
|
222
222
|
"@opentelemetry/sdk-trace-node": "^2.6.0",
|
|
223
223
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
224
|
-
"@types/dockerode": "^3.3.47",
|
|
225
224
|
"@types/node": "^22.0.0",
|
|
226
225
|
"dotenv": "^17.2.3",
|
|
227
226
|
"tsup": "^8.0.0",
|
|
@@ -250,8 +249,8 @@
|
|
|
250
249
|
"access": "public"
|
|
251
250
|
},
|
|
252
251
|
"scripts": {
|
|
253
|
-
"build": "tsup src/index.ts src/tool/index.ts src/
|
|
254
|
-
"dev": "tsup src/index.ts src/tool/index.ts src/
|
|
252
|
+
"build": "tsup src/index.ts src/tool/index.ts src/tool/host/index.ts src/sandbox/index.ts src/execution/index.ts src/inference/index.ts src/inference/errors/index.ts src/middleware/index.ts src/prompt/index.ts src/skill/index.ts src/dispatch/index.ts src/subagents/index.ts src/storage/index.ts src/models/index.ts src/models/reasoning/index.ts src/mcp/index.ts src/profiles/index.ts src/safety/index.ts src/plugin/index.ts src/events/index.ts src/team/index.ts src/logger/index.ts --format esm --dts --clean",
|
|
253
|
+
"dev": "tsup src/index.ts src/tool/index.ts src/tool/host/index.ts src/sandbox/index.ts src/execution/index.ts src/inference/index.ts src/inference/errors/index.ts src/middleware/index.ts src/prompt/index.ts src/skill/index.ts src/dispatch/index.ts src/subagents/index.ts src/storage/index.ts src/models/index.ts src/models/reasoning/index.ts src/mcp/index.ts src/profiles/index.ts src/safety/index.ts src/plugin/index.ts src/events/index.ts src/team/index.ts src/logger/index.ts --format esm --dts --watch",
|
|
255
254
|
"test": "vitest run",
|
|
256
255
|
"test:watch": "vitest",
|
|
257
256
|
"lint": "eslint src/",
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { d as PromptConfig, P as PromptBuildContext, c as PromptSection, e as ModelFamily } from './types-DTSkxakL.js';
|
|
2
|
-
import { S as SkillRegistry } from './registry-DwYqsQkX.js';
|
|
3
|
-
import { M as MiddlewareRunner } from './runner-CI-XeR16.js';
|
|
4
|
-
|
|
5
|
-
interface PromptSectionPreview {
|
|
6
|
-
id: string;
|
|
7
|
-
label: string;
|
|
8
|
-
priority: number;
|
|
9
|
-
size: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare class PromptBuilder {
|
|
13
|
-
private readonly config;
|
|
14
|
-
private customSections;
|
|
15
|
-
private envCache?;
|
|
16
|
-
private instructionCache?;
|
|
17
|
-
private skillRegistryCache?;
|
|
18
|
-
constructor(config?: PromptConfig);
|
|
19
|
-
build(context: PromptBuildContext, middleware?: MiddlewareRunner): Promise<string>;
|
|
20
|
-
addSection(section: PromptSection): void;
|
|
21
|
-
removeSection(id: string): boolean;
|
|
22
|
-
toggleSection(id: string, enabled: boolean): void;
|
|
23
|
-
getSections(): PromptSection[];
|
|
24
|
-
hasSection(id: string): boolean;
|
|
25
|
-
clearCache(): void;
|
|
26
|
-
getSkillRegistry(cwd: string): Promise<SkillRegistry>;
|
|
27
|
-
getModelFamily(model: PromptBuildContext["model"]): ModelFamily;
|
|
28
|
-
getBaseTemplate(model: PromptBuildContext["model"]): string;
|
|
29
|
-
preview(context: PromptBuildContext, middleware?: MiddlewareRunner): Promise<PromptSectionPreview[]>;
|
|
30
|
-
private getEnvironment;
|
|
31
|
-
private getInstructions;
|
|
32
|
-
}
|
|
33
|
-
declare function createPromptBuilder(config?: PromptConfig): PromptBuilder;
|
|
34
|
-
|
|
35
|
-
export { PromptBuilder as P, createPromptBuilder as c };
|
package/dist/chunk-5ARZJWD2.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
// src/safety/risk.ts
|
|
2
|
-
var DEFAULT_TOOL_RISKS = {
|
|
3
|
-
read: "safe",
|
|
4
|
-
read_file: "safe",
|
|
5
|
-
grep: "safe",
|
|
6
|
-
glob: "safe",
|
|
7
|
-
list_dir: "safe",
|
|
8
|
-
plan: "safe",
|
|
9
|
-
invoke_agent: "safe",
|
|
10
|
-
wait_agent: "safe",
|
|
11
|
-
close_agent: "safe",
|
|
12
|
-
skill: "safe",
|
|
13
|
-
skill_resource: "safe",
|
|
14
|
-
write: "moderate",
|
|
15
|
-
write_file: "moderate",
|
|
16
|
-
edit: "moderate",
|
|
17
|
-
edit_file: "moderate",
|
|
18
|
-
create_file: "moderate",
|
|
19
|
-
bash: "dangerous",
|
|
20
|
-
shell: "dangerous",
|
|
21
|
-
delete_file: "dangerous",
|
|
22
|
-
remove: "dangerous"
|
|
23
|
-
};
|
|
24
|
-
function getToolRisk(tool, customRisks) {
|
|
25
|
-
if (customRisks?.[tool]) {
|
|
26
|
-
return customRisks[tool];
|
|
27
|
-
}
|
|
28
|
-
if (DEFAULT_TOOL_RISKS[tool]) {
|
|
29
|
-
return DEFAULT_TOOL_RISKS[tool];
|
|
30
|
-
}
|
|
31
|
-
return "moderate";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/safety/errors.ts
|
|
35
|
-
var ApprovalDeniedError = class extends Error {
|
|
36
|
-
constructor(tool, args, message) {
|
|
37
|
-
super(message || `Operation denied: ${tool}`);
|
|
38
|
-
this.tool = tool;
|
|
39
|
-
this.args = args;
|
|
40
|
-
this.name = "ApprovalDeniedError";
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var ApprovalTimeoutError = class extends Error {
|
|
44
|
-
constructor(tool, timeoutMs) {
|
|
45
|
-
super(`Approval timeout after ${timeoutMs}ms for: ${tool}`);
|
|
46
|
-
this.tool = tool;
|
|
47
|
-
this.timeoutMs = timeoutMs;
|
|
48
|
-
this.name = "ApprovalTimeoutError";
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// src/safety/patterns.ts
|
|
53
|
-
function matchApprovalPattern(pattern, value) {
|
|
54
|
-
if (pattern.length > 500) return false;
|
|
55
|
-
const p = pattern.toLowerCase();
|
|
56
|
-
const v = value.toLowerCase();
|
|
57
|
-
let pi = 0;
|
|
58
|
-
let vi = 0;
|
|
59
|
-
let starPi = -1;
|
|
60
|
-
let starVi = -1;
|
|
61
|
-
while (vi < v.length) {
|
|
62
|
-
if (pi < p.length && (p[pi] === "?" || p[pi] === v[vi])) {
|
|
63
|
-
pi++;
|
|
64
|
-
vi++;
|
|
65
|
-
} else if (pi < p.length && p[pi] === "*") {
|
|
66
|
-
starPi = pi;
|
|
67
|
-
starVi = vi;
|
|
68
|
-
pi++;
|
|
69
|
-
} else if (starPi !== -1) {
|
|
70
|
-
pi = starPi + 1;
|
|
71
|
-
starVi++;
|
|
72
|
-
vi = starVi;
|
|
73
|
-
} else {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
while (pi < p.length && p[pi] === "*") {
|
|
78
|
-
pi++;
|
|
79
|
-
}
|
|
80
|
-
return pi === p.length;
|
|
81
|
-
}
|
|
82
|
-
function extractApprovalPatterns(tool, args) {
|
|
83
|
-
if (!args || typeof args !== "object") {
|
|
84
|
-
return [tool];
|
|
85
|
-
}
|
|
86
|
-
const record = args;
|
|
87
|
-
if ("path" in record && typeof record.path === "string" || "filePath" in record && typeof record.filePath === "string") {
|
|
88
|
-
const path = record.path ?? record.filePath;
|
|
89
|
-
const dir = path.substring(0, path.lastIndexOf("/") + 1);
|
|
90
|
-
return [dir ? `${dir}*` : path];
|
|
91
|
-
}
|
|
92
|
-
if ("command" in record && typeof record.command === "string") {
|
|
93
|
-
const command = record.command.split(/\s+/)[0];
|
|
94
|
-
return [command];
|
|
95
|
-
}
|
|
96
|
-
if ("pattern" in record && typeof record.pattern === "string") {
|
|
97
|
-
return [record.pattern];
|
|
98
|
-
}
|
|
99
|
-
return [tool];
|
|
100
|
-
}
|
|
101
|
-
function describeApprovalOperation(tool, args) {
|
|
102
|
-
if (!args || typeof args !== "object") {
|
|
103
|
-
return `Execute ${tool}`;
|
|
104
|
-
}
|
|
105
|
-
const record = args;
|
|
106
|
-
switch (tool) {
|
|
107
|
-
case "read":
|
|
108
|
-
case "read_file":
|
|
109
|
-
return `Read file: ${record.path ?? record.filePath}`;
|
|
110
|
-
case "write":
|
|
111
|
-
case "write_file":
|
|
112
|
-
case "create_file":
|
|
113
|
-
return `Write file: ${record.path ?? record.filePath}`;
|
|
114
|
-
case "edit":
|
|
115
|
-
case "edit_file":
|
|
116
|
-
return `Edit file: ${record.path ?? record.filePath}`;
|
|
117
|
-
case "delete_file":
|
|
118
|
-
case "remove":
|
|
119
|
-
return `Delete: ${record.path}`;
|
|
120
|
-
case "bash":
|
|
121
|
-
case "shell": {
|
|
122
|
-
const command = String(record.command);
|
|
123
|
-
return `Run command: ${command.slice(0, 100)}${command.length > 100 ? "..." : ""}`;
|
|
124
|
-
}
|
|
125
|
-
case "grep":
|
|
126
|
-
return `Search for: ${record.pattern}`;
|
|
127
|
-
case "glob":
|
|
128
|
-
return `Find files: ${record.pattern}`;
|
|
129
|
-
default: {
|
|
130
|
-
const json = JSON.stringify(args);
|
|
131
|
-
const truncated = json.length > 50 ? `${json.slice(0, 50)}...` : json;
|
|
132
|
-
return `${tool}(${truncated})`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/safety/handler.ts
|
|
138
|
-
function findMatchingRule(rules, tool, patterns) {
|
|
139
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
140
|
-
const rule = rules[index];
|
|
141
|
-
const toolMatches = rule.tool === "*" || matchApprovalPattern(rule.tool, tool);
|
|
142
|
-
const patternMatches = patterns.some(
|
|
143
|
-
(pattern) => matchApprovalPattern(rule.pattern, pattern)
|
|
144
|
-
);
|
|
145
|
-
if (toolMatches && patternMatches) {
|
|
146
|
-
return rule;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return void 0;
|
|
150
|
-
}
|
|
151
|
-
function createApprovalHandler(config = {}) {
|
|
152
|
-
const {
|
|
153
|
-
defaultAction = "ask",
|
|
154
|
-
timeout = 5 * 60 * 1e3,
|
|
155
|
-
onRequest
|
|
156
|
-
} = config;
|
|
157
|
-
let requestCounter = 0;
|
|
158
|
-
const initialRuleCount = config.rules?.length ?? 0;
|
|
159
|
-
const rules = [...config.rules ?? []];
|
|
160
|
-
const activeRequests = /* @__PURE__ */ new Set();
|
|
161
|
-
async function request(sessionId, tool, args, customRisks) {
|
|
162
|
-
const risk = getToolRisk(tool, customRisks);
|
|
163
|
-
const patterns = extractApprovalPatterns(tool, args);
|
|
164
|
-
const matchingRule = findMatchingRule(rules, tool, patterns);
|
|
165
|
-
if (matchingRule) {
|
|
166
|
-
if (matchingRule.action === "allow") {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
throw new ApprovalDeniedError(
|
|
170
|
-
tool,
|
|
171
|
-
args,
|
|
172
|
-
`Denied by rule: ${matchingRule.pattern}`
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
if (risk === "safe" && defaultAction !== "deny") {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (!onRequest) {
|
|
179
|
-
if (defaultAction === "allow") {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (defaultAction === "deny") {
|
|
183
|
-
throw new ApprovalDeniedError(tool, args);
|
|
184
|
-
}
|
|
185
|
-
throw new ApprovalDeniedError(tool, args, "No approval handler configured");
|
|
186
|
-
}
|
|
187
|
-
const id = `approval-${++requestCounter}-${Date.now()}`;
|
|
188
|
-
const requestData = {
|
|
189
|
-
id,
|
|
190
|
-
sessionId,
|
|
191
|
-
tool,
|
|
192
|
-
args,
|
|
193
|
-
description: describeApprovalOperation(tool, args),
|
|
194
|
-
risk,
|
|
195
|
-
patterns,
|
|
196
|
-
timestamp: Date.now()
|
|
197
|
-
};
|
|
198
|
-
const ac = new AbortController();
|
|
199
|
-
activeRequests.add(ac);
|
|
200
|
-
let timeoutId;
|
|
201
|
-
try {
|
|
202
|
-
const action = await Promise.race([
|
|
203
|
-
onRequest(requestData),
|
|
204
|
-
new Promise((_, reject) => {
|
|
205
|
-
timeoutId = setTimeout(() => {
|
|
206
|
-
reject(new ApprovalTimeoutError(tool, timeout));
|
|
207
|
-
}, timeout);
|
|
208
|
-
ac.signal.addEventListener("abort", () => {
|
|
209
|
-
clearTimeout(timeoutId);
|
|
210
|
-
reject(new Error("Cancelled"));
|
|
211
|
-
}, { once: true });
|
|
212
|
-
})
|
|
213
|
-
]);
|
|
214
|
-
switch (action) {
|
|
215
|
-
case "allow":
|
|
216
|
-
return;
|
|
217
|
-
case "deny":
|
|
218
|
-
throw new ApprovalDeniedError(tool, args);
|
|
219
|
-
case "remember":
|
|
220
|
-
for (const pattern of patterns) {
|
|
221
|
-
rules.push({ pattern, tool, action: "allow" });
|
|
222
|
-
}
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
} finally {
|
|
226
|
-
clearTimeout(timeoutId);
|
|
227
|
-
activeRequests.delete(ac);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function cancelAll(_reason) {
|
|
231
|
-
for (const ac of activeRequests) {
|
|
232
|
-
ac.abort();
|
|
233
|
-
}
|
|
234
|
-
activeRequests.clear();
|
|
235
|
-
}
|
|
236
|
-
function addRule(rule) {
|
|
237
|
-
rules.push(rule);
|
|
238
|
-
}
|
|
239
|
-
function getRules() {
|
|
240
|
-
return rules;
|
|
241
|
-
}
|
|
242
|
-
function clearSessionRules() {
|
|
243
|
-
rules.splice(initialRuleCount);
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
request,
|
|
247
|
-
cancelAll,
|
|
248
|
-
addRule,
|
|
249
|
-
getRules,
|
|
250
|
-
clearSessionRules
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export {
|
|
255
|
-
getToolRisk,
|
|
256
|
-
ApprovalDeniedError,
|
|
257
|
-
ApprovalTimeoutError,
|
|
258
|
-
createApprovalHandler
|
|
259
|
-
};
|
package/dist/chunk-DXFBQMXP.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// src/signal/local.ts
|
|
2
|
-
var LocalSignal = class {
|
|
3
|
-
/** type → Set<handler> for typed subscriptions */
|
|
4
|
-
typed = /* @__PURE__ */ new Map();
|
|
5
|
-
/** handlers that receive every event */
|
|
6
|
-
wildcard = /* @__PURE__ */ new Set();
|
|
7
|
-
on(type, handler) {
|
|
8
|
-
let set = this.typed.get(type);
|
|
9
|
-
if (!set) {
|
|
10
|
-
set = /* @__PURE__ */ new Set();
|
|
11
|
-
this.typed.set(type, set);
|
|
12
|
-
}
|
|
13
|
-
const wrapped = (event) => {
|
|
14
|
-
handler(event);
|
|
15
|
-
};
|
|
16
|
-
set.add(wrapped);
|
|
17
|
-
return () => {
|
|
18
|
-
set.delete(wrapped);
|
|
19
|
-
if (set.size === 0) this.typed.delete(type);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
onAny(handler) {
|
|
23
|
-
this.wildcard.add(handler);
|
|
24
|
-
return () => {
|
|
25
|
-
this.wildcard.delete(handler);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
emit(event) {
|
|
29
|
-
const set = this.typed.get(event.type);
|
|
30
|
-
if (set) {
|
|
31
|
-
for (const fn of set) {
|
|
32
|
-
try {
|
|
33
|
-
fn(event);
|
|
34
|
-
} catch {
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
for (const fn of this.wildcard) {
|
|
39
|
-
try {
|
|
40
|
-
fn(event);
|
|
41
|
-
} catch {
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
clear() {
|
|
46
|
-
this.typed.clear();
|
|
47
|
-
this.wildcard.clear();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export {
|
|
52
|
-
LocalSignal
|
|
53
|
-
};
|
package/dist/chunk-H3FUYU52.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
extractFilePathsFromArgs,
|
|
3
|
-
shouldCaptureBaseline
|
|
4
|
-
} from "./chunk-VEKUXUVF.js";
|
|
5
|
-
import {
|
|
6
|
-
snapshotScope,
|
|
7
|
-
withinScope
|
|
8
|
-
} from "./chunk-N7P4PN3O.js";
|
|
9
|
-
|
|
10
|
-
// src/tool/executor.ts
|
|
11
|
-
async function executeAgentToolCall(options) {
|
|
12
|
-
return withinScope(
|
|
13
|
-
{
|
|
14
|
-
kind: "tool",
|
|
15
|
-
name: "tool-call",
|
|
16
|
-
sessionId: options.sessionID,
|
|
17
|
-
attributes: {
|
|
18
|
-
toolName: options.toolName,
|
|
19
|
-
messageId: options.messageID,
|
|
20
|
-
agent: options.agent ?? "default"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
async () => {
|
|
24
|
-
const initialized = options.initialized ?? await options.tool.init({ cwd: options.cwd });
|
|
25
|
-
const ctx = {
|
|
26
|
-
cwd: options.cwd,
|
|
27
|
-
abort: options.abort,
|
|
28
|
-
sessionID: options.sessionID,
|
|
29
|
-
messageID: options.messageID,
|
|
30
|
-
agent: options.agent ?? "default",
|
|
31
|
-
scope: snapshotScope(),
|
|
32
|
-
...options.host ? { host: options.host } : {},
|
|
33
|
-
...options.turnTracker ? { turnTracker: options.turnTracker } : {}
|
|
34
|
-
};
|
|
35
|
-
if (options.middleware?.hasMiddleware) {
|
|
36
|
-
const decision = await options.middleware.runBeforeToolCall(
|
|
37
|
-
options.toolName,
|
|
38
|
-
options.params,
|
|
39
|
-
ctx
|
|
40
|
-
);
|
|
41
|
-
if (decision.action === "deny") {
|
|
42
|
-
return {
|
|
43
|
-
output: decision.reason ?? `Tool call denied: ${options.toolName}`
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (options.turnTracker && initialized.fileOps && shouldCaptureBaseline(initialized.fileOps)) {
|
|
48
|
-
const paths = extractFilePathsFromArgs(
|
|
49
|
-
options.params,
|
|
50
|
-
initialized.fileOps
|
|
51
|
-
);
|
|
52
|
-
for (const path of paths) {
|
|
53
|
-
await options.turnTracker.beforeWrite(path);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const result = await initialized.execute(options.params, ctx);
|
|
57
|
-
if (options.middleware?.hasMiddleware) {
|
|
58
|
-
const transformed = await options.middleware.runAfterToolCall(
|
|
59
|
-
options.toolName,
|
|
60
|
-
options.params,
|
|
61
|
-
result,
|
|
62
|
-
ctx
|
|
63
|
-
);
|
|
64
|
-
return {
|
|
65
|
-
output: transformed.output,
|
|
66
|
-
title: transformed.title,
|
|
67
|
-
metadata: transformed.metadata
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
output: result.output,
|
|
72
|
-
title: result.title,
|
|
73
|
-
metadata: result.metadata
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export {
|
|
80
|
-
executeAgentToolCall
|
|
81
|
-
};
|