@aglyn/plugins-ai 1.0.0-beta.246 → 1.0.0-beta.249

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 (130) hide show
  1. package/package.json +17 -17
  2. package/src/lib/activity/ai-activity-actions.js +5 -1
  3. package/src/lib/activity/ai-activity-actions.js.map +1 -1
  4. package/src/lib/components/ai-job-links.js +14 -0
  5. package/src/lib/components/ai-job-links.js.map +1 -1
  6. package/src/lib/components/ai-site-start-card.component.d.ts +1 -1
  7. package/src/lib/components/ai-site-start-card.component.js +92 -19
  8. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  9. package/src/lib/declarations.server.js +12 -0
  10. package/src/lib/declarations.server.js.map +1 -1
  11. package/src/lib/jobs/ai-build-capabilities.js +56 -2
  12. package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
  13. package/src/lib/jobs/ai-job-build-step.d.ts +3 -8
  14. package/src/lib/jobs/ai-job-build-step.js +49 -12
  15. package/src/lib/jobs/ai-job-build-step.js.map +1 -1
  16. package/src/lib/jobs/ai-job-form-dataset.d.ts +8 -5
  17. package/src/lib/jobs/ai-job-form-dataset.js +28 -10
  18. package/src/lib/jobs/ai-job-form-dataset.js.map +1 -1
  19. package/src/lib/jobs/ai-job-form-step.d.ts +20 -4
  20. package/src/lib/jobs/ai-job-form-step.js +98 -28
  21. package/src/lib/jobs/ai-job-form-step.js.map +1 -1
  22. package/src/lib/jobs/ai-job-layout-language.d.ts +6 -2
  23. package/src/lib/jobs/ai-job-layout-language.js +16 -5
  24. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  25. package/src/lib/jobs/ai-job-layout-step.js +4 -1
  26. package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
  27. package/src/lib/jobs/ai-job-media-step.d.ts +239 -0
  28. package/src/lib/jobs/ai-job-media-step.js +610 -0
  29. package/src/lib/jobs/ai-job-media-step.js.map +1 -0
  30. package/src/lib/jobs/ai-job-page-language.d.ts +2 -0
  31. package/src/lib/jobs/ai-job-page-language.js +9 -0
  32. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  33. package/src/lib/jobs/ai-job-page-sections.js +4 -3
  34. package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
  35. package/src/lib/jobs/ai-job-page-step.js +3 -2
  36. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  37. package/src/lib/jobs/ai-job-plan-step.d.ts +10 -1
  38. package/src/lib/jobs/ai-job-plan-step.js +73 -15
  39. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  40. package/src/lib/jobs/ai-job-settings-step.d.ts +0 -4
  41. package/src/lib/jobs/ai-job-settings-step.js +2 -7
  42. package/src/lib/jobs/ai-job-settings-step.js.map +1 -1
  43. package/src/lib/jobs/ai-job-site-content.d.ts +2 -2
  44. package/src/lib/jobs/ai-job-site-content.js +5 -3
  45. package/src/lib/jobs/ai-job-site-content.js.map +1 -1
  46. package/src/lib/jobs/ai-job-site-datasets.d.ts +1 -1
  47. package/src/lib/jobs/ai-job-site-datasets.js +3 -2
  48. package/src/lib/jobs/ai-job-site-datasets.js.map +1 -1
  49. package/src/lib/jobs/ai-job-site-events.d.ts +148 -0
  50. package/src/lib/jobs/ai-job-site-events.js +313 -0
  51. package/src/lib/jobs/ai-job-site-events.js.map +1 -0
  52. package/src/lib/jobs/ai-job-site-step.d.ts +9 -3
  53. package/src/lib/jobs/ai-job-site-step.js +63 -17
  54. package/src/lib/jobs/ai-job-site-step.js.map +1 -1
  55. package/src/lib/jobs/ai-job-tracking-step.d.ts +184 -0
  56. package/src/lib/jobs/ai-job-tracking-step.js +501 -0
  57. package/src/lib/jobs/ai-job-tracking-step.js.map +1 -0
  58. package/src/lib/jobs/ai-layout-stock-photos.d.ts +41 -0
  59. package/src/lib/jobs/ai-layout-stock-photos.js +71 -3
  60. package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
  61. package/src/lib/jobs/ai-site-publish.js +2 -3
  62. package/src/lib/jobs/ai-site-publish.js.map +1 -1
  63. package/src/lib/jobs/ai-stock-photo-picker.d.ts +24 -0
  64. package/src/lib/jobs/ai-stock-photo-picker.js +108 -0
  65. package/src/lib/jobs/ai-stock-photo-picker.js.map +1 -0
  66. package/src/lib/jobs/fixtures/ai-jazz-events-build-plan-recording.d.ts +37 -0
  67. package/src/lib/jobs/fixtures/ai-jazz-events-build-plan-recording.js +47 -0
  68. package/src/lib/jobs/fixtures/ai-jazz-events-build-plan-recording.js.map +1 -0
  69. package/src/lib/jobs/fixtures/ai-stock-photo-agl3760-recordings.d.ts +21 -0
  70. package/src/lib/jobs/fixtures/ai-stock-photo-agl3760-recordings.js +128 -0
  71. package/src/lib/jobs/fixtures/ai-stock-photo-agl3760-recordings.js.map +1 -0
  72. package/src/lib/jobs/fixtures/ai-stock-photo-agl3769-recordings.d.ts +21 -0
  73. package/src/lib/jobs/fixtures/ai-stock-photo-agl3769-recordings.js +126 -0
  74. package/src/lib/jobs/fixtures/ai-stock-photo-agl3769-recordings.js.map +1 -0
  75. package/src/lib/layout-language/ai-layout-compiler.d.ts +10 -4
  76. package/src/lib/layout-language/ai-layout-compiler.js +38 -19
  77. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  78. package/src/lib/layout-language/ai-layout-frame.d.ts +7 -5
  79. package/src/lib/layout-language/ai-layout-frame.js +12 -9
  80. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  81. package/src/lib/layout-language/ai-layout-gaps.js +3 -1
  82. package/src/lib/layout-language/ai-layout-gaps.js.map +1 -1
  83. package/src/lib/layout-language/ai-layout-labels.d.ts +70 -0
  84. package/src/lib/layout-language/ai-layout-labels.js +162 -0
  85. package/src/lib/layout-language/ai-layout-labels.js.map +1 -0
  86. package/src/lib/layout-language/ai-layout-links.js +5 -2
  87. package/src/lib/layout-language/ai-layout-links.js.map +1 -1
  88. package/src/lib/layout-language/ai-layout-listings.d.ts +14 -1
  89. package/src/lib/layout-language/ai-layout-listings.js +32 -5
  90. package/src/lib/layout-language/ai-layout-listings.js.map +1 -1
  91. package/src/lib/model/ai-build-event-page.d.ts +70 -0
  92. package/src/lib/model/ai-build-event-page.js +145 -0
  93. package/src/lib/model/ai-build-event-page.js.map +1 -0
  94. package/src/lib/model/ai-build-job.d.ts +21 -0
  95. package/src/lib/model/ai-build-job.js +39 -0
  96. package/src/lib/model/ai-build-job.js.map +1 -1
  97. package/src/lib/model/ai-build-plan.d.ts +25 -14
  98. package/src/lib/model/ai-build-plan.js +33 -23
  99. package/src/lib/model/ai-build-plan.js.map +1 -1
  100. package/src/lib/model/ai-job-activity.js +3 -1
  101. package/src/lib/model/ai-job-activity.js.map +1 -1
  102. package/src/lib/model/ai-jobs.types.d.ts +10 -2
  103. package/src/lib/model/ai-jobs.types.js +3 -1
  104. package/src/lib/model/ai-jobs.types.js.map +1 -1
  105. package/src/lib/model/ai-plan-capabilities.d.ts +8 -0
  106. package/src/lib/model/ai-plan-capabilities.js.map +1 -1
  107. package/src/lib/model/ai-site-inventory.d.ts +2 -0
  108. package/src/lib/model/ai-site-inventory.js +5 -0
  109. package/src/lib/model/ai-site-inventory.js.map +1 -1
  110. package/src/lib/model/ai-site-job.d.ts +2 -2
  111. package/src/lib/model/ai-site-job.js +3 -3
  112. package/src/lib/model/ai-site-job.js.map +1 -1
  113. package/src/lib/runtime/ai-doctrine-validators.d.ts +25 -3
  114. package/src/lib/runtime/ai-doctrine-validators.js +53 -6
  115. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  116. package/src/lib/runtime/ai-doctrine.d.ts +6 -1
  117. package/src/lib/runtime/ai-doctrine.js +13 -9
  118. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  119. package/src/lib/runtime/ai-eval-live.d.ts +1 -1
  120. package/src/lib/runtime/ai-eval-live.js +1 -1
  121. package/src/lib/runtime/ai-eval-live.js.map +1 -1
  122. package/src/lib/runtime/ai-palette.d.ts +3 -1
  123. package/src/lib/runtime/ai-palette.generated.js +498 -10
  124. package/src/lib/runtime/ai-palette.generated.js.map +1 -1
  125. package/src/lib/runtime/ai-palette.js +5 -3
  126. package/src/lib/runtime/ai-palette.js.map +1 -1
  127. package/src/lib/runtime/ai-template-examples.js +8 -2
  128. package/src/lib/runtime/ai-template-examples.js.map +1 -1
  129. package/src/lib/server.js +8 -0
  130. package/src/lib/server.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-job.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 { aiSiteKind } from './ai-site-kinds'\nimport {\n AI_BUILD_PLAN_CREATION_NOUNS,\n aiPlanFormDatasetNames,\n aiPlanUndeclaredRefs,\n type AiBuildPlan,\n type AiBuildPlanCreateKind,\n} from './ai-build-plan'\nimport { AI_JOB_CREATE_KINDS } from './ai-job-creations'\nimport { AI_PAGE_CREATE_KINDS } from './ai-page-job'\nimport { FREE_AI_TASTE_CREDITS_PER_MONTH } from '../plan-entitlements'\nimport {\n AI_CREDIT_RANGE_ZERO,\n AI_MEASURED_PAID_SITE_CREDITS,\n AI_MEASURED_PASS_CREDITS,\n AI_MEASURED_STANDALONE_CREATION_CREDITS,\n AI_MEASURED_UNIT_CREDITS,\n aiCreditRangeAdd,\n aiCreditRangeOf,\n aiCreditRangeOrdered,\n aiCreditsPromptFor,\n aiMeasuredPageCredits,\n aiMeasuredStandalonePageCredits,\n type AiCreditRange,\n type AiCreditsPrompt,\n type AiMeasuredCredits,\n} from './ai-credit-estimate'\n\n/**\n * What a site scaffold is (AGL-2911): the inputs a `site` job is admitted\n * with, the plans a scaffold can build, and what one is estimated to cost\n * before it starts.\n *\n * A scaffold is the one job kind that builds a whole site rather than one\n * record: a plan of four to eight screens, the layout they render inside,\n * the contact form they place, a palette suggestion, and — where the email\n * step is loaded — a welcome email. It builds each of those through the job\n * kind that already owns it, so this module describes what a scaffold may\n * ask for and refuses the rest at confirmation, before a credit is spent,\n * naming what to make first.\n *\n * ── The estimate is the guard rail ───────────────────────────────────────\n *\n * A scaffold is tens of model calls, where every other kind is a few, so the\n * member reads what it will cost before they confirm the plan that spends\n * it. The figure is the machine's own nominal credits per step multiplied by\n * the passes the plan implies — an estimate, and said to be one wherever it\n * is shown.\n *\n * This module imports nothing at runtime, so the doors, the step, the batch\n * card and the plan proposal read one vocabulary.\n */\n\n/** How many pages a scaffold builds: enough to be a site, few enough to read. */\nexport const AI_SITE_PAGES = { min: 4, max: 8 } as const\n\n/**\n * How many pages a Free workspace's scaffold builds (AGL-3594): its home page\n * and the one page the brief most needs. A product decision, not a figure the\n * wall derives — the wall's proof (`jobs/ai-job-free-site.spec.ts`) shows a\n * plan and a build of this many pages fit the Free taste with room for one\n * retried page.\n */\nexport const AI_SITE_FREE_PAGES = { min: 1, max: 2 } as const\n\n/** The pages a scaffold builds for a workspace on the Free taste or on a paid plan. */\nexport function aiSitePagesBand(\n freeTaste: boolean | null | undefined,\n): { readonly min: number; readonly max: number } {\n return freeTaste ? AI_SITE_FREE_PAGES : AI_SITE_PAGES\n}\n\n/**\n * The job input a guided site start sets so its plan is confirmed for it\n * (AGL-3594); `jobs/ai-job-auto-confirm.ts` says where it is honored.\n */\nexport const AI_JOB_AUTO_CONFIRM_INPUT = 'autoConfirm'\n\n/** What a Free site start's page selector says under it (AGL-3594). */\nexport const AI_SITE_FREE_PAGES_NOTE = 'Paid plans can generate more pages.'\n\n/**\n * The plan's answer ceiling for a scaffold (AGL-3594), Free and paid. A plan\n * is an outline — each page's title, address, search listing and sections by\n * name — and the build steps write everything else, so a scaffold plans with\n * no thinking and at a ceiling sized to the outline of its largest band with\n * room to spare: about 300 tokens a page. The 13,491-token plan a Free site\n * spent 227 of its 300 credits on was its thinking, at the routing table's\n * 8,000 a call.\n */\nexport const AI_SITE_PLAN_MAX_TOKENS = { free: 2_000, paid: 4_000 } as const\n\n/** What each exchange of a Free site job comes to at its worst, in credits. */\nexport interface AiFreeSiteWorstCase {\n /** The site plan: its answer and its one re-ask, each at its ceiling. */\n plan: number\n /** The site's look (AGL-3660): its one answer at its ceiling, on the fast tier. */\n look: number\n /**\n * The layout a site with none has built first (AGL-3660): its header and\n * footer as ONE answer in the layout language, writing its cached prefix,\n * at the most a live frame answer wrote, and never under what the live\n * guided start's layout step metered.\n */\n layout: number\n /** The saved form a guided start makes (AGL-3596), at what the live guided start's form step metered. */\n form: number\n /**\n * A language page's answer before its sections (AGL-3660): its cached\n * prefix written, its turn, and the whole room its ceiling keeps for\n * thinking. A page is ONE answer, not a pass a section.\n */\n page: number\n /** Each planned section's words in that answer, at the most a section is written in. */\n section: number\n /**\n * Room for one page asked again: the answer once more, reading its cached\n * prefix, with its thinking room and a full page of sections.\n */\n retry: number\n /** A page's listing. */\n listing: number\n}\n\n/**\n * The Free site start's wall at its worst (AGL-3594, re-derived for the\n * layout language in AGL-3660): the plan and the look as\n * `jobs/ai-job-free-site.spec.ts` derives them from their requests at their\n * ceilings; the layout, form and pages from the language requests as they\n * stand, priced as each field says. The spec fails when a figure it derives\n * moves and this does not.\n */\nexport const AI_FREE_SITE_WORST_CASE_CREDITS: Readonly<AiFreeSiteWorstCase> = {\n plan: 35,\n look: 7,\n layout: 23,\n form: 29,\n page: 43,\n section: 4,\n retry: 64,\n listing: 3,\n}\n\n/**\n * The most sections a Free site plans across its pages (AGL-3660), whatever\n * the wall leaves: a full home of five and a page of two or three. A product\n * figure, so the spend a site EXPECTS stays near what it measured; the wall\n * proves it fits.\n */\nexport const AI_FREE_SITE_MAX_SECTIONS = 8\n\n/** What a Free site start builds before its sections: the layouts it builds first, its forms and its pages. */\nexport interface AiFreeSiteCreations {\n layouts: number\n pages: number\n /** The saved forms it makes; a guided start makes one where it places a form. */\n forms: number\n}\n\n/** A Free site start's credits at its worst for this many sections, its room for one retried page included. */\nexport function aiFreeSiteWorstCaseCredits(\n creations: AiFreeSiteCreations,\n sections: number,\n credits: Readonly<AiFreeSiteWorstCase> = AI_FREE_SITE_WORST_CASE_CREDITS,\n): number {\n const pages = Math.max(1, Math.floor(creations.pages))\n return (\n credits.plan +\n credits.look +\n creations.layouts * credits.layout +\n creations.forms * credits.form +\n pages * (credits.page + credits.listing) +\n sections * credits.section +\n credits.retry\n )\n}\n\n/**\n * The most sections a Free site's plan fits in the Free taste at its worst,\n * across all its pages (AGL-3660): the plan, the look, the layout and form it\n * builds first, each page's answer and listing, ROOM FOR ONE RETRIED PAGE,\n * and as many sections as the rest pays for — at most\n * `AI_FREE_SITE_MAX_SECTIONS`, and at most what the pages hold. None when the\n * rest is already past the wall.\n */\nexport function aiFreeSiteSectionsWithin(\n creations: AiFreeSiteCreations,\n taste: number,\n credits: Readonly<AiFreeSiteWorstCase> = AI_FREE_SITE_WORST_CASE_CREDITS,\n): number {\n const pages = Math.max(1, Math.floor(creations.pages))\n const before = aiFreeSiteWorstCaseCredits(creations, 0, credits)\n if (before > taste) return 0\n const paid = credits.section > 0 ? Math.floor((taste - before) / credits.section) : Number.POSITIVE_INFINITY\n return Math.min(AI_FREE_SITE_MAX_SECTIONS, pages * AI_SITE_MAX_SECTIONS, paid)\n}\n\n/**\n * What a Free site start of this many pages can cost at its worst, in\n * credits (AGL-3660): `aiFreeSiteWorstCaseCredits` for an empty site — the\n * plan, its look, the layout and form a guided start builds, each page's\n * answer and listing, the sections its plan is held to\n * (`aiFreeSiteSectionsWithin` at the month's whole taste, which is what the\n * plan step allows) and the room for one retried page.\n *\n * The CEILING a start is quoted with (\"up to 282\"), no longer the figure it\n * is admitted on (AGL-3722): that is the measured p90\n * (`aiFreeSiteCreditRange`), and a start past what is left is asked to be\n * confirmed and pauses with Resume when its credits run out, instead of\n * being held back from starting at all.\n */\nexport function aiFreeSiteCreditEstimate(\n pages: number,\n credits: Readonly<AiFreeSiteWorstCase> = AI_FREE_SITE_WORST_CASE_CREDITS,\n): number {\n const creations: AiFreeSiteCreations = { layouts: 1, forms: 1, pages: Math.max(1, Math.floor(pages)) }\n const sections = aiFreeSiteSectionsWithin(creations, FREE_AI_TASTE_CREDITS_PER_MONTH, credits)\n return aiFreeSiteWorstCaseCredits(creations, sections, credits)\n}\n\n/**\n * What a Free workspace has left of its Free AI credits this month: the less\n * of its own band's balance and its owner's, since the owner's allowance is\n * shared by every Free workspace they hold (AGL-2925) and the reservation\n * refuses at whichever wall is reached first. `resetsOn` is the UTC day the\n * month — and with it both balances — rolls over, `YYYY-MM-DD`.\n */\nexport interface AiFreeCreditsLeft {\n left: number\n total: number\n resetsOn: string\n /**\n * Both meters `left` is the lesser of, in credits net of give-backs, for the\n * usage strip's live read (AGL-3722): the owner's Free allowance across\n * their Free workspaces (`account`, `null` with no owner) and this\n * workspace's band.\n */\n used?: {\n account: number | null\n org: number\n orgBand: number | null\n /** The strip's warn state for these figures, worked out where the strip's own rule is not shipped to the browser. */\n state: 'ok' | 'warn' | 'capped'\n }\n}\n\n/** The first UTC day of the month after `now`, `YYYY-MM-DD`: when the Free credits come back. */\nexport function aiFreeCreditsResetOn(now: Date): string {\n const next = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1))\n return next.toISOString().slice(0, 10)\n}\n\n/** A reset day as a person reads it: \"November 1\". */\nexport function aiFreeCreditsResetLabel(resetsOn: string): string {\n const at = new Date(`${resetsOn}T00:00:00.000Z`)\n return Number.isFinite(at.getTime())\n ? at.toLocaleDateString('en-US', { month: 'long', day: 'numeric', timeZone: 'UTC' })\n : 'the first of next month'\n}\n\n/**\n * What a Free site start of this many pages is likely to cost, its p90 and\n * its ceiling (AGL-3722), before a plan names its sections: the plan, the\n * look, the layout and form a guided start builds, and each page at the\n * nominal section count, at what each MEASURED in production\n * (`AI_MEASURED_UNIT_CREDITS`); the ceiling is the whole worst case the wall\n * is proven with (`aiFreeSiteCreditEstimate`). Two pages: about 137\n * (p90 213, up to 282).\n */\nexport function aiFreeSiteCreditRange(pages: number): AiCreditRange {\n const count = Math.max(1, Math.floor(pages))\n return aiCreditRangeOrdered({\n ...aiSiteStartMeasured(count),\n ceiling: aiFreeSiteCreditEstimate(count),\n })\n}\n\n/** A site start's measured likely and p90 before its plan: plan, look, layout, form and its pages at the nominal sections. */\nfunction aiSiteStartMeasured(pages: number): Pick<AiCreditRange, 'likely' | 'p90'> {\n const { plan, theme, layout, form } = AI_MEASURED_UNIT_CREDITS\n const page = aiMeasuredPageCredits(AI_SITE_NOMINAL_SECTIONS)\n return {\n likely: plan.median + theme.median + layout.median + form.median + pages * page.median,\n p90: plan.p90 + theme.p90 + layout.p90 + form.p90 + pages * page.p90,\n }\n}\n\n/** The smaller first build a site start offers: its home page alone. */\nexport const AI_SITE_HOME_FIRST_LABEL = 'Build the home page first'\n\n/**\n * What a Free site start says before it starts when what is left does not\n * cover its p90 (AGL-3722), or `null` when it fits — or when nothing is known\n * about what is left, since the reservation still decides each pass. Not a\n * refusal: the person may build what fits (the job pauses with Resume when\n * the credits run out), build the home page first, or upgrade.\n */\nexport function aiFreeSitePrompt(\n credits: Pick<AiFreeCreditsLeft, 'left' | 'resetsOn'> | null | undefined,\n pages: number,\n): AiCreditsPrompt | null {\n if (!credits || !Number.isFinite(credits.left)) return null\n const count = Math.max(1, Math.floor(pages))\n const home = aiFreeSiteCreditRange(1)\n return aiCreditsPromptFor(\n aiFreeSiteCreditRange(count),\n credits,\n count > 1 ? { label: AI_SITE_HOME_FIRST_LABEL, ...home } : null,\n )\n}\n\n/**\n * Why a Free start is refused outright (AGL-3722): nothing at all is left,\n * so there is nothing for \"build what fits\" to build.\n */\nexport function aiFreeCreditsNoneLeftText(resetsOn: string): string {\n return (\n `You have no free AI credits left this month. They are shared by all your Free workspaces and ` +\n `renew on ${aiFreeCreditsResetLabel(resetsOn)}. Upgrade this workspace to build with AI now.`\n )\n}\n\n/**\n * The most sections one scaffolded page may hold. The plan model allows more\n * for a page job, which builds one page; a scaffold builds eight, and each\n * section is a pass of its own.\n */\nexport const AI_SITE_MAX_SECTIONS = 8\n\n/**\n * The fewest sections a site start's home page is planned with (AGL-3660).\n * A new site is a full website (Zach, 2026-10-04): its home reads as one — a\n * hero, then bands such as the offer, why us, social proof, and a closing\n * call to action. A plan is an outline and nothing asked for more than a\n * ceiling, so a live Free yoga start (2026-10-07) planned its home with two\n * sections. The plan step names this count in the plan's turn and re-asks a\n * first answer whose home is under it (`aiSiteThinHomeViolations`).\n */\nexport const AI_SITE_HOME_MIN_SECTIONS = 5\n\n/**\n * The blog a paid guided start writes its first posts into (AGL-3676), and\n * the addresses it may answer at, in order of preference: the first one no\n * planned page takes.\n */\nexport const AI_SITE_BLOG_NAME = 'Blog'\nexport const AI_SITE_BLOG_SLUGS = ['blog', 'posts', 'journal', 'articles', 'writing', 'stories'] as const\n\n/** A planned page's first path segment, lower-cased: `/journal/2026` → `journal`. */\nconst firstSegment = (slug: string) => slug.trim().replace(/^\\/+/, '').split('/')[0].toLowerCase()\n\n/** The address the blog answers at, beside these planned pages: the first of `AI_SITE_BLOG_SLUGS` none of them takes. */\nexport function aiSiteBlogSlug(screens: ReadonlyArray<{ slug: string }>): string {\n const taken = new Set(screens.map((screen) => firstSegment(screen.slug)).filter(Boolean))\n return AI_SITE_BLOG_SLUGS.find((slug) => !taken.has(slug)) ?? AI_SITE_BLOG_SLUGS[0]\n}\n\n/** The header's link to the blog (AGL-3660): a path, not a page, since the blog is the posts collection. */\nexport const AI_SITE_BLOG_NAV_ID = 'aiSiteBlog'\n\n/** The nav entry a site whose start writes posts links its blog by. */\nexport function aiSiteBlogNavPage(screens: ReadonlyArray<{ slug: string }>): {\n id: string\n label: string\n slug: string\n href: string\n} {\n const slug = aiSiteBlogSlug(screens)\n return { id: AI_SITE_BLOG_NAV_ID, label: AI_SITE_BLOG_NAME, slug: `/${slug}`, href: `/${slug}` }\n}\n\n/**\n * Whether a planned page stands in for the blog a start writes (AGL-3660):\n * its address is one of the blog's, or its name says it lists posts. The\n * home page never does.\n */\nexport function aiSiteIsBlogStandIn(screen: { slug: string; title: string }): boolean {\n if (aiSitePlanIsHome(screen)) return false\n return (AI_SITE_BLOG_SLUGS as readonly string[]).includes(firstSegment(screen.slug)) || BLOG_PAGE_WORDS.test(screen.title)\n}\n\n/**\n * A start that writes posts, with its plan's stand-in pages taken out\n * (AGL-3676): the plan step asks once for a plan without one and keeps a\n * second answer that still has one, so the scaffold merges it into the blog\n * instead — the page is not built, its links go to the blog, and the blog\n * takes the address it left free. The kept screens hold their plan index,\n * which a page unit's slot is named by.\n */\nexport function aiSitePlanWithoutBlogStandIns<T extends { slug: string; title: string }>(\n screens: readonly T[],\n): { screens: T[]; standIns: T[] } {\n return {\n screens: screens.filter((screen) => !aiSiteIsBlogStandIn(screen)),\n standIns: screens.filter((screen) => aiSiteIsBlogStandIn(screen)),\n }\n}\n\n/** The code a planned page that stands in for the written blog is re-asked under. */\nexport const AI_SITE_BLOG_PAGE_CODE = 'plan-blog-page-duplicate'\n\n/** A page's name that says it lists the posts. */\nconst BLOG_PAGE_WORDS = /\\b(blog|posts?|articles?|journal|writing|stories|news)\\b/i\n\n/**\n * A site plan's pages that stand in for the blog its start writes (AGL-3660):\n * the live Slow Roads start (2026-10-08) planned an \"Articles\" page of\n * featured cards beside the posts it wrote at /blog, and the header linked\n * Articles and never the blog. A page whose address is one of the blog's, or\n * whose name says it lists posts, duplicates it; the home page never does.\n */\nexport function aiSiteBlogStandInViolations(\n plan: Pick<AiBuildPlan, 'screens'>,\n): Array<{ rule: null; code: string; message: string; paths: string[] }> {\n const standIns = plan.screens.flatMap((screen, index) => (aiSiteIsBlogStandIn(screen) ? [{ screen, index }] : []))\n if (!standIns.length) return []\n const names = standIns.map(({ screen }) => `\"${screen.title}\" at ${screen.slug}`).join(', ')\n return [\n {\n rule: null,\n code: AI_SITE_BLOG_PAGE_CODE,\n message: `${names} ${standIns.length === 1 ? 'stands' : 'stand'} in for the blog this site already gets: its first posts are written at /blog, and the header links it. Take ${standIns.length === 1 ? 'that page' : 'those pages'} out, and plan another page the brief needs, or feature the posts in a section of the home page.`,\n paths: standIns.map(({ index }) => `screens[${index}]`),\n },\n ]\n}\n\n/** The code a site plan's work section planned without its pieces is re-asked under. */\nexport const AI_SITE_EMPTY_GALLERY_CODE = 'plan-empty-gallery'\n\n/** The pieces a section that shows the work is planned with (AGL-3660). */\nexport const AI_SITE_GALLERY_MIN_ITEMS = 3\nexport const AI_SITE_GALLERY_MAX_ITEMS = 6\n\n/**\n * A planned section that shows the work: a gallery, a portfolio, a\n * collection, selected or featured work. \"Galleries\" — an audience, as in\n * \"Why galleries choose us\" — and \"how we work\" are not.\n */\nconst GALLERY_SECTION =\n /\\b(gallery|portfolio|collections?|lookbook|showcase|works|projects|(?:selected|featured|recent|our|past) (?:work|pieces|projects))\\b/i\n\n/** A section that only opens, introduces or closes a page, whatever page it is on: \"Portfolio Hero\". */\nconst FRAMING_SECTION = /\\b(hero|intro(?:duction)?|banner|header|cta|call to action|contact|inquiry|enquiry|about)\\b/i\n\n/** Whether a planned section's name says it shows the work. */\nexport function aiSiteSectionShowsWork(name: string): boolean {\n return GALLERY_SECTION.test(name) && !FRAMING_SECTION.test(name)\n}\n\n/** The sentence a site plan's turn states about a section that shows the work. */\nexport const AI_SITE_GALLERY_SENTENCE = `A section that shows the work — a gallery, portfolio, collection or selected works — counts its pieces in its items: ${AI_SITE_GALLERY_MIN_ITEMS} to ${AI_SITE_GALLERY_MAX_ITEMS}.`\n\n/**\n * A site plan's sections that show the work with fewer than three pieces\n * (AGL-3660). The live Juniper Clay start (2026-10-08) planned its Portfolio\n * page's \"Works Gallery\" with no items, and the page's works lost their place\n * to an inquiry form: a page about the work showed none.\n */\nexport function aiSiteEmptyGalleryViolations(\n plan: Pick<AiBuildPlan, 'screens'>,\n): Array<{ rule: null; code: string; message: string; paths: string[] }> {\n const thin = plan.screens.flatMap((screen, screenIndex) =>\n screen.sections.flatMap((section, sectionIndex) =>\n aiSiteSectionShowsWork(section.name) && section.items < AI_SITE_GALLERY_MIN_ITEMS\n ? [{ name: `\"${section.name}\" on ${screen.title}`, path: `screens[${screenIndex}].sections[${sectionIndex}].items` }]\n : [],\n ),\n )\n if (!thin.length) return []\n const names = thin.map((entry) => entry.name).join(', ')\n return [\n {\n rule: null,\n code: AI_SITE_EMPTY_GALLERY_CODE,\n message: `${names} ${thin.length === 1 ? 'shows' : 'show'} the work with fewer than ${AI_SITE_GALLERY_MIN_ITEMS} pieces. Plan ${thin.length === 1 ? 'it' : 'each'} with ${AI_SITE_GALLERY_MIN_ITEMS} to ${AI_SITE_GALLERY_MAX_ITEMS} items, one for each piece it shows.`,\n paths: thin.map((entry) => entry.path),\n },\n ]\n}\n\n/** The violation a site plan whose home page is under its fewest sections is re-asked under. */\nexport const AI_SITE_THIN_HOME_CODE = 'plan-thin-home'\n\n/** What a site plan's home is composed of, in the words the plan's turn and its re-ask both use. */\nexport const AI_SITE_HOME_BANDS =\n 'a hero first, then bands such as services or the offer, about or why us, and testimonials or other social proof, and a closing call to action or contact band last'\n\n/**\n * The fewest sections this site start's home is held to (AGL-3660): five, or\n * 0 — no minimum — where the Free wall cannot pay for a full home beside the\n * other pages. `across` is the sections the Free taste fits across `pages`\n * pages, each other page keeping at least one; `null` is a paid start, which\n * no wall shares out.\n *\n * ⛔ NEVER a lowered minimum. A Free guided start creates its site empty and\n * plans its layout, and the wall then fits 4 sections across two pages. Told\n * \"a home of at least 3\" beside that, the live yoga start of 2026-10-08\n * planned 4 + 3 and then 4 + 2, was refused for the wall twice, and stopped:\n * a home asked for in bands the wall cannot pay for is a start that fails.\n */\nexport function aiSiteHomeMinSections(input: { pages: number; across: number | null }): number {\n if (input.across === null) return AI_SITE_HOME_MIN_SECTIONS\n const others = Math.max(0, Math.floor(input.pages) - 1)\n return input.across - others >= AI_SITE_HOME_MIN_SECTIONS ? AI_SITE_HOME_MIN_SECTIONS : 0\n}\n\n/**\n * What a site start's plan is told to BUILD with (AGL-3660): the sections are\n * a budget to use, never a ceiling to stay under. Told only \"at most 8\", the\n * live prod start of 2026-10-08 planned a home of two sections, and Zach: \"that\n * didn't mean do as little as possible.\" On the Free taste the sentence shares\n * the wall's sections out — a home of five or six, the other page two or\n * three, about seven or eight in all; a paid start's home is asked to be rich.\n * `min` is the home's fewest (`aiSiteHomeMinSections`), 0 where the plan\n * plans no home or the wall cannot pay for a full one.\n */\nexport function aiSiteFullPlanSentence(input: { pages: number; across: number | null; min: number }): string {\n const { across, min } = input\n if (across === null) {\n return min > 0\n ? `Plan a full website, never a minimal one: a rich home page of ${min + 1} or more sections where the brief gives them, and every page with the sections it needs.`\n : 'Plan a full website, never a minimal one: every page with the sections it needs.'\n }\n const lead = `The ${across} sections are the budget to use, not a ceiling to stay under: plan a full website, never a minimal one`\n const others = Math.max(0, Math.floor(input.pages) - 1)\n if (min <= 0 || across < min) return `${lead}.`\n const homeHi = Math.max(min, Math.min(min + 1, across - others))\n if (!others) return `${lead}: the home page at / with ${min} to ${homeHi} sections.`\n const otherHi = Math.max(1, Math.min(3, Math.floor((across - min) / others)))\n const otherLo = Math.max(1, Math.min(2, otherHi, Math.floor((across - homeHi) / others)))\n const totalLo = Math.max(min + others, across - 1)\n const range = (lo: number, hi: number) => (lo === hi ? `${lo}` : `${lo} to ${hi}`)\n const pagesWord = others === 1 ? 'the other page' : 'each other page'\n return `${lead}: the home page at / with ${range(min, homeHi)} sections, ${pagesWord} ${range(otherLo, otherHi)}, about ${range(totalLo, across)} in total.`\n}\n\n/** Whether a planned page is the site's home: the one at `/`. */\nexport function aiSitePlanIsHome(screen: { slug: string }): boolean {\n const slug = screen.slug.trim()\n return slug === '/' || slug === ''\n}\n\n/**\n * A site plan's home page under its fewest sections (AGL-3660), as the plan\n * step's re-ask names it. A plan with no page at `/` — the owner's own home\n * stays — has no home to hold. `across` is the Free wall's section count, so\n * the re-ask says where the sections come from rather than tripping the wall.\n */\nexport function aiSiteThinHomeViolations(\n plan: Pick<AiBuildPlan, 'screens'>,\n options: { min: number; across: number | null },\n): Array<{ rule: null; code: string; message: string; paths: string[] }> {\n const index = plan.screens.findIndex(aiSitePlanIsHome)\n if (index < 0) return []\n const count = plan.screens[index].sections.length\n if (count >= options.min) return []\n const within =\n options.across === null\n ? ''\n : ` Keep the whole plan within ${options.across} sections: take them from the other page where you must.`\n return [\n {\n rule: null,\n code: AI_SITE_THIN_HOME_CODE,\n message: `The home page has ${count} ${count === 1 ? 'section' : 'sections'}, and a new site's home page reads as a full website with at least ${options.min}: ${AI_SITE_HOME_BANDS}.${within}`,\n paths: [`screens[${index}].sections`],\n },\n ]\n}\n\n/**\n * Sections a page is assumed to hold before a plan names them, for the\n * estimate a member reads when they ask for a scaffold. A declared\n * assumption, not a measurement: the plan's own section counts replace it\n * the moment the plan exists.\n */\nexport const AI_SITE_NOMINAL_SECTIONS = 5\n\n/**\n * The credits one pass is held against: the machine's\n * `AI_JOB_STEP_RESERVE_CREDITS`, declared here so the estimate stays a pure\n * number the console computes without the Admin SDK. `ai-site-job.spec.ts`\n * holds the two equal.\n */\nexport const AI_SITE_PASS_CREDITS = 50\n\n/** The longest a scaffold's scalar inputs may run; they are names, not copy. */\nexport const AI_SITE_INPUT_MAX_CHARS = 120\n\n/** The sites one agency batch may generate for in one request. */\nexport const AI_SITE_BATCH_MAX = 25\n\n/**\n * The sites a plan must hold before the org Sites page offers the batch at\n * all: the Agency and Advanced bands, which the plan's `hostLimit` is what\n * distinguishes.\n */\nexport const AI_SITE_BATCH_MIN_HOST_LIMIT = 25\n\nexport interface AiSiteJobInputs {\n /** What the business is, in a few words: the brief's subject. */\n businessType: string\n /**\n * Who the site is for, in a few words (AGL-2918); empty when nobody said.\n * The plan step puts it in front of the model on a line of its own, as it\n * does every other scalar here, so it narrows the pages a plan proposes\n * without a prompt of its own.\n */\n audience: string\n /**\n * The starter site whose shape the person liked (AGL-2918), by its\n * `STARTER_TEMPLATES` id; empty when they picked none.\n *\n * A hint carried as the id rather than the starter, because an id is what\n * the guided start's list, this door and the plan's line all agree on\n * without any of them loading a catalog of node maps. Unrecognized ids are\n * admitted for the same reason an unrecognized business type is: it is a\n * few words in a brief, not a lookup.\n */\n starter: string\n /**\n * The kind of site the person picked (AGL-3660), by its `AI_SITE_KINDS`\n * id; empty when nobody picked one, and the business type suggests it.\n * It sets the look the site is designed in and how its pages are arranged.\n */\n siteKind: string\n /** How many pages the member asked for. */\n pages: number\n /** The per-site variables an agency batch varies; empty when none was given. */\n businessName: string\n city: string\n brand: string\n /** Whether the scaffold also drafts a welcome email. */\n welcomeEmail: boolean\n /**\n * Where the contact form's submissions go (AGL-2918); `null` where nobody\n * said, which is every job created before the question existed and every\n * door that does not ask it.\n *\n * The one setting a new site owner actually needs made, and the one thing\n * about a contact form a model cannot know: whether a submission is a note\n * to read or a lead to chase is a decision about how the business runs. So\n * an answer BINDS the form step rather than hinting to it, and `null`\n * leaves the model's own proposal standing, exactly as it stood before.\n */\n submissions: AiSiteSubmissions | null\n /** The batch this job was created under (AGL-2911); `null` for a single site. */\n batchId: string | null\n}\n\n/**\n * Where a site's contact form sends what a visitor writes.\n *\n * Two, not three. The form step's own vocabulary has a third — a mailing\n * list — which it can only answer with a note, because the stored routing has\n * no place for a list; offering it as a question would be asking somebody to\n * pick an outcome the platform then explains it cannot store.\n */\nexport const AI_SITE_SUBMISSIONS = ['inbox', 'lead'] as const\n\nexport type AiSiteSubmissions = (typeof AI_SITE_SUBMISSIONS)[number]\n\n/**\n * What each answer to \"where do submissions go\" is called, and what it means.\n *\n * Here rather than beside the guided start's own questions, because it is not\n * only the guided start that asks: the agency batch asks the same thing of a\n * whole run (AGL-2918), and two surfaces wording one decision two ways is two\n * decisions. `ai-site-job.spec.ts` holds the list to {@link AI_SITE_SUBMISSIONS}.\n */\nexport const AI_SITE_SUBMISSION_CHOICES: ReadonlyArray<{\n id: AiSiteSubmissions\n label: string\n blurb: string\n}> = [\n {\n id: 'inbox',\n label: 'The Inbox',\n blurb: 'Every message is one to read and reply to.',\n },\n {\n id: 'lead',\n label: 'The Inbox, and CRM as a lead',\n blurb: 'Every message with an email address is also somebody to follow up.',\n },\n]\n\n/**\n * Which kind of email a scaffold's email unit is (AGL-2918), carried on the\n * derived job as `inputs.emailType`. The email step names the kind on the one\n * line it puts above the brief, and a scaffold was naming none.\n *\n * A key of the email step's own `AI_EMAIL_TYPES`, held here because neither\n * step may import the other: a scaffold delegates by job kind, and a\n * deployment that scaffolds is not necessarily one that has loaded the email\n * step. `ai-job-email-step.spec.ts` holds this key to that catalog.\n *\n * `reply` and not `welcome`. The five kinds a member picks are campaigns\n * somebody sends to an audience, and this is an answer to one person who\n * wrote in through the site; the nearest, `welcome`, is a label about signing\n * up, and a kind that misdescribes the email is worse than an absent one\n * because it is the first thing the model is told.\n */\nexport const AI_SITE_EMAIL_TYPE = 'reply'\n\n/**\n * What a site job's plan and every unit it builds are told about the\n * business's name (AGL-3596): that it is the name, used as written. Said on\n * the job's own turn, never in a cached system block, because it is one\n * site's. A model handed only what the business does named it itself —\n * \"Hillside Dog Grooming\" was built as \"Austin Paws Grooming\".\n */\nexport function aiSiteNameSentence(name: string): string {\n return `The business is named “${name}”: the site names it exactly that way, in the header, the footer, the copy and the search listing, and never by any other name.`\n}\n\n/** Where a job's inputs say submissions go, or `null` where they do not say. */\nexport function aiSiteSubmissions(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): AiSiteSubmissions | null {\n const value = inputs?.['submissions']\n return (AI_SITE_SUBMISSIONS as readonly unknown[]).includes(value)\n ? (value as AiSiteSubmissions)\n : null\n}\n\nconst ID_CHARS = /^[A-Za-z0-9_-]{1,64}$/\n\n/** A scaffold's inputs, or the sentence the door refuses them with. */\nexport function parseAiSiteJobInputs(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): AiSiteJobInputs | string {\n const text = (key: string): string | null => {\n const value = inputs?.[key]\n if (value === undefined || value === null || value === '') return ''\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length > AI_SITE_INPUT_MAX_CHARS ? null : trimmed\n }\n const businessType = text('businessType')\n if (businessType === null) {\n return `businessType must be text under ${AI_SITE_INPUT_MAX_CHARS} characters`\n }\n if (!businessType) return 'Say what kind of business the site is for'\n const businessName = text('businessName')\n const city = text('city')\n const brand = text('brand')\n const audience = text('audience')\n const starter = text('starter')\n // A kind this deployment does not know is nobody having picked one.\n const siteKind = aiSiteKind(inputs?.['siteKind'])?.id ?? ''\n for (const [key, value] of [\n ['businessName', businessName],\n ['city', city],\n ['brand', brand],\n ['audience', audience],\n ['starter', starter],\n ] as const) {\n if (value === null)\n return `${key} must be text under ${AI_SITE_INPUT_MAX_CHARS} characters`\n }\n const rawPages = inputs?.['pages']\n const pages =\n typeof rawPages === 'number' ? rawPages : Number(rawPages ?? NaN)\n // Read here across both bands; the door holds a workspace to its own\n // (`aiSitePagesRefusal`), since only it knows the workspace's plan.\n if (\n !Number.isInteger(pages) ||\n pages < AI_SITE_FREE_PAGES.min ||\n pages > AI_SITE_PAGES.max\n ) {\n return `pages must be a whole number from ${AI_SITE_FREE_PAGES.min} to ${AI_SITE_PAGES.max}`\n }\n // Where submissions go is admitted only as one of the two the form step\n // can actually bind; anything else is nobody having said, and the model\n // proposes as it always did rather than the door refusing the whole job.\n const submissions = aiSiteSubmissions(inputs)\n const rawBatch = inputs?.['batchId']\n const batchId =\n rawBatch === undefined || rawBatch === null || rawBatch === ''\n ? null\n : typeof rawBatch === 'string' && ID_CHARS.test(rawBatch)\n ? rawBatch\n : undefined\n if (batchId === undefined) return 'batchId is not a batch id'\n return {\n businessType,\n audience: audience as string,\n starter: starter as string,\n siteKind,\n pages,\n businessName: businessName as string,\n city: city as string,\n brand: brand as string,\n welcomeEmail: inputs?.['welcomeEmail'] !== false,\n submissions,\n batchId,\n }\n}\n\n/**\n * Why a workspace cannot ask for this many pages (AGL-3594), in a sentence a\n * member reads; `null` when it can. A Free workspace builds one or two, and a\n * paid one four to eight, as it always has. Refused rather than clamped: the\n * guided start offers only the band, so a request outside it was not made\n * there, and a job quietly building fewer pages than it was asked for is a\n * worse answer than a sentence saying why.\n */\nexport function aiSitePagesRefusal(pages: number, freeTaste: boolean | null | undefined): string | null {\n const band = aiSitePagesBand(freeTaste)\n if (pages >= band.min && pages <= band.max) return null\n return freeTaste\n ? `A Free workspace's AI site start builds ${AI_SITE_FREE_PAGES.min} or ${AI_SITE_FREE_PAGES.max} pages. ${AI_SITE_FREE_PAGES_NOTE}`\n : `A site is planned with ${band.min} to ${band.max} pages.`\n}\n\n/**\n * What the site itself is, as a step that is NOT the scaffold reads it off a\n * job's inputs (AGL-2918).\n *\n * A scaffold delegates unit by unit under a job derived from its own — a page\n * job, a form job — and the derived job carries the scaffold's inputs. So the\n * two answers that describe the site rather than one record of it are\n * readable by every delegated step, and a step that wants them does not have\n * to know it was delegated to.\n *\n * Lenient where {@link parseAiSiteJobInputs} is strict, because it reads the\n * inputs of jobs that are not scaffolds: a page job started from the Screens\n * page has no `businessType` and no `pages`, and that is not an error here —\n * it is a site nobody described, and the answer is two empty strings.\n */\nexport interface AiSiteWords {\n /** What kind of site it is; empty when the job's inputs do not say. */\n about: string\n /** Who it is for; empty when the job's inputs do not say. */\n audience: string\n}\n\n/** Whether either half of {@link AiSiteWords} says anything. */\nexport function aiSiteWordsSaidAnything(words: AiSiteWords): boolean {\n return Boolean(words.about || words.audience)\n}\n\n/** What a job's inputs say the site is, read defensively and trimmed to the input ceiling. */\nexport function aiSiteWords(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): AiSiteWords {\n const read = (key: string): string => {\n const value = inputs?.[key]\n if (typeof value !== 'string') return ''\n return value.replace(/\\s+/g, ' ').trim().slice(0, AI_SITE_INPUT_MAX_CHARS).trim()\n }\n return { about: read('businessType'), audience: read('audience') }\n}\n\n/**\n * What a scaffold builds for itself: the layout its pages render inside, the\n * form they place, the palette suggestion a member applies in the Theme\n * section, and the datasets its structured content is kept in (AGL-3616),\n * which the data plugin writes. Anything else a plan asks to create is a job\n * of its own.\n */\nexport const AI_SITE_CREATE_KINDS: readonly AiBuildPlanCreateKind[] = [\n 'layout',\n 'form',\n 'theme-change',\n 'dataset',\n]\n\n/** The most datasets one site start creates (AGL-3616). */\nexport const AI_SITE_DATASETS_MAX = 3\n\n/** The creations a scaffold cannot build, in the order the plan lists them, each named once. */\nexport function aiSitePlanPrerequisites(\n plan: AiBuildPlan,\n): Array<{ kind: AiBuildPlanCreateKind; name: string }> {\n const seen = new Set<string>()\n const prerequisites: Array<{ kind: AiBuildPlanCreateKind; name: string }> = []\n const add = (kind: AiBuildPlanCreateKind, name: string) => {\n const key = `${kind}:${name.toLowerCase()}`\n if (seen.has(key)) return\n seen.add(key)\n prerequisites.push({ kind, name })\n }\n for (const entry of plan.create) {\n if (!AI_SITE_CREATE_KINDS.includes(entry.kind)) add(entry.kind, entry.name)\n }\n // A reference the create list does not carry is refused by the plan rules\n // before a plan is kept: rule 2 for a screen's layout, rule 7 for anything\n // else (`plan-creation-undeclared`, AGL-3040). A plan confirmed before that\n // rule existed can still carry one. It is named as a component: the\n // reference carries no kind, and the refusal must say where one is made.\n for (const { name } of aiPlanUndeclaredRefs(plan)) add('component', name)\n return prerequisites\n}\n\n/**\n * Why a scaffold cannot build a plan of this SHAPE — the page band, a page's\n * sections, its addresses, its navigation — in a sentence a member reads;\n * `null` when the shape is one it builds. The plan step holds a plan to it\n * with a re-ask (AGL-3030), and the doors hold a confirmed plan to it again\n * through `aiSitePlanRefusal`.\n */\nexport function aiSitePlanShapeRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean } = {},\n): string | null {\n const { screens } = plan\n const band = aiSitePagesBand(options.freeTaste)\n if (screens.length < band.min || screens.length > band.max) {\n return `This plan builds ${screens.length} ${screens.length === 1 ? 'page' : 'pages'}, and ${\n options.freeTaste ? \"a Free workspace's site scaffold\" : 'a site scaffold'\n } builds ${band.min} to ${band.max}. Describe the site again.`\n }\n const slugs = new Set<string>()\n for (const screen of screens) {\n if (!screen.sections.length) {\n return `The page “${screen.title}” has no sections to build. Describe the site again.`\n }\n if (screen.sections.length > AI_SITE_MAX_SECTIONS) {\n return `The page “${screen.title}” has ${screen.sections.length} sections, and a scaffolded page holds ${AI_SITE_MAX_SECTIONS}. Describe the site again.`\n }\n const slug = screen.slug.trim().toLowerCase()\n if (slugs.has(slug)) {\n return `Two pages in this plan share the address ${screen.slug}. Describe the site again.`\n }\n slugs.add(slug)\n }\n if (!screens.some((screen) => screen.nav)) {\n return 'No page in this plan is in the site navigation. Describe the site again.'\n }\n const datasets = plan.create.filter((entry) => entry.kind === 'dataset').length\n if (datasets > AI_SITE_DATASETS_MAX) {\n return `This plan creates ${datasets} datasets, and a site scaffold creates at most ${AI_SITE_DATASETS_MAX}. Keep the others' items on their pages.`\n }\n return null\n}\n\n/**\n * Why a scaffold cannot build this plan, in a sentence a member reads when\n * confirming it; `null` when it can.\n */\nexport function aiSitePlanRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean } = {},\n): string | null {\n const shape = aiSitePlanShapeRefusal(plan, options)\n if (shape) return shape\n const prerequisites = aiSitePlanPrerequisites(plan)\n if (!prerequisites.length) return null\n const parts = prerequisites.map(\n ({ kind, name }) =>\n `the ${AI_BUILD_PLAN_CREATION_NOUNS[kind].noun} “${name}” ${AI_BUILD_PLAN_CREATION_NOUNS[kind].where}`,\n )\n const listed =\n parts.length === 1\n ? parts[0]\n : `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`\n return `This site needs what the workspace does not have yet. Create ${listed}, then describe the site again.`\n}\n\n/** What the estimate counts a plan in: whether a welcome email follows, and the creations the job builds. */\nexport interface AiPlanPassOptions {\n welcomeEmail?: boolean\n /** The creation kinds the job builds itself; a scaffold's when absent. */\n creates?: readonly AiBuildPlanCreateKind[]\n /** Each page and creation written on its own (`aiStandaloneScreenCreditRange`), not as a site start’s (AGL-3722). */\n standalonePages?: boolean\n}\n\n/**\n * Whether a creation is built with no model: a dataset a form of the plan\n * writes to (AGL-3616) starts empty, designed from its planned fields, so it\n * is no pass of the estimate.\n */\nfunction aiPlanCreationIsModelFree(plan: Pick<AiBuildPlan, 'create'>, entry: AiBuildPlan['create'][number]): boolean {\n return entry.kind === 'dataset' && aiPlanFormDatasetNames(plan).has(entry.name.trim().toLowerCase())\n}\n\n/**\n * The passes a plan implies: one per section of every screen, one more per\n * screen for its search listing and its draft, and one for each thing the\n * plan creates that the job builds. What the estimate is counted in.\n */\nexport function aiPlanPasses(plan: AiBuildPlan, options: AiPlanPassOptions = {}): number {\n const screens = plan.screens.reduce(\n (total, screen) => total + screen.sections.length + 1,\n 0,\n )\n const creates = options.creates ?? AI_SITE_CREATE_KINDS\n const creations = plan.create.filter((entry) => creates.includes(entry.kind) && !aiPlanCreationIsModelFree(plan, entry)).length\n return screens + creations + (options.welcomeEmail ? 1 : 0)\n}\n\n/**\n * About what a plan costs to build, in credits. An ESTIMATE: the nominal\n * credits the machine holds per step, times the passes the plan implies.\n * What each pass actually costs is its model's tokens, recorded on the job\n * as it runs.\n */\nexport function aiPlanCreditEstimate(plan: AiBuildPlan, options: AiPlanPassOptions = {}): number {\n return aiPlanPasses(plan, options) * AI_SITE_PASS_CREDITS\n}\n\n/**\n * About what a job of this kind costs to build from its plan (AGL-3031): a\n * page job counts the layout, forms and components it builds before its\n * page; a template, layout, component, form or email job counts its own\n * record and every creation it builds before it (AGL-3143 §15); and a\n * scaffold counts what it builds. The figure the proposal shows beside\n * Confirm, and the hold a confirmation takes.\n */\nexport function aiJobPlanCreditEstimate(kind: string, plan: AiBuildPlan): number {\n const creates =\n kind === 'page' ? AI_PAGE_CREATE_KINDS : AI_JOB_CREATE_KINDS[kind as keyof typeof AI_JOB_CREATE_KINDS]\n return aiPlanCreditEstimate(plan, creates ? { creates } : {})\n}\n\n/**\n * About what a scaffold of this many pages costs, before a plan names its\n * sections: the same arithmetic on the nominal section count, plus the plan\n * step that proposes it. Shown where a member asks for a scaffold.\n */\nexport function aiSiteCreditEstimate(\n pages: number,\n options: { welcomeEmail?: boolean; siteKind?: string | null } = {},\n): number {\n const screens = Math.max(0, Math.floor(pages))\n const content = aiSiteStartContent(options.siteKind)\n const passes =\n 1 +\n screens * (AI_SITE_NOMINAL_SECTIONS + 1) +\n 2 +\n (options.welcomeEmail ? 1 : 0) +\n (content === 'products' ? 1 : content === 'posts' ? AI_SITE_START_POSTS : 0)\n return passes * AI_SITE_PASS_CREDITS\n}\n\n/** How many first posts a paid blog start writes, one pass each (`AI_SITE_POSTS`, held equal by `ai-site-job.spec.ts`). */\nexport const AI_SITE_START_POSTS = 3\n\n/**\n * The first content a paid start of this kind writes (AGL-3676): a store's\n * first products, a blog's first posts, or nothing. `aiSiteContentPart`'s\n * answer for a paid start, by the kind's id.\n */\nexport function aiSiteStartContent(siteKind: string | null | undefined): 'posts' | 'products' | null {\n if (siteKind === 'store') return 'products'\n if (siteKind === 'blog') return 'posts'\n return null\n}\n\n/**\n * The measured cost of one creation a plan builds (AGL-3722): a layout's or\n * a form's as measured, a theme's as the site start's look measured, and\n * any other kind at the stand-in a single-answer creation is priced at.\n * `standalone` for one written on its own — a build's, a page job's — rather\n * than inside a site start's warm run.\n */\nexport function aiCreationMeasuredCredits(kind: string, options: { standalone?: boolean } = {}): AiMeasuredCredits {\n if (kind === 'layout') {\n return options.standalone ? AI_MEASURED_STANDALONE_CREATION_CREDITS.layout : AI_MEASURED_UNIT_CREDITS.layout\n }\n if (kind === 'form') return AI_MEASURED_UNIT_CREDITS.form\n if (kind === 'theme' || kind === 'theme-change') return AI_MEASURED_UNIT_CREDITS.theme\n return AI_MEASURED_PASS_CREDITS\n}\n\n/** A planned page's range: its sections scaled around the measured page, its ceiling one pass a section and one for its listing. */\nexport function aiScreenCreditRange(sections: number): AiCreditRange {\n return aiCreditRangeOf(aiMeasuredPageCredits(sections), (Math.max(0, sections) + 1) * AI_SITE_PASS_CREDITS)\n}\n\n/**\n * A page written on its own — an Assist build's, a page job's — as a range\n * (AGL-3722): a fixed cost and one per section as such pages measured\n * (`AI_MEASURED_STANDALONE_PAGE`), never a site start's later, cheaper\n * pages; the ceiling as `aiScreenCreditRange`'s.\n */\nexport function aiStandaloneScreenCreditRange(sections: number): AiCreditRange {\n return aiCreditRangeOf(\n aiMeasuredStandalonePageCredits(sections),\n (Math.max(0, sections) + 1) * AI_SITE_PASS_CREDITS,\n )\n}\n\n/**\n * What a plan is likely to cost, its p90 and its ceiling (AGL-3722): the\n * same units `aiPlanCreditEstimate` counts, each at what it measured; the\n * ceiling IS `aiPlanCreditEstimate`.\n */\nexport function aiPlanCreditRange(plan: AiBuildPlan, options: AiPlanPassOptions = {}): AiCreditRange {\n const creates = options.creates ?? AI_SITE_CREATE_KINDS\n let range = AI_CREDIT_RANGE_ZERO\n const screenRange = options.standalonePages ? aiStandaloneScreenCreditRange : aiScreenCreditRange\n for (const screen of plan.screens) range = aiCreditRangeAdd(range, screenRange(screen.sections.length))\n for (const entry of plan.create) {\n if (!creates.includes(entry.kind) || aiPlanCreationIsModelFree(plan, entry)) continue\n range = aiCreditRangeAdd(\n range,\n aiCreditRangeOf(aiCreationMeasuredCredits(entry.kind, { standalone: options.standalonePages }), AI_SITE_PASS_CREDITS),\n )\n }\n if (options.welcomeEmail) range = aiCreditRangeAdd(range, aiCreditRangeOf(AI_MEASURED_PASS_CREDITS, AI_SITE_PASS_CREDITS))\n return aiCreditRangeOrdered(range)\n}\n\n/**\n * `aiJobPlanCreditEstimate` as a range (AGL-3722): the same kinds, each at\n * what it measured. Only a site start writes its pages in one warm run; every\n * other kind's page is written on its own.\n */\nexport function aiJobPlanCreditRange(kind: string, plan: AiBuildPlan): AiCreditRange {\n const creates =\n kind === 'page' ? AI_PAGE_CREATE_KINDS : AI_JOB_CREATE_KINDS[kind as keyof typeof AI_JOB_CREATE_KINDS]\n return aiPlanCreditRange(plan, { ...(creates ? { creates } : {}), standalonePages: kind !== 'site' })\n}\n\n/**\n * A paid site start's range before its plan (AGL-3722): the plan, its look,\n * layout and form, and each page at the nominal sections, as measured; the\n * ceiling is `aiSiteCreditEstimate`.\n */\nexport function aiSiteCreditRange(\n pages: number,\n options: { welcomeEmail?: boolean; siteKind?: string | null } = {},\n): AiCreditRange {\n const count = Math.max(0, Math.floor(pages))\n // A paid start plans and writes on the paid routing, measured apart (AGL-3739).\n const { plan, theme, layout, form, page, email, products } = AI_MEASURED_PAID_SITE_CREDITS\n const content = aiSiteStartContent(options.siteKind)\n // A blog's posts have no measurement of their own yet: the stand-in pass.\n const parts: AiMeasuredCredits[] = [\n plan,\n theme,\n layout,\n form,\n ...Array.from({ length: count }, () => page),\n ...(options.welcomeEmail ? [email] : []),\n ...(content === 'products' ? [products] : content === 'posts' ? [AI_MEASURED_PASS_CREDITS] : []),\n ]\n return aiCreditRangeOrdered({\n likely: parts.reduce((total, part) => total + part.median, 0),\n p90: parts.reduce((total, part) => total + part.p90, 0),\n ceiling: aiSiteCreditEstimate(count, options),\n })\n}\n"],"names":["aiSiteKind","AI_BUILD_PLAN_CREATION_NOUNS","aiPlanFormDatasetNames","aiPlanUndeclaredRefs","AI_JOB_CREATE_KINDS","AI_PAGE_CREATE_KINDS","FREE_AI_TASTE_CREDITS_PER_MONTH","AI_CREDIT_RANGE_ZERO","AI_MEASURED_PAID_SITE_CREDITS","AI_MEASURED_PASS_CREDITS","AI_MEASURED_STANDALONE_CREATION_CREDITS","AI_MEASURED_UNIT_CREDITS","aiCreditRangeAdd","aiCreditRangeOf","aiCreditRangeOrdered","aiCreditsPromptFor","aiMeasuredPageCredits","aiMeasuredStandalonePageCredits","AI_SITE_PAGES","min","max","AI_SITE_FREE_PAGES","aiSitePagesBand","freeTaste","AI_JOB_AUTO_CONFIRM_INPUT","AI_SITE_FREE_PAGES_NOTE","AI_SITE_PLAN_MAX_TOKENS","free","paid","AI_FREE_SITE_WORST_CASE_CREDITS","plan","look","layout","form","page","section","retry","listing","AI_FREE_SITE_MAX_SECTIONS","aiFreeSiteWorstCaseCredits","creations","sections","credits","pages","Math","floor","layouts","forms","aiFreeSiteSectionsWithin","taste","before","Number","POSITIVE_INFINITY","AI_SITE_MAX_SECTIONS","aiFreeSiteCreditEstimate","aiFreeCreditsResetOn","now","next","Date","UTC","getUTCFullYear","getUTCMonth","toISOString","slice","aiFreeCreditsResetLabel","resetsOn","at","isFinite","getTime","toLocaleDateString","month","day","timeZone","aiFreeSiteCreditRange","count","aiSiteStartMeasured","ceiling","theme","AI_SITE_NOMINAL_SECTIONS","likely","median","p90","AI_SITE_HOME_FIRST_LABEL","aiFreeSitePrompt","left","home","label","aiFreeCreditsNoneLeftText","AI_SITE_HOME_MIN_SECTIONS","AI_SITE_BLOG_NAME","AI_SITE_BLOG_SLUGS","firstSegment","slug","trim","replace","split","toLowerCase","aiSiteBlogSlug","screens","taken","Set","map","screen","filter","Boolean","find","has","AI_SITE_BLOG_NAV_ID","aiSiteBlogNavPage","id","href","aiSiteIsBlogStandIn","aiSitePlanIsHome","includes","BLOG_PAGE_WORDS","test","title","aiSitePlanWithoutBlogStandIns","standIns","AI_SITE_BLOG_PAGE_CODE","aiSiteBlogStandInViolations","flatMap","index","length","names","join","rule","code","message","paths","AI_SITE_EMPTY_GALLERY_CODE","AI_SITE_GALLERY_MIN_ITEMS","AI_SITE_GALLERY_MAX_ITEMS","GALLERY_SECTION","FRAMING_SECTION","aiSiteSectionShowsWork","name","AI_SITE_GALLERY_SENTENCE","aiSiteEmptyGalleryViolations","thin","screenIndex","sectionIndex","items","path","entry","AI_SITE_THIN_HOME_CODE","AI_SITE_HOME_BANDS","aiSiteHomeMinSections","input","across","others","aiSiteFullPlanSentence","lead","homeHi","otherHi","otherLo","totalLo","range","lo","hi","pagesWord","aiSiteThinHomeViolations","options","findIndex","within","AI_SITE_PASS_CREDITS","AI_SITE_INPUT_MAX_CHARS","AI_SITE_BATCH_MAX","AI_SITE_BATCH_MIN_HOST_LIMIT","AI_SITE_SUBMISSIONS","AI_SITE_SUBMISSION_CHOICES","blurb","AI_SITE_EMAIL_TYPE","aiSiteNameSentence","aiSiteSubmissions","inputs","value","ID_CHARS","parseAiSiteJobInputs","text","key","undefined","trimmed","businessType","businessName","city","brand","audience","starter","siteKind","rawPages","NaN","isInteger","submissions","rawBatch","batchId","welcomeEmail","aiSitePagesRefusal","band","aiSiteWordsSaidAnything","words","about","aiSiteWords","read","AI_SITE_CREATE_KINDS","AI_SITE_DATASETS_MAX","aiSitePlanPrerequisites","seen","prerequisites","add","kind","push","create","aiSitePlanShapeRefusal","slugs","some","nav","datasets","aiSitePlanRefusal","shape","parts","noun","where","listed","aiPlanCreationIsModelFree","aiPlanPasses","reduce","total","creates","aiPlanCreditEstimate","aiJobPlanCreditEstimate","aiSiteCreditEstimate","content","aiSiteStartContent","passes","AI_SITE_START_POSTS","aiCreationMeasuredCredits","standalone","aiScreenCreditRange","aiStandaloneScreenCreditRange","aiPlanCreditRange","screenRange","standalonePages","aiJobPlanCreditRange","aiSiteCreditRange","email","products","Array","from","part"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,UAAU,QAAQ,qBAAiB;AAC5C,SACEC,4BAA4B,EAC5BC,sBAAsB,EACtBC,oBAAoB,QAGf,qBAAiB;AACxB,SAASC,mBAAmB,QAAQ,wBAAoB;AACxD,SAASC,oBAAoB,QAAQ,mBAAe;AACpD,SAASC,+BAA+B,QAAQ,0BAAsB;AACtE,SACEC,oBAAoB,EACpBC,6BAA6B,EAC7BC,wBAAwB,EACxBC,uCAAuC,EACvCC,wBAAwB,EACxBC,gBAAgB,EAChBC,eAAe,EACfC,oBAAoB,EACpBC,kBAAkB,EAClBC,qBAAqB,EACrBC,+BAA+B,QAI1B,0BAAsB;AAE7B;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GAED,+EAA+E,GAC/E,OAAO,MAAMC,gBAAgB;IAAEC,KAAK;IAAGC,KAAK;AAAE,EAAU;AAExD;;;;;;CAMC,GACD,OAAO,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AC,CAACC,OAAOsB,OAAStB,QAAQsB,KAAKzK,MAAM,EAAE;QAC3DC,KAAK2I,MAAMM,MAAM,CAAC,CAACC,OAAOsB,OAAStB,QAAQsB,KAAKxK,GAAG,EAAE;QACrDL,SAAS2J,qBAAqB7J,OAAOwF;IACvC;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-job.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 { aiSiteKind } from './ai-site-kinds'\nimport {\n AI_BUILD_PLAN_CREATION_NOUNS,\n aiPlanFormDatasetNames,\n aiPlanUndeclaredRefs,\n type AiBuildPlan,\n type AiBuildPlanCreateKind,\n} from './ai-build-plan'\nimport { AI_JOB_CREATE_KINDS } from './ai-job-creations'\nimport { AI_PAGE_CREATE_KINDS } from './ai-page-job'\nimport { FREE_AI_TASTE_CREDITS_PER_MONTH } from '../plan-entitlements'\nimport {\n AI_CREDIT_RANGE_ZERO,\n AI_MEASURED_PAID_SITE_CREDITS,\n AI_MEASURED_PASS_CREDITS,\n AI_MEASURED_STANDALONE_CREATION_CREDITS,\n AI_MEASURED_UNIT_CREDITS,\n aiCreditRangeAdd,\n aiCreditRangeOf,\n aiCreditRangeOrdered,\n aiCreditsPromptFor,\n aiMeasuredPageCredits,\n aiMeasuredStandalonePageCredits,\n type AiCreditRange,\n type AiCreditsPrompt,\n type AiMeasuredCredits,\n} from './ai-credit-estimate'\n\n/**\n * What a site scaffold is (AGL-2911): the inputs a `site` job is admitted\n * with, the plans a scaffold can build, and what one is estimated to cost\n * before it starts.\n *\n * A scaffold is the one job kind that builds a whole site rather than one\n * record: a plan of four to eight screens, the layout they render inside,\n * the contact form they place, a palette suggestion, and — where the email\n * step is loaded — a welcome email. It builds each of those through the job\n * kind that already owns it, so this module describes what a scaffold may\n * ask for and refuses the rest at confirmation, before a credit is spent,\n * naming what to make first.\n *\n * ── The estimate is the guard rail ───────────────────────────────────────\n *\n * A scaffold is tens of model calls, where every other kind is a few, so the\n * member reads what it will cost before they confirm the plan that spends\n * it. The figure is the machine's own nominal credits per step multiplied by\n * the passes the plan implies — an estimate, and said to be one wherever it\n * is shown.\n *\n * This module imports nothing at runtime, so the doors, the step, the batch\n * card and the plan proposal read one vocabulary.\n */\n\n/** How many pages a scaffold builds: enough to be a site, few enough to read. */\nexport const AI_SITE_PAGES = { min: 4, max: 8 } as const\n\n/**\n * How many pages a Free workspace's scaffold builds (AGL-3594): its home page\n * and the one page the brief most needs. A product decision, not a figure the\n * wall derives — the wall's proof (`jobs/ai-job-free-site.spec.ts`) shows a\n * plan and a build of this many pages fit the Free taste with room for one\n * retried page.\n */\nexport const AI_SITE_FREE_PAGES = { min: 1, max: 2 } as const\n\n/** The pages a scaffold builds for a workspace on the Free taste or on a paid plan. */\nexport function aiSitePagesBand(\n freeTaste: boolean | null | undefined,\n): { readonly min: number; readonly max: number } {\n return freeTaste ? AI_SITE_FREE_PAGES : AI_SITE_PAGES\n}\n\n/**\n * The job input a guided site start sets so its plan is confirmed for it\n * (AGL-3594); `jobs/ai-job-auto-confirm.ts` says where it is honored.\n */\nexport const AI_JOB_AUTO_CONFIRM_INPUT = 'autoConfirm'\n\n/** What a Free site start's page selector says under it (AGL-3594). */\nexport const AI_SITE_FREE_PAGES_NOTE = 'Paid plans can generate more pages.'\n\n/**\n * The plan's answer ceiling for a scaffold (AGL-3594), Free and paid. A plan\n * is an outline — each page's title, address, search listing and sections by\n * name — and the build steps write everything else, so a scaffold plans with\n * no thinking and at a ceiling sized to the outline of its largest band with\n * room to spare: about 300 tokens a page. The 13,491-token plan a Free site\n * spent 227 of its 300 credits on was its thinking, at the routing table's\n * 8,000 a call.\n */\nexport const AI_SITE_PLAN_MAX_TOKENS = { free: 2_000, paid: 4_000 } as const\n\n/** What each exchange of a Free site job comes to at its worst, in credits. */\nexport interface AiFreeSiteWorstCase {\n /** The site plan: its answer and its one re-ask, each at its ceiling. */\n plan: number\n /** The site's look (AGL-3660): its one answer at its ceiling, on the fast tier. */\n look: number\n /**\n * The layout a site with none has built first (AGL-3660): its header and\n * footer as ONE answer in the layout language, writing its cached prefix,\n * at the most a live frame answer wrote, and never under what the live\n * guided start's layout step metered.\n */\n layout: number\n /** The saved form a guided start makes (AGL-3596), at what the live guided start's form step metered. */\n form: number\n /**\n * A language page's answer before its sections (AGL-3660): its cached\n * prefix written, its turn, and the whole room its ceiling keeps for\n * thinking. A page is ONE answer, not a pass a section.\n */\n page: number\n /** Each planned section's words in that answer, at the most a section is written in. */\n section: number\n /**\n * Room for one page asked again: the answer once more, reading its cached\n * prefix, with its thinking room and a full page of sections.\n */\n retry: number\n /** A page's listing. */\n listing: number\n}\n\n/**\n * The Free site start's wall at its worst (AGL-3594, re-derived for the\n * layout language in AGL-3660): the plan and the look as\n * `jobs/ai-job-free-site.spec.ts` derives them from their requests at their\n * ceilings; the layout, form and pages from the language requests as they\n * stand, priced as each field says. The spec fails when a figure it derives\n * moves and this does not.\n */\nexport const AI_FREE_SITE_WORST_CASE_CREDITS: Readonly<AiFreeSiteWorstCase> = {\n plan: 36,\n look: 7,\n layout: 23,\n form: 29,\n page: 43,\n section: 4,\n retry: 64,\n listing: 3,\n}\n\n/**\n * The most sections a Free site plans across its pages (AGL-3660), whatever\n * the wall leaves: a full home of five and a page of two or three. A product\n * figure, so the spend a site EXPECTS stays near what it measured; the wall\n * proves it fits.\n */\nexport const AI_FREE_SITE_MAX_SECTIONS = 8\n\n/** What a Free site start builds before its sections: the layouts it builds first, its forms and its pages. */\nexport interface AiFreeSiteCreations {\n layouts: number\n pages: number\n /** The saved forms it makes; a guided start makes one where it places a form. */\n forms: number\n}\n\n/** A Free site start's credits at its worst for this many sections, its room for one retried page included. */\nexport function aiFreeSiteWorstCaseCredits(\n creations: AiFreeSiteCreations,\n sections: number,\n credits: Readonly<AiFreeSiteWorstCase> = AI_FREE_SITE_WORST_CASE_CREDITS,\n): number {\n const pages = Math.max(1, Math.floor(creations.pages))\n return (\n credits.plan +\n credits.look +\n creations.layouts * credits.layout +\n creations.forms * credits.form +\n pages * (credits.page + credits.listing) +\n sections * credits.section +\n credits.retry\n )\n}\n\n/**\n * The most sections a Free site's plan fits in the Free taste at its worst,\n * across all its pages (AGL-3660): the plan, the look, the layout and form it\n * builds first, each page's answer and listing, ROOM FOR ONE RETRIED PAGE,\n * and as many sections as the rest pays for — at most\n * `AI_FREE_SITE_MAX_SECTIONS`, and at most what the pages hold. None when the\n * rest is already past the wall.\n */\nexport function aiFreeSiteSectionsWithin(\n creations: AiFreeSiteCreations,\n taste: number,\n credits: Readonly<AiFreeSiteWorstCase> = AI_FREE_SITE_WORST_CASE_CREDITS,\n): number {\n const pages = Math.max(1, Math.floor(creations.pages))\n const before = aiFreeSiteWorstCaseCredits(creations, 0, credits)\n if (before > taste) return 0\n const paid = credits.section > 0 ? Math.floor((taste - before) / credits.section) : Number.POSITIVE_INFINITY\n return Math.min(AI_FREE_SITE_MAX_SECTIONS, pages * AI_SITE_MAX_SECTIONS, paid)\n}\n\n/**\n * What a Free site start of this many pages can cost at its worst, in\n * credits (AGL-3660): `aiFreeSiteWorstCaseCredits` for an empty site — the\n * plan, its look, the layout and form a guided start builds, each page's\n * answer and listing, the sections its plan is held to\n * (`aiFreeSiteSectionsWithin` at the month's whole taste, which is what the\n * plan step allows) and the room for one retried page.\n *\n * The CEILING a start is quoted with (\"up to 283\"), no longer the figure it\n * is admitted on (AGL-3722): that is the measured p90\n * (`aiFreeSiteCreditRange`), and a start past what is left is asked to be\n * confirmed and pauses with Resume when its credits run out, instead of\n * being held back from starting at all.\n */\nexport function aiFreeSiteCreditEstimate(\n pages: number,\n credits: Readonly<AiFreeSiteWorstCase> = AI_FREE_SITE_WORST_CASE_CREDITS,\n): number {\n const creations: AiFreeSiteCreations = { layouts: 1, forms: 1, pages: Math.max(1, Math.floor(pages)) }\n const sections = aiFreeSiteSectionsWithin(creations, FREE_AI_TASTE_CREDITS_PER_MONTH, credits)\n return aiFreeSiteWorstCaseCredits(creations, sections, credits)\n}\n\n/**\n * What a Free workspace has left of its Free AI credits this month: the less\n * of its own band's balance and its owner's, since the owner's allowance is\n * shared by every Free workspace they hold (AGL-2925) and the reservation\n * refuses at whichever wall is reached first. `resetsOn` is the UTC day the\n * month — and with it both balances — rolls over, `YYYY-MM-DD`.\n */\nexport interface AiFreeCreditsLeft {\n left: number\n total: number\n resetsOn: string\n /**\n * Both meters `left` is the lesser of, in credits net of give-backs, for the\n * usage strip's live read (AGL-3722): the owner's Free allowance across\n * their Free workspaces (`account`, `null` with no owner) and this\n * workspace's band.\n */\n used?: {\n account: number | null\n org: number\n orgBand: number | null\n /** The strip's warn state for these figures, worked out where the strip's own rule is not shipped to the browser. */\n state: 'ok' | 'warn' | 'capped'\n }\n}\n\n/** The first UTC day of the month after `now`, `YYYY-MM-DD`: when the Free credits come back. */\nexport function aiFreeCreditsResetOn(now: Date): string {\n const next = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1))\n return next.toISOString().slice(0, 10)\n}\n\n/** A reset day as a person reads it: \"November 1\". */\nexport function aiFreeCreditsResetLabel(resetsOn: string): string {\n const at = new Date(`${resetsOn}T00:00:00.000Z`)\n return Number.isFinite(at.getTime())\n ? at.toLocaleDateString('en-US', { month: 'long', day: 'numeric', timeZone: 'UTC' })\n : 'the first of next month'\n}\n\n/**\n * What a Free site start of this many pages is likely to cost, its p90 and\n * its ceiling (AGL-3722), before a plan names its sections: the plan, the\n * look, the layout and form a guided start builds, and each page at the\n * nominal section count, at what each MEASURED in production\n * (`AI_MEASURED_UNIT_CREDITS`); the ceiling is the whole worst case the wall\n * is proven with (`aiFreeSiteCreditEstimate`). Two pages: about 137\n * (p90 213, up to 283).\n */\nexport function aiFreeSiteCreditRange(pages: number): AiCreditRange {\n const count = Math.max(1, Math.floor(pages))\n return aiCreditRangeOrdered({\n ...aiSiteStartMeasured(count),\n ceiling: aiFreeSiteCreditEstimate(count),\n })\n}\n\n/** A site start's measured likely and p90 before its plan: plan, look, layout, form and its pages at the nominal sections. */\nfunction aiSiteStartMeasured(pages: number): Pick<AiCreditRange, 'likely' | 'p90'> {\n const { plan, theme, layout, form } = AI_MEASURED_UNIT_CREDITS\n const page = aiMeasuredPageCredits(AI_SITE_NOMINAL_SECTIONS)\n return {\n likely: plan.median + theme.median + layout.median + form.median + pages * page.median,\n p90: plan.p90 + theme.p90 + layout.p90 + form.p90 + pages * page.p90,\n }\n}\n\n/** The smaller first build a site start offers: its home page alone. */\nexport const AI_SITE_HOME_FIRST_LABEL = 'Build the home page first'\n\n/**\n * What a Free site start says before it starts when what is left does not\n * cover its p90 (AGL-3722), or `null` when it fits — or when nothing is known\n * about what is left, since the reservation still decides each pass. Not a\n * refusal: the person may build what fits (the job pauses with Resume when\n * the credits run out), build the home page first, or upgrade.\n */\nexport function aiFreeSitePrompt(\n credits: Pick<AiFreeCreditsLeft, 'left' | 'resetsOn'> | null | undefined,\n pages: number,\n): AiCreditsPrompt | null {\n if (!credits || !Number.isFinite(credits.left)) return null\n const count = Math.max(1, Math.floor(pages))\n const home = aiFreeSiteCreditRange(1)\n return aiCreditsPromptFor(\n aiFreeSiteCreditRange(count),\n credits,\n count > 1 ? { label: AI_SITE_HOME_FIRST_LABEL, ...home } : null,\n )\n}\n\n/**\n * Why a Free start is refused outright (AGL-3722): nothing at all is left,\n * so there is nothing for \"build what fits\" to build.\n */\nexport function aiFreeCreditsNoneLeftText(resetsOn: string): string {\n return (\n `You have no free AI credits left this month. They are shared by all your Free workspaces and ` +\n `renew on ${aiFreeCreditsResetLabel(resetsOn)}. Upgrade this workspace to build with AI now.`\n )\n}\n\n/**\n * The most sections one scaffolded page may hold. The plan model allows more\n * for a page job, which builds one page; a scaffold builds eight, and each\n * section is a pass of its own.\n */\nexport const AI_SITE_MAX_SECTIONS = 8\n\n/**\n * The fewest sections a site start's home page is planned with (AGL-3660).\n * A new site is a full website (Zach, 2026-10-04): its home reads as one — a\n * hero, then bands such as the offer, why us, social proof, and a closing\n * call to action. A plan is an outline and nothing asked for more than a\n * ceiling, so a live Free yoga start (2026-10-07) planned its home with two\n * sections. The plan step names this count in the plan's turn and re-asks a\n * first answer whose home is under it (`aiSiteThinHomeViolations`).\n */\nexport const AI_SITE_HOME_MIN_SECTIONS = 5\n\n/**\n * The blog a paid guided start writes its first posts into (AGL-3676), and\n * the addresses it may answer at, in order of preference: the first one no\n * planned page takes.\n */\nexport const AI_SITE_BLOG_NAME = 'Blog'\nexport const AI_SITE_BLOG_SLUGS = ['blog', 'posts', 'journal', 'articles', 'writing', 'stories'] as const\n\n/** A planned page's first path segment, lower-cased: `/journal/2026` → `journal`. */\nconst firstSegment = (slug: string) => slug.trim().replace(/^\\/+/, '').split('/')[0].toLowerCase()\n\n/** The address the blog answers at, beside these planned pages: the first of `AI_SITE_BLOG_SLUGS` none of them takes. */\nexport function aiSiteBlogSlug(screens: ReadonlyArray<{ slug: string }>): string {\n const taken = new Set(screens.map((screen) => firstSegment(screen.slug)).filter(Boolean))\n return AI_SITE_BLOG_SLUGS.find((slug) => !taken.has(slug)) ?? AI_SITE_BLOG_SLUGS[0]\n}\n\n/** The header's link to the blog (AGL-3660): a path, not a page, since the blog is the posts collection. */\nexport const AI_SITE_BLOG_NAV_ID = 'aiSiteBlog'\n\n/** The nav entry a site whose start writes posts links its blog by. */\nexport function aiSiteBlogNavPage(screens: ReadonlyArray<{ slug: string }>): {\n id: string\n label: string\n slug: string\n href: string\n} {\n const slug = aiSiteBlogSlug(screens)\n return { id: AI_SITE_BLOG_NAV_ID, label: AI_SITE_BLOG_NAME, slug: `/${slug}`, href: `/${slug}` }\n}\n\n/**\n * Whether a planned page stands in for the blog a start writes (AGL-3660):\n * its address is one of the blog's, or its name says it lists posts. The\n * home page never does.\n */\nexport function aiSiteIsBlogStandIn(screen: { slug: string; title: string }): boolean {\n if (aiSitePlanIsHome(screen)) return false\n return (AI_SITE_BLOG_SLUGS as readonly string[]).includes(firstSegment(screen.slug)) || BLOG_PAGE_WORDS.test(screen.title)\n}\n\n/**\n * A start that writes posts, with its plan's stand-in pages taken out\n * (AGL-3676): the plan step asks once for a plan without one and keeps a\n * second answer that still has one, so the scaffold merges it into the blog\n * instead — the page is not built, its links go to the blog, and the blog\n * takes the address it left free. The kept screens hold their plan index,\n * which a page unit's slot is named by.\n */\nexport function aiSitePlanWithoutBlogStandIns<T extends { slug: string; title: string }>(\n screens: readonly T[],\n): { screens: T[]; standIns: T[] } {\n return {\n screens: screens.filter((screen) => !aiSiteIsBlogStandIn(screen)),\n standIns: screens.filter((screen) => aiSiteIsBlogStandIn(screen)),\n }\n}\n\n/** The code a planned page that stands in for the written blog is re-asked under. */\nexport const AI_SITE_BLOG_PAGE_CODE = 'plan-blog-page-duplicate'\n\n/** A page's name that says it lists the posts. */\nconst BLOG_PAGE_WORDS = /\\b(blog|posts?|articles?|journal|writing|stories|news)\\b/i\n\n/**\n * A site plan's pages that stand in for the blog its start writes (AGL-3660):\n * the live Slow Roads start (2026-10-08) planned an \"Articles\" page of\n * featured cards beside the posts it wrote at /blog, and the header linked\n * Articles and never the blog. A page whose address is one of the blog's, or\n * whose name says it lists posts, duplicates it; the home page never does.\n */\nexport function aiSiteBlogStandInViolations(\n plan: Pick<AiBuildPlan, 'screens'>,\n): Array<{ rule: null; code: string; message: string; paths: string[] }> {\n const standIns = plan.screens.flatMap((screen, index) => (aiSiteIsBlogStandIn(screen) ? [{ screen, index }] : []))\n if (!standIns.length) return []\n const names = standIns.map(({ screen }) => `\"${screen.title}\" at ${screen.slug}`).join(', ')\n return [\n {\n rule: null,\n code: AI_SITE_BLOG_PAGE_CODE,\n message: `${names} ${standIns.length === 1 ? 'stands' : 'stand'} in for the blog this site already gets: its first posts are written at /blog, and the header links it. Take ${standIns.length === 1 ? 'that page' : 'those pages'} out, and plan another page the brief needs, or feature the posts in a section of the home page.`,\n paths: standIns.map(({ index }) => `screens[${index}]`),\n },\n ]\n}\n\n/** The code a site plan's work section planned without its pieces is re-asked under. */\nexport const AI_SITE_EMPTY_GALLERY_CODE = 'plan-empty-gallery'\n\n/** The pieces a section that shows the work is planned with (AGL-3660). */\nexport const AI_SITE_GALLERY_MIN_ITEMS = 3\nexport const AI_SITE_GALLERY_MAX_ITEMS = 6\n\n/**\n * A planned section that shows the work: a gallery, a portfolio, a\n * collection, selected or featured work. \"Galleries\" — an audience, as in\n * \"Why galleries choose us\" — and \"how we work\" are not.\n */\nconst GALLERY_SECTION =\n /\\b(gallery|portfolio|collections?|lookbook|showcase|works|projects|(?:selected|featured|recent|our|past) (?:work|pieces|projects))\\b/i\n\n/** A section that only opens, introduces or closes a page, whatever page it is on: \"Portfolio Hero\". */\nconst FRAMING_SECTION = /\\b(hero|intro(?:duction)?|banner|header|cta|call to action|contact|inquiry|enquiry|about)\\b/i\n\n/** Whether a planned section's name says it shows the work. */\nexport function aiSiteSectionShowsWork(name: string): boolean {\n return GALLERY_SECTION.test(name) && !FRAMING_SECTION.test(name)\n}\n\n/** The sentence a site plan's turn states about a section that shows the work. */\nexport const AI_SITE_GALLERY_SENTENCE = `A section that shows the work — a gallery, portfolio, collection or selected works — counts its pieces in its items: ${AI_SITE_GALLERY_MIN_ITEMS} to ${AI_SITE_GALLERY_MAX_ITEMS}.`\n\n/**\n * A site plan's sections that show the work with fewer than three pieces\n * (AGL-3660). The live Juniper Clay start (2026-10-08) planned its Portfolio\n * page's \"Works Gallery\" with no items, and the page's works lost their place\n * to an inquiry form: a page about the work showed none.\n */\nexport function aiSiteEmptyGalleryViolations(\n plan: Pick<AiBuildPlan, 'screens'>,\n): Array<{ rule: null; code: string; message: string; paths: string[] }> {\n const thin = plan.screens.flatMap((screen, screenIndex) =>\n screen.sections.flatMap((section, sectionIndex) =>\n aiSiteSectionShowsWork(section.name) && section.items < AI_SITE_GALLERY_MIN_ITEMS\n ? [{ name: `\"${section.name}\" on ${screen.title}`, path: `screens[${screenIndex}].sections[${sectionIndex}].items` }]\n : [],\n ),\n )\n if (!thin.length) return []\n const names = thin.map((entry) => entry.name).join(', ')\n return [\n {\n rule: null,\n code: AI_SITE_EMPTY_GALLERY_CODE,\n message: `${names} ${thin.length === 1 ? 'shows' : 'show'} the work with fewer than ${AI_SITE_GALLERY_MIN_ITEMS} pieces. Plan ${thin.length === 1 ? 'it' : 'each'} with ${AI_SITE_GALLERY_MIN_ITEMS} to ${AI_SITE_GALLERY_MAX_ITEMS} items, one for each piece it shows.`,\n paths: thin.map((entry) => entry.path),\n },\n ]\n}\n\n/** The violation a site plan whose home page is under its fewest sections is re-asked under. */\nexport const AI_SITE_THIN_HOME_CODE = 'plan-thin-home'\n\n/** What a site plan's home is composed of, in the words the plan's turn and its re-ask both use. */\nexport const AI_SITE_HOME_BANDS =\n 'a hero first, then bands such as services or the offer, about or why us, and testimonials or other social proof, and a closing call to action or contact band last'\n\n/**\n * The fewest sections this site start's home is held to (AGL-3660): five, or\n * 0 — no minimum — where the Free wall cannot pay for a full home beside the\n * other pages. `across` is the sections the Free taste fits across `pages`\n * pages, each other page keeping at least one; `null` is a paid start, which\n * no wall shares out.\n *\n * ⛔ NEVER a lowered minimum. A Free guided start creates its site empty and\n * plans its layout, and the wall then fits 4 sections across two pages. Told\n * \"a home of at least 3\" beside that, the live yoga start of 2026-10-08\n * planned 4 + 3 and then 4 + 2, was refused for the wall twice, and stopped:\n * a home asked for in bands the wall cannot pay for is a start that fails.\n */\nexport function aiSiteHomeMinSections(input: { pages: number; across: number | null }): number {\n if (input.across === null) return AI_SITE_HOME_MIN_SECTIONS\n const others = Math.max(0, Math.floor(input.pages) - 1)\n return input.across - others >= AI_SITE_HOME_MIN_SECTIONS ? AI_SITE_HOME_MIN_SECTIONS : 0\n}\n\n/**\n * What a site start's plan is told to BUILD with (AGL-3660): the sections are\n * a budget to use, never a ceiling to stay under. Told only \"at most 8\", the\n * live prod start of 2026-10-08 planned a home of two sections, and Zach: \"that\n * didn't mean do as little as possible.\" On the Free taste the sentence shares\n * the wall's sections out — a home of five or six, the other page two or\n * three, about seven or eight in all; a paid start's home is asked to be rich.\n * `min` is the home's fewest (`aiSiteHomeMinSections`), 0 where the plan\n * plans no home or the wall cannot pay for a full one.\n */\nexport function aiSiteFullPlanSentence(input: { pages: number; across: number | null; min: number }): string {\n const { across, min } = input\n if (across === null) {\n return min > 0\n ? `Plan a full website, never a minimal one: a rich home page of ${min + 1} or more sections where the brief gives them, and every page with the sections it needs.`\n : 'Plan a full website, never a minimal one: every page with the sections it needs.'\n }\n const lead = `The ${across} sections are the budget to use, not a ceiling to stay under: plan a full website, never a minimal one`\n const others = Math.max(0, Math.floor(input.pages) - 1)\n if (min <= 0 || across < min) return `${lead}.`\n const homeHi = Math.max(min, Math.min(min + 1, across - others))\n if (!others) return `${lead}: the home page at / with ${min} to ${homeHi} sections.`\n const otherHi = Math.max(1, Math.min(3, Math.floor((across - min) / others)))\n const otherLo = Math.max(1, Math.min(2, otherHi, Math.floor((across - homeHi) / others)))\n const totalLo = Math.max(min + others, across - 1)\n const range = (lo: number, hi: number) => (lo === hi ? `${lo}` : `${lo} to ${hi}`)\n const pagesWord = others === 1 ? 'the other page' : 'each other page'\n return `${lead}: the home page at / with ${range(min, homeHi)} sections, ${pagesWord} ${range(otherLo, otherHi)}, about ${range(totalLo, across)} in total.`\n}\n\n/** Whether a planned page is the site's home: the one at `/`. */\nexport function aiSitePlanIsHome(screen: { slug: string }): boolean {\n const slug = screen.slug.trim()\n return slug === '/' || slug === ''\n}\n\n/**\n * A site plan's home page under its fewest sections (AGL-3660), as the plan\n * step's re-ask names it. A plan with no page at `/` — the owner's own home\n * stays — has no home to hold. `across` is the Free wall's section count, so\n * the re-ask says where the sections come from rather than tripping the wall.\n */\nexport function aiSiteThinHomeViolations(\n plan: Pick<AiBuildPlan, 'screens'>,\n options: { min: number; across: number | null },\n): Array<{ rule: null; code: string; message: string; paths: string[] }> {\n const index = plan.screens.findIndex(aiSitePlanIsHome)\n if (index < 0) return []\n const count = plan.screens[index].sections.length\n if (count >= options.min) return []\n const within =\n options.across === null\n ? ''\n : ` Keep the whole plan within ${options.across} sections: take them from the other page where you must.`\n return [\n {\n rule: null,\n code: AI_SITE_THIN_HOME_CODE,\n message: `The home page has ${count} ${count === 1 ? 'section' : 'sections'}, and a new site's home page reads as a full website with at least ${options.min}: ${AI_SITE_HOME_BANDS}.${within}`,\n paths: [`screens[${index}].sections`],\n },\n ]\n}\n\n/**\n * Sections a page is assumed to hold before a plan names them, for the\n * estimate a member reads when they ask for a scaffold. A declared\n * assumption, not a measurement: the plan's own section counts replace it\n * the moment the plan exists.\n */\nexport const AI_SITE_NOMINAL_SECTIONS = 5\n\n/**\n * The credits one pass is held against: the machine's\n * `AI_JOB_STEP_RESERVE_CREDITS`, declared here so the estimate stays a pure\n * number the console computes without the Admin SDK. `ai-site-job.spec.ts`\n * holds the two equal.\n */\nexport const AI_SITE_PASS_CREDITS = 50\n\n/** The longest a scaffold's scalar inputs may run; they are names, not copy. */\nexport const AI_SITE_INPUT_MAX_CHARS = 120\n\n/** The sites one agency batch may generate for in one request. */\nexport const AI_SITE_BATCH_MAX = 25\n\n/**\n * The sites a plan must hold before the org Sites page offers the batch at\n * all: the Agency and Advanced bands, which the plan's `hostLimit` is what\n * distinguishes.\n */\nexport const AI_SITE_BATCH_MIN_HOST_LIMIT = 25\n\nexport interface AiSiteJobInputs {\n /** What the business is, in a few words: the brief's subject. */\n businessType: string\n /**\n * Who the site is for, in a few words (AGL-2918); empty when nobody said.\n * The plan step puts it in front of the model on a line of its own, as it\n * does every other scalar here, so it narrows the pages a plan proposes\n * without a prompt of its own.\n */\n audience: string\n /**\n * The starter site whose shape the person liked (AGL-2918), by its\n * `STARTER_TEMPLATES` id; empty when they picked none.\n *\n * A hint carried as the id rather than the starter, because an id is what\n * the guided start's list, this door and the plan's line all agree on\n * without any of them loading a catalog of node maps. Unrecognized ids are\n * admitted for the same reason an unrecognized business type is: it is a\n * few words in a brief, not a lookup.\n */\n starter: string\n /**\n * The kind of site the person picked (AGL-3660), by its `AI_SITE_KINDS`\n * id; empty when nobody picked one, and the business type suggests it.\n * It sets the look the site is designed in and how its pages are arranged.\n */\n siteKind: string\n /** How many pages the member asked for. */\n pages: number\n /** The per-site variables an agency batch varies; empty when none was given. */\n businessName: string\n city: string\n brand: string\n /** Whether the scaffold also drafts a welcome email. */\n welcomeEmail: boolean\n /**\n * Where the contact form's submissions go (AGL-2918); `null` where nobody\n * said, which is every job created before the question existed and every\n * door that does not ask it.\n *\n * The one setting a new site owner actually needs made, and the one thing\n * about a contact form a model cannot know: whether a submission is a note\n * to read or a lead to chase is a decision about how the business runs. So\n * an answer BINDS the form step rather than hinting to it, and `null`\n * leaves the model's own proposal standing, exactly as it stood before.\n */\n submissions: AiSiteSubmissions | null\n /** The batch this job was created under (AGL-2911); `null` for a single site. */\n batchId: string | null\n}\n\n/**\n * Where a site's contact form sends what a visitor writes.\n *\n * Two, not three. The form step's own vocabulary has a third — a mailing\n * list — which it can only answer with a note, because the stored routing has\n * no place for a list; offering it as a question would be asking somebody to\n * pick an outcome the platform then explains it cannot store.\n */\nexport const AI_SITE_SUBMISSIONS = ['inbox', 'lead'] as const\n\nexport type AiSiteSubmissions = (typeof AI_SITE_SUBMISSIONS)[number]\n\n/**\n * What each answer to \"where do submissions go\" is called, and what it means.\n *\n * Here rather than beside the guided start's own questions, because it is not\n * only the guided start that asks: the agency batch asks the same thing of a\n * whole run (AGL-2918), and two surfaces wording one decision two ways is two\n * decisions. `ai-site-job.spec.ts` holds the list to {@link AI_SITE_SUBMISSIONS}.\n */\nexport const AI_SITE_SUBMISSION_CHOICES: ReadonlyArray<{\n id: AiSiteSubmissions\n label: string\n blurb: string\n}> = [\n {\n id: 'inbox',\n label: 'The Inbox',\n blurb: 'Every message is one to read and reply to.',\n },\n {\n id: 'lead',\n label: 'The Inbox, and CRM as a lead',\n blurb: 'Every message with an email address is also somebody to follow up.',\n },\n]\n\n/**\n * Which kind of email a scaffold's email unit is (AGL-2918), carried on the\n * derived job as `inputs.emailType`. The email step names the kind on the one\n * line it puts above the brief, and a scaffold was naming none.\n *\n * A key of the email step's own `AI_EMAIL_TYPES`, held here because neither\n * step may import the other: a scaffold delegates by job kind, and a\n * deployment that scaffolds is not necessarily one that has loaded the email\n * step. `ai-job-email-step.spec.ts` holds this key to that catalog.\n *\n * `reply` and not `welcome`. The five kinds a member picks are campaigns\n * somebody sends to an audience, and this is an answer to one person who\n * wrote in through the site; the nearest, `welcome`, is a label about signing\n * up, and a kind that misdescribes the email is worse than an absent one\n * because it is the first thing the model is told.\n */\nexport const AI_SITE_EMAIL_TYPE = 'reply'\n\n/**\n * What a site job's plan and every unit it builds are told about the\n * business's name (AGL-3596): that it is the name, used as written. Said on\n * the job's own turn, never in a cached system block, because it is one\n * site's. A model handed only what the business does named it itself —\n * \"Hillside Dog Grooming\" was built as \"Austin Paws Grooming\".\n */\nexport function aiSiteNameSentence(name: string): string {\n return `The business is named “${name}”: the site names it exactly that way, in the header, the footer, the copy and the search listing, and never by any other name.`\n}\n\n/** Where a job's inputs say submissions go, or `null` where they do not say. */\nexport function aiSiteSubmissions(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): AiSiteSubmissions | null {\n const value = inputs?.['submissions']\n return (AI_SITE_SUBMISSIONS as readonly unknown[]).includes(value)\n ? (value as AiSiteSubmissions)\n : null\n}\n\nconst ID_CHARS = /^[A-Za-z0-9_-]{1,64}$/\n\n/** A scaffold's inputs, or the sentence the door refuses them with. */\nexport function parseAiSiteJobInputs(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): AiSiteJobInputs | string {\n const text = (key: string): string | null => {\n const value = inputs?.[key]\n if (value === undefined || value === null || value === '') return ''\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length > AI_SITE_INPUT_MAX_CHARS ? null : trimmed\n }\n const businessType = text('businessType')\n if (businessType === null) {\n return `businessType must be text under ${AI_SITE_INPUT_MAX_CHARS} characters`\n }\n if (!businessType) return 'Say what kind of business the site is for'\n const businessName = text('businessName')\n const city = text('city')\n const brand = text('brand')\n const audience = text('audience')\n const starter = text('starter')\n // A kind this deployment does not know is nobody having picked one.\n const siteKind = aiSiteKind(inputs?.['siteKind'])?.id ?? ''\n for (const [key, value] of [\n ['businessName', businessName],\n ['city', city],\n ['brand', brand],\n ['audience', audience],\n ['starter', starter],\n ] as const) {\n if (value === null)\n return `${key} must be text under ${AI_SITE_INPUT_MAX_CHARS} characters`\n }\n const rawPages = inputs?.['pages']\n const pages =\n typeof rawPages === 'number' ? rawPages : Number(rawPages ?? NaN)\n // Read here across both bands; the door holds a workspace to its own\n // (`aiSitePagesRefusal`), since only it knows the workspace's plan.\n if (\n !Number.isInteger(pages) ||\n pages < AI_SITE_FREE_PAGES.min ||\n pages > AI_SITE_PAGES.max\n ) {\n return `pages must be a whole number from ${AI_SITE_FREE_PAGES.min} to ${AI_SITE_PAGES.max}`\n }\n // Where submissions go is admitted only as one of the two the form step\n // can actually bind; anything else is nobody having said, and the model\n // proposes as it always did rather than the door refusing the whole job.\n const submissions = aiSiteSubmissions(inputs)\n const rawBatch = inputs?.['batchId']\n const batchId =\n rawBatch === undefined || rawBatch === null || rawBatch === ''\n ? null\n : typeof rawBatch === 'string' && ID_CHARS.test(rawBatch)\n ? rawBatch\n : undefined\n if (batchId === undefined) return 'batchId is not a batch id'\n return {\n businessType,\n audience: audience as string,\n starter: starter as string,\n siteKind,\n pages,\n businessName: businessName as string,\n city: city as string,\n brand: brand as string,\n welcomeEmail: inputs?.['welcomeEmail'] !== false,\n submissions,\n batchId,\n }\n}\n\n/**\n * Why a workspace cannot ask for this many pages (AGL-3594), in a sentence a\n * member reads; `null` when it can. A Free workspace builds one or two, and a\n * paid one four to eight, as it always has. Refused rather than clamped: the\n * guided start offers only the band, so a request outside it was not made\n * there, and a job quietly building fewer pages than it was asked for is a\n * worse answer than a sentence saying why.\n */\nexport function aiSitePagesRefusal(pages: number, freeTaste: boolean | null | undefined): string | null {\n const band = aiSitePagesBand(freeTaste)\n if (pages >= band.min && pages <= band.max) return null\n return freeTaste\n ? `A Free workspace's AI site start builds ${AI_SITE_FREE_PAGES.min} or ${AI_SITE_FREE_PAGES.max} pages. ${AI_SITE_FREE_PAGES_NOTE}`\n : `A site is planned with ${band.min} to ${band.max} pages.`\n}\n\n/**\n * What the site itself is, as a step that is NOT the scaffold reads it off a\n * job's inputs (AGL-2918).\n *\n * A scaffold delegates unit by unit under a job derived from its own — a page\n * job, a form job — and the derived job carries the scaffold's inputs. So the\n * two answers that describe the site rather than one record of it are\n * readable by every delegated step, and a step that wants them does not have\n * to know it was delegated to.\n *\n * Lenient where {@link parseAiSiteJobInputs} is strict, because it reads the\n * inputs of jobs that are not scaffolds: a page job started from the Screens\n * page has no `businessType` and no `pages`, and that is not an error here —\n * it is a site nobody described, and the answer is two empty strings.\n */\nexport interface AiSiteWords {\n /** What kind of site it is; empty when the job's inputs do not say. */\n about: string\n /** Who it is for; empty when the job's inputs do not say. */\n audience: string\n}\n\n/** Whether either half of {@link AiSiteWords} says anything. */\nexport function aiSiteWordsSaidAnything(words: AiSiteWords): boolean {\n return Boolean(words.about || words.audience)\n}\n\n/** What a job's inputs say the site is, read defensively and trimmed to the input ceiling. */\nexport function aiSiteWords(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): AiSiteWords {\n const read = (key: string): string => {\n const value = inputs?.[key]\n if (typeof value !== 'string') return ''\n return value.replace(/\\s+/g, ' ').trim().slice(0, AI_SITE_INPUT_MAX_CHARS).trim()\n }\n return { about: read('businessType'), audience: read('audience') }\n}\n\n/**\n * What a scaffold builds for itself: the layout its pages render inside, the\n * form they place, the palette suggestion a member applies in the Theme\n * section, and the datasets its structured content is kept in (AGL-3616),\n * which the data plugin writes. Anything else a plan asks to create is a job\n * of its own.\n */\nexport const AI_SITE_CREATE_KINDS: readonly AiBuildPlanCreateKind[] = [\n 'layout',\n 'form',\n 'theme-change',\n 'dataset',\n]\n\n/** The most datasets one site start creates (AGL-3616). */\nexport const AI_SITE_DATASETS_MAX = 3\n\n/** The creations a scaffold cannot build, in the order the plan lists them, each named once. */\nexport function aiSitePlanPrerequisites(\n plan: AiBuildPlan,\n): Array<{ kind: AiBuildPlanCreateKind; name: string }> {\n const seen = new Set<string>()\n const prerequisites: Array<{ kind: AiBuildPlanCreateKind; name: string }> = []\n const add = (kind: AiBuildPlanCreateKind, name: string) => {\n const key = `${kind}:${name.toLowerCase()}`\n if (seen.has(key)) return\n seen.add(key)\n prerequisites.push({ kind, name })\n }\n for (const entry of plan.create) {\n if (!AI_SITE_CREATE_KINDS.includes(entry.kind)) add(entry.kind, entry.name)\n }\n // A reference the create list does not carry is refused by the plan rules\n // before a plan is kept: rule 2 for a screen's layout, rule 7 for anything\n // else (`plan-creation-undeclared`, AGL-3040). A plan confirmed before that\n // rule existed can still carry one. It is named as a component: the\n // reference carries no kind, and the refusal must say where one is made.\n for (const { name } of aiPlanUndeclaredRefs(plan)) add('component', name)\n return prerequisites\n}\n\n/**\n * Why a scaffold cannot build a plan of this SHAPE — the page band, a page's\n * sections, its addresses, its navigation — in a sentence a member reads;\n * `null` when the shape is one it builds. The plan step holds a plan to it\n * with a re-ask (AGL-3030), and the doors hold a confirmed plan to it again\n * through `aiSitePlanRefusal`.\n */\nexport function aiSitePlanShapeRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean } = {},\n): string | null {\n const { screens } = plan\n const band = aiSitePagesBand(options.freeTaste)\n if (screens.length < band.min || screens.length > band.max) {\n return `This plan builds ${screens.length} ${screens.length === 1 ? 'page' : 'pages'}, and ${\n options.freeTaste ? \"a Free workspace's site scaffold\" : 'a site scaffold'\n } builds ${band.min} to ${band.max}. Describe the site again.`\n }\n const slugs = new Set<string>()\n for (const screen of screens) {\n if (!screen.sections.length) {\n return `The page “${screen.title}” has no sections to build. Describe the site again.`\n }\n if (screen.sections.length > AI_SITE_MAX_SECTIONS) {\n return `The page “${screen.title}” has ${screen.sections.length} sections, and a scaffolded page holds ${AI_SITE_MAX_SECTIONS}. Describe the site again.`\n }\n const slug = screen.slug.trim().toLowerCase()\n if (slugs.has(slug)) {\n return `Two pages in this plan share the address ${screen.slug}. Describe the site again.`\n }\n slugs.add(slug)\n }\n if (!screens.some((screen) => screen.nav)) {\n return 'No page in this plan is in the site navigation. Describe the site again.'\n }\n const datasets = plan.create.filter((entry) => entry.kind === 'dataset').length\n if (datasets > AI_SITE_DATASETS_MAX) {\n return `This plan creates ${datasets} datasets, and a site scaffold creates at most ${AI_SITE_DATASETS_MAX}. Keep the others' items on their pages.`\n }\n return null\n}\n\n/**\n * Why a scaffold cannot build this plan, in a sentence a member reads when\n * confirming it; `null` when it can.\n */\nexport function aiSitePlanRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean } = {},\n): string | null {\n const shape = aiSitePlanShapeRefusal(plan, options)\n if (shape) return shape\n const prerequisites = aiSitePlanPrerequisites(plan)\n if (!prerequisites.length) return null\n const parts = prerequisites.map(\n ({ kind, name }) =>\n `the ${AI_BUILD_PLAN_CREATION_NOUNS[kind].noun} “${name}” ${AI_BUILD_PLAN_CREATION_NOUNS[kind].where}`,\n )\n const listed =\n parts.length === 1\n ? parts[0]\n : `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`\n return `This site needs what the workspace does not have yet. Create ${listed}, then describe the site again.`\n}\n\n/** What the estimate counts a plan in: whether a welcome email follows, and the creations the job builds. */\nexport interface AiPlanPassOptions {\n welcomeEmail?: boolean\n /** The creation kinds the job builds itself; a scaffold's when absent. */\n creates?: readonly AiBuildPlanCreateKind[]\n /** Each page and creation written on its own (`aiStandaloneScreenCreditRange`), not as a site start’s (AGL-3722). */\n standalonePages?: boolean\n}\n\n/**\n * Whether a creation is built with no model: a dataset a form of the plan\n * writes to (AGL-3616) starts empty, designed from its planned fields, so it\n * is no pass of the estimate.\n */\nfunction aiPlanCreationIsModelFree(plan: Pick<AiBuildPlan, 'create'>, entry: AiBuildPlan['create'][number]): boolean {\n return entry.kind === 'dataset' && aiPlanFormDatasetNames(plan).has(entry.name.trim().toLowerCase())\n}\n\n/**\n * The passes a plan implies: one per section of every screen, one more per\n * screen for its search listing and its draft, and one for each thing the\n * plan creates that the job builds. What the estimate is counted in.\n */\nexport function aiPlanPasses(plan: AiBuildPlan, options: AiPlanPassOptions = {}): number {\n const screens = plan.screens.reduce(\n (total, screen) => total + screen.sections.length + 1,\n 0,\n )\n const creates = options.creates ?? AI_SITE_CREATE_KINDS\n const creations = plan.create.filter((entry) => creates.includes(entry.kind) && !aiPlanCreationIsModelFree(plan, entry)).length\n return screens + creations + (options.welcomeEmail ? 1 : 0)\n}\n\n/**\n * About what a plan costs to build, in credits. An ESTIMATE: the nominal\n * credits the machine holds per step, times the passes the plan implies.\n * What each pass actually costs is its model's tokens, recorded on the job\n * as it runs.\n */\nexport function aiPlanCreditEstimate(plan: AiBuildPlan, options: AiPlanPassOptions = {}): number {\n return aiPlanPasses(plan, options) * AI_SITE_PASS_CREDITS\n}\n\n/**\n * About what a job of this kind costs to build from its plan (AGL-3031): a\n * page job counts the layout, forms and components it builds before its\n * page; a template, layout, component, form or email job counts its own\n * record and every creation it builds before it (AGL-3143 §15); and a\n * scaffold counts what it builds. The figure the proposal shows beside\n * Confirm, and the hold a confirmation takes.\n */\nexport function aiJobPlanCreditEstimate(kind: string, plan: AiBuildPlan): number {\n const creates =\n kind === 'page' ? AI_PAGE_CREATE_KINDS : AI_JOB_CREATE_KINDS[kind as keyof typeof AI_JOB_CREATE_KINDS]\n return aiPlanCreditEstimate(plan, creates ? { creates } : {})\n}\n\n/**\n * About what a scaffold of this many pages costs, before a plan names its\n * sections: the same arithmetic on the nominal section count, plus the plan\n * step that proposes it. Shown where a member asks for a scaffold.\n */\nexport function aiSiteCreditEstimate(\n pages: number,\n options: { welcomeEmail?: boolean; siteKind?: string | null } = {},\n): number {\n const screens = Math.max(0, Math.floor(pages))\n const content = aiSiteStartContent(options.siteKind)\n const passes =\n 1 +\n screens * (AI_SITE_NOMINAL_SECTIONS + 1) +\n 2 +\n (options.welcomeEmail ? 1 : 0) +\n (content === 'products' ? 1 : content === 'posts' ? AI_SITE_START_POSTS : 0)\n return passes * AI_SITE_PASS_CREDITS\n}\n\n/** How many first posts a paid blog start writes, one pass each (`AI_SITE_POSTS`, held equal by `ai-site-job.spec.ts`). */\nexport const AI_SITE_START_POSTS = 3\n\n/**\n * The first content a paid start of this kind writes (AGL-3676): a store's\n * first products, a blog's first posts, or nothing. `aiSiteContentPart`'s\n * answer for a paid start, by the kind's id.\n */\nexport function aiSiteStartContent(siteKind: string | null | undefined): 'posts' | 'products' | null {\n if (siteKind === 'store') return 'products'\n if (siteKind === 'blog') return 'posts'\n return null\n}\n\n/**\n * The measured cost of one creation a plan builds (AGL-3722): a layout's or\n * a form's as measured, a theme's as the site start's look measured, and\n * any other kind at the stand-in a single-answer creation is priced at.\n * `standalone` for one written on its own — a build's, a page job's — rather\n * than inside a site start's warm run.\n */\nexport function aiCreationMeasuredCredits(kind: string, options: { standalone?: boolean } = {}): AiMeasuredCredits {\n if (kind === 'layout') {\n return options.standalone ? AI_MEASURED_STANDALONE_CREATION_CREDITS.layout : AI_MEASURED_UNIT_CREDITS.layout\n }\n if (kind === 'form') return AI_MEASURED_UNIT_CREDITS.form\n if (kind === 'theme' || kind === 'theme-change') return AI_MEASURED_UNIT_CREDITS.theme\n return AI_MEASURED_PASS_CREDITS\n}\n\n/** A planned page's range: its sections scaled around the measured page, its ceiling one pass a section and one for its listing. */\nexport function aiScreenCreditRange(sections: number): AiCreditRange {\n return aiCreditRangeOf(aiMeasuredPageCredits(sections), (Math.max(0, sections) + 1) * AI_SITE_PASS_CREDITS)\n}\n\n/**\n * A page written on its own — an Assist build's, a page job's — as a range\n * (AGL-3722): a fixed cost and one per section as such pages measured\n * (`AI_MEASURED_STANDALONE_PAGE`), never a site start's later, cheaper\n * pages; the ceiling as `aiScreenCreditRange`'s.\n */\nexport function aiStandaloneScreenCreditRange(sections: number): AiCreditRange {\n return aiCreditRangeOf(\n aiMeasuredStandalonePageCredits(sections),\n (Math.max(0, sections) + 1) * AI_SITE_PASS_CREDITS,\n )\n}\n\n/**\n * What a plan is likely to cost, its p90 and its ceiling (AGL-3722): the\n * same units `aiPlanCreditEstimate` counts, each at what it measured; the\n * ceiling IS `aiPlanCreditEstimate`.\n */\nexport function aiPlanCreditRange(plan: AiBuildPlan, options: AiPlanPassOptions = {}): AiCreditRange {\n const creates = options.creates ?? AI_SITE_CREATE_KINDS\n let range = AI_CREDIT_RANGE_ZERO\n const screenRange = options.standalonePages ? aiStandaloneScreenCreditRange : aiScreenCreditRange\n for (const screen of plan.screens) range = aiCreditRangeAdd(range, screenRange(screen.sections.length))\n for (const entry of plan.create) {\n if (!creates.includes(entry.kind) || aiPlanCreationIsModelFree(plan, entry)) continue\n range = aiCreditRangeAdd(\n range,\n aiCreditRangeOf(aiCreationMeasuredCredits(entry.kind, { standalone: options.standalonePages }), AI_SITE_PASS_CREDITS),\n )\n }\n if (options.welcomeEmail) range = aiCreditRangeAdd(range, aiCreditRangeOf(AI_MEASURED_PASS_CREDITS, AI_SITE_PASS_CREDITS))\n return aiCreditRangeOrdered(range)\n}\n\n/**\n * `aiJobPlanCreditEstimate` as a range (AGL-3722): the same kinds, each at\n * what it measured. Only a site start writes its pages in one warm run; every\n * other kind's page is written on its own.\n */\nexport function aiJobPlanCreditRange(kind: string, plan: AiBuildPlan): AiCreditRange {\n const creates =\n kind === 'page' ? AI_PAGE_CREATE_KINDS : AI_JOB_CREATE_KINDS[kind as keyof typeof AI_JOB_CREATE_KINDS]\n return aiPlanCreditRange(plan, { ...(creates ? { creates } : {}), standalonePages: kind !== 'site' })\n}\n\n/**\n * A paid site start's range before its plan (AGL-3722): the plan, its look,\n * layout and form, and each page at the nominal sections, as measured; the\n * ceiling is `aiSiteCreditEstimate`.\n */\nexport function aiSiteCreditRange(\n pages: number,\n options: { welcomeEmail?: boolean; siteKind?: string | null } = {},\n): AiCreditRange {\n const count = Math.max(0, Math.floor(pages))\n // A paid start plans and writes on the paid routing, measured apart (AGL-3739).\n const { plan, theme, layout, form, page, email, products } = AI_MEASURED_PAID_SITE_CREDITS\n const content = aiSiteStartContent(options.siteKind)\n // A blog's posts have no measurement of their own yet: the stand-in pass.\n const parts: AiMeasuredCredits[] = [\n plan,\n theme,\n layout,\n form,\n ...Array.from({ length: count }, () => page),\n ...(options.welcomeEmail ? [email] : []),\n ...(content === 'products' ? [products] : content === 'posts' ? [AI_MEASURED_PASS_CREDITS] : []),\n ]\n return aiCreditRangeOrdered({\n likely: parts.reduce((total, part) => total + part.median, 0),\n p90: parts.reduce((total, part) => total + part.p90, 0),\n ceiling: aiSiteCreditEstimate(count, options),\n })\n}\n"],"names":["aiSiteKind","AI_BUILD_PLAN_CREATION_NOUNS","aiPlanFormDatasetNames","aiPlanUndeclaredRefs","AI_JOB_CREATE_KINDS","AI_PAGE_CREATE_KINDS","FREE_AI_TASTE_CREDITS_PER_MONTH","AI_CREDIT_RANGE_ZERO","AI_MEASURED_PAID_SITE_CREDITS","AI_MEASURED_PASS_CREDITS","AI_MEASURED_STANDALONE_CREATION_CREDITS","AI_MEASURED_UNIT_CREDITS","aiCreditRangeAdd","aiCreditRangeOf","aiCreditRangeOrdered","aiCreditsPromptFor","aiMeasuredPageCredits","aiMeasuredStandalonePageCredits","AI_SITE_PAGES","min","max","AI_SITE_FREE_PAGES","aiSitePagesBand","freeTaste","AI_JOB_AUTO_CONFIRM_INPUT","AI_SITE_FREE_PAGES_NOTE","AI_SITE_PLAN_MAX_TOKENS","free","paid","AI_FREE_SITE_WORST_CASE_CREDITS","plan","look","layout","form","page","section","retry","listing","AI_FREE_SITE_MAX_SECTIONS","aiFreeSiteWorstCaseCredits","creations","sections","credits","pages","Math","floor","layouts","forms","aiFreeSiteSectionsWithin","taste","before","Number","POSITIVE_INFINITY","AI_SITE_MAX_SECTIONS","aiFreeSiteCreditEstimate","aiFreeCreditsResetOn","now","next","Date","UTC","getUTCFullYear","getUTCMonth","toISOString","slice","aiFreeCreditsResetLabel","resetsOn","at","isFinite","getTime","toLocaleDateString","month","day","timeZone","aiFreeSiteCreditRange","count","aiSiteStartMeasured","ceiling","theme","AI_SITE_NOMINAL_SECTIONS","likely","median","p90","AI_SITE_HOME_FIRST_LABEL","aiFreeSitePrompt","left","home","label","aiFreeCreditsNoneLeftText","AI_SITE_HOME_MIN_SECTIONS","AI_SITE_BLOG_NAME","AI_SITE_BLOG_SLUGS","firstSegment","slug","trim","replace","split","toLowerCase","aiSiteBlogSlug","screens","taken","Set","map","screen","filter","Boolean","find","has","AI_SITE_BLOG_NAV_ID","aiSiteBlogNavPage","id","href","aiSiteIsBlogStandIn","aiSitePlanIsHome","includes","BLOG_PAGE_WORDS","test","title","aiSitePlanWithoutBlogStandIns","standIns","AI_SITE_BLOG_PAGE_CODE","aiSiteBlogStandInViolations","flatMap","index","length","names","join","rule","code","message","paths","AI_SITE_EMPTY_GALLERY_CODE","AI_SITE_GALLERY_MIN_ITEMS","AI_SITE_GALLERY_MAX_ITEMS","GALLERY_SECTION","FRAMING_SECTION","aiSiteSectionShowsWork","name","AI_SITE_GALLERY_SENTENCE","aiSiteEmptyGalleryViolations","thin","screenIndex","sectionIndex","items","path","entry","AI_SITE_THIN_HOME_CODE","AI_SITE_HOME_BANDS","aiSiteHomeMinSections","input","across","others","aiSiteFullPlanSentence","lead","homeHi","otherHi","otherLo","totalLo","range","lo","hi","pagesWord","aiSiteThinHomeViolations","options","findIndex","within","AI_SITE_PASS_CREDITS","AI_SITE_INPUT_MAX_CHARS","AI_SITE_BATCH_MAX","AI_SITE_BATCH_MIN_HOST_LIMIT","AI_SITE_SUBMISSIONS","AI_SITE_SUBMISSION_CHOICES","blurb","AI_SITE_EMAIL_TYPE","aiSiteNameSentence","aiSiteSubmissions","inputs","value","ID_CHARS","parseAiSiteJobInputs","text","key","undefined","trimmed","businessType","businessName","city","brand","audience","starter","siteKind","rawPages","NaN","isInteger","submissions","rawBatch","batchId","welcomeEmail","aiSitePagesRefusal","band","aiSiteWordsSaidAnything","words","about","aiSiteWords","read","AI_SITE_CREATE_KINDS","AI_SITE_DATASETS_MAX","aiSitePlanPrerequisites","seen","prerequisites","add","kind","push","create","aiSitePlanShapeRefusal","slugs","some","nav","datasets","aiSitePlanRefusal","shape","parts","noun","where","listed","aiPlanCreationIsModelFree","aiPlanPasses","reduce","total","creates","aiPlanCreditEstimate","aiJobPlanCreditEstimate","aiSiteCreditEstimate","content","aiSiteStartContent","passes","AI_SITE_START_POSTS","aiCreationMeasuredCredits","standalone","aiScreenCreditRange","aiStandaloneScreenCreditRange","aiPlanCreditRange","screenRange","standalonePages","aiJobPlanCreditRange","aiSiteCreditRange","email","products","Array","from","part"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,UAAU,QAAQ,qBAAiB;AAC5C,SACEC,4BAA4B,EAC5BC,sBAAsB,EACtBC,oBAAoB,QAGf,qBAAiB;AACxB,SAASC,mBAAmB,QAAQ,wBAAoB;AACxD,SAASC,oBAAoB,QAAQ,mBAAe;AACpD,SAASC,+BAA+B,QAAQ,0BAAsB;AACtE,SACEC,oBAAoB,EACpBC,6BAA6B,EAC7BC,wBAAwB,EACxBC,uCAAuC,EACvCC,wBAAwB,EACxBC,gBAAgB,EAChBC,eAAe,EACfC,oBAAoB,EACpBC,kBAAkB,EAClBC,qBAAqB,EACrBC,+BAA+B,QAI1B,0BAAsB;AAE7B;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GAED,+EAA+E,GAC/E,OAAO,MAAMC,gBAAgB;IAAEC,KAAK;IAAGC,KAAK;AAAE,EAAU;AAExD;;;;;;CAMC,GACD,OAAO,MAAMC,qBAAqB;IAAEF,KAAK;IAAGC,KAAK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,MAAM,EAAE;QAC3DC,KAAK2I,MAAMM,MAAM,CAAC,CAACC,OAAOsB,OAAStB,QAAQsB,KAAKxK,GAAG,EAAE;QACrDL,SAAS2J,qBAAqB7J,OAAOwF;IACvC;AACF"}
@@ -130,6 +130,11 @@ export interface AiDoctrineTreeContext extends AiNodeTreeContext {
130
130
  * to when the site has none for what it promises. Absent: none is known.
131
131
  */
132
132
  homeScreenIds?: readonly string[];
133
+ /**
134
+ * The home pages' own titles (AGL-3760): a link home under one of them says
135
+ * where it goes in the site's language, as "Inicio" does on a Spanish site.
136
+ */
137
+ homeLabels?: readonly string[];
133
138
  /**
134
139
  * The site's pages that place its form, by id (AGL-3729): where a link whose
135
140
  * words ask a visitor to get in touch (`aiAsksToGetInTouch`) does what it
@@ -266,7 +271,9 @@ export declare function detectLayoutRegions(tree: AiDoctrineTree, outputKind: Ai
266
271
  /**
267
272
  * Rule 3. A form on a page is a Form bound by id to a form built on the
268
273
  * Forms page — fields, validation, consent and routing kept in one place.
269
- * Loose fields, an unbound Form, and fields drawn inside a bound Form (which
274
+ * Loose fields — a Form Field, or any of MUI's answer elements (an Input,
275
+ * Select, Radio Group, Checkbox or Rating) — an unbound Form, and fields
276
+ * drawn inside a bound Form (which
270
277
  * the page never renders: the placed form's own design replaces them) are
271
278
  * refused. A form's own design is the one place fields are drawn.
272
279
  *
@@ -509,7 +516,7 @@ export declare function aiAsksToGetInTouch(label: string): boolean;
509
516
  * The root is never taken out. A tree with nothing to repair comes back as
510
517
  * the same object; a node that is changed is copied, never edited in place.
511
518
  */
512
- export declare function aiSettleUnrelatedScreenLinks<T extends AiDoctrineTree>(tree: T, outputKind: AiOutputKind, context?: Pick<AiDoctrineTreeContext, 'homeScreenIds' | 'formScreenIds'> & {
519
+ export declare function aiSettleUnrelatedScreenLinks<T extends AiDoctrineTree>(tree: T, outputKind: AiOutputKind, context?: Pick<AiDoctrineTreeContext, 'homeScreenIds' | 'formScreenIds' | 'homeLabels'> & {
513
520
  /** The page being checked, by every id it goes by: a link never goes to itself. */
514
521
  ownScreenIds?: readonly string[];
515
522
  }): T;
@@ -524,7 +531,7 @@ export declare function aiSettleUnrelatedScreenLinks<T extends AiDoctrineTree>(t
524
531
  * not say home is refused, with a re-ask to link the screen that does what it
525
532
  * says, or to leave the link out.
526
533
  */
527
- export declare function detectUnrelatedScreenLinks(tree: AiDoctrineTree, outputKind: AiOutputKind, context?: Pick<AiDoctrineTreeContext, 'homeScreenIds' | 'formScreenIds'>): AiDoctrineViolation[];
534
+ export declare function detectUnrelatedScreenLinks(tree: AiDoctrineTree, outputKind: AiOutputKind, context?: Pick<AiDoctrineTreeContext, 'homeScreenIds' | 'formScreenIds' | 'homeLabels'>): AiDoctrineViolation[];
528
535
  /**
529
536
  * Rule 10, for a link that goes nowhere (AGL-3072). A Button or a Screen Link
530
537
  * goes where its `screenId` or its `href` says, and those are the only
@@ -907,6 +914,21 @@ export declare function aiSettlePlanLayouts(plan: AiBuildPlan, inventory: AiSite
907
914
  * checks' to settle or refuse.
908
915
  */
909
916
  export declare function aiSettlePlanLayoutRegionSections(plan: AiBuildPlan, inventory: AiSiteInventory | null): AiBuildPlan;
917
+ /**
918
+ * A section that shows the work — a gallery, a portfolio, selected works, by
919
+ * the name `aiSiteSectionShowsWork` reads — planned with fewer pieces than
920
+ * the job's `galleryMinItems` is raised to it before the rules read the plan
921
+ * (AGL-3754). The site start's `plan-empty-gallery` refusal names one answer,
922
+ * "plan it with three to six items", and the fewest is the one that keeps
923
+ * the plan's own count closest: a section's items move no section cap, Free
924
+ * wall or credit figure, which count sections and pages.
925
+ *
926
+ * A section the rule reads as one item of a list split into sections is
927
+ * left for rule 1's re-ask to join, as the Free wall's trim leaves it: raised
928
+ * here, it would hide the split. A job that sets no `galleryMinItems` (every
929
+ * job but a site start) is returned unchanged.
930
+ */
931
+ export declare function aiSettlePlanGalleries(plan: AiBuildPlan, inventory: AiSiteInventory | null, capabilities?: AiPlanCapabilities | null): AiBuildPlan;
910
932
  /** The contact form a plan is given when a section collects answers and the plan makes no form. */
911
933
  export declare const AI_PLAN_SETTLED_FORM: {
912
934
  readonly name: "Contact form";
@@ -15,6 +15,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */ import { sanitizeAuthorHtml } from "@aglyn/aglyn/app-utils/author-html";
18
+ import { isFormInputNode } from "@aglyn/aglyn/app-utils/forms";
18
19
  import { formatBytes, measureNodeMap, nodeMapBytes } from "@aglyn/aglyn/app-utils/measure-node-map";
19
20
  import { MEDIA_CDN_VARIANT_WIDTHS, parseMediaRef } from "@aglyn/aglyn/app-utils/media-ref";
20
21
  import { ESTIMATED_PAGE_TRANSFER_BYTES } from "@aglyn/aglyn/app-utils/plan-entitlements";
@@ -25,7 +26,7 @@ import { parseBreakpointSpan } from "@aglyn/shared-data-enums/breakpoint-span";
25
26
  import { renderEmailHtml } from "@aglyn/shared-util-email/email-render";
26
27
  import { AI_BUILD_PLAN_CREATION_NOUNS, AI_BUILD_PLAN_EMBED_HOST_NAMES, AI_BUILD_PLAN_LIMITS, AI_PLAN_ASKS_FOR_VIDEO, aiEmbedHostOf, aiEmbedVideoKey, AI_PLAN_DATASET_ITEM_OP, aiPlanCreateFor, aiPlanFormDatasetNames, aiPlanItemFor, aiPlanSlugKey, aiPlanUndeclaredRefs, isAiPlanNewRef } from "../model/ai-build-plan.js";
27
28
  import { aiCreationNoun, aiPlanCanPlaceForm, aiPlanUncreatable, aiPlanUncreatableKind } from "../model/ai-plan-capabilities.js";
28
- import { aiFreeSiteSectionsWithin, aiSiteHomeMinSections, aiSitePlanIsHome } from "../model/ai-site-job.js";
29
+ import { aiFreeSiteSectionsWithin, aiSiteHomeMinSections, aiSitePlanIsHome, aiSiteSectionShowsWork } from "../model/ai-site-job.js";
29
30
  import { aiLayoutIsShopPage, aiLayoutShopGridSection } from "../layout-language/ai-layout-listings.js";
30
31
  import { aiStorefrontSays } from "../layout-language/ai-layout-storefront.js";
31
32
  import { AI_INSTANCE_REF_PROP, validateAiNodeTree } from "./ai-node-tree.js";
@@ -527,7 +528,9 @@ export const AI_LAYOUT_REGION_NAMES = Object.keys(AI_LAYOUT_REGIONS);
527
528
  /**
528
529
  * Rule 3. A form on a page is a Form bound by id to a form built on the
529
530
  * Forms page — fields, validation, consent and routing kept in one place.
530
- * Loose fields, an unbound Form, and fields drawn inside a bound Form (which
531
+ * Loose fields — a Form Field, or any of MUI's answer elements (an Input,
532
+ * Select, Radio Group, Checkbox or Rating) — an unbound Form, and fields
533
+ * drawn inside a bound Form (which
531
534
  * the page never renders: the placed form's own design replaces them) are
532
535
  * refused. A form's own design is the one place fields are drawn.
533
536
  *
@@ -543,7 +546,7 @@ export const AI_LAYOUT_REGION_NAMES = Object.keys(AI_LAYOUT_REGIONS);
543
546
  const unbound = [];
544
547
  const shadowed = [];
545
548
  for (const visit of walkTree(tree)){
546
- if (visit.node.componentId === 'formField' && !hasAncestor(tree, visit, (node)=>node.componentId === 'form')) {
549
+ if (isFormInputNode(visit.node) && !hasAncestor(tree, visit, (node)=>node.componentId === 'form')) {
547
550
  loose.push(visit.id);
548
551
  }
549
552
  if (visit.node.componentId === 'form') {
@@ -1843,6 +1846,7 @@ const GRID = 'muiGrid';
1843
1846
  ];
1844
1847
  }
1845
1848
  /** A link's words that say it goes home. */ const HOME_WORDS = /\bhome(?:\s?page)?\b/i;
1849
+ /** A label's words, lowercase, for comparing one label with another. */ const labelWords = (label)=>label.toLowerCase().split(RegExp("[^\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376-\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E-\\u066F\\u0671-\\u06D3\\u06D5\\u06E5-\\u06E6\\u06EE-\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4-\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC-\\u09DD\\u09DF-\\u09E1\\u09F0-\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F-\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32-\\u0A33\\u0A35-\\u0A36\\u0A38-\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2-\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0-\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F-\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32-\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C-\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99-\\u0B9A\\u0B9C\\u0B9E-\\u0B9F\\u0BA3-\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C-\\u0C5D\\u0C60-\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0-\\u0CE1\\u0CF1-\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32-\\u0E33\\u0E40-\\u0E46\\u0E81-\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2-\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065-\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16F1-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u1884\\u1887-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE-\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5-\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183-\\u2184\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3006\\u3031-\\u3035\\u303B-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A-\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6E5\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD-\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5-\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40-\\uFB41\\uFB43-\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u{10000}-\\u{1000B}\\u{1000D}-\\u{10026}\\u{10028}-\\u{1003A}\\u{1003C}-\\u{1003D}\\u{1003F}-\\u{1004D}\\u{10050}-\\u{1005D}\\u{10080}-\\u{100FA}\\u{10280}-\\u{1029C}\\u{102A0}-\\u{102D0}\\u{10300}-\\u{1031F}\\u{1032D}-\\u{10340}\\u{10342}-\\u{10349}\\u{10350}-\\u{10375}\\u{10380}-\\u{1039D}\\u{103A0}-\\u{103C3}\\u{103C8}-\\u{103CF}\\u{10400}-\\u{1049D}\\u{104B0}-\\u{104D3}\\u{104D8}-\\u{104FB}\\u{10500}-\\u{10527}\\u{10530}-\\u{10563}\\u{10570}-\\u{1057A}\\u{1057C}-\\u{1058A}\\u{1058C}-\\u{10592}\\u{10594}-\\u{10595}\\u{10597}-\\u{105A1}\\u{105A3}-\\u{105B1}\\u{105B3}-\\u{105B9}\\u{105BB}-\\u{105BC}\\u{105C0}-\\u{105F3}\\u{10600}-\\u{10736}\\u{10740}-\\u{10755}\\u{10760}-\\u{10767}\\u{10780}-\\u{10785}\\u{10787}-\\u{107B0}\\u{107B2}-\\u{107BA}\\u{10800}-\\u{10805}\\u{10808}\\u{1080A}-\\u{10835}\\u{10837}-\\u{10838}\\u{1083C}\\u{1083F}-\\u{10855}\\u{10860}-\\u{10876}\\u{10880}-\\u{1089E}\\u{108E0}-\\u{108F2}\\u{108F4}-\\u{108F5}\\u{10900}-\\u{10915}\\u{10920}-\\u{10939}\\u{10940}-\\u{10959}\\u{10980}-\\u{109B7}\\u{109BE}-\\u{109BF}\\u{10A00}\\u{10A10}-\\u{10A13}\\u{10A15}-\\u{10A17}\\u{10A19}-\\u{10A35}\\u{10A60}-\\u{10A7C}\\u{10A80}-\\u{10A9C}\\u{10AC0}-\\u{10AC7}\\u{10AC9}-\\u{10AE4}\\u{10B00}-\\u{10B35}\\u{10B40}-\\u{10B55}\\u{10B60}-\\u{10B72}\\u{10B80}-\\u{10B91}\\u{10C00}-\\u{10C48}\\u{10C80}-\\u{10CB2}\\u{10CC0}-\\u{10CF2}\\u{10D00}-\\u{10D23}\\u{10D4A}-\\u{10D65}\\u{10D6F}-\\u{10D85}\\u{10E80}-\\u{10EA9}\\u{10EB0}-\\u{10EB1}\\u{10EC2}-\\u{10EC7}\\u{10F00}-\\u{10F1C}\\u{10F27}\\u{10F30}-\\u{10F45}\\u{10F70}-\\u{10F81}\\u{10FB0}-\\u{10FC4}\\u{10FE0}-\\u{10FF6}\\u{11003}-\\u{11037}\\u{11071}-\\u{11072}\\u{11075}\\u{11083}-\\u{110AF}\\u{110D0}-\\u{110E8}\\u{11103}-\\u{11126}\\u{11144}\\u{11147}\\u{11150}-\\u{11172}\\u{11176}\\u{11183}-\\u{111B2}\\u{111C1}-\\u{111C4}\\u{111DA}\\u{111DC}\\u{11200}-\\u{11211}\\u{11213}-\\u{1122B}\\u{1123F}-\\u{11240}\\u{11280}-\\u{11286}\\u{11288}\\u{1128A}-\\u{1128D}\\u{1128F}-\\u{1129D}\\u{1129F}-\\u{112A8}\\u{112B0}-\\u{112DE}\\u{11305}-\\u{1130C}\\u{1130F}-\\u{11310}\\u{11313}-\\u{11328}\\u{1132A}-\\u{11330}\\u{11332}-\\u{11333}\\u{11335}-\\u{11339}\\u{1133D}\\u{11350}\\u{1135D}-\\u{11361}\\u{11380}-\\u{11389}\\u{1138B}\\u{1138E}\\u{11390}-\\u{113B5}\\u{113B7}\\u{113D1}\\u{113D3}\\u{11400}-\\u{11434}\\u{11447}-\\u{1144A}\\u{1145F}-\\u{11461}\\u{11480}-\\u{114AF}\\u{114C4}-\\u{114C5}\\u{114C7}\\u{11580}-\\u{115AE}\\u{115D8}-\\u{115DB}\\u{11600}-\\u{1162F}\\u{11644}\\u{11680}-\\u{116AA}\\u{116B8}\\u{11700}-\\u{1171A}\\u{11740}-\\u{11746}\\u{11800}-\\u{1182B}\\u{118A0}-\\u{118DF}\\u{118FF}-\\u{11906}\\u{11909}\\u{1190C}-\\u{11913}\\u{11915}-\\u{11916}\\u{11918}-\\u{1192F}\\u{1193F}\\u{11941}\\u{119A0}-\\u{119A7}\\u{119AA}-\\u{119D0}\\u{119E1}\\u{119E3}\\u{11A00}\\u{11A0B}-\\u{11A32}\\u{11A3A}\\u{11A50}\\u{11A5C}-\\u{11A89}\\u{11A9D}\\u{11AB0}-\\u{11AF8}\\u{11BC0}-\\u{11BE0}\\u{11C00}-\\u{11C08}\\u{11C0A}-\\u{11C2E}\\u{11C40}\\u{11C72}-\\u{11C8F}\\u{11D00}-\\u{11D06}\\u{11D08}-\\u{11D09}\\u{11D0B}-\\u{11D30}\\u{11D46}\\u{11D60}-\\u{11D65}\\u{11D67}-\\u{11D68}\\u{11D6A}-\\u{11D89}\\u{11D98}\\u{11DB0}-\\u{11DDB}\\u{11EE0}-\\u{11EF2}\\u{11F02}\\u{11F04}-\\u{11F10}\\u{11F12}-\\u{11F33}\\u{11FB0}\\u{12000}-\\u{12399}\\u{12480}-\\u{12543}\\u{12F90}-\\u{12FF0}\\u{13000}-\\u{1342F}\\u{13441}-\\u{13446}\\u{13460}-\\u{143FA}\\u{14400}-\\u{14646}\\u{16100}-\\u{1611D}\\u{16800}-\\u{16A38}\\u{16A40}-\\u{16A5E}\\u{16A70}-\\u{16ABE}\\u{16AD0}-\\u{16AED}\\u{16B00}-\\u{16B2F}\\u{16B40}-\\u{16B43}\\u{16B63}-\\u{16B77}\\u{16B7D}-\\u{16B8F}\\u{16D40}-\\u{16D6C}\\u{16E40}-\\u{16E7F}\\u{16EA0}-\\u{16EB8}\\u{16EBB}-\\u{16ED3}\\u{16F00}-\\u{16F4A}\\u{16F50}\\u{16F93}-\\u{16F9F}\\u{16FE0}-\\u{16FE1}\\u{16FE3}\\u{16FF2}-\\u{16FF3}\\u{17000}-\\u{18CD5}\\u{18CFF}-\\u{18D1E}\\u{18D80}-\\u{18DF2}\\u{1AFF0}-\\u{1AFF3}\\u{1AFF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6-\\u0CEF\\u0D58-\\u0D5E\\u0D66-\\u0D78\\u0DE6-\\u0DEF\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F33\\u1040-\\u1049\\u1090-\\u1099\\u1369-\\u137C\\u16EE-\\u16F0\\u17E0-\\u17E9\\u17F0-\\u17F9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19DA\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\u2070\\u2074-\\u2079\\u2080-\\u2089\\u2150-\\u2182\\u2185-\\u2189\\u2460-\\u249B\\u24EA-\\u24FF\\u2776-\\u2793\\u2CFD\\u3007\\u3021-\\u3029\\u3038-\\u303A\\u3192-\\u3195\\u3220-\\u3229\\u3248-\\u324F\\u3251-\\u325F\\u3280-\\u3289\\u32B1-\\u32BF\\uA620-\\uA629\\uA6E6-\\uA6EF\\uA830-\\uA835\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uA9F0-\\uA9F9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19\\u{10107}-\\u{10133}\\u{10140}-\\u{10178}\\u{1018A}-\\u{1018B}\\u{102E1}-\\u{102FB}\\u{10320}-\\u{10323}\\u{10341}\\u{1034A}\\u{103D1}-\\u{103D5}\\u{104A0}-\\u{104A9}\\u{10858}-\\u{1085F}\\u{10879}-\\u{1087F}\\u{108A7}-\\u{108AF}\\u{108FB}-\\u{108FF}\\u{10916}-\\u{1091B}\\u{109BC}-\\u{109BD}\\u{109C0}-\\u{109CF}\\u{109D2}-\\u{109FF}\\u{10A40}-\\u{10A48}\\u{10A7D}-\\u{10A7E}\\u{10A9D}-\\u{10A9F}\\u{10AEB}-\\u{10AEF}\\u{10B58}-\\u{10B5F}\\u{10B78}-\\u{10B7F}\\u{10BA9}-\\u{10BAF}\\u{10CFA}-\\u{10CFF}\\u{10D30}-\\u{10D39}\\u{10D40}-\\u{10D49}\\u{10E60}-\\u{10E7E}\\u{10F1D}-\\u{10F26}\\u{10F51}-\\u{10F54}\\u{10FC5}-\\u{10FCB}\\u{11052}-\\u{1106F}\\u{110F0}-\\u{110F9}\\u{11136}-\\u{1113F}\\u{111D0}-\\u{111D9}\\u{111E1}-\\u{111F4}\\u{112F0}-\\u{112F9}\\u{11450}-\\u{11459}\\u{114D0}-\\u{114D9}\\u{11650}-\\u{11659}\\u{116C0}-\\u{116C9}\\u{116D0}-\\u{116E3}\\u{11730}-\\u{1173B}\\u{118E0}-\\u{118F2}\\u{11950}-\\u{11959}\\u{11BF0}-\\u{11BF9}\\u{11C50}-\\u{11C6C}\\u{11D50}-\\u{11D59}\\u{11DA0}-\\u{11DA9}\\u{11DE0}-\\u{11DE9}\\u{11F50}-\\u{11F59}\\u{11FC0}-\\u{11FD4}\\u{12400}-\\u{1246E}\\u{16130}-\\u{16139}\\u{16A60}-\\u{16A69}\\u{16AC0}-\\u{16AC9}\\u{16B50}-\\u{16B59}\\u{16B5B}-\\u{16B61}\\u{16D70}-\\u{16D79}\\u{16E80}-\\u{16E96}\\u{16FF4}-\\u{16FF6}\\u{1CCF0}-\\u{1CCF9}\\u{1D2C0}-\\u{1D2D3}\\u{1D2E0}-\\u{1D2F3}\\u{1D360}-\\u{1D378}\\u{1D7CE}-\\u{1D7FF}\\u{1E140}-\\u{1E149}\\u{1E2F0}-\\u{1E2F9}\\u{1E4F0}-\\u{1E4F9}\\u{1E5F1}-\\u{1E5FA}\\u{1E8C7}-\\u{1E8CF}\\u{1E950}-\\u{1E959}\\u{1EC71}-\\u{1ECAB}\\u{1ECAD}-\\u{1ECAF}\\u{1ECB1}-\\u{1ECB4}\\u{1ED01}-\\u{1ED2D}\\u{1ED2F}-\\u{1ED3D}\\u{1F100}-\\u{1F10C}\\u{1FBF0}-\\u{1FBF9}]+", "u")).filter(Boolean).join(' ');
1846
1850
  /** Words that ask a visitor to get in touch, which the site's form answers. */ const GET_IN_TOUCH_WORDS = /\b(?:contact|book|booking|call|quote|estimate|appointment|schedule|reserve|reservation|get in touch|request|visit|enquire|inquire|enquiry|inquiry|message|talk|consult|consultation|order|pre-?order|sign up|join|apply|start)\b/i;
1847
1851
  /**
1848
1852
  * Whether a link's words ask a visitor to get in touch — contact, book, quote,
@@ -1856,10 +1860,11 @@ const GRID = 'muiGrid';
1856
1860
  * in document order. A link whose words ask a visitor to get in touch, sent to
1857
1861
  * a home page that places the site's form, does what it says (AGL-3729).
1858
1862
  */ function unrelatedScreenLinks(tree, outputKind, context) {
1859
- var _context_homeScreenIds, _context_formScreenIds;
1863
+ var _context_homeScreenIds, _context_formScreenIds, _context_homeLabels;
1860
1864
  if (outputKind === 'email' || outputKind === 'form') return [];
1861
1865
  const home = new Set((_context_homeScreenIds = context.homeScreenIds) != null ? _context_homeScreenIds : []);
1862
1866
  const forms = new Set((_context_formScreenIds = context.formScreenIds) != null ? _context_formScreenIds : []);
1867
+ const homeLabels = new Set(((_context_homeLabels = context.homeLabels) != null ? _context_homeLabels : []).map(labelWords).filter(Boolean));
1863
1868
  const sent = [];
1864
1869
  for (const visit of walkTree(tree)){
1865
1870
  var _node_props, _node_props1, _node_props2;
@@ -1868,7 +1873,7 @@ const GRID = 'muiGrid';
1868
1873
  const screenId = (_node_props = node.props) == null ? void 0 : _node_props['screenId'];
1869
1874
  const linksHome = typeof screenId === 'string' && home.has(screenId) || ((_node_props1 = node.props) == null ? void 0 : _node_props1['href']) === '/';
1870
1875
  const label = typeof ((_node_props2 = node.props) == null ? void 0 : _node_props2['children']) === 'string' ? node.props['children'].trim() : '';
1871
- if (!linksHome || !label || HOME_WORDS.test(label)) continue;
1876
+ if (!linksHome || !label || HOME_WORDS.test(label) || homeLabels.has(labelWords(label))) continue;
1872
1877
  // Home holds the site's form, and the words ask for what it does (AGL-3729).
1873
1878
  if (typeof screenId === 'string' && forms.has(screenId) && aiAsksToGetInTouch(label)) continue;
1874
1879
  // The header and the navigation link home by name and by the site's own brand.
@@ -3288,7 +3293,10 @@ const BUDGET_METRICS = [
3288
3293
  };
3289
3294
  const violations = [
3290
3295
  ...publish,
3291
- ...detectRepeatedSubtrees(tree, otherPages, context),
3296
+ // A form's fields share a shape because a field IS one shape — a Form
3297
+ // Control over a Form Label and an answer — and a form places no
3298
+ // instances, so rule 1 has nothing to ask of one.
3299
+ ...outputKind === 'form' ? [] : detectRepeatedSubtrees(tree, otherPages, context),
3292
3300
  ...detectLayoutRegions(tree, outputKind),
3293
3301
  ...detectInlineForms(tree, outputKind),
3294
3302
  ...detectLiteralStyles(tree, outputKind),
@@ -3802,6 +3810,45 @@ const FORM_SECTION_NAME = /\bform\b|\bsign[- ]?up\b|\bsubscribe\b|\bnewsletter\b
3802
3810
  screens
3803
3811
  }) : plan;
3804
3812
  }
3813
+ /**
3814
+ * A section that shows the work — a gallery, a portfolio, selected works, by
3815
+ * the name `aiSiteSectionShowsWork` reads — planned with fewer pieces than
3816
+ * the job's `galleryMinItems` is raised to it before the rules read the plan
3817
+ * (AGL-3754). The site start's `plan-empty-gallery` refusal names one answer,
3818
+ * "plan it with three to six items", and the fewest is the one that keeps
3819
+ * the plan's own count closest: a section's items move no section cap, Free
3820
+ * wall or credit figure, which count sections and pages.
3821
+ *
3822
+ * A section the rule reads as one item of a list split into sections is
3823
+ * left for rule 1's re-ask to join, as the Free wall's trim leaves it: raised
3824
+ * here, it would hide the split. A job that sets no `galleryMinItems` (every
3825
+ * job but a site start) is returned unchanged.
3826
+ */ export function aiSettlePlanGalleries(plan, inventory, capabilities = null) {
3827
+ var _ref;
3828
+ const least = (_ref = capabilities == null ? void 0 : capabilities.galleryMinItems) != null ? _ref : 0;
3829
+ const thin = (section)=>aiSiteSectionShowsWork(section.name) && section.items < least;
3830
+ if (!plan.screens.some((screen)=>screen.sections.some(thin))) return plan;
3831
+ const split = new Set(detectPlanSplitLists(plan, inventory, capabilities).flatMap((violation)=>{
3832
+ var _violation_paths;
3833
+ return (_violation_paths = violation.paths) != null ? _violation_paths : [];
3834
+ }));
3835
+ let changed = false;
3836
+ const screens = plan.screens.map((screen, screenIndex)=>{
3837
+ if (!screen.sections.some(thin)) return screen;
3838
+ return _extends({}, screen, {
3839
+ sections: screen.sections.map((section, sectionIndex)=>{
3840
+ if (!thin(section) || split.has(`screens[${screenIndex}].sections[${sectionIndex}]`)) return section;
3841
+ changed = true;
3842
+ return _extends({}, section, {
3843
+ items: least
3844
+ });
3845
+ })
3846
+ });
3847
+ });
3848
+ return changed ? _extends({}, plan, {
3849
+ screens
3850
+ }) : plan;
3851
+ }
3805
3852
  /** Every saved form a plan could place, the plan's own creations first. */ function planFormChoices(plan, inventory) {
3806
3853
  var _ref;
3807
3854
  return [