@dudko.dev/agent-web 0.0.52 → 0.0.53
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 +22 -7
- package/dist/agent-web.js +129 -129
- package/dist/agent-web.js.map +1 -1
- package/dist/{chunk-QWOKTI62.js → chunk-MJSVRPBP.js} +24 -12
- package/dist/chunk-MJSVRPBP.js.map +1 -0
- package/dist/index.cjs +68 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -12
- package/dist/index.d.ts +58 -12
- package/dist/index.js +45 -31
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +88 -11
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +56 -10
- package/dist/mcp.d.ts +56 -10
- package/dist/mcp.js +88 -11
- package/dist/mcp.js.map +1 -1
- package/dist/{sandbox-QNEDQZTA.js → sandbox-WICP36ZL.js} +2 -2
- package/dist/{skills-ufoyTJ-B.d.cts → skills-BC8yMqpN.d.cts} +1 -1
- package/dist/{skills-ufoyTJ-B.d.ts → skills-BC8yMqpN.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-QWOKTI62.js.map +0 -1
- /package/dist/{sandbox-QNEDQZTA.js.map → sandbox-WICP36ZL.js.map} +0 -0
package/dist/mcp.cjs
CHANGED
|
@@ -2720,11 +2720,12 @@ var DEFAULT_RECONNECTION = {
|
|
|
2720
2720
|
};
|
|
2721
2721
|
var sanitizeName = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2722
2722
|
var uniqueKey = (base, taken) => {
|
|
2723
|
-
if (!
|
|
2723
|
+
if (!taken(base)) return base;
|
|
2724
|
+
const max = Math.max(MAX_TOOL_NAME_LEN, base.length);
|
|
2724
2725
|
for (let n = 2; n < 100; n++) {
|
|
2725
2726
|
const suffix = `_${n}`;
|
|
2726
|
-
const candidate = base.slice(0,
|
|
2727
|
-
if (!
|
|
2727
|
+
const candidate = base.slice(0, max - suffix.length) + suffix;
|
|
2728
|
+
if (!taken(candidate)) return candidate;
|
|
2728
2729
|
}
|
|
2729
2730
|
return "";
|
|
2730
2731
|
};
|
|
@@ -3121,6 +3122,12 @@ var connectAndList = async (name, cfg, opts, log, probe, onClient, onListener, e
|
|
|
3121
3122
|
...skills ? { skills } : {}
|
|
3122
3123
|
};
|
|
3123
3124
|
};
|
|
3125
|
+
var mcpServerSeq = 0;
|
|
3126
|
+
var newMcpServerId = () => {
|
|
3127
|
+
mcpServerSeq += 1;
|
|
3128
|
+
const random = typeof globalThis.crypto?.randomUUID === "function" ? globalThis.crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
3129
|
+
return `mcp-${mcpServerSeq}-${random}`;
|
|
3130
|
+
};
|
|
3124
3131
|
var connectMcpHttp = async (servers, opts = {}) => {
|
|
3125
3132
|
const log = opts.onLog ?? (() => {
|
|
3126
3133
|
});
|
|
@@ -3139,18 +3146,31 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3139
3146
|
const clients = /* @__PURE__ */ new Map();
|
|
3140
3147
|
const tools = {};
|
|
3141
3148
|
const catalog = [];
|
|
3149
|
+
const listedTools = [];
|
|
3142
3150
|
const results = [];
|
|
3143
3151
|
const instructions = [];
|
|
3144
3152
|
const instructionsOf = /* @__PURE__ */ new Map();
|
|
3145
3153
|
const protocols = [];
|
|
3146
3154
|
const listeners = /* @__PURE__ */ new Map();
|
|
3147
3155
|
const mountedKeys = /* @__PURE__ */ new Map();
|
|
3156
|
+
const unmountedKeys = /* @__PURE__ */ new Map();
|
|
3148
3157
|
const skillCatalogs = /* @__PURE__ */ new Map();
|
|
3149
3158
|
const appsModes = new Map(
|
|
3150
3159
|
Object.entries(servers).map(([name, cfg]) => [name, mcpAppsModeOf(cfg.apps, opts.apps)])
|
|
3151
3160
|
);
|
|
3152
3161
|
const appsOn = [...appsModes.values()].includes("on");
|
|
3153
3162
|
const appToolsOf = /* @__PURE__ */ new Map();
|
|
3163
|
+
const serverIds = new Map(
|
|
3164
|
+
Object.keys(servers).map((name) => [name, newMcpServerId()])
|
|
3165
|
+
);
|
|
3166
|
+
const serverIdOf = (name) => {
|
|
3167
|
+
let id = serverIds.get(name);
|
|
3168
|
+
if (!id) {
|
|
3169
|
+
id = newMcpServerId();
|
|
3170
|
+
serverIds.set(name, id);
|
|
3171
|
+
}
|
|
3172
|
+
return id;
|
|
3173
|
+
};
|
|
3154
3174
|
const appResources = /* @__PURE__ */ new Map();
|
|
3155
3175
|
let appEventSeq = 0;
|
|
3156
3176
|
const requestToolCall = async (name, client, key, toolName, args, options) => {
|
|
@@ -3217,13 +3237,40 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3217
3237
|
for (let i = catalog.length - 1; i >= 0; i--) {
|
|
3218
3238
|
if (catalog[i].server === name) catalog.splice(i, 1);
|
|
3219
3239
|
}
|
|
3240
|
+
for (let i = listedTools.length - 1; i >= 0; i--) {
|
|
3241
|
+
if (listedTools[i].server === name) listedTools.splice(i, 1);
|
|
3242
|
+
}
|
|
3220
3243
|
const keys = [];
|
|
3221
3244
|
const appTools = /* @__PURE__ */ new Map();
|
|
3245
|
+
const takenByOthers = (key) => {
|
|
3246
|
+
for (const [server, own2] of unmountedKeys) if (server !== name && own2.has(key)) return true;
|
|
3247
|
+
return false;
|
|
3248
|
+
};
|
|
3249
|
+
const unmounted = [];
|
|
3222
3250
|
let schemaValidator;
|
|
3223
3251
|
let mounted = 0;
|
|
3224
3252
|
const appsMode = appsModes.get(name) ?? "off";
|
|
3225
3253
|
for (const t of listed) {
|
|
3226
3254
|
const prefixed = prefix + sanitizeName(t.name);
|
|
3255
|
+
const declared = mcpAppToolMeta(t);
|
|
3256
|
+
const readOnlyHint = t.annotations?.readOnlyHint === true;
|
|
3257
|
+
const titled = typeof t.title === "string" ? t.title : t.annotations?.title;
|
|
3258
|
+
const entry = {
|
|
3259
|
+
server: name,
|
|
3260
|
+
name: t.name,
|
|
3261
|
+
key: prefixed,
|
|
3262
|
+
mounted: false,
|
|
3263
|
+
...typeof titled === "string" && titled ? { title: titled } : {},
|
|
3264
|
+
description: t.description ?? "",
|
|
3265
|
+
readOnly: readOnlyHint,
|
|
3266
|
+
// MCP's reading: `destructiveHint` means something only for a tool that is not
|
|
3267
|
+
// read-only, and its default there is true.
|
|
3268
|
+
destructive: !readOnlyHint && t.annotations?.destructiveHint !== false,
|
|
3269
|
+
...declared.resourceUri ? { app: declared.resourceUri, visibility: declared.visibility } : {},
|
|
3270
|
+
appCallable: false
|
|
3271
|
+
};
|
|
3272
|
+
listedTools.push(entry);
|
|
3273
|
+
const notMounted = (app) => unmounted.push({ entry, prefixed, ...app ? { app } : {} });
|
|
3227
3274
|
const ui = appsMode !== "off" ? mcpAppToolMeta(t) : void 0;
|
|
3228
3275
|
if (appsMode === "on" && ui?.refusedUri !== void 0) {
|
|
3229
3276
|
log(
|
|
@@ -3237,19 +3284,20 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3237
3284
|
"info",
|
|
3238
3285
|
`[mcp] ${name}: tool "${t.name}" is for its app only, and apps are off for this server; not mounted`
|
|
3239
3286
|
);
|
|
3287
|
+
notMounted();
|
|
3240
3288
|
continue;
|
|
3241
3289
|
}
|
|
3242
|
-
|
|
3243
|
-
|
|
3290
|
+
notMounted(
|
|
3291
|
+
ui.visibility.includes("app") ? {
|
|
3244
3292
|
name: t.name,
|
|
3245
|
-
key: prefixed,
|
|
3246
3293
|
description: t.description ?? "",
|
|
3247
3294
|
inputSchema: t.inputSchema,
|
|
3248
3295
|
readOnly: t.annotations?.readOnlyHint === true,
|
|
3249
3296
|
visibility: ui.visibility,
|
|
3250
|
-
...ui.resourceUri ? { resourceUri: ui.resourceUri } : {}
|
|
3251
|
-
|
|
3252
|
-
|
|
3297
|
+
...ui.resourceUri ? { resourceUri: ui.resourceUri } : {},
|
|
3298
|
+
serverId: serverIdOf(name)
|
|
3299
|
+
} : void 0
|
|
3300
|
+
);
|
|
3253
3301
|
log("info", `[mcp] ${name}: tool "${t.name}" is for its app only; not mounted`);
|
|
3254
3302
|
continue;
|
|
3255
3303
|
}
|
|
@@ -3258,11 +3306,13 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3258
3306
|
"warn",
|
|
3259
3307
|
`[mcp] ${name}: tool "${t.name}" exceeds the ${MAX_TOOL_NAME_LEN}-char name limit; skipping`
|
|
3260
3308
|
);
|
|
3309
|
+
notMounted();
|
|
3261
3310
|
continue;
|
|
3262
3311
|
}
|
|
3263
|
-
const key = uniqueKey(prefixed, tools);
|
|
3312
|
+
const key = uniqueKey(prefixed, (k) => Object.hasOwn(tools, k) || takenByOthers(k));
|
|
3264
3313
|
if (!key) {
|
|
3265
3314
|
log("warn", `[mcp] ${name}: cannot find a free name for tool "${t.name}"; skipping`);
|
|
3315
|
+
notMounted();
|
|
3266
3316
|
continue;
|
|
3267
3317
|
}
|
|
3268
3318
|
if (key !== prefixed) {
|
|
@@ -3271,7 +3321,10 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3271
3321
|
const description = t.description ?? "";
|
|
3272
3322
|
const readOnly = t.annotations?.readOnlyHint === true;
|
|
3273
3323
|
const appUri = appsMode === "on" ? ui?.resourceUri : void 0;
|
|
3324
|
+
entry.key = key;
|
|
3325
|
+
entry.mounted = true;
|
|
3274
3326
|
if (appsMode === "on" && ui?.visibility.includes("app")) {
|
|
3327
|
+
entry.appCallable = true;
|
|
3275
3328
|
appTools.set(t.name, {
|
|
3276
3329
|
name: t.name,
|
|
3277
3330
|
key,
|
|
@@ -3279,7 +3332,8 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3279
3332
|
inputSchema: t.inputSchema,
|
|
3280
3333
|
readOnly,
|
|
3281
3334
|
visibility: ui.visibility,
|
|
3282
|
-
...appUri ? { resourceUri: appUri } : {}
|
|
3335
|
+
...appUri ? { resourceUri: appUri } : {},
|
|
3336
|
+
serverId: serverIdOf(name)
|
|
3283
3337
|
});
|
|
3284
3338
|
}
|
|
3285
3339
|
let outputValidator;
|
|
@@ -3363,6 +3417,28 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3363
3417
|
mounted += 1;
|
|
3364
3418
|
}
|
|
3365
3419
|
mountedKeys.set(name, keys);
|
|
3420
|
+
const own = /* @__PURE__ */ new Set();
|
|
3421
|
+
unmountedKeys.set(name, own);
|
|
3422
|
+
for (const { entry, prefixed, app } of unmounted) {
|
|
3423
|
+
const key = uniqueKey(
|
|
3424
|
+
prefixed,
|
|
3425
|
+
(k) => Object.hasOwn(tools, k) || own.has(k) || takenByOthers(k)
|
|
3426
|
+
);
|
|
3427
|
+
if (!key) {
|
|
3428
|
+
if (app)
|
|
3429
|
+
log(
|
|
3430
|
+
"warn",
|
|
3431
|
+
`[mcp] ${name}: cannot find a free name for tool "${entry.name}"; its app may not call it`
|
|
3432
|
+
);
|
|
3433
|
+
continue;
|
|
3434
|
+
}
|
|
3435
|
+
entry.key = key;
|
|
3436
|
+
own.add(key);
|
|
3437
|
+
if (app) {
|
|
3438
|
+
entry.appCallable = true;
|
|
3439
|
+
appTools.set(app.name, { ...app, key });
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3366
3442
|
if (appsMode === "on") {
|
|
3367
3443
|
appToolsOf.set(name, appTools);
|
|
3368
3444
|
appResources.delete(name);
|
|
@@ -3488,6 +3564,7 @@ var connectMcpHttp = async (servers, opts = {}) => {
|
|
|
3488
3564
|
return {
|
|
3489
3565
|
tools,
|
|
3490
3566
|
catalog,
|
|
3567
|
+
listed: listedTools,
|
|
3491
3568
|
results,
|
|
3492
3569
|
instructions,
|
|
3493
3570
|
protocols,
|