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
4 changes: 2 additions & 2 deletions src-tauri/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 src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
52 changes: 40 additions & 12 deletions src/Sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Tip text="此会话中没有可计价的轮次"><span className="text-muted-foreground">无法计价</span></Tip>;
const subscription = s.subscription_turns > 0 && (
<Tip text="这些轮次由订阅制上游服务,计入订阅额度,不按用量产生费用">
<span className="text-muted-foreground">订阅额度 {s.subscription_turns} 轮</span>
</Tip>
);
if (s.priced_turns === 0) {
// 全走订阅的会话没有金额可写,但也没有缺什么
if (subscription && s.unpriced_turns === 0 && s.no_usage_turns === 0) return subscription;
return (
<>
<Tip text="此会话中没有可计价的轮次"><span className="text-muted-foreground">无法计价</span></Tip>
{subscription && <Also>{subscription}</Also>}
</>
);
}
const estimated = s.cost_micros_estimated ?? 0;
const noUsage = s.no_usage_turns ?? 0;
return (
<>
{estimated > 0 ? (
{s.cost_micros_estimated > 0 ? (
// **估算不能冒充实测**:合计里有估算的部分,就要带着记号
<Tip text={`其中 ${usd(estimated)} 为估算值:请求在响应结束前断开或中断,输出用量计至断开时;或模型的单价取自其他平台。`}>
<Tip text={`其中 ${usd(s.cost_micros_estimated)} 为估算值:请求在响应结束前断开或中断,输出用量计至断开时;或模型的单价取自其他平台。`}>
<span className="underline decoration-dotted underline-offset-2">~{usd(s.cost_micros)}</span>
</Tip>
) : (
Expand All @@ -150,11 +162,25 @@ function Cost({ s }: { s: SessionView }) {
<span className="ml-1 text-muted-foreground">+{s.unpriced_turns} 轮无法计价</span>
</Tip>
)}
{noUsage > 0 && (
{s.no_usage_turns > 0 && (
<Tip text="这些轮次没有用量数据:上游未报告,或连接在报告之前已结束。费用无法计算,未计入合计">
<span className="ml-1 text-muted-foreground">+{noUsage} 轮无用量</span>
<span className="ml-1 text-muted-foreground">+{s.no_usage_turns} 轮无用量</span>
</Tip>
)}
{subscription && <Also>{subscription}</Also>}
</>
);
}

/**
* 订阅额度跟在金额后面时用「·」隔开,不用「+」:「+N 轮无法计价」说的是
* 合计之外还有没算进来的费用,订阅那几轮没有这样的费用。
*/
function Also({ children }: { children: React.ReactNode }) {
return (
<>
<span className="mx-1 text-muted-foreground">·</span>
{children}
</>
);
}
Expand Down Expand Up @@ -256,8 +282,10 @@ function Waterfall({ turns }: { turns: TurnView[] }) {
/>
</span>
<span className="w-16 text-right">
{/* **没有价格就说没有价格,不写 $0** */}
{t.cost_micros == null ? (
{/* **没有价格就说没有价格,不写 $0**;订阅那一轮也没有金额,但它不是没有价格 */}
{t.billing === "subscription" ? (
<span className="text-neutral-400">订阅额度</span>
) : t.cost_micros == null ? (
<span className="text-neutral-400">无法计价</span>
) : (
// 估算的金额要带记号:取消、断在中间的那几轮输出只计到断开时
Expand Down
30 changes: 20 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
Loading