@rk0429/agentic-relay 2.0.3 → 2.0.5
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/relay.mjs +63 -23
- package/package.json +1 -1
package/dist/relay.mjs
CHANGED
|
@@ -992,11 +992,20 @@ function isRelayEntry(name, config) {
|
|
|
992
992
|
if (config.command?.includes("relay.mjs") || config.command?.includes("agentic-relay")) return true;
|
|
993
993
|
return false;
|
|
994
994
|
}
|
|
995
|
-
function buildChildMcpServers(parentMcpServers, childHttpUrl) {
|
|
995
|
+
function buildChildMcpServers(parentMcpServers, childHttpUrl, relayContext) {
|
|
996
996
|
const result = {};
|
|
997
997
|
for (const [name, config] of Object.entries(parentMcpServers)) {
|
|
998
998
|
if (isRelayEntry(name, config)) {
|
|
999
|
-
|
|
999
|
+
let url = childHttpUrl;
|
|
1000
|
+
if (relayContext) {
|
|
1001
|
+
const params = new URLSearchParams({
|
|
1002
|
+
relay_depth: String(relayContext.depth),
|
|
1003
|
+
relay_parent_session_id: relayContext.parentSessionId,
|
|
1004
|
+
relay_trace_id: relayContext.traceId
|
|
1005
|
+
});
|
|
1006
|
+
url = `${childHttpUrl}?${params.toString()}`;
|
|
1007
|
+
}
|
|
1008
|
+
result[name] = { type: "http", url };
|
|
1000
1009
|
} else if (config.type === "http" || config.type === "sse") {
|
|
1001
1010
|
result[name] = {
|
|
1002
1011
|
type: config.type,
|
|
@@ -1076,7 +1085,7 @@ function buildContextFromEnv() {
|
|
|
1076
1085
|
const depth = Number(process.env["RELAY_DEPTH"] ?? "0");
|
|
1077
1086
|
return { traceId, parentSessionId, depth };
|
|
1078
1087
|
}
|
|
1079
|
-
async function executeSpawnAgent(input, registry2, sessionManager2, guard, hooksEngine2, contextMonitor2, backendSelector, childHttpUrl, onProgress, agentEventStore, hookMemoryDir = "./memory", taskCompleter, taskLifecycleManager) {
|
|
1088
|
+
async function executeSpawnAgent(input, registry2, sessionManager2, guard, hooksEngine2, contextMonitor2, backendSelector, childHttpUrl, onProgress, agentEventStore, hookMemoryDir = "./memory", taskCompleter, taskLifecycleManager, relayContext) {
|
|
1080
1089
|
onProgress?.({ stage: "initializing", percent: 0 });
|
|
1081
1090
|
let inlineTaskId;
|
|
1082
1091
|
if (input.title && taskLifecycleManager) {
|
|
@@ -1119,7 +1128,7 @@ async function executeSpawnAgent(input, registry2, sessionManager2, guard, hooks
|
|
|
1119
1128
|
effectiveBackend = "claude";
|
|
1120
1129
|
selectionReason = "default(no-selector)";
|
|
1121
1130
|
}
|
|
1122
|
-
const envContext = buildContextFromEnv();
|
|
1131
|
+
const envContext = relayContext ?? buildContextFromEnv();
|
|
1123
1132
|
const promptHash = RecursionGuard.hashPrompt(input.prompt);
|
|
1124
1133
|
const context = {
|
|
1125
1134
|
traceId: envContext.traceId,
|
|
@@ -1378,7 +1387,11 @@ ${input.prompt}`;
|
|
|
1378
1387
|
if (childHttpUrl) {
|
|
1379
1388
|
const parentMcpServers = readProjectMcpJson();
|
|
1380
1389
|
if (Object.keys(parentMcpServers).length > 0) {
|
|
1381
|
-
mcpServers = buildChildMcpServers(parentMcpServers, childHttpUrl
|
|
1390
|
+
mcpServers = buildChildMcpServers(parentMcpServers, childHttpUrl, {
|
|
1391
|
+
depth: envContext.depth + 1,
|
|
1392
|
+
parentSessionId: session.relaySessionId,
|
|
1393
|
+
traceId: envContext.traceId
|
|
1394
|
+
});
|
|
1382
1395
|
}
|
|
1383
1396
|
}
|
|
1384
1397
|
return adapter.execute({
|
|
@@ -1840,7 +1853,7 @@ var init_conflict_detector = __esm({
|
|
|
1840
1853
|
});
|
|
1841
1854
|
|
|
1842
1855
|
// src/mcp-server/tools/spawn-agents-parallel.ts
|
|
1843
|
-
async function executeSpawnAgentsParallel(agents, registry2, sessionManager2, guard, hooksEngine2, contextMonitor2, backendSelector, childHttpUrl, onProgress, agentEventStore, hookMemoryDir = "./memory", taskCompleter, taskLifecycleManager) {
|
|
1856
|
+
async function executeSpawnAgentsParallel(agents, registry2, sessionManager2, guard, hooksEngine2, contextMonitor2, backendSelector, childHttpUrl, onProgress, agentEventStore, hookMemoryDir = "./memory", taskCompleter, taskLifecycleManager, relayContext) {
|
|
1844
1857
|
for (let index = 0; index < agents.length; index += 1) {
|
|
1845
1858
|
try {
|
|
1846
1859
|
resolveValidatedSessionMetadata(agents[index]);
|
|
@@ -1865,7 +1878,7 @@ async function executeSpawnAgentsParallel(agents, registry2, sessionManager2, gu
|
|
|
1865
1878
|
};
|
|
1866
1879
|
}
|
|
1867
1880
|
}
|
|
1868
|
-
const envContext = buildContextFromEnv();
|
|
1881
|
+
const envContext = relayContext ?? buildContextFromEnv();
|
|
1869
1882
|
if (envContext.depth >= guard.getConfig().maxDepth) {
|
|
1870
1883
|
const reason = `Max depth exceeded: ${envContext.depth} >= ${guard.getConfig().maxDepth}`;
|
|
1871
1884
|
logger.warn(`Batch spawn blocked by RecursionGuard: ${reason}`);
|
|
@@ -1925,7 +1938,8 @@ async function executeSpawnAgentsParallel(agents, registry2, sessionManager2, gu
|
|
|
1925
1938
|
agentEventStore,
|
|
1926
1939
|
hookMemoryDir,
|
|
1927
1940
|
taskCompleter,
|
|
1928
|
-
taskLifecycleManager
|
|
1941
|
+
taskLifecycleManager,
|
|
1942
|
+
relayContext
|
|
1929
1943
|
).then((result) => {
|
|
1930
1944
|
completedCount++;
|
|
1931
1945
|
onProgress?.({
|
|
@@ -8259,7 +8273,8 @@ var init_response_formatter = __esm({
|
|
|
8259
8273
|
// src/mcp-server/server.ts
|
|
8260
8274
|
var server_exports = {};
|
|
8261
8275
|
__export(server_exports, {
|
|
8262
|
-
RelayMCPServer: () => RelayMCPServer
|
|
8276
|
+
RelayMCPServer: () => RelayMCPServer,
|
|
8277
|
+
extractRelayContextFromUrl: () => extractRelayContextFromUrl
|
|
8263
8278
|
});
|
|
8264
8279
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8265
8280
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -8270,6 +8285,27 @@ import { mkdirSync as mkdirSync3 } from "fs";
|
|
|
8270
8285
|
import path2 from "path";
|
|
8271
8286
|
import { randomUUID } from "crypto";
|
|
8272
8287
|
import { z as z8 } from "zod";
|
|
8288
|
+
function extractRelayContextFromUrl(url) {
|
|
8289
|
+
try {
|
|
8290
|
+
const parsed = new URL(url, "http://localhost");
|
|
8291
|
+
const depth = parsed.searchParams.get("relay_depth");
|
|
8292
|
+
const parentSessionId = parsed.searchParams.get("relay_parent_session_id");
|
|
8293
|
+
const traceId = parsed.searchParams.get("relay_trace_id");
|
|
8294
|
+
if (depth !== null && parentSessionId !== null) {
|
|
8295
|
+
const parsedDepth = Number(depth);
|
|
8296
|
+
if (!Number.isFinite(parsedDepth) || parsedDepth < 0) {
|
|
8297
|
+
return void 0;
|
|
8298
|
+
}
|
|
8299
|
+
return {
|
|
8300
|
+
depth: parsedDepth,
|
|
8301
|
+
parentSessionId,
|
|
8302
|
+
traceId: traceId ?? `trace-${randomUUID()}`
|
|
8303
|
+
};
|
|
8304
|
+
}
|
|
8305
|
+
} catch {
|
|
8306
|
+
}
|
|
8307
|
+
return void 0;
|
|
8308
|
+
}
|
|
8273
8309
|
function createMcpServerOptions() {
|
|
8274
8310
|
const taskStore = new DeferredCleanupTaskStore();
|
|
8275
8311
|
return {
|
|
@@ -8406,7 +8442,7 @@ var init_server = __esm({
|
|
|
8406
8442
|
this.agentEventStore
|
|
8407
8443
|
);
|
|
8408
8444
|
this.server = new McpServer(
|
|
8409
|
-
{ name: "agentic-relay", version: "2.0.
|
|
8445
|
+
{ name: "agentic-relay", version: "2.0.5" },
|
|
8410
8446
|
createMcpServerOptions()
|
|
8411
8447
|
);
|
|
8412
8448
|
this.registerTools(this.server);
|
|
@@ -8436,7 +8472,7 @@ var init_server = __esm({
|
|
|
8436
8472
|
* Run spawn_agent in the background and store the result in taskStore.
|
|
8437
8473
|
* Fire-and-forget: errors are caught and stored as failed task results.
|
|
8438
8474
|
*/
|
|
8439
|
-
runSpawnAgentInBackground(taskId, params, extra) {
|
|
8475
|
+
runSpawnAgentInBackground(taskId, params, extra, relayContext) {
|
|
8440
8476
|
const run = async () => {
|
|
8441
8477
|
try {
|
|
8442
8478
|
const result = await executeSpawnAgent(
|
|
@@ -8452,7 +8488,8 @@ var init_server = __esm({
|
|
|
8452
8488
|
this.agentEventStore,
|
|
8453
8489
|
this.hookMemoryDir,
|
|
8454
8490
|
void 0,
|
|
8455
|
-
this.taskLifecycleManager
|
|
8491
|
+
this.taskLifecycleManager,
|
|
8492
|
+
relayContext
|
|
8456
8493
|
);
|
|
8457
8494
|
const controlOptions = {
|
|
8458
8495
|
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
@@ -8493,7 +8530,7 @@ var init_server = __esm({
|
|
|
8493
8530
|
* Run spawn_agents_parallel in the background and store the result in taskStore.
|
|
8494
8531
|
* Fire-and-forget: errors are caught and stored as failed task results.
|
|
8495
8532
|
*/
|
|
8496
|
-
runSpawnAgentsParallelInBackground(taskId, agents, extra) {
|
|
8533
|
+
runSpawnAgentsParallelInBackground(taskId, agents, extra, relayContext) {
|
|
8497
8534
|
const run = async () => {
|
|
8498
8535
|
try {
|
|
8499
8536
|
const result = await executeSpawnAgentsParallel(
|
|
@@ -8509,7 +8546,8 @@ var init_server = __esm({
|
|
|
8509
8546
|
this.agentEventStore,
|
|
8510
8547
|
this.hookMemoryDir,
|
|
8511
8548
|
void 0,
|
|
8512
|
-
this.taskLifecycleManager
|
|
8549
|
+
this.taskLifecycleManager,
|
|
8550
|
+
relayContext
|
|
8513
8551
|
);
|
|
8514
8552
|
const controlOptions = {
|
|
8515
8553
|
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
@@ -8545,7 +8583,7 @@ var init_server = __esm({
|
|
|
8545
8583
|
};
|
|
8546
8584
|
void run();
|
|
8547
8585
|
}
|
|
8548
|
-
registerTools(server) {
|
|
8586
|
+
registerTools(server, relayContext) {
|
|
8549
8587
|
server.experimental.tasks.registerToolTask(
|
|
8550
8588
|
"spawn_agent",
|
|
8551
8589
|
{
|
|
@@ -8559,7 +8597,7 @@ var init_server = __esm({
|
|
|
8559
8597
|
ttl: DEFAULT_TASK_TTL,
|
|
8560
8598
|
pollInterval: DEFAULT_POLL_INTERVAL
|
|
8561
8599
|
});
|
|
8562
|
-
this.runSpawnAgentInBackground(task.taskId, params, extra);
|
|
8600
|
+
this.runSpawnAgentInBackground(task.taskId, params, extra, relayContext);
|
|
8563
8601
|
return { task };
|
|
8564
8602
|
},
|
|
8565
8603
|
getTask: async (_params, extra) => {
|
|
@@ -8585,7 +8623,7 @@ var init_server = __esm({
|
|
|
8585
8623
|
ttl: DEFAULT_TASK_TTL,
|
|
8586
8624
|
pollInterval: DEFAULT_POLL_INTERVAL
|
|
8587
8625
|
});
|
|
8588
|
-
this.runSpawnAgentsParallelInBackground(task.taskId, params.agents, extra);
|
|
8626
|
+
this.runSpawnAgentsParallelInBackground(task.taskId, params.agents, extra, relayContext);
|
|
8589
8627
|
return { task };
|
|
8590
8628
|
},
|
|
8591
8629
|
getTask: async (_params, extra) => {
|
|
@@ -8623,7 +8661,8 @@ var init_server = __esm({
|
|
|
8623
8661
|
this.agentEventStore,
|
|
8624
8662
|
this.hookMemoryDir,
|
|
8625
8663
|
void 0,
|
|
8626
|
-
this.taskLifecycleManager
|
|
8664
|
+
this.taskLifecycleManager,
|
|
8665
|
+
relayContext
|
|
8627
8666
|
);
|
|
8628
8667
|
const controlOptions = {
|
|
8629
8668
|
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
@@ -8888,14 +8927,15 @@ var init_server = __esm({
|
|
|
8888
8927
|
return;
|
|
8889
8928
|
}
|
|
8890
8929
|
}
|
|
8930
|
+
const childRelayContext = extractRelayContextFromUrl(url);
|
|
8891
8931
|
const transport = new StreamableHTTPServerTransport({
|
|
8892
8932
|
sessionIdGenerator: () => randomUUID()
|
|
8893
8933
|
});
|
|
8894
8934
|
const server = new McpServer(
|
|
8895
|
-
{ name: "agentic-relay", version: "2.0.
|
|
8935
|
+
{ name: "agentic-relay", version: "2.0.5" },
|
|
8896
8936
|
createMcpServerOptions()
|
|
8897
8937
|
);
|
|
8898
|
-
this.registerTools(server);
|
|
8938
|
+
this.registerTools(server, childRelayContext);
|
|
8899
8939
|
transport.onclose = () => {
|
|
8900
8940
|
const sid2 = transport.sessionId;
|
|
8901
8941
|
if (sid2) {
|
|
@@ -13332,7 +13372,7 @@ function createMCPCommand(configManager2, registry2, sessionManager2, hooksEngin
|
|
|
13332
13372
|
responseOutputDir,
|
|
13333
13373
|
relayConfig
|
|
13334
13374
|
);
|
|
13335
|
-
await server.start({ transport, port, currentVersion: "2.0.
|
|
13375
|
+
await server.start({ transport, port, currentVersion: "2.0.5" });
|
|
13336
13376
|
}
|
|
13337
13377
|
})
|
|
13338
13378
|
},
|
|
@@ -13492,7 +13532,7 @@ function createVersionCommand(registry2) {
|
|
|
13492
13532
|
description: "Show relay and backend versions"
|
|
13493
13533
|
},
|
|
13494
13534
|
async run() {
|
|
13495
|
-
const relayVersion = "2.0.
|
|
13535
|
+
const relayVersion = "2.0.5";
|
|
13496
13536
|
console.log(`agentic-relay v${relayVersion}`);
|
|
13497
13537
|
console.log("");
|
|
13498
13538
|
console.log("Backends:");
|
|
@@ -13889,7 +13929,7 @@ var subCommandNames = /* @__PURE__ */ new Set(["claude", "codex", "gemini", "upd
|
|
|
13889
13929
|
var main = defineCommand11({
|
|
13890
13930
|
meta: {
|
|
13891
13931
|
name: "relay",
|
|
13892
|
-
version: "2.0.
|
|
13932
|
+
version: "2.0.5",
|
|
13893
13933
|
description: "Unified CLI proxy for Claude Code, Codex CLI, and Gemini CLI"
|
|
13894
13934
|
},
|
|
13895
13935
|
args: {
|
package/package.json
CHANGED