@byok-sdk/client 0.10.2 → 0.11.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 +71 -3
- 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-memory/index.d.ts +1 -1
- package/dist/agent-memory/index.js +4 -4
- 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 +15889 -14610
- 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-message-mcp-preflight.d.ts +17 -0
- package/dist/daemon/control-protocol.d.ts +38 -0
- package/dist/daemon/create-daemon.d.ts +7 -0
- package/dist/daemon/mcp-tools-probe.d.ts +105 -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 +18 -1
- package/dist/daemon/team-workspace.d.ts +202 -0
- package/dist/daemon/toolset-registry.d.ts +0 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2682 -1090
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const AGENT_MEMORY_RECALL_TOOL_NAME = "
|
|
2
|
-
export declare const AGENT_MEMORY_SAVE_TOOL_NAME = "
|
|
1
|
+
export declare const AGENT_MEMORY_RECALL_TOOL_NAME = "memory_recall";
|
|
2
|
+
export declare const AGENT_MEMORY_SAVE_TOOL_NAME = "memory_save";
|
|
3
3
|
export interface AgentMemoryMcpDeps {
|
|
4
4
|
recall(input: {
|
|
5
5
|
path: string;
|
|
@@ -334,8 +334,84 @@ function createControlClient(socket, reader, opts) {
|
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
|
-
var
|
|
338
|
-
|
|
337
|
+
var AGENT_MESSAGE_TOOL_NAME = "send_agent_message";
|
|
338
|
+
|
|
339
|
+
// src/bin/agent-message-mcp-server.ts
|
|
340
|
+
async function handleAgentMessageMcpRequest(request, deps) {
|
|
341
|
+
const id = request.id;
|
|
342
|
+
if (request.method === "initialize") {
|
|
343
|
+
const params = request.params ?? {};
|
|
344
|
+
return {
|
|
345
|
+
jsonrpc: "2.0",
|
|
346
|
+
id,
|
|
347
|
+
result: {
|
|
348
|
+
protocolVersion: typeof params.protocolVersion === "string" ? params.protocolVersion : "2024-11-05",
|
|
349
|
+
capabilities: { tools: {} },
|
|
350
|
+
serverInfo: { name: "byok-agent-message-mcp", version: "0.0.1" }
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
if (request.method === "notifications/initialized") return void 0;
|
|
355
|
+
if (request.method === "tools/list") {
|
|
356
|
+
return {
|
|
357
|
+
jsonrpc: "2.0",
|
|
358
|
+
id,
|
|
359
|
+
result: { tools: [{
|
|
360
|
+
name: AGENT_MESSAGE_TOOL_NAME,
|
|
361
|
+
description: "Send the single user-visible Agent reply for this exact task. Routing identity is supplied by the authenticated task context.",
|
|
362
|
+
inputSchema: {
|
|
363
|
+
type: "object",
|
|
364
|
+
additionalProperties: false,
|
|
365
|
+
required: ["body"],
|
|
366
|
+
properties: {
|
|
367
|
+
body: { type: "string", minLength: 1 },
|
|
368
|
+
contentType: { type: "string", enum: ["text/plain", "text/markdown"] }
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}] }
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
if (request.method === "tools/call") {
|
|
375
|
+
const params = request.params ?? {};
|
|
376
|
+
if (params.name !== AGENT_MESSAGE_TOOL_NAME) return { jsonrpc: "2.0", id, error: { code: -32602, message: "unknown Agent message tool" } };
|
|
377
|
+
const args = params.arguments;
|
|
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" } };
|
|
379
|
+
const record3 = args;
|
|
380
|
+
if (Object.keys(record3).some((key) => key !== "body" && key !== "contentType") || typeof record3.body !== "string" || record3.body.length === 0) {
|
|
381
|
+
return { jsonrpc: "2.0", id, error: { code: -32602, message: "message input accepts only non-empty body and optional contentType" } };
|
|
382
|
+
}
|
|
383
|
+
const contentType = record3.contentType ?? "text/markdown";
|
|
384
|
+
if (contentType !== "text/plain" && contentType !== "text/markdown") return { jsonrpc: "2.0", id, error: { code: -32602, message: "unsupported contentType" } };
|
|
385
|
+
try {
|
|
386
|
+
const receipt = await deps.publish({ contentType, body: record3.body });
|
|
387
|
+
return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: JSON.stringify(receipt) }] } };
|
|
388
|
+
} catch (error) {
|
|
389
|
+
return { jsonrpc: "2.0", id, error: { code: -32e3, message: error instanceof Error ? error.message : String(error) } };
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return id === void 0 ? void 0 : { jsonrpc: "2.0", id, error: { code: -32601, message: `unknown method: ${String(request.method)}` } };
|
|
393
|
+
}
|
|
394
|
+
function serveAgentMessageMcpOverStdio(input) {
|
|
395
|
+
const reader = createInterface({ input: input.stdin ?? process.stdin, terminal: false });
|
|
396
|
+
const output = input.stdout ?? process.stdout;
|
|
397
|
+
reader.on("line", (line) => {
|
|
398
|
+
const trimmed = line.trim();
|
|
399
|
+
if (trimmed.length === 0) return;
|
|
400
|
+
void (async () => {
|
|
401
|
+
let request;
|
|
402
|
+
try {
|
|
403
|
+
request = JSON.parse(trimmed);
|
|
404
|
+
} catch {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const response = await handleAgentMessageMcpRequest(request, input.deps);
|
|
408
|
+
if (response !== void 0) output.write(`${JSON.stringify(response)}
|
|
409
|
+
`);
|
|
410
|
+
})();
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
var AGENT_MEMORY_RECALL_TOOL_NAME = "memory_recall";
|
|
414
|
+
var AGENT_MEMORY_SAVE_TOOL_NAME = "memory_save";
|
|
339
415
|
function record(value) {
|
|
340
416
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
341
417
|
}
|
|
@@ -366,11 +442,11 @@ async function handleAgentMemoryMcpRequest(request, deps) {
|
|
|
366
442
|
if (!params || !args || typeof params.name !== "string") return invalid(id, "memory tool input must be an object");
|
|
367
443
|
try {
|
|
368
444
|
if (params.name === AGENT_MEMORY_RECALL_TOOL_NAME) {
|
|
369
|
-
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, "
|
|
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");
|
|
370
446
|
return success(id, await deps.recall({ path: args.path, ...args.ifRevision === void 0 ? {} : { ifRevision: args.ifRevision } }));
|
|
371
447
|
}
|
|
372
448
|
if (params.name === AGENT_MEMORY_SAVE_TOOL_NAME) {
|
|
373
|
-
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, "
|
|
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");
|
|
374
450
|
const content = args.content;
|
|
375
451
|
return success(id, await deps.save({ op: args.op, path: args.path, expectedRevision: args.expectedRevision, ...typeof content === "string" ? { content } : {} }));
|
|
376
452
|
}
|
|
@@ -398,14 +474,199 @@ function serveAgentMemoryMcpOverStdio(input) {
|
|
|
398
474
|
})();
|
|
399
475
|
});
|
|
400
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
|
+
}
|
|
401
631
|
|
|
402
|
-
// src/bin/
|
|
632
|
+
// src/bin/sdk-reserved-helper-runners.ts
|
|
633
|
+
var APPROVAL_REQUEST_TIMEOUT_SLOP_MS = 5e3;
|
|
403
634
|
function required(name) {
|
|
404
635
|
const value = process.env[name];
|
|
405
636
|
if (!value) throw new Error(`missing required environment variable ${name}`);
|
|
406
637
|
return value;
|
|
407
638
|
}
|
|
408
|
-
|
|
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() {
|
|
652
|
+
const storeDir = required("BYOK_STORE_DIR");
|
|
653
|
+
const productId = required("BYOK_PRODUCT_ID");
|
|
654
|
+
const contextToken = required("BYOK_AGENT_MESSAGE_CONTEXT");
|
|
655
|
+
let clientPromise;
|
|
656
|
+
const client = async () => {
|
|
657
|
+
if (!clientPromise) clientPromise = connectControlClient({ storeDir, productId }).then((result) => {
|
|
658
|
+
if (!result.ok) throw new Error(result.reason);
|
|
659
|
+
return result.client;
|
|
660
|
+
});
|
|
661
|
+
return clientPromise;
|
|
662
|
+
};
|
|
663
|
+
const deps = {
|
|
664
|
+
publish: async (input) => (await client()).request("agent_messages.publish", { contextToken, ...input })
|
|
665
|
+
};
|
|
666
|
+
serveAgentMessageMcpOverStdio({ deps });
|
|
667
|
+
await waitForInputClose();
|
|
668
|
+
}
|
|
669
|
+
async function runAgentMemoryMcp() {
|
|
409
670
|
const storeDir = required("BYOK_STORE_DIR");
|
|
410
671
|
const productId = required("BYOK_PRODUCT_ID");
|
|
411
672
|
const contextToken = required("BYOK_AGENT_MEMORY_CONTEXT");
|
|
@@ -422,8 +683,80 @@ async function main() {
|
|
|
422
683
|
save: async (input) => (await client()).request("agent_memory.save", { contextToken, ...input })
|
|
423
684
|
};
|
|
424
685
|
serveAgentMemoryMcpOverStdio({ deps });
|
|
686
|
+
await waitForInputClose();
|
|
425
687
|
}
|
|
426
|
-
|
|
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-memory-mcp.ts
|
|
759
|
+
runSdkReservedHelper("agent-memory-mcp").catch((error) => {
|
|
427
760
|
process.stderr.write(`byok-agent-memory-mcp: ${error instanceof Error ? error.message : String(error)}
|
|
428
761
|
`);
|
|
429
762
|
process.exit(1);
|