@xutest1/sdk 0.0.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.
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,15 @@
1
+ export * from "./client.js";
2
+ export * from "./server.js";
3
+ import { createOpencodeClient } from "./client.js";
4
+ import { createOpencodeServer } from "./server.js";
5
+ import type { ServerOptions } from "./server.js";
6
+ export declare function createA3code(options?: ServerOptions): Promise<{
7
+ client: import("./client.js").OpencodeClient;
8
+ server: {
9
+ url: string;
10
+ close(): void;
11
+ };
12
+ }>;
13
+ export declare const createOpencode: typeof createA3code;
14
+ export { createOpencodeClient as createA3codeClient };
15
+ export { createOpencodeServer as createA3codeServer };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ export * from "./client.js";
2
+ export * from "./server.js";
3
+ import { createOpencodeClient } from "./client.js";
4
+ import { createOpencodeServer } from "./server.js";
5
+ // Main function - spawns server + creates client
6
+ export async function createA3code(options) {
7
+ const server = await createOpencodeServer({
8
+ ...options,
9
+ });
10
+ const client = createOpencodeClient({
11
+ baseUrl: server.url,
12
+ });
13
+ return {
14
+ client,
15
+ server,
16
+ };
17
+ }
18
+ // Alias for backward compatibility
19
+ export const createOpencode = createA3code;
20
+ // Re-export with A3code naming
21
+ export { createOpencodeClient as createA3codeClient };
22
+ export { createOpencodeServer as createA3codeServer };
@@ -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/dist/server.js ADDED
@@ -0,0 +1,131 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { join, dirname } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ // Find the ae3code binary from optionalDependencies
6
+ function findBinary() {
7
+ const platform = process.platform; // darwin, linux, win32
8
+ const arch = process.arch; // arm64, x64
9
+ // Map to package names
10
+ const platformMap = {
11
+ 'darwin-arm64': '@xutest1/darwin-arm64',
12
+ 'darwin-x64': '@xutest1/darwin-x64',
13
+ 'linux-x64': '@xutest1/linux-x64',
14
+ 'linux-arm64': '@xutest1/linux-arm64',
15
+ 'win32-x64': '@xutest1/win32-x64',
16
+ };
17
+ const key = `${platform}-${arch}`;
18
+ const pkgName = platformMap[key];
19
+ if (!pkgName) {
20
+ throw new Error(`Unsupported platform: ${key}. Supported: ${Object.keys(platformMap).join(', ')}`);
21
+ }
22
+ const binaryName = platform === 'win32' ? 'ae3code.exe' : 'ae3code';
23
+ // Try to find the package in node_modules
24
+ const possiblePaths = [
25
+ // When installed as dependency
26
+ join(dirname(fileURLToPath(import.meta.url)), '..', '..', pkgName, 'bin', binaryName),
27
+ // When in node_modules
28
+ join(process.cwd(), 'node_modules', pkgName, 'bin', binaryName),
29
+ // Fallback to global
30
+ binaryName,
31
+ ];
32
+ for (const p of possiblePaths) {
33
+ if (existsSync(p)) {
34
+ return p;
35
+ }
36
+ }
37
+ // Return the binary name and hope it's in PATH
38
+ return binaryName;
39
+ }
40
+ export async function createOpencodeServer(options) {
41
+ options = Object.assign({
42
+ hostname: "127.0.0.1",
43
+ port: 4096,
44
+ timeout: 5000,
45
+ }, options ?? {});
46
+ const binaryPath = findBinary();
47
+ const proc = spawn(binaryPath, [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`], {
48
+ signal: options.signal,
49
+ env: {
50
+ ...process.env,
51
+ AE3CODE_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
52
+ },
53
+ });
54
+ const url = await new Promise((resolve, reject) => {
55
+ const id = setTimeout(() => {
56
+ reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
57
+ }, options.timeout);
58
+ let output = "";
59
+ proc.stdout?.on("data", (chunk) => {
60
+ output += chunk.toString();
61
+ const lines = output.split("\n");
62
+ for (const line of lines) {
63
+ if (line.startsWith("opencode server listening") || line.startsWith("ae3code server listening")) {
64
+ const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
65
+ if (!match) {
66
+ throw new Error(`Failed to parse server url from output: ${line}`);
67
+ }
68
+ clearTimeout(id);
69
+ resolve(match[1]);
70
+ return;
71
+ }
72
+ }
73
+ });
74
+ proc.stderr?.on("data", (chunk) => {
75
+ output += chunk.toString();
76
+ });
77
+ proc.on("exit", (code) => {
78
+ clearTimeout(id);
79
+ let msg = `Server exited with code ${code}`;
80
+ if (output.trim()) {
81
+ msg += `\nServer output: ${output}`;
82
+ }
83
+ reject(new Error(msg));
84
+ });
85
+ proc.on("error", (error) => {
86
+ clearTimeout(id);
87
+ reject(error);
88
+ });
89
+ if (options.signal) {
90
+ options.signal.addEventListener("abort", () => {
91
+ clearTimeout(id);
92
+ reject(new Error("Aborted"));
93
+ });
94
+ }
95
+ });
96
+ return {
97
+ url,
98
+ close() {
99
+ proc.kill();
100
+ },
101
+ };
102
+ }
103
+ export function createOpencodeTui(options) {
104
+ const args = [];
105
+ if (options?.project) {
106
+ args.push(`--project=${options.project}`);
107
+ }
108
+ if (options?.model) {
109
+ args.push(`--model=${options.model}`);
110
+ }
111
+ if (options?.session) {
112
+ args.push(`--session=${options.session}`);
113
+ }
114
+ if (options?.agent) {
115
+ args.push(`--agent=${options.agent}`);
116
+ }
117
+ const binaryPath = findBinary();
118
+ const proc = spawn(binaryPath, args, {
119
+ signal: options?.signal,
120
+ stdio: "inherit",
121
+ env: {
122
+ ...process.env,
123
+ AE3CODE_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}),
124
+ },
125
+ });
126
+ return {
127
+ close() {
128
+ proc.kill();
129
+ },
130
+ };
131
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@xutest1/sdk",
3
+ "version": "0.0.1",
4
+ "description": "Type-safe SDK for A3Code AI coding agent",
5
+ "author": "A3Code",
6
+ "license": "MIT",
7
+ "keywords": ["a3code", "ai", "sdk", "coding", "agent"],
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "files": ["dist"],
18
+ "optionalDependencies": {
19
+ "@xutest1/darwin-arm64": "0.0.1",
20
+ "@xutest1/darwin-x64": "0.0.1",
21
+ "@xutest1/linux-x64": "0.0.1",
22
+ "@xutest1/linux-arm64": "0.0.1",
23
+ "@xutest1/win32-x64": "0.0.1"
24
+ },
25
+ "devDependencies": {
26
+ "@tsconfig/node22": "^22.0.0",
27
+ "@types/node": "^22.0.0",
28
+ "typescript": "^5.7.0"
29
+ }
30
+ }