/** * TypeInference - Runtime schema inference and typed handler wrapping. * * Extracts parameter names and default values from function source code, * infers JSON Schema types from defaults, and creates wrapper functions * that unpack args dicts into named positional parameters. */ import type { SwaigHandler } from './SwaigFunction.js'; /** A parsed function parameter with optional default value. */ export interface ParsedParam { name: string; defaultValue?: string; } /** Result of schema inference from a function. */ export interface InferredSchema { /** JSON Schema properties keyed by parameter name. */ parameters: Record; /** List of required parameter names (those without defaults). */ required: string[]; /** Ordered parameter names (excluding rawData). */ paramNames: string[]; /** Whether the function accepts a rawData parameter. */ hasRawData: boolean; } /** * Parse function parameter names and default values from source code. * * Handles arrow functions, regular functions, and method shorthand. * * @param source - The function source text, typically from `fn.toString()`. * @returns An array of `{ name, defaultValue? }` records in declaration order. * Returns an empty array if no parameter list is present. */ export declare function parseFunctionParams(source: string): ParsedParam[]; /** * Infer a JSON Schema from a function's parameters. * * Extracts parameter names and infers JSON Schema types from default-value * literals: * * - Number literals → `"integer"` (whole numbers) or `"number"` (decimals) * - String literals → `"string"` * - Boolean literals → `"boolean"` * - No default → `"string"` (and the parameter is marked required) * * @param fn - The function to inspect. Arrow functions, regular functions, and * method shorthand all work. * @returns An {@link InferredSchema} describing the parameters, or `null` when * the function looks like an old-style `(args, rawData)` SWAIG handler (in * which case no inference is attempted). */ export declare function inferSchema(fn: Function): InferredSchema | null; /** * Create a wrapper function that adapts a typed handler to the standard * `(args, rawData) => result` SWAIG handler signature. * * The wrapper extracts named parameters from the args dict and passes them * as positional arguments to the original function. * * @param fn - The typed handler whose parameters match `paramNames` in order. * @param paramNames - Ordered list of parameter names extracted from `fn`, * produced by {@link inferSchema}. * @param hasRawData - When `true`, the raw-data record is appended as the * final positional argument to mirror the old-style handler shape. * @returns A {@link SwaigHandler} suitable for registration with * {@link AgentBase.defineTool}. */ export declare function createTypedHandlerWrapper(fn: Function, paramNames: string[], hasRawData: boolean): SwaigHandler;