Skip to content

feat(api): add RequestConfigBuilder + completePrompt signal/timeout tests for all providers#711

Closed
easonLiangWorldedtech wants to merge 4 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:feat/abort-signal-core/complete-prompt-abort
Closed

feat(api): add RequestConfigBuilder + completePrompt signal/timeout tests for all providers#711
easonLiangWorldedtech wants to merge 4 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:feat/abort-signal-core/complete-prompt-abort

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR builds on top of the abort signal core plumbing (#674) and adds:

  • RequestConfigBuilder — A new SDK-agnostic request configuration class that unifies timeout, signal, and provider-specific options across all API providers.
  • Complete prompt signal/timeout tests — Comprehensive test coverage for all 25 providers verifying completePrompt signal passing and timeout behavior.
  • Config builder documentation — Enhanced README with generic architecture design and multi-SDK usage examples.

Changes

Area Description
src/api/providers/config-builder/ New RequestConfigBuilder class + README
src/api/providers/*.ts Updated all 25 providers to use the new config builder
src/api/providers/__tests__/ Added completePrompt signal/timeout tests for every provider

Test Plan

  • All unit tests pass (25 provider test files updated)
  • Config builder README validates correctly
  • CI checks pass

Summary by CodeRabbit

  • New Features

    • Single-prompt completion now supports optional cancellation and timeout settings.
    • Added a reusable request configuration builder for composing request options.
    • Expanded provider support so more completion flows can accept the same optional settings.
  • Bug Fixes

    • Completed requests now consistently handle omitted options without breaking existing behavior.
    • Improved request cancellation handling across supported providers.

…nfiguration

Body: Implement generic request configuration builder with chainable methods (addAbortSignal, addHeaders, setOption), static factory methods (fromMetadata, mergeAbortSignals), and 40 unit tests.
…ls early-abort

- Fix README TOC: change #how-mergesignals-works to
  #how-mergeabortsignals-works to match the actual heading anchor
- Simplify mergeAbortSignals: return primarySignal directly when it's
  already aborted instead of creating a new AbortController
…roviders

Add comprehensive test coverage for the updated completePrompt interface that
now accepts CompletePromptOptions { signal?, timeoutMs? }. Each provider spec
includes signal passthrough, timeout passthrough, and backward compatible tests.

Updated implementations:
- requesty.ts: add options parameter support for signal/timeout

Test patterns by provider type:
- OpenAI Client Pattern: signal + timeout as second argument
- Anthropic SDK Pattern: signal as third argument
- Responses API: signal as second argument
- AI SDK (generateText): signal in options object
- VSCode LM: bridge AbortSignal to CancellationToken
- Bedrock: pass abortSignal to client.send
- Gemini: httpOptions.signal in config
- OpenAI Native: merge signals with RequestConfigBuilder
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eb6b91f6-81e5-411e-9de8-381ad5c96f8b

📥 Commits

Reviewing files that changed from the base of the PR and between e8acc6a and fe4adfc.

📒 Files selected for processing (60)
  • src/api/index.ts
  • src/api/providers/__tests__/anthropic-vertex.spec.ts
  • src/api/providers/__tests__/anthropic.spec.ts
  • src/api/providers/__tests__/bedrock.spec.ts
  • src/api/providers/__tests__/complete-prompt-options.spec.ts
  • src/api/providers/__tests__/deepseek.spec.ts
  • src/api/providers/__tests__/fireworks.spec.ts
  • src/api/providers/__tests__/gemini-handler.spec.ts
  • src/api/providers/__tests__/gemini.spec.ts
  • src/api/providers/__tests__/lite-llm.spec.ts
  • src/api/providers/__tests__/lmstudio.spec.ts
  • src/api/providers/__tests__/mimo.spec.ts
  • src/api/providers/__tests__/minimax.spec.ts
  • src/api/providers/__tests__/mistral.spec.ts
  • src/api/providers/__tests__/moonshot.spec.ts
  • src/api/providers/__tests__/native-ollama.spec.ts
  • src/api/providers/__tests__/openai-codex-native-tool-calls.spec.ts
  • src/api/providers/__tests__/openai-native.spec.ts
  • src/api/providers/__tests__/openai.spec.ts
  • src/api/providers/__tests__/opencode-go.spec.ts
  • src/api/providers/__tests__/openrouter.spec.ts
  • src/api/providers/__tests__/poe.spec.ts
  • src/api/providers/__tests__/request-config-builder.spec.ts
  • src/api/providers/__tests__/requesty.spec.ts
  • src/api/providers/__tests__/sambanova.spec.ts
  • src/api/providers/__tests__/unbound.spec.ts
  • src/api/providers/__tests__/vercel-ai-gateway.spec.ts
  • src/api/providers/__tests__/vertex.spec.ts
  • src/api/providers/__tests__/vscode-lm.spec.ts
  • src/api/providers/__tests__/xai.spec.ts
  • src/api/providers/__tests__/zai.spec.ts
  • src/api/providers/__tests__/zoo-gateway.spec.ts
  • src/api/providers/anthropic-vertex.ts
  • src/api/providers/anthropic.ts
  • src/api/providers/base-openai-compatible-provider.ts
  • src/api/providers/bedrock.ts
  • src/api/providers/config-builder/README.md
  • src/api/providers/config-builder/request-config-builder.ts
  • src/api/providers/fake-ai.ts
  • src/api/providers/gemini.ts
  • src/api/providers/index.ts
  • src/api/providers/lite-llm.ts
  • src/api/providers/lm-studio.ts
  • src/api/providers/minimax.ts
  • src/api/providers/mistral.ts
  • src/api/providers/native-ollama.ts
  • src/api/providers/openai-codex.ts
  • src/api/providers/openai-compatible.ts
  • src/api/providers/openai-native.ts
  • src/api/providers/openai.ts
  • src/api/providers/opencode-go.ts
  • src/api/providers/openrouter.ts
  • src/api/providers/poe.ts
  • src/api/providers/requesty.ts
  • src/api/providers/unbound.ts
  • src/api/providers/vercel-ai-gateway.ts
  • src/api/providers/vscode-lm.ts
  • src/api/providers/xai.ts
  • src/api/providers/zoo-gateway.ts
  • src/utils/single-completion-handler.ts

📝 Walkthrough

Walkthrough

Adds a CompletePromptOptions interface with optional signal: AbortSignal and timeoutMs: number fields. Updates SingleCompletionHandler.completePrompt and all provider handler implementations across ~25 providers to accept and forward these options. Introduces a new generic RequestConfigBuilder utility for fluent request option construction and abort-signal merging, with full test coverage across all affected providers.

Changes

completePrompt options propagation across all providers

Layer / File(s) Summary
CompletePromptOptions contract and public API surface
src/api/index.ts, src/utils/single-completion-handler.ts, src/api/providers/fake-ai.ts, src/api/providers/__tests__/complete-prompt-options.spec.ts
Exports the CompletePromptOptions interface with optional signal and timeoutMs; extends SingleCompletionHandler.completePrompt and singleCompletionHandler to accept and forward the new options argument; updates FakeAI/FakeAIHandler interface and implementation; adds type behavior tests.
RequestConfigBuilder utility
src/api/providers/config-builder/request-config-builder.ts, src/api/providers/config-builder/README.md, src/api/providers/index.ts, src/api/providers/__tests__/request-config-builder.spec.ts
Adds generic RequestConfigBuilder<TOptions> with fluent addAbortSignal, addHeaders, setOption, getOption, build methods; static fromMetadata and mergeAbortSignals helpers; re-exports from providers index; README documentation; 461-line Vitest test suite.
OpenAI-family provider implementations
src/api/providers/base-openai-compatible-provider.ts, src/api/providers/openai.ts, src/api/providers/openai-native.ts, src/api/providers/openai-codex.ts, src/api/providers/openai-compatible.ts, src/api/providers/openrouter.ts, src/api/providers/requesty.ts, src/api/providers/unbound.ts, src/api/providers/vercel-ai-gateway.ts, src/api/providers/zoo-gateway.ts, src/api/providers/lm-studio.ts, src/api/providers/lite-llm.ts
Updates completePrompt in all OpenAI-compatible providers to accept CompletePromptOptions and construct OpenAI.RequestOptions from signal/timeoutMs; openai-native and openai-codex use RequestConfigBuilder.mergeAbortSignals to combine caller signal with the handler's existing abort controller.
Non-OpenAI provider implementations
src/api/providers/anthropic.ts, src/api/providers/anthropic-vertex.ts, src/api/providers/gemini.ts, src/api/providers/bedrock.ts, src/api/providers/mistral.ts, src/api/providers/minimax.ts, src/api/providers/xai.ts, src/api/providers/opencode-go.ts, src/api/providers/poe.ts, src/api/providers/openai-compatible.ts, src/api/providers/native-ollama.ts, src/api/providers/vscode-lm.ts
Updates completePrompt in Anthropic, Gemini, Bedrock (via abortSignal), Mistral, MiniMax, xAI, OpenCode-Go, Poe, and OpenAI-Compatible providers; NativeOllamaHandler accepts but ignores the parameter; VsCodeLmHandler bridges AbortSignal to VS Code CancellationTokenSource.
OpenAI-family provider tests
src/api/providers/__tests__/anthropic.spec.ts, src/api/providers/__tests__/anthropic-vertex.spec.ts, src/api/providers/__tests__/openai.spec.ts, src/api/providers/__tests__/openai-native.spec.ts, src/api/providers/__tests__/openai-codex-native-tool-calls.spec.ts, src/api/providers/__tests__/openrouter.spec.ts, src/api/providers/__tests__/requesty.spec.ts, src/api/providers/__tests__/unbound.spec.ts, src/api/providers/__tests__/vercel-ai-gateway.spec.ts, src/api/providers/__tests__/zoo-gateway.spec.ts, src/api/providers/__tests__/lmstudio.spec.ts, src/api/providers/__tests__/lite-llm.spec.ts, src/api/providers/__tests__/deepseek.spec.ts, src/api/providers/__tests__/fireworks.spec.ts, src/api/providers/__tests__/mimo.spec.ts, src/api/providers/__tests__/sambanova.spec.ts, src/api/providers/__tests__/zai.spec.ts, src/api/providers/__tests__/opencode-go.spec.ts
Adds and updates completePrompt tests verifying signal/timeoutMs forwarding to the underlying SDK calls and backward compatibility across all OpenAI-family providers.
Non-OpenAI provider tests
src/api/providers/__tests__/bedrock.spec.ts, src/api/providers/__tests__/gemini.spec.ts, src/api/providers/__tests__/gemini-handler.spec.ts, src/api/providers/__tests__/vertex.spec.ts, src/api/providers/__tests__/mistral.spec.ts, src/api/providers/__tests__/minimax.spec.ts, src/api/providers/__tests__/xai.spec.ts, src/api/providers/__tests__/poe.spec.ts, src/api/providers/__tests__/moonshot.spec.ts, src/api/providers/__tests__/native-ollama.spec.ts, src/api/providers/__tests__/vscode-lm.spec.ts
Adds completePrompt tests for signal propagation (including VS Code CancellationTokenSource bridging, Bedrock abortSignal, Gemini httpOptions.signal) and backward compatibility across non-OpenAI providers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Zoo-Code-Org/Zoo-Code#344: Initial ZooGatewayHandler implementation where completePrompt accepted only prompt; this PR builds directly on that by adding signal/timeoutMs forwarding via createOptions.
  • Zoo-Code-Org/Zoo-Code#652: Rewrites OpencodeGoHandler.completePrompt to route between OpenAI-compatible and Anthropic formats; this PR extends that same method to accept and propagate CompletePromptOptions.
  • Zoo-Code-Org/Zoo-Code#386: Modifies AwsBedrockHandler.completePrompt for adaptive-thinking payloads; this PR adds the options forwarding (abort signal) to the same method.

Suggested labels

awaiting-review

Suggested reviewers

  • taltas
  • JamesRobert20
  • navedmerchant
  • hannesrudolph
  • edelauna

Poem

🐇 Hop hop, a signal now flows through the wire,
Each provider can cancel when callers require,
AbortSignal and timeoutMs dance hand in paw,
RequestConfigBuilder merges them all without flaw,
Twenty-five handlers updated with glee—
No prompt left stranded, the rabbit hops free! 🎉

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants