@opencode-ai/sdk 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -2,6 +2,31 @@ export * from "./gen/types.gen.js";
2
2
  import { createClient } from "./gen/client/client.gen.js";
3
3
  import { OpencodeClient } from "./gen/sdk.gen.js";
4
4
  export { OpencodeClient };
5
+ function pick(value, fallback) {
6
+ if (!value)
7
+ return;
8
+ if (!fallback)
9
+ return value;
10
+ if (value === fallback)
11
+ return fallback;
12
+ if (value === encodeURIComponent(fallback))
13
+ return fallback;
14
+ return value;
15
+ }
16
+ function rewrite(request, directory) {
17
+ if (request.method !== "GET" && request.method !== "HEAD")
18
+ return request;
19
+ const value = pick(request.headers.get("x-opencode-directory"), directory);
20
+ if (!value)
21
+ return request;
22
+ const url = new URL(request.url);
23
+ if (!url.searchParams.has("directory")) {
24
+ url.searchParams.set("directory", value);
25
+ }
26
+ const next = new Request(url, request);
27
+ next.headers.delete("x-opencode-directory");
28
+ return next;
29
+ }
5
30
  export function createOpencodeClient(config) {
6
31
  if (!config?.fetch) {
7
32
  const customFetch = (req) => {
@@ -21,5 +46,6 @@ export function createOpencodeClient(config) {
21
46
  };
22
47
  }
23
48
  const client = createClient(config);
49
+ client.interceptors.request.use((request) => rewrite(request, config?.directory));
24
50
  return new OpencodeClient({ client });
25
51
  }
package/dist/v2/client.js CHANGED
@@ -2,6 +2,41 @@ export * from "./gen/types.gen.js";
2
2
  import { createClient } from "./gen/client/client.gen.js";
3
3
  import { OpencodeClient } from "./gen/sdk.gen.js";
4
4
  export { OpencodeClient };
5
+ function pick(value, fallback, encode) {
6
+ if (!value)
7
+ return;
8
+ if (!fallback)
9
+ return value;
10
+ if (value === fallback)
11
+ return fallback;
12
+ if (encode && value === encode(fallback))
13
+ return fallback;
14
+ return value;
15
+ }
16
+ function rewrite(request, values) {
17
+ if (request.method !== "GET" && request.method !== "HEAD")
18
+ return request;
19
+ const url = new URL(request.url);
20
+ let changed = false;
21
+ for (const [name, key] of [
22
+ ["x-opencode-directory", "directory"],
23
+ ["x-opencode-workspace", "workspace"],
24
+ ]) {
25
+ const value = pick(request.headers.get(name), key === "directory" ? values.directory : values.workspace, key === "directory" ? encodeURIComponent : undefined);
26
+ if (!value)
27
+ continue;
28
+ if (!url.searchParams.has(key)) {
29
+ url.searchParams.set(key, value);
30
+ }
31
+ changed = true;
32
+ }
33
+ if (!changed)
34
+ return request;
35
+ const next = new Request(url, request);
36
+ next.headers.delete("x-opencode-directory");
37
+ next.headers.delete("x-opencode-workspace");
38
+ return next;
39
+ }
5
40
  export function createOpencodeClient(config) {
6
41
  if (!config?.fetch) {
7
42
  const customFetch = (req) => {
@@ -15,11 +50,9 @@ export function createOpencodeClient(config) {
15
50
  };
16
51
  }
17
52
  if (config?.directory) {
18
- const isNonASCII = /[^\x00-\x7F]/.test(config.directory);
19
- const encodedDirectory = isNonASCII ? encodeURIComponent(config.directory) : config.directory;
20
53
  config.headers = {
21
54
  ...config.headers,
22
- "x-opencode-directory": encodedDirectory,
55
+ "x-opencode-directory": encodeURIComponent(config.directory),
23
56
  };
24
57
  }
25
58
  if (config?.experimental_workspaceID) {
@@ -29,5 +62,9 @@ export function createOpencodeClient(config) {
29
62
  };
30
63
  }
31
64
  const client = createClient(config);
65
+ client.interceptors.request.use((request) => rewrite(request, {
66
+ directory: config?.directory,
67
+ workspace: config?.experimental_workspaceID,
68
+ }));
32
69
  return new OpencodeClient({ client });
33
70
  }
@@ -100,6 +100,41 @@ export declare class Auth extends HeyApiClient {
100
100
  auth?: Auth3;
101
101
  }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AuthSetResponses, AuthSetErrors, ThrowOnError, "fields">;
102
102
  }
103
+ export declare class App extends HeyApiClient {
104
+ /**
105
+ * Write log
106
+ *
107
+ * Write a log entry to the server logs with specified level and metadata.
108
+ */
109
+ log<ThrowOnError extends boolean = false>(parameters?: {
110
+ directory?: string;
111
+ workspace?: string;
112
+ service?: string;
113
+ level?: "debug" | "info" | "error" | "warn";
114
+ message?: string;
115
+ extra?: {
116
+ [key: string]: unknown;
117
+ };
118
+ }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AppLogResponses, AppLogErrors, ThrowOnError, "fields">;
119
+ /**
120
+ * List agents
121
+ *
122
+ * Get a list of all available AI agents in the OpenCode system.
123
+ */
124
+ agents<ThrowOnError extends boolean = false>(parameters?: {
125
+ directory?: string;
126
+ workspace?: string;
127
+ }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AppAgentsResponses, unknown, ThrowOnError, "fields">;
128
+ /**
129
+ * List skills
130
+ *
131
+ * Get a list of all available skills in the OpenCode system.
132
+ */
133
+ skills<ThrowOnError extends boolean = false>(parameters?: {
134
+ directory?: string;
135
+ workspace?: string;
136
+ }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AppSkillsResponses, unknown, ThrowOnError, "fields">;
137
+ }
103
138
  export declare class Project extends HeyApiClient {
104
139
  /**
105
140
  * List all projects
@@ -1177,41 +1212,6 @@ export declare class Command extends HeyApiClient {
1177
1212
  workspace?: string;
1178
1213
  }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<CommandListResponses, unknown, ThrowOnError, "fields">;
1179
1214
  }
1180
- export declare class App extends HeyApiClient {
1181
- /**
1182
- * Write log
1183
- *
1184
- * Write a log entry to the server logs with specified level and metadata.
1185
- */
1186
- log<ThrowOnError extends boolean = false>(parameters?: {
1187
- directory?: string;
1188
- workspace?: string;
1189
- service?: string;
1190
- level?: "debug" | "info" | "error" | "warn";
1191
- message?: string;
1192
- extra?: {
1193
- [key: string]: unknown;
1194
- };
1195
- }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AppLogResponses, AppLogErrors, ThrowOnError, "fields">;
1196
- /**
1197
- * List agents
1198
- *
1199
- * Get a list of all available AI agents in the OpenCode system.
1200
- */
1201
- agents<ThrowOnError extends boolean = false>(parameters?: {
1202
- directory?: string;
1203
- workspace?: string;
1204
- }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AppAgentsResponses, unknown, ThrowOnError, "fields">;
1205
- /**
1206
- * List skills
1207
- *
1208
- * Get a list of all available skills in the OpenCode system.
1209
- */
1210
- skills<ThrowOnError extends boolean = false>(parameters?: {
1211
- directory?: string;
1212
- workspace?: string;
1213
- }, options?: Options<never, ThrowOnError>): import("./client/types.gen.js").RequestResult<AppSkillsResponses, unknown, ThrowOnError, "fields">;
1214
- }
1215
1215
  export declare class Lsp extends HeyApiClient {
1216
1216
  /**
1217
1217
  * Get LSP status
@@ -1244,6 +1244,8 @@ export declare class OpencodeClient extends HeyApiClient {
1244
1244
  get global(): Global;
1245
1245
  private _auth?;
1246
1246
  get auth(): Auth;
1247
+ private _app?;
1248
+ get app(): App;
1247
1249
  private _project?;
1248
1250
  get project(): Project;
1249
1251
  private _pty?;
@@ -1284,8 +1286,6 @@ export declare class OpencodeClient extends HeyApiClient {
1284
1286
  get vcs(): Vcs;
1285
1287
  private _command?;
1286
1288
  get command(): Command;
1287
- private _app?;
1288
- get app(): App;
1289
1289
  private _lsp?;
1290
1290
  get lsp(): Lsp;
1291
1291
  private _formatter?;
@@ -166,6 +166,77 @@ export class Auth extends HeyApiClient {
166
166
  });
167
167
  }
168
168
  }
169
+ export class App extends HeyApiClient {
170
+ /**
171
+ * Write log
172
+ *
173
+ * Write a log entry to the server logs with specified level and metadata.
174
+ */
175
+ log(parameters, options) {
176
+ const params = buildClientParams([parameters], [
177
+ {
178
+ args: [
179
+ { in: "query", key: "directory" },
180
+ { in: "query", key: "workspace" },
181
+ { in: "body", key: "service" },
182
+ { in: "body", key: "level" },
183
+ { in: "body", key: "message" },
184
+ { in: "body", key: "extra" },
185
+ ],
186
+ },
187
+ ]);
188
+ return (options?.client ?? this.client).post({
189
+ url: "/log",
190
+ ...options,
191
+ ...params,
192
+ headers: {
193
+ "Content-Type": "application/json",
194
+ ...options?.headers,
195
+ ...params.headers,
196
+ },
197
+ });
198
+ }
199
+ /**
200
+ * List agents
201
+ *
202
+ * Get a list of all available AI agents in the OpenCode system.
203
+ */
204
+ agents(parameters, options) {
205
+ const params = buildClientParams([parameters], [
206
+ {
207
+ args: [
208
+ { in: "query", key: "directory" },
209
+ { in: "query", key: "workspace" },
210
+ ],
211
+ },
212
+ ]);
213
+ return (options?.client ?? this.client).get({
214
+ url: "/agent",
215
+ ...options,
216
+ ...params,
217
+ });
218
+ }
219
+ /**
220
+ * List skills
221
+ *
222
+ * Get a list of all available skills in the OpenCode system.
223
+ */
224
+ skills(parameters, options) {
225
+ const params = buildClientParams([parameters], [
226
+ {
227
+ args: [
228
+ { in: "query", key: "directory" },
229
+ { in: "query", key: "workspace" },
230
+ ],
231
+ },
232
+ ]);
233
+ return (options?.client ?? this.client).get({
234
+ url: "/skill",
235
+ ...options,
236
+ ...params,
237
+ });
238
+ }
239
+ }
169
240
  export class Project extends HeyApiClient {
170
241
  /**
171
242
  * List all projects
@@ -2389,77 +2460,6 @@ export class Command extends HeyApiClient {
2389
2460
  });
2390
2461
  }
2391
2462
  }
2392
- export class App extends HeyApiClient {
2393
- /**
2394
- * Write log
2395
- *
2396
- * Write a log entry to the server logs with specified level and metadata.
2397
- */
2398
- log(parameters, options) {
2399
- const params = buildClientParams([parameters], [
2400
- {
2401
- args: [
2402
- { in: "query", key: "directory" },
2403
- { in: "query", key: "workspace" },
2404
- { in: "body", key: "service" },
2405
- { in: "body", key: "level" },
2406
- { in: "body", key: "message" },
2407
- { in: "body", key: "extra" },
2408
- ],
2409
- },
2410
- ]);
2411
- return (options?.client ?? this.client).post({
2412
- url: "/log",
2413
- ...options,
2414
- ...params,
2415
- headers: {
2416
- "Content-Type": "application/json",
2417
- ...options?.headers,
2418
- ...params.headers,
2419
- },
2420
- });
2421
- }
2422
- /**
2423
- * List agents
2424
- *
2425
- * Get a list of all available AI agents in the OpenCode system.
2426
- */
2427
- agents(parameters, options) {
2428
- const params = buildClientParams([parameters], [
2429
- {
2430
- args: [
2431
- { in: "query", key: "directory" },
2432
- { in: "query", key: "workspace" },
2433
- ],
2434
- },
2435
- ]);
2436
- return (options?.client ?? this.client).get({
2437
- url: "/agent",
2438
- ...options,
2439
- ...params,
2440
- });
2441
- }
2442
- /**
2443
- * List skills
2444
- *
2445
- * Get a list of all available skills in the OpenCode system.
2446
- */
2447
- skills(parameters, options) {
2448
- const params = buildClientParams([parameters], [
2449
- {
2450
- args: [
2451
- { in: "query", key: "directory" },
2452
- { in: "query", key: "workspace" },
2453
- ],
2454
- },
2455
- ]);
2456
- return (options?.client ?? this.client).get({
2457
- url: "/skill",
2458
- ...options,
2459
- ...params,
2460
- });
2461
- }
2462
- }
2463
2463
  export class Lsp extends HeyApiClient {
2464
2464
  /**
2465
2465
  * Get LSP status
@@ -2518,6 +2518,10 @@ export class OpencodeClient extends HeyApiClient {
2518
2518
  get auth() {
2519
2519
  return (this._auth ??= new Auth({ client: this.client }));
2520
2520
  }
2521
+ _app;
2522
+ get app() {
2523
+ return (this._app ??= new App({ client: this.client }));
2524
+ }
2521
2525
  _project;
2522
2526
  get project() {
2523
2527
  return (this._project ??= new Project({ client: this.client }));
@@ -2598,10 +2602,6 @@ export class OpencodeClient extends HeyApiClient {
2598
2602
  get command() {
2599
2603
  return (this._command ??= new Command({ client: this.client }));
2600
2604
  }
2601
- _app;
2602
- get app() {
2603
- return (this._app ??= new App({ client: this.client }));
2604
- }
2605
2605
  _lsp;
2606
2606
  get lsp() {
2607
2607
  return (this._lsp ??= new Lsp({ client: this.client }));
@@ -1210,11 +1210,16 @@ export type Config = {
1210
1210
  watcher?: {
1211
1211
  ignore?: Array<string>;
1212
1212
  };
1213
- plugin?: Array<string>;
1214
1213
  /**
1215
1214
  * Enable or disable snapshot tracking. When false, filesystem snapshots are not recorded and undoing or reverting will not undo/redo file changes. Defaults to true.
1216
1215
  */
1217
1216
  snapshot?: boolean;
1217
+ plugin?: Array<string | [
1218
+ string,
1219
+ {
1220
+ [key: string]: unknown;
1221
+ }
1222
+ ]>;
1218
1223
  /**
1219
1224
  * Control sharing behavior:'manual' allows manual sharing via commands, 'auto' enables automatic sharing, 'disabled' disables all sharing
1220
1225
  */
@@ -1905,6 +1910,48 @@ export type AuthSetResponses = {
1905
1910
  200: boolean;
1906
1911
  };
1907
1912
  export type AuthSetResponse = AuthSetResponses[keyof AuthSetResponses];
1913
+ export type AppLogData = {
1914
+ body?: {
1915
+ /**
1916
+ * Service name for the log entry
1917
+ */
1918
+ service: string;
1919
+ /**
1920
+ * Log level
1921
+ */
1922
+ level: "debug" | "info" | "error" | "warn";
1923
+ /**
1924
+ * Log message
1925
+ */
1926
+ message: string;
1927
+ /**
1928
+ * Additional metadata for the log entry
1929
+ */
1930
+ extra?: {
1931
+ [key: string]: unknown;
1932
+ };
1933
+ };
1934
+ path?: never;
1935
+ query?: {
1936
+ directory?: string;
1937
+ workspace?: string;
1938
+ };
1939
+ url: "/log";
1940
+ };
1941
+ export type AppLogErrors = {
1942
+ /**
1943
+ * Bad request
1944
+ */
1945
+ 400: BadRequestError;
1946
+ };
1947
+ export type AppLogError = AppLogErrors[keyof AppLogErrors];
1948
+ export type AppLogResponses = {
1949
+ /**
1950
+ * Log entry written successfully
1951
+ */
1952
+ 200: boolean;
1953
+ };
1954
+ export type AppLogResponse = AppLogResponses[keyof AppLogResponses];
1908
1955
  export type ProjectListData = {
1909
1956
  body?: never;
1910
1957
  path?: never;
@@ -4304,48 +4351,6 @@ export type CommandListResponses = {
4304
4351
  200: Array<Command>;
4305
4352
  };
4306
4353
  export type CommandListResponse = CommandListResponses[keyof CommandListResponses];
4307
- export type AppLogData = {
4308
- body?: {
4309
- /**
4310
- * Service name for the log entry
4311
- */
4312
- service: string;
4313
- /**
4314
- * Log level
4315
- */
4316
- level: "debug" | "info" | "error" | "warn";
4317
- /**
4318
- * Log message
4319
- */
4320
- message: string;
4321
- /**
4322
- * Additional metadata for the log entry
4323
- */
4324
- extra?: {
4325
- [key: string]: unknown;
4326
- };
4327
- };
4328
- path?: never;
4329
- query?: {
4330
- directory?: string;
4331
- workspace?: string;
4332
- };
4333
- url: "/log";
4334
- };
4335
- export type AppLogErrors = {
4336
- /**
4337
- * Bad request
4338
- */
4339
- 400: BadRequestError;
4340
- };
4341
- export type AppLogError = AppLogErrors[keyof AppLogErrors];
4342
- export type AppLogResponses = {
4343
- /**
4344
- * Log entry written successfully
4345
- */
4346
- 200: boolean;
4347
- };
4348
- export type AppLogResponse = AppLogResponses[keyof AppLogResponses];
4349
4354
  export type AppAgentsData = {
4350
4355
  body?: never;
4351
4356
  path?: never;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode-ai/sdk",
4
- "version": "1.3.3",
4
+ "version": "1.3.4",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {