import type { JsonSchema, Type, type } from "arktype"; import type { Context } from "../context.js"; import { Resource } from "../resource.js"; import type { Secret } from "../secret.js"; import { type ModelConfig } from "./client.js"; /** * Properties for creating or updating a JSONFile */ export interface JSONFileProps | undefined = undefined> { /** * Path to the JSON file */ path: string; /** * Optional ArkType schema to validate and structure the generated JSON * When provided, the resource will use generateObject with schema validation * When not provided, it will extract JSON from between ```json fences */ schema?: T; /** * Base URL for the OpenAI API * @default 'https://api.openai.com/v1' */ baseURL?: string; /** * Prompt for generating content * Use alchemy template literals to include file context: * @example * prompt: await alchemy` * Generate a JSON configuration for: * ${alchemy.file("src/config.ts")} * ` */ prompt: string; /** * System prompt for the model * This is used to provide instructions to the model about how to format the response * @default Depends on whether schema is provided */ system?: string; /** * OpenAI API key to use for generating content * If not provided, will use OPENAI_API_KEY environment variable */ apiKey?: Secret; /** * Model configuration */ model?: ModelConfig; /** * Temperature for controlling randomness in generation. * Higher values (e.g., 0.8) make output more random, * lower values (e.g., 0.2) make it more deterministic. * @default 0.7 */ temperature?: number; /** * Whether to pretty-print the JSON with indentation * @default true */ pretty?: boolean; /** * Number of spaces to use for indentation when pretty-printing * @default 2 */ indent?: number; } /** * A JSON file that can be created, updated, and deleted */ export interface JSONFile extends Omit, Resource<"ai::JSONFile"> { /** * Content of the JSON file as a string */ content: string; /** * Parsed JSON object */ json: T; /** * Schema used to validate the JSON (if provided) */ schema?: JsonSchema; /** * Time at which the file was created */ createdAt: number; /** * Time at which the file was last updated */ updatedAt: number; } /** * Resource for generating JSON files using AI models. * Can operate in two modes: * 1. With schema: Uses generateObject with type validation * 2. Without schema: Extracts JSON from between ```json fences * * @example * // Generate a configuration file with freeform JSON * const config = await JSONFile("app-config", { * path: "./config/app.json", * prompt: await alchemy` * Generate a configuration for a web application with: * - Server settings (port, host, timeout) * - Database connection details (redact any passwords) * - Logging configuration * - Feature flags * `, * model: { * id: "gpt-4o", * provider: "openai" * } * }); * * @example * // Generate JSON with schema validation * import { type } from "arktype"; * * const userSchema = type({ * users: [{ * id: "string", * name: "string", * email: "string", * role: "'admin' | 'user' | 'guest'", * permissions: "string[]", * active: "boolean" * }] * }); * * const userData = await JSONFile("user-data", { * path: "./data/users.json", * schema: userSchema, * prompt: "Generate sample user data for an application with various roles and permissions", * temperature: 0.2 * }); * * // Type-safe access to the generated data * console.log(userData.json.users[0].role); // Typed as 'admin' | 'user' | 'guest' * * @example * // Generate API mock data with custom system prompt * const apiMock = await JSONFile("api-mock", { * path: "./mocks/products-api.json", * prompt: await alchemy` * Create mock data for a product catalog API response with: * - 10 products with different categories * - Each product should have id, name, price, category, inventory, and image_url * - Include pagination metadata (total, page, limit) * `, * system: "You are an API design expert. Create realistic mock JSON data that follows REST API best practices. Your response must be valid JSON inside ```json fences.", * model: { * id: "claude-3-opus-20240229", * provider: "anthropic" * }, * pretty: true, * indent: 4 * }); */ export declare const JSONFile: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ( | undefined = undefined>(this: Context ? type.infer : any>>, id: string, props: JSONFileProps) => Promise ? type.infer : any>>); //# sourceMappingURL=json-file.d.ts.map