@dudko.dev/agent-web 0.0.41 → 0.0.42
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 +7 -3
- package/dist/agent-web.js +133 -133
- package/dist/agent-web.js.map +1 -1
- package/dist/{chunk-4FBTBE74.js → chunk-2MLHZ6LQ.js} +2 -2
- package/dist/{chunk-L7Y3QRAM.js → chunk-DAREMCXF.js} +2 -2
- package/dist/{chunk-YUA2BHRM.js → chunk-ZSZSSJS4.js} +402 -13
- package/dist/chunk-ZSZSSJS4.js.map +1 -0
- package/dist/{elicitation-BA1knkdA.d.cts → elicitation-DS-84_bF.d.cts} +123 -9
- package/dist/{elicitation-BA1knkdA.d.ts → elicitation-DS-84_bF.d.ts} +123 -9
- package/dist/index.cjs +145 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +69 -23
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +352 -9
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +12 -6
- package/dist/mcp.d.ts +12 -6
- package/dist/mcp.js +8 -3
- package/dist/mcp.js.map +1 -1
- package/dist/{sandbox-ZDQIIZS7.js → sandbox-3VRX47UY.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-YUA2BHRM.js.map +0 -1
- /package/dist/{chunk-4FBTBE74.js.map → chunk-2MLHZ6LQ.js.map} +0 -0
- /package/dist/{chunk-L7Y3QRAM.js.map → chunk-DAREMCXF.js.map} +0 -0
- /package/dist/{sandbox-ZDQIIZS7.js.map → sandbox-3VRX47UY.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
KEYS_STORE,
|
|
3
3
|
SECRETS_STORE,
|
|
4
4
|
openAgentWebDB
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZSZSSJS4.js";
|
|
6
6
|
|
|
7
7
|
// src/logger.ts
|
|
8
8
|
var WEIGHT = {
|
|
@@ -507,4 +507,4 @@ export {
|
|
|
507
507
|
mcpAppDownloadOf,
|
|
508
508
|
describeMcpAppPolicy
|
|
509
509
|
};
|
|
510
|
-
//# sourceMappingURL=chunk-
|
|
510
|
+
//# sourceMappingURL=chunk-2MLHZ6LQ.js.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
FILES_STORE,
|
|
3
3
|
createMcpSkillGrants,
|
|
4
4
|
openAgentWebDB
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-ZSZSSJS4.js";
|
|
6
6
|
|
|
7
7
|
// src/limits.ts
|
|
8
8
|
var over = (value, cap2) => typeof cap2 === "number" && cap2 > 0 && (value ?? 0) >= cap2;
|
|
@@ -929,4 +929,4 @@ export {
|
|
|
929
929
|
fileToolBindingOf,
|
|
930
930
|
createFileTools
|
|
931
931
|
};
|
|
932
|
-
//# sourceMappingURL=chunk-
|
|
932
|
+
//# sourceMappingURL=chunk-DAREMCXF.js.map
|
|
@@ -38,7 +38,7 @@ var mcpSkillFilePath = (skillUri, fileUri) => {
|
|
|
38
38
|
}
|
|
39
39
|
return path;
|
|
40
40
|
};
|
|
41
|
-
var mcpSkillEntryRefusal = (entry) => {
|
|
41
|
+
var mcpSkillEntryRefusal = (entry, options = {}) => {
|
|
42
42
|
if (!isRecord(entry) || typeof entry.uri !== "string") return "not a skill entry (no uri)";
|
|
43
43
|
const path = mcpSkillPath(entry.uri);
|
|
44
44
|
if (!path) return `${entry.uri} is not the SKILL.md of a named skill directory`;
|
|
@@ -55,6 +55,7 @@ var mcpSkillEntryRefusal = (entry) => {
|
|
|
55
55
|
if (!oneLine(frontmatter.description)) return "the frontmatter has no description";
|
|
56
56
|
const resources = entry.resources;
|
|
57
57
|
if (resources === "dynamic") {
|
|
58
|
+
if (options.dynamic === true) return void 0;
|
|
58
59
|
return 'its content is generated ("resources": "dynamic"): there are no digests to verify it against';
|
|
59
60
|
}
|
|
60
61
|
if (!Array.isArray(resources)) return 'the entry does not list its files ("resources")';
|
|
@@ -100,7 +101,8 @@ var mcpSkillRecordOf = (entry) => {
|
|
|
100
101
|
name: entry.frontmatter.name,
|
|
101
102
|
description: oneLine(entry.frontmatter.description),
|
|
102
103
|
path: mcpSkillPath(entry.uri) ?? [entry.frontmatter.name],
|
|
103
|
-
files
|
|
104
|
+
files,
|
|
105
|
+
...entry.resources === "dynamic" ? { dynamic: true } : {}
|
|
104
106
|
};
|
|
105
107
|
};
|
|
106
108
|
var labelOf = (server) => (server.replace(/[^a-zA-Z0-9_-]/g, "_") || "_").slice(0, MCP_SKILL_SERVER_LABEL_MAX_CHARS);
|
|
@@ -138,9 +140,9 @@ var selectMcpSkills = (servers, caps = {}) => {
|
|
|
138
140
|
var clipped = (text, max, what) => text.length > max ? `${text.slice(0, max)}
|
|
139
141
|
\u2026 [${what} cut at ${max} characters; the rest is not shown]` : text;
|
|
140
142
|
var shownUri = (uri) => oneLine(uri).replace(/[[\]]/g, "").slice(0, 200);
|
|
141
|
-
var mcpSkillTag = (server) => `[from the MCP server "${labelOf(server)}" - third-party]`;
|
|
142
|
-
var mcpSkillDescription = (description, server) => {
|
|
143
|
-
const tag = ` ${mcpSkillTag(server)}`;
|
|
143
|
+
var mcpSkillTag = (server, dynamic = false) => `[from the MCP server "${labelOf(server)}" - third-party${dynamic ? ", no checksums" : ""}]`;
|
|
144
|
+
var mcpSkillDescription = (description, server, dynamic = false) => {
|
|
145
|
+
const tag = ` ${mcpSkillTag(server, dynamic)}`;
|
|
144
146
|
const room = Math.max(0, MCP_SKILL_DESCRIPTION_MAX_CHARS - tag.length);
|
|
145
147
|
const text = oneLine(description);
|
|
146
148
|
return `${text.length > room ? `${text.slice(0, Math.max(0, room - 1))}\u2026` : text}${tag}`;
|
|
@@ -174,6 +176,133 @@ var resolveMcpSkillFile = (files, requested) => {
|
|
|
174
176
|
}
|
|
175
177
|
return { path };
|
|
176
178
|
};
|
|
179
|
+
var MCP_SKILL_DIRECTORY_ENTRIES_MAX = MCP_SKILL_MAX_RESOURCES + 128;
|
|
180
|
+
var MCP_SKILL_DIRECTORY_MIME_TYPE = "inode/directory";
|
|
181
|
+
var skillDirectoryRef = (requested) => {
|
|
182
|
+
if (typeof requested !== "string") return { refused: "no directory path given" };
|
|
183
|
+
const raw = requested.trim();
|
|
184
|
+
if (raw === "" || raw === "." || raw === "./" || raw === "/") return { dir: "" };
|
|
185
|
+
const refused = { refused: `"${oneLine(requested)}" is not a directory inside the skill` };
|
|
186
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(raw) || raw.startsWith("/") || /[?#\\]/.test(raw)) {
|
|
187
|
+
return refused;
|
|
188
|
+
}
|
|
189
|
+
const dir = raw.replace(/^\.\/+/, "").replace(/\/+$/, "");
|
|
190
|
+
if (!dir) return { dir: "" };
|
|
191
|
+
if (dir.split("/").some((s) => !s || s === "." || s === "..")) return refused;
|
|
192
|
+
return { dir };
|
|
193
|
+
};
|
|
194
|
+
var isPlainPath = (path) => path.split("/").every((s) => s !== "" && s !== "." && s !== "..");
|
|
195
|
+
var skillDirectoryChildren = (paths, dir) => {
|
|
196
|
+
const prefix = dir ? `${dir}/` : "";
|
|
197
|
+
const files = /* @__PURE__ */ new Set();
|
|
198
|
+
const directories = /* @__PURE__ */ new Set();
|
|
199
|
+
for (const path of paths) {
|
|
200
|
+
if (typeof path !== "string" || !isPlainPath(path) || !path.startsWith(prefix)) continue;
|
|
201
|
+
const rest = path.slice(prefix.length);
|
|
202
|
+
const cut = rest.indexOf("/");
|
|
203
|
+
if (cut < 0) files.add(path);
|
|
204
|
+
else directories.add(`${prefix}${rest.slice(0, cut)}`);
|
|
205
|
+
}
|
|
206
|
+
if (dir && !files.size && !directories.size) return void 0;
|
|
207
|
+
return { files: [...files].sort(), directories: [...directories].sort() };
|
|
208
|
+
};
|
|
209
|
+
var skillDirectoryOf = (paths, requested) => {
|
|
210
|
+
const ref = skillDirectoryRef(requested);
|
|
211
|
+
if ("refused" in ref) return void 0;
|
|
212
|
+
const children = skillDirectoryChildren(paths, ref.dir);
|
|
213
|
+
return children ? { dir: ref.dir, ...children } : void 0;
|
|
214
|
+
};
|
|
215
|
+
var resolveMcpSkillPath = (files, requested) => {
|
|
216
|
+
const file = resolveMcpSkillFile(files, requested);
|
|
217
|
+
if ("path" in file) return file;
|
|
218
|
+
return skillDirectoryOf(files, requested) ?? file;
|
|
219
|
+
};
|
|
220
|
+
var canonicalUriOf = (uri) => {
|
|
221
|
+
try {
|
|
222
|
+
const url = new URL(uri);
|
|
223
|
+
url.hash = "";
|
|
224
|
+
return url.href;
|
|
225
|
+
} catch {
|
|
226
|
+
return void 0;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var decodedSegment = (segment) => segment.replace(/(?:%[0-9A-Fa-f]{2})+/g, (run) => {
|
|
230
|
+
let out = "";
|
|
231
|
+
for (let at = 0; at < run.length; ) {
|
|
232
|
+
const lead = Number.parseInt(run.slice(at + 1, at + 3), 16);
|
|
233
|
+
const width = 3 * (lead >= 240 ? 4 : lead >= 224 ? 3 : lead >= 192 ? 2 : 1);
|
|
234
|
+
try {
|
|
235
|
+
out += decodeURIComponent(run.slice(at, at + width));
|
|
236
|
+
at += width;
|
|
237
|
+
} catch {
|
|
238
|
+
out += run.slice(at, at + 3);
|
|
239
|
+
at += 3;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
});
|
|
244
|
+
var isPlainName = (name) => name !== "" && name !== "." && name !== ".." && !name.includes("/") && !name.includes("\0");
|
|
245
|
+
var compareMcpSkillDirectory = (o) => {
|
|
246
|
+
const own = skillDirectoryChildren(o.manifest, o.dir) ?? { files: [], directories: [] };
|
|
247
|
+
const root = canonicalUriOf(o.root);
|
|
248
|
+
if (!root) return { extra: 0, notServed: [], truncated: false };
|
|
249
|
+
const at = o.dir ? o.dir.split("/").map(decodedSegment) : [];
|
|
250
|
+
const nameOf = (path) => decodedSegment(path.slice(path.lastIndexOf("/") + 1));
|
|
251
|
+
const ownFiles = new Map(own.files.map((p) => [nameOf(p), p]));
|
|
252
|
+
const ownDirectories = new Map(own.directories.map((p) => [nameOf(p), p]));
|
|
253
|
+
const truncated = o.live.length > MCP_SKILL_DIRECTORY_ENTRIES_MAX;
|
|
254
|
+
const seen = /* @__PURE__ */ new Set();
|
|
255
|
+
const extra = /* @__PURE__ */ new Set();
|
|
256
|
+
for (const item of o.live.slice(0, MCP_SKILL_DIRECTORY_ENTRIES_MAX)) {
|
|
257
|
+
if (!isRecord(item) || typeof item.uri !== "string") continue;
|
|
258
|
+
const uri = canonicalUriOf(item.uri);
|
|
259
|
+
if (!uri || uri.includes("?") || !uri.startsWith(`${root}/`)) continue;
|
|
260
|
+
const segments = uri.slice(root.length + 1).split("/").map(decodedSegment);
|
|
261
|
+
if (segments.length !== at.length + 1 || !segments.every(isPlainName)) continue;
|
|
262
|
+
if (at.some((s, i) => segments[i] !== s)) continue;
|
|
263
|
+
const name = segments[segments.length - 1];
|
|
264
|
+
const kind = typeof item.mimeType !== "string" ? "any" : item.mimeType === MCP_SKILL_DIRECTORY_MIME_TYPE ? "directory" : "file";
|
|
265
|
+
const file = kind !== "directory" ? ownFiles.get(name) : void 0;
|
|
266
|
+
const directory = kind !== "file" ? ownDirectories.get(name) : void 0;
|
|
267
|
+
if (file !== void 0) seen.add(file);
|
|
268
|
+
if (directory !== void 0) seen.add(directory);
|
|
269
|
+
if (file === void 0 && directory === void 0) extra.add(`${kind} ${name}`);
|
|
270
|
+
}
|
|
271
|
+
const notServed = truncated ? [] : [...own.directories, ...own.files].filter((p) => !seen.has(p)).sort();
|
|
272
|
+
return { extra: extra.size, notServed, truncated };
|
|
273
|
+
};
|
|
274
|
+
var mcpSkillDirectoryNote = (extra, notServed, truncated = false) => {
|
|
275
|
+
const parts = [];
|
|
276
|
+
if (extra > 0) {
|
|
277
|
+
parts.push(
|
|
278
|
+
`The server now lists ${truncated ? "at least " : ""}${extra} more item(s) here than the approved entry of this skill: the skill changed on the server. They are not shown and cannot be read under the current approval.`
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (notServed > 0) {
|
|
282
|
+
parts.push(
|
|
283
|
+
`${notServed} item(s) listed here (notServed) are no longer listed by the server: a read of them will fail - the skill changed on the server.`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
if (!parts.length) return void 0;
|
|
287
|
+
return `${parts.join(" ")} The skill is read again, and asked about again, when the server's skills are refreshed.`;
|
|
288
|
+
};
|
|
289
|
+
var skillDirectoryListing = (name, dir, children, drift) => {
|
|
290
|
+
const directories = children.directories.slice(0, MCP_SKILL_FILES_SHOWN_MAX);
|
|
291
|
+
const files = children.files.slice(0, MCP_SKILL_FILES_SHOWN_MAX - directories.length);
|
|
292
|
+
const more = children.files.length + children.directories.length - files.length - directories.length;
|
|
293
|
+
const shown = /* @__PURE__ */ new Set([...directories, ...files]);
|
|
294
|
+
const notServed = drift ? drift.notServed.filter((p) => shown.has(p)) : [];
|
|
295
|
+
const note = drift ? mcpSkillDirectoryNote(drift.extra, notServed.length, drift.truncated) : void 0;
|
|
296
|
+
return {
|
|
297
|
+
name,
|
|
298
|
+
directory: dir || ".",
|
|
299
|
+
files,
|
|
300
|
+
directories,
|
|
301
|
+
...more > 0 ? { more } : {},
|
|
302
|
+
...notServed.length ? { notServed } : {},
|
|
303
|
+
...note ? { note } : {}
|
|
304
|
+
};
|
|
305
|
+
};
|
|
177
306
|
var MCP_SKILL_URI_MAX_CHARS = 512;
|
|
178
307
|
var mcpSkillUriRefusal = (uri) => {
|
|
179
308
|
if (typeof uri !== "string" || !uri) return "no skill URI given";
|
|
@@ -256,10 +385,20 @@ var mcpSkillsSettingOf = (setting, server) => {
|
|
|
256
385
|
if (setting === true) return { on: true };
|
|
257
386
|
if (isRecord(setting)) {
|
|
258
387
|
const consent = mcpSkillConsentOf(setting.consent, `${server}: skills.consent`);
|
|
259
|
-
|
|
388
|
+
const dynamic = setting.dynamic;
|
|
389
|
+
if (dynamic !== void 0 && typeof dynamic !== "boolean") {
|
|
390
|
+
throw new Error(
|
|
391
|
+
`${server}: skills.dynamic must be true or false, got ${JSON.stringify(dynamic)}`
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
return {
|
|
395
|
+
on: true,
|
|
396
|
+
...consent ? { consent } : {},
|
|
397
|
+
...dynamic === true ? { dynamic: true } : {}
|
|
398
|
+
};
|
|
260
399
|
}
|
|
261
400
|
throw new Error(
|
|
262
|
-
`${server}: skills must be true, false or { consent?: ${consentList} }, got ${JSON.stringify(setting)}`
|
|
401
|
+
`${server}: skills must be true, false or { consent?: ${consentList}, dynamic?: boolean }, got ${JSON.stringify(setting)}`
|
|
263
402
|
);
|
|
264
403
|
};
|
|
265
404
|
var resolveMcpSkillConsent = (server, agent) => server ?? agent ?? MCP_SKILL_CONSENT_DEFAULT;
|
|
@@ -310,6 +449,7 @@ var mcpSkillConsentView = (o) => {
|
|
|
310
449
|
body: mcpSkillBodyPreview(o.body),
|
|
311
450
|
...o.byUri ? { byUri: true } : {},
|
|
312
451
|
...o.nestedIn ? { nestedIn: oneLine(o.nestedIn).slice(0, 200) } : {},
|
|
452
|
+
...o.snapshot ? { dynamic: true, ...o.snapshot.listed ? {} : { noFileListing: true } } : {},
|
|
313
453
|
consent: o.consent
|
|
314
454
|
};
|
|
315
455
|
};
|
|
@@ -319,6 +459,78 @@ var mcpSkillDeniedMessage = (name, server, why, detail) => {
|
|
|
319
459
|
const head = why === "denied" ? `The user did not allow ${what} to be loaded${said}` : why === "denied-earlier" ? `The user already refused ${what} in this task` : why === "no-one-to-ask" ? `${what[0].toUpperCase()}${what.slice(1)} is loaded only with a person's consent, and no one can be asked (no approval handler is configured)` : `No one answered whether ${what} may be loaded${said}`;
|
|
320
460
|
return `${head}: nothing of it is in your context. Do not load it again in this task; continue without it, or say what it would have been needed for.`;
|
|
321
461
|
};
|
|
462
|
+
var MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES = 64;
|
|
463
|
+
var MCP_SKILL_SNAPSHOT_MAX_DEPTH = 8;
|
|
464
|
+
var MCP_SKILL_SNAPSHOTS_MAX_BYTES = 64 * 1024 * 1024;
|
|
465
|
+
var createMcpSkillSnapshotMemory = () => ({ used: 0 });
|
|
466
|
+
var mcpSkillSnapshotBytesRefusal = (bytes, held = 0) => {
|
|
467
|
+
if (bytes > MCP_SKILL_MAX_TOTAL_BYTES) {
|
|
468
|
+
return `its files take more than ${MCP_SKILL_MAX_TOTAL_BYTES} bytes (the limit for one skill)`;
|
|
469
|
+
}
|
|
470
|
+
if (held + bytes > MCP_SKILL_SNAPSHOTS_MAX_BYTES) {
|
|
471
|
+
return `the copies of generated skills this agent holds would pass ${MCP_SKILL_SNAPSHOTS_MAX_BYTES} bytes (${held} held, ${bytes} read of this one)`;
|
|
472
|
+
}
|
|
473
|
+
return void 0;
|
|
474
|
+
};
|
|
475
|
+
var startMcpSkillWalk = (skillUri) => {
|
|
476
|
+
const root = canonicalUriOf(skillUri.slice(0, -"/SKILL.md".length));
|
|
477
|
+
if (!root || root.includes("?")) return void 0;
|
|
478
|
+
return {
|
|
479
|
+
root,
|
|
480
|
+
pending: [{ path: "", depth: 0 }],
|
|
481
|
+
directories: /* @__PURE__ */ new Set([""]),
|
|
482
|
+
files: [],
|
|
483
|
+
seen: /* @__PURE__ */ new Set(["SKILL.md"])
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
var nextMcpSkillWalkDirectory = (walk) => {
|
|
487
|
+
const next = walk.pending.shift();
|
|
488
|
+
if (!next) return void 0;
|
|
489
|
+
return { ...next, uri: next.path ? `${walk.root}/${next.path}` : walk.root };
|
|
490
|
+
};
|
|
491
|
+
var takeMcpSkillWalkListing = (walk, at, live) => {
|
|
492
|
+
const parent = at.path ? at.path.split("/").map(decodedSegment) : [];
|
|
493
|
+
for (const item of live) {
|
|
494
|
+
if (!isRecord(item) || typeof item.uri !== "string") continue;
|
|
495
|
+
const uri = canonicalUriOf(item.uri);
|
|
496
|
+
if (!uri || uri.includes("?") || !uri.startsWith(`${walk.root}/`)) continue;
|
|
497
|
+
const path = uri.slice(walk.root.length + 1);
|
|
498
|
+
if (path.includes("\\")) continue;
|
|
499
|
+
const segments = path.split("/").map(decodedSegment);
|
|
500
|
+
if (segments.length !== parent.length + 1 || !segments.every(isPlainName)) continue;
|
|
501
|
+
if (parent.some((s, i) => segments[i] !== s)) continue;
|
|
502
|
+
const key = segments.join("/");
|
|
503
|
+
if (walk.directories.has(key) || walk.seen.has(key)) continue;
|
|
504
|
+
if (item.mimeType === MCP_SKILL_DIRECTORY_MIME_TYPE) {
|
|
505
|
+
if (at.depth + 1 > MCP_SKILL_SNAPSHOT_MAX_DEPTH) {
|
|
506
|
+
return `its directories go deeper than ${MCP_SKILL_SNAPSHOT_MAX_DEPTH} levels (${shownUri(uri)})`;
|
|
507
|
+
}
|
|
508
|
+
if (walk.directories.size + 1 > MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES) {
|
|
509
|
+
return `it has more than ${MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES} directories to read`;
|
|
510
|
+
}
|
|
511
|
+
walk.directories.add(key);
|
|
512
|
+
walk.pending.push({ path, depth: at.depth + 1 });
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (walk.files.length + 2 > MCP_SKILL_MAX_RESOURCES) {
|
|
516
|
+
return `it holds more than ${MCP_SKILL_MAX_RESOURCES} files (SKILL.md included; the limit)`;
|
|
517
|
+
}
|
|
518
|
+
walk.seen.add(key);
|
|
519
|
+
walk.files.push(path);
|
|
520
|
+
}
|
|
521
|
+
return void 0;
|
|
522
|
+
};
|
|
523
|
+
var mcpSkillSnapshotEntry = (entry, files) => ({
|
|
524
|
+
uri: entry.uri,
|
|
525
|
+
frontmatter: entry.frontmatter,
|
|
526
|
+
resources: files.map(({ uri, size, digest }) => ({ uri, size, digest }))
|
|
527
|
+
});
|
|
528
|
+
var mcpSkillSha256 = async (bytes) => {
|
|
529
|
+
const subtle = globalThis.crypto?.subtle;
|
|
530
|
+
if (!subtle) throw new Error("no WebCrypto (globalThis.crypto.subtle) to compute a digest with");
|
|
531
|
+
const hash = new Uint8Array(await subtle.digest("SHA-256", bytes));
|
|
532
|
+
return `sha256:${Array.from(hash, (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
533
|
+
};
|
|
322
534
|
var MCP_SKILLS_MARK = /* @__PURE__ */ Symbol.for("@dudko.dev/agent:mcp-skills");
|
|
323
535
|
var markMcpSkills = (tool, source) => {
|
|
324
536
|
Object.defineProperty(tool, MCP_SKILLS_MARK, {
|
|
@@ -361,12 +573,164 @@ var mcpSkillGetFailure = (err) => {
|
|
|
361
573
|
return typeof code === "number" ? `${messageOf(err)} (${code})` : messageOf(err);
|
|
362
574
|
};
|
|
363
575
|
var createMcpSkillCatalog = (server, client, log, options = {}) => {
|
|
576
|
+
const admission = { dynamic: options.dynamic === true };
|
|
577
|
+
const digest = options.digest ?? mcpSkillSha256;
|
|
364
578
|
let records = [];
|
|
365
579
|
let entries = /* @__PURE__ */ new Map();
|
|
366
580
|
const added = /* @__PURE__ */ new Map();
|
|
367
581
|
const entryOf = (uri) => entries.get(uri) ?? added.get(uri)?.entry;
|
|
368
582
|
const held = /* @__PURE__ */ new WeakMap();
|
|
369
583
|
const files = /* @__PURE__ */ new WeakMap();
|
|
584
|
+
const changed = /* @__PURE__ */ new WeakSet();
|
|
585
|
+
const copies = /* @__PURE__ */ new WeakMap();
|
|
586
|
+
const snapshotOf = async (entry, opts = {}) => {
|
|
587
|
+
const memory = opts.memory ?? createMcpSkillSnapshotMemory();
|
|
588
|
+
const signal = opts.signal;
|
|
589
|
+
const readOpts = signal ? { signal } : void 0;
|
|
590
|
+
const declined = (why) => {
|
|
591
|
+
log(
|
|
592
|
+
"warn",
|
|
593
|
+
`[mcp] ${server}: the generated skill ${shownUri(entry.uri)} is declined - ${why}; no one is asked, nothing of it is used`
|
|
594
|
+
);
|
|
595
|
+
return new Error(
|
|
596
|
+
`the skill ${shownUri(entry.uri)} of the MCP server "${server}" was not loaded: ${why}`
|
|
597
|
+
);
|
|
598
|
+
};
|
|
599
|
+
const bytesOf = (file) => file.bytes instanceof Uint8Array ? file.bytes : new TextEncoder().encode(typeof file.text === "string" ? file.text : "");
|
|
600
|
+
let main;
|
|
601
|
+
try {
|
|
602
|
+
main = await client.read(entry, void 0, readOpts);
|
|
603
|
+
} catch (err) {
|
|
604
|
+
throw new Error(
|
|
605
|
+
`the skill ${shownUri(entry.uri)} of the MCP server "${server}" was not loaded: ${mcpSkillReadFailure(err)}`
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
const parts = [
|
|
609
|
+
{ uri: entry.uri, path: "SKILL.md", bytes: bytesOf(main) }
|
|
610
|
+
];
|
|
611
|
+
let total = parts[0].bytes.byteLength;
|
|
612
|
+
let refused = mcpSkillSnapshotBytesRefusal(total, memory.used);
|
|
613
|
+
if (refused) throw declined(refused);
|
|
614
|
+
const listed = client.directoryRead === true && typeof client.readDirectory === "function";
|
|
615
|
+
if (listed) {
|
|
616
|
+
const walk = startMcpSkillWalk(entry.uri);
|
|
617
|
+
if (!walk) throw declined("its URI names no directory to read");
|
|
618
|
+
for (let at = nextMcpSkillWalkDirectory(walk); at; at = nextMcpSkillWalkDirectory(walk)) {
|
|
619
|
+
let live;
|
|
620
|
+
try {
|
|
621
|
+
live = (await client.readDirectory(
|
|
622
|
+
at.uri,
|
|
623
|
+
readOpts
|
|
624
|
+
))?.resources;
|
|
625
|
+
} catch (err) {
|
|
626
|
+
if (signal?.aborted) throw err;
|
|
627
|
+
const code = err?.code;
|
|
628
|
+
throw declined(
|
|
629
|
+
`resources/directory/read of ${shownUri(at.uri)} failed - ${messageOf(err)}${typeof code === "number" ? ` (${code})` : ""}`
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
if (!Array.isArray(live)) {
|
|
633
|
+
throw declined(
|
|
634
|
+
`resources/directory/read of ${shownUri(at.uri)} gave no list of resources`
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
refused = takeMcpSkillWalkListing(walk, at, live);
|
|
638
|
+
if (refused) throw declined(refused);
|
|
639
|
+
}
|
|
640
|
+
const root = entry.uri.slice(0, -"SKILL.md".length);
|
|
641
|
+
for (const path of walk.files) {
|
|
642
|
+
const uri = `${root}${path}`;
|
|
643
|
+
let file;
|
|
644
|
+
try {
|
|
645
|
+
file = await client.read(entry, uri, readOpts);
|
|
646
|
+
} catch (err) {
|
|
647
|
+
if (signal?.aborted) throw err;
|
|
648
|
+
throw declined(`its file "${oneLine(path)}" was not read: ${mcpSkillReadFailure(err)}`);
|
|
649
|
+
}
|
|
650
|
+
const bytes = bytesOf(file);
|
|
651
|
+
total += bytes.byteLength;
|
|
652
|
+
refused = mcpSkillSnapshotBytesRefusal(total, memory.used);
|
|
653
|
+
if (refused) throw declined(refused);
|
|
654
|
+
parts.push({
|
|
655
|
+
uri,
|
|
656
|
+
path,
|
|
657
|
+
bytes,
|
|
658
|
+
...typeof file.text === "string" ? { text: file.text } : {}
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const resources = [];
|
|
663
|
+
for (const part of parts) {
|
|
664
|
+
resources.push({
|
|
665
|
+
uri: part.uri,
|
|
666
|
+
size: part.bytes.byteLength,
|
|
667
|
+
digest: await digest(part.bytes)
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
const manifest = mcpSkillSnapshotEntry(entry, resources);
|
|
671
|
+
refused = mcpSkillSnapshotBytesRefusal(total, memory.used);
|
|
672
|
+
if (refused) throw declined(refused);
|
|
673
|
+
memory.used += total;
|
|
674
|
+
copies.set(manifest, new Map(parts.slice(1).map((p) => [p.path, p.text])));
|
|
675
|
+
const loaded = {
|
|
676
|
+
uri: entry.uri,
|
|
677
|
+
body: typeof main.body === "string" ? main.body : "",
|
|
678
|
+
files: mcpSkillRecordOf(manifest).files,
|
|
679
|
+
entry: manifest,
|
|
680
|
+
snapshot: { bytes: total, listed }
|
|
681
|
+
};
|
|
682
|
+
held.set(loaded, manifest);
|
|
683
|
+
log(
|
|
684
|
+
"info",
|
|
685
|
+
`[mcp] ${server}: the generated skill ${shownUri(entry.uri)} read into a snapshot - ${parts.length} file(s), ${total} bytes${listed ? "" : " (the server cannot list its files: SKILL.md alone)"}; the agent's copies of generated skills now hold ${memory.used} bytes`
|
|
686
|
+
);
|
|
687
|
+
return loaded;
|
|
688
|
+
};
|
|
689
|
+
const readDirectory = async (loaded, dir, opts) => {
|
|
690
|
+
const entry = held.get(loaded);
|
|
691
|
+
if (!entry) {
|
|
692
|
+
throw new Error(`the skill ${loaded.uri} was not loaded from the MCP server "${server}"`);
|
|
693
|
+
}
|
|
694
|
+
const ownFiles = mcpSkillRecordOf(entry).files;
|
|
695
|
+
const ref = skillDirectoryRef(dir);
|
|
696
|
+
if ("refused" in ref || ref.dir !== dir || !skillDirectoryChildren(ownFiles, dir)) {
|
|
697
|
+
throw new Error(`the skill ${shownUri(entry.uri)} has no directory "${oneLine(dir)}"`);
|
|
698
|
+
}
|
|
699
|
+
const root = entry.uri.slice(0, -"/SKILL.md".length);
|
|
700
|
+
const uri = dir ? `${root}/${dir}` : root;
|
|
701
|
+
let live;
|
|
702
|
+
try {
|
|
703
|
+
live = (await client.readDirectory(uri, opts))?.resources;
|
|
704
|
+
} catch (err) {
|
|
705
|
+
if (opts?.signal?.aborted) throw err;
|
|
706
|
+
const code = err?.code;
|
|
707
|
+
log(
|
|
708
|
+
"warn",
|
|
709
|
+
`[mcp] ${server}: resources/directory/read of ${shownUri(uri)} failed - ${messageOf(err)}${typeof code === "number" ? ` (${code})` : ""}; the directory is listed from the skill's entry alone`
|
|
710
|
+
);
|
|
711
|
+
return void 0;
|
|
712
|
+
}
|
|
713
|
+
if (!Array.isArray(live)) {
|
|
714
|
+
log(
|
|
715
|
+
"warn",
|
|
716
|
+
`[mcp] ${server}: resources/directory/read of ${shownUri(uri)} gave no list of resources; the directory is listed from the skill's entry alone`
|
|
717
|
+
);
|
|
718
|
+
return void 0;
|
|
719
|
+
}
|
|
720
|
+
const manifest = ["SKILL.md", ...ownFiles];
|
|
721
|
+
const drift = compareMcpSkillDirectory({ manifest, dir, root, live });
|
|
722
|
+
if (drift.extra > 0 || drift.notServed.length > 0) {
|
|
723
|
+
log(
|
|
724
|
+
"warn",
|
|
725
|
+
`[mcp] ${server}: the skill "${oneLine(entry.frontmatter.name)}" (${shownUri(entry.uri)}) changed on the server - its directory "${oneLine(dir) || "."}" lists ${drift.truncated ? "at least " : ""}${drift.extra} item(s) its entry does not and not ${drift.notServed.length} it does; only the files of the entry it was loaded with are read until the server's skills are listed again`
|
|
726
|
+
);
|
|
727
|
+
if (!changed.has(entry)) {
|
|
728
|
+
changed.add(entry);
|
|
729
|
+
options.onChanged?.();
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return drift;
|
|
733
|
+
};
|
|
370
734
|
const refresh = async () => {
|
|
371
735
|
let listing;
|
|
372
736
|
try {
|
|
@@ -389,7 +753,7 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
|
|
|
389
753
|
const nextEntries = /* @__PURE__ */ new Map();
|
|
390
754
|
const nextRecords = [];
|
|
391
755
|
for (const entry of listing.skills) {
|
|
392
|
-
const refused = mcpSkillEntryRefusal(entry);
|
|
756
|
+
const refused = mcpSkillEntryRefusal(entry, admission);
|
|
393
757
|
const uri = isRecord(entry) && typeof entry.uri === "string" ? entry.uri : "(no uri)";
|
|
394
758
|
if (refused) {
|
|
395
759
|
log("warn", `[mcp] ${server}: skill ${oneLine(uri).slice(0, 200)} refused - ${refused}`);
|
|
@@ -433,7 +797,7 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
|
|
|
433
797
|
);
|
|
434
798
|
}
|
|
435
799
|
const entry = answer?.skill;
|
|
436
|
-
const why = mcpSkillEntryRefusal(entry);
|
|
800
|
+
const why = mcpSkillEntryRefusal(entry, admission);
|
|
437
801
|
if (why) {
|
|
438
802
|
log("warn", `[mcp] ${server}: skill ${shownUri(uri)} (by URI) refused - ${why}`);
|
|
439
803
|
throw new Error(
|
|
@@ -454,9 +818,14 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
|
|
|
454
818
|
if (!entry) {
|
|
455
819
|
throw new Error(`the MCP server "${server}" no longer lists the skill ${uri}`);
|
|
456
820
|
}
|
|
821
|
+
if (entry.resources === "dynamic") return snapshotOf(entry, options2);
|
|
457
822
|
let file;
|
|
458
823
|
try {
|
|
459
|
-
file = await client.read(
|
|
824
|
+
file = await client.read(
|
|
825
|
+
entry,
|
|
826
|
+
void 0,
|
|
827
|
+
options2?.signal ? { signal: options2.signal } : void 0
|
|
828
|
+
);
|
|
460
829
|
} catch (err) {
|
|
461
830
|
throw new Error(
|
|
462
831
|
`the skill ${uri} of the MCP server "${server}" was not loaded: ${mcpSkillReadFailure(err)}`
|
|
@@ -477,6 +846,16 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
|
|
|
477
846
|
throw new Error(`the skill ${loaded.uri} was not loaded from the MCP server "${server}"`);
|
|
478
847
|
const target = resolveMcpSkillFile(loaded.files, path);
|
|
479
848
|
if ("refused" in target) throw new Error(target.refused);
|
|
849
|
+
const copy = copies.get(entry);
|
|
850
|
+
if (copy) {
|
|
851
|
+
const text = copy.get(target.path);
|
|
852
|
+
if (typeof text !== "string") {
|
|
853
|
+
throw new Error(
|
|
854
|
+
`the file "${target.path}" of the skill ${loaded.uri} is not text; it is not shown`
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
return text;
|
|
858
|
+
}
|
|
480
859
|
let read = files.get(entry);
|
|
481
860
|
const kept = read?.get(target.path);
|
|
482
861
|
if (kept !== void 0) return kept;
|
|
@@ -499,7 +878,10 @@ var createMcpSkillCatalog = (server, client, log, options = {}) => {
|
|
|
499
878
|
}
|
|
500
879
|
read.set(target.path, file.text);
|
|
501
880
|
return file.text;
|
|
502
|
-
}
|
|
881
|
+
},
|
|
882
|
+
// Never called on a server that did not declare it (Capability Negotiation: a client "MUST
|
|
883
|
+
// NOT call resources/directory/read" there).
|
|
884
|
+
...client.directoryRead === true && typeof client.readDirectory === "function" ? { readDirectory } : {}
|
|
503
885
|
};
|
|
504
886
|
return { source, refresh };
|
|
505
887
|
};
|
|
@@ -551,7 +933,10 @@ export {
|
|
|
551
933
|
mcpSkillPreamble,
|
|
552
934
|
mcpSkillBodyText,
|
|
553
935
|
mcpSkillFileText,
|
|
554
|
-
|
|
936
|
+
MCP_SKILL_DIRECTORY_ENTRIES_MAX,
|
|
937
|
+
skillDirectoryOf,
|
|
938
|
+
resolveMcpSkillPath,
|
|
939
|
+
skillDirectoryListing,
|
|
555
940
|
MCP_SKILL_URI_MAX_CHARS,
|
|
556
941
|
mcpSkillUriRefusal,
|
|
557
942
|
resolveMcpSkillServer,
|
|
@@ -571,6 +956,10 @@ export {
|
|
|
571
956
|
recordMcpSkillConsent,
|
|
572
957
|
mcpSkillConsentView,
|
|
573
958
|
mcpSkillDeniedMessage,
|
|
959
|
+
MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES,
|
|
960
|
+
MCP_SKILL_SNAPSHOT_MAX_DEPTH,
|
|
961
|
+
MCP_SKILL_SNAPSHOTS_MAX_BYTES,
|
|
962
|
+
createMcpSkillSnapshotMemory,
|
|
574
963
|
markMcpSkills,
|
|
575
964
|
collectMcpSkillSources,
|
|
576
965
|
createMcpSkillCatalog,
|
|
@@ -581,4 +970,4 @@ export {
|
|
|
581
970
|
RUNS_STORE,
|
|
582
971
|
openAgentWebDB
|
|
583
972
|
};
|
|
584
|
-
//# sourceMappingURL=chunk-
|
|
973
|
+
//# sourceMappingURL=chunk-ZSZSSJS4.js.map
|