@xutest1/sdk 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +1 -2
  2. package/server.js +23 -2
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@xutest1/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Type-safe SDK for A3Code AI coding agent",
5
5
  "author": "A3Code",
6
6
  "license": "MIT",
7
- "keywords": ["a3code", "ai", "sdk", "coding", "agent"],
8
7
  "type": "module",
9
8
  "exports": {
10
9
  ".": {
package/server.js CHANGED
@@ -1,11 +1,31 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ function findBinary() {
6
+ const platform = process.platform === "win32" ? "windows" : process.platform;
7
+ const arch = process.arch === "arm64" ? "arm64" : "x64";
8
+ const platformKey = `${platform}-${arch}`;
9
+ const exe = process.platform === "win32" ? "ae3code.exe" : "ae3code";
10
+ // Get the directory where this SDK is installed
11
+ const sdkDir = dirname(fileURLToPath(import.meta.url));
12
+ // Go up to node_modules/@scope, then into the platform package
13
+ const scopeDir = dirname(dirname(sdkDir));
14
+ const binaryPath = join(scopeDir, platformKey, "bin", exe);
15
+ if (existsSync(binaryPath)) {
16
+ return binaryPath;
17
+ }
18
+ // Fallback to PATH
19
+ return "ae3code";
20
+ }
2
21
  export async function createOpencodeServer(options) {
3
22
  options = Object.assign({
4
23
  hostname: "127.0.0.1",
5
24
  port: 4096,
6
25
  timeout: 5000,
7
26
  }, options ?? {});
8
- const proc = spawn(`ae3code`, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
27
+ const binaryPath = findBinary();
28
+ const proc = spawn(binaryPath, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
9
29
  signal: options.signal,
10
30
  env: {
11
31
  ...process.env,
@@ -75,7 +95,8 @@ export function createOpencodeTui(options) {
75
95
  if (options?.agent) {
76
96
  args.push(`--agent=${options.agent}`);
77
97
  }
78
- const proc = spawn(`ae3code`, args, {
98
+ const binaryPath = findBinary();
99
+ const proc = spawn(binaryPath, args, {
79
100
  signal: options?.signal,
80
101
  stdio: "inherit",
81
102
  env: {