@matrix-ai/sdk 1.5.2 → 1.6.1

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/v2/server.js CHANGED
@@ -1,4 +1,5 @@
1
- import { spawn } from "node:child_process";
1
+ import launch from "cross-spawn";
2
+ import { stop, bindAbort } from "../process.js";
2
3
  export async function createOpencodeServer(options) {
3
4
  options = Object.assign({
4
5
  hostname: "127.0.0.1",
@@ -8,28 +9,38 @@ export async function createOpencodeServer(options) {
8
9
  const args = [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`];
9
10
  if (options.config?.logLevel)
10
11
  args.push(`--log-level=${options.config.logLevel}`);
11
- const proc = spawn(`opencode`, args, {
12
- signal: options.signal,
12
+ const proc = launch(`opencode`, args, {
13
13
  env: {
14
14
  ...process.env,
15
15
  OPENCODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
16
16
  },
17
17
  });
18
+ let clear = () => { };
18
19
  const url = await new Promise((resolve, reject) => {
19
20
  const id = setTimeout(() => {
21
+ clear();
22
+ stop(proc);
20
23
  reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
21
24
  }, options.timeout);
22
25
  let output = "";
26
+ let resolved = false;
23
27
  proc.stdout?.on("data", (chunk) => {
28
+ if (resolved)
29
+ return;
24
30
  output += chunk.toString();
25
31
  const lines = output.split("\n");
26
32
  for (const line of lines) {
27
33
  if (line.startsWith("opencode server listening")) {
28
34
  const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
29
35
  if (!match) {
30
- throw new Error(`Failed to parse server url from output: ${line}`);
36
+ clear();
37
+ stop(proc);
38
+ clearTimeout(id);
39
+ reject(new Error(`Failed to parse server url from output: ${line}`));
40
+ return;
31
41
  }
32
42
  clearTimeout(id);
43
+ resolved = true;
33
44
  resolve(match[1]);
34
45
  return;
35
46
  }
@@ -50,17 +61,16 @@ export async function createOpencodeServer(options) {
50
61
  clearTimeout(id);
51
62
  reject(error);
52
63
  });
53
- if (options.signal) {
54
- options.signal.addEventListener("abort", () => {
55
- clearTimeout(id);
56
- reject(new Error("Aborted"));
57
- });
58
- }
64
+ clear = bindAbort(proc, options.signal, () => {
65
+ clearTimeout(id);
66
+ reject(options.signal?.reason);
67
+ });
59
68
  });
60
69
  return {
61
70
  url,
62
71
  close() {
63
- proc.kill();
72
+ clear();
73
+ stop(proc);
64
74
  },
65
75
  };
66
76
  }
@@ -78,17 +88,18 @@ export function createOpencodeTui(options) {
78
88
  if (options?.agent) {
79
89
  args.push(`--agent=${options.agent}`);
80
90
  }
81
- const proc = spawn(`opencode`, args, {
82
- signal: options?.signal,
91
+ const proc = launch(`opencode`, args, {
83
92
  stdio: "inherit",
84
93
  env: {
85
94
  ...process.env,
86
95
  OPENCODE_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}),
87
96
  },
88
97
  });
98
+ const clear = bindAbort(proc, options?.signal);
89
99
  return {
90
100
  close() {
91
- proc.kill();
101
+ clear();
102
+ stop(proc);
92
103
  },
93
104
  };
94
105
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@matrix-ai/sdk",
4
- "version": "1.5.2",
4
+ "version": "1.6.1",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -44,9 +44,12 @@
44
44
  "devDependencies": {
45
45
  "@hey-api/openapi-ts": "0.90.10",
46
46
  "@tsconfig/node22": "22.0.2",
47
+ "@types/cross-spawn": "6.0.6",
47
48
  "@types/node": "22.13.9",
48
- "typescript": "5.8.2",
49
- "@typescript/native-preview": "7.0.0-dev.20251207.1"
49
+ "@typescript/native-preview": "7.0.0-dev.20251207.1",
50
+ "typescript": "5.8.2"
50
51
  },
51
- "dependencies": {}
52
+ "dependencies": {
53
+ "cross-spawn": "7.0.6"
54
+ }
52
55
  }