Skip to content

feat(qwen): migrate Qwen provider to AI SDK#11190

Closed
daniel-lxs wants to merge 1 commit intomainfrom
feature/ext-712-migrate-qwen-to-ai-sdk
Closed

feat(qwen): migrate Qwen provider to AI SDK#11190
daniel-lxs wants to merge 1 commit intomainfrom
feature/ext-712-migrate-qwen-to-ai-sdk

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Feb 4, 2026

Summary

Migrates the Qwen Code provider to use the Vercel AI SDK (@ai-sdk/openai-compatible) instead of the direct OpenAI SDK.

Changes

src/api/providers/qwen-code.ts

  • Replaced direct OpenAI SDK usage with @ai-sdk/openai-compatible's createOpenAICompatible
  • Now uses streamText and generateText from the ai package for streaming and completion
  • Uses shared transform utilities (convertToAiSdkMessages, convertToolsForAiSdk, processAiSdkStreamPart, mapToolChoice)
  • Maintains OAuth credential management with automatic token refresh
  • Provider is lazily created and recreated when credentials change
  • Added getModelParams integration for proper model parameter handling

src/api/providers/__tests__/qwen-code-native-tools.spec.ts

  • Updated mocks to use AI SDK mocking patterns (mockStreamText, mockGenerateText)
  • Added mock for @ai-sdk/openai-compatible's createOpenAICompatible
  • Updated test events to use AI SDK stream event types (tool-input-start, tool-input-delta, tool-input-end, reasoning)

Benefits

  • Consistent with other AI SDK-based providers (DeepSeek, Moonshot, HuggingFace)
  • Uses shared transform utilities for message and tool conversion
  • Proper handling of tool calls via AI SDK's tool streaming events
  • Reasoning content handled via AI SDK's reasoning events
  • Maintains backward compatibility with existing OAuth credential flow

Testing

  • All 13 tests pass
  • Lint passes
  • TypeScript compilation passes

Resolves EXT-712


Important

Migrates Qwen Code provider to Vercel AI SDK, updating message handling, tool integration, and OAuth management.

  • Behavior:
    • Migrates Qwen Code provider in qwen-code.ts to use Vercel AI SDK (@ai-sdk/openai-compatible) instead of OpenAI SDK.
    • Uses streamText and generateText for streaming and completion.
    • Integrates getModelParams for model parameter handling.
    • Maintains OAuth credential management with automatic token refresh.
    • Provider is lazily created and recreated when credentials change.
  • Tests:
    • Updates qwen-code-native-tools.spec.ts to use AI SDK mocking patterns (mockStreamText, mockGenerateText).
    • Adds mock for createOpenAICompatible.
    • Updates test events to use AI SDK stream event types (tool-input-start, tool-input-delta, tool-input-end, reasoning).
  • Misc:
    • Uses shared transform utilities for message and tool conversion.
    • Handles tool calls via AI SDK's tool streaming events.
    • Handles reasoning content via AI SDK's reasoning events.

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

- Replace direct OpenAI SDK usage with @ai-sdk/openai-compatible
- Use streamText and generateText from ai package for streaming/completion
- Integrate shared transform utilities for message/tool conversion
- Maintain OAuth credential management with automatic token refresh
- Update tests to use AI SDK mocking patterns

Resolves EXT-712
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners February 4, 2026 17:06
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels Feb 4, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 4, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. Found 1 issue to address:

  • Add error?.status === 401 to the 401 error detection check in createMessage and completePrompt methods (AI SDK uses .status as the primary property for AI_APICallError)

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

}
} catch (error: any) {
// Handle 401 errors by refreshing token and retrying once
if (error?.statusCode === 401 || error?.response?.status === 401) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The 401 error detection may not work correctly with AI SDK errors. AI_APICallError uses .status as its primary property, and AI_RetryError exposes it via .lastError?.status. The current check only looks at .statusCode and .response?.status, which means token refresh may not trigger when the API returns 401.

Suggested change
if (error?.statusCode === 401 || error?.response?.status === 401) {
if (error?.status === 401 || error?.statusCode === 401 || error?.response?.status === 401) {

The same pattern applies to the completePrompt method at line 347.

Fix it with Roo Code or mention @roomote and request a fix.

@daniel-lxs
Copy link
Member Author

This is Qwen Code not Qwen itself

@daniel-lxs daniel-lxs closed this Feb 4, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Feb 4, 2026
@daniel-lxs daniel-lxs deleted the feature/ext-712-migrate-qwen-to-ai-sdk branch February 4, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant