@aglyn/plugins-ai 1.15.0 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-site-import-start.component.js +3 -1
  3. package/src/lib/components/ai-site-import-start.component.js.map +1 -1
  4. package/src/lib/jobs/ai-job-import-step.d.ts +18 -2
  5. package/src/lib/jobs/ai-job-import-step.js +24 -8
  6. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  7. package/src/lib/jobs/ai-job-page-language.d.ts +2 -0
  8. package/src/lib/jobs/ai-job-page-language.js +72 -37
  9. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  10. package/src/lib/jobs/ai-job-page-step.js +5 -3
  11. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  12. package/src/lib/jobs/ai-job-text-step.d.ts +1 -0
  13. package/src/lib/jobs/ai-job-text-step.js.map +1 -1
  14. package/src/lib/jobs/ai-site-import-compile.js +26 -1
  15. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  16. package/src/lib/jobs/ai-site-import-improve.d.ts +59 -6
  17. package/src/lib/jobs/ai-site-import-improve.js +149 -19
  18. package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
  19. package/src/lib/jobs/ai-site-import-plan.js +1 -1
  20. package/src/lib/jobs/ai-site-import-plan.js.map +1 -1
  21. package/src/lib/model/ai-credit-estimate.d.ts +16 -0
  22. package/src/lib/model/ai-credit-estimate.js +14 -0
  23. package/src/lib/model/ai-credit-estimate.js.map +1 -1
  24. package/src/lib/model/ai-site-import-fidelity.d.ts +2 -0
  25. package/src/lib/model/ai-site-import-fidelity.js +7 -1
  26. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  27. package/src/lib/model/ai-site-import-view.d.ts +3 -1
  28. package/src/lib/model/ai-site-import-view.js +8 -3
  29. package/src/lib/model/ai-site-import-view.js.map +1 -1
  30. package/src/lib/model/ai-site-import.d.ts +27 -2
  31. package/src/lib/model/ai-site-import.js +63 -14
  32. package/src/lib/model/ai-site-import.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-plan.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 * IMPROVE IT, GENERATIVE: THE SITE PLANNED ONCE (AGL-4152).\n *\n * A page redesigned on its own cannot reorganize a site. So before anything of\n * it is built, one `submit_site_plan` answer reads what the first wave read and\n * says what the site is, how its menu and footer are organized, where the\n * header's main button goes, how the whole site is drawn, and at most one new\n * page. Every wave's pages are then drawn to it, by code:\n *\n * - the header and footer from `plan.nav`, with no model\n * (`aiSiteImportFrameSource`);\n * - each page's hero, groups, rhythm and closing band from `plan.design`\n * (`aiLayoutDesignChoices`), so the site reads as one design.\n *\n * The answer is held here: every page it names is a real page or the one it\n * proposes, its main button goes somewhere real, nothing the old menu reached\n * is left unreachable, and its words go through the honesty validator. An answer\n * that misses twice, or is refused, is no plan: the import's own frame and\n * design inputs stand, and its page says so.\n *\n * Nothing here runs with the flag off, or for Keep my site.\n *=========================================*/\n\nimport { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from '@aglyn/shared-util-tools/untrusted-text'\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport { AI_SITE_IMPORT_PAGE_ROLES, AI_SITE_IMPORT_PROPOSED_PAGE, aiSiteImportPageIsLegal, type AiSiteImportPage, type AiSiteImportPageRole, type AiSiteImportPlan, type AiSiteImportPlanDesign, type AiSiteImportState } from '../model/ai-site-import'\nimport { AI_SITE_KINDS } from '../model/ai-site-kinds'\nimport type { AiSystemBlock, AiTool } from '../providers/contract'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport type { AiGenerationCheck, AiValidatedGeneration } from '../runtime/ai-doctrine'\nimport { runValidatedGeneration } from '../runtime/ai-doctrine'\nimport type { AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { aiGenerationMaxTokensWithin, aiJobStepBudget } from './ai-job-budget'\nimport { AI_LAYOUT_LANGUAGE_THINKING } from './ai-job-page-language'\nimport { AI_SITE_IMPORT_DROPPED_ITEM_CODE, AI_SITE_IMPORT_INVENTED_FACT_CODE, aiSiteImportHonestyFacts, aiSiteImportInventedIn } from './ai-site-import-honesty'\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** The answer's kind of generation: the name its re-ask and its doctrine scope go by. */\nexport const AI_SITE_IMPORT_PLAN_KIND = 'site-import-plan'\n\n/** The heroes a plan may choose: those a page brought in can draw from one picture. */\nexport const AI_SITE_IMPORT_PLAN_HEROES = ['cover', 'poster', 'split', 'bleed', 'editorial', 'column', 'panel'] as const satisfies ReadonlyArray<AiSiteImportPlanDesign['hero']>\n\n/** The most top-level entries a planned menu holds: more reads as no plan at all. */\nexport const AI_SITE_IMPORT_PLAN_MAX_GROUPS = 6\n\n/** The most characters a menu's label holds, a heading of the footer, or the main button's. */\nexport const AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS = 28\n\n/** The most characters a proposed page's title holds: its search listing's ceiling. */\nexport const AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS = 60\n\nconst GROUP_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['label', 'pages'],\n properties: { label: { type: 'string' }, pages: { type: 'array', items: { type: 'string' } } },\n} as const\n\n/** The plan's tool: strict, every field always written. */\nexport const AI_SITE_IMPORT_PLAN_TOOL: AiTool = {\n name: 'submit_site_plan',\n description: 'Submit the plan of the new site: what it is, its menu and footer, how it is drawn, and at most one new page.',\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['site', 'nav', 'design', 'proposed', 'roles'],\n properties: {\n site: {\n type: 'object',\n additionalProperties: false,\n required: ['what', 'audience', 'kind', 'voice'],\n properties: {\n what: { type: 'string' },\n audience: { type: 'string' },\n kind: { type: 'string', enum: AI_SITE_KINDS.map((kind) => kind.id) },\n voice: { type: 'string' },\n },\n },\n nav: {\n type: 'object',\n additionalProperties: false,\n required: ['groups', 'cta', 'footer'],\n properties: {\n groups: { type: 'array', items: GROUP_SCHEMA },\n cta: {\n type: 'object',\n additionalProperties: false,\n required: ['label', 'target'],\n properties: { label: { type: 'string' }, target: { type: 'string' } },\n },\n footer: { type: 'array', items: GROUP_SCHEMA },\n },\n },\n design: {\n type: 'object',\n additionalProperties: false,\n required: ['hero', 'group', 'rhythm', 'cta'],\n properties: {\n hero: { type: 'string', enum: [...AI_SITE_IMPORT_PLAN_HEROES] },\n group: { type: 'string', enum: ['cards', 'ruled', 'icons'] },\n rhythm: { type: 'string', enum: ['alternate', 'plain'] },\n cta: { type: 'string', enum: ['band', 'photo'] },\n },\n },\n proposed: {\n type: 'object',\n additionalProperties: false,\n required: ['title', 'slug', 'purpose'],\n properties: { title: { type: 'string' }, slug: { type: 'string' }, purpose: { type: 'string' } },\n },\n roles: {\n type: 'array',\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['page', 'role'],\n properties: { page: { type: 'string' }, role: { type: 'string', enum: [...AI_SITE_IMPORT_PAGE_ROLES] } },\n },\n },\n },\n },\n}\n\n/** What a plan is told, cached: every site shares these bytes. */\nexport const AI_SITE_IMPORT_PLAN_TEXT = [\n \"You plan the new website of a small business from what its existing website says. You are its information architect and art director: a visitor should find what they came for in one or two clicks, and the whole site should read as one confident design. The site's old menu is often just its pages in the order they were made. Reorganize it around what a visitor of this kind of business looks for. Answer with submit_site_plan.\",\n '',\n 'site: what is one plain sentence saying what the business does; audience is one short phrase saying who it serves; kind is the kind of site this is; voice is a few plain words on how its writing sounds.',\n '',\n 'nav: the menu, the header\\'s main button and the footer.',\n `- groups are the menu, at most ${AI_SITE_IMPORT_PLAN_MAX_GROUPS} top-level entries, in the order a visitor needs them. An entry with one page is a link under that label; an entry with several is a menu of them under the label. Pages are named by id, as the page list gives them. Group like pages under a clear label rather than listing them all; never put the home page in the menu, since the logo goes home.`,\n '- Every page the page list marks \"in the menu\" must stay reachable: in the menu or the footer. A policy page belongs in the footer.',\n '- cta is the header\\'s one filled button: the one thing a visitor of this business most wants to do. label is its words; target is a page by id, form for the page holding the site\\'s form, or phone for the phone number the site gives. Only what the page list says exists.',\n '- The page the main button goes to is never also a menu entry of its own: the button is its link. Put it in the footer.',\n '- footer is its columns, each a short heading over the pages it links: two to four where there are pages enough, and one where the site has two or three pages, so the footer is never empty.',\n `- Every label is short, at most ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters, plain and in sentence case, so a capital reads as a name.`,\n '',\n 'design: how every page of the site is drawn, chosen once for the whole site from what it is and what it shows. hero: cover, a full-bleed photo with the words over it; poster, the same, taller and centered; split, the words beside a tall photo; bleed, half the band a photo; editorial, display type over a wide photo; column, a centered masthead over a photo; panel, the words on a card over a photo. Choose a photo-led hero only where the site has photos worth it. group: how a set of services or reasons is drawn: cards, ruled columns, or icons. rhythm: alternate grounds between sections, or plain, one ground with space between. cta: the closing call to action on a strong band, or over a photo.',\n '',\n `roles: what each page of the list is for in the new site, by id, one of ${AI_SITE_IMPORT_PAGE_ROLES.join(', ')}: home for the home page; service for a page about what the business offers; contact for a page whose purpose is reaching it or booking; other where none fits. Every page redesigns to its role, so name each one.`,\n '',\n 'proposed: at most one new page the site lacks and a visitor of this kind of business looks for, such as common questions or how it works, named new in the menu or footer wherever it belongs. Propose one only where the request says there is room, and only what you can write without inventing a fact. title is at most 60 characters; slug is its address in lowercase words and hyphens; purpose is one sentence on what it tells a visitor. No page to propose: write all three as \"\".',\n '',\n 'Never write a name, number, price, date, testimonial, client, award, credential, address or guarantee the site does not give.',\n].join('\\n')\n\n/** A plan's system blocks: the platform's text, cached across sites. The site's own words ride the user turn. */\nexport function aiSiteImportPlanInstructions(): readonly AiSystemBlock[] {\n return [{ text: UNTRUSTED_TEXT_RULE }, { text: AI_SITE_IMPORT_PLAN_TEXT, cacheBreakpoint: true }]\n}\n\n/*------------------------------------------\n * What the answer is told\n *-----------------------------------------*/\n\n/** The most characters of a site's own words the answer is told, about the site and about its pages. */\nconst SITE_MAX_CHARS = 6_000\nconst PAGES_MAX_CHARS = 12_000\n/** The headings a page's line names. */\nconst HEADINGS_PER_PAGE = 8\n\n/** What one page tells the plan: its id, title, address, words and headings, and what it holds. */\nfunction pageLine(page: AiSiteImportPage, required: ReadonlySet<string>): string {\n const blocks = page.read?.blocks ?? []\n const headings = blocks.flatMap((block) => (block.kind === 'heading' && block.text.trim() ? [clean(block.text)] : [])).slice(0, HEADINGS_PER_PAGE)\n const marks = [\n ...(required.has(page.draftId) ? ['in the menu'] : []),\n ...(page.read?.forms?.length ? ['holds a form'] : []),\n ...(aiSiteImportPageIsLegal(page) ? ['a policy'] : []),\n ...(page.group !== 'main' ? [`in ${page.group}`] : []),\n ]\n return `${page.draftId} | ${page.slug === '/' ? 'home' : `/${page.slug}`} | ${clean(page.title)} | ${(page.read?.words ?? page.words).toLocaleString('en-US')} words${marks.length ? ` | ${marks.join(', ')}` : ''}${headings.length ? ` | headings: ${headings.join('; ')}` : ''}`\n}\n\n/** The pages a plan may name: every page the import brings in and can link. */\nexport function aiSiteImportPlanPages(state: Pick<AiSiteImportState, 'pages'>): AiSiteImportPage[] {\n return state.pages.filter((page) => !page.refused)\n}\n\n/** A plan's user turn: what the site says of itself and its pages, fenced as the owner's data, and whether there is room for a new page. */\nexport function aiSiteImportPlanPrompt(input: { state: Pick<AiSiteImportState, 'pages' | 'home' | 'siteName' | 'domain'>; required: readonly string[]; roomForPage: boolean }): string {\n const { state } = input\n const home = state.home ?? null\n const required = new Set(input.required)\n const phones = home?.facts.phones ?? []\n const said = [\n `Name: ${clean(home?.siteName) || clean(state.siteName)}`,\n home?.title ? `Title: ${clean(home.title)}` : '',\n home?.description ? `Description: ${clean(home.description)}` : '',\n ...(home?.facts.lines ?? []),\n phones.length ? `Phone: ${phones[0]}` : '',\n ].filter(Boolean)\n return [\n fenceUntrustedText(`What ${state.domain} says of itself`, said.join('\\n'), { maxChars: SITE_MAX_CHARS }),\n 'The page list, one a line: id | address | title | words | what it holds | headings.',\n fenceUntrustedText('The pages', aiSiteImportPlanPages(state).map((page) => pageLine(page, required)).join('\\n'), { maxChars: PAGES_MAX_CHARS }),\n input.roomForPage ? 'There is room for one new page.' : 'There is no room for a new page: write proposed as \"\".',\n phones.length ? 'The site gives a phone number.' : 'The site gives no phone number: target may not be phone.',\n ].join('\\n')\n}\n\n/*------------------------------------------\n * The answer held\n *-----------------------------------------*/\n\nconst SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/\n\nconst invented = (message: string): AiDoctrineViolation => ({ rule: 14, code: AI_SITE_IMPORT_INVENTED_FACT_CODE, message })\nconst dropped = (message: string): AiDoctrineViolation => ({ rule: null, code: AI_SITE_IMPORT_DROPPED_ITEM_CODE, message })\nconst unusable = (message: string): AiDoctrineViolation => ({ rule: null, code: 'site-plan-unusable', message })\n\nconst record = (value: unknown): Record<string, unknown> => (value && typeof value === 'object' ? (value as Record<string, unknown>) : {})\n\n/** A list of groups, as an answer gives them. */\nfunction groupsOf(value: unknown): Array<{ label: string; pages: string[] }> {\n return (Array.isArray(value) ? value : []).map((entry) => {\n const group = record(entry)\n return { label: clean(group['label']), pages: (Array.isArray(group['pages']) ? group['pages'] : []).map(clean).filter(Boolean) }\n })\n}\n\n/** What a plan is held to. */\nexport interface AiSiteImportPlanScope {\n state: Pick<AiSiteImportState, 'pages' | 'home' | 'siteName'>\n /** Every line the import read of the site: what its words may say. */\n scope: readonly string[]\n /** The pages the old menu reached, which must stay reachable. */\n required: readonly string[]\n roomForPage: boolean\n}\n\n/** Every line of a site's first wave a plan's words are held to, with the page's own titles. */\nexport function aiSiteImportPlanScopeLines(state: Pick<AiSiteImportState, 'pages'>, siteLines: readonly string[]): string[] {\n const read = state.pages.flatMap((page) => [page.title, ...(page.read?.blocks ?? []).flatMap((block) => (block.kind === 'image' ? [] : block.text.trim() ? [block.text] : []))])\n return [...siteLines, ...read].map(clean).filter(Boolean)\n}\n\n/**\n * A plan's answer read and held (AGL-4152): a plan to store, or what it broke,\n * each named for the one re-ask. Its words are the honesty validator's: no name\n * or fact the site does not give, in any label or line.\n */\nexport function aiSiteImportPlanRead(raw: unknown, input: AiSiteImportPlanScope): { plan: AiSiteImportPlan | null; violations: AiDoctrineViolation[] } {\n const answer = record(raw)\n const site = record(answer['site'])\n const nav = record(answer['nav'])\n const cta = record(nav['cta'])\n const design = record(answer['design'])\n const proposedRaw = record(answer['proposed'])\n const groups = groupsOf(nav['groups'])\n const footer = groupsOf(nav['footer'])\n const out: AiDoctrineViolation[] = []\n const pages = aiSiteImportPlanPages(input.state)\n const ids = new Set(pages.map((page) => page.draftId))\n const homeIds = new Set(pages.filter((page) => page.slug === '/').map((page) => page.draftId))\n\n const title = clean(proposedRaw['title'])\n const slug = clean(proposedRaw['slug'])\n const purpose = clean(proposedRaw['purpose'])\n const proposes = !!(title || slug || purpose)\n if (proposes) {\n if (!input.roomForPage) out.push(unusable('proposed: there is no room for a new page on this plan. Write title, slug and purpose as \"\".'))\n if (!title || !purpose) out.push(unusable('proposed: a new page needs its title and its purpose, or all three written as \"\".'))\n if (title.length > AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS) out.push(unusable(`proposed: its title is over ${AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS} characters.`))\n if (!SLUG.test(slug)) out.push(unusable('proposed: its slug is lowercase words and hyphens only.'))\n else if (pages.some((page) => page.slug === slug || page.path.replace(/^\\/+|\\/+$/g, '') === slug)) out.push(unusable(`proposed: /${slug} is already a page of this site. Choose another address, or propose no page.`))\n if (pages.some((page) => clean(page.title).toLowerCase() === title.toLowerCase())) out.push(unusable(`proposed: \"${title.slice(0, 60)}\" is already a page of this site.`))\n }\n\n const entry = (name: string, page: string) => {\n if (page === AI_SITE_IMPORT_PROPOSED_PAGE) {\n if (!proposes) out.push(unusable(`${name}: it names the new page, and proposed is empty.`))\n } else if (!ids.has(page)) out.push(unusable(`${name}: \"${page.slice(0, 40)}\" is not a page of this site. Name pages by the ids the page list gives.`))\n }\n if (!groups.length) out.push(unusable('nav.groups: a menu needs at least one entry.'))\n if (groups.length > AI_SITE_IMPORT_PLAN_MAX_GROUPS) out.push(unusable(`nav.groups: at most ${AI_SITE_IMPORT_PLAN_MAX_GROUPS} top-level entries.`))\n for (const [where, list] of [['nav.groups', groups], ['nav.footer', footer]] as const) {\n list.forEach((group, index) => {\n const name = `${where}[${index}]`\n if (!group.label) out.push(unusable(`${name}: it needs a label.`))\n if (group.label.length > AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS) out.push(unusable(`${name}: \"${group.label.slice(0, 40)}\" is over ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters.`))\n if (!group.pages.length) out.push(unusable(`${name}: it links no page.`))\n for (const page of group.pages) entry(name, page)\n })\n }\n groups.forEach((group, index) => {\n if (group.pages.some((page) => homeIds.has(page))) out.push(unusable(`nav.groups[${index}]: the home page is not in the menu: the logo goes home.`))\n })\n const placed = new Set([...groups, ...footer].flatMap((group) => group.pages))\n for (const page of input.required) {\n if (!placed.has(page) && !homeIds.has(page)) {\n const named = pages.find((other) => other.draftId === page)?.title ?? page\n out.push(dropped(`\"${named.slice(0, 60)}\" is in the old menu and nowhere in the new one. Put it in the menu or the footer.`))\n }\n }\n if (proposes && !placed.has(AI_SITE_IMPORT_PROPOSED_PAGE)) out.push(dropped('The new page is linked from nowhere. Put new in the menu or the footer.'))\n\n // The header's one filled button goes somewhere real.\n const ctaLabel = clean(cta['label'])\n const target = clean(cta['target'])\n let ctaPage: string | undefined\n if (!ctaLabel || !target) out.push(unusable('nav.cta: the header needs its main button, with its words and where it goes.'))\n else {\n if (ctaLabel.length > AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS) out.push(unusable(`nav.cta: \"${ctaLabel.slice(0, 40)}\" is over ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters.`))\n if (target === 'form') {\n ctaPage = pages.find((page) => page.read?.forms?.some((form) => form.fields.length))?.draftId\n if (!ctaPage) out.push(unusable('nav.cta: no page of this site holds a form. Send the button to a page, or to phone.'))\n } else if (target === 'phone') {\n if (!input.state.home?.facts.phones.length) out.push(unusable('nav.cta: the site gives no phone number. Send the button to a page.'))\n } else if (target !== AI_SITE_IMPORT_PROPOSED_PAGE || !proposes) entry('nav.cta', target)\n }\n\n const kind = clean(site['kind'])\n if (!AI_SITE_KINDS.some((entry) => entry.id === kind)) out.push(unusable('site.kind: one of the kinds the tool lists.'))\n const what = clean(site['what'])\n const audience = clean(site['audience'])\n if (!what || !audience) out.push(unusable('site: what and audience are each a line, never empty.'))\n const hero = AI_SITE_IMPORT_PLAN_HEROES.find((value) => value === design['hero'])\n const group = (['cards', 'ruled', 'icons'] as const).find((value) => value === design['group'])\n const rhythm = (['alternate', 'plain'] as const).find((value) => value === design['rhythm'])\n const closing = (['band', 'photo'] as const).find((value) => value === design['cta'])\n if (!hero || !group || !rhythm || !closing) out.push(unusable('design: hero, group, rhythm and cta are each one of the values the tool lists.'))\n\n // Every word held to what the site says.\n const held = aiSiteImportHonestyFacts(input.scope)\n const contacts = input.scope.join(' \\n ')\n const lines = [\n ['site.what', what],\n ['site.audience', audience],\n ['site.voice', clean(site['voice'])],\n ['nav.cta', ctaLabel],\n ...groups.map((entry, index) => [`nav.groups[${index}]`, entry.label] as const),\n ...footer.map((entry, index) => [`nav.footer[${index}]`, entry.label] as const),\n ['proposed.title', title],\n ['proposed.purpose', purpose],\n ] as const\n for (const [where, text] of lines) {\n if (!text) continue\n const reason = aiSiteImportInventedIn(text, held)\n if (reason) out.push(invented(`${where}, \"${text.slice(0, 80)}\": ${reason}`))\n else if (aiLayoutGuardContacts(text, contacts) !== text) out.push(invented(`${where}, \"${text.slice(0, 80)}\": it gives a phone number or email the site does not.`))\n }\n if (out.length || !hero || !group || !rhythm || !closing) return { plan: null, violations: out }\n // What each page is for (AGL-4152): a role it does not know, or a page that is none of the site's, is left to the page.\n const roles: Record<string, AiSiteImportPageRole> = {}\n for (const entry of Array.isArray(answer['roles']) ? answer['roles'] : []) {\n const named = record(entry)\n const page = clean(named['page'])\n const role = AI_SITE_IMPORT_PAGE_ROLES.find((value) => value === named['role'])\n if (role && (ids.has(page) || (page === AI_SITE_IMPORT_PROPOSED_PAGE && proposes))) roles[page] = role\n }\n return {\n plan: {\n site: { what, audience, kind, voice: clean(site['voice']) },\n nav: { groups, primaryCta: { label: ctaLabel, target, ...(ctaPage ? { page: ctaPage } : {}) }, footer },\n design: { hero, group, rhythm, cta: closing },\n proposed: proposes ? { title, slug, purpose, on: true } : null,\n ...(Object.keys(roles).length ? { roles } : {}),\n },\n violations: [],\n }\n}\n\n/** A plan's check, answer by answer, for the one re-ask. */\nexport function aiSiteImportPlanCheck(input: AiSiteImportPlanScope): AiGenerationCheck<AiSiteImportPlan> {\n return (answer) => {\n const { plan, violations } = aiSiteImportPlanRead(answer, input)\n return plan ? { value: plan, violations: [] } : { value: null, violations }\n }\n}\n\n/*------------------------------------------\n * The answer asked\n *-----------------------------------------*/\n\n/** The most tokens a plan's answer asks, with its thinking. */\nexport const AI_SITE_IMPORT_PLAN_MOST_TOKENS = 4_000\n\n/** The least time a plan's pass needs: its answer and its one re-ask on the page step's tier. */\nexport const AI_SITE_IMPORT_PLAN_BUDGET = aiJobStepBudget({ tier: AI_STEP_TIERS['job.page'], maxTokens: AI_SITE_IMPORT_PLAN_MOST_TOKENS })\n\n/** The ceiling a plan is asked at on this model. */\nexport function aiSiteImportPlanMaxTokens(model: string): number {\n return aiGenerationMaxTokensWithin({ model, budgetMs: AI_SITE_IMPORT_PLAN_BUDGET.minimumMs, cap: AI_SITE_IMPORT_PLAN_MOST_TOKENS, lookups: 0 })\n}\n\n/** The one plan a generative Improve it asks for, on the page step's tier. */\nexport async function aiRunSiteImportPlan(input: AiSiteImportPlanScope & { state: Pick<AiSiteImportState, 'pages' | 'home' | 'siteName' | 'domain'>; model: string; signal?: AbortSignal }): Promise<AiValidatedGeneration<AiSiteImportPlan>> {\n return runValidatedGeneration<AiSiteImportPlan>(AI_SITE_IMPORT_PLAN_KIND, {\n step: 'job.page',\n model: input.model,\n instructions: aiSiteImportPlanInstructions(),\n messages: [{ role: 'user', content: aiSiteImportPlanPrompt({ state: input.state, required: input.required, roomForPage: input.roomForPage }) }],\n tool: AI_SITE_IMPORT_PLAN_TOOL,\n maxTokens: aiSiteImportPlanMaxTokens(input.model),\n cutOff: { noun: 'plan', smaller: 'Write shorter lines.' },\n ...AI_LAYOUT_LANGUAGE_THINKING,\n check: aiSiteImportPlanCheck(input),\n ...(input.signal ? { signal: input.signal } : {}),\n })\n}\n"],"names":["fenceUntrustedText","UNTRUSTED_TEXT_RULE","aiLayoutGuardContacts","AI_SITE_IMPORT_PAGE_ROLES","AI_SITE_IMPORT_PROPOSED_PAGE","aiSiteImportPageIsLegal","AI_SITE_KINDS","AI_STEP_TIERS","runValidatedGeneration","aiGenerationMaxTokensWithin","aiJobStepBudget","AI_LAYOUT_LANGUAGE_THINKING","AI_SITE_IMPORT_DROPPED_ITEM_CODE","AI_SITE_IMPORT_INVENTED_FACT_CODE","aiSiteImportHonestyFacts","aiSiteImportInventedIn","clean","text","replace","trim","AI_SITE_IMPORT_PLAN_KIND","AI_SITE_IMPORT_PLAN_HEROES","AI_SITE_IMPORT_PLAN_MAX_GROUPS","AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS","AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS","GROUP_SCHEMA","type","additionalProperties","required","properties","label","pages","items","AI_SITE_IMPORT_PLAN_TOOL","name","description","strict","inputSchema","site","what","audience","kind","enum","map","id","voice","nav","groups","cta","target","footer","design","hero","group","rhythm","proposed","title","slug","purpose","roles","page","role","AI_SITE_IMPORT_PLAN_TEXT","join","aiSiteImportPlanInstructions","cacheBreakpoint","SITE_MAX_CHARS","PAGES_MAX_CHARS","HEADINGS_PER_PAGE","pageLine","blocks","read","headings","flatMap","block","slice","marks","has","draftId","forms","length","words","toLocaleString","aiSiteImportPlanPages","state","filter","refused","aiSiteImportPlanPrompt","input","home","Set","phones","facts","said","siteName","lines","Boolean","domain","maxChars","roomForPage","SLUG","invented","message","rule","code","dropped","unusable","record","value","groupsOf","Array","isArray","entry","aiSiteImportPlanScopeLines","siteLines","aiSiteImportPlanRead","raw","answer","proposedRaw","out","ids","homeIds","proposes","push","test","some","path","toLowerCase","where","list","forEach","index","placed","named","find","other","ctaLabel","ctaPage","form","fields","closing","held","scope","contacts","reason","plan","violations","primaryCta","on","Object","keys","aiSiteImportPlanCheck","AI_SITE_IMPORT_PLAN_MOST_TOKENS","AI_SITE_IMPORT_PLAN_BUDGET","tier","maxTokens","aiSiteImportPlanMaxTokens","model","budgetMs","minimumMs","cap","lookups","aiRunSiteImportPlan","step","instructions","messages","content","tool","cutOff","noun","smaller","check","signal"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;2CAqB2C,GAE3C,SAASA,kBAAkB,EAAEC,mBAAmB,QAAQ,0CAAyC;AACjG,SAASC,qBAAqB,QAAQ,uCAAmC;AACzE,SAASC,yBAAyB,EAAEC,4BAA4B,EAAEC,uBAAuB,QAAsI,6BAAyB;AACxP,SAASC,aAAa,QAAQ,4BAAwB;AAEtD,SAASC,aAAa,QAAQ,0BAAsB;AAEpD,SAASC,sBAAsB,QAAQ,4BAAwB;AAE/D,SAASC,2BAA2B,EAAEC,eAAe,QAAQ,qBAAiB;AAC9E,SAASC,2BAA2B,QAAQ,4BAAwB;AACpE,SAASC,gCAAgC,EAAEC,iC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IACrD,OAAOpJ,4BAA4B;QAAEoJ;QAAOC,UAAUL,2BAA2BM,SAAS;QAAEC,KAAKR;QAAiCS,SAAS;IAAE;AAC/I;AAEA,4EAA4E,GAC5E,OAAO,eAAeC,oBAAoB1E,KAAgJ;IACxL,OAAOhF,uBAAyCY,0BAA0B;QACxE+I,MAAM;QACNN,OAAOrE,MAAMqE,KAAK;QAClBO,cAAcpG;QACdqG,UAAU;YAAC;gBAAExG,MAAM;gBAAQyG,SAAS/E,uBAAuB;oBAAEH,OAAOI,MAAMJ,KAAK;oBAAExD,UAAU4D,MAAM5D,QAAQ;oBAAEuE,aAAaX,MAAMW,WAAW;gBAAC;YAAG;SAAE;QAC/IoE,MAAMtI;QACN0H,WAAWC,0BAA0BpE,MAAMqE,KAAK;QAChDW,QAAQ;YAAEC,MAAM;YAAQC,SAAS;QAAuB;OACrD/J;QACHgK,OAAOpB,sBAAsB/D;OACzBA,MAAMoF,MAAM,GAAG;QAAEA,QAAQpF,MAAMoF,MAAM;IAAC,IAAI,CAAC;AAEnD"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-plan.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 * IMPROVE IT, GENERATIVE: THE SITE PLANNED ONCE (AGL-4152).\n *\n * A page redesigned on its own cannot reorganize a site. So before anything of\n * it is built, one `submit_site_plan` answer reads what the first wave read and\n * says what the site is, how its menu and footer are organized, where the\n * header's main button goes, how the whole site is drawn, and at most one new\n * page. Every wave's pages are then drawn to it, by code:\n *\n * - the header and footer from `plan.nav`, with no model\n * (`aiSiteImportFrameSource`);\n * - each page's hero, groups, rhythm and closing band from `plan.design`\n * (`aiLayoutDesignChoices`), so the site reads as one design.\n *\n * The answer is held here: every page it names is a real page or the one it\n * proposes, its main button goes somewhere real, nothing the old menu reached\n * is left unreachable, and its words go through the honesty validator. An answer\n * that misses twice, or is refused, is no plan: the import's own frame and\n * design inputs stand, and its page says so.\n *\n * Nothing here runs with the flag off, or for Keep my site.\n *=========================================*/\n\nimport { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from '@aglyn/shared-util-tools/untrusted-text'\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport { AI_SITE_IMPORT_PAGE_ROLES, AI_SITE_IMPORT_PROPOSED_PAGE, aiSiteImportPageIsLegal, type AiSiteImportPage, type AiSiteImportPageRole, type AiSiteImportPlan, type AiSiteImportPlanDesign, type AiSiteImportState } from '../model/ai-site-import'\nimport { AI_SITE_KINDS } from '../model/ai-site-kinds'\nimport type { AiSystemBlock, AiTool } from '../providers/contract'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport type { AiGenerationCheck, AiValidatedGeneration } from '../runtime/ai-doctrine'\nimport { runValidatedGeneration } from '../runtime/ai-doctrine'\nimport type { AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { aiGenerationMaxTokensWithin, aiJobStepBudget } from './ai-job-budget'\nimport { AI_LAYOUT_LANGUAGE_THINKING } from './ai-job-page-language'\nimport { AI_SITE_IMPORT_DROPPED_ITEM_CODE, AI_SITE_IMPORT_INVENTED_FACT_CODE, aiSiteImportHonestyFacts, aiSiteImportInventedIn } from './ai-site-import-honesty'\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** The answer's kind of generation: the name its re-ask and its doctrine scope go by. */\nexport const AI_SITE_IMPORT_PLAN_KIND = 'site-import-plan'\n\n/** The heroes a plan may choose: those a page brought in can draw from one picture. */\nexport const AI_SITE_IMPORT_PLAN_HEROES = ['cover', 'poster', 'split', 'bleed', 'editorial', 'column', 'panel'] as const satisfies ReadonlyArray<AiSiteImportPlanDesign['hero']>\n\n/** The most top-level entries a planned menu holds: more reads as no plan at all. */\nexport const AI_SITE_IMPORT_PLAN_MAX_GROUPS = 6\n\n/** The most characters a menu's label holds, a heading of the footer, or the main button's. */\nexport const AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS = 28\n\n/** The most characters a proposed page's title holds: its search listing's ceiling. */\nexport const AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS = 60\n\nconst GROUP_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['label', 'pages'],\n properties: { label: { type: 'string' }, pages: { type: 'array', items: { type: 'string' } } },\n} as const\n\n/** The plan's tool: strict, every field always written. */\nexport const AI_SITE_IMPORT_PLAN_TOOL: AiTool = {\n name: 'submit_site_plan',\n description: 'Submit the plan of the new site: what it is, its menu and footer, how it is drawn, and at most one new page.',\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['site', 'nav', 'design', 'proposed', 'roles'],\n properties: {\n site: {\n type: 'object',\n additionalProperties: false,\n required: ['what', 'audience', 'kind', 'voice'],\n properties: {\n what: { type: 'string' },\n audience: { type: 'string' },\n kind: { type: 'string', enum: AI_SITE_KINDS.map((kind) => kind.id) },\n voice: { type: 'string' },\n },\n },\n nav: {\n type: 'object',\n additionalProperties: false,\n required: ['groups', 'cta', 'footer'],\n properties: {\n groups: { type: 'array', items: GROUP_SCHEMA },\n cta: {\n type: 'object',\n additionalProperties: false,\n required: ['label', 'target'],\n properties: { label: { type: 'string' }, target: { type: 'string' } },\n },\n footer: { type: 'array', items: GROUP_SCHEMA },\n },\n },\n design: {\n type: 'object',\n additionalProperties: false,\n required: ['hero', 'group', 'rhythm', 'cta'],\n properties: {\n hero: { type: 'string', enum: [...AI_SITE_IMPORT_PLAN_HEROES] },\n group: { type: 'string', enum: ['cards', 'ruled', 'icons'] },\n rhythm: { type: 'string', enum: ['alternate', 'plain'] },\n cta: { type: 'string', enum: ['band', 'photo'] },\n },\n },\n proposed: {\n type: 'object',\n additionalProperties: false,\n required: ['title', 'slug', 'purpose'],\n properties: { title: { type: 'string' }, slug: { type: 'string' }, purpose: { type: 'string' } },\n },\n roles: {\n type: 'array',\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['page', 'role'],\n properties: { page: { type: 'string' }, role: { type: 'string', enum: [...AI_SITE_IMPORT_PAGE_ROLES] } },\n },\n },\n },\n },\n}\n\n/** What a plan is told, cached: every site shares these bytes. */\nexport const AI_SITE_IMPORT_PLAN_TEXT = [\n \"You plan the new website of a small business from what its existing website says. You are its information architect and art director: a visitor should find what they came for in one or two clicks, and the whole site should read as one confident design. The site's old menu is often just its pages in the order they were made. Reorganize it around what a visitor of this kind of business looks for. Answer with submit_site_plan.\",\n '',\n 'site: what is one plain sentence saying what the business does; audience is one short phrase saying who it serves; kind is the kind of site this is; voice is a few plain words on how its writing sounds.',\n '',\n 'nav: the menu, the header\\'s main button and the footer.',\n `- groups are the menu, at most ${AI_SITE_IMPORT_PLAN_MAX_GROUPS} top-level entries, in the order a visitor needs them. An entry with one page is a link under that label; an entry with several is a menu of them under the label. Pages are named by id, as the page list gives them. Group like pages under a clear label rather than listing them all; never put the home page in the menu, since the logo goes home.`,\n '- Every page the page list marks \"in the menu\" must stay reachable: in the menu or the footer. A policy page belongs in the footer.',\n '- cta is the header\\'s one filled button: the one thing a visitor of this business most wants to do. label is its words; target is a page by id, form for the page holding the site\\'s form, or phone for the phone number the site gives. Only what the page list says exists.',\n '- The page the main button goes to is never also a menu entry of its own: the button is its link. Put it in the footer.',\n '- footer is its columns, each a short heading over the pages it links: two to four where there are pages enough, and one where the site has two or three pages, so the footer is never empty.',\n `- Every label is short, at most ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters, plain and in sentence case, so a capital reads as a name.`,\n '',\n 'design: how every page of the site is drawn, chosen once for the whole site from what it is and what it shows. hero: cover, a full-bleed photo with the words over it; poster, the same, taller and centered; split, the words beside a tall photo; bleed, half the band a photo; editorial, display type with a wide photo boxed under it; column, the words centered in a narrow column with a photo boxed under them; panel, the words on a card over a photo. Where the site opens on a wide photo of its work, its place or its people, lay the words over it (cover, poster, panel) or beside it (split, bleed); keep editorial and column for a site with no such photo. Choose a photo-led hero only where the site has photos worth it. group: how a set of services or reasons is drawn: cards, ruled columns, or icons. rhythm: alternate grounds between sections, or plain, one ground with space between. cta: the closing call to action on a strong band, or over a photo.',\n '',\n `roles: what each page of the list is for in the new site, by id, one of ${AI_SITE_IMPORT_PAGE_ROLES.join(', ')}: home for the home page; service for a page about what the business offers; contact for a page whose purpose is reaching it or booking; other where none fits. Every page redesigns to its role, so name each one.`,\n '',\n 'proposed: at most one new page the site lacks and a visitor of this kind of business looks for, such as common questions or how it works, named new in the menu or footer wherever it belongs. Propose one only where the request says there is room, and only what you can write without inventing a fact. title is at most 60 characters; slug is its address in lowercase words and hyphens; purpose is one sentence on what it tells a visitor. No page to propose: write all three as \"\".',\n '',\n 'Never write a name, number, price, date, testimonial, client, award, credential, address or guarantee the site does not give.',\n].join('\\n')\n\n/** A plan's system blocks: the platform's text, cached across sites. The site's own words ride the user turn. */\nexport function aiSiteImportPlanInstructions(): readonly AiSystemBlock[] {\n return [{ text: UNTRUSTED_TEXT_RULE }, { text: AI_SITE_IMPORT_PLAN_TEXT, cacheBreakpoint: true }]\n}\n\n/*------------------------------------------\n * What the answer is told\n *-----------------------------------------*/\n\n/** The most characters of a site's own words the answer is told, about the site and about its pages. */\nconst SITE_MAX_CHARS = 6_000\nconst PAGES_MAX_CHARS = 12_000\n/** The headings a page's line names. */\nconst HEADINGS_PER_PAGE = 8\n\n/** What one page tells the plan: its id, title, address, words and headings, and what it holds. */\nfunction pageLine(page: AiSiteImportPage, required: ReadonlySet<string>): string {\n const blocks = page.read?.blocks ?? []\n const headings = blocks.flatMap((block) => (block.kind === 'heading' && block.text.trim() ? [clean(block.text)] : [])).slice(0, HEADINGS_PER_PAGE)\n const marks = [\n ...(required.has(page.draftId) ? ['in the menu'] : []),\n ...(page.read?.forms?.length ? ['holds a form'] : []),\n ...(aiSiteImportPageIsLegal(page) ? ['a policy'] : []),\n ...(page.group !== 'main' ? [`in ${page.group}`] : []),\n ]\n return `${page.draftId} | ${page.slug === '/' ? 'home' : `/${page.slug}`} | ${clean(page.title)} | ${(page.read?.words ?? page.words).toLocaleString('en-US')} words${marks.length ? ` | ${marks.join(', ')}` : ''}${headings.length ? ` | headings: ${headings.join('; ')}` : ''}`\n}\n\n/** The pages a plan may name: every page the import brings in and can link. */\nexport function aiSiteImportPlanPages(state: Pick<AiSiteImportState, 'pages'>): AiSiteImportPage[] {\n return state.pages.filter((page) => !page.refused)\n}\n\n/** A plan's user turn: what the site says of itself and its pages, fenced as the owner's data, and whether there is room for a new page. */\nexport function aiSiteImportPlanPrompt(input: { state: Pick<AiSiteImportState, 'pages' | 'home' | 'siteName' | 'domain'>; required: readonly string[]; roomForPage: boolean }): string {\n const { state } = input\n const home = state.home ?? null\n const required = new Set(input.required)\n const phones = home?.facts.phones ?? []\n const said = [\n `Name: ${clean(home?.siteName) || clean(state.siteName)}`,\n home?.title ? `Title: ${clean(home.title)}` : '',\n home?.description ? `Description: ${clean(home.description)}` : '',\n ...(home?.facts.lines ?? []),\n phones.length ? `Phone: ${phones[0]}` : '',\n ].filter(Boolean)\n return [\n fenceUntrustedText(`What ${state.domain} says of itself`, said.join('\\n'), { maxChars: SITE_MAX_CHARS }),\n 'The page list, one a line: id | address | title | words | what it holds | headings.',\n fenceUntrustedText('The pages', aiSiteImportPlanPages(state).map((page) => pageLine(page, required)).join('\\n'), { maxChars: PAGES_MAX_CHARS }),\n input.roomForPage ? 'There is room for one new page.' : 'There is no room for a new page: write proposed as \"\".',\n phones.length ? 'The site gives a phone number.' : 'The site gives no phone number: target may not be phone.',\n ].join('\\n')\n}\n\n/*------------------------------------------\n * The answer held\n *-----------------------------------------*/\n\nconst SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/\n\nconst invented = (message: string): AiDoctrineViolation => ({ rule: 14, code: AI_SITE_IMPORT_INVENTED_FACT_CODE, message })\nconst dropped = (message: string): AiDoctrineViolation => ({ rule: null, code: AI_SITE_IMPORT_DROPPED_ITEM_CODE, message })\nconst unusable = (message: string): AiDoctrineViolation => ({ rule: null, code: 'site-plan-unusable', message })\n\nconst record = (value: unknown): Record<string, unknown> => (value && typeof value === 'object' ? (value as Record<string, unknown>) : {})\n\n/** A list of groups, as an answer gives them. */\nfunction groupsOf(value: unknown): Array<{ label: string; pages: string[] }> {\n return (Array.isArray(value) ? value : []).map((entry) => {\n const group = record(entry)\n return { label: clean(group['label']), pages: (Array.isArray(group['pages']) ? group['pages'] : []).map(clean).filter(Boolean) }\n })\n}\n\n/** What a plan is held to. */\nexport interface AiSiteImportPlanScope {\n state: Pick<AiSiteImportState, 'pages' | 'home' | 'siteName'>\n /** Every line the import read of the site: what its words may say. */\n scope: readonly string[]\n /** The pages the old menu reached, which must stay reachable. */\n required: readonly string[]\n roomForPage: boolean\n}\n\n/** Every line of a site's first wave a plan's words are held to, with the page's own titles. */\nexport function aiSiteImportPlanScopeLines(state: Pick<AiSiteImportState, 'pages'>, siteLines: readonly string[]): string[] {\n const read = state.pages.flatMap((page) => [page.title, ...(page.read?.blocks ?? []).flatMap((block) => (block.kind === 'image' ? [] : block.text.trim() ? [block.text] : []))])\n return [...siteLines, ...read].map(clean).filter(Boolean)\n}\n\n/**\n * A plan's answer read and held (AGL-4152): a plan to store, or what it broke,\n * each named for the one re-ask. Its words are the honesty validator's: no name\n * or fact the site does not give, in any label or line.\n */\nexport function aiSiteImportPlanRead(raw: unknown, input: AiSiteImportPlanScope): { plan: AiSiteImportPlan | null; violations: AiDoctrineViolation[] } {\n const answer = record(raw)\n const site = record(answer['site'])\n const nav = record(answer['nav'])\n const cta = record(nav['cta'])\n const design = record(answer['design'])\n const proposedRaw = record(answer['proposed'])\n const groups = groupsOf(nav['groups'])\n const footer = groupsOf(nav['footer'])\n const out: AiDoctrineViolation[] = []\n const pages = aiSiteImportPlanPages(input.state)\n const ids = new Set(pages.map((page) => page.draftId))\n const homeIds = new Set(pages.filter((page) => page.slug === '/').map((page) => page.draftId))\n\n const title = clean(proposedRaw['title'])\n const slug = clean(proposedRaw['slug'])\n const purpose = clean(proposedRaw['purpose'])\n const proposes = !!(title || slug || purpose)\n if (proposes) {\n if (!input.roomForPage) out.push(unusable('proposed: there is no room for a new page on this plan. Write title, slug and purpose as \"\".'))\n if (!title || !purpose) out.push(unusable('proposed: a new page needs its title and its purpose, or all three written as \"\".'))\n if (title.length > AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS) out.push(unusable(`proposed: its title is over ${AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS} characters.`))\n if (!SLUG.test(slug)) out.push(unusable('proposed: its slug is lowercase words and hyphens only.'))\n else if (pages.some((page) => page.slug === slug || page.path.replace(/^\\/+|\\/+$/g, '') === slug)) out.push(unusable(`proposed: /${slug} is already a page of this site. Choose another address, or propose no page.`))\n if (pages.some((page) => clean(page.title).toLowerCase() === title.toLowerCase())) out.push(unusable(`proposed: \"${title.slice(0, 60)}\" is already a page of this site.`))\n }\n\n const entry = (name: string, page: string) => {\n if (page === AI_SITE_IMPORT_PROPOSED_PAGE) {\n if (!proposes) out.push(unusable(`${name}: it names the new page, and proposed is empty.`))\n } else if (!ids.has(page)) out.push(unusable(`${name}: \"${page.slice(0, 40)}\" is not a page of this site. Name pages by the ids the page list gives.`))\n }\n if (!groups.length) out.push(unusable('nav.groups: a menu needs at least one entry.'))\n if (groups.length > AI_SITE_IMPORT_PLAN_MAX_GROUPS) out.push(unusable(`nav.groups: at most ${AI_SITE_IMPORT_PLAN_MAX_GROUPS} top-level entries.`))\n for (const [where, list] of [['nav.groups', groups], ['nav.footer', footer]] as const) {\n list.forEach((group, index) => {\n const name = `${where}[${index}]`\n if (!group.label) out.push(unusable(`${name}: it needs a label.`))\n if (group.label.length > AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS) out.push(unusable(`${name}: \"${group.label.slice(0, 40)}\" is over ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters.`))\n if (!group.pages.length) out.push(unusable(`${name}: it links no page.`))\n for (const page of group.pages) entry(name, page)\n })\n }\n groups.forEach((group, index) => {\n if (group.pages.some((page) => homeIds.has(page))) out.push(unusable(`nav.groups[${index}]: the home page is not in the menu: the logo goes home.`))\n })\n const placed = new Set([...groups, ...footer].flatMap((group) => group.pages))\n for (const page of input.required) {\n if (!placed.has(page) && !homeIds.has(page)) {\n const named = pages.find((other) => other.draftId === page)?.title ?? page\n out.push(dropped(`\"${named.slice(0, 60)}\" is in the old menu and nowhere in the new one. Put it in the menu or the footer.`))\n }\n }\n if (proposes && !placed.has(AI_SITE_IMPORT_PROPOSED_PAGE)) out.push(dropped('The new page is linked from nowhere. Put new in the menu or the footer.'))\n\n // The header's one filled button goes somewhere real.\n const ctaLabel = clean(cta['label'])\n const target = clean(cta['target'])\n let ctaPage: string | undefined\n if (!ctaLabel || !target) out.push(unusable('nav.cta: the header needs its main button, with its words and where it goes.'))\n else {\n if (ctaLabel.length > AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS) out.push(unusable(`nav.cta: \"${ctaLabel.slice(0, 40)}\" is over ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters.`))\n if (target === 'form') {\n ctaPage = pages.find((page) => page.read?.forms?.some((form) => form.fields.length))?.draftId\n if (!ctaPage) out.push(unusable('nav.cta: no page of this site holds a form. Send the button to a page, or to phone.'))\n } else if (target === 'phone') {\n if (!input.state.home?.facts.phones.length) out.push(unusable('nav.cta: the site gives no phone number. Send the button to a page.'))\n } else if (target !== AI_SITE_IMPORT_PROPOSED_PAGE || !proposes) entry('nav.cta', target)\n }\n\n const kind = clean(site['kind'])\n if (!AI_SITE_KINDS.some((entry) => entry.id === kind)) out.push(unusable('site.kind: one of the kinds the tool lists.'))\n const what = clean(site['what'])\n const audience = clean(site['audience'])\n if (!what || !audience) out.push(unusable('site: what and audience are each a line, never empty.'))\n const hero = AI_SITE_IMPORT_PLAN_HEROES.find((value) => value === design['hero'])\n const group = (['cards', 'ruled', 'icons'] as const).find((value) => value === design['group'])\n const rhythm = (['alternate', 'plain'] as const).find((value) => value === design['rhythm'])\n const closing = (['band', 'photo'] as const).find((value) => value === design['cta'])\n if (!hero || !group || !rhythm || !closing) out.push(unusable('design: hero, group, rhythm and cta are each one of the values the tool lists.'))\n\n // Every word held to what the site says.\n const held = aiSiteImportHonestyFacts(input.scope)\n const contacts = input.scope.join(' \\n ')\n const lines = [\n ['site.what', what],\n ['site.audience', audience],\n ['site.voice', clean(site['voice'])],\n ['nav.cta', ctaLabel],\n ...groups.map((entry, index) => [`nav.groups[${index}]`, entry.label] as const),\n ...footer.map((entry, index) => [`nav.footer[${index}]`, entry.label] as const),\n ['proposed.title', title],\n ['proposed.purpose', purpose],\n ] as const\n for (const [where, text] of lines) {\n if (!text) continue\n const reason = aiSiteImportInventedIn(text, held)\n if (reason) out.push(invented(`${where}, \"${text.slice(0, 80)}\": ${reason}`))\n else if (aiLayoutGuardContacts(text, contacts) !== text) out.push(invented(`${where}, \"${text.slice(0, 80)}\": it gives a phone number or email the site does not.`))\n }\n if (out.length || !hero || !group || !rhythm || !closing) return { plan: null, violations: out }\n // What each page is for (AGL-4152): a role it does not know, or a page that is none of the site's, is left to the page.\n const roles: Record<string, AiSiteImportPageRole> = {}\n for (const entry of Array.isArray(answer['roles']) ? answer['roles'] : []) {\n const named = record(entry)\n const page = clean(named['page'])\n const role = AI_SITE_IMPORT_PAGE_ROLES.find((value) => value === named['role'])\n if (role && (ids.has(page) || (page === AI_SITE_IMPORT_PROPOSED_PAGE && proposes))) roles[page] = role\n }\n return {\n plan: {\n site: { what, audience, kind, voice: clean(site['voice']) },\n nav: { groups, primaryCta: { label: ctaLabel, target, ...(ctaPage ? { page: ctaPage } : {}) }, footer },\n design: { hero, group, rhythm, cta: closing },\n proposed: proposes ? { title, slug, purpose, on: true } : null,\n ...(Object.keys(roles).length ? { roles } : {}),\n },\n violations: [],\n }\n}\n\n/** A plan's check, answer by answer, for the one re-ask. */\nexport function aiSiteImportPlanCheck(input: AiSiteImportPlanScope): AiGenerationCheck<AiSiteImportPlan> {\n return (answer) => {\n const { plan, violations } = aiSiteImportPlanRead(answer, input)\n return plan ? { value: plan, violations: [] } : { value: null, violations }\n }\n}\n\n/*------------------------------------------\n * The answer asked\n *-----------------------------------------*/\n\n/** The most tokens a plan's answer asks, with its thinking. */\nexport const AI_SITE_IMPORT_PLAN_MOST_TOKENS = 4_000\n\n/** The least time a plan's pass needs: its answer and its one re-ask on the page step's tier. */\nexport const AI_SITE_IMPORT_PLAN_BUDGET = aiJobStepBudget({ tier: AI_STEP_TIERS['job.page'], maxTokens: AI_SITE_IMPORT_PLAN_MOST_TOKENS })\n\n/** The ceiling a plan is asked at on this model. */\nexport function aiSiteImportPlanMaxTokens(model: string): number {\n return aiGenerationMaxTokensWithin({ model, budgetMs: AI_SITE_IMPORT_PLAN_BUDGET.minimumMs, cap: AI_SITE_IMPORT_PLAN_MOST_TOKENS, lookups: 0 })\n}\n\n/** The one plan a generative Improve it asks for, on the page step's tier. */\nexport async function aiRunSiteImportPlan(input: AiSiteImportPlanScope & { state: Pick<AiSiteImportState, 'pages' | 'home' | 'siteName' | 'domain'>; model: string; signal?: AbortSignal }): Promise<AiValidatedGeneration<AiSiteImportPlan>> {\n return runValidatedGeneration<AiSiteImportPlan>(AI_SITE_IMPORT_PLAN_KIND, {\n step: 'job.page',\n model: input.model,\n instructions: aiSiteImportPlanInstructions(),\n messages: [{ role: 'user', content: aiSiteImportPlanPrompt({ state: input.state, required: input.required, roomForPage: input.roomForPage }) }],\n tool: AI_SITE_IMPORT_PLAN_TOOL,\n maxTokens: aiSiteImportPlanMaxTokens(input.model),\n cutOff: { noun: 'plan', smaller: 'Write shorter lines.' },\n ...AI_LAYOUT_LANGUAGE_THINKING,\n check: aiSiteImportPlanCheck(input),\n ...(input.signal ? { signal: input.signal } : {}),\n })\n}\n"],"names":["fenceUntrustedText","UNTRUSTED_TEXT_RULE","aiLayoutGuardContacts","AI_SITE_IMPORT_PAGE_ROLES","AI_SITE_IMPORT_PROPOSED_PAGE","aiSiteImportPageIsLegal","AI_SITE_KINDS","AI_STEP_TIERS","runValidatedGeneration","aiGenerationMaxTokensWithin","aiJobStepBudget","AI_LAYOUT_LANGUAGE_THINKING","AI_SITE_IMPORT_DROPPED_ITEM_CODE","AI_SITE_IMPORT_INVENTED_FACT_CODE","aiSiteImportHonestyFacts","aiSiteImportInventedIn","clean","text","replace","trim","AI_SITE_IMPORT_PLAN_KIND","AI_SITE_IMPORT_PLAN_HEROES","AI_SITE_IMPORT_PLAN_MAX_GROUPS","AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS","AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS","GROUP_SCHEMA","type","additionalProperties","required","properties","label","pages","items","AI_SITE_IMPORT_PLAN_TOOL","name","description","strict","inputSchema","site","what","audience","kind","enum","map","id","voice","nav","groups","cta","target","footer","design","hero","group","rhythm","proposed","title","slug","purpose","roles","page","role","AI_SITE_IMPORT_PLAN_TEXT","join","aiSiteImportPlanInstructions","cacheBreakpoint","SITE_MAX_CHARS","PAGES_MAX_CHARS","HEADINGS_PER_PAGE","pageLine","blocks","read","headings","flatMap","block","slice","marks","has","draftId","forms","length","words","toLocaleString","aiSiteImportPlanPages","state","filter","refused","aiSiteImportPlanPrompt","input","home","Set","phones","facts","said","siteName","lines","Boolean","domain","maxChars","roomForPage","SLUG","invented","message","rule","code","dropped","unusable","record","value","groupsOf","Array","isArray","entry","aiSiteImportPlanScopeLines","siteLines","aiSiteImportPlanRead","raw","answer","proposedRaw","out","ids","homeIds","proposes","push","test","some","path","toLowerCase","where","list","forEach","index","placed","named","find","other","ctaLabel","ctaPage","form","fields","closing","held","scope","contacts","reason","plan","violations","primaryCta","on","Object","keys","aiSiteImportPlanCheck","AI_SITE_IMPORT_PLAN_MOST_TOKENS","AI_SITE_IMPORT_PLAN_BUDGET","tier","maxTokens","aiSiteImportPlanMaxTokens","model","budgetMs","minimumMs","cap","lookups","aiRunSiteImportPlan","step","instructions","messages","content","tool","cutOff","noun","smaller","check","signal"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;2CAqB2C,GAE3C,SAASA,kBAAkB,EAAEC,mBAAmB,QAAQ,0CAAyC;AACjG,SAASC,qBAAqB,QAAQ,uCAAmC;AACzE,SAASC,yBAAyB,EAAEC,4BAA4B,EAAEC,uBAAuB,QAAsI,6BAAyB;AACxP,SAASC,aAAa,QAAQ,4BAAwB;AAEtD,SAASC,aAAa,QAAQ,0BAAsB;AAEpD,SAASC,sBAAsB,QAAQ,4BAAwB;AAE/D,SAASC,2BAA2B,EAAEC,eAAe,QAAQ,qBAAiB;AAC9E,SAASC,2BAA2B,QAAQ,4BAAwB;AACpE,SAASC,gCAAgC,EAAEC,iCAAiC,EAAEC,wBAAwB,EAAEC,sBAAsB,QAAQ,8BAA0B;AAEhK,MAAMC,QAAQ,CAACC,OAA2B,OAAOA,SAAS,WAAWA,KAAKC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAExG,uFAAuF,GACvF,OAAO,MAAMC,2BAA2B,mBAAkB;AAE1D,qFAAqF,GACrF,OAAO,MAAMC,6BAA6B;IAAC;IAAS;IAAU;IAAS;IAAS;IAAa;IAAU;CAAQ,CAAiE;AAEhL,mFAAmF,GACnF,OAAO,MAAMC,iCAAiC,EAAC;AAE/C,6FAA6F,GAC7F,OAAO,MAAMC,sCAAsC,GAAE;AAErD,qFAAqF,GACrF,OAAO,MAAMC,sCAAsC,GAAE;AAErD,MAAMC,eAAe;IACnBC,MAAM;IACNC,sBAAsB;IACtBC,UAAU;QAAC;QAAS;KAAQ;IAC5BC,YAAY;QAAEC,OAAO;YAAEJ,MAAM;QAA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F,MAAM,GAAG;QAAEA,QAAQpF,MAAMoF,MAAM;IAAC,IAAI,CAAC;AAEnD"}
@@ -178,6 +178,16 @@ export declare const AI_MEASURED_IMPORT_CREDITS: {
178
178
  readonly median: 35;
179
179
  readonly p90: 50;
180
180
  };
181
+ /**
182
+ * A main page redesigned from its ledger with new copy under a generative
183
+ * Improve it (AGL-4152), its one answer in place of the design and wording
184
+ * answers: the second paid eval's 26 pages (`AI_MEASURED_REDESIGNED_AT`),
185
+ * median 42, p90 79, most 88.
186
+ */
187
+ readonly redesigned: {
188
+ readonly median: 42;
189
+ readonly p90: 79;
190
+ };
181
191
  /** A page copied as it is: no model. It spends only where its source left its listing empty, which the 1 at the p90 covers. */
182
192
  readonly copied: {
183
193
  readonly median: 0;
@@ -197,6 +207,12 @@ export declare const AI_MEASURED_REWORDED_AT: {
197
207
  readonly job: "S_JkQp-XbT";
198
208
  readonly reworded: 10;
199
209
  };
210
+ /** When the `redesigned` row of `AI_MEASURED_IMPORT_CREDITS` was read: the generative eval's second run, over how many answers. */
211
+ export declare const AI_MEASURED_REDESIGNED_AT: {
212
+ readonly read: "2026-11-05";
213
+ readonly eval: "import-improve, run 2";
214
+ readonly redesigned: 26;
215
+ };
200
216
  /**
201
217
  * When the table above was read, and from when its jobs ran. Both tables
202
218
  * were measured before AGL-3781 asked a paid site's plan at medium effort and
@@ -165,6 +165,15 @@
165
165
  median: 35,
166
166
  p90: 50
167
167
  },
168
+ /**
169
+ * A main page redesigned from its ledger with new copy under a generative
170
+ * Improve it (AGL-4152), its one answer in place of the design and wording
171
+ * answers: the second paid eval's 26 pages (`AI_MEASURED_REDESIGNED_AT`),
172
+ * median 42, p90 79, most 88.
173
+ */ redesigned: {
174
+ median: 42,
175
+ p90: 79
176
+ },
168
177
  /** A page copied as it is: no model. It spends only where its source left its listing empty, which the 1 at the p90 covers. */ copied: {
169
178
  median: 0,
170
179
  p90: 1
@@ -181,6 +190,11 @@
181
190
  job: 'S_JkQp-XbT',
182
191
  reworded: 10
183
192
  };
193
+ /** When the `redesigned` row of `AI_MEASURED_IMPORT_CREDITS` was read: the generative eval's second run, over how many answers. */ export const AI_MEASURED_REDESIGNED_AT = {
194
+ read: '2026-11-05',
195
+ eval: 'import-improve, run 2',
196
+ redesigned: 26
197
+ };
184
198
  /**
185
199
  * When the table above was read, and from when its jobs ran. Both tables
186
200
  * were measured before AGL-3781 asked a paid site's plan at medium effort and
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-credit-estimate.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 * WHAT A JOB REALLY COSTS, NEXT TO WHAT IT CAN COST (AGL-3722).\n *\n * Every job's cost used to be quoted at its CEILING: each pass at the\n * `AI_SITE_PASS_CREDITS` (50) a pass is reserved against. A Free Assist\n * build of two pages, a quote form and a layout was quoted 600 credits and\n * refused with 164 left, when builds like it measure about a fifth of that.\n *\n * So a job is now quoted as a RANGE: what it is likely to cost (the sum of\n * the measured medians of what it builds), what it costs nine times in ten\n * (the measured p90s), and its ceiling (the old figure, unchanged). The\n * meter still charges actual use, and the reservation each pass takes is\n * still the ceiling's 50 — only the words and the Free admission move:\n * a Free job is admitted outright when its p90 fits what is left, and asked\n * to be confirmed when it does not.\n *\n * This module is pure: the console, the doors and the specs read one table.\n */\n\n/** One measured cost: the median and the 90th percentile, in credits. */\nexport interface AiMeasuredCredits {\n median: number\n p90: number\n}\n\n/**\n * MEASURED IN PRODUCTION, credits per unit, over every `done` AI job since\n * 2026-10-01 (read 2026-10-09; a whole Free site job came to 148–160):\n *\n * page item 30 / 40 (a page of about `AI_MEASURED_PAGE_SECTIONS` sections, its listing included)\n * form 29 / 31\n * layout 23 / 24 (header and footer, one answer)\n * theme 4 / 8 (a site start's look)\n * plan step 21 / 70\n *\n * THE FAST TIER'S PART, REPRICED (AGL-3781). A site start's look, a Free\n * start's plan and every page's listing run on the fast tier, measured above\n * on Claude Haiku 4.5 at its cost. They run on Claude Haiku 5.5 at the\n * platform's markup now, so those parts are repriced from what production\n * sent, at the new rates and about 30% more tokens: over October 1–14 a look\n * 4 / 7 → 1 / 2, a Free start's plan 15 / 22 → 3 / 5, a listing 3 / 5 → 1 / 1\n * (2 less on every page), and a whole two-page Free site 148 → 121 at the\n * median. The other rows ran on the balanced tier and do not move.\n *\n * HOW TO RE-MEASURE: a read-only collection-group read of `aiJobs` in\n * production where `status == 'done'` and `createdAt` is in the window; group\n * each ledger row's (`items[]`) `creditsSpent` by its `op` (the site start's\n * look is the `theme` row), take the plan step's `steps[].creditsSpent` for\n * `plan`, and each job's `creditsSpent` for the whole-site band. Put each\n * group's median and 90th percentile here, and the dates in\n * `AI_MEASURED_AT`. `ai-credit-estimate.spec.ts` holds the table, the page\n * scaling and the measured whole-site band together, so a re-measure that\n * moves one moves the spec with it.\n */\nexport const AI_MEASURED_UNIT_CREDITS = {\n // 30 / 40 with its listing at Haiku 4.5's cost.\n page: { median: 28, p90: 38 },\n form: { median: 29, p90: 31 },\n layout: { median: 23, p90: 24 },\n // 4 / 8 on Haiku 4.5.\n theme: { median: 1, p90: 2 },\n // 21 / 70: the median is a Free start's plan, on the fast tier; the p90 a\n // plan on the balanced tier, which does not move.\n plan: { median: 4, p90: 70 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/**\n * MEASURED IN PRODUCTION, credits per unit of a PAID site start, whose plan\n * and parts run on the paid routing (Sonnet) rather than a Free start's\n * (Haiku) the table above is mostly made of: every `done` paid site job\n * since 2026-10-01, read 2026-10-12 (6 jobs; products from the 4 stores; AGL-3739).\n *\n * plan step 81 / 86 (a Free start's plan: 20 / 42 on Haiku 4.5, 3 / 5 repriced)\n * page item 29 / 49 (about `AI_MEASURED_PAGE_SECTIONS` sections; 27 / 47 with its listing repriced)\n * form 32 / 39\n * layout 29 / 29\n * theme 4 / 4 (1 / 1 repriced)\n * email 49 / 51\n * products 64 / 66 (a store's first products, one answer)\n *\n * A 5-page store with its welcome email was quoted about 277 off the table\n * above: its plan at a Free start's 21 where paid plans run about 81, and its\n * first products not counted at all where they run about 64. Those stores\n * came to 413-448; this table quotes one at about 404.\n *\n * Re-measure as the table above says, keeping only jobs whose plan step's\n * `tokens.model` is the paid routing's.\n */\nexport const AI_MEASURED_PAID_SITE_CREDITS = {\n plan: { median: 81, p90: 86 },\n page: { median: 27, p90: 47 },\n form: { median: 32, p90: 39 },\n layout: { median: 29, p90: 29 },\n theme: { median: 1, p90: 1 },\n email: { median: 49, p90: 51 },\n products: { median: 64, p90: 66 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/**\n * A page brought in from a person's own website (AGL-3976), priced by how it\n * is built. `page` is a page no step has chosen a build for yet, priced as an\n * AI page: a paid site start's page as measured above. Its site's header and\n * footer, built once in an import's first wave, is that table's layout.\n *\n * `arranged` and `copied` are measured from the one whole import production\n * has run (`AI_MEASURED_IMPORT_AT`, AGL-4083).\n *\n * HOW TO RE-MEASURE: `site-import-fidelity-report.mts --host <id> --job <id>`,\n * read-only, prints each row's count, median, p90 and mean over the ledger's\n * items that succeeded and gave nothing back, grouped by the page's `build`\n * (`siteImportCreditsMeasured`). Each figure here is that reading rounded up:\n * a quote is never under what is drawn.\n */\nexport const AI_MEASURED_IMPORT_CREDITS = {\n page: AI_MEASURED_PAID_SITE_CREDITS.page,\n frame: AI_MEASURED_PAID_SITE_CREDITS.layout,\n /** A main page, its one design answer on the balanced tier over the page's read structure: 77 pages, mean 9.5, median 10, p90 12. */\n arranged: { median: 10, p90: 12 },\n /**\n * A main page arranged and reworded under Also improve my wording (AGL-4152),\n * its design answer and its wording together: 10 pages of the 11/5 live wave\n * (`AI_MEASURED_REWORDED_AT`), mean 35.8, median 34.5, p90 50, most 70.\n */\n reworded: { median: 35, p90: 50 },\n /** A page copied as it is: no model. It spends only where its source left its listing empty, which the 1 at the p90 covers. */\n copied: { median: 0, p90: 1 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/** When `AI_MEASURED_IMPORT_CREDITS` was read, from which import, over how many pages of each build. */\nexport const AI_MEASURED_IMPORT_AT = { read: '2026-11-01', job: 'mxOkjt2ff7', arranged: 77, copied: 266 } as const\n\n/** When the `reworded` row of `AI_MEASURED_IMPORT_CREDITS` was read, from which import, over how many pages. */\nexport const AI_MEASURED_REWORDED_AT = { read: '2026-11-05', job: 'S_JkQp-XbT', reworded: 10 } as const\n\n/**\n * When the table above was read, and from when its jobs ran. Both tables\n * were measured before AGL-3781 asked a paid site's plan at medium effort and\n * the layout language's pages and frames at low. A lower effort draws less,\n * so their plan, page and layout figures stand as the higher reading until\n * the next re-measure: a quote is never under what is drawn.\n */\nexport const AI_MEASURED_AT = { read: '2026-10-09', since: '2026-10-01' } as const\n\n/**\n * What a whole Free two-page site job measured at, in credits, in the same\n * window: 148–160 with its plan, look and listings at Haiku 4.5's cost, 27\n * less at the median with them repriced (AGL-3781).\n */\nexport const AI_MEASURED_FREE_SITE_CREDITS = { low: 121, high: 133 } as const\n\n/** The sections the measured page item is about: a page is scaled around it. */\nexport const AI_MEASURED_PAGE_SECTIONS = 5\n\n/**\n * What a page of this many sections is likely to cost: the measured page\n * scaled by its sections around the ~5-section median — about 6 credits a\n * section, 8 at the p90.\n */\nexport function aiMeasuredPageCredits(sections: number): AiMeasuredCredits {\n const count = Math.max(1, Math.floor(Number.isFinite(sections) ? sections : AI_MEASURED_PAGE_SECTIONS))\n const { median, p90 } = AI_MEASURED_UNIT_CREDITS.page\n return {\n median: Math.ceil((median * count) / AI_MEASURED_PAGE_SECTIONS),\n p90: Math.ceil((p90 * count) / AI_MEASURED_PAGE_SECTIONS),\n }\n}\n\n/**\n * What a page costs when it is written ON ITS OWN — a page an Assist build or\n * a page job writes, rather than one of a site start's pages (AGL-3722).\n *\n * The table's page item is a site start's: its pages are written one after\n * another inside one job, the later ones reading the prompt the first one\n * paid to write, so a 2-section second page measured 19–28. A page written on\n * its own pays that prompt itself and reads the site it lands on, and costs\n * what a site start's FIRST page costs: a 5-section home page measured 39–78\n * (median 40, p90 78), standalone page jobs' writing step 82–105 for a\n * 2-section page, and the Assist build pages of 2026-10-09 22–89 each. Quoting\n * a build's pages at the site start's scaled median told a Free workspace\n * \"about 48 credits\" for two 4-section pages (AGL-3722, 2026-10-10).\n *\n * So it is priced as a fixed cost — the prompt, the site, the listing — and a\n * cost per section: a 4-section page about 38 (p90 76), a 5-section 44 (p90 88).\n * The fixed part was 16 / 30 with its listing at Haiku 4.5's cost (AGL-3781).\n */\nexport const AI_MEASURED_STANDALONE_PAGE = {\n fixed: { median: 14, p90: 28 },\n perSection: { median: 6, p90: 12 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/** What a page of this many sections written on its own is likely to cost. */\nexport function aiMeasuredStandalonePageCredits(sections: number): AiMeasuredCredits {\n const count = Math.max(1, Math.floor(Number.isFinite(sections) ? sections : AI_MEASURED_PAGE_SECTIONS))\n const { fixed, perSection } = AI_MEASURED_STANDALONE_PAGE\n return {\n median: fixed.median + perSection.median * count,\n p90: fixed.p90 + perSection.p90 * count,\n }\n}\n\n/**\n * What a creation costs when it is written ON ITS OWN (AGL-3722), where it\n * measured apart from a site start's: an Assist build's layout came to 24–28\n * (2026-10-09/10), against a site start's 23/24 written in its warm prompt.\n * A form measured the same either way (25–30 on its own, 29/31 in a site\n * start), so it keeps the table's figure.\n */\nexport const AI_MEASURED_STANDALONE_CREATION_CREDITS = {\n layout: { median: 26, p90: 30 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/**\n * What one pass of a kind with no measurement of its own is likely to cost\n * (a component, an email design, a template, an item another runner\n * builds), written on its own: a component job's writing step measured\n * 52–65, a form job's 37, a layout job's 63, and the Assist build of\n * 2026-10-09 a welcome email at 46 and a products step at 60. Until\n * 2026-10-10 this was a site start's form (29/31), which is written inside a\n * site job's warm prompt and is the cheapest single answer there is.\n */\nexport const AI_MEASURED_PASS_CREDITS: AiMeasuredCredits = { median: 50, p90: 65 }\n\n/** A job's cost as it is quoted: likely, nine times in ten, and at its worst. */\nexport interface AiCreditRange {\n /** The sum of the measured medians: what the job is likely to spend. */\n likely: number\n /** The sum of the measured p90s: what a Free job is admitted on. */\n p90: number\n /** Every pass at its reserve: what it can spend at most. */\n ceiling: number\n}\n\nexport const AI_CREDIT_RANGE_ZERO: AiCreditRange = { likely: 0, p90: 0, ceiling: 0 }\n\n/** Two ranges added. */\nexport function aiCreditRangeAdd(a: AiCreditRange, b: AiCreditRange): AiCreditRange {\n return { likely: a.likely + b.likely, p90: a.p90 + b.p90, ceiling: a.ceiling + b.ceiling }\n}\n\n/** A measured cost as a range with its own ceiling, the likely and p90 never above it. */\nexport function aiCreditRangeOf(measured: AiMeasuredCredits, ceiling: number): AiCreditRange {\n const top = Math.max(0, Math.ceil(ceiling))\n return { likely: Math.min(measured.median, top), p90: Math.min(measured.p90, top), ceiling: top }\n}\n\n/** A range whose likely and p90 are each at least the last, and at most the ceiling. */\nexport function aiCreditRangeOrdered(range: AiCreditRange): AiCreditRange {\n const ceiling = Math.max(0, Math.ceil(range.ceiling))\n const likely = Math.min(Math.max(0, Math.ceil(range.likely)), ceiling)\n const p90 = Math.min(Math.max(likely, Math.ceil(range.p90)), ceiling)\n return { likely, p90, ceiling }\n}\n\nconst n = (value: number) => value.toLocaleString('en-US')\n\n/**\n * The range as every surface quotes it: \"About 106 credits (up to 650)\".\n * A job whose likely figure is its ceiling says one number.\n */\nexport function aiCreditRangeText(range: AiCreditRange): string {\n if (range.likely >= range.ceiling) return `About ${n(range.ceiling)} credits`\n return `About ${n(range.likely)} credits (up to ${n(range.ceiling)})`\n}\n\n/**\n * Whether a Free job of this range needs the person's go-ahead before it\n * starts (AGL-3722): its p90 is more than what is left. A job whose p90\n * fits starts with no prompt; one that does not starts only when confirmed,\n * builds as much as what is left pays for, and pauses with Resume.\n */\nexport function aiCreditsNeedConfirm(range: Pick<AiCreditRange, 'p90'>, left: number): boolean {\n return Number.isFinite(left) && range.p90 > Math.max(0, Math.floor(left))\n}\n\n/** The smaller first build a Free job that does not fit is offered (AGL-3722). */\nexport interface AiCreditsSmaller {\n /** \"Build the home page first\". */\n label: string\n likely: number\n p90: number\n ceiling: number\n}\n\n/**\n * What a Free job that does not fit what is left says before it starts, and\n * the choices it offers: build what fits, a smaller first build, or Upgrade.\n * The door that refuses an unconfirmed start answers with it (status 409,\n * `code: AI_CREDITS_CONFIRM_CODE`), and the plan card and the guided start\n * draw it from the same figures.\n */\nexport interface AiCreditsPrompt extends AiCreditRange {\n left: number\n resetsOn: string\n smaller: AiCreditsSmaller | null\n}\n\n/** The `code` a door answers an unconfirmed Free start with. */\nexport const AI_CREDITS_CONFIRM_CODE = 'credits-confirm'\n\n/** \"Build what fits\": the go-ahead for a Free job past what is left. */\nexport const AI_CREDITS_BUILD_WHAT_FITS = 'Build what fits'\n\n/** The smaller first build's button: \"Build the home page first (about 64 credits)\". */\nexport function aiCreditsSmallerText(smaller: Pick<AiCreditsSmaller, 'label' | 'likely'>): string {\n return `${smaller.label} (about ${n(smaller.likely)} credits)`\n}\n\n/** Which way on a prompt offers, in the order it offers them. */\nexport type AiCreditsChoiceKey = 'fits' | 'smaller' | 'upgrade'\n\n/** One way on, as its option button reads it: a short label and the figure under it (AGL-3722). */\nexport interface AiCreditsChoice {\n key: AiCreditsChoiceKey\n label: string\n detail: string\n /** The one choice drawn as the primary button. */\n recommended: boolean\n}\n\nconst credit = (count: number) => `${n(count)} ${count === 1 ? 'credit' : 'credits'}`\n\n/**\n * The prompt's ways on, as its three option buttons read them (Zach,\n * 2026-10-10: \"more appealing and consistent\"): build what fits, the smaller\n * first build when there is one, and Upgrade when it can be offered — each a\n * short sentence-case label with its figure under it. The smaller build is\n * the recommended one when its p90 fits what is left, since it then finishes;\n * otherwise building what fits is.\n */\nexport function aiCreditsChoices(\n prompt: Pick<AiCreditsPrompt, 'left' | 'smaller'>,\n offers: { smaller: boolean; upgrade: boolean },\n): AiCreditsChoice[] {\n const left = Math.max(0, Math.floor(prompt.left))\n const smaller = offers.smaller ? prompt.smaller : null\n const smallerFits = smaller !== null && smaller.p90 <= left\n const choices: AiCreditsChoice[] = [\n {\n key: 'fits',\n label: AI_CREDITS_BUILD_WHAT_FITS,\n detail: `Uses your ${credit(left)} left, then pauses`,\n recommended: !smallerFits,\n },\n ]\n if (smaller) {\n choices.push({\n key: 'smaller',\n label: smaller.label,\n detail: smallerFits ? `About ${credit(smaller.likely)}, fits what you have left` : `About ${credit(smaller.likely)}`,\n recommended: smallerFits,\n })\n }\n if (offers.upgrade) choices.push({ key: 'upgrade', label: 'Upgrade', detail: 'Get more credits', recommended: false })\n return choices\n}\n\n/** A reset day as a person reads it: \"November 1\". */\nfunction resetLabel(resetsOn: string): string {\n const at = new Date(`${resetsOn}T00:00:00.000Z`)\n return Number.isFinite(at.getTime())\n ? at.toLocaleDateString('en-US', { month: 'long', day: 'numeric', timeZone: 'UTC' })\n : 'the first of next month'\n}\n\n/**\n * The plain sentence (Zach, 2026-10-09): \"This build is about N credits (up\n * to M). You have L left, so it will build as much as it can and pause when\n * your credits run out. You can upgrade or resume when they renew.\"\n */\nexport function aiCreditsPromptText(prompt: AiCreditsPrompt, noun: 'build' | 'site' = 'build'): string {\n const size =\n prompt.likely >= prompt.ceiling\n ? `about ${n(prompt.ceiling)} credits`\n : `about ${n(prompt.likely)} credits (up to ${n(prompt.ceiling)})`\n const left = Math.max(0, Math.floor(prompt.left))\n return (\n `This ${noun} is ${size}. You have ${n(left)} left, so it will build as much as it can and pause ` +\n `when your credits run out. You can upgrade or resume when they renew on ${resetLabel(prompt.resetsOn)}.`\n )\n}\n\n/**\n * The record a confirmed Free start keeps (AGL-3722): who said go, when,\n * what was left then and the range they were shown.\n */\nexport interface AiJobCreditsConfirmation extends AiCreditRange {\n by: string\n at: Date | string\n left: number\n}\n\n/** The confirmation a door keeps on the job for the prompt the person confirmed, or `null` when there was none. */\nexport function aiCreditsConfirmation(\n prompt: AiCreditsPrompt | null,\n by: string,\n at: Date,\n): AiJobCreditsConfirmation | null {\n if (!prompt) return null\n return { by, at, left: prompt.left, likely: prompt.likely, p90: prompt.p90, ceiling: prompt.ceiling }\n}\n\n/** The prompt a range needs against what is left, or `null` when it fits. */\nexport function aiCreditsPromptFor(\n range: AiCreditRange,\n credits: { left: number; resetsOn: string } | null | undefined,\n smaller: AiCreditsSmaller | null = null,\n): AiCreditsPrompt | null {\n if (!credits || !aiCreditsNeedConfirm(range, credits.left)) return null\n return { ...range, left: Math.max(0, Math.floor(credits.left)), resetsOn: credits.resetsOn, smaller }\n}\n"],"names":["AI_MEASURED_UNIT_CREDITS","page","median","p90","form","layout","theme","plan","AI_MEASURED_PAID_SITE_CREDITS","email","products","AI_MEASURED_IMPORT_CREDITS","frame","arranged","reworded","copied","AI_MEASURED_IMPORT_AT","read","job","AI_MEASURED_REWORDED_AT","AI_MEASURED_AT","since","AI_MEASURED_FREE_SITE_CREDITS","low","high","AI_MEASURED_PAGE_SECTIONS","aiMeasuredPageCredits","sections","count","Math","max","floor","Number","isFinite","ceil","AI_MEASURED_STANDALONE_PAGE","fixed","perSection","aiMeasuredStandalonePageCredits","AI_MEASURED_STANDALONE_CREATION_CREDITS","AI_MEASURED_PASS_CREDITS","AI_CREDIT_RANGE_ZERO","likely","ceiling","aiCreditRangeAdd","a","b","aiCreditRangeOf","measured","top","min","aiCreditRangeOrdered","range","n","value","toLocaleString","aiCreditRangeText","aiCreditsNeedConfirm","left","AI_CREDITS_CONFIRM_CODE","AI_CREDITS_BUILD_WHAT_FITS","aiCreditsSmallerText","smaller","label","credit","aiCreditsChoices","prompt","offers","smallerFits","choices","key","detail","recommended","push","upgrade","resetLabel","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C,KAAK,WAAW,EAAEjC,EAAEK,MAAM,oDAAoD,CAAC,GAClG,CAAC,wEAAwE,EAAEiB,WAAWT,OAAOU,QAAQ,EAAE,CAAC,CAAC;AAE7G;AAYA,iHAAiH,GACjH,OAAO,SAASW,sBACdrB,MAA8B,EAC9BsB,EAAU,EACVX,EAAQ;IAER,IAAI,CAACX,QAAQ,OAAO;IACpB,OAAO;QAAEsB;QAAIX;QAAInB,MAAMQ,OAAOR,IAAI;QAAEhB,QAAQwB,OAAOxB,MAAM;QAAEvC,KAAK+D,OAAO/D,GAAG;QAAEwC,SAASuB,OAAOvB,OAAO;IAAC;AACtG;AAEA,2EAA2E,GAC3E,OAAO,SAAS8C,mBACdrC,KAAoB,EACpBsC,OAA8D,EAC9D5B,UAAmC,IAAI;IAEvC,IAAI,CAAC4B,WAAW,CAACjC,qBAAqBL,OAAOsC,QAAQhC,IAAI,GAAG,OAAO;IACnE,OAAO,aAAKN;QAAOM,MAAM7B,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAAC2D,QAAQhC,IAAI;QAAIkB,UAAUc,QAAQd,QAAQ;QAAEd;;AAC9F"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-credit-estimate.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 * WHAT A JOB REALLY COSTS, NEXT TO WHAT IT CAN COST (AGL-3722).\n *\n * Every job's cost used to be quoted at its CEILING: each pass at the\n * `AI_SITE_PASS_CREDITS` (50) a pass is reserved against. A Free Assist\n * build of two pages, a quote form and a layout was quoted 600 credits and\n * refused with 164 left, when builds like it measure about a fifth of that.\n *\n * So a job is now quoted as a RANGE: what it is likely to cost (the sum of\n * the measured medians of what it builds), what it costs nine times in ten\n * (the measured p90s), and its ceiling (the old figure, unchanged). The\n * meter still charges actual use, and the reservation each pass takes is\n * still the ceiling's 50 — only the words and the Free admission move:\n * a Free job is admitted outright when its p90 fits what is left, and asked\n * to be confirmed when it does not.\n *\n * This module is pure: the console, the doors and the specs read one table.\n */\n\n/** One measured cost: the median and the 90th percentile, in credits. */\nexport interface AiMeasuredCredits {\n median: number\n p90: number\n}\n\n/**\n * MEASURED IN PRODUCTION, credits per unit, over every `done` AI job since\n * 2026-10-01 (read 2026-10-09; a whole Free site job came to 148–160):\n *\n * page item 30 / 40 (a page of about `AI_MEASURED_PAGE_SECTIONS` sections, its listing included)\n * form 29 / 31\n * layout 23 / 24 (header and footer, one answer)\n * theme 4 / 8 (a site start's look)\n * plan step 21 / 70\n *\n * THE FAST TIER'S PART, REPRICED (AGL-3781). A site start's look, a Free\n * start's plan and every page's listing run on the fast tier, measured above\n * on Claude Haiku 4.5 at its cost. They run on Claude Haiku 5.5 at the\n * platform's markup now, so those parts are repriced from what production\n * sent, at the new rates and about 30% more tokens: over October 1–14 a look\n * 4 / 7 → 1 / 2, a Free start's plan 15 / 22 → 3 / 5, a listing 3 / 5 → 1 / 1\n * (2 less on every page), and a whole two-page Free site 148 → 121 at the\n * median. The other rows ran on the balanced tier and do not move.\n *\n * HOW TO RE-MEASURE: a read-only collection-group read of `aiJobs` in\n * production where `status == 'done'` and `createdAt` is in the window; group\n * each ledger row's (`items[]`) `creditsSpent` by its `op` (the site start's\n * look is the `theme` row), take the plan step's `steps[].creditsSpent` for\n * `plan`, and each job's `creditsSpent` for the whole-site band. Put each\n * group's median and 90th percentile here, and the dates in\n * `AI_MEASURED_AT`. `ai-credit-estimate.spec.ts` holds the table, the page\n * scaling and the measured whole-site band together, so a re-measure that\n * moves one moves the spec with it.\n */\nexport const AI_MEASURED_UNIT_CREDITS = {\n // 30 / 40 with its listing at Haiku 4.5's cost.\n page: { median: 28, p90: 38 },\n form: { median: 29, p90: 31 },\n layout: { median: 23, p90: 24 },\n // 4 / 8 on Haiku 4.5.\n theme: { median: 1, p90: 2 },\n // 21 / 70: the median is a Free start's plan, on the fast tier; the p90 a\n // plan on the balanced tier, which does not move.\n plan: { median: 4, p90: 70 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/**\n * MEASURED IN PRODUCTION, credits per unit of a PAID site start, whose plan\n * and parts run on the paid routing (Sonnet) rather than a Free start's\n * (Haiku) the table above is mostly made of: every `done` paid site job\n * since 2026-10-01, read 2026-10-12 (6 jobs; products from the 4 stores; AGL-3739).\n *\n * plan step 81 / 86 (a Free start's plan: 20 / 42 on Haiku 4.5, 3 / 5 repriced)\n * page item 29 / 49 (about `AI_MEASURED_PAGE_SECTIONS` sections; 27 / 47 with its listing repriced)\n * form 32 / 39\n * layout 29 / 29\n * theme 4 / 4 (1 / 1 repriced)\n * email 49 / 51\n * products 64 / 66 (a store's first products, one answer)\n *\n * A 5-page store with its welcome email was quoted about 277 off the table\n * above: its plan at a Free start's 21 where paid plans run about 81, and its\n * first products not counted at all where they run about 64. Those stores\n * came to 413-448; this table quotes one at about 404.\n *\n * Re-measure as the table above says, keeping only jobs whose plan step's\n * `tokens.model` is the paid routing's.\n */\nexport const AI_MEASURED_PAID_SITE_CREDITS = {\n plan: { median: 81, p90: 86 },\n page: { median: 27, p90: 47 },\n form: { median: 32, p90: 39 },\n layout: { median: 29, p90: 29 },\n theme: { median: 1, p90: 1 },\n email: { median: 49, p90: 51 },\n products: { median: 64, p90: 66 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/**\n * A page brought in from a person's own website (AGL-3976), priced by how it\n * is built. `page` is a page no step has chosen a build for yet, priced as an\n * AI page: a paid site start's page as measured above. Its site's header and\n * footer, built once in an import's first wave, is that table's layout.\n *\n * `arranged` and `copied` are measured from the one whole import production\n * has run (`AI_MEASURED_IMPORT_AT`, AGL-4083).\n *\n * HOW TO RE-MEASURE: `site-import-fidelity-report.mts --host <id> --job <id>`,\n * read-only, prints each row's count, median, p90 and mean over the ledger's\n * items that succeeded and gave nothing back, grouped by the page's `build`\n * (`siteImportCreditsMeasured`). Each figure here is that reading rounded up:\n * a quote is never under what is drawn.\n */\nexport const AI_MEASURED_IMPORT_CREDITS = {\n page: AI_MEASURED_PAID_SITE_CREDITS.page,\n frame: AI_MEASURED_PAID_SITE_CREDITS.layout,\n /** A main page, its one design answer on the balanced tier over the page's read structure: 77 pages, mean 9.5, median 10, p90 12. */\n arranged: { median: 10, p90: 12 },\n /**\n * A main page arranged and reworded under Also improve my wording (AGL-4152),\n * its design answer and its wording together: 10 pages of the 11/5 live wave\n * (`AI_MEASURED_REWORDED_AT`), mean 35.8, median 34.5, p90 50, most 70.\n */\n reworded: { median: 35, p90: 50 },\n /**\n * A main page redesigned from its ledger with new copy under a generative\n * Improve it (AGL-4152), its one answer in place of the design and wording\n * answers: the second paid eval's 26 pages (`AI_MEASURED_REDESIGNED_AT`),\n * median 42, p90 79, most 88.\n */\n redesigned: { median: 42, p90: 79 },\n /** A page copied as it is: no model. It spends only where its source left its listing empty, which the 1 at the p90 covers. */\n copied: { median: 0, p90: 1 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/** When `AI_MEASURED_IMPORT_CREDITS` was read, from which import, over how many pages of each build. */\nexport const AI_MEASURED_IMPORT_AT = { read: '2026-11-01', job: 'mxOkjt2ff7', arranged: 77, copied: 266 } as const\n\n/** When the `reworded` row of `AI_MEASURED_IMPORT_CREDITS` was read, from which import, over how many pages. */\nexport const AI_MEASURED_REWORDED_AT = { read: '2026-11-05', job: 'S_JkQp-XbT', reworded: 10 } as const\n\n/** When the `redesigned` row of `AI_MEASURED_IMPORT_CREDITS` was read: the generative eval's second run, over how many answers. */\nexport const AI_MEASURED_REDESIGNED_AT = { read: '2026-11-05', eval: 'import-improve, run 2', redesigned: 26 } as const\n\n/**\n * When the table above was read, and from when its jobs ran. Both tables\n * were measured before AGL-3781 asked a paid site's plan at medium effort and\n * the layout language's pages and frames at low. A lower effort draws less,\n * so their plan, page and layout figures stand as the higher reading until\n * the next re-measure: a quote is never under what is drawn.\n */\nexport const AI_MEASURED_AT = { read: '2026-10-09', since: '2026-10-01' } as const\n\n/**\n * What a whole Free two-page site job measured at, in credits, in the same\n * window: 148–160 with its plan, look and listings at Haiku 4.5's cost, 27\n * less at the median with them repriced (AGL-3781).\n */\nexport const AI_MEASURED_FREE_SITE_CREDITS = { low: 121, high: 133 } as const\n\n/** The sections the measured page item is about: a page is scaled around it. */\nexport const AI_MEASURED_PAGE_SECTIONS = 5\n\n/**\n * What a page of this many sections is likely to cost: the measured page\n * scaled by its sections around the ~5-section median — about 6 credits a\n * section, 8 at the p90.\n */\nexport function aiMeasuredPageCredits(sections: number): AiMeasuredCredits {\n const count = Math.max(1, Math.floor(Number.isFinite(sections) ? sections : AI_MEASURED_PAGE_SECTIONS))\n const { median, p90 } = AI_MEASURED_UNIT_CREDITS.page\n return {\n median: Math.ceil((median * count) / AI_MEASURED_PAGE_SECTIONS),\n p90: Math.ceil((p90 * count) / AI_MEASURED_PAGE_SECTIONS),\n }\n}\n\n/**\n * What a page costs when it is written ON ITS OWN — a page an Assist build or\n * a page job writes, rather than one of a site start's pages (AGL-3722).\n *\n * The table's page item is a site start's: its pages are written one after\n * another inside one job, the later ones reading the prompt the first one\n * paid to write, so a 2-section second page measured 19–28. A page written on\n * its own pays that prompt itself and reads the site it lands on, and costs\n * what a site start's FIRST page costs: a 5-section home page measured 39–78\n * (median 40, p90 78), standalone page jobs' writing step 82–105 for a\n * 2-section page, and the Assist build pages of 2026-10-09 22–89 each. Quoting\n * a build's pages at the site start's scaled median told a Free workspace\n * \"about 48 credits\" for two 4-section pages (AGL-3722, 2026-10-10).\n *\n * So it is priced as a fixed cost — the prompt, the site, the listing — and a\n * cost per section: a 4-section page about 38 (p90 76), a 5-section 44 (p90 88).\n * The fixed part was 16 / 30 with its listing at Haiku 4.5's cost (AGL-3781).\n */\nexport const AI_MEASURED_STANDALONE_PAGE = {\n fixed: { median: 14, p90: 28 },\n perSection: { median: 6, p90: 12 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/** What a page of this many sections written on its own is likely to cost. */\nexport function aiMeasuredStandalonePageCredits(sections: number): AiMeasuredCredits {\n const count = Math.max(1, Math.floor(Number.isFinite(sections) ? sections : AI_MEASURED_PAGE_SECTIONS))\n const { fixed, perSection } = AI_MEASURED_STANDALONE_PAGE\n return {\n median: fixed.median + perSection.median * count,\n p90: fixed.p90 + perSection.p90 * count,\n }\n}\n\n/**\n * What a creation costs when it is written ON ITS OWN (AGL-3722), where it\n * measured apart from a site start's: an Assist build's layout came to 24–28\n * (2026-10-09/10), against a site start's 23/24 written in its warm prompt.\n * A form measured the same either way (25–30 on its own, 29/31 in a site\n * start), so it keeps the table's figure.\n */\nexport const AI_MEASURED_STANDALONE_CREATION_CREDITS = {\n layout: { median: 26, p90: 30 },\n} as const satisfies Record<string, AiMeasuredCredits>\n\n/**\n * What one pass of a kind with no measurement of its own is likely to cost\n * (a component, an email design, a template, an item another runner\n * builds), written on its own: a component job's writing step measured\n * 52–65, a form job's 37, a layout job's 63, and the Assist build of\n * 2026-10-09 a welcome email at 46 and a products step at 60. Until\n * 2026-10-10 this was a site start's form (29/31), which is written inside a\n * site job's warm prompt and is the cheapest single answer there is.\n */\nexport const AI_MEASURED_PASS_CREDITS: AiMeasuredCredits = { median: 50, p90: 65 }\n\n/** A job's cost as it is quoted: likely, nine times in ten, and at its worst. */\nexport interface AiCreditRange {\n /** The sum of the measured medians: what the job is likely to spend. */\n likely: number\n /** The sum of the measured p90s: what a Free job is admitted on. */\n p90: number\n /** Every pass at its reserve: what it can spend at most. */\n ceiling: number\n}\n\nexport const AI_CREDIT_RANGE_ZERO: AiCreditRange = { likely: 0, p90: 0, ceiling: 0 }\n\n/** Two ranges added. */\nexport function aiCreditRangeAdd(a: AiCreditRange, b: AiCreditRange): AiCreditRange {\n return { likely: a.likely + b.likely, p90: a.p90 + b.p90, ceiling: a.ceiling + b.ceiling }\n}\n\n/** A measured cost as a range with its own ceiling, the likely and p90 never above it. */\nexport function aiCreditRangeOf(measured: AiMeasuredCredits, ceiling: number): AiCreditRange {\n const top = Math.max(0, Math.ceil(ceiling))\n return { likely: Math.min(measured.median, top), p90: Math.min(measured.p90, top), ceiling: top }\n}\n\n/** A range whose likely and p90 are each at least the last, and at most the ceiling. */\nexport function aiCreditRangeOrdered(range: AiCreditRange): AiCreditRange {\n const ceiling = Math.max(0, Math.ceil(range.ceiling))\n const likely = Math.min(Math.max(0, Math.ceil(range.likely)), ceiling)\n const p90 = Math.min(Math.max(likely, Math.ceil(range.p90)), ceiling)\n return { likely, p90, ceiling }\n}\n\nconst n = (value: number) => value.toLocaleString('en-US')\n\n/**\n * The range as every surface quotes it: \"About 106 credits (up to 650)\".\n * A job whose likely figure is its ceiling says one number.\n */\nexport function aiCreditRangeText(range: AiCreditRange): string {\n if (range.likely >= range.ceiling) return `About ${n(range.ceiling)} credits`\n return `About ${n(range.likely)} credits (up to ${n(range.ceiling)})`\n}\n\n/**\n * Whether a Free job of this range needs the person's go-ahead before it\n * starts (AGL-3722): its p90 is more than what is left. A job whose p90\n * fits starts with no prompt; one that does not starts only when confirmed,\n * builds as much as what is left pays for, and pauses with Resume.\n */\nexport function aiCreditsNeedConfirm(range: Pick<AiCreditRange, 'p90'>, left: number): boolean {\n return Number.isFinite(left) && range.p90 > Math.max(0, Math.floor(left))\n}\n\n/** The smaller first build a Free job that does not fit is offered (AGL-3722). */\nexport interface AiCreditsSmaller {\n /** \"Build the home page first\". */\n label: string\n likely: number\n p90: number\n ceiling: number\n}\n\n/**\n * What a Free job that does not fit what is left says before it starts, and\n * the choices it offers: build what fits, a smaller first build, or Upgrade.\n * The door that refuses an unconfirmed start answers with it (status 409,\n * `code: AI_CREDITS_CONFIRM_CODE`), and the plan card and the guided start\n * draw it from the same figures.\n */\nexport interface AiCreditsPrompt extends AiCreditRange {\n left: number\n resetsOn: string\n smaller: AiCreditsSmaller | null\n}\n\n/** The `code` a door answers an unconfirmed Free start with. */\nexport const AI_CREDITS_CONFIRM_CODE = 'credits-confirm'\n\n/** \"Build what fits\": the go-ahead for a Free job past what is left. */\nexport const AI_CREDITS_BUILD_WHAT_FITS = 'Build what fits'\n\n/** The smaller first build's button: \"Build the home page first (about 64 credits)\". */\nexport function aiCreditsSmallerText(smaller: Pick<AiCreditsSmaller, 'label' | 'likely'>): string {\n return `${smaller.label} (about ${n(smaller.likely)} credits)`\n}\n\n/** Which way on a prompt offers, in the order it offers them. */\nexport type AiCreditsChoiceKey = 'fits' | 'smaller' | 'upgrade'\n\n/** One way on, as its option button reads it: a short label and the figure under it (AGL-3722). */\nexport interface AiCreditsChoice {\n key: AiCreditsChoiceKey\n label: string\n detail: string\n /** The one choice drawn as the primary button. */\n recommended: boolean\n}\n\nconst credit = (count: number) => `${n(count)} ${count === 1 ? 'credit' : 'credits'}`\n\n/**\n * The prompt's ways on, as its three option buttons read them (Zach,\n * 2026-10-10: \"more appealing and consistent\"): build what fits, the smaller\n * first build when there is one, and Upgrade when it can be offered — each a\n * short sentence-case label with its figure under it. The smaller build is\n * the recommended one when its p90 fits what is left, since it then finishes;\n * otherwise building what fits is.\n */\nexport function aiCreditsChoices(\n prompt: Pick<AiCreditsPrompt, 'left' | 'smaller'>,\n offers: { smaller: boolean; upgrade: boolean },\n): AiCreditsChoice[] {\n const left = Math.max(0, Math.floor(prompt.left))\n const smaller = offers.smaller ? prompt.smaller : null\n const smallerFits = smaller !== null && smaller.p90 <= left\n const choices: AiCreditsChoice[] = [\n {\n key: 'fits',\n label: AI_CREDITS_BUILD_WHAT_FITS,\n detail: `Uses your ${credit(left)} left, then pauses`,\n recommended: !smallerFits,\n },\n ]\n if (smaller) {\n choices.push({\n key: 'smaller',\n label: smaller.label,\n detail: smallerFits ? `About ${credit(smaller.likely)}, fits what you have left` : `About ${credit(smaller.likely)}`,\n recommended: smallerFits,\n })\n }\n if (offers.upgrade) choices.push({ key: 'upgrade', label: 'Upgrade', detail: 'Get more credits', recommended: false })\n return choices\n}\n\n/** A reset day as a person reads it: \"November 1\". */\nfunction resetLabel(resetsOn: string): string {\n const at = new Date(`${resetsOn}T00:00:00.000Z`)\n return Number.isFinite(at.getTime())\n ? at.toLocaleDateString('en-US', { month: 'long', day: 'numeric', timeZone: 'UTC' })\n : 'the first of next month'\n}\n\n/**\n * The plain sentence (Zach, 2026-10-09): \"This build is about N credits (up\n * to M). You have L left, so it will build as much as it can and pause when\n * your credits run out. You can upgrade or resume when they renew.\"\n */\nexport function aiCreditsPromptText(prompt: AiCreditsPrompt, noun: 'build' | 'site' = 'build'): string {\n const size =\n prompt.likely >= prompt.ceiling\n ? `about ${n(prompt.ceiling)} credits`\n : `about ${n(prompt.likely)} credits (up to ${n(prompt.ceiling)})`\n const left = Math.max(0, Math.floor(prompt.left))\n return (\n `This ${noun} is ${size}. You have ${n(left)} left, so it will build as much as it can and pause ` +\n `when your credits run out. You can upgrade or resume when they renew on ${resetLabel(prompt.resetsOn)}.`\n )\n}\n\n/**\n * The record a confirmed Free start keeps (AGL-3722): who said go, when,\n * what was left then and the range they were shown.\n */\nexport interface AiJobCreditsConfirmation extends AiCreditRange {\n by: string\n at: Date | string\n left: number\n}\n\n/** The confirmation a door keeps on the job for the prompt the person confirmed, or `null` when there was none. */\nexport function aiCreditsConfirmation(\n prompt: AiCreditsPrompt | null,\n by: string,\n at: Date,\n): AiJobCreditsConfirmation | null {\n if (!prompt) return null\n return { by, at, left: prompt.left, likely: prompt.likely, p90: prompt.p90, ceiling: prompt.ceiling }\n}\n\n/** The prompt a range needs against what is left, or `null` when it fits. */\nexport function aiCreditsPromptFor(\n range: AiCreditRange,\n credits: { left: number; resetsOn: string } | null | undefined,\n smaller: AiCreditsSmaller | null = null,\n): AiCreditsPrompt | null {\n if (!credits || !aiCreditsNeedConfirm(range, credits.left)) return null\n return { ...range, left: Math.max(0, Math.floor(credits.left)), resetsOn: credits.resetsOn, smaller }\n}\n"],"names":["AI_MEASURED_UNIT_CREDITS","page","median","p90","form","layout","theme","plan","AI_MEASURED_PAID_SITE_CREDITS","email","products","AI_MEASURED_IMPORT_CREDITS","frame","arranged","reworded","redesigned","copied","AI_MEASURED_IMPORT_AT","read","job","AI_MEASURED_REWORDED_AT","AI_MEASURED_REDESIGNED_AT","eval","AI_MEASURED_AT","since","AI_MEASURED_FREE_SITE_CREDITS","low","high","AI_MEASURED_PAGE_SECTIONS","aiMeasuredPageCredits","sections","count","Math","max","floor","Number","isFinite","ceil","AI_MEASURED_STANDALONE_PAGE","fixed","perSection","aiMeasuredStandalonePageCredits","AI_MEASURED_STANDALONE_CREATION_CREDITS","AI_MEASURED_PASS_CREDITS","AI_CREDIT_RANGE_ZERO","likely","ceiling","aiCreditRangeAdd","a","b","aiCreditRangeOf","measured","top","min","aiCreditRangeOrdered","range","n","value","toLocaleString","aiCreditRangeText","aiCreditsNeedConfirm","left","AI_CREDITS_CONFIRM_CODE","AI_CREDITS_BUILD_WHAT_FITS","aiCreditsSmallerText","smaller","label","credit","aiCreditsChoices","prompt","offers","smallerFits","choices","key","detail","recommended","push","upgrade","resetLabel","resetsOn","at","Date","getTime","toLocaleDateString","month","day","timeZone","aiCreditsPromptText","noun","size","aiCreditsConfirmation","by","aiCreditsPromptFor","credits"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;CAiBC,GAED,uEAAuE;AAMvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GACD,OAAO,MAAMA,2BAA2B;IACtC,gDAAgD;IAChDC,MAAM;QAAEC,QAAQ;QAAIC,KAAK;IAAG;IAC5BC,MAAM;QAAEF,QAAQ;QAAIC,KAAK;IAAG;IAC5BE,QAAQ;QAAEH,QAAQ;QAAIC,KAAK;IAAG;IAC9B,sBAAsB;IACtBG,OAAO;QAAEJ,QAAQ;QAAG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AAQwB,OAAOxB,MAAM;QAAE1C,KAAKkE,OAAOlE,GAAG;QAAE2C,SAASuB,OAAOvB,OAAO;IAAC;AACtG;AAEA,2EAA2E,GAC3E,OAAO,SAAS8C,mBACdrC,KAAoB,EACpBsC,OAA8D,EAC9D5B,UAAmC,IAAI;IAEvC,IAAI,CAAC4B,WAAW,CAACjC,qBAAqBL,OAAOsC,QAAQhC,IAAI,GAAG,OAAO;IACnE,OAAO,aAAKN;QAAOM,MAAM7B,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,CAAC2D,QAAQhC,IAAI;QAAIkB,UAAUc,QAAQd,QAAQ;QAAEd;;AAC9F"}
@@ -455,6 +455,8 @@ export declare function siteImportFidelityThemeOf(theme: unknown, from?: SiteImp
455
455
  * never scores under it here.
456
456
  */
457
457
  export declare function siteImportContentKept(line: string, rewrite: string): number;
458
+ /** How many content words a run of words says, by stem (AGL-4152): what a section says of its own. */
459
+ export declare function siteImportContentWords(text: string): number;
458
460
  /** What a page's facts are told apart by (G4): the names its source says, and every word it says in any case. */
459
461
  export interface SiteImportFactScope {
460
462
  /** Each word the source capitalizes past a sentence's first, in a line not set all in capitals. */
@@ -1970,6 +1970,9 @@ function schemeOf(colors) {
1970
1970
  */ export function siteImportContentKept(line, rewrite) {
1971
1971
  return contentKept(line, rewrite);
1972
1972
  }
1973
+ /** How many content words a run of words says, by stem (AGL-4152): what a section says of its own. */ export function siteImportContentWords(text) {
1974
+ return contentOf(text).size;
1975
+ }
1973
1976
  /** The share of a line's content words another keeps: 1 for a line with none. */ function contentKept(line, rewrite) {
1974
1977
  const said = contentOf(line);
1975
1978
  if (!said.size) return 1;
@@ -2217,7 +2220,10 @@ const isHeading = (node)=>{
2217
2220
  const said = options.proposed ? [] : [
2218
2221
  ...new Set(sourceTexts.filter((text)=>!bareNumber(text)).flatMap((text)=>siteImportFactTokens(text, ownScope, false).filter((token)=>!token.startsWith('name:') || !titleCased(text))))
2219
2222
  ];
2220
- const missingFacts = said.filter((token)=>!onPage.has(token));
2223
+ // A name the page still says, in the sentence case a redesign writes its headings in, is kept (AGL-4152):
2224
+ // "Built on Stone" rewritten "built on stone" keeps its word, and a real name keeps its capital anyway.
2225
+ const wordsOnPage = new Set(shown.flatMap(wordsOf).map((word)=>word.toLowerCase()));
2226
+ const missingFacts = said.filter((token)=>!onPage.has(token) && !(token.startsWith('name:') && wordsOnPage.has(token.slice(5).toLowerCase())));
2221
2227
  // Invented: none that nothing the import read says.
2222
2228
  const allowed = new Set(anywhere.flatMap((text)=>siteImportFactTokens(text, scope, false)));
2223
2229
  const found = [