@rk0429/agentic-relay 0.16.2 → 1.0.0
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 +32 -143
- package/package.json +1 -1
package/dist/relay.mjs
CHANGED
|
@@ -817,13 +817,7 @@ var init_spawn_agent = __esm({
|
|
|
817
817
|
taskInstructionPath: z2.string().optional().describe(
|
|
818
818
|
"Path to a file containing task instructions. Content is prepended to the prompt. Path is resolved relative to the project root and validated against path traversal."
|
|
819
819
|
),
|
|
820
|
-
label: z2.string().optional().describe("Human-readable label for identifying this agent in parallel results and logs.")
|
|
821
|
-
maxResponseLength: z2.number().int().positive().optional().describe(
|
|
822
|
-
"Maximum response length in characters. When exceeded, response is truncated or summarized based on responseMode."
|
|
823
|
-
),
|
|
824
|
-
responseMode: z2.enum(["truncate", "summarize"]).optional().describe(
|
|
825
|
-
"How to handle responses exceeding maxResponseLength. 'truncate' (default) cuts at limit with file save. 'summarize' uses AI to condense."
|
|
826
|
-
)
|
|
820
|
+
label: z2.string().optional().describe("Human-readable label for identifying this agent in parallel results and logs.")
|
|
827
821
|
});
|
|
828
822
|
}
|
|
829
823
|
});
|
|
@@ -1213,70 +1207,6 @@ var init_types = __esm({
|
|
|
1213
1207
|
}
|
|
1214
1208
|
});
|
|
1215
1209
|
|
|
1216
|
-
// src/mcp-server/response-summarizer.ts
|
|
1217
|
-
async function loadClaudeSDK2() {
|
|
1218
|
-
return await import("@anthropic-ai/claude-agent-sdk");
|
|
1219
|
-
}
|
|
1220
|
-
function buildCleanEnv() {
|
|
1221
|
-
const env = {};
|
|
1222
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
1223
|
-
if (value !== void 0 && !CLAUDE_NESTING_ENV_VARS2.includes(key)) {
|
|
1224
|
-
env[key] = value;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
return env;
|
|
1228
|
-
}
|
|
1229
|
-
async function summarizeResponse(text, targetLength) {
|
|
1230
|
-
const { query } = await loadClaudeSDK2();
|
|
1231
|
-
const prompt = `Summarize the following text in ${targetLength} characters or less. Prioritize:
|
|
1232
|
-
1. Key deliverables, artifacts, and file changes
|
|
1233
|
-
2. Important decisions and conclusions
|
|
1234
|
-
3. Action items and next steps
|
|
1235
|
-
|
|
1236
|
-
Preserve technical details (file paths, function names, error messages) when possible.
|
|
1237
|
-
|
|
1238
|
-
<text>
|
|
1239
|
-
${text}
|
|
1240
|
-
</text>`;
|
|
1241
|
-
const q = query({
|
|
1242
|
-
prompt,
|
|
1243
|
-
options: {
|
|
1244
|
-
model: "haiku",
|
|
1245
|
-
maxTurns: 1,
|
|
1246
|
-
env: buildCleanEnv(),
|
|
1247
|
-
cwd: process.cwd(),
|
|
1248
|
-
permissionMode: "bypassPermissions",
|
|
1249
|
-
allowDangerouslySkipPermissions: true
|
|
1250
|
-
}
|
|
1251
|
-
});
|
|
1252
|
-
let resultText = "";
|
|
1253
|
-
for await (const message of q) {
|
|
1254
|
-
if (message.type === "result") {
|
|
1255
|
-
if (message.subtype === "success") {
|
|
1256
|
-
resultText = message.result;
|
|
1257
|
-
} else {
|
|
1258
|
-
const errors = message.errors;
|
|
1259
|
-
throw new Error(`Summarization failed: ${errors?.join("; ") ?? "unknown error"}`);
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
if (!resultText) {
|
|
1264
|
-
throw new Error("No result from summarization");
|
|
1265
|
-
}
|
|
1266
|
-
return resultText;
|
|
1267
|
-
}
|
|
1268
|
-
var CLAUDE_NESTING_ENV_VARS2;
|
|
1269
|
-
var init_response_summarizer = __esm({
|
|
1270
|
-
"src/mcp-server/response-summarizer.ts"() {
|
|
1271
|
-
"use strict";
|
|
1272
|
-
CLAUDE_NESTING_ENV_VARS2 = [
|
|
1273
|
-
"CLAUDECODE",
|
|
1274
|
-
"CLAUDE_CODE_SSE_PORT",
|
|
1275
|
-
"CLAUDE_CODE_ENTRYPOINT"
|
|
1276
|
-
];
|
|
1277
|
-
}
|
|
1278
|
-
});
|
|
1279
|
-
|
|
1280
1210
|
// src/mcp-server/response-formatter.ts
|
|
1281
1211
|
import * as fs from "fs";
|
|
1282
1212
|
import * as path from "path";
|
|
@@ -1311,28 +1241,17 @@ function saveFullResponse(content, sessionId) {
|
|
|
1311
1241
|
}
|
|
1312
1242
|
}
|
|
1313
1243
|
async function processStdout(stdout, options) {
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1316
|
-
if (stdout.length <= maxLength) {
|
|
1244
|
+
const inlineSummaryLength = options?.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH;
|
|
1245
|
+
if (stdout.length <= inlineSummaryLength) {
|
|
1317
1246
|
return { text: stdout, truncated: false };
|
|
1318
1247
|
}
|
|
1319
1248
|
const savedFilePath = saveFullResponse(stdout, options?.sessionId);
|
|
1320
|
-
const
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
const summary = await summarizeResponse(stdout, maxLength);
|
|
1324
|
-
const footer2 = `
|
|
1325
|
-
|
|
1326
|
-
[RESPONSE SUMMARIZED: original ${stdout.length} chars exceeded limit ${maxLength} chars.${savedInfo}]`;
|
|
1327
|
-
return { text: summary + footer2, truncated: true, savedFilePath };
|
|
1328
|
-
} catch {
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
const truncated = stdout.slice(0, maxLength);
|
|
1332
|
-
const footer = `
|
|
1249
|
+
const summary = stdout.slice(0, inlineSummaryLength);
|
|
1250
|
+
const fileRef = savedFilePath ?? "(file save failed)";
|
|
1251
|
+
const footer = `...
|
|
1333
1252
|
|
|
1334
|
-
[RESPONSE
|
|
1335
|
-
return { text:
|
|
1253
|
+
[FULL RESPONSE: ${stdout.length} chars \u2192 ${fileRef}]`;
|
|
1254
|
+
return { text: summary + footer, truncated: true, savedFilePath };
|
|
1336
1255
|
}
|
|
1337
1256
|
function truncateStderr(stderr) {
|
|
1338
1257
|
if (!stderr) return stderr;
|
|
@@ -1388,7 +1307,7 @@ ${JSON.stringify(result.metadata, null, 2)}
|
|
|
1388
1307
|
}
|
|
1389
1308
|
return { text, isError };
|
|
1390
1309
|
}
|
|
1391
|
-
async function formatParallelResponse(result, options
|
|
1310
|
+
async function formatParallelResponse(result, options) {
|
|
1392
1311
|
const isError = result.failureCount === result.totalCount;
|
|
1393
1312
|
const parts = [];
|
|
1394
1313
|
if (result.hasConflicts && result.conflicts) {
|
|
@@ -1408,7 +1327,7 @@ async function formatParallelResponse(result, options, perAgentOptions) {
|
|
|
1408
1327
|
const duration = r.metadata?.durationMs !== void 0 ? `${(r.metadata.durationMs / 1e3).toFixed(1)}s` : "?s";
|
|
1409
1328
|
if (r.exitCode === 0) {
|
|
1410
1329
|
parts.push(`--- Agent ${r.index}${labelPart} (${backend}, ${duration}) SUCCESS ---`);
|
|
1411
|
-
const agentOptions =
|
|
1330
|
+
const agentOptions = { ...options, sessionId: r.sessionId };
|
|
1412
1331
|
const processed = await processStdout(r.stdout || "", agentOptions);
|
|
1413
1332
|
parts.push(processed.text || "(no output)");
|
|
1414
1333
|
} else {
|
|
@@ -1418,18 +1337,21 @@ async function formatParallelResponse(result, options, perAgentOptions) {
|
|
|
1418
1337
|
}
|
|
1419
1338
|
parts.push("");
|
|
1420
1339
|
}
|
|
1340
|
+
const sanitizedResult = {
|
|
1341
|
+
...result,
|
|
1342
|
+
results: result.results.map(({ stdout: _stdout, stderr: _stderr, error: _error, ...rest }) => rest)
|
|
1343
|
+
};
|
|
1421
1344
|
parts.push(`<metadata>
|
|
1422
|
-
${JSON.stringify(
|
|
1345
|
+
${JSON.stringify(sanitizedResult, null, 2)}
|
|
1423
1346
|
</metadata>`);
|
|
1424
1347
|
return { text: parts.join("\n"), isError };
|
|
1425
1348
|
}
|
|
1426
|
-
var STDERR_MAX_LENGTH,
|
|
1349
|
+
var STDERR_MAX_LENGTH, DEFAULT_INLINE_SUMMARY_LENGTH, MAX_SAVED_RESPONSES, RESPONSE_DIR;
|
|
1427
1350
|
var init_response_formatter = __esm({
|
|
1428
1351
|
"src/mcp-server/response-formatter.ts"() {
|
|
1429
1352
|
"use strict";
|
|
1430
|
-
init_response_summarizer();
|
|
1431
1353
|
STDERR_MAX_LENGTH = 2e3;
|
|
1432
|
-
|
|
1354
|
+
DEFAULT_INLINE_SUMMARY_LENGTH = 500;
|
|
1433
1355
|
MAX_SAVED_RESPONSES = 100;
|
|
1434
1356
|
RESPONSE_DIR = path.join(os.tmpdir(), "agentic-relay-responses");
|
|
1435
1357
|
}
|
|
@@ -1478,16 +1400,16 @@ var init_server = __esm({
|
|
|
1478
1400
|
};
|
|
1479
1401
|
MAX_CHILD_HTTP_SESSIONS = 100;
|
|
1480
1402
|
RelayMCPServer = class {
|
|
1481
|
-
constructor(registry2, sessionManager2, guardConfig, hooksEngine2, contextMonitor2,
|
|
1403
|
+
constructor(registry2, sessionManager2, guardConfig, hooksEngine2, contextMonitor2, inlineSummaryLength) {
|
|
1482
1404
|
this.registry = registry2;
|
|
1483
1405
|
this.sessionManager = sessionManager2;
|
|
1484
1406
|
this.hooksEngine = hooksEngine2;
|
|
1485
1407
|
this.contextMonitor = contextMonitor2;
|
|
1486
|
-
this.
|
|
1408
|
+
this.inlineSummaryLength = inlineSummaryLength;
|
|
1487
1409
|
this.guard = new RecursionGuard(guardConfig);
|
|
1488
1410
|
this.backendSelector = new BackendSelector();
|
|
1489
1411
|
this.server = new McpServer(
|
|
1490
|
-
{ name: "agentic-relay", version: "0.
|
|
1412
|
+
{ name: "agentic-relay", version: "1.0.0" },
|
|
1491
1413
|
createMcpServerOptions()
|
|
1492
1414
|
);
|
|
1493
1415
|
this.registerTools(this.server);
|
|
@@ -1523,8 +1445,7 @@ var init_server = __esm({
|
|
|
1523
1445
|
this._childHttpUrl
|
|
1524
1446
|
);
|
|
1525
1447
|
const controlOptions = {
|
|
1526
|
-
|
|
1527
|
-
mode: params.responseMode ?? "truncate",
|
|
1448
|
+
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH,
|
|
1528
1449
|
sessionId: result.sessionId
|
|
1529
1450
|
};
|
|
1530
1451
|
const { text, isError } = await formatSpawnAgentResponse(result, controlOptions);
|
|
@@ -1575,25 +1496,9 @@ var init_server = __esm({
|
|
|
1575
1496
|
this._childHttpUrl
|
|
1576
1497
|
);
|
|
1577
1498
|
const controlOptions = {
|
|
1578
|
-
|
|
1579
|
-
mode: "truncate"
|
|
1499
|
+
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH
|
|
1580
1500
|
};
|
|
1581
|
-
const
|
|
1582
|
-
for (let i = 0; i < agents.length; i++) {
|
|
1583
|
-
const agent = agents[i];
|
|
1584
|
-
if (agent.maxResponseLength !== void 0 || agent.responseMode !== void 0) {
|
|
1585
|
-
perAgentOptions.set(i, {
|
|
1586
|
-
maxLength: agent.maxResponseLength ?? controlOptions.maxLength,
|
|
1587
|
-
mode: agent.responseMode ?? controlOptions.mode,
|
|
1588
|
-
sessionId: result.results[i]?.sessionId
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
const { text, isError } = await formatParallelResponse(
|
|
1593
|
-
result,
|
|
1594
|
-
controlOptions,
|
|
1595
|
-
perAgentOptions.size > 0 ? perAgentOptions : void 0
|
|
1596
|
-
);
|
|
1501
|
+
const { text, isError } = await formatParallelResponse(result, controlOptions);
|
|
1597
1502
|
const callToolResult = {
|
|
1598
1503
|
content: [{ type: "text", text }],
|
|
1599
1504
|
isError
|
|
@@ -1710,25 +1615,9 @@ var init_server = __esm({
|
|
|
1710
1615
|
this._childHttpUrl
|
|
1711
1616
|
);
|
|
1712
1617
|
const controlOptions = {
|
|
1713
|
-
|
|
1714
|
-
mode: "truncate"
|
|
1618
|
+
inlineSummaryLength: this.inlineSummaryLength ?? DEFAULT_INLINE_SUMMARY_LENGTH
|
|
1715
1619
|
};
|
|
1716
|
-
const
|
|
1717
|
-
for (let i = 0; i < agents.length; i++) {
|
|
1718
|
-
const agent = agents[i];
|
|
1719
|
-
if (agent.maxResponseLength !== void 0 || agent.responseMode !== void 0) {
|
|
1720
|
-
perAgentOptions.set(i, {
|
|
1721
|
-
maxLength: agent.maxResponseLength ?? controlOptions.maxLength,
|
|
1722
|
-
mode: agent.responseMode ?? controlOptions.mode,
|
|
1723
|
-
sessionId: result.results[i]?.sessionId
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
const { text, isError } = await formatParallelResponse(
|
|
1728
|
-
result,
|
|
1729
|
-
controlOptions,
|
|
1730
|
-
perAgentOptions.size > 0 ? perAgentOptions : void 0
|
|
1731
|
-
);
|
|
1620
|
+
const { text, isError } = await formatParallelResponse(result, controlOptions);
|
|
1732
1621
|
return {
|
|
1733
1622
|
content: [{ type: "text", text }],
|
|
1734
1623
|
isError
|
|
@@ -1892,7 +1781,7 @@ var init_server = __esm({
|
|
|
1892
1781
|
sessionIdGenerator: () => randomUUID()
|
|
1893
1782
|
});
|
|
1894
1783
|
const server = new McpServer(
|
|
1895
|
-
{ name: "agentic-relay", version: "0.
|
|
1784
|
+
{ name: "agentic-relay", version: "1.0.0" },
|
|
1896
1785
|
createMcpServerOptions()
|
|
1897
1786
|
);
|
|
1898
1787
|
this.registerTools(server);
|
|
@@ -3493,7 +3382,7 @@ var relayConfigSchema = z.object({
|
|
|
3493
3382
|
maxDepth: z.number().int().positive(),
|
|
3494
3383
|
maxCallsPerSession: z.number().int().positive(),
|
|
3495
3384
|
timeoutSec: z.number().positive(),
|
|
3496
|
-
|
|
3385
|
+
inlineSummaryLength: z.number().int().positive().optional()
|
|
3497
3386
|
}).optional(),
|
|
3498
3387
|
telemetry: z.object({
|
|
3499
3388
|
enabled: z.boolean()
|
|
@@ -4724,7 +4613,7 @@ function createMCPCommand(configManager2, registry2, sessionManager2, hooksEngin
|
|
|
4724
4613
|
return;
|
|
4725
4614
|
}
|
|
4726
4615
|
let guardConfig;
|
|
4727
|
-
let
|
|
4616
|
+
let inlineSummaryLength;
|
|
4728
4617
|
try {
|
|
4729
4618
|
const config = await configManager2.getConfig();
|
|
4730
4619
|
if (config.mcpServerMode) {
|
|
@@ -4733,7 +4622,7 @@ function createMCPCommand(configManager2, registry2, sessionManager2, hooksEngin
|
|
|
4733
4622
|
maxCallsPerSession: config.mcpServerMode.maxCallsPerSession ?? 20,
|
|
4734
4623
|
timeoutSec: config.mcpServerMode.timeoutSec ?? 86400
|
|
4735
4624
|
};
|
|
4736
|
-
|
|
4625
|
+
inlineSummaryLength = config.mcpServerMode.inlineSummaryLength;
|
|
4737
4626
|
}
|
|
4738
4627
|
} catch {
|
|
4739
4628
|
}
|
|
@@ -4745,7 +4634,7 @@ function createMCPCommand(configManager2, registry2, sessionManager2, hooksEngin
|
|
|
4745
4634
|
guardConfig,
|
|
4746
4635
|
hooksEngine2,
|
|
4747
4636
|
contextMonitor2,
|
|
4748
|
-
|
|
4637
|
+
inlineSummaryLength
|
|
4749
4638
|
);
|
|
4750
4639
|
await server.start({ transport, port });
|
|
4751
4640
|
}
|
|
@@ -4907,7 +4796,7 @@ function createVersionCommand(registry2) {
|
|
|
4907
4796
|
description: "Show relay and backend versions"
|
|
4908
4797
|
},
|
|
4909
4798
|
async run() {
|
|
4910
|
-
const relayVersion = "0.
|
|
4799
|
+
const relayVersion = "1.0.0";
|
|
4911
4800
|
console.log(`agentic-relay v${relayVersion}`);
|
|
4912
4801
|
console.log("");
|
|
4913
4802
|
console.log("Backends:");
|
|
@@ -5257,7 +5146,7 @@ void configManager.getConfig().then((config) => {
|
|
|
5257
5146
|
var main = defineCommand10({
|
|
5258
5147
|
meta: {
|
|
5259
5148
|
name: "relay",
|
|
5260
|
-
version: "0.
|
|
5149
|
+
version: "1.0.0",
|
|
5261
5150
|
description: "Unified CLI proxy for Claude Code, Codex CLI, and Gemini CLI"
|
|
5262
5151
|
},
|
|
5263
5152
|
subCommands: {
|
package/package.json
CHANGED