@mosaicoo/svg-engine/ai/nlu is the opt-in natural-language layer (headless,
no Material/CDK). It turns a phrase like “draw a red circle” into an editor action:
a rule-based engine matches the text against registered intents, extracts slots,
and either returns ranked candidates or auto-executes the best one. An optional
local-LLM layer handles requests the rules can’t.
The intent registry + matcher. registerIntent(intent) → Disposable; parse(text, ctx, opts?) returns ranked NluCandidate[]; execute(text, ctx, opts?) parses and auto-runs the top match when confident; intents/intentsCount signals.
Register intents and turn text into editor actions.
builtinNluPlugin
A plugin (install via provideSvgEnginePlugin(builtinNluPlugin)) that auto-discovers every menu command as an intent and adds built-ins like create-shape, set-fill, move-selected, resize-selected, duplicate-selected.
An intent definition: id, keywords, optional actionKeywords/slots/destructive/description, and execute(slots, ctx).
NluContext
The per-call context — carries the injector so an intent can resolve editor services.
NluCandidate
A parse result: the matched intent, a confidence in [0,1], extracted slots, and the matches that explain it.
NluSlotSchema
A slot’s shape: number, color, shape, enum, string, point or gradient, with optional/default/anchor keywords.
NluParseOptions
threshold (default 0.3) and maxResults (default 5).
NluExecuteOptions
Adds autoExecuteThreshold (default 0.7) and confirmGate (a confirmation hook — required for destructive intents).
NluExecuteResult
The outcome: executed, the candidate, alternatives, and a rejection reason (no-match, below-threshold, confirmation-declined, destructive-no-gate, execute-error, or null).
Defaults: http://localhost:11434, qwen2.5:3b, and a small list of suggested Qwen models.
LlmIntentResolverService
The escalation layer: resolvePlan(text, ctx) asks the LLM to break a complex request into a multi-step intent plan; resolveAndExecute(text, ctx) runs it.
AiChatMessage / AiChatOptions
The chat message (role, content) and per-call options (model, format, temperature, …).