@cuylabs/agent-core 0.8.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-CAA7FHIH.js → chunk-6HZBHFOL.js} +3 -103
- package/dist/chunk-CJI7PVS2.js +58 -0
- package/dist/{chunk-N6HWIEEA.js → chunk-CMYN2RCB.js} +278 -61
- package/dist/chunk-FII65CN7.js +117 -0
- package/dist/{chunk-IVUJDISU.js → chunk-GFTW23FV.js} +5 -14
- package/dist/chunk-I6PKJ7XQ.js +292 -0
- package/dist/{chunk-BDBZ3SLK.js → chunk-ICZ66572.js} +48 -4
- package/dist/chunk-KYLPMBHD.js +316 -0
- package/dist/chunk-MXAP4UG6.js +2956 -0
- package/dist/{chunk-RZITT45F.js → chunk-N3VX7FEE.js} +39 -6
- package/dist/{chunk-YSLSEQ6B.js → chunk-NDZWXCBZ.js} +218 -95
- package/dist/{chunk-P6YF7USR.js → chunk-Q742PSH3.js} +23 -38
- package/dist/chunk-QAL3OMI3.js +943 -0
- package/dist/{chunk-RFEKJKTO.js → chunk-RN6WZEUF.js} +330 -280
- package/dist/{chunk-ZXAKHMWH.js → chunk-ROTGCYDW.js} +22 -84
- package/dist/chunk-SPBFQXOT.js +0 -0
- package/dist/{chunk-LRHOS4ZN.js → chunk-SPILYYDF.js} +3 -2
- package/dist/chunk-SSFBF3US.js +602 -0
- package/dist/chunk-SZ2XBPTW.js +8 -0
- package/dist/chunk-T4UIX5D7.js +115 -0
- package/dist/chunk-TIHPYVAJ.js +102 -0
- package/dist/{chunk-YUUJK53A.js → chunk-TOTDGK3P.js} +1 -1
- package/dist/chunk-V4RFNEET.js +563 -0
- package/dist/chunk-VOUEJSW6.js +0 -0
- package/dist/{chunk-4BDA7DQY.js → chunk-WBPOZ7CL.js} +673 -273
- 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 -34
- package/dist/{runtime → execution}/index.js +18 -13
- package/dist/index-BCqEGzBj.d.ts +251 -0
- package/dist/index.d.ts +490 -122
- package/dist/index.js +2104 -615
- package/dist/{errors → inference/errors}/index.d.ts +2 -2
- package/dist/{errors → inference/errors}/index.js +1 -1
- package/dist/inference/index.d.ts +16 -23
- package/dist/inference/index.js +45 -16
- 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 -149
- package/dist/middleware/index.js +11 -3
- package/dist/model-messages-B4nK9D1-.d.ts +13 -0
- package/dist/models/index.d.ts +23 -18
- package/dist/models/index.js +48 -11
- package/dist/models/reasoning/index.d.ts +4 -0
- package/dist/{reasoning → models/reasoning}/index.js +3 -3
- package/dist/plugin/index.d.ts +458 -0
- package/dist/plugin/index.js +32 -0
- package/dist/profiles/index.d.ts +55 -0
- package/dist/profiles/index.js +30 -0
- package/dist/prompt/index.d.ts +8 -12
- package/dist/prompt/index.js +3 -2
- 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 +3 -3
- 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 +125 -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 +58 -53
- package/dist/builder-UpOWQMW3.d.ts +0 -34
- package/dist/chunk-7MUFEN4K.js +0 -559
- package/dist/chunk-7VKQ4WPB.js +0 -73
- package/dist/chunk-BFM2YHNM.js +0 -222
- package/dist/chunk-DWYX7ASF.js +0 -26
- package/dist/chunk-KUVSERLJ.js +0 -50
- package/dist/chunk-N7P4PN3O.js +0 -84
- package/dist/chunk-SDSBEQXG.js +0 -157
- package/dist/chunk-SQU2AJHO.js +0 -305
- package/dist/chunk-VBWWUHWI.js +0 -724
- 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-CWSchSql.d.ts +0 -1058
- package/dist/messages-BYWGn8TY.d.ts +0 -110
- package/dist/presets/index.d.ts +0 -53
- package/dist/presets/index.js +0 -28
- package/dist/reasoning/index.d.ts +0 -116
- package/dist/registry-DwYqsQkX.d.ts +0 -164
- package/dist/runner-e2YRcUoX.d.ts +0 -786
- package/dist/scope/index.d.ts +0 -10
- package/dist/scope/index.js +0 -14
- package/dist/session-manager-B_CWGTsl.d.ts +0 -274
- package/dist/signal/index.d.ts +0 -28
- package/dist/signal/index.js +0 -6
- package/dist/sub-agent/index.d.ts +0 -23
- package/dist/sub-agent/index.js +0 -15
- package/dist/tool-BHbyUAy3.d.ts +0 -150
- package/dist/tool-DLXAR9Ce.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-BnpEOYV-.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-KKDrdU9Y.d.ts +0 -325
- package/dist/types-QA4WhEfz.d.ts +0 -138
- package/dist/types-QKHHQLLq.d.ts +0 -336
- package/dist/types-YuWV4ag7.d.ts +0 -72
package/dist/chunk-BFM2YHNM.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
// src/safety/approval/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/approval/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/approval/patterns.ts
|
|
53
|
-
function matchApprovalPattern(pattern, value) {
|
|
54
|
-
const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
55
|
-
return new RegExp(`^${regex}$`, "i").test(value);
|
|
56
|
-
}
|
|
57
|
-
function extractApprovalPatterns(tool, args) {
|
|
58
|
-
if (!args || typeof args !== "object") {
|
|
59
|
-
return [tool];
|
|
60
|
-
}
|
|
61
|
-
const record = args;
|
|
62
|
-
if ("path" in record && typeof record.path === "string" || "filePath" in record && typeof record.filePath === "string") {
|
|
63
|
-
const path = record.path ?? record.filePath;
|
|
64
|
-
const dir = path.substring(0, path.lastIndexOf("/") + 1);
|
|
65
|
-
return [dir ? `${dir}*` : path];
|
|
66
|
-
}
|
|
67
|
-
if ("command" in record && typeof record.command === "string") {
|
|
68
|
-
const command = record.command.split(/\s+/)[0];
|
|
69
|
-
return [command];
|
|
70
|
-
}
|
|
71
|
-
if ("pattern" in record && typeof record.pattern === "string") {
|
|
72
|
-
return [record.pattern];
|
|
73
|
-
}
|
|
74
|
-
return [tool];
|
|
75
|
-
}
|
|
76
|
-
function describeApprovalOperation(tool, args) {
|
|
77
|
-
if (!args || typeof args !== "object") {
|
|
78
|
-
return `Execute ${tool}`;
|
|
79
|
-
}
|
|
80
|
-
const record = args;
|
|
81
|
-
switch (tool) {
|
|
82
|
-
case "read":
|
|
83
|
-
case "read_file":
|
|
84
|
-
return `Read file: ${record.path ?? record.filePath}`;
|
|
85
|
-
case "write":
|
|
86
|
-
case "write_file":
|
|
87
|
-
case "create_file":
|
|
88
|
-
return `Write file: ${record.path ?? record.filePath}`;
|
|
89
|
-
case "edit":
|
|
90
|
-
case "edit_file":
|
|
91
|
-
return `Edit file: ${record.path ?? record.filePath}`;
|
|
92
|
-
case "delete_file":
|
|
93
|
-
case "remove":
|
|
94
|
-
return `Delete: ${record.path}`;
|
|
95
|
-
case "bash":
|
|
96
|
-
case "shell": {
|
|
97
|
-
const command = String(record.command);
|
|
98
|
-
return `Run command: ${command.slice(0, 100)}${command.length > 100 ? "..." : ""}`;
|
|
99
|
-
}
|
|
100
|
-
case "grep":
|
|
101
|
-
return `Search for: ${record.pattern}`;
|
|
102
|
-
case "glob":
|
|
103
|
-
return `Find files: ${record.pattern}`;
|
|
104
|
-
default:
|
|
105
|
-
return `${tool}(${JSON.stringify(args).slice(0, 50)}...)`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// src/safety/approval/handler.ts
|
|
110
|
-
var requestCounter = 0;
|
|
111
|
-
function findMatchingRule(rules, tool, patterns) {
|
|
112
|
-
for (let index = rules.length - 1; index >= 0; index--) {
|
|
113
|
-
const rule = rules[index];
|
|
114
|
-
const toolMatches = rule.tool === "*" || matchApprovalPattern(rule.tool, tool);
|
|
115
|
-
const patternMatches = patterns.some(
|
|
116
|
-
(pattern) => matchApprovalPattern(rule.pattern, pattern)
|
|
117
|
-
);
|
|
118
|
-
if (toolMatches && patternMatches) {
|
|
119
|
-
return rule;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return void 0;
|
|
123
|
-
}
|
|
124
|
-
function createApprovalHandler(config = {}) {
|
|
125
|
-
const {
|
|
126
|
-
defaultAction = "ask",
|
|
127
|
-
timeout = 5 * 60 * 1e3,
|
|
128
|
-
onRequest
|
|
129
|
-
} = config;
|
|
130
|
-
const rules = [...config.rules ?? []];
|
|
131
|
-
const pending = /* @__PURE__ */ new Map();
|
|
132
|
-
async function request(sessionId, tool, args, customRisks) {
|
|
133
|
-
const risk = getToolRisk(tool, customRisks);
|
|
134
|
-
const patterns = extractApprovalPatterns(tool, args);
|
|
135
|
-
const matchingRule = findMatchingRule(rules, tool, patterns);
|
|
136
|
-
if (matchingRule) {
|
|
137
|
-
if (matchingRule.action === "allow") {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
throw new ApprovalDeniedError(
|
|
141
|
-
tool,
|
|
142
|
-
args,
|
|
143
|
-
`Denied by rule: ${matchingRule.pattern}`
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
if (risk === "safe" && defaultAction !== "deny") {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (!onRequest) {
|
|
150
|
-
if (defaultAction === "allow") {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (defaultAction === "deny") {
|
|
154
|
-
throw new ApprovalDeniedError(tool, args);
|
|
155
|
-
}
|
|
156
|
-
throw new ApprovalDeniedError(tool, args, "No approval handler configured");
|
|
157
|
-
}
|
|
158
|
-
const id = `approval-${++requestCounter}-${Date.now()}`;
|
|
159
|
-
const requestData = {
|
|
160
|
-
id,
|
|
161
|
-
sessionId,
|
|
162
|
-
tool,
|
|
163
|
-
args,
|
|
164
|
-
description: describeApprovalOperation(tool, args),
|
|
165
|
-
risk,
|
|
166
|
-
patterns,
|
|
167
|
-
timestamp: Date.now()
|
|
168
|
-
};
|
|
169
|
-
const action = await Promise.race([
|
|
170
|
-
new Promise((resolve, reject) => {
|
|
171
|
-
pending.set(id, { resolve, reject });
|
|
172
|
-
onRequest(requestData).then(resolve).catch(reject).finally(() => pending.delete(id));
|
|
173
|
-
}),
|
|
174
|
-
new Promise((_, reject) => {
|
|
175
|
-
setTimeout(() => {
|
|
176
|
-
pending.delete(id);
|
|
177
|
-
reject(new ApprovalTimeoutError(tool, timeout));
|
|
178
|
-
}, timeout);
|
|
179
|
-
})
|
|
180
|
-
]);
|
|
181
|
-
switch (action) {
|
|
182
|
-
case "allow":
|
|
183
|
-
return;
|
|
184
|
-
case "deny":
|
|
185
|
-
throw new ApprovalDeniedError(tool, args);
|
|
186
|
-
case "remember":
|
|
187
|
-
for (const pattern of patterns) {
|
|
188
|
-
rules.push({ pattern, tool, action: "allow" });
|
|
189
|
-
}
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function cancelAll(reason) {
|
|
194
|
-
for (const [id, { reject }] of pending) {
|
|
195
|
-
reject(new Error(reason ?? "Cancelled"));
|
|
196
|
-
pending.delete(id);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
function addRule(rule) {
|
|
200
|
-
rules.push(rule);
|
|
201
|
-
}
|
|
202
|
-
function getRules() {
|
|
203
|
-
return rules;
|
|
204
|
-
}
|
|
205
|
-
function clearSessionRules() {
|
|
206
|
-
rules.length = config.rules?.length ?? 0;
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
request,
|
|
210
|
-
cancelAll,
|
|
211
|
-
addRule,
|
|
212
|
-
getRules,
|
|
213
|
-
clearSessionRules
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export {
|
|
218
|
-
getToolRisk,
|
|
219
|
-
ApprovalDeniedError,
|
|
220
|
-
ApprovalTimeoutError,
|
|
221
|
-
createApprovalHandler
|
|
222
|
-
};
|
package/dist/chunk-DWYX7ASF.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// src/models/identifiers.ts
|
|
2
|
-
function getModelId(model) {
|
|
3
|
-
if (typeof model === "string") return model;
|
|
4
|
-
if (typeof model === "object" && model !== null && "modelId" in model) {
|
|
5
|
-
return String(model.modelId);
|
|
6
|
-
}
|
|
7
|
-
return String(model);
|
|
8
|
-
}
|
|
9
|
-
function getProviderId(model) {
|
|
10
|
-
if (typeof model === "string") {
|
|
11
|
-
if (model.includes("/")) {
|
|
12
|
-
return model.split("/")[0];
|
|
13
|
-
}
|
|
14
|
-
return void 0;
|
|
15
|
-
}
|
|
16
|
-
if (typeof model === "object" && model !== null && "provider" in model) {
|
|
17
|
-
const provider = String(model.provider);
|
|
18
|
-
return provider.split(".")[0];
|
|
19
|
-
}
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
getModelId,
|
|
25
|
-
getProviderId
|
|
26
|
-
};
|
package/dist/chunk-KUVSERLJ.js
DELETED
|
@@ -1,50 +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
|
-
set.add(handler);
|
|
14
|
-
return () => {
|
|
15
|
-
set.delete(handler);
|
|
16
|
-
if (set.size === 0) this.typed.delete(type);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
onAny(handler) {
|
|
20
|
-
this.wildcard.add(handler);
|
|
21
|
-
return () => {
|
|
22
|
-
this.wildcard.delete(handler);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
emit(event) {
|
|
26
|
-
const set = this.typed.get(event.type);
|
|
27
|
-
if (set) {
|
|
28
|
-
for (const fn of set) {
|
|
29
|
-
try {
|
|
30
|
-
fn(event);
|
|
31
|
-
} catch {
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
for (const fn of this.wildcard) {
|
|
36
|
-
try {
|
|
37
|
-
fn(event);
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
clear() {
|
|
43
|
-
this.typed.clear();
|
|
44
|
-
this.wildcard.clear();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
LocalSignal
|
|
50
|
-
};
|
package/dist/chunk-N7P4PN3O.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// src/scope/store.ts
|
|
2
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
-
import { randomUUID } from "crypto";
|
|
4
|
-
var scopeStore = new AsyncLocalStorage();
|
|
5
|
-
function cloneAttributes(attributes) {
|
|
6
|
-
return { ...attributes };
|
|
7
|
-
}
|
|
8
|
-
function cloneScope(scope) {
|
|
9
|
-
return {
|
|
10
|
-
...scope,
|
|
11
|
-
attributes: cloneAttributes(scope.attributes)
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
function getStoredScope() {
|
|
15
|
-
return scopeStore.getStore();
|
|
16
|
-
}
|
|
17
|
-
function buildScope(options, current) {
|
|
18
|
-
const parent = options.parent === void 0 ? current : options.parent ?? void 0;
|
|
19
|
-
const id = options.id ?? randomUUID();
|
|
20
|
-
return {
|
|
21
|
-
id,
|
|
22
|
-
rootId: parent?.rootId ?? id,
|
|
23
|
-
kind: options.kind,
|
|
24
|
-
name: options.name,
|
|
25
|
-
parentId: parent?.id,
|
|
26
|
-
depth: (parent?.depth ?? -1) + 1,
|
|
27
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
28
|
-
sessionId: options.sessionId ?? parent?.sessionId,
|
|
29
|
-
taskId: options.taskId ?? parent?.taskId,
|
|
30
|
-
step: options.step ?? parent?.step,
|
|
31
|
-
attributes: cloneAttributes(options.attributes ?? {})
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function runWithScope(scope, fn) {
|
|
35
|
-
return Promise.resolve(scopeStore.run(scope, fn));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// src/scope/run.ts
|
|
39
|
-
function currentScope() {
|
|
40
|
-
const scope = getStoredScope();
|
|
41
|
-
return scope ? cloneScope(scope) : void 0;
|
|
42
|
-
}
|
|
43
|
-
function snapshotScope(scope = getStoredScope()) {
|
|
44
|
-
return scope ? cloneScope(scope) : void 0;
|
|
45
|
-
}
|
|
46
|
-
function createScope(options) {
|
|
47
|
-
return buildScope(options, getStoredScope());
|
|
48
|
-
}
|
|
49
|
-
function withinScope(options, fn) {
|
|
50
|
-
return runWithScope(buildScope(options, getStoredScope()), fn);
|
|
51
|
-
}
|
|
52
|
-
function restoreScope(snapshot, fn) {
|
|
53
|
-
if (!snapshot) {
|
|
54
|
-
return Promise.resolve(fn());
|
|
55
|
-
}
|
|
56
|
-
return runWithScope(cloneScope(snapshot), fn);
|
|
57
|
-
}
|
|
58
|
-
async function* streamWithinScope(options, iterable) {
|
|
59
|
-
const scope = buildScope(options, getStoredScope());
|
|
60
|
-
const iterator = await runWithScope(scope, () => iterable[Symbol.asyncIterator]());
|
|
61
|
-
try {
|
|
62
|
-
while (true) {
|
|
63
|
-
const next = await runWithScope(scope, () => iterator.next());
|
|
64
|
-
if (next.done) {
|
|
65
|
-
return next.value;
|
|
66
|
-
}
|
|
67
|
-
yield next.value;
|
|
68
|
-
}
|
|
69
|
-
} finally {
|
|
70
|
-
const returnFn = iterator.return?.bind(iterator);
|
|
71
|
-
if (returnFn) {
|
|
72
|
-
await runWithScope(scope, () => returnFn(void 0));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
currentScope,
|
|
79
|
-
snapshotScope,
|
|
80
|
-
createScope,
|
|
81
|
-
withinScope,
|
|
82
|
-
restoreScope,
|
|
83
|
-
streamWithinScope
|
|
84
|
-
};
|
package/dist/chunk-SDSBEQXG.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// src/tool/registry.ts
|
|
2
|
-
var ToolRegistry = class {
|
|
3
|
-
tools = /* @__PURE__ */ new Map();
|
|
4
|
-
groups = /* @__PURE__ */ new Map();
|
|
5
|
-
// --------------------------------------------------------------------------
|
|
6
|
-
// Tool registration
|
|
7
|
-
// --------------------------------------------------------------------------
|
|
8
|
-
/**
|
|
9
|
-
* Register a tool. Throws if a tool with the same ID is already registered.
|
|
10
|
-
* Use `set()` for upsert semantics.
|
|
11
|
-
*/
|
|
12
|
-
register(tool) {
|
|
13
|
-
if (this.tools.has(tool.id)) {
|
|
14
|
-
throw new Error(`Tool '${tool.id}' is already registered`);
|
|
15
|
-
}
|
|
16
|
-
this.tools.set(tool.id, tool);
|
|
17
|
-
}
|
|
18
|
-
/** Register multiple tools (throws on duplicates). */
|
|
19
|
-
registerAll(tools) {
|
|
20
|
-
for (const tool of tools) {
|
|
21
|
-
this.register(tool);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/** Register or replace a tool (upsert). */
|
|
25
|
-
set(tool) {
|
|
26
|
-
this.tools.set(tool.id, tool);
|
|
27
|
-
}
|
|
28
|
-
/** Unregister a tool by ID. Returns `true` if it existed. */
|
|
29
|
-
unregister(id) {
|
|
30
|
-
return this.tools.delete(id);
|
|
31
|
-
}
|
|
32
|
-
/** Get a tool by ID. */
|
|
33
|
-
get(id) {
|
|
34
|
-
return this.tools.get(id);
|
|
35
|
-
}
|
|
36
|
-
/** Check if a tool is registered. */
|
|
37
|
-
has(id) {
|
|
38
|
-
return this.tools.has(id);
|
|
39
|
-
}
|
|
40
|
-
/** Get all tool IDs. */
|
|
41
|
-
ids() {
|
|
42
|
-
return Array.from(this.tools.keys());
|
|
43
|
-
}
|
|
44
|
-
/** Get all tools. */
|
|
45
|
-
all() {
|
|
46
|
-
return Array.from(this.tools.values());
|
|
47
|
-
}
|
|
48
|
-
/** Clear all tools and groups. */
|
|
49
|
-
clear() {
|
|
50
|
-
this.tools.clear();
|
|
51
|
-
this.groups.clear();
|
|
52
|
-
}
|
|
53
|
-
/** Number of registered tools. */
|
|
54
|
-
get size() {
|
|
55
|
-
return this.tools.size;
|
|
56
|
-
}
|
|
57
|
-
// --------------------------------------------------------------------------
|
|
58
|
-
// Group management
|
|
59
|
-
// --------------------------------------------------------------------------
|
|
60
|
-
/**
|
|
61
|
-
* Register a named group of tool IDs.
|
|
62
|
-
* The group name can be used in `resolve()` specs.
|
|
63
|
-
* Tool IDs don't need to be registered yet — resolution is lazy.
|
|
64
|
-
*/
|
|
65
|
-
registerGroup(name, toolIds) {
|
|
66
|
-
this.groups.set(name, toolIds);
|
|
67
|
-
}
|
|
68
|
-
/** Get tools in a group (only returns registered tools). */
|
|
69
|
-
getGroup(name) {
|
|
70
|
-
const ids = this.groups.get(name);
|
|
71
|
-
if (!ids) return void 0;
|
|
72
|
-
return ids.map((id) => this.tools.get(id)).filter((t) => t !== void 0);
|
|
73
|
-
}
|
|
74
|
-
/** Check if a group is registered. */
|
|
75
|
-
hasGroup(name) {
|
|
76
|
-
return this.groups.has(name);
|
|
77
|
-
}
|
|
78
|
-
/** List all group names. */
|
|
79
|
-
listGroups() {
|
|
80
|
-
return Array.from(this.groups.keys());
|
|
81
|
-
}
|
|
82
|
-
// --------------------------------------------------------------------------
|
|
83
|
-
// Resolution
|
|
84
|
-
// --------------------------------------------------------------------------
|
|
85
|
-
/**
|
|
86
|
-
* Resolve a `ToolSpec` to an array of tools.
|
|
87
|
-
*
|
|
88
|
-
* Supports group names, individual tool IDs, comma-separated strings,
|
|
89
|
-
* exclusions with `-` prefix, booleans, and pass-through arrays.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```typescript
|
|
93
|
-
* registry.resolve("read-only"); // group name
|
|
94
|
-
* registry.resolve("read,grep,glob"); // comma-separated IDs
|
|
95
|
-
* registry.resolve("all,-bash"); // all except bash
|
|
96
|
-
* registry.resolve(["read", "grep"]); // array of IDs
|
|
97
|
-
* registry.resolve(true); // all registered tools
|
|
98
|
-
* registry.resolve(false); // empty array
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
resolve(spec) {
|
|
102
|
-
if (spec === true) return this.all();
|
|
103
|
-
if (spec === false) return [];
|
|
104
|
-
if (Array.isArray(spec) && spec.length > 0 && typeof spec[0] !== "string") {
|
|
105
|
-
return spec;
|
|
106
|
-
}
|
|
107
|
-
const tokens = Array.isArray(spec) ? spec : spec.split(",").map((s) => s.trim()).filter(Boolean);
|
|
108
|
-
const includes = [];
|
|
109
|
-
const excludes = [];
|
|
110
|
-
for (const token of tokens) {
|
|
111
|
-
if (token.startsWith("-")) {
|
|
112
|
-
excludes.push(token.slice(1));
|
|
113
|
-
} else {
|
|
114
|
-
includes.push(token);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const result = /* @__PURE__ */ new Map();
|
|
118
|
-
if (includes.length === 0 && excludes.length > 0) {
|
|
119
|
-
for (const [id, tool] of this.tools) {
|
|
120
|
-
result.set(id, tool);
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
for (const token of includes) {
|
|
124
|
-
if (token === "all") {
|
|
125
|
-
for (const [id, tool] of this.tools) {
|
|
126
|
-
result.set(id, tool);
|
|
127
|
-
}
|
|
128
|
-
} else if (this.groups.has(token)) {
|
|
129
|
-
const ids = this.groups.get(token);
|
|
130
|
-
for (const id of ids) {
|
|
131
|
-
const tool = this.tools.get(id);
|
|
132
|
-
if (tool) result.set(id, tool);
|
|
133
|
-
}
|
|
134
|
-
} else if (this.tools.has(token)) {
|
|
135
|
-
result.set(token, this.tools.get(token));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
for (const id of excludes) {
|
|
140
|
-
if (this.groups.has(id)) {
|
|
141
|
-
const ids = this.groups.get(id);
|
|
142
|
-
for (const gid of ids) {
|
|
143
|
-
result.delete(gid);
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
result.delete(id);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return Array.from(result.values());
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
var defaultRegistry = new ToolRegistry();
|
|
153
|
-
|
|
154
|
-
export {
|
|
155
|
-
ToolRegistry,
|
|
156
|
-
defaultRegistry
|
|
157
|
-
};
|