Commit Graph

5144 Commits

Author SHA1 Message Date
Calcium-Ion
8b8ea60b1e Merge pull request #2877 from QuantumNous/refactor/billing-session
refactor: 抽象统一计费会话 BillingSession
v0.10.8-alpha.12
2026-02-07 00:30:23 +08:00
Calcium-Ion
e57bac7c91 Merge pull request #2878 from QuantumNous/feat/hide-subscription-card-when-no-plans
 refactor(wallet): Top-up layout to embed subscription plans into the recharge card tabs
2026-02-07 00:30:07 +08:00
t0ng7u
158baf0493 refactor(wallet): Top-up layout to embed subscription plans into the recharge card tabs
- Defaulting to subscriptions when available and avoiding initial flash when no plans exist.
- Adjust the wide-screen layout to place wallet and invite sections side by side, simplify the subscription header and controls, and add padding to prevent card borders from clipping.
- Update related i18n strings by adding the new tab label and removing the obsolete subscription blurb.
2026-02-07 00:11:00 +08:00
CaIon
15fc77d400 fix: 修复 BillingSession 多个边界问题
- Settle 部分失败保护:新增 fundingSettled 标记,资金来源提交后
  令牌调整失败不再导致 Refund 误退已结算的资金
- 订阅多扣费修复:trySubscription 传 subConsume 而非 preConsumedQuota
  给 preConsume,保证三者(amount/preConsume/FinalPreConsumedQuota)一致
- 令牌回滚错误记录:preConsume 中 funding 失败时令牌回滚错误不再丢弃
- 移除钱包路径死代码:用户额度不足的 strings.Contains 匹配不可能命中
- WalletFunding.Refund 不重试:IncreaseUserQuota 非幂等,重试会多退
2026-02-06 23:41:51 +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
Calcium-Ion
f18aec5281 Merge pull request #2876 from seefs001/fix/json_schema
fix: /v1/chat/completions -> /v1/responses json_schema
2026-02-06 23:08:49 +08:00
Seefs
57059ac73f fix: /v1/chat/completions -> /v1/responses json_schema 2026-02-06 23:03:58 +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
QuentinHsu
8ec16faf28 feat(topup): hide subscription plans card when no plans available 2026-02-06 20:27:25 +08:00
CaIon
04dd761880 fix: update LIKE pattern sanitization for token search
- Change ESCAPE character from '\' to '!' for compatibility with MySQL/PostgreSQL/SQLite
- Adjust sanitization logic to escape '!' and '_' correctly, improving input validation for search queries
v0.10.8-alpha.11
2026-02-06 19:52:35 +08:00
CaIon
5ff9bc3851 chore: add fmt import for improved logging in token controller v0.10.8-alpha.10 2026-02-06 18:01:11 +08:00
Calcium-Ion
053699fa98 Merge commit from fork
fix: harden token search with pagination, rate limiting and input validation
2026-02-06 17:54:40 +08:00
CaIon
3e1be18310 fix: harden token search with pagination, rate limiting and input validation
- Add configurable per-user token creation limit (max_user_tokens)
- Sanitize search input patterns to prevent expensive queries
- Add per-user search rate limiting (by user ID)
- Add pagination to search endpoint with strict page size cap
- Skip empty search fields instead of matching nothing
- Hide internal errors from API responses
- Fix Interface2String float64 formatting causing config parse failures
- Add float-string fallback in config system for int/uint fields
2026-02-06 17:52:19 +08:00
Calcium-Ion
f3d6e99b28 Merge pull request #2863 from prnake/feat/claude-opus-4-6
feat: add claude-opus-4-6
v0.10.8-alpha.9
2026-02-06 16:18:00 +08:00
Calcium-Ion
6de8dea9b9 Merge commit from fork
🔒 fix(security): sanitize AI-generated HTML to prevent XSS in playground
2026-02-06 16:16:20 +08:00
t0ng7u
ab5456eb10 🔒 fix(security): sanitize AI-generated HTML to prevent XSS in playground
Mitigate XSS vulnerabilities in the playground where AI-generated content
is rendered without sanitization, allowing potential script injection via
prompt injection attacks.

MarkdownRenderer.jsx:
- Replace dangerouslySetInnerHTML with a sandboxed iframe for HTML preview
- Use sandbox="allow-same-origin" to block script execution while allowing
  CSS rendering and iframe height auto-sizing
- Add SandboxedHtmlPreview component with automatic height adjustment

CodeViewer.jsx:
- Add escapeHtml() utility to encode HTML entities before rendering
- Rewrite highlightJson() to process tokens iteratively, escaping each
  token and structural text before wrapping in syntax highlighting spans
- Escape non-JSON and very-large content paths that previously bypassed
  sanitization
- Update linkRegex to correctly match URLs containing & entities

These changes only affect the playground (AI output rendering). Admin-
configured content (home page, about page, footer, notices) remains
unaffected as they use separate code paths and are within the trusted
admin boundary.
2026-02-06 15:10:05 +08:00
Papersnake
8e6071f146 Merge branch 'feat/claude-opus-4-6' of https://github.com/prnake/new-api into feat/claude-opus-4-6 2026-02-06 11:59:14 +08:00
Papersnake
729610beb0 fix: set temperature to 1 2026-02-06 11:56:38 +08:00
Papersnake
c9f5de7048 feat: support adaptive thinking 2026-02-06 11:01:23 +08:00
Papersnake
ff71786d8d fix: aws claude 2026-02-06 09:51:15 +08:00
Papersnake
2504818b5a feat: add claude-opus-4-6 2026-02-06 09:12:45 +08:00
CaIon
9a7a29eed8 Remove deprecated components and hooks 2026-02-05 23:04:49 +08:00
CaIon
4d797e0a5b Update .gitattributes to enhance text file handling and mark additional file types for LF normalization and binary detection 2026-02-05 22:57:32 +08:00
CaIon
3766e3248f Add .gitattributes to mark frontend as vendored 2026-02-05 22:53:07 +08:00
CaIon
b55e42eda7 feat(api): add 'cookie' to passthroughSkipHeaderNamesLower v0.10.8-alpha.8 2026-02-05 22:16:35 +08:00
CaIon
af54ea85d2 feat(oauth): implement custom OAuth provider management #1106
- Add support for custom OAuth providers, including creation, retrieval, updating, and deletion.
- Introduce new model and controller for managing custom OAuth providers.
- Enhance existing OAuth logic to accommodate custom providers.
- Update API routes for custom OAuth provider management.
- Include i18n support for custom OAuth-related messages.
2026-02-05 21:18:43 +08:00
CaIon
632baadb57 feat(oauth): migrate GitHub user identification from login to numeric ID 2026-02-05 20:30:48 +08:00
CaIon
df6c669e73 refactor: unify OAuth providers with i18n support
- Introduce Provider interface pattern for standard OAuth protocols
- Create unified controller/oauth.go with common OAuth logic
- Add OAuthError type for translatable error messages
- Add i18n keys and translations (zh/en) for OAuth messages
- Use common.ApiErrorI18n/ApiSuccessI18n for consistent responses
- Preserve backward compatibility for existing routes and data
2026-02-05 20:21:38 +08:00
Calcium-Ion
c540033985 Merge pull request #2853 from QuantumNous/remove/claude-legacy-models
remove: drop support for claude-2 and claude-1 series models
2026-02-05 17:26:29 +08:00
CaIon
1d611d89d2 remove: drop support for claude-2 and claude-1 series models
- Remove claude-instant-1.2, claude-2, claude-2.0, claude-2.1 from model lists
- Remove /v1/complete endpoint support (legacy completion API)
- Remove RequestModeCompletion and related code paths
- Simplify handler functions by removing requestMode parameter
- Update all channel adaptors that referenced claude handlers
2026-02-05 17:20:46 +08:00
Calcium-Ion
7b1451caa7 Merge pull request #2848 from seefs001/fix/gemini-empty-responses-local-usage
fix: charge local input tokens when Gemini returns empty response
2026-02-05 16:24:23 +08:00
Seefs
ecebd619a4 fix: charge local input tokens when Gemini returns empty response 2026-02-05 15:57:17 +08:00
Seefs
9d73aa44b7 Merge pull request #2826 from dahetaoa/fix-codex-and-sqlite
fix: optimize Codex relay
2026-02-05 13:43:09 +08:00
dahetaoa
05ed9d43af fix(relay/codex): optimize headers and ensure instructions presence 2026-02-04 21:43:33 +00:00
Calcium-Ion
3c7687f952 Merge pull request #2842 from QuantumNous/feat/backend-i18n
feat: backend i18n
v0.10.8-alpha.7
2026-02-05 01:57:44 +08:00
Calcium-Ion
a21ee5f9ed Merge pull request #2840 from seefs001/feature/header-regex-override
feat: 支持基于Go Regex规则和全量的请求体透传
2026-02-05 01:56:27 +08:00
Calcium-Ion
b23bae587a Merge pull request #2837 from seefs001/fix/chat2responses_reasoning
fix: map Responses reasoning stream to chat completion deltas
2026-02-05 01:56:12 +08:00
Calcium-Ion
acfcff368a Merge pull request #2839 from QuantumNous/fix/sidebar-scroll-dvh
🐛 fix: sidebar scroll on mobile dynamic viewport
2026-02-05 01:46:32 +08:00
Calcium-Ion
c4b6f8eef0 Merge pull request #2838 from QuantumNous/fix/subscription-epay
 fix: Improve subscription payment handling and card layout consistency
2026-02-05 01:46:18 +08:00
Seefs
f3e6585441 feat: add header passthrough 2026-02-05 01:43:49 +08:00
t0ng7u
89a10cf3f7 🐛 fix: sidebar scroll on mobile dynamic viewport
Use dynamic viewport height to prevent sidebar scroll lock in mobile browsers
Harden sidebar scroll container with min-height and momentum scrolling
2026-02-05 01:42:24 +08:00
t0ng7u
a4617097fb fix: Improve subscription payment handling and card layout consistency
Unify Epay subscription response format with top-up flow, and harden frontend error handling to avoid object-to-string issues. Refine subscription plan cards layout to be wider, left-aligned, and visually consistent across breakpoints.
2026-02-05 01:34:04 +08:00
CaIon
67613e0642 fix(i18n): prioritize user settings over Accept-Language header
The i18n middleware runs before UserAuth, so user settings weren't
available when language was detected. Now GetLangFromContext checks
user settings first (set by UserAuth) before falling back to the
language set by middleware or Accept-Language header.
2026-02-05 00:37:18 +08:00
Seefs
32fae53a3f fix reasoning_effort log 2026-02-05 00:31:52 +08:00
CaIon
42b5aeaae4 fix(i18n): add missing translations and improve language fallback
- Change default language fallback to English instead of Chinese
- Add ErrRedeemFailed typed error for model layer translation
- Migrate remaining hardcoded messages in controller/user.go
- Add translation keys: redeem.failed, user.create_default_token_error, common.uuid_duplicate, common.invalid_input
2026-02-05 00:16:17 +08:00
Seefs
7e13a01a96 fix: map Responses reasoning stream to chat completion deltas
fix: default summary = detailed

fix ReasoningContent

fix ReasoningContent

fix ReasoningContent

fix ReasoningContent

Revert "fix ReasoningContent"

This reverts commit 45a88f78b91ce2376bca68745d19374bb9e95e88.

fix ReasoningContent

fix ReasoningContent
2026-02-05 00:12:16 +08:00
CaIon
f60fce6584 feat(i18n): add backend multi-language support with user language preference
- Add go-i18n library for internationalization
- Create i18n package with translation keys and YAML locale files (zh/en)
- Implement i18n middleware for language detection from user settings and Accept-Language header
- Add Language field to UserSetting DTO
- Update API response helpers with i18n support (ApiErrorI18n, ApiSuccessI18n)
- Migrate hardcoded messages in token, redemption, and user controllers
- Add frontend language preference settings component
- Sync language preference across header selector and user settings
- Auto-restore user language preference on login
2026-02-05 00:09:32 +08:00
CaIon
ded79c7684 feat(i18n): update translations for performance monitoring and cache management across multiple languages 2026-02-04 23:39:56 +08:00
Calcium-Ion
ca91d6992e Merge pull request #2635 from feitianbubu/pr/1a2a0dbd92384bfe886b93606003f6753fcb4e9d
feat: task log show username
2026-02-04 23:39:41 +08:00
Calcium-Ion
65b2ca4176 Merge pull request #2835 from QuantumNous/feat/performance-monitoring
feat(performance): implement system performance monitoring
v0.10.8-alpha.6
2026-02-04 21:34:44 +08:00