Skip to content

[Fix] Restore adapter v1 endpoint and streaming compatibility#787

Merged
dingyi222666 merged 1 commit intov1-devfrom
fix/adapter-v1-bug
Mar 19, 2026
Merged

[Fix] Restore adapter v1 endpoint and streaming compatibility#787
dingyi222666 merged 1 commit intov1-devfrom
fix/adapter-v1-bug

Conversation

@dingyi222666
Copy link
Copy Markdown
Member

@dingyi222666 dingyi222666 commented Mar 19, 2026

This pr restores v1-compatible endpoint handling across shared and adapter-specific requesters, fixes Claude thinking model resolution, and preserves streamed message chunks that arrive as final message payloads.

New Features

  • Add human-readable middleware duration formatting for debug logs.
  • Add derived Claude thinking model aliases when the API exposes only base model names.

Bug fixes

  • Stop OpenAI-compatible adapters from appending duplicated /v1 or /v3 path segments.
  • Map generated Claude -thinking model names back to supported API models before requests are sent.
  • Handle stream responses that emit message payloads without delta chunks so content is not dropped.
  • Update RWKV defaults to use the expected /v1 endpoint.

Other Changes

  • Reuse shared URL concatenation logic in Doubao and RWKV requesters.
  • Cache available Claude model names inside the requester for request-time normalization.

Normalize requester URL handling so OpenAI-compatible adapters stop appending version prefixes twice, and map generated Claude thinking variants back to real API models when needed.

Also handle message-only stream chunks and readable timing logs so provider responses do not drop content and middleware latency is easier to inspect.

Affected: adapter-claude, adapter-doubao, adapter-rwkv, core, shared-adapter
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

概览

本PR对多个适配器和核心模块进行了改动,主要包括:为Claude适配器添加thinking模型变体处理和模型白名单机制、重构多个适配器的URL拼接逻辑、新增时间格式化工具函数、以及改进流式响应元数据事件处理。

变更清单

队列 / 文件 摘要
Claude适配器thinking模型处理
packages/adapter-claude/src/client.ts, packages/adapter-claude/src/requester.ts
添加了thinking模型变体的动态扩展和去重逻辑;引入THINKING_MODELS常量控制哪些基础模型应生成thinking变体;为ClaudeRequester添加模型白名单管理(_models集合和setModels()方法);更新thinking标志逻辑以基于模型名称是否包含thinking后缀;调整默认max_tokens从4096至10000;从fallbackModels移除claude-3-7-sonnet-thinking-20250219。
适配器URL拼接逻辑重构
packages/adapter-doubao/src/requester.ts, packages/adapter-rwkv/src/index.ts, packages/adapter-rwkv/src/requester.ts, packages/core/src/llm-core/platform/api.ts
移除了特定于/v1后缀检测的URL拼接逻辑,改为简化的端点拼接方式;更新RWKV默认API端点为http://127.0.0.1:8000/v1;多处调用方改为使用公共concatUrl而非私有_concatUrl。
时间格式化工具
packages/core/src/utils/time.ts
新增formatDuration函数,按量级自适应格式化毫秒值(ms/s/m h格式)。
日志和中间件
packages/core/src/chains/chain.ts
更新中间件执行时间日志,使用新的formatDuration函数替代直接传入毫秒数值。
流式响应处理
packages/shared-adapter/src/requester.ts
改进processStreamResponse对delta为null的元数据事件处理;新增reasoning_content的累积注入机制;统一使用getMessageContent提取文本内容。

序列图

不适用。本次变更主要为局部逻辑改进、工具函数添加和URL拼接简化,不涉及跨多组件的新功能流程。

估计代码审查工作量

🎯 3 (中等复杂) | ⏱️ ~25 分钟

相关PR

诗文

🐰 思想的兔子跳啊跳,
变体模型堆一堆,
清除重复如整理草料,
URL拼接更简洁,
时间格式花样多,
流式响应更通畅呀!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了PR的主要目的:恢复v1端点和流式兼容性,与详细的代码变更一致。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed 拉取请求描述与代码变更集密切相关,清晰地阐述了新功能、错误修复和其他改进。

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/adapter-v1-bug
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the robustness and compatibility of the adapter system. It addresses critical issues related to API endpoint versioning, particularly for OpenAI-compatible and specific adapters like RWKV and Doubao, by streamlining URL concatenation logic. Furthermore, it significantly improves the Claude adapter's model resolution, especially for 'thinking' models, and refines stream processing to ensure no data loss when full message payloads are received without delta chunks. These changes collectively aim to provide a more stable and predictable interaction with various LLM APIs.

Highlights

  • API Endpoint Compatibility: Restored v1-compatible endpoint handling across shared and adapter-specific requesters, ensuring correct API path construction.
  • Claude Model Resolution: Fixed Claude thinking model resolution by mapping generated thinking model names back to supported API models and introducing derived aliases.
  • Streaming Compatibility: Preserved streamed message chunks that arrive as final message payloads, preventing content from being dropped in stream responses.
  • Debug Logging: Added human-readable middleware duration formatting for debug logs to improve observability.
  • RWKV Default Endpoint: Updated RWKV defaults to use the expected /v1 endpoint for consistency.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a number of valuable fixes and improvements across the board. It successfully restores v1 endpoint compatibility, enhances Claude model handling by dynamically deriving "thinking" variants, and improves stream processing to prevent data loss. The refactoring to centralize URL concatenation logic and the addition of human-readable duration formatting for logs are also welcome changes that improve code quality and maintainability. I have one suggestion for improving code clarity.

Comment thread packages/adapter-claude/src/client.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/adapter-claude/src/client.ts (1)

214-219: 建议:THINKING_MODELS 常量可考虑内联

根据编码规范:"Do not define named constants unless the value is truly important and reused; inline literal values directly at call sites"。THINKING_MODELS 仅在一处使用。不过,考虑到这是支持 thinking 功能的模型前缀列表,将其作为常量有助于未来维护和更新,当前实现可以接受。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/adapter-claude/src/client.ts` around lines 214 - 219,
THINKING_MODELS is only used once so inline the literal array at its single call
site instead of keeping the named constant: remove the THINKING_MODELS
declaration and replace references to THINKING_MODELS with the array literal
['claude-3-7-sonnet-','claude-opus-4','claude-sonnet-4','claude-haiku-4-5']; if
you prefer to keep readability, alternatively leave THINKING_MODELS but add a
short comment explaining it represents supported thinking-model prefixes to
justify the named constant.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/adapter-claude/src/client.ts`:
- Around line 214-219: THINKING_MODELS is only used once so inline the literal
array at its single call site instead of keeping the named constant: remove the
THINKING_MODELS declaration and replace references to THINKING_MODELS with the
array literal
['claude-3-7-sonnet-','claude-opus-4','claude-sonnet-4','claude-haiku-4-5']; if
you prefer to keep readability, alternatively leave THINKING_MODELS but add a
short comment explaining it represents supported thinking-model prefixes to
justify the named constant.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8ba717d2-7a75-4570-8ba8-e8a58a2a6eb6

📥 Commits

Reviewing files that changed from the base of the PR and between 5696cb3 and 22446d7.

📒 Files selected for processing (9)
  • packages/adapter-claude/src/client.ts
  • packages/adapter-claude/src/requester.ts
  • packages/adapter-doubao/src/requester.ts
  • packages/adapter-rwkv/src/index.ts
  • packages/adapter-rwkv/src/requester.ts
  • packages/core/src/chains/chain.ts
  • packages/core/src/llm-core/platform/api.ts
  • packages/core/src/utils/time.ts
  • packages/shared-adapter/src/requester.ts
💤 Files with no reviewable changes (2)
  • packages/core/src/llm-core/platform/api.ts
  • packages/adapter-rwkv/src/requester.ts

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22446d77f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/llm-core/platform/api.ts
Comment thread packages/adapter-claude/src/requester.ts
Comment thread packages/shared-adapter/src/requester.ts
@dingyi222666 dingyi222666 merged commit 3634df4 into v1-dev Mar 19, 2026
5 checks passed
@dingyi222666 dingyi222666 deleted the fix/adapter-v1-bug branch March 19, 2026 22:56
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