@rk0429/agentic-relay 2.0.4 → 2.0.6

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.
Files changed (2) hide show
  1. package/dist/relay.mjs +94 -28
  2. package/package.json +1 -1
package/dist/relay.mjs CHANGED
@@ -8273,7 +8273,8 @@ var init_response_formatter = __esm({
8273
8273
  // src/mcp-server/server.ts
8274
8274
  var server_exports = {};
8275
8275
  __export(server_exports, {
8276
- RelayMCPServer: () => RelayMCPServer
8276
+ RelayMCPServer: () => RelayMCPServer,
8277
+ extractRelayContextFromUrl: () => extractRelayContextFromUrl
8277
8278
  });
8278
8279
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8279
8280
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -8291,8 +8292,12 @@ function extractRelayContextFromUrl(url) {
8291
8292
  const parentSessionId = parsed.searchParams.get("relay_parent_session_id");
8292
8293
  const traceId = parsed.searchParams.get("relay_trace_id");
8293
8294
  if (depth !== null && parentSessionId !== null) {
8295
+ const parsedDepth = Number(depth);
8296
+ if (!Number.isFinite(parsedDepth) || parsedDepth < 0) {
8297
+ return void 0;
8298
+ }
8294
8299
  return {
8295
- depth: Number(depth),
8300
+ depth: parsedDepth,
8296
8301
  parentSessionId,
8297
8302
  traceId: traceId ?? `trace-${randomUUID()}`
8298
8303
  };
@@ -8437,7 +8442,7 @@ var init_server = __esm({
8437
8442
  this.agentEventStore
8438
8443
  );
8439
8444
  this.server = new McpServer(
8440
- { name: "agentic-relay", version: "2.0.4" },
8445
+ { name: "agentic-relay", version: "2.0.6" },
8441
8446
  createMcpServerOptions()
8442
8447
  );
8443
8448
  this.registerTools(this.server);
@@ -8455,6 +8460,8 @@ var init_server = __esm({
8455
8460
  purgeTimer;
8456
8461
  _childHttpServer;
8457
8462
  _childHttpUrl;
8463
+ _closePromise;
8464
+ _isClosed = false;
8458
8465
  /** URL for child agents to connect via HTTP. Available after start() in stdio mode. */
8459
8466
  get childHttpUrl() {
8460
8467
  return this._childHttpUrl;
@@ -8865,7 +8872,29 @@ var init_server = __esm({
8865
8872
  redirectToStderr();
8866
8873
  logger.info("Starting agentic-relay MCP server (stdio transport)...");
8867
8874
  const transport = new StdioServerTransport();
8868
- await this.server.connect(transport);
8875
+ const handleStdioDisconnect = () => {
8876
+ void transport.close().catch((error) => {
8877
+ const message = error instanceof Error ? error.message : String(error);
8878
+ logger.debug(`Failed to close stdio transport: ${message}`);
8879
+ void this.close();
8880
+ });
8881
+ };
8882
+ const cleanupStdioListeners = () => {
8883
+ process.stdin.off("end", handleStdioDisconnect);
8884
+ process.stdin.off("close", handleStdioDisconnect);
8885
+ };
8886
+ transport.onclose = () => {
8887
+ cleanupStdioListeners();
8888
+ void this.close();
8889
+ };
8890
+ process.stdin.once("end", handleStdioDisconnect);
8891
+ process.stdin.once("close", handleStdioDisconnect);
8892
+ try {
8893
+ await this.server.connect(transport);
8894
+ } catch (error) {
8895
+ cleanupStdioListeners();
8896
+ throw error;
8897
+ }
8869
8898
  await this.startChildHttpServer();
8870
8899
  return;
8871
8900
  }
@@ -8927,7 +8956,7 @@ var init_server = __esm({
8927
8956
  sessionIdGenerator: () => randomUUID()
8928
8957
  });
8929
8958
  const server = new McpServer(
8930
- { name: "agentic-relay", version: "2.0.4" },
8959
+ { name: "agentic-relay", version: "2.0.6" },
8931
8960
  createMcpServerOptions()
8932
8961
  );
8933
8962
  this.registerTools(server, childRelayContext);
@@ -8973,16 +9002,27 @@ var init_server = __esm({
8973
9002
  });
8974
9003
  }
8975
9004
  async close() {
8976
- this.sessionHealthMonitor.stop();
8977
- this.agentEventStore.cleanup();
8978
- clearInterval(this.purgeTimer);
8979
- if (this._childHttpServer) {
8980
- await new Promise((resolve3) => {
8981
- this._childHttpServer.close(() => resolve3());
8982
- });
8983
- this._childHttpServer = void 0;
8984
- this._childHttpUrl = void 0;
9005
+ if (this._isClosed) {
9006
+ return;
9007
+ }
9008
+ if (this._closePromise) {
9009
+ await this._closePromise;
9010
+ return;
8985
9011
  }
9012
+ this._closePromise = (async () => {
9013
+ this.sessionHealthMonitor.stop();
9014
+ this.agentEventStore.cleanup();
9015
+ clearInterval(this.purgeTimer);
9016
+ if (this._childHttpServer) {
9017
+ await new Promise((resolve3) => {
9018
+ this._childHttpServer.close(() => resolve3());
9019
+ });
9020
+ this._childHttpServer = void 0;
9021
+ this._childHttpUrl = void 0;
9022
+ }
9023
+ this._isClosed = true;
9024
+ })();
9025
+ await this._closePromise;
8986
9026
  }
8987
9027
  /** Exposed for testing and graceful shutdown */
8988
9028
  get httpServer() {
@@ -11056,20 +11096,46 @@ var CodexAdapter = class extends BaseAdapter {
11056
11096
  ...!authenticated ? { message: "codex authentication not configured" } : {}
11057
11097
  };
11058
11098
  }
11059
- buildCodexOptions(flags) {
11060
- if (!flags.mcpContext) {
11061
- return {};
11099
+ buildCodexMcpConfig(mcpServers) {
11100
+ if (!mcpServers || Object.keys(mcpServers).length === 0) {
11101
+ return void 0;
11062
11102
  }
11063
- const env = {};
11064
- for (const [key, value] of Object.entries(process.env)) {
11065
- if (value !== void 0) {
11066
- env[key] = value;
11103
+ const configServers = {};
11104
+ for (const [name, server] of Object.entries(mcpServers)) {
11105
+ if ("url" in server) {
11106
+ configServers[name] = {
11107
+ url: server.url,
11108
+ ...server.headers ? { headers: server.headers } : {}
11109
+ };
11110
+ } else {
11111
+ configServers[name] = {
11112
+ command: server.command,
11113
+ ...server.args ? { args: server.args } : {},
11114
+ ...server.env ? { env: server.env } : {}
11115
+ };
11116
+ }
11117
+ }
11118
+ return { mcp_servers: configServers };
11119
+ }
11120
+ buildCodexOptions(flags) {
11121
+ const options = {};
11122
+ if (flags.mcpContext) {
11123
+ const env = {};
11124
+ for (const [key, value] of Object.entries(process.env)) {
11125
+ if (value !== void 0) {
11126
+ env[key] = value;
11127
+ }
11067
11128
  }
11129
+ env.RELAY_TRACE_ID = flags.mcpContext.traceId;
11130
+ env.RELAY_PARENT_SESSION_ID = flags.mcpContext.parentSessionId;
11131
+ env.RELAY_DEPTH = String(flags.mcpContext.depth);
11132
+ options.env = env;
11133
+ }
11134
+ const config = this.buildCodexMcpConfig(flags.mcpServers);
11135
+ if (config) {
11136
+ options.config = config;
11068
11137
  }
11069
- env.RELAY_TRACE_ID = flags.mcpContext.traceId;
11070
- env.RELAY_PARENT_SESSION_ID = flags.mcpContext.parentSessionId;
11071
- env.RELAY_DEPTH = String(flags.mcpContext.depth);
11072
- return { env };
11138
+ return options;
11073
11139
  }
11074
11140
  mapFlags(flags) {
11075
11141
  const args = mapCommonToNative("codex", flags);
@@ -13367,7 +13433,7 @@ function createMCPCommand(configManager2, registry2, sessionManager2, hooksEngin
13367
13433
  responseOutputDir,
13368
13434
  relayConfig
13369
13435
  );
13370
- await server.start({ transport, port, currentVersion: "2.0.4" });
13436
+ await server.start({ transport, port, currentVersion: "2.0.6" });
13371
13437
  }
13372
13438
  })
13373
13439
  },
@@ -13527,7 +13593,7 @@ function createVersionCommand(registry2) {
13527
13593
  description: "Show relay and backend versions"
13528
13594
  },
13529
13595
  async run() {
13530
- const relayVersion = "2.0.4";
13596
+ const relayVersion = "2.0.6";
13531
13597
  console.log(`agentic-relay v${relayVersion}`);
13532
13598
  console.log("");
13533
13599
  console.log("Backends:");
@@ -13924,7 +13990,7 @@ var subCommandNames = /* @__PURE__ */ new Set(["claude", "codex", "gemini", "upd
13924
13990
  var main = defineCommand11({
13925
13991
  meta: {
13926
13992
  name: "relay",
13927
- version: "2.0.4",
13993
+ version: "2.0.6",
13928
13994
  description: "Unified CLI proxy for Claude Code, Codex CLI, and Gemini CLI"
13929
13995
  },
13930
13996
  args: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rk0429/agentic-relay",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Unified CLI proxy for Claude Code, Codex CLI, and Gemini CLI with MCP-based multi-layer sub-agent orchestration",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",