import prettier from "prettier"; 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 an AstroFile */ export interface AstroFileProps { /** * Path to the Astro 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 an Astro component 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 Astro code inside ```astro fences * @default "You are an Astro component generator. Create Astro components based on the user's requirements. Your response MUST include only Astro code inside ```astro 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 Astro code * If not provided, will use the default Prettier configuration */ prettierConfig?: prettier.Options; } /** * An Astro file that can be created, updated, and deleted */ export interface AstroFile extends AstroFileProps, Resource<"ai::AstroFile"> { /** * Content of the Astro 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 Astro files using AI models. * Extracts Astro code from between ```astro fences, validates the response, * and formats the code with Prettier. * * @example * // Create a simple Astro component * const header = await AstroFile("header", { * path: "./src/components/Header.astro", * prompt: await alchemy` * Generate an Astro header component with: * - Site logo * - Navigation menu with Home, About, Services, Contact links * - Mobile responsive design * - Dark/light mode toggle * `, * model: { * id: "gpt-4o", * provider: "openai" * } * }); * * @example * // Generate an Astro page with data fetching * const blogPost = await AstroFile("blog-post", { * path: "./src/pages/blog/[slug].astro", * prompt: await alchemy` * Create an Astro blog post page that: * - Uses getStaticPaths to generate pages from a CMS * - Renders markdown content * - Includes author info, publication date, and related posts * - Has social sharing buttons * * Use the following types: * ${alchemy.file("src/types/Blog.ts")} * `, * temperature: 0.2, * prettierConfig: { * semi: false, * singleQuote: true, * printWidth: 120 * } * }); * * @example * // Generate a layout with custom system prompt * const mainLayout = await AstroFile("main-layout", { * path: "./src/layouts/MainLayout.astro", * prompt: await alchemy` * Create the main layout for an Astro site that: * - Includes common head metadata and SEO optimization * - Has slots for page content, header, and footer * - Imports and uses the Header and Footer components * - Sets up viewport and responsive configurations * `, * system: "You are an expert Astro developer. Create a single Astro layout file inside ```astro fences with no additional text. Follow Astro best practices and include proper typing in the frontmatter section.", * model: { * id: "claude-3-opus-20240229", * provider: "anthropic" * } * }); */ export declare const AstroFile: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context, id: string, props: AstroFileProps) => Promise); //# sourceMappingURL=astro-file.d.ts.map