@aglyn/plugins-ai 1.20.2 → 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.
Files changed (33) hide show
  1. package/package.json +17 -17
  2. package/src/lib/jobs/ai-image-reads.d.ts +22 -5
  3. package/src/lib/jobs/ai-image-reads.js +1 -0
  4. package/src/lib/jobs/ai-image-reads.js.map +1 -1
  5. package/src/lib/jobs/ai-job-import-step.d.ts +3 -0
  6. package/src/lib/jobs/ai-job-import-step.js +14 -2
  7. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  8. package/src/lib/jobs/ai-site-import-document.js +2 -0
  9. package/src/lib/jobs/ai-site-import-document.js.map +1 -1
  10. package/src/lib/jobs/ai-site-import-graphics.d.ts +47 -0
  11. package/src/lib/jobs/ai-site-import-graphics.js +151 -0
  12. package/src/lib/jobs/ai-site-import-graphics.js.map +1 -0
  13. package/src/lib/jobs/ai-site-import-improve.d.ts +2 -1
  14. package/src/lib/jobs/ai-site-import-improve.js +7 -11
  15. package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
  16. package/src/lib/jobs/ai-site-import-pictures.js +1 -1
  17. package/src/lib/jobs/ai-site-import-pictures.js.map +1 -1
  18. package/src/lib/model/ai-site-import-fidelity.d.ts +1 -0
  19. package/src/lib/model/ai-site-import-fidelity.js +4 -2
  20. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  21. package/src/lib/model/ai-site-import-graphic.d.ts +49 -0
  22. package/src/lib/model/ai-site-import-graphic.js +124 -0
  23. package/src/lib/model/ai-site-import-graphic.js.map +1 -0
  24. package/src/lib/model/ai-site-import-ledger.d.ts +8 -1
  25. package/src/lib/model/ai-site-import-ledger.js +7 -7
  26. package/src/lib/model/ai-site-import-ledger.js.map +1 -1
  27. package/src/lib/model/ai-site-import-marks.d.ts +24 -6
  28. package/src/lib/model/ai-site-import-marks.js +23 -6
  29. package/src/lib/model/ai-site-import-marks.js.map +1 -1
  30. package/src/lib/model/ai-site-import.d.ts +7 -0
  31. package/src/lib/model/ai-site-import.js.map +1 -1
  32. package/src/lib/server/ai-image-reads-route.js +30 -2
  33. package/src/lib/server/ai-image-reads-route.js.map +1 -1
@@ -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
  });
@@ -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 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 },\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","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;AAExE,iGAAiG,GACjG,OAAO,MAAMC,6BAA6B,GAAE;AAE5C;;;;CAIC,GACD,OAAO,MAAMC,+BAA+B,KAAK;AACjD,OAAO,MAAMC,+BAA+B,OAAO;AAsBnD,MAAMC,QAAQ,CAACC,OAAiBC,OAAOD,eAAAA,OAAQ,IAAIE,OAAO,CAAC,QAAQ,KAAKC,IAAI;AAE5E,+FAA+F,GAC/F,SAASC,OAAOC,KAAsB;IACpC,IAAIA,MAAMC,IAAI,KAAK,SAAS,OAAO,CAAC,CAACD,MAAME,GAAG;IAC9C,IAAIF,MAAMC,IAAI,KAAK,QAAQ,OAAO,CAACD,MAAMG,MAAM,IAAI,CAAC,CAACT,MAAMM,MAAML,IAAI;IACrE,OAAO,CAAC,CAACD,MAAMM,MAAML,IAAI;AAC3B;AAEA;;;;;;CAMC,GACD,OAAO,SAASS,qBAAqBC,MAAkC,EAAEC,KAAa;IACpF,MAAMC,QAA4B,EAAE;IACpC,MAAMC,WAAqC,EAAE;IAC7C,IAAIC,UAAyC;IAC7C,KAAK,MAAMT,SAASK,OAAQ;QAC1B,IAAI,CAACN,OAAOC,QAAQ;QACpB,MAAMU,SAAS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AAI;QACxB,MAAO0G,KAAK5F,MAAM,GAAG6E,IAAK;YACxB,MAAMgB,KAAKD,KAAKE,WAAW,CAAC,KAAKjB;YACjC,MAAMkB,MAAMF,KAAK,IAAIA,KAAKhB;YAC1BY,MAAMvF,IAAI,CAAC0F,KAAK5E,KAAK,CAAC,GAAG+E,KAAK7G,IAAI;YAClC0G,OAAOA,KAAK5E,KAAK,CAAC+E,KAAK7G,IAAI;QAC7B;QACAwG,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACA1F;IACA,OAAOuF;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;AAExE,iGAAiG,GACjG,OAAO,MAAMC,6BAA6B,GAAE;AAE5C;;;;CAIC,GACD,OAAO,MAAMC,+BAA+B,KAAK;AACjD,OAAO,MAAMC,+BAA+B,OAAO;AAsBnD,MAAMC,QAAQ,CAACC,OAAiBC,OAAOD,eAAAA,OAAQ,IAAIE,OAAO,CAAC,QAAQ,KAAKC,IAAI;AAE5E,+FAA+F,GAC/F,SAASC,OAAOC,KAAsB;IACpC,IAAIA,MAAMC,IAAI,KAAK,SAAS,OAAO,CAAC,CAACD,MAAME,GAAG;IAC9C,IAAIF,MAAMC,IAAI,KAAK,QAAQ,OAAO,CAACD,MAAMG,MAAM,IAAI,CAAC,CAACT,MAAMM,MAAML,IAAI;IACrE,OAAO,CAAC,CAACD,MAAMM,MAAML,IAAI;AAC3B;AAEA;;;;;;CAMC,GACD,OAAO,SAASS,qBAAqBC,MAAkC,EAAEC,KAAa;IACpF,MAAMC,QAA4B,EAAE;IACpC,MAAMC,WAAqC,EAAE;IAC7C,IAAIC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IACA,KAAK,MAAMC,YAAYH,UAAW;QAChC,IAAI,AAACE,CAAAA,OAAOC,QAAO,EAAG1G,IAAI,GAAGc,MAAM,IAAI8E,KAAK;YAC1Ca,QAAQC;YACR;QACF;QACA1F;QACA,kEAAkE;QAClE,IAAI2F,OAAOD,SAAS1G,IAAI;QACxB,MAAO2G,KAAK7F,MAAM,GAAG8E,IAAK;YACxB,MAAMgB,KAAKD,KAAKE,WAAW,CAAC,KAAKjB;YACjC,MAAMkB,MAAMF,KAAK,IAAIA,KAAKhB;YAC1BY,MAAMxF,IAAI,CAAC2F,KAAK7E,KAAK,CAAC,GAAGgF,KAAK9G,IAAI;YAClC2G,OAAOA,KAAK7E,KAAK,CAACgF,KAAK9G,IAAI;QAC7B;QACAyG,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACA3F;IACA,OAAOwF;AACT"}
@@ -0,0 +1,47 @@
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
+ 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;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AAM;QAAK;IAClF;IACAL,KAAKM,KAAK,CAAC,IAAMC;IACjB,IAAI;QACF,MAAMC,QAAQ,MAAMnC,QAAQoC,IAAI,CAAC;YAACb,KAAKF,OAAOnC,GAAG,CAAC,CAACmD,QAAUA,MAAMC,GAAG,GAAG;gBAAE1D,WAAW0C,MAAM1C,SAAS;gBAAEE,QAAQwC,MAAMxC,MAAM;gBAAEC,OAAOuC,MAAMvC,KAAK;gBAAEC;YAAO;YAAI2C;SAAK;QACjK,OAAON,OAAOnC,GAAG,CAAC,CAACmD,OAAOlB;YACxB,MAAMoB,UAAUJ,KAAK,CAAChB,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"}
@@ -214,7 +214,8 @@ export interface AiSiteImportImprovedPage {
214
214
  }
215
215
  /**
216
216
  * The opening of a redesign without a brand's mark for its photo (AGL-4152):
217
- * a picture the source names a logo, a badge or an icon (`aiSiteImportIsBrandMark`)
217
+ * a picture the source names a logo, a badge or an icon, or whose pixels make
218
+ * it a graphic (`aiSiteImportIsBrandMark`),
218
219
  * that the answer keeps in its first section takes the page's widest photo no
219
220
  * section placed instead, or, where it has none, is left out, and a row it
220
221
  * leaves a column empty in is drawn as one column. A client's logo the source
@@ -43,7 +43,7 @@ import { AI_LAYOUT_ALIGNS, AI_LAYOUT_BANDS, AI_LAYOUT_MAX_COLS, AI_LAYOUT_STYLES
43
43
  import { AI_ICON_WORDS } from "../runtime/ai-icon-library.js";
44
44
  import { aiSiteHomeArc } from "../model/ai-site-home-arcs.js";
45
45
  import { SITE_IMPORT_IMPROVED_MEANING, SITE_IMPORT_MEANING_FLOOR, siteImportContentKept, siteImportContentWords } from "../model/ai-site-import-fidelity.js";
46
- import { aiSiteImportIsBrandMark } from "../model/ai-site-import-marks.js";
46
+ import { aiSiteImportImageIsMark } from "../model/ai-site-import-marks.js";
47
47
  import { siteImportLedger } from "../model/ai-site-import-ledger.js";
48
48
  import { AI_SITE_IMPORT_PAGE_CEILING_CREDITS } from "../model/ai-site-import.js";
49
49
  import { estimateAiBilledUsd } from "../providers/catalog.js";
@@ -867,7 +867,8 @@ const WORD_KINDS = new Set([
867
867
  }
868
868
  /**
869
869
  * The opening of a redesign without a brand's mark for its photo (AGL-4152):
870
- * a picture the source names a logo, a badge or an icon (`aiSiteImportIsBrandMark`)
870
+ * a picture the source names a logo, a badge or an icon, or whose pixels make
871
+ * it a graphic (`aiSiteImportIsBrandMark`),
871
872
  * that the answer keeps in its first section takes the page's widest photo no
872
873
  * section placed instead, or, where it has none, is left out, and a row it
873
874
  * leaves a column empty in is drawn as one column. A client's logo the source
@@ -889,10 +890,7 @@ const WORD_KINDS = new Set([
889
890
  };
890
891
  const markAt = (ref)=>{
891
892
  const image = imageOf(ref);
892
- return !!image && aiSiteImportIsBrandMark({
893
- url: image.url,
894
- alt: image.alt
895
- });
893
+ return !!image && aiSiteImportImageIsMark(image, doc.photos);
896
894
  };
897
895
  const marks = new Set(first.blocks.filter((block)=>block.kind === 'keep' && markAt(block.ref)));
898
896
  if (!marks.size) return [
@@ -1039,10 +1037,7 @@ const WORD_KINDS = new Set([
1039
1037
  if (ownOpening.taken) return null;
1040
1038
  const ratioOf = (line)=>{
1041
1039
  const image = line === undefined || scope.used.has(line) ? undefined : doc.blocks[line];
1042
- if ((image == null ? void 0 : image.kind) !== 'image' || aiSiteImportIsBrandMark({
1043
- url: image.url,
1044
- alt: image.alt
1045
- })) return 0;
1040
+ if ((image == null ? void 0 : image.kind) !== 'image' || aiSiteImportImageIsMark(image, scope.photos)) return 0;
1046
1041
  const photo = scope.photos.get(image.url);
1047
1042
  return (photo == null ? void 0 : photo.width) && photo.height ? photo.width / photo.height : 0;
1048
1043
  };
@@ -1510,7 +1505,8 @@ const plus = (a, b)=>({
1510
1505
  /** A redesign's read for a page: its ledger, and everywhere a link may go. */ export function aiSiteImportImproveLedger(doc) {
1511
1506
  return siteImportLedger({
1512
1507
  layout: aiSiteImportLayoutOf(doc),
1513
- blocks: doc.blocks
1508
+ blocks: doc.blocks,
1509
+ photos: doc.photos
1514
1510
  });
1515
1511
  }
1516
1512
  /**