Files
Arcrun/registry/src/index.ts
T
uncle6me-web ea1c0571c1 步驟6 執行統計回寫:每顆零件跑完回寫 success_rate(task 29,design.md「執行統計設計」)
- registry 新增 POST /analytics/record:ANALYTICS_KV 計數器(stats:{hash_id}:{version})
  為唯一真相源,衍生值(success_rate/avg_duration_ms/call_count)回填 comp: 記錄
  ——查詢讀取端讀哪就寫哪,不開第二真相源。KV 無 CAS,誠實標註非原子。
- cypher-executor execution-evaluator 從 stub 改真實作:執行收尾(/cypher/execute
  成功與 ExecutionError 路徑+webhook 路徑)對 trace 裡每顆 Component 節點
  fire-and-forget 回寫,waitUntil 包、不增加執行同步延遲(仿 recordRecipeStats 慣例)。
  成敗判定=trace error 或 output.success===false(makeHttpRunner 非 2xx 不 throw)。
- registry 位置沿 search-nodes 慣例:REGISTRY_BASE_URL 覆蓋,未設走 wasmWorkerUrl。
- 新增單測 13 個全綠;本地雙 wrangler dev 端到端實測:http_request 跑 5 次
  (3 成功+2 失敗)→ success_rate 1→0.6、call_count 0→5,/cypher/search 同步可見。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-31 13:45:05 +08:00

33 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Component Registry Worker — 零件合約管理 HTTP endpoints
// index.ts 只做路由宣告,業務邏輯在 actions/INV Layer 1
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import type { Bindings } from './types';
import guideRoute from './routes/guide';
import validateContractRoute from './routes/validateContract';
import componentsRoute from './routes/components';
import queryRoute from './routes/query';
import initRoute from './routes/init';
import analyticsRoute from './routes/analytics';
const app = new Hono<{ Bindings: Bindings }>();
app.use('*', cors());
// Health check
app.get('/', c => c.json({ service: 'component-registry', version: '1.0.0', status: 'ok' }));
// === Component Registry 端點 ===
app.route('/components/guide', guideRoute);
app.route('/components/validate-contract', validateContractRoute);
app.route('/components', queryRoute); // GET /components/search, /:id, /:id/versions
app.route('/components', componentsRoute); // POST /components
// === 初始化端點(建立 tpl-component template===
app.route('/init', initRoute);
// === 執行統計回寫(cypher-executor 執行收尾 fire-and-forget 打進來)===
app.route('/analytics', analyticsRoute); // POST /analytics/record
export default app;