lody 0.70.2 → 0.71.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/dist/chunks/{directory-handle-Ydn6ZTye.js → directory-handle-BzxIVnuO.js} +62 -16
- package/dist/chunks/{index-BKfeSFHN.js → index-Cbwwpq6s.js} +58 -17
- package/dist/chunks/package-CCAH96XW.js +3947 -0
- package/dist/chunks/{review-viewer-BHFYVB1-.js → review-viewer-Bn33ciqG.js} +2 -2
- package/dist/chunks/{schemas-Dq_X20sw.js → schemas-CRNtikkJ.js} +22 -22
- package/dist/chunks/workspace-watch-protocol-CSO-IQeE.js +84 -0
- package/dist/claude-acp.js +7331 -38655
- package/dist/code-collab-watch-worker.js +99 -0
- package/dist/codex-acp.js +1 -1
- package/dist/file-index-scan-worker.js +2 -2
- package/dist/index.js +140327 -124612
- package/package.json +7 -7
- package/dist/chunks/package-DqzNopZM.js +0 -11
|
@@ -0,0 +1,3947 @@
|
|
|
1
|
+
import { c as array, e as unknown, N as NEVER, u as union, n as number, s as string, o as object, r as record, E as int, l as literal, b as boolean, y as intersection, F as url } from "./schemas-CRNtikkJ.js";
|
|
2
|
+
const AGENT_METHODS = {
|
|
3
|
+
initialize: "initialize",
|
|
4
|
+
authenticate: "authenticate",
|
|
5
|
+
providers_list: "providers/list",
|
|
6
|
+
providers_set: "providers/set",
|
|
7
|
+
providers_disable: "providers/disable",
|
|
8
|
+
session_new: "session/new",
|
|
9
|
+
session_load: "session/load",
|
|
10
|
+
session_set_mode: "session/set_mode",
|
|
11
|
+
session_set_config_option: "session/set_config_option",
|
|
12
|
+
session_prompt: "session/prompt",
|
|
13
|
+
session_cancel: "session/cancel",
|
|
14
|
+
session_list: "session/list",
|
|
15
|
+
session_delete: "session/delete",
|
|
16
|
+
session_fork: "session/fork",
|
|
17
|
+
session_resume: "session/resume",
|
|
18
|
+
session_close: "session/close",
|
|
19
|
+
logout: "logout",
|
|
20
|
+
nes_start: "nes/start",
|
|
21
|
+
nes_suggest: "nes/suggest",
|
|
22
|
+
nes_accept: "nes/accept",
|
|
23
|
+
nes_reject: "nes/reject",
|
|
24
|
+
nes_close: "nes/close",
|
|
25
|
+
document_did_open: "document/didOpen",
|
|
26
|
+
document_did_change: "document/didChange",
|
|
27
|
+
document_did_close: "document/didClose",
|
|
28
|
+
document_did_save: "document/didSave",
|
|
29
|
+
document_did_focus: "document/didFocus"
|
|
30
|
+
};
|
|
31
|
+
const CLIENT_METHODS = {
|
|
32
|
+
session_request_permission: "session/request_permission",
|
|
33
|
+
session_update: "session/update",
|
|
34
|
+
fs_write_text_file: "fs/write_text_file",
|
|
35
|
+
fs_read_text_file: "fs/read_text_file",
|
|
36
|
+
terminal_create: "terminal/create",
|
|
37
|
+
terminal_output: "terminal/output",
|
|
38
|
+
terminal_release: "terminal/release",
|
|
39
|
+
terminal_wait_for_exit: "terminal/wait_for_exit",
|
|
40
|
+
terminal_kill: "terminal/kill",
|
|
41
|
+
elicitation_create: "elicitation/create",
|
|
42
|
+
elicitation_complete: "elicitation/complete"
|
|
43
|
+
};
|
|
44
|
+
const PROTOCOL_VERSION = 1;
|
|
45
|
+
const skippedItem = Symbol("skippedItem");
|
|
46
|
+
function defaultOnError(schema, fallback) {
|
|
47
|
+
return schema.catch(fallback);
|
|
48
|
+
}
|
|
49
|
+
function requiredDefaultOnError(schema, fallback) {
|
|
50
|
+
const schemaWithCatch = schema.catch(fallback);
|
|
51
|
+
return unknown().transform((value, context) => {
|
|
52
|
+
if (value !== void 0)
|
|
53
|
+
return schemaWithCatch.parse(value);
|
|
54
|
+
context.addIssue({
|
|
55
|
+
code: "custom",
|
|
56
|
+
message: "Required value is missing"
|
|
57
|
+
});
|
|
58
|
+
return NEVER;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function stringTag(value, key) {
|
|
62
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
const tag = value[key];
|
|
66
|
+
return typeof tag === "string" ? tag : void 0;
|
|
67
|
+
}
|
|
68
|
+
function excludeKnownTags(schema, key, knownTags) {
|
|
69
|
+
return schema.superRefine((value, context) => {
|
|
70
|
+
const tag = stringTag(value, key);
|
|
71
|
+
if (tag !== void 0 && knownTags.includes(tag)) {
|
|
72
|
+
context.addIssue({
|
|
73
|
+
code: "custom",
|
|
74
|
+
path: [key],
|
|
75
|
+
message: `${key} ${JSON.stringify(tag)} is reserved by a known variant, but the value does not match that variant's schema`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function preserveCustomPayload(schema, key, knownTags) {
|
|
81
|
+
return unknown().transform((value, context) => {
|
|
82
|
+
const result = schema.safeParse(value);
|
|
83
|
+
if (!result.success) {
|
|
84
|
+
for (const issue of result.error.issues) {
|
|
85
|
+
context.addIssue({ ...issue, input: value });
|
|
86
|
+
}
|
|
87
|
+
return NEVER;
|
|
88
|
+
}
|
|
89
|
+
const output = result.data;
|
|
90
|
+
const tag = stringTag(value, key);
|
|
91
|
+
if (tag !== void 0 && !knownTags.includes(tag)) {
|
|
92
|
+
const raw = value;
|
|
93
|
+
for (const [property, rawValue] of Object.entries(raw)) {
|
|
94
|
+
if (property === "__proto__")
|
|
95
|
+
continue;
|
|
96
|
+
if (!Object.hasOwn(output, property))
|
|
97
|
+
output[property] = rawValue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return output;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function vecSkipError(itemSchema) {
|
|
104
|
+
return array(itemSchema.catch(skippedItem)).transform((items) => items.filter((item) => item !== skippedItem));
|
|
105
|
+
}
|
|
106
|
+
const zRequestId = union([number(), string()]).nullable();
|
|
107
|
+
const zSessionId = string();
|
|
108
|
+
const zWriteTextFileRequest = object({
|
|
109
|
+
sessionId: zSessionId,
|
|
110
|
+
path: string(),
|
|
111
|
+
content: string(),
|
|
112
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
113
|
+
});
|
|
114
|
+
const zReadTextFileRequest = object({
|
|
115
|
+
sessionId: zSessionId,
|
|
116
|
+
path: string(),
|
|
117
|
+
line: defaultOnError(int().gte(0).max(4294967295, {
|
|
118
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
119
|
+
}).nullish(), () => void 0),
|
|
120
|
+
limit: defaultOnError(int().gte(0).max(4294967295, {
|
|
121
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
122
|
+
}).nullish(), () => void 0),
|
|
123
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
124
|
+
});
|
|
125
|
+
const zToolCallId = string();
|
|
126
|
+
const zToolKind = union([
|
|
127
|
+
literal("read"),
|
|
128
|
+
literal("edit"),
|
|
129
|
+
literal("delete"),
|
|
130
|
+
literal("move"),
|
|
131
|
+
literal("search"),
|
|
132
|
+
literal("execute"),
|
|
133
|
+
literal("think"),
|
|
134
|
+
literal("fetch"),
|
|
135
|
+
literal("switch_mode"),
|
|
136
|
+
literal("other")
|
|
137
|
+
]);
|
|
138
|
+
const zToolCallStatus = union([
|
|
139
|
+
literal("pending"),
|
|
140
|
+
literal("in_progress"),
|
|
141
|
+
literal("completed"),
|
|
142
|
+
literal("failed")
|
|
143
|
+
]);
|
|
144
|
+
const zRole = union([literal("assistant"), literal("user")]);
|
|
145
|
+
const zAnnotations = object({
|
|
146
|
+
audience: defaultOnError(vecSkipError(zRole).nullish(), () => void 0),
|
|
147
|
+
lastModified: defaultOnError(string().nullish(), () => void 0),
|
|
148
|
+
priority: defaultOnError(number().nullish(), () => void 0),
|
|
149
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
150
|
+
});
|
|
151
|
+
const zTextContent = object({
|
|
152
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => void 0),
|
|
153
|
+
text: string(),
|
|
154
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
155
|
+
});
|
|
156
|
+
const zImageContent = object({
|
|
157
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => void 0),
|
|
158
|
+
data: string(),
|
|
159
|
+
mimeType: string(),
|
|
160
|
+
uri: defaultOnError(string().nullish(), () => void 0),
|
|
161
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
162
|
+
});
|
|
163
|
+
const zAudioContent = object({
|
|
164
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => void 0),
|
|
165
|
+
data: string(),
|
|
166
|
+
mimeType: string(),
|
|
167
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
168
|
+
});
|
|
169
|
+
const zResourceLink = object({
|
|
170
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => void 0),
|
|
171
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
172
|
+
mimeType: defaultOnError(string().nullish(), () => void 0),
|
|
173
|
+
name: string(),
|
|
174
|
+
size: defaultOnError(number().nullish(), () => void 0),
|
|
175
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
176
|
+
uri: string(),
|
|
177
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
178
|
+
});
|
|
179
|
+
const zTextResourceContents = object({
|
|
180
|
+
mimeType: defaultOnError(string().nullish(), () => void 0),
|
|
181
|
+
text: string(),
|
|
182
|
+
uri: string(),
|
|
183
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
184
|
+
});
|
|
185
|
+
const zBlobResourceContents = object({
|
|
186
|
+
blob: string(),
|
|
187
|
+
mimeType: defaultOnError(string().nullish(), () => void 0),
|
|
188
|
+
uri: string(),
|
|
189
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
190
|
+
});
|
|
191
|
+
const zEmbeddedResourceResource = union([
|
|
192
|
+
zTextResourceContents,
|
|
193
|
+
zBlobResourceContents
|
|
194
|
+
]);
|
|
195
|
+
const zEmbeddedResource = object({
|
|
196
|
+
annotations: defaultOnError(zAnnotations.nullish(), () => void 0),
|
|
197
|
+
resource: zEmbeddedResourceResource,
|
|
198
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
199
|
+
});
|
|
200
|
+
const zContentBlock = union([
|
|
201
|
+
zTextContent.and(object({
|
|
202
|
+
type: literal("text")
|
|
203
|
+
})),
|
|
204
|
+
zImageContent.and(object({
|
|
205
|
+
type: literal("image")
|
|
206
|
+
})),
|
|
207
|
+
zAudioContent.and(object({
|
|
208
|
+
type: literal("audio")
|
|
209
|
+
})),
|
|
210
|
+
zResourceLink.and(object({
|
|
211
|
+
type: literal("resource_link")
|
|
212
|
+
})),
|
|
213
|
+
zEmbeddedResource.and(object({
|
|
214
|
+
type: literal("resource")
|
|
215
|
+
}))
|
|
216
|
+
]);
|
|
217
|
+
const zContent = object({
|
|
218
|
+
content: zContentBlock,
|
|
219
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
220
|
+
});
|
|
221
|
+
const zDiff = object({
|
|
222
|
+
path: string(),
|
|
223
|
+
oldText: defaultOnError(string().nullish(), () => void 0),
|
|
224
|
+
newText: string(),
|
|
225
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
226
|
+
});
|
|
227
|
+
const zTerminalId = string();
|
|
228
|
+
const zTerminal = object({
|
|
229
|
+
terminalId: zTerminalId,
|
|
230
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
231
|
+
});
|
|
232
|
+
const zToolCallContent = union([
|
|
233
|
+
zContent.and(object({
|
|
234
|
+
type: literal("content")
|
|
235
|
+
})),
|
|
236
|
+
zDiff.and(object({
|
|
237
|
+
type: literal("diff")
|
|
238
|
+
})),
|
|
239
|
+
zTerminal.and(object({
|
|
240
|
+
type: literal("terminal")
|
|
241
|
+
}))
|
|
242
|
+
]);
|
|
243
|
+
const zToolCallLocation = object({
|
|
244
|
+
path: string(),
|
|
245
|
+
line: defaultOnError(int().gte(0).max(4294967295, {
|
|
246
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
247
|
+
}).nullish(), () => void 0),
|
|
248
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
249
|
+
});
|
|
250
|
+
const zToolCallUpdate = object({
|
|
251
|
+
toolCallId: zToolCallId,
|
|
252
|
+
kind: defaultOnError(zToolKind.nullish(), () => void 0),
|
|
253
|
+
status: defaultOnError(zToolCallStatus.nullish(), () => void 0),
|
|
254
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
255
|
+
content: defaultOnError(vecSkipError(zToolCallContent).nullish(), () => void 0),
|
|
256
|
+
locations: defaultOnError(vecSkipError(zToolCallLocation).nullish(), () => void 0),
|
|
257
|
+
rawInput: defaultOnError(unknown().optional(), () => void 0),
|
|
258
|
+
rawOutput: defaultOnError(unknown().optional(), () => void 0),
|
|
259
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
260
|
+
});
|
|
261
|
+
const zPermissionOptionId = string();
|
|
262
|
+
const zPermissionOptionKind = union([
|
|
263
|
+
literal("allow_once"),
|
|
264
|
+
literal("allow_always"),
|
|
265
|
+
literal("reject_once"),
|
|
266
|
+
literal("reject_always")
|
|
267
|
+
]);
|
|
268
|
+
const zPermissionOption = object({
|
|
269
|
+
optionId: zPermissionOptionId,
|
|
270
|
+
name: string(),
|
|
271
|
+
kind: zPermissionOptionKind,
|
|
272
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
273
|
+
});
|
|
274
|
+
const zRequestPermissionRequest = object({
|
|
275
|
+
sessionId: zSessionId,
|
|
276
|
+
toolCall: zToolCallUpdate,
|
|
277
|
+
options: array(zPermissionOption),
|
|
278
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
279
|
+
});
|
|
280
|
+
const zEnvVariable = object({
|
|
281
|
+
name: string(),
|
|
282
|
+
value: string(),
|
|
283
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
284
|
+
});
|
|
285
|
+
const zCreateTerminalRequest = object({
|
|
286
|
+
sessionId: zSessionId,
|
|
287
|
+
command: string(),
|
|
288
|
+
args: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
289
|
+
env: defaultOnError(vecSkipError(zEnvVariable).optional(), () => []),
|
|
290
|
+
cwd: defaultOnError(string().nullish(), () => void 0),
|
|
291
|
+
outputByteLimit: defaultOnError(number().nullish(), () => void 0),
|
|
292
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
293
|
+
});
|
|
294
|
+
const zTerminalOutputRequest = object({
|
|
295
|
+
sessionId: zSessionId,
|
|
296
|
+
terminalId: zTerminalId,
|
|
297
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
298
|
+
});
|
|
299
|
+
const zReleaseTerminalRequest = object({
|
|
300
|
+
sessionId: zSessionId,
|
|
301
|
+
terminalId: zTerminalId,
|
|
302
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
303
|
+
});
|
|
304
|
+
const zWaitForTerminalExitRequest = object({
|
|
305
|
+
sessionId: zSessionId,
|
|
306
|
+
terminalId: zTerminalId,
|
|
307
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
308
|
+
});
|
|
309
|
+
const zKillTerminalRequest = object({
|
|
310
|
+
sessionId: zSessionId,
|
|
311
|
+
terminalId: zTerminalId,
|
|
312
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
313
|
+
});
|
|
314
|
+
const zElicitationSessionScope = object({
|
|
315
|
+
sessionId: zSessionId,
|
|
316
|
+
toolCallId: defaultOnError(zToolCallId.nullish(), () => void 0)
|
|
317
|
+
});
|
|
318
|
+
const zElicitationRequestScope = object({
|
|
319
|
+
requestId: zRequestId
|
|
320
|
+
});
|
|
321
|
+
const zElicitationSchemaType = literal("object");
|
|
322
|
+
const zStringFormat = union([
|
|
323
|
+
literal("email"),
|
|
324
|
+
literal("uri"),
|
|
325
|
+
literal("date"),
|
|
326
|
+
literal("date-time")
|
|
327
|
+
]);
|
|
328
|
+
const zEnumOption = object({
|
|
329
|
+
const: string(),
|
|
330
|
+
title: string(),
|
|
331
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
332
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
333
|
+
});
|
|
334
|
+
const zStringPropertySchema = object({
|
|
335
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
336
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
337
|
+
minLength: int().gte(0).max(4294967295, {
|
|
338
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
339
|
+
}).nullish(),
|
|
340
|
+
maxLength: int().gte(0).max(4294967295, {
|
|
341
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
342
|
+
}).nullish(),
|
|
343
|
+
pattern: string().nullish(),
|
|
344
|
+
format: zStringFormat.nullish(),
|
|
345
|
+
default: defaultOnError(string().nullish(), () => void 0),
|
|
346
|
+
enum: array(string()).nullish(),
|
|
347
|
+
oneOf: array(zEnumOption).nullish(),
|
|
348
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
349
|
+
});
|
|
350
|
+
const zNumberPropertySchema = object({
|
|
351
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
352
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
353
|
+
minimum: number().nullish(),
|
|
354
|
+
maximum: number().nullish(),
|
|
355
|
+
default: defaultOnError(number().nullish(), () => void 0),
|
|
356
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
357
|
+
});
|
|
358
|
+
const zIntegerPropertySchema = object({
|
|
359
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
360
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
361
|
+
minimum: number().nullish(),
|
|
362
|
+
maximum: number().nullish(),
|
|
363
|
+
default: defaultOnError(number().nullish(), () => void 0),
|
|
364
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
365
|
+
});
|
|
366
|
+
const zBooleanPropertySchema = object({
|
|
367
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
368
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
369
|
+
default: defaultOnError(boolean().nullish(), () => void 0),
|
|
370
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
371
|
+
});
|
|
372
|
+
const zStringMultiSelectItems = object({
|
|
373
|
+
enum: array(string()),
|
|
374
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
375
|
+
});
|
|
376
|
+
const zTitledMultiSelectItems = object({
|
|
377
|
+
anyOf: array(zEnumOption),
|
|
378
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
379
|
+
});
|
|
380
|
+
const zMultiSelectItems = preserveCustomPayload(union([
|
|
381
|
+
zStringMultiSelectItems.and(object({
|
|
382
|
+
type: literal("string")
|
|
383
|
+
})),
|
|
384
|
+
excludeKnownTags(object({
|
|
385
|
+
type: string()
|
|
386
|
+
}), "type", ["string"]),
|
|
387
|
+
zTitledMultiSelectItems
|
|
388
|
+
]), "type", ["string"]);
|
|
389
|
+
const zMultiSelectPropertySchema = object({
|
|
390
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
391
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
392
|
+
minItems: number().nullish(),
|
|
393
|
+
maxItems: number().nullish(),
|
|
394
|
+
items: zMultiSelectItems,
|
|
395
|
+
default: defaultOnError(vecSkipError(string()).nullish(), () => void 0),
|
|
396
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
397
|
+
});
|
|
398
|
+
const zElicitationPropertySchema = preserveCustomPayload(union([
|
|
399
|
+
zStringPropertySchema.and(object({
|
|
400
|
+
type: literal("string")
|
|
401
|
+
})),
|
|
402
|
+
zNumberPropertySchema.and(object({
|
|
403
|
+
type: literal("number")
|
|
404
|
+
})),
|
|
405
|
+
zIntegerPropertySchema.and(object({
|
|
406
|
+
type: literal("integer")
|
|
407
|
+
})),
|
|
408
|
+
zBooleanPropertySchema.and(object({
|
|
409
|
+
type: literal("boolean")
|
|
410
|
+
})),
|
|
411
|
+
zMultiSelectPropertySchema.and(object({
|
|
412
|
+
type: literal("array")
|
|
413
|
+
})),
|
|
414
|
+
excludeKnownTags(object({
|
|
415
|
+
type: string()
|
|
416
|
+
}), "type", ["array", "boolean", "integer", "number", "string"])
|
|
417
|
+
]), "type", ["array", "boolean", "integer", "number", "string"]);
|
|
418
|
+
const zElicitationSchema = object({
|
|
419
|
+
type: defaultOnError(zElicitationSchemaType.optional().default("object"), () => "object"),
|
|
420
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
421
|
+
properties: record(string(), zElicitationPropertySchema).optional().default({}),
|
|
422
|
+
required: array(string()).nullish(),
|
|
423
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
424
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
425
|
+
});
|
|
426
|
+
const zElicitationFormMode = intersection(union([zElicitationSessionScope, zElicitationRequestScope]), object({
|
|
427
|
+
requestedSchema: zElicitationSchema
|
|
428
|
+
}));
|
|
429
|
+
const zElicitationId = string();
|
|
430
|
+
const zElicitationUrlMode = intersection(union([zElicitationSessionScope, zElicitationRequestScope]), object({
|
|
431
|
+
elicitationId: zElicitationId,
|
|
432
|
+
url: url()
|
|
433
|
+
}));
|
|
434
|
+
const zCreateElicitationRequest = preserveCustomPayload(intersection(union([
|
|
435
|
+
zElicitationFormMode.and(object({
|
|
436
|
+
mode: literal("form")
|
|
437
|
+
})),
|
|
438
|
+
zElicitationUrlMode.and(object({
|
|
439
|
+
mode: literal("url")
|
|
440
|
+
})),
|
|
441
|
+
excludeKnownTags(intersection(union([zElicitationSessionScope, zElicitationRequestScope]), object({
|
|
442
|
+
mode: string()
|
|
443
|
+
})), "mode", ["form", "url"])
|
|
444
|
+
]), object({
|
|
445
|
+
message: string(),
|
|
446
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
447
|
+
})), "mode", ["form", "url"]);
|
|
448
|
+
const zMcpServerAcpId = string();
|
|
449
|
+
const zConnectMcpRequest = object({
|
|
450
|
+
serverId: zMcpServerAcpId,
|
|
451
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
452
|
+
});
|
|
453
|
+
const zMcpConnectionId = string();
|
|
454
|
+
const zMessageMcpRequest = object({
|
|
455
|
+
connectionId: zMcpConnectionId,
|
|
456
|
+
method: string(),
|
|
457
|
+
params: record(string(), unknown()).nullish(),
|
|
458
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
459
|
+
});
|
|
460
|
+
const zDisconnectMcpRequest = object({
|
|
461
|
+
connectionId: zMcpConnectionId,
|
|
462
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
463
|
+
});
|
|
464
|
+
const zExtRequest = unknown();
|
|
465
|
+
object({
|
|
466
|
+
id: zRequestId,
|
|
467
|
+
method: string(),
|
|
468
|
+
params: union([
|
|
469
|
+
zWriteTextFileRequest,
|
|
470
|
+
zReadTextFileRequest,
|
|
471
|
+
zRequestPermissionRequest,
|
|
472
|
+
zCreateTerminalRequest,
|
|
473
|
+
zTerminalOutputRequest,
|
|
474
|
+
zReleaseTerminalRequest,
|
|
475
|
+
zWaitForTerminalExitRequest,
|
|
476
|
+
zKillTerminalRequest,
|
|
477
|
+
zCreateElicitationRequest,
|
|
478
|
+
zConnectMcpRequest,
|
|
479
|
+
zMessageMcpRequest,
|
|
480
|
+
zDisconnectMcpRequest,
|
|
481
|
+
zExtRequest
|
|
482
|
+
]).nullish()
|
|
483
|
+
});
|
|
484
|
+
const zProtocolVersion = int().gte(0).lte(65535);
|
|
485
|
+
const zPromptCapabilities = object({
|
|
486
|
+
image: defaultOnError(boolean().optional().default(false), () => false),
|
|
487
|
+
audio: defaultOnError(boolean().optional().default(false), () => false),
|
|
488
|
+
embeddedContext: defaultOnError(boolean().optional().default(false), () => false),
|
|
489
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
490
|
+
});
|
|
491
|
+
const zMcpCapabilities = object({
|
|
492
|
+
http: defaultOnError(boolean().optional().default(false), () => false),
|
|
493
|
+
sse: defaultOnError(boolean().optional().default(false), () => false),
|
|
494
|
+
acp: defaultOnError(boolean().optional().default(false), () => false),
|
|
495
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
496
|
+
});
|
|
497
|
+
const zSessionListCapabilities = object({
|
|
498
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
499
|
+
});
|
|
500
|
+
const zSessionDeleteCapabilities = object({
|
|
501
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
502
|
+
});
|
|
503
|
+
const zSessionAdditionalDirectoriesCapabilities = object({
|
|
504
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
505
|
+
});
|
|
506
|
+
const zSessionForkCapabilities = object({
|
|
507
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
508
|
+
});
|
|
509
|
+
const zSessionResumeCapabilities = object({
|
|
510
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
511
|
+
});
|
|
512
|
+
const zSessionCloseCapabilities = object({
|
|
513
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
514
|
+
});
|
|
515
|
+
const zSessionCapabilities = object({
|
|
516
|
+
list: defaultOnError(zSessionListCapabilities.nullish(), () => void 0),
|
|
517
|
+
delete: defaultOnError(zSessionDeleteCapabilities.nullish(), () => void 0),
|
|
518
|
+
additionalDirectories: defaultOnError(zSessionAdditionalDirectoriesCapabilities.nullish(), () => void 0),
|
|
519
|
+
fork: defaultOnError(zSessionForkCapabilities.nullish(), () => void 0),
|
|
520
|
+
resume: defaultOnError(zSessionResumeCapabilities.nullish(), () => void 0),
|
|
521
|
+
close: defaultOnError(zSessionCloseCapabilities.nullish(), () => void 0),
|
|
522
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
523
|
+
});
|
|
524
|
+
const zLogoutCapabilities = object({
|
|
525
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
526
|
+
});
|
|
527
|
+
const zAgentAuthCapabilities = object({
|
|
528
|
+
logout: defaultOnError(zLogoutCapabilities.nullish(), () => void 0),
|
|
529
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
530
|
+
});
|
|
531
|
+
const zProvidersCapabilities = object({
|
|
532
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
533
|
+
});
|
|
534
|
+
const zNesDocumentDidOpenCapabilities = object({
|
|
535
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
536
|
+
});
|
|
537
|
+
const zTextDocumentSyncKind = union([
|
|
538
|
+
literal("full"),
|
|
539
|
+
literal("incremental")
|
|
540
|
+
]);
|
|
541
|
+
const zNesDocumentDidChangeCapabilities = object({
|
|
542
|
+
syncKind: zTextDocumentSyncKind,
|
|
543
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
544
|
+
});
|
|
545
|
+
const zNesDocumentDidCloseCapabilities = object({
|
|
546
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
547
|
+
});
|
|
548
|
+
const zNesDocumentDidSaveCapabilities = object({
|
|
549
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
550
|
+
});
|
|
551
|
+
const zNesDocumentDidFocusCapabilities = object({
|
|
552
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
553
|
+
});
|
|
554
|
+
const zNesDocumentEventCapabilities = object({
|
|
555
|
+
didOpen: defaultOnError(zNesDocumentDidOpenCapabilities.nullish(), () => void 0),
|
|
556
|
+
didChange: defaultOnError(zNesDocumentDidChangeCapabilities.nullish(), () => void 0),
|
|
557
|
+
didClose: defaultOnError(zNesDocumentDidCloseCapabilities.nullish(), () => void 0),
|
|
558
|
+
didSave: defaultOnError(zNesDocumentDidSaveCapabilities.nullish(), () => void 0),
|
|
559
|
+
didFocus: defaultOnError(zNesDocumentDidFocusCapabilities.nullish(), () => void 0),
|
|
560
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
561
|
+
});
|
|
562
|
+
const zNesEventCapabilities = object({
|
|
563
|
+
document: defaultOnError(zNesDocumentEventCapabilities.nullish(), () => void 0),
|
|
564
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
565
|
+
});
|
|
566
|
+
const zNesRecentFilesCapabilities = object({
|
|
567
|
+
maxCount: defaultOnError(int().gte(0).max(4294967295, {
|
|
568
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
569
|
+
}).nullish(), () => void 0),
|
|
570
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
571
|
+
});
|
|
572
|
+
const zNesRelatedSnippetsCapabilities = object({
|
|
573
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
574
|
+
});
|
|
575
|
+
const zNesEditHistoryCapabilities = object({
|
|
576
|
+
maxCount: defaultOnError(int().gte(0).max(4294967295, {
|
|
577
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
578
|
+
}).nullish(), () => void 0),
|
|
579
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
580
|
+
});
|
|
581
|
+
const zNesUserActionsCapabilities = object({
|
|
582
|
+
maxCount: defaultOnError(int().gte(0).max(4294967295, {
|
|
583
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
584
|
+
}).nullish(), () => void 0),
|
|
585
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
586
|
+
});
|
|
587
|
+
const zNesOpenFilesCapabilities = object({
|
|
588
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
589
|
+
});
|
|
590
|
+
const zNesDiagnosticsCapabilities = object({
|
|
591
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
592
|
+
});
|
|
593
|
+
const zNesContextCapabilities = object({
|
|
594
|
+
recentFiles: defaultOnError(zNesRecentFilesCapabilities.nullish(), () => void 0),
|
|
595
|
+
relatedSnippets: defaultOnError(zNesRelatedSnippetsCapabilities.nullish(), () => void 0),
|
|
596
|
+
editHistory: defaultOnError(zNesEditHistoryCapabilities.nullish(), () => void 0),
|
|
597
|
+
userActions: defaultOnError(zNesUserActionsCapabilities.nullish(), () => void 0),
|
|
598
|
+
openFiles: defaultOnError(zNesOpenFilesCapabilities.nullish(), () => void 0),
|
|
599
|
+
diagnostics: defaultOnError(zNesDiagnosticsCapabilities.nullish(), () => void 0),
|
|
600
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
601
|
+
});
|
|
602
|
+
const zNesCapabilities = object({
|
|
603
|
+
events: defaultOnError(zNesEventCapabilities.nullish(), () => void 0),
|
|
604
|
+
context: defaultOnError(zNesContextCapabilities.nullish(), () => void 0),
|
|
605
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
606
|
+
});
|
|
607
|
+
const zPositionEncodingKind = union([
|
|
608
|
+
literal("utf-16"),
|
|
609
|
+
literal("utf-32"),
|
|
610
|
+
literal("utf-8")
|
|
611
|
+
]);
|
|
612
|
+
const zAgentCapabilities = object({
|
|
613
|
+
loadSession: defaultOnError(boolean().optional().default(false), () => false),
|
|
614
|
+
promptCapabilities: defaultOnError(zPromptCapabilities.optional().default({
|
|
615
|
+
image: false,
|
|
616
|
+
audio: false,
|
|
617
|
+
embeddedContext: false
|
|
618
|
+
}), () => ({
|
|
619
|
+
image: false,
|
|
620
|
+
audio: false,
|
|
621
|
+
embeddedContext: false
|
|
622
|
+
})),
|
|
623
|
+
mcpCapabilities: defaultOnError(zMcpCapabilities.optional().default({
|
|
624
|
+
http: false,
|
|
625
|
+
sse: false,
|
|
626
|
+
acp: false
|
|
627
|
+
}), () => ({
|
|
628
|
+
http: false,
|
|
629
|
+
sse: false,
|
|
630
|
+
acp: false
|
|
631
|
+
})),
|
|
632
|
+
sessionCapabilities: defaultOnError(zSessionCapabilities.optional().default({}), () => ({})),
|
|
633
|
+
auth: defaultOnError(zAgentAuthCapabilities.optional().default({}), () => ({})),
|
|
634
|
+
providers: defaultOnError(zProvidersCapabilities.nullish(), () => void 0),
|
|
635
|
+
nes: defaultOnError(zNesCapabilities.nullish(), () => void 0),
|
|
636
|
+
positionEncoding: defaultOnError(zPositionEncodingKind.nullish(), () => void 0),
|
|
637
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
638
|
+
});
|
|
639
|
+
const zAuthMethodId = string();
|
|
640
|
+
const zAuthEnvVar = object({
|
|
641
|
+
name: string(),
|
|
642
|
+
label: defaultOnError(string().nullish(), () => void 0),
|
|
643
|
+
secret: defaultOnError(boolean().optional().default(true), () => true),
|
|
644
|
+
optional: defaultOnError(boolean().optional().default(false), () => false),
|
|
645
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
646
|
+
});
|
|
647
|
+
const zAuthMethodEnvVar = object({
|
|
648
|
+
id: zAuthMethodId,
|
|
649
|
+
name: string(),
|
|
650
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
651
|
+
vars: requiredDefaultOnError(vecSkipError(zAuthEnvVar), () => []),
|
|
652
|
+
link: defaultOnError(string().nullish(), () => void 0),
|
|
653
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
654
|
+
});
|
|
655
|
+
const zAuthMethodTerminal = object({
|
|
656
|
+
id: zAuthMethodId,
|
|
657
|
+
name: string(),
|
|
658
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
659
|
+
args: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
660
|
+
env: defaultOnError(record(string(), string()).optional(), () => void 0),
|
|
661
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
662
|
+
});
|
|
663
|
+
const zAuthMethodAgent = object({
|
|
664
|
+
id: zAuthMethodId,
|
|
665
|
+
name: string(),
|
|
666
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
667
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
668
|
+
});
|
|
669
|
+
const zAuthMethod = union([
|
|
670
|
+
zAuthMethodEnvVar.and(object({
|
|
671
|
+
type: literal("env_var")
|
|
672
|
+
})),
|
|
673
|
+
zAuthMethodTerminal.and(object({
|
|
674
|
+
type: literal("terminal")
|
|
675
|
+
})),
|
|
676
|
+
zAuthMethodAgent
|
|
677
|
+
]);
|
|
678
|
+
const zImplementation = object({
|
|
679
|
+
name: string(),
|
|
680
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
681
|
+
version: string(),
|
|
682
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
683
|
+
});
|
|
684
|
+
const zInitializeResponse = object({
|
|
685
|
+
protocolVersion: zProtocolVersion,
|
|
686
|
+
agentCapabilities: defaultOnError(zAgentCapabilities.optional().default({
|
|
687
|
+
loadSession: false,
|
|
688
|
+
promptCapabilities: {
|
|
689
|
+
image: false,
|
|
690
|
+
audio: false,
|
|
691
|
+
embeddedContext: false
|
|
692
|
+
},
|
|
693
|
+
mcpCapabilities: {
|
|
694
|
+
http: false,
|
|
695
|
+
sse: false,
|
|
696
|
+
acp: false
|
|
697
|
+
},
|
|
698
|
+
sessionCapabilities: {},
|
|
699
|
+
auth: {}
|
|
700
|
+
}), () => ({
|
|
701
|
+
loadSession: false,
|
|
702
|
+
promptCapabilities: {
|
|
703
|
+
image: false,
|
|
704
|
+
audio: false,
|
|
705
|
+
embeddedContext: false
|
|
706
|
+
},
|
|
707
|
+
mcpCapabilities: {
|
|
708
|
+
http: false,
|
|
709
|
+
sse: false,
|
|
710
|
+
acp: false
|
|
711
|
+
},
|
|
712
|
+
sessionCapabilities: {},
|
|
713
|
+
auth: {}
|
|
714
|
+
})),
|
|
715
|
+
authMethods: defaultOnError(vecSkipError(zAuthMethod).optional().default([]), () => []),
|
|
716
|
+
agentInfo: defaultOnError(zImplementation.nullish(), () => void 0),
|
|
717
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
718
|
+
});
|
|
719
|
+
const zAuthenticateResponse = object({
|
|
720
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
721
|
+
});
|
|
722
|
+
const zProviderId = string();
|
|
723
|
+
const zLlmProtocol = union([
|
|
724
|
+
literal("anthropic"),
|
|
725
|
+
literal("openai"),
|
|
726
|
+
literal("azure"),
|
|
727
|
+
literal("vertex"),
|
|
728
|
+
literal("bedrock"),
|
|
729
|
+
string()
|
|
730
|
+
]);
|
|
731
|
+
const zProviderCurrentConfig = object({
|
|
732
|
+
apiType: zLlmProtocol,
|
|
733
|
+
baseUrl: string(),
|
|
734
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
735
|
+
});
|
|
736
|
+
const zProviderInfo = object({
|
|
737
|
+
providerId: zProviderId,
|
|
738
|
+
supported: requiredDefaultOnError(vecSkipError(zLlmProtocol), () => []),
|
|
739
|
+
required: boolean(),
|
|
740
|
+
current: zProviderCurrentConfig.nullish(),
|
|
741
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
742
|
+
});
|
|
743
|
+
const zListProvidersResponse = object({
|
|
744
|
+
providers: array(zProviderInfo),
|
|
745
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
746
|
+
});
|
|
747
|
+
const zSetProviderResponse = object({
|
|
748
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
749
|
+
});
|
|
750
|
+
const zDisableProviderResponse = object({
|
|
751
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
752
|
+
});
|
|
753
|
+
const zLogoutResponse = object({
|
|
754
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
755
|
+
});
|
|
756
|
+
const zSessionModeId = string();
|
|
757
|
+
const zSessionMode = object({
|
|
758
|
+
id: zSessionModeId,
|
|
759
|
+
name: string(),
|
|
760
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
761
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
762
|
+
});
|
|
763
|
+
const zSessionModeState = object({
|
|
764
|
+
currentModeId: zSessionModeId,
|
|
765
|
+
availableModes: requiredDefaultOnError(vecSkipError(zSessionMode), () => []),
|
|
766
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
767
|
+
});
|
|
768
|
+
const zSessionConfigId = string();
|
|
769
|
+
const zSessionConfigOptionCategory = union([
|
|
770
|
+
literal("mode"),
|
|
771
|
+
literal("model"),
|
|
772
|
+
literal("model_config"),
|
|
773
|
+
literal("thought_level"),
|
|
774
|
+
string()
|
|
775
|
+
]);
|
|
776
|
+
const zSessionConfigValueId = string();
|
|
777
|
+
const zSessionConfigSelectOption = object({
|
|
778
|
+
value: zSessionConfigValueId,
|
|
779
|
+
name: string(),
|
|
780
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
781
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
782
|
+
});
|
|
783
|
+
const zSessionConfigGroupId = string();
|
|
784
|
+
const zSessionConfigSelectGroup = object({
|
|
785
|
+
group: zSessionConfigGroupId,
|
|
786
|
+
name: string(),
|
|
787
|
+
options: requiredDefaultOnError(vecSkipError(zSessionConfigSelectOption), () => []),
|
|
788
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
789
|
+
});
|
|
790
|
+
const zSessionConfigSelectOptions = union([
|
|
791
|
+
array(zSessionConfigSelectOption),
|
|
792
|
+
array(zSessionConfigSelectGroup)
|
|
793
|
+
]);
|
|
794
|
+
const zSessionConfigSelect = object({
|
|
795
|
+
currentValue: zSessionConfigValueId,
|
|
796
|
+
options: zSessionConfigSelectOptions
|
|
797
|
+
});
|
|
798
|
+
const zSessionConfigBoolean = object({
|
|
799
|
+
currentValue: boolean()
|
|
800
|
+
});
|
|
801
|
+
const zSessionConfigOption = intersection(union([
|
|
802
|
+
zSessionConfigSelect.and(object({
|
|
803
|
+
type: literal("select")
|
|
804
|
+
})),
|
|
805
|
+
zSessionConfigBoolean.and(object({
|
|
806
|
+
type: literal("boolean")
|
|
807
|
+
}))
|
|
808
|
+
]), object({
|
|
809
|
+
id: zSessionConfigId,
|
|
810
|
+
name: string(),
|
|
811
|
+
description: defaultOnError(string().nullish(), () => void 0),
|
|
812
|
+
category: defaultOnError(zSessionConfigOptionCategory.nullish(), () => void 0),
|
|
813
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
814
|
+
}));
|
|
815
|
+
const zNewSessionResponse = object({
|
|
816
|
+
sessionId: zSessionId,
|
|
817
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => void 0),
|
|
818
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => void 0),
|
|
819
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
820
|
+
});
|
|
821
|
+
const zLoadSessionResponse = object({
|
|
822
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => void 0),
|
|
823
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => void 0),
|
|
824
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
825
|
+
});
|
|
826
|
+
const zSessionInfo = object({
|
|
827
|
+
sessionId: zSessionId,
|
|
828
|
+
cwd: string(),
|
|
829
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
830
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
831
|
+
updatedAt: defaultOnError(string().nullish(), () => void 0),
|
|
832
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
833
|
+
});
|
|
834
|
+
const zListSessionsResponse = object({
|
|
835
|
+
sessions: requiredDefaultOnError(vecSkipError(zSessionInfo), () => []),
|
|
836
|
+
nextCursor: defaultOnError(string().nullish(), () => void 0),
|
|
837
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
838
|
+
});
|
|
839
|
+
const zDeleteSessionResponse = object({
|
|
840
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
841
|
+
});
|
|
842
|
+
const zForkSessionResponse = object({
|
|
843
|
+
sessionId: zSessionId,
|
|
844
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => void 0),
|
|
845
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => void 0),
|
|
846
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
847
|
+
});
|
|
848
|
+
const zResumeSessionResponse = object({
|
|
849
|
+
modes: defaultOnError(zSessionModeState.nullish(), () => void 0),
|
|
850
|
+
configOptions: defaultOnError(vecSkipError(zSessionConfigOption).nullish(), () => void 0),
|
|
851
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
852
|
+
});
|
|
853
|
+
const zCloseSessionResponse = object({
|
|
854
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
855
|
+
});
|
|
856
|
+
const zSetSessionModeResponse = object({
|
|
857
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
858
|
+
});
|
|
859
|
+
const zSetSessionConfigOptionResponse = object({
|
|
860
|
+
configOptions: requiredDefaultOnError(vecSkipError(zSessionConfigOption), () => []),
|
|
861
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
862
|
+
});
|
|
863
|
+
const zStopReason = union([
|
|
864
|
+
literal("end_turn"),
|
|
865
|
+
literal("max_tokens"),
|
|
866
|
+
literal("max_turn_requests"),
|
|
867
|
+
literal("refusal"),
|
|
868
|
+
literal("cancelled")
|
|
869
|
+
]);
|
|
870
|
+
const zUsage = object({
|
|
871
|
+
totalTokens: number(),
|
|
872
|
+
inputTokens: number(),
|
|
873
|
+
outputTokens: number(),
|
|
874
|
+
thoughtTokens: defaultOnError(number().nullish(), () => void 0),
|
|
875
|
+
cachedReadTokens: defaultOnError(number().nullish(), () => void 0),
|
|
876
|
+
cachedWriteTokens: defaultOnError(number().nullish(), () => void 0),
|
|
877
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
878
|
+
});
|
|
879
|
+
const zPromptResponse = object({
|
|
880
|
+
stopReason: zStopReason,
|
|
881
|
+
usage: defaultOnError(zUsage.nullish(), () => void 0),
|
|
882
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
883
|
+
});
|
|
884
|
+
const zStartNesResponse = object({
|
|
885
|
+
sessionId: zSessionId,
|
|
886
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
887
|
+
});
|
|
888
|
+
const zNesSuggestionId = string();
|
|
889
|
+
const zPosition = object({
|
|
890
|
+
line: int().gte(0).max(4294967295, {
|
|
891
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
892
|
+
}),
|
|
893
|
+
character: int().gte(0).max(4294967295, {
|
|
894
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
895
|
+
}),
|
|
896
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
897
|
+
});
|
|
898
|
+
const zRange = object({
|
|
899
|
+
start: zPosition,
|
|
900
|
+
end: zPosition,
|
|
901
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
902
|
+
});
|
|
903
|
+
const zNesTextEdit = object({
|
|
904
|
+
range: zRange,
|
|
905
|
+
newText: string(),
|
|
906
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
907
|
+
});
|
|
908
|
+
const zNesEditSuggestion = object({
|
|
909
|
+
id: zNesSuggestionId,
|
|
910
|
+
uri: string(),
|
|
911
|
+
edits: array(zNesTextEdit),
|
|
912
|
+
cursorPosition: defaultOnError(zPosition.nullish(), () => void 0),
|
|
913
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
914
|
+
});
|
|
915
|
+
const zNesJumpSuggestion = object({
|
|
916
|
+
id: zNesSuggestionId,
|
|
917
|
+
uri: string(),
|
|
918
|
+
position: zPosition,
|
|
919
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
920
|
+
});
|
|
921
|
+
const zNesRenameSuggestion = object({
|
|
922
|
+
id: zNesSuggestionId,
|
|
923
|
+
uri: string(),
|
|
924
|
+
position: zPosition,
|
|
925
|
+
newName: string(),
|
|
926
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
927
|
+
});
|
|
928
|
+
const zNesSearchAndReplaceSuggestion = object({
|
|
929
|
+
id: zNesSuggestionId,
|
|
930
|
+
uri: string(),
|
|
931
|
+
search: string(),
|
|
932
|
+
replace: string(),
|
|
933
|
+
isRegex: boolean().nullish(),
|
|
934
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
935
|
+
});
|
|
936
|
+
const zNesSuggestion = union([
|
|
937
|
+
zNesEditSuggestion.and(object({
|
|
938
|
+
kind: literal("edit")
|
|
939
|
+
})),
|
|
940
|
+
zNesJumpSuggestion.and(object({
|
|
941
|
+
kind: literal("jump")
|
|
942
|
+
})),
|
|
943
|
+
zNesRenameSuggestion.and(object({
|
|
944
|
+
kind: literal("rename")
|
|
945
|
+
})),
|
|
946
|
+
zNesSearchAndReplaceSuggestion.and(object({
|
|
947
|
+
kind: literal("searchAndReplace")
|
|
948
|
+
}))
|
|
949
|
+
]);
|
|
950
|
+
const zSuggestNesResponse = object({
|
|
951
|
+
suggestions: array(zNesSuggestion),
|
|
952
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
953
|
+
});
|
|
954
|
+
const zCloseNesResponse = object({
|
|
955
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
956
|
+
});
|
|
957
|
+
const zExtResponse = unknown();
|
|
958
|
+
const zMessageMcpResponse = unknown();
|
|
959
|
+
const zErrorCode = union([
|
|
960
|
+
literal(-32700),
|
|
961
|
+
literal(-32600),
|
|
962
|
+
literal(-32601),
|
|
963
|
+
literal(-32602),
|
|
964
|
+
literal(-32603),
|
|
965
|
+
literal(-32800),
|
|
966
|
+
literal(-32e3),
|
|
967
|
+
literal(-32002),
|
|
968
|
+
int().min(-2147483648, {
|
|
969
|
+
error: "Invalid value: Expected int32 to be >= -2147483648"
|
|
970
|
+
}).max(2147483647, {
|
|
971
|
+
error: "Invalid value: Expected int32 to be <= 2147483647"
|
|
972
|
+
})
|
|
973
|
+
]);
|
|
974
|
+
const zError = object({
|
|
975
|
+
code: zErrorCode,
|
|
976
|
+
message: string(),
|
|
977
|
+
data: defaultOnError(unknown().optional(), () => void 0)
|
|
978
|
+
});
|
|
979
|
+
union([
|
|
980
|
+
object({
|
|
981
|
+
id: zRequestId,
|
|
982
|
+
result: union([
|
|
983
|
+
zInitializeResponse,
|
|
984
|
+
zAuthenticateResponse,
|
|
985
|
+
zListProvidersResponse,
|
|
986
|
+
zSetProviderResponse,
|
|
987
|
+
zDisableProviderResponse,
|
|
988
|
+
zLogoutResponse,
|
|
989
|
+
zNewSessionResponse,
|
|
990
|
+
zLoadSessionResponse,
|
|
991
|
+
zListSessionsResponse,
|
|
992
|
+
zDeleteSessionResponse,
|
|
993
|
+
zForkSessionResponse,
|
|
994
|
+
zResumeSessionResponse,
|
|
995
|
+
zCloseSessionResponse,
|
|
996
|
+
zSetSessionModeResponse,
|
|
997
|
+
zSetSessionConfigOptionResponse,
|
|
998
|
+
zPromptResponse,
|
|
999
|
+
zStartNesResponse,
|
|
1000
|
+
zSuggestNesResponse,
|
|
1001
|
+
zCloseNesResponse,
|
|
1002
|
+
zExtResponse,
|
|
1003
|
+
zMessageMcpResponse
|
|
1004
|
+
])
|
|
1005
|
+
}),
|
|
1006
|
+
object({
|
|
1007
|
+
id: zRequestId,
|
|
1008
|
+
error: zError
|
|
1009
|
+
})
|
|
1010
|
+
]);
|
|
1011
|
+
const zMessageId = string();
|
|
1012
|
+
const zContentChunk = object({
|
|
1013
|
+
content: zContentBlock,
|
|
1014
|
+
messageId: defaultOnError(zMessageId.nullish(), () => void 0),
|
|
1015
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1016
|
+
});
|
|
1017
|
+
const zToolCall = object({
|
|
1018
|
+
toolCallId: zToolCallId,
|
|
1019
|
+
title: string(),
|
|
1020
|
+
kind: defaultOnError(zToolKind.optional(), () => void 0),
|
|
1021
|
+
status: defaultOnError(zToolCallStatus.optional(), () => void 0),
|
|
1022
|
+
content: defaultOnError(vecSkipError(zToolCallContent).optional(), () => []),
|
|
1023
|
+
locations: defaultOnError(vecSkipError(zToolCallLocation).optional(), () => []),
|
|
1024
|
+
rawInput: defaultOnError(unknown().optional(), () => void 0),
|
|
1025
|
+
rawOutput: defaultOnError(unknown().optional(), () => void 0),
|
|
1026
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1027
|
+
});
|
|
1028
|
+
const zPlanEntryPriority = union([
|
|
1029
|
+
literal("high"),
|
|
1030
|
+
literal("medium"),
|
|
1031
|
+
literal("low")
|
|
1032
|
+
]);
|
|
1033
|
+
const zPlanEntryStatus = union([
|
|
1034
|
+
literal("pending"),
|
|
1035
|
+
literal("in_progress"),
|
|
1036
|
+
literal("completed")
|
|
1037
|
+
]);
|
|
1038
|
+
const zPlanEntry = object({
|
|
1039
|
+
content: string(),
|
|
1040
|
+
priority: zPlanEntryPriority,
|
|
1041
|
+
status: zPlanEntryStatus,
|
|
1042
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1043
|
+
});
|
|
1044
|
+
const zPlan = object({
|
|
1045
|
+
entries: requiredDefaultOnError(vecSkipError(zPlanEntry), () => []),
|
|
1046
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1047
|
+
});
|
|
1048
|
+
const zPlanId = string();
|
|
1049
|
+
const zPlanItems = object({
|
|
1050
|
+
planId: zPlanId,
|
|
1051
|
+
entries: requiredDefaultOnError(vecSkipError(zPlanEntry), () => []),
|
|
1052
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1053
|
+
});
|
|
1054
|
+
const zPlanFile = object({
|
|
1055
|
+
planId: zPlanId,
|
|
1056
|
+
uri: string(),
|
|
1057
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1058
|
+
});
|
|
1059
|
+
const zPlanMarkdown = object({
|
|
1060
|
+
planId: zPlanId,
|
|
1061
|
+
content: string(),
|
|
1062
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1063
|
+
});
|
|
1064
|
+
const zPlanUpdateContent = union([
|
|
1065
|
+
zPlanItems.and(object({
|
|
1066
|
+
type: literal("items")
|
|
1067
|
+
})),
|
|
1068
|
+
zPlanFile.and(object({
|
|
1069
|
+
type: literal("file")
|
|
1070
|
+
})),
|
|
1071
|
+
zPlanMarkdown.and(object({
|
|
1072
|
+
type: literal("markdown")
|
|
1073
|
+
}))
|
|
1074
|
+
]);
|
|
1075
|
+
const zPlanUpdate = object({
|
|
1076
|
+
plan: zPlanUpdateContent,
|
|
1077
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1078
|
+
});
|
|
1079
|
+
const zPlanRemoved = object({
|
|
1080
|
+
planId: zPlanId,
|
|
1081
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1082
|
+
});
|
|
1083
|
+
const zUnstructuredCommandInput = object({
|
|
1084
|
+
hint: string(),
|
|
1085
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1086
|
+
});
|
|
1087
|
+
const zAvailableCommandInput = zUnstructuredCommandInput;
|
|
1088
|
+
const zAvailableCommand = object({
|
|
1089
|
+
name: string(),
|
|
1090
|
+
description: string(),
|
|
1091
|
+
input: defaultOnError(zAvailableCommandInput.nullish(), () => void 0),
|
|
1092
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1093
|
+
});
|
|
1094
|
+
const zAvailableCommandsUpdate = object({
|
|
1095
|
+
availableCommands: requiredDefaultOnError(vecSkipError(zAvailableCommand), () => []),
|
|
1096
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1097
|
+
});
|
|
1098
|
+
const zCurrentModeUpdate = object({
|
|
1099
|
+
currentModeId: zSessionModeId,
|
|
1100
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1101
|
+
});
|
|
1102
|
+
const zConfigOptionUpdate = object({
|
|
1103
|
+
configOptions: requiredDefaultOnError(vecSkipError(zSessionConfigOption), () => []),
|
|
1104
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1105
|
+
});
|
|
1106
|
+
const zSessionInfoUpdate = object({
|
|
1107
|
+
title: defaultOnError(string().nullish(), () => void 0),
|
|
1108
|
+
updatedAt: defaultOnError(string().nullish(), () => void 0),
|
|
1109
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1110
|
+
});
|
|
1111
|
+
const zCost = object({
|
|
1112
|
+
amount: number(),
|
|
1113
|
+
currency: string(),
|
|
1114
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1115
|
+
});
|
|
1116
|
+
const zUsageUpdate = object({
|
|
1117
|
+
used: number(),
|
|
1118
|
+
size: number(),
|
|
1119
|
+
cost: defaultOnError(zCost.nullish(), () => void 0),
|
|
1120
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1121
|
+
});
|
|
1122
|
+
const zSessionUpdate = union([
|
|
1123
|
+
zContentChunk.and(object({
|
|
1124
|
+
sessionUpdate: literal("user_message_chunk")
|
|
1125
|
+
})),
|
|
1126
|
+
zContentChunk.and(object({
|
|
1127
|
+
sessionUpdate: literal("agent_message_chunk")
|
|
1128
|
+
})),
|
|
1129
|
+
zContentChunk.and(object({
|
|
1130
|
+
sessionUpdate: literal("agent_thought_chunk")
|
|
1131
|
+
})),
|
|
1132
|
+
zToolCall.and(object({
|
|
1133
|
+
sessionUpdate: literal("tool_call")
|
|
1134
|
+
})),
|
|
1135
|
+
zToolCallUpdate.and(object({
|
|
1136
|
+
sessionUpdate: literal("tool_call_update")
|
|
1137
|
+
})),
|
|
1138
|
+
zPlan.and(object({
|
|
1139
|
+
sessionUpdate: literal("plan")
|
|
1140
|
+
})),
|
|
1141
|
+
zPlanUpdate.and(object({
|
|
1142
|
+
sessionUpdate: literal("plan_update")
|
|
1143
|
+
})),
|
|
1144
|
+
zPlanRemoved.and(object({
|
|
1145
|
+
sessionUpdate: literal("plan_removed")
|
|
1146
|
+
})),
|
|
1147
|
+
zAvailableCommandsUpdate.and(object({
|
|
1148
|
+
sessionUpdate: literal("available_commands_update")
|
|
1149
|
+
})),
|
|
1150
|
+
zCurrentModeUpdate.and(object({
|
|
1151
|
+
sessionUpdate: literal("current_mode_update")
|
|
1152
|
+
})),
|
|
1153
|
+
zConfigOptionUpdate.and(object({
|
|
1154
|
+
sessionUpdate: literal("config_option_update")
|
|
1155
|
+
})),
|
|
1156
|
+
zSessionInfoUpdate.and(object({
|
|
1157
|
+
sessionUpdate: literal("session_info_update")
|
|
1158
|
+
})),
|
|
1159
|
+
zUsageUpdate.and(object({
|
|
1160
|
+
sessionUpdate: literal("usage_update")
|
|
1161
|
+
}))
|
|
1162
|
+
]);
|
|
1163
|
+
const zSessionNotification = object({
|
|
1164
|
+
sessionId: zSessionId,
|
|
1165
|
+
update: zSessionUpdate,
|
|
1166
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1167
|
+
});
|
|
1168
|
+
const zCompleteElicitationNotification = object({
|
|
1169
|
+
elicitationId: zElicitationId,
|
|
1170
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1171
|
+
});
|
|
1172
|
+
const zMessageMcpNotification = object({
|
|
1173
|
+
connectionId: zMcpConnectionId,
|
|
1174
|
+
method: string(),
|
|
1175
|
+
params: defaultOnError(record(string(), unknown()).nullish(), () => void 0),
|
|
1176
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1177
|
+
});
|
|
1178
|
+
const zExtNotification = unknown();
|
|
1179
|
+
object({
|
|
1180
|
+
method: string(),
|
|
1181
|
+
params: union([
|
|
1182
|
+
zSessionNotification,
|
|
1183
|
+
zCompleteElicitationNotification,
|
|
1184
|
+
zMessageMcpNotification,
|
|
1185
|
+
zExtNotification
|
|
1186
|
+
]).nullish()
|
|
1187
|
+
});
|
|
1188
|
+
const zFileSystemCapabilities = object({
|
|
1189
|
+
readTextFile: defaultOnError(boolean().optional().default(false), () => false),
|
|
1190
|
+
writeTextFile: defaultOnError(boolean().optional().default(false), () => false),
|
|
1191
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1192
|
+
});
|
|
1193
|
+
const zBooleanConfigOptionCapabilities = object({
|
|
1194
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1195
|
+
});
|
|
1196
|
+
const zSessionConfigOptionsCapabilities = object({
|
|
1197
|
+
boolean: defaultOnError(zBooleanConfigOptionCapabilities.nullish(), () => void 0),
|
|
1198
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1199
|
+
});
|
|
1200
|
+
const zClientSessionCapabilities = object({
|
|
1201
|
+
configOptions: defaultOnError(zSessionConfigOptionsCapabilities.nullish(), () => void 0),
|
|
1202
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1203
|
+
});
|
|
1204
|
+
const zPlanCapabilities = object({
|
|
1205
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1206
|
+
});
|
|
1207
|
+
const zAuthCapabilities = object({
|
|
1208
|
+
terminal: defaultOnError(boolean().optional().default(false), () => false),
|
|
1209
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1210
|
+
});
|
|
1211
|
+
const zElicitationFormCapabilities = object({
|
|
1212
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1213
|
+
});
|
|
1214
|
+
const zElicitationUrlCapabilities = object({
|
|
1215
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1216
|
+
});
|
|
1217
|
+
const zElicitationCapabilities = object({
|
|
1218
|
+
form: defaultOnError(zElicitationFormCapabilities.nullish(), () => void 0),
|
|
1219
|
+
url: defaultOnError(zElicitationUrlCapabilities.nullish(), () => void 0),
|
|
1220
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1221
|
+
});
|
|
1222
|
+
const zNesJumpCapabilities = object({
|
|
1223
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1224
|
+
});
|
|
1225
|
+
const zNesRenameCapabilities = object({
|
|
1226
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1227
|
+
});
|
|
1228
|
+
const zNesSearchAndReplaceCapabilities = object({
|
|
1229
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1230
|
+
});
|
|
1231
|
+
const zClientNesCapabilities = object({
|
|
1232
|
+
jump: defaultOnError(zNesJumpCapabilities.nullish(), () => void 0),
|
|
1233
|
+
rename: defaultOnError(zNesRenameCapabilities.nullish(), () => void 0),
|
|
1234
|
+
searchAndReplace: defaultOnError(zNesSearchAndReplaceCapabilities.nullish(), () => void 0),
|
|
1235
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1236
|
+
});
|
|
1237
|
+
const zClientCapabilities = object({
|
|
1238
|
+
fs: defaultOnError(zFileSystemCapabilities.optional().default({ readTextFile: false, writeTextFile: false }), () => ({ readTextFile: false, writeTextFile: false })),
|
|
1239
|
+
terminal: defaultOnError(boolean().optional().default(false), () => false),
|
|
1240
|
+
session: defaultOnError(zClientSessionCapabilities.nullish(), () => void 0),
|
|
1241
|
+
plan: defaultOnError(zPlanCapabilities.nullish(), () => void 0),
|
|
1242
|
+
auth: defaultOnError(zAuthCapabilities.optional().default({ terminal: false }), () => ({ terminal: false })),
|
|
1243
|
+
elicitation: defaultOnError(zElicitationCapabilities.nullish(), () => void 0),
|
|
1244
|
+
nes: defaultOnError(zClientNesCapabilities.nullish(), () => void 0),
|
|
1245
|
+
positionEncodings: defaultOnError(vecSkipError(zPositionEncodingKind).optional(), () => []),
|
|
1246
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1247
|
+
});
|
|
1248
|
+
const zInitializeRequest = object({
|
|
1249
|
+
protocolVersion: zProtocolVersion,
|
|
1250
|
+
clientCapabilities: defaultOnError(zClientCapabilities.optional().default({
|
|
1251
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
1252
|
+
terminal: false,
|
|
1253
|
+
auth: { terminal: false }
|
|
1254
|
+
}), () => ({
|
|
1255
|
+
fs: { readTextFile: false, writeTextFile: false },
|
|
1256
|
+
terminal: false,
|
|
1257
|
+
auth: { terminal: false }
|
|
1258
|
+
})),
|
|
1259
|
+
clientInfo: defaultOnError(zImplementation.nullish(), () => void 0),
|
|
1260
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1261
|
+
});
|
|
1262
|
+
const zAuthenticateRequest = object({
|
|
1263
|
+
methodId: zAuthMethodId,
|
|
1264
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1265
|
+
});
|
|
1266
|
+
const zListProvidersRequest = object({
|
|
1267
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1268
|
+
});
|
|
1269
|
+
const zSetProviderRequest = object({
|
|
1270
|
+
providerId: zProviderId,
|
|
1271
|
+
apiType: zLlmProtocol,
|
|
1272
|
+
baseUrl: string(),
|
|
1273
|
+
headers: record(string(), string()).optional(),
|
|
1274
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1275
|
+
});
|
|
1276
|
+
const zDisableProviderRequest = object({
|
|
1277
|
+
providerId: zProviderId,
|
|
1278
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1279
|
+
});
|
|
1280
|
+
const zLogoutRequest = object({
|
|
1281
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1282
|
+
});
|
|
1283
|
+
const zHttpHeader = object({
|
|
1284
|
+
name: string(),
|
|
1285
|
+
value: string(),
|
|
1286
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1287
|
+
});
|
|
1288
|
+
const zMcpServerHttp = object({
|
|
1289
|
+
name: string(),
|
|
1290
|
+
url: string(),
|
|
1291
|
+
headers: array(zHttpHeader),
|
|
1292
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1293
|
+
});
|
|
1294
|
+
const zMcpServerSse = object({
|
|
1295
|
+
name: string(),
|
|
1296
|
+
url: string(),
|
|
1297
|
+
headers: array(zHttpHeader),
|
|
1298
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1299
|
+
});
|
|
1300
|
+
const zMcpServerAcp = object({
|
|
1301
|
+
name: string(),
|
|
1302
|
+
serverId: zMcpServerAcpId,
|
|
1303
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1304
|
+
});
|
|
1305
|
+
const zMcpServerStdio = object({
|
|
1306
|
+
name: string(),
|
|
1307
|
+
command: string(),
|
|
1308
|
+
args: array(string()),
|
|
1309
|
+
env: array(zEnvVariable),
|
|
1310
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1311
|
+
});
|
|
1312
|
+
const zMcpServer = union([
|
|
1313
|
+
zMcpServerHttp.and(object({
|
|
1314
|
+
type: literal("http")
|
|
1315
|
+
})),
|
|
1316
|
+
zMcpServerSse.and(object({
|
|
1317
|
+
type: literal("sse")
|
|
1318
|
+
})),
|
|
1319
|
+
zMcpServerAcp.and(object({
|
|
1320
|
+
type: literal("acp")
|
|
1321
|
+
})),
|
|
1322
|
+
zMcpServerStdio
|
|
1323
|
+
]);
|
|
1324
|
+
const zNewSessionRequest = object({
|
|
1325
|
+
cwd: string(),
|
|
1326
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1327
|
+
mcpServers: requiredDefaultOnError(vecSkipError(zMcpServer), () => []),
|
|
1328
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1329
|
+
});
|
|
1330
|
+
const zLoadSessionRequest = object({
|
|
1331
|
+
mcpServers: requiredDefaultOnError(vecSkipError(zMcpServer), () => []),
|
|
1332
|
+
cwd: string(),
|
|
1333
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1334
|
+
sessionId: zSessionId,
|
|
1335
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1336
|
+
});
|
|
1337
|
+
const zListSessionsRequest = object({
|
|
1338
|
+
cwd: string().nullish(),
|
|
1339
|
+
cursor: string().nullish(),
|
|
1340
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1341
|
+
});
|
|
1342
|
+
const zDeleteSessionRequest = object({
|
|
1343
|
+
sessionId: zSessionId,
|
|
1344
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1345
|
+
});
|
|
1346
|
+
const zForkSessionRequest = object({
|
|
1347
|
+
sessionId: zSessionId,
|
|
1348
|
+
cwd: string(),
|
|
1349
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1350
|
+
mcpServers: defaultOnError(vecSkipError(zMcpServer).optional(), () => []),
|
|
1351
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1352
|
+
});
|
|
1353
|
+
const zResumeSessionRequest = object({
|
|
1354
|
+
sessionId: zSessionId,
|
|
1355
|
+
cwd: string(),
|
|
1356
|
+
additionalDirectories: defaultOnError(vecSkipError(string()).optional(), () => []),
|
|
1357
|
+
mcpServers: defaultOnError(vecSkipError(zMcpServer).optional(), () => []),
|
|
1358
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1359
|
+
});
|
|
1360
|
+
const zCloseSessionRequest = object({
|
|
1361
|
+
sessionId: zSessionId,
|
|
1362
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1363
|
+
});
|
|
1364
|
+
const zSetSessionModeRequest = object({
|
|
1365
|
+
sessionId: zSessionId,
|
|
1366
|
+
modeId: zSessionModeId,
|
|
1367
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1368
|
+
});
|
|
1369
|
+
const zSetSessionConfigOptionRequest = intersection(union([
|
|
1370
|
+
object({
|
|
1371
|
+
value: boolean(),
|
|
1372
|
+
type: literal("boolean")
|
|
1373
|
+
}),
|
|
1374
|
+
object({
|
|
1375
|
+
value: zSessionConfigValueId
|
|
1376
|
+
})
|
|
1377
|
+
]), object({
|
|
1378
|
+
sessionId: zSessionId,
|
|
1379
|
+
configId: zSessionConfigId,
|
|
1380
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1381
|
+
}));
|
|
1382
|
+
const zPromptRequest = object({
|
|
1383
|
+
sessionId: zSessionId,
|
|
1384
|
+
prompt: array(zContentBlock),
|
|
1385
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1386
|
+
});
|
|
1387
|
+
const zWorkspaceFolder = object({
|
|
1388
|
+
uri: string(),
|
|
1389
|
+
name: string(),
|
|
1390
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1391
|
+
});
|
|
1392
|
+
const zNesRepository = object({
|
|
1393
|
+
name: string(),
|
|
1394
|
+
owner: string(),
|
|
1395
|
+
remoteUrl: string(),
|
|
1396
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1397
|
+
});
|
|
1398
|
+
const zStartNesRequest = object({
|
|
1399
|
+
workspaceUri: defaultOnError(string().nullish(), () => void 0),
|
|
1400
|
+
workspaceFolders: array(zWorkspaceFolder).nullish(),
|
|
1401
|
+
repository: defaultOnError(zNesRepository.nullish(), () => void 0),
|
|
1402
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1403
|
+
});
|
|
1404
|
+
const zNesTriggerKind = union([
|
|
1405
|
+
literal("automatic"),
|
|
1406
|
+
literal("diagnostic"),
|
|
1407
|
+
literal("manual")
|
|
1408
|
+
]);
|
|
1409
|
+
const zNesRecentFile = object({
|
|
1410
|
+
uri: string(),
|
|
1411
|
+
languageId: string(),
|
|
1412
|
+
text: string(),
|
|
1413
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1414
|
+
});
|
|
1415
|
+
const zNesExcerpt = object({
|
|
1416
|
+
startLine: int().gte(0).max(4294967295, {
|
|
1417
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
1418
|
+
}),
|
|
1419
|
+
endLine: int().gte(0).max(4294967295, {
|
|
1420
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
1421
|
+
}),
|
|
1422
|
+
text: string(),
|
|
1423
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1424
|
+
});
|
|
1425
|
+
const zNesRelatedSnippet = object({
|
|
1426
|
+
uri: string(),
|
|
1427
|
+
excerpts: array(zNesExcerpt),
|
|
1428
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1429
|
+
});
|
|
1430
|
+
const zNesEditHistoryEntry = object({
|
|
1431
|
+
uri: string(),
|
|
1432
|
+
diff: string(),
|
|
1433
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1434
|
+
});
|
|
1435
|
+
const zNesUserAction = object({
|
|
1436
|
+
action: string(),
|
|
1437
|
+
uri: string(),
|
|
1438
|
+
position: zPosition,
|
|
1439
|
+
timestampMs: number(),
|
|
1440
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1441
|
+
});
|
|
1442
|
+
const zNesOpenFile = object({
|
|
1443
|
+
uri: string(),
|
|
1444
|
+
languageId: string(),
|
|
1445
|
+
visibleRange: defaultOnError(zRange.nullish(), () => void 0),
|
|
1446
|
+
lastFocusedMs: defaultOnError(number().nullish(), () => void 0),
|
|
1447
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1448
|
+
});
|
|
1449
|
+
const zNesDiagnosticSeverity = union([
|
|
1450
|
+
literal("error"),
|
|
1451
|
+
literal("warning"),
|
|
1452
|
+
literal("information"),
|
|
1453
|
+
literal("hint")
|
|
1454
|
+
]);
|
|
1455
|
+
const zNesDiagnostic = object({
|
|
1456
|
+
uri: string(),
|
|
1457
|
+
range: zRange,
|
|
1458
|
+
severity: zNesDiagnosticSeverity,
|
|
1459
|
+
message: string(),
|
|
1460
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1461
|
+
});
|
|
1462
|
+
const zNesSuggestContext = object({
|
|
1463
|
+
recentFiles: array(zNesRecentFile).nullish(),
|
|
1464
|
+
relatedSnippets: array(zNesRelatedSnippet).nullish(),
|
|
1465
|
+
editHistory: array(zNesEditHistoryEntry).nullish(),
|
|
1466
|
+
userActions: array(zNesUserAction).nullish(),
|
|
1467
|
+
openFiles: array(zNesOpenFile).nullish(),
|
|
1468
|
+
diagnostics: array(zNesDiagnostic).nullish(),
|
|
1469
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1470
|
+
});
|
|
1471
|
+
const zSuggestNesRequest = object({
|
|
1472
|
+
sessionId: zSessionId,
|
|
1473
|
+
uri: string(),
|
|
1474
|
+
version: number(),
|
|
1475
|
+
position: zPosition,
|
|
1476
|
+
selection: zRange.nullish(),
|
|
1477
|
+
triggerKind: zNesTriggerKind,
|
|
1478
|
+
context: zNesSuggestContext.nullish(),
|
|
1479
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1480
|
+
});
|
|
1481
|
+
const zCloseNesRequest = object({
|
|
1482
|
+
sessionId: zSessionId,
|
|
1483
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1484
|
+
});
|
|
1485
|
+
object({
|
|
1486
|
+
id: zRequestId,
|
|
1487
|
+
method: string(),
|
|
1488
|
+
params: union([
|
|
1489
|
+
zInitializeRequest,
|
|
1490
|
+
zAuthenticateRequest,
|
|
1491
|
+
zListProvidersRequest,
|
|
1492
|
+
zSetProviderRequest,
|
|
1493
|
+
zDisableProviderRequest,
|
|
1494
|
+
zLogoutRequest,
|
|
1495
|
+
zNewSessionRequest,
|
|
1496
|
+
zLoadSessionRequest,
|
|
1497
|
+
zListSessionsRequest,
|
|
1498
|
+
zDeleteSessionRequest,
|
|
1499
|
+
zForkSessionRequest,
|
|
1500
|
+
zResumeSessionRequest,
|
|
1501
|
+
zCloseSessionRequest,
|
|
1502
|
+
zSetSessionModeRequest,
|
|
1503
|
+
zSetSessionConfigOptionRequest,
|
|
1504
|
+
zPromptRequest,
|
|
1505
|
+
zStartNesRequest,
|
|
1506
|
+
zSuggestNesRequest,
|
|
1507
|
+
zCloseNesRequest,
|
|
1508
|
+
zMessageMcpRequest,
|
|
1509
|
+
zExtRequest
|
|
1510
|
+
]).nullish()
|
|
1511
|
+
});
|
|
1512
|
+
const zWriteTextFileResponse = object({
|
|
1513
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1514
|
+
});
|
|
1515
|
+
const zReadTextFileResponse = object({
|
|
1516
|
+
content: string(),
|
|
1517
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1518
|
+
});
|
|
1519
|
+
const zSelectedPermissionOutcome = object({
|
|
1520
|
+
optionId: zPermissionOptionId,
|
|
1521
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1522
|
+
});
|
|
1523
|
+
const zRequestPermissionOutcome = union([
|
|
1524
|
+
object({
|
|
1525
|
+
outcome: literal("cancelled")
|
|
1526
|
+
}),
|
|
1527
|
+
zSelectedPermissionOutcome.and(object({
|
|
1528
|
+
outcome: literal("selected")
|
|
1529
|
+
}))
|
|
1530
|
+
]);
|
|
1531
|
+
const zRequestPermissionResponse = object({
|
|
1532
|
+
outcome: zRequestPermissionOutcome,
|
|
1533
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1534
|
+
});
|
|
1535
|
+
const zCreateTerminalResponse = object({
|
|
1536
|
+
terminalId: zTerminalId,
|
|
1537
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1538
|
+
});
|
|
1539
|
+
const zTerminalExitStatus = object({
|
|
1540
|
+
exitCode: defaultOnError(int().gte(0).max(4294967295, {
|
|
1541
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
1542
|
+
}).nullish(), () => void 0),
|
|
1543
|
+
signal: defaultOnError(string().nullish(), () => void 0),
|
|
1544
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1545
|
+
});
|
|
1546
|
+
const zTerminalOutputResponse = object({
|
|
1547
|
+
output: string(),
|
|
1548
|
+
truncated: boolean(),
|
|
1549
|
+
exitStatus: defaultOnError(zTerminalExitStatus.nullish(), () => void 0),
|
|
1550
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1551
|
+
});
|
|
1552
|
+
const zReleaseTerminalResponse = object({
|
|
1553
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1554
|
+
});
|
|
1555
|
+
const zWaitForTerminalExitResponse = object({
|
|
1556
|
+
exitCode: defaultOnError(int().gte(0).max(4294967295, {
|
|
1557
|
+
error: "Invalid value: Expected uint32 to be <= 4294967295"
|
|
1558
|
+
}).nullish(), () => void 0),
|
|
1559
|
+
signal: defaultOnError(string().nullish(), () => void 0),
|
|
1560
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1561
|
+
});
|
|
1562
|
+
const zKillTerminalResponse = object({
|
|
1563
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1564
|
+
});
|
|
1565
|
+
const zElicitationContentValue = union([
|
|
1566
|
+
string(),
|
|
1567
|
+
number(),
|
|
1568
|
+
number(),
|
|
1569
|
+
boolean(),
|
|
1570
|
+
array(string())
|
|
1571
|
+
]);
|
|
1572
|
+
const zElicitationAcceptAction = object({
|
|
1573
|
+
content: record(string(), zElicitationContentValue).nullish()
|
|
1574
|
+
});
|
|
1575
|
+
const zCreateElicitationResponse = preserveCustomPayload(intersection(union([
|
|
1576
|
+
zElicitationAcceptAction.and(object({
|
|
1577
|
+
action: literal("accept")
|
|
1578
|
+
})),
|
|
1579
|
+
object({
|
|
1580
|
+
action: literal("decline")
|
|
1581
|
+
}),
|
|
1582
|
+
object({
|
|
1583
|
+
action: literal("cancel")
|
|
1584
|
+
}),
|
|
1585
|
+
excludeKnownTags(object({
|
|
1586
|
+
action: string()
|
|
1587
|
+
}), "action", ["accept", "cancel", "decline"])
|
|
1588
|
+
]), object({
|
|
1589
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1590
|
+
})), "action", ["accept", "cancel", "decline"]);
|
|
1591
|
+
const zConnectMcpResponse = object({
|
|
1592
|
+
connectionId: zMcpConnectionId,
|
|
1593
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1594
|
+
});
|
|
1595
|
+
const zDisconnectMcpResponse = object({
|
|
1596
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1597
|
+
});
|
|
1598
|
+
union([
|
|
1599
|
+
object({
|
|
1600
|
+
id: zRequestId,
|
|
1601
|
+
result: union([
|
|
1602
|
+
zWriteTextFileResponse,
|
|
1603
|
+
zReadTextFileResponse,
|
|
1604
|
+
zRequestPermissionResponse,
|
|
1605
|
+
zCreateTerminalResponse,
|
|
1606
|
+
zTerminalOutputResponse,
|
|
1607
|
+
zReleaseTerminalResponse,
|
|
1608
|
+
zWaitForTerminalExitResponse,
|
|
1609
|
+
zKillTerminalResponse,
|
|
1610
|
+
zCreateElicitationResponse,
|
|
1611
|
+
zConnectMcpResponse,
|
|
1612
|
+
zDisconnectMcpResponse,
|
|
1613
|
+
zMessageMcpResponse,
|
|
1614
|
+
zExtResponse
|
|
1615
|
+
])
|
|
1616
|
+
}),
|
|
1617
|
+
object({
|
|
1618
|
+
id: zRequestId,
|
|
1619
|
+
error: zError
|
|
1620
|
+
})
|
|
1621
|
+
]);
|
|
1622
|
+
const zCancelNotification = object({
|
|
1623
|
+
sessionId: zSessionId,
|
|
1624
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1625
|
+
});
|
|
1626
|
+
const zDidOpenDocumentNotification = object({
|
|
1627
|
+
sessionId: zSessionId,
|
|
1628
|
+
uri: string(),
|
|
1629
|
+
languageId: string(),
|
|
1630
|
+
version: number(),
|
|
1631
|
+
text: string(),
|
|
1632
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1633
|
+
});
|
|
1634
|
+
const zTextDocumentContentChangeEvent = object({
|
|
1635
|
+
range: zRange.nullish(),
|
|
1636
|
+
text: string(),
|
|
1637
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1638
|
+
});
|
|
1639
|
+
const zDidChangeDocumentNotification = object({
|
|
1640
|
+
sessionId: zSessionId,
|
|
1641
|
+
uri: string(),
|
|
1642
|
+
version: number(),
|
|
1643
|
+
contentChanges: requiredDefaultOnError(vecSkipError(zTextDocumentContentChangeEvent), () => []),
|
|
1644
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1645
|
+
});
|
|
1646
|
+
const zDidCloseDocumentNotification = object({
|
|
1647
|
+
sessionId: zSessionId,
|
|
1648
|
+
uri: string(),
|
|
1649
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1650
|
+
});
|
|
1651
|
+
const zDidSaveDocumentNotification = object({
|
|
1652
|
+
sessionId: zSessionId,
|
|
1653
|
+
uri: string(),
|
|
1654
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1655
|
+
});
|
|
1656
|
+
const zDidFocusDocumentNotification = object({
|
|
1657
|
+
sessionId: zSessionId,
|
|
1658
|
+
uri: string(),
|
|
1659
|
+
version: number(),
|
|
1660
|
+
position: zPosition,
|
|
1661
|
+
visibleRange: zRange,
|
|
1662
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1663
|
+
});
|
|
1664
|
+
const zAcceptNesNotification = object({
|
|
1665
|
+
sessionId: zSessionId,
|
|
1666
|
+
id: zNesSuggestionId,
|
|
1667
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1668
|
+
});
|
|
1669
|
+
const zNesRejectReason = union([
|
|
1670
|
+
literal("rejected"),
|
|
1671
|
+
literal("ignored"),
|
|
1672
|
+
literal("replaced"),
|
|
1673
|
+
literal("cancelled")
|
|
1674
|
+
]);
|
|
1675
|
+
const zRejectNesNotification = object({
|
|
1676
|
+
sessionId: zSessionId,
|
|
1677
|
+
id: zNesSuggestionId,
|
|
1678
|
+
reason: defaultOnError(zNesRejectReason.nullish(), () => void 0),
|
|
1679
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1680
|
+
});
|
|
1681
|
+
object({
|
|
1682
|
+
method: string(),
|
|
1683
|
+
params: union([
|
|
1684
|
+
zCancelNotification,
|
|
1685
|
+
zDidOpenDocumentNotification,
|
|
1686
|
+
zDidChangeDocumentNotification,
|
|
1687
|
+
zDidCloseDocumentNotification,
|
|
1688
|
+
zDidSaveDocumentNotification,
|
|
1689
|
+
zDidFocusDocumentNotification,
|
|
1690
|
+
zAcceptNesNotification,
|
|
1691
|
+
zRejectNesNotification,
|
|
1692
|
+
zMessageMcpNotification,
|
|
1693
|
+
zExtNotification
|
|
1694
|
+
]).nullish()
|
|
1695
|
+
});
|
|
1696
|
+
object({
|
|
1697
|
+
requestId: zRequestId,
|
|
1698
|
+
_meta: defaultOnError(record(string(), unknown()).nullish(), () => void 0)
|
|
1699
|
+
});
|
|
1700
|
+
function tagOf(value, key) {
|
|
1701
|
+
return typeof value === "object" && value !== null ? value[key] : void 0;
|
|
1702
|
+
}
|
|
1703
|
+
zElicitationFormMode.and(object({ mode: literal("form") })).and(object({ message: string() }));
|
|
1704
|
+
zElicitationUrlMode.and(object({ mode: literal("url") })).and(object({ message: string() }));
|
|
1705
|
+
union([zElicitationSessionScope, zElicitationRequestScope]).and(object({ message: string() }));
|
|
1706
|
+
zStringPropertySchema.and(object({ type: literal("string") }));
|
|
1707
|
+
zNumberPropertySchema.and(object({ type: literal("number") }));
|
|
1708
|
+
zIntegerPropertySchema.and(object({ type: literal("integer") }));
|
|
1709
|
+
zBooleanPropertySchema.and(object({ type: literal("boolean") }));
|
|
1710
|
+
zMultiSelectPropertySchema.and(object({ type: literal("array") }));
|
|
1711
|
+
zStringMultiSelectItems.and(object({ type: literal("string") }));
|
|
1712
|
+
const zGuardCreateElicitationResponseAccept = zElicitationAcceptAction.and(object({ action: literal("accept") }));
|
|
1713
|
+
const zGuardCreateElicitationResponseDecline = object({
|
|
1714
|
+
action: literal("decline")
|
|
1715
|
+
});
|
|
1716
|
+
const zGuardCreateElicitationResponseCancel = object({
|
|
1717
|
+
action: literal("cancel")
|
|
1718
|
+
});
|
|
1719
|
+
const CreateElicitationResponse = {
|
|
1720
|
+
/** Narrow to the `accept` variant, validating its payload. */
|
|
1721
|
+
isAccept(value) {
|
|
1722
|
+
return tagOf(value, "action") === "accept" && zGuardCreateElicitationResponseAccept.safeParse(value).success;
|
|
1723
|
+
},
|
|
1724
|
+
/** Narrow to the `decline` variant, validating its payload. */
|
|
1725
|
+
isDecline(value) {
|
|
1726
|
+
return tagOf(value, "action") === "decline" && zGuardCreateElicitationResponseDecline.safeParse(value).success;
|
|
1727
|
+
},
|
|
1728
|
+
/** Narrow to the `cancel` variant, validating its payload. */
|
|
1729
|
+
isCancel(value) {
|
|
1730
|
+
return tagOf(value, "action") === "cancel" && zGuardCreateElicitationResponseCancel.safeParse(value).success;
|
|
1731
|
+
},
|
|
1732
|
+
/**
|
|
1733
|
+
* Narrow to a custom or future variant: the `action` tag matches no known variant.
|
|
1734
|
+
*
|
|
1735
|
+
* TypeScript keeps the known variants in the narrowed union (they are
|
|
1736
|
+
* structural subtypes of the catch-all), so read vendor payload keys
|
|
1737
|
+
* via a widening cast: `(value as Record<string, unknown>).someKey`.
|
|
1738
|
+
*/
|
|
1739
|
+
isCustom(value) {
|
|
1740
|
+
const tag = tagOf(value, "action");
|
|
1741
|
+
return typeof tag === "string" && !["accept", "cancel", "decline"].includes(tag);
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
const CANCEL_REQUEST_METHOD = "$/cancel_request";
|
|
1745
|
+
function isRecord(value) {
|
|
1746
|
+
return typeof value === "object" && value !== null;
|
|
1747
|
+
}
|
|
1748
|
+
function isJsonRpcId(value) {
|
|
1749
|
+
return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
|
|
1750
|
+
}
|
|
1751
|
+
function cancelRequestId(params) {
|
|
1752
|
+
if (!isRecord(params) || !isJsonRpcId(params["requestId"])) {
|
|
1753
|
+
return void 0;
|
|
1754
|
+
}
|
|
1755
|
+
return params["requestId"];
|
|
1756
|
+
}
|
|
1757
|
+
const Handled = {
|
|
1758
|
+
/**
|
|
1759
|
+
* Marks a message as handled.
|
|
1760
|
+
*/
|
|
1761
|
+
yes() {
|
|
1762
|
+
return { handled: true };
|
|
1763
|
+
},
|
|
1764
|
+
/**
|
|
1765
|
+
* Leaves a message unhandled so later handlers can process it.
|
|
1766
|
+
*/
|
|
1767
|
+
no(message, retry = false) {
|
|
1768
|
+
return { handled: false, message, retry };
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
function rejectedPromise(error) {
|
|
1772
|
+
const promise = Promise.reject(error);
|
|
1773
|
+
promise.catch(() => {
|
|
1774
|
+
});
|
|
1775
|
+
return promise;
|
|
1776
|
+
}
|
|
1777
|
+
function errorDetails(error) {
|
|
1778
|
+
if (error instanceof Error) {
|
|
1779
|
+
return error.message;
|
|
1780
|
+
}
|
|
1781
|
+
if (typeof error === "object" && error != null && "message" in error && typeof error.message === "string") {
|
|
1782
|
+
return error.message;
|
|
1783
|
+
}
|
|
1784
|
+
return void 0;
|
|
1785
|
+
}
|
|
1786
|
+
function isZodError(error) {
|
|
1787
|
+
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";
|
|
1788
|
+
}
|
|
1789
|
+
function errorToResult(error) {
|
|
1790
|
+
if (error instanceof RequestError) {
|
|
1791
|
+
return error.toResult();
|
|
1792
|
+
}
|
|
1793
|
+
if (isZodError(error)) {
|
|
1794
|
+
return RequestError.invalidParams(error.format()).toResult();
|
|
1795
|
+
}
|
|
1796
|
+
const details = errorDetails(error);
|
|
1797
|
+
try {
|
|
1798
|
+
return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
|
|
1799
|
+
} catch {
|
|
1800
|
+
return RequestError.internalError({ details }).toResult();
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
function requestCancelledError(reason) {
|
|
1804
|
+
if (reason instanceof RequestError && reason.code === -32800) {
|
|
1805
|
+
return reason;
|
|
1806
|
+
}
|
|
1807
|
+
return RequestError.requestCancelled(reason);
|
|
1808
|
+
}
|
|
1809
|
+
function errorToRequestResult(error, signal) {
|
|
1810
|
+
const requestCancelled = abortErrorToRequestCancelled(error, signal);
|
|
1811
|
+
return requestCancelled ? requestCancelled.toResult() : errorToResult(error);
|
|
1812
|
+
}
|
|
1813
|
+
function abortErrorToRequestCancelled(error, signal) {
|
|
1814
|
+
if (!signal.aborted || !isAbortError(error)) {
|
|
1815
|
+
return void 0;
|
|
1816
|
+
}
|
|
1817
|
+
return requestCancelledError(signal.reason);
|
|
1818
|
+
}
|
|
1819
|
+
function isAbortError(error) {
|
|
1820
|
+
if (typeof error !== "object" || error === null) {
|
|
1821
|
+
return false;
|
|
1822
|
+
}
|
|
1823
|
+
const maybeAbortError = error;
|
|
1824
|
+
return maybeAbortError.name === "AbortError" || maybeAbortError.code === "ABORT_ERR";
|
|
1825
|
+
}
|
|
1826
|
+
class RequestResponder {
|
|
1827
|
+
id;
|
|
1828
|
+
sendResult;
|
|
1829
|
+
signal;
|
|
1830
|
+
finishRequest;
|
|
1831
|
+
didRespond = false;
|
|
1832
|
+
constructor(id, sendResult, signal = new AbortController().signal, finishRequest) {
|
|
1833
|
+
this.id = id;
|
|
1834
|
+
this.sendResult = sendResult;
|
|
1835
|
+
this.signal = signal;
|
|
1836
|
+
this.finishRequest = finishRequest;
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* Whether this request has already received a response.
|
|
1840
|
+
*/
|
|
1841
|
+
get responded() {
|
|
1842
|
+
return this.didRespond;
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Sends a successful JSON-RPC response.
|
|
1846
|
+
*/
|
|
1847
|
+
respond(response) {
|
|
1848
|
+
return this.respondWithResult({ result: response ?? null });
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Sends an error JSON-RPC response.
|
|
1852
|
+
*/
|
|
1853
|
+
respondWithError(error) {
|
|
1854
|
+
const errorResponse = error instanceof RequestError ? error.toErrorResponse() : error;
|
|
1855
|
+
return this.respondWithResult({ error: errorResponse });
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Sends a complete JSON-RPC result payload.
|
|
1859
|
+
*/
|
|
1860
|
+
respondWithResult(result) {
|
|
1861
|
+
if (this.didRespond) {
|
|
1862
|
+
return rejectedPromise(new Error("JSON-RPC request already responded"));
|
|
1863
|
+
}
|
|
1864
|
+
this.didRespond = true;
|
|
1865
|
+
return this.sendResult(result).finally(() => {
|
|
1866
|
+
this.finishRequest?.();
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
class HandlerRegistration {
|
|
1871
|
+
disposeHandler;
|
|
1872
|
+
active = true;
|
|
1873
|
+
constructor(disposeHandler) {
|
|
1874
|
+
this.disposeHandler = disposeHandler;
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Unregisters the associated handler.
|
|
1878
|
+
*/
|
|
1879
|
+
dispose() {
|
|
1880
|
+
if (!this.active) {
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
this.active = false;
|
|
1884
|
+
this.disposeHandler();
|
|
1885
|
+
}
|
|
1886
|
+
/**
|
|
1887
|
+
* Supports explicit resource management with `using`.
|
|
1888
|
+
*/
|
|
1889
|
+
[Symbol.dispose]() {
|
|
1890
|
+
this.dispose();
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Returns this registration for call sites that intentionally keep it active.
|
|
1894
|
+
*/
|
|
1895
|
+
runIndefinitely() {
|
|
1896
|
+
return this;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
class ConnectionContext {
|
|
1900
|
+
connection;
|
|
1901
|
+
constructor(connection) {
|
|
1902
|
+
this.connection = connection;
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Sends a request over the connection.
|
|
1906
|
+
*/
|
|
1907
|
+
sendRequest(method, params, mapResponse, options) {
|
|
1908
|
+
return this.connection.sendRequest(method, params, mapResponse, options);
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Sends a notification over the connection.
|
|
1912
|
+
*/
|
|
1913
|
+
sendNotification(method, params) {
|
|
1914
|
+
return this.connection.sendNotification(method, params);
|
|
1915
|
+
}
|
|
1916
|
+
/**
|
|
1917
|
+
* Sends a protocol-level request cancellation notification.
|
|
1918
|
+
*/
|
|
1919
|
+
sendCancelRequest(requestId) {
|
|
1920
|
+
return this.connection.sendCancelRequest(requestId);
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Registers a handler that can be disposed independently.
|
|
1924
|
+
*/
|
|
1925
|
+
addDynamicHandler(handler) {
|
|
1926
|
+
return this.connection.addDynamicHandler(handler);
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* AbortSignal that aborts when the connection closes.
|
|
1930
|
+
*/
|
|
1931
|
+
get signal() {
|
|
1932
|
+
return this.connection.signal;
|
|
1933
|
+
}
|
|
1934
|
+
/**
|
|
1935
|
+
* Promise that resolves when the connection closes.
|
|
1936
|
+
*/
|
|
1937
|
+
get closed() {
|
|
1938
|
+
return this.connection.closed;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
class Connection {
|
|
1942
|
+
pendingResponses = /* @__PURE__ */ new Map();
|
|
1943
|
+
incomingRequests = /* @__PURE__ */ new Map();
|
|
1944
|
+
nextRequestId = 0;
|
|
1945
|
+
staticHandlers = [];
|
|
1946
|
+
dynamicHandlers = /* @__PURE__ */ new Set();
|
|
1947
|
+
stream;
|
|
1948
|
+
writeQueue = Promise.resolve();
|
|
1949
|
+
abortController = new AbortController();
|
|
1950
|
+
closedPromise;
|
|
1951
|
+
retryQueue = [];
|
|
1952
|
+
context = new ConnectionContext(this);
|
|
1953
|
+
receiveReader;
|
|
1954
|
+
constructor(requestHandlerOrStream, notificationHandlerOrHandlers, streamOrOptions, options) {
|
|
1955
|
+
if (typeof requestHandlerOrStream === "function") {
|
|
1956
|
+
const requestHandler = requestHandlerOrStream;
|
|
1957
|
+
const notificationHandler = notificationHandlerOrHandlers;
|
|
1958
|
+
const stream2 = streamOrOptions;
|
|
1959
|
+
this.initialize(stream2, [
|
|
1960
|
+
...options?.handlers ?? [],
|
|
1961
|
+
this.legacyHandler(requestHandler, notificationHandler)
|
|
1962
|
+
]);
|
|
1963
|
+
return;
|
|
1964
|
+
}
|
|
1965
|
+
const stream = requestHandlerOrStream;
|
|
1966
|
+
const handlers = notificationHandlerOrHandlers;
|
|
1967
|
+
const connectionOptions = streamOrOptions;
|
|
1968
|
+
this.initialize(stream, [
|
|
1969
|
+
...connectionOptions?.handlers ?? [],
|
|
1970
|
+
...handlers
|
|
1971
|
+
]);
|
|
1972
|
+
}
|
|
1973
|
+
/**
|
|
1974
|
+
* Creates a builder for configuring a handler-based connection.
|
|
1975
|
+
*/
|
|
1976
|
+
static builder() {
|
|
1977
|
+
return new ConnectionBuilder();
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Runs an operation while the connection is open, then closes the connection.
|
|
1981
|
+
*
|
|
1982
|
+
* If the stream closes before `op` settles, the returned promise rejects with
|
|
1983
|
+
* the connection close reason.
|
|
1984
|
+
*/
|
|
1985
|
+
runUntil(op) {
|
|
1986
|
+
let opSettled = false;
|
|
1987
|
+
const opPromise = Promise.resolve().then(() => op(this.context)).finally(() => {
|
|
1988
|
+
opSettled = true;
|
|
1989
|
+
});
|
|
1990
|
+
const closedPromise = this.closed.then(() => {
|
|
1991
|
+
if (opSettled) {
|
|
1992
|
+
return new Promise(() => {
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
throw this.closedReason();
|
|
1996
|
+
});
|
|
1997
|
+
return Promise.race([opPromise, closedPromise]).finally(() => {
|
|
1998
|
+
opSettled = true;
|
|
1999
|
+
this.close();
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
/**
|
|
2003
|
+
* Adds a handler after the connection has started.
|
|
2004
|
+
*
|
|
2005
|
+
* Any messages queued with `Handled.no(message, true)` are retried after the
|
|
2006
|
+
* handler is added.
|
|
2007
|
+
*/
|
|
2008
|
+
addDynamicHandler(handler) {
|
|
2009
|
+
this.dynamicHandlers.add(handler);
|
|
2010
|
+
if (this.retryQueue.length > 0) {
|
|
2011
|
+
for (const message of this.retryQueue.splice(0)) {
|
|
2012
|
+
void this.processIncomingMessage(message).catch((error) => this.close(error));
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
return new HandlerRegistration(() => {
|
|
2016
|
+
this.dynamicHandlers.delete(handler);
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* AbortSignal that aborts when the connection closes.
|
|
2021
|
+
*/
|
|
2022
|
+
get signal() {
|
|
2023
|
+
return this.abortController.signal;
|
|
2024
|
+
}
|
|
2025
|
+
/**
|
|
2026
|
+
* Promise that resolves when the connection closes.
|
|
2027
|
+
*/
|
|
2028
|
+
get closed() {
|
|
2029
|
+
return this.closedPromise;
|
|
2030
|
+
}
|
|
2031
|
+
/** @internal */
|
|
2032
|
+
getContext() {
|
|
2033
|
+
return this.context;
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Sends a JSON-RPC request.
|
|
2037
|
+
*
|
|
2038
|
+
* `mapResponse` can convert the raw result before the returned promise
|
|
2039
|
+
* resolves.
|
|
2040
|
+
*/
|
|
2041
|
+
sendRequest(method, params, mapResponse, options = {}) {
|
|
2042
|
+
if (this.abortController.signal.aborted) {
|
|
2043
|
+
return rejectedPromise(this.closedReason());
|
|
2044
|
+
}
|
|
2045
|
+
const id = this.nextRequestId++;
|
|
2046
|
+
let cancel = () => {
|
|
2047
|
+
};
|
|
2048
|
+
const responsePromise = new Promise((resolve, reject) => {
|
|
2049
|
+
const pendingResponse = {
|
|
2050
|
+
resolve: (response) => {
|
|
2051
|
+
try {
|
|
2052
|
+
const value = mapResponse ? mapResponse(response) : response;
|
|
2053
|
+
resolve(value);
|
|
2054
|
+
} catch (error) {
|
|
2055
|
+
reject(error);
|
|
2056
|
+
}
|
|
2057
|
+
},
|
|
2058
|
+
reject
|
|
2059
|
+
};
|
|
2060
|
+
cancel = () => {
|
|
2061
|
+
if (pendingResponse.cancellationSent) {
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
pendingResponse.cancellationSent = true;
|
|
2065
|
+
pendingResponse.cleanup?.();
|
|
2066
|
+
void this.sendCancelRequest(id).catch(() => {
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
options.cancellationSignal?.addEventListener("abort", cancel, {
|
|
2070
|
+
once: true
|
|
2071
|
+
});
|
|
2072
|
+
pendingResponse.cleanup = () => {
|
|
2073
|
+
options.cancellationSignal?.removeEventListener("abort", cancel);
|
|
2074
|
+
};
|
|
2075
|
+
this.pendingResponses.set(id, pendingResponse);
|
|
2076
|
+
});
|
|
2077
|
+
responsePromise.catch(() => {
|
|
2078
|
+
});
|
|
2079
|
+
const requestSent = this.sendMessage({
|
|
2080
|
+
jsonrpc: "2.0",
|
|
2081
|
+
id,
|
|
2082
|
+
method,
|
|
2083
|
+
params
|
|
2084
|
+
});
|
|
2085
|
+
void requestSent.catch(() => {
|
|
2086
|
+
});
|
|
2087
|
+
if (options.cancellationSignal?.aborted) {
|
|
2088
|
+
cancel();
|
|
2089
|
+
}
|
|
2090
|
+
return responsePromise;
|
|
2091
|
+
}
|
|
2092
|
+
/**
|
|
2093
|
+
* Sends a protocol-level request cancellation notification.
|
|
2094
|
+
*/
|
|
2095
|
+
sendCancelRequest(requestId) {
|
|
2096
|
+
return this.sendNotification(CANCEL_REQUEST_METHOD, { requestId });
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Sends a JSON-RPC notification.
|
|
2100
|
+
*/
|
|
2101
|
+
sendNotification(method, params) {
|
|
2102
|
+
if (this.abortController.signal.aborted) {
|
|
2103
|
+
return rejectedPromise(this.closedReason());
|
|
2104
|
+
}
|
|
2105
|
+
return this.sendMessage({ jsonrpc: "2.0", method, params });
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Closes the connection and rejects pending requests.
|
|
2109
|
+
*/
|
|
2110
|
+
close(error) {
|
|
2111
|
+
if (this.abortController.signal.aborted) {
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
const closeError = error ?? new Error("ACP connection closed");
|
|
2115
|
+
this.abortController.abort(closeError);
|
|
2116
|
+
for (const pendingResponse of this.pendingResponses.values()) {
|
|
2117
|
+
pendingResponse.cleanup?.();
|
|
2118
|
+
pendingResponse.reject(closeError);
|
|
2119
|
+
}
|
|
2120
|
+
this.pendingResponses.clear();
|
|
2121
|
+
for (const controller of this.incomingRequests.values()) {
|
|
2122
|
+
controller.abort(closeError);
|
|
2123
|
+
}
|
|
2124
|
+
this.incomingRequests.clear();
|
|
2125
|
+
void this.receiveReader?.cancel(closeError).catch(() => {
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
initialize(stream, handlers) {
|
|
2129
|
+
this.stream = stream;
|
|
2130
|
+
this.staticHandlers = handlers;
|
|
2131
|
+
this.closedPromise = new Promise((resolve) => {
|
|
2132
|
+
this.abortController.signal.addEventListener("abort", () => resolve());
|
|
2133
|
+
});
|
|
2134
|
+
void this.receive();
|
|
2135
|
+
}
|
|
2136
|
+
legacyHandler(requestHandler, notificationHandler) {
|
|
2137
|
+
return {
|
|
2138
|
+
handleMessage: async (message, cx) => {
|
|
2139
|
+
if (message.kind === "request") {
|
|
2140
|
+
const result = await requestHandler(message.method, message.params, cx);
|
|
2141
|
+
await message.responder.respond(result);
|
|
2142
|
+
} else {
|
|
2143
|
+
await notificationHandler(message.method, message.params, cx);
|
|
2144
|
+
}
|
|
2145
|
+
return Handled.yes();
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
async receive() {
|
|
2150
|
+
let closeError = void 0;
|
|
2151
|
+
try {
|
|
2152
|
+
const reader = this.stream.readable.getReader();
|
|
2153
|
+
this.receiveReader = reader;
|
|
2154
|
+
try {
|
|
2155
|
+
while (!this.abortController.signal.aborted) {
|
|
2156
|
+
const { value: message, done } = await reader.read();
|
|
2157
|
+
if (this.abortController.signal.aborted) {
|
|
2158
|
+
break;
|
|
2159
|
+
}
|
|
2160
|
+
if (done) {
|
|
2161
|
+
break;
|
|
2162
|
+
}
|
|
2163
|
+
if (!message) {
|
|
2164
|
+
continue;
|
|
2165
|
+
}
|
|
2166
|
+
this.receiveMessage(message);
|
|
2167
|
+
}
|
|
2168
|
+
} finally {
|
|
2169
|
+
if (this.receiveReader === reader) {
|
|
2170
|
+
this.receiveReader = void 0;
|
|
2171
|
+
}
|
|
2172
|
+
reader.releaseLock();
|
|
2173
|
+
}
|
|
2174
|
+
} catch (error) {
|
|
2175
|
+
closeError = error;
|
|
2176
|
+
} finally {
|
|
2177
|
+
this.close(closeError);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
receiveMessage(message) {
|
|
2181
|
+
if (this.abortController.signal.aborted) {
|
|
2182
|
+
return;
|
|
2183
|
+
}
|
|
2184
|
+
if (!isRecord(message)) {
|
|
2185
|
+
console.error("Invalid message", { message });
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
if ("method" in message) {
|
|
2189
|
+
if (!("id" in message)) {
|
|
2190
|
+
this.handleProtocolNotification(message);
|
|
2191
|
+
}
|
|
2192
|
+
void this.processIncomingMessage(this.toIncomingMessage(message)).catch((error) => this.close(error));
|
|
2193
|
+
} else if ("id" in message) {
|
|
2194
|
+
this.handleResponse(message);
|
|
2195
|
+
} else {
|
|
2196
|
+
console.error("Invalid message", { message });
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
async processIncomingMessage(message) {
|
|
2200
|
+
if (this.abortController.signal.aborted) {
|
|
2201
|
+
return;
|
|
2202
|
+
}
|
|
2203
|
+
let current = message;
|
|
2204
|
+
let retry = false;
|
|
2205
|
+
try {
|
|
2206
|
+
for (const handler of [
|
|
2207
|
+
...this.staticHandlers,
|
|
2208
|
+
...this.dynamicHandlers.values()
|
|
2209
|
+
]) {
|
|
2210
|
+
if (this.abortController.signal.aborted) {
|
|
2211
|
+
return;
|
|
2212
|
+
}
|
|
2213
|
+
const result = await handler.handleMessage(current, this.context) ?? {
|
|
2214
|
+
handled: true
|
|
2215
|
+
};
|
|
2216
|
+
if (result.handled) {
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
current = result.message ?? current;
|
|
2220
|
+
retry = retry || Boolean(result.retry);
|
|
2221
|
+
}
|
|
2222
|
+
if (retry) {
|
|
2223
|
+
this.retryQueue.push(current);
|
|
2224
|
+
} else if (current.kind === "request") {
|
|
2225
|
+
await current.responder.respondWithError(RequestError.methodNotFound(current.method));
|
|
2226
|
+
}
|
|
2227
|
+
} catch (error) {
|
|
2228
|
+
if (this.abortController.signal.aborted) {
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
if (current.kind === "request" && !current.responder.responded) {
|
|
2232
|
+
await current.responder.respondWithResult(errorToRequestResult(error, current.responder.signal));
|
|
2233
|
+
} else {
|
|
2234
|
+
const response = errorToResult(error);
|
|
2235
|
+
if ("error" in response) {
|
|
2236
|
+
console.error("Error handling notification", message.raw, response.error);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
toIncomingMessage(message) {
|
|
2242
|
+
if ("id" in message) {
|
|
2243
|
+
const abortController = new AbortController();
|
|
2244
|
+
this.incomingRequests.set(message.id, abortController);
|
|
2245
|
+
const finishRequest = () => {
|
|
2246
|
+
if (this.incomingRequests.get(message.id) === abortController) {
|
|
2247
|
+
this.incomingRequests.delete(message.id);
|
|
2248
|
+
}
|
|
2249
|
+
};
|
|
2250
|
+
return {
|
|
2251
|
+
kind: "request",
|
|
2252
|
+
method: message.method,
|
|
2253
|
+
params: message.params,
|
|
2254
|
+
raw: message,
|
|
2255
|
+
signal: abortController.signal,
|
|
2256
|
+
responder: new RequestResponder(message.id, (result) => this.sendMessage({
|
|
2257
|
+
jsonrpc: "2.0",
|
|
2258
|
+
id: message.id,
|
|
2259
|
+
...result
|
|
2260
|
+
}), abortController.signal, finishRequest)
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
return {
|
|
2264
|
+
kind: "notification",
|
|
2265
|
+
method: message.method,
|
|
2266
|
+
params: message.params,
|
|
2267
|
+
raw: message
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
handleResponse(response) {
|
|
2271
|
+
const pendingResponse = this.pendingResponses.get(response.id);
|
|
2272
|
+
if (pendingResponse) {
|
|
2273
|
+
this.pendingResponses.delete(response.id);
|
|
2274
|
+
pendingResponse.cleanup?.();
|
|
2275
|
+
if ("result" in response) {
|
|
2276
|
+
pendingResponse.resolve(response.result);
|
|
2277
|
+
} else if ("error" in response && isRecord(response.error)) {
|
|
2278
|
+
const { code, message, data } = response.error;
|
|
2279
|
+
pendingResponse.reject(new RequestError(code, message, data));
|
|
2280
|
+
} else {
|
|
2281
|
+
pendingResponse.reject(RequestError.invalidRequest(response));
|
|
2282
|
+
}
|
|
2283
|
+
} else {
|
|
2284
|
+
console.error("Got response to unknown request", response.id);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
handleProtocolNotification(message) {
|
|
2288
|
+
if (message.method !== CANCEL_REQUEST_METHOD) {
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
const requestId = cancelRequestId(message.params);
|
|
2292
|
+
if (requestId === void 0) {
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
const controller = this.incomingRequests.get(requestId);
|
|
2296
|
+
if (!controller || controller.signal.aborted) {
|
|
2297
|
+
return;
|
|
2298
|
+
}
|
|
2299
|
+
controller.abort(RequestError.requestCancelled({ requestId }));
|
|
2300
|
+
}
|
|
2301
|
+
closedReason() {
|
|
2302
|
+
return this.abortController.signal.reason ?? new Error("ACP connection closed");
|
|
2303
|
+
}
|
|
2304
|
+
async sendMessage(message) {
|
|
2305
|
+
if (this.abortController.signal.aborted) {
|
|
2306
|
+
return rejectedPromise(this.closedReason());
|
|
2307
|
+
}
|
|
2308
|
+
this.writeQueue = this.writeQueue.then(async () => {
|
|
2309
|
+
if (this.abortController.signal.aborted) {
|
|
2310
|
+
throw this.closedReason();
|
|
2311
|
+
}
|
|
2312
|
+
const writer = this.stream.writable.getWriter();
|
|
2313
|
+
try {
|
|
2314
|
+
await writer.write(message);
|
|
2315
|
+
} finally {
|
|
2316
|
+
writer.releaseLock();
|
|
2317
|
+
}
|
|
2318
|
+
}).catch((error) => {
|
|
2319
|
+
this.close(error);
|
|
2320
|
+
throw error;
|
|
2321
|
+
});
|
|
2322
|
+
return this.writeQueue;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
class ConnectionBuilder {
|
|
2326
|
+
handlers = [];
|
|
2327
|
+
connectionName;
|
|
2328
|
+
/**
|
|
2329
|
+
* Sets a diagnostic name used by handlers created from this builder.
|
|
2330
|
+
*/
|
|
2331
|
+
name(name2) {
|
|
2332
|
+
this.connectionName = name2;
|
|
2333
|
+
return this;
|
|
2334
|
+
}
|
|
2335
|
+
/**
|
|
2336
|
+
* Adds a raw JSON-RPC handler to the handler chain.
|
|
2337
|
+
*/
|
|
2338
|
+
withHandler(handler) {
|
|
2339
|
+
this.handlers.push(handler);
|
|
2340
|
+
return this;
|
|
2341
|
+
}
|
|
2342
|
+
/**
|
|
2343
|
+
* Adds a handler that can inspect every incoming request or notification.
|
|
2344
|
+
*
|
|
2345
|
+
* Observer callbacks that return void pass the message through to later
|
|
2346
|
+
* handlers. Return `Handled.yes()` to stop dispatch explicitly.
|
|
2347
|
+
*/
|
|
2348
|
+
onReceiveMessage(handler) {
|
|
2349
|
+
return this.withHandler({
|
|
2350
|
+
handleMessage: async (message, cx) => await handler(message, cx) ?? Handled.no(message),
|
|
2351
|
+
describe: () => this.connectionName ?? "onReceiveMessage"
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
/**
|
|
2355
|
+
* Adds a typed request handler for one method.
|
|
2356
|
+
*/
|
|
2357
|
+
onReceiveRequest(method, parse, handler) {
|
|
2358
|
+
return this.withHandler({
|
|
2359
|
+
handleMessage: async (message, cx) => {
|
|
2360
|
+
if (message.kind !== "request" || message.method !== method) {
|
|
2361
|
+
return Handled.no(message);
|
|
2362
|
+
}
|
|
2363
|
+
const request = parse(message.params);
|
|
2364
|
+
return await handler(request, message.responder, cx) ?? Handled.yes();
|
|
2365
|
+
},
|
|
2366
|
+
describe: () => `${this.connectionName ?? "request"}:${method}`
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Adds a typed notification handler for one method.
|
|
2371
|
+
*/
|
|
2372
|
+
onReceiveNotification(method, parse, handler) {
|
|
2373
|
+
return this.withHandler({
|
|
2374
|
+
handleMessage: async (message, cx) => {
|
|
2375
|
+
if (message.kind !== "notification" || message.method !== method) {
|
|
2376
|
+
return Handled.no(message);
|
|
2377
|
+
}
|
|
2378
|
+
const notification = parse(message.params);
|
|
2379
|
+
return await handler(notification, cx) ?? Handled.yes();
|
|
2380
|
+
},
|
|
2381
|
+
describe: () => `${this.connectionName ?? "notification"}:${method}`
|
|
2382
|
+
});
|
|
2383
|
+
}
|
|
2384
|
+
/**
|
|
2385
|
+
* Connects the configured handlers to a stream.
|
|
2386
|
+
*/
|
|
2387
|
+
connect(stream, options) {
|
|
2388
|
+
return new Connection(stream, this.handlers, options);
|
|
2389
|
+
}
|
|
2390
|
+
/**
|
|
2391
|
+
* Connects to a stream for the lifetime of `op`, then closes the connection.
|
|
2392
|
+
*/
|
|
2393
|
+
connectWith(stream, op, options) {
|
|
2394
|
+
return this.connect(stream, options).runUntil(op);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
class RequestError extends Error {
|
|
2398
|
+
code;
|
|
2399
|
+
/**
|
|
2400
|
+
* Additional JSON-RPC error data.
|
|
2401
|
+
*/
|
|
2402
|
+
data;
|
|
2403
|
+
constructor(code, message, data) {
|
|
2404
|
+
super(message);
|
|
2405
|
+
this.code = code;
|
|
2406
|
+
this.name = "RequestError";
|
|
2407
|
+
this.data = data;
|
|
2408
|
+
}
|
|
2409
|
+
/**
|
|
2410
|
+
* Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
|
|
2411
|
+
*/
|
|
2412
|
+
static parseError(data, additionalMessage) {
|
|
2413
|
+
return new RequestError(-32700, `Parse error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* The JSON sent is not a valid Request object.
|
|
2417
|
+
*/
|
|
2418
|
+
static invalidRequest(data, additionalMessage) {
|
|
2419
|
+
return new RequestError(-32600, `Invalid request${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* The method does not exist / is not available.
|
|
2423
|
+
*/
|
|
2424
|
+
static methodNotFound(method) {
|
|
2425
|
+
return new RequestError(-32601, `"Method not found": ${method}`, {
|
|
2426
|
+
method
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Invalid method parameter(s).
|
|
2431
|
+
*/
|
|
2432
|
+
static invalidParams(data, additionalMessage) {
|
|
2433
|
+
return new RequestError(-32602, `Invalid params${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* Internal JSON-RPC error.
|
|
2437
|
+
*/
|
|
2438
|
+
static internalError(data, additionalMessage) {
|
|
2439
|
+
return new RequestError(-32603, `Internal error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
2440
|
+
}
|
|
2441
|
+
/**
|
|
2442
|
+
* Execution of the request was aborted.
|
|
2443
|
+
*/
|
|
2444
|
+
static requestCancelled(data, additionalMessage) {
|
|
2445
|
+
return new RequestError(-32800, `Request cancelled${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Authentication required.
|
|
2449
|
+
*/
|
|
2450
|
+
static authRequired(data, additionalMessage) {
|
|
2451
|
+
return new RequestError(-32e3, `Authentication required${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
|
|
2452
|
+
}
|
|
2453
|
+
/**
|
|
2454
|
+
* Resource, such as a file, was not found
|
|
2455
|
+
*/
|
|
2456
|
+
static resourceNotFound(uri) {
|
|
2457
|
+
return new RequestError(-32002, `Resource not found${uri ? `: ${uri}` : ""}`, uri && { uri });
|
|
2458
|
+
}
|
|
2459
|
+
/**
|
|
2460
|
+
* Converts this error to a JSON-RPC result object.
|
|
2461
|
+
*/
|
|
2462
|
+
toResult() {
|
|
2463
|
+
return {
|
|
2464
|
+
error: {
|
|
2465
|
+
code: this.code,
|
|
2466
|
+
message: this.message,
|
|
2467
|
+
data: this.data
|
|
2468
|
+
}
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Converts this error to a JSON-RPC error response payload.
|
|
2473
|
+
*/
|
|
2474
|
+
toErrorResponse() {
|
|
2475
|
+
return {
|
|
2476
|
+
code: this.code,
|
|
2477
|
+
message: this.message,
|
|
2478
|
+
data: this.data
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
const newline = 10;
|
|
2483
|
+
class LineBuffer {
|
|
2484
|
+
/** Bytes of the current (incomplete) line, carried across chunks. */
|
|
2485
|
+
#pending = [];
|
|
2486
|
+
/**
|
|
2487
|
+
* Consumes a chunk, returning each complete line without its trailing
|
|
2488
|
+
* newline.
|
|
2489
|
+
*/
|
|
2490
|
+
push(chunk) {
|
|
2491
|
+
const lines = [];
|
|
2492
|
+
let start = 0;
|
|
2493
|
+
let newlineIndex = chunk.indexOf(newline, start);
|
|
2494
|
+
while (newlineIndex !== -1) {
|
|
2495
|
+
lines.push(this.#takeLine(chunk.subarray(start, newlineIndex)));
|
|
2496
|
+
start = newlineIndex + 1;
|
|
2497
|
+
newlineIndex = chunk.indexOf(newline, start);
|
|
2498
|
+
}
|
|
2499
|
+
if (start < chunk.byteLength) {
|
|
2500
|
+
this.#pending.push(start === 0 ? chunk : new Uint8Array(chunk.subarray(start)));
|
|
2501
|
+
}
|
|
2502
|
+
return lines;
|
|
2503
|
+
}
|
|
2504
|
+
/**
|
|
2505
|
+
* Returns the trailing unterminated line and resets the buffer, or
|
|
2506
|
+
* undefined if no bytes are buffered.
|
|
2507
|
+
*/
|
|
2508
|
+
flush() {
|
|
2509
|
+
if (this.#pending.length === 0) {
|
|
2510
|
+
return void 0;
|
|
2511
|
+
}
|
|
2512
|
+
return this.#takeLine(new Uint8Array(0));
|
|
2513
|
+
}
|
|
2514
|
+
#takeLine(tail) {
|
|
2515
|
+
if (this.#pending.length === 0) {
|
|
2516
|
+
return tail;
|
|
2517
|
+
}
|
|
2518
|
+
let total = tail.byteLength;
|
|
2519
|
+
for (const part of this.#pending) {
|
|
2520
|
+
total += part.byteLength;
|
|
2521
|
+
}
|
|
2522
|
+
const line = new Uint8Array(total);
|
|
2523
|
+
let offset = 0;
|
|
2524
|
+
for (const part of this.#pending) {
|
|
2525
|
+
line.set(part, offset);
|
|
2526
|
+
offset += part.byteLength;
|
|
2527
|
+
}
|
|
2528
|
+
line.set(tail, offset);
|
|
2529
|
+
this.#pending = [];
|
|
2530
|
+
return line;
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
function ndJsonStream(output, input) {
|
|
2534
|
+
const textEncoder = new TextEncoder();
|
|
2535
|
+
const textDecoder = new TextDecoder();
|
|
2536
|
+
let cancelled = false;
|
|
2537
|
+
let inputReader;
|
|
2538
|
+
const readable = new ReadableStream({
|
|
2539
|
+
async start(controller) {
|
|
2540
|
+
const lines = new LineBuffer();
|
|
2541
|
+
const enqueueLine = (lineBytes) => {
|
|
2542
|
+
const trimmedLine = textDecoder.decode(lineBytes).trim();
|
|
2543
|
+
if (trimmedLine) {
|
|
2544
|
+
try {
|
|
2545
|
+
const message = JSON.parse(trimmedLine);
|
|
2546
|
+
if (isRecord(message)) {
|
|
2547
|
+
controller.enqueue(message);
|
|
2548
|
+
} else {
|
|
2549
|
+
console.warn("Skipping JSON line that is not an object:", trimmedLine);
|
|
2550
|
+
}
|
|
2551
|
+
} catch (err) {
|
|
2552
|
+
console.error("Failed to parse JSON message:", trimmedLine, err);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
};
|
|
2556
|
+
const reader = input.getReader();
|
|
2557
|
+
inputReader = reader;
|
|
2558
|
+
try {
|
|
2559
|
+
while (true) {
|
|
2560
|
+
const { value, done } = await reader.read();
|
|
2561
|
+
if (cancelled) {
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2564
|
+
if (done) {
|
|
2565
|
+
break;
|
|
2566
|
+
}
|
|
2567
|
+
if (!value) {
|
|
2568
|
+
continue;
|
|
2569
|
+
}
|
|
2570
|
+
for (const line of lines.push(value)) {
|
|
2571
|
+
enqueueLine(line);
|
|
2572
|
+
if (cancelled) {
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
if (cancelled) {
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
const lastLine = lines.flush();
|
|
2581
|
+
if (lastLine) {
|
|
2582
|
+
enqueueLine(lastLine);
|
|
2583
|
+
}
|
|
2584
|
+
} catch (err) {
|
|
2585
|
+
if (cancelled) {
|
|
2586
|
+
return;
|
|
2587
|
+
}
|
|
2588
|
+
controller.error(err);
|
|
2589
|
+
return;
|
|
2590
|
+
} finally {
|
|
2591
|
+
if (inputReader === reader) {
|
|
2592
|
+
inputReader = void 0;
|
|
2593
|
+
}
|
|
2594
|
+
reader.releaseLock();
|
|
2595
|
+
}
|
|
2596
|
+
if (cancelled) {
|
|
2597
|
+
return;
|
|
2598
|
+
}
|
|
2599
|
+
controller.close();
|
|
2600
|
+
},
|
|
2601
|
+
cancel(reason) {
|
|
2602
|
+
cancelled = true;
|
|
2603
|
+
return inputReader?.cancel(reason);
|
|
2604
|
+
}
|
|
2605
|
+
});
|
|
2606
|
+
const writable = new WritableStream({
|
|
2607
|
+
async write(message) {
|
|
2608
|
+
const content = JSON.stringify(message) + "\n";
|
|
2609
|
+
const writer = output.getWriter();
|
|
2610
|
+
try {
|
|
2611
|
+
await writer.write(textEncoder.encode(content));
|
|
2612
|
+
} finally {
|
|
2613
|
+
writer.releaseLock();
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
});
|
|
2617
|
+
return { readable, writable };
|
|
2618
|
+
}
|
|
2619
|
+
function emptyObjectResponse(response) {
|
|
2620
|
+
return response ?? {};
|
|
2621
|
+
}
|
|
2622
|
+
function isStream(value) {
|
|
2623
|
+
return typeof value === "object" && value !== null && "readable" in value && "writable" in value;
|
|
2624
|
+
}
|
|
2625
|
+
function memoryStreamPair() {
|
|
2626
|
+
const leftToRight = new TransformStream();
|
|
2627
|
+
const rightToLeft = new TransformStream();
|
|
2628
|
+
return [
|
|
2629
|
+
{
|
|
2630
|
+
readable: rightToLeft.readable,
|
|
2631
|
+
writable: leftToRight.writable
|
|
2632
|
+
},
|
|
2633
|
+
{
|
|
2634
|
+
readable: leftToRight.readable,
|
|
2635
|
+
writable: rightToLeft.writable
|
|
2636
|
+
}
|
|
2637
|
+
];
|
|
2638
|
+
}
|
|
2639
|
+
const methods = {
|
|
2640
|
+
agent: {
|
|
2641
|
+
initialize: AGENT_METHODS.initialize,
|
|
2642
|
+
authenticate: AGENT_METHODS.authenticate,
|
|
2643
|
+
logout: AGENT_METHODS.logout,
|
|
2644
|
+
providers: {
|
|
2645
|
+
list: AGENT_METHODS.providers_list,
|
|
2646
|
+
set: AGENT_METHODS.providers_set,
|
|
2647
|
+
disable: AGENT_METHODS.providers_disable
|
|
2648
|
+
},
|
|
2649
|
+
session: {
|
|
2650
|
+
new: AGENT_METHODS.session_new,
|
|
2651
|
+
load: AGENT_METHODS.session_load,
|
|
2652
|
+
list: AGENT_METHODS.session_list,
|
|
2653
|
+
delete: AGENT_METHODS.session_delete,
|
|
2654
|
+
fork: AGENT_METHODS.session_fork,
|
|
2655
|
+
resume: AGENT_METHODS.session_resume,
|
|
2656
|
+
close: AGENT_METHODS.session_close,
|
|
2657
|
+
setMode: AGENT_METHODS.session_set_mode,
|
|
2658
|
+
setConfigOption: AGENT_METHODS.session_set_config_option,
|
|
2659
|
+
prompt: AGENT_METHODS.session_prompt,
|
|
2660
|
+
cancel: AGENT_METHODS.session_cancel
|
|
2661
|
+
}
|
|
2662
|
+
},
|
|
2663
|
+
client: {
|
|
2664
|
+
session: {
|
|
2665
|
+
requestPermission: CLIENT_METHODS.session_request_permission,
|
|
2666
|
+
update: CLIENT_METHODS.session_update
|
|
2667
|
+
},
|
|
2668
|
+
fs: {
|
|
2669
|
+
writeTextFile: CLIENT_METHODS.fs_write_text_file,
|
|
2670
|
+
readTextFile: CLIENT_METHODS.fs_read_text_file
|
|
2671
|
+
},
|
|
2672
|
+
elicitation: {
|
|
2673
|
+
create: CLIENT_METHODS.elicitation_create,
|
|
2674
|
+
complete: CLIENT_METHODS.elicitation_complete
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
};
|
|
2678
|
+
const startActiveSession = Symbol("startActiveSession");
|
|
2679
|
+
class AcpContext {
|
|
2680
|
+
cx;
|
|
2681
|
+
currentRequestId;
|
|
2682
|
+
/** @internal */
|
|
2683
|
+
constructor(cx, currentRequestId) {
|
|
2684
|
+
this.cx = cx;
|
|
2685
|
+
this.currentRequestId = currentRequestId;
|
|
2686
|
+
}
|
|
2687
|
+
/**
|
|
2688
|
+
* JSON-RPC id of the request currently being handled.
|
|
2689
|
+
*
|
|
2690
|
+
* This is `undefined` for notification handlers and for contexts created
|
|
2691
|
+
* outside an inbound request, such as `connect(...)` and `connectWith(...)`.
|
|
2692
|
+
*/
|
|
2693
|
+
get requestId() {
|
|
2694
|
+
return this.currentRequestId;
|
|
2695
|
+
}
|
|
2696
|
+
/** @internal */
|
|
2697
|
+
get connectionContext() {
|
|
2698
|
+
return this.cx;
|
|
2699
|
+
}
|
|
2700
|
+
/** @internal */
|
|
2701
|
+
sendRequest(method, params, mapResponse, options) {
|
|
2702
|
+
return this.cx.sendRequest(method, params, mapResponse, options);
|
|
2703
|
+
}
|
|
2704
|
+
/** @internal */
|
|
2705
|
+
sendNotification(method, params) {
|
|
2706
|
+
return this.cx.sendNotification(method, params);
|
|
2707
|
+
}
|
|
2708
|
+
/** @internal */
|
|
2709
|
+
addDynamicHandler(handler) {
|
|
2710
|
+
return this.cx.addDynamicHandler(handler);
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
class AgentContext extends AcpContext {
|
|
2714
|
+
constructor(cx, requestId) {
|
|
2715
|
+
super(cx, requestId);
|
|
2716
|
+
}
|
|
2717
|
+
/** @internal */
|
|
2718
|
+
static create(cx, requestId) {
|
|
2719
|
+
return new AgentContext(cx, requestId);
|
|
2720
|
+
}
|
|
2721
|
+
request(method, params, options) {
|
|
2722
|
+
const spec = clientRequestSpecsByMethod[method];
|
|
2723
|
+
return this.sendRequest(method, params, spec?.mapResponse, options);
|
|
2724
|
+
}
|
|
2725
|
+
notify(method, params) {
|
|
2726
|
+
return this.sendNotification(method, params);
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
class ClientContext extends AcpContext {
|
|
2730
|
+
constructor(cx, requestId) {
|
|
2731
|
+
super(cx, requestId);
|
|
2732
|
+
}
|
|
2733
|
+
/** @internal */
|
|
2734
|
+
static create(cx, requestId) {
|
|
2735
|
+
return new ClientContext(cx, requestId);
|
|
2736
|
+
}
|
|
2737
|
+
/** @internal */
|
|
2738
|
+
[startActiveSession](params, options) {
|
|
2739
|
+
return this.sendRequest(AGENT_METHODS.session_new, params, (response) => this.attachSession(response), options);
|
|
2740
|
+
}
|
|
2741
|
+
buildSession(cwdOrRequest) {
|
|
2742
|
+
if (typeof cwdOrRequest === "string") {
|
|
2743
|
+
return SessionBuilder.create(this, {
|
|
2744
|
+
cwd: cwdOrRequest,
|
|
2745
|
+
mcpServers: []
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
return SessionBuilder.create(this, cwdOrRequest);
|
|
2749
|
+
}
|
|
2750
|
+
/**
|
|
2751
|
+
* Builds active-session helpers around a `session/new` response.
|
|
2752
|
+
*/
|
|
2753
|
+
attachSession(response) {
|
|
2754
|
+
const updates = new AsyncQueue();
|
|
2755
|
+
const closeSignal = this.connectionContext.signal;
|
|
2756
|
+
const failUpdatesOnClose = () => {
|
|
2757
|
+
updates.fail(closeSignal.reason ?? new Error("ACP connection closed"));
|
|
2758
|
+
};
|
|
2759
|
+
if (closeSignal.aborted) {
|
|
2760
|
+
failUpdatesOnClose();
|
|
2761
|
+
} else {
|
|
2762
|
+
closeSignal.addEventListener("abort", failUpdatesOnClose);
|
|
2763
|
+
}
|
|
2764
|
+
const sessionRegistration = sessionUpdateRouter(this.connectionContext).attach(response, updates);
|
|
2765
|
+
const closeRegistration = new HandlerRegistration(() => {
|
|
2766
|
+
closeSignal.removeEventListener("abort", failUpdatesOnClose);
|
|
2767
|
+
});
|
|
2768
|
+
return ActiveSession.create(this, response, updates, [
|
|
2769
|
+
sessionRegistration,
|
|
2770
|
+
closeRegistration
|
|
2771
|
+
]);
|
|
2772
|
+
}
|
|
2773
|
+
request(method, params, options) {
|
|
2774
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
2775
|
+
return this.sendRequest(method, params, spec?.mapResponse, options);
|
|
2776
|
+
}
|
|
2777
|
+
notify(method, params) {
|
|
2778
|
+
return this.sendNotification(method, params);
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
class AcpConnectionHandle {
|
|
2782
|
+
connection;
|
|
2783
|
+
constructor(connection) {
|
|
2784
|
+
this.connection = connection;
|
|
2785
|
+
}
|
|
2786
|
+
get signal() {
|
|
2787
|
+
return this.connection.signal;
|
|
2788
|
+
}
|
|
2789
|
+
get closed() {
|
|
2790
|
+
return this.connection.closed;
|
|
2791
|
+
}
|
|
2792
|
+
close(error) {
|
|
2793
|
+
this.connection.close(error);
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
class AgentConnectionHandle extends AcpConnectionHandle {
|
|
2797
|
+
connectHandlers;
|
|
2798
|
+
client;
|
|
2799
|
+
didStartConnectHandlers = false;
|
|
2800
|
+
constructor(connection, connectHandlers = []) {
|
|
2801
|
+
super(connection);
|
|
2802
|
+
this.connectHandlers = connectHandlers;
|
|
2803
|
+
this.client = AgentContext.create(connection.getContext());
|
|
2804
|
+
}
|
|
2805
|
+
/** @internal */
|
|
2806
|
+
startConnectHandlers() {
|
|
2807
|
+
if (this.didStartConnectHandlers) {
|
|
2808
|
+
return;
|
|
2809
|
+
}
|
|
2810
|
+
this.didStartConnectHandlers = true;
|
|
2811
|
+
runConnectHandlers(this, this.connectHandlers);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
class ClientConnectionHandle extends AcpConnectionHandle {
|
|
2815
|
+
connectHandlers;
|
|
2816
|
+
agent;
|
|
2817
|
+
didStartConnectHandlers = false;
|
|
2818
|
+
constructor(connection, connectHandlers = []) {
|
|
2819
|
+
super(connection);
|
|
2820
|
+
this.connectHandlers = connectHandlers;
|
|
2821
|
+
this.agent = ClientContext.create(connection.getContext());
|
|
2822
|
+
}
|
|
2823
|
+
/** @internal */
|
|
2824
|
+
startConnectHandlers() {
|
|
2825
|
+
if (this.didStartConnectHandlers) {
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2828
|
+
this.didStartConnectHandlers = true;
|
|
2829
|
+
runConnectHandlers(this, this.connectHandlers);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
function agentConnection(connection, connectHandlers = []) {
|
|
2833
|
+
return new AgentConnectionHandle(connection, connectHandlers);
|
|
2834
|
+
}
|
|
2835
|
+
function clientConnection(connection, connectHandlers = []) {
|
|
2836
|
+
return new ClientConnectionHandle(connection, connectHandlers);
|
|
2837
|
+
}
|
|
2838
|
+
class AsyncQueue {
|
|
2839
|
+
values = [];
|
|
2840
|
+
waiters = [];
|
|
2841
|
+
failed = false;
|
|
2842
|
+
failure;
|
|
2843
|
+
enqueue(value) {
|
|
2844
|
+
if (this.failed) {
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
const waiter = this.waiters.shift();
|
|
2848
|
+
if (waiter) {
|
|
2849
|
+
waiter.resolve(value);
|
|
2850
|
+
} else {
|
|
2851
|
+
this.values.push({ kind: "value", value });
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
reject(error) {
|
|
2855
|
+
if (this.failed) {
|
|
2856
|
+
return;
|
|
2857
|
+
}
|
|
2858
|
+
if (this.waiters.length > 0) {
|
|
2859
|
+
for (const waiter of this.waiters.splice(0)) {
|
|
2860
|
+
waiter.reject(error);
|
|
2861
|
+
}
|
|
2862
|
+
return;
|
|
2863
|
+
}
|
|
2864
|
+
this.values.push({ kind: "error", error });
|
|
2865
|
+
}
|
|
2866
|
+
clearErrors() {
|
|
2867
|
+
this.values = this.values.filter((entry) => entry.kind === "value");
|
|
2868
|
+
}
|
|
2869
|
+
fail(error) {
|
|
2870
|
+
if (this.failed) {
|
|
2871
|
+
return;
|
|
2872
|
+
}
|
|
2873
|
+
this.failed = true;
|
|
2874
|
+
this.failure = error;
|
|
2875
|
+
for (const waiter of this.waiters.splice(0)) {
|
|
2876
|
+
waiter.reject(error);
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
next() {
|
|
2880
|
+
if (this.values.length > 0) {
|
|
2881
|
+
const entry = this.values.shift();
|
|
2882
|
+
if (entry.kind === "error") {
|
|
2883
|
+
return Promise.reject(entry.error);
|
|
2884
|
+
}
|
|
2885
|
+
return Promise.resolve(entry.value);
|
|
2886
|
+
}
|
|
2887
|
+
if (this.failed) {
|
|
2888
|
+
return Promise.reject(this.failure);
|
|
2889
|
+
}
|
|
2890
|
+
return new Promise((resolve, reject) => {
|
|
2891
|
+
this.waiters.push({ resolve, reject });
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
function cloneNewSessionRequest(request) {
|
|
2896
|
+
return {
|
|
2897
|
+
...request,
|
|
2898
|
+
additionalDirectories: request.additionalDirectories ? [...request.additionalDirectories] : void 0,
|
|
2899
|
+
mcpServers: [...request.mcpServers]
|
|
2900
|
+
};
|
|
2901
|
+
}
|
|
2902
|
+
class SessionBuilder {
|
|
2903
|
+
cx;
|
|
2904
|
+
request;
|
|
2905
|
+
constructor(cx, request) {
|
|
2906
|
+
this.cx = cx;
|
|
2907
|
+
this.request = cloneNewSessionRequest(request);
|
|
2908
|
+
}
|
|
2909
|
+
/** @internal */
|
|
2910
|
+
static create(cx, request) {
|
|
2911
|
+
return new SessionBuilder(cx, request);
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Returns the `session/new` request that will be sent.
|
|
2915
|
+
*
|
|
2916
|
+
* The returned object is a defensive copy, so mutating it does not change the
|
|
2917
|
+
* builder.
|
|
2918
|
+
*/
|
|
2919
|
+
toRequest() {
|
|
2920
|
+
return cloneNewSessionRequest(this.request);
|
|
2921
|
+
}
|
|
2922
|
+
/**
|
|
2923
|
+
* Replaces the additional workspace roots for this session.
|
|
2924
|
+
*
|
|
2925
|
+
* `additionalDirectories` expand the session's file-system scope without
|
|
2926
|
+
* changing `cwd`. Each path should be absolute.
|
|
2927
|
+
*/
|
|
2928
|
+
withAdditionalDirectories(additionalDirectories) {
|
|
2929
|
+
this.request = {
|
|
2930
|
+
...this.request,
|
|
2931
|
+
additionalDirectories: [...additionalDirectories]
|
|
2932
|
+
};
|
|
2933
|
+
return this;
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* Adds one MCP server to the `session/new` request.
|
|
2937
|
+
*/
|
|
2938
|
+
withMcpServer(mcpServer) {
|
|
2939
|
+
this.request = {
|
|
2940
|
+
...this.request,
|
|
2941
|
+
mcpServers: [...this.request.mcpServers, mcpServer]
|
|
2942
|
+
};
|
|
2943
|
+
return this;
|
|
2944
|
+
}
|
|
2945
|
+
/**
|
|
2946
|
+
* Starts the session and returns an `ActiveSession` for prompting and reading
|
|
2947
|
+
* updates.
|
|
2948
|
+
*
|
|
2949
|
+
* Call `dispose()` on the returned session when you no longer need update
|
|
2950
|
+
* routing, or use `withSession(...)` to scope disposal automatically.
|
|
2951
|
+
*/
|
|
2952
|
+
async start(options) {
|
|
2953
|
+
return this.cx[startActiveSession](this.toRequest(), options);
|
|
2954
|
+
}
|
|
2955
|
+
/**
|
|
2956
|
+
* Starts the session, runs `op`, and disposes the active-session update
|
|
2957
|
+
* routing when `op` finishes or throws.
|
|
2958
|
+
*/
|
|
2959
|
+
async withSession(op) {
|
|
2960
|
+
const session = await this.start();
|
|
2961
|
+
try {
|
|
2962
|
+
return await op(session);
|
|
2963
|
+
} finally {
|
|
2964
|
+
session.dispose();
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
class ActiveSession {
|
|
2969
|
+
cx;
|
|
2970
|
+
sessionResponse;
|
|
2971
|
+
updates;
|
|
2972
|
+
registrations;
|
|
2973
|
+
constructor(cx, sessionResponse, updates, registrations) {
|
|
2974
|
+
this.cx = cx;
|
|
2975
|
+
this.sessionResponse = sessionResponse;
|
|
2976
|
+
this.updates = updates;
|
|
2977
|
+
this.registrations = registrations;
|
|
2978
|
+
}
|
|
2979
|
+
/** @internal */
|
|
2980
|
+
static create(cx, sessionResponse, updates, registrations) {
|
|
2981
|
+
return new ActiveSession(cx, sessionResponse, updates, registrations);
|
|
2982
|
+
}
|
|
2983
|
+
/**
|
|
2984
|
+
* Session ID returned by `session/new`.
|
|
2985
|
+
*/
|
|
2986
|
+
get sessionId() {
|
|
2987
|
+
return this.sessionResponse.sessionId;
|
|
2988
|
+
}
|
|
2989
|
+
/**
|
|
2990
|
+
* Mode state returned when the session was created, if the agent provided it.
|
|
2991
|
+
*/
|
|
2992
|
+
get modes() {
|
|
2993
|
+
return this.sessionResponse.modes;
|
|
2994
|
+
}
|
|
2995
|
+
/**
|
|
2996
|
+
* Metadata returned when the session was created.
|
|
2997
|
+
*/
|
|
2998
|
+
get meta() {
|
|
2999
|
+
return this.sessionResponse._meta;
|
|
3000
|
+
}
|
|
3001
|
+
/**
|
|
3002
|
+
* Full response returned by `session/new`.
|
|
3003
|
+
*/
|
|
3004
|
+
get newSessionResponse() {
|
|
3005
|
+
return this.sessionResponse;
|
|
3006
|
+
}
|
|
3007
|
+
/**
|
|
3008
|
+
* Sends a prompt to this session.
|
|
3009
|
+
*
|
|
3010
|
+
* Strings are converted to one text content block. A single content block is
|
|
3011
|
+
* wrapped in an array. The returned promise resolves with the final
|
|
3012
|
+
* `PromptResponse`, and the same completion is also queued as a `stop`
|
|
3013
|
+
* message for `nextUpdate()`.
|
|
3014
|
+
*/
|
|
3015
|
+
prompt(prompt, options) {
|
|
3016
|
+
this.updates.clearErrors();
|
|
3017
|
+
const response = this.cx.request(AGENT_METHODS.session_prompt, {
|
|
3018
|
+
sessionId: this.sessionId,
|
|
3019
|
+
prompt: this.promptBlocks(prompt)
|
|
3020
|
+
}, options);
|
|
3021
|
+
void response.then((value) => {
|
|
3022
|
+
this.updates.enqueue({
|
|
3023
|
+
kind: "stop",
|
|
3024
|
+
response: value,
|
|
3025
|
+
stopReason: value.stopReason
|
|
3026
|
+
});
|
|
3027
|
+
}, (error) => {
|
|
3028
|
+
this.updates.reject(error);
|
|
3029
|
+
});
|
|
3030
|
+
return response;
|
|
3031
|
+
}
|
|
3032
|
+
/**
|
|
3033
|
+
* Reads the next update or stop message for this session.
|
|
3034
|
+
*/
|
|
3035
|
+
nextUpdate() {
|
|
3036
|
+
return this.updates.next();
|
|
3037
|
+
}
|
|
3038
|
+
/**
|
|
3039
|
+
* Reads text chunks until the current prompt turn stops.
|
|
3040
|
+
*
|
|
3041
|
+
* Only `agent_message_chunk` updates with text content are appended. Other
|
|
3042
|
+
* update types are ignored by this helper; use `nextUpdate()` when you need
|
|
3043
|
+
* tool calls, plans, or the final `PromptResponse`.
|
|
3044
|
+
*/
|
|
3045
|
+
async readText() {
|
|
3046
|
+
let output = "";
|
|
3047
|
+
for (; ; ) {
|
|
3048
|
+
const message = await this.nextUpdate();
|
|
3049
|
+
if (message.kind === "stop") {
|
|
3050
|
+
return output;
|
|
3051
|
+
}
|
|
3052
|
+
const { update } = message;
|
|
3053
|
+
if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
3054
|
+
output += update.content.text;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
/**
|
|
3059
|
+
* Stops routing updates to this active-session helper.
|
|
3060
|
+
*
|
|
3061
|
+
* This does not close the ACP session on the agent. Use `ClientContext`
|
|
3062
|
+
* session lifecycle methods when the protocol session itself should be closed
|
|
3063
|
+
* or deleted.
|
|
3064
|
+
*/
|
|
3065
|
+
dispose() {
|
|
3066
|
+
for (const registration of this.registrations.splice(0)) {
|
|
3067
|
+
registration.dispose();
|
|
3068
|
+
}
|
|
3069
|
+
this.updates.fail(new Error("Active session disposed"));
|
|
3070
|
+
}
|
|
3071
|
+
/**
|
|
3072
|
+
* Supports explicit resource management with `using`.
|
|
3073
|
+
*/
|
|
3074
|
+
[Symbol.dispose]() {
|
|
3075
|
+
this.dispose();
|
|
3076
|
+
}
|
|
3077
|
+
promptBlocks(prompt) {
|
|
3078
|
+
if (typeof prompt === "string") {
|
|
3079
|
+
return [{ type: "text", text: prompt }];
|
|
3080
|
+
}
|
|
3081
|
+
if (Array.isArray(prompt)) {
|
|
3082
|
+
return prompt;
|
|
3083
|
+
}
|
|
3084
|
+
return [prompt];
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
function parseParams(parser, params) {
|
|
3088
|
+
if (!parser) {
|
|
3089
|
+
return params;
|
|
3090
|
+
}
|
|
3091
|
+
if (typeof parser === "function") {
|
|
3092
|
+
return parser(params);
|
|
3093
|
+
}
|
|
3094
|
+
return parser.parse(params);
|
|
3095
|
+
}
|
|
3096
|
+
function requestSpec(method, params, mapResponse) {
|
|
3097
|
+
return { method, params, mapResponse };
|
|
3098
|
+
}
|
|
3099
|
+
function notificationSpec(method, params) {
|
|
3100
|
+
return { method, params };
|
|
3101
|
+
}
|
|
3102
|
+
function registerAppRequest(builder, spec, context, handler) {
|
|
3103
|
+
builder.onReceiveRequest(spec.method, (params) => parseParams(spec.params, params), async (params, responder, cx) => {
|
|
3104
|
+
const response = await handler(context(params, cx, responder.signal, responder.id));
|
|
3105
|
+
await responder.respond(spec.mapResponse ? spec.mapResponse(response) : response);
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
function registerAppNotification(builder, spec, context, handler) {
|
|
3109
|
+
builder.onReceiveNotification(spec.method, (params) => parseParams(spec.params, params), (params, cx) => handler(context(params, cx, cx.signal)));
|
|
3110
|
+
}
|
|
3111
|
+
function specsByMethod(specs) {
|
|
3112
|
+
const byMethod = {};
|
|
3113
|
+
for (const spec of Object.values(specs)) {
|
|
3114
|
+
byMethod[spec.method] = spec;
|
|
3115
|
+
}
|
|
3116
|
+
return byMethod;
|
|
3117
|
+
}
|
|
3118
|
+
const agentRequestSpecs = {
|
|
3119
|
+
initialize: requestSpec(AGENT_METHODS.initialize, zInitializeRequest),
|
|
3120
|
+
newSession: requestSpec(AGENT_METHODS.session_new, zNewSessionRequest),
|
|
3121
|
+
loadSession: requestSpec(AGENT_METHODS.session_load, zLoadSessionRequest, emptyObjectResponse),
|
|
3122
|
+
unstable_forkSession: requestSpec(AGENT_METHODS.session_fork, zForkSessionRequest),
|
|
3123
|
+
listSessions: requestSpec(AGENT_METHODS.session_list, zListSessionsRequest),
|
|
3124
|
+
deleteSession: requestSpec(AGENT_METHODS.session_delete, zDeleteSessionRequest, emptyObjectResponse),
|
|
3125
|
+
resumeSession: requestSpec(AGENT_METHODS.session_resume, zResumeSessionRequest),
|
|
3126
|
+
closeSession: requestSpec(AGENT_METHODS.session_close, zCloseSessionRequest, emptyObjectResponse),
|
|
3127
|
+
setSessionMode: requestSpec(AGENT_METHODS.session_set_mode, zSetSessionModeRequest, emptyObjectResponse),
|
|
3128
|
+
setSessionConfigOption: requestSpec(AGENT_METHODS.session_set_config_option, zSetSessionConfigOptionRequest),
|
|
3129
|
+
authenticate: requestSpec(AGENT_METHODS.authenticate, zAuthenticateRequest, emptyObjectResponse),
|
|
3130
|
+
unstable_listProviders: requestSpec(AGENT_METHODS.providers_list, zListProvidersRequest),
|
|
3131
|
+
unstable_setProvider: requestSpec(AGENT_METHODS.providers_set, zSetProviderRequest, emptyObjectResponse),
|
|
3132
|
+
unstable_disableProvider: requestSpec(AGENT_METHODS.providers_disable, zDisableProviderRequest, emptyObjectResponse),
|
|
3133
|
+
logout: requestSpec(AGENT_METHODS.logout, zLogoutRequest, emptyObjectResponse),
|
|
3134
|
+
prompt: requestSpec(AGENT_METHODS.session_prompt, zPromptRequest),
|
|
3135
|
+
unstable_startNes: requestSpec(AGENT_METHODS.nes_start, zStartNesRequest),
|
|
3136
|
+
unstable_suggestNes: requestSpec(AGENT_METHODS.nes_suggest, zSuggestNesRequest),
|
|
3137
|
+
unstable_closeNes: requestSpec(AGENT_METHODS.nes_close, zCloseNesRequest, emptyObjectResponse)
|
|
3138
|
+
};
|
|
3139
|
+
const agentNotificationSpecs = {
|
|
3140
|
+
cancel: notificationSpec(AGENT_METHODS.session_cancel, zCancelNotification),
|
|
3141
|
+
unstable_didOpenDocument: notificationSpec(AGENT_METHODS.document_did_open, zDidOpenDocumentNotification),
|
|
3142
|
+
unstable_didChangeDocument: notificationSpec(AGENT_METHODS.document_did_change, zDidChangeDocumentNotification),
|
|
3143
|
+
unstable_didCloseDocument: notificationSpec(AGENT_METHODS.document_did_close, zDidCloseDocumentNotification),
|
|
3144
|
+
unstable_didSaveDocument: notificationSpec(AGENT_METHODS.document_did_save, zDidSaveDocumentNotification),
|
|
3145
|
+
unstable_didFocusDocument: notificationSpec(AGENT_METHODS.document_did_focus, zDidFocusDocumentNotification),
|
|
3146
|
+
unstable_acceptNes: notificationSpec(AGENT_METHODS.nes_accept, zAcceptNesNotification),
|
|
3147
|
+
unstable_rejectNes: notificationSpec(AGENT_METHODS.nes_reject, zRejectNesNotification)
|
|
3148
|
+
};
|
|
3149
|
+
const clientRequestSpecs = {
|
|
3150
|
+
requestPermission: requestSpec(CLIENT_METHODS.session_request_permission, zRequestPermissionRequest),
|
|
3151
|
+
writeTextFile: requestSpec(CLIENT_METHODS.fs_write_text_file, zWriteTextFileRequest, emptyObjectResponse),
|
|
3152
|
+
readTextFile: requestSpec(CLIENT_METHODS.fs_read_text_file, zReadTextFileRequest),
|
|
3153
|
+
createTerminal: requestSpec(CLIENT_METHODS.terminal_create, zCreateTerminalRequest),
|
|
3154
|
+
terminalOutput: requestSpec(CLIENT_METHODS.terminal_output, zTerminalOutputRequest),
|
|
3155
|
+
releaseTerminal: requestSpec(CLIENT_METHODS.terminal_release, zReleaseTerminalRequest, emptyObjectResponse),
|
|
3156
|
+
waitForTerminalExit: requestSpec(CLIENT_METHODS.terminal_wait_for_exit, zWaitForTerminalExitRequest),
|
|
3157
|
+
killTerminal: requestSpec(CLIENT_METHODS.terminal_kill, zKillTerminalRequest, emptyObjectResponse),
|
|
3158
|
+
unstable_createElicitation: requestSpec(CLIENT_METHODS.elicitation_create, zCreateElicitationRequest)
|
|
3159
|
+
};
|
|
3160
|
+
const clientNotificationSpecs = {
|
|
3161
|
+
sessionUpdate: notificationSpec(CLIENT_METHODS.session_update, zSessionNotification),
|
|
3162
|
+
unstable_completeElicitation: notificationSpec(CLIENT_METHODS.elicitation_complete, zCompleteElicitationNotification)
|
|
3163
|
+
};
|
|
3164
|
+
const agentRequestSpecsByMethod = specsByMethod(agentRequestSpecs);
|
|
3165
|
+
const agentNotificationSpecsByMethod = specsByMethod(agentNotificationSpecs);
|
|
3166
|
+
const clientRequestSpecsByMethod = specsByMethod(clientRequestSpecs);
|
|
3167
|
+
const clientNotificationSpecsByMethod = specsByMethod(clientNotificationSpecs);
|
|
3168
|
+
function agentRequestContext(params, client2, signal, requestId) {
|
|
3169
|
+
return {
|
|
3170
|
+
params,
|
|
3171
|
+
requestId,
|
|
3172
|
+
signal,
|
|
3173
|
+
client: client2
|
|
3174
|
+
};
|
|
3175
|
+
}
|
|
3176
|
+
function agentNotificationContext(params, client2, signal) {
|
|
3177
|
+
return {
|
|
3178
|
+
params,
|
|
3179
|
+
signal,
|
|
3180
|
+
client: client2
|
|
3181
|
+
};
|
|
3182
|
+
}
|
|
3183
|
+
function clientRequestContext(params, agent2, signal, requestId) {
|
|
3184
|
+
return {
|
|
3185
|
+
params,
|
|
3186
|
+
requestId,
|
|
3187
|
+
signal,
|
|
3188
|
+
agent: agent2
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
function clientNotificationContext(params, agent2, signal) {
|
|
3192
|
+
return {
|
|
3193
|
+
params,
|
|
3194
|
+
signal,
|
|
3195
|
+
agent: agent2
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
class SessionUpdateRouter {
|
|
3199
|
+
activeSessions = /* @__PURE__ */ new Map();
|
|
3200
|
+
handleMessage(message) {
|
|
3201
|
+
if (message.kind !== "notification" || message.method !== CLIENT_METHODS.session_update) {
|
|
3202
|
+
return Handled.no(message);
|
|
3203
|
+
}
|
|
3204
|
+
const notification = zSessionNotification.parse(message.params);
|
|
3205
|
+
const update = {
|
|
3206
|
+
kind: "session_update",
|
|
3207
|
+
notification,
|
|
3208
|
+
update: notification.update
|
|
3209
|
+
};
|
|
3210
|
+
const activeSessions = this.activeSessions.get(notification.sessionId);
|
|
3211
|
+
if (activeSessions && activeSessions.size > 0) {
|
|
3212
|
+
for (const session of activeSessions) {
|
|
3213
|
+
session.enqueue(update);
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
return Handled.no(message);
|
|
3217
|
+
}
|
|
3218
|
+
attach(response, updates) {
|
|
3219
|
+
const sessions = this.activeSessions.get(response.sessionId) ?? /* @__PURE__ */ new Set();
|
|
3220
|
+
sessions.add(updates);
|
|
3221
|
+
this.activeSessions.set(response.sessionId, sessions);
|
|
3222
|
+
return new HandlerRegistration(() => {
|
|
3223
|
+
sessions.delete(updates);
|
|
3224
|
+
if (sessions.size === 0) {
|
|
3225
|
+
this.activeSessions.delete(response.sessionId);
|
|
3226
|
+
}
|
|
3227
|
+
});
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
const sessionUpdateRouters = /* @__PURE__ */ new WeakMap();
|
|
3231
|
+
function sessionUpdateRouter(cx) {
|
|
3232
|
+
let router = sessionUpdateRouters.get(cx);
|
|
3233
|
+
if (!router) {
|
|
3234
|
+
router = new SessionUpdateRouter();
|
|
3235
|
+
sessionUpdateRouters.set(cx, router);
|
|
3236
|
+
}
|
|
3237
|
+
return router;
|
|
3238
|
+
}
|
|
3239
|
+
function runConnectHandlers(connection, handlers) {
|
|
3240
|
+
for (const handler of handlers) {
|
|
3241
|
+
let result;
|
|
3242
|
+
try {
|
|
3243
|
+
result = handler(connection);
|
|
3244
|
+
} catch (error) {
|
|
3245
|
+
connection.close(error);
|
|
3246
|
+
throw error;
|
|
3247
|
+
}
|
|
3248
|
+
void Promise.resolve(result).catch((error) => {
|
|
3249
|
+
connection.close(error);
|
|
3250
|
+
});
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
const appBuilder = Symbol("appBuilder");
|
|
3254
|
+
const runAgentConnectHandlers = Symbol("runAgentConnectHandlers");
|
|
3255
|
+
const runClientConnectHandlers = Symbol("runClientConnectHandlers");
|
|
3256
|
+
function agent(options) {
|
|
3257
|
+
return new AgentApp(options);
|
|
3258
|
+
}
|
|
3259
|
+
class AgentApp {
|
|
3260
|
+
builder = Connection.builder();
|
|
3261
|
+
connectHandlers = [];
|
|
3262
|
+
constructor(options = {}) {
|
|
3263
|
+
if (options.name) {
|
|
3264
|
+
this.builder.name(options.name);
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
/** @internal */
|
|
3268
|
+
[appBuilder]() {
|
|
3269
|
+
return this.builder;
|
|
3270
|
+
}
|
|
3271
|
+
/** @internal */
|
|
3272
|
+
[runAgentConnectHandlers](connection) {
|
|
3273
|
+
runConnectHandlers(connection, this.connectHandlers);
|
|
3274
|
+
}
|
|
3275
|
+
connect(target, options = {}) {
|
|
3276
|
+
return this.connectConnection(target, options).connection;
|
|
3277
|
+
}
|
|
3278
|
+
connectWith(target, op) {
|
|
3279
|
+
const { rawConnection, connection } = this.connectConnection(target);
|
|
3280
|
+
return rawConnection.runUntil(() => op(connection.client));
|
|
3281
|
+
}
|
|
3282
|
+
/**
|
|
3283
|
+
* Registers a handler that runs when this agent app opens a connection.
|
|
3284
|
+
*
|
|
3285
|
+
* Use this for connection-scoped work that needs to call client-side ACP
|
|
3286
|
+
* methods outside an inbound request handler.
|
|
3287
|
+
*/
|
|
3288
|
+
onConnect(handler) {
|
|
3289
|
+
this.connectHandlers.push(handler);
|
|
3290
|
+
return this;
|
|
3291
|
+
}
|
|
3292
|
+
onRequest(method, handlerOrParams, handler) {
|
|
3293
|
+
if (handler) {
|
|
3294
|
+
return this.request({ method, params: handlerOrParams }, handler);
|
|
3295
|
+
}
|
|
3296
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
3297
|
+
if (!spec) {
|
|
3298
|
+
throw new Error(`Unknown ACP request method '${method}'. Pass a params parser for custom methods.`);
|
|
3299
|
+
}
|
|
3300
|
+
return this.request(spec, handlerOrParams);
|
|
3301
|
+
}
|
|
3302
|
+
onNotification(method, handlerOrParams, handler) {
|
|
3303
|
+
if (handler) {
|
|
3304
|
+
return this.notification({ method, params: handlerOrParams }, handler);
|
|
3305
|
+
}
|
|
3306
|
+
const spec = agentNotificationSpecsByMethod[method];
|
|
3307
|
+
if (!spec) {
|
|
3308
|
+
throw new Error(`Unknown ACP notification method '${method}'. Pass a params parser for custom methods.`);
|
|
3309
|
+
}
|
|
3310
|
+
return this.notification(spec, handlerOrParams);
|
|
3311
|
+
}
|
|
3312
|
+
request(spec, handler) {
|
|
3313
|
+
registerAppRequest(this.builder, spec, (params, cx, signal, requestId) => agentRequestContext(params, AgentContext.create(cx, requestId), signal, requestId), handler);
|
|
3314
|
+
return this;
|
|
3315
|
+
}
|
|
3316
|
+
notification(spec, handler) {
|
|
3317
|
+
registerAppNotification(this.builder, spec, (params, cx, signal) => agentNotificationContext(params, AgentContext.create(cx), signal), handler);
|
|
3318
|
+
return this;
|
|
3319
|
+
}
|
|
3320
|
+
connectConnection(target, options = {}) {
|
|
3321
|
+
if (isStream(target)) {
|
|
3322
|
+
const state2 = this.openStreamConnection(target);
|
|
3323
|
+
if (!options.deferConnectHandlers) {
|
|
3324
|
+
this[runAgentConnectHandlers](state2.connection);
|
|
3325
|
+
}
|
|
3326
|
+
return state2;
|
|
3327
|
+
}
|
|
3328
|
+
const [thisStream, peerStream] = memoryStreamPair();
|
|
3329
|
+
const peerRawConnection = target[appBuilder]().connect(peerStream);
|
|
3330
|
+
const peerConnection = clientConnection(peerRawConnection);
|
|
3331
|
+
const state = this.openStreamConnection(thisStream);
|
|
3332
|
+
void state.rawConnection.closed.then(() => peerConnection.close());
|
|
3333
|
+
void peerRawConnection.closed.then(() => state.connection.close());
|
|
3334
|
+
try {
|
|
3335
|
+
target[runClientConnectHandlers](peerConnection);
|
|
3336
|
+
this[runAgentConnectHandlers](state.connection);
|
|
3337
|
+
} catch (error) {
|
|
3338
|
+
peerConnection.close(error);
|
|
3339
|
+
state.connection.close(error);
|
|
3340
|
+
throw error;
|
|
3341
|
+
}
|
|
3342
|
+
return state;
|
|
3343
|
+
}
|
|
3344
|
+
openStreamConnection(stream) {
|
|
3345
|
+
const rawConnection = this.builder.connect(stream);
|
|
3346
|
+
return {
|
|
3347
|
+
rawConnection,
|
|
3348
|
+
connection: agentConnection(rawConnection, this.connectHandlers)
|
|
3349
|
+
};
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
function client(options) {
|
|
3353
|
+
return new ClientApp(options);
|
|
3354
|
+
}
|
|
3355
|
+
class ClientApp {
|
|
3356
|
+
builder = Connection.builder();
|
|
3357
|
+
connectHandlers = [];
|
|
3358
|
+
constructor(options = {}) {
|
|
3359
|
+
if (options.name) {
|
|
3360
|
+
this.builder.name(options.name);
|
|
3361
|
+
}
|
|
3362
|
+
this.builder.withHandler({
|
|
3363
|
+
handleMessage: (message, cx) => sessionUpdateRouter(cx).handleMessage(message),
|
|
3364
|
+
describe: () => "client-session-update-router"
|
|
3365
|
+
});
|
|
3366
|
+
}
|
|
3367
|
+
/** @internal */
|
|
3368
|
+
[appBuilder]() {
|
|
3369
|
+
return this.builder;
|
|
3370
|
+
}
|
|
3371
|
+
/** @internal */
|
|
3372
|
+
[runClientConnectHandlers](connection) {
|
|
3373
|
+
runConnectHandlers(connection, this.connectHandlers);
|
|
3374
|
+
}
|
|
3375
|
+
connect(target) {
|
|
3376
|
+
return this.connectConnection(target).connection;
|
|
3377
|
+
}
|
|
3378
|
+
connectWith(target, op) {
|
|
3379
|
+
const { rawConnection, connection } = this.connectConnection(target);
|
|
3380
|
+
return rawConnection.runUntil(() => op(connection.agent));
|
|
3381
|
+
}
|
|
3382
|
+
/**
|
|
3383
|
+
* Registers a handler that runs when this client app opens a connection.
|
|
3384
|
+
*
|
|
3385
|
+
* Use this for connection-scoped work that needs to call agent-side ACP
|
|
3386
|
+
* methods outside an inbound request handler.
|
|
3387
|
+
*/
|
|
3388
|
+
onConnect(handler) {
|
|
3389
|
+
this.connectHandlers.push(handler);
|
|
3390
|
+
return this;
|
|
3391
|
+
}
|
|
3392
|
+
onRequest(method, handlerOrParams, handler) {
|
|
3393
|
+
if (handler) {
|
|
3394
|
+
return this.request({ method, params: handlerOrParams }, handler);
|
|
3395
|
+
}
|
|
3396
|
+
const spec = clientRequestSpecsByMethod[method];
|
|
3397
|
+
if (!spec) {
|
|
3398
|
+
throw new Error(`Unknown ACP request method '${method}'. Pass a params parser for custom methods.`);
|
|
3399
|
+
}
|
|
3400
|
+
return this.request(spec, handlerOrParams);
|
|
3401
|
+
}
|
|
3402
|
+
onNotification(method, handlerOrParams, handler) {
|
|
3403
|
+
if (handler) {
|
|
3404
|
+
return this.notification({ method, params: handlerOrParams }, handler);
|
|
3405
|
+
}
|
|
3406
|
+
const spec = clientNotificationSpecsByMethod[method];
|
|
3407
|
+
if (!spec) {
|
|
3408
|
+
throw new Error(`Unknown ACP notification method '${method}'. Pass a params parser for custom methods.`);
|
|
3409
|
+
}
|
|
3410
|
+
return this.notification(spec, handlerOrParams);
|
|
3411
|
+
}
|
|
3412
|
+
request(spec, handler) {
|
|
3413
|
+
registerAppRequest(this.builder, spec, (params, cx, signal, requestId) => clientRequestContext(params, ClientContext.create(cx, requestId), signal, requestId), handler);
|
|
3414
|
+
return this;
|
|
3415
|
+
}
|
|
3416
|
+
notification(spec, handler) {
|
|
3417
|
+
registerAppNotification(this.builder, spec, (params, cx, signal) => clientNotificationContext(params, ClientContext.create(cx), signal), handler);
|
|
3418
|
+
return this;
|
|
3419
|
+
}
|
|
3420
|
+
connectConnection(target) {
|
|
3421
|
+
if (isStream(target)) {
|
|
3422
|
+
const state2 = this.openStreamConnection(target);
|
|
3423
|
+
this[runClientConnectHandlers](state2.connection);
|
|
3424
|
+
return state2;
|
|
3425
|
+
}
|
|
3426
|
+
const [thisStream, peerStream] = memoryStreamPair();
|
|
3427
|
+
const peerRawConnection = target[appBuilder]().connect(peerStream);
|
|
3428
|
+
const peerConnection = agentConnection(peerRawConnection);
|
|
3429
|
+
const state = this.openStreamConnection(thisStream);
|
|
3430
|
+
void state.rawConnection.closed.then(() => peerConnection.close());
|
|
3431
|
+
void peerRawConnection.closed.then(() => state.connection.close());
|
|
3432
|
+
try {
|
|
3433
|
+
target[runAgentConnectHandlers](peerConnection);
|
|
3434
|
+
this[runClientConnectHandlers](state.connection);
|
|
3435
|
+
} catch (error) {
|
|
3436
|
+
peerConnection.close(error);
|
|
3437
|
+
state.connection.close(error);
|
|
3438
|
+
throw error;
|
|
3439
|
+
}
|
|
3440
|
+
return state;
|
|
3441
|
+
}
|
|
3442
|
+
openStreamConnection(stream) {
|
|
3443
|
+
const rawConnection = this.builder.connect(stream);
|
|
3444
|
+
return {
|
|
3445
|
+
rawConnection,
|
|
3446
|
+
connection: clientConnection(rawConnection, this.connectHandlers)
|
|
3447
|
+
};
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
const legacyClientRequestMethods = /* @__PURE__ */ new Set([
|
|
3451
|
+
CLIENT_METHODS.session_request_permission,
|
|
3452
|
+
CLIENT_METHODS.fs_write_text_file,
|
|
3453
|
+
CLIENT_METHODS.fs_read_text_file,
|
|
3454
|
+
CLIENT_METHODS.terminal_create,
|
|
3455
|
+
CLIENT_METHODS.terminal_output,
|
|
3456
|
+
CLIENT_METHODS.terminal_release,
|
|
3457
|
+
CLIENT_METHODS.terminal_wait_for_exit,
|
|
3458
|
+
CLIENT_METHODS.terminal_kill,
|
|
3459
|
+
CLIENT_METHODS.elicitation_create
|
|
3460
|
+
]);
|
|
3461
|
+
const legacyClientNotificationMethods = /* @__PURE__ */ new Set([
|
|
3462
|
+
CLIENT_METHODS.session_update,
|
|
3463
|
+
CLIENT_METHODS.elicitation_complete
|
|
3464
|
+
]);
|
|
3465
|
+
function legacyClientApp(implementation) {
|
|
3466
|
+
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) ?? {});
|
|
3467
|
+
if (implementation.unstable_createElicitation) {
|
|
3468
|
+
app.onRequest(CLIENT_METHODS.elicitation_create, (ctx) => implementation.unstable_createElicitation(ctx.params));
|
|
3469
|
+
}
|
|
3470
|
+
if (implementation.unstable_completeElicitation) {
|
|
3471
|
+
app.onNotification(CLIENT_METHODS.elicitation_complete, (ctx) => implementation.unstable_completeElicitation(ctx.params));
|
|
3472
|
+
}
|
|
3473
|
+
if (implementation.extMethod) {
|
|
3474
|
+
app[appBuilder]().withHandler({
|
|
3475
|
+
handleMessage: async (message) => {
|
|
3476
|
+
if (message.kind !== "request" || legacyClientRequestMethods.has(message.method)) {
|
|
3477
|
+
return Handled.no(message);
|
|
3478
|
+
}
|
|
3479
|
+
await message.responder.respond(await implementation.extMethod(message.method, message.params));
|
|
3480
|
+
return Handled.yes();
|
|
3481
|
+
},
|
|
3482
|
+
describe: () => "legacy-client-extension-request"
|
|
3483
|
+
});
|
|
3484
|
+
}
|
|
3485
|
+
if (implementation.extNotification) {
|
|
3486
|
+
app[appBuilder]().withHandler({
|
|
3487
|
+
handleMessage: async (message) => {
|
|
3488
|
+
if (message.kind !== "notification" || legacyClientNotificationMethods.has(message.method)) {
|
|
3489
|
+
return Handled.no(message);
|
|
3490
|
+
}
|
|
3491
|
+
await implementation.extNotification(message.method, message.params);
|
|
3492
|
+
return Handled.yes();
|
|
3493
|
+
},
|
|
3494
|
+
describe: () => "legacy-client-extension-notification"
|
|
3495
|
+
});
|
|
3496
|
+
}
|
|
3497
|
+
return app;
|
|
3498
|
+
}
|
|
3499
|
+
class ClientSideConnection {
|
|
3500
|
+
connection;
|
|
3501
|
+
/**
|
|
3502
|
+
* Creates a new client-side connection to an agent.
|
|
3503
|
+
*
|
|
3504
|
+
* This establishes the communication channel between a client and agent
|
|
3505
|
+
* following the ACP specification.
|
|
3506
|
+
*
|
|
3507
|
+
* @param toClient - A function that creates a Client handler to process incoming agent requests
|
|
3508
|
+
* @param stream - The bidirectional message stream for communication. Typically created using
|
|
3509
|
+
* {@link ndJsonStream} for stdio-based connections.
|
|
3510
|
+
*
|
|
3511
|
+
* See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
|
|
3512
|
+
*
|
|
3513
|
+
* @deprecated Prefer `client({ name }).connectWith(stream, async (ctx) => ...)`.
|
|
3514
|
+
*/
|
|
3515
|
+
constructor(toClient, stream) {
|
|
3516
|
+
this.connection = legacyClientApp(toClient(this))[appBuilder]().connect(stream);
|
|
3517
|
+
}
|
|
3518
|
+
/**
|
|
3519
|
+
* Establishes the connection with a client and negotiates protocol capabilities.
|
|
3520
|
+
*
|
|
3521
|
+
* This method is called once at the beginning of the connection to:
|
|
3522
|
+
* - Negotiate the protocol version to use
|
|
3523
|
+
* - Exchange capability information between client and agent
|
|
3524
|
+
* - Determine available authentication methods
|
|
3525
|
+
*
|
|
3526
|
+
* The agent should respond with its supported protocol version and capabilities.
|
|
3527
|
+
*
|
|
3528
|
+
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
3529
|
+
*/
|
|
3530
|
+
initialize(params) {
|
|
3531
|
+
return this.connection.sendRequest(AGENT_METHODS.initialize, params);
|
|
3532
|
+
}
|
|
3533
|
+
/**
|
|
3534
|
+
* Creates a new conversation session with the agent.
|
|
3535
|
+
*
|
|
3536
|
+
* Sessions represent independent conversation contexts with their own history and state.
|
|
3537
|
+
*
|
|
3538
|
+
* The agent should:
|
|
3539
|
+
* - Create a new session context
|
|
3540
|
+
* - Connect to any specified MCP servers
|
|
3541
|
+
* - Return a unique session ID for future requests
|
|
3542
|
+
*
|
|
3543
|
+
* The request may include `additionalDirectories` to expand the session's filesystem
|
|
3544
|
+
* scope beyond `cwd` without changing the base for relative paths.
|
|
3545
|
+
*
|
|
3546
|
+
* May return an `auth_required` error if the agent requires authentication.
|
|
3547
|
+
*
|
|
3548
|
+
* See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
|
|
3549
|
+
*/
|
|
3550
|
+
newSession(params) {
|
|
3551
|
+
return this.connection.sendRequest(AGENT_METHODS.session_new, params);
|
|
3552
|
+
}
|
|
3553
|
+
/**
|
|
3554
|
+
* Loads an existing session to resume a previous conversation.
|
|
3555
|
+
*
|
|
3556
|
+
* This method is only available if the agent advertises the `loadSession` capability.
|
|
3557
|
+
*
|
|
3558
|
+
* The agent should:
|
|
3559
|
+
* - Restore the session context and conversation history
|
|
3560
|
+
* - Connect to the specified MCP servers
|
|
3561
|
+
* - Stream the entire conversation history back to the client via notifications
|
|
3562
|
+
*
|
|
3563
|
+
* The request may include `additionalDirectories` to set the complete list of
|
|
3564
|
+
* additional workspace roots for the loaded session.
|
|
3565
|
+
*
|
|
3566
|
+
* See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
|
|
3567
|
+
*/
|
|
3568
|
+
loadSession(params) {
|
|
3569
|
+
return this.connection.sendRequest(AGENT_METHODS.session_load, params, emptyObjectResponse);
|
|
3570
|
+
}
|
|
3571
|
+
/**
|
|
3572
|
+
* **UNSTABLE**
|
|
3573
|
+
*
|
|
3574
|
+
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3575
|
+
*
|
|
3576
|
+
* Forks an existing session to create a new independent session.
|
|
3577
|
+
*
|
|
3578
|
+
* Creates a new session based on the context of an existing one, allowing
|
|
3579
|
+
* operations like generating summaries without affecting the original session's history.
|
|
3580
|
+
*
|
|
3581
|
+
* The request may include `additionalDirectories` to set the complete list of
|
|
3582
|
+
* additional workspace roots for the forked session.
|
|
3583
|
+
*
|
|
3584
|
+
* This method is only available if the agent advertises the `session.fork` capability.
|
|
3585
|
+
*
|
|
3586
|
+
* @experimental
|
|
3587
|
+
*/
|
|
3588
|
+
unstable_forkSession(params) {
|
|
3589
|
+
return this.connection.sendRequest(AGENT_METHODS.session_fork, params);
|
|
3590
|
+
}
|
|
3591
|
+
/**
|
|
3592
|
+
* Lists existing sessions from the agent.
|
|
3593
|
+
*
|
|
3594
|
+
* This method is only available if the agent advertises the `listSessions` capability.
|
|
3595
|
+
*
|
|
3596
|
+
* Returns a list of sessions with metadata like session ID, working directory,
|
|
3597
|
+
* title, and last update time. Supports filtering by working directory,
|
|
3598
|
+
* `additionalDirectories`, and cursor-based pagination.
|
|
3599
|
+
*/
|
|
3600
|
+
listSessions(params) {
|
|
3601
|
+
return this.connection.sendRequest(AGENT_METHODS.session_list, params);
|
|
3602
|
+
}
|
|
3603
|
+
/**
|
|
3604
|
+
* Deletes an existing session returned by `session/list`.
|
|
3605
|
+
*
|
|
3606
|
+
* This method is only available if the agent advertises the `sessionCapabilities.delete` capability.
|
|
3607
|
+
*/
|
|
3608
|
+
deleteSession(params) {
|
|
3609
|
+
return this.connection.sendRequest(AGENT_METHODS.session_delete, params, emptyObjectResponse);
|
|
3610
|
+
}
|
|
3611
|
+
/**
|
|
3612
|
+
* Resumes an existing session without returning previous messages.
|
|
3613
|
+
*
|
|
3614
|
+
* This method is only available if the agent advertises the `session.resume` capability.
|
|
3615
|
+
*
|
|
3616
|
+
* The agent should resume the session context, allowing the conversation to continue
|
|
3617
|
+
* without replaying the message history (unlike `session/load`).
|
|
3618
|
+
*
|
|
3619
|
+
* The request may include `additionalDirectories` to set the complete list of
|
|
3620
|
+
* additional workspace roots for the resumed session.
|
|
3621
|
+
*/
|
|
3622
|
+
resumeSession(params) {
|
|
3623
|
+
return this.connection.sendRequest(AGENT_METHODS.session_resume, params);
|
|
3624
|
+
}
|
|
3625
|
+
/**
|
|
3626
|
+
* Closes an active session and frees up any resources associated with it.
|
|
3627
|
+
*
|
|
3628
|
+
* This method is only available if the agent advertises the `session.close` capability.
|
|
3629
|
+
*
|
|
3630
|
+
* The agent must cancel any ongoing work (as if `session/cancel` was called)
|
|
3631
|
+
* and then free up any resources associated with the session.
|
|
3632
|
+
*/
|
|
3633
|
+
closeSession(params) {
|
|
3634
|
+
return this.connection.sendRequest(AGENT_METHODS.session_close, params, emptyObjectResponse);
|
|
3635
|
+
}
|
|
3636
|
+
/**
|
|
3637
|
+
* Sets the operational mode for a session.
|
|
3638
|
+
*
|
|
3639
|
+
* Allows switching between different agent modes (e.g., "ask", "architect", "code")
|
|
3640
|
+
* that affect system prompts, tool availability, and permission behaviors.
|
|
3641
|
+
*
|
|
3642
|
+
* The mode must be one of the modes advertised in `availableModes` during session
|
|
3643
|
+
* creation or loading. Agents may also change modes autonomously and notify the
|
|
3644
|
+
* client via `current_mode_update` notifications.
|
|
3645
|
+
*
|
|
3646
|
+
* This method can be called at any time during a session, whether the Agent is
|
|
3647
|
+
* idle or actively generating a turn.
|
|
3648
|
+
*
|
|
3649
|
+
* See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
|
|
3650
|
+
*/
|
|
3651
|
+
setSessionMode(params) {
|
|
3652
|
+
return this.connection.sendRequest(AGENT_METHODS.session_set_mode, params, emptyObjectResponse);
|
|
3653
|
+
}
|
|
3654
|
+
/**
|
|
3655
|
+
* Set a configuration option for a given session.
|
|
3656
|
+
*
|
|
3657
|
+
* The response contains the full set of configuration options and their current values,
|
|
3658
|
+
* as changing one option may affect the available values or state of other options.
|
|
3659
|
+
*/
|
|
3660
|
+
setSessionConfigOption(params) {
|
|
3661
|
+
return this.connection.sendRequest(AGENT_METHODS.session_set_config_option, params);
|
|
3662
|
+
}
|
|
3663
|
+
/**
|
|
3664
|
+
* Authenticates the client using the specified authentication method.
|
|
3665
|
+
*
|
|
3666
|
+
* Called when the agent requires authentication before allowing session creation.
|
|
3667
|
+
* The client provides the authentication method ID that was advertised during initialization.
|
|
3668
|
+
*
|
|
3669
|
+
* After successful authentication, the client can proceed to create sessions with
|
|
3670
|
+
* `newSession` without receiving an `auth_required` error.
|
|
3671
|
+
*
|
|
3672
|
+
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
3673
|
+
*/
|
|
3674
|
+
authenticate(params) {
|
|
3675
|
+
return this.connection.sendRequest(AGENT_METHODS.authenticate, params, emptyObjectResponse);
|
|
3676
|
+
}
|
|
3677
|
+
/**
|
|
3678
|
+
* **UNSTABLE**
|
|
3679
|
+
*
|
|
3680
|
+
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3681
|
+
*
|
|
3682
|
+
* Lists providers that can be configured by the client.
|
|
3683
|
+
*
|
|
3684
|
+
* This method is only available if the agent advertises the `providers` capability.
|
|
3685
|
+
*
|
|
3686
|
+
* @experimental
|
|
3687
|
+
*/
|
|
3688
|
+
unstable_listProviders(params) {
|
|
3689
|
+
return this.connection.sendRequest(AGENT_METHODS.providers_list, params);
|
|
3690
|
+
}
|
|
3691
|
+
/**
|
|
3692
|
+
* **UNSTABLE**
|
|
3693
|
+
*
|
|
3694
|
+
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3695
|
+
*
|
|
3696
|
+
* Replaces the configuration for a provider.
|
|
3697
|
+
*
|
|
3698
|
+
* This method is only available if the agent advertises the `providers` capability.
|
|
3699
|
+
*
|
|
3700
|
+
* @experimental
|
|
3701
|
+
*/
|
|
3702
|
+
unstable_setProvider(params) {
|
|
3703
|
+
return this.connection.sendRequest(AGENT_METHODS.providers_set, params, emptyObjectResponse);
|
|
3704
|
+
}
|
|
3705
|
+
/**
|
|
3706
|
+
* **UNSTABLE**
|
|
3707
|
+
*
|
|
3708
|
+
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3709
|
+
*
|
|
3710
|
+
* Disables a provider.
|
|
3711
|
+
*
|
|
3712
|
+
* This method is only available if the agent advertises the `providers` capability.
|
|
3713
|
+
*
|
|
3714
|
+
* @experimental
|
|
3715
|
+
*/
|
|
3716
|
+
unstable_disableProvider(params) {
|
|
3717
|
+
return this.connection.sendRequest(AGENT_METHODS.providers_disable, params, emptyObjectResponse);
|
|
3718
|
+
}
|
|
3719
|
+
/**
|
|
3720
|
+
* Logout of the current authentication method.
|
|
3721
|
+
*/
|
|
3722
|
+
logout(params) {
|
|
3723
|
+
return this.connection.sendRequest(AGENT_METHODS.logout, params, emptyObjectResponse);
|
|
3724
|
+
}
|
|
3725
|
+
/**
|
|
3726
|
+
* Processes a user prompt within a session.
|
|
3727
|
+
*
|
|
3728
|
+
* This method handles the whole lifecycle of a prompt:
|
|
3729
|
+
* - Receives user messages with optional context (files, images, etc.)
|
|
3730
|
+
* - Processes the prompt using language models
|
|
3731
|
+
* - Reports language model content and tool calls to the Clients
|
|
3732
|
+
* - Requests permission to run tools
|
|
3733
|
+
* - Executes any requested tool calls
|
|
3734
|
+
* - Returns when the turn is complete with a stop reason
|
|
3735
|
+
*
|
|
3736
|
+
* See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
|
|
3737
|
+
*/
|
|
3738
|
+
prompt(params) {
|
|
3739
|
+
return this.connection.sendRequest(AGENT_METHODS.session_prompt, params);
|
|
3740
|
+
}
|
|
3741
|
+
/**
|
|
3742
|
+
* Cancels ongoing operations for a session.
|
|
3743
|
+
*
|
|
3744
|
+
* This is a notification sent by the client to cancel an ongoing prompt turn.
|
|
3745
|
+
*
|
|
3746
|
+
* Upon receiving this notification, the Agent SHOULD:
|
|
3747
|
+
* - Stop all language model requests as soon as possible
|
|
3748
|
+
* - Abort all tool call invocations in progress
|
|
3749
|
+
* - Send any pending `session/update` notifications
|
|
3750
|
+
* - Respond to the original `session/prompt` request with `StopReason::Cancelled`
|
|
3751
|
+
*
|
|
3752
|
+
* See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
|
|
3753
|
+
*/
|
|
3754
|
+
cancel(params) {
|
|
3755
|
+
return this.connection.sendNotification(AGENT_METHODS.session_cancel, params);
|
|
3756
|
+
}
|
|
3757
|
+
/**
|
|
3758
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3759
|
+
*
|
|
3760
|
+
* Starts a NES (Next Edit Suggestions) session.
|
|
3761
|
+
*
|
|
3762
|
+
* @experimental
|
|
3763
|
+
*/
|
|
3764
|
+
unstable_startNes(params) {
|
|
3765
|
+
return this.connection.sendRequest(AGENT_METHODS.nes_start, params);
|
|
3766
|
+
}
|
|
3767
|
+
/**
|
|
3768
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3769
|
+
*
|
|
3770
|
+
* Sends a NES suggestion request.
|
|
3771
|
+
*
|
|
3772
|
+
* @experimental
|
|
3773
|
+
*/
|
|
3774
|
+
unstable_suggestNes(params) {
|
|
3775
|
+
return this.connection.sendRequest(AGENT_METHODS.nes_suggest, params);
|
|
3776
|
+
}
|
|
3777
|
+
/**
|
|
3778
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3779
|
+
*
|
|
3780
|
+
* Closes a NES session.
|
|
3781
|
+
*
|
|
3782
|
+
* @experimental
|
|
3783
|
+
*/
|
|
3784
|
+
unstable_closeNes(params) {
|
|
3785
|
+
return this.connection.sendRequest(AGENT_METHODS.nes_close, params, emptyObjectResponse);
|
|
3786
|
+
}
|
|
3787
|
+
/**
|
|
3788
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3789
|
+
*
|
|
3790
|
+
* Notifies the agent that a document was opened.
|
|
3791
|
+
*
|
|
3792
|
+
* @experimental
|
|
3793
|
+
*/
|
|
3794
|
+
unstable_didOpenDocument(params) {
|
|
3795
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_open, params);
|
|
3796
|
+
}
|
|
3797
|
+
/**
|
|
3798
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3799
|
+
*
|
|
3800
|
+
* Notifies the agent that a document was changed.
|
|
3801
|
+
*
|
|
3802
|
+
* @experimental
|
|
3803
|
+
*/
|
|
3804
|
+
unstable_didChangeDocument(params) {
|
|
3805
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_change, params);
|
|
3806
|
+
}
|
|
3807
|
+
/**
|
|
3808
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3809
|
+
*
|
|
3810
|
+
* Notifies the agent that a document was closed.
|
|
3811
|
+
*
|
|
3812
|
+
* @experimental
|
|
3813
|
+
*/
|
|
3814
|
+
unstable_didCloseDocument(params) {
|
|
3815
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_close, params);
|
|
3816
|
+
}
|
|
3817
|
+
/**
|
|
3818
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3819
|
+
*
|
|
3820
|
+
* Notifies the agent that a document was saved.
|
|
3821
|
+
*
|
|
3822
|
+
* @experimental
|
|
3823
|
+
*/
|
|
3824
|
+
unstable_didSaveDocument(params) {
|
|
3825
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_save, params);
|
|
3826
|
+
}
|
|
3827
|
+
/**
|
|
3828
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3829
|
+
*
|
|
3830
|
+
* Notifies the agent that a document received focus.
|
|
3831
|
+
*
|
|
3832
|
+
* @experimental
|
|
3833
|
+
*/
|
|
3834
|
+
unstable_didFocusDocument(params) {
|
|
3835
|
+
return this.connection.sendNotification(AGENT_METHODS.document_did_focus, params);
|
|
3836
|
+
}
|
|
3837
|
+
/**
|
|
3838
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3839
|
+
*
|
|
3840
|
+
* Notifies the agent that a NES suggestion was accepted.
|
|
3841
|
+
*
|
|
3842
|
+
* @experimental
|
|
3843
|
+
*/
|
|
3844
|
+
unstable_acceptNes(params) {
|
|
3845
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_accept, params);
|
|
3846
|
+
}
|
|
3847
|
+
/**
|
|
3848
|
+
* **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
3849
|
+
*
|
|
3850
|
+
* Notifies the agent that a NES suggestion was rejected.
|
|
3851
|
+
*
|
|
3852
|
+
* @experimental
|
|
3853
|
+
*/
|
|
3854
|
+
unstable_rejectNes(params) {
|
|
3855
|
+
return this.connection.sendNotification(AGENT_METHODS.nes_reject, params);
|
|
3856
|
+
}
|
|
3857
|
+
request(method, params, options) {
|
|
3858
|
+
const spec = agentRequestSpecsByMethod[method];
|
|
3859
|
+
return this.connection.sendRequest(method, params, spec?.mapResponse, options);
|
|
3860
|
+
}
|
|
3861
|
+
notify(method, params) {
|
|
3862
|
+
return this.connection.sendNotification(method, params);
|
|
3863
|
+
}
|
|
3864
|
+
/**
|
|
3865
|
+
* Extension method.
|
|
3866
|
+
*
|
|
3867
|
+
* @deprecated Use {@link request}.
|
|
3868
|
+
*/
|
|
3869
|
+
extMethod(method, params) {
|
|
3870
|
+
return this.request(method, params);
|
|
3871
|
+
}
|
|
3872
|
+
/**
|
|
3873
|
+
* Extension notification.
|
|
3874
|
+
*
|
|
3875
|
+
* @deprecated Use {@link notify}.
|
|
3876
|
+
*/
|
|
3877
|
+
extNotification(method, params) {
|
|
3878
|
+
return this.notify(method, params);
|
|
3879
|
+
}
|
|
3880
|
+
/**
|
|
3881
|
+
* AbortSignal that aborts when the connection closes.
|
|
3882
|
+
*
|
|
3883
|
+
* This signal can be used to:
|
|
3884
|
+
* - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
|
|
3885
|
+
* - Check connection status synchronously: `if (connection.signal.aborted) {...}`
|
|
3886
|
+
* - Pass to other APIs (fetch, setTimeout) for automatic cancellation
|
|
3887
|
+
*
|
|
3888
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
3889
|
+
*
|
|
3890
|
+
* @example
|
|
3891
|
+
* ```typescript
|
|
3892
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
3893
|
+
*
|
|
3894
|
+
* // Listen for closure
|
|
3895
|
+
* connection.signal.addEventListener('abort', () => {
|
|
3896
|
+
* console.log('Connection closed - performing cleanup');
|
|
3897
|
+
* });
|
|
3898
|
+
*
|
|
3899
|
+
* // Check status
|
|
3900
|
+
* if (connection.signal.aborted) {
|
|
3901
|
+
* console.log('Connection is already closed');
|
|
3902
|
+
* }
|
|
3903
|
+
*
|
|
3904
|
+
* // Pass to other APIs
|
|
3905
|
+
* fetch(url, { signal: connection.signal });
|
|
3906
|
+
* ```
|
|
3907
|
+
*/
|
|
3908
|
+
get signal() {
|
|
3909
|
+
return this.connection.signal;
|
|
3910
|
+
}
|
|
3911
|
+
/**
|
|
3912
|
+
* Promise that resolves when the connection closes.
|
|
3913
|
+
*
|
|
3914
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
3915
|
+
* Once closed, the connection cannot send or receive any more messages.
|
|
3916
|
+
*
|
|
3917
|
+
* This is useful for async/await style cleanup:
|
|
3918
|
+
*
|
|
3919
|
+
* @example
|
|
3920
|
+
* ```typescript
|
|
3921
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
3922
|
+
* await connection.closed;
|
|
3923
|
+
* console.log('Connection closed - performing cleanup');
|
|
3924
|
+
* ```
|
|
3925
|
+
*/
|
|
3926
|
+
get closed() {
|
|
3927
|
+
return this.connection.closed;
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
const name = "acp-extension-claude";
|
|
3931
|
+
const version = "0.59.0";
|
|
3932
|
+
const dependencies = { "@anthropic-ai/claude-agent-sdk": "0.3.207" };
|
|
3933
|
+
const packageJson = {
|
|
3934
|
+
name,
|
|
3935
|
+
version,
|
|
3936
|
+
dependencies
|
|
3937
|
+
};
|
|
3938
|
+
export {
|
|
3939
|
+
ClientSideConnection as C,
|
|
3940
|
+
PROTOCOL_VERSION as P,
|
|
3941
|
+
RequestError as R,
|
|
3942
|
+
CreateElicitationResponse as a,
|
|
3943
|
+
agent as b,
|
|
3944
|
+
methods as m,
|
|
3945
|
+
ndJsonStream as n,
|
|
3946
|
+
packageJson as p
|
|
3947
|
+
};
|