@hopcoderx/sdk 1.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.
- package/dist/client.d.ts +7 -0
- package/dist/client.js +25 -0
- package/dist/gen/client/client.gen.d.ts +2 -0
- package/dist/gen/client/client.gen.js +165 -0
- package/dist/gen/client/index.d.ts +7 -0
- package/dist/gen/client/index.js +5 -0
- package/dist/gen/client/types.gen.d.ts +127 -0
- package/dist/gen/client/types.gen.js +2 -0
- package/dist/gen/client/utils.gen.d.ts +38 -0
- package/dist/gen/client/utils.gen.js +226 -0
- package/dist/gen/client.gen.d.ts +12 -0
- package/dist/gen/client.gen.js +5 -0
- package/dist/gen/core/auth.gen.d.ts +18 -0
- package/dist/gen/core/auth.gen.js +14 -0
- package/dist/gen/core/bodySerializer.gen.d.ts +17 -0
- package/dist/gen/core/bodySerializer.gen.js +57 -0
- package/dist/gen/core/params.gen.d.ts +33 -0
- package/dist/gen/core/params.gen.js +89 -0
- package/dist/gen/core/pathSerializer.gen.d.ts +33 -0
- package/dist/gen/core/pathSerializer.gen.js +106 -0
- package/dist/gen/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/gen/core/queryKeySerializer.gen.js +93 -0
- package/dist/gen/core/serverSentEvents.gen.d.ts +59 -0
- package/dist/gen/core/serverSentEvents.gen.js +117 -0
- package/dist/gen/core/types.gen.d.ts +78 -0
- package/dist/gen/core/types.gen.js +2 -0
- package/dist/gen/core/utils.gen.d.ts +14 -0
- package/dist/gen/core/utils.gen.js +69 -0
- package/dist/gen/sdk.gen.d.ts +403 -0
- package/dist/gen/sdk.gen.js +881 -0
- package/dist/gen/types.gen.d.ts +3380 -0
- package/dist/gen/types.gen.js +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +16 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +94 -0
- package/dist/v2/client.d.ts +7 -0
- package/dist/v2/client.js +27 -0
- package/dist/v2/gen/client/client.gen.d.ts +2 -0
- package/dist/v2/gen/client/client.gen.js +232 -0
- package/dist/v2/gen/client/index.d.ts +8 -0
- package/dist/v2/gen/client/index.js +6 -0
- package/dist/v2/gen/client/types.gen.d.ts +117 -0
- package/dist/v2/gen/client/types.gen.js +2 -0
- package/dist/v2/gen/client/utils.gen.d.ts +33 -0
- package/dist/v2/gen/client/utils.gen.js +226 -0
- package/dist/v2/gen/client.gen.d.ts +12 -0
- package/dist/v2/gen/client.gen.js +3 -0
- package/dist/v2/gen/core/auth.gen.d.ts +18 -0
- package/dist/v2/gen/core/auth.gen.js +14 -0
- package/dist/v2/gen/core/bodySerializer.gen.d.ts +25 -0
- package/dist/v2/gen/core/bodySerializer.gen.js +57 -0
- package/dist/v2/gen/core/params.gen.d.ts +43 -0
- package/dist/v2/gen/core/params.gen.js +102 -0
- package/dist/v2/gen/core/pathSerializer.gen.d.ts +33 -0
- package/dist/v2/gen/core/pathSerializer.gen.js +106 -0
- package/dist/v2/gen/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/v2/gen/core/queryKeySerializer.gen.js +93 -0
- package/dist/v2/gen/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/v2/gen/core/serverSentEvents.gen.js +133 -0
- package/dist/v2/gen/core/types.gen.d.ts +78 -0
- package/dist/v2/gen/core/types.gen.js +2 -0
- package/dist/v2/gen/core/utils.gen.d.ts +19 -0
- package/dist/v2/gen/core/utils.gen.js +87 -0
- package/dist/v2/gen/sdk.gen.d.ts +1105 -0
- package/dist/v2/gen/sdk.gen.js +2148 -0
- package/dist/v2/gen/types.gen.d.ts +4382 -0
- package/dist/v2/gen/types.gen.js +2 -0
- package/dist/v2/index.d.ts +10 -0
- package/dist/v2/index.js +16 -0
- package/dist/v2/server.d.ts +23 -0
- package/dist/v2/server.js +94 -0
- package/package.json +73 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./server.js";
|
|
3
|
+
import type { ServerOptions } from "./server.js";
|
|
4
|
+
export declare function createHopCoderX(options?: ServerOptions): Promise<{
|
|
5
|
+
client: import("./client.js").HopCoderXClient;
|
|
6
|
+
server: {
|
|
7
|
+
url: string;
|
|
8
|
+
close(): void;
|
|
9
|
+
};
|
|
10
|
+
}>;
|
package/dist/v2/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./server.js";
|
|
3
|
+
import { createHopCoderXClient } from "./client.js";
|
|
4
|
+
import { createHopCoderXServer } from "./server.js";
|
|
5
|
+
export async function createHopCoderX(options) {
|
|
6
|
+
const server = await createHopCoderXServer({
|
|
7
|
+
...options,
|
|
8
|
+
});
|
|
9
|
+
const client = createHopCoderXClient({
|
|
10
|
+
baseUrl: server.url,
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
client,
|
|
14
|
+
server,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -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 createHopCoderXServer(options?: ServerOptions): Promise<{
|
|
18
|
+
url: string;
|
|
19
|
+
close(): void;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function createHopCoderXTui(options?: TuiOptions): {
|
|
22
|
+
close(): void;
|
|
23
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
export async function createHopCoderXServer(options) {
|
|
3
|
+
options = Object.assign({
|
|
4
|
+
hostname: "127.0.0.1",
|
|
5
|
+
port: 4096,
|
|
6
|
+
timeout: 5000,
|
|
7
|
+
}, options ?? {});
|
|
8
|
+
const args = [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`];
|
|
9
|
+
if (options.config?.logLevel)
|
|
10
|
+
args.push(`--log-level=${options.config.logLevel}`);
|
|
11
|
+
const proc = spawn(`HopCoderX`, args, {
|
|
12
|
+
signal: options.signal,
|
|
13
|
+
env: {
|
|
14
|
+
...process.env,
|
|
15
|
+
HOPCODERX_CONFIG_CONTENT: JSON.stringify(options.config ?? {}),
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const url = await new Promise((resolve, reject) => {
|
|
19
|
+
const id = setTimeout(() => {
|
|
20
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
21
|
+
}, options.timeout);
|
|
22
|
+
let output = "";
|
|
23
|
+
proc.stdout?.on("data", (chunk) => {
|
|
24
|
+
output += chunk.toString();
|
|
25
|
+
const lines = output.split("\n");
|
|
26
|
+
for (const line of lines) {
|
|
27
|
+
if (line.startsWith("HopCoderX server listening")) {
|
|
28
|
+
const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
29
|
+
if (!match) {
|
|
30
|
+
throw new Error(`Failed to parse server url from output: ${line}`);
|
|
31
|
+
}
|
|
32
|
+
clearTimeout(id);
|
|
33
|
+
resolve(match[1]);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
proc.stderr?.on("data", (chunk) => {
|
|
39
|
+
output += chunk.toString();
|
|
40
|
+
});
|
|
41
|
+
proc.on("exit", (code) => {
|
|
42
|
+
clearTimeout(id);
|
|
43
|
+
let msg = `Server exited with code ${code}`;
|
|
44
|
+
if (output.trim()) {
|
|
45
|
+
msg += `\nServer output: ${output}`;
|
|
46
|
+
}
|
|
47
|
+
reject(new Error(msg));
|
|
48
|
+
});
|
|
49
|
+
proc.on("error", (error) => {
|
|
50
|
+
clearTimeout(id);
|
|
51
|
+
reject(error);
|
|
52
|
+
});
|
|
53
|
+
if (options.signal) {
|
|
54
|
+
options.signal.addEventListener("abort", () => {
|
|
55
|
+
clearTimeout(id);
|
|
56
|
+
reject(new Error("Aborted"));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
url,
|
|
62
|
+
close() {
|
|
63
|
+
proc.kill();
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function createHopCoderXTui(options) {
|
|
68
|
+
const args = [];
|
|
69
|
+
if (options?.project) {
|
|
70
|
+
args.push(`--project=${options.project}`);
|
|
71
|
+
}
|
|
72
|
+
if (options?.model) {
|
|
73
|
+
args.push(`--model=${options.model}`);
|
|
74
|
+
}
|
|
75
|
+
if (options?.session) {
|
|
76
|
+
args.push(`--session=${options.session}`);
|
|
77
|
+
}
|
|
78
|
+
if (options?.agent) {
|
|
79
|
+
args.push(`--agent=${options.agent}`);
|
|
80
|
+
}
|
|
81
|
+
const proc = spawn(`HopCoderX`, args, {
|
|
82
|
+
signal: options?.signal,
|
|
83
|
+
stdio: "inherit",
|
|
84
|
+
env: {
|
|
85
|
+
...process.env,
|
|
86
|
+
HOPCODERX_CONFIG_CONTENT: JSON.stringify(options?.config ?? {}),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
close() {
|
|
91
|
+
proc.kill();
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@hopcoderx/sdk",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"typecheck": "tsgo --noEmit",
|
|
9
|
+
"build": "./script/build.ts"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./client": {
|
|
17
|
+
"import": "./dist/client.js",
|
|
18
|
+
"types": "./dist/client.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./server": {
|
|
21
|
+
"import": "./dist/server.js",
|
|
22
|
+
"types": "./dist/server.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./v2": {
|
|
25
|
+
"types": {
|
|
26
|
+
"import": "./dist/v2/index.d.js",
|
|
27
|
+
"types": "./dist/v2/index.d.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"default": {
|
|
30
|
+
"import": "./dist/v2/index.js",
|
|
31
|
+
"types": "./dist/v2/index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./v2/client": {
|
|
35
|
+
"types": {
|
|
36
|
+
"import": "./dist/v2/client.d.js",
|
|
37
|
+
"types": "./dist/v2/client.d.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"default": {
|
|
40
|
+
"import": "./dist/v2/client.js",
|
|
41
|
+
"types": "./dist/v2/client.d.ts"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./v2/gen/client": {
|
|
45
|
+
"types": {
|
|
46
|
+
"import": "./dist/v2/gen/client/index.d.js",
|
|
47
|
+
"types": "./dist/v2/gen/client/index.d.d.ts"
|
|
48
|
+
},
|
|
49
|
+
"default": {
|
|
50
|
+
"import": "./dist/v2/gen/client/index.js",
|
|
51
|
+
"types": "./dist/v2/gen/client/index.d.ts"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"./v2/server": {
|
|
55
|
+
"import": "./dist/v2/server.js",
|
|
56
|
+
"types": "./dist/v2/server.d.ts"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"dist"
|
|
61
|
+
],
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@hey-api/openapi-ts": "0.90.10",
|
|
64
|
+
"@tsconfig/node22": "catalog:",
|
|
65
|
+
"@types/node": "catalog:",
|
|
66
|
+
"typescript": "catalog:",
|
|
67
|
+
"@typescript/native-preview": "catalog:"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"directory": "dist"
|
|
72
|
+
}
|
|
73
|
+
}
|