Commit Graph

27 Commits

  • fix: ensure resume args precede image args (#10709)
    ## Summary
    Fixes argument ordering when `resumeThread()` is used with
    `local_image`. The SDK previously emitted CLI args with `--image` before
    `resume <threadId>`, which caused the Codex CLI to treat `resume`/UUID
    as image paths and start a new session. This PR moves `resume
    <threadId>` before any `--image` flags and adds a regression test.
    
    ## Bug Report / Links
    - OpenAI issue: https://github.com/openai/codex/issues/10708
    - Repro repo:
    https://github.com/cryptonerdcn/codex-resume-local-image-repro
    - Repro issue (repo):
    https://github.com/cryptonerdcn/codex-resume-local-image-repro/issues/1
    
    ## Repro (pre-fix)
    1. Build SDK from source
    2. Run resume + local_image
    3. Args order: `--image <path> resume <id>`
    4. Result: new session created (thread id changes)
    
    ## Fix
    Move `resume <threadId>` before `--image` in `CodexExec.run` and add a
    regression test to assert ordering.
    
    ## Tests
    - `cd sdk/typescript && npm test`
      - **Failed**: `codex-rs/target/debug/codex` missing (ENOENT)
    
    ## Notes
    - I can rerun tests in an environment with `codex-rs` built and report
    results.
  • feat: make it possible to specify --config flags in the SDK (#10003)
    Updates the `CodexOptions` passed to the `Codex()` constructor in the
    SDK to support a `config` property that is a map of configuration data
    that will be transformed into `--config` flags passed to the invocation
    of `codex`.
    
    Therefore, something like this:
    
    ```typescript
    const codex = new Codex({
      config: {
        show_raw_agent_reasoning: true,
        sandbox_workspace_write: { network_access: true },
      },
    });
    ```
    
    would result in the following args being added to the invocation of
    `codex`:
    
    ```shell
    --config show_raw_agent_reasoning=true --config sandbox_workspace_write.network_access=true
    ```
  • add WebSearchMode enum (#9216)
    ### What
    Add `WebSearchMode` enum (disabled, cached live, defaults to cached) to
    config + V2 protocol. This enum takes precedence over legacy flags:
    `web_search_cached`, `web_search_request`, and `tools.web_search`.
    
    Keep `--search` as live.
    
    ### Tests
    Added tests
  • fix: handle early codex exec exit (#8825)
    Fixes CodexExec to avoid missing early process exits by registering the
    exit handler up front and deferring the error until after stdout is
    drained, and adds a regression test that simulates a fast-exit child
    while still producing output so hangs are caught.
  • feat(ts-sdk): allow overriding CLI environment (#6648)
    ## Summary
    - add an `env` option for the TypeScript Codex client and plumb it into
    `CodexExec` so the CLI can run without inheriting `process.env`
    - extend the test spy to capture spawn environments, add coverage for
    the new option, and document how to use it
    
    ## Testing
    - `pnpm test` *(fails: corepack cannot download pnpm because outbound
    network access is blocked in the sandbox)*
    
    ------
    [Codex
    Task](https://chatgpt.com/codex/tasks/task_i_6916b2d7c7548322a72d61d91a2dac85)
  • feat: Add support for --add-dir to exec and TypeScript SDK (#6565)
    ## Summary
    
    Adds support for specifying additional directories in the TypeScript SDK
    through a new `additionalDirectories` option in `ThreadOptions`.
    
    ## Changes
    
    - Added `additionalDirectories` parameter to `ThreadOptions` interface
    - Updated `CodexExec` to accept and pass through additional directories
    via the `--config` flag for `sandbox_workspace_write.writable_roots`
    - Added comprehensive test coverage for the new functionality
    
    ## Test plan
    
    - Added test case that verifies `additionalDirectories` is correctly
    passed as repeated flags
    - Existing tests continue to pass
    
    ---------
    
    Co-authored-by: Claude <noreply@anthropic.com>
  • Add AbortSignal support to TypeScript SDK (#6378)
    ## Summary
    Adds AbortSignal support to the TypeScript SDK for canceling thread
    execution using AbortController.
    
    ## Changes
    - Add `signal?: AbortSignal` property to `TurnOptions` type
    - Pass signal through Thread class methods to exec layer  
    - Add signal parameter to `CodexExecArgs`
    - Leverage Node.js native `spawn()` signal support for automatic
    cancellation
    - Add comprehensive test coverage (6 tests covering all abort scenarios)
    
    ## Implementation
    The implementation uses Node.js's built-in AbortSignal support in
    `spawn()` (available since Node v15, SDK requires >=18), which
    automatically handles:
    - Checking if already aborted before starting
    - Killing the child process when abort is triggered
    - Emitting appropriate error events
    - All cleanup operations
    
    This is a one-line change to the core implementation (`signal:
    args.signal` passed to spawn), making it simple, reliable, and
    maintainable.
    
    ## Usage Example
    ```typescript
    import { Codex } from '@openai/codex-sdk';
    
    const codex = new Codex({ apiKey: 'your-api-key' });
    const thread = codex.startThread();
    
    // Create AbortController
    const controller = new AbortController();
    
    // Run with abort signal
    const resultPromise = thread.run("Your prompt here", {
      signal: controller.signal
    });
    
    // Cancel anytime
    controller.abort('User requested cancellation');
    ```
    
    ## Testing
    All tests pass (23 total across SDK):
    -  Aborts when signal is already aborted (both run and runStreamed)
    -  Aborts during execution/iteration
    -  Completes normally when not aborted
    -  Backward compatible (signal is optional)
    
    Tests verified to fail correctly when signal support is removed (no
    false positives).
    
    ---------
    
    Co-authored-by: Claude <noreply@anthropic.com>
    Co-authored-by: pakrym-oai <pakrym@openai.com>
  • [SDK] Add network_access and web_search options to TypeScript SDK (#6367)
    ## Summary
    
    This PR adds two new optional boolean fields to `ThreadOptions` in the
    TypeScript SDK:
    
    - **`networkAccess`**: Enables network access in the sandbox by setting
    `sandbox_workspace_write.network_access` config
    - **`webSearch`**: Enables the web search tool by setting
    `tools.web_search` config
    
    These options map to existing Codex configuration options and are
    properly threaded through the SDK layers:
    1. `ThreadOptions` (threadOptions.ts) - User-facing API
    2. `CodexExecArgs` (exec.ts) - Internal execution args  
    3. CLI flags via `--config` in the `codex exec` command
    
    ## Changes
    
    - `sdk/typescript/src/threadOptions.ts`: Added `networkAccess` and
    `webSearch` fields to `ThreadOptions` type
    - `sdk/typescript/src/exec.ts`: Added fields to `CodexExecArgs` and CLI
    flag generation
    - `sdk/typescript/src/thread.ts`: Pass options through to exec layer
    
    ## Test Plan
    
    - [x] Build succeeds (`pnpm build`)
    - [x] Linter passes (`pnpm lint`)
    - [x] Type definitions are properly exported
    - [ ] Manual testing with sample code (to be done by reviewer)
    
    ---------
    
    Co-authored-by: Claude <noreply@anthropic.com>
  • Add modelReasoningEffort option to TypeScript SDK (#6237)
    ## Summary
    - Adds `ModelReasoningEffort` type to TypeScript SDK with values:
    `minimal`, `low`, `medium`, `high`
    - Adds `modelReasoningEffort` option to `ThreadOptions`
    - Forwards the option to the codex CLI via `--config
    model_reasoning_effort="<value>"`
    - Includes test coverage for the new option
    
    ## Changes
    - `sdk/typescript/src/threadOptions.ts`: Define `ModelReasoningEffort`
    type and add to `ThreadOptions`
    - `sdk/typescript/src/index.ts`: Export `ModelReasoningEffort` type
    - `sdk/typescript/src/exec.ts`: Forward `modelReasoningEffort` to CLI as
    config flag
    - `sdk/typescript/src/thread.ts`: Pass option through to exec (+ debug
    logging)
    - `sdk/typescript/tests/run.test.ts`: Add test for
    `modelReasoningEffort` flag forwarding
    
    ---------
    
    Co-authored-by: Eric Traut <etraut@openai.com>
  • Re-enable SDK image forwarding test (#5934)
    ## Summary
    - re-enable the TypeScript SDK test that verifies local images are
    forwarded to `codex exec`
    
    ## Testing
    - `pnpm test` *(fails: unable to download pnpm 10.8.1 because external
    network access is blocked in the sandbox)*
    
    ------
    https://chatgpt.com/codex/tasks/task_i_690289cb861083209fd006867e2adfb1
  • Skip flaky test (#5680)
    Did an investigation but couldn't find anything obvious. Let's skip for
    now.
  • 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 .
  • Set codex SDK TypeScript originator (#4894)
    ## Summary
    - ensure the TypeScript SDK sets CODEX_INTERNAL_ORIGINATOR_OVERRIDE to
    codex_sdk_ts when spawning the Codex CLI
    - extend the responses proxy test helper to capture request headers for
    assertions
    - add coverage that verifies Codex threads launched from the TypeScript
    SDK send the codex_sdk_ts originator header
    
    ## Testing
    - Not Run (not requested)
    
    
    ------
    https://chatgpt.com/codex/tasks/task_i_68e561b125248320a487f129093d16e7
  • Misc SDK fixes (#4752)
    Remove codex-level workingDirectory
    Throw on turn.failed in `run()`
    Cleanup readme
  • Expose turn token usage in the SDK (#4700)
    It's present on the event, add it to the final result as well.
  • Store settings on the thread instead of turn (#4579)
    It's much more common to keep the same settings for the entire
    conversation, we can add per-turn overrides later.
  • Add initial set of doc comments to the SDK (#4513)
    Also perform minor code cleanup.
  • Explicit node imports (#4567)
    To help with compatibility
  • SDK: support working directory and skipGitRepoCheck options (#4563)
    Make options not required, add support for working directory and
    skipGitRepoCheck options on the turn
  • Add executable detection and export Codex from the SDK (#4532)
    Executable detection uses the same rules as the codex wrapper.