ai-functions
Version:
Core AI primitives for building intelligent applications
58 lines • 2.62 kB
TypeScript
/**
* AI() and ai() - Core AI function constructors
*
* This module is a re-export layer that delegates to focused modules:
* - ai-schemas.ts - Schema-based AI function generation
* - function-registry.ts - Function definition and registry
* - primitives.ts - Auto-define proxy functionality (`define`, `createSmartAI`, `aiProxy`)
*
* All exports are maintained for backward compatibility.
*/
export { createSchemaFunctions, type AISchemaOptions, type SchemaFunctions, type InferSimpleSchemaResult, } from './ai-schemas.js';
export { defineFunction, createDefinedFunction, createFunctionRegistry, functions, resetGlobalRegistry, convertArgsToJSONSchema, fillTemplate, generateCode, generateAndRunCode, type GeneratedCodeRunResult, } from './function-registry.js';
export { define, createSmartAI, aiProxy as ai, type AIProxy } from './primitives.js';
/**
* Helper to create a function that supports both regular calls and tagged template literals
* @example
* const fn = withTemplate((prompt) => doSomething(prompt))
* fn('hello') // regular call
* fn`hello ${name}` // tagged template literal
*/
export declare function withTemplate<TArgs extends unknown[], TReturn>(fn: (prompt: string, ...args: TArgs) => TReturn): ((prompt: string, ...args: TArgs) => TReturn) & ((strings: TemplateStringsArray, ...values: unknown[]) => TReturn);
import type { SimpleSchema } from './schema.js';
import { type AISchemaOptions, type SchemaFunctions } from './ai-schemas.js';
/**
* Create AI functions from schemas
*
* @example
* ```ts
* const ai = AI({
* storyBrand: {
* hero: 'Who is the customer?',
* problem: {
* internal: 'What internal problem do they face?',
* external: 'What external challenge exists?',
* philosophical: 'Why is this wrong?',
* },
* guide: 'Who helps them? (the brand)',
* plan: ['What are the steps to success?'],
* callToAction: 'What should they do?',
* success: 'What does success look like?',
* failure: 'What happens if they fail?',
* },
* recipe: {
* name: 'Recipe name',
* type: 'food | drink | dessert',
* servings: 'How many servings? (number)',
* ingredients: ['List all ingredients'],
* steps: ['Cooking steps in order'],
* },
* })
*
* // Call the generated functions
* const brand = await ai.storyBrand('Acme Corp sells widgets')
* const dinner = await ai.recipe('Italian pasta for 4 people')
* ```
*/
export declare function AI<T extends Record<string, SimpleSchema>>(schemas: T, defaultOptions?: AISchemaOptions): SchemaFunctions<T>;
//# sourceMappingURL=ai.d.ts.map