From bbf2c8f2446a037418e03fec947a2b49d8b9efd3 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Tue, 22 Sep 2026 13:23:27 +0800 Subject: [PATCH 1/2] fix(traffic): WebSocket connections are no longer listed as having no routing Core now reports the route of a WebSocket request (ThinkWatch-Core#99): the matched rule, the group and the one hop to the upstream. The request drawer's tooltip still named WebSocket connections among the requests without routing information. It now names the causes that remain: local answers, refusals by a routing rule, and requests whose client disconnected before any upstream answered. The type mirror follows core: request_started carries the billing of the upstream it is headed to, and a history row's billing can be free, which is what a local answer records. Co-Authored-By: Claude Opus 5 --- src/RequestDrawer.i18n.tsx | 4 ++-- src/events.test.ts | 1 + src/types.ts | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/RequestDrawer.i18n.tsx b/src/RequestDrawer.i18n.tsx index 74e74b1a..24a30eed 100644 --- a/src/RequestDrawer.i18n.tsx +++ b/src/RequestDrawer.i18n.tsx @@ -58,7 +58,7 @@ export const requestDrawerText = messages( failover: (failed: number) => `已发生故障转移:前 ${failed} 个上游失败,已自动切换至下一个上游。`, noRouting: "此请求没有路由信息", - noRoutingTip: "网关本地应答的请求、被路由规则拒绝的请求,以及 WebSocket 连接,不记录路由信息。", + noRoutingTip: "网关本地应答的请求、被路由规则拒绝的请求,以及上游应答之前客户端就断开的请求,不记录路由信息。", possibleCauses: "可能原因", // 内容 @@ -152,7 +152,7 @@ export const requestDrawerText = messages( : `Failover occurred: the first ${failed} upstreams failed, and the request was switched to the next upstream automatically.`, noRouting: "No routing information for this request", noRoutingTip: - "Requests answered locally by the gateway, requests refused by a routing rule, and WebSocket connections carry no routing information.", + "Requests answered locally by the gateway, requests refused by a routing rule, and requests whose client disconnected before any upstream answered carry no routing information.", possibleCauses: "Possible causes", request: "Request", diff --git a/src/events.test.ts b/src/events.test.ts index 96c57d0f..4be26b35 100644 --- a/src/events.test.ts +++ b/src/events.test.ts @@ -22,6 +22,7 @@ function started(over: Partial> id: 1, client: "claude-code", provider: "relay", + billing: "per-token", model: "claude-sonnet-4-5", method: "POST", path: "/v1/messages", diff --git a/src/types.ts b/src/types.ts index 31b1be17..9e7cd839 100644 --- a/src/types.ts +++ b/src/types.ts @@ -32,7 +32,7 @@ export type CoreEvent = * 长出一批对不上任何会话的影子组。界面因此不读它:归组只认落库之后 * 的 `session`。 */ - | { kind: "request_started"; id: number; client: string; client_hint?: string | null; peer?: string | null; key_masked?: string | null; provider: string; model: string; method: string; path: string; at_ms: number; session_fp?: string | null } + | { kind: "request_started"; id: number; client: string; client_hint?: string | null; peer?: string | null; key_masked?: string | null; provider: string; billing: string; model: string; method: string; path: string; at_ms: number; session_fp?: string | null } | { kind: "request_headers"; id: number; status: number; ttfb_ms: number } /** * 三种结局(结束、失败、取消)都带着 `model`,和开始事件里的是同一个。 @@ -673,9 +673,9 @@ export interface HistoryRow { local: boolean; /** 客户端没等到响应结束就断开了。**不是失败**,`error` 为空 */ cancelled: boolean; - /** 路由决策与尝试链。没经过路由的(WebSocket、本地应答、被规则拒绝的)没有 */ + /** 路由决策与尝试链。本地应答的、被规则拒绝的、上游应答之前客户端就断开的没有 */ routing?: RoutingView; - /** 服务它的那家怎么收钱:`per-token` / `subscription` / `unknown` */ + /** 服务它的那家怎么收钱:`per-token` / `subscription` / `free` / `unknown`。本地应答是 `free` */ billing: string; /** 缓存命中省下了多少微分。没有 = 算不出来 */ cache_saved_micros?: number; From 7a5917b5da58a599959d3f08e799f9ae728109e3 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Tue, 22 Sep 2026 13:51:11 +0800 Subject: [PATCH 2/2] chore: pin core v0.24.1 for WebSocket routing and the billing on request_started request_started now carries billing, and the field is required, so the hand-written event in the SSE framing test gains it too. Without it the event no longer parses, which is also what a newer app does with an older core's starts: the two ship together. Co-Authored-By: Claude Opus 5 --- src-tauri/Cargo.lock | 8 ++++---- src-tauri/Cargo.toml | 2 +- src-tauri/src/control.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d2b62769..235ee20a 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4982,8 +4982,8 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tw-api" -version = "0.24.0" -source = "git+https://github.com/ThinkWatchProject/ThinkWatch-Core.git?tag=v0.24.0#e418d07358fa15dc1ab21db9f095b3b1e9462782" +version = "0.24.1" +source = "git+https://github.com/ThinkWatchProject/ThinkWatch-Core.git?tag=v0.24.1#ef802fe1a3a0ba4f95a6b680dadfe61476c4f7be" dependencies = [ "serde", "serde_json", @@ -4992,8 +4992,8 @@ dependencies = [ [[package]] name = "tw-types" -version = "0.24.0" -source = "git+https://github.com/ThinkWatchProject/ThinkWatch-Core.git?tag=v0.24.0#e418d07358fa15dc1ab21db9f095b3b1e9462782" +version = "0.24.1" +source = "git+https://github.com/ThinkWatchProject/ThinkWatch-Core.git?tag=v0.24.1#ef802fe1a3a0ba4f95a6b680dadfe61476c4f7be" dependencies = [ "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7ed0f0f1..abdde7bd 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -31,7 +31,7 @@ tauri-plugin-deep-link = "2" # 编出来的东西不一样;而更要紧的是,打进 `.app` 的那个 twcore 二进制 # 必须和这里编译进去的协议镜像来自同一个 core 版本 —— 打包脚本正是从 # 这个 tag 去取二进制的(见 scripts/fetch-core.sh)。 -tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.24.0" } +tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.24.1" } anyhow = "1" libc = "0.2" diff --git a/src-tauri/src/control.rs b/src-tauri/src/control.rs index 17253730..ddd0056e 100644 --- a/src-tauri/src/control.rs +++ b/src-tauri/src/control.rs @@ -1186,7 +1186,7 @@ mod tests { let mut got = Vec::new(); for chunk in [ "data: {\"kind\":\"request_", - "started\",\"id\":1,\"client\":\"c\",\"provider\":\"p\",\"model\":\"m\",\"method\":\"POST\",\"path\":\"/x\",\"at_ms\":0}\n\n", + "started\",\"id\":1,\"client\":\"c\",\"provider\":\"p\",\"billing\":\"per-token\",\"model\":\"m\",\"method\":\"POST\",\"path\":\"/x\",\"at_ms\":0}\n\n", ] { buf.push_str(chunk); while let Some(idx) = buf.find("\n\n") {