/** * Compatibility shim for older in-repository callers. * * `soma-ai` no longer owns an OOUI vocabulary and intentionally does not * depend on `soma-ui`. A Host that still renders legacy `ooui:` declarations * must build its own composed pack and pass it here. New Tailwind page * generation does not call this module. */ import { registerOouiPacks, resolveOouiEngine, } from 'soma-core/server/ooui'; import type { SomaOouiEngine, SomaOouiPack } from 'soma-core/server/ooui'; export interface EnsureOouiEngineOptions { /** Vocabulary assembled by the Host from the components it actually mounts. */ readonly packs?: readonly SomaOouiPack[]; } let memo: { readonly key: unknown; readonly engine: SomaOouiEngine } | null = null; /** * Return the Host-registered OOUI engine, registering the supplied packs once. * * There is deliberately no default pack: supplying one here would recreate * the soma-ai → soma-ui dependency that the package boundary forbids. */ export function ensureOouiEngine(options: EnsureOouiEngineOptions = {}): SomaOouiEngine { const existing = resolveOouiEngine(); const packs = options.packs; if (!packs || packs.length === 0) { if (existing) return existing; throw new Error( '[soma-ai/ooui] 未注册演绎引擎;Tailwind 生成页不需要 OOUI,旧 ooui: 页面请由 Host 注入词汇包', ); } if (memo && memo.key === packs && resolveOouiEngine() === memo.engine) return memo.engine; const engine = registerOouiPacks(packs); memo = { key: packs, engine }; return engine; } /** Return the current Host engine without providing a fallback. */ export function currentOouiEngine(): SomaOouiEngine | undefined { return resolveOouiEngine(); }