Skip to content

refactor(providers): use extractReasoningFromDelta helper for reasoni…#588

Open
daewoongoh wants to merge 3 commits into
Zoo-Code-Org:mainfrom
daewoongoh:refactor/use-extract-reasoning-helper
Open

refactor(providers): use extractReasoningFromDelta helper for reasoni…#588
daewoongoh wants to merge 3 commits into
Zoo-Code-Org:mainfrom
daewoongoh:refactor/use-extract-reasoning-helper

Conversation

@daewoongoh

@daewoongoh daewoongoh commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Related GitHub Issue

#570

Description

This PR replaces duplicated inline reasoning-delta extraction logic across seven providers with the shared extractReasoningFromDelta helper.

Affected providers:

  • deepseek
  • mimo
  • openai
  • opencode-go
  • qwen-code
  • requesty
  • unbound

Previously, each provider had a near-identical streaming check for delta.reasoning_content and emitted reasoning chunks inline. Since src/api/providers/utils/extract-reasoning.ts already provides the canonical extraction behavior and is already used by other OpenAI-compatible providers, this PR brings the remaining duplicated call sites in line with the shared implementation.

Test Procedure

cd src && npx vitest run api/providers/__tests__/

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
    Existing tests cover the changed provider behavior, and the shared helper is already test-covered.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A

Documentation Updates

  • No documentation updates are required.

Additional Notes

This is a focused provider refactor. It removes duplicated reasoning extraction logic and routes all seven affected providers through the shared extractReasoningFromDelta helper.

The intended behavior for existing reasoning_content chunks is unchanged for normal string payloads. The practical improvement is that these providers now also handle the reasoning fallback supported by the helper, so future or model-specific deltas using that field will stream reasoning text instead of being ignored.

Get in Touch

hehegwk_23849

Summary by CodeRabbit

  • Refactor
    • Consolidated reasoning extraction so streamed "reasoning" output is detected and emitted consistently across AI provider integrations.
  • Tests
    • Added unit tests to verify streamed reasoning chunks are produced and fallback correctly when primary fields are absent.

Oh Daewoong and others added 2 commits June 12, 2026 13:18
…ng streams

Replace duplicated reasoning_content extraction logic across 7 providers
(deepseek, mimo, openai, opencode-go, qwen-code, requesty, unbound) with
the shared extractReasoningFromDelta helper. This also adds the OpenRouter-
style 'reasoning' field fallback to each provider for free.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 083b062e-435a-4b17-851a-685c7101de58

📥 Commits

Reviewing files that changed from the base of the PR and between 9bf62ed and 869d952.

📒 Files selected for processing (3)
  • src/api/providers/__tests__/openai.spec.ts
  • src/api/providers/__tests__/requesty.spec.ts
  • src/api/providers/__tests__/unbound.spec.ts

📝 Walkthrough

Walkthrough

Provider streaming handlers (DeepSeek, MiMo, OpenAI, Opencode-Go, Qwen-Code, Requesty, Unbound) now import and use extractReasoningFromDelta(delta) to emit { type: "reasoning", text } chunks when present; tests were added to verify extraction and fallback from delta.reasoning_content to delta.reasoning.

Changes

Consolidate Reasoning Extraction Helper Adoption

Layer / File(s) Summary
Add shared helper imports
src/api/providers/deepseek.ts, src/api/providers/mimo.ts, src/api/providers/openai.ts, src/api/providers/opencode-go.ts, src/api/providers/qwen-code.ts, src/api/providers/requesty.ts, src/api/providers/unbound.ts
Each provider adds an import for extractReasoningFromDelta from the local utils module.
Replace inline extraction with helper and add tests
src/api/providers/deepseek.ts, src/api/providers/mimo.ts, src/api/providers/openai.ts, src/api/providers/opencode-go.ts, src/api/providers/qwen-code.ts, src/api/providers/requesty.ts, src/api/providers/unbound.ts, src/api/providers/__tests__/openai.spec.ts, src/api/providers/__tests__/requesty.spec.ts, src/api/providers/__tests__/unbound.spec.ts
Streaming handlers now call extractReasoningFromDelta(delta) and yield { type: "reasoning", text } only when non-empty. New tests validate emission from delta.reasoning_content and fallback to delta.reasoning.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • taltas
  • navedmerchant
  • hannesrudolph
  • edelauna
  • JamesRobert20

Poem

🐰 I hopped through deltas, soft and keen,
Shared the thinking that had been unseen.
From scattered checks to one small art,
Reasoning gathered, whole not parts.
Cheers from a rabbit — tidy code, smart! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly refers to the main refactoring effort of consolidating reasoning extraction logic, but is truncated and lacks complete context about the scope.
Description check ✅ Passed Description includes all required template sections: linked issue (#570), implementation details with affected providers, test procedure, completed checklist items, and documentation considerations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 timed out. The project may have too many dependencies for the sandbox.


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 and usage tips.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Add streaming tests for openai, requesty, and unbound covering:
- delta.reasoning_content yields a reasoning chunk
- delta.reasoning fallback yields a reasoning chunk when reasoning_content
  is absent (OpenRouter-style)

This raises line coverage on the changed reasoning paths from 50%.
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.

1 participant