@openai/codex-sdk 0.45.0-alpha.5 → 0.45.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/README.md CHANGED
@@ -50,6 +50,39 @@ for await (const event of events) {
50
50
  }
51
51
  ```
52
52
 
53
+ ### Structured output
54
+
55
+ The Codex agent can produce a JSON response that conforms to a specified schema. The schema can be provided for each turn as a plain JSON object.
56
+
57
+ ```typescript
58
+ const schema = {
59
+ type: "object",
60
+ properties: {
61
+ summary: { type: "string" },
62
+ status: { type: "string", enum: ["ok", "action_required"] },
63
+ },
64
+ required: ["summary", "status"],
65
+ additionalProperties: false,
66
+ } as const;
67
+
68
+ const turn = await thread.run("Summarize repository status", { outputSchema: schema });
69
+ console.log(turn.finalResponse);
70
+ ```
71
+
72
+ You can also create a JSON schema from a [Zod schema](https://github.com/colinhacks/zod) using the [`zod-to-json-schema`](https://www.npmjs.com/package/zod-to-json-schema) package and setting the `target` to `"openAi"`.
73
+
74
+ ```typescript
75
+ const schema = z.object({
76
+ summary: z.string(),
77
+ status: z.enum(["ok", "action_required"]),
78
+ });
79
+
80
+ const turn = await thread.run("Summarize repository status", {
81
+ outputSchema: zodToJsonSchema(schema, { target: "openAi" }),
82
+ });
83
+ console.log(turn.finalResponse);
84
+ ```
85
+
53
86
  ### Resuming an existing thread
54
87
 
55
88
  Threads are persisted in `~/.codex/sessions`. If you lose the in-memory `Thread` object, reconstruct it with `resumeThread()` and keep going.
@@ -70,4 +103,3 @@ const thread = codex.startThread({
70
103
  skipGitRepoCheck: true,
71
104
  });
72
105
  ```
73
-
package/dist/index.d.ts CHANGED
@@ -148,6 +148,11 @@ type ThreadErrorEvent = {
148
148
  /** Top-level JSONL events emitted by codex exec. */
149
149
  type ThreadEvent = ThreadStartedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | ItemStartedEvent | ItemUpdatedEvent | ItemCompletedEvent | ThreadErrorEvent;
150
150
 
151
+ type TurnOptions = {
152
+ /** JSON schema describing the expected agent output. */
153
+ outputSchema?: unknown;
154
+ };
155
+
151
156
  /** Completed turn. */
152
157
  type Turn = {
153
158
  items: ThreadItem[];
@@ -173,10 +178,10 @@ declare class Thread {
173
178
  /** Returns the ID of the thread. Populated after the first turn starts. */
174
179
  get id(): string | null;
175
180
  /** Provides the input to the agent and streams events as they are produced during the turn. */
176
- runStreamed(input: string): Promise<StreamedTurn>;
181
+ runStreamed(input: string, turnOptions?: TurnOptions): Promise<StreamedTurn>;
177
182
  private runStreamedInternal;
178
183
  /** Provides the input to the agent and returns the completed turn. */
179
- run(input: string): Promise<Turn>;
184
+ run(input: string, turnOptions?: TurnOptions): Promise<Turn>;
180
185
  }
181
186
 
182
187
  type CodexOptions = {
@@ -218,4 +223,4 @@ declare class Codex {
218
223
  resumeThread(id: string, options?: ThreadOptions): Thread;
219
224
  }
220
225
 
221
- export { type AgentMessageItem, type ApprovalMode, Codex, type CodexOptions, type CommandExecutionItem, type ErrorItem, type FileChangeItem, type Input, type ItemCompletedEvent, type ItemStartedEvent, type ItemUpdatedEvent, type McpToolCallItem, type ReasoningItem, type RunResult, type RunStreamedResult, type SandboxMode, Thread, type ThreadError, type ThreadErrorEvent, type ThreadEvent, type ThreadItem, type ThreadOptions, type ThreadStartedEvent, type TodoListItem, type TurnCompletedEvent, type TurnFailedEvent, type TurnStartedEvent, type Usage, type WebSearchItem };
226
+ export { type AgentMessageItem, type ApprovalMode, Codex, type CodexOptions, type CommandExecutionItem, type ErrorItem, type FileChangeItem, type Input, type ItemCompletedEvent, type ItemStartedEvent, type ItemUpdatedEvent, type McpToolCallItem, type ReasoningItem, type RunResult, type RunStreamedResult, type SandboxMode, Thread, type ThreadError, type ThreadErrorEvent, type ThreadEvent, type ThreadItem, type ThreadOptions, type ThreadStartedEvent, type TodoListItem, type TurnCompletedEvent, type TurnFailedEvent, type TurnOptions, type TurnStartedEvent, type Usage, type WebSearchItem };
package/dist/index.js CHANGED
@@ -1,3 +1,35 @@
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
+
1
33
  // src/thread.ts
2
34
  var Thread = class {
3
35
  _exec;
@@ -16,10 +48,11 @@ var Thread = class {
16
48
  this._threadOptions = threadOptions;
17
49
  }
18
50
  /** Provides the input to the agent and streams events as they are produced during the turn. */
19
- async runStreamed(input) {
20
- return { events: this.runStreamedInternal(input) };
51
+ async runStreamed(input, turnOptions = {}) {
52
+ return { events: this.runStreamedInternal(input, turnOptions) };
21
53
  }
22
- async *runStreamedInternal(input) {
54
+ async *runStreamedInternal(input, turnOptions = {}) {
55
+ const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);
23
56
  const options = this._threadOptions;
24
57
  const generator = this._exec.run({
25
58
  input,
@@ -29,24 +62,29 @@ var Thread = class {
29
62
  model: options?.model,
30
63
  sandboxMode: options?.sandboxMode,
31
64
  workingDirectory: options?.workingDirectory,
32
- skipGitRepoCheck: options?.skipGitRepoCheck
65
+ skipGitRepoCheck: options?.skipGitRepoCheck,
66
+ outputSchemaFile: schemaPath
33
67
  });
34
- for await (const item of generator) {
35
- let parsed;
36
- try {
37
- parsed = JSON.parse(item);
38
- } catch (error) {
39
- throw new Error(`Failed to parse item: ${item}`, { cause: error });
40
- }
41
- if (parsed.type === "thread.started") {
42
- this._id = parsed.thread_id;
68
+ try {
69
+ for await (const item of generator) {
70
+ let parsed;
71
+ try {
72
+ parsed = JSON.parse(item);
73
+ } catch (error) {
74
+ throw new Error(`Failed to parse item: ${item}`, { cause: error });
75
+ }
76
+ if (parsed.type === "thread.started") {
77
+ this._id = parsed.thread_id;
78
+ }
79
+ yield parsed;
43
80
  }
44
- yield parsed;
81
+ } finally {
82
+ await cleanup();
45
83
  }
46
84
  }
47
85
  /** Provides the input to the agent and returns the completed turn. */
48
- async run(input) {
49
- const generator = this.runStreamedInternal(input);
86
+ async run(input, turnOptions = {}) {
87
+ const generator = this.runStreamedInternal(input, turnOptions);
50
88
  const items = [];
51
89
  let finalResponse = "";
52
90
  let usage = null;
@@ -73,8 +111,8 @@ var Thread = class {
73
111
 
74
112
  // src/exec.ts
75
113
  import { spawn } from "child_process";
114
+ import path2 from "path";
76
115
  import readline from "readline";
77
- import path from "path";
78
116
  import { fileURLToPath } from "url";
79
117
  var CodexExec = class {
80
118
  executablePath;
@@ -95,6 +133,9 @@ var CodexExec = class {
95
133
  if (args.skipGitRepoCheck) {
96
134
  commandArgs.push("--skip-git-repo-check");
97
135
  }
136
+ if (args.outputSchemaFile) {
137
+ commandArgs.push("--output-schema", args.outputSchemaFile);
138
+ }
98
139
  if (args.threadId) {
99
140
  commandArgs.push("resume", args.threadId);
100
141
  }
@@ -161,7 +202,7 @@ var CodexExec = class {
161
202
  }
162
203
  };
163
204
  var scriptFileName = fileURLToPath(import.meta.url);
164
- var scriptDirName = path.dirname(scriptFileName);
205
+ var scriptDirName = path2.dirname(scriptFileName);
165
206
  function findCodexPath() {
166
207
  const { platform, arch } = process;
167
208
  let targetTriple = null;
@@ -209,10 +250,10 @@ function findCodexPath() {
209
250
  if (!targetTriple) {
210
251
  throw new Error(`Unsupported platform: ${platform} (${arch})`);
211
252
  }
212
- const vendorRoot = path.join(scriptDirName, "..", "vendor");
213
- const archRoot = path.join(vendorRoot, targetTriple);
253
+ const vendorRoot = path2.join(scriptDirName, "..", "vendor");
254
+ const archRoot = path2.join(vendorRoot, targetTriple);
214
255
  const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
215
- const binaryPath = path.join(archRoot, "codex", codexBinaryName);
256
+ const binaryPath = path2.join(archRoot, "codex", codexBinaryName);
216
257
  return binaryPath;
217
258
  }
218
259
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/thread.ts","../src/exec.ts","../src/codex.ts"],"sourcesContent":["import { CodexOptions } from \"./codexOptions\";\nimport { ThreadEvent, ThreadError, Usage } from \"./events\";\nimport { CodexExec } from \"./exec\";\nimport { ThreadItem } from \"./items\";\nimport { ThreadOptions } from \"./threadOptions\";\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 Input = string;\n\n/** Respesent 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: string): Promise<StreamedTurn> {\n return { events: this.runStreamedInternal(input) };\n }\n\n private async *runStreamedInternal(input: string): AsyncGenerator<ThreadEvent> {\n const options = this._threadOptions;\n const generator = this._exec.run({\n input,\n baseUrl: this._options.baseUrl,\n apiKey: this._options.apiKey,\n threadId: this._id,\n model: options?.model,\n sandboxMode: options?.sandboxMode,\n workingDirectory: options?.workingDirectory,\n skipGitRepoCheck: options?.skipGitRepoCheck,\n });\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 }\n\n /** Provides the input to the agent and returns the completed turn. */\n async run(input: string): Promise<Turn> {\n const generator = this.runStreamedInternal(input);\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","import { spawn } from \"node:child_process\";\n\nimport readline from \"node:readline\";\n\nimport { SandboxMode } from \"./threadOptions\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport type CodexExecArgs = {\n input: string;\n\n baseUrl?: string;\n apiKey?: string;\n threadId?: string | null;\n // --model\n model?: string;\n // --sandbox\n sandboxMode?: SandboxMode;\n // --cd\n workingDirectory?: string;\n // --skip-git-repo-check\n skipGitRepoCheck?: boolean;\n};\n\nexport class CodexExec {\n private executablePath: string;\n constructor(executablePath: string | null = null) {\n this.executablePath = executablePath || findCodexPath();\n }\n\n async *run(args: CodexExecArgs): AsyncGenerator<string> {\n const commandArgs: string[] = [\"exec\", \"--experimental-json\"];\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.skipGitRepoCheck) {\n commandArgs.push(\"--skip-git-repo-check\");\n }\n\n if (args.threadId) {\n commandArgs.push(\"resume\", args.threadId);\n }\n\n const env = {\n ...process.env,\n };\n if (args.baseUrl) {\n env.OPENAI_BASE_URL = args.baseUrl;\n }\n if (args.apiKey) {\n env.CODEX_API_KEY = args.apiKey;\n }\n\n const child = spawn(this.executablePath, commandArgs, {\n env,\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 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 const exitCode = new Promise((resolve, reject) => {\n child.once(\"exit\", (code) => {\n if (code === 0) {\n resolve(code);\n } else {\n const stderrBuffer = Buffer.concat(stderrChunks);\n reject(\n new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString(\"utf8\")}`),\n );\n }\n });\n });\n\n if (spawnError) throw spawnError;\n await exitCode;\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\nconst scriptFileName = fileURLToPath(import.meta.url);\nconst scriptDirName = path.dirname(scriptFileName);\n\nfunction findCodexPath() {\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 vendorRoot = path.join(scriptDirName, \"..\", \"vendor\");\n const archRoot = path.join(vendorRoot, targetTriple);\n const codexBinaryName = process.platform === \"win32\" ? \"codex.exe\" : \"codex\";\n const binaryPath = path.join(archRoot, \"codex\", codexBinaryName);\n\n return binaryPath;\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { CodexExec } from \"./exec\";\nimport { Thread } from \"./thread\";\nimport { ThreadOptions } from \"./threadOptions\";\n\n/**\n * Codex is the main class for interacting with the Codex agent.\n *\n * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.\n */\nexport class Codex {\n private exec: CodexExec;\n private options: CodexOptions;\n\n constructor(options: CodexOptions = {}) {\n this.exec = new CodexExec(options.codexPathOverride);\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 ~/.codex/sessions.\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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S,SAAS,EAAE;AAAA,EACxD;AACF;","names":[]}
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 }\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 Input = string;\n\n/** Respesent 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: string, turnOptions: TurnOptions = {}): Promise<StreamedTurn> {\n return { events: this.runStreamedInternal(input, turnOptions) };\n }\n\n private async *runStreamedInternal(\n input: string,\n turnOptions: TurnOptions = {},\n ): AsyncGenerator<ThreadEvent> {\n const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);\n const options = this._threadOptions;\n const generator = this._exec.run({\n input,\n baseUrl: this._options.baseUrl,\n apiKey: this._options.apiKey,\n threadId: this._id,\n model: options?.model,\n sandboxMode: options?.sandboxMode,\n workingDirectory: options?.workingDirectory,\n skipGitRepoCheck: options?.skipGitRepoCheck,\n outputSchemaFile: schemaPath,\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: string, 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","import { spawn } from \"node:child_process\";\nimport path from \"node:path\";\nimport readline from \"node:readline\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { SandboxMode } from \"./threadOptions\";\n\nexport type CodexExecArgs = {\n input: string;\n\n baseUrl?: string;\n apiKey?: string;\n threadId?: string | null;\n // --model\n model?: string;\n // --sandbox\n sandboxMode?: SandboxMode;\n // --cd\n workingDirectory?: string;\n // --skip-git-repo-check\n skipGitRepoCheck?: boolean;\n // --output-schema\n outputSchemaFile?: string;\n};\n\nexport class CodexExec {\n private executablePath: string;\n constructor(executablePath: string | null = null) {\n this.executablePath = executablePath || findCodexPath();\n }\n\n async *run(args: CodexExecArgs): AsyncGenerator<string> {\n const commandArgs: string[] = [\"exec\", \"--experimental-json\"];\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.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.threadId) {\n commandArgs.push(\"resume\", args.threadId);\n }\n\n const env = {\n ...process.env,\n };\n if (args.baseUrl) {\n env.OPENAI_BASE_URL = args.baseUrl;\n }\n if (args.apiKey) {\n env.CODEX_API_KEY = args.apiKey;\n }\n\n const child = spawn(this.executablePath, commandArgs, {\n env,\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 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 const exitCode = new Promise((resolve, reject) => {\n child.once(\"exit\", (code) => {\n if (code === 0) {\n resolve(code);\n } else {\n const stderrBuffer = Buffer.concat(stderrChunks);\n reject(\n new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString(\"utf8\")}`),\n );\n }\n });\n });\n\n if (spawnError) throw spawnError;\n await exitCode;\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\nconst scriptFileName = fileURLToPath(import.meta.url);\nconst scriptDirName = path.dirname(scriptFileName);\n\nfunction findCodexPath() {\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 vendorRoot = path.join(scriptDirName, \"..\", \"vendor\");\n const archRoot = path.join(vendorRoot, targetTriple);\n const codexBinaryName = process.platform === \"win32\" ? \"codex.exe\" : \"codex\";\n const binaryPath = path.join(archRoot, \"codex\", codexBinaryName);\n\n return binaryPath;\n}\n","import { CodexOptions } from \"./codexOptions\";\nimport { CodexExec } from \"./exec\";\nimport { Thread } from \"./thread\";\nimport { ThreadOptions } from \"./threadOptions\";\n\n/**\n * Codex is the main class for interacting with the Codex agent.\n *\n * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.\n */\nexport class Codex {\n private exec: CodexExec;\n private options: CodexOptions;\n\n constructor(options: CodexOptions = {}) {\n this.exec = new CodexExec(options.codexPathOverride);\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 ~/.codex/sessions.\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,QAAM,aAAa,KAAK,KAAK,WAAW,aAAa;AACrD,QAAM,UAAU,YAAY;AAC1B,QAAI;AACF,YAAM,GAAG,GAAG,WAAW,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,IACzD,QACO;AAAA,IAEP;AAAA,EACF;AAEA,MAAI;AACF,UAAM,GAAG,UAAU,YAAY,KAAK,UAAU,MAAM,GAAG,MAAM;A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,cAAc;AACrE,QAAM,aAAaA,MAAK,KAAK,UAAU,SAAS,eAAe;AAE/D,SAAO;AACT;;;ACrLO,IAAM,QAAN,MAAY;AAAA,EACT;AAAA,EACA;AAAA,EAER,YAAY,UAAwB,CAAC,GAAG;AACtC,SAAK,OAAO,IAAI,UAAU,QAAQ,iBAAiB;AACnD,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAY,UAAyB,CAAC,GAAW;AAC/C,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,OAAO;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,aAAa,IAAY,UAAyB,CAAC,GAAW;AAC5D,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,SAAS,EAAE;AAAA,EACxD;AACF;","names":["path"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openai/codex-sdk",
3
- "version": "0.45.0-alpha.5",
3
+ "version": "0.45.0",
4
4
  "description": "TypeScript SDK for Codex APIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -58,6 +58,8 @@
58
58
  "ts-node": "^10.9.2",
59
59
  "tsup": "^8.5.0",
60
60
  "typescript": "^5.9.2",
61
- "typescript-eslint": "^8.45.0"
61
+ "typescript-eslint": "^8.45.0",
62
+ "zod": "^3.24.2",
63
+ "zod-to-json-schema": "^3.24.6"
62
64
  }
63
65
  }