Commit Graph

4 Commits

  • 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>
  • 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
  • SDK CI (#4483)
    Build debug codex in SDK configuration