Commit Graph

5236 Commits

Author SHA1 Message Date
CaIon
48c9b17c26 fix(i18n): remove duplicate task ID translations and clean up unused keys across multiple languages 2026-02-22 16:45:35 +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
9976b311ef refactor(task): enhance UpdateWithStatus for CAS updates and add integration tests
- Updated UpdateWithStatus method to use Model().Select("*").Updates() for conditional updates, preventing GORM's INSERT fallback.
- Introduced comprehensive integration tests for UpdateWithStatus, covering scenarios for winning and losing CAS updates, as well as concurrent updates.
- Added task_cas_test.go to validate the new behavior and ensure data integrity during concurrent state transitions.
2026-02-22 16:01:19 +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
76892e8376 refactor(relay): enhance remix logic for billing context extraction
- Updated the remix handling in ResolveOriginTask to prioritize extracting OtherRatios from the BillingContext of the original task if available.
- Retained the previous logic for extracting seconds and size from task data as a fallback.
- Improved clarity and maintainability of the remix logic by separating the new and old approaches.
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
v0.10.9 v0.10.9-alpha.8
2026-02-22 15:41:29 +08:00
Seefs
dbc3236245 Merge pull request #2968 from 0-don/fix/claude-input-text-content-block
fix: normalize input_text content blocks in Claude-to-OpenAI conversion
2026-02-21 14:28:59 +08:00
Seefs
31deb0daac Merge pull request #2973 from RedwindA/feat/modelsdotdev
feat(ratio-sync): support models.dev ratio sync and fix Gemini cache ratios
2026-02-21 14:28:18 +08:00
Seefs
588cbe8ae0 Merge pull request #2976 from wellsgz/codex/aws-claude-sonnet-4-6
feat(aws): add claude-sonnet-4-6 Bedrock mapping and cross-region support
2026-02-21 14:27:18 +08:00
wellsgz
452ac1cdb8 feat: add aws claude-sonnet-4-6 model mapping 2026-02-21 13:24:30 +08:00
CaIon
7aa1590be3 fix: add dynamic route for custom OAuth provider callbacks (#2911)
Custom OAuth providers redirect to /oauth/{slug} after authorization,
but only hardcoded provider routes (github, discord, oidc, linuxdo)
existed in the frontend router, causing a 404 for custom providers.
v0.10.9-alpha.7
2026-02-20 22:01:21 +08:00
RedwindA
333caa7f0c fix: adjust default Gemini cache ratios 2026-02-20 12:28:30 +08:00
RedwindA
afa70518a4 feat: add models.dev preset support to upstream ratio sync 2026-02-20 12:28:26 +08:00
0-don
e8e94e958f fix: normalize input_text content blocks in Claude-to-OpenAI conversion
Clients like OpenClaw send input_text content blocks (a Responses API
type) through /v1/messages. The Claude-to-OpenAI converter silently
drops unknown types, so the message arrives empty at the upstream,
causing "Invalid value: 'input_text'" errors.

Map input_text to text since they share the same structure.
2026-02-19 22:29:40 +01:00
Calcium-Ion
f77381cc75 Merge pull request #2926 from seefs001/fix/status_code_mapping
fix: support numeric status code mapping in ResetStatusCode
v0.10.9-alpha.6
2026-02-12 15:27:36 +08:00
Seefs
cadb4c566d fix: normalize search pagination params to avoid [object Object] 2026-02-12 15:21:51 +08:00
Calcium-Ion
61a5fa39dd Merge pull request #2928 from RedwindA/fix/token-Search
fix(token-search): use TrimPrefix for sk- token normalization
2026-02-12 15:19:34 +08:00
Seefs
c78b37662b fix: ignore header passthrough during channel tests 2026-02-12 15:16:24 +08:00
RedwindA
091a7611b1 fix(token-search): use TrimPrefix for sk- token normalization 2026-02-12 15:12:49 +08:00
Seefs
30fed3cc5c fix: rename bulk test action to skip manually disabled channels 2026-02-12 15:09:30 +08:00
Seefs
4ac59ca6e6 fix: support numeric status code mapping in ResetStatusCode 2026-02-12 14:58:17 +08:00
skynono
30da5bbd08 优化: 任务日志查询速度并显示用户详情 (#2905)
* perf: task log show userinfo

* feat: add Tooltip component to TaskLogsColumnDefs
2026-02-12 14:49:38 +08:00
Weilei
11d5f2ac12 Merge pull request #2916 from worryzyy/feature/add-quota-amount-input
feat(user): add currency amount input with auto quota conversion
2026-02-12 14:48:32 +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 v0.10.9-alpha.5 2026-02-12 01:51:27 +08:00
funkpopo
75e533edb0 feat(xai): 为xAI渠道添加/v1/responses支持 (#2897)
* feat(xai): 为xAI渠道添加/v1/responses支持

* Add video generation model to constants

* fix: 修正先前更改中对于grok-3-mini的思考预算和"-search"设计
2026-02-12 00:42:39 +08:00
CaIon
036c2df423 chore: remove deprecated Docker badge from README 2026-02-11 22:21:02 +08:00
CaIon
f57f7646d3 feat: refactor extra_body handling for improved configuration parsing 2026-02-11 22:15:22 +08:00
CaIon
fd9f1b0026 Update README
# Conflicts:
#	README.fr.md
#	README.ja.md
#	README.md
#	README.zh_CN.md
2026-02-11 22:15:16 +08:00
Seefs
c01bbd006a feat: logs cache field (#2920)
* feat: logs cache field

* feat: logs cache field

* feat: logs cache field
2026-02-11 21:50:39 +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
Calcium-Ion
fb5bc7c4f2 Merge pull request #2917 from QuantumNous/dependabot/npm_and_yarn/web/axios-1.13.5
chore(deps): bump axios from 1.12.0 to 1.13.5 in /web
2026-02-11 19:48:41 +08:00
CaIon
92fc0fca28 fix: update README files to improve link formatting and readability 2026-02-11 18:14:38 +08:00
CaIon
5cc16d6d8f feat: add Aion UI link to README files 2026-02-11 18:05:08 +08:00
dependabot[bot]
8730c47cd0 chore(deps): bump axios from 1.12.0 to 1.13.5 in /web
Bumps [axios](https://github.com/axios/axios) from 1.12.0 to 1.13.5.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.12.0...v1.13.5)

---
updated-dependencies:
- dependency-name: axios
  dependency-version: 1.13.5
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-02-11 09:46:29 +00:00
CaIon
8dad2ad1ba simplify language selector display to use text-only labels
Replace icon-based language options with plain text labels in both the
header dropdown and preferences settings to keep the UI clean and
avoid potential controversies. Remove unused country-flag-icons dependency.
2026-02-11 17:44:31 +08:00
Calcium-Ion
e9aee8bf6b Merge pull request #2909 from seefs001/fix/stream-supported-channel v0.10.9-alpha.4 2026-02-11 02:08:00 +08:00
Seefs
34a5323f14 fix streamSupportedChannels 2026-02-11 01:39:01 +08:00
Calcium-Ion
ba032b72c6 Merge pull request #2898 from seefs001/feature/channel-affinity-tips
optimize: channel affinity tips
v0.10.9-alpha.3
2026-02-08 23:53:45 +08:00
Seefs
8f831fcdb3 fix: channel affinity tips 2026-02-08 23:47:23 +08:00
CaIon
784ad7d23e feat: add project conventions and coding standards documentation for new-api 2026-02-08 20:31:20 +08:00
Calcium-Ion
f4f144bc69 Merge pull request #2896 from seefs001/fix/tips-model-manager
改变端点映射文案
2026-02-08 20:15:58 +08:00
Seefs
19eeeeca4e 改变端点映射文案 2026-02-08 20:12:01 +08:00