// 仓颉意图引擎桥:entry(ArkTS) → cjagent(HAR, 仓颉 so) // 仓颉侧只做文本→意图 JSON 的解析,后端调用仍在 ArkTS 侧执行 import { parseIntent, splitIntents, inferSlot } from 'libohos_app_cangjie_cjagent.so' export interface IntentResult { action: string; slot: string; date: string; jump: string; } export function parseIntentCj(text: string): IntentResult | null { try { const json: string = parseIntent(text); return JSON.parse(json) as IntentResult; } catch (err) { console.error('[IntentEngine] cangjie parse failed:', (err as Error).message); return null; } } export interface SegmentResult { segments: string[]; } // 多意图拆分:仓颉按连接词/标点切句;单意图时返回 null(走原路径零开销) export function splitSegmentsCj(text: string): string[] | null { try { const json: string = splitIntents(text); const parsed = JSON.parse(json) as SegmentResult; if (parsed.segments.length > 1) { return parsed.segments; } return null; } catch (err) { console.error('[IntentEngine] cangjie split failed:', (err as Error).message); return null; } } // 餐次推断(仓颉决策链):按小时返回 breakfast/lunch/dinner,失败时 ArkTS 本地兜底 export function inferSlotCj(hour: number): string { try { const json: string = inferSlot(hour); const parsed = JSON.parse(json) as { slot: string }; return parsed.slot; } catch (err) { console.error('[IntentEngine] cangjie inferSlot failed:', (err as Error).message); return hour < 9 ? 'breakfast' : (hour < 15 ? 'lunch' : 'dinner'); } }