From f32e0c89c592f2f98acd7435578a8cd860ba293e Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Sun, 20 Sep 2026 00:47:32 +0800 Subject: [PATCH] feat: say a session was served by a subscription instead of calling it unpriced MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A session whose turns all went to a subscription upstream (Codex on a ChatGPT account) showed "cannot be priced" in the sessions list, and every turn in its detail said the same, while the overview reported the same requests as subscription usage. Core now reports subscription_turns per session and billing per turn, so the page no longer has to guess from a missing amount. - The cost cell reads 订阅额度 N 轮, the overview's wording with the page's unit. After an amount it is set off with a middle dot rather than a plus: "+N 轮无法计价" means money missing from the total, and subscription turns have none. - Each subscription turn in the detail reads 订阅额度 instead of 无法计价. - Measured, estimated, unpriced and no-usage turns render as before; the fallbacks for cores that did not send priced_turns and the other optional session fields are gone. Pins core v0.9.1. Co-Authored-By: Claude Opus 5 --- src-tauri/Cargo.lock | 4 ++-- src-tauri/Cargo.toml | 2 +- src/Sessions.tsx | 52 ++++++++++++++++++++++++++++++++++---------- src/types.ts | 30 ++++++++++++++++--------- 4 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 941770f5..f632c062 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4982,8 +4982,8 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tw-api" -version = "0.9.0" -source = "git+https://github.com/ThinkWatchProject/ThinkWatch-Core.git?tag=v0.9.0#1a05e15a5dadc2b50372e42ff3b355ea6ee803ca" +version = "0.9.1" +source = "git+https://github.com/ThinkWatchProject/ThinkWatch-Core.git?tag=v0.9.1#0e002d6c5fec4d8598eedcb7ae26d1861cf899d7" dependencies = [ "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 9727555b..cffd5f45 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.9.0" } +tw-api = { git = "https://github.com/ThinkWatchProject/ThinkWatch-Core.git", tag = "v0.9.1" } anyhow = "1" libc = "0.2" diff --git a/src/Sessions.tsx b/src/Sessions.tsx index 0d06e8cb..5bba2cf6 100644 --- a/src/Sessions.tsx +++ b/src/Sessions.tsx @@ -126,20 +126,32 @@ export default function Sessions() { * * **三态**:有价格的加起来,没价格的单独说,一轮都没有价格时 * 不显示 $0 —— 那是在撒谎。 + * + * 订阅制上游服务的轮次**不在这三态里**:它们计入订阅额度,不按用量产生 + * 费用,既不加进合计,也不是「无法计价」。概览上同一批请求写的是「订阅额度 + * N 次」,这里用同一个说法。 */ function Cost({ s }: { s: SessionView }) { - // 旧版本的 core 不给 `priced_turns`,那时只能按老办法减出来 - const priced = s.priced_turns ?? s.turns - s.unpriced_turns; - if (priced === 0) { - return 无法计价; + const subscription = s.subscription_turns > 0 && ( + + 订阅额度 {s.subscription_turns} 轮 + + ); + if (s.priced_turns === 0) { + // 全走订阅的会话没有金额可写,但也没有缺什么 + if (subscription && s.unpriced_turns === 0 && s.no_usage_turns === 0) return subscription; + return ( + <> + 无法计价 + {subscription && {subscription}} + + ); } - const estimated = s.cost_micros_estimated ?? 0; - const noUsage = s.no_usage_turns ?? 0; return ( <> - {estimated > 0 ? ( + {s.cost_micros_estimated > 0 ? ( // **估算不能冒充实测**:合计里有估算的部分,就要带着记号 - + ~{usd(s.cost_micros)} ) : ( @@ -150,11 +162,25 @@ function Cost({ s }: { s: SessionView }) { +{s.unpriced_turns} 轮无法计价 )} - {noUsage > 0 && ( + {s.no_usage_turns > 0 && ( - +{noUsage} 轮无用量 + +{s.no_usage_turns} 轮无用量 )} + {subscription && {subscription}} + + ); +} + +/** + * 订阅额度跟在金额后面时用「·」隔开,不用「+」:「+N 轮无法计价」说的是 + * 合计之外还有没算进来的费用,订阅那几轮没有这样的费用。 + */ +function Also({ children }: { children: React.ReactNode }) { + return ( + <> + · + {children} ); } @@ -256,8 +282,10 @@ function Waterfall({ turns }: { turns: TurnView[] }) { /> - {/* **没有价格就说没有价格,不写 $0** */} - {t.cost_micros == null ? ( + {/* **没有价格就说没有价格,不写 $0**;订阅那一轮也没有金额,但它不是没有价格 */} + {t.billing === "subscription" ? ( + 订阅额度 + ) : t.cost_micros == null ? ( 无法计价 ) : ( // 估算的金额要带记号:取消、断在中间的那几轮输出只计到断开时 diff --git a/src/types.ts b/src/types.ts index c6b9d636..5b842256 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1328,14 +1328,19 @@ export interface SessionView { turns: number; /** 有价格的那些轮次加起来,单位是**微分** */ cost_micros: number; - /** 其中估算的那部分。**不为 0 时合计要带记号**。旧版本的 core 不给 */ - cost_micros_estimated?: number; - /** 算出了价格的轮数。旧版本的 core 不给 */ - priced_turns?: number; + /** 其中估算的那部分。**不为 0 时合计要带记号** */ + cost_micros_estimated: number; + /** 算出了价格的轮数 */ + priced_turns: number; /** **模型不在价目表里的轮数。**「$1.23」和「$1.23,另有 4 轮没有价格」不是一个结论 */ unpriced_turns: number; - /** 没有拿到用量、算不出花费的轮数。旧版本的 core 不给 */ - no_usage_turns?: number; + /** 没有拿到用量、算不出花费的轮数 */ + no_usage_turns: number; + /** + * 由订阅制上游服务的轮数:计入订阅额度,**没有金额,也不是「无法计价」**。 + * 和上面三个数互不相交,和概览的 `subscription_requests` 数的是同一类请求 + */ + subscription_turns: number; input_tokens: number; output_tokens: number; cache_read_tokens: number; @@ -1359,10 +1364,15 @@ export interface TurnView { cost_micros: number | null; duration_ms: number | null; error: string | null; - /** 客户端没等到这一轮结束就断开了。旧版本的 core 不给 */ - cancelled?: boolean; - /** 这一轮的金额是估算。**瀑布图上要带记号**。旧版本的 core 不给 */ - cost_estimated?: boolean; + /** 客户端没等到这一轮结束就断开了 */ + cancelled: boolean; + /** 这一轮的金额是估算。**瀑布图上要带记号** */ + cost_estimated: boolean; + /** + * 服务它的那家怎么收钱,和 `HistoryRow.billing` 同一套词。订阅制那一轮的 + * `cost_micros` 也是 null,**只看金额分不出它和「无法计价」** + */ + billing: string; } export interface SessionDetail {