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 TypeScriptFile */ export interface TypeScriptFileProps { /** * Path to the TypeScript file */ path: string; /** * 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 TypeScript utility function using: * ${alchemy.file("src/types.ts")} * ` */ prompt: string; /** * System prompt for the model * This is used to provide instructions to the model about how to format the response * The default system prompt instructs the model to return TypeScript code inside ```ts fences * @default "You are a TypeScript code generator. Create TypeScript code based on the user's requirements. Your response MUST include only TypeScript code inside ```ts fences. Do not include any other text, explanations, or multiple code blocks." */ 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; /** * Prettier configuration to use for formatting the TypeScript code * If not provided, will use the default Prettier configuration */ prettierConfig?: object; } /** * A TypeScript file that can be created, updated, and deleted */ export interface TypeScriptFile extends TypeScriptFileProps, Resource<"ai::TypeScriptFile"> { /** * Content of the TypeScript file */ content: string; /** * Time at which the file was created */ createdAt: number; /** * Time at which the file was last updated */ updatedAt: number; } /** * Resource for generating TypeScript files using AI models. * Extracts TypeScript code from between ```ts fences, validates the response, * and formats the code with Prettier. * * @example * // Create a utility function * const utils = await TypeScriptFile("string-utils", { * path: "./src/utils/string-utils.ts", * prompt: await alchemy` * Generate TypeScript utility functions for string manipulation: * - Capitalize first letter * - Truncate with ellipsis * - Convert to camelCase and kebab-case * - Remove special characters * `, * model: { * id: "gpt-4o", * provider: "openai" * } * }); * * @example * // Generate a TypeScript class with custom formatting * const userService = await TypeScriptFile("user-service", { * path: "./src/services/UserService.ts", * prompt: await alchemy` * Create a UserService class that handles user authentication and profile management. * The service should use the User type from: * ${alchemy.file("src/types/User.ts")} * * Include methods for: * - login(email, password) * - register(user) * - updateProfile(userId, profileData) * - deleteAccount(userId) * `, * temperature: 0.2, * prettierConfig: { * semi: false, * singleQuote: true, * printWidth: 120 * } * }); * * @example * // Generate a React hook with custom system prompt * const useFormHook = await TypeScriptFile("use-form", { * path: "./src/hooks/useForm.ts", * prompt: await alchemy` * Create a custom React hook called useForm that handles form state, validation, and submission. * It should support: * - Initial values * - Validation rules * - Field errors * - Form submission with loading state * - Reset functionality * `, * system: "You are an expert React developer specializing in TypeScript hooks. Create a single TypeScript file inside ```ts fences with no additional text. Follow React best practices and include proper typing.", * model: { * id: "claude-3-opus-20240229", * provider: "anthropic" * } * }); */ export declare const TypeScriptFile: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context, id: string, props: TypeScriptFileProps) => Promise); //# sourceMappingURL=typescript-file.d.ts.map