@opencode-ai/sdk 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "exports": {
6
6
  ".": "./dist/index.js"
7
7
  },
8
- "version": "0.0.1",
8
+ "version": "0.0.3",
9
9
  "files": [
10
10
  "dist"
11
11
  ],
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { $ } from "bun";
3
- import fs from "fs/promises";
4
- import path from "path";
5
- console.log("=== Generating JS SDK ===");
6
- console.log();
7
- import { createClient } from "@hey-api/openapi-ts";
8
- const dir = new URL("..", import.meta.url).pathname;
9
- await fs.rm(path.join(dir, "src/gen"), { recursive: true, force: true });
10
- await $ `bun run ../../opencode/src/index.ts generate > openapi.json`.cwd(dir);
11
- await createClient({
12
- input: "./openapi.json",
13
- output: "./src/gen",
14
- plugins: [
15
- {
16
- name: "@hey-api/typescript",
17
- exportFromIndex: false,
18
- },
19
- {
20
- name: "@hey-api/sdk",
21
- instance: "OpencodeClient",
22
- exportFromIndex: false,
23
- auth: false,
24
- },
25
- {
26
- name: "@hey-api/client-fetch",
27
- exportFromIndex: false,
28
- baseUrl: "http://localhost:4096",
29
- },
30
- ],
31
- });
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env bun
2
- import { $ } from "bun";
3
- await import("./generate.js");
4
- await $ `bun tsc`;
@@ -1,145 +0,0 @@
1
- import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils';
2
- export const createClient = (config = {}) => {
3
- let _config = mergeConfigs(createConfig(), config);
4
- const getConfig = () => ({ ..._config });
5
- const setConfig = (config) => {
6
- _config = mergeConfigs(_config, config);
7
- return getConfig();
8
- };
9
- const interceptors = createInterceptors();
10
- const request = async (options) => {
11
- const opts = {
12
- ..._config,
13
- ...options,
14
- fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
15
- headers: mergeHeaders(_config.headers, options.headers),
16
- };
17
- if (opts.security) {
18
- await setAuthParams({
19
- ...opts,
20
- security: opts.security,
21
- });
22
- }
23
- if (opts.requestValidator) {
24
- await opts.requestValidator(opts);
25
- }
26
- if (opts.body && opts.bodySerializer) {
27
- opts.body = opts.bodySerializer(opts.body);
28
- }
29
- // remove Content-Type header if body is empty to avoid sending invalid requests
30
- if (opts.body === undefined || opts.body === '') {
31
- opts.headers.delete('Content-Type');
32
- }
33
- const url = buildUrl(opts);
34
- const requestInit = {
35
- redirect: 'follow',
36
- ...opts,
37
- };
38
- let request = new Request(url, requestInit);
39
- for (const fn of interceptors.request._fns) {
40
- if (fn) {
41
- request = await fn(request, opts);
42
- }
43
- }
44
- // fetch must be assigned here, otherwise it would throw the error:
45
- // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
46
- const _fetch = opts.fetch;
47
- let response = await _fetch(request);
48
- for (const fn of interceptors.response._fns) {
49
- if (fn) {
50
- response = await fn(response, request, opts);
51
- }
52
- }
53
- const result = {
54
- request,
55
- response,
56
- };
57
- if (response.ok) {
58
- if (response.status === 204 ||
59
- response.headers.get('Content-Length') === '0') {
60
- return opts.responseStyle === 'data'
61
- ? {}
62
- : {
63
- data: {},
64
- ...result,
65
- };
66
- }
67
- const parseAs = (opts.parseAs === 'auto'
68
- ? getParseAs(response.headers.get('Content-Type'))
69
- : opts.parseAs) ?? 'json';
70
- let data;
71
- switch (parseAs) {
72
- case 'arrayBuffer':
73
- case 'blob':
74
- case 'formData':
75
- case 'json':
76
- case 'text':
77
- data = await response[parseAs]();
78
- break;
79
- case 'stream':
80
- return opts.responseStyle === 'data'
81
- ? response.body
82
- : {
83
- data: response.body,
84
- ...result,
85
- };
86
- }
87
- if (parseAs === 'json') {
88
- if (opts.responseValidator) {
89
- await opts.responseValidator(data);
90
- }
91
- if (opts.responseTransformer) {
92
- data = await opts.responseTransformer(data);
93
- }
94
- }
95
- return opts.responseStyle === 'data'
96
- ? data
97
- : {
98
- data,
99
- ...result,
100
- };
101
- }
102
- const textError = await response.text();
103
- let jsonError;
104
- try {
105
- jsonError = JSON.parse(textError);
106
- }
107
- catch {
108
- // noop
109
- }
110
- const error = jsonError ?? textError;
111
- let finalError = error;
112
- for (const fn of interceptors.error._fns) {
113
- if (fn) {
114
- finalError = (await fn(error, response, request, opts));
115
- }
116
- }
117
- finalError = finalError || {};
118
- if (opts.throwOnError) {
119
- throw finalError;
120
- }
121
- // TODO: we probably want to return error and improve types
122
- return opts.responseStyle === 'data'
123
- ? undefined
124
- : {
125
- error: finalError,
126
- ...result,
127
- };
128
- };
129
- return {
130
- buildUrl,
131
- connect: (options) => request({ ...options, method: 'CONNECT' }),
132
- delete: (options) => request({ ...options, method: 'DELETE' }),
133
- get: (options) => request({ ...options, method: 'GET' }),
134
- getConfig,
135
- head: (options) => request({ ...options, method: 'HEAD' }),
136
- interceptors,
137
- options: (options) => request({ ...options, method: 'OPTIONS' }),
138
- patch: (options) => request({ ...options, method: 'PATCH' }),
139
- post: (options) => request({ ...options, method: 'POST' }),
140
- put: (options) => request({ ...options, method: 'PUT' }),
141
- request,
142
- setConfig,
143
- trace: (options) => request({ ...options, method: 'TRACE' }),
144
- };
145
- };
@@ -1,4 +0,0 @@
1
- export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer';
2
- export { buildClientParams } from '../core/params';
3
- export { createClient } from './client';
4
- export { createConfig, mergeHeaders } from './utils';
File without changes
@@ -1,284 +0,0 @@
1
- import { getAuthToken } from '../core/auth';
2
- import { jsonBodySerializer } from '../core/bodySerializer';
3
- import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from '../core/pathSerializer';
4
- const PATH_PARAM_RE = /\{[^{}]+\}/g;
5
- const defaultPathSerializer = ({ path, url: _url }) => {
6
- let url = _url;
7
- const matches = _url.match(PATH_PARAM_RE);
8
- if (matches) {
9
- for (const match of matches) {
10
- let explode = false;
11
- let name = match.substring(1, match.length - 1);
12
- let style = 'simple';
13
- if (name.endsWith('*')) {
14
- explode = true;
15
- name = name.substring(0, name.length - 1);
16
- }
17
- if (name.startsWith('.')) {
18
- name = name.substring(1);
19
- style = 'label';
20
- }
21
- else if (name.startsWith(';')) {
22
- name = name.substring(1);
23
- style = 'matrix';
24
- }
25
- const value = path[name];
26
- if (value === undefined || value === null) {
27
- continue;
28
- }
29
- if (Array.isArray(value)) {
30
- url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
31
- continue;
32
- }
33
- if (typeof value === 'object') {
34
- url = url.replace(match, serializeObjectParam({
35
- explode,
36
- name,
37
- style,
38
- value: value,
39
- valueOnly: true,
40
- }));
41
- continue;
42
- }
43
- if (style === 'matrix') {
44
- url = url.replace(match, `;${serializePrimitiveParam({
45
- name,
46
- value: value,
47
- })}`);
48
- continue;
49
- }
50
- const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
51
- url = url.replace(match, replaceValue);
52
- }
53
- }
54
- return url;
55
- };
56
- export const createQuerySerializer = ({ allowReserved, array, object, } = {}) => {
57
- const querySerializer = (queryParams) => {
58
- const search = [];
59
- if (queryParams && typeof queryParams === 'object') {
60
- for (const name in queryParams) {
61
- const value = queryParams[name];
62
- if (value === undefined || value === null) {
63
- continue;
64
- }
65
- if (Array.isArray(value)) {
66
- const serializedArray = serializeArrayParam({
67
- allowReserved,
68
- explode: true,
69
- name,
70
- style: 'form',
71
- value,
72
- ...array,
73
- });
74
- if (serializedArray)
75
- search.push(serializedArray);
76
- }
77
- else if (typeof value === 'object') {
78
- const serializedObject = serializeObjectParam({
79
- allowReserved,
80
- explode: true,
81
- name,
82
- style: 'deepObject',
83
- value: value,
84
- ...object,
85
- });
86
- if (serializedObject)
87
- search.push(serializedObject);
88
- }
89
- else {
90
- const serializedPrimitive = serializePrimitiveParam({
91
- allowReserved,
92
- name,
93
- value: value,
94
- });
95
- if (serializedPrimitive)
96
- search.push(serializedPrimitive);
97
- }
98
- }
99
- }
100
- return search.join('&');
101
- };
102
- return querySerializer;
103
- };
104
- /**
105
- * Infers parseAs value from provided Content-Type header.
106
- */
107
- export const getParseAs = (contentType) => {
108
- if (!contentType) {
109
- // If no Content-Type header is provided, the best we can do is return the raw response body,
110
- // which is effectively the same as the 'stream' option.
111
- return 'stream';
112
- }
113
- const cleanContent = contentType.split(';')[0]?.trim();
114
- if (!cleanContent) {
115
- return;
116
- }
117
- if (cleanContent.startsWith('application/json') ||
118
- cleanContent.endsWith('+json')) {
119
- return 'json';
120
- }
121
- if (cleanContent === 'multipart/form-data') {
122
- return 'formData';
123
- }
124
- if (['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))) {
125
- return 'blob';
126
- }
127
- if (cleanContent.startsWith('text/')) {
128
- return 'text';
129
- }
130
- return;
131
- };
132
- export const setAuthParams = async ({ security, ...options }) => {
133
- for (const auth of security) {
134
- const token = await getAuthToken(auth, options.auth);
135
- if (!token) {
136
- continue;
137
- }
138
- const name = auth.name ?? 'Authorization';
139
- switch (auth.in) {
140
- case 'query':
141
- if (!options.query) {
142
- options.query = {};
143
- }
144
- options.query[name] = token;
145
- break;
146
- case 'cookie':
147
- options.headers.append('Cookie', `${name}=${token}`);
148
- break;
149
- case 'header':
150
- default:
151
- options.headers.set(name, token);
152
- break;
153
- }
154
- return;
155
- }
156
- };
157
- export const buildUrl = (options) => {
158
- const url = getUrl({
159
- baseUrl: options.baseUrl,
160
- path: options.path,
161
- query: options.query,
162
- querySerializer: typeof options.querySerializer === 'function'
163
- ? options.querySerializer
164
- : createQuerySerializer(options.querySerializer),
165
- url: options.url,
166
- });
167
- return url;
168
- };
169
- export const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
170
- const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
171
- let url = (baseUrl ?? '') + pathUrl;
172
- if (path) {
173
- url = defaultPathSerializer({ path, url });
174
- }
175
- let search = query ? querySerializer(query) : '';
176
- if (search.startsWith('?')) {
177
- search = search.substring(1);
178
- }
179
- if (search) {
180
- url += `?${search}`;
181
- }
182
- return url;
183
- };
184
- export const mergeConfigs = (a, b) => {
185
- const config = { ...a, ...b };
186
- if (config.baseUrl?.endsWith('/')) {
187
- config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
188
- }
189
- config.headers = mergeHeaders(a.headers, b.headers);
190
- return config;
191
- };
192
- export const mergeHeaders = (...headers) => {
193
- const mergedHeaders = new Headers();
194
- for (const header of headers) {
195
- if (!header || typeof header !== 'object') {
196
- continue;
197
- }
198
- const iterator = header instanceof Headers ? header.entries() : Object.entries(header);
199
- for (const [key, value] of iterator) {
200
- if (value === null) {
201
- mergedHeaders.delete(key);
202
- }
203
- else if (Array.isArray(value)) {
204
- for (const v of value) {
205
- mergedHeaders.append(key, v);
206
- }
207
- }
208
- else if (value !== undefined) {
209
- // assume object headers are meant to be JSON stringified, i.e. their
210
- // content value in OpenAPI specification is 'application/json'
211
- mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
212
- }
213
- }
214
- }
215
- return mergedHeaders;
216
- };
217
- class Interceptors {
218
- _fns;
219
- constructor() {
220
- this._fns = [];
221
- }
222
- clear() {
223
- this._fns = [];
224
- }
225
- getInterceptorIndex(id) {
226
- if (typeof id === 'number') {
227
- return this._fns[id] ? id : -1;
228
- }
229
- else {
230
- return this._fns.indexOf(id);
231
- }
232
- }
233
- exists(id) {
234
- const index = this.getInterceptorIndex(id);
235
- return !!this._fns[index];
236
- }
237
- eject(id) {
238
- const index = this.getInterceptorIndex(id);
239
- if (this._fns[index]) {
240
- this._fns[index] = null;
241
- }
242
- }
243
- update(id, fn) {
244
- const index = this.getInterceptorIndex(id);
245
- if (this._fns[index]) {
246
- this._fns[index] = fn;
247
- return id;
248
- }
249
- else {
250
- return false;
251
- }
252
- }
253
- use(fn) {
254
- this._fns = [...this._fns, fn];
255
- return this._fns.length - 1;
256
- }
257
- }
258
- // do not add `Middleware` as return type so we can use _fns internally
259
- export const createInterceptors = () => ({
260
- error: new Interceptors(),
261
- request: new Interceptors(),
262
- response: new Interceptors(),
263
- });
264
- const defaultQuerySerializer = createQuerySerializer({
265
- allowReserved: false,
266
- array: {
267
- explode: true,
268
- style: 'form',
269
- },
270
- object: {
271
- explode: true,
272
- style: 'deepObject',
273
- },
274
- });
275
- const defaultHeaders = {
276
- 'Content-Type': 'application/json',
277
- };
278
- export const createConfig = (override = {}) => ({
279
- ...jsonBodySerializer,
280
- headers: defaultHeaders,
281
- parseAs: 'auto',
282
- querySerializer: defaultQuerySerializer,
283
- ...override,
284
- });
@@ -1,5 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- import { createClient, createConfig } from './client';
3
- export const client = createClient(createConfig({
4
- baseUrl: 'http://localhost:4096'
5
- }));
@@ -1,13 +0,0 @@
1
- export const getAuthToken = async (auth, callback) => {
2
- const token = typeof callback === 'function' ? await callback(auth) : callback;
3
- if (!token) {
4
- return;
5
- }
6
- if (auth.scheme === 'bearer') {
7
- return `Bearer ${token}`;
8
- }
9
- if (auth.scheme === 'basic') {
10
- return `Basic ${btoa(token)}`;
11
- }
12
- return token;
13
- };
@@ -1,53 +0,0 @@
1
- const serializeFormDataPair = (data, key, value) => {
2
- if (typeof value === 'string' || value instanceof Blob) {
3
- data.append(key, value);
4
- }
5
- else {
6
- data.append(key, JSON.stringify(value));
7
- }
8
- };
9
- const serializeUrlSearchParamsPair = (data, key, value) => {
10
- if (typeof value === 'string') {
11
- data.append(key, value);
12
- }
13
- else {
14
- data.append(key, JSON.stringify(value));
15
- }
16
- };
17
- export const formDataBodySerializer = {
18
- bodySerializer: (body) => {
19
- const data = new FormData();
20
- Object.entries(body).forEach(([key, value]) => {
21
- if (value === undefined || value === null) {
22
- return;
23
- }
24
- if (Array.isArray(value)) {
25
- value.forEach((v) => serializeFormDataPair(data, key, v));
26
- }
27
- else {
28
- serializeFormDataPair(data, key, value);
29
- }
30
- });
31
- return data;
32
- },
33
- };
34
- export const jsonBodySerializer = {
35
- bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === 'bigint' ? value.toString() : value),
36
- };
37
- export const urlSearchParamsBodySerializer = {
38
- bodySerializer: (body) => {
39
- const data = new URLSearchParams();
40
- Object.entries(body).forEach(([key, value]) => {
41
- if (value === undefined || value === null) {
42
- return;
43
- }
44
- if (Array.isArray(value)) {
45
- value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
46
- }
47
- else {
48
- serializeUrlSearchParamsPair(data, key, value);
49
- }
50
- });
51
- return data.toString();
52
- },
53
- };
@@ -1,87 +0,0 @@
1
- const extraPrefixesMap = {
2
- $body_: 'body',
3
- $headers_: 'headers',
4
- $path_: 'path',
5
- $query_: 'query',
6
- };
7
- const extraPrefixes = Object.entries(extraPrefixesMap);
8
- const buildKeyMap = (fields, map) => {
9
- if (!map) {
10
- map = new Map();
11
- }
12
- for (const config of fields) {
13
- if ('in' in config) {
14
- if (config.key) {
15
- map.set(config.key, {
16
- in: config.in,
17
- map: config.map,
18
- });
19
- }
20
- }
21
- else if (config.args) {
22
- buildKeyMap(config.args, map);
23
- }
24
- }
25
- return map;
26
- };
27
- const stripEmptySlots = (params) => {
28
- for (const [slot, value] of Object.entries(params)) {
29
- if (value && typeof value === 'object' && !Object.keys(value).length) {
30
- delete params[slot];
31
- }
32
- }
33
- };
34
- export const buildClientParams = (args, fields) => {
35
- const params = {
36
- body: {},
37
- headers: {},
38
- path: {},
39
- query: {},
40
- };
41
- const map = buildKeyMap(fields);
42
- let config;
43
- for (const [index, arg] of args.entries()) {
44
- if (fields[index]) {
45
- config = fields[index];
46
- }
47
- if (!config) {
48
- continue;
49
- }
50
- if ('in' in config) {
51
- if (config.key) {
52
- const field = map.get(config.key);
53
- const name = field.map || config.key;
54
- params[field.in][name] = arg;
55
- }
56
- else {
57
- params.body = arg;
58
- }
59
- }
60
- else {
61
- for (const [key, value] of Object.entries(arg ?? {})) {
62
- const field = map.get(key);
63
- if (field) {
64
- const name = field.map || key;
65
- params[field.in][name] = value;
66
- }
67
- else {
68
- const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
69
- if (extra) {
70
- const [prefix, slot] = extra;
71
- params[slot][key.slice(prefix.length)] = value;
72
- }
73
- else {
74
- for (const [slot, allowed] of Object.entries(config.allowExtra ?? {})) {
75
- if (allowed) {
76
- params[slot][key] = value;
77
- break;
78
- }
79
- }
80
- }
81
- }
82
- }
83
- }
84
- }
85
- stripEmptySlots(params);
86
- return params;
87
- };
@@ -1,113 +0,0 @@
1
- export const separatorArrayExplode = (style) => {
2
- switch (style) {
3
- case 'label':
4
- return '.';
5
- case 'matrix':
6
- return ';';
7
- case 'simple':
8
- return ',';
9
- default:
10
- return '&';
11
- }
12
- };
13
- export const separatorArrayNoExplode = (style) => {
14
- switch (style) {
15
- case 'form':
16
- return ',';
17
- case 'pipeDelimited':
18
- return '|';
19
- case 'spaceDelimited':
20
- return '%20';
21
- default:
22
- return ',';
23
- }
24
- };
25
- export const separatorObjectExplode = (style) => {
26
- switch (style) {
27
- case 'label':
28
- return '.';
29
- case 'matrix':
30
- return ';';
31
- case 'simple':
32
- return ',';
33
- default:
34
- return '&';
35
- }
36
- };
37
- export const serializeArrayParam = ({ allowReserved, explode, name, style, value, }) => {
38
- if (!explode) {
39
- const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
40
- switch (style) {
41
- case 'label':
42
- return `.${joinedValues}`;
43
- case 'matrix':
44
- return `;${name}=${joinedValues}`;
45
- case 'simple':
46
- return joinedValues;
47
- default:
48
- return `${name}=${joinedValues}`;
49
- }
50
- }
51
- const separator = separatorArrayExplode(style);
52
- const joinedValues = value
53
- .map((v) => {
54
- if (style === 'label' || style === 'simple') {
55
- return allowReserved ? v : encodeURIComponent(v);
56
- }
57
- return serializePrimitiveParam({
58
- allowReserved,
59
- name,
60
- value: v,
61
- });
62
- })
63
- .join(separator);
64
- return style === 'label' || style === 'matrix'
65
- ? separator + joinedValues
66
- : joinedValues;
67
- };
68
- export const serializePrimitiveParam = ({ allowReserved, name, value, }) => {
69
- if (value === undefined || value === null) {
70
- return '';
71
- }
72
- if (typeof value === 'object') {
73
- throw new Error('Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.');
74
- }
75
- return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
76
- };
77
- export const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly, }) => {
78
- if (value instanceof Date) {
79
- return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
80
- }
81
- if (style !== 'deepObject' && !explode) {
82
- let values = [];
83
- Object.entries(value).forEach(([key, v]) => {
84
- values = [
85
- ...values,
86
- key,
87
- allowReserved ? v : encodeURIComponent(v),
88
- ];
89
- });
90
- const joinedValues = values.join(',');
91
- switch (style) {
92
- case 'form':
93
- return `${name}=${joinedValues}`;
94
- case 'label':
95
- return `.${joinedValues}`;
96
- case 'matrix':
97
- return `;${name}=${joinedValues}`;
98
- default:
99
- return joinedValues;
100
- }
101
- }
102
- const separator = separatorObjectExplode(style);
103
- const joinedValues = Object.entries(value)
104
- .map(([key, v]) => serializePrimitiveParam({
105
- allowReserved,
106
- name: style === 'deepObject' ? `${name}[${key}]` : key,
107
- value: v,
108
- }))
109
- .join(separator);
110
- return style === 'label' || style === 'matrix'
111
- ? separator + joinedValues
112
- : joinedValues;
113
- };
File without changes
@@ -1,291 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
2
- import { client as _heyApiClient } from './client.gen';
3
- class _HeyApiClient {
4
- _client = _heyApiClient;
5
- constructor(args) {
6
- if (args?.client) {
7
- this._client = args.client;
8
- }
9
- }
10
- }
11
- class Event extends _HeyApiClient {
12
- /**
13
- * Get events
14
- */
15
- subscribe(options) {
16
- return (options?.client ?? this._client).get({
17
- url: '/event',
18
- ...options
19
- });
20
- }
21
- }
22
- class App extends _HeyApiClient {
23
- /**
24
- * Get app info
25
- */
26
- get(options) {
27
- return (options?.client ?? this._client).get({
28
- url: '/app',
29
- ...options
30
- });
31
- }
32
- /**
33
- * Initialize the app
34
- */
35
- init(options) {
36
- return (options?.client ?? this._client).post({
37
- url: '/app/init',
38
- ...options
39
- });
40
- }
41
- /**
42
- * Write a log entry to the server logs
43
- */
44
- log(options) {
45
- return (options?.client ?? this._client).post({
46
- url: '/log',
47
- ...options,
48
- headers: {
49
- 'Content-Type': 'application/json',
50
- ...options?.headers
51
- }
52
- });
53
- }
54
- /**
55
- * List all modes
56
- */
57
- modes(options) {
58
- return (options?.client ?? this._client).get({
59
- url: '/mode',
60
- ...options
61
- });
62
- }
63
- }
64
- class Config extends _HeyApiClient {
65
- /**
66
- * Get config info
67
- */
68
- get(options) {
69
- return (options?.client ?? this._client).get({
70
- url: '/config',
71
- ...options
72
- });
73
- }
74
- /**
75
- * List all providers
76
- */
77
- providers(options) {
78
- return (options?.client ?? this._client).get({
79
- url: '/config/providers',
80
- ...options
81
- });
82
- }
83
- }
84
- class Session extends _HeyApiClient {
85
- /**
86
- * List all sessions
87
- */
88
- list(options) {
89
- return (options?.client ?? this._client).get({
90
- url: '/session',
91
- ...options
92
- });
93
- }
94
- /**
95
- * Create a new session
96
- */
97
- create(options) {
98
- return (options?.client ?? this._client).post({
99
- url: '/session',
100
- ...options
101
- });
102
- }
103
- /**
104
- * Delete a session and all its data
105
- */
106
- delete(options) {
107
- return (options.client ?? this._client).delete({
108
- url: '/session/{id}',
109
- ...options
110
- });
111
- }
112
- /**
113
- * Analyze the app and create an AGENTS.md file
114
- */
115
- init(options) {
116
- return (options.client ?? this._client).post({
117
- url: '/session/{id}/init',
118
- ...options,
119
- headers: {
120
- 'Content-Type': 'application/json',
121
- ...options.headers
122
- }
123
- });
124
- }
125
- /**
126
- * Abort a session
127
- */
128
- abort(options) {
129
- return (options.client ?? this._client).post({
130
- url: '/session/{id}/abort',
131
- ...options
132
- });
133
- }
134
- /**
135
- * Unshare the session
136
- */
137
- unshare(options) {
138
- return (options.client ?? this._client).delete({
139
- url: '/session/{id}/share',
140
- ...options
141
- });
142
- }
143
- /**
144
- * Share a session
145
- */
146
- share(options) {
147
- return (options.client ?? this._client).post({
148
- url: '/session/{id}/share',
149
- ...options
150
- });
151
- }
152
- /**
153
- * Summarize the session
154
- */
155
- summarize(options) {
156
- return (options.client ?? this._client).post({
157
- url: '/session/{id}/summarize',
158
- ...options,
159
- headers: {
160
- 'Content-Type': 'application/json',
161
- ...options.headers
162
- }
163
- });
164
- }
165
- /**
166
- * List messages for a session
167
- */
168
- messages(options) {
169
- return (options.client ?? this._client).get({
170
- url: '/session/{id}/message',
171
- ...options
172
- });
173
- }
174
- /**
175
- * Create and send a new message to a session
176
- */
177
- chat(options) {
178
- return (options.client ?? this._client).post({
179
- url: '/session/{id}/message',
180
- ...options,
181
- headers: {
182
- 'Content-Type': 'application/json',
183
- ...options.headers
184
- }
185
- });
186
- }
187
- /**
188
- * Revert a message
189
- */
190
- revert(options) {
191
- return (options.client ?? this._client).post({
192
- url: '/session/{id}/revert',
193
- ...options,
194
- headers: {
195
- 'Content-Type': 'application/json',
196
- ...options.headers
197
- }
198
- });
199
- }
200
- /**
201
- * Restore all reverted messages
202
- */
203
- unrevert(options) {
204
- return (options.client ?? this._client).post({
205
- url: '/session/{id}/unrevert',
206
- ...options
207
- });
208
- }
209
- }
210
- class Find extends _HeyApiClient {
211
- /**
212
- * Find text in files
213
- */
214
- text(options) {
215
- return (options.client ?? this._client).get({
216
- url: '/find',
217
- ...options
218
- });
219
- }
220
- /**
221
- * Find files
222
- */
223
- files(options) {
224
- return (options.client ?? this._client).get({
225
- url: '/find/file',
226
- ...options
227
- });
228
- }
229
- /**
230
- * Find workspace symbols
231
- */
232
- symbols(options) {
233
- return (options.client ?? this._client).get({
234
- url: '/find/symbol',
235
- ...options
236
- });
237
- }
238
- }
239
- class File extends _HeyApiClient {
240
- /**
241
- * Read a file
242
- */
243
- read(options) {
244
- return (options.client ?? this._client).get({
245
- url: '/file',
246
- ...options
247
- });
248
- }
249
- /**
250
- * Get file status
251
- */
252
- status(options) {
253
- return (options?.client ?? this._client).get({
254
- url: '/file/status',
255
- ...options
256
- });
257
- }
258
- }
259
- class Tui extends _HeyApiClient {
260
- /**
261
- * Append prompt to the TUI
262
- */
263
- appendPrompt(options) {
264
- return (options?.client ?? this._client).post({
265
- url: '/tui/append-prompt',
266
- ...options,
267
- headers: {
268
- 'Content-Type': 'application/json',
269
- ...options?.headers
270
- }
271
- });
272
- }
273
- /**
274
- * Open the help dialog
275
- */
276
- openHelp(options) {
277
- return (options?.client ?? this._client).post({
278
- url: '/tui/open-help',
279
- ...options
280
- });
281
- }
282
- }
283
- export class OpencodeClient extends _HeyApiClient {
284
- event = new Event({ client: this._client });
285
- app = new App({ client: this._client });
286
- config = new Config({ client: this._client });
287
- session = new Session({ client: this._client });
288
- find = new Find({ client: this._client });
289
- file = new File({ client: this._client });
290
- tui = new Tui({ client: this._client });
291
- }
@@ -1 +0,0 @@
1
- // This file is auto-generated by @hey-api/openapi-ts
package/dist/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- import { createClient } from "./gen/client/client";
2
- import { OpencodeClient } from "./gen/sdk.gen";
3
- export function createOpencodeClient(config) {
4
- const client = createClient(config);
5
- return new OpencodeClient({ client });
6
- }