@openai/codex-sdk 0.43.0-alpha.8 → 0.44.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 +70 -0
- package/dist/index.d.ts +113 -47
- package/dist/index.js +78 -31
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
- package/vendor/aarch64-apple-darwin/codex/codex +0 -0
- package/vendor/aarch64-pc-windows-msvc/codex/codex.exe +0 -0
- package/vendor/aarch64-unknown-linux-musl/codex/codex +0 -0
- package/vendor/x86_64-apple-darwin/codex/codex +0 -0
- package/vendor/x86_64-pc-windows-msvc/codex/codex.exe +0 -0
- package/vendor/x86_64-unknown-linux-musl/codex/codex +0 -0
package/README.md
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
1
|
# Codex SDK
|
|
2
|
+
|
|
3
|
+
Bring the power of the best coding agent to your application.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @openai/codex-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Call `startThread()` and `run()` to start a thead with Codex.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { Codex } from "@openai/codex-sdk";
|
|
17
|
+
|
|
18
|
+
const codex = new Codex();
|
|
19
|
+
const thread = codex.startThread();
|
|
20
|
+
const result = await thread.run("Diagnose the test failure and propose a fix");
|
|
21
|
+
|
|
22
|
+
console.log(result);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You can call `run()` again to continue the same thread.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const result = await thread.run("Implement the fix");
|
|
29
|
+
|
|
30
|
+
console.log(result);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Streaming
|
|
34
|
+
|
|
35
|
+
The `await run()` method completes when a thread turn is complete and agent is prepared the final response.
|
|
36
|
+
|
|
37
|
+
You can thread items while they are being produced by calling `await runStreamed()`.
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const result = thread.runStreamed("Diagnose the test failure and propose a fix");
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Resuming a thread
|
|
44
|
+
|
|
45
|
+
If you don't have the original `Thread` instance to continue the thread, you can resume a thread by calling `resumeThread()` and providing the thread.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const threadId = "...";
|
|
49
|
+
const thread = codex.resumeThread(threadId);
|
|
50
|
+
const result = await thread.run("Implement the fix");
|
|
51
|
+
|
|
52
|
+
console.log(result);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Working directory
|
|
56
|
+
|
|
57
|
+
By default, Codex will run in the current working directory. You can change the working directory by passing the `workingDirectory` option to the when creating a thread.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const thread = codex.startThread({
|
|
61
|
+
workingDirectory: "/path/to/working/directory",
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To avoid unrecoverable errors, Codex requires the working directory to be a git repository. You can skip the git repository check by passing the `skipGitRepoCheck` option to the when creating a thread.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const thread = codex.startThread({
|
|
69
|
+
skipGitRepoCheck: true,
|
|
70
|
+
});
|
|
71
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,155 +1,221 @@
|
|
|
1
|
+
/** The status of a command execution. */
|
|
1
2
|
type CommandExecutionStatus = "in_progress" | "completed" | "failed";
|
|
3
|
+
/** A command executed by the agent. */
|
|
2
4
|
type CommandExecutionItem = {
|
|
3
5
|
id: string;
|
|
4
|
-
|
|
6
|
+
type: "command_execution";
|
|
7
|
+
/** The command line executed by the agent. */
|
|
5
8
|
command: string;
|
|
9
|
+
/** Aggregated stdout and stderr captured while the command was running. */
|
|
6
10
|
aggregated_output: string;
|
|
11
|
+
/** Set when the command exits; omitted while still running. */
|
|
7
12
|
exit_code?: number;
|
|
13
|
+
/** Current status of the command execution. */
|
|
8
14
|
status: CommandExecutionStatus;
|
|
9
15
|
};
|
|
16
|
+
/** Indicates the type of the file change. */
|
|
10
17
|
type PatchChangeKind = "add" | "delete" | "update";
|
|
18
|
+
/** A set of file changes by the agent. */
|
|
11
19
|
type FileUpdateChange = {
|
|
12
20
|
path: string;
|
|
13
21
|
kind: PatchChangeKind;
|
|
14
22
|
};
|
|
23
|
+
/** The status of a file change. */
|
|
15
24
|
type PatchApplyStatus = "completed" | "failed";
|
|
25
|
+
/** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
|
|
16
26
|
type FileChangeItem = {
|
|
17
27
|
id: string;
|
|
18
|
-
|
|
28
|
+
type: "file_change";
|
|
29
|
+
/** Individual file changes that comprise the patch. */
|
|
19
30
|
changes: FileUpdateChange[];
|
|
31
|
+
/** Whether the patch ultimately succeeded or failed. */
|
|
20
32
|
status: PatchApplyStatus;
|
|
21
33
|
};
|
|
34
|
+
/** The status of an MCP tool call. */
|
|
22
35
|
type McpToolCallStatus = "in_progress" | "completed" | "failed";
|
|
36
|
+
/**
|
|
37
|
+
* Represents a call to an MCP tool. The item starts when the invocation is dispatched
|
|
38
|
+
* and completes when the MCP server reports success or failure.
|
|
39
|
+
*/
|
|
23
40
|
type McpToolCallItem = {
|
|
24
41
|
id: string;
|
|
25
|
-
|
|
42
|
+
type: "mcp_tool_call";
|
|
43
|
+
/** Name of the MCP server handling the request. */
|
|
26
44
|
server: string;
|
|
45
|
+
/** The tool invoked on the MCP server. */
|
|
27
46
|
tool: string;
|
|
47
|
+
/** Current status of the tool invocation. */
|
|
28
48
|
status: McpToolCallStatus;
|
|
29
49
|
};
|
|
30
|
-
|
|
50
|
+
/** Response from the agent. Either natural-language text or JSON when structured output is requested. */
|
|
51
|
+
type AgentMessageItem = {
|
|
31
52
|
id: string;
|
|
32
|
-
|
|
53
|
+
type: "agent_message";
|
|
54
|
+
/** Either natural-language text or JSON when structured output is requested. */
|
|
33
55
|
text: string;
|
|
34
56
|
};
|
|
57
|
+
/** Agent's reasoning summary. */
|
|
35
58
|
type ReasoningItem = {
|
|
36
59
|
id: string;
|
|
37
|
-
|
|
60
|
+
type: "reasoning";
|
|
38
61
|
text: string;
|
|
39
62
|
};
|
|
63
|
+
/** Captures a web search request. Completes when results are returned to the agent. */
|
|
40
64
|
type WebSearchItem = {
|
|
41
65
|
id: string;
|
|
42
|
-
|
|
66
|
+
type: "web_search";
|
|
43
67
|
query: string;
|
|
44
68
|
};
|
|
69
|
+
/** Describes a non-fatal error surfaced as an item. */
|
|
45
70
|
type ErrorItem = {
|
|
46
71
|
id: string;
|
|
47
|
-
|
|
72
|
+
type: "error";
|
|
48
73
|
message: string;
|
|
49
74
|
};
|
|
75
|
+
/** An item in the agent's to-do list. */
|
|
50
76
|
type TodoItem = {
|
|
51
77
|
text: string;
|
|
52
78
|
completed: boolean;
|
|
53
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Tracks the agent's running to-do list. Starts when the plan is issued, updates as steps change,
|
|
82
|
+
* and completes when the turn ends.
|
|
83
|
+
*/
|
|
54
84
|
type TodoListItem = {
|
|
55
85
|
id: string;
|
|
56
|
-
|
|
86
|
+
type: "todo_list";
|
|
57
87
|
items: TodoItem[];
|
|
58
88
|
};
|
|
59
|
-
|
|
89
|
+
/** Canonical union of thread items and their type-specific payloads. */
|
|
90
|
+
type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | WebSearchItem | TodoListItem | ErrorItem;
|
|
60
91
|
|
|
92
|
+
/** Emitted when a new thread is started as the first event. */
|
|
61
93
|
type ThreadStartedEvent = {
|
|
62
94
|
type: "thread.started";
|
|
95
|
+
/** The identifier of the new thread. Can be used to resume the thread later. */
|
|
63
96
|
thread_id: string;
|
|
64
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* Emitted when a turn is started by sending a new prompt to the model.
|
|
100
|
+
* A turn encompasses all events that happen while the agent is processing the prompt.
|
|
101
|
+
*/
|
|
65
102
|
type TurnStartedEvent = {
|
|
66
103
|
type: "turn.started";
|
|
67
104
|
};
|
|
105
|
+
/** Describes the usage of tokens during a turn. */
|
|
68
106
|
type Usage = {
|
|
107
|
+
/** The number of input tokens used during the turn. */
|
|
69
108
|
input_tokens: number;
|
|
109
|
+
/** The number of cached input tokens used during the turn. */
|
|
70
110
|
cached_input_tokens: number;
|
|
111
|
+
/** The number of output tokens used during the turn. */
|
|
71
112
|
output_tokens: number;
|
|
72
113
|
};
|
|
114
|
+
/** Emitted when a turn is completed. Typically right after the assistant's response. */
|
|
73
115
|
type TurnCompletedEvent = {
|
|
74
116
|
type: "turn.completed";
|
|
75
117
|
usage: Usage;
|
|
76
118
|
};
|
|
119
|
+
/** Indicates that a turn failed with an error. */
|
|
77
120
|
type TurnFailedEvent = {
|
|
78
121
|
type: "turn.failed";
|
|
79
122
|
error: ThreadError;
|
|
80
123
|
};
|
|
124
|
+
/** Emitted when a new item is added to the thread. Typically the item is initially "in progress". */
|
|
81
125
|
type ItemStartedEvent = {
|
|
82
126
|
type: "item.started";
|
|
83
127
|
item: ThreadItem;
|
|
84
128
|
};
|
|
129
|
+
/** Emitted when an item is updated. */
|
|
85
130
|
type ItemUpdatedEvent = {
|
|
86
131
|
type: "item.updated";
|
|
87
132
|
item: ThreadItem;
|
|
88
133
|
};
|
|
134
|
+
/** Signals that an item has reached a terminal state—either success or failure. */
|
|
89
135
|
type ItemCompletedEvent = {
|
|
90
136
|
type: "item.completed";
|
|
91
137
|
item: ThreadItem;
|
|
92
138
|
};
|
|
139
|
+
/** Fatal error emitted by the stream. */
|
|
93
140
|
type ThreadError = {
|
|
94
141
|
message: string;
|
|
95
142
|
};
|
|
143
|
+
/** Represents an unrecoverable error emitted directly by the event stream. */
|
|
96
144
|
type ThreadErrorEvent = {
|
|
97
145
|
type: "error";
|
|
98
146
|
message: string;
|
|
99
147
|
};
|
|
148
|
+
/** Top-level JSONL events emitted by codex exec. */
|
|
100
149
|
type ThreadEvent = ThreadStartedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | ItemStartedEvent | ItemUpdatedEvent | ItemCompletedEvent | ThreadErrorEvent;
|
|
101
150
|
|
|
151
|
+
/** Completed turn. */
|
|
152
|
+
type Turn = {
|
|
153
|
+
items: ThreadItem[];
|
|
154
|
+
finalResponse: string;
|
|
155
|
+
};
|
|
156
|
+
/** Alias for `Turn` to describe the result of `run()`. */
|
|
157
|
+
type RunResult = Turn;
|
|
158
|
+
/** The result of the `runStreamed` method. */
|
|
159
|
+
type StreamedTurn = {
|
|
160
|
+
events: AsyncGenerator<ThreadEvent>;
|
|
161
|
+
};
|
|
162
|
+
/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */
|
|
163
|
+
type RunStreamedResult = StreamedTurn;
|
|
164
|
+
/** An input to send to the agent. */
|
|
165
|
+
type Input = string;
|
|
166
|
+
/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */
|
|
167
|
+
declare class Thread {
|
|
168
|
+
private _exec;
|
|
169
|
+
private _options;
|
|
170
|
+
private _id;
|
|
171
|
+
private _threadOptions;
|
|
172
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
173
|
+
get id(): string | null;
|
|
174
|
+
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
175
|
+
runStreamed(input: string): Promise<StreamedTurn>;
|
|
176
|
+
private runStreamedInternal;
|
|
177
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
178
|
+
run(input: string): Promise<Turn>;
|
|
179
|
+
}
|
|
180
|
+
|
|
102
181
|
type CodexOptions = {
|
|
103
182
|
codexPathOverride?: string;
|
|
104
183
|
baseUrl?: string;
|
|
105
184
|
apiKey?: string;
|
|
185
|
+
workingDirectory?: string;
|
|
106
186
|
};
|
|
107
187
|
|
|
108
188
|
type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
|
|
109
189
|
type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
|
|
110
|
-
type
|
|
111
|
-
model?: string;
|
|
112
|
-
sandboxMode?: SandboxMode;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
type CodexExecArgs = {
|
|
116
|
-
input: string;
|
|
117
|
-
baseUrl?: string;
|
|
118
|
-
apiKey?: string;
|
|
119
|
-
threadId?: string | null;
|
|
190
|
+
type ThreadOptions = {
|
|
120
191
|
model?: string;
|
|
121
192
|
sandboxMode?: SandboxMode;
|
|
193
|
+
workingDirectory?: string;
|
|
194
|
+
skipGitRepoCheck?: boolean;
|
|
122
195
|
};
|
|
123
|
-
declare class CodexExec {
|
|
124
|
-
private executablePath;
|
|
125
|
-
constructor(executablePath?: string | null);
|
|
126
|
-
run(args: CodexExecArgs): AsyncGenerator<string>;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
type RunResult = {
|
|
130
|
-
items: ThreadItem[];
|
|
131
|
-
finalResponse: string;
|
|
132
|
-
};
|
|
133
|
-
type RunStreamedResult = {
|
|
134
|
-
events: AsyncGenerator<ThreadEvent>;
|
|
135
|
-
};
|
|
136
|
-
type Input = string;
|
|
137
|
-
declare class Thread {
|
|
138
|
-
private exec;
|
|
139
|
-
private options;
|
|
140
|
-
id: string | null;
|
|
141
|
-
constructor(exec: CodexExec, options: CodexOptions, id?: string | null);
|
|
142
|
-
runStreamed(input: string, options?: TurnOptions): Promise<RunStreamedResult>;
|
|
143
|
-
private runStreamedInternal;
|
|
144
|
-
run(input: string, options?: TurnOptions): Promise<RunResult>;
|
|
145
|
-
}
|
|
146
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Codex is the main class for interacting with the Codex agent.
|
|
199
|
+
*
|
|
200
|
+
* Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
|
|
201
|
+
*/
|
|
147
202
|
declare class Codex {
|
|
148
203
|
private exec;
|
|
149
204
|
private options;
|
|
150
|
-
constructor(options
|
|
151
|
-
|
|
152
|
-
|
|
205
|
+
constructor(options?: CodexOptions);
|
|
206
|
+
/**
|
|
207
|
+
* Starts a new conversation with an agent.
|
|
208
|
+
* @returns A new thread instance.
|
|
209
|
+
*/
|
|
210
|
+
startThread(options?: ThreadOptions): Thread;
|
|
211
|
+
/**
|
|
212
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
213
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
214
|
+
*
|
|
215
|
+
* @param id The id of the thread to resume.
|
|
216
|
+
* @returns A new thread instance.
|
|
217
|
+
*/
|
|
218
|
+
resumeThread(id: string, options?: ThreadOptions): Thread;
|
|
153
219
|
}
|
|
154
220
|
|
|
155
|
-
export { type
|
|
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, type ThreadOptions as TheadOptions, Thread, type ThreadError, type ThreadErrorEvent, type ThreadEvent, type ThreadItem, type ThreadStartedEvent, type TodoListItem, type TurnCompletedEvent, type TurnFailedEvent, type TurnStartedEvent, type WebSearchItem };
|
package/dist/index.js
CHANGED
|
@@ -1,40 +1,57 @@
|
|
|
1
1
|
// src/thread.ts
|
|
2
2
|
var Thread = class {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.
|
|
3
|
+
_exec;
|
|
4
|
+
_options;
|
|
5
|
+
_id;
|
|
6
|
+
_threadOptions;
|
|
7
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
8
|
+
get id() {
|
|
9
|
+
return this._id;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/* @internal */
|
|
12
|
+
constructor(exec, options, threadOptions, id = null) {
|
|
13
|
+
this._exec = exec;
|
|
14
|
+
this._options = options;
|
|
15
|
+
this._id = id;
|
|
16
|
+
this._threadOptions = threadOptions;
|
|
13
17
|
}
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
/** 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) };
|
|
21
|
+
}
|
|
22
|
+
async *runStreamedInternal(input) {
|
|
23
|
+
const options = this._threadOptions;
|
|
24
|
+
const generator = this._exec.run({
|
|
16
25
|
input,
|
|
17
|
-
baseUrl: this.
|
|
18
|
-
apiKey: this.
|
|
19
|
-
threadId: this.
|
|
26
|
+
baseUrl: this._options.baseUrl,
|
|
27
|
+
apiKey: this._options.apiKey,
|
|
28
|
+
threadId: this._id,
|
|
20
29
|
model: options?.model,
|
|
21
|
-
sandboxMode: options?.sandboxMode
|
|
30
|
+
sandboxMode: options?.sandboxMode,
|
|
31
|
+
workingDirectory: options?.workingDirectory,
|
|
32
|
+
skipGitRepoCheck: options?.skipGitRepoCheck
|
|
22
33
|
});
|
|
23
34
|
for await (const item of generator) {
|
|
24
|
-
|
|
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
|
+
}
|
|
25
41
|
if (parsed.type === "thread.started") {
|
|
26
|
-
this.
|
|
42
|
+
this._id = parsed.thread_id;
|
|
27
43
|
}
|
|
28
44
|
yield parsed;
|
|
29
45
|
}
|
|
30
46
|
}
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
48
|
+
async run(input) {
|
|
49
|
+
const generator = this.runStreamedInternal(input);
|
|
33
50
|
const items = [];
|
|
34
51
|
let finalResponse = "";
|
|
35
52
|
for await (const event of generator) {
|
|
36
53
|
if (event.type === "item.completed") {
|
|
37
|
-
if (event.item.
|
|
54
|
+
if (event.item.type === "agent_message") {
|
|
38
55
|
finalResponse = event.item.text;
|
|
39
56
|
}
|
|
40
57
|
items.push(event.item);
|
|
@@ -62,10 +79,14 @@ var CodexExec = class {
|
|
|
62
79
|
if (args.sandboxMode) {
|
|
63
80
|
commandArgs.push("--sandbox", args.sandboxMode);
|
|
64
81
|
}
|
|
82
|
+
if (args.workingDirectory) {
|
|
83
|
+
commandArgs.push("--cd", args.workingDirectory);
|
|
84
|
+
}
|
|
85
|
+
if (args.skipGitRepoCheck) {
|
|
86
|
+
commandArgs.push("--skip-git-repo-check");
|
|
87
|
+
}
|
|
65
88
|
if (args.threadId) {
|
|
66
|
-
commandArgs.push("resume", args.threadId
|
|
67
|
-
} else {
|
|
68
|
-
commandArgs.push(args.input);
|
|
89
|
+
commandArgs.push("resume", args.threadId);
|
|
69
90
|
}
|
|
70
91
|
const env = {
|
|
71
92
|
...process.env
|
|
@@ -74,17 +95,29 @@ var CodexExec = class {
|
|
|
74
95
|
env.OPENAI_BASE_URL = args.baseUrl;
|
|
75
96
|
}
|
|
76
97
|
if (args.apiKey) {
|
|
77
|
-
env.
|
|
98
|
+
env.CODEX_API_KEY = args.apiKey;
|
|
78
99
|
}
|
|
79
100
|
const child = spawn(this.executablePath, commandArgs, {
|
|
80
101
|
env
|
|
81
102
|
});
|
|
82
103
|
let spawnError = null;
|
|
83
104
|
child.once("error", (err) => spawnError = err);
|
|
105
|
+
if (!child.stdin) {
|
|
106
|
+
child.kill();
|
|
107
|
+
throw new Error("Child process has no stdin");
|
|
108
|
+
}
|
|
109
|
+
child.stdin.write(args.input);
|
|
110
|
+
child.stdin.end();
|
|
84
111
|
if (!child.stdout) {
|
|
85
112
|
child.kill();
|
|
86
113
|
throw new Error("Child process has no stdout");
|
|
87
114
|
}
|
|
115
|
+
const stderrChunks = [];
|
|
116
|
+
if (child.stderr) {
|
|
117
|
+
child.stderr.on("data", (data) => {
|
|
118
|
+
stderrChunks.push(data);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
88
121
|
const rl = readline.createInterface({
|
|
89
122
|
input: child.stdout,
|
|
90
123
|
crlfDelay: Infinity
|
|
@@ -93,12 +126,15 @@ var CodexExec = class {
|
|
|
93
126
|
for await (const line of rl) {
|
|
94
127
|
yield line;
|
|
95
128
|
}
|
|
96
|
-
const exitCode = new Promise((resolve) => {
|
|
129
|
+
const exitCode = new Promise((resolve, reject) => {
|
|
97
130
|
child.once("exit", (code) => {
|
|
98
131
|
if (code === 0) {
|
|
99
132
|
resolve(code);
|
|
100
133
|
} else {
|
|
101
|
-
|
|
134
|
+
const stderrBuffer = Buffer.concat(stderrChunks);
|
|
135
|
+
reject(
|
|
136
|
+
new Error(`Codex Exec exited with code ${code}: ${stderrBuffer.toString("utf8")}`)
|
|
137
|
+
);
|
|
102
138
|
}
|
|
103
139
|
});
|
|
104
140
|
});
|
|
@@ -174,15 +210,26 @@ function findCodexPath() {
|
|
|
174
210
|
var Codex = class {
|
|
175
211
|
exec;
|
|
176
212
|
options;
|
|
177
|
-
constructor(options) {
|
|
213
|
+
constructor(options = {}) {
|
|
178
214
|
this.exec = new CodexExec(options.codexPathOverride);
|
|
179
215
|
this.options = options;
|
|
180
216
|
}
|
|
181
|
-
|
|
182
|
-
|
|
217
|
+
/**
|
|
218
|
+
* Starts a new conversation with an agent.
|
|
219
|
+
* @returns A new thread instance.
|
|
220
|
+
*/
|
|
221
|
+
startThread(options = {}) {
|
|
222
|
+
return new Thread(this.exec, this.options, options);
|
|
183
223
|
}
|
|
184
|
-
|
|
185
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
226
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
227
|
+
*
|
|
228
|
+
* @param id The id of the thread to resume.
|
|
229
|
+
* @returns A new thread instance.
|
|
230
|
+
*/
|
|
231
|
+
resumeThread(id, options = {}) {
|
|
232
|
+
return new Thread(this.exec, this.options, options, id);
|
|
186
233
|
}
|
|
187
234
|
};
|
|
188
235
|
export {
|
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 } from \"./events\";\nimport { CodexExec } from \"./exec\";\nimport { ThreadItem } from \"./items\";\nimport { TurnOptions } from \"./turnOptions\";\n\nexport type RunResult = {\n items: ThreadItem[];\n finalResponse: string;\n};\n\nexport type RunStreamedResult = {\n events: AsyncGenerator<ThreadEvent>;\n};\n\nexport type Input = string;\n\nexport class Thread {\n private exec: CodexExec;\n private options: CodexOptions;\n public id: string | null;\n\n constructor(exec: CodexExec, options: CodexOptions, id: string | null = null) {\n this.exec = exec;\n this.options = options;\n this.id = id;\n }\n\n async runStreamed(input: string, options?: TurnOptions): Promise<RunStreamedResult> {\n return { events: this.runStreamedInternal(input, options) };\n }\n\n private async *runStreamedInternal(\n input: string,\n options?: TurnOptions,\n ): AsyncGenerator<ThreadEvent> {\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 });\n for await (const item of generator) {\n const parsed = JSON.parse(item) as ThreadEvent;\n if (parsed.type === \"thread.started\") {\n this.id = parsed.thread_id;\n }\n yield parsed;\n }\n }\n\n async run(input: string, options?: TurnOptions): Promise<RunResult> {\n const generator = this.runStreamedInternal(input, options);\n const items: ThreadItem[] = [];\n let finalResponse: string = \"\";\n for await (const event of generator) {\n if (event.type === \"item.completed\") {\n if (event.item.item_type === \"assistant_message\") {\n finalResponse = event.item.text;\n }\n items.push(event.item);\n }\n }\n return { items, finalResponse };\n }\n}\n","import { spawn } from \"child_process\";\n\nimport readline from \"node:readline\";\n\nimport { SandboxMode } from \"./turnOptions\";\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?: string;\n sandboxMode?: SandboxMode;\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.threadId) {\n commandArgs.push(\"resume\", args.threadId, args.input);\n } else {\n commandArgs.push(args.input);\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.OPENAI_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.stdout) {\n child.kill();\n throw new Error(\"Child process has no stdout\");\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) => {\n child.once(\"exit\", (code) => { \n if (code === 0) {\n resolve(code);\n } else {\n throw new Error(`Codex Exec exited with code ${code}`);\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\";\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 startThread(): Thread {\n return new Thread(this.exec, this.options);\n }\n\n resumeThread(id: string): Thread {\n return new Thread(this.exec, this.options, id);\n }\n}\n"],"mappings":";AAiBO,IAAM,SAAN,MAAa;AAAA,EACV;AAAA,EACA;AAAA,EACD;AAAA,EAEP,YAAY,MAAiB,SAAuB,KAAoB,MAAM;AAC5E,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,KAAK;AAAA,EACZ;AAAA,EAEA,MAAM,YAAY,OAAe,SAAmD;AAClF,WAAO,EAAE,QAAQ,KAAK,oBAAoB,OAAO,OAAO,EAAE;AAAA,EAC5D;AAAA,EAEA,OAAe,oBACb,OACA,SAC6B;AAC7B,UAAM,YAAY,KAAK,KAAK,IAAI;AAAA,MAC9B;AAAA,MACA,SAAS,KAAK,QAAQ;AAAA,MACtB,QAAQ,KAAK,QAAQ;AAAA,MACrB,UAAU,KAAK;AAAA,MACf,OAAO,SAAS;AAAA,MAChB,aAAa,SAAS;AAAA,IACxB,CAAC;AACD,qBAAiB,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A,QACF,KAAK;AACH,yBAAe;AACf;AAAA,QACF;AACE;AAAA,MACJ;AACA;AAAA,IACF,KAAK;AACH,cAAQ,MAAM;AAAA,QACZ,KAAK;AACH,yBAAe;AACf;AAAA,QACF,KAAK;AACH,yBAAe;AACf;AAAA,QACF;AACE;AAAA,MACJ;AACA;AAAA,IACF;AACE;AAAA,EACJ;AAEA,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI,MAAM,yBAAyB,QAAQ,KAAK,IAAI,GAAG;AAAA,EAC/D;AAEA,QAAM,aAAa,KAAK,KAAK,eAAe,MAAM,QAAQ;AAC1D,QAAM,WAAW,KAAK,KAAK,YAAY,YAAY;AACnD,QAAM,kBAAkB,QAAQ,aAAa,UAAU,cAAc;AACrE,QAAM,aAAa,KAAK,KAAK,UAAU,SAAS,eAAe;AAE/D,SAAO;AACT;;;ACzJO,IAAM,QAAN,MAAY;AAAA,EACT;AAAA,EACA;AAAA,EAER,YAAY,SAAuB;AACjC,SAAK,OAAO,IAAI,UAAU,QAAQ,iBAAiB;AACnD,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,cAAsB;AACpB,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,OAAO;AAAA,EAC3C;AAAA,EAEA,aAAa,IAAoB;AAC/B,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,EAAE;AAAA,EAC/C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/thread.ts","../src/exec.ts","../src/codex.ts"],"sourcesContent":["import { CodexOptions } from \"./codexOptions\";\nimport { ThreadEvent } 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};\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 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 }\n }\n return { items, finalResponse };\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":";AA2BO,IAAM,SAAN,MAAa;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGR,IAAW,KAAoB;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,YACE,MACA,SACA,eACA,KAAoB,MACpB;AACA,SAAK,QAAQ;AACb,SAAK,WAAW;AAChB,SAAK,MAAM;AACX,SAAK,iBAAiB;AAAA,EACxB;AAAA;AAAA,EAGA,MAAM,YAAY,OAAsC;AACtD,WAAO,EAAE,QAAQ,KAAK,oBAAoB,KAAK,EAAE;AAAA,EACnD;AAAA,EAEA,OAAe,oBAAoB,OAA4C;AAC7E,UAAM,UAAU,KAAK;AACrB,UAAM,YAAY,KAAK,MAAM,IAAI;AAAA,MAC/B;AAAA,MACA,SAAS,KAAK,SAAS;AAAA,MACvB,QAAQ,KAAK,SAAS;AAAA,MACtB,UAAU,KAAK;AAAA,MACf,OAAO,SAAS;AAAA,MAChB,aAAa,SAAS;AAAA,MACtB,kBAAkB,SAAS;AAAA,MAC3B,kBAAkB,SAAS;AAAA,IAC7B,CAAC;AACD,qBAAiB,QAAQ,WAAW;AAClC,UAAI;AACJ,UAAI;AACF,iBAAS,KAAK,MAAM,IAAI;AAAA,MAC1B,SAAS,OAAO;AACd,cAAM,IAAI,MAAM,yBAAyB,IAAI,IAAI,EAAE,OAAO,MAAM,CAAC;AAAA,MACnE;AACA,UAAI,OAAO,SAAS,kBAA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;AAAA;AAAA;AAAA;AAAA,EASA,aAAa,IAAY,UAAyB,CAAC,GAAW;AAC5D,WAAO,IAAI,OAAO,KAAK,MAAM,KAAK,SAAS,SAAS,EAAE;AAAA,EACxD;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openai/codex-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"description": "TypeScript SDK for Codex APIs.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/openai/codex.git",
|
|
8
|
+
"directory": "sdk/typescript"
|
|
9
|
+
},
|
|
5
10
|
"keywords": [
|
|
6
11
|
"openai",
|
|
7
12
|
"codex",
|
|
@@ -45,13 +50,14 @@
|
|
|
45
50
|
"eslint": "^9.36.0",
|
|
46
51
|
"eslint-config-prettier": "^9.1.2",
|
|
47
52
|
"eslint-plugin-jest": "^29.0.1",
|
|
53
|
+
"eslint-plugin-node-import": "^1.0.5",
|
|
48
54
|
"jest": "^29.7.0",
|
|
49
55
|
"prettier": "^3.6.2",
|
|
50
56
|
"ts-jest": "^29.3.4",
|
|
57
|
+
"ts-jest-mock-import-meta": "^1.3.1",
|
|
51
58
|
"ts-node": "^10.9.2",
|
|
52
59
|
"tsup": "^8.5.0",
|
|
53
60
|
"typescript": "^5.9.2",
|
|
54
|
-
"typescript-eslint": "^8.45.0"
|
|
55
|
-
"ts-jest-mock-import-meta": "^1.3.1"
|
|
61
|
+
"typescript-eslint": "^8.45.0"
|
|
56
62
|
}
|
|
57
63
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|