@di-code/coding-agent 0.1.7 → 0.1.9
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 +54 -567
- package/compositions/base.yml +54 -0
- package/compositions/interactive.yml +14 -0
- package/compositions/json.yml +6 -0
- package/compositions/print.yml +5 -0
- package/compositions/rpc.yml +12 -0
- package/compositions/webui.yml +9 -0
- package/dist/cli.d.ts +22 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +97 -3
- package/dist/cli.js.map +1 -1
- package/dist/composition-loader-entry.d.ts +11 -0
- package/dist/composition-loader-entry.d.ts.map +1 -0
- package/dist/composition-loader-entry.js +12 -0
- package/dist/composition-loader-entry.js.map +1 -0
- package/dist/compositions.d.ts +32 -0
- package/dist/compositions.d.ts.map +1 -0
- package/dist/compositions.js +173 -0
- package/dist/compositions.js.map +1 -0
- package/dist/core/session/session-manager.d.ts +9 -2
- package/dist/core/session/session-manager.d.ts.map +1 -1
- package/dist/core/session/session-manager.js +28 -0
- package/dist/core/session/session-manager.js.map +1 -1
- package/dist/core/session/session-storage.d.ts.map +1 -1
- package/dist/core/session/session-storage.js +20 -3
- package/dist/core/session/session-storage.js.map +1 -1
- package/dist/core/session/types.d.ts +11 -2
- package/dist/core/session/types.d.ts.map +1 -1
- package/dist/core/session/types.js.map +1 -1
- package/dist/core/session-tools.d.ts +5 -0
- package/dist/core/session-tools.d.ts.map +1 -0
- package/dist/core/session-tools.js +17 -0
- package/dist/core/session-tools.js.map +1 -0
- package/dist/core/session.d.ts +19 -7
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +71 -39
- package/dist/core/session.js.map +1 -1
- package/dist/core/tools/bash.d.ts +1 -38
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +1 -207
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts +1 -24
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +1 -135
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts +1 -26
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -140
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +1 -23
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/file-search.d.ts +1 -13
- package/dist/core/tools/file-search.d.ts.map +1 -1
- package/dist/core/tools/file-search.js +1 -98
- package/dist/core/tools/file-search.js.map +1 -1
- package/dist/core/tools/glob.d.ts +1 -10
- package/dist/core/tools/glob.d.ts.map +1 -1
- package/dist/core/tools/glob.js +1 -43
- package/dist/core/tools/glob.js.map +1 -1
- package/dist/core/tools/grep.d.ts +1 -12
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -66
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/load-skill.d.ts +1 -9
- package/dist/core/tools/load-skill.d.ts.map +1 -1
- package/dist/core/tools/load-skill.js +1 -21
- package/dist/core/tools/load-skill.js.map +1 -1
- package/dist/core/tools/path-boundary.d.ts +1 -4
- package/dist/core/tools/path-boundary.d.ts.map +1 -1
- package/dist/core/tools/path-boundary.js +1 -65
- package/dist/core/tools/path-boundary.js.map +1 -1
- package/dist/core/tools/read.d.ts +1 -16
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -131
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts +1 -16
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -44
- package/dist/core/tools/write.js.map +1 -1
- package/dist/entry.js +30 -28
- package/dist/entry.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/interactive/builtin.d.ts +17 -0
- package/dist/interactive/builtin.d.ts.map +1 -0
- package/dist/interactive/builtin.js +47 -0
- package/dist/interactive/builtin.js.map +1 -0
- package/dist/interactive/controller.d.ts +85 -0
- package/dist/interactive/controller.d.ts.map +1 -0
- package/dist/interactive/controller.js +211 -0
- package/dist/interactive/controller.js.map +1 -0
- package/dist/interactive/index.d.ts +3 -0
- package/dist/interactive/index.d.ts.map +1 -0
- package/dist/interactive/index.js +3 -0
- package/dist/interactive/index.js.map +1 -0
- package/dist/interactive-host-entry.d.ts +7 -0
- package/dist/interactive-host-entry.d.ts.map +1 -0
- package/dist/interactive-host-entry.js +123 -0
- package/dist/interactive-host-entry.js.map +1 -0
- package/dist/interactive-profile.d.ts +18 -0
- package/dist/interactive-profile.d.ts.map +1 -0
- package/dist/interactive-profile.js +290 -0
- package/dist/interactive-profile.js.map +1 -0
- package/dist/interactive-resources-entry.d.ts +7 -0
- package/dist/interactive-resources-entry.d.ts.map +1 -0
- package/dist/interactive-resources-entry.js +42 -0
- package/dist/interactive-resources-entry.js.map +1 -0
- package/dist/legacy-main.d.ts +39 -0
- package/dist/legacy-main.d.ts.map +1 -0
- package/dist/legacy-main.js +611 -0
- package/dist/legacy-main.js.map +1 -0
- package/dist/main.d.ts +15 -34
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +130 -518
- package/dist/main.js.map +1 -1
- package/dist/mcp/entries.d.ts +42 -0
- package/dist/mcp/entries.d.ts.map +1 -0
- package/dist/mcp/entries.js +98 -0
- package/dist/mcp/entries.js.map +1 -0
- package/dist/mcp-client-entry.d.ts +5 -0
- package/dist/mcp-client-entry.d.ts.map +1 -0
- package/dist/mcp-client-entry.js +6 -0
- package/dist/mcp-client-entry.js.map +1 -0
- package/dist/mcp-config-entry.d.ts +5 -0
- package/dist/mcp-config-entry.d.ts.map +1 -0
- package/dist/mcp-config-entry.js +6 -0
- package/dist/mcp-config-entry.js.map +1 -0
- package/dist/mcp-tools-entry.d.ts +5 -0
- package/dist/mcp-tools-entry.d.ts.map +1 -0
- package/dist/mcp-tools-entry.js +6 -0
- package/dist/mcp-tools-entry.js.map +1 -0
- package/dist/mcp-transport-entry.d.ts +5 -0
- package/dist/mcp-transport-entry.d.ts.map +1 -0
- package/dist/mcp-transport-entry.js +6 -0
- package/dist/mcp-transport-entry.js.map +1 -0
- package/dist/modes/interactive-entry.d.ts +18 -0
- package/dist/modes/interactive-entry.d.ts.map +1 -0
- package/dist/modes/interactive-entry.js +21 -0
- package/dist/modes/interactive-entry.js.map +1 -0
- package/dist/modes/interactive.d.ts +16 -6
- package/dist/modes/interactive.d.ts.map +1 -1
- package/dist/modes/interactive.js +81 -32
- package/dist/modes/interactive.js.map +1 -1
- package/dist/modes/json-entry.d.ts +13 -0
- package/dist/modes/json-entry.d.ts.map +1 -0
- package/dist/modes/json-entry.js +14 -0
- package/dist/modes/json-entry.js.map +1 -0
- package/dist/modes/json.d.ts +4 -1
- package/dist/modes/json.d.ts.map +1 -1
- package/dist/modes/json.js +3 -3
- package/dist/modes/json.js.map +1 -1
- package/dist/modes/print-entry.d.ts +10 -0
- package/dist/modes/print-entry.d.ts.map +1 -0
- package/dist/modes/print-entry.js +11 -0
- package/dist/modes/print-entry.js.map +1 -0
- package/dist/modes/tree-selector.d.ts.map +1 -1
- package/dist/modes/tree-selector.js +4 -0
- package/dist/modes/tree-selector.js.map +1 -1
- package/dist/plugin-dump-composition.d.ts +6 -0
- package/dist/plugin-dump-composition.d.ts.map +1 -0
- package/dist/plugin-dump-composition.js +7 -0
- package/dist/plugin-dump-composition.js.map +1 -0
- package/dist/plugin-inventory.d.ts +7 -0
- package/dist/plugin-inventory.d.ts.map +1 -0
- package/dist/plugin-inventory.js +8 -0
- package/dist/plugin-inventory.js.map +1 -0
- package/dist/plugin-manager.d.ts +6 -0
- package/dist/plugin-manager.d.ts.map +1 -0
- package/dist/plugin-manager.js +7 -0
- package/dist/plugin-manager.js.map +1 -0
- package/dist/plugin-trace.d.ts +6 -0
- package/dist/plugin-trace.d.ts.map +1 -0
- package/dist/plugin-trace.js +7 -0
- package/dist/plugin-trace.js.map +1 -0
- package/dist/plugins/dynamic-broker.d.ts +76 -0
- package/dist/plugins/dynamic-broker.d.ts.map +1 -0
- package/dist/plugins/dynamic-broker.js +852 -0
- package/dist/plugins/dynamic-broker.js.map +1 -0
- package/dist/plugins/profile.d.ts +15 -0
- package/dist/plugins/profile.d.ts.map +1 -0
- package/dist/plugins/profile.js +34 -0
- package/dist/plugins/profile.js.map +1 -0
- package/dist/plugins/runtime-host.d.ts +37 -0
- package/dist/plugins/runtime-host.d.ts.map +1 -0
- package/dist/plugins/runtime-host.js +95 -0
- package/dist/plugins/runtime-host.js.map +1 -0
- package/dist/plugins/trust.d.ts +8 -0
- package/dist/plugins/trust.d.ts.map +1 -0
- package/dist/plugins/trust.js +59 -0
- package/dist/plugins/trust.js.map +1 -0
- package/dist/project-trust-entry.d.ts +15 -0
- package/dist/project-trust-entry.d.ts.map +1 -0
- package/dist/project-trust-entry.js +15 -0
- package/dist/project-trust-entry.js.map +1 -0
- package/dist/rpc/client.d.ts +78 -6
- package/dist/rpc/client.d.ts.map +1 -1
- package/dist/rpc/client.js +172 -4
- package/dist/rpc/client.js.map +1 -1
- package/dist/rpc/dispatcher.d.ts +121 -0
- package/dist/rpc/dispatcher.d.ts.map +1 -0
- package/dist/rpc/dispatcher.js +994 -0
- package/dist/rpc/dispatcher.js.map +1 -0
- package/dist/rpc/index.d.ts +2 -0
- package/dist/rpc/index.d.ts.map +1 -1
- package/dist/rpc/index.js +2 -0
- package/dist/rpc/index.js.map +1 -1
- package/dist/rpc/lifecycle.d.ts +6 -0
- package/dist/rpc/lifecycle.d.ts.map +1 -0
- package/dist/rpc/lifecycle.js +24 -0
- package/dist/rpc/lifecycle.js.map +1 -0
- package/dist/rpc/protocol.d.ts +112 -31
- package/dist/rpc/protocol.d.ts.map +1 -1
- package/dist/rpc/protocol.js +569 -117
- package/dist/rpc/protocol.js.map +1 -1
- package/dist/rpc/server-service.d.ts +7 -0
- package/dist/rpc/server-service.d.ts.map +1 -0
- package/dist/rpc/server-service.js +3 -0
- package/dist/rpc/server-service.js.map +1 -0
- package/dist/rpc/server.d.ts +16 -19
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +59 -115
- package/dist/rpc/server.js.map +1 -1
- package/dist/rpc-client-sdk-entry.d.ts +12 -0
- package/dist/rpc-client-sdk-entry.d.ts.map +1 -0
- package/dist/rpc-client-sdk-entry.js +11 -0
- package/dist/rpc-client-sdk-entry.js.map +1 -0
- package/dist/rpc-entry.js +50 -18
- package/dist/rpc-entry.js.map +1 -1
- package/dist/rpc-server-entry.d.ts +8 -0
- package/dist/rpc-server-entry.d.ts.map +1 -0
- package/dist/rpc-server-entry.js +67 -0
- package/dist/rpc-server-entry.js.map +1 -0
- package/dist/runtime/attachment-store.d.ts +13 -0
- package/dist/runtime/attachment-store.d.ts.map +1 -0
- package/dist/runtime/attachment-store.js +93 -0
- package/dist/runtime/attachment-store.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +14 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +29 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/interactive-host-service.d.ts +22 -0
- package/dist/runtime/interactive-host-service.d.ts.map +1 -0
- package/dist/runtime/interactive-host-service.js +2 -0
- package/dist/runtime/interactive-host-service.js.map +1 -0
- package/dist/runtime/interactive-resource-service.d.ts +11 -0
- package/dist/runtime/interactive-resource-service.d.ts.map +1 -0
- package/dist/runtime/interactive-resource-service.js +3 -0
- package/dist/runtime/interactive-resource-service.js.map +1 -0
- package/dist/runtime/plugin-inventory-entry.d.ts +5 -0
- package/dist/runtime/plugin-inventory-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-inventory-entry.js +18 -0
- package/dist/runtime/plugin-inventory-entry.js.map +1 -0
- package/dist/runtime/plugin-inventory-service.d.ts +8 -0
- package/dist/runtime/plugin-inventory-service.d.ts.map +1 -0
- package/dist/runtime/plugin-inventory-service.js +3 -0
- package/dist/runtime/plugin-inventory-service.js.map +1 -0
- package/dist/runtime/plugin-manager-entry.d.ts +20 -0
- package/dist/runtime/plugin-manager-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-manager-entry.js +96 -0
- package/dist/runtime/plugin-manager-entry.js.map +1 -0
- package/dist/runtime/plugin-observability-entry.d.ts +12 -0
- package/dist/runtime/plugin-observability-entry.d.ts.map +1 -0
- package/dist/runtime/plugin-observability-entry.js +73 -0
- package/dist/runtime/plugin-observability-entry.js.map +1 -0
- package/dist/runtime/product-host.d.ts +91 -0
- package/dist/runtime/product-host.d.ts.map +1 -0
- package/dist/runtime/product-host.js +529 -0
- package/dist/runtime/product-host.js.map +1 -0
- package/dist/runtime/session-factory.d.ts +17 -0
- package/dist/runtime/session-factory.d.ts.map +1 -0
- package/dist/runtime/session-factory.js +75 -0
- package/dist/runtime/session-factory.js.map +1 -0
- package/dist/runtime/session-host.d.ts +152 -0
- package/dist/runtime/session-host.d.ts.map +1 -0
- package/dist/runtime/session-host.js +895 -0
- package/dist/runtime/session-host.js.map +1 -0
- package/dist/runtime-core-entry.d.ts +11 -0
- package/dist/runtime-core-entry.d.ts.map +1 -0
- package/dist/runtime-core-entry.js +9 -0
- package/dist/runtime-core-entry.js.map +1 -0
- package/dist/session-factory-entry.d.ts +7 -0
- package/dist/session-factory-entry.d.ts.map +1 -0
- package/dist/session-factory-entry.js +9 -0
- package/dist/session-factory-entry.js.map +1 -0
- package/dist/session-store-jsonl-entry.d.ts +7 -0
- package/dist/session-store-jsonl-entry.d.ts.map +1 -0
- package/dist/session-store-jsonl-entry.js +33 -0
- package/dist/session-store-jsonl-entry.js.map +1 -0
- package/dist/startup.d.ts +12 -1
- package/dist/startup.d.ts.map +1 -1
- package/dist/startup.js +106 -15
- package/dist/startup.js.map +1 -1
- package/dist/subagents/index.d.ts +2 -0
- package/dist/subagents/index.d.ts.map +1 -0
- package/dist/subagents/index.js +2 -0
- package/dist/subagents/index.js.map +1 -0
- package/dist/subagents/service.d.ts +50 -0
- package/dist/subagents/service.d.ts.map +1 -0
- package/dist/subagents/service.js +521 -0
- package/dist/subagents/service.js.map +1 -0
- package/dist/ui-host.d.ts +125 -0
- package/dist/ui-host.d.ts.map +1 -0
- package/dist/ui-host.js +275 -0
- package/dist/ui-host.js.map +1 -0
- package/dist/web/assets/index-BwfuGMvv.css +1 -0
- package/dist/web/assets/index-DPUaJqFJ.js +41 -0
- package/dist/web/assets/index-DPUaJqFJ.js.map +1 -0
- package/dist/web/index.html +14 -0
- package/dist/web-command.d.ts +11 -0
- package/dist/web-command.d.ts.map +1 -0
- package/dist/web-command.js +114 -0
- package/dist/web-command.js.map +1 -0
- package/dist/web-frontend.d.ts +73 -0
- package/dist/web-frontend.d.ts.map +1 -0
- package/dist/web-frontend.js +249 -0
- package/dist/web-frontend.js.map +1 -0
- package/dist/web.d.ts +254 -0
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +740 -0
- package/dist/web.js.map +1 -0
- package/dist/webui-entry.d.ts +3 -0
- package/dist/webui-entry.d.ts.map +1 -0
- package/dist/webui-entry.js +73 -0
- package/dist/webui-entry.js.map +1 -0
- package/dist/webui.d.ts +91 -0
- package/dist/webui.d.ts.map +1 -0
- package/dist/webui.js +882 -0
- package/dist/webui.js.map +1 -0
- package/package.json +89 -8
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
const DEFAULT_MAX_DEPTH = 2;
|
|
3
|
+
const DEFAULT_MAX_CONCURRENT = 4;
|
|
4
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
5
|
+
const DEFAULT_MAX_RESULT_BYTES = 32 * 1024;
|
|
6
|
+
// Keep recent terminal results available to the wait tool after active runs are reclaimed.
|
|
7
|
+
const TERMINAL_RESULT_CACHE_SIZE = 128;
|
|
8
|
+
function errorMessage(cause) {
|
|
9
|
+
return redactCredentials(cause instanceof Error ? cause.message : String(cause)).slice(0, 1_000);
|
|
10
|
+
}
|
|
11
|
+
function boundedText(value, maxBytes) {
|
|
12
|
+
const bytes = Buffer.from(value, "utf8");
|
|
13
|
+
if (bytes.byteLength <= maxBytes)
|
|
14
|
+
return value;
|
|
15
|
+
const marker = Buffer.from("\n[truncated]", "utf8");
|
|
16
|
+
if (maxBytes <= marker.byteLength) {
|
|
17
|
+
for (let end = Math.min(maxBytes, bytes.byteLength); end >= 0; end--) {
|
|
18
|
+
const prefix = bytes.subarray(0, end).toString("utf8");
|
|
19
|
+
if (Buffer.byteLength(prefix, "utf8") <= maxBytes)
|
|
20
|
+
return prefix;
|
|
21
|
+
}
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
for (let end = Math.min(maxBytes - marker.byteLength, bytes.byteLength); end >= 0; end--) {
|
|
25
|
+
const prefix = bytes.subarray(0, end).toString("utf8");
|
|
26
|
+
if (Buffer.byteLength(prefix, "utf8") + marker.byteLength <= maxBytes)
|
|
27
|
+
return `${prefix}\n[truncated]`;
|
|
28
|
+
}
|
|
29
|
+
return "\n[truncated]";
|
|
30
|
+
}
|
|
31
|
+
function redactCredentials(value) {
|
|
32
|
+
return value
|
|
33
|
+
.replace(/(\b(?:api[_-]?key|token|secret|authorization|password)\b\s*[=:]\s*(?:Bearer\s+)?)[^\s,;}\]]+/gi, "$1[redacted]")
|
|
34
|
+
.replace(/\bBearer\s+[A-Za-z0-9._~+/=-]+/gi, "Bearer [redacted]");
|
|
35
|
+
}
|
|
36
|
+
function waitWithSignal(promise, signal, message) {
|
|
37
|
+
if (!signal)
|
|
38
|
+
return promise;
|
|
39
|
+
if (signal.aborted)
|
|
40
|
+
return Promise.reject(new Error(message));
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
43
|
+
const onAbort = () => {
|
|
44
|
+
cleanup();
|
|
45
|
+
reject(new Error(message));
|
|
46
|
+
};
|
|
47
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
48
|
+
void promise.then((value) => {
|
|
49
|
+
cleanup();
|
|
50
|
+
resolve(value);
|
|
51
|
+
}, (cause) => {
|
|
52
|
+
cleanup();
|
|
53
|
+
reject(cause);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function isTerminalStatus(status) {
|
|
58
|
+
return status === "completed" || status === "failed" || status === "cancelled";
|
|
59
|
+
}
|
|
60
|
+
class InProcessRun {
|
|
61
|
+
_status = "running";
|
|
62
|
+
abortController = new AbortController();
|
|
63
|
+
session;
|
|
64
|
+
resultPromise;
|
|
65
|
+
resolveResult;
|
|
66
|
+
id;
|
|
67
|
+
parentSessionId;
|
|
68
|
+
providerId = "in-process";
|
|
69
|
+
constructor(id, request, session, maxResultBytes) {
|
|
70
|
+
this.id = id;
|
|
71
|
+
this.parentSessionId = request.parentSessionId;
|
|
72
|
+
this.sessionPrompt = request.prompt;
|
|
73
|
+
this.maxResultBytes = maxResultBytes;
|
|
74
|
+
this.session = session;
|
|
75
|
+
this.resultPromise = new Promise((resolve) => {
|
|
76
|
+
this.resolveResult = resolve;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
begin() {
|
|
80
|
+
void this.run(this.sessionPrompt, this.maxResultBytes);
|
|
81
|
+
}
|
|
82
|
+
sessionPrompt;
|
|
83
|
+
maxResultBytes;
|
|
84
|
+
get status() {
|
|
85
|
+
return this._status;
|
|
86
|
+
}
|
|
87
|
+
wait(signal) {
|
|
88
|
+
return waitWithSignal(this.resultPromise, signal, "Subagent wait was cancelled.");
|
|
89
|
+
}
|
|
90
|
+
async sendMessage(input, signal) {
|
|
91
|
+
if (this._status !== "running")
|
|
92
|
+
throw new Error(`Subagent "${this.id}" is ${this._status}.`);
|
|
93
|
+
if (!input.text.trim())
|
|
94
|
+
throw new Error("send_message.message must be non-empty");
|
|
95
|
+
if (signal?.aborted)
|
|
96
|
+
throw new Error("Subagent message was cancelled.");
|
|
97
|
+
await this.session.steer(input.text, signal);
|
|
98
|
+
}
|
|
99
|
+
async cancel() {
|
|
100
|
+
if (this._status !== "running")
|
|
101
|
+
return;
|
|
102
|
+
this.abortController.abort();
|
|
103
|
+
this._status = "cancelled";
|
|
104
|
+
this.resolveResult({ id: this.id, status: "cancelled", text: "" });
|
|
105
|
+
}
|
|
106
|
+
async run(prompt, maxResultBytes) {
|
|
107
|
+
try {
|
|
108
|
+
const result = await this.session.prompt(prompt, this.abortController.signal);
|
|
109
|
+
if (this._status !== "running")
|
|
110
|
+
return;
|
|
111
|
+
this._status =
|
|
112
|
+
result.stopReason === "aborted" ? "cancelled" : result.stopReason === "error" ? "failed" : "completed";
|
|
113
|
+
const text = redactCredentials(result.content
|
|
114
|
+
.filter((content) => content.type === "text")
|
|
115
|
+
.map((content) => content.text)
|
|
116
|
+
.join(""));
|
|
117
|
+
const final = {
|
|
118
|
+
id: this.id,
|
|
119
|
+
status: this._status,
|
|
120
|
+
text: boundedText(text, maxResultBytes),
|
|
121
|
+
...(result.errorMessage ? { errorMessage: errorMessage(result.errorMessage) } : {}),
|
|
122
|
+
};
|
|
123
|
+
this.resolveResult(final);
|
|
124
|
+
}
|
|
125
|
+
catch (cause) {
|
|
126
|
+
if (this._status !== "running")
|
|
127
|
+
return;
|
|
128
|
+
this._status = this.abortController.signal.aborted ? "cancelled" : "failed";
|
|
129
|
+
const final = { id: this.id, status: this._status, text: "", errorMessage: errorMessage(cause) };
|
|
130
|
+
this.resolveResult(final);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Normalizes plugin provider lifecycle so a provider cannot leave the host waiting forever. */
|
|
135
|
+
class ManagedRun {
|
|
136
|
+
_status = "running";
|
|
137
|
+
resultPromise;
|
|
138
|
+
resolveResult;
|
|
139
|
+
timeout;
|
|
140
|
+
id;
|
|
141
|
+
parentSessionId;
|
|
142
|
+
providerId;
|
|
143
|
+
inner;
|
|
144
|
+
constructor(inner, timeoutMs, maxResultBytes) {
|
|
145
|
+
this.inner = inner;
|
|
146
|
+
this.id = inner.id;
|
|
147
|
+
this.parentSessionId = inner.parentSessionId;
|
|
148
|
+
this.providerId = inner.providerId;
|
|
149
|
+
this.resultPromise = new Promise((resolve) => {
|
|
150
|
+
this.resolveResult = resolve;
|
|
151
|
+
});
|
|
152
|
+
this.timeout = setTimeout(() => void this.finishCancelled(), timeoutMs);
|
|
153
|
+
void this.observe(maxResultBytes);
|
|
154
|
+
}
|
|
155
|
+
get status() {
|
|
156
|
+
return this._status;
|
|
157
|
+
}
|
|
158
|
+
wait(signal) {
|
|
159
|
+
return waitWithSignal(this.resultPromise, signal, "Subagent wait was cancelled.");
|
|
160
|
+
}
|
|
161
|
+
sendMessage(input, signal) {
|
|
162
|
+
if (!input.text.trim())
|
|
163
|
+
return Promise.reject(new Error("send_message.message must be non-empty"));
|
|
164
|
+
if (signal?.aborted)
|
|
165
|
+
return Promise.reject(new Error("Subagent message was cancelled."));
|
|
166
|
+
return this.inner.sendMessage(input, signal);
|
|
167
|
+
}
|
|
168
|
+
async cancel() {
|
|
169
|
+
if (this._status !== "running")
|
|
170
|
+
return;
|
|
171
|
+
await this.finishCancelled();
|
|
172
|
+
}
|
|
173
|
+
async observe(maxResultBytes) {
|
|
174
|
+
try {
|
|
175
|
+
const result = await this.inner.wait();
|
|
176
|
+
if (this._status !== "running")
|
|
177
|
+
return;
|
|
178
|
+
if (result.id !== this.id ||
|
|
179
|
+
!isTerminalStatus(result.status) ||
|
|
180
|
+
typeof result.text !== "string" ||
|
|
181
|
+
(result.errorMessage !== undefined && typeof result.errorMessage !== "string"))
|
|
182
|
+
throw new Error("Subagent provider returned an invalid result.");
|
|
183
|
+
this._status = result.status;
|
|
184
|
+
this.resolveResult({
|
|
185
|
+
...result,
|
|
186
|
+
text: boundedText(redactCredentials(result.text), maxResultBytes),
|
|
187
|
+
...(result.errorMessage === undefined ? {} : { errorMessage: errorMessage(result.errorMessage) }),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (cause) {
|
|
191
|
+
if (this._status !== "running")
|
|
192
|
+
return;
|
|
193
|
+
this._status = "failed";
|
|
194
|
+
this.resolveResult({ id: this.id, status: "failed", text: "", errorMessage: errorMessage(cause) });
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
clearTimeout(this.timeout);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async finishCancelled() {
|
|
201
|
+
if (this._status !== "running")
|
|
202
|
+
return;
|
|
203
|
+
this._status = "cancelled";
|
|
204
|
+
this.resolveResult({ id: this.id, status: "cancelled", text: "" });
|
|
205
|
+
clearTimeout(this.timeout);
|
|
206
|
+
void this.inner.cancel().catch(() => undefined);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export class SubagentService {
|
|
210
|
+
config;
|
|
211
|
+
options;
|
|
212
|
+
providers;
|
|
213
|
+
runs = new Map();
|
|
214
|
+
terminalResults = new Map();
|
|
215
|
+
activeCount = 0;
|
|
216
|
+
constructor(options) {
|
|
217
|
+
if (!options.parentSessionId.trim())
|
|
218
|
+
throw new Error("parentSessionId must be non-empty");
|
|
219
|
+
this.options = {
|
|
220
|
+
maxDepth: options.maxDepth ?? DEFAULT_MAX_DEPTH,
|
|
221
|
+
maxConcurrent: options.maxConcurrent ?? DEFAULT_MAX_CONCURRENT,
|
|
222
|
+
defaultTimeoutMs: options.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
223
|
+
maxResultBytes: options.maxResultBytes ?? DEFAULT_MAX_RESULT_BYTES,
|
|
224
|
+
};
|
|
225
|
+
if (!Number.isInteger(this.options.maxDepth) || this.options.maxDepth < 0)
|
|
226
|
+
throw new RangeError("maxDepth must be a non-negative integer");
|
|
227
|
+
if (!Number.isInteger(this.options.maxConcurrent) || this.options.maxConcurrent < 1)
|
|
228
|
+
throw new RangeError("maxConcurrent must be positive");
|
|
229
|
+
if (!Number.isInteger(this.options.defaultTimeoutMs) || this.options.defaultTimeoutMs < 1)
|
|
230
|
+
throw new RangeError("defaultTimeoutMs must be positive");
|
|
231
|
+
if (!Number.isInteger(this.options.maxResultBytes) || this.options.maxResultBytes < 1)
|
|
232
|
+
throw new RangeError("maxResultBytes must be positive");
|
|
233
|
+
const providerEntries = new Map();
|
|
234
|
+
for (const provider of options.providers ?? []) {
|
|
235
|
+
if (!provider.id.trim())
|
|
236
|
+
throw new Error("subagent provider id must be non-empty");
|
|
237
|
+
if (providerEntries.has(provider.id))
|
|
238
|
+
throw new Error(`Duplicate subagent provider "${provider.id}".`);
|
|
239
|
+
providerEntries.set(provider.id, provider);
|
|
240
|
+
}
|
|
241
|
+
this.providers = providerEntries;
|
|
242
|
+
this.config = options;
|
|
243
|
+
}
|
|
244
|
+
list() {
|
|
245
|
+
return [...this.runs.values()];
|
|
246
|
+
}
|
|
247
|
+
rememberTerminalResult(result) {
|
|
248
|
+
this.terminalResults.delete(result.id);
|
|
249
|
+
this.terminalResults.set(result.id, result);
|
|
250
|
+
if (this.terminalResults.size <= TERMINAL_RESULT_CACHE_SIZE)
|
|
251
|
+
return;
|
|
252
|
+
const oldestId = this.terminalResults.keys().next().value;
|
|
253
|
+
if (oldestId !== undefined)
|
|
254
|
+
this.terminalResults.delete(oldestId);
|
|
255
|
+
}
|
|
256
|
+
completeRun(run, result) {
|
|
257
|
+
if (this.runs.get(run.id) !== run)
|
|
258
|
+
return;
|
|
259
|
+
this.runs.delete(run.id);
|
|
260
|
+
this.activeCount--;
|
|
261
|
+
this.rememberTerminalResult(result);
|
|
262
|
+
}
|
|
263
|
+
async start(input, signal) {
|
|
264
|
+
const depth = input.depth ?? (this.config.currentDepth ?? 0) + 1;
|
|
265
|
+
if (!input.prompt.trim())
|
|
266
|
+
throw new Error("subagent.prompt must be non-empty");
|
|
267
|
+
if (!Number.isInteger(depth) || depth < 0 || depth > this.options.maxDepth)
|
|
268
|
+
throw new Error(`Subagent depth must be between 0 and ${this.options.maxDepth}.`);
|
|
269
|
+
if (this.activeCount >= this.options.maxConcurrent)
|
|
270
|
+
throw new Error("Subagent concurrency limit reached.");
|
|
271
|
+
if (input.providerId !== undefined && !this.providers.has(input.providerId))
|
|
272
|
+
throw new Error(`Unknown subagent provider "${input.providerId}".`);
|
|
273
|
+
if (signal?.aborted)
|
|
274
|
+
throw new Error("Subagent start was cancelled.");
|
|
275
|
+
const id = randomUUID();
|
|
276
|
+
const request = {
|
|
277
|
+
parentSessionId: this.config.parentSessionId,
|
|
278
|
+
cwd: this.config.cwd,
|
|
279
|
+
model: { id: this.config.model.id, provider: this.config.model.provider },
|
|
280
|
+
prompt: input.prompt,
|
|
281
|
+
toolNames: [...(this.config.toolNames ?? [])],
|
|
282
|
+
pluginIds: [...(this.config.pluginIds ?? [])],
|
|
283
|
+
depth,
|
|
284
|
+
maxDepth: this.options.maxDepth,
|
|
285
|
+
timeoutMs: this.options.defaultTimeoutMs,
|
|
286
|
+
maxResultBytes: this.options.maxResultBytes,
|
|
287
|
+
};
|
|
288
|
+
this.activeCount++;
|
|
289
|
+
const custom = input.providerId ? this.providers.get(input.providerId) : undefined;
|
|
290
|
+
let run;
|
|
291
|
+
let inProcess;
|
|
292
|
+
try {
|
|
293
|
+
if (custom) {
|
|
294
|
+
const providerRun = await custom.start(request, signal);
|
|
295
|
+
if (!providerRun ||
|
|
296
|
+
typeof providerRun.id !== "string" ||
|
|
297
|
+
!providerRun.id.trim() ||
|
|
298
|
+
typeof providerRun.providerId !== "string" ||
|
|
299
|
+
providerRun.providerId !== custom.id ||
|
|
300
|
+
typeof providerRun.parentSessionId !== "string" ||
|
|
301
|
+
providerRun.parentSessionId !== request.parentSessionId ||
|
|
302
|
+
providerRun.status !== "running" ||
|
|
303
|
+
typeof providerRun.wait !== "function" ||
|
|
304
|
+
typeof providerRun.cancel !== "function" ||
|
|
305
|
+
typeof providerRun.sendMessage !== "function") {
|
|
306
|
+
if (providerRun && typeof providerRun.cancel === "function")
|
|
307
|
+
await providerRun.cancel().catch(() => undefined);
|
|
308
|
+
throw new Error(`Subagent provider "${custom.id}" returned an invalid running instance.`);
|
|
309
|
+
}
|
|
310
|
+
run = new ManagedRun(providerRun, this.options.defaultTimeoutMs, this.options.maxResultBytes);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
inProcess = new InProcessRun(id, request, this.config.createSession(request), this.options.maxResultBytes);
|
|
314
|
+
run = inProcess;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (cause) {
|
|
318
|
+
this.activeCount--;
|
|
319
|
+
throw cause;
|
|
320
|
+
}
|
|
321
|
+
if (!run ||
|
|
322
|
+
typeof run.id !== "string" ||
|
|
323
|
+
typeof run.providerId !== "string" ||
|
|
324
|
+
typeof run.parentSessionId !== "string" ||
|
|
325
|
+
typeof run.wait !== "function" ||
|
|
326
|
+
typeof run.cancel !== "function" ||
|
|
327
|
+
typeof run.sendMessage !== "function") {
|
|
328
|
+
this.activeCount--;
|
|
329
|
+
throw new Error("Subagent provider returned an invalid run.");
|
|
330
|
+
}
|
|
331
|
+
if (run.parentSessionId !== request.parentSessionId) {
|
|
332
|
+
this.activeCount--;
|
|
333
|
+
await run.cancel();
|
|
334
|
+
throw new Error(`Subagent provider "${run.providerId}" returned a run for a different parent Session.`);
|
|
335
|
+
}
|
|
336
|
+
if (!run.id.trim() || !run.providerId.trim()) {
|
|
337
|
+
this.activeCount--;
|
|
338
|
+
await run.cancel();
|
|
339
|
+
throw new Error(`Subagent provider "${run.providerId}" returned invalid run identifiers.`);
|
|
340
|
+
}
|
|
341
|
+
if (signal?.aborted) {
|
|
342
|
+
this.activeCount--;
|
|
343
|
+
await run.cancel();
|
|
344
|
+
throw new Error("Subagent start was cancelled.");
|
|
345
|
+
}
|
|
346
|
+
if (this.runs.has(run.id)) {
|
|
347
|
+
this.activeCount--;
|
|
348
|
+
await run.cancel();
|
|
349
|
+
throw new Error(`Subagent run id "${run.id}" is already in use.`);
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
await this.config.emit?.({
|
|
353
|
+
type: "subagent_start",
|
|
354
|
+
runId: run.id,
|
|
355
|
+
parentSessionId: request.parentSessionId,
|
|
356
|
+
status: run.status,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
catch (cause) {
|
|
360
|
+
this.activeCount--;
|
|
361
|
+
await run.cancel();
|
|
362
|
+
throw cause;
|
|
363
|
+
}
|
|
364
|
+
this.runs.set(run.id, run);
|
|
365
|
+
this.terminalResults.delete(run.id);
|
|
366
|
+
inProcess?.begin();
|
|
367
|
+
const abortListener = signal ? () => void run.cancel() : undefined;
|
|
368
|
+
if (signal && abortListener)
|
|
369
|
+
signal.addEventListener("abort", abortListener, { once: true });
|
|
370
|
+
const timeout = setTimeout(() => void run.cancel(), this.options.defaultTimeoutMs);
|
|
371
|
+
void run
|
|
372
|
+
.wait()
|
|
373
|
+
.then((result) => {
|
|
374
|
+
this.completeRun(run, result);
|
|
375
|
+
return this.config.emit?.({
|
|
376
|
+
type: "subagent_end",
|
|
377
|
+
runId: run.id,
|
|
378
|
+
parentSessionId: request.parentSessionId,
|
|
379
|
+
status: result.status,
|
|
380
|
+
text: result.text,
|
|
381
|
+
...(result.errorMessage ? { errorMessage: result.errorMessage } : {}),
|
|
382
|
+
});
|
|
383
|
+
}, () => {
|
|
384
|
+
if (this.runs.get(run.id) === run) {
|
|
385
|
+
this.runs.delete(run.id);
|
|
386
|
+
this.activeCount--;
|
|
387
|
+
}
|
|
388
|
+
})
|
|
389
|
+
.catch(() => undefined)
|
|
390
|
+
.finally(() => {
|
|
391
|
+
clearTimeout(timeout);
|
|
392
|
+
if (signal && abortListener)
|
|
393
|
+
signal.removeEventListener("abort", abortListener);
|
|
394
|
+
});
|
|
395
|
+
return run;
|
|
396
|
+
}
|
|
397
|
+
get(id) {
|
|
398
|
+
const run = this.runs.get(id);
|
|
399
|
+
if (!run)
|
|
400
|
+
throw new Error(`Unknown subagent "${id}".`);
|
|
401
|
+
return run;
|
|
402
|
+
}
|
|
403
|
+
async interrupt(id) {
|
|
404
|
+
const run = this.runs.get(id);
|
|
405
|
+
if (run) {
|
|
406
|
+
await run.cancel();
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
if (this.terminalResults.has(id))
|
|
410
|
+
return;
|
|
411
|
+
throw new Error(`Unknown subagent "${id}".`);
|
|
412
|
+
}
|
|
413
|
+
async dispose() {
|
|
414
|
+
const runs = [...this.runs.values()];
|
|
415
|
+
await Promise.all(runs.map((run) => run.cancel()));
|
|
416
|
+
await Promise.all(runs.map((run) => run.wait().catch(() => undefined)));
|
|
417
|
+
this.terminalResults.clear();
|
|
418
|
+
}
|
|
419
|
+
createTools() {
|
|
420
|
+
const text = (value) => [{ type: "text", text: value }];
|
|
421
|
+
return [
|
|
422
|
+
{
|
|
423
|
+
name: "subagent",
|
|
424
|
+
description: "Start a bounded child Agent and return its run id.",
|
|
425
|
+
parameters: {
|
|
426
|
+
type: "object",
|
|
427
|
+
required: ["prompt"],
|
|
428
|
+
properties: {
|
|
429
|
+
prompt: { type: "string" },
|
|
430
|
+
depth: { type: "integer" },
|
|
431
|
+
providerId: { type: "string" },
|
|
432
|
+
},
|
|
433
|
+
additionalProperties: false,
|
|
434
|
+
},
|
|
435
|
+
execute: async (_id, args, signal) => {
|
|
436
|
+
const value = args;
|
|
437
|
+
if (typeof value.prompt !== "string")
|
|
438
|
+
throw new Error("subagent.prompt must be a string");
|
|
439
|
+
if (value.depth !== undefined && (!Number.isInteger(value.depth) || typeof value.depth !== "number"))
|
|
440
|
+
throw new Error("subagent.depth must be an integer");
|
|
441
|
+
if (value.providerId !== undefined && typeof value.providerId !== "string")
|
|
442
|
+
throw new Error("subagent.providerId must be a string");
|
|
443
|
+
const run = await this.start({
|
|
444
|
+
prompt: value.prompt,
|
|
445
|
+
depth: value.depth,
|
|
446
|
+
providerId: value.providerId,
|
|
447
|
+
}, signal);
|
|
448
|
+
return text(JSON.stringify({ id: run.id, status: run.status }));
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "subagent_list",
|
|
453
|
+
description: "List child Agent runs owned by this Session.",
|
|
454
|
+
parameters: { type: "object", properties: {}, additionalProperties: false },
|
|
455
|
+
execute: async () => text(JSON.stringify(this.list().map((run) => ({ id: run.id, status: run.status })))),
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: "send_message",
|
|
459
|
+
description: "Send a message to a running child Agent.",
|
|
460
|
+
parameters: {
|
|
461
|
+
type: "object",
|
|
462
|
+
properties: { id: { type: "string" }, message: { type: "string" } },
|
|
463
|
+
required: ["id", "message"],
|
|
464
|
+
additionalProperties: false,
|
|
465
|
+
},
|
|
466
|
+
execute: async (_id, args, signal) => {
|
|
467
|
+
const value = args;
|
|
468
|
+
if (typeof value.id !== "string" || value.id.trim() === "")
|
|
469
|
+
throw new Error("send_message.id must be non-empty");
|
|
470
|
+
if (typeof value.message !== "string")
|
|
471
|
+
throw new Error("send_message.message must be a string");
|
|
472
|
+
await this.get(value.id).sendMessage({ text: value.message }, signal);
|
|
473
|
+
return text("Message sent.");
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: "wait",
|
|
478
|
+
description: "Wait for a child Agent and return its bounded result.",
|
|
479
|
+
parameters: {
|
|
480
|
+
type: "object",
|
|
481
|
+
properties: { id: { type: "string" } },
|
|
482
|
+
required: ["id"],
|
|
483
|
+
additionalProperties: false,
|
|
484
|
+
},
|
|
485
|
+
execute: async (_id, args, signal) => {
|
|
486
|
+
const id = args.id;
|
|
487
|
+
if (typeof id !== "string" || id.trim() === "")
|
|
488
|
+
throw new Error("wait.id must be non-empty");
|
|
489
|
+
const activeRun = this.runs.get(id);
|
|
490
|
+
const result = activeRun ? await activeRun.wait(signal) : this.terminalResults.get(id);
|
|
491
|
+
if (!result)
|
|
492
|
+
throw new Error(`Unknown subagent "${id}".`);
|
|
493
|
+
return text(JSON.stringify({
|
|
494
|
+
id: result.id,
|
|
495
|
+
status: result.status,
|
|
496
|
+
text: result.text,
|
|
497
|
+
...(result.errorMessage === undefined ? {} : { errorMessage: result.errorMessage }),
|
|
498
|
+
}));
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
name: "interrupt",
|
|
503
|
+
description: "Cancel a running child Agent.",
|
|
504
|
+
parameters: {
|
|
505
|
+
type: "object",
|
|
506
|
+
properties: { id: { type: "string" } },
|
|
507
|
+
required: ["id"],
|
|
508
|
+
additionalProperties: false,
|
|
509
|
+
},
|
|
510
|
+
execute: async (_id, args) => {
|
|
511
|
+
const id = args.id;
|
|
512
|
+
if (typeof id !== "string" || id.trim() === "")
|
|
513
|
+
throw new Error("interrupt.id must be non-empty");
|
|
514
|
+
await this.interrupt(id);
|
|
515
|
+
return text("Interrupt requested.");
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
];
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/subagents/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAuCzC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC3C,2FAA2F;AAC3F,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,iBAAiB,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAClG,CAAC;AAED,SAAS,WAAW,CAAC,KAAa,E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;wBAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;oBAClG,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;oBACzB,OAAO,IAAI,CAAC,sBAAsB,CAAC,CAAC;gBACrC,CAAC;aACD;SAC4D,CAAC;IAChE,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentTool, AgentToolResult } from \"@di-code/agent\";\nimport type { Model, Provider, TSchema } from \"@di-code/ai\";\nimport type {\n\tSubagentInput,\n\tSubagentProvider,\n\tSubagentResult,\n\tSubagentRun,\n\tSubagentStartRequest,\n\tSubagentStatus,\n} from \"@di-code/plugin-runtime\";\nimport type { AgentSession } from \"../core/session.ts\";\n\nexport interface SubagentEvent {\n\treadonly type: \"subagent_start\" | \"subagent_update\" | \"subagent_end\";\n\treadonly runId: string;\n\treadonly parentSessionId: string;\n\treadonly status: SubagentStatus;\n\treadonly text?: string;\n\treadonly errorMessage?: string;\n}\n\nexport interface SubagentServiceOptions {\n\treadonly parentSessionId: string;\n\treadonly cwd: string;\n\treadonly provider: Provider;\n\treadonly model: Model;\n\treadonly createSession: (request: SubagentStartRequest) => AgentSession;\n\treadonly providers?: readonly SubagentProvider[];\n\treadonly maxDepth?: number;\n\treadonly maxConcurrent?: number;\n\treadonly defaultTimeoutMs?: number;\n\treadonly maxResultBytes?: number;\n\treadonly currentDepth?: number;\n\treadonly toolNames?: readonly string[];\n\treadonly pluginIds?: readonly string[];\n\treadonly emit?: (event: SubagentEvent) => void | Promise<void>;\n}\n\nconst DEFAULT_MAX_DEPTH = 2;\nconst DEFAULT_MAX_CONCURRENT = 4;\nconst DEFAULT_TIMEOUT_MS = 120_000;\nconst DEFAULT_MAX_RESULT_BYTES = 32 * 1024;\n// Keep recent terminal results available to the wait tool after active runs are reclaimed.\nconst TERMINAL_RESULT_CACHE_SIZE = 128;\n\nfunction errorMessage(cause: unknown): string {\n\treturn redactCredentials(cause instanceof Error ? cause.message : String(cause)).slice(0, 1_000);\n}\n\nfunction boundedText(value: string, maxBytes: number): string {\n\tconst bytes = Buffer.from(value, \"utf8\");\n\tif (bytes.byteLength <= maxBytes) return value;\n\tconst marker = Buffer.from(\"\\n[truncated]\", \"utf8\");\n\tif (maxBytes <= marker.byteLength) {\n\t\tfor (let end = Math.min(maxBytes, bytes.byteLength); end >= 0; end--) {\n\t\t\tconst prefix = bytes.subarray(0, end).toString(\"utf8\");\n\t\t\tif (Buffer.byteLength(prefix, \"utf8\") <= maxBytes) return prefix;\n\t\t}\n\t\treturn \"\";\n\t}\n\tfor (let end = Math.min(maxBytes - marker.byteLength, bytes.byteLength); end >= 0; end--) {\n\t\tconst prefix = bytes.subarray(0, end).toString(\"utf8\");\n\t\tif (Buffer.byteLength(prefix, \"utf8\") + marker.byteLength <= maxBytes) return `${prefix}\\n[truncated]`;\n\t}\n\treturn \"\\n[truncated]\";\n}\n\nfunction redactCredentials(value: string): string {\n\treturn value\n\t\t.replace(\n\t\t\t/(\\b(?:api[_-]?key|token|secret|authorization|password)\\b\\s*[=:]\\s*(?:Bearer\\s+)?)[^\\s,;}\\]]+/gi,\n\t\t\t\"$1[redacted]\",\n\t\t)\n\t\t.replace(/\\bBearer\\s+[A-Za-z0-9._~+/=-]+/gi, \"Bearer [redacted]\");\n}\n\nfunction waitWithSignal<T>(promise: Promise<T>, signal: AbortSignal | undefined, message: string): Promise<T> {\n\tif (!signal) return promise;\n\tif (signal.aborted) return Promise.reject(new Error(message));\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst cleanup = (): void => signal.removeEventListener(\"abort\", onAbort);\n\t\tconst onAbort = (): void => {\n\t\t\tcleanup();\n\t\t\treject(new Error(message));\n\t\t};\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid promise.then(\n\t\t\t(value) => {\n\t\t\t\tcleanup();\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(cause) => {\n\t\t\t\tcleanup();\n\t\t\t\treject(cause);\n\t\t\t},\n\t\t);\n\t});\n}\n\nfunction isTerminalStatus(status: SubagentStatus): status is Exclude<SubagentStatus, \"running\"> {\n\treturn status === \"completed\" || status === \"failed\" || status === \"cancelled\";\n}\n\nclass InProcessRun implements SubagentRun {\n\tprivate _status: SubagentStatus = \"running\";\n\tprivate readonly abortController = new AbortController();\n\tprivate readonly session: AgentSession;\n\tprivate readonly resultPromise: Promise<SubagentResult>;\n\tprivate resolveResult!: (result: SubagentResult) => void;\n\treadonly id: string;\n\treadonly parentSessionId: string;\n\treadonly providerId = \"in-process\";\n\n\tconstructor(id: string, request: SubagentStartRequest, session: AgentSession, maxResultBytes: number) {\n\t\tthis.id = id;\n\t\tthis.parentSessionId = request.parentSessionId;\n\t\tthis.sessionPrompt = request.prompt;\n\t\tthis.maxResultBytes = maxResultBytes;\n\t\tthis.session = session;\n\t\tthis.resultPromise = new Promise<SubagentResult>((resolve) => {\n\t\t\tthis.resolveResult = resolve;\n\t\t});\n\t}\n\n\tbegin(): void {\n\t\tvoid this.run(this.sessionPrompt, this.maxResultBytes);\n\t}\n\n\tprivate readonly sessionPrompt: string;\n\tprivate readonly maxResultBytes: number;\n\n\tget status(): SubagentStatus {\n\t\treturn this._status;\n\t}\n\n\twait(signal?: AbortSignal): Promise<SubagentResult> {\n\t\treturn waitWithSignal(this.resultPromise, signal, \"Subagent wait was cancelled.\");\n\t}\n\n\tasync sendMessage(input: SubagentInput, signal?: AbortSignal): Promise<void> {\n\t\tif (this._status !== \"running\") throw new Error(`Subagent \"${this.id}\" is ${this._status}.`);\n\t\tif (!input.text.trim()) throw new Error(\"send_message.message must be non-empty\");\n\t\tif (signal?.aborted) throw new Error(\"Subagent message was cancelled.\");\n\t\tawait this.session.steer(input.text, signal);\n\t}\n\n\tasync cancel(): Promise<void> {\n\t\tif (this._status !== \"running\") return;\n\t\tthis.abortController.abort();\n\t\tthis._status = \"cancelled\";\n\t\tthis.resolveResult({ id: this.id, status: \"cancelled\", text: \"\" });\n\t}\n\n\tprivate async run(prompt: string, maxResultBytes: number): Promise<void> {\n\t\ttry {\n\t\t\tconst result = await this.session.prompt(prompt, this.abortController.signal);\n\t\t\tif (this._status !== \"running\") return;\n\t\t\tthis._status =\n\t\t\t\tresult.stopReason === \"aborted\" ? \"cancelled\" : result.stopReason === \"error\" ? \"failed\" : \"completed\";\n\t\t\tconst text = redactCredentials(\n\t\t\t\tresult.content\n\t\t\t\t\t.filter((content) => content.type === \"text\")\n\t\t\t\t\t.map((content) => content.text)\n\t\t\t\t\t.join(\"\"),\n\t\t\t);\n\t\t\tconst final: SubagentResult = {\n\t\t\t\tid: this.id,\n\t\t\t\tstatus: this._status,\n\t\t\t\ttext: boundedText(text, maxResultBytes),\n\t\t\t\t...(result.errorMessage ? { errorMessage: errorMessage(result.errorMessage) } : {}),\n\t\t\t};\n\t\t\tthis.resolveResult(final);\n\t\t} catch (cause) {\n\t\t\tif (this._status !== \"running\") return;\n\t\t\tthis._status = this.abortController.signal.aborted ? \"cancelled\" : \"failed\";\n\t\t\tconst final: SubagentResult = { id: this.id, status: this._status, text: \"\", errorMessage: errorMessage(cause) };\n\t\t\tthis.resolveResult(final);\n\t\t}\n\t}\n}\n\n/** Normalizes plugin provider lifecycle so a provider cannot leave the host waiting forever. */\nclass ManagedRun implements SubagentRun {\n\tprivate _status: SubagentStatus = \"running\";\n\tprivate readonly resultPromise: Promise<SubagentResult>;\n\tprivate resolveResult!: (result: SubagentResult) => void;\n\tprivate readonly timeout: ReturnType<typeof setTimeout>;\n\treadonly id: string;\n\treadonly parentSessionId: string;\n\treadonly providerId: string;\n\tprivate readonly inner: SubagentRun;\n\n\tconstructor(inner: SubagentRun, timeoutMs: number, maxResultBytes: number) {\n\t\tthis.inner = inner;\n\t\tthis.id = inner.id;\n\t\tthis.parentSessionId = inner.parentSessionId;\n\t\tthis.providerId = inner.providerId;\n\t\tthis.resultPromise = new Promise((resolve) => {\n\t\t\tthis.resolveResult = resolve;\n\t\t});\n\t\tthis.timeout = setTimeout(() => void this.finishCancelled(), timeoutMs);\n\t\tvoid this.observe(maxResultBytes);\n\t}\n\n\tget status(): SubagentStatus {\n\t\treturn this._status;\n\t}\n\n\twait(signal?: AbortSignal): Promise<SubagentResult> {\n\t\treturn waitWithSignal(this.resultPromise, signal, \"Subagent wait was cancelled.\");\n\t}\n\n\tsendMessage(input: SubagentInput, signal?: AbortSignal): Promise<void> {\n\t\tif (!input.text.trim()) return Promise.reject(new Error(\"send_message.message must be non-empty\"));\n\t\tif (signal?.aborted) return Promise.reject(new Error(\"Subagent message was cancelled.\"));\n\t\treturn this.inner.sendMessage(input, signal);\n\t}\n\n\tasync cancel(): Promise<void> {\n\t\tif (this._status !== \"running\") return;\n\t\tawait this.finishCancelled();\n\t}\n\n\tprivate async observe(maxResultBytes: number): Promise<void> {\n\t\ttry {\n\t\t\tconst result = await this.inner.wait();\n\t\t\tif (this._status !== \"running\") return;\n\t\t\tif (\n\t\t\t\tresult.id !== this.id ||\n\t\t\t\t!isTerminalStatus(result.status) ||\n\t\t\t\ttypeof result.text !== \"string\" ||\n\t\t\t\t(result.errorMessage !== undefined && typeof result.errorMessage !== \"string\")\n\t\t\t)\n\t\t\t\tthrow new Error(\"Subagent provider returned an invalid result.\");\n\t\t\tthis._status = result.status;\n\t\t\tthis.resolveResult({\n\t\t\t\t...result,\n\t\t\t\ttext: boundedText(redactCredentials(result.text), maxResultBytes),\n\t\t\t\t...(result.errorMessage === undefined ? {} : { errorMessage: errorMessage(result.errorMessage) }),\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\tif (this._status !== \"running\") return;\n\t\t\tthis._status = \"failed\";\n\t\t\tthis.resolveResult({ id: this.id, status: \"failed\", text: \"\", errorMessage: errorMessage(cause) });\n\t\t} finally {\n\t\t\tclearTimeout(this.timeout);\n\t\t}\n\t}\n\n\tprivate async finishCancelled(): Promise<void> {\n\t\tif (this._status !== \"running\") return;\n\t\tthis._status = \"cancelled\";\n\t\tthis.resolveResult({ id: this.id, status: \"cancelled\", text: \"\" });\n\t\tclearTimeout(this.timeout);\n\t\tvoid this.inner.cancel().catch(() => undefined);\n\t}\n}\n\nexport class SubagentService {\n\tprivate readonly config: SubagentServiceOptions;\n\tprivate readonly options: Required<\n\t\tPick<SubagentServiceOptions, \"maxDepth\" | \"maxConcurrent\" | \"defaultTimeoutMs\" | \"maxResultBytes\">\n\t>;\n\tprivate readonly providers: ReadonlyMap<string, SubagentProvider>;\n\tprivate readonly runs = new Map<string, SubagentRun>();\n\tprivate readonly terminalResults = new Map<string, SubagentResult>();\n\tprivate activeCount = 0;\n\n\tconstructor(options: SubagentServiceOptions) {\n\t\tif (!options.parentSessionId.trim()) throw new Error(\"parentSessionId must be non-empty\");\n\t\tthis.options = {\n\t\t\tmaxDepth: options.maxDepth ?? DEFAULT_MAX_DEPTH,\n\t\t\tmaxConcurrent: options.maxConcurrent ?? DEFAULT_MAX_CONCURRENT,\n\t\t\tdefaultTimeoutMs: options.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS,\n\t\t\tmaxResultBytes: options.maxResultBytes ?? DEFAULT_MAX_RESULT_BYTES,\n\t\t};\n\t\tif (!Number.isInteger(this.options.maxDepth) || this.options.maxDepth < 0)\n\t\t\tthrow new RangeError(\"maxDepth must be a non-negative integer\");\n\t\tif (!Number.isInteger(this.options.maxConcurrent) || this.options.maxConcurrent < 1)\n\t\t\tthrow new RangeError(\"maxConcurrent must be positive\");\n\t\tif (!Number.isInteger(this.options.defaultTimeoutMs) || this.options.defaultTimeoutMs < 1)\n\t\t\tthrow new RangeError(\"defaultTimeoutMs must be positive\");\n\t\tif (!Number.isInteger(this.options.maxResultBytes) || this.options.maxResultBytes < 1)\n\t\t\tthrow new RangeError(\"maxResultBytes must be positive\");\n\t\tconst providerEntries = new Map<string, SubagentProvider>();\n\t\tfor (const provider of options.providers ?? []) {\n\t\t\tif (!provider.id.trim()) throw new Error(\"subagent provider id must be non-empty\");\n\t\t\tif (providerEntries.has(provider.id)) throw new Error(`Duplicate subagent provider \"${provider.id}\".`);\n\t\t\tproviderEntries.set(provider.id, provider);\n\t\t}\n\t\tthis.providers = providerEntries;\n\t\tthis.config = options;\n\t}\n\n\tlist(): readonly SubagentRun[] {\n\t\treturn [...this.runs.values()];\n\t}\n\n\tprivate rememberTerminalResult(result: SubagentResult): void {\n\t\tthis.terminalResults.delete(result.id);\n\t\tthis.terminalResults.set(result.id, result);\n\t\tif (this.terminalResults.size <= TERMINAL_RESULT_CACHE_SIZE) return;\n\t\tconst oldestId = this.terminalResults.keys().next().value;\n\t\tif (oldestId !== undefined) this.terminalResults.delete(oldestId);\n\t}\n\n\tprivate completeRun(run: SubagentRun, result: SubagentResult): void {\n\t\tif (this.runs.get(run.id) !== run) return;\n\t\tthis.runs.delete(run.id);\n\t\tthis.activeCount--;\n\t\tthis.rememberTerminalResult(result);\n\t}\n\n\tasync start(\n\t\tinput: {\n\t\t\treadonly prompt: string;\n\t\t\treadonly depth?: number;\n\t\t\treadonly providerId?: string;\n\t\t},\n\t\tsignal?: AbortSignal,\n\t): Promise<SubagentRun> {\n\t\tconst depth = input.depth ?? (this.config.currentDepth ?? 0) + 1;\n\t\tif (!input.prompt.trim()) throw new Error(\"subagent.prompt must be non-empty\");\n\t\tif (!Number.isInteger(depth) || depth < 0 || depth > this.options.maxDepth)\n\t\t\tthrow new Error(`Subagent depth must be between 0 and ${this.options.maxDepth}.`);\n\t\tif (this.activeCount >= this.options.maxConcurrent) throw new Error(\"Subagent concurrency limit reached.\");\n\t\tif (input.providerId !== undefined && !this.providers.has(input.providerId))\n\t\t\tthrow new Error(`Unknown subagent provider \"${input.providerId}\".`);\n\t\tif (signal?.aborted) throw new Error(\"Subagent start was cancelled.\");\n\t\tconst id = randomUUID();\n\t\tconst request: SubagentStartRequest = {\n\t\t\tparentSessionId: this.config.parentSessionId,\n\t\t\tcwd: this.config.cwd,\n\t\t\tmodel: { id: this.config.model.id, provider: this.config.model.provider },\n\t\t\tprompt: input.prompt,\n\t\t\ttoolNames: [...(this.config.toolNames ?? [])],\n\t\t\tpluginIds: [...(this.config.pluginIds ?? [])],\n\t\t\tdepth,\n\t\t\tmaxDepth: this.options.maxDepth,\n\t\t\ttimeoutMs: this.options.defaultTimeoutMs,\n\t\t\tmaxResultBytes: this.options.maxResultBytes,\n\t\t};\n\t\tthis.activeCount++;\n\t\tconst custom = input.providerId ? this.providers.get(input.providerId) : undefined;\n\t\tlet run: SubagentRun;\n\t\tlet inProcess: InProcessRun | undefined;\n\t\ttry {\n\t\t\tif (custom) {\n\t\t\t\tconst providerRun = await custom.start(request, signal);\n\t\t\t\tif (\n\t\t\t\t\t!providerRun ||\n\t\t\t\t\ttypeof providerRun.id !== \"string\" ||\n\t\t\t\t\t!providerRun.id.trim() ||\n\t\t\t\t\ttypeof providerRun.providerId !== \"string\" ||\n\t\t\t\t\tproviderRun.providerId !== custom.id ||\n\t\t\t\t\ttypeof providerRun.parentSessionId !== \"string\" ||\n\t\t\t\t\tproviderRun.parentSessionId !== request.parentSessionId ||\n\t\t\t\t\tproviderRun.status !== \"running\" ||\n\t\t\t\t\ttypeof providerRun.wait !== \"function\" ||\n\t\t\t\t\ttypeof providerRun.cancel !== \"function\" ||\n\t\t\t\t\ttypeof providerRun.sendMessage !== \"function\"\n\t\t\t\t) {\n\t\t\t\t\tif (providerRun && typeof providerRun.cancel === \"function\")\n\t\t\t\t\t\tawait providerRun.cancel().catch(() => undefined);\n\t\t\t\t\tthrow new Error(`Subagent provider \"${custom.id}\" returned an invalid running instance.`);\n\t\t\t\t}\n\t\t\t\trun = new ManagedRun(providerRun, this.options.defaultTimeoutMs, this.options.maxResultBytes);\n\t\t\t} else {\n\t\t\t\tinProcess = new InProcessRun(id, request, this.config.createSession(request), this.options.maxResultBytes);\n\t\t\t\trun = inProcess;\n\t\t\t}\n\t\t} catch (cause) {\n\t\t\tthis.activeCount--;\n\t\t\tthrow cause;\n\t\t}\n\t\tif (\n\t\t\t!run ||\n\t\t\ttypeof run.id !== \"string\" ||\n\t\t\ttypeof run.providerId !== \"string\" ||\n\t\t\ttypeof run.parentSessionId !== \"string\" ||\n\t\t\ttypeof run.wait !== \"function\" ||\n\t\t\ttypeof run.cancel !== \"function\" ||\n\t\t\ttypeof run.sendMessage !== \"function\"\n\t\t) {\n\t\t\tthis.activeCount--;\n\t\t\tthrow new Error(\"Subagent provider returned an invalid run.\");\n\t\t}\n\t\tif (run.parentSessionId !== request.parentSessionId) {\n\t\t\tthis.activeCount--;\n\t\t\tawait run.cancel();\n\t\t\tthrow new Error(`Subagent provider \"${run.providerId}\" returned a run for a different parent Session.`);\n\t\t}\n\t\tif (!run.id.trim() || !run.providerId.trim()) {\n\t\t\tthis.activeCount--;\n\t\t\tawait run.cancel();\n\t\t\tthrow new Error(`Subagent provider \"${run.providerId}\" returned invalid run identifiers.`);\n\t\t}\n\t\tif (signal?.aborted) {\n\t\t\tthis.activeCount--;\n\t\t\tawait run.cancel();\n\t\t\tthrow new Error(\"Subagent start was cancelled.\");\n\t\t}\n\t\tif (this.runs.has(run.id)) {\n\t\t\tthis.activeCount--;\n\t\t\tawait run.cancel();\n\t\t\tthrow new Error(`Subagent run id \"${run.id}\" is already in use.`);\n\t\t}\n\t\ttry {\n\t\t\tawait this.config.emit?.({\n\t\t\t\ttype: \"subagent_start\",\n\t\t\t\trunId: run.id,\n\t\t\t\tparentSessionId: request.parentSessionId,\n\t\t\t\tstatus: run.status,\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\tthis.activeCount--;\n\t\t\tawait run.cancel();\n\t\t\tthrow cause;\n\t\t}\n\t\tthis.runs.set(run.id, run);\n\t\tthis.terminalResults.delete(run.id);\n\t\tinProcess?.begin();\n\t\tconst abortListener = signal ? () => void run.cancel() : undefined;\n\t\tif (signal && abortListener) signal.addEventListener(\"abort\", abortListener, { once: true });\n\t\tconst timeout = setTimeout(() => void run.cancel(), this.options.defaultTimeoutMs);\n\t\tvoid run\n\t\t\t.wait()\n\t\t\t.then(\n\t\t\t\t(result) => {\n\t\t\t\t\tthis.completeRun(run, result);\n\t\t\t\t\treturn this.config.emit?.({\n\t\t\t\t\t\ttype: \"subagent_end\",\n\t\t\t\t\t\trunId: run.id,\n\t\t\t\t\t\tparentSessionId: request.parentSessionId,\n\t\t\t\t\t\tstatus: result.status,\n\t\t\t\t\t\ttext: result.text,\n\t\t\t\t\t\t...(result.errorMessage ? { errorMessage: result.errorMessage } : {}),\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tif (this.runs.get(run.id) === run) {\n\t\t\t\t\t\tthis.runs.delete(run.id);\n\t\t\t\t\t\tthis.activeCount--;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t)\n\t\t\t.catch(() => undefined)\n\t\t\t.finally(() => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tif (signal && abortListener) signal.removeEventListener(\"abort\", abortListener);\n\t\t\t});\n\t\treturn run;\n\t}\n\n\tget(id: string): SubagentRun {\n\t\tconst run = this.runs.get(id);\n\t\tif (!run) throw new Error(`Unknown subagent \"${id}\".`);\n\t\treturn run;\n\t}\n\n\tasync interrupt(id: string): Promise<void> {\n\t\tconst run = this.runs.get(id);\n\t\tif (run) {\n\t\t\tawait run.cancel();\n\t\t\treturn;\n\t\t}\n\t\tif (this.terminalResults.has(id)) return;\n\t\tthrow new Error(`Unknown subagent \"${id}\".`);\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tconst runs = [...this.runs.values()];\n\t\tawait Promise.all(runs.map((run) => run.cancel()));\n\t\tawait Promise.all(runs.map((run) => run.wait().catch(() => undefined)));\n\t\tthis.terminalResults.clear();\n\t}\n\n\tcreateTools(): readonly AgentTool<TSchema, AgentToolResult>[] {\n\t\tconst text = (value: string): AgentToolResult => [{ type: \"text\", text: value }];\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: \"subagent\",\n\t\t\t\tdescription: \"Start a bounded child Agent and return its run id.\",\n\t\t\t\tparameters: {\n\t\t\t\t\ttype: \"object\",\n\t\t\t\t\trequired: [\"prompt\"],\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tprompt: { type: \"string\" },\n\t\t\t\t\t\tdepth: { type: \"integer\" },\n\t\t\t\t\t\tproviderId: { type: \"string\" },\n\t\t\t\t\t},\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t},\n\t\t\t\texecute: async (_id: string, args: Record<string, unknown>, signal?: AbortSignal) => {\n\t\t\t\t\tconst value = args as { prompt?: unknown; depth?: unknown; providerId?: unknown };\n\t\t\t\t\tif (typeof value.prompt !== \"string\") throw new Error(\"subagent.prompt must be a string\");\n\t\t\t\t\tif (value.depth !== undefined && (!Number.isInteger(value.depth) || typeof value.depth !== \"number\"))\n\t\t\t\t\t\tthrow new Error(\"subagent.depth must be an integer\");\n\t\t\t\t\tif (value.providerId !== undefined && typeof value.providerId !== \"string\")\n\t\t\t\t\t\tthrow new Error(\"subagent.providerId must be a string\");\n\t\t\t\t\tconst run = await this.start(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tprompt: value.prompt,\n\t\t\t\t\t\t\tdepth: value.depth as number | undefined,\n\t\t\t\t\t\t\tproviderId: value.providerId as string | undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t);\n\t\t\t\t\treturn text(JSON.stringify({ id: run.id, status: run.status }));\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"subagent_list\",\n\t\t\t\tdescription: \"List child Agent runs owned by this Session.\",\n\t\t\t\tparameters: { type: \"object\", properties: {}, additionalProperties: false },\n\t\t\t\texecute: async () => text(JSON.stringify(this.list().map((run) => ({ id: run.id, status: run.status })))),\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"send_message\",\n\t\t\t\tdescription: \"Send a message to a running child Agent.\",\n\t\t\t\tparameters: {\n\t\t\t\t\ttype: \"object\",\n\t\t\t\t\tproperties: { id: { type: \"string\" }, message: { type: \"string\" } },\n\t\t\t\t\trequired: [\"id\", \"message\"],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t},\n\t\t\t\texecute: async (_id: string, args: Record<string, unknown>, signal?: AbortSignal) => {\n\t\t\t\t\tconst value = args as { id?: unknown; message?: unknown };\n\t\t\t\t\tif (typeof value.id !== \"string\" || value.id.trim() === \"\")\n\t\t\t\t\t\tthrow new Error(\"send_message.id must be non-empty\");\n\t\t\t\t\tif (typeof value.message !== \"string\") throw new Error(\"send_message.message must be a string\");\n\t\t\t\t\tawait this.get(value.id).sendMessage({ text: value.message }, signal);\n\t\t\t\t\treturn text(\"Message sent.\");\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"wait\",\n\t\t\t\tdescription: \"Wait for a child Agent and return its bounded result.\",\n\t\t\t\tparameters: {\n\t\t\t\t\ttype: \"object\",\n\t\t\t\t\tproperties: { id: { type: \"string\" } },\n\t\t\t\t\trequired: [\"id\"],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t},\n\t\t\t\texecute: async (_id: string, args: Record<string, unknown>, signal?: AbortSignal) => {\n\t\t\t\t\tconst id = (args as { id?: unknown }).id;\n\t\t\t\t\tif (typeof id !== \"string\" || id.trim() === \"\") throw new Error(\"wait.id must be non-empty\");\n\t\t\t\t\tconst activeRun = this.runs.get(id);\n\t\t\t\t\tconst result = activeRun ? await activeRun.wait(signal) : this.terminalResults.get(id);\n\t\t\t\t\tif (!result) throw new Error(`Unknown subagent \"${id}\".`);\n\t\t\t\t\treturn text(\n\t\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\tstatus: result.status,\n\t\t\t\t\t\t\ttext: result.text,\n\t\t\t\t\t\t\t...(result.errorMessage === undefined ? {} : { errorMessage: result.errorMessage }),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: \"interrupt\",\n\t\t\t\tdescription: \"Cancel a running child Agent.\",\n\t\t\t\tparameters: {\n\t\t\t\t\ttype: \"object\",\n\t\t\t\t\tproperties: { id: { type: \"string\" } },\n\t\t\t\t\trequired: [\"id\"],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t},\n\t\t\t\texecute: async (_id: string, args: Record<string, unknown>) => {\n\t\t\t\t\tconst id = (args as { id?: unknown }).id;\n\t\t\t\t\tif (typeof id !== \"string\" || id.trim() === \"\") throw new Error(\"interrupt.id must be non-empty\");\n\t\t\t\t\tawait this.interrupt(id);\n\t\t\t\t\treturn text(\"Interrupt requested.\");\n\t\t\t\t},\n\t\t\t},\n\t\t] as unknown as readonly AgentTool<TSchema, AgentToolResult>[];\n\t}\n}\n"]}
|