Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 10, 2026

Summary

Migrates the Qwen Code provider (QwenCodeHandler) from manual OpenAI SDK streaming to the Vercel AI SDK via OpenAICompatibleHandler (Archetype 1 migration per plans/ai-sdk-migration-guide.md).

Changes

  • Base class: BaseProviderOpenAICompatibleHandler using @ai-sdk/openai-compatible
  • Streaming: Manual SSE/delta assembly → streamText() + processAiSdkStreamPart()
  • Reasoning: Manual <think> tag parsing → extractReasoningMiddleware({ tagName: "think" })
  • Tools: NativeToolCallParser + manual deltas → AI SDK native tool handling
  • Messages: convertToOpenAiMessagesconvertToAiSdkMessages
  • Errors: Raw OpenAI errors → handleAiSdkError()
  • OAuth: Fully preserved — dynamic getLanguageModel() creates fresh provider with current OAuth credentials per request; createMessage() and completePrompt() both include 401 retry
  • isAiSdkProvider(): Returns true (inherited from OpenAICompatibleHandler)
  • Tests: Rewritten to mock AI SDK instead of OpenAI SDK (11 tests, all passing)

Breaking Change Audit

All potential breaking changes were investigated and resolved:

Finding Verdict
Text dedup guard removed ✅ Non-issue — DashScope compatible-mode API uses standard incremental deltas
isAiSdkProvider() flips true ✅ Correct behavior — reasoning preserved as intended for AI SDK providers
includeUsage not explicit ✅ Non-issue — @ai-sdk/openai-compatible handles internally

Removed Dependencies (from this file)

  • openai SDK direct usage
  • convertToOpenAiMessages from openai-format.ts (reduces consumer count from 8 → 7)
  • NativeToolCallParser import

Important

Refactor Qwen Code provider to use Vercel AI SDK, updating OAuth handling and tests.

  • Migration:
    • Refactor QwenCodeHandler to extend OpenAICompatibleHandler using Vercel AI SDK.
    • Replace manual SSE/delta handling with streamText() and processAiSdkStreamPart().
    • Use extractReasoningMiddleware for reasoning tag parsing.
    • Replace NativeToolCallParser with AI SDK native tool handling.
    • Convert messages using convertToAiSdkMessages.
    • Handle errors with handleAiSdkError().
  • OAuth Handling:
    • Load and refresh OAuth credentials dynamically in qwen-code.ts.
    • Implement forceRefreshAndAuthenticate() for token refresh.
    • Use safeWriteJson for saving refreshed credentials.
  • Tests:
    • Update tests in qwen-code-native-tools.spec.ts to mock AI SDK instead of OpenAI SDK.
    • Add tests for OAuth credential loading and token refresh.
  • Misc:
    • Remove direct openai SDK usage.
    • Remove convertToOpenAiMessages dependency.

This description was created by Ellipsis for c784551. You can customize this summary. It will automatically update as commits are pushed.

…ndler

Replace manual OpenAI SDK streaming with Vercel AI SDK:
- Extend OpenAICompatibleHandler instead of BaseProvider
- Use @ai-sdk/openai-compatible with dynamic OAuth credentials
- Replace manual <think> tag parsing with extractReasoningMiddleware
- Remove NativeToolCallParser and manual tool call delta assembly
- Use convertToAiSdkMessages, processAiSdkStreamPart, handleAiSdkError
- Preserve full OAuth lifecycle (load, refresh, 401 retry)
- Override getLanguageModel() for per-request fresh provider creation
- Rewrite tests to mock AI SDK instead of OpenAI SDK (11 tests)
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Feb 10, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 10, 2026

Rooviewer Clock   See task

Review complete. No issues found. The latest commit correctly normalizes test path assertions with path.resolve() to match getQwenCachedCredentialPath() behavior, fixing Windows CI compatibility.

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Feb 10, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 10, 2026
@hannesrudolph hannesrudolph merged commit 938e699 into main Feb 10, 2026
10 checks passed
@hannesrudolph hannesrudolph deleted the refactor/migrate-qwen-code-to-ai-sdk branch February 10, 2026 01:45
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants