@northflare/runner 0.0.17 → 0.0.19

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.
Files changed (107) hide show
  1. package/package.json +3 -3
  2. package/{lib/codex-sdk/tsup.config.ts → tsup.config.ts} +2 -2
  3. package/lib/codex-sdk/.prettierignore +0 -3
  4. package/lib/codex-sdk/.prettierrc +0 -5
  5. package/lib/codex-sdk/README.md +0 -133
  6. package/lib/codex-sdk/dist/index.d.ts +0 -260
  7. package/lib/codex-sdk/dist/index.js +0 -426
  8. package/lib/codex-sdk/dist/samples/basic_streaming.d.ts +0 -3
  9. package/lib/codex-sdk/dist/samples/basic_streaming.d.ts.map +0 -1
  10. package/lib/codex-sdk/dist/samples/basic_streaming.js +0 -81
  11. package/lib/codex-sdk/dist/samples/basic_streaming.js.map +0 -1
  12. package/lib/codex-sdk/dist/samples/helpers.d.ts +0 -2
  13. package/lib/codex-sdk/dist/samples/helpers.d.ts.map +0 -1
  14. package/lib/codex-sdk/dist/samples/helpers.js +0 -6
  15. package/lib/codex-sdk/dist/samples/helpers.js.map +0 -1
  16. package/lib/codex-sdk/dist/samples/structured_output.d.ts +0 -3
  17. package/lib/codex-sdk/dist/samples/structured_output.d.ts.map +0 -1
  18. package/lib/codex-sdk/dist/samples/structured_output.js +0 -17
  19. package/lib/codex-sdk/dist/samples/structured_output.js.map +0 -1
  20. package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts +0 -3
  21. package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts.map +0 -1
  22. package/lib/codex-sdk/dist/samples/structured_output_zod.js +0 -16
  23. package/lib/codex-sdk/dist/samples/structured_output_zod.js.map +0 -1
  24. package/lib/codex-sdk/dist/src/codex.d.ts +0 -27
  25. package/lib/codex-sdk/dist/src/codex.d.ts.map +0 -1
  26. package/lib/codex-sdk/dist/src/codex.js +0 -33
  27. package/lib/codex-sdk/dist/src/codex.js.map +0 -1
  28. package/lib/codex-sdk/dist/src/codexOptions.d.ts +0 -11
  29. package/lib/codex-sdk/dist/src/codexOptions.d.ts.map +0 -1
  30. package/lib/codex-sdk/dist/src/codexOptions.js +0 -2
  31. package/lib/codex-sdk/dist/src/codexOptions.js.map +0 -1
  32. package/lib/codex-sdk/dist/src/events.d.ts +0 -60
  33. package/lib/codex-sdk/dist/src/events.d.ts.map +0 -1
  34. package/lib/codex-sdk/dist/src/events.js +0 -3
  35. package/lib/codex-sdk/dist/src/events.js.map +0 -1
  36. package/lib/codex-sdk/dist/src/exec.d.ts +0 -27
  37. package/lib/codex-sdk/dist/src/exec.d.ts.map +0 -1
  38. package/lib/codex-sdk/dist/src/exec.js +0 -264
  39. package/lib/codex-sdk/dist/src/exec.js.map +0 -1
  40. package/lib/codex-sdk/dist/src/index.d.ts +0 -9
  41. package/lib/codex-sdk/dist/src/index.d.ts.map +0 -1
  42. package/lib/codex-sdk/dist/src/index.js +0 -3
  43. package/lib/codex-sdk/dist/src/index.js.map +0 -1
  44. package/lib/codex-sdk/dist/src/items.d.ts +0 -103
  45. package/lib/codex-sdk/dist/src/items.d.ts.map +0 -1
  46. package/lib/codex-sdk/dist/src/items.js +0 -3
  47. package/lib/codex-sdk/dist/src/items.js.map +0 -1
  48. package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts +0 -6
  49. package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts.map +0 -1
  50. package/lib/codex-sdk/dist/src/outputSchemaFile.js +0 -33
  51. package/lib/codex-sdk/dist/src/outputSchemaFile.js.map +0 -1
  52. package/lib/codex-sdk/dist/src/thread.d.ts +0 -41
  53. package/lib/codex-sdk/dist/src/thread.d.ts.map +0 -1
  54. package/lib/codex-sdk/dist/src/thread.js +0 -109
  55. package/lib/codex-sdk/dist/src/thread.js.map +0 -1
  56. package/lib/codex-sdk/dist/src/threadOptions.d.ts +0 -16
  57. package/lib/codex-sdk/dist/src/threadOptions.d.ts.map +0 -1
  58. package/lib/codex-sdk/dist/src/threadOptions.js +0 -2
  59. package/lib/codex-sdk/dist/src/threadOptions.js.map +0 -1
  60. package/lib/codex-sdk/dist/src/turnOptions.d.ts +0 -7
  61. package/lib/codex-sdk/dist/src/turnOptions.d.ts.map +0 -1
  62. package/lib/codex-sdk/dist/src/turnOptions.js +0 -2
  63. package/lib/codex-sdk/dist/src/turnOptions.js.map +0 -1
  64. package/lib/codex-sdk/dist/tests/abort.test.d.ts +0 -2
  65. package/lib/codex-sdk/dist/tests/abort.test.d.ts.map +0 -1
  66. package/lib/codex-sdk/dist/tests/abort.test.js +0 -130
  67. package/lib/codex-sdk/dist/tests/abort.test.js.map +0 -1
  68. package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts +0 -6
  69. package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts.map +0 -1
  70. package/lib/codex-sdk/dist/tests/codexExecSpy.js +0 -28
  71. package/lib/codex-sdk/dist/tests/codexExecSpy.js.map +0 -1
  72. package/lib/codex-sdk/dist/tests/responsesProxy.d.ts +0 -56
  73. package/lib/codex-sdk/dist/tests/responsesProxy.d.ts.map +0 -1
  74. package/lib/codex-sdk/dist/tests/responsesProxy.js +0 -155
  75. package/lib/codex-sdk/dist/tests/responsesProxy.js.map +0 -1
  76. package/lib/codex-sdk/dist/tests/run.test.d.ts +0 -2
  77. package/lib/codex-sdk/dist/tests/run.test.d.ts.map +0 -1
  78. package/lib/codex-sdk/dist/tests/run.test.js +0 -524
  79. package/lib/codex-sdk/dist/tests/run.test.js.map +0 -1
  80. package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts +0 -2
  81. package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts.map +0 -1
  82. package/lib/codex-sdk/dist/tests/runStreamed.test.js +0 -153
  83. package/lib/codex-sdk/dist/tests/runStreamed.test.js.map +0 -1
  84. package/lib/codex-sdk/dist/tsup.config.d.ts +0 -3
  85. package/lib/codex-sdk/dist/tsup.config.js +0 -12
  86. package/lib/codex-sdk/eslint.config.js +0 -21
  87. package/lib/codex-sdk/jest.config.cjs +0 -31
  88. package/lib/codex-sdk/package.json +0 -65
  89. package/lib/codex-sdk/samples/basic_streaming.ts +0 -90
  90. package/lib/codex-sdk/samples/helpers.ts +0 -8
  91. package/lib/codex-sdk/samples/structured_output.ts +0 -22
  92. package/lib/codex-sdk/samples/structured_output_zod.ts +0 -19
  93. package/lib/codex-sdk/src/codex.ts +0 -38
  94. package/lib/codex-sdk/src/codexOptions.ts +0 -10
  95. package/lib/codex-sdk/src/events.ts +0 -80
  96. package/lib/codex-sdk/src/exec.ts +0 -336
  97. package/lib/codex-sdk/src/index.ts +0 -39
  98. package/lib/codex-sdk/src/items.ts +0 -127
  99. package/lib/codex-sdk/src/outputSchemaFile.ts +0 -40
  100. package/lib/codex-sdk/src/thread.ts +0 -155
  101. package/lib/codex-sdk/src/threadOptions.ts +0 -18
  102. package/lib/codex-sdk/src/turnOptions.ts +0 -6
  103. package/lib/codex-sdk/tests/abort.test.ts +0 -165
  104. package/lib/codex-sdk/tests/codexExecSpy.ts +0 -37
  105. package/lib/codex-sdk/tests/responsesProxy.ts +0 -225
  106. package/lib/codex-sdk/tests/run.test.ts +0 -687
  107. package/lib/codex-sdk/tests/runStreamed.test.ts +0 -211
@@ -1,426 +0,0 @@
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
- webSearchEnabled: options?.webSearchEnabled,
73
- approvalPolicy: options?.approvalPolicy,
74
- additionalDirectories: options?.additionalDirectories,
75
- configOverrides: options?.configOverrides
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 { existsSync } from "fs";
139
- import path2 from "path";
140
- import readline from "readline";
141
- import { fileURLToPath } from "url";
142
- import { createRequire } from "module";
143
- var INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
144
- var TYPESCRIPT_SDK_ORIGINATOR = "codex_sdk_ts";
145
- var isDebugEnabled = process.env["DEBUG"] === "true";
146
- var CodexExec = class {
147
- executablePath;
148
- envOverride;
149
- constructor(executablePath = null, env) {
150
- this.executablePath = executablePath || findCodexPath();
151
- this.envOverride = env;
152
- }
153
- async *run(args) {
154
- const commandArgs = ["exec", "--experimental-json"];
155
- if (args.model) {
156
- commandArgs.push("--model", args.model);
157
- }
158
- if (args.sandboxMode) {
159
- commandArgs.push("--sandbox", args.sandboxMode);
160
- }
161
- if (args.workingDirectory) {
162
- commandArgs.push("--cd", args.workingDirectory);
163
- }
164
- if (args.additionalDirectories?.length) {
165
- for (const dir of args.additionalDirectories) {
166
- commandArgs.push("--add-dir", dir);
167
- }
168
- }
169
- if (args.skipGitRepoCheck) {
170
- commandArgs.push("--skip-git-repo-check");
171
- }
172
- if (args.outputSchemaFile) {
173
- commandArgs.push("--output-schema", args.outputSchemaFile);
174
- }
175
- if (args.modelReasoningEffort) {
176
- commandArgs.push("--config", `model_reasoning_effort="${args.modelReasoningEffort}"`);
177
- }
178
- if (args.networkAccessEnabled !== void 0) {
179
- commandArgs.push(
180
- "--config",
181
- `sandbox_workspace_write.network_access=${args.networkAccessEnabled}`
182
- );
183
- }
184
- if (args.webSearchEnabled !== void 0) {
185
- commandArgs.push("--config", `features.web_search_request=${args.webSearchEnabled}`);
186
- }
187
- if (args.approvalPolicy) {
188
- commandArgs.push("--config", `approval_policy="${args.approvalPolicy}"`);
189
- }
190
- if (args.configOverrides) {
191
- for (const [key, value] of Object.entries(args.configOverrides)) {
192
- const formatted = formatConfigValue(value);
193
- commandArgs.push("--config", `${key}=${formatted}`);
194
- }
195
- }
196
- if (args.images?.length) {
197
- for (const image of args.images) {
198
- commandArgs.push("--image", image);
199
- }
200
- }
201
- if (args.threadId) {
202
- commandArgs.push("resume", args.threadId);
203
- }
204
- if (isDebugEnabled) {
205
- console.log("[CodexExec] Executable path:", this.executablePath);
206
- console.log("[CodexExec] Command arguments:", commandArgs);
207
- }
208
- const env = {};
209
- if (this.envOverride) {
210
- Object.assign(env, this.envOverride);
211
- } else {
212
- for (const [key, value] of Object.entries(process.env)) {
213
- if (value !== void 0) {
214
- env[key] = value;
215
- }
216
- }
217
- }
218
- if (!env[INTERNAL_ORIGINATOR_ENV]) {
219
- env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;
220
- }
221
- if (args.baseUrl) {
222
- env.OPENAI_BASE_URL = args.baseUrl;
223
- }
224
- if (args.apiKey) {
225
- env.CODEX_API_KEY = args.apiKey;
226
- }
227
- const child = spawn(this.executablePath, commandArgs, {
228
- env,
229
- signal: args.signal
230
- });
231
- let spawnError = null;
232
- child.once("error", (err) => spawnError = err);
233
- if (!child.stdin) {
234
- child.kill();
235
- throw new Error("Child process has no stdin");
236
- }
237
- child.stdin.write(args.input);
238
- child.stdin.end();
239
- if (!child.stdout) {
240
- child.kill();
241
- throw new Error("Child process has no stdout");
242
- }
243
- const stderrChunks = [];
244
- if (child.stderr) {
245
- child.stderr.on("data", (data) => {
246
- stderrChunks.push(data);
247
- });
248
- }
249
- const rl = readline.createInterface({
250
- input: child.stdout,
251
- crlfDelay: Infinity
252
- });
253
- try {
254
- for await (const line of rl) {
255
- yield line;
256
- }
257
- const exitCode = new Promise((resolve, reject) => {
258
- child.once("exit", (code) => {
259
- if (code === 0) {
260
- resolve(code);
261
- } else {
262
- const stderrBuffer = Buffer.concat(stderrChunks);
263
- reject(
264
- new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString("utf8")}`)
265
- );
266
- }
267
- });
268
- });
269
- if (spawnError) throw spawnError;
270
- await exitCode;
271
- } finally {
272
- rl.close();
273
- child.removeAllListeners();
274
- try {
275
- if (!child.killed) child.kill();
276
- } catch {
277
- }
278
- }
279
- }
280
- };
281
- var scriptFileName = fileURLToPath(import.meta.url);
282
- var scriptDirName = path2.dirname(scriptFileName);
283
- var require2 = createRequire(import.meta.url);
284
- function findCodexPath() {
285
- const { platform, arch } = process;
286
- let targetTriple = null;
287
- switch (platform) {
288
- case "linux":
289
- case "android":
290
- switch (arch) {
291
- case "x64":
292
- targetTriple = "x86_64-unknown-linux-musl";
293
- break;
294
- case "arm64":
295
- targetTriple = "aarch64-unknown-linux-musl";
296
- break;
297
- default:
298
- break;
299
- }
300
- break;
301
- case "darwin":
302
- switch (arch) {
303
- case "x64":
304
- targetTriple = "x86_64-apple-darwin";
305
- break;
306
- case "arm64":
307
- targetTriple = "aarch64-apple-darwin";
308
- break;
309
- default:
310
- break;
311
- }
312
- break;
313
- case "win32":
314
- switch (arch) {
315
- case "x64":
316
- targetTriple = "x86_64-pc-windows-msvc";
317
- break;
318
- case "arm64":
319
- targetTriple = "aarch64-pc-windows-msvc";
320
- break;
321
- default:
322
- break;
323
- }
324
- break;
325
- default:
326
- break;
327
- }
328
- if (!targetTriple) {
329
- throw new Error(`Unsupported platform: ${platform} (${arch})`);
330
- }
331
- const vendorResolution = resolveUpstreamVendorRoot();
332
- let vendorRoot;
333
- if (vendorResolution.path) {
334
- vendorRoot = vendorResolution.path;
335
- } else {
336
- vendorRoot = path2.join(scriptDirName, "..", "vendor");
337
- const reason = vendorResolution.reason ? `: ${vendorResolution.reason}` : "";
338
- console.warn(
339
- `[Codex SDK] Failed to resolve upstream vendor package${reason}, falling back to local vendor directory`
340
- );
341
- }
342
- const archRoot = path2.join(vendorRoot, targetTriple);
343
- const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
344
- const binaryPath = path2.join(archRoot, "codex", codexBinaryName);
345
- return binaryPath;
346
- }
347
- function resolveUpstreamVendorRoot() {
348
- let searchPaths = null;
349
- try {
350
- searchPaths = require2.resolve.paths("@openai/codex-sdk");
351
- } catch (error) {
352
- return { path: null, reason: error?.message || String(error) };
353
- }
354
- if (!searchPaths?.length) {
355
- return { path: null, reason: "no module search paths returned" };
356
- }
357
- let locatedPackageRoot = null;
358
- for (const basePath of searchPaths) {
359
- if (!basePath) continue;
360
- const packageRoot = path2.join(basePath, "@openai/codex-sdk");
361
- const packageJsonPath = path2.join(packageRoot, "package.json");
362
- if (!existsSync(packageJsonPath)) {
363
- continue;
364
- }
365
- locatedPackageRoot = packageRoot;
366
- const vendorPath = path2.join(packageRoot, "vendor");
367
- if (existsSync(vendorPath)) {
368
- return { path: vendorPath };
369
- }
370
- }
371
- if (locatedPackageRoot) {
372
- return { path: null, reason: `vendor directory missing in ${locatedPackageRoot}` };
373
- }
374
- return {
375
- path: null,
376
- reason: `@openai/codex-sdk not found in node_modules search paths (${searchPaths.join(", ")})`
377
- };
378
- }
379
- function formatConfigValue(value) {
380
- if (typeof value === "string") {
381
- return JSON.stringify(value);
382
- }
383
- if (typeof value === "number" || typeof value === "boolean") {
384
- return String(value);
385
- }
386
- if (value === null || value === void 0) {
387
- return "null";
388
- }
389
- try {
390
- return JSON.stringify(value);
391
- } catch {
392
- return JSON.stringify(String(value));
393
- }
394
- }
395
-
396
- // src/codex.ts
397
- var Codex = class {
398
- exec;
399
- options;
400
- constructor(options = {}) {
401
- this.exec = new CodexExec(options.codexPathOverride, options.env);
402
- this.options = options;
403
- }
404
- /**
405
- * Starts a new conversation with an agent.
406
- * @returns A new thread instance.
407
- */
408
- startThread(options = {}) {
409
- return new Thread(this.exec, this.options, options);
410
- }
411
- /**
412
- * Resumes a conversation with an agent based on the thread id.
413
- * Threads are persisted in ~/.codex/sessions.
414
- *
415
- * @param id The id of the thread to resume.
416
- * @returns A new thread instance.
417
- */
418
- resumeThread(id, options = {}) {
419
- return new Thread(this.exec, this.options, options, id);
420
- }
421
- };
422
- export {
423
- Codex,
424
- Thread
425
- };
426
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env -S NODE_NO_WARNINGS=1 pnpm ts-node-esm --files
2
- export {};
3
- //# sourceMappingURL=basic_streaming.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basic_streaming.d.ts","sourceRoot":"","sources":["../../samples/basic_streaming.ts"],"names":[],"mappings":""}
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env -S NODE_NO_WARNINGS=1 pnpm ts-node-esm --files
2
- import { createInterface } from "node:readline/promises";
3
- import { stdin as input, stdout as output } from "node:process";
4
- import { Codex } from "@openai/codex-sdk";
5
- import { codexPathOverride } from "./helpers.ts";
6
- const codex = new Codex({ codexPathOverride: codexPathOverride() });
7
- const thread = codex.startThread();
8
- const rl = createInterface({ input, output });
9
- const handleItemCompleted = (item) => {
10
- switch (item.type) {
11
- case "agent_message":
12
- console.log(`Assistant: ${item.text}`);
13
- break;
14
- case "reasoning":
15
- console.log(`Reasoning: ${item.text}`);
16
- break;
17
- case "command_execution": {
18
- const exitText = item.exit_code !== undefined ? ` Exit code ${item.exit_code}.` : "";
19
- console.log(`Command ${item.command} ${item.status}.${exitText}`);
20
- break;
21
- }
22
- case "file_change": {
23
- for (const change of item.changes) {
24
- console.log(`File ${change.kind} ${change.path}`);
25
- }
26
- break;
27
- }
28
- }
29
- };
30
- const handleItemUpdated = (item) => {
31
- switch (item.type) {
32
- case "todo_list": {
33
- console.log(`Todo:`);
34
- for (const todo of item.items) {
35
- console.log(`\t ${todo.completed ? "x" : " "} ${todo.text}`);
36
- }
37
- break;
38
- }
39
- }
40
- };
41
- const handleEvent = (event) => {
42
- switch (event.type) {
43
- case "item.completed":
44
- handleItemCompleted(event.item);
45
- break;
46
- case "item.updated":
47
- case "item.started":
48
- handleItemUpdated(event.item);
49
- break;
50
- case "turn.completed":
51
- console.log(`Used ${event.usage.input_tokens} input tokens, ${event.usage.cached_input_tokens} cached input tokens, ${event.usage.output_tokens} output tokens.`);
52
- break;
53
- case "turn.failed":
54
- console.error(`Turn failed: ${event.error.message}`);
55
- break;
56
- }
57
- };
58
- const main = async () => {
59
- try {
60
- while (true) {
61
- const inputText = await rl.question(">");
62
- const trimmed = inputText.trim();
63
- if (trimmed.length === 0) {
64
- continue;
65
- }
66
- const { events } = await thread.runStreamed(inputText);
67
- for await (const event of events) {
68
- handleEvent(event);
69
- }
70
- }
71
- }
72
- finally {
73
- rl.close();
74
- }
75
- };
76
- main().catch((err) => {
77
- const message = err instanceof Error ? err.message : String(err);
78
- console.error(`Unexpected error: ${message}`);
79
- process.exit(1);
80
- });
81
- //# sourceMappingURL=basic_streaming.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basic_streaming.js","sourceRoot":"","sources":["../../samples/basic_streaming.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CA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AAK,CAAC,EAAE,CAAC;gBACzB,SAAS;YACX,CAAC;YACD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YACvD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBACjC,WAAW,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;IACb,CAAC;AACH,CAAC,CAAC;AAEF,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,CAAC,KAAK,CAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;IAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function codexPathOverride(): string;
2
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../samples/helpers.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,WAKhC"}
@@ -1,6 +0,0 @@
1
- import path from "node:path";
2
- export function codexPathOverride() {
3
- return (process.env.CODEX_EXECUTABLE ??
4
- path.join(process.cwd(), "..", "..", "codex-rs", "target", "debug", "codex"));
5
- }
6
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../samples/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,iBAAiB;IAC/B,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,gBAAgB;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAC7E,CAAC;AACJ,CAAC"}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env -S NODE_NO_WARNINGS=1 pnpm ts-node-esm --files
2
- export {};
3
- //# sourceMappingURL=structured_output.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured_output.d.ts","sourceRoot":"","sources":["../../samples/structured_output.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env -S NODE_NO_WARNINGS=1 pnpm ts-node-esm --files
2
- import { Codex } from "@openai/codex-sdk";
3
- import { codexPathOverride } from "./helpers.ts";
4
- const codex = new Codex({ codexPathOverride: codexPathOverride() });
5
- const thread = codex.startThread();
6
- const schema = {
7
- type: "object",
8
- properties: {
9
- summary: { type: "string" },
10
- status: { type: "string", enum: ["ok", "action_required"] },
11
- },
12
- required: ["summary", "status"],
13
- additionalProperties: false,
14
- };
15
- const turn = await thread.run("Summarize repository status", { outputSchema: schema });
16
- console.log(turn.finalResponse);
17
- //# sourceMappingURL=structured_output.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured_output.js","sourceRoot":"","sources":["../../samples/structured_output.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;AAEpE,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;AAEnC,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,iBAAiB,CAAC,EAAE;KAC5D;IACD,QAAQ,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC/B,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,6BAA6B,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;AACvF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env -S NODE_NO_WARNINGS=1 pnpm ts-node-esm --files
2
- export {};
3
- //# sourceMappingURL=structured_output_zod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured_output_zod.d.ts","sourceRoot":"","sources":["../../samples/structured_output_zod.ts"],"names":[],"mappings":""}
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env -S NODE_NO_WARNINGS=1 pnpm ts-node-esm --files
2
- import { Codex } from "@openai/codex-sdk";
3
- import { codexPathOverride } from "./helpers.ts";
4
- import z from "zod";
5
- import zodToJsonSchema from "zod-to-json-schema";
6
- const codex = new Codex({ codexPathOverride: codexPathOverride() });
7
- const thread = codex.startThread();
8
- const schema = z.object({
9
- summary: z.string(),
10
- status: z.enum(["ok", "action_required"]),
11
- });
12
- const turn = await thread.run("Summarize repository status", {
13
- outputSchema: zodToJsonSchema(schema, { target: "openAi" }),
14
- });
15
- console.log(turn.finalResponse);
16
- //# sourceMappingURL=structured_output_zod.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"structured_output_zod.js","sourceRoot":"","sources":["../../samples/structured_output_zod.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAEjD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACpE,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;AAEnC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;CAC1C,CAAC,CAAC;AAEH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,6BAA6B,EAAE;IAC3D,YAAY,EAAE,eAAe,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;CAC5D,CAAC,CAAC;AACH,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC"}
@@ -1,27 +0,0 @@
1
- import { CodexOptions } from "./codexOptions";
2
- import { Thread } from "./thread";
3
- import { ThreadOptions } from "./threadOptions";
4
- /**
5
- * Codex is the main class for interacting with the Codex agent.
6
- *
7
- * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
8
- */
9
- export declare class Codex {
10
- private exec;
11
- private options;
12
- constructor(options?: CodexOptions);
13
- /**
14
- * Starts a new conversation with an agent.
15
- * @returns A new thread instance.
16
- */
17
- startThread(options?: ThreadOptions): Thread;
18
- /**
19
- * Resumes a conversation with an agent based on the thread id.
20
- * Threads are persisted in ~/.codex/sessions.
21
- *
22
- * @param id The id of the thread to resume.
23
- * @returns A new thread instance.
24
- */
25
- resumeThread(id: string, options?: ThreadOptions): Thread;
26
- }
27
- //# sourceMappingURL=codex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,OAAO,CAAe;gBAElB,OAAO,GAAE,YAAiB;IAKtC;;;OAGG;IACH,WAAW,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM;IAIhD;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM;CAG9D"}
@@ -1,33 +0,0 @@
1
- import { CodexExec } from "./exec";
2
- import { Thread } from "./thread";
3
- /**
4
- * Codex is the main class for interacting with the Codex agent.
5
- *
6
- * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
7
- */
8
- export class Codex {
9
- exec;
10
- options;
11
- constructor(options = {}) {
12
- this.exec = new CodexExec(options.codexPathOverride, options.env);
13
- this.options = options;
14
- }
15
- /**
16
- * Starts a new conversation with an agent.
17
- * @returns A new thread instance.
18
- */
19
- startThread(options = {}) {
20
- return new Thread(this.exec, this.options, options);
21
- }
22
- /**
23
- * Resumes a conversation with an agent based on the thread id.
24
- * Threads are persisted in ~/.codex/sessions.
25
- *
26
- * @param id The id of the thread to resume.
27
- * @returns A new thread instance.
28
- */
29
- resumeThread(id, options = {}) {
30
- return new Thread(this.exec, this.options, options, id);
31
- }
32
- }
33
- //# sourceMappingURL=codex.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/codex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC;;;;GAIG;AACH,MAAM,OAAO,KAAK;IACR,IAAI,CAAY;IAChB,OAAO,CAAe;IAE9B,YAAY,UAAwB,EAAE;QACpC,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAClE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,UAAyB,EAAE;QACrC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACH,YAAY,CAAC,EAAU,EAAE,UAAyB,EAAE;QAClD,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF"}