Spaces:
Sleeping
Sleeping
| export interface GeneratedFile { | |
| path: string; | |
| content: string; | |
| } | |
| // Parses model output formatted as: | |
| // ### FILE: app/page.tsx | |
| // ```tsx | |
| // ...content... | |
| // ``` | |
| export function parseGeneratedFiles(raw: string): GeneratedFile[] { | |
| const files: GeneratedFile[] = []; | |
| const fileBlockRegex = /### FILE:\s*(.+?)\s*\n```[a-zA-Z]*\n([\s\S]*?)```/g; | |
| let match: RegExpExecArray | null; | |
| while ((match = fileBlockRegex.exec(raw)) !== null) { | |
| const filePath = match[1].trim(); | |
| const content = match[2].replace(/\s+$/, "") + "\n"; | |
| files.push({ path: filePath, content }); | |
| } | |
| return files; | |
| } | |