backeer-opencode 0.3.1 → 0.4.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.
@@ -1,3 +1,1859 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res, err) => function __init() {
4
+ if (err) throw err[0];
5
+ try {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ } catch (e) {
8
+ throw err = [e], e;
9
+ }
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+
16
+ // node_modules/@opencode/client/dist/chunks/service-timing-9rqn6x4v.js
17
+ function __exportSetter(name, newValue) {
18
+ this[name] = __returnValue.bind(null, newValue);
19
+ }
20
+ var __defProp2, __returnValue, __export2;
21
+ var init_service_timing_9rqn6x4v = __esm({
22
+ "node_modules/@opencode/client/dist/chunks/service-timing-9rqn6x4v.js"() {
23
+ __defProp2 = Object.defineProperty;
24
+ __returnValue = (v) => v;
25
+ __export2 = (target, all) => {
26
+ for (var name in all)
27
+ __defProp2(target, name, {
28
+ get: all[name],
29
+ enumerable: true,
30
+ configurable: true,
31
+ set: __exportSetter.bind(all, name)
32
+ });
33
+ };
34
+ }
35
+ });
36
+
37
+ // node_modules/@opencode/client/dist/chunks/service-timing-frbwqjmf.js
38
+ function make7(connect) {
39
+ let current;
40
+ const capacity = 4096;
41
+ function stop2(connection) {
42
+ connection.connected = void 0;
43
+ connection.controller.abort();
44
+ if (current === connection)
45
+ current = void 0;
46
+ }
47
+ async function run(connection) {
48
+ let iterator;
49
+ let completion = {};
50
+ try {
51
+ if (connection.controller.signal.aborted)
52
+ return;
53
+ iterator = connect(connection.controller.signal, () => {
54
+ connection.subscribers.forEach((subscriber) => subscriber.activity?.());
55
+ })[Symbol.asyncIterator]();
56
+ while (!connection.controller.signal.aborted) {
57
+ const item = await iterator.next();
58
+ if (item.done || connection.controller.signal.aborted)
59
+ break;
60
+ if (item.value.type === "server.connected")
61
+ connection.connected = item.value;
62
+ connection.subscribers.forEach((subscriber) => subscriber.push(item.value));
63
+ }
64
+ } catch (error) {
65
+ completion = { error };
66
+ } finally {
67
+ stop2(connection);
68
+ try {
69
+ await iterator?.return?.();
70
+ } catch (error) {
71
+ if (!("error" in completion))
72
+ completion = { error };
73
+ }
74
+ connection.subscribers.forEach((subscriber) => subscriber.finish(completion));
75
+ }
76
+ }
77
+ return {
78
+ subscribe(options) {
79
+ return {
80
+ [Symbol.asyncIterator]() {
81
+ const pending = [];
82
+ const queued = [];
83
+ let started = false;
84
+ let completion;
85
+ let connection;
86
+ function finish(result, discard = true) {
87
+ completion = result;
88
+ if (discard)
89
+ queued.length = 0;
90
+ options?.signal?.removeEventListener("abort", abort);
91
+ if (connection?.subscribers.delete(subscriber) && !connection.subscribers.size)
92
+ stop2(connection);
93
+ pending.splice(0).forEach((request) => {
94
+ if ("error" in result)
95
+ request.reject(result.error);
96
+ else
97
+ request.resolve({ done: true, value: void 0 });
98
+ });
99
+ }
100
+ function abort() {
101
+ finish({});
102
+ }
103
+ const subscriber = {
104
+ activity: options?.onActivity,
105
+ finish(result) {
106
+ finish(result, false);
107
+ },
108
+ push(value) {
109
+ if (completion)
110
+ return;
111
+ const request = pending.shift();
112
+ if (request) {
113
+ request.resolve({ done: false, value });
114
+ return;
115
+ }
116
+ if (queued.length === capacity) {
117
+ finish({ error: new Error(`Event subscriber exceeded its ${capacity}-event capacity`) });
118
+ return;
119
+ }
120
+ queued.push(value);
121
+ }
122
+ };
123
+ function start() {
124
+ if (completion)
125
+ return;
126
+ const fresh = !current;
127
+ connection = current ?? {
128
+ controller: new AbortController(),
129
+ subscribers: /* @__PURE__ */ new Set()
130
+ };
131
+ current = connection;
132
+ connection.subscribers.add(subscriber);
133
+ if (connection.connected)
134
+ subscriber.push(connection.connected);
135
+ if (fresh)
136
+ run(connection);
137
+ }
138
+ return {
139
+ next() {
140
+ const value = queued.shift();
141
+ if (value)
142
+ return Promise.resolve({ done: false, value });
143
+ if (completion) {
144
+ if ("error" in completion)
145
+ return Promise.reject(completion.error);
146
+ return Promise.resolve({ done: true, value: void 0 });
147
+ }
148
+ if (options?.signal?.aborted) {
149
+ abort();
150
+ return Promise.resolve({ done: true, value: void 0 });
151
+ }
152
+ const request = Promise.withResolvers();
153
+ pending.push(request);
154
+ if (!started) {
155
+ started = true;
156
+ options?.signal?.addEventListener("abort", abort, { once: true });
157
+ start();
158
+ }
159
+ return request.promise;
160
+ },
161
+ return() {
162
+ finish({});
163
+ return Promise.resolve({ done: true, value: void 0 });
164
+ }
165
+ };
166
+ }
167
+ };
168
+ }
169
+ };
170
+ }
171
+ var exports_shared_events;
172
+ var init_service_timing_frbwqjmf = __esm({
173
+ "node_modules/@opencode/client/dist/chunks/service-timing-frbwqjmf.js"() {
174
+ init_service_timing_9rqn6x4v();
175
+ exports_shared_events = {};
176
+ __export2(exports_shared_events, {
177
+ SharedEvents: () => exports_shared_events,
178
+ make: () => make7
179
+ });
180
+ }
181
+ });
182
+
183
+ // node_modules/@opencode/client/dist/chunks/service-timing-js54wxgp.js
184
+ var ClientError2;
185
+ var init_service_timing_js54wxgp = __esm({
186
+ "node_modules/@opencode/client/dist/chunks/service-timing-js54wxgp.js"() {
187
+ ClientError2 = class extends Error {
188
+ reason;
189
+ name = "ClientError";
190
+ constructor(reason, options) {
191
+ const detail = options?.detail ?? (options?.cause instanceof Error ? options.cause.message : void 0);
192
+ super(detail ? `${reason}: ${detail}` : reason, options);
193
+ this.reason = reason;
194
+ }
195
+ };
196
+ }
197
+ });
198
+
199
+ // node_modules/@opencode/client/dist/chunks/service-timing-tbh3h57v.js
200
+ function make3(options) {
201
+ const fetch2 = options.fetch ?? globalThis.fetch;
202
+ const prepare = (descriptor, requestOptions) => {
203
+ const baseUrl = new URL(options.baseUrl);
204
+ if (!baseUrl.pathname.endsWith("/"))
205
+ baseUrl.pathname += "/";
206
+ const url = new URL(descriptor.path.slice(1), baseUrl);
207
+ for (const [key, value] of Object.entries(descriptor.query ?? {}))
208
+ appendQuery(url.searchParams, key, value);
209
+ const headers = new Headers(options.headers);
210
+ for (const [key, value] of Object.entries(descriptor.headers ?? {})) {
211
+ if (value !== void 0 && value !== null)
212
+ headers.set(key, String(value));
213
+ }
214
+ for (const [key, value] of new Headers(requestOptions?.headers))
215
+ headers.set(key, value);
216
+ if (descriptor.body !== void 0 && !headers.has("content-type"))
217
+ headers.set("content-type", descriptor.binaryBody ? "application/octet-stream" : "application/json");
218
+ return {
219
+ url,
220
+ init: {
221
+ method: descriptor.method,
222
+ signal: requestOptions?.signal,
223
+ headers,
224
+ body: descriptor.body === void 0 ? void 0 : descriptor.binaryBody ? descriptor.body : JSON.stringify(descriptor.body)
225
+ }
226
+ };
227
+ };
228
+ const execute = async (descriptor, requestOptions) => {
229
+ try {
230
+ const prepared = prepare(descriptor, requestOptions);
231
+ return await fetch2(prepared.url, prepared.init);
232
+ } catch (cause) {
233
+ throw new ClientError2("Transport", { cause });
234
+ }
235
+ };
236
+ const responseError = async (response, descriptor) => {
237
+ if (descriptor.declaredStatuses.includes(response.status))
238
+ throw declared(await json(response));
239
+ try {
240
+ await response.body?.cancel();
241
+ } catch {
242
+ }
243
+ throw new ClientError2("UnexpectedStatus", { cause: { status: response.status }, detail: String(response.status) });
244
+ };
245
+ const request = async (descriptor, requestOptions) => {
246
+ const response = await execute(descriptor, requestOptions);
247
+ if (response.status !== descriptor.successStatus)
248
+ return responseError(response, descriptor);
249
+ if (descriptor.binary)
250
+ return new Uint8Array(await response.arrayBuffer());
251
+ if (descriptor.empty) {
252
+ try {
253
+ await response.body?.cancel();
254
+ } catch {
255
+ }
256
+ return;
257
+ }
258
+ return await json(response);
259
+ };
260
+ const sse = (descriptor, requestOptions) => ({
261
+ async *[Symbol.asyncIterator]() {
262
+ const response = await execute(descriptor, requestOptions);
263
+ if (response.status !== descriptor.successStatus)
264
+ await responseError(response, descriptor);
265
+ if (!isContentType(response, "text/event-stream")) {
266
+ try {
267
+ await response.body?.cancel();
268
+ } catch {
269
+ }
270
+ throw new ClientError2("UnsupportedContentType", { detail: response.headers.get("content-type") });
271
+ }
272
+ if (response.body === null)
273
+ throw new ClientError2("MalformedResponse");
274
+ const reader = response.body.getReader();
275
+ const decoder = new TextDecoder();
276
+ let buffer = "";
277
+ try {
278
+ while (true) {
279
+ let next;
280
+ try {
281
+ next = await reader.read();
282
+ } catch (cause) {
283
+ throw new ClientError2("Transport", { cause });
284
+ }
285
+ if (!next.done)
286
+ requestOptions?.onActivity?.();
287
+ buffer += decoder.decode(next.value, { stream: !next.done });
288
+ if (buffer.length > maxSseEventBytes)
289
+ throw new ClientError2("SseEventTooLarge");
290
+ const trailingCarriageReturn = !next.done && buffer.endsWith("\r");
291
+ if (trailingCarriageReturn)
292
+ buffer = buffer.slice(0, -1);
293
+ buffer = buffer.replaceAll(`\r
294
+ `, `
295
+ `).replaceAll("\r", `
296
+ `);
297
+ if (trailingCarriageReturn)
298
+ buffer += "\r";
299
+ if (next.done && buffer !== "")
300
+ buffer += `
301
+
302
+ `;
303
+ let boundary = buffer.indexOf(`
304
+
305
+ `);
306
+ while (boundary >= 0) {
307
+ const block = buffer.slice(0, boundary);
308
+ buffer = buffer.slice(boundary + 2);
309
+ const data = block.split(`
310
+ `).flatMap((line) => line.startsWith("data:") ? [line.slice(5).trimStart()] : []).join(`
311
+ `);
312
+ if (data !== "") {
313
+ try {
314
+ yield JSON.parse(data);
315
+ } catch (cause) {
316
+ throw new ClientError2("MalformedResponse", { cause });
317
+ }
318
+ }
319
+ boundary = buffer.indexOf(`
320
+
321
+ `);
322
+ }
323
+ if (next.done)
324
+ return;
325
+ }
326
+ } finally {
327
+ try {
328
+ await reader.cancel();
329
+ } catch {
330
+ }
331
+ reader.releaseLock();
332
+ }
333
+ }
334
+ });
335
+ return {
336
+ server: {
337
+ info: (requestOptions) => request({ method: "GET", path: `/api/info`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions),
338
+ pair: (requestOptions) => request({ method: "POST", path: `/api/pair`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions),
339
+ connect: (input, requestOptions) => request({
340
+ method: "GET",
341
+ path: `/auth/connect/${encodeURIComponent(input.code)}`,
342
+ successStatus: 200,
343
+ declaredStatuses: [400, 401],
344
+ empty: false
345
+ }, requestOptions)
346
+ },
347
+ location: {
348
+ get: (input, requestOptions) => request({
349
+ method: "GET",
350
+ path: `/api/location`,
351
+ query: { location: input?.["location"] },
352
+ successStatus: 200,
353
+ declaredStatuses: [400, 401, 404],
354
+ empty: false
355
+ }, requestOptions),
356
+ reload: (requestOptions) => request({
357
+ method: "POST",
358
+ path: `/api/location/reload`,
359
+ successStatus: 204,
360
+ declaredStatuses: [400, 401, 503],
361
+ empty: true
362
+ }, requestOptions)
363
+ },
364
+ agent: {
365
+ list: (input, requestOptions) => request({
366
+ method: "GET",
367
+ path: `/api/agent`,
368
+ query: { location: input?.["location"] },
369
+ successStatus: 200,
370
+ declaredStatuses: [400, 401, 404],
371
+ empty: false
372
+ }, requestOptions),
373
+ get: (input, requestOptions) => request({
374
+ method: "GET",
375
+ path: `/api/agent/${encodeURIComponent(input.agentID)}`,
376
+ query: { location: input["location"] },
377
+ successStatus: 200,
378
+ declaredStatuses: [400, 401, 404],
379
+ empty: false
380
+ }, requestOptions)
381
+ },
382
+ plugin: {
383
+ list: (input, requestOptions) => request({
384
+ method: "GET",
385
+ path: `/api/plugin`,
386
+ query: { location: input?.["location"] },
387
+ successStatus: 200,
388
+ declaredStatuses: [400, 401, 404],
389
+ empty: false
390
+ }, requestOptions),
391
+ check: (input, requestOptions) => request({
392
+ method: "POST",
393
+ path: `/api/plugin/check`,
394
+ query: { location: input?.["location"] },
395
+ body: { target: input?.["target"] },
396
+ successStatus: 200,
397
+ declaredStatuses: [400, 401, 404],
398
+ empty: false
399
+ }, requestOptions),
400
+ update: (input, requestOptions) => request({
401
+ method: "POST",
402
+ path: `/api/plugin/update`,
403
+ query: { location: input["location"] },
404
+ body: { targets: input["targets"] },
405
+ successStatus: 204,
406
+ declaredStatuses: [400, 401, 404, 503],
407
+ empty: true
408
+ }, requestOptions)
409
+ },
410
+ session: {
411
+ list: (input, requestOptions) => request({
412
+ method: "GET",
413
+ path: `/api/session`,
414
+ query: {
415
+ limit: input?.["limit"],
416
+ order: input?.["order"],
417
+ search: input?.["search"],
418
+ parentID: input?.["parentID"],
419
+ directory: input?.["directory"],
420
+ project: input?.["project"],
421
+ subpath: input?.["subpath"],
422
+ cursor: input?.["cursor"]
423
+ },
424
+ successStatus: 200,
425
+ declaredStatuses: [400, 401],
426
+ empty: false
427
+ }, requestOptions),
428
+ stats: (input, requestOptions) => request({
429
+ method: "GET",
430
+ path: `/api/experimental/session/stats`,
431
+ query: {
432
+ from: input?.["from"],
433
+ to: input?.["to"],
434
+ project: input?.["project"],
435
+ timezone: input?.["timezone"],
436
+ tools: input?.["tools"]
437
+ },
438
+ successStatus: 200,
439
+ declaredStatuses: [400, 401],
440
+ empty: false
441
+ }, requestOptions).then((value) => value.data),
442
+ create: (input, requestOptions) => request({
443
+ method: "POST",
444
+ path: `/api/session`,
445
+ body: {
446
+ id: input?.["id"],
447
+ parentID: input?.["parentID"],
448
+ title: input?.["title"],
449
+ agent: input?.["agent"],
450
+ model: input?.["model"],
451
+ location: input?.["location"],
452
+ metadata: input?.["metadata"],
453
+ permissions: input?.["permissions"]
454
+ },
455
+ successStatus: 200,
456
+ declaredStatuses: [400, 401, 404],
457
+ empty: false
458
+ }, requestOptions).then((value) => value.data),
459
+ import: (input, requestOptions) => request({
460
+ method: "POST",
461
+ path: `/api/experimental/session/import`,
462
+ body: { info: input["info"], messages: input["messages"], location: input["location"] },
463
+ successStatus: 200,
464
+ declaredStatuses: [400, 401, 404, 409],
465
+ empty: false
466
+ }, requestOptions).then((value) => value.data),
467
+ export: (input, requestOptions) => request({
468
+ method: "GET",
469
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/export`,
470
+ query: { sanitize: input["sanitize"] },
471
+ successStatus: 200,
472
+ declaredStatuses: [400, 401, 404, 500],
473
+ empty: false
474
+ }, requestOptions).then((value) => value.data),
475
+ active: (requestOptions) => request({
476
+ method: "GET",
477
+ path: `/api/session/active`,
478
+ successStatus: 200,
479
+ declaredStatuses: [400, 401],
480
+ empty: false
481
+ }, requestOptions).then((value) => value.data),
482
+ get: (input, requestOptions) => request({
483
+ method: "GET",
484
+ path: `/api/session/${encodeURIComponent(input.sessionID)}`,
485
+ successStatus: 200,
486
+ declaredStatuses: [400, 401, 404],
487
+ empty: false
488
+ }, requestOptions).then((value) => value.data),
489
+ remove: (input, requestOptions) => request({
490
+ method: "DELETE",
491
+ path: `/api/session/${encodeURIComponent(input.sessionID)}`,
492
+ successStatus: 204,
493
+ declaredStatuses: [400, 401, 404],
494
+ empty: true
495
+ }, requestOptions),
496
+ fork: (input, requestOptions) => request({
497
+ method: "POST",
498
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/fork`,
499
+ body: { before: input["before"] },
500
+ successStatus: 200,
501
+ declaredStatuses: [400, 401, 404],
502
+ empty: false
503
+ }, requestOptions).then((value) => value.data),
504
+ switchAgent: (input, requestOptions) => request({
505
+ method: "POST",
506
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/agent`,
507
+ body: { agent: input["agent"] },
508
+ successStatus: 204,
509
+ declaredStatuses: [400, 401, 404],
510
+ empty: true
511
+ }, requestOptions),
512
+ switchModel: (input, requestOptions) => request({
513
+ method: "POST",
514
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/model`,
515
+ body: { model: input["model"] },
516
+ successStatus: 204,
517
+ declaredStatuses: [400, 401, 404],
518
+ empty: true
519
+ }, requestOptions),
520
+ update: (input, requestOptions) => request({
521
+ method: "PATCH",
522
+ path: `/api/session/${encodeURIComponent(input.sessionID)}`,
523
+ body: { title: input["title"], metadata: input["metadata"], permissions: input["permissions"] },
524
+ successStatus: 204,
525
+ declaredStatuses: [400, 401, 404],
526
+ empty: true
527
+ }, requestOptions),
528
+ move: (input, requestOptions) => request({
529
+ method: "POST",
530
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/move`,
531
+ body: { directory: input["directory"], delivery: input["delivery"] },
532
+ successStatus: 204,
533
+ declaredStatuses: [400, 401, 404],
534
+ empty: true
535
+ }, requestOptions),
536
+ prompt: (input, requestOptions) => request({
537
+ method: "POST",
538
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/prompt`,
539
+ body: {
540
+ id: input["id"],
541
+ text: input["text"],
542
+ files: input["files"],
543
+ agents: input["agents"],
544
+ skills: input["skills"],
545
+ metadata: input["metadata"],
546
+ delivery: input["delivery"],
547
+ resume: input["resume"]
548
+ },
549
+ successStatus: 200,
550
+ declaredStatuses: [400, 401, 404, 409],
551
+ empty: false
552
+ }, requestOptions).then((value) => value.data),
553
+ command: (input, requestOptions) => request({
554
+ method: "POST",
555
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/command`,
556
+ body: {
557
+ name: input["name"],
558
+ text: input["text"],
559
+ files: input["files"],
560
+ agents: input["agents"],
561
+ skills: input["skills"],
562
+ delivery: input["delivery"]
563
+ },
564
+ successStatus: 204,
565
+ declaredStatuses: [400, 401, 404, 500],
566
+ empty: true
567
+ }, requestOptions),
568
+ skill: (input, requestOptions) => request({
569
+ method: "POST",
570
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/skill`,
571
+ body: { id: input["id"], resume: input["resume"] },
572
+ successStatus: 204,
573
+ declaredStatuses: [400, 401, 404],
574
+ empty: true
575
+ }, requestOptions),
576
+ synthetic: (input, requestOptions) => request({
577
+ method: "POST",
578
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/synthetic`,
579
+ body: {
580
+ id: input["id"],
581
+ text: input["text"],
582
+ description: input["description"],
583
+ metadata: input["metadata"],
584
+ delivery: input["delivery"],
585
+ resume: input["resume"]
586
+ },
587
+ successStatus: 200,
588
+ declaredStatuses: [400, 401, 404, 409],
589
+ empty: false
590
+ }, requestOptions).then((value) => value.data),
591
+ shell: (input, requestOptions) => request({
592
+ method: "POST",
593
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/shell`,
594
+ body: { id: input["id"], command: input["command"] },
595
+ successStatus: 204,
596
+ declaredStatuses: [400, 401, 404],
597
+ empty: true
598
+ }, requestOptions),
599
+ compact: (input, requestOptions) => request({
600
+ method: "POST",
601
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/compact`,
602
+ body: { id: input["id"], delivery: input["delivery"] },
603
+ successStatus: 200,
604
+ declaredStatuses: [400, 401, 404, 409],
605
+ empty: false
606
+ }, requestOptions).then((value) => value.data),
607
+ wait: (input, requestOptions) => request({
608
+ method: "POST",
609
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/wait`,
610
+ successStatus: 204,
611
+ declaredStatuses: [400, 401, 404, 503],
612
+ empty: true
613
+ }, requestOptions),
614
+ revert: {
615
+ stage: (input, requestOptions) => request({
616
+ method: "POST",
617
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/revert/stage`,
618
+ body: { messageID: input["messageID"], files: input["files"] },
619
+ successStatus: 200,
620
+ declaredStatuses: [400, 401, 404, 409, 500],
621
+ empty: false
622
+ }, requestOptions).then((value) => value.data),
623
+ clear: (input, requestOptions) => request({
624
+ method: "DELETE",
625
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/revert`,
626
+ successStatus: 204,
627
+ declaredStatuses: [400, 401, 404, 409, 500],
628
+ empty: true
629
+ }, requestOptions),
630
+ commit: (input, requestOptions) => request({
631
+ method: "POST",
632
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/revert/commit`,
633
+ successStatus: 204,
634
+ declaredStatuses: [400, 401, 404, 409],
635
+ empty: true
636
+ }, requestOptions)
637
+ },
638
+ context: (input, requestOptions) => request({
639
+ method: "GET",
640
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/context`,
641
+ successStatus: 200,
642
+ declaredStatuses: [400, 401, 404, 500],
643
+ empty: false
644
+ }, requestOptions).then((value) => value.data),
645
+ diff: (input, requestOptions) => request({
646
+ method: "GET",
647
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/diff`,
648
+ query: { from: input["from"], to: input["to"], context: input["context"] },
649
+ successStatus: 200,
650
+ declaredStatuses: [400, 401, 404, 500],
651
+ empty: false
652
+ }, requestOptions).then((value) => value.data),
653
+ inbox: {
654
+ list: (input, requestOptions) => request({
655
+ method: "GET",
656
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/inbox`,
657
+ successStatus: 200,
658
+ declaredStatuses: [400, 401, 404],
659
+ empty: false
660
+ }, requestOptions).then((value) => value.data),
661
+ cancel: (input, requestOptions) => request({
662
+ method: "DELETE",
663
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/inbox/${encodeURIComponent(input.inboxID)}`,
664
+ successStatus: 204,
665
+ declaredStatuses: [400, 401, 404],
666
+ empty: true
667
+ }, requestOptions),
668
+ update: (input, requestOptions) => request({
669
+ method: "PATCH",
670
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/inbox/${encodeURIComponent(input.inboxID)}`,
671
+ body: { delivery: input["delivery"] },
672
+ successStatus: 204,
673
+ declaredStatuses: [400, 401, 404, 409],
674
+ empty: true
675
+ }, requestOptions)
676
+ },
677
+ instructions: {
678
+ entry: {
679
+ list: (input, requestOptions) => request({
680
+ method: "GET",
681
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries`,
682
+ successStatus: 200,
683
+ declaredStatuses: [400, 401, 404],
684
+ empty: false
685
+ }, requestOptions).then((value) => value.data),
686
+ put: (input, requestOptions) => request({
687
+ method: "PUT",
688
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`,
689
+ body: { value: input["value"] },
690
+ successStatus: 204,
691
+ declaredStatuses: [400, 401, 404, 413],
692
+ empty: true
693
+ }, requestOptions),
694
+ remove: (input, requestOptions) => request({
695
+ method: "DELETE",
696
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/instructions/entries/${encodeURIComponent(input.key)}`,
697
+ successStatus: 204,
698
+ declaredStatuses: [400, 401, 404],
699
+ empty: true
700
+ }, requestOptions)
701
+ }
702
+ },
703
+ generate: (input, requestOptions) => request({
704
+ method: "POST",
705
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/generate`,
706
+ body: { prompt: input["prompt"] },
707
+ successStatus: 200,
708
+ declaredStatuses: [400, 401, 404, 503],
709
+ empty: false
710
+ }, requestOptions).then((value) => value.data),
711
+ log: (input, requestOptions) => sse({
712
+ method: "GET",
713
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/log`,
714
+ query: { after: input["after"], follow: input["follow"] },
715
+ successStatus: 200,
716
+ declaredStatuses: [400, 401, 404],
717
+ empty: false
718
+ }, requestOptions),
719
+ interrupt: (input, requestOptions) => request({
720
+ method: "POST",
721
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/interrupt`,
722
+ query: { resume: input["resume"] },
723
+ successStatus: 200,
724
+ declaredStatuses: [400, 401, 404],
725
+ empty: false
726
+ }, requestOptions),
727
+ background: (input, requestOptions) => request({
728
+ method: "POST",
729
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/background`,
730
+ successStatus: 204,
731
+ declaredStatuses: [400, 401, 404],
732
+ empty: true
733
+ }, requestOptions),
734
+ message: {
735
+ get: (input, requestOptions) => request({
736
+ method: "GET",
737
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/message/${encodeURIComponent(input.messageID)}`,
738
+ successStatus: 200,
739
+ declaredStatuses: [400, 401, 404],
740
+ empty: false
741
+ }, requestOptions).then((value) => value.data)
742
+ },
743
+ form: {
744
+ list: (input, requestOptions) => request({
745
+ method: "GET",
746
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form`,
747
+ successStatus: 200,
748
+ declaredStatuses: [400, 401, 404],
749
+ empty: false
750
+ }, requestOptions).then((value) => value.data),
751
+ create: (input, requestOptions) => request({
752
+ method: "POST",
753
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form`,
754
+ body: { id: input["id"], title: input["title"], metadata: input["metadata"], fields: input["fields"] },
755
+ successStatus: 200,
756
+ declaredStatuses: [400, 401, 404, 409],
757
+ empty: false
758
+ }, requestOptions).then((value) => value.data),
759
+ get: (input, requestOptions) => request({
760
+ method: "GET",
761
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form/${encodeURIComponent(input.formID)}`,
762
+ successStatus: 200,
763
+ declaredStatuses: [400, 401, 404],
764
+ empty: false
765
+ }, requestOptions).then((value) => value.data),
766
+ reply: (input, requestOptions) => request({
767
+ method: "POST",
768
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form/${encodeURIComponent(input.formID)}/reply`,
769
+ body: { answer: input["answer"] },
770
+ successStatus: 204,
771
+ declaredStatuses: [400, 401, 404, 409],
772
+ empty: true
773
+ }, requestOptions),
774
+ cancel: (input, requestOptions) => request({
775
+ method: "DELETE",
776
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/form/${encodeURIComponent(input.formID)}`,
777
+ query: { message: input["message"] },
778
+ successStatus: 204,
779
+ declaredStatuses: [400, 401, 404, 409],
780
+ empty: true
781
+ }, requestOptions)
782
+ },
783
+ environment: (input, requestOptions) => request({
784
+ method: "PUT",
785
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/environment`,
786
+ body: { variables: input["variables"] },
787
+ successStatus: 204,
788
+ declaredStatuses: [400, 401, 404],
789
+ empty: true
790
+ }, requestOptions),
791
+ view: (input, requestOptions) => request({
792
+ method: "POST",
793
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/view`,
794
+ body: { idle: input["idle"] },
795
+ successStatus: 204,
796
+ declaredStatuses: [400, 401, 404],
797
+ empty: true
798
+ }, requestOptions)
799
+ },
800
+ message: {
801
+ list: (input, requestOptions) => request({
802
+ method: "GET",
803
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/message`,
804
+ query: { limit: input["limit"], order: input["order"], cursor: input["cursor"], type: input["type"] },
805
+ successStatus: 200,
806
+ declaredStatuses: [400, 401, 404, 500],
807
+ empty: false
808
+ }, requestOptions)
809
+ },
810
+ model: {
811
+ list: (input, requestOptions) => request({
812
+ method: "GET",
813
+ path: `/api/model`,
814
+ query: { location: input?.["location"] },
815
+ successStatus: 200,
816
+ declaredStatuses: [400, 401, 404, 503],
817
+ empty: false
818
+ }, requestOptions),
819
+ default: (input, requestOptions) => request({
820
+ method: "GET",
821
+ path: `/api/model/default`,
822
+ query: { location: input?.["location"] },
823
+ successStatus: 200,
824
+ declaredStatuses: [400, 401, 404, 503],
825
+ empty: false
826
+ }, requestOptions)
827
+ },
828
+ generate: {
829
+ text: (input, requestOptions) => request({
830
+ method: "POST",
831
+ path: `/api/experimental/generate`,
832
+ body: { prompt: input["prompt"], model: input["model"] },
833
+ successStatus: 200,
834
+ declaredStatuses: [400, 401, 404, 503],
835
+ empty: false
836
+ }, requestOptions).then((value) => value.data)
837
+ },
838
+ provider: {
839
+ list: (input, requestOptions) => request({
840
+ method: "GET",
841
+ path: `/api/provider`,
842
+ query: { location: input?.["location"] },
843
+ successStatus: 200,
844
+ declaredStatuses: [400, 401, 404, 503],
845
+ empty: false
846
+ }, requestOptions),
847
+ get: (input, requestOptions) => request({
848
+ method: "GET",
849
+ path: `/api/provider/${encodeURIComponent(input.providerID)}`,
850
+ query: { location: input["location"] },
851
+ successStatus: 200,
852
+ declaredStatuses: [400, 401, 404, 503],
853
+ empty: false
854
+ }, requestOptions)
855
+ },
856
+ integration: {
857
+ list: (input, requestOptions) => request({
858
+ method: "GET",
859
+ path: `/api/integration`,
860
+ query: { location: input?.["location"] },
861
+ successStatus: 200,
862
+ declaredStatuses: [400, 401, 404],
863
+ empty: false
864
+ }, requestOptions),
865
+ get: (input, requestOptions) => request({
866
+ method: "GET",
867
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}`,
868
+ query: { location: input["location"] },
869
+ successStatus: 200,
870
+ declaredStatuses: [400, 401, 404],
871
+ empty: false
872
+ }, requestOptions),
873
+ wellknown: {
874
+ add: (input, requestOptions) => request({
875
+ method: "POST",
876
+ path: `/api/experimental/integration/wellknown`,
877
+ query: { location: input["location"] },
878
+ body: { url: input["url"] },
879
+ successStatus: 204,
880
+ declaredStatuses: [400, 401, 404],
881
+ empty: true
882
+ }, requestOptions)
883
+ },
884
+ connect: {
885
+ key: (input, requestOptions) => request({
886
+ method: "POST",
887
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/key`,
888
+ query: { location: input["location"] },
889
+ body: { key: input["key"], answer: input["answer"], label: input["label"] },
890
+ successStatus: 204,
891
+ declaredStatuses: [400, 401, 404],
892
+ empty: true
893
+ }, requestOptions),
894
+ external: (input, requestOptions) => request({
895
+ method: "POST",
896
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/external`,
897
+ query: { location: input["location"] },
898
+ body: { methodID: input["methodID"], answer: input["answer"], label: input["label"] },
899
+ successStatus: 204,
900
+ declaredStatuses: [400, 401, 404],
901
+ empty: true
902
+ }, requestOptions)
903
+ },
904
+ oauth: {
905
+ connect: (input, requestOptions) => request({
906
+ method: "POST",
907
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth`,
908
+ query: { location: input["location"] },
909
+ body: { methodID: input["methodID"], answer: input["answer"], label: input["label"] },
910
+ successStatus: 200,
911
+ declaredStatuses: [400, 401, 404],
912
+ empty: false
913
+ }, requestOptions),
914
+ status: (input, requestOptions) => request({
915
+ method: "GET",
916
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth/${encodeURIComponent(input.attemptID)}`,
917
+ query: { location: input["location"] },
918
+ successStatus: 200,
919
+ declaredStatuses: [400, 401, 404],
920
+ empty: false
921
+ }, requestOptions),
922
+ complete: (input, requestOptions) => request({
923
+ method: "POST",
924
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth/${encodeURIComponent(input.attemptID)}/complete`,
925
+ query: { location: input["location"] },
926
+ body: { code: input["code"] },
927
+ successStatus: 204,
928
+ declaredStatuses: [400, 401, 404],
929
+ empty: true
930
+ }, requestOptions),
931
+ cancel: (input, requestOptions) => request({
932
+ method: "DELETE",
933
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/oauth/${encodeURIComponent(input.attemptID)}`,
934
+ query: { location: input["location"] },
935
+ successStatus: 204,
936
+ declaredStatuses: [400, 401, 404],
937
+ empty: true
938
+ }, requestOptions)
939
+ },
940
+ command: {
941
+ connect: (input, requestOptions) => request({
942
+ method: "POST",
943
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/command`,
944
+ query: { location: input["location"] },
945
+ body: { methodID: input["methodID"], label: input["label"] },
946
+ successStatus: 200,
947
+ declaredStatuses: [400, 401, 404],
948
+ empty: false
949
+ }, requestOptions),
950
+ status: (input, requestOptions) => request({
951
+ method: "GET",
952
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/command/${encodeURIComponent(input.attemptID)}`,
953
+ query: { location: input["location"] },
954
+ successStatus: 200,
955
+ declaredStatuses: [400, 401, 404],
956
+ empty: false
957
+ }, requestOptions),
958
+ cancel: (input, requestOptions) => request({
959
+ method: "DELETE",
960
+ path: `/api/integration/${encodeURIComponent(input.integrationID)}/connect/command/${encodeURIComponent(input.attemptID)}`,
961
+ query: { location: input["location"] },
962
+ successStatus: 204,
963
+ declaredStatuses: [400, 401, 404],
964
+ empty: true
965
+ }, requestOptions)
966
+ }
967
+ },
968
+ mcp: {
969
+ list: (input, requestOptions) => request({
970
+ method: "GET",
971
+ path: `/api/mcp`,
972
+ query: { location: input?.["location"] },
973
+ successStatus: 200,
974
+ declaredStatuses: [400, 401, 404],
975
+ empty: false
976
+ }, requestOptions),
977
+ add: (input, requestOptions) => request({
978
+ method: "PUT",
979
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`,
980
+ query: { location: input["location"] },
981
+ body: { config: input["config"] },
982
+ successStatus: 204,
983
+ declaredStatuses: [400, 401, 404],
984
+ empty: true
985
+ }, requestOptions),
986
+ remove: (input, requestOptions) => request({
987
+ method: "DELETE",
988
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}`,
989
+ query: { location: input["location"] },
990
+ successStatus: 204,
991
+ declaredStatuses: [400, 401, 404],
992
+ empty: true
993
+ }, requestOptions),
994
+ connect: (input, requestOptions) => request({
995
+ method: "POST",
996
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/connect`,
997
+ query: { location: input["location"] },
998
+ successStatus: 204,
999
+ declaredStatuses: [400, 401, 404],
1000
+ empty: true
1001
+ }, requestOptions),
1002
+ disconnect: (input, requestOptions) => request({
1003
+ method: "POST",
1004
+ path: `/api/experimental/mcp/${encodeURIComponent(input.server)}/disconnect`,
1005
+ query: { location: input["location"] },
1006
+ successStatus: 204,
1007
+ declaredStatuses: [400, 401, 404],
1008
+ empty: true
1009
+ }, requestOptions),
1010
+ resource: {
1011
+ catalog: (input, requestOptions) => request({
1012
+ method: "GET",
1013
+ path: `/api/mcp/resource`,
1014
+ query: { location: input?.["location"] },
1015
+ successStatus: 200,
1016
+ declaredStatuses: [400, 401, 404],
1017
+ empty: false
1018
+ }, requestOptions)
1019
+ }
1020
+ },
1021
+ credential: {
1022
+ list: (requestOptions) => request({ method: "GET", path: `/api/credential`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions).then((value) => value.data),
1023
+ create: (input, requestOptions) => request({
1024
+ method: "POST",
1025
+ path: `/api/credential`,
1026
+ body: {
1027
+ id: input["id"],
1028
+ integrationID: input["integrationID"],
1029
+ label: input["label"],
1030
+ value: input["value"],
1031
+ activate: input["activate"]
1032
+ },
1033
+ successStatus: 200,
1034
+ declaredStatuses: [400, 401, 409],
1035
+ empty: false
1036
+ }, requestOptions).then((value) => value.data),
1037
+ update: (input, requestOptions) => request({
1038
+ method: "PATCH",
1039
+ path: `/api/credential/${encodeURIComponent(input.credentialID)}`,
1040
+ body: { label: input["label"] },
1041
+ successStatus: 204,
1042
+ declaredStatuses: [400, 401],
1043
+ empty: true
1044
+ }, requestOptions),
1045
+ activate: (input, requestOptions) => request({
1046
+ method: "POST",
1047
+ path: `/api/credential/${encodeURIComponent(input.credentialID)}/activate`,
1048
+ successStatus: 204,
1049
+ declaredStatuses: [400, 401],
1050
+ empty: true
1051
+ }, requestOptions),
1052
+ remove: (input, requestOptions) => request({
1053
+ method: "DELETE",
1054
+ path: `/api/credential/${encodeURIComponent(input.credentialID)}`,
1055
+ successStatus: 204,
1056
+ declaredStatuses: [400, 401],
1057
+ empty: true
1058
+ }, requestOptions)
1059
+ },
1060
+ project: {
1061
+ list: (requestOptions) => request({ method: "GET", path: `/api/project`, successStatus: 200, declaredStatuses: [400, 401, 404], empty: false }, requestOptions),
1062
+ update: (input, requestOptions) => request({
1063
+ method: "PATCH",
1064
+ path: `/api/project/${encodeURIComponent(input.projectID)}`,
1065
+ body: {
1066
+ canonical: input["canonical"],
1067
+ name: input["name"],
1068
+ icon: input["icon"],
1069
+ commands: input["commands"]
1070
+ },
1071
+ successStatus: 200,
1072
+ declaredStatuses: [400, 401, 404],
1073
+ empty: false
1074
+ }, requestOptions)
1075
+ },
1076
+ form: {
1077
+ list: (input, requestOptions) => request({
1078
+ method: "GET",
1079
+ path: `/api/form`,
1080
+ query: { location: input?.["location"] },
1081
+ successStatus: 200,
1082
+ declaredStatuses: [400, 401, 404],
1083
+ empty: false
1084
+ }, requestOptions)
1085
+ },
1086
+ permission: {
1087
+ request: {
1088
+ list: (input, requestOptions) => request({
1089
+ method: "GET",
1090
+ path: `/api/permission/request`,
1091
+ query: { location: input?.["location"] },
1092
+ successStatus: 200,
1093
+ declaredStatuses: [400, 401, 404],
1094
+ empty: false
1095
+ }, requestOptions)
1096
+ },
1097
+ saved: {
1098
+ list: (input, requestOptions) => request({
1099
+ method: "GET",
1100
+ path: `/api/permission/saved`,
1101
+ query: { projectID: input?.["projectID"] },
1102
+ successStatus: 200,
1103
+ declaredStatuses: [400, 401, 404],
1104
+ empty: false
1105
+ }, requestOptions).then((value) => value.data),
1106
+ remove: (input, requestOptions) => request({
1107
+ method: "DELETE",
1108
+ path: `/api/permission/saved/${encodeURIComponent(input.id)}`,
1109
+ successStatus: 204,
1110
+ declaredStatuses: [400, 401, 404],
1111
+ empty: true
1112
+ }, requestOptions)
1113
+ },
1114
+ create: (input, requestOptions) => request({
1115
+ method: "POST",
1116
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission`,
1117
+ body: {
1118
+ id: input["id"],
1119
+ action: input["action"],
1120
+ resources: input["resources"],
1121
+ save: input["save"],
1122
+ metadata: input["metadata"],
1123
+ source: input["source"],
1124
+ agent: input["agent"]
1125
+ },
1126
+ successStatus: 200,
1127
+ declaredStatuses: [400, 401, 404],
1128
+ empty: false
1129
+ }, requestOptions).then((value) => value.data),
1130
+ list: (input, requestOptions) => request({
1131
+ method: "GET",
1132
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission`,
1133
+ successStatus: 200,
1134
+ declaredStatuses: [400, 401, 404],
1135
+ empty: false
1136
+ }, requestOptions).then((value) => value.data),
1137
+ get: (input, requestOptions) => request({
1138
+ method: "GET",
1139
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission/${encodeURIComponent(input.requestID)}`,
1140
+ successStatus: 200,
1141
+ declaredStatuses: [400, 401, 404],
1142
+ empty: false
1143
+ }, requestOptions).then((value) => value.data),
1144
+ reply: (input, requestOptions) => request({
1145
+ method: "POST",
1146
+ path: `/api/session/${encodeURIComponent(input.sessionID)}/permission/${encodeURIComponent(input.requestID)}/reply`,
1147
+ body: { decision: input["decision"], message: input["message"] },
1148
+ successStatus: 204,
1149
+ declaredStatuses: [400, 401, 404],
1150
+ empty: true
1151
+ }, requestOptions)
1152
+ },
1153
+ file: {
1154
+ read: (input, requestOptions) => request({
1155
+ method: "GET",
1156
+ path: `/api/fs/read/${encodePath(input.path)}`,
1157
+ query: { location: input["location"] },
1158
+ successStatus: 200,
1159
+ declaredStatuses: [400, 401, 404],
1160
+ empty: false,
1161
+ binary: true
1162
+ }, requestOptions),
1163
+ list: (input, requestOptions) => request({
1164
+ method: "GET",
1165
+ path: `/api/fs/list`,
1166
+ query: { location: input?.["location"], path: input?.["path"] },
1167
+ successStatus: 200,
1168
+ declaredStatuses: [400, 401, 404],
1169
+ empty: false
1170
+ }, requestOptions),
1171
+ find: (input, requestOptions) => request({
1172
+ method: "GET",
1173
+ path: `/api/fs/find`,
1174
+ query: { location: input["location"], query: input["query"], type: input["type"], limit: input["limit"] },
1175
+ successStatus: 200,
1176
+ declaredStatuses: [400, 401, 404],
1177
+ empty: false
1178
+ }, requestOptions),
1179
+ write: (input, requestOptions) => request({
1180
+ method: "POST",
1181
+ path: `/api/experimental/fs/write`,
1182
+ query: { location: input["location"], path: input["path"] },
1183
+ body: input["payload"],
1184
+ successStatus: 200,
1185
+ declaredStatuses: [400, 401, 404],
1186
+ empty: false,
1187
+ binaryBody: true
1188
+ }, requestOptions)
1189
+ },
1190
+ command: {
1191
+ list: (input, requestOptions) => request({
1192
+ method: "GET",
1193
+ path: `/api/command`,
1194
+ query: { location: input?.["location"] },
1195
+ successStatus: 200,
1196
+ declaredStatuses: [400, 401, 404],
1197
+ empty: false
1198
+ }, requestOptions)
1199
+ },
1200
+ skill: {
1201
+ list: (input, requestOptions) => request({
1202
+ method: "GET",
1203
+ path: `/api/skill`,
1204
+ query: { location: input?.["location"] },
1205
+ successStatus: 200,
1206
+ declaredStatuses: [400, 401, 404],
1207
+ empty: false
1208
+ }, requestOptions)
1209
+ },
1210
+ rpc: {
1211
+ call: (input, requestOptions) => request({
1212
+ method: "POST",
1213
+ path: `/api/rpc/${encodeURIComponent(input.rpcID)}/${encodeURIComponent(input.method)}`,
1214
+ query: { location: input["location"] },
1215
+ body: { input: input["input"] },
1216
+ successStatus: 200,
1217
+ declaredStatuses: [400, 401, 404, 500],
1218
+ empty: false
1219
+ }, requestOptions)
1220
+ },
1221
+ event: {
1222
+ subscribe: (requestOptions) => sse({ method: "GET", path: `/api/event`, successStatus: 200, declaredStatuses: [400, 401], empty: false }, requestOptions)
1223
+ },
1224
+ pty: {
1225
+ list: (input, requestOptions) => request({
1226
+ method: "GET",
1227
+ path: `/api/pty`,
1228
+ query: { location: input?.["location"] },
1229
+ successStatus: 200,
1230
+ declaredStatuses: [400, 401, 404],
1231
+ empty: false
1232
+ }, requestOptions),
1233
+ create: (input, requestOptions) => request({
1234
+ method: "POST",
1235
+ path: `/api/pty`,
1236
+ query: { location: input?.["location"] },
1237
+ body: {
1238
+ command: input?.["command"],
1239
+ args: input?.["args"],
1240
+ cwd: input?.["cwd"],
1241
+ title: input?.["title"],
1242
+ env: input?.["env"]
1243
+ },
1244
+ successStatus: 200,
1245
+ declaredStatuses: [400, 401, 404],
1246
+ empty: false
1247
+ }, requestOptions),
1248
+ get: (input, requestOptions) => request({
1249
+ method: "GET",
1250
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}`,
1251
+ query: { location: input["location"] },
1252
+ successStatus: 200,
1253
+ declaredStatuses: [400, 401, 404],
1254
+ empty: false
1255
+ }, requestOptions),
1256
+ update: (input, requestOptions) => request({
1257
+ method: "PUT",
1258
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}`,
1259
+ query: { location: input["location"] },
1260
+ body: { title: input["title"], size: input["size"] },
1261
+ successStatus: 200,
1262
+ declaredStatuses: [400, 401, 404],
1263
+ empty: false
1264
+ }, requestOptions),
1265
+ remove: (input, requestOptions) => request({
1266
+ method: "DELETE",
1267
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}`,
1268
+ query: { location: input["location"] },
1269
+ successStatus: 204,
1270
+ declaredStatuses: [400, 401, 404],
1271
+ empty: true
1272
+ }, requestOptions),
1273
+ connect: {
1274
+ token: (input, requestOptions) => request({
1275
+ method: "POST",
1276
+ path: `/api/pty/${encodeURIComponent(input.ptyID)}/connect-token`,
1277
+ query: { location: input["location"] },
1278
+ headers: { "x-opencode-ticket": input["x-opencode-ticket"] },
1279
+ successStatus: 200,
1280
+ declaredStatuses: [400, 401, 403, 404],
1281
+ empty: false
1282
+ }, requestOptions)
1283
+ }
1284
+ },
1285
+ experimental: {
1286
+ persistentPty: {
1287
+ read: (input, requestOptions) => request({
1288
+ method: "GET",
1289
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal/read`,
1290
+ query: { lines: input["lines"] },
1291
+ successStatus: 200,
1292
+ declaredStatuses: [400, 401, 503],
1293
+ empty: false
1294
+ }, requestOptions).then((value) => value.data),
1295
+ list: (input, requestOptions) => request({
1296
+ method: "GET",
1297
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`,
1298
+ successStatus: 200,
1299
+ declaredStatuses: [400, 401, 503],
1300
+ empty: false
1301
+ }, requestOptions).then((value) => value.data),
1302
+ create: (input, requestOptions) => request({
1303
+ method: "POST",
1304
+ path: `/api/experimental/session/${encodeURIComponent(input.sessionID)}/terminal`,
1305
+ body: {
1306
+ command: input["command"],
1307
+ args: input["args"],
1308
+ cwd: input["cwd"],
1309
+ title: input["title"],
1310
+ env: input["env"],
1311
+ size: input["size"]
1312
+ },
1313
+ successStatus: 200,
1314
+ declaredStatuses: [400, 401, 503],
1315
+ empty: false
1316
+ }, requestOptions).then((value) => value.data),
1317
+ shutdown: (requestOptions) => request({
1318
+ method: "POST",
1319
+ path: `/api/experimental/persistent-pty/shutdown`,
1320
+ successStatus: 204,
1321
+ declaredStatuses: [400, 401, 503],
1322
+ empty: true
1323
+ }, requestOptions),
1324
+ handoff: (requestOptions) => request({
1325
+ method: "POST",
1326
+ path: `/api/experimental/persistent-pty/handoff`,
1327
+ successStatus: 200,
1328
+ declaredStatuses: [400, 401, 503],
1329
+ empty: false
1330
+ }, requestOptions),
1331
+ get: (input, requestOptions) => request({
1332
+ method: "GET",
1333
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`,
1334
+ successStatus: 200,
1335
+ declaredStatuses: [400, 401, 404, 503],
1336
+ empty: false
1337
+ }, requestOptions).then((value) => value.data),
1338
+ update: (input, requestOptions) => request({
1339
+ method: "PUT",
1340
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`,
1341
+ body: { attachmentID: input["attachmentID"], size: input["size"] },
1342
+ successStatus: 200,
1343
+ declaredStatuses: [400, 401, 404, 503],
1344
+ empty: false
1345
+ }, requestOptions).then((value) => value.data),
1346
+ snapshot: (input, requestOptions) => request({
1347
+ method: "GET",
1348
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/snapshot`,
1349
+ successStatus: 200,
1350
+ declaredStatuses: [400, 401, 404, 503],
1351
+ empty: false
1352
+ }, requestOptions).then((value) => value.data),
1353
+ remove: (input, requestOptions) => request({
1354
+ method: "DELETE",
1355
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}`,
1356
+ successStatus: 204,
1357
+ declaredStatuses: [400, 401, 404, 503],
1358
+ empty: true
1359
+ }, requestOptions),
1360
+ connectToken: (input, requestOptions) => request({
1361
+ method: "POST",
1362
+ path: `/api/experimental/persistent-pty/${encodeURIComponent(input.ptyID)}/connect-token`,
1363
+ headers: { "x-opencode-ticket": input["x-opencode-ticket"] },
1364
+ successStatus: 200,
1365
+ declaredStatuses: [400, 401, 403, 404, 503],
1366
+ empty: false
1367
+ }, requestOptions).then((value) => value.data)
1368
+ }
1369
+ },
1370
+ shell: {
1371
+ list: (input, requestOptions) => request({
1372
+ method: "GET",
1373
+ path: `/api/shell`,
1374
+ query: { location: input?.["location"] },
1375
+ successStatus: 200,
1376
+ declaredStatuses: [400, 401, 404],
1377
+ empty: false
1378
+ }, requestOptions),
1379
+ create: (input, requestOptions) => request({
1380
+ method: "POST",
1381
+ path: `/api/shell`,
1382
+ query: { location: input["location"] },
1383
+ body: {
1384
+ command: input["command"],
1385
+ cwd: input["cwd"],
1386
+ timeout: input["timeout"],
1387
+ metadata: input["metadata"]
1388
+ },
1389
+ successStatus: 200,
1390
+ declaredStatuses: [400, 401, 404],
1391
+ empty: false
1392
+ }, requestOptions),
1393
+ get: (input, requestOptions) => request({
1394
+ method: "GET",
1395
+ path: `/api/shell/${encodeURIComponent(input.id)}`,
1396
+ query: { location: input["location"] },
1397
+ successStatus: 200,
1398
+ declaredStatuses: [400, 401, 404],
1399
+ empty: false
1400
+ }, requestOptions),
1401
+ output: (input, requestOptions) => request({
1402
+ method: "GET",
1403
+ path: `/api/shell/${encodeURIComponent(input.id)}/output`,
1404
+ query: { location: input["location"], cursor: input["cursor"], limit: input["limit"] },
1405
+ successStatus: 200,
1406
+ declaredStatuses: [400, 401, 404],
1407
+ empty: false
1408
+ }, requestOptions),
1409
+ remove: (input, requestOptions) => request({
1410
+ method: "DELETE",
1411
+ path: `/api/shell/${encodeURIComponent(input.id)}`,
1412
+ query: { location: input["location"] },
1413
+ successStatus: 204,
1414
+ declaredStatuses: [400, 401, 404],
1415
+ empty: true
1416
+ }, requestOptions)
1417
+ },
1418
+ reference: {
1419
+ list: (input, requestOptions) => request({
1420
+ method: "GET",
1421
+ path: `/api/reference`,
1422
+ query: { location: input?.["location"] },
1423
+ successStatus: 200,
1424
+ declaredStatuses: [400, 401, 404],
1425
+ empty: false
1426
+ }, requestOptions)
1427
+ },
1428
+ worktree: {
1429
+ list: (input, requestOptions) => request({
1430
+ method: "GET",
1431
+ path: `/api/worktree`,
1432
+ query: { projectID: input["projectID"] },
1433
+ successStatus: 200,
1434
+ declaredStatuses: [400, 401, 404],
1435
+ empty: false
1436
+ }, requestOptions),
1437
+ create: (input, requestOptions) => request({
1438
+ method: "POST",
1439
+ path: `/api/worktree`,
1440
+ body: {
1441
+ projectID: input["projectID"],
1442
+ from: input["from"],
1443
+ branch: input["branch"],
1444
+ directory: input["directory"],
1445
+ name: input["name"]
1446
+ },
1447
+ successStatus: 200,
1448
+ declaredStatuses: [400, 401, 404],
1449
+ empty: false
1450
+ }, requestOptions),
1451
+ remove: (input, requestOptions) => request({
1452
+ method: "DELETE",
1453
+ path: `/api/worktree`,
1454
+ body: { projectID: input["projectID"], directory: input["directory"], force: input["force"] },
1455
+ successStatus: 204,
1456
+ declaredStatuses: [400, 401, 404],
1457
+ empty: true
1458
+ }, requestOptions),
1459
+ refresh: (input, requestOptions) => request({
1460
+ method: "POST",
1461
+ path: `/api/worktree/refresh`,
1462
+ body: { projectID: input["projectID"] },
1463
+ successStatus: 204,
1464
+ declaredStatuses: [400, 401, 404],
1465
+ empty: true
1466
+ }, requestOptions)
1467
+ },
1468
+ vcs: {
1469
+ init: (input, requestOptions) => request({
1470
+ method: "POST",
1471
+ path: `/api/vcs/init`,
1472
+ query: { location: input?.["location"], provider: input?.["provider"] },
1473
+ successStatus: 204,
1474
+ declaredStatuses: [400, 401, 404, 409, 501, 503],
1475
+ empty: true
1476
+ }, requestOptions),
1477
+ get: (input, requestOptions) => request({
1478
+ method: "GET",
1479
+ path: `/api/vcs`,
1480
+ query: { location: input?.["location"] },
1481
+ successStatus: 200,
1482
+ declaredStatuses: [400, 401, 404],
1483
+ empty: false
1484
+ }, requestOptions),
1485
+ base: (input, requestOptions) => request({
1486
+ method: "GET",
1487
+ path: `/api/vcs/base`,
1488
+ query: { location: input?.["location"] },
1489
+ successStatus: 200,
1490
+ declaredStatuses: [400, 401, 404, 503],
1491
+ empty: false
1492
+ }, requestOptions),
1493
+ status: (input, requestOptions) => request({
1494
+ method: "GET",
1495
+ path: `/api/vcs/status`,
1496
+ query: { location: input?.["location"] },
1497
+ successStatus: 200,
1498
+ declaredStatuses: [400, 401, 404],
1499
+ empty: false
1500
+ }, requestOptions),
1501
+ branch: {
1502
+ list: (input, requestOptions) => request({
1503
+ method: "GET",
1504
+ path: `/api/vcs/branch`,
1505
+ query: { location: input?.["location"], search: input?.["search"], limit: input?.["limit"] },
1506
+ successStatus: 200,
1507
+ declaredStatuses: [400, 401, 404],
1508
+ empty: false
1509
+ }, requestOptions)
1510
+ },
1511
+ diff: (input, requestOptions) => request({
1512
+ method: "GET",
1513
+ path: `/api/vcs/diff`,
1514
+ query: { location: input["location"], mode: input["mode"], base: input["base"], context: input["context"] },
1515
+ successStatus: 200,
1516
+ declaredStatuses: [400, 401, 404, 503],
1517
+ empty: false
1518
+ }, requestOptions)
1519
+ },
1520
+ debug: {
1521
+ location: {
1522
+ list: (requestOptions) => request({
1523
+ method: "GET",
1524
+ path: `/api/debug/location`,
1525
+ successStatus: 200,
1526
+ declaredStatuses: [400, 401],
1527
+ empty: false
1528
+ }, requestOptions),
1529
+ evict: (input, requestOptions) => request({
1530
+ method: "DELETE",
1531
+ path: `/api/debug/location`,
1532
+ query: { location: input?.["location"] },
1533
+ successStatus: 204,
1534
+ declaredStatuses: [400, 401],
1535
+ empty: true
1536
+ }, requestOptions)
1537
+ }
1538
+ },
1539
+ migration: {
1540
+ v1: {
1541
+ status: (requestOptions) => request({
1542
+ method: "GET",
1543
+ path: `/api/experimental/migration/v1`,
1544
+ successStatus: 200,
1545
+ declaredStatuses: [400, 401],
1546
+ empty: false
1547
+ }, requestOptions)
1548
+ }
1549
+ },
1550
+ websearch: {
1551
+ providers: (input, requestOptions) => request({
1552
+ method: "GET",
1553
+ path: `/api/websearch/provider`,
1554
+ query: { location: input?.["location"] },
1555
+ successStatus: 200,
1556
+ declaredStatuses: [400, 401, 404, 503],
1557
+ empty: false
1558
+ }, requestOptions),
1559
+ query: (input, requestOptions) => request({
1560
+ method: "POST",
1561
+ path: `/api/websearch`,
1562
+ query: { location: input["location"] },
1563
+ body: { query: input["query"], providerID: input["providerID"] },
1564
+ successStatus: 200,
1565
+ declaredStatuses: [400, 401, 404, 503],
1566
+ empty: false
1567
+ }, requestOptions)
1568
+ },
1569
+ config: {
1570
+ get: (input, requestOptions) => request({
1571
+ method: "GET",
1572
+ path: `/api/config`,
1573
+ query: { location: input?.["location"] },
1574
+ successStatus: 200,
1575
+ declaredStatuses: [400, 401, 404],
1576
+ empty: false
1577
+ }, requestOptions),
1578
+ shells: (requestOptions) => request({
1579
+ method: "GET",
1580
+ path: `/api/config/shell`,
1581
+ successStatus: 200,
1582
+ declaredStatuses: [400, 401, 404],
1583
+ empty: false
1584
+ }, requestOptions),
1585
+ update: (input, requestOptions) => request({
1586
+ method: "PATCH",
1587
+ path: `/api/experimental/config`,
1588
+ body: { shell: input["shell"] },
1589
+ successStatus: 204,
1590
+ declaredStatuses: [400, 401, 404],
1591
+ empty: true
1592
+ }, requestOptions)
1593
+ }
1594
+ };
1595
+ }
1596
+ function encodePath(value) {
1597
+ return value.split("/").map(encodeURIComponent).join("/");
1598
+ }
1599
+ function appendQuery(params, key, value) {
1600
+ if (value === void 0)
1601
+ return;
1602
+ if (value === null) {
1603
+ params.append(key, "null");
1604
+ return;
1605
+ }
1606
+ if (Array.isArray(value)) {
1607
+ for (const item of value)
1608
+ appendQuery(params, key, item);
1609
+ return;
1610
+ }
1611
+ if (typeof value === "object") {
1612
+ for (const [child, item] of Object.entries(value))
1613
+ appendQuery(params, `${key}[${child}]`, item);
1614
+ return;
1615
+ }
1616
+ params.append(key, String(value));
1617
+ }
1618
+ async function json(response) {
1619
+ if (!isContentType(response, "application/json") && !response.headers.get("content-type")?.includes("+json")) {
1620
+ try {
1621
+ await response.body?.cancel();
1622
+ } catch {
1623
+ }
1624
+ throw new ClientError2("UnsupportedContentType", { detail: response.headers.get("content-type") });
1625
+ }
1626
+ let text;
1627
+ try {
1628
+ text = await response.text();
1629
+ } catch (cause) {
1630
+ throw new ClientError2("Transport", { cause });
1631
+ }
1632
+ if (text === "")
1633
+ throw new ClientError2("MalformedResponse");
1634
+ try {
1635
+ return JSON.parse(text);
1636
+ } catch (cause) {
1637
+ throw new ClientError2("MalformedResponse", { cause });
1638
+ }
1639
+ }
1640
+ function declared(body) {
1641
+ const error = Object.assign(new Error(body.message ?? body.data?.message), body);
1642
+ if (body._tag)
1643
+ error.name = body._tag;
1644
+ return error;
1645
+ }
1646
+ function isContentType(response, expected) {
1647
+ return response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === expected;
1648
+ }
1649
+ var exports_client2, maxSseEventBytes;
1650
+ var init_service_timing_tbh3h57v = __esm({
1651
+ "node_modules/@opencode/client/dist/chunks/service-timing-tbh3h57v.js"() {
1652
+ init_service_timing_js54wxgp();
1653
+ init_service_timing_9rqn6x4v();
1654
+ exports_client2 = {};
1655
+ __export2(exports_client2, {
1656
+ make: () => make3
1657
+ });
1658
+ maxSseEventBytes = 16 * 1024 * 1024;
1659
+ }
1660
+ });
1661
+
1662
+ // node_modules/@opencode/client/dist/chunks/service-timing-vt9jbch8.js
1663
+ var isInvalidRequestError2, isUnauthorizedError2, isLocationNotFoundError2, isServiceUnavailableError2, isAgentNotFoundError2, isInvalidCursorError2, isSessionNotFoundError2, isConflictError2, isUnknownError2, isMessageNotFoundError2, isCommandNotFoundError2, isCommandExecutionError2, isSkillNotFoundError2, isSessionBusyError2, isInstructionEntryValueTooLargeError2, isFormNotFoundError2, isFormInvalidAnswerError2, isFormAlreadySettledError2, isProviderNotFoundError2, isIntegrationNotFoundError2, isIntegrationAttemptNotFoundError2, isIntegrationMethodNotFoundError2, isMcpServerNotFoundError2, isProjectNotFoundError2, isPermissionNotFoundError2, isFileNotFoundError2, isRpcError2, isRpcInternalError2, isPtyNotFoundError2, isForbiddenError2, isShellNotFoundError2, isWorktreeError2, isVcsInitNotSupportedError2;
1664
+ var init_service_timing_vt9jbch8 = __esm({
1665
+ "node_modules/@opencode/client/dist/chunks/service-timing-vt9jbch8.js"() {
1666
+ isInvalidRequestError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "InvalidRequestError";
1667
+ isUnauthorizedError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnauthorizedError";
1668
+ isLocationNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "LocationNotFoundError";
1669
+ isServiceUnavailableError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ServiceUnavailableError";
1670
+ isAgentNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "AgentNotFoundError";
1671
+ isInvalidCursorError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "InvalidCursorError";
1672
+ isSessionNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SessionNotFoundError";
1673
+ isConflictError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ConflictError";
1674
+ isUnknownError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "UnknownError";
1675
+ isMessageNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "MessageNotFoundError";
1676
+ isCommandNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandNotFoundError";
1677
+ isCommandExecutionError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "CommandExecutionError";
1678
+ isSkillNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SkillNotFoundError";
1679
+ isSessionBusyError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "SessionBusyError";
1680
+ isInstructionEntryValueTooLargeError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "InstructionEntryValueTooLargeError";
1681
+ isFormNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormNotFoundError";
1682
+ isFormInvalidAnswerError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormInvalidAnswerError";
1683
+ isFormAlreadySettledError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FormAlreadySettledError";
1684
+ isProviderNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ProviderNotFoundError";
1685
+ isIntegrationNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "IntegrationNotFoundError";
1686
+ isIntegrationAttemptNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "IntegrationAttemptNotFoundError";
1687
+ isIntegrationMethodNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "IntegrationMethodNotFoundError";
1688
+ isMcpServerNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "McpServerNotFoundError";
1689
+ isProjectNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ProjectNotFoundError";
1690
+ isPermissionNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "PermissionNotFoundError";
1691
+ isFileNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "FileNotFoundError";
1692
+ isRpcError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "RpcError";
1693
+ isRpcInternalError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "RpcInternalError";
1694
+ isPtyNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "PtyNotFoundError";
1695
+ isForbiddenError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ForbiddenError";
1696
+ isShellNotFoundError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "ShellNotFoundError";
1697
+ isWorktreeError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "WorktreeError";
1698
+ isVcsInitNotSupportedError2 = (value) => typeof value === "object" && value !== null && "_tag" in value && value["_tag"] === "VcsInitNotSupportedError";
1699
+ }
1700
+ });
1701
+
1702
+ // node_modules/@opencode/client/dist/chunks/service-timing-1y4a697q.js
1703
+ function makeRpc2(raw, events) {
1704
+ return (definition) => {
1705
+ const subscribe = (name, options) => {
1706
+ if (!Object.hasOwn(definition.events, name))
1707
+ throw new Error(`Unknown RPC event: ${definition.id}.${name}`);
1708
+ const type = eventType(definition, name);
1709
+ return {
1710
+ [Symbol.asyncIterator]() {
1711
+ const controller = new AbortController();
1712
+ const signal2 = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
1713
+ const iterator = (async function* () {
1714
+ try {
1715
+ for await (const published of events.subscribe({ signal: signal2 })) {
1716
+ if (signal2.aborted)
1717
+ return;
1718
+ if (published.type !== type)
1719
+ continue;
1720
+ yield published;
1721
+ }
1722
+ } catch (error) {
1723
+ if (!signal2.aborted)
1724
+ throw error;
1725
+ } finally {
1726
+ controller.abort();
1727
+ }
1728
+ })();
1729
+ return {
1730
+ next: () => iterator.next(),
1731
+ return: () => {
1732
+ controller.abort();
1733
+ return iterator.return();
1734
+ }
1735
+ };
1736
+ }
1737
+ };
1738
+ };
1739
+ return Object.assign(Object.fromEntries(Object.keys(definition.methods).map((name) => [
1740
+ name,
1741
+ async (input, options) => {
1742
+ try {
1743
+ const result = await raw.rpc.call({
1744
+ rpcID: definition.id,
1745
+ method: name,
1746
+ input,
1747
+ location: options?.location
1748
+ }, { signal: options?.signal, headers: options?.headers });
1749
+ return result.output;
1750
+ } catch (error) {
1751
+ if (!isRpcError2(error) && !isRpcInternalError2(error))
1752
+ throw error;
1753
+ throw error.data === void 0 ? { type: error.type, message: error.message } : { type: error.type, message: error.message, data: error.data };
1754
+ }
1755
+ }
1756
+ ])), {
1757
+ events: {
1758
+ subscribe,
1759
+ on: (name, handler, options) => {
1760
+ const controller = new AbortController();
1761
+ const signal2 = options?.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
1762
+ const source = subscribe(name, { signal: signal2 });
1763
+ (async () => {
1764
+ for await (const event of source)
1765
+ await handler(event);
1766
+ })().catch((error) => console.error(error));
1767
+ return () => controller.abort();
1768
+ }
1769
+ }
1770
+ });
1771
+ };
1772
+ }
1773
+ function eventType(definition, name) {
1774
+ return `rpc.${definition.id}.${name}`;
1775
+ }
1776
+ var init_service_timing_1y4a697q = __esm({
1777
+ "node_modules/@opencode/client/dist/chunks/service-timing-1y4a697q.js"() {
1778
+ init_service_timing_vt9jbch8();
1779
+ }
1780
+ });
1781
+
1782
+ // node_modules/@opencode/client/dist/chunks/service-timing-e4sc9kq6.js
1783
+ function make2(options) {
1784
+ const raw = make3(options);
1785
+ const events = make7((signal2, onActivity) => raw.event.subscribe({ signal: signal2, onActivity }));
1786
+ return {
1787
+ ...raw,
1788
+ rpc: Object.assign(makeRpc2(raw, events), raw.rpc),
1789
+ event: events
1790
+ };
1791
+ }
1792
+ var exports_client;
1793
+ var init_service_timing_e4sc9kq6 = __esm({
1794
+ "node_modules/@opencode/client/dist/chunks/service-timing-e4sc9kq6.js"() {
1795
+ init_service_timing_frbwqjmf();
1796
+ init_service_timing_tbh3h57v();
1797
+ init_service_timing_1y4a697q();
1798
+ init_service_timing_9rqn6x4v();
1799
+ exports_client = {};
1800
+ __export2(exports_client, {
1801
+ OpenCode: () => exports_client,
1802
+ make: () => make2
1803
+ });
1804
+ }
1805
+ });
1806
+
1807
+ // node_modules/@opencode/client/dist/promise/index.js
1808
+ var promise_exports = {};
1809
+ __export(promise_exports, {
1810
+ ClientError: () => ClientError2,
1811
+ OpenCode: () => exports_client,
1812
+ isAgentNotFoundError: () => isAgentNotFoundError2,
1813
+ isCommandExecutionError: () => isCommandExecutionError2,
1814
+ isCommandNotFoundError: () => isCommandNotFoundError2,
1815
+ isConflictError: () => isConflictError2,
1816
+ isFileNotFoundError: () => isFileNotFoundError2,
1817
+ isForbiddenError: () => isForbiddenError2,
1818
+ isFormAlreadySettledError: () => isFormAlreadySettledError2,
1819
+ isFormInvalidAnswerError: () => isFormInvalidAnswerError2,
1820
+ isFormNotFoundError: () => isFormNotFoundError2,
1821
+ isInstructionEntryValueTooLargeError: () => isInstructionEntryValueTooLargeError2,
1822
+ isIntegrationAttemptNotFoundError: () => isIntegrationAttemptNotFoundError2,
1823
+ isIntegrationMethodNotFoundError: () => isIntegrationMethodNotFoundError2,
1824
+ isIntegrationNotFoundError: () => isIntegrationNotFoundError2,
1825
+ isInvalidCursorError: () => isInvalidCursorError2,
1826
+ isInvalidRequestError: () => isInvalidRequestError2,
1827
+ isLocationNotFoundError: () => isLocationNotFoundError2,
1828
+ isMcpServerNotFoundError: () => isMcpServerNotFoundError2,
1829
+ isMessageNotFoundError: () => isMessageNotFoundError2,
1830
+ isPermissionNotFoundError: () => isPermissionNotFoundError2,
1831
+ isProjectNotFoundError: () => isProjectNotFoundError2,
1832
+ isProviderNotFoundError: () => isProviderNotFoundError2,
1833
+ isPtyNotFoundError: () => isPtyNotFoundError2,
1834
+ isRpcError: () => isRpcError2,
1835
+ isRpcInternalError: () => isRpcInternalError2,
1836
+ isServiceUnavailableError: () => isServiceUnavailableError2,
1837
+ isSessionBusyError: () => isSessionBusyError2,
1838
+ isSessionNotFoundError: () => isSessionNotFoundError2,
1839
+ isShellNotFoundError: () => isShellNotFoundError2,
1840
+ isSkillNotFoundError: () => isSkillNotFoundError2,
1841
+ isUnauthorizedError: () => isUnauthorizedError2,
1842
+ isUnknownError: () => isUnknownError2,
1843
+ isVcsInitNotSupportedError: () => isVcsInitNotSupportedError2,
1844
+ isWorktreeError: () => isWorktreeError2
1845
+ });
1846
+ var init_promise = __esm({
1847
+ "node_modules/@opencode/client/dist/promise/index.js"() {
1848
+ init_service_timing_e4sc9kq6();
1849
+ init_service_timing_tbh3h57v();
1850
+ init_service_timing_js54wxgp();
1851
+ init_service_timing_1y4a697q();
1852
+ init_service_timing_vt9jbch8();
1853
+ init_service_timing_frbwqjmf();
1854
+ }
1855
+ });
1856
+
1
1857
  // src/config.js
2
1858
  import { readFileSync } from "node:fs";
3
1859
  import { homedir } from "node:os";
@@ -238,19 +2094,19 @@ function isRetryable(status) {
238
2094
  function isAbortError(error) {
239
2095
  return error instanceof Error && error.name === "AbortError";
240
2096
  }
241
- function sleep(milliseconds, signal) {
2097
+ function sleep(milliseconds, signal2) {
242
2098
  return new Promise((resolve2) => {
243
- if (signal?.aborted) {
2099
+ if (signal2?.aborted) {
244
2100
  resolve2();
245
2101
  return;
246
2102
  }
247
2103
  const timeout = setTimeout(done, milliseconds);
248
2104
  function done() {
249
2105
  clearTimeout(timeout);
250
- signal?.removeEventListener("abort", done);
2106
+ signal2?.removeEventListener("abort", done);
251
2107
  resolve2();
252
2108
  }
253
- signal?.addEventListener("abort", done, { once: true });
2109
+ signal2?.addEventListener("abort", done, { once: true });
254
2110
  });
255
2111
  }
256
2112
  async function postJsonWithRetry(config, url, body, options = {}) {
@@ -493,7 +2349,7 @@ import { randomUUID } from "node:crypto";
493
2349
  import { statSync } from "node:fs";
494
2350
 
495
2351
  // src/updates.js
496
- var PLUGIN_VERSION = "0.2.5";
2352
+ var PLUGIN_VERSION = "0.4.0";
497
2353
  var PACKAGE_NAME = "backeer-opencode";
498
2354
  var NPM_REGISTRY_URL = "https://registry.npmjs.org";
499
2355
  var CHECK_TIMEOUT_MS = 3e3;
@@ -524,7 +2380,8 @@ function isVersionNewer(latestValue, currentValue) {
524
2380
  }
525
2381
  function createUpdateChecker({
526
2382
  fetchImplementation = globalThis.fetch,
527
- now = () => Date.now()
2383
+ now = () => Date.now(),
2384
+ v2 = false
528
2385
  } = {}) {
529
2386
  let checkedAt = 0;
530
2387
  let cachedResult;
@@ -554,7 +2411,7 @@ function createUpdateChecker({
554
2411
  state: "available",
555
2412
  currentVersion: PLUGIN_VERSION,
556
2413
  latestVersion,
557
- updateCommand: `opencode plugin ${PACKAGE_NAME}@${latestVersion} -g --force`
2414
+ updateCommand: v2 ? `opencode plugin add ${PACKAGE_NAME}@${latestVersion}` : `opencode plugin ${PACKAGE_NAME}@${latestVersion} -g --force`
558
2415
  };
559
2416
  } catch {
560
2417
  return { state: "unavailable", currentVersion: PLUGIN_VERSION };
@@ -1651,13 +3508,13 @@ function nextSseFrame(buffer) {
1651
3508
  }
1652
3509
  return { frame: buffer.slice(0, lfIndex), rest: buffer.slice(lfIndex + 2) };
1653
3510
  }
1654
- async function consumeSse(response, state, onCommand, signal, reporter) {
3511
+ async function consumeSse(response, state, onCommand, signal2, reporter) {
1655
3512
  if (!response.body) throw new Error("Backeer command stream has no body");
1656
3513
  const reader = response.body.getReader();
1657
3514
  const decoder = new TextDecoder();
1658
3515
  let buffer = "";
1659
3516
  try {
1660
- while (!signal.aborted) {
3517
+ while (!signal2.aborted) {
1661
3518
  const item = await reader.read();
1662
3519
  if (item.done) break;
1663
3520
  buffer += decoder.decode(item.value, { stream: true });
@@ -1686,7 +3543,7 @@ async function consumeSse(response, state, onCommand, signal, reporter) {
1686
3543
  });
1687
3544
  }
1688
3545
  }
1689
- async function openCommandStream(config, state, signal, fetchImplementation) {
3546
+ async function openCommandStream(config, state, signal2, fetchImplementation) {
1690
3547
  const headers = {
1691
3548
  Accept: "text/event-stream",
1692
3549
  Authorization: `Bearer ${config.token}`
@@ -1694,7 +3551,7 @@ async function openCommandStream(config, state, signal, fetchImplementation) {
1694
3551
  if (state.lastEventID) headers["Last-Event-ID"] = state.lastEventID;
1695
3552
  const response = await fetchImplementation(config.commandStreamEndpoint, {
1696
3553
  headers,
1697
- signal
3554
+ signal: signal2
1698
3555
  });
1699
3556
  if (!response.ok) {
1700
3557
  const responseBody = limit(await response.text(), 500);
@@ -1713,7 +3570,7 @@ async function consumeConnection({
1713
3570
  response,
1714
3571
  state,
1715
3572
  onCommand,
1716
- signal,
3573
+ signal: signal2,
1717
3574
  reporter,
1718
3575
  now,
1719
3576
  stableConnectionMs,
@@ -1722,7 +3579,7 @@ async function consumeConnection({
1722
3579
  const connectedAt = now();
1723
3580
  const framesBeforeConnection = state.framesReceived;
1724
3581
  try {
1725
- await consumeSse(response, state, onCommand, signal, reporter);
3582
+ await consumeSse(response, state, onCommand, signal2, reporter);
1726
3583
  } finally {
1727
3584
  const receivedFrame = state.framesReceived > framesBeforeConnection;
1728
3585
  if (receivedFrame || now() - connectedAt >= stableConnectionMs) onStable();
@@ -1743,7 +3600,7 @@ function streamErrorState(error, lastLoggedError, reconnectDelay, reporter) {
1743
3600
  };
1744
3601
  }
1745
3602
  async function runCommandStream(config, reporter, {
1746
- signal,
3603
+ signal: signal2,
1747
3604
  hasPending,
1748
3605
  onCommand,
1749
3606
  fetchImplementation = fetch,
@@ -1754,19 +3611,19 @@ async function runCommandStream(config, reporter, {
1754
3611
  const state = { lastEventID: "", framesReceived: 0 };
1755
3612
  let reconnectDelay = 1e3;
1756
3613
  let lastLoggedError = "";
1757
- while (!signal.aborted && hasPending()) {
3614
+ while (!signal2.aborted && hasPending()) {
1758
3615
  try {
1759
3616
  const response = await openCommandStream(
1760
3617
  config,
1761
3618
  state,
1762
- signal,
3619
+ signal2,
1763
3620
  fetchImplementation
1764
3621
  );
1765
3622
  await consumeConnection({
1766
3623
  response,
1767
3624
  state,
1768
3625
  onCommand,
1769
- signal,
3626
+ signal: signal2,
1770
3627
  reporter,
1771
3628
  now,
1772
3629
  stableConnectionMs,
@@ -1776,13 +3633,13 @@ async function runCommandStream(config, reporter, {
1776
3633
  }
1777
3634
  });
1778
3635
  } catch (error) {
1779
- if (signal.aborted || isAbortError(error)) return;
3636
+ if (signal2.aborted || isAbortError(error)) return;
1780
3637
  const next = streamErrorState(error, lastLoggedError, reconnectDelay, reporter);
1781
3638
  reconnectDelay = next.reconnectDelay;
1782
3639
  lastLoggedError = next.lastLoggedError;
1783
3640
  }
1784
- if (!signal.aborted && hasPending()) {
1785
- await sleepImplementation(reconnectDelay, signal);
3641
+ if (!signal2.aborted && hasPending()) {
3642
+ await sleepImplementation(reconnectDelay, signal2);
1786
3643
  reconnectDelay = Math.min(reconnectDelay * 2, 6e4);
1787
3644
  }
1788
3645
  }
@@ -2070,7 +3927,7 @@ function createPermissionController({
2070
3927
  }
2071
3928
 
2072
3929
  // src/plugin.js
2073
- async function BackeerPlugin({ client, directory }, options = {}) {
3930
+ async function BackeerPlugin({ client, directory, feedback, v2 = false }, options = {}) {
2074
3931
  const bootstrapReporter = createOpenCodeReporter(
2075
3932
  client,
2076
3933
  options.logLevel ?? process.env.BACKEER_LOG_LEVEL
@@ -2083,7 +3940,7 @@ async function BackeerPlugin({ client, directory }, options = {}) {
2083
3940
  return {};
2084
3941
  }
2085
3942
  const reporter = createOpenCodeReporter(client, config.logLevel);
2086
- const conversation = createConversationFeedback({ client, reporter });
3943
+ const conversation = feedback ?? createConversationFeedback({ client, reporter });
2087
3944
  const permissionController = createPermissionController({
2088
3945
  config,
2089
3946
  reporter,
@@ -2101,7 +3958,7 @@ async function BackeerPlugin({ client, directory }, options = {}) {
2101
3958
  const permissionPublications = createDeliveryTracker();
2102
3959
  const questionPublications = createDeliveryTracker();
2103
3960
  const todoCompletions = createCompletionTracker();
2104
- const updateChecker = createUpdateChecker();
3961
+ const updateChecker = createUpdateChecker({ v2 });
2105
3962
  const handleBackeerCommand = createBackeerCommandHandler({
2106
3963
  client,
2107
3964
  config,
@@ -2239,6 +4096,746 @@ async function BackeerPlugin({ client, directory }, options = {}) {
2239
4096
  }
2240
4097
  };
2241
4098
  }
4099
+
4100
+ // src/opencode-v2-forms.js
4101
+ init_promise();
4102
+
4103
+ // node_modules/@opencode/client/dist/chunks/service-timing-ve4aws36.js
4104
+ import { spawn } from "node:child_process";
4105
+ var stderrLimit = 8 * 1024;
4106
+ function spawnServiceContender2(command, args, env) {
4107
+ const child = spawn(command, args, {
4108
+ detached: true,
4109
+ windowsHide: true,
4110
+ stdio: ["ignore", "ignore", "pipe"],
4111
+ env: { ...process.env, ...env }
4112
+ });
4113
+ let error;
4114
+ let closed = false;
4115
+ let stderr = Buffer.alloc(0);
4116
+ const onStderr = (chunk) => {
4117
+ const tail = chunk.subarray(-stderrLimit);
4118
+ stderr = tail.length === stderrLimit ? Buffer.from(tail) : Buffer.concat([stderr.subarray(-(stderrLimit - tail.length)), tail]);
4119
+ };
4120
+ child.stderr?.on("data", onStderr);
4121
+ if (child.stderr !== null && "unref" in child.stderr && typeof child.stderr.unref === "function")
4122
+ child.stderr.unref();
4123
+ child.once("error", (cause) => {
4124
+ error = new Error("Failed to start server", { cause });
4125
+ });
4126
+ child.once("close", () => {
4127
+ closed = true;
4128
+ });
4129
+ child.unref();
4130
+ return {
4131
+ child,
4132
+ error: () => error,
4133
+ closed: () => closed,
4134
+ stderr: () => stderr.toString("utf8").trim(),
4135
+ release: () => {
4136
+ child.stderr?.off("data", onStderr);
4137
+ child.stderr?.resume();
4138
+ stderr = Buffer.alloc(0);
4139
+ }
4140
+ };
4141
+ }
4142
+ function contenderPool2(timing) {
4143
+ const contenders = /* @__PURE__ */ new Set();
4144
+ let failure;
4145
+ let spawnDelay = timing.spawnDelay;
4146
+ let lastSpawn = 0;
4147
+ return {
4148
+ failure: () => failure,
4149
+ serviceAnswered() {
4150
+ spawnDelay = timing.spawnDelay;
4151
+ },
4152
+ evict(pid) {
4153
+ for (const item of contenders) {
4154
+ if (item.child.pid === pid || contenderFinished2(item)) {
4155
+ item.release();
4156
+ contenders.delete(item);
4157
+ }
4158
+ }
4159
+ failure = void 0;
4160
+ lastSpawn = 0;
4161
+ },
4162
+ recruitNow() {
4163
+ lastSpawn = Date.now() - spawnDelay;
4164
+ },
4165
+ reap() {
4166
+ const finished = [...contenders].filter(contenderFinished2);
4167
+ failure ??= finished.map(contenderFailure).find((error) => error !== void 0);
4168
+ if (finished.some((item) => item.child.exitCode === 0))
4169
+ spawnDelay = Math.min(spawnDelay * 2, timing.maxSpawnDelay);
4170
+ finished.forEach((item) => contenders.delete(item));
4171
+ return contenders.size === 0 ? failure : void 0;
4172
+ },
4173
+ shouldRecruit(registered2) {
4174
+ if (lastSpawn === 0 && registered2)
4175
+ lastSpawn = Date.now();
4176
+ return failure === void 0 && contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay;
4177
+ },
4178
+ add(contender) {
4179
+ contenders.add(contender);
4180
+ lastSpawn = Date.now();
4181
+ },
4182
+ releaseAll() {
4183
+ contenders.forEach((contender) => contender.release());
4184
+ }
4185
+ };
4186
+ }
4187
+ function contenderFailure(contender) {
4188
+ const error = contender.error();
4189
+ if (error !== void 0)
4190
+ return error;
4191
+ if (contender.child.exitCode !== null && contender.child.exitCode !== 0)
4192
+ return startupError(`Server process exited with code ${contender.child.exitCode}`, contender.stderr());
4193
+ if (contender.child.signalCode !== null)
4194
+ return startupError(`Server process terminated by ${contender.child.signalCode}`, contender.stderr());
4195
+ return;
4196
+ }
4197
+ function contenderFinished2(contender) {
4198
+ return contender.error() !== void 0 || contender.closed();
4199
+ }
4200
+ function startupError(message, stderr) {
4201
+ return new Error(stderr ? `${message}
4202
+ ${stderr}` : message);
4203
+ }
4204
+
4205
+ // node_modules/@opencode/client/dist/chunks/service-timing-xgnj2w4v.js
4206
+ var timings = /* @__PURE__ */ new WeakMap();
4207
+ var defaultEnsureTiming2 = {
4208
+ pollInterval: 25,
4209
+ requestTimeout: 2e3,
4210
+ spawnDelay: 5e3,
4211
+ maxSpawnDelay: 3e4,
4212
+ promiseTimeout: 12e4,
4213
+ stopPollInterval: 50,
4214
+ stopPollAttempts: 100
4215
+ };
4216
+ function ensureTiming2(options) {
4217
+ return timings.get(options) ?? defaultEnsureTiming2;
4218
+ }
4219
+
4220
+ // node_modules/@opencode/client/dist/chunks/service-timing-sxt88q69.js
4221
+ function matchesVersion2(version, options) {
4222
+ if (options.version === void 0)
4223
+ return true;
4224
+ if (version === void 0)
4225
+ return false;
4226
+ if (typeof options.version === "function")
4227
+ return options.version(version);
4228
+ return version === options.version;
4229
+ }
4230
+
4231
+ // node_modules/@opencode/client/dist/chunks/service-timing-0rcx1gca.js
4232
+ init_service_timing_9rqn6x4v();
4233
+ import { readFile, rename, rm, writeFile } from "node:fs/promises";
4234
+ var exports_pty_handoff = {};
4235
+ __export2(exports_pty_handoff, {
4236
+ PtyHandoff: () => exports_pty_handoff,
4237
+ clear: () => clear2,
4238
+ complete: () => complete2,
4239
+ environment: () => environment2,
4240
+ prepare: () => prepare2
4241
+ });
4242
+ async function prepare2(file, info, timeout) {
4243
+ const existing = await read(file);
4244
+ if (existing !== void 0 && existing.expiresAt > Date.now() && same(existing.source, info))
4245
+ return;
4246
+ const { OpenCode } = await Promise.resolve().then(() => (init_promise(), promise_exports));
4247
+ const client = OpenCode.make({
4248
+ baseUrl: info.url,
4249
+ headers: info.password === void 0 ? void 0 : { authorization: "Basic " + Buffer.from(`opencode:${info.password}`).toString("base64") }
4250
+ });
4251
+ const handoff = await client.experimental.persistentPty.handoff({ signal: AbortSignal.timeout(timeout) }).then(parse).catch(async (cause) => {
4252
+ const concurrent = await read(file);
4253
+ if (concurrent !== void 0 && concurrent.expiresAt > Date.now() && same(concurrent.source, info))
4254
+ return;
4255
+ console.warn("Background service cannot hand off persistent terminals; shutting them down before replacement", cause);
4256
+ await client.experimental.persistentPty.shutdown({ signal: AbortSignal.timeout(timeout) }).catch(() => {
4257
+ });
4258
+ return null;
4259
+ });
4260
+ if (handoff === void 0)
4261
+ return;
4262
+ await publish2(file, info, handoff).catch((cause) => console.warn("Failed to publish persistent terminal handoff", cause));
4263
+ }
4264
+ function parse(body) {
4265
+ if (typeof body !== "object" || body === null || !("handoff" in body))
4266
+ throw new Error("Invalid persistent terminal handoff response");
4267
+ if (body.handoff === null)
4268
+ return null;
4269
+ if (!isHandoff(body.handoff) || body.handoff.expiresAt <= Date.now())
4270
+ throw new Error("Invalid or expired persistent terminal handoff");
4271
+ return body.handoff;
4272
+ }
4273
+ async function publish2(file, info, handoff) {
4274
+ const temporary = `${file}.pty-handoff.${crypto.randomUUID()}.tmp`;
4275
+ await writeFile(temporary, JSON.stringify({
4276
+ source: { id: info.id, pid: info.pid, url: info.url },
4277
+ handoff,
4278
+ expiresAt: handoff?.expiresAt ?? Date.now() + 3e4
4279
+ }), { mode: 384, flag: "wx" });
4280
+ await rename(temporary, file + ".pty-handoff").finally(() => rm(temporary, { force: true }));
4281
+ }
4282
+ async function environment2(file, env) {
4283
+ const record = await read(file);
4284
+ const current = await readFile(file, "utf8").then((text) => JSON.parse(text)).catch(() => {
4285
+ return;
4286
+ });
4287
+ const handoff = record !== void 0 && record.expiresAt > Date.now() && (current === void 0 || same(record.source, current)) ? record.handoff : void 0;
4288
+ return { ...env, OPENCODE_PTY_HANDOFF: handoff == null ? void 0 : JSON.stringify(handoff) };
4289
+ }
4290
+ async function complete2(file, info) {
4291
+ const record = await read(file);
4292
+ if (record !== void 0 && !same(record.source, info))
4293
+ await clear2(file);
4294
+ }
4295
+ async function clear2(file) {
4296
+ await rm(file + ".pty-handoff", { force: true });
4297
+ }
4298
+ async function read(file) {
4299
+ const value = await readFile(file + ".pty-handoff", "utf8").then((text) => JSON.parse(text)).catch(() => {
4300
+ return;
4301
+ });
4302
+ if (typeof value !== "object" || value === null || !("source" in value) || !("handoff" in value))
4303
+ return;
4304
+ if (typeof value.source !== "object" || value.source === null)
4305
+ return;
4306
+ if (!("pid" in value.source) || typeof value.source.pid !== "number")
4307
+ return;
4308
+ if (!("url" in value.source) || typeof value.source.url !== "string")
4309
+ return;
4310
+ if ("id" in value.source && typeof value.source.id !== "string")
4311
+ return;
4312
+ if (value.handoff !== null && !isHandoff(value.handoff))
4313
+ return;
4314
+ if (!("expiresAt" in value) || typeof value.expiresAt !== "number" || !Number.isFinite(value.expiresAt))
4315
+ return;
4316
+ return {
4317
+ source: {
4318
+ id: "id" in value.source && typeof value.source.id === "string" ? value.source.id : void 0,
4319
+ pid: value.source.pid,
4320
+ url: value.source.url
4321
+ },
4322
+ handoff: value.handoff,
4323
+ expiresAt: value.expiresAt
4324
+ };
4325
+ }
4326
+ function same(left, right) {
4327
+ return left.id === right.id && left.pid === right.pid && left.url === right.url;
4328
+ }
4329
+ function isHandoff(value) {
4330
+ return typeof value === "object" && value !== null && "directory" in value && typeof value.directory === "string" && "instanceID" in value && typeof value.instanceID === "string" && "ticket" in value && typeof value.ticket === "string" && "expiresAt" in value && typeof value.expiresAt === "number" && Number.isFinite(value.expiresAt);
4331
+ }
4332
+
4333
+ // node_modules/@opencode/client/dist/chunks/service-timing-8ye1ye6f.js
4334
+ import { homedir as homedir2 } from "node:os";
4335
+ import { join as join2 } from "node:path";
4336
+ function decide2(service, options) {
4337
+ if (!matchesVersion2(service.version, options))
4338
+ return { _tag: "replace", pty: service.state === "ready" ? "handoff" : "clear" };
4339
+ if (!service.compatible)
4340
+ return fail("Background service uses an incompatible health protocol. Update this client or explicitly restart the service.");
4341
+ if (service.state === "ready")
4342
+ return { _tag: "reuse" };
4343
+ if (service.state === "failed")
4344
+ return fail("Background service failed to start");
4345
+ return { _tag: "wait" };
4346
+ }
4347
+ function fail(message) {
4348
+ return { _tag: "fail", error: new Error(message) };
4349
+ }
4350
+ function fallback2() {
4351
+ return join2(process.env["XDG_STATE_HOME"] ?? join2(homedir2(), ".local", "state"), "opencode", "service.json");
4352
+ }
4353
+ function same2(left, right) {
4354
+ return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
4355
+ }
4356
+ async function probeResult2(info, timeout = defaultEnsureTiming2.requestTimeout) {
4357
+ const endpoint = {
4358
+ url: info.url,
4359
+ auth: info.password === void 0 ? void 0 : { type: "basic", username: "opencode", password: info.password }
4360
+ };
4361
+ const signal2 = AbortSignal.timeout(timeout);
4362
+ const result = await fetch(new URL("/api/info", info.url), { headers: headers2(endpoint), signal: signal2 }).then(async (response2) => ({
4363
+ response: response2,
4364
+ body: response2.status === 404 ? void 0 : await response2.json()
4365
+ })).catch(() => {
4366
+ return;
4367
+ });
4368
+ if (result === void 0)
4369
+ return { service: void 0, timedOut: signal2.aborted };
4370
+ const response = result.response;
4371
+ if (response.status === 404)
4372
+ return {
4373
+ service: {
4374
+ info,
4375
+ endpoint,
4376
+ version: info.version,
4377
+ state: "ready",
4378
+ compatible: false
4379
+ },
4380
+ timedOut: false
4381
+ };
4382
+ const serverInfo = decodeInfo(result.body);
4383
+ if (serverInfo === void 0)
4384
+ return { service: void 0, timedOut: false };
4385
+ if (serverInfo.pid !== info.pid)
4386
+ return { service: void 0, timedOut: false };
4387
+ if (info.version !== void 0 && serverInfo.version !== info.version)
4388
+ return { service: void 0, timedOut: false };
4389
+ return {
4390
+ service: {
4391
+ info,
4392
+ endpoint,
4393
+ version: serverInfo.version,
4394
+ state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
4395
+ compatible: true
4396
+ },
4397
+ timedOut: false
4398
+ };
4399
+ }
4400
+ function headers2(endpoint) {
4401
+ if (endpoint.auth === void 0)
4402
+ return;
4403
+ return {
4404
+ authorization: "Basic " + Buffer.from(endpoint.auth.username + ":" + endpoint.auth.password).toString("base64")
4405
+ };
4406
+ }
4407
+ function decodeInfo(input) {
4408
+ if (typeof input !== "object" || input === null)
4409
+ return;
4410
+ if (!("version" in input) || typeof input.version !== "string")
4411
+ return;
4412
+ if (!("pid" in input) || typeof input.pid !== "number" || !Number.isInteger(input.pid) || input.pid < 0)
4413
+ return;
4414
+ return { version: input.version, pid: input.pid };
4415
+ }
4416
+
4417
+ // node_modules/@opencode/client/dist/promise/service.js
4418
+ import { readFile as readFile2, rm as rm2 } from "node:fs/promises";
4419
+ async function discover(options = {}) {
4420
+ const found = (await registered(options.file)).service;
4421
+ if (found?.state !== "ready")
4422
+ return;
4423
+ if (!found.compatible)
4424
+ return;
4425
+ if (!matchesVersion2(found.version, options))
4426
+ return;
4427
+ return found.endpoint;
4428
+ }
4429
+ async function ensure(options = {}) {
4430
+ const timing = ensureTiming2(options);
4431
+ const deadline = Date.now() + timing.promiseTimeout;
4432
+ const pool = contenderPool2(timing);
4433
+ let timeouts;
4434
+ let announced = false;
4435
+ const announce = (reason, previousVersion) => {
4436
+ if (announced)
4437
+ return;
4438
+ announced = true;
4439
+ options.onStart?.(reason, previousVersion);
4440
+ };
4441
+ const spawnContender = async () => {
4442
+ const [command, ...args] = options.command ?? ["opencode", "serve", "--service"];
4443
+ if (command === void 0)
4444
+ throw new Error("Missing service command");
4445
+ try {
4446
+ return spawnServiceContender2(command, args, await environment2(options.file ?? fallback2(), options.env));
4447
+ } catch (cause) {
4448
+ throw new Error("Failed to start server", { cause });
4449
+ }
4450
+ };
4451
+ try {
4452
+ while (true) {
4453
+ if (Date.now() >= deadline)
4454
+ throw pool.failure() ?? new Error("Timed out waiting for the background service to start");
4455
+ const registration = await registered(options.file, timing.requestTimeout);
4456
+ if (registration.timedOut && registration.info !== void 0) {
4457
+ timeouts = {
4458
+ info: registration.info,
4459
+ count: timeouts !== void 0 && same2(timeouts.info, registration.info) ? timeouts.count + 1 : 1
4460
+ };
4461
+ if (timeouts.count >= 3) {
4462
+ announce("missing");
4463
+ console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
4464
+ await clear2(options.file ?? fallback2());
4465
+ await terminate(registration.info, options, timing);
4466
+ pool.evict(registration.info.pid);
4467
+ pool.recruitNow();
4468
+ timeouts = void 0;
4469
+ }
4470
+ } else
4471
+ timeouts = void 0;
4472
+ if (registration.service !== void 0) {
4473
+ pool.serviceAnswered();
4474
+ const service2 = registration.service;
4475
+ const decision = decide2(service2, options);
4476
+ if (decision._tag === "fail")
4477
+ throw decision.error;
4478
+ if (decision._tag === "reuse") {
4479
+ await complete2(options.file ?? fallback2(), service2.info);
4480
+ return service2.endpoint;
4481
+ }
4482
+ if (decision._tag === "replace") {
4483
+ announce("version-mismatch", service2.version);
4484
+ if (service2.state !== "ready")
4485
+ console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
4486
+ await stop({ file: options.file, pty: decision.pty }).catch(() => {
4487
+ return;
4488
+ });
4489
+ pool.evict(service2.info.pid);
4490
+ }
4491
+ } else {
4492
+ const failed = pool.reap();
4493
+ if (failed !== void 0)
4494
+ throw failed;
4495
+ if (pool.shouldRecruit(registration.info !== void 0)) {
4496
+ announce("missing");
4497
+ pool.add(await spawnContender());
4498
+ }
4499
+ }
4500
+ await delay(timing.pollInterval);
4501
+ }
4502
+ } finally {
4503
+ pool.releaseAll();
4504
+ }
4505
+ }
4506
+ async function stop(options = {}) {
4507
+ const info = await read2(options.file);
4508
+ await (options.pty === "handoff" && info !== void 0 ? prepare2(options.file ?? fallback2(), info, defaultEnsureTiming2.requestTimeout) : clear2(options.file ?? fallback2())).catch((cause) => console.warn("Failed to prepare persistent terminals for replacement", cause));
4509
+ if (info !== void 0)
4510
+ await terminate(info, options, ensureTiming2(options));
4511
+ }
4512
+ async function read2(file) {
4513
+ const text = await readFile2(file ?? fallback2(), "utf8").catch(() => {
4514
+ return;
4515
+ });
4516
+ if (text === void 0)
4517
+ return;
4518
+ try {
4519
+ return JSON.parse(text);
4520
+ } catch {
4521
+ return;
4522
+ }
4523
+ }
4524
+ async function registered(file, timeout) {
4525
+ const info = await read2(file);
4526
+ if (info === void 0)
4527
+ return { info: void 0, service: void 0, timedOut: false };
4528
+ return { info, ...await probeResult2(info, timeout) };
4529
+ }
4530
+ function signal(pid, name) {
4531
+ try {
4532
+ process.kill(pid, name);
4533
+ } catch {
4534
+ }
4535
+ }
4536
+ function stopped(pid) {
4537
+ try {
4538
+ process.kill(pid, 0);
4539
+ return false;
4540
+ } catch {
4541
+ return true;
4542
+ }
4543
+ }
4544
+ async function waitUntilStopped(pid, timing) {
4545
+ for (let attempt = 0; attempt <= timing.stopPollAttempts; attempt++) {
4546
+ if (stopped(pid))
4547
+ return true;
4548
+ if (attempt < timing.stopPollAttempts)
4549
+ await delay(timing.stopPollInterval);
4550
+ }
4551
+ return false;
4552
+ }
4553
+ async function terminate(info, options, timing) {
4554
+ const current = await read2(options.file);
4555
+ if (current === void 0 || !same2(current, info))
4556
+ return;
4557
+ signal(info.pid, "SIGTERM");
4558
+ if (!await waitUntilStopped(info.pid, timing)) {
4559
+ signal(info.pid, "SIGKILL");
4560
+ if (!await waitUntilStopped(info.pid, timing))
4561
+ throw new Error(`Server process ${info.pid} is still running`);
4562
+ }
4563
+ const latest = await read2(options.file);
4564
+ if (latest === void 0 || !same2(latest, info))
4565
+ return;
4566
+ await rm2(options.file ?? fallback2(), { force: true });
4567
+ }
4568
+ function delay(milliseconds) {
4569
+ return new Promise((resolve2) => setTimeout(resolve2, milliseconds));
4570
+ }
4571
+ var Service = { discover, ensure, stop, headers: headers2 };
4572
+
4573
+ // src/opencode-v2-forms.js
4574
+ async function getFormApi(ctx, sessionID, { makeClient = exports_client.make } = {}) {
4575
+ const endpoint = await Service.discover({ version: ctx.app.version });
4576
+ if (!endpoint) {
4577
+ throw new HttpError("Remote question replies require the OpenCode V2 shared service", 501);
4578
+ }
4579
+ const client = makeClient({ baseUrl: endpoint.url, headers: Service.headers(endpoint) });
4580
+ let session;
4581
+ try {
4582
+ session = await client.session.get({ sessionID });
4583
+ } catch {
4584
+ throw new HttpError("The question session is not owned by the shared OpenCode service", 501);
4585
+ }
4586
+ if (session.location.directory !== ctx.location.directory) {
4587
+ throw new HttpError("The question session belongs to another OpenCode location", 403);
4588
+ }
4589
+ return client.session.form;
4590
+ }
4591
+
4592
+ // src/opencode-v2-client.js
4593
+ async function nativeReply(operation) {
4594
+ try {
4595
+ return await operation();
4596
+ } catch (error) {
4597
+ const statuses = {
4598
+ PermissionNotFoundError: 404,
4599
+ SessionNotFoundError: 404,
4600
+ FormNotFoundError: 404,
4601
+ FormAlreadySettledError: 409,
4602
+ FormInvalidAnswerError: 422
4603
+ };
4604
+ const status = statuses[error?._tag];
4605
+ if (status) throw new HttpError(error.message || error._tag, status);
4606
+ throw error;
4607
+ }
4608
+ }
4609
+ function questionForm(form) {
4610
+ return form?.metadata?.kind === "question" && typeof form.sessionID === "string" && form.sessionID !== "global" && Array.isArray(form.fields) && form.fields.length > 0 && form.fields.every(
4611
+ (field) => ["string", "multiselect"].includes(field.type) && !field.hidden && !field.when?.length
4612
+ );
4613
+ }
4614
+ function normalizeV2Event(event) {
4615
+ const properties = event.data ?? {};
4616
+ const normalized = { ...event, properties };
4617
+ if (event.type === "form.created") {
4618
+ const form = properties.form;
4619
+ if (!questionForm(form)) return [];
4620
+ return [{ ...normalized, type: "question.v2.asked", properties: {
4621
+ id: form.id,
4622
+ sessionID: form.sessionID,
4623
+ questions: form.fields.map((field) => ({
4624
+ header: field.title ?? form.title,
4625
+ question: field.description ?? field.title ?? form.title,
4626
+ options: (field.options ?? []).map((option) => ({
4627
+ label: option.label,
4628
+ description: option.description ?? ""
4629
+ })),
4630
+ multiple: field.type === "multiselect",
4631
+ custom: field.custom === true || !field.options?.length
4632
+ }))
4633
+ } }];
4634
+ }
4635
+ if (event.type === "form.replied" || event.type === "form.cancelled") {
4636
+ return [{ ...normalized, type: event.type === "form.replied" ? "question.v2.replied" : "question.v2.rejected" }];
4637
+ }
4638
+ if (event.type === "session.execution.started") {
4639
+ return [{ ...normalized, type: "session.status", properties: {
4640
+ ...properties,
4641
+ status: { type: "busy" }
4642
+ } }];
4643
+ }
4644
+ if (["session.execution.succeeded", "session.execution.interrupted"].includes(event.type)) {
4645
+ return [
4646
+ { ...normalized, type: "message.updated", properties: { info: {
4647
+ role: "assistant",
4648
+ sessionID: properties.sessionID,
4649
+ id: event.id,
4650
+ time: { completed: event.created },
4651
+ error: event.type === "session.execution.interrupted"
4652
+ } } },
4653
+ { ...normalized, type: "session.idle" }
4654
+ ];
4655
+ }
4656
+ if (event.type === "session.execution.failed") {
4657
+ return [{ ...normalized, type: "session.error" }, { ...normalized, type: "session.idle" }];
4658
+ }
4659
+ if (event.type === "session.idle" || event.type === "session.status" && properties.status?.type === "idle") {
4660
+ return [];
4661
+ }
4662
+ return [normalized];
4663
+ }
4664
+ function createV2Client(ctx, resolveFormApi = (sessionID) => getFormApi(ctx, sessionID)) {
4665
+ return {
4666
+ app: {
4667
+ async log({ body }) {
4668
+ console.error(JSON.stringify(body));
4669
+ }
4670
+ },
4671
+ session: {
4672
+ get: ({ path }) => ctx.session.get({ sessionID: path.id }),
4673
+ prompt: ({ path, body }) => ctx.session.synthetic({
4674
+ sessionID: path.id,
4675
+ text: body.parts.map((part) => part.text).join("\n"),
4676
+ resume: false
4677
+ })
4678
+ },
4679
+ postSessionIdPermissionsPermissionId: ({ path, body }) => nativeReply(() => ctx.permission.reply({
4680
+ sessionID: path.id,
4681
+ requestID: path.permissionID,
4682
+ decision: body.response
4683
+ })),
4684
+ v2: { session: { question: {
4685
+ async reply({ sessionID, requestID, questionV2Reply }) {
4686
+ const api = await resolveFormApi(sessionID);
4687
+ const form = await nativeReply(() => api.get({ sessionID, formID: requestID }));
4688
+ if (!questionForm(form)) throw new HttpError("Unsupported OpenCode question form", 422);
4689
+ const answers = questionV2Reply.answers;
4690
+ if (!Array.isArray(answers) || answers.length !== form.fields.length) {
4691
+ throw new HttpError("Question answer count does not match the form", 422);
4692
+ }
4693
+ const answer = {};
4694
+ form.fields.forEach((field, index) => {
4695
+ const selections = answers[index];
4696
+ if (!Array.isArray(selections) || selections.some((value) => typeof value !== "string")) {
4697
+ throw new HttpError("Invalid question answer", 422);
4698
+ }
4699
+ const values = selections.map(
4700
+ (label) => field.options?.find((option) => option.label === label)?.value ?? label
4701
+ );
4702
+ if (field.type === "multiselect") answer[field.key] = values;
4703
+ else if (values.length === 1) answer[field.key] = values[0];
4704
+ else if (values.length > 1) throw new HttpError("Single-choice question has multiple answers", 422);
4705
+ });
4706
+ return nativeReply(() => api.reply({ sessionID, formID: requestID, answer }));
4707
+ },
4708
+ async reject({ sessionID, requestID }) {
4709
+ const api = await resolveFormApi(sessionID);
4710
+ const form = await nativeReply(() => api.get({ sessionID, formID: requestID }));
4711
+ if (!questionForm(form)) throw new HttpError("Unsupported OpenCode question form", 422);
4712
+ return nativeReply(() => api.cancel({ sessionID, formID: requestID }));
4713
+ }
4714
+ } } },
4715
+ async ownsEvent(event) {
4716
+ if (event.location?.directory) return event.location.directory === ctx.location.directory;
4717
+ const sessionID = event.data?.sessionID ?? event.data?.form?.sessionID;
4718
+ if (!sessionID) return event.type === "installation.update-available";
4719
+ if (sessionID === "global") return false;
4720
+ try {
4721
+ const session = await ctx.session.get({ sessionID });
4722
+ return session.location?.directory === ctx.location.directory;
4723
+ } catch {
4724
+ return false;
4725
+ }
4726
+ }
4727
+ };
4728
+ }
4729
+
4730
+ // src/opencode-v2.js
4731
+ function waitForReconnect(signal2, delay2) {
4732
+ return new Promise((resolve2) => {
4733
+ const finish = () => {
4734
+ clearTimeout(timer);
4735
+ signal2.removeEventListener("abort", finish);
4736
+ resolve2();
4737
+ };
4738
+ const timer = setTimeout(finish, delay2);
4739
+ signal2.addEventListener("abort", finish, { once: true });
4740
+ if (signal2.aborted) finish();
4741
+ });
4742
+ }
4743
+ async function setup(ctx) {
4744
+ const client = createV2Client(ctx);
4745
+ const reporter = createOpenCodeReporter(client, ctx.options?.logLevel ?? process.env.BACKEER_LOG_LEVEL);
4746
+ const feedback = Object.fromEntries(
4747
+ ["info", "success", "applied", "warning", "error"].map((kind) => [
4748
+ kind,
4749
+ () => {
4750
+ }
4751
+ ])
4752
+ );
4753
+ feedback.handle = () => {
4754
+ };
4755
+ feedback.dispose = () => {
4756
+ };
4757
+ const hooks = await BackeerPlugin({
4758
+ client,
4759
+ directory: ctx.location.directory,
4760
+ feedback,
4761
+ v2: true
4762
+ }, { ...ctx.options, todos: false });
4763
+ if (!hooks.event) return;
4764
+ const controller = new AbortController();
4765
+ let streamTask;
4766
+ let cleanupTask;
4767
+ const registrations = [];
4768
+ function cleanup() {
4769
+ cleanupTask ??= (async () => {
4770
+ controller.abort();
4771
+ await streamTask?.catch(() => {
4772
+ });
4773
+ await hooks.dispose();
4774
+ await Promise.all(registrations.map((registration) => registration.dispose()));
4775
+ })();
4776
+ return cleanupTask;
4777
+ }
4778
+ try {
4779
+ await ctx.command.transform((editor) => {
4780
+ editor.add({
4781
+ name: "backeer",
4782
+ description: "Check, test, update, or manage Backeer",
4783
+ async execute({ sessionID, prompt, delivery }) {
4784
+ const output = { parts: [] };
4785
+ await hooks["command.execute.before"]({
4786
+ command: "backeer",
4787
+ sessionID,
4788
+ arguments: prompt.text
4789
+ }, output);
4790
+ if (output.parts.length) {
4791
+ await ctx.session.prompt({
4792
+ sessionID,
4793
+ text: output.parts.map((part) => part.text).join("\n"),
4794
+ delivery
4795
+ });
4796
+ }
4797
+ }
4798
+ });
4799
+ }).then((registration) => registrations.push(registration));
4800
+ registrations.push(await ctx.session.hook("prompt", async (event) => {
4801
+ const output = { message: { id: event.messageID }, parts: [] };
4802
+ await hooks["chat.message"]({ sessionID: event.sessionID }, output);
4803
+ if (output.parts.length) {
4804
+ event.prompt.text += `
4805
+
4806
+ ${output.parts.map((part) => part.text).join("\n")}`;
4807
+ }
4808
+ }));
4809
+ streamTask = (async () => {
4810
+ let delay2 = 1e3;
4811
+ while (!controller.signal.aborted) {
4812
+ try {
4813
+ for await (const event of ctx.event.subscribe({ signal: controller.signal })) {
4814
+ if (controller.signal.aborted) break;
4815
+ if (!await client.ownsEvent(event)) continue;
4816
+ delay2 = 1e3;
4817
+ for (const normalized of normalizeV2Event(event)) {
4818
+ await hooks.event({ event: normalized });
4819
+ }
4820
+ }
4821
+ } catch (error) {
4822
+ if (!controller.signal.aborted) reporter.error("OpenCode event stream disconnected", error);
4823
+ }
4824
+ if (!controller.signal.aborted) {
4825
+ await waitForReconnect(controller.signal, delay2);
4826
+ delay2 = Math.min(delay2 * 2, 3e4);
4827
+ }
4828
+ }
4829
+ })();
4830
+ return cleanup;
4831
+ } catch (error) {
4832
+ await cleanup();
4833
+ throw error;
4834
+ }
4835
+ }
4836
+
4837
+ // src/index.js
4838
+ var index_default = { id: "backeer-opencode", setup, server: BackeerPlugin };
2242
4839
  export {
2243
- BackeerPlugin as default
4840
+ index_default as default
2244
4841
  };