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

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 (116) hide show
  1. package/package.json +17 -17
  2. package/src/lib/activity/ai-activity-actions.js +3 -1
  3. package/src/lib/activity/ai-activity-actions.js.map +1 -1
  4. package/src/lib/components/ai-job-links.js +7 -0
  5. package/src/lib/components/ai-job-links.js.map +1 -1
  6. package/src/lib/components/ai-product-zones.d.ts +3 -1
  7. package/src/lib/components/ai-product-zones.js.map +1 -1
  8. package/src/lib/components/ai-products-hub-card.component.js +1 -1
  9. package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
  10. package/src/lib/components/ai-products-proposals.component.js +17 -9
  11. package/src/lib/components/ai-products-proposals.component.js.map +1 -1
  12. package/src/lib/components/ai-site-start-card.component.js +6 -4
  13. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  14. package/src/lib/components/ai-upsell-dialog.component.js +1 -1
  15. package/src/lib/components/ai-upsell-dialog.component.js.map +1 -1
  16. package/src/lib/jobs/ai-build-capabilities.js +162 -2
  17. package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
  18. package/src/lib/jobs/ai-job-build-step.d.ts +7 -0
  19. package/src/lib/jobs/ai-job-build-step.js +85 -16
  20. package/src/lib/jobs/ai-job-build-step.js.map +1 -1
  21. package/src/lib/jobs/ai-job-duplicate-step.d.ts +123 -0
  22. package/src/lib/jobs/ai-job-duplicate-step.js +269 -0
  23. package/src/lib/jobs/ai-job-duplicate-step.js.map +1 -0
  24. package/src/lib/jobs/ai-job-layout-language.js +13 -0
  25. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  26. package/src/lib/jobs/ai-job-navigation-step.d.ts +157 -0
  27. package/src/lib/jobs/ai-job-navigation-step.js +439 -0
  28. package/src/lib/jobs/ai-job-navigation-step.js.map +1 -0
  29. package/src/lib/jobs/ai-job-page-language.d.ts +2 -1
  30. package/src/lib/jobs/ai-job-page-language.js +21 -5
  31. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  32. package/src/lib/jobs/ai-job-page-sections.js +1 -1
  33. package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
  34. package/src/lib/jobs/ai-job-plan-step.d.ts +4 -2
  35. package/src/lib/jobs/ai-job-plan-step.js +16 -7
  36. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  37. package/src/lib/jobs/ai-job-products-step.d.ts +2 -2
  38. package/src/lib/jobs/ai-job-products-step.js +2 -2
  39. package/src/lib/jobs/ai-job-products-step.js.map +1 -1
  40. package/src/lib/jobs/ai-job-settings-step.d.ts +272 -0
  41. package/src/lib/jobs/ai-job-settings-step.js +695 -0
  42. package/src/lib/jobs/ai-job-settings-step.js.map +1 -0
  43. package/src/lib/jobs/ai-job-site-content.d.ts +20 -6
  44. package/src/lib/jobs/ai-job-site-content.js +28 -12
  45. package/src/lib/jobs/ai-job-site-content.js.map +1 -1
  46. package/src/lib/jobs/ai-job-site-datasets.d.ts +2 -0
  47. package/src/lib/jobs/ai-job-site-datasets.js +10 -3
  48. package/src/lib/jobs/ai-job-site-datasets.js.map +1 -1
  49. package/src/lib/jobs/ai-job-site-step.d.ts +3 -1
  50. package/src/lib/jobs/ai-job-site-step.js +70 -10
  51. package/src/lib/jobs/ai-job-site-step.js.map +1 -1
  52. package/src/lib/jobs/ai-site-publish.d.ts +62 -4
  53. package/src/lib/jobs/ai-site-publish.js +203 -56
  54. package/src/lib/jobs/ai-site-publish.js.map +1 -1
  55. package/src/lib/layout-language/ai-layout-compiler.d.ts +7 -4
  56. package/src/lib/layout-language/ai-layout-compiler.js +26 -25
  57. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  58. package/src/lib/layout-language/ai-layout-frame-hollows.d.ts +41 -0
  59. package/src/lib/layout-language/ai-layout-frame-hollows.js +330 -0
  60. package/src/lib/layout-language/ai-layout-frame-hollows.js.map +1 -0
  61. package/src/lib/layout-language/ai-layout-frame.d.ts +18 -1
  62. package/src/lib/layout-language/ai-layout-frame.js +83 -13
  63. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  64. package/src/lib/layout-language/ai-layout-listings.d.ts +35 -0
  65. package/src/lib/layout-language/ai-layout-listings.js +34 -0
  66. package/src/lib/layout-language/ai-layout-listings.js.map +1 -1
  67. package/src/lib/layout-language/ai-layout-tree.d.ts +2 -0
  68. package/src/lib/layout-language/ai-layout-tree.js +17 -0
  69. package/src/lib/layout-language/ai-layout-tree.js.map +1 -1
  70. package/src/lib/model/ai-build-job.d.ts +23 -0
  71. package/src/lib/model/ai-build-job.js +102 -13
  72. package/src/lib/model/ai-build-job.js.map +1 -1
  73. package/src/lib/model/ai-build-plan.d.ts +25 -0
  74. package/src/lib/model/ai-build-plan.js +45 -1
  75. package/src/lib/model/ai-build-plan.js.map +1 -1
  76. package/src/lib/model/ai-credit-estimate.d.ts +52 -0
  77. package/src/lib/model/ai-credit-estimate.js +51 -0
  78. package/src/lib/model/ai-credit-estimate.js.map +1 -1
  79. package/src/lib/model/ai-job-activity.js +4 -1
  80. package/src/lib/model/ai-job-activity.js.map +1 -1
  81. package/src/lib/model/ai-jobs.types.d.ts +10 -2
  82. package/src/lib/model/ai-jobs.types.js +4 -1
  83. package/src/lib/model/ai-jobs.types.js.map +1 -1
  84. package/src/lib/model/ai-layout-menus.d.ts +104 -0
  85. package/src/lib/model/ai-layout-menus.js +518 -0
  86. package/src/lib/model/ai-layout-menus.js.map +1 -0
  87. package/src/lib/model/ai-products.d.ts +31 -1
  88. package/src/lib/model/ai-products.js +34 -1
  89. package/src/lib/model/ai-products.js.map +1 -1
  90. package/src/lib/model/ai-site-inventory.d.ts +15 -0
  91. package/src/lib/model/ai-site-inventory.js.map +1 -1
  92. package/src/lib/model/ai-site-job.d.ts +10 -0
  93. package/src/lib/model/ai-site-job.js +36 -9
  94. package/src/lib/model/ai-site-job.js.map +1 -1
  95. package/src/lib/model/ai-site-store-pages.js +1 -1
  96. package/src/lib/model/ai-site-store-pages.js.map +1 -1
  97. package/src/lib/runtime/ai-doctrine-validators.d.ts +53 -0
  98. package/src/lib/runtime/ai-doctrine-validators.js +166 -25
  99. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  100. package/src/lib/runtime/ai-doctrine.js +7 -2
  101. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  102. package/src/lib/runtime/ai-palette.generated.js +1 -1
  103. package/src/lib/runtime/ai-palette.generated.js.map +1 -1
  104. package/src/lib/runtime/ai-products-generation.d.ts +4 -2
  105. package/src/lib/runtime/ai-products-generation.js +12 -6
  106. package/src/lib/runtime/ai-products-generation.js.map +1 -1
  107. package/src/lib/runtime/site-inventory.d.ts +12 -0
  108. package/src/lib/runtime/site-inventory.js +29 -1
  109. package/src/lib/runtime/site-inventory.js.map +1 -1
  110. package/src/lib/server.js +12 -0
  111. package/src/lib/server.js.map +1 -1
  112. package/src/lib/testing/stand-in-dataset-index.js +37 -3
  113. package/src/lib/testing/stand-in-dataset-index.js.map +1 -1
  114. package/src/lib/tools/ai-products-tool.d.ts +3 -1
  115. package/src/lib/tools/ai-products-tool.js +15 -5
  116. package/src/lib/tools/ai-products-tool.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-publish.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 { isFirstPublishedRoute } from '@aglyn/aglyn/app-utils/analytics-events'\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\nimport {\n blockingRouteOwner,\n normalizeScreenSlug,\n SCREEN_ROOT_PATH,\n screenRoutePathToUrl,\n} from '@aglyn/aglyn/app-utils/screen-route'\nimport { decodeStoredNodes, encodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport { dropPluginSiteCache } from '@aglyn/aglyn/plugin-manager/plugin-site-cache'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { sendGa4SitePublished } from '@aglyn/tenant-data-admin/server/ga4-measurement-protocol'\nimport { FieldValue, type Firestore } from 'firebase-admin/firestore'\nimport type { AiJob, AiJobOutput, AiJobSitePublish } from '../model/ai-jobs.types'\nimport { AI_SITE_BLOG_SLUGS } from '../model/ai-site-job'\nimport { aiLayoutWithStoreLinks, type AiStoreLayoutLinks } from '../model/ai-layout-store-links'\nimport { AI_STORE_LINKS_SOURCE_FIELD as STORE_LINKS_SOURCE_FIELD } from './ai-job-store-links-layout'\n\n/**\n * A store's links a build drafted into the site's own layout (AGL-3676): the\n * draft version, the links in it, and the site's page addresses they were\n * checked against. Its publish makes that version the live one, or — where\n * the layout changed since the draft was made — adds the same links to the\n * version that is live now.\n */\nexport interface AiSitePublishStoreLinks {\n layoutId: string\n versionId: string\n links: AiStoreLayoutLinks\n screenPaths?: Readonly<Record<string, string>>\n}\n\n/**\n * A guided site start publishes what it built (AGL-3596).\n *\n * A person who asked for \"a website\" in the guided start and watched it build\n * was then handed drafts: a site whose address still answered with the\n * starter, or with nothing. A `site` job started from the guided start (its\n * plan confirmed on the person's behalf, `inputs.autoConfirm`) therefore ends\n * by putting every page it built on the site, through the same writes a\n * person's Publish makes:\n *\n * - each page's address in the host's routing map, `publishedAt` on the page,\n * in ONE batch with the publish outbox entry that drops the live site's\n * cached pages (AGL-2575), the drop itself attempted at once;\n * - the home page takes `/` from the starter home page the site was created\n * with (AGL-3408), and an untouched starter goes to the trash rather than\n * staying beside it as a second \"Home\";\n * - the navigation entries the pages proposed are added to the header of\n * the layout they render inside, as a new live version of that layout;\n * - `site_published` once, server-side, as the scheduled publish sends it.\n *\n * A page that cannot be published — deleted meanwhile, no address, an address\n * another page holds — stays a draft and is reported with the plain sentence\n * for why. It never fails the job: the site is still built, and the person\n * fixes that one page in Pages. Every other job kind keeps producing drafts.\n *\n * The allowance is respected by construction: a draft is counted against the\n * plan's pages when it is written (`aiDraftBandRefusal`), so publishing\n * drafts adds none, and retiring the starter frees the one it held.\n */\n\nexport interface AiSitePublishDeps {\n sendSitePublished?: typeof sendGa4SitePublished\n dropCache?: typeof dropPluginSiteCache\n}\n\n/**\n * Whether a build puts its pages live (AGL-3616): only where its request\n * asked to (`publish`, set by Assist's proposal) AND the member ticked the\n * plan card's box when confirming (`publishConfirmed`, set by the resume\n * door). Every other build leaves drafts.\n */\nexport function aiJobPublishesBuild(job: Pick<AiJob, 'kind' | 'inputs'>): boolean {\n return job.kind === 'build' && job.inputs?.['publish'] === true && job.inputs?.['publishConfirmed'] === true\n}\n\n/** Whether a finished job of this shape publishes what it built. */\nexport function aiJobPublishesSite(job: Pick<AiJob, 'kind' | 'inputs'>): boolean {\n return job.kind === 'site' && job.inputs?.['autoConfirm'] === true\n}\n\n/**\n * Where a site answers: its custom domain, else its subdomain under the\n * deployment's tenant apex — never a hard-coded platform host, so a\n * self-hosted deployment links to its own sites.\n */\nexport function aiSiteLiveUrl(host: { cname?: unknown; subdomain?: unknown }): string | null {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim() : '')\n const origin = hostPublicOrigin({ cname: text(host.cname) || null, subdomain: text(host.subdomain) || null })\n return origin ? `${origin}/` : null\n}\n\n/** The sentences a page that stayed a draft is reported with. */\nexport const AI_SITE_PUBLISH_DELETED = 'It was deleted before it could be published.'\nexport const AI_SITE_PUBLISH_NO_ADDRESS = 'It has no address yet. Give it one in Pages and publish it.'\nexport const aiSitePublishTakenCopy = (path: string): string =>\n `Another page is already published at ${screenRoutePathToUrl(path)}. Give this one another address in Pages and publish it.`\nexport const AI_SITE_PUBLISH_FAILED = 'It could not be published just now. Publish it from Pages.'\n\n/** A navigation entry a page proposed, as the page step reports it. */\ninterface NavEntry {\n screenId: string\n label: string\n}\n\nfunction navEntriesOf(outputs: readonly AiJobOutput[]): NavEntry[] {\n const entries: NavEntry[] = []\n for (const output of outputs) {\n if (output.resource !== 'screen') continue\n const navigation = output.proposal?.['navigation'] as { label?: unknown } | undefined\n const label = typeof navigation?.label === 'string' ? navigation.label.trim() : ''\n if (label && !entries.some((entry) => entry.screenId === output.id)) {\n entries.push({ screenId: output.id, label })\n }\n }\n return entries\n}\n\ntype MutableNode = {\n $id: string\n componentId?: string\n parentId?: string\n props?: Record<string, unknown>\n nodes?: string[]\n [key: string]: unknown\n}\n\n/**\n * The blog paths a start's layout links and must not publish (AGL-3660): its\n * header, phone menu and footer link the blog by path while the posts part is\n * still owed, so a start whose posts part then failed or was skipped drops\n * every address the blog could have taken. None while the blog was written.\n */\nexport function aiSiteUnwrittenBlogHrefs(blogUnwritten: boolean | undefined): string[] {\n return blogUnwritten ? AI_SITE_BLOG_SLUGS.map((slug) => `/${slug}`) : []\n}\n\n/**\n * The layout's nodes with its links to the retired starter home pointed at\n * the new home, and a link for each proposed entry the header does not\n * already carry, placed in the header's toolbar after its existing links.\n * `null` when nothing changes, or when the layout has no toolbar to hold an\n * entry and no link to repoint.\n */\nexport function aiLayoutWithNavigation(\n nodes: NodesMap,\n input: {\n entries: readonly NavEntry[]\n retiredHomeId?: string | null\n homeId?: string | null\n /** Paths whose links come out: a blog the start linked and never wrote (AGL-3660). */\n droppedHrefs?: readonly string[]\n },\n): NodesMap | null {\n const map: Record<string, MutableNode> = {}\n for (const [id, node] of Object.entries(nodes as unknown as Record<string, MutableNode>)) {\n map[id] = { ...node, ...(node.props ? { props: { ...node.props } } : {}), ...(node.nodes ? { nodes: [...node.nodes] } : {}) }\n }\n let changed = false\n // The header, the phone menu and the footer link a blog by its path before\n // its posts are written (AGL-3660); a start whose posts were not written\n // publishes none of those links to a page that does not exist.\n const dropped = new Set(input.droppedHrefs ?? [])\n if (dropped.size) {\n const gone = new Set(\n Object.entries(map)\n .filter(([, node]) => node.componentId === 'muiScreenLink' && dropped.has(String(node.props?.['href'] ?? '')))\n .map(([id]) => id),\n )\n if (gone.size) {\n for (const id of gone) delete map[id]\n for (const node of Object.values(map)) {\n if (node.nodes?.some((child) => gone.has(child))) node.nodes = node.nodes.filter((child) => !gone.has(child))\n }\n changed = true\n }\n }\n const links = Object.values(map).filter((node) => node.componentId === 'muiScreenLink')\n if (input.retiredHomeId && input.homeId) {\n for (const link of links) {\n if (link.props?.['screenId'] === input.retiredHomeId) {\n link.props = { ...link.props, screenId: input.homeId }\n changed = true\n }\n }\n }\n const linked = new Set(links.map((link) => link.props?.['screenId']).filter(Boolean))\n const toolbar = Object.values(map).find((node) => node.componentId === 'muiToolbar')\n const missing = input.entries.filter((entry) => !linked.has(entry.screenId))\n if (toolbar && missing.length) {\n const children = toolbar.nodes ?? []\n // After the last link already in the toolbar (the brand), before the\n // search, the mode switch and the call to action.\n const lastLink = children.reduce(\n (at, id, index) => (map[id]?.componentId === 'muiScreenLink' ? index : at),\n -1,\n )\n const added = missing.map((entry) => {\n const id = `ai_nav_${createResourceUid()}`\n map[id] = {\n $id: id,\n componentId: 'muiScreenLink',\n pluginId: 'mui',\n parentId: toolbar.$id,\n props: { children: entry.label, screenId: entry.screenId, renderAs: 'link', color: 'inherit' },\n sx: { textDecoration: 'none', whiteSpace: 'nowrap' },\n nodes: [],\n }\n return id\n })\n toolbar.nodes = [...children.slice(0, lastLink + 1), ...added, ...children.slice(lastLink + 1)]\n changed = true\n }\n return changed ? (map as unknown as NodesMap) : null\n}\n\n/**\n * A retry's publish merged into the start's first (AGL-3730): the pages it\n * put live join the published list, a page it published leaves the drafts,\n * and a page it left a draft is reported with its newest reason.\n */\nexport function aiMergeSitePublish(previous: AiJobSitePublish, retried: AiJobSitePublish): AiJobSitePublish {\n const now = new Set([...retried.published, ...retried.drafts].map((page) => page.id))\n return {\n liveUrl: retried.liveUrl ?? previous.liveUrl,\n published: [...previous.published.filter((page) => !now.has(page.id)), ...retried.published],\n drafts: [...previous.drafts.filter((page) => !now.has(page.id)), ...retried.drafts],\n }\n}\n\n/**\n * Publishes the pages a guided site start built. Never throws for a page; a\n * Firestore failure of the publish write itself reports every page as a\n * draft, for the same reason, and is logged.\n */\nexport async function aiPublishGuidedSite(\n firestore: Firestore,\n input: {\n job: Pick<AiJob, '$id' | 'orgId' | 'hostId'>\n outputs: readonly AiJobOutput[]\n now: Date\n /** The start owed its blog's posts and wrote none (AGL-3660): its links to the blog come out. */\n blogUnwritten?: boolean\n /** Paths the layout links that the start did not write, such as a store page (AGL-3676): their links come out. */\n unwrittenHrefs?: readonly string[]\n /** A store's links a build drafted into the site's own layout (AGL-3676), which go live with its pages. */\n storeLinks?: AiSitePublishStoreLinks | null\n /**\n * The start published once already, and Try again rebuilt what failed\n * (AGL-3730): only `outputs` go live, beside what is. The home address is\n * never taken from the starter here, the starter is never retired, and\n * `site_published` is not sent again; a retried page at `/` that the\n * starter still holds stays a draft and says so.\n */\n retry?: boolean\n },\n deps: AiSitePublishDeps = {},\n): Promise<AiJobSitePublish> {\n const sendSitePublished = deps.sendSitePublished ?? sendGa4SitePublished\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n const { job, now } = input\n const hostId = job.hostId ?? ''\n const pages = input.outputs.filter(\n (output, index, all) =>\n output.resource === 'screen' &&\n (output.hostId ?? hostId) === hostId &&\n all.findIndex((other) => other.resource === 'screen' && other.id === output.id) === index,\n )\n const hostRef = firestore.collection('hosts').doc(hostId)\n const host = await hostRef.get()\n const result: AiJobSitePublish = {\n liveUrl: aiSiteLiveUrl({ cname: host.get('cname'), subdomain: host.get('subdomain') }),\n published: [],\n drafts: [],\n }\n if (!host.exists || !pages.length) return result\n\n const before = { ...((host.get('screens') ?? {}) as Record<string, string>) }\n const starter = (host.get('defaultHomeScreenId') as string | undefined) || null\n // A retry never takes `/` from the starter (AGL-3730): it holds it like any page.\n const placeholder = input.retry ? null : starter\n const routing = { ...before }\n const entries: Record<string, string> = {}\n const accepted: Array<{ id: string; label: string; path: string; slug: string }> = []\n for (const page of pages) {\n const snapshot = await hostRef.collection('screens').doc(page.id).get()\n const label = String(snapshot.get('displayName') ?? page.label ?? '') || page.label\n if (!snapshot.exists || snapshot.get('deletedAt') != null) {\n result.drafts.push({ id: page.id, label, reason: AI_SITE_PUBLISH_DELETED })\n continue\n }\n const slug = normalizeScreenSlug(String(snapshot.get('slug') ?? ''))\n if (!slug) {\n result.drafts.push({ id: page.id, label, reason: AI_SITE_PUBLISH_NO_ADDRESS })\n continue\n }\n const owner = blockingRouteOwner(routing, slug, placeholder)\n if (owner && owner !== page.id) {\n result.drafts.push({ id: page.id, label, reason: aiSitePublishTakenCopy(slug) })\n continue\n }\n routing[page.id] = slug\n entries[page.id] = slug\n accepted.push({ id: page.id, label, path: slug, slug })\n }\n if (!accepted.length) return result\n\n // The first real home page replaces the placeholder in the same write.\n const home = accepted.find((page) => page.path === SCREEN_ROOT_PATH) ?? null\n const releases =\n home && placeholder && placeholder !== home.id && before[placeholder] === SCREEN_ROOT_PATH\n ? placeholder\n : null\n // An untouched starter home (still its one first version) is retired to the\n // trash; one its owner edited stays in Pages as their draft.\n const retire = releases\n ? (await hostRef.collection('screens').doc(releases).collection('versions').limit(2).get()).size <= 1\n : false\n\n // The header of the layout the pages render inside learns their entries.\n const layoutWrite = await aiNavigationLayoutWrite(firestore, {\n hostId,\n pageIds: accepted.map((page) => page.id),\n entries: navEntriesOf(pages).filter((entry) => entries[entry.screenId]),\n droppedHrefs: [...aiSiteUnwrittenBlogHrefs(input.blogUnwritten), ...(input.unwrittenHrefs ?? [])],\n retiredHomeId: releases,\n homeId: home?.id ?? null,\n jobId: job.$id,\n now,\n storeLinks: input.storeLinks ?? null,\n }).catch((error: unknown) => {\n console.error('ai site publish: navigation not applied', { hostId, jobId: job.$id, error })\n return null\n })\n // A store's links drafted into a layout the pages' navigation did not touch go live on their own.\n const storeLinks = input.storeLinks ?? null\n const storeLinksWrite =\n storeLinks && layoutWrite?.layoutRef.id !== storeLinks.layoutId\n ? await aiLayoutVersionWrite(firestore, {\n hostId,\n layoutId: storeLinks.layoutId,\n transform: () => null,\n storeLinks,\n jobId: job.$id,\n now,\n }).catch((error: unknown) => {\n console.error('ai site publish: store links not applied', { hostId, jobId: job.$id, error })\n return null\n })\n : null\n const layoutWrites = [layoutWrite, storeLinksWrite].filter((write): write is LayoutWrite => Boolean(write))\n\n const paths = [\n ...new Set(\n [\n ...Object.values(entries),\n ...(releases ? [SCREEN_ROOT_PATH] : []),\n ].map((path) => screenRoutePathToUrl(path)),\n ),\n ]\n const batch = firestore.batch()\n const hostUpdates: Record<string, unknown> = { updatedAt: now }\n for (const [id, path] of Object.entries(entries)) hostUpdates[`screens.${id}`] = path\n if (releases) {\n hostUpdates[`screens.${releases}`] = FieldValue.delete()\n hostUpdates['defaultHomeScreenId'] = FieldValue.delete()\n batch.set(\n hostRef.collection('screens').doc(releases),\n { publishedAt: FieldValue.delete(), ...(retire ? { deletedAt: now } : {}) },\n { merge: true },\n )\n } else if (placeholder && entries[placeholder]) {\n hostUpdates['defaultHomeScreenId'] = FieldValue.delete()\n }\n batch.update(hostRef, hostUpdates)\n for (const page of accepted) {\n batch.set(hostRef.collection('screens').doc(page.id), { slug: page.slug, publishedAt: now }, { merge: true })\n }\n for (const write of layoutWrites) {\n if (write.version) batch.create(write.versionRef, write.version)\n batch.set(write.layoutRef, { versionId: write.versionRef.id, updatedAt: now }, { merge: true })\n }\n // The announce, written down in the publish's own batch (AGL-2575): a\n // layout change reaches every page, so it asks for the whole site.\n const outboxRef = firestore.collection('publishOutbox').doc(createResourceUid())\n batch.set(outboxRef, {\n hostId,\n paths: paths.length ? paths : [SCREEN_ROOT_PATH],\n createdAt: FieldValue.serverTimestamp(),\n attempts: 0,\n ...(layoutWrites.length ? { entireHost: true } : {}),\n })\n try {\n await batch.commit()\n } catch (error) {\n console.error('ai site publish failed', { hostId, jobId: job.$id, error })\n for (const page of accepted) result.drafts.push({ id: page.id, label: page.label, reason: AI_SITE_PUBLISH_FAILED })\n return result\n }\n result.published = accepted.map(({ id, label, path }) => ({ id, label, path: screenRoutePathToUrl(path) }))\n\n // The live site's cached pages go now; the outbox entry stays for the\n // drain unless the drop certainly happened.\n const dropped = await dropCache({\n hostIds: [hostId],\n reason: 'guided AI site start published',\n ...(layoutWrites.length ? {} : { paths: { [hostId]: paths } }),\n })\n if (dropped.complete) await outboxRef.delete().catch(() => undefined)\n // A site that came alive with nobody's browser on the publish (AGL-1589),\n // announced once: a retry's pages join a site already announced (AGL-3730).\n if (!input.retry) await sendSitePublished({ hostId, firstPublish: isFirstPublishedRoute(before, placeholder) })\n return result\n}\n\ninterface LayoutWrite {\n layoutRef: FirebaseFirestore.DocumentReference\n versionRef: FirebaseFirestore.DocumentReference\n /** The new version to create; `null` where the live version becomes one already written (a store's links draft). */\n version: Record<string, unknown> | null\n}\n\n/**\n * The new live version of the layout the published pages render inside, with\n * their navigation entries and the home link moved off a retired starter;\n * `null` when there is nothing to change or no one layout to change.\n */\nasync function aiNavigationLayoutWrite(\n firestore: Firestore,\n input: {\n hostId: string\n pageIds: readonly string[]\n entries: readonly NavEntry[]\n droppedHrefs: readonly string[]\n retiredHomeId: string | null\n homeId: string | null\n jobId: string\n now: Date\n storeLinks?: AiSitePublishStoreLinks | null\n },\n): Promise<LayoutWrite | null> {\n if (!input.entries.length && !input.retiredHomeId && !input.droppedHrefs.length && !input.storeLinks) return null\n const hostRef = firestore.collection('hosts').doc(input.hostId)\n const layoutIds = new Set<string>()\n for (const id of input.pageIds) {\n const screen = await hostRef.collection('screens').doc(id).get()\n const versionId = screen.get('versionId')\n const version =\n typeof versionId === 'string' && versionId\n ? await hostRef.collection('screens').doc(id).collection('versions').doc(versionId).get()\n : null\n const layoutId = version?.get('layoutId') ?? screen.get('layoutId')\n if (typeof layoutId === 'string' && layoutId) layoutIds.add(layoutId)\n }\n if (layoutIds.size !== 1) return null\n const [layoutId] = [...layoutIds]\n return aiLayoutVersionWrite(firestore, {\n hostId: input.hostId,\n layoutId,\n transform: (nodes) => aiLayoutWithNavigation(nodes, input),\n storeLinks: input.storeLinks ?? null,\n jobId: input.jobId,\n now: input.now,\n })\n}\n\n/**\n * The new live version of one layout: `transform` applied to the version\n * live now. A store's links drafted into this layout (AGL-3676) start it from\n * that draft while the draft was made from the live version, and are added\n * to the live version otherwise; a draft with nothing more to add becomes\n * the live version as it is. `null` when nothing changes.\n */\nasync function aiLayoutVersionWrite(\n firestore: Firestore,\n input: {\n hostId: string\n layoutId: string\n transform: (nodes: NodesMap) => NodesMap | null\n storeLinks: AiSitePublishStoreLinks | null\n jobId: string\n now: Date\n },\n): Promise<LayoutWrite | null> {\n const { layoutId } = input\n const layoutRef = firestore.collection('hosts').doc(input.hostId).collection('layouts').doc(layoutId)\n const layout = await layoutRef.get()\n const currentVersionId = layout.get('versionId')\n if (!layout.exists || layout.get('deletedAt') != null || typeof currentVersionId !== 'string') return null\n const current = await layoutRef.collection('versions').doc(currentVersionId).get()\n const links = input.storeLinks?.layoutId === layoutId ? input.storeLinks : null\n const draftRef = links ? layoutRef.collection('versions').doc(links.versionId) : null\n const draft = draftRef ? await draftRef.get() : null\n const fromDraft = Boolean(draft?.exists && draft.get(STORE_LINKS_SOURCE_FIELD) === currentVersionId)\n const base = fromDraft && draft ? draft : current\n const nodes = base.exists ? decodeStoredNodes<NodesMap>(base.get('nodes')) : null\n if (!nodes) return null\n let next = input.transform(nodes)\n if (links && !fromDraft) {\n const added = aiLayoutWithStoreLinks((next ?? nodes) as never, links.links, links.screenPaths)\n next = (added.nodes as NodesMap | null) ?? next\n }\n if (!next) return fromDraft && draftRef ? { layoutRef, versionRef: draftRef, version: null } : null\n const packed = encodeStoredNodes(next)\n if (!packed) return null\n const versionRef = layoutRef.collection('versions').doc(createResourceUid())\n return {\n layoutRef,\n versionRef,\n version: {\n layoutId,\n hostId: input.hostId,\n displayName: 'Navigation for the new pages',\n nodes: Buffer.from(packed),\n createdAt: input.now,\n updatedAt: input.now,\n aiJobId: input.jobId,\n },\n }\n}\n"],"names":["isFirstPublishedRoute","createResourceUid","hostPublicOrigin","blockingRouteOwner","normalizeScreenSlug","SCREEN_ROOT_PATH","screenRoutePathToUrl","decodeStoredNodes","encodeStoredNodes","dropPluginSiteCache","sendGa4SitePublished","FieldValue","AI_SITE_BLOG_SLUGS","aiLayoutWithStoreLinks","AI_STORE_LINKS_SOURCE_FIELD","STORE_LINKS_SOURCE_FIELD","aiJobPublishesBuild","job","kind","inputs","aiJobPublishesSite","aiSiteLiveUrl","host","text","value","trim","origin","cname","subdomain","AI_SITE_PUBLISH_DELETED","AI_SITE_PUBLISH_NO_ADDRESS","aiSitePublishTakenCopy","path","AI_SITE_PUBLISH_FAILED","navEntriesOf","outputs","entries","output","resource","navigation","proposal","label","some","entry","screenId","id","push","aiSiteUnwrittenBlogHrefs","blogUnwritten","map","slug","aiLayoutWithNavigation","nodes","input","node","Object","props","changed","dropped","Set","droppedHrefs","size","gone","filter","componentId","has","String","values","child","links","retiredHomeId","homeId","link","linked","Boolean","toolbar","find","missing","length","children","lastLink","reduce","at","index","added","$id","pluginId","parentId","renderAs","color","sx","textDecoration","whiteSpace","slice","aiMergeSitePublish","previous","retried","now","published","drafts","page","liveUrl","aiPublishGuidedSite","firestore","deps","accepted","sendSitePublished","dropCache","hostId","pages","all","findIndex","other","hostRef","collection","doc","get","result","exists","before","starter","placeholder","retry","routing","snapshot","reason","owner","home","releases","retire","limit","layoutWrite","aiNavigationLayoutWrite","pageIds","unwrittenHrefs","jobId","storeLinks","catch","error","console","storeLinksWrite","layoutRef","layoutId","aiLayoutVersionWrite","transform","layoutWrites","write","paths","batch","hostUpdates","updatedAt","delete","set","publishedAt","deletedAt","merge","update","version","create","versionRef","versionId","outboxRef","createdAt","serverTimestamp","attempts","entireHost","commit","hostIds","complete","undefined","firstPublish","layoutIds","screen","add","layout","currentVersionId","current","draftRef","draft","fromDraft","base","next","screenPaths","packed","displayName","Buffer","from","aiJobId"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SACEC,kBAAkB,EAClBC,mBAAmB,EACnBC,gBAAgB,EAChBC,oBAAoB,QACf,sCAAqC;AAC5C,SAASC,iBAAiB,EAAEC,iBAAiB,QAAQ,sCAAqC;AAC1F,SAASC,mBAAmB,QAAQ,gDAA+C;AAEnF,SAASC,oBAAoB,QAAQ,2DAA0D;AAC/F,SAASC,UAAU,QAAwB,2BAA0B;AAErE,SAASC,kBAAkB,QAAQ,0BAAsB;AACzD,SAASC,sBAAsB,QAAiC,oCAAgC;AAChG,SAASC,+BAA+BC,wBAAwB,QAAQ,iCAA6B;AAmDrG;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,GAAmC;QACtCA,aAAoCA;IAAnE,OAAOA,IAAIC,IAAI,KAAK,WAAWD,EAAAA,cAAAA,IAAIE,MAAM,qBAAVF,WAAY,CAAC,UAAU,MAAK,QAAQA,EAAAA,eAAAA,IAAIE,MAAM,qBAAVF,YAAY,CAAC,mBAAmB,MAAK;AAC1G;AAEA,kEAAkE,GAClE,OAAO,SAASG,mBAAmBH,GAAmC;QACtCA;IAA9B,OAAOA,IAAIC,IAAI,KAAK,UAAUD,EAAAA,cAAAA,IAAIE,MAAM,qBAAVF,WAAY,CAAC,cAAc,MAAK;AAChE;AAEA;;;;CAIC,GACD,OAAO,SAASI,cAAcC,IAA8C;IAC1E,MAAMC,OAAO,CAACC,QAAoB,OAAOA,UAAU,WAAWA,MAAMC,IAAI,KAAK;IAC7E,MAAMC,SAASxB,iBAAiB;QAAEyB,OAAOJ,KAAKD,KAAKK,KAAK,KAAK;QAAMC,WAAWL,KAAKD,KAAKM,SAAS,KAAK;IAAK;IAC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IAAK,IAAI;IAC/F,MAAM0B,SAAS/K,kBAAkB6K;IACjC,IAAI,CAACE,QAAQ,OAAO;IACpB,MAAMxB,aAAalB,UAAU3B,UAAU,CAAC,YAAYC,GAAG,CAAClH;IACxD,OAAO;QACL4I;QACAkB;QACAF,SAAS;YACPf;YACAlC,QAAQvD,MAAMuD,MAAM;YACpB4E,aAAa;YACbpI,OAAOqI,OAAOC,IAAI,CAACH;YACnBrB,WAAW7G,MAAM4C,GAAG;YACpBqD,WAAWjG,MAAM4C,GAAG;YACpB0F,SAAStI,MAAMkF,KAAK;QACtB;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-publish.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 { isFirstPublishedRoute } from '@aglyn/aglyn/app-utils/analytics-events'\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\nimport {\n blockingRouteOwner,\n normalizeScreenSlug,\n SCREEN_ROOT_PATH,\n screenRoutePathToUrl,\n} from '@aglyn/aglyn/app-utils/screen-route'\nimport { resolvePageLocale } from '@aglyn/aglyn/app-utils/seo-locale'\nimport { decodeStoredNodes, encodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport { dropPluginSiteCache } from '@aglyn/aglyn/plugin-manager/plugin-site-cache'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { sendGa4SitePublished } from '@aglyn/tenant-data-admin/server/ga4-measurement-protocol'\nimport { FieldValue, type Firestore } from 'firebase-admin/firestore'\nimport {\n aiLayoutFrameHollows,\n aiLayoutFrameHollowsSaid,\n aiLayoutFrameIsHollow,\n aiLayoutRepairFrameHollows,\n aiLayoutWithoutFrameHollows,\n} from '../layout-language/ai-layout-frame-hollows'\nimport { aiPlanLanguage } from '../model/ai-build-plan'\nimport type { AiJob, AiJobOutput, AiJobSitePublish } from '../model/ai-jobs.types'\nimport { AI_SITE_BLOG_SLUGS } from '../model/ai-site-job'\nimport { aiLayoutWithStoreLinks, type AiStoreLayoutLinks } from '../model/ai-layout-store-links'\nimport { aiLayoutWithMenuChanges, aiNoMenuChanges } from '../model/ai-layout-menus'\nimport { AI_STORE_LINKS_SOURCE_FIELD as STORE_LINKS_SOURCE_FIELD } from './ai-job-store-links-layout'\n\n/**\n * A store's links a build drafted into the site's own layout (AGL-3676): the\n * draft version, the links in it, and the site's page addresses they were\n * checked against. Its publish makes that version the live one, or — where\n * the layout changed since the draft was made — adds the same links to the\n * version that is live now.\n */\nexport interface AiSitePublishStoreLinks {\n layoutId: string\n versionId: string\n links: AiStoreLayoutLinks\n screenPaths?: Readonly<Record<string, string>>\n}\n\n/**\n * A guided site start publishes what it built (AGL-3596).\n *\n * A person who asked for \"a website\" in the guided start and watched it build\n * was then handed drafts: a site whose address still answered with the\n * starter, or with nothing. A `site` job started from the guided start (its\n * plan confirmed on the person's behalf, `inputs.autoConfirm`) therefore ends\n * by putting every page it built on the site, through the same writes a\n * person's Publish makes:\n *\n * - each page's address in the host's routing map, `publishedAt` on the page,\n * in ONE batch with the publish outbox entry that drops the live site's\n * cached pages (AGL-2575), the drop itself attempted at once;\n * - the home page takes `/` from the starter home page the site was created\n * with (AGL-3408), and an untouched starter goes to the trash rather than\n * staying beside it as a second \"Home\";\n * - the navigation entries the pages proposed are added to the header of\n * the layout they render inside, as a new live version of that layout;\n * - `site_published` once, server-side, as the scheduled publish sends it.\n *\n * A page that cannot be published — deleted meanwhile, no address, an address\n * another page holds — stays a draft and is reported with the plain sentence\n * for why. It never fails the job: the site is still built, and the person\n * fixes that one page in Pages. Every other job kind keeps producing drafts.\n *\n * The allowance is respected by construction: a draft is counted against the\n * plan's pages when it is written (`aiDraftBandRefusal`), so publishing\n * drafts adds none, and retiring the starter frees the one it held.\n */\n\nexport interface AiSitePublishDeps {\n sendSitePublished?: typeof sendGa4SitePublished\n dropCache?: typeof dropPluginSiteCache\n}\n\n/**\n * Whether a build puts its pages live (AGL-3616): only where its request\n * asked to (`publish`, set by Assist's proposal) AND the member ticked the\n * plan card's box when confirming (`publishConfirmed`, set by the resume\n * door). Every other build leaves drafts.\n */\nexport function aiJobPublishesBuild(job: Pick<AiJob, 'kind' | 'inputs'>): boolean {\n return job.kind === 'build' && job.inputs?.['publish'] === true && job.inputs?.['publishConfirmed'] === true\n}\n\n/**\n * The host fields a guided start writes for its plan's language (AGL-3750),\n * as the Languages card saves one language: `locales` of that one and\n * `defaultLocale` the same. `null` — nothing written — where the plan said no\n * valid language, where it is the language the site already publishes in\n * (English for a new site), and on a site with more than one language, whose\n * languages are the owner's decision. Nothing is translated: the pages were\n * written in the brief's language, and this says so to the reader.\n */\nexport function aiSiteLanguageUpdates(\n host: { locales?: unknown; defaultLocale?: unknown },\n language: string | null | undefined,\n): { locales: string[]; defaultLocale: string } | null {\n const code = aiPlanLanguage(language)\n if (!code) return null\n const locales = Array.isArray(host.locales)\n ? host.locales.filter((one): one is string => typeof one === 'string' && one.trim() !== '')\n : []\n if (locales.length > 1) return null\n const current = resolvePageLocale({\n host: {\n ...(typeof host.defaultLocale === 'string' ? { defaultLocale: host.defaultLocale } : {}),\n locales,\n },\n })\n if (current === code) return null\n return { locales: [code], defaultLocale: code }\n}\n\n/** Whether a finished job of this shape publishes what it built. */\nexport function aiJobPublishesSite(job: Pick<AiJob, 'kind' | 'inputs'>): boolean {\n return job.kind === 'site' && job.inputs?.['autoConfirm'] === true\n}\n\n/**\n * Where a site answers: its custom domain, else its subdomain under the\n * deployment's tenant apex — never a hard-coded platform host, so a\n * self-hosted deployment links to its own sites.\n */\nexport function aiSiteLiveUrl(host: { cname?: unknown; subdomain?: unknown }): string | null {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim() : '')\n const origin = hostPublicOrigin({ cname: text(host.cname) || null, subdomain: text(host.subdomain) || null })\n return origin ? `${origin}/` : null\n}\n\n/** The sentences a page that stayed a draft is reported with. */\nexport const AI_SITE_PUBLISH_DELETED = 'It was deleted before it could be published.'\nexport const AI_SITE_PUBLISH_NO_ADDRESS = 'It has no address yet. Give it one in Pages and publish it.'\nexport const aiSitePublishTakenCopy = (path: string): string =>\n `Another page is already published at ${screenRoutePathToUrl(path)}. Give this one another address in Pages and publish it.`\nexport const AI_SITE_PUBLISH_FAILED = 'It could not be published just now. Publish it from Pages.'\n\n/** A navigation entry a page proposed, as the page step reports it. */\ninterface NavEntry {\n screenId: string\n label: string\n}\n\nfunction navEntriesOf(outputs: readonly AiJobOutput[]): NavEntry[] {\n const entries: NavEntry[] = []\n for (const output of outputs) {\n if (output.resource !== 'screen') continue\n const navigation = output.proposal?.['navigation'] as { label?: unknown } | undefined\n const label = typeof navigation?.label === 'string' ? navigation.label.trim() : ''\n if (label && !entries.some((entry) => entry.screenId === output.id)) {\n entries.push({ screenId: output.id, label })\n }\n }\n return entries\n}\n\ntype MutableNode = {\n $id: string\n componentId?: string\n parentId?: string\n props?: Record<string, unknown>\n nodes?: string[]\n [key: string]: unknown\n}\n\n/**\n * The blog paths a start's layout links and must not publish (AGL-3660): its\n * header, phone menu and footer link the blog by path while the posts part is\n * still owed, so a start whose posts part then failed or was skipped drops\n * every address the blog could have taken. None while the blog was written.\n */\nexport function aiSiteUnwrittenBlogHrefs(blogUnwritten: boolean | undefined): string[] {\n return blogUnwritten ? AI_SITE_BLOG_SLUGS.map((slug) => `/${slug}`) : []\n}\n\n/**\n * The layout's nodes with its links to the retired starter home pointed at\n * the new home, its links to pages the start did not write taken out, and a\n * link for each proposed entry the header does not already carry, added by\n * the navigation op's `aiLayoutWithMenuChanges` (AGL-3747): to the header's\n * menu and its phone menu, after their items, or after the brand in a\n * starter's Toolbar. `null` when nothing changes, or when the layout has no\n * header to hold an entry and no link to repoint or take out.\n */\nexport function aiLayoutWithNavigation(\n nodes: NodesMap,\n input: {\n entries: readonly NavEntry[]\n retiredHomeId?: string | null\n homeId?: string | null\n /** Paths whose links come out: a blog the start linked and never wrote (AGL-3660). */\n droppedHrefs?: readonly string[]\n },\n): NodesMap | null {\n const map: Record<string, MutableNode> = {}\n for (const [id, node] of Object.entries(nodes as unknown as Record<string, MutableNode>)) {\n map[id] = { ...node, ...(node.props ? { props: { ...node.props } } : {}), ...(node.nodes ? { nodes: [...node.nodes] } : {}) }\n }\n let changed = false\n // The header, the phone menu and the footer link a blog by its path before\n // its posts are written (AGL-3660); a start whose posts were not written\n // publishes none of those links to a page that does not exist.\n const dropped = new Set(input.droppedHrefs ?? [])\n if (dropped.size) {\n const gone = new Set(\n Object.entries(map)\n .filter(([, node]) => node.componentId === 'muiScreenLink' && dropped.has(String(node.props?.['href'] ?? '')))\n .map(([id]) => id),\n )\n if (gone.size) {\n for (const id of gone) delete map[id]\n for (const node of Object.values(map)) {\n if (node.nodes?.some((child) => gone.has(child))) node.nodes = node.nodes.filter((child) => !gone.has(child))\n }\n // A footer heading whose links all went goes with them, and its column\n // when that leaves it only the heading (AGL-3735).\n aiLayoutRepairFrameHollows(map as unknown as Record<string, unknown>)\n changed = true\n }\n }\n const links = Object.values(map).filter((node) => node.componentId === 'muiScreenLink')\n if (input.retiredHomeId && input.homeId) {\n for (const link of links) {\n if (link.props?.['screenId'] === input.retiredHomeId) {\n link.props = { ...link.props, screenId: input.homeId }\n changed = true\n }\n }\n }\n // The entries go into the header through the navigation op's own code\n // (AGL-3747): the bar's menu and the phone menu's, after the items already\n // there, each looking like its neighbours. A page some link already opens,\n // or an item of the same name, is not added again.\n const linked = new Set(links.map((link) => link.props?.['screenId']).filter(Boolean))\n const missing = input.entries.filter((entry) => !linked.has(entry.screenId))\n if (missing.length) {\n const added = aiLayoutWithMenuChanges(\n map,\n ['header'],\n { ...aiNoMenuChanges(), add: missing.map((entry) => ({ parent: null, label: entry.label, to: { screenId: entry.screenId } })) },\n { newId: () => `ai_nav_${createResourceUid()}` },\n )\n if (added.nodes) return added.nodes as unknown as NodesMap\n }\n return changed ? (map as unknown as NodesMap) : null\n}\n\n/** The blog a start writes, as its header entry links it (`aiSiteBlogNavPage`). */\nexport interface AiSiteBlogEntry {\n label: string\n href: string\n}\n\n/**\n * The layout's nodes with the blog's header entry put back (AGL-3747): a\n * start whose posts part failed published with every link to the blog taken\n * out (AGL-3660), and Try again's posts went live with none to reach them.\n * Added by the navigation op's `aiLayoutWithMenuChanges`, as the start's\n * other entries are — the bar's menu and the phone menu — second after the\n * home page's item, as the start first linked it (AGL-3676), else last.\n * `null` where some link already opens the blog, or the layout has no header\n * menu to hold it.\n */\nexport function aiLayoutWithBlogEntry(\n nodes: NodesMap,\n input: { blog: AiSiteBlogEntry; homeId?: string | null },\n): NodesMap | null {\n const blogHrefs = new Set([input.blog.href, ...AI_SITE_BLOG_SLUGS.map((slug) => `/${slug}`)])\n const linked = Object.values(nodes as unknown as Record<string, MutableNode>).some(\n (node) => node?.componentId === 'muiScreenLink' && blogHrefs.has(String(node.props?.['href'] ?? '')),\n )\n if (linked) return null\n const home = [...(input.homeId ? [{ screenId: input.homeId }] : []), { href: '/' }]\n const added = aiLayoutWithMenuChanges(\n nodes as unknown as Record<string, unknown>,\n ['header'],\n { ...aiNoMenuChanges(), add: [{ parent: null, label: input.blog.label, to: { href: input.blog.href }, after: home }] },\n { newId: () => `ai_nav_${createResourceUid()}` },\n )\n return (added.nodes as unknown as NodesMap | null) ?? null\n}\n\n/**\n * Puts the blog's header entry back on a live start whose posts Try again\n * wrote (AGL-3747), as a new live version of the layout its published pages\n * render inside, in one batch with the publish outbox entry that drops the\n * live site's cached pages, the drop itself attempted at once. Returns\n * whether the entry went live; never throws for a layout it cannot change.\n */\nexport async function aiRestoreGuidedBlogEntry(\n firestore: Firestore,\n input: {\n job: Pick<AiJob, '$id' | 'hostId'>\n /** The start's published pages: the layout they share is the one changed. */\n pageIds: readonly string[]\n /** The published home page, which the blog's entry follows. */\n homeId?: string | null\n blog: AiSiteBlogEntry\n now: Date\n },\n deps: Pick<AiSitePublishDeps, 'dropCache'> = {},\n): Promise<boolean> {\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n const hostId = input.job.hostId ?? ''\n if (!hostId || !input.pageIds.length) return false\n const layoutId = await aiPagesLayoutId(firestore, hostId, input.pageIds)\n if (!layoutId) return false\n const write = await aiLayoutVersionWrite(firestore, {\n hostId,\n layoutId,\n transform: (nodes) => aiLayoutWithBlogEntry(nodes, { blog: input.blog, homeId: input.homeId ?? null }),\n storeLinks: null,\n jobId: input.job.$id,\n now: input.now,\n displayName: 'Navigation for the blog',\n })\n if (!write?.version) return false\n const batch = firestore.batch()\n batch.create(write.versionRef, write.version)\n batch.set(write.layoutRef, { versionId: write.versionRef.id, updatedAt: input.now }, { merge: true })\n // A layout change reaches every page, so the announce asks for the whole site.\n const outboxRef = firestore.collection('publishOutbox').doc(createResourceUid())\n batch.set(outboxRef, {\n hostId,\n paths: [SCREEN_ROOT_PATH],\n createdAt: FieldValue.serverTimestamp(),\n attempts: 0,\n entireHost: true,\n })\n await batch.commit()\n const dropped = await dropCache({ hostIds: [hostId], reason: 'guided AI site start linked its blog' })\n if (dropped.complete) await outboxRef.delete().catch(() => undefined)\n return true\n}\n\n/**\n * A retry's publish merged into the start's first (AGL-3730): the pages it\n * put live join the published list, a page it published leaves the drafts,\n * and a page it left a draft is reported with its newest reason.\n */\nexport function aiMergeSitePublish(previous: AiJobSitePublish, retried: AiJobSitePublish): AiJobSitePublish {\n const now = new Set([...retried.published, ...retried.drafts].map((page) => page.id))\n return {\n liveUrl: retried.liveUrl ?? previous.liveUrl,\n published: [...previous.published.filter((page) => !now.has(page.id)), ...retried.published],\n drafts: [...previous.drafts.filter((page) => !now.has(page.id)), ...retried.drafts],\n }\n}\n\n/**\n * Publishes the pages a guided site start built. Never throws for a page; a\n * Firestore failure of the publish write itself reports every page as a\n * draft, for the same reason, and is logged.\n */\nexport async function aiPublishGuidedSite(\n firestore: Firestore,\n input: {\n job: Pick<AiJob, '$id' | 'orgId' | 'hostId'>\n outputs: readonly AiJobOutput[]\n now: Date\n /** The start owed its blog's posts and wrote none (AGL-3660): its links to the blog come out. */\n blogUnwritten?: boolean\n /** Paths the layout links that the start did not write, such as a store page (AGL-3676): their links come out. */\n unwrittenHrefs?: readonly string[]\n /** A store's links a build drafted into the site's own layout (AGL-3676), which go live with its pages. */\n storeLinks?: AiSitePublishStoreLinks | null\n /**\n * The start published once already, and Try again rebuilt what failed\n * (AGL-3730): only `outputs` go live, beside what is. The home address is\n * never taken from the starter here, the starter is never retired, and\n * `site_published` is not sent again; a retried page at `/` that the\n * starter still holds stays a draft and says so.\n */\n retry?: boolean\n /**\n * The language the plan says the brief and copy are in (AGL-3750): the\n * site publishes in it, where `aiSiteLanguageUpdates` says so.\n */\n language?: string | null\n },\n deps: AiSitePublishDeps = {},\n): Promise<AiJobSitePublish> {\n const sendSitePublished = deps.sendSitePublished ?? sendGa4SitePublished\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n const { job, now } = input\n const hostId = job.hostId ?? ''\n const pages = input.outputs.filter(\n (output, index, all) =>\n output.resource === 'screen' &&\n (output.hostId ?? hostId) === hostId &&\n all.findIndex((other) => other.resource === 'screen' && other.id === output.id) === index,\n )\n const hostRef = firestore.collection('hosts').doc(hostId)\n const host = await hostRef.get()\n const result: AiJobSitePublish = {\n liveUrl: aiSiteLiveUrl({ cname: host.get('cname'), subdomain: host.get('subdomain') }),\n published: [],\n drafts: [],\n }\n if (!host.exists || !pages.length) return result\n\n const before = { ...((host.get('screens') ?? {}) as Record<string, string>) }\n const starter = (host.get('defaultHomeScreenId') as string | undefined) || null\n // A retry never takes `/` from the starter (AGL-3730): it holds it like any page.\n const placeholder = input.retry ? null : starter\n const routing = { ...before }\n const entries: Record<string, string> = {}\n const accepted: Array<{ id: string; label: string; path: string; slug: string }> = []\n for (const page of pages) {\n const snapshot = await hostRef.collection('screens').doc(page.id).get()\n const label = String(snapshot.get('displayName') ?? page.label ?? '') || page.label\n if (!snapshot.exists || snapshot.get('deletedAt') != null) {\n result.drafts.push({ id: page.id, label, reason: AI_SITE_PUBLISH_DELETED })\n continue\n }\n const slug = normalizeScreenSlug(String(snapshot.get('slug') ?? ''))\n if (!slug) {\n result.drafts.push({ id: page.id, label, reason: AI_SITE_PUBLISH_NO_ADDRESS })\n continue\n }\n const owner = blockingRouteOwner(routing, slug, placeholder)\n if (owner && owner !== page.id) {\n result.drafts.push({ id: page.id, label, reason: aiSitePublishTakenCopy(slug) })\n continue\n }\n routing[page.id] = slug\n entries[page.id] = slug\n accepted.push({ id: page.id, label, path: slug, slug })\n }\n if (!accepted.length) return result\n\n // The first real home page replaces the placeholder in the same write.\n const home = accepted.find((page) => page.path === SCREEN_ROOT_PATH) ?? null\n const releases =\n home && placeholder && placeholder !== home.id && before[placeholder] === SCREEN_ROOT_PATH\n ? placeholder\n : null\n // An untouched starter home (still its one first version) is retired to the\n // trash; one its owner edited stays in Pages as their draft.\n const retire = releases\n ? (await hostRef.collection('screens').doc(releases).collection('versions').limit(2).get()).size <= 1\n : false\n\n // The header of the layout the pages render inside learns their entries.\n const layoutWrite = await aiNavigationLayoutWrite(firestore, {\n hostId,\n pageIds: accepted.map((page) => page.id),\n entries: navEntriesOf(pages).filter((entry) => entries[entry.screenId]),\n droppedHrefs: [...aiSiteUnwrittenBlogHrefs(input.blogUnwritten), ...(input.unwrittenHrefs ?? [])],\n retiredHomeId: releases,\n homeId: home?.id ?? null,\n jobId: job.$id,\n now,\n storeLinks: input.storeLinks ?? null,\n }).catch((error: unknown) => {\n console.error('ai site publish: navigation not applied', { hostId, jobId: job.$id, error })\n return null\n })\n // A store's links drafted into a layout the pages' navigation did not touch go live on their own.\n const storeLinks = input.storeLinks ?? null\n const storeLinksWrite =\n storeLinks && layoutWrite?.layoutRef.id !== storeLinks.layoutId\n ? await aiLayoutVersionWrite(firestore, {\n hostId,\n layoutId: storeLinks.layoutId,\n transform: () => null,\n storeLinks,\n jobId: job.$id,\n now,\n }).catch((error: unknown) => {\n console.error('ai site publish: store links not applied', { hostId, jobId: job.$id, error })\n return null\n })\n : null\n const layoutWrites = [layoutWrite, storeLinksWrite].filter((write): write is LayoutWrite => Boolean(write))\n\n const paths = [\n ...new Set(\n [\n ...Object.values(entries),\n ...(releases ? [SCREEN_ROOT_PATH] : []),\n ].map((path) => screenRoutePathToUrl(path)),\n ),\n ]\n const batch = firestore.batch()\n const hostUpdates: Record<string, unknown> = { updatedAt: now }\n for (const [id, path] of Object.entries(entries)) hostUpdates[`screens.${id}`] = path\n if (releases) {\n hostUpdates[`screens.${releases}`] = FieldValue.delete()\n hostUpdates['defaultHomeScreenId'] = FieldValue.delete()\n batch.set(\n hostRef.collection('screens').doc(releases),\n { publishedAt: FieldValue.delete(), ...(retire ? { deletedAt: now } : {}) },\n { merge: true },\n )\n } else if (placeholder && entries[placeholder]) {\n hostUpdates['defaultHomeScreenId'] = FieldValue.delete()\n }\n // The site's language, from its plan (AGL-3750): every page's `<html lang>`\n // reads it, so the announce below asks for the whole site.\n const language = aiSiteLanguageUpdates(\n { locales: host.get('locales'), defaultLocale: host.get('defaultLocale') },\n input.language,\n )\n if (language) Object.assign(hostUpdates, language)\n const entireHost = layoutWrites.length > 0 || language !== null\n batch.update(hostRef, hostUpdates)\n for (const page of accepted) {\n batch.set(hostRef.collection('screens').doc(page.id), { slug: page.slug, publishedAt: now }, { merge: true })\n }\n for (const write of layoutWrites) {\n if (write.version) batch.create(write.versionRef, write.version)\n batch.set(write.layoutRef, { versionId: write.versionRef.id, updatedAt: now }, { merge: true })\n }\n // The announce, written down in the publish's own batch (AGL-2575): a\n // layout change reaches every page, so it asks for the whole site.\n const outboxRef = firestore.collection('publishOutbox').doc(createResourceUid())\n batch.set(outboxRef, {\n hostId,\n paths: paths.length ? paths : [SCREEN_ROOT_PATH],\n createdAt: FieldValue.serverTimestamp(),\n attempts: 0,\n ...(entireHost ? { entireHost: true } : {}),\n })\n try {\n await batch.commit()\n } catch (error) {\n console.error('ai site publish failed', { hostId, jobId: job.$id, error })\n for (const page of accepted) result.drafts.push({ id: page.id, label: page.label, reason: AI_SITE_PUBLISH_FAILED })\n return result\n }\n result.published = accepted.map(({ id, label, path }) => ({ id, label, path: screenRoutePathToUrl(path) }))\n\n // The live site's cached pages go now; the outbox entry stays for the\n // drain unless the drop certainly happened.\n const dropped = await dropCache({\n hostIds: [hostId],\n reason: 'guided AI site start published',\n ...(entireHost ? {} : { paths: { [hostId]: paths } }),\n })\n if (dropped.complete) await outboxRef.delete().catch(() => undefined)\n // A site that came alive with nobody's browser on the publish (AGL-1589),\n // announced once: a retry's pages join a site already announced (AGL-3730).\n if (!input.retry) await sendSitePublished({ hostId, firstPublish: isFirstPublishedRoute(before, placeholder) })\n return result\n}\n\ninterface LayoutWrite {\n layoutRef: FirebaseFirestore.DocumentReference\n versionRef: FirebaseFirestore.DocumentReference\n /** The new version to create; `null` where the live version becomes one already written (a store's links draft). */\n version: Record<string, unknown> | null\n}\n\n/**\n * The new live version of the layout the published pages render inside, with\n * their navigation entries and the home link moved off a retired starter;\n * `null` when there is nothing to change or no one layout to change.\n */\nasync function aiNavigationLayoutWrite(\n firestore: Firestore,\n input: {\n hostId: string\n pageIds: readonly string[]\n entries: readonly NavEntry[]\n droppedHrefs: readonly string[]\n retiredHomeId: string | null\n homeId: string | null\n jobId: string\n now: Date\n storeLinks?: AiSitePublishStoreLinks | null\n },\n): Promise<LayoutWrite | null> {\n if (!input.entries.length && !input.retiredHomeId && !input.droppedHrefs.length && !input.storeLinks) return null\n const layoutId = await aiPagesLayoutId(firestore, input.hostId, input.pageIds)\n if (!layoutId) return null\n return aiLayoutVersionWrite(firestore, {\n hostId: input.hostId,\n layoutId,\n transform: (nodes) => aiLayoutWithNavigation(nodes, input),\n storeLinks: input.storeLinks ?? null,\n jobId: input.jobId,\n now: input.now,\n })\n}\n\n/** The one layout the pages render inside, by their current versions; `null` where they do not share one. */\nasync function aiPagesLayoutId(firestore: Firestore, hostId: string, pageIds: readonly string[]): Promise<string | null> {\n const hostRef = firestore.collection('hosts').doc(hostId)\n const layoutIds = new Set<string>()\n for (const id of pageIds) {\n const screen = await hostRef.collection('screens').doc(id).get()\n const versionId = screen.get('versionId')\n const version =\n typeof versionId === 'string' && versionId\n ? await hostRef.collection('screens').doc(id).collection('versions').doc(versionId).get()\n : null\n const layoutId = version?.get('layoutId') ?? screen.get('layoutId')\n if (typeof layoutId === 'string' && layoutId) layoutIds.add(layoutId)\n }\n return layoutIds.size === 1 ? [...layoutIds][0] : null\n}\n\n/**\n * The new live version of one layout: `transform` applied to the version\n * live now. A store's links drafted into this layout (AGL-3676) start it from\n * that draft while the draft was made from the live version, and are added\n * to the live version otherwise; a draft with nothing more to add becomes\n * the live version as it is. `null` when nothing changes.\n */\nasync function aiLayoutVersionWrite(\n firestore: Firestore,\n input: {\n hostId: string\n layoutId: string\n transform: (nodes: NodesMap) => NodesMap | null\n storeLinks: AiSitePublishStoreLinks | null\n jobId: string\n now: Date\n /** The new version's name in the layout's versions. */\n displayName?: string\n },\n): Promise<LayoutWrite | null> {\n const { layoutId } = input\n const layoutRef = firestore.collection('hosts').doc(input.hostId).collection('layouts').doc(layoutId)\n const layout = await layoutRef.get()\n const currentVersionId = layout.get('versionId')\n if (!layout.exists || layout.get('deletedAt') != null || typeof currentVersionId !== 'string') return null\n const current = await layoutRef.collection('versions').doc(currentVersionId).get()\n const links = input.storeLinks?.layoutId === layoutId ? input.storeLinks : null\n const draftRef = links ? layoutRef.collection('versions').doc(links.versionId) : null\n const draft = draftRef ? await draftRef.get() : null\n const fromDraft = Boolean(draft?.exists && draft.get(STORE_LINKS_SOURCE_FIELD) === currentVersionId)\n const base = fromDraft && draft ? draft : current\n const nodes = base.exists ? decodeStoredNodes<NodesMap>(base.get('nodes')) : null\n if (!nodes) return null\n let next = input.transform(nodes)\n if (links && !fromDraft) {\n const added = aiLayoutWithStoreLinks((next ?? nodes) as never, links.links, links.screenPaths)\n next = (added.nodes as NodesMap | null) ?? next\n }\n // What a publish puts live has no hollow heading, column or menu (AGL-3735).\n next = (aiLayoutWithoutFrameHollows((next ?? nodes) as unknown as Record<string, unknown>) as NodesMap | null) ?? next\n const hollow = aiLayoutFrameHollows((next ?? nodes) as unknown as Record<string, unknown>)\n if (aiLayoutFrameIsHollow(hollow)) {\n console.error('ai site publish: a layout is still hollow after its repair', { layoutId, hollow: aiLayoutFrameHollowsSaid(hollow) })\n }\n if (!next) return fromDraft && draftRef ? { layoutRef, versionRef: draftRef, version: null } : null\n const packed = encodeStoredNodes(next)\n if (!packed) return null\n const versionRef = layoutRef.collection('versions').doc(createResourceUid())\n return {\n layoutRef,\n versionRef,\n version: {\n layoutId,\n hostId: input.hostId,\n displayName: input.displayName ?? 'Navigation for the new pages',\n nodes: Buffer.from(packed),\n createdAt: input.now,\n updatedAt: input.now,\n aiJobId: input.jobId,\n },\n }\n}\n"],"names":["isFirstPublishedRoute","createResourceUid","hostPublicOrigin","blockingRouteOwner","normalizeScreenSlug","SCREEN_ROOT_PATH","screenRoutePathToUrl","resolvePageLocale","decodeStoredNodes","encodeStoredNodes","dropPluginSiteCache","sendGa4SitePublished","FieldValue","aiLayoutFrameHollows","aiLayoutFrameHollowsSaid","aiLayoutFrameIsHollow","aiLayoutRepairFrameHollows","aiLayoutWithoutFrameHollows","aiPlanLanguage","AI_SITE_BLOG_SLUGS","aiLayoutWithStoreLinks","aiLayoutWithMenuChanges","aiNoMenuChanges","AI_STORE_LINKS_SOURCE_FIELD","STORE_LINKS_SOURCE_FIELD","aiJobPublishesBuild","job","kind","inputs","aiSiteLanguageUpdates","host","language","code","locales","Array","isArray","filter","one","trim","length","current","defaultLocale","aiJobPublishesSite","aiSiteLiveUrl","text","value","origin","cname","subdomain","AI_SITE_PUBLISH_DELETED","AI_SITE_PUBLISH_NO_ADDRESS","aiSitePublishTakenCopy","path","AI_SITE_PUBLISH_FAILED","navEntriesOf","outputs","entries","output","resource","navigation","proposal","label","some","entry","screenId","id","push","aiSiteUnwrittenBlogHrefs","blogUnwritten","map","slug","aiLayoutWithNavigation","nodes","input","node","Object","props","changed","dropped","Set","droppedHrefs","size","gone","componentId","has","String","values","child","links","retiredHomeId","homeId","link","linked","Boolean","missing","added","add","parent","to","newId","aiLayoutWithBlogEntry","blogHrefs","blog","href","home","after","aiRestoreGuidedBlogEntry","firestore","deps","dropCache","hostId","pageIds","layoutId","aiPagesLayoutId","write","aiLayoutVersionWrite","transform","storeLinks","jobId","$id","now","displayName","version","batch","create","versionRef","set","layoutRef","versionId","updatedAt","merge","outboxRef","collection","doc","paths","createdAt","serverTimestamp","attempts","entireHost","commit","hostIds","reason","complete","delete","catch","undefined","aiMergeSitePublish","previous","retried","published","drafts","page","liveUrl","aiPublishGuidedSite","accepted","sendSitePublished","pages","index","all","findIndex","other","hostRef","get","result","exists","before","starter","placeholder","retry","routing","snapshot","owner","find","releases","retire","limit","layoutWrite","aiNavigationLayoutWrite","unwrittenHrefs","error","console","storeLinksWrite","layoutWrites","hostUpdates","publishedAt","deletedAt","assign","update","firstPublish","layoutIds","screen","layout","currentVersionId","draftRef","draft","fromDraft","base","next","screenPaths","hollow","packed","Buffer","from","aiJobId"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SACEC,kBAAkB,EAClBC,mBAAmB,EACnBC,gBAAgB,EAChBC,oBAAoB,QACf,sCAAqC;AAC5C,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,iBAAiB,EAAEC,iBAAiB,QAAQ,sCAAqC;AAC1F,SAASC,mBAAmB,QAAQ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2C,SAAS,CAAC5C;IAC3B,IAAIgB,SAAS,CAAC2G,WAAW;YAEfpG;QADR,MAAMA,QAAQ3E,uBAAwBiL,eAAAA,OAAQ7H,OAAiBgB,MAAMA,KAAK,EAAEA,MAAM8G,WAAW;QAC7FD,QAAQtG,eAAAA,MAAMvB,KAAK,YAAXuB,eAAmCsG;IAC7C;IACA,6EAA6E;IAC7EA,QAAQpL,+BAAAA,4BAA6BoL,eAAAA,OAAQ7H,kBAArCvD,+BAA0GoL;IAClH,MAAME,SAAS1L,qBAAsBwL,eAAAA,OAAQ7H;IAC7C,IAAIzD,sBAAsBwL,SAAS;QACjCnB,QAAQD,KAAK,CAAC,8DAA8D;YAAEnE;YAAUuF,QAAQzL,yBAAyByL;QAAQ;IACnI;IACA,IAAI,CAACF,MAAM,OAAOF,aAAaF,WAAW;QAAElE;QAAWF,YAAYoE;QAAUvE,SAAS;IAAK,IAAI;IAC/F,MAAM8E,SAAS/L,kBAAkB4L;IACjC,IAAI,CAACG,QAAQ,OAAO;IACpB,MAAM3E,aAAaE,UAAUK,UAAU,CAAC,YAAYC,GAAG,CAACpI;IACxD,OAAO;QACL8H;QACAF;QACAH,SAAS;YACPV;YACAF,QAAQrC,MAAMqC,MAAM;YACpBW,WAAW,GAAEhD,qBAAAA,MAAMgD,WAAW,YAAjBhD,qBAAqB;YAClCD,OAAOiI,OAAOC,IAAI,CAACF;YACnBjE,WAAW9D,MAAM+C,GAAG;YACpBS,WAAWxD,MAAM+C,GAAG;YACpBmF,SAASlI,MAAM6C,KAAK;QACtB;IACF;AACF"}
@@ -18,7 +18,7 @@ import { type AiIconLibraryEntry } from '../runtime/ai-icon-library';
18
18
  import { type AiLayoutBand, type AiLayoutBlock, type AiLayoutSection, type AiLayoutSettlement } from './ai-layout-language';
19
19
  import { type AiLayoutDesign, type AiLayoutDesignChoices, type AiLayoutGroupVariant } from './ai-layout-design';
20
20
  import { type AiLayoutDestination, type AiLayoutLinkScope, type AiLayoutTargets } from './ai-layout-links';
21
- import { AiLayoutTreeBuilder, type AiLayoutRawTree } from './ai-layout-tree';
21
+ import { aiLayoutSpans, AiLayoutTreeBuilder, type AiLayoutRawTree } from './ai-layout-tree';
22
22
  /**
23
23
  * The layout language compiler (AGL-3660): a page designed in the language
24
24
  * (`ai-layout-language.ts`) becomes the element tree the page stores — built
@@ -171,12 +171,13 @@ export interface SectionScope {
171
171
  export declare function aiCompileLayoutPage(sections: readonly AiLayoutSection[], plan: AiLayoutPagePlan, targets: AiLayoutTargets, options: AiLayoutCompileOptions): AiLayoutCompiledPage;
172
172
  /** A band's own colors, as palette roles: the dark band pins the scheme instead. */
173
173
  export declare function bandSx(band: AiLayoutBand): Record<string, unknown> | null;
174
- /** Spans out of twelve for relative widths: each at least three, summing to twelve. */
175
- export declare function aiLayoutSpans(weights: readonly number[]): number[];
174
+ export { aiLayoutSpans };
176
175
  export declare function compileRow(scope: SectionScope, columns: Array<{
177
176
  column: AiLayoutBlock[];
178
177
  weight: number;
179
- }>): string;
178
+ }>,
179
+ /** How the columns sit against each other: centered on a page, top-aligned in a footer (AGL-3735). */
180
+ alignItems?: 'center' | 'flex-start'): string;
180
181
  export type Room = 'full' | 'half' | 'narrow';
181
182
  /** A column of blocks, top to bottom, with buttons side by side; `null` when nothing in it compiles. */
182
183
  export declare function compileFlow(scope: SectionScope, blocks: readonly AiLayoutBlock[], room: Room): string | null;
@@ -220,6 +221,8 @@ export declare const AI_LAYOUT_STORE_EMPTY: {
220
221
  /** Said where the site has no page to get in touch on. */
221
222
  readonly textAlone: "Our first pieces are being finished now. Check back soon.";
222
223
  };
224
+ /** The words of the link under each record's card to its own page (AGL-3727). */
225
+ export declare const AI_LAYOUT_RECORD_LINK_LABEL = "View details";
223
226
  /** The fields a record's card shows: its name, a kicker line and its words, each by id. */
224
227
  export declare function aiLayoutRecordCardFields(fields: readonly {
225
228
  id: string;
@@ -23,10 +23,10 @@ import { aiPageScrollInteraction } from "../runtime/ai-page-links.js";
23
23
  import { aiLayoutFitText, aiLayoutQuoteGap, aiLayoutWords } from "./ai-layout-copy.js";
24
24
  import { AI_LAYOUT_GROUP_KINDS, AI_LAYOUT_MAX_ITEMS } from "./ai-layout-language.js";
25
25
  import { aiLayoutDesignChoices, aiLayoutFamily, aiLayoutGroupVariant } from "./ai-layout-design.js";
26
- import { AI_LAYOUT_FEATURED_RECORDS, AI_LAYOUT_LISTING_ELEMENTS, aiLayoutListingAt } from "./ai-layout-listings.js";
26
+ import { AI_LAYOUT_FEATURED_RECORDS, AI_LAYOUT_LISTING_ELEMENTS, aiLayoutListingAt, aiLayoutRecordHref } from "./ai-layout-listings.js";
27
27
  import { aiStorefrontItemIcons } from "./ai-layout-storefront.js";
28
28
  import { aiLayoutRenamedLabel, aiLayoutResolveLink } from "./ai-layout-links.js";
29
- import { AI_LAYOUT_FRAMES, AiLayoutTreeBuilder } from "./ai-layout-tree.js";
29
+ import { aiLayoutSpans, AI_LAYOUT_FRAMES, AiLayoutTreeBuilder } from "./ai-layout-tree.js";
30
30
  /**
31
31
  * What a section is called to a screen reader: its plan name, with any note
32
32
  * the plan left in brackets taken out. A live blog plan (2026-10-09) named a
@@ -579,24 +579,9 @@ function sameShape(columns) {
579
579
  };
580
580
  }
581
581
  // ── A row of columns ──────────────────────────────────────────────────────
582
- /** Spans out of twelve for relative widths: each at least three, summing to twelve. */ export function aiLayoutSpans(weights) {
583
- const total = weights.reduce((sum, weight)=>sum + weight, 0);
584
- const spans = weights.map((weight)=>Math.max(3, Math.round(weight / total * 12)));
585
- let over = spans.reduce((sum, span)=>sum + span, 0) - 12;
586
- while(over !== 0){
587
- // Take from (or give to) the widest column that can spare it.
588
- const order = spans.map((span, position)=>({
589
- span,
590
- position
591
- })).sort((a, b)=>over > 0 ? b.span - a.span : a.span - b.span);
592
- const pick = order.find((entry)=>over > 0 ? entry.span > 3 : true);
593
- if (!pick) break;
594
- spans[pick.position] += over > 0 ? -1 : 1;
595
- over += over > 0 ? -1 : 1;
596
- }
597
- return spans;
598
- }
599
- export function compileRow(scope, columns) {
582
+ // Spans out of twelve live with the tree, so a frame's repair reads them without the compiler (AGL-3735).
583
+ export { aiLayoutSpans };
584
+ export function compileRow(scope, columns, /** How the columns sit against each other: centered on a page, top-aligned in a footer (AGL-3735). */ alignItems = 'center') {
600
585
  const tree = scope.page.tree;
601
586
  const spans = aiLayoutSpans(columns.map((entry)=>entry.weight));
602
587
  const items = columns.map((entry, position)=>{
@@ -613,7 +598,7 @@ export function compileRow(scope, columns) {
613
598
  container: true,
614
599
  spacing: columns.length >= 3 ? '4' : '6'
615
600
  }, {
616
- alignItems: 'center'
601
+ alignItems
617
602
  }, items, 'row');
618
603
  }
619
604
  /** A column of blocks, top to bottom, with buttons side by side; `null` when nothing in it compiles. */ export function compileFlow(scope, blocks, room) {
@@ -2581,6 +2566,7 @@ function listingSection(scope, blocks, placed) {
2581
2566
  ], 'posts');
2582
2567
  }
2583
2568
  // ── A dataset's records (AGL-3616) ───────────────────────────────────────
2569
+ /** The words of the link under each record's card to its own page (AGL-3727). */ export const AI_LAYOUT_RECORD_LINK_LABEL = 'View details';
2584
2570
  /** A field whose name says it is a record's kicker: its category, role, time or place. */ const RECORD_KICKER = /\b(category|categories|type|kind|role|title|position|section|course|date|dates|time|times|when|day|days|location|place|where|venue|city|duration|level|tag|tags)\b/i;
2585
2571
  /** A field whose name says it is a record's words: its description, bio or answer. */ const RECORD_BODY = /\b(description|summary|details?|about|bio|biography|answer|text|notes?|body|blurb|overview|excerpt|ingredients|includes)\b/i;
2586
2572
  /** A dataset of questions and answers, listed as a ruled list rather than cards. */ const RECORD_QUESTIONS = /\b(faqs?|questions?|q ?& ?a)\b/i;
@@ -2639,6 +2625,9 @@ function listingSection(scope, blocks, placed) {
2639
2625
  }, textAlign), muted(scope), null, 'recordBody') : null;
2640
2626
  const photoField = !questions && listing.imageField ? listing.imageField : null;
2641
2627
  const opens = Boolean(photoField) && aiOpensGalleriesInLightbox(page);
2628
+ // Each card opens its record's own page where the dataset has one (AGL-3727):
2629
+ // `/{base}/{{item.<address>}}`, filled per record as the card repeats.
2630
+ const recordHref = aiLayoutRecordHref(listing);
2642
2631
  const portrait = ((_page_design = page.design) == null ? void 0 : _page_design.input.kind) === 'photography' || RECORD_PEOPLE.test(listing.name);
2643
2632
  const picture = photoField ? tree.add('image', _extends({
2644
2633
  src: `{{item.${photoField}}}`,
@@ -2648,13 +2637,23 @@ function listingSection(scope, blocks, placed) {
2648
2637
  loading: 'lazy'
2649
2638
  }, opens ? _extends({}, lightboxProps(scope), fields.title ? {
2650
2639
  lightboxCaption: `{{item.${fields.title}}}`
2651
- } : {}) : {}), {
2640
+ } : {}) : {}, recordHref && !opens ? {
2641
+ href: recordHref
2642
+ } : {}), {
2652
2643
  aspectRatio: portrait ? '4 / 5' : '4 / 3',
2653
2644
  borderRadius: 2
2654
2645
  }, null, 'recordImage') : null;
2646
+ const more = recordHref ? tree.add('muiScreenLink', {
2647
+ children: AI_LAYOUT_RECORD_LINK_LABEL,
2648
+ href: recordHref,
2649
+ renderAs: 'link',
2650
+ color: 'inherit'
2651
+ }, {
2652
+ alignSelf: scope.centered && !questions ? 'center' : 'flex-start'
2653
+ }, null, 'recordLink') : null;
2655
2654
  page.settled.push({
2656
2655
  at: scope.at,
2657
- what: `${listing.name} listed from its dataset${questions ? ' as a ruled list' : picture ? ' as picture cards' : ' as cards'}`
2656
+ what: `${listing.name} listed from its dataset${questions ? ' as a ruled list' : picture ? ' as picture cards' : ' as cards'}${recordHref ? `, each linking its page under /${listing.recordBase}` : ''}`
2658
2657
  });
2659
2658
  const card = questions ? tree.add('muiStack', {
2660
2659
  spacing: '1'
@@ -2663,7 +2662,8 @@ function listingSection(scope, blocks, placed) {
2663
2662
  pt: 3
2664
2663
  }, [
2665
2664
  title,
2666
- body
2665
+ body,
2666
+ more
2667
2667
  ], 'record') : tree.add('muiStack', _extends({
2668
2668
  spacing: picture ? '1.5' : '1'
2669
2669
  }, scope.centered ? {
@@ -2672,7 +2672,8 @@ function listingSection(scope, blocks, placed) {
2672
2672
  picture,
2673
2673
  kicker,
2674
2674
  title,
2675
- body
2675
+ body,
2676
+ more
2676
2677
  ], 'record');
2677
2678
  return tree.add(AI_LAYOUT_LISTING_ELEMENTS.records, _extends({
2678
2679
  repeatDataset: listing.datasetId