import type { ComponentRunner, EdgeType } from '../types'; export const VALID_EDGE_TYPES = new Set([ // 現有 'PIPE', 'IF', 'FOREACH', 'CONTINUE', // 新增:執行語意 'IS_A', 'ON_SUCCESS', 'ON_FAIL', // 新增:觸發語意 'ON_CLICK', 'CALLS_SUBFLOW', // 新增:結構語意(記錄圖結構,不執行) 'CONTAINS', 'HAS_STYLE', 'HAS_BEHAVIOR', ]); /** 內建零件 ID 集合(Worker 記憶體中已有實作)*/ export const BUILTIN_IDS = new Set([ 'webhook', 'comp_passthrough', 'comp_uppercase', 'comp_counter', ]); /** 語意邊 → EdgeType 映射(ADR-057 u6u L1:支援中文語意關係詞) * 完成後 → PIPE(成功後觸發下一個) * 失敗時 → CONTINUE(失敗後繼續) * 對每個 → FOREACH(迭代執行) * 條件滿足時 → IF(條件分支) */ export const SEMANTIC_EDGE_MAP: Record = { // 中文語意詞 '完成後': 'PIPE', '失敗時': 'ON_FAIL', '對每個': 'FOREACH', '條件滿足時': 'IF', // 英文別名 'SUCCESS': 'ON_SUCCESS', 'FAIL': 'ON_FAIL', 'CLICK': 'ON_CLICK', 'SUBFLOW': 'CALLS_SUBFLOW', }; /** * 內建零件表(靜態函數) * WASM 零件 = 各自獨立 Worker,cypher-executor 走 HTTP URL 呼叫(不從 R2 讀) */ export const BUILTIN_COMPONENTS = new Map([ ['comp_passthrough', (ctx) => ctx], ['comp_uppercase', (ctx) => { const c = ctx as Record; return { ...c, text: String(c.text || '').toUpperCase() }; }], ['comp_counter', (ctx) => { const c = ctx as Record; return { ...c, count: (Number(c.count) || 0) + 1 }; }], ]); export const SCORE_THRESHOLD = 0.5;