@aglyn/plugins-ai 1.15.0 → 1.15.2
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.
- package/package.json +17 -17
- package/src/lib/components/ai-site-import-start.component.js +3 -1
- package/src/lib/components/ai-site-import-start.component.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +18 -2
- package/src/lib/jobs/ai-job-import-step.js +24 -8
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +2 -0
- package/src/lib/jobs/ai-job-page-language.js +72 -37
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +5 -3
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.d.ts +1 -0
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +26 -1
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-improve.d.ts +59 -6
- package/src/lib/jobs/ai-site-import-improve.js +149 -19
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
- package/src/lib/jobs/ai-site-import-plan.js +1 -1
- package/src/lib/jobs/ai-site-import-plan.js.map +1 -1
- package/src/lib/model/ai-credit-estimate.d.ts +16 -0
- package/src/lib/model/ai-credit-estimate.js +14 -0
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +2 -0
- package/src/lib/model/ai-site-import-fidelity.js +7 -1
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-view.d.ts +3 -1
- package/src/lib/model/ai-site-import-view.js +8 -3
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +27 -2
- package/src/lib/model/ai-site-import.js +63 -14
- package/src/lib/model/ai-site-import.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import.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\n/*==========================================\n * BRING MY SITE: THE WHOLE SITE, IN REVIEWED WAVES (AGL-3976, parent AGL-3973).\n *\n * The `import` job reads a website the workspace has PROVED it owns\n * (AGL-3974's claims) and brings it in as draft pages of a new site. This\n * module is the job's plan of record, pure, so the step, the doors, the\n * console and the specs read one set of rules:\n *\n * - **The inventory.** The crawl's pages, grouped: the MAIN pages (home, the\n * pages its menu links, every top-level page, and any page that belongs to\n * no collection), then each COLLECTION (an address prefix holding at least\n * `AI_SITE_IMPORT_COLLECTION_MIN` pages: `/blog/…`, `/news/…`, a dated\n * `/2024/05/…` archive).\n * - **Never past the plan.** Pages are kept in that order until the site's\n * room under its plan's page count is used; the rest are LEFT OUT, said so\n * with the reason, never dropped silently. So a plan's limit always leaves\n * out a collection's tail before it leaves out a main page.\n * - **Waves.** The kept pages are cut into waves of at most\n * `AI_SITE_IMPORT_WAVE_PAGES`. The first wave is the main pages, with the\n * site's header and footer built first; each later wave is one\n * collection's next slice, so a review is about one kind of page at a\n * time (\"Blog, 1 of 3\"). A wave runs, then waits for the person: nothing\n * starts the next one but them.\n * - **The price.** An imported page is an AI page (`AI_MEASURED_IMPORT_CREDITS`,\n * about 27 credits); a wave is quoted before it starts as its pages and,\n * for the first, its header and footer. Once the step says how each page\n * is built, a page copied as it is costs its listing and a page Aglyn AI\n * arranges its arrangement, and the quote names both (AGL-4083).\n * - **Home first (AGL-4083).** The read's verdict (`aiSiteImportReadVerdict`)\n * stops an import whose home page could not be read before anything is\n * planned, quoted or spent: a site seen without its home page is not the\n * site. The person is told why and checks again.\n *=========================================*/\n\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\nimport { videoEmbedOf } from '@aglyn/aglyn/plugin-manager/video-embed-provider'\nimport type { SiteImportBlock, SiteImportForm, SiteImportVideo } from '../site-import/site-import-html'\nimport { aiCreditRangeOrdered, aiCreditRangeText, AI_MEASURED_IMPORT_CREDITS, AI_MEASURED_PAID_SITE_CREDITS, type AiCreditRange } from './ai-credit-estimate'\nimport { aiMediaCreditsPerPicture } from './ai-media-credits'\nimport type { AiJob, AiJobItemLedger } from './ai-jobs.types'\n\n/** The job kind. */\nexport const AI_SITE_IMPORT_KIND = 'import' as const\n\n/** The input naming the proved domain the job brings in. */\nexport const AI_SITE_IMPORT_DOMAIN_INPUT = 'domain'\n\n/** The most pages one wave brings in. */\nexport const AI_SITE_IMPORT_WAVE_PAGES = 10\n\n/**\n * The most pages one import reads, whatever the plan allows: an unlimited\n * plan is still one crawl's worth, and the crawl's own time budget may stop\n * sooner (the inventory then says so). Only pages count: a file a link\n * points at is never fetched as one (AGL-4106), so aglyn.com's 209 pages fit\n * with room where 136 press-kit files once took 136 of 200.\n */\nexport const AI_SITE_IMPORT_MAX_PAGES = 400\n\n/** The fewest pages under one address prefix that make it a collection. */\nexport const AI_SITE_IMPORT_COLLECTION_MIN = 3\n\n/** The most photos brought in from one page. */\nexport const AI_SITE_IMPORT_IMAGES_PER_PAGE = 8\n\n/**\n * The most characters of one page's text a wave keeps for the page step's\n * prompt, which reads no more than this; every word is kept on the read's\n * `blocks` (AGL-4083).\n */\nexport const AI_SITE_IMPORT_PAGE_TEXT_MAX_CHARS = 6_000\n\n/** The most sections one imported page is planned with: one for every second-level heading (AGL-4083). */\nexport const AI_SITE_IMPORT_MAX_SECTIONS = 24\n\n/** The most blocks of one page a wave's read keeps. */\nexport const AI_SITE_IMPORT_READ_MAX_BLOCKS = 2_000\n\n/** The most characters of one page's blocks a wave's read keeps: a long policy is 40,000. */\nexport const AI_SITE_IMPORT_READ_MAX_CHARS = 120_000\n\n/** The most characters one page's layout keeps on the job document (AGL-4106): its icons' drawings go first. */\nexport const AI_SITE_IMPORT_LAYOUT_MAX_CHARS = 48_000\n\n/**\n * The most characters of blocks (and their layouts, AGL-4106) the reads of one import hold at once: they\n * ride the job document, which Firestore caps at 1 MiB, beside the\n * inventory and the ledger. A wave's later page past it keeps what fits and\n * says it was cut.\n */\nexport const AI_SITE_IMPORT_WAVE_READ_MAX_CHARS = 400_000\n\n/**\n * A collection's page longer than this is prose: a policy, an article, a\n * long story (AGL-4083). A collection's page is copied as it is whatever its\n * length, and since AGL-4106 a main page is arranged whatever its length:\n * `/product` at 1,072 words is laid out as its source lays it out, not copied\n * as one column.\n */\nexport const AI_SITE_IMPORT_PROSE_WORDS = 900\n\n/** The answers bot protection and firewalls turn a crawler away with: asked to sign in, refused, or told to slow down. */\nexport const AI_SITE_IMPORT_BLOCKED_STATUSES: ReadonlySet<number> = new Set([401, 403, 429])\n\n/** The most characters a section's name, a page's title or a label keeps. */\nexport const AI_SITE_IMPORT_LABEL_MAX_CHARS = 60\n\n/** A page with fewer words than this and no photo has nothing to bring in. */\nexport const AI_SITE_IMPORT_MIN_WORDS = 5\n\n/** The item ledger slot of the site's header and footer. */\nexport const AI_SITE_IMPORT_FRAME_SLOT = 'frame'\n\n/** The ceiling one imported page reserves: its answer pass and its listing pass, at 50 each. */\nexport const AI_SITE_IMPORT_PAGE_CEILING_CREDITS = 100\n\n/** The ceiling a page copied as it is reserves: its listing pass alone. */\nexport const AI_SITE_IMPORT_COPIED_CEILING_CREDITS = 50\n\n/** The ceiling the header and footer reserve: one answer at 50. */\nexport const AI_SITE_IMPORT_FRAME_CEILING_CREDITS = 50\n\n/** The most left-out pages listed by address; the rest are counted. */\nexport const AI_SITE_IMPORT_LEFT_OUT_LISTED = 60\n\n/** A page the crawl read, as the inventory keeps it: no text, only what plans it. */\nexport interface AiSiteImportListedPage {\n url: string\n path: string\n title: string\n foundBy: 'home' | 'sitemap' | 'link'\n words: number\n images: number\n}\n\nexport type AiSiteImportGroupKind = 'main' | 'collection'\n\nexport interface AiSiteImportGroup {\n /** `main`, or `c:<prefix>` for a collection. */\n id: string\n label: string\n kind: AiSiteImportGroupKind\n /** Pages of the group the crawl read, kept or not. */\n pages: number\n}\n\n/** Why a page the site has is not brought in. */\nexport type AiSiteImportLeftOutReason =\n /** Past the site's room under its plan's page count. */\n | 'plan-limit'\n /** robots.txt keeps AglynBot off it. */\n | 'robots'\n /** A sign-in page: refused outright. */\n | 'login-form'\n /** No text and no photo: nothing to bring in. */\n | 'empty'\n /** It could not be read: an error, no answer, or not a web page. */\n | 'unreadable'\n /** The site's bot protection or firewall turned AglynBot away (401, 403 or 429). */\n | 'blocked'\n /** Over the size one page may be. */\n | 'too-large'\n /** It sends visitors to another website. */\n | 'off-site'\n /** The read stopped (its clock, its bytes, its page count) before it got to it (AGL-4083). */\n | 'not-reached'\n /** A link to a file (a download, a PDF with no extension), not a page (AGL-4106). */\n | 'file'\n /** Another address of a page already found: a gallery photo's link, a home page's second address (AGL-4152). */\n | 'duplicate'\n /** The cart, checkout or account screen the site's platform makes, not a page of the owner's (AGL-4152). */\n | 'system-page'\n /** The site itself answers that the address does not exist (404 or 410): a link or sitemap line gone stale (AGL-4152). */\n | 'missing'\n\nexport const AI_SITE_IMPORT_LEFT_OUT_REASONS: readonly AiSiteImportLeftOutReason[] = [\n 'plan-limit',\n 'robots',\n 'login-form',\n 'empty',\n 'unreadable',\n 'blocked',\n 'too-large',\n 'off-site',\n 'not-reached',\n 'file',\n 'duplicate',\n 'system-page',\n 'missing',\n]\n\n/** The reasons that mean the page was there and AglynBot could not read it: the \"could not be read\" of what was found. */\nexport const AI_SITE_IMPORT_UNREAD_REASONS: readonly AiSiteImportLeftOutReason[] = ['unreadable', 'blocked', 'too-large', 'not-reached']\n\nexport interface AiSiteImportLeftOut {\n url: string\n path: string\n title: string\n reason: AiSiteImportLeftOutReason\n /** The path of the page a `duplicate` is another address of: where a link to it goes on the new site. */\n sameAs?: string\n}\n\n/** The left-out addresses that are other addresses of a kept page, as their path and that page's. */\nexport function aiSiteImportOtherAddresses(state: Partial<Pick<AiSiteImportState, 'leftOut'>>): Array<{ path: string; sameAs: string }> {\n const key = (path: string) => path.split('?')[0].replace(/\\/+$/, '') || '/'\n return (state.leftOut ?? []).flatMap((entry) =>\n entry.reason === 'duplicate' && entry.sameAs && key(entry.path) !== key(entry.sameAs) ? [{ path: key(entry.path), sameAs: key(entry.sameAs) }] : [],\n )\n}\n\n/** A photo brought into the site's media library, as a page places it. */\nexport interface AiSiteImportPhoto {\n mediaId: string\n src: string\n width?: number\n height?: number\n alt?: string\n /** The address on the old site it was read from, where a page that is copied places it (AGL-4084). */\n from?: string\n}\n\n/*------------------------------------------\n * The source's layout, as the reader reads it (AGL-4106)\n *-----------------------------------------*/\n\n/**\n * One line of a page, by its index in the page's main-region blocks\n * (`AiSiteImportPageRead.blocks`, 0-based). The layout holds no words of\n * its own: every word is a block's, placed once.\n */\nexport type SiteImportLineRef = number\n\n/** A section's background, in the layout language's bands. */\nexport type SiteImportBand = 'plain' | 'soft' | 'brand' | 'dark'\n\n/** How the source draws a button: filled, outlined, or as a link with button padding. */\nexport type SiteImportButtonStyle = 'primary' | 'secondary' | 'quiet'\n\n/** What a repeated group of the source is. */\nexport type SiteImportGroupKind = 'cards' | 'steps' | 'stats' | 'faq' | 'quotes' | 'logos' | 'pricing' | 'list' | 'text'\n\nexport const SITE_IMPORT_GROUP_KINDS: readonly SiteImportGroupKind[] = ['cards', 'steps', 'stats', 'faq', 'quotes', 'logos', 'pricing', 'list', 'text']\n\n/**\n * One line in place. `role` only where the source's own styling says it (an\n * uppercase eyebrow, a large lede, a large bold statement, a small note).\n */\nexport interface SiteImportLayoutLine {\n kind: 'line'\n line: SiteImportLineRef\n role?: 'eyebrow' | 'lede' | 'statement' | 'note'\n /** The source draws this line (a link, or a `<button>`'s words) as a button. Its destination is the link block's `href`. */\n button?: SiteImportButtonStyle\n /** An eyebrow the source sets in a pill of its own: a fill or a border, its corners rounded (AGL-4138). */\n chip?: true\n /** An eyebrow's color as the source shows it, `#rrggbb` over the ground it sits on (AGL-4138). */\n color?: string\n}\n\n/**\n * How the source frames a picture (AGL-4138): the shape its own `width` and\n * `height` give it, the box it crops it to, its fit in that box, its corners\n * and its shadow. A source that draws a picture at `width: 100%; height:\n * auto` crops nothing, and a page brought in shows it whole.\n */\nexport interface SiteImportPictureFit {\n /** The picture's own shape, width over height, from its `width` and `height` attributes. */\n ratio?: number\n /** A shape the source crops it to, width over height: an `aspect-ratio` on it or its box. */\n box?: number\n /** A height in px the source crops it to, at whatever width its column gives it. */\n height?: number\n objectFit?: 'cover' | 'contain'\n /** Its corners' radius in px, on it or its box; 999 for a round one. */\n radius?: number\n /** It, or its box, is set on a shadow. */\n shadow?: true\n /** A width in px the source holds it to, its `max-width` or its box's: a film's card narrower than its column. */\n measure?: number\n}\n\n/** A picture in place: an image block. */\nexport interface SiteImportLayoutPicture {\n kind: 'picture'\n line: SiteImportLineRef\n /** Where clicking it goes, when it sits in a link. */\n href?: string\n /** It sits in a `<button>` (a video's poster, a lightbox): the picture is kept, the button is not a destination. */\n button?: true\n /** How the source frames it (AGL-4138). */\n fit?: SiteImportPictureFit\n}\n\n/**\n * A filled square an icon sits in (AGL-4138): its fill and corners, and the\n * icon's own color in it, as the source draws them, `#rrggbb`.\n */\nexport interface SiteImportIconTile {\n fill: string\n radius: number\n color: string | null\n}\n\n/** A line the source draws along one side of each item of a group, in place of a box (AGL-4138): a step's rule. */\nexport interface SiteImportRule {\n side: 'top' | 'right' | 'bottom' | 'left'\n /** Its width in px. */\n width: number\n /** Its color, `#rrggbb`; `null` where the source draws it in the words' own. */\n color: string | null\n}\n\n/** An icon standing on its own, by index into `SiteImportLayout.icons`. */\nexport interface SiteImportLayoutIcon {\n kind: 'icon'\n icon: number\n}\n\n/** Where one of the page's forms sat, by index into `AiSiteImportPageRead.forms`. */\nexport interface SiteImportLayoutForm {\n kind: 'form'\n form: number\n}\n\n/**\n * Where one of the page's videos sat (AGL-4140), by index into\n * `AiSiteImportPageRead.videos`. Its poster, when the source shows one, is an\n * image line: the film's first paint, copied into the library as any picture.\n */\nexport interface SiteImportLayoutVideo {\n kind: 'video'\n video: number\n poster?: SiteImportLineRef\n /** How the source frames its poster (AGL-4138), as it frames any picture. */\n fit?: SiteImportPictureFit\n /** The box the source plays it in casts a shadow. */\n shadow?: true\n}\n\n/**\n * A row of columns side by side; `cols` are relative widths in twelfths\n * (`[4, 8]`, `[1, 1, 1]`). Every list of lists is a list of objects: the\n * layout rides a Firestore document, which holds no array inside an array.\n */\nexport interface SiteImportLayoutRow {\n kind: 'row'\n cols: number[]\n cells: Array<{ nodes: SiteImportLayoutNode[] }>\n}\n\n/**\n * One item of a group. Every line of the item is in `lines`, in order, and\n * in exactly one of the named parts.\n */\nexport interface SiteImportLayoutItem {\n lines: SiteImportLineRef[]\n /** The item's name: its heading, its title link, or its first short line. */\n title?: SiteImportLineRef\n /** A stat's figure, a step's number, a plan's price. */\n figure?: SiteImportLineRef\n text?: SiteImportLineRef[]\n /** Its bullet points (a plan's features). */\n list?: SiteImportLineRef[]\n /** Its own call to action: a \"See … →\" link or a button, last in the item, or a button wherever it sits. */\n link?: SiteImportLineRef[]\n /** Those of `link` the source draws as buttons, each as it draws it (AGL-4083). */\n ctas?: Array<{ line: SiteImportLineRef; style: SiteImportButtonStyle }>\n /** A tag on it, a short line in a filled pill: \"Popular\", \"New\", \"Best value\" (AGL-4083). */\n badge?: SiteImportLineRef\n /** What its price is for, beside the price: \"/mo\" (AGL-4083). */\n period?: SiteImportLineRef\n image?: SiteImportLineRef\n /** How the source frames its picture (AGL-4138). */\n imageFit?: SiteImportPictureFit\n /** The icon that leads it, by index into `SiteImportLayout.icons`. */\n icon?: number\n /** The filled square its lead icon sits in (AGL-4138). */\n tile?: SiteImportIconTile\n /** A second icon at the end of its first row, as an arrow that it is a link (AGL-4138), by index into `SiteImportLayout.icons`. */\n mark?: number\n /** Its figure is drawn in the muted words' color, not the brand's (AGL-4138). */\n figureMuted?: true\n /** The icon each of its bullet points carries (a check mark), when they share one. */\n listIcon?: number\n /** Where the item goes as a whole: its title link's address. */\n to?: string\n /** The video it holds (AGL-4140), by index into the read's videos; its poster is its `image`. */\n video?: number\n}\n\nexport interface SiteImportLayoutGroup {\n kind: 'group'\n group: SiteImportGroupKind\n /** Columns the source lays the items out in on a wide screen. */\n columns: number\n /** Columns on a tablet, where the source sets fewer there than on a wide screen (AGL-4138). */\n columnsSm?: number\n /** Each item is drawn as a box: a shadow, a fill of its own, or a border on two sides or more. */\n boxed: boolean\n /** Each item is drawn with a line along one side and no box (AGL-4138). */\n rule?: SiteImportRule\n /** How the items' words are set, where it is not the section's alignment (AGL-4138). */\n align?: 'start' | 'center'\n /**\n * Each item is a row of its own, its parts side by side, one under another:\n * a plan's name, words and button, or a label and its value (AGL-4083).\n */\n inline?: true\n /** Its items are photos, not marks (AGL-4152): a gallery, drawn as its pictures in its columns. Only on a `logos` group. */\n gallery?: true\n items: SiteImportLayoutItem[]\n}\n\n/** A table: rows of cells, each cell its lines (objects, not nested arrays, for Firestore). */\nexport interface SiteImportLayoutTable {\n kind: 'table'\n /** Whether the first row names the columns. */\n header: boolean\n rows: Array<{ cells: Array<{ lines: SiteImportLineRef[] }> }>\n}\n\n/** A tab strip and its panels; a panel the source did not draw is empty. */\nexport interface SiteImportLayoutTabs {\n kind: 'tabs'\n tabs: Array<{ label: SiteImportLineRef | null; selected?: true; panel: SiteImportLayoutNode[] }>\n}\n\nexport type SiteImportLayoutNode =\n | SiteImportLayoutLine\n | SiteImportLayoutPicture\n | SiteImportLayoutIcon\n | SiteImportLayoutForm\n | SiteImportLayoutVideo\n | SiteImportLayoutRow\n | SiteImportLayoutGroup\n | SiteImportLayoutTable\n | SiteImportLayoutTabs\n\n/** Where the hero's picture sits against its words. */\nexport type SiteImportHeroPicture = 'beside' | 'behind' | 'below' | 'above'\n\nexport interface SiteImportLayoutSection {\n /** Its `aria-label`, its heading, or \"Section n\": neutralized, cut to a label. */\n name: string\n /** How its edges were found: a landmark (`<section>`), a container of its own, or its headings. */\n from: 'landmark' | 'container' | 'heading'\n /**\n * Its band against the page's own ground (AGL-4152): a light fill within\n * OKLab ΔE 0.02 of the page's, or none, is `plain`, any other light one\n * `soft`; `brand` and `dark` as its color says.\n */\n band: SiteImportBand\n /**\n * Its band by its color's own lightness, near white `plain` and any other\n * light fill `soft`, where that differs from {@link SiteImportLayoutSection.band}:\n * what Improve it and the design answer's text read. Absent, the two agree.\n */\n absoluteBand?: SiteImportBand\n /** Its background color as `#rrggbb`, when it has one. */\n background: string | null\n /** Its background in the page's dark scheme (AGL-4152), where its stylesheets change it. */\n darkBackground?: string\n /** A gradient, a photo, or a film playing on its own behind it (AGL-4140), its poster an image line. */\n backdrop?: { kind: 'gradient' } | { kind: 'picture'; url: string } | { kind: 'video'; video: number; poster?: SiteImportLineRef }\n align: 'start' | 'center'\n /**\n * How wide the source lets the section's content run on a wide screen, in\n * px (AGL-4083): the narrowest cap on it and the wrappers around its\n * content. Absent where the source sets none.\n */\n width?: number\n /**\n * Set on the section holding the page's first `<h1>`; `measure` the\n * narrowest width in px the source holds its heading to (AGL-4152).\n */\n hero?: { picture: SiteImportHeroPicture | null; measure?: number }\n nodes: SiteImportLayoutNode[]\n /** Every line of the section, in order. */\n lines: SiteImportLineRef[]\n}\n\n/** The widths a page's column is drawn at: the Container element's Max Width choices. */\nexport type SiteImportWidth = 'sm' | 'md' | 'lg' | 'xl'\n\n/**\n * The Max Width a source's cap in px reads as (AGL-4083), `null` for a source\n * that sets none. `sm` is 600 and `md` 900: a post's 760 column is `md`, as a\n * column held to 600 would read narrower than its source.\n */\nexport function siteImportWidthOf(px: number | null | undefined): SiteImportWidth | null {\n if (typeof px !== 'number' || !Number.isFinite(px) || px <= 0) return null\n if (px >= 1400) return 'xl'\n if (px >= 1100) return 'lg'\n if (px >= 750) return 'md'\n return 'sm'\n}\n\n/** An icon the page draws, once however often it repeats. */\nexport interface SiteImportIconShape {\n viewBox: string\n /** One path, for the Besigner's icon element (`iconPath`, drawn on a 24-unit square). */\n path?: string\n /** A small drawing of several shapes, geometry only, for a picture of it. */\n svg?: string\n}\n\n/** What the source's look is made of (AGL-4106), read from its stylesheets. */\nexport interface SiteImportLookFacts {\n fonts: {\n /** The family its body text is set in, as named, when it is not a system font. */\n body: string | null\n /** The family its headings are set in. */\n headings: string | null\n /** The families it loads from Google Fonts, in order. */\n google: string[]\n }\n /** The page's own background, `#rrggbb`. */\n background: string | null\n /** Its body text color. */\n text: string | null\n /** The fill of its filled buttons, the most used first. */\n buttonFill: string | null\n /** The text color on them. */\n buttonText: string | null\n /** Its buttons' corner radius, px. */\n buttonRadius: number | null\n /** The color its text links are drawn in. */\n link: string | null\n /**\n * The brand colors its root's custom properties declare (AGL-4152), the most\n * read first: what it says its brand is, whether or not this page draws it.\n * Absent with none, and on a read made before.\n */\n palette?: string[]\n /** Its header bar's background. */\n header: string | null\n /**\n * The dark ground Keep my site keeps (AGL-4152): its page's fill in its dark\n * scheme where its stylesheets say one, else the fill of its dark bands, the\n * most used first. Absent on a read made before.\n */\n darkBackground?: string | null\n /** The fill of its `soft` bands, the most used first (AGL-4152): what Keep my site's paper is. Absent on a read made before. */\n paperBackground?: string | null\n /** The fill of its `soft` bands in its dark scheme (AGL-4152), where its stylesheets say one. */\n darkPaper?: string | null\n /** Whether its filled buttons are set in capitals (AGL-4152). Absent on a read made before. */\n buttonCase?: 'upper' | 'none' | null\n /** Whether its outlined buttons are set in capitals (AGL-4152); `null` for a page with none. */\n outlinedCase?: 'upper' | 'none' | null\n /** Whether its text buttons and the links a page draws as them are set in capitals (AGL-4152); `null` for a page with none. */\n textCase?: 'upper' | 'none' | null\n /** The words' color on its outlined buttons (AGL-4152), the most used first. */\n buttonOutline?: string | null\n /** The fill an outlined button of its own sets (AGL-4152); `null` where they leave the ground showing. */\n outlinedFill?: string | null\n /**\n * The color most of its eyebrows are drawn in, where that is a color of its\n * own: none of its text's, its buttons' or white (AGL-4138). The look pass\n * pins it as the theme's third color. Absent on a read made before.\n */\n eyebrow?: string | null\n}\n\n/** A page's layout, as the source lays it out (AGL-4106). */\nexport interface SiteImportLayout {\n v: 1\n sections: SiteImportLayoutSection[]\n icons: SiteImportIconShape[]\n look: SiteImportLookFacts\n}\n\n/** One entry of a menu, as the source's header shows it. */\nexport interface SiteImportNavEntry {\n label: string\n /** The line under it in a mega menu. */\n text?: string\n /** Where it goes: absolute http(s), `mailto:` or `tel:`. */\n href: string\n /** Its icon, when it has a one-path icon. */\n iconPath?: string\n viewBox?: string\n /** The heading of the menu's column it sits in (\"By team\"). */\n column?: string\n /** The column of its panel it sits in, by index into its group's `columns` (AGL-4139). */\n at?: number\n /** The filled box its icon sits in, as the source draws it (AGL-4139): its fill, corners and the icon's own color. */\n tile?: { fill: string; radius: number; color: string | null }\n}\n\n/**\n * One column of a menu's panel as the source sets it (AGL-4139): its heading,\n * its other lines of words, the fill it sits on, the picture it shows, and\n * its own width. A footer's filled box is read the same way, with its links.\n */\nexport interface SiteImportNavColumn {\n heading: string | null\n /** Its words outside its links, after its heading, as written. */\n lines: string[]\n /** The fill it sits on against its panel's: none, a light one, the brand's, or a dark one. */\n band: SiteImportBand\n /** The picture it shows outside its links (a featured card's), with `src` once the look pass brings it into the library. */\n image?: { url: string; alt: string }\n /** Its own width in CSS pixels, where the source sets one. */\n width?: number\n /** A footer box's links, as written (AGL-4139). */\n links?: SiteImportFooterLink[]\n /** The icon beside its heading, one path on a 24-unit square. */\n iconPath?: string\n}\n\n/** A top-level item of the source's menu: a link, or a menu of entries under a name. */\nexport interface SiteImportNavGroup {\n label: string\n /** Where the name itself goes; `null` when it only opens its menu. */\n href: string | null\n /** Empty for a plain link. */\n items: SiteImportNavEntry[]\n /** Its panel's columns side by side, in the source's order (AGL-4139); absent on a read made before. */\n columns?: SiteImportNavColumn[]\n /**\n * Its panel (AGL-4139): how wide the source caps it, and whether it opens\n * on hover — hidden until shown, under a name that is not a button.\n */\n panel?: { width: number | null; hover: boolean }\n}\n\n/** A button in the source's header outside its menu (\"Sign in\", \"Start free\"). */\nexport interface SiteImportNavCta {\n label: string\n href: string | null\n style: SiteImportButtonStyle\n}\n\n/** The source's header menu (AGL-4106). Untrusted data from the owner's site. */\nexport interface SiteImportNavTree {\n items: SiteImportNavGroup[]\n ctas: SiteImportNavCta[]\n /** The source shows a menu button on phones. */\n phoneMenu: boolean\n /** The header bar's background, `#rrggbb`. */\n background: string | null\n}\n\nexport interface SiteImportFooterLink {\n label: string\n href: string\n}\n\n/** The source's footer (AGL-4106): its columns, profiles and facts, as written. */\nexport interface SiteImportFooter {\n columns: Array<{ heading: string; links: SiteImportFooterLink[] }>\n /** Its links to profiles on other sites. */\n social: Array<SiteImportFooterLink & { network: string }>\n /** Links outside any column and not a profile (Privacy, Terms, Status). */\n links: SiteImportFooterLink[]\n /** Its lines of text outside links (a tagline), as written. */\n text: string[]\n address: string | null\n phone: string | null\n email: string | null\n /** Its © line, word for word. */\n copyright: string | null\n /** It opens with the site's logo (AGL-4139). */\n logo?: boolean\n /** Its filled boxes, each with its heading, words and links (AGL-4139), which `text` and `links` then leave out. */\n panels?: SiteImportNavColumn[]\n}\n\n/** Every line a layout's nodes place, in order. */\nexport function siteImportLayoutLines(nodes: readonly SiteImportLayoutNode[]): SiteImportLineRef[] {\n const out: SiteImportLineRef[] = []\n const visit = (list: readonly SiteImportLayoutNode[]) => {\n for (const node of list) {\n switch (node.kind) {\n case 'line':\n case 'picture':\n out.push(node.line)\n break\n case 'video':\n if (node.poster !== undefined) out.push(node.poster)\n break\n case 'row':\n for (const cell of node.cells) visit(cell.nodes)\n break\n case 'group':\n for (const item of node.items) out.push(...item.lines)\n break\n case 'table':\n for (const row of node.rows) for (const cell of row.cells) out.push(...cell.lines)\n break\n case 'tabs':\n for (const tab of node.tabs) {\n if (tab.label !== null) out.push(tab.label)\n visit(tab.panel)\n }\n break\n default:\n break\n }\n }\n }\n visit(nodes)\n return out\n}\n\n/** How many characters a layout weighs on the job document. */\nexport function siteImportLayoutChars(layout: SiteImportLayout | null | undefined): number {\n return layout ? JSON.stringify(layout).length : 0\n}\n\n/**\n * A layout over only the first `count` lines (a read the wave's budget cut\n * short): references past the cut are dropped, and what is left empty goes.\n */\nexport function siteImportLayoutWithin(layout: SiteImportLayout, count: number): SiteImportLayout {\n const keep = (ref: SiteImportLineRef) => ref >= 0 && ref < count\n const sections = layout.sections\n .map((section) => {\n const { backdrop } = section\n // A film behind the words keeps its place; a poster past the cut goes (AGL-4140).\n const behind = backdrop?.kind === 'video' && backdrop.poster !== undefined && !keep(backdrop.poster) ? { backdrop: { kind: 'video' as const, video: backdrop.video } } : {}\n return { ...section, ...behind, nodes: siteImportFilterNodes(section.nodes, keep), lines: section.lines.filter(keep) }\n })\n .filter((section) => section.lines.length)\n return { ...layout, sections }\n}\n\n/** Nodes with only the lines `keep` keeps; what is left empty goes. */\nexport function siteImportFilterNodes(list: readonly SiteImportLayoutNode[], keep: (ref: SiteImportLineRef) => boolean): SiteImportLayoutNode[] {\n const nodes = (list: readonly SiteImportLayoutNode[]): SiteImportLayoutNode[] =>\n list.flatMap((node): SiteImportLayoutNode[] => {\n switch (node.kind) {\n case 'line':\n case 'picture':\n return keep(node.line) ? [node] : []\n case 'icon':\n case 'form':\n return [node]\n case 'video': {\n // The film stays where it sat; a poster past the cut goes.\n if (node.poster === undefined || keep(node.poster)) return [node]\n const { poster: _poster, ...rest } = node\n return [rest]\n }\n case 'row': {\n const cells = node.cells.map((cell) => ({ nodes: nodes(cell.nodes) }))\n return cells.some((cell) => cell.nodes.length) ? [{ ...node, cells }] : []\n }\n case 'group': {\n const items = node.items\n .map((item) => trimItem(item, keep))\n .filter((item) => item.lines.length || item.icon !== undefined || item.video !== undefined)\n return items.length ? [{ ...node, items }] : []\n }\n case 'table': {\n const rows = node.rows\n .map((row) => ({ cells: row.cells.map((cell) => ({ lines: cell.lines.filter(keep) })) }))\n .filter((row) => row.cells.some((cell) => cell.lines.length))\n return rows.length ? [{ ...node, rows }] : []\n }\n case 'tabs': {\n const tabs = node.tabs.map((tab) => ({ ...tab, label: tab.label !== null && keep(tab.label) ? tab.label : null, panel: nodes(tab.panel) }))\n return tabs.some((tab) => tab.label !== null || tab.panel.length) ? [{ ...node, tabs }] : []\n }\n default:\n return []\n }\n })\n return nodes(list)\n}\n\nfunction trimItem(item: SiteImportLayoutItem, keep: (ref: SiteImportLineRef) => boolean): SiteImportLayoutItem {\n const out: SiteImportLayoutItem = { ...item, lines: item.lines.filter(keep) }\n for (const key of ['title', 'figure', 'image', 'badge', 'period'] as const) if (out[key] !== undefined && !keep(out[key] as number)) delete out[key]\n if (out.image === undefined) delete out.imageFit\n if (out.figure === undefined) delete out.figureMuted\n for (const key of ['text', 'list', 'link'] as const) {\n const list = out[key]?.filter(keep)\n if (list?.length) out[key] = list\n else delete out[key]\n }\n const ctas = out.ctas?.filter((cta) => keep(cta.line))\n if (ctas?.length) out.ctas = ctas\n else delete out.ctas\n return out\n}\n\n/*------------------------------------------\n * A page's videos (AGL-4140)\n *-----------------------------------------*/\n\n/** The words that name a control as one that plays a film: a facade's label, a \"Watch the film\" button. */\nexport const SITE_IMPORT_PLAY_WORDS = /\\b(?:play|watch|video|film)\\b/i\n\n/**\n * Where a video of a page brought in plays from on the new page, or `null`\n * where the Video element cannot play it: a link to a video host whose\n * player the element frames (`hosted`), else the file the old site serves at\n * an https address, which the new page plays from that address. A video on\n * any other host is shown as its poster, linking to it.\n */\nexport function siteImportFilmSource(video: Pick<SiteImportVideo, 'src' | 'embed'> | null | undefined): { src: string; hosted: boolean } | null {\n if (!video) return null\n const embed = video.embed?.trim()\n if (embed && videoEmbedOf(embed)) return { src: embed, hosted: true }\n const file = video.src?.trim()\n return file && /^https:\\/\\//i.test(file) ? { src: file, hosted: false } : null\n}\n\n/**\n * The films a page brought in plays from the old site's own address\n * (AGL-4140): the https file of each video its layout places where it sits or\n * in an item, which the Video element plays because its poster is in the\n * library. A film on a host's player, one behind a section's words (drawn as\n * its poster), and one with no poster the library holds play nothing from\n * the old site. The rule the compile places a film by (`filmPlaces`).\n */\nexport function aiSiteImportOwnFilms(\n read: Pick<AiSiteImportPageRead, 'videos' | 'layout' | 'blocks'> | null | undefined,\n photos: ReadonlyArray<{ from?: string }>,\n): string[] {\n const videos = read?.videos ?? []\n if (!videos.length || !read?.layout) return []\n const held = new Set(photos.flatMap((photo) => (photo.from ? [photo.from] : [])))\n const out: string[] = []\n const place = (video: number, poster: SiteImportLineRef | undefined) => {\n const source = siteImportFilmSource(videos[video])\n const block = poster === undefined ? undefined : read.blocks?.[poster]\n if (source && !source.hosted && block?.kind === 'image' && held.has(block.url) && !out.includes(source.src)) out.push(source.src)\n }\n const visit = (nodes: readonly SiteImportLayoutNode[]) => {\n for (const node of nodes) {\n if (node.kind === 'video') place(node.video, node.poster)\n else if (node.kind === 'row') for (const cell of node.cells) visit(cell.nodes)\n else if (node.kind === 'tabs') for (const tab of node.tabs) visit(tab.panel)\n else if (node.kind === 'group') for (const item of node.items) if (item.video !== undefined) place(item.video, item.image)\n }\n }\n for (const section of read.layout.sections) visit(section.nodes)\n return out\n}\n\n/**\n * The most hosts a site approves of one kind: `APPROVED_IMAGE_HOSTS_MAX` in\n * `security-origins.js`, the tenant policy's own ceiling, which a spec holds\n * this to.\n */\nexport const SITE_IMPORT_APPROVED_HOSTS_MAX = 50\n\n/**\n * A host as the Security tab keeps one and the tenant's policy reads it\n * (`normalizeApprovedImageHost` in `security-origins.js`, which a spec holds\n * this to): lowercase, a hostname with at least one dot and a letter-only\n * last label, an optional leading `*.`, and no scheme, path, port or\n * separator; `null` for anything else.\n */\nexport function siteImportApprovedHost(value: unknown): string | null {\n if (typeof value !== 'string') return null\n const host = value.trim().toLowerCase()\n if (!host || host.length > 253) return null\n if (/[\\s;,/\\\\?#@:]/.test(host)) return null\n const bare = host.startsWith('*.') ? host.slice(2) : host\n if (!bare || bare === '*') return null\n return /^(?=.{1,253}$)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,63}$/.test(bare) ? host : null\n}\n\n/**\n * A site's approved media hosts with the old site's film hosts added\n * (AGL-4140): every entry the owner has kept as it is and where it is, each\n * new host once, after them, within `SITE_IMPORT_APPROVED_HOSTS_MAX`; `null`\n * when nothing is added.\n */\nexport function siteImportApprovedHostsWith(current: unknown, addresses: readonly string[]): string[] | null {\n const owner = Array.isArray(current) ? current.filter((entry): entry is string => typeof entry === 'string') : []\n const have = new Set(owner.map((entry) => entry.trim().toLowerCase()))\n const out = [...owner]\n const hostnameOf = (address: string): string | null => {\n try {\n return new URL(address).hostname\n } catch {\n return null\n }\n }\n for (const address of addresses) {\n const host = siteImportApprovedHost(hostnameOf(address))\n if (!host || have.has(host) || out.length >= SITE_IMPORT_APPROVED_HOSTS_MAX) continue\n have.add(host)\n out.push(host)\n }\n return out.length > owner.length ? out : null\n}\n\n/**\n * What a page's row says of its videos (AGL-4140), or `null`: a film the old\n * site serves itself plays from there, the owner may move it, and its address\n * was approved for the site to play (`approved`, once the host write is in);\n * a film the source showed no poster for is left out, since its poster is the\n * button a visitor presses, and the owner may add it with one.\n */\nexport function aiSiteImportVideoNote(\n videos: readonly SiteImportVideo[] | null | undefined,\n own: { films: number; approved: boolean } = { films: 0, approved: false },\n): string | null {\n const posterless = (videos ?? []).filter((video) => siteImportFilmSource(video) && !video.poster).length\n const approved = own.approved ? ' Its address was added to Approved media hosts in Admin → Security, so it plays on your new site.' : ''\n const notes = [\n own.films === 1 ? `A video on this page plays from your old site's address; pick it from your media library to move it.${approved}` : '',\n own.films > 1 ? `Videos on this page play from your old site's address; pick each from your media library to move it.${approved ? ' Their addresses were added to Approved media hosts in Admin → Security, so they play on your new site.' : ''}` : '',\n posterless === 1 ? 'A video on this page had no poster picture, so it was left out: add it with the Video element and pick a poster for it.' : '',\n posterless > 1 ? 'Videos on this page had no poster picture, so they were left out: add each with the Video element and pick a poster for it.' : '',\n ].filter(Boolean)\n return notes.length ? notes.join(' ') : null\n}\n\n/** A layout with its icons' drawings dropped, for a page that must be lighter. */\nexport function siteImportLayoutWithoutDrawings(layout: SiteImportLayout): SiteImportLayout {\n return { ...layout, icons: layout.icons.map((icon) => (icon.svg ? { viewBox: icon.viewBox } : icon)) }\n}\n\n/** What a wave's read found on one page, for its model answer. Never on the wire. */\nexport interface AiSiteImportPageRead {\n /** What the page holds that a visitor cannot see (AGL-4152): the addresses of its pictures, and its words. A build is held to not drawing them. */\n concealed?: { pictures: string[]; words: string[] }\n at: string\n title: string\n /** The page's text in order, cut to `AI_SITE_IMPORT_PAGE_TEXT_MAX_CHARS`; fenced only when a prompt reads it. */\n text: string\n /** The page's sections, from its headings. */\n sections: string[]\n /** Its photos' addresses, at most `AI_SITE_IMPORT_IMAGES_PER_PAGE`. */\n images: Array<{ url: string; alt: string }>\n /**\n * Every block of the page's main region, in order (AGL-4083): its words as\n * written, its headings, lists, links and pictures, within\n * `AI_SITE_IMPORT_READ_MAX_BLOCKS` and `AI_SITE_IMPORT_READ_MAX_CHARS`.\n * Untrusted data: fenced wherever a prompt reads it. Emptied once the page\n * is in; absent on a read made before it was kept.\n */\n blocks?: SiteImportBlock[]\n /** Set when `blocks` had to stop short of the page, at its budget or the wave's. */\n cut?: boolean\n /** The words of the page's main region, as the old page has them. */\n words?: number\n /** The forms the page asks visitors to fill in, by their fields. */\n forms?: SiteImportForm[]\n /**\n * How the source lays the page out (AGL-4106): its sections, bands, rows,\n * groups, pictures, icons and buttons, over `blocks` by index. Absent on a\n * read made before the reader, or when it did not fit the wave's budget.\n */\n layout?: SiteImportLayout | null\n /**\n * The page's browser title and meta description as the source writes them\n * (AGL-4107), which the new page's listing keeps word for word. Absent on a\n * read made before they were kept.\n */\n meta?: { title: string; description: string }\n /**\n * The videos the page shows (AGL-4140), which its layout places by index:\n * where each plays from, its poster's address and what a search engine\n * reads of it. Untrusted data. Absent on a page that shows none, or a read\n * made before they were kept; emptied with `blocks` once the page is in.\n */\n videos?: SiteImportVideo[]\n}\n\n/** How a page is built from its old page, as the step chose: its words copied as they are, or arranged by Aglyn AI. */\nexport type AiSiteImportBuild = 'copied' | 'arranged'\n\n/**\n * How an import finishes the owner's site (AGL-4152): kept as it is with a\n * light polish, or improved. Absent on an older import, which is `keep`.\n */\nexport type AiSiteImportFinish = 'keep' | 'improve'\n\n/** The job input the finish is carried in from Bring my site. */\nexport const AI_SITE_IMPORT_FINISH_INPUT = 'finish'\n\n/** The job input carrying whether an improved site's wording is improved too (AGL-4152). */\nexport const AI_SITE_IMPORT_WORDING_INPUT = 'wording'\n\n/** Whether a page's words were kept as written or improved (AGL-4152). */\nexport type AiSiteImportWords = 'kept' | 'improved'\n\n/** How the owner asked the site to be finished, as one choice: the finish, and under `improve` whether its wording is improved too (AGL-4152). */\nexport interface AiSiteImportChoice {\n finish: AiSiteImportFinish\n /** Always `false` under `keep`: Keep my site never rewrites a word. */\n wording: boolean\n}\n\n/** What Bring my site preselects (AGL-4152): Improve it, with Also improve my wording on. */\nexport const AI_SITE_IMPORT_DEFAULT_CHOICE: Readonly<AiSiteImportChoice> = { finish: 'improve', wording: true }\n\n/**\n * The words a policy page's address or title carries (AGL-4152), each matched\n * as whole words, its plural too: a main page that names one keeps every word\n * even when its wave improves the wording of the rest.\n */\nexport const AI_SITE_IMPORT_LEGAL_SLUGS: readonly string[] = [\n 'privacy',\n 'terms',\n 'cookie',\n 'legal',\n 'refund',\n 'return',\n 'shipping-policy',\n 'disclaimer',\n 'accessibility',\n 'gdpr',\n 'imprint',\n 'impressum',\n]\n\nexport interface AiSiteImportPage {\n /** The item ledger slot: `p0`, `p1`, … */\n slot: string\n url: string\n path: string\n title: string\n group: string\n wave: number\n /** The id the page's draft is written under, minted with the inventory. */\n draftId: string\n /** The page's address on the new site. */\n slug: string\n words: number\n images: number\n /** Filled by the wave's read; the text is cleared once the page is in. */\n read?: AiSiteImportPageRead | null\n /** Set when the wave's read found the page cannot be brought in after all. */\n refused?: AiSiteImportLeftOutReason | null\n /** How the step builds the page (`aiSiteImportPageBuild`); absent until it chooses, and the page is priced as an AI page. */\n build?: AiSiteImportBuild | null\n /** What came through once the page is in: its words on the new page. */\n brought?: { words: number } | null\n /** Whether its words were kept or improved, stamped with its build at its wave's start (AGL-4152). */\n wording?: AiSiteImportWords | null\n /** Filled once the page's photos are in the library. */\n photos?: {\n brought: number\n /** Already in the library from an earlier page or import: the same file, never a second copy. */\n reused: number\n skipped: number\n assets: AiSiteImportPhoto[]\n } | null\n /** Each form of the read, by its index, and the saved form that takes its place, `null` where none does (AGL-4083). */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** What the page's row says of its forms. */\n formNote?: string | null\n /** Where the page came from under a generative Improve it (AGL-4152): the source's, or the plan's proposed page. Absent is the source's. */\n origin?: 'source' | 'proposed' | null\n /** The sections its redesign added (AGL-4152). */\n added?: AiSiteImportAddedSection[] | null\n /** Its pictures by where each came from (AGL-4152). */\n pictures?: AiSiteImportPagePictures | null\n /**\n * How its generative Improve it came out (AGL-4152): `redesigned` from its\n * answer, or `layout-kept` where the redesign did not pass and today's\n * compile drew it. Absent on every other page.\n */\n redesign?: AiSiteImportRedesign | null\n}\n\n/** How a page's generative Improve it came out (AGL-4152). */\nexport type AiSiteImportRedesign = 'redesigned' | 'layout-kept'\n\n/** What a page's row says where its redesign did not pass (AGL-4152). */\nexport const AI_SITE_IMPORT_LAYOUT_KEPT = 'Layout kept: the redesign did not pass'\n\n/** What a proposed page's row says where it could not be written: it has no old page to keep, so it is left out. */\nexport const AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN = 'This new page was left out: it could not be written without inventing facts. Its credits are given back.'\n\n/**\n * A wave's place in its import: waiting to start, running, in and waiting for\n * the person's review, in, or `stopped` — the import was canceled before the\n * wave was in, while it ran or before it started (AGL-4107).\n */\nexport type AiSiteImportWaveStatus = 'waiting' | 'running' | 'review' | 'done' | 'stopped'\n\nexport interface AiSiteImportWave {\n index: number\n label: string\n /** The group the wave brings in; the first wave's is `main`. */\n group: string\n slots: string[]\n /** Whether the wave builds the site's header and footer first. */\n frame: boolean\n status: AiSiteImportWaveStatus\n startedAt: string | null\n finishedAt: string | null\n /** How the wave was built, stamped at its start (AGL-4152): the site's finish then. */\n finish?: AiSiteImportFinish | null\n /** Whether its improved pages' wording was improved too, stamped at its start (AGL-4152). */\n wording?: boolean | null\n /**\n * Whether it is a generative Improve it (AGL-4152):\n * `SITE_IMPORT_GENERATIVE_RELEASE_FLAG` was on for the organization when the\n * wave started, under Improve it. Its site is planned, and with new copy on\n * its improved pages are redesigned from a ledger. Absent, today's Improve it.\n */\n generative?: true\n /**\n * `SITE_IMPORT_VIDEO_POSTERS_RELEASE_FLAG` was on for the organization when\n * the wave started (AGL-4140): its pages place a YouTube film with no\n * poster the library holds, for the page to draw YouTube's own still in.\n */\n videoPosters?: true\n}\n\nexport interface AiSiteImportState {\n domain: string\n /** The site's name, as Create site was given it: the header's name. */\n siteName: string\n ownership: { method: string | null; provenAt: number | null; detail: string | null }\n readAt: string\n /** The plan's page count; `null` when it has none. */\n pageLimit: number | null\n /** Pages the site already had when its import read the old site. */\n existingPages: number\n /** Pages the crawl read. */\n found: number\n /** Why the crawl stopped short of the whole site, or `null` when it did not. */\n stoppedBy: string | null\n groups: AiSiteImportGroup[]\n pages: AiSiteImportPage[]\n waves: AiSiteImportWave[]\n /** At most `AI_SITE_IMPORT_LEFT_OUT_LISTED`, by address. */\n leftOut: AiSiteImportLeftOut[]\n /** Every page left out, by reason, listed or not. */\n leftOutCount: Partial<Record<AiSiteImportLeftOutReason, number>>\n /** The header and footer's draft id, built in the first wave; `null` when there are no main pages. */\n frame: { draftId: string } | null\n /**\n * \"Start every remaining wave\" (AGL-4083): each wave closes and the next\n * starts with no review between them; the last wave's close is the stop.\n * Off unless the person chose it.\n */\n autoContinue?: boolean\n /**\n * The wave \"Start every remaining wave\" was chosen at (AGL-4084): the one\n * start the person made, which the day's limit counts; the waves it starts\n * after it are the same start.\n */\n autoContinueFrom?: number | null\n /** What the read found of the site as a whole; a stopping verdict plans nothing. */\n verdict?: AiSiteImportReadVerdict | null\n /** What the home page says of the site as a whole (AGL-4084): its look, its header and footer, its listing. */\n home?: AiSiteImportHome | null\n /** The look pass, once it ran in the first wave (AGL-4084). */\n look?: AiSiteImportLook | null\n /** How the owner asked the site to be finished (AGL-4152); absent reads as `keep`. Changeable before each wave. */\n finish?: AiSiteImportFinish | null\n /** Under `improve`, whether the main pages' wording is improved too (AGL-4152): on unless the owner turns it off. */\n wording?: boolean | null\n /**\n * The one site plan a generative Improve it draws from (AGL-4152), written\n * once after the first wave's read. Absent until that step exists, and on\n * every import that is not generative; a page's design then comes from the\n * import's own inputs (`aiSiteImportDesignInputs`). `null` is a plan asked\n * for that did not pass: the import's frame and design inputs stand, and its\n * page says so.\n */\n plan?: AiSiteImportPlan | null\n /** The owner saw the plan and started the build (AGL-4152): its proposed page is settled, in or out. */\n planAccepted?: true\n /** Whether a slot nothing else fills may take a generated picture (AGL-4152); absent is `AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT`. */\n generatedPictures?: boolean | null\n /**\n * `SITE_IMPORT_GENERATIVE_RELEASE_FLAG` was on for the organization when the\n * site was read (AGL-4152): what its page says and quotes before a wave\n * starts. A wave's own stamp decides how it is built.\n */\n generative?: true\n /** The source's photos a redesigned page left off (AGL-4152), which a later page's slot takes before a stock photo. */\n sitePhotos?: AiSiteImportPhoto[] | null\n}\n\n/**\n * The site plan (AGL-4152): what the site is, its menu, its design, and at\n * most one proposed page. Page references are draft ids. Its words are the\n * site's own data, fenced wherever a prompt reads them.\n */\nexport interface AiSiteImportPlan {\n site: { what: string; audience: string; kind: string; voice: string }\n nav: {\n groups: Array<{ label: string; pages: string[] }>\n /**\n * The header's filled call to action: `target` is a page's draft id, `form`\n * or `phone`; `page` is the page a `form` target sends a visitor to, read\n * when the plan was checked, since a settled page keeps no form.\n */\n primaryCta: { label: string; target: string; page?: string } | null\n footer: Array<{ label: string; pages: string[] }>\n }\n /** One for the site, so every page of every wave is drawn alike. */\n design: AiSiteImportPlanDesign\n /** At most one new page, on by default, with a switch (`AiSiteImportPage.origin`). `draftId` names its page once the plan is in. */\n proposed: { title: string; slug: string; purpose: string; on: boolean; draftId?: string } | null\n /**\n * What each page is for in the new site, by its draft id (AGL-4152): what\n * its redesign plans it as, and how many new sections it has room for. A\n * plan made before roles reads each page's from its address and what it holds.\n */\n roles?: Record<string, AiSiteImportPageRole>\n}\n\n/** What a page is for in a planned site (AGL-4152): what its redesign plans it as. */\nexport type AiSiteImportPageRole = 'home' | 'service' | 'about' | 'contact' | 'gallery' | 'pricing' | 'faq' | 'other'\n\nexport const AI_SITE_IMPORT_PAGE_ROLES: readonly AiSiteImportPageRole[] = ['home', 'service', 'about', 'contact', 'gallery', 'pricing', 'faq', 'other']\n\n/** How a plan draws the site: the hero, each group, the bands' rhythm and the closing call to action. */\nexport interface AiSiteImportPlanDesign {\n hero: 'cover' | 'poster' | 'split' | 'bleed' | 'editorial' | 'column' | 'panel'\n group: 'cards' | 'ruled' | 'icons'\n rhythm: 'alternate' | 'plain'\n /** A closing call to action on a strong band, or over a photo. */\n cta: 'band' | 'photo'\n}\n\n/** The owner's answer to the plan's review (AGL-4152): the proposed page, and generated pictures. */\nexport interface AiSiteImportPlanChoice {\n addPage?: boolean\n pictures?: boolean\n}\n\n/**\n * Whether generated pictures are on where the owner has not said (AGL-4152):\n * on, with a switch. A picture costs credits, so a wave that may take them\n * quotes them in its ceiling before it starts, and the switch turns them off.\n */\nexport const AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT = true\n\n/** What a plan's row and panel say where it did not pass (AGL-4152). */\nexport const AI_SITE_IMPORT_PLAN_FELL_BACK = 'Your menu and footer stay as your site has them: the plan for your new site did not pass.'\n\n/** The ledger slot of the plan's proposed page. */\nexport const AI_SITE_IMPORT_PROPOSED_SLOT = 'proposed'\n\n/** What a plan's answer calls its proposed page before it has an id. */\nexport const AI_SITE_IMPORT_PROPOSED_PAGE = 'new'\n\n/** The most generated pictures one page takes (AGL-4152), a hero or a section's lead only. */\nexport const AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE = 2\n\n/** What the plan's own pass may spend at most: its answer and its one re-ask at the measured p90. */\nexport const AI_SITE_IMPORT_PLAN_CEILING_CREDITS = 180\n\n/** A section a redesign added to a page (AGL-4152): what its row and What's new say. */\nexport interface AiSiteImportAddedSection {\n heading: string\n /** The items it holds, where it holds a group of them. */\n items?: number\n}\n\n/** What a redesigned page shows of its pictures (AGL-4152), by where each came from. */\nexport interface AiSiteImportPagePictures {\n /** The page's own and the site's source photos placed. */\n source: number\n /** Slots filled from the stock library. */\n stock: number\n /** Slots filled by a generated picture. */\n generated: number\n /** Slots with no picture yet, which a later pass fills or drops. */\n slots: number\n /** The source's photos left off the page, by address, listed for the owner. */\n unplaced: string[]\n}\n\n/**\n * What the home page says of the site as a whole (AGL-4084), kept from the\n * read: the site's listing in its own words, its header's brand as the\n * source draws it, and the words its header and footer carry. Untrusted\n * data from the owner's site, fenced wherever a prompt reads it.\n */\nexport interface AiSiteImportHome {\n url: string\n title: string\n description: string\n ogImage: string | null\n /** The site's icon its head names (AGL-4139): its largest touch icon, else its largest picture icon. Absent on a read made before. */\n favicon?: string | null\n siteName: string\n brand: {\n kind: 'logo-only' | 'logo-and-name' | 'name-only'\n /** The name as the header prints it, where it prints one. */\n text: string\n logo: { url: string; alt: string; type: 'svg' | 'raster' | null } | null\n }\n facts: {\n /** The header's and footer's lines, as written, in order. */\n lines: string[]\n emails: string[]\n phones: string[]\n social: string[]\n address: string\n }\n /**\n * The source's header menu as its home page builds it (AGL-4108): its\n * items, their menus, its buttons. The header and footer are drawn from it\n * with no model; absent on a read made before the reader, or where the home\n * page has no menu the reader can find.\n */\n nav?: SiteImportNavTree | null\n /** The source's footer as its home page builds it (AGL-4108): its columns, profiles, facts and © line. */\n footer?: SiteImportFooter | null\n /** What the source's look is made of (AGL-4108): its colors, its button fill and corners, its fonts. */\n look?: SiteImportLookFacts | null\n /**\n * The first picture its home page's main content shows that is not its logo\n * (AGL-4152): what a look with no color of its own, and a logo with none,\n * takes its brand from. Absent on a read made before, or with none.\n */\n hero?: { url: string; alt: string } | null\n}\n\n/**\n * Whether the site's header and footer are built from the source's own menu\n * (AGL-4108), with no model: the home page's menu was read. Then the frame\n * costs nothing and is quoted at nothing.\n */\nexport function aiSiteImportFrameIsRead(state: Pick<AiSiteImportState, 'home'> | null | undefined): boolean {\n const nav = state?.home?.nav\n return !!nav && (nav.items.length > 0 || nav.ctas.length > 0)\n}\n\n/** Where an imported look's brand came from (AGL-4152). */\nexport type AiSiteImportLookFrom = 'source' | 'logo' | 'photo' | 'seed'\n\n/** What the look pass did (AGL-4084): no model is asked. */\nexport interface AiSiteImportLook {\n at: string\n /**\n * The theme: drawn for the site (`applied`), or the owner's kept (`kept`).\n * `unread` is a pass from before AGL-4152, which left a source with no color\n * to read in the stock theme; a pass no longer does.\n */\n theme: 'applied' | 'kept' | 'unread'\n /**\n * Where the applied theme's brand came from (AGL-4152): what the source draws\n * or declares (`source`), its logo's colors (`logo`), its hero or share\n * picture's (`photo`), or, with none of those, the seed's draw for the kind of\n * site (`seed`). Absent on a pass from before.\n */\n from?: AiSiteImportLookFrom\n /** The source's colors it was drawn from, the strongest first. */\n colors: string[]\n /** The source's logo, as the library holds it, for the header's brand. */\n logo: AiSiteImportPhoto | null\n /** The pictures the home page's menus show (AGL-4139), as the library holds them, each by the address it came `from`. */\n pictures?: AiSiteImportPhoto[]\n /** Whether the site's listing was taken from the home page's own words. */\n seo: boolean\n /** The look's seed, which every page of the import is drawn with. */\n seed: number | null\n /** The look's header arrangement, band rhythm and motion, which the header, the footer and every page are drawn in. */\n style?: { headerAlign?: string; rhythm?: string; motion?: string } | null\n /**\n * Under a generative Improve it (AGL-4152), the colors the theme drew, which\n * a redesign is held to as it is asked (`SiteImportFidelityTheme`). Absent\n * on every other import, and where the owner's own theme was kept.\n */\n drawn?: Record<string, unknown> | null\n}\n\n/*------------------------------------------\n * The read's verdict: Home first (AGL-4083)\n *-----------------------------------------*/\n\n/**\n * - `home-blocked`: bot protection or a firewall turned AglynBot away from\n * the home page (401, 403 or 429).\n * - `home-unreadable`: the home page could not be read for any other reason,\n * or read as an empty shell (a site that needs a browser to show its words).\n * - `mostly-blocked`: the home page came in, but more than half the site's\n * addresses were turned away; the import goes on, and says so.\n * - `ok`: anything else.\n */\nexport type AiSiteImportReadVerdictKind = 'ok' | 'home-blocked' | 'home-unreadable' | 'mostly-blocked'\n\n/** Why the home page did not come in. */\nexport type AiSiteImportHomeProblem =\n | 'blocked'\n | 'http-error'\n | 'unreachable'\n | 'not-html'\n | 'too-large'\n | 'off-site'\n | 'robots'\n | 'login-form'\n | 'not-reached'\n | 'empty'\n\nexport interface AiSiteImportReadVerdict {\n kind: AiSiteImportReadVerdictKind\n /** Addresses turned away by bot protection or a firewall, the home page among them. */\n blocked: number\n /** The site's addresses the read knew of: the sitemaps', or everything it asked for. */\n total: number\n /** What the home page answered, when it answered with an error. */\n homeStatus: number | null\n homeProblem: AiSiteImportHomeProblem | null\n /** Whose edge turned the home page away, when it said. */\n edge: 'vercel' | 'cloudflare' | null\n}\n\n/** A crawl as the verdict reads it; the crawler's `SiteImportInventory` is one. */\nexport interface AiSiteImportReadInput {\n pages: ReadonlyArray<{\n path: string\n foundBy: string\n blocks: ReadonlyArray<{ kind: string; text?: string; inline?: boolean }>\n images: readonly unknown[]\n }>\n skipped: ReadonlyArray<{ url: string; reason: string; status?: number; edge?: string | null }>\n sitemapUrls: number\n}\n\nconst pathOfUrl = (url: string): string => {\n try {\n return new URL(url).pathname.replace(/\\/+$/, '') || '/'\n } catch {\n return ''\n }\n}\n\nconst wordsOf = (text: string) => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** How much of a site was turned away counts its pages: never another address of one, or its platform's screen. */\nconst isOneOfTheSitesPages = (entry: { reason: string }) => entry.reason !== 'duplicate' && entry.reason !== 'system-page'\n\n/** One verdict from what became of the home page and how much of the site was turned away. */\nfunction readVerdictOf(\n home: { problem: AiSiteImportHomeProblem; status: number | null; edge: string | null } | null,\n blocked: number,\n total: number,\n): AiSiteImportReadVerdict {\n const edge: AiSiteImportReadVerdict['edge'] = home?.edge === 'vercel' ? 'vercel' : home?.edge === 'cloudflare' ? 'cloudflare' : null\n const base = { blocked, total, homeStatus: home?.status ?? null, homeProblem: home?.problem ?? null, edge }\n if (home) return { kind: home.problem === 'blocked' ? 'home-blocked' : 'home-unreadable', ...base }\n return { kind: total > 0 && blocked * 2 > total ? 'mostly-blocked' : 'ok', ...base }\n}\n\n/** What a crawler skip of the home page means for it. */\nfunction homeProblemOfSkip(reason: string, status: number | undefined): AiSiteImportHomeProblem {\n switch (reason) {\n case 'http-error':\n return status !== undefined && AI_SITE_IMPORT_BLOCKED_STATUSES.has(status) ? 'blocked' : 'http-error'\n case 'off-origin-redirect':\n return 'off-site'\n case 'not-html':\n case 'too-large':\n case 'robots':\n case 'login-form':\n case 'not-reached':\n return reason\n default:\n return 'unreachable'\n }\n}\n\n/**\n * The read's verdict (AGL-4083), pure over the crawl: whether the home page\n * came in, and how much of the site bot protection turned away. An import\n * whose verdict stops (`aiSiteImportReadStops`) plans no wave, quotes\n * nothing and spends nothing: the person is told why and checks again.\n */\nexport function aiSiteImportReadVerdict(crawled: AiSiteImportReadInput): AiSiteImportReadVerdict {\n const blocked = crawled.skipped.filter(\n (entry) => entry.reason === 'http-error' && entry.status !== undefined && AI_SITE_IMPORT_BLOCKED_STATUSES.has(entry.status),\n ).length\n const total = Math.max(crawled.sitemapUrls, crawled.pages.length + crawled.skipped.filter(isOneOfTheSitesPages).length)\n const page = crawled.pages.find((entry) => entry.foundBy === 'home') ?? crawled.pages.find((entry) => (entry.path.replace(/\\/+$/, '') || '/') === '/')\n if (page) {\n const words = page.blocks.reduce((sum, block) => sum + (block.kind === 'image' || block.inline ? 0 : wordsOf(block.text ?? '')), 0)\n const empty = words < AI_SITE_IMPORT_MIN_WORDS && page.images.length === 0\n return readVerdictOf(empty ? { problem: 'empty', status: null, edge: null } : null, blocked, total)\n }\n const skip = crawled.skipped.find((entry) => pathOfUrl(entry.url) === '/')\n return readVerdictOf(\n skip\n ? { problem: homeProblemOfSkip(skip.reason, skip.status), status: skip.status ?? null, edge: skip.edge ?? null }\n : { problem: 'not-reached', status: null, edge: null },\n blocked,\n total,\n )\n}\n\n/** Whether a verdict stops the import before anything is planned: its home page is not in. */\nexport function aiSiteImportReadStops(verdict: AiSiteImportReadVerdict | null | undefined): boolean {\n return verdict?.kind === 'home-blocked' || verdict?.kind === 'home-unreadable'\n}\n\n/** The review an import that stopped at its read waits under: `blocked` or `unreadable`; `null` when it goes on. */\nexport function aiSiteImportReadVerdictReason(verdict: AiSiteImportReadVerdict | null | undefined): 'blocked' | 'unreadable' | null {\n if (verdict?.kind === 'home-blocked') return 'blocked'\n if (verdict?.kind === 'home-unreadable') return 'unreadable'\n return null\n}\n\n/** Where a site owner lets AglynBot through, on the edges that name themselves. */\nexport const AI_SITE_IMPORT_EDGE_HINTS: Readonly<Record<'vercel' | 'cloudflare', string>> = {\n vercel: 'Your site answers through Vercel: in its Firewall, under Rules, add a bypass rule for the user agent AglynBot.',\n cloudflare:\n 'Your site answers through Cloudflare: under Security, WAF, add a custom rule that skips the checks when the user agent contains AglynBot.',\n}\n\nconst NOTHING_SPENT = 'Nothing was brought in and no AI credits were used.'\n\n/** Why the home page could not be read, inside the sentence that says so. */\nfunction homeProblemText(verdict: AiSiteImportReadVerdict): string {\n switch (verdict.homeProblem) {\n case 'http-error':\n return verdict.homeStatus ? `it answered with an error, ${verdict.homeStatus}` : 'it answered with an error'\n case 'not-html':\n return 'it did not answer with a web page'\n case 'too-large':\n return 'it is larger than a page can be to bring in'\n case 'off-site':\n return 'it sends visitors to another website'\n case 'not-reached':\n return 'the read ran out of time before it'\n default:\n return 'it did not answer'\n }\n}\n\n/**\n * What the person is told about the read (AGL-4083), in console words: why\n * nothing was brought in and what to do, or that most of the site was turned\n * away. `null` when there is nothing to say.\n */\nexport function aiSiteImportReadVerdictMessage(verdict: AiSiteImportReadVerdict | null | undefined, domain: string): string | null {\n if (!verdict) return null\n if (verdict.kind === 'home-blocked') {\n const others = Math.max(0, verdict.blocked - 1)\n const more = others ? `, and ${others.toLocaleString('en-US')} other ${others === 1 ? 'page' : 'pages'}` : ''\n const lead = `Your site’s bot protection or firewall turned AglynBot away before it could read your home page${more}. ${NOTHING_SPENT} Allow AglynBot in your site’s bot or firewall settings, then choose Check again.`\n return verdict.edge ? `${lead} ${AI_SITE_IMPORT_EDGE_HINTS[verdict.edge]}` : lead\n }\n if (verdict.kind === 'home-unreadable') {\n switch (verdict.homeProblem) {\n case 'robots':\n return `Your site’s robots.txt asks AglynBot not to read your home page. ${NOTHING_SPENT} Allow AglynBot in your robots.txt, then choose Check again.`\n case 'login-form':\n return `Your home page asks for a password, and pages that do are never brought in. ${NOTHING_SPENT} Open your home page to visitors, then choose Check again.`\n case 'empty':\n return `No text could be read from your home page. If your site is built in a way that needs a browser to show its words, it cannot be brought in yet. ${NOTHING_SPENT}`\n default:\n return `Your home page could not be read (${homeProblemText(verdict)}). ${NOTHING_SPENT} Check that ${domain} is up and answers at https://${domain}/, then choose Check again.`\n }\n }\n if (verdict.kind === 'mostly-blocked') {\n return `${verdict.blocked.toLocaleString('en-US')} of ${verdict.total.toLocaleString('en-US')} pages were turned away by your site’s bot protection; see Not brought in.`\n }\n return null\n}\n\n/** The verdict an inventory reads from its own pages and skips, when the step did not hand it the crawl's. */\nfunction inventoryVerdict(input: Pick<AiSiteImportInventoryInput, 'pages' | 'skipped' | 'skippedOverflow'>): AiSiteImportReadVerdict {\n const blocked = input.skipped.filter((entry) => entry.reason === 'blocked').length\n const total = input.pages.length + input.skipped.filter(isOneOfTheSitesPages).length + Math.max(0, input.skippedOverflow ?? 0)\n const page = input.pages.find((entry) => entry.foundBy === 'home') ?? input.pages.find((entry) => (entry.path.replace(/\\/+$/, '') || '/') === '/')\n if (page) {\n const empty = page.words < AI_SITE_IMPORT_MIN_WORDS && page.images === 0\n return readVerdictOf(empty ? { problem: 'empty', status: null, edge: null } : null, blocked, total)\n }\n const skip = input.skipped.find((entry) => pathOfUrl(entry.url) === '/')\n const problem: AiSiteImportHomeProblem = !skip\n ? 'not-reached'\n : skip.reason === 'blocked'\n ? 'blocked'\n : skip.reason === 'robots' || skip.reason === 'login-form' || skip.reason === 'too-large' || skip.reason === 'off-site' || skip.reason === 'not-reached' || skip.reason === 'empty'\n ? skip.reason\n : 'unreachable'\n return readVerdictOf({ problem, status: null, edge: null }, blocked, total)\n}\n\n/*------------------------------------------\n * Grouping and waves\n *-----------------------------------------*/\n\nconst clipLabel = (text: string) => {\n const line = String(text ?? '').replace(/\\s+/g, ' ').trim()\n return line.length > AI_SITE_IMPORT_LABEL_MAX_CHARS\n ? `${line.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 1).trimEnd()}…`\n : line\n}\n\nconst segmentsOf = (path: string) => String(path ?? '').split('/').filter(Boolean)\n\n/** A collection's prefix for a page address: its first segment, a dated archive's `posts`; `null` for a top-level page. */\nexport function aiSiteImportPrefix(path: string): string | null {\n const segments = segmentsOf(path)\n if (segments.length < 2) return null\n const first = segments[0].toLowerCase()\n return /^\\d{4}$/.test(first) ? 'posts' : first\n}\n\n/** \"news-and-events\" → \"News and events\". */\nexport function aiSiteImportPrefixLabel(prefix: string): string {\n const words = decodeURIComponent(prefix).replace(/[-_+]+/g, ' ').trim()\n return words ? `${words.charAt(0).toUpperCase()}${words.slice(1)}` : 'Pages'\n}\n\n/**\n * The inventory's groups, in the order they are brought in: the main pages,\n * then each collection — one the home page's menu links first, in menu order,\n * then the larger before the smaller.\n */\nexport function aiSiteImportGroups(\n pages: readonly AiSiteImportListedPage[],\n menu: readonly string[] = [],\n): { groups: AiSiteImportGroup[]; groupOf: (page: AiSiteImportListedPage) => string } {\n const counts = new Map<string, number>()\n for (const page of pages) {\n const prefix = aiSiteImportPrefix(page.path)\n if (prefix) counts.set(prefix, (counts.get(prefix) ?? 0) + 1)\n }\n const menuPaths = new Set(menu.map((path) => path.replace(/\\/+$/, '') || '/'))\n const collections = new Set([...counts].filter(([, count]) => count >= AI_SITE_IMPORT_COLLECTION_MIN).map(([prefix]) => prefix))\n const groupOf = (page: AiSiteImportListedPage) => {\n const path = page.path.replace(/\\/+$/, '') || '/'\n if (page.foundBy === 'home' || menuPaths.has(path)) return 'main'\n const prefix = aiSiteImportPrefix(page.path)\n return prefix && collections.has(prefix) ? `c:${prefix}` : 'main'\n }\n const menuRank = (prefix: string) => {\n const index = menu.findIndex((path) => {\n const first = segmentsOf(path)[0]?.toLowerCase()\n return first === prefix\n })\n return index === -1 ? Number.POSITIVE_INFINITY : index\n }\n const sized = new Map<string, number>()\n for (const page of pages) sized.set(groupOf(page), (sized.get(groupOf(page)) ?? 0) + 1)\n const ordered = [...collections]\n .filter((prefix) => (sized.get(`c:${prefix}`) ?? 0) > 0)\n .sort((a, b) => menuRank(a) - menuRank(b) || (sized.get(`c:${b}`) ?? 0) - (sized.get(`c:${a}`) ?? 0) || a.localeCompare(b))\n const groups: AiSiteImportGroup[] = []\n if ((sized.get('main') ?? 0) > 0) groups.push({ id: 'main', label: 'Main pages', kind: 'main', pages: sized.get('main') ?? 0 })\n for (const prefix of ordered) {\n groups.push({ id: `c:${prefix}`, label: aiSiteImportPrefixLabel(prefix), kind: 'collection', pages: sized.get(`c:${prefix}`) ?? 0 })\n }\n return { groups, groupOf }\n}\n\n/**\n * The main pages in the order a visitor meets them: home, then the menu's\n * order, then the rest as the crawl read them. A collection keeps the crawl's\n * order, which is its sitemap's.\n */\nfunction orderedWithin(\n group: string,\n pages: readonly AiSiteImportListedPage[],\n menu: readonly string[],\n): AiSiteImportListedPage[] {\n if (group !== 'main') return [...pages]\n const rank = (page: AiSiteImportListedPage) => {\n if (page.foundBy === 'home' || segmentsOf(page.path).length === 0) return -1\n const path = page.path.replace(/\\/+$/, '') || '/'\n const index = menu.findIndex((entry) => (entry.replace(/\\/+$/, '') || '/') === path)\n return index === -1 ? Number.POSITIVE_INFINITY : index\n }\n return pages\n .map((page, order) => ({ page, order }))\n .sort((a, b) => rank(a.page) - rank(b.page) || a.order - b.order)\n .map(({ page }) => page)\n}\n\n/**\n * The address a page takes on the new site: one segment, as every Aglyn page\n * has, from the last segment of its old address; home is the root. Two pages\n * that would take the same address are told apart by their collection, then\n * by a number. The draft writer still makes it unique on the site itself.\n */\nexport function aiSiteImportSlug(path: string, taken: Set<string>): string {\n const segments = segmentsOf(path)\n if (!segments.length) {\n if (!taken.has('/')) {\n taken.add('/')\n return '/'\n }\n }\n const clean = (value: string) =>\n decodeURIComponent(value)\n .toLowerCase()\n .replace(/\\.(?:html?|php|aspx?)$/, '')\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n const last = clean(segments[segments.length - 1] ?? '') || 'page'\n const prefixed = segments.length > 1 ? clean(`${segments[0]}-${segments[segments.length - 1]}`) : last\n for (const candidate of [last, prefixed]) {\n if (candidate && !taken.has(candidate)) {\n taken.add(candidate)\n return candidate\n }\n }\n let attempt = 2\n while (taken.has(`${last}-${attempt}`)) attempt += 1\n const slug = `${last}-${attempt}`\n taken.add(slug)\n return slug\n}\n\nexport interface AiSiteImportInventoryInput {\n domain: string\n siteName: string\n ownership: AiSiteImportState['ownership']\n readAt: string\n pages: readonly AiSiteImportListedPage[]\n /** Addresses the home page's menu links, in its order. */\n menu: readonly string[]\n /** What the crawl could not read, by reason. */\n skipped: ReadonlyArray<{ url: string; reason: AiSiteImportLeftOutReason; sameAs?: string }>\n /** Skips the crawl only counted. */\n skippedOverflow?: number\n stoppedBy: string | null\n /**\n * The read's verdict from the crawl itself (`aiSiteImportReadVerdict`), with\n * the status and edge the home page answered with; read from `pages` and\n * `skipped` when absent.\n */\n verdict?: AiSiteImportReadVerdict | null\n /** The plan's page count; `null` for none. */\n pageLimit: number | null\n existingPages: number\n /** Mints one draft id; the inventory names every page's draft before any is written. */\n mintId: () => string\n wavePages?: number\n}\n\n/**\n * The site's inventory cut into waves, every page left out said with its\n * reason. Pure: the step reads the site, this decides what comes in.\n */\nexport function aiSiteImportInventory(input: AiSiteImportInventoryInput): AiSiteImportState {\n const wavePages = Math.max(1, Math.floor(input.wavePages ?? AI_SITE_IMPORT_WAVE_PAGES))\n const limit = input.pageLimit === null || !Number.isFinite(input.pageLimit) ? null : Math.max(0, Math.floor(input.pageLimit))\n const leftOut: AiSiteImportLeftOut[] = []\n const leftOutCount: Partial<Record<AiSiteImportLeftOutReason, number>> = {}\n const leave = (entry: AiSiteImportLeftOut) => {\n leftOutCount[entry.reason] = (leftOutCount[entry.reason] ?? 0) + 1\n if (leftOut.length < AI_SITE_IMPORT_LEFT_OUT_LISTED) leftOut.push(entry)\n }\n // The read asks for a wave's worth past the plan's room, so a page its page\n // budget never reached is past the plan; any other stop is not the plan's.\n const unreached: AiSiteImportLeftOutReason = input.stoppedBy === 'page-budget' && limit !== null ? 'plan-limit' : 'not-reached'\n for (const skipped of input.skipped) {\n let path = '/'\n let sameAs: string | null = null\n try {\n const url = new URL(skipped.url)\n // Its query too: forty addresses of one path are told apart by it.\n path = `${url.pathname}${url.search}`\n if (skipped.sameAs) sameAs = new URL(skipped.sameAs).pathname\n } catch {\n // A malformed address keeps the root as its path.\n }\n leave({ url: skipped.url, path, title: '', reason: skipped.reason === 'not-reached' ? unreached : skipped.reason, ...(sameAs ? { sameAs } : {}) })\n }\n if (input.skippedOverflow) leftOutCount['unreadable'] = (leftOutCount['unreadable'] ?? 0) + input.skippedOverflow\n\n // Home first: a site read without its home page plans nothing at all.\n const verdict = input.verdict ?? inventoryVerdict(input)\n if (aiSiteImportReadStops(verdict)) {\n return {\n domain: input.domain,\n siteName: clipLabel(input.siteName) || input.domain,\n ownership: input.ownership,\n readAt: input.readAt,\n pageLimit: limit,\n existingPages: Math.max(0, input.existingPages),\n found: input.pages.length,\n stoppedBy: input.stoppedBy,\n groups: [],\n pages: [],\n waves: [],\n leftOut,\n leftOutCount,\n frame: null,\n verdict,\n }\n }\n\n const readable = input.pages.filter((page) => {\n if (page.words >= AI_SITE_IMPORT_MIN_WORDS || page.images > 0) return true\n leave({ url: page.url, path: page.path, title: clipLabel(page.title), reason: 'empty' })\n return false\n })\n const { groups, groupOf } = aiSiteImportGroups(readable, input.menu)\n let room = limit === null ? Number.POSITIVE_INFINITY : Math.max(0, limit - Math.max(0, input.existingPages))\n const pages: AiSiteImportPage[] = []\n const waves: AiSiteImportWave[] = []\n const taken = new Set<string>()\n for (const group of groups) {\n const members = orderedWithin(group.id, readable.filter((page) => groupOf(page) === group.id), input.menu)\n const kept: AiSiteImportListedPage[] = []\n for (const page of members) {\n if (room > 0) {\n kept.push(page)\n room -= 1\n } else {\n leave({ url: page.url, path: page.path, title: clipLabel(page.title), reason: 'plan-limit' })\n }\n }\n const parts = Math.ceil(kept.length / wavePages)\n for (let part = 0; part < parts; part += 1) {\n const index = waves.length\n const slice = kept.slice(part * wavePages, (part + 1) * wavePages)\n const slots: string[] = []\n for (const page of slice) {\n const slot = `p${pages.length}`\n slots.push(slot)\n pages.push({\n slot,\n url: page.url,\n path: page.path,\n title: clipLabel(page.title) || aiSiteImportPrefixLabel(segmentsOf(page.path).pop() ?? 'Home'),\n group: group.id,\n wave: index,\n draftId: input.mintId(),\n slug: aiSiteImportSlug(page.path, taken),\n words: page.words,\n images: page.images,\n })\n }\n waves.push({\n index,\n label: parts > 1 ? `${group.label}, ${part + 1} of ${parts}` : group.label,\n group: group.id,\n slots,\n frame: index === 0 && group.kind === 'main',\n status: 'waiting',\n startedAt: null,\n finishedAt: null,\n })\n }\n }\n return {\n domain: input.domain,\n siteName: clipLabel(input.siteName) || input.domain,\n ownership: input.ownership,\n readAt: input.readAt,\n pageLimit: limit,\n existingPages: Math.max(0, input.existingPages),\n found: input.pages.length,\n stoppedBy: input.stoppedBy,\n groups,\n pages,\n waves,\n leftOut,\n leftOutCount,\n frame: waves[0]?.frame ? { draftId: input.mintId() } : null,\n verdict,\n }\n}\n\n/** The item ledger an inventory starts: the header and footer, then every page, all pending. */\nexport function aiSiteImportLedger(state: AiSiteImportState): AiJobItemLedger[] {\n const row = (slot: string, op: string, label: string): AiJobItemLedger => ({\n slot,\n op,\n label,\n status: 'pending',\n attempt: 1,\n creditsSpent: 0,\n creditsRefunded: 0,\n outputs: [],\n })\n return [\n ...(state.frame ? [row(AI_SITE_IMPORT_FRAME_SLOT, 'layout', 'Header and footer')] : []),\n ...state.pages.map((page) => row(page.slot, 'page', page.title)),\n ]\n}\n\n/*------------------------------------------\n * What runs next\n *-----------------------------------------*/\n\nexport type AiSiteImportWork =\n | { kind: 'inventory' }\n | { kind: 'start-wave'; wave: AiSiteImportWave }\n /** Pages of the running wave its read did not reach before its clock ran out. */\n | { kind: 'read'; wave: AiSiteImportWave; pages: AiSiteImportPage[] }\n /** The site's plan (AGL-4152), once, after the first wave's read and before its look. */\n | { kind: 'plan'; wave: AiSiteImportWave }\n /** The owner started the build under a plan they saw: its proposed page settled, no model. */\n | { kind: 'plan-accepted'; wave: AiSiteImportWave }\n | { kind: 'frame'; wave: AiSiteImportWave }\n | { kind: 'images'; wave: AiSiteImportWave; page: AiSiteImportPage }\n /** A page's forms, rebuilt as the site's own before the page places them (AGL-4083). */\n | { kind: 'forms'; wave: AiSiteImportWave; page: AiSiteImportPage }\n | { kind: 'page'; wave: AiSiteImportWave; page: AiSiteImportPage }\n | { kind: 'close-wave'; wave: AiSiteImportWave }\n | { kind: 'done' }\n\nconst OPEN = new Set(['pending', 'running'])\n\n/** Whether an item is still to be built. */\nexport function aiSiteImportItemOpen(items: readonly AiJobItemLedger[] | null | undefined, slot: string): boolean {\n const row = (items ?? []).find((entry) => entry.slot === slot)\n return Boolean(row && OPEN.has(row.status))\n}\n\n/** The wave running now, else `null`. */\nexport function aiSiteImportRunningWave(state: AiSiteImportState | null | undefined): AiSiteImportWave | null {\n return state?.waves.find((wave) => wave.status === 'running') ?? null\n}\n\n/** The next wave a person may start, else `null`. */\nexport function aiSiteImportNextWave(state: AiSiteImportState | null | undefined): AiSiteImportWave | null {\n if (!state || aiSiteImportRunningWave(state) || aiSiteImportReadStops(state.verdict)) return null\n return state.waves.find((wave) => wave.status === 'waiting') ?? null\n}\n\n/** The wave a person is reviewing, else `null`. */\nexport function aiSiteImportReviewWave(state: AiSiteImportState | null | undefined): AiSiteImportWave | null {\n return state?.waves.find((wave) => wave.status === 'review') ?? null\n}\n\n/** Whether a page's read holds a form that asks something, where its layout placed one. */\nfunction pageHoldsForm(page: AiSiteImportPage): boolean {\n const { read } = page\n if (!read?.layout || !read.forms?.some((form) => form.fields.length)) return false\n const holds = (nodes: readonly SiteImportLayoutNode[]): boolean =>\n nodes.some((node) => {\n if (node.kind === 'form') return (read.forms?.[node.form]?.fields.length ?? 0) > 0\n if (node.kind === 'row') return node.cells.some((cell) => holds(cell.nodes))\n if (node.kind === 'tabs') return node.tabs.some((tab) => holds(tab.panel))\n return false\n })\n return read.layout.sections.some((section) => holds(section.nodes))\n}\n\n/** What the next pass of the step does. */\nexport function aiSiteImportNextWork(\n state: AiSiteImportState | null | undefined,\n items: readonly AiJobItemLedger[] | null | undefined,\n): AiSiteImportWork {\n // A read that stopped at its home page reads again: the person's Check again.\n if (!state || aiSiteImportReadStops(state.verdict)) return { kind: 'inventory' }\n const running = aiSiteImportRunningWave(state)\n if (!running) {\n const next = aiSiteImportNextWave(state)\n return next ? { kind: 'start-wave', wave: next } : { kind: 'done' }\n }\n const open = running.slots\n .filter((slot) => aiSiteImportItemOpen(items, slot))\n .map((slot) => state.pages.find((page) => page.slot === slot))\n .filter((page): page is AiSiteImportPage => !!page)\n const unread = open.filter((page) => !page.read && !page.refused)\n const reached = open.filter((page) => !unread.includes(page))\n // Nothing in hand: the wave's read goes on first. Pages in hand are built\n // first (AGL-4083): a read that stopped short, or that left pages out to keep\n // the job within what one document holds, goes on once their words are gone.\n if (unread.length && !reached.length) return { kind: 'read', wave: running, pages: unread }\n // A generative Improve it plans the site once, before anything of it is built (AGL-4152).\n if (running.generative && running.frame && state.waves[0]?.index === running.index) {\n if (state.plan === undefined) return { kind: 'plan', wave: running }\n if (state.plan && !state.planAccepted) return { kind: 'plan-accepted', wave: running }\n }\n if (running.frame && state.frame && aiSiteImportItemOpen(items, AI_SITE_IMPORT_FRAME_SLOT)) {\n return { kind: 'frame', wave: running }\n }\n const page = reached[0]\n if (!page) return { kind: 'close-wave', wave: running }\n if (!page.photos) return { kind: 'images', wave: running, page }\n return !page.forms && pageHoldsForm(page) ? { kind: 'forms', wave: running, page } : { kind: 'page', wave: running, page }\n}\n\n/*------------------------------------------\n * The state, one pass at a time\n *-----------------------------------------*/\n\nconst withPage = (state: AiSiteImportState, slot: string, patch: Partial<AiSiteImportPage>): AiSiteImportState => ({\n ...state,\n pages: state.pages.map((page) => (page.slot === slot ? { ...page, ...patch } : page)),\n})\n\nconst withWave = (state: AiSiteImportState, index: number, patch: Partial<AiSiteImportWave>): AiSiteImportState => ({\n ...state,\n waves: state.waves.map((wave) => (wave.index === index ? { ...wave, ...patch } : wave)),\n})\n\n/** A wave started: running, with what its read found on each page. */\nexport function aiSiteImportWaveStarted(\n state: AiSiteImportState,\n index: number,\n at: string,\n reads: ReadonlyMap<string, AiSiteImportPageRead | AiSiteImportLeftOutReason>,\n): AiSiteImportState {\n // The wave reviewed before this one is done: starting the next is the person's say-so.\n const next = withWave(\n { ...state, waves: state.waves.map((wave) => (wave.status === 'review' ? { ...wave, status: 'done' as const } : wave)) },\n index,\n { status: 'running', startedAt: at, finishedAt: null },\n )\n return aiSiteImportPagesRead(next, reads)\n}\n\n/** How many characters a block holds, as the job document stores it. */\nexport function aiSiteImportBlockChars(block: SiteImportBlock): number {\n if (block.kind === 'image') return block.url.length + block.alt.length\n return block.text.length + (block.kind === 'link' ? block.href.length : 0)\n}\n\n/** A page's blocks in order, as many as fit `maxChars` and `maxBlocks`, and whether any had to go. */\nexport function aiSiteImportCapBlocks(\n blocks: readonly SiteImportBlock[],\n maxChars: number,\n maxBlocks: number = AI_SITE_IMPORT_READ_MAX_BLOCKS,\n): { blocks: SiteImportBlock[]; chars: number; cut: boolean } {\n const kept: SiteImportBlock[] = []\n let chars = 0\n for (const block of blocks) {\n const size = aiSiteImportBlockChars(block)\n if (kept.length >= maxBlocks || chars + size > maxChars) return { blocks: kept, chars, cut: true }\n kept.push(block)\n chars += size\n }\n return { blocks: kept, chars, cut: false }\n}\n\nconst readChars = (read: AiSiteImportPageRead | null | undefined) =>\n (read?.blocks ?? []).reduce((total, block) => total + aiSiteImportBlockChars(block), 0) + siteImportLayoutChars(read?.layout)\n\n/**\n * A page's layout in the room the wave has left after its blocks (AGL-4106):\n * cut to the blocks kept, its drawings dropped when it would not fit with\n * them, and left off when it would not fit at all (the page is then laid out\n * from its lines alone).\n */\nfunction layoutWithin(layout: SiteImportLayout | null | undefined, blocks: number, left: number): SiteImportLayout | null {\n if (!layout) return null\n const room = Math.min(left, AI_SITE_IMPORT_LAYOUT_MAX_CHARS)\n const cut = siteImportLayoutWithin(layout, blocks)\n if (siteImportLayoutChars(cut) <= room) return cut\n const light = siteImportLayoutWithoutDrawings(cut)\n return siteImportLayoutChars(light) <= room ? light : null\n}\n\n/**\n * More of a running wave's pages, read now. Their blocks share\n * `AI_SITE_IMPORT_WAVE_READ_MAX_CHARS` with every read still held: a page\n * past it keeps what fits, in order, and is marked `cut`.\n */\nexport function aiSiteImportPagesRead(\n state: AiSiteImportState,\n reads: ReadonlyMap<string, AiSiteImportPageRead | AiSiteImportLeftOutReason>,\n): AiSiteImportState {\n let held = state.pages.filter((page) => !reads.has(page.slot)).reduce((total, page) => total + readChars(page.read), 0)\n let next = state\n for (const [slot, read] of reads) {\n if (typeof read === 'string') {\n next = withPage(next, slot, { refused: read, read: null })\n continue\n }\n let kept = read\n if (read.blocks) {\n const room = Math.max(0, Math.min(AI_SITE_IMPORT_READ_MAX_CHARS, AI_SITE_IMPORT_WAVE_READ_MAX_CHARS - held))\n const capped = aiSiteImportCapBlocks(read.blocks, room)\n held += capped.chars\n kept = { ...read, blocks: capped.blocks, ...(capped.cut || read.cut ? { cut: true } : {}) }\n if (read.layout) {\n const layout = layoutWithin(read.layout, capped.blocks.length, Math.max(0, AI_SITE_IMPORT_WAVE_READ_MAX_CHARS - held))\n held += siteImportLayoutChars(layout)\n kept = { ...kept, layout }\n }\n }\n next = withPage(next, slot, { read: kept, refused: null, title: clipLabel(read.title) || next.pages.find((page) => page.slot === slot)?.title || '' })\n }\n return next\n}\n\n/** A page's photos are in the library. */\nexport function aiSiteImportPhotosIn(\n state: AiSiteImportState,\n slot: string,\n photos: NonNullable<AiSiteImportPage['photos']>,\n): AiSiteImportState {\n return withPage(state, slot, { photos })\n}\n\n/** A page's forms are the site's own (AGL-4083). */\nexport function aiSiteImportFormsIn(\n state: AiSiteImportState,\n slot: string,\n forms: NonNullable<AiSiteImportPage['forms']>,\n note: string | null,\n): AiSiteImportState {\n return withPage(state, slot, { forms, ...(note ? { formNote: note } : {}) })\n}\n\n/**\n * A page is in: nothing of its read is kept but what its row shows (AGL-4083).\n * Every page rides one job document, and on 11/1 what 344 settled pages still\n * held left a 400-page import too little room for the next wave's read.\n */\nexport function aiSiteImportPageSettled(state: AiSiteImportState, slot: string): AiSiteImportState {\n const page = state.pages.find((entry) => entry.slot === slot)\n if (!page?.read) return state\n const { meta: _meta, ...read } = page.read\n return withPage(state, slot, {\n read: { ...read, text: '', sections: [], images: [], blocks: [], forms: [], layout: null, ...(read.videos ? { videos: [] } : {}) },\n ...(page.photos ? { photos: { ...page.photos, assets: [] } } : {}),\n })\n}\n\n/** A wave is in: waiting for its review, or done when no wave follows it. */\nexport function aiSiteImportWaveClosed(state: AiSiteImportState, index: number, at: string): AiSiteImportState {\n const later = state.waves.some((wave) => wave.index > index && wave.status === 'waiting')\n // Start every remaining wave: no review between waves, the last one's close is the stop.\n let next = withWave(state, index, { status: later && !state.autoContinue ? 'review' : 'done', finishedAt: at })\n // What the wave read is no longer needed by any model answer.\n for (const slot of state.waves.find((wave) => wave.index === index)?.slots ?? []) next = aiSiteImportPageSettled(next, slot)\n return next\n}\n\n/**\n * The state of an import a person canceled (AGL-4107): every wave settled. A\n * wave that ran, or was waiting to, is stopped; one already in, for review or\n * done, is in. On 10/29 a canceled import still showed its second wave as\n * running, with nothing running it.\n */\nexport function aiSiteImportCanceled(state: AiSiteImportState, at: string): AiSiteImportState {\n return {\n ...state,\n autoContinue: false,\n waves: state.waves.map((wave): AiSiteImportWave => {\n if (wave.status === 'running' || wave.status === 'waiting') return { ...wave, status: 'stopped', finishedAt: wave.status === 'running' ? at : wave.finishedAt }\n if (wave.status === 'review') return { ...wave, status: 'done' }\n return wave\n }),\n }\n}\n\n/** The state as the console reads it: every page's read text left off. */\nexport function aiSiteImportWire(state: AiSiteImportState | null | undefined): AiSiteImportState | null {\n if (!state) return null\n return {\n ...state,\n pages: state.pages.map((page) =>\n page.read ? { ...page, read: { ...page.read, text: '', images: [], blocks: [], forms: [], layout: null, ...(page.read.videos ? { videos: [] } : {}) } } : page,\n ),\n }\n}\n\n/*------------------------------------------\n * Keep my site, or Improve it (AGL-4152)\n *-----------------------------------------*/\n\n/** A finish read defensively: only `improve` is improve, so an import that never said reads as `keep`. */\nexport function aiSiteImportFinishOf(value: unknown): AiSiteImportFinish {\n return value === 'improve' ? 'improve' : 'keep'\n}\n\n/** Whether the wording is improved: only under `improve`, and on unless the owner switched it off. */\nexport function aiSiteImportWordingOf(finish: AiSiteImportFinish, value: unknown): boolean {\n return finish === 'improve' && value !== false && value !== 'false'\n}\n\n/** The choice an import holds now, read defensively: an older import with none is `keep`, never silently improved. */\nexport function aiSiteImportChoiceOf(state: Pick<AiSiteImportState, 'finish' | 'wording'> | null | undefined): AiSiteImportChoice {\n const finish = aiSiteImportFinishOf(state?.finish)\n return { finish, wording: aiSiteImportWordingOf(finish, state?.wording) }\n}\n\n/** The choice Bring my site carried in the job's inputs (`AI_SITE_IMPORT_FINISH_INPUT`, `AI_SITE_IMPORT_WORDING_INPUT`); none is `keep`. */\nexport function aiSiteImportChoiceFromInputs(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportChoice {\n const finish = aiSiteImportFinishOf(inputs?.[AI_SITE_IMPORT_FINISH_INPUT])\n return { finish, wording: aiSiteImportWordingOf(finish, inputs?.[AI_SITE_IMPORT_WORDING_INPUT]) }\n}\n\n/** Whether a word names a legal entry's part: the word itself, or its plural. */\nconst namesPart = (word: string, part: string) =>\n word === part || word === `${part}s` || (part.endsWith('y') && word === `${part.slice(0, -1)}ies`)\n\n/** Whether a page is a policy (`AI_SITE_IMPORT_LEGAL_SLUGS`) by its address on either site or its title (AGL-4152). */\nexport function aiSiteImportPageIsLegal(page: Pick<AiSiteImportPage, 'slug' | 'title'> & Partial<Pick<AiSiteImportPage, 'path'>>): boolean {\n const wordsOf = (text: string | undefined) => String(text ?? '').toLowerCase().split(/[^\\p{L}\\p{N}]+/u).filter(Boolean)\n const said = [wordsOf(page.slug), wordsOf(page.path), wordsOf(page.title)]\n return AI_SITE_IMPORT_LEGAL_SLUGS.some((entry) => {\n const parts = entry.split('-')\n return said.some((words) => words.some((_, at) => parts.every((part, offset) => namesPart(words[at + offset] ?? '', part))))\n })\n}\n\n/**\n * Whether a page's words are improved under a choice (AGL-4152): only a main\n * page Aglyn AI arranges, under Improve it with its wording on, and never a\n * policy page. Every other page keeps every word as written.\n */\nexport function aiSiteImportPageWording(\n page: Pick<AiSiteImportPage, 'group' | 'words' | 'slug' | 'title' | 'build'> & Partial<Pick<AiSiteImportPage, 'path'>>,\n choice: AiSiteImportChoice,\n): AiSiteImportWords {\n const build = page.build ?? aiSiteImportPageBuild(page)\n return choice.finish === 'improve' && choice.wording && build === 'arranged' && page.group === 'main' && !aiSiteImportPageIsLegal(page) ? 'improved' : 'kept'\n}\n\n/**\n * How a wave is built (AGL-4152): as it was stamped when it started, which a\n * later change never redraws; a wave not yet started is the import's choice\n * now. A wave that started before the choice existed reads as `keep`.\n */\nexport function aiSiteImportWaveChoice(state: Pick<AiSiteImportState, 'finish' | 'wording'> | null | undefined, wave: AiSiteImportWave): AiSiteImportChoice {\n if (!wave.startedAt && (wave.status === 'waiting' || wave.status === 'stopped')) return aiSiteImportChoiceOf(state)\n const finish = aiSiteImportFinishOf(wave.finish)\n return { finish, wording: finish === 'improve' && wave.wording === true }\n}\n\n/**\n * A wave starting (AGL-4152): stamped with the import's choice now, and each\n * of its pages with whether its words are kept or improved. The step stamps a\n * wave once, when it starts, so a change made before a later wave reaches only\n * the waves that have not started.\n */\nexport function aiSiteImportWaveStamped(state: AiSiteImportState, index: number, options: { generative?: boolean; videoPosters?: boolean } = {}): AiSiteImportState {\n const wave = state.waves.find((entry) => entry.index === index)\n if (!wave) return state\n const choice = aiSiteImportChoiceOf(state)\n const slots = new Set(wave.slots)\n // A generative Improve it plans the site and its design with new copy or without (AGL-4152):\n // a page is redesigned from its ledger only where its words are improved too.\n const generative = options.generative === true && choice.finish === 'improve'\n return {\n ...state,\n waves: state.waves.map((entry) =>\n entry.index === index\n ? {\n ...entry,\n finish: choice.finish,\n wording: choice.wording,\n ...(generative ? { generative: true as const } : {}),\n // YouTube's own still for a film with no poster (AGL-4140), whatever the finish.\n ...(options.videoPosters === true ? { videoPosters: true as const } : {}),\n }\n : entry,\n ),\n pages: state.pages.map((page) => (slots.has(page.slot) ? { ...page, wording: aiSiteImportPageWording(page, choice) } : page)),\n }\n}\n\n/**\n * The owner's change between waves (AGL-4152), as the resume door writes it\n * onto an import waiting for a wave: the finish, and the wording switch,\n * always off under `keep`. What is not given keeps the import's choice now.\n * `null` when the job is not an import waiting for a wave that has not started.\n */\nexport function aiSiteImportFinishUpdate(\n job: Pick<AiJob, 'kind' | 'status' | 'review' | 'siteImport'>,\n change: { finish?: AiSiteImportFinish | null; wording?: boolean | null },\n): { 'siteImport.finish': AiSiteImportFinish; 'siteImport.wording': boolean } | null {\n const state = job.siteImport ?? null\n if (job.kind !== AI_SITE_IMPORT_KIND || job.status !== 'needs_review' || job.review?.reason !== 'wave' || !state) return null\n if (aiSiteImportReadStops(state.verdict) || !state.waves.some((wave) => wave.status === 'waiting')) return null\n const now = aiSiteImportChoiceOf(state)\n const finish = change.finish ? aiSiteImportFinishOf(change.finish) : now.finish\n // Under Improve, the switch as given, else as it stands, else on (its default).\n const asked = typeof change.wording === 'boolean' ? change.wording : now.finish === 'improve' ? now.wording : AI_SITE_IMPORT_DEFAULT_CHOICE.wording\n return { 'siteImport.finish': finish, 'siteImport.wording': aiSiteImportWordingOf(finish, asked) }\n}\n\n/** The most source photos an import holds for a later page's slots: each is a library reference, and every page rides one job document. */\nconst SITE_PHOTOS_HELD = 24\n\n/**\n * How a page's generative Improve it came out (AGL-4152), what it added and what\n * it shows, for its row; and the source's photos it left off, which a later\n * page's slot takes before a stock photo.\n */\nexport function aiSiteImportRedesignOf(state: AiSiteImportState, slot: string, redesign: AiSiteImportRedesign, added?: readonly AiSiteImportAddedSection[], pictures?: AiSiteImportPagePictures | null): AiSiteImportState {\n const next = withPage(state, slot, { redesign, ...(added?.length ? { added: [...added] } : {}), ...(pictures ? { pictures } : {}) })\n const left = new Set(pictures?.unplaced ?? [])\n if (!left.size) return next\n const assets = state.pages.find((page) => page.slot === slot)?.photos?.assets ?? []\n const held = next.sitePhotos ?? []\n const pool = [...held, ...assets.filter((photo) => !!photo.from && left.has(photo.from) && !held.some((other) => other.src === photo.src))].slice(0, SITE_PHOTOS_HELD)\n return pool.length ? { ...next, sitePhotos: pool } : next\n}\n\n/*------------------------------------------\n * The site's plan (AGL-4152)\n *-----------------------------------------*/\n\n/** Whether generated pictures are on for an import: as its owner said, else the default. */\nexport function aiSiteImportGeneratedPicturesOn(state: Pick<AiSiteImportState, 'generatedPictures'> | null | undefined): boolean {\n return typeof state?.generatedPictures === 'boolean' ? state.generatedPictures : AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT\n}\n\n/** Whether the job waits on its owner's say-so over a plan (AGL-4152): shown, and nothing of the site built. */\nexport function aiSiteImportPlanAwaits(state: Pick<AiSiteImportState, 'plan' | 'planAccepted'> | null | undefined): boolean {\n return !!state?.plan && !state.planAccepted\n}\n\n/** Whether the site has room for a page more than the import brings in (AGL-4152): the plan's count, against what is there and what is coming. */\nexport function aiSiteImportHasRoomForPage(state: Pick<AiSiteImportState, 'pages'>, room: { limit: number | null; used: number }): boolean {\n if (room.limit === null) return true\n return room.limit - room.used - state.pages.filter((page) => !page.refused).length >= 1\n}\n\n/**\n * The plan in, or the plan that did not pass (`null`). A proposed page takes\n * its place in the wave's rows as a page of its own, new, with no source: its\n * words are written from what the site says, so its one line is its purpose.\n */\nexport function aiSiteImportPlanIn(state: AiSiteImportState, wave: Pick<AiSiteImportWave, 'index'>, plan: AiSiteImportPlan | null, at: string, draftId: string): AiSiteImportState {\n if (!plan?.proposed) return { ...state, plan }\n const proposed = plan.proposed\n const named = (pages: readonly string[]) => pages.map((page) => (page === AI_SITE_IMPORT_PROPOSED_PAGE ? draftId : page))\n const page: AiSiteImportPage = {\n slot: AI_SITE_IMPORT_PROPOSED_SLOT,\n url: `https://${state.domain}/${proposed.slug}`,\n path: `/${proposed.slug}`,\n title: proposed.title,\n group: 'main',\n wave: wave.index,\n draftId,\n slug: proposed.slug,\n words: 0,\n images: 0,\n origin: 'proposed',\n build: 'arranged',\n wording: 'improved',\n photos: { brought: 0, reused: 0, skipped: 0, assets: [] },\n read: {\n at,\n title: proposed.title,\n text: proposed.purpose,\n sections: [proposed.title],\n images: [],\n blocks: [\n { kind: 'heading', level: 1, text: proposed.title, region: 'main' },\n { kind: 'paragraph', text: proposed.purpose, region: 'main' },\n ],\n words: proposed.purpose.split(/\\s+/).filter(Boolean).length,\n forms: [],\n layout: null,\n },\n }\n const cta = plan.nav.primaryCta\n return {\n ...state,\n plan: {\n ...plan,\n nav: {\n groups: plan.nav.groups.map((group) => ({ ...group, pages: named(group.pages) })),\n primaryCta: cta && cta.target === AI_SITE_IMPORT_PROPOSED_PAGE ? { ...cta, target: draftId } : cta,\n footer: plan.nav.footer.map((column) => ({ ...column, pages: named(column.pages) })),\n },\n proposed: { ...proposed, draftId },\n ...(plan.roles ? { roles: Object.fromEntries(Object.entries(plan.roles).map(([id, role]) => [id === AI_SITE_IMPORT_PROPOSED_PAGE ? draftId : id, role])) } : {}),\n },\n pages: [...state.pages, page],\n waves: state.waves.map((entry) => (entry.index === wave.index ? { ...entry, slots: [...entry.slots, AI_SITE_IMPORT_PROPOSED_SLOT] } : entry)),\n }\n}\n\n/** A plan with its proposed page's row: pending, unless it is the one row a plan has already added. */\nexport function aiSiteImportPlanRow(state: Pick<AiSiteImportState, 'plan'>, items: readonly AiJobItemLedger[]): AiJobItemLedger[] {\n const proposed = state.plan?.proposed\n if (!proposed || items.some((row) => row.slot === AI_SITE_IMPORT_PROPOSED_SLOT)) return [...items]\n return [...items, { slot: AI_SITE_IMPORT_PROPOSED_SLOT, op: 'page', label: proposed.title, status: 'pending', attempt: 1, creditsSpent: 0, creditsRefunded: 0, outputs: [] }]\n}\n\n/**\n * The owner started the build (AGL-4152). A proposed page they switched off is\n * gone: its row, its place in the wave, and every menu entry that named it.\n */\nexport function aiSiteImportPlanAccepted(state: AiSiteImportState, items: readonly AiJobItemLedger[]): { state: AiSiteImportState; items: AiJobItemLedger[] } {\n const plan = state.plan\n if (!plan?.proposed || plan.proposed.on) return { state: { ...state, planAccepted: true }, items: [...items] }\n const off = plan.proposed.draftId\n const kept = (pages: readonly string[]) => pages.filter((page) => page !== off)\n const cta = plan.nav.primaryCta\n return {\n state: {\n ...state,\n planAccepted: true,\n plan: {\n ...plan,\n nav: {\n groups: plan.nav.groups.map((group) => ({ ...group, pages: kept(group.pages) })).filter((group) => group.pages.length),\n primaryCta: cta?.target === off ? null : cta,\n footer: plan.nav.footer.map((column) => ({ ...column, pages: kept(column.pages) })).filter((column) => column.pages.length),\n },\n proposed: { ...plan.proposed, on: false },\n },\n pages: state.pages.filter((page) => page.slot !== AI_SITE_IMPORT_PROPOSED_SLOT),\n waves: state.waves.map((wave) => ({ ...wave, slots: wave.slots.filter((slot) => slot !== AI_SITE_IMPORT_PROPOSED_SLOT) })),\n },\n items: items.filter((row) => row.slot !== AI_SITE_IMPORT_PROPOSED_SLOT),\n }\n}\n\n/**\n * The owner's answer to a plan (AGL-4152), as the resume door writes it onto\n * an import waiting on one. What is not given stands. `null` when the job is\n * not an import waiting on a plan, or nothing is asked.\n */\nexport function aiSiteImportPlanUpdate(\n job: Pick<AiJob, 'kind' | 'status' | 'review' | 'siteImport'>,\n change: AiSiteImportPlanChoice,\n): Record<string, boolean> | null {\n const state = job.siteImport ?? null\n if (job.kind !== AI_SITE_IMPORT_KIND || job.status !== 'needs_review' || job.review?.reason !== 'wave' || !aiSiteImportPlanAwaits(state)) return null\n const update: Record<string, boolean> = {}\n if (typeof change.addPage === 'boolean' && state?.plan?.proposed) update['siteImport.plan.proposed.on'] = change.addPage\n if (typeof change.pictures === 'boolean') update['siteImport.generatedPictures'] = change.pictures\n return Object.keys(update).length ? update : null\n}\n\n/**\n * A page whose rewrite was refused (AGL-4152): it keeps every word as\n * written, and its row reads as kept. Only a page stamped `improved` changes.\n */\nexport function aiSiteImportWordsKept(state: AiSiteImportState, slot: string): AiSiteImportState {\n if (!state.pages.some((page) => page.slot === slot && page.wording === 'improved')) return state\n return { ...state, pages: state.pages.map((page) => (page.slot === slot ? { ...page, wording: 'kept' as const } : page)) }\n}\n\n/** The pages of a wave whose words a choice improves, of those it still owes (AGL-4152). */\nexport function aiSiteImportWordingPages(\n state: AiSiteImportState,\n wave: AiSiteImportWave,\n choice: AiSiteImportChoice,\n items?: readonly AiJobItemLedger[] | null,\n): number {\n if (choice.finish !== 'improve' || !choice.wording) return 0\n return wave.slots.filter((slot) => {\n const page = state.pages.find((entry) => entry.slot === slot)\n return !!page && !page.refused && (!items || aiSiteImportItemOpen(items, slot)) && aiSiteImportPageWording(page, choice) === 'improved'\n }).length\n}\n\n/**\n * What improving this many pages' wording adds (AGL-4152): a reworded page\n * is quoted as measured (`AI_MEASURED_IMPORT_CREDITS.reworded`) in place of an\n * arranged one, its design answer and its wording together, so each adds the\n * difference between the two. Its ceiling, the page's two passes, does not\n * move, and no price is new.\n */\nexport function aiSiteImportWordingCredits(pages: number): { likely: number; p90: number } {\n const count = whole(pages)\n const { reworded, arranged } = AI_MEASURED_IMPORT_CREDITS\n return { likely: count * (reworded.median - arranged.median), p90: count * (reworded.p90 - arranged.p90) }\n}\n\n/*------------------------------------------\n * Credits\n *-----------------------------------------*/\n\n/**\n * How a page is built (AGL-4083), decided by code: every page of a collection\n * (a blog, the legal pages, news) is copied as it is; every main page is\n * arranged by Aglyn AI whatever its length (AGL-4106), its words kept as\n * written. Both are laid out from the source's own layout.\n */\nexport function aiSiteImportPageBuild(page: Pick<AiSiteImportPage, 'group' | 'words'>): AiSiteImportBuild {\n return page.group !== 'main' ? 'copied' : 'arranged'\n}\n\nconst whole = (value: number | undefined) => Math.max(0, Math.floor(Number.isFinite(value) ? (value as number) : 0))\n\n/**\n * What bringing in this many pages costs, quoted before it starts (AGL-3976):\n * each page an AI page as measured, its ceiling its two passes, and the\n * site's header and footer once when the wave builds them. Pages the step has\n * chosen a build for (AGL-4083) are priced by it: `arranged` at the\n * arrangement answer and its listing, `copied` at the listing alone. Of the\n * arranged, those `reworded` under Also improve my wording (AGL-4152) are\n * priced as an AI page, inside the same ceiling.\n */\nexport function aiSiteImportCreditRange(\n pages: number,\n options: {\n frame?: boolean\n arranged?: number\n copied?: number\n reworded?: number\n /** The site's plan, still owed under a generative Improve it (AGL-4152), priced as a paid site's plan until it is measured. */\n plan?: boolean\n /** A proposed page not yet among the wave's own, quoted as a redesigned page (AGL-4152). */\n proposed?: number\n /** Generated pictures it may take at most (AGL-4152): in its ceiling only, since each takes what nothing else fills. */\n pictures?: number\n } = {},\n): AiCreditRange {\n const count = whole(pages)\n const proposed = whole(options.proposed)\n const arranged = whole(options.arranged) + proposed\n const copied = whole(options.copied)\n const wording = aiSiteImportWordingCredits(Math.min(arranged, whole(options.reworded) + proposed))\n const measured = AI_MEASURED_IMPORT_CREDITS\n const plan = options.plan ? AI_MEASURED_PAID_SITE_CREDITS.plan : { median: 0, p90: 0 }\n return aiCreditRangeOrdered({\n likely:\n count * measured.page.median +\n arranged * measured.arranged.median +\n wording.likely +\n copied * measured.copied.median +\n (options.frame ? measured.frame.median : 0) +\n plan.median,\n p90: count * measured.page.p90 + arranged * measured.arranged.p90 + wording.p90 + copied * measured.copied.p90 + (options.frame ? measured.frame.p90 : 0) + plan.p90,\n ceiling:\n (count + arranged) * AI_SITE_IMPORT_PAGE_CEILING_CREDITS +\n copied * AI_SITE_IMPORT_COPIED_CEILING_CREDITS +\n (options.frame ? AI_SITE_IMPORT_FRAME_CEILING_CREDITS : 0) +\n (options.plan ? AI_SITE_IMPORT_PLAN_CEILING_CREDITS : 0) +\n whole(options.pictures) * aiMediaCreditsPerPicture('photo', undefined, '1K'),\n })\n}\n\n/**\n * What a wave still owes, by how its pages are built, and whether its header\n * and footer are owed. `reworded` are those of `arranged` whose words the\n * wave improves (AGL-4152): as stamped once it has started, and as the\n * import's choice now would stamp them before.\n */\nexport function aiSiteImportWaveOwed(\n state: AiSiteImportState,\n wave: AiSiteImportWave,\n items?: readonly AiJobItemLedger[] | null,\n): { pages: number; arranged: number; reworded: number; copied: number; frame: boolean; plan?: boolean; proposed?: number; pictures?: number } {\n const owed = (slot: string) => (items ? aiSiteImportItemOpen(items, slot) : true)\n const choice = aiSiteImportWaveChoice(state, wave)\n // A generative Improve it's own (AGL-4152): its frame draws from the plan, and a plan is owed once.\n const generative = aiSiteImportWaveIsGenerative(state, wave)\n const planned = generative && !!state.plan\n // A header and footer drawn from the source's own menu ask no model (AGL-4108), so are owed nothing.\n const counts = { pages: 0, arranged: 0, reworded: 0, copied: 0, frame: wave.frame && !!state.frame && !aiSiteImportFrameIsRead(state) && !planned && owed(AI_SITE_IMPORT_FRAME_SLOT) }\n for (const slot of wave.slots) {\n const page = state.pages.find((entry) => entry.slot === slot)\n if (!owed(slot) || page?.refused) continue\n if (page?.build === 'arranged') {\n counts.arranged += 1\n if ((wave.startedAt ? page.wording : aiSiteImportPageWording(page, choice)) === 'improved') counts.reworded += 1\n } else if (page?.build === 'copied') counts.copied += 1\n else counts.pages += 1\n }\n if (!generative) return counts\n const first = state.waves[0]?.index === wave.index && wave.frame\n // Before the plan is in, a page it may propose is quoted, where the plan's count has room for one.\n const proposed = first && state.plan === undefined && choice.wording && aiSiteImportHasRoomForPage(state, { limit: state.pageLimit, used: state.existingPages }) ? 1 : 0\n const pictures = choice.wording && aiSiteImportGeneratedPicturesOn(state) ? (counts.reworded + proposed) * AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE : 0\n return { ...counts, ...(first && state.plan === undefined ? { plan: true } : {}), ...(proposed ? { proposed } : {}), ...(pictures ? { pictures } : {}) }\n}\n\n/**\n * Whether a wave is a generative Improve it (AGL-4152): as stamped once it has\n * started; before, whether the import was read under the flag and asks to be\n * improved now.\n */\nexport function aiSiteImportWaveIsGenerative(state: Pick<AiSiteImportState, 'generative' | 'finish' | 'wording'>, wave: AiSiteImportWave): boolean {\n return wave.startedAt ? wave.generative === true : state.generative === true && aiSiteImportChoiceOf(state).finish === 'improve'\n}\n\n/** A wave's quote: the pages it has still to bring in, and its header and footer while they are owed. */\nexport function aiSiteImportWaveCreditRange(\n state: AiSiteImportState,\n wave: AiSiteImportWave,\n items?: readonly AiJobItemLedger[] | null,\n): AiCreditRange {\n const owed = aiSiteImportWaveOwed(state, wave, items)\n return aiSiteImportCreditRange(owed.pages, { frame: owed.frame, arranged: owed.arranged, reworded: owed.reworded, copied: owed.copied, plan: owed.plan, proposed: owed.proposed, pictures: owed.pictures })\n}\n\n/** Every wave still waiting, quoted at once: \"Start every remaining wave\" (AGL-4083). */\nexport function aiSiteImportRemainingCreditRange(\n state: AiSiteImportState,\n items?: readonly AiJobItemLedger[] | null,\n): AiCreditRange {\n const total = { pages: 0, arranged: 0, reworded: 0, copied: 0, frame: false, plan: false, proposed: 0, pictures: 0 }\n for (const wave of state.waves) {\n if (wave.status !== 'waiting') continue\n const owed = aiSiteImportWaveOwed(state, wave, items)\n total.pages += owed.pages\n total.arranged += owed.arranged\n total.reworded += owed.reworded\n total.copied += owed.copied\n total.frame = total.frame || owed.frame\n total.plan = total.plan || owed.plan === true\n total.proposed += owed.proposed ?? 0\n total.pictures += owed.pictures ?? 0\n }\n return aiSiteImportCreditRange(total.pages, { frame: total.frame, arranged: total.arranged, reworded: total.reworded, copied: total.copied, plan: total.plan, proposed: total.proposed, pictures: total.pictures })\n}\n\n/**\n * \"About 95 credits (up to 600): 7 pages arranged by Aglyn AI, 3 copied as\n * they are\"; the build is named once the step has chosen, and pages whose\n * words are improved too (AGL-4152) as \"arranged and reworded by Aglyn AI\".\n */\nexport function aiSiteImportQuoteText(\n range: AiCreditRange,\n owed: Pick<ReturnType<typeof aiSiteImportWaveOwed>, 'arranged' | 'copied'> & Partial<Pick<ReturnType<typeof aiSiteImportWaveOwed>, 'reworded' | 'plan' | 'proposed' | 'pictures'>>,\n options: { generative?: boolean } = {},\n): string {\n const reworded = Math.min(owed.arranged, whole(owed.reworded))\n const runs: Array<[number, (count: number) => string]> = [\n // Under a generative Improve it, a page redesigned from its ledger (AGL-4152).\n [reworded, () => (options.generative ? `redesigned by ${PLATFORM_BRAND_NAME} AI` : `arranged and reworded by ${PLATFORM_BRAND_NAME} AI`)],\n [owed.arranged - reworded, () => `arranged by ${PLATFORM_BRAND_NAME} AI`],\n [owed.copied, (count) => `copied as ${count === 1 ? 'it is' : 'they are'}`],\n ]\n const parts: string[] = []\n for (const [count, what] of runs) {\n if (!count) continue\n // The first run names its pages; the rest are counted beside it.\n parts.push(`${parts.length ? count.toLocaleString('en-US') : aiSiteImportPagesText(count)} ${what(count)}`)\n }\n // What a generative Improve it adds (AGL-4152): its plan, the page it may propose, the pictures it may generate.\n if (owed.plan) parts.unshift('your site’s plan')\n if (owed.proposed) parts.push('a new page if the plan proposes one')\n if (owed.pictures) parts.push(`up to ${owed.pictures.toLocaleString('en-US')} generated pictures`)\n return parts.length ? `${aiCreditRangeText(range)}: ${parts.join(', ')}` : aiCreditRangeText(range)\n}\n\n/*------------------------------------------\n * Words\n *-----------------------------------------*/\n\n/** Why a page is not brought in, as a person reads it. */\nexport const AI_SITE_IMPORT_LEFT_OUT_COPY: Readonly<Record<AiSiteImportLeftOutReason, string>> = {\n 'plan-limit': 'Past your plan’s page count. Upgrade for more pages, then bring the rest in.',\n robots: 'The site’s robots.txt asks AglynBot not to read it.',\n 'login-form': 'A sign-in page. Pages that ask for a password are never brought in.',\n empty:\n 'No text could be read from this page. If your site is built in a way that needs a browser to show its words, it cannot be brought in yet.',\n unreadable: 'It could not be read just now.',\n blocked:\n 'The site’s bot protection or firewall turned AglynBot away. Allow AglynBot in your site’s bot or firewall settings, then bring the site in again.',\n 'too-large': 'Larger than a page can be to bring in.',\n 'off-site': 'It sends visitors to another website.',\n 'not-reached': 'Not reached: the read stopped before it got to this page.',\n file: 'A file, not a page.',\n duplicate: 'A second address for the same page, so it is not brought in twice.',\n 'system-page': 'A cart, checkout, account, or search screen your website platform makes, not a page of your own.',\n missing: 'Your site says this page does not exist, though a link or sitemap on your site still points to it.',\n}\n\n/** \"3 pages\" / \"1 page\". */\nexport function aiSiteImportPagesText(count: number): string {\n return `${count.toLocaleString('en-US')} ${count === 1 ? 'page' : 'pages'}`\n}\n\n/** The review a finished wave parks on, or the first wave's go-ahead once the site is read. */\nexport function aiSiteImportWaveMessage(\n state: AiSiteImportState,\n items: readonly AiJobItemLedger[] | null | undefined,\n): string {\n // A read that stopped at its home page says why, and what to do.\n if (aiSiteImportReadStops(state.verdict)) return aiSiteImportReadVerdictMessage(state.verdict, state.domain) ?? ''\n const next = aiSiteImportNextWave(state)\n const reviewing = aiSiteImportReviewWave(state)\n if (!reviewing) {\n const kept = state.pages.length\n return next\n ? `Your site is read: ${aiSiteImportPagesText(kept)} to bring in, in ${state.waves.length === 1 ? 'one wave' : `${state.waves.length} waves`}. Start the first wave when you are ready.`\n : 'Your site is read, and nothing on it can be brought in.'\n }\n const rows = (items ?? []).filter((row) => reviewing.slots.includes(row.slot))\n const done = rows.filter((row) => row.status === 'succeeded' || row.status === 'degraded').length\n const lead = `${reviewing.label} is in: ${aiSiteImportPagesText(done)} ready to review as drafts.`\n return next ? `${lead} Start ${next.label} when you are ready.` : lead\n}\n"],"names":["PLATFORM_BRAND_NAME","videoEmbedOf","aiCreditRangeOrdered","aiCreditRangeText","AI_MEASURED_IMPORT_CREDITS","AI_MEASURED_PAID_SITE_CREDITS","aiMediaCreditsPerPicture","AI_SITE_IMPORT_KIND","AI_SITE_IMPORT_DOMAIN_INPUT","AI_SITE_IMPORT_WAVE_PAGES","AI_SITE_IMPORT_MAX_PAGES","AI_SITE_IMPORT_COLLECTION_MIN","AI_SITE_IMPORT_IMAGES_PER_PAGE","AI_SITE_IMPORT_PAGE_TEXT_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","AI_SITE_IMPORT_READ_MAX_BLOCKS","AI_SITE_IMPORT_READ_MAX_CHARS","AI_SITE_IMPORT_LAYOUT_MAX_CHARS","AI_SITE_IMPORT_WAVE_READ_MAX_CHARS","AI_SITE_IMPORT_PROSE_WORDS","AI_SITE_IMPORT_BLOCKED_STATUSES","Set","AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MIN_WORDS","AI_SITE_IMPORT_FRAME_SLOT","AI_SITE_IMPORT_PAGE_CEILING_CREDITS","AI_SITE_IMPORT_COPIED_CEILING_CREDITS","AI_SITE_IMPORT_FRAME_CEILING_CREDITS","AI_SITE_IMPORT_LEFT_OUT_LISTED","AI_SITE_IMPORT_LEFT_OUT_REASONS","AI_SITE_IMPORT_UNREAD_REASONS","aiSiteImportOtherAddresses","state","key","path","split","replace","leftOut","flatMap","entry","reason","sameAs","SITE_IMPORT_GROUP_KINDS","siteImportWidthOf","px","Number","isFinite","siteImportLayoutLines","nodes","out","visit","list","node","kind","push","line","poster","undefined","cell","cells","item","items","lines","row","rows","tab","tabs","label","panel","siteImportLayoutChars","layout","JSON","stringify","length","siteImportLayoutWithin","count","keep","ref","sections","map","section","backdrop","behind","video","siteImportFilterNodes","filter","_poster","rest","some","trimItem","icon","image","imageFit","figure","figureMuted","ctas","cta","SITE_IMPORT_PLAY_WORDS","siteImportFilmSource","embed","trim","src","hosted","file","test","aiSiteImportOwnFilms","read","photos","videos","held","photo","from","place","source","block","blocks","has","url","includes","SITE_IMPORT_APPROVED_HOSTS_MAX","siteImportApprovedHost","value","host","toLowerCase","bare","startsWith","slice","siteImportApprovedHostsWith","current","addresses","owner","Array","isArray","have","hostnameOf","address","URL","hostname","add","aiSiteImportVideoNote","own","films","approved","posterless","notes","Boolean","join","siteImportLayoutWithoutDrawings","icons","svg","viewBox","AI_SITE_IMPORT_FINISH_INPUT","AI_SITE_IMPORT_WORDING_INPUT","AI_SITE_IMPORT_DEFAULT_CHOICE","finish","wording","AI_SITE_IMPORT_LEGAL_SLUGS","AI_SITE_IMPORT_LAYOUT_KEPT","AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN","AI_SITE_IMPORT_PAGE_ROLES","AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT","AI_SITE_IMPORT_PLAN_FELL_BACK","AI_SITE_IMPORT_PROPOSED_SLOT","AI_SITE_IMPORT_PROPOSED_PAGE","AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE","AI_SITE_IMPORT_PLAN_CEILING_CREDITS","aiSiteImportFrameIsRead","nav","home","pathOfUrl","pathname","wordsOf","text","match","isOneOfTheSitesPages","readVerdictOf","blocked","total","edge","base","homeStatus","status","homeProblem","problem","homeProblemOfSkip","aiSiteImportReadVerdict","crawled","skip","skipped","Math","max","sitemapUrls","pages","page","find","foundBy","words","reduce","sum","inline","empty","images","aiSiteImportReadStops","verdict","aiSiteImportReadVerdictReason","AI_SITE_IMPORT_EDGE_HINTS","vercel","cloudflare","NOTHING_SPENT","homeProblemText","aiSiteImportReadVerdictMessage","domain","others","more","toLocaleString","lead","inventoryVerdict","input","skippedOverflow","clipLabel","String","trimEnd","segmentsOf","aiSiteImportPrefix","segments","first","aiSiteImportPrefixLabel","prefix","decodeURIComponent","charAt","toUpperCase","aiSiteImportGroups","menu","sized","counts","Map","set","get","menuPaths","collections","groupOf","menuRank","index","findIndex","POSITIVE_INFINITY","ordered","sort","a","b","localeCompare","groups","id","orderedWithin","group","rank","order","aiSiteImportSlug","taken","clean","last","prefixed","candidate","attempt","slug","aiSiteImportInventory","leftOutCount","waves","wavePages","floor","limit","pageLimit","leave","unreached","stoppedBy","search","title","siteName","ownership","readAt","existingPages","found","frame","readable","room","members","kept","parts","ceil","part","slots","slot","pop","wave","draftId","mintId","startedAt","finishedAt","aiSiteImportLedger","op","creditsSpent","creditsRefunded","outputs","OPEN","aiSiteImportItemOpen","aiSiteImportRunningWave","aiSiteImportNextWave","aiSiteImportReviewWave","pageHoldsForm","forms","form","fields","holds","aiSiteImportNextWork","running","next","open","unread","refused","reached","generative","plan","planAccepted","withPage","patch","withWave","aiSiteImportWaveStarted","at","reads","aiSiteImportPagesRead","aiSiteImportBlockChars","alt","href","aiSiteImportCapBlocks","maxChars","maxBlocks","chars","size","cut","readChars","layoutWithin","left","min","light","capped","aiSiteImportPhotosIn","aiSiteImportFormsIn","note","formNote","aiSiteImportPageSettled","meta","_meta","assets","aiSiteImportWaveClosed","later","autoContinue","aiSiteImportCanceled","aiSiteImportWire","aiSiteImportFinishOf","aiSiteImportWordingOf","aiSiteImportChoiceOf","aiSiteImportChoiceFromInputs","inputs","namesPart","word","endsWith","aiSiteImportPageIsLegal","said","_","every","offset","aiSiteImportPageWording","choice","build","aiSiteImportPageBuild","aiSiteImportWaveChoice","aiSiteImportWaveStamped","options","videoPosters","aiSiteImportFinishUpdate","job","change","siteImport","review","now","asked","SITE_PHOTOS_HELD","aiSiteImportRedesignOf","redesign","added","pictures","unplaced","sitePhotos","pool","other","aiSiteImportGeneratedPicturesOn","generatedPictures","aiSiteImportPlanAwaits","aiSiteImportHasRoomForPage","used","aiSiteImportPlanIn","proposed","named","origin","brought","reused","purpose","level","region","primaryCta","target","footer","column","roles","Object","fromEntries","entries","role","aiSiteImportPlanRow","aiSiteImportPlanAccepted","on","off","aiSiteImportPlanUpdate","update","addPage","keys","aiSiteImportWordsKept","aiSiteImportWordingPages","aiSiteImportWordingCredits","whole","reworded","arranged","likely","median","p90","aiSiteImportCreditRange","copied","measured","ceiling","aiSiteImportWaveOwed","owed","aiSiteImportWaveIsGenerative","planned","aiSiteImportWaveCreditRange","aiSiteImportRemainingCreditRange","aiSiteImportQuoteText","range","runs","what","aiSiteImportPagesText","unshift","AI_SITE_IMPORT_LEFT_OUT_COPY","robots","unreadable","duplicate","missing","aiSiteImportWaveMessage","reviewing","done"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAgC2C,GAE3C,SAASA,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,YAAY,QAAQ,mDAAkD;AAE/E,SAASC,oBAAoB,EAAEC,iBAAiB,EAAEC,0BAA0B,EAAEC,6BAA6B,QAA4B,0BAAsB;AAC7J,SAASC,wBAAwB,QAAQ,wBAAoB;AAG7D,kBAAkB,GAClB,OAAO,MAAMC,sBAAsB,SAAiB;AAEpD,0DAA0D,GAC1D,OAAO,MAAMC,8BAA8B,SAAQ;AAEnD,uCAAuC,GACvC,OAAO,MAAMC,4BAA4B,GAAE;AAE3C;;;;;;CAMC,GACD,OAAO,MAAMC,2BAA2B,IAAG;AAE3C,yEAAyE,GACzE,OAAO,MAAMC,gCAAgC,EAAC;AAE9C,8CAA8C,GAC9C,OAAO,MAAMC,iCAAiC,EAAC;AAE/C;;;;CAIC,GACD,OAAO,MAAMC,qCAAqC,KAAK;AAEvD,wGAAwG,GACxG,OAAO,MAAMC,8BA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,SAAS;AAC7E;AAEA,6FAA6F,GAC7F,OAAO,SAAS4X,wBACdva,KAAwB,EACxB6B,KAAoD;QAGHqJ;IADjD,iEAAiE;IACjE,IAAIR,sBAAsB1K,MAAM2K,OAAO,GAAG,QAAOO,kCAAAA,+BAA+BlL,MAAM2K,OAAO,EAAE3K,MAAMmL,MAAM,aAA1DD,kCAA+D;IAChH,MAAMwG,OAAOT,qBAAqBjR;IAClC,MAAMwa,YAAYtJ,uBAAuBlR;IACzC,IAAI,CAACwa,WAAW;QACd,MAAM3K,OAAO7P,MAAMgK,KAAK,CAACvH,MAAM;QAC/B,OAAOiP,OACH,CAAC,mBAAmB,EAAEsI,sBAAsBnK,MAAM,iBAAiB,EAAE7P,MAAM0O,KAAK,CAACjM,MAAM,KAAK,IAAI,aAAa,GAAGzC,MAAM0O,KAAK,CAACjM,MAAM,CAAC,MAAM,CAAC,CAAC,0CAA0C,CAAC,GACtL;IACN;IACA,MAAMT,OAAO,CAACH,gBAAAA,QAAS,EAAE,EAAEwB,MAAM,CAAC,CAACtB,MAAQyY,UAAUvK,KAAK,CAAC3K,QAAQ,CAACvD,IAAImO,IAAI;IAC5E,MAAMuK,OAAOzY,KAAKqB,MAAM,CAAC,CAACtB,MAAQA,IAAIsH,MAAM,KAAK,eAAetH,IAAIsH,MAAM,KAAK,YAAY5G,MAAM;IACjG,MAAM8I,OAAO,GAAGiP,UAAUrY,KAAK,CAAC,QAAQ,EAAE6X,sBAAsBS,MAAM,2BAA2B,CAAC;IAClG,OAAO/I,OAAO,GAAGnG,KAAK,OAAO,EAAEmG,KAAKvP,KAAK,CAAC,oBAAoB,CAAC,GAAGoJ;AACpE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-import.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\n/*==========================================\n * BRING MY SITE: THE WHOLE SITE, IN REVIEWED WAVES (AGL-3976, parent AGL-3973).\n *\n * The `import` job reads a website the workspace has PROVED it owns\n * (AGL-3974's claims) and brings it in as draft pages of a new site. This\n * module is the job's plan of record, pure, so the step, the doors, the\n * console and the specs read one set of rules:\n *\n * - **The inventory.** The crawl's pages, grouped: the MAIN pages (home, the\n * pages its menu links, every top-level page, and any page that belongs to\n * no collection), then each COLLECTION (an address prefix holding at least\n * `AI_SITE_IMPORT_COLLECTION_MIN` pages: `/blog/…`, `/news/…`, a dated\n * `/2024/05/…` archive).\n * - **Never past the plan.** Pages are kept in that order until the site's\n * room under its plan's page count is used; the rest are LEFT OUT, said so\n * with the reason, never dropped silently. So a plan's limit always leaves\n * out a collection's tail before it leaves out a main page.\n * - **Waves.** The kept pages are cut into waves of at most\n * `AI_SITE_IMPORT_WAVE_PAGES`. The first wave is the main pages, with the\n * site's header and footer built first; each later wave is one\n * collection's next slice, so a review is about one kind of page at a\n * time (\"Blog, 1 of 3\"). A wave runs, then waits for the person: nothing\n * starts the next one but them.\n * - **The price.** An imported page is an AI page (`AI_MEASURED_IMPORT_CREDITS`,\n * about 27 credits); a wave is quoted before it starts as its pages and,\n * for the first, its header and footer. Once the step says how each page\n * is built, a page copied as it is costs its listing and a page Aglyn AI\n * arranges its arrangement, and the quote names both (AGL-4083).\n * - **Home first (AGL-4083).** The read's verdict (`aiSiteImportReadVerdict`)\n * stops an import whose home page could not be read before anything is\n * planned, quoted or spent: a site seen without its home page is not the\n * site. The person is told why and checks again.\n *=========================================*/\n\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\nimport { videoEmbedOf } from '@aglyn/aglyn/plugin-manager/video-embed-provider'\nimport type { SiteImportBlock, SiteImportForm, SiteImportVideo } from '../site-import/site-import-html'\nimport { aiCreditRangeOrdered, aiCreditRangeText, AI_MEASURED_IMPORT_CREDITS, AI_MEASURED_PAID_SITE_CREDITS, type AiCreditRange } from './ai-credit-estimate'\nimport { aiMediaCreditsPerPicture } from './ai-media-credits'\nimport type { AiJob, AiJobItemLedger } from './ai-jobs.types'\n\n/** The job kind. */\nexport const AI_SITE_IMPORT_KIND = 'import' as const\n\n/** The input naming the proved domain the job brings in. */\nexport const AI_SITE_IMPORT_DOMAIN_INPUT = 'domain'\n\n/** The most pages one wave brings in. */\nexport const AI_SITE_IMPORT_WAVE_PAGES = 10\n\n/**\n * The most pages one import reads, whatever the plan allows: an unlimited\n * plan is still one crawl's worth, and the crawl's own time budget may stop\n * sooner (the inventory then says so). Only pages count: a file a link\n * points at is never fetched as one (AGL-4106), so aglyn.com's 209 pages fit\n * with room where 136 press-kit files once took 136 of 200.\n */\nexport const AI_SITE_IMPORT_MAX_PAGES = 400\n\n/** The fewest pages under one address prefix that make it a collection. */\nexport const AI_SITE_IMPORT_COLLECTION_MIN = 3\n\n/** The most photos brought in from one page. */\nexport const AI_SITE_IMPORT_IMAGES_PER_PAGE = 8\n\n/**\n * The most characters of one page's text a wave keeps for the page step's\n * prompt, which reads no more than this; every word is kept on the read's\n * `blocks` (AGL-4083).\n */\nexport const AI_SITE_IMPORT_PAGE_TEXT_MAX_CHARS = 6_000\n\n/** The most sections one imported page is planned with: one for every second-level heading (AGL-4083). */\nexport const AI_SITE_IMPORT_MAX_SECTIONS = 24\n\n/** The most blocks of one page a wave's read keeps. */\nexport const AI_SITE_IMPORT_READ_MAX_BLOCKS = 2_000\n\n/** The most characters of one page's blocks a wave's read keeps: a long policy is 40,000. */\nexport const AI_SITE_IMPORT_READ_MAX_CHARS = 120_000\n\n/** The most characters one page's layout keeps on the job document (AGL-4106): its icons' drawings go first. */\nexport const AI_SITE_IMPORT_LAYOUT_MAX_CHARS = 48_000\n\n/**\n * The most characters of blocks (and their layouts, AGL-4106) the reads of one import hold at once: they\n * ride the job document, which Firestore caps at 1 MiB, beside the\n * inventory and the ledger. A wave's later page past it keeps what fits and\n * says it was cut.\n */\nexport const AI_SITE_IMPORT_WAVE_READ_MAX_CHARS = 400_000\n\n/**\n * A collection's page longer than this is prose: a policy, an article, a\n * long story (AGL-4083). A collection's page is copied as it is whatever its\n * length, and since AGL-4106 a main page is arranged whatever its length:\n * `/product` at 1,072 words is laid out as its source lays it out, not copied\n * as one column.\n */\nexport const AI_SITE_IMPORT_PROSE_WORDS = 900\n\n/** The answers bot protection and firewalls turn a crawler away with: asked to sign in, refused, or told to slow down. */\nexport const AI_SITE_IMPORT_BLOCKED_STATUSES: ReadonlySet<number> = new Set([401, 403, 429])\n\n/** The most characters a section's name, a page's title or a label keeps. */\nexport const AI_SITE_IMPORT_LABEL_MAX_CHARS = 60\n\n/** A page with fewer words than this and no photo has nothing to bring in. */\nexport const AI_SITE_IMPORT_MIN_WORDS = 5\n\n/** The item ledger slot of the site's header and footer. */\nexport const AI_SITE_IMPORT_FRAME_SLOT = 'frame'\n\n/** The ceiling one imported page reserves: its answer pass and its listing pass, at 50 each. */\nexport const AI_SITE_IMPORT_PAGE_CEILING_CREDITS = 100\n\n/** The ceiling a page copied as it is reserves: its listing pass alone. */\nexport const AI_SITE_IMPORT_COPIED_CEILING_CREDITS = 50\n\n/** The ceiling the header and footer reserve: one answer at 50. */\nexport const AI_SITE_IMPORT_FRAME_CEILING_CREDITS = 50\n\n/** The most left-out pages listed by address; the rest are counted. */\nexport const AI_SITE_IMPORT_LEFT_OUT_LISTED = 60\n\n/** A page the crawl read, as the inventory keeps it: no text, only what plans it. */\nexport interface AiSiteImportListedPage {\n url: string\n path: string\n title: string\n foundBy: 'home' | 'sitemap' | 'link'\n words: number\n images: number\n}\n\nexport type AiSiteImportGroupKind = 'main' | 'collection'\n\nexport interface AiSiteImportGroup {\n /** `main`, or `c:<prefix>` for a collection. */\n id: string\n label: string\n kind: AiSiteImportGroupKind\n /** Pages of the group the crawl read, kept or not. */\n pages: number\n}\n\n/** Why a page the site has is not brought in. */\nexport type AiSiteImportLeftOutReason =\n /** Past the site's room under its plan's page count. */\n | 'plan-limit'\n /** robots.txt keeps AglynBot off it. */\n | 'robots'\n /** A sign-in page: refused outright. */\n | 'login-form'\n /** No text and no photo: nothing to bring in. */\n | 'empty'\n /** It could not be read: an error, no answer, or not a web page. */\n | 'unreadable'\n /** The site's bot protection or firewall turned AglynBot away (401, 403 or 429). */\n | 'blocked'\n /** Over the size one page may be. */\n | 'too-large'\n /** It sends visitors to another website. */\n | 'off-site'\n /** The read stopped (its clock, its bytes, its page count) before it got to it (AGL-4083). */\n | 'not-reached'\n /** A link to a file (a download, a PDF with no extension), not a page (AGL-4106). */\n | 'file'\n /** Another address of a page already found: a gallery photo's link, a home page's second address (AGL-4152). */\n | 'duplicate'\n /** The cart, checkout or account screen the site's platform makes, not a page of the owner's (AGL-4152). */\n | 'system-page'\n /** The site itself answers that the address does not exist (404 or 410): a link or sitemap line gone stale (AGL-4152). */\n | 'missing'\n\nexport const AI_SITE_IMPORT_LEFT_OUT_REASONS: readonly AiSiteImportLeftOutReason[] = [\n 'plan-limit',\n 'robots',\n 'login-form',\n 'empty',\n 'unreadable',\n 'blocked',\n 'too-large',\n 'off-site',\n 'not-reached',\n 'file',\n 'duplicate',\n 'system-page',\n 'missing',\n]\n\n/** The reasons that mean the page was there and AglynBot could not read it: the \"could not be read\" of what was found. */\nexport const AI_SITE_IMPORT_UNREAD_REASONS: readonly AiSiteImportLeftOutReason[] = ['unreadable', 'blocked', 'too-large', 'not-reached']\n\nexport interface AiSiteImportLeftOut {\n url: string\n path: string\n title: string\n reason: AiSiteImportLeftOutReason\n /** The path of the page a `duplicate` is another address of: where a link to it goes on the new site. */\n sameAs?: string\n}\n\n/** The left-out addresses that are other addresses of a kept page, as their path and that page's. */\nexport function aiSiteImportOtherAddresses(state: Partial<Pick<AiSiteImportState, 'leftOut'>>): Array<{ path: string; sameAs: string }> {\n const key = (path: string) => path.split('?')[0].replace(/\\/+$/, '') || '/'\n return (state.leftOut ?? []).flatMap((entry) =>\n entry.reason === 'duplicate' && entry.sameAs && key(entry.path) !== key(entry.sameAs) ? [{ path: key(entry.path), sameAs: key(entry.sameAs) }] : [],\n )\n}\n\n/** A photo brought into the site's media library, as a page places it. */\nexport interface AiSiteImportPhoto {\n mediaId: string\n src: string\n width?: number\n height?: number\n alt?: string\n /** The address on the old site it was read from, where a page that is copied places it (AGL-4084). */\n from?: string\n}\n\n/*------------------------------------------\n * The source's layout, as the reader reads it (AGL-4106)\n *-----------------------------------------*/\n\n/**\n * One line of a page, by its index in the page's main-region blocks\n * (`AiSiteImportPageRead.blocks`, 0-based). The layout holds no words of\n * its own: every word is a block's, placed once.\n */\nexport type SiteImportLineRef = number\n\n/** A section's background, in the layout language's bands. */\nexport type SiteImportBand = 'plain' | 'soft' | 'brand' | 'dark'\n\n/** How the source draws a button: filled, outlined, or as a link with button padding. */\nexport type SiteImportButtonStyle = 'primary' | 'secondary' | 'quiet'\n\n/** What a repeated group of the source is. */\nexport type SiteImportGroupKind = 'cards' | 'steps' | 'stats' | 'faq' | 'quotes' | 'logos' | 'pricing' | 'list' | 'text'\n\nexport const SITE_IMPORT_GROUP_KINDS: readonly SiteImportGroupKind[] = ['cards', 'steps', 'stats', 'faq', 'quotes', 'logos', 'pricing', 'list', 'text']\n\n/**\n * One line in place. `role` only where the source's own styling says it (an\n * uppercase eyebrow, a large lede, a large bold statement, a small note).\n */\nexport interface SiteImportLayoutLine {\n kind: 'line'\n line: SiteImportLineRef\n role?: 'eyebrow' | 'lede' | 'statement' | 'note'\n /** The source draws this line (a link, or a `<button>`'s words) as a button. Its destination is the link block's `href`. */\n button?: SiteImportButtonStyle\n /** An eyebrow the source sets in a pill of its own: a fill or a border, its corners rounded (AGL-4138). */\n chip?: true\n /** An eyebrow's color as the source shows it, `#rrggbb` over the ground it sits on (AGL-4138). */\n color?: string\n}\n\n/**\n * How the source frames a picture (AGL-4138): the shape its own `width` and\n * `height` give it, the box it crops it to, its fit in that box, its corners\n * and its shadow. A source that draws a picture at `width: 100%; height:\n * auto` crops nothing, and a page brought in shows it whole.\n */\nexport interface SiteImportPictureFit {\n /** The picture's own shape, width over height, from its `width` and `height` attributes. */\n ratio?: number\n /** A shape the source crops it to, width over height: an `aspect-ratio` on it or its box. */\n box?: number\n /** A height in px the source crops it to, at whatever width its column gives it. */\n height?: number\n objectFit?: 'cover' | 'contain'\n /** Its corners' radius in px, on it or its box; 999 for a round one. */\n radius?: number\n /** It, or its box, is set on a shadow. */\n shadow?: true\n /** A width in px the source holds it to, its `max-width` or its box's: a film's card narrower than its column. */\n measure?: number\n}\n\n/** A picture in place: an image block. */\nexport interface SiteImportLayoutPicture {\n kind: 'picture'\n line: SiteImportLineRef\n /** Where clicking it goes, when it sits in a link. */\n href?: string\n /** It sits in a `<button>` (a video's poster, a lightbox): the picture is kept, the button is not a destination. */\n button?: true\n /** How the source frames it (AGL-4138). */\n fit?: SiteImportPictureFit\n}\n\n/**\n * A filled square an icon sits in (AGL-4138): its fill and corners, and the\n * icon's own color in it, as the source draws them, `#rrggbb`.\n */\nexport interface SiteImportIconTile {\n fill: string\n radius: number\n color: string | null\n}\n\n/** A line the source draws along one side of each item of a group, in place of a box (AGL-4138): a step's rule. */\nexport interface SiteImportRule {\n side: 'top' | 'right' | 'bottom' | 'left'\n /** Its width in px. */\n width: number\n /** Its color, `#rrggbb`; `null` where the source draws it in the words' own. */\n color: string | null\n}\n\n/** An icon standing on its own, by index into `SiteImportLayout.icons`. */\nexport interface SiteImportLayoutIcon {\n kind: 'icon'\n icon: number\n}\n\n/** Where one of the page's forms sat, by index into `AiSiteImportPageRead.forms`. */\nexport interface SiteImportLayoutForm {\n kind: 'form'\n form: number\n}\n\n/**\n * Where one of the page's videos sat (AGL-4140), by index into\n * `AiSiteImportPageRead.videos`. Its poster, when the source shows one, is an\n * image line: the film's first paint, copied into the library as any picture.\n */\nexport interface SiteImportLayoutVideo {\n kind: 'video'\n video: number\n poster?: SiteImportLineRef\n /** How the source frames its poster (AGL-4138), as it frames any picture. */\n fit?: SiteImportPictureFit\n /** The box the source plays it in casts a shadow. */\n shadow?: true\n}\n\n/**\n * A row of columns side by side; `cols` are relative widths in twelfths\n * (`[4, 8]`, `[1, 1, 1]`). Every list of lists is a list of objects: the\n * layout rides a Firestore document, which holds no array inside an array.\n */\nexport interface SiteImportLayoutRow {\n kind: 'row'\n cols: number[]\n cells: Array<{ nodes: SiteImportLayoutNode[] }>\n}\n\n/**\n * One item of a group. Every line of the item is in `lines`, in order, and\n * in exactly one of the named parts.\n */\nexport interface SiteImportLayoutItem {\n lines: SiteImportLineRef[]\n /** The item's name: its heading, its title link, or its first short line. */\n title?: SiteImportLineRef\n /** A stat's figure, a step's number, a plan's price. */\n figure?: SiteImportLineRef\n text?: SiteImportLineRef[]\n /** Its bullet points (a plan's features). */\n list?: SiteImportLineRef[]\n /** Its own call to action: a \"See … →\" link or a button, last in the item, or a button wherever it sits. */\n link?: SiteImportLineRef[]\n /** Those of `link` the source draws as buttons, each as it draws it (AGL-4083). */\n ctas?: Array<{ line: SiteImportLineRef; style: SiteImportButtonStyle }>\n /** A tag on it, a short line in a filled pill: \"Popular\", \"New\", \"Best value\" (AGL-4083). */\n badge?: SiteImportLineRef\n /** What its price is for, beside the price: \"/mo\" (AGL-4083). */\n period?: SiteImportLineRef\n image?: SiteImportLineRef\n /** How the source frames its picture (AGL-4138). */\n imageFit?: SiteImportPictureFit\n /** The icon that leads it, by index into `SiteImportLayout.icons`. */\n icon?: number\n /** The filled square its lead icon sits in (AGL-4138). */\n tile?: SiteImportIconTile\n /** A second icon at the end of its first row, as an arrow that it is a link (AGL-4138), by index into `SiteImportLayout.icons`. */\n mark?: number\n /** Its figure is drawn in the muted words' color, not the brand's (AGL-4138). */\n figureMuted?: true\n /** The icon each of its bullet points carries (a check mark), when they share one. */\n listIcon?: number\n /** Where the item goes as a whole: its title link's address. */\n to?: string\n /** The video it holds (AGL-4140), by index into the read's videos; its poster is its `image`. */\n video?: number\n}\n\nexport interface SiteImportLayoutGroup {\n kind: 'group'\n group: SiteImportGroupKind\n /** Columns the source lays the items out in on a wide screen. */\n columns: number\n /** Columns on a tablet, where the source sets fewer there than on a wide screen (AGL-4138). */\n columnsSm?: number\n /** Each item is drawn as a box: a shadow, a fill of its own, or a border on two sides or more. */\n boxed: boolean\n /** Each item is drawn with a line along one side and no box (AGL-4138). */\n rule?: SiteImportRule\n /** How the items' words are set, where it is not the section's alignment (AGL-4138). */\n align?: 'start' | 'center'\n /**\n * Each item is a row of its own, its parts side by side, one under another:\n * a plan's name, words and button, or a label and its value (AGL-4083).\n */\n inline?: true\n /** Its items are photos, not marks (AGL-4152): a gallery, drawn as its pictures in its columns. Only on a `logos` group. */\n gallery?: true\n items: SiteImportLayoutItem[]\n}\n\n/** A table: rows of cells, each cell its lines (objects, not nested arrays, for Firestore). */\nexport interface SiteImportLayoutTable {\n kind: 'table'\n /** Whether the first row names the columns. */\n header: boolean\n rows: Array<{ cells: Array<{ lines: SiteImportLineRef[] }> }>\n}\n\n/** A tab strip and its panels; a panel the source did not draw is empty. */\nexport interface SiteImportLayoutTabs {\n kind: 'tabs'\n tabs: Array<{ label: SiteImportLineRef | null; selected?: true; panel: SiteImportLayoutNode[] }>\n}\n\nexport type SiteImportLayoutNode =\n | SiteImportLayoutLine\n | SiteImportLayoutPicture\n | SiteImportLayoutIcon\n | SiteImportLayoutForm\n | SiteImportLayoutVideo\n | SiteImportLayoutRow\n | SiteImportLayoutGroup\n | SiteImportLayoutTable\n | SiteImportLayoutTabs\n\n/** Where the hero's picture sits against its words. */\nexport type SiteImportHeroPicture = 'beside' | 'behind' | 'below' | 'above'\n\nexport interface SiteImportLayoutSection {\n /** Its `aria-label`, its heading, or \"Section n\": neutralized, cut to a label. */\n name: string\n /** How its edges were found: a landmark (`<section>`), a container of its own, or its headings. */\n from: 'landmark' | 'container' | 'heading'\n /**\n * Its band against the page's own ground (AGL-4152): a light fill within\n * OKLab ΔE 0.02 of the page's, or none, is `plain`, any other light one\n * `soft`; `brand` and `dark` as its color says.\n */\n band: SiteImportBand\n /**\n * Its band by its color's own lightness, near white `plain` and any other\n * light fill `soft`, where that differs from {@link SiteImportLayoutSection.band}:\n * what Improve it and the design answer's text read. Absent, the two agree.\n */\n absoluteBand?: SiteImportBand\n /** Its background color as `#rrggbb`, when it has one. */\n background: string | null\n /** Its background in the page's dark scheme (AGL-4152), where its stylesheets change it. */\n darkBackground?: string\n /** A gradient, a photo, or a film playing on its own behind it (AGL-4140), its poster an image line. */\n backdrop?: { kind: 'gradient' } | { kind: 'picture'; url: string } | { kind: 'video'; video: number; poster?: SiteImportLineRef }\n align: 'start' | 'center'\n /**\n * How wide the source lets the section's content run on a wide screen, in\n * px (AGL-4083): the narrowest cap on it and the wrappers around its\n * content. Absent where the source sets none.\n */\n width?: number\n /**\n * Set on the section holding the page's first `<h1>`; `measure` the\n * narrowest width in px the source holds its heading to (AGL-4152).\n */\n hero?: { picture: SiteImportHeroPicture | null; measure?: number }\n nodes: SiteImportLayoutNode[]\n /** Every line of the section, in order. */\n lines: SiteImportLineRef[]\n}\n\n/** The widths a page's column is drawn at: the Container element's Max Width choices. */\nexport type SiteImportWidth = 'sm' | 'md' | 'lg' | 'xl'\n\n/**\n * The Max Width a source's cap in px reads as (AGL-4083), `null` for a source\n * that sets none. `sm` is 600 and `md` 900: a post's 760 column is `md`, as a\n * column held to 600 would read narrower than its source.\n */\nexport function siteImportWidthOf(px: number | null | undefined): SiteImportWidth | null {\n if (typeof px !== 'number' || !Number.isFinite(px) || px <= 0) return null\n if (px >= 1400) return 'xl'\n if (px >= 1100) return 'lg'\n if (px >= 750) return 'md'\n return 'sm'\n}\n\n/** An icon the page draws, once however often it repeats. */\nexport interface SiteImportIconShape {\n viewBox: string\n /** One path, for the Besigner's icon element (`iconPath`, drawn on a 24-unit square). */\n path?: string\n /** A small drawing of several shapes, geometry only, for a picture of it. */\n svg?: string\n}\n\n/** What the source's look is made of (AGL-4106), read from its stylesheets. */\nexport interface SiteImportLookFacts {\n fonts: {\n /** The family its body text is set in, as named, when it is not a system font. */\n body: string | null\n /** The family its headings are set in. */\n headings: string | null\n /** The families it loads from Google Fonts, in order. */\n google: string[]\n }\n /** The page's own background, `#rrggbb`. */\n background: string | null\n /** Its body text color. */\n text: string | null\n /** The fill of its filled buttons, the most used first. */\n buttonFill: string | null\n /** The text color on them. */\n buttonText: string | null\n /** Its buttons' corner radius, px. */\n buttonRadius: number | null\n /** The color its text links are drawn in. */\n link: string | null\n /**\n * The brand colors its root's custom properties declare (AGL-4152), the most\n * read first: what it says its brand is, whether or not this page draws it.\n * Absent with none, and on a read made before.\n */\n palette?: string[]\n /** Its header bar's background. */\n header: string | null\n /**\n * The dark ground Keep my site keeps (AGL-4152): its page's fill in its dark\n * scheme where its stylesheets say one, else the fill of its dark bands, the\n * most used first. Absent on a read made before.\n */\n darkBackground?: string | null\n /** The fill of its `soft` bands, the most used first (AGL-4152): what Keep my site's paper is. Absent on a read made before. */\n paperBackground?: string | null\n /** The fill of its `soft` bands in its dark scheme (AGL-4152), where its stylesheets say one. */\n darkPaper?: string | null\n /** Whether its filled buttons are set in capitals (AGL-4152). Absent on a read made before. */\n buttonCase?: 'upper' | 'none' | null\n /** Whether its outlined buttons are set in capitals (AGL-4152); `null` for a page with none. */\n outlinedCase?: 'upper' | 'none' | null\n /** Whether its text buttons and the links a page draws as them are set in capitals (AGL-4152); `null` for a page with none. */\n textCase?: 'upper' | 'none' | null\n /** The words' color on its outlined buttons (AGL-4152), the most used first. */\n buttonOutline?: string | null\n /** The fill an outlined button of its own sets (AGL-4152); `null` where they leave the ground showing. */\n outlinedFill?: string | null\n /**\n * The color most of its eyebrows are drawn in, where that is a color of its\n * own: none of its text's, its buttons' or white (AGL-4138). The look pass\n * pins it as the theme's third color. Absent on a read made before.\n */\n eyebrow?: string | null\n}\n\n/** A page's layout, as the source lays it out (AGL-4106). */\nexport interface SiteImportLayout {\n v: 1\n sections: SiteImportLayoutSection[]\n icons: SiteImportIconShape[]\n look: SiteImportLookFacts\n}\n\n/** One entry of a menu, as the source's header shows it. */\nexport interface SiteImportNavEntry {\n label: string\n /** The line under it in a mega menu. */\n text?: string\n /** Where it goes: absolute http(s), `mailto:` or `tel:`. */\n href: string\n /** Its icon, when it has a one-path icon. */\n iconPath?: string\n viewBox?: string\n /** The heading of the menu's column it sits in (\"By team\"). */\n column?: string\n /** The column of its panel it sits in, by index into its group's `columns` (AGL-4139). */\n at?: number\n /** The filled box its icon sits in, as the source draws it (AGL-4139): its fill, corners and the icon's own color. */\n tile?: { fill: string; radius: number; color: string | null }\n}\n\n/**\n * One column of a menu's panel as the source sets it (AGL-4139): its heading,\n * its other lines of words, the fill it sits on, the picture it shows, and\n * its own width. A footer's filled box is read the same way, with its links.\n */\nexport interface SiteImportNavColumn {\n heading: string | null\n /** Its words outside its links, after its heading, as written. */\n lines: string[]\n /** The fill it sits on against its panel's: none, a light one, the brand's, or a dark one. */\n band: SiteImportBand\n /** The picture it shows outside its links (a featured card's), with `src` once the look pass brings it into the library. */\n image?: { url: string; alt: string }\n /** Its own width in CSS pixels, where the source sets one. */\n width?: number\n /** A footer box's links, as written (AGL-4139). */\n links?: SiteImportFooterLink[]\n /** The icon beside its heading, one path on a 24-unit square. */\n iconPath?: string\n}\n\n/** A top-level item of the source's menu: a link, or a menu of entries under a name. */\nexport interface SiteImportNavGroup {\n label: string\n /** Where the name itself goes; `null` when it only opens its menu. */\n href: string | null\n /** Empty for a plain link. */\n items: SiteImportNavEntry[]\n /** Its panel's columns side by side, in the source's order (AGL-4139); absent on a read made before. */\n columns?: SiteImportNavColumn[]\n /**\n * Its panel (AGL-4139): how wide the source caps it, and whether it opens\n * on hover — hidden until shown, under a name that is not a button.\n */\n panel?: { width: number | null; hover: boolean }\n}\n\n/** A button in the source's header outside its menu (\"Sign in\", \"Start free\"). */\nexport interface SiteImportNavCta {\n label: string\n href: string | null\n style: SiteImportButtonStyle\n}\n\n/** The source's header menu (AGL-4106). Untrusted data from the owner's site. */\nexport interface SiteImportNavTree {\n items: SiteImportNavGroup[]\n ctas: SiteImportNavCta[]\n /** The source shows a menu button on phones. */\n phoneMenu: boolean\n /** The header bar's background, `#rrggbb`. */\n background: string | null\n}\n\nexport interface SiteImportFooterLink {\n label: string\n href: string\n}\n\n/** The source's footer (AGL-4106): its columns, profiles and facts, as written. */\nexport interface SiteImportFooter {\n columns: Array<{ heading: string; links: SiteImportFooterLink[] }>\n /** Its links to profiles on other sites. */\n social: Array<SiteImportFooterLink & { network: string }>\n /** Links outside any column and not a profile (Privacy, Terms, Status). */\n links: SiteImportFooterLink[]\n /** Its lines of text outside links (a tagline), as written. */\n text: string[]\n address: string | null\n phone: string | null\n email: string | null\n /** Its © line, word for word. */\n copyright: string | null\n /** It opens with the site's logo (AGL-4139). */\n logo?: boolean\n /** Its filled boxes, each with its heading, words and links (AGL-4139), which `text` and `links` then leave out. */\n panels?: SiteImportNavColumn[]\n}\n\n/** Every line a layout's nodes place, in order. */\nexport function siteImportLayoutLines(nodes: readonly SiteImportLayoutNode[]): SiteImportLineRef[] {\n const out: SiteImportLineRef[] = []\n const visit = (list: readonly SiteImportLayoutNode[]) => {\n for (const node of list) {\n switch (node.kind) {\n case 'line':\n case 'picture':\n out.push(node.line)\n break\n case 'video':\n if (node.poster !== undefined) out.push(node.poster)\n break\n case 'row':\n for (const cell of node.cells) visit(cell.nodes)\n break\n case 'group':\n for (const item of node.items) out.push(...item.lines)\n break\n case 'table':\n for (const row of node.rows) for (const cell of row.cells) out.push(...cell.lines)\n break\n case 'tabs':\n for (const tab of node.tabs) {\n if (tab.label !== null) out.push(tab.label)\n visit(tab.panel)\n }\n break\n default:\n break\n }\n }\n }\n visit(nodes)\n return out\n}\n\n/** How many characters a layout weighs on the job document. */\nexport function siteImportLayoutChars(layout: SiteImportLayout | null | undefined): number {\n return layout ? JSON.stringify(layout).length : 0\n}\n\n/**\n * A layout over only the first `count` lines (a read the wave's budget cut\n * short): references past the cut are dropped, and what is left empty goes.\n */\nexport function siteImportLayoutWithin(layout: SiteImportLayout, count: number): SiteImportLayout {\n const keep = (ref: SiteImportLineRef) => ref >= 0 && ref < count\n const sections = layout.sections\n .map((section) => {\n const { backdrop } = section\n // A film behind the words keeps its place; a poster past the cut goes (AGL-4140).\n const behind = backdrop?.kind === 'video' && backdrop.poster !== undefined && !keep(backdrop.poster) ? { backdrop: { kind: 'video' as const, video: backdrop.video } } : {}\n return { ...section, ...behind, nodes: siteImportFilterNodes(section.nodes, keep), lines: section.lines.filter(keep) }\n })\n .filter((section) => section.lines.length)\n return { ...layout, sections }\n}\n\n/** Nodes with only the lines `keep` keeps; what is left empty goes. */\nexport function siteImportFilterNodes(list: readonly SiteImportLayoutNode[], keep: (ref: SiteImportLineRef) => boolean): SiteImportLayoutNode[] {\n const nodes = (list: readonly SiteImportLayoutNode[]): SiteImportLayoutNode[] =>\n list.flatMap((node): SiteImportLayoutNode[] => {\n switch (node.kind) {\n case 'line':\n case 'picture':\n return keep(node.line) ? [node] : []\n case 'icon':\n case 'form':\n return [node]\n case 'video': {\n // The film stays where it sat; a poster past the cut goes.\n if (node.poster === undefined || keep(node.poster)) return [node]\n const { poster: _poster, ...rest } = node\n return [rest]\n }\n case 'row': {\n const cells = node.cells.map((cell) => ({ nodes: nodes(cell.nodes) }))\n return cells.some((cell) => cell.nodes.length) ? [{ ...node, cells }] : []\n }\n case 'group': {\n const items = node.items\n .map((item) => trimItem(item, keep))\n .filter((item) => item.lines.length || item.icon !== undefined || item.video !== undefined)\n return items.length ? [{ ...node, items }] : []\n }\n case 'table': {\n const rows = node.rows\n .map((row) => ({ cells: row.cells.map((cell) => ({ lines: cell.lines.filter(keep) })) }))\n .filter((row) => row.cells.some((cell) => cell.lines.length))\n return rows.length ? [{ ...node, rows }] : []\n }\n case 'tabs': {\n const tabs = node.tabs.map((tab) => ({ ...tab, label: tab.label !== null && keep(tab.label) ? tab.label : null, panel: nodes(tab.panel) }))\n return tabs.some((tab) => tab.label !== null || tab.panel.length) ? [{ ...node, tabs }] : []\n }\n default:\n return []\n }\n })\n return nodes(list)\n}\n\nfunction trimItem(item: SiteImportLayoutItem, keep: (ref: SiteImportLineRef) => boolean): SiteImportLayoutItem {\n const out: SiteImportLayoutItem = { ...item, lines: item.lines.filter(keep) }\n for (const key of ['title', 'figure', 'image', 'badge', 'period'] as const) if (out[key] !== undefined && !keep(out[key] as number)) delete out[key]\n if (out.image === undefined) delete out.imageFit\n if (out.figure === undefined) delete out.figureMuted\n for (const key of ['text', 'list', 'link'] as const) {\n const list = out[key]?.filter(keep)\n if (list?.length) out[key] = list\n else delete out[key]\n }\n const ctas = out.ctas?.filter((cta) => keep(cta.line))\n if (ctas?.length) out.ctas = ctas\n else delete out.ctas\n return out\n}\n\n/*------------------------------------------\n * A page's videos (AGL-4140)\n *-----------------------------------------*/\n\n/** The words that name a control as one that plays a film: a facade's label, a \"Watch the film\" button. */\nexport const SITE_IMPORT_PLAY_WORDS = /\\b(?:play|watch|video|film)\\b/i\n\n/**\n * Where a video of a page brought in plays from on the new page, or `null`\n * where the Video element cannot play it: a link to a video host whose\n * player the element frames (`hosted`), else the file the old site serves at\n * an https address, which the new page plays from that address. A video on\n * any other host is shown as its poster, linking to it.\n */\nexport function siteImportFilmSource(video: Pick<SiteImportVideo, 'src' | 'embed'> | null | undefined): { src: string; hosted: boolean } | null {\n if (!video) return null\n const embed = video.embed?.trim()\n if (embed && videoEmbedOf(embed)) return { src: embed, hosted: true }\n const file = video.src?.trim()\n return file && /^https:\\/\\//i.test(file) ? { src: file, hosted: false } : null\n}\n\n/**\n * The films a page brought in plays from the old site's own address\n * (AGL-4140): the https file of each video its layout places where it sits or\n * in an item, which the Video element plays because its poster is in the\n * library. A film on a host's player, one behind a section's words (drawn as\n * its poster), and one with no poster the library holds play nothing from\n * the old site. The rule the compile places a film by (`filmPlaces`).\n */\nexport function aiSiteImportOwnFilms(\n read: Pick<AiSiteImportPageRead, 'videos' | 'layout' | 'blocks'> | null | undefined,\n photos: ReadonlyArray<{ from?: string }>,\n): string[] {\n const videos = read?.videos ?? []\n if (!videos.length || !read?.layout) return []\n const held = new Set(photos.flatMap((photo) => (photo.from ? [photo.from] : [])))\n const out: string[] = []\n const place = (video: number, poster: SiteImportLineRef | undefined) => {\n const source = siteImportFilmSource(videos[video])\n const block = poster === undefined ? undefined : read.blocks?.[poster]\n if (source && !source.hosted && block?.kind === 'image' && held.has(block.url) && !out.includes(source.src)) out.push(source.src)\n }\n const visit = (nodes: readonly SiteImportLayoutNode[]) => {\n for (const node of nodes) {\n if (node.kind === 'video') place(node.video, node.poster)\n else if (node.kind === 'row') for (const cell of node.cells) visit(cell.nodes)\n else if (node.kind === 'tabs') for (const tab of node.tabs) visit(tab.panel)\n else if (node.kind === 'group') for (const item of node.items) if (item.video !== undefined) place(item.video, item.image)\n }\n }\n for (const section of read.layout.sections) visit(section.nodes)\n return out\n}\n\n/**\n * The most hosts a site approves of one kind: `APPROVED_IMAGE_HOSTS_MAX` in\n * `security-origins.js`, the tenant policy's own ceiling, which a spec holds\n * this to.\n */\nexport const SITE_IMPORT_APPROVED_HOSTS_MAX = 50\n\n/**\n * A host as the Security tab keeps one and the tenant's policy reads it\n * (`normalizeApprovedImageHost` in `security-origins.js`, which a spec holds\n * this to): lowercase, a hostname with at least one dot and a letter-only\n * last label, an optional leading `*.`, and no scheme, path, port or\n * separator; `null` for anything else.\n */\nexport function siteImportApprovedHost(value: unknown): string | null {\n if (typeof value !== 'string') return null\n const host = value.trim().toLowerCase()\n if (!host || host.length > 253) return null\n if (/[\\s;,/\\\\?#@:]/.test(host)) return null\n const bare = host.startsWith('*.') ? host.slice(2) : host\n if (!bare || bare === '*') return null\n return /^(?=.{1,253}$)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z]{2,63}$/.test(bare) ? host : null\n}\n\n/**\n * A site's approved media hosts with the old site's film hosts added\n * (AGL-4140): every entry the owner has kept as it is and where it is, each\n * new host once, after them, within `SITE_IMPORT_APPROVED_HOSTS_MAX`; `null`\n * when nothing is added.\n */\nexport function siteImportApprovedHostsWith(current: unknown, addresses: readonly string[]): string[] | null {\n const owner = Array.isArray(current) ? current.filter((entry): entry is string => typeof entry === 'string') : []\n const have = new Set(owner.map((entry) => entry.trim().toLowerCase()))\n const out = [...owner]\n const hostnameOf = (address: string): string | null => {\n try {\n return new URL(address).hostname\n } catch {\n return null\n }\n }\n for (const address of addresses) {\n const host = siteImportApprovedHost(hostnameOf(address))\n if (!host || have.has(host) || out.length >= SITE_IMPORT_APPROVED_HOSTS_MAX) continue\n have.add(host)\n out.push(host)\n }\n return out.length > owner.length ? out : null\n}\n\n/**\n * What a page's row says of its videos (AGL-4140), or `null`: a film the old\n * site serves itself plays from there, the owner may move it, and its address\n * was approved for the site to play (`approved`, once the host write is in);\n * a film the source showed no poster for is left out, since its poster is the\n * button a visitor presses, and the owner may add it with one.\n */\nexport function aiSiteImportVideoNote(\n videos: readonly SiteImportVideo[] | null | undefined,\n own: { films: number; approved: boolean } = { films: 0, approved: false },\n): string | null {\n const posterless = (videos ?? []).filter((video) => siteImportFilmSource(video) && !video.poster).length\n const approved = own.approved ? ' Its address was added to Approved media hosts in Admin → Security, so it plays on your new site.' : ''\n const notes = [\n own.films === 1 ? `A video on this page plays from your old site's address; pick it from your media library to move it.${approved}` : '',\n own.films > 1 ? `Videos on this page play from your old site's address; pick each from your media library to move it.${approved ? ' Their addresses were added to Approved media hosts in Admin → Security, so they play on your new site.' : ''}` : '',\n posterless === 1 ? 'A video on this page had no poster picture, so it was left out: add it with the Video element and pick a poster for it.' : '',\n posterless > 1 ? 'Videos on this page had no poster picture, so they were left out: add each with the Video element and pick a poster for it.' : '',\n ].filter(Boolean)\n return notes.length ? notes.join(' ') : null\n}\n\n/** A layout with its icons' drawings dropped, for a page that must be lighter. */\nexport function siteImportLayoutWithoutDrawings(layout: SiteImportLayout): SiteImportLayout {\n return { ...layout, icons: layout.icons.map((icon) => (icon.svg ? { viewBox: icon.viewBox } : icon)) }\n}\n\n/** What a wave's read found on one page, for its model answer. Never on the wire. */\nexport interface AiSiteImportPageRead {\n /** What the page holds that a visitor cannot see (AGL-4152): the addresses of its pictures, and its words. A build is held to not drawing them. */\n concealed?: { pictures: string[]; words: string[] }\n at: string\n title: string\n /** The page's text in order, cut to `AI_SITE_IMPORT_PAGE_TEXT_MAX_CHARS`; fenced only when a prompt reads it. */\n text: string\n /** The page's sections, from its headings. */\n sections: string[]\n /** Its photos' addresses, at most `AI_SITE_IMPORT_IMAGES_PER_PAGE`. */\n images: Array<{ url: string; alt: string }>\n /**\n * Every block of the page's main region, in order (AGL-4083): its words as\n * written, its headings, lists, links and pictures, within\n * `AI_SITE_IMPORT_READ_MAX_BLOCKS` and `AI_SITE_IMPORT_READ_MAX_CHARS`.\n * Untrusted data: fenced wherever a prompt reads it. Emptied once the page\n * is in; absent on a read made before it was kept.\n */\n blocks?: SiteImportBlock[]\n /** Set when `blocks` had to stop short of the page, at its budget or the wave's. */\n cut?: boolean\n /** The words of the page's main region, as the old page has them. */\n words?: number\n /** The forms the page asks visitors to fill in, by their fields. */\n forms?: SiteImportForm[]\n /**\n * How the source lays the page out (AGL-4106): its sections, bands, rows,\n * groups, pictures, icons and buttons, over `blocks` by index. Absent on a\n * read made before the reader, or when it did not fit the wave's budget.\n */\n layout?: SiteImportLayout | null\n /**\n * The page's browser title and meta description as the source writes them\n * (AGL-4107), which the new page's listing keeps word for word. Absent on a\n * read made before they were kept.\n */\n meta?: { title: string; description: string }\n /**\n * The videos the page shows (AGL-4140), which its layout places by index:\n * where each plays from, its poster's address and what a search engine\n * reads of it. Untrusted data. Absent on a page that shows none, or a read\n * made before they were kept; emptied with `blocks` once the page is in.\n */\n videos?: SiteImportVideo[]\n}\n\n/** How a page is built from its old page, as the step chose: its words copied as they are, or arranged by Aglyn AI. */\nexport type AiSiteImportBuild = 'copied' | 'arranged'\n\n/**\n * How an import finishes the owner's site (AGL-4152): kept as it is with a\n * light polish, or improved. Absent on an older import, which is `keep`.\n */\nexport type AiSiteImportFinish = 'keep' | 'improve'\n\n/** The job input the finish is carried in from Bring my site. */\nexport const AI_SITE_IMPORT_FINISH_INPUT = 'finish'\n\n/** The job input carrying whether an improved site's wording is improved too (AGL-4152). */\nexport const AI_SITE_IMPORT_WORDING_INPUT = 'wording'\n\n/** Whether a page's words were kept as written or improved (AGL-4152). */\nexport type AiSiteImportWords = 'kept' | 'improved'\n\n/** How the owner asked the site to be finished, as one choice: the finish, and under `improve` whether its wording is improved too (AGL-4152). */\nexport interface AiSiteImportChoice {\n finish: AiSiteImportFinish\n /** Always `false` under `keep`: Keep my site never rewrites a word. */\n wording: boolean\n}\n\n/** What Bring my site preselects (AGL-4152): Improve it, with Also improve my wording on. */\nexport const AI_SITE_IMPORT_DEFAULT_CHOICE: Readonly<AiSiteImportChoice> = { finish: 'improve', wording: true }\n\n/**\n * The words a policy page's address or title carries (AGL-4152), each matched\n * as whole words, its plural too: a main page that names one keeps every word\n * even when its wave improves the wording of the rest.\n */\nexport const AI_SITE_IMPORT_LEGAL_SLUGS: readonly string[] = [\n 'privacy',\n 'terms',\n 'cookie',\n 'legal',\n 'refund',\n 'return',\n 'shipping-policy',\n 'disclaimer',\n 'accessibility',\n 'gdpr',\n 'imprint',\n 'impressum',\n]\n\nexport interface AiSiteImportPage {\n /** The item ledger slot: `p0`, `p1`, … */\n slot: string\n url: string\n path: string\n title: string\n group: string\n wave: number\n /** The id the page's draft is written under, minted with the inventory. */\n draftId: string\n /** The page's address on the new site. */\n slug: string\n words: number\n images: number\n /** Filled by the wave's read; the text is cleared once the page is in. */\n read?: AiSiteImportPageRead | null\n /** Set when the wave's read found the page cannot be brought in after all. */\n refused?: AiSiteImportLeftOutReason | null\n /** How the step builds the page (`aiSiteImportPageBuild`); absent until it chooses, and the page is priced as an AI page. */\n build?: AiSiteImportBuild | null\n /** What came through once the page is in: its words on the new page. */\n brought?: { words: number } | null\n /** Whether its words were kept or improved, stamped with its build at its wave's start (AGL-4152). */\n wording?: AiSiteImportWords | null\n /** Filled once the page's photos are in the library. */\n photos?: {\n brought: number\n /** Already in the library from an earlier page or import: the same file, never a second copy. */\n reused: number\n skipped: number\n assets: AiSiteImportPhoto[]\n } | null\n /** Each form of the read, by its index, and the saved form that takes its place, `null` where none does (AGL-4083). */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** What the page's row says of its forms. */\n formNote?: string | null\n /** Where the page came from under a generative Improve it (AGL-4152): the source's, or the plan's proposed page. Absent is the source's. */\n origin?: 'source' | 'proposed' | null\n /** The sections its redesign added (AGL-4152). */\n added?: AiSiteImportAddedSection[] | null\n /** Its pictures by where each came from (AGL-4152). */\n pictures?: AiSiteImportPagePictures | null\n /**\n * How its generative Improve it came out (AGL-4152): `redesigned` from its\n * answer, or `layout-kept` where the redesign did not pass and today's\n * compile drew it. Absent on every other page.\n */\n redesign?: AiSiteImportRedesign | null\n /**\n * Why its layout was kept, or the design lines its redesign was taken\n * missing, by internal code (AGL-4152): `improve-invented-fact`,\n * `improve-new-sections`, `refused`. For the job's record and the import's\n * report; its row reads in words, never these.\n */\n redesignMissed?: string[] | null\n}\n\n/** How a page's generative Improve it came out (AGL-4152). */\nexport type AiSiteImportRedesign = 'redesigned' | 'layout-kept'\n\n/** What a page's row says where its redesign did not pass (AGL-4152). */\nexport const AI_SITE_IMPORT_LAYOUT_KEPT = 'Layout kept: the redesign did not pass'\n\n/** What a proposed page's row says where it could not be written: it has no old page to keep, so it is left out. */\nexport const AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN = 'This new page was left out: it could not be written without inventing facts. Its credits are given back.'\n\n/**\n * A wave's place in its import: waiting to start, running, in and waiting for\n * the person's review, in, or `stopped` — the import was canceled before the\n * wave was in, while it ran or before it started (AGL-4107).\n */\nexport type AiSiteImportWaveStatus = 'waiting' | 'running' | 'review' | 'done' | 'stopped'\n\nexport interface AiSiteImportWave {\n index: number\n label: string\n /** The group the wave brings in; the first wave's is `main`. */\n group: string\n slots: string[]\n /** Whether the wave builds the site's header and footer first. */\n frame: boolean\n status: AiSiteImportWaveStatus\n startedAt: string | null\n finishedAt: string | null\n /** How the wave was built, stamped at its start (AGL-4152): the site's finish then. */\n finish?: AiSiteImportFinish | null\n /** Whether its improved pages' wording was improved too, stamped at its start (AGL-4152). */\n wording?: boolean | null\n /**\n * Whether it is a generative Improve it (AGL-4152):\n * `SITE_IMPORT_GENERATIVE_RELEASE_FLAG` was on for the organization when the\n * wave started, under Improve it. Its site is planned, and with new copy on\n * its improved pages are redesigned from a ledger. Absent, today's Improve it.\n */\n generative?: true\n /**\n * `SITE_IMPORT_VIDEO_POSTERS_RELEASE_FLAG` was on for the organization when\n * the wave started (AGL-4140): its pages place a YouTube film with no\n * poster the library holds, for the page to draw YouTube's own still in.\n */\n videoPosters?: true\n}\n\nexport interface AiSiteImportState {\n domain: string\n /** The site's name, as Create site was given it: the header's name. */\n siteName: string\n ownership: { method: string | null; provenAt: number | null; detail: string | null }\n readAt: string\n /** The plan's page count; `null` when it has none. */\n pageLimit: number | null\n /** Pages the site already had when its import read the old site. */\n existingPages: number\n /** Pages the crawl read. */\n found: number\n /** Why the crawl stopped short of the whole site, or `null` when it did not. */\n stoppedBy: string | null\n groups: AiSiteImportGroup[]\n pages: AiSiteImportPage[]\n waves: AiSiteImportWave[]\n /** At most `AI_SITE_IMPORT_LEFT_OUT_LISTED`, by address. */\n leftOut: AiSiteImportLeftOut[]\n /** Every page left out, by reason, listed or not. */\n leftOutCount: Partial<Record<AiSiteImportLeftOutReason, number>>\n /** The header and footer's draft id, built in the first wave; `null` when there are no main pages. */\n frame: { draftId: string } | null\n /**\n * \"Start every remaining wave\" (AGL-4083): each wave closes and the next\n * starts with no review between them; the last wave's close is the stop.\n * Off unless the person chose it.\n */\n autoContinue?: boolean\n /**\n * The wave \"Start every remaining wave\" was chosen at (AGL-4084): the one\n * start the person made, which the day's limit counts; the waves it starts\n * after it are the same start.\n */\n autoContinueFrom?: number | null\n /** What the read found of the site as a whole; a stopping verdict plans nothing. */\n verdict?: AiSiteImportReadVerdict | null\n /** What the home page says of the site as a whole (AGL-4084): its look, its header and footer, its listing. */\n home?: AiSiteImportHome | null\n /** The look pass, once it ran in the first wave (AGL-4084). */\n look?: AiSiteImportLook | null\n /** How the owner asked the site to be finished (AGL-4152); absent reads as `keep`. Changeable before each wave. */\n finish?: AiSiteImportFinish | null\n /** Under `improve`, whether the main pages' wording is improved too (AGL-4152): on unless the owner turns it off. */\n wording?: boolean | null\n /**\n * The one site plan a generative Improve it draws from (AGL-4152), written\n * once after the first wave's read. Absent until that step exists, and on\n * every import that is not generative; a page's design then comes from the\n * import's own inputs (`aiSiteImportDesignInputs`). `null` is a plan asked\n * for that did not pass: the import's frame and design inputs stand, and its\n * page says so.\n */\n plan?: AiSiteImportPlan | null\n /** The owner saw the plan and started the build (AGL-4152): its proposed page is settled, in or out. */\n planAccepted?: true\n /** Whether a slot nothing else fills may take a generated picture (AGL-4152); absent is `AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT`. */\n generatedPictures?: boolean | null\n /**\n * `SITE_IMPORT_GENERATIVE_RELEASE_FLAG` was on for the organization when the\n * site was read (AGL-4152): what its page says and quotes before a wave\n * starts. A wave's own stamp decides how it is built.\n */\n generative?: true\n /** The source's photos a redesigned page left off (AGL-4152), which a later page's slot takes before a stock photo. */\n sitePhotos?: AiSiteImportPhoto[] | null\n /**\n * What the site's pages say, as a generative wave read them (AGL-4152):\n * each line once, in reading order, up to `AI_SITE_IMPORT_SAID_MAX_CHARS`.\n * A page's read is emptied once it is in, so without these a later page's\n * redesign was held as if no earlier page had said anything: the home\n * page's towns, years and credentials read as invented on the next.\n * Kept past each page, and written only by a generative wave.\n */\n said?: string[] | null\n}\n\n/** The most characters of what the site's pages say an import keeps for its redesigns' facts (AGL-4152). */\nexport const AI_SITE_IMPORT_SAID_MAX_CHARS = 16_000\n\n/** What the site's pages say, with these reads' lines added where there is room (AGL-4152). */\nexport function aiSiteImportSaid(said: readonly string[] | null | undefined, reads: Iterable<AiSiteImportPageRead | AiSiteImportLeftOutReason>): string[] {\n const out = [...(said ?? [])]\n const seen = new Set(out)\n let chars = out.reduce((sum, line) => sum + line.length, 0)\n for (const read of reads) {\n if (typeof read === 'string') continue\n for (const block of read.blocks ?? []) {\n if (block.kind === 'image') continue\n const line = block.text.replace(/\\s+/g, ' ').trim()\n if (!line || seen.has(line) || chars + line.length > AI_SITE_IMPORT_SAID_MAX_CHARS) continue\n seen.add(line)\n out.push(line)\n chars += line.length\n }\n }\n return out\n}\n\n/**\n * The site plan (AGL-4152): what the site is, its menu, its design, and at\n * most one proposed page. Page references are draft ids. Its words are the\n * site's own data, fenced wherever a prompt reads them.\n */\nexport interface AiSiteImportPlan {\n site: { what: string; audience: string; kind: string; voice: string }\n nav: {\n groups: Array<{ label: string; pages: string[] }>\n /**\n * The header's filled call to action: `target` is a page's draft id, `form`\n * or `phone`; `page` is the page a `form` target sends a visitor to, read\n * when the plan was checked, since a settled page keeps no form.\n */\n primaryCta: { label: string; target: string; page?: string } | null\n footer: Array<{ label: string; pages: string[] }>\n }\n /** One for the site, so every page of every wave is drawn alike. */\n design: AiSiteImportPlanDesign\n /** At most one new page, on by default, with a switch (`AiSiteImportPage.origin`). `draftId` names its page once the plan is in. */\n proposed: { title: string; slug: string; purpose: string; on: boolean; draftId?: string } | null\n /**\n * What each page is for in the new site, by its draft id (AGL-4152): what\n * its redesign plans it as, and how many new sections it has room for. A\n * plan made before roles reads each page's from its address and what it holds.\n */\n roles?: Record<string, AiSiteImportPageRole>\n}\n\n/** What a page is for in a planned site (AGL-4152): what its redesign plans it as. */\nexport type AiSiteImportPageRole = 'home' | 'service' | 'about' | 'contact' | 'gallery' | 'pricing' | 'faq' | 'other'\n\nexport const AI_SITE_IMPORT_PAGE_ROLES: readonly AiSiteImportPageRole[] = ['home', 'service', 'about', 'contact', 'gallery', 'pricing', 'faq', 'other']\n\n/** How a plan draws the site: the hero, each group, the bands' rhythm and the closing call to action. */\nexport interface AiSiteImportPlanDesign {\n hero: 'cover' | 'poster' | 'split' | 'bleed' | 'editorial' | 'column' | 'panel'\n group: 'cards' | 'ruled' | 'icons'\n rhythm: 'alternate' | 'plain'\n /** A closing call to action on a strong band, or over a photo. */\n cta: 'band' | 'photo'\n}\n\n/** The owner's answer to the plan's review (AGL-4152): the proposed page, and generated pictures. */\nexport interface AiSiteImportPlanChoice {\n addPage?: boolean\n pictures?: boolean\n}\n\n/**\n * Whether generated pictures are on where the owner has not said (AGL-4152):\n * on, with a switch. A picture costs credits, so a wave that may take them\n * quotes them in its ceiling before it starts, and the switch turns them off.\n */\nexport const AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT = true\n\n/** What a plan's row and panel say where it did not pass (AGL-4152). */\nexport const AI_SITE_IMPORT_PLAN_FELL_BACK = 'Your menu and footer stay as your site has them: the plan for your new site did not pass.'\n\n/** The ledger slot of the plan's proposed page. */\nexport const AI_SITE_IMPORT_PROPOSED_SLOT = 'proposed'\n\n/** What a plan's answer calls its proposed page before it has an id. */\nexport const AI_SITE_IMPORT_PROPOSED_PAGE = 'new'\n\n/** The most generated pictures one page takes (AGL-4152), a hero or a section's lead only. */\nexport const AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE = 2\n\n/** What the plan's own pass may spend at most: its answer and its one re-ask at the measured p90. */\nexport const AI_SITE_IMPORT_PLAN_CEILING_CREDITS = 180\n\n/** A section a redesign added to a page (AGL-4152): what its row and What's new say. */\nexport interface AiSiteImportAddedSection {\n heading: string\n /** The items it holds, where it holds a group of them. */\n items?: number\n}\n\n/** What a redesigned page shows of its pictures (AGL-4152), by where each came from. */\nexport interface AiSiteImportPagePictures {\n /** The page's own and the site's source photos placed. */\n source: number\n /** Slots filled from the stock library. */\n stock: number\n /** Slots filled by a generated picture. */\n generated: number\n /** Slots with no picture yet, which a later pass fills or drops. */\n slots: number\n /** The source's photos left off the page, by address, listed for the owner. */\n unplaced: string[]\n}\n\n/**\n * What the home page says of the site as a whole (AGL-4084), kept from the\n * read: the site's listing in its own words, its header's brand as the\n * source draws it, and the words its header and footer carry. Untrusted\n * data from the owner's site, fenced wherever a prompt reads it.\n */\nexport interface AiSiteImportHome {\n url: string\n title: string\n description: string\n ogImage: string | null\n /** The site's icon its head names (AGL-4139): its largest touch icon, else its largest picture icon. Absent on a read made before. */\n favicon?: string | null\n siteName: string\n brand: {\n kind: 'logo-only' | 'logo-and-name' | 'name-only'\n /** The name as the header prints it, where it prints one. */\n text: string\n logo: { url: string; alt: string; type: 'svg' | 'raster' | null } | null\n }\n facts: {\n /** The header's and footer's lines, as written, in order. */\n lines: string[]\n emails: string[]\n phones: string[]\n social: string[]\n address: string\n }\n /**\n * The source's header menu as its home page builds it (AGL-4108): its\n * items, their menus, its buttons. The header and footer are drawn from it\n * with no model; absent on a read made before the reader, or where the home\n * page has no menu the reader can find.\n */\n nav?: SiteImportNavTree | null\n /** The source's footer as its home page builds it (AGL-4108): its columns, profiles, facts and © line. */\n footer?: SiteImportFooter | null\n /** What the source's look is made of (AGL-4108): its colors, its button fill and corners, its fonts. */\n look?: SiteImportLookFacts | null\n /**\n * The first picture its home page's main content shows that is not its logo\n * (AGL-4152): what a look with no color of its own, and a logo with none,\n * takes its brand from. Absent on a read made before, or with none.\n */\n hero?: { url: string; alt: string } | null\n}\n\n/**\n * Whether the site's header and footer are built from the source's own menu\n * (AGL-4108), with no model: the home page's menu was read. Then the frame\n * costs nothing and is quoted at nothing.\n */\nexport function aiSiteImportFrameIsRead(state: Pick<AiSiteImportState, 'home'> | null | undefined): boolean {\n const nav = state?.home?.nav\n return !!nav && (nav.items.length > 0 || nav.ctas.length > 0)\n}\n\n/** Where an imported look's brand came from (AGL-4152). */\nexport type AiSiteImportLookFrom = 'source' | 'logo' | 'photo' | 'seed'\n\n/** What the look pass did (AGL-4084): no model is asked. */\nexport interface AiSiteImportLook {\n at: string\n /**\n * The theme: drawn for the site (`applied`), or the owner's kept (`kept`).\n * `unread` is a pass from before AGL-4152, which left a source with no color\n * to read in the stock theme; a pass no longer does.\n */\n theme: 'applied' | 'kept' | 'unread'\n /**\n * Where the applied theme's brand came from (AGL-4152): what the source draws\n * or declares (`source`), its logo's colors (`logo`), its hero or share\n * picture's (`photo`), or, with none of those, the seed's draw for the kind of\n * site (`seed`). Absent on a pass from before.\n */\n from?: AiSiteImportLookFrom\n /** The source's colors it was drawn from, the strongest first. */\n colors: string[]\n /** The source's logo, as the library holds it, for the header's brand. */\n logo: AiSiteImportPhoto | null\n /** The pictures the home page's menus show (AGL-4139), as the library holds them, each by the address it came `from`. */\n pictures?: AiSiteImportPhoto[]\n /** Whether the site's listing was taken from the home page's own words. */\n seo: boolean\n /** The look's seed, which every page of the import is drawn with. */\n seed: number | null\n /** The look's header arrangement, band rhythm and motion, which the header, the footer and every page are drawn in. */\n style?: { headerAlign?: string; rhythm?: string; motion?: string } | null\n /**\n * Under a generative Improve it (AGL-4152), the colors the theme drew, which\n * a redesign is held to as it is asked (`SiteImportFidelityTheme`). Absent\n * on every other import, and where the owner's own theme was kept.\n */\n drawn?: Record<string, unknown> | null\n}\n\n/*------------------------------------------\n * The read's verdict: Home first (AGL-4083)\n *-----------------------------------------*/\n\n/**\n * - `home-blocked`: bot protection or a firewall turned AglynBot away from\n * the home page (401, 403 or 429).\n * - `home-unreadable`: the home page could not be read for any other reason,\n * or read as an empty shell (a site that needs a browser to show its words).\n * - `mostly-blocked`: the home page came in, but more than half the site's\n * addresses were turned away; the import goes on, and says so.\n * - `ok`: anything else.\n */\nexport type AiSiteImportReadVerdictKind = 'ok' | 'home-blocked' | 'home-unreadable' | 'mostly-blocked'\n\n/** Why the home page did not come in. */\nexport type AiSiteImportHomeProblem =\n | 'blocked'\n | 'http-error'\n | 'unreachable'\n | 'not-html'\n | 'too-large'\n | 'off-site'\n | 'robots'\n | 'login-form'\n | 'not-reached'\n | 'empty'\n\nexport interface AiSiteImportReadVerdict {\n kind: AiSiteImportReadVerdictKind\n /** Addresses turned away by bot protection or a firewall, the home page among them. */\n blocked: number\n /** The site's addresses the read knew of: the sitemaps', or everything it asked for. */\n total: number\n /** What the home page answered, when it answered with an error. */\n homeStatus: number | null\n homeProblem: AiSiteImportHomeProblem | null\n /** Whose edge turned the home page away, when it said. */\n edge: 'vercel' | 'cloudflare' | null\n}\n\n/** A crawl as the verdict reads it; the crawler's `SiteImportInventory` is one. */\nexport interface AiSiteImportReadInput {\n pages: ReadonlyArray<{\n path: string\n foundBy: string\n blocks: ReadonlyArray<{ kind: string; text?: string; inline?: boolean }>\n images: readonly unknown[]\n }>\n skipped: ReadonlyArray<{ url: string; reason: string; status?: number; edge?: string | null }>\n sitemapUrls: number\n}\n\nconst pathOfUrl = (url: string): string => {\n try {\n return new URL(url).pathname.replace(/\\/+$/, '') || '/'\n } catch {\n return ''\n }\n}\n\nconst wordsOf = (text: string) => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** How much of a site was turned away counts its pages: never another address of one, or its platform's screen. */\nconst isOneOfTheSitesPages = (entry: { reason: string }) => entry.reason !== 'duplicate' && entry.reason !== 'system-page'\n\n/** One verdict from what became of the home page and how much of the site was turned away. */\nfunction readVerdictOf(\n home: { problem: AiSiteImportHomeProblem; status: number | null; edge: string | null } | null,\n blocked: number,\n total: number,\n): AiSiteImportReadVerdict {\n const edge: AiSiteImportReadVerdict['edge'] = home?.edge === 'vercel' ? 'vercel' : home?.edge === 'cloudflare' ? 'cloudflare' : null\n const base = { blocked, total, homeStatus: home?.status ?? null, homeProblem: home?.problem ?? null, edge }\n if (home) return { kind: home.problem === 'blocked' ? 'home-blocked' : 'home-unreadable', ...base }\n return { kind: total > 0 && blocked * 2 > total ? 'mostly-blocked' : 'ok', ...base }\n}\n\n/** What a crawler skip of the home page means for it. */\nfunction homeProblemOfSkip(reason: string, status: number | undefined): AiSiteImportHomeProblem {\n switch (reason) {\n case 'http-error':\n return status !== undefined && AI_SITE_IMPORT_BLOCKED_STATUSES.has(status) ? 'blocked' : 'http-error'\n case 'off-origin-redirect':\n return 'off-site'\n case 'not-html':\n case 'too-large':\n case 'robots':\n case 'login-form':\n case 'not-reached':\n return reason\n default:\n return 'unreachable'\n }\n}\n\n/**\n * The read's verdict (AGL-4083), pure over the crawl: whether the home page\n * came in, and how much of the site bot protection turned away. An import\n * whose verdict stops (`aiSiteImportReadStops`) plans no wave, quotes\n * nothing and spends nothing: the person is told why and checks again.\n */\nexport function aiSiteImportReadVerdict(crawled: AiSiteImportReadInput): AiSiteImportReadVerdict {\n const blocked = crawled.skipped.filter(\n (entry) => entry.reason === 'http-error' && entry.status !== undefined && AI_SITE_IMPORT_BLOCKED_STATUSES.has(entry.status),\n ).length\n const total = Math.max(crawled.sitemapUrls, crawled.pages.length + crawled.skipped.filter(isOneOfTheSitesPages).length)\n const page = crawled.pages.find((entry) => entry.foundBy === 'home') ?? crawled.pages.find((entry) => (entry.path.replace(/\\/+$/, '') || '/') === '/')\n if (page) {\n const words = page.blocks.reduce((sum, block) => sum + (block.kind === 'image' || block.inline ? 0 : wordsOf(block.text ?? '')), 0)\n const empty = words < AI_SITE_IMPORT_MIN_WORDS && page.images.length === 0\n return readVerdictOf(empty ? { problem: 'empty', status: null, edge: null } : null, blocked, total)\n }\n const skip = crawled.skipped.find((entry) => pathOfUrl(entry.url) === '/')\n return readVerdictOf(\n skip\n ? { problem: homeProblemOfSkip(skip.reason, skip.status), status: skip.status ?? null, edge: skip.edge ?? null }\n : { problem: 'not-reached', status: null, edge: null },\n blocked,\n total,\n )\n}\n\n/** Whether a verdict stops the import before anything is planned: its home page is not in. */\nexport function aiSiteImportReadStops(verdict: AiSiteImportReadVerdict | null | undefined): boolean {\n return verdict?.kind === 'home-blocked' || verdict?.kind === 'home-unreadable'\n}\n\n/** The review an import that stopped at its read waits under: `blocked` or `unreadable`; `null` when it goes on. */\nexport function aiSiteImportReadVerdictReason(verdict: AiSiteImportReadVerdict | null | undefined): 'blocked' | 'unreadable' | null {\n if (verdict?.kind === 'home-blocked') return 'blocked'\n if (verdict?.kind === 'home-unreadable') return 'unreadable'\n return null\n}\n\n/** Where a site owner lets AglynBot through, on the edges that name themselves. */\nexport const AI_SITE_IMPORT_EDGE_HINTS: Readonly<Record<'vercel' | 'cloudflare', string>> = {\n vercel: 'Your site answers through Vercel: in its Firewall, under Rules, add a bypass rule for the user agent AglynBot.',\n cloudflare:\n 'Your site answers through Cloudflare: under Security, WAF, add a custom rule that skips the checks when the user agent contains AglynBot.',\n}\n\nconst NOTHING_SPENT = 'Nothing was brought in and no AI credits were used.'\n\n/** Why the home page could not be read, inside the sentence that says so. */\nfunction homeProblemText(verdict: AiSiteImportReadVerdict): string {\n switch (verdict.homeProblem) {\n case 'http-error':\n return verdict.homeStatus ? `it answered with an error, ${verdict.homeStatus}` : 'it answered with an error'\n case 'not-html':\n return 'it did not answer with a web page'\n case 'too-large':\n return 'it is larger than a page can be to bring in'\n case 'off-site':\n return 'it sends visitors to another website'\n case 'not-reached':\n return 'the read ran out of time before it'\n default:\n return 'it did not answer'\n }\n}\n\n/**\n * What the person is told about the read (AGL-4083), in console words: why\n * nothing was brought in and what to do, or that most of the site was turned\n * away. `null` when there is nothing to say.\n */\nexport function aiSiteImportReadVerdictMessage(verdict: AiSiteImportReadVerdict | null | undefined, domain: string): string | null {\n if (!verdict) return null\n if (verdict.kind === 'home-blocked') {\n const others = Math.max(0, verdict.blocked - 1)\n const more = others ? `, and ${others.toLocaleString('en-US')} other ${others === 1 ? 'page' : 'pages'}` : ''\n const lead = `Your site’s bot protection or firewall turned AglynBot away before it could read your home page${more}. ${NOTHING_SPENT} Allow AglynBot in your site’s bot or firewall settings, then choose Check again.`\n return verdict.edge ? `${lead} ${AI_SITE_IMPORT_EDGE_HINTS[verdict.edge]}` : lead\n }\n if (verdict.kind === 'home-unreadable') {\n switch (verdict.homeProblem) {\n case 'robots':\n return `Your site’s robots.txt asks AglynBot not to read your home page. ${NOTHING_SPENT} Allow AglynBot in your robots.txt, then choose Check again.`\n case 'login-form':\n return `Your home page asks for a password, and pages that do are never brought in. ${NOTHING_SPENT} Open your home page to visitors, then choose Check again.`\n case 'empty':\n return `No text could be read from your home page. If your site is built in a way that needs a browser to show its words, it cannot be brought in yet. ${NOTHING_SPENT}`\n default:\n return `Your home page could not be read (${homeProblemText(verdict)}). ${NOTHING_SPENT} Check that ${domain} is up and answers at https://${domain}/, then choose Check again.`\n }\n }\n if (verdict.kind === 'mostly-blocked') {\n return `${verdict.blocked.toLocaleString('en-US')} of ${verdict.total.toLocaleString('en-US')} pages were turned away by your site’s bot protection; see Not brought in.`\n }\n return null\n}\n\n/** The verdict an inventory reads from its own pages and skips, when the step did not hand it the crawl's. */\nfunction inventoryVerdict(input: Pick<AiSiteImportInventoryInput, 'pages' | 'skipped' | 'skippedOverflow'>): AiSiteImportReadVerdict {\n const blocked = input.skipped.filter((entry) => entry.reason === 'blocked').length\n const total = input.pages.length + input.skipped.filter(isOneOfTheSitesPages).length + Math.max(0, input.skippedOverflow ?? 0)\n const page = input.pages.find((entry) => entry.foundBy === 'home') ?? input.pages.find((entry) => (entry.path.replace(/\\/+$/, '') || '/') === '/')\n if (page) {\n const empty = page.words < AI_SITE_IMPORT_MIN_WORDS && page.images === 0\n return readVerdictOf(empty ? { problem: 'empty', status: null, edge: null } : null, blocked, total)\n }\n const skip = input.skipped.find((entry) => pathOfUrl(entry.url) === '/')\n const problem: AiSiteImportHomeProblem = !skip\n ? 'not-reached'\n : skip.reason === 'blocked'\n ? 'blocked'\n : skip.reason === 'robots' || skip.reason === 'login-form' || skip.reason === 'too-large' || skip.reason === 'off-site' || skip.reason === 'not-reached' || skip.reason === 'empty'\n ? skip.reason\n : 'unreachable'\n return readVerdictOf({ problem, status: null, edge: null }, blocked, total)\n}\n\n/*------------------------------------------\n * Grouping and waves\n *-----------------------------------------*/\n\nconst clipLabel = (text: string) => {\n const line = String(text ?? '').replace(/\\s+/g, ' ').trim()\n return line.length > AI_SITE_IMPORT_LABEL_MAX_CHARS\n ? `${line.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 1).trimEnd()}…`\n : line\n}\n\nconst segmentsOf = (path: string) => String(path ?? '').split('/').filter(Boolean)\n\n/** A collection's prefix for a page address: its first segment, a dated archive's `posts`; `null` for a top-level page. */\nexport function aiSiteImportPrefix(path: string): string | null {\n const segments = segmentsOf(path)\n if (segments.length < 2) return null\n const first = segments[0].toLowerCase()\n return /^\\d{4}$/.test(first) ? 'posts' : first\n}\n\n/** \"news-and-events\" → \"News and events\". */\nexport function aiSiteImportPrefixLabel(prefix: string): string {\n const words = decodeURIComponent(prefix).replace(/[-_+]+/g, ' ').trim()\n return words ? `${words.charAt(0).toUpperCase()}${words.slice(1)}` : 'Pages'\n}\n\n/**\n * The inventory's groups, in the order they are brought in: the main pages,\n * then each collection — one the home page's menu links first, in menu order,\n * then the larger before the smaller.\n */\nexport function aiSiteImportGroups(\n pages: readonly AiSiteImportListedPage[],\n menu: readonly string[] = [],\n): { groups: AiSiteImportGroup[]; groupOf: (page: AiSiteImportListedPage) => string } {\n const counts = new Map<string, number>()\n for (const page of pages) {\n const prefix = aiSiteImportPrefix(page.path)\n if (prefix) counts.set(prefix, (counts.get(prefix) ?? 0) + 1)\n }\n const menuPaths = new Set(menu.map((path) => path.replace(/\\/+$/, '') || '/'))\n const collections = new Set([...counts].filter(([, count]) => count >= AI_SITE_IMPORT_COLLECTION_MIN).map(([prefix]) => prefix))\n const groupOf = (page: AiSiteImportListedPage) => {\n const path = page.path.replace(/\\/+$/, '') || '/'\n if (page.foundBy === 'home' || menuPaths.has(path)) return 'main'\n const prefix = aiSiteImportPrefix(page.path)\n return prefix && collections.has(prefix) ? `c:${prefix}` : 'main'\n }\n const menuRank = (prefix: string) => {\n const index = menu.findIndex((path) => {\n const first = segmentsOf(path)[0]?.toLowerCase()\n return first === prefix\n })\n return index === -1 ? Number.POSITIVE_INFINITY : index\n }\n const sized = new Map<string, number>()\n for (const page of pages) sized.set(groupOf(page), (sized.get(groupOf(page)) ?? 0) + 1)\n const ordered = [...collections]\n .filter((prefix) => (sized.get(`c:${prefix}`) ?? 0) > 0)\n .sort((a, b) => menuRank(a) - menuRank(b) || (sized.get(`c:${b}`) ?? 0) - (sized.get(`c:${a}`) ?? 0) || a.localeCompare(b))\n const groups: AiSiteImportGroup[] = []\n if ((sized.get('main') ?? 0) > 0) groups.push({ id: 'main', label: 'Main pages', kind: 'main', pages: sized.get('main') ?? 0 })\n for (const prefix of ordered) {\n groups.push({ id: `c:${prefix}`, label: aiSiteImportPrefixLabel(prefix), kind: 'collection', pages: sized.get(`c:${prefix}`) ?? 0 })\n }\n return { groups, groupOf }\n}\n\n/**\n * The main pages in the order a visitor meets them: home, then the menu's\n * order, then the rest as the crawl read them. A collection keeps the crawl's\n * order, which is its sitemap's.\n */\nfunction orderedWithin(\n group: string,\n pages: readonly AiSiteImportListedPage[],\n menu: readonly string[],\n): AiSiteImportListedPage[] {\n if (group !== 'main') return [...pages]\n const rank = (page: AiSiteImportListedPage) => {\n if (page.foundBy === 'home' || segmentsOf(page.path).length === 0) return -1\n const path = page.path.replace(/\\/+$/, '') || '/'\n const index = menu.findIndex((entry) => (entry.replace(/\\/+$/, '') || '/') === path)\n return index === -1 ? Number.POSITIVE_INFINITY : index\n }\n return pages\n .map((page, order) => ({ page, order }))\n .sort((a, b) => rank(a.page) - rank(b.page) || a.order - b.order)\n .map(({ page }) => page)\n}\n\n/**\n * The address a page takes on the new site: one segment, as every Aglyn page\n * has, from the last segment of its old address; home is the root. Two pages\n * that would take the same address are told apart by their collection, then\n * by a number. The draft writer still makes it unique on the site itself.\n */\nexport function aiSiteImportSlug(path: string, taken: Set<string>): string {\n const segments = segmentsOf(path)\n if (!segments.length) {\n if (!taken.has('/')) {\n taken.add('/')\n return '/'\n }\n }\n const clean = (value: string) =>\n decodeURIComponent(value)\n .toLowerCase()\n .replace(/\\.(?:html?|php|aspx?)$/, '')\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n const last = clean(segments[segments.length - 1] ?? '') || 'page'\n const prefixed = segments.length > 1 ? clean(`${segments[0]}-${segments[segments.length - 1]}`) : last\n for (const candidate of [last, prefixed]) {\n if (candidate && !taken.has(candidate)) {\n taken.add(candidate)\n return candidate\n }\n }\n let attempt = 2\n while (taken.has(`${last}-${attempt}`)) attempt += 1\n const slug = `${last}-${attempt}`\n taken.add(slug)\n return slug\n}\n\nexport interface AiSiteImportInventoryInput {\n domain: string\n siteName: string\n ownership: AiSiteImportState['ownership']\n readAt: string\n pages: readonly AiSiteImportListedPage[]\n /** Addresses the home page's menu links, in its order. */\n menu: readonly string[]\n /** What the crawl could not read, by reason. */\n skipped: ReadonlyArray<{ url: string; reason: AiSiteImportLeftOutReason; sameAs?: string }>\n /** Skips the crawl only counted. */\n skippedOverflow?: number\n stoppedBy: string | null\n /**\n * The read's verdict from the crawl itself (`aiSiteImportReadVerdict`), with\n * the status and edge the home page answered with; read from `pages` and\n * `skipped` when absent.\n */\n verdict?: AiSiteImportReadVerdict | null\n /** The plan's page count; `null` for none. */\n pageLimit: number | null\n existingPages: number\n /** Mints one draft id; the inventory names every page's draft before any is written. */\n mintId: () => string\n wavePages?: number\n}\n\n/**\n * The site's inventory cut into waves, every page left out said with its\n * reason. Pure: the step reads the site, this decides what comes in.\n */\nexport function aiSiteImportInventory(input: AiSiteImportInventoryInput): AiSiteImportState {\n const wavePages = Math.max(1, Math.floor(input.wavePages ?? AI_SITE_IMPORT_WAVE_PAGES))\n const limit = input.pageLimit === null || !Number.isFinite(input.pageLimit) ? null : Math.max(0, Math.floor(input.pageLimit))\n const leftOut: AiSiteImportLeftOut[] = []\n const leftOutCount: Partial<Record<AiSiteImportLeftOutReason, number>> = {}\n const leave = (entry: AiSiteImportLeftOut) => {\n leftOutCount[entry.reason] = (leftOutCount[entry.reason] ?? 0) + 1\n if (leftOut.length < AI_SITE_IMPORT_LEFT_OUT_LISTED) leftOut.push(entry)\n }\n // The read asks for a wave's worth past the plan's room, so a page its page\n // budget never reached is past the plan; any other stop is not the plan's.\n const unreached: AiSiteImportLeftOutReason = input.stoppedBy === 'page-budget' && limit !== null ? 'plan-limit' : 'not-reached'\n for (const skipped of input.skipped) {\n let path = '/'\n let sameAs: string | null = null\n try {\n const url = new URL(skipped.url)\n // Its query too: forty addresses of one path are told apart by it.\n path = `${url.pathname}${url.search}`\n if (skipped.sameAs) sameAs = new URL(skipped.sameAs).pathname\n } catch {\n // A malformed address keeps the root as its path.\n }\n leave({ url: skipped.url, path, title: '', reason: skipped.reason === 'not-reached' ? unreached : skipped.reason, ...(sameAs ? { sameAs } : {}) })\n }\n if (input.skippedOverflow) leftOutCount['unreadable'] = (leftOutCount['unreadable'] ?? 0) + input.skippedOverflow\n\n // Home first: a site read without its home page plans nothing at all.\n const verdict = input.verdict ?? inventoryVerdict(input)\n if (aiSiteImportReadStops(verdict)) {\n return {\n domain: input.domain,\n siteName: clipLabel(input.siteName) || input.domain,\n ownership: input.ownership,\n readAt: input.readAt,\n pageLimit: limit,\n existingPages: Math.max(0, input.existingPages),\n found: input.pages.length,\n stoppedBy: input.stoppedBy,\n groups: [],\n pages: [],\n waves: [],\n leftOut,\n leftOutCount,\n frame: null,\n verdict,\n }\n }\n\n const readable = input.pages.filter((page) => {\n if (page.words >= AI_SITE_IMPORT_MIN_WORDS || page.images > 0) return true\n leave({ url: page.url, path: page.path, title: clipLabel(page.title), reason: 'empty' })\n return false\n })\n const { groups, groupOf } = aiSiteImportGroups(readable, input.menu)\n let room = limit === null ? Number.POSITIVE_INFINITY : Math.max(0, limit - Math.max(0, input.existingPages))\n const pages: AiSiteImportPage[] = []\n const waves: AiSiteImportWave[] = []\n const taken = new Set<string>()\n for (const group of groups) {\n const members = orderedWithin(group.id, readable.filter((page) => groupOf(page) === group.id), input.menu)\n const kept: AiSiteImportListedPage[] = []\n for (const page of members) {\n if (room > 0) {\n kept.push(page)\n room -= 1\n } else {\n leave({ url: page.url, path: page.path, title: clipLabel(page.title), reason: 'plan-limit' })\n }\n }\n const parts = Math.ceil(kept.length / wavePages)\n for (let part = 0; part < parts; part += 1) {\n const index = waves.length\n const slice = kept.slice(part * wavePages, (part + 1) * wavePages)\n const slots: string[] = []\n for (const page of slice) {\n const slot = `p${pages.length}`\n slots.push(slot)\n pages.push({\n slot,\n url: page.url,\n path: page.path,\n title: clipLabel(page.title) || aiSiteImportPrefixLabel(segmentsOf(page.path).pop() ?? 'Home'),\n group: group.id,\n wave: index,\n draftId: input.mintId(),\n slug: aiSiteImportSlug(page.path, taken),\n words: page.words,\n images: page.images,\n })\n }\n waves.push({\n index,\n label: parts > 1 ? `${group.label}, ${part + 1} of ${parts}` : group.label,\n group: group.id,\n slots,\n frame: index === 0 && group.kind === 'main',\n status: 'waiting',\n startedAt: null,\n finishedAt: null,\n })\n }\n }\n return {\n domain: input.domain,\n siteName: clipLabel(input.siteName) || input.domain,\n ownership: input.ownership,\n readAt: input.readAt,\n pageLimit: limit,\n existingPages: Math.max(0, input.existingPages),\n found: input.pages.length,\n stoppedBy: input.stoppedBy,\n groups,\n pages,\n waves,\n leftOut,\n leftOutCount,\n frame: waves[0]?.frame ? { draftId: input.mintId() } : null,\n verdict,\n }\n}\n\n/** The item ledger an inventory starts: the header and footer, then every page, all pending. */\nexport function aiSiteImportLedger(state: AiSiteImportState): AiJobItemLedger[] {\n const row = (slot: string, op: string, label: string): AiJobItemLedger => ({\n slot,\n op,\n label,\n status: 'pending',\n attempt: 1,\n creditsSpent: 0,\n creditsRefunded: 0,\n outputs: [],\n })\n return [\n ...(state.frame ? [row(AI_SITE_IMPORT_FRAME_SLOT, 'layout', 'Header and footer')] : []),\n ...state.pages.map((page) => row(page.slot, 'page', page.title)),\n ]\n}\n\n/*------------------------------------------\n * What runs next\n *-----------------------------------------*/\n\nexport type AiSiteImportWork =\n | { kind: 'inventory' }\n | { kind: 'start-wave'; wave: AiSiteImportWave }\n /** Pages of the running wave its read did not reach before its clock ran out. */\n | { kind: 'read'; wave: AiSiteImportWave; pages: AiSiteImportPage[] }\n /** The site's plan (AGL-4152), once, after the first wave's read and before its look. */\n | { kind: 'plan'; wave: AiSiteImportWave }\n /** The owner started the build under a plan they saw: its proposed page settled, no model. */\n | { kind: 'plan-accepted'; wave: AiSiteImportWave }\n | { kind: 'frame'; wave: AiSiteImportWave }\n | { kind: 'images'; wave: AiSiteImportWave; page: AiSiteImportPage }\n /** A page's forms, rebuilt as the site's own before the page places them (AGL-4083). */\n | { kind: 'forms'; wave: AiSiteImportWave; page: AiSiteImportPage }\n | { kind: 'page'; wave: AiSiteImportWave; page: AiSiteImportPage }\n | { kind: 'close-wave'; wave: AiSiteImportWave }\n | { kind: 'done' }\n\nconst OPEN = new Set(['pending', 'running'])\n\n/** Whether an item is still to be built. */\nexport function aiSiteImportItemOpen(items: readonly AiJobItemLedger[] | null | undefined, slot: string): boolean {\n const row = (items ?? []).find((entry) => entry.slot === slot)\n return Boolean(row && OPEN.has(row.status))\n}\n\n/** The wave running now, else `null`. */\nexport function aiSiteImportRunningWave(state: AiSiteImportState | null | undefined): AiSiteImportWave | null {\n return state?.waves.find((wave) => wave.status === 'running') ?? null\n}\n\n/** The next wave a person may start, else `null`. */\nexport function aiSiteImportNextWave(state: AiSiteImportState | null | undefined): AiSiteImportWave | null {\n if (!state || aiSiteImportRunningWave(state) || aiSiteImportReadStops(state.verdict)) return null\n return state.waves.find((wave) => wave.status === 'waiting') ?? null\n}\n\n/** The wave a person is reviewing, else `null`. */\nexport function aiSiteImportReviewWave(state: AiSiteImportState | null | undefined): AiSiteImportWave | null {\n return state?.waves.find((wave) => wave.status === 'review') ?? null\n}\n\n/** Whether a page's read holds a form that asks something, where its layout placed one. */\nfunction pageHoldsForm(page: AiSiteImportPage): boolean {\n const { read } = page\n if (!read?.layout || !read.forms?.some((form) => form.fields.length)) return false\n const holds = (nodes: readonly SiteImportLayoutNode[]): boolean =>\n nodes.some((node) => {\n if (node.kind === 'form') return (read.forms?.[node.form]?.fields.length ?? 0) > 0\n if (node.kind === 'row') return node.cells.some((cell) => holds(cell.nodes))\n if (node.kind === 'tabs') return node.tabs.some((tab) => holds(tab.panel))\n return false\n })\n return read.layout.sections.some((section) => holds(section.nodes))\n}\n\n/** What the next pass of the step does. */\nexport function aiSiteImportNextWork(\n state: AiSiteImportState | null | undefined,\n items: readonly AiJobItemLedger[] | null | undefined,\n): AiSiteImportWork {\n // A read that stopped at its home page reads again: the person's Check again.\n if (!state || aiSiteImportReadStops(state.verdict)) return { kind: 'inventory' }\n const running = aiSiteImportRunningWave(state)\n if (!running) {\n const next = aiSiteImportNextWave(state)\n return next ? { kind: 'start-wave', wave: next } : { kind: 'done' }\n }\n const open = running.slots\n .filter((slot) => aiSiteImportItemOpen(items, slot))\n .map((slot) => state.pages.find((page) => page.slot === slot))\n .filter((page): page is AiSiteImportPage => !!page)\n const unread = open.filter((page) => !page.read && !page.refused)\n const reached = open.filter((page) => !unread.includes(page))\n // Nothing in hand: the wave's read goes on first. Pages in hand are built\n // first (AGL-4083): a read that stopped short, or that left pages out to keep\n // the job within what one document holds, goes on once their words are gone.\n if (unread.length && !reached.length) return { kind: 'read', wave: running, pages: unread }\n // A generative Improve it plans the site once, before anything of it is built (AGL-4152).\n if (running.generative && running.frame && state.waves[0]?.index === running.index) {\n if (state.plan === undefined) return { kind: 'plan', wave: running }\n if (state.plan && !state.planAccepted) return { kind: 'plan-accepted', wave: running }\n }\n if (running.frame && state.frame && aiSiteImportItemOpen(items, AI_SITE_IMPORT_FRAME_SLOT)) {\n return { kind: 'frame', wave: running }\n }\n const page = reached[0]\n if (!page) return { kind: 'close-wave', wave: running }\n if (!page.photos) return { kind: 'images', wave: running, page }\n return !page.forms && pageHoldsForm(page) ? { kind: 'forms', wave: running, page } : { kind: 'page', wave: running, page }\n}\n\n/*------------------------------------------\n * The state, one pass at a time\n *-----------------------------------------*/\n\nconst withPage = (state: AiSiteImportState, slot: string, patch: Partial<AiSiteImportPage>): AiSiteImportState => ({\n ...state,\n pages: state.pages.map((page) => (page.slot === slot ? { ...page, ...patch } : page)),\n})\n\nconst withWave = (state: AiSiteImportState, index: number, patch: Partial<AiSiteImportWave>): AiSiteImportState => ({\n ...state,\n waves: state.waves.map((wave) => (wave.index === index ? { ...wave, ...patch } : wave)),\n})\n\n/** A wave started: running, with what its read found on each page. */\nexport function aiSiteImportWaveStarted(\n state: AiSiteImportState,\n index: number,\n at: string,\n reads: ReadonlyMap<string, AiSiteImportPageRead | AiSiteImportLeftOutReason>,\n): AiSiteImportState {\n // The wave reviewed before this one is done: starting the next is the person's say-so.\n const next = withWave(\n { ...state, waves: state.waves.map((wave) => (wave.status === 'review' ? { ...wave, status: 'done' as const } : wave)) },\n index,\n { status: 'running', startedAt: at, finishedAt: null },\n )\n return aiSiteImportPagesRead(next, reads)\n}\n\n/** How many characters a block holds, as the job document stores it. */\nexport function aiSiteImportBlockChars(block: SiteImportBlock): number {\n if (block.kind === 'image') return block.url.length + block.alt.length\n return block.text.length + (block.kind === 'link' ? block.href.length : 0)\n}\n\n/** A page's blocks in order, as many as fit `maxChars` and `maxBlocks`, and whether any had to go. */\nexport function aiSiteImportCapBlocks(\n blocks: readonly SiteImportBlock[],\n maxChars: number,\n maxBlocks: number = AI_SITE_IMPORT_READ_MAX_BLOCKS,\n): { blocks: SiteImportBlock[]; chars: number; cut: boolean } {\n const kept: SiteImportBlock[] = []\n let chars = 0\n for (const block of blocks) {\n const size = aiSiteImportBlockChars(block)\n if (kept.length >= maxBlocks || chars + size > maxChars) return { blocks: kept, chars, cut: true }\n kept.push(block)\n chars += size\n }\n return { blocks: kept, chars, cut: false }\n}\n\nconst readChars = (read: AiSiteImportPageRead | null | undefined) =>\n (read?.blocks ?? []).reduce((total, block) => total + aiSiteImportBlockChars(block), 0) + siteImportLayoutChars(read?.layout)\n\n/**\n * A page's layout in the room the wave has left after its blocks (AGL-4106):\n * cut to the blocks kept, its drawings dropped when it would not fit with\n * them, and left off when it would not fit at all (the page is then laid out\n * from its lines alone).\n */\nfunction layoutWithin(layout: SiteImportLayout | null | undefined, blocks: number, left: number): SiteImportLayout | null {\n if (!layout) return null\n const room = Math.min(left, AI_SITE_IMPORT_LAYOUT_MAX_CHARS)\n const cut = siteImportLayoutWithin(layout, blocks)\n if (siteImportLayoutChars(cut) <= room) return cut\n const light = siteImportLayoutWithoutDrawings(cut)\n return siteImportLayoutChars(light) <= room ? light : null\n}\n\n/**\n * More of a running wave's pages, read now. Their blocks share\n * `AI_SITE_IMPORT_WAVE_READ_MAX_CHARS` with every read still held: a page\n * past it keeps what fits, in order, and is marked `cut`.\n */\nexport function aiSiteImportPagesRead(\n state: AiSiteImportState,\n reads: ReadonlyMap<string, AiSiteImportPageRead | AiSiteImportLeftOutReason>,\n): AiSiteImportState {\n let held = state.pages.filter((page) => !reads.has(page.slot)).reduce((total, page) => total + readChars(page.read), 0)\n let next = state\n for (const [slot, read] of reads) {\n if (typeof read === 'string') {\n next = withPage(next, slot, { refused: read, read: null })\n continue\n }\n let kept = read\n if (read.blocks) {\n const room = Math.max(0, Math.min(AI_SITE_IMPORT_READ_MAX_CHARS, AI_SITE_IMPORT_WAVE_READ_MAX_CHARS - held))\n const capped = aiSiteImportCapBlocks(read.blocks, room)\n held += capped.chars\n kept = { ...read, blocks: capped.blocks, ...(capped.cut || read.cut ? { cut: true } : {}) }\n if (read.layout) {\n const layout = layoutWithin(read.layout, capped.blocks.length, Math.max(0, AI_SITE_IMPORT_WAVE_READ_MAX_CHARS - held))\n held += siteImportLayoutChars(layout)\n kept = { ...kept, layout }\n }\n }\n next = withPage(next, slot, { read: kept, refused: null, title: clipLabel(read.title) || next.pages.find((page) => page.slot === slot)?.title || '' })\n }\n // A generative wave keeps what its pages say past each page (AGL-4152); any other leaves the state as it was.\n if (next.waves.some((wave) => wave.status === 'running' && wave.generative)) next = { ...next, said: aiSiteImportSaid(next.said, reads.values()) }\n return next\n}\n\n/** A page's photos are in the library. */\nexport function aiSiteImportPhotosIn(\n state: AiSiteImportState,\n slot: string,\n photos: NonNullable<AiSiteImportPage['photos']>,\n): AiSiteImportState {\n return withPage(state, slot, { photos })\n}\n\n/** A page's forms are the site's own (AGL-4083). */\nexport function aiSiteImportFormsIn(\n state: AiSiteImportState,\n slot: string,\n forms: NonNullable<AiSiteImportPage['forms']>,\n note: string | null,\n): AiSiteImportState {\n return withPage(state, slot, { forms, ...(note ? { formNote: note } : {}) })\n}\n\n/**\n * A page is in: nothing of its read is kept but what its row shows (AGL-4083).\n * Every page rides one job document, and on 11/1 what 344 settled pages still\n * held left a 400-page import too little room for the next wave's read.\n */\nexport function aiSiteImportPageSettled(state: AiSiteImportState, slot: string): AiSiteImportState {\n const page = state.pages.find((entry) => entry.slot === slot)\n if (!page?.read) return state\n const { meta: _meta, ...read } = page.read\n return withPage(state, slot, {\n read: { ...read, text: '', sections: [], images: [], blocks: [], forms: [], layout: null, ...(read.videos ? { videos: [] } : {}) },\n ...(page.photos ? { photos: { ...page.photos, assets: [] } } : {}),\n })\n}\n\n/** A wave is in: waiting for its review, or done when no wave follows it. */\nexport function aiSiteImportWaveClosed(state: AiSiteImportState, index: number, at: string): AiSiteImportState {\n const later = state.waves.some((wave) => wave.index > index && wave.status === 'waiting')\n // Start every remaining wave: no review between waves, the last one's close is the stop.\n let next = withWave(state, index, { status: later && !state.autoContinue ? 'review' : 'done', finishedAt: at })\n // What the wave read is no longer needed by any model answer.\n for (const slot of state.waves.find((wave) => wave.index === index)?.slots ?? []) next = aiSiteImportPageSettled(next, slot)\n return next\n}\n\n/**\n * The state of an import a person canceled (AGL-4107): every wave settled. A\n * wave that ran, or was waiting to, is stopped; one already in, for review or\n * done, is in. On 10/29 a canceled import still showed its second wave as\n * running, with nothing running it.\n */\nexport function aiSiteImportCanceled(state: AiSiteImportState, at: string): AiSiteImportState {\n return {\n ...state,\n autoContinue: false,\n waves: state.waves.map((wave): AiSiteImportWave => {\n if (wave.status === 'running' || wave.status === 'waiting') return { ...wave, status: 'stopped', finishedAt: wave.status === 'running' ? at : wave.finishedAt }\n if (wave.status === 'review') return { ...wave, status: 'done' }\n return wave\n }),\n }\n}\n\n/** The state as the console reads it: every page's read text left off. */\nexport function aiSiteImportWire(state: AiSiteImportState | null | undefined): AiSiteImportState | null {\n if (!state) return null\n // What the site's pages say is the redesigns' (AGL-4152): the console reads none of it.\n const { said: _said, ...rest } = state\n return {\n ...rest,\n pages: state.pages.map((page) =>\n page.read ? { ...page, read: { ...page.read, text: '', images: [], blocks: [], forms: [], layout: null, ...(page.read.videos ? { videos: [] } : {}) } } : page,\n ),\n }\n}\n\n/*------------------------------------------\n * Keep my site, or Improve it (AGL-4152)\n *-----------------------------------------*/\n\n/** A finish read defensively: only `improve` is improve, so an import that never said reads as `keep`. */\nexport function aiSiteImportFinishOf(value: unknown): AiSiteImportFinish {\n return value === 'improve' ? 'improve' : 'keep'\n}\n\n/** Whether the wording is improved: only under `improve`, and on unless the owner switched it off. */\nexport function aiSiteImportWordingOf(finish: AiSiteImportFinish, value: unknown): boolean {\n return finish === 'improve' && value !== false && value !== 'false'\n}\n\n/** The choice an import holds now, read defensively: an older import with none is `keep`, never silently improved. */\nexport function aiSiteImportChoiceOf(state: Pick<AiSiteImportState, 'finish' | 'wording'> | null | undefined): AiSiteImportChoice {\n const finish = aiSiteImportFinishOf(state?.finish)\n return { finish, wording: aiSiteImportWordingOf(finish, state?.wording) }\n}\n\n/** The choice Bring my site carried in the job's inputs (`AI_SITE_IMPORT_FINISH_INPUT`, `AI_SITE_IMPORT_WORDING_INPUT`); none is `keep`. */\nexport function aiSiteImportChoiceFromInputs(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportChoice {\n const finish = aiSiteImportFinishOf(inputs?.[AI_SITE_IMPORT_FINISH_INPUT])\n return { finish, wording: aiSiteImportWordingOf(finish, inputs?.[AI_SITE_IMPORT_WORDING_INPUT]) }\n}\n\n/** Whether a word names a legal entry's part: the word itself, or its plural. */\nconst namesPart = (word: string, part: string) =>\n word === part || word === `${part}s` || (part.endsWith('y') && word === `${part.slice(0, -1)}ies`)\n\n/** Whether a page is a policy (`AI_SITE_IMPORT_LEGAL_SLUGS`) by its address on either site or its title (AGL-4152). */\nexport function aiSiteImportPageIsLegal(page: Pick<AiSiteImportPage, 'slug' | 'title'> & Partial<Pick<AiSiteImportPage, 'path'>>): boolean {\n const wordsOf = (text: string | undefined) => String(text ?? '').toLowerCase().split(/[^\\p{L}\\p{N}]+/u).filter(Boolean)\n const said = [wordsOf(page.slug), wordsOf(page.path), wordsOf(page.title)]\n return AI_SITE_IMPORT_LEGAL_SLUGS.some((entry) => {\n const parts = entry.split('-')\n return said.some((words) => words.some((_, at) => parts.every((part, offset) => namesPart(words[at + offset] ?? '', part))))\n })\n}\n\n/**\n * Whether a page's words are improved under a choice (AGL-4152): only a main\n * page Aglyn AI arranges, under Improve it with its wording on, and never a\n * policy page. Every other page keeps every word as written.\n */\nexport function aiSiteImportPageWording(\n page: Pick<AiSiteImportPage, 'group' | 'words' | 'slug' | 'title' | 'build'> & Partial<Pick<AiSiteImportPage, 'path'>>,\n choice: AiSiteImportChoice,\n): AiSiteImportWords {\n const build = page.build ?? aiSiteImportPageBuild(page)\n return choice.finish === 'improve' && choice.wording && build === 'arranged' && page.group === 'main' && !aiSiteImportPageIsLegal(page) ? 'improved' : 'kept'\n}\n\n/**\n * How a wave is built (AGL-4152): as it was stamped when it started, which a\n * later change never redraws; a wave not yet started is the import's choice\n * now. A wave that started before the choice existed reads as `keep`.\n */\nexport function aiSiteImportWaveChoice(state: Pick<AiSiteImportState, 'finish' | 'wording'> | null | undefined, wave: AiSiteImportWave): AiSiteImportChoice {\n if (!wave.startedAt && (wave.status === 'waiting' || wave.status === 'stopped')) return aiSiteImportChoiceOf(state)\n const finish = aiSiteImportFinishOf(wave.finish)\n return { finish, wording: finish === 'improve' && wave.wording === true }\n}\n\n/**\n * A wave starting (AGL-4152): stamped with the import's choice now, and each\n * of its pages with whether its words are kept or improved. The step stamps a\n * wave once, when it starts, so a change made before a later wave reaches only\n * the waves that have not started.\n */\nexport function aiSiteImportWaveStamped(state: AiSiteImportState, index: number, options: { generative?: boolean; videoPosters?: boolean } = {}): AiSiteImportState {\n const wave = state.waves.find((entry) => entry.index === index)\n if (!wave) return state\n const choice = aiSiteImportChoiceOf(state)\n const slots = new Set(wave.slots)\n // A generative Improve it plans the site and its design with new copy or without (AGL-4152):\n // a page is redesigned from its ledger only where its words are improved too.\n const generative = options.generative === true && choice.finish === 'improve'\n return {\n ...state,\n waves: state.waves.map((entry) =>\n entry.index === index\n ? {\n ...entry,\n finish: choice.finish,\n wording: choice.wording,\n ...(generative ? { generative: true as const } : {}),\n // YouTube's own still for a film with no poster (AGL-4140), whatever the finish.\n ...(options.videoPosters === true ? { videoPosters: true as const } : {}),\n }\n : entry,\n ),\n pages: state.pages.map((page) => (slots.has(page.slot) ? { ...page, wording: aiSiteImportPageWording(page, choice) } : page)),\n // What its pages say, kept past each page for every redesign's facts (AGL-4152): the home page's first.\n ...(generative\n ? {\n said: aiSiteImportSaid(\n state.said,\n [...state.pages].sort((a, b) => Number(b.slug === '/') - Number(a.slug === '/')).flatMap((page) => (slots.has(page.slot) && page.read ? [page.read] : [])),\n ),\n }\n : {}),\n }\n}\n\n/**\n * The owner's change between waves (AGL-4152), as the resume door writes it\n * onto an import waiting for a wave: the finish, and the wording switch,\n * always off under `keep`. What is not given keeps the import's choice now.\n * `null` when the job is not an import waiting for a wave that has not started.\n */\nexport function aiSiteImportFinishUpdate(\n job: Pick<AiJob, 'kind' | 'status' | 'review' | 'siteImport'>,\n change: { finish?: AiSiteImportFinish | null; wording?: boolean | null },\n): { 'siteImport.finish': AiSiteImportFinish; 'siteImport.wording': boolean } | null {\n const state = job.siteImport ?? null\n if (job.kind !== AI_SITE_IMPORT_KIND || job.status !== 'needs_review' || job.review?.reason !== 'wave' || !state) return null\n if (aiSiteImportReadStops(state.verdict) || !state.waves.some((wave) => wave.status === 'waiting')) return null\n const now = aiSiteImportChoiceOf(state)\n const finish = change.finish ? aiSiteImportFinishOf(change.finish) : now.finish\n // Under Improve, the switch as given, else as it stands, else on (its default).\n const asked = typeof change.wording === 'boolean' ? change.wording : now.finish === 'improve' ? now.wording : AI_SITE_IMPORT_DEFAULT_CHOICE.wording\n return { 'siteImport.finish': finish, 'siteImport.wording': aiSiteImportWordingOf(finish, asked) }\n}\n\n/** The most source photos an import holds for a later page's slots: each is a library reference, and every page rides one job document. */\nconst SITE_PHOTOS_HELD = 24\n\n/**\n * How a page's generative Improve it came out (AGL-4152), what it added and what\n * it shows, for its row; and the source's photos it left off, which a later\n * page's slot takes before a stock photo.\n */\nexport function aiSiteImportRedesignOf(\n state: AiSiteImportState,\n slot: string,\n redesign: AiSiteImportRedesign,\n added?: readonly AiSiteImportAddedSection[],\n pictures?: AiSiteImportPagePictures | null,\n missed?: readonly string[] | null,\n): AiSiteImportState {\n const next = withPage(state, slot, { redesign, ...(added?.length ? { added: [...added] } : {}), ...(pictures ? { pictures } : {}), ...(missed?.length ? { redesignMissed: missed.slice(0, 8).map((code) => code.slice(0, 40)) } : {}) })\n const left = new Set(pictures?.unplaced ?? [])\n if (!left.size) return next\n const assets = state.pages.find((page) => page.slot === slot)?.photos?.assets ?? []\n const held = next.sitePhotos ?? []\n const pool = [...held, ...assets.filter((photo) => !!photo.from && left.has(photo.from) && !held.some((other) => other.src === photo.src))].slice(0, SITE_PHOTOS_HELD)\n return pool.length ? { ...next, sitePhotos: pool } : next\n}\n\n/*------------------------------------------\n * The site's plan (AGL-4152)\n *-----------------------------------------*/\n\n/** Whether generated pictures are on for an import: as its owner said, else the default. */\nexport function aiSiteImportGeneratedPicturesOn(state: Pick<AiSiteImportState, 'generatedPictures'> | null | undefined): boolean {\n return typeof state?.generatedPictures === 'boolean' ? state.generatedPictures : AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT\n}\n\n/** Whether the job waits on its owner's say-so over a plan (AGL-4152): shown, and nothing of the site built. */\nexport function aiSiteImportPlanAwaits(state: Pick<AiSiteImportState, 'plan' | 'planAccepted'> | null | undefined): boolean {\n return !!state?.plan && !state.planAccepted\n}\n\n/** Whether the site has room for a page more than the import brings in (AGL-4152): the plan's count, against what is there and what is coming. */\nexport function aiSiteImportHasRoomForPage(state: Pick<AiSiteImportState, 'pages'>, room: { limit: number | null; used: number }): boolean {\n if (room.limit === null) return true\n return room.limit - room.used - state.pages.filter((page) => !page.refused).length >= 1\n}\n\n/**\n * The plan in, or the plan that did not pass (`null`). A proposed page takes\n * its place in the wave's rows as a page of its own, new, with no source: its\n * words are written from what the site says, so its one line is its purpose.\n */\nexport function aiSiteImportPlanIn(state: AiSiteImportState, wave: Pick<AiSiteImportWave, 'index'>, plan: AiSiteImportPlan | null, at: string, draftId: string): AiSiteImportState {\n if (!plan?.proposed) return { ...state, plan }\n const proposed = plan.proposed\n const named = (pages: readonly string[]) => pages.map((page) => (page === AI_SITE_IMPORT_PROPOSED_PAGE ? draftId : page))\n const page: AiSiteImportPage = {\n slot: AI_SITE_IMPORT_PROPOSED_SLOT,\n url: `https://${state.domain}/${proposed.slug}`,\n path: `/${proposed.slug}`,\n title: proposed.title,\n group: 'main',\n wave: wave.index,\n draftId,\n slug: proposed.slug,\n words: 0,\n images: 0,\n origin: 'proposed',\n build: 'arranged',\n wording: 'improved',\n photos: { brought: 0, reused: 0, skipped: 0, assets: [] },\n read: {\n at,\n title: proposed.title,\n text: proposed.purpose,\n sections: [proposed.title],\n images: [],\n blocks: [\n { kind: 'heading', level: 1, text: proposed.title, region: 'main' },\n { kind: 'paragraph', text: proposed.purpose, region: 'main' },\n ],\n words: proposed.purpose.split(/\\s+/).filter(Boolean).length,\n forms: [],\n layout: null,\n },\n }\n const cta = plan.nav.primaryCta\n return {\n ...state,\n plan: {\n ...plan,\n nav: {\n groups: plan.nav.groups.map((group) => ({ ...group, pages: named(group.pages) })),\n primaryCta: cta && cta.target === AI_SITE_IMPORT_PROPOSED_PAGE ? { ...cta, target: draftId } : cta,\n footer: plan.nav.footer.map((column) => ({ ...column, pages: named(column.pages) })),\n },\n proposed: { ...proposed, draftId },\n ...(plan.roles ? { roles: Object.fromEntries(Object.entries(plan.roles).map(([id, role]) => [id === AI_SITE_IMPORT_PROPOSED_PAGE ? draftId : id, role])) } : {}),\n },\n pages: [...state.pages, page],\n waves: state.waves.map((entry) => (entry.index === wave.index ? { ...entry, slots: [...entry.slots, AI_SITE_IMPORT_PROPOSED_SLOT] } : entry)),\n }\n}\n\n/** A plan with its proposed page's row: pending, unless it is the one row a plan has already added. */\nexport function aiSiteImportPlanRow(state: Pick<AiSiteImportState, 'plan'>, items: readonly AiJobItemLedger[]): AiJobItemLedger[] {\n const proposed = state.plan?.proposed\n if (!proposed || items.some((row) => row.slot === AI_SITE_IMPORT_PROPOSED_SLOT)) return [...items]\n return [...items, { slot: AI_SITE_IMPORT_PROPOSED_SLOT, op: 'page', label: proposed.title, status: 'pending', attempt: 1, creditsSpent: 0, creditsRefunded: 0, outputs: [] }]\n}\n\n/**\n * The owner started the build (AGL-4152). A proposed page they switched off is\n * gone: its row, its place in the wave, and every menu entry that named it.\n */\nexport function aiSiteImportPlanAccepted(state: AiSiteImportState, items: readonly AiJobItemLedger[]): { state: AiSiteImportState; items: AiJobItemLedger[] } {\n const plan = state.plan\n if (!plan?.proposed || plan.proposed.on) return { state: { ...state, planAccepted: true }, items: [...items] }\n const off = plan.proposed.draftId\n const kept = (pages: readonly string[]) => pages.filter((page) => page !== off)\n const cta = plan.nav.primaryCta\n return {\n state: {\n ...state,\n planAccepted: true,\n plan: {\n ...plan,\n nav: {\n groups: plan.nav.groups.map((group) => ({ ...group, pages: kept(group.pages) })).filter((group) => group.pages.length),\n primaryCta: cta?.target === off ? null : cta,\n footer: plan.nav.footer.map((column) => ({ ...column, pages: kept(column.pages) })).filter((column) => column.pages.length),\n },\n proposed: { ...plan.proposed, on: false },\n },\n pages: state.pages.filter((page) => page.slot !== AI_SITE_IMPORT_PROPOSED_SLOT),\n waves: state.waves.map((wave) => ({ ...wave, slots: wave.slots.filter((slot) => slot !== AI_SITE_IMPORT_PROPOSED_SLOT) })),\n },\n items: items.filter((row) => row.slot !== AI_SITE_IMPORT_PROPOSED_SLOT),\n }\n}\n\n/**\n * The owner's answer to a plan (AGL-4152), as the resume door writes it onto\n * an import waiting on one. What is not given stands. `null` when the job is\n * not an import waiting on a plan, or nothing is asked.\n */\nexport function aiSiteImportPlanUpdate(\n job: Pick<AiJob, 'kind' | 'status' | 'review' | 'siteImport'>,\n change: AiSiteImportPlanChoice,\n): Record<string, boolean> | null {\n const state = job.siteImport ?? null\n if (job.kind !== AI_SITE_IMPORT_KIND || job.status !== 'needs_review' || job.review?.reason !== 'wave' || !aiSiteImportPlanAwaits(state)) return null\n const update: Record<string, boolean> = {}\n if (typeof change.addPage === 'boolean' && state?.plan?.proposed) update['siteImport.plan.proposed.on'] = change.addPage\n if (typeof change.pictures === 'boolean') update['siteImport.generatedPictures'] = change.pictures\n return Object.keys(update).length ? update : null\n}\n\n/**\n * A page whose rewrite was refused (AGL-4152): it keeps every word as\n * written, and its row reads as kept. Only a page stamped `improved` changes.\n */\nexport function aiSiteImportWordsKept(state: AiSiteImportState, slot: string): AiSiteImportState {\n if (!state.pages.some((page) => page.slot === slot && page.wording === 'improved')) return state\n return { ...state, pages: state.pages.map((page) => (page.slot === slot ? { ...page, wording: 'kept' as const } : page)) }\n}\n\n/** The pages of a wave whose words a choice improves, of those it still owes (AGL-4152). */\nexport function aiSiteImportWordingPages(\n state: AiSiteImportState,\n wave: AiSiteImportWave,\n choice: AiSiteImportChoice,\n items?: readonly AiJobItemLedger[] | null,\n): number {\n if (choice.finish !== 'improve' || !choice.wording) return 0\n return wave.slots.filter((slot) => {\n const page = state.pages.find((entry) => entry.slot === slot)\n return !!page && !page.refused && (!items || aiSiteImportItemOpen(items, slot)) && aiSiteImportPageWording(page, choice) === 'improved'\n }).length\n}\n\n/**\n * What improving this many pages' wording adds (AGL-4152): a reworded page\n * is quoted as measured (`AI_MEASURED_IMPORT_CREDITS.reworded`) in place of an\n * arranged one, its design answer and its wording together, so each adds the\n * difference between the two. Its ceiling, the page's two passes, does not\n * move, and no price is new.\n */\nexport function aiSiteImportWordingCredits(pages: number, options: { generative?: boolean } = {}): { likely: number; p90: number } {\n const count = whole(pages)\n // Under a generative Improve it (AGL-4152) new copy is a redesign from the ledger, measured on its own row.\n const { arranged } = AI_MEASURED_IMPORT_CREDITS\n const worded = options.generative ? AI_MEASURED_IMPORT_CREDITS.redesigned : AI_MEASURED_IMPORT_CREDITS.reworded\n return { likely: count * (worded.median - arranged.median), p90: count * (worded.p90 - arranged.p90) }\n}\n\n/*------------------------------------------\n * Credits\n *-----------------------------------------*/\n\n/**\n * How a page is built (AGL-4083), decided by code: every page of a collection\n * (a blog, the legal pages, news) is copied as it is; every main page is\n * arranged by Aglyn AI whatever its length (AGL-4106), its words kept as\n * written. Both are laid out from the source's own layout.\n */\nexport function aiSiteImportPageBuild(page: Pick<AiSiteImportPage, 'group' | 'words'>): AiSiteImportBuild {\n return page.group !== 'main' ? 'copied' : 'arranged'\n}\n\nconst whole = (value: number | undefined) => Math.max(0, Math.floor(Number.isFinite(value) ? (value as number) : 0))\n\n/**\n * What bringing in this many pages costs, quoted before it starts (AGL-3976):\n * each page an AI page as measured, its ceiling its two passes, and the\n * site's header and footer once when the wave builds them. Pages the step has\n * chosen a build for (AGL-4083) are priced by it: `arranged` at the\n * arrangement answer and its listing, `copied` at the listing alone. Of the\n * arranged, those `reworded` under Also improve my wording (AGL-4152) are\n * priced as an AI page, inside the same ceiling.\n */\nexport function aiSiteImportCreditRange(\n pages: number,\n options: {\n frame?: boolean\n arranged?: number\n copied?: number\n reworded?: number\n /** The site's plan, still owed under a generative Improve it (AGL-4152), priced as a paid site's plan until it is measured. */\n plan?: boolean\n /** A proposed page not yet among the wave's own, quoted as a redesigned page (AGL-4152). */\n proposed?: number\n /** Generated pictures it may take at most (AGL-4152): in its ceiling only, since each takes what nothing else fills. */\n pictures?: number\n /** Its reworded pages are redesigned from their ledgers (AGL-4152), quoted on that row. */\n generative?: boolean\n } = {},\n): AiCreditRange {\n const count = whole(pages)\n const proposed = whole(options.proposed)\n const arranged = whole(options.arranged) + proposed\n const copied = whole(options.copied)\n const wording = aiSiteImportWordingCredits(Math.min(arranged, whole(options.reworded) + proposed), options.generative ? { generative: true } : {})\n const measured = AI_MEASURED_IMPORT_CREDITS\n const plan = options.plan ? AI_MEASURED_PAID_SITE_CREDITS.plan : { median: 0, p90: 0 }\n return aiCreditRangeOrdered({\n likely:\n count * measured.page.median +\n arranged * measured.arranged.median +\n wording.likely +\n copied * measured.copied.median +\n (options.frame ? measured.frame.median : 0) +\n plan.median,\n p90: count * measured.page.p90 + arranged * measured.arranged.p90 + wording.p90 + copied * measured.copied.p90 + (options.frame ? measured.frame.p90 : 0) + plan.p90,\n ceiling:\n (count + arranged) * AI_SITE_IMPORT_PAGE_CEILING_CREDITS +\n copied * AI_SITE_IMPORT_COPIED_CEILING_CREDITS +\n (options.frame ? AI_SITE_IMPORT_FRAME_CEILING_CREDITS : 0) +\n (options.plan ? AI_SITE_IMPORT_PLAN_CEILING_CREDITS : 0) +\n whole(options.pictures) * aiMediaCreditsPerPicture('photo', undefined, '1K'),\n })\n}\n\n/**\n * What a wave still owes, by how its pages are built, and whether its header\n * and footer are owed. `reworded` are those of `arranged` whose words the\n * wave improves (AGL-4152): as stamped once it has started, and as the\n * import's choice now would stamp them before.\n */\nexport function aiSiteImportWaveOwed(\n state: AiSiteImportState,\n wave: AiSiteImportWave,\n items?: readonly AiJobItemLedger[] | null,\n): { pages: number; arranged: number; reworded: number; copied: number; frame: boolean; plan?: boolean; proposed?: number; pictures?: number; generative?: boolean } {\n const owed = (slot: string) => (items ? aiSiteImportItemOpen(items, slot) : true)\n const choice = aiSiteImportWaveChoice(state, wave)\n // A generative Improve it's own (AGL-4152): its frame draws from the plan, and a plan is owed once.\n const generative = aiSiteImportWaveIsGenerative(state, wave)\n const planned = generative && !!state.plan\n // A header and footer drawn from the source's own menu ask no model (AGL-4108), so are owed nothing.\n const counts = { pages: 0, arranged: 0, reworded: 0, copied: 0, frame: wave.frame && !!state.frame && !aiSiteImportFrameIsRead(state) && !planned && owed(AI_SITE_IMPORT_FRAME_SLOT) }\n for (const slot of wave.slots) {\n const page = state.pages.find((entry) => entry.slot === slot)\n if (!owed(slot) || page?.refused) continue\n if (page?.build === 'arranged') {\n counts.arranged += 1\n if ((wave.startedAt ? page.wording : aiSiteImportPageWording(page, choice)) === 'improved') counts.reworded += 1\n } else if (page?.build === 'copied') counts.copied += 1\n else counts.pages += 1\n }\n if (!generative) return counts\n const first = state.waves[0]?.index === wave.index && wave.frame\n // Before the plan is in, a page it may propose is quoted, where the plan's count has room for one.\n const proposed = first && state.plan === undefined && choice.wording && aiSiteImportHasRoomForPage(state, { limit: state.pageLimit, used: state.existingPages }) ? 1 : 0\n const pictures = choice.wording && aiSiteImportGeneratedPicturesOn(state) ? (counts.reworded + proposed) * AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE : 0\n return { ...counts, generative: true, ...(first && state.plan === undefined ? { plan: true } : {}), ...(proposed ? { proposed } : {}), ...(pictures ? { pictures } : {}) }\n}\n\n/**\n * Whether a wave is a generative Improve it (AGL-4152): as stamped once it has\n * started; before, whether the import was read under the flag and asks to be\n * improved now.\n */\nexport function aiSiteImportWaveIsGenerative(state: Pick<AiSiteImportState, 'generative' | 'finish' | 'wording'>, wave: AiSiteImportWave): boolean {\n return wave.startedAt ? wave.generative === true : state.generative === true && aiSiteImportChoiceOf(state).finish === 'improve'\n}\n\n/** A wave's quote: the pages it has still to bring in, and its header and footer while they are owed. */\nexport function aiSiteImportWaveCreditRange(\n state: AiSiteImportState,\n wave: AiSiteImportWave,\n items?: readonly AiJobItemLedger[] | null,\n): AiCreditRange {\n const owed = aiSiteImportWaveOwed(state, wave, items)\n return aiSiteImportCreditRange(owed.pages, { frame: owed.frame, arranged: owed.arranged, reworded: owed.reworded, copied: owed.copied, plan: owed.plan, proposed: owed.proposed, pictures: owed.pictures, ...(owed.generative ? { generative: true } : {}) })\n}\n\n/** Every wave still waiting, quoted at once: \"Start every remaining wave\" (AGL-4083). */\nexport function aiSiteImportRemainingCreditRange(\n state: AiSiteImportState,\n items?: readonly AiJobItemLedger[] | null,\n): AiCreditRange {\n const total = { pages: 0, arranged: 0, reworded: 0, copied: 0, frame: false, plan: false, proposed: 0, pictures: 0, generative: false }\n for (const wave of state.waves) {\n if (wave.status !== 'waiting') continue\n const owed = aiSiteImportWaveOwed(state, wave, items)\n total.pages += owed.pages\n total.arranged += owed.arranged\n total.reworded += owed.reworded\n total.copied += owed.copied\n total.frame = total.frame || owed.frame\n total.plan = total.plan || owed.plan === true\n total.proposed += owed.proposed ?? 0\n total.pictures += owed.pictures ?? 0\n total.generative = total.generative || owed.generative === true\n }\n return aiSiteImportCreditRange(total.pages, { frame: total.frame, arranged: total.arranged, reworded: total.reworded, copied: total.copied, plan: total.plan, proposed: total.proposed, pictures: total.pictures, ...(total.generative ? { generative: true } : {}) })\n}\n\n/**\n * \"About 95 credits (up to 600): 7 pages arranged by Aglyn AI, 3 copied as\n * they are\"; the build is named once the step has chosen, and pages whose\n * words are improved too (AGL-4152) as \"arranged and reworded by Aglyn AI\".\n */\nexport function aiSiteImportQuoteText(\n range: AiCreditRange,\n owed: Pick<ReturnType<typeof aiSiteImportWaveOwed>, 'arranged' | 'copied'> & Partial<Pick<ReturnType<typeof aiSiteImportWaveOwed>, 'reworded' | 'plan' | 'proposed' | 'pictures'>>,\n options: { generative?: boolean } = {},\n): string {\n const reworded = Math.min(owed.arranged, whole(owed.reworded))\n const runs: Array<[number, (count: number) => string]> = [\n // Under a generative Improve it, a page redesigned from its ledger (AGL-4152).\n [reworded, () => (options.generative ? `redesigned by ${PLATFORM_BRAND_NAME} AI` : `arranged and reworded by ${PLATFORM_BRAND_NAME} AI`)],\n [owed.arranged - reworded, () => `arranged by ${PLATFORM_BRAND_NAME} AI`],\n [owed.copied, (count) => `copied as ${count === 1 ? 'it is' : 'they are'}`],\n ]\n const parts: string[] = []\n for (const [count, what] of runs) {\n if (!count) continue\n // The first run names its pages; the rest are counted beside it.\n parts.push(`${parts.length ? count.toLocaleString('en-US') : aiSiteImportPagesText(count)} ${what(count)}`)\n }\n // What a generative Improve it adds (AGL-4152): its plan, the page it may propose, the pictures it may generate.\n if (owed.plan) parts.unshift('your site’s plan')\n if (owed.proposed) parts.push('a new page if the plan proposes one')\n if (owed.pictures) parts.push(`up to ${owed.pictures.toLocaleString('en-US')} generated pictures`)\n return parts.length ? `${aiCreditRangeText(range)}: ${parts.join(', ')}` : aiCreditRangeText(range)\n}\n\n/*------------------------------------------\n * Words\n *-----------------------------------------*/\n\n/** Why a page is not brought in, as a person reads it. */\nexport const AI_SITE_IMPORT_LEFT_OUT_COPY: Readonly<Record<AiSiteImportLeftOutReason, string>> = {\n 'plan-limit': 'Past your plan’s page count. Upgrade for more pages, then bring the rest in.',\n robots: 'The site’s robots.txt asks AglynBot not to read it.',\n 'login-form': 'A sign-in page. Pages that ask for a password are never brought in.',\n empty:\n 'No text could be read from this page. If your site is built in a way that needs a browser to show its words, it cannot be brought in yet.',\n unreadable: 'It could not be read just now.',\n blocked:\n 'The site’s bot protection or firewall turned AglynBot away. Allow AglynBot in your site’s bot or firewall settings, then bring the site in again.',\n 'too-large': 'Larger than a page can be to bring in.',\n 'off-site': 'It sends visitors to another website.',\n 'not-reached': 'Not reached: the read stopped before it got to this page.',\n file: 'A file, not a page.',\n duplicate: 'A second address for the same page, so it is not brought in twice.',\n 'system-page': 'A cart, checkout, account, or search screen your website platform makes, not a page of your own.',\n missing: 'Your site says this page does not exist, though a link or sitemap on your site still points to it.',\n}\n\n/** \"3 pages\" / \"1 page\". */\nexport function aiSiteImportPagesText(count: number): string {\n return `${count.toLocaleString('en-US')} ${count === 1 ? 'page' : 'pages'}`\n}\n\n/** The review a finished wave parks on, or the first wave's go-ahead once the site is read. */\nexport function aiSiteImportWaveMessage(\n state: AiSiteImportState,\n items: readonly AiJobItemLedger[] | null | undefined,\n): string {\n // A read that stopped at its home page says why, and what to do.\n if (aiSiteImportReadStops(state.verdict)) return aiSiteImportReadVerdictMessage(state.verdict, state.domain) ?? ''\n const next = aiSiteImportNextWave(state)\n const reviewing = aiSiteImportReviewWave(state)\n if (!reviewing) {\n const kept = state.pages.length\n return next\n ? `Your site is read: ${aiSiteImportPagesText(kept)} to bring in, in ${state.waves.length === 1 ? 'one wave' : `${state.waves.length} waves`}. Start the first wave when you are ready.`\n : 'Your site is read, and nothing on it can be brought in.'\n }\n const rows = (items ?? []).filter((row) => reviewing.slots.includes(row.slot))\n const done = rows.filter((row) => row.status === 'succeeded' || row.status === 'degraded').length\n const lead = `${reviewing.label} is in: ${aiSiteImportPagesText(done)} ready to review as drafts.`\n return next ? `${lead} Start ${next.label} when you are ready.` : lead\n}\n"],"names":["PLATFORM_BRAND_NAME","videoEmbedOf","aiCreditRangeOrdered","aiCreditRangeText","AI_MEASURED_IMPORT_CREDITS","AI_MEASURED_PAID_SITE_CREDITS","aiMediaCreditsPerPicture","AI_SITE_IMPORT_KIND","AI_SITE_IMPORT_DOMAIN_INPUT","AI_SITE_IMPORT_WAVE_PAGES","AI_SITE_IMPORT_MAX_PAGES","AI_SITE_IMPORT_COLLECTION_MIN","AI_SITE_IMPORT_IMAGES_PER_PAGE","AI_SITE_IMPORT_PAGE_TEXT_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","AI_SITE_IMPORT_READ_MAX_BLOCKS","AI_SITE_IMPORT_READ_MAX_CHARS","AI_SITE_IMPORT_LAYOUT_MAX_CHARS","AI_SITE_IMPORT_WAVE_READ_MAX_CHARS","AI_SITE_IMPORT_PROSE_WORDS","AI_SITE_IMPORT_BLOCKED_STATUSES","Set","AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MIN_WORDS","AI_SITE_IMPORT_FRAME_SLOT","AI_SITE_IMPORT_PAGE_CEILING_CREDITS","AI_SITE_IMPORT_COPIED_CEILING_CREDITS","AI_SITE_IMPORT_FRAME_CEILING_CREDITS","AI_SITE_IMPORT_LEFT_OUT_LISTED","AI_SITE_IMPORT_LEFT_OUT_REASONS","AI_SITE_IMPORT_UNREAD_REASONS","aiSiteImportOtherAddresses","state","key","path","split","replace","leftOut","flatMap","entry","reason","sameAs","SITE_IMPORT_GROUP_KINDS","siteImportWidthOf","px","Number","isFinite","siteImportLayoutLines","nodes","out","visit","list","node","kind","push","line","poster","undefined","cell","cells","item","items","lines","row","rows","tab","tabs","label","panel","siteImportLayoutChars","layout","JSON","stringify","length","siteImportLayoutWithin","count","keep","ref","sections","map","section","backdrop","behind","video","siteImportFilterNodes","filter","_poster","rest","some","trimItem","icon","image","imageFit","figure","figureMuted","ctas","cta","SITE_IMPORT_PLAY_WORDS","siteImportFilmSource","embed","trim","src","hosted","file","test","aiSiteImportOwnFilms","read","photos","videos","held","photo","from","place","source","block","blocks","has","url","includes","SITE_IMPORT_APPROVED_HOSTS_MAX","siteImportApprovedHost","value","host","toLowerCase","bare","startsWith","slice","siteImportApprovedHostsWith","current","addresses","owner","Array","isArray","have","hostnameOf","address","URL","hostname","add","aiSiteImportVideoNote","own","films","approved","posterless","notes","Boolean","join","siteImportLayoutWithoutDrawings","icons","svg","viewBox","AI_SITE_IMPORT_FINISH_INPUT","AI_SITE_IMPORT_WORDING_INPUT","AI_SITE_IMPORT_DEFAULT_CHOICE","finish","wording","AI_SITE_IMPORT_LEGAL_SLUGS","AI_SITE_IMPORT_LAYOUT_KEPT","AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN","AI_SITE_IMPORT_SAID_MAX_CHARS","aiSiteImportSaid","said","reads","seen","chars","reduce","sum","text","AI_SITE_IMPORT_PAGE_ROLES","AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT","AI_SITE_IMPORT_PLAN_FELL_BACK","AI_SITE_IMPORT_PROPOSED_SLOT","AI_SITE_IMPORT_PROPOSED_PAGE","AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE","AI_SITE_IMPORT_PLAN_CEILING_CREDITS","aiSiteImportFrameIsRead","nav","home","pathOfUrl","pathname","wordsOf","match","isOneOfTheSitesPages","readVerdictOf","blocked","total","edge","base","homeStatus","status","homeProblem","problem","homeProblemOfSkip","aiSiteImportReadVerdict","crawled","skip","skipped","Math","max","sitemapUrls","pages","page","find","foundBy","words","inline","empty","images","aiSiteImportReadStops","verdict","aiSiteImportReadVerdictReason","AI_SITE_IMPORT_EDGE_HINTS","vercel","cloudflare","NOTHING_SPENT","homeProblemText","aiSiteImportReadVerdictMessage","domain","others","more","toLocaleString","lead","inventoryVerdict","input","skippedOverflow","clipLabel","String","trimEnd","segmentsOf","aiSiteImportPrefix","segments","first","aiSiteImportPrefixLabel","prefix","decodeURIComponent","charAt","toUpperCase","aiSiteImportGroups","menu","sized","counts","Map","set","get","menuPaths","collections","groupOf","menuRank","index","findIndex","POSITIVE_INFINITY","ordered","sort","a","b","localeCompare","groups","id","orderedWithin","group","rank","order","aiSiteImportSlug","taken","clean","last","prefixed","candidate","attempt","slug","aiSiteImportInventory","leftOutCount","waves","wavePages","floor","limit","pageLimit","leave","unreached","stoppedBy","search","title","siteName","ownership","readAt","existingPages","found","frame","readable","room","members","kept","parts","ceil","part","slots","slot","pop","wave","draftId","mintId","startedAt","finishedAt","aiSiteImportLedger","op","creditsSpent","creditsRefunded","outputs","OPEN","aiSiteImportItemOpen","aiSiteImportRunningWave","aiSiteImportNextWave","aiSiteImportReviewWave","pageHoldsForm","forms","form","fields","holds","aiSiteImportNextWork","running","next","open","unread","refused","reached","generative","plan","planAccepted","withPage","patch","withWave","aiSiteImportWaveStarted","at","aiSiteImportPagesRead","aiSiteImportBlockChars","alt","href","aiSiteImportCapBlocks","maxChars","maxBlocks","size","cut","readChars","layoutWithin","left","min","light","capped","values","aiSiteImportPhotosIn","aiSiteImportFormsIn","note","formNote","aiSiteImportPageSettled","meta","_meta","assets","aiSiteImportWaveClosed","later","autoContinue","aiSiteImportCanceled","aiSiteImportWire","_said","aiSiteImportFinishOf","aiSiteImportWordingOf","aiSiteImportChoiceOf","aiSiteImportChoiceFromInputs","inputs","namesPart","word","endsWith","aiSiteImportPageIsLegal","_","every","offset","aiSiteImportPageWording","choice","build","aiSiteImportPageBuild","aiSiteImportWaveChoice","aiSiteImportWaveStamped","options","videoPosters","aiSiteImportFinishUpdate","job","change","siteImport","review","now","asked","SITE_PHOTOS_HELD","aiSiteImportRedesignOf","redesign","added","pictures","missed","redesignMissed","code","unplaced","sitePhotos","pool","other","aiSiteImportGeneratedPicturesOn","generatedPictures","aiSiteImportPlanAwaits","aiSiteImportHasRoomForPage","used","aiSiteImportPlanIn","proposed","named","origin","brought","reused","purpose","level","region","primaryCta","target","footer","column","roles","Object","fromEntries","entries","role","aiSiteImportPlanRow","aiSiteImportPlanAccepted","on","off","aiSiteImportPlanUpdate","update","addPage","keys","aiSiteImportWordsKept","aiSiteImportWordingPages","aiSiteImportWordingCredits","whole","arranged","worded","redesigned","reworded","likely","median","p90","aiSiteImportCreditRange","copied","measured","ceiling","aiSiteImportWaveOwed","owed","aiSiteImportWaveIsGenerative","planned","aiSiteImportWaveCreditRange","aiSiteImportRemainingCreditRange","aiSiteImportQuoteText","range","runs","what","aiSiteImportPagesText","unshift","AI_SITE_IMPORT_LEFT_OUT_COPY","robots","unreadable","duplicate","missing","aiSiteImportWaveMessage","reviewing","done"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAgC2C,GAE3C,SAASA,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,YAAY,QAAQ,mDAAkD;AAE/E,SAASC,oBAAoB,EAAEC,iBAAiB,EAAEC,0BAA0B,EAAEC,6BAA6B,QAA4B,0BAAsB;AAC7J,SAASC,wBAAwB,QAAQ,wBAAoB;AAG7D,kBAAkB,GAClB,OAAO,MAAMC,sBAAsB,SAAiB;AAEpD,0DAA0D,GAC1D,OAAO,MAAMC,8BAA8B,SAAQ;AAEnD,uCAAuC,GACvC,OAAO,MAAMC,4BAA4B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