myccusage 1.7.1__tar.gz → 1.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {myccusage-1.7.1 → myccusage-1.7.2}/PKG-INFO +1 -1
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage.egg-info/PKG-INFO +1 -1
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/__init__.py +1 -1
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/base.py +26 -10
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/workbuddy.py +12 -4
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/cli.py +131 -15
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/core.py +38 -2
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/macos/build_app.sh +2 -2
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/web/static/app.js +12 -2
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/web/static/index.html +1 -1
- {myccusage-1.7.1 → myccusage-1.7.2}/pyproject.toml +1 -1
- {myccusage-1.7.1 → myccusage-1.7.2}/LICENSE +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/README.md +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage.egg-info/SOURCES.txt +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage.egg-info/dependency_links.txt +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage.egg-info/entry_points.txt +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage.egg-info/top_level.txt +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/__main__.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/__init__.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/agy.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/claude.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/codex.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/grok.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/hermes.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/opencode.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/adapters/pi.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/macos/AppIcon.icns +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/macos/generate_icon.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/macos/main.swift +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/sync.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/web/__init__.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/web/server.py +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/myccusage_lib/web/static/style.css +0 -0
- {myccusage-1.7.1 → myccusage-1.7.2}/setup.cfg +0 -0
|
@@ -19,9 +19,9 @@ _CANDIDATE_HOME_DIRS: list[str] | None = None
|
|
|
19
19
|
# 模型维度:未识别到模型时使用的占位名(统一用字符串,避免 None 作为字典键带来的歧义)
|
|
20
20
|
UNKNOWN_MODEL = "unknown"
|
|
21
21
|
|
|
22
|
-
# 文件级持久缓存的 schema 版本。records 由
|
|
23
|
-
# 旧缓存必须失效,否则会混入缺少
|
|
24
|
-
_FILE_CACHE_SCHEMA =
|
|
22
|
+
# 文件级持久缓存的 schema 版本。records 由 8 元组扩展为 9 元组(末尾追加 credit),
|
|
23
|
+
# 旧缓存必须失效,否则会混入缺少 credit 的旧数据。版本不匹配时整体丢弃并重建一次。
|
|
24
|
+
_FILE_CACHE_SCHEMA = 3
|
|
25
25
|
|
|
26
26
|
# 非真实模型的伪名(大小写不敏感),统一归入 UNKNOWN_MODEL
|
|
27
27
|
_PSEUDO_MODELS = frozenset({"<synthetic>", "synthetic", "none", "null", "unknown", ""})
|
|
@@ -152,7 +152,7 @@ class BaseAgentAdapter:
|
|
|
152
152
|
self._full_cache = (fingerprint, (daily_map, session_list))
|
|
153
153
|
|
|
154
154
|
@staticmethod
|
|
155
|
-
def _bump_model(models: dict, model: str, inp: int, cr: int, out: int, tot: int) -> None:
|
|
155
|
+
def _bump_model(models: dict, model: str, inp: int, cr: int, out: int, tot: int, credit: float = 0.0) -> None:
|
|
156
156
|
"""
|
|
157
157
|
模型维度累加(含调用次数)。
|
|
158
158
|
|
|
@@ -167,25 +167,28 @@ class BaseAgentAdapter:
|
|
|
167
167
|
m = models[model] = {
|
|
168
168
|
"inputTokens": 0, "cacheReadTokens": 0,
|
|
169
169
|
"outputTokens": 0, "totalTokens": 0, "calls": 0,
|
|
170
|
+
"credit": 0.0,
|
|
170
171
|
}
|
|
171
172
|
m["inputTokens"] += inp
|
|
172
173
|
m["cacheReadTokens"] += cr
|
|
173
174
|
m["outputTokens"] += out
|
|
174
175
|
m["totalTokens"] += tot
|
|
175
176
|
m["calls"] += 1
|
|
177
|
+
if credit:
|
|
178
|
+
m["credit"] = round(m.get("credit", 0.0) + credit, 4)
|
|
176
179
|
|
|
177
180
|
@staticmethod
|
|
178
181
|
def _accumulate_records(records) -> tuple[dict[str, list[dict]], list[dict]]:
|
|
179
182
|
"""
|
|
180
183
|
把记录流聚合为 (daily_map, session_list):
|
|
181
|
-
- records
|
|
182
|
-
(sessionId, 日期, ISO时间, 输入Token, 缓存读Token, 输出Token, 合计Token,
|
|
184
|
+
- records 元素支持 8 元组或 9 元组 (兼容 WorkBuddy credit 字段):
|
|
185
|
+
(sessionId, 日期, ISO时间, 输入Token, 缓存读Token, 输出Token, 合计Token, 模型名, [credit])
|
|
183
186
|
第 8 位模型名一律经 normalize_model_name() 归一化,未识别时用 UNKNOWN_MODEL。
|
|
184
187
|
- daily_map: { "YYYY-MM-DD": [ 当日会话切片, ... ] },同日同会话自动合并累加
|
|
185
188
|
- session_list: 每个会话的全生命周期累计
|
|
186
189
|
|
|
187
190
|
除既有度量字段外,两类条目都额外携带 models 子结构(纯新增,既有字段一字不改):
|
|
188
|
-
models = { 模型名: {inputTokens, cacheReadTokens, outputTokens, totalTokens, calls} }
|
|
191
|
+
models = { 模型名: {inputTokens, cacheReadTokens, outputTokens, totalTokens, calls, credit} }
|
|
189
192
|
|
|
190
193
|
不变式(务必守恒,改造后须逐条验证):
|
|
191
194
|
sum(models[m]["totalTokens"] for m in models) == totalTokens
|
|
@@ -201,7 +204,14 @@ class BaseAgentAdapter:
|
|
|
201
204
|
sessions: dict[str, dict] = {}
|
|
202
205
|
bump = BaseAgentAdapter._bump_model
|
|
203
206
|
|
|
204
|
-
for
|
|
207
|
+
for rec in records:
|
|
208
|
+
if len(rec) >= 9:
|
|
209
|
+
sid, date_str, iso_str, inp, cr, out, tot, model, credit = rec[:9]
|
|
210
|
+
credit = float(credit or 0.0)
|
|
211
|
+
else:
|
|
212
|
+
sid, date_str, iso_str, inp, cr, out, tot, model = rec[:8]
|
|
213
|
+
credit = 0.0
|
|
214
|
+
|
|
205
215
|
# 1) 每日切片累加
|
|
206
216
|
day = daily.get(date_str)
|
|
207
217
|
if day is None:
|
|
@@ -215,6 +225,7 @@ class BaseAgentAdapter:
|
|
|
215
225
|
"cacheReadTokens": 0,
|
|
216
226
|
"outputTokens": 0,
|
|
217
227
|
"totalTokens": 0,
|
|
228
|
+
"credit": 0.0,
|
|
218
229
|
"lastActivity": iso_str,
|
|
219
230
|
"models": {},
|
|
220
231
|
}
|
|
@@ -222,9 +233,11 @@ class BaseAgentAdapter:
|
|
|
222
233
|
ds["cacheReadTokens"] += cr
|
|
223
234
|
ds["outputTokens"] += out
|
|
224
235
|
ds["totalTokens"] += tot
|
|
236
|
+
if credit:
|
|
237
|
+
ds["credit"] = round(ds.get("credit", 0.0) + credit, 4)
|
|
225
238
|
if iso_str > ds["lastActivity"]:
|
|
226
239
|
ds["lastActivity"] = iso_str
|
|
227
|
-
bump(ds["models"], model, inp, cr, out, tot)
|
|
240
|
+
bump(ds["models"], model, inp, cr, out, tot, credit)
|
|
228
241
|
|
|
229
242
|
# 2) 会话全生命周期累加
|
|
230
243
|
ss = sessions.get(sid)
|
|
@@ -235,6 +248,7 @@ class BaseAgentAdapter:
|
|
|
235
248
|
"cacheReadTokens": 0,
|
|
236
249
|
"outputTokens": 0,
|
|
237
250
|
"totalTokens": 0,
|
|
251
|
+
"credit": 0.0,
|
|
238
252
|
"lastActivity": iso_str,
|
|
239
253
|
"models": {},
|
|
240
254
|
}
|
|
@@ -242,9 +256,11 @@ class BaseAgentAdapter:
|
|
|
242
256
|
ss["cacheReadTokens"] += cr
|
|
243
257
|
ss["outputTokens"] += out
|
|
244
258
|
ss["totalTokens"] += tot
|
|
259
|
+
if credit:
|
|
260
|
+
ss["credit"] = round(ss.get("credit", 0.0) + credit, 4)
|
|
245
261
|
if iso_str > ss["lastActivity"]:
|
|
246
262
|
ss["lastActivity"] = iso_str
|
|
247
|
-
bump(ss["models"], model, inp, cr, out, tot)
|
|
263
|
+
bump(ss["models"], model, inp, cr, out, tot, credit)
|
|
248
264
|
|
|
249
265
|
return ({d: list(day.values()) for d, day in daily.items()}, list(sessions.values()))
|
|
250
266
|
|
|
@@ -192,15 +192,23 @@ class WorkBuddyAdapter(BaseAgentAdapter):
|
|
|
192
192
|
date_str = ms_to_date_str(ts)
|
|
193
193
|
iso_str = ms_to_iso(ts)
|
|
194
194
|
|
|
195
|
-
# 兼容 rawUsage 与 usage
|
|
195
|
+
# 兼容 rawUsage 与 usage 两种特殊数据格式并提取官方积分
|
|
196
|
+
credit = 0.0
|
|
196
197
|
if ru:
|
|
197
198
|
hit = ru.get("prompt_cache_hit_tokens", 0)
|
|
198
199
|
miss = ru.get("prompt_cache_miss_tokens", 0)
|
|
199
200
|
out = ru.get("completion_tokens", 0)
|
|
201
|
+
c_val = ru.get("credit")
|
|
202
|
+
if c_val is not None:
|
|
203
|
+
try:
|
|
204
|
+
credit = float(c_val)
|
|
205
|
+
except (ValueError, TypeError):
|
|
206
|
+
credit = 0.0
|
|
200
207
|
else:
|
|
201
208
|
if "input_tokens" in u:
|
|
202
|
-
|
|
203
|
-
hit = 0
|
|
209
|
+
inp = u.get("input_tokens", 0)
|
|
210
|
+
hit = u.get("cache_read_input_tokens", 0)
|
|
211
|
+
miss = max(0, inp - hit)
|
|
204
212
|
out = u.get("output_tokens", 0)
|
|
205
213
|
else:
|
|
206
214
|
inp = u.get("inputTokens", 0)
|
|
@@ -209,7 +217,7 @@ class WorkBuddyAdapter(BaseAgentAdapter):
|
|
|
209
217
|
out = u.get("outputTokens", 0)
|
|
210
218
|
tot = hit + miss + out
|
|
211
219
|
model = normalize_model_name(pd.get("requestModelName") or pd.get("requestModelId") or pd.get("model"))
|
|
212
|
-
records.append((sid, date_str, iso_str, miss, hit, out, tot, model))
|
|
220
|
+
records.append((sid, date_str, iso_str, miss, hit, out, tot, model, credit))
|
|
213
221
|
except Exception:
|
|
214
222
|
records = cached[2] if cached else []
|
|
215
223
|
else:
|
|
@@ -145,6 +145,28 @@ def render_daily_table(data):
|
|
|
145
145
|
display_name = data["displayName"]
|
|
146
146
|
sort_by_tokens = data["sortByTokens"]
|
|
147
147
|
sum_info = data["summary"]
|
|
148
|
+
is_workbuddy = (data.get("agent") == "workbuddy") or (sum_info.get("credit", 0.0) > 0)
|
|
149
|
+
|
|
150
|
+
# 预设各个数据列的固定宽度
|
|
151
|
+
w_rank = 5
|
|
152
|
+
w_time = 13
|
|
153
|
+
w_total = 8
|
|
154
|
+
w_input = 8
|
|
155
|
+
w_output = 8
|
|
156
|
+
w_cache = 8
|
|
157
|
+
w_hit = 7
|
|
158
|
+
w_credit = 10 if is_workbuddy else 0
|
|
159
|
+
w_cost = 10
|
|
160
|
+
|
|
161
|
+
# 计算非标题列的总宽度(包含列之间的分隔符宽度等预估常数)
|
|
162
|
+
extra_sep = 3 if is_workbuddy else 0
|
|
163
|
+
fixed_width = w_rank + w_time + w_total + w_input + w_output + w_cache + w_hit + w_credit + w_cost + 24 + extra_sep
|
|
164
|
+
|
|
165
|
+
# 将剩余空间全部分配给会话标题列,并保证最小宽度为 20
|
|
166
|
+
w_title = max(20, term_width - fixed_width)
|
|
167
|
+
total_table_width = min(term_width, fixed_width + w_title)
|
|
168
|
+
|
|
169
|
+
credit_hdr = (pad_str("官方积分", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
148
170
|
|
|
149
171
|
# 分支一:按 Token 消耗量排序的展示逻辑(不分层级,平铺展示)
|
|
150
172
|
if sort_by_tokens:
|
|
@@ -152,6 +174,12 @@ def render_daily_table(data):
|
|
|
152
174
|
print("=" * total_table_width)
|
|
153
175
|
print(f" {display_name} 单日会话消耗排行 (共 {len(flat_records)} 条日度会话记录 - 按当日消耗排序)")
|
|
154
176
|
print(" * 模式:[-d / --daily] 每日会话账本(不混淆前日用量,仅算当日实际消耗)")
|
|
177
|
+
if is_workbuddy:
|
|
178
|
+
total_credit = sum_info.get("credit", 0.0)
|
|
179
|
+
total_cost = sum_info.get("costCny", 0.0)
|
|
180
|
+
ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效价格 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
|
|
181
|
+
print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
|
|
182
|
+
print(f" * 换算:{ratio_desc}")
|
|
155
183
|
print("=" * total_table_width)
|
|
156
184
|
|
|
157
185
|
# 拼接表头,严格使用之前分配的各列宽度进行居中或对齐
|
|
@@ -163,6 +191,7 @@ def render_daily_table(data):
|
|
|
163
191
|
pad_str("Output", w_output, "right") + " │ " +
|
|
164
192
|
pad_str("Cache", w_cache, "right") + " │ " +
|
|
165
193
|
pad_str("Hitrate", w_hit, "right") + " │ " +
|
|
194
|
+
credit_hdr +
|
|
166
195
|
pad_str("等效价格", w_cost, "right") + " │ " +
|
|
167
196
|
pad_str("会话标题", w_title, "left")
|
|
168
197
|
)
|
|
@@ -171,8 +200,8 @@ def render_daily_table(data):
|
|
|
171
200
|
|
|
172
201
|
# 遍历扁平化的记录进行单行渲染
|
|
173
202
|
for r in flat_records:
|
|
174
|
-
# 根据动态分配的标题列宽进行智能截断
|
|
175
203
|
t_str = truncate_title(r["title"], w_title)
|
|
204
|
+
credit_col = (pad_str(f"{r.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
176
205
|
print(
|
|
177
206
|
pad_str(str(r["index"]), w_rank, "center") + " │ " +
|
|
178
207
|
pad_str(r["time"], w_time, "center") + " │ " +
|
|
@@ -181,12 +210,17 @@ def render_daily_table(data):
|
|
|
181
210
|
pad_str(format_tokens(r["outputTokens"]), w_output, "right") + " │ " +
|
|
182
211
|
pad_str(format_tokens(r["cacheTokens"]), w_cache, "right") + " │ " +
|
|
183
212
|
pad_str(format_hitrate(r["cacheTokens"], r["inputTokens"]), w_hit, "right") + " │ " +
|
|
213
|
+
credit_col +
|
|
184
214
|
pad_str(f"¥{r['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
|
|
185
215
|
pad_str(t_str, w_title, "left")
|
|
186
216
|
)
|
|
187
217
|
print("─" * total_table_width)
|
|
188
218
|
|
|
189
219
|
# 打印全周期合计行
|
|
220
|
+
sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
221
|
+
summary_label = f"共 {len(flat_records)} 条日度会话记录 (~${sum_info['costUsd']:.2f} USD)"
|
|
222
|
+
if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
|
|
223
|
+
summary_label = f"共 {len(flat_records)} 条日度会话记录 (1 积分 ≈ ¥{sum_info['costCny'] / sum_info['credit']:.3f}, ~${sum_info['costUsd']:.2f} USD)"
|
|
190
224
|
print(
|
|
191
225
|
pad_str("汇总", w_rank, "center") + " │ " +
|
|
192
226
|
pad_str("--", w_time, "center") + " │ " +
|
|
@@ -195,8 +229,9 @@ def render_daily_table(data):
|
|
|
195
229
|
pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
|
|
196
230
|
pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
|
|
197
231
|
pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
|
|
232
|
+
sum_credit_col +
|
|
198
233
|
pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
199
|
-
pad_str(
|
|
234
|
+
pad_str(summary_label, w_title, "left")
|
|
200
235
|
)
|
|
201
236
|
print("=" * total_table_width)
|
|
202
237
|
return
|
|
@@ -205,7 +240,15 @@ def render_daily_table(data):
|
|
|
205
240
|
print("=" * total_table_width)
|
|
206
241
|
print(f" {display_name} 每日会话账本 (共 {data['activeDaysCount']} 个活动日, {data['totalRecordsCount']} 笔日度会话)")
|
|
207
242
|
print(" * 模式:[-d / --daily 默认] 不混淆前日用量,精准分列“此日、此 Session”的实际发生额")
|
|
208
|
-
|
|
243
|
+
if is_workbuddy:
|
|
244
|
+
total_credit = sum_info.get("credit", 0.0)
|
|
245
|
+
total_cost = sum_info.get("costCny", 0.0)
|
|
246
|
+
ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效基准 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
|
|
247
|
+
print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
|
|
248
|
+
print(" * 计价:DeepSeek-V4.1-Flash 高峰期等效基准 (供比对官方积分与理论 API 成本换算)")
|
|
249
|
+
print(f" * 换算:{ratio_desc}")
|
|
250
|
+
else:
|
|
251
|
+
print(" * 计价:DeepSeek-V4.1-Flash 高峰期 (未命中 ¥2/M | 缓存命中 ¥0.04/M | 输出 ¥8/M)")
|
|
209
252
|
print("=" * total_table_width)
|
|
210
253
|
|
|
211
254
|
# 渲染主表头
|
|
@@ -217,6 +260,7 @@ def render_daily_table(data):
|
|
|
217
260
|
pad_str("Output", w_output, "right") + " │ " +
|
|
218
261
|
pad_str("Cache", w_cache, "right") + " │ " +
|
|
219
262
|
pad_str("Hitrate", w_hit, "right") + " │ " +
|
|
263
|
+
credit_hdr +
|
|
220
264
|
pad_str("等效价格", w_cost, "right") + " │ " +
|
|
221
265
|
pad_str("会话标题", w_title, "left")
|
|
222
266
|
)
|
|
@@ -229,6 +273,7 @@ def render_daily_table(data):
|
|
|
229
273
|
# 渲染第一级:最细粒度的单笔会话记录
|
|
230
274
|
for r in day["records"]:
|
|
231
275
|
t_str = truncate_title(r["title"], w_title)
|
|
276
|
+
credit_col = (pad_str(f"{r.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
232
277
|
row = (
|
|
233
278
|
pad_str(str(r["index"]), w_rank, "center") + " │ " +
|
|
234
279
|
pad_str(r["time"], w_time, "center") + " │ " +
|
|
@@ -237,6 +282,7 @@ def render_daily_table(data):
|
|
|
237
282
|
pad_str(format_tokens(r["outputTokens"]), w_output, "right") + " │ " +
|
|
238
283
|
pad_str(format_tokens(r["cacheTokens"]), w_cache, "right") + " │ " +
|
|
239
284
|
pad_str(format_hitrate(r["cacheTokens"], r["inputTokens"]), w_hit, "right") + " │ " +
|
|
285
|
+
credit_col +
|
|
240
286
|
pad_str(f"¥{r['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
|
|
241
287
|
pad_str(t_str, w_title, "left")
|
|
242
288
|
)
|
|
@@ -245,6 +291,7 @@ def render_daily_table(data):
|
|
|
245
291
|
# 渲染第二级:日小计(统计当日内所有会话的消耗汇总)
|
|
246
292
|
day_short = day["date"][5:] if len(day["date"]) >= 10 else day["date"]
|
|
247
293
|
day_time_label = f"{day_short}({day['weekday']}) 小计"
|
|
294
|
+
day_credit_col = (pad_str(f"{day.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
248
295
|
day_subtotal_row = (
|
|
249
296
|
pad_str("日计", w_rank, "center") + " │ " +
|
|
250
297
|
pad_str(day_time_label, w_time, "center") + " │ " +
|
|
@@ -253,6 +300,7 @@ def render_daily_table(data):
|
|
|
253
300
|
pad_str(format_tokens(day["outputTokens"]), w_output, "right") + " │ " +
|
|
254
301
|
pad_str(format_tokens(day["cacheTokens"]), w_cache, "right") + " │ " +
|
|
255
302
|
pad_str(format_hitrate(day["cacheTokens"], day["inputTokens"]), w_hit, "right") + " │ " +
|
|
303
|
+
day_credit_col +
|
|
256
304
|
pad_str(f"¥{day['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
257
305
|
pad_str(f"当日净消耗 ({day['count']} 笔会话)", w_title, "left")
|
|
258
306
|
)
|
|
@@ -261,6 +309,7 @@ def render_daily_table(data):
|
|
|
261
309
|
print("·" * total_table_width)
|
|
262
310
|
|
|
263
311
|
# 渲染第三级:周小计(统计当周内所有活动日的消耗汇总)
|
|
312
|
+
week_credit_col = (pad_str(f"{week.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
264
313
|
week_subtotal_row = (
|
|
265
314
|
pad_str("周计", w_rank, "center") + " │ " +
|
|
266
315
|
pad_str(f"{week['weekKey']} 小计", w_time, "center") + " │ " +
|
|
@@ -269,6 +318,7 @@ def render_daily_table(data):
|
|
|
269
318
|
pad_str(format_tokens(week["outputTokens"]), w_output, "right") + " │ " +
|
|
270
319
|
pad_str(format_tokens(week["cacheTokens"]), w_cache, "right") + " │ " +
|
|
271
320
|
pad_str(format_hitrate(week["cacheTokens"], week["inputTokens"]), w_hit, "right") + " │ " +
|
|
321
|
+
week_credit_col +
|
|
272
322
|
pad_str(f"¥{week['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
273
323
|
pad_str(f"本周净消耗 ({week['count']} 笔会话)", w_title, "left")
|
|
274
324
|
)
|
|
@@ -277,6 +327,12 @@ def render_daily_table(data):
|
|
|
277
327
|
print("─" * total_table_width)
|
|
278
328
|
|
|
279
329
|
# 渲染第四级:全周期合计(对所有历史数据的全局统计汇总)
|
|
330
|
+
sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
331
|
+
summary_label = f"全周期净消耗 (~${sum_info['costUsd']:.2f} USD)"
|
|
332
|
+
if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
|
|
333
|
+
cr = sum_info['credit']
|
|
334
|
+
cy = sum_info['costCny']
|
|
335
|
+
summary_label = f"全周期净消耗 (1 积分 ≈ ¥{cy / cr:.3f} 等效基准, ~${sum_info['costUsd']:.2f} USD)"
|
|
280
336
|
grand_total_row = (
|
|
281
337
|
pad_str("汇总", w_rank, "center") + " │ " +
|
|
282
338
|
pad_str("全周期合计", w_time, "center") + " │ " +
|
|
@@ -285,8 +341,9 @@ def render_daily_table(data):
|
|
|
285
341
|
pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
|
|
286
342
|
pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
|
|
287
343
|
pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
|
|
344
|
+
sum_credit_col +
|
|
288
345
|
pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
289
|
-
pad_str(
|
|
346
|
+
pad_str(summary_label, w_title, "left")
|
|
290
347
|
)
|
|
291
348
|
print(grand_total_row)
|
|
292
349
|
print("=" * total_table_width)
|
|
@@ -295,6 +352,8 @@ def render_session_table(data):
|
|
|
295
352
|
"""渲染项目总览模式的终端表格"""
|
|
296
353
|
# 动态获取终端宽度,实现响应式排版
|
|
297
354
|
term_width = shutil.get_terminal_size((118, 24)).columns
|
|
355
|
+
sum_info = data["summary"]
|
|
356
|
+
is_workbuddy = (data.get("agent") == "workbuddy") or (data.get("agentType") == "workbuddy") or (sum_info.get("credit", 0.0) > 0)
|
|
298
357
|
|
|
299
358
|
# 预设固定的字段宽度
|
|
300
359
|
w_rank = 5
|
|
@@ -304,23 +363,32 @@ def render_session_table(data):
|
|
|
304
363
|
w_output = 8
|
|
305
364
|
w_cache = 8
|
|
306
365
|
w_hit = 7
|
|
366
|
+
w_credit = 10 if is_workbuddy else 0
|
|
307
367
|
w_cost = 11
|
|
308
368
|
|
|
309
369
|
# 计算并分配标题列所需的剩余宽度
|
|
310
|
-
|
|
311
|
-
|
|
370
|
+
extra_sep = 3 if is_workbuddy else 0
|
|
371
|
+
fixed_width = w_rank + w_time + w_total + w_input + w_output + w_cache + w_hit + w_credit + w_cost + 24 + extra_sep
|
|
372
|
+
w_title = max(20, term_width - fixed_width)
|
|
312
373
|
total_table_width = min(term_width, fixed_width + w_title)
|
|
313
374
|
|
|
314
375
|
display_name = data["displayName"]
|
|
315
376
|
sort_by_tokens = data["sortByTokens"]
|
|
316
377
|
sum_info = data["summary"]
|
|
317
378
|
sessions = data["flatRecords"]
|
|
379
|
+
credit_hdr = (pad_str("官方积分", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
318
380
|
|
|
319
381
|
# 排行榜分支:按 Token 全局排序平铺展示
|
|
320
382
|
if sort_by_tokens:
|
|
321
383
|
print("=" * total_table_width)
|
|
322
384
|
print(f" {display_name} 项目/会话总用量排行 (共 {len(sessions)} 个 Session - 按全生命周期 Token 消耗降序)")
|
|
323
385
|
print(" * 模式:[-s / --session] 专注每个任务/Project 的全生命周期总耗费")
|
|
386
|
+
if is_workbuddy:
|
|
387
|
+
total_credit = sum_info.get("credit", 0.0)
|
|
388
|
+
total_cost = sum_info.get("costCny", 0.0)
|
|
389
|
+
ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效价格 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
|
|
390
|
+
print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
|
|
391
|
+
print(f" * 换算:{ratio_desc}")
|
|
324
392
|
print("=" * total_table_width)
|
|
325
393
|
header = (
|
|
326
394
|
pad_str("序号", w_rank, "center") + " │ " +
|
|
@@ -330,6 +398,7 @@ def render_session_table(data):
|
|
|
330
398
|
pad_str("Output", w_output, "right") + " │ " +
|
|
331
399
|
pad_str("Cache", w_cache, "right") + " │ " +
|
|
332
400
|
pad_str("Hitrate", w_hit, "right") + " │ " +
|
|
401
|
+
credit_hdr +
|
|
333
402
|
pad_str("等效价格", w_cost, "right") + " │ " +
|
|
334
403
|
pad_str("会话标题", w_title, "left")
|
|
335
404
|
)
|
|
@@ -339,6 +408,7 @@ def render_session_table(data):
|
|
|
339
408
|
# 遍历汇总后的会话进行展示
|
|
340
409
|
for s in sessions:
|
|
341
410
|
t_str = truncate_title(s["title"], w_title)
|
|
411
|
+
credit_col = (pad_str(f"{s.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
342
412
|
print(
|
|
343
413
|
pad_str(str(s["index"]), w_rank, "center") + " │ " +
|
|
344
414
|
pad_str(s["time"], w_time, "center") + " │ " +
|
|
@@ -347,12 +417,17 @@ def render_session_table(data):
|
|
|
347
417
|
pad_str(format_tokens(s["outputTokens"]), w_output, "right") + " │ " +
|
|
348
418
|
pad_str(format_tokens(s["cacheTokens"]), w_cache, "right") + " │ " +
|
|
349
419
|
pad_str(format_hitrate(s["cacheTokens"], s["inputTokens"]), w_hit, "right") + " │ " +
|
|
420
|
+
credit_col +
|
|
350
421
|
pad_str(f"¥{s['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
|
|
351
422
|
pad_str(t_str, w_title, "left")
|
|
352
423
|
)
|
|
353
424
|
print("─" * total_table_width)
|
|
354
425
|
|
|
355
426
|
# 打印全周期合计行
|
|
427
|
+
sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
428
|
+
summary_label = f"共 {len(sessions)} 个项目会话 (~${sum_info['costUsd']:.2f} USD)"
|
|
429
|
+
if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
|
|
430
|
+
summary_label = f"共 {len(sessions)} 个项目会话 (1 积分 ≈ ¥{sum_info['costCny'] / sum_info['credit']:.3f}, ~${sum_info['costUsd']:.2f} USD)"
|
|
356
431
|
print(
|
|
357
432
|
pad_str("汇总", w_rank, "center") + " │ " +
|
|
358
433
|
pad_str("--", w_time, "center") + " │ " +
|
|
@@ -361,8 +436,9 @@ def render_session_table(data):
|
|
|
361
436
|
pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
|
|
362
437
|
pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
|
|
363
438
|
pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
|
|
439
|
+
sum_credit_col +
|
|
364
440
|
pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
365
|
-
pad_str(
|
|
441
|
+
pad_str(summary_label, w_title, "left")
|
|
366
442
|
)
|
|
367
443
|
print("=" * total_table_width)
|
|
368
444
|
return
|
|
@@ -371,7 +447,15 @@ def render_session_table(data):
|
|
|
371
447
|
print("=" * total_table_width)
|
|
372
448
|
print(f" {display_name} 项目/会话总览 (共 {len(sessions)} 个 Session - 全生命周期累计消耗)")
|
|
373
449
|
print(" * 模式:[-s / --session] 专注每个任务/Project 的全生命周期总耗费(按最新访问时间排序)")
|
|
374
|
-
|
|
450
|
+
if is_workbuddy:
|
|
451
|
+
total_credit = sum_info.get("credit", 0.0)
|
|
452
|
+
total_cost = sum_info.get("costCny", 0.0)
|
|
453
|
+
ratio_desc = f"全周期平均 1 积分 ≈ ¥{total_cost / total_credit:.4f} 等效基准 (¥1.00 ≈ {total_credit / total_cost:.2f} 积分)" if total_credit > 0 and total_cost > 0 else "积分已独立核算"
|
|
454
|
+
print(" * 积分:WorkBuddy 官方算力扣费 (来自 rawUsage.credit,多智能体 Subagent 全量计入)")
|
|
455
|
+
print(" * 计价:DeepSeek-V4.1-Flash 高峰期等效基准 (供比对官方积分与理论 API 成本换算)")
|
|
456
|
+
print(f" * 换算:{ratio_desc}")
|
|
457
|
+
else:
|
|
458
|
+
print(" * 计价:DeepSeek-V4.1-Flash 高峰期 (未命中 ¥2/M | 缓存命中 ¥0.04/M | 输出 ¥8/M)")
|
|
375
459
|
print("=" * total_table_width)
|
|
376
460
|
|
|
377
461
|
header = (
|
|
@@ -382,6 +466,7 @@ def render_session_table(data):
|
|
|
382
466
|
pad_str("Output", w_output, "right") + " │ " +
|
|
383
467
|
pad_str("Cache", w_cache, "right") + " │ " +
|
|
384
468
|
pad_str("Hitrate", w_hit, "right") + " │ " +
|
|
469
|
+
credit_hdr +
|
|
385
470
|
pad_str("等效价格", w_cost, "right") + " │ " +
|
|
386
471
|
pad_str("会话标题", w_title, "left")
|
|
387
472
|
)
|
|
@@ -397,6 +482,7 @@ def render_session_table(data):
|
|
|
397
482
|
# 第一级:呈现单个项目的累计统计概况
|
|
398
483
|
for s in day["records"]:
|
|
399
484
|
t_str = truncate_title(s["title"], w_title)
|
|
485
|
+
credit_col = (pad_str(f"{s.get('creditRaw', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
400
486
|
row = (
|
|
401
487
|
pad_str(str(global_idx), w_rank, "center") + " │ " +
|
|
402
488
|
pad_str(s["time"], w_time, "center") + " │ " +
|
|
@@ -405,6 +491,7 @@ def render_session_table(data):
|
|
|
405
491
|
pad_str(format_tokens(s["outputTokens"]), w_output, "right") + " │ " +
|
|
406
492
|
pad_str(format_tokens(s["cacheTokens"]), w_cache, "right") + " │ " +
|
|
407
493
|
pad_str(format_hitrate(s["cacheTokens"], s["inputTokens"]), w_hit, "right") + " │ " +
|
|
494
|
+
credit_col +
|
|
408
495
|
pad_str(f"¥{s['costCnyRaw']:.2f}", w_cost, "right") + " │ " +
|
|
409
496
|
pad_str(t_str, w_title, "left")
|
|
410
497
|
)
|
|
@@ -414,6 +501,7 @@ def render_session_table(data):
|
|
|
414
501
|
# 第二级:日小计
|
|
415
502
|
day_short = day["date"][5:] if len(day["date"]) >= 10 else day["date"]
|
|
416
503
|
day_time_label = f"{day_short}({day['weekday']}) 小计"
|
|
504
|
+
day_credit_col = (pad_str(f"{day.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
417
505
|
day_subtotal_row = (
|
|
418
506
|
pad_str("日计", w_rank, "center") + " │ " +
|
|
419
507
|
pad_str(day_time_label, w_time, "center") + " │ " +
|
|
@@ -422,6 +510,7 @@ def render_session_table(data):
|
|
|
422
510
|
pad_str(format_tokens(day["outputTokens"]), w_output, "right") + " │ " +
|
|
423
511
|
pad_str(format_tokens(day["cacheTokens"]), w_cache, "right") + " │ " +
|
|
424
512
|
pad_str(format_hitrate(day["cacheTokens"], day["inputTokens"]), w_hit, "right") + " │ " +
|
|
513
|
+
day_credit_col +
|
|
425
514
|
pad_str(f"¥{day['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
426
515
|
pad_str(f"当日活跃项目 ({day['count']} 个会话)", w_title, "left")
|
|
427
516
|
)
|
|
@@ -429,6 +518,7 @@ def render_session_table(data):
|
|
|
429
518
|
print("·" * total_table_width)
|
|
430
519
|
|
|
431
520
|
# 第三级:周小计
|
|
521
|
+
week_credit_col = (pad_str(f"{week.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
432
522
|
week_subtotal_row = (
|
|
433
523
|
pad_str("周计", w_rank, "center") + " │ " +
|
|
434
524
|
pad_str(f"{week['weekKey']} 小计", w_time, "center") + " │ " +
|
|
@@ -437,6 +527,7 @@ def render_session_table(data):
|
|
|
437
527
|
pad_str(format_tokens(week["outputTokens"]), w_output, "right") + " │ " +
|
|
438
528
|
pad_str(format_tokens(week["cacheTokens"]), w_cache, "right") + " │ " +
|
|
439
529
|
pad_str(format_hitrate(week["cacheTokens"], week["inputTokens"]), w_hit, "right") + " │ " +
|
|
530
|
+
week_credit_col +
|
|
440
531
|
pad_str(f"¥{week['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
441
532
|
pad_str(f"本周活跃项目 ({week['count']} 个会话)", w_title, "left")
|
|
442
533
|
)
|
|
@@ -444,6 +535,12 @@ def render_session_table(data):
|
|
|
444
535
|
print("─" * total_table_width)
|
|
445
536
|
|
|
446
537
|
# 第四级:全周期合计
|
|
538
|
+
sum_credit_col = (pad_str(f"{sum_info.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
539
|
+
summary_label = f"共 {len(sessions)} 个项目会话 (~${sum_info['costUsd']:.2f} USD)"
|
|
540
|
+
if is_workbuddy and sum_info.get("credit", 0.0) > 0 and sum_info.get("costCny", 0.0) > 0:
|
|
541
|
+
cr = sum_info['credit']
|
|
542
|
+
cy = sum_info['costCny']
|
|
543
|
+
summary_label = f"共 {len(sessions)} 个项目会话 (1 积分 ≈ ¥{cy / cr:.3f} 等效基准, ~${sum_info['costUsd']:.2f} USD)"
|
|
447
544
|
grand_total_row = (
|
|
448
545
|
pad_str("汇总", w_rank, "center") + " │ " +
|
|
449
546
|
pad_str("全周期合计", w_time, "center") + " │ " +
|
|
@@ -452,8 +549,9 @@ def render_session_table(data):
|
|
|
452
549
|
pad_str(format_tokens(sum_info["outputTokens"]), w_output, "right") + " │ " +
|
|
453
550
|
pad_str(format_tokens(sum_info["cacheTokens"]), w_cache, "right") + " │ " +
|
|
454
551
|
pad_str(format_hitrate(sum_info["cacheTokens"], sum_info["inputTokens"]), w_hit, "right") + " │ " +
|
|
552
|
+
sum_credit_col +
|
|
455
553
|
pad_str(f"¥{sum_info['costCny']:.2f}", w_cost, "right") + " │ " +
|
|
456
|
-
pad_str(
|
|
554
|
+
pad_str(summary_label, w_title, "left")
|
|
457
555
|
)
|
|
458
556
|
print(grand_total_row)
|
|
459
557
|
print("=" * total_table_width)
|
|
@@ -485,23 +583,27 @@ def render_quick_summary(summary):
|
|
|
485
583
|
w_name = 24
|
|
486
584
|
w_tok = 12
|
|
487
585
|
w_hit = 10
|
|
488
|
-
w_cost =
|
|
586
|
+
w_cost = 14
|
|
489
587
|
w_sess = 10
|
|
490
588
|
hdr = (
|
|
491
589
|
pad_str("Agent 名称", w_name, "left") + " │ " +
|
|
492
590
|
pad_str("今日Token", w_tok, "right") + " │ " +
|
|
493
591
|
pad_str("缓存率", w_hit, "right") + " │ " +
|
|
494
|
-
pad_str("
|
|
592
|
+
pad_str("费用/积分", w_cost, "right") + " │ " +
|
|
495
593
|
pad_str("会话数", w_sess, "right")
|
|
496
594
|
)
|
|
497
595
|
print(hdr)
|
|
498
596
|
print("─" * total_table_width)
|
|
499
597
|
for a in agents:
|
|
598
|
+
if a.get("id") == "workbuddy" and a.get("credit", 0.0) > 0:
|
|
599
|
+
cost_disp = f"{a['credit']:.1f}积/¥{a['costCny']:.2f}"
|
|
600
|
+
else:
|
|
601
|
+
cost_disp = f"¥{a['costCny']:.2f}"
|
|
500
602
|
row = (
|
|
501
603
|
pad_str(a["name"], w_name, "left") + " │ " +
|
|
502
604
|
pad_str(format_tokens(a["totalTokens"]), w_tok, "right") + " │ " +
|
|
503
605
|
pad_str(f"{a['hitRate']:.1f}%", w_hit, "right") + " │ " +
|
|
504
|
-
pad_str(
|
|
606
|
+
pad_str(cost_disp, w_cost, "right") + " │ " +
|
|
505
607
|
pad_str(f"{a['sessionCount']} 笔", w_sess, "right")
|
|
506
608
|
)
|
|
507
609
|
print(row)
|
|
@@ -544,13 +646,24 @@ def render_model_table(data, agent_type=None):
|
|
|
544
646
|
print("=" * term_width)
|
|
545
647
|
return
|
|
546
648
|
|
|
649
|
+
is_workbuddy = (agent_type == "workbuddy")
|
|
547
650
|
total_tok = totals.get("totalTokens", 0) or 1
|
|
548
|
-
w_name
|
|
651
|
+
w_name = 28
|
|
652
|
+
w_tok = 11
|
|
653
|
+
w_pct = 7
|
|
654
|
+
w_credit = 10 if is_workbuddy else 0
|
|
655
|
+
w_call = 9
|
|
656
|
+
w_agent = 20
|
|
657
|
+
|
|
658
|
+
credit_hdr = (pad_str("官方积分", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
659
|
+
extra_w = 13 if is_workbuddy else 0
|
|
660
|
+
term_width = max(term_width, 78 + extra_w)
|
|
549
661
|
|
|
550
662
|
print(
|
|
551
663
|
pad_str("模型名称", w_name, "left") + " │ " +
|
|
552
664
|
pad_str("Token 总量", w_tok, "right") + " │ " +
|
|
553
665
|
pad_str("占比", w_pct, "right") + " │ " +
|
|
666
|
+
credit_hdr +
|
|
554
667
|
pad_str("调用次数", w_call, "right") + " │ " +
|
|
555
668
|
pad_str("来源 Agent", w_agent, "left")
|
|
556
669
|
)
|
|
@@ -560,17 +673,20 @@ def render_model_table(data, agent_type=None):
|
|
|
560
673
|
agents_str = ",".join(m.get("agents", {}).keys())
|
|
561
674
|
if display_len(agents_str) > w_agent:
|
|
562
675
|
agents_str = agents_str[:w_agent - 2] + "…"
|
|
676
|
+
credit_col = (pad_str(f"{m.get('credit', 0.0):.2f}", w_credit, "right") + " │ ") if is_workbuddy else ""
|
|
563
677
|
print(
|
|
564
678
|
pad_str(m.get("model", ""), w_name, "left") + " │ " +
|
|
565
679
|
pad_str(format_tokens(m.get("totalTokens", 0)), w_tok, "right") + " │ " +
|
|
566
680
|
pad_str(f"{m.get('totalTokens', 0) / total_tok * 100:.1f}%", w_pct, "right") + " │ " +
|
|
681
|
+
credit_col +
|
|
567
682
|
pad_str(f"{m.get('calls', 0):,}", w_call, "right") + " │ " +
|
|
568
683
|
pad_str(agents_str, w_agent, "left")
|
|
569
684
|
)
|
|
570
685
|
|
|
571
686
|
print("─" * term_width)
|
|
572
|
-
|
|
573
|
-
|
|
687
|
+
credit_sum_str = f" │ {totals.get('credit', 0.0):.2f} 官方积分" if is_workbuddy else ""
|
|
688
|
+
print(f" 合计: {len(models)} 个模型 │ {format_tokens(totals.get('totalTokens', 0))} Tokens"
|
|
689
|
+
f"{credit_sum_str} │ {totals.get('calls', 0):,} 次调用")
|
|
574
690
|
|
|
575
691
|
unknown_tok = totals.get("unknownTokens", 0)
|
|
576
692
|
if unknown_tok:
|
|
@@ -202,6 +202,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
202
202
|
grand_cache = 0
|
|
203
203
|
grand_output = 0
|
|
204
204
|
grand_cost = 0.0
|
|
205
|
+
grand_credit = 0.0
|
|
205
206
|
total_records = 0
|
|
206
207
|
|
|
207
208
|
daily_trend = []
|
|
@@ -227,6 +228,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
227
228
|
"cacheTokens": 0,
|
|
228
229
|
"outputTokens": 0,
|
|
229
230
|
"costCny": 0.0,
|
|
231
|
+
"credit": 0.0,
|
|
230
232
|
"count": 0,
|
|
231
233
|
"days": []
|
|
232
234
|
}
|
|
@@ -239,6 +241,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
239
241
|
day_cache = 0
|
|
240
242
|
day_output = 0
|
|
241
243
|
day_cost = 0.0
|
|
244
|
+
day_credit = 0.0
|
|
242
245
|
day_records = []
|
|
243
246
|
|
|
244
247
|
for s in s_list:
|
|
@@ -247,6 +250,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
247
250
|
ca = s.get("cacheReadTokens", 0)
|
|
248
251
|
out = max(0, tot - (inp + ca))
|
|
249
252
|
cost = calc_deepseek_cost(inp, ca, out)
|
|
253
|
+
credit = float(s.get("credit", 0.0) or 0.0)
|
|
250
254
|
|
|
251
255
|
if not summary_only:
|
|
252
256
|
sid = s.get("sessionId", "")
|
|
@@ -268,6 +272,8 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
268
272
|
"outputTokens": out,
|
|
269
273
|
"costCny": round(cost, 2),
|
|
270
274
|
"costCnyRaw": cost,
|
|
275
|
+
"credit": round(credit, 2),
|
|
276
|
+
"creditRaw": credit,
|
|
271
277
|
"remoteDevice": s.get("remoteDevice", ""),
|
|
272
278
|
"isRemote": s.get("isRemote", False),
|
|
273
279
|
}
|
|
@@ -280,6 +286,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
280
286
|
day_cache += ca
|
|
281
287
|
day_output += out
|
|
282
288
|
day_cost += cost
|
|
289
|
+
day_credit += credit
|
|
283
290
|
|
|
284
291
|
record_cnt = len(s_list) if summary_only else len(day_records)
|
|
285
292
|
|
|
@@ -293,6 +300,8 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
293
300
|
"cacheTokens": day_cache,
|
|
294
301
|
"outputTokens": day_output,
|
|
295
302
|
"costCny": round(day_cost, 2),
|
|
303
|
+
"credit": round(day_credit, 2),
|
|
304
|
+
"creditRaw": day_credit,
|
|
296
305
|
"records": day_records,
|
|
297
306
|
"count": record_cnt
|
|
298
307
|
}
|
|
@@ -302,6 +311,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
302
311
|
weeks_dict[week_key]["cacheTokens"] += day_cache
|
|
303
312
|
weeks_dict[week_key]["outputTokens"] += day_output
|
|
304
313
|
weeks_dict[week_key]["costCny"] += day_cost
|
|
314
|
+
weeks_dict[week_key]["credit"] = weeks_dict[week_key].get("credit", 0.0) + day_credit
|
|
305
315
|
weeks_dict[week_key]["count"] += record_cnt
|
|
306
316
|
|
|
307
317
|
daily_trend.append({
|
|
@@ -312,6 +322,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
312
322
|
"cacheTokens": day_cache,
|
|
313
323
|
"outputTokens": day_output,
|
|
314
324
|
"costCny": round(day_cost, 2),
|
|
325
|
+
"credit": round(day_credit, 2),
|
|
315
326
|
"count": record_cnt
|
|
316
327
|
})
|
|
317
328
|
|
|
@@ -320,12 +331,14 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
320
331
|
grand_cache += day_cache
|
|
321
332
|
grand_output += day_output
|
|
322
333
|
grand_cost += day_cost
|
|
334
|
+
grand_credit += day_credit
|
|
323
335
|
total_records += record_cnt
|
|
324
336
|
|
|
325
|
-
# 格式化周小计的 costCny
|
|
337
|
+
# 格式化周小计的 costCny 与 credit
|
|
326
338
|
weeks = list(weeks_dict.values())
|
|
327
339
|
for w in weeks:
|
|
328
340
|
w["costCny"] = round(w["costCny"], 2)
|
|
341
|
+
w["credit"] = round(w.get("credit", 0.0), 2)
|
|
329
342
|
|
|
330
343
|
# 根据请求处理排序逻辑
|
|
331
344
|
if sort_by_tokens and not summary_only:
|
|
@@ -348,6 +361,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
348
361
|
"cacheTokens": t_ca,
|
|
349
362
|
"outputTokens": today_entry["outputTokens"],
|
|
350
363
|
"costCny": today_entry["costCny"],
|
|
364
|
+
"credit": today_entry.get("credit", 0.0),
|
|
351
365
|
"cacheHitRate": round(t_ca / max(1, t_inp + t_ca) * 100, 1),
|
|
352
366
|
"sessionCount": today_entry.get("count", 0)
|
|
353
367
|
}
|
|
@@ -360,6 +374,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
360
374
|
"cacheTokens": 0,
|
|
361
375
|
"outputTokens": 0,
|
|
362
376
|
"costCny": 0.0,
|
|
377
|
+
"credit": 0.0,
|
|
363
378
|
"cacheHitRate": 0.0,
|
|
364
379
|
"sessionCount": 0
|
|
365
380
|
}
|
|
@@ -378,6 +393,7 @@ def get_daily_data(agent_type, sort_by_tokens=False, force_refresh=False, summar
|
|
|
378
393
|
"outputTokens": grand_output,
|
|
379
394
|
"costCny": round(grand_cost, 2),
|
|
380
395
|
"costUsd": round(grand_cost / USD_CNY_RATE, 2),
|
|
396
|
+
"credit": round(grand_credit, 2),
|
|
381
397
|
"cacheHitRate": hit_rate
|
|
382
398
|
},
|
|
383
399
|
"today": today_dict,
|
|
@@ -424,6 +440,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
424
440
|
grand_cache = 0
|
|
425
441
|
grand_output = 0
|
|
426
442
|
grand_cost = 0.0
|
|
443
|
+
grand_credit = 0.0
|
|
427
444
|
|
|
428
445
|
for s in raw_sessions:
|
|
429
446
|
sid = s.get("sessionId", "")
|
|
@@ -436,6 +453,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
436
453
|
ca = s.get("cacheReadTokens", 0)
|
|
437
454
|
out = max(0, tot - (inp + ca))
|
|
438
455
|
cost = calc_deepseek_cost(inp, ca, out)
|
|
456
|
+
credit = float(s.get("credit", 0.0) or 0.0)
|
|
439
457
|
title = s.get("title") or resolve_title(sid, titles)
|
|
440
458
|
|
|
441
459
|
grand_total += tot
|
|
@@ -443,6 +461,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
443
461
|
grand_cache += ca
|
|
444
462
|
grand_output += out
|
|
445
463
|
grand_cost += cost
|
|
464
|
+
grand_credit += credit
|
|
446
465
|
|
|
447
466
|
sessions.append({
|
|
448
467
|
"sessionId": sid,
|
|
@@ -455,6 +474,8 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
455
474
|
"outputTokens": out,
|
|
456
475
|
"costCny": round(cost, 2),
|
|
457
476
|
"costCnyRaw": cost,
|
|
477
|
+
"credit": round(credit, 2),
|
|
478
|
+
"creditRaw": credit,
|
|
458
479
|
"remoteDevice": s.get("remoteDevice", ""),
|
|
459
480
|
"isRemote": s.get("isRemote", False),
|
|
460
481
|
})
|
|
@@ -496,6 +517,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
496
517
|
"cacheTokens": 0,
|
|
497
518
|
"outputTokens": 0,
|
|
498
519
|
"costCny": 0.0,
|
|
520
|
+
"credit": 0.0,
|
|
499
521
|
"count": 0,
|
|
500
522
|
"days_map": OrderedDict()
|
|
501
523
|
}
|
|
@@ -510,6 +532,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
510
532
|
"cacheTokens": 0,
|
|
511
533
|
"outputTokens": 0,
|
|
512
534
|
"costCny": 0.0,
|
|
535
|
+
"credit": 0.0,
|
|
513
536
|
"records": []
|
|
514
537
|
}
|
|
515
538
|
d_entry = w_entry["days_map"][day_key]
|
|
@@ -519,12 +542,14 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
519
542
|
d_entry["cacheTokens"] += s["cacheTokens"]
|
|
520
543
|
d_entry["outputTokens"] += s["outputTokens"]
|
|
521
544
|
d_entry["costCny"] += s["costCnyRaw"]
|
|
545
|
+
d_entry["credit"] += s.get("creditRaw", 0.0)
|
|
522
546
|
|
|
523
547
|
w_entry["totalTokens"] += s["totalTokens"]
|
|
524
548
|
w_entry["inputTokens"] += s["inputTokens"]
|
|
525
549
|
w_entry["cacheTokens"] += s["cacheTokens"]
|
|
526
550
|
w_entry["outputTokens"] += s["outputTokens"]
|
|
527
551
|
w_entry["costCny"] += s["costCnyRaw"]
|
|
552
|
+
w_entry["credit"] += s.get("creditRaw", 0.0)
|
|
528
553
|
w_entry["count"] += 1
|
|
529
554
|
|
|
530
555
|
weeks = []
|
|
@@ -532,6 +557,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
532
557
|
days_list = []
|
|
533
558
|
for d_k, d_v in w_v["days_map"].items():
|
|
534
559
|
d_v["costCny"] = round(d_v["costCny"], 2)
|
|
560
|
+
d_v["credit"] = round(d_v.get("credit", 0.0), 2)
|
|
535
561
|
d_v["count"] = len(d_v["records"])
|
|
536
562
|
days_list.append(d_v)
|
|
537
563
|
weeks.append({
|
|
@@ -541,6 +567,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
541
567
|
"cacheTokens": w_v["cacheTokens"],
|
|
542
568
|
"outputTokens": w_v["outputTokens"],
|
|
543
569
|
"costCny": round(w_v["costCny"], 2),
|
|
570
|
+
"credit": round(w_v.get("credit", 0.0), 2),
|
|
544
571
|
"count": w_v["count"],
|
|
545
572
|
"days": days_list
|
|
546
573
|
})
|
|
@@ -560,6 +587,7 @@ def get_session_data(agent_type, sort_by_tokens=False):
|
|
|
560
587
|
"outputTokens": grand_output,
|
|
561
588
|
"costCny": round(grand_cost, 2),
|
|
562
589
|
"costUsd": round(grand_cost / USD_CNY_RATE, 2),
|
|
590
|
+
"credit": round(grand_credit, 2),
|
|
563
591
|
"cacheHitRate": hit_rate
|
|
564
592
|
},
|
|
565
593
|
"weeks": weeks,
|
|
@@ -862,6 +890,7 @@ def get_today_quick_summary(force_refresh=False):
|
|
|
862
890
|
t_out = sum(s.get("outputTokens", 0) for s in slices)
|
|
863
891
|
cost = calc_deepseek_cost(t_inp, t_cache, t_out)
|
|
864
892
|
hit_rate = round(t_cache / max(1, t_inp + t_cache) * 100, 1)
|
|
893
|
+
t_credit = sum(float(s.get("credit", 0.0) or 0.0) for s in slices)
|
|
865
894
|
|
|
866
895
|
latest_s = max(slices, key=lambda s: s.get("lastActivity", "") or "", default=None)
|
|
867
896
|
|
|
@@ -880,6 +909,7 @@ def get_today_quick_summary(force_refresh=False):
|
|
|
880
909
|
"outputTokens": t_out,
|
|
881
910
|
"hitRate": hit_rate,
|
|
882
911
|
"costCny": round(cost, 2),
|
|
912
|
+
"credit": round(t_credit, 2),
|
|
883
913
|
"sessionCount": len(slices),
|
|
884
914
|
"latestSession": latest_s
|
|
885
915
|
}
|
|
@@ -1015,12 +1045,15 @@ def get_model_breakdown(agent_type=None):
|
|
|
1015
1045
|
"model": model,
|
|
1016
1046
|
"inputTokens": 0, "cacheReadTokens": 0,
|
|
1017
1047
|
"outputTokens": 0, "totalTokens": 0, "calls": 0,
|
|
1048
|
+
"credit": 0.0,
|
|
1018
1049
|
}
|
|
1019
1050
|
e["inputTokens"] += mv.get("inputTokens", 0)
|
|
1020
1051
|
e["cacheReadTokens"] += mv.get("cacheReadTokens", 0)
|
|
1021
1052
|
e["outputTokens"] += mv.get("outputTokens", 0)
|
|
1022
1053
|
e["totalTokens"] += mv.get("totalTokens", 0)
|
|
1023
1054
|
e["calls"] += mv.get("calls", 0)
|
|
1055
|
+
if "credit" in mv:
|
|
1056
|
+
e["credit"] = round(e.get("credit", 0.0) + float(mv["credit"] or 0.0), 4)
|
|
1024
1057
|
return e
|
|
1025
1058
|
|
|
1026
1059
|
def _bump_agent(entry: dict, aid: str, mv: dict) -> None:
|
|
@@ -1028,9 +1061,11 @@ def get_model_breakdown(agent_type=None):
|
|
|
1028
1061
|
agents = entry.setdefault("agents", {})
|
|
1029
1062
|
ag = agents.get(aid)
|
|
1030
1063
|
if ag is None:
|
|
1031
|
-
ag = agents[aid] = {"totalTokens": 0, "calls": 0}
|
|
1064
|
+
ag = agents[aid] = {"totalTokens": 0, "calls": 0, "credit": 0.0}
|
|
1032
1065
|
ag["totalTokens"] += mv.get("totalTokens", 0)
|
|
1033
1066
|
ag["calls"] += mv.get("calls", 0)
|
|
1067
|
+
if "credit" in mv:
|
|
1068
|
+
ag["credit"] = round(ag.get("credit", 0.0) + float(mv["credit"] or 0.0), 4)
|
|
1034
1069
|
|
|
1035
1070
|
def _record(aid: str, d_str: str, mname: str, mv: dict) -> None:
|
|
1036
1071
|
"""把单个模型的用量同时记入 全局 / 按 Agent / 按日期 三个视图。"""
|
|
@@ -1090,6 +1125,7 @@ def get_model_breakdown(agent_type=None):
|
|
|
1090
1125
|
"totals": {
|
|
1091
1126
|
"models": len(models),
|
|
1092
1127
|
"totalTokens": sum(x["totalTokens"] for x in models),
|
|
1128
|
+
"credit": round(sum(x.get("credit", 0.0) for x in models), 2),
|
|
1093
1129
|
"calls": sum(x["calls"] for x in models),
|
|
1094
1130
|
"unknownTokens": unknown.get("totalTokens", 0),
|
|
1095
1131
|
"unknownCalls": unknown.get("calls", 0),
|
|
@@ -91,9 +91,9 @@ cat << 'EOF' > "${CONTENTS_DIR}/Info.plist"
|
|
|
91
91
|
<key>CFBundlePackageType</key>
|
|
92
92
|
<string>APPL</string>
|
|
93
93
|
<key>CFBundleShortVersionString</key>
|
|
94
|
-
<string>1.7.
|
|
94
|
+
<string>1.7.2</string>
|
|
95
95
|
<key>CFBundleVersion</key>
|
|
96
|
-
<string>1.7.
|
|
96
|
+
<string>1.7.2</string>
|
|
97
97
|
<key>LSMinimumSystemVersion</key>
|
|
98
98
|
<string>13.0</string>
|
|
99
99
|
<key>LSUIElement</key>
|
|
@@ -2012,7 +2012,13 @@
|
|
|
2012
2012
|
el.subTotalTokens.textContent = `Input: ${formatTokens(sum.inputTokens)} | Cache: ${formatTokens(sum.cacheTokens)} | Output: ${formatTokens(sum.outputTokens)}`;
|
|
2013
2013
|
|
|
2014
2014
|
el.valTotalCost.textContent = formatKpiMainCost(model, currentCost);
|
|
2015
|
-
|
|
2015
|
+
if ((data.agent === 'workbuddy' || (sum.credit && sum.credit > 0)) && sum.credit > 0) {
|
|
2016
|
+
const cr = sum.credit;
|
|
2017
|
+
const ratio = currentCost > 0 ? (currentCost / cr).toFixed(4) : '0';
|
|
2018
|
+
el.valTotalCostUsd.innerHTML = `<span style="color:var(--accent-pink,#f43f5e);font-weight:600;">${cr.toFixed(2)} 官方积分</span> · 1积≈¥${ratio}`;
|
|
2019
|
+
} else {
|
|
2020
|
+
el.valTotalCostUsd.textContent = formatKpiSubCost(model, currentCost);
|
|
2021
|
+
}
|
|
2016
2022
|
|
|
2017
2023
|
const costBadge = document.querySelector('.highlight-card .kpi-badge');
|
|
2018
2024
|
if (costBadge) costBadge.textContent = model.name;
|
|
@@ -2747,6 +2753,10 @@
|
|
|
2747
2753
|
const aCost = (a.inputTokens !== undefined || a.cacheTokens !== undefined || a.outputTokens !== undefined)
|
|
2748
2754
|
? calcCost(model, a.inputTokens, a.cacheTokens, a.outputTokens)
|
|
2749
2755
|
: (a.costCny || 0);
|
|
2756
|
+
let costDisplay = formatInlineCost(model, aCost);
|
|
2757
|
+
if (a.id === 'workbuddy' && a.credit > 0) {
|
|
2758
|
+
costDisplay += ` · <span style="color:var(--accent-pink,#f43f5e);">${a.credit.toFixed(1)}积</span>`;
|
|
2759
|
+
}
|
|
2750
2760
|
html += `
|
|
2751
2761
|
<div class="agent-stat-card" data-agent="${a.id}">
|
|
2752
2762
|
<div class="agent-stat-name">
|
|
@@ -2757,7 +2767,7 @@
|
|
|
2757
2767
|
</div>
|
|
2758
2768
|
<div class="agent-stat-values">
|
|
2759
2769
|
<span class="agent-token-num">${formatTokens(a.totalTokens)}</span>
|
|
2760
|
-
<span class="agent-cost-num">${
|
|
2770
|
+
<span class="agent-cost-num">${costDisplay}</span>
|
|
2761
2771
|
</div>
|
|
2762
2772
|
<div style="margin-top: 8px; font-size: 0.75rem; color: var(--text-muted);">
|
|
2763
2773
|
Prompt 缓存命中率: <strong style="color: var(--color-cache);">${a.cacheHitRate}%</strong>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|