Commit Graph

5290 Commits

Author SHA1 Message Date
Seefs
3286f3da4d feat: support token-map rewrite for comma-separated headers and add bedrock anthropic-beta preset 2026-02-27 19:47:32 +08:00
Seefs
6c6096f706 refactor(override): simplify header overrides to a lowercase single map 2026-02-25 17:24:18 +08:00
Seefs
305dbce4ad fix: merge runtime and channel header overrides, skip missing source headers 2026-02-25 16:12:34 +08:00
Seefs
bb0c663dbe fix pass_headers 2026-02-25 15:39:49 +08:00
Seefs
0519446571 feat:add CLI param-override templates with visual editor and apply on first rule match 2026-02-25 15:08:23 +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
CaIon
4a4cf0a0df fix: improve multipart form data handling by detecting content type. fix #3007 v0.11.0-alpha.9 2026-02-25 12:51:46 +08:00
CaIon
c5365e4b43 feat(middleware): add RouteTag middleware for enhanced logging and routing
- Introduced RouteTag middleware to set route tags for different API endpoints.
- Updated logger to include route tags in log output.
- Applied RouteTag middleware across various routers including API, dashboard, relay, video, and web routers for consistent logging.
2026-02-25 00:11:24 +08:00
CaIon
0da0d80647 fix: handle nil setting in user retrieval from database v0.11.0-alpha.8 2026-02-24 23:46:46 +08:00
Calcium-Ion
aa9e0fe7a8 Merge pull request #3002 from RedwindA/feat/zeroMatchHint
feat(web): add custom-model create hint and i18n translations
v0.11.0-alpha.7
2026-02-24 22:05:05 +08:00
RedwindA
79e1daff5a feat(web): add custom-model create hint and i18n translations 2026-02-24 21:44:21 +08:00
CaIon
4c7e65cb24 feat: add comprehensive tests for StreamScannerHandler functionality
- Introduced a new test file for StreamScannerHandler, covering various scenarios including nil inputs, empty bodies, chunk processing, order preservation, and handler failures.
- Enhanced error handling and data processing logic in StreamScannerHandler to improve robustness and performance.
2026-02-24 17:36:08 +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
Calcium-Ion
d2553564e0 Merge pull request #2993 from seefs001/feature/user-oauth-detail
feat: move user bindings to dedicated management modal
2026-02-24 13:01:10 +08:00
Seefs
a7c35cd61e Merge pull request #2997 from Caisin/fix/issue-2214-accept-encoding-passthrough
fix: skip Accept-Encoding during header passthrough (#2214)
2026-02-24 12:42:46 +08:00
hekx
98de082804 fix: skip Accept-Encoding during header passthrough (#2214) 2026-02-24 09:58:50 +08:00
Calcium-Ion
0d0f7473d4 Merge pull request #2994 from seefs001/fix/grok-violates-check
fix: violation fee check
v0.11.0-alpha.6
2026-02-23 22:03:52 +08:00
Seefs
532691b06b fix: violation fee check 2026-02-23 22:02:59 +08:00
CaIon
0835e15091 fix: enhance data trimming and validation in stream scanner 2026-02-23 17:42:22 +08:00
CaIon
80c213072c fix: improve multipart form data handling in gin context
- Added caching for the original Content-Type header in the parseMultipartFormData function.
- This change ensures that the Content-Type is retrieved from the context if previously set, enhancing performance and consistency.
v0.11.0-alpha.5
2026-02-23 16:59:46 +08:00
Seefs
2f4d38fefd refactor: extract binding modal and polish binding management UX 2026-02-23 15:16:22 +08:00
Seefs
9a5f8222bd feat: move user bindings to dedicated management modal 2026-02-23 14:51:55 +08:00
CaIon
016812baa6 feat: implement caching for channel retrieval 2026-02-23 14:11:11 +08:00
Calcium-Ion
d0b35ed60b Merge pull request #2959 from seefs001/fix/gemini-tool-use-token
fix: unify usage mapping and include toolUsePromptTokenCount
v0.11.0-alpha.4
2026-02-22 23:35:09 +08:00
Calcium-Ion
4b058b4a1d Merge pull request #2960 from seefs001/feature/minimax-native-claude
feat: minimax native /v1/messages
2026-02-22 23:32:53 +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
Calcium-Ion
77838100a6 feat: add missing OpenAI/Claude/Gemini request fields (#2971)
* feat: add missing OpenAI/Claude/Gemini request fields and responses stream options

* fix: skip field filtering when request passthrough is enabled

* fix: include subscription in personal sidebar module controls

* feat: gate Claude inference_geo passthrough behind channel setting and add field docs
2026-02-22 23:31:18 +08:00
Seefs
a01a77fc6f fix: claude affinity cache counter (#2980)
* fix: claude affinity cache counter

* fix: claude affinity cache counter

* fix: stabilize cache usage stats format and simplify modal rendering
2026-02-22 23:30:02 +08:00
CaIon
3b87d31191 feat: add audio preview functionality 2026-02-22 23:23:13 +08:00
CaIon
3b6af5dca3 refactor: clean up unused code and improve error logging in adaptor and mjp modules v0.11.0-alpha.3 2026-02-22 22:11:05 +08:00
CaIon
af2831ce31 feat: add validation for invalid status code entries in channel modal
- Introduced a new function to collect invalid status code entries from the status code mapping.
- Updated the EditChannelModal to display an error message if invalid status codes are detected.
- Enhanced localization files to include new error messages for invalid status codes in multiple languages.
- Removed unused styles from the RiskAcknowledgementModal for cleaner UI.
2026-02-22 21:36:38 +08:00
CaIon
ee414e10c9 feat(mjp): update billing log for failed tasks 2026-02-22 20:34:25 +08:00
Calcium-Ion
3523947aba Merge pull request #2987 from seefs001/feature/channel-retry-warning
Feature/channel retry warning
2026-02-22 20:33:05 +08:00
Seefs
c4c4e5eda6 feat: add localized high-risk status remap guard with optimized modal UX 2026-02-22 20:14:56 +08:00
Seefs
4831bb7b5b feat: guard new 504/524 status remaps with risk confirmation 2026-02-22 20:03:46 +08:00
CaIon
f4dded51ab Update README 2026-02-22 18:24:42 +08:00
CaIon
13ada6484a feat(task): introduce task timeout configuration and cleanup unfinished tasks
- Added TaskTimeoutMinutes constant to configure the timeout duration for asynchronous tasks.
- Implemented sweepTimedOutTasks function to identify and handle unfinished tasks that exceed the timeout limit, marking them as failed and processing refunds if applicable.
- Enhanced task polling loop to include the new timeout handling logic, ensuring timely cleanup of stale tasks.
v0.11.0-alpha.2
2026-02-22 17:59:38 +08:00
Seefs
303fff44e7 feat: add pass_headers op, grouped presets (incl. Gemini 4K), and robust JSON fallback 2026-02-22 17:16:57 +08:00
Calcium-Ion
902661df3f Merge pull request #2985 from QuantumNous/refactor/async-task-merge
refactor: async task
v0.11.0-alpha.1
2026-02-22 16:59:56 +08:00
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