@ai-nd-co/codex-sdk 1.0.9
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/LICENSE +201 -0
- package/README.md +133 -0
- package/dist/index.d.ts +261 -0
- package/dist/index.js +358 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
- package/vendor/x86_64-pc-windows-msvc/codex/codex-command-runner.exe +0 -0
- package/vendor/x86_64-pc-windows-msvc/codex/codex-windows-sandbox-setup.exe +0 -0
- package/vendor/x86_64-pc-windows-msvc/codex/codex.exe +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 OpenAI
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
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 WebSearchMode = "disabled" | "cached" | "live";
|
|
224
|
+
type ThreadOptions = {
|
|
225
|
+
model?: string;
|
|
226
|
+
sandboxMode?: SandboxMode;
|
|
227
|
+
workingDirectory?: string;
|
|
228
|
+
skipGitRepoCheck?: boolean;
|
|
229
|
+
modelReasoningEffort?: ModelReasoningEffort;
|
|
230
|
+
networkAccessEnabled?: boolean;
|
|
231
|
+
webSearchMode?: WebSearchMode;
|
|
232
|
+
webSearchEnabled?: boolean;
|
|
233
|
+
approvalPolicy?: ApprovalMode;
|
|
234
|
+
additionalDirectories?: string[];
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Codex is the main class for interacting with the Codex agent.
|
|
239
|
+
*
|
|
240
|
+
* Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.
|
|
241
|
+
*/
|
|
242
|
+
declare class Codex {
|
|
243
|
+
private exec;
|
|
244
|
+
private options;
|
|
245
|
+
constructor(options?: CodexOptions);
|
|
246
|
+
/**
|
|
247
|
+
* Starts a new conversation with an agent.
|
|
248
|
+
* @returns A new thread instance.
|
|
249
|
+
*/
|
|
250
|
+
startThread(options?: ThreadOptions): Thread;
|
|
251
|
+
/**
|
|
252
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
253
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
254
|
+
*
|
|
255
|
+
* @param id The id of the thread to resume.
|
|
256
|
+
* @returns A new thread instance.
|
|
257
|
+
*/
|
|
258
|
+
resumeThread(id: string, options?: ThreadOptions): Thread;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
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, type WebSearchMode };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// src/outputSchemaFile.ts
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
async function createOutputSchemaFile(schema) {
|
|
6
|
+
if (schema === void 0) {
|
|
7
|
+
return { cleanup: async () => {
|
|
8
|
+
} };
|
|
9
|
+
}
|
|
10
|
+
if (!isJsonObject(schema)) {
|
|
11
|
+
throw new Error("outputSchema must be a plain JSON object");
|
|
12
|
+
}
|
|
13
|
+
const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), "codex-output-schema-"));
|
|
14
|
+
const schemaPath = path.join(schemaDir, "schema.json");
|
|
15
|
+
const cleanup = async () => {
|
|
16
|
+
try {
|
|
17
|
+
await fs.rm(schemaDir, { recursive: true, force: true });
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
try {
|
|
22
|
+
await fs.writeFile(schemaPath, JSON.stringify(schema), "utf8");
|
|
23
|
+
return { schemaPath, cleanup };
|
|
24
|
+
} catch (error) {
|
|
25
|
+
await cleanup();
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isJsonObject(value) {
|
|
30
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/thread.ts
|
|
34
|
+
var Thread = class {
|
|
35
|
+
_exec;
|
|
36
|
+
_options;
|
|
37
|
+
_id;
|
|
38
|
+
_threadOptions;
|
|
39
|
+
/** Returns the ID of the thread. Populated after the first turn starts. */
|
|
40
|
+
get id() {
|
|
41
|
+
return this._id;
|
|
42
|
+
}
|
|
43
|
+
/* @internal */
|
|
44
|
+
constructor(exec, options, threadOptions, id = null) {
|
|
45
|
+
this._exec = exec;
|
|
46
|
+
this._options = options;
|
|
47
|
+
this._id = id;
|
|
48
|
+
this._threadOptions = threadOptions;
|
|
49
|
+
}
|
|
50
|
+
/** Provides the input to the agent and streams events as they are produced during the turn. */
|
|
51
|
+
async runStreamed(input, turnOptions = {}) {
|
|
52
|
+
return { events: this.runStreamedInternal(input, turnOptions) };
|
|
53
|
+
}
|
|
54
|
+
async *runStreamedInternal(input, turnOptions = {}) {
|
|
55
|
+
const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);
|
|
56
|
+
const options = this._threadOptions;
|
|
57
|
+
const { prompt, images } = normalizeInput(input);
|
|
58
|
+
const generator = this._exec.run({
|
|
59
|
+
input: prompt,
|
|
60
|
+
baseUrl: this._options.baseUrl,
|
|
61
|
+
apiKey: this._options.apiKey,
|
|
62
|
+
threadId: this._id,
|
|
63
|
+
images,
|
|
64
|
+
model: options?.model,
|
|
65
|
+
sandboxMode: options?.sandboxMode,
|
|
66
|
+
workingDirectory: options?.workingDirectory,
|
|
67
|
+
skipGitRepoCheck: options?.skipGitRepoCheck,
|
|
68
|
+
outputSchemaFile: schemaPath,
|
|
69
|
+
modelReasoningEffort: options?.modelReasoningEffort,
|
|
70
|
+
signal: turnOptions.signal,
|
|
71
|
+
networkAccessEnabled: options?.networkAccessEnabled,
|
|
72
|
+
webSearchMode: options?.webSearchMode,
|
|
73
|
+
webSearchEnabled: options?.webSearchEnabled,
|
|
74
|
+
approvalPolicy: options?.approvalPolicy,
|
|
75
|
+
additionalDirectories: options?.additionalDirectories
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
for await (const item of generator) {
|
|
79
|
+
let parsed;
|
|
80
|
+
try {
|
|
81
|
+
parsed = JSON.parse(item);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new Error(`Failed to parse item: ${item}`, { cause: error });
|
|
84
|
+
}
|
|
85
|
+
if (parsed.type === "thread.started") {
|
|
86
|
+
this._id = parsed.thread_id;
|
|
87
|
+
}
|
|
88
|
+
yield parsed;
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
await cleanup();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Provides the input to the agent and returns the completed turn. */
|
|
95
|
+
async run(input, turnOptions = {}) {
|
|
96
|
+
const generator = this.runStreamedInternal(input, turnOptions);
|
|
97
|
+
const items = [];
|
|
98
|
+
let finalResponse = "";
|
|
99
|
+
let usage = null;
|
|
100
|
+
let turnFailure = null;
|
|
101
|
+
for await (const event of generator) {
|
|
102
|
+
if (event.type === "item.completed") {
|
|
103
|
+
if (event.item.type === "agent_message") {
|
|
104
|
+
finalResponse = event.item.text;
|
|
105
|
+
}
|
|
106
|
+
items.push(event.item);
|
|
107
|
+
} else if (event.type === "turn.completed") {
|
|
108
|
+
usage = event.usage;
|
|
109
|
+
} else if (event.type === "turn.failed") {
|
|
110
|
+
turnFailure = event.error;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (turnFailure) {
|
|
115
|
+
throw new Error(turnFailure.message);
|
|
116
|
+
}
|
|
117
|
+
return { items, finalResponse, usage };
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function normalizeInput(input) {
|
|
121
|
+
if (typeof input === "string") {
|
|
122
|
+
return { prompt: input, images: [] };
|
|
123
|
+
}
|
|
124
|
+
const promptParts = [];
|
|
125
|
+
const images = [];
|
|
126
|
+
for (const item of input) {
|
|
127
|
+
if (item.type === "text") {
|
|
128
|
+
promptParts.push(item.text);
|
|
129
|
+
} else if (item.type === "local_image") {
|
|
130
|
+
images.push(item.path);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { prompt: promptParts.join("\n\n"), images };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/exec.ts
|
|
137
|
+
import { spawn } from "child_process";
|
|
138
|
+
import path2 from "path";
|
|
139
|
+
import readline from "readline";
|
|
140
|
+
import { fileURLToPath } from "url";
|
|
141
|
+
var INTERNAL_ORIGINATOR_ENV = "CODEX_INTERNAL_ORIGINATOR_OVERRIDE";
|
|
142
|
+
var TYPESCRIPT_SDK_ORIGINATOR = "codex_sdk_ts";
|
|
143
|
+
var CodexExec = class {
|
|
144
|
+
executablePath;
|
|
145
|
+
envOverride;
|
|
146
|
+
constructor(executablePath = null, env) {
|
|
147
|
+
this.executablePath = executablePath || findCodexPath();
|
|
148
|
+
this.envOverride = env;
|
|
149
|
+
}
|
|
150
|
+
async *run(args) {
|
|
151
|
+
const commandArgs = ["exec", "--experimental-json"];
|
|
152
|
+
if (args.model) {
|
|
153
|
+
commandArgs.push("--model", args.model);
|
|
154
|
+
}
|
|
155
|
+
if (args.sandboxMode) {
|
|
156
|
+
commandArgs.push("--sandbox", args.sandboxMode);
|
|
157
|
+
}
|
|
158
|
+
if (args.workingDirectory) {
|
|
159
|
+
commandArgs.push("--cd", args.workingDirectory);
|
|
160
|
+
}
|
|
161
|
+
if (args.additionalDirectories?.length) {
|
|
162
|
+
for (const dir of args.additionalDirectories) {
|
|
163
|
+
commandArgs.push("--add-dir", dir);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (args.skipGitRepoCheck) {
|
|
167
|
+
commandArgs.push("--skip-git-repo-check");
|
|
168
|
+
}
|
|
169
|
+
if (args.outputSchemaFile) {
|
|
170
|
+
commandArgs.push("--output-schema", args.outputSchemaFile);
|
|
171
|
+
}
|
|
172
|
+
if (args.modelReasoningEffort) {
|
|
173
|
+
commandArgs.push("--config", `model_reasoning_effort="${args.modelReasoningEffort}"`);
|
|
174
|
+
}
|
|
175
|
+
if (args.networkAccessEnabled !== void 0) {
|
|
176
|
+
commandArgs.push(
|
|
177
|
+
"--config",
|
|
178
|
+
`sandbox_workspace_write.network_access=${args.networkAccessEnabled}`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (args.webSearchMode) {
|
|
182
|
+
commandArgs.push("--config", `web_search="${args.webSearchMode}"`);
|
|
183
|
+
} else if (args.webSearchEnabled === true) {
|
|
184
|
+
commandArgs.push("--config", `web_search="live"`);
|
|
185
|
+
} else if (args.webSearchEnabled === false) {
|
|
186
|
+
commandArgs.push("--config", `web_search="disabled"`);
|
|
187
|
+
}
|
|
188
|
+
if (args.approvalPolicy) {
|
|
189
|
+
commandArgs.push("--config", `approval_policy="${args.approvalPolicy}"`);
|
|
190
|
+
}
|
|
191
|
+
if (args.images?.length) {
|
|
192
|
+
for (const image of args.images) {
|
|
193
|
+
commandArgs.push("--image", image);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (args.threadId) {
|
|
197
|
+
commandArgs.push("resume", args.threadId);
|
|
198
|
+
}
|
|
199
|
+
const env = {};
|
|
200
|
+
if (this.envOverride) {
|
|
201
|
+
Object.assign(env, this.envOverride);
|
|
202
|
+
} else {
|
|
203
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
204
|
+
if (value !== void 0) {
|
|
205
|
+
env[key] = value;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (!env[INTERNAL_ORIGINATOR_ENV]) {
|
|
210
|
+
env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;
|
|
211
|
+
}
|
|
212
|
+
if (args.baseUrl) {
|
|
213
|
+
env.OPENAI_BASE_URL = args.baseUrl;
|
|
214
|
+
}
|
|
215
|
+
if (args.apiKey) {
|
|
216
|
+
env.CODEX_API_KEY = args.apiKey;
|
|
217
|
+
}
|
|
218
|
+
const child = spawn(this.executablePath, commandArgs, {
|
|
219
|
+
env,
|
|
220
|
+
signal: args.signal
|
|
221
|
+
});
|
|
222
|
+
let spawnError = null;
|
|
223
|
+
child.once("error", (err) => spawnError = err);
|
|
224
|
+
if (!child.stdin) {
|
|
225
|
+
child.kill();
|
|
226
|
+
throw new Error("Child process has no stdin");
|
|
227
|
+
}
|
|
228
|
+
child.stdin.write(args.input);
|
|
229
|
+
child.stdin.end();
|
|
230
|
+
if (!child.stdout) {
|
|
231
|
+
child.kill();
|
|
232
|
+
throw new Error("Child process has no stdout");
|
|
233
|
+
}
|
|
234
|
+
const stderrChunks = [];
|
|
235
|
+
if (child.stderr) {
|
|
236
|
+
child.stderr.on("data", (data) => {
|
|
237
|
+
stderrChunks.push(data);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const exitPromise = new Promise(
|
|
241
|
+
(resolve) => {
|
|
242
|
+
child.once("exit", (code, signal) => {
|
|
243
|
+
resolve({ code, signal });
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
const rl = readline.createInterface({
|
|
248
|
+
input: child.stdout,
|
|
249
|
+
crlfDelay: Infinity
|
|
250
|
+
});
|
|
251
|
+
try {
|
|
252
|
+
for await (const line of rl) {
|
|
253
|
+
yield line;
|
|
254
|
+
}
|
|
255
|
+
if (spawnError) throw spawnError;
|
|
256
|
+
const { code, signal } = await exitPromise;
|
|
257
|
+
if (code !== 0 || signal) {
|
|
258
|
+
const stderrBuffer = Buffer.concat(stderrChunks);
|
|
259
|
+
const detail = signal ? `signal ${signal}` : `code ${code ?? 1}`;
|
|
260
|
+
throw new Error(`Codex Exec exited with ${detail}: ${stderrBuffer.toString("utf8")}`);
|
|
261
|
+
}
|
|
262
|
+
} finally {
|
|
263
|
+
rl.close();
|
|
264
|
+
child.removeAllListeners();
|
|
265
|
+
try {
|
|
266
|
+
if (!child.killed) child.kill();
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
var scriptFileName = fileURLToPath(import.meta.url);
|
|
273
|
+
var scriptDirName = path2.dirname(scriptFileName);
|
|
274
|
+
function findCodexPath() {
|
|
275
|
+
const { platform, arch } = process;
|
|
276
|
+
let targetTriple = null;
|
|
277
|
+
switch (platform) {
|
|
278
|
+
case "linux":
|
|
279
|
+
case "android":
|
|
280
|
+
switch (arch) {
|
|
281
|
+
case "x64":
|
|
282
|
+
targetTriple = "x86_64-unknown-linux-musl";
|
|
283
|
+
break;
|
|
284
|
+
case "arm64":
|
|
285
|
+
targetTriple = "aarch64-unknown-linux-musl";
|
|
286
|
+
break;
|
|
287
|
+
default:
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
case "darwin":
|
|
292
|
+
switch (arch) {
|
|
293
|
+
case "x64":
|
|
294
|
+
targetTriple = "x86_64-apple-darwin";
|
|
295
|
+
break;
|
|
296
|
+
case "arm64":
|
|
297
|
+
targetTriple = "aarch64-apple-darwin";
|
|
298
|
+
break;
|
|
299
|
+
default:
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
case "win32":
|
|
304
|
+
switch (arch) {
|
|
305
|
+
case "x64":
|
|
306
|
+
targetTriple = "x86_64-pc-windows-msvc";
|
|
307
|
+
break;
|
|
308
|
+
case "arm64":
|
|
309
|
+
targetTriple = "aarch64-pc-windows-msvc";
|
|
310
|
+
break;
|
|
311
|
+
default:
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
default:
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
if (!targetTriple) {
|
|
319
|
+
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
|
320
|
+
}
|
|
321
|
+
const vendorRoot = path2.join(scriptDirName, "..", "vendor");
|
|
322
|
+
const archRoot = path2.join(vendorRoot, targetTriple);
|
|
323
|
+
const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
|
|
324
|
+
const binaryPath = path2.join(archRoot, "codex", codexBinaryName);
|
|
325
|
+
return binaryPath;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/codex.ts
|
|
329
|
+
var Codex = class {
|
|
330
|
+
exec;
|
|
331
|
+
options;
|
|
332
|
+
constructor(options = {}) {
|
|
333
|
+
this.exec = new CodexExec(options.codexPathOverride, options.env);
|
|
334
|
+
this.options = options;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Starts a new conversation with an agent.
|
|
338
|
+
* @returns A new thread instance.
|
|
339
|
+
*/
|
|
340
|
+
startThread(options = {}) {
|
|
341
|
+
return new Thread(this.exec, this.options, options);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Resumes a conversation with an agent based on the thread id.
|
|
345
|
+
* Threads are persisted in ~/.codex/sessions.
|
|
346
|
+
*
|
|
347
|
+
* @param id The id of the thread to resume.
|
|
348
|
+
* @returns A new thread instance.
|
|
349
|
+
*/
|
|
350
|
+
resumeThread(id, options = {}) {
|
|
351
|
+
return new Thread(this.exec, this.options, options, id);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
export {
|
|
355
|
+
Codex,
|
|
356
|
+
Thread
|
|
357
|
+
};
|
|
358
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/outputSchemaFile.ts","../src/thread.ts","../src/exec.ts","../src/codex.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\r\nimport os from \"node:os\";\r\nimport path from \"node:path\";\r\n\r\nexport type OutputSchemaFile = {\r\n schemaPath?: string;\r\n cleanup: () => Promise<void>;\r\n};\r\n\r\nexport async function createOutputSchemaFile(schema: unknown): Promise<OutputSchemaFile> {\r\n if (schema === undefined) {\r\n return { cleanup: async () => {} };\r\n }\r\n\r\n if (!isJsonObject(schema)) {\r\n throw new Error(\"outputSchema must be a plain JSON object\");\r\n }\r\n\r\n const schemaDir = await fs.mkdtemp(path.join(os.tmpdir(), \"codex-output-schema-\"));\r\n const schemaPath = path.join(schemaDir, \"schema.json\");\r\n const cleanup = async () => {\r\n try {\r\n await fs.rm(schemaDir, { recursive: true, force: true });\r\n } catch {\r\n // suppress\r\n }\r\n };\r\n\r\n try {\r\n await fs.writeFile(schemaPath, JSON.stringify(schema), \"utf8\");\r\n return { schemaPath, cleanup };\r\n } catch (error) {\r\n await cleanup();\r\n throw error;\r\n }\r\n}\r\n\r\nfunction isJsonObject(value: unknown): value is Record<string, unknown> {\r\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\r\n}\r\n","import { CodexOptions } from \"./codexOptions\";\r\nimport { ThreadEvent, ThreadError, Usage } from \"./events\";\r\nimport { CodexExec } from \"./exec\";\r\nimport { ThreadItem } from \"./items\";\r\nimport { ThreadOptions } from \"./threadOptions\";\r\nimport { TurnOptions } from \"./turnOptions\";\r\nimport { createOutputSchemaFile } from \"./outputSchemaFile\";\r\n\r\n/** Completed turn. */\r\nexport type Turn = {\r\n items: ThreadItem[];\r\n finalResponse: string;\r\n usage: Usage | null;\r\n};\r\n\r\n/** Alias for `Turn` to describe the result of `run()`. */\r\nexport type RunResult = Turn;\r\n\r\n/** The result of the `runStreamed` method. */\r\nexport type StreamedTurn = {\r\n events: AsyncGenerator<ThreadEvent>;\r\n};\r\n\r\n/** Alias for `StreamedTurn` to describe the result of `runStreamed()`. */\r\nexport type RunStreamedResult = StreamedTurn;\r\n\r\n/** An input to send to the agent. */\r\nexport type UserInput =\r\n | {\r\n type: \"text\";\r\n text: string;\r\n }\r\n | {\r\n type: \"local_image\";\r\n path: string;\r\n };\r\n\r\nexport type Input = string | UserInput[];\r\n\r\n/** Respesent a thread of conversation with the agent. One thread can have multiple consecutive turns. */\r\nexport class Thread {\r\n private _exec: CodexExec;\r\n private _options: CodexOptions;\r\n private _id: string | null;\r\n private _threadOptions: ThreadOptions;\r\n\r\n /** Returns the ID of the thread. Populated after the first turn starts. */\r\n public get id(): string | null {\r\n return this._id;\r\n }\r\n\r\n /* @internal */\r\n constructor(\r\n exec: CodexExec,\r\n options: CodexOptions,\r\n threadOptions: ThreadOptions,\r\n id: string | null = null,\r\n ) {\r\n this._exec = exec;\r\n this._options = options;\r\n this._id = id;\r\n this._threadOptions = threadOptions;\r\n }\r\n\r\n /** Provides the input to the agent and streams events as they are produced during the turn. */\r\n async runStreamed(input: Input, turnOptions: TurnOptions = {}): Promise<StreamedTurn> {\r\n return { events: this.runStreamedInternal(input, turnOptions) };\r\n }\r\n\r\n private async *runStreamedInternal(\r\n input: Input,\r\n turnOptions: TurnOptions = {},\r\n ): AsyncGenerator<ThreadEvent> {\r\n const { schemaPath, cleanup } = await createOutputSchemaFile(turnOptions.outputSchema);\r\n const options = this._threadOptions;\r\n const { prompt, images } = normalizeInput(input);\r\n const generator = this._exec.run({\r\n input: prompt,\r\n baseUrl: this._options.baseUrl,\r\n apiKey: this._options.apiKey,\r\n threadId: this._id,\r\n images,\r\n model: options?.model,\r\n sandboxMode: options?.sandboxMode,\r\n workingDirectory: options?.workingDirectory,\r\n skipGitRepoCheck: options?.skipGitRepoCheck,\r\n outputSchemaFile: schemaPath,\r\n modelReasoningEffort: options?.modelReasoningEffort,\r\n signal: turnOptions.signal,\r\n networkAccessEnabled: options?.networkAccessEnabled,\r\n webSearchMode: options?.webSearchMode,\r\n webSearchEnabled: options?.webSearchEnabled,\r\n approvalPolicy: options?.approvalPolicy,\r\n additionalDirectories: options?.additionalDirectories,\r\n });\r\n try {\r\n for await (const item of generator) {\r\n let parsed: ThreadEvent;\r\n try {\r\n parsed = JSON.parse(item) as ThreadEvent;\r\n } catch (error) {\r\n throw new Error(`Failed to parse item: ${item}`, { cause: error });\r\n }\r\n if (parsed.type === \"thread.started\") {\r\n this._id = parsed.thread_id;\r\n }\r\n yield parsed;\r\n }\r\n } finally {\r\n await cleanup();\r\n }\r\n }\r\n\r\n /** Provides the input to the agent and returns the completed turn. */\r\n async run(input: Input, turnOptions: TurnOptions = {}): Promise<Turn> {\r\n const generator = this.runStreamedInternal(input, turnOptions);\r\n const items: ThreadItem[] = [];\r\n let finalResponse: string = \"\";\r\n let usage: Usage | null = null;\r\n let turnFailure: ThreadError | null = null;\r\n for await (const event of generator) {\r\n if (event.type === \"item.completed\") {\r\n if (event.item.type === \"agent_message\") {\r\n finalResponse = event.item.text;\r\n }\r\n items.push(event.item);\r\n } else if (event.type === \"turn.completed\") {\r\n usage = event.usage;\r\n } else if (event.type === \"turn.failed\") {\r\n turnFailure = event.error;\r\n break;\r\n }\r\n }\r\n if (turnFailure) {\r\n throw new Error(turnFailure.message);\r\n }\r\n return { items, finalResponse, usage };\r\n }\r\n}\r\n\r\nfunction normalizeInput(input: Input): { prompt: string; images: string[] } {\r\n if (typeof input === \"string\") {\r\n return { prompt: input, images: [] };\r\n }\r\n const promptParts: string[] = [];\r\n const images: string[] = [];\r\n for (const item of input) {\r\n if (item.type === \"text\") {\r\n promptParts.push(item.text);\r\n } else if (item.type === \"local_image\") {\r\n images.push(item.path);\r\n }\r\n }\r\n return { prompt: promptParts.join(\"\\n\\n\"), images };\r\n}\r\n","import { spawn } from \"node:child_process\";\r\nimport path from \"node:path\";\r\nimport readline from \"node:readline\";\r\nimport { fileURLToPath } from \"node:url\";\r\n\r\nimport {\r\n SandboxMode,\r\n ModelReasoningEffort,\r\n ApprovalMode,\r\n WebSearchMode,\r\n} from \"./threadOptions\";\r\n\r\nexport type CodexExecArgs = {\r\n input: string;\r\n\r\n baseUrl?: string;\r\n apiKey?: string;\r\n threadId?: string | null;\r\n images?: string[];\r\n // --model\r\n model?: string;\r\n // --sandbox\r\n sandboxMode?: SandboxMode;\r\n // --cd\r\n workingDirectory?: string;\r\n // --add-dir\r\n additionalDirectories?: string[];\r\n // --skip-git-repo-check\r\n skipGitRepoCheck?: boolean;\r\n // --output-schema\r\n outputSchemaFile?: string;\r\n // --config model_reasoning_effort\r\n modelReasoningEffort?: ModelReasoningEffort;\r\n // AbortSignal to cancel the execution\r\n signal?: AbortSignal;\r\n // --config sandbox_workspace_write.network_access\r\n networkAccessEnabled?: boolean;\r\n // --config web_search\r\n webSearchMode?: WebSearchMode;\r\n // legacy --config features.web_search_request\r\n webSearchEnabled?: boolean;\r\n // --config approval_policy\r\n approvalPolicy?: ApprovalMode;\r\n};\r\n\r\nconst INTERNAL_ORIGINATOR_ENV = \"CODEX_INTERNAL_ORIGINATOR_OVERRIDE\";\r\nconst TYPESCRIPT_SDK_ORIGINATOR = \"codex_sdk_ts\";\r\n\r\nexport class CodexExec {\r\n private executablePath: string;\r\n private envOverride?: Record<string, string>;\r\n\r\n constructor(executablePath: string | null = null, env?: Record<string, string>) {\r\n this.executablePath = executablePath || findCodexPath();\r\n this.envOverride = env;\r\n }\r\n\r\n async *run(args: CodexExecArgs): AsyncGenerator<string> {\r\n const commandArgs: string[] = [\"exec\", \"--experimental-json\"];\r\n\r\n if (args.model) {\r\n commandArgs.push(\"--model\", args.model);\r\n }\r\n\r\n if (args.sandboxMode) {\r\n commandArgs.push(\"--sandbox\", args.sandboxMode);\r\n }\r\n\r\n if (args.workingDirectory) {\r\n commandArgs.push(\"--cd\", args.workingDirectory);\r\n }\r\n\r\n if (args.additionalDirectories?.length) {\r\n for (const dir of args.additionalDirectories) {\r\n commandArgs.push(\"--add-dir\", dir);\r\n }\r\n }\r\n\r\n if (args.skipGitRepoCheck) {\r\n commandArgs.push(\"--skip-git-repo-check\");\r\n }\r\n\r\n if (args.outputSchemaFile) {\r\n commandArgs.push(\"--output-schema\", args.outputSchemaFile);\r\n }\r\n\r\n if (args.modelReasoningEffort) {\r\n commandArgs.push(\"--config\", `model_reasoning_effort=\"${args.modelReasoningEffort}\"`);\r\n }\r\n\r\n if (args.networkAccessEnabled !== undefined) {\r\n commandArgs.push(\r\n \"--config\",\r\n `sandbox_workspace_write.network_access=${args.networkAccessEnabled}`,\r\n );\r\n }\r\n\r\n if (args.webSearchMode) {\r\n commandArgs.push(\"--config\", `web_search=\"${args.webSearchMode}\"`);\r\n } else if (args.webSearchEnabled === true) {\r\n commandArgs.push(\"--config\", `web_search=\"live\"`);\r\n } else if (args.webSearchEnabled === false) {\r\n commandArgs.push(\"--config\", `web_search=\"disabled\"`);\r\n }\r\n\r\n if (args.approvalPolicy) {\r\n commandArgs.push(\"--config\", `approval_policy=\"${args.approvalPolicy}\"`);\r\n }\r\n\r\n if (args.images?.length) {\r\n for (const image of args.images) {\r\n commandArgs.push(\"--image\", image);\r\n }\r\n }\r\n\r\n if (args.threadId) {\r\n commandArgs.push(\"resume\", args.threadId);\r\n }\r\n\r\n const env: Record<string, string> = {};\r\n if (this.envOverride) {\r\n Object.assign(env, this.envOverride);\r\n } else {\r\n for (const [key, value] of Object.entries(process.env)) {\r\n if (value !== undefined) {\r\n env[key] = value;\r\n }\r\n }\r\n }\r\n if (!env[INTERNAL_ORIGINATOR_ENV]) {\r\n env[INTERNAL_ORIGINATOR_ENV] = TYPESCRIPT_SDK_ORIGINATOR;\r\n }\r\n if (args.baseUrl) {\r\n env.OPENAI_BASE_URL = args.baseUrl;\r\n }\r\n if (args.apiKey) {\r\n env.CODEX_API_KEY = args.apiKey;\r\n }\r\n\r\n const child = spawn(this.executablePath, commandArgs, {\r\n env,\r\n signal: args.signal,\r\n });\r\n\r\n let spawnError: unknown | null = null;\r\n child.once(\"error\", (err) => (spawnError = err));\r\n\r\n if (!child.stdin) {\r\n child.kill();\r\n throw new Error(\"Child process has no stdin\");\r\n }\r\n child.stdin.write(args.input);\r\n child.stdin.end();\r\n\r\n if (!child.stdout) {\r\n child.kill();\r\n throw new Error(\"Child process has no stdout\");\r\n }\r\n const stderrChunks: Buffer[] = [];\r\n\r\n if (child.stderr) {\r\n child.stderr.on(\"data\", (data) => {\r\n stderrChunks.push(data);\r\n });\r\n }\r\n\r\n const exitPromise = new Promise<{ code: number | null; signal: NodeJS.Signals | null }>(\r\n (resolve) => {\r\n child.once(\"exit\", (code, signal) => {\r\n resolve({ code, signal });\r\n });\r\n },\r\n );\r\n\r\n const rl = readline.createInterface({\r\n input: child.stdout,\r\n crlfDelay: Infinity,\r\n });\r\n\r\n try {\r\n for await (const line of rl) {\r\n // `line` is a string (Node sets default encoding to utf8 for readline)\r\n yield line as string;\r\n }\r\n\r\n if (spawnError) throw spawnError;\r\n const { code, signal } = await exitPromise;\r\n if (code !== 0 || signal) {\r\n const stderrBuffer = Buffer.concat(stderrChunks);\r\n const detail = signal ? `signal ${signal}` : `code ${code ?? 1}`;\r\n throw new Error(`Codex Exec exited with ${detail}: ${stderrBuffer.toString(\"utf8\")}`);\r\n }\r\n } finally {\r\n rl.close();\r\n child.removeAllListeners();\r\n try {\r\n if (!child.killed) child.kill();\r\n } catch {\r\n // ignore\r\n }\r\n }\r\n }\r\n}\r\n\r\nconst scriptFileName = fileURLToPath(import.meta.url);\r\nconst scriptDirName = path.dirname(scriptFileName);\r\n\r\nfunction findCodexPath() {\r\n const { platform, arch } = process;\r\n\r\n let targetTriple = null;\r\n switch (platform) {\r\n case \"linux\":\r\n case \"android\":\r\n switch (arch) {\r\n case \"x64\":\r\n targetTriple = \"x86_64-unknown-linux-musl\";\r\n break;\r\n case \"arm64\":\r\n targetTriple = \"aarch64-unknown-linux-musl\";\r\n break;\r\n default:\r\n break;\r\n }\r\n break;\r\n case \"darwin\":\r\n switch (arch) {\r\n case \"x64\":\r\n targetTriple = \"x86_64-apple-darwin\";\r\n break;\r\n case \"arm64\":\r\n targetTriple = \"aarch64-apple-darwin\";\r\n break;\r\n default:\r\n break;\r\n }\r\n break;\r\n case \"win32\":\r\n switch (arch) {\r\n case \"x64\":\r\n targetTriple = \"x86_64-pc-windows-msvc\";\r\n break;\r\n case \"arm64\":\r\n targetTriple = \"aarch64-pc-windows-msvc\";\r\n break;\r\n default:\r\n break;\r\n }\r\n break;\r\n default:\r\n break;\r\n }\r\n\r\n if (!targetTriple) {\r\n throw new Error(`Unsupported platform: ${platform} (${arch})`);\r\n }\r\n\r\n const vendorRoot = path.join(scriptDirName, \"..\", \"vendor\");\r\n const archRoot = path.join(vendorRoot, targetTriple);\r\n const codexBinaryName = process.platform === \"win32\" ? \"codex.exe\" : \"codex\";\r\n const binaryPath = path.join(archRoot, \"codex\", codexBinaryName);\r\n\r\n return binaryPath;\r\n}\r\n","import { CodexOptions } from \"./codexOptions\";\r\nimport { CodexExec } from \"./exec\";\r\nimport { Thread } from \"./thread\";\r\nimport { ThreadOptions } from \"./threadOptions\";\r\n\r\n/**\r\n * Codex is the main class for interacting with the Codex agent.\r\n *\r\n * Use the `startThread()` method to start a new thread or `resumeThread()` to resume a previously started thread.\r\n */\r\nexport class Codex {\r\n private exec: CodexExec;\r\n private options: CodexOptions;\r\n\r\n constructor(options: CodexOptions = {}) {\r\n this.exec = new CodexExec(options.codexPathOverride, options.env);\r\n this.options = options;\r\n }\r\n\r\n /**\r\n * Starts a new conversation with an agent.\r\n * @returns A new thread instance.\r\n */\r\n startThread(options: ThreadOptions = {}): Thread {\r\n return new Thread(this.exec, this.options, options);\r\n }\r\n\r\n /**\r\n * Resumes a conversation with an agent based on the thread id.\r\n * Threads are persisted in ~/.codex/sessions.\r\n *\r\n * @param id The id of the thread to resume.\r\n * @returns A new thread instance.\r\n */\r\n resumeThread(id: string, options: ThreadOptions = {}): Thread {\r\n return new Thread(this.exec, this.options, options, id);\r\n }\r\n}\r\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,YAA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AS,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
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-nd-co/codex-sdk",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "TypeScript SDK for Codex APIs.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/ai-nd-co/codex.git",
|
|
8
|
+
"directory": "sdk/typescript"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"openai",
|
|
12
|
+
"codex",
|
|
13
|
+
"sdk",
|
|
14
|
+
"typescript",
|
|
15
|
+
"api"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"vendor"
|
|
36
|
+
],
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"build:watch": "tsup --watch",
|
|
42
|
+
"lint": "pnpm eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
43
|
+
"lint:fix": "pnpm eslint --fix \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
44
|
+
"test": "jest",
|
|
45
|
+
"test:watch": "jest --watch",
|
|
46
|
+
"coverage": "jest --coverage",
|
|
47
|
+
"format": "prettier --check .",
|
|
48
|
+
"format:fix": "prettier --write ."
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.24.0",
|
|
52
|
+
"@types/jest": "^29.5.14",
|
|
53
|
+
"@types/node": "^20.19.18",
|
|
54
|
+
"eslint": "^9.36.0",
|
|
55
|
+
"eslint-config-prettier": "^9.1.2",
|
|
56
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
57
|
+
"eslint-plugin-node-import": "^1.0.5",
|
|
58
|
+
"jest": "^29.7.0",
|
|
59
|
+
"prettier": "^3.6.2",
|
|
60
|
+
"ts-jest": "^29.3.4",
|
|
61
|
+
"ts-jest-mock-import-meta": "^1.3.1",
|
|
62
|
+
"ts-node": "^10.9.2",
|
|
63
|
+
"tsup": "^8.5.0",
|
|
64
|
+
"typescript": "^5.9.2",
|
|
65
|
+
"typescript-eslint": "^8.45.0",
|
|
66
|
+
"zod": "^3.24.2",
|
|
67
|
+
"zod-to-json-schema": "^3.24.6"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
Binary file
|
|
Binary file
|