feat: add images support to the Codex Typescript SDK (#5281)
Extend `run` and `runStreamed` input to be either a `string` or
structured input. A structured input is an array of text parts and/or
image paths, which will then be fed to the CLI through the `--image`
argument. Text parts are combined with double newlines. For instance:
```ts
const turn = await thread.run([
{ type: "text", text: "Describe these screenshots" },
{ type: "local_image", path: "./ui.png" },
{ type: "local_image", path: "./diagram.jpg" },
{ type: "text", text: "Thanks!" },
]);
```
Ends up launching the CLI with:
```
codex exec --image foo.png --image bar.png "Describe these screenshots\n\nThanks!"
```
The complete `Input` type for both function now is:
```ts
export type UserInput =
| {
type: "text";
text: string;
}
| {
type: "local_image";
path: string;
};
export type Input = string | UserInput[];
```
This brings the Codex SDK closer to feature parity with the CLI.
Adresses #5280 .
This commit is contained in:
@@ -83,6 +83,18 @@ const turn = await thread.run("Summarize repository status", {
|
||||
console.log(turn.finalResponse);
|
||||
```
|
||||
|
||||
### Attaching images
|
||||
|
||||
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`.
|
||||
|
||||
```typescript
|
||||
const turn = await thread.run([
|
||||
{ type: "text", text: "Describe these screenshots" },
|
||||
{ type: "local_image", path: "./ui.png" },
|
||||
{ type: "local_image", path: "./diagram.jpg" },
|
||||
]);
|
||||
```
|
||||
|
||||
### Resuming an existing thread
|
||||
|
||||
Threads are persisted in `~/.codex/sessions`. If you lose the in-memory `Thread` object, reconstruct it with `resumeThread()` and keep going.
|
||||
@@ -95,7 +107,7 @@ await thread.run("Implement the fix");
|
||||
|
||||
### Working directory controls
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
```typescript
|
||||
const thread = codex.startThread({
|
||||
|
||||
Reference in New Issue
Block a user