@desplega.ai/agent-swarm 1.136.0 → 1.138.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 +12 -3
- package/dist/acp-adapter-6nttxe2q.js +4787 -0
- package/dist/{actions-agcbc8nd.js → actions-z9dzgh3f.js} +7 -8
- package/dist/{app-g2s78xya.js → app-wb6bc7tt.js} +4 -5
- package/dist/{assistant-yd3jkb9d.js → assistant-08pd6pgy.js} +9 -10
- package/dist/{boot-reembed-6spqw4q0.js → boot-reembed-hstr4e2c.js} +4 -4
- package/dist/{boot-reembed-b22s9w5x.js → boot-reembed-y7p7qjbf.js} +5 -5
- package/dist/{boot-scrub-logs-6h3cqkc0.js → boot-scrub-logs-azbnxwhn.js} +3 -3
- package/dist/{claude-adapter-ng5y8zd7.js → claude-adapter-rwaq6eda.js} +10 -9
- package/dist/{claude-managed-adapter-5zr3n86v.js → claude-managed-adapter-vtseey1x.js} +3 -3
- package/dist/{cli-qckgdqmr.js → cli-005yr57a.js} +2 -2
- package/dist/{cli-54ht104h.js → cli-0cka8dnm.js} +3 -3
- package/dist/{cli-gpdtxzar.js → cli-23cpnqk9.js} +1 -1
- package/dist/{cli-qhfkxrpg.js → cli-2ypjdmqg.js} +223 -474
- package/dist/{cli-bnq8h7ea.js → cli-3719ggyf.js} +17 -10
- package/dist/cli-390sgxn5.js +257 -0
- package/dist/{cli-z6e8eqrm.js → cli-47esr8ht.js} +2 -2
- package/dist/{cli-jjhnma34.js → cli-4jaj24py.js} +248 -101
- package/dist/{cli-6gwgzdgw.js → cli-69377c2a.js} +5 -5
- package/dist/{cli-ads0hfw2.js → cli-6v4d8r8c.js} +205 -75
- package/dist/{cli-mgef08pc.js → cli-8rtyss6g.js} +1 -1
- package/dist/{cli-35jknh9e.js → cli-9w7vsmbm.js} +5 -5
- package/dist/{cli-m3z53bed.js → cli-b4zdc3x6.js} +1 -1
- package/dist/{cli-fpjmcbhz.js → cli-ba87cw29.js} +4 -4
- package/dist/{cli-4gzv54ss.js → cli-bzk75kdc.js} +43 -11
- package/dist/{cli-d5ygfv18.js → cli-cywkhzqs.js} +35 -11
- package/dist/{cli-0crn5kaz.js → cli-d62cd9qs.js} +16 -4
- package/dist/{cli-5bnz1t86.js → cli-f9skf1v7.js} +51 -7
- package/dist/{cli-06ghj6pe.js → cli-fytpjraz.js} +4 -4
- package/dist/{cli-j7qp8gtf.js → cli-h7c5dam1.js} +16 -11
- package/dist/{cli-4r4jkqep.js → cli-kkn46gfr.js} +9 -3
- package/dist/{cli-tmn19cdz.js → cli-kq9htgbr.js} +415 -62
- package/dist/{cli-8v57p983.js → cli-pkmqqxp8.js} +45 -69
- package/dist/{cli-84vrhesc.js → cli-qf34ej1d.js} +1 -1
- package/dist/{cli-v3qda694.js → cli-rnyttbh0.js} +0 -5
- package/dist/cli-rx5cxzn2.js +7 -0
- package/dist/{cli-cw70hymf.js → cli-s25avqg9.js} +2 -0
- package/dist/{cli-tee8w7tq.js → cli-s6t1qv67.js} +15 -10
- package/dist/{cli-68vayryq.js → cli-tb4csb08.js} +2 -2
- package/dist/{cli-y16cesaq.js → cli-vy48y9bx.js} +2 -2
- package/dist/{cli-3y553gws.js → cli-y294regh.js} +1 -1
- package/dist/{cli-spf767vc.js → cli-y43043ws.js} +1 -1
- package/dist/{cli-hz5hp6wn.js → cli-yh2eybyt.js} +1 -1
- package/dist/{cli-edwrx42s.js → cli-zmyxt25p.js} +5 -5
- package/dist/cli.js +40 -18
- package/dist/{codex-adapter-kw11ps3j.js → codex-adapter-yzep6mvb.js} +7 -6
- package/dist/{codex-session-runner-sffb69v7.js → codex-session-runner-25e8tn72.js} +7 -6
- package/dist/{commands-0xxp4tz8.js → commands-0vv72d6a.js} +3 -3
- package/dist/{db-0npp39zd.js → db-x61ncfa1.js} +19 -3
- package/dist/{google-generative-ai-6xxdj4t3.js → google-generative-ai-zyhy3dab.js} +1 -1
- package/dist/{google-vertex-zma18wb0.js → google-vertex-t25h65yd.js} +1 -1
- package/dist/{handlers-5p7a1jx6.js → handlers-fwdcaahf.js} +9 -10
- package/dist/{hook-jjpxn4se.js → hook-mpwfgynm.js} +6 -5
- package/dist/{hook-hpefr0a8.js → hook-x18504ja.js} +8 -7
- package/dist/{http-wfp33653.js → http-83m6qdds.js} +590 -192
- package/dist/{index-pe58mf1r.js → index-1nsdwvn5.js} +2 -1
- package/dist/{index-17h657rg.js → index-38f98ck3.js} +9 -9
- package/dist/{index-m2p7ctyh.js → index-7kxvtd38.js} +24 -12
- package/dist/{index-racb4wfq.js → index-a4naswjn.js} +23 -10
- package/dist/{index-p13cfsc2.js → index-agykc6k2.js} +2 -1
- package/dist/{index-zh66wm65.js → index-dawtzfhw.js} +22 -9
- package/dist/{keepalive-wxjd633a.js → keepalive-y0m8g5wn.js} +5 -5
- package/dist/{lead-359ec2z0.js → lead-ka18ef6a.js} +36 -36
- package/dist/{maintenance-rr03qjtb.js → maintenance-x585p56c.js} +5 -5
- package/dist/{oauth-refresh-sweep-jwj22yb8.js → oauth-refresh-sweep-kdm9vj7a.js} +4 -4
- package/dist/{onboard-asnhchcv.js → onboard-5v229nvt.js} +664 -248
- package/dist/{opencode-adapter-sx38y7f7.js → opencode-adapter-46nnmnvv.js} +3 -3
- package/dist/{otel-impl-54cra6mw.js → otel-impl-k47aj4sd.js} +73 -4
- package/dist/{pi-mono-adapter-29g7axgj.js → pi-mono-adapter-wawfj09v.js} +42 -40
- package/dist/{pricing-refresh-mkyy7c2y.js → pricing-refresh-ky2gjp05.js} +5 -5
- package/dist/{rbac-roles-kb3afm95.js → rbac-roles-0j0f7s8r.js} +4 -4
- package/dist/{rbac-roles-ak56tr75.js → rbac-roles-az4wc15e.js} +3 -3
- package/dist/{render-v2-434asg49.js → render-v2-seyxq61z.js} +4 -5
- package/dist/{seed-pricing-nbmd7ah8.js → seed-pricing-fev611hx.js} +4 -4
- package/dist/{setup-wh4qmjs4.js → setup-hy404zwh.js} +2 -2
- package/dist/{worker-j1d27tjv.js → worker-g1j5hn16.js} +36 -36
- package/openapi.json +197 -27
- package/package.json +9 -3
- package/src/be/db-client.ts +58 -5
- package/src/be/db-retention.ts +550 -121
- package/src/be/db.ts +367 -55
- package/src/be/memory/raters/retrieval.ts +40 -0
- package/src/be/migrations/140_approval_request_cancelled_status.sql +64 -0
- package/src/be/pricing-normalize.ts +3 -0
- package/src/be/script-connections.ts +26 -6
- package/src/be/seed-pricing.ts +18 -8
- package/src/be/swarm-config-guard.ts +33 -0
- package/src/cli.tsx +20 -1
- package/src/commands/onboard/compose-generator.ts +63 -7
- package/src/commands/onboard/env-generator.ts +32 -4
- package/src/commands/onboard/manifest.ts +4 -1
- package/src/commands/onboard/non-interactive.ts +159 -0
- package/src/commands/onboard/steps/generate.tsx +1 -34
- package/src/commands/onboard/steps/harness-credentials.tsx +181 -1
- package/src/commands/onboard/steps/harness.tsx +20 -6
- package/src/commands/onboard/steps/review.tsx +3 -2
- package/src/commands/onboard/types.ts +48 -1
- package/src/commands/onboard.tsx +18 -13
- package/src/commands/provider-credentials.ts +17 -3
- package/src/commands/runner.ts +1 -0
- package/src/heartbeat/heartbeat.ts +47 -7
- package/src/http/approval-requests.ts +53 -8
- package/src/http/index.ts +9 -1
- package/src/http/mcp-servers.ts +2 -0
- package/src/http/memory.ts +27 -1
- package/src/http/oauth-callback.ts +33 -0
- package/src/http/repos.ts +6 -0
- package/src/http/script-connections.ts +77 -0
- package/src/http/session-data.ts +5 -1
- package/src/http/stats.ts +21 -30
- package/src/http/tasks.ts +10 -0
- package/src/oauth/presets.ts +29 -0
- package/src/otel-impl.ts +96 -1
- package/src/otel.ts +34 -0
- package/src/prompts/memories.ts +2 -2
- package/src/providers/acp-adapter.ts +325 -0
- package/src/providers/acp-swarm-events.ts +113 -0
- package/src/providers/acp-targets.ts +103 -0
- package/src/providers/claude-managed-models.ts +17 -1
- package/src/providers/codex-adapter.ts +3 -3
- package/src/providers/codex-oauth/auth-json-fs.ts +2 -2
- package/src/providers/codex-oauth/home.ts +13 -0
- package/src/providers/index.ts +5 -1
- package/src/providers/types.ts +1 -1
- package/src/server-user.ts +1 -0
- package/src/slack/app.ts +5 -1
- package/src/tasks/worker-follow-up.ts +78 -7
- package/src/telemetry.ts +151 -0
- package/src/tests/acp-adapter.test.ts +192 -0
- package/src/tests/acp-swarm-events.test.ts +132 -0
- package/src/tests/agents-list-model-display.test.ts +20 -0
- package/src/tests/approval-cancellation-migration.test.ts +134 -0
- package/src/tests/approval-requests.test.ts +456 -2
- package/src/tests/apps-spike2.test.ts +4 -1
- package/src/tests/apps-sync-engine.test.ts +22 -18
- package/src/tests/claude-managed-adapter.test.ts +12 -0
- package/src/tests/codex-oauth-auth-json-fs.test.ts +19 -0
- package/src/tests/connection-embedded-auth.test.ts +4 -1
- package/src/tests/context-window.test.ts +2 -0
- package/src/tests/credential-check.test.ts +6 -0
- package/src/tests/db-client-busy-retry.test.ts +18 -0
- package/src/tests/db-client.test.ts +23 -0
- package/src/tests/db-retention-telemetry.test.ts +569 -0
- package/src/tests/db-retention.test.ts +456 -117
- package/src/tests/heartbeat.test.ts +140 -0
- package/src/tests/memory-http-recall-gating.test.ts +120 -13
- package/src/tests/memory-store.test.ts +41 -0
- package/src/tests/migration-046-budgets.test.ts +27 -5
- package/src/tests/oauth-presets.test.ts +17 -5
- package/src/tests/onboard-compose.test.ts +99 -0
- package/src/tests/onboard-env.test.ts +43 -0
- package/src/tests/onboard-manifest.test.ts +17 -1
- package/src/tests/onboard-non-interactive.test.ts +89 -0
- package/src/tests/pool-affinity.test.ts +100 -0
- package/src/tests/promote-draft-task-route.test.ts +32 -1
- package/src/tests/sandbox-spawn-test-helpers.ts +3 -0
- package/src/tests/sandboxed-process.test.ts +2 -2
- package/src/tests/schedule-target-type.test.ts +6 -3
- package/src/tests/script-connections-http.test.ts +4 -3
- package/src/tests/script-connections.test.ts +6 -1
- package/src/tests/script-workflows-runtime-e2e.test.ts +36 -28
- package/src/tests/scripts-external-api.test.ts +8 -5
- package/src/tests/scripts-http.test.ts +6 -3
- package/src/tests/scripts-mcp-e2e.test.ts +65 -60
- package/src/tests/scripts-retention.test.ts +6 -3
- package/src/tests/scripts-runtime-identity.test.ts +4 -2
- package/src/tests/scripts-runtime.test.ts +18 -16
- package/src/tests/session-costs-model-key-normalize.test.ts +2 -0
- package/src/tests/slack-read-boundaries.test.ts +3 -1
- package/src/tests/task-lifecycle-telemetry.test.ts +1 -0
- package/src/tests/task-tools-ctx.test.ts +88 -1
- package/src/tests/telemetry-init.test.ts +61 -0
- package/src/tests/tool-annotations.test.ts +4 -1
- package/src/tests/vendored-openapi.test.ts +15 -2
- package/src/tests/workflow-e2e.test.ts +4 -1
- package/src/tests/workflow-engine-v2.test.ts +5 -2
- package/src/tests/workflow-executors.test.ts +24 -19
- package/src/tests/workflow-http-v2.test.ts +17 -2
- package/src/tests/workflow-llm.test.ts +57 -0
- package/src/tests/workflow-retry-v2.test.ts +142 -1
- package/src/tests/workflow-swarm-script.test.ts +20 -17
- package/src/tools/get-task-details.ts +1 -0
- package/src/tools/mcp-servers/mcp-server-create.ts +7 -1
- package/src/tools/memory-search.ts +27 -2
- package/src/tools/send-task.ts +28 -10
- package/src/tools/task-action.ts +13 -5
- package/src/types.ts +31 -2
- package/src/utils/context-window.ts +2 -0
- package/src/workflows/approval-notifications.ts +72 -0
- package/src/workflows/checkpoint.ts +16 -9
- package/src/workflows/completed-step-routing.ts +31 -0
- package/src/workflows/engine.ts +59 -43
- package/src/workflows/executors/human-in-the-loop.ts +38 -4
- package/src/workflows/executors/raw-llm.ts +8 -6
- package/src/workflows/executors/validate.ts +6 -5
- package/src/workflows/executors/workflow-llm.ts +35 -0
- package/src/workflows/resume.ts +90 -13
- package/src/workflows/retry-poller.ts +8 -1
- package/vendored-openapi/README.md +4 -2
- package/vendored-openapi/manifest.json +33 -0
- package/vendored-openapi/microsoft-graph.json +781 -0
- package/dist/cli-5tnr64pm.js +0 -29
- package/dist/{anthropic-messages-pm7pp23c.js → anthropic-messages-tvgm75yc.js} +3 -3
- package/dist/{azure-openai-responses-cwesc845.js → azure-openai-responses-hed7waek.js} +4 -4
- package/dist/{cli-s9gpxh9q.js → cli-5kmzp1wx.js} +0 -0
- package/dist/{cli-s73zwwqn.js → cli-xjx3fbtn.js} +4 -4
- package/dist/{openai-codex-responses-xxca1qr1.js → openai-codex-responses-gv3n8rg0.js} +3 -3
- package/dist/{openai-completions-yzftqrft.js → openai-completions-dkrj9433.js} +8 -8
- package/dist/{openai-responses-e4dcwm9g.js → openai-responses-spk6t7kh.js} +11 -11
- package/dist/{openrouter-images-asqqnbvh.js → openrouter-images-71hthwh9.js} +3 -3
|
@@ -0,0 +1,4787 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchInstalledMcpServers
|
|
3
|
+
} from "./cli-tng3131n.js";
|
|
4
|
+
import"./cli-rx5cxzn2.js";
|
|
5
|
+
import {
|
|
6
|
+
array,
|
|
7
|
+
boolean,
|
|
8
|
+
exports_external,
|
|
9
|
+
int,
|
|
10
|
+
intersection,
|
|
11
|
+
literal,
|
|
12
|
+
number,
|
|
13
|
+
object,
|
|
14
|
+
record,
|
|
15
|
+
string,
|
|
16
|
+
union,
|
|
17
|
+
unknown,
|
|
18
|
+
url
|
|
19
|
+
} from "./cli-pqv5gvyf.js";
|
|
20
|
+
import {
|
|
21
|
+
init_package,
|
|
22
|
+
package_default
|
|
23
|
+
} from "./cli-kkn46gfr.js";
|
|
24
|
+
import {
|
|
25
|
+
init_secret_scrubber,
|
|
26
|
+
scrubSecrets
|
|
27
|
+
} from "./cli-mkq1rk7b.js";
|
|
28
|
+
import"./cli-pq2ee5ja.js";
|
|
29
|
+
|
|
30
|
+
// node_modules/@agentclientprotocol/sdk/dist/schema/index.js
|
|
31
|
+
var AGENT_METHODS = {
|
|
32
|
+
initialize: "initialize",
|
|
33
|
+
authenticate: "authenticate",
|
|
34
|
+
providers_list: "providers/list",
|
|
35
|
+
providers_set: "providers/set",
|
|
36
|
+
providers_disable: "providers/disable",
|
|
37
|
+
session_new: "session/new",
|
|
38
|
+
session_load: "session/load",
|
|
39
|
+
session_set_mode: "session/set_mode",
|
|
40
|
+
session_set_config_option: "session/set_config_option",
|
|
41
|
+
session_prompt: "session/prompt",
|
|
42
|
+
session_cancel: "session/cancel",
|
|
43
|
+
mcp_message: "mcp/message",
|
|
44
|
+
session_list: "session/list",
|
|
45
|
+
session_delete: "session/delete",
|
|
46
|
+
session_fork: "session/fork",
|
|
47
|
+
session_resume: "session/resume",
|
|
48
|
+
session_close: "session/close",
|
|
49
|
+
logout: "logout",
|
|
50
|
+
nes_start: "nes/start",
|
|
51
|
+
nes_suggest: "nes/suggest",
|
|
52
|
+
nes_accept: "nes/accept",
|
|
53
|
+
nes_reject: "nes/reject",
|
|
54
|
+
nes_close: "nes/close",
|
|
55
|
+
document_did_open: "document/didOpen",
|
|
56
|
+
document_did_change: "document/didChange",
|
|
57
|
+
document_did_close: "document/didClose",
|
|
58
|
+
document_did_save: "document/didSave",
|
|
59
|
+
document_did_focus: "document/didFocus"
|
|
60
|
+
};
|
|
61
|
+
var CLIENT_METHODS = {
|
|
62
|
+
session_request_permission: "session/request_permission",
|
|
63
|
+
session_update: "session/update",
|
|
64
|
+
fs_write_text_file: "fs/write_text_file",
|
|
65
|
+
fs_read_text_file: "fs/read_text_file",
|
|
66
|
+
terminal_create: "terminal/create",
|
|
67
|
+
terminal_output: "terminal/output",
|
|
68
|
+
terminal_release: "terminal/release",
|
|
69
|
+
terminal_wait_for_exit: "terminal/wait_for_exit",
|
|
70
|
+
terminal_kill: "terminal/kill",
|
|
71
|
+
mcp_connect: "mcp/connect",
|
|
72
|
+
mcp_message: "mcp/message",
|
|
73
|
+
mcp_disconnect: "mcp/disconnect",
|
|
74
|
+
elicitation_create: "elicitation/create",
|
|
75
|
+
elicitation_complete: "elicitation/complete"
|
|
76
|
+
};
|
|
77
|
+
var PROTOCOL_METHODS = {
|
|
78
|
+
cancel_request: "$/cancel_request"
|
|
79
|
+
};
|
|
80
|
+
var PROTOCOL_VERSION = 1;
|
|
81
|
+
|
|
82
|
+
// node_modules/@agentclientprotocol/sdk/dist/schema-deserialize.js
|
|
83
|
+
var skippedItem = Symbol("skippedItem");
|
|
84
|
+
function defaultOnError(schema, fallback) {
|
|
85
|
+
return schema.catch(fallback);
|
|
86
|
+
}
|
|
87
|
+
function requiredDefaultOnError(schema, fallback) {
|
|
88
|
+
const schemaWithCatch = schema.catch(fallback);
|
|
89
|
+
return exports_external.unknown().transform((value, context) => {
|
|
90
|
+
if (value !== undefined)
|
|
91
|
+
return schemaWithCatch.parse(value);
|
|
92
|
+
context.addIssue({
|
|
93
|
+
code: "custom",
|
|
94
|
+
message: "Required value is missing"
|
|
95
|
+
});
|
|
96
|
+
return exports_external.NEVER;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function stringTag(value, key) {
|
|
100
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const tag = value[key];
|
|
104
|
+
return typeof tag === "string" ? tag : undefined;
|
|
105
|
+
}
|
|
106
|
+
function excludeKnownTags(schema, key, knownTags) {
|
|
107
|
+
return schema.superRefine((value, context) => {
|
|
108
|
+
const tag = stringTag(value, key);
|
|
109
|
+
if (tag !== undefined && knownTags.includes(tag)) {
|
|
110
|
+
context.addIssue({
|
|
111
|
+
code: "custom",
|
|
112
|
+
path: [key],
|
|
113
|
+
message: `${key} ${JSON.stringify(tag)} is reserved by a known variant, ` + `but the value does not match that variant's schema`
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function preserveCustomPayload(schema, key, knownTags) {
|
|
119
|
+
return exports_external.unknown().transform((value, context) => {
|
|
120
|
+
const result = schema.safeParse(value);
|
|
121
|
+
if (!result.success) {
|
|
122
|
+
for (const issue of result.error.issues) {
|
|
123
|
+
context.addIssue({ ...issue, input: value });
|
|
124
|
+
}
|
|
125
|
+
return exports_external.NEVER;
|
|
126
|
+
}
|
|
127
|
+
const output = result.data;
|
|
128
|
+
const tag = stringTag(value, key);
|
|
129
|
+
if (tag !== undefined && !knownTags.includes(tag)) {
|
|
130
|
+
const raw = value;
|
|
131
|
+
for (const [property, rawValue] of Object.entries(raw)) {
|
|
132
|
+
if (property === "__proto__")
|
|
133
|
+
continue;
|
|
134
|
+
if (!Object.hasOwn(output, property))
|
|
135
|
+
output[property] = rawValue;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return output;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function vecSkipError(itemSchema) {
|
|
142
|
+
return exports_external.array(itemSchema.catch(skippedItem)).transform((items) => items.filter((item) => item !== skippedItem));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js
|
|
146
|
+
var zRequestId = union([number(), string()]).nullable();
|
|
147
|
+
var zSessionId = string();
|
|
148
|
+
var zWriteTextFileRequest = object({
|
|
149
|
+
sessionId: zSessionId,
|
|
150
|
+
path: string(),
|
|
151
|
+
content: string(),
|
|
152
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
153
|
+
return;
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
var zReadTextFileRequest = object({
|
|
157
|
+
sessionId: zSessionId,
|
|
158
|
+
path: string(),
|
|
159
|
+
line: defaultOnError(int().gte(0).max(4294967295, {
|
|
160
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
161
|
+
}).nullish(), () => {
|
|
162
|
+
return;
|
|
163
|
+
}),
|
|
164
|
+
limit: defaultOnError(int().gte(0).max(4294967295, {
|
|
165
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
166
|
+
}).nullish(), () => {
|
|
167
|
+
return;
|
|
168
|
+
}),
|
|
169
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
170
|
+
return;
|
|
171
|
+
})
|
|
172
|
+
});
|
|
173
|
+
var zToolCallId = string();
|
|
174
|
+
var zToolKind = union([
|
|
175
|
+
literal("read"),
|
|
176
|
+
literal("edit"),
|
|
177
|
+
literal("delete"),
|
|
178
|
+
literal("move"),
|
|
179
|
+
literal("search"),
|
|
180
|
+
literal("execute"),
|
|
181
|
+
literal("think"),
|
|
182
|
+
literal("fetch"),
|
|
183
|
+
literal("switch_mode"),
|
|
184
|
+
literal("other")
|
|
185
|
+
]);
|
|
186
|
+
var zToolCallStatus = union([
|
|
187
|
+
literal("pending"),
|
|
188
|
+
literal("in_progress"),
|
|
189
|
+
literal("completed"),
|
|
190
|
+
literal("failed")
|
|
191
|
+
]);
|
|
192
|
+
var zRole = union([literal("assistant"), literal("user")]);
|
|
193
|
+
var zAnnotations = object({
|
|
194
|
+
audience: defaultOnError(vecSkipError(zRole).nullish(), () => {
|
|
195
|
+
return;
|
|
196
|
+
}),
|
|
197
|
+
lastModified: defaultOnError(string().nullish(), () => {
|
|
198
|
+
return;
|
|
199
|
+
}),
|
|
200
|
+
priority: defaultOnError(number().nullish(), () => {
|
|
201
|
+
return;
|
|
202
|
+
}),
|
|
203
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
204
|
+
return;
|
|
205
|
+
})
|
|
206
|
+
});
|
|
207
|
+
var zTextContent = object({
|
|
208
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => {
|
|
209
|
+
return;
|
|
210
|
+
}),
|
|
211
|
+
text: string(),
|
|
212
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
213
|
+
return;
|
|
214
|
+
})
|
|
215
|
+
});
|
|
216
|
+
var zImageContent = object({
|
|
217
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => {
|
|
218
|
+
return;
|
|
219
|
+
}),
|
|
220
|
+
data: string(),
|
|
221
|
+
mimeType: string(),
|
|
222
|
+
uri: defaultOnError(string().nullish(), () => {
|
|
223
|
+
return;
|
|
224
|
+
}),
|
|
225
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
226
|
+
return;
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
var zAudioContent = object({
|
|
230
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => {
|
|
231
|
+
return;
|
|
232
|
+
}),
|
|
233
|
+
data: string(),
|
|
234
|
+
mimeType: string(),
|
|
235
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
236
|
+
return;
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
var zResourceLink = object({
|
|
240
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => {
|
|
241
|
+
return;
|
|
242
|
+
}),
|
|
243
|
+
description: defaultOnError(string().nullish(), () => {
|
|
244
|
+
return;
|
|
245
|
+
}),
|
|
246
|
+
mimeType: defaultOnError(string().nullish(), () => {
|
|
247
|
+
return;
|
|
248
|
+
}),
|
|
249
|
+
name: string(),
|
|
250
|
+
size: defaultOnError(number().nullish(), () => {
|
|
251
|
+
return;
|
|
252
|
+
}),
|
|
253
|
+
title: defaultOnError(string().nullish(), () => {
|
|
254
|
+
return;
|
|
255
|
+
}),
|
|
256
|
+
uri: string(),
|
|
257
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
258
|
+
return;
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
var zTextResourceContents = object({
|
|
262
|
+
mimeType: defaultOnError(string().nullish(), () => {
|
|
263
|
+
return;
|
|
264
|
+
}),
|
|
265
|
+
text: string(),
|
|
266
|
+
uri: string(),
|
|
267
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
268
|
+
return;
|
|
269
|
+
})
|
|
270
|
+
});
|
|
271
|
+
var zBlobResourceContents = object({
|
|
272
|
+
blob: string(),
|
|
273
|
+
mimeType: defaultOnError(string().nullish(), () => {
|
|
274
|
+
return;
|
|
275
|
+
}),
|
|
276
|
+
uri: string(),
|
|
277
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
278
|
+
return;
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
var zEmbeddedResourceResource = union([
|
|
282
|
+
zTextResourceContents,
|
|
283
|
+
zBlobResourceContents
|
|
284
|
+
]);
|
|
285
|
+
var zEmbeddedResource = object({
|
|
286
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => {
|
|
287
|
+
return;
|
|
288
|
+
}),
|
|
289
|
+
resource: zEmbeddedResourceResource,
|
|
290
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
291
|
+
return;
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
var zContentBlock = union([
|
|
295
|
+
zTextContent.and(object({
|
|
296
|
+
type: literal("text")
|
|
297
|
+
})),
|
|
298
|
+
zImageContent.and(object({
|
|
299
|
+
type: literal("image")
|
|
300
|
+
})),
|
|
301
|
+
zAudioContent.and(object({
|
|
302
|
+
type: literal("audio")
|
|
303
|
+
})),
|
|
304
|
+
zResourceLink.and(object({
|
|
305
|
+
type: literal("resource_link")
|
|
306
|
+
})),
|
|
307
|
+
zEmbeddedResource.and(object({
|
|
308
|
+
type: literal("resource")
|
|
309
|
+
}))
|
|
310
|
+
]);
|
|
311
|
+
var zContent = object({
|
|
312
|
+
content: zContentBlock,
|
|
313
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
314
|
+
return;
|
|
315
|
+
})
|
|
316
|
+
});
|
|
317
|
+
var zDiff = object({
|
|
318
|
+
path: string(),
|
|
319
|
+
oldText: defaultOnError(string().nullish(), () => {
|
|
320
|
+
return;
|
|
321
|
+
}),
|
|
322
|
+
newText: string(),
|
|
323
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
324
|
+
return;
|
|
325
|
+
})
|
|
326
|
+
});
|
|
327
|
+
var zTerminalId = string();
|
|
328
|
+
var zTerminal = object({
|
|
329
|
+
terminalId: zTerminalId,
|
|
330
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
331
|
+
return;
|
|
332
|
+
})
|
|
333
|
+
});
|
|
334
|
+
var zToolCallContent = union([
|
|
335
|
+
zContent.and(object({
|
|
336
|
+
type: literal("content")
|
|
337
|
+
})),
|
|
338
|
+
zDiff.and(object({
|
|
339
|
+
type: literal("diff")
|
|
340
|
+
})),
|
|
341
|
+
zTerminal.and(object({
|
|
342
|
+
type: literal("terminal")
|
|
343
|
+
}))
|
|
344
|
+
]);
|
|
345
|
+
var zToolCallLocation = object({
|
|
346
|
+
path: string(),
|
|
347
|
+
line: defaultOnError(int().gte(0).max(4294967295, {
|
|
348
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
349
|
+
}).nullish(), () => {
|
|
350
|
+
return;
|
|
351
|
+
}),
|
|
352
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
353
|
+
return;
|
|
354
|
+
})
|
|
355
|
+
});
|
|
356
|
+
var zToolCallUpdate = object({
|
|
357
|
+
toolCallId: zToolCallId,
|
|
358
|
+
kind: defaultOnError(zToolKind.nullish(), () => {
|
|
359
|
+
return;
|
|
360
|
+
}),
|
|
361
|
+
status: defaultOnError(zToolCallStatus.nullish(), () => {
|
|
362
|
+
return;
|
|
363
|
+
}),
|
|
364
|
+
title: defaultOnError(string().nullish(), () => {
|
|
365
|
+
return;
|
|
366
|
+
}),
|
|
367
|
+
name: defaultOnError(string().nullish(), () => {
|
|
368
|
+
return;
|
|
369
|
+
}),
|
|
370
|
+
content: defaultOnError(vecSkipError(zToolCallContent).nullish(), () => {
|
|
371
|
+
return;
|
|
372
|
+
}),
|
|
373
|
+
locations: defaultOnError(vecSkipError(zToolCallLocation).nullish(), () => {
|
|
374
|
+
return;
|
|
375
|
+
}),
|
|
376
|
+
rawInput: defaultOnError(unknown().optional(), () => {
|
|
377
|
+
return;
|
|
378
|
+
}),
|
|
379
|
+
rawOutput: defaultOnError(unknown().optional(), () => {
|
|
380
|
+
return;
|
|
381
|
+
}),
|
|
382
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
383
|
+
return;
|
|
384
|
+
})
|
|
385
|
+
});
|
|
386
|
+
var zPermissionOptionId = string();
|
|
387
|
+
var zPermissionOptionKind = union([
|
|
388
|
+
literal("allow_once"),
|
|
389
|
+
literal("allow_always"),
|
|
390
|
+
literal("reject_once"),
|
|
391
|
+
literal("reject_always")
|
|
392
|
+
]);
|
|
393
|
+
var zPermissionOption = object({
|
|
394
|
+
optionId: zPermissionOptionId,
|
|
395
|
+
name: string(),
|
|
396
|
+
kind: zPermissionOptionKind,
|
|
397
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
398
|
+
return;
|
|
399
|
+
})
|
|
400
|
+
});
|
|
401
|
+
var zRequestPermissionRequest = object({
|
|
402
|
+
sessionId: zSessionId,
|
|
403
|
+
toolCall: zToolCallUpdate,
|
|
404
|
+
options: array(zPermissionOption),
|
|
405
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
406
|
+
return;
|
|
407
|
+
})
|
|
408
|
+
});
|
|
409
|
+
var zEnvVariable = object({
|
|
410
|
+
name: string(),
|
|
411
|
+
value: string(),
|
|
412
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
413
|
+
return;
|
|
414
|
+
})
|
|
415
|
+
});
|
|
416
|
+
var zCreateTerminalRequest = object({
|
|
417
|
+
sessionId: zSessionId,
|
|
418
|
+
command: string(),
|
|
419
|
+
args: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
420
|
+
env: defaultOnError(vecSkipError(zEnvVariable).optional(), () => []),
|
|
421
|
+
cwd: defaultOnError(string().nullish(), () => {
|
|
422
|
+
return;
|
|
423
|
+
}),
|
|
424
|
+
outputByteLimit: defaultOnError(number().nullish(), () => {
|
|
425
|
+
return;
|
|
426
|
+
}),
|
|
427
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
428
|
+
return;
|
|
429
|
+
})
|
|
430
|
+
});
|
|
431
|
+
var zTerminalOutputRequest = object({
|
|
432
|
+
sessionId: zSessionId,
|
|
433
|
+
terminalId: zTerminalId,
|
|
434
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
435
|
+
return;
|
|
436
|
+
})
|
|
437
|
+
});
|
|
438
|
+
var zReleaseTerminalRequest = object({
|
|
439
|
+
sessionId: zSessionId,
|
|
440
|
+
terminalId: zTerminalId,
|
|
441
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
442
|
+
return;
|
|
443
|
+
})
|
|
444
|
+
});
|
|
445
|
+
var zWaitForTerminalExitRequest = object({
|
|
446
|
+
sessionId: zSessionId,
|
|
447
|
+
terminalId: zTerminalId,
|
|
448
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
449
|
+
return;
|
|
450
|
+
})
|
|
451
|
+
});
|
|
452
|
+
var zKillTerminalRequest = object({
|
|
453
|
+
sessionId: zSessionId,
|
|
454
|
+
terminalId: zTerminalId,
|
|
455
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
456
|
+
return;
|
|
457
|
+
})
|
|
458
|
+
});
|
|
459
|
+
var zElicitationSessionScope = object({
|
|
460
|
+
sessionId: zSessionId,
|
|
461
|
+
toolCallId: defaultOnError(zToolCallId.nullish(), () => {
|
|
462
|
+
return;
|
|
463
|
+
})
|
|
464
|
+
});
|
|
465
|
+
var zElicitationRequestScope = object({
|
|
466
|
+
requestId: zRequestId
|
|
467
|
+
});
|
|
468
|
+
var zElicitationSchemaType = literal("object");
|
|
469
|
+
var zStringFormat = union([
|
|
470
|
+
literal("email"),
|
|
471
|
+
literal("uri"),
|
|
472
|
+
literal("date"),
|
|
473
|
+
literal("date-time")
|
|
474
|
+
]);
|
|
475
|
+
var zEnumOption = object({
|
|
476
|
+
const: string(),
|
|
477
|
+
title: string(),
|
|
478
|
+
description: defaultOnError(string().nullish(), () => {
|
|
479
|
+
return;
|
|
480
|
+
}),
|
|
481
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
482
|
+
return;
|
|
483
|
+
})
|
|
484
|
+
});
|
|
485
|
+
var zStringPropertySchema = object({
|
|
486
|
+
title: defaultOnError(string().nullish(), () => {
|
|
487
|
+
return;
|
|
488
|
+
}),
|
|
489
|
+
description: defaultOnError(string().nullish(), () => {
|
|
490
|
+
return;
|
|
491
|
+
}),
|
|
492
|
+
minLength: int().gte(0).max(4294967295, {
|
|
493
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
494
|
+
}).nullish(),
|
|
495
|
+
maxLength: int().gte(0).max(4294967295, {
|
|
496
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
497
|
+
}).nullish(),
|
|
498
|
+
pattern: string().nullish(),
|
|
499
|
+
format: zStringFormat.nullish(),
|
|
500
|
+
default: defaultOnError(string().nullish(), () => {
|
|
501
|
+
return;
|
|
502
|
+
}),
|
|
503
|
+
enum: array(string()).nullish(),
|
|
504
|
+
oneOf: array(zEnumOption).nullish(),
|
|
505
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
506
|
+
return;
|
|
507
|
+
})
|
|
508
|
+
});
|
|
509
|
+
var zNumberPropertySchema = object({
|
|
510
|
+
title: defaultOnError(string().nullish(), () => {
|
|
511
|
+
return;
|
|
512
|
+
}),
|
|
513
|
+
description: defaultOnError(string().nullish(), () => {
|
|
514
|
+
return;
|
|
515
|
+
}),
|
|
516
|
+
minimum: number().nullish(),
|
|
517
|
+
maximum: number().nullish(),
|
|
518
|
+
default: defaultOnError(number().nullish(), () => {
|
|
519
|
+
return;
|
|
520
|
+
}),
|
|
521
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
522
|
+
return;
|
|
523
|
+
})
|
|
524
|
+
});
|
|
525
|
+
var zIntegerPropertySchema = object({
|
|
526
|
+
title: defaultOnError(string().nullish(), () => {
|
|
527
|
+
return;
|
|
528
|
+
}),
|
|
529
|
+
description: defaultOnError(string().nullish(), () => {
|
|
530
|
+
return;
|
|
531
|
+
}),
|
|
532
|
+
minimum: number().nullish(),
|
|
533
|
+
maximum: number().nullish(),
|
|
534
|
+
default: defaultOnError(number().nullish(), () => {
|
|
535
|
+
return;
|
|
536
|
+
}),
|
|
537
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
538
|
+
return;
|
|
539
|
+
})
|
|
540
|
+
});
|
|
541
|
+
var zBooleanPropertySchema = object({
|
|
542
|
+
title: defaultOnError(string().nullish(), () => {
|
|
543
|
+
return;
|
|
544
|
+
}),
|
|
545
|
+
description: defaultOnError(string().nullish(), () => {
|
|
546
|
+
return;
|
|
547
|
+
}),
|
|
548
|
+
default: defaultOnError(boolean().nullish(), () => {
|
|
549
|
+
return;
|
|
550
|
+
}),
|
|
551
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
552
|
+
return;
|
|
553
|
+
})
|
|
554
|
+
});
|
|
555
|
+
var zStringMultiSelectItems = object({
|
|
556
|
+
enum: array(string()),
|
|
557
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
558
|
+
return;
|
|
559
|
+
})
|
|
560
|
+
});
|
|
561
|
+
var zTitledMultiSelectItems = object({
|
|
562
|
+
anyOf: array(zEnumOption),
|
|
563
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
564
|
+
return;
|
|
565
|
+
})
|
|
566
|
+
});
|
|
567
|
+
var zMultiSelectItems = preserveCustomPayload(union([
|
|
568
|
+
zStringMultiSelectItems.and(object({
|
|
569
|
+
type: literal("string")
|
|
570
|
+
})),
|
|
571
|
+
excludeKnownTags(object({
|
|
572
|
+
type: string()
|
|
573
|
+
}), "type", ["string"]),
|
|
574
|
+
zTitledMultiSelectItems
|
|
575
|
+
]), "type", ["string"]);
|
|
576
|
+
var zMultiSelectPropertySchema = object({
|
|
577
|
+
title: defaultOnError(string().nullish(), () => {
|
|
578
|
+
return;
|
|
579
|
+
}),
|
|
580
|
+
description: defaultOnError(string().nullish(), () => {
|
|
581
|
+
return;
|
|
582
|
+
}),
|
|
583
|
+
minItems: number().nullish(),
|
|
584
|
+
maxItems: number().nullish(),
|
|
585
|
+
items: zMultiSelectItems,
|
|
586
|
+
default: defaultOnError(vecSkipError(string()).nullish(), () => {
|
|
587
|
+
return;
|
|
588
|
+
}),
|
|
589
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
590
|
+
return;
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
var zElicitationPropertySchema = preserveCustomPayload(union([
|
|
594
|
+
zStringPropertySchema.and(object({
|
|
595
|
+
type: literal("string")
|
|
596
|
+
})),
|
|
597
|
+
zNumberPropertySchema.and(object({
|
|
598
|
+
type: literal("number")
|
|
599
|
+
})),
|
|
600
|
+
zIntegerPropertySchema.and(object({
|
|
601
|
+
type: literal("integer")
|
|
602
|
+
})),
|
|
603
|
+
zBooleanPropertySchema.and(object({
|
|
604
|
+
type: literal("boolean")
|
|
605
|
+
})),
|
|
606
|
+
zMultiSelectPropertySchema.and(object({
|
|
607
|
+
type: literal("array")
|
|
608
|
+
})),
|
|
609
|
+
excludeKnownTags(object({
|
|
610
|
+
type: string()
|
|
611
|
+
}), "type", ["array", "boolean", "integer", "number", "string"])
|
|
612
|
+
]), "type", ["array", "boolean", "integer", "number", "string"]);
|
|
613
|
+
var zElicitationSchema = object({
|
|
614
|
+
type: defaultOnError(zElicitationSchemaType.optional().default("object"), () => "object"),
|
|
615
|
+
title: defaultOnError(string().nullish(), () => {
|
|
616
|
+
return;
|
|
617
|
+
}),
|
|
618
|
+
properties: record(string(), zElicitationPropertySchema).optional().default({}),
|
|
619
|
+
required: array(string()).nullish(),
|
|
620
|
+
description: defaultOnError(string().nullish(), () => {
|
|
621
|
+
return;
|
|
622
|
+
}),
|
|
623
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
624
|
+
return;
|
|
625
|
+
})
|
|
626
|
+
});
|
|
627
|
+
var zElicitationFormMode = intersection(union([zElicitationSessionScope, zElicitationRequestScope]), object({
|
|
628
|
+
requestedSchema: zElicitationSchema
|
|
629
|
+
}));
|
|
630
|
+
var zElicitationId = string();
|
|
631
|
+
var zElicitationUrlMode = intersection(union([zElicitationSessionScope, zElicitationRequestScope]), object({
|
|
632
|
+
elicitationId: zElicitationId,
|
|
633
|
+
url: url()
|
|
634
|
+
}));
|
|
635
|
+
var zCreateElicitationRequest = preserveCustomPayload(intersection(union([
|
|
636
|
+
zElicitationFormMode.and(object({
|
|
637
|
+
mode: literal("form")
|
|
638
|
+
})),
|
|
639
|
+
zElicitationUrlMode.and(object({
|
|
640
|
+
mode: literal("url")
|
|
641
|
+
})),
|
|
642
|
+
excludeKnownTags(intersection(union([zElicitationSessionScope, zElicitationRequestScope]), object({
|
|
643
|
+
mode: string()
|
|
644
|
+
})), "mode", ["form", "url"])
|
|
645
|
+
]), object({
|
|
646
|
+
message: string(),
|
|
647
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
648
|
+
return;
|
|
649
|
+
})
|
|
650
|
+
})), "mode", ["form", "url"]);
|
|
651
|
+
var zMcpServerAcpId = string();
|
|
652
|
+
var zConnectMcpRequest = object({
|
|
653
|
+
serverId: zMcpServerAcpId,
|
|
654
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
655
|
+
return;
|
|
656
|
+
})
|
|
657
|
+
});
|
|
658
|
+
var zMcpConnectionId = string();
|
|
659
|
+
var zMessageMcpRequest = object({
|
|
660
|
+
connectionId: zMcpConnectionId,
|
|
661
|
+
method: string(),
|
|
662
|
+
params: record(string(), unknown()).nullish(),
|
|
663
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
664
|
+
return;
|
|
665
|
+
})
|
|
666
|
+
});
|
|
667
|
+
var zDisconnectMcpRequest = object({
|
|
668
|
+
connectionId: zMcpConnectionId,
|
|
669
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
670
|
+
return;
|
|
671
|
+
})
|
|
672
|
+
});
|
|
673
|
+
var zExtRequest = unknown();
|
|
674
|
+
var zAgentRequest = object({
|
|
675
|
+
id: zRequestId,
|
|
676
|
+
method: string(),
|
|
677
|
+
params: union([
|
|
678
|
+
zWriteTextFileRequest,
|
|
679
|
+
zReadTextFileRequest,
|
|
680
|
+
zRequestPermissionRequest,
|
|
681
|
+
zCreateTerminalRequest,
|
|
682
|
+
zTerminalOutputRequest,
|
|
683
|
+
zReleaseTerminalRequest,
|
|
684
|
+
zWaitForTerminalExitRequest,
|
|
685
|
+
zKillTerminalRequest,
|
|
686
|
+
zCreateElicitationRequest,
|
|
687
|
+
zConnectMcpRequest,
|
|
688
|
+
zMessageMcpRequest,
|
|
689
|
+
zDisconnectMcpRequest,
|
|
690
|
+
zExtRequest
|
|
691
|
+
]).nullish()
|
|
692
|
+
});
|
|
693
|
+
var zProtocolVersion = int().gte(0).lte(65535);
|
|
694
|
+
var zPromptCapabilities = object({
|
|
695
|
+
image: defaultOnError(boolean().optional().default(false), () => false),
|
|
696
|
+
audio: defaultOnError(boolean().optional().default(false), () => false),
|
|
697
|
+
embeddedContext: defaultOnError(boolean().optional().default(false), () => false),
|
|
698
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
699
|
+
return;
|
|
700
|
+
})
|
|
701
|
+
});
|
|
702
|
+
var zMcpCapabilities = object({
|
|
703
|
+
http: defaultOnError(boolean().optional().default(false), () => false),
|
|
704
|
+
sse: defaultOnError(boolean().optional().default(false), () => false),
|
|
705
|
+
acp: defaultOnError(boolean().optional().default(false), () => false),
|
|
706
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
707
|
+
return;
|
|
708
|
+
})
|
|
709
|
+
});
|
|
710
|
+
var zSessionListCapabilities = object({
|
|
711
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
712
|
+
return;
|
|
713
|
+
})
|
|
714
|
+
});
|
|
715
|
+
var zSessionDeleteCapabilities = object({
|
|
716
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
717
|
+
return;
|
|
718
|
+
})
|
|
719
|
+
});
|
|
720
|
+
var zSessionAdditionalDirectoriesCapabilities = object({
|
|
721
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
722
|
+
return;
|
|
723
|
+
})
|
|
724
|
+
});
|
|
725
|
+
var zSessionForkCapabilities = object({
|
|
726
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
727
|
+
return;
|
|
728
|
+
})
|
|
729
|
+
});
|
|
730
|
+
var zSessionResumeCapabilities = object({
|
|
731
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
732
|
+
return;
|
|
733
|
+
})
|
|
734
|
+
});
|
|
735
|
+
var zSessionCloseCapabilities = object({
|
|
736
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
737
|
+
return;
|
|
738
|
+
})
|
|
739
|
+
});
|
|
740
|
+
var zSessionCapabilities = object({
|
|
741
|
+
list: defaultOnError(zSessionListCapabilities.nullish(), () => {
|
|
742
|
+
return;
|
|
743
|
+
}),
|
|
744
|
+
delete: defaultOnError(zSessionDeleteCapabilities.nullish(), () => {
|
|
745
|
+
return;
|
|
746
|
+
}),
|
|
747
|
+
additionalDirectories: defaultOnError(zSessionAdditionalDirectoriesCapabilities.nullish(), () => {
|
|
748
|
+
return;
|
|
749
|
+
}),
|
|
750
|
+
fork: defaultOnError(zSessionForkCapabilities.nullish(), () => {
|
|
751
|
+
return;
|
|
752
|
+
}),
|
|
753
|
+
resume: defaultOnError(zSessionResumeCapabilities.nullish(), () => {
|
|
754
|
+
return;
|
|
755
|
+
}),
|
|
756
|
+
close: defaultOnError(zSessionCloseCapabilities.nullish(), () => {
|
|
757
|
+
return;
|
|
758
|
+
}),
|
|
759
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
760
|
+
return;
|
|
761
|
+
})
|
|
762
|
+
});
|
|
763
|
+
var zLogoutCapabilities = object({
|
|
764
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
765
|
+
return;
|
|
766
|
+
})
|
|
767
|
+
});
|
|
768
|
+
var zAgentAuthCapabilities = object({
|
|
769
|
+
logout: defaultOnError(zLogoutCapabilities.nullish(), () => {
|
|
770
|
+
return;
|
|
771
|
+
}),
|
|
772
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
773
|
+
return;
|
|
774
|
+
})
|
|
775
|
+
});
|
|
776
|
+
var zProvidersCapabilities = object({
|
|
777
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
778
|
+
return;
|
|
779
|
+
})
|
|
780
|
+
});
|
|
781
|
+
var zNesDocumentDidOpenCapabilities = object({
|
|
782
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
783
|
+
return;
|
|
784
|
+
})
|
|
785
|
+
});
|
|
786
|
+
var zTextDocumentSyncKind = union([
|
|
787
|
+
literal("full"),
|
|
788
|
+
literal("incremental")
|
|
789
|
+
]);
|
|
790
|
+
var zNesDocumentDidChangeCapabilities = object({
|
|
791
|
+
syncKind: zTextDocumentSyncKind,
|
|
792
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
793
|
+
return;
|
|
794
|
+
})
|
|
795
|
+
});
|
|
796
|
+
var zNesDocumentDidCloseCapabilities = object({
|
|
797
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
798
|
+
return;
|
|
799
|
+
})
|
|
800
|
+
});
|
|
801
|
+
var zNesDocumentDidSaveCapabilities = object({
|
|
802
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
803
|
+
return;
|
|
804
|
+
})
|
|
805
|
+
});
|
|
806
|
+
var zNesDocumentDidFocusCapabilities = object({
|
|
807
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
808
|
+
return;
|
|
809
|
+
})
|
|
810
|
+
});
|
|
811
|
+
var zNesDocumentEventCapabilities = object({
|
|
812
|
+
didOpen: defaultOnError(zNesDocumentDidOpenCapabilities.nullish(), () => {
|
|
813
|
+
return;
|
|
814
|
+
}),
|
|
815
|
+
didChange: defaultOnError(zNesDocumentDidChangeCapabilities.nullish(), () => {
|
|
816
|
+
return;
|
|
817
|
+
}),
|
|
818
|
+
didClose: defaultOnError(zNesDocumentDidCloseCapabilities.nullish(), () => {
|
|
819
|
+
return;
|
|
820
|
+
}),
|
|
821
|
+
didSave: defaultOnError(zNesDocumentDidSaveCapabilities.nullish(), () => {
|
|
822
|
+
return;
|
|
823
|
+
}),
|
|
824
|
+
didFocus: defaultOnError(zNesDocumentDidFocusCapabilities.nullish(), () => {
|
|
825
|
+
return;
|
|
826
|
+
}),
|
|
827
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
828
|
+
return;
|
|
829
|
+
})
|
|
830
|
+
});
|
|
831
|
+
var zNesEventCapabilities = object({
|
|
832
|
+
document: defaultOnError(zNesDocumentEventCapabilities.nullish(), () => {
|
|
833
|
+
return;
|
|
834
|
+
}),
|
|
835
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
836
|
+
return;
|
|
837
|
+
})
|
|
838
|
+
});
|
|
839
|
+
var zNesRecentFilesCapabilities = object({
|
|
840
|
+
maxCount: defaultOnError(int().gte(0).max(4294967295, {
|
|
841
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
842
|
+
}).nullish(), () => {
|
|
843
|
+
return;
|
|
844
|
+
}),
|
|
845
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
846
|
+
return;
|
|
847
|
+
})
|
|
848
|
+
});
|
|
849
|
+
var zNesRelatedSnippetsCapabilities = object({
|
|
850
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
851
|
+
return;
|
|
852
|
+
})
|
|
853
|
+
});
|
|
854
|
+
var zNesEditHistoryCapabilities = object({
|
|
855
|
+
maxCount: defaultOnError(int().gte(0).max(4294967295, {
|
|
856
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
857
|
+
}).nullish(), () => {
|
|
858
|
+
return;
|
|
859
|
+
}),
|
|
860
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
861
|
+
return;
|
|
862
|
+
})
|
|
863
|
+
});
|
|
864
|
+
var zNesUserActionsCapabilities = object({
|
|
865
|
+
maxCount: defaultOnError(int().gte(0).max(4294967295, {
|
|
866
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
867
|
+
}).nullish(), () => {
|
|
868
|
+
return;
|
|
869
|
+
}),
|
|
870
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
871
|
+
return;
|
|
872
|
+
})
|
|
873
|
+
});
|
|
874
|
+
var zNesOpenFilesCapabilities = object({
|
|
875
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
876
|
+
return;
|
|
877
|
+
})
|
|
878
|
+
});
|
|
879
|
+
var zNesDiagnosticsCapabilities = object({
|
|
880
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
881
|
+
return;
|
|
882
|
+
})
|
|
883
|
+
});
|
|
884
|
+
var zNesContextCapabilities = object({
|
|
885
|
+
recentFiles: defaultOnError(zNesRecentFilesCapabilities.nullish(), () => {
|
|
886
|
+
return;
|
|
887
|
+
}),
|
|
888
|
+
relatedSnippets: defaultOnError(zNesRelatedSnippetsCapabilities.nullish(), () => {
|
|
889
|
+
return;
|
|
890
|
+
}),
|
|
891
|
+
editHistory: defaultOnError(zNesEditHistoryCapabilities.nullish(), () => {
|
|
892
|
+
return;
|
|
893
|
+
}),
|
|
894
|
+
userActions: defaultOnError(zNesUserActionsCapabilities.nullish(), () => {
|
|
895
|
+
return;
|
|
896
|
+
}),
|
|
897
|
+
openFiles: defaultOnError(zNesOpenFilesCapabilities.nullish(), () => {
|
|
898
|
+
return;
|
|
899
|
+
}),
|
|
900
|
+
diagnostics: defaultOnError(zNesDiagnosticsCapabilities.nullish(), () => {
|
|
901
|
+
return;
|
|
902
|
+
}),
|
|
903
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
904
|
+
return;
|
|
905
|
+
})
|
|
906
|
+
});
|
|
907
|
+
var zNesCapabilities = object({
|
|
908
|
+
events: defaultOnError(zNesEventCapabilities.nullish(), () => {
|
|
909
|
+
return;
|
|
910
|
+
}),
|
|
911
|
+
context: defaultOnError(zNesContextCapabilities.nullish(), () => {
|
|
912
|
+
return;
|
|
913
|
+
}),
|
|
914
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
915
|
+
return;
|
|
916
|
+
})
|
|
917
|
+
});
|
|
918
|
+
var zPositionEncodingKind = union([
|
|
919
|
+
literal("utf-16"),
|
|
920
|
+
literal("utf-32"),
|
|
921
|
+
literal("utf-8")
|
|
922
|
+
]);
|
|
923
|
+
var zAgentCapabilities = object({
|
|
924
|
+
loadSession: defaultOnError(boolean().optional().default(false), () => false),
|
|
925
|
+
promptCapabilities: defaultOnError(zPromptCapabilities.optional().default({
|
|
926
|
+
image: false,
|
|
927
|
+
audio: false,
|
|
928
|
+
embeddedContext: false
|
|
929
|
+
}), () => ({
|
|
930
|
+
image: false,
|
|
931
|
+
audio: false,
|
|
932
|
+
embeddedContext: false
|
|
933
|
+
})),
|
|
934
|
+
mcpCapabilities: defaultOnError(zMcpCapabilities.optional().default({
|
|
935
|
+
http: false,
|
|
936
|
+
sse: false,
|
|
937
|
+
acp: false
|
|
938
|
+
}), () => ({
|
|
939
|
+
http: false,
|
|
940
|
+
sse: false,
|
|
941
|
+
acp: false
|
|
942
|
+
})),
|
|
943
|
+
sessionCapabilities: defaultOnError(zSessionCapabilities.optional().default({}), () => ({})),
|
|
944
|
+
auth: defaultOnError(zAgentAuthCapabilities.optional().default({}), () => ({})),
|
|
945
|
+
providers: defaultOnError(zProvidersCapabilities.nullish(), () => {
|
|
946
|
+
return;
|
|
947
|
+
}),
|
|
948
|
+
nes: defaultOnError(zNesCapabilities.nullish(), () => {
|
|
949
|
+
return;
|
|
950
|
+
}),
|
|
951
|
+
positionEncoding: defaultOnError(zPositionEncodingKind.nullish(), () => {
|
|
952
|
+
return;
|
|
953
|
+
}),
|
|
954
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
955
|
+
return;
|
|
956
|
+
})
|
|
957
|
+
});
|
|
958
|
+
var zAuthMethodId = string();
|
|
959
|
+
var zAuthMethodTerminal = object({
|
|
960
|
+
id: zAuthMethodId,
|
|
961
|
+
name: string(),
|
|
962
|
+
description: defaultOnError(string().nullish(), () => {
|
|
963
|
+
return;
|
|
964
|
+
}),
|
|
965
|
+
args: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
966
|
+
env: defaultOnError(record(string(), string()).optional(), () => {
|
|
967
|
+
return;
|
|
968
|
+
}),
|
|
969
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
970
|
+
return;
|
|
971
|
+
})
|
|
972
|
+
});
|
|
973
|
+
var zAuthMethodAgent = object({
|
|
974
|
+
id: zAuthMethodId,
|
|
975
|
+
name: string(),
|
|
976
|
+
description: defaultOnError(string().nullish(), () => {
|
|
977
|
+
return;
|
|
978
|
+
}),
|
|
979
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
980
|
+
return;
|
|
981
|
+
})
|
|
982
|
+
});
|
|
983
|
+
var zAuthMethod = union([
|
|
984
|
+
zAuthMethodTerminal.and(object({
|
|
985
|
+
type: literal("terminal")
|
|
986
|
+
})),
|
|
987
|
+
zAuthMethodAgent
|
|
988
|
+
]);
|
|
989
|
+
var zImplementation = object({
|
|
990
|
+
name: string(),
|
|
991
|
+
title: defaultOnError(string().nullish(), () => {
|
|
992
|
+
return;
|
|
993
|
+
}),
|
|
994
|
+
version: string(),
|
|
995
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
996
|
+
return;
|
|
997
|
+
})
|
|
998
|
+
});
|
|
999
|
+
var zInitializeResponse = object({
|
|
1000
|
+
protocolVersion: zProtocolVersion,
|
|
1001
|
+
agentCapabilities: defaultOnError(zAgentCapabilities.optional().default({
|
|
1002
|
+
loadSession: false,
|
|
1003
|
+
promptCapabilities: {
|
|
1004
|
+
image: false,
|
|
1005
|
+
audio: false,
|
|
1006
|
+
embeddedContext: false
|
|
1007
|
+
},
|
|
1008
|
+
mcpCapabilities: {
|
|
1009
|
+
http: false,
|
|
1010
|
+
sse: false,
|
|
1011
|
+
acp: false
|
|
1012
|
+
},
|
|
1013
|
+
sessionCapabilities: {},
|
|
1014
|
+
auth: {}
|
|
1015
|
+
}), () => ({
|
|
1016
|
+
loadSession: false,
|
|
1017
|
+
promptCapabilities: {
|
|
1018
|
+
image: false,
|
|
1019
|
+
audio: false,
|
|
1020
|
+
embeddedContext: false
|
|
1021
|
+
},
|
|
1022
|
+
mcpCapabilities: {
|
|
1023
|
+
http: false,
|
|
1024
|
+
sse: false,
|
|
1025
|
+
acp: false
|
|
1026
|
+
},
|
|
1027
|
+
sessionCapabilities: {},
|
|
1028
|
+
auth: {}
|
|
1029
|
+
})),
|
|
1030
|
+
authMethods: defaultOnError(vecSkipError(zAuthMethod).optional().default([]), () => []),
|
|
1031
|
+
agentInfo: defaultOnError(zImplementation.nullish(), () => {
|
|
1032
|
+
return;
|
|
1033
|
+
}),
|
|
1034
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1035
|
+
return;
|
|
1036
|
+
})
|
|
1037
|
+
});
|
|
1038
|
+
var zAuthenticateResponse = object({
|
|
1039
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1040
|
+
return;
|
|
1041
|
+
})
|
|
1042
|
+
});
|
|
1043
|
+
var zProviderId = string();
|
|
1044
|
+
var zLlmProtocol = union([
|
|
1045
|
+
literal("anthropic"),
|
|
1046
|
+
literal("openai"),
|
|
1047
|
+
literal("azure"),
|
|
1048
|
+
literal("vertex"),
|
|
1049
|
+
literal("bedrock"),
|
|
1050
|
+
string()
|
|
1051
|
+
]);
|
|
1052
|
+
var zProviderCurrentConfig = object({
|
|
1053
|
+
apiType: zLlmProtocol,
|
|
1054
|
+
baseUrl: string(),
|
|
1055
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1056
|
+
return;
|
|
1057
|
+
})
|
|
1058
|
+
});
|
|
1059
|
+
var zProviderInfo = object({
|
|
1060
|
+
providerId: zProviderId,
|
|
1061
|
+
supported: requiredDefaultOnError(vecSkipError(zLlmProtocol), () => []),
|
|
1062
|
+
required: boolean(),
|
|
1063
|
+
current: zProviderCurrentConfig.nullish(),
|
|
1064
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1065
|
+
return;
|
|
1066
|
+
})
|
|
1067
|
+
});
|
|
1068
|
+
var zListProvidersResponse = object({
|
|
1069
|
+
providers: array(zProviderInfo),
|
|
1070
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1071
|
+
return;
|
|
1072
|
+
})
|
|
1073
|
+
});
|
|
1074
|
+
var zSetProviderResponse = object({
|
|
1075
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1076
|
+
return;
|
|
1077
|
+
})
|
|
1078
|
+
});
|
|
1079
|
+
var zDisableProviderResponse = object({
|
|
1080
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1081
|
+
return;
|
|
1082
|
+
})
|
|
1083
|
+
});
|
|
1084
|
+
var zLogoutResponse = object({
|
|
1085
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1086
|
+
return;
|
|
1087
|
+
})
|
|
1088
|
+
});
|
|
1089
|
+
var zSessionModeId = string();
|
|
1090
|
+
var zSessionMode = object({
|
|
1091
|
+
id: zSessionModeId,
|
|
1092
|
+
name: string(),
|
|
1093
|
+
description: defaultOnError(string().nullish(), () => {
|
|
1094
|
+
return;
|
|
1095
|
+
}),
|
|
1096
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1097
|
+
return;
|
|
1098
|
+
})
|
|
1099
|
+
});
|
|
1100
|
+
var zSessionModeState = object({
|
|
1101
|
+
currentModeId: zSessionModeId,
|
|
1102
|
+
availableModes: requiredDefaultOnError(vecSkipError(zSessionMode), () => []),
|
|
1103
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1104
|
+
return;
|
|
1105
|
+
})
|
|
1106
|
+
});
|
|
1107
|
+
var zSessionConfigId = string();
|
|
1108
|
+
var zSessionConfigOptionCategory = union([
|
|
1109
|
+
literal("mode"),
|
|
1110
|
+
literal("model"),
|
|
1111
|
+
literal("model_config"),
|
|
1112
|
+
literal("thought_level"),
|
|
1113
|
+
string()
|
|
1114
|
+
]);
|
|
1115
|
+
var zSessionConfigValueId = string();
|
|
1116
|
+
var zSessionConfigSelectOption = object({
|
|
1117
|
+
value: zSessionConfigValueId,
|
|
1118
|
+
name: string(),
|
|
1119
|
+
description: defaultOnError(string().nullish(), () => {
|
|
1120
|
+
return;
|
|
1121
|
+
}),
|
|
1122
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1123
|
+
return;
|
|
1124
|
+
})
|
|
1125
|
+
});
|
|
1126
|
+
var zSessionConfigGroupId = string();
|
|
1127
|
+
var zSessionConfigSelectGroup = object({
|
|
1128
|
+
group: zSessionConfigGroupId,
|
|
1129
|
+
name: string(),
|
|
1130
|
+
options: requiredDefaultOnError(vecSkipError(zSessionConfigSelectOption), () => []),
|
|
1131
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1132
|
+
return;
|
|
1133
|
+
})
|
|
1134
|
+
});
|
|
1135
|
+
var zSessionConfigSelectOptions = union([
|
|
1136
|
+
array(zSessionConfigSelectOption),
|
|
1137
|
+
array(zSessionConfigSelectGroup)
|
|
1138
|
+
]);
|
|
1139
|
+
var zSessionConfigSelect = object({
|
|
1140
|
+
currentValue: zSessionConfigValueId,
|
|
1141
|
+
options: zSessionConfigSelectOptions
|
|
1142
|
+
});
|
|
1143
|
+
var zSessionConfigBoolean = object({
|
|
1144
|
+
currentValue: boolean()
|
|
1145
|
+
});
|
|
1146
|
+
var zSessionConfigOption = intersection(union([
|
|
1147
|
+
zSessionConfigSelect.and(object({
|
|
1148
|
+
type: literal("select")
|
|
1149
|
+
})),
|
|
1150
|
+
zSessionConfigBoolean.and(object({
|
|
1151
|
+
type: literal("boolean")
|
|
1152
|
+
}))
|
|
1153
|
+
]), object({
|
|
1154
|
+
id: zSessionConfigId,
|
|
1155
|
+
name: string(),
|
|
1156
|
+
description: defaultOnError(string().nullish(), () => {
|
|
1157
|
+
return;
|
|
1158
|
+
}),
|
|
1159
|
+
category: defaultOnError(zSessionConfigOptionCategory.nullish(), () => {
|
|
1160
|
+
return;
|
|
1161
|
+
}),
|
|
1162
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1163
|
+
return;
|
|
1164
|
+
})
|
|
1165
|
+
}));
|
|
1166
|
+
var zNewSessionResponse = object({
|
|
1167
|
+
sessionId: zSessionId,
|
|
1168
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => {
|
|
1169
|
+
return;
|
|
1170
|
+
}),
|
|
1171
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => {
|
|
1172
|
+
return;
|
|
1173
|
+
}),
|
|
1174
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1175
|
+
return;
|
|
1176
|
+
})
|
|
1177
|
+
});
|
|
1178
|
+
var zLoadSessionResponse = object({
|
|
1179
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => {
|
|
1180
|
+
return;
|
|
1181
|
+
}),
|
|
1182
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => {
|
|
1183
|
+
return;
|
|
1184
|
+
}),
|
|
1185
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1186
|
+
return;
|
|
1187
|
+
})
|
|
1188
|
+
});
|
|
1189
|
+
var zSessionInfo = object({
|
|
1190
|
+
sessionId: zSessionId,
|
|
1191
|
+
cwd: string(),
|
|
1192
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1193
|
+
title: defaultOnError(string().nullish(), () => {
|
|
1194
|
+
return;
|
|
1195
|
+
}),
|
|
1196
|
+
updatedAt: defaultOnError(string().nullish(), () => {
|
|
1197
|
+
return;
|
|
1198
|
+
}),
|
|
1199
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1200
|
+
return;
|
|
1201
|
+
})
|
|
1202
|
+
});
|
|
1203
|
+
var zListSessionsResponse = object({
|
|
1204
|
+
sessions: requiredDefaultOnError(vecSkipError(zSessionInfo), () => []),
|
|
1205
|
+
nextCursor: defaultOnError(string().nullish(), () => {
|
|
1206
|
+
return;
|
|
1207
|
+
}),
|
|
1208
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1209
|
+
return;
|
|
1210
|
+
})
|
|
1211
|
+
});
|
|
1212
|
+
var zDeleteSessionResponse = object({
|
|
1213
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1214
|
+
return;
|
|
1215
|
+
})
|
|
1216
|
+
});
|
|
1217
|
+
var zForkSessionResponse = object({
|
|
1218
|
+
sessionId: zSessionId,
|
|
1219
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => {
|
|
1220
|
+
return;
|
|
1221
|
+
}),
|
|
1222
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => {
|
|
1223
|
+
return;
|
|
1224
|
+
}),
|
|
1225
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1226
|
+
return;
|
|
1227
|
+
})
|
|
1228
|
+
});
|
|
1229
|
+
var zResumeSessionResponse = object({
|
|
1230
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => {
|
|
1231
|
+
return;
|
|
1232
|
+
}),
|
|
1233
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => {
|
|
1234
|
+
return;
|
|
1235
|
+
}),
|
|
1236
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1237
|
+
return;
|
|
1238
|
+
})
|
|
1239
|
+
});
|
|
1240
|
+
var zCloseSessionResponse = object({
|
|
1241
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1242
|
+
return;
|
|
1243
|
+
})
|
|
1244
|
+
});
|
|
1245
|
+
var zSetSessionModeResponse = object({
|
|
1246
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1247
|
+
return;
|
|
1248
|
+
})
|
|
1249
|
+
});
|
|
1250
|
+
var zSetSessionConfigOptionResponse = object({
|
|
1251
|
+
configOptions: requiredDefaultOnError(vecSkipError(zSessionConfigOption), () => []),
|
|
1252
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1253
|
+
return;
|
|
1254
|
+
})
|
|
1255
|
+
});
|
|
1256
|
+
var zStopReason = union([
|
|
1257
|
+
literal("end_turn"),
|
|
1258
|
+
literal("max_tokens"),
|
|
1259
|
+
literal("max_turn_requests"),
|
|
1260
|
+
literal("refusal"),
|
|
1261
|
+
literal("cancelled")
|
|
1262
|
+
]);
|
|
1263
|
+
var zUsage = object({
|
|
1264
|
+
totalTokens: number(),
|
|
1265
|
+
inputTokens: number(),
|
|
1266
|
+
outputTokens: number(),
|
|
1267
|
+
thoughtTokens: defaultOnError(number().nullish(), () => {
|
|
1268
|
+
return;
|
|
1269
|
+
}),
|
|
1270
|
+
cachedReadTokens: defaultOnError(number().nullish(), () => {
|
|
1271
|
+
return;
|
|
1272
|
+
}),
|
|
1273
|
+
cachedWriteTokens: defaultOnError(number().nullish(), () => {
|
|
1274
|
+
return;
|
|
1275
|
+
}),
|
|
1276
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1277
|
+
return;
|
|
1278
|
+
})
|
|
1279
|
+
});
|
|
1280
|
+
var zPromptResponse = object({
|
|
1281
|
+
stopReason: zStopReason,
|
|
1282
|
+
usage: defaultOnError(zUsage.nullish(), () => {
|
|
1283
|
+
return;
|
|
1284
|
+
}),
|
|
1285
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1286
|
+
return;
|
|
1287
|
+
})
|
|
1288
|
+
});
|
|
1289
|
+
var zStartNesResponse = object({
|
|
1290
|
+
sessionId: zSessionId,
|
|
1291
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1292
|
+
return;
|
|
1293
|
+
})
|
|
1294
|
+
});
|
|
1295
|
+
var zNesSuggestionId = string();
|
|
1296
|
+
var zPosition = object({
|
|
1297
|
+
line: int().gte(0).max(4294967295, {
|
|
1298
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
1299
|
+
}),
|
|
1300
|
+
character: int().gte(0).max(4294967295, {
|
|
1301
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
1302
|
+
}),
|
|
1303
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1304
|
+
return;
|
|
1305
|
+
})
|
|
1306
|
+
});
|
|
1307
|
+
var zRange = object({
|
|
1308
|
+
start: zPosition,
|
|
1309
|
+
end: zPosition,
|
|
1310
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1311
|
+
return;
|
|
1312
|
+
})
|
|
1313
|
+
});
|
|
1314
|
+
var zNesTextEdit = object({
|
|
1315
|
+
range: zRange,
|
|
1316
|
+
newText: string(),
|
|
1317
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1318
|
+
return;
|
|
1319
|
+
})
|
|
1320
|
+
});
|
|
1321
|
+
var zNesEditSuggestion = object({
|
|
1322
|
+
id: zNesSuggestionId,
|
|
1323
|
+
uri: string(),
|
|
1324
|
+
edits: array(zNesTextEdit),
|
|
1325
|
+
cursorPosition: defaultOnError(zPosition.nullish(), () => {
|
|
1326
|
+
return;
|
|
1327
|
+
}),
|
|
1328
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1329
|
+
return;
|
|
1330
|
+
})
|
|
1331
|
+
});
|
|
1332
|
+
var zNesJumpSuggestion = object({
|
|
1333
|
+
id: zNesSuggestionId,
|
|
1334
|
+
uri: string(),
|
|
1335
|
+
position: zPosition,
|
|
1336
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1337
|
+
return;
|
|
1338
|
+
})
|
|
1339
|
+
});
|
|
1340
|
+
var zNesRenameSuggestion = object({
|
|
1341
|
+
id: zNesSuggestionId,
|
|
1342
|
+
uri: string(),
|
|
1343
|
+
position: zPosition,
|
|
1344
|
+
newName: string(),
|
|
1345
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1346
|
+
return;
|
|
1347
|
+
})
|
|
1348
|
+
});
|
|
1349
|
+
var zNesSearchAndReplaceSuggestion = object({
|
|
1350
|
+
id: zNesSuggestionId,
|
|
1351
|
+
uri: string(),
|
|
1352
|
+
search: string(),
|
|
1353
|
+
replace: string(),
|
|
1354
|
+
isRegex: boolean().nullish(),
|
|
1355
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1356
|
+
return;
|
|
1357
|
+
})
|
|
1358
|
+
});
|
|
1359
|
+
var zNesSuggestion = union([
|
|
1360
|
+
zNesEditSuggestion.and(object({
|
|
1361
|
+
kind: literal("edit")
|
|
1362
|
+
})),
|
|
1363
|
+
zNesJumpSuggestion.and(object({
|
|
1364
|
+
kind: literal("jump")
|
|
1365
|
+
})),
|
|
1366
|
+
zNesRenameSuggestion.and(object({
|
|
1367
|
+
kind: literal("rename")
|
|
1368
|
+
})),
|
|
1369
|
+
zNesSearchAndReplaceSuggestion.and(object({
|
|
1370
|
+
kind: literal("searchAndReplace")
|
|
1371
|
+
}))
|
|
1372
|
+
]);
|
|
1373
|
+
var zSuggestNesResponse = object({
|
|
1374
|
+
suggestions: array(zNesSuggestion),
|
|
1375
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1376
|
+
return;
|
|
1377
|
+
})
|
|
1378
|
+
});
|
|
1379
|
+
var zCloseNesResponse = object({
|
|
1380
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1381
|
+
return;
|
|
1382
|
+
})
|
|
1383
|
+
});
|
|
1384
|
+
var zExtResponse = unknown();
|
|
1385
|
+
var zMessageMcpResponse = unknown();
|
|
1386
|
+
var zErrorCode = union([
|
|
1387
|
+
literal(-32700),
|
|
1388
|
+
literal(-32600),
|
|
1389
|
+
literal(-32601),
|
|
1390
|
+
literal(-32602),
|
|
1391
|
+
literal(-32603),
|
|
1392
|
+
literal(-32800),
|
|
1393
|
+
literal(-32000),
|
|
1394
|
+
literal(-32002),
|
|
1395
|
+
int().min(-2147483648, {
|
|
1396
|
+
error: "Invalid value: Expected int32 to be >= -2147483648"
|
|
1397
|
+
}).max(2147483647, {
|
|
1398
|
+
error: "Invalid value: Expected int32 to be <= 2147483647"
|
|
1399
|
+
})
|
|
1400
|
+
]);
|
|
1401
|
+
var zError = object({
|
|
1402
|
+
code: zErrorCode,
|
|
1403
|
+
message: string(),
|
|
1404
|
+
data: defaultOnError(unknown().optional(), () => {
|
|
1405
|
+
return;
|
|
1406
|
+
})
|
|
1407
|
+
});
|
|
1408
|
+
var zAgentResponse = union([
|
|
1409
|
+
object({
|
|
1410
|
+
id: zRequestId,
|
|
1411
|
+
result: union([
|
|
1412
|
+
zInitializeResponse,
|
|
1413
|
+
zAuthenticateResponse,
|
|
1414
|
+
zListProvidersResponse,
|
|
1415
|
+
zSetProviderResponse,
|
|
1416
|
+
zDisableProviderResponse,
|
|
1417
|
+
zLogoutResponse,
|
|
1418
|
+
zNewSessionResponse,
|
|
1419
|
+
zLoadSessionResponse,
|
|
1420
|
+
zListSessionsResponse,
|
|
1421
|
+
zDeleteSessionResponse,
|
|
1422
|
+
zForkSessionResponse,
|
|
1423
|
+
zResumeSessionResponse,
|
|
1424
|
+
zCloseSessionResponse,
|
|
1425
|
+
zSetSessionModeResponse,
|
|
1426
|
+
zSetSessionConfigOptionResponse,
|
|
1427
|
+
zPromptResponse,
|
|
1428
|
+
zStartNesResponse,
|
|
1429
|
+
zSuggestNesResponse,
|
|
1430
|
+
zCloseNesResponse,
|
|
1431
|
+
zExtResponse,
|
|
1432
|
+
zMessageMcpResponse
|
|
1433
|
+
])
|
|
1434
|
+
}),
|
|
1435
|
+
object({
|
|
1436
|
+
id: zRequestId,
|
|
1437
|
+
error: zError
|
|
1438
|
+
})
|
|
1439
|
+
]);
|
|
1440
|
+
var zMessageId = string();
|
|
1441
|
+
var zContentChunk = object({
|
|
1442
|
+
content: zContentBlock,
|
|
1443
|
+
messageId: defaultOnError(zMessageId.nullish(), () => {
|
|
1444
|
+
return;
|
|
1445
|
+
}),
|
|
1446
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1447
|
+
return;
|
|
1448
|
+
})
|
|
1449
|
+
});
|
|
1450
|
+
var zToolCall = object({
|
|
1451
|
+
toolCallId: zToolCallId,
|
|
1452
|
+
title: string(),
|
|
1453
|
+
name: defaultOnError(string().nullish(), () => {
|
|
1454
|
+
return;
|
|
1455
|
+
}),
|
|
1456
|
+
kind: defaultOnError(zToolKind.optional(), () => {
|
|
1457
|
+
return;
|
|
1458
|
+
}),
|
|
1459
|
+
status: defaultOnError(zToolCallStatus.optional(), () => {
|
|
1460
|
+
return;
|
|
1461
|
+
}),
|
|
1462
|
+
content: defaultOnError(vecSkipError(zToolCallContent).optional(), () => []),
|
|
1463
|
+
locations: defaultOnError(vecSkipError(zToolCallLocation).optional(), () => []),
|
|
1464
|
+
rawInput: defaultOnError(unknown().optional(), () => {
|
|
1465
|
+
return;
|
|
1466
|
+
}),
|
|
1467
|
+
rawOutput: defaultOnError(unknown().optional(), () => {
|
|
1468
|
+
return;
|
|
1469
|
+
}),
|
|
1470
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1471
|
+
return;
|
|
1472
|
+
})
|
|
1473
|
+
});
|
|
1474
|
+
var zPlanEntryPriority = union([
|
|
1475
|
+
literal("high"),
|
|
1476
|
+
literal("medium"),
|
|
1477
|
+
literal("low")
|
|
1478
|
+
]);
|
|
1479
|
+
var zPlanEntryStatus = union([
|
|
1480
|
+
literal("pending"),
|
|
1481
|
+
literal("in_progress"),
|
|
1482
|
+
literal("completed")
|
|
1483
|
+
]);
|
|
1484
|
+
var zPlanEntry = object({
|
|
1485
|
+
content: string(),
|
|
1486
|
+
priority: zPlanEntryPriority,
|
|
1487
|
+
status: zPlanEntryStatus,
|
|
1488
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1489
|
+
return;
|
|
1490
|
+
})
|
|
1491
|
+
});
|
|
1492
|
+
var zPlan = object({
|
|
1493
|
+
entries: requiredDefaultOnError(vecSkipError(zPlanEntry), () => []),
|
|
1494
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1495
|
+
return;
|
|
1496
|
+
})
|
|
1497
|
+
});
|
|
1498
|
+
var zPlanId = string();
|
|
1499
|
+
var zPlanItems = object({
|
|
1500
|
+
planId: zPlanId,
|
|
1501
|
+
entries: requiredDefaultOnError(vecSkipError(zPlanEntry), () => []),
|
|
1502
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1503
|
+
return;
|
|
1504
|
+
})
|
|
1505
|
+
});
|
|
1506
|
+
var zPlanFile = object({
|
|
1507
|
+
planId: zPlanId,
|
|
1508
|
+
uri: string(),
|
|
1509
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1510
|
+
return;
|
|
1511
|
+
})
|
|
1512
|
+
});
|
|
1513
|
+
var zPlanMarkdown = object({
|
|
1514
|
+
planId: zPlanId,
|
|
1515
|
+
content: string(),
|
|
1516
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1517
|
+
return;
|
|
1518
|
+
})
|
|
1519
|
+
});
|
|
1520
|
+
var zPlanUpdateContent = union([
|
|
1521
|
+
zPlanItems.and(object({
|
|
1522
|
+
type: literal("items")
|
|
1523
|
+
})),
|
|
1524
|
+
zPlanFile.and(object({
|
|
1525
|
+
type: literal("file")
|
|
1526
|
+
})),
|
|
1527
|
+
zPlanMarkdown.and(object({
|
|
1528
|
+
type: literal("markdown")
|
|
1529
|
+
}))
|
|
1530
|
+
]);
|
|
1531
|
+
var zPlanUpdate = object({
|
|
1532
|
+
plan: zPlanUpdateContent,
|
|
1533
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1534
|
+
return;
|
|
1535
|
+
})
|
|
1536
|
+
});
|
|
1537
|
+
var zPlanRemoved = object({
|
|
1538
|
+
planId: zPlanId,
|
|
1539
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1540
|
+
return;
|
|
1541
|
+
})
|
|
1542
|
+
});
|
|
1543
|
+
var zUnstructuredCommandInput = object({
|
|
1544
|
+
hint: string(),
|
|
1545
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1546
|
+
return;
|
|
1547
|
+
})
|
|
1548
|
+
});
|
|
1549
|
+
var zAvailableCommandInput = zUnstructuredCommandInput;
|
|
1550
|
+
var zAvailableCommand = object({
|
|
1551
|
+
name: string(),
|
|
1552
|
+
description: string(),
|
|
1553
|
+
input: defaultOnError(zAvailableCommandInput.nullish(), () => {
|
|
1554
|
+
return;
|
|
1555
|
+
}),
|
|
1556
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1557
|
+
return;
|
|
1558
|
+
})
|
|
1559
|
+
});
|
|
1560
|
+
var zAvailableCommandsUpdate = object({
|
|
1561
|
+
availableCommands: requiredDefaultOnError(vecSkipError(zAvailableCommand), () => []),
|
|
1562
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1563
|
+
return;
|
|
1564
|
+
})
|
|
1565
|
+
});
|
|
1566
|
+
var zCurrentModeUpdate = object({
|
|
1567
|
+
currentModeId: zSessionModeId,
|
|
1568
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1569
|
+
return;
|
|
1570
|
+
})
|
|
1571
|
+
});
|
|
1572
|
+
var zConfigOptionUpdate = object({
|
|
1573
|
+
configOptions: requiredDefaultOnError(vecSkipError(zSessionConfigOption), () => []),
|
|
1574
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1575
|
+
return;
|
|
1576
|
+
})
|
|
1577
|
+
});
|
|
1578
|
+
var zSessionInfoUpdate = object({
|
|
1579
|
+
title: defaultOnError(string().nullish(), () => {
|
|
1580
|
+
return;
|
|
1581
|
+
}),
|
|
1582
|
+
updatedAt: defaultOnError(string().nullish(), () => {
|
|
1583
|
+
return;
|
|
1584
|
+
}),
|
|
1585
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1586
|
+
return;
|
|
1587
|
+
})
|
|
1588
|
+
});
|
|
1589
|
+
var zCost = object({
|
|
1590
|
+
amount: number(),
|
|
1591
|
+
currency: string(),
|
|
1592
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1593
|
+
return;
|
|
1594
|
+
})
|
|
1595
|
+
});
|
|
1596
|
+
var zUsageUpdate = object({
|
|
1597
|
+
used: number(),
|
|
1598
|
+
size: number(),
|
|
1599
|
+
cost: defaultOnError(zCost.nullish(), () => {
|
|
1600
|
+
return;
|
|
1601
|
+
}),
|
|
1602
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1603
|
+
return;
|
|
1604
|
+
})
|
|
1605
|
+
});
|
|
1606
|
+
var zCompactionId = string();
|
|
1607
|
+
var zCompactionStatus = union([
|
|
1608
|
+
literal("in_progress"),
|
|
1609
|
+
literal("completed"),
|
|
1610
|
+
literal("failed"),
|
|
1611
|
+
literal("cancelled"),
|
|
1612
|
+
string()
|
|
1613
|
+
]);
|
|
1614
|
+
var zCompactionUpdate = object({
|
|
1615
|
+
compactionId: zCompactionId,
|
|
1616
|
+
status: zCompactionStatus,
|
|
1617
|
+
summary: defaultOnError(vecSkipError(zContentBlock).nullish(), () => {
|
|
1618
|
+
return;
|
|
1619
|
+
}),
|
|
1620
|
+
error: defaultOnError(string().nullish(), () => {
|
|
1621
|
+
return;
|
|
1622
|
+
}),
|
|
1623
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1624
|
+
return;
|
|
1625
|
+
})
|
|
1626
|
+
});
|
|
1627
|
+
var zCompactionSummaryChunk = object({
|
|
1628
|
+
compactionId: zCompactionId,
|
|
1629
|
+
content: zContentBlock,
|
|
1630
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1631
|
+
return;
|
|
1632
|
+
})
|
|
1633
|
+
});
|
|
1634
|
+
var zSessionUpdate = union([
|
|
1635
|
+
zContentChunk.and(object({
|
|
1636
|
+
sessionUpdate: literal("user_message_chunk")
|
|
1637
|
+
})),
|
|
1638
|
+
zContentChunk.and(object({
|
|
1639
|
+
sessionUpdate: literal("agent_message_chunk")
|
|
1640
|
+
})),
|
|
1641
|
+
zContentChunk.and(object({
|
|
1642
|
+
sessionUpdate: literal("agent_thought_chunk")
|
|
1643
|
+
})),
|
|
1644
|
+
zToolCall.and(object({
|
|
1645
|
+
sessionUpdate: literal("tool_call")
|
|
1646
|
+
})),
|
|
1647
|
+
zToolCallUpdate.and(object({
|
|
1648
|
+
sessionUpdate: literal("tool_call_update")
|
|
1649
|
+
})),
|
|
1650
|
+
zPlan.and(object({
|
|
1651
|
+
sessionUpdate: literal("plan")
|
|
1652
|
+
})),
|
|
1653
|
+
zPlanUpdate.and(object({
|
|
1654
|
+
sessionUpdate: literal("plan_update")
|
|
1655
|
+
})),
|
|
1656
|
+
zPlanRemoved.and(object({
|
|
1657
|
+
sessionUpdate: literal("plan_removed")
|
|
1658
|
+
})),
|
|
1659
|
+
zAvailableCommandsUpdate.and(object({
|
|
1660
|
+
sessionUpdate: literal("available_commands_update")
|
|
1661
|
+
})),
|
|
1662
|
+
zCurrentModeUpdate.and(object({
|
|
1663
|
+
sessionUpdate: literal("current_mode_update")
|
|
1664
|
+
})),
|
|
1665
|
+
zConfigOptionUpdate.and(object({
|
|
1666
|
+
sessionUpdate: literal("config_option_update")
|
|
1667
|
+
})),
|
|
1668
|
+
zSessionInfoUpdate.and(object({
|
|
1669
|
+
sessionUpdate: literal("session_info_update")
|
|
1670
|
+
})),
|
|
1671
|
+
zUsageUpdate.and(object({
|
|
1672
|
+
sessionUpdate: literal("usage_update")
|
|
1673
|
+
})),
|
|
1674
|
+
zCompactionUpdate.and(object({
|
|
1675
|
+
sessionUpdate: literal("compaction_update")
|
|
1676
|
+
})),
|
|
1677
|
+
zCompactionSummaryChunk.and(object({
|
|
1678
|
+
sessionUpdate: literal("compaction_summary_chunk")
|
|
1679
|
+
}))
|
|
1680
|
+
]);
|
|
1681
|
+
var zSessionNotification = object({
|
|
1682
|
+
sessionId: zSessionId,
|
|
1683
|
+
update: zSessionUpdate,
|
|
1684
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1685
|
+
return;
|
|
1686
|
+
})
|
|
1687
|
+
});
|
|
1688
|
+
var zCompleteElicitationNotification = object({
|
|
1689
|
+
elicitationId: zElicitationId,
|
|
1690
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1691
|
+
return;
|
|
1692
|
+
})
|
|
1693
|
+
});
|
|
1694
|
+
var zMessageMcpNotification = object({
|
|
1695
|
+
connectionId: zMcpConnectionId,
|
|
1696
|
+
method: string(),
|
|
1697
|
+
params: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1698
|
+
return;
|
|
1699
|
+
}),
|
|
1700
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1701
|
+
return;
|
|
1702
|
+
})
|
|
1703
|
+
});
|
|
1704
|
+
var zExtNotification = unknown();
|
|
1705
|
+
var zAgentNotification = object({
|
|
1706
|
+
method: string(),
|
|
1707
|
+
params: union([
|
|
1708
|
+
zSessionNotification,
|
|
1709
|
+
zCompleteElicitationNotification,
|
|
1710
|
+
zMessageMcpNotification,
|
|
1711
|
+
zExtNotification
|
|
1712
|
+
]).nullish()
|
|
1713
|
+
});
|
|
1714
|
+
var zFileSystemCapabilities = object({
|
|
1715
|
+
readTextFile: defaultOnError(boolean().optional().default(false), () => false),
|
|
1716
|
+
writeTextFile: defaultOnError(boolean().optional().default(false), () => false),
|
|
1717
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1718
|
+
return;
|
|
1719
|
+
})
|
|
1720
|
+
});
|
|
1721
|
+
var zCompactionCapabilities = record(string(), unknown());
|
|
1722
|
+
var zBooleanConfigOptionCapabilities = object({
|
|
1723
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1724
|
+
return;
|
|
1725
|
+
})
|
|
1726
|
+
});
|
|
1727
|
+
var zSessionConfigOptionsCapabilities = object({
|
|
1728
|
+
boolean: defaultOnError(zBooleanConfigOptionCapabilities.nullish(), () => {
|
|
1729
|
+
return;
|
|
1730
|
+
}),
|
|
1731
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1732
|
+
return;
|
|
1733
|
+
})
|
|
1734
|
+
});
|
|
1735
|
+
var zClientSessionCapabilities = object({
|
|
1736
|
+
compaction: defaultOnError(zCompactionCapabilities.nullish(), () => {
|
|
1737
|
+
return;
|
|
1738
|
+
}),
|
|
1739
|
+
configOptions: defaultOnError(zSessionConfigOptionsCapabilities.nullish(), () => {
|
|
1740
|
+
return;
|
|
1741
|
+
}),
|
|
1742
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1743
|
+
return;
|
|
1744
|
+
})
|
|
1745
|
+
});
|
|
1746
|
+
var zPlanCapabilities = object({
|
|
1747
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1748
|
+
return;
|
|
1749
|
+
})
|
|
1750
|
+
});
|
|
1751
|
+
var zAuthCapabilities = object({
|
|
1752
|
+
terminal: defaultOnError(boolean().optional().default(false), () => false),
|
|
1753
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1754
|
+
return;
|
|
1755
|
+
})
|
|
1756
|
+
});
|
|
1757
|
+
var zElicitationFormCapabilities = object({
|
|
1758
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1759
|
+
return;
|
|
1760
|
+
})
|
|
1761
|
+
});
|
|
1762
|
+
var zElicitationUrlCapabilities = object({
|
|
1763
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1764
|
+
return;
|
|
1765
|
+
})
|
|
1766
|
+
});
|
|
1767
|
+
var zElicitationCapabilities = object({
|
|
1768
|
+
form: defaultOnError(zElicitationFormCapabilities.nullish(), () => {
|
|
1769
|
+
return;
|
|
1770
|
+
}),
|
|
1771
|
+
url: defaultOnError(zElicitationUrlCapabilities.nullish(), () => {
|
|
1772
|
+
return;
|
|
1773
|
+
}),
|
|
1774
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1775
|
+
return;
|
|
1776
|
+
})
|
|
1777
|
+
});
|
|
1778
|
+
var zNesJumpCapabilities = object({
|
|
1779
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1780
|
+
return;
|
|
1781
|
+
})
|
|
1782
|
+
});
|
|
1783
|
+
var zNesRenameCapabilities = object({
|
|
1784
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1785
|
+
return;
|
|
1786
|
+
})
|
|
1787
|
+
});
|
|
1788
|
+
var zNesSearchAndReplaceCapabilities = object({
|
|
1789
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1790
|
+
return;
|
|
1791
|
+
})
|
|
1792
|
+
});
|
|
1793
|
+
var zClientNesCapabilities = object({
|
|
1794
|
+
jump: defaultOnError(zNesJumpCapabilities.nullish(), () => {
|
|
1795
|
+
return;
|
|
1796
|
+
}),
|
|
1797
|
+
rename: defaultOnError(zNesRenameCapabilities.nullish(), () => {
|
|
1798
|
+
return;
|
|
1799
|
+
}),
|
|
1800
|
+
searchAndReplace: defaultOnError(zNesSearchAndReplaceCapabilities.nullish(), () => {
|
|
1801
|
+
return;
|
|
1802
|
+
}),
|
|
1803
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1804
|
+
return;
|
|
1805
|
+
})
|
|
1806
|
+
});
|
|
1807
|
+
var zClientCapabilities = object({
|
|
1808
|
+
fs: defaultOnError(zFileSystemCapabilities.optional().default({ readTextFile: false, writeTextFile: false }), () => ({ readTextFile: false, writeTextFile: false })),
|
|
1809
|
+
terminal: defaultOnError(boolean().optional().default(false), () => false),
|
|
1810
|
+
session: defaultOnError(zClientSessionCapabilities.nullish(), () => {
|
|
1811
|
+
return;
|
|
1812
|
+
}),
|
|
1813
|
+
plan: defaultOnError(zPlanCapabilities.nullish(), () => {
|
|
1814
|
+
return;
|
|
1815
|
+
}),
|
|
1816
|
+
auth: defaultOnError(zAuthCapabilities.optional().default({ terminal: false }), () => ({ terminal: false })),
|
|
1817
|
+
elicitation: defaultOnError(zElicitationCapabilities.nullish(), () => {
|
|
1818
|
+
return;
|
|
1819
|
+
}),
|
|
1820
|
+
nes: defaultOnError(zClientNesCapabilities.nullish(), () => {
|
|
1821
|
+
return;
|
|
1822
|
+
}),
|
|
1823
|
+
positionEncodings: defaultOnError(vecSkipError(zPositionEncodingKind).optional(), () => []),
|
|
1824
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1825
|
+
return;
|
|
1826
|
+
})
|
|
1827
|
+
});
|
|
1828
|
+
var zInitializeRequest = object({
|
|
1829
|
+
protocolVersion: zProtocolVersion,
|
|
1830
|
+
clientCapabilities: defaultOnError(zClientCapabilities.optional().default({
|
|
1831
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
1832
|
+
terminal: false,
|
|
1833
|
+
auth: { terminal: false }
|
|
1834
|
+
}), () => ({
|
|
1835
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
1836
|
+
terminal: false,
|
|
1837
|
+
auth: { terminal: false }
|
|
1838
|
+
})),
|
|
1839
|
+
clientInfo: defaultOnError(zImplementation.nullish(), () => {
|
|
1840
|
+
return;
|
|
1841
|
+
}),
|
|
1842
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1843
|
+
return;
|
|
1844
|
+
})
|
|
1845
|
+
});
|
|
1846
|
+
var zAuthenticateRequest = object({
|
|
1847
|
+
methodId: zAuthMethodId,
|
|
1848
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1849
|
+
return;
|
|
1850
|
+
})
|
|
1851
|
+
});
|
|
1852
|
+
var zListProvidersRequest = object({
|
|
1853
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1854
|
+
return;
|
|
1855
|
+
})
|
|
1856
|
+
});
|
|
1857
|
+
var zSetProviderRequest = object({
|
|
1858
|
+
providerId: zProviderId,
|
|
1859
|
+
apiType: zLlmProtocol,
|
|
1860
|
+
baseUrl: string(),
|
|
1861
|
+
headers: record(string(), string()).optional(),
|
|
1862
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1863
|
+
return;
|
|
1864
|
+
})
|
|
1865
|
+
});
|
|
1866
|
+
var zDisableProviderRequest = object({
|
|
1867
|
+
providerId: zProviderId,
|
|
1868
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1869
|
+
return;
|
|
1870
|
+
})
|
|
1871
|
+
});
|
|
1872
|
+
var zLogoutRequest = object({
|
|
1873
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1874
|
+
return;
|
|
1875
|
+
})
|
|
1876
|
+
});
|
|
1877
|
+
var zHttpHeader = object({
|
|
1878
|
+
name: string(),
|
|
1879
|
+
value: string(),
|
|
1880
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1881
|
+
return;
|
|
1882
|
+
})
|
|
1883
|
+
});
|
|
1884
|
+
var zMcpServerHttp = object({
|
|
1885
|
+
name: string(),
|
|
1886
|
+
url: string(),
|
|
1887
|
+
headers: array(zHttpHeader),
|
|
1888
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1889
|
+
return;
|
|
1890
|
+
})
|
|
1891
|
+
});
|
|
1892
|
+
var zMcpServerSse = object({
|
|
1893
|
+
name: string(),
|
|
1894
|
+
url: string(),
|
|
1895
|
+
headers: array(zHttpHeader),
|
|
1896
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1897
|
+
return;
|
|
1898
|
+
})
|
|
1899
|
+
});
|
|
1900
|
+
var zMcpServerAcp = object({
|
|
1901
|
+
name: string(),
|
|
1902
|
+
serverId: zMcpServerAcpId,
|
|
1903
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1904
|
+
return;
|
|
1905
|
+
})
|
|
1906
|
+
});
|
|
1907
|
+
var zMcpServerStdio = object({
|
|
1908
|
+
name: string(),
|
|
1909
|
+
command: string(),
|
|
1910
|
+
args: array(string()),
|
|
1911
|
+
env: array(zEnvVariable),
|
|
1912
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1913
|
+
return;
|
|
1914
|
+
})
|
|
1915
|
+
});
|
|
1916
|
+
var zMcpServer = union([
|
|
1917
|
+
zMcpServerHttp.and(object({
|
|
1918
|
+
type: literal("http")
|
|
1919
|
+
})),
|
|
1920
|
+
zMcpServerSse.and(object({
|
|
1921
|
+
type: literal("sse")
|
|
1922
|
+
})),
|
|
1923
|
+
zMcpServerAcp.and(object({
|
|
1924
|
+
type: literal("acp")
|
|
1925
|
+
})),
|
|
1926
|
+
zMcpServerStdio
|
|
1927
|
+
]);
|
|
1928
|
+
var zNewSessionRequest = object({
|
|
1929
|
+
cwd: string(),
|
|
1930
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1931
|
+
mcpServers: requiredDefaultOnError(vecSkipError(zMcpServer), () => []),
|
|
1932
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1933
|
+
return;
|
|
1934
|
+
})
|
|
1935
|
+
});
|
|
1936
|
+
var zLoadSessionRequest = object({
|
|
1937
|
+
mcpServers: requiredDefaultOnError(vecSkipError(zMcpServer), () => []),
|
|
1938
|
+
cwd: string(),
|
|
1939
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1940
|
+
sessionId: zSessionId,
|
|
1941
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1942
|
+
return;
|
|
1943
|
+
})
|
|
1944
|
+
});
|
|
1945
|
+
var zListSessionsRequest = object({
|
|
1946
|
+
cwd: string().nullish(),
|
|
1947
|
+
cursor: string().nullish(),
|
|
1948
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1949
|
+
return;
|
|
1950
|
+
})
|
|
1951
|
+
});
|
|
1952
|
+
var zDeleteSessionRequest = object({
|
|
1953
|
+
sessionId: zSessionId,
|
|
1954
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1955
|
+
return;
|
|
1956
|
+
})
|
|
1957
|
+
});
|
|
1958
|
+
var zForkSessionRequest = object({
|
|
1959
|
+
sessionId: zSessionId,
|
|
1960
|
+
cwd: string(),
|
|
1961
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1962
|
+
mcpServers: defaultOnError(vecSkipError(zMcpServer).optional(), () => []),
|
|
1963
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1964
|
+
return;
|
|
1965
|
+
})
|
|
1966
|
+
});
|
|
1967
|
+
var zResumeSessionRequest = object({
|
|
1968
|
+
sessionId: zSessionId,
|
|
1969
|
+
cwd: string(),
|
|
1970
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1971
|
+
mcpServers: defaultOnError(vecSkipError(zMcpServer).optional(), () => []),
|
|
1972
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1973
|
+
return;
|
|
1974
|
+
})
|
|
1975
|
+
});
|
|
1976
|
+
var zCloseSessionRequest = object({
|
|
1977
|
+
sessionId: zSessionId,
|
|
1978
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1979
|
+
return;
|
|
1980
|
+
})
|
|
1981
|
+
});
|
|
1982
|
+
var zSetSessionModeRequest = object({
|
|
1983
|
+
sessionId: zSessionId,
|
|
1984
|
+
modeId: zSessionModeId,
|
|
1985
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
1986
|
+
return;
|
|
1987
|
+
})
|
|
1988
|
+
});
|
|
1989
|
+
var zSetSessionConfigOptionRequest = intersection(union([
|
|
1990
|
+
object({
|
|
1991
|
+
value: boolean(),
|
|
1992
|
+
type: literal("boolean")
|
|
1993
|
+
}),
|
|
1994
|
+
object({
|
|
1995
|
+
value: zSessionConfigValueId
|
|
1996
|
+
})
|
|
1997
|
+
]), object({
|
|
1998
|
+
sessionId: zSessionId,
|
|
1999
|
+
configId: zSessionConfigId,
|
|
2000
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2001
|
+
return;
|
|
2002
|
+
})
|
|
2003
|
+
}));
|
|
2004
|
+
var zPromptRequest = object({
|
|
2005
|
+
sessionId: zSessionId,
|
|
2006
|
+
prompt: array(zContentBlock),
|
|
2007
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2008
|
+
return;
|
|
2009
|
+
})
|
|
2010
|
+
});
|
|
2011
|
+
var zWorkspaceFolder = object({
|
|
2012
|
+
uri: string(),
|
|
2013
|
+
name: string(),
|
|
2014
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2015
|
+
return;
|
|
2016
|
+
})
|
|
2017
|
+
});
|
|
2018
|
+
var zNesRepository = object({
|
|
2019
|
+
name: string(),
|
|
2020
|
+
owner: string(),
|
|
2021
|
+
remoteUrl: string(),
|
|
2022
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2023
|
+
return;
|
|
2024
|
+
})
|
|
2025
|
+
});
|
|
2026
|
+
var zStartNesRequest = object({
|
|
2027
|
+
workspaceUri: defaultOnError(string().nullish(), () => {
|
|
2028
|
+
return;
|
|
2029
|
+
}),
|
|
2030
|
+
workspaceFolders: array(zWorkspaceFolder).nullish(),
|
|
2031
|
+
repository: defaultOnError(zNesRepository.nullish(), () => {
|
|
2032
|
+
return;
|
|
2033
|
+
}),
|
|
2034
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2035
|
+
return;
|
|
2036
|
+
})
|
|
2037
|
+
});
|
|
2038
|
+
var zNesTriggerKind = union([
|
|
2039
|
+
literal("automatic"),
|
|
2040
|
+
literal("diagnostic"),
|
|
2041
|
+
literal("manual")
|
|
2042
|
+
]);
|
|
2043
|
+
var zNesRecentFile = object({
|
|
2044
|
+
uri: string(),
|
|
2045
|
+
languageId: string(),
|
|
2046
|
+
text: string(),
|
|
2047
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2048
|
+
return;
|
|
2049
|
+
})
|
|
2050
|
+
});
|
|
2051
|
+
var zNesExcerpt = object({
|
|
2052
|
+
startLine: int().gte(0).max(4294967295, {
|
|
2053
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
2054
|
+
}),
|
|
2055
|
+
endLine: int().gte(0).max(4294967295, {
|
|
2056
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
2057
|
+
}),
|
|
2058
|
+
text: string(),
|
|
2059
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2060
|
+
return;
|
|
2061
|
+
})
|
|
2062
|
+
});
|
|
2063
|
+
var zNesRelatedSnippet = object({
|
|
2064
|
+
uri: string(),
|
|
2065
|
+
excerpts: array(zNesExcerpt),
|
|
2066
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2067
|
+
return;
|
|
2068
|
+
})
|
|
2069
|
+
});
|
|
2070
|
+
var zNesEditHistoryEntry = object({
|
|
2071
|
+
uri: string(),
|
|
2072
|
+
diff: string(),
|
|
2073
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2074
|
+
return;
|
|
2075
|
+
})
|
|
2076
|
+
});
|
|
2077
|
+
var zNesUserAction = object({
|
|
2078
|
+
action: string(),
|
|
2079
|
+
uri: string(),
|
|
2080
|
+
position: zPosition,
|
|
2081
|
+
timestampMs: number(),
|
|
2082
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2083
|
+
return;
|
|
2084
|
+
})
|
|
2085
|
+
});
|
|
2086
|
+
var zNesOpenFile = object({
|
|
2087
|
+
uri: string(),
|
|
2088
|
+
languageId: string(),
|
|
2089
|
+
visibleRange: defaultOnError(zRange.nullish(), () => {
|
|
2090
|
+
return;
|
|
2091
|
+
}),
|
|
2092
|
+
lastFocusedMs: defaultOnError(number().nullish(), () => {
|
|
2093
|
+
return;
|
|
2094
|
+
}),
|
|
2095
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2096
|
+
return;
|
|
2097
|
+
})
|
|
2098
|
+
});
|
|
2099
|
+
var zNesDiagnosticSeverity = union([
|
|
2100
|
+
literal("error"),
|
|
2101
|
+
literal("warning"),
|
|
2102
|
+
literal("information"),
|
|
2103
|
+
literal("hint")
|
|
2104
|
+
]);
|
|
2105
|
+
var zNesDiagnostic = object({
|
|
2106
|
+
uri: string(),
|
|
2107
|
+
range: zRange,
|
|
2108
|
+
severity: zNesDiagnosticSeverity,
|
|
2109
|
+
message: string(),
|
|
2110
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2111
|
+
return;
|
|
2112
|
+
})
|
|
2113
|
+
});
|
|
2114
|
+
var zNesSuggestContext = object({
|
|
2115
|
+
recentFiles: array(zNesRecentFile).nullish(),
|
|
2116
|
+
relatedSnippets: array(zNesRelatedSnippet).nullish(),
|
|
2117
|
+
editHistory: array(zNesEditHistoryEntry).nullish(),
|
|
2118
|
+
userActions: array(zNesUserAction).nullish(),
|
|
2119
|
+
openFiles: array(zNesOpenFile).nullish(),
|
|
2120
|
+
diagnostics: array(zNesDiagnostic).nullish(),
|
|
2121
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2122
|
+
return;
|
|
2123
|
+
})
|
|
2124
|
+
});
|
|
2125
|
+
var zSuggestNesRequest = object({
|
|
2126
|
+
sessionId: zSessionId,
|
|
2127
|
+
uri: string(),
|
|
2128
|
+
version: number(),
|
|
2129
|
+
position: zPosition,
|
|
2130
|
+
selection: zRange.nullish(),
|
|
2131
|
+
triggerKind: zNesTriggerKind,
|
|
2132
|
+
context: zNesSuggestContext.nullish(),
|
|
2133
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2134
|
+
return;
|
|
2135
|
+
})
|
|
2136
|
+
});
|
|
2137
|
+
var zCloseNesRequest = object({
|
|
2138
|
+
sessionId: zSessionId,
|
|
2139
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2140
|
+
return;
|
|
2141
|
+
})
|
|
2142
|
+
});
|
|
2143
|
+
var zClientRequest = object({
|
|
2144
|
+
id: zRequestId,
|
|
2145
|
+
method: string(),
|
|
2146
|
+
params: union([
|
|
2147
|
+
zInitializeRequest,
|
|
2148
|
+
zAuthenticateRequest,
|
|
2149
|
+
zListProvidersRequest,
|
|
2150
|
+
zSetProviderRequest,
|
|
2151
|
+
zDisableProviderRequest,
|
|
2152
|
+
zLogoutRequest,
|
|
2153
|
+
zNewSessionRequest,
|
|
2154
|
+
zLoadSessionRequest,
|
|
2155
|
+
zListSessionsRequest,
|
|
2156
|
+
zDeleteSessionRequest,
|
|
2157
|
+
zForkSessionRequest,
|
|
2158
|
+
zResumeSessionRequest,
|
|
2159
|
+
zCloseSessionRequest,
|
|
2160
|
+
zSetSessionModeRequest,
|
|
2161
|
+
zSetSessionConfigOptionRequest,
|
|
2162
|
+
zPromptRequest,
|
|
2163
|
+
zStartNesRequest,
|
|
2164
|
+
zSuggestNesRequest,
|
|
2165
|
+
zCloseNesRequest,
|
|
2166
|
+
zMessageMcpRequest,
|
|
2167
|
+
zExtRequest
|
|
2168
|
+
]).nullish()
|
|
2169
|
+
});
|
|
2170
|
+
var zWriteTextFileResponse = object({
|
|
2171
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2172
|
+
return;
|
|
2173
|
+
})
|
|
2174
|
+
});
|
|
2175
|
+
var zReadTextFileResponse = object({
|
|
2176
|
+
content: string(),
|
|
2177
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2178
|
+
return;
|
|
2179
|
+
})
|
|
2180
|
+
});
|
|
2181
|
+
var zSelectedPermissionOutcome = object({
|
|
2182
|
+
optionId: zPermissionOptionId,
|
|
2183
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2184
|
+
return;
|
|
2185
|
+
})
|
|
2186
|
+
});
|
|
2187
|
+
var zRequestPermissionOutcome = union([
|
|
2188
|
+
object({
|
|
2189
|
+
outcome: literal("cancelled")
|
|
2190
|
+
}),
|
|
2191
|
+
zSelectedPermissionOutcome.and(object({
|
|
2192
|
+
outcome: literal("selected")
|
|
2193
|
+
}))
|
|
2194
|
+
]);
|
|
2195
|
+
var zRequestPermissionResponse = object({
|
|
2196
|
+
outcome: zRequestPermissionOutcome,
|
|
2197
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2198
|
+
return;
|
|
2199
|
+
})
|
|
2200
|
+
});
|
|
2201
|
+
var zCreateTerminalResponse = object({
|
|
2202
|
+
terminalId: zTerminalId,
|
|
2203
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2204
|
+
return;
|
|
2205
|
+
})
|
|
2206
|
+
});
|
|
2207
|
+
var zTerminalExitStatus = object({
|
|
2208
|
+
exitCode: defaultOnError(int().gte(0).max(4294967295, {
|
|
2209
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
2210
|
+
}).nullish(), () => {
|
|
2211
|
+
return;
|
|
2212
|
+
}),
|
|
2213
|
+
signal: defaultOnError(string().nullish(), () => {
|
|
2214
|
+
return;
|
|
2215
|
+
}),
|
|
2216
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2217
|
+
return;
|
|
2218
|
+
})
|
|
2219
|
+
});
|
|
2220
|
+
var zTerminalOutputResponse = object({
|
|
2221
|
+
output: string(),
|
|
2222
|
+
truncated: boolean(),
|
|
2223
|
+
exitStatus: defaultOnError(zTerminalExitStatus.nullish(), () => {
|
|
2224
|
+
return;
|
|
2225
|
+
}),
|
|
2226
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2227
|
+
return;
|
|
2228
|
+
})
|
|
2229
|
+
});
|
|
2230
|
+
var zReleaseTerminalResponse = object({
|
|
2231
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2232
|
+
return;
|
|
2233
|
+
})
|
|
2234
|
+
});
|
|
2235
|
+
var zWaitForTerminalExitResponse = object({
|
|
2236
|
+
exitCode: defaultOnError(int().gte(0).max(4294967295, {
|
|
2237
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
2238
|
+
}).nullish(), () => {
|
|
2239
|
+
return;
|
|
2240
|
+
}),
|
|
2241
|
+
signal: defaultOnError(string().nullish(), () => {
|
|
2242
|
+
return;
|
|
2243
|
+
}),
|
|
2244
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2245
|
+
return;
|
|
2246
|
+
})
|
|
2247
|
+
});
|
|
2248
|
+
var zKillTerminalResponse = object({
|
|
2249
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2250
|
+
return;
|
|
2251
|
+
})
|
|
2252
|
+
});
|
|
2253
|
+
var zElicitationContentValue = union([
|
|
2254
|
+
string(),
|
|
2255
|
+
number(),
|
|
2256
|
+
number(),
|
|
2257
|
+
boolean(),
|
|
2258
|
+
array(string())
|
|
2259
|
+
]);
|
|
2260
|
+
var zElicitationAcceptAction = object({
|
|
2261
|
+
content: record(string(), zElicitationContentValue).nullish()
|
|
2262
|
+
});
|
|
2263
|
+
var zCreateElicitationResponse = preserveCustomPayload(intersection(union([
|
|
2264
|
+
zElicitationAcceptAction.and(object({
|
|
2265
|
+
action: literal("accept")
|
|
2266
|
+
})),
|
|
2267
|
+
object({
|
|
2268
|
+
action: literal("decline")
|
|
2269
|
+
}),
|
|
2270
|
+
object({
|
|
2271
|
+
action: literal("cancel")
|
|
2272
|
+
}),
|
|
2273
|
+
excludeKnownTags(object({
|
|
2274
|
+
action: string()
|
|
2275
|
+
}), "action", ["accept", "cancel", "decline"])
|
|
2276
|
+
]), object({
|
|
2277
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2278
|
+
return;
|
|
2279
|
+
})
|
|
2280
|
+
})), "action", ["accept", "cancel", "decline"]);
|
|
2281
|
+
var zConnectMcpResponse = object({
|
|
2282
|
+
connectionId: zMcpConnectionId,
|
|
2283
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2284
|
+
return;
|
|
2285
|
+
})
|
|
2286
|
+
});
|
|
2287
|
+
var zDisconnectMcpResponse = object({
|
|
2288
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2289
|
+
return;
|
|
2290
|
+
})
|
|
2291
|
+
});
|
|
2292
|
+
var zClientResponse = union([
|
|
2293
|
+
object({
|
|
2294
|
+
id: zRequestId,
|
|
2295
|
+
result: union([
|
|
2296
|
+
zWriteTextFileResponse,
|
|
2297
|
+
zReadTextFileResponse,
|
|
2298
|
+
zRequestPermissionResponse,
|
|
2299
|
+
zCreateTerminalResponse,
|
|
2300
|
+
zTerminalOutputResponse,
|
|
2301
|
+
zReleaseTerminalResponse,
|
|
2302
|
+
zWaitForTerminalExitResponse,
|
|
2303
|
+
zKillTerminalResponse,
|
|
2304
|
+
zCreateElicitationResponse,
|
|
2305
|
+
zConnectMcpResponse,
|
|
2306
|
+
zDisconnectMcpResponse,
|
|
2307
|
+
zMessageMcpResponse,
|
|
2308
|
+
zExtResponse
|
|
2309
|
+
])
|
|
2310
|
+
}),
|
|
2311
|
+
object({
|
|
2312
|
+
id: zRequestId,
|
|
2313
|
+
error: zError
|
|
2314
|
+
})
|
|
2315
|
+
]);
|
|
2316
|
+
var zCancelNotification = object({
|
|
2317
|
+
sessionId: zSessionId,
|
|
2318
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2319
|
+
return;
|
|
2320
|
+
})
|
|
2321
|
+
});
|
|
2322
|
+
var zDidOpenDocumentNotification = object({
|
|
2323
|
+
sessionId: zSessionId,
|
|
2324
|
+
uri: string(),
|
|
2325
|
+
languageId: string(),
|
|
2326
|
+
version: number(),
|
|
2327
|
+
text: string(),
|
|
2328
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2329
|
+
return;
|
|
2330
|
+
})
|
|
2331
|
+
});
|
|
2332
|
+
var zTextDocumentContentChangeEvent = object({
|
|
2333
|
+
range: zRange.nullish(),
|
|
2334
|
+
text: string(),
|
|
2335
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2336
|
+
return;
|
|
2337
|
+
})
|
|
2338
|
+
});
|
|
2339
|
+
var zDidChangeDocumentNotification = object({
|
|
2340
|
+
sessionId: zSessionId,
|
|
2341
|
+
uri: string(),
|
|
2342
|
+
version: number(),
|
|
2343
|
+
contentChanges: requiredDefaultOnError(vecSkipError(zTextDocumentContentChangeEvent), () => []),
|
|
2344
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2345
|
+
return;
|
|
2346
|
+
})
|
|
2347
|
+
});
|
|
2348
|
+
var zDidCloseDocumentNotification = object({
|
|
2349
|
+
sessionId: zSessionId,
|
|
2350
|
+
uri: string(),
|
|
2351
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2352
|
+
return;
|
|
2353
|
+
})
|
|
2354
|
+
});
|
|
2355
|
+
var zDidSaveDocumentNotification = object({
|
|
2356
|
+
sessionId: zSessionId,
|
|
2357
|
+
uri: string(),
|
|
2358
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2359
|
+
return;
|
|
2360
|
+
})
|
|
2361
|
+
});
|
|
2362
|
+
var zDidFocusDocumentNotification = object({
|
|
2363
|
+
sessionId: zSessionId,
|
|
2364
|
+
uri: string(),
|
|
2365
|
+
version: number(),
|
|
2366
|
+
position: zPosition,
|
|
2367
|
+
visibleRange: zRange,
|
|
2368
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2369
|
+
return;
|
|
2370
|
+
})
|
|
2371
|
+
});
|
|
2372
|
+
var zAcceptNesNotification = object({
|
|
2373
|
+
sessionId: zSessionId,
|
|
2374
|
+
id: zNesSuggestionId,
|
|
2375
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2376
|
+
return;
|
|
2377
|
+
})
|
|
2378
|
+
});
|
|
2379
|
+
var zNesRejectReason = union([
|
|
2380
|
+
literal("rejected"),
|
|
2381
|
+
literal("ignored"),
|
|
2382
|
+
literal("replaced"),
|
|
2383
|
+
literal("cancelled")
|
|
2384
|
+
]);
|
|
2385
|
+
var zRejectNesNotification = object({
|
|
2386
|
+
sessionId: zSessionId,
|
|
2387
|
+
id: zNesSuggestionId,
|
|
2388
|
+
reason: defaultOnError(zNesRejectReason.nullish(), () => {
|
|
2389
|
+
return;
|
|
2390
|
+
}),
|
|
2391
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2392
|
+
return;
|
|
2393
|
+
})
|
|
2394
|
+
});
|
|
2395
|
+
var zClientNotification = object({
|
|
2396
|
+
method: string(),
|
|
2397
|
+
params: union([
|
|
2398
|
+
zCancelNotification,
|
|
2399
|
+
zDidOpenDocumentNotification,
|
|
2400
|
+
zDidChangeDocumentNotification,
|
|
2401
|
+
zDidCloseDocumentNotification,
|
|
2402
|
+
zDidSaveDocumentNotification,
|
|
2403
|
+
zDidFocusDocumentNotification,
|
|
2404
|
+
zAcceptNesNotification,
|
|
2405
|
+
zRejectNesNotification,
|
|
2406
|
+
zMessageMcpNotification,
|
|
2407
|
+
zExtNotification
|
|
2408
|
+
]).nullish()
|
|
2409
|
+
});
|
|
2410
|
+
var zCancelRequestNotification = object({
|
|
2411
|
+
requestId: zRequestId,
|
|
2412
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => {
|
|
2413
|
+
return;
|
|
2414
|
+
})
|
|
2415
|
+
});
|
|
2416
|
+
|
|
2417
|
+
// node_modules/@agentclientprotocol/sdk/dist/jsonrpc.js
|
|
2418
|
+
var CANCEL_REQUEST_METHOD = "$/cancel_request";
|
|
2419
|
+
function isRequestMessage(value) {
|
|
2420
|
+
return isJsonRpcEnvelope(value) && "id" in value && typeof value["method"] === "string" && isJsonRpcId(value["id"]);
|
|
2421
|
+
}
|
|
2422
|
+
function isResponseMessage(value) {
|
|
2423
|
+
if (!isJsonRpcEnvelope(value) || "method" in value) {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
if (!("id" in value) || !isJsonRpcId(value["id"])) {
|
|
2427
|
+
return false;
|
|
2428
|
+
}
|
|
2429
|
+
const hasResult = Object.hasOwn(value, "result");
|
|
2430
|
+
const hasError = Object.hasOwn(value, "error");
|
|
2431
|
+
if (hasResult === hasError) {
|
|
2432
|
+
return false;
|
|
2433
|
+
}
|
|
2434
|
+
return !hasError || isErrorResponse(value["error"]);
|
|
2435
|
+
}
|
|
2436
|
+
function isNotificationMessage(value) {
|
|
2437
|
+
return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
|
|
2438
|
+
}
|
|
2439
|
+
function isRecord(value) {
|
|
2440
|
+
return typeof value === "object" && value !== null;
|
|
2441
|
+
}
|
|
2442
|
+
function isJsonRpcEnvelope(value) {
|
|
2443
|
+
return isRecord(value) && value["jsonrpc"] === "2.0";
|
|
2444
|
+
}
|
|
2445
|
+
function isJsonRpcId(value) {
|
|
2446
|
+
return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
2447
|
+
}
|
|
2448
|
+
function isResponseShapedMessage(value) {
|
|
2449
|
+
return isRecord(value) && !("method" in value) && (("id" in value) || ("result" in value) || ("error" in value));
|
|
2450
|
+
}
|
|
2451
|
+
function isResponseBatch(batch) {
|
|
2452
|
+
let hasValidCall = false;
|
|
2453
|
+
let hasValidResponse = false;
|
|
2454
|
+
let hasCallShape = false;
|
|
2455
|
+
let hasResponseShape = false;
|
|
2456
|
+
for (const entry of batch) {
|
|
2457
|
+
hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
|
|
2458
|
+
hasValidResponse ||= isResponseMessage(entry);
|
|
2459
|
+
if (!isRecord(entry)) {
|
|
2460
|
+
continue;
|
|
2461
|
+
}
|
|
2462
|
+
hasCallShape ||= "method" in entry;
|
|
2463
|
+
hasResponseShape ||= "result" in entry || "error" in entry;
|
|
2464
|
+
}
|
|
2465
|
+
if (hasValidCall) {
|
|
2466
|
+
return false;
|
|
2467
|
+
}
|
|
2468
|
+
if (hasValidResponse) {
|
|
2469
|
+
return true;
|
|
2470
|
+
}
|
|
2471
|
+
return hasResponseShape && !hasCallShape;
|
|
2472
|
+
}
|
|
2473
|
+
function cancelRequestId(params) {
|
|
2474
|
+
if (!isRecord(params) || !isJsonRpcId(params["requestId"])) {
|
|
2475
|
+
return;
|
|
2476
|
+
}
|
|
2477
|
+
return params["requestId"];
|
|
2478
|
+
}
|
|
2479
|
+
function isErrorResponse(value) {
|
|
2480
|
+
return isRecord(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
|
|
2481
|
+
}
|
|
2482
|
+
var Handled = {
|
|
2483
|
+
yes() {
|
|
2484
|
+
return { handled: true };
|
|
2485
|
+
},
|
|
2486
|
+
no(message, retry = false) {
|
|
2487
|
+
return { handled: false, message, retry };
|
|
2488
|
+
}
|
|
2489
|
+
};
|
|
2490
|
+
function rejectedPromise(error) {
|
|
2491
|
+
const promise = Promise.reject(error);
|
|
2492
|
+
promise.catch(() => {});
|
|
2493
|
+
return promise;
|
|
2494
|
+
}
|
|
2495
|
+
function errorDetails(error) {
|
|
2496
|
+
if (error instanceof Error) {
|
|
2497
|
+
return error.message;
|
|
2498
|
+
}
|
|
2499
|
+
if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
|
|
2500
|
+
return error.message;
|
|
2501
|
+
}
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
function isZodError(error) {
|
|
2505
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === "ZodError" && "issues" in error && Array.isArray(error.issues) && "format" in error && typeof error.format === "function";
|
|
2506
|
+
}
|
|
2507
|
+
function errorToResult(error) {
|
|
2508
|
+
if (error instanceof RequestError) {
|
|
2509
|
+
return error.toResult();
|
|
2510
|
+
}
|
|
2511
|
+
if (isZodError(error)) {
|
|
2512
|
+
return RequestError.invalidParams(error.format()).toResult();
|
|
2513
|
+
}
|
|
2514
|
+
const details = errorDetails(error);
|
|
2515
|
+
try {
|
|
2516
|
+
return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
|
|
2517
|
+
} catch {
|
|
2518
|
+
return RequestError.internalError({ details }).toResult();
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
function requestCancelledError(reason) {
|
|
2522
|
+
if (reason instanceof RequestError && reason.code === -32800) {
|
|
2523
|
+
return reason;
|
|
2524
|
+
}
|
|
2525
|
+
return RequestError.requestCancelled(reason);
|
|
2526
|
+
}
|
|
2527
|
+
function errorToRequestResult(error, signal) {
|
|
2528
|
+
const requestCancelled = abortErrorToRequestCancelled(error, signal);
|
|
2529
|
+
return requestCancelled ? requestCancelled.toResult() : errorToResult(error);
|
|
2530
|
+
}
|
|
2531
|
+
function abortErrorToRequestCancelled(error, signal) {
|
|
2532
|
+
if (!signal.aborted || !isAbortError(error)) {
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2535
|
+
return requestCancelledError(signal.reason);
|
|
2536
|
+
}
|
|
2537
|
+
function isAbortError(error) {
|
|
2538
|
+
if (typeof error !== "object" || error === null) {
|
|
2539
|
+
return false;
|
|
2540
|
+
}
|
|
2541
|
+
const maybeAbortError = error;
|
|
2542
|
+
return maybeAbortError.name === "AbortError" || maybeAbortError.code === "ABORT_ERR";
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
class RequestResponder {
|
|
2546
|
+
id;
|
|
2547
|
+
sendResult;
|
|
2548
|
+
signal;
|
|
2549
|
+
finishRequest;
|
|
2550
|
+
didRespond = false;
|
|
2551
|
+
constructor(id, sendResult, signal = new AbortController().signal, finishRequest) {
|
|
2552
|
+
this.id = id;
|
|
2553
|
+
this.sendResult = sendResult;
|
|
2554
|
+
this.signal = signal;
|
|
2555
|
+
this.finishRequest = finishRequest;
|
|
2556
|
+
}
|
|
2557
|
+
get responded() {
|
|
2558
|
+
return this.didRespond;
|
|
2559
|
+
}
|
|
2560
|
+
respond(response) {
|
|
2561
|
+
return this.respondWithResult({ result: response ?? null });
|
|
2562
|
+
}
|
|
2563
|
+
respondWithError(error) {
|
|
2564
|
+
const errorResponse = error instanceof RequestError ? error.toErrorResponse() : error;
|
|
2565
|
+
return this.respondWithResult({ error: errorResponse });
|
|
2566
|
+
}
|
|
2567
|
+
respondWithResult(result) {
|
|
2568
|
+
if (this.didRespond) {
|
|
2569
|
+
return rejectedPromise(new Error("JSON-RPC request already responded"));
|
|
2570
|
+
}
|
|
2571
|
+
this.didRespond = true;
|
|
2572
|
+
return this.sendResult(result).finally(() => {
|
|
2573
|
+
this.finishRequest?.();
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
var requestBatchSizes = new WeakMap;
|
|
2578
|
+
class HandlerRegistration {
|
|
2579
|
+
disposeHandler;
|
|
2580
|
+
active = true;
|
|
2581
|
+
constructor(disposeHandler) {
|
|
2582
|
+
this.disposeHandler = disposeHandler;
|
|
2583
|
+
}
|
|
2584
|
+
dispose() {
|
|
2585
|
+
if (!this.active) {
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
this.active = false;
|
|
2589
|
+
this.disposeHandler();
|
|
2590
|
+
}
|
|
2591
|
+
[Symbol.dispose]() {
|
|
2592
|
+
this.dispose();
|
|
2593
|
+
}
|
|
2594
|
+
runIndefinitely() {
|
|
2595
|
+
return this;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
class ConnectionContext {
|
|
2600
|
+
connection;
|
|
2601
|
+
constructor(connection) {
|
|
2602
|
+
this.connection = connection;
|
|
2603
|
+
}
|
|
2604
|
+
sendRequest(method, params, mapResponse, options) {
|
|
2605
|
+
return this.connection.sendRequest(method, params, mapResponse, options);
|
|
2606
|
+
}
|
|
2607
|
+
sendNotification(method, params) {
|
|
2608
|
+
return this.connection.sendNotification(method, params);
|
|
2609
|
+
}
|
|
2610
|
+
sendBatch(entries) {
|
|
2611
|
+
return this.connection.sendBatch(entries);
|
|
2612
|
+
}
|
|
2613
|
+
sendCancelRequest(requestId) {
|
|
2614
|
+
return this.connection.sendCancelRequest(requestId);
|
|
2615
|
+
}
|
|
2616
|
+
addDynamicHandler(handler) {
|
|
2617
|
+
return this.connection.addDynamicHandler(handler);
|
|
2618
|
+
}
|
|
2619
|
+
get signal() {
|
|
2620
|
+
return this.connection.signal;
|
|
2621
|
+
}
|
|
2622
|
+
get closed() {
|
|
2623
|
+
return this.connection.closed;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
class Connection {
|
|
2628
|
+
pendingResponses = new Map;
|
|
2629
|
+
incomingRequests = new Map;
|
|
2630
|
+
nextRequestId = 0;
|
|
2631
|
+
staticHandlers = [];
|
|
2632
|
+
dynamicHandlers = new Set;
|
|
2633
|
+
stream;
|
|
2634
|
+
writeQueue = Promise.resolve();
|
|
2635
|
+
abortController = new AbortController;
|
|
2636
|
+
closedPromise;
|
|
2637
|
+
retryQueue = [];
|
|
2638
|
+
context = new ConnectionContext(this);
|
|
2639
|
+
receiveReader;
|
|
2640
|
+
allowBatches = true;
|
|
2641
|
+
constructor(requestHandlerOrStream, notificationHandlerOrHandlers, streamOrOptions, options) {
|
|
2642
|
+
if (typeof requestHandlerOrStream === "function") {
|
|
2643
|
+
const requestHandler = requestHandlerOrStream;
|
|
2644
|
+
const notificationHandler = notificationHandlerOrHandlers;
|
|
2645
|
+
const stream2 = streamOrOptions;
|
|
2646
|
+
this.initialize(stream2, [
|
|
2647
|
+
...options?.handlers ?? [],
|
|
2648
|
+
this.legacyHandler(requestHandler, notificationHandler)
|
|
2649
|
+
], options);
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
const stream = requestHandlerOrStream;
|
|
2653
|
+
const handlers = notificationHandlerOrHandlers;
|
|
2654
|
+
const connectionOptions = streamOrOptions;
|
|
2655
|
+
this.initialize(stream, [...connectionOptions?.handlers ?? [], ...handlers], connectionOptions);
|
|
2656
|
+
}
|
|
2657
|
+
static builder() {
|
|
2658
|
+
return new ConnectionBuilder;
|
|
2659
|
+
}
|
|
2660
|
+
runUntil(op) {
|
|
2661
|
+
let opSettled = false;
|
|
2662
|
+
const opPromise = Promise.resolve().then(() => op(this.context)).finally(() => {
|
|
2663
|
+
opSettled = true;
|
|
2664
|
+
});
|
|
2665
|
+
const closedPromise = this.closed.then(() => {
|
|
2666
|
+
if (opSettled) {
|
|
2667
|
+
return new Promise(() => {});
|
|
2668
|
+
}
|
|
2669
|
+
throw this.closedReason();
|
|
2670
|
+
});
|
|
2671
|
+
return Promise.race([opPromise, closedPromise]).finally(() => {
|
|
2672
|
+
opSettled = true;
|
|
2673
|
+
this.close();
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
addDynamicHandler(handler) {
|
|
2677
|
+
this.dynamicHandlers.add(handler);
|
|
2678
|
+
if (this.retryQueue.length > 0) {
|
|
2679
|
+
for (const message of this.retryQueue.splice(0)) {
|
|
2680
|
+
this.processIncomingMessage(message).catch((error) => this.close(error));
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
return new HandlerRegistration(() => {
|
|
2684
|
+
this.dynamicHandlers.delete(handler);
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
get signal() {
|
|
2688
|
+
return this.abortController.signal;
|
|
2689
|
+
}
|
|
2690
|
+
get closed() {
|
|
2691
|
+
return this.closedPromise;
|
|
2692
|
+
}
|
|
2693
|
+
getContext() {
|
|
2694
|
+
return this.context;
|
|
2695
|
+
}
|
|
2696
|
+
sendRequest(method, params, mapResponse, options = {}) {
|
|
2697
|
+
if (this.abortController.signal.aborted) {
|
|
2698
|
+
return rejectedPromise(this.closedReason());
|
|
2699
|
+
}
|
|
2700
|
+
const request = this.prepareRequest(method, params, mapResponse, options);
|
|
2701
|
+
const requestSent = this.sendWireMessage(request.message);
|
|
2702
|
+
requestSent.catch(() => {});
|
|
2703
|
+
if (options.cancellationSignal?.aborted) {
|
|
2704
|
+
request.cancel();
|
|
2705
|
+
}
|
|
2706
|
+
return request.response;
|
|
2707
|
+
}
|
|
2708
|
+
sendBatch(entries) {
|
|
2709
|
+
if (this.abortController.signal.aborted) {
|
|
2710
|
+
return rejectedPromise(this.closedReason());
|
|
2711
|
+
}
|
|
2712
|
+
if (!this.allowBatches) {
|
|
2713
|
+
return rejectedPromise(new TypeError("JSON-RPC batches are not supported on this connection"));
|
|
2714
|
+
}
|
|
2715
|
+
if (entries.length === 0) {
|
|
2716
|
+
return rejectedPromise(new TypeError("JSON-RPC batch must contain at least one entry"));
|
|
2717
|
+
}
|
|
2718
|
+
const messages = [];
|
|
2719
|
+
const cancellations = [];
|
|
2720
|
+
const outputs = [];
|
|
2721
|
+
for (const entry of entries) {
|
|
2722
|
+
if (entry.kind === "notification") {
|
|
2723
|
+
messages.push({
|
|
2724
|
+
jsonrpc: "2.0",
|
|
2725
|
+
method: entry.method,
|
|
2726
|
+
params: entry.params
|
|
2727
|
+
});
|
|
2728
|
+
outputs.push(Promise.resolve(undefined));
|
|
2729
|
+
continue;
|
|
2730
|
+
}
|
|
2731
|
+
const request = this.prepareRequest(entry.method, entry.params, entry.mapResponse, entry.options);
|
|
2732
|
+
messages.push(request.message);
|
|
2733
|
+
outputs.push(request.response);
|
|
2734
|
+
cancellations.push({
|
|
2735
|
+
signal: entry.options?.cancellationSignal,
|
|
2736
|
+
cancel: request.cancel
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
const batch = messages;
|
|
2740
|
+
const batchSent = this.sendWireMessage(batch);
|
|
2741
|
+
for (const cancellation of cancellations) {
|
|
2742
|
+
if (cancellation.signal?.aborted) {
|
|
2743
|
+
cancellation.cancel();
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
const response = Promise.all([batchSent, ...outputs]).then(([, ...resolved]) => resolved);
|
|
2747
|
+
response.catch(() => {});
|
|
2748
|
+
return response;
|
|
2749
|
+
}
|
|
2750
|
+
sendCancelRequest(requestId) {
|
|
2751
|
+
return this.sendNotification(CANCEL_REQUEST_METHOD, { requestId });
|
|
2752
|
+
}
|
|
2753
|
+
sendNotification(method, params) {
|
|
2754
|
+
if (this.abortController.signal.aborted) {
|
|
2755
|
+
return rejectedPromise(this.closedReason());
|
|
2756
|
+
}
|
|
2757
|
+
return this.sendWireMessage({ jsonrpc: "2.0", method, params });
|
|
2758
|
+
}
|
|
2759
|
+
prepareRequest(method, params, mapResponse, options = {}) {
|
|
2760
|
+
const id = this.nextRequestId++;
|
|
2761
|
+
let cancel = () => {};
|
|
2762
|
+
const response = new Promise((resolve, reject) => {
|
|
2763
|
+
const pendingResponse = {
|
|
2764
|
+
resolve: (value) => {
|
|
2765
|
+
try {
|
|
2766
|
+
resolve(mapResponse ? mapResponse(value) : value);
|
|
2767
|
+
} catch (error) {
|
|
2768
|
+
reject(error);
|
|
2769
|
+
}
|
|
2770
|
+
},
|
|
2771
|
+
reject
|
|
2772
|
+
};
|
|
2773
|
+
cancel = () => {
|
|
2774
|
+
if (pendingResponse.cancellationSent) {
|
|
2775
|
+
return;
|
|
2776
|
+
}
|
|
2777
|
+
pendingResponse.cancellationSent = true;
|
|
2778
|
+
pendingResponse.cleanup?.();
|
|
2779
|
+
this.sendCancelRequest(id).catch(() => {});
|
|
2780
|
+
};
|
|
2781
|
+
options.cancellationSignal?.addEventListener("abort", cancel, {
|
|
2782
|
+
once: true
|
|
2783
|
+
});
|
|
2784
|
+
pendingResponse.cleanup = () => {
|
|
2785
|
+
options.cancellationSignal?.removeEventListener("abort", cancel);
|
|
2786
|
+
};
|
|
2787
|
+
this.pendingResponses.set(id, pendingResponse);
|
|
2788
|
+
});
|
|
2789
|
+
response.catch(() => {});
|
|
2790
|
+
return {
|
|
2791
|
+
message: { jsonrpc: "2.0", id, method, params },
|
|
2792
|
+
response,
|
|
2793
|
+
cancel: () => cancel()
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2796
|
+
close(error) {
|
|
2797
|
+
if (this.abortController.signal.aborted) {
|
|
2798
|
+
return;
|
|
2799
|
+
}
|
|
2800
|
+
const closeError = error ?? new Error("ACP connection closed");
|
|
2801
|
+
this.abortController.abort(closeError);
|
|
2802
|
+
for (const pendingResponse of this.pendingResponses.values()) {
|
|
2803
|
+
pendingResponse.cleanup?.();
|
|
2804
|
+
pendingResponse.reject(closeError);
|
|
2805
|
+
}
|
|
2806
|
+
this.pendingResponses.clear();
|
|
2807
|
+
for (const controller of this.incomingRequests.values()) {
|
|
2808
|
+
controller.abort(closeError);
|
|
2809
|
+
}
|
|
2810
|
+
this.incomingRequests.clear();
|
|
2811
|
+
this.receiveReader?.cancel(closeError).catch(() => {});
|
|
2812
|
+
}
|
|
2813
|
+
initialize(stream, handlers, options) {
|
|
2814
|
+
this.stream = stream;
|
|
2815
|
+
this.staticHandlers = handlers;
|
|
2816
|
+
this.allowBatches = options?.allowBatches ?? true;
|
|
2817
|
+
this.closedPromise = new Promise((resolve) => {
|
|
2818
|
+
this.abortController.signal.addEventListener("abort", () => resolve());
|
|
2819
|
+
});
|
|
2820
|
+
this.receive();
|
|
2821
|
+
}
|
|
2822
|
+
legacyHandler(requestHandler, notificationHandler) {
|
|
2823
|
+
return {
|
|
2824
|
+
handleMessage: async (message, cx) => {
|
|
2825
|
+
if (message.kind === "request") {
|
|
2826
|
+
const result = await requestHandler(message.method, message.params, cx);
|
|
2827
|
+
await message.responder.respond(result);
|
|
2828
|
+
} else {
|
|
2829
|
+
await notificationHandler(message.method, message.params, cx);
|
|
2830
|
+
}
|
|
2831
|
+
return Handled.yes();
|
|
2832
|
+
}
|
|
2833
|
+
};
|
|
2834
|
+
}
|
|
2835
|
+
async receive() {
|
|
2836
|
+
let closeError = undefined;
|
|
2837
|
+
try {
|
|
2838
|
+
const reader = this.stream.readable.getReader();
|
|
2839
|
+
this.receiveReader = reader;
|
|
2840
|
+
try {
|
|
2841
|
+
while (!this.abortController.signal.aborted) {
|
|
2842
|
+
const { value: message, done } = await reader.read();
|
|
2843
|
+
if (this.abortController.signal.aborted) {
|
|
2844
|
+
break;
|
|
2845
|
+
}
|
|
2846
|
+
if (done) {
|
|
2847
|
+
break;
|
|
2848
|
+
}
|
|
2849
|
+
this.receiveWireMessage(message);
|
|
2850
|
+
}
|
|
2851
|
+
} finally {
|
|
2852
|
+
if (this.receiveReader === reader) {
|
|
2853
|
+
this.receiveReader = undefined;
|
|
2854
|
+
}
|
|
2855
|
+
reader.releaseLock();
|
|
2856
|
+
}
|
|
2857
|
+
} catch (error) {
|
|
2858
|
+
closeError = error;
|
|
2859
|
+
} finally {
|
|
2860
|
+
this.close(closeError);
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
receiveWireMessage(message) {
|
|
2864
|
+
if (Array.isArray(message)) {
|
|
2865
|
+
if (!this.allowBatches) {
|
|
2866
|
+
this.close(new TypeError("JSON-RPC batches are not supported on this connection"));
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
this.receiveBatch(message);
|
|
2870
|
+
return;
|
|
2871
|
+
}
|
|
2872
|
+
if (!isRequestMessage(message) && !isNotificationMessage(message) && !isResponseShapedMessage(message)) {
|
|
2873
|
+
this.sendWireMessage(protocolErrorResponse(RequestError.invalidRequest(message))).catch(() => {});
|
|
2874
|
+
return;
|
|
2875
|
+
}
|
|
2876
|
+
this.receiveMessage(message);
|
|
2877
|
+
}
|
|
2878
|
+
receiveBatch(batch) {
|
|
2879
|
+
if (batch.length === 0) {
|
|
2880
|
+
this.sendWireMessage(protocolErrorResponse(RequestError.invalidRequest(batch))).catch(() => {});
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
const responseBatch = isResponseBatch(batch);
|
|
2884
|
+
const responseCount = responseBatch ? 0 : batch.reduce((count, message) => count + (isNotificationMessage(message) ? 0 : 1), 0);
|
|
2885
|
+
let remaining = responseCount;
|
|
2886
|
+
let remainingNotifications = batch.reduce((count, message) => count + (isNotificationMessage(message) ? 1 : 0), 0);
|
|
2887
|
+
let responseSent = false;
|
|
2888
|
+
const responses = [];
|
|
2889
|
+
const sendResponsesIfReady = async () => {
|
|
2890
|
+
if (responseSent || remaining !== 0 || remainingNotifications !== 0 || responses.length === 0) {
|
|
2891
|
+
return;
|
|
2892
|
+
}
|
|
2893
|
+
responseSent = true;
|
|
2894
|
+
await this.sendWireMessage(responses);
|
|
2895
|
+
};
|
|
2896
|
+
const collectResponse = async (response) => {
|
|
2897
|
+
responses.push(response);
|
|
2898
|
+
remaining -= 1;
|
|
2899
|
+
await sendResponsesIfReady();
|
|
2900
|
+
};
|
|
2901
|
+
for (const message of batch) {
|
|
2902
|
+
if (responseBatch) {
|
|
2903
|
+
if (isResponseShapedMessage(message)) {
|
|
2904
|
+
this.receiveMessage(message);
|
|
2905
|
+
}
|
|
2906
|
+
continue;
|
|
2907
|
+
}
|
|
2908
|
+
if (!isRequestMessage(message) && !isNotificationMessage(message)) {
|
|
2909
|
+
collectResponse(protocolErrorResponse(RequestError.invalidRequest(message))).catch(() => {});
|
|
2910
|
+
continue;
|
|
2911
|
+
}
|
|
2912
|
+
const processing = this.receiveMessage(message, isRequestMessage(message) ? collectResponse : undefined, batch.length);
|
|
2913
|
+
if (isNotificationMessage(message)) {
|
|
2914
|
+
processing.finally(() => {
|
|
2915
|
+
remainingNotifications -= 1;
|
|
2916
|
+
sendResponsesIfReady().catch((error) => this.close(error));
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
receiveMessage(message, sendResponse, batchSize) {
|
|
2922
|
+
if (this.abortController.signal.aborted) {
|
|
2923
|
+
return Promise.resolve();
|
|
2924
|
+
}
|
|
2925
|
+
if (!isRecord(message)) {
|
|
2926
|
+
console.error("Invalid message", { message });
|
|
2927
|
+
return Promise.resolve();
|
|
2928
|
+
}
|
|
2929
|
+
if ("method" in message) {
|
|
2930
|
+
if (!("id" in message)) {
|
|
2931
|
+
this.handleProtocolNotification(message);
|
|
2932
|
+
}
|
|
2933
|
+
return this.processIncomingMessage(this.toIncomingMessage(message, sendResponse, batchSize)).catch((error) => this.close(error));
|
|
2934
|
+
} else if ("id" in message) {
|
|
2935
|
+
this.handleResponse(message);
|
|
2936
|
+
} else {
|
|
2937
|
+
console.error("Invalid message", { message });
|
|
2938
|
+
}
|
|
2939
|
+
return Promise.resolve();
|
|
2940
|
+
}
|
|
2941
|
+
async processIncomingMessage(message) {
|
|
2942
|
+
if (this.abortController.signal.aborted) {
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
let current = message;
|
|
2946
|
+
let retry = false;
|
|
2947
|
+
try {
|
|
2948
|
+
for (const handler of [
|
|
2949
|
+
...this.staticHandlers,
|
|
2950
|
+
...this.dynamicHandlers.values()
|
|
2951
|
+
]) {
|
|
2952
|
+
if (this.abortController.signal.aborted) {
|
|
2953
|
+
return;
|
|
2954
|
+
}
|
|
2955
|
+
const result = await handler.handleMessage(current, this.context) ?? {
|
|
2956
|
+
handled: true
|
|
2957
|
+
};
|
|
2958
|
+
if (result.handled) {
|
|
2959
|
+
return;
|
|
2960
|
+
}
|
|
2961
|
+
current = result.message ?? current;
|
|
2962
|
+
retry = retry || Boolean(result.retry);
|
|
2963
|
+
}
|
|
2964
|
+
if (retry) {
|
|
2965
|
+
this.retryQueue.push(current);
|
|
2966
|
+
} else if (current.kind === "request") {
|
|
2967
|
+
await current.responder.respondWithError(RequestError.methodNotFound(current.method));
|
|
2968
|
+
}
|
|
2969
|
+
} catch (error) {
|
|
2970
|
+
if (this.abortController.signal.aborted) {
|
|
2971
|
+
return;
|
|
2972
|
+
}
|
|
2973
|
+
if (current.kind === "request" && !current.responder.responded) {
|
|
2974
|
+
await current.responder.respondWithResult(errorToRequestResult(error, current.responder.signal));
|
|
2975
|
+
} else {
|
|
2976
|
+
const response = errorToResult(error);
|
|
2977
|
+
if ("error" in response) {
|
|
2978
|
+
console.error("Error handling notification", message.raw, response.error);
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
toIncomingMessage(message, sendResponse, batchSize) {
|
|
2984
|
+
if ("id" in message) {
|
|
2985
|
+
const abortController = new AbortController;
|
|
2986
|
+
this.incomingRequests.set(message.id, abortController);
|
|
2987
|
+
const finishRequest = () => {
|
|
2988
|
+
if (this.incomingRequests.get(message.id) === abortController) {
|
|
2989
|
+
this.incomingRequests.delete(message.id);
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
const responder = new RequestResponder(message.id, (result) => {
|
|
2993
|
+
const response = {
|
|
2994
|
+
jsonrpc: "2.0",
|
|
2995
|
+
id: message.id,
|
|
2996
|
+
...result
|
|
2997
|
+
};
|
|
2998
|
+
return sendResponse ? sendResponse(response) : this.sendWireMessage(response);
|
|
2999
|
+
}, abortController.signal, finishRequest);
|
|
3000
|
+
if (batchSize !== undefined) {
|
|
3001
|
+
requestBatchSizes.set(responder, batchSize);
|
|
3002
|
+
}
|
|
3003
|
+
return {
|
|
3004
|
+
kind: "request",
|
|
3005
|
+
method: message.method,
|
|
3006
|
+
params: message.params,
|
|
3007
|
+
raw: message,
|
|
3008
|
+
signal: abortController.signal,
|
|
3009
|
+
responder
|
|
3010
|
+
};
|
|
3011
|
+
}
|
|
3012
|
+
return {
|
|
3013
|
+
kind: "notification",
|
|
3014
|
+
method: message.method,
|
|
3015
|
+
params: message.params,
|
|
3016
|
+
raw: message
|
|
3017
|
+
};
|
|
3018
|
+
}
|
|
3019
|
+
handleResponse(response) {
|
|
3020
|
+
const pendingResponse = this.pendingResponses.get(response.id);
|
|
3021
|
+
if (pendingResponse) {
|
|
3022
|
+
this.pendingResponses.delete(response.id);
|
|
3023
|
+
pendingResponse.cleanup?.();
|
|
3024
|
+
if (!isResponseMessage(response)) {
|
|
3025
|
+
pendingResponse.reject(RequestError.invalidRequest(response));
|
|
3026
|
+
} else if ("result" in response) {
|
|
3027
|
+
pendingResponse.resolve(response.result);
|
|
3028
|
+
} else {
|
|
3029
|
+
const { code, message, data } = response.error;
|
|
3030
|
+
pendingResponse.reject(new RequestError(code, message, data));
|
|
3031
|
+
}
|
|
3032
|
+
} else {
|
|
3033
|
+
console.error("Got response to unknown request", response.id);
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
handleProtocolNotification(message) {
|
|
3037
|
+
if (message.method !== CANCEL_REQUEST_METHOD) {
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
const requestId = cancelRequestId(message.params);
|
|
3041
|
+
if (requestId === undefined) {
|
|
3042
|
+
return;
|
|
3043
|
+
}
|
|
3044
|
+
const controller = this.incomingRequests.get(requestId);
|
|
3045
|
+
if (!controller || controller.signal.aborted) {
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
controller.abort(RequestError.requestCancelled({ requestId }));
|
|
3049
|
+
}
|
|
3050
|
+
closedReason() {
|
|
3051
|
+
return this.abortController.signal.reason ?? new Error("ACP connection closed");
|
|
3052
|
+
}
|
|
3053
|
+
async sendWireMessage(message) {
|
|
3054
|
+
if (this.abortController.signal.aborted) {
|
|
3055
|
+
return rejectedPromise(this.closedReason());
|
|
3056
|
+
}
|
|
3057
|
+
this.writeQueue = this.writeQueue.then(async () => {
|
|
3058
|
+
if (this.abortController.signal.aborted) {
|
|
3059
|
+
throw this.closedReason();
|
|
3060
|
+
}
|
|
3061
|
+
const writer = this.stream.writable.getWriter();
|
|
3062
|
+
try {
|
|
3063
|
+
await writer.write(message);
|
|
3064
|
+
} finally {
|
|
3065
|
+
writer.releaseLock();
|
|
3066
|
+
}
|
|
3067
|
+
}).catch((error) => {
|
|
3068
|
+
this.close(error);
|
|
3069
|
+
throw error;
|
|
3070
|
+
});
|
|
3071
|
+
return this.writeQueue;
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
class ConnectionBuilder {
|
|
3076
|
+
handlers = [];
|
|
3077
|
+
connectionName;
|
|
3078
|
+
name(name) {
|
|
3079
|
+
this.connectionName = name;
|
|
3080
|
+
return this;
|
|
3081
|
+
}
|
|
3082
|
+
withHandler(handler) {
|
|
3083
|
+
this.handlers.push(handler);
|
|
3084
|
+
return this;
|
|
3085
|
+
}
|
|
3086
|
+
onReceiveMessage(handler) {
|
|
3087
|
+
return this.withHandler({
|
|
3088
|
+
handleMessage: async (message, cx) => await handler(message, cx) ?? Handled.no(message),
|
|
3089
|
+
describe: () => this.connectionName ?? "onReceiveMessage"
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
onReceiveRequest(method, parse, handler) {
|
|
3093
|
+
return this.withHandler({
|
|
3094
|
+
handleMessage: async (message, cx) => {
|
|
3095
|
+
if (message.kind !== "request" || message.method !== method) {
|
|
3096
|
+
return Handled.no(message);
|
|
3097
|
+
}
|
|
3098
|
+
const request = parse(message.params);
|
|
3099
|
+
return await handler(request, message.responder, cx) ?? Handled.yes();
|
|
3100
|
+
},
|
|
3101
|
+
describe: () => `${this.connectionName ?? "request"}:${method}`
|
|
3102
|
+
});
|
|
3103
|
+
}
|
|
3104
|
+
onReceiveNotification(method, parse, handler) {
|
|
3105
|
+
return this.withHandler({
|
|
3106
|
+
handleMessage: async (message, cx) => {
|
|
3107
|
+
if (message.kind !== "notification" || message.method !== method) {
|
|
3108
|
+
return Handled.no(message);
|
|
3109
|
+
}
|
|
3110
|
+
const notification = parse(message.params);
|
|
3111
|
+
return await handler(notification, cx) ?? Handled.yes();
|
|
3112
|
+
},
|
|
3113
|
+
describe: () => `${this.connectionName ?? "notification"}:${method}`
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
connect(stream, options) {
|
|
3117
|
+
return new Connection(stream, this.handlers, options);
|
|
3118
|
+
}
|
|
3119
|
+
connectWith(stream, op, options) {
|
|
3120
|
+
return this.connect(stream, options).runUntil(op);
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
|
|
3124
|
+
class RequestError extends Error {
|
|
3125
|
+
code;
|
|
3126
|
+
data;
|
|
3127
|
+
constructor(code, message, data) {
|
|
3128
|
+
super(message);
|
|
3129
|
+
this.code = code;
|
|
3130
|
+
this.name = "RequestError";
|
|
3131
|
+
this.data = data;
|
|
3132
|
+
}
|
|
3133
|
+
static parseError(data, additionalMessage) {
|
|
3134
|
+
return new RequestError(-32700, `Parse error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
3135
|
+
}
|
|
3136
|
+
static invalidRequest(data, additionalMessage) {
|
|
3137
|
+
return new RequestError(-32600, `Invalid request${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
3138
|
+
}
|
|
3139
|
+
static methodNotFound(method) {
|
|
3140
|
+
return new RequestError(-32601, `"Method not found": ${method}`, {
|
|
3141
|
+
method
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3144
|
+
static invalidParams(data, additionalMessage) {
|
|
3145
|
+
return new RequestError(-32602, `Invalid params${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
3146
|
+
}
|
|
3147
|
+
static internalError(data, additionalMessage) {
|
|
3148
|
+
return new RequestError(-32603, `Internal error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
3149
|
+
}
|
|
3150
|
+
static requestCancelled(data, additionalMessage) {
|
|
3151
|
+
return new RequestError(-32800, `Request cancelled${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
3152
|
+
}
|
|
3153
|
+
static authRequired(data, additionalMessage) {
|
|
3154
|
+
return new RequestError(-32000, `Authentication required${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
3155
|
+
}
|
|
3156
|
+
static resourceNotFound(uri) {
|
|
3157
|
+
return new RequestError(-32002, `Resource not found${uri ? `: ${uri}` : ""}`, uri && { uri });
|
|
3158
|
+
}
|
|
3159
|
+
toResult() {
|
|
3160
|
+
return {
|
|
3161
|
+
error: {
|
|
3162
|
+
code: this.code,
|
|
3163
|
+
message: this.message,
|
|
3164
|
+
data: this.data
|
|
3165
|
+
}
|
|
3166
|
+
};
|
|
3167
|
+
}
|
|
3168
|
+
toErrorResponse() {
|
|
3169
|
+
return {
|
|
3170
|
+
code: this.code,
|
|
3171
|
+
message: this.message,
|
|
3172
|
+
data: this.data
|
|
3173
|
+
};
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
function protocolErrorResponse(error) {
|
|
3177
|
+
return {
|
|
3178
|
+
jsonrpc: "2.0",
|
|
3179
|
+
id: null,
|
|
3180
|
+
error: error.toErrorResponse()
|
|
3181
|
+
};
|
|
3182
|
+
}
|
|
3183
|
+
|
|
3184
|
+
// node_modules/@agentclientprotocol/sdk/dist/line-buffer.js
|
|
3185
|
+
var newline = 10;
|
|
3186
|
+
|
|
3187
|
+
class LineBuffer {
|
|
3188
|
+
#pending = [];
|
|
3189
|
+
push(chunk) {
|
|
3190
|
+
const lines = [];
|
|
3191
|
+
let start = 0;
|
|
3192
|
+
let newlineIndex = chunk.indexOf(newline, start);
|
|
3193
|
+
while (newlineIndex !== -1) {
|
|
3194
|
+
lines.push(this.#takeLine(chunk.subarray(start, newlineIndex)));
|
|
3195
|
+
start = newlineIndex + 1;
|
|
3196
|
+
newlineIndex = chunk.indexOf(newline, start);
|
|
3197
|
+
}
|
|
3198
|
+
if (start < chunk.byteLength) {
|
|
3199
|
+
this.#pending.push(start === 0 ? chunk : new Uint8Array(chunk.subarray(start)));
|
|
3200
|
+
}
|
|
3201
|
+
return lines;
|
|
3202
|
+
}
|
|
3203
|
+
flush() {
|
|
3204
|
+
if (this.#pending.length === 0) {
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
return this.#takeLine(new Uint8Array(0));
|
|
3208
|
+
}
|
|
3209
|
+
#takeLine(tail) {
|
|
3210
|
+
if (this.#pending.length === 0) {
|
|
3211
|
+
return tail;
|
|
3212
|
+
}
|
|
3213
|
+
let total = tail.byteLength;
|
|
3214
|
+
for (const part of this.#pending) {
|
|
3215
|
+
total += part.byteLength;
|
|
3216
|
+
}
|
|
3217
|
+
const line = new Uint8Array(total);
|
|
3218
|
+
let offset = 0;
|
|
3219
|
+
for (const part of this.#pending) {
|
|
3220
|
+
line.set(part, offset);
|
|
3221
|
+
offset += part.byteLength;
|
|
3222
|
+
}
|
|
3223
|
+
line.set(tail, offset);
|
|
3224
|
+
this.#pending = [];
|
|
3225
|
+
return line;
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
// node_modules/@agentclientprotocol/sdk/dist/stream.js
|
|
3230
|
+
function ndJsonStream(output, input) {
|
|
3231
|
+
const textEncoder = new TextEncoder;
|
|
3232
|
+
const textDecoder = new TextDecoder;
|
|
3233
|
+
let cancelled = false;
|
|
3234
|
+
let inputReader;
|
|
3235
|
+
let outputWrite = Promise.resolve();
|
|
3236
|
+
const writeJson = (message) => {
|
|
3237
|
+
const content = JSON.stringify(message) + `
|
|
3238
|
+
`;
|
|
3239
|
+
const write = outputWrite.then(async () => {
|
|
3240
|
+
const writer = output.getWriter();
|
|
3241
|
+
try {
|
|
3242
|
+
await writer.write(textEncoder.encode(content));
|
|
3243
|
+
} finally {
|
|
3244
|
+
writer.releaseLock();
|
|
3245
|
+
}
|
|
3246
|
+
});
|
|
3247
|
+
outputWrite = write.catch(() => {});
|
|
3248
|
+
return write;
|
|
3249
|
+
};
|
|
3250
|
+
const readable = new ReadableStream({
|
|
3251
|
+
async start(controller) {
|
|
3252
|
+
const lines = new LineBuffer;
|
|
3253
|
+
const enqueueLine = async (lineBytes) => {
|
|
3254
|
+
const trimmedLine = textDecoder.decode(lineBytes).trim();
|
|
3255
|
+
if (!trimmedLine) {
|
|
3256
|
+
return;
|
|
3257
|
+
}
|
|
3258
|
+
let message;
|
|
3259
|
+
try {
|
|
3260
|
+
message = JSON.parse(trimmedLine);
|
|
3261
|
+
} catch {
|
|
3262
|
+
await writeJson(protocolErrorResponse(RequestError.parseError()));
|
|
3263
|
+
return;
|
|
3264
|
+
}
|
|
3265
|
+
if (isRecord(message) || Array.isArray(message)) {
|
|
3266
|
+
controller.enqueue(message);
|
|
3267
|
+
} else {
|
|
3268
|
+
await writeJson(protocolErrorResponse(RequestError.invalidRequest(message)));
|
|
3269
|
+
}
|
|
3270
|
+
};
|
|
3271
|
+
const reader = input.getReader();
|
|
3272
|
+
inputReader = reader;
|
|
3273
|
+
try {
|
|
3274
|
+
while (true) {
|
|
3275
|
+
const { value, done } = await reader.read();
|
|
3276
|
+
if (cancelled) {
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
if (done) {
|
|
3280
|
+
break;
|
|
3281
|
+
}
|
|
3282
|
+
if (!value) {
|
|
3283
|
+
continue;
|
|
3284
|
+
}
|
|
3285
|
+
for (const line of lines.push(value)) {
|
|
3286
|
+
await enqueueLine(line);
|
|
3287
|
+
if (cancelled) {
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
if (cancelled) {
|
|
3293
|
+
return;
|
|
3294
|
+
}
|
|
3295
|
+
const lastLine = lines.flush();
|
|
3296
|
+
if (lastLine) {
|
|
3297
|
+
await enqueueLine(lastLine);
|
|
3298
|
+
}
|
|
3299
|
+
} catch (err) {
|
|
3300
|
+
if (cancelled) {
|
|
3301
|
+
return;
|
|
3302
|
+
}
|
|
3303
|
+
controller.error(err);
|
|
3304
|
+
return;
|
|
3305
|
+
} finally {
|
|
3306
|
+
if (inputReader === reader) {
|
|
3307
|
+
inputReader = undefined;
|
|
3308
|
+
}
|
|
3309
|
+
reader.releaseLock();
|
|
3310
|
+
}
|
|
3311
|
+
if (cancelled) {
|
|
3312
|
+
return;
|
|
3313
|
+
}
|
|
3314
|
+
controller.close();
|
|
3315
|
+
},
|
|
3316
|
+
cancel(reason) {
|
|
3317
|
+
cancelled = true;
|
|
3318
|
+
return inputReader?.cancel(reason);
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
const writable = new WritableStream({
|
|
3322
|
+
write(message) {
|
|
3323
|
+
return writeJson(message);
|
|
3324
|
+
}
|
|
3325
|
+
});
|
|
3326
|
+
return { readable, writable };
|
|
3327
|
+
}
|
|
3328
|
+
|
|
3329
|
+
// node_modules/@agentclientprotocol/sdk/dist/schema/guards.gen.js
|
|
3330
|
+
var zGuardCreateElicitationRequestForm = zElicitationFormMode.and(object({ mode: literal("form") })).and(object({ message: string() }));
|
|
3331
|
+
var zGuardCreateElicitationRequestUrl = zElicitationUrlMode.and(object({ mode: literal("url") })).and(object({ message: string() }));
|
|
3332
|
+
var zGuardCreateElicitationRequestCustom = union([zElicitationSessionScope, zElicitationRequestScope]).and(object({ message: string() }));
|
|
3333
|
+
var zGuardElicitationPropertySchemaString = zStringPropertySchema.and(object({ type: literal("string") }));
|
|
3334
|
+
var zGuardElicitationPropertySchemaNumber = zNumberPropertySchema.and(object({ type: literal("number") }));
|
|
3335
|
+
var zGuardElicitationPropertySchemaInteger = zIntegerPropertySchema.and(object({ type: literal("integer") }));
|
|
3336
|
+
var zGuardElicitationPropertySchemaBoolean = zBooleanPropertySchema.and(object({ type: literal("boolean") }));
|
|
3337
|
+
var zGuardElicitationPropertySchemaArray = zMultiSelectPropertySchema.and(object({ type: literal("array") }));
|
|
3338
|
+
var zGuardMultiSelectItemsString = zStringMultiSelectItems.and(object({ type: literal("string") }));
|
|
3339
|
+
var zGuardCreateElicitationResponseAccept = zElicitationAcceptAction.and(object({ action: literal("accept") }));
|
|
3340
|
+
var zGuardCreateElicitationResponseDecline = object({
|
|
3341
|
+
action: literal("decline")
|
|
3342
|
+
});
|
|
3343
|
+
var zGuardCreateElicitationResponseCancel = object({
|
|
3344
|
+
action: literal("cancel")
|
|
3345
|
+
});
|
|
3346
|
+
// node_modules/@agentclientprotocol/sdk/dist/acp.js
|
|
3347
|
+
function ndJsonStream2(output, input) {
|
|
3348
|
+
return ndJsonStream(output, input);
|
|
3349
|
+
}
|
|
3350
|
+
function emptyObjectResponse(response) {
|
|
3351
|
+
return response ?? {};
|
|
3352
|
+
}
|
|
3353
|
+
function isStream(value) {
|
|
3354
|
+
return typeof value === "object" && value !== null && "readable" in value && "writable" in value;
|
|
3355
|
+
}
|
|
3356
|
+
function memoryStreamPair() {
|
|
3357
|
+
const leftToRight = new TransformStream;
|
|
3358
|
+
const rightToLeft = new TransformStream;
|
|
3359
|
+
return [
|
|
3360
|
+
{
|
|
3361
|
+
readable: rightToLeft.readable,
|
|
3362
|
+
writable: leftToRight.writable
|
|
3363
|
+
},
|
|
3364
|
+
{
|
|
3365
|
+
readable: leftToRight.readable,
|
|
3366
|
+
writable: rightToLeft.writable
|
|
3367
|
+
}
|
|
3368
|
+
];
|
|
3369
|
+
}
|
|
3370
|
+
var methods = {
|
|
3371
|
+
agent: {
|
|
3372
|
+
initialize: AGENT_METHODS.initialize,
|
|
3373
|
+
authenticate: AGENT_METHODS.authenticate,
|
|
3374
|
+
logout: AGENT_METHODS.logout,
|
|
3375
|
+
providers: {
|
|
3376
|
+
list: AGENT_METHODS.providers_list,
|
|
3377
|
+
set: AGENT_METHODS.providers_set,
|
|
3378
|
+
disable: AGENT_METHODS.providers_disable
|
|
3379
|
+
},
|
|
3380
|
+
session: {
|
|
3381
|
+
new: AGENT_METHODS.session_new,
|
|
3382
|
+
load: AGENT_METHODS.session_load,
|
|
3383
|
+
list: AGENT_METHODS.session_list,
|
|
3384
|
+
delete: AGENT_METHODS.session_delete,
|
|
3385
|
+
fork: AGENT_METHODS.session_fork,
|
|
3386
|
+
resume: AGENT_METHODS.session_resume,
|
|
3387
|
+
close: AGENT_METHODS.session_close,
|
|
3388
|
+
setMode: AGENT_METHODS.session_set_mode,
|
|
3389
|
+
setConfigOption: AGENT_METHODS.session_set_config_option,
|
|
3390
|
+
prompt: AGENT_METHODS.session_prompt,
|
|
3391
|
+
cancel: AGENT_METHODS.session_cancel
|
|
3392
|
+
},
|
|
3393
|
+
nes: {
|
|
3394
|
+
start: AGENT_METHODS.nes_start,
|
|
3395
|
+
suggest: AGENT_METHODS.nes_suggest,
|
|
3396
|
+
accept: AGENT_METHODS.nes_accept,
|
|
3397
|
+
reject: AGENT_METHODS.nes_reject,
|
|
3398
|
+
close: AGENT_METHODS.nes_close
|
|
3399
|
+
},
|
|
3400
|
+
document: {
|
|
3401
|
+
didOpen: AGENT_METHODS.document_did_open,
|
|
3402
|
+
didChange: AGENT_METHODS.document_did_change,
|
|
3403
|
+
didClose: AGENT_METHODS.document_did_close,
|
|
3404
|
+
didSave: AGENT_METHODS.document_did_save,
|
|
3405
|
+
didFocus: AGENT_METHODS.document_did_focus
|
|
3406
|
+
}
|
|
3407
|
+
},
|
|
3408
|
+
client: {
|
|
3409
|
+
session: {
|
|
3410
|
+
requestPermission: CLIENT_METHODS.session_request_permission,
|
|
3411
|
+
update: CLIENT_METHODS.session_update
|
|
3412
|
+
},
|
|
3413
|
+
fs: {
|
|
3414
|
+
writeTextFile: CLIENT_METHODS.fs_write_text_file,
|
|
3415
|
+
readTextFile: CLIENT_METHODS.fs_read_text_file
|
|
3416
|
+
},
|
|
3417
|
+
terminal: {
|
|
3418
|
+
create: CLIENT_METHODS.terminal_create,
|
|
3419
|
+
output: CLIENT_METHODS.terminal_output,
|
|
3420
|
+
release: CLIENT_METHODS.terminal_release,
|
|
3421
|
+
waitForExit: CLIENT_METHODS.terminal_wait_for_exit,
|
|
3422
|
+
kill: CLIENT_METHODS.terminal_kill
|
|
3423
|
+
},
|
|
3424
|
+
elicitation: {
|
|
3425
|
+
create: CLIENT_METHODS.elicitation_create,
|
|
3426
|
+
complete: CLIENT_METHODS.elicitation_complete
|
|
3427
|
+
}
|
|
3428
|
+
},
|
|
3429
|
+
protocol: {
|
|
3430
|
+
cancelRequest: PROTOCOL_METHODS.cancel_request
|
|
3431
|
+
}
|
|
3432
|
+
};
|
|
3433
|
+
var startActiveSession = Symbol("startActiveSession");
|
|
3434
|
+
|
|
3435
|
+
class AcpContext {
|
|
3436
|
+
cx;
|
|
3437
|
+
currentRequestId;
|
|
3438
|
+
constructor(cx, currentRequestId) {
|
|
3439
|
+
this.cx = cx;
|
|
3440
|
+
this.currentRequestId = currentRequestId;
|
|
3441
|
+
}
|
|
3442
|
+
get requestId() {
|
|
3443
|
+
return this.currentRequestId;
|
|
3444
|
+
}
|
|
3445
|
+
get connectionContext() {
|
|
3446
|
+
return this.cx;
|
|
3447
|
+
}
|
|
3448
|
+
sendRequest(method, params, mapResponse, options) {
|
|
3449
|
+
return this.cx.sendRequest(method, params, mapResponse, options);
|
|
3450
|
+
}
|
|
3451
|
+
sendNotification(method, params) {
|
|
3452
|
+
return this.cx.sendNotification(method, params);
|
|
3453
|
+
}
|
|
3454
|
+
addDynamicHandler(handler) {
|
|
3455
|
+
return this.cx.addDynamicHandler(handler);
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
|
|
3459
|
+
class AgentContext extends AcpContext {
|
|
3460
|
+
constructor(cx, requestId) {
|
|
3461
|
+
super(cx, requestId);
|
|
3462
|
+
}
|
|
3463
|
+
static create(cx, requestId) {
|
|
3464
|
+
return new AgentContext(cx, requestId);
|
|
3465
|
+
}
|
|
3466
|
+
request(method, params, options) {
|
|
3467
|
+
const spec = clientRequestSpecsByMethod[method];
|
|
3468
|
+
return this.sendRequest(method, params, spec?.mapResponse, options);
|
|
3469
|
+
}
|
|
3470
|
+
notify(method, params) {
|
|
3471
|
+
return this.sendNotification(method, params);
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
class ClientContext extends AcpContext {
|
|
3476
|
+
constructor(cx, requestId) {
|
|
3477
|
+
super(cx, requestId);
|
|
3478
|
+
}
|
|
3479
|
+
static create(cx, requestId) {
|
|
3480
|
+
return new ClientContext(cx, requestId);
|
|
3481
|
+
}
|
|
3482
|
+
[startActiveSession](params, options) {
|
|
3483
|
+
return this.sendRequest(AGENT_METHODS.session_new, params, (response) => this.attachSession(response), options);
|
|
3484
|
+
}
|
|
3485
|
+
buildSession(cwdOrRequest) {
|
|
3486
|
+
if (typeof cwdOrRequest === "string") {
|
|
3487
|
+
return SessionBuilder.create(this, {
|
|
3488
|
+
cwd: cwdOrRequest,
|
|
3489
|
+
mcpServers: []
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3492
|
+
return SessionBuilder.create(this, cwdOrRequest);
|
|
3493
|
+
}
|
|
3494
|
+
attachSession(response) {
|
|
3495
|
+
const updates = new AsyncQueue;
|
|
3496
|
+
const closeSignal = this.connectionContext.signal;
|
|
3497
|
+
const failUpdatesOnClose = () => {
|
|
3498
|
+
updates.fail(closeSignal.reason ?? new Error("ACP connection closed"));
|
|
3499
|
+
};
|
|
3500
|
+
if (closeSignal.aborted) {
|
|
3501
|
+
failUpdatesOnClose();
|
|
3502
|
+
} else {
|
|
3503
|
+
closeSignal.addEventListener("abort", failUpdatesOnClose);
|
|
3504
|
+
}
|
|
3505
|
+
const sessionRegistration = sessionUpdateRouter(this.connectionContext).attach(response, updates);
|
|
3506
|
+
const closeRegistration = new HandlerRegistration(() => {
|
|
3507
|
+
closeSignal.removeEventListener("abort", failUpdatesOnClose);
|
|
3508
|
+
});
|
|
3509
|
+
return ActiveSession.create(this, response, updates, [
|
|
3510
|
+
sessionRegistration,
|
|
3511
|
+
closeRegistration
|
|
3512
|
+
]);
|
|
3513
|
+
}
|
|
3514
|
+
request(method, params, options) {
|
|
3515
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
3516
|
+
return this.sendRequest(method, params, spec?.mapResponse, options);
|
|
3517
|
+
}
|
|
3518
|
+
notify(method, params) {
|
|
3519
|
+
return this.sendNotification(method, params);
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
class AcpConnectionHandle {
|
|
3524
|
+
connection;
|
|
3525
|
+
constructor(connection) {
|
|
3526
|
+
this.connection = connection;
|
|
3527
|
+
}
|
|
3528
|
+
get signal() {
|
|
3529
|
+
return this.connection.signal;
|
|
3530
|
+
}
|
|
3531
|
+
get closed() {
|
|
3532
|
+
return this.connection.closed;
|
|
3533
|
+
}
|
|
3534
|
+
close(error) {
|
|
3535
|
+
this.connection.close(error);
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
class AgentConnectionHandle extends AcpConnectionHandle {
|
|
3540
|
+
connectHandlers;
|
|
3541
|
+
client;
|
|
3542
|
+
didStartConnectHandlers = false;
|
|
3543
|
+
constructor(connection, connectHandlers = []) {
|
|
3544
|
+
super(connection);
|
|
3545
|
+
this.connectHandlers = connectHandlers;
|
|
3546
|
+
this.client = AgentContext.create(connection.getContext());
|
|
3547
|
+
}
|
|
3548
|
+
startConnectHandlers() {
|
|
3549
|
+
if (this.didStartConnectHandlers) {
|
|
3550
|
+
return;
|
|
3551
|
+
}
|
|
3552
|
+
this.didStartConnectHandlers = true;
|
|
3553
|
+
runConnectHandlers(this, this.connectHandlers);
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
class ClientConnectionHandle extends AcpConnectionHandle {
|
|
3558
|
+
connectHandlers;
|
|
3559
|
+
agent;
|
|
3560
|
+
didStartConnectHandlers = false;
|
|
3561
|
+
constructor(connection, connectHandlers = []) {
|
|
3562
|
+
super(connection);
|
|
3563
|
+
this.connectHandlers = connectHandlers;
|
|
3564
|
+
this.agent = ClientContext.create(connection.getContext());
|
|
3565
|
+
}
|
|
3566
|
+
startConnectHandlers() {
|
|
3567
|
+
if (this.didStartConnectHandlers) {
|
|
3568
|
+
return;
|
|
3569
|
+
}
|
|
3570
|
+
this.didStartConnectHandlers = true;
|
|
3571
|
+
runConnectHandlers(this, this.connectHandlers);
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
function agentConnection(connection, connectHandlers = []) {
|
|
3575
|
+
return new AgentConnectionHandle(connection, connectHandlers);
|
|
3576
|
+
}
|
|
3577
|
+
function clientConnection(connection, connectHandlers = []) {
|
|
3578
|
+
return new ClientConnectionHandle(connection, connectHandlers);
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
class AsyncQueue {
|
|
3582
|
+
values = [];
|
|
3583
|
+
waiters = [];
|
|
3584
|
+
failed = false;
|
|
3585
|
+
failure;
|
|
3586
|
+
enqueue(value) {
|
|
3587
|
+
if (this.failed) {
|
|
3588
|
+
return;
|
|
3589
|
+
}
|
|
3590
|
+
const waiter = this.waiters.shift();
|
|
3591
|
+
if (waiter) {
|
|
3592
|
+
waiter.resolve(value);
|
|
3593
|
+
} else {
|
|
3594
|
+
this.values.push({ kind: "value", value });
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
reject(error) {
|
|
3598
|
+
if (this.failed) {
|
|
3599
|
+
return;
|
|
3600
|
+
}
|
|
3601
|
+
if (this.waiters.length > 0) {
|
|
3602
|
+
for (const waiter of this.waiters.splice(0)) {
|
|
3603
|
+
waiter.reject(error);
|
|
3604
|
+
}
|
|
3605
|
+
return;
|
|
3606
|
+
}
|
|
3607
|
+
this.values.push({ kind: "error", error });
|
|
3608
|
+
}
|
|
3609
|
+
clearErrors() {
|
|
3610
|
+
this.values = this.values.filter((entry) => entry.kind === "value");
|
|
3611
|
+
}
|
|
3612
|
+
fail(error) {
|
|
3613
|
+
if (this.failed) {
|
|
3614
|
+
return;
|
|
3615
|
+
}
|
|
3616
|
+
this.failed = true;
|
|
3617
|
+
this.failure = error;
|
|
3618
|
+
for (const waiter of this.waiters.splice(0)) {
|
|
3619
|
+
waiter.reject(error);
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
next() {
|
|
3623
|
+
if (this.values.length > 0) {
|
|
3624
|
+
const entry = this.values.shift();
|
|
3625
|
+
if (entry.kind === "error") {
|
|
3626
|
+
return Promise.reject(entry.error);
|
|
3627
|
+
}
|
|
3628
|
+
return Promise.resolve(entry.value);
|
|
3629
|
+
}
|
|
3630
|
+
if (this.failed) {
|
|
3631
|
+
return Promise.reject(this.failure);
|
|
3632
|
+
}
|
|
3633
|
+
return new Promise((resolve, reject) => {
|
|
3634
|
+
this.waiters.push({ resolve, reject });
|
|
3635
|
+
});
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
function cloneNewSessionRequest(request) {
|
|
3639
|
+
return {
|
|
3640
|
+
...request,
|
|
3641
|
+
additionalDirectories: request.additionalDirectories ? [...request.additionalDirectories] : undefined,
|
|
3642
|
+
mcpServers: [...request.mcpServers]
|
|
3643
|
+
};
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
class SessionBuilder {
|
|
3647
|
+
cx;
|
|
3648
|
+
request;
|
|
3649
|
+
constructor(cx, request) {
|
|
3650
|
+
this.cx = cx;
|
|
3651
|
+
this.request = cloneNewSessionRequest(request);
|
|
3652
|
+
}
|
|
3653
|
+
static create(cx, request) {
|
|
3654
|
+
return new SessionBuilder(cx, request);
|
|
3655
|
+
}
|
|
3656
|
+
toRequest() {
|
|
3657
|
+
return cloneNewSessionRequest(this.request);
|
|
3658
|
+
}
|
|
3659
|
+
withAdditionalDirectories(additionalDirectories) {
|
|
3660
|
+
this.request = {
|
|
3661
|
+
...this.request,
|
|
3662
|
+
additionalDirectories: [...additionalDirectories]
|
|
3663
|
+
};
|
|
3664
|
+
return this;
|
|
3665
|
+
}
|
|
3666
|
+
withMcpServer(mcpServer) {
|
|
3667
|
+
this.request = {
|
|
3668
|
+
...this.request,
|
|
3669
|
+
mcpServers: [...this.request.mcpServers, mcpServer]
|
|
3670
|
+
};
|
|
3671
|
+
return this;
|
|
3672
|
+
}
|
|
3673
|
+
async start(options) {
|
|
3674
|
+
return this.cx[startActiveSession](this.toRequest(), options);
|
|
3675
|
+
}
|
|
3676
|
+
async withSession(op) {
|
|
3677
|
+
const session = await this.start();
|
|
3678
|
+
try {
|
|
3679
|
+
return await op(session);
|
|
3680
|
+
} finally {
|
|
3681
|
+
session.dispose();
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
|
|
3686
|
+
class ActiveSession {
|
|
3687
|
+
cx;
|
|
3688
|
+
sessionResponse;
|
|
3689
|
+
updates;
|
|
3690
|
+
registrations;
|
|
3691
|
+
constructor(cx, sessionResponse, updates, registrations) {
|
|
3692
|
+
this.cx = cx;
|
|
3693
|
+
this.sessionResponse = sessionResponse;
|
|
3694
|
+
this.updates = updates;
|
|
3695
|
+
this.registrations = registrations;
|
|
3696
|
+
}
|
|
3697
|
+
static create(cx, sessionResponse, updates, registrations) {
|
|
3698
|
+
return new ActiveSession(cx, sessionResponse, updates, registrations);
|
|
3699
|
+
}
|
|
3700
|
+
get sessionId() {
|
|
3701
|
+
return this.sessionResponse.sessionId;
|
|
3702
|
+
}
|
|
3703
|
+
get modes() {
|
|
3704
|
+
return this.sessionResponse.modes;
|
|
3705
|
+
}
|
|
3706
|
+
get meta() {
|
|
3707
|
+
return this.sessionResponse._meta;
|
|
3708
|
+
}
|
|
3709
|
+
get newSessionResponse() {
|
|
3710
|
+
return this.sessionResponse;
|
|
3711
|
+
}
|
|
3712
|
+
prompt(prompt, options) {
|
|
3713
|
+
this.updates.clearErrors();
|
|
3714
|
+
const response = this.cx.request(AGENT_METHODS.session_prompt, {
|
|
3715
|
+
sessionId: this.sessionId,
|
|
3716
|
+
prompt: this.promptBlocks(prompt)
|
|
3717
|
+
}, options);
|
|
3718
|
+
response.then((value) => {
|
|
3719
|
+
this.updates.enqueue({
|
|
3720
|
+
kind: "stop",
|
|
3721
|
+
response: value,
|
|
3722
|
+
stopReason: value.stopReason
|
|
3723
|
+
});
|
|
3724
|
+
}, (error) => {
|
|
3725
|
+
this.updates.reject(error);
|
|
3726
|
+
});
|
|
3727
|
+
return response;
|
|
3728
|
+
}
|
|
3729
|
+
nextUpdate() {
|
|
3730
|
+
return this.updates.next();
|
|
3731
|
+
}
|
|
3732
|
+
async readText() {
|
|
3733
|
+
let output = "";
|
|
3734
|
+
for (;; ) {
|
|
3735
|
+
const message = await this.nextUpdate();
|
|
3736
|
+
if (message.kind === "stop") {
|
|
3737
|
+
return output;
|
|
3738
|
+
}
|
|
3739
|
+
const { update } = message;
|
|
3740
|
+
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
3741
|
+
output += update.content.text;
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
dispose() {
|
|
3746
|
+
for (const registration of this.registrations.splice(0)) {
|
|
3747
|
+
registration.dispose();
|
|
3748
|
+
}
|
|
3749
|
+
this.updates.fail(new Error("Active session disposed"));
|
|
3750
|
+
}
|
|
3751
|
+
[Symbol.dispose]() {
|
|
3752
|
+
this.dispose();
|
|
3753
|
+
}
|
|
3754
|
+
promptBlocks(prompt) {
|
|
3755
|
+
if (typeof prompt === "string") {
|
|
3756
|
+
return [{ type: "text", text: prompt }];
|
|
3757
|
+
}
|
|
3758
|
+
if (Array.isArray(prompt)) {
|
|
3759
|
+
return prompt;
|
|
3760
|
+
}
|
|
3761
|
+
return [prompt];
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
function parseParams(parser, params) {
|
|
3765
|
+
if (!parser) {
|
|
3766
|
+
return params;
|
|
3767
|
+
}
|
|
3768
|
+
if (typeof parser === "function") {
|
|
3769
|
+
return parser(params);
|
|
3770
|
+
}
|
|
3771
|
+
return parser.parse(params);
|
|
3772
|
+
}
|
|
3773
|
+
function requestSpec(method, params, mapResponse) {
|
|
3774
|
+
return { method, params, mapResponse };
|
|
3775
|
+
}
|
|
3776
|
+
function notificationSpec(method, params) {
|
|
3777
|
+
return { method, params };
|
|
3778
|
+
}
|
|
3779
|
+
function registerAppRequest(builder, spec, context, handler) {
|
|
3780
|
+
builder.onReceiveRequest(spec.method, (params) => parseParams(spec.params, params), async (params, responder, cx) => {
|
|
3781
|
+
const response = await handler(context(params, cx, responder.signal, responder.id));
|
|
3782
|
+
await responder.respond(spec.mapResponse ? spec.mapResponse(response) : response);
|
|
3783
|
+
});
|
|
3784
|
+
}
|
|
3785
|
+
function registerAppNotification(builder, spec, context, handler) {
|
|
3786
|
+
builder.onReceiveNotification(spec.method, (params) => parseParams(spec.params, params), (params, cx) => handler(context(params, cx, cx.signal)));
|
|
3787
|
+
}
|
|
3788
|
+
function specsByMethod(specs) {
|
|
3789
|
+
const byMethod = {};
|
|
3790
|
+
for (const spec of Object.values(specs)) {
|
|
3791
|
+
byMethod[spec.method] = spec;
|
|
3792
|
+
}
|
|
3793
|
+
return byMethod;
|
|
3794
|
+
}
|
|
3795
|
+
var agentRequestSpecs = {
|
|
3796
|
+
initialize: requestSpec(AGENT_METHODS.initialize, zInitializeRequest),
|
|
3797
|
+
newSession: requestSpec(AGENT_METHODS.session_new, zNewSessionRequest),
|
|
3798
|
+
loadSession: requestSpec(AGENT_METHODS.session_load, zLoadSessionRequest, emptyObjectResponse),
|
|
3799
|
+
unstable_forkSession: requestSpec(AGENT_METHODS.session_fork, zForkSessionRequest),
|
|
3800
|
+
listSessions: requestSpec(AGENT_METHODS.session_list, zListSessionsRequest),
|
|
3801
|
+
deleteSession: requestSpec(AGENT_METHODS.session_delete, zDeleteSessionRequest, emptyObjectResponse),
|
|
3802
|
+
resumeSession: requestSpec(AGENT_METHODS.session_resume, zResumeSessionRequest),
|
|
3803
|
+
closeSession: requestSpec(AGENT_METHODS.session_close, zCloseSessionRequest, emptyObjectResponse),
|
|
3804
|
+
setSessionMode: requestSpec(AGENT_METHODS.session_set_mode, zSetSessionModeRequest, emptyObjectResponse),
|
|
3805
|
+
setSessionConfigOption: requestSpec(AGENT_METHODS.session_set_config_option, zSetSessionConfigOptionRequest),
|
|
3806
|
+
authenticate: requestSpec(AGENT_METHODS.authenticate, zAuthenticateRequest, emptyObjectResponse),
|
|
3807
|
+
unstable_listProviders: requestSpec(AGENT_METHODS.providers_list, zListProvidersRequest),
|
|
3808
|
+
unstable_setProvider: requestSpec(AGENT_METHODS.providers_set, zSetProviderRequest, emptyObjectResponse),
|
|
3809
|
+
unstable_disableProvider: requestSpec(AGENT_METHODS.providers_disable, zDisableProviderRequest, emptyObjectResponse),
|
|
3810
|
+
logout: requestSpec(AGENT_METHODS.logout, zLogoutRequest, emptyObjectResponse),
|
|
3811
|
+
prompt: requestSpec(AGENT_METHODS.session_prompt, zPromptRequest),
|
|
3812
|
+
unstable_startNes: requestSpec(AGENT_METHODS.nes_start, zStartNesRequest),
|
|
3813
|
+
unstable_suggestNes: requestSpec(AGENT_METHODS.nes_suggest, zSuggestNesRequest),
|
|
3814
|
+
unstable_closeNes: requestSpec(AGENT_METHODS.nes_close, zCloseNesRequest, emptyObjectResponse)
|
|
3815
|
+
};
|
|
3816
|
+
var agentNotificationSpecs = {
|
|
3817
|
+
cancel: notificationSpec(AGENT_METHODS.session_cancel, zCancelNotification),
|
|
3818
|
+
unstable_didOpenDocument: notificationSpec(AGENT_METHODS.document_did_open, zDidOpenDocumentNotification),
|
|
3819
|
+
unstable_didChangeDocument: notificationSpec(AGENT_METHODS.document_did_change, zDidChangeDocumentNotification),
|
|
3820
|
+
unstable_didCloseDocument: notificationSpec(AGENT_METHODS.document_did_close, zDidCloseDocumentNotification),
|
|
3821
|
+
unstable_didSaveDocument: notificationSpec(AGENT_METHODS.document_did_save, zDidSaveDocumentNotification),
|
|
3822
|
+
unstable_didFocusDocument: notificationSpec(AGENT_METHODS.document_did_focus, zDidFocusDocumentNotification),
|
|
3823
|
+
unstable_acceptNes: notificationSpec(AGENT_METHODS.nes_accept, zAcceptNesNotification),
|
|
3824
|
+
unstable_rejectNes: notificationSpec(AGENT_METHODS.nes_reject, zRejectNesNotification)
|
|
3825
|
+
};
|
|
3826
|
+
var clientRequestSpecs = {
|
|
3827
|
+
requestPermission: requestSpec(CLIENT_METHODS.session_request_permission, zRequestPermissionRequest),
|
|
3828
|
+
writeTextFile: requestSpec(CLIENT_METHODS.fs_write_text_file, zWriteTextFileRequest, emptyObjectResponse),
|
|
3829
|
+
readTextFile: requestSpec(CLIENT_METHODS.fs_read_text_file, zReadTextFileRequest),
|
|
3830
|
+
createTerminal: requestSpec(CLIENT_METHODS.terminal_create, zCreateTerminalRequest),
|
|
3831
|
+
terminalOutput: requestSpec(CLIENT_METHODS.terminal_output, zTerminalOutputRequest),
|
|
3832
|
+
releaseTerminal: requestSpec(CLIENT_METHODS.terminal_release, zReleaseTerminalRequest, emptyObjectResponse),
|
|
3833
|
+
waitForTerminalExit: requestSpec(CLIENT_METHODS.terminal_wait_for_exit, zWaitForTerminalExitRequest),
|
|
3834
|
+
killTerminal: requestSpec(CLIENT_METHODS.terminal_kill, zKillTerminalRequest, emptyObjectResponse),
|
|
3835
|
+
createElicitation: requestSpec(CLIENT_METHODS.elicitation_create, zCreateElicitationRequest)
|
|
3836
|
+
};
|
|
3837
|
+
var clientNotificationSpecs = {
|
|
3838
|
+
sessionUpdate: notificationSpec(CLIENT_METHODS.session_update, zSessionNotification),
|
|
3839
|
+
completeElicitation: notificationSpec(CLIENT_METHODS.elicitation_complete, zCompleteElicitationNotification)
|
|
3840
|
+
};
|
|
3841
|
+
var agentRequestSpecsByMethod = specsByMethod(agentRequestSpecs);
|
|
3842
|
+
var agentNotificationSpecsByMethod = specsByMethod(agentNotificationSpecs);
|
|
3843
|
+
var clientRequestSpecsByMethod = specsByMethod(clientRequestSpecs);
|
|
3844
|
+
var clientNotificationSpecsByMethod = specsByMethod(clientNotificationSpecs);
|
|
3845
|
+
function agentRequestContext(params, client, signal, requestId) {
|
|
3846
|
+
return {
|
|
3847
|
+
params,
|
|
3848
|
+
requestId,
|
|
3849
|
+
signal,
|
|
3850
|
+
client
|
|
3851
|
+
};
|
|
3852
|
+
}
|
|
3853
|
+
function agentNotificationContext(params, client, signal) {
|
|
3854
|
+
return {
|
|
3855
|
+
params,
|
|
3856
|
+
signal,
|
|
3857
|
+
client
|
|
3858
|
+
};
|
|
3859
|
+
}
|
|
3860
|
+
function clientRequestContext(params, agent, signal, requestId) {
|
|
3861
|
+
return {
|
|
3862
|
+
params,
|
|
3863
|
+
requestId,
|
|
3864
|
+
signal,
|
|
3865
|
+
agent
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
function clientNotificationContext(params, agent, signal) {
|
|
3869
|
+
return {
|
|
3870
|
+
params,
|
|
3871
|
+
signal,
|
|
3872
|
+
agent
|
|
3873
|
+
};
|
|
3874
|
+
}
|
|
3875
|
+
|
|
3876
|
+
class SessionUpdateRouter {
|
|
3877
|
+
activeSessions = new Map;
|
|
3878
|
+
handleMessage(message) {
|
|
3879
|
+
if (message.kind !== "notification" || message.method !== CLIENT_METHODS.session_update) {
|
|
3880
|
+
return Handled.no(message);
|
|
3881
|
+
}
|
|
3882
|
+
const notification = zSessionNotification.parse(message.params);
|
|
3883
|
+
const update = {
|
|
3884
|
+
kind: "session_update",
|
|
3885
|
+
notification,
|
|
3886
|
+
update: notification.update
|
|
3887
|
+
};
|
|
3888
|
+
const activeSessions = this.activeSessions.get(notification.sessionId);
|
|
3889
|
+
if (activeSessions && activeSessions.size > 0) {
|
|
3890
|
+
for (const session of activeSessions) {
|
|
3891
|
+
session.enqueue(update);
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
return Handled.no(message);
|
|
3895
|
+
}
|
|
3896
|
+
attach(response, updates) {
|
|
3897
|
+
const sessions = this.activeSessions.get(response.sessionId) ?? new Set;
|
|
3898
|
+
sessions.add(updates);
|
|
3899
|
+
this.activeSessions.set(response.sessionId, sessions);
|
|
3900
|
+
return new HandlerRegistration(() => {
|
|
3901
|
+
sessions.delete(updates);
|
|
3902
|
+
if (sessions.size === 0) {
|
|
3903
|
+
this.activeSessions.delete(response.sessionId);
|
|
3904
|
+
}
|
|
3905
|
+
});
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
var sessionUpdateRouters = new WeakMap;
|
|
3909
|
+
function sessionUpdateRouter(cx) {
|
|
3910
|
+
let router = sessionUpdateRouters.get(cx);
|
|
3911
|
+
if (!router) {
|
|
3912
|
+
router = new SessionUpdateRouter;
|
|
3913
|
+
sessionUpdateRouters.set(cx, router);
|
|
3914
|
+
}
|
|
3915
|
+
return router;
|
|
3916
|
+
}
|
|
3917
|
+
function runConnectHandlers(connection, handlers) {
|
|
3918
|
+
for (const handler of handlers) {
|
|
3919
|
+
let result;
|
|
3920
|
+
try {
|
|
3921
|
+
result = handler(connection);
|
|
3922
|
+
} catch (error) {
|
|
3923
|
+
connection.close(error);
|
|
3924
|
+
throw error;
|
|
3925
|
+
}
|
|
3926
|
+
Promise.resolve(result).catch((error) => {
|
|
3927
|
+
connection.close(error);
|
|
3928
|
+
});
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
var appBuilder = Symbol("appBuilder");
|
|
3932
|
+
var runAgentConnectHandlers = Symbol("runAgentConnectHandlers");
|
|
3933
|
+
var runClientConnectHandlers = Symbol("runClientConnectHandlers");
|
|
3934
|
+
var stableConnectionOptions = { allowBatches: false };
|
|
3935
|
+
class AgentApp {
|
|
3936
|
+
builder = Connection.builder();
|
|
3937
|
+
connectHandlers = [];
|
|
3938
|
+
constructor(options = {}) {
|
|
3939
|
+
if (options.name) {
|
|
3940
|
+
this.builder.name(options.name);
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3943
|
+
[appBuilder]() {
|
|
3944
|
+
return this.builder;
|
|
3945
|
+
}
|
|
3946
|
+
[runAgentConnectHandlers](connection) {
|
|
3947
|
+
runConnectHandlers(connection, this.connectHandlers);
|
|
3948
|
+
}
|
|
3949
|
+
connect(target, options = {}) {
|
|
3950
|
+
return this.connectConnection(target, options).connection;
|
|
3951
|
+
}
|
|
3952
|
+
connectWith(target, op) {
|
|
3953
|
+
const { rawConnection, connection } = this.connectConnection(target);
|
|
3954
|
+
return rawConnection.runUntil(() => op(connection.client));
|
|
3955
|
+
}
|
|
3956
|
+
onConnect(handler) {
|
|
3957
|
+
this.connectHandlers.push(handler);
|
|
3958
|
+
return this;
|
|
3959
|
+
}
|
|
3960
|
+
onRequest(method, handlerOrParams, handler) {
|
|
3961
|
+
if (handler) {
|
|
3962
|
+
return this.request({ method, params: handlerOrParams }, handler);
|
|
3963
|
+
}
|
|
3964
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
3965
|
+
if (!spec) {
|
|
3966
|
+
throw new Error(`Unknown ACP request method '${method}'. Pass a params parser for custom methods.`);
|
|
3967
|
+
}
|
|
3968
|
+
return this.request(spec, handlerOrParams);
|
|
3969
|
+
}
|
|
3970
|
+
onNotification(method, handlerOrParams, handler) {
|
|
3971
|
+
if (handler) {
|
|
3972
|
+
return this.notification({ method, params: handlerOrParams }, handler);
|
|
3973
|
+
}
|
|
3974
|
+
const spec = agentNotificationSpecsByMethod[method];
|
|
3975
|
+
if (!spec) {
|
|
3976
|
+
throw new Error(`Unknown ACP notification method '${method}'. Pass a params parser for custom methods.`);
|
|
3977
|
+
}
|
|
3978
|
+
return this.notification(spec, handlerOrParams);
|
|
3979
|
+
}
|
|
3980
|
+
request(spec, handler) {
|
|
3981
|
+
registerAppRequest(this.builder, spec, (params, cx, signal, requestId) => agentRequestContext(params, AgentContext.create(cx, requestId), signal, requestId), handler);
|
|
3982
|
+
return this;
|
|
3983
|
+
}
|
|
3984
|
+
notification(spec, handler) {
|
|
3985
|
+
registerAppNotification(this.builder, spec, (params, cx, signal) => agentNotificationContext(params, AgentContext.create(cx), signal), handler);
|
|
3986
|
+
return this;
|
|
3987
|
+
}
|
|
3988
|
+
connectConnection(target, options = {}) {
|
|
3989
|
+
if (isStream(target)) {
|
|
3990
|
+
const state2 = this.openStreamConnection(target);
|
|
3991
|
+
if (!options.deferConnectHandlers) {
|
|
3992
|
+
this[runAgentConnectHandlers](state2.connection);
|
|
3993
|
+
}
|
|
3994
|
+
return state2;
|
|
3995
|
+
}
|
|
3996
|
+
const [thisStream, peerStream] = memoryStreamPair();
|
|
3997
|
+
const peerRawConnection = target[appBuilder]().connect(peerStream, stableConnectionOptions);
|
|
3998
|
+
const peerConnection = clientConnection(peerRawConnection);
|
|
3999
|
+
const state = this.openStreamConnection(thisStream);
|
|
4000
|
+
state.rawConnection.closed.then(() => peerConnection.close());
|
|
4001
|
+
peerRawConnection.closed.then(() => state.connection.close());
|
|
4002
|
+
try {
|
|
4003
|
+
target[runClientConnectHandlers](peerConnection);
|
|
4004
|
+
this[runAgentConnectHandlers](state.connection);
|
|
4005
|
+
} catch (error) {
|
|
4006
|
+
peerConnection.close(error);
|
|
4007
|
+
state.connection.close(error);
|
|
4008
|
+
throw error;
|
|
4009
|
+
}
|
|
4010
|
+
return state;
|
|
4011
|
+
}
|
|
4012
|
+
openStreamConnection(stream) {
|
|
4013
|
+
const rawConnection = this.builder.connect(stream, stableConnectionOptions);
|
|
4014
|
+
return {
|
|
4015
|
+
rawConnection,
|
|
4016
|
+
connection: agentConnection(rawConnection, this.connectHandlers)
|
|
4017
|
+
};
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
function client(options) {
|
|
4021
|
+
return new ClientApp(options);
|
|
4022
|
+
}
|
|
4023
|
+
|
|
4024
|
+
class ClientApp {
|
|
4025
|
+
builder = Connection.builder();
|
|
4026
|
+
connectHandlers = [];
|
|
4027
|
+
constructor(options = {}) {
|
|
4028
|
+
if (options.name) {
|
|
4029
|
+
this.builder.name(options.name);
|
|
4030
|
+
}
|
|
4031
|
+
this.builder.withHandler({
|
|
4032
|
+
handleMessage: (message, cx) => sessionUpdateRouter(cx).handleMessage(message),
|
|
4033
|
+
describe: () => "client-session-update-router"
|
|
4034
|
+
});
|
|
4035
|
+
}
|
|
4036
|
+
[appBuilder]() {
|
|
4037
|
+
return this.builder;
|
|
4038
|
+
}
|
|
4039
|
+
[runClientConnectHandlers](connection) {
|
|
4040
|
+
runConnectHandlers(connection, this.connectHandlers);
|
|
4041
|
+
}
|
|
4042
|
+
connect(target) {
|
|
4043
|
+
return this.connectConnection(target).connection;
|
|
4044
|
+
}
|
|
4045
|
+
connectWith(target, op) {
|
|
4046
|
+
const { rawConnection, connection } = this.connectConnection(target);
|
|
4047
|
+
return rawConnection.runUntil(() => op(connection.agent));
|
|
4048
|
+
}
|
|
4049
|
+
onConnect(handler) {
|
|
4050
|
+
this.connectHandlers.push(handler);
|
|
4051
|
+
return this;
|
|
4052
|
+
}
|
|
4053
|
+
onRequest(method, handlerOrParams, handler) {
|
|
4054
|
+
if (handler) {
|
|
4055
|
+
return this.request({ method, params: handlerOrParams }, handler);
|
|
4056
|
+
}
|
|
4057
|
+
const spec = clientRequestSpecsByMethod[method];
|
|
4058
|
+
if (!spec) {
|
|
4059
|
+
throw new Error(`Unknown ACP request method '${method}'. Pass a params parser for custom methods.`);
|
|
4060
|
+
}
|
|
4061
|
+
return this.request(spec, handlerOrParams);
|
|
4062
|
+
}
|
|
4063
|
+
onNotification(method, handlerOrParams, handler) {
|
|
4064
|
+
if (handler) {
|
|
4065
|
+
return this.notification({ method, params: handlerOrParams }, handler);
|
|
4066
|
+
}
|
|
4067
|
+
const spec = clientNotificationSpecsByMethod[method];
|
|
4068
|
+
if (!spec) {
|
|
4069
|
+
throw new Error(`Unknown ACP notification method '${method}'. Pass a params parser for custom methods.`);
|
|
4070
|
+
}
|
|
4071
|
+
return this.notification(spec, handlerOrParams);
|
|
4072
|
+
}
|
|
4073
|
+
request(spec, handler) {
|
|
4074
|
+
registerAppRequest(this.builder, spec, (params, cx, signal, requestId) => clientRequestContext(params, ClientContext.create(cx, requestId), signal, requestId), handler);
|
|
4075
|
+
return this;
|
|
4076
|
+
}
|
|
4077
|
+
notification(spec, handler) {
|
|
4078
|
+
registerAppNotification(this.builder, spec, (params, cx, signal) => clientNotificationContext(params, ClientContext.create(cx), signal), handler);
|
|
4079
|
+
return this;
|
|
4080
|
+
}
|
|
4081
|
+
connectConnection(target) {
|
|
4082
|
+
if (isStream(target)) {
|
|
4083
|
+
const state2 = this.openStreamConnection(target);
|
|
4084
|
+
this[runClientConnectHandlers](state2.connection);
|
|
4085
|
+
return state2;
|
|
4086
|
+
}
|
|
4087
|
+
const [thisStream, peerStream] = memoryStreamPair();
|
|
4088
|
+
const peerRawConnection = target[appBuilder]().connect(peerStream, stableConnectionOptions);
|
|
4089
|
+
const peerConnection = agentConnection(peerRawConnection);
|
|
4090
|
+
const state = this.openStreamConnection(thisStream);
|
|
4091
|
+
state.rawConnection.closed.then(() => peerConnection.close());
|
|
4092
|
+
peerRawConnection.closed.then(() => state.connection.close());
|
|
4093
|
+
try {
|
|
4094
|
+
target[runAgentConnectHandlers](peerConnection);
|
|
4095
|
+
this[runClientConnectHandlers](state.connection);
|
|
4096
|
+
} catch (error) {
|
|
4097
|
+
peerConnection.close(error);
|
|
4098
|
+
state.connection.close(error);
|
|
4099
|
+
throw error;
|
|
4100
|
+
}
|
|
4101
|
+
return state;
|
|
4102
|
+
}
|
|
4103
|
+
openStreamConnection(stream) {
|
|
4104
|
+
const rawConnection = this.builder.connect(stream, stableConnectionOptions);
|
|
4105
|
+
return {
|
|
4106
|
+
rawConnection,
|
|
4107
|
+
connection: clientConnection(rawConnection, this.connectHandlers)
|
|
4108
|
+
};
|
|
4109
|
+
}
|
|
4110
|
+
}
|
|
4111
|
+
var legacyAgentRequestMethods = new Set([
|
|
4112
|
+
AGENT_METHODS.initialize,
|
|
4113
|
+
AGENT_METHODS.authenticate,
|
|
4114
|
+
AGENT_METHODS.providers_list,
|
|
4115
|
+
AGENT_METHODS.providers_set,
|
|
4116
|
+
AGENT_METHODS.providers_disable,
|
|
4117
|
+
AGENT_METHODS.session_new,
|
|
4118
|
+
AGENT_METHODS.session_load,
|
|
4119
|
+
AGENT_METHODS.session_set_mode,
|
|
4120
|
+
AGENT_METHODS.session_set_config_option,
|
|
4121
|
+
AGENT_METHODS.session_prompt,
|
|
4122
|
+
AGENT_METHODS.session_list,
|
|
4123
|
+
AGENT_METHODS.session_delete,
|
|
4124
|
+
AGENT_METHODS.session_fork,
|
|
4125
|
+
AGENT_METHODS.session_resume,
|
|
4126
|
+
AGENT_METHODS.session_close,
|
|
4127
|
+
AGENT_METHODS.logout,
|
|
4128
|
+
AGENT_METHODS.nes_start,
|
|
4129
|
+
AGENT_METHODS.nes_suggest,
|
|
4130
|
+
AGENT_METHODS.nes_close
|
|
4131
|
+
]);
|
|
4132
|
+
var legacyAgentNotificationMethods = new Set([
|
|
4133
|
+
AGENT_METHODS.session_cancel,
|
|
4134
|
+
AGENT_METHODS.nes_accept,
|
|
4135
|
+
AGENT_METHODS.nes_reject,
|
|
4136
|
+
AGENT_METHODS.document_did_open,
|
|
4137
|
+
AGENT_METHODS.document_did_change,
|
|
4138
|
+
AGENT_METHODS.document_did_close,
|
|
4139
|
+
AGENT_METHODS.document_did_save,
|
|
4140
|
+
AGENT_METHODS.document_did_focus
|
|
4141
|
+
]);
|
|
4142
|
+
var legacyClientRequestMethods = new Set([
|
|
4143
|
+
CLIENT_METHODS.session_request_permission,
|
|
4144
|
+
CLIENT_METHODS.fs_write_text_file,
|
|
4145
|
+
CLIENT_METHODS.fs_read_text_file,
|
|
4146
|
+
CLIENT_METHODS.terminal_create,
|
|
4147
|
+
CLIENT_METHODS.terminal_output,
|
|
4148
|
+
CLIENT_METHODS.terminal_release,
|
|
4149
|
+
CLIENT_METHODS.terminal_wait_for_exit,
|
|
4150
|
+
CLIENT_METHODS.terminal_kill,
|
|
4151
|
+
CLIENT_METHODS.elicitation_create
|
|
4152
|
+
]);
|
|
4153
|
+
var legacyClientNotificationMethods = new Set([
|
|
4154
|
+
CLIENT_METHODS.session_update,
|
|
4155
|
+
CLIENT_METHODS.elicitation_complete
|
|
4156
|
+
]);
|
|
4157
|
+
function legacyClientApp(implementation) {
|
|
4158
|
+
const app = client().onRequest(CLIENT_METHODS.session_request_permission, (ctx) => implementation.requestPermission(ctx.params)).onNotification(CLIENT_METHODS.session_update, (ctx) => implementation.sessionUpdate(ctx.params)).onRequest(CLIENT_METHODS.fs_write_text_file, async (ctx) => await implementation.writeTextFile?.(ctx.params) ?? {}).onRequest(CLIENT_METHODS.fs_read_text_file, async (ctx) => await implementation.readTextFile?.(ctx.params)).onRequest(CLIENT_METHODS.terminal_create, async (ctx) => await implementation.createTerminal?.(ctx.params)).onRequest(CLIENT_METHODS.terminal_output, async (ctx) => await implementation.terminalOutput?.(ctx.params)).onRequest(CLIENT_METHODS.terminal_release, async (ctx) => await implementation.releaseTerminal?.(ctx.params) ?? {}).onRequest(CLIENT_METHODS.terminal_wait_for_exit, async (ctx) => await implementation.waitForTerminalExit?.(ctx.params)).onRequest(CLIENT_METHODS.terminal_kill, async (ctx) => await implementation.killTerminal?.(ctx.params) ?? {});
|
|
4159
|
+
if (implementation.createElicitation) {
|
|
4160
|
+
app.onRequest(CLIENT_METHODS.elicitation_create, (ctx) => implementation.createElicitation(ctx.params));
|
|
4161
|
+
}
|
|
4162
|
+
if (implementation.completeElicitation) {
|
|
4163
|
+
app.onNotification(CLIENT_METHODS.elicitation_complete, (ctx) => implementation.completeElicitation(ctx.params));
|
|
4164
|
+
}
|
|
4165
|
+
if (implementation.extMethod) {
|
|
4166
|
+
app[appBuilder]().withHandler({
|
|
4167
|
+
handleMessage: async (message) => {
|
|
4168
|
+
if (message.kind !== "request" || legacyClientRequestMethods.has(message.method)) {
|
|
4169
|
+
return Handled.no(message);
|
|
4170
|
+
}
|
|
4171
|
+
await message.responder.respond(await implementation.extMethod(message.method, message.params));
|
|
4172
|
+
return Handled.yes();
|
|
4173
|
+
},
|
|
4174
|
+
describe: () => "legacy-client-extension-request"
|
|
4175
|
+
});
|
|
4176
|
+
}
|
|
4177
|
+
if (implementation.extNotification) {
|
|
4178
|
+
app[appBuilder]().withHandler({
|
|
4179
|
+
handleMessage: async (message) => {
|
|
4180
|
+
if (message.kind !== "notification" || legacyClientNotificationMethods.has(message.method)) {
|
|
4181
|
+
return Handled.no(message);
|
|
4182
|
+
}
|
|
4183
|
+
await implementation.extNotification(message.method, message.params);
|
|
4184
|
+
return Handled.yes();
|
|
4185
|
+
},
|
|
4186
|
+
describe: () => "legacy-client-extension-notification"
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
return app;
|
|
4190
|
+
}
|
|
4191
|
+
class TerminalHandle {
|
|
4192
|
+
id;
|
|
4193
|
+
sessionId;
|
|
4194
|
+
connection;
|
|
4195
|
+
constructor(id, sessionId, conn) {
|
|
4196
|
+
this.id = id;
|
|
4197
|
+
this.sessionId = sessionId;
|
|
4198
|
+
this.connection = conn;
|
|
4199
|
+
}
|
|
4200
|
+
static create(id, sessionId, conn) {
|
|
4201
|
+
return new TerminalHandle(id, sessionId, conn);
|
|
4202
|
+
}
|
|
4203
|
+
currentOutput() {
|
|
4204
|
+
return this.connection.sendRequest(CLIENT_METHODS.terminal_output, {
|
|
4205
|
+
sessionId: this.sessionId,
|
|
4206
|
+
terminalId: this.id
|
|
4207
|
+
});
|
|
4208
|
+
}
|
|
4209
|
+
waitForExit() {
|
|
4210
|
+
return this.connection.sendRequest(CLIENT_METHODS.terminal_wait_for_exit, {
|
|
4211
|
+
sessionId: this.sessionId,
|
|
4212
|
+
terminalId: this.id
|
|
4213
|
+
});
|
|
4214
|
+
}
|
|
4215
|
+
kill() {
|
|
4216
|
+
return this.connection.sendRequest(CLIENT_METHODS.terminal_kill, {
|
|
4217
|
+
sessionId: this.sessionId,
|
|
4218
|
+
terminalId: this.id
|
|
4219
|
+
}, emptyObjectResponse);
|
|
4220
|
+
}
|
|
4221
|
+
release() {
|
|
4222
|
+
return this.connection.sendRequest(CLIENT_METHODS.terminal_release, {
|
|
4223
|
+
sessionId: this.sessionId,
|
|
4224
|
+
terminalId: this.id
|
|
4225
|
+
}, emptyObjectResponse);
|
|
4226
|
+
}
|
|
4227
|
+
async[Symbol.asyncDispose]() {
|
|
4228
|
+
await this.release();
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
|
|
4232
|
+
class ClientSideConnection {
|
|
4233
|
+
connection;
|
|
4234
|
+
constructor(toClient, stream) {
|
|
4235
|
+
this.connection = legacyClientApp(toClient(this))[appBuilder]().connect(stream, stableConnectionOptions);
|
|
4236
|
+
}
|
|
4237
|
+
initialize(params) {
|
|
4238
|
+
return this.connection.sendRequest(AGENT_METHODS.initialize, params);
|
|
4239
|
+
}
|
|
4240
|
+
newSession(params) {
|
|
4241
|
+
return this.connection.sendRequest(AGENT_METHODS.session_new, params);
|
|
4242
|
+
}
|
|
4243
|
+
loadSession(params) {
|
|
4244
|
+
return this.connection.sendRequest(AGENT_METHODS.session_load, params, emptyObjectResponse);
|
|
4245
|
+
}
|
|
4246
|
+
unstable_forkSession(params) {
|
|
4247
|
+
return this.connection.sendRequest(AGENT_METHODS.session_fork, params);
|
|
4248
|
+
}
|
|
4249
|
+
listSessions(params) {
|
|
4250
|
+
return this.connection.sendRequest(AGENT_METHODS.session_list, params);
|
|
4251
|
+
}
|
|
4252
|
+
deleteSession(params) {
|
|
4253
|
+
return this.connection.sendRequest(AGENT_METHODS.session_delete, params, emptyObjectResponse);
|
|
4254
|
+
}
|
|
4255
|
+
resumeSession(params) {
|
|
4256
|
+
return this.connection.sendRequest(AGENT_METHODS.session_resume, params);
|
|
4257
|
+
}
|
|
4258
|
+
closeSession(params) {
|
|
4259
|
+
return this.connection.sendRequest(AGENT_METHODS.session_close, params, emptyObjectResponse);
|
|
4260
|
+
}
|
|
4261
|
+
setSessionMode(params) {
|
|
4262
|
+
return this.connection.sendRequest(AGENT_METHODS.session_set_mode, params, emptyObjectResponse);
|
|
4263
|
+
}
|
|
4264
|
+
setSessionConfigOption(params) {
|
|
4265
|
+
return this.connection.sendRequest(AGENT_METHODS.session_set_config_option, params);
|
|
4266
|
+
}
|
|
4267
|
+
authenticate(params) {
|
|
4268
|
+
return this.connection.sendRequest(AGENT_METHODS.authenticate, params, emptyObjectResponse);
|
|
4269
|
+
}
|
|
4270
|
+
unstable_listProviders(params) {
|
|
4271
|
+
return this.connection.sendRequest(AGENT_METHODS.providers_list, params);
|
|
4272
|
+
}
|
|
4273
|
+
unstable_setProvider(params) {
|
|
4274
|
+
return this.connection.sendRequest(AGENT_METHODS.providers_set, params, emptyObjectResponse);
|
|
4275
|
+
}
|
|
4276
|
+
unstable_disableProvider(params) {
|
|
4277
|
+
return this.connection.sendRequest(AGENT_METHODS.providers_disable, params, emptyObjectResponse);
|
|
4278
|
+
}
|
|
4279
|
+
logout(params) {
|
|
4280
|
+
return this.connection.sendRequest(AGENT_METHODS.logout, params, emptyObjectResponse);
|
|
4281
|
+
}
|
|
4282
|
+
prompt(params) {
|
|
4283
|
+
return this.connection.sendRequest(AGENT_METHODS.session_prompt, params);
|
|
4284
|
+
}
|
|
4285
|
+
cancel(params) {
|
|
4286
|
+
return this.connection.sendNotification(AGENT_METHODS.session_cancel, params);
|
|
4287
|
+
}
|
|
4288
|
+
unstable_startNes(params) {
|
|
4289
|
+
return this.connection.sendRequest(AGENT_METHODS.nes_start, params);
|
|
4290
|
+
}
|
|
4291
|
+
unstable_suggestNes(params) {
|
|
4292
|
+
return this.connection.sendRequest(AGENT_METHODS.nes_suggest, params);
|
|
4293
|
+
}
|
|
4294
|
+
unstable_closeNes(params) {
|
|
4295
|
+
return this.connection.sendRequest(AGENT_METHODS.nes_close, params, emptyObjectResponse);
|
|
4296
|
+
}
|
|
4297
|
+
unstable_didOpenDocument(params) {
|
|
4298
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_open, params);
|
|
4299
|
+
}
|
|
4300
|
+
unstable_didChangeDocument(params) {
|
|
4301
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
|
|
4302
|
+
}
|
|
4303
|
+
unstable_didCloseDocument(params) {
|
|
4304
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
|
|
4305
|
+
}
|
|
4306
|
+
unstable_didSaveDocument(params) {
|
|
4307
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
|
|
4308
|
+
}
|
|
4309
|
+
unstable_didFocusDocument(params) {
|
|
4310
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
|
|
4311
|
+
}
|
|
4312
|
+
unstable_acceptNes(params) {
|
|
4313
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
|
|
4314
|
+
}
|
|
4315
|
+
unstable_rejectNes(params) {
|
|
4316
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
|
|
4317
|
+
}
|
|
4318
|
+
request(method, params, options) {
|
|
4319
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
4320
|
+
return this.connection.sendRequest(method, params, spec?.mapResponse, options);
|
|
4321
|
+
}
|
|
4322
|
+
notify(method, params) {
|
|
4323
|
+
return this.connection.sendNotification(method, params);
|
|
4324
|
+
}
|
|
4325
|
+
extMethod(method, params) {
|
|
4326
|
+
return this.request(method, params);
|
|
4327
|
+
}
|
|
4328
|
+
extNotification(method, params) {
|
|
4329
|
+
return this.notify(method, params);
|
|
4330
|
+
}
|
|
4331
|
+
get signal() {
|
|
4332
|
+
return this.connection.signal;
|
|
4333
|
+
}
|
|
4334
|
+
get closed() {
|
|
4335
|
+
return this.connection.closed;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
|
|
4339
|
+
// src/providers/acp-adapter.ts
|
|
4340
|
+
init_package();
|
|
4341
|
+
init_secret_scrubber();
|
|
4342
|
+
|
|
4343
|
+
// src/providers/acp-swarm-events.ts
|
|
4344
|
+
function contentToText(content) {
|
|
4345
|
+
if (content.type === "text")
|
|
4346
|
+
return content.text;
|
|
4347
|
+
return JSON.stringify(content);
|
|
4348
|
+
}
|
|
4349
|
+
function toolName(update) {
|
|
4350
|
+
return update.title ?? update.kind ?? "tool";
|
|
4351
|
+
}
|
|
4352
|
+
function toolResult(update) {
|
|
4353
|
+
return {
|
|
4354
|
+
status: update.status,
|
|
4355
|
+
content: update.content,
|
|
4356
|
+
rawOutput: update.rawOutput,
|
|
4357
|
+
locations: update.locations
|
|
4358
|
+
};
|
|
4359
|
+
}
|
|
4360
|
+
function translateAcpSessionUpdate(update) {
|
|
4361
|
+
switch (update.sessionUpdate) {
|
|
4362
|
+
case "agent_message_chunk":
|
|
4363
|
+
return [{ type: "message", role: "assistant", content: contentToText(update.content) }];
|
|
4364
|
+
case "user_message_chunk":
|
|
4365
|
+
return [{ type: "message", role: "user", content: contentToText(update.content) }];
|
|
4366
|
+
case "agent_thought_chunk":
|
|
4367
|
+
return [
|
|
4368
|
+
{
|
|
4369
|
+
type: "custom",
|
|
4370
|
+
name: "acp_agent_thought_chunk",
|
|
4371
|
+
data: { content: update.content, messageId: update.messageId ?? null }
|
|
4372
|
+
}
|
|
4373
|
+
];
|
|
4374
|
+
case "tool_call":
|
|
4375
|
+
return [
|
|
4376
|
+
{
|
|
4377
|
+
type: "tool_start",
|
|
4378
|
+
toolCallId: update.toolCallId,
|
|
4379
|
+
toolName: toolName(update),
|
|
4380
|
+
args: update.rawInput ?? update.content ?? null
|
|
4381
|
+
}
|
|
4382
|
+
];
|
|
4383
|
+
case "tool_call_update": {
|
|
4384
|
+
if (update.status === "completed" || update.status === "failed") {
|
|
4385
|
+
return [
|
|
4386
|
+
{
|
|
4387
|
+
type: "tool_end",
|
|
4388
|
+
toolCallId: update.toolCallId,
|
|
4389
|
+
toolName: toolName(update),
|
|
4390
|
+
result: toolResult(update)
|
|
4391
|
+
}
|
|
4392
|
+
];
|
|
4393
|
+
}
|
|
4394
|
+
return [
|
|
4395
|
+
{
|
|
4396
|
+
type: "progress",
|
|
4397
|
+
message: `ACP tool ${update.toolCallId}${update.status ? ` ${update.status}` : " updated"}`
|
|
4398
|
+
},
|
|
4399
|
+
{
|
|
4400
|
+
type: "custom",
|
|
4401
|
+
name: "acp_tool_call_update",
|
|
4402
|
+
data: update
|
|
4403
|
+
}
|
|
4404
|
+
];
|
|
4405
|
+
}
|
|
4406
|
+
case "current_mode_update":
|
|
4407
|
+
return [{ type: "custom", name: "acp_current_mode_update", data: update }];
|
|
4408
|
+
case "plan":
|
|
4409
|
+
return [{ type: "custom", name: "acp_plan", data: update }];
|
|
4410
|
+
case "available_commands_update":
|
|
4411
|
+
return [{ type: "custom", name: "acp_available_commands_update", data: update }];
|
|
4412
|
+
case "config_option_update":
|
|
4413
|
+
return [{ type: "custom", name: "acp_config_option_update", data: update }];
|
|
4414
|
+
case "session_info_update":
|
|
4415
|
+
return [{ type: "custom", name: "acp_session_info_update", data: update }];
|
|
4416
|
+
case "usage_update":
|
|
4417
|
+
return [
|
|
4418
|
+
{
|
|
4419
|
+
type: "context_usage",
|
|
4420
|
+
contextUsedTokens: update.used,
|
|
4421
|
+
contextTotalTokens: update.size,
|
|
4422
|
+
contextPercent: update.size > 0 ? update.used / update.size : null,
|
|
4423
|
+
outputTokens: null,
|
|
4424
|
+
contextFormula: "harness-reported"
|
|
4425
|
+
}
|
|
4426
|
+
];
|
|
4427
|
+
default:
|
|
4428
|
+
return [
|
|
4429
|
+
{
|
|
4430
|
+
type: "custom",
|
|
4431
|
+
name: `acp_${update.sessionUpdate}`,
|
|
4432
|
+
data: update
|
|
4433
|
+
}
|
|
4434
|
+
];
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
function translateAcpSessionNotification(notification) {
|
|
4438
|
+
return translateAcpSessionUpdate(notification.update);
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
// src/providers/acp-targets.ts
|
|
4442
|
+
import { join } from "node:path";
|
|
4443
|
+
|
|
4444
|
+
class AcpTargetResolutionError extends Error {
|
|
4445
|
+
constructor(message) {
|
|
4446
|
+
super(message);
|
|
4447
|
+
this.name = "AcpTargetResolutionError";
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
var BASE_ENV_KEYS = [
|
|
4451
|
+
"PATH",
|
|
4452
|
+
"HOME",
|
|
4453
|
+
"TMPDIR",
|
|
4454
|
+
"TMP",
|
|
4455
|
+
"TEMP",
|
|
4456
|
+
"SHELL",
|
|
4457
|
+
"USER",
|
|
4458
|
+
"LOGNAME",
|
|
4459
|
+
"LANG",
|
|
4460
|
+
"LC_ALL",
|
|
4461
|
+
"BUN_INSTALL",
|
|
4462
|
+
"NODE_PATH"
|
|
4463
|
+
];
|
|
4464
|
+
function readEnv(config, key) {
|
|
4465
|
+
return config.env?.[key] ?? process.env[key];
|
|
4466
|
+
}
|
|
4467
|
+
function baseTargetEnv(config) {
|
|
4468
|
+
const env = {};
|
|
4469
|
+
for (const key of BASE_ENV_KEYS) {
|
|
4470
|
+
const value = readEnv(config, key);
|
|
4471
|
+
if (value)
|
|
4472
|
+
env[key] = value;
|
|
4473
|
+
}
|
|
4474
|
+
return env;
|
|
4475
|
+
}
|
|
4476
|
+
function parseCommand(command, args) {
|
|
4477
|
+
const trimmed = command.trim();
|
|
4478
|
+
if (!trimmed) {
|
|
4479
|
+
throw new AcpTargetResolutionError("ACP target command is empty. Set ACP_TARGET_COMMAND to an ACP-compatible executable.");
|
|
4480
|
+
}
|
|
4481
|
+
if (args?.trim()) {
|
|
4482
|
+
try {
|
|
4483
|
+
const parsed = JSON.parse(args);
|
|
4484
|
+
if (Array.isArray(parsed) && parsed.every((part) => typeof part === "string")) {
|
|
4485
|
+
return [trimmed, ...parsed];
|
|
4486
|
+
}
|
|
4487
|
+
} catch {}
|
|
4488
|
+
return [trimmed, ...args.trim().split(/\s+/).filter(Boolean)];
|
|
4489
|
+
}
|
|
4490
|
+
return trimmed.split(/\s+/).filter(Boolean);
|
|
4491
|
+
}
|
|
4492
|
+
var customTargetProfile = {
|
|
4493
|
+
target: "custom",
|
|
4494
|
+
command(config) {
|
|
4495
|
+
const command = readEnv(config, "ACP_TARGET_COMMAND") ?? readEnv(config, "ACP_COMMAND");
|
|
4496
|
+
if (!command) {
|
|
4497
|
+
throw new AcpTargetResolutionError("No ACP target configured. Set ACP_TARGET_COMMAND to an ACP-compatible executable before using HARNESS_PROVIDER=acp.");
|
|
4498
|
+
}
|
|
4499
|
+
return parseCommand(command, readEnv(config, "ACP_TARGET_ARGS"));
|
|
4500
|
+
},
|
|
4501
|
+
env(config) {
|
|
4502
|
+
return baseTargetEnv(config);
|
|
4503
|
+
},
|
|
4504
|
+
async writeSystemPromptArtifact(config) {
|
|
4505
|
+
const relativePath = readEnv(config, "ACP_SYSTEM_PROMPT_PATH");
|
|
4506
|
+
if (!relativePath)
|
|
4507
|
+
return;
|
|
4508
|
+
const targetPath = relativePath.startsWith("/") ? relativePath : join(config.cwd, relativePath);
|
|
4509
|
+
await Bun.write(targetPath, config.systemPrompt ?? "");
|
|
4510
|
+
}
|
|
4511
|
+
};
|
|
4512
|
+
function resolveAcpTarget(config) {
|
|
4513
|
+
const target = readEnv(config, "ACP_TARGET") ?? "custom";
|
|
4514
|
+
switch (target) {
|
|
4515
|
+
case "custom":
|
|
4516
|
+
return customTargetProfile;
|
|
4517
|
+
default:
|
|
4518
|
+
throw new AcpTargetResolutionError(`Unsupported ACP target "${target}". Only the generic "custom" target exists today — leave ACP_TARGET unset and point ACP_TARGET_COMMAND at your ACP agent.`);
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
|
|
4522
|
+
// src/providers/acp-adapter.ts
|
|
4523
|
+
class SwarmAcpClient {
|
|
4524
|
+
emit;
|
|
4525
|
+
constructor(emit) {
|
|
4526
|
+
this.emit = emit;
|
|
4527
|
+
}
|
|
4528
|
+
async requestPermission(params) {
|
|
4529
|
+
const selected = params.options.find((option) => option.kind === "allow_always") ?? params.options.find((option) => option.kind === "allow_once") ?? params.options[0];
|
|
4530
|
+
if (!selected)
|
|
4531
|
+
return { outcome: { outcome: "cancelled" } };
|
|
4532
|
+
return { outcome: { outcome: "selected", optionId: selected.optionId } };
|
|
4533
|
+
}
|
|
4534
|
+
async sessionUpdate(params) {
|
|
4535
|
+
for (const event of translateAcpSessionNotification(params)) {
|
|
4536
|
+
this.emit(event);
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
class ACPSession {
|
|
4542
|
+
connection;
|
|
4543
|
+
process;
|
|
4544
|
+
config;
|
|
4545
|
+
sessionId;
|
|
4546
|
+
listeners = new Set;
|
|
4547
|
+
pendingEvents = [];
|
|
4548
|
+
startedAt = Date.now();
|
|
4549
|
+
completed = false;
|
|
4550
|
+
aborted = false;
|
|
4551
|
+
output = "";
|
|
4552
|
+
completionPromise;
|
|
4553
|
+
completionResolve;
|
|
4554
|
+
constructor(connection, process2, config, sessionId) {
|
|
4555
|
+
this.connection = connection;
|
|
4556
|
+
this.process = process2;
|
|
4557
|
+
this.config = config;
|
|
4558
|
+
this.sessionId = sessionId;
|
|
4559
|
+
this.completionPromise = new Promise((resolve) => {
|
|
4560
|
+
this.completionResolve = resolve;
|
|
4561
|
+
});
|
|
4562
|
+
this.consumeStderr();
|
|
4563
|
+
this.emit({ type: "session_init", sessionId, provider: "acp" });
|
|
4564
|
+
this.runPrompt();
|
|
4565
|
+
}
|
|
4566
|
+
onEvent(listener) {
|
|
4567
|
+
this.listeners.add(listener);
|
|
4568
|
+
for (const event of this.pendingEvents.splice(0)) {
|
|
4569
|
+
listener(event);
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
waitForCompletion() {
|
|
4573
|
+
return this.completionPromise;
|
|
4574
|
+
}
|
|
4575
|
+
async abort() {
|
|
4576
|
+
if (this.aborted)
|
|
4577
|
+
return;
|
|
4578
|
+
this.aborted = true;
|
|
4579
|
+
try {
|
|
4580
|
+
await this.connection.cancel({ sessionId: this.sessionId });
|
|
4581
|
+
} catch (err) {
|
|
4582
|
+
this.emit({
|
|
4583
|
+
type: "error",
|
|
4584
|
+
message: scrubSecrets(`ACP session/cancel failed: ${formatError(err)}`),
|
|
4585
|
+
category: "abort"
|
|
4586
|
+
});
|
|
4587
|
+
}
|
|
4588
|
+
this.process.kill();
|
|
4589
|
+
this.finish({
|
|
4590
|
+
exitCode: 1,
|
|
4591
|
+
sessionId: this.sessionId,
|
|
4592
|
+
isError: true,
|
|
4593
|
+
failureReason: "aborted"
|
|
4594
|
+
});
|
|
4595
|
+
}
|
|
4596
|
+
emitFromAcp(event) {
|
|
4597
|
+
this.emit(event);
|
|
4598
|
+
}
|
|
4599
|
+
emit(event) {
|
|
4600
|
+
if (event.type === "message" && event.role === "assistant") {
|
|
4601
|
+
this.output += event.content;
|
|
4602
|
+
}
|
|
4603
|
+
if (this.listeners.size === 0) {
|
|
4604
|
+
this.pendingEvents.push(event);
|
|
4605
|
+
return;
|
|
4606
|
+
}
|
|
4607
|
+
for (const listener of this.listeners) {
|
|
4608
|
+
listener(event);
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
async runPrompt() {
|
|
4612
|
+
try {
|
|
4613
|
+
const response = await this.connection.prompt({
|
|
4614
|
+
sessionId: this.sessionId,
|
|
4615
|
+
prompt: [{ type: "text", text: this.config.prompt }]
|
|
4616
|
+
});
|
|
4617
|
+
const isError = response.stopReason === "refusal" || response.stopReason === "cancelled";
|
|
4618
|
+
const cost = this.buildCostData(isError);
|
|
4619
|
+
const result = {
|
|
4620
|
+
exitCode: isError ? 1 : 0,
|
|
4621
|
+
sessionId: this.sessionId,
|
|
4622
|
+
cost,
|
|
4623
|
+
output: this.output,
|
|
4624
|
+
isError,
|
|
4625
|
+
failureReason: isError ? `ACP prompt stopped with ${response.stopReason}` : undefined
|
|
4626
|
+
};
|
|
4627
|
+
this.emit({ type: "result", cost, output: this.output, isError });
|
|
4628
|
+
this.finish(result);
|
|
4629
|
+
} catch (err) {
|
|
4630
|
+
const message = scrubSecrets(formatError(err));
|
|
4631
|
+
this.emit({ type: "error", message, category: "protocol" });
|
|
4632
|
+
this.finish({
|
|
4633
|
+
exitCode: 1,
|
|
4634
|
+
sessionId: this.sessionId,
|
|
4635
|
+
isError: true,
|
|
4636
|
+
failureReason: `ACP prompt failed: ${message}`
|
|
4637
|
+
});
|
|
4638
|
+
} finally {
|
|
4639
|
+
this.process.kill();
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
async consumeStderr() {
|
|
4643
|
+
const stderr = this.process.stderr;
|
|
4644
|
+
if (!stderr)
|
|
4645
|
+
return;
|
|
4646
|
+
const reader = stderr.getReader();
|
|
4647
|
+
const decoder = new TextDecoder;
|
|
4648
|
+
try {
|
|
4649
|
+
while (true) {
|
|
4650
|
+
const { done, value } = await reader.read();
|
|
4651
|
+
if (done)
|
|
4652
|
+
break;
|
|
4653
|
+
if (value.length > 0) {
|
|
4654
|
+
this.emit({ type: "raw_stderr", content: scrubSecrets(decoder.decode(value)) });
|
|
4655
|
+
}
|
|
4656
|
+
}
|
|
4657
|
+
} catch {}
|
|
4658
|
+
}
|
|
4659
|
+
buildCostData(isError) {
|
|
4660
|
+
return {
|
|
4661
|
+
sessionId: this.sessionId,
|
|
4662
|
+
taskId: this.config.taskId,
|
|
4663
|
+
agentId: this.config.agentId,
|
|
4664
|
+
totalCostUsd: 0,
|
|
4665
|
+
durationMs: Date.now() - this.startedAt,
|
|
4666
|
+
numTurns: 1,
|
|
4667
|
+
model: this.config.model,
|
|
4668
|
+
isError,
|
|
4669
|
+
provider: "acp"
|
|
4670
|
+
};
|
|
4671
|
+
}
|
|
4672
|
+
finish(result) {
|
|
4673
|
+
if (this.completed)
|
|
4674
|
+
return;
|
|
4675
|
+
this.completed = true;
|
|
4676
|
+
this.completionResolve(result);
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
class ACPAdapter {
|
|
4681
|
+
name = "acp";
|
|
4682
|
+
traits = {
|
|
4683
|
+
hasMcp: true,
|
|
4684
|
+
hasLocalEnvironment: true
|
|
4685
|
+
};
|
|
4686
|
+
async createSession(config) {
|
|
4687
|
+
const target = resolveAcpTarget(config);
|
|
4688
|
+
await target.writeSystemPromptArtifact(config);
|
|
4689
|
+
const command = target.command(config);
|
|
4690
|
+
const proc = Bun.spawn(command, {
|
|
4691
|
+
cwd: config.cwd,
|
|
4692
|
+
env: target.env(config),
|
|
4693
|
+
stdin: "pipe",
|
|
4694
|
+
stdout: "pipe",
|
|
4695
|
+
stderr: "pipe"
|
|
4696
|
+
});
|
|
4697
|
+
let session = null;
|
|
4698
|
+
const client2 = new SwarmAcpClient((event) => session?.emitFromAcp(event));
|
|
4699
|
+
const stream = ndJsonStream2(fileSinkWritableStream(proc.stdin), proc.stdout);
|
|
4700
|
+
const connection = new ClientSideConnection(() => client2, stream);
|
|
4701
|
+
try {
|
|
4702
|
+
await connection.initialize({
|
|
4703
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
4704
|
+
clientInfo: { name: "agent-swarm", version: package_default.version },
|
|
4705
|
+
clientCapabilities: {}
|
|
4706
|
+
});
|
|
4707
|
+
const installedServers = await fetchInstalledMcpServers(config.apiUrl, config.apiKey, config.agentId, "claude");
|
|
4708
|
+
const newSession = await connection.newSession({
|
|
4709
|
+
cwd: config.cwd,
|
|
4710
|
+
mcpServers: [
|
|
4711
|
+
{
|
|
4712
|
+
type: "http",
|
|
4713
|
+
name: "swarm",
|
|
4714
|
+
url: `${config.apiUrl.replace(/\/+$/, "")}/mcp`,
|
|
4715
|
+
headers: [
|
|
4716
|
+
{ name: "Authorization", value: `Bearer ${config.apiKey}` },
|
|
4717
|
+
{ name: "X-Agent-ID", value: config.agentId },
|
|
4718
|
+
{ name: "X-Source-Task-Id", value: config.taskId }
|
|
4719
|
+
]
|
|
4720
|
+
},
|
|
4721
|
+
...toAcpMcpServers(installedServers)
|
|
4722
|
+
]
|
|
4723
|
+
});
|
|
4724
|
+
session = new ACPSession(connection, proc, config, newSession.sessionId);
|
|
4725
|
+
return session;
|
|
4726
|
+
} catch (err) {
|
|
4727
|
+
proc.kill();
|
|
4728
|
+
throw new Error(`ACP target failed during startup: ${scrubSecrets(formatError(err))}`);
|
|
4729
|
+
}
|
|
4730
|
+
}
|
|
4731
|
+
async canResume(_sessionId) {
|
|
4732
|
+
return false;
|
|
4733
|
+
}
|
|
4734
|
+
formatCommand(commandName) {
|
|
4735
|
+
return `/${commandName}`;
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
function toAcpMcpServers(installed) {
|
|
4739
|
+
if (!installed)
|
|
4740
|
+
return [];
|
|
4741
|
+
const servers = [];
|
|
4742
|
+
for (const [name, entry] of Object.entries(installed)) {
|
|
4743
|
+
if (typeof entry.command === "string") {
|
|
4744
|
+
const env = entry.env ?? {};
|
|
4745
|
+
servers.push({
|
|
4746
|
+
name,
|
|
4747
|
+
command: entry.command,
|
|
4748
|
+
args: Array.isArray(entry.args) ? entry.args : [],
|
|
4749
|
+
env: Object.entries(env).map(([key, value]) => ({ name: key, value }))
|
|
4750
|
+
});
|
|
4751
|
+
continue;
|
|
4752
|
+
}
|
|
4753
|
+
if (typeof entry.url === "string") {
|
|
4754
|
+
const headers = entry.headers ?? {};
|
|
4755
|
+
servers.push({
|
|
4756
|
+
type: entry.type === "sse" ? "sse" : "http",
|
|
4757
|
+
name,
|
|
4758
|
+
url: entry.url,
|
|
4759
|
+
headers: Object.entries(headers).map(([key, value]) => ({ name: key, value }))
|
|
4760
|
+
});
|
|
4761
|
+
continue;
|
|
4762
|
+
}
|
|
4763
|
+
console.warn(`\x1B[33m[acp]\x1B[0m Skipping installed MCP server "${name}": no command or url in resolved config`);
|
|
4764
|
+
}
|
|
4765
|
+
return servers;
|
|
4766
|
+
}
|
|
4767
|
+
function formatError(err) {
|
|
4768
|
+
return err instanceof Error ? err.message : String(err);
|
|
4769
|
+
}
|
|
4770
|
+
function fileSinkWritableStream(sink) {
|
|
4771
|
+
return new WritableStream({
|
|
4772
|
+
write(chunk) {
|
|
4773
|
+
sink.write(chunk);
|
|
4774
|
+
sink.flush();
|
|
4775
|
+
},
|
|
4776
|
+
close() {
|
|
4777
|
+
sink.end();
|
|
4778
|
+
},
|
|
4779
|
+
abort() {
|
|
4780
|
+
sink.end();
|
|
4781
|
+
}
|
|
4782
|
+
});
|
|
4783
|
+
}
|
|
4784
|
+
export {
|
|
4785
|
+
ACPAdapter,
|
|
4786
|
+
toAcpMcpServers
|
|
4787
|
+
};
|