feat: 采集 LLM token 用量并上报 lpt-be

- 客户端解析上游 usage(含 DeepSeek 缓存命中/未命中),跨重试累加
- 新增计价表(三档单价 + 峰谷时段),费用在结算时冻结
- 新增用量上报与本地 outbox 重试;4xx 判定为确定性拒绝,不无限重试
- 面板补充 Token/费用/调用次数与计价快照
- 顺带修复面板内联脚本转义错误(模板字面量吃掉 \n 与 \',面板一直空白)
This commit is contained in:
2026-10-10 18:46:01 +08:00
parent fd1193a66f
commit 935f4781a4
24 changed files with 2632 additions and 65 deletions
+9
View File
@@ -116,7 +116,11 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
logStore.add({
timestamp: new Date().toISOString(),
endpoint: "/fetch-title",
taskType: "fetch-title",
model: "",
attempts: 1,
// 抓标题不过 LLM,不计入用量统计
isLlmCall: false,
durationMs: Date.now() - t0,
status: 200,
requestBody: { url },
@@ -130,12 +134,17 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
logStore.add({
timestamp: new Date().toISOString(),
endpoint: "/fetch-title",
taskType: "fetch-title",
model: "",
attempts: 1,
// 抓标题不过 LLM,不计入用量统计
isLlmCall: false,
durationMs: Date.now() - t0,
status: blocked ? 400 : 502,
requestBody: { url },
responseBody: { url, title: null },
error: message,
errorCode: blocked ? "unsafe_url" : "fetch_failed",
});
if (blocked) {
return reply.status(400).send({ error: message });