| @@ -2,14 +2,19 @@ | ||
| 2 | 2 | import { reqDataBasics } from '@shared/lib/data'; |
| 3 | 3 | import { retryTwice } from './helpers'; |
| 4 | 4 | |
| 5 | 5 | const generatePatterns = async (page, data) => { |
| 6 | - const { siteProfile } = data; | |
| 6 | + const { siteProfile, designBuild } = data; | |
| 7 | 7 | return await retryTwice(async () => { |
| 8 | 8 | const response = await fetch(`${AI_HOST}/api/patterns`, { |
| 9 | 9 | method: 'POST', |
| 10 | 10 | headers: { 'Content-Type': 'application/json' }, |
| 11 | - body: JSON.stringify({ ...reqDataBasics, siteProfile, page }), | |
| 11 | + body: JSON.stringify({ | |
| 12 | + ...reqDataBasics, | |
| 13 | + siteProfile, | |
| 14 | + page, | |
| 15 | + buildId: designBuild?.buildId, | |
| 16 | + }), | |
| 12 | 17 | }); |
| 13 | 18 | if (!response.ok) { |
| 14 | 19 | throw new Error( |
| 15 | 20 | `Pattern generation failed with status ${response.status}`, |
| @@ -29,13 +34,12 @@ | ||
| 29 | 34 | export const generatePageContent = async (pages, data) => { |
| 30 | 35 | const splits = pages.map(splitGeneratedContent); |
| 31 | 36 | |
| 32 | 37 | const result = await Promise.allSettled( |
| 33 | - splits.map( | |
| 34 | - ({ toGenerate }) => | |
| 35 | - generatePatterns(toGenerate, data) | |
| 36 | - .then((response) => response) | |
| 37 | - .catch(() => toGenerate), // safe fallback | |
| 38 | + splits.map(({ toGenerate }) => | |
| 39 | + toGenerate.patterns.length | |
| 40 | + ? generatePatterns(toGenerate, data).catch(() => toGenerate) | |
| 41 | + : Promise.resolve(toGenerate), | |
| 38 | 42 | ), |
| 39 | 43 | ); |
| 40 | 44 | |
| 41 | 45 | return result?.map((pageResult, i) => { |