@opencode-ai/sdk 0.6.2 → 0.6.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/server.d.ts +4 -2
- package/dist/server.js +13 -9
- package/package.json +1 -1
package/dist/server.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Config } from "./gen/types.gen.js";
|
|
2
|
+
export type ServerOptions = {
|
|
2
3
|
hostname?: string;
|
|
3
4
|
port?: number;
|
|
4
5
|
signal?: AbortSignal;
|
|
5
6
|
timeout?: number;
|
|
7
|
+
config?: Config;
|
|
6
8
|
};
|
|
7
|
-
export declare function createOpencodeServer(
|
|
9
|
+
export declare function createOpencodeServer(options?: ServerOptions): Promise<{
|
|
8
10
|
url: string;
|
|
9
11
|
close(): void;
|
|
10
12
|
}>;
|
package/dist/server.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
export async function createOpencodeServer(
|
|
3
|
-
|
|
2
|
+
export async function createOpencodeServer(options) {
|
|
3
|
+
options = Object.assign({
|
|
4
4
|
hostname: "127.0.0.1",
|
|
5
5
|
port: 4096,
|
|
6
6
|
timeout: 5000,
|
|
7
|
-
},
|
|
8
|
-
const proc = spawn(`opencode`, [`serve`, `--hostname=${
|
|
9
|
-
signal:
|
|
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
|
+
},
|
|
10
14
|
});
|
|
11
15
|
const url = await new Promise((resolve, reject) => {
|
|
12
16
|
const id = setTimeout(() => {
|
|
13
|
-
reject(new Error(`Timeout waiting for server to start after ${
|
|
14
|
-
},
|
|
17
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
18
|
+
}, options.timeout);
|
|
15
19
|
let output = "";
|
|
16
20
|
proc.stdout?.on("data", (chunk) => {
|
|
17
21
|
output += chunk.toString();
|
|
@@ -43,8 +47,8 @@ export async function createOpencodeServer(config) {
|
|
|
43
47
|
clearTimeout(id);
|
|
44
48
|
reject(error);
|
|
45
49
|
});
|
|
46
|
-
if (
|
|
47
|
-
|
|
50
|
+
if (options.signal) {
|
|
51
|
+
options.signal.addEventListener("abort", () => {
|
|
48
52
|
clearTimeout(id);
|
|
49
53
|
reject(new Error("Aborted"));
|
|
50
54
|
});
|