/** * Core AI Utilities * * Simple LLM helpers for vibe-apps. Provides generateText(), streamText(), and generateObject() * functions that work with the platform's AI proxy - no API keys needed. * * Uses the same AI proxy infrastructure as agents, but without the agent overhead. * Ideal for simple completion tasks, text analysis, and structured output generation. * * @example * ```typescript * import { generateText, streamText, generateObject } from './core-ai'; * * // Simple completion * const result = await generateText(env, { * prompt: 'Summarize this: ...', * }); * console.log(result.text); * * // Streaming * const stream = await streamText(env, { * prompt: 'Write a story about...', * }); * for await (const chunk of stream.textStream) { * console.log(chunk); * } * * // Structured output * import { z } from 'zod'; * const result = await generateObject(env, { * prompt: 'Extract entities from: ...', * schema: z.object({ * people: z.array(z.string()), * places: z.array(z.string()), * }), * }); * console.log(result.object); * ``` */ import { type ModelMessage, type UserContent, type ToolSet, type ToolChoice } from 'ai'; import type { Hono } from 'hono'; import type { z } from 'zod'; import { type Env } from './core-utils'; export { tool, type ModelMessage, type ModelMessage as CoreMessage, type Tool, type ToolSet, type ToolChoice, type TextPart, type ImagePart, type FilePart, type UserContent, type DataContent, } from 'ai'; /** * Message format for chat-style completions */ export interface ChatMessage { role: 'user' | 'assistant' | 'system'; content: string; } /** * Call settings for LLM requests */ export interface AICallSettings { maxOutputTokens?: number; temperature?: number; topP?: number; topK?: number; presencePenalty?: number; frequencyPenalty?: number; stopSequences?: string[]; seed?: number; maxRetries?: number; abortSignal?: AbortSignal; } /** * Options for text generation */ export interface GenerateTextOptions extends AICallSettings { /** Text prompt string, or content parts array for multimodal input (images, files) */ prompt?: UserContent; /** Chat-style messages (alternative to prompt) - use for multi-turn or complex multimodal */ messages?: Array; /** System prompt for context/behavior */ system?: string; /** Tools for function calling */ tools?: ToolSet; /** How the model should choose which tool to use */ toolChoice?: ToolChoice; /** Maximum number of tool-use steps */ maxSteps?: number; } /** * Options for streaming text generation (same parameters as GenerateTextOptions) */ export type StreamTextOptions = GenerateTextOptions; /** * Options for structured object generation */ export interface GenerateObjectOptions extends Omit { /** Text prompt string, or content parts array for multimodal input (images, files) */ prompt?: UserContent; /** Chat-style messages (alternative to prompt) - use for multi-turn or complex multimodal */ messages?: Array; /** System prompt for context/behavior */ system?: string; /** Zod schema for structured output */ schema: z.ZodType; } /** * Generate text completion using the AI proxy. * * @param env - Worker environment bindings * @param options - Generation options (prompt, messages, system) * @returns AI SDK result with text, usage stats, etc. * * @example * ```typescript * const result = await generateText(env, { * prompt: 'Explain quantum computing in simple terms', * }); * console.log(result.text); * ``` */ export declare function generateText(env: Env, options: GenerateTextOptions): Promise>; /** * Stream text generation using the AI proxy. * * @param env - Worker environment bindings * @param options - Generation options (prompt, messages, system) * @returns AI SDK streaming result with textStream, fullStream, etc. * * @example * ```typescript * const result = await streamText(env, { * prompt: 'Write a poem about the ocean', * }); * * // Option 1: Iterate over text chunks * for await (const chunk of result.textStream) { * process.stdout.write(chunk); * } * * // Option 2: Return as HTTP streaming response * return result.toTextStreamResponse(); * ``` */ export declare function streamText(env: Env, options: StreamTextOptions): Promise>; /** * Generate structured output (JSON) using the AI proxy. * Uses Zod schema for type-safe structured generation. * * @param env - Worker environment bindings * @param options - Generation options including Zod schema * @returns AI SDK result with typed object, usage stats, etc. * * @example * ```typescript * import { z } from 'zod'; * * const result = await generateObject(env, { * prompt: 'Extract contact info from: John Smith, john@example.com, 555-1234', * schema: z.object({ * name: z.string(), * email: z.string().email(), * phone: z.string().optional(), * }), * }); * console.log(result.object); // { name: 'John Smith', email: 'john@example.com', phone: '555-1234' } * ``` */ export declare function generateObject(env: Env, options: GenerateObjectOptions): Promise>; /** * Mount AI routes on the Hono app. * Provides /api/ai/generate and /api/ai/stream endpoints. */ export declare function aiRoutes(app: Hono<{ Bindings: Env; }>): void;