From e537336591d36291aa139b823032d719e113b533 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Sun, 11 Oct 2026 00:19:06 +0800 Subject: [PATCH] v0.70.0 Upstream balances (OpenRouter, DeepSeek, Moonshot, Sub2API, New API / One API, ThinkWatch Enterprise) with the pre-release review fixes, the spent amount's scope, and the Z.ai / BigModel sign-in marker. Protocol 46. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 38 +++++++++++++++++++------------------- Cargo.toml | 2 +- release-notes/0.70.0.md | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 release-notes/0.70.0.md diff --git a/Cargo.lock b/Cargo.lock index 11a574cf..ff154efe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3143,7 +3143,7 @@ dependencies = [ [[package]] name = "tw-api" -version = "0.69.0" +version = "0.70.0" dependencies = [ "serde", "serde_json", @@ -3154,7 +3154,7 @@ dependencies = [ [[package]] name = "tw-bedrock" -version = "0.69.0" +version = "0.70.0" dependencies = [ "aws-credential-types", "aws-sigv4", @@ -3175,7 +3175,7 @@ dependencies = [ [[package]] name = "tw-breaker" -version = "0.69.0" +version = "0.70.0" dependencies = [ "serde", "serde_json", @@ -3183,7 +3183,7 @@ dependencies = [ [[package]] name = "tw-config" -version = "0.69.0" +version = "0.70.0" dependencies = [ "blake3", "libc", @@ -3208,7 +3208,7 @@ dependencies = [ [[package]] name = "tw-control" -version = "0.69.0" +version = "0.70.0" dependencies = [ "axum", "base64", @@ -3251,7 +3251,7 @@ dependencies = [ [[package]] name = "tw-dialect" -version = "0.69.0" +version = "0.70.0" dependencies = [ "memchr", "serde", @@ -3260,7 +3260,7 @@ dependencies = [ [[package]] name = "tw-engine" -version = "0.69.0" +version = "0.70.0" dependencies = [ "chrono", "serde", @@ -3274,7 +3274,7 @@ dependencies = [ [[package]] name = "tw-gateway" -version = "0.69.0" +version = "0.70.0" dependencies = [ "arc-swap", "async-stream", @@ -3325,7 +3325,7 @@ dependencies = [ [[package]] name = "tw-guard" -version = "0.69.0" +version = "0.70.0" dependencies = [ "base64", "bytes", @@ -3341,7 +3341,7 @@ dependencies = [ [[package]] name = "tw-link" -version = "0.69.0" +version = "0.70.0" dependencies = [ "serde", "serde_json", @@ -3355,7 +3355,7 @@ dependencies = [ [[package]] name = "tw-observe" -version = "0.69.0" +version = "0.70.0" dependencies = [ "tokio", "tracing", @@ -3364,7 +3364,7 @@ dependencies = [ [[package]] name = "tw-plugin" -version = "0.69.0" +version = "0.70.0" dependencies = [ "libc", "rand 0.10.2", @@ -3379,7 +3379,7 @@ dependencies = [ [[package]] name = "tw-pricing" -version = "0.69.0" +version = "0.70.0" dependencies = [ "arc-swap", "flate2", @@ -3392,14 +3392,14 @@ dependencies = [ [[package]] name = "tw-secret" -version = "0.69.0" +version = "0.70.0" dependencies = [ "thiserror", ] [[package]] name = "tw-store" -version = "0.69.0" +version = "0.70.0" dependencies = [ "blake3", "bytes", @@ -3419,7 +3419,7 @@ dependencies = [ [[package]] name = "tw-types" -version = "0.69.0" +version = "0.70.0" dependencies = [ "serde", "serde_json", @@ -3428,7 +3428,7 @@ dependencies = [ [[package]] name = "tw-watch" -version = "0.69.0" +version = "0.70.0" dependencies = [ "libc", "notify", @@ -3439,7 +3439,7 @@ dependencies = [ [[package]] name = "tw-yaml" -version = "0.69.0" +version = "0.70.0" dependencies = [ "saphyr-parser", "serde_yaml_ng", @@ -3449,7 +3449,7 @@ dependencies = [ [[package]] name = "twcore" -version = "0.69.0" +version = "0.70.0" dependencies = [ "anyhow", "axum", diff --git a/Cargo.toml b/Cargo.toml index dfd707b0..f6fdb726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,7 +54,7 @@ categories = ["network-programming", "web-programming::http-server"] # 二进制走 CalVer,crate 走 SemVer —— 两者是两回事,卖给不同的人。 # 这里是 crate 的版本。 -version = "0.69.0" +version = "0.70.0" [workspace.dependencies] # ── 内部 crate ─────────────────────────────────────────── diff --git a/release-notes/0.70.0.md b/release-notes/0.70.0.md new file mode 100644 index 00000000..20933e14 --- /dev/null +++ b/release-notes/0.70.0.md @@ -0,0 +1,26 @@ +This release reads each upstream's balance: the money left on a key, the quota of a relay key and its time windows, a key's limit and spend on OpenRouter, or the usage and limits a ThinkWatch Enterprise gateway reports for a key. It also records which upstreams were written by signing in to a Z.ai or BigModel account. + +**Upgrade notes** + +- The control-plane protocol version (`CONTROL_API_VERSION`) goes from 45 to 46. ThinkWatch Lite connects only to a core with the same protocol version: ThinkWatch Lite 2026.10.13 includes 0.69.0 (protocol 45) and does not connect to 0.70.0. A server used with it stays on 0.69.0 until the app is updated to a release that includes 0.70.0; `sudo twcore upgrade --version 0.69.0 --restart` switches a server back. +- The request store's schema is unchanged; nothing is cleared. +- Configuration: an upstream takes two new optional keys, `balance:` and `signed_in:`. Existing configurations load unchanged and read balances where the address is recognized. +- New message codes: `control.balance_none`, `gw.balance.rejected`, `gw.balance.status`, `gw.balance.unrecognized`, `gw.balance.timeout`, `gw.balance.connect`, `gw.balance.request_failed`. +- Changed in the protocol: + - `ProviderView` gains `balance` (the latest reading), `balance_setting` (what the configuration says) and `signed_in`; `ProviderInput` gains `balance`; `ProviderTestResult` gains `balance`. + - New types `Balance`, `BalanceQuota`, `BalanceWindow`, `BalanceScope`, `Spent`, `SpentPeriod`, `BalanceSetting`. + - New event `balance_updated` and endpoint `POST /providers/{name}/balance/refresh`: `404 control.balance_none` for an upstream with no balance to read, `502` with the reason when the source could not be determined because a request failed. + +**Balances.** An upstream's `balance:` says where its balance is read from, with the upstream's own key and proxy: `openrouter`, `deepseek`, `moonshot`, `sub2api`, `newapi` (New API and One API) or `thinkwatch` (a ThinkWatch Enterprise gateway); `off` reads nothing. The default, `auto`, recognizes OpenRouter, DeepSeek and Moonshot by their address; any other address, except Anthropic's, OpenAI's and Gemini's own, is asked once whether it is a Sub2API relay, a New API relay or a ThinkWatch Enterprise gateway, and the answer is kept in memory only. ChatGPT and Z.ai accounts and Bedrock upstreams have no balance; their quota windows are reported as before. + +A reading is one or more of: money left on the key (a wallet, in its own currency), a total quota with what has been used of it, time windows with their limits, use and reset time, and the money already spent. Per source: + +- OpenRouter: the key's own limit, if it has one, and what the key spent this month (or in total), with the key's expiry. The account's credits need a management key and are not read. +- DeepSeek and Moonshot: the account balance, in its currency. +- Sub2API: the key's quota and its 5-hour, daily and weekly windows, or its subscription's windows, or the wallet balance; what was spent today is the amount actually charged. +- New API and One API: the key's quota and use, in the unit the site displays (US dollars, yuan or tokens, read from the site's public status); a site that does not say is marked as an unknown unit rather than dollars. +- ThinkWatch Enterprise: the key's limits and usage when the key has limits of its own, otherwise the account's limits and its total over all of its keys, each limit saying which. + +Balances are read at start, at most once a minute after requests through that upstream end, every ten minutes otherwise, and on request; **Check connection** also reads the balance and runs the recognition for `auto`, waiting at most five seconds for it. A failed read keeps the previous reading and says why; reading a balance never affects forwarding. Requests go only to the upstream's own address, through its proxy, and redirects are not followed. + +**Z.ai and BigModel sign-in.** An upstream written by signing in to a Z.ai or BigModel account now carries `signed_in: zai` or `signed_in: bigmodel`, and `ProviderView.signed_in` says so, so an app can show it as an account sign-in. Signing in again sets it on upstreams written before this release. Saving the upstream with the same key keeps it; replacing or removing the key clears it.