Commit Graph

386 Commits

Author SHA1 Message Date
CaIon 6bde1a9c8d Merge origin/main into nightly
Resolve conflicts:
- .gitignore: keep nightly additions (.test, skills-lock.json)
- relay/helper/price.go: keep both billingexpr and model imports
- en.json / zh-CN.json: keep nightly's superset of i18n entries
- service/billing_session.go: add missing 3rd arg to DecreaseUserQuota
- en.json / zh-CN.json: deduplicate 129+320 duplicate i18n keys
2026-04-23 21:37:03 +08:00
CaIon 5c4ed5be99 fix(billing): use tieredQuota fallback in composeTieredTextQuota error path
Remove the intermediate branch that recomputed quota from
EstimatedQuotaBeforeGroup when tieredResult is nil. This discarded the
FinalPreConsumedQuota fallback that TryTieredSettle already selected.
Now the error path simply adds tool surcharges to the passed-in
tieredQuota, preserving the existing fallback semantics.

Also removes unrelated mise.toml and adds a test covering the error
fallback with a pre-consumed quota that differs from the estimate.
2026-04-23 18:59:48 +08:00
Seefs e729b22197 fix: refresh codex credentials for auto-disabled channels (#4324) 2026-04-22 22:54:52 +08:00
Seefs f995a868e4 Merge pull request #4089 from seefs001/feature/waffo-pay
rafactor: payment
2026-04-18 14:22:54 +08:00
CaIon 22e509c1ef refactor: simplify ShouldDisableChannel function by removing unused parameters and commented-out code 2026-04-16 20:56:44 +08:00
CaIon 8c8661d0d7 refactor: clean up unused imports and commented-out code in channel.go 2026-04-13 16:39:12 +08:00
CaIon 040e8c1da8 feat: replace quota input with amount-first UI and atomic quota adjustment
- Refactor token, redemption, and user quota inputs to prioritize monetary
  amount entry, with raw quota input collapsed by default
- Add atomic quota adjustment modal for users with add/subtract/override modes,
  bypassing batch update queue for immediate DB consistency
- Make user quota fields readonly in edit form; all modifications go through
  the dedicated adjust-quota modal via POST /api/user/manage
- Add DecreaseUserQuota `db` parameter for direct DB writes, matching
  IncreaseUserQuota behavior
- Support negative quota display in amount conversion helpers
- Add i18n keys for all new UI strings across all locales
2026-04-09 22:44:53 +08:00
yyhhyyyyyy 1fe9f6f989 fix(billing): preserve text tool surcharges in tiered settlement 2026-04-09 18:18:01 +08:00
CaIon 4d2993e4cc Merge remote-tracking branch 'origin/main' into nightly
# Conflicts:
#	web/src/helpers/render.jsx
#	web/src/hooks/usage-logs/useUsageLogsData.jsx
#	web/src/i18n/locales/en.json
2026-04-09 17:12:21 +08:00
Seefs 1ad2557668 Merge pull request #3488 from clansty/feature/channel-affinity-include-model
feat: add IncludeModelName option to channel affinity rules
2026-04-08 11:54:31 +08:00
CaIon 03758a4a85 refactor(file-source): unify file source creation and enhance caching mechanisms 2026-04-06 15:54:55 +08:00
CaIon 8fc0eb78e2 feat(billing): enhance task billing process with video input detection and updated pricing logic
- Added `EstimateBilling` function to check for video input in request metadata and return corresponding discount ratios.
- Updated `ModelPriceHelperPerCall` to incorporate new pricing logic based on model ratios and video input.
- Enhanced task billing logs to include model ratio information and adjusted calculations for actual quota based on additional multipliers.
- Introduced `renderTaskBillingProcess` to improve rendering of task billing information in the UI.
2026-04-06 15:54:55 +08:00
Seefs 82c2008d2c fix: emit claude message_delta for usage-only final stream chunk 2026-04-04 20:21:13 +08:00
RedwindA f449e06b9d fix: handle ISOBMFF extended sizes in HEIF dimension parser
parseHEIFDimensions now correctly handles boxSize==1 (64-bit extended
size) and boxSize==0 (box-to-EOF), preventing the parser from breaking
out of the loop when encountering these valid ISOBMFF box headers
before reaching the meta box.
2026-04-02 17:01:21 +08:00
RedwindA 79527c0ab1 feat: add HEIC/HEIF image format support
Add detection, MIME type mapping, and dimension parsing for HEIC/HEIF
images via ISOBMFF ftyp brand inspection and ispe box parsing. Update
Gemini relay to accept these formats and refactor getImageConfig to
properly retry decoders using buffered data.
2026-04-02 16:40:45 +08:00
CaIon 35d0704640 Merge branch 'origin/main' into nightly
Resolve 4 conflicts:
- relay/compatible_handler.go: accept main's refactor (postConsumeQuota -> service.PostTextConsumeQuota)
- service/quota.go: accept main's PostClaudeConsumeQuota deletion, keep nightly's tiered billing in PostWssConsumeQuota and PostAudioConsumeQuota
- web/src/i18n/locales/{en,zh-CN}.json: merge both sets of translation keys

Post-merge integration:
- Add tiered billing (TryTieredSettle, InjectTieredBillingInfo) to PostTextConsumeQuota
- Update tool pricing calls to use nightly's generic GetToolPriceForModel/GetToolPrice API
2026-04-02 00:39:13 +08:00
CaIon 5238f279db feat: record stream interruption reasons via StreamStatus
- Add StreamStatus type (relay/common) to track stream end reason
  (done/timeout/client_gone/scanner_error/eof/panic/ping_fail) and
  accumulate soft errors during streaming via sync.Once + sync.Mutex.
- Add StreamResult (relay/helper) as the callback interface: adapters
  call sr.Error() for soft errors, sr.Stop() for fatal, sr.Done() for
  normal completion. No early-return problem — multiple errors per chunk
  are naturally supported.
- Refactor StreamScannerHandler callback from func(string) bool to
  func(string, *StreamResult). All 9 channel adapters updated.
- Write stream_status into log other JSON field (admin-only) with
  status ok/error, end_reason, error_count, and error messages.
- Frontend: display stream status in log detail expansion for admins.
2026-03-31 16:54:39 +08:00
Clansty 70560d5371 feat: add IncludeModelName option to channel affinity rules for per-model affinity tracking 2026-03-29 02:22:24 +08:00
Seefs 926e1781dd fix: preserve cache usage in openai-to-claude response conversion 2026-03-25 13:49:21 +08:00
Seefs d4a470a638 fix: restore pre-3400 OpenRouter billing semantics 2026-03-25 13:24:52 +08:00
Seefs 9f61407bf0 fix: restore pre-3400 OpenRouter billing semantics 2026-03-25 13:11:51 +08:00
Calcium-Ion 0191a68d4e Merge pull request #3400 from seefs001/fix/openai-usage
refactor: optimize billing flow for OpenAI-to-Anthropic convert
2026-03-23 15:03:57 +08:00
Seefs 9ecad90652 refactor: optimize billing flow for OpenAI-to-Anthropic convert 2026-03-23 14:22:12 +08:00
Seefs b09337e6ed fix: honor channel affinity skip-retry when preferred channel is disabled 2026-03-18 16:08:31 +08:00
Seefs 5db25f47f1 feat: add param override audit modal for usage logs 2026-03-17 17:00:01 +08:00
CaIon 6e3ef48c9b feat: implement tool pricing settings UI and enhance tool call quota calculations 2026-03-17 16:59:25 +08:00
CaIon c5405b2a12 feat: add billing expression system documentation and enhance tiered billing logic
- Introduced a new rule for the Billing Expression System, emphasizing the importance of reading `pkg/billingexpr/expr.md` for dynamic billing.
- Updated the billing expression logic to support new variables and improved handling of image and audio tokens.
- Enhanced the tiered billing functionality with versioning support for expressions and refined quota calculations.
- Added tests to validate the new billing expression features and ensure correctness in pricing calculations.
2026-03-17 16:59:25 +08:00
CaIon 5b03b39db2 feat: enhance tiered billing logic and improve variable handling in pricing calculations 2026-03-17 16:59:25 +08:00
CaIon f6c0852da9 refactor: update billing calculations to use quota per unit
- Adjusted billing calculations in tests and core logic to incorporate a new QuotaPerUnit field.
- Modified estimated quota calculations to reflect changes in tiered billing logic.
- Updated related tests to ensure accuracy with the new quota calculations.
- Enhanced dynamic pricing components to align with updated billing expressions.
2026-03-17 16:59:25 +08:00
CaIon f0589cc478 feat: enhance tiered billing functionality and UI components
- Introduced new fields for billing mode and expression in the Pricing model.
- Implemented dynamic pricing breakdown component to display tiered billing details.
- Updated various components to support and render tiered billing information.
- Enhanced pricing calculation logic to accommodate dynamic pricing scenarios.
- Added tests for new billing expression functionalities and UI components.
2026-03-17 16:59:25 +08:00
CaIon 91ed4e196a feat: implement tiered billing expression evaluation and related functionality
- Added support for tiered billing expressions in the billing system.
- Introduced new types and functions for handling billing expressions, including caching and execution.
- Updated existing billing logic to accommodate tiered billing scenarios.
- Enhanced request handling to support incoming billing expression requests.
- Added tests for tiered billing functionality to ensure correctness.
2026-03-17 16:59:25 +08:00
Nekohy 1b17986283 delete some if 2026-03-05 06:24:22 +08:00
Nekohy a4629f2630 feats: repair the thinking of claude to openrouter convert 2026-03-05 06:12:48 +08:00
feitianbubu 4798165272 fix: update task billing log content to include reason 2026-03-03 12:37:43 +08:00
Seefs 70821e2051 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 ad326beb10 Merge pull request #3066 from seefs001/fix/aws-header-override
Fix/aws header override
2026-03-02 18:54:56 +08:00
CaIon 4b61c54c41 fix: handle rate limits and improve error response parsing in video task updates 2026-03-02 17:11:57 +08:00
Seefs 2cf3c1836c fix: preserve explicit zero values in native relay requests 2026-03-01 15:47:03 +08:00
Seefs 8103b4b1a7 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 a33a3eae87 fix: vertex ai video proxy and task polling improvements 2026-02-27 18:47:47 +08:00
Seefs a955d4102d refactor(override): simplify header overrides to a lowercase single map 2026-02-25 17:24:18 +08:00
Seefs e027f38244 feat:add CLI param-override templates with visual editor and apply on first rule match 2026-02-25 15:08:23 +08:00
Seefs b15ad2924e fix: violation fee check 2026-02-23 22:02:59 +08:00
Calcium-Ion c948652647 Merge pull request #2961 from seefs001/feature/codex-oauth-with-proxy
feat: codex oauth proxy
2026-02-22 23:32:36 +08:00
Seefs 8cfc2b4398 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 c1b05d3b5a refactor: clean up unused code and improve error logging in adaptor and mjp modules 2026-02-22 22:11:05 +08:00
CaIon 7bc0bf21f3 feat(mjp): update billing log for failed tasks 2026-02-22 20:34:25 +08:00
CaIon bc7c5cf9cf 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.
2026-02-22 17:59:38 +08:00
CaIon 06fe03e34c 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 374aabf301 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