@agentvault/agentvault 0.17.2 → 0.17.4

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/cli.js CHANGED
@@ -46477,6 +46477,7 @@ var http_handlers_exports = {};
46477
46477
  __export(http_handlers_exports, {
46478
46478
  handleActionRequest: () => handleActionRequest,
46479
46479
  handleDecisionRequest: () => handleDecisionRequest,
46480
+ handleMcpConfigRequest: () => handleMcpConfigRequest,
46480
46481
  handleSendRequest: () => handleSendRequest,
46481
46482
  handleStatusRequest: () => handleStatusRequest,
46482
46483
  handleTargetsRequest: () => handleTargetsRequest
@@ -46618,12 +46619,90 @@ function handleTargetsRequest(channel2) {
46618
46619
  }
46619
46620
  };
46620
46621
  }
46622
+ function handleMcpConfigRequest(agentName, port, mcpSkillCount) {
46623
+ return {
46624
+ status: 200,
46625
+ body: {
46626
+ mcpServers: {
46627
+ [`agentvault-${agentName}`]: {
46628
+ url: `http://127.0.0.1:${port}/mcp`
46629
+ }
46630
+ },
46631
+ _meta: {
46632
+ agent: agentName,
46633
+ skills_count: mcpSkillCount,
46634
+ transport: "streamable-http",
46635
+ auth: "none (localhost)",
46636
+ instructions: "Add the mcpServers block to your MCP configuration file (e.g., .mcp.json or mcp_config.json)"
46637
+ }
46638
+ }
46639
+ };
46640
+ }
46621
46641
  var init_http_handlers = __esm({
46622
46642
  "src/http-handlers.ts"() {
46623
46643
  "use strict";
46624
46644
  }
46625
46645
  });
46626
46646
 
46647
+ // src/mcp-proxy-helpers.ts
46648
+ var mcp_proxy_helpers_exports = {};
46649
+ __export(mcp_proxy_helpers_exports, {
46650
+ createMcpProxyRequest: () => createMcpProxyRequest
46651
+ });
46652
+ import { Readable } from "node:stream";
46653
+ async function createMcpProxyRequest(mcpServer, payload) {
46654
+ const bodyStr = JSON.stringify(payload);
46655
+ const req = Object.assign(new Readable({ read() {
46656
+ } }), {
46657
+ method: "POST",
46658
+ url: "/mcp",
46659
+ headers: {
46660
+ "content-type": "application/json",
46661
+ "content-length": String(Buffer.byteLength(bodyStr)),
46662
+ // Use localhost to bypass SPT validation (WS already authenticated)
46663
+ host: "localhost"
46664
+ },
46665
+ socket: { remoteAddress: "127.0.0.1" }
46666
+ });
46667
+ req.push(bodyStr);
46668
+ req.push(null);
46669
+ let responseStatus = 200;
46670
+ let responseBody = "";
46671
+ const chunks = [];
46672
+ const res = {
46673
+ writeHead: (status) => {
46674
+ responseStatus = status;
46675
+ },
46676
+ write: (chunk) => {
46677
+ chunks.push(typeof chunk === "string" ? chunk : chunk.toString());
46678
+ return true;
46679
+ },
46680
+ end: (data) => {
46681
+ if (data) chunks.push(typeof data === "string" ? data : data.toString());
46682
+ responseBody = chunks.join("");
46683
+ },
46684
+ setHeader: () => {
46685
+ },
46686
+ getHeader: () => void 0,
46687
+ statusCode: 200,
46688
+ headersSent: false
46689
+ };
46690
+ await mcpServer.handleRequest(req, res);
46691
+ if (responseBody) {
46692
+ try {
46693
+ return JSON.parse(responseBody);
46694
+ } catch {
46695
+ return { jsonrpc: "2.0", error: { code: -32603, message: responseBody } };
46696
+ }
46697
+ }
46698
+ return null;
46699
+ }
46700
+ var init_mcp_proxy_helpers = __esm({
46701
+ "src/mcp-proxy-helpers.ts"() {
46702
+ "use strict";
46703
+ }
46704
+ });
46705
+
46627
46706
  // src/workspace-handlers.ts
46628
46707
  var workspace_handlers_exports = {};
46629
46708
  __export(workspace_handlers_exports, {
@@ -46839,6 +46918,7 @@ var init_channel = __esm({
46839
46918
  _stopped = false;
46840
46919
  _persisted = null;
46841
46920
  _httpServer = null;
46921
+ _mcpServer = null;
46842
46922
  _pollFallbackTimer = null;
46843
46923
  _heartbeatTimer = null;
46844
46924
  _heartbeatCallback = null;
@@ -46919,6 +46999,12 @@ var init_channel = __esm({
46919
46999
  get telemetry() {
46920
47000
  return this._telemetryReporter;
46921
47001
  }
47002
+ /**
47003
+ * Check if a skill is in shadow mode. Returns the shadow config if active, undefined otherwise.
47004
+ */
47005
+ getShadowConfig(skillName) {
47006
+ return this._persisted?.shadowSkills?.[skillName];
47007
+ }
46922
47008
  async start() {
46923
47009
  this._stopped = false;
46924
47010
  await libsodium_wrappers_default.ready;
@@ -47884,9 +47970,28 @@ var init_channel = __esm({
47884
47970
  const result = handlers.handleTargetsRequest(this);
47885
47971
  res.writeHead(result.status, { "Content-Type": "application/json" });
47886
47972
  res.end(JSON.stringify(result.body));
47973
+ } else if (req.url === "/mcp" && (req.method === "POST" || req.method === "GET" || req.method === "DELETE")) {
47974
+ if (!this._mcpServer) {
47975
+ res.writeHead(503, { "Content-Type": "application/json" });
47976
+ res.end(JSON.stringify({ ok: false, error: "MCP server not initialized" }));
47977
+ return;
47978
+ }
47979
+ this._mcpServer.handleRequest(req, res).catch((err) => {
47980
+ console.error("[MCP] Request handling error:", err);
47981
+ if (!res.headersSent) {
47982
+ res.writeHead(500, { "Content-Type": "application/json" });
47983
+ res.end(JSON.stringify({ ok: false, error: "Internal MCP error" }));
47984
+ }
47985
+ });
47986
+ } else if (req.method === "GET" && req.url === "/mcp-config") {
47987
+ const agentName = this.config.agentName ?? "agent";
47988
+ const mcpSkillCount = this._mcpServer?.skillCount ?? 0;
47989
+ const result = handlers.handleMcpConfigRequest(agentName, port, mcpSkillCount);
47990
+ res.writeHead(result.status, { "Content-Type": "application/json" });
47991
+ res.end(JSON.stringify(result.body));
47887
47992
  } else {
47888
47993
  res.writeHead(404, { "Content-Type": "application/json" });
47889
- res.end(JSON.stringify({ ok: false, error: "Not found. Use POST /send, POST /decision, POST /action, GET /status, or GET /targets" }));
47994
+ res.end(JSON.stringify({ ok: false, error: "Not found. Use POST /send, POST /decision, POST /action, GET /status, GET /targets, or /mcp" }));
47890
47995
  }
47891
47996
  });
47892
47997
  this._httpServer.listen(port, "127.0.0.1", () => {
@@ -47899,6 +48004,17 @@ var init_channel = __esm({
47899
48004
  this._httpServer = null;
47900
48005
  }
47901
48006
  }
48007
+ /**
48008
+ * Attach an MCP server instance to this channel.
48009
+ * The MCP server will be served at /mcp on the local HTTP server.
48010
+ */
48011
+ setMcpServer(mcpServer) {
48012
+ this._mcpServer = mcpServer;
48013
+ }
48014
+ /** The attached MCP server, if any. */
48015
+ get mcpServer() {
48016
+ return this._mcpServer;
48017
+ }
47902
48018
  // --- Topic management ---
47903
48019
  /**
47904
48020
  * Create a new topic within the conversation group.
@@ -48493,6 +48609,33 @@ var init_channel = __esm({
48493
48609
  await this._fetchScanRules();
48494
48610
  return;
48495
48611
  }
48612
+ if (data.event === "mcp_request") {
48613
+ const requestId = data.data?.request_id;
48614
+ const mcpPayload = data.data?.mcp_payload;
48615
+ if (requestId && mcpPayload && this._mcpServer) {
48616
+ try {
48617
+ const { createMcpProxyRequest: createMcpProxyRequest2 } = await Promise.resolve().then(() => (init_mcp_proxy_helpers(), mcp_proxy_helpers_exports));
48618
+ const mcpResponse = await createMcpProxyRequest2(this._mcpServer, mcpPayload);
48619
+ ws.send(JSON.stringify({
48620
+ event: "mcp_response",
48621
+ data: { request_id: requestId, mcp_payload: mcpResponse }
48622
+ }));
48623
+ } catch (err) {
48624
+ ws.send(JSON.stringify({
48625
+ event: "mcp_response",
48626
+ data: {
48627
+ request_id: requestId,
48628
+ mcp_payload: {
48629
+ jsonrpc: "2.0",
48630
+ id: mcpPayload?.id ?? null,
48631
+ error: { code: -32603, message: String(err) }
48632
+ }
48633
+ }
48634
+ }));
48635
+ }
48636
+ }
48637
+ return;
48638
+ }
48496
48639
  if (data.event === "hub_identity_sync") {
48497
48640
  if (this._persisted && data.data?.hub_id) {
48498
48641
  const changed = this._persisted.hubId !== data.data.hub_id || this._persisted.agentRole !== (data.data.agent_role ?? "peer");
@@ -48529,6 +48672,46 @@ var init_channel = __esm({
48529
48672
  }
48530
48673
  this.emit("hub_identity_role_changed", data.data);
48531
48674
  }
48675
+ if (data.event === "shadow_config_sync") {
48676
+ if (this._persisted && data.data?.skills) {
48677
+ this._persisted.shadowSkills = data.data.skills;
48678
+ this._persistState();
48679
+ console.log(`[SecureChannel] Shadow config synced: ${Object.keys(data.data.skills).length} skill(s)`);
48680
+ }
48681
+ }
48682
+ if (data.event === "shadow_session_created") {
48683
+ if (this._persisted && data.data?.skill_name) {
48684
+ if (!this._persisted.shadowSkills) this._persisted.shadowSkills = {};
48685
+ this._persisted.shadowSkills[data.data.skill_name] = {
48686
+ sessionId: data.data.session_id,
48687
+ autonomyLevel: data.data.autonomy_level,
48688
+ decisionClass: data.data.decision_class
48689
+ };
48690
+ this._persistState();
48691
+ console.log(`[SecureChannel] Shadow session created for skill: ${data.data.skill_name}`);
48692
+ }
48693
+ this.emit("shadow_session_created", data.data);
48694
+ }
48695
+ if (data.event === "shadow_session_graduated") {
48696
+ if (this._persisted?.shadowSkills && data.data?.skill_name) {
48697
+ if (data.data.autonomy_level === "autonomous") {
48698
+ delete this._persisted.shadowSkills[data.data.skill_name];
48699
+ } else {
48700
+ const entry = this._persisted.shadowSkills[data.data.skill_name];
48701
+ if (entry) entry.autonomyLevel = data.data.autonomy_level;
48702
+ }
48703
+ this._persistState();
48704
+ console.log(`[SecureChannel] Shadow session graduated: ${data.data.skill_name} \u2192 ${data.data.autonomy_level}`);
48705
+ }
48706
+ this.emit("shadow_session_graduated", data.data);
48707
+ }
48708
+ if (data.event === "shadow_session_deleted") {
48709
+ if (this._persisted?.shadowSkills && data.data?.skill_name) {
48710
+ delete this._persisted.shadowSkills[data.data.skill_name];
48711
+ this._persistState();
48712
+ }
48713
+ this.emit("shadow_session_deleted", data.data);
48714
+ }
48532
48715
  if (data.event === "hub_identity_removed") {
48533
48716
  if (this._persisted) {
48534
48717
  delete this._persisted.hubAddress;
@@ -50456,18 +50639,6 @@ var init_fetch_interceptor = __esm({
50456
50639
  }
50457
50640
  });
50458
50641
 
50459
- // src/openclaw-entry.ts
50460
- var init_openclaw_entry = __esm({
50461
- "src/openclaw-entry.ts"() {
50462
- "use strict";
50463
- init_account_config();
50464
- init_fetch_interceptor();
50465
- init_http_handlers();
50466
- init_openclaw_compat();
50467
- init_types();
50468
- }
50469
- });
50470
-
50471
50642
  // ../../node_modules/zod/v3/helpers/util.js
50472
50643
  var util, objectUtil, ZodParsedType, getParsedType;
50473
50644
  var init_util = __esm({
@@ -70590,7 +70761,7 @@ var init_mcp = __esm({
70590
70761
  });
70591
70762
 
70592
70763
  // ../../node_modules/@hono/node-server/dist/index.mjs
70593
- import { Readable } from "stream";
70764
+ import { Readable as Readable2 } from "stream";
70594
70765
  import crypto2 from "crypto";
70595
70766
  var GlobalRequest, Request2, newHeadersFromIncoming, wrapBodyStream, newRequestFromIncoming, getRequestCache, requestCache, incomingKey, urlKey, headersKey, abortControllerKey, getAbortController, requestPrototype, responseCache, getResponseCache, cacheKey, GlobalResponse, Response2;
70596
70767
  var init_dist2 = __esm({
@@ -70650,7 +70821,7 @@ var init_dist2 = __esm({
70650
70821
  init.body = new ReadableStream({
70651
70822
  async pull(controller) {
70652
70823
  try {
70653
- reader ||= Readable.toWeb(incoming).getReader();
70824
+ reader ||= Readable2.toWeb(incoming).getReader();
70654
70825
  const { done, value } = await reader.read();
70655
70826
  if (done) {
70656
70827
  controller.close();
@@ -70663,7 +70834,7 @@ var init_dist2 = __esm({
70663
70834
  }
70664
70835
  });
70665
70836
  } else {
70666
- init.body = Readable.toWeb(incoming);
70837
+ init.body = Readable2.toWeb(incoming);
70667
70838
  }
70668
70839
  }
70669
70840
  return new Request2(url2, init);
@@ -70824,13 +70995,6 @@ var init_mcp_server2 = __esm({
70824
70995
  }
70825
70996
  });
70826
70997
 
70827
- // src/mcp-handlers.ts
70828
- var init_mcp_handlers = __esm({
70829
- "src/mcp-handlers.ts"() {
70830
- "use strict";
70831
- }
70832
- });
70833
-
70834
70998
  // src/skill-manifest.ts
70835
70999
  function parseSkillMd(content) {
70836
71000
  const lines = content.split("\n");
@@ -70936,6 +71100,27 @@ var init_skill_manifest = __esm({
70936
71100
  }
70937
71101
  });
70938
71102
 
71103
+ // src/openclaw-entry.ts
71104
+ var init_openclaw_entry = __esm({
71105
+ "src/openclaw-entry.ts"() {
71106
+ "use strict";
71107
+ init_account_config();
71108
+ init_fetch_interceptor();
71109
+ init_http_handlers();
71110
+ init_openclaw_compat();
71111
+ init_types();
71112
+ init_mcp_server2();
71113
+ init_skill_manifest();
71114
+ }
71115
+ });
71116
+
71117
+ // src/mcp-handlers.ts
71118
+ var init_mcp_handlers = __esm({
71119
+ "src/mcp-handlers.ts"() {
71120
+ "use strict";
71121
+ }
71122
+ });
71123
+
70939
71124
  // src/skill-invoker.ts
70940
71125
  var init_skill_invoker = __esm({
70941
71126
  "src/skill-invoker.ts"() {