922a57fe34
Self-hosted 開源:WASM 零件 + recipe + cypher-executor,跑在你自己的 Cloudflare。 此為重建的乾淨歷史起點(移除曾誤 commit 的 GCP SA 金鑰,舊歷史保留在 richblack/arcrun 與本地 backup 分支)。含: - acr init --self-hosted installer(建 KV/R2 + codeload 拉預編譯 wasm + wrangler deploy + seed recipe) - recipe push 把關(資料外流提醒 + 打通檢查) - 19 個正當零件預編譯 wasm(claude_api/km_writer/kbdb_upsert_block 排除:違反 DECISIONS §1) - CLI / cypher-executor / registry / 完整 SDD Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { Hono } from 'hono';
|
|
import type { Bindings } from '../types';
|
|
import { graphSchema } from '../lib/schemas';
|
|
import { recordTelemetry } from '../lib/telemetry';
|
|
|
|
export const validateRouter = new Hono<{ Bindings: Bindings }>();
|
|
|
|
// POST /validate — 驗證圖定義(不執行)
|
|
validateRouter.post('/validate', async (c) => {
|
|
const start = Date.now();
|
|
const apiKey = c.req.header('X-Arcrun-API-Key');
|
|
const userAgent = c.req.header('User-Agent') ?? undefined;
|
|
|
|
const body = await c.req.json();
|
|
const parsed = graphSchema.safeParse(body);
|
|
if (!parsed.success) {
|
|
recordTelemetry(c.env, apiKey, {
|
|
event_type: 'validation_error',
|
|
error_code: 'schema_failed',
|
|
duration_ms: Date.now() - start,
|
|
agent_user_agent: userAgent,
|
|
}, c.executionCtx);
|
|
return c.json({ valid: false, errors: parsed.error.issues }, 400);
|
|
}
|
|
|
|
const nodeIds = new Set(parsed.data.nodes.map(n => n.id));
|
|
const invalidEdges = parsed.data.edges.filter(e => !nodeIds.has(e.from) || !nodeIds.has(e.to));
|
|
|
|
if (invalidEdges.length > 0) {
|
|
recordTelemetry(c.env, apiKey, {
|
|
event_type: 'validation_error',
|
|
error_code: 'edge_node_missing',
|
|
duration_ms: Date.now() - start,
|
|
agent_user_agent: userAgent,
|
|
}, c.executionCtx);
|
|
return c.json({
|
|
valid: false,
|
|
errors: invalidEdges.map(e => `邊 ${e.from} → ${e.to} 指向不存在的節點`),
|
|
}, 400);
|
|
}
|
|
|
|
return c.json({ valid: true, nodeCount: parsed.data.nodes.length, edgeCount: parsed.data.edges.length });
|
|
});
|