@rk0429/agentic-relay 2.0.3 → 2.0.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/relay.mjs +57 -22
- 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?.({
|
|
@@ -8270,6 +8284,23 @@ import { mkdirSync as mkdirSync3 } from "fs";
|
|
|
8270
8284
|
import path2 from "path";
|
|
8271
8285
|
import { randomUUID } from "crypto";
|
|
8272
8286
|
import { z as z8 } from "zod";
|
|
8287
|
+
function extractRelayContextFromUrl(url) {
|
|
8288
|
+
try {
|
|
8289
|
+
const parsed = new URL(url, "http://localhost");
|
|
8290
|
+
const depth = parsed.searchParams.get("relay_depth");
|
|
8291
|
+
const parentSessionId = parsed.searchParams.get("relay_parent_session_id");
|
|
8292
|
+
const traceId = parsed.searchParams.get("relay_trace_id");
|
|
8293
|
+
if (depth !== null && parentSessionId !== null) {
|
|
8294
|
+
return {
|
|
8295
|
+
depth: Number(depth),
|
|
8296
|
+
parentSessionId,
|
|
8297
|
+
traceId: traceId ?? `trace-${randomUUID()}`
|
|
8298
|
+
};
|
|
8299
|
+
}
|
|
8300
|
+
} catch {
|
|
8301
|
+
}
|
|
8302
|
+
return void 0;
|
|
8303
|
+
}
|
|
8273
8304
|
function createMcpServerOptions() {
|
|
8274
8305
|
const taskStore = new DeferredCleanupTaskStore();
|
|
8275
8306
|
return {
|
|
@@ -8406,7 +8437,7 @@ var init_server = __esm({
|
|
|
8406
8437
|
this.agentEventStore
|
|
8407
8438
|
);
|
|
8408
8439
|
this.server = new McpServer(
|
|
8409
|
-
{ name: "agentic-relay", version: "2.0.
|
|
8440
|
+
{ name: "agentic-relay", version: "2.0.4" },
|
|
8410
8441
|
createMcpServerOptions()
|
|
8411
8442
|
);
|
|
8412
8443
|
this.registerTools(this.server);
|
|
@@ -8436,7 +8467,7 @@ var init_server = __esm({
|
|
|
8436
8467
|
* Run spawn_agent in the background and store the result in taskStore.
|
|
8437
8468
|
* Fire-and-forget: errors are caught and stored as failed task results.
|
|
8438
8469
|
*/
|
|
8439
|
-
runSpawnAgentInBackground(taskId, params, extra) {
|
|
8470
|
+
runSpawnAgentInBackground(taskId, params, extra, relayContext) {
|
|
8440
8471
|
const run = async () => {
|
|
8441
8472
|
try {
|
|
8442
8473
|
const result = await executeSpawnAgent(
|
|
@@ -8452,7 +8483,8 @@ var init_server = __esm({
|
|
|
8452
8483
|
this.agentEventStore,
|
|
8453
8484
|
this.hookMemoryDir,
|
|
8454
8485
|
void 0,
|
|
8455
|
-
this.taskLifecycleManager
|
|
8486
|
+
this.taskLifecycleManager,
|
|
8487
|
+
relayContext
|
|
8456
8488
|
);
|
|
8457
8489
|
const controlOptions = {
|
|
8458
8490
|
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
@@ -8493,7 +8525,7 @@ var init_server = __esm({
|
|
|
8493
8525
|
* Run spawn_agents_parallel in the background and store the result in taskStore.
|
|
8494
8526
|
* Fire-and-forget: errors are caught and stored as failed task results.
|
|
8495
8527
|
*/
|
|
8496
|
-
runSpawnAgentsParallelInBackground(taskId, agents, extra) {
|
|
8528
|
+
runSpawnAgentsParallelInBackground(taskId, agents, extra, relayContext) {
|
|
8497
8529
|
const run = async () => {
|
|
8498
8530
|
try {
|
|
8499
8531
|
const result = await executeSpawnAgentsParallel(
|
|
@@ -8509,7 +8541,8 @@ var init_server = __esm({
|
|
|
8509
8541
|
this.agentEventStore,
|
|
8510
8542
|
this.hookMemoryDir,
|
|
8511
8543
|
void 0,
|
|
8512
|
-
this.taskLifecycleManager
|
|
8544
|
+
this.taskLifecycleManager,
|
|
8545
|
+
relayContext
|
|
8513
8546
|
);
|
|
8514
8547
|
const controlOptions = {
|
|
8515
8548
|
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
@@ -8545,7 +8578,7 @@ var init_server = __esm({
|
|
|
8545
8578
|
};
|
|
8546
8579
|
void run();
|
|
8547
8580
|
}
|
|
8548
|
-
registerTools(server) {
|
|
8581
|
+
registerTools(server, relayContext) {
|
|
8549
8582
|
server.experimental.tasks.registerToolTask(
|
|
8550
8583
|
"spawn_agent",
|
|
8551
8584
|
{
|
|
@@ -8559,7 +8592,7 @@ var init_server = __esm({
|
|
|
8559
8592
|
ttl: DEFAULT_TASK_TTL,
|
|
8560
8593
|
pollInterval: DEFAULT_POLL_INTERVAL
|
|
8561
8594
|
});
|
|
8562
|
-
this.runSpawnAgentInBackground(task.taskId, params, extra);
|
|
8595
|
+
this.runSpawnAgentInBackground(task.taskId, params, extra, relayContext);
|
|
8563
8596
|
return { task };
|
|
8564
8597
|
},
|
|
8565
8598
|
getTask: async (_params, extra) => {
|
|
@@ -8585,7 +8618,7 @@ var init_server = __esm({
|
|
|
8585
8618
|
ttl: DEFAULT_TASK_TTL,
|
|
8586
8619
|
pollInterval: DEFAULT_POLL_INTERVAL
|
|
8587
8620
|
});
|
|
8588
|
-
this.runSpawnAgentsParallelInBackground(task.taskId, params.agents, extra);
|
|
8621
|
+
this.runSpawnAgentsParallelInBackground(task.taskId, params.agents, extra, relayContext);
|
|
8589
8622
|
return { task };
|
|
8590
8623
|
},
|
|
8591
8624
|
getTask: async (_params, extra) => {
|
|
@@ -8623,7 +8656,8 @@ var init_server = __esm({
|
|
|
8623
8656
|
this.agentEventStore,
|
|
8624
8657
|
this.hookMemoryDir,
|
|
8625
8658
|
void 0,
|
|
8626
|
-
this.taskLifecycleManager
|
|
8659
|
+
this.taskLifecycleManager,
|
|
8660
|
+
relayContext
|
|
8627
8661
|
);
|
|
8628
8662
|
const controlOptions = {
|
|
8629
8663
|
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
@@ -8888,14 +8922,15 @@ var init_server = __esm({
|
|
|
8888
8922
|
return;
|
|
8889
8923
|
}
|
|
8890
8924
|
}
|
|
8925
|
+
const childRelayContext = extractRelayContextFromUrl(url);
|
|
8891
8926
|
const transport = new StreamableHTTPServerTransport({
|
|
8892
8927
|
sessionIdGenerator: () => randomUUID()
|
|
8893
8928
|
});
|
|
8894
8929
|
const server = new McpServer(
|
|
8895
|
-
{ name: "agentic-relay", version: "2.0.
|
|
8930
|
+
{ name: "agentic-relay", version: "2.0.4" },
|
|
8896
8931
|
createMcpServerOptions()
|
|
8897
8932
|
);
|
|
8898
|
-
this.registerTools(server);
|
|
8933
|
+
this.registerTools(server, childRelayContext);
|
|
8899
8934
|
transport.onclose = () => {
|
|
8900
8935
|
const sid2 = transport.sessionId;
|
|
8901
8936
|
if (sid2) {
|
|
@@ -13332,7 +13367,7 @@ function createMCPCommand(configManager2, registry2, sessionManager2, hooksEngin
|
|
|
13332
13367
|
responseOutputDir,
|
|
13333
13368
|
relayConfig
|
|
13334
13369
|
);
|
|
13335
|
-
await server.start({ transport, port, currentVersion: "2.0.
|
|
13370
|
+
await server.start({ transport, port, currentVersion: "2.0.4" });
|
|
13336
13371
|
}
|
|
13337
13372
|
})
|
|
13338
13373
|
},
|
|
@@ -13492,7 +13527,7 @@ function createVersionCommand(registry2) {
|
|
|
13492
13527
|
description: "Show relay and backend versions"
|
|
13493
13528
|
},
|
|
13494
13529
|
async run() {
|
|
13495
|
-
const relayVersion = "2.0.
|
|
13530
|
+
const relayVersion = "2.0.4";
|
|
13496
13531
|
console.log(`agentic-relay v${relayVersion}`);
|
|
13497
13532
|
console.log("");
|
|
13498
13533
|
console.log("Backends:");
|
|
@@ -13889,7 +13924,7 @@ var subCommandNames = /* @__PURE__ */ new Set(["claude", "codex", "gemini", "upd
|
|
|
13889
13924
|
var main = defineCommand11({
|
|
13890
13925
|
meta: {
|
|
13891
13926
|
name: "relay",
|
|
13892
|
-
version: "2.0.
|
|
13927
|
+
version: "2.0.4",
|
|
13893
13928
|
description: "Unified CLI proxy for Claude Code, Codex CLI, and Gemini CLI"
|
|
13894
13929
|
},
|
|
13895
13930
|
args: {
|
package/package.json
CHANGED