(imagePath: string, brief: string)
| 15 | * Check a generated mockup against the original brief. |
| 16 | */ |
| 17 | export async function checkMockup(imagePath: string, brief: string): Promise<CheckResult> { |
| 18 | const apiKey = requireApiKey(); |
| 19 | const imageData = fs.readFileSync(imagePath).toString("base64"); |
| 20 | |
| 21 | const controller = new AbortController(); |
| 22 | const timeout = setTimeout(() => controller.abort(), 60_000); |
| 23 | |
| 24 | try { |
| 25 | const response = await fetch("https://api.openai.com/v1/chat/completions", { |
| 26 | method: "POST", |
| 27 | headers: { |
| 28 | "Authorization": `Bearer ${apiKey}`, |
| 29 | "Content-Type": "application/json", |
| 30 | }, |
| 31 | body: JSON.stringify({ |
| 32 | model: "gpt-4o", |
| 33 | messages: [{ |
| 34 | role: "user", |
| 35 | content: [ |
| 36 | { |
| 37 | type: "image_url", |
| 38 | image_url: { url: `data:image/png;base64,${imageData}` }, |
| 39 | }, |
| 40 | { |
| 41 | type: "text", |
| 42 | text: [ |
| 43 | "You are a UI quality checker. Evaluate this mockup against the design brief.", |
| 44 | "", |
| 45 | `Brief: ${brief}`, |
| 46 | "", |
| 47 | "Check these 3 things:", |
| 48 | "1. TEXT READABILITY: Are all labels, headings, and body text legible? Any misspellings?", |
| 49 | "2. LAYOUT COMPLETENESS: Are all requested elements present? Anything missing?", |
| 50 | "3. VISUAL COHERENCE: Does it look like a real production UI, not AI art or a collage?", |
| 51 | "", |
| 52 | "Respond with exactly one line:", |
| 53 | "PASS — if all 3 checks pass", |
| 54 | "FAIL: [list specific issues] — if any check fails", |
| 55 | ].join("\n"), |
| 56 | }, |
| 57 | ], |
| 58 | }], |
| 59 | max_tokens: 200, |
| 60 | }), |
| 61 | signal: controller.signal, |
| 62 | }); |
| 63 | |
| 64 | if (!response.ok) { |
| 65 | const error = await response.text(); |
| 66 | if (response.status === 403 && error.includes("organization must be verified")) { |
| 67 | console.error("OpenAI organization verification required. Go to https://platform.openai.com/settings/organization to verify."); |
| 68 | return { pass: true, issues: "OpenAI org not verified — vision check skipped" }; |
| 69 | } |
| 70 | // Non-blocking: if vision check fails, default to PASS with warning |
| 71 | console.error(`Vision check API error (${response.status}): ${error}`); |
| 72 | return { pass: true, issues: "Vision check unavailable — skipped" }; |
| 73 | } |
| 74 |
no test coverage detected