diff --git a/WORKLOG.md b/WORKLOG.md index b34eff1..99b4520 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -52,9 +52,16 @@ - Set: 写 L1 + 写 L2 - Invalidate: L1 + L2 同步失效 +### 蒸馏队列端点修复 (2026-06-02) +- `GET /api/v1/distill/status` — 引擎状态(queue_len, batch_size, last_distill, daily_used) +- `GET /api/v1/distill/queue` — 队列内容(episode_id, content, category) +- `GET /api/v1/distill/quota` — 配额(remaining, used, limit, percent, status) +- Engine 新增 QueueLen/QueueItems/GetStatus/GetQuota 导出方法 + ## 提交记录 -- `[本次提交]` — G8: Restore+ListBackups 端点;G9: SearchCache 双级缓存(内存+Redis) +- `[本次提交]` — distill端点: /status /queue /quota;G8: Restore+ListBackups;G9: SearchCache 双级缓存 +- `[前次提交]` — G8: Restore+ListBackups 端点;G9: SearchCache 双级缓存(内存+Redis L2) - `b005916` — G7 E3: crystallize路由路径+GetSkillCandidates通过Rust IPC查LanceDB - `243a206` — G7.3: skill execute + quality_score fix diff --git a/go/internal/api/server.go b/go/internal/api/server.go index 45ce785..42c350a 100644 --- a/go/internal/api/server.go +++ b/go/internal/api/server.go @@ -631,6 +631,29 @@ func NewServer() http.Handler { routes.AutoDistillTrigger(epID, req.Content, req.Category, req.Namespace, req.AgentID) respondJSON(w, 200, map[string]string{"status": "queued", "episode_id": epID}) }) + // 蒸馏队列状态端点(G8-G9 配套) + mux.HandleFunc("/api/v1/distill/status", func(w http.ResponseWriter, r *http.Request) { + if routes.DistillEngineRef == nil { + respondJSON(w, 200, map[string]interface{}{"status": "not_initialized", "queue_len": 0}) + return + } + respondJSON(w, 200, routes.DistillEngineRef.GetStatus()) + }) + mux.HandleFunc("/api/v1/distill/queue", func(w http.ResponseWriter, r *http.Request) { + if routes.DistillEngineRef == nil { + respondJSON(w, 200, map[string]interface{}{"queue": []interface{}{}, "count": 0}) + return + } + items := routes.DistillEngineRef.QueueItems() + respondJSON(w, 200, map[string]interface{}{"queue": items, "count": len(items)}) + }) + mux.HandleFunc("/api/v1/distill/quota", func(w http.ResponseWriter, r *http.Request) { + if routes.DistillEngineRef == nil { + respondJSON(w, 200, map[string]interface{}{"remaining": 0, "used": 0, "limit": 0, "status": "not_initialized"}) + return + } + respondJSON(w, 200, routes.DistillEngineRef.GetQuota()) + }) mux.HandleFunc("/api/v1/distilled/{id}", func(w http.ResponseWriter, r *http.Request) { if r.Method == "DELETE" { adminAPI.DeleteDistilled(w, r) diff --git a/go/internal/distill/engine.go b/go/internal/distill/engine.go index 65112ba..683d365 100644 --- a/go/internal/distill/engine.go +++ b/go/internal/distill/engine.go @@ -516,3 +516,75 @@ func fallbackDistill(inputs []DistillInput) map[DistillInput]DistillResult { } return results } + +// ─── 端点导出方法(G8-G9 配套)─────────────────────────────── + +// QueueLen 返回当前队列长度 +func (e *Engine) QueueLen() int { + e.mu.Lock() + defer e.mu.Unlock() + return len(e.queue) +} + +// QueueItems 返回队列内容(摘要) +func (e *Engine) QueueItems() []map[string]string { + e.mu.Lock() + defer e.mu.Unlock() + items := make([]map[string]string, len(e.queue)) + for i, q := range e.queue { + content := q.Content + if len(content) > 80 { + content = content[:80] + "..." + } + items[i] = map[string]string{ + "episode_id": q.EpisodeID, + "content": content, + "category": string(q.Category), + } + } + return items +} + +// GetStatus 返回引擎运行时状态 +func (e *Engine) GetStatus() map[string]interface{} { + e.mu.Lock() + defer e.mu.Unlock() + return map[string]interface{}{ + "queue_len": len(e.queue), + "batch_size": e.batchSize, + "last_distill": e.lastDistill.Format(time.RFC3339), + "daily_used": e.dailyUsed, + "daily_limit": e.dailyLimit, + "daily_remaining": e.dailyLimit - e.dailyUsed, + } +} + +// GetQuota 返回配额(基于 Engine 自身追踪) +func (e *Engine) GetQuota() map[string]interface{} { + e.mu.Lock() + used := e.dailyUsed + limit := e.dailyLimit + e.mu.Unlock() + remain := limit - used + if remain < 0 { + remain = 0 + } + pct := float64(used) / float64(limit) * 100 + if limit == 0 { + pct = 0 + } + status := "normal" + if used >= limit { + status = "exceeded" + } else if pct >= 80 { + status = "near" + } + return map[string]interface{}{ + "remaining": remain, + "used": used, + "limit": limit, + "percent": pct, + "near_limit": pct >= 80, + "status": status, + } +}