UNPKG

ai-functions

Version:

Core AI primitives for building intelligent applications

73 lines 2.84 kB
/** * Tagged template literal utilities * * Provides support for tagged template syntax across all AI functions: * - fn`prompt ${variable}` - template literal syntax * - Objects/arrays auto-convert to YAML * - Options chaining: fn`prompt`({ model: '...' }) * * @packageDocumentation */ /** * Common options for all AI functions */ export interface FunctionOptions { /** Model to use (e.g., 'claude-opus-4-5', 'gpt-5-1', 'gemini-3-pro') */ model?: string; /** Thinking level: 'none', 'low', 'medium', 'high', or token budget number */ thinking?: 'none' | 'low' | 'medium' | 'high' | number; /** Temperature (0-2) */ temperature?: number; /** Maximum tokens to generate */ maxTokens?: number; /** System prompt */ system?: string; /** Processing mode */ mode?: 'default' | 'background'; } /** * Parse a tagged template literal into a prompt string * Objects and arrays are converted to YAML for readability */ export declare function parseTemplate(strings: TemplateStringsArray, ...values: unknown[]): string; /** * Result type that is both a Promise and can be called with options */ export type ChainablePromise<T> = Promise<T> & { (options?: FunctionOptions): Promise<T>; }; /** * Create a chainable promise that supports both await and options chaining */ export declare function createChainablePromise<T>(executor: (options?: FunctionOptions) => Promise<T>, defaultOptions?: FunctionOptions): ChainablePromise<T>; /** * Template function signature */ export type TemplateFunction<T> = { (strings: TemplateStringsArray, ...values: unknown[]): ChainablePromise<T>; (prompt: string, options?: FunctionOptions): Promise<T>; }; /** * Create a function that supports both tagged templates and regular calls */ export declare function createTemplateFunction<T>(handler: (prompt: string, options?: FunctionOptions) => Promise<T>): TemplateFunction<T>; /** * Create a function with batch support */ export interface BatchableFunction<T, TInput = string> extends TemplateFunction<T> { batch: (inputs: TInput[]) => Promise<T[]>; } /** * Add batch capability to a template function */ export declare function withBatch<T, TInput = string>(fn: TemplateFunction<T>, batchHandler: (inputs: TInput[]) => Promise<T[]>): BatchableFunction<T, TInput>; /** * Create an async iterable from a streaming generator */ export declare function createAsyncIterable<T>(items: T[] | (() => AsyncGenerator<T>)): AsyncIterable<T>; /** * Create a result that is both a Promise (resolves to array) and AsyncIterable (streams items) */ export type StreamableList<T> = Promise<T[]> & AsyncIterable<T>; export declare function createStreamableList<T>(getItems: () => Promise<T[]>, streamItems?: () => AsyncGenerator<T>): StreamableList<T>; //# sourceMappingURL=template.d.ts.map