@byok-sdk/client 0.10.2 → 0.12.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/README.md +86 -6
- package/dist/adapters/claude/claude-adapter.d.ts +3 -2
- package/dist/adapters/claude/permission-mapping.d.ts +48 -1
- package/dist/adapters/claude/resolve-approval-mcp-bin.d.ts +3 -2
- package/dist/adapters/codex/permission-mapping.d.ts +16 -0
- package/dist/adapters/index.js +292 -23
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/mcp-tool-grants.d.ts +36 -0
- package/dist/adapters/pi/resolve-extensions.d.ts +4 -1
- package/dist/adapters/pi/subagents-policy-config.d.ts +7 -0
- package/dist/adapters/pi/subagents-policy-extension.js +137 -0
- package/dist/adapters/pi/subagents-policy-extension.js.map +1 -0
- package/dist/agent-home.d.ts +33 -0
- package/dist/agent-memory/index.d.ts +1 -1
- package/dist/agent-memory/index.js +12 -9
- package/dist/agent-memory/index.js.map +1 -1
- package/dist/bin/agent-memory-mcp-server.d.ts +2 -2
- package/dist/bin/agent-message-mcp-server.d.ts +0 -1
- package/dist/bin/byok-agent-memory-mcp.js +340 -7
- package/dist/bin/byok-agent-memory-mcp.js.map +1 -1
- package/dist/bin/byok-agent-message-mcp.js +331 -7
- package/dist/bin/byok-agent-message-mcp.js.map +1 -1
- package/dist/bin/byok-agent-team-mcp.d.ts +2 -0
- package/dist/bin/byok-agent-team-mcp.js +765 -0
- package/dist/bin/byok-agent-team-mcp.js.map +1 -0
- package/dist/bin/byok-agent.js +16413 -14479
- package/dist/bin/byok-agent.js.map +1 -1
- package/dist/bin/byok-approval-mcp.js +312 -45
- package/dist/bin/byok-approval-mcp.js.map +1 -1
- package/dist/bin/commands/team.d.ts +15 -0
- package/dist/bin/sdk-reserved-helper-runners.d.ts +2 -0
- package/dist/bin/team-mcp-server.d.ts +27 -0
- package/dist/bin/team-tmux-view.d.ts +19 -0
- package/dist/daemon/agent-egress-controller.d.ts +4 -0
- package/dist/daemon/agent-message-mcp-preflight.d.ts +17 -0
- package/dist/daemon/auth-manager.d.ts +20 -0
- package/dist/daemon/blob-client.d.ts +24 -6
- package/dist/daemon/connection-manager.d.ts +7 -0
- package/dist/daemon/control-protocol.d.ts +38 -0
- package/dist/daemon/create-daemon.d.ts +9 -0
- package/dist/daemon/device-credential-store.d.ts +16 -0
- package/dist/daemon/long-poll-transport.d.ts +3 -0
- package/dist/daemon/mcp-tools-probe.d.ts +105 -0
- package/dist/daemon/replay-cursor.d.ts +9 -0
- package/dist/daemon/resolve-agent-memory-mcp-bin.d.ts +2 -1
- package/dist/daemon/resolve-agent-message-mcp-bin.d.ts +2 -1
- package/dist/daemon/task-runner.d.ts +22 -1
- package/dist/daemon/team-workspace.d.ts +202 -0
- package/dist/daemon/toolset-registry.d.ts +0 -2
- package/dist/daemon/url.d.ts +7 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +3611 -1364
- package/dist/index.js.map +1 -1
- package/dist/sdk-reserved-helper-host.d.ts +25 -0
- package/dist/sdk-reserved-mcp.d.ts +23 -0
- package/dist/types.d.ts +36 -0
- package/package.json +10 -5
|
@@ -335,6 +335,8 @@ function createControlClient(socket, reader, opts) {
|
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
337
|
var AGENT_MESSAGE_TOOL_NAME = "send_agent_message";
|
|
338
|
+
|
|
339
|
+
// src/bin/agent-message-mcp-server.ts
|
|
338
340
|
async function handleAgentMessageMcpRequest(request, deps) {
|
|
339
341
|
const id = request.id;
|
|
340
342
|
if (request.method === "initialize") {
|
|
@@ -374,14 +376,14 @@ async function handleAgentMessageMcpRequest(request, deps) {
|
|
|
374
376
|
if (params.name !== AGENT_MESSAGE_TOOL_NAME) return { jsonrpc: "2.0", id, error: { code: -32602, message: "unknown Agent message tool" } };
|
|
375
377
|
const args = params.arguments;
|
|
376
378
|
if (args === null || typeof args !== "object" || Array.isArray(args)) return { jsonrpc: "2.0", id, error: { code: -32602, message: "message input must be an object" } };
|
|
377
|
-
const
|
|
378
|
-
if (Object.keys(
|
|
379
|
+
const record3 = args;
|
|
380
|
+
if (Object.keys(record3).some((key) => key !== "body" && key !== "contentType") || typeof record3.body !== "string" || record3.body.length === 0) {
|
|
379
381
|
return { jsonrpc: "2.0", id, error: { code: -32602, message: "message input accepts only non-empty body and optional contentType" } };
|
|
380
382
|
}
|
|
381
|
-
const contentType =
|
|
383
|
+
const contentType = record3.contentType ?? "text/markdown";
|
|
382
384
|
if (contentType !== "text/plain" && contentType !== "text/markdown") return { jsonrpc: "2.0", id, error: { code: -32602, message: "unsupported contentType" } };
|
|
383
385
|
try {
|
|
384
|
-
const receipt = await deps.publish({ contentType, body:
|
|
386
|
+
const receipt = await deps.publish({ contentType, body: record3.body });
|
|
385
387
|
return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: JSON.stringify(receipt) }] } };
|
|
386
388
|
} catch (error) {
|
|
387
389
|
return { jsonrpc: "2.0", id, error: { code: -32e3, message: error instanceof Error ? error.message : String(error) } };
|
|
@@ -408,14 +410,245 @@ function serveAgentMessageMcpOverStdio(input) {
|
|
|
408
410
|
})();
|
|
409
411
|
});
|
|
410
412
|
}
|
|
413
|
+
var AGENT_MEMORY_RECALL_TOOL_NAME = "memory_recall";
|
|
414
|
+
var AGENT_MEMORY_SAVE_TOOL_NAME = "memory_save";
|
|
415
|
+
function record(value) {
|
|
416
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
417
|
+
}
|
|
418
|
+
function invalid(id, message) {
|
|
419
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message } };
|
|
420
|
+
}
|
|
421
|
+
function success(id, value) {
|
|
422
|
+
return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: JSON.stringify(value) }] } };
|
|
423
|
+
}
|
|
424
|
+
async function handleAgentMemoryMcpRequest(request, deps) {
|
|
425
|
+
const id = request.id;
|
|
426
|
+
if (request.method === "initialize") {
|
|
427
|
+
const params2 = record(request.params) ?? {};
|
|
428
|
+
return { jsonrpc: "2.0", id, result: { protocolVersion: typeof params2.protocolVersion === "string" ? params2.protocolVersion : "2024-11-05", capabilities: { tools: {} }, serverInfo: { name: "byok-agent-memory-mcp", version: "0.0.1" } } };
|
|
429
|
+
}
|
|
430
|
+
if (request.method === "notifications/initialized") return void 0;
|
|
431
|
+
if (request.method === "tools/list") return {
|
|
432
|
+
jsonrpc: "2.0",
|
|
433
|
+
id,
|
|
434
|
+
result: { tools: [
|
|
435
|
+
{ name: AGENT_MEMORY_RECALL_TOOL_NAME, description: "Recall one SDK-owned memory file for this exact active Agent task. Identity and memory root are never model parameters.", inputSchema: { type: "object", additionalProperties: false, required: ["path"], properties: { path: { type: "string" }, ifRevision: { type: "string", pattern: "^sha256:[a-f0-9]{64}$" } } } },
|
|
436
|
+
{ name: AGENT_MEMORY_SAVE_TOOL_NAME, description: "Atomically replace or delete one SDK-owned memory file with exact sha256 compare-and-swap.", inputSchema: { type: "object", additionalProperties: false, required: ["op", "path", "expectedRevision"], properties: { op: { type: "string", enum: ["replace", "delete"] }, path: { type: "string" }, expectedRevision: { type: "string", pattern: "^sha256:[a-f0-9]{64}$" }, content: { type: "string" } } } }
|
|
437
|
+
] }
|
|
438
|
+
};
|
|
439
|
+
if (request.method !== "tools/call") return id === void 0 ? void 0 : { jsonrpc: "2.0", id, error: { code: -32601, message: `unknown method: ${String(request.method)}` } };
|
|
440
|
+
const params = record(request.params);
|
|
441
|
+
const args = record(params?.arguments);
|
|
442
|
+
if (!params || !args || typeof params.name !== "string") return invalid(id, "memory tool input must be an object");
|
|
443
|
+
try {
|
|
444
|
+
if (params.name === AGENT_MEMORY_RECALL_TOOL_NAME) {
|
|
445
|
+
if (Object.keys(args).some((key) => key !== "path" && key !== "ifRevision") || typeof args.path !== "string" || args.ifRevision !== void 0 && typeof args.ifRevision !== "string") return invalid(id, "memory_recall accepts only path and optional ifRevision");
|
|
446
|
+
return success(id, await deps.recall({ path: args.path, ...args.ifRevision === void 0 ? {} : { ifRevision: args.ifRevision } }));
|
|
447
|
+
}
|
|
448
|
+
if (params.name === AGENT_MEMORY_SAVE_TOOL_NAME) {
|
|
449
|
+
if (Object.keys(args).some((key) => key !== "op" && key !== "path" && key !== "expectedRevision" && key !== "content") || args.op !== "replace" && args.op !== "delete" || typeof args.path !== "string" || typeof args.expectedRevision !== "string" || args.op === "replace" && typeof args.content !== "string" || args.op === "delete" && args.content !== void 0) return invalid(id, "memory_save requires replace|delete, path, expectedRevision, and content only for replace");
|
|
450
|
+
const content = args.content;
|
|
451
|
+
return success(id, await deps.save({ op: args.op, path: args.path, expectedRevision: args.expectedRevision, ...typeof content === "string" ? { content } : {} }));
|
|
452
|
+
}
|
|
453
|
+
return invalid(id, "unknown Agent memory tool");
|
|
454
|
+
} catch (error) {
|
|
455
|
+
return { jsonrpc: "2.0", id, error: { code: -32e3, message: error instanceof Error ? error.message : String(error) } };
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function serveAgentMemoryMcpOverStdio(input) {
|
|
459
|
+
const reader = createInterface({ input: input.stdin ?? process.stdin, terminal: false });
|
|
460
|
+
const output = input.stdout ?? process.stdout;
|
|
461
|
+
reader.on("line", (line) => {
|
|
462
|
+
const trimmed = line.trim();
|
|
463
|
+
if (!trimmed) return;
|
|
464
|
+
void (async () => {
|
|
465
|
+
let request;
|
|
466
|
+
try {
|
|
467
|
+
request = JSON.parse(trimmed);
|
|
468
|
+
} catch {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const response = await handleAgentMemoryMcpRequest(request, input.deps);
|
|
472
|
+
if (response !== void 0) output.write(`${JSON.stringify(response)}
|
|
473
|
+
`);
|
|
474
|
+
})();
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
var TEAM_POST_TOOL_NAME = "post_team_message";
|
|
478
|
+
var TEAM_READ_TOOL_NAME = "read_team_messages";
|
|
479
|
+
var TEAM_ACK_TOOL_NAME = "ack_team_messages";
|
|
480
|
+
var record2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
481
|
+
var invalid2 = (id, message) => ({ jsonrpc: "2.0", id, error: { code: -32602, message } });
|
|
482
|
+
var success2 = (id, value) => ({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text: JSON.stringify(value) }] } });
|
|
483
|
+
async function handleTeamMcpRequest(request, deps) {
|
|
484
|
+
const { id } = request;
|
|
485
|
+
if (request.method === "initialize") {
|
|
486
|
+
const params2 = record2(request.params) ?? {};
|
|
487
|
+
return { jsonrpc: "2.0", id, result: { protocolVersion: typeof params2.protocolVersion === "string" ? params2.protocolVersion : "2024-11-05", capabilities: { tools: {} }, serverInfo: { name: "byok-agent-team-mcp", version: "0.0.1" } } };
|
|
488
|
+
}
|
|
489
|
+
if (request.method === "notifications/initialized") return void 0;
|
|
490
|
+
if (request.method === "tools/list") return { jsonrpc: "2.0", id, result: { tools: [
|
|
491
|
+
{ name: TEAM_POST_TOOL_NAME, description: "Post one broadcast message as this exact leased team member. Sender and workspace are daemon-owned.", inputSchema: { type: "object", additionalProperties: false, required: ["body"], properties: { body: { type: "string" }, contentType: { type: "string" } } } },
|
|
492
|
+
{ name: TEAM_READ_TOOL_NAME, description: "Read ordered team messages visible to this exact leased member.", inputSchema: { type: "object", additionalProperties: false, properties: { afterSeq: { type: "integer", minimum: 0 } } } },
|
|
493
|
+
{ name: TEAM_ACK_TOOL_NAME, description: "Durably acknowledge messages through an already delivered sequence for this exact leased member.", inputSchema: { type: "object", additionalProperties: false, required: ["throughSeq"], properties: { throughSeq: { type: "integer", minimum: 0 } } } }
|
|
494
|
+
] } };
|
|
495
|
+
if (request.method !== "tools/call") return id === void 0 ? void 0 : { jsonrpc: "2.0", id, error: { code: -32601, message: `unknown method: ${String(request.method)}` } };
|
|
496
|
+
const params = record2(request.params);
|
|
497
|
+
const args = record2(params?.arguments);
|
|
498
|
+
if (!params || !args || typeof params.name !== "string") return invalid2(id, "team tool input must be an object");
|
|
499
|
+
try {
|
|
500
|
+
if (params.name === TEAM_POST_TOOL_NAME) {
|
|
501
|
+
if (Object.keys(args).some((key) => key !== "body" && key !== "contentType") || typeof args.body !== "string" || args.contentType !== void 0 && typeof args.contentType !== "string") return invalid2(id, "post_team_message accepts body and optional contentType only");
|
|
502
|
+
return success2(id, await deps.post({ body: args.body, ...typeof args.contentType === "string" ? { contentType: args.contentType } : {} }));
|
|
503
|
+
}
|
|
504
|
+
if (params.name === TEAM_READ_TOOL_NAME) {
|
|
505
|
+
if (Object.keys(args).some((key) => key !== "afterSeq") || args.afterSeq !== void 0 && (!Number.isSafeInteger(args.afterSeq) || Number(args.afterSeq) < 0)) return invalid2(id, "read_team_messages accepts optional non-negative integer afterSeq only");
|
|
506
|
+
return success2(id, await deps.read(args.afterSeq === void 0 ? {} : { afterSeq: Number(args.afterSeq) }));
|
|
507
|
+
}
|
|
508
|
+
if (params.name === TEAM_ACK_TOOL_NAME) {
|
|
509
|
+
if (Object.keys(args).some((key) => key !== "throughSeq") || !Number.isSafeInteger(args.throughSeq) || Number(args.throughSeq) < 0) return invalid2(id, "ack_team_messages requires non-negative integer throughSeq only");
|
|
510
|
+
return success2(id, await deps.ack({ throughSeq: Number(args.throughSeq) }));
|
|
511
|
+
}
|
|
512
|
+
return invalid2(id, "unknown team tool");
|
|
513
|
+
} catch (error) {
|
|
514
|
+
return { jsonrpc: "2.0", id, error: { code: -32e3, message: error instanceof Error ? error.message : String(error) } };
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function serveTeamMcpOverStdio(input) {
|
|
518
|
+
const reader = createInterface({ input: input.stdin ?? process.stdin, terminal: false });
|
|
519
|
+
const output = input.stdout ?? process.stdout;
|
|
520
|
+
reader.on("line", (line) => {
|
|
521
|
+
const trimmed = line.trim();
|
|
522
|
+
if (!trimmed) return;
|
|
523
|
+
void (async () => {
|
|
524
|
+
let request;
|
|
525
|
+
try {
|
|
526
|
+
request = JSON.parse(trimmed);
|
|
527
|
+
} catch {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const response = await handleTeamMcpRequest(request, input.deps);
|
|
531
|
+
if (response !== void 0) output.write(`${JSON.stringify(response)}
|
|
532
|
+
`);
|
|
533
|
+
})();
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
var APPROVAL_TOOL_NAME = "approval_prompt";
|
|
537
|
+
var APPROVAL_SUMMARY_MAX_CHARS = 500;
|
|
538
|
+
function errorMessage2(err) {
|
|
539
|
+
return err instanceof Error ? err.message : String(err);
|
|
540
|
+
}
|
|
541
|
+
function summarizeToolCall(toolName, input) {
|
|
542
|
+
let inputStr;
|
|
543
|
+
try {
|
|
544
|
+
inputStr = JSON.stringify(input);
|
|
545
|
+
} catch (err) {
|
|
546
|
+
inputStr = `<unserializable input: ${errorMessage2(err)}>`;
|
|
547
|
+
}
|
|
548
|
+
const bounded = inputStr.length > APPROVAL_SUMMARY_MAX_CHARS ? `${inputStr.slice(0, APPROVAL_SUMMARY_MAX_CHARS)}\u2026 [truncated]` : inputStr;
|
|
549
|
+
return `${toolName}: ${bounded}`;
|
|
550
|
+
}
|
|
551
|
+
async function handleMcpRequest(req, deps, taskId) {
|
|
552
|
+
const id = req.id;
|
|
553
|
+
if (req.method === "initialize") {
|
|
554
|
+
const params = req.params ?? {};
|
|
555
|
+
return {
|
|
556
|
+
jsonrpc: "2.0",
|
|
557
|
+
id,
|
|
558
|
+
result: {
|
|
559
|
+
protocolVersion: typeof params.protocolVersion === "string" ? params.protocolVersion : "2024-11-05",
|
|
560
|
+
capabilities: { tools: {} },
|
|
561
|
+
serverInfo: { name: "byok-approval-mcp", version: "0.0.1" }
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
if (req.method === "notifications/initialized") {
|
|
566
|
+
return void 0;
|
|
567
|
+
}
|
|
568
|
+
if (req.method === "tools/list") {
|
|
569
|
+
return {
|
|
570
|
+
jsonrpc: "2.0",
|
|
571
|
+
id,
|
|
572
|
+
result: {
|
|
573
|
+
tools: [
|
|
574
|
+
{
|
|
575
|
+
name: APPROVAL_TOOL_NAME,
|
|
576
|
+
description: "Requests operator approval for a pending tool call. Blocks until a human (or this device's daemon) decides, or the configured timeout elapses (fail-closed deny on timeout).",
|
|
577
|
+
inputSchema: {
|
|
578
|
+
type: "object",
|
|
579
|
+
properties: {
|
|
580
|
+
tool_name: { type: "string" },
|
|
581
|
+
input: { type: "object" }
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
]
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
if (req.method === "tools/call") {
|
|
590
|
+
const params = req.params ?? {};
|
|
591
|
+
if (params.name !== APPROVAL_TOOL_NAME) {
|
|
592
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: `unknown tool "${String(params.name)}"` } };
|
|
593
|
+
}
|
|
594
|
+
const args = params.arguments ?? {};
|
|
595
|
+
const toolName = typeof args.tool_name === "string" ? args.tool_name : "unknown tool";
|
|
596
|
+
const input = args.input ?? {};
|
|
597
|
+
const summary = summarizeToolCall(toolName, input);
|
|
598
|
+
let outcome;
|
|
599
|
+
try {
|
|
600
|
+
outcome = await deps.requestApproval(taskId, summary);
|
|
601
|
+
} catch (err) {
|
|
602
|
+
outcome = { approved: false, reason: `could not reach the approving device: ${errorMessage2(err)}` };
|
|
603
|
+
}
|
|
604
|
+
const payload = outcome.approved ? { behavior: "allow", updatedInput: input } : { behavior: "deny", message: outcome.reason ?? "denied" };
|
|
605
|
+
return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: JSON.stringify(payload) }] } };
|
|
606
|
+
}
|
|
607
|
+
if (id !== void 0) {
|
|
608
|
+
return { jsonrpc: "2.0", id, error: { code: -32601, message: `unknown method: ${String(req.method)}` } };
|
|
609
|
+
}
|
|
610
|
+
return void 0;
|
|
611
|
+
}
|
|
612
|
+
function serveApprovalMcpOverStdio(opts) {
|
|
613
|
+
const input = opts.input ?? process.stdin;
|
|
614
|
+
const output = opts.output ?? process.stdout;
|
|
615
|
+
const rl = createInterface({ input, terminal: false });
|
|
616
|
+
rl.on("line", (line) => {
|
|
617
|
+
const trimmed = line.trim();
|
|
618
|
+
if (!trimmed) return;
|
|
619
|
+
let parsed;
|
|
620
|
+
try {
|
|
621
|
+
parsed = JSON.parse(trimmed);
|
|
622
|
+
} catch {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
void handleMcpRequest(parsed, opts.deps, opts.taskId).then((response) => {
|
|
626
|
+
if (response !== void 0) output.write(`${JSON.stringify(response)}
|
|
627
|
+
`);
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
}
|
|
411
631
|
|
|
412
|
-
// src/bin/
|
|
632
|
+
// src/bin/sdk-reserved-helper-runners.ts
|
|
633
|
+
var APPROVAL_REQUEST_TIMEOUT_SLOP_MS = 5e3;
|
|
413
634
|
function required(name) {
|
|
414
635
|
const value = process.env[name];
|
|
415
636
|
if (!value) throw new Error(`missing required environment variable ${name}`);
|
|
416
637
|
return value;
|
|
417
638
|
}
|
|
418
|
-
|
|
639
|
+
function waitForInputClose(input = process.stdin) {
|
|
640
|
+
if (input.readableEnded || input.destroyed) return Promise.resolve();
|
|
641
|
+
return new Promise((resolve) => {
|
|
642
|
+
const done = () => {
|
|
643
|
+
input.off("end", done);
|
|
644
|
+
input.off("close", done);
|
|
645
|
+
resolve();
|
|
646
|
+
};
|
|
647
|
+
input.once("end", done);
|
|
648
|
+
input.once("close", done);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
async function runAgentMessageMcp() {
|
|
419
652
|
const storeDir = required("BYOK_STORE_DIR");
|
|
420
653
|
const productId = required("BYOK_PRODUCT_ID");
|
|
421
654
|
const contextToken = required("BYOK_AGENT_MESSAGE_CONTEXT");
|
|
@@ -431,8 +664,99 @@ async function main() {
|
|
|
431
664
|
publish: async (input) => (await client()).request("agent_messages.publish", { contextToken, ...input })
|
|
432
665
|
};
|
|
433
666
|
serveAgentMessageMcpOverStdio({ deps });
|
|
667
|
+
await waitForInputClose();
|
|
668
|
+
}
|
|
669
|
+
async function runAgentMemoryMcp() {
|
|
670
|
+
const storeDir = required("BYOK_STORE_DIR");
|
|
671
|
+
const productId = required("BYOK_PRODUCT_ID");
|
|
672
|
+
const contextToken = required("BYOK_AGENT_MEMORY_CONTEXT");
|
|
673
|
+
let clientPromise;
|
|
674
|
+
const client = async () => {
|
|
675
|
+
if (!clientPromise) clientPromise = connectControlClient({ storeDir, productId }).then((result) => {
|
|
676
|
+
if (!result.ok) throw new Error(result.reason);
|
|
677
|
+
return result.client;
|
|
678
|
+
});
|
|
679
|
+
return clientPromise;
|
|
680
|
+
};
|
|
681
|
+
const deps = {
|
|
682
|
+
recall: async (input) => (await client()).request("agent_memory.recall", { contextToken, ...input }),
|
|
683
|
+
save: async (input) => (await client()).request("agent_memory.save", { contextToken, ...input })
|
|
684
|
+
};
|
|
685
|
+
serveAgentMemoryMcpOverStdio({ deps });
|
|
686
|
+
await waitForInputClose();
|
|
434
687
|
}
|
|
435
|
-
|
|
688
|
+
async function runApprovalMcp() {
|
|
689
|
+
const storeDir = required("BYOK_STORE_DIR");
|
|
690
|
+
const productId = required("BYOK_PRODUCT_ID");
|
|
691
|
+
const taskId = required("BYOK_TASK_ID");
|
|
692
|
+
const timeoutMs = Number(process.env.BYOK_APPROVAL_TIMEOUT_MS ?? "600000");
|
|
693
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
694
|
+
throw new Error("invalid BYOK_APPROVAL_TIMEOUT_MS environment variable");
|
|
695
|
+
}
|
|
696
|
+
let clientPromise;
|
|
697
|
+
const client = async () => {
|
|
698
|
+
if (!clientPromise) clientPromise = connectControlClient({
|
|
699
|
+
storeDir,
|
|
700
|
+
productId,
|
|
701
|
+
requestTimeoutMs: timeoutMs + APPROVAL_REQUEST_TIMEOUT_SLOP_MS
|
|
702
|
+
}).then((result) => {
|
|
703
|
+
if (!result.ok) throw new Error(result.reason);
|
|
704
|
+
return result.client;
|
|
705
|
+
});
|
|
706
|
+
return clientPromise;
|
|
707
|
+
};
|
|
708
|
+
const deps = {
|
|
709
|
+
requestApproval: async (requestedTaskId, summary) => {
|
|
710
|
+
try {
|
|
711
|
+
return await (await client()).request("approvals.request", { taskId: requestedTaskId, summary });
|
|
712
|
+
} catch (error) {
|
|
713
|
+
clientPromise = void 0;
|
|
714
|
+
throw error;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
serveApprovalMcpOverStdio({ taskId, deps });
|
|
719
|
+
await waitForInputClose();
|
|
720
|
+
}
|
|
721
|
+
async function runAgentTeamMcp() {
|
|
722
|
+
const storeDir = required("BYOK_STORE_DIR");
|
|
723
|
+
const productId = required("BYOK_PRODUCT_ID");
|
|
724
|
+
const lease = required("BYOK_TEAM_MEMBER_CONTEXT");
|
|
725
|
+
let clientPromise;
|
|
726
|
+
const client = async () => {
|
|
727
|
+
if (!clientPromise) clientPromise = connectControlClient({ storeDir, productId }).then((result) => {
|
|
728
|
+
if (!result.ok) throw new Error(result.reason);
|
|
729
|
+
return result.client;
|
|
730
|
+
});
|
|
731
|
+
return clientPromise;
|
|
732
|
+
};
|
|
733
|
+
const deps = {
|
|
734
|
+
post: async (input) => (await client()).request("team_messages.post", { context: lease, ...input }),
|
|
735
|
+
read: async (input) => (await client()).request("team_messages.read", { context: lease, ...input }),
|
|
736
|
+
ack: async (input) => (await client()).request("team_messages.ack", { context: lease, ...input })
|
|
737
|
+
};
|
|
738
|
+
serveTeamMcpOverStdio({ deps });
|
|
739
|
+
await waitForInputClose();
|
|
740
|
+
}
|
|
741
|
+
async function runSdkReservedHelper(kind) {
|
|
742
|
+
switch (kind) {
|
|
743
|
+
case "agent-message-mcp":
|
|
744
|
+
await runAgentMessageMcp();
|
|
745
|
+
return;
|
|
746
|
+
case "agent-memory-mcp":
|
|
747
|
+
await runAgentMemoryMcp();
|
|
748
|
+
return;
|
|
749
|
+
case "approval-mcp":
|
|
750
|
+
await runApprovalMcp();
|
|
751
|
+
return;
|
|
752
|
+
case "agent-team-mcp":
|
|
753
|
+
await runAgentTeamMcp();
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/bin/byok-agent-message-mcp.ts
|
|
759
|
+
runSdkReservedHelper("agent-message-mcp").catch((error) => {
|
|
436
760
|
process.stderr.write(`byok-agent-message-mcp: ${error instanceof Error ? error.message : String(error)}
|
|
437
761
|
`);
|
|
438
762
|
process.exit(1);
|