/** * Domain Registry * * Provides auto-discovery and registration of framework domains for MCP servers. * Instead of hardcoding tool definitions and dispatch logic per domain, domains * export a `DomainDescriptor` and the registry generates everything automatically. * * @example * ```typescript * import { DomainRegistry } from '@lokascript/framework'; * * const registry = new DomainRegistry(); * * // Register domains (each provides a descriptor) * registry.register({ * name: 'sql', * description: 'Natural language SQL', * languages: ['en', 'es', 'ja', 'ar'], * inputLabel: 'query', * inputDescription: 'SQL query in natural language', * getDSL: () => import('@lokascript/domains/sql').then(m => m.createSQLDSL()), * getRenderer: () => import('@lokascript/domains/sql').then(m => m.renderSQL), * }); * * // Auto-generate MCP tool definitions * const tools = registry.getToolDefinitions(); * * // Dispatch a tool call * const result = await registry.handleToolCall('parse_sql', { query: 'select name from users' }); * ``` */ import type { MultilingualDSL } from './create-dsl'; import type { NaturalLanguageRenderer, DomainRenderFn } from '../generation/renderer'; import type { CommandSchema } from '../schema/command-schema'; import type { Diagnostic } from '../generation/diagnostics'; import type { GeneratedPrompt, PromptGeneratorConfig } from '../prompts/types'; import type { SynthesisConfig, SynthesisResult } from '../training/types'; import type { LSEFeedback } from '../feedback/types'; /** * Describes a domain for auto-registration in MCP servers. * * Domains provide this descriptor to the registry, which generates * tool definitions and handles dispatch automatically. */ export interface DomainDescriptor { /** Short identifier (used in tool names: parse_{name}, compile_{name}, etc.) */ readonly name: string; /** Human-readable description */ readonly description: string; /** Supported language codes */ readonly languages: readonly string[]; /** Label for the primary input parameter (e.g., 'query', 'scenario', 'code') */ readonly inputLabel: string; /** Description of the primary input parameter */ readonly inputDescription: string; /** What compile_{name} produces (e.g., "a SQL query string"). Used in tool description. */ readonly outputDescription?: string; /** * Factory to lazily create the DSL instance. * Called once on first tool use. The result is cached. */ readonly getDSL: () => MultilingualDSL | Promise; /** * Factory to lazily create the renderer. * Required for translate_{name} tool. Called once on first use. * * The function form may return `null` for an action it cannot render; the * translate tool reports that as an unsuccessful translation. */ readonly getRenderer?: () => NaturalLanguageRenderer | DomainRenderFn | Promise; /** * Which standard tools to generate. Default: all four. */ readonly tools?: readonly ('parse' | 'compile' | 'validate' | 'translate')[]; /** * Optional command schemas for this domain. * When provided, enables system prompt generation, training data synthesis, * and structured feedback via the registry's convenience methods. */ readonly schemas?: readonly CommandSchema[]; /** * Optional scan configuration for AOT compilation and Vite plugin. * Declares which HTML attributes/script types this domain uses. */ readonly scanConfig?: { /** Attribute names to scan for (e.g., ['data-sql', '_sql']) */ readonly attributes: readonly string[]; /** Script tag types to scan for (e.g., ['text/sql-dsl']) */ readonly scriptTypes?: readonly string[]; /** Default language when not specified on element */ readonly defaultLanguage?: string; /** Keywords for detection, keyed by language code */ readonly keywords?: Readonly>; }; } /** * MCP tool definition. Compatible with the MCP SDK's tool schema. */ export interface MCPToolDefinition { readonly name: string; readonly description: string; readonly inputSchema: { readonly type: 'object'; readonly properties: Record; readonly required: readonly string[]; }; } /** * MCP tool response. Compatible with the MCP SDK's response format. */ export interface MCPToolResponse { readonly content: ReadonlyArray<{ readonly type: string; readonly text: string; }>; readonly isError?: boolean; } /** * Registry for framework domains. * * Manages domain descriptors, generates MCP tool definitions, * and dispatches tool calls to the appropriate domain. */ export declare class DomainRegistry { private descriptors; private dslCache; private rendererCache; /** * Register a domain. * @throws if a domain with the same name is already registered */ register(descriptor: DomainDescriptor): void; /** * Attach schemas to an already-registered domain. * Useful for lazy loading schemas after initial registration. */ setSchemas(name: string, schemas: readonly CommandSchema[]): void; /** * Get all registered domain names. */ getDomainNames(): string[]; /** * Get a specific domain descriptor. */ getDescriptor(name: string): DomainDescriptor | undefined; /** * Generate MCP tool definitions for all registered domains. */ getToolDefinitions(): MCPToolDefinition[]; /** * Check if a tool name belongs to a registered domain. */ canHandle(toolName: string): boolean; /** * Handle a tool call by dispatching to the appropriate domain. * Returns null if the tool name doesn't match any registered domain. */ handleToolCall(toolName: string, args: Record): Promise; /** * Get the DSL instance for a named domain. * Returns null if the domain is not registered. * The DSL is lazily created and cached. */ getDSLForDomain(name: string): Promise; /** * Generate an LLM system prompt for a domain from its schemas. * Returns null if the domain is not registered or has no schemas. */ generatePrompt(domain: string, config?: Partial): GeneratedPrompt | null; /** * Synthesize training data for a domain from its schemas. * Returns null if the domain is not registered or has no schemas. */ generateTrainingData(domain: string, config?: Partial): SynthesisResult | null; /** * Build structured feedback for a failed LSE input in a domain. * Returns null if the domain is not registered or has no schemas. */ buildFeedback(domain: string, input: string, inputFormat: 'explicit' | 'json' | 'natural', diagnostics: readonly Diagnostic[]): LSEFeedback | null; /** * Get schemas for a domain (if available). */ getSchemas(domain: string): readonly CommandSchema[] | null; /** * Create a SchemaLookup from a domain's schemas. */ private createSchemaLookup; private getDSL; private getRenderer; private handleParse; private handleCompile; private handleValidate; private handleTranslate; } //# sourceMappingURL=domain-registry.d.ts.map