@aglyn/plugins-ai 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-site-build-page.component.js +5 -3
  3. package/src/lib/components/ai-site-build-page.component.js.map +1 -1
  4. package/src/lib/components/ai-site-import-finish.component.d.ts +3 -1
  5. package/src/lib/components/ai-site-import-finish.component.js +3 -3
  6. package/src/lib/components/ai-site-import-finish.component.js.map +1 -1
  7. package/src/lib/components/ai-site-import-job.component.d.ts +4 -3
  8. package/src/lib/components/ai-site-import-job.component.js +141 -43
  9. package/src/lib/components/ai-site-import-job.component.js.map +1 -1
  10. package/src/lib/components/ai-site-import-plan.component.d.ts +42 -0
  11. package/src/lib/components/ai-site-import-plan.component.js +246 -0
  12. package/src/lib/components/ai-site-import-plan.component.js.map +1 -0
  13. package/src/lib/components/ai-site-import-start.component.d.ts +3 -1
  14. package/src/lib/components/ai-site-import-start.component.js +3 -2
  15. package/src/lib/components/ai-site-import-start.component.js.map +1 -1
  16. package/src/lib/components/ai-site-start-card.component.js +6 -2
  17. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  18. package/src/lib/components/ai-site-start-steps.component.d.ts +3 -2
  19. package/src/lib/components/ai-site-start-steps.component.js +12 -5
  20. package/src/lib/components/ai-site-start-steps.component.js.map +1 -1
  21. package/src/lib/jobs/ai-job-import-step.d.ts +47 -2
  22. package/src/lib/jobs/ai-job-import-step.js +356 -22
  23. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  24. package/src/lib/jobs/ai-job-layout-language.js +4 -1
  25. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  26. package/src/lib/jobs/ai-job-page-language.d.ts +21 -2
  27. package/src/lib/jobs/ai-job-page-language.js +217 -5
  28. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  29. package/src/lib/jobs/ai-job-page-step.d.ts +7 -0
  30. package/src/lib/jobs/ai-job-page-step.js +73 -12
  31. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  32. package/src/lib/jobs/ai-job-plan-step.js +4 -2
  33. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  34. package/src/lib/jobs/ai-job-site-look.js +14 -5
  35. package/src/lib/jobs/ai-job-site-look.js.map +1 -1
  36. package/src/lib/jobs/ai-job-text-step.d.ts +10 -2
  37. package/src/lib/jobs/ai-job-text-step.js.map +1 -1
  38. package/src/lib/jobs/ai-jobs.js +2 -1
  39. package/src/lib/jobs/ai-jobs.js.map +1 -1
  40. package/src/lib/jobs/ai-site-import-compile.d.ts +43 -2
  41. package/src/lib/jobs/ai-site-import-compile.js +105 -62
  42. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  43. package/src/lib/jobs/ai-site-import-document.d.ts +25 -1
  44. package/src/lib/jobs/ai-site-import-document.js +26 -7
  45. package/src/lib/jobs/ai-site-import-document.js.map +1 -1
  46. package/src/lib/jobs/ai-site-import-honesty.d.ts +65 -0
  47. package/src/lib/jobs/ai-site-import-honesty.js +271 -0
  48. package/src/lib/jobs/ai-site-import-honesty.js.map +1 -0
  49. package/src/lib/jobs/ai-site-import-improve.d.ts +233 -0
  50. package/src/lib/jobs/ai-site-import-improve.js +1151 -0
  51. package/src/lib/jobs/ai-site-import-improve.js.map +1 -0
  52. package/src/lib/jobs/ai-site-import-look.d.ts +4 -0
  53. package/src/lib/jobs/ai-site-import-look.js +16 -6
  54. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  55. package/src/lib/jobs/ai-site-import-pictures.d.ts +83 -0
  56. package/src/lib/jobs/ai-site-import-pictures.js +261 -0
  57. package/src/lib/jobs/ai-site-import-pictures.js.map +1 -0
  58. package/src/lib/jobs/ai-site-import-plan.d.ts +78 -0
  59. package/src/lib/jobs/ai-site-import-plan.js +627 -0
  60. package/src/lib/jobs/ai-site-import-plan.js.map +1 -0
  61. package/src/lib/jobs/ai-site-import-wording.js +2 -5
  62. package/src/lib/jobs/ai-site-import-wording.js.map +1 -1
  63. package/src/lib/layout-language/ai-layout-compiler.d.ts +6 -0
  64. package/src/lib/layout-language/ai-layout-compiler.js +10 -6
  65. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  66. package/src/lib/layout-language/ai-layout-design.d.ts +9 -0
  67. package/src/lib/layout-language/ai-layout-design.js +29 -3
  68. package/src/lib/layout-language/ai-layout-design.js.map +1 -1
  69. package/src/lib/layout-language/ai-layout-frame-source.d.ts +5 -0
  70. package/src/lib/layout-language/ai-layout-frame-source.js +4 -2
  71. package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
  72. package/src/lib/layout-language/ai-layout-frame.d.ts +2 -0
  73. package/src/lib/layout-language/ai-layout-frame.js +20 -12
  74. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  75. package/src/lib/layout-language/ai-layout-language.d.ts +8 -0
  76. package/src/lib/layout-language/ai-layout-language.js +7 -3
  77. package/src/lib/layout-language/ai-layout-language.js.map +1 -1
  78. package/src/lib/model/ai-site-import-fidelity.d.ts +62 -0
  79. package/src/lib/model/ai-site-import-fidelity.js +374 -0
  80. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  81. package/src/lib/model/ai-site-import-ledger.d.ts +82 -0
  82. package/src/lib/model/ai-site-import-ledger.js +254 -0
  83. package/src/lib/model/ai-site-import-ledger.js.map +1 -0
  84. package/src/lib/model/ai-site-import-view.d.ts +110 -6
  85. package/src/lib/model/ai-site-import-view.js +166 -13
  86. package/src/lib/model/ai-site-import-view.js.map +1 -1
  87. package/src/lib/model/ai-site-import.d.ts +227 -2
  88. package/src/lib/model/ai-site-import.js +312 -15
  89. package/src/lib/model/ai-site-import.js.map +1 -1
  90. package/src/lib/model/ai-site-job.js +4 -0
  91. package/src/lib/model/ai-site-job.js.map +1 -1
  92. package/src/lib/model/ai-site-kinds.d.ts +2 -0
  93. package/src/lib/model/ai-site-kinds.js +7 -0
  94. package/src/lib/model/ai-site-kinds.js.map +1 -1
  95. package/src/lib/model/ai-site-look.d.ts +14 -5
  96. package/src/lib/model/ai-site-look.js +22 -16
  97. package/src/lib/model/ai-site-look.js.map +1 -1
  98. package/src/lib/model/ai-site-start.d.ts +37 -7
  99. package/src/lib/model/ai-site-start.js +54 -10
  100. package/src/lib/model/ai-site-start.js.map +1 -1
  101. package/src/lib/model/ai-site-starter-look.d.ts +69 -0
  102. package/src/lib/model/ai-site-starter-look.js +90 -0
  103. package/src/lib/model/ai-site-starter-look.js.map +1 -0
  104. package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -0
  105. package/src/lib/runtime/ai-doctrine-validators.js +3 -2
  106. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  107. package/src/lib/runtime/ai-doctrine.d.ts +10 -0
  108. package/src/lib/runtime/ai-doctrine.js +16 -2
  109. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  110. package/src/lib/server/ai-jobs-resume.js +12 -3
  111. package/src/lib/server/ai-jobs-resume.js.map +1 -1
  112. package/src/lib/server/ai-jobs-route.js +5 -1
  113. package/src/lib/server/ai-jobs-route.js.map +1 -1
  114. package/src/lib/server/ai-site-import-route.d.ts +6 -0
  115. package/src/lib/server/ai-site-import-route.js +8 -1
  116. package/src/lib/server/ai-site-import-route.js.map +1 -1
  117. package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +46 -7
  118. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +260 -14
  119. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  120. package/src/lib/site-import/fixtures/site-import-improve-answers.d.ts +33 -0
  121. package/src/lib/site-import/fixtures/site-import-improve-answers.js +457 -0
  122. package/src/lib/site-import/fixtures/site-import-improve-answers.js.map +1 -0
  123. package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +29 -0
  124. package/src/lib/site-import/fixtures/site-layout-recordings.js +26 -0
  125. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  126. package/src/lib/site-import/site-import-flag.d.ts +17 -0
  127. package/src/lib/site-import/site-import-flag.js +15 -0
  128. package/src/lib/site-import/site-import-flag.js.map +1 -1
@@ -91,7 +91,10 @@ export function aiLayoutSiteBrandOf(inputs) {
91
91
  // The logo's own words and shape, as the source names and draws it (AGL-4108).
92
92
  const alt = typeof value['alt'] === 'string' ? value['alt'].replace(/\s+/g, ' ').trim().slice(0, 120) : '';
93
93
  const aspect = typeof value['aspect'] === 'number' && Number.isFinite(value['aspect']) && value['aspect'] > 0 ? Math.min(value['aspect'], 8) : null;
94
- return _extends({}, src ? {
94
+ const height = typeof value['height'] === 'string' && /^\d{2}px$/.test(value['height']) ? value['height'] : null;
95
+ return _extends({}, src && height ? {
96
+ height
97
+ } : {}, src ? {
95
98
  logo: {
96
99
  src
97
100
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-layout-language.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isHostImageToken, resolveHostToken, type HostTokenSource } from '@aglyn/aglyn/app-utils/host-tokens'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { aiLayoutDesignChoices, type AiLayoutDesign } from '../layout-language/ai-layout-design'\nimport { aiCompileLayoutFrame, type AiLayoutFrameBrand } from '../layout-language/ai-layout-frame'\nimport { aiLayoutFrameSourceOf, aiLayoutFrameSourcePageIds, type AiLayoutFrameSource } from '../layout-language/ai-layout-frame-source'\nimport {\n aiLayoutFrameHollows,\n aiLayoutFrameHollowsSaid,\n aiLayoutFrameIsHollow,\n aiLayoutRepairFrameHollows,\n} from '../layout-language/ai-layout-frame-hollows'\nimport {\n AI_LAYOUT_FRAME_TOOL,\n AI_LAYOUT_LANGUAGE_TEXT,\n aiReadLayoutFrame,\n type AiLayoutSection,\n} from '../layout-language/ai-layout-language'\nimport type {\n AiLayoutPage,\n AiLayoutTargets,\n} from '../layout-language/ai-layout-links'\nimport { aiLayoutCopyCheck } from '../layout-language/ai-layout-gaps'\nimport { aiLayoutStoredTree } from '../layout-language/ai-layout-store'\nimport { AI_GENERATION_MAX_ATTEMPTS } from '../runtime/ai-generation-bounds'\nimport type { AiJob, AiJobPlan } from '../model/ai-jobs.types'\nimport { aiLayoutSpeaksOtherThanEnglish } from '../layout-language/ai-layout-labels'\nimport {\n aiHomeScreenIds,\n type AiSiteInventory,\n} from '../model/ai-site-inventory'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport type { AiGenerationCheck, AiValidatedTree } from '../runtime/ai-doctrine'\nimport {\n aiSettleMechanicalRules,\n aiSettleUnrelatedScreenLinks,\n validateAiDoctrineTree,\n type AiDoctrineNode,\n type AiDoctrineViolation,\n} from '../runtime/ai-doctrine-validators'\nimport type { AiLoadEstimate } from '../runtime/ai-palette'\nimport { aiSiteKindDesignLines } from '../model/ai-site-kinds'\nimport type { AiStoreFrameLinks } from '../model/ai-site-store-pages'\nimport type { AiSystemBlock } from '../runtime/ai-runtime'\nimport { aiJobStepBudget } from './ai-job-budget'\nimport { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from '@aglyn/shared-util-tools/untrusted-text'\nimport { aiJobBriefLine } from './ai-job-generation'\nimport {\n AI_LAYOUT_SITE_PAGES_MAX,\n aiLayoutIsHomeSlug,\n aiLayoutSitePages,\n} from './ai-job-layout-site-pages'\nimport {\n AI_LAYOUT_FRAME_THINKING_TOKENS,\n aiLayoutPageTargets,\n} from './ai-job-page-language'\nimport { AI_SITE_NAME_TOKEN } from './ai-layout-site-facts'\n\n/**\n * A site's layout built in the compact layout language (AGL-3660): the layout\n * step's pass for a guided start's and a build's layout unit. The model\n * designs the header and the footer — their bands, the call to action, the\n * footer's columns and every word — in one short answer through\n * `submit_frame`, and the compiler writes the layout around what the site\n * owes it: its name as the brand, its pages as the navigation and the phone\n * menu, the Layout Slot, and the footer at the bottom of a short page\n * (`ai-layout-frame.ts`).\n */\n\n/**\n * The most a frame's answer asks for: two sections of a few blocks each (the\n * live runs of 2026-10-07 wrote 442 to 583), and the thinking before them.\n */\nexport const AI_JOB_LAYOUT_LANGUAGE_TOKENS = 1_200 + AI_LAYOUT_FRAME_THINKING_TOKENS\n\n/** A language layout pass's time, on the tier the layout step is served from. */\nexport const AI_JOB_LAYOUT_LANGUAGE_BUDGET = aiJobStepBudget({\n tier: AI_STEP_TIERS['job.layout'],\n maxTokens: AI_JOB_LAYOUT_LANGUAGE_TOKENS,\n})\n\n/** The generation kind a frame is asked under, which the doctrine scopes. */\nexport const AI_LAYOUT_FRAME_KIND = 'layout-frame'\n\n/** The language, as the frame door's cached instructions. */\nexport const AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS: readonly AiSystemBlock[] = [\n {\n text: [\n AI_LAYOUT_LANGUAGE_TEXT,\n '',\n \"Now you design a site's header and footer, each one section of the language, answered with submit_frame.\",\n \"- header: the platform writes the site's name and its navigation itself. Choose its band and align (start, or center for a centered navigation), and give it at most one button: the call to action every page shows.\",\n '- footer: a section like any other, usually a row of two or three columns: a few words about the business, the details the brief gives, and a list of links (items with to). Put no contact detail, opening hours or address in it that the brief does not give, and no gap in square brackets for one.',\n ].join('\\n'),\n cacheBreakpoint: true,\n },\n]\n\n/**\n * The unit input a site brought in from elsewhere gives its header and\n * footer (AGL-4084): its header's brand as the source draws it, and the words\n * the source's header and footer carry — its address, phone, email, hours\n * and profiles — word for word. Read defensively; `null` on every other job.\n */\nexport const AI_LAYOUT_SITE_BRAND_INPUT = 'siteBrand'\nexport const AI_LAYOUT_SITE_FACTS_INPUT = 'siteFacts'\n\n/**\n * The unit input a site brought in gives its header and footer where the\n * reader found the source's menu (AGL-4108): its menu, its buttons and its\n * footer, every link resolved to a page of the site or the source's own\n * address (`AiLayoutFrameSource`). With it the frame is drawn by code and no\n * model is asked; read defensively, `null` on every other job.\n */\nexport const AI_LAYOUT_SITE_FRAME_INPUT = 'siteFrame'\n\n/** A job's source frame (AGL-4108), held to what a link and a label may carry; `null` where it has none. */\nexport function aiLayoutSiteFrameOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLayoutFrameSource | null {\n return aiLayoutFrameSourceOf(inputs?.[AI_LAYOUT_SITE_FRAME_INPUT])\n}\n\n/** The most characters of a site's own header and footer words a frame is shown. */\nexport const AI_LAYOUT_SITE_FACTS_MAX_CHARS = 4_000\n\nexport interface AiLayoutSiteFacts {\n /** Where they were read: the owner's own home page. */\n url: string\n /** The site's own description of itself. */\n description: string\n /** Its header's and footer's lines, as written. */\n lines: string[]\n}\n\nexport function aiLayoutSiteBrandOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLayoutFrameBrand | null {\n const raw = inputs?.[AI_LAYOUT_SITE_BRAND_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const logo = value['logo'] as Record<string, unknown> | null | undefined\n const src = typeof logo?.['src'] === 'string' && logo['src'].trim() ? logo['src'].trim() : null\n // The logo's own words and shape, as the source names and draws it (AGL-4108).\n const alt = typeof value['alt'] === 'string' ? value['alt'].replace(/\\s+/g, ' ').trim().slice(0, 120) : ''\n const aspect = typeof value['aspect'] === 'number' && Number.isFinite(value['aspect']) && value['aspect'] > 0 ? Math.min(value['aspect'], 8) : null\n return {\n ...(src ? { logo: { src } } : {}),\n name: src ? value['name'] === true : true,\n ...(src && alt ? { alt } : {}),\n ...(src && aspect ? { aspect } : {}),\n // The footer opens with the logo too, where the source's does (AGL-4139).\n ...(src && value['footer'] === true ? { footer: true } : {}),\n }\n}\n\n/**\n * The brand a site's own logo gives its frame (AGL-4119), for the logo a\n * person brought to Create site: the logo alone, in the header and the footer.\n * By token rather than by value, so a logo changed later follows. `null` for\n * a site with none, whose frame carries its name as it always has.\n */\nexport function aiLayoutHostBrandOf(host: HostTokenSource | null | undefined): AiLayoutFrameBrand | null {\n if (!resolveHostToken('logo', host)) return null\n return {\n logo: { src: '{{host.logo}}' },\n ...(host?.logoDarkUrl?.trim() ? { logoDark: { src: '{{host.logoDark}}' } } : {}),\n name: false,\n footer: true,\n }\n}\n\n/** A job's brand: what a site brought in draws its logo as, else the site's own logo. */\nexport function aiLayoutFrameBrandOf(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n host: HostTokenSource | null | undefined,\n): AiLayoutFrameBrand | null {\n const brought = aiLayoutSiteBrandOf(inputs)\n return brought?.logo ? brought : (aiLayoutHostBrandOf(host) ?? brought)\n}\n\nexport function aiLayoutSiteFactsOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLayoutSiteFacts | null {\n const raw = inputs?.[AI_LAYOUT_SITE_FACTS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const lines = Array.isArray(value['lines']) ? value['lines'].filter((line): line is string => typeof line === 'string' && !!line.trim()) : []\n const description = typeof value['description'] === 'string' ? value['description'] : ''\n if (!lines.length && !description.trim()) return null\n return { url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '', description, lines }\n}\n\n/** A site's own header and footer words as one text, which its frame's contact details are held to (AGL-4084). */\nexport function aiLayoutSiteFactsText(inputs: Readonly<Record<string, unknown>> | null | undefined): string {\n const facts = aiLayoutSiteFactsOf(inputs)\n return facts ? [facts.description, ...facts.lines].filter(Boolean).join('\\n') : ''\n}\n\n/**\n * What a frame brought in from the owner's own site is told (AGL-4084): its\n * footer carries the details the source's header and footer give, as they\n * give them, and nothing else; the words themselves, fenced as data.\n */\nexport function aiLayoutSiteFactsLines(facts: AiLayoutSiteFacts | null): string[] {\n if (!facts) return []\n const text = [facts.description ? `About the site, in its own words: ${facts.description}` : '', ...facts.lines].filter(Boolean).join('\\n')\n return [\n \"This site's header and footer on its owner's current website carry the words below. Put in the footer the details they give (the address, phone number, email, hours and profiles), written exactly as they are written there, and its own words about itself; invent nothing they do not give, and print no word of these instructions.\",\n fenceUntrustedText(`The header and footer of ${facts.url || \"the owner's site\"}`, text, { maxChars: AI_LAYOUT_SITE_FACTS_MAX_CHARS }),\n ]\n}\n\n/** The frame door's system blocks: the language's, and for a site brought in the rule that fenced text is data (AGL-4084). */\nexport function aiJobLayoutLanguageInstructions(job: Pick<AiJob, 'inputs'>): readonly AiSystemBlock[] {\n return aiLayoutSiteFactsOf(job.inputs)\n ? [...AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS, { text: UNTRUSTED_TEXT_RULE }]\n : AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS\n}\n\n/** The site's name as the brand: the name the job was given, else the token the site's own name fills. */\nexport function aiLayoutSiteName(job: Pick<AiJob, 'inputs'>): string {\n const given = job.inputs?.['businessName']\n return typeof given === 'string' && given.trim()\n ? given.trim()\n : AI_SITE_NAME_TOKEN\n}\n\n/** The pages a frame's navigation links: the planned pages, else the site's own, in order. */\nexport function aiLayoutNavPages(\n job: Pick<AiJob, 'inputs'> & { plan?: Pick<AiJobPlan, 'language'> | null },\n inventory: AiSiteInventory | null,\n): AiLayoutPage[] {\n // The header and the footer link the pages the job was told (AGL-3660),\n // else the site's own, the home page always and first, labelled Home. The\n // model draws neither list, so it cannot drop a page. A site in another\n // language keeps its home page's own title: a Spanish start's \"Inicio\" was\n // linked as \"Home\" (AGL-3760).\n const planned = aiLayoutSitePages(job.inputs)\n const own = (inventory?.screens ?? [])\n .filter((row) => !row.template)\n .map((row) => ({ id: row.id, label: row.name, slug: row.slug }))\n const siteHome = planned.some((page) => aiLayoutIsHomeSlug(page.slug))\n ? []\n : own.filter((page) => aiLayoutIsHomeSlug(page.slug)).slice(0, 1)\n const pages = [...siteHome, ...(planned.length ? planned : own)].filter((page) => page.label.trim())\n const home = pages.find((page) => aiLayoutIsHomeSlug(page.slug))\n return [\n ...(home ? [aiLayoutSpeaksOtherThanEnglish(job.plan?.language) ? home : { ...home, label: 'Home' }] : []),\n ...pages.filter((page) => page !== home && !aiLayoutIsHomeSlug(page.slug)),\n ].slice(0, AI_LAYOUT_SITE_PAGES_MAX)\n}\n\n/** The home page the brand links: the planned home, else the site's. */\nexport function aiLayoutHomeId(\n pages: readonly AiLayoutPage[],\n inventory: AiSiteInventory | null,\n): string | null {\n const planned = pages.find((page) => aiLayoutIsHomeSlug(page.slug))\n return planned?.id ?? aiHomeScreenIds(inventory)[0] ?? null\n}\n\n/** The frame's user turn: the site, its brief, its pages and its form. */\nexport function aiLayoutFramePrompt(input: {\n job: Pick<AiJob, 'brief' | '$id'> & Partial<Pick<AiJob, 'inputs'>>\n siteName: string\n pages: readonly AiLayoutPage[]\n targets: AiLayoutTargets\n}): string {\n const { job, pages, targets } = input\n // A site brought in (AGL-4084) is told its own words, fenced, and no brief a footer could print.\n const facts = aiLayoutSiteFactsOf(job.inputs)\n return [\n `Site: ${input.siteName === AI_SITE_NAME_TOKEN ? 'the business the brief describes' : `\"${input.siteName}\"`}`,\n ...(facts ? aiLayoutSiteFactsLines(facts) : [aiJobBriefLine(job)]),\n ...aiSiteKindDesignLines(job.inputs),\n pages.length\n ? `Its pages, which the navigation links: ${pages.map((page) => `${page.label} (page:${page.id})`).join(', ')}.`\n : 'It has no pages yet.',\n targets.forms.length || targets.formPageId\n ? 'A call to action that asks a visitor to get in touch goes to form.'\n : 'The site has no form yet.',\n // A storefront's header (AGL-3676): its cart, and an announcement line.\n ...(aiLayoutShopPageId(targets)\n ? [\n \"This is an online store: give the header no button, since the platform puts the cart beside the navigation. Give the header one note instead: a short announcement for the bar above it, under 60 characters, about the shop from the brief (a promise it makes, such as its shipping, or what is new); never invent an offer, a discount, a price or a shipping threshold the brief does not give.\",\n ]\n : []),\n `Design seed: ${job.$id.slice(-6)}.`,\n ].join('\\n')\n}\n\n/** A store's Shop page, by its id: the page its catalog's whole list is placed on (AGL-3676). */\nexport function aiLayoutShopPageId(targets: Pick<AiLayoutTargets, 'listings'>): string | null {\n const products = (targets.listings ?? []).find((listing) => listing.kind === 'products')\n return products?.placements.find((placement) => placement.role === 'index')?.screenId ?? null\n}\n\n/** A validated language layout. */\nexport interface AiLayoutFrameBuilt {\n rootId: string\n nodes: NodesMap\n load: AiLoadEstimate | null\n /** What the last answer's gaps took out of the frame (`ai-layout-gaps.ts`). */\n dropped: string[]\n}\n\n/** What a frame is built with: the site, its pages and links, its look, and the layout door's own checks. */\nexport interface AiLayoutFrameInput {\n /** The header arrangement the site's look chose (AGL-3660); the answer's otherwise. */\n headerAlign?: 'start' | 'center'\n siteName: string\n homeId: string | null\n pages: readonly AiLayoutPage[]\n targets: AiLayoutTargets\n extend: (tree: AiValidatedTree) => AiDoctrineViolation[]\n /** The site's design (`aiLayoutDesignOf`), whose pages' closing band the footer sits under. */\n design?: AiLayoutDesign | null\n /** A store's own pages, which the header and footer link by path (AGL-3676). */\n storeLinks?: AiStoreFrameLinks | null\n /** The site's language, which the frame's own words are written in (AGL-3760). */\n language?: string\n /** The header's brand as a site brought in draws it (AGL-4084). */\n brand?: AiLayoutFrameBrand | null\n /** A site brought in's own header and footer (AGL-4108), drawn in place of the design's. */\n source?: AiLayoutFrameSource | null\n}\n\n/** The check a frame answer is held to: read, compiled, stored and checked as a layout, with the layout door's own checks. */\nexport function aiLayoutFrameCheck(input: AiLayoutFrameInput): AiGenerationCheck<AiLayoutFrameBuilt> {\n let answers = 0\n return (answer) => {\n // The last answer a generation takes has its gaps taken out rather than asked about again.\n answers += 1\n return aiLayoutFrameBuild(aiReadLayoutFrame(answer), input, answers >= AI_GENERATION_MAX_ATTEMPTS)\n }\n}\n\n/**\n * A site brought in's header and footer as its source builds them\n * (AGL-4108), with no model: compiled, stored and checked as a layout, held\n * to every check an answer is. `value` is `null` with the violations where it\n * does not pass, and the frame is then designed by the model instead.\n */\nexport function aiLayoutSourceFrameBuild(input: AiLayoutFrameInput & { source: AiLayoutFrameSource }): ReturnType<AiGenerationCheck<AiLayoutFrameBuilt>> {\n const band = input.source.header === 'brand' || input.source.header === 'dark' ? input.source.header : 'plain'\n return aiLayoutFrameBuild({ header: { band, align: 'start', blocks: [] }, footer: null }, input, true)\n}\n\n/** A frame compiled, stored and checked as a layout; `last` takes its gaps out rather than asking about them. */\nfunction aiLayoutFrameBuild(frame: { header: AiLayoutSection | null; footer: AiLayoutSection | null }, input: AiLayoutFrameInput, last: boolean): ReturnType<AiGenerationCheck<AiLayoutFrameBuilt>> {\n if (input.headerAlign && frame.header && !input.source) frame.header.align = input.headerAlign\n const compiled = aiCompileLayoutFrame(\n frame,\n {\n siteName: input.siteName,\n homeId: input.homeId,\n navPages: input.pages,\n closesDark: input.design ? aiLayoutDesignChoices(input.design).coverClose : false,\n // A site that sells carries its cart in the header (AGL-3676).\n cart: (input.targets.listings ?? []).some((listing) => listing.kind === 'products' && listing.cart !== false),\n // And a store's header is a storefront's: no button repeating its navigation, an announcement bar (AGL-3676).\n shopId: aiLayoutShopPageId(input.targets),\n // And its account and policies, written after it (AGL-3676).\n storeLinks: input.storeLinks ?? null,\n ...(input.language ? { language: input.language } : {}),\n ...(input.brand ? { brand: input.brand } : {}),\n ...(input.source ? { source: input.source } : {}),\n },\n input.targets,\n )\n // The pages a source's menu and footer link by id (AGL-4108).\n const sourcePages = input.source ? aiLayoutFrameSourcePageIds(input.source) : []\n // A site's own logo is a token no address rule knows (AGL-4119), and these\n // two are ours to name: no model writes them.\n const logoTokens = [input.brand?.logo?.src, input.brand?.logoDark?.src].filter(\n (src): src is string => Boolean(src && isHostImageToken(src)),\n )\n const context = {\n screenIds: [\n ...new Set([\n ...input.targets.pages.map((page) => page.id),\n ...input.pages.map((page) => page.id),\n ...(input.homeId ? [input.homeId] : []),\n ...sourcePages,\n ]),\n ],\n formIds: input.targets.forms.map((form) => form.id),\n homeScreenIds: input.targets.homeIds,\n // A link home under the home page's own title says home, in any language (AGL-3760).\n homeLabels: [\n ...input.pages.filter((page) => aiLayoutIsHomeSlug(page.slug)),\n ...input.targets.pages.filter((page) => input.targets.homeIds.includes(page.id)),\n ].map((page) => page.label),\n // A footer's \"Get in touch\" goes to the form, wherever it is placed (AGL-3729).\n ...(input.targets.formPageId ? { formScreenIds: [input.targets.formPageId] } : {}),\n codeBuilt: true,\n ...(logoTokens.length ? { bindingTokens: logoTokens } : {}),\n // A source's header and footer are its owner's own words and menu\n // (AGL-4108), drawn by code where they repeat: no model wrote a block\n // twice that a component should carry once.\n ...(input.source ? { ownWords: true, reusableComponents: false } : {}),\n }\n const stored = aiLayoutStoredTree(compiled.tree, 'layout', context)\n if (stored.ok === false) {\n console.error('ai layout frame: a compiled layout did not store', {\n error: stored.error,\n })\n return {\n value: null,\n violations: [\n {\n rule: null,\n code: 'layout-compile',\n message: 'This layout could not be built. Try again.',\n detail: stored.error,\n },\n ],\n }\n }\n // No gap and no internal reference in the words of a frame every published page shows.\n const navPages = [...input.targets.pages, ...input.pages]\n const copy = aiLayoutCopyCheck(\n stored.nodes,\n stored.rootId,\n {\n pages: navPages,\n ids: [...navPages.map((page) => page.id), ...input.targets.forms.map((form) => form.id)],\n },\n last,\n )\n const { dropped } = copy\n // An attribute a rule has one answer for is settled, not asked of the model again (AGL-3660).\n const nodes = aiSettleUnrelatedScreenLinks(\n aiSettleMechanicalRules(\n { rootId: stored.rootId, nodes: copy.nodes as unknown as Record<string, AiDoctrineNode> },\n 'layout',\n // And on the last answer, a link that goes nowhere, as the check below reads it (AGL-4076).\n last ? context : undefined,\n ),\n 'layout',\n context,\n ).nodes as unknown as typeof copy.nodes\n // The copy check can take words out of the footer: no heading or column\n // is left with nothing under it (AGL-3735), and none may remain.\n aiLayoutRepairFrameHollows(nodes as unknown as Record<string, unknown>)\n const hollow = aiLayoutFrameHollows(nodes as unknown as Record<string, unknown>)\n const report = validateAiDoctrineTree(\n { rootId: stored.rootId, nodes },\n 'layout',\n context,\n )\n const violations = [\n ...report.violations,\n ...(aiLayoutFrameIsHollow(hollow)\n ? [\n {\n rule: null,\n code: 'layout-frame-hollow',\n message: 'Every footer heading needs something under it, and every footer column more than a heading.',\n detail: aiLayoutFrameHollowsSaid(hollow).join('; '),\n },\n ]\n : []),\n ...copy.violations,\n ...input.extend({\n rootId: stored.rootId,\n nodes,\n repairs: [],\n sourceIds: {},\n score: report.score as AiValidatedTree['score'],\n load: report.load,\n }),\n ]\n return {\n value: violations.length\n ? null\n : { rootId: stored.rootId, nodes, load: report.load, dropped },\n violations,\n }\n}\n\n/** What a frame's links resolve against: the site's pages and its form, as a page's do. */\nexport function aiLayoutFrameTargets(\n job: Pick<AiJob, 'brief' | 'inputs'>,\n inventory: AiSiteInventory | null,\n): AiLayoutTargets {\n return aiLayoutPageTargets({ job, inventory, own: [] })\n}\n"],"names":["isHostImageToken","resolveHostToken","aiLayoutDesignChoices","aiCompileLayoutFrame","aiLayoutFrameSourceOf","aiLayoutFrameSourcePageIds","aiLayoutFrameHollows","aiLayoutFrameHollowsSaid","aiLayoutFrameIsHollow","aiLayoutRepairFrameHollows","AI_LAYOUT_LANGUAGE_TEXT","aiReadLayoutFrame","aiLayoutCopyCheck","aiLayoutStoredTree","AI_GENERATION_MAX_ATTEMPTS","aiLayoutSpeaksOtherThanEnglish","aiHomeScreenIds","AI_STEP_TIERS","aiSettleMechanicalRules","aiSettleUnrelatedScreenLinks","validateAiDoctrineTree","aiSiteKindDesignLines","aiJobStepBudget","fenceUntrustedText","UNTRUSTED_TEXT_RULE","aiJobBriefLine","AI_LAYOUT_SITE_PAGES_MAX","aiLayoutIsHomeSlug","aiLayoutSitePages","AI_LAYOUT_FRAME_THINKING_TOKENS","aiLayoutPageTargets","AI_SITE_NAME_TOKEN","AI_JOB_LAYOUT_LANGUAGE_TOKENS","AI_JOB_LAYOUT_LANGUAGE_BUDGET","tier","maxTokens","AI_LAYOUT_FRAME_KIND","AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS","text","join","cacheBreakpoint","AI_LAYOUT_SITE_BRAND_INPUT","AI_LAYOUT_SITE_FACTS_INPUT","AI_LAYOUT_SITE_FRAME_INPUT","aiLayoutSiteFrameOf","inputs","AI_LAYOUT_SITE_FACTS_MAX_CHARS","aiLayoutSiteBrandOf","raw","value","logo","src","trim","alt","replace","slice","aspect","Number","isFinite","Math","min","name","footer","aiLayoutHostBrandOf","host","logoDarkUrl","logoDark","aiLayoutFrameBrandOf","brought","aiLayoutSiteFactsOf","lines","Array","isArray","filter","line","description","length","url","aiLayoutSiteFactsText","facts","Boolean","aiLayoutSiteFactsLines","maxChars","aiJobLayoutLanguageInstructions","job","aiLayoutSiteName","given","aiLayoutNavPages","inventory","planned","own","screens","row","template","map","id","label","slug","siteHome","some","page","pages","home","find","plan","language","aiLayoutHomeId","aiLayoutFramePrompt","input","targets","siteName","forms","formPageId","aiLayoutShopPageId","$id","products","listings","listing","kind","placements","placement","role","screenId","aiLayoutFrameCheck","answers","answer","aiLayoutFrameBuild","aiLayoutSourceFrameBuild","band","source","header","align","blocks","frame","last","headerAlign","compiled","homeId","navPages","closesDark","design","coverClose","cart","shopId","storeLinks","brand","sourcePages","logoTokens","context","screenIds","Set","formIds","form","homeScreenIds","homeIds","homeLabels","includes","formScreenIds","codeBuilt","bindingTokens","ownWords","reusableComponents","stored","tree","ok","console","error","violations","rule","code","message","detail","copy","nodes","rootId","ids","dropped","undefined","hollow","report","extend","repairs","sourceIds","score","load","aiLayoutFrameTargets"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,gBAAgB,QAA8B,qCAAoC;AAE7G,SAASC,qBAAqB,QAA6B,yCAAqC;AAChG,SAASC,oBAAoB,QAAiC,wCAAoC;AAClG,SAASC,qBAAqB,EAAEC,0BAA0B,QAAkC,+CAA2C;AACvI,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,qBAAqB,EACrBC,0BAA0B,QACrB,gDAA4C;AACnD,SAEEC,uBAAuB,EACvBC,iBAAiB,QAEZ,2CA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,MAAM;YACrBD;YACAQ,SAAS,EAAE;YACXC,WAAW,CAAC;YACZC,OAAOJ,OAAOI,KAAK;YACnBC,MAAML,OAAOK,IAAI;QACnB;KACD;IACD,OAAO;QACLvI,OAAOsH,WAAW3F,MAAM,GACpB,OACA;YAAEkG,QAAQZ,OAAOY,MAAM;YAAED;YAAOW,MAAML,OAAOK,IAAI;YAAER;QAAQ;QAC/DT;IACF;AACF;AAEA,yFAAyF,GACzF,OAAO,SAASkB,qBACdrG,GAAoC,EACpCI,SAAiC;IAEjC,OAAO1D,oBAAoB;QAAEsD;QAAKI;QAAWE,KAAK,EAAE;IAAC;AACvD"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-layout-language.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { isHostImageToken, resolveHostToken, type HostTokenSource } from '@aglyn/aglyn/app-utils/host-tokens'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { aiLayoutDesignChoices, type AiLayoutDesign } from '../layout-language/ai-layout-design'\nimport { aiCompileLayoutFrame, type AiLayoutFrameBrand } from '../layout-language/ai-layout-frame'\nimport { aiLayoutFrameSourceOf, aiLayoutFrameSourcePageIds, type AiLayoutFrameSource } from '../layout-language/ai-layout-frame-source'\nimport {\n aiLayoutFrameHollows,\n aiLayoutFrameHollowsSaid,\n aiLayoutFrameIsHollow,\n aiLayoutRepairFrameHollows,\n} from '../layout-language/ai-layout-frame-hollows'\nimport {\n AI_LAYOUT_FRAME_TOOL,\n AI_LAYOUT_LANGUAGE_TEXT,\n aiReadLayoutFrame,\n type AiLayoutSection,\n} from '../layout-language/ai-layout-language'\nimport type {\n AiLayoutPage,\n AiLayoutTargets,\n} from '../layout-language/ai-layout-links'\nimport { aiLayoutCopyCheck } from '../layout-language/ai-layout-gaps'\nimport { aiLayoutStoredTree } from '../layout-language/ai-layout-store'\nimport { AI_GENERATION_MAX_ATTEMPTS } from '../runtime/ai-generation-bounds'\nimport type { AiJob, AiJobPlan } from '../model/ai-jobs.types'\nimport { aiLayoutSpeaksOtherThanEnglish } from '../layout-language/ai-layout-labels'\nimport {\n aiHomeScreenIds,\n type AiSiteInventory,\n} from '../model/ai-site-inventory'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport type { AiGenerationCheck, AiValidatedTree } from '../runtime/ai-doctrine'\nimport {\n aiSettleMechanicalRules,\n aiSettleUnrelatedScreenLinks,\n validateAiDoctrineTree,\n type AiDoctrineNode,\n type AiDoctrineViolation,\n} from '../runtime/ai-doctrine-validators'\nimport type { AiLoadEstimate } from '../runtime/ai-palette'\nimport { aiSiteKindDesignLines } from '../model/ai-site-kinds'\nimport type { AiStoreFrameLinks } from '../model/ai-site-store-pages'\nimport type { AiSystemBlock } from '../runtime/ai-runtime'\nimport { aiJobStepBudget } from './ai-job-budget'\nimport { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from '@aglyn/shared-util-tools/untrusted-text'\nimport { aiJobBriefLine } from './ai-job-generation'\nimport {\n AI_LAYOUT_SITE_PAGES_MAX,\n aiLayoutIsHomeSlug,\n aiLayoutSitePages,\n} from './ai-job-layout-site-pages'\nimport {\n AI_LAYOUT_FRAME_THINKING_TOKENS,\n aiLayoutPageTargets,\n} from './ai-job-page-language'\nimport { AI_SITE_NAME_TOKEN } from './ai-layout-site-facts'\n\n/**\n * A site's layout built in the compact layout language (AGL-3660): the layout\n * step's pass for a guided start's and a build's layout unit. The model\n * designs the header and the footer — their bands, the call to action, the\n * footer's columns and every word — in one short answer through\n * `submit_frame`, and the compiler writes the layout around what the site\n * owes it: its name as the brand, its pages as the navigation and the phone\n * menu, the Layout Slot, and the footer at the bottom of a short page\n * (`ai-layout-frame.ts`).\n */\n\n/**\n * The most a frame's answer asks for: two sections of a few blocks each (the\n * live runs of 2026-10-07 wrote 442 to 583), and the thinking before them.\n */\nexport const AI_JOB_LAYOUT_LANGUAGE_TOKENS = 1_200 + AI_LAYOUT_FRAME_THINKING_TOKENS\n\n/** A language layout pass's time, on the tier the layout step is served from. */\nexport const AI_JOB_LAYOUT_LANGUAGE_BUDGET = aiJobStepBudget({\n tier: AI_STEP_TIERS['job.layout'],\n maxTokens: AI_JOB_LAYOUT_LANGUAGE_TOKENS,\n})\n\n/** The generation kind a frame is asked under, which the doctrine scopes. */\nexport const AI_LAYOUT_FRAME_KIND = 'layout-frame'\n\n/** The language, as the frame door's cached instructions. */\nexport const AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS: readonly AiSystemBlock[] = [\n {\n text: [\n AI_LAYOUT_LANGUAGE_TEXT,\n '',\n \"Now you design a site's header and footer, each one section of the language, answered with submit_frame.\",\n \"- header: the platform writes the site's name and its navigation itself. Choose its band and align (start, or center for a centered navigation), and give it at most one button: the call to action every page shows.\",\n '- footer: a section like any other, usually a row of two or three columns: a few words about the business, the details the brief gives, and a list of links (items with to). Put no contact detail, opening hours or address in it that the brief does not give, and no gap in square brackets for one.',\n ].join('\\n'),\n cacheBreakpoint: true,\n },\n]\n\n/**\n * The unit input a site brought in from elsewhere gives its header and\n * footer (AGL-4084): its header's brand as the source draws it, and the words\n * the source's header and footer carry — its address, phone, email, hours\n * and profiles — word for word. Read defensively; `null` on every other job.\n */\nexport const AI_LAYOUT_SITE_BRAND_INPUT = 'siteBrand'\nexport const AI_LAYOUT_SITE_FACTS_INPUT = 'siteFacts'\n\n/**\n * The unit input a site brought in gives its header and footer where the\n * reader found the source's menu (AGL-4108): its menu, its buttons and its\n * footer, every link resolved to a page of the site or the source's own\n * address (`AiLayoutFrameSource`). With it the frame is drawn by code and no\n * model is asked; read defensively, `null` on every other job.\n */\nexport const AI_LAYOUT_SITE_FRAME_INPUT = 'siteFrame'\n\n/** A job's source frame (AGL-4108), held to what a link and a label may carry; `null` where it has none. */\nexport function aiLayoutSiteFrameOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLayoutFrameSource | null {\n return aiLayoutFrameSourceOf(inputs?.[AI_LAYOUT_SITE_FRAME_INPUT])\n}\n\n/** The most characters of a site's own header and footer words a frame is shown. */\nexport const AI_LAYOUT_SITE_FACTS_MAX_CHARS = 4_000\n\nexport interface AiLayoutSiteFacts {\n /** Where they were read: the owner's own home page. */\n url: string\n /** The site's own description of itself. */\n description: string\n /** Its header's and footer's lines, as written. */\n lines: string[]\n}\n\nexport function aiLayoutSiteBrandOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLayoutFrameBrand | null {\n const raw = inputs?.[AI_LAYOUT_SITE_BRAND_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const logo = value['logo'] as Record<string, unknown> | null | undefined\n const src = typeof logo?.['src'] === 'string' && logo['src'].trim() ? logo['src'].trim() : null\n // The logo's own words and shape, as the source names and draws it (AGL-4108).\n const alt = typeof value['alt'] === 'string' ? value['alt'].replace(/\\s+/g, ' ').trim().slice(0, 120) : ''\n const aspect = typeof value['aspect'] === 'number' && Number.isFinite(value['aspect']) && value['aspect'] > 0 ? Math.min(value['aspect'], 8) : null\n const height = typeof value['height'] === 'string' && /^\\d{2}px$/.test(value['height']) ? value['height'] : null\n return {\n ...(src && height ? { height } : {}),\n ...(src ? { logo: { src } } : {}),\n name: src ? value['name'] === true : true,\n ...(src && alt ? { alt } : {}),\n ...(src && aspect ? { aspect } : {}),\n // The footer opens with the logo too, where the source's does (AGL-4139).\n ...(src && value['footer'] === true ? { footer: true } : {}),\n }\n}\n\n/**\n * The brand a site's own logo gives its frame (AGL-4119), for the logo a\n * person brought to Create site: the logo alone, in the header and the footer.\n * By token rather than by value, so a logo changed later follows. `null` for\n * a site with none, whose frame carries its name as it always has.\n */\nexport function aiLayoutHostBrandOf(host: HostTokenSource | null | undefined): AiLayoutFrameBrand | null {\n if (!resolveHostToken('logo', host)) return null\n return {\n logo: { src: '{{host.logo}}' },\n ...(host?.logoDarkUrl?.trim() ? { logoDark: { src: '{{host.logoDark}}' } } : {}),\n name: false,\n footer: true,\n }\n}\n\n/** A job's brand: what a site brought in draws its logo as, else the site's own logo. */\nexport function aiLayoutFrameBrandOf(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n host: HostTokenSource | null | undefined,\n): AiLayoutFrameBrand | null {\n const brought = aiLayoutSiteBrandOf(inputs)\n return brought?.logo ? brought : (aiLayoutHostBrandOf(host) ?? brought)\n}\n\nexport function aiLayoutSiteFactsOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiLayoutSiteFacts | null {\n const raw = inputs?.[AI_LAYOUT_SITE_FACTS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const lines = Array.isArray(value['lines']) ? value['lines'].filter((line): line is string => typeof line === 'string' && !!line.trim()) : []\n const description = typeof value['description'] === 'string' ? value['description'] : ''\n if (!lines.length && !description.trim()) return null\n return { url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '', description, lines }\n}\n\n/** A site's own header and footer words as one text, which its frame's contact details are held to (AGL-4084). */\nexport function aiLayoutSiteFactsText(inputs: Readonly<Record<string, unknown>> | null | undefined): string {\n const facts = aiLayoutSiteFactsOf(inputs)\n return facts ? [facts.description, ...facts.lines].filter(Boolean).join('\\n') : ''\n}\n\n/**\n * What a frame brought in from the owner's own site is told (AGL-4084): its\n * footer carries the details the source's header and footer give, as they\n * give them, and nothing else; the words themselves, fenced as data.\n */\nexport function aiLayoutSiteFactsLines(facts: AiLayoutSiteFacts | null): string[] {\n if (!facts) return []\n const text = [facts.description ? `About the site, in its own words: ${facts.description}` : '', ...facts.lines].filter(Boolean).join('\\n')\n return [\n \"This site's header and footer on its owner's current website carry the words below. Put in the footer the details they give (the address, phone number, email, hours and profiles), written exactly as they are written there, and its own words about itself; invent nothing they do not give, and print no word of these instructions.\",\n fenceUntrustedText(`The header and footer of ${facts.url || \"the owner's site\"}`, text, { maxChars: AI_LAYOUT_SITE_FACTS_MAX_CHARS }),\n ]\n}\n\n/** The frame door's system blocks: the language's, and for a site brought in the rule that fenced text is data (AGL-4084). */\nexport function aiJobLayoutLanguageInstructions(job: Pick<AiJob, 'inputs'>): readonly AiSystemBlock[] {\n return aiLayoutSiteFactsOf(job.inputs)\n ? [...AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS, { text: UNTRUSTED_TEXT_RULE }]\n : AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS\n}\n\n/** The site's name as the brand: the name the job was given, else the token the site's own name fills. */\nexport function aiLayoutSiteName(job: Pick<AiJob, 'inputs'>): string {\n const given = job.inputs?.['businessName']\n return typeof given === 'string' && given.trim()\n ? given.trim()\n : AI_SITE_NAME_TOKEN\n}\n\n/** The pages a frame's navigation links: the planned pages, else the site's own, in order. */\nexport function aiLayoutNavPages(\n job: Pick<AiJob, 'inputs'> & { plan?: Pick<AiJobPlan, 'language'> | null },\n inventory: AiSiteInventory | null,\n): AiLayoutPage[] {\n // The header and the footer link the pages the job was told (AGL-3660),\n // else the site's own, the home page always and first, labelled Home. The\n // model draws neither list, so it cannot drop a page. A site in another\n // language keeps its home page's own title: a Spanish start's \"Inicio\" was\n // linked as \"Home\" (AGL-3760).\n const planned = aiLayoutSitePages(job.inputs)\n const own = (inventory?.screens ?? [])\n .filter((row) => !row.template)\n .map((row) => ({ id: row.id, label: row.name, slug: row.slug }))\n const siteHome = planned.some((page) => aiLayoutIsHomeSlug(page.slug))\n ? []\n : own.filter((page) => aiLayoutIsHomeSlug(page.slug)).slice(0, 1)\n const pages = [...siteHome, ...(planned.length ? planned : own)].filter((page) => page.label.trim())\n const home = pages.find((page) => aiLayoutIsHomeSlug(page.slug))\n return [\n ...(home ? [aiLayoutSpeaksOtherThanEnglish(job.plan?.language) ? home : { ...home, label: 'Home' }] : []),\n ...pages.filter((page) => page !== home && !aiLayoutIsHomeSlug(page.slug)),\n ].slice(0, AI_LAYOUT_SITE_PAGES_MAX)\n}\n\n/** The home page the brand links: the planned home, else the site's. */\nexport function aiLayoutHomeId(\n pages: readonly AiLayoutPage[],\n inventory: AiSiteInventory | null,\n): string | null {\n const planned = pages.find((page) => aiLayoutIsHomeSlug(page.slug))\n return planned?.id ?? aiHomeScreenIds(inventory)[0] ?? null\n}\n\n/** The frame's user turn: the site, its brief, its pages and its form. */\nexport function aiLayoutFramePrompt(input: {\n job: Pick<AiJob, 'brief' | '$id'> & Partial<Pick<AiJob, 'inputs'>>\n siteName: string\n pages: readonly AiLayoutPage[]\n targets: AiLayoutTargets\n}): string {\n const { job, pages, targets } = input\n // A site brought in (AGL-4084) is told its own words, fenced, and no brief a footer could print.\n const facts = aiLayoutSiteFactsOf(job.inputs)\n return [\n `Site: ${input.siteName === AI_SITE_NAME_TOKEN ? 'the business the brief describes' : `\"${input.siteName}\"`}`,\n ...(facts ? aiLayoutSiteFactsLines(facts) : [aiJobBriefLine(job)]),\n ...aiSiteKindDesignLines(job.inputs),\n pages.length\n ? `Its pages, which the navigation links: ${pages.map((page) => `${page.label} (page:${page.id})`).join(', ')}.`\n : 'It has no pages yet.',\n targets.forms.length || targets.formPageId\n ? 'A call to action that asks a visitor to get in touch goes to form.'\n : 'The site has no form yet.',\n // A storefront's header (AGL-3676): its cart, and an announcement line.\n ...(aiLayoutShopPageId(targets)\n ? [\n \"This is an online store: give the header no button, since the platform puts the cart beside the navigation. Give the header one note instead: a short announcement for the bar above it, under 60 characters, about the shop from the brief (a promise it makes, such as its shipping, or what is new); never invent an offer, a discount, a price or a shipping threshold the brief does not give.\",\n ]\n : []),\n `Design seed: ${job.$id.slice(-6)}.`,\n ].join('\\n')\n}\n\n/** A store's Shop page, by its id: the page its catalog's whole list is placed on (AGL-3676). */\nexport function aiLayoutShopPageId(targets: Pick<AiLayoutTargets, 'listings'>): string | null {\n const products = (targets.listings ?? []).find((listing) => listing.kind === 'products')\n return products?.placements.find((placement) => placement.role === 'index')?.screenId ?? null\n}\n\n/** A validated language layout. */\nexport interface AiLayoutFrameBuilt {\n rootId: string\n nodes: NodesMap\n load: AiLoadEstimate | null\n /** What the last answer's gaps took out of the frame (`ai-layout-gaps.ts`). */\n dropped: string[]\n}\n\n/** What a frame is built with: the site, its pages and links, its look, and the layout door's own checks. */\nexport interface AiLayoutFrameInput {\n /** The header arrangement the site's look chose (AGL-3660); the answer's otherwise. */\n headerAlign?: 'start' | 'center'\n siteName: string\n homeId: string | null\n pages: readonly AiLayoutPage[]\n targets: AiLayoutTargets\n extend: (tree: AiValidatedTree) => AiDoctrineViolation[]\n /** The site's design (`aiLayoutDesignOf`), whose pages' closing band the footer sits under. */\n design?: AiLayoutDesign | null\n /** A store's own pages, which the header and footer link by path (AGL-3676). */\n storeLinks?: AiStoreFrameLinks | null\n /** The site's language, which the frame's own words are written in (AGL-3760). */\n language?: string\n /** The header's brand as a site brought in draws it (AGL-4084). */\n brand?: AiLayoutFrameBrand | null\n /** A site brought in's own header and footer (AGL-4108), drawn in place of the design's. */\n source?: AiLayoutFrameSource | null\n}\n\n/** The check a frame answer is held to: read, compiled, stored and checked as a layout, with the layout door's own checks. */\nexport function aiLayoutFrameCheck(input: AiLayoutFrameInput): AiGenerationCheck<AiLayoutFrameBuilt> {\n let answers = 0\n return (answer) => {\n // The last answer a generation takes has its gaps taken out rather than asked about again.\n answers += 1\n return aiLayoutFrameBuild(aiReadLayoutFrame(answer), input, answers >= AI_GENERATION_MAX_ATTEMPTS)\n }\n}\n\n/**\n * A site brought in's header and footer as its source builds them\n * (AGL-4108), with no model: compiled, stored and checked as a layout, held\n * to every check an answer is. `value` is `null` with the violations where it\n * does not pass, and the frame is then designed by the model instead.\n */\nexport function aiLayoutSourceFrameBuild(input: AiLayoutFrameInput & { source: AiLayoutFrameSource }): ReturnType<AiGenerationCheck<AiLayoutFrameBuilt>> {\n const band = input.source.header === 'brand' || input.source.header === 'dark' ? input.source.header : 'plain'\n return aiLayoutFrameBuild({ header: { band, align: 'start', blocks: [] }, footer: null }, input, true)\n}\n\n/** A frame compiled, stored and checked as a layout; `last` takes its gaps out rather than asking about them. */\nfunction aiLayoutFrameBuild(frame: { header: AiLayoutSection | null; footer: AiLayoutSection | null }, input: AiLayoutFrameInput, last: boolean): ReturnType<AiGenerationCheck<AiLayoutFrameBuilt>> {\n if (input.headerAlign && frame.header && !input.source) frame.header.align = input.headerAlign\n const compiled = aiCompileLayoutFrame(\n frame,\n {\n siteName: input.siteName,\n homeId: input.homeId,\n navPages: input.pages,\n closesDark: input.design ? aiLayoutDesignChoices(input.design).coverClose : false,\n // A site that sells carries its cart in the header (AGL-3676).\n cart: (input.targets.listings ?? []).some((listing) => listing.kind === 'products' && listing.cart !== false),\n // And a store's header is a storefront's: no button repeating its navigation, an announcement bar (AGL-3676).\n shopId: aiLayoutShopPageId(input.targets),\n // And its account and policies, written after it (AGL-3676).\n storeLinks: input.storeLinks ?? null,\n ...(input.language ? { language: input.language } : {}),\n ...(input.brand ? { brand: input.brand } : {}),\n ...(input.source ? { source: input.source } : {}),\n },\n input.targets,\n )\n // The pages a source's menu and footer link by id (AGL-4108).\n const sourcePages = input.source ? aiLayoutFrameSourcePageIds(input.source) : []\n // A site's own logo is a token no address rule knows (AGL-4119), and these\n // two are ours to name: no model writes them.\n const logoTokens = [input.brand?.logo?.src, input.brand?.logoDark?.src].filter(\n (src): src is string => Boolean(src && isHostImageToken(src)),\n )\n const context = {\n screenIds: [\n ...new Set([\n ...input.targets.pages.map((page) => page.id),\n ...input.pages.map((page) => page.id),\n ...(input.homeId ? [input.homeId] : []),\n ...sourcePages,\n ]),\n ],\n formIds: input.targets.forms.map((form) => form.id),\n homeScreenIds: input.targets.homeIds,\n // A link home under the home page's own title says home, in any language (AGL-3760).\n homeLabels: [\n ...input.pages.filter((page) => aiLayoutIsHomeSlug(page.slug)),\n ...input.targets.pages.filter((page) => input.targets.homeIds.includes(page.id)),\n ].map((page) => page.label),\n // A footer's \"Get in touch\" goes to the form, wherever it is placed (AGL-3729).\n ...(input.targets.formPageId ? { formScreenIds: [input.targets.formPageId] } : {}),\n codeBuilt: true,\n ...(logoTokens.length ? { bindingTokens: logoTokens } : {}),\n // A source's header and footer are its owner's own words and menu\n // (AGL-4108), drawn by code where they repeat: no model wrote a block\n // twice that a component should carry once.\n ...(input.source ? { ownWords: true, reusableComponents: false } : {}),\n }\n const stored = aiLayoutStoredTree(compiled.tree, 'layout', context)\n if (stored.ok === false) {\n console.error('ai layout frame: a compiled layout did not store', {\n error: stored.error,\n })\n return {\n value: null,\n violations: [\n {\n rule: null,\n code: 'layout-compile',\n message: 'This layout could not be built. Try again.',\n detail: stored.error,\n },\n ],\n }\n }\n // No gap and no internal reference in the words of a frame every published page shows.\n const navPages = [...input.targets.pages, ...input.pages]\n const copy = aiLayoutCopyCheck(\n stored.nodes,\n stored.rootId,\n {\n pages: navPages,\n ids: [...navPages.map((page) => page.id), ...input.targets.forms.map((form) => form.id)],\n },\n last,\n )\n const { dropped } = copy\n // An attribute a rule has one answer for is settled, not asked of the model again (AGL-3660).\n const nodes = aiSettleUnrelatedScreenLinks(\n aiSettleMechanicalRules(\n { rootId: stored.rootId, nodes: copy.nodes as unknown as Record<string, AiDoctrineNode> },\n 'layout',\n // And on the last answer, a link that goes nowhere, as the check below reads it (AGL-4076).\n last ? context : undefined,\n ),\n 'layout',\n context,\n ).nodes as unknown as typeof copy.nodes\n // The copy check can take words out of the footer: no heading or column\n // is left with nothing under it (AGL-3735), and none may remain.\n aiLayoutRepairFrameHollows(nodes as unknown as Record<string, unknown>)\n const hollow = aiLayoutFrameHollows(nodes as unknown as Record<string, unknown>)\n const report = validateAiDoctrineTree(\n { rootId: stored.rootId, nodes },\n 'layout',\n context,\n )\n const violations = [\n ...report.violations,\n ...(aiLayoutFrameIsHollow(hollow)\n ? [\n {\n rule: null,\n code: 'layout-frame-hollow',\n message: 'Every footer heading needs something under it, and every footer column more than a heading.',\n detail: aiLayoutFrameHollowsSaid(hollow).join('; '),\n },\n ]\n : []),\n ...copy.violations,\n ...input.extend({\n rootId: stored.rootId,\n nodes,\n repairs: [],\n sourceIds: {},\n score: report.score as AiValidatedTree['score'],\n load: report.load,\n }),\n ]\n return {\n value: violations.length\n ? null\n : { rootId: stored.rootId, nodes, load: report.load, dropped },\n violations,\n }\n}\n\n/** What a frame's links resolve against: the site's pages and its form, as a page's do. */\nexport function aiLayoutFrameTargets(\n job: Pick<AiJob, 'brief' | 'inputs'>,\n inventory: AiSiteInventory | null,\n): AiLayoutTargets {\n return aiLayoutPageTargets({ job, inventory, own: [] })\n}\n"],"names":["isHostImageToken","resolveHostToken","aiLayoutDesignChoices","aiCompileLayoutFrame","aiLayoutFrameSourceOf","aiLayoutFrameSourcePageIds","aiLayoutFrameHollows","aiLayoutFrameHollowsSaid","aiLayoutFrameIsHollow","aiLayoutRepairFrameHollows","AI_LAYOUT_LANGUAGE_TEXT","aiReadLayoutFrame","aiLayoutCopyCheck","aiLayoutStoredTree","AI_GENERATION_MAX_ATTEMPTS","aiLayoutSpeaksOtherThanEnglish","aiHomeScreenIds","AI_STEP_TIERS","aiSettleMechanicalRules","aiSettleUnrelatedScreenLinks","validateAiDoctrineTree","aiSiteKindDesignLines","aiJobStepBudget","fenceUntrustedText","UNTRUSTED_TEXT_RULE","aiJobBriefLine","AI_LAYOUT_SITE_PAGES_MAX","aiLayoutIsHomeSlug","aiLayoutSitePages","AI_LAYOUT_FRAME_THINKING_TOKENS","aiLayoutPageTargets","AI_SITE_NAME_TOKEN","AI_JOB_LAYOUT_LANGUAGE_TOKENS","AI_JOB_LAYOUT_LANGUAGE_BUDGET","tier","maxTokens","AI_LAYOUT_FRAME_KIND","AI_JOB_LAYOUT_LANGUAGE_INSTRUCTIONS","text","join","cacheBreakpoint","AI_LAYOUT_SITE_BRAND_INPUT","AI_LAYOUT_SITE_FACTS_INPUT","AI_LAYOUT_SITE_FRAME_INPUT","aiLayoutSiteFrameOf","inputs","AI_LAYOUT_SITE_FACTS_MAX_CHARS","aiLayoutSiteBrandOf","raw","value","logo","src","trim","alt","replace","slice","aspect","Number","isFinite","Math","min","height","test","name","footer","aiLayoutHostBrandOf","host","logoDarkUrl","logoDark","aiLayoutFrameBrandOf","brought","aiLayoutSiteFactsOf","lines","Array","isArray","filter","line","description","length","url","aiLayoutSiteFactsText","facts","Boolean","aiLayoutSiteFactsLines","maxChars","aiJobLayoutLanguageInstructions","job","aiLayoutSiteName","given","aiLayoutNavPages","inventory","planned","own","screens","row","template","map","id","label","slug","siteHome","some","page","pages","home","find","plan","language","aiLayoutHomeId","aiLayoutFramePrompt","input","targets","siteName","forms","formPageId","aiLayoutShopPageId","$id","products","listings","listing","kind","placements","placement","role","screenId","aiLayoutFrameCheck","answers","answer","aiLayoutFrameBuild","aiLayoutSourceFrameBuild","band","source","header","align","blocks","frame","last","headerAlign","compiled","homeId","navPages","closesDark","design","coverClose","cart","shopId","storeLinks","brand","sourcePages","logoTokens","context","screenIds","Set","formIds","form","homeScreenIds","homeIds","homeLabels","includes","formScreenIds","codeBuilt","bindingTokens","ownWords","reusableComponents","stored","tree","ok","console","error","violations","rule","code","message","detail","copy","nodes","rootId","ids","dropped","undefined","hollow","report","extend","repairs","sourceIds","score","load","aiLayoutFrameTargets"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,gBAAgB,QAA8B,qCAAoC;AAE7G,SAASC,qBAAqB,QAA6B,yCAAqC;AAChG,SAASC,oBAAoB,QAAiC,wCAAoC;AAClG,SAASC,qBAAqB,EAAEC,0BAA0B,QAAkC,+CAA2C;AACvI,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,qBAAqB,EACrBC,0BAA0B,QACrB,gDAA4C;AACnD,SAEEC,uBAAuB,EACvBC,iBAAiB,QAEZ,2CAAuC;AAK9C,SAASC,i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EV,MAAM;gBACNC,MAAM;gBACNC,SAAS;gBACTC,QAAQtK,yBAAyB6K,QAAQ7I,IAAI,CAAC;YAChD;SACD,GACD,EAAE;WACHuI,KAAKL,UAAU;WACf3D,MAAMwE,MAAM,CAAC;YACdN,QAAQZ,OAAOY,MAAM;YACrBD;YACAQ,SAAS,EAAE;YACXC,WAAW,CAAC;YACZC,OAAOJ,OAAOI,KAAK;YACnBC,MAAML,OAAOK,IAAI;QACnB;KACD;IACD,OAAO;QACLzI,OAAOwH,WAAW3F,MAAM,GACpB,OACA;YAAEkG,QAAQZ,OAAOY,MAAM;YAAED;YAAOW,MAAML,OAAOK,IAAI;YAAER;QAAQ;QAC/DT;IACF;AACF;AAEA,yFAAyF,GACzF,OAAO,SAASkB,qBACdrG,GAAoC,EACpCI,SAAiC;IAEjC,OAAO5D,oBAAoB;QAAEwD;QAAKI;QAAWE,KAAK,EAAE;IAAC;AACvD"}
@@ -25,10 +25,11 @@ import type { AiLayoutTargets } from '../layout-language/ai-layout-links';
25
25
  import { type AiGenerationCheck, type AiValidatedGeneration } from '../runtime/ai-doctrine';
26
26
  import { type AiDoctrineTreeContext, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators';
27
27
  import type { AiLoadEstimate } from '../runtime/ai-palette';
28
- import type { AiLayoutDesign } from '../layout-language/ai-layout-design';
28
+ import { type AiLayoutDesign } from '../layout-language/ai-layout-design';
29
29
  import type { AiSystemBlock } from '../runtime/ai-runtime';
30
30
  import { type AiSiteImportDocument } from './ai-site-import-document';
31
- import { type AiSiteImportWords } from '../model/ai-site-import';
31
+ import { type AiSiteImportDesigned } from './ai-site-import-compile';
32
+ import { type AiSiteImportAddedSection, type AiSiteImportPagePictures, type AiSiteImportRedesign, type AiSiteImportWords } from '../model/ai-site-import';
32
33
  /**
33
34
  * A page built in the compact layout language (AGL-3660): the page step's
34
35
  * pass for a site's page units — a guided start's and a build's — in place of
@@ -273,6 +274,17 @@ export interface AiLayoutPageBuilt {
273
274
  * where none was. Absent on every other page.
274
275
  */
275
276
  words?: AiSiteImportWords;
277
+ /**
278
+ * How a generative Improve it came out (AGL-4152): redesigned from its
279
+ * answer, or its layout kept where the redesign did not pass; what it added
280
+ * and what it shows. Absent on every other page.
281
+ */
282
+ redesign?: {
283
+ status: AiSiteImportRedesign;
284
+ added: AiSiteImportAddedSection[];
285
+ pictures: AiSiteImportPagePictures | null;
286
+ names?: string[];
287
+ };
276
288
  }
277
289
  export interface AiLayoutPageCheckInput {
278
290
  screen: AiBuildPlanScreen;
@@ -419,6 +431,8 @@ export declare function aiImportedPageCheck(input: Pick<AiLayoutPageCheckInput,
419
431
  doc: AiSiteImportDocument;
420
432
  language?: string;
421
433
  rewritten?: readonly string[];
434
+ /** Sections a generative Improve it planned (AGL-4152), drawn in place of the source's layout. */
435
+ given?: AiSiteImportDesigned | null;
422
436
  }): (answer: Record<string, unknown> | null) => {
423
437
  value: AiLayoutPageBuilt | null;
424
438
  violations: AiDoctrineViolation[];
@@ -450,3 +464,8 @@ export declare function aiSiteImportWordingMaxTokens(model: string): number;
450
464
  * my wording on, and never a policy page, by its address or its title.
451
465
  */
452
466
  export declare function aiImportedPageRewords(doc: Pick<AiSiteImportDocument, 'build' | 'finish' | 'wording' | 'title' | 'url'>, screen: Pick<AiBuildPlanScreen, 'slug' | 'title'>): boolean;
467
+ /**
468
+ * The ceiling a redesign is asked at on this model (AGL-4152): what the page
469
+ * step's time holds of a whole page's design and words, and its one re-ask.
470
+ */
471
+ export declare function aiSiteImportImproveMaxTokens(model: string): number;
@@ -32,16 +32,20 @@ import { aiDoctrineNeedsInputMessage, runValidatedGeneration } from "../runtime/
32
32
  import { aiSettleMechanicalRules, aiSettleUnrelatedScreenLinks, validateAiDoctrineTree } from "../runtime/ai-doctrine-validators.js";
33
33
  import { aiSiteKindDesignLines, aiSiteKindOfInputs } from "../model/ai-site-kinds.js";
34
34
  import { aiSiteSeed } from "../model/ai-site-look.js";
35
+ import { aiLayoutPlannedChoicesOf } from "../layout-language/ai-layout-design.js";
35
36
  import { aiOriginJobId } from "./ai-job-draft-ids.js";
37
+ import { aiPageSectionNodeId } from "./ai-job-page-sections.js";
36
38
  import { aiGenerationWorstCaseOnTierMs, aiJobStepBudget } from "./ai-job-budget.js";
37
39
  import { aiJobBriefLine, aiPlanReferenceLines } from "./ai-job-generation.js";
38
40
  import { aiLayoutIsHomeSlug, aiLayoutSiteAliases, aiLayoutSitePages } from "./ai-job-layout-site-pages.js";
39
41
  import { aiLayoutInventedContactViolations } from "./ai-layout-site-facts.js";
40
42
  import { aiSiteContactOf } from "../model/ai-site-details.js";
41
43
  import { aiSiteImportDocumentOf } from "./ai-site-import-document.js";
42
- import { AI_SITE_IMPORT_DESIGN_MAX_CHARS, aiCompileImportedPage, aiSiteImportDesignText, aiSiteImportFinishOf, aiSiteImportSectionNames } from "./ai-site-import-compile.js";
43
- import { aiSiteImportPageIsLegal } from "../model/ai-site-import.js";
44
+ import { AI_SITE_IMPORT_DESIGN_MAX_CHARS, aiCompileImportedPage, aiSiteImportDesignText, aiSiteImportFinishOf, aiSiteImportLayoutOf, aiSiteImportSectionNames } from "./ai-site-import-compile.js";
45
+ import { aiSiteImportPageIsLegal, AI_SITE_IMPORT_LAYOUT_KEPT, AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN } from "../model/ai-site-import.js";
46
+ import { siteImportFidelity } from "../model/ai-site-import-fidelity.js";
44
47
  import { aiGenerationMaxTokensWithin, aiGenerationWorstCaseMs } from "./ai-job-budget.js";
48
+ import { AI_SITE_IMPORT_IMPROVE_KIND, AI_SITE_IMPORT_IMPROVE_MOST_TOKENS, AI_SITE_IMPORT_IMPROVE_TOOL, aiSiteImportImproveCheck, aiSiteImportImproveDestinations, aiSiteImportImproveDigest, aiSiteImportImproveInstructions, aiSiteImportImproveLedger, aiSiteImportImprovePrompt, aiSiteImportImproveScope, aiSiteImportImprovedMisses, aiSiteImportImproveInputUsage, aiSiteImportImproveReaskTokens, aiSiteImportImproveRoleLines, aiSiteImportImproveTokensWithin, aiSiteImportNewSectionsWanted, aiSiteImportPageRoleOf } from "./ai-site-import-improve.js";
45
49
  import { AI_SITE_IMPORT_WORDING_INSTRUCTIONS, AI_SITE_IMPORT_WORDING_KIND, AI_SITE_IMPORT_WORDING_TOOL, aiSiteImportWordingCheck, aiSiteImportWordingPage, aiSiteImportWordingPrompt, aiSiteImportWordingTokens } from "./ai-site-import-wording.js";
46
50
  /**
47
51
  * A page built in the compact layout language (AGL-3660): the page step's
@@ -462,11 +466,15 @@ export const AI_JOB_PAGE_LANGUAGE_BUDGET = aiJobStepBudget({
462
466
  if (!kind) return null;
463
467
  const style = (_job_inputs = job.inputs) == null ? void 0 : _job_inputs['siteStyle'];
464
468
  const seed = typeof (style == null ? void 0 : style['seed']) === 'number' && Number.isFinite(style['seed']) ? style['seed'] >>> 0 : aiSiteSeed(aiOriginJobId(job));
465
- return {
469
+ // What a site's plan chose for every page of it (AGL-4152).
470
+ const planned = aiLayoutPlannedChoicesOf(style == null ? void 0 : style['planned']);
471
+ return _extends({
466
472
  kind: kind.id,
467
473
  seed,
468
474
  home: aiLayoutIsHomeSlug(slug)
469
- };
475
+ }, planned ? {
476
+ planned
477
+ } : {});
470
478
  }
471
479
  /**
472
480
  * The site a page's entrance motion is drawn for (AGL-3838): its design where
@@ -935,6 +943,8 @@ export const AI_JOB_PAGE_LANGUAGE_BUDGET = aiJobStepBudget({
935
943
  ownWords: true
936
944
  }, ((_input_rewritten = input.rewritten) == null ? void 0 : _input_rewritten.length) ? {
937
945
  rewritten: input.rewritten
946
+ } : {}, input.doc.videoPosters ? {
947
+ hostStills: true
938
948
  } : {});
939
949
  const plan = {
940
950
  title: input.screen.title,
@@ -955,7 +965,9 @@ export const AI_JOB_PAGE_LANGUAGE_BUDGET = aiJobStepBudget({
955
965
  answer: design,
956
966
  // Kept as it is or improved, as the page's wave was asked (AGL-4152).
957
967
  finish: aiSiteImportFinishOf(input.doc)
958
- }, input.language ? {
968
+ }, input.given ? {
969
+ given: input.given
970
+ } : {}, input.language ? {
959
971
  language: input.language
960
972
  } : {}));
961
973
  // A film's Video element keeps its id, as a section's root does: the button that plays it names it (AGL-4140).
@@ -1127,6 +1139,14 @@ const NO_USAGE = {
1127
1139
  status: 'ok',
1128
1140
  value: plain.value
1129
1141
  });
1142
+ // Redesigned from its ledger (AGL-4152), where its wave was stamped so: one answer in place of design and wording.
1143
+ if (doc.generative && aiImportedPageRewords(doc, input.screen)) return aiRunImprovedPage({
1144
+ input,
1145
+ doc,
1146
+ checkInput,
1147
+ plain: plain.value,
1148
+ spend
1149
+ });
1130
1150
  const observe = (_input_observe = input.observe) != null ? _input_observe : (inner)=>inner;
1131
1151
  // The design answer the page was drawn with, which its reworded page is drawn with too.
1132
1152
  const drawn = {
@@ -1269,5 +1289,197 @@ const NO_USAGE = {
1269
1289
  })
1270
1290
  });
1271
1291
  }
1292
+ /**
1293
+ * The ceiling a redesign is asked at on this model (AGL-4152): what the page
1294
+ * step's time holds of a whole page's design and words, and its one re-ask.
1295
+ */ export function aiSiteImportImproveMaxTokens(model) {
1296
+ return aiGenerationMaxTokensWithin({
1297
+ model,
1298
+ budgetMs: AI_JOB_PAGE_LANGUAGE_BUDGET.minimumMs,
1299
+ cap: AI_SITE_IMPORT_IMPROVE_MOST_TOKENS,
1300
+ lookups: 0
1301
+ });
1302
+ }
1303
+ /**
1304
+ * A page redesigned from its ledger (AGL-4152): one `submit_improved_page`
1305
+ * answer on the page step's tier in place of the design and wording answers,
1306
+ * held by the honesty validator, the kept ledger and the design lines, with the
1307
+ * one re-ask naming what missed. An answer that misses again, is refused or is
1308
+ * cut off leaves the page as today's compile draws it, every word the source's,
1309
+ * and its row says the layout was kept.
1310
+ */ async function aiRunImprovedPage(scope) {
1311
+ var _doc_theme, _input_observe, _doc_siteLines, _doc_plan, _ref, _ref1, _input_context_framing, _doc_plan1;
1312
+ var _input_job_inputs, _doc_plan2, _input_targets_forms_;
1313
+ const { input, doc, checkInput, plain, spend } = scope;
1314
+ const ledger = aiSiteImportImproveLedger(doc);
1315
+ const named = (_input_job_inputs = input.job.inputs) == null ? void 0 : _input_job_inputs['businessName'];
1316
+ const siteName = typeof named === 'string' ? named : null;
1317
+ const facts = aiSiteImportImproveScope(doc, siteName);
1318
+ const theme = (_doc_theme = doc.theme) != null ? _doc_theme : null;
1319
+ const design = importedDesign(checkInput.design, input.screen);
1320
+ const source = {
1321
+ layout: aiSiteImportLayoutOf(doc),
1322
+ blocks: doc.blocks,
1323
+ photos: doc.photos
1324
+ };
1325
+ const savedForms = doc.forms ? doc.forms.filter((form)=>form.formId).length : input.targets.forms.length ? 1 : 0;
1326
+ const observe = (_input_observe = input.observe) != null ? _input_observe : (inner)=>inner;
1327
+ // What the page is for, and the new sections it has room for (AGL-4152).
1328
+ const role = aiSiteImportPageRoleOf(doc, input.screen.slug);
1329
+ const needs = {
1330
+ role,
1331
+ wanted: aiSiteImportNewSectionsWanted(role, ledger, !!doc.proposed)
1332
+ };
1333
+ const instructions = aiSiteImportImproveInstructions(aiSiteImportImproveDigest({
1334
+ siteName,
1335
+ scope: (_doc_siteLines = doc.siteLines) != null ? _doc_siteLines : [],
1336
+ plan: (_doc_plan = doc.plan) != null ? _doc_plan : null
1337
+ }));
1338
+ const prompt = aiSiteImportImprovePrompt({
1339
+ screen: input.screen,
1340
+ doc,
1341
+ ledger,
1342
+ destinations: aiSiteImportImproveDestinations(doc, ledger),
1343
+ kindLines: aiSiteKindDesignLines(input.job.inputs),
1344
+ seed: input.job.$id.slice(-6),
1345
+ roleLines: aiSiteImportImproveRoleLines(_extends({}, needs, {
1346
+ folded: ledger.folded,
1347
+ kind: (_ref = (_doc_plan2 = doc.plan) == null ? void 0 : _doc_plan2.site.kind) != null ? _ref : null,
1348
+ seed: aiSiteSeed(input.job.$id)
1349
+ }))
1350
+ });
1351
+ // The page's ceiling holds in code: the answer asks no more than it buys, and a re-ask it cannot pay for is not asked.
1352
+ const most = aiSiteImportImproveMaxTokens(input.model);
1353
+ const first = aiSiteImportImproveTokensWithin({
1354
+ model: input.model,
1355
+ spent: spend.usage,
1356
+ input: aiSiteImportImproveInputUsage({
1357
+ systemChars: instructions.reduce((sum, block)=>sum + block.text.length, 0),
1358
+ promptChars: prompt.length
1359
+ }),
1360
+ most
1361
+ });
1362
+ const answered = await runValidatedGeneration(AI_SITE_IMPORT_IMPROVE_KIND, _extends({
1363
+ step: 'job.page',
1364
+ model: input.model,
1365
+ instructions,
1366
+ messages: [
1367
+ {
1368
+ role: 'user',
1369
+ content: prompt
1370
+ }
1371
+ ],
1372
+ tool: AI_SITE_IMPORT_IMPROVE_TOOL,
1373
+ maxTokens: Math.max(1, first),
1374
+ // Nothing is spent before it: a page brought in is compiled with no model first.
1375
+ reaskTokens: (spent, last)=>aiSiteImportImproveReaskTokens({
1376
+ model: input.model,
1377
+ spent,
1378
+ lastOutput: last.outputTokens,
1379
+ most
1380
+ }),
1381
+ cutOff: {
1382
+ noun: 'page',
1383
+ smaller: 'Write shorter copy, and fewer sections.'
1384
+ }
1385
+ }, AI_LAYOUT_LANGUAGE_THINKING, {
1386
+ check: observe(aiSiteImportImproveCheck({
1387
+ doc,
1388
+ ledger,
1389
+ design,
1390
+ scope: facts,
1391
+ formId: input.targets.forms.length === 1 ? (_ref1 = (_input_targets_forms_ = input.targets.forms[0]) == null ? void 0 : _input_targets_forms_.id) != null ? _ref1 : null : null,
1392
+ framing: (_input_context_framing = input.context.framing) != null ? _input_context_framing : null,
1393
+ plan: (_doc_plan1 = doc.plan) != null ? _doc_plan1 : null,
1394
+ theme,
1395
+ needs,
1396
+ build: (page)=>aiImportedPageCheck(_extends({}, checkInput, {
1397
+ doc,
1398
+ given: page.given,
1399
+ rewritten: page.written,
1400
+ screen: _extends({}, input.screen, {
1401
+ sections: page.names.map((name)=>({
1402
+ name,
1403
+ uses: [],
1404
+ items: 0
1405
+ }))
1406
+ }),
1407
+ sectionIds: page.names.map((_, index)=>{
1408
+ var _input_sectionIds_index;
1409
+ return (_input_sectionIds_index = input.sectionIds[index]) != null ? _input_sectionIds_index : aiPageSectionNodeId(input.job.$id, index);
1410
+ })
1411
+ }))(null),
1412
+ score: (built, destinations)=>{
1413
+ const tree = {
1414
+ rootId: CANVAS_ROOT_ELEMENT_ID,
1415
+ nodes: built.nodes
1416
+ };
1417
+ const report = siteImportFidelity(source, tree, {
1418
+ finish: 'improve',
1419
+ words: 'improved',
1420
+ theme,
1421
+ improved: _extends({
1422
+ scope: facts,
1423
+ destinations,
1424
+ forms: savedForms
1425
+ }, doc.proposed ? {
1426
+ proposed: true
1427
+ } : {})
1428
+ });
1429
+ return aiSiteImportImprovedMisses(report);
1430
+ }
1431
+ }))
1432
+ }, input.signal ? {
1433
+ signal: input.signal
1434
+ } : {}));
1435
+ const spent = spentTogether(spend, answered);
1436
+ if (answered.status !== 'ok') {
1437
+ // Logged by its codes alone: an answer's words are the site's content.
1438
+ console.info('ai imported page: its redesign did not pass, its layout kept', {
1439
+ status: answered.status,
1440
+ codes: answered.status === 'needs_input' ? [
1441
+ ...new Set(answered.violations.map((violation)=>violation.code))
1442
+ ] : []
1443
+ });
1444
+ // A new page has no words of its own to fall back on: it is left out, and its row says why.
1445
+ if (doc.proposed) return _extends({}, spent, {
1446
+ status: 'needs_input',
1447
+ violations: answered.status === 'needs_input' ? answered.violations : [],
1448
+ message: AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN,
1449
+ answer: null
1450
+ });
1451
+ return _extends({}, spent, {
1452
+ status: 'ok',
1453
+ value: _extends({}, plain, {
1454
+ settled: [
1455
+ ...plain.settled,
1456
+ {
1457
+ at: 'page',
1458
+ what: AI_SITE_IMPORT_LAYOUT_KEPT
1459
+ }
1460
+ ],
1461
+ words: 'kept',
1462
+ redesign: {
1463
+ status: 'layout-kept',
1464
+ added: [],
1465
+ pictures: null
1466
+ }
1467
+ })
1468
+ });
1469
+ }
1470
+ const { built, page } = answered.value;
1471
+ return _extends({}, spent, {
1472
+ status: 'ok',
1473
+ value: _extends({}, built, {
1474
+ words: 'improved',
1475
+ redesign: {
1476
+ status: 'redesigned',
1477
+ added: page.added,
1478
+ pictures: page.pictures,
1479
+ names: page.names
1480
+ }
1481
+ })
1482
+ });
1483
+ }
1272
1484
 
1273
1485
  //# sourceMappingURL=ai-job-page-language.js.map