@livx.cc/agentx 0.99.50 → 0.99.52

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/dist/index.js CHANGED
@@ -9243,8 +9243,35 @@ function describeSpec(s) {
9243
9243
  args: ${JSON.stringify(s.inputSchema)}` : "";
9244
9244
  return `${s.name} \u2014 ${s.description ?? "(no description)"}${schema}`;
9245
9245
  }
9246
+ function editDistance(a, b) {
9247
+ let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
9248
+ for (let i = 1; i <= a.length; i++) {
9249
+ const cur = [i];
9250
+ for (let j = 1; j <= b.length; j++) cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
9251
+ prev = cur;
9252
+ }
9253
+ return prev[b.length];
9254
+ }
9255
+ function closestName(name, known) {
9256
+ let best, bestD = Infinity;
9257
+ for (const k of known) {
9258
+ const d = editDistance(name.toLowerCase(), k.toLowerCase());
9259
+ if (d < bestD) {
9260
+ best = k;
9261
+ bestD = d;
9262
+ }
9263
+ }
9264
+ return best !== void 0 && bestD <= Math.max(2, Math.floor(name.length * 0.3)) ? best : void 0;
9265
+ }
9266
+ function unknownMcpToolMessage(name, known, prefix = "mcp__") {
9267
+ const guess = closestName(name, known);
9268
+ if (guess) return `Error: unknown MCP tool '${name}' \u2014 did you mean '${guess}'?`;
9269
+ if (!name.startsWith(prefix) && known.some((k) => k.startsWith(prefix))) return `Error: '${name}' is not an MCP tool (MCP tool names start with '${prefix}'). If it is one of your own tools, call it directly, not via McpCall; otherwise use ToolSearch to find the MCP tool you need.`;
9270
+ return `Error: unknown MCP tool '${name}'. Use ToolSearch to find valid names.`;
9271
+ }
9246
9272
  function makeMcpToolSearch(specs, callTool, options = {}) {
9247
9273
  const maxResults = options.maxResults ?? 10;
9274
+ const prefix = options.prefix ?? "mcp__";
9248
9275
  const callTimeoutMs = options.timeoutMs ?? MCP_CALL_TIMEOUT_MS;
9249
9276
  const byName = new Map(specs.map((s) => [s.name, s]));
9250
9277
  const catalogLine = `${specs.length} MCP tool(s) available \u2014 search by keyword, then call by exact name.`;
@@ -9272,9 +9299,12 @@ function makeMcpToolSearch(specs, callTool, options = {}) {
9272
9299
  }
9273
9300
  },
9274
9301
  maxDurationMs: callTimeoutMs,
9275
- async run({ name, args }, ctx) {
9276
- const n = String(name ?? "");
9277
- if (!byName.has(n)) return `Error: unknown MCP tool '${n}'. Use ToolSearch to find valid names.`;
9302
+ async run(input, ctx) {
9303
+ const { name, args } = input ?? {};
9304
+ const n = String(name ?? "").trim();
9305
+ if (!n) return `Error: McpCall requires \`name\` (the exact MCP tool name) \u2014 got keys [${Object.keys(input ?? {}).join(", ")}]. Call it as McpCall({ name: "mcp__<server>__<tool>", args: {...} }).`;
9306
+ if (n === searchTool.name) return searchTool.run({ query: args?.query ?? args?.keyword ?? args?.q }, ctx);
9307
+ if (!byName.has(n)) return unknownMcpToolMessage(n, [...byName.keys()], prefix);
9278
9308
  return runMcpCall(n, (o) => callTool(n, args ?? {}, o), ctx, callTimeoutMs);
9279
9309
  }
9280
9310
  };