Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ categories = ["network-programming", "web-programming::http-server"]

# 二进制走 CalVer,crate 走 SemVer —— 两者是两回事,卖给不同的人。
# 这里是 crate 的版本。
version = "0.56.0"
version = "0.57.0"

[workspace.dependencies]
# ── 内部 crate ───────────────────────────────────────────
Expand Down
17 changes: 16 additions & 1 deletion crates/tw-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,22 @@ pub const MSG_CODES: &str = include_str!("../msg-codes.txt");
///
/// 30 起概览还带 [`Overview::failover`]([`FailoverView`]:上游失败之后停用多久、流开头
/// 最多等多久)。照 29 写的界面读不出这一项,也就改不了它。
pub const CONTROL_API_VERSION: u32 = 30;
///
/// **31 起有上游体检**:新端点 `GET /upstreams/health`([`UpstreamHealth`]:每家上游的请求、
/// 失败、取消,回答里写的模型名和发出去的对不对得上,上游报的输入和本地估算之比、本该读得到
/// 缓存的轮次读到了多少,各带样本数和别家服务同一个模型时的参照,以及首 token 和生成速度的
/// 中位数)。[`Event::RequestStarted`] 多了 `input_estimate`,三种结局多了 `answered_model`。
/// 照 30 写的界面看不到体检。
///
/// 31 起**整个请求历史都能搜**:`POST /history/search`([`HistorySearchQuery`] →
/// [`HistorySearchPage`])按流量页的筛选条件翻遍库里每一条,往回一页一页取;`content` 时
/// 还读正文还在的那些请求里新的一轮和回答(文字和工具调用),带打过码的摘录。照 30 写的
/// 界面只看得到自己载入的那几千条。
///
/// 31 起出站脱敏有**身份证号和银行卡号**两条出厂就开的规则:[`Matcher`] 多了
/// `cn-resident-id` 和 `bank-card`([`CardNetwork`]、[`CardPrefix`]),[`SecretKind`] 多了
/// `personal`。照 30 写的界面说不出这两条规则按什么认。
pub const CONTROL_API_VERSION: u32 = 31;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
Expand Down
34 changes: 34 additions & 0 deletions release-notes/0.57.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This release redacts Chinese resident ID numbers and bank card numbers out of the box, searches the whole request history including the text of requests and answers, and adds an upstream check-up: whether the model named in an upstream's answers matches the one sent, how its reported input compares with other upstreams serving the same model, how much of its input comes from the prompt cache, and its time to first token and speed.

**Upgrade notes**

- The control-plane protocol version (`CONTROL_API_VERSION`) is now 31. ThinkWatch Lite connects only to a core with the same protocol version, and has to regenerate its protocol types from this release to use it. A server used with ThinkWatch Lite 2026.9.26 or earlier (protocol 30) stays on 0.56.0 until the app is updated to a release that includes 0.57.0; `sudo twcore upgrade --version 0.56.0 --restart` switches a server back.
- The request store's schema goes from 22 to 23 (three new columns): **the request history is cleared** when the store is rebuilt on first start.
- **Two redaction rules are on by default**: `cn-resident-id` and `bank-card` (see below). With outbound redaction in `enforce`, such numbers in a request are replaced before it leaves; in `observe` they are recorded. `security.redact.disable` turns either off.
- **Routing estimates input size the way token counting does.** Rules on `input_tokens` now see one token per CJK character, 1,600 per image or file, and no thinking, instead of four bytes per token with images and files left out. A request with many images can now cross a size threshold it used to stay under.
- Changed in the protocol:
- `POST /history/search` (`HistorySearchQuery` → `HistorySearchPage`, with `HistoryCursor`, `ContentHit`, `ContentSide`, `SearchStop`).
- `GET /upstreams/health` (`UpstreamHealth`, `UpstreamCheckup`, `ModelConsistency`, `ModelPair`, `InputVsEstimate`, `InputForModel`, `RatioView`, `CacheReads`, `CacheForModel`, `CacheTally`, `MedianView`).
- `Event::RequestStarted` has `input_estimate`; `RequestFinished`, `RequestFailed` and `RequestCancelled` have `answered_model` (both left out when absent).
- `Matcher` has `cn-resident-id` (`born_since`) and `bank-card` (`networks`: `CardNetwork`, `CardPrefix`); `SecretKind` has `personal`.
- No message codes change.

**Chinese resident ID numbers and bank card numbers.** Outbound redaction looked only for credentials. Two built-in rules now look for personal numbers, held to the same bar as the credential rules: a value must check out structurally, not merely look like one.
- `cn-resident-id`: an 18-character resident ID number whose first two digits are a province-level code, whose birth date is a real date between 1900-01-01 and today, and whose check character (ISO 7064 MOD 11-2) is right. The old 15-digit numbers are not matched.
- `bank-card`: a number whose prefix and length belong to UnionPay, Visa, Mastercard, American Express, JCB, Discover or Diners Club and which passes the Luhn check, written in one run or in groups of four separated by single spaces or hyphens (and American Express's 4-6-5, Diners Club's 4-6-4). The public test card numbers of Stripe, Braintree and Adyen are left alone.
- A number inside a longer run of letters or digits is not matched, and neither is a number written as a JSON number (a tool call's arguments, for example): replacing it would leave the body invalid JSON.
- Placeholders say what was there: `<<TW_ID_NUMBER_1>>`, `<<TW_CARD_NUMBER_1>>`. They are restored in the answer as before, streams included. The security log shows only the last four characters.
- Scanning a request body also got faster: the token scan no longer allocates per token.

**Searching the whole history.** The Traffic page searched only the requests it had loaded. `POST /history/search` applies the same filter to every stored request, in pages that go back in time.
- It matches the free text against the path, client, client hint, peer, upstream, model and error message, and takes the message codes whose translation matched, so a query in the app's own language finds errors stored in English.
- With `content`, it also searches, for requests whose bodies are still kept, what is new in each request: the last user turn (text and tool results) and the answer (text, and each tool call's name and input). Clients that resend the whole conversation every turn therefore do not match every later request of a session. Each match comes with a short excerpt, with credentials masked.
- Content search reads at most 500 requests' bodies or 1.5 seconds per call, newest first, and says how far back it got, so a client can offer to search further.

**Upstream check-up.** `GET /upstreams/health` reports, for every upstream over a window (the last 7 days by default), facts and sample sizes rather than verdicts:
- requests, failures and cancellations;
- whether the model named in its answers matches the model sent (after rule rewrites), with up to three example pairs. Names are compared after removing differences that are not a different model (vendor prefixes, dates and snapshot markers, Bedrock's inference-profile and version forms, `4.5` against `4-5`), never the family, size, generation or variant;
- the median ratio of the input it reported to the gateway's local estimate, overall and, for every model that other upstreams also served, next to the ratio of those other upstreams;
- for later turns of a conversation sent to it within five minutes of the previous one, the share of input read from the prompt cache and how many such turns read none, also next to other upstreams serving the same model;
- median time to first token and generation speed.
- The answered model is read from the upstream's own response in the same pass that reads usage (Bedrock's responses do not name one). The estimate is the one routing already computes.
Loading