Commit Graph
6899 Commits
Author SHA1 Message Date
alfadb 59ea2290e6 feat(scheduling): suspend exhausted legacy ollama cloud accounts
增量 4a(③ 组 A6+C25+E9 + ⑤ 组 A2 + F4,同批落地):

- A2: 新增 AccountModeOllamaLegacy/OllamaCredits 常量与
  Account.GetOllamaCloudAccountMode 解析器(非 ollama_cloud/非 apikey
  返回空串;未设置或值不认识默认 legacy,存量账号保持受阈值保护)
- A6: AllowedSchedulingThresholdPlatforms 纳入 ollama_cloud(4 个消费点
  同步生效:评估器门禁、设置校验、存储解析、设置审计 diff)
- C25: 评估器新增 ollama 分支 + ollamaCloudThresholdCandidates,仅 legacy
  产生 5h/weekly 停调候选(credits 型月度信用池候选恒空);快照缺失/
  status!=ok/无窗口数据不停调;取最晚 reset(与 openai/anthropic 同类)
- E9: 前端 SchedulingThresholdPlatformType union 与
  SCHEDULING_THRESHOLD_PLATFORMS 数组加 ollama_cloud(与后端白名单两侧同步)
- F4: 评估器表驱动用例(legacy 停/credits 不停/默认 legacy/坏快照不停)、
  ApplyAccountSchedulingThreshold 端到端(temp_unschedulable 落库断言)、
  mode 解析器用例、设置校验 ollama_cloud 往返用例

无迁移、无 DTO 变更(account_mode 为自由 JSONB,无 CHECK 约束)。
2026-09-13 10:38:55 +08:00
alfadb d36c935255 feat(billing): gate unpriced ollama cloud models at save and request time
- save-time gate on admin account create/update (and AccountService, which has
  no production consumers but is the spec-mandated location): non-empty
  model_mapping values and empty-mapping allowed_models lists must all resolve
  via GetModelPricing, otherwise 400 MODEL_PRICING_MISSING
- request-time gate: ollama_cloud accounts no longer fall into the global
  zero-cost path when pricing is unavailable; explicit 4xx instead
- operational preflight SQL documented as comments (not a migration)
- include ollama_cloud in the billing model candidate filter (S1) so claude-*
  names can no longer be priced at Anthropic rates for this platform
- keep ollama_cloud out of the LiteLLM platform map on purpose (comment only)
- refresh a stale comment in upstream_billing_probe.go
2026-09-13 10:38:55 +08:00
alfadb 707bcafd82 fix(billing): keep gpt-oss names out of the OpenAI pricing fallback chain
复现:动态目录含 gpt-5.4 时,gpt-oss:120b/20b 经 matchOpenAIModel 末端
catch-all 落到 DefaultTestModel(gpt-5.4) 价卡($2.5/$15 per MTok,实测
日志 "OpenAI fallback to default model gpt-oss:120b -> gpt-5.4"),绕过
fallbackPrices 的 ollama 价卡($0.15/$0.60 与 $0.07/$0.30),输入价
静默多收约 17~36 倍。

修复:GetModelPricing 第 5 步排除 gpt-oss 前缀进 OpenAI 回退链(返回 nil
交还 BillingService 走 fallbackPrices 的 ollama 价卡);不动任何其它匹配
规则与价格数值。gpt-oss-120b-medium(Antigravity 白名单同名族,仓库无其
定价条目)由误计 gpt-5.4 价转为 fail-closed,与无目录时行为一致。

回归护栏:ollama_cloud_dynamic_catalog_pricing_test.go 表驱动钉死 8 个
ollama 独占模型在目录已加载形态下的实际解析价,并钉住真实 OpenAI 名
(gpt-5.4 目录精确命中 / gpt-4o catch-all / gpt-5.5 静态兜底)不受影响。
2026-09-13 10:38:55 +08:00
alfadb 04ce8a499c feat(billing): price ollama cloud models and resolve tagged model names
B2-②: add fallbackPrices entries for the 8 ollama-exclusive cloud models
(gpt-oss:120b/20b, gemma4:31b, mistral-large-3:675b, qwen3.5:397b,
nemotron-3-super/nano:30b/ultra) with official per-token rates, plus
exact/prefix family rules in getFallbackPricing. gpt-oss tiers and the
three nemotron tiers are matched precisely (no bare gpt-oss/nemotron
prefix); models without a published cached-input tier bill cached input
at the input rate instead of 0.

B2-①: two-level pricing lookup for ":tag" model names. Shared helper
normalizePricingModelNameForLookup yields the stripped candidate; wired
into getModelPricingAt (full chain rerun, pricingAt preserved),
matchGroupModelPricing (exact retry) and lookupChannelPricingNormalized
(third retry after the codex normalization; applyChannelOverrides
inherits it). Literal name always wins, so bedrock canonical keys like
us.anthropic.claude-sonnet-4-5-20250929-v1:0 are never destructively
stripped; normalizeChannelPricingModelName stays untouched.

Tests: full /v1/models listing pinned with hit paths, tag-strip and
fail-closed behavior, bedrock double-key regression at base/channel/
group layers.
2026-09-13 10:38:55 +08:00
alfadb e701fd2dbc feat(ollama): make responses and max_tokens hooks platform-aware
- C31: include ollama_cloud in SupportsNativeCNResponses so /v1/responses
  ingress routes to the platform-native endpoint instead of degrading to
  raw CC, and the stateless normalize hook (store=false + strip
  previous_response_id) now applies to ollama accounts
- D2/C37': reject the stateful conversation field with an explicit 400
  invalid_request_error on native Responses accounts instead of silently
  dropping context; normalizeDeepSeekResponsesRequestBody now returns
  ([]byte, error) with all three production call sites propagating the
  typed error as a client-visible 400
- D1': clamp max_tokens for non-DeepSeek models too on ollama.com
  upstreams (raw CC, native Responses, Anthropic Messages); the host
  check is the boundary, the >65535 upstream 400 is model-independent;
  delete the now-dead isOllamaCloudRawChatCompletionsAccount predicate
- C39: mark ollama_cloud accounts force_responses in the Responses
  probe (per-protocol, no network probe) and let the admin handler
  schedule the probe for ollama_cloud accounts
2026-09-13 10:38:55 +08:00
alfadb b16d411aa6 feat(ui): render ollama_cloud usage cell
E17: account for ollama_cloud explicitly in both usage-cell computeds.
Empirically the cell already renders via the generic api-key root branch
(eligible -> OllamaCloudUsageCell + today-stats, ineligible -> '-'
placeholder), because eligibility itself is server-driven
(ollama_cloud_usage.eligible, fixed backend-side in the previous
commit); so the computeds pin that behavior instead of flipping to the
scrolling-window root branch, which would drop today-stats rows and
fire /usage calls the backend rejects for api-key accounts.

- showUsageWindows: explicit ollama_cloud api-key branch -> false
  (generic api-key branch renders the Ollama cell)
- shouldFetchUsage: document why ollama_cloud stays unfetched (backend
  /usage rejects api-key accounts; data arrives via account payload and
  the dedicated refresh endpoint, same shape as CN platforms)
- tests: eligible renders OllamaCloudUsageCell without /usage fetch;
  missing/eligible=false renders placeholder, never CN quota cells
2026-09-13 10:38:55 +08:00
alfadb e98f8d20e5 feat(ollama): platform-ize ollama_cloud usage service
- D1(u): usage platform whitelist now admits platform=ollama_cloud via
  authoritative OllamaCloudUsagePlatforms (ollama_cloud + legacy host
  platforms); host gate (official ollama.com) untouched
- D3(u): repository SQL platform whitelist derived from the service list
  (const -> var via ollamaCloudPlatformsSQLLiteral) instead of a hand
  mirrored literal - drift now structurally impossible
- D4(u)+F3: TestOllamaCloudUsagePlatformsMirror locks the derivation
  (parse count, ElementsMatch, eligible SQL contains every platform);
  existing predicate test covers ollama_cloud and dynamically sized list
- D2(u): ErrOllamaCloudUsageAccountInvalid message derived from the
  whitelist (code unchanged - external contract)
- D6(u): doc comment on IsOllamaCloudUsageAccount (three conditions,
  reverse-proxy eligible=false is expected)
- D8(u): decision record on ollamaCloudUsageSettingsURL (hardcoded
  official settings page, not configurable - host gate / SSRF surface)
- D9(u): OllamaCloudUsageState.EligibleReason distinguishes
  platform_not_eligible / wrong_account_type / unsupported_base_url
- F5: service usage tests cover ollama_cloud platform (official host
  pass, reverse-proxy fail, oauth reject) and reason codes
2026-09-13 10:38:55 +08:00
alfadb 348f4dc82f feat(platform): align ollama_cloud platform lists for composite routing and pricing
- C11: matchingPlatforms composite branch includes ollama_cloud so channel
  pricing/mapping cache lookups stay consistent with isConcreteRequestPlatform
- C20: openAICompatibleTextTargetAllowed allows ollama_cloud resolved targets
- C21: compositeAvailableModels aggregates ollama_cloud account mapping keys
  (claude default-list fallback already gated off by IsMultiProtocolAPIKeyProvider)
- test sync: composite matchingPlatforms expectation, bulk account event
  rebuild coverage for the ollama_cloud bucket, ollama_cloud text-target case
2026-09-13 10:38:55 +08:00
alfadb 1777ec4b91 feat(platform): admit ollama_cloud to scheduling pool and composite routes 2026-09-13 10:38:55 +08:00
alfadb ab67f3d444 feat(platform): wire ollama_cloud into scheduling and routing
增量 2(⑥ 组 + ⑨ 组,严格同批):

⑥ adaptive 准入 / 协议路由 / base 守卫:
- A9/A13: IsOllamaCloud 谓词 + Account.IsOllamaCloud();
  IsMultiProtocolAPIKeyProvider 纳入 ollama_cloud(adaptive 总开关)
- A11: GetAPIProtocol 缺省档扩为 opencode_go || ollama_cloud → adaptive
- A7/A10 + C30/Q2-3: DefaultOllamaCloudBaseURL(https://ollama.com/v1) /
  DefaultOllamaCloudAnthropicBaseURL(https://ollama.com),并补
  GetOpenAIBaseURL 与 defaultCNProtocolBaseURL 的平台分支
- C33/Q2-4 + S6 层 1: GetOpenAIBaseURL 平台守卫纳入 ollama_cloud;
  多协议账号缺省端点不再回落 https://api.openai.com
- C32: shouldForwardOpenAIResponsesViaRawChatCompletions 新增 ollama_cloud
  分支(不复用 opencode 的恒 false)
- S5: nativeAnthropicTargetURL 改用版本感知 buildOpenAIEndpointURL,
  删除 opencode_go 特判(消灭 /v1/v1/messages)
- S6 层 2: CC / Responses / passthrough 三处 OpenAI 官方域名兜底
  对多协议账号改为显式报错(防凭据外泄)

⑨ count_tokens(必须与 C40 同批):
- findings B1: openai_gateway_count_tokens.go 本地估算分支加入
  IsOllamaCloud()(命中时不产生任何出站请求)
- C40: routes/gateway.go 的 responses 兼容白名单与 count_tokens
  分派白名单加入 service.PlatformOllamaCloud

新增单测 ollama_cloud_platform_routing_test.go:
默认协议/base、nativeAnthropicTargetURL 带与不带 /v1 双向、C32 分流、
count_tokens 本地估算零出站。
2026-09-13 10:38:55 +08:00
alfadb 27b9e2357e fix(ollama): clamp DeepSeek max_output_tokens on all native Responses paths 2026-09-13 10:38:55 +08:00
alfadb 35d05f3d25 fix(ollama): apply DeepSeek reasoning/max_tokens adapter on CC bridge paths 2026-09-13 10:38:55 +08:00
alfadb 8321c57bd6 fix(ollama): normalize DeepSeek reasoning by upstream endpoint, not platform 2026-09-13 10:38:55 +08:00
alfadb 84c5ae94d4 feat(platform): add ollama_cloud platform skeleton
- 新增 PlatformOllamaCloud 常量与 AllowedQuotaPlatforms 白名单
- 同步 ent schema 平台校验(user_platform_quota / channel_monitor /
  channel_monitor_request_template)及生成物
- 新增迁移 239:4 类 CHECK 放宽至 238 的超集(含 ollama_cloud),零 DML 回填
- 新增迁移测试断言 239 为 238 严格超集
- 前端:平台目录、类型联合、配色、图标、i18n 文案
2026-09-13 10:38:55 +08:00
Wesley Liddick bdb42e22f8 Merge pull request #7064 from xlplbo/codex/openai-ws-v2-pool-capacity
fix(openai-ws): 对齐新版 ctx_pool 连接容量计算
2026-09-12 20:13:03 +08:00
Wesley Liddick 9383e0b154 Merge pull request #7057 from Sjeary/codex/issue-7042-max-context-window
fix(codex): 保留本地模型目录的最大上下文窗口
2026-09-12 20:11:40 +08:00
Wesley Liddick c7ed614240 Merge pull request #7001 from SavitarC/feat/ops-token-stats-all-platforms
feat(ops): 扩展 Token 请求统计至所有平台
2026-09-12 19:34:45 +08:00
Wesley Liddick a59f0c7fac Merge pull request #5833 from xuhaihan/fix/openai-fast-missing-tier
fix(openai): force priority when fast tier is omitted
2026-09-12 19:31:21 +08:00
Wesley Liddick 0a378f3432 Merge pull request #7026 from ouchihao/codex/bug-key-quota-reset-state
fix(keys): sync status after resetting quota
2026-09-12 19:30:40 +08:00
Wesley Liddick f2b51e3b24 Merge pull request #7023 from ouchihao/codex/bug-profile-api-errors
fix(profile): show normalized API error messages
2026-09-12 19:30:29 +08:00
Wesley Liddick 329641a86f Merge pull request #7025 from ouchihao/codex/bug-proxy-partial-import-refresh
fix(proxies): refresh the list after partial imports
2026-09-12 19:30:09 +08:00
Wesley Liddick f0dd497780 Merge pull request #7054 from ouchihao/codex/bug-usage-export-filter-snapshot
fix(usage): keep export filters consistent across pages
2026-09-12 19:29:57 +08:00
Wesley Liddick 99b93b2985 Merge pull request #7053 from ouchihao/codex/bug-proxy-filter-pagination
fix(proxies): reset pagination when changing filters
2026-09-12 19:29:41 +08:00
Wesley Liddick 67845665d6 Merge pull request #7050 from ouchihao/codex/bug-balance-email-verification-race
fix(profile): remove verified notification emails by identity
2026-09-12 19:29:24 +08:00
Wesley Liddick 3a070ec1bf Merge pull request #7010 from xpflying/fix/openai-privacy-client-cf-challenge
fix(openai): 隐私/账号检查客户端改用 Firefox 指纹,规避 chatgpt.com Cloudflare 质询
2026-09-12 19:28:09 +08:00
Wesley Liddick 749cd7c354 Merge pull request #7062 from wc4440222/fix/channel-monitor-minimax-provider
fix(channel-monitor): add missing minimax to provider allowlists
2026-09-12 19:27:46 +08:00
Wesley Liddick eaa4083e23 Merge pull request #6995 from alfadb/fix/claude-mid-conversation-output-config
fix(claude): 修复对话中 output_config 的 beta 兼容问题
2026-09-12 19:27:21 +08:00
Wesley Liddick 3873215908 Merge pull request #7049 from xlplbo/perf/openai-ws-pool-queue-wake
perf(openai): WS 连接池排队等待者按账号池变更重选连接
2026-09-12 19:26:56 +08:00
Wesley Liddick 2a4f3d1a71 Merge pull request #7043 from xlplbo/fix/openai-ws-max-conns-factor-default
fix(openai-ws): ctx_pool 每账号连接上限系数默认值改为 5.0
2026-09-12 19:26:26 +08:00
Wesley Liddick 4ff3e6dfb9 Merge pull request #7055 from ouchihao/codex/bug-redeem-profile-refresh
fix(redeem): preserve success when account refresh fails
2026-09-12 19:26:02 +08:00
Wesley Liddick f78c4b241e Merge pull request #7011 from ouchihao/codex/issue-7003-compact-default-model
fix(config): use GPT-5.5 as the default compact model
2026-09-12 19:25:43 +08:00
Wesley Liddick e67ffda7ae Merge pull request #7012 from ouchihao/codex/issue-6982-easypay-upstream-type-dots
fix(payment): allow periods in EasyPay upstream types
2026-09-12 19:24:48 +08:00
Wesley Liddick d2067668d3 Merge pull request #7024 from ouchihao/codex/fix-subscription-assignment-selection
fix(subscriptions): clear assignment user before search debounce
2026-09-12 19:24:00 +08:00
Wesley Liddick ba57ea914b Merge pull request #7052 from ouchihao/codex/issue-2912-transient-auth-failures
fix(auth): preserve sessions during temporary service failures
2026-09-12 19:23:12 +08:00
Wesley Liddick 5948988aae Merge pull request #7022 from ouchihao/codex/issue-3623-accept-encoding-header
fix(gateway): avoid duplicate Accept-Encoding headers
2026-09-12 19:22:44 +08:00
xlplbo 76b3f3c7cf docs(ui): 精简 OpenAI WS 模式提示 2026-09-12 17:38:55 +08:00
xlplbo db15ddf07f docs(ui): 区分 OpenAI WS 开关与连接模式说明 2026-09-12 16:54:22 +08:00
xlplbo 5d5b395d00 docs(ui): 完善 OpenAI WS 模式说明 2026-09-12 16:32:17 +08:00
xlplbo cf3aca6e3b fix(ui): 按 OpenAI WS 模式显示链路提示 2026-09-12 16:28:04 +08:00
xlplbo 956f4672e4 fix(openai-ws): 对齐 OpenAI 新版上下文池容量计算 2026-09-12 16:13:16 +08:00
Wesley Liddick 6206ce940e Merge pull request #6929 from feeeei/fix/gemini-inband-response-signals
fix(gemini): 原生路径登记 2xx 响应里的带内错误信号
2026-09-12 16:08:26 +08:00
Zichen Wang 5968fd0ed9 fix(channel-monitor): add missing minimax to provider allowlists
Fixes #7061

monitorProviders and probeCapableProviders were missing
MonitorProviderMiniMax even though the constant, adapter, ent schema and
error message all already included minimax, so provider=minimax was
rejected by validateProvider.
2026-09-12 15:30:43 +08:00
chihao.ou bb0b50d8bc fix(redeem): preserve success when account refresh fails 2026-09-12 13:50:12 +08:00
chihao.ou 429d6f0480 fix(usage): keep export filters consistent across pages 2026-09-12 13:44:33 +08:00
chihao.ou 5bafffed51 fix(proxies): reset pagination when changing filters 2026-09-12 13:44:05 +08:00
chihao.ou 781a02aea7 fix(auth): preserve sessions during temporary service failures 2026-09-12 13:41:16 +08:00
chihao.ou 3645ce5f43 fix(profile): remove verified notification emails by identity 2026-09-12 13:38:11 +08:00
xlplbo 7cf90c79d6 perf(openai): WS 连接池排队等待者按账号池变更重选连接 2026-09-12 13:01:43 +08:00
Sjeary 195a331322 fix(codex): preserve maximum context window in model catalogs 2026-09-11 21:56:25 -07:00
xlplbo 29371b0819 fix(openai-ws): ctx_pool 每账号连接上限系数默认值改为 5.0 2026-09-12 11:39:05 +08:00