'use server'; /** * @fileOverview This file defines a Genkit flow that helps new users by suggesting an initial set of code files * and project structure based on a simple prompt describing the desired application. * * - aiHelpFromPrompt - A function that takes a prompt and returns suggested code files and project structure. * - AIHelpFromPromptInput - The input type for the aiHelpFromPrompt function. * - AIHelpFromPromptOutput - The return type for the aiHelpFromPrompt function. */ import {ai} from '@/ai/genkit'; import {z} from 'genkit'; const AIHelpFromPromptInputSchema = z.object({ prompt: z.string().describe('A prompt describing the type of application to build.'), }); export type AIHelpFromPromptInput = z.infer; const AIHelpFromPromptOutputSchema = z.object({ suggestedFiles: z.array(z.object({ filePath: z.string().describe('The path for the suggested file.'), fileContent: z.string().describe('The content of the suggested file.'), })).describe('An array of suggested code files and their content.'), explanation: z.string().describe('An explanation of the suggested file structure and code.'), }); export type AIHelpFromPromptOutput = z.infer; export async function aiHelpFromPrompt(input: AIHelpFromPromptInput): Promise { return aiHelpFromPromptFlow(input); } const prompt = ai.definePrompt({ name: 'aiHelpFromPromptPrompt', input: {schema: AIHelpFromPromptInputSchema}, output: {schema: AIHelpFromPromptOutputSchema}, prompt: `You are an AI assistant designed to help new users quickly start developing applications. Based on the user's prompt describing the desired application, suggest an initial set of code files and a project structure to get them started. Provide the suggested files as an array of objects, each containing the file path and the file content. Explain the suggested file structure and the code in detail so that the user understands the purpose of each file and how they fit together. User Prompt: {{{prompt}}} Example Output: { "suggestedFiles": [ { "filePath": "src/components/MyComponent.tsx", "fileContent": "// MyComponent.tsx\nimport React from 'react';\n\nconst MyComponent = () => {\n return (\n
\n

Hello, world!

\n
\n );\n};\n\nexport default MyComponent;" }, { "filePath": "src/pages/index.tsx", "fileContent": "// index.tsx\nimport MyComponent from '../components/MyComponent';\n\nconst Home = () => {\n return (\n
\n \n
\n );\n};\n\nexport default Home;" } ], "explanation": "This project structure includes a component (MyComponent.tsx) and a page (index.tsx) that uses the component. This is a basic structure for a React application." } `, }); const aiHelpFromPromptFlow = ai.defineFlow( { name: 'aiHelpFromPromptFlow', inputSchema: AIHelpFromPromptInputSchema, outputSchema: AIHelpFromPromptOutputSchema, }, async input => { const {output} = await prompt(input, { config: { safetySettings: [ { category: 'HARM_CATEGORY_HATE_SPEECH', threshold: 'BLOCK_ONLY_HIGH', }, { category: 'HARM_CATEGORY_DANGEROUS_CONTENT', threshold: 'BLOCK_NONE', }, { category: 'HARM_CATEGORY_HARASSMENT', threshold: 'BLOCK_MEDIUM_AND_ABOVE', }, { category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', threshold: 'BLOCK_LOW_AND_ABOVE', }, ], }, }); return output!; } ); 'use server'; /** * @fileOverview This file defines a Genkit flow that helps new users by suggesting an initial set of code files * and project structure based on a simple prompt describing the desired application. * * - aiHelpFromPrompt - A function that takes a prompt and returns suggested code files and project structure. * - AIHelpFromPromptInput - The input type for the aiHelpFromPrompt function. * - AIHelpFromPromptOutput - The return type for the aiHelpFromPrompt function. */ import {ai} from '@/ai/genkit'; import {z} from 'genkit'; const AIHelpFromPromptInputSchema = z.object({ prompt: z.string().describe('A prompt describing the type of application to build.'), }); export type AIHelpFromPromptInput = z.infer; const AIHelpFromPromptOutputSchema = z.object({ suggestedFiles: z.array(z.object({ filePath: z.string().describe('The path for the suggested file.'), fileContent: z.string().describe('The content of the suggested file.'), })).describe('An array of suggested code files and their content.'), explanation: z.string().describe('An explanation of the suggested file structure and code.'), }); export type AIHelpFromPromptOutput = z.infer; export async function aiHelpFromPrompt(input: AIHelpFromPromptInput): Promise { return aiHelpFromPromptFlow(input); } const prompt = ai.definePrompt({ name: 'aiHelpFromPromptPrompt', input: {schema: AIHelpFromPromptInputSchema},