alchemylab-opencode 1.0.15 → 1.0.16

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.
@@ -0,0 +1,4794 @@
1
+ // Built by esbuild from opencode-server source
2
+ if (typeof globalThis.Bun === 'undefined') {
3
+ globalThis.Bun = {
4
+ version: '0.0.0-node-compat',
5
+ stdin: { async text() { const chunks = []; for await (const c of process.stdin) chunks.push(c); return Buffer.concat(chunks).toString(); } },
6
+ which(cmd) { try { return require('child_process').execFileSync('which', [cmd], { encoding: 'utf8' }).trim(); } catch { return null; } },
7
+ };
8
+ }
9
+ if (typeof globalThis.__name === 'undefined') { globalThis.__name = (t, n) => { Object.defineProperty(t, 'name', { value: n, configurable: true }); return t; }; }
10
+ if (typeof globalThis.__export === 'undefined') { globalThis.__export = (t, a) => { for (const k in a) Object.defineProperty(t, k, { get: a[k], enumerable: true }); }; }
11
+
12
+ import {
13
+ Server
14
+ } from "./chunk-UMPQHK6N.js";
15
+ import {
16
+ InstanceBootstrap
17
+ } from "./chunk-S53MTTCM.js";
18
+ import "./chunk-3AF5MXLF.js";
19
+ import "./chunk-PWFRMDDF.js";
20
+ import "./chunk-BKZE6GM3.js";
21
+ import {
22
+ Agent,
23
+ Provider
24
+ } from "./chunk-GNXOGOVC.js";
25
+ import "./chunk-AAJTTZ2B.js";
26
+ import {
27
+ Filesystem,
28
+ Flag,
29
+ Instance,
30
+ NamedError
31
+ } from "./chunk-3PZZ2D23.js";
32
+ import "./chunk-CR6IREZA.js";
33
+ import "./chunk-BI5OUHTQ.js";
34
+ import "./chunk-VL3RSEZ2.js";
35
+ import {
36
+ __require
37
+ } from "./chunk-HORZKFCR.js";
38
+
39
+ // packages/opencode/src/cli/cmd/run.ts
40
+ import path from "path";
41
+ import { pathToFileURL } from "url";
42
+
43
+ // packages/opencode/src/cli/ui.ts
44
+ import z from "zod";
45
+ import { EOL } from "os";
46
+
47
+ // packages/opencode/src/cli/logo.ts
48
+ var logo = {
49
+ left: [" ", "\u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2584", "\u2588__\u2588 \u2588__\u2588 \u2588^^^ \u2588__\u2588", "\u2580\u2580\u2580\u2580 \u2588\u2580\u2580\u2580 \u2580\u2580\u2580\u2580 \u2580~~\u2580"],
50
+ right: [" \u2584 ", "\u2588\u2580\u2580\u2580 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588", "\u2588___ \u2588__\u2588 \u2588__\u2588 \u2588^^^", "\u2580\u2580\u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580\u2580\u2580"]
51
+ };
52
+
53
+ // packages/opencode/src/cli/ui.ts
54
+ var UI;
55
+ ((UI2) => {
56
+ const wordmark = [
57
+ `\u2800 \u2584 `,
58
+ `\u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2584 \u2588\u2580\u2580\u2580 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588 \u2588\u2580\u2580\u2588`,
59
+ `\u2588 \u2588 \u2588 \u2588 \u2588\u2580\u2580\u2580 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588\u2580\u2580\u2580`,
60
+ `\u2580\u2580\u2580\u2580 \u2588\u2580\u2580\u2580 \u2580\u2580\u2580\u2580 \u2580 \u2580 \u2580\u2580\u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580\u2580\u2580`
61
+ ];
62
+ UI2.CancelledError = NamedError.create("UICancelledError", z.void());
63
+ UI2.Style = {
64
+ TEXT_HIGHLIGHT: "\x1B[96m",
65
+ TEXT_HIGHLIGHT_BOLD: "\x1B[96m\x1B[1m",
66
+ TEXT_DIM: "\x1B[90m",
67
+ TEXT_DIM_BOLD: "\x1B[90m\x1B[1m",
68
+ TEXT_NORMAL: "\x1B[0m",
69
+ TEXT_NORMAL_BOLD: "\x1B[1m",
70
+ TEXT_WARNING: "\x1B[93m",
71
+ TEXT_WARNING_BOLD: "\x1B[93m\x1B[1m",
72
+ TEXT_DANGER: "\x1B[91m",
73
+ TEXT_DANGER_BOLD: "\x1B[91m\x1B[1m",
74
+ TEXT_SUCCESS: "\x1B[92m",
75
+ TEXT_SUCCESS_BOLD: "\x1B[92m\x1B[1m",
76
+ TEXT_INFO: "\x1B[94m",
77
+ TEXT_INFO_BOLD: "\x1B[94m\x1B[1m"
78
+ };
79
+ function println(...message) {
80
+ print(...message);
81
+ process.stderr.write(EOL);
82
+ }
83
+ UI2.println = println;
84
+ function print(...message) {
85
+ blank = false;
86
+ process.stderr.write(message.join(" "));
87
+ }
88
+ UI2.print = print;
89
+ let blank = false;
90
+ function empty() {
91
+ if (blank) return;
92
+ println("" + UI2.Style.TEXT_NORMAL);
93
+ blank = true;
94
+ }
95
+ UI2.empty = empty;
96
+ function logo2(pad) {
97
+ if (!process.stdout.isTTY && !process.stderr.isTTY) {
98
+ const result2 = [];
99
+ for (const row of wordmark) {
100
+ if (pad) result2.push(pad);
101
+ result2.push(row);
102
+ result2.push(EOL);
103
+ }
104
+ return result2.join("").trimEnd();
105
+ }
106
+ const result = [];
107
+ const reset = "\x1B[0m";
108
+ const left = {
109
+ fg: "\x1B[90m",
110
+ shadow: "\x1B[38;5;235m",
111
+ bg: "\x1B[48;5;235m"
112
+ };
113
+ const right = {
114
+ fg: reset,
115
+ shadow: "\x1B[38;5;238m",
116
+ bg: "\x1B[48;5;238m"
117
+ };
118
+ const gap = " ";
119
+ const draw = (line, fg, shadow, bg) => {
120
+ const parts = [];
121
+ for (const char of line) {
122
+ if (char === "_") {
123
+ parts.push(bg, " ", reset);
124
+ continue;
125
+ }
126
+ if (char === "^") {
127
+ parts.push(fg, bg, "\u2580", reset);
128
+ continue;
129
+ }
130
+ if (char === "~") {
131
+ parts.push(shadow, "\u2580", reset);
132
+ continue;
133
+ }
134
+ if (char === " ") {
135
+ parts.push(" ");
136
+ continue;
137
+ }
138
+ parts.push(fg, char, reset);
139
+ }
140
+ return parts.join("");
141
+ };
142
+ logo.left.forEach((row, index) => {
143
+ if (pad) result.push(pad);
144
+ result.push(draw(row, left.fg, left.shadow, left.bg));
145
+ result.push(gap);
146
+ const other = logo.right[index] ?? "";
147
+ result.push(draw(other, right.fg, right.shadow, right.bg));
148
+ result.push(EOL);
149
+ });
150
+ return result.join("").trimEnd();
151
+ }
152
+ UI2.logo = logo2;
153
+ async function input(prompt) {
154
+ const readline = __require("readline");
155
+ const rl = readline.createInterface({
156
+ input: process.stdin,
157
+ output: process.stdout
158
+ });
159
+ return new Promise((resolve) => {
160
+ rl.question(prompt, (answer) => {
161
+ rl.close();
162
+ resolve(answer.trim());
163
+ });
164
+ });
165
+ }
166
+ UI2.input = input;
167
+ function error(message) {
168
+ if (message.startsWith("Error: ")) {
169
+ message = message.slice("Error: ".length);
170
+ }
171
+ println(UI2.Style.TEXT_DANGER_BOLD + "Error: " + UI2.Style.TEXT_NORMAL + message);
172
+ }
173
+ UI2.error = error;
174
+ function markdown(text) {
175
+ return text;
176
+ }
177
+ UI2.markdown = markdown;
178
+ })(UI || (UI = {}));
179
+
180
+ // packages/opencode/src/cli/cmd/cmd.ts
181
+ function cmd(input) {
182
+ return input;
183
+ }
184
+
185
+ // packages/opencode/src/cli/bootstrap.ts
186
+ async function bootstrap(directory, cb) {
187
+ return Instance.provide({
188
+ directory,
189
+ init: InstanceBootstrap,
190
+ fn: async () => {
191
+ try {
192
+ const result = await cb();
193
+ return result;
194
+ } finally {
195
+ await Instance.dispose();
196
+ }
197
+ }
198
+ });
199
+ }
200
+
201
+ // packages/opencode/src/cli/cmd/run.ts
202
+ import { EOL as EOL2 } from "os";
203
+
204
+ // packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts
205
+ var createSseClient = ({
206
+ onRequest,
207
+ onSseError,
208
+ onSseEvent,
209
+ responseTransformer,
210
+ responseValidator,
211
+ sseDefaultRetryDelay,
212
+ sseMaxRetryAttempts,
213
+ sseMaxRetryDelay,
214
+ sseSleepFn,
215
+ url,
216
+ ...options
217
+ }) => {
218
+ let lastEventId;
219
+ const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
220
+ const createStream = async function* () {
221
+ let retryDelay = sseDefaultRetryDelay ?? 3e3;
222
+ let attempt = 0;
223
+ const signal = options.signal ?? new AbortController().signal;
224
+ while (true) {
225
+ if (signal.aborted) break;
226
+ attempt++;
227
+ const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
228
+ if (lastEventId !== void 0) {
229
+ headers.set("Last-Event-ID", lastEventId);
230
+ }
231
+ try {
232
+ const requestInit = {
233
+ redirect: "follow",
234
+ ...options,
235
+ body: options.serializedBody,
236
+ headers,
237
+ signal
238
+ };
239
+ let request = new Request(url, requestInit);
240
+ if (onRequest) {
241
+ request = await onRequest(url, requestInit);
242
+ }
243
+ const _fetch = options.fetch ?? globalThis.fetch;
244
+ const response = await _fetch(request);
245
+ if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
246
+ if (!response.body) throw new Error("No body in SSE response");
247
+ const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
248
+ let buffer = "";
249
+ const abortHandler = () => {
250
+ try {
251
+ reader.cancel();
252
+ } catch {
253
+ }
254
+ };
255
+ signal.addEventListener("abort", abortHandler);
256
+ try {
257
+ while (true) {
258
+ const { done, value } = await reader.read();
259
+ if (done) break;
260
+ buffer += value;
261
+ buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
262
+ const chunks = buffer.split("\n\n");
263
+ buffer = chunks.pop() ?? "";
264
+ for (const chunk of chunks) {
265
+ const lines = chunk.split("\n");
266
+ const dataLines = [];
267
+ let eventName;
268
+ for (const line of lines) {
269
+ if (line.startsWith("data:")) {
270
+ dataLines.push(line.replace(/^data:\s*/, ""));
271
+ } else if (line.startsWith("event:")) {
272
+ eventName = line.replace(/^event:\s*/, "");
273
+ } else if (line.startsWith("id:")) {
274
+ lastEventId = line.replace(/^id:\s*/, "");
275
+ } else if (line.startsWith("retry:")) {
276
+ const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
277
+ if (!Number.isNaN(parsed)) {
278
+ retryDelay = parsed;
279
+ }
280
+ }
281
+ }
282
+ let data;
283
+ let parsedJson = false;
284
+ if (dataLines.length) {
285
+ const rawData = dataLines.join("\n");
286
+ try {
287
+ data = JSON.parse(rawData);
288
+ parsedJson = true;
289
+ } catch {
290
+ data = rawData;
291
+ }
292
+ }
293
+ if (parsedJson) {
294
+ if (responseValidator) {
295
+ await responseValidator(data);
296
+ }
297
+ if (responseTransformer) {
298
+ data = await responseTransformer(data);
299
+ }
300
+ }
301
+ onSseEvent?.({
302
+ data,
303
+ event: eventName,
304
+ id: lastEventId,
305
+ retry: retryDelay
306
+ });
307
+ if (dataLines.length) {
308
+ yield data;
309
+ }
310
+ }
311
+ }
312
+ } finally {
313
+ signal.removeEventListener("abort", abortHandler);
314
+ reader.releaseLock();
315
+ }
316
+ break;
317
+ } catch (error) {
318
+ onSseError?.(error);
319
+ if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
320
+ break;
321
+ }
322
+ const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
323
+ await sleep(backoff);
324
+ }
325
+ }
326
+ };
327
+ const stream = createStream();
328
+ return { stream };
329
+ };
330
+
331
+ // packages/sdk/src/v2/gen/core/pathSerializer.gen.ts
332
+ var separatorArrayExplode = (style) => {
333
+ switch (style) {
334
+ case "label":
335
+ return ".";
336
+ case "matrix":
337
+ return ";";
338
+ case "simple":
339
+ return ",";
340
+ default:
341
+ return "&";
342
+ }
343
+ };
344
+ var separatorArrayNoExplode = (style) => {
345
+ switch (style) {
346
+ case "form":
347
+ return ",";
348
+ case "pipeDelimited":
349
+ return "|";
350
+ case "spaceDelimited":
351
+ return "%20";
352
+ default:
353
+ return ",";
354
+ }
355
+ };
356
+ var separatorObjectExplode = (style) => {
357
+ switch (style) {
358
+ case "label":
359
+ return ".";
360
+ case "matrix":
361
+ return ";";
362
+ case "simple":
363
+ return ",";
364
+ default:
365
+ return "&";
366
+ }
367
+ };
368
+ var serializeArrayParam = ({
369
+ allowReserved,
370
+ explode,
371
+ name,
372
+ style,
373
+ value
374
+ }) => {
375
+ if (!explode) {
376
+ const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(
377
+ separatorArrayNoExplode(style)
378
+ );
379
+ switch (style) {
380
+ case "label":
381
+ return `.${joinedValues2}`;
382
+ case "matrix":
383
+ return `;${name}=${joinedValues2}`;
384
+ case "simple":
385
+ return joinedValues2;
386
+ default:
387
+ return `${name}=${joinedValues2}`;
388
+ }
389
+ }
390
+ const separator = separatorArrayExplode(style);
391
+ const joinedValues = value.map((v) => {
392
+ if (style === "label" || style === "simple") {
393
+ return allowReserved ? v : encodeURIComponent(v);
394
+ }
395
+ return serializePrimitiveParam({
396
+ allowReserved,
397
+ name,
398
+ value: v
399
+ });
400
+ }).join(separator);
401
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
402
+ };
403
+ var serializePrimitiveParam = ({ allowReserved, name, value }) => {
404
+ if (value === void 0 || value === null) {
405
+ return "";
406
+ }
407
+ if (typeof value === "object") {
408
+ throw new Error(
409
+ "Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
410
+ );
411
+ }
412
+ return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
413
+ };
414
+ var serializeObjectParam = ({
415
+ allowReserved,
416
+ explode,
417
+ name,
418
+ style,
419
+ value,
420
+ valueOnly
421
+ }) => {
422
+ if (value instanceof Date) {
423
+ return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
424
+ }
425
+ if (style !== "deepObject" && !explode) {
426
+ let values = [];
427
+ Object.entries(value).forEach(([key, v]) => {
428
+ values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
429
+ });
430
+ const joinedValues2 = values.join(",");
431
+ switch (style) {
432
+ case "form":
433
+ return `${name}=${joinedValues2}`;
434
+ case "label":
435
+ return `.${joinedValues2}`;
436
+ case "matrix":
437
+ return `;${name}=${joinedValues2}`;
438
+ default:
439
+ return joinedValues2;
440
+ }
441
+ }
442
+ const separator = separatorObjectExplode(style);
443
+ const joinedValues = Object.entries(value).map(
444
+ ([key, v]) => serializePrimitiveParam({
445
+ allowReserved,
446
+ name: style === "deepObject" ? `${name}[${key}]` : key,
447
+ value: v
448
+ })
449
+ ).join(separator);
450
+ return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
451
+ };
452
+
453
+ // packages/sdk/src/v2/gen/core/utils.gen.ts
454
+ var PATH_PARAM_RE = /\{[^{}]+\}/g;
455
+ var defaultPathSerializer = ({ path: path2, url: _url }) => {
456
+ let url = _url;
457
+ const matches = _url.match(PATH_PARAM_RE);
458
+ if (matches) {
459
+ for (const match of matches) {
460
+ let explode = false;
461
+ let name = match.substring(1, match.length - 1);
462
+ let style = "simple";
463
+ if (name.endsWith("*")) {
464
+ explode = true;
465
+ name = name.substring(0, name.length - 1);
466
+ }
467
+ if (name.startsWith(".")) {
468
+ name = name.substring(1);
469
+ style = "label";
470
+ } else if (name.startsWith(";")) {
471
+ name = name.substring(1);
472
+ style = "matrix";
473
+ }
474
+ const value = path2[name];
475
+ if (value === void 0 || value === null) {
476
+ continue;
477
+ }
478
+ if (Array.isArray(value)) {
479
+ url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
480
+ continue;
481
+ }
482
+ if (typeof value === "object") {
483
+ url = url.replace(
484
+ match,
485
+ serializeObjectParam({
486
+ explode,
487
+ name,
488
+ style,
489
+ value,
490
+ valueOnly: true
491
+ })
492
+ );
493
+ continue;
494
+ }
495
+ if (style === "matrix") {
496
+ url = url.replace(
497
+ match,
498
+ `;${serializePrimitiveParam({
499
+ name,
500
+ value
501
+ })}`
502
+ );
503
+ continue;
504
+ }
505
+ const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
506
+ url = url.replace(match, replaceValue);
507
+ }
508
+ }
509
+ return url;
510
+ };
511
+ var getUrl = ({
512
+ baseUrl,
513
+ path: path2,
514
+ query,
515
+ querySerializer,
516
+ url: _url
517
+ }) => {
518
+ const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
519
+ let url = (baseUrl ?? "") + pathUrl;
520
+ if (path2) {
521
+ url = defaultPathSerializer({ path: path2, url });
522
+ }
523
+ let search = query ? querySerializer(query) : "";
524
+ if (search.startsWith("?")) {
525
+ search = search.substring(1);
526
+ }
527
+ if (search) {
528
+ url += `?${search}`;
529
+ }
530
+ return url;
531
+ };
532
+ function getValidRequestBody(options) {
533
+ const hasBody = options.body !== void 0;
534
+ const isSerializedBody = hasBody && options.bodySerializer;
535
+ if (isSerializedBody) {
536
+ if ("serializedBody" in options) {
537
+ const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
538
+ return hasSerializedBody ? options.serializedBody : null;
539
+ }
540
+ return options.body !== "" ? options.body : null;
541
+ }
542
+ if (hasBody) {
543
+ return options.body;
544
+ }
545
+ return void 0;
546
+ }
547
+
548
+ // packages/sdk/src/v2/gen/core/auth.gen.ts
549
+ var getAuthToken = async (auth, callback) => {
550
+ const token = typeof callback === "function" ? await callback(auth) : callback;
551
+ if (!token) {
552
+ return;
553
+ }
554
+ if (auth.scheme === "bearer") {
555
+ return `Bearer ${token}`;
556
+ }
557
+ if (auth.scheme === "basic") {
558
+ return `Basic ${btoa(token)}`;
559
+ }
560
+ return token;
561
+ };
562
+
563
+ // packages/sdk/src/v2/gen/core/bodySerializer.gen.ts
564
+ var jsonBodySerializer = {
565
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
566
+ };
567
+
568
+ // packages/sdk/src/v2/gen/client/utils.gen.ts
569
+ var createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
570
+ const querySerializer = (queryParams) => {
571
+ const search = [];
572
+ if (queryParams && typeof queryParams === "object") {
573
+ for (const name in queryParams) {
574
+ const value = queryParams[name];
575
+ if (value === void 0 || value === null) {
576
+ continue;
577
+ }
578
+ const options = parameters[name] || args;
579
+ if (Array.isArray(value)) {
580
+ const serializedArray = serializeArrayParam({
581
+ allowReserved: options.allowReserved,
582
+ explode: true,
583
+ name,
584
+ style: "form",
585
+ value,
586
+ ...options.array
587
+ });
588
+ if (serializedArray) search.push(serializedArray);
589
+ } else if (typeof value === "object") {
590
+ const serializedObject = serializeObjectParam({
591
+ allowReserved: options.allowReserved,
592
+ explode: true,
593
+ name,
594
+ style: "deepObject",
595
+ value,
596
+ ...options.object
597
+ });
598
+ if (serializedObject) search.push(serializedObject);
599
+ } else {
600
+ const serializedPrimitive = serializePrimitiveParam({
601
+ allowReserved: options.allowReserved,
602
+ name,
603
+ value
604
+ });
605
+ if (serializedPrimitive) search.push(serializedPrimitive);
606
+ }
607
+ }
608
+ }
609
+ return search.join("&");
610
+ };
611
+ return querySerializer;
612
+ };
613
+ var getParseAs = (contentType) => {
614
+ if (!contentType) {
615
+ return "stream";
616
+ }
617
+ const cleanContent = contentType.split(";")[0]?.trim();
618
+ if (!cleanContent) {
619
+ return;
620
+ }
621
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
622
+ return "json";
623
+ }
624
+ if (cleanContent === "multipart/form-data") {
625
+ return "formData";
626
+ }
627
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
628
+ return "blob";
629
+ }
630
+ if (cleanContent.startsWith("text/")) {
631
+ return "text";
632
+ }
633
+ return;
634
+ };
635
+ var checkForExistence = (options, name) => {
636
+ if (!name) {
637
+ return false;
638
+ }
639
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
640
+ return true;
641
+ }
642
+ return false;
643
+ };
644
+ var setAuthParams = async ({
645
+ security,
646
+ ...options
647
+ }) => {
648
+ for (const auth of security) {
649
+ if (checkForExistence(options, auth.name)) {
650
+ continue;
651
+ }
652
+ const token = await getAuthToken(auth, options.auth);
653
+ if (!token) {
654
+ continue;
655
+ }
656
+ const name = auth.name ?? "Authorization";
657
+ switch (auth.in) {
658
+ case "query":
659
+ if (!options.query) {
660
+ options.query = {};
661
+ }
662
+ options.query[name] = token;
663
+ break;
664
+ case "cookie":
665
+ options.headers.append("Cookie", `${name}=${token}`);
666
+ break;
667
+ case "header":
668
+ default:
669
+ options.headers.set(name, token);
670
+ break;
671
+ }
672
+ }
673
+ };
674
+ var buildUrl = (options) => getUrl({
675
+ baseUrl: options.baseUrl,
676
+ path: options.path,
677
+ query: options.query,
678
+ querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
679
+ url: options.url
680
+ });
681
+ var mergeConfigs = (a, b) => {
682
+ const config = { ...a, ...b };
683
+ if (config.baseUrl?.endsWith("/")) {
684
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
685
+ }
686
+ config.headers = mergeHeaders(a.headers, b.headers);
687
+ return config;
688
+ };
689
+ var headersEntries = (headers) => {
690
+ const entries = [];
691
+ headers.forEach((value, key) => {
692
+ entries.push([key, value]);
693
+ });
694
+ return entries;
695
+ };
696
+ var mergeHeaders = (...headers) => {
697
+ const mergedHeaders = new Headers();
698
+ for (const header of headers) {
699
+ if (!header) {
700
+ continue;
701
+ }
702
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
703
+ for (const [key, value] of iterator) {
704
+ if (value === null) {
705
+ mergedHeaders.delete(key);
706
+ } else if (Array.isArray(value)) {
707
+ for (const v of value) {
708
+ mergedHeaders.append(key, v);
709
+ }
710
+ } else if (value !== void 0) {
711
+ mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
712
+ }
713
+ }
714
+ }
715
+ return mergedHeaders;
716
+ };
717
+ var Interceptors = class {
718
+ fns = [];
719
+ clear() {
720
+ this.fns = [];
721
+ }
722
+ eject(id) {
723
+ const index = this.getInterceptorIndex(id);
724
+ if (this.fns[index]) {
725
+ this.fns[index] = null;
726
+ }
727
+ }
728
+ exists(id) {
729
+ const index = this.getInterceptorIndex(id);
730
+ return Boolean(this.fns[index]);
731
+ }
732
+ getInterceptorIndex(id) {
733
+ if (typeof id === "number") {
734
+ return this.fns[id] ? id : -1;
735
+ }
736
+ return this.fns.indexOf(id);
737
+ }
738
+ update(id, fn) {
739
+ const index = this.getInterceptorIndex(id);
740
+ if (this.fns[index]) {
741
+ this.fns[index] = fn;
742
+ return id;
743
+ }
744
+ return false;
745
+ }
746
+ use(fn) {
747
+ this.fns.push(fn);
748
+ return this.fns.length - 1;
749
+ }
750
+ };
751
+ var createInterceptors = () => ({
752
+ error: new Interceptors(),
753
+ request: new Interceptors(),
754
+ response: new Interceptors()
755
+ });
756
+ var defaultQuerySerializer = createQuerySerializer({
757
+ allowReserved: false,
758
+ array: {
759
+ explode: true,
760
+ style: "form"
761
+ },
762
+ object: {
763
+ explode: true,
764
+ style: "deepObject"
765
+ }
766
+ });
767
+ var defaultHeaders = {
768
+ "Content-Type": "application/json"
769
+ };
770
+ var createConfig = (override = {}) => ({
771
+ ...jsonBodySerializer,
772
+ headers: defaultHeaders,
773
+ parseAs: "auto",
774
+ querySerializer: defaultQuerySerializer,
775
+ ...override
776
+ });
777
+
778
+ // packages/sdk/src/v2/gen/client/client.gen.ts
779
+ var createClient = (config = {}) => {
780
+ let _config = mergeConfigs(createConfig(), config);
781
+ const getConfig = () => ({ ..._config });
782
+ const setConfig = (config2) => {
783
+ _config = mergeConfigs(_config, config2);
784
+ return getConfig();
785
+ };
786
+ const interceptors = createInterceptors();
787
+ const beforeRequest = async (options) => {
788
+ const opts = {
789
+ ..._config,
790
+ ...options,
791
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
792
+ headers: mergeHeaders(_config.headers, options.headers),
793
+ serializedBody: void 0
794
+ };
795
+ if (opts.security) {
796
+ await setAuthParams({
797
+ ...opts,
798
+ security: opts.security
799
+ });
800
+ }
801
+ if (opts.requestValidator) {
802
+ await opts.requestValidator(opts);
803
+ }
804
+ if (opts.body !== void 0 && opts.bodySerializer) {
805
+ opts.serializedBody = opts.bodySerializer(opts.body);
806
+ }
807
+ if (opts.body === void 0 || opts.serializedBody === "") {
808
+ opts.headers.delete("Content-Type");
809
+ }
810
+ const url = buildUrl(opts);
811
+ return { opts, url };
812
+ };
813
+ const request = async (options) => {
814
+ const { opts, url } = await beforeRequest(options);
815
+ const requestInit = {
816
+ redirect: "follow",
817
+ ...opts,
818
+ body: getValidRequestBody(opts)
819
+ };
820
+ let request2 = new Request(url, requestInit);
821
+ for (const fn of interceptors.request.fns) {
822
+ if (fn) {
823
+ request2 = await fn(request2, opts);
824
+ }
825
+ }
826
+ const _fetch = opts.fetch;
827
+ let response;
828
+ try {
829
+ response = await _fetch(request2);
830
+ } catch (error2) {
831
+ let finalError2 = error2;
832
+ for (const fn of interceptors.error.fns) {
833
+ if (fn) {
834
+ finalError2 = await fn(error2, void 0, request2, opts);
835
+ }
836
+ }
837
+ finalError2 = finalError2 || {};
838
+ if (opts.throwOnError) {
839
+ throw finalError2;
840
+ }
841
+ return opts.responseStyle === "data" ? void 0 : {
842
+ error: finalError2,
843
+ request: request2,
844
+ response: void 0
845
+ };
846
+ }
847
+ for (const fn of interceptors.response.fns) {
848
+ if (fn) {
849
+ response = await fn(response, request2, opts);
850
+ }
851
+ }
852
+ const result = {
853
+ request: request2,
854
+ response
855
+ };
856
+ if (response.ok) {
857
+ const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
858
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
859
+ let emptyData;
860
+ switch (parseAs) {
861
+ case "arrayBuffer":
862
+ case "blob":
863
+ case "text":
864
+ emptyData = await response[parseAs]();
865
+ break;
866
+ case "formData":
867
+ emptyData = new FormData();
868
+ break;
869
+ case "stream":
870
+ emptyData = response.body;
871
+ break;
872
+ case "json":
873
+ default:
874
+ emptyData = {};
875
+ break;
876
+ }
877
+ return opts.responseStyle === "data" ? emptyData : {
878
+ data: emptyData,
879
+ ...result
880
+ };
881
+ }
882
+ let data;
883
+ switch (parseAs) {
884
+ case "arrayBuffer":
885
+ case "blob":
886
+ case "formData":
887
+ case "text":
888
+ data = await response[parseAs]();
889
+ break;
890
+ case "json": {
891
+ const text = await response.text();
892
+ data = text ? JSON.parse(text) : {};
893
+ break;
894
+ }
895
+ case "stream":
896
+ return opts.responseStyle === "data" ? response.body : {
897
+ data: response.body,
898
+ ...result
899
+ };
900
+ }
901
+ if (parseAs === "json") {
902
+ if (opts.responseValidator) {
903
+ await opts.responseValidator(data);
904
+ }
905
+ if (opts.responseTransformer) {
906
+ data = await opts.responseTransformer(data);
907
+ }
908
+ }
909
+ return opts.responseStyle === "data" ? data : {
910
+ data,
911
+ ...result
912
+ };
913
+ }
914
+ const textError = await response.text();
915
+ let jsonError;
916
+ try {
917
+ jsonError = JSON.parse(textError);
918
+ } catch {
919
+ }
920
+ const error = jsonError ?? textError;
921
+ let finalError = error;
922
+ for (const fn of interceptors.error.fns) {
923
+ if (fn) {
924
+ finalError = await fn(error, response, request2, opts);
925
+ }
926
+ }
927
+ finalError = finalError || {};
928
+ if (opts.throwOnError) {
929
+ throw finalError;
930
+ }
931
+ return opts.responseStyle === "data" ? void 0 : {
932
+ error: finalError,
933
+ ...result
934
+ };
935
+ };
936
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
937
+ const makeSseFn = (method) => async (options) => {
938
+ const { opts, url } = await beforeRequest(options);
939
+ return createSseClient({
940
+ ...opts,
941
+ body: opts.body,
942
+ headers: opts.headers,
943
+ method,
944
+ onRequest: async (url2, init) => {
945
+ let request2 = new Request(url2, init);
946
+ for (const fn of interceptors.request.fns) {
947
+ if (fn) {
948
+ request2 = await fn(request2, opts);
949
+ }
950
+ }
951
+ return request2;
952
+ },
953
+ serializedBody: getValidRequestBody(opts),
954
+ url
955
+ });
956
+ };
957
+ return {
958
+ buildUrl,
959
+ connect: makeMethodFn("CONNECT"),
960
+ delete: makeMethodFn("DELETE"),
961
+ get: makeMethodFn("GET"),
962
+ getConfig,
963
+ head: makeMethodFn("HEAD"),
964
+ interceptors,
965
+ options: makeMethodFn("OPTIONS"),
966
+ patch: makeMethodFn("PATCH"),
967
+ post: makeMethodFn("POST"),
968
+ put: makeMethodFn("PUT"),
969
+ request,
970
+ setConfig,
971
+ sse: {
972
+ connect: makeSseFn("CONNECT"),
973
+ delete: makeSseFn("DELETE"),
974
+ get: makeSseFn("GET"),
975
+ head: makeSseFn("HEAD"),
976
+ options: makeSseFn("OPTIONS"),
977
+ patch: makeSseFn("PATCH"),
978
+ post: makeSseFn("POST"),
979
+ put: makeSseFn("PUT"),
980
+ trace: makeSseFn("TRACE")
981
+ },
982
+ trace: makeMethodFn("TRACE")
983
+ };
984
+ };
985
+
986
+ // packages/sdk/src/v2/gen/core/params.gen.ts
987
+ var extraPrefixesMap = {
988
+ $body_: "body",
989
+ $headers_: "headers",
990
+ $path_: "path",
991
+ $query_: "query"
992
+ };
993
+ var extraPrefixes = Object.entries(extraPrefixesMap);
994
+ var buildKeyMap = (fields, map) => {
995
+ if (!map) {
996
+ map = /* @__PURE__ */ new Map();
997
+ }
998
+ for (const config of fields) {
999
+ if ("in" in config) {
1000
+ if (config.key) {
1001
+ map.set(config.key, {
1002
+ in: config.in,
1003
+ map: config.map
1004
+ });
1005
+ }
1006
+ } else if ("key" in config) {
1007
+ map.set(config.key, {
1008
+ map: config.map
1009
+ });
1010
+ } else if (config.args) {
1011
+ buildKeyMap(config.args, map);
1012
+ }
1013
+ }
1014
+ return map;
1015
+ };
1016
+ var stripEmptySlots = (params) => {
1017
+ for (const [slot, value] of Object.entries(params)) {
1018
+ if (value && typeof value === "object" && !Object.keys(value).length) {
1019
+ delete params[slot];
1020
+ }
1021
+ }
1022
+ };
1023
+ var buildClientParams = (args, fields) => {
1024
+ const params = {
1025
+ body: {},
1026
+ headers: {},
1027
+ path: {},
1028
+ query: {}
1029
+ };
1030
+ const map = buildKeyMap(fields);
1031
+ let config;
1032
+ for (const [index, arg] of args.entries()) {
1033
+ if (fields[index]) {
1034
+ config = fields[index];
1035
+ }
1036
+ if (!config) {
1037
+ continue;
1038
+ }
1039
+ if ("in" in config) {
1040
+ if (config.key) {
1041
+ const field = map.get(config.key);
1042
+ const name = field.map || config.key;
1043
+ if (field.in) {
1044
+ ;
1045
+ params[field.in][name] = arg;
1046
+ }
1047
+ } else {
1048
+ params.body = arg;
1049
+ }
1050
+ } else {
1051
+ for (const [key, value] of Object.entries(arg ?? {})) {
1052
+ const field = map.get(key);
1053
+ if (field) {
1054
+ if (field.in) {
1055
+ const name = field.map || key;
1056
+ params[field.in][name] = value;
1057
+ } else {
1058
+ params[field.map] = value;
1059
+ }
1060
+ } else {
1061
+ const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
1062
+ if (extra) {
1063
+ const [prefix, slot] = extra;
1064
+ params[slot][key.slice(prefix.length)] = value;
1065
+ } else if ("allowExtra" in config && config.allowExtra) {
1066
+ for (const [slot, allowed] of Object.entries(config.allowExtra)) {
1067
+ if (allowed) {
1068
+ ;
1069
+ params[slot][key] = value;
1070
+ break;
1071
+ }
1072
+ }
1073
+ }
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ stripEmptySlots(params);
1079
+ return params;
1080
+ };
1081
+
1082
+ // packages/sdk/src/v2/gen/client.gen.ts
1083
+ var client = createClient(createConfig({ baseUrl: "http://localhost:4096" }));
1084
+
1085
+ // packages/sdk/src/v2/gen/sdk.gen.ts
1086
+ var HeyApiClient = class {
1087
+ client;
1088
+ constructor(args) {
1089
+ this.client = args?.client ?? client;
1090
+ }
1091
+ };
1092
+ var HeyApiRegistry = class {
1093
+ defaultKey = "default";
1094
+ instances = /* @__PURE__ */ new Map();
1095
+ get(key) {
1096
+ const instance = this.instances.get(key ?? this.defaultKey);
1097
+ if (!instance) {
1098
+ throw new Error(`No SDK client found. Create one with "new OpencodeClient()" to fix this error.`);
1099
+ }
1100
+ return instance;
1101
+ }
1102
+ set(value, key) {
1103
+ this.instances.set(key ?? this.defaultKey, value);
1104
+ }
1105
+ };
1106
+ var SyncEvent = class extends HeyApiClient {
1107
+ /**
1108
+ * Subscribe to global sync events
1109
+ *
1110
+ * Get global sync events
1111
+ */
1112
+ subscribe(options) {
1113
+ return (options?.client ?? this.client).sse.get({
1114
+ url: "/global/sync-event",
1115
+ ...options
1116
+ });
1117
+ }
1118
+ };
1119
+ var Config = class extends HeyApiClient {
1120
+ /**
1121
+ * Get global configuration
1122
+ *
1123
+ * Retrieve the current global OpenCode configuration settings and preferences.
1124
+ */
1125
+ get(options) {
1126
+ return (options?.client ?? this.client).get({
1127
+ url: "/global/config",
1128
+ ...options
1129
+ });
1130
+ }
1131
+ /**
1132
+ * Update global configuration
1133
+ *
1134
+ * Update global OpenCode configuration settings and preferences.
1135
+ */
1136
+ update(parameters, options) {
1137
+ const params = buildClientParams([parameters], [{ args: [{ key: "config", map: "body" }] }]);
1138
+ return (options?.client ?? this.client).patch({
1139
+ url: "/global/config",
1140
+ ...options,
1141
+ ...params,
1142
+ headers: {
1143
+ "Content-Type": "application/json",
1144
+ ...options?.headers,
1145
+ ...params.headers
1146
+ }
1147
+ });
1148
+ }
1149
+ };
1150
+ var Global = class extends HeyApiClient {
1151
+ /**
1152
+ * Get health
1153
+ *
1154
+ * Get health information about the OpenCode server.
1155
+ */
1156
+ health(options) {
1157
+ return (options?.client ?? this.client).get({
1158
+ url: "/global/health",
1159
+ ...options
1160
+ });
1161
+ }
1162
+ /**
1163
+ * Get global events
1164
+ *
1165
+ * Subscribe to global events from the OpenCode system using server-sent events.
1166
+ */
1167
+ event(options) {
1168
+ return (options?.client ?? this.client).sse.get({
1169
+ url: "/global/event",
1170
+ ...options
1171
+ });
1172
+ }
1173
+ /**
1174
+ * Dispose instance
1175
+ *
1176
+ * Clean up and dispose all OpenCode instances, releasing all resources.
1177
+ */
1178
+ dispose(options) {
1179
+ return (options?.client ?? this.client).post({
1180
+ url: "/global/dispose",
1181
+ ...options
1182
+ });
1183
+ }
1184
+ /**
1185
+ * Upgrade opencode
1186
+ *
1187
+ * Upgrade opencode to the specified version or latest if not specified.
1188
+ */
1189
+ upgrade(parameters, options) {
1190
+ const params = buildClientParams([parameters], [{ args: [{ in: "body", key: "target" }] }]);
1191
+ return (options?.client ?? this.client).post({
1192
+ url: "/global/upgrade",
1193
+ ...options,
1194
+ ...params,
1195
+ headers: {
1196
+ "Content-Type": "application/json",
1197
+ ...options?.headers,
1198
+ ...params.headers
1199
+ }
1200
+ });
1201
+ }
1202
+ _syncEvent;
1203
+ get syncEvent() {
1204
+ return this._syncEvent ??= new SyncEvent({ client: this.client });
1205
+ }
1206
+ _config;
1207
+ get config() {
1208
+ return this._config ??= new Config({ client: this.client });
1209
+ }
1210
+ };
1211
+ var Auth = class extends HeyApiClient {
1212
+ /**
1213
+ * Remove auth credentials
1214
+ *
1215
+ * Remove authentication credentials
1216
+ */
1217
+ remove(parameters, options) {
1218
+ const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "providerID" }] }]);
1219
+ return (options?.client ?? this.client).delete({
1220
+ url: "/auth/{providerID}",
1221
+ ...options,
1222
+ ...params
1223
+ });
1224
+ }
1225
+ /**
1226
+ * Set auth credentials
1227
+ *
1228
+ * Set authentication credentials
1229
+ */
1230
+ set(parameters, options) {
1231
+ const params = buildClientParams(
1232
+ [parameters],
1233
+ [
1234
+ {
1235
+ args: [
1236
+ { in: "path", key: "providerID" },
1237
+ { key: "auth", map: "body" }
1238
+ ]
1239
+ }
1240
+ ]
1241
+ );
1242
+ return (options?.client ?? this.client).put({
1243
+ url: "/auth/{providerID}",
1244
+ ...options,
1245
+ ...params,
1246
+ headers: {
1247
+ "Content-Type": "application/json",
1248
+ ...options?.headers,
1249
+ ...params.headers
1250
+ }
1251
+ });
1252
+ }
1253
+ };
1254
+ var App = class extends HeyApiClient {
1255
+ /**
1256
+ * Write log
1257
+ *
1258
+ * Write a log entry to the server logs with specified level and metadata.
1259
+ */
1260
+ log(parameters, options) {
1261
+ const params = buildClientParams(
1262
+ [parameters],
1263
+ [
1264
+ {
1265
+ args: [
1266
+ { in: "query", key: "directory" },
1267
+ { in: "query", key: "workspace" },
1268
+ { in: "body", key: "service" },
1269
+ { in: "body", key: "level" },
1270
+ { in: "body", key: "message" },
1271
+ { in: "body", key: "extra" }
1272
+ ]
1273
+ }
1274
+ ]
1275
+ );
1276
+ return (options?.client ?? this.client).post({
1277
+ url: "/log",
1278
+ ...options,
1279
+ ...params,
1280
+ headers: {
1281
+ "Content-Type": "application/json",
1282
+ ...options?.headers,
1283
+ ...params.headers
1284
+ }
1285
+ });
1286
+ }
1287
+ /**
1288
+ * List agents
1289
+ *
1290
+ * Get a list of all available AI agents in the OpenCode system.
1291
+ */
1292
+ agents(parameters, options) {
1293
+ const params = buildClientParams(
1294
+ [parameters],
1295
+ [
1296
+ {
1297
+ args: [
1298
+ { in: "query", key: "directory" },
1299
+ { in: "query", key: "workspace" }
1300
+ ]
1301
+ }
1302
+ ]
1303
+ );
1304
+ return (options?.client ?? this.client).get({
1305
+ url: "/agent",
1306
+ ...options,
1307
+ ...params
1308
+ });
1309
+ }
1310
+ /**
1311
+ * List skills
1312
+ *
1313
+ * Get a list of all available skills in the OpenCode system.
1314
+ */
1315
+ skills(parameters, options) {
1316
+ const params = buildClientParams(
1317
+ [parameters],
1318
+ [
1319
+ {
1320
+ args: [
1321
+ { in: "query", key: "directory" },
1322
+ { in: "query", key: "workspace" }
1323
+ ]
1324
+ }
1325
+ ]
1326
+ );
1327
+ return (options?.client ?? this.client).get({
1328
+ url: "/skill",
1329
+ ...options,
1330
+ ...params
1331
+ });
1332
+ }
1333
+ };
1334
+ var Project = class extends HeyApiClient {
1335
+ /**
1336
+ * List all projects
1337
+ *
1338
+ * Get a list of projects that have been opened with OpenCode.
1339
+ */
1340
+ list(parameters, options) {
1341
+ const params = buildClientParams(
1342
+ [parameters],
1343
+ [
1344
+ {
1345
+ args: [
1346
+ { in: "query", key: "directory" },
1347
+ { in: "query", key: "workspace" }
1348
+ ]
1349
+ }
1350
+ ]
1351
+ );
1352
+ return (options?.client ?? this.client).get({
1353
+ url: "/project",
1354
+ ...options,
1355
+ ...params
1356
+ });
1357
+ }
1358
+ /**
1359
+ * Get current project
1360
+ *
1361
+ * Retrieve the currently active project that OpenCode is working with.
1362
+ */
1363
+ current(parameters, options) {
1364
+ const params = buildClientParams(
1365
+ [parameters],
1366
+ [
1367
+ {
1368
+ args: [
1369
+ { in: "query", key: "directory" },
1370
+ { in: "query", key: "workspace" }
1371
+ ]
1372
+ }
1373
+ ]
1374
+ );
1375
+ return (options?.client ?? this.client).get({
1376
+ url: "/project/current",
1377
+ ...options,
1378
+ ...params
1379
+ });
1380
+ }
1381
+ /**
1382
+ * Initialize git repository
1383
+ *
1384
+ * Create a git repository for the current project and return the refreshed project info.
1385
+ */
1386
+ initGit(parameters, options) {
1387
+ const params = buildClientParams(
1388
+ [parameters],
1389
+ [
1390
+ {
1391
+ args: [
1392
+ { in: "query", key: "directory" },
1393
+ { in: "query", key: "workspace" }
1394
+ ]
1395
+ }
1396
+ ]
1397
+ );
1398
+ return (options?.client ?? this.client).post({
1399
+ url: "/project/git/init",
1400
+ ...options,
1401
+ ...params
1402
+ });
1403
+ }
1404
+ /**
1405
+ * Update project
1406
+ *
1407
+ * Update project properties such as name, icon, and commands.
1408
+ */
1409
+ update(parameters, options) {
1410
+ const params = buildClientParams(
1411
+ [parameters],
1412
+ [
1413
+ {
1414
+ args: [
1415
+ { in: "path", key: "projectID" },
1416
+ { in: "query", key: "directory" },
1417
+ { in: "query", key: "workspace" },
1418
+ { in: "body", key: "name" },
1419
+ { in: "body", key: "icon" },
1420
+ { in: "body", key: "commands" }
1421
+ ]
1422
+ }
1423
+ ]
1424
+ );
1425
+ return (options?.client ?? this.client).patch({
1426
+ url: "/project/{projectID}",
1427
+ ...options,
1428
+ ...params,
1429
+ headers: {
1430
+ "Content-Type": "application/json",
1431
+ ...options?.headers,
1432
+ ...params.headers
1433
+ }
1434
+ });
1435
+ }
1436
+ };
1437
+ var Pty = class extends HeyApiClient {
1438
+ /**
1439
+ * List PTY sessions
1440
+ *
1441
+ * Get a list of all active pseudo-terminal (PTY) sessions managed by OpenCode.
1442
+ */
1443
+ list(parameters, options) {
1444
+ const params = buildClientParams(
1445
+ [parameters],
1446
+ [
1447
+ {
1448
+ args: [
1449
+ { in: "query", key: "directory" },
1450
+ { in: "query", key: "workspace" }
1451
+ ]
1452
+ }
1453
+ ]
1454
+ );
1455
+ return (options?.client ?? this.client).get({
1456
+ url: "/pty",
1457
+ ...options,
1458
+ ...params
1459
+ });
1460
+ }
1461
+ /**
1462
+ * Create PTY session
1463
+ *
1464
+ * Create a new pseudo-terminal (PTY) session for running shell commands and processes.
1465
+ */
1466
+ create(parameters, options) {
1467
+ const params = buildClientParams(
1468
+ [parameters],
1469
+ [
1470
+ {
1471
+ args: [
1472
+ { in: "query", key: "directory" },
1473
+ { in: "query", key: "workspace" },
1474
+ { in: "body", key: "command" },
1475
+ { in: "body", key: "args" },
1476
+ { in: "body", key: "cwd" },
1477
+ { in: "body", key: "title" },
1478
+ { in: "body", key: "env" }
1479
+ ]
1480
+ }
1481
+ ]
1482
+ );
1483
+ return (options?.client ?? this.client).post({
1484
+ url: "/pty",
1485
+ ...options,
1486
+ ...params,
1487
+ headers: {
1488
+ "Content-Type": "application/json",
1489
+ ...options?.headers,
1490
+ ...params.headers
1491
+ }
1492
+ });
1493
+ }
1494
+ /**
1495
+ * Remove PTY session
1496
+ *
1497
+ * Remove and terminate a specific pseudo-terminal (PTY) session.
1498
+ */
1499
+ remove(parameters, options) {
1500
+ const params = buildClientParams(
1501
+ [parameters],
1502
+ [
1503
+ {
1504
+ args: [
1505
+ { in: "path", key: "ptyID" },
1506
+ { in: "query", key: "directory" },
1507
+ { in: "query", key: "workspace" }
1508
+ ]
1509
+ }
1510
+ ]
1511
+ );
1512
+ return (options?.client ?? this.client).delete({
1513
+ url: "/pty/{ptyID}",
1514
+ ...options,
1515
+ ...params
1516
+ });
1517
+ }
1518
+ /**
1519
+ * Get PTY session
1520
+ *
1521
+ * Retrieve detailed information about a specific pseudo-terminal (PTY) session.
1522
+ */
1523
+ get(parameters, options) {
1524
+ const params = buildClientParams(
1525
+ [parameters],
1526
+ [
1527
+ {
1528
+ args: [
1529
+ { in: "path", key: "ptyID" },
1530
+ { in: "query", key: "directory" },
1531
+ { in: "query", key: "workspace" }
1532
+ ]
1533
+ }
1534
+ ]
1535
+ );
1536
+ return (options?.client ?? this.client).get({
1537
+ url: "/pty/{ptyID}",
1538
+ ...options,
1539
+ ...params
1540
+ });
1541
+ }
1542
+ /**
1543
+ * Update PTY session
1544
+ *
1545
+ * Update properties of an existing pseudo-terminal (PTY) session.
1546
+ */
1547
+ update(parameters, options) {
1548
+ const params = buildClientParams(
1549
+ [parameters],
1550
+ [
1551
+ {
1552
+ args: [
1553
+ { in: "path", key: "ptyID" },
1554
+ { in: "query", key: "directory" },
1555
+ { in: "query", key: "workspace" },
1556
+ { in: "body", key: "title" },
1557
+ { in: "body", key: "size" }
1558
+ ]
1559
+ }
1560
+ ]
1561
+ );
1562
+ return (options?.client ?? this.client).put({
1563
+ url: "/pty/{ptyID}",
1564
+ ...options,
1565
+ ...params,
1566
+ headers: {
1567
+ "Content-Type": "application/json",
1568
+ ...options?.headers,
1569
+ ...params.headers
1570
+ }
1571
+ });
1572
+ }
1573
+ /**
1574
+ * Connect to PTY session
1575
+ *
1576
+ * Establish a WebSocket connection to interact with a pseudo-terminal (PTY) session in real-time.
1577
+ */
1578
+ connect(parameters, options) {
1579
+ const params = buildClientParams(
1580
+ [parameters],
1581
+ [
1582
+ {
1583
+ args: [
1584
+ { in: "path", key: "ptyID" },
1585
+ { in: "query", key: "directory" },
1586
+ { in: "query", key: "workspace" }
1587
+ ]
1588
+ }
1589
+ ]
1590
+ );
1591
+ return (options?.client ?? this.client).get({
1592
+ url: "/pty/{ptyID}/connect",
1593
+ ...options,
1594
+ ...params
1595
+ });
1596
+ }
1597
+ };
1598
+ var Config2 = class extends HeyApiClient {
1599
+ /**
1600
+ * Get configuration
1601
+ *
1602
+ * Retrieve the current OpenCode configuration settings and preferences.
1603
+ */
1604
+ get(parameters, options) {
1605
+ const params = buildClientParams(
1606
+ [parameters],
1607
+ [
1608
+ {
1609
+ args: [
1610
+ { in: "query", key: "directory" },
1611
+ { in: "query", key: "workspace" }
1612
+ ]
1613
+ }
1614
+ ]
1615
+ );
1616
+ return (options?.client ?? this.client).get({
1617
+ url: "/config",
1618
+ ...options,
1619
+ ...params
1620
+ });
1621
+ }
1622
+ /**
1623
+ * Update configuration
1624
+ *
1625
+ * Update OpenCode configuration settings and preferences.
1626
+ */
1627
+ update(parameters, options) {
1628
+ const params = buildClientParams(
1629
+ [parameters],
1630
+ [
1631
+ {
1632
+ args: [
1633
+ { in: "query", key: "directory" },
1634
+ { in: "query", key: "workspace" },
1635
+ { key: "config", map: "body" }
1636
+ ]
1637
+ }
1638
+ ]
1639
+ );
1640
+ return (options?.client ?? this.client).patch({
1641
+ url: "/config",
1642
+ ...options,
1643
+ ...params,
1644
+ headers: {
1645
+ "Content-Type": "application/json",
1646
+ ...options?.headers,
1647
+ ...params.headers
1648
+ }
1649
+ });
1650
+ }
1651
+ /**
1652
+ * List config providers
1653
+ *
1654
+ * Get a list of all configured AI providers and their default models.
1655
+ */
1656
+ providers(parameters, options) {
1657
+ const params = buildClientParams(
1658
+ [parameters],
1659
+ [
1660
+ {
1661
+ args: [
1662
+ { in: "query", key: "directory" },
1663
+ { in: "query", key: "workspace" }
1664
+ ]
1665
+ }
1666
+ ]
1667
+ );
1668
+ return (options?.client ?? this.client).get({
1669
+ url: "/config/providers",
1670
+ ...options,
1671
+ ...params
1672
+ });
1673
+ }
1674
+ };
1675
+ var Console = class extends HeyApiClient {
1676
+ /**
1677
+ * Get active Console provider metadata
1678
+ *
1679
+ * Get the active Console org name and the set of provider IDs managed by that Console org.
1680
+ */
1681
+ get(parameters, options) {
1682
+ const params = buildClientParams(
1683
+ [parameters],
1684
+ [
1685
+ {
1686
+ args: [
1687
+ { in: "query", key: "directory" },
1688
+ { in: "query", key: "workspace" }
1689
+ ]
1690
+ }
1691
+ ]
1692
+ );
1693
+ return (options?.client ?? this.client).get({
1694
+ url: "/experimental/console",
1695
+ ...options,
1696
+ ...params
1697
+ });
1698
+ }
1699
+ /**
1700
+ * List switchable Console orgs
1701
+ *
1702
+ * Get the available Console orgs across logged-in accounts, including the current active org.
1703
+ */
1704
+ listOrgs(parameters, options) {
1705
+ const params = buildClientParams(
1706
+ [parameters],
1707
+ [
1708
+ {
1709
+ args: [
1710
+ { in: "query", key: "directory" },
1711
+ { in: "query", key: "workspace" }
1712
+ ]
1713
+ }
1714
+ ]
1715
+ );
1716
+ return (options?.client ?? this.client).get({
1717
+ url: "/experimental/console/orgs",
1718
+ ...options,
1719
+ ...params
1720
+ });
1721
+ }
1722
+ /**
1723
+ * Switch active Console org
1724
+ *
1725
+ * Persist a new active Console account/org selection for the current local OpenCode state.
1726
+ */
1727
+ switchOrg(parameters, options) {
1728
+ const params = buildClientParams(
1729
+ [parameters],
1730
+ [
1731
+ {
1732
+ args: [
1733
+ { in: "query", key: "directory" },
1734
+ { in: "query", key: "workspace" },
1735
+ { in: "body", key: "accountID" },
1736
+ { in: "body", key: "orgID" }
1737
+ ]
1738
+ }
1739
+ ]
1740
+ );
1741
+ return (options?.client ?? this.client).post({
1742
+ url: "/experimental/console/switch",
1743
+ ...options,
1744
+ ...params,
1745
+ headers: {
1746
+ "Content-Type": "application/json",
1747
+ ...options?.headers,
1748
+ ...params.headers
1749
+ }
1750
+ });
1751
+ }
1752
+ };
1753
+ var Workspace = class extends HeyApiClient {
1754
+ /**
1755
+ * List workspaces
1756
+ *
1757
+ * List all workspaces.
1758
+ */
1759
+ list(parameters, options) {
1760
+ const params = buildClientParams(
1761
+ [parameters],
1762
+ [
1763
+ {
1764
+ args: [
1765
+ { in: "query", key: "directory" },
1766
+ { in: "query", key: "workspace" }
1767
+ ]
1768
+ }
1769
+ ]
1770
+ );
1771
+ return (options?.client ?? this.client).get({
1772
+ url: "/experimental/workspace",
1773
+ ...options,
1774
+ ...params
1775
+ });
1776
+ }
1777
+ /**
1778
+ * Create workspace
1779
+ *
1780
+ * Create a workspace for the current project.
1781
+ */
1782
+ create(parameters, options) {
1783
+ const params = buildClientParams(
1784
+ [parameters],
1785
+ [
1786
+ {
1787
+ args: [
1788
+ { in: "query", key: "directory" },
1789
+ { in: "query", key: "workspace" },
1790
+ { in: "body", key: "id" },
1791
+ { in: "body", key: "type" },
1792
+ { in: "body", key: "branch" },
1793
+ { in: "body", key: "extra" }
1794
+ ]
1795
+ }
1796
+ ]
1797
+ );
1798
+ return (options?.client ?? this.client).post({
1799
+ url: "/experimental/workspace",
1800
+ ...options,
1801
+ ...params,
1802
+ headers: {
1803
+ "Content-Type": "application/json",
1804
+ ...options?.headers,
1805
+ ...params.headers
1806
+ }
1807
+ });
1808
+ }
1809
+ /**
1810
+ * Remove workspace
1811
+ *
1812
+ * Remove an existing workspace.
1813
+ */
1814
+ remove(parameters, options) {
1815
+ const params = buildClientParams(
1816
+ [parameters],
1817
+ [
1818
+ {
1819
+ args: [
1820
+ { in: "path", key: "id" },
1821
+ { in: "query", key: "directory" },
1822
+ { in: "query", key: "workspace" }
1823
+ ]
1824
+ }
1825
+ ]
1826
+ );
1827
+ return (options?.client ?? this.client).delete({
1828
+ url: "/experimental/workspace/{id}",
1829
+ ...options,
1830
+ ...params
1831
+ });
1832
+ }
1833
+ };
1834
+ var Session = class extends HeyApiClient {
1835
+ /**
1836
+ * List sessions
1837
+ *
1838
+ * Get a list of all OpenCode sessions across projects, sorted by most recently updated. Archived sessions are excluded by default.
1839
+ */
1840
+ list(parameters, options) {
1841
+ const params = buildClientParams(
1842
+ [parameters],
1843
+ [
1844
+ {
1845
+ args: [
1846
+ { in: "query", key: "directory" },
1847
+ { in: "query", key: "workspace" },
1848
+ { in: "query", key: "roots" },
1849
+ { in: "query", key: "start" },
1850
+ { in: "query", key: "cursor" },
1851
+ { in: "query", key: "search" },
1852
+ { in: "query", key: "limit" },
1853
+ { in: "query", key: "archived" }
1854
+ ]
1855
+ }
1856
+ ]
1857
+ );
1858
+ return (options?.client ?? this.client).get({
1859
+ url: "/experimental/session",
1860
+ ...options,
1861
+ ...params
1862
+ });
1863
+ }
1864
+ };
1865
+ var Resource = class extends HeyApiClient {
1866
+ /**
1867
+ * Get MCP resources
1868
+ *
1869
+ * Get all available MCP resources from connected servers. Optionally filter by name.
1870
+ */
1871
+ list(parameters, options) {
1872
+ const params = buildClientParams(
1873
+ [parameters],
1874
+ [
1875
+ {
1876
+ args: [
1877
+ { in: "query", key: "directory" },
1878
+ { in: "query", key: "workspace" }
1879
+ ]
1880
+ }
1881
+ ]
1882
+ );
1883
+ return (options?.client ?? this.client).get({
1884
+ url: "/experimental/resource",
1885
+ ...options,
1886
+ ...params
1887
+ });
1888
+ }
1889
+ };
1890
+ var Experimental = class extends HeyApiClient {
1891
+ _console;
1892
+ get console() {
1893
+ return this._console ??= new Console({ client: this.client });
1894
+ }
1895
+ _workspace;
1896
+ get workspace() {
1897
+ return this._workspace ??= new Workspace({ client: this.client });
1898
+ }
1899
+ _session;
1900
+ get session() {
1901
+ return this._session ??= new Session({ client: this.client });
1902
+ }
1903
+ _resource;
1904
+ get resource() {
1905
+ return this._resource ??= new Resource({ client: this.client });
1906
+ }
1907
+ };
1908
+ var Tool = class extends HeyApiClient {
1909
+ /**
1910
+ * List tool IDs
1911
+ *
1912
+ * Get a list of all available tool IDs, including both built-in tools and dynamically registered tools.
1913
+ */
1914
+ ids(parameters, options) {
1915
+ const params = buildClientParams(
1916
+ [parameters],
1917
+ [
1918
+ {
1919
+ args: [
1920
+ { in: "query", key: "directory" },
1921
+ { in: "query", key: "workspace" }
1922
+ ]
1923
+ }
1924
+ ]
1925
+ );
1926
+ return (options?.client ?? this.client).get({
1927
+ url: "/experimental/tool/ids",
1928
+ ...options,
1929
+ ...params
1930
+ });
1931
+ }
1932
+ /**
1933
+ * List tools
1934
+ *
1935
+ * Get a list of available tools with their JSON schema parameters for a specific provider and model combination.
1936
+ */
1937
+ list(parameters, options) {
1938
+ const params = buildClientParams(
1939
+ [parameters],
1940
+ [
1941
+ {
1942
+ args: [
1943
+ { in: "query", key: "directory" },
1944
+ { in: "query", key: "workspace" },
1945
+ { in: "query", key: "provider" },
1946
+ { in: "query", key: "model" }
1947
+ ]
1948
+ }
1949
+ ]
1950
+ );
1951
+ return (options?.client ?? this.client).get({
1952
+ url: "/experimental/tool",
1953
+ ...options,
1954
+ ...params
1955
+ });
1956
+ }
1957
+ };
1958
+ var Worktree = class extends HeyApiClient {
1959
+ /**
1960
+ * Remove worktree
1961
+ *
1962
+ * Remove a git worktree and delete its branch.
1963
+ */
1964
+ remove(parameters, options) {
1965
+ const params = buildClientParams(
1966
+ [parameters],
1967
+ [
1968
+ {
1969
+ args: [
1970
+ { in: "query", key: "directory" },
1971
+ { in: "query", key: "workspace" },
1972
+ { key: "worktreeRemoveInput", map: "body" }
1973
+ ]
1974
+ }
1975
+ ]
1976
+ );
1977
+ return (options?.client ?? this.client).delete({
1978
+ url: "/experimental/worktree",
1979
+ ...options,
1980
+ ...params,
1981
+ headers: {
1982
+ "Content-Type": "application/json",
1983
+ ...options?.headers,
1984
+ ...params.headers
1985
+ }
1986
+ });
1987
+ }
1988
+ /**
1989
+ * List worktrees
1990
+ *
1991
+ * List all sandbox worktrees for the current project.
1992
+ */
1993
+ list(parameters, options) {
1994
+ const params = buildClientParams(
1995
+ [parameters],
1996
+ [
1997
+ {
1998
+ args: [
1999
+ { in: "query", key: "directory" },
2000
+ { in: "query", key: "workspace" }
2001
+ ]
2002
+ }
2003
+ ]
2004
+ );
2005
+ return (options?.client ?? this.client).get({
2006
+ url: "/experimental/worktree",
2007
+ ...options,
2008
+ ...params
2009
+ });
2010
+ }
2011
+ /**
2012
+ * Create worktree
2013
+ *
2014
+ * Create a new git worktree for the current project and run any configured startup scripts.
2015
+ */
2016
+ create(parameters, options) {
2017
+ const params = buildClientParams(
2018
+ [parameters],
2019
+ [
2020
+ {
2021
+ args: [
2022
+ { in: "query", key: "directory" },
2023
+ { in: "query", key: "workspace" },
2024
+ { key: "worktreeCreateInput", map: "body" }
2025
+ ]
2026
+ }
2027
+ ]
2028
+ );
2029
+ return (options?.client ?? this.client).post({
2030
+ url: "/experimental/worktree",
2031
+ ...options,
2032
+ ...params,
2033
+ headers: {
2034
+ "Content-Type": "application/json",
2035
+ ...options?.headers,
2036
+ ...params.headers
2037
+ }
2038
+ });
2039
+ }
2040
+ /**
2041
+ * Reset worktree
2042
+ *
2043
+ * Reset a worktree branch to the primary default branch.
2044
+ */
2045
+ reset(parameters, options) {
2046
+ const params = buildClientParams(
2047
+ [parameters],
2048
+ [
2049
+ {
2050
+ args: [
2051
+ { in: "query", key: "directory" },
2052
+ { in: "query", key: "workspace" },
2053
+ { key: "worktreeResetInput", map: "body" }
2054
+ ]
2055
+ }
2056
+ ]
2057
+ );
2058
+ return (options?.client ?? this.client).post({
2059
+ url: "/experimental/worktree/reset",
2060
+ ...options,
2061
+ ...params,
2062
+ headers: {
2063
+ "Content-Type": "application/json",
2064
+ ...options?.headers,
2065
+ ...params.headers
2066
+ }
2067
+ });
2068
+ }
2069
+ };
2070
+ var Session2 = class extends HeyApiClient {
2071
+ /**
2072
+ * List sessions
2073
+ *
2074
+ * Get a list of all OpenCode sessions, sorted by most recently updated.
2075
+ */
2076
+ list(parameters, options) {
2077
+ const params = buildClientParams(
2078
+ [parameters],
2079
+ [
2080
+ {
2081
+ args: [
2082
+ { in: "query", key: "directory" },
2083
+ { in: "query", key: "workspace" },
2084
+ { in: "query", key: "roots" },
2085
+ { in: "query", key: "start" },
2086
+ { in: "query", key: "search" },
2087
+ { in: "query", key: "limit" }
2088
+ ]
2089
+ }
2090
+ ]
2091
+ );
2092
+ return (options?.client ?? this.client).get({
2093
+ url: "/session",
2094
+ ...options,
2095
+ ...params
2096
+ });
2097
+ }
2098
+ /**
2099
+ * Create session
2100
+ *
2101
+ * Create a new OpenCode session for interacting with AI assistants and managing conversations.
2102
+ */
2103
+ create(parameters, options) {
2104
+ const params = buildClientParams(
2105
+ [parameters],
2106
+ [
2107
+ {
2108
+ args: [
2109
+ { in: "query", key: "directory" },
2110
+ { in: "query", key: "workspace" },
2111
+ { in: "body", key: "parentID" },
2112
+ { in: "body", key: "title" },
2113
+ { in: "body", key: "permission" },
2114
+ { in: "body", key: "workspaceID" }
2115
+ ]
2116
+ }
2117
+ ]
2118
+ );
2119
+ return (options?.client ?? this.client).post({
2120
+ url: "/session",
2121
+ ...options,
2122
+ ...params,
2123
+ headers: {
2124
+ "Content-Type": "application/json",
2125
+ ...options?.headers,
2126
+ ...params.headers
2127
+ }
2128
+ });
2129
+ }
2130
+ /**
2131
+ * Get session status
2132
+ *
2133
+ * Retrieve the current status of all sessions, including active, idle, and completed states.
2134
+ */
2135
+ status(parameters, options) {
2136
+ const params = buildClientParams(
2137
+ [parameters],
2138
+ [
2139
+ {
2140
+ args: [
2141
+ { in: "query", key: "directory" },
2142
+ { in: "query", key: "workspace" }
2143
+ ]
2144
+ }
2145
+ ]
2146
+ );
2147
+ return (options?.client ?? this.client).get({
2148
+ url: "/session/status",
2149
+ ...options,
2150
+ ...params
2151
+ });
2152
+ }
2153
+ /**
2154
+ * Delete session
2155
+ *
2156
+ * Delete a session and permanently remove all associated data, including messages and history.
2157
+ */
2158
+ delete(parameters, options) {
2159
+ const params = buildClientParams(
2160
+ [parameters],
2161
+ [
2162
+ {
2163
+ args: [
2164
+ { in: "path", key: "sessionID" },
2165
+ { in: "query", key: "directory" },
2166
+ { in: "query", key: "workspace" }
2167
+ ]
2168
+ }
2169
+ ]
2170
+ );
2171
+ return (options?.client ?? this.client).delete({
2172
+ url: "/session/{sessionID}",
2173
+ ...options,
2174
+ ...params
2175
+ });
2176
+ }
2177
+ /**
2178
+ * Get session
2179
+ *
2180
+ * Retrieve detailed information about a specific OpenCode session.
2181
+ */
2182
+ get(parameters, options) {
2183
+ const params = buildClientParams(
2184
+ [parameters],
2185
+ [
2186
+ {
2187
+ args: [
2188
+ { in: "path", key: "sessionID" },
2189
+ { in: "query", key: "directory" },
2190
+ { in: "query", key: "workspace" }
2191
+ ]
2192
+ }
2193
+ ]
2194
+ );
2195
+ return (options?.client ?? this.client).get({
2196
+ url: "/session/{sessionID}",
2197
+ ...options,
2198
+ ...params
2199
+ });
2200
+ }
2201
+ /**
2202
+ * Update session
2203
+ *
2204
+ * Update properties of an existing session, such as title or other metadata.
2205
+ */
2206
+ update(parameters, options) {
2207
+ const params = buildClientParams(
2208
+ [parameters],
2209
+ [
2210
+ {
2211
+ args: [
2212
+ { in: "path", key: "sessionID" },
2213
+ { in: "query", key: "directory" },
2214
+ { in: "query", key: "workspace" },
2215
+ { in: "body", key: "title" },
2216
+ { in: "body", key: "time" }
2217
+ ]
2218
+ }
2219
+ ]
2220
+ );
2221
+ return (options?.client ?? this.client).patch({
2222
+ url: "/session/{sessionID}",
2223
+ ...options,
2224
+ ...params,
2225
+ headers: {
2226
+ "Content-Type": "application/json",
2227
+ ...options?.headers,
2228
+ ...params.headers
2229
+ }
2230
+ });
2231
+ }
2232
+ /**
2233
+ * Get session children
2234
+ *
2235
+ * Retrieve all child sessions that were forked from the specified parent session.
2236
+ */
2237
+ children(parameters, options) {
2238
+ const params = buildClientParams(
2239
+ [parameters],
2240
+ [
2241
+ {
2242
+ args: [
2243
+ { in: "path", key: "sessionID" },
2244
+ { in: "query", key: "directory" },
2245
+ { in: "query", key: "workspace" }
2246
+ ]
2247
+ }
2248
+ ]
2249
+ );
2250
+ return (options?.client ?? this.client).get({
2251
+ url: "/session/{sessionID}/children",
2252
+ ...options,
2253
+ ...params
2254
+ });
2255
+ }
2256
+ /**
2257
+ * Get session todos
2258
+ *
2259
+ * Retrieve the todo list associated with a specific session, showing tasks and action items.
2260
+ */
2261
+ todo(parameters, options) {
2262
+ const params = buildClientParams(
2263
+ [parameters],
2264
+ [
2265
+ {
2266
+ args: [
2267
+ { in: "path", key: "sessionID" },
2268
+ { in: "query", key: "directory" },
2269
+ { in: "query", key: "workspace" }
2270
+ ]
2271
+ }
2272
+ ]
2273
+ );
2274
+ return (options?.client ?? this.client).get({
2275
+ url: "/session/{sessionID}/todo",
2276
+ ...options,
2277
+ ...params
2278
+ });
2279
+ }
2280
+ /**
2281
+ * Initialize session
2282
+ *
2283
+ * Analyze the current application and create an AGENTS.md file with project-specific agent configurations.
2284
+ */
2285
+ init(parameters, options) {
2286
+ const params = buildClientParams(
2287
+ [parameters],
2288
+ [
2289
+ {
2290
+ args: [
2291
+ { in: "path", key: "sessionID" },
2292
+ { in: "query", key: "directory" },
2293
+ { in: "query", key: "workspace" },
2294
+ { in: "body", key: "modelID" },
2295
+ { in: "body", key: "providerID" },
2296
+ { in: "body", key: "messageID" }
2297
+ ]
2298
+ }
2299
+ ]
2300
+ );
2301
+ return (options?.client ?? this.client).post({
2302
+ url: "/session/{sessionID}/init",
2303
+ ...options,
2304
+ ...params,
2305
+ headers: {
2306
+ "Content-Type": "application/json",
2307
+ ...options?.headers,
2308
+ ...params.headers
2309
+ }
2310
+ });
2311
+ }
2312
+ /**
2313
+ * Fork session
2314
+ *
2315
+ * Create a new session by forking an existing session at a specific message point.
2316
+ */
2317
+ fork(parameters, options) {
2318
+ const params = buildClientParams(
2319
+ [parameters],
2320
+ [
2321
+ {
2322
+ args: [
2323
+ { in: "path", key: "sessionID" },
2324
+ { in: "query", key: "directory" },
2325
+ { in: "query", key: "workspace" },
2326
+ { in: "body", key: "messageID" }
2327
+ ]
2328
+ }
2329
+ ]
2330
+ );
2331
+ return (options?.client ?? this.client).post({
2332
+ url: "/session/{sessionID}/fork",
2333
+ ...options,
2334
+ ...params,
2335
+ headers: {
2336
+ "Content-Type": "application/json",
2337
+ ...options?.headers,
2338
+ ...params.headers
2339
+ }
2340
+ });
2341
+ }
2342
+ /**
2343
+ * Abort session
2344
+ *
2345
+ * Abort an active session and stop any ongoing AI processing or command execution.
2346
+ */
2347
+ abort(parameters, options) {
2348
+ const params = buildClientParams(
2349
+ [parameters],
2350
+ [
2351
+ {
2352
+ args: [
2353
+ { in: "path", key: "sessionID" },
2354
+ { in: "query", key: "directory" },
2355
+ { in: "query", key: "workspace" }
2356
+ ]
2357
+ }
2358
+ ]
2359
+ );
2360
+ return (options?.client ?? this.client).post({
2361
+ url: "/session/{sessionID}/abort",
2362
+ ...options,
2363
+ ...params
2364
+ });
2365
+ }
2366
+ /**
2367
+ * Unshare session
2368
+ *
2369
+ * Remove the shareable link for a session, making it private again.
2370
+ */
2371
+ unshare(parameters, options) {
2372
+ const params = buildClientParams(
2373
+ [parameters],
2374
+ [
2375
+ {
2376
+ args: [
2377
+ { in: "path", key: "sessionID" },
2378
+ { in: "query", key: "directory" },
2379
+ { in: "query", key: "workspace" }
2380
+ ]
2381
+ }
2382
+ ]
2383
+ );
2384
+ return (options?.client ?? this.client).delete({
2385
+ url: "/session/{sessionID}/share",
2386
+ ...options,
2387
+ ...params
2388
+ });
2389
+ }
2390
+ /**
2391
+ * Share session
2392
+ *
2393
+ * Create a shareable link for a session, allowing others to view the conversation.
2394
+ */
2395
+ share(parameters, options) {
2396
+ const params = buildClientParams(
2397
+ [parameters],
2398
+ [
2399
+ {
2400
+ args: [
2401
+ { in: "path", key: "sessionID" },
2402
+ { in: "query", key: "directory" },
2403
+ { in: "query", key: "workspace" }
2404
+ ]
2405
+ }
2406
+ ]
2407
+ );
2408
+ return (options?.client ?? this.client).post({
2409
+ url: "/session/{sessionID}/share",
2410
+ ...options,
2411
+ ...params
2412
+ });
2413
+ }
2414
+ /**
2415
+ * Get message diff
2416
+ *
2417
+ * Get the file changes (diff) that resulted from a specific user message in the session.
2418
+ */
2419
+ diff(parameters, options) {
2420
+ const params = buildClientParams(
2421
+ [parameters],
2422
+ [
2423
+ {
2424
+ args: [
2425
+ { in: "path", key: "sessionID" },
2426
+ { in: "query", key: "directory" },
2427
+ { in: "query", key: "workspace" },
2428
+ { in: "query", key: "messageID" }
2429
+ ]
2430
+ }
2431
+ ]
2432
+ );
2433
+ return (options?.client ?? this.client).get({
2434
+ url: "/session/{sessionID}/diff",
2435
+ ...options,
2436
+ ...params
2437
+ });
2438
+ }
2439
+ /**
2440
+ * Summarize session
2441
+ *
2442
+ * Generate a concise summary of the session using AI compaction to preserve key information.
2443
+ */
2444
+ summarize(parameters, options) {
2445
+ const params = buildClientParams(
2446
+ [parameters],
2447
+ [
2448
+ {
2449
+ args: [
2450
+ { in: "path", key: "sessionID" },
2451
+ { in: "query", key: "directory" },
2452
+ { in: "query", key: "workspace" },
2453
+ { in: "body", key: "providerID" },
2454
+ { in: "body", key: "modelID" },
2455
+ { in: "body", key: "auto" }
2456
+ ]
2457
+ }
2458
+ ]
2459
+ );
2460
+ return (options?.client ?? this.client).post({
2461
+ url: "/session/{sessionID}/summarize",
2462
+ ...options,
2463
+ ...params,
2464
+ headers: {
2465
+ "Content-Type": "application/json",
2466
+ ...options?.headers,
2467
+ ...params.headers
2468
+ }
2469
+ });
2470
+ }
2471
+ /**
2472
+ * Get session messages
2473
+ *
2474
+ * Retrieve all messages in a session, including user prompts and AI responses.
2475
+ */
2476
+ messages(parameters, options) {
2477
+ const params = buildClientParams(
2478
+ [parameters],
2479
+ [
2480
+ {
2481
+ args: [
2482
+ { in: "path", key: "sessionID" },
2483
+ { in: "query", key: "directory" },
2484
+ { in: "query", key: "workspace" },
2485
+ { in: "query", key: "limit" },
2486
+ { in: "query", key: "before" }
2487
+ ]
2488
+ }
2489
+ ]
2490
+ );
2491
+ return (options?.client ?? this.client).get({
2492
+ url: "/session/{sessionID}/message",
2493
+ ...options,
2494
+ ...params
2495
+ });
2496
+ }
2497
+ /**
2498
+ * Send message
2499
+ *
2500
+ * Create and send a new message to a session, streaming the AI response.
2501
+ */
2502
+ prompt(parameters, options) {
2503
+ const params = buildClientParams(
2504
+ [parameters],
2505
+ [
2506
+ {
2507
+ args: [
2508
+ { in: "path", key: "sessionID" },
2509
+ { in: "query", key: "directory" },
2510
+ { in: "query", key: "workspace" },
2511
+ { in: "body", key: "messageID" },
2512
+ { in: "body", key: "model" },
2513
+ { in: "body", key: "agent" },
2514
+ { in: "body", key: "noReply" },
2515
+ { in: "body", key: "tools" },
2516
+ { in: "body", key: "format" },
2517
+ { in: "body", key: "system" },
2518
+ { in: "body", key: "variant" },
2519
+ { in: "body", key: "parts" }
2520
+ ]
2521
+ }
2522
+ ]
2523
+ );
2524
+ return (options?.client ?? this.client).post({
2525
+ url: "/session/{sessionID}/message",
2526
+ ...options,
2527
+ ...params,
2528
+ headers: {
2529
+ "Content-Type": "application/json",
2530
+ ...options?.headers,
2531
+ ...params.headers
2532
+ }
2533
+ });
2534
+ }
2535
+ /**
2536
+ * Delete message
2537
+ *
2538
+ * Permanently delete a specific message (and all of its parts) from a session. This does not revert any file changes that may have been made while processing the message.
2539
+ */
2540
+ deleteMessage(parameters, options) {
2541
+ const params = buildClientParams(
2542
+ [parameters],
2543
+ [
2544
+ {
2545
+ args: [
2546
+ { in: "path", key: "sessionID" },
2547
+ { in: "path", key: "messageID" },
2548
+ { in: "query", key: "directory" },
2549
+ { in: "query", key: "workspace" }
2550
+ ]
2551
+ }
2552
+ ]
2553
+ );
2554
+ return (options?.client ?? this.client).delete({
2555
+ url: "/session/{sessionID}/message/{messageID}",
2556
+ ...options,
2557
+ ...params
2558
+ });
2559
+ }
2560
+ /**
2561
+ * Get message
2562
+ *
2563
+ * Retrieve a specific message from a session by its message ID.
2564
+ */
2565
+ message(parameters, options) {
2566
+ const params = buildClientParams(
2567
+ [parameters],
2568
+ [
2569
+ {
2570
+ args: [
2571
+ { in: "path", key: "sessionID" },
2572
+ { in: "path", key: "messageID" },
2573
+ { in: "query", key: "directory" },
2574
+ { in: "query", key: "workspace" }
2575
+ ]
2576
+ }
2577
+ ]
2578
+ );
2579
+ return (options?.client ?? this.client).get({
2580
+ url: "/session/{sessionID}/message/{messageID}",
2581
+ ...options,
2582
+ ...params
2583
+ });
2584
+ }
2585
+ /**
2586
+ * Send async message
2587
+ *
2588
+ * Create and send a new message to a session asynchronously, starting the session if needed and returning immediately.
2589
+ */
2590
+ promptAsync(parameters, options) {
2591
+ const params = buildClientParams(
2592
+ [parameters],
2593
+ [
2594
+ {
2595
+ args: [
2596
+ { in: "path", key: "sessionID" },
2597
+ { in: "query", key: "directory" },
2598
+ { in: "query", key: "workspace" },
2599
+ { in: "body", key: "messageID" },
2600
+ { in: "body", key: "model" },
2601
+ { in: "body", key: "agent" },
2602
+ { in: "body", key: "noReply" },
2603
+ { in: "body", key: "tools" },
2604
+ { in: "body", key: "format" },
2605
+ { in: "body", key: "system" },
2606
+ { in: "body", key: "variant" },
2607
+ { in: "body", key: "parts" }
2608
+ ]
2609
+ }
2610
+ ]
2611
+ );
2612
+ return (options?.client ?? this.client).post({
2613
+ url: "/session/{sessionID}/prompt_async",
2614
+ ...options,
2615
+ ...params,
2616
+ headers: {
2617
+ "Content-Type": "application/json",
2618
+ ...options?.headers,
2619
+ ...params.headers
2620
+ }
2621
+ });
2622
+ }
2623
+ /**
2624
+ * Send command
2625
+ *
2626
+ * Send a new command to a session for execution by the AI assistant.
2627
+ */
2628
+ command(parameters, options) {
2629
+ const params = buildClientParams(
2630
+ [parameters],
2631
+ [
2632
+ {
2633
+ args: [
2634
+ { in: "path", key: "sessionID" },
2635
+ { in: "query", key: "directory" },
2636
+ { in: "query", key: "workspace" },
2637
+ { in: "body", key: "messageID" },
2638
+ { in: "body", key: "agent" },
2639
+ { in: "body", key: "model" },
2640
+ { in: "body", key: "arguments" },
2641
+ { in: "body", key: "command" },
2642
+ { in: "body", key: "variant" },
2643
+ { in: "body", key: "parts" }
2644
+ ]
2645
+ }
2646
+ ]
2647
+ );
2648
+ return (options?.client ?? this.client).post({
2649
+ url: "/session/{sessionID}/command",
2650
+ ...options,
2651
+ ...params,
2652
+ headers: {
2653
+ "Content-Type": "application/json",
2654
+ ...options?.headers,
2655
+ ...params.headers
2656
+ }
2657
+ });
2658
+ }
2659
+ /**
2660
+ * Run shell command
2661
+ *
2662
+ * Execute a shell command within the session context and return the AI's response.
2663
+ */
2664
+ shell(parameters, options) {
2665
+ const params = buildClientParams(
2666
+ [parameters],
2667
+ [
2668
+ {
2669
+ args: [
2670
+ { in: "path", key: "sessionID" },
2671
+ { in: "query", key: "directory" },
2672
+ { in: "query", key: "workspace" },
2673
+ { in: "body", key: "messageID" },
2674
+ { in: "body", key: "agent" },
2675
+ { in: "body", key: "model" },
2676
+ { in: "body", key: "command" }
2677
+ ]
2678
+ }
2679
+ ]
2680
+ );
2681
+ return (options?.client ?? this.client).post({
2682
+ url: "/session/{sessionID}/shell",
2683
+ ...options,
2684
+ ...params,
2685
+ headers: {
2686
+ "Content-Type": "application/json",
2687
+ ...options?.headers,
2688
+ ...params.headers
2689
+ }
2690
+ });
2691
+ }
2692
+ /**
2693
+ * Revert message
2694
+ *
2695
+ * Revert a specific message in a session, undoing its effects and restoring the previous state.
2696
+ */
2697
+ revert(parameters, options) {
2698
+ const params = buildClientParams(
2699
+ [parameters],
2700
+ [
2701
+ {
2702
+ args: [
2703
+ { in: "path", key: "sessionID" },
2704
+ { in: "query", key: "directory" },
2705
+ { in: "query", key: "workspace" },
2706
+ { in: "body", key: "messageID" },
2707
+ { in: "body", key: "partID" }
2708
+ ]
2709
+ }
2710
+ ]
2711
+ );
2712
+ return (options?.client ?? this.client).post({
2713
+ url: "/session/{sessionID}/revert",
2714
+ ...options,
2715
+ ...params,
2716
+ headers: {
2717
+ "Content-Type": "application/json",
2718
+ ...options?.headers,
2719
+ ...params.headers
2720
+ }
2721
+ });
2722
+ }
2723
+ /**
2724
+ * Restore reverted messages
2725
+ *
2726
+ * Restore all previously reverted messages in a session.
2727
+ */
2728
+ unrevert(parameters, options) {
2729
+ const params = buildClientParams(
2730
+ [parameters],
2731
+ [
2732
+ {
2733
+ args: [
2734
+ { in: "path", key: "sessionID" },
2735
+ { in: "query", key: "directory" },
2736
+ { in: "query", key: "workspace" }
2737
+ ]
2738
+ }
2739
+ ]
2740
+ );
2741
+ return (options?.client ?? this.client).post({
2742
+ url: "/session/{sessionID}/unrevert",
2743
+ ...options,
2744
+ ...params
2745
+ });
2746
+ }
2747
+ };
2748
+ var Part = class extends HeyApiClient {
2749
+ /**
2750
+ * Delete a part from a message
2751
+ */
2752
+ delete(parameters, options) {
2753
+ const params = buildClientParams(
2754
+ [parameters],
2755
+ [
2756
+ {
2757
+ args: [
2758
+ { in: "path", key: "sessionID" },
2759
+ { in: "path", key: "messageID" },
2760
+ { in: "path", key: "partID" },
2761
+ { in: "query", key: "directory" },
2762
+ { in: "query", key: "workspace" }
2763
+ ]
2764
+ }
2765
+ ]
2766
+ );
2767
+ return (options?.client ?? this.client).delete({
2768
+ url: "/session/{sessionID}/message/{messageID}/part/{partID}",
2769
+ ...options,
2770
+ ...params
2771
+ });
2772
+ }
2773
+ /**
2774
+ * Update a part in a message
2775
+ */
2776
+ update(parameters, options) {
2777
+ const params = buildClientParams(
2778
+ [parameters],
2779
+ [
2780
+ {
2781
+ args: [
2782
+ { in: "path", key: "sessionID" },
2783
+ { in: "path", key: "messageID" },
2784
+ { in: "path", key: "partID" },
2785
+ { in: "query", key: "directory" },
2786
+ { in: "query", key: "workspace" },
2787
+ { key: "part", map: "body" }
2788
+ ]
2789
+ }
2790
+ ]
2791
+ );
2792
+ return (options?.client ?? this.client).patch({
2793
+ url: "/session/{sessionID}/message/{messageID}/part/{partID}",
2794
+ ...options,
2795
+ ...params,
2796
+ headers: {
2797
+ "Content-Type": "application/json",
2798
+ ...options?.headers,
2799
+ ...params.headers
2800
+ }
2801
+ });
2802
+ }
2803
+ };
2804
+ var Permission = class extends HeyApiClient {
2805
+ /**
2806
+ * Respond to permission
2807
+ *
2808
+ * Approve or deny a permission request from the AI assistant.
2809
+ *
2810
+ * @deprecated
2811
+ */
2812
+ respond(parameters, options) {
2813
+ const params = buildClientParams(
2814
+ [parameters],
2815
+ [
2816
+ {
2817
+ args: [
2818
+ { in: "path", key: "sessionID" },
2819
+ { in: "path", key: "permissionID" },
2820
+ { in: "query", key: "directory" },
2821
+ { in: "query", key: "workspace" },
2822
+ { in: "body", key: "response" }
2823
+ ]
2824
+ }
2825
+ ]
2826
+ );
2827
+ return (options?.client ?? this.client).post({
2828
+ url: "/session/{sessionID}/permissions/{permissionID}",
2829
+ ...options,
2830
+ ...params,
2831
+ headers: {
2832
+ "Content-Type": "application/json",
2833
+ ...options?.headers,
2834
+ ...params.headers
2835
+ }
2836
+ });
2837
+ }
2838
+ /**
2839
+ * Respond to permission request
2840
+ *
2841
+ * Approve or deny a permission request from the AI assistant.
2842
+ */
2843
+ reply(parameters, options) {
2844
+ const params = buildClientParams(
2845
+ [parameters],
2846
+ [
2847
+ {
2848
+ args: [
2849
+ { in: "path", key: "requestID" },
2850
+ { in: "query", key: "directory" },
2851
+ { in: "query", key: "workspace" },
2852
+ { in: "body", key: "reply" },
2853
+ { in: "body", key: "message" }
2854
+ ]
2855
+ }
2856
+ ]
2857
+ );
2858
+ return (options?.client ?? this.client).post({
2859
+ url: "/permission/{requestID}/reply",
2860
+ ...options,
2861
+ ...params,
2862
+ headers: {
2863
+ "Content-Type": "application/json",
2864
+ ...options?.headers,
2865
+ ...params.headers
2866
+ }
2867
+ });
2868
+ }
2869
+ /**
2870
+ * List pending permissions
2871
+ *
2872
+ * Get all pending permission requests across all sessions.
2873
+ */
2874
+ list(parameters, options) {
2875
+ const params = buildClientParams(
2876
+ [parameters],
2877
+ [
2878
+ {
2879
+ args: [
2880
+ { in: "query", key: "directory" },
2881
+ { in: "query", key: "workspace" }
2882
+ ]
2883
+ }
2884
+ ]
2885
+ );
2886
+ return (options?.client ?? this.client).get({
2887
+ url: "/permission",
2888
+ ...options,
2889
+ ...params
2890
+ });
2891
+ }
2892
+ };
2893
+ var Question = class extends HeyApiClient {
2894
+ /**
2895
+ * List pending questions
2896
+ *
2897
+ * Get all pending question requests across all sessions.
2898
+ */
2899
+ list(parameters, options) {
2900
+ const params = buildClientParams(
2901
+ [parameters],
2902
+ [
2903
+ {
2904
+ args: [
2905
+ { in: "query", key: "directory" },
2906
+ { in: "query", key: "workspace" }
2907
+ ]
2908
+ }
2909
+ ]
2910
+ );
2911
+ return (options?.client ?? this.client).get({
2912
+ url: "/question",
2913
+ ...options,
2914
+ ...params
2915
+ });
2916
+ }
2917
+ /**
2918
+ * Reply to question request
2919
+ *
2920
+ * Provide answers to a question request from the AI assistant.
2921
+ */
2922
+ reply(parameters, options) {
2923
+ const params = buildClientParams(
2924
+ [parameters],
2925
+ [
2926
+ {
2927
+ args: [
2928
+ { in: "path", key: "requestID" },
2929
+ { in: "query", key: "directory" },
2930
+ { in: "query", key: "workspace" },
2931
+ { in: "body", key: "answers" }
2932
+ ]
2933
+ }
2934
+ ]
2935
+ );
2936
+ return (options?.client ?? this.client).post({
2937
+ url: "/question/{requestID}/reply",
2938
+ ...options,
2939
+ ...params,
2940
+ headers: {
2941
+ "Content-Type": "application/json",
2942
+ ...options?.headers,
2943
+ ...params.headers
2944
+ }
2945
+ });
2946
+ }
2947
+ /**
2948
+ * Reject question request
2949
+ *
2950
+ * Reject a question request from the AI assistant.
2951
+ */
2952
+ reject(parameters, options) {
2953
+ const params = buildClientParams(
2954
+ [parameters],
2955
+ [
2956
+ {
2957
+ args: [
2958
+ { in: "path", key: "requestID" },
2959
+ { in: "query", key: "directory" },
2960
+ { in: "query", key: "workspace" }
2961
+ ]
2962
+ }
2963
+ ]
2964
+ );
2965
+ return (options?.client ?? this.client).post({
2966
+ url: "/question/{requestID}/reject",
2967
+ ...options,
2968
+ ...params
2969
+ });
2970
+ }
2971
+ };
2972
+ var Oauth = class extends HeyApiClient {
2973
+ /**
2974
+ * OAuth authorize
2975
+ *
2976
+ * Initiate OAuth authorization for a specific AI provider to get an authorization URL.
2977
+ */
2978
+ authorize(parameters, options) {
2979
+ const params = buildClientParams(
2980
+ [parameters],
2981
+ [
2982
+ {
2983
+ args: [
2984
+ { in: "path", key: "providerID" },
2985
+ { in: "query", key: "directory" },
2986
+ { in: "query", key: "workspace" },
2987
+ { in: "body", key: "method" },
2988
+ { in: "body", key: "inputs" }
2989
+ ]
2990
+ }
2991
+ ]
2992
+ );
2993
+ return (options?.client ?? this.client).post({
2994
+ url: "/provider/{providerID}/oauth/authorize",
2995
+ ...options,
2996
+ ...params,
2997
+ headers: {
2998
+ "Content-Type": "application/json",
2999
+ ...options?.headers,
3000
+ ...params.headers
3001
+ }
3002
+ });
3003
+ }
3004
+ /**
3005
+ * OAuth callback
3006
+ *
3007
+ * Handle the OAuth callback from a provider after user authorization.
3008
+ */
3009
+ callback(parameters, options) {
3010
+ const params = buildClientParams(
3011
+ [parameters],
3012
+ [
3013
+ {
3014
+ args: [
3015
+ { in: "path", key: "providerID" },
3016
+ { in: "query", key: "directory" },
3017
+ { in: "query", key: "workspace" },
3018
+ { in: "body", key: "method" },
3019
+ { in: "body", key: "code" }
3020
+ ]
3021
+ }
3022
+ ]
3023
+ );
3024
+ return (options?.client ?? this.client).post({
3025
+ url: "/provider/{providerID}/oauth/callback",
3026
+ ...options,
3027
+ ...params,
3028
+ headers: {
3029
+ "Content-Type": "application/json",
3030
+ ...options?.headers,
3031
+ ...params.headers
3032
+ }
3033
+ });
3034
+ }
3035
+ };
3036
+ var Provider2 = class extends HeyApiClient {
3037
+ /**
3038
+ * List providers
3039
+ *
3040
+ * Get a list of all available AI providers, including both available and connected ones.
3041
+ */
3042
+ list(parameters, options) {
3043
+ const params = buildClientParams(
3044
+ [parameters],
3045
+ [
3046
+ {
3047
+ args: [
3048
+ { in: "query", key: "directory" },
3049
+ { in: "query", key: "workspace" }
3050
+ ]
3051
+ }
3052
+ ]
3053
+ );
3054
+ return (options?.client ?? this.client).get({
3055
+ url: "/provider",
3056
+ ...options,
3057
+ ...params
3058
+ });
3059
+ }
3060
+ /**
3061
+ * Get provider auth methods
3062
+ *
3063
+ * Retrieve available authentication methods for all AI providers.
3064
+ */
3065
+ auth(parameters, options) {
3066
+ const params = buildClientParams(
3067
+ [parameters],
3068
+ [
3069
+ {
3070
+ args: [
3071
+ { in: "query", key: "directory" },
3072
+ { in: "query", key: "workspace" }
3073
+ ]
3074
+ }
3075
+ ]
3076
+ );
3077
+ return (options?.client ?? this.client).get({
3078
+ url: "/provider/auth",
3079
+ ...options,
3080
+ ...params
3081
+ });
3082
+ }
3083
+ _oauth;
3084
+ get oauth() {
3085
+ return this._oauth ??= new Oauth({ client: this.client });
3086
+ }
3087
+ };
3088
+ var Find = class extends HeyApiClient {
3089
+ /**
3090
+ * Find text
3091
+ *
3092
+ * Search for text patterns across files in the project using ripgrep.
3093
+ */
3094
+ text(parameters, options) {
3095
+ const params = buildClientParams(
3096
+ [parameters],
3097
+ [
3098
+ {
3099
+ args: [
3100
+ { in: "query", key: "directory" },
3101
+ { in: "query", key: "workspace" },
3102
+ { in: "query", key: "pattern" }
3103
+ ]
3104
+ }
3105
+ ]
3106
+ );
3107
+ return (options?.client ?? this.client).get({
3108
+ url: "/find",
3109
+ ...options,
3110
+ ...params
3111
+ });
3112
+ }
3113
+ /**
3114
+ * Find files
3115
+ *
3116
+ * Search for files or directories by name or pattern in the project directory.
3117
+ */
3118
+ files(parameters, options) {
3119
+ const params = buildClientParams(
3120
+ [parameters],
3121
+ [
3122
+ {
3123
+ args: [
3124
+ { in: "query", key: "directory" },
3125
+ { in: "query", key: "workspace" },
3126
+ { in: "query", key: "query" },
3127
+ { in: "query", key: "dirs" },
3128
+ { in: "query", key: "type" },
3129
+ { in: "query", key: "limit" }
3130
+ ]
3131
+ }
3132
+ ]
3133
+ );
3134
+ return (options?.client ?? this.client).get({
3135
+ url: "/find/file",
3136
+ ...options,
3137
+ ...params
3138
+ });
3139
+ }
3140
+ /**
3141
+ * Find symbols
3142
+ *
3143
+ * Search for workspace symbols like functions, classes, and variables using LSP.
3144
+ */
3145
+ symbols(parameters, options) {
3146
+ const params = buildClientParams(
3147
+ [parameters],
3148
+ [
3149
+ {
3150
+ args: [
3151
+ { in: "query", key: "directory" },
3152
+ { in: "query", key: "workspace" },
3153
+ { in: "query", key: "query" }
3154
+ ]
3155
+ }
3156
+ ]
3157
+ );
3158
+ return (options?.client ?? this.client).get({
3159
+ url: "/find/symbol",
3160
+ ...options,
3161
+ ...params
3162
+ });
3163
+ }
3164
+ };
3165
+ var File = class extends HeyApiClient {
3166
+ /**
3167
+ * List files
3168
+ *
3169
+ * List files and directories in a specified path.
3170
+ */
3171
+ list(parameters, options) {
3172
+ const params = buildClientParams(
3173
+ [parameters],
3174
+ [
3175
+ {
3176
+ args: [
3177
+ { in: "query", key: "directory" },
3178
+ { in: "query", key: "workspace" },
3179
+ { in: "query", key: "path" }
3180
+ ]
3181
+ }
3182
+ ]
3183
+ );
3184
+ return (options?.client ?? this.client).get({
3185
+ url: "/file",
3186
+ ...options,
3187
+ ...params
3188
+ });
3189
+ }
3190
+ /**
3191
+ * Read file
3192
+ *
3193
+ * Read the content of a specified file.
3194
+ */
3195
+ read(parameters, options) {
3196
+ const params = buildClientParams(
3197
+ [parameters],
3198
+ [
3199
+ {
3200
+ args: [
3201
+ { in: "query", key: "directory" },
3202
+ { in: "query", key: "workspace" },
3203
+ { in: "query", key: "path" }
3204
+ ]
3205
+ }
3206
+ ]
3207
+ );
3208
+ return (options?.client ?? this.client).get({
3209
+ url: "/file/content",
3210
+ ...options,
3211
+ ...params
3212
+ });
3213
+ }
3214
+ /**
3215
+ * Get file status
3216
+ *
3217
+ * Get the git status of all files in the project.
3218
+ */
3219
+ status(parameters, options) {
3220
+ const params = buildClientParams(
3221
+ [parameters],
3222
+ [
3223
+ {
3224
+ args: [
3225
+ { in: "query", key: "directory" },
3226
+ { in: "query", key: "workspace" }
3227
+ ]
3228
+ }
3229
+ ]
3230
+ );
3231
+ return (options?.client ?? this.client).get({
3232
+ url: "/file/status",
3233
+ ...options,
3234
+ ...params
3235
+ });
3236
+ }
3237
+ };
3238
+ var Event = class extends HeyApiClient {
3239
+ /**
3240
+ * Subscribe to events
3241
+ *
3242
+ * Get events
3243
+ */
3244
+ subscribe(parameters, options) {
3245
+ const params = buildClientParams(
3246
+ [parameters],
3247
+ [
3248
+ {
3249
+ args: [
3250
+ { in: "query", key: "directory" },
3251
+ { in: "query", key: "workspace" }
3252
+ ]
3253
+ }
3254
+ ]
3255
+ );
3256
+ return (options?.client ?? this.client).sse.get({
3257
+ url: "/event",
3258
+ ...options,
3259
+ ...params
3260
+ });
3261
+ }
3262
+ };
3263
+ var Auth2 = class extends HeyApiClient {
3264
+ /**
3265
+ * Remove MCP OAuth
3266
+ *
3267
+ * Remove OAuth credentials for an MCP server
3268
+ */
3269
+ remove(parameters, options) {
3270
+ const params = buildClientParams(
3271
+ [parameters],
3272
+ [
3273
+ {
3274
+ args: [
3275
+ { in: "path", key: "name" },
3276
+ { in: "query", key: "directory" },
3277
+ { in: "query", key: "workspace" }
3278
+ ]
3279
+ }
3280
+ ]
3281
+ );
3282
+ return (options?.client ?? this.client).delete({
3283
+ url: "/mcp/{name}/auth",
3284
+ ...options,
3285
+ ...params
3286
+ });
3287
+ }
3288
+ /**
3289
+ * Start MCP OAuth
3290
+ *
3291
+ * Start OAuth authentication flow for a Model Context Protocol (MCP) server.
3292
+ */
3293
+ start(parameters, options) {
3294
+ const params = buildClientParams(
3295
+ [parameters],
3296
+ [
3297
+ {
3298
+ args: [
3299
+ { in: "path", key: "name" },
3300
+ { in: "query", key: "directory" },
3301
+ { in: "query", key: "workspace" }
3302
+ ]
3303
+ }
3304
+ ]
3305
+ );
3306
+ return (options?.client ?? this.client).post({
3307
+ url: "/mcp/{name}/auth",
3308
+ ...options,
3309
+ ...params
3310
+ });
3311
+ }
3312
+ /**
3313
+ * Complete MCP OAuth
3314
+ *
3315
+ * Complete OAuth authentication for a Model Context Protocol (MCP) server using the authorization code.
3316
+ */
3317
+ callback(parameters, options) {
3318
+ const params = buildClientParams(
3319
+ [parameters],
3320
+ [
3321
+ {
3322
+ args: [
3323
+ { in: "path", key: "name" },
3324
+ { in: "query", key: "directory" },
3325
+ { in: "query", key: "workspace" },
3326
+ { in: "body", key: "code" }
3327
+ ]
3328
+ }
3329
+ ]
3330
+ );
3331
+ return (options?.client ?? this.client).post({
3332
+ url: "/mcp/{name}/auth/callback",
3333
+ ...options,
3334
+ ...params,
3335
+ headers: {
3336
+ "Content-Type": "application/json",
3337
+ ...options?.headers,
3338
+ ...params.headers
3339
+ }
3340
+ });
3341
+ }
3342
+ /**
3343
+ * Authenticate MCP OAuth
3344
+ *
3345
+ * Start OAuth flow and wait for callback (opens browser)
3346
+ */
3347
+ authenticate(parameters, options) {
3348
+ const params = buildClientParams(
3349
+ [parameters],
3350
+ [
3351
+ {
3352
+ args: [
3353
+ { in: "path", key: "name" },
3354
+ { in: "query", key: "directory" },
3355
+ { in: "query", key: "workspace" }
3356
+ ]
3357
+ }
3358
+ ]
3359
+ );
3360
+ return (options?.client ?? this.client).post(
3361
+ {
3362
+ url: "/mcp/{name}/auth/authenticate",
3363
+ ...options,
3364
+ ...params
3365
+ }
3366
+ );
3367
+ }
3368
+ };
3369
+ var Mcp = class extends HeyApiClient {
3370
+ /**
3371
+ * Get MCP status
3372
+ *
3373
+ * Get the status of all Model Context Protocol (MCP) servers.
3374
+ */
3375
+ status(parameters, options) {
3376
+ const params = buildClientParams(
3377
+ [parameters],
3378
+ [
3379
+ {
3380
+ args: [
3381
+ { in: "query", key: "directory" },
3382
+ { in: "query", key: "workspace" }
3383
+ ]
3384
+ }
3385
+ ]
3386
+ );
3387
+ return (options?.client ?? this.client).get({
3388
+ url: "/mcp",
3389
+ ...options,
3390
+ ...params
3391
+ });
3392
+ }
3393
+ /**
3394
+ * Add MCP server
3395
+ *
3396
+ * Dynamically add a new Model Context Protocol (MCP) server to the system.
3397
+ */
3398
+ add(parameters, options) {
3399
+ const params = buildClientParams(
3400
+ [parameters],
3401
+ [
3402
+ {
3403
+ args: [
3404
+ { in: "query", key: "directory" },
3405
+ { in: "query", key: "workspace" },
3406
+ { in: "body", key: "name" },
3407
+ { in: "body", key: "config" }
3408
+ ]
3409
+ }
3410
+ ]
3411
+ );
3412
+ return (options?.client ?? this.client).post({
3413
+ url: "/mcp",
3414
+ ...options,
3415
+ ...params,
3416
+ headers: {
3417
+ "Content-Type": "application/json",
3418
+ ...options?.headers,
3419
+ ...params.headers
3420
+ }
3421
+ });
3422
+ }
3423
+ /**
3424
+ * Connect an MCP server
3425
+ */
3426
+ connect(parameters, options) {
3427
+ const params = buildClientParams(
3428
+ [parameters],
3429
+ [
3430
+ {
3431
+ args: [
3432
+ { in: "path", key: "name" },
3433
+ { in: "query", key: "directory" },
3434
+ { in: "query", key: "workspace" }
3435
+ ]
3436
+ }
3437
+ ]
3438
+ );
3439
+ return (options?.client ?? this.client).post({
3440
+ url: "/mcp/{name}/connect",
3441
+ ...options,
3442
+ ...params
3443
+ });
3444
+ }
3445
+ /**
3446
+ * Disconnect an MCP server
3447
+ */
3448
+ disconnect(parameters, options) {
3449
+ const params = buildClientParams(
3450
+ [parameters],
3451
+ [
3452
+ {
3453
+ args: [
3454
+ { in: "path", key: "name" },
3455
+ { in: "query", key: "directory" },
3456
+ { in: "query", key: "workspace" }
3457
+ ]
3458
+ }
3459
+ ]
3460
+ );
3461
+ return (options?.client ?? this.client).post({
3462
+ url: "/mcp/{name}/disconnect",
3463
+ ...options,
3464
+ ...params
3465
+ });
3466
+ }
3467
+ _auth;
3468
+ get auth() {
3469
+ return this._auth ??= new Auth2({ client: this.client });
3470
+ }
3471
+ };
3472
+ var Control = class extends HeyApiClient {
3473
+ /**
3474
+ * Get next TUI request
3475
+ *
3476
+ * Retrieve the next TUI (Terminal User Interface) request from the queue for processing.
3477
+ */
3478
+ next(parameters, options) {
3479
+ const params = buildClientParams(
3480
+ [parameters],
3481
+ [
3482
+ {
3483
+ args: [
3484
+ { in: "query", key: "directory" },
3485
+ { in: "query", key: "workspace" }
3486
+ ]
3487
+ }
3488
+ ]
3489
+ );
3490
+ return (options?.client ?? this.client).get({
3491
+ url: "/tui/control/next",
3492
+ ...options,
3493
+ ...params
3494
+ });
3495
+ }
3496
+ /**
3497
+ * Submit TUI response
3498
+ *
3499
+ * Submit a response to the TUI request queue to complete a pending request.
3500
+ */
3501
+ response(parameters, options) {
3502
+ const params = buildClientParams(
3503
+ [parameters],
3504
+ [
3505
+ {
3506
+ args: [
3507
+ { in: "query", key: "directory" },
3508
+ { in: "query", key: "workspace" },
3509
+ { key: "body", map: "body" }
3510
+ ]
3511
+ }
3512
+ ]
3513
+ );
3514
+ return (options?.client ?? this.client).post({
3515
+ url: "/tui/control/response",
3516
+ ...options,
3517
+ ...params,
3518
+ headers: {
3519
+ "Content-Type": "application/json",
3520
+ ...options?.headers,
3521
+ ...params.headers
3522
+ }
3523
+ });
3524
+ }
3525
+ };
3526
+ var Tui = class extends HeyApiClient {
3527
+ /**
3528
+ * Append TUI prompt
3529
+ *
3530
+ * Append prompt to the TUI
3531
+ */
3532
+ appendPrompt(parameters, options) {
3533
+ const params = buildClientParams(
3534
+ [parameters],
3535
+ [
3536
+ {
3537
+ args: [
3538
+ { in: "query", key: "directory" },
3539
+ { in: "query", key: "workspace" },
3540
+ { in: "body", key: "text" }
3541
+ ]
3542
+ }
3543
+ ]
3544
+ );
3545
+ return (options?.client ?? this.client).post({
3546
+ url: "/tui/append-prompt",
3547
+ ...options,
3548
+ ...params,
3549
+ headers: {
3550
+ "Content-Type": "application/json",
3551
+ ...options?.headers,
3552
+ ...params.headers
3553
+ }
3554
+ });
3555
+ }
3556
+ /**
3557
+ * Open help dialog
3558
+ *
3559
+ * Open the help dialog in the TUI to display user assistance information.
3560
+ */
3561
+ openHelp(parameters, options) {
3562
+ const params = buildClientParams(
3563
+ [parameters],
3564
+ [
3565
+ {
3566
+ args: [
3567
+ { in: "query", key: "directory" },
3568
+ { in: "query", key: "workspace" }
3569
+ ]
3570
+ }
3571
+ ]
3572
+ );
3573
+ return (options?.client ?? this.client).post({
3574
+ url: "/tui/open-help",
3575
+ ...options,
3576
+ ...params
3577
+ });
3578
+ }
3579
+ /**
3580
+ * Open sessions dialog
3581
+ *
3582
+ * Open the session dialog
3583
+ */
3584
+ openSessions(parameters, options) {
3585
+ const params = buildClientParams(
3586
+ [parameters],
3587
+ [
3588
+ {
3589
+ args: [
3590
+ { in: "query", key: "directory" },
3591
+ { in: "query", key: "workspace" }
3592
+ ]
3593
+ }
3594
+ ]
3595
+ );
3596
+ return (options?.client ?? this.client).post({
3597
+ url: "/tui/open-sessions",
3598
+ ...options,
3599
+ ...params
3600
+ });
3601
+ }
3602
+ /**
3603
+ * Open themes dialog
3604
+ *
3605
+ * Open the theme dialog
3606
+ */
3607
+ openThemes(parameters, options) {
3608
+ const params = buildClientParams(
3609
+ [parameters],
3610
+ [
3611
+ {
3612
+ args: [
3613
+ { in: "query", key: "directory" },
3614
+ { in: "query", key: "workspace" }
3615
+ ]
3616
+ }
3617
+ ]
3618
+ );
3619
+ return (options?.client ?? this.client).post({
3620
+ url: "/tui/open-themes",
3621
+ ...options,
3622
+ ...params
3623
+ });
3624
+ }
3625
+ /**
3626
+ * Open models dialog
3627
+ *
3628
+ * Open the model dialog
3629
+ */
3630
+ openModels(parameters, options) {
3631
+ const params = buildClientParams(
3632
+ [parameters],
3633
+ [
3634
+ {
3635
+ args: [
3636
+ { in: "query", key: "directory" },
3637
+ { in: "query", key: "workspace" }
3638
+ ]
3639
+ }
3640
+ ]
3641
+ );
3642
+ return (options?.client ?? this.client).post({
3643
+ url: "/tui/open-models",
3644
+ ...options,
3645
+ ...params
3646
+ });
3647
+ }
3648
+ /**
3649
+ * Submit TUI prompt
3650
+ *
3651
+ * Submit the prompt
3652
+ */
3653
+ submitPrompt(parameters, options) {
3654
+ const params = buildClientParams(
3655
+ [parameters],
3656
+ [
3657
+ {
3658
+ args: [
3659
+ { in: "query", key: "directory" },
3660
+ { in: "query", key: "workspace" }
3661
+ ]
3662
+ }
3663
+ ]
3664
+ );
3665
+ return (options?.client ?? this.client).post({
3666
+ url: "/tui/submit-prompt",
3667
+ ...options,
3668
+ ...params
3669
+ });
3670
+ }
3671
+ /**
3672
+ * Clear TUI prompt
3673
+ *
3674
+ * Clear the prompt
3675
+ */
3676
+ clearPrompt(parameters, options) {
3677
+ const params = buildClientParams(
3678
+ [parameters],
3679
+ [
3680
+ {
3681
+ args: [
3682
+ { in: "query", key: "directory" },
3683
+ { in: "query", key: "workspace" }
3684
+ ]
3685
+ }
3686
+ ]
3687
+ );
3688
+ return (options?.client ?? this.client).post({
3689
+ url: "/tui/clear-prompt",
3690
+ ...options,
3691
+ ...params
3692
+ });
3693
+ }
3694
+ /**
3695
+ * Execute TUI command
3696
+ *
3697
+ * Execute a TUI command (e.g. agent_cycle)
3698
+ */
3699
+ executeCommand(parameters, options) {
3700
+ const params = buildClientParams(
3701
+ [parameters],
3702
+ [
3703
+ {
3704
+ args: [
3705
+ { in: "query", key: "directory" },
3706
+ { in: "query", key: "workspace" },
3707
+ { in: "body", key: "command" }
3708
+ ]
3709
+ }
3710
+ ]
3711
+ );
3712
+ return (options?.client ?? this.client).post({
3713
+ url: "/tui/execute-command",
3714
+ ...options,
3715
+ ...params,
3716
+ headers: {
3717
+ "Content-Type": "application/json",
3718
+ ...options?.headers,
3719
+ ...params.headers
3720
+ }
3721
+ });
3722
+ }
3723
+ /**
3724
+ * Show TUI toast
3725
+ *
3726
+ * Show a toast notification in the TUI
3727
+ */
3728
+ showToast(parameters, options) {
3729
+ const params = buildClientParams(
3730
+ [parameters],
3731
+ [
3732
+ {
3733
+ args: [
3734
+ { in: "query", key: "directory" },
3735
+ { in: "query", key: "workspace" },
3736
+ { in: "body", key: "title" },
3737
+ { in: "body", key: "message" },
3738
+ { in: "body", key: "variant" },
3739
+ { in: "body", key: "duration" }
3740
+ ]
3741
+ }
3742
+ ]
3743
+ );
3744
+ return (options?.client ?? this.client).post({
3745
+ url: "/tui/show-toast",
3746
+ ...options,
3747
+ ...params,
3748
+ headers: {
3749
+ "Content-Type": "application/json",
3750
+ ...options?.headers,
3751
+ ...params.headers
3752
+ }
3753
+ });
3754
+ }
3755
+ /**
3756
+ * Publish TUI event
3757
+ *
3758
+ * Publish a TUI event
3759
+ */
3760
+ publish(parameters, options) {
3761
+ const params = buildClientParams(
3762
+ [parameters],
3763
+ [
3764
+ {
3765
+ args: [
3766
+ { in: "query", key: "directory" },
3767
+ { in: "query", key: "workspace" },
3768
+ { key: "body", map: "body" }
3769
+ ]
3770
+ }
3771
+ ]
3772
+ );
3773
+ return (options?.client ?? this.client).post({
3774
+ url: "/tui/publish",
3775
+ ...options,
3776
+ ...params,
3777
+ headers: {
3778
+ "Content-Type": "application/json",
3779
+ ...options?.headers,
3780
+ ...params.headers
3781
+ }
3782
+ });
3783
+ }
3784
+ /**
3785
+ * Select session
3786
+ *
3787
+ * Navigate the TUI to display the specified session.
3788
+ */
3789
+ selectSession(parameters, options) {
3790
+ const params = buildClientParams(
3791
+ [parameters],
3792
+ [
3793
+ {
3794
+ args: [
3795
+ { in: "query", key: "directory" },
3796
+ { in: "query", key: "workspace" },
3797
+ { in: "body", key: "sessionID" }
3798
+ ]
3799
+ }
3800
+ ]
3801
+ );
3802
+ return (options?.client ?? this.client).post({
3803
+ url: "/tui/select-session",
3804
+ ...options,
3805
+ ...params,
3806
+ headers: {
3807
+ "Content-Type": "application/json",
3808
+ ...options?.headers,
3809
+ ...params.headers
3810
+ }
3811
+ });
3812
+ }
3813
+ _control;
3814
+ get control() {
3815
+ return this._control ??= new Control({ client: this.client });
3816
+ }
3817
+ };
3818
+ var Instance2 = class extends HeyApiClient {
3819
+ /**
3820
+ * Dispose instance
3821
+ *
3822
+ * Clean up and dispose the current OpenCode instance, releasing all resources.
3823
+ */
3824
+ dispose(parameters, options) {
3825
+ const params = buildClientParams(
3826
+ [parameters],
3827
+ [
3828
+ {
3829
+ args: [
3830
+ { in: "query", key: "directory" },
3831
+ { in: "query", key: "workspace" }
3832
+ ]
3833
+ }
3834
+ ]
3835
+ );
3836
+ return (options?.client ?? this.client).post({
3837
+ url: "/instance/dispose",
3838
+ ...options,
3839
+ ...params
3840
+ });
3841
+ }
3842
+ };
3843
+ var Path = class extends HeyApiClient {
3844
+ /**
3845
+ * Get paths
3846
+ *
3847
+ * Retrieve the current working directory and related path information for the OpenCode instance.
3848
+ */
3849
+ get(parameters, options) {
3850
+ const params = buildClientParams(
3851
+ [parameters],
3852
+ [
3853
+ {
3854
+ args: [
3855
+ { in: "query", key: "directory" },
3856
+ { in: "query", key: "workspace" }
3857
+ ]
3858
+ }
3859
+ ]
3860
+ );
3861
+ return (options?.client ?? this.client).get({
3862
+ url: "/path",
3863
+ ...options,
3864
+ ...params
3865
+ });
3866
+ }
3867
+ };
3868
+ var Vcs = class extends HeyApiClient {
3869
+ /**
3870
+ * Get VCS info
3871
+ *
3872
+ * Retrieve version control system (VCS) information for the current project, such as git branch.
3873
+ */
3874
+ get(parameters, options) {
3875
+ const params = buildClientParams(
3876
+ [parameters],
3877
+ [
3878
+ {
3879
+ args: [
3880
+ { in: "query", key: "directory" },
3881
+ { in: "query", key: "workspace" }
3882
+ ]
3883
+ }
3884
+ ]
3885
+ );
3886
+ return (options?.client ?? this.client).get({
3887
+ url: "/vcs",
3888
+ ...options,
3889
+ ...params
3890
+ });
3891
+ }
3892
+ /**
3893
+ * Get VCS diff
3894
+ *
3895
+ * Retrieve the current git diff for the working tree or against the default branch.
3896
+ */
3897
+ diff(parameters, options) {
3898
+ const params = buildClientParams(
3899
+ [parameters],
3900
+ [
3901
+ {
3902
+ args: [
3903
+ { in: "query", key: "directory" },
3904
+ { in: "query", key: "workspace" },
3905
+ { in: "query", key: "mode" }
3906
+ ]
3907
+ }
3908
+ ]
3909
+ );
3910
+ return (options?.client ?? this.client).get({
3911
+ url: "/vcs/diff",
3912
+ ...options,
3913
+ ...params
3914
+ });
3915
+ }
3916
+ };
3917
+ var Command = class extends HeyApiClient {
3918
+ /**
3919
+ * List commands
3920
+ *
3921
+ * Get a list of all available commands in the OpenCode system.
3922
+ */
3923
+ list(parameters, options) {
3924
+ const params = buildClientParams(
3925
+ [parameters],
3926
+ [
3927
+ {
3928
+ args: [
3929
+ { in: "query", key: "directory" },
3930
+ { in: "query", key: "workspace" }
3931
+ ]
3932
+ }
3933
+ ]
3934
+ );
3935
+ return (options?.client ?? this.client).get({
3936
+ url: "/command",
3937
+ ...options,
3938
+ ...params
3939
+ });
3940
+ }
3941
+ };
3942
+ var Lsp = class extends HeyApiClient {
3943
+ /**
3944
+ * Get LSP status
3945
+ *
3946
+ * Get LSP server status
3947
+ */
3948
+ status(parameters, options) {
3949
+ const params = buildClientParams(
3950
+ [parameters],
3951
+ [
3952
+ {
3953
+ args: [
3954
+ { in: "query", key: "directory" },
3955
+ { in: "query", key: "workspace" }
3956
+ ]
3957
+ }
3958
+ ]
3959
+ );
3960
+ return (options?.client ?? this.client).get({
3961
+ url: "/lsp",
3962
+ ...options,
3963
+ ...params
3964
+ });
3965
+ }
3966
+ };
3967
+ var Formatter = class extends HeyApiClient {
3968
+ /**
3969
+ * Get formatter status
3970
+ *
3971
+ * Get formatter status
3972
+ */
3973
+ status(parameters, options) {
3974
+ const params = buildClientParams(
3975
+ [parameters],
3976
+ [
3977
+ {
3978
+ args: [
3979
+ { in: "query", key: "directory" },
3980
+ { in: "query", key: "workspace" }
3981
+ ]
3982
+ }
3983
+ ]
3984
+ );
3985
+ return (options?.client ?? this.client).get({
3986
+ url: "/formatter",
3987
+ ...options,
3988
+ ...params
3989
+ });
3990
+ }
3991
+ };
3992
+ var OpencodeClient = class _OpencodeClient extends HeyApiClient {
3993
+ static __registry = new HeyApiRegistry();
3994
+ constructor(args) {
3995
+ super(args);
3996
+ _OpencodeClient.__registry.set(this, args?.key);
3997
+ }
3998
+ _global;
3999
+ get global() {
4000
+ return this._global ??= new Global({ client: this.client });
4001
+ }
4002
+ _auth;
4003
+ get auth() {
4004
+ return this._auth ??= new Auth({ client: this.client });
4005
+ }
4006
+ _app;
4007
+ get app() {
4008
+ return this._app ??= new App({ client: this.client });
4009
+ }
4010
+ _project;
4011
+ get project() {
4012
+ return this._project ??= new Project({ client: this.client });
4013
+ }
4014
+ _pty;
4015
+ get pty() {
4016
+ return this._pty ??= new Pty({ client: this.client });
4017
+ }
4018
+ _config;
4019
+ get config() {
4020
+ return this._config ??= new Config2({ client: this.client });
4021
+ }
4022
+ _experimental;
4023
+ get experimental() {
4024
+ return this._experimental ??= new Experimental({ client: this.client });
4025
+ }
4026
+ _tool;
4027
+ get tool() {
4028
+ return this._tool ??= new Tool({ client: this.client });
4029
+ }
4030
+ _worktree;
4031
+ get worktree() {
4032
+ return this._worktree ??= new Worktree({ client: this.client });
4033
+ }
4034
+ _session;
4035
+ get session() {
4036
+ return this._session ??= new Session2({ client: this.client });
4037
+ }
4038
+ _part;
4039
+ get part() {
4040
+ return this._part ??= new Part({ client: this.client });
4041
+ }
4042
+ _permission;
4043
+ get permission() {
4044
+ return this._permission ??= new Permission({ client: this.client });
4045
+ }
4046
+ _question;
4047
+ get question() {
4048
+ return this._question ??= new Question({ client: this.client });
4049
+ }
4050
+ _provider;
4051
+ get provider() {
4052
+ return this._provider ??= new Provider2({ client: this.client });
4053
+ }
4054
+ _find;
4055
+ get find() {
4056
+ return this._find ??= new Find({ client: this.client });
4057
+ }
4058
+ _file;
4059
+ get file() {
4060
+ return this._file ??= new File({ client: this.client });
4061
+ }
4062
+ _event;
4063
+ get event() {
4064
+ return this._event ??= new Event({ client: this.client });
4065
+ }
4066
+ _mcp;
4067
+ get mcp() {
4068
+ return this._mcp ??= new Mcp({ client: this.client });
4069
+ }
4070
+ _tui;
4071
+ get tui() {
4072
+ return this._tui ??= new Tui({ client: this.client });
4073
+ }
4074
+ _instance;
4075
+ get instance() {
4076
+ return this._instance ??= new Instance2({ client: this.client });
4077
+ }
4078
+ _path;
4079
+ get path() {
4080
+ return this._path ??= new Path({ client: this.client });
4081
+ }
4082
+ _vcs;
4083
+ get vcs() {
4084
+ return this._vcs ??= new Vcs({ client: this.client });
4085
+ }
4086
+ _command;
4087
+ get command() {
4088
+ return this._command ??= new Command({ client: this.client });
4089
+ }
4090
+ _lsp;
4091
+ get lsp() {
4092
+ return this._lsp ??= new Lsp({ client: this.client });
4093
+ }
4094
+ _formatter;
4095
+ get formatter() {
4096
+ return this._formatter ??= new Formatter({ client: this.client });
4097
+ }
4098
+ };
4099
+
4100
+ // packages/sdk/src/v2/client.ts
4101
+ function pick(value, fallback2, encode) {
4102
+ if (!value) return;
4103
+ if (!fallback2) return value;
4104
+ if (value === fallback2) return fallback2;
4105
+ if (encode && value === encode(fallback2)) return fallback2;
4106
+ return value;
4107
+ }
4108
+ function rewrite(request, values) {
4109
+ if (request.method !== "GET" && request.method !== "HEAD") return request;
4110
+ const url = new URL(request.url);
4111
+ let changed = false;
4112
+ for (const [name, key] of [
4113
+ ["x-opencode-directory", "directory"],
4114
+ ["x-opencode-workspace", "workspace"]
4115
+ ]) {
4116
+ const value = pick(
4117
+ request.headers.get(name),
4118
+ key === "directory" ? values.directory : values.workspace,
4119
+ key === "directory" ? encodeURIComponent : void 0
4120
+ );
4121
+ if (!value) continue;
4122
+ if (!url.searchParams.has(key)) {
4123
+ url.searchParams.set(key, value);
4124
+ }
4125
+ changed = true;
4126
+ }
4127
+ if (!changed) return request;
4128
+ const next = new Request(url, request);
4129
+ next.headers.delete("x-opencode-directory");
4130
+ next.headers.delete("x-opencode-workspace");
4131
+ return next;
4132
+ }
4133
+ function createOpencodeClient(config) {
4134
+ if (!config?.fetch) {
4135
+ const customFetch = (req) => {
4136
+ req.timeout = false;
4137
+ return fetch(req);
4138
+ };
4139
+ config = {
4140
+ ...config,
4141
+ fetch: customFetch
4142
+ };
4143
+ }
4144
+ if (config?.directory) {
4145
+ config.headers = {
4146
+ ...config.headers,
4147
+ "x-opencode-directory": encodeURIComponent(config.directory)
4148
+ };
4149
+ }
4150
+ if (config?.experimental_workspaceID) {
4151
+ config.headers = {
4152
+ ...config.headers,
4153
+ "x-opencode-workspace": config.experimental_workspaceID
4154
+ };
4155
+ }
4156
+ const client2 = createClient(config);
4157
+ client2.interceptors.request.use(
4158
+ (request) => rewrite(request, {
4159
+ directory: config?.directory,
4160
+ workspace: config?.experimental_workspaceID
4161
+ })
4162
+ );
4163
+ return new OpencodeClient({ client: client2 });
4164
+ }
4165
+
4166
+ // packages/sdk/src/v2/server.ts
4167
+ import launch from "cross-spawn";
4168
+
4169
+ // packages/opencode/src/util/locale.ts
4170
+ var Locale;
4171
+ ((Locale2) => {
4172
+ function titlecase(str) {
4173
+ return str.replace(/\b\w/g, (c) => c.toUpperCase());
4174
+ }
4175
+ Locale2.titlecase = titlecase;
4176
+ function time(input) {
4177
+ const date = new Date(input);
4178
+ return date.toLocaleTimeString(void 0, { timeStyle: "short" });
4179
+ }
4180
+ Locale2.time = time;
4181
+ function datetime(input) {
4182
+ const date = new Date(input);
4183
+ const localTime = time(input);
4184
+ const localDate = date.toLocaleDateString();
4185
+ return `${localTime} \xB7 ${localDate}`;
4186
+ }
4187
+ Locale2.datetime = datetime;
4188
+ function todayTimeOrDateTime(input) {
4189
+ const date = new Date(input);
4190
+ const now = /* @__PURE__ */ new Date();
4191
+ const isToday = date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
4192
+ if (isToday) {
4193
+ return time(input);
4194
+ } else {
4195
+ return datetime(input);
4196
+ }
4197
+ }
4198
+ Locale2.todayTimeOrDateTime = todayTimeOrDateTime;
4199
+ function number(num) {
4200
+ if (num >= 1e6) {
4201
+ return (num / 1e6).toFixed(1) + "M";
4202
+ } else if (num >= 1e3) {
4203
+ return (num / 1e3).toFixed(1) + "K";
4204
+ }
4205
+ return num.toString();
4206
+ }
4207
+ Locale2.number = number;
4208
+ function duration(input) {
4209
+ if (input < 1e3) {
4210
+ return `${input}ms`;
4211
+ }
4212
+ if (input < 6e4) {
4213
+ return `${(input / 1e3).toFixed(1)}s`;
4214
+ }
4215
+ if (input < 36e5) {
4216
+ const minutes = Math.floor(input / 6e4);
4217
+ const seconds = Math.floor(input % 6e4 / 1e3);
4218
+ return `${minutes}m ${seconds}s`;
4219
+ }
4220
+ if (input < 864e5) {
4221
+ const hours2 = Math.floor(input / 36e5);
4222
+ const minutes = Math.floor(input % 36e5 / 6e4);
4223
+ return `${hours2}h ${minutes}m`;
4224
+ }
4225
+ const hours = Math.floor(input / 36e5);
4226
+ const days = Math.floor(input % 36e5 / 864e5);
4227
+ return `${days}d ${hours}h`;
4228
+ }
4229
+ Locale2.duration = duration;
4230
+ function truncate(str, len) {
4231
+ if (str.length <= len) return str;
4232
+ return str.slice(0, len - 1) + "\u2026";
4233
+ }
4234
+ Locale2.truncate = truncate;
4235
+ function truncateMiddle(str, maxLength = 35) {
4236
+ if (str.length <= maxLength) return str;
4237
+ const ellipsis = "\u2026";
4238
+ const keepStart = Math.ceil((maxLength - ellipsis.length) / 2);
4239
+ const keepEnd = Math.floor((maxLength - ellipsis.length) / 2);
4240
+ return str.slice(0, keepStart) + ellipsis + str.slice(-keepEnd);
4241
+ }
4242
+ Locale2.truncateMiddle = truncateMiddle;
4243
+ function pluralize(count, singular, plural) {
4244
+ const template = count === 1 ? singular : plural;
4245
+ return template.replace("{}", count.toString());
4246
+ }
4247
+ Locale2.pluralize = pluralize;
4248
+ })(Locale || (Locale = {}));
4249
+
4250
+ // packages/opencode/src/cli/cmd/run.ts
4251
+ function props(part) {
4252
+ const state = part.state;
4253
+ return {
4254
+ input: state.input,
4255
+ metadata: "metadata" in state ? state.metadata : {},
4256
+ part
4257
+ };
4258
+ }
4259
+ function inline(info) {
4260
+ const suffix = info.description ? UI.Style.TEXT_DIM + ` ${info.description}` + UI.Style.TEXT_NORMAL : "";
4261
+ UI.println(UI.Style.TEXT_NORMAL + info.icon, UI.Style.TEXT_NORMAL + info.title + suffix);
4262
+ }
4263
+ function block(info, output) {
4264
+ UI.empty();
4265
+ inline(info);
4266
+ if (!output?.trim()) return;
4267
+ UI.println(output);
4268
+ UI.empty();
4269
+ }
4270
+ function fallback(part) {
4271
+ const state = part.state;
4272
+ const input = "input" in state ? state.input : void 0;
4273
+ const title = ("title" in state && state.title ? state.title : void 0) || (input && typeof input === "object" && Object.keys(input).length > 0 ? JSON.stringify(input) : "Unknown");
4274
+ inline({
4275
+ icon: "\u2699",
4276
+ title: `${part.tool} ${title}`
4277
+ });
4278
+ }
4279
+ function glob(info) {
4280
+ const root = info.input.path ?? "";
4281
+ const title = `Glob "${info.input.pattern}"`;
4282
+ const suffix = root ? `in ${normalizePath(root)}` : "";
4283
+ const num = info.metadata.count;
4284
+ const description = num === void 0 ? suffix : `${suffix}${suffix ? " \xB7 " : ""}${num} ${num === 1 ? "match" : "matches"}`;
4285
+ inline({
4286
+ icon: "\u2731",
4287
+ title,
4288
+ ...description && { description }
4289
+ });
4290
+ }
4291
+ function grep(info) {
4292
+ const root = info.input.path ?? "";
4293
+ const title = `Grep "${info.input.pattern}"`;
4294
+ const suffix = root ? `in ${normalizePath(root)}` : "";
4295
+ const num = info.metadata.matches;
4296
+ const description = num === void 0 ? suffix : `${suffix}${suffix ? " \xB7 " : ""}${num} ${num === 1 ? "match" : "matches"}`;
4297
+ inline({
4298
+ icon: "\u2731",
4299
+ title,
4300
+ ...description && { description }
4301
+ });
4302
+ }
4303
+ function list(info) {
4304
+ const dir = info.input.path ? normalizePath(info.input.path) : "";
4305
+ inline({
4306
+ icon: "\u2192",
4307
+ title: dir ? `List ${dir}` : "List"
4308
+ });
4309
+ }
4310
+ function read(info) {
4311
+ const file = normalizePath(info.input.filePath);
4312
+ const pairs = Object.entries(info.input).filter(([key, value]) => {
4313
+ if (key === "filePath") return false;
4314
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
4315
+ });
4316
+ const description = pairs.length ? `[${pairs.map(([key, value]) => `${key}=${value}`).join(", ")}]` : void 0;
4317
+ inline({
4318
+ icon: "\u2192",
4319
+ title: `Read ${file}`,
4320
+ ...description && { description }
4321
+ });
4322
+ }
4323
+ function write(info) {
4324
+ block(
4325
+ {
4326
+ icon: "\u2190",
4327
+ title: `Write ${normalizePath(info.input.filePath)}`
4328
+ },
4329
+ info.part.state.status === "completed" ? info.part.state.output : void 0
4330
+ );
4331
+ }
4332
+ function webfetch(info) {
4333
+ inline({
4334
+ icon: "%",
4335
+ title: `WebFetch ${info.input.url}`
4336
+ });
4337
+ }
4338
+ function edit(info) {
4339
+ const title = normalizePath(info.input.filePath);
4340
+ const diff = info.metadata.diff;
4341
+ block(
4342
+ {
4343
+ icon: "\u2190",
4344
+ title: `Edit ${title}`
4345
+ },
4346
+ diff
4347
+ );
4348
+ }
4349
+ function codesearch(info) {
4350
+ inline({
4351
+ icon: "\u25C7",
4352
+ title: `Exa Code Search "${info.input.query}"`
4353
+ });
4354
+ }
4355
+ function websearch(info) {
4356
+ inline({
4357
+ icon: "\u25C8",
4358
+ title: `Exa Web Search "${info.input.query}"`
4359
+ });
4360
+ }
4361
+ function task(info) {
4362
+ const input = info.part.state.input;
4363
+ const status = info.part.state.status;
4364
+ const subagent = typeof input.subagent_type === "string" && input.subagent_type.trim().length > 0 ? input.subagent_type : "unknown";
4365
+ const agent = Locale.titlecase(subagent);
4366
+ const desc = typeof input.description === "string" && input.description.trim().length > 0 ? input.description : void 0;
4367
+ const icon = status === "error" ? "\u2717" : status === "running" ? "\u2022" : "\u2713";
4368
+ const name = desc ?? `${agent} Task`;
4369
+ inline({
4370
+ icon,
4371
+ title: name,
4372
+ description: desc ? `${agent} Agent` : void 0
4373
+ });
4374
+ }
4375
+ function skill(info) {
4376
+ inline({
4377
+ icon: "\u2192",
4378
+ title: `Skill "${info.input.name}"`
4379
+ });
4380
+ }
4381
+ function bash(info) {
4382
+ const output = info.part.state.status === "completed" ? info.part.state.output?.trim() : void 0;
4383
+ block(
4384
+ {
4385
+ icon: "$",
4386
+ title: `${info.input.command}`
4387
+ },
4388
+ output
4389
+ );
4390
+ }
4391
+ function todo(info) {
4392
+ block(
4393
+ {
4394
+ icon: "#",
4395
+ title: "Todos"
4396
+ },
4397
+ info.input.todos.map((item) => `${item.status === "completed" ? "[x]" : "[ ]"} ${item.content}`).join("\n")
4398
+ );
4399
+ }
4400
+ function normalizePath(input) {
4401
+ if (!input) return "";
4402
+ if (path.isAbsolute(input)) return path.relative(process.cwd(), input) || ".";
4403
+ return input;
4404
+ }
4405
+ var RunCommand = cmd({
4406
+ command: "run [message..]",
4407
+ describe: "run opencode with a message",
4408
+ builder: (yargs) => {
4409
+ return yargs.positional("message", {
4410
+ describe: "message to send",
4411
+ type: "string",
4412
+ array: true,
4413
+ default: []
4414
+ }).option("command", {
4415
+ describe: "the command to run, use message for args",
4416
+ type: "string"
4417
+ }).option("continue", {
4418
+ alias: ["c"],
4419
+ describe: "continue the last session",
4420
+ type: "boolean"
4421
+ }).option("session", {
4422
+ alias: ["s"],
4423
+ describe: "session id to continue",
4424
+ type: "string"
4425
+ }).option("fork", {
4426
+ describe: "fork the session before continuing (requires --continue or --session)",
4427
+ type: "boolean"
4428
+ }).option("share", {
4429
+ type: "boolean",
4430
+ describe: "share the session"
4431
+ }).option("model", {
4432
+ type: "string",
4433
+ alias: ["m"],
4434
+ describe: "model to use in the format of provider/model"
4435
+ }).option("agent", {
4436
+ type: "string",
4437
+ describe: "agent to use"
4438
+ }).option("format", {
4439
+ type: "string",
4440
+ choices: ["default", "json"],
4441
+ default: "default",
4442
+ describe: "format: default (formatted) or json (raw JSON events)"
4443
+ }).option("file", {
4444
+ alias: ["f"],
4445
+ type: "string",
4446
+ array: true,
4447
+ describe: "file(s) to attach to message"
4448
+ }).option("title", {
4449
+ type: "string",
4450
+ describe: "title for the session (uses truncated prompt if no value provided)"
4451
+ }).option("attach", {
4452
+ type: "string",
4453
+ describe: "attach to a running opencode server (e.g., http://localhost:4096)"
4454
+ }).option("password", {
4455
+ alias: ["p"],
4456
+ type: "string",
4457
+ describe: "basic auth password (defaults to OPENCODE_SERVER_PASSWORD)"
4458
+ }).option("dir", {
4459
+ type: "string",
4460
+ describe: "directory to run in, path on remote server if attaching"
4461
+ }).option("port", {
4462
+ type: "number",
4463
+ describe: "port for the local server (defaults to random port if no value provided)"
4464
+ }).option("variant", {
4465
+ type: "string",
4466
+ describe: "model variant (provider-specific reasoning effort, e.g., high, max, minimal)"
4467
+ }).option("thinking", {
4468
+ type: "boolean",
4469
+ describe: "show thinking blocks",
4470
+ default: false
4471
+ }).option("dangerously-skip-permissions", {
4472
+ type: "boolean",
4473
+ describe: "auto-approve permissions that are not explicitly denied (dangerous!)",
4474
+ default: false
4475
+ });
4476
+ },
4477
+ handler: async (args) => {
4478
+ let message = [...args.message, ...args["--"] || []].map((arg) => arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg).join(" ");
4479
+ const directory = (() => {
4480
+ if (!args.dir) return void 0;
4481
+ if (args.attach) return args.dir;
4482
+ try {
4483
+ process.chdir(args.dir);
4484
+ return process.cwd();
4485
+ } catch {
4486
+ UI.error("Failed to change directory to " + args.dir);
4487
+ process.exit(1);
4488
+ }
4489
+ })();
4490
+ const files = [];
4491
+ if (args.file) {
4492
+ const list2 = Array.isArray(args.file) ? args.file : [args.file];
4493
+ for (const filePath of list2) {
4494
+ const resolvedPath = path.resolve(process.cwd(), filePath);
4495
+ if (!await Filesystem.exists(resolvedPath)) {
4496
+ UI.error(`File not found: ${filePath}`);
4497
+ process.exit(1);
4498
+ }
4499
+ const mime = await Filesystem.isDir(resolvedPath) ? "application/x-directory" : "text/plain";
4500
+ files.push({
4501
+ type: "file",
4502
+ url: pathToFileURL(resolvedPath).href,
4503
+ filename: path.basename(resolvedPath),
4504
+ mime
4505
+ });
4506
+ }
4507
+ }
4508
+ if (!process.stdin.isTTY) message += "\n" + await Bun.stdin.text();
4509
+ if (message.trim().length === 0 && !args.command) {
4510
+ UI.error("You must provide a message or a command");
4511
+ process.exit(1);
4512
+ }
4513
+ if (args.fork && !args.continue && !args.session) {
4514
+ UI.error("--fork requires --continue or --session");
4515
+ process.exit(1);
4516
+ }
4517
+ const rules = [
4518
+ {
4519
+ permission: "question",
4520
+ action: "deny",
4521
+ pattern: "*"
4522
+ },
4523
+ {
4524
+ permission: "plan_enter",
4525
+ action: "deny",
4526
+ pattern: "*"
4527
+ },
4528
+ {
4529
+ permission: "plan_exit",
4530
+ action: "deny",
4531
+ pattern: "*"
4532
+ }
4533
+ ];
4534
+ function title() {
4535
+ if (args.title === void 0) return;
4536
+ if (args.title !== "") return args.title;
4537
+ return message.slice(0, 50) + (message.length > 50 ? "..." : "");
4538
+ }
4539
+ async function session(sdk) {
4540
+ const baseID = args.continue ? (await sdk.session.list()).data?.find((s) => !s.parentID)?.id : args.session;
4541
+ if (baseID && args.fork) {
4542
+ const forked = await sdk.session.fork({ sessionID: baseID });
4543
+ return forked.data?.id;
4544
+ }
4545
+ if (baseID) return baseID;
4546
+ const name = title();
4547
+ const result = await sdk.session.create({ title: name, permission: rules });
4548
+ return result.data?.id;
4549
+ }
4550
+ async function share(sdk, sessionID) {
4551
+ const cfg = await sdk.config.get();
4552
+ if (!cfg.data) return;
4553
+ if (cfg.data.share !== "auto" && !Flag.OPENCODE_AUTO_SHARE && !args.share) return;
4554
+ const res = await sdk.session.share({ sessionID }).catch((error) => {
4555
+ if (error instanceof Error && error.message.includes("disabled")) {
4556
+ UI.println(UI.Style.TEXT_DANGER_BOLD + "! " + error.message);
4557
+ }
4558
+ return { error };
4559
+ });
4560
+ if (!res.error && "data" in res && res.data?.share?.url) {
4561
+ UI.println(UI.Style.TEXT_INFO_BOLD + "~ " + res.data.share.url);
4562
+ }
4563
+ }
4564
+ async function execute(sdk) {
4565
+ function tool(part) {
4566
+ try {
4567
+ if (part.tool === "bash") return bash(props(part));
4568
+ if (part.tool === "glob") return glob(props(part));
4569
+ if (part.tool === "grep") return grep(props(part));
4570
+ if (part.tool === "list") return list(props(part));
4571
+ if (part.tool === "read") return read(props(part));
4572
+ if (part.tool === "write") return write(props(part));
4573
+ if (part.tool === "webfetch") return webfetch(props(part));
4574
+ if (part.tool === "edit") return edit(props(part));
4575
+ if (part.tool === "codesearch") return codesearch(props(part));
4576
+ if (part.tool === "websearch") return websearch(props(part));
4577
+ if (part.tool === "task") return task(props(part));
4578
+ if (part.tool === "todowrite") return todo(props(part));
4579
+ if (part.tool === "skill") return skill(props(part));
4580
+ return fallback(part);
4581
+ } catch {
4582
+ return fallback(part);
4583
+ }
4584
+ }
4585
+ function emit(type, data) {
4586
+ if (args.format === "json") {
4587
+ process.stdout.write(JSON.stringify({ type, timestamp: Date.now(), sessionID, ...data }) + EOL2);
4588
+ return true;
4589
+ }
4590
+ return false;
4591
+ }
4592
+ const events = await sdk.event.subscribe();
4593
+ let error;
4594
+ async function loop() {
4595
+ const toggles = /* @__PURE__ */ new Map();
4596
+ for await (const event of events.stream) {
4597
+ if (event.type === "message.updated" && event.properties.info.role === "assistant" && args.format !== "json" && toggles.get("start") !== true) {
4598
+ UI.empty();
4599
+ UI.println(`> ${event.properties.info.agent} \xB7 ${event.properties.info.modelID}`);
4600
+ UI.empty();
4601
+ toggles.set("start", true);
4602
+ }
4603
+ if (event.type === "message.part.updated") {
4604
+ const part = event.properties.part;
4605
+ if (part.sessionID !== sessionID) continue;
4606
+ if (part.type === "tool" && (part.state.status === "completed" || part.state.status === "error")) {
4607
+ if (emit("tool_use", { part })) continue;
4608
+ if (part.state.status === "completed") {
4609
+ tool(part);
4610
+ continue;
4611
+ }
4612
+ inline({
4613
+ icon: "\u2717",
4614
+ title: `${part.tool} failed`
4615
+ });
4616
+ UI.error(part.state.error);
4617
+ }
4618
+ if (part.type === "tool" && part.tool === "task" && part.state.status === "running" && args.format !== "json") {
4619
+ if (toggles.get(part.id) === true) continue;
4620
+ task(props(part));
4621
+ toggles.set(part.id, true);
4622
+ }
4623
+ if (part.type === "step-start") {
4624
+ if (emit("step_start", { part })) continue;
4625
+ }
4626
+ if (part.type === "step-finish") {
4627
+ if (emit("step_finish", { part })) continue;
4628
+ }
4629
+ if (part.type === "text" && part.time?.end) {
4630
+ if (emit("text", { part })) continue;
4631
+ const text = part.text.trim();
4632
+ if (!text) continue;
4633
+ if (!process.stdout.isTTY) {
4634
+ process.stdout.write(text + EOL2);
4635
+ continue;
4636
+ }
4637
+ UI.empty();
4638
+ UI.println(text);
4639
+ UI.empty();
4640
+ }
4641
+ if (part.type === "reasoning" && part.time?.end && args.thinking) {
4642
+ if (emit("reasoning", { part })) continue;
4643
+ const text = part.text.trim();
4644
+ if (!text) continue;
4645
+ const line = `Thinking: ${text}`;
4646
+ if (process.stdout.isTTY) {
4647
+ UI.empty();
4648
+ UI.println(`${UI.Style.TEXT_DIM}\x1B[3m${line}\x1B[0m${UI.Style.TEXT_NORMAL}`);
4649
+ UI.empty();
4650
+ continue;
4651
+ }
4652
+ process.stdout.write(line + EOL2);
4653
+ }
4654
+ }
4655
+ if (event.type === "session.error") {
4656
+ const props2 = event.properties;
4657
+ if (props2.sessionID !== sessionID || !props2.error) continue;
4658
+ let err = String(props2.error.name);
4659
+ if ("data" in props2.error && props2.error.data && "message" in props2.error.data) {
4660
+ err = String(props2.error.data.message);
4661
+ }
4662
+ error = error ? error + EOL2 + err : err;
4663
+ if (emit("error", { error: props2.error })) continue;
4664
+ UI.error(err);
4665
+ }
4666
+ if (event.type === "session.status" && event.properties.sessionID === sessionID && event.properties.status.type === "idle") {
4667
+ break;
4668
+ }
4669
+ if (event.type === "permission.asked") {
4670
+ const permission = event.properties;
4671
+ if (permission.sessionID !== sessionID) continue;
4672
+ if (args["dangerously-skip-permissions"]) {
4673
+ await sdk.permission.reply({
4674
+ requestID: permission.id,
4675
+ reply: "once"
4676
+ });
4677
+ } else {
4678
+ UI.println(
4679
+ UI.Style.TEXT_WARNING_BOLD + "!",
4680
+ UI.Style.TEXT_NORMAL + `permission requested: ${permission.permission} (${permission.patterns.join(", ")}); auto-rejecting`
4681
+ );
4682
+ await sdk.permission.reply({
4683
+ requestID: permission.id,
4684
+ reply: "reject"
4685
+ });
4686
+ }
4687
+ }
4688
+ }
4689
+ }
4690
+ const agent = await (async () => {
4691
+ if (!args.agent) return void 0;
4692
+ if (args.attach) {
4693
+ const modes = await sdk.app.agents(void 0, { throwOnError: true }).then((x) => x.data ?? []).catch(() => void 0);
4694
+ if (!modes) {
4695
+ UI.println(
4696
+ UI.Style.TEXT_WARNING_BOLD + "!",
4697
+ UI.Style.TEXT_NORMAL,
4698
+ `failed to list agents from ${args.attach}. Falling back to default agent`
4699
+ );
4700
+ return void 0;
4701
+ }
4702
+ const agent2 = modes.find((a) => a.name === args.agent);
4703
+ if (!agent2) {
4704
+ UI.println(
4705
+ UI.Style.TEXT_WARNING_BOLD + "!",
4706
+ UI.Style.TEXT_NORMAL,
4707
+ `agent "${args.agent}" not found. Falling back to default agent`
4708
+ );
4709
+ return void 0;
4710
+ }
4711
+ if (agent2.mode === "subagent") {
4712
+ UI.println(
4713
+ UI.Style.TEXT_WARNING_BOLD + "!",
4714
+ UI.Style.TEXT_NORMAL,
4715
+ `agent "${args.agent}" is a subagent, not a primary agent. Falling back to default agent`
4716
+ );
4717
+ return void 0;
4718
+ }
4719
+ return args.agent;
4720
+ }
4721
+ const entry = await Agent.get(args.agent);
4722
+ if (!entry) {
4723
+ UI.println(
4724
+ UI.Style.TEXT_WARNING_BOLD + "!",
4725
+ UI.Style.TEXT_NORMAL,
4726
+ `agent "${args.agent}" not found. Falling back to default agent`
4727
+ );
4728
+ return void 0;
4729
+ }
4730
+ if (entry.mode === "subagent") {
4731
+ UI.println(
4732
+ UI.Style.TEXT_WARNING_BOLD + "!",
4733
+ UI.Style.TEXT_NORMAL,
4734
+ `agent "${args.agent}" is a subagent, not a primary agent. Falling back to default agent`
4735
+ );
4736
+ return void 0;
4737
+ }
4738
+ return args.agent;
4739
+ })();
4740
+ const sessionID = await session(sdk);
4741
+ if (!sessionID) {
4742
+ UI.error("Session not found");
4743
+ process.exit(1);
4744
+ }
4745
+ await share(sdk, sessionID);
4746
+ loop().catch((e) => {
4747
+ console.error(e);
4748
+ process.exit(1);
4749
+ });
4750
+ if (args.command) {
4751
+ await sdk.session.command({
4752
+ sessionID,
4753
+ agent,
4754
+ model: args.model,
4755
+ command: args.command,
4756
+ arguments: message,
4757
+ variant: args.variant
4758
+ });
4759
+ } else {
4760
+ const model = args.model ? Provider.parseModel(args.model) : void 0;
4761
+ await sdk.session.prompt({
4762
+ sessionID,
4763
+ agent,
4764
+ model,
4765
+ variant: args.variant,
4766
+ parts: [...files, { type: "text", text: message }]
4767
+ });
4768
+ }
4769
+ }
4770
+ if (args.attach) {
4771
+ const headers = (() => {
4772
+ const password = args.password ?? process.env.OPENCODE_SERVER_PASSWORD;
4773
+ if (!password) return void 0;
4774
+ const username = process.env.OPENCODE_SERVER_USERNAME ?? "opencode";
4775
+ const auth = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
4776
+ return { Authorization: auth };
4777
+ })();
4778
+ const sdk = createOpencodeClient({ baseUrl: args.attach, directory, headers });
4779
+ return await execute(sdk);
4780
+ }
4781
+ await bootstrap(process.cwd(), async () => {
4782
+ const fetchFn = (async (input, init) => {
4783
+ const request = new Request(input, init);
4784
+ return Server.Default().fetch(request);
4785
+ });
4786
+ const sdk = createOpencodeClient({ baseUrl: "http://opencode.internal", fetch: fetchFn });
4787
+ await execute(sdk);
4788
+ });
4789
+ }
4790
+ });
4791
+ export {
4792
+ RunCommand
4793
+ };
4794
+ //# sourceMappingURL=run-TP5VUB6L.js.map