@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
|
@@ -334,6 +334,205 @@ function createControlClient(socket, reader, opts) {
|
|
|
334
334
|
}
|
|
335
335
|
};
|
|
336
336
|
}
|
|
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";
|
|
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
|
+
}
|
|
337
536
|
var APPROVAL_TOOL_NAME = "approval_prompt";
|
|
338
537
|
var APPROVAL_SUMMARY_MAX_CHARS = 500;
|
|
339
538
|
function errorMessage2(err) {
|
|
@@ -430,67 +629,135 @@ function serveApprovalMcpOverStdio(opts) {
|
|
|
430
629
|
});
|
|
431
630
|
}
|
|
432
631
|
|
|
433
|
-
// src/bin/
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
var REQUEST_TIMEOUT_SLOP_MS = 5e3;
|
|
438
|
-
function requireEnv(name) {
|
|
632
|
+
// src/bin/sdk-reserved-helper-runners.ts
|
|
633
|
+
var APPROVAL_REQUEST_TIMEOUT_SLOP_MS = 5e3;
|
|
634
|
+
function required(name) {
|
|
439
635
|
const value = process.env[name];
|
|
440
|
-
if (!value) {
|
|
441
|
-
process.stderr.write(`byok-approval-mcp: missing required env var ${name} \u2014 refusing to start
|
|
442
|
-
`);
|
|
443
|
-
process.exit(1);
|
|
444
|
-
}
|
|
636
|
+
if (!value) throw new Error(`missing required environment variable ${name}`);
|
|
445
637
|
return value;
|
|
446
638
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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() {
|
|
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();
|
|
687
|
+
}
|
|
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");
|
|
451
692
|
const timeoutMs = Number(process.env.BYOK_APPROVAL_TIMEOUT_MS ?? "600000");
|
|
452
693
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
453
|
-
|
|
454
|
-
process.exit(1);
|
|
694
|
+
throw new Error("invalid BYOK_APPROVAL_TIMEOUT_MS environment variable");
|
|
455
695
|
}
|
|
456
696
|
let clientPromise;
|
|
457
|
-
|
|
458
|
-
if (!clientPromise) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
467
|
-
);
|
|
468
|
-
clientPromise.catch(() => {
|
|
469
|
-
clientPromise = void 0;
|
|
470
|
-
});
|
|
471
|
-
}
|
|
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
|
+
});
|
|
472
706
|
return clientPromise;
|
|
473
|
-
}
|
|
707
|
+
};
|
|
474
708
|
const deps = {
|
|
475
|
-
requestApproval: async (
|
|
476
|
-
let client;
|
|
709
|
+
requestApproval: async (requestedTaskId, summary) => {
|
|
477
710
|
try {
|
|
478
|
-
|
|
479
|
-
} catch (
|
|
480
|
-
throw new Error(`could not connect to the daemon control socket: ${errorMessage3(err)}`);
|
|
481
|
-
}
|
|
482
|
-
try {
|
|
483
|
-
return await client.request("approvals.request", { taskId: tId, summary });
|
|
484
|
-
} catch (err) {
|
|
711
|
+
return await (await client()).request("approvals.request", { taskId: requestedTaskId, summary });
|
|
712
|
+
} catch (error) {
|
|
485
713
|
clientPromise = void 0;
|
|
486
|
-
throw
|
|
714
|
+
throw error;
|
|
487
715
|
}
|
|
488
716
|
}
|
|
489
717
|
};
|
|
490
718
|
serveApprovalMcpOverStdio({ taskId, deps });
|
|
719
|
+
await waitForInputClose();
|
|
491
720
|
}
|
|
492
|
-
|
|
493
|
-
|
|
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-approval-mcp.ts
|
|
759
|
+
runSdkReservedHelper("approval-mcp").catch((error) => {
|
|
760
|
+
process.stderr.write(`byok-approval-mcp: ${error instanceof Error ? error.message : String(error)}
|
|
494
761
|
`);
|
|
495
762
|
process.exit(1);
|
|
496
763
|
});
|