Skip to content

feat(relay): hosted-tool conversion fidelity, reasoning normalization, and billing usage integrity - #7137

Merged
Calcium-Ion merged 5 commits into
mainfrom
feat/relaykit-tools
Sep 1, 2026
Merged

Calcium-Ion merged 5 commits into
mainfrom
feat/relaykit-tools

Conversation

@Calcium-Ion

@Calcium-Ion Calcium-Ion commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

🔗 关联任务 / Related Issue

  • Closes #

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

📝 变更描述 / Description

本 PR 包含 5 个提交,围绕 relaykit 跨协议转换与计费完整性三条主线:

1. 内置(hosted)工具跨协议保真转换(feat(relaykit): preserve hosted tools across conversions)

  • 新增协议中立的工具转换层 toolconv:跨协议转换时将工具定义、tool_choice、hosted 工具调用历史从载荷中摘出、绕过中间 pivot、在目标协议贴回。web_search 在 OpenAI Chat / Claude / Gemini / Responses 四协议间全向保真,MCP 在 Claude ↔ Responses 间保真。
  • 新增 citations/grounding 双向桥:Claude citations ↔ Chat url_citation annotations,Gemini groundingSupports → annotations / web_search_call。
  • 转换损耗策略三档(allow/safe/strict),默认 allow(静默降级 + 结构化诊断落管理日志);拒绝为渠道级 opt-in(ChannelOtherSettings.ToolLossPolicy),拒绝返回 400;响应/流阶段无论何种策略均不拒绝。
  • 转换诊断(conversion diagnostics)管线:按 code+path+severity 去重、上限 32 条,写入消费日志 other.admin_info.conversion_diagnostics(仅管理员可见)。

2. reasoning/thinking 归一化(refactor(relaykit): normalize reasoning and thinking intent)

  • 各协议推理参数统一归一化为 ReasoningIntent(unset/enabled/adaptive/disabled + 五档 effort + budget),按模型家族能力表渲染为目标协议字段;支持 Claude adaptive thinking,未知上游降级 manual。
  • 模型后缀解析(-thinking/-nothinking/effort 尾缀)上提到 relay 入口层(ApplyReasoningModelSuffix):入口一次解析、产出 ReasoningConversionState、同步到所有出站请求副本;转换器只消费显式意图,不再各自解析模型名。deepseek-v4- 前缀与火山引擎自解析后缀保持交由渠道 adaptor 处理,generic -thinking 裁剪仅限 OpenRouter 方言。
  • effort 尾缀白名单(qwen-max 等真实模型名保护)从 relaykit 硬编码移至宿主配置(GlobalSettings.EffortTailModelIDs)。
  • 客户端显式发送的 max_tokens: 0 恢复视为未设置(填默认值),管理员配置的默认值 0 语义不变。
  • 计价身份维持既有契约:ModelPriceHelper 使用带后缀的 origin 模型名 + 通配倍率条目。

3. 计费 usage 完整性(fix(billing): preserve authoritative usage across relay hops)

  • 以上游原生 usage 快照(BillingUsage sidecar)为结算真源:跨协议桥接克隆搬运而非重建,Source/Semantic 保留真实上游方言,级联部署可依赖该契约。
  • 修复:Claude 纯缓存读场景重复计费;全零 usage 快照抢占结算(结算 0);Gemini 估算抹掉原生缓存/thoughts 明细;Gemini 流式部分 metadata 覆盖(改单调合并,CacheCreation 整体替换、candidates+thoughts 成对采信);Claude 流中断时快照过期少计 output;倒数第二个 SSE 事件 usage 兜底收窄并对齐 cached_tokens 帧;非流式不可信 usage 整份替换防明细放大。
  • Gemini 流异常结束(客户端中断/下游写失败)照常结算,不再触发全额退款;上游 timeout 时 Responses 流补发终结事件。
  • Gemini 渠道补上函数调用按次附加费计数(六个 handler 均接入,willContinue 终结分片只计一次),与 OpenAI/Claude 渠道对齐。
  • 删除 Gemini -nothinking 计费别名路径(其差异定价只服务于已退役的 2.5 flash preview 模型,且存在 self-use 模式下落 37.5 兜底倍率的多收风险);保留 -nothinking 请求适配(关闭 thinking)与 BillingModelName 基础设施。

4. 协议桥与端点(feat(relay): bridge Responses with Claude and Gemini protocols)

  • Responses 客户端 → Claude 渠道原生流式/非流式(此前 not implemented);Claude → Responses 请求由两跳 pivot 改为单跳直连转换器;Gemini → Responses 原生流方向 + sequence_number。
  • 新增 POST /v1/messages/count_tokens 端点(Anthropic token 计数,不走上游、不计费、不受估算开关影响)。
  • 流式工具调用记账修复:按 chat index 建稳定 item_id、延迟 call_id 回填、并行调用 ID/参数保持独立,冲突 ID 拒绝而非静默合并。

5. 宿主接线(fix(relay): wire relaykit conversions into host channels)

  • handler/adaptor 接线、渠道设置、跨渠道重试时 ReasoningConversion 状态清理、转换失败错误呈现(客户端错误 400 + SkipRetry)。

📸 运行证明 / Proof of Work

两模块构建与测试通过:根模块 go build ./... && go test ./...;relaykit 独立模块 cd relaykit && GOWORK=off go build ./... && GOWORK=off go test ./...。计费不变量、转换语义与后缀适配均有对应单元/回归测试锁定(testify)。

✅ 提交前检查项 / Checklist

  • 人工确认: 无论描述是否由 AI 生成,我已审阅全部内容,并声明对其准确性与完整性负责。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • 新功能关联 Issue: 若此 PR 标记为 `New feature`,我已关联对应 Issue;若尚无 Issue,我已先自行创建。
  • 事前沟通: 若改动较大或涉及方向性变更,已在关联 Issue 中与维护者沟通并达成一致。
  • 功能范围: 本 PR 不是 Coding Plan、逆向渠道、第三方封装接口,也不是对 Codex 渠道类型的改动。
  • 范围聚焦: 本 PR 为一项聚焦改动,未包含无关代码。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

Summary by CodeRabbit

  • New Features
    • Added Claude token-counting support through the Messages API.
    • Expanded OpenAI Responses compatibility, including streaming, reasoning, hosted tools, citations, and direct Claude conversions.
    • Improved Gemini and Claude support for reasoning, tool calls, web search, grounding, and multimodal content.
    • Added configurable tool-loss policies for request conversions.
  • Bug Fixes
    • Improved token usage, billing, tool-call tracking, streaming completion, and citation preservation.
    • Conversion failures now provide clearer client errors and diagnostic details.
  • Documentation
    • Updated conversion guidance for reasoning and tool-loss behavior.

- add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies
- bridge citations, grounding metadata, and hosted-tool stream lifecycles
- document the public conversion behavior and channel policy controls
- centralize provider-neutral reasoning intent, effort, and budget mappings
- parse model suffixes at the host entry boundary while preserving provider-owned tails
- keep adaptive Claude thinking and explicit zero-token compatibility consistent
- carry native BillingUsage sidecars through direct and streamed protocol bridges
- merge partial and terminal usage monotonically with safe fallback settlement
- retain cache metadata, penultimate usage, and per-call Gemini tool surcharges
- add direct request, response, and stream converters across supported relay formats
- expose Claude count_tokens and Chat-to-Responses compatibility endpoints
- carry conversion diagnostics through the host while retaining the curated public goldens
- connect handlers, adaptors, and channel settings to the standalone conversion layer
- keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned
- ignore local audit artifacts and retain focused public regression coverage
@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 773c2d19-853a-4cd2-976d-af4414ca48bc

📥 Commits

Reviewing files that changed from the base of the PR and between b7017c2 and bbe20f2.

📒 Files selected for processing (149)
  • .gitignore
  • controller/channel-test.go
  • controller/relay.go
  • controller/relay_count_tokens_test.go
  • model/channel.go
  • relay/channel/aws/adaptor.go
  • relay/channel/aws/relay_aws_test.go
  • relay/channel/claude/adaptor.go
  • relay/channel/claude/adaptor_test.go
  • relay/channel/claude/relay-claude.go
  • relay/channel/claude/relay_claude_test.go
  • relay/channel/claude/relay_responses.go
  • relay/channel/gemini/adaptor.go
  • relay/channel/gemini/relay-gemini-native.go
  • relay/channel/gemini/relay-gemini.go
  • relay/channel/gemini/relay_responses.go
  • relay/channel/newapi/adaptor.go
  • relay/channel/openai/adaptor.go
  • relay/channel/openai/chat_via_responses.go
  • relay/channel/openai/chat_via_responses_test.go
  • relay/channel/openai/helper.go
  • relay/channel/openai/relay-openai.go
  • relay/channel/openai/relay_responses.go
  • relay/channel/openai/responses_via_chat.go
  • relay/channel/sub2api/adaptor_test.go
  • relay/channel/vertex/adaptor.go
  • relay/channel/zhipu_4v/adaptor.go
  • relay/chat_completions_via_responses.go
  • relay/chat_completions_via_responses_test.go
  • relay/claude_handler.go
  • relay/common/conversion_diagnostics.go
  • relay/common/override.go
  • relay/common/relay_info.go
  • relay/common/relay_info_test.go
  • relay/common/tool_usage.go
  • relay/compatible_handler.go
  • relay/convert_request_error.go
  • relay/convert_request_error_test.go
  • relay/gemini_handler.go
  • relay/helper/price.go
  • relay/helper/price_test.go
  • relay/helper/reasoning_suffix.go
  • relay/helper/reasoning_suffix_test.go
  • relay/responses_handler.go
  • relaykit/README.md
  • relaykit/dto/billing_usage.go
  • relaykit/dto/channel_settings.go
  • relaykit/dto/channel_settings_test.go
  • relaykit/dto/claude.go
  • relaykit/dto/gemini.go
  • relaykit/dto/openai_request.go
  • relaykit/dto/openai_response.go
  • relaykit/dto/reasoning_state.go
  • relaykit/dto/usage_merge.go
  • relaykit/dto/usage_merge_test.go
  • relaykit/reasonmap/reasonmap.go
  • relaykit/relayconvert/claude_default_max_tokens_test.go
  • relaykit/relayconvert/convmeta/meta.go
  • relaykit/relayconvert/convmeta/meta_test.go
  • relaykit/relayconvert/convmeta/options.go
  • relaykit/relayconvert/golden_test.go
  • relaykit/relayconvert/internal/claude_messages/citations.go
  • relaykit/relayconvert/internal/claude_messages/stream_billing_usage_test.go
  • relaykit/relayconvert/internal/claude_messages/to_oai_chat_req.go
  • relaykit/relayconvert/internal/claude_messages/to_oai_chat_resp.go
  • relaykit/relayconvert/internal/claude_messages/to_oai_responses_hosted_stream.go
  • relaykit/relayconvert/internal/claude_messages/to_oai_responses_req.go
  • relaykit/relayconvert/internal/gemini_chat/grounding.go
  • relaykit/relayconvert/internal/gemini_chat/to_oai_chat_req.go
  • relaykit/relayconvert/internal/gemini_chat/to_oai_chat_resp.go
  • relaykit/relayconvert/internal/gemini_chat/to_oai_responses_hosted_stream.go
  • relaykit/relayconvert/internal/oai_chat/citations.go
  • relaykit/relayconvert/internal/oai_chat/to_claude_messages_req.go
  • relaykit/relayconvert/internal/oai_chat/to_claude_messages_resp.go
  • relaykit/relayconvert/internal/oai_chat/to_claude_messages_resp_test.go
  • relaykit/relayconvert/internal/oai_chat/to_gemini_chat_req.go
  • relaykit/relayconvert/internal/oai_chat/to_gemini_chat_resp.go
  • relaykit/relayconvert/internal/oai_chat/to_oai_responses_req.go
  • relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp.go
  • relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.go
  • relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go
  • relaykit/relayconvert/internal/oai_responses/to_claude_messages_req.go
  • relaykit/relayconvert/internal/oai_responses/to_claude_messages_resp.go
  • relaykit/relayconvert/internal/oai_responses/to_claude_messages_stream_resp.go
  • relaykit/relayconvert/internal/oai_responses/to_claude_messages_stream_resp_test.go
  • relaykit/relayconvert/internal/oai_responses/to_gemini_chat_req.go
  • relaykit/relayconvert/internal/oai_responses/to_oai_chat_req.go
  • relaykit/relayconvert/internal/oai_responses/to_oai_chat_resp.go
  • relaykit/relayconvert/internal/oai_responses/to_oai_chat_resp_test.go
  • relaykit/relayconvert/internal/oai_responses/to_oai_chat_stream_resp.go
  • relaykit/relayconvert/internal/shared/claude/reasoning.go
  • relaykit/relayconvert/internal/shared/claude/usage.go
  • relaykit/relayconvert/internal/shared/gemini/request.go
  • relaykit/relayconvert/internal/toolconv/decode.go
  • relaykit/relayconvert/internal/toolconv/encode.go
  • relaykit/relayconvert/internal/toolconv/hosted_values.go
  • relaykit/relayconvert/internal/toolconv/model.go
  • relaykit/relayconvert/internal/toolconv/policy_test.go
  • relaykit/relayconvert/internal/toolconv/response.go
  • relaykit/relayconvert/internal/toolconv/response_artifacts.go
  • relaykit/relayconvert/reasoning/claude.go
  • relaykit/relayconvert/reasoning/gemini.go
  • relaykit/relayconvert/reasoning/intent.go
  • relaykit/relayconvert/reasoning/intent_test.go
  • relaykit/relayconvert/reasoning/suffix.go
  • relaykit/relayconvert/reasoning/suffix_test.go
  • relaykit/relayconvert/request_compat.go
  • relaykit/relayconvert/request_registry.go
  • relaykit/relayconvert/request_registry_test.go
  • relaykit/relayconvert/response_compat.go
  • relaykit/relayconvert/response_registry.go
  • relaykit/relayconvert/response_registry_test.go
  • relaykit/relayconvert/terminal_stream_test.go
  • relaykit/relayconvert/testdata/golden/request/claude_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/request/claude_to_openai.golden.json
  • relaykit/relayconvert/testdata/golden/request/claude_to_openai_responses.golden.json
  • relaykit/relayconvert/testdata/golden/request/gemini_to_claude.golden.json
  • relaykit/relayconvert/testdata/golden/request/gemini_to_openai.golden.json
  • relaykit/relayconvert/testdata/golden/request/gemini_to_openai_responses.golden.json
  • relaykit/relayconvert/testdata/golden/request/openai_responses_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/request/openai_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/response/claude_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/response/gemini_to_claude.golden.json
  • relaykit/relayconvert/testdata/golden/response/openai_responses_to_claude.golden.json
  • relaykit/relayconvert/testdata/golden/response/openai_responses_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/response/openai_responses_to_openai.golden.json
  • relaykit/relayconvert/testdata/golden/response/openai_to_claude.golden.json
  • relaykit/relayconvert/testdata/golden/response/openai_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/response/openai_to_openai_responses.golden.json
  • relaykit/relayconvert/testdata/golden/stream/claude_to_gemini.golden.json
  • relaykit/relayconvert/testdata/golden/stream/gemini_to_claude.golden.json
  • relaykit/relayconvert/text_converter_registry.go
  • relaykit/relayconvert/text_converter_registry_test.go
  • relaykit/relayconvert/tool_loss_policy_test.go
  • relaykit/types/conversion.go
  • router/relay-router.go
  • router/relay_router_test.go
  • service/billing_session.go
  • service/billing_usage.go
  • service/log_info_generate.go
  • service/quota.go
  • service/request_converter.go
  • service/response_converter.go
  • service/text_quota.go
  • service/text_quota_test.go
  • service/token_counter.go
  • setting/model_setting/global.go
  • setting/ratio_setting/model_ratio.go
  • setting/reasoning/suffix.go

Walkthrough

The change centralizes reasoning conversion, adds request-phase tool-loss policies and diagnostics, introduces direct Claude and OpenAI Responses routes, adds stateful provider stream conversion, normalizes billing usage, preserves annotations and hosted-tool data, and exposes Claude token counting.

Changes

Relay conversion and reasoning

Layer / File(s) Summary
Shared reasoning and request conversion
relaykit/relayconvert/reasoning/*, relay/helper/reasoning_suffix.go, relaykit/relayconvert/internal/shared/*
Reasoning intents now support Claude, Gemini, OpenAI Chat, and OpenAI Responses. Model suffixes are parsed at the host layer and carried through conversion metadata.
Tool conversion and loss policies
relaykit/relayconvert/internal/toolconv/*, relaykit/types/conversion.go, relaykit/relayconvert/request_registry.go
Requests and hosted-tool history are extracted, converted, and reattached with conversion diagnostics. allow, safe, and strict policies control request-phase loss rejection.
Provider response conversion
relaykit/relayconvert/internal/claude_messages/*, relaykit/relayconvert/internal/gemini_chat/*, relaykit/relayconvert/internal/oai_chat/*, relaykit/relayconvert/internal/oai_responses/*
Stateful stream converters preserve reasoning, citations, tool calls, hosted-tool events, ordering, sequence numbers, and conversion errors.
Usage and billing handling
relaykit/dto/billing_usage.go, relaykit/dto/usage_merge.go, service/*, relay/helper/price.go
Provider billing snapshots now canonicalize into shared usage data. Non-zero usage merging preserves earlier values and provider metadata. Billing uses the resolved billing model name.
Relay integration and validation
relay/channel/*, relay/*_handler.go, service/response_converter.go, router/*, controller/*
Handlers use the shared conversion service, propagate conversion diagnostics, route direct protocol conversions, and expose POST /v1/messages/count_tokens. Tests cover reasoning, streaming, usage, diagnostics, routing, and conversion order.

Estimated code review effort: 5 (Critical) | ~120 minutes

Poem

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

✨ 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 feat/relaykit-tools

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.

@Calcium-Ion
Calcium-Ion merged commit 0ed497f into main Sep 1, 2026
2 of 3 checks passed
yiranxiaohui pushed a commit to yiranxiaohui/new-api that referenced this pull request Sep 2, 2026
Resolve conflicts with upstream QuantumNous#7137:

- controller/relay.go: keep the shared service.ProcessChannelError
  wrapper and thread relayInfo through it so conversion diagnostics
  land in error logs for HTTP, task, and Responses WebSocket relays.
- relay/channel/openai/relay_responses.go: adopt upstream's
  relayconvert.NormalizeResponsesUsage + dto.MergeUsageNonZero.
- Drop service.ApplyResponsesUsage; the WebSocket session now uses the
  same relaykit normalizer, which is extended to honour Responses
  output_tokens_details so reasoning/image token details are billed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
yiranxiaohui pushed a commit to yiranxiaohui/new-api that referenced this pull request Sep 2, 2026
… and port fork video features

Sync QuantumNous/new-api main through 0ed497f via the resolved PR QuantumNous#6914
branch. Upstream replaced every Go video task adaptor with the sandboxed
JS task plugin system and reserved channel type 61 for "Task Plugin".

Fork features ported onto the plugin system:

- New API Video channel: renumbered to ChannelTypeNewAPIVideo = 62 with a
  one-time, idempotent migration of channel rows and task platforms from
  the legacy 61 (guarded by an options marker so real Task Plugin
  channels are never touched). Reimplemented as factory plugin
  plugins/tasks/newapi-video: POST /v1/video/generations submit, JSON-only
  bodies, per-call billing (no multipliers), tolerant result-URL
  extraction, and channel-backed content proxying for upstreams that
  return their own /content endpoint.
- xAI Grok Imagine video: reimplemented as factory plugin plugins/tasks/xai
  (channelTypes [48]) with the native generation body, OpenAI video
  size -> aspect_ratio/resolution translation, multipart input_reference
  via file placeholders, and the per-model resolution ratios. The native
  POST /v1/videos/generations entry collides with the host's
  /v1/videos/:task_id shape, so it is bound host-side through the new
  middleware.PinHostOwnedPluginRoute instead of meta.routes.
- Removed relay/channel/task/{sora,xai}, the ClientProtocol task field,
  and the fork's video-proxy channel branches (now plugin artifacts).

Conflict resolutions:
- controller/relay.go: keep service.ProcessChannelError wrapper plus the
  fork's per-channel concurrency slot; adopt upstream stage/refund flow.
- relay/claude_handler.go: adopt upstream ApplyReasoningModelSuffix and
  keep the fork's post-processing (history-aware thinking strip, clear_
  thinking edit removal, sampling normalisation, developer role,
  tool normalisation).
- relay/common/relay_info.go: upstream fields plus fork UserRatio.
- router/web-router.go: upstream plugin dispatcher chain plus the fork's
  index injector on "/" and "/index.html".
- model/*, middleware/distributor.go, service/channel_select.go,
  relay/channel/openai/*: upstream.
- i18n locale files: union of both sides.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ChinaToyHunter added a commit to ChinaToyHunter/new-api that referenced this pull request Sep 3, 2026
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…, and billing usage integrity (QuantumNous#7137)

* feat(relaykit): preserve hosted tools across conversions

- add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies
- bridge citations, grounding metadata, and hosted-tool stream lifecycles
- document the public conversion behavior and channel policy controls

* refactor(relaykit): normalize reasoning and thinking intent

- centralize provider-neutral reasoning intent, effort, and budget mappings
- parse model suffixes at the host entry boundary while preserving provider-owned tails
- keep adaptive Claude thinking and explicit zero-token compatibility consistent

* fix(billing): preserve authoritative usage across relay hops

- carry native BillingUsage sidecars through direct and streamed protocol bridges
- merge partial and terminal usage monotonically with safe fallback settlement
- retain cache metadata, penultimate usage, and per-call Gemini tool surcharges

* feat(relay): bridge Responses with Claude and Gemini protocols

- add direct request, response, and stream converters across supported relay formats
- expose Claude count_tokens and Chat-to-Responses compatibility endpoints
- carry conversion diagnostics through the host while retaining the curated public goldens

* fix(relay): wire relaykit conversions into host channels

- connect handlers, adaptors, and channel settings to the standalone conversion layer
- keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned
- ignore local audit artifacts and retain focused public regression coverage
MAakber pushed a commit to MAakber/new-api that referenced this pull request Sep 11, 2026
…, and billing usage integrity (QuantumNous#7137)

* feat(relaykit): preserve hosted tools across conversions

- add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies
- bridge citations, grounding metadata, and hosted-tool stream lifecycles
- document the public conversion behavior and channel policy controls

* refactor(relaykit): normalize reasoning and thinking intent

- centralize provider-neutral reasoning intent, effort, and budget mappings
- parse model suffixes at the host entry boundary while preserving provider-owned tails
- keep adaptive Claude thinking and explicit zero-token compatibility consistent

* fix(billing): preserve authoritative usage across relay hops

- carry native BillingUsage sidecars through direct and streamed protocol bridges
- merge partial and terminal usage monotonically with safe fallback settlement
- retain cache metadata, penultimate usage, and per-call Gemini tool surcharges

* feat(relay): bridge Responses with Claude and Gemini protocols

- add direct request, response, and stream converters across supported relay formats
- expose Claude count_tokens and Chat-to-Responses compatibility endpoints
- carry conversion diagnostics through the host while retaining the curated public goldens

* fix(relay): wire relaykit conversions into host channels

- connect handlers, adaptors, and channel settings to the standalone conversion layer
- keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned
- ignore local audit artifacts and retain focused public regression coverage

(cherry picked from commit 0ed497f)
lazzman pushed a commit to lazzman/new-api that referenced this pull request Sep 14, 2026
…, and billing usage integrity (QuantumNous#7137)

* feat(relaykit): preserve hosted tools across conversions

- add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies
- bridge citations, grounding metadata, and hosted-tool stream lifecycles
- document the public conversion behavior and channel policy controls

* refactor(relaykit): normalize reasoning and thinking intent

- centralize provider-neutral reasoning intent, effort, and budget mappings
- parse model suffixes at the host entry boundary while preserving provider-owned tails
- keep adaptive Claude thinking and explicit zero-token compatibility consistent

* fix(billing): preserve authoritative usage across relay hops

- carry native BillingUsage sidecars through direct and streamed protocol bridges
- merge partial and terminal usage monotonically with safe fallback settlement
- retain cache metadata, penultimate usage, and per-call Gemini tool surcharges

* feat(relay): bridge Responses with Claude and Gemini protocols

- add direct request, response, and stream converters across supported relay formats
- expose Claude count_tokens and Chat-to-Responses compatibility endpoints
- carry conversion diagnostics through the host while retaining the curated public goldens

* fix(relay): wire relaykit conversions into host channels

- connect handlers, adaptors, and channel settings to the standalone conversion layer
- keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned
- ignore local audit artifacts and retain focused public regression coverage
lazzman pushed a commit to lazzman/new-api that referenced this pull request Sep 17, 2026
…, and billing usage integrity (QuantumNous#7137)

* feat(relaykit): preserve hosted tools across conversions

- add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies
- bridge citations, grounding metadata, and hosted-tool stream lifecycles
- document the public conversion behavior and channel policy controls

* refactor(relaykit): normalize reasoning and thinking intent

- centralize provider-neutral reasoning intent, effort, and budget mappings
- parse model suffixes at the host entry boundary while preserving provider-owned tails
- keep adaptive Claude thinking and explicit zero-token compatibility consistent

* fix(billing): preserve authoritative usage across relay hops

- carry native BillingUsage sidecars through direct and streamed protocol bridges
- merge partial and terminal usage monotonically with safe fallback settlement
- retain cache metadata, penultimate usage, and per-call Gemini tool surcharges

* feat(relay): bridge Responses with Claude and Gemini protocols

- add direct request, response, and stream converters across supported relay formats
- expose Claude count_tokens and Chat-to-Responses compatibility endpoints
- carry conversion diagnostics through the host while retaining the curated public goldens

* fix(relay): wire relaykit conversions into host channels

- connect handlers, adaptors, and channel settings to the standalone conversion layer
- keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned
- ignore local audit artifacts and retain focused public regression coverage
bigfish9 added a commit to lanlingxiawu/new-api-er that referenced this pull request Sep 17, 2026
移植上游 QuantumNous#7211(49ec469668)。gpt-6-astra 不匹配原先的 "gpt-5" 前缀,
max_tokens / temperature / top_p / logprobs 原样透传,上游返回 400
"Unsupported parameter: 'max_tokens' ... Use 'max_completion_tokens' instead",
渠道测试也因此失败。

- dto 新增 OpenAIChatCapabilities / GetOpenAIChatCapabilities,按映射后模型与
  推理力度统一决定:是否改用 max_completion_tokens、是否把 system 改为
  developer、是否支持 temperature / top_p / logprobs(含 top_logprobs)。
- IsOpenAIGPT5Model 精确匹配 gpt-5 / gpt-5-* / gpt-5.*,不再误中 gpt-50 等。
- gpt-6-astra 及其日期快照纳入规则;gpt-5.1/5.2/5.4 未开推理时保留采样参数;
  未识别的模型(含未来代际、gpt-6-astra-pro)不改写。
- adaptor 冲突手动解决:本分支没有 QuantumNous#7137 的推理意图函数,保留
  ParseOpenAIReasoningEffortFromModelSuffix,但改为先剥离推理力度后缀再判定能力,
  否则 gpt-6-astra-high 会被当作未知模型放行。

上游 controller/channel_test_request_test.go 依赖本分支缺少的
EffortTailModelIDs / ApplyReasoningModelSuffix,未移植;改为在
relay/channel/openai/chat_capabilities_test.go 覆盖转换行为。
quqi1599 added a commit to quqi1599/gmvupup-new-api that referenced this pull request Oct 4, 2026
Alex-lsky added a commit to Alex-lsky/new-api that referenced this pull request Oct 11, 2026
Sync 266 upstream commits since f116414 (2026-08-18):

Highlights merged:
- Stability: OOM fix (QuantumNous#6949), SQLite WAL/busy-timeout (QuantumNous#7030), TLS transport
  isolation (QuantumNous#7627), DB migration hardening, bounded upstream header waits
- Billing integrity: cross-protocol conversion loss fixes, stream-cut usage
  estimation (QuantumNous#7427), cached-token breakdowns, Gemini stream token details,
  tokenkit calibration, image billing via ResponsesUsageAccumulator
- Auth/security overhaul: scoped access tokens, step-up verification, audit
  logs, password transport encryption (opt-in), unified OAuth, passkey RPID
- Architecture: hosted-tool DTOs + ResponsesToolState (QuantumNous#7137), moejs JS task
  plugins, pricing expression system, model/vendor management rework,
  Responses WebSocket relay, channel editor redesign

Custom features preserved and re-integrated:
- bridge_tool_types / strip_tool_types / repair_text_tool_call_models:
  request-side chat bridge now coexists with upstream ResponsesToolState;
  response restoration prefers the bridge (keeps hashed long-name
  round-trips) and falls back to ToolState
- emulated hosted tools (web_search/image/vision) + tool_hosting MCP module:
  wiring moved into PrepareResponsesRequest (new 5th return value carries
  the emulation base body)
- price alias: GetCompletionRatio/GetBillingMode/GetBillingExpr/ratio lookups
  keep alias resolution ahead of upstream builtin-expression precedence;
  UI alias mode re-integrated into the expression pricing editors and
  PRICING_KEYS pipeline
- non-native Responses upstream history guard: rewrites now also run on the
  adaptor's fast path
- Aliyun ACR release workflow, custom Dockerfile tweaks

Merge notes:
- relaykit converter signatures synthesized: (ctx, req, bridge)
- responses stream handler delegates usage/tool/image accounting to
  service.ResponsesUsageAccumulator (upstream semantics for images on
  incomplete responses)
- go.mod: upstream dependency set + modelcontextprotocol/go-sdk v1.7.0
- i18n locales: key union, normalized via i18n:sync

Verification on Windows:
- go build ./... OK; relaykit tests all green; relay tests green except
  pre-existing TestWriteMCPVisionImageSecureTemporaryFile (Windows file
  perms, fails on pre-merge branch too)
- controller: 101 failures identical to upstream/main run on the same
  machine (DB matrix tests need AUDIT_MYSQL_DSN etc; security tests hit
  Windows temp-dir cleanup locks) - not merge regressions
- web: typecheck clean, vitest 2221/2221, lint clean for touched files,
  production build OK
yzcaiai added a commit to yzcaiai/new-api that referenced this pull request Oct 14, 2026
Rebase the fork onto upstream v1.0.0-rc.44 (718a4e7), which already
carries the rc.31 reasoning refactor (PR QuantumNous#7137): a protocol-neutral
reasoning.Intent IR plus the geminiCapabilitiesFor capability table. The
five local patches that previously implemented effort forwarding and the
Gemini 3 thinking_level split are fully subsumed by that refactor, so the
fork now tracks upstream directly and only keeps its own additions.

Gemini 4 Argon rejects thinkingBudget with HTTP 400 and cannot disable
thinking, so it needs the thinking_level dialect: register gemini-4 in
the capability table, map minimal (dropped by this family) to low, and
give the family its documented medium default.

- relaykit/relayconvert/reasoning/gemini.go: gemini-4 capability entry,
  minimal to low coercion, medium default effort
- relaykit/relayconvert/reasoning/gemini_test.go: render and normalize
  cases covering level passthrough, budget conversion, disable fallback,
  and the minimal downgrade
- relay/channel/gemini/constant.go: list gemini-4-argon as a known model
- .github/workflows/docker-publish.yml: restore the GHCR multi-arch build
  and derive the version tag from the nearest release tag instead of a
  hardcoded rc number
@Calcium-Ion
Calcium-Ion deleted the feat/relaykit-tools branch October 22, 2026 04:57
timwenx pushed a commit to timwenx/new-api that referenced this pull request Nov 18, 2026
…, and billing usage integrity (QuantumNous#7137)

* feat(relaykit): preserve hosted tools across conversions

- add protocol-neutral hosted-tool DTOs, conversion metadata, and loss policies
- bridge citations, grounding metadata, and hosted-tool stream lifecycles
- document the public conversion behavior and channel policy controls

* refactor(relaykit): normalize reasoning and thinking intent

- centralize provider-neutral reasoning intent, effort, and budget mappings
- parse model suffixes at the host entry boundary while preserving provider-owned tails
- keep adaptive Claude thinking and explicit zero-token compatibility consistent

* fix(billing): preserve authoritative usage across relay hops

- carry native BillingUsage sidecars through direct and streamed protocol bridges
- merge partial and terminal usage monotonically with safe fallback settlement
- retain cache metadata, penultimate usage, and per-call Gemini tool surcharges

* feat(relay): bridge Responses with Claude and Gemini protocols

- add direct request, response, and stream converters across supported relay formats
- expose Claude count_tokens and Chat-to-Responses compatibility endpoints
- carry conversion diagnostics through the host while retaining the curated public goldens

* fix(relay): wire relaykit conversions into host channels

- connect handlers, adaptors, and channel settings to the standalone conversion layer
- keep model mapping, pricing identity, retries, and provider-specific suffix behavior aligned
- ignore local audit artifacts and retain focused public regression coverage
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