@openai/codex-sdk 0.45.0-alpha.3 → 0.45.0-alpha.5

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
@@ -1,6 +1,8 @@
1
1
  # Codex SDK
2
2
 
3
- Bring the power of the best coding agent to your application.
3
+ Embed the Codex agent in your workflows and apps.
4
+
5
+ The TypeScript SDK wraps the bundled `codex` binary. It spawns the CLI and exchanges JSONL events over stdin/stdout.
4
6
 
5
7
  ## Installation
6
8
 
@@ -8,68 +10,64 @@ Bring the power of the best coding agent to your application.
8
10
  npm install @openai/codex-sdk
9
11
  ```
10
12
 
11
- ## Usage
13
+ Requires Node.js 18+.
12
14
 
13
- Call `startThread()` and `run()` to start a thread with Codex.
15
+ ## Quickstart
14
16
 
15
17
  ```typescript
16
18
  import { Codex } from "@openai/codex-sdk";
17
19
 
18
20
  const codex = new Codex();
19
21
  const thread = codex.startThread();
20
- const result = await thread.run("Diagnose the test failure and propose a fix");
22
+ const turn = await thread.run("Diagnose the test failure and propose a fix");
21
23
 
22
- console.log(result);
24
+ console.log(turn.finalResponse);
25
+ console.log(turn.items);
23
26
  ```
24
27
 
25
- You can call `run()` again to continue the same thread.
28
+ Call `run()` repeatedly on the same `Thread` instance to continue that conversation.
26
29
 
27
30
  ```typescript
28
- const result = await thread.run("Implement the fix");
29
-
30
- console.log(result);
31
+ const nextTurn = await thread.run("Implement the fix");
31
32
  ```
32
33
 
33
- ### Streaming
34
-
35
- The `run()` method completes when a thread turn is complete and the agent has produced the final response.
34
+ ### Streaming responses
36
35
 
37
- You can stream events while they are being produced by calling `runStreamed()` and iterating the returned generator.
36
+ `run()` buffers events until the turn finishes. To react to intermediate progress—tool calls, streaming responses, and file diffs—use `runStreamed()` instead, which returns an async generator of structured events.
38
37
 
39
38
  ```typescript
40
39
  const { events } = await thread.runStreamed("Diagnose the test failure and propose a fix");
41
40
 
42
41
  for await (const event of events) {
43
- console.log(event);
42
+ switch (event.type) {
43
+ case "item.completed":
44
+ console.log("item", event.item);
45
+ break;
46
+ case "turn.completed":
47
+ console.log("usage", event.usage);
48
+ break;
49
+ }
44
50
  }
45
51
  ```
46
52
 
47
- ### Resuming a thread
53
+ ### Resuming an existing thread
48
54
 
49
- If you don't have the original `Thread` instance to continue the thread, you can resume by calling `resumeThread()` and providing the thread identifier.
55
+ Threads are persisted in `~/.codex/sessions`. If you lose the in-memory `Thread` object, reconstruct it with `resumeThread()` and keep going.
50
56
 
51
57
  ```typescript
52
- const threadId = "...";
53
- const thread = codex.resumeThread(threadId);
54
- const result = await thread.run("Implement the fix");
55
-
56
- console.log(result);
58
+ const savedThreadId = process.env.CODEX_THREAD_ID!;
59
+ const thread = codex.resumeThread(savedThreadId);
60
+ await thread.run("Implement the fix");
57
61
  ```
58
62
 
59
- ### Working directory
63
+ ### Working directory controls
60
64
 
61
- By default, Codex will run in the current working directory. You can change the working directory by passing the `workingDirectory` option when creating a thread.
62
-
63
- ```typescript
64
- const thread = codex.startThread({
65
- workingDirectory: "/path/to/working/directory",
66
- });
67
- ```
68
-
69
- 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 when creating a thread.
65
+ Codex runs in the current working directory by default. 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 when creating a thread.
70
66
 
71
67
  ```typescript
72
68
  const thread = codex.startThread({
69
+ workingDirectory: "/path/to/project",
73
70
  skipGitRepoCheck: true,
74
71
  });
75
72
  ```
73
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openai/codex-sdk",
3
- "version": "0.45.0-alpha.3",
3
+ "version": "0.45.0-alpha.5",
4
4
  "description": "TypeScript SDK for Codex APIs.",
5
5
  "repository": {
6
6
  "type": "git",