Commit Graph
8396 Commits
Author SHA1 Message Date
shaw 06e7a2ed4b Merge branch 'main' into feat/declare-image-input-models
# Conflicts:
#	backend/internal/service/openai_codex_models_service.go
2026-11-26 11:50:34 +08:00
Wesley Liddick eef63ee7cd Merge pull request #9099 from PMExtra/feat/channel-expose-response-model
feat(channel): 渠道支持向用户显示实际响应模型
2026-11-26 11:49:58 +08:00
Wesley Liddick 76d8d976d5 Merge pull request #9095 from pood1e/fix/anthropic-bridge-deepseek-default-effort
fix(openai): default DeepSeek effort to high in the Anthropic bridge
2026-11-26 11:49:45 +08:00
Wesley Liddick 3db5753641 Merge pull request #9093 from pood1e/feat/openai-chat-reasoning-content
feat(openai): let API-key accounts opt into reasoning_content on raw Chat Completions
2026-11-26 11:49:32 +08:00
Wesley Liddick 164d7056ed Merge pull request #9088 from PMExtra/feat/proxy-ip-checked-at
feat(proxy): 代理列表显示出口 IP 与最后检测时间
2026-11-26 11:49:18 +08:00
Wesley Liddick 7b2a5f5d48 Merge pull request #9087 from wucm667/fix/issue-9086-tooltip-scroll
fix(frontend): keep help tooltips aligned after scrolling
2026-11-26 11:49:05 +08:00
Wesley Liddick 821701e45b Merge pull request #9085 from adamcjm/fix/opencode-user-agent-version
fix(opencode): 上游 User-Agent 版本更新至 1.19.6 并支持环境变量覆盖
2026-11-26 11:48:52 +08:00
Wesley Liddick ab00fef989 Merge pull request #9084 from r266-tech/codex/command-code-image-modalities
fix(codex): include Command Code image capabilities in model catalogs
2026-11-26 11:48:38 +08:00
Wesley Liddick bb7fb85cd5 Merge pull request #9081 from bin-bash-dev/fix/sse-keepalive-retry-accounting
fix(openai): account SSE keepalive bytes across failover attempts
2026-11-26 11:48:25 +08:00
Wesley Liddick e55f9db056 Merge pull request #9080 from bin-bash-dev/fix/content-moderation-lazy-queue
fix(moderation): allocate async moderation queue on demand
2026-11-26 11:48:11 +08:00
Wesley Liddick 3dd9a24957 Merge pull request #9079 from wucm667/fix/issue-9077-versionless-identity
fix(antigravity): handle versionless system identity openers
2026-11-26 11:47:57 +08:00
Wesley Liddick 2c5325ace8 Merge pull request #9076 from r266-tech/codex/optional-antigravity-stream-summaries
feat(antigravity): let upstream choose Gemini stream summaries
2026-11-26 11:47:43 +08:00
Wesley Liddick be8dfee8b2 Merge pull request #9069 from wucm667/feat/issue-9066-proxy-account-count
fix(accounts): show proxy account counts in account dialogs
2026-11-26 11:47:30 +08:00
Wesley Liddick f3ea22ec91 Merge pull request #9064 from PMExtra/feat/account-upstream-error-stats
feat(accounts): 在账号今日统计和用量趋势中展示上游错误次数
2026-11-26 11:47:17 +08:00
Wesley Liddick 8ace90b8d0 Merge pull request #9060 from LagrangeQ/fix/gemini-empty-stream-usage
fix(gemini): preserve stream usage after empty metadata
2026-11-26 11:47:04 +08:00
Wesley Liddick 62b3fa1aac Merge pull request #9046 from alfadb/fix/zhipu-overload-429-short-cooldown
fix(ratelimit): 智谱平台过载 429 改用秒级冷却
2026-11-26 11:46:51 +08:00
Wesley Liddick a55adce0aa Merge pull request #9034 from r266-tech/codex/shorten-proxy-network-cooldown
fix(openai): recover sooner after transport reachability failures
2026-11-26 11:46:38 +08:00
Wesley Liddick d081e563f7 Merge pull request #9012 from Anankke/fix/toolname-stream-restore
fix(gateway): restore tool names split across stream deltas
2026-11-26 11:46:23 +08:00
Wesley Liddick 6f34149c15 Merge pull request #9004 from Anankke/fix/sticky-session-rebind-cas
fix(gateway): do not overwrite a sticky rebind after a long forward
2026-11-26 11:46:10 +08:00
Wesley Liddick ddc855a51d Merge pull request #8995 from r266-tech/codex/show-requester-in-ops-error-detail
fix(ops): show requester in request error details
2026-11-26 11:45:58 +08:00
Wesley Liddick e3eb96c0b5 Merge pull request #8994 from wucm667/fix/issue-8991-terminal-context
fix(openai): normalize standalone terminal context
2026-11-26 11:45:44 +08:00
Wesley Liddick 4ecec232d8 Merge pull request #8860 from Anankke/fix/account-usage-auto-refresh
fix(accounts): refetch Gemini usage when the account's quota tier changes
2026-11-26 11:45:30 +08:00
PMExtraandClaude Opus 5.5 8c4336eb58 fix(usage): chain Localized on user usage DTO mapping line
TestUserFacingGroupDTOsAreLocalized statically requires every user-facing
dto.*FromService call to chain .Localized( on the same line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 01:01:21 +08:00
PMExtraandClaude Opus 5.5 a1c7be6e90 feat(channel): optionally show actual response model to users
Add a channel-level toggle (features_config.expose_response_model, off by
default). When enabled, regular users see the final response model next to
the requested model in their usage records; the intermediate mapping chain
stays admin-only.

- Channel.IsResponseModelExposed + ChannelService.ResponseModelExposedChannels
  read from the in-memory channel cache, so no extra DB queries
- User usage list/detail fill the new optional response_model field
  (upstream_response_model -> upstream_model -> model, omitted when equal
  to the requested model)
- Channel form toggle, UsageTable rendering and i18n

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 00:45:37 +08:00
pood1eandClaude Opus 5.5 2945ecf89b fix(openai): default DeepSeek effort to high in the Anthropic bridge
Without a client effort, the Anthropic bridge sends `medium`. DeepSeek's
reasoning scale is low/high/max, as the Codex manifest already declares,
and DeepSeek-V4.1 rejects `medium`. Every Anthropic-format request without
an explicit effort therefore failed on DeepSeek models. The bridge now
sends DeepSeek's default level instead. Explicit efforts, disabled thinking
and other models are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 06:40:19 -08:00
pood1eandClaude Opus 5.5 5c95c63e15 feat(codex): let accounts declare image-input models
The Codex manifest advertises image input from synced upstream metadata
or a few known model names. Multimodal models served by vLLM or SGLang
match neither, so Codex blocks image attachments for them. The new account
extra key `image_input_models` lists upstream model IDs that accept image
input, and the manifest honors it ahead of synced metadata.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 05:52:27 -08:00
pood1eandClaude Opus 5.5 21a95dbaa8 feat(openai): let API-key accounts opt into reasoning_content on raw Chat Completions
vLLM and SGLang stream reasoning in `reasoning`, while DeepSeek-style
clients read `reasoning_content`. The raw Chat Completions path already
mirrors these fields for Ollama Cloud accounts. The new account extra key
`openai_chat_reasoning_content` enables the same normalization for other
OpenAI API-key accounts. Ollama Cloud keeps it unconditionally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 05:51:41 -08:00
wucm667 afd87f38be fix(frontend): keep help tooltips aligned after scrolling 2026-11-25 14:55:16 +08:00
PMExtraandClaude Opus 5.5 1ba1ae8ef0 feat(proxy): show exit IP and last check time in proxy list
- Expose latency_checked_at (from cached UpdatedAt) on admin proxy list
- Show exit IP under location and last check time under created_at
- Include region/city in quality check result
- Quality check now updates row latency/IP/location on failure too,
  matching the backend snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 14:27:06 +08:00
adam b3fdd01f0b fix(opencode): 上游 User-Agent 版本更新至 1.19.6 并支持环境变量覆盖
出站到 opencode.ai 的规范 User-Agent 一直硬编码为 opencode/1.0.0,已明显落后于
真实客户端(opencode-ai npm 包当前为 1.19.6)。上游按 opencode/<version> 格式
校验客户端身份,陈旧的版本号本身会成为可识别的特征。

- 默认版本号更新为 1.19.6,注释说明跟随 opencode-ai 最新发布
- 新增 OPENCODE_USER_AGENT_VERSION 环境变量覆盖,后续升级无需改代码
- 版本号按三段 semver 校验,非法或空值回退内置默认
- 补充 Normalize/Resolve 与 UA 格式的单元测试
2026-11-25 12:59:28 +08:00
r266-tech f90198a5ee fix(codex): include Command Code image capabilities in model catalogs 2026-11-25 12:50:23 +08:00
bin-bash-dev 1f5ca63440 fix(openai): account SSE keepalive bytes across failover attempts
Problem: on /v1/responses passthrough accounts with
gateway.stream_keepalive_interval enabled, a failover-eligible upstream
error (e.g. an overloaded `event: error` before any visible output) is
only failed over once. If the first attempt has already written a
keepalive comment, the next attempt that fails the same way is treated
as if semantic output had reached the client: the error is delivered as
response.failed and the remaining schedulable accounts are never tried.

Root cause: handleStreamingResponsePassthrough starts a new SSE
keepalive for every attempt, and startOpenAISSEKeepalive replaces the
instance stored on the gin.Context. Keepalive bytes were tracked per
instance, so OpenAICompactKeepaliveAdjustedWrittenSize subtracted only
the current instance's bytes from c.Writer.Size(); comments written by
an earlier attempt stayed in Size() and were counted as real output.
openAIStreamClientOutputStarted therefore reported output as started
and the passthrough stream stopped proposing failover.
StopOpenAICompactSSEKeepaliveCommitted had the same per-instance blind
spot and reported "not committed" when only an earlier instance had
committed the 200 response.

Fix: keep the keepalive byte count in a request-scoped atomic counter
stored on the gin.Context and shared by every keepalive instance of the
request (retries and nested starts). AdjustedWrittenSize subtracts the
cumulative count, and the committed check also reports true once any
keepalive of the request has written a comment. Single-keepalive
behaviour is unchanged.

Tests: a handler-level regression test drives the real Responses
handler with three passthrough accounts (the first attempt emits a real
keepalive and then fails over, the second fails immediately, the third
succeeds); on the previous code only accounts [1 2] are called and the
client receives response.failed. Service-level tests cover cumulative
accounting across restarts, the committed check after a previous
attempt, restarts without beats, and nested keepalives; they drive beats
manually instead of relying on timer scheduling.
2026-11-25 04:01:48 +08:00
bin-bash-dev fe72ddf1ae fix(moderation): allocate async moderation queue on demand
问题:NewContentModerationService 在构造时就执行
make(chan contentModerationTask, maxContentModerationQueueSize)。
maxContentModerationQueueSize=100000,单个任务 288 字节,因此每个实例一
构造就常驻约 28.8MB,与是否启用异步审核、是否有流量都无关。service 包测
试会创建数百个短生命周期实例,测试进程的提交内存随之涨到 GiB 级;生产上
任何额外构造的实例也要白白付出同样的代价。

根因:队列深度按允许的最大值预分配,而真正的丢弃判据
len(queue) >= cfg.QueueSize 只依赖运行期配置,并不需要预先占满容量。

修法:
- 构造函数不再创建队列,只标记 asyncQueueLazy;首次入队时按
  min(64, QueueSize) 创建,满且仍低于 QueueSize 时按 2 倍扩容(上限
  QueueSize),迁移已排队任务;运行期调大 QueueSize 也能继续扩容。
- 丢弃判据仍是 len >= QueueSize,丢弃计数与告警日志保持不变。
- 未经构造函数创建的零值服务入队仍是 no-op(不计数、不告警)。
- 队列创建/扩容时关闭并替换 asyncWake 广播唤醒 worker,阻塞在旧
  channel 上的 worker 会重新读取新队列,不空转、不漏取任务。
- GetStatus 与日志读取队列长度改为加锁读取,不会触发分配。

测试:
- content_moderation_queue_contract_test.go 只使用既有接口:构造后不预
  留队列;在独立子进程中测量 64 个空闲实例的堆增量(旧实现约
  28,803,490 字节/实例,修复后约 451 字节/实例,阈值 64KiB);
  QueueSize=8 时收 8 丢 12、记录路径同样受限、4096 全收且调大到 8192
  后继续接收;零值服务 no-op;真实 worker 并发消费 400 条记录不丢不重。
  结构与内存用例在修复前失败,其余语义用例修复前后均通过。
- content_moderation_queue_lazy_test.go 用 synctest 覆盖初始容量与扩容
  上限、多生产者/消费者恰好一次投递、扩容期间消费者持续读取、首次创建
  与替换队列时的唤醒、取消与空闲超时。
2026-11-25 03:56:32 +08:00
wucm667 2b836b7b7c fix(antigravity): handle versionless system identity openers 2026-11-25 02:44:44 +08:00
r266-tech 876f137d8f feat(antigravity): let upstream choose Gemini stream summaries 2026-11-25 01:15:18 +08:00
PMExtraandClaude Opus 5.5 8decae9779 feat(accounts): show upstream error counts in today stats and usage trend
Count provider-owned, non-business-limited rows in ops_error_logs per
account (same definition as the ops dashboard) and expose them as
`upstream_errors` on today stats and per-day account usage history.

- Today stats column shows today's upstream errors (highlighted when > 0).
- Usage statistics modal adds an upstream error trend line plus today and
  30-day totals; days with only errors are merged into the history.
- Counts are omitted when ops monitoring is disabled so the UI hides them
  instead of showing a misleading 0. Failover intermediate attempts are
  attributed only to the last failing account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 22:46:46 +08:00
wucm667 0c7d3ff58c fix(accounts): show proxy account counts in account dialogs 2026-11-24 18:42:21 +08:00
LagrangeQ 52b5d71d60 fix(gemini): preserve stream usage after empty metadata
Ignore usageMetadata without counters so a trailing placeholder cannot overwrite measured input, output, or cached tokens. Preserve explicit zero counters and add regression coverage for the Gemini native, Chat Completions, Messages, and stream collection paths.
2026-11-24 14:57:23 +08:00
github-actions[bot] 0f66714571 chore: sync VERSION to 0.2.25 [skip ci] 2026-11-24 03:21:26 +00:00
Wesley Liddick 348997267d Merge pull request #9052 from Wei-Shaw/feat/header-override-identity-variables
feat(accounts): 请求头覆写支持身份上报变量
v0.2.25
2026-11-24 11:11:32 +08:00
shaw c5147eab16 fix(accounts): 身份上报变量审计修复
- request_id 可由客户端经 X-Request-ID 自带:代入前只保留字母数字与
  . _ -,其余替换为下划线并限长,防止在组合模板里伪造其它身份字段
- 模板不合法的存量条目不再被提前丢弃:应用时删除同名客户端头且不发送
- 错误记录中的上报请求头不再包含固定文本(可能是中转密钥),混合模板
  记为 "…name=value" 形态
- 模型列表/清单等跨用户共享缓存的请求不携带用户身份,避免缓存被打散
- 只改账号类型(不带 credentials)的更新同样校验变量使用
- 编辑器连点同一变量不再产生重名行
- 补充认证中间件到真实转发构建器的端到端用例
2026-11-24 10:56:25 +08:00
shaw 0f1e3c1f6a feat(accounts): 请求头覆写支持身份上报变量
API Key 账号的请求头覆写值可使用 {{user_id}} / {{api_key_id}} /
{{group_id}} / {{request_id}},转发时替换为本次请求的网关身份,便于
逐层定位到具体用户。

- 仅 api_key 账号解析变量;OAuth(含 Grok OAuth)保存时拒绝,运行时
  整条请求头不发送
- 变量取不到值(无用户上下文的后台请求)时整条不发送,同名的客户端
  请求头照样删除,防止伪造
- OpenAI WS 连接池按上报身份分桶,握手头不解析 request_id
- 错误记录的上游事件记录实际上报的请求头(仅变量生成的部分),错误
  详情新增「身份上报请求头」区块
- 编辑器新增变量面板、发送示例预览与行内错误提示
2026-11-24 10:28:55 +08:00
Wesley Liddick 00c51f07d2 Merge pull request #9045 from itzhan/fix/openai-passthrough-400-error-forwarding
fix(openai): preserve invalid_encrypted_content and apply error passthrough rules in passthrough mode
2026-11-24 09:58:02 +08:00
Wesley Liddick 4d4433df09 Merge pull request #9008 from Brisbanehuang/codex/key-billing-group-details
feat(accounts): 支持从上游分组同步账号名称与备注
2026-11-24 09:57:35 +08:00
shaw eabf37852a fix(openai): compact response.failed 改写容量降载码,空白 code 回退内嵌提取
- 透传结构化错误在 compact 心跳已提交时写 response.failed,上游的
  server_is_overloaded / slow_down 必须与其它写 response.failed 的路径一样
  改写为可重试的 server_error,否则 Codex 会直接终止会话
- error.code 为空白字符串时回退到 message 内嵌 JSON 的 code,与错误分类
  看到的 code 保持一致
- 移除测试文件中仅为保留 import 而存在的占位变量
2026-11-24 09:42:41 +08:00
shaw 34423bf1e1 fix(accounts): 上游分组文字先修剪再校验控制字符
首尾的换行或制表符只是多余空白,不应导致整个字段被丢弃而不同步;
修剪后仍含控制字符的才拒绝。
2026-11-24 09:42:39 +08:00
shaw 797fde4e95 fix(deps): 升级 gorilla/websocket 修复 GO-2026-6278
govulncheck 新收录 GO-2026-6278(WebSocket mask key 使用弱随机数),
v1.5.3 受影响且上游尚无带修复的正式 tag,升级到 govulncheck 指定的修复
提交 v1.5.4-0.20240701034025-d67f41855da4。

该库仅用于管理端 ops WebSocket 的服务端升级;服务端只声明 sub2api-admin
一个子协议,上游对子协议匹配顺序的调整不改变协商结果。
2026-11-24 09:21:39 +08:00
shaw ba9df6f1c3 fix(deps): 升级 gorilla/websocket 修复 GO-2026-6278
govulncheck 新收录 GO-2026-6278(WebSocket mask key 使用弱随机数),
v1.5.3 受影响且上游尚无带修复的正式 tag,升级到 govulncheck 指定的修复
提交 v1.5.4-0.20240701034025-d67f41855da4。

该库仅用于管理端 ops WebSocket 的服务端升级;服务端只声明 sub2api-admin
一个子协议,上游对子协议匹配顺序的调整不改变协商结果。
2026-11-24 09:21:38 +08:00
shaw 38903b6d1d fix(accounts): 上游分组文字入库前校验,include 支持多值
- 上游分组名称/描述与探测快照、倍率在同一条 UPDATE 中写库。gjson 对未转义
  字符串返回原始字节,非法 UTF-8 会被 PostgreSQL 以 22021 拒绝,导致整条
  UPDATE 失败:快照与倍率都写不进去,next_probe_at 不推进,账号每个调度
  周期都被重试并挤占探测名额。现在非法 UTF-8 只丢弃对应字段
- 名称拒绝控制字符,备注仅保留换行与制表符,避免上游向管理端写入
  转义序列等不可见内容
- /v1/sub2api/billing 的 include 按逗号分隔列表解析并支持重复参数,
  后续新增可选段时不会让 include=group 失效
2026-11-24 08:58:55 +08:00
shaw 4339d50615 fix(openai): 修复透传错误脱敏越界并收紧结构化错误字段
- replaceCaseInsensitive 改为在原始字节上做大小写不敏感匹配。原实现用
  strings.ToLower 后的下标切原串,遇到折叠后字节长度变化的字符(Ⱥ、Kelvin
  符号、非法 UTF-8)会越界 panic 或把上游主机名原样漏给客户端;同时消除
  该函数的 errcheck 告警
- error.type/code/param 只接受字符串或数字并限长 256 字节,避免上游把对象
  或数组以原始 JSON 形式塞进这三个字段
- 规则命中且未配置自定义文案时,上游消息同样经过凭据与主机名脱敏
- compact 心跳已提交时 response.failed 保留结构化 error.code
2026-11-24 08:56:01 +08:00