/** * SWMLHandler - SWML verb handler framework. * * Consolidates the abstract {@link SWMLVerbHandler} base class, the * concrete {@link AIVerbHandler} for the SWML "ai" verb (including its * {@link AIVerbBuildOptions} build signature), and the {@link VerbHandlerRegistry} * that maps verb names to handler instances. * * Verb handlers provide specialized logic for complex SWML verbs that * cannot be handled generically by the schema-driven SwmlBuilder. * The "ai" verb is complex and requires specialized handling, particularly * for managing prompts, SWAIG functions, and AI configurations. * * Register implementations via {@link VerbHandlerRegistry.registerHandler}. * * Mirrors Python SDK's single-file layout in * `signalwire/signalwire/core/swml_handler.py`. */ /** * Abstract base class for pluggable SWML verb handlers. * * Each concrete handler owns one verb name and provides validate/build * logic for that verb's configuration. Subclass this to create handlers * for custom or complex SWML verbs that require specialized handling * beyond generic schema-driven validation. * * @example * ```ts * class MyVerbHandler extends SWMLVerbHandler { * getVerbName(): string { return 'my_verb'; } * validateConfig(config: Record): [boolean, string[]] { * const errors: string[] = []; * if (!config['url']) errors.push("Missing required field 'url'"); * return [errors.length === 0, errors]; * } * buildConfig(opts: Record): Record { * return { url: opts['url'] }; * } * } * ``` */ export declare abstract class SWMLVerbHandler { /** * Get the name of the SWML verb this handler handles. * @returns The verb name as a string (e.g. "ai", "play"). */ abstract getVerbName(): string; /** * Validate the configuration for this verb. * @param config - The configuration dictionary for this verb. * @returns A `[isValid, errorMessages]` tuple where `isValid` is `true` * when the config is valid and `errorMessages` lists any issues found. */ abstract validateConfig(config: Record): [boolean, string[]]; /** * Build a configuration object for this verb from the provided arguments. * @param opts - Key-value arguments specific to this verb. * @returns A configuration dictionary ready for inclusion in a SWML document. */ abstract buildConfig(opts: Record): Record; } /** Options accepted by {@link AIVerbHandler.buildConfig}. */ export interface AIVerbBuildOptions { /** Text prompt for the AI (mutually exclusive with promptPom). */ promptText?: string; /** POM structure for the AI prompt (mutually exclusive with promptText). */ promptPom?: Record[]; /** Optional contexts and steps configuration (can be combined with text or pom). */ contexts?: Record; /** Optional post-prompt text. */ postPrompt?: string; /** Optional URL for post-prompt processing. */ postPromptUrl?: string; /** Optional SWAIG configuration. */ swaig?: Record; /** Additional AI parameters; see {@link AIVerbHandler.buildConfig} for routing rules. */ [key: string]: unknown; } /** Handler for the SWML 'ai' verb. */ export declare class AIVerbHandler extends SWMLVerbHandler { /** * Get the name of the verb this handler handles. * @returns "ai" as the verb name. */ getVerbName(): string; /** * Validate the configuration for the AI verb. * * Checks that: * - `prompt` is present and is an object * - `prompt` contains exactly one of `text` or `pom` (mutually exclusive) * - `prompt.contexts`, if present, is an object * - `SWAIG`, if present, is an object * * @param config - The configuration dictionary for the AI verb. * @returns A [isValid, errorMessages] tuple. */ validateConfig(config: Record): [boolean, string[]]; /** * Build a configuration for the AI verb. * * Requires exactly one of `promptText` or `promptPom` (mutually exclusive). * Throws an `Error` if both or neither are provided. * * Extra keys in `opts` are routed as follows: * - `languages`, `hints`, `pronounce`, `globalData` / `global_data` are placed at the top level of the config. * - All other extra keys are placed into `config.params`. * * @param opts - Build options for the AI verb configuration. * @returns AI verb configuration dictionary. */ buildConfig(opts?: AIVerbBuildOptions): Record; } /** * Registry for SWML verb handlers. * * This class maintains a registry of handlers for special SWML verbs * and provides methods for accessing and using them. The "ai" verb handler * ({@link AIVerbHandler}) is registered automatically on construction. * * @example * ```ts * const registry = new VerbHandlerRegistry(); * * // The "ai" handler is already registered * registry.hasHandler('ai'); // true * * // Register a custom handler * registry.registerHandler(new MyCustomVerbHandler()); * * // Look up a handler * const handler = registry.getHandler('ai'); * if (handler) { * const [valid, errors] = handler.validateConfig(config); * } * ``` */ export declare class VerbHandlerRegistry { private handlers; /** Initialize the registry with default handlers. */ constructor(); /** * Register a new verb handler, replacing any existing handler for the same verb name. * @param handler - The handler to register. */ registerHandler(handler: SWMLVerbHandler): void; /** * Get the handler for a specific verb. * @param verbName - The name of the verb (e.g. "ai"). * @returns The handler if found, or `undefined` otherwise. */ getHandler(verbName: string): SWMLVerbHandler | undefined; /** * Check if a handler exists for a specific verb. * @param verbName - The name of the verb. * @returns `true` if a handler is registered for the verb, `false` otherwise. */ hasHandler(verbName: string): boolean; }