@xutest1/sdk 0.1.8 → 0.2.0

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/package.json CHANGED
@@ -1,23 +1,31 @@
1
1
  {
2
2
  "name": "@xutest1/sdk",
3
- "version": "0.1.8",
4
- "description": "A3CODE SDK - AI coding assistant SDK",
3
+ "version": "0.2.0",
4
+ "description": "Type-safe SDK for A3Code AI coding agent",
5
+ "author": "A3Code",
6
+ "license": "MIT",
7
+ "keywords": ["a3code", "ai", "sdk", "coding", "agent"],
5
8
  "type": "module",
6
- "main": "index.js",
7
9
  "exports": {
8
- ".": "./index.js",
9
- "./client": "./client.js",
10
- "./server": "./server.js"
10
+ ".": {
11
+ "import": "./index.js",
12
+ "types": "./index.d.ts"
13
+ },
14
+ "./client": {
15
+ "import": "./client.js",
16
+ "types": "./client.d.ts"
17
+ },
18
+ "./server": {
19
+ "import": "./server.js",
20
+ "types": "./server.d.ts"
21
+ }
11
22
  },
12
- "files": ["*.js"],
13
- "keywords": ["a3code", "ai", "sdk", "coding", "assistant"],
14
- "author": "A3CODE",
15
- "license": "MIT",
23
+ "files": ["*"],
16
24
  "optionalDependencies": {
17
- "@xutest1/darwin-arm64": "0.1.8",
18
- "@xutest1/darwin-x64": "0.1.8",
19
- "@xutest1/linux-arm64": "0.1.8",
20
- "@xutest1/linux-x64": "0.1.8",
21
- "@xutest1/windows-x64": "0.1.8"
25
+ "@xutest1/darwin-arm64": "0.2.0",
26
+ "@xutest1/darwin-x64": "0.2.0",
27
+ "@xutest1/linux-arm64": "0.2.0",
28
+ "@xutest1/linux-x64": "0.2.0",
29
+ "@xutest1/windows-x64": "0.2.0"
22
30
  }
23
31
  }
package/server.d.ts ADDED
@@ -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
+ };
package/server.js CHANGED
@@ -1,136 +1,91 @@
1
- // src/server.ts
2
1
  import { spawn } from "node:child_process";
3
- import { existsSync } from "node:fs";
4
- import { join, dirname } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import { platform, arch } from "node:os";
7
- var __filename2 = fileURLToPath(import.meta.url);
8
- var __dirname2 = dirname(__filename2);
9
- function findBinary() {
10
- const os = platform();
11
- const cpu = arch();
12
- const platformMap = {
13
- darwin: "darwin",
14
- linux: "linux",
15
- win32: "win32"
16
- };
17
- const archMap = {
18
- arm64: "arm64",
19
- x64: "x64"
20
- };
21
- const pkgPlatform = platformMap[os];
22
- const pkgArch = archMap[cpu];
23
- if (pkgPlatform && pkgArch) {
24
- const binaryName = os === "win32" ? "ae3code.exe" : "ae3code";
25
- const possiblePaths = [
26
- join(process.cwd(), "node_modules", "@xutest1", `${pkgPlatform}-${pkgArch}`, "bin", binaryName),
27
- join(__dirname2, "..", `@xutest1`, `${pkgPlatform}-${pkgArch}`, "bin", binaryName)
28
- ];
29
- for (const binPath of possiblePaths) {
30
- if (existsSync(binPath)) {
31
- return binPath;
32
- }
33
- }
34
- }
35
- return "ae3code";
36
- }
37
- async function createOpencodeServer(options) {
38
- options = Object.assign({
39
- hostname: "127.0.0.1",
40
- port: 4096,
41
- timeout: 5000
42
- }, options ?? {});
43
- const binaryPath = findBinary();
44
- const proc = spawn(binaryPath, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
45
- signal: options.signal,
46
- env: {
47
- ...process.env,
48
- AE3CODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {})
49
- }
50
- });
51
- const url = await new Promise((resolve, reject) => {
52
- const id = setTimeout(() => {
53
- reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
54
- }, options.timeout);
55
- let output = "";
56
- proc.stdout?.on("data", (chunk) => {
57
- output += chunk.toString();
58
- const lines = output.split(`
59
- `);
60
- for (const line of lines) {
61
- if (line.startsWith("opencode server listening") || line.startsWith("ae3code server listening")) {
62
- const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
63
- if (!match) {
64
- throw new Error(`Failed to parse server url from output: ${line}`);
65
- }
66
- clearTimeout(id);
67
- resolve(match[1]);
68
- return;
69
- }
70
- }
71
- });
72
- proc.stderr?.on("data", (chunk) => {
73
- output += chunk.toString();
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(`ae3code`, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
9
+ signal: options.signal,
10
+ env: {
11
+ ...process.env,
12
+ AE3CODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
13
+ },
74
14
  });
75
- proc.on("exit", (code) => {
76
- clearTimeout(id);
77
- let msg = `Server exited with code ${code}`;
78
- if (output.trim()) {
79
- msg += `
80
- Server output: ${output}`;
81
- }
82
- reject(new Error(msg));
83
- });
84
- proc.on("error", (error) => {
85
- clearTimeout(id);
86
- reject(error);
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") || line.startsWith("ae3code 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
+ }
87
56
  });
88
- if (options.signal) {
89
- options.signal.addEventListener("abort", () => {
90
- clearTimeout(id);
91
- reject(new Error("Aborted"));
92
- });
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}`);
93
68
  }
94
- });
95
- return {
96
- url,
97
- close() {
98
- proc.kill();
69
+ if (options?.model) {
70
+ args.push(`--model=${options.model}`);
99
71
  }
100
- };
101
- }
102
- function createOpencodeTui(options) {
103
- const args = [];
104
- if (options?.project) {
105
- args.push(`--project=${options.project}`);
106
- }
107
- if (options?.model) {
108
- args.push(`--model=${options.model}`);
109
- }
110
- if (options?.session) {
111
- args.push(`--session=${options.session}`);
112
- }
113
- if (options?.agent) {
114
- args.push(`--agent=${options.agent}`);
115
- }
116
- const binaryPath = findBinary();
117
- const proc = spawn(binaryPath, args, {
118
- signal: options?.signal,
119
- stdio: "inherit",
120
- env: {
121
- ...process.env,
122
- AE3CODE_CONFIG_CONTENT: JSON.stringify(options?.config ?? {})
72
+ if (options?.session) {
73
+ args.push(`--session=${options.session}`);
123
74
  }
124
- });
125
- return {
126
- close() {
127
- proc.kill();
75
+ if (options?.agent) {
76
+ args.push(`--agent=${options.agent}`);
128
77
  }
129
- };
78
+ const proc = spawn(`ae3code`, args, {
79
+ signal: options?.signal,
80
+ stdio: "inherit",
81
+ env: {
82
+ ...process.env,
83
+ AE3CODE_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}),
84
+ },
85
+ });
86
+ return {
87
+ close() {
88
+ proc.kill();
89
+ },
90
+ };
130
91
  }
131
- export {
132
- createOpencodeTui,
133
- createOpencodeServer,
134
- createOpencodeServer as createA3codeServer,
135
- createOpencodeTui as createA3codeTui
136
- };