@charzhu/openjaw-agent 0.2.2 → 0.2.3

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/main.js CHANGED
@@ -19289,6 +19289,16 @@ var init_registry = __esm({
19289
19289
  this.registerTool(tool);
19290
19290
  }
19291
19291
  }
19292
+ /**
19293
+ * Remove a tool by name. Returns true if a tool was removed.
19294
+ *
19295
+ * Used to drop stale MCP tools when a server reconnects, is denied,
19296
+ * or is removed so the LLM does not try to call a tool whose backing
19297
+ * connection no longer exists.
19298
+ */
19299
+ unregisterTool(name) {
19300
+ return this.tools.delete(name);
19301
+ }
19292
19302
  getTool(name) {
19293
19303
  return this.tools.get(name);
19294
19304
  }
@@ -48558,12 +48568,14 @@ ${helpMessage}` : field.label;
48558
48568
  bus.registerRpc("delegation.status", () => ({ delegated: [], paused: false }));
48559
48569
  bus.registerRpc("delegation.pause", (params) => ({ paused: Boolean(params.paused) }));
48560
48570
  bus.registerRpc("subagent.interrupt", () => ({ ok: true }));
48571
+ syncMcpTools(mcpManager, toolRegistry);
48561
48572
  bus.emitEvent({
48562
48573
  payload: sessionInfoSnapshot(agentLoop, toolRegistry),
48563
48574
  session_id: agentLoop.sessionId,
48564
48575
  type: "session.info"
48565
48576
  });
48566
48577
  const onToolsChanged = /* @__PURE__ */ __name(() => {
48578
+ syncMcpTools(mcpManager, toolRegistry);
48567
48579
  bus.emitEvent({
48568
48580
  payload: sessionInfoSnapshot(agentLoop, toolRegistry),
48569
48581
  session_id: agentLoop.sessionId,
@@ -48580,7 +48592,7 @@ ${helpMessage}` : field.label;
48580
48592
  }
48581
48593
  };
48582
48594
  }
48583
- var PROVIDERS2, PROVIDER_LABELS, PROVIDER_AUTH, isProviderAuthenticated, buildProviderOption, fetchLiveModels, BRIDGE_SOURCES, isBridgeSource, inferBridgeSource, bridgeLabels, bridgeEventLabels, stripBridgeGlyph, firstLogLine, bridgeUser, formatBridgeText, runProcess, contentToText, sessionMessageToMarkdown, usageSnapshot, sessionInfoSnapshot;
48595
+ var PROVIDERS2, PROVIDER_LABELS, PROVIDER_AUTH, isProviderAuthenticated, buildProviderOption, fetchLiveModels, BRIDGE_SOURCES, isBridgeSource, inferBridgeSource, bridgeLabels, bridgeEventLabels, stripBridgeGlyph, firstLogLine, bridgeUser, formatBridgeText, runProcess, contentToText, sessionMessageToMarkdown, usageSnapshot, sessionInfoSnapshot, MCP_TOOL_PREFIX, MAX_TOTAL_TOOLS, syncMcpTools;
48584
48596
  var init_rpcHandlers = __esm({
48585
48597
  "src/rpcHandlers.ts"() {
48586
48598
  "use strict";
@@ -48809,6 +48821,23 @@ ${raw}`;
48809
48821
  tools: { [agentLoop.providerName]: toolRegistry.listTools().map((t) => t.name) },
48810
48822
  usage: usageSnapshot(agentLoop)
48811
48823
  }), "sessionInfoSnapshot");
48824
+ MCP_TOOL_PREFIX = "mcp__";
48825
+ MAX_TOTAL_TOOLS = 200;
48826
+ syncMcpTools = /* @__PURE__ */ __name((mcpManager, toolRegistry) => {
48827
+ let removed = 0;
48828
+ for (const tool of toolRegistry.listTools()) {
48829
+ if (tool.name.startsWith(MCP_TOOL_PREFIX)) {
48830
+ if (toolRegistry.unregisterTool(tool.name)) removed++;
48831
+ }
48832
+ }
48833
+ const nonMcpCount = toolRegistry.listTools().length;
48834
+ const budget = Math.max(0, MAX_TOTAL_TOOLS - nonMcpCount);
48835
+ const mcpTools = mcpManager.getTools(budget);
48836
+ for (const tool of mcpTools) {
48837
+ toolRegistry.registerTool(tool);
48838
+ }
48839
+ return { added: mcpTools.length, removed };
48840
+ }, "syncMcpTools");
48812
48841
  __name(registerRpcHandlers, "registerRpcHandlers");
48813
48842
  }
48814
48843
  });