feat(logs): 实时日志展开显示单笔 token 用量与缓存命中率

- calllog 新增 peek_tokens(rid):只读不消耗,供实时日志展示(落库仍由 _row pop)
- AccessLog.add 把 token 挂到条目 tokens 字段
- 实时日志展开新增「Token 用量」块:输入/输出/缓存命中/推理 + 命中率(cached÷prompt)
- 调用日志详情弹窗补同样一行 token(数据取自 tok_* 列)
- 版本 2.9.3 → 2.9.4
This commit is contained in:
jidekin committed 2026-10-23 15:19:39 +08:00
1 parent fdeeee5066
commit d2214bd355
8 files changed
+90 -1

No files matched your search

+11
View File
@@ -618,6 +618,17 @@ def note_tokens(rid: str, prompt: int, completion: int,
break
def peek_tokens(rid: str) -> dict[str, int] | None:
"""按 rid 偷看 token 用量(**不消耗**)—— 实时日志页展开时展示用。
真正落库时由 `_row()` 负责 pop 清空,这里只读,避免两边抢同一份数据。
"""
if not store.enabled or not rid:
return None
with _tok_lock:
return TOKENS_BY_RID.get(str(rid))
def on_access(entry: dict[str, Any]) -> None:
"""`AccessLog.add()` 调用:拿到访问日志条目;若响应元数据已就绪则立即落库。"""
if not store.enabled: