feat(llm): 用量落库 + 只读汇总端点 + 面板用量小卡(契约 v0.64)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- model 层新增可选 UsageSink(nil ⇒ 逐字不变,既有用例零改动)
- 组合根注入 UsageWriter:有界队列 1024 + 单写者 + 批量事务(128/批、2s 兜底),
  队列满丢弃 + 限流 WARN,绝不阻塞模型调用;sink 挂 RuntimeLLM(热重载不断)
- 迁移 0017:表 llm_usage(13 列,session_id 可空)+ idx_created_at + idx_session_id
- 新端点 GET /api/v1/admin/llm/usage(owner|admin 读;缺省近 24h、上限 90 天、
  超限 400 不静默裁剪;hitRate = cacheHit/(cacheHit+cacheMiss),分母 0 ⇒ 0;
  绝不含凭据与正文;未接线/查库失败 ⇒ 500 usage_unavailable)
- LLM_USAGE_RETENTION(默认 720h,≤0 = 关闭清理):启动清一次 + 每小时
- 面板 LLM 页「用量(近 24h)」小卡 + Docs 两份同步 v0.64
- 已知缺口(如实登记):session_id 恒 NULL,需 loop 侧在请求上打标,留列后接
This commit is contained in:
AskaEth committed 2026-10-04 22:16:26 +08:00
1 parent 18381f65fd
commit be38651ba4
32 files changed
+2233 -44

No files matched your search

+7
View File
@@ -92,6 +92,13 @@ type ServerConfig struct {
// 「立即回收」,一次笔误不该把整库未引用附件清空。判据与动作见
// internal/runtime/documents/gc.go。
DocumentRetention time.Duration `env:"DOCUMENT_RETENTION" default:"168h"`
// LLMUsageRetention 是 LLM 用量样本(`llm_usage` 表)的保留期(Go duration
// string),默认 720h = 30 天(切片 U1,主人裁决「2.4 落」)。**≤0 = 关闭
// 清理**:0 同样刻意不解释成「立即清空」,而是「不清理、全留」——一次笔误
// 不该把成本视图清空。清理在启动期跑一次,此后按固定间隔(见
// cmd/cyrene/wire_usage.go)继续。
LLMUsageRetention time.Duration `env:"LLM_USAGE_RETENTION" default:"720h"`
}
// AdminPathPrefix 返回管理面板前端路由的绝对路径前缀(默认 `/admin`)。