@aglyn/plugins-ai 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/components/ai-site-build-page.component.js +5 -3
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-finish.component.d.ts +3 -1
- package/src/lib/components/ai-site-import-finish.component.js +3 -3
- package/src/lib/components/ai-site-import-finish.component.js.map +1 -1
- package/src/lib/components/ai-site-import-job.component.d.ts +4 -3
- package/src/lib/components/ai-site-import-job.component.js +141 -43
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/components/ai-site-import-plan.component.d.ts +42 -0
- package/src/lib/components/ai-site-import-plan.component.js +246 -0
- package/src/lib/components/ai-site-import-plan.component.js.map +1 -0
- package/src/lib/components/ai-site-import-start.component.d.ts +3 -1
- package/src/lib/components/ai-site-import-start.component.js +3 -2
- package/src/lib/components/ai-site-import-start.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.js +6 -2
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/components/ai-site-start-steps.component.d.ts +3 -2
- package/src/lib/components/ai-site-start-steps.component.js +12 -5
- package/src/lib/components/ai-site-start-steps.component.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +47 -2
- package/src/lib/jobs/ai-job-import-step.js +356 -22
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.js +4 -1
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +21 -2
- package/src/lib/jobs/ai-job-page-language.js +217 -5
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.d.ts +7 -0
- package/src/lib/jobs/ai-job-page-step.js +73 -12
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.js +4 -2
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-look.js +14 -5
- package/src/lib/jobs/ai-job-site-look.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.d.ts +10 -2
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.js +2 -1
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.d.ts +43 -2
- package/src/lib/jobs/ai-site-import-compile.js +105 -62
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +25 -1
- package/src/lib/jobs/ai-site-import-document.js +26 -7
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-honesty.d.ts +65 -0
- package/src/lib/jobs/ai-site-import-honesty.js +271 -0
- package/src/lib/jobs/ai-site-import-honesty.js.map +1 -0
- package/src/lib/jobs/ai-site-import-improve.d.ts +233 -0
- package/src/lib/jobs/ai-site-import-improve.js +1151 -0
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -0
- package/src/lib/jobs/ai-site-import-look.d.ts +4 -0
- package/src/lib/jobs/ai-site-import-look.js +16 -6
- package/src/lib/jobs/ai-site-import-look.js.map +1 -1
- package/src/lib/jobs/ai-site-import-pictures.d.ts +83 -0
- package/src/lib/jobs/ai-site-import-pictures.js +261 -0
- package/src/lib/jobs/ai-site-import-pictures.js.map +1 -0
- package/src/lib/jobs/ai-site-import-plan.d.ts +78 -0
- package/src/lib/jobs/ai-site-import-plan.js +627 -0
- package/src/lib/jobs/ai-site-import-plan.js.map +1 -0
- package/src/lib/jobs/ai-site-import-wording.js +2 -5
- package/src/lib/jobs/ai-site-import-wording.js.map +1 -1
- package/src/lib/layout-language/ai-layout-compiler.d.ts +6 -0
- package/src/lib/layout-language/ai-layout-compiler.js +10 -6
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-design.d.ts +9 -0
- package/src/lib/layout-language/ai-layout-design.js +29 -3
- package/src/lib/layout-language/ai-layout-design.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame-source.d.ts +5 -0
- package/src/lib/layout-language/ai-layout-frame-source.js +4 -2
- package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-frame.js +20 -12
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +8 -0
- package/src/lib/layout-language/ai-layout-language.js +7 -3
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +62 -0
- package/src/lib/model/ai-site-import-fidelity.js +374 -0
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-ledger.d.ts +82 -0
- package/src/lib/model/ai-site-import-ledger.js +254 -0
- package/src/lib/model/ai-site-import-ledger.js.map +1 -0
- package/src/lib/model/ai-site-import-view.d.ts +110 -6
- package/src/lib/model/ai-site-import-view.js +166 -13
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +227 -2
- package/src/lib/model/ai-site-import.js +312 -15
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/model/ai-site-job.js +4 -0
- package/src/lib/model/ai-site-job.js.map +1 -1
- package/src/lib/model/ai-site-kinds.d.ts +2 -0
- package/src/lib/model/ai-site-kinds.js +7 -0
- package/src/lib/model/ai-site-kinds.js.map +1 -1
- package/src/lib/model/ai-site-look.d.ts +14 -5
- package/src/lib/model/ai-site-look.js +22 -16
- package/src/lib/model/ai-site-look.js.map +1 -1
- package/src/lib/model/ai-site-start.d.ts +37 -7
- package/src/lib/model/ai-site-start.js +54 -10
- package/src/lib/model/ai-site-start.js.map +1 -1
- package/src/lib/model/ai-site-starter-look.d.ts +69 -0
- package/src/lib/model/ai-site-starter-look.js +90 -0
- package/src/lib/model/ai-site-starter-look.js.map +1 -0
- package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -0
- package/src/lib/runtime/ai-doctrine-validators.js +3 -2
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +10 -0
- package/src/lib/runtime/ai-doctrine.js +16 -2
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/server/ai-jobs-resume.js +12 -3
- package/src/lib/server/ai-jobs-resume.js.map +1 -1
- package/src/lib/server/ai-jobs-route.js +5 -1
- package/src/lib/server/ai-jobs-route.js.map +1 -1
- package/src/lib/server/ai-site-import-route.d.ts +6 -0
- package/src/lib/server/ai-site-import-route.js +8 -1
- package/src/lib/server/ai-site-import-route.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +46 -7
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +260 -14
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-improve-answers.d.ts +33 -0
- package/src/lib/site-import/fixtures/site-import-improve-answers.js +457 -0
- package/src/lib/site-import/fixtures/site-import-improve-answers.js.map +1 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +29 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js +26 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/site-import-flag.d.ts +17 -0
- package/src/lib/site-import/site-import-flag.js +15 -0
- package/src/lib/site-import/site-import-flag.js.map +1 -1
|
@@ -0,0 +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,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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AAS/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"}
|
|
@@ -50,6 +50,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
50
50
|
* footer, of the page's listing or of its title in the Pages list.
|
|
51
51
|
*=========================================*/ import { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from "@aglyn/shared-util-tools/untrusted-text";
|
|
52
52
|
import { aiLayoutGuardContacts } from "../layout-language/ai-layout-copy.js";
|
|
53
|
+
import { SITE_IMPORT_POSTAL_PATTERNS } from "../model/ai-site-import-ledger.js";
|
|
53
54
|
import { SITE_IMPORT_MEANING_FLOOR, siteImportContentKept, siteImportFactScope, siteImportFactTokens } from "../model/ai-site-import-fidelity.js";
|
|
54
55
|
import { detectOffVoiceCopy } from "../runtime/ai-doctrine-validators.js";
|
|
55
56
|
import { AI_GENERATION_MAX_ATTEMPTS } from "../runtime/ai-generation-bounds.js";
|
|
@@ -134,11 +135,7 @@ const SHOWN_MAX_CHARS = AI_SITE_IMPORT_WORDING_MAX_CHARS - 1000;
|
|
|
134
135
|
'cards',
|
|
135
136
|
'pricing'
|
|
136
137
|
]);
|
|
137
|
-
|
|
138
|
-
RegExp("\\b\\d{1,6}\\s+(?:[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376-\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0560-\\u0588\\u05D0-\\u05EA\\u05EF-\\u05F2\\u0620-\\u064A\\u066E-\\u066F\\u0671-\\u06D3\\u06D5\\u06E5-\\u06E6\\u06EE-\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4-\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u0860-\\u086A\\u0870-\\u0887\\u0889-\\u088F\\u08A0-\\u08C9\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F-\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC-\\u09DD\\u09DF-\\u09E1\\u09F0-\\u09F1\\u09FC\\u0A05-\\u0A0A\\u0A0F-\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32-\\u0A33\\u0A35-\\u0A36\\u0A38-\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2-\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0-\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F-\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32-\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C-\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99-\\u0B9A\\u0B9C\\u0B9E-\\u0B9F\\u0BA3-\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C5C-\\u0C5D\\u0C60-\\u0C61\\u0C80\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDC-\\u0CDE\\u0CE0-\\u0CE1\\u0CF1-\\u0CF2\\u0D04-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D54-\\u0D56\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32-\\u0E33\\u0E40-\\u0E46\\u0E81-\\u0E82\\u0E84\\u0E86-\\u0E8A\\u0E8C-\\u0EA3\\u0EA5\\u0EA7-\\u0EB0\\u0EB2-\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065-\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16F1-\\u16F8\\u1700-\\u1711\\u171F-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1878\\u1880-\\u1884\\u1887-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4C\\u1B83-\\u1BA0\\u1BAE-\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1C80-\\u1C8A\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1CE9-\\u1CEC\\u1CEE-\\u1CF3\\u1CF5-\\u1CF6\\u1CFA\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183-\\u2184\\u2C00-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3006\\u3031-\\u3035\\u303B-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312F\\u3131-\\u318E\\u31A0-\\u31BF\\u31F0-\\u31FF\\u3400-\\u4DBF\\u4E00-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A-\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6E5\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7DC\\uA7F1-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD-\\uA8FE\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5-\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB69\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40-\\uFB41\\uFB43-\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u{10000}-\\u{1000B}\\u{1000D}-\\u{10026}\\u{10028}-\\u{1003A}\\u{1003C}-\\u{1003D}\\u{1003F}-\\u{1004D}\\u{10050}-\\u{1005D}\\u{10080}-\\u{100FA}\\u{10280}-\\u{1029C}\\u{102A0}-\\u{102D0}\\u{10300}-\\u{1031F}\\u{1032D}-\\u{10340}\\u{10342}-\\u{10349}\\u{10350}-\\u{10375}\\u{10380}-\\u{1039D}\\u{103A0}-\\u{103C3}\\u{103C8}-\\u{103CF}\\u{10400}-\\u{1049D}\\u{104B0}-\\u{104D3}\\u{104D8}-\\u{104FB}\\u{10500}-\\u{10527}\\u{10530}-\\u{10563}\\u{10570}-\\u{1057A}\\u{1057C}-\\u{1058A}\\u{1058C}-\\u{10592}\\u{10594}-\\u{10595}\\u{10597}-\\u{105A1}\\u{105A3}-\\u{105B1}\\u{105B3}-\\u{105B9}\\u{105BB}-\\u{105BC}\\u{105C0}-\\u{105F3}\\u{10600}-\\u{10736}\\u{10740}-\\u{10755}\\u{10760}-\\u{10767}\\u{10780}-\\u{10785}\\u{10787}-\\u{107B0}\\u{107B2}-\\u{107BA}\\u{10800}-\\u{10805}\\u{10808}\\u{1080A}-\\u{10835}\\u{10837}-\\u{10838}\\u{1083C}\\u{1083F}-\\u{10855}\\u{10860}-\\u{10876}\\u{10880}-\\u{1089E}\\u{108E0}-\\u{108F2}\\u{108F4}-\\u{108F5}\\u{10900}-\\u{10915}\\u{10920}-\\u{10939}\\u{10940}-\\u{10959}\\u{10980}-\\u{109B7}\\u{109BE}-\\u{109BF}\\u{10A00}\\u{10A10}-\\u{10A13}\\u{10A15}-\\u{10A17}\\u{10A19}-\\u{10A35}\\u{10A60}-\\u{10A7C}\\u{10A80}-\\u{10A9C}\\u{10AC0}-\\u{10AC7}\\u{10AC9}-\\u{10AE4}\\u{10B00}-\\u{10B35}\\u{10B40}-\\u{10B55}\\u{10B60}-\\u{10B72}\\u{10B80}-\\u{10B91}\\u{10C00}-\\u{10C48}\\u{10C80}-\\u{10CB2}\\u{10CC0}-\\u{10CF2}\\u{10D00}-\\u{10D23}\\u{10D4A}-\\u{10D65}\\u{10D6F}-\\u{10D85}\\u{10E80}-\\u{10EA9}\\u{10EB0}-\\u{10EB1}\\u{10EC2}-\\u{10EC7}\\u{10F00}-\\u{10F1C}\\u{10F27}\\u{10F30}-\\u{10F45}\\u{10F70}-\\u{10F81}\\u{10FB0}-\\u{10FC4}\\u{10FE0}-\\u{10FF6}\\u{11003}-\\u{11037}\\u{11071}-\\u{11072}\\u{11075}\\u{11083}-\\u{110AF}\\u{110D0}-\\u{110E8}\\u{11103}-\\u{11126}\\u{11144}\\u{11147}\\u{11150}-\\u{11172}\\u{11176}\\u{11183}-\\u{111B2}\\u{111C1}-\\u{111C4}\\u{111DA}\\u{111DC}\\u{11200}-\\u{11211}\\u{11213}-\\u{1122B}\\u{1123F}-\\u{11240}\\u{11280}-\\u{11286}\\u{11288}\\u{1128A}-\\u{1128D}\\u{1128F}-\\u{1129D}\\u{1129F}-\\u{112A8}\\u{112B0}-\\u{112DE}\\u{11305}-\\u{1130C}\\u{1130F}-\\u{11310}\\u{11313}-\\u{11328}\\u{1132A}-\\u{11330}\\u{11332}-\\u{11333}\\u{11335}-\\u{11339}\\u{1133D}\\u{11350}\\u{1135D}-\\u{11361}\\u{11380}-\\u{11389}\\u{1138B}\\u{1138E}\\u{11390}-\\u{113B5}\\u{113B7}\\u{113D1}\\u{113D3}\\u{11400}-\\u{11434}\\u{11447}-\\u{1144A}\\u{1145F}-\\u{11461}\\u{11480}-\\u{114AF}\\u{114C4}-\\u{114C5}\\u{114C7}\\u{11580}-\\u{115AE}\\u{115D8}-\\u{115DB}\\u{11600}-\\u{1162F}\\u{11644}\\u{11680}-\\u{116AA}\\u{116B8}\\u{11700}-\\u{1171A}\\u{11740}-\\u{11746}\\u{11800}-\\u{1182B}\\u{118A0}-\\u{118DF}\\u{118FF}-\\u{11906}\\u{11909}\\u{1190C}-\\u{11913}\\u{11915}-\\u{11916}\\u{11918}-\\u{1192F}\\u{1193F}\\u{11941}\\u{119A0}-\\u{119A7}\\u{119AA}-\\u{119D0}\\u{119E1}\\u{119E3}\\u{11A00}\\u{11A0B}-\\u{11A32}\\u{11A3A}\\u{11A50}\\u{11A5C}-\\u{11A89}\\u{11A9D}\\u{11AB0}-\\u{11AF8}\\u{11BC0}-\\u{11BE0}\\u{11C00}-\\u{11C08}\\u{11C0A}-\\u{11C2E}\\u{11C40}\\u{11C72}-\\u{11C8F}\\u{11D00}-\\u{11D06}\\u{11D08}-\\u{11D09}\\u{11D0B}-\\u{11D30}\\u{11D46}\\u{11D60}-\\u{11D65}\\u{11D67}-\\u{11D68}\\u{11D6A}-\\u{11D89}\\u{11D98}\\u{11DB0}-\\u{11DDB}\\u{11EE0}-\\u{11EF2}\\u{11F02}\\u{11F04}-\\u{11F10}\\u{11F12}-\\u{11F33}\\u{11FB0}\\u{12000}-\\u{12399}\\u{12480}-\\u{12543}\\u{12F90}-\\u{12FF0}\\u{13000}-\\u{1342F}\\u{13441}-\\u{13446}\\u{13460}-\\u{143FA}\\u{14400}-\\u{14646}\\u{16100}-\\u{1611D}\\u{16800}-\\u{16A38}\\u{16A40}-\\u{16A5E}\\u{16A70}-\\u{16ABE}\\u{16AD0}-\\u{16AED}\\u{16B00}-\\u{16B2F}\\u{16B40}-\\u{16B43}\\u{16B63}-\\u{16B77}\\u{16B7D}-\\u{16B8F}\\u{16D40}-\\u{16D6C}\\u{16E40}-\\u{16E7F}\\u{16EA0}-\\u{16EB8}\\u{16EBB}-\\u{16ED3}\\u{16F00}-\\u{16F4A}\\u{16F50}\\u{16F93}-\\u{16F9F}\\u{16FE0}-\\u{16FE1}\\u{16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\u{1E5ED}\\u{1E5F0}\\u{1E6C0}-\\u{1E6DE}\\u{1E6E0}-\\u{1E6E2}\\u{1E6E4}-\\u{1E6E5}\\u{1E6E7}-\\u{1E6ED}\\u{1E6F0}-\\u{1E6F4}\\u{1E6FE}-\\u{1E6FF}\\u{1E7E0}-\\u{1E7E6}\\u{1E7E8}-\\u{1E7EB}\\u{1E7ED}-\\u{1E7EE}\\u{1E7F0}-\\u{1E7FE}\\u{1E800}-\\u{1E8C4}\\u{1E900}-\\u{1E943}\\u{1E94B}\\u{1EE00}-\\u{1EE03}\\u{1EE05}-\\u{1EE1F}\\u{1EE21}-\\u{1EE22}\\u{1EE24}\\u{1EE27}\\u{1EE29}-\\u{1EE32}\\u{1EE34}-\\u{1EE37}\\u{1EE39}\\u{1EE3B}\\u{1EE42}\\u{1EE47}\\u{1EE49}\\u{1EE4B}\\u{1EE4D}-\\u{1EE4F}\\u{1EE51}-\\u{1EE52}\\u{1EE54}\\u{1EE57}\\u{1EE59}\\u{1EE5B}\\u{1EE5D}\\u{1EE5F}\\u{1EE61}-\\u{1EE62}\\u{1EE64}\\u{1EE67}-\\u{1EE6A}\\u{1EE6C}-\\u{1EE72}\\u{1EE74}-\\u{1EE77}\\u{1EE79}-\\u{1EE7C}\\u{1EE7E}\\u{1EE80}-\\u{1EE89}\\u{1EE8B}-\\u{1EE9B}\\u{1EEA1}-\\u{1EEA3}\\u{1EEA5}-\\u{1EEA9}\\u{1EEAB}-\\u{1EEBB}\\u{20000}-\\u{2A6DF}\\u{2A700}-\\u{2B81D}\\u{2B820}-\\u{2CEAD}\\u{2CEB0}-\\u{2EBE0}\\u{2EBF0}-\\u{2EE5D}\\u{2F800}-\\u{2FA1D}\\u{30000}-\\u{3134A}\\u{31350}-\\u{33479}\\d'.-]+\\s+){0,4}(?:street|st|avenue|ave|road|rd|boulevard|blvd|lane|ln|drive|dr|way|court|ct|place|pl|parkway|pkwy|highway|hwy|trail|trl|circle|cir|square|sq|suite|ste)\\b", "iu"),
|
|
139
|
-
/\bp\.?\s?o\.?\s+box\s+\d/iu,
|
|
140
|
-
/\b[A-Z]{2}\s+\d{5}(?:-\d{4})?\b/u
|
|
141
|
-
];
|
|
138
|
+
const POSTAL = SITE_IMPORT_POSTAL_PATTERNS;
|
|
142
139
|
const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : '';
|
|
143
140
|
/** Whether a block is a line of the page: a link inside a sentence is in its sentence. */ function isLine(block) {
|
|
144
141
|
if (!block) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-wording.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 * A PAGE BROUGHT IN, ITS WORDING IMPROVED (AGL-4152).\n *\n * Under Improve it with Also improve my wording on, a main page Aglyn AI\n * arranges is asked one more answer after its design: `submit_wording`, the\n * lines it rewords, each by its index in the page's blocks with its new\n * words. Nothing else rides the tool — no link, no picture, no structure —\n * so the page's sections, groups, buttons and destinations are the source's\n * whatever it says.\n *\n * - **What may be reworded** (`aiSiteImportWordingPage`): headings,\n * paragraphs, list items and a link the source draws as a button, the\n * words of FAQ, card, step and list items among them. Everything else is\n * kept as written: quotes and testimonials, pricing, stats and logos,\n * card titles, figures, badges, tables, tabs, eyebrows and fine print, a\n * paragraph with a link inside it, a postal address, an email or phone\n * link, and every line with no words.\n * - **What every rewrite holds** (`aiSiteImportWordingHolds`, pure): its\n * facts — prices, numbers, dates, times, percentages, emails, web\n * addresses, phones and names, the site's own name among them — exactly as\n * often as its line says them and none of its own; no contact the page\n * does not give; no gap; its line's script; 0.5 to 1.6 times its words,\n * within the characters its place holds; most of its meaning\n * (`SITE_IMPORT_MEANING_FLOOR`); and no filler, placeholder or judgment\n * word. A line refused is asked again once; refused again, it is kept as\n * written.\n * - **The page** (`aiSiteImportRewordedDocument`): the source's document\n * with the rewritten lines' words swapped in, every block at its index and\n * the source's own layout pinned, which the page step compiles and checks\n * whole as any page brought in, rule 14's copy checks on for the reworded\n * lines (`AiDoctrineTreeContext.rewritten`).\n *\n * Never asked of a page copied as it is, of a policy page, of the header and\n * footer, of the page's listing or of its title in the Pages list.\n *=========================================*/\n\nimport { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from '@aglyn/shared-util-tools/untrusted-text'\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport type { SiteImportLayoutNode, SiteImportLineRef } from '../model/ai-site-import'\nimport {\n SITE_IMPORT_MEANING_FLOOR,\n siteImportContentKept,\n siteImportFactScope,\n siteImportFactTokens,\n type SiteImportFactScope,\n} from '../model/ai-site-import-fidelity'\nimport type { AiSystemBlock, AiTool } from '../providers/contract'\nimport type { AiGenerationCheck } from '../runtime/ai-doctrine'\nimport { detectOffVoiceCopy, type AiCopyFraming, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { AI_GENERATION_MAX_ATTEMPTS } from '../runtime/ai-generation-bounds'\nimport { aiPlaceholderTokens } from '../runtime/ai-placeholder-tokens'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\nimport type { SiteImportBlock } from '../site-import/site-import-html'\nimport { aiSiteImportLayoutOf } from './ai-site-import-compile'\nimport {\n AI_SITE_IMPORT_HEADLINE_MAX_CHARS,\n AI_SITE_IMPORT_LABEL_CHARS,\n AI_SITE_IMPORT_TEXT_MAX_CHARS,\n aiSiteImportWordsIn,\n type AiSiteImportDocument,\n} from './ai-site-import-document'\n\n/*------------------------------------------\n * The tool and its cached instructions\n *-----------------------------------------*/\n\n/** The wording answer's kind of generation: the name its re-ask and its doctrine scope go by. */\nexport const AI_SITE_IMPORT_WORDING_KIND = 'page-wording'\n\n/** The wording tool: the lines reworded, each by its number, with its new words, and nothing else. */\nexport const AI_SITE_IMPORT_WORDING_TOOL: AiTool = {\n name: 'submit_wording',\n description: \"Submit the page's reworded lines: one entry for each line reworded, by its number, with its new words. A line left out keeps its words.\",\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['lines'],\n properties: {\n lines: {\n type: 'array',\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['line', 'text'],\n properties: { line: { type: 'integer' }, text: { type: 'string' } },\n },\n },\n },\n },\n}\n\n/** The most a rewrite may run to, against its line's words. */\nexport const AI_SITE_IMPORT_WORDING_LENGTH = { least: 0.5, most: 1.6 } as const\n\n/**\n * What a wording answer is told, cached: one static block every page shares,\n * and the rule that fenced text is data. The page itself rides the user turn.\n */\nexport const AI_SITE_IMPORT_WORDING_TEXT = [\n \"You rewrite the wording of a page brought in from its owner's own website so it reads as a strong professional copywriter would write it, in the owner's voice: each heading a clear, specific promise of what the visitor gets, each paragraph leading with the benefit, in active words, with nothing that does not earn its place. Rebuild a sentence freely where that makes it clearer or stronger. The page's design, its sections and what each section shows are fixed, and so is every fact on it.\",\n '',\n 'Answer with submit_wording: one entry in lines for each line you reword, by its number, with its new words. A line you leave out is kept exactly as written. Rewrite every heading, lede, paragraph and button that could be clearer or stronger, and leave out only a line that is already as strong as it can be. Reword only a line shown as a heading, a paragraph, a list item or a button; a line shown \"as written\" is the owner\\'s exactly and is never answered.',\n '',\n 'Each rewrite:',\n \"- says what its line means, in the line's own language and script, and makes no claim, promise, offer or detail the page does not make;\",\n '- keeps every name, price, number, date, time, percentage, address, phone number, email and web address exactly as the line writes it, as often as the line has it, and adds none;',\n `- runs between ${AI_SITE_IMPORT_WORDING_LENGTH.least} and ${AI_SITE_IMPORT_WORDING_LENGTH.most} times its line's words, and never past the characters shown;`,\n '- stays what its line is: a heading for a heading, a sentence or more for a paragraph, a short label for a button;',\n '- writes no placeholder, no gap in brackets, no filler and no word that calls the work simple or cheap.',\n].join('\\n')\n\n/** The wording answer's cached instructions, and the rule that fenced text is data. */\nexport const AI_SITE_IMPORT_WORDING_INSTRUCTIONS: readonly AiSystemBlock[] = [\n { text: AI_SITE_IMPORT_WORDING_TEXT, cacheBreakpoint: true },\n { text: UNTRUSTED_TEXT_RULE },\n]\n\n/*------------------------------------------\n * The page's lines: those it may reword, and those kept as written\n *-----------------------------------------*/\n\n/** What a line is, as the prompt names it and its place holds it. */\nexport type AiSiteImportWordingKind = 'heading' | 'paragraph' | 'list item' | 'button'\n\n/** A line a rewrite may reword. */\nexport interface AiSiteImportWordingLine {\n /** Its index in the page's blocks: the number the tool answers by. */\n line: SiteImportLineRef\n kind: AiSiteImportWordingKind\n /** Its words as written. */\n text: string\n /** The most characters a rewrite of it holds. */\n limit: number\n /** Its section, by index. */\n section: number\n}\n\n/** One entry of the page as the prompt shows it: a line to reword, one kept as written, or a part with no lines of the tool. */\nexport interface AiSiteImportWordingEntry {\n section: number\n /** The line's number, absent for a part shown whole (a table). */\n line?: SiteImportLineRef\n /** What it is: \"heading\", \"quote\", \"a table of 4 rows\". */\n what: string\n text: string\n /** Set where a rewrite may reword it. */\n reword?: AiSiteImportWordingLine\n}\n\n/** A page as the wording answer is shown it. */\nexport interface AiSiteImportWordingPage {\n /** The page's sections' names, in order. */\n sections: string[]\n /** Every entry, in order, as far as the prompt's room goes. */\n entries: AiSiteImportWordingEntry[]\n /** The lines a rewrite may reword: those shown. */\n lines: AiSiteImportWordingLine[]\n /** Whether the page runs past what the prompt shows: the rest keeps its words. */\n cut: boolean\n}\n\n/** The most characters of a page the wording prompt shows, inside the fence's cap with room for its section heads. */\nexport const AI_SITE_IMPORT_WORDING_MAX_CHARS = 12_000\nconst SHOWN_MAX_CHARS = AI_SITE_IMPORT_WORDING_MAX_CHARS - 1_000\n\n/** The most characters of a line kept as written the prompt shows: it is there to be read around, never answered. */\nconst KEPT_SHOWN_CHARS = 160\n\n/** Groups whose every line is the owner's exactly: quotes, prices, figures, names. */\nconst FIXED_GROUPS = new Set(['quotes', 'pricing', 'stats', 'logos'])\n\n/** Groups whose items' titles are names: a card's title is a product's or a service's. */\nconst NAMED_GROUPS = new Set(['cards', 'pricing'])\n\n/** A postal address as a page writes one: a house number, a few words and a street word; a PO box; a region and postal code. */\nconst POSTAL = [\n /\\b\\d{1,6}\\s+(?:[\\p{L}\\d'.-]+\\s+){0,4}(?:street|st|avenue|ave|road|rd|boulevard|blvd|lane|ln|drive|dr|way|court|ct|place|pl|parkway|pkwy|highway|hwy|trail|trl|circle|cir|square|sq|suite|ste)\\b/iu,\n /\\bp\\.?\\s?o\\.?\\s+box\\s+\\d/iu,\n /\\b[A-Z]{2}\\s+\\d{5}(?:-\\d{4})?\\b/u,\n] as const\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** Whether a block is a line of the page: a link inside a sentence is in its sentence. */\nfunction isLine(block: SiteImportBlock | undefined): boolean {\n if (!block) return false\n if (block.kind === 'image') return !!block.url\n if (block.kind === 'link') return !block.inline && !!clean(block.text)\n return !!clean(block.text)\n}\n\n/** The most characters a rewrite of a line holds: its place's, or the line's own where it already runs past it. */\nfunction limitOf(kind: AiSiteImportWordingKind, text: string, title: boolean): number {\n const place =\n kind === 'heading'\n ? AI_SITE_IMPORT_HEADLINE_MAX_CHARS\n : kind === 'button'\n ? AI_SITE_IMPORT_LABEL_CHARS\n : title\n ? AI_TEXT_LIMITS.label\n : AI_SITE_IMPORT_TEXT_MAX_CHARS\n return text.length > place ? text.length : place\n}\n\n/** Tokens a line's words come to, as the ceiling plans them: four characters a token, and the entry around it. */\nconst tokensOf = (line: AiSiteImportWordingLine) => Math.ceil(line.text.length / 4) + 12\n\n/** Room for the thinking a wording answer does before it writes, inside its ceiling. */\nexport const AI_SITE_IMPORT_WORDING_THINKING_TOKENS = 1_000\n\n/** How much of a page the wording answer is shown. */\nexport interface AiSiteImportWordingRoom {\n /** The most characters of the page the prompt shows. */\n maxChars?: number\n /** The ceiling the answer is asked at: the lines offered are those a rewrite of every one fits in (`aiSiteImportWordingTokens`). */\n maxTokens?: number\n}\n\n/**\n * The page as the wording answer is shown it (G1, G2): its sections and,\n * in each, its lines in order, each marked as a line a rewrite may reword\n * or one kept as written. A line is reworded only where every place the\n * layout puts it allows it. The lines shown stop where the prompt's room,\n * or the answer's ceiling, does; those past it keep their words.\n */\nexport function aiSiteImportWordingPage(doc: Pick<AiSiteImportDocument, 'blocks' | 'title' | 'layout'>, room: AiSiteImportWordingRoom = {}): AiSiteImportWordingPage {\n const maxChars = room.maxChars ?? SHOWN_MAX_CHARS\n const maxTokens = room.maxTokens ?? Number.POSITIVE_INFINITY\n const layout = aiSiteImportLayoutOf(doc)\n const fixed = new Set<SiteImportLineRef>()\n const order: Array<{ section: number; ref?: SiteImportLineRef; what?: string; reword?: { kind: AiSiteImportWordingKind; title: boolean } }> = []\n const seen = new Set<SiteImportLineRef>()\n\n const kept = (section: number, ref: SiteImportLineRef | undefined) => {\n if (ref === undefined || !isLine(doc.blocks[ref]) || doc.blocks[ref]?.kind === 'image') return\n fixed.add(ref)\n if (!seen.has(ref)) {\n seen.add(ref)\n order.push({ section, ref })\n }\n }\n // A line placed where a rewrite may reach it, unless what it says keeps it as written.\n const offer = (section: number, ref: SiteImportLineRef | undefined, place: { button?: boolean; role?: string; title?: boolean } = {}) => {\n if (ref === undefined) return\n const block = doc.blocks[ref]\n if (!block || !isLine(block) || block.kind === 'image') return\n const kind = rewordable(ref, block, place)\n if (!kind) return kept(section, ref)\n if (!seen.has(ref)) {\n seen.add(ref)\n order.push({ section, ref, reword: { kind, title: !!place.title } })\n }\n }\n const rewordable = (ref: SiteImportLineRef, block: SiteImportBlock, place: { button?: boolean; role?: string }): AiSiteImportWordingKind | null => {\n if (block.kind === 'image' || block.kind === 'quote') return null\n const text = clean(block.text)\n if (!aiSiteImportWordsIn(text) || !/\\p{L}/u.test(text)) return null\n if (POSTAL.some((pattern) => pattern.test(text))) return null\n // A label the source sets apart, or its fine print, is the owner's as written.\n if (place.role === 'eyebrow' || place.role === 'note') return null\n if (block.kind === 'link') {\n if (!place.button || /^(?:mailto|tel|sms):/i.test(block.href)) return null\n return 'button'\n }\n // A sentence with a link inside it keeps its words, so the link's words are still in it.\n const next = doc.blocks[ref + 1]\n if (next?.kind === 'link' && next.inline) return null\n if (block.kind === 'heading') return 'heading'\n if (block.kind === 'list-item') return 'list item'\n return 'paragraph'\n }\n\n const walk = (nodes: readonly SiteImportLayoutNode[], section: number, whole: boolean): void => {\n for (const node of nodes) {\n switch (node.kind) {\n case 'line':\n if (whole) kept(section, node.line)\n else offer(section, node.line, { button: !!node.button, ...(node.role ? { role: node.role } : {}) })\n break\n case 'row':\n for (const cell of node.cells) walk(cell.nodes, section, whole)\n break\n case 'group': {\n const all = whole || FIXED_GROUPS.has(node.group)\n for (const item of node.items) {\n const ctas = new Set((item.ctas ?? []).map((cta) => cta.line))\n const named = new Set<SiteImportLineRef>()\n const place = (ref: SiteImportLineRef | undefined, how: { button?: boolean; title?: boolean } = {}) => {\n if (ref === undefined) return\n named.add(ref)\n if (all) kept(section, ref)\n else offer(section, ref, how)\n }\n // A card's title names its product or service; a figure, a badge and a period are facts.\n if (NAMED_GROUPS.has(node.group)) {\n if (item.title !== undefined) named.add(item.title)\n kept(section, item.title)\n } else place(item.title, { title: true })\n for (const ref of [item.figure, item.badge, item.period]) {\n if (ref === undefined) continue\n named.add(ref)\n kept(section, ref)\n }\n for (const ref of item.text ?? []) place(ref)\n for (const ref of item.list ?? []) place(ref)\n for (const ref of item.link ?? []) {\n if (ctas.has(ref)) place(ref, { button: true })\n else {\n named.add(ref)\n kept(section, ref)\n }\n }\n for (const ref of item.lines) if (!named.has(ref) && ref !== item.image) kept(section, ref)\n }\n break\n }\n case 'table': {\n for (const row of node.rows) {\n for (const cell of row.cells) {\n for (const ref of cell.lines) {\n fixed.add(ref)\n seen.add(ref)\n }\n }\n }\n order.push({ section, what: `a table of ${node.rows.length} ${node.rows.length === 1 ? 'row' : 'rows'}` })\n break\n }\n case 'tabs':\n for (const tab of node.tabs) {\n kept(section, tab.label ?? undefined)\n walk(tab.panel, section, true)\n }\n break\n default:\n break\n }\n }\n }\n layout.sections.forEach((section, index) => {\n walk(section.nodes, index, false)\n // A line of the section no part of its layout places keeps its words.\n for (const ref of section.lines) if (!seen.has(ref)) kept(index, ref)\n })\n\n const all: AiSiteImportWordingEntry[] = order.map((entry) => {\n if (entry.ref === undefined) return { section: entry.section, what: `${entry.what ?? 'a part'}, as written`, text: '' }\n const block = doc.blocks[entry.ref] as SiteImportBlock\n const text = block.kind === 'image' ? '' : clean(block.text)\n const reword = entry.reword && !fixed.has(entry.ref) ? entry.reword : null\n if (!reword) {\n return { section: entry.section, line: entry.ref, what: block.kind === 'quote' ? 'quote, as written' : 'as written', text: text.length > KEPT_SHOWN_CHARS ? `${text.slice(0, KEPT_SHOWN_CHARS).trimEnd()} …` : text }\n }\n const line: AiSiteImportWordingLine = { line: entry.ref, kind: reword.kind, text, limit: limitOf(reword.kind, text, reword.title), section: entry.section }\n // A paragraph's own ceiling is far past what 1.6 times its words reach: only a tighter place's is shown.\n const bound = line.limit < AI_SITE_IMPORT_TEXT_MAX_CHARS\n return { section: entry.section, line: entry.ref, what: bound ? `${line.kind}, up to ${line.limit} characters` : line.kind, text, reword: line }\n })\n const entries: AiSiteImportWordingEntry[] = []\n const lines: AiSiteImportWordingLine[] = []\n let chars = 0\n let tokens = 0\n let cut = false\n for (const entry of shortened(all)) {\n chars += entry.what.length + entry.text.length + 12\n if (entry.reword) tokens += tokensOf(entry.reword)\n if (chars > maxChars || 2 * tokens + AI_SITE_IMPORT_WORDING_THINKING_TOKENS > maxTokens) {\n cut = true\n break\n }\n entries.push(entry)\n if (entry.reword) lines.push(entry.reword)\n }\n return { sections: layout.sections.map((section) => section.name), entries, lines, cut }\n}\n\n/** The most lines kept as written the prompt shows in a row: a run longer than this shows its first two, and how many follow. */\nconst KEPT_RUN = 3\n\n/**\n * The page's entries with each long run of lines kept as written told in a\n * few: a plan's prices or a table's cells are there to be read around, and\n * a run of them would crowd out the lines that are the answer's to reword.\n */\nfunction shortened(entries: readonly AiSiteImportWordingEntry[]): AiSiteImportWordingEntry[] {\n const out: AiSiteImportWordingEntry[] = []\n for (let at = 0; at < entries.length; ) {\n const first = entries[at] as AiSiteImportWordingEntry\n if (first.reword) {\n out.push(first)\n at += 1\n continue\n }\n let end = at\n while (end < entries.length && !entries[end]?.reword && entries[end]?.section === first.section) end += 1\n const run = entries.slice(at, end)\n if (run.length > KEPT_RUN) {\n out.push(...run.slice(0, 2), { section: first.section, what: `${run.length - 2} more lines, as written`, text: '' })\n } else out.push(...run)\n at = end\n }\n return out\n}\n\n/*------------------------------------------\n * The prompt\n *-----------------------------------------*/\n\n/** The page's lines as the fence holds them: each section's name, then its lines, numbered. */\nexport function aiSiteImportWordingText(page: AiSiteImportWordingPage): string {\n const out: string[] = []\n let section = -1\n for (const entry of page.entries) {\n if (entry.section !== section) {\n section = entry.section\n out.push(`Section ${section + 1} \"${page.sections[section] ?? ''}\":`)\n }\n out.push(entry.line === undefined ? `- ${entry.what}` : `[${entry.line}] ${entry.what}: ${entry.text}`)\n }\n if (page.cut) out.push('(The page goes on past here; the rest keeps its words.)')\n return out.join('\\n')\n}\n\n/** A wording answer's user turn: the page, the site's own name, and its lines, fenced as the owner's data. */\nexport function aiSiteImportWordingPrompt(input: {\n screen: { title: string; slug: string }\n doc: Pick<AiSiteImportDocument, 'url'>\n page: AiSiteImportWordingPage\n siteName?: string | null\n}): string {\n const name = clean(input.siteName)\n const count = input.page.lines.length\n return [\n `Page: \"${input.screen.title}\" at ${input.screen.slug}`,\n ...(name ? [\"The site's own name, which every rewrite writes exactly as it is wherever its line says it:\", fenceUntrustedText(\"The site's name\", name, { maxChars: 200 })] : []),\n `Its lines, in order, ${count === 1 ? 'one of them' : `${count} of them`} yours to reword, each with its number and what it is, and the most characters a rewrite may hold where its place holds fewer than a paragraph:`,\n fenceUntrustedText(`The words of the owner's page ${input.doc.url}`, aiSiteImportWordingText(input.page), { maxChars: AI_SITE_IMPORT_WORDING_MAX_CHARS }),\n ].join('\\n')\n}\n\n/**\n * The ceiling a page's wording answer wants (G1): twice its lines' own\n * tokens, so a rewrite of every line fits with room, and its thinking.\n * The page step holds it to the time the design answer leaves.\n */\nexport function aiSiteImportWordingTokens(page: AiSiteImportWordingPage): number {\n return 2 * page.lines.reduce((sum, line) => sum + tokensOf(line), 0) + AI_SITE_IMPORT_WORDING_THINKING_TOKENS\n}\n\n/*------------------------------------------\n * The answer, and what every rewrite holds\n *-----------------------------------------*/\n\n/** One line as an answer rewords it. */\nexport interface AiSiteImportRewrite {\n line: number\n text: string\n}\n\n/** An answer's lines, read defensively: each with a whole number and words; `null` where it has no list of lines. */\nexport function aiReadWordingAnswer(answer: Record<string, unknown> | null | undefined): AiSiteImportRewrite[] | null {\n const lines = answer?.['lines']\n if (!Array.isArray(lines)) return null\n return lines.flatMap((entry): AiSiteImportRewrite[] => {\n if (!entry || typeof entry !== 'object') return []\n const { line, text } = entry as Record<string, unknown>\n return typeof line === 'number' && Number.isInteger(line) && typeof text === 'string' ? [{ line, text }] : []\n })\n}\n\n/** Why a rewrite was refused (G3). */\nexport type AiSiteImportWordingCode =\n | 'wording-no-line'\n | 'wording-fixed-line'\n | 'wording-repeated-line'\n | 'wording-empty'\n | 'wording-script'\n | 'wording-length'\n | 'wording-dropped-fact'\n | 'wording-dropped-name'\n | 'wording-invented-fact'\n | 'wording-gap'\n | 'wording-meaning'\n | 'wording-copy'\n\n/** A rewrite refused, and why. */\nexport interface AiSiteImportWordingRefusal {\n line: number\n code: AiSiteImportWordingCode\n /** What the model is told: what the line broke and what to do. */\n message: string\n /** What it broke, beyond the message: the facts it dropped or added. */\n detail?: string\n}\n\n/** What a page's rewrites are held to beyond their own lines. */\nexport interface AiSiteImportWordingScope {\n doc: Pick<AiSiteImportDocument, 'blocks'>\n page: Pick<AiSiteImportWordingPage, 'lines'>\n /** The site's own name, which every rewrite says as often as its line does. */\n siteName?: string | null\n /** Who the copy is framed for: agency and enterprise copy holds to the judgment-word rule. */\n framing?: AiCopyFraming\n}\n\n/** The rewrites that hold, by line, and those refused. */\nexport interface AiSiteImportWordingHeld {\n held: Map<number, string>\n refused: AiSiteImportWordingRefusal[]\n}\n\n/** The scripts a line is told apart by; Chinese and Japanese writing count as one. */\nconst SCRIPTS: ReadonlyArray<readonly [string, RegExp]> = [\n ['latin', /\\p{Script=Latin}/u],\n ['cyrillic', /\\p{Script=Cyrillic}/u],\n ['greek', /\\p{Script=Greek}/u],\n ['arabic', /\\p{Script=Arabic}/u],\n ['hebrew', /\\p{Script=Hebrew}/u],\n ['cjk', /[\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}]/u],\n ['hangul', /\\p{Script=Hangul}/u],\n ['thai', /\\p{Script=Thai}/u],\n ['devanagari', /\\p{Script=Devanagari}/u],\n]\n\n/** The script most of a line's letters are written in; `null` for a line with none. */\nexport function aiSiteImportScriptOf(text: string): string | null {\n const counts = new Map<string, number>()\n for (const char of text) {\n if (!/\\p{L}/u.test(char)) continue\n const script = SCRIPTS.find(([, pattern]) => pattern.test(char))?.[0] ?? 'other'\n counts.set(script, (counts.get(script) ?? 0) + 1)\n }\n let best: string | null = null\n let most = 0\n for (const [script, count] of counts) {\n if (count > most) {\n best = script\n most = count\n }\n }\n return best\n}\n\n/** How often a run of words says a name, whole, in any case. */\nfunction timesSaid(text: string, name: string): number {\n if (!name) return 0\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\s+/g, '\\\\s+')\n return [...text.matchAll(new RegExp(`(?<![\\\\p{L}\\\\p{N}])${escaped}(?![\\\\p{L}\\\\p{N}])`, 'giu'))].length\n}\n\n/** Each token of `a` not matched by one of `b`, as often as it is short. */\nfunction short(a: readonly string[], b: readonly string[]): string[] {\n const left = new Map<string, number>()\n for (const token of b) left.set(token, (left.get(token) ?? 0) + 1)\n const out: string[] = []\n for (const token of a) {\n const count = left.get(token) ?? 0\n if (count > 0) left.set(token, count - 1)\n else out.push(token)\n }\n return out\n}\n\n/** A fact token as the model reads it: its words, not its kind. */\nconst shownFact = (token: string) => `\"${token.replace(/^[a-z]+:/, '')}\"`\n\n/** The words of every line of the page as written: the facts a rewrite's contact details are held to. */\nfunction pageText(doc: Pick<AiSiteImportDocument, 'blocks'>): string {\n return doc.blocks.map((block) => (block.kind === 'image' ? clean(block.alt) : clean(block.text))).filter(Boolean).join('\\n')\n}\n\n/**\n * Every rule a rewrite is held to (G2, G3), pure, one line at a time: a\n * rewrite that breaks one is refused, and its line keeps its words. A\n * rewrite the same as its line is no rewrite, and is neither.\n */\nexport function aiSiteImportWordingHolds(scope: AiSiteImportWordingScope, rewrites: readonly AiSiteImportRewrite[]): AiSiteImportWordingHeld {\n const allowed = new Map(scope.page.lines.map((line) => [line.line, line]))\n const sources = scope.doc.blocks.flatMap((block) => (isLine(block) && block.kind !== 'image' ? [clean(block.text)] : []))\n const facts: SiteImportFactScope = siteImportFactScope(sources)\n const contacts = pageText(scope.doc)\n const name = clean(scope.siteName)\n const held = new Map<number, string>()\n const refused: AiSiteImportWordingRefusal[] = []\n const answered = new Set<number>()\n for (const rewrite of rewrites) {\n const at = rewrite.line\n const refuse = (code: AiSiteImportWordingCode, message: string, detail?: string) => refused.push({ line: at, code, message: `Line ${at}: ${message}`, ...(detail ? { detail } : {}) })\n if (answered.has(at)) {\n refuse('wording-repeated-line', 'it was answered more than once. Give each line once.')\n continue\n }\n answered.add(at)\n const block = scope.doc.blocks[at]\n if (!block || !isLine(block)) {\n refuse('wording-no-line', 'there is no such line on this page. Answer only the lines shown, by their numbers.')\n continue\n }\n const line = allowed.get(at)\n if (!line) {\n refuse('wording-fixed-line', 'it is kept exactly as the owner wrote it. Leave it out.')\n continue\n }\n const text = clean(rewrite.text)\n if (!text) {\n refuse('wording-empty', 'it was given no words. Leave a line out to keep it as written; never empty it.')\n continue\n }\n if (text === line.text) continue\n if (aiSiteImportScriptOf(text) !== aiSiteImportScriptOf(line.text)) {\n refuse('wording-script', \"it is not written in the line's own language. Write it in the language and script the line is in.\")\n continue\n }\n const words = aiSiteImportWordsIn(text)\n const source = aiSiteImportWordsIn(line.text)\n if (words < AI_SITE_IMPORT_WORDING_LENGTH.least * source || words > AI_SITE_IMPORT_WORDING_LENGTH.most * source || text.length > line.limit) {\n const least = Math.ceil(AI_SITE_IMPORT_WORDING_LENGTH.least * source)\n const most = Math.floor(AI_SITE_IMPORT_WORDING_LENGTH.most * source)\n refuse(\n 'wording-length',\n `it runs to ${words} ${words === 1 ? 'word' : 'words'} and ${text.length} characters. Keep it between ${least} and ${most} words, and within ${line.limit} characters.`,\n `The line has ${source} ${source === 1 ? 'word' : 'words'}.`,\n )\n continue\n }\n const before = siteImportFactTokens(line.text, facts, false)\n const after = siteImportFactTokens(text, facts, true)\n const nameBefore = timesSaid(line.text, name)\n const nameAfter = timesSaid(text, name)\n const dropped = short(before, after)\n const added = short(after, before)\n const names = [...dropped.filter((token) => token.startsWith('name:')), ...(nameAfter < nameBefore ? [`name:${name}`] : [])]\n if (names.length) {\n refuse('wording-dropped-name', 'it leaves out a name the line says. Keep every name exactly as the line writes it, as often.', `Left out: ${[...new Set(names)].map(shownFact).join(', ')}.`)\n continue\n }\n if (dropped.length) {\n refuse(\n 'wording-dropped-fact',\n 'it leaves out a fact the line says. Keep every price, number, date, time, percentage, address, phone number, email and web address exactly as the line writes it, as often.',\n `Left out: ${[...new Set(dropped)].map(shownFact).join(', ')}.`,\n )\n continue\n }\n const guarded = aiLayoutGuardContacts(text, contacts)\n if (added.length || nameAfter > nameBefore || guarded !== text) {\n const shown = [...new Set([...added, ...(nameAfter > nameBefore ? [`name:${name}`] : [])])]\n refuse('wording-invented-fact', 'it adds a fact or a name the line does not say. Add none of your own.', shown.length ? `Added: ${shown.map(shownFact).join(', ')}.` : undefined)\n continue\n }\n if (/\\[[^\\]]*\\]/.test(text) && !/\\[[^\\]]*\\]/.test(line.text)) {\n refuse('wording-gap', 'it leaves a gap in square brackets. Write the line whole, from its own words.')\n continue\n }\n if (siteImportContentKept(line.text, text) < SITE_IMPORT_MEANING_FLOOR) {\n refuse('wording-meaning', \"it no longer says what the line says. Keep its meaning and most of its words' substance.\")\n continue\n }\n if (detectOffVoiceCopy([{ at: 'line', text }], scope.framing ?? null).length || aiPlaceholderTokens(text).length) {\n refuse('wording-copy', \"it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words from the line's own.\")\n continue\n }\n held.set(at, text)\n }\n return { held, refused }\n}\n\n/** A refusal as the re-ask names it. */\nexport function aiSiteImportWordingViolation(refusal: AiSiteImportWordingRefusal): AiDoctrineViolation {\n const shape = refusal.code === 'wording-no-line' || refusal.code === 'wording-fixed-line' || refusal.code === 'wording-repeated-line'\n return { rule: shape ? null : 14, code: refusal.code, message: refusal.message, ...(refusal.detail ? { detail: refusal.detail } : {}) }\n}\n\n/*------------------------------------------\n * The page reworded\n *-----------------------------------------*/\n\n/**\n * The page with its rewrites (G3): the source's document, each rewritten\n * line's words in place of its own and every block at its index, its layout\n * pinned to the source's so no section moves or is renamed. An image, or a\n * line no rewrite names, is the source's.\n */\nexport function aiSiteImportRewordedDocument(doc: AiSiteImportDocument, rewrites: ReadonlyMap<number, string>): AiSiteImportDocument {\n return {\n ...doc,\n layout: aiSiteImportLayoutOf(doc),\n blocks: doc.blocks.map((block, index) => {\n const text = rewrites.get(index)\n return text === undefined || block.kind === 'image' ? block : { ...block, text }\n }),\n }\n}\n\n/** A page's wording, settled: the page built in its rewrites, and the lines kept as written after their re-ask. */\nexport interface AiSiteImportWorded<T> {\n built: T\n /** The lines reworded, by number. */\n rewrites: Map<number, string>\n /** The lines refused twice, which keep their words. */\n kept: AiSiteImportWordingRefusal[]\n}\n\n/**\n * The wording answer's check (G3): every rewrite held line by line, a\n * refused one asked again once — the lines that held are kept between the\n * answers — and the page built whole in what held (`build`, the page step's\n * check of a page brought in, with rule 14 on for the rewritten lines). On\n * the last answer a line refused again keeps its words; a page that cannot\n * be built in its rewrites is refused whole, and the page step keeps the\n * page's words.\n *\n * Stateful across one generation's answers: make one for each.\n */\nexport function aiSiteImportWordingCheck<T>(input: AiSiteImportWordingScope & {\n doc: AiSiteImportDocument\n build: (reworded: AiSiteImportDocument, rewritten: readonly string[]) => { value: T | null; violations: AiDoctrineViolation[] }\n /** The answers one generation makes; the last keeps a line refused again as written. */\n attempts?: number\n}): AiGenerationCheck<AiSiteImportWorded<T>> {\n const attempts = input.attempts ?? AI_GENERATION_MAX_ATTEMPTS\n const held = new Map<number, string>()\n let answers = 0\n return (answer) => {\n answers += 1\n const rewrites = aiReadWordingAnswer(answer)\n if (!rewrites) return { value: null, violations: [{ rule: null, code: 'wording-unreadable', message: 'The answer gave no list of lines. Answer with submit_wording.' }] }\n const checked = aiSiteImportWordingHolds(input, rewrites)\n for (const [line, text] of checked.held) held.set(line, text)\n // A line refused now that held in an earlier answer keeps that rewrite.\n const refused = checked.refused.filter((refusal) => !held.has(refusal.line))\n if (refused.length && answers < attempts) {\n return {\n value: null,\n violations: [\n ...refused.map(aiSiteImportWordingViolation),\n {\n rule: null,\n code: 'wording-kept-lines',\n message: `Every other line you reworded holds and is kept. Answer again with ${refused.length === 1 ? 'that line' : 'those lines'} alone, or leave ${refused.length === 1 ? 'it' : 'them'} out to keep the owner's words.`,\n },\n ],\n offending: { lines: rewrites.filter((rewrite) => refused.some((refusal) => refusal.line === rewrite.line)) },\n }\n }\n const reworded = aiSiteImportRewordedDocument(input.doc, held)\n const built = input.build(reworded, [...held.values()])\n if (!built.value) return { value: null, violations: built.violations }\n return { value: { built: built.value, rewrites: new Map(held), kept: refused }, violations: [] }\n }\n}\n"],"names":["fenceUntrustedText","UNTRUSTED_TEXT_RULE","aiLayoutGuardContacts","SITE_IMPORT_MEANING_FLOOR","siteImportContentKept","siteImportFactScope","siteImportFactTokens","detectOffVoiceCopy","AI_GENERATION_MAX_ATTEMPTS","aiPlaceholderTokens","AI_TEXT_LIMITS","aiSiteImportLayoutOf","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_TEXT_MAX_CHARS","aiSiteImportWordsIn","AI_SITE_IMPORT_WORDING_KIND","AI_SITE_IMPORT_WORDING_TOOL","name","description","strict","inputSchema","type","additionalProperties","required","properties","lines","items","line","text","AI_SITE_IMPORT_WORDING_LENGTH","least","most","AI_SITE_IMPORT_WORDING_TEXT","join","AI_SITE_IMPORT_WORDING_INSTRUCTIONS","cacheBreakpoint","AI_SITE_IMPORT_WORDING_MAX_CHARS","SHOWN_MAX_CHARS","KEPT_SHOWN_CHARS","FIXED_GROUPS","Set","NAMED_GROUPS","POSTAL","clean","replace","trim","isLine","block","kind","url","inline","limitOf","title","place","label","length","tokensOf","Math","ceil","AI_SITE_IMPORT_WORDING_THINKING_TOKENS","aiSiteImportWordingPage","doc","room","maxChars","maxTokens","Number","POSITIVE_INFINITY","layout","fixed","order","seen","kept","section","ref","undefined","blocks","add","has","push","offer","rewordable","reword","test","some","pattern","role","button","href","next","walk","nodes","whole","node","cell","cells","all","group","item","ctas","map","cta","named","how","figure","badge","period","list","link","image","row","rows","what","tab","tabs","panel","sections","forEach","index","entry","slice","trimEnd","limit","bound","entries","chars","tokens","cut","shortened","KEPT_RUN","out","at","first","end","run","aiSiteImportWordingText","page","aiSiteImportWordingPrompt","input","siteName","count","screen","slug","aiSiteImportWordingTokens","reduce","sum","aiReadWordingAnswer","answer","Array","isArray","flatMap","isInteger","SCRIPTS","aiSiteImportScriptOf","counts","Map","char","script","find","set","get","best","timesSaid","escaped","matchAll","RegExp","short","a","b","left","token","shownFact","pageText","alt","filter","Boolean","aiSiteImportWordingHolds","scope","rewrites","allowed","sources","facts","contacts","held","refused","answered","rewrite","refuse","code","message","detail","words","source","floor","before","after","nameBefore","nameAfter","dropped","added","names","startsWith","guarded","shown","framing","aiSiteImportWordingViolation","refusal","shape","rule","aiSiteImportRewordedDocument","aiSiteImportWordingCheck","attempts","answers","value","violations","checked","offending","reworded","built","build","values"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAkC2C,GAE3C,SAASA,kBAAkB,EAAEC,mBAAmB,QAAQ,0CAAyC;AACjG,SAASC,qBAAqB,QAAQ,uCAAmC;AAEzE,SACEC,yBAAyB,EACzBC,qBAAqB,EACrBC,mBAAmB,EACnBC,oBAAoB,QAEf,sCAAkC;AAGzC,SAASC,kBAAkB,QAAsD,uCAAmC;AACpH,SAASC,0BAA0B,QAAQ,qCAAiC;AAC5E,SAASC,mBAAmB,QAAQ,sCAAkC;AACtE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,SAASC,oBAAoB,QAAQ,8BAA0B;AAC/D,SACEC,iCAAiC,EACjCC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,mBAAmB,QAEd,+BAA2B;AAElC;;2CAE2C,GAE3C,+FAA+F,GAC/F,OAAO,MAAMC,8BAA8B,eAAc;AAEzD,oGAAoG,GACpG,OAAO,MAAMC,8BAAsC;IACjDC,MAAM;IACNC,aAAa;IACbC,QAAQ;IACRC,aAAa;QACXC,MAAM;QACNC,sBAAsB;QACtBC,UAAU;YAAC;SAAQ;QACnBC,YAAY;YACVC,OAAO;gBACLJ,MAAM;gBACNK,OAAO;oBACLL,MAAM;oBACNC,sBAAsB;oBACtBC,UAAU;wBAAC;wBAAQ;qBAAO;oBAC1BC,YAAY;wBAAEG,MAAM;4BAAEN,MAAM;wBAAU;wBAAGO,MAAM;4BAAEP,MAAM;wBAAS;oBAAE;gBACpE;YACF;QACF;IACF;AACF,EAAC;AAED,6DAA6D,GAC7D,OAAO,MAAMQ,gCAAgC;IAAEC,OAAO;IAAKC,MAAM;AAAI,EAAU;AAE/E;;;CAGC,GACD,OAAO,MAA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MAAM,CAAC,CAACY,UAAYF,QAAQpG,IAAI,CAAC,CAAC0H,UAAYA,QAAQlL,IAAI,KAAK8J,QAAQ9J,IAAI;gBAAG;YAC7G;QACF;QACA,MAAM6L,WAAWR,6BAA6BvE,MAAM5E,GAAG,EAAEyH;QACzD,MAAMmC,QAAQhF,MAAMiF,KAAK,CAACF,UAAU;eAAIlC,KAAKqC,MAAM;SAAG;QACtD,IAAI,CAACF,MAAML,KAAK,EAAE,OAAO;YAAEA,OAAO;YAAMC,YAAYI,MAAMJ,UAAU;QAAC;QACrE,OAAO;YAAED,OAAO;gBAAEK,OAAOA,MAAML,KAAK;gBAAEnC,UAAU,IAAIvB,IAAI4B;gBAAO/G,MAAMgH;YAAQ;YAAG8B,YAAY,EAAE;QAAC;IACjG;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-wording.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 * A PAGE BROUGHT IN, ITS WORDING IMPROVED (AGL-4152).\n *\n * Under Improve it with Also improve my wording on, a main page Aglyn AI\n * arranges is asked one more answer after its design: `submit_wording`, the\n * lines it rewords, each by its index in the page's blocks with its new\n * words. Nothing else rides the tool — no link, no picture, no structure —\n * so the page's sections, groups, buttons and destinations are the source's\n * whatever it says.\n *\n * - **What may be reworded** (`aiSiteImportWordingPage`): headings,\n * paragraphs, list items and a link the source draws as a button, the\n * words of FAQ, card, step and list items among them. Everything else is\n * kept as written: quotes and testimonials, pricing, stats and logos,\n * card titles, figures, badges, tables, tabs, eyebrows and fine print, a\n * paragraph with a link inside it, a postal address, an email or phone\n * link, and every line with no words.\n * - **What every rewrite holds** (`aiSiteImportWordingHolds`, pure): its\n * facts — prices, numbers, dates, times, percentages, emails, web\n * addresses, phones and names, the site's own name among them — exactly as\n * often as its line says them and none of its own; no contact the page\n * does not give; no gap; its line's script; 0.5 to 1.6 times its words,\n * within the characters its place holds; most of its meaning\n * (`SITE_IMPORT_MEANING_FLOOR`); and no filler, placeholder or judgment\n * word. A line refused is asked again once; refused again, it is kept as\n * written.\n * - **The page** (`aiSiteImportRewordedDocument`): the source's document\n * with the rewritten lines' words swapped in, every block at its index and\n * the source's own layout pinned, which the page step compiles and checks\n * whole as any page brought in, rule 14's copy checks on for the reworded\n * lines (`AiDoctrineTreeContext.rewritten`).\n *\n * Never asked of a page copied as it is, of a policy page, of the header and\n * footer, of the page's listing or of its title in the Pages list.\n *=========================================*/\n\nimport { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from '@aglyn/shared-util-tools/untrusted-text'\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport type { SiteImportLayoutNode, SiteImportLineRef } from '../model/ai-site-import'\nimport { SITE_IMPORT_POSTAL_PATTERNS } from '../model/ai-site-import-ledger'\nimport {\n SITE_IMPORT_MEANING_FLOOR,\n siteImportContentKept,\n siteImportFactScope,\n siteImportFactTokens,\n type SiteImportFactScope,\n} from '../model/ai-site-import-fidelity'\nimport type { AiSystemBlock, AiTool } from '../providers/contract'\nimport type { AiGenerationCheck } from '../runtime/ai-doctrine'\nimport { detectOffVoiceCopy, type AiCopyFraming, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { AI_GENERATION_MAX_ATTEMPTS } from '../runtime/ai-generation-bounds'\nimport { aiPlaceholderTokens } from '../runtime/ai-placeholder-tokens'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\nimport type { SiteImportBlock } from '../site-import/site-import-html'\nimport { aiSiteImportLayoutOf } from './ai-site-import-compile'\nimport {\n AI_SITE_IMPORT_HEADLINE_MAX_CHARS,\n AI_SITE_IMPORT_LABEL_CHARS,\n AI_SITE_IMPORT_TEXT_MAX_CHARS,\n aiSiteImportWordsIn,\n type AiSiteImportDocument,\n} from './ai-site-import-document'\n\n/*------------------------------------------\n * The tool and its cached instructions\n *-----------------------------------------*/\n\n/** The wording answer's kind of generation: the name its re-ask and its doctrine scope go by. */\nexport const AI_SITE_IMPORT_WORDING_KIND = 'page-wording'\n\n/** The wording tool: the lines reworded, each by its number, with its new words, and nothing else. */\nexport const AI_SITE_IMPORT_WORDING_TOOL: AiTool = {\n name: 'submit_wording',\n description: \"Submit the page's reworded lines: one entry for each line reworded, by its number, with its new words. A line left out keeps its words.\",\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['lines'],\n properties: {\n lines: {\n type: 'array',\n items: {\n type: 'object',\n additionalProperties: false,\n required: ['line', 'text'],\n properties: { line: { type: 'integer' }, text: { type: 'string' } },\n },\n },\n },\n },\n}\n\n/** The most a rewrite may run to, against its line's words. */\nexport const AI_SITE_IMPORT_WORDING_LENGTH = { least: 0.5, most: 1.6 } as const\n\n/**\n * What a wording answer is told, cached: one static block every page shares,\n * and the rule that fenced text is data. The page itself rides the user turn.\n */\nexport const AI_SITE_IMPORT_WORDING_TEXT = [\n \"You rewrite the wording of a page brought in from its owner's own website so it reads as a strong professional copywriter would write it, in the owner's voice: each heading a clear, specific promise of what the visitor gets, each paragraph leading with the benefit, in active words, with nothing that does not earn its place. Rebuild a sentence freely where that makes it clearer or stronger. The page's design, its sections and what each section shows are fixed, and so is every fact on it.\",\n '',\n 'Answer with submit_wording: one entry in lines for each line you reword, by its number, with its new words. A line you leave out is kept exactly as written. Rewrite every heading, lede, paragraph and button that could be clearer or stronger, and leave out only a line that is already as strong as it can be. Reword only a line shown as a heading, a paragraph, a list item or a button; a line shown \"as written\" is the owner\\'s exactly and is never answered.',\n '',\n 'Each rewrite:',\n \"- says what its line means, in the line's own language and script, and makes no claim, promise, offer or detail the page does not make;\",\n '- keeps every name, price, number, date, time, percentage, address, phone number, email and web address exactly as the line writes it, as often as the line has it, and adds none;',\n `- runs between ${AI_SITE_IMPORT_WORDING_LENGTH.least} and ${AI_SITE_IMPORT_WORDING_LENGTH.most} times its line's words, and never past the characters shown;`,\n '- stays what its line is: a heading for a heading, a sentence or more for a paragraph, a short label for a button;',\n '- writes no placeholder, no gap in brackets, no filler and no word that calls the work simple or cheap.',\n].join('\\n')\n\n/** The wording answer's cached instructions, and the rule that fenced text is data. */\nexport const AI_SITE_IMPORT_WORDING_INSTRUCTIONS: readonly AiSystemBlock[] = [\n { text: AI_SITE_IMPORT_WORDING_TEXT, cacheBreakpoint: true },\n { text: UNTRUSTED_TEXT_RULE },\n]\n\n/*------------------------------------------\n * The page's lines: those it may reword, and those kept as written\n *-----------------------------------------*/\n\n/** What a line is, as the prompt names it and its place holds it. */\nexport type AiSiteImportWordingKind = 'heading' | 'paragraph' | 'list item' | 'button'\n\n/** A line a rewrite may reword. */\nexport interface AiSiteImportWordingLine {\n /** Its index in the page's blocks: the number the tool answers by. */\n line: SiteImportLineRef\n kind: AiSiteImportWordingKind\n /** Its words as written. */\n text: string\n /** The most characters a rewrite of it holds. */\n limit: number\n /** Its section, by index. */\n section: number\n}\n\n/** One entry of the page as the prompt shows it: a line to reword, one kept as written, or a part with no lines of the tool. */\nexport interface AiSiteImportWordingEntry {\n section: number\n /** The line's number, absent for a part shown whole (a table). */\n line?: SiteImportLineRef\n /** What it is: \"heading\", \"quote\", \"a table of 4 rows\". */\n what: string\n text: string\n /** Set where a rewrite may reword it. */\n reword?: AiSiteImportWordingLine\n}\n\n/** A page as the wording answer is shown it. */\nexport interface AiSiteImportWordingPage {\n /** The page's sections' names, in order. */\n sections: string[]\n /** Every entry, in order, as far as the prompt's room goes. */\n entries: AiSiteImportWordingEntry[]\n /** The lines a rewrite may reword: those shown. */\n lines: AiSiteImportWordingLine[]\n /** Whether the page runs past what the prompt shows: the rest keeps its words. */\n cut: boolean\n}\n\n/** The most characters of a page the wording prompt shows, inside the fence's cap with room for its section heads. */\nexport const AI_SITE_IMPORT_WORDING_MAX_CHARS = 12_000\nconst SHOWN_MAX_CHARS = AI_SITE_IMPORT_WORDING_MAX_CHARS - 1_000\n\n/** The most characters of a line kept as written the prompt shows: it is there to be read around, never answered. */\nconst KEPT_SHOWN_CHARS = 160\n\n/** Groups whose every line is the owner's exactly: quotes, prices, figures, names. */\nconst FIXED_GROUPS = new Set(['quotes', 'pricing', 'stats', 'logos'])\n\n/** Groups whose items' titles are names: a card's title is a product's or a service's. */\nconst NAMED_GROUPS = new Set(['cards', 'pricing'])\n\nconst POSTAL = SITE_IMPORT_POSTAL_PATTERNS\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** Whether a block is a line of the page: a link inside a sentence is in its sentence. */\nfunction isLine(block: SiteImportBlock | undefined): boolean {\n if (!block) return false\n if (block.kind === 'image') return !!block.url\n if (block.kind === 'link') return !block.inline && !!clean(block.text)\n return !!clean(block.text)\n}\n\n/** The most characters a rewrite of a line holds: its place's, or the line's own where it already runs past it. */\nfunction limitOf(kind: AiSiteImportWordingKind, text: string, title: boolean): number {\n const place =\n kind === 'heading'\n ? AI_SITE_IMPORT_HEADLINE_MAX_CHARS\n : kind === 'button'\n ? AI_SITE_IMPORT_LABEL_CHARS\n : title\n ? AI_TEXT_LIMITS.label\n : AI_SITE_IMPORT_TEXT_MAX_CHARS\n return text.length > place ? text.length : place\n}\n\n/** Tokens a line's words come to, as the ceiling plans them: four characters a token, and the entry around it. */\nconst tokensOf = (line: AiSiteImportWordingLine) => Math.ceil(line.text.length / 4) + 12\n\n/** Room for the thinking a wording answer does before it writes, inside its ceiling. */\nexport const AI_SITE_IMPORT_WORDING_THINKING_TOKENS = 1_000\n\n/** How much of a page the wording answer is shown. */\nexport interface AiSiteImportWordingRoom {\n /** The most characters of the page the prompt shows. */\n maxChars?: number\n /** The ceiling the answer is asked at: the lines offered are those a rewrite of every one fits in (`aiSiteImportWordingTokens`). */\n maxTokens?: number\n}\n\n/**\n * The page as the wording answer is shown it (G1, G2): its sections and,\n * in each, its lines in order, each marked as a line a rewrite may reword\n * or one kept as written. A line is reworded only where every place the\n * layout puts it allows it. The lines shown stop where the prompt's room,\n * or the answer's ceiling, does; those past it keep their words.\n */\nexport function aiSiteImportWordingPage(doc: Pick<AiSiteImportDocument, 'blocks' | 'title' | 'layout'>, room: AiSiteImportWordingRoom = {}): AiSiteImportWordingPage {\n const maxChars = room.maxChars ?? SHOWN_MAX_CHARS\n const maxTokens = room.maxTokens ?? Number.POSITIVE_INFINITY\n const layout = aiSiteImportLayoutOf(doc)\n const fixed = new Set<SiteImportLineRef>()\n const order: Array<{ section: number; ref?: SiteImportLineRef; what?: string; reword?: { kind: AiSiteImportWordingKind; title: boolean } }> = []\n const seen = new Set<SiteImportLineRef>()\n\n const kept = (section: number, ref: SiteImportLineRef | undefined) => {\n if (ref === undefined || !isLine(doc.blocks[ref]) || doc.blocks[ref]?.kind === 'image') return\n fixed.add(ref)\n if (!seen.has(ref)) {\n seen.add(ref)\n order.push({ section, ref })\n }\n }\n // A line placed where a rewrite may reach it, unless what it says keeps it as written.\n const offer = (section: number, ref: SiteImportLineRef | undefined, place: { button?: boolean; role?: string; title?: boolean } = {}) => {\n if (ref === undefined) return\n const block = doc.blocks[ref]\n if (!block || !isLine(block) || block.kind === 'image') return\n const kind = rewordable(ref, block, place)\n if (!kind) return kept(section, ref)\n if (!seen.has(ref)) {\n seen.add(ref)\n order.push({ section, ref, reword: { kind, title: !!place.title } })\n }\n }\n const rewordable = (ref: SiteImportLineRef, block: SiteImportBlock, place: { button?: boolean; role?: string }): AiSiteImportWordingKind | null => {\n if (block.kind === 'image' || block.kind === 'quote') return null\n const text = clean(block.text)\n if (!aiSiteImportWordsIn(text) || !/\\p{L}/u.test(text)) return null\n if (POSTAL.some((pattern) => pattern.test(text))) return null\n // A label the source sets apart, or its fine print, is the owner's as written.\n if (place.role === 'eyebrow' || place.role === 'note') return null\n if (block.kind === 'link') {\n if (!place.button || /^(?:mailto|tel|sms):/i.test(block.href)) return null\n return 'button'\n }\n // A sentence with a link inside it keeps its words, so the link's words are still in it.\n const next = doc.blocks[ref + 1]\n if (next?.kind === 'link' && next.inline) return null\n if (block.kind === 'heading') return 'heading'\n if (block.kind === 'list-item') return 'list item'\n return 'paragraph'\n }\n\n const walk = (nodes: readonly SiteImportLayoutNode[], section: number, whole: boolean): void => {\n for (const node of nodes) {\n switch (node.kind) {\n case 'line':\n if (whole) kept(section, node.line)\n else offer(section, node.line, { button: !!node.button, ...(node.role ? { role: node.role } : {}) })\n break\n case 'row':\n for (const cell of node.cells) walk(cell.nodes, section, whole)\n break\n case 'group': {\n const all = whole || FIXED_GROUPS.has(node.group)\n for (const item of node.items) {\n const ctas = new Set((item.ctas ?? []).map((cta) => cta.line))\n const named = new Set<SiteImportLineRef>()\n const place = (ref: SiteImportLineRef | undefined, how: { button?: boolean; title?: boolean } = {}) => {\n if (ref === undefined) return\n named.add(ref)\n if (all) kept(section, ref)\n else offer(section, ref, how)\n }\n // A card's title names its product or service; a figure, a badge and a period are facts.\n if (NAMED_GROUPS.has(node.group)) {\n if (item.title !== undefined) named.add(item.title)\n kept(section, item.title)\n } else place(item.title, { title: true })\n for (const ref of [item.figure, item.badge, item.period]) {\n if (ref === undefined) continue\n named.add(ref)\n kept(section, ref)\n }\n for (const ref of item.text ?? []) place(ref)\n for (const ref of item.list ?? []) place(ref)\n for (const ref of item.link ?? []) {\n if (ctas.has(ref)) place(ref, { button: true })\n else {\n named.add(ref)\n kept(section, ref)\n }\n }\n for (const ref of item.lines) if (!named.has(ref) && ref !== item.image) kept(section, ref)\n }\n break\n }\n case 'table': {\n for (const row of node.rows) {\n for (const cell of row.cells) {\n for (const ref of cell.lines) {\n fixed.add(ref)\n seen.add(ref)\n }\n }\n }\n order.push({ section, what: `a table of ${node.rows.length} ${node.rows.length === 1 ? 'row' : 'rows'}` })\n break\n }\n case 'tabs':\n for (const tab of node.tabs) {\n kept(section, tab.label ?? undefined)\n walk(tab.panel, section, true)\n }\n break\n default:\n break\n }\n }\n }\n layout.sections.forEach((section, index) => {\n walk(section.nodes, index, false)\n // A line of the section no part of its layout places keeps its words.\n for (const ref of section.lines) if (!seen.has(ref)) kept(index, ref)\n })\n\n const all: AiSiteImportWordingEntry[] = order.map((entry) => {\n if (entry.ref === undefined) return { section: entry.section, what: `${entry.what ?? 'a part'}, as written`, text: '' }\n const block = doc.blocks[entry.ref] as SiteImportBlock\n const text = block.kind === 'image' ? '' : clean(block.text)\n const reword = entry.reword && !fixed.has(entry.ref) ? entry.reword : null\n if (!reword) {\n return { section: entry.section, line: entry.ref, what: block.kind === 'quote' ? 'quote, as written' : 'as written', text: text.length > KEPT_SHOWN_CHARS ? `${text.slice(0, KEPT_SHOWN_CHARS).trimEnd()} …` : text }\n }\n const line: AiSiteImportWordingLine = { line: entry.ref, kind: reword.kind, text, limit: limitOf(reword.kind, text, reword.title), section: entry.section }\n // A paragraph's own ceiling is far past what 1.6 times its words reach: only a tighter place's is shown.\n const bound = line.limit < AI_SITE_IMPORT_TEXT_MAX_CHARS\n return { section: entry.section, line: entry.ref, what: bound ? `${line.kind}, up to ${line.limit} characters` : line.kind, text, reword: line }\n })\n const entries: AiSiteImportWordingEntry[] = []\n const lines: AiSiteImportWordingLine[] = []\n let chars = 0\n let tokens = 0\n let cut = false\n for (const entry of shortened(all)) {\n chars += entry.what.length + entry.text.length + 12\n if (entry.reword) tokens += tokensOf(entry.reword)\n if (chars > maxChars || 2 * tokens + AI_SITE_IMPORT_WORDING_THINKING_TOKENS > maxTokens) {\n cut = true\n break\n }\n entries.push(entry)\n if (entry.reword) lines.push(entry.reword)\n }\n return { sections: layout.sections.map((section) => section.name), entries, lines, cut }\n}\n\n/** The most lines kept as written the prompt shows in a row: a run longer than this shows its first two, and how many follow. */\nconst KEPT_RUN = 3\n\n/**\n * The page's entries with each long run of lines kept as written told in a\n * few: a plan's prices or a table's cells are there to be read around, and\n * a run of them would crowd out the lines that are the answer's to reword.\n */\nfunction shortened(entries: readonly AiSiteImportWordingEntry[]): AiSiteImportWordingEntry[] {\n const out: AiSiteImportWordingEntry[] = []\n for (let at = 0; at < entries.length; ) {\n const first = entries[at] as AiSiteImportWordingEntry\n if (first.reword) {\n out.push(first)\n at += 1\n continue\n }\n let end = at\n while (end < entries.length && !entries[end]?.reword && entries[end]?.section === first.section) end += 1\n const run = entries.slice(at, end)\n if (run.length > KEPT_RUN) {\n out.push(...run.slice(0, 2), { section: first.section, what: `${run.length - 2} more lines, as written`, text: '' })\n } else out.push(...run)\n at = end\n }\n return out\n}\n\n/*------------------------------------------\n * The prompt\n *-----------------------------------------*/\n\n/** The page's lines as the fence holds them: each section's name, then its lines, numbered. */\nexport function aiSiteImportWordingText(page: AiSiteImportWordingPage): string {\n const out: string[] = []\n let section = -1\n for (const entry of page.entries) {\n if (entry.section !== section) {\n section = entry.section\n out.push(`Section ${section + 1} \"${page.sections[section] ?? ''}\":`)\n }\n out.push(entry.line === undefined ? `- ${entry.what}` : `[${entry.line}] ${entry.what}: ${entry.text}`)\n }\n if (page.cut) out.push('(The page goes on past here; the rest keeps its words.)')\n return out.join('\\n')\n}\n\n/** A wording answer's user turn: the page, the site's own name, and its lines, fenced as the owner's data. */\nexport function aiSiteImportWordingPrompt(input: {\n screen: { title: string; slug: string }\n doc: Pick<AiSiteImportDocument, 'url'>\n page: AiSiteImportWordingPage\n siteName?: string | null\n}): string {\n const name = clean(input.siteName)\n const count = input.page.lines.length\n return [\n `Page: \"${input.screen.title}\" at ${input.screen.slug}`,\n ...(name ? [\"The site's own name, which every rewrite writes exactly as it is wherever its line says it:\", fenceUntrustedText(\"The site's name\", name, { maxChars: 200 })] : []),\n `Its lines, in order, ${count === 1 ? 'one of them' : `${count} of them`} yours to reword, each with its number and what it is, and the most characters a rewrite may hold where its place holds fewer than a paragraph:`,\n fenceUntrustedText(`The words of the owner's page ${input.doc.url}`, aiSiteImportWordingText(input.page), { maxChars: AI_SITE_IMPORT_WORDING_MAX_CHARS }),\n ].join('\\n')\n}\n\n/**\n * The ceiling a page's wording answer wants (G1): twice its lines' own\n * tokens, so a rewrite of every line fits with room, and its thinking.\n * The page step holds it to the time the design answer leaves.\n */\nexport function aiSiteImportWordingTokens(page: AiSiteImportWordingPage): number {\n return 2 * page.lines.reduce((sum, line) => sum + tokensOf(line), 0) + AI_SITE_IMPORT_WORDING_THINKING_TOKENS\n}\n\n/*------------------------------------------\n * The answer, and what every rewrite holds\n *-----------------------------------------*/\n\n/** One line as an answer rewords it. */\nexport interface AiSiteImportRewrite {\n line: number\n text: string\n}\n\n/** An answer's lines, read defensively: each with a whole number and words; `null` where it has no list of lines. */\nexport function aiReadWordingAnswer(answer: Record<string, unknown> | null | undefined): AiSiteImportRewrite[] | null {\n const lines = answer?.['lines']\n if (!Array.isArray(lines)) return null\n return lines.flatMap((entry): AiSiteImportRewrite[] => {\n if (!entry || typeof entry !== 'object') return []\n const { line, text } = entry as Record<string, unknown>\n return typeof line === 'number' && Number.isInteger(line) && typeof text === 'string' ? [{ line, text }] : []\n })\n}\n\n/** Why a rewrite was refused (G3). */\nexport type AiSiteImportWordingCode =\n | 'wording-no-line'\n | 'wording-fixed-line'\n | 'wording-repeated-line'\n | 'wording-empty'\n | 'wording-script'\n | 'wording-length'\n | 'wording-dropped-fact'\n | 'wording-dropped-name'\n | 'wording-invented-fact'\n | 'wording-gap'\n | 'wording-meaning'\n | 'wording-copy'\n\n/** A rewrite refused, and why. */\nexport interface AiSiteImportWordingRefusal {\n line: number\n code: AiSiteImportWordingCode\n /** What the model is told: what the line broke and what to do. */\n message: string\n /** What it broke, beyond the message: the facts it dropped or added. */\n detail?: string\n}\n\n/** What a page's rewrites are held to beyond their own lines. */\nexport interface AiSiteImportWordingScope {\n doc: Pick<AiSiteImportDocument, 'blocks'>\n page: Pick<AiSiteImportWordingPage, 'lines'>\n /** The site's own name, which every rewrite says as often as its line does. */\n siteName?: string | null\n /** Who the copy is framed for: agency and enterprise copy holds to the judgment-word rule. */\n framing?: AiCopyFraming\n}\n\n/** The rewrites that hold, by line, and those refused. */\nexport interface AiSiteImportWordingHeld {\n held: Map<number, string>\n refused: AiSiteImportWordingRefusal[]\n}\n\n/** The scripts a line is told apart by; Chinese and Japanese writing count as one. */\nconst SCRIPTS: ReadonlyArray<readonly [string, RegExp]> = [\n ['latin', /\\p{Script=Latin}/u],\n ['cyrillic', /\\p{Script=Cyrillic}/u],\n ['greek', /\\p{Script=Greek}/u],\n ['arabic', /\\p{Script=Arabic}/u],\n ['hebrew', /\\p{Script=Hebrew}/u],\n ['cjk', /[\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}]/u],\n ['hangul', /\\p{Script=Hangul}/u],\n ['thai', /\\p{Script=Thai}/u],\n ['devanagari', /\\p{Script=Devanagari}/u],\n]\n\n/** The script most of a line's letters are written in; `null` for a line with none. */\nexport function aiSiteImportScriptOf(text: string): string | null {\n const counts = new Map<string, number>()\n for (const char of text) {\n if (!/\\p{L}/u.test(char)) continue\n const script = SCRIPTS.find(([, pattern]) => pattern.test(char))?.[0] ?? 'other'\n counts.set(script, (counts.get(script) ?? 0) + 1)\n }\n let best: string | null = null\n let most = 0\n for (const [script, count] of counts) {\n if (count > most) {\n best = script\n most = count\n }\n }\n return best\n}\n\n/** How often a run of words says a name, whole, in any case. */\nfunction timesSaid(text: string, name: string): number {\n if (!name) return 0\n const escaped = name.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&').replace(/\\s+/g, '\\\\s+')\n return [...text.matchAll(new RegExp(`(?<![\\\\p{L}\\\\p{N}])${escaped}(?![\\\\p{L}\\\\p{N}])`, 'giu'))].length\n}\n\n/** Each token of `a` not matched by one of `b`, as often as it is short. */\nfunction short(a: readonly string[], b: readonly string[]): string[] {\n const left = new Map<string, number>()\n for (const token of b) left.set(token, (left.get(token) ?? 0) + 1)\n const out: string[] = []\n for (const token of a) {\n const count = left.get(token) ?? 0\n if (count > 0) left.set(token, count - 1)\n else out.push(token)\n }\n return out\n}\n\n/** A fact token as the model reads it: its words, not its kind. */\nconst shownFact = (token: string) => `\"${token.replace(/^[a-z]+:/, '')}\"`\n\n/** The words of every line of the page as written: the facts a rewrite's contact details are held to. */\nfunction pageText(doc: Pick<AiSiteImportDocument, 'blocks'>): string {\n return doc.blocks.map((block) => (block.kind === 'image' ? clean(block.alt) : clean(block.text))).filter(Boolean).join('\\n')\n}\n\n/**\n * Every rule a rewrite is held to (G2, G3), pure, one line at a time: a\n * rewrite that breaks one is refused, and its line keeps its words. A\n * rewrite the same as its line is no rewrite, and is neither.\n */\nexport function aiSiteImportWordingHolds(scope: AiSiteImportWordingScope, rewrites: readonly AiSiteImportRewrite[]): AiSiteImportWordingHeld {\n const allowed = new Map(scope.page.lines.map((line) => [line.line, line]))\n const sources = scope.doc.blocks.flatMap((block) => (isLine(block) && block.kind !== 'image' ? [clean(block.text)] : []))\n const facts: SiteImportFactScope = siteImportFactScope(sources)\n const contacts = pageText(scope.doc)\n const name = clean(scope.siteName)\n const held = new Map<number, string>()\n const refused: AiSiteImportWordingRefusal[] = []\n const answered = new Set<number>()\n for (const rewrite of rewrites) {\n const at = rewrite.line\n const refuse = (code: AiSiteImportWordingCode, message: string, detail?: string) => refused.push({ line: at, code, message: `Line ${at}: ${message}`, ...(detail ? { detail } : {}) })\n if (answered.has(at)) {\n refuse('wording-repeated-line', 'it was answered more than once. Give each line once.')\n continue\n }\n answered.add(at)\n const block = scope.doc.blocks[at]\n if (!block || !isLine(block)) {\n refuse('wording-no-line', 'there is no such line on this page. Answer only the lines shown, by their numbers.')\n continue\n }\n const line = allowed.get(at)\n if (!line) {\n refuse('wording-fixed-line', 'it is kept exactly as the owner wrote it. Leave it out.')\n continue\n }\n const text = clean(rewrite.text)\n if (!text) {\n refuse('wording-empty', 'it was given no words. Leave a line out to keep it as written; never empty it.')\n continue\n }\n if (text === line.text) continue\n if (aiSiteImportScriptOf(text) !== aiSiteImportScriptOf(line.text)) {\n refuse('wording-script', \"it is not written in the line's own language. Write it in the language and script the line is in.\")\n continue\n }\n const words = aiSiteImportWordsIn(text)\n const source = aiSiteImportWordsIn(line.text)\n if (words < AI_SITE_IMPORT_WORDING_LENGTH.least * source || words > AI_SITE_IMPORT_WORDING_LENGTH.most * source || text.length > line.limit) {\n const least = Math.ceil(AI_SITE_IMPORT_WORDING_LENGTH.least * source)\n const most = Math.floor(AI_SITE_IMPORT_WORDING_LENGTH.most * source)\n refuse(\n 'wording-length',\n `it runs to ${words} ${words === 1 ? 'word' : 'words'} and ${text.length} characters. Keep it between ${least} and ${most} words, and within ${line.limit} characters.`,\n `The line has ${source} ${source === 1 ? 'word' : 'words'}.`,\n )\n continue\n }\n const before = siteImportFactTokens(line.text, facts, false)\n const after = siteImportFactTokens(text, facts, true)\n const nameBefore = timesSaid(line.text, name)\n const nameAfter = timesSaid(text, name)\n const dropped = short(before, after)\n const added = short(after, before)\n const names = [...dropped.filter((token) => token.startsWith('name:')), ...(nameAfter < nameBefore ? [`name:${name}`] : [])]\n if (names.length) {\n refuse('wording-dropped-name', 'it leaves out a name the line says. Keep every name exactly as the line writes it, as often.', `Left out: ${[...new Set(names)].map(shownFact).join(', ')}.`)\n continue\n }\n if (dropped.length) {\n refuse(\n 'wording-dropped-fact',\n 'it leaves out a fact the line says. Keep every price, number, date, time, percentage, address, phone number, email and web address exactly as the line writes it, as often.',\n `Left out: ${[...new Set(dropped)].map(shownFact).join(', ')}.`,\n )\n continue\n }\n const guarded = aiLayoutGuardContacts(text, contacts)\n if (added.length || nameAfter > nameBefore || guarded !== text) {\n const shown = [...new Set([...added, ...(nameAfter > nameBefore ? [`name:${name}`] : [])])]\n refuse('wording-invented-fact', 'it adds a fact or a name the line does not say. Add none of your own.', shown.length ? `Added: ${shown.map(shownFact).join(', ')}.` : undefined)\n continue\n }\n if (/\\[[^\\]]*\\]/.test(text) && !/\\[[^\\]]*\\]/.test(line.text)) {\n refuse('wording-gap', 'it leaves a gap in square brackets. Write the line whole, from its own words.')\n continue\n }\n if (siteImportContentKept(line.text, text) < SITE_IMPORT_MEANING_FLOOR) {\n refuse('wording-meaning', \"it no longer says what the line says. Keep its meaning and most of its words' substance.\")\n continue\n }\n if (detectOffVoiceCopy([{ at: 'line', text }], scope.framing ?? null).length || aiPlaceholderTokens(text).length) {\n refuse('wording-copy', \"it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words from the line's own.\")\n continue\n }\n held.set(at, text)\n }\n return { held, refused }\n}\n\n/** A refusal as the re-ask names it. */\nexport function aiSiteImportWordingViolation(refusal: AiSiteImportWordingRefusal): AiDoctrineViolation {\n const shape = refusal.code === 'wording-no-line' || refusal.code === 'wording-fixed-line' || refusal.code === 'wording-repeated-line'\n return { rule: shape ? null : 14, code: refusal.code, message: refusal.message, ...(refusal.detail ? { detail: refusal.detail } : {}) }\n}\n\n/*------------------------------------------\n * The page reworded\n *-----------------------------------------*/\n\n/**\n * The page with its rewrites (G3): the source's document, each rewritten\n * line's words in place of its own and every block at its index, its layout\n * pinned to the source's so no section moves or is renamed. An image, or a\n * line no rewrite names, is the source's.\n */\nexport function aiSiteImportRewordedDocument(doc: AiSiteImportDocument, rewrites: ReadonlyMap<number, string>): AiSiteImportDocument {\n return {\n ...doc,\n layout: aiSiteImportLayoutOf(doc),\n blocks: doc.blocks.map((block, index) => {\n const text = rewrites.get(index)\n return text === undefined || block.kind === 'image' ? block : { ...block, text }\n }),\n }\n}\n\n/** A page's wording, settled: the page built in its rewrites, and the lines kept as written after their re-ask. */\nexport interface AiSiteImportWorded<T> {\n built: T\n /** The lines reworded, by number. */\n rewrites: Map<number, string>\n /** The lines refused twice, which keep their words. */\n kept: AiSiteImportWordingRefusal[]\n}\n\n/**\n * The wording answer's check (G3): every rewrite held line by line, a\n * refused one asked again once — the lines that held are kept between the\n * answers — and the page built whole in what held (`build`, the page step's\n * check of a page brought in, with rule 14 on for the rewritten lines). On\n * the last answer a line refused again keeps its words; a page that cannot\n * be built in its rewrites is refused whole, and the page step keeps the\n * page's words.\n *\n * Stateful across one generation's answers: make one for each.\n */\nexport function aiSiteImportWordingCheck<T>(input: AiSiteImportWordingScope & {\n doc: AiSiteImportDocument\n build: (reworded: AiSiteImportDocument, rewritten: readonly string[]) => { value: T | null; violations: AiDoctrineViolation[] }\n /** The answers one generation makes; the last keeps a line refused again as written. */\n attempts?: number\n}): AiGenerationCheck<AiSiteImportWorded<T>> {\n const attempts = input.attempts ?? AI_GENERATION_MAX_ATTEMPTS\n const held = new Map<number, string>()\n let answers = 0\n return (answer) => {\n answers += 1\n const rewrites = aiReadWordingAnswer(answer)\n if (!rewrites) return { value: null, violations: [{ rule: null, code: 'wording-unreadable', message: 'The answer gave no list of lines. Answer with submit_wording.' }] }\n const checked = aiSiteImportWordingHolds(input, rewrites)\n for (const [line, text] of checked.held) held.set(line, text)\n // A line refused now that held in an earlier answer keeps that rewrite.\n const refused = checked.refused.filter((refusal) => !held.has(refusal.line))\n if (refused.length && answers < attempts) {\n return {\n value: null,\n violations: [\n ...refused.map(aiSiteImportWordingViolation),\n {\n rule: null,\n code: 'wording-kept-lines',\n message: `Every other line you reworded holds and is kept. Answer again with ${refused.length === 1 ? 'that line' : 'those lines'} alone, or leave ${refused.length === 1 ? 'it' : 'them'} out to keep the owner's words.`,\n },\n ],\n offending: { lines: rewrites.filter((rewrite) => refused.some((refusal) => refusal.line === rewrite.line)) },\n }\n }\n const reworded = aiSiteImportRewordedDocument(input.doc, held)\n const built = input.build(reworded, [...held.values()])\n if (!built.value) return { value: null, violations: built.violations }\n return { value: { built: built.value, rewrites: new Map(held), kept: refused }, violations: [] }\n }\n}\n"],"names":["fenceUntrustedText","UNTRUSTED_TEXT_RULE","aiLayoutGuardContacts","SITE_IMPORT_POSTAL_PATTERNS","SITE_IMPORT_MEANING_FLOOR","siteImportContentKept","siteImportFactScope","siteImportFactTokens","detectOffVoiceCopy","AI_GENERATION_MAX_ATTEMPTS","aiPlaceholderTokens","AI_TEXT_LIMITS","aiSiteImportLayoutOf","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_TEXT_MAX_CHARS","aiSiteImportWordsIn","AI_SITE_IMPORT_WORDING_KIND","AI_SITE_IMPORT_WORDING_TOOL","name","description","strict","inputSchema","type","additionalProperties","required","properties","lines","items","line","text","AI_SITE_IMPORT_WORDING_LENGTH","least","most","AI_SITE_IMPORT_WORDING_TEXT","join","AI_SITE_IMPORT_WORDING_INSTRUCTIONS","cacheBreakpoint","AI_SITE_IMPORT_WORDING_MAX_CHARS","SHOWN_MAX_CHARS","KEPT_SHOWN_CHARS","FIXED_GROUPS","Set","NAMED_GROUPS","POSTAL","clean","replace","trim","isLine","block","kind","url","inline","limitOf","title","place","label","length","tokensOf","Math","ceil","AI_SITE_IMPORT_WORDING_THINKING_TOKENS","aiSiteImportWordingPage","doc","room","maxChars","maxTokens","Number","POSITIVE_INFINITY","layout","fixed","order","seen","kept","section","ref","undefined","blocks","add","has","push","offer","rewordable","reword","test","some","pattern","role","button","href","next","walk","nodes","whole","node","cell","cells","all","group","item","ctas","map","cta","named","how","figure","badge","period","list","link","image","row","rows","what","tab","tabs","panel","sections","forEach","index","entry","slice","trimEnd","limit","bound","entries","chars","tokens","cut","shortened","KEPT_RUN","out","at","first","end","run","aiSiteImportWordingText","page","aiSiteImportWordingPrompt","input","siteName","count","screen","slug","aiSiteImportWordingTokens","reduce","sum","aiReadWordingAnswer","answer","Array","isArray","flatMap","isInteger","SCRIPTS","aiSiteImportScriptOf","counts","Map","char","script","find","set","get","best","timesSaid","escaped","matchAll","RegExp","short","a","b","left","token","shownFact","pageText","alt","filter","Boolean","aiSiteImportWordingHolds","scope","rewrites","allowed","sources","facts","contacts","held","refused","answered","rewrite","refuse","code","message","detail","words","source","floor","before","after","nameBefore","nameAfter","dropped","added","names","startsWith","guarded","shown","framing","aiSiteImportWordingViolation","refusal","shape","rule","aiSiteImportRewordedDocument","aiSiteImportWordingCheck","attempts","answers","value","violations","checked","offending","reworded","built","build","values"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAkC2C,GAE3C,SAASA,kBAAkB,EAAEC,mBAAmB,QAAQ,0CAAyC;AACjG,SAASC,qBAAqB,QAAQ,uCAAmC;AAEzE,SAASC,2BAA2B,QAAQ,oCAAgC;AAC5E,SACEC,yBAAyB,EACzBC,qBAAqB,EACrBC,mBAAmB,EACnBC,oBAAoB,QAEf,sCAAkC;AAGzC,SAASC,kBAAkB,QAAsD,uCAAmC;AACpH,SAASC,0BAA0B,QAAQ,qCAAiC;AAC5E,SAASC,mBAAmB,QAAQ,sCAAkC;AACtE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,SAASC,oBAAoB,QAAQ,8BAA0B;AAC/D,SACEC,iCAAiC,EACjCC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,mBAAmB,QAEd,+BAA2B;AAElC;;2CAE2C,GAE3C,+FAA+F,GAC/F,OAAO,MAAMC,8BAA8B,eAAc;AAEzD,oGAAoG,GACpG,OAAO,MAAMC,8BAAsC;IACjDC,MAAM;IACNC,aAAa;IACbC,QAAQ;IACRC,aAAa;QACXC,MAAM;QACNC,sBAAsB;QACtBC,UAAU;YAAC;SAAQ;QACnBC,YAAY;YACVC,OAAO;gBACLJ,MAAM;gBACNK,OAAO;oBACLL,MAAM;oBACNC,sBAAsB;oBACtBC,UAAU;wBAAC;wBAAQ;qBAAO;oBAC1BC,YAAY;wBAAEG,MAAM;4BAAEN,MAAM;wBAAU;wBAAGO,MAAM;4BAAEP,MAAM;wBAAS;oBAAE;gBACpE;YACF;QACF;IACF;AACF,EAAC;AAED,6DAA6D,GAC7D,OAAO,MAAMQ,gCAAgC;IAAEC,OAAO;IAAKC,MAAM;AAAI,EAAU;AAE/E;;;CAGC,GACD,OAAO,MAAMC,8BAA8B;IACzC;IAC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H,UAAYA,QAAQlL,IAAI,KAAK8J,QAAQ9J,IAAI;gBAAG;YAC7G;QACF;QACA,MAAM6L,WAAWR,6BAA6BvE,MAAM5E,GAAG,EAAEyH;QACzD,MAAMmC,QAAQhF,MAAMiF,KAAK,CAACF,UAAU;eAAIlC,KAAKqC,MAAM;SAAG;QACtD,IAAI,CAACF,MAAML,KAAK,EAAE,OAAO;YAAEA,OAAO;YAAMC,YAAYI,MAAMJ,UAAU;QAAC;QACrE,OAAO;YAAED,OAAO;gBAAEK,OAAOA,MAAML,KAAK;gBAAEnC,UAAU,IAAIvB,IAAI4B;gBAAO/G,MAAMgH;YAAQ;YAAG8B,YAAY,EAAE;QAAC;IACjG;AACF"}
|
|
@@ -111,6 +111,12 @@ export interface AiLayoutCompileOptions {
|
|
|
111
111
|
* link is still the source's.
|
|
112
112
|
*/
|
|
113
113
|
finish?: AiLayoutImportFinish;
|
|
114
|
+
/**
|
|
115
|
+
* How a page's plain and soft bands run, over the site's design choice
|
|
116
|
+
* (AGL-4152): a generative Improve it plans its own grounds, and neighbors of
|
|
117
|
+
* one ground never meet. Absent, the design's own.
|
|
118
|
+
*/
|
|
119
|
+
bandRhythm?: AiLayoutDesignChoices['bandRhythm'];
|
|
114
120
|
}
|
|
115
121
|
/** Words exactly as given, one space between them: how a page brought in shows them (AGL-4107). */
|
|
116
122
|
export declare function aiLayoutAsWritten(value: unknown): string;
|
|
@@ -101,7 +101,9 @@ function formSectionOf(sections, plan, targets) {
|
|
|
101
101
|
itemIds: plan.sections.map(()=>[]),
|
|
102
102
|
design: options.design ? {
|
|
103
103
|
input: options.design,
|
|
104
|
-
choices: aiLayoutDesignChoices(options.design)
|
|
104
|
+
choices: _extends({}, aiLayoutDesignChoices(options.design), options.bandRhythm ? {
|
|
105
|
+
bandRhythm: options.bandRhythm
|
|
106
|
+
} : {})
|
|
105
107
|
} : null,
|
|
106
108
|
pictures: 0,
|
|
107
109
|
features: 0,
|
|
@@ -1159,7 +1161,9 @@ function image(scope, block, room) {
|
|
|
1159
1161
|
var _block_to;
|
|
1160
1162
|
const { page } = scope;
|
|
1161
1163
|
// A page brought in places the source's own picture, as the library holds it (AGL-4107).
|
|
1162
|
-
|
|
1164
|
+
// An image a redesign asks for in words (AGL-4152), with no picture of its own, is a slot like any other page's.
|
|
1165
|
+
if (page.options.verbatim && block.picture) return sourcePicture(scope, block.picture, room);
|
|
1166
|
+
if (page.options.verbatim && !block.text) return null;
|
|
1163
1167
|
const alt = aiLayoutFitText(block.text, 'alt', scope.page.options.language);
|
|
1164
1168
|
if (!alt) return null;
|
|
1165
1169
|
if (page.images >= maxImages(page)) {
|
|
@@ -4557,11 +4561,11 @@ function listingSection(scope, blocks, placed) {
|
|
|
4557
4561
|
* the source's, nothing else. Any other opening is drawn as its source lays
|
|
4558
4562
|
* it out, its picture where the source placed it.
|
|
4559
4563
|
*/ function importedHero(scope, raw, blocks) {
|
|
4560
|
-
var _ref;
|
|
4564
|
+
var _ref, _ref1;
|
|
4561
4565
|
const { page } = scope;
|
|
4562
4566
|
if (!page.design || !raw.hero) return null;
|
|
4563
|
-
// Its one picture, or its one film, poster first (AGL-4140).
|
|
4564
|
-
const pictures = blocks.filter((block)=>block.kind === 'image' && block.picture || block.kind === 'video' && block.video);
|
|
4567
|
+
// Its one picture, or its one film, poster first (AGL-4140); a slot a redesign asked for in words (AGL-4152).
|
|
4568
|
+
const pictures = blocks.filter((block)=>block.kind === 'image' && (block.picture || block.text) || block.kind === 'video' && block.video);
|
|
4565
4569
|
if (pictures.length !== 1) return null;
|
|
4566
4570
|
const words = blocks.filter((block)=>block.kind !== 'image' && block.kind !== 'video');
|
|
4567
4571
|
if (!words.length || !words.every((block)=>WORD_KINDS.has(block.kind))) return null;
|
|
@@ -4599,7 +4603,7 @@ function listingSection(scope, blocks, placed) {
|
|
|
4599
4603
|
});
|
|
4600
4604
|
const picture = pictures[0].picture;
|
|
4601
4605
|
const opening = hero(scope, flow, _extends({
|
|
4602
|
-
alt: (_ref = picture == null ? void 0 : picture.alt) != null ? _ref : '',
|
|
4606
|
+
alt: (_ref = (_ref1 = picture == null ? void 0 : picture.alt) != null ? _ref1 : pictures[0].text) != null ? _ref : '',
|
|
4603
4607
|
given: true
|
|
4604
4608
|
}, (picture == null ? void 0 : picture.src) ? {
|
|
4605
4609
|
src: picture.src
|