Commit Graph
1795 Commits
Author SHA1 Message Date
harukaandClaude Opus 5.5 4ca1a2097c perf(openai): skip full-body decodes for Codex bootstrap and compaction
Every /v1/responses request ran the automation and delegation bootstrap
normalizers, each a json.Decoder token scan plus a full map decode, and
NormalizeCompactionTriggerInputOrder decoded the whole body on each HTTP
request and WebSocket turn, although almost none of them can change it.

- Bootstrap normalizers return early unless the raw body contains
  function_call_output and one of their tool names, or any \u escape that
  could spell them.
- The compaction normalizer returns early when the body has neither
  compaction_trigger nor a \u escape and is a valid JSON object, so invalid
  or non-object bodies still report the original decode error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 0853d16036 fix(images): give async image tasks their own body memory reservation
Async tasks inherited the ingress reservation through context.WithoutCancel,
but RequestBodyLimit releases and closes it when Submit returns. The task's
request body was a plain reader, so the gateway's read reserved against the
closed reservation and every task failed with a 503 budget error.

- Add httputil.DetachRequestBodyMemory: a reservation on the same budget that
  the handler's release does not close. It takes over the retained body's
  existing charge from the request and reserves only the remainder, so the
  body is never counted twice; the caller releases it when the work ends.
- Submit reserves the retained body before creating the task, returning 503
  with Retry-After on exhaustion instead of accepting a task that cannot run;
  the task releases it when execution finishes.
- Back the task request with PrereadBody so the body is not buffered again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
haruka 6c140b8976 perf(gateway): reduce JSON copies and repeated request parsing 2026-11-06 03:00:02 -05:00
shaw 7e3b6c72fa fix(openai): 按已屏蔽前缀长度精确匹配 cyber transcript,修复长会话误拦 (#8519)
同一来源触发 cyber 屏蔽后,scope 激活期间任何历史超过 256 个 item 的
会话都会因 lookup 截断被 fail-closed 判为 transcript_lookup_limit_exceeded,
即使与被屏蔽会话毫无关系、且带有不同的显式 session_id。

改为在命中时记录 transcript 屏蔽 key 覆盖的历史长度(按 API Key 建 Redis
SET 索引,随 scope 同 TTL),查询时仅在这些长度处重算前缀哈希:
- 无关长会话不再被误拦,历史长度本身不再决定屏蔽
- 追加任意数量 item 仍能命中被屏蔽前缀,防逃逸能力不降
- 查询 MGET 由最多 256 key 降为记录长度数,遍历在最长记录长度处提前终止
- scope 门控、API Key 命名空间与 cyber-transcript:v3 哈希格式均不变
2026-11-05 21:51:26 +08:00
haruka 457602c8fc fix(backend): bound gateway resources and background work 2026-11-04 23:54:03 +08:00
Wesley Liddick b9d6ff5ca2 Merge pull request #8504 from feeeei/feat/registration-email-blacklist
feat(auth): 注册邮箱精确黑名单,保存时可批量禁用命中的已注册用户
2026-11-04 21:01:00 +08:00
feeeei 721dfb282e feat(auth): 注册邮箱精确黑名单,保存时可批量禁用命中的已注册用户
- 系统设置 → 注册设置新增「邮箱黑名单(精确匹配)」,弹窗编辑、批量粘贴,上限 20000 条,
  名单存于 settings 键 registration_email_blacklist,由专用接口整体读写;运行时读 60s TTL
  进程内缓存,保存后本实例立即生效
- 按收件箱身份匹配(复用 NormalizeEmailForAliasDedup):Gmail 点号、googlemail.com 与 +后缀
  变体视为同一邮箱
- 邮箱注册、发验证码、第三方登录补建账号、绑定/换绑邮箱命中时返回 EMAIL_BLOCKED;
  已验证邮箱的 OAuth 登录只在新建账号时拦截,已有账号是否可用由账号状态决定
- 保存后对新增项查找仍启用的普通用户并弹窗确认批量禁用(跳过管理员、已禁用与已删除用户),
  与单个禁用一样在同一事务内吊销 MCP 授权,禁用后清理认证缓存;也可随时对整份名单手动检查
2026-11-04 17:52:05 +08:00
Wesley Liddick 6f92090d7f Merge pull request #8462 from feeeei/feat/openai-image-size-tier-routing
feat(openai): 生图账号按 1K/2K/4K 尺寸档位分流
2026-11-04 17:11:58 +08:00
feeeei a699c2baed fix(openai): 透传放行空 instructions,响应回显按客户端原值还原
- OAuth 透传不再对 codex 模型的空串、空白或非字符串 instructions 本地返回 403,原样转发给上游(官方 Codex 接口已不要求 instructions 必传)。
- 网关补写、追加或搬运 instructions 后,response.instructions 回显按客户端请求里的原始取值还原,客户端未传时还原为 null;覆盖原生与透传两条 HTTP 路径的流式、非流式与 SSE 转 JSON 出口。还原值压缩成单行,写回 SSE data 行不会拆帧。
2026-11-03 23:01:12 +08:00
feeeei e452e41e40 feat(openai): 生图账号按 1K/2K/4K 尺寸档位分流
账号 extra 新增 openai_image_size_tiers,限定账号承接的生图尺寸档位;档位口径与
计费 ClassifyImageBillingTier 一致(最长边 ≤1024=1K、≤2048=2K、更大=4K)。
缺省、空列表或三档齐全表示不限,存量账号行为不变。

- 请求尺寸可识别:只调度到允许该档位的账号,切号也只在这些账号之间进行。
- 未传 size / auto / 无法识别:不过滤,按偏好层级逐层选号——不限档位 → 允许 4K →
  允许 2K → 仅 1K;跳过没有账号的层级;较早层级只能排队时继续尝试后续层级,都抢不到
  槽位时返回最早的排队结果,且溢出选中的账号不改写会话已有的粘性绑定;会话粘性与
  previous_response_id 绑定的账号不受偏好约束。
- 档位轮次包在代理隔离 fail-open 之内:先不绕过隔离跑完全部档位,再整体绕过重跑。
- 覆盖 /v1/images/generations、/v1/images/edits(含异步图片任务)与 /v1/responses
  显式 image_generation 工具(tools[].size);判定挂在高级调度与旧调度/DB 复检的共用
  兼容检查上;调度快照 extra 白名单加入该键。
- 分组内持久可调度、支持该模型且具备所需能力的账号都不允许该档位时返回 400
  invalid_request_error,临时不可用仍为 503。
- 测试连接:受限账号按最低允许档位发送代表尺寸(1024x1024 / 1536x1024 / 3840x2160)。
- 前端:创建/编辑账号弹窗(OpenAI 全部类型)与批量编辑加入档位多选,至少保留一档;
  批量编辑全选时提交空列表表示不限。
2026-11-03 13:18:50 +08:00
lyen1688 194d69e636 完善管理员密钥权限并新增需确认的全权兼容模式 2026-11-01 23:52:35 +08:00
shaw f532737de2 Merge branch 'main' into codex/management-mcp
# Conflicts:
#	backend/go.mod
#	backend/go.sum
2026-10-30 09:21:24 +08:00
harukaandClaude Opus 5.5 575dd9bc2b fix(backend): make MCP client registration stateless
Registration was capped at 1000 pending clients site-wide while the limit
per IP was 10 per minute, so one address could exhaust the cap and block
every new MCP client.

- Issue client IDs as HMAC-signed tokens carrying the client name,
  redirect URI digests and grant types. Registration writes nothing;
  rows are created only when a user approves a client, so there is no
  shared capacity to exhaust.
- Persist the signing key in security_secrets via the existing
  get-or-create helper, cached lock-free, so instances share it.
- Drop mcp_oauth_clients from migration 249 and keep the client name on
  each grant. Prune expired grants on authorization, before the owner
  row is locked.
- Fix an unchecked type assertion in managementmcp tests flagged by
  golangci-lint v2.14.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 14:46:08 -04:00
harukaandClaude Opus 5.5 ee71c7f379 fix(backend): harden management MCP per review
- Reject JSON-RPC batches and non-object bodies before the SDK; return each
  tool result once as text and bound the encoded payload (H1).
- Enable MCP only when MCP_PUBLIC_URL is set; drop the frontend URL fallback
  and expose a read-only mcp_enabled public setting (M1).
- Expire never-authorized clients after 24h, cap pending registrations
  globally, aggregate MCP IP limits by IPv6 /64, and limit registration
  bodies to 4 KiB (M2).
- Revoke MCP grants with revoke-all-sessions and always require step-up for
  administrator write grants (M3).
- Rate limit /api/v1/mcp per IP before authentication and write last_used_at
  at most once per minute (M4).
- Persistently revoke grants when an account is disabled or demoted, derive
  result redaction from SensitiveCredentialKeys, allowlist browser sessions
  for step-up, audit every MCP read, reject invisible characters in
  client_name, and document site-root-only deployment (L1-L5, L7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 09:30:23 -04:00
Wesley Liddick 184193f01e Merge pull request #8369 from feeeei/fix/gemini-bound-cache-pool-retry
fix(gemini): 绑定显式缓存的请求在池模式上游网关账号上按配置同账号重试
2026-10-28 18:03:11 +08:00
feeeei 31564b2e86 fix(gemini): 刷新 Gemini 默认模型列表,移除已停用的 2.x 模型
- 账号白名单"同步最新支持模型"、/v1/models 与 /v1beta/models 的兜底列表共用的三处 Gemini 默认列表
  (前端 geminiModels、geminicli.DefaultModels、gemini.DefaultModels)统一为同一份 17 个现役模型:
  3.x 生图、3-flash、3.1-pro-preview(-customtools)、3.1/3.5 flash(-lite)、3.6/3.7/3.8-flash、4-argon;
  移除 2.0/2.5 系列与 3-pro-preview
- 连接测试默认模型由 gemini-2.0-flash 改为 gemini-3.5-flash;Google One 账号仍用其保守模型集
- 前端下拉候选总表补入 antigravity 模型并去重,antigravity 账号白名单下拉不再只显示与其他平台重叠的条目
- 生图模型识别补上 gemini-3.1-flash-lite-image
2026-10-28 16:00:21 +08:00
feeeei de44e3a0bf fix(gemini): 分组账号都声明模型映射时,/v1beta/models 列表与详情按声明的模型应答
- 原先 /v1beta/models 与 /v1beta/models/{model} 从分组中按优先级挑一个账号透传其上游列表;
  分组由多个第三方中转 Key 组成且各配 model_mapping 时,结果只反映选中账号的上游,
  与 /v1/models(合并各账号映射)不一致,下游"同步上游支持的模型"会拿到残缺或不可路由的模型
- 分组内每个可调度 Gemini 账号都有生效映射时,列表返回映射键并集(并上混合调度
  antigravity 账号的 Gemini 模型),分组白名单按 FilterForListing 与 /v1/models 同口径过滤,不再请求上游
- 详情按同一来源判断:键末尾 * 按前缀匹配,customtools 别名按请求路径的规则归一,未覆盖返回 404
- 有账号未配置映射(接受任意模型)或查询出错时,保持原选号透传逻辑
2026-10-28 16:00:21 +08:00
haruka f17918ea17 feat(backend): add OAuth-authenticated management MCP 2026-10-28 05:54:56 +08:00
Wesley Liddick 2c9d9760d8 Merge pull request #8303 from SipengXie2024/fix/pagination-offset-overflow
fix(pagination): keep page offsets from overflowing int
2026-10-27 20:42:55 +08:00
Wesley Liddick 15701ba187 Merge pull request #8339 from aomsir/fix/grok-model-catalog-audit
fix(grok): 完善模型目录来源诊断与原始响应模型审计
2026-10-27 19:00:01 +08:00
feeeei a207412375 fix(gemini): 绑定显式缓存的请求在池模式上游网关账号上按配置同账号重试
- 绑定缓存的请求收到上游网关账号的 429 / 5xx 时,原先直接按耗尽处理原样回写,pool_mode_retry_count 不生效;
  现按 pool_mode_retry_status_codes 判定可重试,在持有缓存的账号上同账号重试,用尽后仍原样回写
- 可重试的错误标为请求级瞬时故障:故障在上游网关持有缓存的账号上,重试用尽不临时封禁本账号
- 可重试时每次尝试登记 retry 类 ops 上游事件,重试成功记为恢复,不计入换号次数
- 非池模式账号或状态码不在重试列表内时行为不变
2026-10-27 12:11:54 +08:00
Aomsir dfc13ce7f9 fix(grok): 修复模型目录审计相关 lint 错误 2026-10-25 22:08:54 +08:00
Aomsir d4136cea5e fix(grok): 提供账号模型目录差异诊断 2026-10-25 05:52:29 +08:00
wx-11 fd998129ec feat(billing): support per-image billing for multi-image requests
按实际出图张数计费,解析不到时回退请求 n;新增分组级 image_count_billing 开关,仅对 OpenAI 和 Composite 分组开放;前端在图片计费区域提供按张计费勾选项。
2026-10-24 11:35:27 +08:00
lyen1688 e445cc3e2d 新增按操作与资源范围授权的管理员 API 密钥 2026-10-23 19:16:57 +08:00
SipengXie2024 9aa16c8c66 fix(pagination): validate numeric ranges and reuse safe offsets
Use strconv to reject pagination values outside the native int range,
reuse PaginationParams.Offset for API key slices, and derive test bounds
from math.MaxInt. Cover parsing, response metadata, strict handlers, and
in-memory pagination at the arithmetic boundaries.
2026-10-23 15:24:24 +08:00
SipengXie2024 f965280489 fix(pagination): keep page offsets from overflowing int
A page such as 9223372036854775807 passed every pagination check, so
(page-1)*pageSize wrapped around. With an even page size the offset
became negative and PostgreSQL rejected the query with "OFFSET must not
be negative"; paths that slice in memory (paginateSlice, balance history
merge) panicked with a negative slice bound. Both surfaced as HTTP 500 on
list endpoints such as /api/v1/admin/users, /api/v1/usage, /api/v1/keys
and /api/v1/admin/payment/orders.

- PaginationParams.Offset saturates Page at MaxInt/limit, so offset and
  offset+limit both stay within int.
- ParsePagination clamps page the same way, which covers the repositories
  that compute (page-1)*pageSize themselves.
- The prompt audit event list and the OpenAI token stats filter parse page
  on their own; they now reject an overflowing page with 400, like other
  invalid pagination input there.
2026-10-22 16:37:56 +00:00
Wesley Liddick b6c366380b Merge pull request #8249 from feeeei/perf/lazy-single-antigravity-probe
perf(gateway): 单 antigravity 账号分组判定改为按需求值,纯 Gemini/Anthropic 分组不再每请求回源数据库
2026-10-21 17:43:49 +08:00
Wesley Liddick b751230512 Merge pull request #8210 from feeeei/fix/anthropic-compat-stream-disconnect-billing
fix(gateway): Anthropic 账号 chat/responses 兼容流式客户端断开后读完上游再计费
2026-10-21 17:43:37 +08:00
Wesley Liddick 98f83b7263 Merge pull request #8167 from feeeei/fix/gemini-group-image-generation-gate
fix(gemini): 分组「允许当前分组生图」开关对 Gemini 系入口生效
2026-10-21 17:43:01 +08:00
feeeei d5dbb5c36b perf(gateway): 单 antigravity 账号分组判定改为按需求值
三个入口(Gemini 原生、/v1/messages 的 Gemini 分支与 Claude 路径)
每个请求都会查询分组的 antigravity:forced 快照桶。纯 Gemini/Anthropic
分组的该桶恒为空,空快照按未命中处理,于是每个请求都回源 PG 并重新
发布快照,而判定结果只被 antigravity 账号的 503 原地重试与模型限流
预检查读取。

入口改为挂载延迟判定:antigravity 账号首次需要时才查询快照,同一请求
内只查一次;显式设置的 SingleAccountRetry 标记仍优先。其他平台的请求
不再触发该查询。
2026-10-20 23:49:34 +08:00
feeeei 4355236e00 fix(gateway): 兼容流上游未正常结束时报错并对齐原生收尾
客户端在线时,Anthropic 账号的 chat/responses 兼容流在上游未发出结束事件
(message_stop、带 stop_reason 的 message_delta 或 [DONE])就中断,不再补发
finish_reason / [DONE] / response.completed 报成功:
- 读间隔超时、读错误、message_start 之后直接 EOF:service 写出协议内终止
  事件(CC 为 error 帧,Responses 为沿用流内 id 与 sequence_number 的
  response.failed),返回错误并带上已观测到的 usage;读间隔超时调用
  HandleStreamTimeout。
- 流内 event: error:立即结束读取,与 /v1/messages 共用
  sseStreamErrorEventFailover 转为 UpstreamFailoverError,未输出前换号重试,
  客户端在线时不计费。
- 两个 handler 的错误分支对带结果的错误照常入账。

客户端断开后的读取:stream_data_interval_timeout 未启用时按 180s 启用读间隔
上限;请求 ctx 取消也视为断开。复用 anthropicNativeStreamInterval。行泵在
计时器到期且已有缓冲行时优先交付数据,下游写入慢不再被判为上游空闲。
2026-10-20 01:25:19 +08:00
feeeei 47cb84b8b0 fix(gemini): 分组「允许当前分组生图」开关对 Gemini 系入口生效
- 门禁作用于展示该开关的 Gemini 系分组(gemini/antigravity/composite);无分组 Key、
  anthropic 等其他平台分组不受影响,OpenAI/Grok 仍走各自门禁
- 生图判定:复用图片接口的 gemini-*-image 判定(isGeminiCompatibleImageModel),或请求体
  generationConfig.responseModalities 含 IMAGE(camelCase/snake_case、字符串/整数枚举、
  重复键逐个检查);countTokens 不拦
- 两道检查:/v1/messages、/v1/chat/completions、/v1/responses、/v1beta/models 入口在
  选号前按客户端请求名与渠道映射名预检;Gemini 兼容与 Antigravity 的 6 个转发函数在
  账号模型映射后再按上游模型名检查,覆盖账号级别名
- 拒绝统一返回 400(Gemini 原生 INVALID_ARGUMENT,其余 invalid_request_error),
  不触发换号与账号处罚,下游 sub2api 把本实例当上游时不会因此停用账号;
  请求标记为本地功能门禁
- 升级兼容:迁移 246 把存量 gemini/antigravity 分组的生图开关置为开启;新建分组与简易
  模式默认分组对 gemini/antigravity 默认开启(与 grok 同为 OR 语义,创建时传 false 不生效),
  前端创建表单同步默认值;composite 不回填(同一开关还控制 OpenAI 生图),未开启的
  composite 分组升级后 Gemini 生图返回 400
- 未覆盖:最终模型名不符合 gemini-*-image 形态(如上游中转自定义的 nano-banana 别名)
  且请求体未声明 IMAGE 模态;门禁按 Key 所属分组判断,Claude Code 专用分组降级到
  其他分组时仍按原分组
2026-10-19 23:53:29 +08:00
feeeei d6120b5d8e feat(account): Vertex 账号支持配额上限
- 新增 AccountTypeSupportsQuota / SupportsAccountQuota(apikey/bedrock/service_account)
  作为配额账号类型的唯一判定,累加、超限停调度、额度通知、接口输出与计费仓储统一改用;
  池模式等其它特性仍只看 IsAPIKeyOrBedrock
- service_account 配额语义与 apikey 一致:配置了任一上限才累加,用满停调度,跨阈值发额度通知
- 计费事务中账号已删除时跳过账号配额计数,与 API Key 对称,用户扣费不再整笔回滚
- 账号额度通知只对配置了上限的账号做检查
- 前端创建/编辑弹窗对 Vertex 开放配额设置,设上限后用量列显示配额进度条;
  账号类型判断收敛到 supportsAccountQuota
2026-10-19 23:31:46 +08:00
Wesley Liddick 43157c478e Merge pull request #8121 from Larry-Labs/fix/gpt55-subscription-retirement
fix(openai): respect GPT-5.5 retirement on ChatGPT upstreams
2026-10-16 12:27:39 +08:00
shaw 1b92038eaf fix(payment): fix EasyPay order queries and confirm notifications before crediting
Order query:
- 彩虹易支付 and ZPay read act=order parameters from the URL query only;
  a body-only request is answered with "No Act!", so order status queries
  (reconcile, payment status checks) never reached the order. Parameters
  are now sent in the URL query and mirrored in the form body for forks
  that read the body.
- Decode status/money/trade_no leniently: PHP deployments commonly return
  integers as strings ("status":"1"), which previously failed the whole
  response decode. JSON null falls back to the nested data object.
- Treat a non-success code as a query error instead of an unpaid order,
  and require an echoed out_trade_no to match the queried order.
- Strip the request URL (which carries the merchant key) from transport
  errors before they are returned.

Notifications:
- Add payment.NotificationConfirmer. After a notification is verified, the
  webhook asks the same provider instance to confirm it; EasyPay queries
  the upstream order and requires it to be paid with a matching amount and
  trade_no (a missing notify trade_no is filled from the query). Failures
  are recorded as PAYMENT_UPSTREAM_UNCONFIRMED and answered with 502 so the
  gateway retries; the order stays pending and reconcile still applies.
- EasyPay notifications must carry the instance's configured pid, and
  field values other than name must be plain tokens.
- Return URLs must use a plain hostname or IP literal without userinfo.
2026-10-16 09:39:55 +08:00
xugao 26aab6dc07 fix(openai): respect GPT-5.5 retirement on ChatGPT upstreams 2026-10-15 20:53:15 +08:00
Wesley Liddick 698d142468 Merge pull request #8088 from wucm667/fix/issue-8077-workspace-aware-import
fix(openai): isolate Codex imports by workspace
2026-10-15 16:40:38 +08:00
shaw 9d3cc4507f fix(antigravity): keep legacy default passthroughs and bill Claude 5.5 tier IDs at base rates
- Restore runtime default passthroughs and Gemini 3.1 Pro aliases for
  explicit Antigravity model_mapping. Mappings saved before the Gemini
  3.x Flash / 3.1 Pro releases still depend on them; dropping them would
  silently remove those models from existing accounts on upgrade.
- Capability sync now skips injected-only passthrough targets, so models
  the upstream catalog omits no longer mark the sync as partial.
- Price Antigravity claude-{opus,sonnet}-5-5-{high,medium,low} at the base
  Opus/Sonnet 5.5 card instead of substring-matching claude-opus-5 /
  claude-sonnet-4-5 (1.25x-3x overbilling).
2026-10-15 15:47:42 +08:00
shaw 8afd2abd97 Merge remote-tracking branch 'origin/main' into contrib/gemini-4-argon-support
Resolve Gemini 4 Argon pricing conflicts in favor of main (#8078), which
already provides the base and Cyber Permissive price cards, thinking-tier
pricing aliases, and the local pricing snapshot.
2026-10-15 15:37:14 +08:00
shaw d19265ddb2 fix(gateway): 拒绝含 OpenAI 网关 OAuth 的 composite 歧义路由,防止凭据误入 Anthropic 管线
composite 分组中 openai OAuth 账号与 deepseek API Key 账号同时显式映射同一
gpt 模型时,模型归属判为歧义、路由层不解析平台,请求落到默认 Anthropic
GatewayHandler;handler 再按模型名前缀猜回 openai 并选中 OpenAI OAuth 账号,
ChatGPT token 被发往 api.anthropic.com,上游 401 "Invalid bearer token"
经 failover 逐号打成临时不可调度,单请求即可扫空号池。

- 归属记录声明方是否含 OpenAI 网关族 OAuth / setup-token;当模型名兜底也
  落在 OpenAI 网关族时判为配置错误,路由中间件与 WS 入口直接 400 拒绝并
  提示配置显式路由。纯 API Key 歧义及 Anthropic/Antigravity/Gemini OAuth
  歧义保持原行为。
- 模型归属改按配置计算(ListModelAvailabilityCandidates),不再随限流 /
  临时不可调度在「唯一归属」与「歧义」之间翻转。
- Anthropic 请求构建前校验凭据:非 Anthropic 网关族的 OAuth 凭据不出站,
  返回仅换号、不处罚账号的 failover;count_tokens 返回 404 不支持。
  API Key 不受限(上游可能兼容多种协议格式)。
2026-10-15 14:57:03 +08:00
Long Li feab6d80dc fix(antigravity): preserve tool_result images, native Gemini functionCall/thoughtSignature, and composite /v1beta routing 2026-10-15 06:55:32 +09:00
Long Li 373d43533a feat(antigravity): support Gemini 4 Argon and accurate upstream model catalogs 2026-10-15 02:06:23 +09:00
wucm667 16611a8ee0 fix(openai): isolate Codex imports by workspace 2026-10-14 18:34:52 +08:00
Wesley Liddick 53c21fed25 Merge pull request #8006 from feeeei/feat/gemini-explicit-cache
feat(gemini): 支持显式上下文缓存,并完善 Vertex 与第三方 API Key 账号
2026-10-13 14:51:11 +08:00
feeeei 43a3c197cb fix(gemini): 显式缓存恢复流程区分账号已删除与暂不支持缓存,上游必已过期后作废意图
后台回滚在持有账号返回 nil 时把修改意图当作已回滚清除:账号临时关闭显式缓存能力后
意图丢失,重新开启也无法补偿。

- boundAccount 区分两种情形:账号已删除返回 nil,账号存在但不支持显式缓存返回
  errGeminiCachedContentAccountUnsupported;BoundAccount 对外行为不变
- 账号暂不支持缓存时不改动上游、保留意图,租约过期后重试(期间同一缓存的修改返回 409);
  账号已删除时没有凭据可回滚上游,软删本地记录
- 修改前到期时间加上单次最长有效期与 1 小时容忍都已过去时上游缓存必已自行过期:
  账号不支持缓存或上游回滚持续失败的意图不再重试,直接作废本地记录
- 测试夹具 GetForOwner 过滤已软删记录
2026-10-13 00:54:27 +08:00
feeeei 8b74741efe fix(groups): 广场 Vary 保留 Origin,分组译文语言代码统一大小写
- 模型广场以追加方式写入 Vary: Accept-Language,保留 CORS 中间件为具体来源
  写入的 Vary: Origin
- 管理端写入分组译文时语言代码统一为 BCP 47 惯用大小写(en、zh-TW),
  统一后重复的语言代码(如 en 与 EN)返回 400 INVALID_GROUP_I18N
- 用户侧按语言取译文时规范写法的键优先,仅大小写不同的多个键按字节序取最小者,
  同一请求语言的结果固定
2026-10-12 18:09:03 +08:00
feeeei 26b31a83e4 fix(gemini): 显式缓存修改串行化、失败回滚,确定金额费用按 Key / 订阅预留
同一缓存的并发 PATCH 可能以与上游提交不同的顺序写回本地到期时间;
确定金额的存储费只预留用户余额,并发续期可越过 API Key 总额度与订阅额度;
上游已修改而本地写回失败时没有可恢复的状态。

- 新增迁移 245:缓存记录增加修改意图(mutation_token / mutation_lease_until)。
  PATCH 在调用上游前登记意图并取得 2 分钟租约,条件为没有进行中的修改且到期时间
  未变;上游修改、本地写回与计费均由持有者完成,并发的修改返回 409 ABORTED
- 上游结果未知、本地写回失败或进程退出时修改意图保留且不计费;租约过期后由下一次
  修改或后台每分钟的恢复流程把上游有效期回滚到修改前的到期时间(已到期则删除上游
  缓存与本地记录)。上游明确拒绝或请求未发出时直接清除意图
- 修改 / 删除上游缓存的单次调用超时改为 30 秒;请求发出前的失败包装为
  ErrGeminiCachedContentRequestNotSent
- CheckChargeAffordable 与 ReserveInflightCharge 合并为 ReserveFixedCharge:在途预留
  新增订阅、API Key 两个维度(Redis billing:inflight_scope:*),先登记本笔预留再读取
  库中权威用量(Key quota_used 与限速窗口、订阅日 / 周 / 月用量)叠加同维度在途合计
  校验;预留随计费任务交接,落库后释放
- GetRateLimitData 一并读取 quota_used
2026-10-12 17:14:56 +08:00
feeeei daebb7a80c fix(gemini): 模型列表与模型详情接口支持 Agent Platform (Vertex) 账号
Gemini 分组对外提供 AI Studio 兼容协议,分组内账号不一定是 AI Studio。
分组只剩 Vertex 服务账号时,GET /v1beta/models 与 /v1beta/models/{model}
选中服务账号后报 502 unsupported account type: service_account。

- SelectAccountForAIStudioEndpoints 改名 SelectAccountForModelsEndpoints,
  Vertex 账号排在所有 AI Studio 兼容账号之后参与选号
- ForwardAIStudioGET 拆为 ForwardListModels / ForwardGetModel,按账号类型分流:
  AI Studio 兼容账号原样转发;Vertex 服务账号读取 Google 发布方模型列表并
  转换为 AI Studio 格式,模型详情在该模型所用区域的列表中查找;Vertex API Key
  账号返回内置列表
- Vertex 发布方模型分页读取抽成 listVertexGeminiPublisherModels,与后台
  同步上游模型共用
- 模型接口响应体上限改用 gateway.models_list_read_max_bytes,超出时报错
2026-10-11 22:03:36 +08:00
feeeei 05d7946af8 fix(gemini): 显式缓存错误透传收窄到上游网关账号,延长沿用创建时计费口径
- 绑定缓存的请求与缓存管理接口收到 429 / 5xx 时,只有上游网关账号的响应原样回写
  (UpstreamFailoverError.BoundUpstreamPassthrough / GeminiCachedContentUpstreamError.UpstreamGateway),
  官方账号仍走错误透传规则与通用映射,不向客户端暴露配额明细
- 记录新增 channel_usage(迁移 244)保存创建时的渠道计费口径,PATCH 延长按同一口径预检、报价与记账
- 创建 / 延长费用行的 request_id 改为固定前缀 gcache:{create|patch}:{id},不被客户端或网关请求 id 覆盖,
  按缓存 ID 即可检索一个缓存的全部费用行
- 调度快照凭据投影补齐 base_url / auth_mode / 上游显式缓存声明,显式缓存候选过滤一次算全,
  不再逐个选号后剔除
2026-10-11 01:37:04 +08:00