/** * The **Context Router** — Photon AI's token-optimization layer. * * Before a prompt reaches the LLM, the router classifies it into one or more * {@link PhotonAIDomain}s and reports which columns it appears to name. The * provider pipeline then sends *only* the capabilities, column fields, state * slices, and prompt sections those domains require. * * ### Why this is not keyword matching * Photon AI's design rule is intent detection over keyword lists. The router * honours that by deriving its vocabulary from the **live intent registry**: * every intent already declares the alias phrases that identify it, and every * intent key already maps to a domain. So the router's dictionary *is* the * registry — a custom intent registered at runtime becomes routable with no * change here, and an alias reworded in a builtin updates routing for free. * Nothing in this file enumerates English words for grid concepts. * * ### Failure mode * Under-including is the only dangerous outcome: a filter request that arrives * without filter operators cannot be answered. Every ambiguity therefore * resolves toward *more* context — an unrecognized prompt falls back to the * full payload, exactly matching the pre-router behaviour. The optimization is * strictly opportunistic. * * @packageDocumentation */ import type { ColumnDef } from '../../types/column.types'; import type { PhotonAICommandRegistry } from '../photon-ai-registry'; import { PhotonAIDomain, type PhotonAIContextScope } from './ai-provider.types'; /** * Resolves the domains one intent key belongs to. * * Shared with `GridContextBuilder`, which uses it to decide whether a * registered intent's capability entry belongs in a scoped context — so the * classification that selects domains and the projection that honours them can * never disagree about which domain an intent lives in. * * An empty result means "unattributed", which callers must treat as * *always include* rather than *never include*: that is the signature of a * host-app custom intent, and withholding it would make it unreachable. */ export declare function domainsForIntentKey(key: string): readonly PhotonAIDomain[]; /** * Classifies a natural-language prompt into the minimal set of grid domains * needed to answer it, and the columns it names. * * Construct once per service; {@link route} is pure with respect to the * registry's contents at call time, so runtime-registered intents are picked up * on the next prompt without any invalidation step. */ export declare class ContextRouter { private readonly registry; constructor(registry: PhotonAICommandRegistry); /** * Classifies `prompt` and returns the context scope to build for it. * * @param prompt - The raw user command, exactly as typed. * @param columns - The grid's current columns, used to detect column mentions. */ route(prompt: string, columns: readonly ColumnDef[]): PhotonAIContextScope; /** * Matches the prompt's tokens against every registered intent's alias * phrases, collecting the domain of each intent that fires. * * An intent counts as referenced when *any* of its alias phrases is fully * covered by the token set — the same containment rule `IntentParser` uses to * pick a command, applied here without the tie-breaking, because routing * wants the union of plausible domains rather than a single winner. Sending * two domains when the user meant one costs a little; sending the wrong one * costs the request. */ private classifyDomains; /** * Finds columns the prompt names, by exact word match against each column's * `colId`, `field`, and `header`. * * Deliberately exact rather than fuzzy: `EntityResolver` does fuzzy matching * when it must resolve *the* target column, but here a wrong guess would * silently drop the column the user actually meant from the context. An exact * miss just means all columns are sent — correct, only less cheap. Multi-word * headers match when every one of their words is present. */ private detectColumns; /** Whether any of a column's names appears in the prompt's words. */ private mentionsColumn; } //# sourceMappingURL=context-router.d.ts.map