@aglyn/plugins-ai 1.20.1 → 1.20.3
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/jobs/ai-image-reads.d.ts +22 -5
- package/src/lib/jobs/ai-image-reads.js +1 -0
- package/src/lib/jobs/ai-image-reads.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +8 -0
- package/src/lib/jobs/ai-job-import-step.js +29 -2
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +2 -0
- package/src/lib/jobs/ai-site-import-document.js +4 -0
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-graphics.d.ts +47 -0
- package/src/lib/jobs/ai-site-import-graphics.js +151 -0
- package/src/lib/jobs/ai-site-import-graphics.js.map +1 -0
- package/src/lib/jobs/ai-site-import-honesty.d.ts +5 -0
- package/src/lib/jobs/ai-site-import-honesty.js +32 -1
- package/src/lib/jobs/ai-site-import-honesty.js.map +1 -1
- package/src/lib/jobs/ai-site-import-improve.d.ts +9 -1
- package/src/lib/jobs/ai-site-import-improve.js +26 -11
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
- package/src/lib/jobs/ai-site-import-pictures.js +1 -1
- package/src/lib/jobs/ai-site-import-pictures.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +1 -0
- package/src/lib/model/ai-site-import-fidelity.js +4 -2
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-graphic.d.ts +49 -0
- package/src/lib/model/ai-site-import-graphic.js +124 -0
- package/src/lib/model/ai-site-import-graphic.js.map +1 -0
- package/src/lib/model/ai-site-import-ledger.d.ts +8 -1
- package/src/lib/model/ai-site-import-ledger.js +7 -7
- package/src/lib/model/ai-site-import-ledger.js.map +1 -1
- package/src/lib/model/ai-site-import-marks.d.ts +24 -6
- package/src/lib/model/ai-site-import-marks.js +23 -6
- package/src/lib/model/ai-site-import-marks.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +7 -0
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/server/ai-image-reads-route.js +30 -2
- package/src/lib/server/ai-image-reads-route.js.map +1 -1
|
@@ -60,6 +60,8 @@ export interface AiSiteImportDocument {
|
|
|
60
60
|
scope?: string[];
|
|
61
61
|
/** The site's plan, once a wave has one (AGL-4152). */
|
|
62
62
|
plan?: AiSiteImportPlan | null;
|
|
63
|
+
/** The draft id of the site's page whose read holds a form (AGL-4152): where a page with none sends a link to `form`. */
|
|
64
|
+
formPage?: string;
|
|
63
65
|
/** The theme's colors as its look drew them, where one was drawn (`SiteImportFidelityTheme`, AGL-4152). */
|
|
64
66
|
theme?: Record<string, unknown> | null;
|
|
65
67
|
/** The plan's proposed page (AGL-4152): new to the site, with no source to hold it to, and never kept as a fallback. */
|
|
@@ -182,6 +182,8 @@ const clean = (text)=>String(text != null ? text : '').replace(/\s+/g, ' ').trim
|
|
|
182
182
|
alt: photo['alt']
|
|
183
183
|
} : {}, typeof photo['from'] === 'string' ? {
|
|
184
184
|
from: photo['from']
|
|
185
|
+
} : {}, typeof photo['graphic'] === 'boolean' ? {
|
|
186
|
+
graphic: photo['graphic']
|
|
185
187
|
} : {})
|
|
186
188
|
] : [];
|
|
187
189
|
});
|
|
@@ -213,6 +215,8 @@ const clean = (text)=>String(text != null ? text : '').replace(/\s+/g, ' ').trim
|
|
|
213
215
|
scope: strings(value['scope'])
|
|
214
216
|
} : {}, value['plan'] && typeof value['plan'] === 'object' ? {
|
|
215
217
|
plan: value['plan']
|
|
218
|
+
} : {}, typeof value['formPage'] === 'string' && value['formPage'] ? {
|
|
219
|
+
formPage: value['formPage']
|
|
216
220
|
} : {}, value['theme'] && typeof value['theme'] === 'object' ? {
|
|
217
221
|
theme: value['theme']
|
|
218
222
|
} : {}, value['proposed'] === true ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-document.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 WORD FOR WORD (AGL-4084, AGL-4107).\n *\n * An imported page is never rewritten. Its words are the source's, as the\n * crawler read them (`AiSiteImportPageRead.blocks`), and how the source lays\n * them out is the reader's (`AiSiteImportPageRead.layout`, AGL-4106). This\n * module is the page as its job carries it: its blocks, its layout, its\n * photos and where its links go, read defensively off the job's inputs.\n *\n * - **Lines.** The page's main region, numbered: every heading, paragraph,\n * list item, quote, link and picture in source order. A link inside a\n * sentence is in its sentence already and is no line of its own.\n * - **Sections.** Where a read kept no layout (one made before the reader,\n * or one past its budget), one for the page's opening and one at each\n * second-level heading, as the source divides itself.\n *\n * The page is drawn by the site compiler (`ai-site-import-compile.ts`), with\n * every line on it exactly once and never a word that is not the source's.\n *=========================================*/\n\n\nimport {\n AI_SITE_IMPORT_LABEL_MAX_CHARS,\n AI_SITE_IMPORT_MAX_SECTIONS,\n type AiSiteImportBuild,\n type AiSiteImportFinish,\n type AiSiteImportPageRole,\n type AiSiteImportPhoto,\n type AiSiteImportPlan,\n type AiSiteImportWords,\n type SiteImportLayout,\n} from '../model/ai-site-import'\nimport type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html'\nimport { siteImportLabel } from '../site-import/site-import-page'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\n\n/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */\nexport const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = 'importedSections'\n\n/** A page brought in, as the import step hands it to the page step. Untrusted data from the owner's site. */\nexport interface AiSiteImportDocument {\n build: AiSiteImportBuild\n /** The page's name on the new site: its h1 where the source shows no heading. */\n title: string\n /** Where the page is on the owner's website. */\n url: string\n /** The page's main region, in order. */\n blocks: SiteImportBlock[]\n /** Its photos as the library holds them, each by the source address it was read from. */\n photos: AiSiteImportPhoto[]\n /** The site's own pages a link may go to: the source path each was read from, and the page it is now. */\n links: Array<{ path: string; id: string }>\n /** The origins the old site answers on: a link to one of them is to a page of its own. */\n origins: string[]\n /**\n * How the source lays the page out (AGL-4106), over `blocks` by index;\n * absent on a read made before the reader, or one past its budget.\n */\n layout?: SiteImportLayout | null\n /** How the page's wave finishes it (AGL-4152); absent is `keep`. */\n finish?: AiSiteImportFinish | null\n /** Whether its words are improved (AGL-4152); absent is kept as written. */\n wording?: AiSiteImportWords | null\n /** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */\n videos?: SiteImportVideo[]\n /** Redesigned from its ledger (AGL-4152): its wave was stamped generative. Absent, today's Improve it. */\n generative?: true\n /** What the site says of itself, the same bytes on every page of an import: a redesign's cached digest (AGL-4152). */\n siteLines?: string[]\n /** The lines of the wave's other pages, which a redesign's facts may come from (AGL-4152). */\n scope?: string[]\n /** The site's plan, once a wave has one (AGL-4152). */\n plan?: AiSiteImportPlan | null\n /** The theme's colors as its look drew them, where one was drawn (`SiteImportFidelityTheme`, AGL-4152). */\n theme?: Record<string, unknown> | null\n /** The plan's proposed page (AGL-4152): new to the site, with no source to hold it to, and never kept as a fallback. */\n proposed?: true\n /** What the page is for in the planned site (AGL-4152), as its plan says; absent, read from its address and what it holds. */\n role?: AiSiteImportPageRole\n /** Source photos of the site's earlier pages that none of them placed, for a slot of this one (AGL-4152). */\n sitePhotos?: AiSiteImportPhoto[]\n /** A slot nothing else fills may take a generated picture: its owner said so, and it is quoted (AGL-4152). */\n generatedPictures?: true\n /**\n * Its wave was stamped with `release_video_embed_posters` (AGL-4140): a\n * YouTube film whose poster the library could not hold is placed with no\n * poster, and the published page draws YouTube's own still for it.\n */\n videoPosters?: true\n}\n\n/** The most characters a text element holds (the palette's ceiling for body copy). */\nexport const AI_SITE_IMPORT_TEXT_MAX_CHARS = AI_TEXT_LIMITS.body\n\n/** The most characters a heading style holds; a longer heading is drawn in a subtitle style, still a heading. */\nexport const AI_SITE_IMPORT_HEADLINE_MAX_CHARS = AI_TEXT_LIMITS.headline\n\n/** The most characters a button's label holds; a longer link keeps its words as a line of text. */\nexport const AI_SITE_IMPORT_LABEL_CHARS = 40\n\n/**\n * What one page may weigh, inside the budget of a page of its owner's own\n * words (`AI_OWN_WORDS_PAGE_BUDGET`): a page that would run past it ends at\n * the section before, marked `cut`.\n */\nexport const AI_SITE_IMPORT_DOC_MAX_NODES = 1_400\nexport const AI_SITE_IMPORT_DOC_MAX_CHARS = 200_000\n\n/** One numbered line of a page. */\nexport interface AiSiteImportLine {\n /** 1-based, in source order. */\n n: number\n block: SiteImportBlock\n /** The section it belongs to, by plan index. */\n section: number\n}\n\nexport interface AiSiteImportDocSection {\n name: string\n /** Its lines' numbers, in order. */\n lines: number[]\n}\n\nexport interface AiSiteImportDocLines {\n lines: AiSiteImportLine[]\n sections: AiSiteImportDocSection[]\n}\n\nconst clean = (text: string) => String(text ?? '').replace(/\\s+/g, ' ').trim()\n\n/** Whether a block is a line of its own: a link inside a sentence is in its sentence already. */\nfunction isLine(block: SiteImportBlock): boolean {\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/**\n * The page's lines and sections (AGL-4084): the opening, then one section\n * at each second-level heading, at most `AI_SITE_IMPORT_MAX_SECTIONS` (the\n * last holds whatever follows). A page that opens on a second-level heading\n * opens with it. Section names are the headings' words, neutralized and cut\n * to a label, since they travel outside a fence.\n */\nexport function aiSiteImportDocLines(blocks: readonly SiteImportBlock[], title: string): AiSiteImportDocLines {\n const lines: AiSiteImportLine[] = []\n const sections: AiSiteImportDocSection[] = []\n let current: AiSiteImportDocSection | null = null\n for (const block of blocks) {\n if (!isLine(block)) continue\n const starts = block.kind === 'heading' && block.level === 2 && sections.length < AI_SITE_IMPORT_MAX_SECTIONS\n if (!current || (starts && current.lines.length > 0)) {\n current = { name: '', lines: [] }\n sections.push(current)\n }\n const n = lines.length + 1\n lines.push({ n, block, section: sections.length - 1 })\n current.lines.push(n)\n }\n const named = new Set<string>()\n sections.forEach((section, index) => {\n const heading = section.lines.map((n) => lines[n - 1].block).find((block) => block.kind === 'heading')\n let name = siteImportLabel(heading && heading.kind === 'heading' ? heading.text : index === 0 ? title : '') || (index === 0 ? siteImportLabel(title) : '')\n if (!name) name = `Section ${index + 1}`\n // Two sections of one name are told apart, so a link to either finds it.\n let unique = name\n for (let attempt = 2; named.has(unique.toLowerCase()); attempt += 1) {\n unique = `${name.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 4)} (${attempt})`\n }\n named.add(unique.toLowerCase())\n section.name = unique\n })\n if (!sections.length) sections.push({ name: siteImportLabel(title) || 'Introduction', lines: [] })\n return { lines, sections }\n}\n\n/** The words a line shows: an image's are its description. */\nexport function aiSiteImportLineText(line: Pick<AiSiteImportLine, 'block'>): string {\n return line.block.kind === 'image' ? clean(line.block.alt) : clean(line.block.text)\n}\n\n/** How many words a line says: its runs of letters and digits, as the review counts them. */\nexport const aiSiteImportWordsIn = (text: string): number => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** The input a page job carries, read defensively; `null` on every other job. */\nexport function aiSiteImportDocumentOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportDocument | null {\n const raw = inputs?.[AI_LAYOUT_IMPORTED_SECTIONS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const build = value['build'] === 'copied' || value['build'] === 'arranged' ? value['build'] : null\n if (!build || !Array.isArray(value['blocks'])) return null\n const blocks = (value['blocks'] as unknown[]).flatMap((entry): SiteImportBlock[] => {\n if (!entry || typeof entry !== 'object') return []\n const block = entry as Record<string, unknown>\n const text = typeof block['text'] === 'string' ? block['text'] : ''\n const region = 'main' as const\n switch (block['kind']) {\n case 'heading': {\n const level = Number(block['level'])\n return [{ kind: 'heading', level: (Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2) as 1 | 2 | 3 | 4 | 5 | 6, text, region }]\n }\n case 'paragraph':\n case 'list-item':\n case 'quote':\n return [{ kind: block['kind'], text, region }]\n case 'image':\n return typeof block['url'] === 'string' ? [{ kind: 'image', url: block['url'], alt: typeof block['alt'] === 'string' ? block['alt'] : '', region }] : []\n case 'link':\n return typeof block['href'] === 'string'\n ? [{ kind: 'link', text, href: block['href'], region, ...(block['inline'] === true ? { inline: true as const } : {}) }]\n : []\n default:\n return []\n }\n })\n const strings = (list: unknown) => (Array.isArray(list) ? list.filter((entry): entry is string => typeof entry === 'string') : [])\n const size = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0)\n const photosOf = (list: unknown) =>\n (Array.isArray(list) ? list : []).flatMap((entry): AiSiteImportPhoto[] => {\n const photo = entry as Record<string, unknown> | null\n return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string'\n ? [\n {\n mediaId: photo['mediaId'],\n src: photo['src'],\n // Its size, which frames it at its own shape where the source's tag gives none (AGL-4138).\n ...(size(photo['width']) ? { width: size(photo['width']) } : {}),\n ...(size(photo['height']) ? { height: size(photo['height']) } : {}),\n ...(typeof photo['alt'] === 'string' ? { alt: photo['alt'] } : {}),\n ...(typeof photo['from'] === 'string' ? { from: photo['from'] } : {}),\n },\n ]\n : []\n })\n return {\n build,\n title: typeof value['title'] === 'string' ? value['title'] : '',\n url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',\n blocks,\n photos: photosOf(value['photos']),\n links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry) => {\n const link = entry as Record<string, unknown> | null\n return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [{ path: link['path'], id: link['id'] }] : []\n }),\n origins: strings(value['origins']),\n // How the page's wave finishes it and whether its words are improved (AGL-4152); anything else is absent: kept.\n ...(value['finish'] === 'keep' || value['finish'] === 'improve' ? { finish: value['finish'] } : {}),\n ...(value['wording'] === 'kept' || value['wording'] === 'improved' ? { wording: value['wording'] } : {}),\n ...(value['generative'] === true ? { generative: true as const } : {}),\n ...(Array.isArray(value['siteLines']) ? { siteLines: strings(value['siteLines']) } : {}),\n ...(Array.isArray(value['scope']) ? { scope: strings(value['scope']) } : {}),\n ...(value['plan'] && typeof value['plan'] === 'object' ? { plan: value['plan'] as AiSiteImportPlan } : {}),\n ...(value['theme'] && typeof value['theme'] === 'object' ? { theme: value['theme'] as Record<string, unknown> } : {}),\n ...(value['proposed'] === true ? { proposed: true as const } : {}),\n ...(Array.isArray(value['sitePhotos']) ? { sitePhotos: photosOf(value['sitePhotos']) } : {}),\n ...(value['generatedPictures'] === true ? { generatedPictures: true as const } : {}),\n ...(value['videoPosters'] === true ? { videoPosters: true as const } : {}),\n ...(isLayout(value['layout']) ? { layout: value['layout'] } : {}),\n ...(Array.isArray(value['videos']) ? { videos: (value['videos'] as unknown[]).map(videoOf) } : {}),\n }\n}\n\n/**\n * A video as the read keeps it (AGL-4140), read defensively: every address\n * held to http(s), every fact to its kind. One that is no object keeps its\n * place in the list, so the layout's indexes still name the right one.\n */\nfunction videoOf(entry: unknown): SiteImportVideo {\n const video = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {}\n const address = (value: unknown): string | undefined => (typeof value === 'string' && /^https?:\\/\\//i.test(value.trim()) ? value.trim().slice(0, 2048) : undefined)\n const words = (value: unknown, max: number): string | undefined => (typeof value === 'string' && value.trim() ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : undefined)\n const src = address(video['src'])\n const embed = address(video['embed'])\n const poster = address(video['poster'])\n const description = words(video['description'], 2_000)\n const uploadDate = typeof video['uploadDate'] === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(video['uploadDate']) ? video['uploadDate'] : undefined\n const seconds = Number(video['durationSeconds'])\n const flag = (key: 'autoplay' | 'muted' | 'loop' | 'controls') => (video[key] === true ? { [key]: true as const } : {})\n return {\n ...(src ? { src } : {}),\n ...(embed ? { embed } : {}),\n ...(poster ? { poster } : {}),\n title: words(video['title'], 200) ?? '',\n ...(description ? { description } : {}),\n ...(uploadDate ? { uploadDate } : {}),\n ...(Number.isFinite(seconds) && seconds > 0 ? { durationSeconds: Math.round(seconds) } : {}),\n ...flag('autoplay'),\n ...flag('muted'),\n ...flag('loop'),\n ...flag('controls'),\n }\n}\n\n/** Whether a value is a layout as the reader writes one: its sections, icons and look. */\nfunction isLayout(value: unknown): value is SiteImportLayout {\n if (!value || typeof value !== 'object') return false\n const layout = value as Record<string, unknown>\n return (\n layout['v'] === 1 &&\n Array.isArray(layout['sections']) &&\n (layout['sections'] as unknown[]).every((section) => !!section && typeof section === 'object' && Array.isArray((section as Record<string, unknown>)['nodes'])) &&\n Array.isArray(layout['icons'])\n )\n}\n\n/*------------------------------------------\n * Words in parts a text element holds\n *-----------------------------------------*/\n\n/** A paragraph cut between sentences into parts a text element holds, every word kept in order. */\nexport function aiSiteImportTextParts(text: string, max = AI_SITE_IMPORT_TEXT_MAX_CHARS): string[] {\n const words = clean(text)\n if (words.length <= max) return words ? [words] : []\n const sentences = words.match(/[^.!?…]+(?:[.!?…]+[\"'”’)\\]]*\\s*|$)/g) ?? [words]\n const parts: string[] = []\n let part = ''\n const push = () => {\n if (part.trim()) parts.push(part.trim())\n part = ''\n }\n for (const sentence of sentences) {\n if ((part + sentence).trim().length <= max) {\n part += sentence\n continue\n }\n push()\n // One sentence longer than an element holds is cut between words.\n let rest = sentence.trim()\n while (rest.length > max) {\n const at = rest.lastIndexOf(' ', max)\n const cut = at > 0 ? at : max\n parts.push(rest.slice(0, cut).trim())\n rest = rest.slice(cut).trim()\n }\n part = rest ? `${rest} ` : ''\n }\n push()\n return parts\n}\n"],"names":["AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","siteImportLabel","AI_TEXT_LIMITS","AI_LAYOUT_IMPORTED_SECTIONS_INPUT","AI_SITE_IMPORT_TEXT_MAX_CHARS","body","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","headline","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_DOC_MAX_NODES","AI_SITE_IMPORT_DOC_MAX_CHARS","clean","text","String","replace","trim","isLine","block","kind","url","inline","aiSiteImportDocLines","blocks","title","lines","sections","current","starts","level","length","name","push","n","section","named","Set","forEach","index","heading","map","find","unique","attempt","has","toLowerCase","slice","add","aiSiteImportLineText","line","alt","aiSiteImportWordsIn","match","aiSiteImportDocumentOf","inputs","raw","value","build","Array","isArray","flatMap","entry","region","Number","isInteger","href","strings","list","filter","size","isFinite","Math","round","photosOf","photo","mediaId","src","width","height","from","photos","links","link","path","id","origins","finish","wording","generative","siteLines","scope","plan","theme","proposed","sitePhotos","generatedPictures","videoPosters","isLayout","layout","videos","videoOf","words","video","address","test","undefined","max","embed","poster","description","uploadDate","seconds","flag","key","durationSeconds","every","aiSiteImportTextParts","sentences","parts","part","sentence","rest","at","lastIndexOf","cut"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C,GAG3C,SACEA,8BAA8B,EAC9BC,2BAA2B,QAQtB,6BAAyB;AAEhC,SAASC,eAAe,QAAQ,qCAAiC;AACjE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,2GAA2G,GAC3G,OAAO,MAAMC,oCAAoC,mBAAkB;AAwDnE,oFAAoF,GACpF,OAAO,MAAMC,gCAAgCF,eAAeG,IAAI,CAAA;AAEhE,+GAA+G,GAC/G,OAAO,MAAMC,oCAA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,iGAAiG,GACjG,OAAO,SAASkB,sBAAsBvG,IAAY,EAAE6F,MAAMrG,6BAA6B;QAGnEgG;IAFlB,MAAMA,QAAQzF,MAAMC;IACpB,IAAIwF,MAAMvE,MAAM,IAAI4E,KAAK,OAAOL,QAAQ;QAACA;KAAM,GAAG,EAAE;IACpD,MAAMgB,aAAYhB,eAAAA,MAAMjD,KAAK,CAAC,kDAAZiD,eAAsD;QAACA;KAAM;IAC/E,MAAMiB,QAAkB,EAAE;IAC1B,IAAIC,OAAO;IACX,MAAMvF,OAAO;QACX,IAAIuF,KAAKvG,IAAI,IAAIsG,MAAMtF,IAAI,CAACuF,KAAKvG,IAAI;QACrCuG,OAAO;IACT;IACA,KAAK,MAAMC,YAAYH,UAAW;QAChC,IAAI,AAACE,CAAAA,OAAOC,QAAO,EAAGxG,IAAI,GAAGc,MAAM,IAAI4E,KAAK;YAC1Ca,QAAQC;YACR;QACF;QACAxF;QACA,kEAAkE;QAClE,IAAIyF,OAAOD,SAASxG,IAAI;QACxB,MAAOyG,KAAK3F,MAAM,GAAG4E,IAAK;YACxB,MAAMgB,KAAKD,KAAKE,WAAW,CAAC,KAAKjB;YACjC,MAAMkB,MAAMF,KAAK,IAAIA,KAAKhB;YAC1BY,MAAMtF,IAAI,CAACyF,KAAK3E,KAAK,CAAC,GAAG8E,KAAK5G,IAAI;YAClCyG,OAAOA,KAAK3E,KAAK,CAAC8E,KAAK5G,IAAI;QAC7B;QACAuG,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACAzF;IACA,OAAOsF;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-document.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 WORD FOR WORD (AGL-4084, AGL-4107).\n *\n * An imported page is never rewritten. Its words are the source's, as the\n * crawler read them (`AiSiteImportPageRead.blocks`), and how the source lays\n * them out is the reader's (`AiSiteImportPageRead.layout`, AGL-4106). This\n * module is the page as its job carries it: its blocks, its layout, its\n * photos and where its links go, read defensively off the job's inputs.\n *\n * - **Lines.** The page's main region, numbered: every heading, paragraph,\n * list item, quote, link and picture in source order. A link inside a\n * sentence is in its sentence already and is no line of its own.\n * - **Sections.** Where a read kept no layout (one made before the reader,\n * or one past its budget), one for the page's opening and one at each\n * second-level heading, as the source divides itself.\n *\n * The page is drawn by the site compiler (`ai-site-import-compile.ts`), with\n * every line on it exactly once and never a word that is not the source's.\n *=========================================*/\n\n\nimport {\n AI_SITE_IMPORT_LABEL_MAX_CHARS,\n AI_SITE_IMPORT_MAX_SECTIONS,\n type AiSiteImportBuild,\n type AiSiteImportFinish,\n type AiSiteImportPageRole,\n type AiSiteImportPhoto,\n type AiSiteImportPlan,\n type AiSiteImportWords,\n type SiteImportLayout,\n} from '../model/ai-site-import'\nimport type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html'\nimport { siteImportLabel } from '../site-import/site-import-page'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\n\n/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */\nexport const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = 'importedSections'\n\n/** A page brought in, as the import step hands it to the page step. Untrusted data from the owner's site. */\nexport interface AiSiteImportDocument {\n build: AiSiteImportBuild\n /** The page's name on the new site: its h1 where the source shows no heading. */\n title: string\n /** Where the page is on the owner's website. */\n url: string\n /** The page's main region, in order. */\n blocks: SiteImportBlock[]\n /** Its photos as the library holds them, each by the source address it was read from. */\n photos: AiSiteImportPhoto[]\n /** The site's own pages a link may go to: the source path each was read from, and the page it is now. */\n links: Array<{ path: string; id: string }>\n /** The origins the old site answers on: a link to one of them is to a page of its own. */\n origins: string[]\n /**\n * How the source lays the page out (AGL-4106), over `blocks` by index;\n * absent on a read made before the reader, or one past its budget.\n */\n layout?: SiteImportLayout | null\n /** How the page's wave finishes it (AGL-4152); absent is `keep`. */\n finish?: AiSiteImportFinish | null\n /** Whether its words are improved (AGL-4152); absent is kept as written. */\n wording?: AiSiteImportWords | null\n /** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */\n videos?: SiteImportVideo[]\n /** Redesigned from its ledger (AGL-4152): its wave was stamped generative. Absent, today's Improve it. */\n generative?: true\n /** What the site says of itself, the same bytes on every page of an import: a redesign's cached digest (AGL-4152). */\n siteLines?: string[]\n /** The lines of the wave's other pages, which a redesign's facts may come from (AGL-4152). */\n scope?: string[]\n /** The site's plan, once a wave has one (AGL-4152). */\n plan?: AiSiteImportPlan | null\n /** The draft id of the site's page whose read holds a form (AGL-4152): where a page with none sends a link to `form`. */\n formPage?: string\n /** The theme's colors as its look drew them, where one was drawn (`SiteImportFidelityTheme`, AGL-4152). */\n theme?: Record<string, unknown> | null\n /** The plan's proposed page (AGL-4152): new to the site, with no source to hold it to, and never kept as a fallback. */\n proposed?: true\n /** What the page is for in the planned site (AGL-4152), as its plan says; absent, read from its address and what it holds. */\n role?: AiSiteImportPageRole\n /** Source photos of the site's earlier pages that none of them placed, for a slot of this one (AGL-4152). */\n sitePhotos?: AiSiteImportPhoto[]\n /** A slot nothing else fills may take a generated picture: its owner said so, and it is quoted (AGL-4152). */\n generatedPictures?: true\n /**\n * Its wave was stamped with `release_video_embed_posters` (AGL-4140): a\n * YouTube film whose poster the library could not hold is placed with no\n * poster, and the published page draws YouTube's own still for it.\n */\n videoPosters?: true\n}\n\n/** The most characters a text element holds (the palette's ceiling for body copy). */\nexport const AI_SITE_IMPORT_TEXT_MAX_CHARS = AI_TEXT_LIMITS.body\n\n/** The most characters a heading style holds; a longer heading is drawn in a subtitle style, still a heading. */\nexport const AI_SITE_IMPORT_HEADLINE_MAX_CHARS = AI_TEXT_LIMITS.headline\n\n/** The most characters a button's label holds; a longer link keeps its words as a line of text. */\nexport const AI_SITE_IMPORT_LABEL_CHARS = 40\n\n/**\n * What one page may weigh, inside the budget of a page of its owner's own\n * words (`AI_OWN_WORDS_PAGE_BUDGET`): a page that would run past it ends at\n * the section before, marked `cut`.\n */\nexport const AI_SITE_IMPORT_DOC_MAX_NODES = 1_400\nexport const AI_SITE_IMPORT_DOC_MAX_CHARS = 200_000\n\n/** One numbered line of a page. */\nexport interface AiSiteImportLine {\n /** 1-based, in source order. */\n n: number\n block: SiteImportBlock\n /** The section it belongs to, by plan index. */\n section: number\n}\n\nexport interface AiSiteImportDocSection {\n name: string\n /** Its lines' numbers, in order. */\n lines: number[]\n}\n\nexport interface AiSiteImportDocLines {\n lines: AiSiteImportLine[]\n sections: AiSiteImportDocSection[]\n}\n\nconst clean = (text: string) => String(text ?? '').replace(/\\s+/g, ' ').trim()\n\n/** Whether a block is a line of its own: a link inside a sentence is in its sentence already. */\nfunction isLine(block: SiteImportBlock): boolean {\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/**\n * The page's lines and sections (AGL-4084): the opening, then one section\n * at each second-level heading, at most `AI_SITE_IMPORT_MAX_SECTIONS` (the\n * last holds whatever follows). A page that opens on a second-level heading\n * opens with it. Section names are the headings' words, neutralized and cut\n * to a label, since they travel outside a fence.\n */\nexport function aiSiteImportDocLines(blocks: readonly SiteImportBlock[], title: string): AiSiteImportDocLines {\n const lines: AiSiteImportLine[] = []\n const sections: AiSiteImportDocSection[] = []\n let current: AiSiteImportDocSection | null = null\n for (const block of blocks) {\n if (!isLine(block)) continue\n const starts = block.kind === 'heading' && block.level === 2 && sections.length < AI_SITE_IMPORT_MAX_SECTIONS\n if (!current || (starts && current.lines.length > 0)) {\n current = { name: '', lines: [] }\n sections.push(current)\n }\n const n = lines.length + 1\n lines.push({ n, block, section: sections.length - 1 })\n current.lines.push(n)\n }\n const named = new Set<string>()\n sections.forEach((section, index) => {\n const heading = section.lines.map((n) => lines[n - 1].block).find((block) => block.kind === 'heading')\n let name = siteImportLabel(heading && heading.kind === 'heading' ? heading.text : index === 0 ? title : '') || (index === 0 ? siteImportLabel(title) : '')\n if (!name) name = `Section ${index + 1}`\n // Two sections of one name are told apart, so a link to either finds it.\n let unique = name\n for (let attempt = 2; named.has(unique.toLowerCase()); attempt += 1) {\n unique = `${name.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 4)} (${attempt})`\n }\n named.add(unique.toLowerCase())\n section.name = unique\n })\n if (!sections.length) sections.push({ name: siteImportLabel(title) || 'Introduction', lines: [] })\n return { lines, sections }\n}\n\n/** The words a line shows: an image's are its description. */\nexport function aiSiteImportLineText(line: Pick<AiSiteImportLine, 'block'>): string {\n return line.block.kind === 'image' ? clean(line.block.alt) : clean(line.block.text)\n}\n\n/** How many words a line says: its runs of letters and digits, as the review counts them. */\nexport const aiSiteImportWordsIn = (text: string): number => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** The input a page job carries, read defensively; `null` on every other job. */\nexport function aiSiteImportDocumentOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportDocument | null {\n const raw = inputs?.[AI_LAYOUT_IMPORTED_SECTIONS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const build = value['build'] === 'copied' || value['build'] === 'arranged' ? value['build'] : null\n if (!build || !Array.isArray(value['blocks'])) return null\n const blocks = (value['blocks'] as unknown[]).flatMap((entry): SiteImportBlock[] => {\n if (!entry || typeof entry !== 'object') return []\n const block = entry as Record<string, unknown>\n const text = typeof block['text'] === 'string' ? block['text'] : ''\n const region = 'main' as const\n switch (block['kind']) {\n case 'heading': {\n const level = Number(block['level'])\n return [{ kind: 'heading', level: (Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2) as 1 | 2 | 3 | 4 | 5 | 6, text, region }]\n }\n case 'paragraph':\n case 'list-item':\n case 'quote':\n return [{ kind: block['kind'], text, region }]\n case 'image':\n return typeof block['url'] === 'string' ? [{ kind: 'image', url: block['url'], alt: typeof block['alt'] === 'string' ? block['alt'] : '', region }] : []\n case 'link':\n return typeof block['href'] === 'string'\n ? [{ kind: 'link', text, href: block['href'], region, ...(block['inline'] === true ? { inline: true as const } : {}) }]\n : []\n default:\n return []\n }\n })\n const strings = (list: unknown) => (Array.isArray(list) ? list.filter((entry): entry is string => typeof entry === 'string') : [])\n const size = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0)\n const photosOf = (list: unknown) =>\n (Array.isArray(list) ? list : []).flatMap((entry): AiSiteImportPhoto[] => {\n const photo = entry as Record<string, unknown> | null\n return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string'\n ? [\n {\n mediaId: photo['mediaId'],\n src: photo['src'],\n // Its size, which frames it at its own shape where the source's tag gives none (AGL-4138).\n ...(size(photo['width']) ? { width: size(photo['width']) } : {}),\n ...(size(photo['height']) ? { height: size(photo['height']) } : {}),\n ...(typeof photo['alt'] === 'string' ? { alt: photo['alt'] } : {}),\n ...(typeof photo['from'] === 'string' ? { from: photo['from'] } : {}),\n // Whether its pixels make it a graphic, read when it was brought in (AGL-4152).\n ...(typeof photo['graphic'] === 'boolean' ? { graphic: photo['graphic'] } : {}),\n },\n ]\n : []\n })\n return {\n build,\n title: typeof value['title'] === 'string' ? value['title'] : '',\n url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',\n blocks,\n photos: photosOf(value['photos']),\n links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry) => {\n const link = entry as Record<string, unknown> | null\n return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [{ path: link['path'], id: link['id'] }] : []\n }),\n origins: strings(value['origins']),\n // How the page's wave finishes it and whether its words are improved (AGL-4152); anything else is absent: kept.\n ...(value['finish'] === 'keep' || value['finish'] === 'improve' ? { finish: value['finish'] } : {}),\n ...(value['wording'] === 'kept' || value['wording'] === 'improved' ? { wording: value['wording'] } : {}),\n ...(value['generative'] === true ? { generative: true as const } : {}),\n ...(Array.isArray(value['siteLines']) ? { siteLines: strings(value['siteLines']) } : {}),\n ...(Array.isArray(value['scope']) ? { scope: strings(value['scope']) } : {}),\n ...(value['plan'] && typeof value['plan'] === 'object' ? { plan: value['plan'] as AiSiteImportPlan } : {}),\n ...(typeof value['formPage'] === 'string' && value['formPage'] ? { formPage: value['formPage'] } : {}),\n ...(value['theme'] && typeof value['theme'] === 'object' ? { theme: value['theme'] as Record<string, unknown> } : {}),\n ...(value['proposed'] === true ? { proposed: true as const } : {}),\n ...(Array.isArray(value['sitePhotos']) ? { sitePhotos: photosOf(value['sitePhotos']) } : {}),\n ...(value['generatedPictures'] === true ? { generatedPictures: true as const } : {}),\n ...(value['videoPosters'] === true ? { videoPosters: true as const } : {}),\n ...(isLayout(value['layout']) ? { layout: value['layout'] } : {}),\n ...(Array.isArray(value['videos']) ? { videos: (value['videos'] as unknown[]).map(videoOf) } : {}),\n }\n}\n\n/**\n * A video as the read keeps it (AGL-4140), read defensively: every address\n * held to http(s), every fact to its kind. One that is no object keeps its\n * place in the list, so the layout's indexes still name the right one.\n */\nfunction videoOf(entry: unknown): SiteImportVideo {\n const video = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {}\n const address = (value: unknown): string | undefined => (typeof value === 'string' && /^https?:\\/\\//i.test(value.trim()) ? value.trim().slice(0, 2048) : undefined)\n const words = (value: unknown, max: number): string | undefined => (typeof value === 'string' && value.trim() ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : undefined)\n const src = address(video['src'])\n const embed = address(video['embed'])\n const poster = address(video['poster'])\n const description = words(video['description'], 2_000)\n const uploadDate = typeof video['uploadDate'] === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(video['uploadDate']) ? video['uploadDate'] : undefined\n const seconds = Number(video['durationSeconds'])\n const flag = (key: 'autoplay' | 'muted' | 'loop' | 'controls') => (video[key] === true ? { [key]: true as const } : {})\n return {\n ...(src ? { src } : {}),\n ...(embed ? { embed } : {}),\n ...(poster ? { poster } : {}),\n title: words(video['title'], 200) ?? '',\n ...(description ? { description } : {}),\n ...(uploadDate ? { uploadDate } : {}),\n ...(Number.isFinite(seconds) && seconds > 0 ? { durationSeconds: Math.round(seconds) } : {}),\n ...flag('autoplay'),\n ...flag('muted'),\n ...flag('loop'),\n ...flag('controls'),\n }\n}\n\n/** Whether a value is a layout as the reader writes one: its sections, icons and look. */\nfunction isLayout(value: unknown): value is SiteImportLayout {\n if (!value || typeof value !== 'object') return false\n const layout = value as Record<string, unknown>\n return (\n layout['v'] === 1 &&\n Array.isArray(layout['sections']) &&\n (layout['sections'] as unknown[]).every((section) => !!section && typeof section === 'object' && Array.isArray((section as Record<string, unknown>)['nodes'])) &&\n Array.isArray(layout['icons'])\n )\n}\n\n/*------------------------------------------\n * Words in parts a text element holds\n *-----------------------------------------*/\n\n/** A paragraph cut between sentences into parts a text element holds, every word kept in order. */\nexport function aiSiteImportTextParts(text: string, max = AI_SITE_IMPORT_TEXT_MAX_CHARS): string[] {\n const words = clean(text)\n if (words.length <= max) return words ? [words] : []\n const sentences = words.match(/[^.!?…]+(?:[.!?…]+[\"'”’)\\]]*\\s*|$)/g) ?? [words]\n const parts: string[] = []\n let part = ''\n const push = () => {\n if (part.trim()) parts.push(part.trim())\n part = ''\n }\n for (const sentence of sentences) {\n if ((part + sentence).trim().length <= max) {\n part += sentence\n continue\n }\n push()\n // One sentence longer than an element holds is cut between words.\n let rest = sentence.trim()\n while (rest.length > max) {\n const at = rest.lastIndexOf(' ', max)\n const cut = at > 0 ? at : max\n parts.push(rest.slice(0, cut).trim())\n rest = rest.slice(cut).trim()\n }\n part = rest ? `${rest} ` : ''\n }\n push()\n return parts\n}\n"],"names":["AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","siteImportLabel","AI_TEXT_LIMITS","AI_LAYOUT_IMPORTED_SECTIONS_INPUT","AI_SITE_IMPORT_TEXT_MAX_CHARS","body","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","headline","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_DOC_MAX_NODES","AI_SITE_IMPORT_DOC_MAX_CHARS","clean","text","String","replace","trim","isLine","block","kind","url","inline","aiSiteImportDocLines","blocks","title","lines","sections","current","starts","level","length","name","push","n","section","named","Set","forEach","index","heading","map","find","unique","attempt","has","toLowerCase","slice","add","aiSiteImportLineText","line","alt","aiSiteImportWordsIn","match","aiSiteImportDocumentOf","inputs","raw","value","build","Array","isArray","flatMap","entry","region","Number","isInteger","href","strings","list","filter","size","isFinite","Math","round","photosOf","photo","mediaId","src","width","height","from","graphic","photos","links","link","path","id","origins","finish","wording","generative","siteLines","scope","plan","formPage","theme","proposed","sitePhotos","generatedPictures","videoPosters","isLayout","layout","videos","videoOf","words","video","address","test","undefined","max","embed","poster","description","uploadDate","seconds","flag","key","durationSeconds","every","aiSiteImportTextParts","sentences","parts","part","sentence","rest","at","lastIndexOf","cut"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C,GAG3C,SACEA,8BAA8B,EAC9BC,2BAA2B,QAQtB,6BAAyB;AAEhC,SAASC,eAAe,QAAQ,qCAAiC;AACjE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,2GAA2G,GAC3G,OAAO,MAAMC,oCAAoC,mBAAkB;AA0DnE,oFAAoF,GACpF,OAAO,MAAMC,gCAAgCF,eAAeG,IAAI,CAAA;AAEhE,+GAA+G,GAC/G,OAAO,MAAMC,oCAAoCJ,eAAeK,QAAQ,CAAA;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* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { AiSiteImportPhoto } from '../model/ai-site-import';
|
|
18
|
+
/** The clock for reading one page's pictures. */
|
|
19
|
+
export declare const AI_SITE_IMPORT_GRAPHICS_MS = 20000;
|
|
20
|
+
/** Whether a picture's bytes make it a graphic (`aiSiteImportLooksGraphic`), decoded in this process. */
|
|
21
|
+
export declare function aiSiteImportGraphicOfBytes(bytes: Uint8Array): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether each of a site's library pictures, by its media reference, is a
|
|
24
|
+
* graphic, read and decoded in THIS process: what the import does off
|
|
25
|
+
* Vercel, and what the images function does for it there. `null` for one
|
|
26
|
+
* that is not the site's or its org's, cannot be read, or cannot be decoded.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readAiSiteImportGraphicsHere(firestore: FirebaseFirestore.Firestore, refs: readonly string[], hostId: string, orgId: string, signal?: AbortSignal): Promise<Array<boolean | null>>;
|
|
29
|
+
/** Reads whether each picture, by its media reference, is a graphic: `null` for one that could not be read. */
|
|
30
|
+
export type AiSiteImportPictureGraphics = (refs: readonly string[], input: {
|
|
31
|
+
firestore: FirebaseFirestore.Firestore;
|
|
32
|
+
hostId: string;
|
|
33
|
+
orgId: string;
|
|
34
|
+
signal: AbortSignal;
|
|
35
|
+
}) => Promise<ReadonlyArray<boolean | null>>;
|
|
36
|
+
/**
|
|
37
|
+
* A page's photos, each with whether its pixels make it a graphic
|
|
38
|
+
* (`AiSiteImportPhoto.graphic`, AGL-4152), inside the read's own clock.
|
|
39
|
+
* Never throws: a read that fails leaves the photos as they came, and a
|
|
40
|
+
* photo that could not be read keeps no flag.
|
|
41
|
+
*/
|
|
42
|
+
export declare function aiSiteImportPhotoGraphics(assets: readonly AiSiteImportPhoto[], input: {
|
|
43
|
+
firestore: FirebaseFirestore.Firestore;
|
|
44
|
+
hostId: string;
|
|
45
|
+
orgId: string;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
}, read?: AiSiteImportPictureGraphics): Promise<AiSiteImportPhoto[]>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ /*==========================================
|
|
17
|
+
* WHICH OF A PAGE'S PHOTOS ARE GRAPHICS, READ AS THE IMPORT BRINGS THEM IN (AGL-4152).
|
|
18
|
+
*
|
|
19
|
+
* A page's pictures, once in the site's library, are each drawn small and
|
|
20
|
+
* read (`aiSiteImportPixelFacts`), and every photo entry keeps the answer as
|
|
21
|
+
* `graphic`, so a redesign reads a flag and never a picture while a model
|
|
22
|
+
* waits. The read is the library's own (`readAiMediaAssetBytes`): nothing is
|
|
23
|
+
* fetched from a URL.
|
|
24
|
+
*
|
|
25
|
+
* Decoding takes `sharp`, whose native library on Vercel only the plugins'
|
|
26
|
+
* image function ships (`ai-image-reads.ts`, AGL-4048): there the page's
|
|
27
|
+
* pictures go to it by their media references, in one signed request; off
|
|
28
|
+
* Vercel they are read here. A picture that cannot be read keeps no flag,
|
|
29
|
+
* and its name decides, as before.
|
|
30
|
+
*=========================================*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
31
|
+
import { AI_SITE_IMPORT_GRAPHIC_SIDE, aiSiteImportLooksGraphic, aiSiteImportPixelFacts } from "../model/ai-site-import-graphic.js";
|
|
32
|
+
import { aiMediaAssetLocation, loadAiMediaSharp, readAiMediaAssetBytes } from "./ai-media-asset.js";
|
|
33
|
+
/** The clock for reading one page's pictures. */ export const AI_SITE_IMPORT_GRAPHICS_MS = 20000;
|
|
34
|
+
/** The largest picture read: the largest an import brings in. */ const GRAPHIC_MAX_BYTES = 8 * 1024 * 1024;
|
|
35
|
+
/** The raster types an import stores. */ const GRAPHIC_TYPES = /^image\/(?:png|jpeg|webp|gif)$/;
|
|
36
|
+
/** The pictures read at once in this process. */ const AT_ONCE = 4;
|
|
37
|
+
/** Whether a picture's bytes make it a graphic (`aiSiteImportLooksGraphic`), decoded in this process. */ export async function aiSiteImportGraphicOfBytes(bytes) {
|
|
38
|
+
const sharp = await loadAiMediaSharp();
|
|
39
|
+
const side = AI_SITE_IMPORT_GRAPHIC_SIDE;
|
|
40
|
+
const { data, info } = await sharp(Buffer.from(bytes), {
|
|
41
|
+
limitInputPixels: 64000000,
|
|
42
|
+
animated: false
|
|
43
|
+
}).resize(side, side, {
|
|
44
|
+
fit: 'inside'
|
|
45
|
+
}).ensureAlpha().raw().toBuffer({
|
|
46
|
+
resolveWithObject: true
|
|
47
|
+
});
|
|
48
|
+
return aiSiteImportLooksGraphic(aiSiteImportPixelFacts(new Uint8Array(data), info.width, info.height, info.channels));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether each of a site's library pictures, by its media reference, is a
|
|
52
|
+
* graphic, read and decoded in THIS process: what the import does off
|
|
53
|
+
* Vercel, and what the images function does for it there. `null` for one
|
|
54
|
+
* that is not the site's or its org's, cannot be read, or cannot be decoded.
|
|
55
|
+
*/ export async function readAiSiteImportGraphicsHere(firestore, refs, hostId, orgId, signal) {
|
|
56
|
+
const out = refs.map(()=>null);
|
|
57
|
+
let next = 0;
|
|
58
|
+
const worker = async ()=>{
|
|
59
|
+
while(next < refs.length && !(signal == null ? void 0 : signal.aborted)){
|
|
60
|
+
const at = next++;
|
|
61
|
+
const location = aiMediaAssetLocation(refs[at], hostId, orgId);
|
|
62
|
+
if (!location) continue;
|
|
63
|
+
try {
|
|
64
|
+
const asset = await readAiMediaAssetBytes(firestore, location, hostId, {
|
|
65
|
+
maxBytes: GRAPHIC_MAX_BYTES,
|
|
66
|
+
types: GRAPHIC_TYPES
|
|
67
|
+
});
|
|
68
|
+
out[at] = asset ? await aiSiteImportGraphicOfBytes(new Uint8Array(asset.buffer)) : null;
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.warn('[site-import] a picture’s pixels could not be read', {
|
|
71
|
+
hostId,
|
|
72
|
+
error
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
await Promise.all(Array.from({
|
|
78
|
+
length: Math.min(AT_ONCE, refs.length)
|
|
79
|
+
}, worker));
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** Where `sharp` is shipped (`ai-image-reads.ts`): the images function on Vercel, this process elsewhere. */ const readPictureGraphics = async (refs, { firestore, hostId, orgId, signal })=>{
|
|
83
|
+
const images = await import("./ai-image-reads.js");
|
|
84
|
+
const origin = images.aiImageReadsOrigin();
|
|
85
|
+
if (!origin) return readAiSiteImportGraphicsHere(firestore, refs, hostId, orgId, signal);
|
|
86
|
+
const out = [];
|
|
87
|
+
for(let at = 0; at < refs.length; at += images.AI_PICTURE_GRAPHICS_MAX_REFS){
|
|
88
|
+
const chunk = refs.slice(at, at + images.AI_PICTURE_GRAPHICS_MAX_REFS);
|
|
89
|
+
const answer = await images.requestAiImageReads(origin, {
|
|
90
|
+
op: 'picture-graphics',
|
|
91
|
+
refs: chunk,
|
|
92
|
+
hostId,
|
|
93
|
+
orgId
|
|
94
|
+
}, signal);
|
|
95
|
+
const graphics = Array.isArray(answer == null ? void 0 : answer.graphics) ? answer.graphics : [];
|
|
96
|
+
out.push(...chunk.map((_ref, index)=>typeof graphics[index] === 'boolean' ? graphics[index] : null));
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* A page's photos, each with whether its pixels make it a graphic
|
|
102
|
+
* (`AiSiteImportPhoto.graphic`, AGL-4152), inside the read's own clock.
|
|
103
|
+
* Never throws: a read that fails leaves the photos as they came, and a
|
|
104
|
+
* photo that could not be read keeps no flag.
|
|
105
|
+
*/ export async function aiSiteImportPhotoGraphics(assets, input, read = readPictureGraphics) {
|
|
106
|
+
var _input_signal;
|
|
107
|
+
if (!assets.length || ((_input_signal = input.signal) == null ? void 0 : _input_signal.aborted)) return [
|
|
108
|
+
...assets
|
|
109
|
+
];
|
|
110
|
+
const signal = AbortSignal.any([
|
|
111
|
+
AbortSignal.timeout(AI_SITE_IMPORT_GRAPHICS_MS),
|
|
112
|
+
...input.signal ? [
|
|
113
|
+
input.signal
|
|
114
|
+
] : []
|
|
115
|
+
]);
|
|
116
|
+
// The clock holds whichever way the read runs: an answer that does not come in time is none.
|
|
117
|
+
const late = new Promise((_resolve, reject)=>{
|
|
118
|
+
if (signal.aborted) reject(signal.reason);
|
|
119
|
+
else signal.addEventListener('abort', ()=>reject(signal.reason), {
|
|
120
|
+
once: true
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
late.catch(()=>undefined);
|
|
124
|
+
try {
|
|
125
|
+
const flags = await Promise.race([
|
|
126
|
+
read(assets.map((photo)=>photo.src), {
|
|
127
|
+
firestore: input.firestore,
|
|
128
|
+
hostId: input.hostId,
|
|
129
|
+
orgId: input.orgId,
|
|
130
|
+
signal
|
|
131
|
+
}),
|
|
132
|
+
late
|
|
133
|
+
]);
|
|
134
|
+
return assets.map((photo, index)=>{
|
|
135
|
+
const graphic = flags[index];
|
|
136
|
+
return typeof graphic === 'boolean' ? _extends({}, photo, {
|
|
137
|
+
graphic
|
|
138
|
+
}) : photo;
|
|
139
|
+
});
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.warn('[site-import] a page’s pictures could not be read for graphics', {
|
|
142
|
+
hostId: input.hostId,
|
|
143
|
+
error
|
|
144
|
+
});
|
|
145
|
+
return [
|
|
146
|
+
...assets
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=ai-site-import-graphics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-graphics.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 * WHICH OF A PAGE'S PHOTOS ARE GRAPHICS, READ AS THE IMPORT BRINGS THEM IN (AGL-4152).\n *\n * A page's pictures, once in the site's library, are each drawn small and\n * read (`aiSiteImportPixelFacts`), and every photo entry keeps the answer as\n * `graphic`, so a redesign reads a flag and never a picture while a model\n * waits. The read is the library's own (`readAiMediaAssetBytes`): nothing is\n * fetched from a URL.\n *\n * Decoding takes `sharp`, whose native library on Vercel only the plugins'\n * image function ships (`ai-image-reads.ts`, AGL-4048): there the page's\n * pictures go to it by their media references, in one signed request; off\n * Vercel they are read here. A picture that cannot be read keeps no flag,\n * and its name decides, as before.\n *=========================================*/\n\nimport type { AiSiteImportPhoto } from '../model/ai-site-import'\nimport { AI_SITE_IMPORT_GRAPHIC_SIDE, aiSiteImportLooksGraphic, aiSiteImportPixelFacts } from '../model/ai-site-import-graphic'\nimport { aiMediaAssetLocation, loadAiMediaSharp, readAiMediaAssetBytes } from './ai-media-asset'\n\n/** The clock for reading one page's pictures. */\nexport const AI_SITE_IMPORT_GRAPHICS_MS = 20_000\n\n/** The largest picture read: the largest an import brings in. */\nconst GRAPHIC_MAX_BYTES = 8 * 1024 * 1024\n\n/** The raster types an import stores. */\nconst GRAPHIC_TYPES = /^image\\/(?:png|jpeg|webp|gif)$/\n\n/** The pictures read at once in this process. */\nconst AT_ONCE = 4\n\n/** The part of `sharp` the read uses. */\ninterface SharpGraphicPipeline {\n resize(width: number, height: number, options: { fit: 'inside' }): SharpGraphicPipeline\n ensureAlpha(): SharpGraphicPipeline\n raw(): SharpGraphicPipeline\n toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer; info: { width: number; height: number; channels: number } }>\n}\ntype SharpGraphic = (input: Buffer, options?: { limitInputPixels?: number; animated?: boolean }) => SharpGraphicPipeline\n\n/** Whether a picture's bytes make it a graphic (`aiSiteImportLooksGraphic`), decoded in this process. */\nexport async function aiSiteImportGraphicOfBytes(bytes: Uint8Array): Promise<boolean> {\n const sharp = (await loadAiMediaSharp()) as SharpGraphic\n const side = AI_SITE_IMPORT_GRAPHIC_SIDE\n const { data, info } = await sharp(Buffer.from(bytes), { limitInputPixels: 64_000_000, animated: false })\n .resize(side, side, { fit: 'inside' })\n .ensureAlpha()\n .raw()\n .toBuffer({ resolveWithObject: true })\n return aiSiteImportLooksGraphic(aiSiteImportPixelFacts(new Uint8Array(data), info.width, info.height, info.channels))\n}\n\n/**\n * Whether each of a site's library pictures, by its media reference, is a\n * graphic, read and decoded in THIS process: what the import does off\n * Vercel, and what the images function does for it there. `null` for one\n * that is not the site's or its org's, cannot be read, or cannot be decoded.\n */\nexport async function readAiSiteImportGraphicsHere(\n firestore: FirebaseFirestore.Firestore,\n refs: readonly string[],\n hostId: string,\n orgId: string,\n signal?: AbortSignal,\n): Promise<Array<boolean | null>> {\n const out: Array<boolean | null> = refs.map(() => null)\n let next = 0\n const worker = async () => {\n while (next < refs.length && !signal?.aborted) {\n const at = next++\n const location = aiMediaAssetLocation(refs[at], hostId, orgId)\n if (!location) continue\n try {\n const asset = await readAiMediaAssetBytes(firestore, location, hostId, { maxBytes: GRAPHIC_MAX_BYTES, types: GRAPHIC_TYPES })\n out[at] = asset ? await aiSiteImportGraphicOfBytes(new Uint8Array(asset.buffer)) : null\n } catch (error) {\n console.warn('[site-import] a picture’s pixels could not be read', { hostId, error })\n }\n }\n }\n await Promise.all(Array.from({ length: Math.min(AT_ONCE, refs.length) }, worker))\n return out\n}\n\n/** Reads whether each picture, by its media reference, is a graphic: `null` for one that could not be read. */\nexport type AiSiteImportPictureGraphics = (\n refs: readonly string[],\n input: { firestore: FirebaseFirestore.Firestore; hostId: string; orgId: string; signal: AbortSignal },\n) => Promise<ReadonlyArray<boolean | null>>\n\n/** Where `sharp` is shipped (`ai-image-reads.ts`): the images function on Vercel, this process elsewhere. */\nconst readPictureGraphics: AiSiteImportPictureGraphics = async (refs, { firestore, hostId, orgId, signal }) => {\n const images = await import('./ai-image-reads')\n const origin = images.aiImageReadsOrigin()\n if (!origin) return readAiSiteImportGraphicsHere(firestore, refs, hostId, orgId, signal)\n const out: Array<boolean | null> = []\n for (let at = 0; at < refs.length; at += images.AI_PICTURE_GRAPHICS_MAX_REFS) {\n const chunk = refs.slice(at, at + images.AI_PICTURE_GRAPHICS_MAX_REFS)\n const answer = await images.requestAiImageReads<{ graphics?: unknown }>(origin, { op: 'picture-graphics', refs: chunk, hostId, orgId }, signal)\n const graphics = Array.isArray(answer?.graphics) ? answer.graphics : []\n out.push(...chunk.map((_ref, index) => (typeof graphics[index] === 'boolean' ? (graphics[index] as boolean) : null)))\n }\n return out\n}\n\n/**\n * A page's photos, each with whether its pixels make it a graphic\n * (`AiSiteImportPhoto.graphic`, AGL-4152), inside the read's own clock.\n * Never throws: a read that fails leaves the photos as they came, and a\n * photo that could not be read keeps no flag.\n */\nexport async function aiSiteImportPhotoGraphics(\n assets: readonly AiSiteImportPhoto[],\n input: { firestore: FirebaseFirestore.Firestore; hostId: string; orgId: string; signal?: AbortSignal },\n read: AiSiteImportPictureGraphics = readPictureGraphics,\n): Promise<AiSiteImportPhoto[]> {\n if (!assets.length || input.signal?.aborted) return [...assets]\n const signal = AbortSignal.any([AbortSignal.timeout(AI_SITE_IMPORT_GRAPHICS_MS), ...(input.signal ? [input.signal] : [])])\n // The clock holds whichever way the read runs: an answer that does not come in time is none.\n const late = new Promise<never>((_resolve, reject) => {\n if (signal.aborted) reject(signal.reason)\n else signal.addEventListener('abort', () => reject(signal.reason), { once: true })\n })\n late.catch(() => undefined)\n try {\n const flags = await Promise.race([read(assets.map((photo) => photo.src), { firestore: input.firestore, hostId: input.hostId, orgId: input.orgId, signal }), late])\n return assets.map((photo, index) => {\n const graphic = flags[index]\n return typeof graphic === 'boolean' ? { ...photo, graphic } : photo\n })\n } catch (error) {\n console.warn('[site-import] a page’s pictures could not be read for graphics', { hostId: input.hostId, error })\n return [...assets]\n }\n}\n"],"names":["AI_SITE_IMPORT_GRAPHIC_SIDE","aiSiteImportLooksGraphic","aiSiteImportPixelFacts","aiMediaAssetLocation","loadAiMediaSharp","readAiMediaAssetBytes","AI_SITE_IMPORT_GRAPHICS_MS","GRAPHIC_MAX_BYTES","GRAPHIC_TYPES","AT_ONCE","aiSiteImportGraphicOfBytes","bytes","sharp","side","data","info","Buffer","from","limitInputPixels","animated","resize","fit","ensureAlpha","raw","toBuffer","resolveWithObject","Uint8Array","width","height","channels","readAiSiteImportGraphicsHere","firestore","refs","hostId","orgId","signal","out","map","next","worker","length","aborted","at","location","asset","maxBytes","types","buffer","error","console","warn","Promise","all","Array","Math","min","readPictureGraphics","images","origin","aiImageReadsOrigin","AI_PICTURE_GRAPHICS_MAX_REFS","chunk","slice","answer","requestAiImageReads","op","graphics","isArray","push","_ref","index","aiSiteImportPhotoGraphics","assets","input","read","AbortSignal","any","timeout","late","_resolve","reject","reason","addEventListener","once","catch","undefined","flags","race","photo","src","graphic"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;2CAc2C;AAG3C,SAASA,2BAA2B,EAAEC,wBAAwB,EAAEC,sBAAsB,QAAQ,qCAAiC;AAC/H,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,qBAAqB,QAAQ,sBAAkB;AAEhG,+CAA+C,GAC/C,OAAO,MAAMC,6BAA6B,MAAM;AAEhD,+DAA+D,GAC/D,MAAMC,oBAAoB,IAAI,OAAO;AAErC,uCAAuC,GACvC,MAAMC,gBAAgB;AAEtB,+CAA+C,GAC/C,MAAMC,UAAU;AAWhB,uGAAuG,GACvG,OAAO,eAAeC,2BAA2BC,KAAiB;IAChE,MAAMC,QAAS,MAAMR;IACrB,MAAMS,OAAOb;IACb,MAAM,EAAEc,IAAI,EAAEC,IAAI,EAAE,GAAG,MAAMH,MAAMI,OAAOC,IAAI,CAACN,QAAQ;QAAEO,kBAAkB;QAAYC,UAAU;IAAM,GACpGC,MAAM,CAACP,MAAMA,MAAM;QAAEQ,KAAK;IAAS,GACnCC,WAAW,GACXC,GAAG,GACHC,QAAQ,CAAC;QAAEC,mBAAmB;IAAK;IACtC,OAAOxB,yBAAyBC,uBAAuB,IAAIwB,WAAWZ,OAAOC,KAAKY,KAAK,EAAEZ,KAAKa,MAAM,EAAEb,KAAKc,QAAQ;AACrH;AAEA;;;;;CAKC,GACD,OAAO,eAAeC,6BACpBC,SAAsC,EACtCC,IAAuB,EACvBC,MAAc,EACdC,KAAa,EACbC,MAAoB;IAEpB,MAAMC,MAA6BJ,KAAKK,GA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ChB,MAAM;YAC5B,OAAO,OAAOoB,YAAY,YAAY,aAAKF;gBAAOE;iBAAYF;QAChE;IACF,EAAE,OAAOxC,OAAO;QACdC,QAAQC,IAAI,CAAC,kEAAkE;YAAEjB,QAAQwC,MAAMxC,MAAM;YAAEe;QAAM;QAC7G,OAAO;eAAIwB;SAAO;IACpB;AACF"}
|
|
@@ -62,6 +62,11 @@ export declare function aiSiteImportInventedIn(text: string, held: AiSiteImportH
|
|
|
62
62
|
* each picture on an item, and what a group kept whole holds (AGL-4152).
|
|
63
63
|
*/
|
|
64
64
|
export declare function aiSiteImportImprovedPlaced(sections: readonly AiSiteImportImprovedSection[], ledger: Pick<SiteImportLedger, 'items'>): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Where this page may link, in words (AGL-4152): only the kinds of destination
|
|
67
|
+
* it has, so a refusal never names a form, phone or email the page cannot use.
|
|
68
|
+
*/
|
|
69
|
+
export declare function aiSiteImportLinkKinds(destinations: ReadonlyMap<string, string>, ledger: Pick<SiteImportLedger, 'links'>): string;
|
|
65
70
|
/**
|
|
66
71
|
* An answer held to what the import read, and to its ledger (AGL-4152). No
|
|
67
72
|
* violation is a redesign that may be built; each one names its line.
|
|
@@ -194,6 +194,36 @@ const dropped = (message)=>({
|
|
|
194
194
|
code: AI_SITE_IMPORT_DROPPED_ITEM_CODE,
|
|
195
195
|
message
|
|
196
196
|
});
|
|
197
|
+
/**
|
|
198
|
+
* Where this page may link, in words (AGL-4152): only the kinds of destination
|
|
199
|
+
* it has, so a refusal never names a form, phone or email the page cannot use.
|
|
200
|
+
*/ export function aiSiteImportLinkKinds(destinations, ledger) {
|
|
201
|
+
const keys = [
|
|
202
|
+
...destinations.keys()
|
|
203
|
+
];
|
|
204
|
+
const kinds = [
|
|
205
|
+
...keys.some((key)=>key.startsWith('page:')) ? [
|
|
206
|
+
'a page of this site'
|
|
207
|
+
] : [],
|
|
208
|
+
...destinations.has('form') ? [
|
|
209
|
+
'form'
|
|
210
|
+
] : [],
|
|
211
|
+
...destinations.has('phone') ? [
|
|
212
|
+
'phone'
|
|
213
|
+
] : [],
|
|
214
|
+
...destinations.has('email') ? [
|
|
215
|
+
'email'
|
|
216
|
+
] : [],
|
|
217
|
+
...keys.some((key)=>/^#\d+$/.test(key)) ? [
|
|
218
|
+
'a section as #n'
|
|
219
|
+
] : [],
|
|
220
|
+
...ledger.links.length ? [
|
|
221
|
+
'an address the source links'
|
|
222
|
+
] : []
|
|
223
|
+
];
|
|
224
|
+
if (!kinds.length) return 'a destination this page has (it has none)';
|
|
225
|
+
return kinds.length === 1 ? kinds[0] : `${kinds.slice(0, -1).join(', ')}, or ${kinds[kinds.length - 1]}`;
|
|
226
|
+
}
|
|
197
227
|
/**
|
|
198
228
|
* An answer held to what the import read, and to its ledger (AGL-4152). No
|
|
199
229
|
* violation is a redesign that may be built; each one names its line.
|
|
@@ -209,6 +239,7 @@ const dropped = (message)=>({
|
|
|
209
239
|
]));
|
|
210
240
|
const placed = aiSiteImportImprovedPlaced(sections, input.ledger);
|
|
211
241
|
const links = new Set();
|
|
242
|
+
const allowed = aiSiteImportLinkKinds(input.destinations, input.ledger);
|
|
212
243
|
sections.forEach((section, index)=>{
|
|
213
244
|
section.blocks.forEach((raw, position)=>{
|
|
214
245
|
if (raw.kind === 'keep') return;
|
|
@@ -230,7 +261,7 @@ const dropped = (message)=>({
|
|
|
230
261
|
}
|
|
231
262
|
for (const to of linksOf(block)){
|
|
232
263
|
if (input.destinations.has(to)) links.add(input.destinations.get(to));
|
|
233
|
-
else out.push(invented(`${at}: it links to "${to.slice(0, 80)}", which is not
|
|
264
|
+
else out.push(invented(`${at}: it links to "${to.slice(0, 80)}", which is not ${allowed}.`));
|
|
234
265
|
}
|
|
235
266
|
});
|
|
236
267
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-honesty.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 * NEW COPY MAY SAY WHAT THE SOURCE SUPPORTS, AND NOTHING IT DOES NOT (AGL-4152).\n *\n * A redesign may describe what the source says and what this kind of business\n * generally does. It may not make up a name, number, price, date, testimonial,\n * client, award, credential, address or guarantee, and it may not lose what\n * the ledger holds. This is the gate, pure, one answer at a time:\n *\n * - `improve-invented-fact`: a word of its copy says a fact, a name, a\n * credential or a guarantee outside what the import read, or a link goes\n * somewhere the source does not.\n * - `improve-dropped-item`: something the ledger holds is not on the page, or\n * is on it twice.\n *\n * Each names the line, so the one re-ask can mend that line.\n *=========================================*/\n\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport type { AiLayoutBlock, AiLayoutItem } from '../layout-language/ai-layout-language'\nimport { siteImportFactScope, siteImportFactTokens, type SiteImportFactScope } from '../model/ai-site-import-fidelity'\nimport type { SiteImportLedger } from '../model/ai-site-import-ledger'\nimport { detectOffVoiceCopy, type AiCopyFraming, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { aiPlaceholderTokens } from '../runtime/ai-placeholder-tokens'\n\nexport const AI_SITE_IMPORT_INVENTED_FACT_CODE = 'improve-invented-fact'\nexport const AI_SITE_IMPORT_DROPPED_ITEM_CODE = 'improve-dropped-item'\n\n/** A block a redesign answered: the layout language, or a `keep` of a ledger ref. */\nexport type AiSiteImportImprovedBlock = AiLayoutBlock | { kind: 'keep'; ref: string; col?: number }\n\n/** A section a redesign answered. */\nexport interface AiSiteImportImprovedSection {\n band?: 'plain' | 'soft' | 'brand' | 'dark'\n cols?: number[]\n align?: 'start' | 'center'\n blocks: AiSiteImportImprovedBlock[]\n}\n\n/** What a redesign's copy is held against. */\nexport interface AiSiteImportHonestyScope {\n ledger: SiteImportLedger\n /** Every line the import read: this page's, the wave's other pages', and what the home page says of the site. */\n scope: readonly string[]\n /** Where a link may go, as an answer writes it, and the ledger's links' own destinations. */\n destinations: ReadonlyMap<string, string>\n framing?: AiCopyFraming | null\n /** Words the platform's own request put to the answer, no one's name or fact (`siteImportFactScope`). */\n vocabulary?: readonly string[]\n /** This page's own `page:<id>`, where it has one: a link the source makes to the page it is on asks nothing of the answer. */\n own?: string | null\n}\n\n/** Words past a sentence's first that are no one's name, in any heading: the short form of a question list. */\nconst NO_NAMES = new Set(['FAQ', 'FAQs', 'I'])\n\n/**\n * Credentials and guarantees: outside what the source says, each is a claim\n * only its owner can make, however a sentence puts it.\n */\nconst CLAIMS: ReadonlyArray<readonly [string, RegExp]> = [\n ['licensed', /\\blicen[sc]ed\\b/i],\n ['certified', /\\b(?:board-)?certified\\b/i],\n ['accredited', /\\baccredited\\b/i],\n ['insured', /\\binsured\\b/i],\n ['bonded', /\\bbonded\\b/i],\n ['award', /\\baward(?:s|-winning)?\\b/i],\n ['guarantee', /\\bguarantee[ds]?\\b/i],\n ['warranty', /\\bwarrant(?:y|ies)\\b/i],\n ['money-back', /\\bmoney[- ]back\\b/i],\n ['top-rated', /\\btop[- ]rated\\b/i],\n ['five-star', /\\b(?:5|five)[- ]star\\b/i],\n ['voted', /\\bvoted\\b/i],\n ['featured in', /\\bfeatured in\\b/i],\n ['trusted by', /\\btrusted by\\b/i],\n]\n\n/** A count no digit says: \"hundreds of clients\", \"two decades\", \"ten years\". */\nconst COUNTS = [\n /\\b(?:hundreds|thousands|millions|dozens|decades?|centur(?:y|ies))\\b/i,\n /\\b(?:two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|fifteen|twenty|thirty|forty|fifty)\\s+(?:years?|clients?|customers?|families|projects?|homes?|offices?|locations?|reviews?|stars?)\\b/i,\n]\n\n/** A word that opens a line in quotation marks and runs on: a testimonial, whoever is made to say it. */\nconst QUOTED = /^[\"“”'‘][^\"“”]{15,}[\"“”]/\n\n/** Whether text is in the source's own words: its fact tokens, and whatever a scope says of it. */\nexport interface AiSiteImportHonestyFacts {\n facts: SiteImportFactScope\n tokens: ReadonlySet<string>\n /** The source's words, as one text, for what a claim is checked against. */\n said: string\n}\n\n/** What every line of an answer is checked against; `vocabulary` is said, and names and claims nothing. */\nexport function aiSiteImportHonestyFacts(scope: readonly string[], vocabulary: readonly string[] = []): AiSiteImportHonestyFacts {\n const facts = siteImportFactScope(scope, vocabulary)\n return { facts, tokens: new Set(scope.flatMap((text) => siteImportFactTokens(text, facts, false))), said: scope.join(' \\n ') }\n}\n\nconst shown = (token: string) => `\"${token.replace(/^[a-z]+:/, '')}\"`\n\n/** What one line of new copy says that the source does not: a reason in words, or `null`. */\nexport function aiSiteImportInventedIn(text: string, held: AiSiteImportHonestyFacts): string | null {\n const invented = siteImportFactTokens(text, held.facts, true).filter((token) => !held.tokens.has(token) && !(token.startsWith('name:') && NO_NAMES.has(token.slice(5))))\n if (invented.length) return `it says ${[...new Set(invented)].map(shown).join(', ')}, which nothing the site says supports. Say only names and figures the site gives; a heading is in sentence case, so a capital reads as a name.`\n for (const [claim, pattern] of CLAIMS) {\n if (pattern.test(text) && !pattern.test(held.said)) return `it claims ${shown(claim)}, which the site does not. Leave credentials, awards and guarantees to the owner.`\n }\n for (const pattern of COUNTS) {\n const found = pattern.exec(text)?.[0]\n if (found && !new RegExp(`\\\\b${found.replace(/\\s+/g, '\\\\s+')}\\\\b`, 'i').test(held.said)) return `it says ${shown(found)}, a count the site does not give.`\n }\n if (QUOTED.test(text.trim()) && !held.said.includes(text.trim().slice(1, 20))) return 'it reads as a testimonial the site does not have. Quote a customer only by keeping their quote.'\n return null\n}\n\n/** Each written line of a block, as its place on the page names it. */\nfunction writtenLines(block: AiLayoutBlock, at: string): Array<{ at: string; text: string }> {\n const out: Array<{ at: string; text: string }> = []\n if (block.text && block.kind !== 'image') out.push({ at, text: block.text })\n ;(block.items ?? []).forEach((item: AiLayoutItem, index) => {\n if (item.title.trim()) out.push({ at: `${at}, item ${index + 1}`, text: item.title })\n if (item.text.trim()) out.push({ at: `${at}, item ${index + 1}`, text: item.text })\n })\n return out\n}\n\n/** Where a block sends a visitor, its own and its items'. */\nconst linksOf = (block: AiLayoutBlock): string[] => [...(block.to ? [block.to] : []), ...(block.items ?? []).flatMap((item) => (item.to ? [item.to] : []))]\n\n/**\n * Every ledger ref an answer places, as often as it places it: each `keep`,\n * each picture on an item, and what a group kept whole holds (AGL-4152).\n */\nexport function aiSiteImportImprovedPlaced(sections: readonly AiSiteImportImprovedSection[], ledger: Pick<SiteImportLedger, 'items'>): string[] {\n const holds = new Map(ledger.items.map((item) => [item.ref, item.holds ?? []]))\n return sections.flatMap((section) =>\n section.blocks.flatMap((block) => (block.kind === 'keep' ? [block.ref, ...(holds.get(block.ref) ?? [])] : (block.items ?? []).flatMap((item) => (item.ref ? [item.ref] : [])))),\n )\n}\n\nconst invented = (message: string, detail?: string): AiDoctrineViolation => ({ rule: 14, code: AI_SITE_IMPORT_INVENTED_FACT_CODE, message, ...(detail ? { detail } : {}) })\nconst dropped = (message: string): AiDoctrineViolation => ({ rule: null, code: AI_SITE_IMPORT_DROPPED_ITEM_CODE, message })\n\n/**\n * An answer held to what the import read, and to its ledger (AGL-4152). No\n * violation is a redesign that may be built; each one names its line.\n */\nexport function aiSiteImportHonesty(sections: readonly AiSiteImportImprovedSection[], input: AiSiteImportHonestyScope): AiDoctrineViolation[] {\n const held = aiSiteImportHonestyFacts(input.scope, input.vocabulary ?? [])\n const contacts = input.scope.join(' \\n ')\n const out: AiDoctrineViolation[] = []\n const refs = new Map(input.ledger.items.map((item) => [item.ref, item]))\n const placed = aiSiteImportImprovedPlaced(sections, input.ledger)\n const links = new Set<string>()\n sections.forEach((section, index) => {\n section.blocks.forEach((raw, position) => {\n if (raw.kind === 'keep') return\n const block = raw\n const at = `section ${index + 1}, block ${position + 1}`\n for (const line of writtenLines(block, at)) {\n const reason = aiSiteImportInventedIn(line.text, held)\n if (reason) out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": ${reason}`))\n else if (aiLayoutGuardContacts(line.text, contacts) !== line.text) out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": it gives a phone number or email the site does not.`))\n else if (/\\[[^\\]]*\\]/.test(line.text) || aiPlaceholderTokens(line.text).length || detectOffVoiceCopy([{ at: 'line', text: line.text }], input.framing ?? null).length) {\n out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words.`))\n }\n }\n for (const to of linksOf(block)) {\n if (input.destinations.has(to)) links.add(input.destinations.get(to) as string)\n else out.push(invented(`${at}: it links to \"${to.slice(0, 80)}\", which is not a page of this site, form, phone, email, a section as #n, or an address the source links.`))\n }\n })\n })\n // What the ledger holds: each thing that must land, once; no ref twice, and none it does not hold.\n const inGroup = new Map(input.ledger.items.flatMap((item) => (item.holds ?? []).map((held) => [held, item.ref] as const)))\n for (const ref of new Set(placed)) {\n if (!refs.has(ref)) out.push(dropped(`keep \"${ref.slice(0, 40)}\" names nothing on this page. Use only the refs the page lists.`))\n else if (placed.filter((entry) => entry === ref).length > 1) {\n const group = inGroup.get(ref)\n out.push(dropped(`${ref} is placed ${placed.filter((entry) => entry === ref).length} times${group && placed.includes(group) ? `: keeping ${group} whole places it already` : ''}. Place it once.`))\n }\n }\n for (const item of input.ledger.items) {\n if (item.must && !placed.includes(item.ref)) out.push(dropped(`${item.ref} is not on the page. Place it with a keep block, exactly once${item.folded ? ': this page is long, so its groups are kept whole' : ''}.`))\n }\n // The page's own opening picture outranks a new one: a picture asked for in words never takes its place.\n const opening = input.ledger.items.find((item) => item.kind === 'picture' && item.section === 0)\n const first = sections[0]?.blocks ?? []\n if (opening && first.some((block) => block.kind === 'image' && !block.picture) && !first.some((block) => block.kind === 'keep' && block.ref === opening.ref)) {\n out.push(dropped(`${opening.ref} is the page's own opening picture. Open with it, with a keep block, in place of a picture asked for in words.`))\n }\n const kept = new Set(placed)\n const keptLines = new Set(input.ledger.items.filter((item) => kept.has(item.ref)).flatMap((item) => item.lines))\n for (const link of input.ledger.links) {\n const to = input.destinations.get(link.ref)\n if (!to || to === input.own || links.has(to) || keptLines.has(link.line)) continue\n out.push(dropped(`${link.ref} (\"${link.text.slice(0, 60)}\") goes nowhere on the page. Link to it from a button or an item.`))\n }\n return out\n}\n"],"names":["aiLayoutGuardContacts","siteImportFactScope","siteImportFactTokens","detectOffVoiceCopy","aiPlaceholderTokens","AI_SITE_IMPORT_INVENTED_FACT_CODE","AI_SITE_IMPORT_DROPPED_ITEM_CODE","NO_NAMES","Set","CLAIMS","COUNTS","QUOTED","aiSiteImportHonestyFacts","scope","vocabulary","facts","tokens","flatMap","text","said","join","shown","token","replace","aiSiteImportInventedIn","held","invented","filter","has","startsWith","slice","length","map","claim","pattern","test","found","exec","RegExp","trim","includes","writtenLines","block","at","out","kind","push","items","forEach","item","index","title","linksOf","to","aiSiteImportImprovedPlaced","sections","ledger","holds","Map","ref","section","blocks","get","message","detail","rule","code","dropped","aiSiteImportHonesty","input","contacts","refs","placed","links","raw","position","line","reason","framing","destinations","add","inGroup","entry","group","must","folded","opening","find","first","some","picture","kept","keptLines","lines","link","own"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;2CAe2C,GAE3C,SAASA,qBAAqB,QAAQ,uCAAmC;AAEzE,SAASC,mBAAmB,EAAEC,oBAAoB,QAAkC,sCAAkC;AAEtH,SAASC,kBAAkB,QAAsD,uCAAmC;AACpH,SAASC,mBAAmB,QAAQ,sCAAkC;AAEtE,OAAO,MAAMC,oCAAoC,wBAAuB;AACxE,OAAO,MAAMC,mCAAmC,uBAAsB;AA2BtE,6GAA6G,GAC7G,MAAMC,WAAW,IAAIC,IAAI;IAAC;IAAO;IAAQ;CAAI;AAE7C;;;CAGC,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AQzB,MAAMb,MAAM,CAACiB,KAAK,CAAE;QACrC,MAAMpB,KAAKgB,MAAMU,YAAY,CAACjB,GAAG,CAACgC,KAAKnC,GAAG;QAC1C,IAAI,CAACN,MAAMA,OAAOgB,MAAM0B,GAAG,IAAItB,MAAM7C,GAAG,CAACyB,OAAOuC,UAAUhE,GAAG,CAACkE,KAAKlB,IAAI,GAAG;QAC1EhC,IAAIE,IAAI,CAACqB,QAAQ,GAAG2B,KAAKnC,GAAG,CAAC,GAAG,EAAEmC,KAAK5E,IAAI,CAACY,KAAK,CAAC,GAAG,IAAI,iEAAiE,CAAC;IAC7H;IACA,OAAOc;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-honesty.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 * NEW COPY MAY SAY WHAT THE SOURCE SUPPORTS, AND NOTHING IT DOES NOT (AGL-4152).\n *\n * A redesign may describe what the source says and what this kind of business\n * generally does. It may not make up a name, number, price, date, testimonial,\n * client, award, credential, address or guarantee, and it may not lose what\n * the ledger holds. This is the gate, pure, one answer at a time:\n *\n * - `improve-invented-fact`: a word of its copy says a fact, a name, a\n * credential or a guarantee outside what the import read, or a link goes\n * somewhere the source does not.\n * - `improve-dropped-item`: something the ledger holds is not on the page, or\n * is on it twice.\n *\n * Each names the line, so the one re-ask can mend that line.\n *=========================================*/\n\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport type { AiLayoutBlock, AiLayoutItem } from '../layout-language/ai-layout-language'\nimport { siteImportFactScope, siteImportFactTokens, type SiteImportFactScope } from '../model/ai-site-import-fidelity'\nimport type { SiteImportLedger } from '../model/ai-site-import-ledger'\nimport { detectOffVoiceCopy, type AiCopyFraming, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { aiPlaceholderTokens } from '../runtime/ai-placeholder-tokens'\n\nexport const AI_SITE_IMPORT_INVENTED_FACT_CODE = 'improve-invented-fact'\nexport const AI_SITE_IMPORT_DROPPED_ITEM_CODE = 'improve-dropped-item'\n\n/** A block a redesign answered: the layout language, or a `keep` of a ledger ref. */\nexport type AiSiteImportImprovedBlock = AiLayoutBlock | { kind: 'keep'; ref: string; col?: number }\n\n/** A section a redesign answered. */\nexport interface AiSiteImportImprovedSection {\n band?: 'plain' | 'soft' | 'brand' | 'dark'\n cols?: number[]\n align?: 'start' | 'center'\n blocks: AiSiteImportImprovedBlock[]\n}\n\n/** What a redesign's copy is held against. */\nexport interface AiSiteImportHonestyScope {\n ledger: SiteImportLedger\n /** Every line the import read: this page's, the wave's other pages', and what the home page says of the site. */\n scope: readonly string[]\n /** Where a link may go, as an answer writes it, and the ledger's links' own destinations. */\n destinations: ReadonlyMap<string, string>\n framing?: AiCopyFraming | null\n /** Words the platform's own request put to the answer, no one's name or fact (`siteImportFactScope`). */\n vocabulary?: readonly string[]\n /** This page's own `page:<id>`, where it has one: a link the source makes to the page it is on asks nothing of the answer. */\n own?: string | null\n}\n\n/** Words past a sentence's first that are no one's name, in any heading: the short form of a question list. */\nconst NO_NAMES = new Set(['FAQ', 'FAQs', 'I'])\n\n/**\n * Credentials and guarantees: outside what the source says, each is a claim\n * only its owner can make, however a sentence puts it.\n */\nconst CLAIMS: ReadonlyArray<readonly [string, RegExp]> = [\n ['licensed', /\\blicen[sc]ed\\b/i],\n ['certified', /\\b(?:board-)?certified\\b/i],\n ['accredited', /\\baccredited\\b/i],\n ['insured', /\\binsured\\b/i],\n ['bonded', /\\bbonded\\b/i],\n ['award', /\\baward(?:s|-winning)?\\b/i],\n ['guarantee', /\\bguarantee[ds]?\\b/i],\n ['warranty', /\\bwarrant(?:y|ies)\\b/i],\n ['money-back', /\\bmoney[- ]back\\b/i],\n ['top-rated', /\\btop[- ]rated\\b/i],\n ['five-star', /\\b(?:5|five)[- ]star\\b/i],\n ['voted', /\\bvoted\\b/i],\n ['featured in', /\\bfeatured in\\b/i],\n ['trusted by', /\\btrusted by\\b/i],\n]\n\n/** A count no digit says: \"hundreds of clients\", \"two decades\", \"ten years\". */\nconst COUNTS = [\n /\\b(?:hundreds|thousands|millions|dozens|decades?|centur(?:y|ies))\\b/i,\n /\\b(?:two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|fifteen|twenty|thirty|forty|fifty)\\s+(?:years?|clients?|customers?|families|projects?|homes?|offices?|locations?|reviews?|stars?)\\b/i,\n]\n\n/** A word that opens a line in quotation marks and runs on: a testimonial, whoever is made to say it. */\nconst QUOTED = /^[\"“”'‘][^\"“”]{15,}[\"“”]/\n\n/** Whether text is in the source's own words: its fact tokens, and whatever a scope says of it. */\nexport interface AiSiteImportHonestyFacts {\n facts: SiteImportFactScope\n tokens: ReadonlySet<string>\n /** The source's words, as one text, for what a claim is checked against. */\n said: string\n}\n\n/** What every line of an answer is checked against; `vocabulary` is said, and names and claims nothing. */\nexport function aiSiteImportHonestyFacts(scope: readonly string[], vocabulary: readonly string[] = []): AiSiteImportHonestyFacts {\n const facts = siteImportFactScope(scope, vocabulary)\n return { facts, tokens: new Set(scope.flatMap((text) => siteImportFactTokens(text, facts, false))), said: scope.join(' \\n ') }\n}\n\nconst shown = (token: string) => `\"${token.replace(/^[a-z]+:/, '')}\"`\n\n/** What one line of new copy says that the source does not: a reason in words, or `null`. */\nexport function aiSiteImportInventedIn(text: string, held: AiSiteImportHonestyFacts): string | null {\n const invented = siteImportFactTokens(text, held.facts, true).filter((token) => !held.tokens.has(token) && !(token.startsWith('name:') && NO_NAMES.has(token.slice(5))))\n if (invented.length) return `it says ${[...new Set(invented)].map(shown).join(', ')}, which nothing the site says supports. Say only names and figures the site gives; a heading is in sentence case, so a capital reads as a name.`\n for (const [claim, pattern] of CLAIMS) {\n if (pattern.test(text) && !pattern.test(held.said)) return `it claims ${shown(claim)}, which the site does not. Leave credentials, awards and guarantees to the owner.`\n }\n for (const pattern of COUNTS) {\n const found = pattern.exec(text)?.[0]\n if (found && !new RegExp(`\\\\b${found.replace(/\\s+/g, '\\\\s+')}\\\\b`, 'i').test(held.said)) return `it says ${shown(found)}, a count the site does not give.`\n }\n if (QUOTED.test(text.trim()) && !held.said.includes(text.trim().slice(1, 20))) return 'it reads as a testimonial the site does not have. Quote a customer only by keeping their quote.'\n return null\n}\n\n/** Each written line of a block, as its place on the page names it. */\nfunction writtenLines(block: AiLayoutBlock, at: string): Array<{ at: string; text: string }> {\n const out: Array<{ at: string; text: string }> = []\n if (block.text && block.kind !== 'image') out.push({ at, text: block.text })\n ;(block.items ?? []).forEach((item: AiLayoutItem, index) => {\n if (item.title.trim()) out.push({ at: `${at}, item ${index + 1}`, text: item.title })\n if (item.text.trim()) out.push({ at: `${at}, item ${index + 1}`, text: item.text })\n })\n return out\n}\n\n/** Where a block sends a visitor, its own and its items'. */\nconst linksOf = (block: AiLayoutBlock): string[] => [...(block.to ? [block.to] : []), ...(block.items ?? []).flatMap((item) => (item.to ? [item.to] : []))]\n\n/**\n * Every ledger ref an answer places, as often as it places it: each `keep`,\n * each picture on an item, and what a group kept whole holds (AGL-4152).\n */\nexport function aiSiteImportImprovedPlaced(sections: readonly AiSiteImportImprovedSection[], ledger: Pick<SiteImportLedger, 'items'>): string[] {\n const holds = new Map(ledger.items.map((item) => [item.ref, item.holds ?? []]))\n return sections.flatMap((section) =>\n section.blocks.flatMap((block) => (block.kind === 'keep' ? [block.ref, ...(holds.get(block.ref) ?? [])] : (block.items ?? []).flatMap((item) => (item.ref ? [item.ref] : [])))),\n )\n}\n\nconst invented = (message: string, detail?: string): AiDoctrineViolation => ({ rule: 14, code: AI_SITE_IMPORT_INVENTED_FACT_CODE, message, ...(detail ? { detail } : {}) })\nconst dropped = (message: string): AiDoctrineViolation => ({ rule: null, code: AI_SITE_IMPORT_DROPPED_ITEM_CODE, message })\n\n/**\n * Where this page may link, in words (AGL-4152): only the kinds of destination\n * it has, so a refusal never names a form, phone or email the page cannot use.\n */\nexport function aiSiteImportLinkKinds(destinations: ReadonlyMap<string, string>, ledger: Pick<SiteImportLedger, 'links'>): string {\n const keys = [...destinations.keys()]\n const kinds = [\n ...(keys.some((key) => key.startsWith('page:')) ? ['a page of this site'] : []),\n ...(destinations.has('form') ? ['form'] : []),\n ...(destinations.has('phone') ? ['phone'] : []),\n ...(destinations.has('email') ? ['email'] : []),\n ...(keys.some((key) => /^#\\d+$/.test(key)) ? ['a section as #n'] : []),\n ...(ledger.links.length ? ['an address the source links'] : []),\n ]\n if (!kinds.length) return 'a destination this page has (it has none)'\n return kinds.length === 1 ? (kinds[0] as string) : `${kinds.slice(0, -1).join(', ')}, or ${kinds[kinds.length - 1] as string}`\n}\n\n/**\n * An answer held to what the import read, and to its ledger (AGL-4152). No\n * violation is a redesign that may be built; each one names its line.\n */\nexport function aiSiteImportHonesty(sections: readonly AiSiteImportImprovedSection[], input: AiSiteImportHonestyScope): AiDoctrineViolation[] {\n const held = aiSiteImportHonestyFacts(input.scope, input.vocabulary ?? [])\n const contacts = input.scope.join(' \\n ')\n const out: AiDoctrineViolation[] = []\n const refs = new Map(input.ledger.items.map((item) => [item.ref, item]))\n const placed = aiSiteImportImprovedPlaced(sections, input.ledger)\n const links = new Set<string>()\n const allowed = aiSiteImportLinkKinds(input.destinations, input.ledger)\n sections.forEach((section, index) => {\n section.blocks.forEach((raw, position) => {\n if (raw.kind === 'keep') return\n const block = raw\n const at = `section ${index + 1}, block ${position + 1}`\n for (const line of writtenLines(block, at)) {\n const reason = aiSiteImportInventedIn(line.text, held)\n if (reason) out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": ${reason}`))\n else if (aiLayoutGuardContacts(line.text, contacts) !== line.text) out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": it gives a phone number or email the site does not.`))\n else if (/\\[[^\\]]*\\]/.test(line.text) || aiPlaceholderTokens(line.text).length || detectOffVoiceCopy([{ at: 'line', text: line.text }], input.framing ?? null).length) {\n out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words.`))\n }\n }\n for (const to of linksOf(block)) {\n if (input.destinations.has(to)) links.add(input.destinations.get(to) as string)\n else out.push(invented(`${at}: it links to \"${to.slice(0, 80)}\", which is not ${allowed}.`))\n }\n })\n })\n // What the ledger holds: each thing that must land, once; no ref twice, and none it does not hold.\n const inGroup = new Map(input.ledger.items.flatMap((item) => (item.holds ?? []).map((held) => [held, item.ref] as const)))\n for (const ref of new Set(placed)) {\n if (!refs.has(ref)) out.push(dropped(`keep \"${ref.slice(0, 40)}\" names nothing on this page. Use only the refs the page lists.`))\n else if (placed.filter((entry) => entry === ref).length > 1) {\n const group = inGroup.get(ref)\n out.push(dropped(`${ref} is placed ${placed.filter((entry) => entry === ref).length} times${group && placed.includes(group) ? `: keeping ${group} whole places it already` : ''}. Place it once.`))\n }\n }\n for (const item of input.ledger.items) {\n if (item.must && !placed.includes(item.ref)) out.push(dropped(`${item.ref} is not on the page. Place it with a keep block, exactly once${item.folded ? ': this page is long, so its groups are kept whole' : ''}.`))\n }\n // The page's own opening picture outranks a new one: a picture asked for in words never takes its place.\n const opening = input.ledger.items.find((item) => item.kind === 'picture' && item.section === 0)\n const first = sections[0]?.blocks ?? []\n if (opening && first.some((block) => block.kind === 'image' && !block.picture) && !first.some((block) => block.kind === 'keep' && block.ref === opening.ref)) {\n out.push(dropped(`${opening.ref} is the page's own opening picture. Open with it, with a keep block, in place of a picture asked for in words.`))\n }\n const kept = new Set(placed)\n const keptLines = new Set(input.ledger.items.filter((item) => kept.has(item.ref)).flatMap((item) => item.lines))\n for (const link of input.ledger.links) {\n const to = input.destinations.get(link.ref)\n if (!to || to === input.own || links.has(to) || keptLines.has(link.line)) continue\n out.push(dropped(`${link.ref} (\"${link.text.slice(0, 60)}\") goes nowhere on the page. Link to it from a button or an item.`))\n }\n return out\n}\n"],"names":["aiLayoutGuardContacts","siteImportFactScope","siteImportFactTokens","detectOffVoiceCopy","aiPlaceholderTokens","AI_SITE_IMPORT_INVENTED_FACT_CODE","AI_SITE_IMPORT_DROPPED_ITEM_CODE","NO_NAMES","Set","CLAIMS","COUNTS","QUOTED","aiSiteImportHonestyFacts","scope","vocabulary","facts","tokens","flatMap","text","said","join","shown","token","replace","aiSiteImportInventedIn","held","invented","filter","has","startsWith","slice","length","map","claim","pattern","test","found","exec","RegExp","trim","includes","writtenLines","block","at","out","kind","push","items","forEach","item","index","title","linksOf","to","aiSiteImportImprovedPlaced","sections","ledger","holds","Map","ref","section","blocks","get","message","detail","rule","code","dropped","aiSiteImportLinkKinds","destinations","keys","kinds","some","key","links","aiSiteImportHonesty","input","contacts","refs","placed","allowed","raw","position","line","reason","framing","add","inGroup","entry","group","must","folded","opening","find","first","picture","kept","keptLines","lines","link","own"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;2CAe2C,GAE3C,SAASA,qBAAqB,QAAQ,uCAAmC;AAEzE,SAASC,mBAAmB,EAAEC,oBAAoB,QAAkC,sCAAkC;AAEtH,SAASC,kBAAkB,QAAsD,uCAAmC;AACpH,SAASC,mBAAmB,QAAQ,sCAAkC;AAEtE,OAAO,MAAMC,oCAAoC,wBAAuB;AACxE,OAAO,MAAMC,mCAAmC,uBAAsB;AA2BtE,6GAA6G,GAC7G,MAAMC,WAAW,IAAIC,IAAI;IAAC;IAAO;IAAQ;CAAI;AAE7C;;;CAGC,GACD,MAAMC,SAAmD;IACvD;QAAC;QAAY;KAAmB;IAChC;QAAC;QAAa;KAA4B;IAC1C;QAAC;QAAc;KAAkB;IACjC;QAAC;QAAW;KAAe;IAC3B;QAAC;QAAU;KAAc;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AiSiteImportDocumen
|
|
|
70
70
|
sections?: number;
|
|
71
71
|
formSection?: number | null;
|
|
72
72
|
}): Map<string, string>;
|
|
73
|
+
/**
|
|
74
|
+
* The site's page that holds its form (AGL-4152), as `page:<id>`: the one the
|
|
75
|
+
* plan's header button sends `form` to, else the one the import read a form
|
|
76
|
+
* on. `null` where no page of the site holds one, where that page is not one a
|
|
77
|
+
* link may go to, or where it is the page itself, which holds its form in place.
|
|
78
|
+
*/
|
|
79
|
+
export declare function aiSiteImportFormPageOf(doc: Pick<AiSiteImportDocument, 'plan' | 'formPage' | 'links' | 'url'>): string | null;
|
|
73
80
|
/**
|
|
74
81
|
* The page's own `page:<id>` on the new site (AGL-4152), by its address: a
|
|
75
82
|
* link to it from itself goes nowhere a visitor is not already. `null` where
|
|
@@ -207,7 +214,8 @@ export interface AiSiteImportImprovedPage {
|
|
|
207
214
|
}
|
|
208
215
|
/**
|
|
209
216
|
* The opening of a redesign without a brand's mark for its photo (AGL-4152):
|
|
210
|
-
* a picture the source names a logo, a badge or an icon
|
|
217
|
+
* a picture the source names a logo, a badge or an icon, or whose pixels make
|
|
218
|
+
* it a graphic (`aiSiteImportIsBrandMark`),
|
|
211
219
|
* that the answer keeps in its first section takes the page's widest photo no
|
|
212
220
|
* section placed instead, or, where it has none, is left out, and a row it
|
|
213
221
|
* leaves a column empty in is drawn as one column. A client's logo the source
|