@opencode-ai/sdk 1.0.133 → 1.0.137
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.d.ts +1 -1
- package/dist/client.js +7 -6
- package/dist/gen/sdk.gen.d.ts +59 -7
- package/dist/gen/sdk.gen.js +139 -15
- package/dist/gen/types.gen.d.ts +389 -16
- package/dist/v2/client.d.ts +7 -0
- package/dist/v2/client.js +25 -0
- package/dist/v2/gen/client/client.gen.d.ts +2 -0
- package/dist/v2/gen/client/client.gen.js +225 -0
- package/dist/v2/gen/client/index.d.ts +8 -0
- package/dist/v2/gen/client/index.js +6 -0
- package/dist/v2/gen/client/types.gen.d.ts +117 -0
- package/dist/v2/gen/client/types.gen.js +2 -0
- package/dist/v2/gen/client/utils.gen.d.ts +33 -0
- package/dist/v2/gen/client/utils.gen.js +226 -0
- package/dist/v2/gen/client.gen.d.ts +12 -0
- package/dist/v2/gen/client.gen.js +3 -0
- package/dist/v2/gen/core/auth.gen.d.ts +18 -0
- package/dist/v2/gen/core/auth.gen.js +14 -0
- package/dist/v2/gen/core/bodySerializer.gen.d.ts +25 -0
- package/dist/v2/gen/core/bodySerializer.gen.js +57 -0
- package/dist/v2/gen/core/params.gen.d.ts +43 -0
- package/dist/v2/gen/core/params.gen.js +102 -0
- package/dist/v2/gen/core/pathSerializer.gen.d.ts +33 -0
- package/dist/v2/gen/core/pathSerializer.gen.js +106 -0
- package/dist/v2/gen/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/v2/gen/core/queryKeySerializer.gen.js +93 -0
- package/dist/v2/gen/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/v2/gen/core/serverSentEvents.gen.js +131 -0
- package/dist/v2/gen/core/types.gen.d.ts +78 -0
- package/dist/v2/gen/core/types.gen.js +2 -0
- package/dist/v2/gen/core/utils.gen.d.ts +19 -0
- package/dist/v2/gen/core/utils.gen.js +87 -0
- package/dist/v2/gen/sdk.gen.d.ts +850 -0
- package/dist/v2/gen/sdk.gen.js +1626 -0
- package/dist/v2/gen/types.gen.d.ts +3356 -0
- package/dist/v2/gen/types.gen.js +2 -0
- package/dist/v2/index.d.ts +10 -0
- package/dist/v2/index.js +16 -0
- package/dist/v2/server.d.ts +23 -0
- package/dist/v2/server.js +91 -0
- package/package.json +15 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./server.js";
|
|
3
|
+
import type { ServerOptions } from "./server.js";
|
|
4
|
+
export declare function createOpencode(options?: ServerOptions): Promise<{
|
|
5
|
+
client: import("./client.js").OpencodeClient;
|
|
6
|
+
server: {
|
|
7
|
+
url: string;
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
package/dist/v2/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./server.js";
|
|
3
|
+
import { createOpencodeClient } from "./client.js";
|
|
4
|
+
import { createOpencodeServer } from "./server.js";
|
|
5
|
+
export async function createOpencode(options) {
|
|
6
|
+
const server = await createOpencodeServer({
|
|
7
|
+
...options,
|
|
8
|
+
});
|
|
9
|
+
const client = createOpencodeClient({
|
|
10
|
+
baseUrl: server.url,
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
client,
|
|
14
|
+
server,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Config } from "./gen/types.gen.js";
|
|
2
|
+
export type ServerOptions = {
|
|
3
|
+
hostname?: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
config?: Config;
|
|
8
|
+
};
|
|
9
|
+
export type TuiOptions = {
|
|
10
|
+
project?: string;
|
|
11
|
+
model?: string;
|
|
12
|
+
session?: string;
|
|
13
|
+
agent?: string;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
config?: Config;
|
|
16
|
+
};
|
|
17
|
+
export declare function createOpencodeServer(options?: ServerOptions): Promise<{
|
|
18
|
+
url: string;
|
|
19
|
+
close(): void;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function createOpencodeTui(options?: TuiOptions): {
|
|
22
|
+
close(): void;
|
|
23
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
export async function createOpencodeServer(options) {
|
|
3
|
+
options = Object.assign({
|
|
4
|
+
hostname: "127.0.0.1",
|
|
5
|
+
port: 4096,
|
|
6
|
+
timeout: 5000,
|
|
7
|
+
}, options ?? {});
|
|
8
|
+
const proc = spawn(`opencode`, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
|
|
9
|
+
signal: options.signal,
|
|
10
|
+
env: {
|
|
11
|
+
...process.env,
|
|
12
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const url = await new Promise((resolve, reject) => {
|
|
16
|
+
const id = setTimeout(() => {
|
|
17
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
18
|
+
}, options.timeout);
|
|
19
|
+
let output = "";
|
|
20
|
+
proc.stdout?.on("data", (chunk) => {
|
|
21
|
+
output += chunk.toString();
|
|
22
|
+
const lines = output.split("\n");
|
|
23
|
+
for (const line of lines) {
|
|
24
|
+
if (line.startsWith("opencode server listening")) {
|
|
25
|
+
const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
26
|
+
if (!match) {
|
|
27
|
+
throw new Error(`Failed to parse server url from output: ${line}`);
|
|
28
|
+
}
|
|
29
|
+
clearTimeout(id);
|
|
30
|
+
resolve(match[1]);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
proc.stderr?.on("data", (chunk) => {
|
|
36
|
+
output += chunk.toString();
|
|
37
|
+
});
|
|
38
|
+
proc.on("exit", (code) => {
|
|
39
|
+
clearTimeout(id);
|
|
40
|
+
let msg = `Server exited with code ${code}`;
|
|
41
|
+
if (output.trim()) {
|
|
42
|
+
msg += `\nServer output: ${output}`;
|
|
43
|
+
}
|
|
44
|
+
reject(new Error(msg));
|
|
45
|
+
});
|
|
46
|
+
proc.on("error", (error) => {
|
|
47
|
+
clearTimeout(id);
|
|
48
|
+
reject(error);
|
|
49
|
+
});
|
|
50
|
+
if (options.signal) {
|
|
51
|
+
options.signal.addEventListener("abort", () => {
|
|
52
|
+
clearTimeout(id);
|
|
53
|
+
reject(new Error("Aborted"));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
url,
|
|
59
|
+
close() {
|
|
60
|
+
proc.kill();
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function createOpencodeTui(options) {
|
|
65
|
+
const args = [];
|
|
66
|
+
if (options?.project) {
|
|
67
|
+
args.push(`--project=${options.project}`);
|
|
68
|
+
}
|
|
69
|
+
if (options?.model) {
|
|
70
|
+
args.push(`--model=${options.model}`);
|
|
71
|
+
}
|
|
72
|
+
if (options?.session) {
|
|
73
|
+
args.push(`--session=${options.session}`);
|
|
74
|
+
}
|
|
75
|
+
if (options?.agent) {
|
|
76
|
+
args.push(`--agent=${options.agent}`);
|
|
77
|
+
}
|
|
78
|
+
const proc = spawn(`opencode`, args, {
|
|
79
|
+
signal: options?.signal,
|
|
80
|
+
stdio: "inherit",
|
|
81
|
+
env: {
|
|
82
|
+
...process.env,
|
|
83
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}),
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
close() {
|
|
88
|
+
proc.kill();
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
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.0.
|
|
4
|
+
"version": "1.0.137",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"typecheck": "tsgo --noEmit",
|
|
@@ -19,17 +19,29 @@
|
|
|
19
19
|
"./server": {
|
|
20
20
|
"import": "./dist/server.js",
|
|
21
21
|
"types": "./dist/server.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./v2": {
|
|
24
|
+
"import": "./dist/v2/index.js",
|
|
25
|
+
"types": "./dist/v2/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./v2/client": {
|
|
28
|
+
"import": "./dist/v2/client.js",
|
|
29
|
+
"types": "./dist/v2/client.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./v2/server": {
|
|
32
|
+
"import": "./dist/v2/server.js",
|
|
33
|
+
"types": "./dist/v2/server.d.ts"
|
|
22
34
|
}
|
|
23
35
|
},
|
|
24
36
|
"files": [
|
|
25
37
|
"dist"
|
|
26
38
|
],
|
|
27
39
|
"devDependencies": {
|
|
28
|
-
"@hey-api/openapi-ts": "0.
|
|
40
|
+
"@hey-api/openapi-ts": "0.88.1",
|
|
29
41
|
"@tsconfig/node22": "22.0.2",
|
|
30
42
|
"@types/node": "22.13.9",
|
|
31
43
|
"typescript": "5.8.2",
|
|
32
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
44
|
+
"@typescript/native-preview": "7.0.0-dev.20251207.1"
|
|
33
45
|
},
|
|
34
46
|
"dependencies": {},
|
|
35
47
|
"publishConfig": {
|