1083 Commits

Author SHA1 Message Date
CaIon
9bb2b6a6ae feat: implement token key fetching and masking in API responses 2026-03-08 22:40:40 +08:00
CaIon
3c71e0cd09 fix(video_proxy): update task retrieval to include user ID for improved context 2026-03-06 22:06:42 +08:00
CaIon
8186ed0ea5 fix: update language settings and improve model pricing editor for better clarity and functionality 2026-03-06 21:36:51 +08:00
Seefs
3cb0ca264f fix(relay): skip retries for bad response body errors 2026-03-06 18:22:25 +08:00
feitianbubu
1b85b183e6 fix: fetch model add header passthrough rule key check 2026-03-05 17:49:36 +08:00
Seefs
0a804f0e70 fix: refine upstream update ignore UX and detect behavior 2026-03-03 14:00:48 +08:00
Seefs
e71f5a45f2 feat: auto fetch upstream models (#2979)
* feat: add upstream model update detection with scheduled sync and manual apply flows

* feat: support upstream model removal sync and selectable deletes in update modal

* feat: add detect-only upstream updates and show compact +/- model badges

* feat: improve upstream model update UX

* feat: improve upstream model update UX

* fix: respect model_mapping in upstream update detection

* feat: improve upstream update modal to prevent missed add/remove actions

* feat: add admin upstream model update notifications with digest and truncation

* fix: avoid repeated partial-submit confirmation in upstream update modal

* feat: improve ui/ux

* feat: suppress upstream update alerts for unchanged channel-count within 24h

* fix: submit upstream update choices even when no models are selected

* feat: improve upstream model update flow and split frontend updater

* fix merge conflict
2026-03-02 22:01:53 +08:00
Seefs
0e9198e9b5 fix: preserve explicit zero values in native relay requests 2026-03-01 15:47:03 +08:00
Seefs
99bb41e310 Merge pull request #3009 from seefs001/feature/improve-param-override
feat: improve channel override ui/ux
2026-02-28 18:19:40 +08:00
Seefs
24b427170e fix: redirect subscription payment return to user-accessible page 2026-02-28 15:14:08 +08:00
Seefs
c3291e407a fix: vertex ai video proxy and task polling improvements 2026-02-27 18:47:47 +08:00
Seefs
985189af23 fix: support vertex multi-key task fetch in content proxy 2026-02-27 17:07:10 +08:00
Seefs
5ed997905c fix: align Vertex content fetch flow with Gemini and handle base64 payloads 2026-02-27 16:49:37 +08:00
Seefs
db0b452ea2 Merge branch 'upstream-main' into feature/improve-param-override
# Conflicts:
#	relay/channel/api_request_test.go
#	relay/common/override_test.go
#	web/src/components/table/channels/modals/EditChannelModal.jsx
2026-02-25 13:39:54 +08:00
Calcium-Ion
6d03fc828d Merge pull request #2998 from seefs001/fix/pr-2900
Fix/pr 2900
2026-02-24 13:35:05 +08:00
Seefs
af31935102 fix: check oauthUser.Username length 2026-02-24 13:26:19 +08:00
Seefs
9a5f8222bd feat: move user bindings to dedicated management modal 2026-02-23 14:51:55 +08:00
Calcium-Ion
722b77dc31 Merge pull request #2961 from seefs001/feature/codex-oauth-with-proxy
feat: codex oauth proxy
2026-02-22 23:32:36 +08:00
CaIon
3b6af5dca3 refactor: clean up unused code and improve error logging in adaptor and mjp modules 2026-02-22 22:11:05 +08:00
CaIon
ee414e10c9 feat(mjp): update billing log for failed tasks 2026-02-22 20:34:25 +08:00
Seefs
4831bb7b5b feat: guard new 504/524 status remaps with risk confirmation 2026-02-22 20:03:46 +08:00
CaIon
ec5c6b28ea feat(task): add model redirection, per-call billing, and multipart retry fix for async tasks
1. Async task model redirection (aligned with sync tasks):
   - Integrate ModelMappedHelper in RelayTaskSubmit after model name
     determination, populating OriginModelName / UpstreamModelName on RelayInfo.
   - All task adaptors now send UpstreamModelName to upstream providers:
     - Gemini & Vertex: BuildRequestURL uses UpstreamModelName.
     - Doubao & Ali: BuildRequestBody conditionally overwrites body.Model.
     - Vidu, Kling, Hailuo, Jimeng: convertToRequestPayload accepts RelayInfo
       and unconditionally uses info.UpstreamModelName.
     - Sora: BuildRequestBody parses JSON and multipart bodies to replace
       the "model" field with UpstreamModelName.
   - Frontend log visibility: LogTaskConsumption and taskBillingOther now
     emit is_model_mapped / upstream_model_name in the "other" JSON field.
   - Billing safety: RecalculateTaskQuotaByTokens reads model name from
     BillingContext.OriginModelName (via taskModelName) instead of
     task.Data["model"], preventing billing leaks from upstream model names.

2. Per-call billing (TaskPricePatches lifecycle):
   - Rename TaskBillingContext.ModelName → OriginModelName; add PerCallBilling
     bool field, populated from TaskPricePatches at submission time.
   - settleTaskBillingOnComplete short-circuits when PerCallBilling is true,
     skipping both adaptor adjustments and token-based recalculation.
   - Remove ModelName from TaskSubmitResult; use relayInfo.OriginModelName
     consistently in controller/relay.go for billing context and logging.

3. Multipart retry boundary mismatch fix:
   - Root cause: after Sora (or OpenAI audio) rebuilds a multipart body with a
     new boundary and overwrites c.Request.Header["Content-Type"], subsequent
     calls to ParseMultipartFormReusable on retry would parse the cached
     original body with the wrong boundary, causing "NextPart: EOF".
   - Fix: ParseMultipartFormReusable now caches the original Content-Type in
     gin context key "_original_multipart_ct" on first call and reuses it for
     all subsequent parses, making multipart parsing retry-safe globally.
   - Sora adaptor reverted to the standard pattern (direct header set/get),
     which is now safe thanks to the root fix.

4. Tests:
   - task_billing_test.go: update makeTask to use OriginModelName; add
     PerCallBilling settlement tests (skip adaptor adjust, skip token recalc);
     add non-per-call adaptor adjustment test with refund verification.
2026-02-22 16:33:00 +08:00
CaIon
5ec4633cb8 refactor(task): add CAS-guarded updates to prevent concurrent billing conflicts
Replace all bare task.Update() (DB.Save) calls with UpdateWithStatus(),
which adds a WHERE status = ? guard to prevent concurrent processes from
overwriting each other's state transitions.

Key changes:

model/task.go:
- Add taskSnapshot struct with Equal() method for change detection
- Add Snapshot() method to capture pre-update state
- Add UpdateWithStatus(fromStatus) using DB.Where().Save() for CAS
  semantics with full-struct save (no explicit field listing needed)

model/midjourney.go:
- Add UpdateWithStatus(fromStatus string) with same CAS pattern

service/task_polling.go (updateVideoSingleTask):
- Snapshot before processing upstream response; skip DB write if unchanged
- Terminal transitions (SUCCESS/FAILURE) use UpdateWithStatus CAS:
  billing/refund only executes if this process wins the transition
- Non-terminal updates also use UpdateWithStatus to prevent overwriting
  a concurrent terminal transition back to IN_PROGRESS
- Defer settleTaskBillingOnComplete to after CAS check (shouldSettle flag)

relay/relay_task.go (tryRealtimeFetch):
- Add snapshot + change detection; use UpdateWithStatus for CAS safety

controller/midjourney.go (UpdateMidjourneyTaskBulk):
- Capture preStatus before mutations; use UpdateWithStatus CAS
- Gate refund (IncreaseUserQuota) on CAS success (won && shouldReturnQuota)

This prevents the multi-instance race condition where:
1. Instance A reads task (IN_PROGRESS), fetches upstream (still IN_PROGRESS)
2. Instance B reads same task, fetches upstream (now SUCCESS), writes SUCCESS
3. Instance A's bare Save() overwrites SUCCESS back to IN_PROGRESS
2026-02-22 16:01:19 +08:00
CaIon
cda540180b refactor(relay): improve channel locking and retry logic in RelayTask
- Enhanced the RelayTask function to utilize a locked channel when available, allowing for better reuse during retries.
- Updated error handling to ensure proper context setup for the selected channel.
- Clarified comments in ResolveOriginTask regarding channel locking and retry behavior.
- Introduced a new field in TaskRelayInfo to store the locked channel object, improving type safety and reducing import cycles.
2026-02-22 16:01:19 +08:00
CaIon
a920d1f925 refactor(relay): rename RelayTask to RelayTaskFetch and update routing
- Renamed RelayTask function to RelayTaskFetch for clarity.
- Updated routing in relay-router.go and video-router.go to use RelayTaskFetch for fetch operations.
- Enhanced error handling in RelayTaskFetch function.
- Adjusted task data conversion in TaskAdaptor to include task ID.
2026-02-22 16:01:19 +08:00
CaIon
809ba92089 refactor(logs): add refund logging for asynchronous tasks and update translations 2026-02-22 16:01:19 +08:00
CaIon
d6e11fd2e1 feat(task): add adaptor billing interface and async settlement framework
Add three billing lifecycle methods to the TaskAdaptor interface:
- EstimateBilling: compute OtherRatios from user request before pricing
- AdjustBillingOnSubmit: adjust ratios from upstream submit response
- AdjustBillingOnComplete: determine final quota at task terminal state

Introduce BaseBilling as embeddable no-op default for adaptors without
custom billing. Move Sora/Ali OtherRatios logic from shared validation
into per-adaptor EstimateBilling implementations.

Add TaskBillingContext to persist pricing params (model_price, group_ratio,
other_ratios) in task private data for async polling settlement.

Extract RecalculateTaskQuota as a general-purpose delta settlement
function and unify polling billing via settleTaskBillingOnComplete
(adaptor-first, then token-based fallback).
2026-02-22 16:00:27 +08:00
CaIon
9e3954428d refactor(task): extract billing and polling logic from controller to service layer
Restructure the task relay system for better separation of concerns:
- Extract task billing into service/task_billing.go with unified settlement flow
- Move task polling loop from controller to service/task_polling.go (supports Suno + video platforms)
- Split RelayTask into fetch/submit paths with dedicated retry logic (taskSubmitWithRetry)
- Add TaskDto, TaskResponse generics, and FetchReq to dto/task.go
- Add taskcommon/helpers.go for shared task adaptor utilities
- Remove controller/task_video.go (logic consolidated into service layer)
- Update all task adaptors (ali, doubao, gemini, hailuo, jimeng, kling, sora, suno, vertex, vidu)
- Simplify frontend task logs to use new TaskDto response format
2026-02-22 16:00:27 +08:00
Seefs
e0a6ee1cb8 imporve oauth provider UI/UX (#2983)
* feat: imporve UI/UX

* fix: stabilize provider enabled toggle and polish custom OAuth settings UX

* fix: add access policy/message templates and persist advanced fields reliably

* fix: move template fill actions below fields and keep advanced form flow cleaner
2026-02-22 15:41:29 +08:00
Seefs
91b300f522 feat: unify param/header overrides with retry-aware conditions and flexible header operations 2026-02-22 00:45:49 +08:00
Seefs
ff76e75f4c feat: add retry-aware param override with return_error and prune_objects 2026-02-22 00:10:49 +08:00
RedwindA
afa70518a4 feat: add models.dev preset support to upstream ratio sync 2026-02-20 12:28:26 +08:00
Seefs
20c9002fde feat: codex oauth proxy 2026-02-17 18:00:10 +08:00
Calcium-Ion
f77381cc75 Merge pull request #2926 from seefs001/fix/status_code_mapping
fix: support numeric status code mapping in ResetStatusCode
2026-02-12 15:27:36 +08:00
Seefs
30fed3cc5c fix: rename bulk test action to skip manually disabled channels 2026-02-12 15:09:30 +08:00
Calcium-Ion
eecec32819 feat: add OpenRouter pricing support to upstream ratio sync (#2925) 2026-02-12 14:46:37 +08:00
CaIon
eca4eff5f0 feat: Improve backend multilingual support 2026-02-12 14:29:56 +08:00
RedwindA
b1ef7d1517 feat: add OpenRouter pricing support to upstream ratio sync 2026-02-12 12:57:27 +08:00
CaIon
197b89ea58 feat: refactor request body handling to use BodyStorage for improved efficiency 2026-02-12 01:51:27 +08:00
Oliver Tzeng
6597610395 feat(localization): added zh_TW (#2913)
* feat(localization): added zh_TW

* fixed based on @coderabbitai

* updated false translation for zh_TW

* new workflow

* revert

* fixed a lot of translations

* turned most zh to zh-CN

* fallbacklang

* bruh

* eliminate ALL _

* fix: paths and other miscs thanks @Calcium-Ion

* fixed translation and temp fix for preferencessettings.js

* fixed translation error

* fixed issue about legacy support

* reverted stupid coderabbit's suggestion
2026-02-11 20:37:53 +08:00
feitianbubu
e5d47daf26 feat: allow custom username for new users 2026-02-09 15:03:53 +08:00
Calcium-Ion
7a146a11f5 Merge pull request #2870 from seefs001/feature/cache-creation-configurable
feat: make 5m cache-creation ratio configurable
2026-02-08 00:28:42 +08:00
Calcium-Ion
83a5245bb1 Merge pull request #2875 from seefs001/feature/channel-test-stream
feat: channel test with stream=true
2026-02-08 00:17:07 +08:00
Calcium-Ion
8e1a990b45 Merge pull request #2857 from QuantumNous/feat/custom-oauth
feat(oauth): implement custom OAuth provider
2026-02-08 00:13:20 +08:00
CaIon
0c0ccf510b refactor: 抽象统一计费会话 BillingSession
将散落在多个文件中的预扣费/结算/退款逻辑抽象为统一的 BillingSession 生命周期管理:

- 新增 BillingSettler 接口 (relay/common/billing.go) 避免循环引用
- 新增 FundingSource 接口 + WalletFunding / SubscriptionFunding 实现 (service/funding_source.go)
- 新增 BillingSession 封装预扣/结算/退款原子操作 (service/billing_session.go)
- 新增 SettleBilling 统一结算辅助函数,替换各 handler 中的 quotaDelta 模式
- 重写 PreConsumeBilling 为 BillingSession 工厂入口
- controller/relay.go 退款守卫改用 BillingSession.Refund()

修复的 Bug:
- 令牌额度泄漏:PreConsumeTokenQuota 成功但 DecreaseUserQuota 失败时未回滚
- 订阅退款遗漏:FinalPreConsumedQuota=0 但 SubscriptionPreConsumed>0 时跳过退款
- 订阅多扣费:subConsume 强制为 1 但 FinalPreConsumedQuota 不同步
- 退款路径不统一:钱包/订阅退款逻辑现统一由 FundingSource.Refund 分派
2026-02-06 23:14:25 +08:00
Seefs
fac9c367b1 fix: auto default codex to /v1/responses without overriding user-selected endpoint 2026-02-06 22:08:55 +08:00
Seefs
23227e18f9 feat: channel test stream 2026-02-06 21:57:38 +08:00
CaIon
d814d62e2f refactor: enhance API security with read-only token authentication and improved rate limiting 2026-02-06 21:26:26 +08:00
Seefs
50ee4361d0 feat: make 5m cache-creation ratio configurable 2026-02-06 19:46:59 +08:00
CaIon
5ff9bc3851 chore: add fmt import for improved logging in token controller 2026-02-06 18:01:11 +08:00