@aglyn/plugins-ai 1.6.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +2 -2
  2. package/package.json +17 -17
  3. package/src/lib/components/ai-insight-dialog.component.js +14 -0
  4. package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
  5. package/src/lib/insights/ai-figure-readers.d.ts +13 -0
  6. package/src/lib/insights/ai-figure-readers.js +158 -11
  7. package/src/lib/insights/ai-figure-readers.js.map +1 -1
  8. package/src/lib/insights/ai-figure-summaries.js +4 -2
  9. package/src/lib/insights/ai-figure-summaries.js.map +1 -1
  10. package/src/lib/insights/ai-insight-digest.d.ts +27 -17
  11. package/src/lib/insights/ai-insight-digest.js +96 -107
  12. package/src/lib/insights/ai-insight-digest.js.map +1 -1
  13. package/src/lib/jobs/ai-job-import-step.d.ts +28 -2
  14. package/src/lib/jobs/ai-job-import-step.js +170 -14
  15. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  16. package/src/lib/jobs/ai-job-insight-budget.d.ts +19 -3
  17. package/src/lib/jobs/ai-job-insight-budget.js +18 -4
  18. package/src/lib/jobs/ai-job-insight-budget.js.map +1 -1
  19. package/src/lib/jobs/ai-job-insight-step.d.ts +2 -2
  20. package/src/lib/jobs/ai-job-insight-step.js +17 -7
  21. package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
  22. package/src/lib/jobs/ai-job-layout-language.js +2 -0
  23. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  24. package/src/lib/jobs/ai-job-page-language.js +6 -2
  25. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  26. package/src/lib/jobs/ai-site-import-compile.d.ts +13 -3
  27. package/src/lib/jobs/ai-site-import-compile.js +336 -27
  28. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  29. package/src/lib/jobs/ai-site-import-document.d.ts +3 -1
  30. package/src/lib/jobs/ai-site-import-document.js +36 -0
  31. package/src/lib/jobs/ai-site-import-document.js.map +1 -1
  32. package/src/lib/jobs/ai-site-import-look.d.ts +9 -0
  33. package/src/lib/jobs/ai-site-import-look.js +89 -6
  34. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  35. package/src/lib/layout-language/ai-layout-compiler.d.ts +16 -0
  36. package/src/lib/layout-language/ai-layout-compiler.js +351 -54
  37. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  38. package/src/lib/layout-language/ai-layout-frame-source.d.ts +88 -2
  39. package/src/lib/layout-language/ai-layout-frame-source.js +591 -30
  40. package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
  41. package/src/lib/layout-language/ai-layout-frame.js +30 -18
  42. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  43. package/src/lib/layout-language/ai-layout-language.d.ts +72 -3
  44. package/src/lib/layout-language/ai-layout-language.js +5 -3
  45. package/src/lib/layout-language/ai-layout-language.js.map +1 -1
  46. package/src/lib/layout-language/ai-layout-store.d.ts +8 -0
  47. package/src/lib/layout-language/ai-layout-store.js +32 -6
  48. package/src/lib/layout-language/ai-layout-store.js.map +1 -1
  49. package/src/lib/model/ai-insight.d.ts +23 -3
  50. package/src/lib/model/ai-insight.js +17 -3
  51. package/src/lib/model/ai-insight.js.map +1 -1
  52. package/src/lib/model/ai-site-import-fidelity.d.ts +31 -1
  53. package/src/lib/model/ai-site-import-fidelity.js +347 -25
  54. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  55. package/src/lib/model/ai-site-import.d.ts +203 -6
  56. package/src/lib/model/ai-site-import.js +161 -5
  57. package/src/lib/model/ai-site-import.js.map +1 -1
  58. package/src/lib/model/ai-site-look.d.ts +8 -1
  59. package/src/lib/model/ai-site-look.js +8 -5
  60. package/src/lib/model/ai-site-look.js.map +1 -1
  61. package/src/lib/providers/routing.js +3 -1
  62. package/src/lib/providers/routing.js.map +1 -1
  63. package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -1
  64. package/src/lib/runtime/ai-doctrine-validators.js +25 -2
  65. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  66. package/src/lib/runtime/ai-insight-check.d.ts +7 -0
  67. package/src/lib/runtime/ai-insight-check.js +111 -27
  68. package/src/lib/runtime/ai-insight-check.js.map +1 -1
  69. package/src/lib/runtime/ai-node-tree.js +19 -2
  70. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  71. package/src/lib/runtime/ai-page-links.d.ts +15 -0
  72. package/src/lib/runtime/ai-page-links.js +48 -0
  73. package/src/lib/runtime/ai-page-links.js.map +1 -1
  74. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +30 -5
  75. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  76. package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +9 -0
  77. package/src/lib/site-import/fixtures/site-layout-recordings.js +24 -5
  78. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  79. package/src/lib/site-import/site-import-crawl.d.ts +3 -1
  80. package/src/lib/site-import/site-import-crawl.js +8 -3
  81. package/src/lib/site-import/site-import-crawl.js.map +1 -1
  82. package/src/lib/site-import/site-import-css.d.ts +20 -0
  83. package/src/lib/site-import/site-import-css.js +106 -0
  84. package/src/lib/site-import/site-import-css.js.map +1 -1
  85. package/src/lib/site-import/site-import-html.d.ts +39 -0
  86. package/src/lib/site-import/site-import-html.js +515 -5
  87. package/src/lib/site-import/site-import-html.js.map +1 -1
  88. package/src/lib/site-import/site-import-layout.d.ts +16 -6
  89. package/src/lib/site-import/site-import-layout.js +524 -52
  90. package/src/lib/site-import/site-import-layout.js.map +1 -1
  91. package/src/lib/site-import/site-import-nav.js +286 -24
  92. package/src/lib/site-import/site-import-nav.js.map +1 -1
  93. package/src/lib/site-import/site-import-page.js +3 -0
  94. package/src/lib/site-import/site-import-page.js.map +1 -1
  95. package/src/lib/tools/ai-insight-tool.js +45 -2
  96. package/src/lib/tools/ai-insight-tool.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/ai/src/lib/site-import/fixtures/site-import-fidelity-replay.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 * The recorded pages brought in again, offline (AGL-4109), for the fidelity\n * spec and the fidelity report: each page of `site-layout/` read by the\n * reader, built by the import's compile and held to its page check as the\n * page step stores it, and each recorded home page's header and footer drawn\n * as the frame step draws them, with no model. Every page the source links\n * on its own site is a page the import plans, as on a whole-site import. No\n * live AI: a design answer here is a recorded one, in the shape the tool\n * answers.\n */\n\nimport { aiImportedPageCheck } from '../../jobs/ai-job-page-language'\nimport { aiSiteImportFrameJob, aiSiteImportHomeOf } from '../../jobs/ai-job-import-step'\nimport { aiLayoutSiteBrandOf, aiLayoutSiteFrameOf, aiLayoutSourceFrameBuild } from '../../jobs/ai-job-layout-language'\nimport { aiLayoutChecks } from '../../jobs/ai-job-layout-step'\nimport { aiSiteImportSectionNames } from '../../jobs/ai-site-import-compile'\nimport type { AiSiteImportDocument } from '../../jobs/ai-site-import-document'\nimport type { AiLayoutFrameSource } from '../../layout-language/ai-layout-frame-source'\nimport type { AiJob } from '../../model/ai-jobs.types'\nimport { aiSiteImportLedger, type AiSiteImportPage, type AiSiteImportState, type SiteImportFooter, type SiteImportNavTree } from '../../model/ai-site-import'\nimport type { SiteImportFidelitySource, SiteImportFidelityTree } from '../../model/ai-site-import-fidelity'\nimport { emptyAiSiteInventory } from '../../model/ai-site-inventory'\nimport type { SiteImportInventory } from '../site-import-crawl'\nimport { extractSiteImportPage, type SiteImportBlock } from '../site-import-html'\nimport { siteImportLayout, siteImportLookOf } from '../site-import-layout'\nimport { siteImportFooterColumns, siteImportNavTree, type SiteImportFrameSource } from '../site-import-nav'\nimport { siteImportPageRead } from '../site-import-page'\nimport { SITE_LAYOUT_PAGES, siteLayoutRecording, siteLayoutSameSite, type SiteLayoutPageName } from './site-layout-recordings'\n\n/** The page's same-site addresses, each a page the import plans: every page a link may go to. */\nfunction plannedLinks(blocks: readonly SiteImportBlock[], origin: string): Array<{ path: string; id: string }> {\n const paths = new Set<string>()\n for (const block of blocks) {\n if (block.kind !== 'link') continue\n try {\n const url = new URL(block.href)\n const path = url.pathname.replace(/\\/+$/, '') || '/'\n if (url.origin === origin && path !== '/') paths.add(path)\n } catch {\n // Not an address.\n }\n }\n return [...paths].map((path) => ({ path, id: `p${path.replace(/[^a-z0-9]+/gi, '-')}` }))\n}\n\n/** A recorded page as a wave's read keeps it and the import step hands it on: its blocks, its layout, its photos in the library. */\nexport function siteImportReplayDocument(name: SiteLayoutPageName): AiSiteImportDocument {\n const { url } = SITE_LAYOUT_PAGES[name]\n const page = extractSiteImportPage(siteLayoutRecording(name), url, siteLayoutSameSite(name), { structure: true })\n const layout = siteImportLayout(page as Parameters<typeof siteImportLayout>[0])\n const path = new URL(url).pathname\n const read = siteImportPageRead({ ...page, layout, url, path, foundBy: path === '/' ? 'home' : 'sitemap', bytes: 0 } as never, 'now')\n const blocks = read.blocks ?? []\n const origin = new URL(url).origin\n const pictures = [...new Set(blocks.flatMap((block) => (block.kind === 'image' ? [block.url] : [])))]\n return {\n build: 'arranged',\n title: read.title,\n url,\n blocks,\n photos: pictures.map((from, index) => ({ mediaId: `m${index}`, src: `media:host-import/m${index}`, from, width: 1600, height: 900 })),\n links: plannedLinks(blocks, origin),\n origins: [origin, origin.replace('://', '://www.')],\n ...(read.layout ? { layout: read.layout } : {}),\n }\n}\n\n/** A recorded page built as the page step builds it: its source, its stored nodes, and what the page check said. */\nexport interface SiteImportReplayPage {\n doc: AiSiteImportDocument\n source: SiteImportFidelitySource\n tree: SiteImportFidelityTree\n violations: unknown[]\n}\n\n/**\n * A recorded page built and checked as the page step stores it (AGL-4109):\n * with a recorded design `answer`, as a main page is arranged, or with none,\n * as a page is drawn from its layout alone; `forms` are the site's saved\n * forms. `layout: false` builds it as a read with no layout was built, one\n * section at each second-level heading, as the 10/29 import did.\n */\nexport function siteImportReplayPage(\n name: SiteLayoutPageName,\n options: { answer?: Record<string, unknown> | null; forms?: Array<{ id: string; name: string }>; layout?: boolean } = {},\n): SiteImportReplayPage {\n const read = siteImportReplayDocument(name)\n const { layout, ...rest } = read\n const doc: AiSiteImportDocument = options.layout === false ? rest : read\n const names = aiSiteImportSectionNames(doc)\n const sectionIds = names.map((_, index) => `sec-${index}`)\n const screen = { title: doc.title, slug: name === 'home' ? '/' : `/${name}`, sections: names.map((section) => ({ name: section, uses: [] as string[], items: 0 })) }\n const forms = options.forms ?? []\n const targets = { pageId: 'p0', pages: [], homeIds: [], forms, formPageId: null, components: [], facts: '' }\n const check = aiImportedPageCheck({\n screen: screen as never,\n sectionIds,\n targets: targets as never,\n context: { screenIds: doc.links.map((link) => link.id), formIds: forms.map((form) => form.id), componentIds: [], codeBuilt: true },\n design: { kind: 'business', seed: 7, home: name === 'home' } as never,\n doc,\n })\n const result = check(options.answer ?? null)\n const nodes = (result.value?.nodes ?? {}) as unknown as SiteImportFidelityTree['nodes']\n return {\n doc,\n source: { layout: layout as NonNullable<typeof layout>, blocks: read.blocks, photos: read.photos },\n tree: { rootId: '_@_', nodes },\n violations: result.violations,\n }\n}\n\n/**\n * The design answer recorded for aglyn.com's Home, in the tool's shape: a\n * split hero, ruled cards, a dark band asked where the source drew its own\n * white, a style of pictures for a group that has none. The compile spec\n * holds the same one.\n */\nexport const SITE_IMPORT_REPLAY_HOME_ANSWER: Readonly<Record<string, unknown>> = {\n sections: [\n { hero: 'split', band: 'source', align: 'start', groups: [] },\n { hero: 'none', band: 'source', align: 'source', groups: [{ kind: 'source', style: 'ruled' }] },\n { hero: 'none', band: 'dark', align: 'source', groups: [] },\n { hero: 'none', band: 'source', align: 'source', groups: [{ kind: 'source', style: 'pictures' }] },\n ],\n}\n\n/** The recorded home pages a header and footer is drawn from. */\nexport type SiteImportReplayHome = Extract<SiteLayoutPageName, 'home' | 'pottery'>\n\nconst NOW = new Date('2026-10-29T18:00:00.000Z')\n\n/** A recorded home page as the crawl keeps it: its menu, footer and look read as the source builds them. */\nfunction crawledHome(name: SiteImportReplayHome): SiteImportInventory['pages'][number] {\n const { url } = SITE_LAYOUT_PAGES[name]\n const extract = extractSiteImportPage(siteLayoutRecording(name), url, siteLayoutSameSite(name), { structure: true })\n const source = extract as SiteImportFrameSource\n const { structure: _structure, loginForm: _loginForm, ...rest } = extract\n return { ...rest, url, path: '/', foundBy: 'home', bytes: 0, nav: siteImportNavTree(source), footer: siteImportFooterColumns(source), look: siteImportLookOf(source) }\n}\n\n/** A site planned for its first wave: Home, and two pages of its own. */\nfunction replayState(name: SiteImportReplayHome): AiSiteImportState {\n const origin = new URL(SITE_LAYOUT_PAGES[name].url).origin\n const paths = name === 'home' ? ['/', '/product', '/pricing'] : ['/', '/classes', '/gallery']\n const pages: AiSiteImportPage[] = paths.map((path, index) => {\n const slug = path === '/' ? '/' : (path.split('/').filter(Boolean).pop() as string)\n return { slot: `p${index}`, url: `${origin}${path}`, path, title: slug, group: 'main', wave: 1, draftId: `draft${index}`, slug, words: 300, images: 0 }\n })\n return {\n domain: new URL(origin).hostname.replace(/^www\\./, ''),\n siteName: 'import-check',\n ownership: { method: 'dns', provenAt: 1, detail: null },\n readAt: NOW.toISOString(),\n pageLimit: null,\n existingPages: 0,\n found: pages.length,\n stoppedBy: null,\n groups: [],\n pages,\n waves: [{ index: 1, label: 'Wave 1', group: 'main', slots: pages.map((page) => page.slot), frame: true, status: 'running', startedAt: NOW.toISOString(), finishedAt: null }],\n leftOut: [],\n leftOutCount: {},\n frame: { draftId: 'frameDraft' },\n home: aiSiteImportHomeOf({ pages: [crawledHome(name)] }),\n look: {\n at: NOW.toISOString(),\n theme: 'applied',\n colors: [],\n logo: name === 'home' ? { mediaId: 'm1', src: 'media:host-import/m1', width: 632, height: 192 } : null,\n seo: true,\n seed: 7,\n },\n }\n}\n\n/** A recorded home page's header and footer as the frame step draws them: the source's menu and footer, the stored nodes, the check's word. */\nexport interface SiteImportReplayFrame {\n nav: SiteImportNavTree | null\n footer: SiteImportFooter | null\n tree: SiteImportFidelityTree\n violations: unknown[]\n}\n\n/** A recorded home page's header and footer, drawn with no model as the layout step stores them (AGL-4108). */\nexport function siteImportReplayFrame(name: SiteImportReplayHome): SiteImportReplayFrame {\n const state = replayState(name)\n const job = {\n $id: 'importJob',\n orgId: 'org-replay',\n hostId: 'host-replay',\n kind: 'import',\n status: 'running',\n brief: `Bring in ${state.domain}`,\n inputs: { domain: state.domain },\n steps: [],\n outputs: [],\n createdBy: 'uid-replay',\n createdAt: NOW,\n updatedAt: NOW,\n expiresAt: NOW,\n } as unknown as AiJob\n const frameJob = aiSiteImportFrameJob(job, state, state.waves[0] as AiSiteImportState['waves'][number], aiSiteImportLedger(state))\n const home = state.pages[0] as AiSiteImportPage\n const built = aiLayoutSourceFrameBuild({\n siteName: String(frameJob.inputs?.['businessName']),\n homeId: home.draftId,\n pages: [{ id: home.draftId, label: 'Home', slug: '/' }],\n targets: { pageId: null, pages: [], homeIds: [home.draftId], forms: [], formPageId: null, components: [], facts: '' } as never,\n extend: aiLayoutChecks(emptyAiSiteInventory('host-replay'), frameJob.plan ?? null, [frameJob.brief, ...(state.home?.facts.lines ?? [])].join('\\n')),\n brand: aiLayoutSiteBrandOf(frameJob.inputs),\n source: aiLayoutSiteFrameOf(frameJob.inputs) as AiLayoutFrameSource,\n })\n const nodes = (built.value?.nodes ?? {}) as unknown as SiteImportFidelityTree['nodes']\n return { nav: state.home?.nav ?? null, footer: state.home?.footer ?? null, tree: { rootId: '_@_', nodes }, violations: built.violations }\n}\n"],"names":["aiImportedPageCheck","aiSiteImportFrameJob","aiSiteImportHomeOf","aiLayoutSiteBrandOf","aiLayoutSiteFrameOf","aiLayoutSourceFrameBuild","aiLayoutChecks","aiSiteImportSectionNames","aiSiteImportLedger","emptyAiSiteInventory","extractSiteImportPage","siteImportLayout","siteImportLookOf","siteImportFooterColumns","siteImportNavTree","siteImportPageRead","SITE_LAYOUT_PAGES","siteLayoutRecording","siteLayoutSameSite","plannedLinks","blocks","origin","paths","Set","block","kind","url","URL","href","path","pathname","replace","add","map","id","siteImportReplayDocument","name","read","page","structure","layout","foundBy","bytes","pictures","flatMap","build","title","photos","from","index","mediaId","src","width","height","links","origins","siteImportReplayPage","options","result","rest","doc","names","sectionIds","_","screen","slug","sections","section","uses","items","forms","targets","pageId","pages","homeIds","formPageId","components","facts","check","context","screenIds","link","formIds","form","componentIds","codeBuilt","design","seed","home","answer","nodes","value","source","tree","rootId","violations","SITE_IMPORT_REPLAY_HOME_ANSWER","hero","band","align","groups","style","NOW","Date","crawledHome","extract","_structure","loginForm","_loginForm","nav","footer","look","replayState","split","filter","Boolean","pop","slot","group","wave","draftId","words","images","domain","hostname","siteName","ownership","method","provenAt","detail","readAt","toISOString","pageLimit","existingPages","found","length","stoppedBy","waves","label","slots","frame","status","startedAt","finishedAt","leftOut","leftOutCount","at","theme","colors","logo","seo","siteImportReplayFrame","frameJob","state","built","job","$id","orgId","hostId","brief","inputs","steps","outputs","createdBy","createdAt","updatedAt","expiresAt","String","homeId","extend","plan","lines","join","brand"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GAED,SAASA,mBAAmB,QAAQ,qCAAiC;AACrE,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,mCAA+B;AACxF,SAASC,mBAAmB,EAAEC,mBAAmB,EAAEC,wBAAwB,QAAQ,uCAAmC;AACtH,SAASC,cAAc,QAAQ,mCAA+B;AAC9D,SAASC,wBAAwB,QAAQ,uCAAmC;AAI5E,SAASC,kBAAkB,QAAsG,gCAA4B;AAE7J,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YAAY2D,MAAM3D,UAAU;IAAC;AAC1I"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/ai/src/lib/site-import/fixtures/site-import-fidelity-replay.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 * The recorded pages brought in again, offline (AGL-4109), for the fidelity\n * spec and the fidelity report: each page of `site-layout/` read by the\n * reader, built by the import's compile and held to its page check as the\n * page step stores it, and each recorded home page's header and footer drawn\n * as the frame step draws them, with no model. Every page the source links\n * on its own site is a page the import plans, as on a whole-site import. No\n * live AI: a design answer here is a recorded one, in the shape the tool\n * answers.\n */\n\nimport { aiImportedPageCheck } from '../../jobs/ai-job-page-language'\nimport { aiSiteImportFrameJob, aiSiteImportHomeOf } from '../../jobs/ai-job-import-step'\nimport { aiLayoutSiteBrandOf, aiLayoutSiteFrameOf, aiLayoutSourceFrameBuild } from '../../jobs/ai-job-layout-language'\nimport { aiLayoutChecks } from '../../jobs/ai-job-layout-step'\nimport { aiSiteImportSectionNames } from '../../jobs/ai-site-import-compile'\nimport type { AiSiteImportDocument } from '../../jobs/ai-site-import-document'\nimport type { AiLayoutFrameSource } from '../../layout-language/ai-layout-frame-source'\nimport type { AiJob } from '../../model/ai-jobs.types'\nimport { aiSiteImportLedger, type AiSiteImportPage, type AiSiteImportState, type SiteImportFooter, type SiteImportNavTree } from '../../model/ai-site-import'\nimport type { SiteImportFidelitySource, SiteImportFidelityTree } from '../../model/ai-site-import-fidelity'\nimport { emptyAiSiteInventory } from '../../model/ai-site-inventory'\nimport type { SiteImportInventory } from '../site-import-crawl'\nimport { extractSiteImportPage, type SiteImportBlock } from '../site-import-html'\nimport { siteImportLayout, siteImportLookOf } from '../site-import-layout'\nimport { siteImportFooterColumns, siteImportNavTree, type SiteImportFrameSource } from '../site-import-nav'\nimport { siteImportPageRead } from '../site-import-page'\nimport { SITE_LAYOUT_PAGES, siteLayoutRecording, siteLayoutSameSite, type SiteLayoutPageName } from './site-layout-recordings'\n\n/** The page's same-site addresses, each a page the import plans: every page a link may go to. */\nfunction plannedLinks(blocks: readonly SiteImportBlock[], origin: string): Array<{ path: string; id: string }> {\n const paths = new Set<string>()\n for (const block of blocks) {\n if (block.kind !== 'link') continue\n try {\n const url = new URL(block.href)\n const path = url.pathname.replace(/\\/+$/, '') || '/'\n if (url.origin === origin && path !== '/') paths.add(path)\n } catch {\n // Not an address.\n }\n }\n return [...paths].map((path) => ({ path, id: `p${path.replace(/[^a-z0-9]+/gi, '-')}` }))\n}\n\n/** A recorded page as a wave's read keeps it and the import step hands it on: its blocks, its layout, its photos in the library. */\nexport function siteImportReplayDocument(name: SiteLayoutPageName): AiSiteImportDocument {\n const { url } = SITE_LAYOUT_PAGES[name]\n const page = extractSiteImportPage(siteLayoutRecording(name), url, siteLayoutSameSite(name), { structure: true })\n const layout = siteImportLayout(page as Parameters<typeof siteImportLayout>[0])\n const path = new URL(url).pathname\n const read = siteImportPageRead({ ...page, layout, url, path, foundBy: path === '/' ? 'home' : 'sitemap', bytes: 0 } as never, 'now')\n const blocks = read.blocks ?? []\n const origin = new URL(url).origin\n const pictures = [...new Set(blocks.flatMap((block) => (block.kind === 'image' ? [block.url] : [])))]\n return {\n build: 'arranged',\n title: read.title,\n url,\n blocks,\n photos: pictures.map((from, index) => ({ mediaId: `m${index}`, src: `media:host-import/m${index}`, from, width: 1600, height: 900 })),\n links: plannedLinks(blocks, origin),\n origins: [origin, origin.replace('://', '://www.')],\n ...(read.layout ? { layout: read.layout } : {}),\n ...(read.videos?.length ? { videos: read.videos } : {}),\n }\n}\n\n/** A recorded page built as the page step builds it: its source, its stored nodes, and what the page check said. */\nexport interface SiteImportReplayPage {\n doc: AiSiteImportDocument\n source: SiteImportFidelitySource\n tree: SiteImportFidelityTree\n violations: unknown[]\n}\n\n/**\n * A recorded page built and checked as the page step stores it (AGL-4109):\n * with a recorded design `answer`, as a main page is arranged, or with none,\n * as a page is drawn from its layout alone; `forms` are the site's saved\n * forms. `layout: false` builds it as a read with no layout was built, one\n * section at each second-level heading, as the 10/29 import did.\n */\nexport function siteImportReplayPage(\n name: SiteLayoutPageName,\n options: { answer?: Record<string, unknown> | null; forms?: Array<{ id: string; name: string }>; layout?: boolean } = {},\n): SiteImportReplayPage {\n const read = siteImportReplayDocument(name)\n const { layout, ...rest } = read\n const doc: AiSiteImportDocument = options.layout === false ? rest : read\n const names = aiSiteImportSectionNames(doc)\n const sectionIds = names.map((_, index) => `sec-${index}`)\n const screen = { title: doc.title, slug: name === 'home' ? '/' : `/${name}`, sections: names.map((section) => ({ name: section, uses: [] as string[], items: 0 })) }\n const forms = options.forms ?? []\n const targets = { pageId: 'p0', pages: [], homeIds: [], forms, formPageId: null, components: [], facts: '' }\n const check = aiImportedPageCheck({\n screen: screen as never,\n sectionIds,\n targets: targets as never,\n context: { screenIds: doc.links.map((link) => link.id), formIds: forms.map((form) => form.id), componentIds: [], codeBuilt: true },\n design: { kind: 'business', seed: 7, home: name === 'home' } as never,\n doc,\n })\n const result = check(options.answer ?? null)\n const nodes = (result.value?.nodes ?? {}) as unknown as SiteImportFidelityTree['nodes']\n return {\n doc,\n source: { layout: layout as NonNullable<typeof layout>, blocks: read.blocks, photos: read.photos },\n tree: { rootId: '_@_', nodes },\n violations: result.violations,\n }\n}\n\n/**\n * The design answer recorded for aglyn.com's Home, in the tool's shape: a\n * split hero, ruled cards, a dark band asked where the source drew its own\n * white, a style of pictures for a group that has none. The compile spec\n * holds the same one.\n */\nexport const SITE_IMPORT_REPLAY_HOME_ANSWER: Readonly<Record<string, unknown>> = {\n sections: [\n { hero: 'split', band: 'source', align: 'start', groups: [] },\n { hero: 'none', band: 'source', align: 'source', groups: [{ kind: 'source', style: 'ruled' }] },\n { hero: 'none', band: 'dark', align: 'source', groups: [] },\n { hero: 'none', band: 'source', align: 'source', groups: [{ kind: 'source', style: 'pictures' }] },\n ],\n}\n\n/** The recorded home pages a header and footer is drawn from. */\nexport type SiteImportReplayHome = Extract<SiteLayoutPageName, 'home' | 'pottery'>\n\nconst NOW = new Date('2026-10-29T18:00:00.000Z')\n\n/** A recorded home page as the crawl keeps it: its menu, footer and look read as the source builds them. */\nfunction crawledHome(name: SiteImportReplayHome): SiteImportInventory['pages'][number] {\n const { url } = SITE_LAYOUT_PAGES[name]\n const extract = extractSiteImportPage(siteLayoutRecording(name), url, siteLayoutSameSite(name), { structure: true })\n const source = extract as SiteImportFrameSource\n const { structure: _structure, loginForm: _loginForm, ...rest } = extract\n return { ...rest, url, path: '/', foundBy: 'home', bytes: 0, nav: siteImportNavTree(source), footer: siteImportFooterColumns(source), look: siteImportLookOf(source) }\n}\n\n/** A site planned for its first wave: Home, and two pages of its own. */\nfunction replayState(name: SiteImportReplayHome): AiSiteImportState {\n const origin = new URL(SITE_LAYOUT_PAGES[name].url).origin\n const paths = name === 'home' ? ['/', '/product', '/pricing'] : ['/', '/classes', '/gallery']\n const home = aiSiteImportHomeOf({ pages: [crawledHome(name)] })\n const pages: AiSiteImportPage[] = paths.map((path, index) => {\n const slug = path === '/' ? '/' : (path.split('/').filter(Boolean).pop() as string)\n return { slot: `p${index}`, url: `${origin}${path}`, path, title: slug, group: 'main', wave: 1, draftId: `draft${index}`, slug, words: 300, images: 0 }\n })\n return {\n domain: new URL(origin).hostname.replace(/^www\\./, ''),\n siteName: 'import-check',\n ownership: { method: 'dns', provenAt: 1, detail: null },\n readAt: NOW.toISOString(),\n pageLimit: null,\n existingPages: 0,\n found: pages.length,\n stoppedBy: null,\n groups: [],\n pages,\n waves: [{ index: 1, label: 'Wave 1', group: 'main', slots: pages.map((page) => page.slot), frame: true, status: 'running', startedAt: NOW.toISOString(), finishedAt: null }],\n leftOut: [],\n leftOutCount: {},\n frame: { draftId: 'frameDraft' },\n home,\n look: {\n at: NOW.toISOString(),\n theme: 'applied',\n colors: [],\n logo: name === 'home' ? { mediaId: 'm1', src: 'media:host-import/m1', width: 632, height: 192 } : null,\n // The menus' pictures, in the library as the look pass brings them in (AGL-4139).\n pictures: siteImportMenuPictures(home).map((from, index) => ({ mediaId: `mp${index}`, src: `media:host-import/mp${index}`, from, width: 1200, height: 750 })),\n seo: true,\n seed: 7,\n },\n }\n}\n\n/** The pictures a home page's menus show, each once: what the look pass brings in. */\nfunction siteImportMenuPictures(home: AiSiteImportState['home']): string[] {\n const urls = (home?.nav?.items ?? []).flatMap((group) => (group.columns ?? []).flatMap((column) => (column.image ? [column.image.url] : [])))\n return [...new Set(urls)]\n}\n\n/** A recorded home page's header and footer as the frame step draws them: the source's menu and footer, the stored nodes, the check's word. */\nexport interface SiteImportReplayFrame {\n nav: SiteImportNavTree | null\n footer: SiteImportFooter | null\n tree: SiteImportFidelityTree\n violations: unknown[]\n}\n\n/** A recorded home page's header and footer, drawn with no model as the layout step stores them (AGL-4108). */\nexport function siteImportReplayFrame(name: SiteImportReplayHome): SiteImportReplayFrame {\n const state = replayState(name)\n const job = {\n $id: 'importJob',\n orgId: 'org-replay',\n hostId: 'host-replay',\n kind: 'import',\n status: 'running',\n brief: `Bring in ${state.domain}`,\n inputs: { domain: state.domain },\n steps: [],\n outputs: [],\n createdBy: 'uid-replay',\n createdAt: NOW,\n updatedAt: NOW,\n expiresAt: NOW,\n } as unknown as AiJob\n const frameJob = aiSiteImportFrameJob(job, state, state.waves[0] as AiSiteImportState['waves'][number], aiSiteImportLedger(state))\n const home = state.pages[0] as AiSiteImportPage\n const built = aiLayoutSourceFrameBuild({\n siteName: String(frameJob.inputs?.['businessName']),\n homeId: home.draftId,\n pages: [{ id: home.draftId, label: 'Home', slug: '/' }],\n targets: { pageId: null, pages: [], homeIds: [home.draftId], forms: [], formPageId: null, components: [], facts: '' } as never,\n extend: aiLayoutChecks(emptyAiSiteInventory('host-replay'), frameJob.plan ?? null, [frameJob.brief, ...(state.home?.facts.lines ?? [])].join('\\n')),\n brand: aiLayoutSiteBrandOf(frameJob.inputs),\n source: aiLayoutSiteFrameOf(frameJob.inputs) as AiLayoutFrameSource,\n })\n const nodes = (built.value?.nodes ?? {}) as unknown as SiteImportFidelityTree['nodes']\n return { nav: state.home?.nav ?? null, footer: state.home?.footer ?? null, tree: { rootId: '_@_', nodes }, violations: built.violations }\n}\n"],"names":["aiImportedPageCheck","aiSiteImportFrameJob","aiSiteImportHomeOf","aiLayoutSiteBrandOf","aiLayoutSiteFrameOf","aiLayoutSourceFrameBuild","aiLayoutChecks","aiSiteImportSectionNames","aiSiteImportLedger","emptyAiSiteInventory","extractSiteImportPage","siteImportLayout","siteImportLookOf","siteImportFooterColumns","siteImportNavTree","siteImportPageRead","SITE_LAYOUT_PAGES","siteLayoutRecording","siteLayoutSameSite","plannedLinks","blocks","origin","paths","Set","block","kind","url","URL","href","path","pathname","replace","add","map","id","siteImportReplayDocument","name","read","page","structure","layout","foundBy","bytes","pictures","flatMap","build","title","photos","from","index","mediaId","src","width","height","links","origins","videos","length","siteImportReplayPage","options","result","rest","doc","names","sectionIds","_","screen","slug","sections","section","uses","items","forms","targets","pageId","pages","homeIds","formPageId","components","facts","check","context","screenIds","link","formIds","form","componentIds","codeBuilt","design","seed","home","answer","nodes","value","source","tree","rootId","violations","SITE_IMPORT_REPLAY_HOME_ANSWER","hero","band","align","groups","style","NOW","Date","crawledHome","extract","_structure","loginForm","_loginForm","nav","footer","look","replayState","split","filter","Boolean","pop","slot","group","wave","draftId","words","images","domain","hostname","siteName","ownership","method","provenAt","detail","readAt","toISOString","pageLimit","existingPages","found","stoppedBy","waves","label","slots","frame","status","startedAt","finishedAt","leftOut","leftOutCount","at","theme","colors","logo","siteImportMenuPictures","seo","urls","columns","column","image","siteImportReplayFrame","frameJob","state","built","job","$id","orgId","hostId","brief","inputs","steps","outputs","createdBy","createdAt","updatedAt","expiresAt","String","homeId","extend","plan","lines","join","brand"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;CASC,GAED,SAASA,mBAAmB,QAAQ,qCAAiC;AACrE,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,mCAA+B;AACxF,SAASC,mBAAmB,EAAEC,mBAAmB,EAAEC,wBAAwB,QAAQ,uCAAmC;AACtH,SAASC,cAAc,QAAQ,mCAA+B;AAC9D,SAASC,wBAAwB,QAAQ,uCAAmC;AAI5E,SAASC,kBAAkB,QAAsG,gCAA4B;AAE7J,SAASC,oBAAoB,QAAQ,mCAA+B;AAEpE,SAASC,qBAAqB,QAA8B,yBAAqB;AACjF,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,2BAAuB;AAC1E,SAASC,uBAAuB,EAAEC,iBAAiB,QAAoC,wBAAoB;AAC3G,SAASC,kBAAkB,QAAQ,yBAAqB;AACxD,SAASC,iBAAiB,EAAEC,mBAAmB,EAAEC,kBAAkB,QAAiC,8BAA0B;AAE9H,+FAA+F,GAC/F,SAASC,aAAaC,MAAkC,EAAEC,MAAc;IACtE,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,SAASJ,OAAQ;QAC1B,IAAII,MAAMC,IAAI,KAAK,QAAQ;QAC3B,IAAI;YACF,MAAMC,MAAM,IAAIC,IAAIH,MAAMI,IAAI;YAC9B,MAAMC,OAAOH,IAAII,QAAQ,CAACC,OAAO,CAAC,QAAQ,OAAO;YACjD,IAAIL,IAAIL,MAAM,KAAKA,UAAUQ,SAAS,KAAKP,MAAMU,GAAG,CAACH;QACvD,EAAE,eAAM;QACN,kBAAkB;QACpB;IACF;IACA,OAAO;WAAIP;KAAM,CAACW,GAAG,CAAC,CAACJ,OAAU,CAAA;YAAEA;YAAMK,IAAI,CAAC,CAAC,EAAEL,KAAKE,OAAO,CAAC,gBAAgB,MAAM;QAAC,CAAA;AACvF;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
17
  export declare const SITE_LAYOUT_AGLYN_ORIGIN = "https://aglyn.com";
18
18
  export declare const SITE_LAYOUT_POTTERY_ORIGIN = "https://www.tidewater-pottery.example";
19
+ export declare const SITE_LAYOUT_BAKERY_ORIGIN = "https://www.hearth-bakery.example";
19
20
  /** The recorded pages, by name: the file and the address it was read from. */
20
21
  export declare const SITE_LAYOUT_PAGES: {
21
22
  readonly home: {
@@ -42,10 +43,18 @@ export declare const SITE_LAYOUT_PAGES: {
42
43
  readonly file: "aglyn-blog-post.html";
43
44
  readonly url: "https://aglyn.com/blog/multi-site-cost-sheet-2026";
44
45
  };
46
+ readonly blog: {
47
+ readonly file: "aglyn-blog.html";
48
+ readonly url: "https://aglyn.com/blog";
49
+ };
45
50
  readonly pottery: {
46
51
  readonly file: "squarespace-pottery.html";
47
52
  readonly url: "https://www.tidewater-pottery.example/";
48
53
  };
54
+ readonly bakery: {
55
+ readonly file: "video-bakery.html";
56
+ readonly url: "https://www.hearth-bakery.example/";
57
+ };
49
58
  };
50
59
  export type SiteLayoutPageName = keyof typeof SITE_LAYOUT_PAGES;
51
60
  /** One recorded page's markup. */
@@ -21,9 +21,16 @@
21
21
  * `site-layout/` holds five pages of aglyn.com as AglynBot read them on
22
22
  * 2026-10-28 and 2026-10-29 (home, product, pricing, contact, one blog post),
23
23
  * its pricing page again as it read on 2026-11-01, which a live import fell
24
- * short on (`livePricing`), and one page in the markup a Squarespace site is
25
- * built with, written for these specs about a studio that does not exist, so
26
- * the readers are never tuned to one site's markup.
24
+ * short on (`livePricing`), its blog listing as it read on 2026-11-03, whose
25
+ * cards crop their pictures to a height of their own (`blog`, AGL-4138), and
26
+ * one page in the markup a Squarespace site is built with, written for these
27
+ * specs about a studio that does not exist, so the readers are never tuned to
28
+ * one site's markup.
29
+ * A bakery that does not exist either, in the markup a WordPress block theme
30
+ * writes, shows a film of every kind the reader reads (AGL-4140): a
31
+ * `<video>` playing behind its opening, a YouTube frame, a `lite-youtube`
32
+ * facade, a card's picture linking a Vimeo page, and an `og:video` in its
33
+ * head.
27
34
  *
28
35
  * The aglyn.com recordings keep what the `aglyn-com/` ones dropped and the
29
36
  * layout is made of: class names, inline icons and the page's own stylesheet.
@@ -35,13 +42,17 @@
35
42
  * are dropped, a grid framework's own hints kept; the pricing page keeps the
36
43
  * first 14 rows of its plan table, and the product, pricing, contact and blog
37
44
  * pages their header menu without its panels and their footer's © line. The
38
- * home page keeps its header and footer whole, for the menu reader. Every
39
- * address, phone number, author and profile is a placeholder.
45
+ * blog listing keeps its first page of posts, a featured one and six cards,
46
+ * without its search box and its newsletter band, inside the blog post's
47
+ * header and footer. The home page keeps its header and footer whole, for
48
+ * the menu reader. Every address, phone number, author and profile is a
49
+ * placeholder.
40
50
  */ import { readFileSync } from "node:fs";
41
51
  import { join } from "node:path";
42
52
  const DIR = join(__dirname, 'site-layout');
43
53
  export const SITE_LAYOUT_AGLYN_ORIGIN = 'https://aglyn.com';
44
54
  export const SITE_LAYOUT_POTTERY_ORIGIN = 'https://www.tidewater-pottery.example';
55
+ export const SITE_LAYOUT_BAKERY_ORIGIN = 'https://www.hearth-bakery.example';
45
56
  /** The recorded pages, by name: the file and the address it was read from. */ export const SITE_LAYOUT_PAGES = {
46
57
  home: {
47
58
  file: 'aglyn-home.html',
@@ -67,9 +78,17 @@ export const SITE_LAYOUT_POTTERY_ORIGIN = 'https://www.tidewater-pottery.example
67
78
  file: 'aglyn-blog-post.html',
68
79
  url: `${SITE_LAYOUT_AGLYN_ORIGIN}/blog/multi-site-cost-sheet-2026`
69
80
  },
81
+ blog: {
82
+ file: 'aglyn-blog.html',
83
+ url: `${SITE_LAYOUT_AGLYN_ORIGIN}/blog`
84
+ },
70
85
  pottery: {
71
86
  file: 'squarespace-pottery.html',
72
87
  url: `${SITE_LAYOUT_POTTERY_ORIGIN}/`
88
+ },
89
+ bakery: {
90
+ file: 'video-bakery.html',
91
+ url: `${SITE_LAYOUT_BAKERY_ORIGIN}/`
73
92
  }
74
93
  };
75
94
  const cache = new Map();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/ai/src/lib/site-import/fixtures/site-layout-recordings.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 * Pages recorded with their layout (AGL-4106), for the specs of the layout,\n * menu and stylesheet readers, and for the compile and fidelity specs that\n * read what they find.\n *\n * `site-layout/` holds five pages of aglyn.com as AglynBot read them on\n * 2026-10-28 and 2026-10-29 (home, product, pricing, contact, one blog post),\n * its pricing page again as it read on 2026-11-01, which a live import fell\n * short on (`livePricing`), and one page in the markup a Squarespace site is\n * built with, written for these specs about a studio that does not exist, so\n * the readers are never tuned to one site's markup.\n *\n * The aglyn.com recordings keep what the `aglyn-com/` ones dropped and the\n * layout is made of: class names, inline icons and the page's own stylesheet.\n * Each was trimmed before it entered the repo: script bodies are gone (one\n * small inline script with a hostile line stands in for them; the\n * structured data stays), so are preload links, `data-*` attributes and\n * `srcset`s; the stylesheet keeps only the rules for classes the page uses\n * and the properties the readers read; class names the kept rules do not name\n * are dropped, a grid framework's own hints kept; the pricing page keeps the\n * first 14 rows of its plan table, and the product, pricing, contact and blog\n * pages their header menu without its panels and their footer's © line. The\n * home page keeps its header and footer whole, for the menu reader. Every\n * address, phone number, author and profile is a placeholder.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\nconst DIR = join(__dirname, 'site-layout')\n\nexport const SITE_LAYOUT_AGLYN_ORIGIN = 'https://aglyn.com'\nexport const SITE_LAYOUT_POTTERY_ORIGIN = 'https://www.tidewater-pottery.example'\n\n/** The recorded pages, by name: the file and the address it was read from. */\nexport const SITE_LAYOUT_PAGES = {\n home: { file: 'aglyn-home.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/` },\n product: { file: 'aglyn-product.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/product` },\n pricing: { file: 'aglyn-pricing.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/pricing` },\n livePricing: { file: 'aglyn-pricing-2026-11.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/pricing` },\n contact: { file: 'aglyn-contact.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/contact` },\n post: { file: 'aglyn-blog-post.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/blog/multi-site-cost-sheet-2026` },\n pottery: { file: 'squarespace-pottery.html', url: `${SITE_LAYOUT_POTTERY_ORIGIN}/` },\n} as const\n\nexport type SiteLayoutPageName = keyof typeof SITE_LAYOUT_PAGES\n\nconst cache = new Map<string, string>()\n\n/** One recorded page's markup. */\nexport function siteLayoutRecording(name: SiteLayoutPageName): string {\n const { file } = SITE_LAYOUT_PAGES[name]\n const held = cache.get(file)\n if (held !== undefined) return held\n const text = readFileSync(join(DIR, file), 'utf8')\n cache.set(file, text)\n return text\n}\n\n/** Whether an address is on the recorded page's own site. */\nexport function siteLayoutSameSite(name: SiteLayoutPageName): (url: URL) => boolean {\n const origin = new URL(SITE_LAYOUT_PAGES[name].url).origin\n const bare = origin.replace('://www.', '://')\n const www = origin.replace('://', '://www.').replace('://www.www.', '://www.')\n return (url) => url.origin === origin || url.origin === bare || url.origin === www\n}\n"],"names":["readFileSync","join","DIR","__dirname","SITE_LAYOUT_AGLYN_ORIGIN","SITE_LAYOUT_POTTERY_ORIGIN","SITE_LAYOUT_PAGES","home","file","url","product","pricing","livePricing","contact","post","pottery","cache","Map","siteLayoutRecording","name","held","get","undefined","text","set","siteLayoutSameSite","origin","URL","bare","replace","www"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED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G,EAAEiB,MAAM;IAC1D,MAAME,OAAOF,OAAOG,OAAO,CAAC,WAAW;IACvC,MAAMC,MAAMJ,OAAOG,OAAO,CAAC,OAAO,WAAWA,OAAO,CAAC,eAAe;IACpE,OAAO,CAACpB,MAAQA,IAAIiB,MAAM,KAAKA,UAAUjB,IAAIiB,MAAM,KAAKE,QAAQnB,IAAIiB,MAAM,KAAKI;AACjF"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/ai/src/lib/site-import/fixtures/site-layout-recordings.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 * Pages recorded with their layout (AGL-4106), for the specs of the layout,\n * menu and stylesheet readers, and for the compile and fidelity specs that\n * read what they find.\n *\n * `site-layout/` holds five pages of aglyn.com as AglynBot read them on\n * 2026-10-28 and 2026-10-29 (home, product, pricing, contact, one blog post),\n * its pricing page again as it read on 2026-11-01, which a live import fell\n * short on (`livePricing`), its blog listing as it read on 2026-11-03, whose\n * cards crop their pictures to a height of their own (`blog`, AGL-4138), and\n * one page in the markup a Squarespace site is built with, written for these\n * specs about a studio that does not exist, so the readers are never tuned to\n * one site's markup.\n * A bakery that does not exist either, in the markup a WordPress block theme\n * writes, shows a film of every kind the reader reads (AGL-4140): a\n * `<video>` playing behind its opening, a YouTube frame, a `lite-youtube`\n * facade, a card's picture linking a Vimeo page, and an `og:video` in its\n * head.\n *\n * The aglyn.com recordings keep what the `aglyn-com/` ones dropped and the\n * layout is made of: class names, inline icons and the page's own stylesheet.\n * Each was trimmed before it entered the repo: script bodies are gone (one\n * small inline script with a hostile line stands in for them; the\n * structured data stays), so are preload links, `data-*` attributes and\n * `srcset`s; the stylesheet keeps only the rules for classes the page uses\n * and the properties the readers read; class names the kept rules do not name\n * are dropped, a grid framework's own hints kept; the pricing page keeps the\n * first 14 rows of its plan table, and the product, pricing, contact and blog\n * pages their header menu without its panels and their footer's © line. The\n * blog listing keeps its first page of posts, a featured one and six cards,\n * without its search box and its newsletter band, inside the blog post's\n * header and footer. The home page keeps its header and footer whole, for\n * the menu reader. Every address, phone number, author and profile is a\n * placeholder.\n */\n\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\nconst DIR = join(__dirname, 'site-layout')\n\nexport const SITE_LAYOUT_AGLYN_ORIGIN = 'https://aglyn.com'\nexport const SITE_LAYOUT_POTTERY_ORIGIN = 'https://www.tidewater-pottery.example'\nexport const SITE_LAYOUT_BAKERY_ORIGIN = 'https://www.hearth-bakery.example'\n\n/** The recorded pages, by name: the file and the address it was read from. */\nexport const SITE_LAYOUT_PAGES = {\n home: { file: 'aglyn-home.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/` },\n product: { file: 'aglyn-product.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/product` },\n pricing: { file: 'aglyn-pricing.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/pricing` },\n livePricing: { file: 'aglyn-pricing-2026-11.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/pricing` },\n contact: { file: 'aglyn-contact.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/contact` },\n post: { file: 'aglyn-blog-post.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/blog/multi-site-cost-sheet-2026` },\n blog: { file: 'aglyn-blog.html', url: `${SITE_LAYOUT_AGLYN_ORIGIN}/blog` },\n pottery: { file: 'squarespace-pottery.html', url: `${SITE_LAYOUT_POTTERY_ORIGIN}/` },\n bakery: { file: 'video-bakery.html', url: `${SITE_LAYOUT_BAKERY_ORIGIN}/` },\n} as const\n\nexport type SiteLayoutPageName = keyof typeof SITE_LAYOUT_PAGES\n\nconst cache = new Map<string, string>()\n\n/** One recorded page's markup. */\nexport function siteLayoutRecording(name: SiteLayoutPageName): string {\n const { file } = SITE_LAYOUT_PAGES[name]\n const held = cache.get(file)\n if (held !== undefined) return held\n const text = readFileSync(join(DIR, file), 'utf8')\n cache.set(file, text)\n return text\n}\n\n/** Whether an address is on the recorded page's own site. */\nexport function siteLayoutSameSite(name: SiteLayoutPageName): (url: URL) => boolean {\n const origin = new URL(SITE_LAYOUT_PAGES[name].url).origin\n const bare = origin.replace('://www.', '://')\n const www = origin.replace('://', '://www.').replace('://www.www.', '://www.')\n return (url) => url.origin === origin || url.origin === bare || url.origin === www\n}\n"],"names":["readFileSync","join","DIR","__dirname","SITE_LAYOUT_AGLYN_ORIGIN","SITE_LAYOUT_POTTERY_ORIGIN","SITE_LAYOUT_BAKERY_ORIGIN","SITE_LAYOUT_PAGES","home","file","url","product","pricing","livePricing","contact","post","blog","pottery","bakery","cache","Map","siteLayoutRecording","name","held","get","undefined","text","set","siteLayoutSameSite","origin","URL","bare","replace","www"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCC,GAED,SAASA,YAAY,QAAQ,UAAS;AACtC,SAASC,IAAI,QAAQ,YAAW;AAEhC,MAAMC,MAAMD,KAAKE,WAAW;AAE5B,OAAO,MAAMC,2BAA2B,oBAAmB;AAC3D,OAAO,MAAMC,6BAA6B,wCAAuC;AACjF,OAAO,MAAMC,4BAA4B,oCAAmC;AAE5E,4EAA4E,GAC5E,OAAO,MAAMC,oBAAoB;IAC/BC,MAAM;QAAEC,MAAM;QAAmBC,KAAK,GAAGN,yBAAyB,CAAC,CAAC;IAAC;IACrEO,SAAS;QAAEF,MAAM;QAAsBC,KAAK,GAAGN,yBAAyB,QAAQ,CAAC;IAAC;IAClFQ,SAAS;QAAEH,MAAM;QAAsBC,KAAK,GAAGN,yBAAyB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, type PublicFetchResult } from '../jobs/ai-theme-brand-inputs';
18
18
  import type { SiteImportFooter, SiteImportLayout, SiteImportLookFacts, SiteImportNavTree } from '../model/ai-site-import';
19
- import { type SiteImportBlock, type SiteImportBrandMark, type SiteImportForm, type SiteImportIcon, type SiteImportImage, type SiteImportNavLink, type SiteImportOrganization } from './site-import-html';
19
+ import { type SiteImportBlock, type SiteImportBrandMark, type SiteImportForm, type SiteImportVideo, type SiteImportIcon, type SiteImportImage, type SiteImportNavLink, type SiteImportOrganization } from './site-import-html';
20
20
  /**
21
21
  * Where the bot's user agent points a site owner who wants to know what it is
22
22
  * (AGL-3983): the operator's own page about it. `SITE_IMPORT_BOT_INFO_URL` on
@@ -105,6 +105,8 @@ export interface SiteImportPage {
105
105
  kept: SiteImportForm[];
106
106
  removed: number;
107
107
  };
108
+ /** Its videos (AGL-4140), each once; absent on a page with none. */
109
+ videos?: SiteImportVideo[];
108
110
  bytes: number;
109
111
  /** How the source lays the page out (AGL-4106), on a read asked for it (`layout`): a wave's. */
110
112
  layout?: SiteImportLayout | null;
@@ -446,11 +446,13 @@ function skipReasonFor(result) {
446
446
  if (extract.structure) {
447
447
  const linked = await Promise.all(extract.structure.stylesheets.filter((url)=>!/fonts\.googleapis\.com/i.test(url)).slice(0, AI_THEME_REFERENCE_STYLESHEETS).map(stylesheet));
448
448
  const css = linked.filter((text)=>typeof text === 'string');
449
- const source = {
449
+ const source = _extends({
450
450
  blocks: extract.blocks,
451
451
  organization: extract.organization,
452
452
  structure: extract.structure
453
- };
453
+ }, extract.videos ? {
454
+ videos: extract.videos
455
+ } : {});
454
456
  try {
455
457
  built = _extends({}, readLayout ? {
456
458
  layout: siteImportLayout(source, css)
@@ -486,7 +488,10 @@ function skipReasonFor(result) {
486
488
  links: [
487
489
  ...new Set(links.map(canon))
488
490
  ],
489
- forms: extract.forms,
491
+ forms: extract.forms
492
+ }, extract.videos ? {
493
+ videos: extract.videos
494
+ } : {}, {
490
495
  bytes: page.bytes
491
496
  }));
492
497
  return null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/site-import/site-import-crawl.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 * THE SITE-IMPORT CRAWLER (AGL-3974, parent AGL-3973).\n *\n * Reads a website a workspace has PROVED it owns (domain-ownership.ts in\n * tenant-data-admin; the doors check the proof before calling this) into a\n * typed inventory: each page's title, description, headings and text in\n * order, images and menu links. It writes nothing; the import job decides\n * what becomes a page.\n *\n * Every request goes through `fetchPublicTextDetailed`, the theme job's\n * SSRF-guarded fetch: https on the default port only, public addresses only,\n * the socket pinned to the address checked. On top of that:\n *\n * - **One site.** The site is `https://<domain>` and `https://www.<domain>`,\n * one site to its owner. Every redirect hop and every discovered link must\n * stay on it; a page that redirects anywhere else is refused, not followed.\n * - **AglynBot.** Every request says `AglynBot/1.0 (+<the operator's bot page>)`,\n * and robots.txt is read first and honored for every page: the AglynBot\n * group, else `*`. A robots.txt that answers 404 allows everything; one\n * that cannot be read at all (5xx, no answer) stops the crawl, because\n * \"could not ask\" is not \"allowed\".\n * - **Our own edge.** A site this platform serves gets the edge secret\n * (`site-import-edge.ts`, AGL-4085), which lifts our bot challenge for\n * AglynBot; it is asked per request and per redirect hop, and a request\n * that leaves the site's two origins never carries it.\n * - **Sitemap first.** The sitemaps robots.txt names, else /sitemap.xml (an\n * index's children included), then same-site links found on the pages read,\n * for whatever the sitemap missed.\n * - **Budgets.** Pages (the caller's, from the plan), bytes per page (a page\n * over it is refused, not cut), bytes in total, and wall-clock time. A\n * whole site's worth fits (AGL-4083): aglyn.com's 123 pages average 440 KB,\n * 54 MB in all, so the total is 160 MB; a page is parsed and dropped as it\n * is read, so what is held is its blocks, never its bytes.\n * - **Four at a time.** robots.txt, the sitemaps and the home page are read\n * one after another; the rest four at a time, and the inventory keeps the\n * order they were asked in, which is the sitemap's.\n * - **Nothing vanishes.** An address a stop (the clock, the bytes, the page\n * budget) left unread is listed as `not-reached`, so the inventory's\n * counts add up to the site. A wave's own read leaves its unread pages for\n * its next pass instead.\n * - **No lookalikes.** A domain that wears a brand it is not\n * (`lookalikeBrandForHost`) is refused before any request.\n * - **No sign-in pages.** A page with a password field is refused and\n * reported; forms with payment fields, scripts, iframes and embeds never\n * reach the inventory (site-import-html.ts).\n *=========================================*/\n\nimport { lookalikeBrandForHost } from '@aglyn/shared-util-email/outbound-phishing-screen'\nimport { fenceUntrustedText } from '@aglyn/shared-util-tools/untrusted-text'\nimport {\n AI_THEME_REFERENCE_STYLESHEETS,\n AI_THEME_STYLESHEET_MAX_BYTES,\n fetchPublicTextDetailed,\n type PublicFetchEdge,\n type PublicFetchOptions,\n type PublicFetchResult,\n} from '../jobs/ai-theme-brand-inputs'\nimport type { SiteImportFooter, SiteImportLayout, SiteImportLookFacts, SiteImportNavTree } from '../model/ai-site-import'\nimport {\n extractSiteImportPage,\n readMetaValues,\n type SiteImportBlock,\n type SiteImportBrandMark,\n type SiteImportForm,\n type SiteImportIcon,\n type SiteImportImage,\n type SiteImportNavLink,\n type SiteImportOrganization,\n} from './site-import-html'\nimport {\n AGLYN_BOT_TOKEN,\n parseRobotsTxt,\n parseSitemap,\n robotsAllows,\n robotsRulesFor,\n type RobotsRule,\n} from './site-import-robots'\nimport { NO_SITE_IMPORT_HEADERS, siteImportEdgeHeadersFor, type SiteImportHeadersFor } from './site-import-edge'\nimport { siteImportLayout, siteImportLookOf } from './site-import-layout'\nimport { siteImportFooterColumns, siteImportNavTree } from './site-import-nav'\n\n/**\n * Where the bot's user agent points a site owner who wants to know what it is\n * (AGL-3983): the operator's own page about it. `SITE_IMPORT_BOT_INFO_URL` on\n * a self-hosted deployment, so its crawler never names Aglyn's address; the\n * literal is only that variable's default.\n *\n * Aglyn's is the Bring my site guide, which says what AglynBot reads and how\n * robots.txt keeps it out. There is no page of its own (Zach, 10/20: \"we don't\n * need a bot page at all\"), and the site it reads is the reader's own: an\n * import starts only once its owner has proved the site is theirs.\n */\nexport const AGLYN_BOT_INFO_URL =\n process.env['SITE_IMPORT_BOT_INFO_URL'] ?? 'https://docs.aglyn.com/ai/bring-my-site'\n\n/** What every crawler request says it is. */\nexport const AGLYN_BOT_USER_AGENT = `AglynBot/1.0 (+${AGLYN_BOT_INFO_URL})`\n\nexport const SITE_IMPORT_DEFAULTS = {\n maxPageBytes: 2 * 1024 * 1024,\n /**\n * A whole site's worth (AGL-4083): 54 MB for aglyn.com's 123 pages, with\n * room; 400 pages at its 440 KB average are 176 MB (AGL-4106).\n */\n maxTotalBytes: 320 * 1024 * 1024,\n timeBudgetMs: 60_000,\n /** One request's own clock, inside the whole crawl's. */\n requestTimeoutMs: 8_000,\n robotsMaxBytes: 256 * 1024,\n sitemapMaxBytes: 4 * 1024 * 1024,\n /** Sitemap documents read, an index's children included: an index of six children is seven. */\n maxSitemaps: 24,\n /** URLs a sitemap may contribute to the queue. */\n maxSitemapUrls: 2_000,\n /** Reasons kept in `skipped` before the list stops growing: every address a sitemap may name. */\n maxSkipped: 2_000,\n /** Pages read at once, after robots.txt, the sitemaps and the home page. */\n concurrency: 4,\n} as const\n\n/** Never a page: files a link may point at that are not HTML. */\nconst NON_PAGE_EXTENSION =\n /\\.(?:pdf|jpe?g|png|gif|webp|avif|svg|ico|bmp|tiff?|zip|gz|tgz|rar|7z|mp4|m4v|mov|webm|mp3|wav|ogg|m4a|docx?|xlsx?|pptx?|csv|txt|css|js|mjs|json|xml|rss|atom|woff2?|ttf|otf|eot|exe|dmg|apk)$/i\n\nconst TRACKING_PARAM = /^(?:utm_[a-z]+|fbclid|gclid|msclkid|mc_cid|mc_eid|_ga|ref)$/i\n\n/**\n * Never a page, whatever its extension (AGL-4106): an API's or a CDN's path\n * (aglyn.com's press kit links 136 `/api/media/cdn/…?download=1` files) and\n * any address that asks for a download.\n */\nconst NON_PAGE_PATH = /^\\/(?:api|cdn-cgi|wp-json|_next\\/static|_next\\/image)(?:\\/|$)/i\nconst DOWNLOAD_PARAM = /^(?:download|dl|attachment)$/i\n\nconst DOMAIN_PATTERN = /^(?!-)[a-z0-9-]{1,63}(\\.[a-z0-9-]{1,63})+$/\n\nexport type SiteImportSkipReason =\n /** The page has a password field: a sign-in page, refused outright. */\n | 'login-form'\n /** robots.txt keeps AglynBot off this path. */\n | 'robots'\n /** A redirect left the site. */\n | 'off-origin-redirect'\n /** Over the per-page byte cap. */\n | 'too-large'\n /** Answered with something that is not HTML. */\n | 'not-html'\n /** Answered 4xx or 5xx. */\n | 'http-error'\n /** No answer, a private address, or a refused address. */\n | 'unreachable'\n /** Never asked for: a stop (time, bytes, the page budget) came first (AGL-4083). */\n | 'not-reached'\n\nexport interface SiteImportSkipped {\n url: string\n reason: SiteImportSkipReason\n status?: number\n /** Where an off-origin redirect pointed. */\n location?: string\n /** Whose edge turned an error answer away, when it said (AGL-4083). */\n edge?: PublicFetchEdge\n}\n\nexport interface SiteImportPage {\n /** The address the page was read from, after any same-site redirect. */\n url: string\n path: string\n /** Where the crawler learned of the page. */\n foundBy: 'home' | 'sitemap' | 'link'\n title: string\n description: string\n lang: string | null\n canonical: string | null\n /** The share card (AGL-4083). */\n ogImage: string | null\n /** The site's own name, as its head gives it. */\n siteName: string\n icons: SiteImportIcon[]\n /** The header's link home: the brand's logo and words. */\n brand: SiteImportBrandMark | null\n organization: SiteImportOrganization | null\n blocks: SiteImportBlock[]\n images: SiteImportImage[]\n navLinks: SiteImportNavLink[]\n /** Same-site page addresses this page links to. */\n links: string[]\n forms: { kept: SiteImportForm[]; removed: number }\n bytes: number\n /** How the source lays the page out (AGL-4106), on a read asked for it (`layout`): a wave's. */\n layout?: SiteImportLayout | null\n /** The home page's menu, footer and look, as its source builds them (AGL-4106). */\n nav?: SiteImportNavTree | null\n footer?: SiteImportFooter | null\n look?: SiteImportLookFacts | null\n}\n\nexport type SiteImportStop =\n | 'page-budget'\n | 'total-bytes'\n | 'time'\n /** robots.txt could not be read, so nothing was asked of the site. */\n | 'robots-unreachable'\n\nexport interface SiteImportInventory {\n domain: string\n /** The site's origins: the bare name and its `www.` twin. */\n origins: string[]\n /** Set when nothing was fetched at all. */\n refused: 'invalid-domain' | 'lookalike' | null\n pages: SiteImportPage[]\n skipped: SiteImportSkipped[]\n /** Skips past {@link SITE_IMPORT_DEFAULTS.maxSkipped}, counted only. */\n skippedOverflow: number\n robots: { found: boolean; sitemaps: string[] }\n /** Page addresses the sitemaps listed (same-site, before robots and budget). */\n sitemapUrls: number\n stoppedBy: SiteImportStop | null\n bytesRead: number\n startedAt: number\n finishedAt: number\n}\n\nexport interface SiteImportCrawlOptions {\n /** The proved domain; `www.` is folded in. */\n domain: string\n /** The most pages the inventory may hold: the plan's page count. */\n maxPages: number\n maxPageBytes?: number\n maxTotalBytes?: number\n timeBudgetMs?: number\n signal?: AbortSignal\n /**\n * Read the sitemap's shallow addresses before its deep ones (AGL-3976), so a\n * crawl the page budget stops reads a site's main pages before the tail of\n * its blog. A sitemap's own order is kept among addresses of one depth.\n */\n shallowFirst?: boolean\n /**\n * Read exactly these addresses of the site, in order, and nothing else\n * (AGL-3976): an import's wave reads its own pages again when it starts. No\n * sitemap is read and no link is followed; robots.txt is read and honored\n * as for any crawl, and every other rule holds.\n */\n only?: readonly string[]\n /**\n * Read how each page is laid out (AGL-4106): its structure, through its own\n * stylesheets (the first two it links, each asked once a crawl). On by\n * default for a wave's read (`only`), whose pages are built; the home page's\n * menu, footer and look are read on every crawl.\n */\n layout?: boolean\n}\n\nexport interface SiteImportCrawlSeams {\n fetch?: (url: string, options: PublicFetchOptions) => Promise<PublicFetchResult>\n now?: () => number\n /**\n * Request headers for the site being read, asked once per crawl with its\n * domain (AGL-4083, AGL-4085). Absent, the crawl asks the edge\n * (`siteImportEdgeHeadersFor`): Aglyn's edge secret for each of the site's\n * two origins this platform serves, decided origin by origin, and nothing\n * anywhere else. Either way the headers go only to the site's two origins,\n * and the fetch asks again on every redirect hop, so a hop anywhere else\n * carries nothing. Always under the crawler's own `Accept` and `User-Agent`.\n */\n headersFor?: (domain: string) => Promise<Readonly<Record<string, string>>> | Readonly<Record<string, string>>\n}\n\n/**\n * The per-request headers of a crawl of `domain`: the seam's, else the edge's,\n * and none for any address off the site's two origins. Never throws.\n */\nasync function siteRequestHeaders(\n seams: SiteImportCrawlSeams,\n domain: string,\n origins: readonly string[],\n): Promise<SiteImportHeadersFor> {\n let inner: SiteImportHeadersFor = NO_SITE_IMPORT_HEADERS\n try {\n if (seams.headersFor) {\n const headers = await seams.headersFor(domain)\n if (headers && Object.keys(headers).length) inner = () => headers\n } else {\n inner = await siteImportEdgeHeadersFor(origins)\n }\n } catch (error) {\n console.warn('[site-import] the edge headers could not be read; reading without them', { domain, error })\n }\n return (url: URL) => (origins.includes(url.origin) ? inner(url) : {})\n}\n\n/** The site's two origins for a domain. */\nexport function siteImportOrigins(domain: string): string[] {\n const bare = domain.replace(/^www\\./, '')\n return [`https://${bare}`, `https://www.${bare}`]\n}\n\n/** A crawlable page address on the site, normalized for de-duplication; else null. */\nexport function siteImportPageKey(url: URL, origins: readonly string[]): string | null {\n if (url.protocol !== 'https:' || url.username || url.password) return null\n if (url.port && url.port !== '443') return null\n if (!origins.includes(url.origin)) return null\n if (NON_PAGE_EXTENSION.test(url.pathname) || NON_PAGE_PATH.test(url.pathname)) return null\n if ([...url.searchParams.keys()].some((key) => DOWNLOAD_PARAM.test(key))) return null\n const clean = new URL(url.toString())\n clean.hash = ''\n for (const key of [...clean.searchParams.keys()]) {\n if (TRACKING_PARAM.test(key)) clean.searchParams.delete(key)\n }\n clean.search = clean.searchParams.toString() ? `?${clean.searchParams.toString()}` : ''\n return clean.toString()\n}\n\nfunction skipReasonFor(result: PublicFetchResult): SiteImportSkipReason {\n switch (result.refusal) {\n case 'redirect-refused':\n return 'off-origin-redirect'\n case 'content-type':\n return 'not-html'\n case 'too-large':\n return 'too-large'\n case 'http-status':\n return 'http-error'\n default:\n return 'unreachable'\n }\n}\n\n/** Read a proved site into an inventory. Never throws for anything the site does. */\nexport async function crawlSiteForImport(\n options: SiteImportCrawlOptions,\n seams: SiteImportCrawlSeams = {},\n): Promise<SiteImportInventory> {\n const now = seams.now ?? Date.now\n const fetchText = seams.fetch ?? fetchPublicTextDetailed\n const domain = String(options.domain ?? '').trim().toLowerCase().replace(/\\.+$/, '').replace(/^www\\./, '')\n const origins = DOMAIN_PATTERN.test(domain) ? siteImportOrigins(domain) : []\n const startedAt = now()\n const inventory: SiteImportInventory = {\n domain,\n origins,\n refused: null,\n pages: [],\n skipped: [],\n skippedOverflow: 0,\n robots: { found: false, sitemaps: [] },\n sitemapUrls: 0,\n stoppedBy: null,\n bytesRead: 0,\n startedAt,\n finishedAt: startedAt,\n }\n const finish = () => {\n inventory.finishedAt = now()\n return inventory\n }\n if (!origins.length) {\n inventory.refused = 'invalid-domain'\n return finish()\n }\n if (lookalikeBrandForHost(domain)) {\n inventory.refused = 'lookalike'\n return finish()\n }\n\n // Asked once, before anything else, and held to the site's two origins.\n const headersFor = await siteRequestHeaders(seams, domain, origins)\n const maxPages = Math.max(0, Math.floor(options.maxPages))\n const maxPageBytes = options.maxPageBytes ?? SITE_IMPORT_DEFAULTS.maxPageBytes\n const maxTotalBytes = options.maxTotalBytes ?? SITE_IMPORT_DEFAULTS.maxTotalBytes\n const deadlineAt = startedAt + (options.timeBudgetMs ?? SITE_IMPORT_DEFAULTS.timeBudgetMs)\n const controller = new AbortController()\n const onAbort = () => controller.abort()\n options.signal?.addEventListener('abort', onAbort)\n if (options.signal?.aborted) controller.abort()\n const timer = setTimeout(() => controller.abort(), Math.max(0, deadlineAt - startedAt))\n\n const sameSite = (url: URL) => origins.includes(url.origin) && url.protocol === 'https:'\n const remainingBytes = () => maxTotalBytes - inventory.bytesRead\n const outOfTime = () => controller.signal.aborted || now() >= deadlineAt\n const request = (url: string, accept: RegExp, acceptHeader: string, maxBytes: number) =>\n fetchText(url, {\n maxBytes,\n accept,\n acceptHeader,\n userAgent: AGLYN_BOT_USER_AGENT,\n headersFor,\n signal: controller.signal,\n timeoutMs: Math.max(1, Math.min(SITE_IMPORT_DEFAULTS.requestTimeoutMs, deadlineAt - now())),\n redirectAllowed: (_from, to) => sameSite(to),\n refuseOver: true,\n })\n const skip = (entry: SiteImportSkipped) => {\n if (inventory.skipped.length < SITE_IMPORT_DEFAULTS.maxSkipped) inventory.skipped.push(entry)\n else inventory.skippedOverflow += 1\n }\n\n try {\n // robots.txt, before anything else is asked of the site.\n const home = `${origins[0]}/`\n let rules: RobotsRule[] = []\n const robots = await request(\n `${origins[0]}/robots.txt`,\n /text\\/plain|text\\/html|^$/i,\n 'text/plain',\n Math.min(SITE_IMPORT_DEFAULTS.robotsMaxBytes, remainingBytes()),\n )\n if (robots.ok) {\n inventory.bytesRead += robots.bytes\n const parsed = parseRobotsTxt(robots.text)\n rules = robotsRulesFor(parsed, AGLYN_BOT_TOKEN)\n inventory.robots = { found: true, sitemaps: parsed.sitemaps }\n } else if (\n !(robots.refusal === 'http-status' && (robots.status ?? 0) >= 400 && (robots.status ?? 0) < 500)\n ) {\n inventory.stoppedBy = outOfTime() ? 'time' : 'robots-unreachable'\n return finish()\n }\n const allowed = (key: string) => {\n const url = new URL(key)\n return robotsAllows(rules, `${url.pathname}${url.search}`)\n }\n\n // A wave's own pages (AGL-3976): exactly those, after robots.txt.\n const only = options.only\n ? options.only\n .map((raw) => {\n try {\n return siteImportPageKey(new URL(raw), origins)\n } catch {\n return null\n }\n })\n .filter((key): key is string => !!key)\n : null\n\n // Sitemaps: the ones robots.txt names on this site, else /sitemap.xml.\n const sitemapQueue: string[] = []\n for (const raw of inventory.robots.sitemaps) {\n try {\n const url = new URL(raw)\n if (sameSite(url)) sitemapQueue.push(url.toString())\n } catch {\n // A malformed Sitemap line names nothing.\n }\n }\n if (!sitemapQueue.length && !only) sitemapQueue.push(`${origins[0]}/sitemap.xml`)\n if (only) sitemapQueue.length = 0\n const sitemapSeen = new Set<string>()\n const fromSitemap: string[] = []\n let sitemapsRead = 0\n while (sitemapQueue.length && sitemapsRead < SITE_IMPORT_DEFAULTS.maxSitemaps && !outOfTime()) {\n const next = sitemapQueue.shift() as string\n if (sitemapSeen.has(next)) continue\n sitemapSeen.add(next)\n if (/\\.gz$/i.test(new URL(next).pathname)) continue\n if (!allowed(next)) continue\n const room = Math.min(SITE_IMPORT_DEFAULTS.sitemapMaxBytes, remainingBytes())\n if (room <= 0) break\n sitemapsRead += 1\n const sitemap = await request(next, /xml|text\\/plain/i, 'application/xml, text/xml;q=0.9', room)\n if (!sitemap.ok) continue\n inventory.bytesRead += sitemap.bytes\n const entries = parseSitemap(sitemap.text)\n for (const location of entries.locations) {\n let url: URL\n try {\n url = new URL(location)\n } catch {\n continue\n }\n if (entries.index) {\n if (sameSite(url)) sitemapQueue.push(url.toString())\n continue\n }\n const key = siteImportPageKey(url, origins)\n if (key && fromSitemap.length < SITE_IMPORT_DEFAULTS.maxSitemapUrls) fromSitemap.push(key)\n }\n }\n inventory.sitemapUrls = fromSitemap.length\n if (options.shallowFirst) {\n const depth = (key: string) => new URL(key).pathname.split('/').filter(Boolean).length\n const ranked = fromSitemap.map((key, order) => ({ key, order, depth: depth(key) }))\n ranked.sort((a, b) => a.depth - b.depth || a.order - b.order)\n fromSitemap.splice(0, fromSitemap.length, ...ranked.map((entry) => entry.key))\n }\n\n // Pages: home, then the sitemap's, then links the pages themselves name.\n // A wave's read is its own pages alone.\n const queue: { key: string; foundBy: SiteImportPage['foundBy'] }[] = only\n ? only.map((key) => ({ key, foundBy: (new URL(key).pathname === '/' ? 'home' : 'link') as SiteImportPage['foundBy'] }))\n : [{ key: home, foundBy: 'home' }]\n const queued = new Set<string>(only ?? [home])\n for (const key of fromSitemap) {\n if (queued.has(key)) continue\n queued.add(key)\n queue.push({ key, foundBy: 'sitemap' })\n }\n const read = new Set<string>()\n // The site's two names are one site: once the home page says which one\n // it answers on, every address is read on that one, so /about is not\n // read twice as example.com/about and www.example.com/about.\n // A wave's read starts on the name its pages were read on the first time.\n let preferred = only?.length ? new URL(only[0]).origin : origins[0]\n const canon = (raw: string) => {\n const url = new URL(raw)\n return origins.includes(url.origin) && url.origin !== preferred\n ? `${preferred}${url.pathname}${url.search}`\n : raw\n }\n const maxAttempts = maxPages * 3 + 10\n let attempts = 0\n type Asked = { next: (typeof queue)[number]; key: string; cap: number; page: PublicFetchResult }\n /** The pages asked for and not yet taken in, in the order they were asked. */\n const window: Array<Promise<Asked>> = []\n /** The bytes the asked pages may still read: what is left is shared, never promised twice. */\n let reserved = 0\n let stop: SiteImportStop | null = null\n /** Asked for and never read, because a stop came first: listed as not reached. */\n const cutOff: string[] = []\n /** Home alone first, so its answer settles which of the site's two names the rest are read on. */\n let homeIn = !!only\n /** Why no more may be asked now: a stop, `wait` for an asked page to come in first, or nothing. */\n const held = (): SiteImportStop | 'wait' | null => {\n if (inventory.pages.length >= maxPages) return 'page-budget'\n if (outOfTime()) return 'time'\n if (remainingBytes() <= 0) return 'total-bytes'\n if (attempts >= maxAttempts) return 'page-budget'\n if (inventory.pages.length + window.length >= maxPages) return 'wait'\n if (remainingBytes() - reserved <= 0) return 'wait'\n return null\n }\n const readLayout = options.layout ?? !!only\n /** Linked stylesheets, each asked once a crawl. */\n const sheets = new Map<string, Promise<string | null>>()\n const stylesheet = (url: string): Promise<string | null> => {\n const held = sheets.get(url)\n if (held) return held\n const room = Math.min(AI_THEME_STYLESHEET_MAX_BYTES, remainingBytes() - reserved)\n const asked: Promise<string | null> =\n room <= 0 || outOfTime()\n ? Promise.resolve(null)\n : request(url, /text\\/css|text\\/plain/i, 'text/css,*/*;q=0.1', room).then(\n (answer) => {\n if (!answer.ok) return null\n inventory.bytesRead += answer.bytes\n return answer.text\n },\n () => null,\n )\n sheets.set(url, asked)\n return asked\n }\n /** Takes one asked page in: the inventory's next page, a skip, or the reason the read must stop. */\n const takeIn = async ({ next, key, cap, page }: Asked): Promise<SiteImportStop | null> => {\n const foundBy = next.foundBy\n if (foundBy === 'home') homeIn = true\n if (!page.ok) {\n if (page.refusal === 'too-large' && cap < maxPageBytes) {\n cutOff.push(key)\n return 'total-bytes'\n }\n if (page.refusal === 'network' && outOfTime()) {\n cutOff.push(key)\n return 'time'\n }\n // A file is not a page: it takes nothing from the page budget's attempts (AGL-4106).\n if (page.refusal === 'content-type') attempts = Math.max(0, attempts - 1)\n skip({\n url: key,\n reason: skipReasonFor(page),\n ...(page.status ? { status: page.status } : {}),\n ...(page.location ? { location: page.location } : {}),\n ...(page.edge ? { edge: page.edge } : {}),\n })\n return null\n }\n inventory.bytesRead += page.bytes\n if (foundBy === 'home') preferred = new URL(page.url).origin\n const finalKey = canon(siteImportPageKey(new URL(page.url), origins) ?? page.url)\n if (finalKey !== key) {\n if (read.has(finalKey)) return null\n read.add(finalKey)\n if (!allowed(finalKey)) {\n skip({ url: finalKey, reason: 'robots' })\n return null\n }\n }\n const isHome = foundBy === 'home'\n const structured = readLayout || isHome\n const extract = extractSiteImportPage(page.text, page.url, sameSite, { structure: structured })\n if (extract.loginForm) {\n skip({ url: finalKey, reason: 'login-form' })\n return null\n }\n const links: string[] = []\n for (const link of extract.links) {\n const linkKey = siteImportPageKey(new URL(link), origins)\n if (!linkKey) continue\n links.push(linkKey)\n if (!only && !queued.has(linkKey)) {\n queued.add(linkKey)\n queue.push({ key: linkKey, foundBy: 'link' })\n }\n }\n // How the page is built (AGL-4106), through its own stylesheets.\n let built: Pick<SiteImportPage, 'layout' | 'nav' | 'footer' | 'look'> = {}\n if (extract.structure) {\n const linked = await Promise.all(extract.structure.stylesheets.filter((url) => !/fonts\\.googleapis\\.com/i.test(url)).slice(0, AI_THEME_REFERENCE_STYLESHEETS).map(stylesheet))\n const css = linked.filter((text): text is string => typeof text === 'string')\n const source = { blocks: extract.blocks, organization: extract.organization, structure: extract.structure }\n try {\n built = {\n ...(readLayout ? { layout: siteImportLayout(source, css) } : {}),\n ...(isHome ? { nav: siteImportNavTree(source, css), footer: siteImportFooterColumns(source, css), look: siteImportLookOf(source, css) } : {}),\n }\n } catch (error) {\n // A page the reader cannot lay out is still its words.\n console.warn('[site-import] the layout could not be read', { url: page.url, error })\n }\n }\n inventory.pages.push({\n ...built,\n url: finalKey,\n path: new URL(finalKey).pathname,\n foundBy,\n title: extract.title,\n description: extract.description,\n lang: extract.lang,\n canonical: extract.canonical,\n ogImage: extract.ogImage,\n siteName: extract.siteName,\n icons: extract.icons,\n brand: extract.brand,\n organization: extract.organization,\n blocks: extract.blocks,\n images: extract.images,\n navLinks: extract.navLinks,\n links: [...new Set(links.map(canon))],\n forms: extract.forms,\n bytes: page.bytes,\n })\n return null\n }\n for (;;) {\n const width = homeIn ? SITE_IMPORT_DEFAULTS.concurrency : 1\n while (!stop && queue.length && window.length < width) {\n const why = held()\n if (why === 'wait') break\n if (why) {\n stop = why\n break\n }\n const next = queue.shift() as (typeof queue)[number]\n const key = canon(next.key)\n if (read.has(key)) continue\n if (!allowed(key)) {\n skip({ url: key, reason: 'robots' })\n if (next.foundBy === 'home') homeIn = true\n continue\n }\n attempts += 1\n read.add(key)\n const cap = Math.min(maxPageBytes, remainingBytes() - reserved)\n reserved += cap\n window.push(\n request(key, /text\\/html|application\\/xhtml\\+xml/i, 'text/html, application/xhtml+xml;q=0.9', cap).then((page) => ({ next, key, cap, page })),\n )\n }\n if (!window.length) break\n const asked = await (window.shift() as Promise<Asked>)\n reserved -= asked.cap\n stop = (await takeIn(asked)) ?? stop\n }\n inventory.stoppedBy = stop\n // Whatever a stop left unread is said, never dropped; a wave's own read\n // leaves its unread pages for its next pass instead.\n if (stop && !only) {\n const unread = [...cutOff]\n for (const next of queue) {\n const key = canon(next.key)\n if (!read.has(key) && !unread.includes(key)) unread.push(key)\n }\n for (const url of unread) skip({ url, reason: 'not-reached' })\n }\n return finish()\n } finally {\n clearTimeout(timer)\n options.signal?.removeEventListener('abort', onAbort)\n }\n}\n\n/**\n * The home page's `aglyn-site-verification` values, for the meta-tag proof:\n * the same fetch, user agent and same-site redirects as the crawl, but no\n * robots.txt, because the person asked for this one page to be read.\n * `answered: false` when the page could not be read at all.\n */\nexport async function readSiteVerificationMeta(\n domain: string,\n metaName: string,\n seams: SiteImportCrawlSeams = {},\n): Promise<{ answered: boolean; values: string[]; url?: string }> {\n const fetchText = seams.fetch ?? fetchPublicTextDetailed\n const bare = String(domain ?? '').trim().toLowerCase().replace(/^www\\./, '')\n if (!DOMAIN_PATTERN.test(bare) || lookalikeBrandForHost(bare)) return { answered: false, values: [] }\n const origins = siteImportOrigins(bare)\n const result = await fetchText(`${origins[0]}/`, {\n maxBytes: SITE_IMPORT_DEFAULTS.maxPageBytes,\n accept: /text\\/html|application\\/xhtml\\+xml/i,\n acceptHeader: 'text/html, application/xhtml+xml;q=0.9',\n userAgent: AGLYN_BOT_USER_AGENT,\n headersFor: await siteRequestHeaders(seams, bare, origins),\n timeoutMs: SITE_IMPORT_DEFAULTS.requestTimeoutMs,\n redirectAllowed: (_from, to) => to.protocol === 'https:' && origins.includes(to.origin),\n })\n if (!result.ok) {\n // An answer that is not the page (a 404, a redirect off the site) is\n // still an answer: the tag is not where it must be.\n const answered = result.refusal === 'http-status' || result.refusal === 'redirect-refused' || result.refusal === 'content-type'\n return { answered, values: [], url: result.url }\n }\n const head = result.text.split(/<body\\b/i)[0] ?? ''\n return { answered: true, values: readMetaValues(head, metaName), url: result.url }\n}\n\n/**\n * One page as text for a prompt: its title, description and blocks in order,\n * fenced as untrusted data. The importer's prompt carries `UNTRUSTED_TEXT_RULE`.\n */\nexport function siteImportPagePromptText(page: SiteImportPage, maxChars = 12_000): string {\n const lines: string[] = []\n if (page.title) lines.push(`Title: ${page.title}`)\n if (page.description) lines.push(`Description: ${page.description}`)\n for (const block of page.blocks) {\n if (block.kind === 'heading') lines.push(`${'#'.repeat(block.level)} ${block.text}`)\n else if (block.kind === 'image') lines.push(`[image: ${block.alt || 'no description'}]`)\n else if (block.kind === 'list-item') lines.push(`- ${block.text}`)\n else if (block.kind === 'quote') lines.push(`> ${block.text}`)\n else if (block.kind === 'link') {\n // A link inside a sentence is in its block's words already.\n if (!block.inline) lines.push(block.text)\n } else lines.push(block.text)\n }\n return fenceUntrustedText(`Page ${page.path} of the site being imported`, lines.join('\\n'), { maxChars })\n}\n"],"names":["process","lookalikeBrandForHost","fenceUntrustedText","AI_THEME_REFERENCE_STYLESHEETS","AI_THEME_STYLESHEET_MAX_BYTES","fetchPublicTextDetailed","extractSiteImportPage","readMetaValues","AGLYN_BOT_TOKEN","parseRobotsTxt","parseSitemap","robotsAllows","robotsRulesFor","NO_SITE_IMPORT_HEADERS","siteImportEdgeHeadersFor","siteImportLayout","siteImportLookOf","siteImportFooterColumns","siteImportNavTree","AGLYN_BOT_INFO_URL","env","AGLYN_BOT_USER_AGENT","SITE_IMPORT_DEFAULTS","maxPageBytes","maxTotalBytes","timeBudgetMs","requestTimeoutMs","robotsMaxBytes","sitemapMaxBytes","maxSitemaps","maxSitemapUrls","maxSkipped","concurrency","NON_PAGE_EXTENSION","TRACKING_PARAM","NON_PAGE_PATH","DOWNLOAD_PARAM","DOMAIN_PATTERN","siteRequestHeaders","seams","domain","origins","inner","headersFor","headers","Object","keys","length","error","console","warn","url","includes","origin","siteImportOrigins","bare","replace","siteImportPageKey","protocol","username","password","port","test","pathname","searchParams","some","key","clean","URL","toString","hash","delete","search","skipReasonFor","result","refusal","crawlSiteForImport","options","now","Date","fetchText","fetch","String","trim","toLowerCase","startedAt","inventory","refused","pages","skipped","skippedOverflow","robots","found","sitemaps","sitemapUrls","stoppedBy","bytesRead","finishedAt","finish","maxPages","Math","max","floor","deadlineAt","controller","AbortController","onAbort","abort","signal","addEventListener","aborted","timer","setTimeout","sameSite","remainingBytes","outOfTime","request","accept","acceptHeader","maxBytes","userAgent","timeoutMs","min","redirectAllowed","_from","to","refuseOver","skip","entry","push","home","rules","ok","bytes","parsed","text","status","allowed","only","map","raw","filter","sitemapQueue","sitemapSeen","Set","fromSitemap","sitemapsRead","next","shift","has","add","room","sitemap","entries","location","locations","index","shallowFirst","depth","split","Boolean","ranked","order","sort","a","b","splice","queue","foundBy","queued","read","preferred","canon","maxAttempts","attempts","window","reserved","stop","cutOff","homeIn","held","readLayout","layout","sheets","Map","stylesheet","get","asked","Promise","resolve","then","answer","set","takeIn","cap","page","reason","edge","finalKey","isHome","structured","extract","structure","loginForm","links","link","linkKey","built","linked","all","stylesheets","slice","css","source","blocks","organization","nav","footer","look","path","title","description","lang","canonical","ogImage","siteName","icons","brand","images","navLinks","forms","width","why","unread","clearTimeout","removeEventListener","readSiteVerificationMeta","metaName","answered","values","head","siteImportPagePromptText","maxChars","lines","block","kind","repeat","level","alt","inline","join"],"mappings":";IA8GEA;AA9GF;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA6C2C,GAE3C,SAASC,qBAAqB,QAAQ,oDAAmD;AACzF,SAASC,kBAAkB,QAAQ,0CAAyC;AAC5E,SACEC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,uBAAuB,QAIlB,mCAA+B;AAEtC,SACEC,qBAAqB,EACrBC,cAAc,QAQT,wBAAoB;AAC3B,SACEC,eAAe,EACfC,cAAc,EACdC,YAAY,EACZC,YAAY,EACZC,cAAc,QAET,0BAAsB;AAC7B,SAASC,sBAAsB,EAAEC,wBAAwB,QAAmC,wBAAoB;AAChH,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,0BAAsB;AACzE,SAASC,uBAAuB,EAAEC,iBAAiB,QAAQ,uBAAmB;AAE9E;;;;;;;;;;CAUC,GACD,OAAO,MAAMC,sBACXnB,wCAAAA,QAAQoB,GAAG,CAAC,2BAA2B,YAAvCpB,wCAA2C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C,EAAEwB,MAAMO,IAAI,CAAC,OAAO;QAAER;IAAS;AACzG"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/site-import/site-import-crawl.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 * THE SITE-IMPORT CRAWLER (AGL-3974, parent AGL-3973).\n *\n * Reads a website a workspace has PROVED it owns (domain-ownership.ts in\n * tenant-data-admin; the doors check the proof before calling this) into a\n * typed inventory: each page's title, description, headings and text in\n * order, images and menu links. It writes nothing; the import job decides\n * what becomes a page.\n *\n * Every request goes through `fetchPublicTextDetailed`, the theme job's\n * SSRF-guarded fetch: https on the default port only, public addresses only,\n * the socket pinned to the address checked. On top of that:\n *\n * - **One site.** The site is `https://<domain>` and `https://www.<domain>`,\n * one site to its owner. Every redirect hop and every discovered link must\n * stay on it; a page that redirects anywhere else is refused, not followed.\n * - **AglynBot.** Every request says `AglynBot/1.0 (+<the operator's bot page>)`,\n * and robots.txt is read first and honored for every page: the AglynBot\n * group, else `*`. A robots.txt that answers 404 allows everything; one\n * that cannot be read at all (5xx, no answer) stops the crawl, because\n * \"could not ask\" is not \"allowed\".\n * - **Our own edge.** A site this platform serves gets the edge secret\n * (`site-import-edge.ts`, AGL-4085), which lifts our bot challenge for\n * AglynBot; it is asked per request and per redirect hop, and a request\n * that leaves the site's two origins never carries it.\n * - **Sitemap first.** The sitemaps robots.txt names, else /sitemap.xml (an\n * index's children included), then same-site links found on the pages read,\n * for whatever the sitemap missed.\n * - **Budgets.** Pages (the caller's, from the plan), bytes per page (a page\n * over it is refused, not cut), bytes in total, and wall-clock time. A\n * whole site's worth fits (AGL-4083): aglyn.com's 123 pages average 440 KB,\n * 54 MB in all, so the total is 160 MB; a page is parsed and dropped as it\n * is read, so what is held is its blocks, never its bytes.\n * - **Four at a time.** robots.txt, the sitemaps and the home page are read\n * one after another; the rest four at a time, and the inventory keeps the\n * order they were asked in, which is the sitemap's.\n * - **Nothing vanishes.** An address a stop (the clock, the bytes, the page\n * budget) left unread is listed as `not-reached`, so the inventory's\n * counts add up to the site. A wave's own read leaves its unread pages for\n * its next pass instead.\n * - **No lookalikes.** A domain that wears a brand it is not\n * (`lookalikeBrandForHost`) is refused before any request.\n * - **No sign-in pages.** A page with a password field is refused and\n * reported; forms with payment fields, scripts, iframes and embeds never\n * reach the inventory (site-import-html.ts).\n *=========================================*/\n\nimport { lookalikeBrandForHost } from '@aglyn/shared-util-email/outbound-phishing-screen'\nimport { fenceUntrustedText } from '@aglyn/shared-util-tools/untrusted-text'\nimport {\n AI_THEME_REFERENCE_STYLESHEETS,\n AI_THEME_STYLESHEET_MAX_BYTES,\n fetchPublicTextDetailed,\n type PublicFetchEdge,\n type PublicFetchOptions,\n type PublicFetchResult,\n} from '../jobs/ai-theme-brand-inputs'\nimport type { SiteImportFooter, SiteImportLayout, SiteImportLookFacts, SiteImportNavTree } from '../model/ai-site-import'\nimport {\n extractSiteImportPage,\n readMetaValues,\n type SiteImportBlock,\n type SiteImportBrandMark,\n type SiteImportForm,\n type SiteImportVideo,\n type SiteImportIcon,\n type SiteImportImage,\n type SiteImportNavLink,\n type SiteImportOrganization,\n} from './site-import-html'\nimport {\n AGLYN_BOT_TOKEN,\n parseRobotsTxt,\n parseSitemap,\n robotsAllows,\n robotsRulesFor,\n type RobotsRule,\n} from './site-import-robots'\nimport { NO_SITE_IMPORT_HEADERS, siteImportEdgeHeadersFor, type SiteImportHeadersFor } from './site-import-edge'\nimport { siteImportLayout, siteImportLookOf } from './site-import-layout'\nimport { siteImportFooterColumns, siteImportNavTree } from './site-import-nav'\n\n/**\n * Where the bot's user agent points a site owner who wants to know what it is\n * (AGL-3983): the operator's own page about it. `SITE_IMPORT_BOT_INFO_URL` on\n * a self-hosted deployment, so its crawler never names Aglyn's address; the\n * literal is only that variable's default.\n *\n * Aglyn's is the Bring my site guide, which says what AglynBot reads and how\n * robots.txt keeps it out. There is no page of its own (Zach, 10/20: \"we don't\n * need a bot page at all\"), and the site it reads is the reader's own: an\n * import starts only once its owner has proved the site is theirs.\n */\nexport const AGLYN_BOT_INFO_URL =\n process.env['SITE_IMPORT_BOT_INFO_URL'] ?? 'https://docs.aglyn.com/ai/bring-my-site'\n\n/** What every crawler request says it is. */\nexport const AGLYN_BOT_USER_AGENT = `AglynBot/1.0 (+${AGLYN_BOT_INFO_URL})`\n\nexport const SITE_IMPORT_DEFAULTS = {\n maxPageBytes: 2 * 1024 * 1024,\n /**\n * A whole site's worth (AGL-4083): 54 MB for aglyn.com's 123 pages, with\n * room; 400 pages at its 440 KB average are 176 MB (AGL-4106).\n */\n maxTotalBytes: 320 * 1024 * 1024,\n timeBudgetMs: 60_000,\n /** One request's own clock, inside the whole crawl's. */\n requestTimeoutMs: 8_000,\n robotsMaxBytes: 256 * 1024,\n sitemapMaxBytes: 4 * 1024 * 1024,\n /** Sitemap documents read, an index's children included: an index of six children is seven. */\n maxSitemaps: 24,\n /** URLs a sitemap may contribute to the queue. */\n maxSitemapUrls: 2_000,\n /** Reasons kept in `skipped` before the list stops growing: every address a sitemap may name. */\n maxSkipped: 2_000,\n /** Pages read at once, after robots.txt, the sitemaps and the home page. */\n concurrency: 4,\n} as const\n\n/** Never a page: files a link may point at that are not HTML. */\nconst NON_PAGE_EXTENSION =\n /\\.(?:pdf|jpe?g|png|gif|webp|avif|svg|ico|bmp|tiff?|zip|gz|tgz|rar|7z|mp4|m4v|mov|webm|mp3|wav|ogg|m4a|docx?|xlsx?|pptx?|csv|txt|css|js|mjs|json|xml|rss|atom|woff2?|ttf|otf|eot|exe|dmg|apk)$/i\n\nconst TRACKING_PARAM = /^(?:utm_[a-z]+|fbclid|gclid|msclkid|mc_cid|mc_eid|_ga|ref)$/i\n\n/**\n * Never a page, whatever its extension (AGL-4106): an API's or a CDN's path\n * (aglyn.com's press kit links 136 `/api/media/cdn/…?download=1` files) and\n * any address that asks for a download.\n */\nconst NON_PAGE_PATH = /^\\/(?:api|cdn-cgi|wp-json|_next\\/static|_next\\/image)(?:\\/|$)/i\nconst DOWNLOAD_PARAM = /^(?:download|dl|attachment)$/i\n\nconst DOMAIN_PATTERN = /^(?!-)[a-z0-9-]{1,63}(\\.[a-z0-9-]{1,63})+$/\n\nexport type SiteImportSkipReason =\n /** The page has a password field: a sign-in page, refused outright. */\n | 'login-form'\n /** robots.txt keeps AglynBot off this path. */\n | 'robots'\n /** A redirect left the site. */\n | 'off-origin-redirect'\n /** Over the per-page byte cap. */\n | 'too-large'\n /** Answered with something that is not HTML. */\n | 'not-html'\n /** Answered 4xx or 5xx. */\n | 'http-error'\n /** No answer, a private address, or a refused address. */\n | 'unreachable'\n /** Never asked for: a stop (time, bytes, the page budget) came first (AGL-4083). */\n | 'not-reached'\n\nexport interface SiteImportSkipped {\n url: string\n reason: SiteImportSkipReason\n status?: number\n /** Where an off-origin redirect pointed. */\n location?: string\n /** Whose edge turned an error answer away, when it said (AGL-4083). */\n edge?: PublicFetchEdge\n}\n\nexport interface SiteImportPage {\n /** The address the page was read from, after any same-site redirect. */\n url: string\n path: string\n /** Where the crawler learned of the page. */\n foundBy: 'home' | 'sitemap' | 'link'\n title: string\n description: string\n lang: string | null\n canonical: string | null\n /** The share card (AGL-4083). */\n ogImage: string | null\n /** The site's own name, as its head gives it. */\n siteName: string\n icons: SiteImportIcon[]\n /** The header's link home: the brand's logo and words. */\n brand: SiteImportBrandMark | null\n organization: SiteImportOrganization | null\n blocks: SiteImportBlock[]\n images: SiteImportImage[]\n navLinks: SiteImportNavLink[]\n /** Same-site page addresses this page links to. */\n links: string[]\n forms: { kept: SiteImportForm[]; removed: number }\n /** Its videos (AGL-4140), each once; absent on a page with none. */\n videos?: SiteImportVideo[]\n bytes: number\n /** How the source lays the page out (AGL-4106), on a read asked for it (`layout`): a wave's. */\n layout?: SiteImportLayout | null\n /** The home page's menu, footer and look, as its source builds them (AGL-4106). */\n nav?: SiteImportNavTree | null\n footer?: SiteImportFooter | null\n look?: SiteImportLookFacts | null\n}\n\nexport type SiteImportStop =\n | 'page-budget'\n | 'total-bytes'\n | 'time'\n /** robots.txt could not be read, so nothing was asked of the site. */\n | 'robots-unreachable'\n\nexport interface SiteImportInventory {\n domain: string\n /** The site's origins: the bare name and its `www.` twin. */\n origins: string[]\n /** Set when nothing was fetched at all. */\n refused: 'invalid-domain' | 'lookalike' | null\n pages: SiteImportPage[]\n skipped: SiteImportSkipped[]\n /** Skips past {@link SITE_IMPORT_DEFAULTS.maxSkipped}, counted only. */\n skippedOverflow: number\n robots: { found: boolean; sitemaps: string[] }\n /** Page addresses the sitemaps listed (same-site, before robots and budget). */\n sitemapUrls: number\n stoppedBy: SiteImportStop | null\n bytesRead: number\n startedAt: number\n finishedAt: number\n}\n\nexport interface SiteImportCrawlOptions {\n /** The proved domain; `www.` is folded in. */\n domain: string\n /** The most pages the inventory may hold: the plan's page count. */\n maxPages: number\n maxPageBytes?: number\n maxTotalBytes?: number\n timeBudgetMs?: number\n signal?: AbortSignal\n /**\n * Read the sitemap's shallow addresses before its deep ones (AGL-3976), so a\n * crawl the page budget stops reads a site's main pages before the tail of\n * its blog. A sitemap's own order is kept among addresses of one depth.\n */\n shallowFirst?: boolean\n /**\n * Read exactly these addresses of the site, in order, and nothing else\n * (AGL-3976): an import's wave reads its own pages again when it starts. No\n * sitemap is read and no link is followed; robots.txt is read and honored\n * as for any crawl, and every other rule holds.\n */\n only?: readonly string[]\n /**\n * Read how each page is laid out (AGL-4106): its structure, through its own\n * stylesheets (the first two it links, each asked once a crawl). On by\n * default for a wave's read (`only`), whose pages are built; the home page's\n * menu, footer and look are read on every crawl.\n */\n layout?: boolean\n}\n\nexport interface SiteImportCrawlSeams {\n fetch?: (url: string, options: PublicFetchOptions) => Promise<PublicFetchResult>\n now?: () => number\n /**\n * Request headers for the site being read, asked once per crawl with its\n * domain (AGL-4083, AGL-4085). Absent, the crawl asks the edge\n * (`siteImportEdgeHeadersFor`): Aglyn's edge secret for each of the site's\n * two origins this platform serves, decided origin by origin, and nothing\n * anywhere else. Either way the headers go only to the site's two origins,\n * and the fetch asks again on every redirect hop, so a hop anywhere else\n * carries nothing. Always under the crawler's own `Accept` and `User-Agent`.\n */\n headersFor?: (domain: string) => Promise<Readonly<Record<string, string>>> | Readonly<Record<string, string>>\n}\n\n/**\n * The per-request headers of a crawl of `domain`: the seam's, else the edge's,\n * and none for any address off the site's two origins. Never throws.\n */\nasync function siteRequestHeaders(\n seams: SiteImportCrawlSeams,\n domain: string,\n origins: readonly string[],\n): Promise<SiteImportHeadersFor> {\n let inner: SiteImportHeadersFor = NO_SITE_IMPORT_HEADERS\n try {\n if (seams.headersFor) {\n const headers = await seams.headersFor(domain)\n if (headers && Object.keys(headers).length) inner = () => headers\n } else {\n inner = await siteImportEdgeHeadersFor(origins)\n }\n } catch (error) {\n console.warn('[site-import] the edge headers could not be read; reading without them', { domain, error })\n }\n return (url: URL) => (origins.includes(url.origin) ? inner(url) : {})\n}\n\n/** The site's two origins for a domain. */\nexport function siteImportOrigins(domain: string): string[] {\n const bare = domain.replace(/^www\\./, '')\n return [`https://${bare}`, `https://www.${bare}`]\n}\n\n/** A crawlable page address on the site, normalized for de-duplication; else null. */\nexport function siteImportPageKey(url: URL, origins: readonly string[]): string | null {\n if (url.protocol !== 'https:' || url.username || url.password) return null\n if (url.port && url.port !== '443') return null\n if (!origins.includes(url.origin)) return null\n if (NON_PAGE_EXTENSION.test(url.pathname) || NON_PAGE_PATH.test(url.pathname)) return null\n if ([...url.searchParams.keys()].some((key) => DOWNLOAD_PARAM.test(key))) return null\n const clean = new URL(url.toString())\n clean.hash = ''\n for (const key of [...clean.searchParams.keys()]) {\n if (TRACKING_PARAM.test(key)) clean.searchParams.delete(key)\n }\n clean.search = clean.searchParams.toString() ? `?${clean.searchParams.toString()}` : ''\n return clean.toString()\n}\n\nfunction skipReasonFor(result: PublicFetchResult): SiteImportSkipReason {\n switch (result.refusal) {\n case 'redirect-refused':\n return 'off-origin-redirect'\n case 'content-type':\n return 'not-html'\n case 'too-large':\n return 'too-large'\n case 'http-status':\n return 'http-error'\n default:\n return 'unreachable'\n }\n}\n\n/** Read a proved site into an inventory. Never throws for anything the site does. */\nexport async function crawlSiteForImport(\n options: SiteImportCrawlOptions,\n seams: SiteImportCrawlSeams = {},\n): Promise<SiteImportInventory> {\n const now = seams.now ?? Date.now\n const fetchText = seams.fetch ?? fetchPublicTextDetailed\n const domain = String(options.domain ?? '').trim().toLowerCase().replace(/\\.+$/, '').replace(/^www\\./, '')\n const origins = DOMAIN_PATTERN.test(domain) ? siteImportOrigins(domain) : []\n const startedAt = now()\n const inventory: SiteImportInventory = {\n domain,\n origins,\n refused: null,\n pages: [],\n skipped: [],\n skippedOverflow: 0,\n robots: { found: false, sitemaps: [] },\n sitemapUrls: 0,\n stoppedBy: null,\n bytesRead: 0,\n startedAt,\n finishedAt: startedAt,\n }\n const finish = () => {\n inventory.finishedAt = now()\n return inventory\n }\n if (!origins.length) {\n inventory.refused = 'invalid-domain'\n return finish()\n }\n if (lookalikeBrandForHost(domain)) {\n inventory.refused = 'lookalike'\n return finish()\n }\n\n // Asked once, before anything else, and held to the site's two origins.\n const headersFor = await siteRequestHeaders(seams, domain, origins)\n const maxPages = Math.max(0, Math.floor(options.maxPages))\n const maxPageBytes = options.maxPageBytes ?? SITE_IMPORT_DEFAULTS.maxPageBytes\n const maxTotalBytes = options.maxTotalBytes ?? SITE_IMPORT_DEFAULTS.maxTotalBytes\n const deadlineAt = startedAt + (options.timeBudgetMs ?? SITE_IMPORT_DEFAULTS.timeBudgetMs)\n const controller = new AbortController()\n const onAbort = () => controller.abort()\n options.signal?.addEventListener('abort', onAbort)\n if (options.signal?.aborted) controller.abort()\n const timer = setTimeout(() => controller.abort(), Math.max(0, deadlineAt - startedAt))\n\n const sameSite = (url: URL) => origins.includes(url.origin) && url.protocol === 'https:'\n const remainingBytes = () => maxTotalBytes - inventory.bytesRead\n const outOfTime = () => controller.signal.aborted || now() >= deadlineAt\n const request = (url: string, accept: RegExp, acceptHeader: string, maxBytes: number) =>\n fetchText(url, {\n maxBytes,\n accept,\n acceptHeader,\n userAgent: AGLYN_BOT_USER_AGENT,\n headersFor,\n signal: controller.signal,\n timeoutMs: Math.max(1, Math.min(SITE_IMPORT_DEFAULTS.requestTimeoutMs, deadlineAt - now())),\n redirectAllowed: (_from, to) => sameSite(to),\n refuseOver: true,\n })\n const skip = (entry: SiteImportSkipped) => {\n if (inventory.skipped.length < SITE_IMPORT_DEFAULTS.maxSkipped) inventory.skipped.push(entry)\n else inventory.skippedOverflow += 1\n }\n\n try {\n // robots.txt, before anything else is asked of the site.\n const home = `${origins[0]}/`\n let rules: RobotsRule[] = []\n const robots = await request(\n `${origins[0]}/robots.txt`,\n /text\\/plain|text\\/html|^$/i,\n 'text/plain',\n Math.min(SITE_IMPORT_DEFAULTS.robotsMaxBytes, remainingBytes()),\n )\n if (robots.ok) {\n inventory.bytesRead += robots.bytes\n const parsed = parseRobotsTxt(robots.text)\n rules = robotsRulesFor(parsed, AGLYN_BOT_TOKEN)\n inventory.robots = { found: true, sitemaps: parsed.sitemaps }\n } else if (\n !(robots.refusal === 'http-status' && (robots.status ?? 0) >= 400 && (robots.status ?? 0) < 500)\n ) {\n inventory.stoppedBy = outOfTime() ? 'time' : 'robots-unreachable'\n return finish()\n }\n const allowed = (key: string) => {\n const url = new URL(key)\n return robotsAllows(rules, `${url.pathname}${url.search}`)\n }\n\n // A wave's own pages (AGL-3976): exactly those, after robots.txt.\n const only = options.only\n ? options.only\n .map((raw) => {\n try {\n return siteImportPageKey(new URL(raw), origins)\n } catch {\n return null\n }\n })\n .filter((key): key is string => !!key)\n : null\n\n // Sitemaps: the ones robots.txt names on this site, else /sitemap.xml.\n const sitemapQueue: string[] = []\n for (const raw of inventory.robots.sitemaps) {\n try {\n const url = new URL(raw)\n if (sameSite(url)) sitemapQueue.push(url.toString())\n } catch {\n // A malformed Sitemap line names nothing.\n }\n }\n if (!sitemapQueue.length && !only) sitemapQueue.push(`${origins[0]}/sitemap.xml`)\n if (only) sitemapQueue.length = 0\n const sitemapSeen = new Set<string>()\n const fromSitemap: string[] = []\n let sitemapsRead = 0\n while (sitemapQueue.length && sitemapsRead < SITE_IMPORT_DEFAULTS.maxSitemaps && !outOfTime()) {\n const next = sitemapQueue.shift() as string\n if (sitemapSeen.has(next)) continue\n sitemapSeen.add(next)\n if (/\\.gz$/i.test(new URL(next).pathname)) continue\n if (!allowed(next)) continue\n const room = Math.min(SITE_IMPORT_DEFAULTS.sitemapMaxBytes, remainingBytes())\n if (room <= 0) break\n sitemapsRead += 1\n const sitemap = await request(next, /xml|text\\/plain/i, 'application/xml, text/xml;q=0.9', room)\n if (!sitemap.ok) continue\n inventory.bytesRead += sitemap.bytes\n const entries = parseSitemap(sitemap.text)\n for (const location of entries.locations) {\n let url: URL\n try {\n url = new URL(location)\n } catch {\n continue\n }\n if (entries.index) {\n if (sameSite(url)) sitemapQueue.push(url.toString())\n continue\n }\n const key = siteImportPageKey(url, origins)\n if (key && fromSitemap.length < SITE_IMPORT_DEFAULTS.maxSitemapUrls) fromSitemap.push(key)\n }\n }\n inventory.sitemapUrls = fromSitemap.length\n if (options.shallowFirst) {\n const depth = (key: string) => new URL(key).pathname.split('/').filter(Boolean).length\n const ranked = fromSitemap.map((key, order) => ({ key, order, depth: depth(key) }))\n ranked.sort((a, b) => a.depth - b.depth || a.order - b.order)\n fromSitemap.splice(0, fromSitemap.length, ...ranked.map((entry) => entry.key))\n }\n\n // Pages: home, then the sitemap's, then links the pages themselves name.\n // A wave's read is its own pages alone.\n const queue: { key: string; foundBy: SiteImportPage['foundBy'] }[] = only\n ? only.map((key) => ({ key, foundBy: (new URL(key).pathname === '/' ? 'home' : 'link') as SiteImportPage['foundBy'] }))\n : [{ key: home, foundBy: 'home' }]\n const queued = new Set<string>(only ?? [home])\n for (const key of fromSitemap) {\n if (queued.has(key)) continue\n queued.add(key)\n queue.push({ key, foundBy: 'sitemap' })\n }\n const read = new Set<string>()\n // The site's two names are one site: once the home page says which one\n // it answers on, every address is read on that one, so /about is not\n // read twice as example.com/about and www.example.com/about.\n // A wave's read starts on the name its pages were read on the first time.\n let preferred = only?.length ? new URL(only[0]).origin : origins[0]\n const canon = (raw: string) => {\n const url = new URL(raw)\n return origins.includes(url.origin) && url.origin !== preferred\n ? `${preferred}${url.pathname}${url.search}`\n : raw\n }\n const maxAttempts = maxPages * 3 + 10\n let attempts = 0\n type Asked = { next: (typeof queue)[number]; key: string; cap: number; page: PublicFetchResult }\n /** The pages asked for and not yet taken in, in the order they were asked. */\n const window: Array<Promise<Asked>> = []\n /** The bytes the asked pages may still read: what is left is shared, never promised twice. */\n let reserved = 0\n let stop: SiteImportStop | null = null\n /** Asked for and never read, because a stop came first: listed as not reached. */\n const cutOff: string[] = []\n /** Home alone first, so its answer settles which of the site's two names the rest are read on. */\n let homeIn = !!only\n /** Why no more may be asked now: a stop, `wait` for an asked page to come in first, or nothing. */\n const held = (): SiteImportStop | 'wait' | null => {\n if (inventory.pages.length >= maxPages) return 'page-budget'\n if (outOfTime()) return 'time'\n if (remainingBytes() <= 0) return 'total-bytes'\n if (attempts >= maxAttempts) return 'page-budget'\n if (inventory.pages.length + window.length >= maxPages) return 'wait'\n if (remainingBytes() - reserved <= 0) return 'wait'\n return null\n }\n const readLayout = options.layout ?? !!only\n /** Linked stylesheets, each asked once a crawl. */\n const sheets = new Map<string, Promise<string | null>>()\n const stylesheet = (url: string): Promise<string | null> => {\n const held = sheets.get(url)\n if (held) return held\n const room = Math.min(AI_THEME_STYLESHEET_MAX_BYTES, remainingBytes() - reserved)\n const asked: Promise<string | null> =\n room <= 0 || outOfTime()\n ? Promise.resolve(null)\n : request(url, /text\\/css|text\\/plain/i, 'text/css,*/*;q=0.1', room).then(\n (answer) => {\n if (!answer.ok) return null\n inventory.bytesRead += answer.bytes\n return answer.text\n },\n () => null,\n )\n sheets.set(url, asked)\n return asked\n }\n /** Takes one asked page in: the inventory's next page, a skip, or the reason the read must stop. */\n const takeIn = async ({ next, key, cap, page }: Asked): Promise<SiteImportStop | null> => {\n const foundBy = next.foundBy\n if (foundBy === 'home') homeIn = true\n if (!page.ok) {\n if (page.refusal === 'too-large' && cap < maxPageBytes) {\n cutOff.push(key)\n return 'total-bytes'\n }\n if (page.refusal === 'network' && outOfTime()) {\n cutOff.push(key)\n return 'time'\n }\n // A file is not a page: it takes nothing from the page budget's attempts (AGL-4106).\n if (page.refusal === 'content-type') attempts = Math.max(0, attempts - 1)\n skip({\n url: key,\n reason: skipReasonFor(page),\n ...(page.status ? { status: page.status } : {}),\n ...(page.location ? { location: page.location } : {}),\n ...(page.edge ? { edge: page.edge } : {}),\n })\n return null\n }\n inventory.bytesRead += page.bytes\n if (foundBy === 'home') preferred = new URL(page.url).origin\n const finalKey = canon(siteImportPageKey(new URL(page.url), origins) ?? page.url)\n if (finalKey !== key) {\n if (read.has(finalKey)) return null\n read.add(finalKey)\n if (!allowed(finalKey)) {\n skip({ url: finalKey, reason: 'robots' })\n return null\n }\n }\n const isHome = foundBy === 'home'\n const structured = readLayout || isHome\n const extract = extractSiteImportPage(page.text, page.url, sameSite, { structure: structured })\n if (extract.loginForm) {\n skip({ url: finalKey, reason: 'login-form' })\n return null\n }\n const links: string[] = []\n for (const link of extract.links) {\n const linkKey = siteImportPageKey(new URL(link), origins)\n if (!linkKey) continue\n links.push(linkKey)\n if (!only && !queued.has(linkKey)) {\n queued.add(linkKey)\n queue.push({ key: linkKey, foundBy: 'link' })\n }\n }\n // How the page is built (AGL-4106), through its own stylesheets.\n let built: Pick<SiteImportPage, 'layout' | 'nav' | 'footer' | 'look'> = {}\n if (extract.structure) {\n const linked = await Promise.all(extract.structure.stylesheets.filter((url) => !/fonts\\.googleapis\\.com/i.test(url)).slice(0, AI_THEME_REFERENCE_STYLESHEETS).map(stylesheet))\n const css = linked.filter((text): text is string => typeof text === 'string')\n const source = { blocks: extract.blocks, organization: extract.organization, structure: extract.structure, ...(extract.videos ? { videos: extract.videos } : {}) }\n try {\n built = {\n ...(readLayout ? { layout: siteImportLayout(source, css) } : {}),\n ...(isHome ? { nav: siteImportNavTree(source, css), footer: siteImportFooterColumns(source, css), look: siteImportLookOf(source, css) } : {}),\n }\n } catch (error) {\n // A page the reader cannot lay out is still its words.\n console.warn('[site-import] the layout could not be read', { url: page.url, error })\n }\n }\n inventory.pages.push({\n ...built,\n url: finalKey,\n path: new URL(finalKey).pathname,\n foundBy,\n title: extract.title,\n description: extract.description,\n lang: extract.lang,\n canonical: extract.canonical,\n ogImage: extract.ogImage,\n siteName: extract.siteName,\n icons: extract.icons,\n brand: extract.brand,\n organization: extract.organization,\n blocks: extract.blocks,\n images: extract.images,\n navLinks: extract.navLinks,\n links: [...new Set(links.map(canon))],\n forms: extract.forms,\n ...(extract.videos ? { videos: extract.videos } : {}),\n bytes: page.bytes,\n })\n return null\n }\n for (;;) {\n const width = homeIn ? SITE_IMPORT_DEFAULTS.concurrency : 1\n while (!stop && queue.length && window.length < width) {\n const why = held()\n if (why === 'wait') break\n if (why) {\n stop = why\n break\n }\n const next = queue.shift() as (typeof queue)[number]\n const key = canon(next.key)\n if (read.has(key)) continue\n if (!allowed(key)) {\n skip({ url: key, reason: 'robots' })\n if (next.foundBy === 'home') homeIn = true\n continue\n }\n attempts += 1\n read.add(key)\n const cap = Math.min(maxPageBytes, remainingBytes() - reserved)\n reserved += cap\n window.push(\n request(key, /text\\/html|application\\/xhtml\\+xml/i, 'text/html, application/xhtml+xml;q=0.9', cap).then((page) => ({ next, key, cap, page })),\n )\n }\n if (!window.length) break\n const asked = await (window.shift() as Promise<Asked>)\n reserved -= asked.cap\n stop = (await takeIn(asked)) ?? stop\n }\n inventory.stoppedBy = stop\n // Whatever a stop left unread is said, never dropped; a wave's own read\n // leaves its unread pages for its next pass instead.\n if (stop && !only) {\n const unread = [...cutOff]\n for (const next of queue) {\n const key = canon(next.key)\n if (!read.has(key) && !unread.includes(key)) unread.push(key)\n }\n for (const url of unread) skip({ url, reason: 'not-reached' })\n }\n return finish()\n } finally {\n clearTimeout(timer)\n options.signal?.removeEventListener('abort', onAbort)\n }\n}\n\n/**\n * The home page's `aglyn-site-verification` values, for the meta-tag proof:\n * the same fetch, user agent and same-site redirects as the crawl, but no\n * robots.txt, because the person asked for this one page to be read.\n * `answered: false` when the page could not be read at all.\n */\nexport async function readSiteVerificationMeta(\n domain: string,\n metaName: string,\n seams: SiteImportCrawlSeams = {},\n): Promise<{ answered: boolean; values: string[]; url?: string }> {\n const fetchText = seams.fetch ?? fetchPublicTextDetailed\n const bare = String(domain ?? '').trim().toLowerCase().replace(/^www\\./, '')\n if (!DOMAIN_PATTERN.test(bare) || lookalikeBrandForHost(bare)) return { answered: false, values: [] }\n const origins = siteImportOrigins(bare)\n const result = await fetchText(`${origins[0]}/`, {\n maxBytes: SITE_IMPORT_DEFAULTS.maxPageBytes,\n accept: /text\\/html|application\\/xhtml\\+xml/i,\n acceptHeader: 'text/html, application/xhtml+xml;q=0.9',\n userAgent: AGLYN_BOT_USER_AGENT,\n headersFor: await siteRequestHeaders(seams, bare, origins),\n timeoutMs: SITE_IMPORT_DEFAULTS.requestTimeoutMs,\n redirectAllowed: (_from, to) => to.protocol === 'https:' && origins.includes(to.origin),\n })\n if (!result.ok) {\n // An answer that is not the page (a 404, a redirect off the site) is\n // still an answer: the tag is not where it must be.\n const answered = result.refusal === 'http-status' || result.refusal === 'redirect-refused' || result.refusal === 'content-type'\n return { answered, values: [], url: result.url }\n }\n const head = result.text.split(/<body\\b/i)[0] ?? ''\n return { answered: true, values: readMetaValues(head, metaName), url: result.url }\n}\n\n/**\n * One page as text for a prompt: its title, description and blocks in order,\n * fenced as untrusted data. The importer's prompt carries `UNTRUSTED_TEXT_RULE`.\n */\nexport function siteImportPagePromptText(page: SiteImportPage, maxChars = 12_000): string {\n const lines: string[] = []\n if (page.title) lines.push(`Title: ${page.title}`)\n if (page.description) lines.push(`Description: ${page.description}`)\n for (const block of page.blocks) {\n if (block.kind === 'heading') lines.push(`${'#'.repeat(block.level)} ${block.text}`)\n else if (block.kind === 'image') lines.push(`[image: ${block.alt || 'no description'}]`)\n else if (block.kind === 'list-item') lines.push(`- ${block.text}`)\n else if (block.kind === 'quote') lines.push(`> ${block.text}`)\n else if (block.kind === 'link') {\n // A link inside a sentence is in its block's words already.\n if (!block.inline) lines.push(block.text)\n } else lines.push(block.text)\n }\n return fenceUntrustedText(`Page ${page.path} of the site being imported`, lines.join('\\n'), { maxChars })\n}\n"],"names":["process","lookalikeBrandForHost","fenceUntrustedText","AI_THEME_REFERENCE_STYLESHEETS","AI_THEME_STYLESHEET_MAX_BYTES","fetchPublicTextDetailed","extractSiteImportPage","readMetaValues","AGLYN_BOT_TOKEN","parseRobotsTxt","parseSitemap","robotsAllows","robotsRulesFor","NO_SITE_IMPORT_HEADERS","siteImportEdgeHeadersFor","siteImportLayout","siteImportLookOf","siteImportFooterColumns","siteImportNavTree","AGLYN_BOT_INFO_URL","env","AGLYN_BOT_USER_AGENT","SITE_IMPORT_DEFAULTS","maxPageBytes","maxTotalBytes","timeBudgetMs","requestTimeoutMs","robotsMaxBytes","sitemapMaxBytes","maxSitemaps","maxSitemapUrls","maxSkipped","concurrency","NON_PAGE_EXTENSION","TRACKING_PARAM","NON_PAGE_PATH","DOWNLOAD_PARAM","DOMAIN_PATTERN","siteRequestHeaders","seams","domain","origins","inner","headersFor","headers","Object","keys","length","error","console","warn","url","includes","origin","siteImportOrigins","bare","replace","siteImportPageKey","protocol","username","password","port","test","pathname","searchParams","some","key","clean","URL","toString","hash","delete","search","skipReasonFor","result","refusal","crawlSiteForImport","options","now","Date","fetchText","fetch","String","trim","toLowerCase","startedAt","inventory","refused","pages","skipped","skippedOverflow","robots","found","sitemaps","sitemapUrls","stoppedBy","bytesRead","finishedAt","finish","maxPages","Math","max","floor","deadlineAt","controller","AbortController","onAbort","abort","signal","addEventListener","aborted","timer","setTimeout","sameSite","remainingBytes","outOfTime","request","accept","acceptHeader","maxBytes","userAgent","timeoutMs","min","redirectAllowed","_from","to","refuseOver","skip","entry","push","home","rules","ok","bytes","parsed","text","status","allowed","only","map","raw","filter","sitemapQueue","sitemapSeen","Set","fromSitemap","sitemapsRead","next","shift","has","add","room","sitemap","entries","location","locations","index","shallowFirst","depth","split","Boolean","ranked","order","sort","a","b","splice","queue","foundBy","queued","read","preferred","canon","maxAttempts","attempts","window","reserved","stop","cutOff","homeIn","held","readLayout","layout","sheets","Map","stylesheet","get","asked","Promise","resolve","then","answer","set","takeIn","cap","page","reason","edge","finalKey","isHome","structured","extract","structure","loginForm","links","link","linkKey","built","linked","all","stylesheets","slice","css","source","blocks","organization","videos","nav","footer","look","path","title","description","lang","canonical","ogImage","siteName","icons","brand","images","navLinks","forms","width","why","unread","clearTimeout","removeEventListener","readSiteVerificationMeta","metaName","answered","values","head","siteImportPagePromptText","maxChars","lines","block","kind","repeat","level","alt","inline","join"],"mappings":";IA+GEA;AA/GF;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA6C2C,GAE3C,SAASC,qBAAqB,QAAQ,oDAAmD;AACzF,SAASC,kBAAkB,QAAQ,0CAAyC;AAC5E,SACEC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,uBAAuB,QAIlB,mCAA+B;AAEtC,SACEC,qBAAqB,EACrBC,cAAc,QAST,wBAAoB;AAC3B,SACEC,eAAe,EACfC,cAAc,EACdC,YAAY,EACZC,YAAY,EACZC,cAAc,QAET,0BAAsB;AAC7B,SAASC,sBAAsB,EAAEC,wBAAwB,QAAmC,wBAAoB;AAChH,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,0BA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AC,EAAE,EAAEoH,MAAM9G,IAAI,EAAE;aACxD,IAAI8G,MAAMC,IAAI,KAAK,QAAQ;YAC9B,4DAA4D;YAC5D,IAAI,CAACD,MAAMK,MAAM,EAAEN,MAAMnH,IAAI,CAACoH,MAAM9G,IAAI;QAC1C,OAAO6G,MAAMnH,IAAI,CAACoH,MAAM9G,IAAI;IAC9B;IACA,OAAOrI,mBAAmB,CAAC,KAAK,EAAEiM,KAAKyB,IAAI,CAAC,2BAA2B,CAAC,EAAEwB,MAAMO,IAAI,CAAC,OAAO;QAAER;IAAS;AACzG"}
@@ -104,6 +104,26 @@ export interface SiteImportBackground {
104
104
  export declare function siteImportBackgroundOf(style: SiteImportComputedStyle): SiteImportBackground;
105
105
  /** Whether an element draws a border on any side. */
106
106
  export declare function siteImportHasBorder(style: SiteImportComputedStyle): boolean;
107
+ /** A side of an element's box. */
108
+ export type SiteImportSide = 'top' | 'right' | 'bottom' | 'left';
109
+ /** One side's border, where it draws one: its width in px and its color as written. */
110
+ export interface SiteImportBorderSide {
111
+ width: number;
112
+ color: SiteImportRgba | null;
113
+ }
114
+ /**
115
+ * The sides an element draws a border on (AGL-4138), each with its width and
116
+ * color: a box is bordered on every side, a rule on one. The shorthand draws
117
+ * all four; a side's own declaration, or `border-width` and `border-style`
118
+ * by side, draw only theirs.
119
+ */
120
+ export declare function siteImportBorderSides(style: SiteImportComputedStyle): Partial<Record<SiteImportSide, SiteImportBorderSide>>;
121
+ /** A picture box's `aspect-ratio`, width over height: `16 / 9`, `1.5`, `auto 4 / 3`; `null` where it sets none. */
122
+ export declare function siteImportAspectRatio(value: string | undefined): number | null;
123
+ /** A color as it shows over the ground it sits on, its strength blended in: `rgba(0,0,0,.6)` over white is `#666666`. */
124
+ export declare function siteImportOpaque(color: SiteImportRgba, under?: SiteImportRgba | null): SiteImportRgba;
125
+ /** How far apart two colors look, in OKLab (0 the same, about 1 black from white). */
126
+ export declare function siteImportColorDistance(a: SiteImportRgba, b: SiteImportRgba): number;
107
127
  /** Whether an element draws a shadow. */
108
128
  export declare function siteImportHasShadow(style: SiteImportComputedStyle): boolean;
109
129
  /** An element's corner radius in px, or `null`. */