ai-functions
Version:
Core AI primitives for building intelligent applications
54 lines • 1.86 kB
TypeScript
/**
* Simplified schema syntax for AI generation
*
* Converts human-readable schema definitions to Zod schemas:
* - 'description' → z.string().describe('description')
* - 'description (number)' → z.number().describe('description')
* - 'description (boolean)' → z.boolean().describe('description')
* - 'description (integer)' → z.number().int().describe('description')
* - 'description (date)' → z.string().datetime().describe('description')
* - 'opt1 | opt2 | opt3' → z.enum(['opt1', 'opt2', 'opt3'])
* - ['description'] → z.array(z.string()).describe('description')
* - { nested } → z.object() recursively
*
* @packageDocumentation
*/
import { type ZodTypeAny } from 'zod';
/**
* Simplified schema types
*/
export type SimpleSchema = string | [string] | [number] | [SimpleSchema] | {
[key: string]: SimpleSchema;
} | ZodTypeAny;
/**
* Convert a simplified schema to a Zod schema
*
* @example
* ```ts
* import { schema } from 'ai-functions'
* import { z } from 'zod'
*
* // These are equivalent:
* const simple = schema({
* name: 'What is the recipe name?',
* ingredients: ['List all ingredients'],
* steps: ['List all cooking steps'],
* })
*
* const zod = z.object({
* name: z.string().describe('What is the recipe name?'),
* ingredients: z.array(z.string()).describe('List all ingredients'),
* steps: z.array(z.string()).describe('List all cooking steps'),
* })
* ```
*/
export declare function schema<T extends SimpleSchema>(input: T): ZodTypeAny;
/**
* Type helper to infer the output type from a simple schema
*/
export type InferSimpleSchema<T> = T extends string ? string : T extends [string] ? string[] : T extends [number] ? number[] : T extends {
[K in keyof T]: SimpleSchema;
} ? {
[K in keyof T]: InferSimpleSchema<T[K]>;
} : unknown;
//# sourceMappingURL=schema.d.ts.map