console: 任务详情自动显示成本明细
打开详情就自动拉 GET /tasks/{id}/cost(不再只靠
“查成本”按钮出 JSON),详情顶部新一行:美元、总
token(实际/估算、缓存、无价单列)、轮数、fallback
次数;美元小于 1 美分时用 4 位小数,避免小任务
显示成 $0.00 误导成免费;加载中/失败有各自的
弱化文案,成本拉失败不影响详情其它内容;原
“查成本”按钮不动,仍可手动拉原始 JSON。
服务端不用改:成本接口与 _get_task 的 token 聚合
都已在 #150 / 详情 meta 那单里就位。
This commit is contained in:
1 parent
0f7162934b
commit
994c4ea5d1
7 files changed
+57
-31
No files matched your search
@@ -70,6 +70,15 @@ export function durationOf(t: Task): [string, string] {
|
||||
return ["—", "总耗时:无可用时间戳"];
|
||||
}
|
||||
|
||||
// 成本美元:usd_micros 是微美元(1 美元 = 1,000,000)。
|
||||
// 小于 1 美分时用 4 位小数,否则 2 位——小任务直接 toFixed(2)
|
||||
// 会把 $0.003 显示成 $0.00,误导成免费。
|
||||
export function fmtCostUsd(micros: number | null | undefined): string {
|
||||
if (micros === null || micros === undefined || !Number.isFinite(Number(micros))) return "—";
|
||||
const v = Number(micros) / 1000000;
|
||||
return "$" + (v > 0 && v < 0.01 ? v.toFixed(4) : v.toFixed(2));
|
||||
}
|
||||
|
||||
export function tokenOf(t: Task): [string, string] {
|
||||
const total = num(t.total_tokens);
|
||||
if (total !== null) {
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface Task {
|
||||
child_model?: string; child_effort?: string; approval?: string;
|
||||
result_text?: string; error_text?: string;
|
||||
}
|
||||
export interface TaskCost { task_id?: string; project_id?: string; total_tokens?: number; usd_micros?: number; turns?: number; fallback_count?: number; actual_tokens?: number; estimated_tokens?: number; cached_input_tokens?: number; unpriced_actual_tokens?: number }
|
||||
export interface Review { id: string; target_type?: string; branch?: string; sha?: string; instructions?: string; status?: string; created_at?: number; findings?: string }
|
||||
export interface Approval { id: string; kind?: string; status?: string; summary?: string; decision?: string; decided_by?: string; decided_at?: number }
|
||||
export interface Followup { mode?: string; status?: string; sender_task_id?: string; body?: string }
|
||||
|
||||
Reference in new issue
Block a user