2
0
mirror of https://github.com/QuantumNous/new-api.git synced 2026-08-31 02:41:34 +00:00

6268 Commits

Author SHA1 Message Date
CaIon
2b6f1dfefb
fix(model): drop leftover prefill_groups unique constraints before AutoMigrate v1.0.0-rc.29 2026-08-30 23:02:58 +08:00
Calcium-Ion
2bf0820f4b
Revert "fix(model): drop leftover prefill_groups unique constraints before Au…" (#7101)
This reverts commit 69a41eeadc81adb08d04346512c76d62fd6203db.
2026-08-30 22:55:17 +08:00
Seefs
69a41eeadc
fix(model): drop leftover prefill_groups unique constraints before AutoMigrate (#7100) 2026-08-30 22:51:50 +08:00
CaIon
74158715cd
fix initialize database 2026-08-30 22:29:33 +08:00
txgo
b518d0033b
fix(relay): bound the wait for upstream response headers (fixes unbounded heap growth → OOM) (#6949)
* fix(relay): bound the wait for upstream response headers (fixes unbounded heap growth)

The relay transport sets a dial timeout, a TLS handshake timeout and an expect-continue
timeout, but nothing bounds how long it waits for the upstream *response headers* after
the request has been written. An upstream that accepts the connection and then never
answers -- without sending FIN/RST, which is what happens when a NAT/firewall silently
drops the flow or the provider hangs -- parks the goroutine in
net/http.(*persistConn).roundTrip forever.

That goroutine keeps the whole request alive, which in practice means three copies of the
request body stay reachable for the lifetime of the process: the raw bytes from
io.ReadAll in CreateBodyStorageFromReader, the decoded messages held as json.RawMessage,
and the re-marshalled upstream body from common.Marshal. BodyStorageCleanup cannot help
here: it runs after c.Next() returns, and for these requests c.Next() never returns.

Measured on v1.0.0-rc.23 in production (see #6947 for the full evidence):

  - 23 goroutines stuck in persistConn.roundTrip on a single 40h-old instance,
    blocked between 353 and 1894 minutes (5.9h to 31.5h)
  - 96.9% of the live heap, sampled after a forced GC, attributable to those three
    body copies (HeapAlloc 892 MiB surviving three GC cycles; HeapObjects dropping
    30x while bytes dropped only 25%)
  - the live floor grows with uptime: 33.7 MiB at 0.1h, 89.2 at 13.8h, 510.0 at 40.1h,
    955.2 at 146.8h, OOMKilled at 172.9h -- same image, same config, same load

Doubling the memory limit and adding GOMEMLIMIT only moved the OOM from 132h to 172.9h.

RELAY_TIMEOUT (http.Client.Timeout) cannot be used for this: it covers the whole response
read and would cut legitimate long streaming calls, which is why it defaults to 0.
ResponseHeaderTimeout only bounds the wait for the headers; streaming after they arrive is
unaffected.

The default is deliberately generous. Non-streaming upstreams usually send the response
headers only once generation has finished, so the value has to leave room for a long
completion. 1800s is 12x shorter than the shortest hang observed here while leaving
several times the headroom a normal non-streaming request needs; 0 restores the previous
unbounded behaviour.

The assignment goes next to the other transport.* lines rather than inside the else
branch: newRelayHTTPTransport() normally takes the http.DefaultTransport.Clone() path,
and DefaultTransport does not set ResponseHeaderTimeout either.

This repo already sets ResponseHeaderTimeout on its other outbound transports
(controller/model_sync.go, controller/ratio_sync.go); the relay path appears to have
been missed.

Refs #6947. Likely also the root cause of #6731, which reported the same symptom
(production OOM on /v1/responses after ~64h) but was closed for template reasons.

* review: clamp overflowing timeout values and switch the test to testify

Addresses the two CodeRabbit findings on this PR.

Overflow (common/init.go:113): a RELAY_RESPONSE_HEADER_TIMEOUT beyond ~9.2e9 seconds
overflows time.Duration and can wrap into a *tiny positive* timeout, which would cut
every relay request instead of only the stuck ones. The value is now clamped before the
conversion, with regression tests for both the negative and the overflowing input.

I did not add fail-on-startup validation for negative values, for two reasons: the
existing `if seconds > 0` guard already treats them as "disabled", and the neighbouring
env-driven timeouts in this file are less strict still -- RelayIdleConnTimeout is
converted with no guard at all. Failing startup on a bad value would be a behaviour
change out of step with the rest of the file; happy to add it if you'd prefer that
direction repo-wide.

Test style: switched to testify (require.Equal / require.Zero / require.Positive), which
is what every other test under service/ uses.

go build, go vet and go test ./common/... ./service/... pass.
(`go build ./...` fails on the `web/dist` embed both with and without this change -- the
frontend bundle is not checked in.)
v1.0.0-rc.28
2026-08-30 21:18:41 +08:00
CaIon
6eb6f35ed2
fix(model): return string from JSON column Valuers for pg simple protocol
With PrepareStmt disabled, PostgreSQL queries run over pgx's simple
protocol, which encodes every []byte parameter as a bytea hex literal
('\x...'). driver.Valuer implementations returning []byte from
json.Marshal therefore fail json-column writes with SQLSTATE 22P02
(reported on the channels UPDATE path via ChannelInfo).

Reproduced against a live PostgreSQL 16: []byte Valuer into a json
column fails under simple protocol, string succeeds; []byte into a
text column silently stores the hex literal (no such path exists in
the repo today — audited all Valuers, json.RawMessage fields, and raw
SQL call sites).

- ChannelInfo, Properties, TaskPrivateData, JSONValue Value() now
  return string; zero-value nil semantics unchanged. Task.Data
  (bare json.RawMessage) is unaffected — database/sql's default
  converter already passes it as expected.
- Their Scan() counterparts now accept both []byte and string via a
  shared jsonScanBytes helper: SQLite returns string for these columns
  once Value() emits string, and the old []byte-only assertions
  silently zeroed the field (caught by the model test suite).
- Add regression tests locking both contracts: json-column Valuers
  must return string (or nil for zero values), Scanners must accept
  []byte and string.

Verified end-to-end against PostgreSQL 16 with the real model types:
Channel create/update/read-back, Task json fields, PrefillGroup items.
2026-08-30 21:13:21 +08:00
Xayinn
1751f43ee0
fix(sqlite): enable WAL + working busy timeout + _txlock=immediate to stop concurrent write lockouts (#7030)
* fix(sqlite): enable WAL + working busy timeout + _txlock=immediate to stop concurrent write lockouts
2026-08-30 20:46:56 +08:00
ruiyunzhao
b5b94bc685
fix(subscription): 无有效订阅时前端如实显示「仅用订阅」偏好 (#6222) (#7086)
Co-authored-by: Claude <noreply@anthropic.com>
2026-08-30 20:45:24 +08:00
CaIon
dc4732cfed
feat(web): factory task plugins update only with the system
Marketplace install/upgrade on a factory-served plugin actually created
a permanent override shadowing every future built-in release. The card
now shows an informational "Updates with the system" badge instead of
the action, while keeping the built-in vs marketplace version line and
the upgradable state badge visible. Deliberate overrides are untouched:
upload and marketplace actions on overridden or third-party plugins
behave as before, and the plugins table now hints when an override
lags behind the shipped built-in version so operators know deleting it
restores the newer factory plugin.
2026-08-30 20:37:06 +08:00
PuppetKL
0bee5d4410
fix(ali): honor image response format (#5513) (#7048) 2026-08-30 20:33:15 +08:00
CaIon
66031a09d9
fix(model): disable PostgreSQL prepared statements for pooler compatibility
GORM v1.25.2 closes cached prepared statements asynchronously on any SQL
error and immediately re-Parses the same deterministic name (pgx's
stmt_<sha256>) on the same client connection. Transaction-pooling proxies
(PgBouncer >=1.21 with max_prepared_statements, Neon, Supabase) respond
with FATAL "prepared statement name is already in use" (SQLSTATE 08P01)
and drop the connection. PreferSimpleProtocol only disables pgx's
implicit prepare and never covered GORM's explicit PrepareStmt cache.

- PostgreSQL now runs with PrepareStmt disabled entirely; named prepared
  statements are fundamentally session state and cannot be made safe
  under transaction pooling. Parse/plan cost is noise for this workload.
- Upgrade gorm to v1.25.12 so MySQL/SQLite statement caches (still
  enabled) no longer churn close/re-prepare on ordinary SQL errors;
  v1.25.9+ restricts eviction to driver.ErrBadConn. Deliberately not
  v1.26+, whose LRU eviction has an open use-after-close race (#7831).
- sanitizeDBError now attaches a remediation hint on 08P01/42P05 so
  affected deployments can self-diagnose from the log line.
2026-08-30 20:06:32 +08:00
CaIon
6c22550ea3
feat(task): resolve channel-mapped aliases and case variants for plugin models
Channel model_mapping keys exposed in a channel's model list now act as
first-class aliases for task-plugin models across the whole line:

- Derived alias view (model/task_model_alias.go): built from enabled
  channels' model_mapping, chain-following with cycle detection, declared
  names always win, cross-plugin conflicts dropped. Rebuilt on channel
  cache refresh, registry generation change, and a 60s TTL.
- Request path: PinTaskPluginEndpoint resolves declared-name case folds
  and mapping aliases before endpoint lookup (never rewriting the body
  until the endpoint is claimed), pins with MappedModel, and the decode
  contract accepts alias echoes without loosening model ownership for
  normal pins. Legacy /v1/tasks submit folds case variants the same way.
  Fixes aliases on POST /v1/responses silently falling through to the
  main relay against task channels.
- Mapping order: ModelMappedHelper now runs before the plugin submit
  hook builds and caches the upstream body, so channel model_mapping
  actually reaches the upstream request. Plugins receive the mapped
  name as ctx.upstreamModel in both decode and submit contexts.
- Billing: identity stays the origin name; when the alias has no tiered
  expression, the selected channel's mapping tail expression applies.
  Pricing page and billing-expr smoke tests resolve aliases to the
  owning plugin's usage schema.
- Case folding: ASCII-only fold with exact-match priority; same-plugin
  and cross-plugin fold collisions rejected at registration.
- Plugins: model-keyed rate tables, req_key derivation, and combo
  validation in doubao/kling/jimeng/hailuo/vidu/sunoapi now key on
  ctx.upstreamModel || ctx.model; render/echo paths keep ctx.model.
2026-08-30 19:13:51 +08:00
CaIon
918427d8ab
feat(auth): make password encryption opt-in #6743 2026-08-29 20:54:07 +08:00
憧憬Licoy
8454082f93
feat(chat): add AQBot preset (#7079) 2026-08-29 20:34:56 +08:00
CaIon
b80d633cf5
feat(auth): encrypt password login transport
Closes #6743
2026-08-29 20:11:36 +08:00
Seefs
98d50d5383
fix(web): recheck setup status after page reload (#6968) 2026-08-29 19:24:14 +08:00
Alex Xiang
0f2a2075ab
fix(relay): 请求参数校验错误返回 HTTP 400 (#6774)
* fix(relay): return 400 for invalid request parameters
2026-08-29 19:21:09 +08:00
Calcium-Ion
eb48396d5f
feat(task): replace built-in task adaptors with a sandboxed JS plugin system (#7076) v1.0.0-rc.27 2026-08-29 18:51:57 +08:00
Uladzislau
7037ac15bd
fix(docker): add relaykit go.mod to dev build context (#7072) 2026-08-29 18:40:21 +08:00
zcxads666
ac381acf4b
fix(billing): 修复时间规则恒真表达式导致倍率全天生效 (#6934)
Co-authored-by: seefs001 <i@seefs.me>
2026-08-29 13:42:33 +08:00
zcxads666
692e8d6ee6
fix(web): restore admin unbinding for built-in providers (#6987)
* fix(web): align admin binding types

Refs #6985

* test(web): restore animation mock
2026-08-29 13:34:22 +08:00
Seefs
e468b73915
docs: update PR template and remove PR Check workflow (#7053)
* docs: update PR template and remove PR Check workflow

* docs: add hidden agent issue and PR templates
2026-08-27 22:36:44 +08:00
Seefs
ba2e9287bb
feat(ollama): passthrough Claude Messages and OpenAI Responses (#7051) 2026-08-27 21:51:07 +08:00
Seefs
cae3676ec6
feat: glm chanel /v1/responses (#7050) 2026-08-27 21:25:35 +08:00
Seefs
8f6961c675
feat: vllm thinking_token_budget (#7027) v1.0.0-rc.26 2026-08-26 21:06:22 +08:00
CaIon
8c25eee71b
chore(build): upgrade Bun to 1.4.0 2026-08-26 21:04:54 +08:00
Seefs
a073f74b38
refactor: deprecate int32 (#7025)
* refactor: deprecate int32

* fix(db): reject legacy user quota schemas at startup

* fix(quota): enforce wallet bounds and saturating billing conversions

* fix(rate-limit): keep count*duration from wrapping int64

* fix: error message
2026-08-26 20:57:54 +08:00
Seefs
2d8e50bf36
refactor(web): prevent credential autofill in usage log filters (#6966) 2026-08-21 23:47:48 +08:00
Qi
f116414284
fix: settle Responses cached token usage (#6892) v1.0.0-rc.25 2026-08-18 18:24:43 +08:00
RedwindA
137d1171f2
feat(web): fade in streamed response words and harden playground editor (#6895)
* feat(web): fade in newly streamed response words

Animate only new word-level deltas while markdown is still streaming, and
cache markdown-it instances per parser id so concurrent Response trees do
not rebuild or reparse on every render.

* fix(web): keep CodeMirror editor alive across keystroke re-renders

Deliver onKeyDown through a ref instead of the extensions memo so a new
handler identity no longer tears down the EditorView, which reset the
cursor to the document start and made typing appear right-to-left.

* feat(web): add unsaved changes confirmation dialog in PlaygroundMessageEditor

Implement a confirmation dialog to warn users about unsaved changes when attempting to leave the editor. This includes handling the beforeunload event to prevent accidental navigation away from the editor. Additionally, add tests to verify the dialog's behavior under various scenarios.

* test(web): cover beforeunload guard and fade hydration suppression

Address review feedback: add regression tests for the unsaved-changes
beforeunload guard and the first-render fade suppression of hydrated
content, and annotate getCachedMarkdown's return type.
2026-08-18 18:20:53 +08:00
Seefs
4add708ebe
feat: channel test (#6917)
* feat: channel test

* fix: code smell
2026-08-18 18:03:59 +08:00
Seefs
2b0efd8484
refactor: advanced custom channel route editor (#6865)
* refactor: advanced custom channel route editor

* fix(channels): show raw balance response from balance cell
2026-08-18 17:31:21 +08:00
Seefs
3dda1d50c6
fix(relaykit): preserve parameterless tools in Claude conversion (#6862) 2026-08-18 17:30:59 +08:00
QuentinHsu
e2c7aa7b10
test(web): standardize frontend tests on Vitest (#6569)
* test(web): standardize frontend tests on Vitest

- configure Vitest, jsdom, and React Testing Library with shared test scripts.
- migrate existing node:test suites to the Vitest runner.
- rewrite JsonCodeEditor component tests with RTL and remove the direct happy-dom dependency.

* fix(ci): run frontend tests with Vitest

- invoke the configured Vitest script so browser test setup loads in CI.
- migrate remaining node:test suites to Vitest lifecycle APIs.

* test(web): use shared jsdom environment for component tests

- migrate usage cost and tool price tests to React Testing Library.
- remove duplicate happy-dom globals and rely on the configured Vitest setup.

* test(web): verify behavior with shared vitest setup

- replace Node test assertions with Vitest expect across frontend suites.
- migrate Keys component tests to React Testing Library interactions.
- centralize jsdom browser mocks for consistent component execution.

* fix(web): unblock frozen installs and Vitest CI

- sync dompurify 3.4.13 metadata into the Bun lockfile.
- replace the bun:test and happy-dom redemption harness with Vitest and RTL.
- preserve quota conversion, error feedback, and stale-response coverage in jsdom.
2026-08-15 14:18:10 +08:00
Seefs
116255f076
fix(oauth): align custom binding response fields in frontend (#6818)
* fix(oauth): align custom binding response fields in frontend

* fix(oauth): restore custom access policy guidance
2026-08-15 13:56:06 +08:00
zcxads666
4442bb3028
fix(relay): stop injecting empty tools into Claude requests 2026-08-15 13:55:18 +08:00
Seefs
e90a7c48e5
feat: add field passthrough controls for gateway channels (#6847) 2026-08-15 13:54:25 +08:00
Seefs
7d09c6954e
fix: prompt_cache_key openai chat -> openai responses (#6861) 2026-08-15 13:09:50 +08:00
CaIon
47ba9d2c63
fix(topup): guard wallet quota during recharge 2026-08-14 17:34:57 +08:00
dependabot[bot]
bbf67df049
chore(deps-dev): bump electron from 39.8.5 to 39.8.10 in /electron (#6705)
Bumps [electron](https://github.com/electron/electron) from 39.8.5 to 39.8.10.
- [Release notes](https://github.com/electron/electron/releases)
- [Commits](https://github.com/electron/electron/compare/v39.8.5...v39.8.10)

---
updated-dependencies:
- dependency-name: electron
  dependency-version: 39.8.10
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-14 17:02:31 +08:00
dependabot[bot]
cf38105a99
chore(deps-dev): bump js-yaml from 4.3.0 to 4.3.1 in /electron (#6704)
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 4.3.0 to 4.3.1.
- [Changelog](https://github.com/nodeca/js-yaml/blob/4.3.1/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/4.3.0...4.3.1)

---
updated-dependencies:
- dependency-name: js-yaml
  dependency-version: 4.3.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-14 17:01:35 +08:00
Shawn Wang
2a0ce3475c
fix(topup): reject uncreditable orders before payment (#6845)
* fix(topup): reject uncreditable orders before payment

* fix(topup): align zero-ratio Stripe validation

* fix(topup): mirror settlement conversions in validation
2026-08-14 17:01:32 +08:00
dependabot[bot]
e5efc73cdb
chore(deps-dev): bump tar from 7.5.16 to 7.5.22 in /electron (#6468)
Bumps [tar](https://github.com/isaacs/node-tar) from 7.5.16 to 7.5.22.
- [Release notes](https://github.com/isaacs/node-tar/releases)
- [Changelog](https://github.com/isaacs/node-tar/blob/main/CHANGELOG.md)
- [Commits](https://github.com/isaacs/node-tar/compare/v7.5.16...v7.5.22)

---
updated-dependencies:
- dependency-name: tar
  dependency-version: 7.5.22
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-14 17:01:15 +08:00
dependabot[bot]
53a8739eed
chore(deps-dev): bump fast-uri from 3.1.4 to 3.1.5 in /electron (#6846)
Bumps [fast-uri](https://github.com/fastify/fast-uri) from 3.1.4 to 3.1.5.
- [Release notes](https://github.com/fastify/fast-uri/releases)
- [Commits](https://github.com/fastify/fast-uri/compare/v3.1.4...v3.1.5)

---
updated-dependencies:
- dependency-name: fast-uri
  dependency-version: 3.1.5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-14 16:59:05 +08:00
dependabot[bot]
f250f3b589
chore(deps): bump dompurify from 3.4.11 to 3.4.13 in /web (#6735)
Bumps [dompurify](https://github.com/cure53/DOMPurify) from 3.4.11 to 3.4.13.
- [Release notes](https://github.com/cure53/DOMPurify/releases)
- [Commits](https://github.com/cure53/DOMPurify/compare/3.4.11...3.4.13)

---
updated-dependencies:
- dependency-name: dompurify
  dependency-version: 3.4.13
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-14 16:58:37 +08:00
dependabot[bot]
6260580755
chore(deps): bump builder-util-runtime and electron-builder in /electron (#6467)
Bumps [builder-util-runtime](https://github.com/electron-userland/electron-builder/tree/HEAD/packages/builder-util-runtime) to 9.7.0 and updates ancestor dependency [electron-builder](https://github.com/electron-userland/electron-builder/tree/HEAD/packages/electron-builder). These dependencies need to be updated together.


Updates `builder-util-runtime` from 9.5.1 to 9.7.0
- [Release notes](https://github.com/electron-userland/electron-builder/releases)
- [Changelog](https://github.com/electron-userland/electron-builder/blob/master/packages/builder-util-runtime/CHANGELOG.md)
- [Commits](https://github.com/electron-userland/electron-builder/commits/HEAD/packages/builder-util-runtime)

Updates `electron-builder` from 26.7.0 to 26.15.3
- [Release notes](https://github.com/electron-userland/electron-builder/releases)
- [Changelog](https://github.com/electron-userland/electron-builder/blob/master/packages/electron-builder/CHANGELOG.md)
- [Commits](https://github.com/electron-userland/electron-builder/commits/electron-builder@26.15.3/packages/electron-builder)

---
updated-dependencies:
- dependency-name: builder-util-runtime
  dependency-version: 9.7.0
  dependency-type: indirect
- dependency-name: electron-builder
  dependency-version: 26.15.3
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-08-14 16:56:51 +08:00
Scott
93d2df85f8
fix(ali): 修复阿里图片模型映射后仍使用原始模型名判断协议的问题 (#6772)
* feat(ali): support Qwen Image 3 requests

* refactor(ali): narrow Qwen Image 3 support

* fix(ali): focus image model mapping fix
2026-08-14 16:43:39 +08:00
Shawn Wang
15cfdeddef
fix(web): keep fetched model selection in sync with form (#6841)
* fix(web): keep fetched model selection in sync with form

* refactor(web): reuse parsed channel models
2026-08-14 16:40:34 +08:00
wans10
58d4e9bd3b
fix(billing): 异步任务退款时同步减少 used_quota (#6795)
* fix(billing): 异步任务退款时同步减少 used_quota
退款时仅恢复了 quota(剩余额度),但未同步减少 used_quota(已用额度),
导致"总额度"(quota + used_quota)随退款次数持续虚增,超出用户实际充值金额。

修复三处退款路径:
- RefundTaskQuota:任务失败完整退款
- RecalculateTaskQuota:差额结算退款分支
- controller/midjourney.go:Midjourney 任务失败退款

新增 model.UpdateUserUsedQuota 公开函数,仅调整 used_quota 不影响 request_count。

* fix(billing): 任务退款时同步扣减渠道 used_quota

* fix(billing): complete async task refund accounting

* style(model): group internal Midjourney fields

---------

Co-authored-by: CaIon <i@caion.me>
2026-08-13 22:06:40 +08:00
CaIon
ccd535ef8e
fix: harden concurrent quota and status updates 2026-08-11 22:03:47 +08:00