@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.
- package/package.json +3 -3
- package/{lib/codex-sdk/tsup.config.ts → tsup.config.ts} +2 -2
- package/lib/codex-sdk/.prettierignore +0 -3
- package/lib/codex-sdk/.prettierrc +0 -5
- package/lib/codex-sdk/README.md +0 -133
- package/lib/codex-sdk/dist/index.d.ts +0 -260
- package/lib/codex-sdk/dist/index.js +0 -426
- package/lib/codex-sdk/dist/samples/basic_streaming.d.ts +0 -3
- package/lib/codex-sdk/dist/samples/basic_streaming.d.ts.map +0 -1
- package/lib/codex-sdk/dist/samples/basic_streaming.js +0 -81
- package/lib/codex-sdk/dist/samples/basic_streaming.js.map +0 -1
- package/lib/codex-sdk/dist/samples/helpers.d.ts +0 -2
- package/lib/codex-sdk/dist/samples/helpers.d.ts.map +0 -1
- package/lib/codex-sdk/dist/samples/helpers.js +0 -6
- package/lib/codex-sdk/dist/samples/helpers.js.map +0 -1
- package/lib/codex-sdk/dist/samples/structured_output.d.ts +0 -3
- package/lib/codex-sdk/dist/samples/structured_output.d.ts.map +0 -1
- package/lib/codex-sdk/dist/samples/structured_output.js +0 -17
- package/lib/codex-sdk/dist/samples/structured_output.js.map +0 -1
- package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts +0 -3
- package/lib/codex-sdk/dist/samples/structured_output_zod.d.ts.map +0 -1
- package/lib/codex-sdk/dist/samples/structured_output_zod.js +0 -16
- package/lib/codex-sdk/dist/samples/structured_output_zod.js.map +0 -1
- package/lib/codex-sdk/dist/src/codex.d.ts +0 -27
- package/lib/codex-sdk/dist/src/codex.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/codex.js +0 -33
- package/lib/codex-sdk/dist/src/codex.js.map +0 -1
- package/lib/codex-sdk/dist/src/codexOptions.d.ts +0 -11
- package/lib/codex-sdk/dist/src/codexOptions.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/codexOptions.js +0 -2
- package/lib/codex-sdk/dist/src/codexOptions.js.map +0 -1
- package/lib/codex-sdk/dist/src/events.d.ts +0 -60
- package/lib/codex-sdk/dist/src/events.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/events.js +0 -3
- package/lib/codex-sdk/dist/src/events.js.map +0 -1
- package/lib/codex-sdk/dist/src/exec.d.ts +0 -27
- package/lib/codex-sdk/dist/src/exec.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/exec.js +0 -264
- package/lib/codex-sdk/dist/src/exec.js.map +0 -1
- package/lib/codex-sdk/dist/src/index.d.ts +0 -9
- package/lib/codex-sdk/dist/src/index.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/index.js +0 -3
- package/lib/codex-sdk/dist/src/index.js.map +0 -1
- package/lib/codex-sdk/dist/src/items.d.ts +0 -103
- package/lib/codex-sdk/dist/src/items.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/items.js +0 -3
- package/lib/codex-sdk/dist/src/items.js.map +0 -1
- package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts +0 -6
- package/lib/codex-sdk/dist/src/outputSchemaFile.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/outputSchemaFile.js +0 -33
- package/lib/codex-sdk/dist/src/outputSchemaFile.js.map +0 -1
- package/lib/codex-sdk/dist/src/thread.d.ts +0 -41
- package/lib/codex-sdk/dist/src/thread.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/thread.js +0 -109
- package/lib/codex-sdk/dist/src/thread.js.map +0 -1
- package/lib/codex-sdk/dist/src/threadOptions.d.ts +0 -16
- package/lib/codex-sdk/dist/src/threadOptions.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/threadOptions.js +0 -2
- package/lib/codex-sdk/dist/src/threadOptions.js.map +0 -1
- package/lib/codex-sdk/dist/src/turnOptions.d.ts +0 -7
- package/lib/codex-sdk/dist/src/turnOptions.d.ts.map +0 -1
- package/lib/codex-sdk/dist/src/turnOptions.js +0 -2
- package/lib/codex-sdk/dist/src/turnOptions.js.map +0 -1
- package/lib/codex-sdk/dist/tests/abort.test.d.ts +0 -2
- package/lib/codex-sdk/dist/tests/abort.test.d.ts.map +0 -1
- package/lib/codex-sdk/dist/tests/abort.test.js +0 -130
- package/lib/codex-sdk/dist/tests/abort.test.js.map +0 -1
- package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts +0 -6
- package/lib/codex-sdk/dist/tests/codexExecSpy.d.ts.map +0 -1
- package/lib/codex-sdk/dist/tests/codexExecSpy.js +0 -28
- package/lib/codex-sdk/dist/tests/codexExecSpy.js.map +0 -1
- package/lib/codex-sdk/dist/tests/responsesProxy.d.ts +0 -56
- package/lib/codex-sdk/dist/tests/responsesProxy.d.ts.map +0 -1
- package/lib/codex-sdk/dist/tests/responsesProxy.js +0 -155
- package/lib/codex-sdk/dist/tests/responsesProxy.js.map +0 -1
- package/lib/codex-sdk/dist/tests/run.test.d.ts +0 -2
- package/lib/codex-sdk/dist/tests/run.test.d.ts.map +0 -1
- package/lib/codex-sdk/dist/tests/run.test.js +0 -524
- package/lib/codex-sdk/dist/tests/run.test.js.map +0 -1
- package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts +0 -2
- package/lib/codex-sdk/dist/tests/runStreamed.test.d.ts.map +0 -1
- package/lib/codex-sdk/dist/tests/runStreamed.test.js +0 -153
- package/lib/codex-sdk/dist/tests/runStreamed.test.js.map +0 -1
- package/lib/codex-sdk/dist/tsup.config.d.ts +0 -3
- package/lib/codex-sdk/dist/tsup.config.js +0 -12
- package/lib/codex-sdk/eslint.config.js +0 -21
- package/lib/codex-sdk/jest.config.cjs +0 -31
- package/lib/codex-sdk/package.json +0 -65
- package/lib/codex-sdk/samples/basic_streaming.ts +0 -90
- package/lib/codex-sdk/samples/helpers.ts +0 -8
- package/lib/codex-sdk/samples/structured_output.ts +0 -22
- package/lib/codex-sdk/samples/structured_output_zod.ts +0 -19
- package/lib/codex-sdk/src/codex.ts +0 -38
- package/lib/codex-sdk/src/codexOptions.ts +0 -10
- package/lib/codex-sdk/src/events.ts +0 -80
- package/lib/codex-sdk/src/exec.ts +0 -336
- package/lib/codex-sdk/src/index.ts +0 -39
- package/lib/codex-sdk/src/items.ts +0 -127
- package/lib/codex-sdk/src/outputSchemaFile.ts +0 -40
- package/lib/codex-sdk/src/thread.ts +0 -155
- package/lib/codex-sdk/src/threadOptions.ts +0 -18
- package/lib/codex-sdk/src/turnOptions.ts +0 -6
- package/lib/codex-sdk/tests/abort.test.ts +0 -165
- package/lib/codex-sdk/tests/codexExecSpy.ts +0 -37
- package/lib/codex-sdk/tests/responsesProxy.ts +0 -225
- package/lib/codex-sdk/tests/run.test.ts +0 -687
- package/lib/codex-sdk/tests/runStreamed.test.ts +0 -211
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@northflare/runner",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Distributed conversation runner for Northflare",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"@anthropic-ai/claude-agent-sdk": "0.1.51",
|
|
13
13
|
"@botanicastudios/claude-code-sdk-ts": "0.2.22-fork",
|
|
14
14
|
"@botanicastudios/mcp-host-rpc": "^0.4.0",
|
|
15
|
-
"@northflare/codex-sdk": "file:lib/codex-sdk",
|
|
16
15
|
"@openai/codex-sdk": "^0.60.1",
|
|
17
16
|
"@openrouter/ai-sdk-provider": "^1.2.8",
|
|
18
17
|
"@tanstack/react-query": "^5.x.x",
|
|
@@ -28,7 +27,8 @@
|
|
|
28
27
|
"simple-git": "^3.x.x",
|
|
29
28
|
"winston": "^3.x.x",
|
|
30
29
|
"zod": "^3.25.8",
|
|
31
|
-
"@northflare/agent": "0.1.
|
|
30
|
+
"@northflare/agent": "0.1.3",
|
|
31
|
+
"@northflare/codex-sdk": "0.1.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/eventsource": "^1.1.15",
|
package/lib/codex-sdk/README.md
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
# Codex SDK
|
|
2
|
-
|
|
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.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @openai/codex-sdk
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Requires Node.js 18+.
|
|
14
|
-
|
|
15
|
-
## Quickstart
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { Codex } from "@openai/codex-sdk";
|
|
19
|
-
|
|
20
|
-
const codex = new Codex();
|
|
21
|
-
const thread = codex.startThread();
|
|
22
|
-
const turn = await thread.run("Diagnose the test failure and propose a fix");
|
|
23
|
-
|
|
24
|
-
console.log(turn.finalResponse);
|
|
25
|
-
console.log(turn.items);
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Call `run()` repeatedly on the same `Thread` instance to continue that conversation.
|
|
29
|
-
|
|
30
|
-
```typescript
|
|
31
|
-
const nextTurn = await thread.run("Implement the fix");
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Streaming responses
|
|
35
|
-
|
|
36
|
-
`run()` buffers events until the turn finishes. To react to intermediate progress—tool calls, streaming responses, and file change notifications—use `runStreamed()` instead, which returns an async generator of structured events.
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
const { events } = await thread.runStreamed("Diagnose the test failure and propose a fix");
|
|
40
|
-
|
|
41
|
-
for await (const event of events) {
|
|
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
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
|
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
|
-
|
|
86
|
-
### Attaching images
|
|
87
|
-
|
|
88
|
-
Provide structured input entries when you need to include images alongside text. Text entries are concatenated into the final prompt while image entries are passed to the Codex CLI via `--image`.
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
const turn = await thread.run([
|
|
92
|
-
{ type: "text", text: "Describe these screenshots" },
|
|
93
|
-
{ type: "local_image", path: "./ui.png" },
|
|
94
|
-
{ type: "local_image", path: "./diagram.jpg" },
|
|
95
|
-
]);
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Resuming an existing thread
|
|
99
|
-
|
|
100
|
-
Threads are persisted in `~/.codex/sessions`. If you lose the in-memory `Thread` object, reconstruct it with `resumeThread()` and keep going.
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
const savedThreadId = process.env.CODEX_THREAD_ID!;
|
|
104
|
-
const thread = codex.resumeThread(savedThreadId);
|
|
105
|
-
await thread.run("Implement the fix");
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Working directory controls
|
|
109
|
-
|
|
110
|
-
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.
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
const thread = codex.startThread({
|
|
114
|
-
workingDirectory: "/path/to/project",
|
|
115
|
-
skipGitRepoCheck: true,
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Controlling the Codex CLI environment
|
|
120
|
-
|
|
121
|
-
By default, the Codex CLI inherits the Node.js process environment. Provide the optional `env` parameter when instantiating the
|
|
122
|
-
`Codex` client to fully control which variables the CLI receives—useful for sandboxed hosts like Electron apps.
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
const codex = new Codex({
|
|
126
|
-
env: {
|
|
127
|
-
PATH: "/usr/local/bin",
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
The SDK still injects its required variables (such as `OPENAI_BASE_URL` and `CODEX_API_KEY`) on top of the environment you
|
|
133
|
-
provide.
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { ContentBlock } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
|
|
3
|
-
/** The status of a command execution. */
|
|
4
|
-
type CommandExecutionStatus = "in_progress" | "completed" | "failed";
|
|
5
|
-
/** A command executed by the agent. */
|
|
6
|
-
type CommandExecutionItem = {
|
|
7
|
-
id: string;
|
|
8
|
-
type: "command_execution";
|
|
9
|
-
/** The command line executed by the agent. */
|
|
10
|
-
command: string;
|
|
11
|
-
/** Aggregated stdout and stderr captured while the command was running. */
|
|
12
|
-
aggregated_output: string;
|
|
13
|
-
/** Set when the command exits; omitted while still running. */
|
|
14
|
-
exit_code?: number;
|
|
15
|
-
/** Current status of the command execution. */
|
|
16
|
-
status: CommandExecutionStatus;
|
|
17
|
-
};
|
|
18
|
-
/** Indicates the type of the file change. */
|
|
19
|
-
type PatchChangeKind = "add" | "delete" | "update";
|
|
20
|
-
/** A set of file changes by the agent. */
|
|
21
|
-
type FileUpdateChange = {
|
|
22
|
-
path: string;
|
|
23
|
-
kind: PatchChangeKind;
|
|
24
|
-
};
|
|
25
|
-
/** The status of a file change. */
|
|
26
|
-
type PatchApplyStatus = "completed" | "failed";
|
|
27
|
-
/** A set of file changes by the agent. Emitted once the patch succeeds or fails. */
|
|
28
|
-
type FileChangeItem = {
|
|
29
|
-
id: string;
|
|
30
|
-
type: "file_change";
|
|
31
|
-
/** Individual file changes that comprise the patch. */
|
|
32
|
-
changes: FileUpdateChange[];
|
|
33
|
-
/** Whether the patch ultimately succeeded or failed. */
|
|
34
|
-
status: PatchApplyStatus;
|
|
35
|
-
};
|
|
36
|
-
/** The status of an MCP tool call. */
|
|
37
|
-
type McpToolCallStatus = "in_progress" | "completed" | "failed";
|
|
38
|
-
/**
|
|
39
|
-
* Represents a call to an MCP tool. The item starts when the invocation is dispatched
|
|
40
|
-
* and completes when the MCP server reports success or failure.
|
|
41
|
-
*/
|
|
42
|
-
type McpToolCallItem = {
|
|
43
|
-
id: string;
|
|
44
|
-
type: "mcp_tool_call";
|
|
45
|
-
/** Name of the MCP server handling the request. */
|
|
46
|
-
server: string;
|
|
47
|
-
/** The tool invoked on the MCP server. */
|
|
48
|
-
tool: string;
|
|
49
|
-
/** Arguments forwarded to the tool invocation. */
|
|
50
|
-
arguments: unknown;
|
|
51
|
-
/** Result payload returned by the MCP server for successful calls. */
|
|
52
|
-
result?: {
|
|
53
|
-
content: ContentBlock[];
|
|
54
|
-
structured_content: unknown;
|
|
55
|
-
};
|
|
56
|
-
/** Error message reported for failed calls. */
|
|
57
|
-
error?: {
|
|
58
|
-
message: string;
|
|
59
|
-
};
|
|
60
|
-
/** Current status of the tool invocation. */
|
|
61
|
-
status: McpToolCallStatus;
|
|
62
|
-
};
|
|
63
|
-
/** Response from the agent. Either natural-language text or JSON when structured output is requested. */
|
|
64
|
-
type AgentMessageItem = {
|
|
65
|
-
id: string;
|
|
66
|
-
type: "agent_message";
|
|
67
|
-
/** Either natural-language text or JSON when structured output is requested. */
|
|
68
|
-
text: string;
|
|
69
|
-
};
|
|
70
|
-
/** Agent's reasoning summary. */
|
|
71
|
-
type ReasoningItem = {
|
|
72
|
-
id: string;
|
|
73
|
-
type: "reasoning";
|
|
74
|
-
text: string;
|
|
75
|
-
};
|
|
76
|
-
/** Captures a web search request. Completes when results are returned to the agent. */
|
|
77
|
-
type WebSearchItem = {
|
|
78
|
-
id: string;
|
|
79
|
-
type: "web_search";
|
|
80
|
-
query: string;
|
|
81
|
-
};
|
|
82
|
-
/** Describes a non-fatal error surfaced as an item. */
|
|
83
|
-
type ErrorItem = {
|
|
84
|
-
id: string;
|
|
85
|
-
type: "error";
|
|
86
|
-
message: string;
|
|
87
|
-
};
|
|
88
|
-
/** An item in the agent's to-do list. */
|
|
89
|
-
type TodoItem = {
|
|
90
|
-
text: string;
|
|
91
|
-
completed: boolean;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Tracks the agent's running to-do list. Starts when the plan is issued, updates as steps change,
|
|
95
|
-
* and completes when the turn ends.
|
|
96
|
-
*/
|
|
97
|
-
type TodoListItem = {
|
|
98
|
-
id: string;
|
|
99
|
-
type: "todo_list";
|
|
100
|
-
items: TodoItem[];
|
|
101
|
-
};
|
|
102
|
-
/** Canonical union of thread items and their type-specific payloads. */
|
|
103
|
-
type ThreadItem = AgentMessageItem | ReasoningItem | CommandExecutionItem | FileChangeItem | McpToolCallItem | WebSearchItem | TodoListItem | ErrorItem;
|
|
104
|
-
|
|
105
|
-
/** Emitted when a new thread is started as the first event. */
|
|
106
|
-
type ThreadStartedEvent = {
|
|
107
|
-
type: "thread.started";
|
|
108
|
-
/** The identifier of the new thread. Can be used to resume the thread later. */
|
|
109
|
-
thread_id: string;
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Emitted when a turn is started by sending a new prompt to the model.
|
|
113
|
-
* A turn encompasses all events that happen while the agent is processing the prompt.
|
|
114
|
-
*/
|
|
115
|
-
type TurnStartedEvent = {
|
|
116
|
-
type: "turn.started";
|
|
117
|
-
};
|
|
118
|
-
/** Describes the usage of tokens during a turn. */
|
|
119
|
-
type Usage = {
|
|
120
|
-
/** The number of input tokens used during the turn. */
|
|
121
|
-
input_tokens: number;
|
|
122
|
-
/** The number of cached input tokens used during the turn. */
|
|
123
|
-
cached_input_tokens: number;
|
|
124
|
-
/** The number of output tokens used during the turn. */
|
|
125
|
-
output_tokens: number;
|
|
126
|
-
};
|
|
127
|
-
/** Emitted when a turn is completed. Typically right after the assistant's response. */
|
|
128
|
-
type TurnCompletedEvent = {
|
|
129
|
-
type: "turn.completed";
|
|
130
|
-
usage: Usage;
|
|
131
|
-
};
|
|
132
|
-
/** Indicates that a turn failed with an error. */
|
|
133
|
-
type TurnFailedEvent = {
|
|
134
|
-
type: "turn.failed";
|
|
135
|
-
error: ThreadError;
|
|
136
|
-
};
|
|
137
|
-
/** Emitted when a new item is added to the thread. Typically the item is initially "in progress". */
|
|
138
|
-
type ItemStartedEvent = {
|
|
139
|
-
type: "item.started";
|
|
140
|
-
item: ThreadItem;
|
|
141
|
-
};
|
|
142
|
-
/** Emitted when an item is updated. */
|
|
143
|
-
type ItemUpdatedEvent = {
|
|
144
|
-
type: "item.updated";
|
|
145
|
-
item: ThreadItem;
|
|
146
|
-
};
|
|
147
|
-
/** Signals that an item has reached a terminal state—either success or failure. */
|
|
148
|
-
type ItemCompletedEvent = {
|
|
149
|
-
type: "item.completed";
|
|
150
|
-
item: ThreadItem;
|
|
151
|
-
};
|
|
152
|
-
/** Fatal error emitted by the stream. */
|
|
153
|
-
type ThreadError = {
|
|
154
|
-
message: string;
|
|
155
|
-
};
|
|
156
|
-
/** Represents an unrecoverable error emitted directly by the event stream. */
|
|
157
|
-
type ThreadErrorEvent = {
|
|
158
|
-
type: "error";
|
|
159
|
-
message: string;
|
|
160
|
-
};
|
|
161
|
-
/** Top-level JSONL events emitted by codex exec. */
|
|
162
|
-
type ThreadEvent = ThreadStartedEvent | TurnStartedEvent | TurnCompletedEvent | TurnFailedEvent | ItemStartedEvent | ItemUpdatedEvent | ItemCompletedEvent | ThreadErrorEvent;
|
|
163
|
-
|
|
164
|
-
type TurnOptions = {
|
|
165
|
-
/** JSON schema describing the expected agent output. */
|
|
166
|
-
outputSchema?: unknown;
|
|
167
|
-
/** AbortSignal to cancel the turn. */
|
|
168
|
-
signal?: AbortSignal;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/** Completed turn. */
|
|
172
|
-
type Turn = {
|
|
173
|
-
items: ThreadItem[];
|
|
174
|
-
finalResponse: string;
|
|
175
|
-
usage: Usage | null;
|
|
176
|
-
};
|
|
177
|
-
/** Alias for `Turn` to describe the result of `run()`. */
|
|
178
|
-
type RunResult = Turn;
|
|
179
|
-
/** The result of the `runStreamed` method. */
|
|
180
|
-
type StreamedTurn = {
|
|
181
|
-
events: AsyncGenerator<ThreadEvent>;
|
|
182
|
-
};
|
|
183
|
-
/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */
|
|
184
|
-
type RunStreamedResult = StreamedTurn;
|
|
185
|
-
/** An input to send to the agent. */
|
|
186
|
-
type UserInput = {
|
|
187
|
-
type: "text";
|
|
188
|
-
text: string;
|
|
189
|
-
} | {
|
|
190
|
-
type: "local_image";
|
|
191
|
-
path: string;
|
|
192
|
-
};
|
|
193
|
-
type Input = string | UserInput[];
|
|
194
|
-
/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */
|
|
195
|
-
declare class Thread {
|
|
196
|
-
private _exec;
|
|
197
|
-
private _options;
|
|
198
|
-
private _id;
|
|
199
|
-
private _threadOptions;
|
|
200
|
-
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
201
|
-
get id(): string | null;
|
|
202
|
-
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
203
|
-
runStreamed(input: Input, turnOptions?: TurnOptions): Promise<StreamedTurn>;
|
|
204
|
-
private runStreamedInternal;
|
|
205
|
-
/** Provides the input to the agent and returns the completed turn. */
|
|
206
|
-
run(input: Input, turnOptions?: TurnOptions): Promise<Turn>;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
type CodexOptions = {
|
|
210
|
-
codexPathOverride?: string;
|
|
211
|
-
baseUrl?: string;
|
|
212
|
-
apiKey?: string;
|
|
213
|
-
/**
|
|
214
|
-
* Environment variables passed to the Codex CLI process. When provided, the SDK
|
|
215
|
-
* will not inherit variables from `process.env`.
|
|
216
|
-
*/
|
|
217
|
-
env?: Record<string, string>;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
type ApprovalMode = "never" | "on-request" | "on-failure" | "untrusted";
|
|
221
|
-
type SandboxMode = "read-only" | "workspace-write" | "danger-full-access";
|
|
222
|
-
type ModelReasoningEffort = "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
223
|
-
type ThreadOptions = {
|
|
224
|
-
model?: string;
|
|
225
|
-
sandboxMode?: SandboxMode;
|
|
226
|
-
workingDirectory?: string;
|
|
227
|
-
skipGitRepoCheck?: boolean;
|
|
228
|
-
modelReasoningEffort?: ModelReasoningEffort;
|
|
229
|
-
networkAccessEnabled?: boolean;
|
|
230
|
-
webSearchEnabled?: boolean;
|
|
231
|
-
approvalPolicy?: ApprovalMode;
|
|
232
|
-
additionalDirectories?: string[];
|
|
233
|
-
configOverrides?: Record<string, unknown>;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Codex is the main class for interacting with the Codex agent.
|
|
238
|
-
*
|
|
239
|
-
* Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
|
|
240
|
-
*/
|
|
241
|
-
declare class Codex {
|
|
242
|
-
private exec;
|
|
243
|
-
private options;
|
|
244
|
-
constructor(options?: CodexOptions);
|
|
245
|
-
/**
|
|
246
|
-
* Starts a new conversation with an agent.
|
|
247
|
-
* @returns A new thread instance.
|
|
248
|
-
*/
|
|
249
|
-
startThread(options?: ThreadOptions): Thread;
|
|
250
|
-
/**
|
|
251
|
-
* Resumes a conversation with an agent based on the thread id.
|
|
252
|
-
* Threads are persisted in ~/.codex/sessions.
|
|
253
|
-
*
|
|
254
|
-
* @param id The id of the thread to resume.
|
|
255
|
-
* @returns A new thread instance.
|
|
256
|
-
*/
|
|
257
|
-
resumeThread(id: string, options?: ThreadOptions): Thread;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
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 ModelReasoningEffort, 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 UserInput, type WebSearchItem };
|