@kilocode/sdk 1.0.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/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/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 +24 -0
- package/dist/server.js +125 -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 +1111 -0
- package/dist/v2/gen/sdk.gen.js +2162 -0
- package/dist/v2/gen/types.gen.d.ts +4366 -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 +24 -0
- package/dist/v2/server.js +125 -0
- package/package.json +51 -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 createOpencode(options?: ServerOptions): Promise<{
|
|
5
|
+
client: import("./client.js").OpencodeClient;
|
|
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 { createOpencodeClient } from "./client.js";
|
|
4
|
+
import { createOpencodeServer } from "./server.js";
|
|
5
|
+
export async function createOpencode(options) {
|
|
6
|
+
const server = await createOpencodeServer({
|
|
7
|
+
...options,
|
|
8
|
+
});
|
|
9
|
+
const client = createOpencodeClient({
|
|
10
|
+
baseUrl: server.url,
|
|
11
|
+
});
|
|
12
|
+
return {
|
|
13
|
+
client,
|
|
14
|
+
server,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Config } from "./gen/types.gen.js";
|
|
2
|
+
export declare function buildConfigEnv(config?: Config): string;
|
|
3
|
+
export type ServerOptions = {
|
|
4
|
+
hostname?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
config?: Config;
|
|
9
|
+
};
|
|
10
|
+
export type TuiOptions = {
|
|
11
|
+
project?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
session?: string;
|
|
14
|
+
agent?: string;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
config?: Config;
|
|
17
|
+
};
|
|
18
|
+
export declare function createOpencodeServer(options?: ServerOptions): Promise<{
|
|
19
|
+
url: string;
|
|
20
|
+
close(): void;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function createOpencodeTui(options?: TuiOptions): {
|
|
23
|
+
close(): void;
|
|
24
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
// kilocode_change start - Merge existing OPENCODE_CONFIG_CONTENT with new config
|
|
3
|
+
// This preserves Kilocode-injected modes when spawning nested CLI instances
|
|
4
|
+
function mergeConfig(existing, incoming) {
|
|
5
|
+
const base = existing ?? {};
|
|
6
|
+
const override = incoming ?? {};
|
|
7
|
+
return {
|
|
8
|
+
...base,
|
|
9
|
+
...override,
|
|
10
|
+
agent: { ...base.agent, ...override.agent },
|
|
11
|
+
command: { ...base.command, ...override.command },
|
|
12
|
+
mcp: { ...base.mcp, ...override.mcp },
|
|
13
|
+
mode: { ...base.mode, ...override.mode },
|
|
14
|
+
plugin: [...(base.plugin ?? []), ...(override.plugin ?? [])],
|
|
15
|
+
instructions: [...(base.instructions ?? []), ...(override.instructions ?? [])],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function parseExistingConfig() {
|
|
19
|
+
const content = process.env.OPENCODE_CONFIG_CONTENT;
|
|
20
|
+
if (!content)
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
return JSON.parse(content);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function buildConfigEnv(config) {
|
|
30
|
+
const merged = mergeConfig(parseExistingConfig(), config);
|
|
31
|
+
return JSON.stringify(merged);
|
|
32
|
+
}
|
|
33
|
+
export async function createOpencodeServer(options) {
|
|
34
|
+
options = Object.assign({
|
|
35
|
+
hostname: "127.0.0.1",
|
|
36
|
+
port: 4096,
|
|
37
|
+
timeout: 5000,
|
|
38
|
+
}, options ?? {});
|
|
39
|
+
const args = [`serve`, `--hostname=${options.hostname}`, `--port=${options.port}`];
|
|
40
|
+
if (options.config?.logLevel)
|
|
41
|
+
args.push(`--log-level=${options.config.logLevel}`);
|
|
42
|
+
const proc = spawn(`opencode`, args, {
|
|
43
|
+
signal: options.signal,
|
|
44
|
+
env: {
|
|
45
|
+
...process.env,
|
|
46
|
+
OPENCODE_CONFIG_CONTENT: buildConfigEnv(options.config), // kilocode_change
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const url = await new Promise((resolve, reject) => {
|
|
50
|
+
const id = setTimeout(() => {
|
|
51
|
+
reject(new Error(`Timeout waiting for server to start after ${options.timeout}ms`));
|
|
52
|
+
}, options.timeout);
|
|
53
|
+
let output = "";
|
|
54
|
+
proc.stdout?.on("data", (chunk) => {
|
|
55
|
+
output += chunk.toString();
|
|
56
|
+
const lines = output.split("\n");
|
|
57
|
+
for (const line of lines) {
|
|
58
|
+
if (line.startsWith("opencode server listening")) {
|
|
59
|
+
const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
60
|
+
if (!match) {
|
|
61
|
+
throw new Error(`Failed to parse server url from output: ${line}`);
|
|
62
|
+
}
|
|
63
|
+
clearTimeout(id);
|
|
64
|
+
resolve(match[1]);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
proc.stderr?.on("data", (chunk) => {
|
|
70
|
+
output += chunk.toString();
|
|
71
|
+
});
|
|
72
|
+
proc.on("exit", (code) => {
|
|
73
|
+
clearTimeout(id);
|
|
74
|
+
let msg = `Server exited with code ${code}`;
|
|
75
|
+
if (output.trim()) {
|
|
76
|
+
msg += `\nServer output: ${output}`;
|
|
77
|
+
}
|
|
78
|
+
reject(new Error(msg));
|
|
79
|
+
});
|
|
80
|
+
proc.on("error", (error) => {
|
|
81
|
+
clearTimeout(id);
|
|
82
|
+
reject(error);
|
|
83
|
+
});
|
|
84
|
+
if (options.signal) {
|
|
85
|
+
options.signal.addEventListener("abort", () => {
|
|
86
|
+
clearTimeout(id);
|
|
87
|
+
reject(new Error("Aborted"));
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
url,
|
|
93
|
+
close() {
|
|
94
|
+
proc.kill();
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function createOpencodeTui(options) {
|
|
99
|
+
const args = [];
|
|
100
|
+
if (options?.project) {
|
|
101
|
+
args.push(`--project=${options.project}`);
|
|
102
|
+
}
|
|
103
|
+
if (options?.model) {
|
|
104
|
+
args.push(`--model=${options.model}`);
|
|
105
|
+
}
|
|
106
|
+
if (options?.session) {
|
|
107
|
+
args.push(`--session=${options.session}`);
|
|
108
|
+
}
|
|
109
|
+
if (options?.agent) {
|
|
110
|
+
args.push(`--agent=${options.agent}`);
|
|
111
|
+
}
|
|
112
|
+
const proc = spawn(`opencode`, args, {
|
|
113
|
+
signal: options?.signal,
|
|
114
|
+
stdio: "inherit",
|
|
115
|
+
env: {
|
|
116
|
+
...process.env,
|
|
117
|
+
OPENCODE_CONFIG_CONTENT: buildConfigEnv(options?.config), // kilocode_change
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
close() {
|
|
122
|
+
proc.kill();
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "@kilocode/sdk",
|
|
4
|
+
"version": "1.0.0",
|
|
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
|
+
"import": "./dist/v2/index.js",
|
|
26
|
+
"types": "./dist/v2/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./v2/client": {
|
|
29
|
+
"import": "./dist/v2/client.js",
|
|
30
|
+
"types": "./dist/v2/client.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./v2/server": {
|
|
33
|
+
"import": "./dist/v2/server.js",
|
|
34
|
+
"types": "./dist/v2/server.d.ts"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@hey-api/openapi-ts": "0.90.10",
|
|
42
|
+
"@tsconfig/node22": "22.0.2",
|
|
43
|
+
"@types/node": "22.13.9",
|
|
44
|
+
"typescript": "5.8.2",
|
|
45
|
+
"@typescript/native-preview": "7.0.0-dev.20251207.1"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"directory": "dist"
|
|
50
|
+
}
|
|
51
|
+
}
|