Skip to content

feat: support Command Code Provider Chat Completions API - #22

Merged
Mars-Sea merged 3 commits into
Mars-Sea:mainfrom
hachimi-ak-ioi:feat/provider-api-endpoint-selection
Sep 5, 2026
Merged

feat: support Command Code Provider Chat Completions API#22
Mars-Sea merged 3 commits into
Mars-Sea:mainfrom
hachimi-ak-ioi:feat/provider-api-endpoint-selection

Conversation

@hachimi-ak-ioi

Copy link
Copy Markdown
Contributor

Summary

Adds support for the documented /provider/v1/chat/completions endpoint as the preferred chat transport for accounts with Provider API access.

  • Auto-selects Chat Completions by default; falls back to the legacy /alpha/generate only when Provider API returns 403 upgrade_required (Go plan).
  • Adds a per-account protocol cache so a Go-plan rejection does not pay the double TTFT on every request.
  • Chat Completions path uses a flat OpenAI-compatible request body.
  • Chat Completions path replays historical reasoning as reasoning_content, which DeepSeek's thinking-mode/tool-loop contract requires.
  • Parses OpenAI SSE reasoning / reasoning_content / content / tool_calls / usage into dsh StreamChunk.
  • Keeps the legacy /alpha/generate transport and its existing no-reasoning-replay behavior unchanged.

Testing

  • npm run typecheck
  • npm test (292 passing)
  • npm run build
  • Added unit tests for OpenAI body construction with reasoning_content replay, OpenAI SSE reasoning/content/tool-call parsing, and auto fallback/caching on upgrade_required.

Closes discussion in #19 about Plan-type based endpoint selection.

Use the documented /provider/v1/chat/completions transport for accounts
with Provider API access, falling back to /alpha/generate only when the
Provider API returns upgrade_required (Go plan).

The Chat Completions transport:
- sends a flat OpenAI-compatible request body
- replays historical reasoning as reasoning_content (DeepSeek thinking-mode
  tool-loop requirement)
- parses OpenAI SSE reasoning/content/tool_calls/usage into StreamChunks
- keeps the legacy /alpha/generate transport unchanged, including its
  existing no-reasoning-replay behavior

Includes protocol selection with per-account cache and unit tests.
Copilot AI lite review requested due to automatic review settings September 4, 2026 23:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Mars-Sea
Mars-Sea merged commit c684d8e into Mars-Sea:main Sep 5, 2026
5 checks passed
@hachimi-ak-ioi
hachimi-ak-ioi deleted the feat/provider-api-endpoint-selection branch September 5, 2026 02:47
@hachimi-ak-ioi
hachimi-ak-ioi restored the feat/provider-api-endpoint-selection branch September 5, 2026 02:48
Mars-Sea added a commit that referenced this pull request Sep 7, 2026
…mmand-code@1.50.0 sync

- feat: support Command Code Provider Chat Completions API (#22): use the
  documented POST /provider/v1/chat/completions transport for accounts with
  Provider API access, falling back to /alpha/generate only on
  upgrade_required (Go plan). Historical reasoning replays as
  reasoning_content; OpenAI SSE parsed into StreamChunks. Legacy transport
  unchanged, including no-reasoning-replay.
- fix: remap overlong cross-provider tool-call ids to the gateway limit
  (#23): mid-session switches from another provider replay that provider's
  tool ids verbatim; ids longer than 64 chars are rejected mid-stream
  (input[N].call_id must be <= 64). Both transports remap overlong paired
  ids to short per-request aliases (cc-1, cc-2, ...), correlated across
  call/result; ids within the limit pass through unchanged.
- chore: sync with the official command-code@1.50.0 CLI (2026-09-06):
  COMMAND_CODE_CLI_VERSION is now 1.50.0, re-verified with no snapshot
  changes (efforts, vision, thinking, plans, subscription maps, deals,
  peak/off-peak windows all identical to 1.49.1).
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.

3 participants