@hasna/codewith-sdk 0.1.26
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/LICENSE +201 -0
- package/MODIFICATIONS.md +17 -0
- package/NOTICE +12 -0
- package/README.md +149 -0
- package/THIRD_PARTY_NOTICES.md +18 -0
- package/dist/index.d.ts +276 -0
- package/dist/index.js +554 -0
- package/dist/index.js.map +1 -0
- package/licenses/bubblewrap-LGPL-2.0.txt +481 -0
- package/licenses/ripgrep-LICENSE-MIT.txt +21 -0
- package/licenses/ripgrep-UNLICENSE.txt +21 -0
- package/licenses/zsh-LICENCE.txt +32 -0
- package/package.json +78 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
// src/outputSchemaFile.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
async function createOutputSchemaFile(schema) {
|
|
6
|
+
if (schema === void 0) {
|
|
7
|
+
return { cleanup: async () => {
|
|
8
|
+
} };
|
|
9
|
+
}
|
|
10
|
+
if (!isJsonObject(schema)) {
|
|
11
|
+
throw new Error("outputSchema must be a plain JSON object");
|
|
12
|
+
}
|
|
13
|
+
const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), "codex-output-schema-"));
|
|
14
|
+
const schemaPath = path.join(schemaDir, "schema.json");
|
|
15
|
+
const cleanup = async () => {
|
|
16
|
+
try {
|
|
17
|
+
await fs.rm(schemaDir, { recursive: true, force: true });
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
await fs.writeFile(schemaPath, JSON.stringify(schema), "utf8");
|
|
23
|
+
return { schemaPath, cleanup };
|
|
24
|
+
} catch (error) {
|
|
25
|
+
await cleanup();
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isJsonObject(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/thread.ts
|
|
34
|
+
var Thread = class {
|
|
35
|
+
_exec;
|
|
36
|
+
_options;
|
|
37
|
+
_id;
|
|
38
|
+
_threadOptions;
|
|
39
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
40
|
+
get id() {
|
|
41
|
+
return this._id;
|
|
42
|
+
}
|
|
43
|
+
/* @internal */
|
|
44
|
+
constructor(exec, options, threadOptions, id = null) {
|
|
45
|
+
this._exec = exec;
|
|
46
|
+
this._options = options;
|
|
47
|
+
this._id = id;
|
|
48
|
+
this._threadOptions = threadOptions;
|
|
49
|
+
}
|
|
50
|
+
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
51
|
+
async runStreamed(input, turnOptions = {}) {
|
|
52
|
+
return { events: this.runStreamedInternal(input, turnOptions) };
|
|
53
|
+
}
|
|
54
|
+
async *runStreamedInternal(input, turnOptions = {}) {
|
|
55
|
+
const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);
|
|
56
|
+
const options = this._threadOptions;
|
|
57
|
+
const { prompt, images } = normalizeInput(input);
|
|
58
|
+
const generator = this._exec.run({
|
|
59
|
+
input: prompt,
|
|
60
|
+
baseUrl: this._options.baseUrl,
|
|
61
|
+
apiKey: this._options.apiKey,
|
|
62
|
+
threadId: this._id,
|
|
63
|
+
images,
|
|
64
|
+
model: options?.model,
|
|
65
|
+
sandboxMode: options?.sandboxMode,
|
|
66
|
+
workingDirectory: options?.workingDirectory,
|
|
67
|
+
skipGitRepoCheck: options?.skipGitRepoCheck,
|
|
68
|
+
outputSchemaFile: schemaPath,
|
|
69
|
+
modelReasoningEffort: options?.modelReasoningEffort,
|
|
70
|
+
signal: turnOptions.signal,
|
|
71
|
+
networkAccessEnabled: options?.networkAccessEnabled,
|
|
72
|
+
webSearchMode: options?.webSearchMode,
|
|
73
|
+
webSearchEnabled: options?.webSearchEnabled,
|
|
74
|
+
approvalPolicy: options?.approvalPolicy,
|
|
75
|
+
additionalDirectories: options?.additionalDirectories
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
for await (const item of generator) {
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(item);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error(`Failed to parse item: ${item}`, { cause: error });
|
|
84
|
+
}
|
|
85
|
+
if (parsed.type === "thread.started") {
|
|
86
|
+
this._id = parsed.thread_id;
|
|
87
|
+
}
|
|
88
|
+
yield parsed;
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
await cleanup();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
95
|
+
async run(input, turnOptions = {}) {
|
|
96
|
+
const generator = this.runStreamedInternal(input, turnOptions);
|
|
97
|
+
const items = [];
|
|
98
|
+
let finalResponse = "";
|
|
99
|
+
let usage = null;
|
|
100
|
+
let turnFailure = null;
|
|
101
|
+
for await (const event of generator) {
|
|
102
|
+
if (event.type === "item.completed") {
|
|
103
|
+
if (event.item.type === "agent_message") {
|
|
104
|
+
finalResponse = event.item.text;
|
|
105
|
+
}
|
|
106
|
+
items.push(event.item);
|
|
107
|
+
} else if (event.type === "turn.completed") {
|
|
108
|
+
usage = event.usage;
|
|
109
|
+
} else if (event.type === "turn.failed") {
|
|
110
|
+
turnFailure = event.error;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (turnFailure) {
|
|
115
|
+
throw new Error(turnFailure.message);
|
|
116
|
+
}
|
|
117
|
+
return { items, finalResponse, usage };
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function normalizeInput(input) {
|
|
121
|
+
if (typeof input === "string") {
|
|
122
|
+
return { prompt: input, images: [] };
|
|
123
|
+
}
|
|
124
|
+
const promptParts = [];
|
|
125
|
+
const images = [];
|
|
126
|
+
for (const item of input) {
|
|
127
|
+
if (item.type === "text") {
|
|
128
|
+
promptParts.push(item.text);
|
|
129
|
+
} else if (item.type === "local_image") {
|
|
130
|
+
images.push(item.path);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { prompt: promptParts.join("\n\n"), images };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/exec.ts
|
|
137
|
+
import { spawn } from "child_process";
|
|
138
|
+
import { statSync } from "fs";
|
|
139
|
+
import path2 from "path";
|
|
140
|
+
import readline from "readline";
|
|
141
|
+
import { createRequire } from "module";
|
|
142
|
+
var INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
|
|
143
|
+
var TYPESCRIPT_SDK_ORIGINATOR = "codex_sdk_ts";
|
|
144
|
+
var CODEX_NPM_NAME = "@hasna/codewith";
|
|
145
|
+
var PLATFORM_PACKAGE_BY_TARGET = {
|
|
146
|
+
"x86_64-unknown-linux-musl": "@hasna/codewith-linux-x64",
|
|
147
|
+
"aarch64-unknown-linux-musl": "@hasna/codewith-linux-arm64",
|
|
148
|
+
"x86_64-apple-darwin": "@hasna/codewith-darwin-x64",
|
|
149
|
+
"aarch64-apple-darwin": "@hasna/codewith-darwin-arm64",
|
|
150
|
+
"x86_64-pc-windows-msvc": "@hasna/codewith-win32-x64",
|
|
151
|
+
"aarch64-pc-windows-msvc": "@hasna/codewith-win32-arm64"
|
|
152
|
+
};
|
|
153
|
+
var moduleRequire = createRequire(import.meta.url);
|
|
154
|
+
var CodexExec = class {
|
|
155
|
+
executablePath;
|
|
156
|
+
pathDirs;
|
|
157
|
+
envOverride;
|
|
158
|
+
configOverrides;
|
|
159
|
+
constructor(executablePath = null, env, configOverrides) {
|
|
160
|
+
if (executablePath) {
|
|
161
|
+
this.executablePath = executablePath;
|
|
162
|
+
this.pathDirs = [];
|
|
163
|
+
} else {
|
|
164
|
+
const resolved = findCodexPath();
|
|
165
|
+
this.executablePath = resolved.executablePath;
|
|
166
|
+
this.pathDirs = resolved.pathDirs;
|
|
167
|
+
}
|
|
168
|
+
this.envOverride = env;
|
|
169
|
+
this.configOverrides = configOverrides;
|
|
170
|
+
}
|
|
171
|
+
async *run(args) {
|
|
172
|
+
const commandArgs = ["exec", "--experimental-json"];
|
|
173
|
+
if (this.configOverrides) {
|
|
174
|
+
for (const override of serializeConfigOverrides(this.configOverrides)) {
|
|
175
|
+
commandArgs.push("--config", override);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (args.baseUrl) {
|
|
179
|
+
commandArgs.push(
|
|
180
|
+
"--config",
|
|
181
|
+
`openai_base_url=${toTomlValue(args.baseUrl, "openai_base_url")}`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (args.model) {
|
|
185
|
+
commandArgs.push("--model", args.model);
|
|
186
|
+
}
|
|
187
|
+
if (args.sandboxMode) {
|
|
188
|
+
commandArgs.push("--sandbox", args.sandboxMode);
|
|
189
|
+
}
|
|
190
|
+
if (args.workingDirectory) {
|
|
191
|
+
commandArgs.push("--cd", args.workingDirectory);
|
|
192
|
+
}
|
|
193
|
+
if (args.additionalDirectories?.length) {
|
|
194
|
+
for (const dir of args.additionalDirectories) {
|
|
195
|
+
commandArgs.push("--add-dir", dir);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (args.skipGitRepoCheck) {
|
|
199
|
+
commandArgs.push("--skip-git-repo-check");
|
|
200
|
+
}
|
|
201
|
+
if (args.outputSchemaFile) {
|
|
202
|
+
commandArgs.push("--output-schema", args.outputSchemaFile);
|
|
203
|
+
}
|
|
204
|
+
if (args.modelReasoningEffort) {
|
|
205
|
+
commandArgs.push("--config", `model_reasoning_effort="${args.modelReasoningEffort}"`);
|
|
206
|
+
}
|
|
207
|
+
if (args.networkAccessEnabled !== void 0) {
|
|
208
|
+
commandArgs.push(
|
|
209
|
+
"--config",
|
|
210
|
+
`sandbox_workspace_write.network_access=${args.networkAccessEnabled}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (args.webSearchMode) {
|
|
214
|
+
commandArgs.push("--config", `web_search="${args.webSearchMode}"`);
|
|
215
|
+
} else if (args.webSearchEnabled === true) {
|
|
216
|
+
commandArgs.push("--config", `web_search="live"`);
|
|
217
|
+
} else if (args.webSearchEnabled === false) {
|
|
218
|
+
commandArgs.push("--config", `web_search="disabled"`);
|
|
219
|
+
}
|
|
220
|
+
if (args.approvalPolicy) {
|
|
221
|
+
commandArgs.push("--config", `approval_policy="${args.approvalPolicy}"`);
|
|
222
|
+
}
|
|
223
|
+
if (args.threadId) {
|
|
224
|
+
commandArgs.push("resume", args.threadId);
|
|
225
|
+
}
|
|
226
|
+
if (args.images?.length) {
|
|
227
|
+
for (const image of args.images) {
|
|
228
|
+
commandArgs.push("--image", image);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const env = {};
|
|
232
|
+
if (this.envOverride) {
|
|
233
|
+
Object.assign(env, this.envOverride);
|
|
234
|
+
} else {
|
|
235
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
236
|
+
if (value !== void 0) {
|
|
237
|
+
env[key] = value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!env[INTERNAL_ORIGINATOR_ENV]) {
|
|
242
|
+
env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;
|
|
243
|
+
}
|
|
244
|
+
if (args.apiKey) {
|
|
245
|
+
env.CODEX_API_KEY = args.apiKey;
|
|
246
|
+
}
|
|
247
|
+
if (this.pathDirs.length > 0) {
|
|
248
|
+
prependPathDirs(env, this.pathDirs);
|
|
249
|
+
}
|
|
250
|
+
const child = spawn(this.executablePath, commandArgs, {
|
|
251
|
+
env,
|
|
252
|
+
signal: args.signal
|
|
253
|
+
});
|
|
254
|
+
let spawnError = null;
|
|
255
|
+
child.once("error", (err) => spawnError = err);
|
|
256
|
+
if (!child.stdin) {
|
|
257
|
+
child.kill();
|
|
258
|
+
throw new Error("Child process has no stdin");
|
|
259
|
+
}
|
|
260
|
+
child.stdin.write(args.input);
|
|
261
|
+
child.stdin.end();
|
|
262
|
+
if (!child.stdout) {
|
|
263
|
+
child.kill();
|
|
264
|
+
throw new Error("Child process has no stdout");
|
|
265
|
+
}
|
|
266
|
+
const stderrChunks = [];
|
|
267
|
+
if (child.stderr) {
|
|
268
|
+
child.stderr.on("data", (data) => {
|
|
269
|
+
stderrChunks.push(data);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const exitPromise = new Promise(
|
|
273
|
+
(resolve) => {
|
|
274
|
+
child.once("exit", (code, signal) => {
|
|
275
|
+
resolve({ code, signal });
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
const rl = readline.createInterface({
|
|
280
|
+
input: child.stdout,
|
|
281
|
+
crlfDelay: Infinity
|
|
282
|
+
});
|
|
283
|
+
try {
|
|
284
|
+
for await (const line of rl) {
|
|
285
|
+
yield line;
|
|
286
|
+
}
|
|
287
|
+
if (spawnError) throw spawnError;
|
|
288
|
+
const { code, signal } = await exitPromise;
|
|
289
|
+
if (code !== 0 || signal) {
|
|
290
|
+
const stderrBuffer = Buffer.concat(stderrChunks);
|
|
291
|
+
const detail = signal ? `signal ${signal}` : `code ${code ?? 1}`;
|
|
292
|
+
throw new Error(`Codewith exec exited with ${detail}: ${stderrBuffer.toString("utf8")}`);
|
|
293
|
+
}
|
|
294
|
+
} finally {
|
|
295
|
+
rl.close();
|
|
296
|
+
child.removeAllListeners();
|
|
297
|
+
try {
|
|
298
|
+
if (!child.killed) child.kill();
|
|
299
|
+
} catch {
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
function serializeConfigOverrides(configOverrides) {
|
|
305
|
+
const overrides = [];
|
|
306
|
+
flattenConfigOverrides(configOverrides, "", overrides);
|
|
307
|
+
return overrides;
|
|
308
|
+
}
|
|
309
|
+
function flattenConfigOverrides(value, prefix, overrides) {
|
|
310
|
+
if (!isPlainObject(value)) {
|
|
311
|
+
if (prefix) {
|
|
312
|
+
overrides.push(`${prefix}=${toTomlValue(value, prefix)}`);
|
|
313
|
+
return;
|
|
314
|
+
} else {
|
|
315
|
+
throw new Error("Codewith config overrides must be a plain object");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const entries = Object.entries(value);
|
|
319
|
+
if (!prefix && entries.length === 0) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (prefix && entries.length === 0) {
|
|
323
|
+
overrides.push(`${prefix}={}`);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
for (const [key, child] of entries) {
|
|
327
|
+
if (!key) {
|
|
328
|
+
throw new Error("Codewith config override keys must be non-empty strings");
|
|
329
|
+
}
|
|
330
|
+
if (child === void 0) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const path3 = prefix ? `${prefix}.${key}` : key;
|
|
334
|
+
if (isPlainObject(child)) {
|
|
335
|
+
flattenConfigOverrides(child, path3, overrides);
|
|
336
|
+
} else {
|
|
337
|
+
overrides.push(`${path3}=${toTomlValue(child, path3)}`);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function toTomlValue(value, path3) {
|
|
342
|
+
if (typeof value === "string") {
|
|
343
|
+
return JSON.stringify(value);
|
|
344
|
+
} else if (typeof value === "number") {
|
|
345
|
+
if (!Number.isFinite(value)) {
|
|
346
|
+
throw new Error(`Codewith config override at ${path3} must be a finite number`);
|
|
347
|
+
}
|
|
348
|
+
return `${value}`;
|
|
349
|
+
} else if (typeof value === "boolean") {
|
|
350
|
+
return value ? "true" : "false";
|
|
351
|
+
} else if (Array.isArray(value)) {
|
|
352
|
+
const rendered = value.map((item, index) => toTomlValue(item, `${path3}[${index}]`));
|
|
353
|
+
return `[${rendered.join(", ")}]`;
|
|
354
|
+
} else if (isPlainObject(value)) {
|
|
355
|
+
const parts = [];
|
|
356
|
+
for (const [key, child] of Object.entries(value)) {
|
|
357
|
+
if (!key) {
|
|
358
|
+
throw new Error("Codewith config override keys must be non-empty strings");
|
|
359
|
+
}
|
|
360
|
+
if (child === void 0) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
parts.push(`${formatTomlKey(key)} = ${toTomlValue(child, `${path3}.${key}`)}`);
|
|
364
|
+
}
|
|
365
|
+
return `{${parts.join(", ")}}`;
|
|
366
|
+
} else if (value === null) {
|
|
367
|
+
throw new Error(`Codewith config override at ${path3} cannot be null`);
|
|
368
|
+
} else {
|
|
369
|
+
const typeName = typeof value;
|
|
370
|
+
throw new Error(`Unsupported Codewith config override value at ${path3}: ${typeName}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
var TOML_BARE_KEY = /^[A-Za-z0-9_-]+$/;
|
|
374
|
+
function formatTomlKey(key) {
|
|
375
|
+
return TOML_BARE_KEY.test(key) ? key : JSON.stringify(key);
|
|
376
|
+
}
|
|
377
|
+
function isPlainObject(value) {
|
|
378
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
379
|
+
}
|
|
380
|
+
function findCodexPath() {
|
|
381
|
+
const { platform, arch } = process;
|
|
382
|
+
let targetTriple = null;
|
|
383
|
+
switch (platform) {
|
|
384
|
+
case "linux":
|
|
385
|
+
case "android":
|
|
386
|
+
switch (arch) {
|
|
387
|
+
case "x64":
|
|
388
|
+
targetTriple = "x86_64-unknown-linux-musl";
|
|
389
|
+
break;
|
|
390
|
+
case "arm64":
|
|
391
|
+
targetTriple = "aarch64-unknown-linux-musl";
|
|
392
|
+
break;
|
|
393
|
+
default:
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
case "darwin":
|
|
398
|
+
switch (arch) {
|
|
399
|
+
case "x64":
|
|
400
|
+
targetTriple = "x86_64-apple-darwin";
|
|
401
|
+
break;
|
|
402
|
+
case "arm64":
|
|
403
|
+
targetTriple = "aarch64-apple-darwin";
|
|
404
|
+
break;
|
|
405
|
+
default:
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
break;
|
|
409
|
+
case "win32":
|
|
410
|
+
switch (arch) {
|
|
411
|
+
case "x64":
|
|
412
|
+
targetTriple = "x86_64-pc-windows-msvc";
|
|
413
|
+
break;
|
|
414
|
+
case "arm64":
|
|
415
|
+
targetTriple = "aarch64-pc-windows-msvc";
|
|
416
|
+
break;
|
|
417
|
+
default:
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
break;
|
|
421
|
+
default:
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
if (!targetTriple) {
|
|
425
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
426
|
+
}
|
|
427
|
+
const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
|
|
428
|
+
if (!platformPackage) {
|
|
429
|
+
throw new Error(`Unsupported target triple: ${targetTriple}`);
|
|
430
|
+
}
|
|
431
|
+
let vendorRoot;
|
|
432
|
+
try {
|
|
433
|
+
const codexPackageJsonPath = moduleRequire.resolve(`${CODEX_NPM_NAME}/package.json`);
|
|
434
|
+
const codexRequire = createRequire(codexPackageJsonPath);
|
|
435
|
+
const platformPackageJsonPath = codexRequire.resolve(`${platformPackage}/package.json`);
|
|
436
|
+
vendorRoot = path2.join(path2.dirname(platformPackageJsonPath), "vendor");
|
|
437
|
+
} catch {
|
|
438
|
+
throw new Error(
|
|
439
|
+
`Unable to locate Codewith CLI binaries. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
const codewithBinaryName = process.platform === "win32" ? "codewith.exe" : "codewith";
|
|
443
|
+
const legacyCodexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
|
|
444
|
+
const nativePackage = resolveNativePackage(
|
|
445
|
+
vendorRoot,
|
|
446
|
+
targetTriple,
|
|
447
|
+
codewithBinaryName,
|
|
448
|
+
legacyCodexBinaryName
|
|
449
|
+
);
|
|
450
|
+
if (!nativePackage) {
|
|
451
|
+
throw new Error(
|
|
452
|
+
`Unable to locate Codewith CLI binaries for ${targetTriple}. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return nativePackage;
|
|
456
|
+
}
|
|
457
|
+
function resolveNativePackage(vendorRoot, targetTriple, codewithBinaryName, legacyCodexBinaryName = codewithBinaryName) {
|
|
458
|
+
const packageRoot = path2.join(vendorRoot, targetTriple);
|
|
459
|
+
const packagePathDirs = existingDirs(
|
|
460
|
+
path2.join(packageRoot, "codewith-path"),
|
|
461
|
+
path2.join(packageRoot, "codex-path")
|
|
462
|
+
);
|
|
463
|
+
const packageBinaryPath = path2.join(packageRoot, "bin", codewithBinaryName);
|
|
464
|
+
if (isFile(packageBinaryPath) && isFile(path2.join(packageRoot, "codex-package.json"))) {
|
|
465
|
+
return {
|
|
466
|
+
executablePath: packageBinaryPath,
|
|
467
|
+
pathDirs: packagePathDirs
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
const legacyPackageBinaryPath = path2.join(packageRoot, "bin", legacyCodexBinaryName);
|
|
471
|
+
if (isFile(legacyPackageBinaryPath) && isFile(path2.join(packageRoot, "codex-package.json"))) {
|
|
472
|
+
return {
|
|
473
|
+
executablePath: legacyPackageBinaryPath,
|
|
474
|
+
pathDirs: packagePathDirs
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const legacyBinaryPath = path2.join(packageRoot, "codex", legacyCodexBinaryName);
|
|
478
|
+
if (isFile(legacyBinaryPath)) {
|
|
479
|
+
return {
|
|
480
|
+
executablePath: legacyBinaryPath,
|
|
481
|
+
pathDirs: existingDirs(path2.join(packageRoot, "path"))
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
function existingDirs(...dirs) {
|
|
487
|
+
return dirs.filter(isDirectory);
|
|
488
|
+
}
|
|
489
|
+
function prependPathDirs(env, pathDirs, platform = process.platform) {
|
|
490
|
+
const pathKey = pathEnvKey(env, platform);
|
|
491
|
+
if (platform === "win32") {
|
|
492
|
+
for (const key of Object.keys(env)) {
|
|
493
|
+
if (key.toLowerCase() === "path" && key !== pathKey) {
|
|
494
|
+
delete env[key];
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const existingEntries = (env[pathKey] ?? "").split(path2.delimiter).filter((entry) => entry.length > 0 && !pathDirs.includes(entry));
|
|
499
|
+
env[pathKey] = [...pathDirs, ...existingEntries].join(path2.delimiter);
|
|
500
|
+
}
|
|
501
|
+
function pathEnvKey(env, platform) {
|
|
502
|
+
if (platform !== "win32") {
|
|
503
|
+
return "PATH";
|
|
504
|
+
}
|
|
505
|
+
const matchingKeys = Object.keys(env).filter((key) => key.toLowerCase() === "path");
|
|
506
|
+
return matchingKeys.includes("Path") ? "Path" : matchingKeys.at(-1) ?? "PATH";
|
|
507
|
+
}
|
|
508
|
+
function isFile(filePath) {
|
|
509
|
+
try {
|
|
510
|
+
return statSync(filePath).isFile();
|
|
511
|
+
} catch {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function isDirectory(filePath) {
|
|
516
|
+
try {
|
|
517
|
+
return statSync(filePath).isDirectory();
|
|
518
|
+
} catch {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/codex.ts
|
|
524
|
+
var Codewith = class {
|
|
525
|
+
exec;
|
|
526
|
+
options;
|
|
527
|
+
constructor(options = {}) {
|
|
528
|
+
const { codexPathOverride, env, config } = options;
|
|
529
|
+
this.exec = new CodexExec(codexPathOverride, env, config);
|
|
530
|
+
this.options = options;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Starts a new conversation with an agent.
|
|
534
|
+
* @returns A new thread instance.
|
|
535
|
+
*/
|
|
536
|
+
startThread(options = {}) {
|
|
537
|
+
return new Thread(this.exec, this.options, options);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
541
|
+
* Threads are persisted in ~/.codewith/sessions by default.
|
|
542
|
+
*
|
|
543
|
+
* @param id The id of the thread to resume.
|
|
544
|
+
* @returns A new thread instance.
|
|
545
|
+
*/
|
|
546
|
+
resumeThread(id, options = {}) {
|
|
547
|
+
return new Thread(this.exec, this.options, options, id);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
export {
|
|
551
|
+
Codewith,
|
|
552
|
+
Thread
|
|
553
|
+
};
|
|
554
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/outputSchemaFile.ts","../src/thread.ts","../src/exec.ts","../src/codex.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nexport type OutputSchemaFile = {\n schemaPath?: string;\n cleanup: () => Promise<void>;\n};\n\nexport async function createOutputSchemaFile(schema: unknown): Promise<OutputSchemaFile> {\n if (schema === undefined) {\n return { cleanup: async () => {} };\n }\n\n if (!isJsonObject(schema)) {\n throw new Error(\"outputSchema must be a plain JSON object\");\n }\n\n const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), \"codex-output-schema-\"));\n const schemaPath = path.join(schemaDir, \"schema.json\");\n const cleanup = async () => {\n try {\n await fs.rm(schemaDir, { recursive: true, force: true });\n } catch {\n // suppress\n }\n };\n\n try {\n await fs.writeFile(schemaPath, JSON.stringify(schema), \"utf8\");\n return { schemaPath, cleanup };\n } catch (error) {\n await cleanup();\n throw error;\n }\n}\n\nfunction isJsonObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { ThreadEvent, ThreadError, Usage } from \"./events\";\nimport { CodexExec } from \"./exec\";\nimport { ThreadItem } from \"./items\";\nimport { ThreadOptions } from \"./threadOptions\";\nimport { TurnOptions } from \"./turnOptions\";\nimport { createOutputSchemaFile } from \"./outputSchemaFile\";\n\n/** Completed turn. */\nexport type Turn = {\n items: ThreadItem[];\n finalResponse: string;\n usage: Usage | null;\n};\n\n/** Alias for `Turn` to describe the result of `run()`. */\nexport type RunResult = Turn;\n\n/** The result of the `runStreamed` method. */\nexport type StreamedTurn = {\n events: AsyncGenerator<ThreadEvent>;\n};\n\n/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */\nexport type RunStreamedResult = StreamedTurn;\n\n/** An input to send to the agent. */\nexport type UserInput =\n | {\n type: \"text\";\n text: string;\n }\n | {\n type: \"local_image\";\n path: string;\n };\n\nexport type Input = string | UserInput[];\n\n/** Represent a thread of conversation with the agent. One thread can have multiple consecutive turns. */\nexport class Thread {\n private _exec: CodexExec;\n private _options: CodexOptions;\n private _id: string | null;\n private _threadOptions: ThreadOptions;\n\n /** Returns the ID of the thread. Populated after the first turn starts. */\n public get id(): string | null {\n return this._id;\n }\n\n /* @internal */\n constructor(\n exec: CodexExec,\n options: CodexOptions,\n threadOptions: ThreadOptions,\n id: string | null = null,\n ) {\n this._exec = exec;\n this._options = options;\n this._id = id;\n this._threadOptions = threadOptions;\n }\n\n /** Provides the input to the agent and streams events as they are produced during the turn. */\n async runStreamed(input: Input, turnOptions: TurnOptions = {}): Promise<StreamedTurn> {\n return { events: this.runStreamedInternal(input, turnOptions) };\n }\n\n private async *runStreamedInternal(\n input: Input,\n turnOptions: TurnOptions = {},\n ): AsyncGenerator<ThreadEvent> {\n const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);\n const options = this._threadOptions;\n const { prompt, images } = normalizeInput(input);\n const generator = this._exec.run({\n input: prompt,\n baseUrl: this._options.baseUrl,\n apiKey: this._options.apiKey,\n threadId: this._id,\n images,\n model: options?.model,\n sandboxMode: options?.sandboxMode,\n workingDirectory: options?.workingDirectory,\n skipGitRepoCheck: options?.skipGitRepoCheck,\n outputSchemaFile: schemaPath,\n modelReasoningEffort: options?.modelReasoningEffort,\n signal: turnOptions.signal,\n networkAccessEnabled: options?.networkAccessEnabled,\n webSearchMode: options?.webSearchMode,\n webSearchEnabled: options?.webSearchEnabled,\n approvalPolicy: options?.approvalPolicy,\n additionalDirectories: options?.additionalDirectories,\n });\n try {\n for await (const item of generator) {\n let parsed: ThreadEvent;\n try {\n parsed = JSON.parse(item) as ThreadEvent;\n } catch (error) {\n throw new Error(`Failed to parse item: ${item}`, { cause: error });\n }\n if (parsed.type === \"thread.started\") {\n this._id = parsed.thread_id;\n }\n yield parsed;\n }\n } finally {\n await cleanup();\n }\n }\n\n /** Provides the input to the agent and returns the completed turn. */\n async run(input: Input, turnOptions: TurnOptions = {}): Promise<Turn> {\n const generator = this.runStreamedInternal(input, turnOptions);\n const items: ThreadItem[] = [];\n let finalResponse: string = \"\";\n let usage: Usage | null = null;\n let turnFailure: ThreadError | null = null;\n for await (const event of generator) {\n if (event.type === \"item.completed\") {\n if (event.item.type === \"agent_message\") {\n finalResponse = event.item.text;\n }\n items.push(event.item);\n } else if (event.type === \"turn.completed\") {\n usage = event.usage;\n } else if (event.type === \"turn.failed\") {\n turnFailure = event.error;\n break;\n }\n }\n if (turnFailure) {\n throw new Error(turnFailure.message);\n }\n return { items, finalResponse, usage };\n }\n}\n\nfunction normalizeInput(input: Input): { prompt: string; images: string[] } {\n if (typeof input === \"string\") {\n return { prompt: input, images: [] };\n }\n const promptParts: string[] = [];\n const images: string[] = [];\n for (const item of input) {\n if (item.type === \"text\") {\n promptParts.push(item.text);\n } else if (item.type === \"local_image\") {\n images.push(item.path);\n }\n }\n return { prompt: promptParts.join(\"\\n\\n\"), images };\n}\n","import { spawn } from \"node:child_process\";\nimport { statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport readline from \"node:readline\";\nimport { createRequire } from \"node:module\";\n\nimport type { CodexConfigObject, CodexConfigValue } from \"./codexOptions\";\nimport { SandboxMode, ModelReasoningEffort, ApprovalMode, WebSearchMode } from \"./threadOptions\";\n\nexport type CodexExecArgs = {\n input: string;\n\n baseUrl?: string;\n apiKey?: string;\n threadId?: string | null;\n images?: string[];\n // --model\n model?: string;\n // --sandbox\n sandboxMode?: SandboxMode;\n // --cd\n workingDirectory?: string;\n // --add-dir\n additionalDirectories?: string[];\n // --skip-git-repo-check\n skipGitRepoCheck?: boolean;\n // --output-schema\n outputSchemaFile?: string;\n // --config model_reasoning_effort\n modelReasoningEffort?: ModelReasoningEffort;\n // AbortSignal to cancel the execution\n signal?: AbortSignal;\n // --config sandbox_workspace_write.network_access\n networkAccessEnabled?: boolean;\n // --config web_search\n webSearchMode?: WebSearchMode;\n // legacy --config features.web_search_request\n webSearchEnabled?: boolean;\n // --config approval_policy\n approvalPolicy?: ApprovalMode;\n};\n\nconst INTERNAL_ORIGINATOR_ENV = \"CODEX_INTERNAL_ORIGINATOR_OVERRIDE\";\nconst TYPESCRIPT_SDK_ORIGINATOR = \"codex_sdk_ts\";\nconst CODEX_NPM_NAME = \"@hasna/codewith\";\n\nconst PLATFORM_PACKAGE_BY_TARGET: Record<string, string> = {\n \"x86_64-unknown-linux-musl\": \"@hasna/codewith-linux-x64\",\n \"aarch64-unknown-linux-musl\": \"@hasna/codewith-linux-arm64\",\n \"x86_64-apple-darwin\": \"@hasna/codewith-darwin-x64\",\n \"aarch64-apple-darwin\": \"@hasna/codewith-darwin-arm64\",\n \"x86_64-pc-windows-msvc\": \"@hasna/codewith-win32-x64\",\n \"aarch64-pc-windows-msvc\": \"@hasna/codewith-win32-arm64\",\n};\n\nconst moduleRequire = createRequire(import.meta.url);\n\ntype CodexPathResolution = {\n executablePath: string;\n pathDirs: string[];\n};\n\nexport class CodexExec {\n private executablePath: string;\n private pathDirs: string[];\n private envOverride?: Record<string, string>;\n private configOverrides?: CodexConfigObject;\n\n constructor(\n executablePath: string | null = null,\n env?: Record<string, string>,\n configOverrides?: CodexConfigObject,\n ) {\n if (executablePath) {\n this.executablePath = executablePath;\n this.pathDirs = [];\n } else {\n const resolved = findCodexPath();\n this.executablePath = resolved.executablePath;\n this.pathDirs = resolved.pathDirs;\n }\n this.envOverride = env;\n this.configOverrides = configOverrides;\n }\n\n async *run(args: CodexExecArgs): AsyncGenerator<string> {\n const commandArgs: string[] = [\"exec\", \"--experimental-json\"];\n\n if (this.configOverrides) {\n for (const override of serializeConfigOverrides(this.configOverrides)) {\n commandArgs.push(\"--config\", override);\n }\n }\n\n if (args.baseUrl) {\n commandArgs.push(\n \"--config\",\n `openai_base_url=${toTomlValue(args.baseUrl, \"openai_base_url\")}`,\n );\n }\n\n if (args.model) {\n commandArgs.push(\"--model\", args.model);\n }\n\n if (args.sandboxMode) {\n commandArgs.push(\"--sandbox\", args.sandboxMode);\n }\n\n if (args.workingDirectory) {\n commandArgs.push(\"--cd\", args.workingDirectory);\n }\n\n if (args.additionalDirectories?.length) {\n for (const dir of args.additionalDirectories) {\n commandArgs.push(\"--add-dir\", dir);\n }\n }\n\n if (args.skipGitRepoCheck) {\n commandArgs.push(\"--skip-git-repo-check\");\n }\n\n if (args.outputSchemaFile) {\n commandArgs.push(\"--output-schema\", args.outputSchemaFile);\n }\n\n if (args.modelReasoningEffort) {\n commandArgs.push(\"--config\", `model_reasoning_effort=\"${args.modelReasoningEffort}\"`);\n }\n\n if (args.networkAccessEnabled !== undefined) {\n commandArgs.push(\n \"--config\",\n `sandbox_workspace_write.network_access=${args.networkAccessEnabled}`,\n );\n }\n\n if (args.webSearchMode) {\n commandArgs.push(\"--config\", `web_search=\"${args.webSearchMode}\"`);\n } else if (args.webSearchEnabled === true) {\n commandArgs.push(\"--config\", `web_search=\"live\"`);\n } else if (args.webSearchEnabled === false) {\n commandArgs.push(\"--config\", `web_search=\"disabled\"`);\n }\n\n if (args.approvalPolicy) {\n commandArgs.push(\"--config\", `approval_policy=\"${args.approvalPolicy}\"`);\n }\n\n if (args.threadId) {\n commandArgs.push(\"resume\", args.threadId);\n }\n\n if (args.images?.length) {\n for (const image of args.images) {\n commandArgs.push(\"--image\", image);\n }\n }\n\n const env: Record<string, string> = {};\n if (this.envOverride) {\n Object.assign(env, this.envOverride);\n } else {\n for (const [key, value] of Object.entries(process.env)) {\n if (value !== undefined) {\n env[key] = value;\n }\n }\n }\n if (!env[INTERNAL_ORIGINATOR_ENV]) {\n env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;\n }\n if (args.apiKey) {\n env.CODEX_API_KEY = args.apiKey;\n }\n if (this.pathDirs.length > 0) {\n prependPathDirs(env, this.pathDirs);\n }\n\n const child = spawn(this.executablePath, commandArgs, {\n env,\n signal: args.signal,\n });\n\n let spawnError: unknown | null = null;\n child.once(\"error\", (err) => (spawnError = err));\n\n if (!child.stdin) {\n child.kill();\n throw new Error(\"Child process has no stdin\");\n }\n child.stdin.write(args.input);\n child.stdin.end();\n\n if (!child.stdout) {\n child.kill();\n throw new Error(\"Child process has no stdout\");\n }\n const stderrChunks: Buffer[] = [];\n\n if (child.stderr) {\n child.stderr.on(\"data\", (data) => {\n stderrChunks.push(data);\n });\n }\n\n const exitPromise = new Promise<{ code: number | null; signal: NodeJS.Signals | null }>(\n (resolve) => {\n child.once(\"exit\", (code, signal) => {\n resolve({ code, signal });\n });\n },\n );\n\n const rl = readline.createInterface({\n input: child.stdout,\n crlfDelay: Infinity,\n });\n\n try {\n for await (const line of rl) {\n // `line` is a string (Node sets default encoding to utf8 for readline)\n yield line as string;\n }\n\n if (spawnError) throw spawnError;\n const { code, signal } = await exitPromise;\n if (code !== 0 || signal) {\n const stderrBuffer = Buffer.concat(stderrChunks);\n const detail = signal ? `signal ${signal}` : `code ${code ?? 1}`;\n throw new Error(`Codewith exec exited with ${detail}: ${stderrBuffer.toString(\"utf8\")}`);\n }\n } finally {\n rl.close();\n child.removeAllListeners();\n try {\n if (!child.killed) child.kill();\n } catch {\n // ignore\n }\n }\n }\n}\n\nfunction serializeConfigOverrides(configOverrides: CodexConfigObject): string[] {\n const overrides: string[] = [];\n flattenConfigOverrides(configOverrides, \"\", overrides);\n return overrides;\n}\n\nfunction flattenConfigOverrides(\n value: CodexConfigValue,\n prefix: string,\n overrides: string[],\n): void {\n if (!isPlainObject(value)) {\n if (prefix) {\n overrides.push(`${prefix}=${toTomlValue(value, prefix)}`);\n return;\n } else {\n throw new Error(\"Codewith config overrides must be a plain object\");\n }\n }\n\n const entries = Object.entries(value);\n if (!prefix && entries.length === 0) {\n return;\n }\n\n if (prefix && entries.length === 0) {\n overrides.push(`${prefix}={}`);\n return;\n }\n\n for (const [key, child] of entries) {\n if (!key) {\n throw new Error(\"Codewith config override keys must be non-empty strings\");\n }\n if (child === undefined) {\n continue;\n }\n const path = prefix ? `${prefix}.${key}` : key;\n if (isPlainObject(child)) {\n flattenConfigOverrides(child, path, overrides);\n } else {\n overrides.push(`${path}=${toTomlValue(child, path)}`);\n }\n }\n}\n\nfunction toTomlValue(value: CodexConfigValue, path: string): string {\n if (typeof value === \"string\") {\n return JSON.stringify(value);\n } else if (typeof value === \"number\") {\n if (!Number.isFinite(value)) {\n throw new Error(`Codewith config override at ${path} must be a finite number`);\n }\n return `${value}`;\n } else if (typeof value === \"boolean\") {\n return value ? \"true\" : \"false\";\n } else if (Array.isArray(value)) {\n const rendered = value.map((item, index) => toTomlValue(item, `${path}[${index}]`));\n return `[${rendered.join(\", \")}]`;\n } else if (isPlainObject(value)) {\n const parts: string[] = [];\n for (const [key, child] of Object.entries(value)) {\n if (!key) {\n throw new Error(\"Codewith config override keys must be non-empty strings\");\n }\n if (child === undefined) {\n continue;\n }\n parts.push(`${formatTomlKey(key)} = ${toTomlValue(child, `${path}.${key}`)}`);\n }\n return `{${parts.join(\", \")}}`;\n } else if (value === null) {\n throw new Error(`Codewith config override at ${path} cannot be null`);\n } else {\n const typeName = typeof value;\n throw new Error(`Unsupported Codewith config override value at ${path}: ${typeName}`);\n }\n}\n\nconst TOML_BARE_KEY = /^[A-Za-z0-9_-]+$/;\nfunction formatTomlKey(key: string): string {\n return TOML_BARE_KEY.test(key) ? key : JSON.stringify(key);\n}\n\nfunction isPlainObject(value: unknown): value is CodexConfigObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction findCodexPath(): CodexPathResolution {\n const { platform, arch } = process;\n\n let targetTriple = null;\n switch (platform) {\n case \"linux\":\n case \"android\":\n switch (arch) {\n case \"x64\":\n targetTriple = \"x86_64-unknown-linux-musl\";\n break;\n case \"arm64\":\n targetTriple = \"aarch64-unknown-linux-musl\";\n break;\n default:\n break;\n }\n break;\n case \"darwin\":\n switch (arch) {\n case \"x64\":\n targetTriple = \"x86_64-apple-darwin\";\n break;\n case \"arm64\":\n targetTriple = \"aarch64-apple-darwin\";\n break;\n default:\n break;\n }\n break;\n case \"win32\":\n switch (arch) {\n case \"x64\":\n targetTriple = \"x86_64-pc-windows-msvc\";\n break;\n case \"arm64\":\n targetTriple = \"aarch64-pc-windows-msvc\";\n break;\n default:\n break;\n }\n break;\n default:\n break;\n }\n\n if (!targetTriple) {\n throw new Error(`Unsupported platform: ${platform} (${arch})`);\n }\n\n const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];\n if (!platformPackage) {\n throw new Error(`Unsupported target triple: ${targetTriple}`);\n }\n\n let vendorRoot: string;\n try {\n const codexPackageJsonPath = moduleRequire.resolve(`${CODEX_NPM_NAME}/package.json`);\n const codexRequire = createRequire(codexPackageJsonPath);\n const platformPackageJsonPath = codexRequire.resolve(`${platformPackage}/package.json`);\n vendorRoot = path.join(path.dirname(platformPackageJsonPath), \"vendor\");\n } catch {\n throw new Error(\n `Unable to locate Codewith CLI binaries. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`,\n );\n }\n\n const codewithBinaryName = process.platform === \"win32\" ? \"codewith.exe\" : \"codewith\";\n const legacyCodexBinaryName = process.platform === \"win32\" ? \"codex.exe\" : \"codex\";\n const nativePackage = resolveNativePackage(\n vendorRoot,\n targetTriple,\n codewithBinaryName,\n legacyCodexBinaryName,\n );\n if (!nativePackage) {\n throw new Error(\n `Unable to locate Codewith CLI binaries for ${targetTriple}. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`,\n );\n }\n\n return nativePackage;\n}\n\nexport function resolveNativePackage(\n vendorRoot: string,\n targetTriple: string,\n codewithBinaryName: string,\n legacyCodexBinaryName = codewithBinaryName,\n): CodexPathResolution | null {\n const packageRoot = path.join(vendorRoot, targetTriple);\n const packagePathDirs = existingDirs(\n path.join(packageRoot, \"codewith-path\"),\n path.join(packageRoot, \"codex-path\"),\n );\n\n const packageBinaryPath = path.join(packageRoot, \"bin\", codewithBinaryName);\n if (isFile(packageBinaryPath) && isFile(path.join(packageRoot, \"codex-package.json\"))) {\n return {\n executablePath: packageBinaryPath,\n pathDirs: packagePathDirs,\n };\n }\n\n const legacyPackageBinaryPath = path.join(packageRoot, \"bin\", legacyCodexBinaryName);\n if (isFile(legacyPackageBinaryPath) && isFile(path.join(packageRoot, \"codex-package.json\"))) {\n return {\n executablePath: legacyPackageBinaryPath,\n pathDirs: packagePathDirs,\n };\n }\n\n const legacyBinaryPath = path.join(packageRoot, \"codex\", legacyCodexBinaryName);\n if (isFile(legacyBinaryPath)) {\n return {\n executablePath: legacyBinaryPath,\n pathDirs: existingDirs(path.join(packageRoot, \"path\")),\n };\n }\n\n return null;\n}\n\nfunction existingDirs(...dirs: string[]): string[] {\n return dirs.filter(isDirectory);\n}\n\nexport function prependPathDirs(\n env: Record<string, string>,\n pathDirs: string[],\n platform: NodeJS.Platform = process.platform,\n): void {\n const pathKey = pathEnvKey(env, platform);\n if (platform === \"win32\") {\n for (const key of Object.keys(env)) {\n if (key.toLowerCase() === \"path\" && key !== pathKey) {\n delete env[key];\n }\n }\n }\n\n const existingEntries = (env[pathKey] ?? \"\")\n .split(path.delimiter)\n .filter((entry) => entry.length > 0 && !pathDirs.includes(entry));\n env[pathKey] = [...pathDirs, ...existingEntries].join(path.delimiter);\n}\n\nfunction pathEnvKey(env: Record<string, string>, platform: NodeJS.Platform): string {\n if (platform !== \"win32\") {\n return \"PATH\";\n }\n\n const matchingKeys = Object.keys(env).filter((key) => key.toLowerCase() === \"path\");\n return matchingKeys.includes(\"Path\") ? \"Path\" : (matchingKeys.at(-1) ?? \"PATH\");\n}\n\nfunction isFile(filePath: string): boolean {\n try {\n return statSync(filePath).isFile();\n } catch {\n return false;\n }\n}\n\nfunction isDirectory(filePath: string): boolean {\n try {\n return statSync(filePath).isDirectory();\n } catch {\n return false;\n }\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { CodexExec } from \"./exec\";\nimport { Thread } from \"./thread\";\nimport { ThreadOptions } from \"./threadOptions\";\n\n/**\n * Codewith is the main class for interacting with the Codewith agent.\n *\n * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.\n */\nexport class Codewith {\n private exec: CodexExec;\n private options: CodexOptions;\n\n constructor(options: CodexOptions = {}) {\n const { codexPathOverride, env, config } = options;\n this.exec = new CodexExec(codexPathOverride, env, config);\n this.options = options;\n }\n\n /**\n * Starts a new conversation with an agent.\n * @returns A new thread instance.\n */\n startThread(options: ThreadOptions = {}): Thread {\n return new Thread(this.exec, this.options, options);\n }\n\n /**\n * Resumes a conversation with an agent based on the thread id.\n * Threads are persisted in ~/.codewith/sessions by default.\n *\n * @param id The id of the thread to resume.\n * @returns A new thread instance.\n */\n resumeThread(id: string, options: ThreadOptions = {}): Thread {\n return new Thread(this.exec, this.options, options, id);\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,QAAQ;AACf,OAAO,UAAU;AAOjB,eAAsB,uBAAuB,QAA4C;AACvF,MAAI,WAAW,QAAW;AACxB,WAAO,EAAE,SAAS,YAAY;AAAA,IAAC,EAAE;AAAA,EACnC;AAEA,MAAI,CAAC,aAAa,MAAM,GAAG;AACzB,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC5D;AAEA,QAAM,YAAY,MAAM,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,sBAAsB,CAAC;AACjF,Q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