@factory/droid-sdk 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -482
- package/dist/chunk-4G2RKM2H.js +25831 -0
- package/dist/chunk-4G2RKM2H.js.map +1 -0
- package/dist/chunk-ROFAQUG4.mjs +25831 -0
- package/dist/chunk-ROFAQUG4.mjs.map +1 -0
- package/dist/{index-CwXX5IUH.d.cts → index-_nUPGHpH.d.mts} +92630 -79659
- package/dist/{index-CwXX5IUH.d.ts → index-_nUPGHpH.d.ts} +92630 -79659
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -93103
- package/dist/index.js +829 -11745
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +830 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node.d.mts +757 -0
- package/dist/node.d.ts +757 -0
- package/dist/node.js +4731 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +4731 -0
- package/dist/node.mjs.map +1 -0
- package/docs/typescript-sdk-reference.md +1437 -0
- package/examples/browser/daemon-lifecycle.ts +95 -0
- package/examples/browser/daemon-model-discovery.ts +47 -0
- package/examples/browser/daemon-multi-session.ts +66 -0
- package/examples/browser/daemon-session.ts +73 -0
- package/examples/browser/index.html +69 -0
- package/examples/browser/list-sessions.ts +50 -0
- package/examples/node/abort-session-stream.ts +34 -0
- package/examples/node/ask-user-elicitation.ts +39 -0
- package/examples/node/compact-session.ts +63 -0
- package/examples/node/custom-system-prompt.ts +35 -0
- package/examples/node/document-input.ts +58 -0
- package/examples/node/enter-spec-mode.ts +87 -0
- package/examples/node/external-mcp.ts +45 -0
- package/examples/node/fork-session.ts +56 -0
- package/examples/node/hook-execution.ts +94 -0
- package/examples/node/image-attachment.ts +41 -0
- package/examples/node/init-metadata.ts +24 -0
- package/examples/node/interrupt-session.ts +55 -0
- package/examples/node/list-sessions.ts +20 -0
- package/examples/node/model-discovery.ts +28 -0
- package/examples/node/model-selection.ts +35 -0
- package/examples/node/multi-turn-session.ts +37 -0
- package/examples/node/observability.ts +75 -0
- package/examples/node/partial-stream.ts +56 -0
- package/examples/node/permission-handler.ts +60 -0
- package/examples/node/rename-session.ts +33 -0
- package/examples/node/result-metadata.ts +43 -0
- package/examples/node/resume-session.ts +41 -0
- package/examples/node/rewind-session.ts +79 -0
- package/examples/node/run.ts +32 -0
- package/examples/node/sdk-mcp-tool.ts +56 -0
- package/examples/node/session-settings.ts +35 -0
- package/examples/node/session-stream.ts +59 -0
- package/examples/node/skills.ts +24 -0
- package/examples/node/spec-mode-new-session.ts +120 -0
- package/examples/node/spec-mode-same-session.ts +119 -0
- package/examples/node/structured-output.ts +96 -0
- package/examples/node/tool-controls.ts +26 -0
- package/examples/package.json +3 -0
- package/package.json +20 -42
- package/dist/index.cjs +0 -12135
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -93103
- package/dist/protocol/index.cjs +0 -6466
- package/dist/protocol/index.cjs.map +0 -1
- package/dist/protocol/index.d.cts +0 -2
- package/dist/protocol/index.d.ts +0 -2
- package/dist/protocol/index.js +0 -6078
- package/dist/protocol/index.js.map +0 -1
- package/docs/daemon-usage-guide.md +0 -544
- package/docs/sdk-usage-guide.md +0 -748
- package/examples/abort-session-stream.ts +0 -34
- package/examples/daemon-multi-session.ts +0 -67
- package/examples/droid-dev-structured-output.ts +0 -44
- package/examples/fork-session.ts +0 -68
- package/examples/hook-execution.ts +0 -68
- package/examples/init-metadata.ts +0 -24
- package/examples/interrupt-session.ts +0 -35
- package/examples/list-sessions.ts +0 -19
- package/examples/multi-turn-session.ts +0 -40
- package/examples/permission-handler.ts +0 -41
- package/examples/readme-structured-output.ts +0 -26
- package/examples/result-metadata.ts +0 -63
- package/examples/run.ts +0 -39
- package/examples/sdk-mcp-tool.ts +0 -44
- package/examples/session-stream.ts +0 -57
- package/examples/spec-mode-new-session.ts +0 -61
- package/examples/spec-mode-same-session.ts +0 -72
- package/examples/structured-output.ts +0 -60
- package/examples/test-compact.ts +0 -65
- package/examples/test-rewind.ts +0 -87
- package/examples/tool-controls.ts +0 -37
package/dist/node.js
ADDED
|
@@ -0,0 +1,4731 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
var _chunk4G2RKM2Hjs = require('./chunk-4G2RKM2H.js');
|
|
445
|
+
|
|
446
|
+
// src/exec-core/client.ts
|
|
447
|
+
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
448
|
+
var _uuid = require('uuid');
|
|
449
|
+
var _zod = require('zod');
|
|
450
|
+
|
|
451
|
+
// src/exec-core/constants.ts
|
|
452
|
+
var DEFAULT_REQUEST_TIMEOUT2 = 3e4;
|
|
453
|
+
var SESSION_INIT_TIMEOUT2 = 6e4;
|
|
454
|
+
var COMPACTION_TIMEOUT2 = 24e4;
|
|
455
|
+
var MCP_AUTH_TIMEOUT2 = 3e5;
|
|
456
|
+
var WINDOWS_JOB_OBJECT_ERROR_MARKER = "AssignProcessToJobObject";
|
|
457
|
+
var CLI_JSONRPC_CHILD_SPAWN_LATENCY_METRIC = "cli_jsonrpc_child_spawn_latency";
|
|
458
|
+
var noopLogger = {
|
|
459
|
+
info() {
|
|
460
|
+
},
|
|
461
|
+
warn() {
|
|
462
|
+
},
|
|
463
|
+
exception() {
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/exec-core/default-deps.ts
|
|
468
|
+
function getRuntimeEnvironment() {
|
|
469
|
+
return _nullishCoalesce(_optionalChain([globalThis, 'access', _ => _.process, 'optionalAccess', _2 => _2.env]), () => ( {}));
|
|
470
|
+
}
|
|
471
|
+
var defaultExecCoreDeps = {
|
|
472
|
+
logger: {
|
|
473
|
+
info() {
|
|
474
|
+
},
|
|
475
|
+
warn() {
|
|
476
|
+
},
|
|
477
|
+
exception() {
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
metrics: {
|
|
481
|
+
addToCounter() {
|
|
482
|
+
},
|
|
483
|
+
recordDuration() {
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
tracing: {
|
|
487
|
+
getCurrentContext() {
|
|
488
|
+
return void 0;
|
|
489
|
+
},
|
|
490
|
+
injectContext() {
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
commandResolver: {
|
|
494
|
+
resolveDroidCommand(isDevelopment) {
|
|
495
|
+
return {
|
|
496
|
+
execPath: isDevelopment ? "droid-dev" : "droid",
|
|
497
|
+
prefixArgs: []
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
factoryPathResolver: {
|
|
502
|
+
getFactoryHome() {
|
|
503
|
+
const env = getRuntimeEnvironment();
|
|
504
|
+
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(env.FACTORY_HOME_OVERRIDE, () => ( env.HOME)), () => ( env.USERPROFILE)), () => ( ""));
|
|
505
|
+
},
|
|
506
|
+
getFactoryDirName() {
|
|
507
|
+
return ".factory";
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
environmentResolver: {
|
|
511
|
+
resolveTransportLogEnvValue() {
|
|
512
|
+
return getRuntimeEnvironment().FACTORY_DROID_SDK_TRANSPORT_LOG;
|
|
513
|
+
},
|
|
514
|
+
sanitizeSpawnEnv(env) {
|
|
515
|
+
return env;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/exec-core/enums.ts
|
|
521
|
+
var DroidClientEvent = /* @__PURE__ */ ((DroidClientEvent2) => {
|
|
522
|
+
DroidClientEvent2["SESSION_NOTIFICATION"] = "session_notification";
|
|
523
|
+
DroidClientEvent2["REQUEST_PERMISSION"] = "request_permission";
|
|
524
|
+
DroidClientEvent2["ASK_USER"] = "ask_user";
|
|
525
|
+
DroidClientEvent2["ERROR"] = "error";
|
|
526
|
+
return DroidClientEvent2;
|
|
527
|
+
})(DroidClientEvent || {});
|
|
528
|
+
var DroidProcessMode = /* @__PURE__ */ ((DroidProcessMode2) => {
|
|
529
|
+
DroidProcessMode2["Acp"] = "acp";
|
|
530
|
+
DroidProcessMode2["StreamJsonRpc"] = "stream-jsonrpc";
|
|
531
|
+
return DroidProcessMode2;
|
|
532
|
+
})(DroidProcessMode || {});
|
|
533
|
+
var TransportDirection = /* @__PURE__ */ ((TransportDirection2) => {
|
|
534
|
+
TransportDirection2["In"] = "in";
|
|
535
|
+
TransportDirection2["Out"] = "out";
|
|
536
|
+
TransportDirection2["OutFailed"] = "out_failed";
|
|
537
|
+
return TransportDirection2;
|
|
538
|
+
})(TransportDirection || {});
|
|
539
|
+
|
|
540
|
+
// ../droid-sdk-core/src/observability.ts
|
|
541
|
+
function sanitizeAttributes(attributes) {
|
|
542
|
+
if (attributes === void 0) {
|
|
543
|
+
return void 0;
|
|
544
|
+
}
|
|
545
|
+
const sanitized = {};
|
|
546
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
547
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
548
|
+
sanitized[key] = value;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return Object.keys(sanitized).length > 0 ? sanitized : void 0;
|
|
552
|
+
}
|
|
553
|
+
function serializeError(error) {
|
|
554
|
+
if (error instanceof Error) {
|
|
555
|
+
const code = "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
556
|
+
return {
|
|
557
|
+
name: error.name || void 0,
|
|
558
|
+
message: error.message,
|
|
559
|
+
...code !== void 0 && { code }
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
return { message: String(error) };
|
|
563
|
+
}
|
|
564
|
+
function handleSinkFailure(error, options) {
|
|
565
|
+
try {
|
|
566
|
+
_optionalChain([options, 'optionalAccess', _3 => _3.onError, 'optionalCall', _4 => _4(error)]);
|
|
567
|
+
} catch (e2) {
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function emitDroidLog(observability, event, options) {
|
|
571
|
+
const sink = _optionalChain([observability, 'optionalAccess', _5 => _5.logger]);
|
|
572
|
+
if (!sink) {
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
try {
|
|
576
|
+
sink.log({
|
|
577
|
+
level: event.level,
|
|
578
|
+
name: event.name,
|
|
579
|
+
message: event.message,
|
|
580
|
+
attributes: sanitizeAttributes(event.attributes),
|
|
581
|
+
...event.error !== void 0 && {
|
|
582
|
+
error: serializeError(event.error)
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
return true;
|
|
586
|
+
} catch (error) {
|
|
587
|
+
handleSinkFailure(error, options);
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function recordDroidMetric(observability, event, options) {
|
|
592
|
+
const sink = _optionalChain([observability, 'optionalAccess', _6 => _6.metrics]);
|
|
593
|
+
if (!sink) {
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
try {
|
|
597
|
+
sink.record({
|
|
598
|
+
name: event.name,
|
|
599
|
+
kind: event.kind,
|
|
600
|
+
value: event.value,
|
|
601
|
+
unit: event.unit,
|
|
602
|
+
attributes: sanitizeAttributes(event.attributes)
|
|
603
|
+
});
|
|
604
|
+
return true;
|
|
605
|
+
} catch (error) {
|
|
606
|
+
handleSinkFailure(error, options);
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
function injectDroidTraceContext(observability, carrier, options) {
|
|
611
|
+
const sink = _optionalChain([observability, 'optionalAccess', _7 => _7.tracing]);
|
|
612
|
+
if (!sink) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
try {
|
|
616
|
+
sink.inject(carrier);
|
|
617
|
+
return true;
|
|
618
|
+
} catch (error) {
|
|
619
|
+
handleSinkFailure(error, options);
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/exec-core/deps.ts
|
|
625
|
+
function logWarn(logger, message, metadata) {
|
|
626
|
+
logger.warn(message, metadata);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/exec-core/observability-adapter.ts
|
|
630
|
+
function createSinkFailureOptions(fallback) {
|
|
631
|
+
return {
|
|
632
|
+
onError(sinkError) {
|
|
633
|
+
logWarn(fallback, "[droid-sdk observability] customer sink threw", {
|
|
634
|
+
cause: sinkError
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
var CONTENT_BEARING_KEYS = ["output", "preview", "stderrTail"];
|
|
640
|
+
function redactContentForCustomerSink(metadata) {
|
|
641
|
+
if (metadata === void 0) {
|
|
642
|
+
return void 0;
|
|
643
|
+
}
|
|
644
|
+
let redacted;
|
|
645
|
+
for (const key of CONTENT_BEARING_KEYS) {
|
|
646
|
+
if (!(key in metadata)) {
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
redacted ??= { ...metadata };
|
|
650
|
+
const value = redacted[key];
|
|
651
|
+
delete redacted[key];
|
|
652
|
+
if (typeof value === "string") {
|
|
653
|
+
redacted[`${key}ByteLength`] = new TextEncoder().encode(value).byteLength;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return _nullishCoalesce(redacted, () => ( metadata));
|
|
657
|
+
}
|
|
658
|
+
function createLogger(observability, fallback) {
|
|
659
|
+
const sink = _optionalChain([observability, 'optionalAccess', _8 => _8.logger]);
|
|
660
|
+
if (!sink) {
|
|
661
|
+
return fallback;
|
|
662
|
+
}
|
|
663
|
+
const sinkObservability = { logger: sink };
|
|
664
|
+
const sinkFailureOptions = createSinkFailureOptions(fallback);
|
|
665
|
+
return {
|
|
666
|
+
info(message, metadata) {
|
|
667
|
+
emitDroidLog(
|
|
668
|
+
sinkObservability,
|
|
669
|
+
{
|
|
670
|
+
level: "info",
|
|
671
|
+
name: "droid.sdk.info",
|
|
672
|
+
message,
|
|
673
|
+
attributes: redactContentForCustomerSink(metadata)
|
|
674
|
+
},
|
|
675
|
+
sinkFailureOptions
|
|
676
|
+
);
|
|
677
|
+
},
|
|
678
|
+
warn(message, metadata) {
|
|
679
|
+
emitDroidLog(
|
|
680
|
+
sinkObservability,
|
|
681
|
+
{
|
|
682
|
+
level: "warn",
|
|
683
|
+
name: "droid.sdk.warn",
|
|
684
|
+
message,
|
|
685
|
+
attributes: redactContentForCustomerSink(metadata)
|
|
686
|
+
},
|
|
687
|
+
sinkFailureOptions
|
|
688
|
+
);
|
|
689
|
+
},
|
|
690
|
+
exception(error, message, metadata) {
|
|
691
|
+
emitDroidLog(
|
|
692
|
+
sinkObservability,
|
|
693
|
+
{
|
|
694
|
+
level: "error",
|
|
695
|
+
name: "droid.sdk.error",
|
|
696
|
+
message,
|
|
697
|
+
attributes: redactContentForCustomerSink(metadata),
|
|
698
|
+
error
|
|
699
|
+
},
|
|
700
|
+
sinkFailureOptions
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function createMetrics(observability, fallback, failureLogger) {
|
|
706
|
+
const sink = _optionalChain([observability, 'optionalAccess', _9 => _9.metrics]);
|
|
707
|
+
if (!sink) {
|
|
708
|
+
return fallback;
|
|
709
|
+
}
|
|
710
|
+
const sinkObservability = { metrics: sink };
|
|
711
|
+
const sinkFailureOptions = createSinkFailureOptions(failureLogger);
|
|
712
|
+
return {
|
|
713
|
+
addToCounter(metric, value, tags) {
|
|
714
|
+
recordDroidMetric(
|
|
715
|
+
sinkObservability,
|
|
716
|
+
{
|
|
717
|
+
name: metric,
|
|
718
|
+
kind: "counter",
|
|
719
|
+
value,
|
|
720
|
+
unit: "1",
|
|
721
|
+
attributes: tags
|
|
722
|
+
},
|
|
723
|
+
sinkFailureOptions
|
|
724
|
+
);
|
|
725
|
+
},
|
|
726
|
+
recordDuration(metric, valueMs, tags) {
|
|
727
|
+
recordDroidMetric(
|
|
728
|
+
sinkObservability,
|
|
729
|
+
{
|
|
730
|
+
name: metric,
|
|
731
|
+
kind: "histogram",
|
|
732
|
+
value: valueMs,
|
|
733
|
+
unit: "ms",
|
|
734
|
+
attributes: tags
|
|
735
|
+
},
|
|
736
|
+
sinkFailureOptions
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function createTracing(observability, fallback, failureLogger) {
|
|
742
|
+
const sink = _optionalChain([observability, 'optionalAccess', _10 => _10.tracing]);
|
|
743
|
+
if (!sink) {
|
|
744
|
+
return fallback;
|
|
745
|
+
}
|
|
746
|
+
const sinkObservability = { tracing: sink };
|
|
747
|
+
const sinkFailureOptions = createSinkFailureOptions(failureLogger);
|
|
748
|
+
return {
|
|
749
|
+
getCurrentContext() {
|
|
750
|
+
return {};
|
|
751
|
+
},
|
|
752
|
+
injectContext(meta) {
|
|
753
|
+
const carrier = {};
|
|
754
|
+
if (!injectDroidTraceContext(sinkObservability, carrier, sinkFailureOptions)) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (carrier.traceparent !== void 0) {
|
|
758
|
+
meta.traceparent = carrier.traceparent;
|
|
759
|
+
}
|
|
760
|
+
if (carrier.tracestate !== void 0) {
|
|
761
|
+
meta.tracestate = carrier.tracestate;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function resolveExecCoreDeps(observability, fallback = defaultExecCoreDeps) {
|
|
767
|
+
return {
|
|
768
|
+
logger: createLogger(observability, fallback.logger),
|
|
769
|
+
metrics: createMetrics(observability, fallback.metrics, fallback.logger),
|
|
770
|
+
tracing: createTracing(observability, fallback.tracing, fallback.logger),
|
|
771
|
+
commandResolver: fallback.commandResolver,
|
|
772
|
+
factoryPathResolver: fallback.factoryPathResolver,
|
|
773
|
+
environmentResolver: fallback.environmentResolver
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// src/exec-core/client.ts
|
|
778
|
+
function getResponseId(response) {
|
|
779
|
+
const parsed = _chunk4G2RKM2Hjs.JsonRpcBaseResponseSchema.safeParse(response);
|
|
780
|
+
return parsed.success ? parsed.data.id : void 0;
|
|
781
|
+
}
|
|
782
|
+
var JsonRpcEnvelopePeekSchema = _chunk4G2RKM2Hjs.JsonRpcEnvelopeSchema.partial().extend({
|
|
783
|
+
type: _zod.z.nativeEnum(_chunk4G2RKM2Hjs.JsonRpcMessageType).optional(),
|
|
784
|
+
method: _zod.z.string().optional(),
|
|
785
|
+
id: _zod.z.string().nullable().optional()
|
|
786
|
+
}).passthrough();
|
|
787
|
+
function inspectJsonRpcEnvelope2(message) {
|
|
788
|
+
const result = JsonRpcEnvelopePeekSchema.safeParse(message);
|
|
789
|
+
if (!result.success) {
|
|
790
|
+
return { protocolVersionMismatch: null };
|
|
791
|
+
}
|
|
792
|
+
const envelope = result.data;
|
|
793
|
+
return {
|
|
794
|
+
protocolVersionMismatch: envelope.factoryProtocolVersion !== void 0 && envelope.factoryProtocolVersion !== _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION ? {
|
|
795
|
+
localFactoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
796
|
+
peerFactoryProtocolVersion: envelope.factoryProtocolVersion,
|
|
797
|
+
messageType: envelope.type,
|
|
798
|
+
method: envelope.method,
|
|
799
|
+
requestId: envelope.id
|
|
800
|
+
} : null
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
var DroidClient = (_class = class _DroidClient extends _events2.default {
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
__init() {this.pendingRequests = /* @__PURE__ */ new Map()}
|
|
808
|
+
__init2() {this.permissionHandlers = /* @__PURE__ */ new Map()}
|
|
809
|
+
__init3() {this.askUserHandlers = /* @__PURE__ */ new Map()}
|
|
810
|
+
__init4() {this.pendingPermissionRequests = /* @__PURE__ */ new Map()}
|
|
811
|
+
__init5() {this.pendingAskUserRequests = /* @__PURE__ */ new Map()}
|
|
812
|
+
__init6() {this.currentSessionId = null}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Sticky error from a transport failure. Once set, all subsequent
|
|
816
|
+
* `sendRequest()` calls throw this error immediately, preventing
|
|
817
|
+
* requests from hanging on a dead transport.
|
|
818
|
+
*/
|
|
819
|
+
__init7() {this.transportError = null}
|
|
820
|
+
__init8() {this.completedTurnObserved = false}
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
constructor(options, deps = defaultExecCoreDeps) {
|
|
825
|
+
super();_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);;
|
|
826
|
+
this.transport = options.transport;
|
|
827
|
+
const resolved = resolveExecCoreDeps(options.observability, deps);
|
|
828
|
+
this.logger = resolved.logger;
|
|
829
|
+
this.tracing = resolved.tracing;
|
|
830
|
+
this.requestTimeout = _nullishCoalesce(options.requestTimeout, () => ( DEFAULT_REQUEST_TIMEOUT2));
|
|
831
|
+
this.sessionInitTimeout = _nullishCoalesce(options.sessionInitTimeout, () => ( SESSION_INIT_TIMEOUT2));
|
|
832
|
+
this.onRequestSettled = options.onRequestSettled;
|
|
833
|
+
this.transport.onMessage((message) => {
|
|
834
|
+
void this.handleMessage(message).catch((error) => {
|
|
835
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
836
|
+
this.emit(
|
|
837
|
+
"session_notification" /* SESSION_NOTIFICATION */,
|
|
838
|
+
_DroidClient.createNotificationEvent(
|
|
839
|
+
_DroidClient.createErrorNotification(err)
|
|
840
|
+
)
|
|
841
|
+
);
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
this.transport.onError((error) => {
|
|
845
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
846
|
+
const expectedCleanExit = err instanceof _chunk4G2RKM2Hjs.ProcessExitError && err.exitCode === 0 && this.completedTurnObserved;
|
|
847
|
+
if (expectedCleanExit) {
|
|
848
|
+
this.logger.info("[DroidClient] Process exited after completed turn", {
|
|
849
|
+
exitCode: err.exitCode
|
|
850
|
+
});
|
|
851
|
+
} else {
|
|
852
|
+
this.logger.exception(err, "Transport error");
|
|
853
|
+
}
|
|
854
|
+
this.transportError = err;
|
|
855
|
+
this.rejectAllPending(err);
|
|
856
|
+
if (this.listenerCount("error" /* ERROR */) > 0) {
|
|
857
|
+
this.emit("error" /* ERROR */, err);
|
|
858
|
+
}
|
|
859
|
+
this.emit(
|
|
860
|
+
"session_notification" /* SESSION_NOTIFICATION */,
|
|
861
|
+
_DroidClient.createNotificationEvent(
|
|
862
|
+
_DroidClient.createErrorNotification(err)
|
|
863
|
+
)
|
|
864
|
+
);
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
get sessionId() {
|
|
868
|
+
return this.currentSessionId;
|
|
869
|
+
}
|
|
870
|
+
get isConnected() {
|
|
871
|
+
return this.transport.isConnected;
|
|
872
|
+
}
|
|
873
|
+
requireMcpOAuthOptOutSupport() {
|
|
874
|
+
if (this.peerProtocolVersion === _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)(
|
|
878
|
+
"MCP OAuth opt-out requires a confirmed matching Droid protocol version. The connected Droid reported an incompatible protocol version and cannot disable OAuth for MCP servers.",
|
|
879
|
+
{
|
|
880
|
+
value: {
|
|
881
|
+
localFactoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
882
|
+
peerFactoryProtocolVersion: this.peerProtocolVersion
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
validateMcpServersProtocolSupport(mcpServers) {
|
|
888
|
+
if (_optionalChain([mcpServers, 'optionalAccess', _11 => _11.some, 'call', _12 => _12((server) => "oauth" in server && server.oauth === false)])) {
|
|
889
|
+
this.requireMcpOAuthOptOutSupport();
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
async initializeSession(params) {
|
|
893
|
+
const request = {
|
|
894
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
895
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
896
|
+
type: "request",
|
|
897
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
898
|
+
id: _uuid.v4.call(void 0, ),
|
|
899
|
+
method: "droid.initialize_session" /* INITIALIZE_SESSION */,
|
|
900
|
+
params
|
|
901
|
+
};
|
|
902
|
+
const rawResponse = await this.sendRequest(
|
|
903
|
+
request,
|
|
904
|
+
this.sessionInitTimeout
|
|
905
|
+
);
|
|
906
|
+
const response = _chunk4G2RKM2Hjs.InitializeSessionResponseSchema.parse(rawResponse);
|
|
907
|
+
this.peerProtocolVersion = response.factoryProtocolVersion;
|
|
908
|
+
if (response.error) {
|
|
909
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Initialize session request failed", {
|
|
910
|
+
requestId: request.id,
|
|
911
|
+
code: response.error.code,
|
|
912
|
+
message: response.error.message,
|
|
913
|
+
data: response.error.data
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
this.validateMcpServersProtocolSupport(params.mcpServers);
|
|
917
|
+
const result = _chunk4G2RKM2Hjs.InitializeSessionResultSchema.parse(response.result);
|
|
918
|
+
this.currentSessionId = result.sessionId;
|
|
919
|
+
return response;
|
|
920
|
+
}
|
|
921
|
+
async loadSession(params) {
|
|
922
|
+
const request = {
|
|
923
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
924
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
925
|
+
type: "request",
|
|
926
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
927
|
+
id: _uuid.v4.call(void 0, ),
|
|
928
|
+
method: "droid.load_session" /* LOAD_SESSION */,
|
|
929
|
+
params
|
|
930
|
+
};
|
|
931
|
+
const rawResponse = await this.sendRequest(
|
|
932
|
+
request,
|
|
933
|
+
this.sessionInitTimeout
|
|
934
|
+
);
|
|
935
|
+
const response = _chunk4G2RKM2Hjs.LoadSessionResponseSchema.parse(rawResponse);
|
|
936
|
+
this.peerProtocolVersion = response.factoryProtocolVersion;
|
|
937
|
+
if (response.error) {
|
|
938
|
+
const isSessionNotFound = response.error.code === -32004 /* ENTITY_NOT_FOUND */;
|
|
939
|
+
if (isSessionNotFound) {
|
|
940
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionNotFoundError)(params.sessionId, {
|
|
941
|
+
requestId: request.id,
|
|
942
|
+
code: response.error.code,
|
|
943
|
+
message: response.error.message,
|
|
944
|
+
data: response.error.data
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Load session request failed", {
|
|
948
|
+
requestId: request.id,
|
|
949
|
+
code: response.error.code,
|
|
950
|
+
message: response.error.message,
|
|
951
|
+
data: response.error.data
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
this.validateMcpServersProtocolSupport(params.mcpServers);
|
|
955
|
+
this.currentSessionId = params.sessionId;
|
|
956
|
+
return response;
|
|
957
|
+
}
|
|
958
|
+
async addUserMessage(params, requestId) {
|
|
959
|
+
if (!this.currentSessionId) {
|
|
960
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
961
|
+
"No active session. Call initializeSession or loadSession first."
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
this.completedTurnObserved = false;
|
|
965
|
+
const request = {
|
|
966
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
967
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
968
|
+
type: "request",
|
|
969
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
970
|
+
id: _nullishCoalesce(requestId, () => ( _uuid.v4.call(void 0, ))),
|
|
971
|
+
method: "droid.add_user_message" /* ADD_USER_MESSAGE */,
|
|
972
|
+
params: {
|
|
973
|
+
...params.messageId && { messageId: params.messageId },
|
|
974
|
+
text: params.text,
|
|
975
|
+
images: params.images,
|
|
976
|
+
imagePaths: params.imagePaths,
|
|
977
|
+
files: params.files,
|
|
978
|
+
outputFormat: params.outputFormat,
|
|
979
|
+
...params.skipAgentLoop && { skipAgentLoop: params.skipAgentLoop },
|
|
980
|
+
queuePlacement: _nullishCoalesce(params.queuePlacement, () => ( "end_of_turn")) /* EndOfTurn */,
|
|
981
|
+
...params.role && { role: params.role },
|
|
982
|
+
...params.visibility && { visibility: params.visibility }
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
const rawResponse = await this.sendRequest(request);
|
|
986
|
+
const response = _chunk4G2RKM2Hjs.AddUserMessageResponseSchema.parse(rawResponse);
|
|
987
|
+
if (response.error) {
|
|
988
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Add user message request failed", {
|
|
989
|
+
requestId: request.id,
|
|
990
|
+
code: response.error.code,
|
|
991
|
+
message: response.error.message,
|
|
992
|
+
data: response.error.data
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
return response;
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Persists user-only messages without starting an agent turn.
|
|
999
|
+
*
|
|
1000
|
+
* Use for daemon-owned activity that belongs in session history but was not
|
|
1001
|
+
* produced by the agent, such as commands run while a session starts.
|
|
1002
|
+
*/
|
|
1003
|
+
async appendMessages(params, requestId) {
|
|
1004
|
+
if (!this.currentSessionId) {
|
|
1005
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1006
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
const request = {
|
|
1010
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1011
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1012
|
+
type: "request",
|
|
1013
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1014
|
+
id: _nullishCoalesce(requestId, () => ( _uuid.v4.call(void 0, ))),
|
|
1015
|
+
method: "droid.append_messages" /* APPEND_MESSAGES */,
|
|
1016
|
+
params
|
|
1017
|
+
};
|
|
1018
|
+
const rawResponse = await this.sendRequest(request);
|
|
1019
|
+
const response = _chunk4G2RKM2Hjs.AppendMessagesResponseSchema.parse(rawResponse);
|
|
1020
|
+
if (response.error) {
|
|
1021
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Append messages request failed", {
|
|
1022
|
+
requestId: request.id,
|
|
1023
|
+
code: response.error.code,
|
|
1024
|
+
message: response.error.message,
|
|
1025
|
+
data: response.error.data
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
1028
|
+
return response;
|
|
1029
|
+
}
|
|
1030
|
+
async resolveQueuedUserMessage(params) {
|
|
1031
|
+
if (!this.currentSessionId) {
|
|
1032
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1033
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
const request = {
|
|
1037
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1038
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1039
|
+
type: "request",
|
|
1040
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1041
|
+
id: _uuid.v4.call(void 0, ),
|
|
1042
|
+
method: "droid.resolve_queued_user_message" /* RESOLVE_QUEUED_USER_MESSAGE */,
|
|
1043
|
+
params
|
|
1044
|
+
};
|
|
1045
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1046
|
+
const response = _chunk4G2RKM2Hjs.ResolveQueuedUserMessageResponseSchema.parse(rawResponse);
|
|
1047
|
+
if (response.error) {
|
|
1048
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Resolve queued user message request failed", {
|
|
1049
|
+
requestId: request.id,
|
|
1050
|
+
code: response.error.code,
|
|
1051
|
+
message: response.error.message,
|
|
1052
|
+
data: response.error.data
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
return response;
|
|
1056
|
+
}
|
|
1057
|
+
async interruptSession(params = {}) {
|
|
1058
|
+
if (!this.currentSessionId) {
|
|
1059
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1060
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
const request = {
|
|
1064
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1065
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1066
|
+
type: "request",
|
|
1067
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1068
|
+
id: _uuid.v4.call(void 0, ),
|
|
1069
|
+
method: "droid.interrupt_session" /* INTERRUPT_SESSION */,
|
|
1070
|
+
params
|
|
1071
|
+
};
|
|
1072
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1073
|
+
const response = _chunk4G2RKM2Hjs.InterruptSessionResponseSchema.parse(rawResponse);
|
|
1074
|
+
if (response.error) {
|
|
1075
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Interrupt session request failed", {
|
|
1076
|
+
requestId: request.id,
|
|
1077
|
+
code: response.error.code,
|
|
1078
|
+
message: response.error.message,
|
|
1079
|
+
data: response.error.data
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
return response;
|
|
1083
|
+
}
|
|
1084
|
+
async closeSession(params = {}) {
|
|
1085
|
+
if (!this.currentSessionId) {
|
|
1086
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1087
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1088
|
+
);
|
|
1089
|
+
}
|
|
1090
|
+
const request = {
|
|
1091
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1092
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1093
|
+
type: "request",
|
|
1094
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1095
|
+
id: _uuid.v4.call(void 0, ),
|
|
1096
|
+
method: "droid.close_session" /* CLOSE_SESSION */,
|
|
1097
|
+
params
|
|
1098
|
+
};
|
|
1099
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1100
|
+
const response = _chunk4G2RKM2Hjs.CloseSessionResponseSchema.parse(rawResponse);
|
|
1101
|
+
if (response.error) {
|
|
1102
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Close session request failed", {
|
|
1103
|
+
requestId: request.id,
|
|
1104
|
+
code: response.error.code,
|
|
1105
|
+
message: response.error.message,
|
|
1106
|
+
data: response.error.data
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
return response;
|
|
1110
|
+
}
|
|
1111
|
+
async killWorkerSession(params) {
|
|
1112
|
+
if (!this.currentSessionId) {
|
|
1113
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1114
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
const request = {
|
|
1118
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1119
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1120
|
+
type: "request",
|
|
1121
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1122
|
+
id: _uuid.v4.call(void 0, ),
|
|
1123
|
+
method: "droid.kill_worker_session" /* KILL_WORKER_SESSION */,
|
|
1124
|
+
params
|
|
1125
|
+
};
|
|
1126
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1127
|
+
const response = _chunk4G2RKM2Hjs.KillWorkerSessionResponseSchema.parse(rawResponse);
|
|
1128
|
+
if (response.error) {
|
|
1129
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Kill worker session request failed", {
|
|
1130
|
+
requestId: request.id,
|
|
1131
|
+
code: response.error.code,
|
|
1132
|
+
message: response.error.message,
|
|
1133
|
+
data: response.error.data
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
return response;
|
|
1137
|
+
}
|
|
1138
|
+
async updateSessionSettings(params, requestId) {
|
|
1139
|
+
if (!this.currentSessionId) {
|
|
1140
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1141
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
const request = {
|
|
1145
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1146
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1147
|
+
type: "request",
|
|
1148
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1149
|
+
id: _nullishCoalesce(requestId, () => ( _uuid.v4.call(void 0, ))),
|
|
1150
|
+
method: "droid.update_session_settings" /* UPDATE_SESSION_SETTINGS */,
|
|
1151
|
+
params
|
|
1152
|
+
};
|
|
1153
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1154
|
+
const responseParsed = _chunk4G2RKM2Hjs.UpdateSessionSettingsResponseSchema.safeParse(rawResponse);
|
|
1155
|
+
if (!responseParsed.success) {
|
|
1156
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)(
|
|
1157
|
+
"Invalid update session settings response format",
|
|
1158
|
+
{
|
|
1159
|
+
requestId: request.id,
|
|
1160
|
+
code: -32700 /* PARSE_ERROR */,
|
|
1161
|
+
message: responseParsed.error.message,
|
|
1162
|
+
data: rawResponse
|
|
1163
|
+
}
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
const response = responseParsed.data;
|
|
1167
|
+
if (response.error) {
|
|
1168
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Update session settings request failed", {
|
|
1169
|
+
requestId: request.id,
|
|
1170
|
+
code: response.error.code,
|
|
1171
|
+
message: response.error.message,
|
|
1172
|
+
data: response.error.data
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
return response;
|
|
1176
|
+
}
|
|
1177
|
+
async changeWorkingDirectory(params) {
|
|
1178
|
+
if (!this.currentSessionId) {
|
|
1179
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1180
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
const request = {
|
|
1184
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1185
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1186
|
+
type: "request",
|
|
1187
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1188
|
+
id: _uuid.v4.call(void 0, ),
|
|
1189
|
+
method: "droid.change_working_directory" /* CHANGE_WORKING_DIRECTORY */,
|
|
1190
|
+
params
|
|
1191
|
+
};
|
|
1192
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1193
|
+
const response = _chunk4G2RKM2Hjs.ChangeWorkingDirectoryResponseSchema.parse(rawResponse);
|
|
1194
|
+
if (response.error) {
|
|
1195
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Change working directory request failed", {
|
|
1196
|
+
requestId: request.id,
|
|
1197
|
+
code: response.error.code,
|
|
1198
|
+
message: response.error.message,
|
|
1199
|
+
data: response.error.data
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
return response;
|
|
1203
|
+
}
|
|
1204
|
+
async toggleMcpServer(params) {
|
|
1205
|
+
if (!this.currentSessionId) {
|
|
1206
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1207
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
const request = {
|
|
1211
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1212
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1213
|
+
type: "request",
|
|
1214
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1215
|
+
id: _uuid.v4.call(void 0, ),
|
|
1216
|
+
method: "droid.toggle_mcp_server" /* TOGGLE_MCP_SERVER */,
|
|
1217
|
+
params: {
|
|
1218
|
+
serverName: params.serverName,
|
|
1219
|
+
enabled: params.enabled,
|
|
1220
|
+
settingsLevel: params.settingsLevel
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1224
|
+
const response = _chunk4G2RKM2Hjs.ToggleMcpServerResponseSchema.parse(rawResponse);
|
|
1225
|
+
return response;
|
|
1226
|
+
}
|
|
1227
|
+
async authenticateMcpServer(params) {
|
|
1228
|
+
if (!this.currentSessionId) {
|
|
1229
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1230
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
const request = {
|
|
1234
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1235
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1236
|
+
type: "request",
|
|
1237
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1238
|
+
id: _uuid.v4.call(void 0, ),
|
|
1239
|
+
method: "droid.authenticate_mcp_server" /* AUTHENTICATE_MCP_SERVER */,
|
|
1240
|
+
params: {
|
|
1241
|
+
serverName: params.serverName
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
const rawResponse = await this.sendRequest(request, MCP_AUTH_TIMEOUT2);
|
|
1245
|
+
const response = _chunk4G2RKM2Hjs.AuthenticateMcpServerResponseSchema.parse(rawResponse);
|
|
1246
|
+
return response;
|
|
1247
|
+
}
|
|
1248
|
+
async cancelMcpAuth(params) {
|
|
1249
|
+
if (!this.currentSessionId) {
|
|
1250
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1251
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1252
|
+
);
|
|
1253
|
+
}
|
|
1254
|
+
const request = {
|
|
1255
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1256
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1257
|
+
type: "request",
|
|
1258
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1259
|
+
id: _uuid.v4.call(void 0, ),
|
|
1260
|
+
method: "droid.cancel_mcp_auth" /* CANCEL_MCP_AUTH */,
|
|
1261
|
+
params: {
|
|
1262
|
+
serverName: params.serverName
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1266
|
+
const response = _chunk4G2RKM2Hjs.CancelMcpAuthResponseSchema.parse(rawResponse);
|
|
1267
|
+
return response;
|
|
1268
|
+
}
|
|
1269
|
+
async clearMcpAuth(params) {
|
|
1270
|
+
if (!this.currentSessionId) {
|
|
1271
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1272
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
const request = {
|
|
1276
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1277
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1278
|
+
type: "request",
|
|
1279
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1280
|
+
id: _uuid.v4.call(void 0, ),
|
|
1281
|
+
method: "droid.clear_mcp_auth" /* CLEAR_MCP_AUTH */,
|
|
1282
|
+
params: {
|
|
1283
|
+
serverName: params.serverName
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1287
|
+
const response = _chunk4G2RKM2Hjs.ClearMcpAuthResponseSchema.parse(rawResponse);
|
|
1288
|
+
return response;
|
|
1289
|
+
}
|
|
1290
|
+
async addMcpServer(params) {
|
|
1291
|
+
if (!this.currentSessionId) {
|
|
1292
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1293
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
if (params.oauth === false) {
|
|
1297
|
+
this.requireMcpOAuthOptOutSupport();
|
|
1298
|
+
}
|
|
1299
|
+
const request = {
|
|
1300
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1301
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1302
|
+
type: "request",
|
|
1303
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1304
|
+
id: _uuid.v4.call(void 0, ),
|
|
1305
|
+
method: "droid.add_mcp_server" /* ADD_MCP_SERVER */,
|
|
1306
|
+
params
|
|
1307
|
+
};
|
|
1308
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1309
|
+
const response = _chunk4G2RKM2Hjs.AddMcpServerResponseSchema.parse(rawResponse);
|
|
1310
|
+
return response;
|
|
1311
|
+
}
|
|
1312
|
+
async removeMcpServer(params) {
|
|
1313
|
+
if (!this.currentSessionId) {
|
|
1314
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1315
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
const request = {
|
|
1319
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1320
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1321
|
+
type: "request",
|
|
1322
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1323
|
+
id: _uuid.v4.call(void 0, ),
|
|
1324
|
+
method: "droid.remove_mcp_server" /* REMOVE_MCP_SERVER */,
|
|
1325
|
+
params
|
|
1326
|
+
};
|
|
1327
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1328
|
+
const response = _chunk4G2RKM2Hjs.RemoveMcpServerResponseSchema.parse(rawResponse);
|
|
1329
|
+
return response;
|
|
1330
|
+
}
|
|
1331
|
+
async listModels(params = {}) {
|
|
1332
|
+
const request = {
|
|
1333
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1334
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1335
|
+
type: "request",
|
|
1336
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1337
|
+
id: _uuid.v4.call(void 0, ),
|
|
1338
|
+
method: "droid.list_models" /* LIST_MODELS */,
|
|
1339
|
+
params
|
|
1340
|
+
};
|
|
1341
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1342
|
+
return _chunk4G2RKM2Hjs.ListModelsResponseSchema.parse(rawResponse);
|
|
1343
|
+
}
|
|
1344
|
+
async listMcpRegistry() {
|
|
1345
|
+
if (!this.currentSessionId) {
|
|
1346
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1347
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
const request = {
|
|
1351
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1352
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1353
|
+
type: "request",
|
|
1354
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1355
|
+
id: _uuid.v4.call(void 0, ),
|
|
1356
|
+
method: "droid.list_mcp_registry" /* LIST_MCP_REGISTRY */,
|
|
1357
|
+
params: {}
|
|
1358
|
+
};
|
|
1359
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1360
|
+
const response = _chunk4G2RKM2Hjs.ListMcpRegistryResponseSchema.parse(rawResponse);
|
|
1361
|
+
return response;
|
|
1362
|
+
}
|
|
1363
|
+
async listMcpTools() {
|
|
1364
|
+
if (!this.currentSessionId) {
|
|
1365
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1366
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
const request = {
|
|
1370
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1371
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1372
|
+
type: "request",
|
|
1373
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1374
|
+
id: _uuid.v4.call(void 0, ),
|
|
1375
|
+
method: "droid.list_mcp_tools" /* LIST_MCP_TOOLS */,
|
|
1376
|
+
params: {}
|
|
1377
|
+
};
|
|
1378
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1379
|
+
const response = _chunk4G2RKM2Hjs.ListMcpToolsResponseSchema.parse(rawResponse);
|
|
1380
|
+
return response;
|
|
1381
|
+
}
|
|
1382
|
+
async listTools(params = {}) {
|
|
1383
|
+
const request = {
|
|
1384
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1385
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1386
|
+
type: "request",
|
|
1387
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1388
|
+
id: _uuid.v4.call(void 0, ),
|
|
1389
|
+
method: "droid.list_tools" /* LIST_TOOLS */,
|
|
1390
|
+
params
|
|
1391
|
+
};
|
|
1392
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1393
|
+
const response = _chunk4G2RKM2Hjs.ListToolsResponseSchema.parse(rawResponse);
|
|
1394
|
+
return response;
|
|
1395
|
+
}
|
|
1396
|
+
async listMcpServers() {
|
|
1397
|
+
if (!this.currentSessionId) {
|
|
1398
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1399
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1400
|
+
);
|
|
1401
|
+
}
|
|
1402
|
+
const request = {
|
|
1403
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1404
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1405
|
+
type: "request",
|
|
1406
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1407
|
+
id: _uuid.v4.call(void 0, ),
|
|
1408
|
+
method: "droid.list_mcp_servers" /* LIST_MCP_SERVERS */,
|
|
1409
|
+
params: {}
|
|
1410
|
+
};
|
|
1411
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1412
|
+
const response = _chunk4G2RKM2Hjs.ListMcpServersResponseSchema.parse(rawResponse);
|
|
1413
|
+
return response;
|
|
1414
|
+
}
|
|
1415
|
+
async toggleMcpTool(serverName, toolName, enabled) {
|
|
1416
|
+
if (!this.currentSessionId) {
|
|
1417
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1418
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1419
|
+
);
|
|
1420
|
+
}
|
|
1421
|
+
const request = {
|
|
1422
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1423
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1424
|
+
type: "request",
|
|
1425
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1426
|
+
id: _uuid.v4.call(void 0, ),
|
|
1427
|
+
method: "droid.toggle_mcp_tool" /* TOGGLE_MCP_TOOL */,
|
|
1428
|
+
params: { serverName, toolName, enabled }
|
|
1429
|
+
};
|
|
1430
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1431
|
+
const response = _chunk4G2RKM2Hjs.ToggleMcpToolResponseSchema.parse(rawResponse);
|
|
1432
|
+
return response;
|
|
1433
|
+
}
|
|
1434
|
+
async submitMcpAuthCode(params) {
|
|
1435
|
+
if (!this.currentSessionId) {
|
|
1436
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1437
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
const request = {
|
|
1441
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1442
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1443
|
+
type: "request",
|
|
1444
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1445
|
+
id: _uuid.v4.call(void 0, ),
|
|
1446
|
+
method: "droid.submit_mcp_auth_code" /* SUBMIT_MCP_AUTH_CODE */,
|
|
1447
|
+
params
|
|
1448
|
+
};
|
|
1449
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1450
|
+
const response = _chunk4G2RKM2Hjs.SubmitMcpAuthCodeResponseSchema.parse(rawResponse);
|
|
1451
|
+
return response;
|
|
1452
|
+
}
|
|
1453
|
+
async submitMcpAuthError(params) {
|
|
1454
|
+
if (!this.currentSessionId) {
|
|
1455
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1456
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
const request = {
|
|
1460
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1461
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1462
|
+
type: "request",
|
|
1463
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1464
|
+
id: _uuid.v4.call(void 0, ),
|
|
1465
|
+
method: "droid.submit_mcp_auth_error" /* SUBMIT_MCP_AUTH_ERROR */,
|
|
1466
|
+
params
|
|
1467
|
+
};
|
|
1468
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1469
|
+
const response = _chunk4G2RKM2Hjs.SubmitMcpAuthErrorResponseSchema.parse(rawResponse);
|
|
1470
|
+
return response;
|
|
1471
|
+
}
|
|
1472
|
+
async listSkills() {
|
|
1473
|
+
if (!this.currentSessionId) {
|
|
1474
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1475
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
const request = {
|
|
1479
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1480
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1481
|
+
type: "request",
|
|
1482
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1483
|
+
id: _uuid.v4.call(void 0, ),
|
|
1484
|
+
method: "droid.list_skills" /* LIST_SKILLS */,
|
|
1485
|
+
params: {}
|
|
1486
|
+
};
|
|
1487
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1488
|
+
const response = _chunk4G2RKM2Hjs.ListSkillsResponseSchema.parse(rawResponse);
|
|
1489
|
+
return response;
|
|
1490
|
+
}
|
|
1491
|
+
async setSkillDisabled(skillName, disabled, settingsLevel) {
|
|
1492
|
+
if (!this.currentSessionId) {
|
|
1493
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1494
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
const request = {
|
|
1498
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1499
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1500
|
+
type: "request",
|
|
1501
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1502
|
+
id: _uuid.v4.call(void 0, ),
|
|
1503
|
+
method: "droid.set_skill_disabled" /* SET_SKILL_DISABLED */,
|
|
1504
|
+
params: { skillName, disabled, settingsLevel }
|
|
1505
|
+
};
|
|
1506
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1507
|
+
return _chunk4G2RKM2Hjs.SetSkillDisabledResponseSchema.parse(rawResponse);
|
|
1508
|
+
}
|
|
1509
|
+
async listCommands() {
|
|
1510
|
+
if (!this.currentSessionId) {
|
|
1511
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1512
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
const request = {
|
|
1516
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1517
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1518
|
+
type: "request",
|
|
1519
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1520
|
+
id: _uuid.v4.call(void 0, ),
|
|
1521
|
+
method: "droid.list_commands" /* LIST_COMMANDS */,
|
|
1522
|
+
params: {}
|
|
1523
|
+
};
|
|
1524
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1525
|
+
const response = _chunk4G2RKM2Hjs.ListCommandsResponseSchema.parse(rawResponse);
|
|
1526
|
+
return response;
|
|
1527
|
+
}
|
|
1528
|
+
async getContextStats() {
|
|
1529
|
+
if (!this.currentSessionId) {
|
|
1530
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1531
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
const request = {
|
|
1535
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1536
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1537
|
+
type: "request",
|
|
1538
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1539
|
+
id: _uuid.v4.call(void 0, ),
|
|
1540
|
+
method: "droid.get_context_stats" /* GET_CONTEXT_STATS */,
|
|
1541
|
+
params: {}
|
|
1542
|
+
};
|
|
1543
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1544
|
+
const response = _chunk4G2RKM2Hjs.GetContextStatsResponseSchema.parse(rawResponse);
|
|
1545
|
+
return response;
|
|
1546
|
+
}
|
|
1547
|
+
async getContextBreakdown() {
|
|
1548
|
+
if (!this.currentSessionId) {
|
|
1549
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1550
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1551
|
+
);
|
|
1552
|
+
}
|
|
1553
|
+
const request = {
|
|
1554
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1555
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1556
|
+
type: "request",
|
|
1557
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1558
|
+
id: _uuid.v4.call(void 0, ),
|
|
1559
|
+
method: "droid.get_context_breakdown" /* GET_CONTEXT_BREAKDOWN */,
|
|
1560
|
+
params: {}
|
|
1561
|
+
};
|
|
1562
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1563
|
+
const response = _chunk4G2RKM2Hjs.GetContextBreakdownResponseSchema.parse(rawResponse);
|
|
1564
|
+
return response;
|
|
1565
|
+
}
|
|
1566
|
+
async submitBugReport(userComment, clientLogs, source) {
|
|
1567
|
+
if (!this.currentSessionId) {
|
|
1568
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1569
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1570
|
+
);
|
|
1571
|
+
}
|
|
1572
|
+
const request = {
|
|
1573
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1574
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1575
|
+
type: "request",
|
|
1576
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1577
|
+
id: _uuid.v4.call(void 0, ),
|
|
1578
|
+
method: "droid.submit_bug_report" /* SUBMIT_BUG_REPORT */,
|
|
1579
|
+
params: { userComment, clientLogs, source }
|
|
1580
|
+
};
|
|
1581
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1582
|
+
const response = _chunk4G2RKM2Hjs.SubmitBugReportResponseSchema.parse(rawResponse);
|
|
1583
|
+
return response;
|
|
1584
|
+
}
|
|
1585
|
+
async getRewindInfo(params, timeout = this.requestTimeout) {
|
|
1586
|
+
if (!this.currentSessionId) {
|
|
1587
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1588
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1589
|
+
);
|
|
1590
|
+
}
|
|
1591
|
+
const request = {
|
|
1592
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1593
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1594
|
+
type: "request",
|
|
1595
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1596
|
+
id: _uuid.v4.call(void 0, ),
|
|
1597
|
+
method: "droid.get_rewind_info" /* GET_REWIND_INFO */,
|
|
1598
|
+
params: {
|
|
1599
|
+
sessionId: this.currentSessionId,
|
|
1600
|
+
messageId: params.messageId
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
const rawResponse = await this.sendRequest(request, timeout);
|
|
1604
|
+
return _chunk4G2RKM2Hjs.GetRewindInfoResponseSchema.parse(rawResponse);
|
|
1605
|
+
}
|
|
1606
|
+
async executeRewind(params) {
|
|
1607
|
+
if (!this.currentSessionId) {
|
|
1608
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1609
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
const request = {
|
|
1613
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1614
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1615
|
+
type: "request",
|
|
1616
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1617
|
+
id: _uuid.v4.call(void 0, ),
|
|
1618
|
+
method: "droid.execute_rewind" /* EXECUTE_REWIND */,
|
|
1619
|
+
params: {
|
|
1620
|
+
sessionId: this.currentSessionId,
|
|
1621
|
+
messageId: params.messageId,
|
|
1622
|
+
filesToRestore: params.filesToRestore,
|
|
1623
|
+
filesToDelete: params.filesToDelete,
|
|
1624
|
+
forkTitle: params.forkTitle
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
const rawResponse = await this.sendRequest(
|
|
1628
|
+
request,
|
|
1629
|
+
this.requestTimeout * 2
|
|
1630
|
+
);
|
|
1631
|
+
return _chunk4G2RKM2Hjs.ExecuteRewindResponseSchema.parse(rawResponse);
|
|
1632
|
+
}
|
|
1633
|
+
async compactSession(params) {
|
|
1634
|
+
if (!this.currentSessionId) {
|
|
1635
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1636
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1637
|
+
);
|
|
1638
|
+
}
|
|
1639
|
+
const request = {
|
|
1640
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1641
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1642
|
+
type: "request",
|
|
1643
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1644
|
+
id: _uuid.v4.call(void 0, ),
|
|
1645
|
+
method: "droid.compact_session" /* COMPACT_SESSION */,
|
|
1646
|
+
params: {
|
|
1647
|
+
customInstructions: params.customInstructions
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
const rawResponse = await this.sendRequest(request, COMPACTION_TIMEOUT2);
|
|
1651
|
+
return _chunk4G2RKM2Hjs.CompactSessionResponseSchema.parse(rawResponse);
|
|
1652
|
+
}
|
|
1653
|
+
async forkSession(params) {
|
|
1654
|
+
if (!this.currentSessionId) {
|
|
1655
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1656
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
const request = {
|
|
1660
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1661
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1662
|
+
type: "request",
|
|
1663
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1664
|
+
id: _uuid.v4.call(void 0, ),
|
|
1665
|
+
method: "droid.fork_session" /* FORK_SESSION */,
|
|
1666
|
+
params: _nullishCoalesce(params, () => ( {}))
|
|
1667
|
+
};
|
|
1668
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1669
|
+
return _chunk4G2RKM2Hjs.ForkSessionResponseSchema.parse(rawResponse);
|
|
1670
|
+
}
|
|
1671
|
+
async renameSession(params, requestId) {
|
|
1672
|
+
if (!this.currentSessionId) {
|
|
1673
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionError)(
|
|
1674
|
+
"No active session. Call initializeSession or loadSession first."
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
const request = {
|
|
1678
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1679
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1680
|
+
type: "request",
|
|
1681
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1682
|
+
id: _nullishCoalesce(requestId, () => ( _uuid.v4.call(void 0, ))),
|
|
1683
|
+
method: "droid.rename_session" /* RENAME_SESSION */,
|
|
1684
|
+
params: {
|
|
1685
|
+
title: params.title
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
const rawResponse = await this.sendRequest(request, this.requestTimeout);
|
|
1689
|
+
return _chunk4G2RKM2Hjs.RenameSessionResponseSchema.parse(rawResponse);
|
|
1690
|
+
}
|
|
1691
|
+
async warmupCache() {
|
|
1692
|
+
const response = {
|
|
1693
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
1694
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
1695
|
+
type: "response",
|
|
1696
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
1697
|
+
id: _uuid.v4.call(void 0, ),
|
|
1698
|
+
result: {}
|
|
1699
|
+
};
|
|
1700
|
+
return _chunk4G2RKM2Hjs.WarmupCacheResponseSchema.parse(response);
|
|
1701
|
+
}
|
|
1702
|
+
onNotification(callback, filter) {
|
|
1703
|
+
const handler = (notification) => {
|
|
1704
|
+
if (_optionalChain([filter, 'optionalAccess', _13 => _13.type]) !== void 0 && filter.type !== notification.params.notification.type) {
|
|
1705
|
+
return;
|
|
1706
|
+
}
|
|
1707
|
+
try {
|
|
1708
|
+
callback(notification);
|
|
1709
|
+
} catch (e3) {
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
this.on("session_notification" /* SESSION_NOTIFICATION */, handler);
|
|
1713
|
+
return () => this.off("session_notification" /* SESSION_NOTIFICATION */, handler);
|
|
1714
|
+
}
|
|
1715
|
+
onError(callback) {
|
|
1716
|
+
const handler = (error) => {
|
|
1717
|
+
try {
|
|
1718
|
+
callback(error);
|
|
1719
|
+
} catch (e4) {
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
this.on("error" /* ERROR */, handler);
|
|
1723
|
+
if (this.transportError) {
|
|
1724
|
+
handler(this.transportError);
|
|
1725
|
+
}
|
|
1726
|
+
return () => this.off("error" /* ERROR */, handler);
|
|
1727
|
+
}
|
|
1728
|
+
setPermissionHandler(handler) {
|
|
1729
|
+
this.permissionHandlers.set(
|
|
1730
|
+
"default",
|
|
1731
|
+
async (event) => await handler(event)
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
clearPermissionHandler() {
|
|
1735
|
+
this.permissionHandlers.delete("default");
|
|
1736
|
+
}
|
|
1737
|
+
setAskUserHandler(handler) {
|
|
1738
|
+
this.askUserHandlers.set("default", async (event) => await handler(event));
|
|
1739
|
+
}
|
|
1740
|
+
clearAskUserHandler() {
|
|
1741
|
+
this.askUserHandlers.delete("default");
|
|
1742
|
+
}
|
|
1743
|
+
async close() {
|
|
1744
|
+
const closeError = new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
1745
|
+
"Droid client closed: pending requests cancelled"
|
|
1746
|
+
);
|
|
1747
|
+
this.rejectAllPending(closeError);
|
|
1748
|
+
this.permissionHandlers.clear();
|
|
1749
|
+
this.askUserHandlers.clear();
|
|
1750
|
+
this.removeAllListeners();
|
|
1751
|
+
await this.transport.close();
|
|
1752
|
+
}
|
|
1753
|
+
rejectAllPending(error) {
|
|
1754
|
+
this.pendingRequests.forEach(({ timeoutId, reject }, requestId) => {
|
|
1755
|
+
if (timeoutId) {
|
|
1756
|
+
clearTimeout(timeoutId);
|
|
1757
|
+
}
|
|
1758
|
+
reject(error);
|
|
1759
|
+
this.notifyRequestSettled(requestId);
|
|
1760
|
+
});
|
|
1761
|
+
this.pendingRequests.clear();
|
|
1762
|
+
this.pendingPermissionRequests.forEach(({ reject }) => {
|
|
1763
|
+
reject(error);
|
|
1764
|
+
});
|
|
1765
|
+
this.pendingPermissionRequests.clear();
|
|
1766
|
+
this.pendingAskUserRequests.forEach(({ reject }) => {
|
|
1767
|
+
reject(error);
|
|
1768
|
+
});
|
|
1769
|
+
this.pendingAskUserRequests.clear();
|
|
1770
|
+
}
|
|
1771
|
+
settleRequest(requestId) {
|
|
1772
|
+
this.pendingRequests.delete(requestId);
|
|
1773
|
+
this.notifyRequestSettled(requestId);
|
|
1774
|
+
}
|
|
1775
|
+
notifyRequestSettled(requestId) {
|
|
1776
|
+
try {
|
|
1777
|
+
_optionalChain([this, 'access', _14 => _14.onRequestSettled, 'optionalCall', _15 => _15(requestId)]);
|
|
1778
|
+
} catch (e5) {
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
async sendRequest(request, timeout) {
|
|
1782
|
+
if (this.transportError) {
|
|
1783
|
+
throw this.transportError;
|
|
1784
|
+
}
|
|
1785
|
+
const responsePromise = new Promise(
|
|
1786
|
+
(resolve2, reject) => {
|
|
1787
|
+
const timeoutId = timeout ? setTimeout(() => {
|
|
1788
|
+
this.settleRequest(request.id);
|
|
1789
|
+
reject(
|
|
1790
|
+
new (0, _chunk4G2RKM2Hjs.TimeoutError)("Send request timed out", {
|
|
1791
|
+
requestId: request.id,
|
|
1792
|
+
method: request.method,
|
|
1793
|
+
timeout
|
|
1794
|
+
})
|
|
1795
|
+
);
|
|
1796
|
+
}, timeout) : void 0;
|
|
1797
|
+
this.pendingRequests.set(request.id, {
|
|
1798
|
+
method: request.method,
|
|
1799
|
+
resolve: resolve2,
|
|
1800
|
+
reject,
|
|
1801
|
+
timeoutId
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
);
|
|
1805
|
+
const _meta = {};
|
|
1806
|
+
this.tracing.injectContext(_meta, this.tracing.getCurrentContext());
|
|
1807
|
+
const requestWithMeta = _meta.traceparent ? { ...request, _meta } : request;
|
|
1808
|
+
try {
|
|
1809
|
+
this.logger.info("[DroidClient] [daemon -> droid] sending request", {
|
|
1810
|
+
requestId: request.id,
|
|
1811
|
+
method: request.method
|
|
1812
|
+
});
|
|
1813
|
+
await this.transport.send(JSON.stringify(requestWithMeta));
|
|
1814
|
+
} catch (error) {
|
|
1815
|
+
const pending = this.pendingRequests.get(request.id);
|
|
1816
|
+
if (pending) {
|
|
1817
|
+
if (pending.timeoutId) {
|
|
1818
|
+
clearTimeout(pending.timeoutId);
|
|
1819
|
+
}
|
|
1820
|
+
this.settleRequest(request.id);
|
|
1821
|
+
pending.reject(
|
|
1822
|
+
new (0, _chunk4G2RKM2Hjs.ProtocolError)("[daemon -> droid] Failed to send request", {
|
|
1823
|
+
requestId: request.id,
|
|
1824
|
+
cause: error
|
|
1825
|
+
})
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
return responsePromise;
|
|
1830
|
+
}
|
|
1831
|
+
async handleMessage(message) {
|
|
1832
|
+
try {
|
|
1833
|
+
const parsed = JSON.parse(message);
|
|
1834
|
+
if ("result" in parsed || "error" in parsed) {
|
|
1835
|
+
this.handleResponse(parsed);
|
|
1836
|
+
} else if ("method" in parsed) {
|
|
1837
|
+
await this.handleEvent(parsed);
|
|
1838
|
+
} else {
|
|
1839
|
+
throw new (0, _chunk4G2RKM2Hjs.ProtocolError)("Invalid message format", {
|
|
1840
|
+
message
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
} catch (e6) {
|
|
1844
|
+
this.logger.warn("[DroidClient] Failed to handle message", {
|
|
1845
|
+
messageByteLength: new TextEncoder().encode(message).byteLength
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
handleResponse(response) {
|
|
1850
|
+
try {
|
|
1851
|
+
const responseId = getResponseId(response);
|
|
1852
|
+
if (responseId !== null && responseId !== void 0) {
|
|
1853
|
+
const pending = this.pendingRequests.get(responseId);
|
|
1854
|
+
if (pending) {
|
|
1855
|
+
let validatedResponse;
|
|
1856
|
+
switch (pending.method) {
|
|
1857
|
+
case "droid.initialize_session" /* INITIALIZE_SESSION */:
|
|
1858
|
+
validatedResponse = _chunk4G2RKM2Hjs.InitializeSessionResponseSchema.parse(response);
|
|
1859
|
+
break;
|
|
1860
|
+
case "droid.load_session" /* LOAD_SESSION */:
|
|
1861
|
+
validatedResponse = _chunk4G2RKM2Hjs.LoadSessionResponseSchema.parse(response);
|
|
1862
|
+
break;
|
|
1863
|
+
case "droid.add_user_message" /* ADD_USER_MESSAGE */:
|
|
1864
|
+
validatedResponse = _chunk4G2RKM2Hjs.AddUserMessageResponseSchema.parse(response);
|
|
1865
|
+
break;
|
|
1866
|
+
case "droid.append_messages" /* APPEND_MESSAGES */:
|
|
1867
|
+
validatedResponse = _chunk4G2RKM2Hjs.AppendMessagesResponseSchema.parse(response);
|
|
1868
|
+
break;
|
|
1869
|
+
case "droid.resolve_queued_user_message" /* RESOLVE_QUEUED_USER_MESSAGE */:
|
|
1870
|
+
validatedResponse = _chunk4G2RKM2Hjs.ResolveQueuedUserMessageResponseSchema.parse(response);
|
|
1871
|
+
break;
|
|
1872
|
+
case "droid.interrupt_session" /* INTERRUPT_SESSION */:
|
|
1873
|
+
validatedResponse = _chunk4G2RKM2Hjs.InterruptSessionResponseSchema.parse(response);
|
|
1874
|
+
break;
|
|
1875
|
+
case "droid.close_session" /* CLOSE_SESSION */:
|
|
1876
|
+
validatedResponse = _chunk4G2RKM2Hjs.CloseSessionResponseSchema.parse(response);
|
|
1877
|
+
break;
|
|
1878
|
+
case "droid.update_session_settings" /* UPDATE_SESSION_SETTINGS */:
|
|
1879
|
+
validatedResponse = _chunk4G2RKM2Hjs.UpdateSessionSettingsResponseSchema.parse(response);
|
|
1880
|
+
break;
|
|
1881
|
+
case "droid.change_working_directory" /* CHANGE_WORKING_DIRECTORY */:
|
|
1882
|
+
validatedResponse = _chunk4G2RKM2Hjs.ChangeWorkingDirectoryResponseSchema.parse(response);
|
|
1883
|
+
break;
|
|
1884
|
+
case "droid.toggle_mcp_server" /* TOGGLE_MCP_SERVER */:
|
|
1885
|
+
validatedResponse = _chunk4G2RKM2Hjs.ToggleMcpServerResponseSchema.parse(response);
|
|
1886
|
+
break;
|
|
1887
|
+
case "droid.authenticate_mcp_server" /* AUTHENTICATE_MCP_SERVER */:
|
|
1888
|
+
validatedResponse = _chunk4G2RKM2Hjs.AuthenticateMcpServerResponseSchema.parse(response);
|
|
1889
|
+
break;
|
|
1890
|
+
case "droid.cancel_mcp_auth" /* CANCEL_MCP_AUTH */:
|
|
1891
|
+
validatedResponse = _chunk4G2RKM2Hjs.CancelMcpAuthResponseSchema.parse(response);
|
|
1892
|
+
break;
|
|
1893
|
+
case "droid.clear_mcp_auth" /* CLEAR_MCP_AUTH */:
|
|
1894
|
+
validatedResponse = _chunk4G2RKM2Hjs.ClearMcpAuthResponseSchema.parse(response);
|
|
1895
|
+
break;
|
|
1896
|
+
case "droid.add_mcp_server" /* ADD_MCP_SERVER */:
|
|
1897
|
+
validatedResponse = _chunk4G2RKM2Hjs.AddMcpServerResponseSchema.parse(response);
|
|
1898
|
+
break;
|
|
1899
|
+
case "droid.remove_mcp_server" /* REMOVE_MCP_SERVER */:
|
|
1900
|
+
validatedResponse = _chunk4G2RKM2Hjs.RemoveMcpServerResponseSchema.parse(response);
|
|
1901
|
+
break;
|
|
1902
|
+
case "droid.list_models" /* LIST_MODELS */:
|
|
1903
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListModelsResponseSchema.parse(response);
|
|
1904
|
+
break;
|
|
1905
|
+
case "droid.list_mcp_registry" /* LIST_MCP_REGISTRY */:
|
|
1906
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListMcpRegistryResponseSchema.parse(response);
|
|
1907
|
+
break;
|
|
1908
|
+
case "droid.list_mcp_tools" /* LIST_MCP_TOOLS */:
|
|
1909
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListMcpToolsResponseSchema.parse(response);
|
|
1910
|
+
break;
|
|
1911
|
+
case "droid.list_tools" /* LIST_TOOLS */:
|
|
1912
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListToolsResponseSchema.parse(response);
|
|
1913
|
+
break;
|
|
1914
|
+
case "droid.toggle_mcp_tool" /* TOGGLE_MCP_TOOL */:
|
|
1915
|
+
validatedResponse = _chunk4G2RKM2Hjs.ToggleMcpToolResponseSchema.parse(response);
|
|
1916
|
+
break;
|
|
1917
|
+
case "droid.submit_mcp_auth_code" /* SUBMIT_MCP_AUTH_CODE */:
|
|
1918
|
+
validatedResponse = _chunk4G2RKM2Hjs.SubmitMcpAuthCodeResponseSchema.parse(response);
|
|
1919
|
+
break;
|
|
1920
|
+
case "droid.submit_mcp_auth_error" /* SUBMIT_MCP_AUTH_ERROR */:
|
|
1921
|
+
validatedResponse = _chunk4G2RKM2Hjs.SubmitMcpAuthErrorResponseSchema.parse(response);
|
|
1922
|
+
break;
|
|
1923
|
+
case "droid.kill_worker_session" /* KILL_WORKER_SESSION */:
|
|
1924
|
+
validatedResponse = _chunk4G2RKM2Hjs.KillWorkerSessionResponseSchema.parse(response);
|
|
1925
|
+
break;
|
|
1926
|
+
case "droid.list_skills" /* LIST_SKILLS */:
|
|
1927
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListSkillsResponseSchema.parse(response);
|
|
1928
|
+
break;
|
|
1929
|
+
case "droid.set_skill_disabled" /* SET_SKILL_DISABLED */:
|
|
1930
|
+
validatedResponse = _chunk4G2RKM2Hjs.SetSkillDisabledResponseSchema.parse(response);
|
|
1931
|
+
break;
|
|
1932
|
+
case "droid.list_commands" /* LIST_COMMANDS */:
|
|
1933
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListCommandsResponseSchema.parse(response);
|
|
1934
|
+
break;
|
|
1935
|
+
case "droid.submit_bug_report" /* SUBMIT_BUG_REPORT */:
|
|
1936
|
+
validatedResponse = _chunk4G2RKM2Hjs.SubmitBugReportResponseSchema.parse(response);
|
|
1937
|
+
break;
|
|
1938
|
+
case "droid.list_mcp_servers" /* LIST_MCP_SERVERS */:
|
|
1939
|
+
validatedResponse = _chunk4G2RKM2Hjs.ListMcpServersResponseSchema.parse(response);
|
|
1940
|
+
break;
|
|
1941
|
+
case "droid.get_rewind_info" /* GET_REWIND_INFO */:
|
|
1942
|
+
validatedResponse = _chunk4G2RKM2Hjs.GetRewindInfoResponseSchema.parse(response);
|
|
1943
|
+
break;
|
|
1944
|
+
case "droid.execute_rewind" /* EXECUTE_REWIND */:
|
|
1945
|
+
validatedResponse = _chunk4G2RKM2Hjs.ExecuteRewindResponseSchema.parse(response);
|
|
1946
|
+
break;
|
|
1947
|
+
case "droid.compact_session" /* COMPACT_SESSION */:
|
|
1948
|
+
validatedResponse = _chunk4G2RKM2Hjs.CompactSessionResponseSchema.parse(response);
|
|
1949
|
+
break;
|
|
1950
|
+
case "droid.fork_session" /* FORK_SESSION */:
|
|
1951
|
+
validatedResponse = _chunk4G2RKM2Hjs.ForkSessionResponseSchema.parse(response);
|
|
1952
|
+
break;
|
|
1953
|
+
case "droid.rename_session" /* RENAME_SESSION */:
|
|
1954
|
+
validatedResponse = _chunk4G2RKM2Hjs.RenameSessionResponseSchema.parse(response);
|
|
1955
|
+
break;
|
|
1956
|
+
case "droid.get_context_stats" /* GET_CONTEXT_STATS */:
|
|
1957
|
+
validatedResponse = _chunk4G2RKM2Hjs.GetContextStatsResponseSchema.parse(response);
|
|
1958
|
+
break;
|
|
1959
|
+
case "droid.get_context_breakdown" /* GET_CONTEXT_BREAKDOWN */:
|
|
1960
|
+
validatedResponse = _chunk4G2RKM2Hjs.GetContextBreakdownResponseSchema.parse(response);
|
|
1961
|
+
break;
|
|
1962
|
+
case "droid.warmup_cache" /* WARMUP_CACHE */:
|
|
1963
|
+
validatedResponse = _chunk4G2RKM2Hjs.WarmupCacheResponseSchema.parse(response);
|
|
1964
|
+
break;
|
|
1965
|
+
default: {
|
|
1966
|
+
const exhaustiveCheck = pending.method;
|
|
1967
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
1968
|
+
"Unsupported method in response handler",
|
|
1969
|
+
{
|
|
1970
|
+
method: exhaustiveCheck
|
|
1971
|
+
}
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (pending.timeoutId) {
|
|
1976
|
+
clearTimeout(pending.timeoutId);
|
|
1977
|
+
}
|
|
1978
|
+
this.settleRequest(responseId);
|
|
1979
|
+
pending.resolve(validatedResponse);
|
|
1980
|
+
} else {
|
|
1981
|
+
const validatedResponse = _chunk4G2RKM2Hjs.JsonRpcBaseResponseSchema.parse(response);
|
|
1982
|
+
this.logger.info(
|
|
1983
|
+
"[DroidClient] Received response for request not in pending map",
|
|
1984
|
+
{
|
|
1985
|
+
requestId: _nullishCoalesce(validatedResponse.id, () => ( void 0))
|
|
1986
|
+
}
|
|
1987
|
+
);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
} catch (error) {
|
|
1991
|
+
const responseId = getResponseId(response);
|
|
1992
|
+
const pending = responseId !== null && responseId !== void 0 ? this.pendingRequests.get(responseId) : void 0;
|
|
1993
|
+
const zodIssues = error instanceof _zod.z.ZodError ? error.issues.map((issue) => ({
|
|
1994
|
+
path: issue.path,
|
|
1995
|
+
code: issue.code,
|
|
1996
|
+
message: issue.message
|
|
1997
|
+
})) : void 0;
|
|
1998
|
+
this.logger.exception(error, "Invalid response format", {
|
|
1999
|
+
method: _optionalChain([pending, 'optionalAccess', _16 => _16.method]),
|
|
2000
|
+
requestId: _nullishCoalesce(responseId, () => ( void 0)),
|
|
2001
|
+
zodIssues
|
|
2002
|
+
});
|
|
2003
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2004
|
+
const code = error instanceof _zod.z.ZodError ? -32700 /* PARSE_ERROR */ : -32603 /* INTERNAL_ERROR */;
|
|
2005
|
+
const message = code === -32700 /* PARSE_ERROR */ ? "Invalid response format" : "Internal error while handling response";
|
|
2006
|
+
if (responseId === null || responseId === void 0) {
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
if (!pending) {
|
|
2010
|
+
this.logger.info(
|
|
2011
|
+
"[DroidClient] Dropping unhandleable response with no pending request",
|
|
2012
|
+
{
|
|
2013
|
+
requestId: responseId,
|
|
2014
|
+
code,
|
|
2015
|
+
message: err.message
|
|
2016
|
+
}
|
|
2017
|
+
);
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
if (pending.timeoutId) {
|
|
2021
|
+
clearTimeout(pending.timeoutId);
|
|
2022
|
+
}
|
|
2023
|
+
this.settleRequest(responseId);
|
|
2024
|
+
const syntheticFailure = {
|
|
2025
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2026
|
+
type: "response",
|
|
2027
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2028
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2029
|
+
id: responseId,
|
|
2030
|
+
error: {
|
|
2031
|
+
code,
|
|
2032
|
+
message,
|
|
2033
|
+
data: err.message
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
pending.resolve(syntheticFailure);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
async handleEvent(event) {
|
|
2040
|
+
try {
|
|
2041
|
+
const validatedEvent = _chunk4G2RKM2Hjs.CliRequestOrNotificationSchema.parse(event);
|
|
2042
|
+
if (validatedEvent.method === "droid.session_notification" /* SESSION_NOTIFICATION */) {
|
|
2043
|
+
const notification = validatedEvent.params.notification;
|
|
2044
|
+
if (notification.type === "agent_turn_completed" /* AGENT_TURN_COMPLETED */) {
|
|
2045
|
+
this.completedTurnObserved = true;
|
|
2046
|
+
} else if (notification.type === "droid_working_state_changed" /* DROID_WORKING_STATE_CHANGED */ && notification.newState !== "idle" /* Idle */) {
|
|
2047
|
+
this.completedTurnObserved = false;
|
|
2048
|
+
}
|
|
2049
|
+
this.emit("session_notification" /* SESSION_NOTIFICATION */, validatedEvent);
|
|
2050
|
+
} else if (validatedEvent.method === "droid.request_permission" /* REQUEST_PERMISSION */) {
|
|
2051
|
+
await this.handlePermissionRequest(validatedEvent);
|
|
2052
|
+
} else if (validatedEvent.method === "droid.ask_user" /* ASK_USER */) {
|
|
2053
|
+
await this.handleAskUserRequest(validatedEvent);
|
|
2054
|
+
}
|
|
2055
|
+
} catch (error) {
|
|
2056
|
+
this.logDroppedEventParseError(error, event);
|
|
2057
|
+
await this.replyWithParseFailureIfRequest(error, event);
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* When an incoming CLI->client request fails to parse, send back a
|
|
2062
|
+
* structurally valid JsonRpcBaseResponseFailure so the peer's pending
|
|
2063
|
+
* request doesn't hang. No-ops for notifications (no id to reply on)
|
|
2064
|
+
* or events we can't correlate.
|
|
2065
|
+
*/
|
|
2066
|
+
async replyWithParseFailureIfRequest(error, event) {
|
|
2067
|
+
const type = _DroidClient.getNestedString(event, ["type"]);
|
|
2068
|
+
const id = _DroidClient.getNestedString(event, ["id"]);
|
|
2069
|
+
if (type !== "request" || !id) {
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2073
|
+
const code = error instanceof _zod.z.ZodError ? -32600 /* INVALID_REQUEST */ : -32603 /* INTERNAL_ERROR */;
|
|
2074
|
+
const message = code === -32600 /* INVALID_REQUEST */ ? "Invalid request format" : "Internal error while handling request";
|
|
2075
|
+
const errorResponse = {
|
|
2076
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2077
|
+
type: "response",
|
|
2078
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2079
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2080
|
+
id,
|
|
2081
|
+
error: {
|
|
2082
|
+
code,
|
|
2083
|
+
message,
|
|
2084
|
+
data: err.message
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
try {
|
|
2088
|
+
await this.transport.send(JSON.stringify(errorResponse));
|
|
2089
|
+
} catch (sendError) {
|
|
2090
|
+
this.logger.exception(
|
|
2091
|
+
sendError,
|
|
2092
|
+
"Failed to send parse-failure response back to peer"
|
|
2093
|
+
);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Invariant: parsing failures for incoming events (notifications or
|
|
2098
|
+
* server-initiated requests) must NEVER surface as user-visible ERROR
|
|
2099
|
+
* notifications. Version skew, unknown inner enum values, missing
|
|
2100
|
+
* fields, or malformed shapes all degrade to a log-and-drop so the
|
|
2101
|
+
* session continues quietly instead of flashing a synthetic error on
|
|
2102
|
+
* every
|
|
2103
|
+
*/
|
|
2104
|
+
logDroppedEventParseError(error, event) {
|
|
2105
|
+
const { protocolVersionMismatch } = inspectJsonRpcEnvelope2(event);
|
|
2106
|
+
const method = _DroidClient.getNestedString(event, ["method"]);
|
|
2107
|
+
const notificationType = _DroidClient.getNestedString(event, [
|
|
2108
|
+
"params",
|
|
2109
|
+
"notification",
|
|
2110
|
+
"type"
|
|
2111
|
+
]);
|
|
2112
|
+
const sessionId = _nullishCoalesce(this.currentSessionId, () => ( _DroidClient.getNestedString(event, ["params", "sessionId"])));
|
|
2113
|
+
const meta = {
|
|
2114
|
+
value: {
|
|
2115
|
+
method: _nullishCoalesce(method, () => ( void 0)),
|
|
2116
|
+
notificationType: _nullishCoalesce(notificationType, () => ( void 0)),
|
|
2117
|
+
protocolVersionMismatch: _nullishCoalesce(protocolVersionMismatch, () => ( void 0)),
|
|
2118
|
+
sessionId: _nullishCoalesce(sessionId, () => ( void 0))
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
if (protocolVersionMismatch) {
|
|
2122
|
+
this.logger.info(
|
|
2123
|
+
"[DroidClient] Dropping unsupported event from newer peer",
|
|
2124
|
+
meta
|
|
2125
|
+
);
|
|
2126
|
+
} else {
|
|
2127
|
+
this.logger.warn("[DroidClient] Dropping malformed event", {
|
|
2128
|
+
...meta,
|
|
2129
|
+
cause: error
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
async handlePermissionRequest(event) {
|
|
2134
|
+
if (this.pendingPermissionRequests.has(event.id)) {
|
|
2135
|
+
this.logger.info(
|
|
2136
|
+
"[DroidClient] Ignoring duplicate pending permission request",
|
|
2137
|
+
{
|
|
2138
|
+
requestId: event.id
|
|
2139
|
+
}
|
|
2140
|
+
);
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
this.logger.info("[DroidClient] Handling permission request", {
|
|
2144
|
+
requestId: event.id,
|
|
2145
|
+
toolCount: event.params.toolUses.length
|
|
2146
|
+
});
|
|
2147
|
+
this.emit("request_permission" /* REQUEST_PERMISSION */, event);
|
|
2148
|
+
let selectedOption = "cancel" /* Cancel */;
|
|
2149
|
+
let comment;
|
|
2150
|
+
let editedSpecContent;
|
|
2151
|
+
const handler = this.permissionHandlers.get("default");
|
|
2152
|
+
if (handler) {
|
|
2153
|
+
try {
|
|
2154
|
+
this.logger.info(
|
|
2155
|
+
"[DroidClient] Waiting for permission handler to resolve",
|
|
2156
|
+
{
|
|
2157
|
+
requestId: event.id
|
|
2158
|
+
}
|
|
2159
|
+
);
|
|
2160
|
+
const handlerPromise = new Promise(
|
|
2161
|
+
(resolve2, reject) => {
|
|
2162
|
+
this.pendingPermissionRequests.set(event.id, { reject });
|
|
2163
|
+
handler(event).then(resolve2).catch(reject).finally(() => {
|
|
2164
|
+
this.pendingPermissionRequests.delete(event.id);
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
);
|
|
2168
|
+
const handlerResult = await handlerPromise;
|
|
2169
|
+
if (typeof handlerResult === "string" && handlerResult === "proceed_edit" /* ProceedEdit */) {
|
|
2170
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
2171
|
+
"Permission handler returned proceed_edit without editedSpecContent"
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
const parsedHandlerResult = _chunk4G2RKM2Hjs.RequestPermissionResultSchema.safeParse(
|
|
2175
|
+
typeof handlerResult === "string" ? { selectedOption: handlerResult } : handlerResult
|
|
2176
|
+
);
|
|
2177
|
+
if (parsedHandlerResult.success) {
|
|
2178
|
+
selectedOption = parsedHandlerResult.data.selectedOption;
|
|
2179
|
+
comment = parsedHandlerResult.data.comment;
|
|
2180
|
+
editedSpecContent = parsedHandlerResult.data.editedSpecContent;
|
|
2181
|
+
} else {
|
|
2182
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
2183
|
+
"Permission handler returned invalid result",
|
|
2184
|
+
{
|
|
2185
|
+
cause: parsedHandlerResult.error
|
|
2186
|
+
}
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
if (!event.params.options.some(
|
|
2190
|
+
(option) => option.value === selectedOption
|
|
2191
|
+
)) {
|
|
2192
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
2193
|
+
`Permission handler selected unavailable option: ${selectedOption}`
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
this.logger.info("[DroidClient] Permission handler resolved", {
|
|
2197
|
+
requestId: event.id,
|
|
2198
|
+
result: selectedOption
|
|
2199
|
+
});
|
|
2200
|
+
} catch (error) {
|
|
2201
|
+
this.logger.exception(
|
|
2202
|
+
error,
|
|
2203
|
+
"Failed to handle permission request (processing)"
|
|
2204
|
+
);
|
|
2205
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2206
|
+
this.emit(
|
|
2207
|
+
"session_notification" /* SESSION_NOTIFICATION */,
|
|
2208
|
+
_DroidClient.createNotificationEvent(
|
|
2209
|
+
_DroidClient.createErrorNotification(err)
|
|
2210
|
+
)
|
|
2211
|
+
);
|
|
2212
|
+
this.pendingPermissionRequests.delete(event.id);
|
|
2213
|
+
const cancelResponse = {
|
|
2214
|
+
type: "response",
|
|
2215
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2216
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2217
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2218
|
+
id: event.id,
|
|
2219
|
+
result: {
|
|
2220
|
+
selectedOption: "cancel" /* Cancel */
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
try {
|
|
2224
|
+
await this.transport.send(JSON.stringify(cancelResponse));
|
|
2225
|
+
} catch (sendError) {
|
|
2226
|
+
this.logger.exception(
|
|
2227
|
+
sendError,
|
|
2228
|
+
"Failed to handle permission request (send cancellation)"
|
|
2229
|
+
);
|
|
2230
|
+
const sendErr = sendError instanceof Error ? sendError : new Error(String(sendError));
|
|
2231
|
+
this.emit(
|
|
2232
|
+
"session_notification" /* SESSION_NOTIFICATION */,
|
|
2233
|
+
_DroidClient.createNotificationEvent(
|
|
2234
|
+
_DroidClient.createErrorNotification(sendErr)
|
|
2235
|
+
)
|
|
2236
|
+
);
|
|
2237
|
+
}
|
|
2238
|
+
return;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
const response = {
|
|
2242
|
+
type: "response",
|
|
2243
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2244
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2245
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2246
|
+
id: event.id,
|
|
2247
|
+
result: {
|
|
2248
|
+
selectedOption,
|
|
2249
|
+
...comment !== void 0 && { comment },
|
|
2250
|
+
...editedSpecContent !== void 0 && { editedSpecContent }
|
|
2251
|
+
}
|
|
2252
|
+
};
|
|
2253
|
+
this.logger.info("[DroidClient] Sending permission response back to CLI", {
|
|
2254
|
+
requestId: event.id,
|
|
2255
|
+
result: String(selectedOption)
|
|
2256
|
+
});
|
|
2257
|
+
await this.transport.send(JSON.stringify(response));
|
|
2258
|
+
}
|
|
2259
|
+
async handleAskUserRequest(event) {
|
|
2260
|
+
this.logger.info("[DroidClient] Handling ask-user request", {
|
|
2261
|
+
requestId: event.id,
|
|
2262
|
+
toolCallId: event.params.toolCallId,
|
|
2263
|
+
questionCount: event.params.questions.length
|
|
2264
|
+
});
|
|
2265
|
+
this.emit("ask_user" /* ASK_USER */, event);
|
|
2266
|
+
let result = { cancelled: true, answers: [] };
|
|
2267
|
+
const handler = this.askUserHandlers.get("default");
|
|
2268
|
+
if (handler) {
|
|
2269
|
+
try {
|
|
2270
|
+
this.logger.info(
|
|
2271
|
+
"[DroidClient] Waiting for ask-user handler to resolve",
|
|
2272
|
+
{
|
|
2273
|
+
requestId: event.id
|
|
2274
|
+
}
|
|
2275
|
+
);
|
|
2276
|
+
const handlerPromise = new Promise((resolve2, reject) => {
|
|
2277
|
+
this.pendingAskUserRequests.set(event.id, { reject });
|
|
2278
|
+
handler(event).then(resolve2).catch(reject).finally(() => {
|
|
2279
|
+
this.pendingAskUserRequests.delete(event.id);
|
|
2280
|
+
});
|
|
2281
|
+
});
|
|
2282
|
+
const parsedResult = _chunk4G2RKM2Hjs.AskUserResultSchema.safeParse(
|
|
2283
|
+
await handlerPromise
|
|
2284
|
+
);
|
|
2285
|
+
if (!parsedResult.success) {
|
|
2286
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
2287
|
+
"AskUser handler returned invalid result",
|
|
2288
|
+
{
|
|
2289
|
+
cause: parsedResult.error
|
|
2290
|
+
}
|
|
2291
|
+
);
|
|
2292
|
+
}
|
|
2293
|
+
result = parsedResult.data;
|
|
2294
|
+
this.logger.info("[DroidClient] Ask-user handler resolved", {
|
|
2295
|
+
requestId: event.id,
|
|
2296
|
+
cancelled: _nullishCoalesce(result.cancelled, () => ( false)),
|
|
2297
|
+
answerCount: result.answers.length
|
|
2298
|
+
});
|
|
2299
|
+
} catch (error) {
|
|
2300
|
+
this.logger.exception(error, "Failed to handle ask-user request");
|
|
2301
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2302
|
+
this.emit(
|
|
2303
|
+
"session_notification" /* SESSION_NOTIFICATION */,
|
|
2304
|
+
_DroidClient.createNotificationEvent(
|
|
2305
|
+
_DroidClient.createErrorNotification(err)
|
|
2306
|
+
)
|
|
2307
|
+
);
|
|
2308
|
+
this.pendingAskUserRequests.delete(event.id);
|
|
2309
|
+
const cancelResponse = {
|
|
2310
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2311
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2312
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2313
|
+
type: "response",
|
|
2314
|
+
id: event.id,
|
|
2315
|
+
result: {
|
|
2316
|
+
cancelled: true,
|
|
2317
|
+
answers: []
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
try {
|
|
2321
|
+
await this.transport.send(JSON.stringify(cancelResponse));
|
|
2322
|
+
} catch (sendError) {
|
|
2323
|
+
this.logger.exception(
|
|
2324
|
+
sendError,
|
|
2325
|
+
"Failed to send ask-user cancellation"
|
|
2326
|
+
);
|
|
2327
|
+
}
|
|
2328
|
+
return;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
const response = {
|
|
2332
|
+
type: "response",
|
|
2333
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2334
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2335
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2336
|
+
id: event.id,
|
|
2337
|
+
result
|
|
2338
|
+
};
|
|
2339
|
+
this.logger.info("[DroidClient] Sending ask-user response back to CLI", {
|
|
2340
|
+
requestId: event.id,
|
|
2341
|
+
cancelled: _nullishCoalesce(result.cancelled, () => ( false))
|
|
2342
|
+
});
|
|
2343
|
+
await this.transport.send(JSON.stringify(response));
|
|
2344
|
+
}
|
|
2345
|
+
static getErrorType(error) {
|
|
2346
|
+
switch (error.constructor) {
|
|
2347
|
+
case _chunk4G2RKM2Hjs.ConnectionError:
|
|
2348
|
+
return "ConnectionError" /* CONNECTION_ERROR */;
|
|
2349
|
+
case _chunk4G2RKM2Hjs.ProtocolError:
|
|
2350
|
+
return "ProtocolError" /* PROTOCOL_ERROR */;
|
|
2351
|
+
case _chunk4G2RKM2Hjs.SessionError:
|
|
2352
|
+
return "SessionError" /* SESSION_ERROR */;
|
|
2353
|
+
case _chunk4G2RKM2Hjs.TimeoutError:
|
|
2354
|
+
return "TimeoutError" /* TIMEOUT_ERROR */;
|
|
2355
|
+
case _chunk4G2RKM2Hjs.ProcessExitError:
|
|
2356
|
+
return "ProcessExitError" /* PROCESS_EXIT_ERROR */;
|
|
2357
|
+
case _chunk4G2RKM2Hjs.DroidClientError:
|
|
2358
|
+
return "DroidClientError" /* DROID_CLIENT_ERROR */;
|
|
2359
|
+
default:
|
|
2360
|
+
return "Error" /* ERROR */;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
static createErrorNotification(error) {
|
|
2364
|
+
return {
|
|
2365
|
+
type: "error" /* ERROR */,
|
|
2366
|
+
message: error.message,
|
|
2367
|
+
errorType: _DroidClient.getErrorType(error),
|
|
2368
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2369
|
+
...error instanceof _chunk4G2RKM2Hjs.ProcessExitError && error.exitCode !== void 0 ? { exitCode: error.exitCode } : {},
|
|
2370
|
+
error: {
|
|
2371
|
+
name: error.name,
|
|
2372
|
+
message: error.message
|
|
2373
|
+
}
|
|
2374
|
+
};
|
|
2375
|
+
}
|
|
2376
|
+
static getNestedString(value, path3) {
|
|
2377
|
+
let current = value;
|
|
2378
|
+
for (const key of path3) {
|
|
2379
|
+
if (!_DroidClient.isRecord(current)) {
|
|
2380
|
+
return null;
|
|
2381
|
+
}
|
|
2382
|
+
current = current[key];
|
|
2383
|
+
}
|
|
2384
|
+
return typeof current === "string" ? current : null;
|
|
2385
|
+
}
|
|
2386
|
+
static isRecord(value) {
|
|
2387
|
+
return typeof value === "object" && value !== null;
|
|
2388
|
+
}
|
|
2389
|
+
/**
|
|
2390
|
+
* Create a full SessionNotificationEvent for locally-generated notifications.
|
|
2391
|
+
* Used when the SDK needs to emit error notifications that weren't received from the CLI.
|
|
2392
|
+
*/
|
|
2393
|
+
static createNotificationEvent(notification) {
|
|
2394
|
+
return {
|
|
2395
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION2,
|
|
2396
|
+
type: "notification",
|
|
2397
|
+
factoryApiVersion: _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION,
|
|
2398
|
+
factoryProtocolVersion: _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION,
|
|
2399
|
+
method: "droid.session_notification" /* SESSION_NOTIFICATION */,
|
|
2400
|
+
params: { notification }
|
|
2401
|
+
};
|
|
2402
|
+
}
|
|
2403
|
+
}, _class);
|
|
2404
|
+
|
|
2405
|
+
// src/exec-core/managed-process.ts
|
|
2406
|
+
var _child_process = require('child_process');
|
|
2407
|
+
var _fs = require('fs'); var fs3 = _interopRequireWildcard(_fs);
|
|
2408
|
+
var _readline = require('readline'); var readline = _interopRequireWildcard(_readline);
|
|
2409
|
+
|
|
2410
|
+
// src/exec-core/runtime-utils.ts
|
|
2411
|
+
var _os = require('os'); var os = _interopRequireWildcard(_os);
|
|
2412
|
+
var _path = require('path'); var path2 = _interopRequireWildcard(_path);
|
|
2413
|
+
function isErrnoException(error) {
|
|
2414
|
+
return error !== null && typeof error === "object" && "code" in error && typeof error.code === "string";
|
|
2415
|
+
}
|
|
2416
|
+
function expandTilde(filepath) {
|
|
2417
|
+
if (!filepath) {
|
|
2418
|
+
return filepath;
|
|
2419
|
+
}
|
|
2420
|
+
if (filepath === "~") {
|
|
2421
|
+
return _os.homedir.call(void 0, );
|
|
2422
|
+
}
|
|
2423
|
+
if (filepath.startsWith("~/") || filepath.startsWith("~\\")) {
|
|
2424
|
+
return _path.join.call(void 0, _os.homedir.call(void 0, ), filepath.slice(2));
|
|
2425
|
+
}
|
|
2426
|
+
return filepath;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// src/exec-core/transport-logger.ts
|
|
2430
|
+
|
|
2431
|
+
|
|
2432
|
+
var LOG_FILE_NAME = "droid-transport.log";
|
|
2433
|
+
var LOG_DIR_MODE = 448;
|
|
2434
|
+
var LOG_FILE_MODE = 384;
|
|
2435
|
+
var state = null;
|
|
2436
|
+
var enabledCache = null;
|
|
2437
|
+
var HOST_PID_TAG = `host_pid=${process.pid}`;
|
|
2438
|
+
function isTruthy(value) {
|
|
2439
|
+
const v = value.trim().toLowerCase();
|
|
2440
|
+
return v !== "" && v !== "0" && v !== "false" && v !== "off" && v !== "no";
|
|
2441
|
+
}
|
|
2442
|
+
function directionMarker(direction) {
|
|
2443
|
+
switch (direction) {
|
|
2444
|
+
case "in" /* In */:
|
|
2445
|
+
return "IN ";
|
|
2446
|
+
case "out" /* Out */:
|
|
2447
|
+
return "OUT";
|
|
2448
|
+
case "out_failed" /* OutFailed */:
|
|
2449
|
+
return "OUT!";
|
|
2450
|
+
default:
|
|
2451
|
+
return "???";
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
function isTransportLoggingEnabled(deps = defaultExecCoreDeps) {
|
|
2455
|
+
if (enabledCache !== null) return enabledCache;
|
|
2456
|
+
enabledCache = isTruthy(
|
|
2457
|
+
_nullishCoalesce(deps.environmentResolver.resolveTransportLogEnvValue(), () => ( ""))
|
|
2458
|
+
);
|
|
2459
|
+
return enabledCache;
|
|
2460
|
+
}
|
|
2461
|
+
function looksLikePath(value) {
|
|
2462
|
+
return path2.default.isAbsolute(value) || value.startsWith("~") || value.startsWith("./") || value.startsWith("../") || value.startsWith(".\\") || value.startsWith("..\\") || value.includes("/") || value.includes("\\");
|
|
2463
|
+
}
|
|
2464
|
+
function resolveLogPath(deps) {
|
|
2465
|
+
const envValue = deps.environmentResolver.resolveTransportLogEnvValue();
|
|
2466
|
+
const pathResolver = deps.factoryPathResolver;
|
|
2467
|
+
if (envValue && looksLikePath(envValue)) {
|
|
2468
|
+
if (envValue === "~" || envValue.startsWith("~/") || envValue.startsWith("~\\")) {
|
|
2469
|
+
const rest = envValue.slice(2);
|
|
2470
|
+
const home = pathResolver.getFactoryHome();
|
|
2471
|
+
return rest ? path2.default.join(home, rest) : home;
|
|
2472
|
+
}
|
|
2473
|
+
return envValue;
|
|
2474
|
+
}
|
|
2475
|
+
return path2.default.join(
|
|
2476
|
+
pathResolver.getFactoryHome(),
|
|
2477
|
+
pathResolver.getFactoryDirName(),
|
|
2478
|
+
"logs",
|
|
2479
|
+
LOG_FILE_NAME
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
function initState(deps) {
|
|
2483
|
+
const result = { stream: null, failed: false };
|
|
2484
|
+
try {
|
|
2485
|
+
const logPath = resolveLogPath(deps);
|
|
2486
|
+
const logsDir = path2.default.dirname(logPath);
|
|
2487
|
+
const logsDirExisted = fs3.default.existsSync(logsDir);
|
|
2488
|
+
if (!logsDirExisted) {
|
|
2489
|
+
fs3.default.mkdirSync(logsDir, { recursive: true, mode: LOG_DIR_MODE });
|
|
2490
|
+
}
|
|
2491
|
+
if (process.platform !== "win32" && !logsDirExisted) {
|
|
2492
|
+
try {
|
|
2493
|
+
fs3.default.chmodSync(logsDir, LOG_DIR_MODE);
|
|
2494
|
+
} catch (chmodError) {
|
|
2495
|
+
logWarn(
|
|
2496
|
+
deps.logger,
|
|
2497
|
+
"[droid-sdk transport-logger] failed to chmod logs dir",
|
|
2498
|
+
{
|
|
2499
|
+
cause: chmodError
|
|
2500
|
+
}
|
|
2501
|
+
);
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
const stream = fs3.default.createWriteStream(logPath, {
|
|
2505
|
+
flags: "a",
|
|
2506
|
+
encoding: "utf8",
|
|
2507
|
+
mode: LOG_FILE_MODE
|
|
2508
|
+
});
|
|
2509
|
+
if (process.platform !== "win32") {
|
|
2510
|
+
try {
|
|
2511
|
+
fs3.default.chmodSync(logPath, LOG_FILE_MODE);
|
|
2512
|
+
} catch (chmodError) {
|
|
2513
|
+
logWarn(
|
|
2514
|
+
deps.logger,
|
|
2515
|
+
"[droid-sdk transport-logger] failed to chmod log file",
|
|
2516
|
+
{
|
|
2517
|
+
cause: chmodError
|
|
2518
|
+
}
|
|
2519
|
+
);
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
stream.on("error", (streamError) => {
|
|
2523
|
+
deps.logger.warn("[droid-sdk transport-logger] write stream error", {
|
|
2524
|
+
cause: streamError
|
|
2525
|
+
});
|
|
2526
|
+
result.stream = null;
|
|
2527
|
+
result.failed = true;
|
|
2528
|
+
});
|
|
2529
|
+
result.stream = stream;
|
|
2530
|
+
} catch (initError) {
|
|
2531
|
+
logWarn(
|
|
2532
|
+
deps.logger,
|
|
2533
|
+
"[droid-sdk transport-logger] failed to open log file",
|
|
2534
|
+
{
|
|
2535
|
+
cause: initError
|
|
2536
|
+
}
|
|
2537
|
+
);
|
|
2538
|
+
result.failed = true;
|
|
2539
|
+
}
|
|
2540
|
+
return result;
|
|
2541
|
+
}
|
|
2542
|
+
function getState(deps) {
|
|
2543
|
+
if (!isTransportLoggingEnabled(deps)) return null;
|
|
2544
|
+
if (state === null) {
|
|
2545
|
+
state = initState(deps);
|
|
2546
|
+
}
|
|
2547
|
+
if (state.failed) return null;
|
|
2548
|
+
return state;
|
|
2549
|
+
}
|
|
2550
|
+
function logTransportMessage(direction, message, childPid, deps = defaultExecCoreDeps) {
|
|
2551
|
+
const s = getState(deps);
|
|
2552
|
+
if (!s || !s.stream) return;
|
|
2553
|
+
try {
|
|
2554
|
+
const marker = directionMarker(direction);
|
|
2555
|
+
const childTag = `[child_pid=${_nullishCoalesce(childPid, () => ( "-"))}]`;
|
|
2556
|
+
s.stream.write(
|
|
2557
|
+
`[${(/* @__PURE__ */ new Date()).toISOString()}] [${HOST_PID_TAG}] ${childTag} ${marker} ${message}
|
|
2558
|
+
`
|
|
2559
|
+
);
|
|
2560
|
+
} catch (writeError) {
|
|
2561
|
+
logWarn(
|
|
2562
|
+
deps.logger,
|
|
2563
|
+
"[droid-sdk transport-logger] write failed, disabling",
|
|
2564
|
+
{
|
|
2565
|
+
cause: writeError
|
|
2566
|
+
}
|
|
2567
|
+
);
|
|
2568
|
+
s.failed = true;
|
|
2569
|
+
s.stream = null;
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
async function __resetTransportLoggerForTests(deps = defaultExecCoreDeps) {
|
|
2573
|
+
const stream = _nullishCoalesce(_optionalChain([state, 'optionalAccess', _17 => _17.stream]), () => ( null));
|
|
2574
|
+
state = null;
|
|
2575
|
+
enabledCache = null;
|
|
2576
|
+
if (!stream) return;
|
|
2577
|
+
await new Promise((resolve2) => {
|
|
2578
|
+
stream.once("finish", () => resolve2());
|
|
2579
|
+
stream.once("error", () => resolve2());
|
|
2580
|
+
try {
|
|
2581
|
+
stream.end();
|
|
2582
|
+
} catch (endError) {
|
|
2583
|
+
logWarn(
|
|
2584
|
+
deps.logger,
|
|
2585
|
+
"[droid-sdk transport-logger] failed to end stream on reset",
|
|
2586
|
+
{
|
|
2587
|
+
cause: endError
|
|
2588
|
+
}
|
|
2589
|
+
);
|
|
2590
|
+
resolve2();
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
// src/exec-core/managed-process.ts
|
|
2596
|
+
var MAX_NON_JSON_LOG_LENGTH = 200;
|
|
2597
|
+
var EXIT_STDIO_DRAIN_TIMEOUT_MS = 2e3;
|
|
2598
|
+
var GRACEFUL_EXIT_TIMEOUT_MS = 2e3;
|
|
2599
|
+
var FORCED_EXIT_TIMEOUT_MS = 3e3;
|
|
2600
|
+
function describeSpawnError(error, context) {
|
|
2601
|
+
if (!isErrnoException(error)) {
|
|
2602
|
+
return `Failed to start Droid: ${error.message}`;
|
|
2603
|
+
}
|
|
2604
|
+
if (error.code === "ENOENT") {
|
|
2605
|
+
if (_optionalChain([context, 'optionalAccess', _18 => _18.cwd]) && !fs3.default.existsSync(context.cwd)) {
|
|
2606
|
+
return `Failed to start Droid: working directory does not exist (${context.cwd})`;
|
|
2607
|
+
}
|
|
2608
|
+
return `Failed to start Droid: executable not found${_optionalChain([context, 'optionalAccess', _19 => _19.execPath]) ? ` (${context.execPath})` : ""}`;
|
|
2609
|
+
}
|
|
2610
|
+
if (error.code === "EACCES") {
|
|
2611
|
+
return `Failed to start Droid: permission denied${_optionalChain([context, 'optionalAccess', _20 => _20.execPath]) ? ` (${context.execPath})` : ""}`;
|
|
2612
|
+
}
|
|
2613
|
+
return `Failed to start Droid: ${error.code}`;
|
|
2614
|
+
}
|
|
2615
|
+
function describeExitError(code, signal) {
|
|
2616
|
+
if (signal) {
|
|
2617
|
+
return `Droid process was killed (${signal})`;
|
|
2618
|
+
}
|
|
2619
|
+
if (code !== null) {
|
|
2620
|
+
return `Droid process exited unexpectedly (exit code ${code})`;
|
|
2621
|
+
}
|
|
2622
|
+
return "Droid process exited unexpectedly";
|
|
2623
|
+
}
|
|
2624
|
+
var ManagedProcessImpl = (_class2 = class {
|
|
2625
|
+
constructor(childProcess, logPrefix, spawnContext, deps, transportLoggerDeps = deps) {;_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);_class2.prototype.__init14.call(this);_class2.prototype.__init15.call(this);_class2.prototype.__init16.call(this);
|
|
2626
|
+
this.logPrefix = logPrefix;
|
|
2627
|
+
this.spawnContext = spawnContext;
|
|
2628
|
+
this.transportLoggerDeps = transportLoggerDeps;
|
|
2629
|
+
this._childProcess = childProcess;
|
|
2630
|
+
this.logger = deps.logger;
|
|
2631
|
+
this.setupHandlers();
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
|
|
2635
|
+
|
|
2636
|
+
|
|
2637
|
+
__init9() {this.messageHandler = null}
|
|
2638
|
+
__init10() {this.errorHandler = null}
|
|
2639
|
+
__init11() {this.readlineInterface = null}
|
|
2640
|
+
__init12() {this.isClosing = false}
|
|
2641
|
+
/** Latch so exit teardown/classification runs exactly once per process. */
|
|
2642
|
+
__init13() {this.exitFinalized = false}
|
|
2643
|
+
__init14() {this.exitDrainTimer = null}
|
|
2644
|
+
/**
|
|
2645
|
+
* Sticky error from a process error or unexpected exit event. Once set,
|
|
2646
|
+
* all subsequent `send()` calls throw this error immediately instead of
|
|
2647
|
+
* hanging on a dead transport.
|
|
2648
|
+
*/
|
|
2649
|
+
__init15() {this.processError = null}
|
|
2650
|
+
__init16() {this.queuedSendPromise = Promise.resolve()}
|
|
2651
|
+
|
|
2652
|
+
get childProcess() {
|
|
2653
|
+
if (!this._childProcess) {
|
|
2654
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Process not connected");
|
|
2655
|
+
}
|
|
2656
|
+
return this._childProcess;
|
|
2657
|
+
}
|
|
2658
|
+
setupHandlers() {
|
|
2659
|
+
if (!this.childProcess.stdout) {
|
|
2660
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Failed to get process stdout");
|
|
2661
|
+
}
|
|
2662
|
+
this.readlineInterface = readline.createInterface({
|
|
2663
|
+
input: this.childProcess.stdout,
|
|
2664
|
+
crlfDelay: Infinity
|
|
2665
|
+
});
|
|
2666
|
+
this.readlineInterface.on("line", (line) => {
|
|
2667
|
+
const trimmedLine = line.trim();
|
|
2668
|
+
if (this.messageHandler && trimmedLine) {
|
|
2669
|
+
if (trimmedLine.startsWith("{") || trimmedLine.startsWith("[")) {
|
|
2670
|
+
logTransportMessage(
|
|
2671
|
+
"in" /* In */,
|
|
2672
|
+
trimmedLine,
|
|
2673
|
+
_optionalChain([this, 'access', _21 => _21._childProcess, 'optionalAccess', _22 => _22.pid]),
|
|
2674
|
+
this.transportLoggerDeps
|
|
2675
|
+
);
|
|
2676
|
+
this.messageHandler(trimmedLine);
|
|
2677
|
+
} else {
|
|
2678
|
+
const truncated = trimmedLine.length > MAX_NON_JSON_LOG_LENGTH ? trimmedLine.substring(0, MAX_NON_JSON_LOG_LENGTH) : trimmedLine;
|
|
2679
|
+
this.logger.warn("[droid process] non-JSON output", {
|
|
2680
|
+
state: this.logPrefix,
|
|
2681
|
+
output: truncated
|
|
2682
|
+
});
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
});
|
|
2686
|
+
this.childProcess.on("error", (error) => {
|
|
2687
|
+
this.processError = new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
2688
|
+
describeSpawnError(error, this.spawnContext),
|
|
2689
|
+
{
|
|
2690
|
+
error,
|
|
2691
|
+
cwd: _optionalChain([this, 'access', _23 => _23.spawnContext, 'optionalAccess', _24 => _24.cwd]),
|
|
2692
|
+
execPath: _optionalChain([this, 'access', _25 => _25.spawnContext, 'optionalAccess', _26 => _26.execPath])
|
|
2693
|
+
}
|
|
2694
|
+
);
|
|
2695
|
+
if (!this.isClosing && this.errorHandler) {
|
|
2696
|
+
this.errorHandler(this.processError);
|
|
2697
|
+
}
|
|
2698
|
+
});
|
|
2699
|
+
this.childProcess.on("exit", (code, signal) => {
|
|
2700
|
+
this.exitDrainTimer = setTimeout(() => {
|
|
2701
|
+
this.finalizeExit(code, signal);
|
|
2702
|
+
}, EXIT_STDIO_DRAIN_TIMEOUT_MS);
|
|
2703
|
+
_optionalChain([this, 'access', _27 => _27.exitDrainTimer, 'access', _28 => _28.unref, 'optionalCall', _29 => _29()]);
|
|
2704
|
+
});
|
|
2705
|
+
this.childProcess.on("close", (code, signal) => {
|
|
2706
|
+
this.finalizeExit(code, signal);
|
|
2707
|
+
});
|
|
2708
|
+
if (this.childProcess.stderr) {
|
|
2709
|
+
this.childProcess.stderr.on("data", (data) => {
|
|
2710
|
+
this.logger.warn("[droid process] stderr", {
|
|
2711
|
+
state: this.logPrefix,
|
|
2712
|
+
output: data.toString()
|
|
2713
|
+
});
|
|
2714
|
+
});
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
finalizeExit(code, signal) {
|
|
2718
|
+
if (this.exitFinalized) {
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
this.exitFinalized = true;
|
|
2722
|
+
if (this.exitDrainTimer) {
|
|
2723
|
+
clearTimeout(this.exitDrainTimer);
|
|
2724
|
+
this.exitDrainTimer = null;
|
|
2725
|
+
}
|
|
2726
|
+
this._childProcess = null;
|
|
2727
|
+
if (this.readlineInterface) {
|
|
2728
|
+
this.readlineInterface.close();
|
|
2729
|
+
this.readlineInterface = null;
|
|
2730
|
+
}
|
|
2731
|
+
if (!this.isClosing) {
|
|
2732
|
+
this.processError = new (0, _chunk4G2RKM2Hjs.ProcessExitError)(
|
|
2733
|
+
describeExitError(code, signal),
|
|
2734
|
+
{
|
|
2735
|
+
exitCode: _nullishCoalesce(code, () => ( void 0)),
|
|
2736
|
+
signal: _nullishCoalesce(signal, () => ( void 0))
|
|
2737
|
+
}
|
|
2738
|
+
);
|
|
2739
|
+
if (this.errorHandler) {
|
|
2740
|
+
this.errorHandler(this.processError);
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
async send(message) {
|
|
2745
|
+
if (this.processError) {
|
|
2746
|
+
throw this.processError;
|
|
2747
|
+
}
|
|
2748
|
+
if (!this._childProcess || !this._childProcess.stdin) {
|
|
2749
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Process not connected");
|
|
2750
|
+
}
|
|
2751
|
+
const previousSends = this.queuedSendPromise;
|
|
2752
|
+
this.queuedSendPromise = (async () => {
|
|
2753
|
+
await previousSends.catch(() => {
|
|
2754
|
+
});
|
|
2755
|
+
if (!this._childProcess || !this._childProcess.stdin || this._childProcess.killed || this.isClosing) {
|
|
2756
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Process disconnected before write");
|
|
2757
|
+
}
|
|
2758
|
+
await new Promise((resolve2, reject) => {
|
|
2759
|
+
try {
|
|
2760
|
+
if (!this._childProcess || !this._childProcess.stdin) {
|
|
2761
|
+
reject(new (0, _chunk4G2RKM2Hjs.ConnectionError)("Process stdin unavailable"));
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
const stdin = this._childProcess.stdin;
|
|
2765
|
+
if ("writable" in stdin && !stdin.writable) {
|
|
2766
|
+
reject(new (0, _chunk4G2RKM2Hjs.ConnectionError)("Process stdin is not writable"));
|
|
2767
|
+
return;
|
|
2768
|
+
}
|
|
2769
|
+
const childPid = _optionalChain([this, 'access', _30 => _30._childProcess, 'optionalAccess', _31 => _31.pid]);
|
|
2770
|
+
stdin.write(`${message}
|
|
2771
|
+
`, (error) => {
|
|
2772
|
+
if (error) {
|
|
2773
|
+
logTransportMessage(
|
|
2774
|
+
"out_failed" /* OutFailed */,
|
|
2775
|
+
message,
|
|
2776
|
+
childPid,
|
|
2777
|
+
this.transportLoggerDeps
|
|
2778
|
+
);
|
|
2779
|
+
const errorMessage = error.message || String(error);
|
|
2780
|
+
if (errorMessage.includes("EPIPE") || errorMessage.includes("ECONNRESET")) {
|
|
2781
|
+
reject(
|
|
2782
|
+
new (0, _chunk4G2RKM2Hjs.ConnectionError)("Process stdin closed during write", {
|
|
2783
|
+
error
|
|
2784
|
+
})
|
|
2785
|
+
);
|
|
2786
|
+
} else {
|
|
2787
|
+
reject(
|
|
2788
|
+
new (0, _chunk4G2RKM2Hjs.ConnectionError)("Failed to write to process stdin", {
|
|
2789
|
+
error
|
|
2790
|
+
})
|
|
2791
|
+
);
|
|
2792
|
+
}
|
|
2793
|
+
} else {
|
|
2794
|
+
logTransportMessage(
|
|
2795
|
+
"out" /* Out */,
|
|
2796
|
+
message,
|
|
2797
|
+
childPid,
|
|
2798
|
+
this.transportLoggerDeps
|
|
2799
|
+
);
|
|
2800
|
+
resolve2();
|
|
2801
|
+
}
|
|
2802
|
+
});
|
|
2803
|
+
} catch (error) {
|
|
2804
|
+
logWarn(
|
|
2805
|
+
this.logger,
|
|
2806
|
+
"[ManagedProcess] Error writing to process stdin",
|
|
2807
|
+
{
|
|
2808
|
+
cause: error
|
|
2809
|
+
}
|
|
2810
|
+
);
|
|
2811
|
+
reject(
|
|
2812
|
+
new (0, _chunk4G2RKM2Hjs.ConnectionError)("Error writing to process stdin", {
|
|
2813
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
2814
|
+
})
|
|
2815
|
+
);
|
|
2816
|
+
}
|
|
2817
|
+
});
|
|
2818
|
+
})();
|
|
2819
|
+
return this.queuedSendPromise;
|
|
2820
|
+
}
|
|
2821
|
+
onMessage(handler) {
|
|
2822
|
+
this.messageHandler = handler;
|
|
2823
|
+
}
|
|
2824
|
+
onError(handler) {
|
|
2825
|
+
this.errorHandler = handler;
|
|
2826
|
+
}
|
|
2827
|
+
async close() {
|
|
2828
|
+
this.isClosing = true;
|
|
2829
|
+
if (this._childProcess) {
|
|
2830
|
+
const processToClose = this._childProcess;
|
|
2831
|
+
if (processToClose.pid === void 0 || processToClose.exitCode !== null || processToClose.signalCode !== null && processToClose.signalCode !== void 0) {
|
|
2832
|
+
this._childProcess = null;
|
|
2833
|
+
} else {
|
|
2834
|
+
await new Promise((resolve2) => {
|
|
2835
|
+
let forcedExitTimeout;
|
|
2836
|
+
const gracefulExitTimeout = setTimeout(() => {
|
|
2837
|
+
if (processToClose.exitCode === null) {
|
|
2838
|
+
if (process.platform === "win32") {
|
|
2839
|
+
this.killProcessTree(processToClose, "SIGKILL");
|
|
2840
|
+
} else {
|
|
2841
|
+
this.killProcessTree(processToClose, "SIGTERM");
|
|
2842
|
+
forcedExitTimeout = setTimeout(() => {
|
|
2843
|
+
if (processToClose.exitCode === null) {
|
|
2844
|
+
this.killProcessTree(processToClose, "SIGKILL");
|
|
2845
|
+
}
|
|
2846
|
+
}, FORCED_EXIT_TIMEOUT_MS);
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
}, GRACEFUL_EXIT_TIMEOUT_MS);
|
|
2850
|
+
processToClose.once("exit", () => {
|
|
2851
|
+
clearTimeout(gracefulExitTimeout);
|
|
2852
|
+
if (forcedExitTimeout) clearTimeout(forcedExitTimeout);
|
|
2853
|
+
resolve2();
|
|
2854
|
+
});
|
|
2855
|
+
if (processToClose.stdin) {
|
|
2856
|
+
processToClose.stdin.end();
|
|
2857
|
+
}
|
|
2858
|
+
});
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
if (this.readlineInterface) {
|
|
2862
|
+
this.readlineInterface.close();
|
|
2863
|
+
this.readlineInterface = null;
|
|
2864
|
+
}
|
|
2865
|
+
this.exitFinalized = true;
|
|
2866
|
+
if (this.exitDrainTimer) {
|
|
2867
|
+
clearTimeout(this.exitDrainTimer);
|
|
2868
|
+
this.exitDrainTimer = null;
|
|
2869
|
+
}
|
|
2870
|
+
this._childProcess = null;
|
|
2871
|
+
this.isClosing = false;
|
|
2872
|
+
}
|
|
2873
|
+
killProcessTree(childProcess, signal) {
|
|
2874
|
+
if (process.platform !== "win32" || childProcess.pid === void 0) {
|
|
2875
|
+
childProcess.kill(signal);
|
|
2876
|
+
return;
|
|
2877
|
+
}
|
|
2878
|
+
const result = _child_process.spawnSync.call(void 0,
|
|
2879
|
+
"taskkill",
|
|
2880
|
+
["/PID", String(childProcess.pid), "/T", "/F"],
|
|
2881
|
+
{
|
|
2882
|
+
stdio: "ignore",
|
|
2883
|
+
windowsHide: true
|
|
2884
|
+
}
|
|
2885
|
+
);
|
|
2886
|
+
if (!result.error && result.status === 0) {
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
logWarn(
|
|
2890
|
+
this.logger,
|
|
2891
|
+
"[ManagedProcess] Failed to kill Windows process tree",
|
|
2892
|
+
{
|
|
2893
|
+
pid: childProcess.pid,
|
|
2894
|
+
signal,
|
|
2895
|
+
status: result.status,
|
|
2896
|
+
cause: result.error
|
|
2897
|
+
}
|
|
2898
|
+
);
|
|
2899
|
+
childProcess.kill(signal);
|
|
2900
|
+
}
|
|
2901
|
+
get isConnected() {
|
|
2902
|
+
return this._childProcess !== null && !this._childProcess.killed && this._childProcess.stdin !== null && !this._childProcess.stdin.destroyed && ("writable" in this._childProcess.stdin ? this._childProcess.stdin.writable : true);
|
|
2903
|
+
}
|
|
2904
|
+
}, _class2);
|
|
2905
|
+
|
|
2906
|
+
// src/exec-core/process-manager.ts
|
|
2907
|
+
|
|
2908
|
+
|
|
2909
|
+
// src/exec-core/windows-job-object-retry.ts
|
|
2910
|
+
var DEFAULT_BACKOFF_MS = [50, 150, 400];
|
|
2911
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
2912
|
+
var DEFAULT_GRACE_PERIOD_MS = 250;
|
|
2913
|
+
var defaultSleep = (ms) => new Promise((resolve2) => {
|
|
2914
|
+
setTimeout(resolve2, ms);
|
|
2915
|
+
});
|
|
2916
|
+
function observeEarlySpawnFailure(childProcess, gracePeriodMs, sleep) {
|
|
2917
|
+
const observation = {
|
|
2918
|
+
exited: false,
|
|
2919
|
+
code: null,
|
|
2920
|
+
signal: null,
|
|
2921
|
+
error: null,
|
|
2922
|
+
stderr: ""
|
|
2923
|
+
};
|
|
2924
|
+
const stderrListener = (data) => {
|
|
2925
|
+
observation.stderr += data.toString();
|
|
2926
|
+
};
|
|
2927
|
+
const exitListener = (code, signal) => {
|
|
2928
|
+
observation.exited = true;
|
|
2929
|
+
observation.code = code;
|
|
2930
|
+
observation.signal = signal;
|
|
2931
|
+
};
|
|
2932
|
+
const errorListener = (err) => {
|
|
2933
|
+
observation.error = err;
|
|
2934
|
+
};
|
|
2935
|
+
_optionalChain([childProcess, 'access', _32 => _32.stderr, 'optionalAccess', _33 => _33.on, 'call', _34 => _34("data", stderrListener)]);
|
|
2936
|
+
childProcess.once("exit", exitListener);
|
|
2937
|
+
childProcess.once("error", errorListener);
|
|
2938
|
+
const cleanup = () => {
|
|
2939
|
+
_optionalChain([childProcess, 'access', _35 => _35.stderr, 'optionalAccess', _36 => _36.off, 'call', _37 => _37("data", stderrListener)]);
|
|
2940
|
+
childProcess.off("exit", exitListener);
|
|
2941
|
+
childProcess.off("error", errorListener);
|
|
2942
|
+
};
|
|
2943
|
+
return new Promise((resolve2) => {
|
|
2944
|
+
const resolveAndCleanup = () => {
|
|
2945
|
+
cleanup();
|
|
2946
|
+
resolve2(observation);
|
|
2947
|
+
};
|
|
2948
|
+
const onExitResolve = () => {
|
|
2949
|
+
setImmediate(resolveAndCleanup);
|
|
2950
|
+
};
|
|
2951
|
+
childProcess.once("exit", onExitResolve);
|
|
2952
|
+
childProcess.once("error", onExitResolve);
|
|
2953
|
+
void sleep(gracePeriodMs).then(() => {
|
|
2954
|
+
childProcess.off("exit", onExitResolve);
|
|
2955
|
+
childProcess.off("error", onExitResolve);
|
|
2956
|
+
resolveAndCleanup();
|
|
2957
|
+
});
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
async function spawnWithWindowsJobObjectRetry(spawnFactory, options = {}) {
|
|
2961
|
+
const enabled = _nullishCoalesce(options.enabled, () => ( process.platform === "win32"));
|
|
2962
|
+
if (!enabled) {
|
|
2963
|
+
return spawnFactory();
|
|
2964
|
+
}
|
|
2965
|
+
const maxRetries = _nullishCoalesce(options.maxRetries, () => ( DEFAULT_MAX_RETRIES));
|
|
2966
|
+
const backoff = _nullishCoalesce(options.backoffMs, () => ( DEFAULT_BACKOFF_MS));
|
|
2967
|
+
const gracePeriodMs = _nullishCoalesce(options.gracePeriodMs, () => ( DEFAULT_GRACE_PERIOD_MS));
|
|
2968
|
+
const sleep = _nullishCoalesce(options.sleep, () => ( defaultSleep));
|
|
2969
|
+
const logPrefix = _nullishCoalesce(options.logPrefix, () => ( "[spawnWithWindowsJobObjectRetry]"));
|
|
2970
|
+
const logger = _nullishCoalesce(options.logger, () => ( noopLogger));
|
|
2971
|
+
let lastChild = null;
|
|
2972
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2973
|
+
const child = spawnFactory();
|
|
2974
|
+
lastChild = child;
|
|
2975
|
+
const observation = await observeEarlySpawnFailure(
|
|
2976
|
+
child,
|
|
2977
|
+
gracePeriodMs,
|
|
2978
|
+
sleep
|
|
2979
|
+
);
|
|
2980
|
+
if (!observation.exited && !observation.error) {
|
|
2981
|
+
return child;
|
|
2982
|
+
}
|
|
2983
|
+
const isRetryableJobObjectFailure = observation.stderr.includes(WINDOWS_JOB_OBJECT_ERROR_MARKER) || observation.exited && observation.code !== 0 && !observation.error;
|
|
2984
|
+
if (attempt === maxRetries || !isRetryableJobObjectFailure) {
|
|
2985
|
+
return child;
|
|
2986
|
+
}
|
|
2987
|
+
logger.warn("spawnWithWindowsJobObjectRetry: retrying on early failure", {
|
|
2988
|
+
name: logPrefix,
|
|
2989
|
+
attempt: attempt + 1,
|
|
2990
|
+
maxAttempts: maxRetries,
|
|
2991
|
+
exitCode: observation.code,
|
|
2992
|
+
signal: observation.signal,
|
|
2993
|
+
stderrTail: observation.stderr.slice(-256)
|
|
2994
|
+
});
|
|
2995
|
+
try {
|
|
2996
|
+
await _optionalChain([options, 'access', _38 => _38.disposeEarlyExited, 'optionalCall', _39 => _39(child)]);
|
|
2997
|
+
} catch (disposeErr) {
|
|
2998
|
+
logWarn(logger, "spawnWithWindowsJobObjectRetry: dispose error", {
|
|
2999
|
+
cause: disposeErr instanceof Error ? disposeErr : new Error(String(disposeErr)),
|
|
3000
|
+
name: logPrefix
|
|
3001
|
+
});
|
|
3002
|
+
}
|
|
3003
|
+
await sleep(_nullishCoalesce(_nullishCoalesce(backoff[attempt], () => ( backoff[backoff.length - 1])), () => ( 400)));
|
|
3004
|
+
}
|
|
3005
|
+
if (lastChild) return lastChild;
|
|
3006
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
3007
|
+
"spawnWithWindowsJobObjectRetry: exhausted retries without child",
|
|
3008
|
+
{}
|
|
3009
|
+
);
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
// src/exec-core/process-manager.ts
|
|
3013
|
+
function buildArgs(config) {
|
|
3014
|
+
const args = [];
|
|
3015
|
+
if (config.mode === "acp" /* Acp */) {
|
|
3016
|
+
args.push("exec", "--output-format", "acp");
|
|
3017
|
+
} else {
|
|
3018
|
+
args.push(
|
|
3019
|
+
"exec",
|
|
3020
|
+
"--input-format",
|
|
3021
|
+
"stream-jsonrpc",
|
|
3022
|
+
"--output-format",
|
|
3023
|
+
"stream-jsonrpc"
|
|
3024
|
+
);
|
|
3025
|
+
}
|
|
3026
|
+
if (config.extraArgs) {
|
|
3027
|
+
args.push(...config.extraArgs);
|
|
3028
|
+
}
|
|
3029
|
+
return args;
|
|
3030
|
+
}
|
|
3031
|
+
var DroidProcessManager = class {
|
|
3032
|
+
|
|
3033
|
+
|
|
3034
|
+
|
|
3035
|
+
|
|
3036
|
+
constructor(options = {}, deps = defaultExecCoreDeps) {
|
|
3037
|
+
const resolved = resolveExecCoreDeps(options.observability, deps);
|
|
3038
|
+
this.deps = resolved;
|
|
3039
|
+
this.transportLoggerDeps = deps;
|
|
3040
|
+
this.logger = resolved.logger;
|
|
3041
|
+
this.commandResolver = resolved.commandResolver;
|
|
3042
|
+
}
|
|
3043
|
+
/**
|
|
3044
|
+
* Spawn a new droid process with the given configuration.
|
|
3045
|
+
*
|
|
3046
|
+
* Returns a synchronous ManagedProcess as soon as the OS reports the child
|
|
3047
|
+
* as spawned. This does not retry Windows Job Object spawn failures — use
|
|
3048
|
+
* {@link DroidProcessManager#spawnWithWindowsRetry} for that.
|
|
3049
|
+
*/
|
|
3050
|
+
spawn(config) {
|
|
3051
|
+
const { logPrefix, execPath, expandedCwd, childProcess } = this.spawnChildProcess(config);
|
|
3052
|
+
return new ManagedProcessImpl(
|
|
3053
|
+
childProcess,
|
|
3054
|
+
logPrefix,
|
|
3055
|
+
{
|
|
3056
|
+
cwd: expandedCwd,
|
|
3057
|
+
execPath
|
|
3058
|
+
},
|
|
3059
|
+
this.deps,
|
|
3060
|
+
this.transportLoggerDeps
|
|
3061
|
+
);
|
|
3062
|
+
}
|
|
3063
|
+
/**
|
|
3064
|
+
* Spawn a droid process with automatic retry for the Windows Job Object
|
|
3065
|
+
* spawn error class (FAC-19070). On non-Windows platforms this behaves
|
|
3066
|
+
* identically to {@link DroidProcessManager#spawn} but returns a promise.
|
|
3067
|
+
*
|
|
3068
|
+
* When a Windows child process exits within the startup grace period and
|
|
3069
|
+
* the exit looks like the `AssignProcessToJobObject` failure pattern, the
|
|
3070
|
+
* dead child is disposed and a fresh spawn is attempted, up to the
|
|
3071
|
+
* configured retry cap.
|
|
3072
|
+
*/
|
|
3073
|
+
async spawnWithWindowsRetry(config, retryOptions = {}) {
|
|
3074
|
+
if (process.platform !== "win32") {
|
|
3075
|
+
return this.spawn(config);
|
|
3076
|
+
}
|
|
3077
|
+
const planned = this.prepareSpawn(config);
|
|
3078
|
+
const childProcess = await spawnWithWindowsJobObjectRetry(
|
|
3079
|
+
() => this.invokeNodeSpawn(planned),
|
|
3080
|
+
{
|
|
3081
|
+
...retryOptions,
|
|
3082
|
+
logPrefix: "[DroidProcessManager]",
|
|
3083
|
+
logger: this.logger,
|
|
3084
|
+
disposeEarlyExited: (child) => {
|
|
3085
|
+
try {
|
|
3086
|
+
_optionalChain([child, 'access', _40 => _40.stdin, 'optionalAccess', _41 => _41.end, 'call', _42 => _42()]);
|
|
3087
|
+
} catch (stdinErr) {
|
|
3088
|
+
logWarn(
|
|
3089
|
+
this.logger,
|
|
3090
|
+
"DroidProcessManager: stdin.end() threw during dispose",
|
|
3091
|
+
{
|
|
3092
|
+
cause: stdinErr instanceof Error ? stdinErr : new Error(String(stdinErr))
|
|
3093
|
+
}
|
|
3094
|
+
);
|
|
3095
|
+
}
|
|
3096
|
+
try {
|
|
3097
|
+
child.kill();
|
|
3098
|
+
} catch (killErr) {
|
|
3099
|
+
logWarn(
|
|
3100
|
+
this.logger,
|
|
3101
|
+
"DroidProcessManager: kill() threw during dispose",
|
|
3102
|
+
{
|
|
3103
|
+
cause: killErr instanceof Error ? killErr : new Error(String(killErr))
|
|
3104
|
+
}
|
|
3105
|
+
);
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
);
|
|
3110
|
+
if (!childProcess.stdout || !childProcess.stdin) {
|
|
3111
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Failed to get process stdio");
|
|
3112
|
+
}
|
|
3113
|
+
return new ManagedProcessImpl(
|
|
3114
|
+
childProcess,
|
|
3115
|
+
planned.logPrefix,
|
|
3116
|
+
{
|
|
3117
|
+
cwd: planned.expandedCwd,
|
|
3118
|
+
execPath: planned.execPath
|
|
3119
|
+
},
|
|
3120
|
+
this.deps,
|
|
3121
|
+
this.transportLoggerDeps
|
|
3122
|
+
);
|
|
3123
|
+
}
|
|
3124
|
+
prepareSpawn(config) {
|
|
3125
|
+
const command = this.commandResolver.resolveDroidCommand(
|
|
3126
|
+
_nullishCoalesce(config.isDevelopment, () => ( false))
|
|
3127
|
+
);
|
|
3128
|
+
const execPath = config.execPath || command.execPath;
|
|
3129
|
+
const prefixArgs = config.execPath ? [] : command.prefixArgs;
|
|
3130
|
+
const args = [...prefixArgs, ...buildArgs(config)];
|
|
3131
|
+
const expandedCwd = config.cwd ? expandTilde(config.cwd) : void 0;
|
|
3132
|
+
const logPrefix = config.mode === "acp" /* Acp */ ? "[droid acp]" : "[droid exec]";
|
|
3133
|
+
this.logger.info("[droid process] Spawning", {
|
|
3134
|
+
state: logPrefix,
|
|
3135
|
+
path: execPath,
|
|
3136
|
+
args,
|
|
3137
|
+
cwd: expandedCwd,
|
|
3138
|
+
version: process.env.CLI_VERSION || "unknown"
|
|
3139
|
+
});
|
|
3140
|
+
return {
|
|
3141
|
+
logPrefix,
|
|
3142
|
+
execPath,
|
|
3143
|
+
expandedCwd,
|
|
3144
|
+
args,
|
|
3145
|
+
env: {
|
|
3146
|
+
...this.deps.environmentResolver.sanitizeSpawnEnv({
|
|
3147
|
+
...process.env,
|
|
3148
|
+
...config.env
|
|
3149
|
+
}),
|
|
3150
|
+
...config.trustedEnv
|
|
3151
|
+
},
|
|
3152
|
+
enableIpc: _nullishCoalesce(config.enableIpc, () => ( false)),
|
|
3153
|
+
stdio: config.stdio
|
|
3154
|
+
};
|
|
3155
|
+
}
|
|
3156
|
+
invokeNodeSpawn(planned) {
|
|
3157
|
+
const options = {
|
|
3158
|
+
cwd: planned.expandedCwd,
|
|
3159
|
+
env: planned.env,
|
|
3160
|
+
stdio: _nullishCoalesce(planned.stdio, () => ( (planned.enableIpc ? ["pipe", "pipe", "pipe", "ipc"] : ["pipe", "pipe", "pipe"])))
|
|
3161
|
+
};
|
|
3162
|
+
if (planned.enableIpc) {
|
|
3163
|
+
options.serialization = "json";
|
|
3164
|
+
}
|
|
3165
|
+
return _child_process.spawn.call(void 0, planned.execPath, planned.args, options);
|
|
3166
|
+
}
|
|
3167
|
+
spawnChildProcess(config) {
|
|
3168
|
+
const planned = this.prepareSpawn(config);
|
|
3169
|
+
const childProcess = this.invokeNodeSpawn(planned);
|
|
3170
|
+
if (!childProcess.stdout || !childProcess.stdin) {
|
|
3171
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Failed to get process stdio");
|
|
3172
|
+
}
|
|
3173
|
+
return {
|
|
3174
|
+
logPrefix: planned.logPrefix,
|
|
3175
|
+
execPath: planned.execPath,
|
|
3176
|
+
expandedCwd: planned.expandedCwd,
|
|
3177
|
+
childProcess
|
|
3178
|
+
};
|
|
3179
|
+
}
|
|
3180
|
+
};
|
|
3181
|
+
|
|
3182
|
+
// src/exec-core/process-transport.ts
|
|
3183
|
+
var ProcessTransport = (_class3 = class {
|
|
3184
|
+
__init17() {this.managedProcess = null}
|
|
3185
|
+
|
|
3186
|
+
|
|
3187
|
+
// Store handlers that may be registered before connect() is called
|
|
3188
|
+
__init18() {this.messageHandler = null}
|
|
3189
|
+
__init19() {this.errorHandler = null}
|
|
3190
|
+
|
|
3191
|
+
constructor(options = {}, deps = defaultExecCoreDeps) {;_class3.prototype.__init17.call(this);_class3.prototype.__init18.call(this);_class3.prototype.__init19.call(this);
|
|
3192
|
+
this.options = options;
|
|
3193
|
+
const resolved = resolveExecCoreDeps(options.observability, deps);
|
|
3194
|
+
this.metrics = resolved.metrics;
|
|
3195
|
+
this.processManager = new DroidProcessManager(
|
|
3196
|
+
{
|
|
3197
|
+
observability: options.observability
|
|
3198
|
+
},
|
|
3199
|
+
deps
|
|
3200
|
+
);
|
|
3201
|
+
}
|
|
3202
|
+
async connect() {
|
|
3203
|
+
if (this.managedProcess && this.managedProcess.isConnected) {
|
|
3204
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Transport already connected");
|
|
3205
|
+
}
|
|
3206
|
+
const config = {
|
|
3207
|
+
execPath: this.options.droidExecPath,
|
|
3208
|
+
isDevelopment: this.options.isDevelopment,
|
|
3209
|
+
mode: "stream-jsonrpc" /* StreamJsonRpc */,
|
|
3210
|
+
cwd: this.options.cwd,
|
|
3211
|
+
env: this.options.env,
|
|
3212
|
+
extraArgs: this.options.droidExecExtraArgs,
|
|
3213
|
+
enableIpc: this.options.enableIpc
|
|
3214
|
+
};
|
|
3215
|
+
const spawnStart = performance.now();
|
|
3216
|
+
let spawnOutcome = "error";
|
|
3217
|
+
try {
|
|
3218
|
+
this.managedProcess = process.platform === "win32" ? await this.processManager.spawnWithWindowsRetry(config) : this.processManager.spawn(config);
|
|
3219
|
+
spawnOutcome = "success";
|
|
3220
|
+
} finally {
|
|
3221
|
+
this.metrics.recordDuration(
|
|
3222
|
+
CLI_JSONRPC_CHILD_SPAWN_LATENCY_METRIC,
|
|
3223
|
+
performance.now() - spawnStart,
|
|
3224
|
+
{ outcome: spawnOutcome, source: "process_transport" }
|
|
3225
|
+
);
|
|
3226
|
+
}
|
|
3227
|
+
if (this.messageHandler) {
|
|
3228
|
+
this.managedProcess.onMessage(this.messageHandler);
|
|
3229
|
+
}
|
|
3230
|
+
if (this.errorHandler) {
|
|
3231
|
+
this.managedProcess.onError(this.errorHandler);
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
async send(message) {
|
|
3235
|
+
if (!this.managedProcess) {
|
|
3236
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)("Transport not connected");
|
|
3237
|
+
}
|
|
3238
|
+
return this.managedProcess.send(message);
|
|
3239
|
+
}
|
|
3240
|
+
onMessage(handler) {
|
|
3241
|
+
this.messageHandler = handler;
|
|
3242
|
+
if (this.managedProcess) {
|
|
3243
|
+
this.managedProcess.onMessage(handler);
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
onError(handler) {
|
|
3247
|
+
this.errorHandler = handler;
|
|
3248
|
+
if (this.managedProcess) {
|
|
3249
|
+
this.managedProcess.onError(handler);
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
async close() {
|
|
3253
|
+
if (this.managedProcess) {
|
|
3254
|
+
await this.managedProcess.close();
|
|
3255
|
+
this.managedProcess = null;
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
get isConnected() {
|
|
3259
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _43 => _43.managedProcess, 'optionalAccess', _44 => _44.isConnected]), () => ( false));
|
|
3260
|
+
}
|
|
3261
|
+
getManagedProcess() {
|
|
3262
|
+
return this.managedProcess;
|
|
3263
|
+
}
|
|
3264
|
+
}, _class3);
|
|
3265
|
+
|
|
3266
|
+
// src/helpers.ts
|
|
3267
|
+
function resolveApiKey(apiKey) {
|
|
3268
|
+
const resolved = _nullishCoalesce(apiKey, () => ( process.env.FACTORY_API_KEY));
|
|
3269
|
+
if (!resolved) {
|
|
3270
|
+
throw new (0, _chunk4G2RKM2Hjs.DroidClientError)(
|
|
3271
|
+
"No Factory API key found. Pass `apiKey` when creating the session, or set the FACTORY_API_KEY environment variable."
|
|
3272
|
+
);
|
|
3273
|
+
}
|
|
3274
|
+
return resolved;
|
|
3275
|
+
}
|
|
3276
|
+
async function createTransport(options) {
|
|
3277
|
+
if (options.transport) {
|
|
3278
|
+
return options.transport;
|
|
3279
|
+
}
|
|
3280
|
+
const processTransport = new ProcessTransport({
|
|
3281
|
+
droidExecPath: options.execPath,
|
|
3282
|
+
droidExecExtraArgs: options.execArgs,
|
|
3283
|
+
cwd: options.cwd,
|
|
3284
|
+
env: { ...options.env, FACTORY_API_KEY: resolveApiKey(options.apiKey) },
|
|
3285
|
+
observability: options.observability
|
|
3286
|
+
});
|
|
3287
|
+
await processTransport.connect();
|
|
3288
|
+
return processTransport;
|
|
3289
|
+
}
|
|
3290
|
+
function setupClientHandlers(client, options) {
|
|
3291
|
+
if (options.permissionHandler) {
|
|
3292
|
+
const handler = options.permissionHandler;
|
|
3293
|
+
client.setPermissionHandler((event) => handler(event.params));
|
|
3294
|
+
}
|
|
3295
|
+
if (options.askUserHandler) {
|
|
3296
|
+
const handler = options.askUserHandler;
|
|
3297
|
+
client.setAskUserHandler((event) => handler(event.params));
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
async function createConfiguredClient(options) {
|
|
3301
|
+
const transport = await createTransport(options);
|
|
3302
|
+
const client = new DroidClient({
|
|
3303
|
+
transport,
|
|
3304
|
+
observability: options.observability
|
|
3305
|
+
});
|
|
3306
|
+
setupClientHandlers(client, options);
|
|
3307
|
+
return { transport, client };
|
|
3308
|
+
}
|
|
3309
|
+
async function closeQuietly(resource) {
|
|
3310
|
+
if (!resource) {
|
|
3311
|
+
return;
|
|
3312
|
+
}
|
|
3313
|
+
try {
|
|
3314
|
+
await resource.close();
|
|
3315
|
+
} catch (e7) {
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
function buildInitParams(options) {
|
|
3319
|
+
return {
|
|
3320
|
+
machineId: _nullishCoalesce(options.machineId, () => ( "default")),
|
|
3321
|
+
cwd: _nullishCoalesce(options.cwd, () => ( process.cwd())),
|
|
3322
|
+
...options.modelId !== void 0 && { modelId: options.modelId },
|
|
3323
|
+
...options.autonomyLevel !== void 0 && {
|
|
3324
|
+
autonomyLevel: options.autonomyLevel
|
|
3325
|
+
},
|
|
3326
|
+
...options.interactionMode !== void 0 && {
|
|
3327
|
+
interactionMode: options.interactionMode
|
|
3328
|
+
},
|
|
3329
|
+
...options.reasoningEffort !== void 0 && {
|
|
3330
|
+
reasoningEffort: options.reasoningEffort
|
|
3331
|
+
},
|
|
3332
|
+
...options.systemPrompt !== void 0 && {
|
|
3333
|
+
systemPrompt: options.systemPrompt
|
|
3334
|
+
},
|
|
3335
|
+
...options.specModeModelId !== void 0 && {
|
|
3336
|
+
specModeModelId: options.specModeModelId
|
|
3337
|
+
},
|
|
3338
|
+
...options.specModeReasoningEffort !== void 0 && {
|
|
3339
|
+
specModeReasoningEffort: options.specModeReasoningEffort
|
|
3340
|
+
},
|
|
3341
|
+
...options.mcpServers !== void 0 && {
|
|
3342
|
+
mcpServers: options.mcpServers
|
|
3343
|
+
},
|
|
3344
|
+
...options.disabledToolIds !== void 0 && {
|
|
3345
|
+
disabledToolIds: options.disabledToolIds
|
|
3346
|
+
},
|
|
3347
|
+
...options.sessionSource !== void 0 && {
|
|
3348
|
+
sessionSource: options.sessionSource
|
|
3349
|
+
},
|
|
3350
|
+
...options.autoRejectPermissionRequests !== void 0 && {
|
|
3351
|
+
autoRejectPermissionRequests: options.autoRejectPermissionRequests
|
|
3352
|
+
},
|
|
3353
|
+
...options.disableBuiltinSkills !== void 0 && {
|
|
3354
|
+
disableBuiltinSkills: options.disableBuiltinSkills
|
|
3355
|
+
},
|
|
3356
|
+
tags: [..._nullishCoalesce(options.tags, () => ( [])), _chunk4G2RKM2Hjs.SDK_TAG]
|
|
3357
|
+
};
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
// src/mcp.ts
|
|
3361
|
+
var _crypto = require('crypto');
|
|
3362
|
+
|
|
3363
|
+
var _http = require('http'); var _http2 = _interopRequireDefault(_http);
|
|
3364
|
+
var _mcpjs = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
3365
|
+
var _streamableHttpjs = require('@modelcontextprotocol/sdk/server/streamableHttp.js');
|
|
3366
|
+
|
|
3367
|
+
function tool(name, description, inputSchemaOrHandler, handler) {
|
|
3368
|
+
if (typeof inputSchemaOrHandler === "function") {
|
|
3369
|
+
const actualHandler = inputSchemaOrHandler;
|
|
3370
|
+
return {
|
|
3371
|
+
name,
|
|
3372
|
+
description,
|
|
3373
|
+
handler: (input) => actualHandler(input)
|
|
3374
|
+
};
|
|
3375
|
+
}
|
|
3376
|
+
if (!handler) {
|
|
3377
|
+
throw new Error(`Missing handler for SDK MCP tool "${name}"`);
|
|
3378
|
+
}
|
|
3379
|
+
const inputObjectSchema = _zod.z.object(inputSchemaOrHandler);
|
|
3380
|
+
return {
|
|
3381
|
+
name,
|
|
3382
|
+
description,
|
|
3383
|
+
inputSchema: inputSchemaOrHandler,
|
|
3384
|
+
handler: (input) => handler(inputObjectSchema.parse(input))
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
function isSdkMcpServer(server) {
|
|
3388
|
+
return server instanceof SdkMcpServer;
|
|
3389
|
+
}
|
|
3390
|
+
function toCallToolResult(result) {
|
|
3391
|
+
if (typeof result === "string") {
|
|
3392
|
+
return {
|
|
3393
|
+
content: [{ type: "text", text: result }]
|
|
3394
|
+
};
|
|
3395
|
+
}
|
|
3396
|
+
return result;
|
|
3397
|
+
}
|
|
3398
|
+
async function readJsonBody(req) {
|
|
3399
|
+
const chunks = [];
|
|
3400
|
+
for await (const chunk of req) {
|
|
3401
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
3402
|
+
}
|
|
3403
|
+
if (chunks.length === 0) {
|
|
3404
|
+
return void 0;
|
|
3405
|
+
}
|
|
3406
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
3407
|
+
}
|
|
3408
|
+
function writeJsonError(res, statusCode, message, headers = {}) {
|
|
3409
|
+
if (res.headersSent) {
|
|
3410
|
+
return;
|
|
3411
|
+
}
|
|
3412
|
+
res.writeHead(statusCode, {
|
|
3413
|
+
"content-type": "application/json",
|
|
3414
|
+
...headers
|
|
3415
|
+
});
|
|
3416
|
+
res.end(
|
|
3417
|
+
JSON.stringify({
|
|
3418
|
+
jsonrpc: _chunk4G2RKM2Hjs.JSONRPC_VERSION,
|
|
3419
|
+
error: { code: -32603 /* INTERNAL_ERROR */, message },
|
|
3420
|
+
id: null
|
|
3421
|
+
})
|
|
3422
|
+
);
|
|
3423
|
+
}
|
|
3424
|
+
function hasValidBearerToken(authorization, token) {
|
|
3425
|
+
if (!authorization) {
|
|
3426
|
+
return false;
|
|
3427
|
+
}
|
|
3428
|
+
const separator = authorization.indexOf(" ");
|
|
3429
|
+
if (separator === -1 || authorization.slice(0, separator).toLowerCase() !== "bearer") {
|
|
3430
|
+
return false;
|
|
3431
|
+
}
|
|
3432
|
+
const actual = Buffer.from(authorization.slice(separator + 1));
|
|
3433
|
+
const expected = Buffer.from(token);
|
|
3434
|
+
return actual.length === expected.length && _crypto.timingSafeEqual.call(void 0, actual, expected);
|
|
3435
|
+
}
|
|
3436
|
+
var SdkMcpServer = (_class4 = class {
|
|
3437
|
+
|
|
3438
|
+
|
|
3439
|
+
|
|
3440
|
+
__init20() {this._httpServer = null}
|
|
3441
|
+
__init21() {this._url = null}
|
|
3442
|
+
__init22() {this._token = null}
|
|
3443
|
+
constructor(options) {;_class4.prototype.__init20.call(this);_class4.prototype.__init21.call(this);_class4.prototype.__init22.call(this);
|
|
3444
|
+
this.name = options.name;
|
|
3445
|
+
this.version = _nullishCoalesce(options.version, () => ( "1.0.0"));
|
|
3446
|
+
this.tools = options.tools;
|
|
3447
|
+
}
|
|
3448
|
+
get config() {
|
|
3449
|
+
if (!this._url || !this._token) {
|
|
3450
|
+
return null;
|
|
3451
|
+
}
|
|
3452
|
+
return {
|
|
3453
|
+
type: "http" /* Http */,
|
|
3454
|
+
name: this.name,
|
|
3455
|
+
url: this._url,
|
|
3456
|
+
oauth: false,
|
|
3457
|
+
headers: [
|
|
3458
|
+
{
|
|
3459
|
+
name: "Authorization",
|
|
3460
|
+
value: `Bearer ${this._token}`
|
|
3461
|
+
}
|
|
3462
|
+
]
|
|
3463
|
+
};
|
|
3464
|
+
}
|
|
3465
|
+
async start() {
|
|
3466
|
+
if (this.config) {
|
|
3467
|
+
return this.config;
|
|
3468
|
+
}
|
|
3469
|
+
this._token = _crypto.randomBytes.call(void 0, 32).toString("base64url");
|
|
3470
|
+
this._httpServer = _http2.default.createServer((req, res) => {
|
|
3471
|
+
void this.handleRequest(req, res);
|
|
3472
|
+
});
|
|
3473
|
+
this._httpServer.listen(0, "127.0.0.1");
|
|
3474
|
+
await _events.once.call(void 0, this._httpServer, "listening");
|
|
3475
|
+
const address = this._httpServer.address();
|
|
3476
|
+
if (!address || typeof address === "string") {
|
|
3477
|
+
throw new Error("Unable to determine SDK MCP server address");
|
|
3478
|
+
}
|
|
3479
|
+
this._url = `http://127.0.0.1:${address.port}/mcp`;
|
|
3480
|
+
const config = this.config;
|
|
3481
|
+
if (!config) {
|
|
3482
|
+
throw new Error("Unable to start SDK MCP server");
|
|
3483
|
+
}
|
|
3484
|
+
return config;
|
|
3485
|
+
}
|
|
3486
|
+
async close() {
|
|
3487
|
+
const server = this._httpServer;
|
|
3488
|
+
this._httpServer = null;
|
|
3489
|
+
this._url = null;
|
|
3490
|
+
this._token = null;
|
|
3491
|
+
if (!server) {
|
|
3492
|
+
return;
|
|
3493
|
+
}
|
|
3494
|
+
_optionalChain([server, 'access', _45 => _45.closeAllConnections, 'optionalCall', _46 => _46()]);
|
|
3495
|
+
server.close();
|
|
3496
|
+
await _events.once.call(void 0, server, "close");
|
|
3497
|
+
}
|
|
3498
|
+
createMcpServer() {
|
|
3499
|
+
const server = new (0, _mcpjs.McpServer)({
|
|
3500
|
+
name: this.name,
|
|
3501
|
+
version: this.version
|
|
3502
|
+
});
|
|
3503
|
+
for (const sdkTool of this.tools) {
|
|
3504
|
+
server.registerTool(
|
|
3505
|
+
sdkTool.name,
|
|
3506
|
+
{
|
|
3507
|
+
description: sdkTool.description,
|
|
3508
|
+
...sdkTool.inputSchema && {
|
|
3509
|
+
inputSchema: sdkTool.inputSchema
|
|
3510
|
+
}
|
|
3511
|
+
},
|
|
3512
|
+
async (input) => toCallToolResult(await sdkTool.handler(input))
|
|
3513
|
+
);
|
|
3514
|
+
}
|
|
3515
|
+
return server;
|
|
3516
|
+
}
|
|
3517
|
+
async handleRequest(req, res) {
|
|
3518
|
+
if (req.url !== "/mcp") {
|
|
3519
|
+
res.writeHead(404).end();
|
|
3520
|
+
return;
|
|
3521
|
+
}
|
|
3522
|
+
if (req.method !== "POST") {
|
|
3523
|
+
res.writeHead(405).end();
|
|
3524
|
+
return;
|
|
3525
|
+
}
|
|
3526
|
+
const token = this._token;
|
|
3527
|
+
if (!token || !hasValidBearerToken(req.headers.authorization, token)) {
|
|
3528
|
+
writeJsonError(res, 401, "Unauthorized", {
|
|
3529
|
+
"www-authenticate": "Bearer"
|
|
3530
|
+
});
|
|
3531
|
+
return;
|
|
3532
|
+
}
|
|
3533
|
+
const server = this.createMcpServer();
|
|
3534
|
+
const transport = new (0, _streamableHttpjs.StreamableHTTPServerTransport)({
|
|
3535
|
+
sessionIdGenerator: void 0
|
|
3536
|
+
});
|
|
3537
|
+
res.on("close", () => {
|
|
3538
|
+
void transport.close();
|
|
3539
|
+
void server.close();
|
|
3540
|
+
});
|
|
3541
|
+
try {
|
|
3542
|
+
const body = await readJsonBody(req);
|
|
3543
|
+
await server.connect(transport);
|
|
3544
|
+
await transport.handleRequest(req, res, body);
|
|
3545
|
+
} catch (error) {
|
|
3546
|
+
writeJsonError(
|
|
3547
|
+
res,
|
|
3548
|
+
500,
|
|
3549
|
+
error instanceof Error ? error.message : "Internal server error"
|
|
3550
|
+
);
|
|
3551
|
+
await transport.close();
|
|
3552
|
+
await server.close();
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
}, _class4);
|
|
3556
|
+
function createSdkMcpServer(options) {
|
|
3557
|
+
return new SdkMcpServer(options);
|
|
3558
|
+
}
|
|
3559
|
+
async function startSdkMcpServers(servers) {
|
|
3560
|
+
if (!servers) {
|
|
3561
|
+
return { cleanup: async () => {
|
|
3562
|
+
} };
|
|
3563
|
+
}
|
|
3564
|
+
const startedServers = [];
|
|
3565
|
+
const mcpServers = [];
|
|
3566
|
+
try {
|
|
3567
|
+
for (const server of servers) {
|
|
3568
|
+
if (isSdkMcpServer(server)) {
|
|
3569
|
+
mcpServers.push(await server.start());
|
|
3570
|
+
startedServers.push(server);
|
|
3571
|
+
} else {
|
|
3572
|
+
mcpServers.push(server);
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
} catch (error) {
|
|
3576
|
+
await Promise.all(startedServers.map((server) => server.close()));
|
|
3577
|
+
throw error;
|
|
3578
|
+
}
|
|
3579
|
+
return {
|
|
3580
|
+
mcpServers,
|
|
3581
|
+
cleanup: async () => {
|
|
3582
|
+
await Promise.all(startedServers.map((server) => server.close()));
|
|
3583
|
+
}
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
// src/session.ts
|
|
3588
|
+
var DroidSession = (_class5 = class _DroidSession {
|
|
3589
|
+
/** @internal */
|
|
3590
|
+
constructor(client, sessionId, metadata, _runtime, cleanupCallbacks = []) {;_class5.prototype.__init23.call(this);_class5.prototype.__init24.call(this);_class5.prototype.__init25.call(this);_class5.prototype.__init26.call(this);_class5.prototype.__init27.call(this);_class5.prototype.__init28.call(this);
|
|
3591
|
+
this._runtime = _runtime;
|
|
3592
|
+
this._client = client;
|
|
3593
|
+
this._sessionId = sessionId;
|
|
3594
|
+
this._settings = metadata.settings;
|
|
3595
|
+
this._cwd = metadata.cwd;
|
|
3596
|
+
this._cleanupCallbacks = cleanupCallbacks;
|
|
3597
|
+
this._bindMetadataNotifications();
|
|
3598
|
+
this._bindAbortSignal();
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
|
|
3602
|
+
|
|
3603
|
+
|
|
3604
|
+
|
|
3605
|
+
__init23() {this._settingsRevision = 0}
|
|
3606
|
+
__init24() {this._status = "active"}
|
|
3607
|
+
|
|
3608
|
+
__init25() {this._cleanupAbortSignal = null}
|
|
3609
|
+
__init26() {this._cleanupCallbacks = []}
|
|
3610
|
+
__init27() {this._activeBridges = /* @__PURE__ */ new Set()}
|
|
3611
|
+
__init28() {this._notificationCleanups = /* @__PURE__ */ new Set()}
|
|
3612
|
+
get id() {
|
|
3613
|
+
return this._sessionId;
|
|
3614
|
+
}
|
|
3615
|
+
get settings() {
|
|
3616
|
+
return this._settings;
|
|
3617
|
+
}
|
|
3618
|
+
get cwd() {
|
|
3619
|
+
return this._cwd;
|
|
3620
|
+
}
|
|
3621
|
+
async *stream(prompt, options) {
|
|
3622
|
+
this._ensureNotClosed();
|
|
3623
|
+
yield* _chunk4G2RKM2Hjs.streamFromClient.call(void 0,
|
|
3624
|
+
{
|
|
3625
|
+
onNotification: (handler) => this._client.onNotification((notification) => {
|
|
3626
|
+
const inner = _chunk4G2RKM2Hjs.extractInnerNotification.call(void 0, notification);
|
|
3627
|
+
if (inner) handler(inner);
|
|
3628
|
+
}),
|
|
3629
|
+
onError: (handler) => this._client.onError(handler),
|
|
3630
|
+
addUserMessage: (params) => this._client.addUserMessage(params),
|
|
3631
|
+
interruptSession: () => this._client.interruptSession()
|
|
3632
|
+
},
|
|
3633
|
+
this._sessionId,
|
|
3634
|
+
this._activeBridges,
|
|
3635
|
+
prompt,
|
|
3636
|
+
options
|
|
3637
|
+
);
|
|
3638
|
+
}
|
|
3639
|
+
async interrupt() {
|
|
3640
|
+
this._ensureNotClosed();
|
|
3641
|
+
await this._client.interruptSession();
|
|
3642
|
+
}
|
|
3643
|
+
async close() {
|
|
3644
|
+
if (this._status === "closed" || this._status === "replaced") {
|
|
3645
|
+
return;
|
|
3646
|
+
}
|
|
3647
|
+
this._status = "closed";
|
|
3648
|
+
this._releaseHandleSubscriptions();
|
|
3649
|
+
_optionalChain([this, 'access', _47 => _47._cleanupAbortSignal, 'optionalCall', _48 => _48()]);
|
|
3650
|
+
this._cleanupAbortSignal = null;
|
|
3651
|
+
for (const bridge of this._activeBridges) {
|
|
3652
|
+
bridge.signalDone();
|
|
3653
|
+
bridge.release();
|
|
3654
|
+
}
|
|
3655
|
+
try {
|
|
3656
|
+
await this._client.closeSession({ reason: "other" }).catch(() => {
|
|
3657
|
+
});
|
|
3658
|
+
await this._client.close();
|
|
3659
|
+
} finally {
|
|
3660
|
+
const cleanups = this._cleanupCallbacks.splice(0);
|
|
3661
|
+
await Promise.all(cleanups.map((cleanup) => cleanup()));
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
async updateSettings(params) {
|
|
3665
|
+
this._ensureNotClosed();
|
|
3666
|
+
const revision = this._settingsRevision;
|
|
3667
|
+
const result = _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
3668
|
+
await this._client.updateSessionSettings(params)
|
|
3669
|
+
);
|
|
3670
|
+
if (params.disabledToolIds !== void 0) {
|
|
3671
|
+
this._runtime.loadParams.disabledToolIds = params.disabledToolIds;
|
|
3672
|
+
}
|
|
3673
|
+
if (this._settingsRevision === revision) {
|
|
3674
|
+
this._settings = _chunk4G2RKM2Hjs.mergeSessionSettings.call(void 0, this._settings, params);
|
|
3675
|
+
}
|
|
3676
|
+
return result;
|
|
3677
|
+
}
|
|
3678
|
+
async enterSpecMode(params = {}) {
|
|
3679
|
+
return this.updateSettings({
|
|
3680
|
+
interactionMode: "spec" /* Spec */,
|
|
3681
|
+
...params
|
|
3682
|
+
});
|
|
3683
|
+
}
|
|
3684
|
+
async exitSpecMode() {
|
|
3685
|
+
return this.updateSettings({
|
|
3686
|
+
interactionMode: "auto" /* Auto */
|
|
3687
|
+
});
|
|
3688
|
+
}
|
|
3689
|
+
async addMcpServer(params) {
|
|
3690
|
+
this._ensureNotClosed();
|
|
3691
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.addMcpServer(params));
|
|
3692
|
+
}
|
|
3693
|
+
async removeMcpServer(params) {
|
|
3694
|
+
this._ensureNotClosed();
|
|
3695
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.removeMcpServer(params));
|
|
3696
|
+
}
|
|
3697
|
+
async toggleMcpServer(params) {
|
|
3698
|
+
this._ensureNotClosed();
|
|
3699
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.toggleMcpServer(params));
|
|
3700
|
+
}
|
|
3701
|
+
async listMcpServers() {
|
|
3702
|
+
this._ensureNotClosed();
|
|
3703
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.listMcpServers());
|
|
3704
|
+
}
|
|
3705
|
+
async listMcpTools() {
|
|
3706
|
+
this._ensureNotClosed();
|
|
3707
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.listMcpTools()).tools;
|
|
3708
|
+
}
|
|
3709
|
+
async listTools(params = {}) {
|
|
3710
|
+
this._ensureNotClosed();
|
|
3711
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.listTools(params)).tools.map(
|
|
3712
|
+
({ id: _protocolId, llmId, currentlyAllowed, ...tool2 }) => ({
|
|
3713
|
+
...tool2,
|
|
3714
|
+
id: llmId,
|
|
3715
|
+
allowed: currentlyAllowed
|
|
3716
|
+
})
|
|
3717
|
+
);
|
|
3718
|
+
}
|
|
3719
|
+
async authenticateMcpServer(params) {
|
|
3720
|
+
this._ensureNotClosed();
|
|
3721
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
3722
|
+
await this._client.authenticateMcpServer(params)
|
|
3723
|
+
);
|
|
3724
|
+
}
|
|
3725
|
+
async listSkills() {
|
|
3726
|
+
this._ensureNotClosed();
|
|
3727
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.listSkills());
|
|
3728
|
+
}
|
|
3729
|
+
async setSkillDisabled(params) {
|
|
3730
|
+
this._ensureNotClosed();
|
|
3731
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
3732
|
+
await this._client.setSkillDisabled(
|
|
3733
|
+
params.skillName,
|
|
3734
|
+
params.disabled,
|
|
3735
|
+
params.settingsLevel
|
|
3736
|
+
)
|
|
3737
|
+
);
|
|
3738
|
+
}
|
|
3739
|
+
async getRewindInfo(params) {
|
|
3740
|
+
this._ensureNotClosed();
|
|
3741
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.getRewindInfo(params));
|
|
3742
|
+
}
|
|
3743
|
+
async rewind(params) {
|
|
3744
|
+
const { session, result } = await this._runReplacement(
|
|
3745
|
+
() => this._client.executeRewind(params).then(_chunk4G2RKM2Hjs.unwrapResponseResult)
|
|
3746
|
+
);
|
|
3747
|
+
const { newSessionId: _newSessionId, ...metadata } = result;
|
|
3748
|
+
return { session, ...metadata };
|
|
3749
|
+
}
|
|
3750
|
+
async compact(params) {
|
|
3751
|
+
const { session, result } = await this._runReplacement(
|
|
3752
|
+
() => this._client.compactSession(_nullishCoalesce(params, () => ( {}))).then(_chunk4G2RKM2Hjs.unwrapResponseResult)
|
|
3753
|
+
);
|
|
3754
|
+
return { session, removedCount: result.removedCount };
|
|
3755
|
+
}
|
|
3756
|
+
async fork(params = {}) {
|
|
3757
|
+
const { session } = await this._runReplacement(
|
|
3758
|
+
() => this._client.forkSession(params).then(_chunk4G2RKM2Hjs.unwrapResponseResult)
|
|
3759
|
+
);
|
|
3760
|
+
return session;
|
|
3761
|
+
}
|
|
3762
|
+
async getContextStats() {
|
|
3763
|
+
this._ensureNotClosed();
|
|
3764
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.getContextStats());
|
|
3765
|
+
}
|
|
3766
|
+
async rename(params) {
|
|
3767
|
+
this._ensureNotClosed();
|
|
3768
|
+
_chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, await this._client.renameSession(params));
|
|
3769
|
+
}
|
|
3770
|
+
onNotification(callback, filter) {
|
|
3771
|
+
this._ensureNotClosed();
|
|
3772
|
+
const unsubscribe = this._client.onNotification(callback, filter);
|
|
3773
|
+
const cleanup = () => {
|
|
3774
|
+
this._notificationCleanups.delete(cleanup);
|
|
3775
|
+
unsubscribe();
|
|
3776
|
+
};
|
|
3777
|
+
this._notificationCleanups.add(cleanup);
|
|
3778
|
+
return cleanup;
|
|
3779
|
+
}
|
|
3780
|
+
_ensureNotClosed() {
|
|
3781
|
+
if (this._status === "replaced" && this._replacementSessionId) {
|
|
3782
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionReplacedError)(
|
|
3783
|
+
this._sessionId,
|
|
3784
|
+
this._replacementSessionId
|
|
3785
|
+
);
|
|
3786
|
+
}
|
|
3787
|
+
if (this._status !== "active") {
|
|
3788
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
3789
|
+
this._status === "replacing" ? "Session replacement is already in progress." : "Session has been closed. Create a new session to continue."
|
|
3790
|
+
);
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
_beginReplacement() {
|
|
3794
|
+
this._ensureNotClosed();
|
|
3795
|
+
if (this._activeBridges.size > 0) {
|
|
3796
|
+
throw new (0, _chunk4G2RKM2Hjs.ConcurrentStreamError)(this._sessionId);
|
|
3797
|
+
}
|
|
3798
|
+
this._status = "replacing";
|
|
3799
|
+
}
|
|
3800
|
+
async _runReplacement(operation) {
|
|
3801
|
+
this._beginReplacement();
|
|
3802
|
+
let result;
|
|
3803
|
+
try {
|
|
3804
|
+
result = await operation();
|
|
3805
|
+
} catch (error) {
|
|
3806
|
+
if (this._status === "replacing") {
|
|
3807
|
+
this._status = "active";
|
|
3808
|
+
}
|
|
3809
|
+
throw error;
|
|
3810
|
+
}
|
|
3811
|
+
if (this._status !== "replacing") {
|
|
3812
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionReplacementError)(this._sessionId, result.newSessionId, {
|
|
3813
|
+
cause: new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
3814
|
+
"Session closed while replacement was in progress."
|
|
3815
|
+
),
|
|
3816
|
+
rollbackError: new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
3817
|
+
"The source session was already closed."
|
|
3818
|
+
)
|
|
3819
|
+
});
|
|
3820
|
+
}
|
|
3821
|
+
return {
|
|
3822
|
+
session: await this._loadReplacement(result.newSessionId),
|
|
3823
|
+
result
|
|
3824
|
+
};
|
|
3825
|
+
}
|
|
3826
|
+
async _loadReplacement(replacementSessionId) {
|
|
3827
|
+
try {
|
|
3828
|
+
const loadResult = _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
3829
|
+
await this._client.loadSession({
|
|
3830
|
+
...this._runtime.loadParams,
|
|
3831
|
+
sessionId: replacementSessionId
|
|
3832
|
+
})
|
|
3833
|
+
);
|
|
3834
|
+
if (this._status !== "replacing") {
|
|
3835
|
+
throw new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
3836
|
+
"Session closed while replacement was loading."
|
|
3837
|
+
);
|
|
3838
|
+
}
|
|
3839
|
+
_optionalChain([this, 'access', _49 => _49._cleanupAbortSignal, 'optionalCall', _50 => _50()]);
|
|
3840
|
+
this._cleanupAbortSignal = null;
|
|
3841
|
+
this._releaseHandleSubscriptions();
|
|
3842
|
+
const cleanupCallbacks = this._cleanupCallbacks;
|
|
3843
|
+
this._cleanupCallbacks = [];
|
|
3844
|
+
const replacement = new _DroidSession(
|
|
3845
|
+
this._client,
|
|
3846
|
+
replacementSessionId,
|
|
3847
|
+
{ settings: loadResult.settings, cwd: loadResult.cwd },
|
|
3848
|
+
this._runtime,
|
|
3849
|
+
cleanupCallbacks
|
|
3850
|
+
);
|
|
3851
|
+
this._replacementSessionId = replacementSessionId;
|
|
3852
|
+
this._status = "replaced";
|
|
3853
|
+
return replacement;
|
|
3854
|
+
} catch (cause) {
|
|
3855
|
+
if (this._status !== "replacing") {
|
|
3856
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionReplacementError)(
|
|
3857
|
+
this._sessionId,
|
|
3858
|
+
replacementSessionId,
|
|
3859
|
+
{
|
|
3860
|
+
cause,
|
|
3861
|
+
rollbackError: new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
3862
|
+
"The source session was closed before rollback."
|
|
3863
|
+
)
|
|
3864
|
+
}
|
|
3865
|
+
);
|
|
3866
|
+
}
|
|
3867
|
+
let rollbackResult;
|
|
3868
|
+
try {
|
|
3869
|
+
rollbackResult = _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
3870
|
+
await this._client.loadSession({
|
|
3871
|
+
...this._runtime.loadParams,
|
|
3872
|
+
sessionId: this._sessionId
|
|
3873
|
+
})
|
|
3874
|
+
);
|
|
3875
|
+
} catch (rollbackError) {
|
|
3876
|
+
await this._disposeAfterFailedRollback();
|
|
3877
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionReplacementError)(
|
|
3878
|
+
this._sessionId,
|
|
3879
|
+
replacementSessionId,
|
|
3880
|
+
{ cause, rollbackError }
|
|
3881
|
+
);
|
|
3882
|
+
}
|
|
3883
|
+
if (this._status !== "replacing") {
|
|
3884
|
+
const rollbackError = new (0, _chunk4G2RKM2Hjs.ConnectionError)(
|
|
3885
|
+
"Session closed while replacement rollback was loading."
|
|
3886
|
+
);
|
|
3887
|
+
await this._disposeAfterFailedRollback();
|
|
3888
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionReplacementError)(
|
|
3889
|
+
this._sessionId,
|
|
3890
|
+
replacementSessionId,
|
|
3891
|
+
{ cause, rollbackError }
|
|
3892
|
+
);
|
|
3893
|
+
}
|
|
3894
|
+
this._settings = rollbackResult.settings;
|
|
3895
|
+
this._cwd = rollbackResult.cwd;
|
|
3896
|
+
this._status = "active";
|
|
3897
|
+
throw new (0, _chunk4G2RKM2Hjs.SessionReplacementError)(this._sessionId, replacementSessionId, {
|
|
3898
|
+
cause
|
|
3899
|
+
});
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
_bindAbortSignal() {
|
|
3903
|
+
this._cleanupAbortSignal = _chunk4G2RKM2Hjs.wireAbortSignal.call(void 0,
|
|
3904
|
+
this._runtime.abortSignal,
|
|
3905
|
+
() => void this.close()
|
|
3906
|
+
);
|
|
3907
|
+
}
|
|
3908
|
+
_bindMetadataNotifications() {
|
|
3909
|
+
const unsubscribe = this._client.onNotification((notification) => {
|
|
3910
|
+
const inner = _chunk4G2RKM2Hjs.extractInnerNotification.call(void 0, notification);
|
|
3911
|
+
if (_optionalChain([inner, 'optionalAccess', _51 => _51.type]) === "settings_updated" /* SETTINGS_UPDATED */) {
|
|
3912
|
+
this._settings = _chunk4G2RKM2Hjs.mergeSessionSettings.call(void 0, this._settings, inner.settings);
|
|
3913
|
+
this._settingsRevision++;
|
|
3914
|
+
} else if (_optionalChain([inner, 'optionalAccess', _52 => _52.type]) === "session_working_directory_changed" /* SESSION_WORKING_DIRECTORY_CHANGED */) {
|
|
3915
|
+
this._cwd = inner.cwd;
|
|
3916
|
+
}
|
|
3917
|
+
});
|
|
3918
|
+
const cleanup = () => {
|
|
3919
|
+
this._notificationCleanups.delete(cleanup);
|
|
3920
|
+
unsubscribe();
|
|
3921
|
+
};
|
|
3922
|
+
this._notificationCleanups.add(cleanup);
|
|
3923
|
+
}
|
|
3924
|
+
_releaseHandleSubscriptions() {
|
|
3925
|
+
for (const cleanup of [...this._notificationCleanups]) cleanup();
|
|
3926
|
+
}
|
|
3927
|
+
async _disposeAfterFailedRollback() {
|
|
3928
|
+
this._status = "closed";
|
|
3929
|
+
_optionalChain([this, 'access', _53 => _53._cleanupAbortSignal, 'optionalCall', _54 => _54()]);
|
|
3930
|
+
this._cleanupAbortSignal = null;
|
|
3931
|
+
this._releaseHandleSubscriptions();
|
|
3932
|
+
await closeQuietly(this._client);
|
|
3933
|
+
const cleanups = this._cleanupCallbacks.splice(0);
|
|
3934
|
+
await Promise.allSettled(
|
|
3935
|
+
cleanups.map((cleanup) => Promise.resolve().then(cleanup))
|
|
3936
|
+
);
|
|
3937
|
+
}
|
|
3938
|
+
}, _class5);
|
|
3939
|
+
function createReplacementLoadParams(options, mcpServers) {
|
|
3940
|
+
return {
|
|
3941
|
+
mcpServers,
|
|
3942
|
+
disabledToolIds: options.disabledToolIds,
|
|
3943
|
+
autoRejectPermissionRequests: options.autoRejectPermissionRequests,
|
|
3944
|
+
disableBuiltinSkills: options.disableBuiltinSkills,
|
|
3945
|
+
sessionSource: options.sessionSource
|
|
3946
|
+
};
|
|
3947
|
+
}
|
|
3948
|
+
async function createSession(options = {}) {
|
|
3949
|
+
const { client } = await createConfiguredClient(options);
|
|
3950
|
+
let cleanupInitAbortSignal = _optionalChain([options, 'access', _55 => _55.abortSignal, 'optionalAccess', _56 => _56.aborted]) ? () => {
|
|
3951
|
+
} : _chunk4G2RKM2Hjs.wireAbortSignal.call(void 0, options.abortSignal, () => {
|
|
3952
|
+
void closeQuietly(client);
|
|
3953
|
+
});
|
|
3954
|
+
let sdkMcpServers;
|
|
3955
|
+
try {
|
|
3956
|
+
sdkMcpServers = await startSdkMcpServers(options.mcpServers);
|
|
3957
|
+
const initParams = buildInitParams({
|
|
3958
|
+
...options,
|
|
3959
|
+
mcpServers: sdkMcpServers.mcpServers
|
|
3960
|
+
});
|
|
3961
|
+
const initResult = _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
3962
|
+
await client.initializeSession(initParams)
|
|
3963
|
+
);
|
|
3964
|
+
const session = new DroidSession(
|
|
3965
|
+
client,
|
|
3966
|
+
initResult.sessionId,
|
|
3967
|
+
{
|
|
3968
|
+
settings: initResult.settings,
|
|
3969
|
+
cwd: _nullishCoalesce(_optionalChain([initResult, 'access', _57 => _57.worktree, 'optionalAccess', _58 => _58.path]), () => ( initParams.cwd))
|
|
3970
|
+
},
|
|
3971
|
+
{
|
|
3972
|
+
abortSignal: options.abortSignal,
|
|
3973
|
+
loadParams: createReplacementLoadParams(
|
|
3974
|
+
options,
|
|
3975
|
+
sdkMcpServers.mcpServers
|
|
3976
|
+
)
|
|
3977
|
+
},
|
|
3978
|
+
[sdkMcpServers.cleanup]
|
|
3979
|
+
);
|
|
3980
|
+
cleanupInitAbortSignal();
|
|
3981
|
+
cleanupInitAbortSignal = () => {
|
|
3982
|
+
};
|
|
3983
|
+
return session;
|
|
3984
|
+
} catch (error) {
|
|
3985
|
+
cleanupInitAbortSignal();
|
|
3986
|
+
await _optionalChain([sdkMcpServers, 'optionalAccess', _59 => _59.cleanup, 'call', _60 => _60()]);
|
|
3987
|
+
await closeQuietly(client);
|
|
3988
|
+
throw error;
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
async function resumeSession(sessionId, options = {}) {
|
|
3992
|
+
const { client } = await createConfiguredClient(options);
|
|
3993
|
+
let cleanupLoadAbortSignal = _optionalChain([options, 'access', _61 => _61.abortSignal, 'optionalAccess', _62 => _62.aborted]) ? () => {
|
|
3994
|
+
} : _chunk4G2RKM2Hjs.wireAbortSignal.call(void 0, options.abortSignal, () => {
|
|
3995
|
+
void closeQuietly(client);
|
|
3996
|
+
});
|
|
3997
|
+
let sdkMcpServers;
|
|
3998
|
+
try {
|
|
3999
|
+
sdkMcpServers = await startSdkMcpServers(options.mcpServers);
|
|
4000
|
+
const replacementLoadParams = createReplacementLoadParams(
|
|
4001
|
+
options,
|
|
4002
|
+
sdkMcpServers.mcpServers
|
|
4003
|
+
);
|
|
4004
|
+
const loadResult = _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0,
|
|
4005
|
+
await client.loadSession({ sessionId, ...replacementLoadParams })
|
|
4006
|
+
);
|
|
4007
|
+
const session = new DroidSession(
|
|
4008
|
+
client,
|
|
4009
|
+
sessionId,
|
|
4010
|
+
{ settings: loadResult.settings, cwd: loadResult.cwd },
|
|
4011
|
+
{
|
|
4012
|
+
abortSignal: options.abortSignal,
|
|
4013
|
+
loadParams: replacementLoadParams
|
|
4014
|
+
},
|
|
4015
|
+
[sdkMcpServers.cleanup]
|
|
4016
|
+
);
|
|
4017
|
+
cleanupLoadAbortSignal();
|
|
4018
|
+
cleanupLoadAbortSignal = () => {
|
|
4019
|
+
};
|
|
4020
|
+
return session;
|
|
4021
|
+
} catch (error) {
|
|
4022
|
+
cleanupLoadAbortSignal();
|
|
4023
|
+
await _optionalChain([sdkMcpServers, 'optionalAccess', _63 => _63.cleanup, 'call', _64 => _64()]);
|
|
4024
|
+
await closeQuietly(client);
|
|
4025
|
+
throw error;
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
// src/run.ts
|
|
4030
|
+
async function run(prompt, options = {}) {
|
|
4031
|
+
const session = await createSession(options);
|
|
4032
|
+
try {
|
|
4033
|
+
for await (const msg of session.stream(prompt, {
|
|
4034
|
+
...options,
|
|
4035
|
+
includePartialMessages: false
|
|
4036
|
+
})) {
|
|
4037
|
+
if (msg.type === _chunk4G2RKM2Hjs.DroidMessageType.Result) {
|
|
4038
|
+
return msg;
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
throw new Error("Stream completed without a result message");
|
|
4042
|
+
} finally {
|
|
4043
|
+
await session.close();
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
// src/session-discovery.ts
|
|
4048
|
+
|
|
4049
|
+
|
|
4050
|
+
|
|
4051
|
+
var FAVORITES_FILE = ".favorites";
|
|
4052
|
+
var SESSION_EXTENSION = ".jsonl";
|
|
4053
|
+
var SETTINGS_SUFFIX = ".settings.json";
|
|
4054
|
+
var MISSION_TAG_PREFIX = "mission:";
|
|
4055
|
+
var MISSION_ID_METADATA_KEY = "missionId";
|
|
4056
|
+
var DECOMP_SESSION_TYPE_TAG = "decompSessionType";
|
|
4057
|
+
var DECOMP_SESSION_TYPE_METADATA_KEY = "value";
|
|
4058
|
+
var LF = 10;
|
|
4059
|
+
var CR = 13;
|
|
4060
|
+
var SPACE = 32;
|
|
4061
|
+
var TAB = 9;
|
|
4062
|
+
var PARSE_OVERSAMPLE = 20;
|
|
4063
|
+
function readFileBuffer(filePath) {
|
|
4064
|
+
try {
|
|
4065
|
+
return fs3.readFileSync(filePath);
|
|
4066
|
+
} catch (e8) {
|
|
4067
|
+
return null;
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
function parseJsonBuffer(buf) {
|
|
4071
|
+
try {
|
|
4072
|
+
return JSON.parse(buf.toString("utf-8"));
|
|
4073
|
+
} catch (e9) {
|
|
4074
|
+
return null;
|
|
4075
|
+
}
|
|
4076
|
+
}
|
|
4077
|
+
function scanBufferForLines(buf) {
|
|
4078
|
+
let nonEmptyLineCount = 0;
|
|
4079
|
+
let firstLineEnd = -1;
|
|
4080
|
+
let currentLineHasContent = false;
|
|
4081
|
+
for (let i = 0; i < buf.length; i++) {
|
|
4082
|
+
const ch = buf[i];
|
|
4083
|
+
if (ch === LF) {
|
|
4084
|
+
if (currentLineHasContent) nonEmptyLineCount++;
|
|
4085
|
+
if (firstLineEnd === -1) firstLineEnd = i;
|
|
4086
|
+
currentLineHasContent = false;
|
|
4087
|
+
} else if (ch !== CR && ch !== SPACE && ch !== TAB) {
|
|
4088
|
+
currentLineHasContent = true;
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
if (currentLineHasContent) nonEmptyLineCount++;
|
|
4092
|
+
const end = firstLineEnd === -1 ? buf.length : firstLineEnd > 0 && buf[firstLineEnd - 1] === CR ? firstLineEnd - 1 : firstLineEnd;
|
|
4093
|
+
return {
|
|
4094
|
+
firstLine: buf.subarray(0, end),
|
|
4095
|
+
nonEmptyLineCount
|
|
4096
|
+
};
|
|
4097
|
+
}
|
|
4098
|
+
function loadFavorites(sessionsDir) {
|
|
4099
|
+
const buf = readFileBuffer(path2.join(sessionsDir, FAVORITES_FILE));
|
|
4100
|
+
if (!buf) return /* @__PURE__ */ new Set();
|
|
4101
|
+
const parsed = parseJsonBuffer(buf);
|
|
4102
|
+
if (!Array.isArray(parsed)) return /* @__PURE__ */ new Set();
|
|
4103
|
+
return new Set(parsed.filter((id) => typeof id === "string"));
|
|
4104
|
+
}
|
|
4105
|
+
function loadSettingsFile(directory, sessionId) {
|
|
4106
|
+
const buf = readFileBuffer(
|
|
4107
|
+
path2.join(directory, `${sessionId}${SETTINGS_SUFFIX}`)
|
|
4108
|
+
);
|
|
4109
|
+
if (!buf) return null;
|
|
4110
|
+
const parsed = parseJsonBuffer(buf);
|
|
4111
|
+
if (parsed === null) return null;
|
|
4112
|
+
const result = _chunk4G2RKM2Hjs.SessionSettingsFileSchema.safeParse(parsed);
|
|
4113
|
+
return result.success ? result.data : null;
|
|
4114
|
+
}
|
|
4115
|
+
function getMissionMetadataFromTags(settings) {
|
|
4116
|
+
if (!_optionalChain([settings, 'optionalAccess', _65 => _65.tags])) return {};
|
|
4117
|
+
const missionTag = settings.tags.find(
|
|
4118
|
+
(tag) => tag.name.startsWith(MISSION_TAG_PREFIX)
|
|
4119
|
+
);
|
|
4120
|
+
const roleTag = settings.tags.find(
|
|
4121
|
+
(tag) => tag.name === DECOMP_SESSION_TYPE_TAG
|
|
4122
|
+
);
|
|
4123
|
+
return {
|
|
4124
|
+
decompMissionId: _optionalChain([missionTag, 'optionalAccess', _66 => _66.metadata, 'optionalAccess', _67 => _67[MISSION_ID_METADATA_KEY]]),
|
|
4125
|
+
decompSessionType: _optionalChain([roleTag, 'optionalAccess', _68 => _68.metadata, 'optionalAccess', _69 => _69[DECOMP_SESSION_TYPE_METADATA_KEY]])
|
|
4126
|
+
};
|
|
4127
|
+
}
|
|
4128
|
+
function parseSessionFile(candidate, ctx) {
|
|
4129
|
+
const buf = readFileBuffer(candidate.sessionPath);
|
|
4130
|
+
if (!buf) return null;
|
|
4131
|
+
const scanned = scanBufferForLines(buf);
|
|
4132
|
+
const firstParsed = parseJsonBuffer(scanned.firstLine);
|
|
4133
|
+
if (firstParsed === null) return null;
|
|
4134
|
+
const firstResult = _chunk4G2RKM2Hjs.SessionStartEventSchema.safeParse(firstParsed);
|
|
4135
|
+
if (!firstResult.success) return null;
|
|
4136
|
+
const summary = firstResult.data;
|
|
4137
|
+
if (ctx.requiredCwd !== void 0 && (summary.cwd === void 0 || path2.resolve(summary.cwd) !== ctx.requiredCwd)) {
|
|
4138
|
+
return null;
|
|
4139
|
+
}
|
|
4140
|
+
const settingsName = `${candidate.sessionId}${SETTINGS_SUFFIX}`;
|
|
4141
|
+
const settings = candidate.siblingNames.has(settingsName) ? loadSettingsFile(candidate.directory, candidate.sessionId) : null;
|
|
4142
|
+
if (_optionalChain([settings, 'optionalAccess', _70 => _70.archivedAt])) return null;
|
|
4143
|
+
const tagMeta = getMissionMetadataFromTags(settings);
|
|
4144
|
+
const decompSessionType = _nullishCoalesce(summary.decompSessionType, () => ( _chunk4G2RKM2Hjs.SessionStartDecompSessionTypeSchema.safeParse(tagMeta.decompSessionType).data));
|
|
4145
|
+
const messageCount = Math.max(0, scanned.nonEmptyLineCount - 1);
|
|
4146
|
+
return {
|
|
4147
|
+
id: candidate.sessionId,
|
|
4148
|
+
title: summary.title,
|
|
4149
|
+
owner: _nullishCoalesce(summary.owner, () => ( "")),
|
|
4150
|
+
messageCount,
|
|
4151
|
+
modifiedTime: candidate.stats.mtime,
|
|
4152
|
+
createdTime: candidate.stats.birthtime || candidate.stats.ctime,
|
|
4153
|
+
isFavorite: ctx.favorites.has(candidate.sessionId),
|
|
4154
|
+
cwd: summary.cwd,
|
|
4155
|
+
decompSessionType,
|
|
4156
|
+
decompMissionId: _nullishCoalesce(tagMeta.decompMissionId, () => ( summary.decompMissionId))
|
|
4157
|
+
};
|
|
4158
|
+
}
|
|
4159
|
+
function readDirEntries(directory) {
|
|
4160
|
+
try {
|
|
4161
|
+
return fs3.readdirSync(directory, { withFileTypes: true });
|
|
4162
|
+
} catch (e10) {
|
|
4163
|
+
return [];
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
function collectCandidates(directory, entries) {
|
|
4167
|
+
const siblingNames = new Set(entries.map((e) => e.name));
|
|
4168
|
+
const candidates = [];
|
|
4169
|
+
for (const entry of entries) {
|
|
4170
|
+
if (entry.isDirectory()) continue;
|
|
4171
|
+
if (!entry.name.endsWith(SESSION_EXTENSION)) continue;
|
|
4172
|
+
const sessionPath = path2.join(directory, entry.name);
|
|
4173
|
+
let stats;
|
|
4174
|
+
try {
|
|
4175
|
+
stats = fs3.statSync(sessionPath);
|
|
4176
|
+
} catch (e11) {
|
|
4177
|
+
continue;
|
|
4178
|
+
}
|
|
4179
|
+
candidates.push({
|
|
4180
|
+
sessionId: entry.name.slice(0, -SESSION_EXTENSION.length),
|
|
4181
|
+
sessionPath,
|
|
4182
|
+
directory,
|
|
4183
|
+
siblingNames,
|
|
4184
|
+
stats
|
|
4185
|
+
});
|
|
4186
|
+
}
|
|
4187
|
+
return candidates;
|
|
4188
|
+
}
|
|
4189
|
+
function parseUpTo(candidates, ctx, limit) {
|
|
4190
|
+
const out = [];
|
|
4191
|
+
for (const candidate of candidates) {
|
|
4192
|
+
if (limit !== void 0 && out.length >= limit) break;
|
|
4193
|
+
const metadata = parseSessionFile(candidate, ctx);
|
|
4194
|
+
if (metadata) out.push(metadata);
|
|
4195
|
+
}
|
|
4196
|
+
return out;
|
|
4197
|
+
}
|
|
4198
|
+
function sanitizePathToDirectoryName(cwd) {
|
|
4199
|
+
let expandedPath = cwd;
|
|
4200
|
+
if (cwd.startsWith("~/") || cwd === "~") {
|
|
4201
|
+
expandedPath = path2.join(os.homedir(), cwd.slice(1));
|
|
4202
|
+
}
|
|
4203
|
+
const absolutePath = path2.resolve(expandedPath);
|
|
4204
|
+
let canonicalPath = absolutePath;
|
|
4205
|
+
try {
|
|
4206
|
+
canonicalPath = fs3.realpathSync(absolutePath);
|
|
4207
|
+
} catch (e12) {
|
|
4208
|
+
canonicalPath = absolutePath;
|
|
4209
|
+
}
|
|
4210
|
+
const normalized = canonicalPath.replace(/[\\/]+$/, "");
|
|
4211
|
+
if (process.platform === "win32") {
|
|
4212
|
+
return `-${normalized.replace(/^([A-Z]):/i, "$1").replace(/[\\/]+/g, "-")}`;
|
|
4213
|
+
}
|
|
4214
|
+
return `-${normalized.replace(/^\/+/, "").replace(/\/+/g, "-")}`;
|
|
4215
|
+
}
|
|
4216
|
+
function getDefaultSessionsDir() {
|
|
4217
|
+
return path2.join(os.homedir(), ".factory", "sessions");
|
|
4218
|
+
}
|
|
4219
|
+
async function listSessions(options = {}) {
|
|
4220
|
+
const sessionsDir = _nullishCoalesce(options.sessionsDir, () => ( getDefaultSessionsDir()));
|
|
4221
|
+
const favorites = loadFavorites(sessionsDir);
|
|
4222
|
+
const rootEntries = readDirEntries(sessionsDir);
|
|
4223
|
+
const legacyCandidates = collectCandidates(sessionsDir, rootEntries);
|
|
4224
|
+
const projectCandidates = [];
|
|
4225
|
+
let requiredCwd;
|
|
4226
|
+
if (options.fetchOutsideCWD) {
|
|
4227
|
+
for (const entry of rootEntries) {
|
|
4228
|
+
if (!entry.isDirectory()) continue;
|
|
4229
|
+
if (!entry.name.startsWith("-")) continue;
|
|
4230
|
+
const dir = path2.join(sessionsDir, entry.name);
|
|
4231
|
+
projectCandidates.push(...collectCandidates(dir, readDirEntries(dir)));
|
|
4232
|
+
}
|
|
4233
|
+
} else {
|
|
4234
|
+
const normalizedCwd = path2.resolve(_nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
4235
|
+
requiredCwd = normalizedCwd;
|
|
4236
|
+
const projectDir = path2.join(
|
|
4237
|
+
sessionsDir,
|
|
4238
|
+
sanitizePathToDirectoryName(normalizedCwd)
|
|
4239
|
+
);
|
|
4240
|
+
projectCandidates.push(
|
|
4241
|
+
...collectCandidates(projectDir, readDirEntries(projectDir))
|
|
4242
|
+
);
|
|
4243
|
+
}
|
|
4244
|
+
const byMtimeDesc = (a, b) => b.stats.mtime.getTime() - a.stats.mtime.getTime();
|
|
4245
|
+
projectCandidates.sort(byMtimeDesc);
|
|
4246
|
+
legacyCandidates.sort(byMtimeDesc);
|
|
4247
|
+
const parseLimit = options.limit !== void 0 && options.limit >= 0 ? options.limit + PARSE_OVERSAMPLE : void 0;
|
|
4248
|
+
const ctx = { favorites };
|
|
4249
|
+
const legacyCtx = requiredCwd !== void 0 ? { favorites, requiredCwd } : ctx;
|
|
4250
|
+
const projectSessions = parseUpTo(projectCandidates, ctx, parseLimit);
|
|
4251
|
+
const legacySessions = parseUpTo(legacyCandidates, legacyCtx, parseLimit);
|
|
4252
|
+
const byId = /* @__PURE__ */ new Map();
|
|
4253
|
+
for (const session of [...projectSessions, ...legacySessions]) {
|
|
4254
|
+
const existing = byId.get(session.id);
|
|
4255
|
+
if (!existing || session.modifiedTime.getTime() > existing.modifiedTime.getTime()) {
|
|
4256
|
+
byId.set(session.id, session);
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
const sorted = Array.from(byId.values()).sort(
|
|
4260
|
+
(a, b) => b.modifiedTime.getTime() - a.modifiedTime.getTime()
|
|
4261
|
+
);
|
|
4262
|
+
if (options.limit !== void 0 && options.limit >= 0) {
|
|
4263
|
+
return sorted.slice(0, options.limit);
|
|
4264
|
+
}
|
|
4265
|
+
return sorted;
|
|
4266
|
+
}
|
|
4267
|
+
|
|
4268
|
+
// src/model-discovery.ts
|
|
4269
|
+
async function listModels(options = {}) {
|
|
4270
|
+
const { includeDisabled, ...transportOptions } = options;
|
|
4271
|
+
const { client } = await createConfiguredClient(transportOptions);
|
|
4272
|
+
try {
|
|
4273
|
+
const response = await client.listModels({
|
|
4274
|
+
...includeDisabled !== void 0 && { includeDisabled }
|
|
4275
|
+
});
|
|
4276
|
+
return _chunk4G2RKM2Hjs.unwrapResponseResult.call(void 0, response).models;
|
|
4277
|
+
} finally {
|
|
4278
|
+
await closeQuietly(client);
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
|
|
4283
|
+
|
|
4284
|
+
|
|
4285
|
+
|
|
4286
|
+
|
|
4287
|
+
|
|
4288
|
+
|
|
4289
|
+
|
|
4290
|
+
|
|
4291
|
+
|
|
4292
|
+
|
|
4293
|
+
|
|
4294
|
+
|
|
4295
|
+
|
|
4296
|
+
|
|
4297
|
+
|
|
4298
|
+
|
|
4299
|
+
|
|
4300
|
+
|
|
4301
|
+
|
|
4302
|
+
|
|
4303
|
+
|
|
4304
|
+
|
|
4305
|
+
|
|
4306
|
+
|
|
4307
|
+
|
|
4308
|
+
|
|
4309
|
+
|
|
4310
|
+
|
|
4311
|
+
|
|
4312
|
+
|
|
4313
|
+
|
|
4314
|
+
|
|
4315
|
+
|
|
4316
|
+
|
|
4317
|
+
|
|
4318
|
+
|
|
4319
|
+
|
|
4320
|
+
|
|
4321
|
+
|
|
4322
|
+
|
|
4323
|
+
|
|
4324
|
+
|
|
4325
|
+
|
|
4326
|
+
|
|
4327
|
+
|
|
4328
|
+
|
|
4329
|
+
|
|
4330
|
+
|
|
4331
|
+
|
|
4332
|
+
|
|
4333
|
+
|
|
4334
|
+
|
|
4335
|
+
|
|
4336
|
+
|
|
4337
|
+
|
|
4338
|
+
|
|
4339
|
+
|
|
4340
|
+
|
|
4341
|
+
|
|
4342
|
+
|
|
4343
|
+
|
|
4344
|
+
|
|
4345
|
+
|
|
4346
|
+
|
|
4347
|
+
|
|
4348
|
+
|
|
4349
|
+
|
|
4350
|
+
|
|
4351
|
+
|
|
4352
|
+
|
|
4353
|
+
|
|
4354
|
+
|
|
4355
|
+
|
|
4356
|
+
|
|
4357
|
+
|
|
4358
|
+
|
|
4359
|
+
|
|
4360
|
+
|
|
4361
|
+
|
|
4362
|
+
|
|
4363
|
+
|
|
4364
|
+
|
|
4365
|
+
|
|
4366
|
+
|
|
4367
|
+
|
|
4368
|
+
|
|
4369
|
+
|
|
4370
|
+
|
|
4371
|
+
|
|
4372
|
+
|
|
4373
|
+
|
|
4374
|
+
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
|
|
4378
|
+
|
|
4379
|
+
|
|
4380
|
+
|
|
4381
|
+
|
|
4382
|
+
|
|
4383
|
+
|
|
4384
|
+
|
|
4385
|
+
|
|
4386
|
+
|
|
4387
|
+
|
|
4388
|
+
|
|
4389
|
+
|
|
4390
|
+
|
|
4391
|
+
|
|
4392
|
+
|
|
4393
|
+
|
|
4394
|
+
|
|
4395
|
+
|
|
4396
|
+
|
|
4397
|
+
|
|
4398
|
+
|
|
4399
|
+
|
|
4400
|
+
|
|
4401
|
+
|
|
4402
|
+
|
|
4403
|
+
|
|
4404
|
+
|
|
4405
|
+
|
|
4406
|
+
|
|
4407
|
+
|
|
4408
|
+
|
|
4409
|
+
|
|
4410
|
+
|
|
4411
|
+
|
|
4412
|
+
|
|
4413
|
+
|
|
4414
|
+
|
|
4415
|
+
|
|
4416
|
+
|
|
4417
|
+
|
|
4418
|
+
|
|
4419
|
+
|
|
4420
|
+
|
|
4421
|
+
|
|
4422
|
+
|
|
4423
|
+
|
|
4424
|
+
|
|
4425
|
+
|
|
4426
|
+
|
|
4427
|
+
|
|
4428
|
+
|
|
4429
|
+
|
|
4430
|
+
|
|
4431
|
+
|
|
4432
|
+
|
|
4433
|
+
|
|
4434
|
+
|
|
4435
|
+
|
|
4436
|
+
|
|
4437
|
+
|
|
4438
|
+
|
|
4439
|
+
|
|
4440
|
+
|
|
4441
|
+
|
|
4442
|
+
|
|
4443
|
+
|
|
4444
|
+
|
|
4445
|
+
|
|
4446
|
+
|
|
4447
|
+
|
|
4448
|
+
|
|
4449
|
+
|
|
4450
|
+
|
|
4451
|
+
|
|
4452
|
+
|
|
4453
|
+
|
|
4454
|
+
|
|
4455
|
+
|
|
4456
|
+
|
|
4457
|
+
|
|
4458
|
+
|
|
4459
|
+
|
|
4460
|
+
|
|
4461
|
+
|
|
4462
|
+
|
|
4463
|
+
|
|
4464
|
+
|
|
4465
|
+
|
|
4466
|
+
|
|
4467
|
+
|
|
4468
|
+
|
|
4469
|
+
|
|
4470
|
+
|
|
4471
|
+
|
|
4472
|
+
|
|
4473
|
+
|
|
4474
|
+
|
|
4475
|
+
|
|
4476
|
+
|
|
4477
|
+
|
|
4478
|
+
|
|
4479
|
+
|
|
4480
|
+
|
|
4481
|
+
|
|
4482
|
+
|
|
4483
|
+
|
|
4484
|
+
|
|
4485
|
+
|
|
4486
|
+
|
|
4487
|
+
|
|
4488
|
+
|
|
4489
|
+
|
|
4490
|
+
|
|
4491
|
+
|
|
4492
|
+
|
|
4493
|
+
|
|
4494
|
+
|
|
4495
|
+
|
|
4496
|
+
|
|
4497
|
+
|
|
4498
|
+
|
|
4499
|
+
|
|
4500
|
+
|
|
4501
|
+
|
|
4502
|
+
|
|
4503
|
+
|
|
4504
|
+
|
|
4505
|
+
|
|
4506
|
+
|
|
4507
|
+
|
|
4508
|
+
|
|
4509
|
+
|
|
4510
|
+
|
|
4511
|
+
|
|
4512
|
+
|
|
4513
|
+
|
|
4514
|
+
|
|
4515
|
+
|
|
4516
|
+
|
|
4517
|
+
|
|
4518
|
+
|
|
4519
|
+
|
|
4520
|
+
|
|
4521
|
+
|
|
4522
|
+
|
|
4523
|
+
|
|
4524
|
+
|
|
4525
|
+
|
|
4526
|
+
|
|
4527
|
+
|
|
4528
|
+
|
|
4529
|
+
|
|
4530
|
+
|
|
4531
|
+
|
|
4532
|
+
|
|
4533
|
+
|
|
4534
|
+
|
|
4535
|
+
|
|
4536
|
+
|
|
4537
|
+
|
|
4538
|
+
|
|
4539
|
+
|
|
4540
|
+
|
|
4541
|
+
|
|
4542
|
+
|
|
4543
|
+
|
|
4544
|
+
|
|
4545
|
+
|
|
4546
|
+
|
|
4547
|
+
|
|
4548
|
+
|
|
4549
|
+
|
|
4550
|
+
|
|
4551
|
+
|
|
4552
|
+
|
|
4553
|
+
|
|
4554
|
+
|
|
4555
|
+
|
|
4556
|
+
|
|
4557
|
+
|
|
4558
|
+
|
|
4559
|
+
|
|
4560
|
+
|
|
4561
|
+
|
|
4562
|
+
|
|
4563
|
+
|
|
4564
|
+
|
|
4565
|
+
|
|
4566
|
+
|
|
4567
|
+
|
|
4568
|
+
|
|
4569
|
+
|
|
4570
|
+
|
|
4571
|
+
|
|
4572
|
+
|
|
4573
|
+
|
|
4574
|
+
|
|
4575
|
+
|
|
4576
|
+
|
|
4577
|
+
|
|
4578
|
+
|
|
4579
|
+
|
|
4580
|
+
|
|
4581
|
+
|
|
4582
|
+
|
|
4583
|
+
|
|
4584
|
+
|
|
4585
|
+
|
|
4586
|
+
|
|
4587
|
+
|
|
4588
|
+
|
|
4589
|
+
|
|
4590
|
+
|
|
4591
|
+
|
|
4592
|
+
|
|
4593
|
+
|
|
4594
|
+
|
|
4595
|
+
|
|
4596
|
+
|
|
4597
|
+
|
|
4598
|
+
|
|
4599
|
+
|
|
4600
|
+
|
|
4601
|
+
|
|
4602
|
+
|
|
4603
|
+
|
|
4604
|
+
|
|
4605
|
+
|
|
4606
|
+
|
|
4607
|
+
|
|
4608
|
+
|
|
4609
|
+
|
|
4610
|
+
|
|
4611
|
+
|
|
4612
|
+
|
|
4613
|
+
|
|
4614
|
+
|
|
4615
|
+
|
|
4616
|
+
|
|
4617
|
+
|
|
4618
|
+
|
|
4619
|
+
|
|
4620
|
+
|
|
4621
|
+
|
|
4622
|
+
|
|
4623
|
+
|
|
4624
|
+
|
|
4625
|
+
|
|
4626
|
+
|
|
4627
|
+
|
|
4628
|
+
|
|
4629
|
+
|
|
4630
|
+
|
|
4631
|
+
|
|
4632
|
+
|
|
4633
|
+
|
|
4634
|
+
|
|
4635
|
+
|
|
4636
|
+
|
|
4637
|
+
|
|
4638
|
+
|
|
4639
|
+
|
|
4640
|
+
|
|
4641
|
+
|
|
4642
|
+
|
|
4643
|
+
|
|
4644
|
+
|
|
4645
|
+
|
|
4646
|
+
|
|
4647
|
+
|
|
4648
|
+
|
|
4649
|
+
|
|
4650
|
+
|
|
4651
|
+
|
|
4652
|
+
|
|
4653
|
+
|
|
4654
|
+
|
|
4655
|
+
|
|
4656
|
+
|
|
4657
|
+
|
|
4658
|
+
|
|
4659
|
+
|
|
4660
|
+
|
|
4661
|
+
|
|
4662
|
+
|
|
4663
|
+
|
|
4664
|
+
|
|
4665
|
+
|
|
4666
|
+
|
|
4667
|
+
|
|
4668
|
+
|
|
4669
|
+
|
|
4670
|
+
|
|
4671
|
+
|
|
4672
|
+
|
|
4673
|
+
|
|
4674
|
+
|
|
4675
|
+
|
|
4676
|
+
|
|
4677
|
+
|
|
4678
|
+
|
|
4679
|
+
|
|
4680
|
+
|
|
4681
|
+
|
|
4682
|
+
|
|
4683
|
+
|
|
4684
|
+
|
|
4685
|
+
|
|
4686
|
+
|
|
4687
|
+
|
|
4688
|
+
|
|
4689
|
+
|
|
4690
|
+
|
|
4691
|
+
|
|
4692
|
+
|
|
4693
|
+
|
|
4694
|
+
|
|
4695
|
+
|
|
4696
|
+
|
|
4697
|
+
|
|
4698
|
+
|
|
4699
|
+
|
|
4700
|
+
|
|
4701
|
+
|
|
4702
|
+
|
|
4703
|
+
|
|
4704
|
+
|
|
4705
|
+
|
|
4706
|
+
|
|
4707
|
+
|
|
4708
|
+
|
|
4709
|
+
|
|
4710
|
+
|
|
4711
|
+
|
|
4712
|
+
|
|
4713
|
+
|
|
4714
|
+
|
|
4715
|
+
|
|
4716
|
+
|
|
4717
|
+
|
|
4718
|
+
|
|
4719
|
+
|
|
4720
|
+
|
|
4721
|
+
|
|
4722
|
+
|
|
4723
|
+
|
|
4724
|
+
|
|
4725
|
+
|
|
4726
|
+
|
|
4727
|
+
|
|
4728
|
+
|
|
4729
|
+
|
|
4730
|
+
exports.AbortError = _chunk4G2RKM2Hjs.AbortError; exports.AddMcpServerRequestParamsSchema = _chunk4G2RKM2Hjs.AddMcpServerRequestParamsSchema; exports.AddMcpServerRequestSchema = _chunk4G2RKM2Hjs.AddMcpServerRequestSchema; exports.AddMcpServerResponseSchema = _chunk4G2RKM2Hjs.AddMcpServerResponseSchema; exports.AddMcpServerResultSchema = _chunk4G2RKM2Hjs.AddMcpServerResultSchema; exports.AddUserMessageRequestParamsSchema = _chunk4G2RKM2Hjs.AddUserMessageRequestParamsSchema; exports.AddUserMessageRequestSchema = _chunk4G2RKM2Hjs.AddUserMessageRequestSchema; exports.AddUserMessageResponseSchema = _chunk4G2RKM2Hjs.AddUserMessageResponseSchema; exports.AddUserMessageResultSchema = _chunk4G2RKM2Hjs.AddUserMessageResultSchema; exports.ApplyPatchToolConfirmationDetailsSchema = _chunk4G2RKM2Hjs.ApplyPatchToolConfirmationDetailsSchema; exports.AskUserCollectedAnswerSchema = _chunk4G2RKM2Hjs.AskUserCollectedAnswerSchema; exports.AskUserConfirmationDetailsSchema = _chunk4G2RKM2Hjs.AskUserConfirmationDetailsSchema; exports.AskUserQuestionSchema = _chunk4G2RKM2Hjs.AskUserQuestionSchema; exports.AskUserRequestParamsSchema = _chunk4G2RKM2Hjs.AskUserRequestParamsSchema; exports.AskUserRequestSchema = _chunk4G2RKM2Hjs.AskUserRequestSchema; exports.AskUserResponseSchema = _chunk4G2RKM2Hjs.AskUserResponseSchema; exports.AskUserResultSchema = _chunk4G2RKM2Hjs.AskUserResultSchema; exports.AssistantTextCompleteNotificationSchema = _chunk4G2RKM2Hjs.AssistantTextCompleteNotificationSchema; exports.AssistantTextDeltaNotificationSchema = _chunk4G2RKM2Hjs.AssistantTextDeltaNotificationSchema; exports.AuthenticateMcpServerRequestParamsSchema = _chunk4G2RKM2Hjs.AuthenticateMcpServerRequestParamsSchema; exports.AuthenticateMcpServerRequestSchema = _chunk4G2RKM2Hjs.AuthenticateMcpServerRequestSchema; exports.AuthenticateMcpServerResponseSchema = _chunk4G2RKM2Hjs.AuthenticateMcpServerResponseSchema; exports.AuthenticateMcpServerResultSchema = _chunk4G2RKM2Hjs.AuthenticateMcpServerResultSchema; exports.AutonomyLevel = _chunk4G2RKM2Hjs.AutonomyLevel; exports.AvailableModelConfigSchema = _chunk4G2RKM2Hjs.AvailableModelConfigSchema; exports.Base64ImageSourceSchema = _chunk4G2RKM2Hjs.Base64ImageSourceSchema; exports.BaseNotificationSchema = _chunk4G2RKM2Hjs.BaseNotificationSchema; exports.BaseRequestSchema = _chunk4G2RKM2Hjs.BaseRequestSchema; exports.BaseResponseFailureSchema = _chunk4G2RKM2Hjs.BaseResponseFailureSchema; exports.BaseResponseSuccessSchema = _chunk4G2RKM2Hjs.BaseResponseSuccessSchema; exports.CLI_JSONRPC_CHILD_SPAWN_LATENCY_METRIC = CLI_JSONRPC_CHILD_SPAWN_LATENCY_METRIC; exports.COMPACTION_TIMEOUT = _chunk4G2RKM2Hjs.COMPACTION_TIMEOUT; exports.CancelMcpAuthRequestParamsSchema = _chunk4G2RKM2Hjs.CancelMcpAuthRequestParamsSchema; exports.CancelMcpAuthRequestSchema = _chunk4G2RKM2Hjs.CancelMcpAuthRequestSchema; exports.CancelMcpAuthResponseSchema = _chunk4G2RKM2Hjs.CancelMcpAuthResponseSchema; exports.CancelMcpAuthResultSchema = _chunk4G2RKM2Hjs.CancelMcpAuthResultSchema; exports.ChangeWorkingDirectoryRequestParamsSchema = _chunk4G2RKM2Hjs.ChangeWorkingDirectoryRequestParamsSchema; exports.ChangeWorkingDirectoryRequestSchema = _chunk4G2RKM2Hjs.ChangeWorkingDirectoryRequestSchema; exports.ChangeWorkingDirectoryResponseSchema = _chunk4G2RKM2Hjs.ChangeWorkingDirectoryResponseSchema; exports.ChangeWorkingDirectoryResultSchema = _chunk4G2RKM2Hjs.ChangeWorkingDirectoryResultSchema; exports.ClearMcpAuthRequestParamsSchema = _chunk4G2RKM2Hjs.ClearMcpAuthRequestParamsSchema; exports.ClearMcpAuthRequestSchema = _chunk4G2RKM2Hjs.ClearMcpAuthRequestSchema; exports.ClearMcpAuthResponseSchema = _chunk4G2RKM2Hjs.ClearMcpAuthResponseSchema; exports.ClearMcpAuthResultSchema = _chunk4G2RKM2Hjs.ClearMcpAuthResultSchema; exports.CliRequestOrNotificationSchema = _chunk4G2RKM2Hjs.CliRequestOrNotificationSchema; exports.ClientDestroyedError = _chunk4G2RKM2Hjs.ClientDestroyedError; exports.ClientRequestSchema = _chunk4G2RKM2Hjs.ClientRequestSchema; exports.ClientUiSurface = _chunk4G2RKM2Hjs.ClientUiSurface; exports.CloseSessionRequestParamsSchema = _chunk4G2RKM2Hjs.CloseSessionRequestParamsSchema; exports.CloseSessionRequestSchema = _chunk4G2RKM2Hjs.CloseSessionRequestSchema; exports.CloseSessionResponseSchema = _chunk4G2RKM2Hjs.CloseSessionResponseSchema; exports.CloseSessionResultSchema = _chunk4G2RKM2Hjs.CloseSessionResultSchema; exports.CompactSessionRequestParamsSchema = _chunk4G2RKM2Hjs.CompactSessionRequestParamsSchema; exports.CompactSessionRequestSchema = _chunk4G2RKM2Hjs.CompactSessionRequestSchema; exports.CompactSessionResponseSchema = _chunk4G2RKM2Hjs.CompactSessionResponseSchema; exports.CompactSessionResultSchema = _chunk4G2RKM2Hjs.CompactSessionResultSchema; exports.ComputeLimitExceededError = _chunk4G2RKM2Hjs.ComputeLimitExceededError; exports.ComputerConnectAttemptTrigger = _chunk4G2RKM2Hjs.ComputerConnectAttemptTrigger; exports.ComputerConnectStartType = _chunk4G2RKM2Hjs.ComputerConnectStartType; exports.ComputerListResponseSchema = _chunk4G2RKM2Hjs.ComputerListResponseSchema; exports.ComputerMetricSchema = _chunk4G2RKM2Hjs.ComputerMetricSchema; exports.ComputerMetricsResponseSchema = _chunk4G2RKM2Hjs.ComputerMetricsResponseSchema; exports.ComputerSchema = _chunk4G2RKM2Hjs.ComputerSchema; exports.ConcurrentStreamError = _chunk4G2RKM2Hjs.ConcurrentStreamError; exports.ConnectionClosedError = _chunk4G2RKM2Hjs.ConnectionClosedError; exports.ConnectionError = _chunk4G2RKM2Hjs.ConnectionError; exports.ConnectionFailureReason = _chunk4G2RKM2Hjs.ConnectionFailureReason; exports.ContentBlockSchema = _chunk4G2RKM2Hjs.ContentBlockSchema; exports.ContextBreakdownCategorySchema = _chunk4G2RKM2Hjs.ContextBreakdownCategorySchema; exports.ContextBreakdownResultSchema = _chunk4G2RKM2Hjs.GetContextBreakdownResultSchema; exports.ContextStatsAccuracy = _chunk4G2RKM2Hjs.ContextStatsAccuracy; exports.ContextStatsSchema = _chunk4G2RKM2Hjs.ContextStatsSchema; exports.CreateMessageNotificationSchema = _chunk4G2RKM2Hjs.CreateMessageNotificationSchema; exports.CreateToolConfirmationDetailsSchema = _chunk4G2RKM2Hjs.CreateToolConfirmationDetailsSchema; exports.DEFAULT_LOCAL_DAEMON_WS_URL = _chunk4G2RKM2Hjs.DEFAULT_LOCAL_DAEMON_WS_URL; exports.DEFAULT_REQUEST_TIMEOUT = _chunk4G2RKM2Hjs.DEFAULT_REQUEST_TIMEOUT; exports.DaemonAuthenticationMode = _chunk4G2RKM2Hjs.DaemonAuthenticationMode; exports.DaemonClient = _chunk4G2RKM2Hjs.DaemonClient; exports.DaemonClientMetaError = _chunk4G2RKM2Hjs.MetaError; exports.DaemonDroidEvent = _chunk4G2RKM2Hjs.DaemonDroidEvent; exports.DaemonRequestPermissionSchema = _chunk4G2RKM2Hjs.DaemonRequestPermissionSchema; exports.DaemonSessionController = _chunk4G2RKM2Hjs.DaemonSessionController; exports.DecompSessionType = _chunk4G2RKM2Hjs.DecompSessionType; exports.DiscoveredIssueSchema = _chunk4G2RKM2Hjs.DiscoveredIssueSchema; exports.DismissalRecordSchema = _chunk4G2RKM2Hjs.DismissalRecordSchema; exports.DismissalType = _chunk4G2RKM2Hjs.DismissalType; exports.DocumentBlockSchema = _chunk4G2RKM2Hjs.DocumentBlockSchema; exports.DocumentSourceSchema = _chunk4G2RKM2Hjs.DocumentSourceSchema; exports.DroidClient = DroidClient; exports.DroidClientError = _chunk4G2RKM2Hjs.DroidClientError; exports.DroidClientEvent = DroidClientEvent; exports.DroidClientMethod = _chunk4G2RKM2Hjs.DroidClientMethod; exports.DroidErrorType = _chunk4G2RKM2Hjs.DroidErrorType; exports.DroidEvent = _chunk4G2RKM2Hjs.DroidEvent; exports.DroidHookEventSchema = _chunk4G2RKM2Hjs.DroidHookEventSchema; exports.DroidHookExecutionResultSchema = _chunk4G2RKM2Hjs.DroidHookExecutionResultSchema; exports.DroidHookOutputSchema = _chunk4G2RKM2Hjs.DroidHookOutputSchema; exports.DroidHookSpecificOutputSchema = _chunk4G2RKM2Hjs.DroidHookSpecificOutputSchema; exports.DroidInteractionMode = _chunk4G2RKM2Hjs.DroidInteractionMode; exports.DroidMessageType = _chunk4G2RKM2Hjs.DroidMessageType; exports.DroidProcessManager = DroidProcessManager; exports.DroidProcessMode = DroidProcessMode; exports.DroidServerMethod = _chunk4G2RKM2Hjs.DroidServerMethod; exports.DroidSession = DroidSession; exports.DroidWorkingState = _chunk4G2RKM2Hjs.DroidWorkingState; exports.DroidWorkingStateChangedNotificationSchema = _chunk4G2RKM2Hjs.DroidWorkingStateChangedNotificationSchema; exports.EditToolConfirmationDetailsSchema = _chunk4G2RKM2Hjs.EditToolConfirmationDetailsSchema; exports.EmptyResultSchema = _chunk4G2RKM2Hjs.EmptyResultSchema; exports.ErrorDetailSchema = _chunk4G2RKM2Hjs.ErrorDetailSchema; exports.ErrorNotificationSchema = _chunk4G2RKM2Hjs.ErrorNotificationSchema; exports.ExecToolInfoSchema = _chunk4G2RKM2Hjs.ExecToolInfoSchema; exports.ExecuteRewindRequestParamsSchema = _chunk4G2RKM2Hjs.ExecuteRewindRequestParamsSchema; exports.ExecuteRewindRequestSchema = _chunk4G2RKM2Hjs.ExecuteRewindRequestSchema; exports.ExecuteRewindResponseSchema = _chunk4G2RKM2Hjs.ExecuteRewindResponseSchema; exports.ExecuteRewindResultSchema = _chunk4G2RKM2Hjs.ExecuteRewindResultSchema; exports.ExecuteToolConfirmationDetailsSchema = _chunk4G2RKM2Hjs.ExecuteToolConfirmationDetailsSchema; exports.ExitSpecModeConfirmationDetailsSchema = _chunk4G2RKM2Hjs.ExitSpecModeConfirmationDetailsSchema; exports.FACTORY_CLIENT_HEADER = _chunk4G2RKM2Hjs.FACTORY_CLIENT_HEADER; exports.FACTORY_CLIENT_VERSION = _chunk4G2RKM2Hjs.FACTORY_CLIENT_VERSION; exports.FACTORY_PROTOCOL_VERSION = _chunk4G2RKM2Hjs.FACTORY_PROTOCOL_VERSION2; exports.FactoryDaemonTransport = _chunk4G2RKM2Hjs.FactoryDaemonTransport; exports.FactoryDroidMessageRole = _chunk4G2RKM2Hjs.FactoryDroidMessageRole; exports.FactoryDroidMessageSchema = _chunk4G2RKM2Hjs.FactoryDroidMessageSchema; exports.FeatureStatus = _chunk4G2RKM2Hjs.FeatureStatus; exports.FeatureSuccessState = _chunk4G2RKM2Hjs.FeatureSuccessState; exports.FeatureSuccessStateSchema = _chunk4G2RKM2Hjs.FeatureSuccessStateSchema; exports.ForkSessionRequestParamsSchema = _chunk4G2RKM2Hjs.ForkSessionRequestParamsSchema; exports.ForkSessionRequestSchema = _chunk4G2RKM2Hjs.ForkSessionRequestSchema; exports.ForkSessionResponseSchema = _chunk4G2RKM2Hjs.ForkSessionResponseSchema; exports.ForkSessionResultSchema = _chunk4G2RKM2Hjs.ForkSessionResultSchema; exports.GetContextStatsRequestParamsSchema = _chunk4G2RKM2Hjs.GetContextStatsRequestParamsSchema; exports.GetContextStatsRequestSchema = _chunk4G2RKM2Hjs.GetContextStatsRequestSchema; exports.GetContextStatsResponseSchema = _chunk4G2RKM2Hjs.GetContextStatsResponseSchema; exports.GetContextStatsResultSchema = _chunk4G2RKM2Hjs.ContextStatsSchema; exports.GetRewindInfoRequestParamsSchema = _chunk4G2RKM2Hjs.GetRewindInfoRequestParamsSchema; exports.GetRewindInfoRequestSchema = _chunk4G2RKM2Hjs.GetRewindInfoRequestSchema; exports.GetRewindInfoResponseSchema = _chunk4G2RKM2Hjs.GetRewindInfoResponseSchema; exports.GetRewindInfoResultSchema = _chunk4G2RKM2Hjs.GetRewindInfoResultSchema; exports.GitRepoInfoSchema = _chunk4G2RKM2Hjs.GitRepoInfoSchema; exports.HandoffItemsDismissedEntrySchema = _chunk4G2RKM2Hjs.HandoffItemsDismissedEntrySchema; exports.HandoffSchema = _chunk4G2RKM2Hjs.HandoffSchema; exports.HookCommandSchema = _chunk4G2RKM2Hjs.HookCommandSchema; exports.HookExecutionCompletedNotificationSchema = _chunk4G2RKM2Hjs.HookExecutionCompletedNotificationSchema; exports.HookExecutionStartedNotificationSchema = _chunk4G2RKM2Hjs.HookExecutionStartedNotificationSchema; exports.HookResultSchema = _chunk4G2RKM2Hjs.HookResultSchema; exports.HttpHeaderSchema = _chunk4G2RKM2Hjs.HttpHeaderSchema; exports.HttpMcpConfigSchema = _chunk4G2RKM2Hjs.HttpMcpSchema; exports.IPC_DAEMON_URL = _chunk4G2RKM2Hjs.IPC_DAEMON_URL; exports.ImageBlockSchema = _chunk4G2RKM2Hjs.ImageBlockSchema; exports.InProcessDaemonClientTransport = _chunk4G2RKM2Hjs.InProcessDaemonClientTransport; exports.InitializeSessionRequestParamsSchema = _chunk4G2RKM2Hjs.InitializeSessionRequestParamsSchema; exports.InitializeSessionRequestSchema = _chunk4G2RKM2Hjs.InitializeSessionRequestSchema; exports.InitializeSessionResponseSchema = _chunk4G2RKM2Hjs.InitializeSessionResponseSchema; exports.InitializeSessionResultSchema = _chunk4G2RKM2Hjs.InitializeSessionResultSchema2; exports.InteractiveCheckSchema = _chunk4G2RKM2Hjs.InteractiveCheckSchema; exports.InterruptSessionRequestParamsSchema = _chunk4G2RKM2Hjs.InterruptSessionRequestParamsSchema; exports.InterruptSessionRequestSchema = _chunk4G2RKM2Hjs.InterruptSessionRequestSchema; exports.InterruptSessionResponseSchema = _chunk4G2RKM2Hjs.InterruptSessionResponseSchema; exports.InterruptSessionResultSchema = _chunk4G2RKM2Hjs.InterruptSessionResultSchema; exports.InvalidSessionCwdError = _chunk4G2RKM2Hjs.InvalidSessionCwdError; exports.IpcDaemonClientTransport = _chunk4G2RKM2Hjs.IpcDaemonClientTransport; exports.IssueSeverity = _chunk4G2RKM2Hjs.IssueSeverity; exports.JSONRPC_VERSION = _chunk4G2RKM2Hjs.JSONRPC_VERSION3; exports.JsonArraySchema = _chunk4G2RKM2Hjs.JsonArraySchema; exports.JsonObjectSchema = _chunk4G2RKM2Hjs.JsonObjectSchema; exports.JsonRpcEnvelopeSchema = _chunk4G2RKM2Hjs.JsonRpcEnvelopeSchema; exports.JsonRpcErrorCode = _chunk4G2RKM2Hjs.JsonRpcErrorCode; exports.JsonRpcErrorSchema = _chunk4G2RKM2Hjs.JsonRpcErrorSchema; exports.JsonRpcMessageSchema = _chunk4G2RKM2Hjs.JsonRpcMessageSchema; exports.JsonRpcMessageType = _chunk4G2RKM2Hjs.JsonRpcMessageType; exports.JsonRpcNotificationSchema = _chunk4G2RKM2Hjs.JsonRpcNotificationSchema; exports.JsonRpcRequestError = _chunk4G2RKM2Hjs.JsonRpcRequestError; exports.JsonRpcRequestSchema = _chunk4G2RKM2Hjs.JsonRpcRequestSchema; exports.JsonRpcResponseFailureSchema = _chunk4G2RKM2Hjs.JsonRpcResponseFailureSchema; exports.JsonRpcResponseSchema = _chunk4G2RKM2Hjs.JsonRpcResponseSchema; exports.JsonRpcResponseSuccessSchema = _chunk4G2RKM2Hjs.JsonRpcResponseSuccessSchema; exports.JsonValueSchema = _chunk4G2RKM2Hjs.JsonValueSchema; exports.KillWorkerSessionRequestParamsSchema = _chunk4G2RKM2Hjs.KillWorkerSessionRequestParamsSchema; exports.KillWorkerSessionRequestSchema = _chunk4G2RKM2Hjs.KillWorkerSessionRequestSchema; exports.KillWorkerSessionResponseSchema = _chunk4G2RKM2Hjs.KillWorkerSessionResponseSchema; exports.KillWorkerSessionResultSchema = _chunk4G2RKM2Hjs.KillWorkerSessionResultSchema; exports.LEGACY_FACTORY_API_VERSION = _chunk4G2RKM2Hjs.LEGACY_FACTORY_API_VERSION2; exports.LOCAL_MACHINE_ID = _chunk4G2RKM2Hjs.LOCAL_MACHINE_ID; exports.ListMcpRegistryRequestParamsSchema = _chunk4G2RKM2Hjs.ListMcpRegistryRequestParamsSchema; exports.ListMcpRegistryRequestSchema = _chunk4G2RKM2Hjs.ListMcpRegistryRequestSchema; exports.ListMcpRegistryResponseSchema = _chunk4G2RKM2Hjs.ListMcpRegistryResponseSchema; exports.ListMcpRegistryResultSchema = _chunk4G2RKM2Hjs.ListMcpRegistryResultSchema; exports.ListMcpServersRequestParamsSchema = _chunk4G2RKM2Hjs.ListMcpServersRequestParamsSchema; exports.ListMcpServersRequestSchema = _chunk4G2RKM2Hjs.ListMcpServersRequestSchema; exports.ListMcpServersResponseSchema = _chunk4G2RKM2Hjs.ListMcpServersResponseSchema; exports.ListMcpServersResultSchema = _chunk4G2RKM2Hjs.ListMcpServersResultSchema; exports.ListMcpToolsRequestParamsSchema = _chunk4G2RKM2Hjs.ListMcpToolsRequestParamsSchema; exports.ListMcpToolsRequestSchema = _chunk4G2RKM2Hjs.ListMcpToolsRequestSchema; exports.ListMcpToolsResponseSchema = _chunk4G2RKM2Hjs.ListMcpToolsResponseSchema; exports.ListMcpToolsResultSchema = _chunk4G2RKM2Hjs.ListMcpToolsResultSchema; exports.ListModelsOptionsSchema = _chunk4G2RKM2Hjs.ListModelsOptionsSchema; exports.ListModelsResultSchema = _chunk4G2RKM2Hjs.ListModelsResultSchema; exports.ListSkillsRequestParamsSchema = _chunk4G2RKM2Hjs.ListSkillsRequestParamsSchema; exports.ListSkillsRequestSchema = _chunk4G2RKM2Hjs.ListSkillsRequestSchema; exports.ListSkillsResponseSchema = _chunk4G2RKM2Hjs.ListSkillsResponseSchema; exports.ListSkillsResultSchema = _chunk4G2RKM2Hjs.ListSkillsResultSchema; exports.ListToolsRequestParamsSchema = _chunk4G2RKM2Hjs.ListToolsRequestParamsSchema; exports.ListToolsRequestSchema = _chunk4G2RKM2Hjs.ListToolsRequestSchema; exports.ListToolsResponseSchema = _chunk4G2RKM2Hjs.ListToolsResponseSchema; exports.ListToolsResultSchema = _chunk4G2RKM2Hjs.ListToolsResultSchema; exports.LoadSessionRequestParamsSchema = _chunk4G2RKM2Hjs.LoadSessionRequestParamsSchema; exports.LoadSessionRequestSchema = _chunk4G2RKM2Hjs.LoadSessionRequestSchema; exports.LoadSessionResponseSchema = _chunk4G2RKM2Hjs.LoadSessionResponseSchema; exports.LoadSessionResultSchema = _chunk4G2RKM2Hjs.LoadSessionResultSchema; exports.MACHINE_TYPE_WEBSOCKET_OVERRIDES = _chunk4G2RKM2Hjs.MACHINE_TYPE_WEBSOCKET_OVERRIDES; exports.MANAGED_COMPUTER_MAX_RETRIES = _chunk4G2RKM2Hjs.MANAGED_COMPUTER_MAX_RETRIES; exports.MCP_AUTH_TIMEOUT = _chunk4G2RKM2Hjs.MCP_AUTH_TIMEOUT; exports.MachineTemplateBuildStatusSchema = _chunk4G2RKM2Hjs.MachineTemplateBuildStatusSchema; exports.MachineTemplateListResponseSchema = _chunk4G2RKM2Hjs.MachineTemplateListResponseSchema; exports.MachineTemplateSchema = _chunk4G2RKM2Hjs.MachineTemplateSchema; exports.MachineType = _chunk4G2RKM2Hjs.MachineType; exports.ManagedProcessImpl = ManagedProcessImpl; exports.McpAuthCompletedNotificationSchema = _chunk4G2RKM2Hjs.McpAuthCompletedNotificationSchema; exports.McpAuthOutcome = _chunk4G2RKM2Hjs.McpAuthOutcome; exports.McpAuthRequiredNotificationSchema = _chunk4G2RKM2Hjs.McpAuthRequiredNotificationSchema; exports.McpHttpServerConfigFieldsSchema = _chunk4G2RKM2Hjs.McpHttpServerConfigFieldsSchema; exports.McpRegistryServerSchema = _chunk4G2RKM2Hjs.McpRegistryServerSchema; exports.McpServerConfigSchema = _chunk4G2RKM2Hjs.McpServerConfigSchema; exports.McpServerStatus = _chunk4G2RKM2Hjs.McpServerStatus; exports.McpServerStatusInfoSchema = _chunk4G2RKM2Hjs.McpServerStatusInfoSchema; exports.McpServerType = _chunk4G2RKM2Hjs.McpServerType; exports.McpSseServerConfigFieldsSchema = _chunk4G2RKM2Hjs.McpSseServerConfigFieldsSchema; exports.McpStatus = _chunk4G2RKM2Hjs.McpStatus; exports.McpStatusChangedNotificationSchema = _chunk4G2RKM2Hjs.McpStatusChangedNotificationSchema; exports.McpStatusSummarySchema = _chunk4G2RKM2Hjs.McpStatusSummarySchema; exports.McpStdioServerConfigFieldsSchema = _chunk4G2RKM2Hjs.McpStdioServerConfigFieldsSchema; exports.McpToolConfirmationDetailsSchema = _chunk4G2RKM2Hjs.McpToolConfirmationDetailsSchema; exports.McpToolInfoSchema = _chunk4G2RKM2Hjs.McpToolInfoSchema; exports.McpToolInputSchemaSchema = _chunk4G2RKM2Hjs.McpToolInputSchemaSchema; exports.MessageVisibility = _chunk4G2RKM2Hjs.MessageVisibility; exports.Metric = _chunk4G2RKM2Hjs.Metric; exports.MilestoneValidationTriggeredEntrySchema = _chunk4G2RKM2Hjs.MilestoneValidationTriggeredEntrySchema; exports.MissionAcceptedEntrySchema = _chunk4G2RKM2Hjs.MissionAcceptedEntrySchema; exports.MissionFeatureSchema = _chunk4G2RKM2Hjs.MissionFeatureSchema; exports.MissionFeaturesChangedNotificationSchema = _chunk4G2RKM2Hjs.MissionFeaturesChangedNotificationSchema; exports.MissionHeartbeatNotificationSchema = _chunk4G2RKM2Hjs.MissionHeartbeatNotificationSchema; exports.MissionPausedEntrySchema = _chunk4G2RKM2Hjs.MissionPausedEntrySchema; exports.MissionProgressEntryNotificationSchema = _chunk4G2RKM2Hjs.MissionProgressEntryNotificationSchema; exports.MissionResumedEntrySchema = _chunk4G2RKM2Hjs.MissionResumedEntrySchema; exports.MissionRunStartedEntrySchema = _chunk4G2RKM2Hjs.MissionRunStartedEntrySchema; exports.MissionSnapshotSchema = _chunk4G2RKM2Hjs.MissionStateSchema; exports.MissionState = _chunk4G2RKM2Hjs.MissionState; exports.MissionStateChangedNotificationSchema = _chunk4G2RKM2Hjs.MissionStateChangedNotificationSchema; exports.MissionWorkerCompletedNotificationSchema = _chunk4G2RKM2Hjs.MissionWorkerCompletedNotificationSchema; exports.MissionWorkerStartedNotificationSchema = _chunk4G2RKM2Hjs.MissionWorkerStartedNotificationSchema; exports.ModelInfoSchema = _chunk4G2RKM2Hjs.ModelInfoSchema; exports.ModelMetadataSchema = _chunk4G2RKM2Hjs.ModelMetadataSchema; exports.ModelProvider = _chunk4G2RKM2Hjs.ModelProvider; exports.MultiMissionStateManager = _chunk4G2RKM2Hjs.MultiMissionStateManager; exports.MultiSessionStateManager = _chunk4G2RKM2Hjs.MultiSessionStateManager; exports.OtelTracing = _chunk4G2RKM2Hjs.OtelTracing; exports.OutputFormatSchema = _chunk4G2RKM2Hjs.OutputFormatSchema; exports.OutputFormatType = _chunk4G2RKM2Hjs.OutputFormatType; exports.PermissionResolvedNotificationSchema = _chunk4G2RKM2Hjs.PermissionResolvedNotificationSchema; exports.ProcessExitError = _chunk4G2RKM2Hjs.ProcessExitError; exports.ProcessTransport = ProcessTransport; exports.ProgressLogEntrySchema = _chunk4G2RKM2Hjs.ProgressLogEntrySchema; exports.ProgressLogEntryType = _chunk4G2RKM2Hjs.ProgressLogEntryType; exports.ProposeMissionConfirmationDetailsSchema = _chunk4G2RKM2Hjs.ProposeMissionConfirmationDetailsSchema; exports.ProtocolError = _chunk4G2RKM2Hjs.ProtocolError; exports.QueuedUserMessageDisplayGroup = _chunk4G2RKM2Hjs.QueuedUserMessageDisplayGroup; exports.QueuedUserMessageKind = _chunk4G2RKM2Hjs.QueuedUserMessageKind; exports.REWIND_TIMEOUT = _chunk4G2RKM2Hjs.REWIND_TIMEOUT; exports.ReasoningEffort = _chunk4G2RKM2Hjs.ReasoningEffort; exports.RedactedThinkingBlockSchema = _chunk4G2RKM2Hjs.RedactedThinkingBlockSchema; exports.RefreshComputerResponseSchema = _chunk4G2RKM2Hjs.RefreshComputerResponseSchema; exports.RelayConnectionError = _chunk4G2RKM2Hjs.RelayConnectionError; exports.RemoteSessionListResponseSchema = _chunk4G2RKM2Hjs.RemoteSessionListResponseSchema; exports.RemoteSessionSchema = _chunk4G2RKM2Hjs.RemoteSessionSchema; exports.RemoveMcpServerRequestParamsSchema = _chunk4G2RKM2Hjs.RemoveMcpServerRequestParamsSchema; exports.RemoveMcpServerRequestSchema = _chunk4G2RKM2Hjs.RemoveMcpServerRequestSchema; exports.RemoveMcpServerResponseSchema = _chunk4G2RKM2Hjs.RemoveMcpServerResponseSchema; exports.RemoveMcpServerResultSchema = _chunk4G2RKM2Hjs.RemoveMcpServerResultSchema; exports.RenameSessionRequestParamsSchema = _chunk4G2RKM2Hjs.RenameSessionRequestParamsSchema; exports.RenameSessionRequestSchema = _chunk4G2RKM2Hjs.RenameSessionRequestSchema; exports.RenameSessionResponseSchema = _chunk4G2RKM2Hjs.RenameSessionResponseSchema; exports.RenameSessionResultSchema = _chunk4G2RKM2Hjs.RenameSessionResultSchema; exports.RequestPermissionRequestParamsSchema = _chunk4G2RKM2Hjs.RequestPermissionRequestParamsSchema; exports.RequestPermissionRequestSchema = _chunk4G2RKM2Hjs.RequestPermissionRequestSchema; exports.RequestPermissionResponseSchema = _chunk4G2RKM2Hjs.RequestPermissionResponseSchema; exports.RequestPermissionResultSchema = _chunk4G2RKM2Hjs.RequestPermissionResultSchema; exports.RewindEvictedFileSchema = _chunk4G2RKM2Hjs.RewindEvictedFileSchema; exports.RewindFileCreationSchema = _chunk4G2RKM2Hjs.RewindFileCreationSchema; exports.RewindFileSnapshotSchema = _chunk4G2RKM2Hjs.RewindFileSnapshotSchema; exports.SDK_TAG = _chunk4G2RKM2Hjs.SDK_TAG; exports.SDK_VERSION = _chunk4G2RKM2Hjs.SDK_VERSION; exports.SESSION_INIT_TIMEOUT = _chunk4G2RKM2Hjs.SESSION_INIT_TIMEOUT; exports.SLACK_DELEGATION_MAX_RETRIES = _chunk4G2RKM2Hjs.SLACK_DELEGATION_MAX_RETRIES; exports.SdkMcpServer = SdkMcpServer; exports.ServerRequestHandlerType = _chunk4G2RKM2Hjs.ServerRequestHandlerType; exports.SessionError = _chunk4G2RKM2Hjs.SessionError; exports.SessionMetadataSchema = _chunk4G2RKM2Hjs.SessionMetadataSchema; exports.SessionNotFoundError = _chunk4G2RKM2Hjs.SessionNotFoundError; exports.SessionNotificationParamsSchema = _chunk4G2RKM2Hjs.SessionNotificationParamsSchema; exports.SessionNotificationPayloadSchema = _chunk4G2RKM2Hjs.SessionNotificationPayloadSchema; exports.SessionNotificationSchema = _chunk4G2RKM2Hjs.SessionNotificationSchema; exports.SessionNotificationSchemaList = _chunk4G2RKM2Hjs.SessionNotificationSchemaList; exports.SessionNotificationType = _chunk4G2RKM2Hjs.SessionNotificationType; exports.SessionPlatform = _chunk4G2RKM2Hjs.SessionPlatform; exports.SessionReplacedError = _chunk4G2RKM2Hjs.SessionReplacedError; exports.SessionReplacementError = _chunk4G2RKM2Hjs.SessionReplacementError; exports.SessionSettingsFileSchema = _chunk4G2RKM2Hjs.SessionSettingsFileSchema; exports.SessionSettingsSchema = _chunk4G2RKM2Hjs.SessionSettingsSchema; exports.SessionSourceSchema = _chunk4G2RKM2Hjs.SessionSourceSchema; exports.SessionStartEventSchema = _chunk4G2RKM2Hjs.SessionStartEventSchema; exports.SessionTagSchema = _chunk4G2RKM2Hjs.SessionTagSchema; exports.SessionTitleUpdatedNotificationSchema = _chunk4G2RKM2Hjs.SessionTitleUpdatedNotificationSchema; exports.SessionTokenUsageChangedNotificationSchema = _chunk4G2RKM2Hjs.SessionTokenUsageChangedNotificationSchema; exports.SetSkillDisabledRequestParamsSchema = _chunk4G2RKM2Hjs.SetSkillDisabledRequestParamsSchema; exports.SetSkillDisabledRequestSchema = _chunk4G2RKM2Hjs.SetSkillDisabledRequestSchema; exports.SetSkillDisabledResponseSchema = _chunk4G2RKM2Hjs.SetSkillDisabledResponseSchema; exports.SetSkillDisabledResultSchema = _chunk4G2RKM2Hjs.SetSkillDisabledResultSchema; exports.SettingsLevel = _chunk4G2RKM2Hjs.SettingsLevel; exports.SettingsUpdatedNotificationSchema = _chunk4G2RKM2Hjs.SettingsUpdatedNotificationSchema; exports.SettingsUpdatedPayloadSchema = _chunk4G2RKM2Hjs.SettingsUpdatedPayloadSchema; exports.SkillDeviationSchema = _chunk4G2RKM2Hjs.SkillDeviationSchema; exports.SkillFeedbackSchema = _chunk4G2RKM2Hjs.SkillFeedbackSchema; exports.SkillInfoSchema = _chunk4G2RKM2Hjs.SkillInfoSchema; exports.SkillLocation = _chunk4G2RKM2Hjs.SkillLocation; exports.SkillResourceSchema = _chunk4G2RKM2Hjs.SkillResourceSchema; exports.SpanAttribute = _chunk4G2RKM2Hjs.SpanAttribute; exports.SpanEvent = _chunk4G2RKM2Hjs.SpanEvent; exports.SpanName = _chunk4G2RKM2Hjs.SpanName; exports.SseMcpConfigSchema = _chunk4G2RKM2Hjs.SseMcpSchema; exports.StartMissionRunConfirmationDetailsSchema = _chunk4G2RKM2Hjs.StartMissionRunConfirmationDetailsSchema; exports.StdioMcpConfigSchema = _chunk4G2RKM2Hjs.StdioMcpSchema; exports.StreamStateTracker = _chunk4G2RKM2Hjs.StreamStateTracker; exports.StructuredOutputErrorSchema = _chunk4G2RKM2Hjs.StructuredOutputErrorSchema; exports.StructuredOutputNotificationSchema = _chunk4G2RKM2Hjs.StructuredOutputNotificationSchema; exports.SubmitBugReportRequestParamsSchema = _chunk4G2RKM2Hjs.SubmitBugReportRequestParamsSchema; exports.SubmitBugReportRequestSchema = _chunk4G2RKM2Hjs.SubmitBugReportRequestSchema; exports.SubmitBugReportResponseSchema = _chunk4G2RKM2Hjs.SubmitBugReportResponseSchema; exports.SubmitBugReportResultSchema = _chunk4G2RKM2Hjs.SubmitBugReportResultSchema; exports.SubmitMcpAuthCodeRequestParamsSchema = _chunk4G2RKM2Hjs.SubmitMcpAuthCodeRequestParamsSchema; exports.SubmitMcpAuthCodeRequestSchema = _chunk4G2RKM2Hjs.SubmitMcpAuthCodeRequestSchema; exports.SubmitMcpAuthCodeResponseSchema = _chunk4G2RKM2Hjs.SubmitMcpAuthCodeResponseSchema; exports.SubmitMcpAuthCodeResultSchema = _chunk4G2RKM2Hjs.SubmitMcpAuthCodeResultSchema; exports.SuccessResultSchema = _chunk4G2RKM2Hjs.SuccessResultSchema; exports.TestCaseSchema = _chunk4G2RKM2Hjs.TestCaseSchema; exports.TestFileSchema = _chunk4G2RKM2Hjs.TestFileSchema; exports.TestsSchema = _chunk4G2RKM2Hjs.TestsSchema; exports.TextBlockSchema = _chunk4G2RKM2Hjs.TextBlockSchema; exports.ThinkingBlockSchema = _chunk4G2RKM2Hjs.ThinkingBlockSchema; exports.ThinkingTextCompleteNotificationSchema = _chunk4G2RKM2Hjs.ThinkingTextCompleteNotificationSchema; exports.ThinkingTextDeltaNotificationSchema = _chunk4G2RKM2Hjs.ThinkingTextDeltaNotificationSchema; exports.TimeoutError = _chunk4G2RKM2Hjs.TimeoutError; exports.ToggleMcpServerRequestParamsSchema = _chunk4G2RKM2Hjs.ToggleMcpServerRequestParamsSchema; exports.ToggleMcpServerRequestSchema = _chunk4G2RKM2Hjs.ToggleMcpServerRequestSchema; exports.ToggleMcpServerResponseSchema = _chunk4G2RKM2Hjs.ToggleMcpServerResponseSchema; exports.ToggleMcpServerResultSchema = _chunk4G2RKM2Hjs.ToggleMcpServerResultSchema; exports.ToggleMcpToolRequestParamsSchema = _chunk4G2RKM2Hjs.ToggleMcpToolRequestParamsSchema; exports.ToggleMcpToolRequestSchema = _chunk4G2RKM2Hjs.ToggleMcpToolRequestSchema; exports.ToggleMcpToolResponseSchema = _chunk4G2RKM2Hjs.ToggleMcpToolResponseSchema; exports.ToggleMcpToolResultSchema = _chunk4G2RKM2Hjs.ToggleMcpToolResultSchema; exports.TokenUsageSchema = _chunk4G2RKM2Hjs.TokenUsageSchema; exports.ToolCallNotificationSchema = _chunk4G2RKM2Hjs.ToolCallNotificationSchema; exports.ToolConfirmationDetailsSchema = _chunk4G2RKM2Hjs.ToolConfirmationDetailsSchema; exports.ToolConfirmationInfoSchema = _chunk4G2RKM2Hjs.ToolConfirmationInfoSchema; exports.ToolConfirmationListItemSchema = _chunk4G2RKM2Hjs.ToolConfirmationListItemSchema; exports.ToolConfirmationOutcome = _chunk4G2RKM2Hjs.ToolConfirmationOutcome; exports.ToolConfirmationType = _chunk4G2RKM2Hjs.ToolConfirmationType; exports.ToolProgressUpdateNotificationSchema = _chunk4G2RKM2Hjs.ToolProgressUpdateNotificationSchema; exports.ToolProgressUpdateSchema = _chunk4G2RKM2Hjs.ToolProgressUpdateSchema; exports.ToolResultBlockSchema = _chunk4G2RKM2Hjs.ToolResultSchema; exports.ToolResultNotificationSchema = _chunk4G2RKM2Hjs.ToolResultNotificationSchema; exports.ToolSelectionOverridesSchema = _chunk4G2RKM2Hjs.ToolSelectionOverridesSchema; exports.ToolUseBlockSchema = _chunk4G2RKM2Hjs.ToolUseSchema; exports.ToolUseSchema = _chunk4G2RKM2Hjs.ToolUseSchema2; exports.TraceContextMetaSchema = _chunk4G2RKM2Hjs.TraceContextMetaSchema; exports.TransportDirection = TransportDirection; exports.TunnelConnection = _chunk4G2RKM2Hjs.TunnelConnection; exports.UpdateSessionSettingsRequestParamsSchema = _chunk4G2RKM2Hjs.UpdateSessionSettingsRequestParamsSchema; exports.UpdateSessionSettingsRequestSchema = _chunk4G2RKM2Hjs.UpdateSessionSettingsRequestSchema; exports.UpdateSessionSettingsResponseSchema = _chunk4G2RKM2Hjs.UpdateSessionSettingsResponseSchema; exports.UpdateSessionSettingsResultSchema = _chunk4G2RKM2Hjs.UpdateSessionSettingsResultSchema; exports.VerificationCommandSchema = _chunk4G2RKM2Hjs.VerificationCommandSchema; exports.VerificationSchema = _chunk4G2RKM2Hjs.VerificationSchema; exports.WINDOWS_JOB_OBJECT_ERROR_MARKER = WINDOWS_JOB_OBJECT_ERROR_MARKER; exports.WebSocketConnectionError = _chunk4G2RKM2Hjs.WebSocketConnectionError; exports.WebSocketDaemonTransport = _chunk4G2RKM2Hjs.WebSocketDaemonTransport; exports.WorkerCompletedEntrySchema = _chunk4G2RKM2Hjs.WorkerCompletedEntrySchema; exports.WorkerFailedEntrySchema = _chunk4G2RKM2Hjs.WorkerFailedEntrySchema; exports.WorkerPausedEntrySchema = _chunk4G2RKM2Hjs.WorkerPausedEntrySchema; exports.WorkerSelectedFeatureEntrySchema = _chunk4G2RKM2Hjs.WorkerSelectedFeatureEntrySchema; exports.WorkerStartedEntrySchema = _chunk4G2RKM2Hjs.WorkerStartedEntrySchema; exports.WorkerStateInfoSchema = _chunk4G2RKM2Hjs.WorkerStateInfoSchema; exports.__resetTransportLoggerForTests = __resetTransportLoggerForTests; exports.buildUserMessageContentBlocks = _chunk4G2RKM2Hjs.buildUserMessageContentBlocks; exports.configureDaemonCoreDeps = _chunk4G2RKM2Hjs.configureDaemonCoreDeps; exports.connectAndAuthenticate = _chunk4G2RKM2Hjs.connectAndAuthenticate; exports.connectToDaemon = _chunk4G2RKM2Hjs.connectToDaemon; exports.connectWithRetry = _chunk4G2RKM2Hjs.connectWithRetry; exports.convertNotificationToStreamMessage = _chunk4G2RKM2Hjs.convertNotificationToStreamMessage; exports.createComputer = _chunk4G2RKM2Hjs.createComputer; exports.createResponseSchema = _chunk4G2RKM2Hjs.createResponseSchema; exports.createSdkMcpServer = createSdkMcpServer; exports.createSession = createSession; exports.createWebSocketDaemonClient = _chunk4G2RKM2Hjs.createWebSocketDaemonClient; exports.defaultDaemonCoreDeps = _chunk4G2RKM2Hjs.defaultDaemonCoreDeps; exports.deleteComputer = _chunk4G2RKM2Hjs.deleteComputer; exports.filterMessagesForUI = _chunk4G2RKM2Hjs.filterMessagesForUI; exports.getComputer = _chunk4G2RKM2Hjs.getComputer; exports.getComputerByName = _chunk4G2RKM2Hjs.getComputerByName; exports.getComputerMetrics = _chunk4G2RKM2Hjs.getComputerMetrics; exports.getMachineTemplate = _chunk4G2RKM2Hjs.getMachineTemplate; exports.getPermissionToolInputForDisplay = _chunk4G2RKM2Hjs.getPermissionToolInputForDisplay; exports.getQueuedUserMessageDisplayGroup = _chunk4G2RKM2Hjs.getQueuedUserMessageDisplayGroup; exports.getQueuedUserMessageReviewPriority = _chunk4G2RKM2Hjs.getQueuedUserMessageReviewPriority; exports.getSubagentCallingMetadata = _chunk4G2RKM2Hjs.getSubagentCallingMetadata; exports.getToolResultBlocks = _chunk4G2RKM2Hjs.getToolResultBlocks; exports.getToolResultToolUseId = _chunk4G2RKM2Hjs.getToolResultToolUseId; exports.hasDecoupledInteractionSettings = _chunk4G2RKM2Hjs.hasDecoupledInteractionSettings; exports.hasSubagentSessionTag = _chunk4G2RKM2Hjs.hasSubagentSessionTag; exports.inspectJsonRpcEnvelope = _chunk4G2RKM2Hjs.inspectJsonRpcEnvelope; exports.isDaemonQueuedMessageKind = _chunk4G2RKM2Hjs.isDaemonQueuedMessageKind; exports.isPendingToolResultMarker = _chunk4G2RKM2Hjs.isPendingToolResultMarker; exports.isPersistedHookMessage = _chunk4G2RKM2Hjs.isPersistedHookMessage; exports.isReviewableQueuedMessageKind = _chunk4G2RKM2Hjs.isReviewableQueuedMessageKind; exports.isTransportLoggingEnabled = isTransportLoggingEnabled; exports.listComputers = _chunk4G2RKM2Hjs.listComputers; exports.listMachineTemplates = _chunk4G2RKM2Hjs.listMachineTemplates; exports.listModels = listModels; exports.listRemoteSessions = _chunk4G2RKM2Hjs.listRemoteSessions; exports.listSessions = listSessions; exports.logTransportMessage = logTransportMessage; exports.machineTypeToMachineConnectionType = _chunk4G2RKM2Hjs.machineTypeToMachineConnectionType; exports.noopLogger = noopLogger; exports.orderMessagesByParentChain = _chunk4G2RKM2Hjs.orderMessagesByParentChain; exports.recordComputerConnectSli = _chunk4G2RKM2Hjs.recordComputerConnectSli; exports.refreshComputer = _chunk4G2RKM2Hjs.refreshComputer; exports.repairParentChainCorruption = _chunk4G2RKM2Hjs.repairParentChainCorruption; exports.resolveExecCoreDeps = resolveExecCoreDeps; exports.restartComputer = _chunk4G2RKM2Hjs.restartComputer; exports.resumeSession = resumeSession; exports.retryInstallDeps = _chunk4G2RKM2Hjs.retryInstallDeps; exports.retryWithLogger = _chunk4G2RKM2Hjs.retryWithLogger; exports.run = run; exports.spawnWithWindowsJobObjectRetry = spawnWithWindowsJobObjectRetry; exports.sumTokenUsage = _chunk4G2RKM2Hjs.sumTokenUsage; exports.summarizeSessionToolUsage = _chunk4G2RKM2Hjs.summarizeSessionToolUsage; exports.toError = _chunk4G2RKM2Hjs.toError; exports.tool = tool; exports.updateComputer = _chunk4G2RKM2Hjs.updateComputer;
|
|
4731
|
+
//# sourceMappingURL=node.js.map
|