@aglyn/plugins-ai 1.14.0 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/components/ai-site-build-page.component.js +5 -3
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-finish.component.d.ts +3 -1
- package/src/lib/components/ai-site-import-finish.component.js +3 -3
- package/src/lib/components/ai-site-import-finish.component.js.map +1 -1
- package/src/lib/components/ai-site-import-job.component.d.ts +4 -3
- package/src/lib/components/ai-site-import-job.component.js +141 -43
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/components/ai-site-import-plan.component.d.ts +42 -0
- package/src/lib/components/ai-site-import-plan.component.js +246 -0
- package/src/lib/components/ai-site-import-plan.component.js.map +1 -0
- package/src/lib/components/ai-site-import-start.component.d.ts +3 -1
- package/src/lib/components/ai-site-import-start.component.js +6 -3
- package/src/lib/components/ai-site-import-start.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.js +6 -2
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/components/ai-site-start-steps.component.d.ts +3 -2
- package/src/lib/components/ai-site-start-steps.component.js +12 -5
- package/src/lib/components/ai-site-start-steps.component.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +63 -2
- package/src/lib/jobs/ai-job-import-step.js +372 -22
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.js +4 -1
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +23 -2
- package/src/lib/jobs/ai-job-page-language.js +252 -5
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.d.ts +7 -0
- package/src/lib/jobs/ai-job-page-step.js +75 -12
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.js +4 -2
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-look.js +14 -5
- package/src/lib/jobs/ai-job-site-look.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.d.ts +11 -2
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.js +2 -1
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.d.ts +43 -2
- package/src/lib/jobs/ai-site-import-compile.js +131 -63
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +25 -1
- package/src/lib/jobs/ai-site-import-document.js +26 -7
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-honesty.d.ts +65 -0
- package/src/lib/jobs/ai-site-import-honesty.js +271 -0
- package/src/lib/jobs/ai-site-import-honesty.js.map +1 -0
- package/src/lib/jobs/ai-site-import-improve.d.ts +286 -0
- package/src/lib/jobs/ai-site-import-improve.js +1281 -0
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -0
- package/src/lib/jobs/ai-site-import-look.d.ts +4 -0
- package/src/lib/jobs/ai-site-import-look.js +16 -6
- package/src/lib/jobs/ai-site-import-look.js.map +1 -1
- package/src/lib/jobs/ai-site-import-pictures.d.ts +83 -0
- package/src/lib/jobs/ai-site-import-pictures.js +261 -0
- package/src/lib/jobs/ai-site-import-pictures.js.map +1 -0
- package/src/lib/jobs/ai-site-import-plan.d.ts +78 -0
- package/src/lib/jobs/ai-site-import-plan.js +627 -0
- package/src/lib/jobs/ai-site-import-plan.js.map +1 -0
- package/src/lib/jobs/ai-site-import-wording.js +2 -5
- package/src/lib/jobs/ai-site-import-wording.js.map +1 -1
- package/src/lib/layout-language/ai-layout-compiler.d.ts +6 -0
- package/src/lib/layout-language/ai-layout-compiler.js +10 -6
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-design.d.ts +9 -0
- package/src/lib/layout-language/ai-layout-design.js +29 -3
- package/src/lib/layout-language/ai-layout-design.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame-source.d.ts +5 -0
- package/src/lib/layout-language/ai-layout-frame-source.js +4 -2
- package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-frame.js +20 -12
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +8 -0
- package/src/lib/layout-language/ai-layout-language.js +7 -3
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-credit-estimate.d.ts +16 -0
- package/src/lib/model/ai-credit-estimate.js +14 -0
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +64 -0
- package/src/lib/model/ai-site-import-fidelity.js +380 -0
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-ledger.d.ts +82 -0
- package/src/lib/model/ai-site-import-ledger.js +254 -0
- package/src/lib/model/ai-site-import-ledger.js.map +1 -0
- package/src/lib/model/ai-site-import-view.d.ts +113 -7
- package/src/lib/model/ai-site-import-view.js +174 -16
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +253 -3
- package/src/lib/model/ai-site-import.js +371 -25
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/model/ai-site-job.js +4 -0
- package/src/lib/model/ai-site-job.js.map +1 -1
- package/src/lib/model/ai-site-kinds.d.ts +2 -0
- package/src/lib/model/ai-site-kinds.js +7 -0
- package/src/lib/model/ai-site-kinds.js.map +1 -1
- package/src/lib/model/ai-site-look.d.ts +14 -5
- package/src/lib/model/ai-site-look.js +22 -16
- package/src/lib/model/ai-site-look.js.map +1 -1
- package/src/lib/model/ai-site-start.d.ts +37 -7
- package/src/lib/model/ai-site-start.js +54 -10
- package/src/lib/model/ai-site-start.js.map +1 -1
- package/src/lib/model/ai-site-starter-look.d.ts +69 -0
- package/src/lib/model/ai-site-starter-look.js +90 -0
- package/src/lib/model/ai-site-starter-look.js.map +1 -0
- package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -0
- package/src/lib/runtime/ai-doctrine-validators.js +3 -2
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +10 -0
- package/src/lib/runtime/ai-doctrine.js +16 -2
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/server/ai-jobs-resume.js +12 -3
- package/src/lib/server/ai-jobs-resume.js.map +1 -1
- package/src/lib/server/ai-jobs-route.js +5 -1
- package/src/lib/server/ai-jobs-route.js.map +1 -1
- package/src/lib/server/ai-site-import-route.d.ts +6 -0
- package/src/lib/server/ai-site-import-route.js +8 -1
- package/src/lib/server/ai-site-import-route.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +46 -7
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +260 -14
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-improve-answers.d.ts +33 -0
- package/src/lib/site-import/fixtures/site-import-improve-answers.js +457 -0
- package/src/lib/site-import/fixtures/site-import-improve-answers.js.map +1 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +29 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js +26 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/site-import-flag.d.ts +17 -0
- package/src/lib/site-import/site-import-flag.js +15 -0
- package/src/lib/site-import/site-import-flag.js.map +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { type AiSiteImportBuild, type AiSiteImportFinish, type AiSiteImportPhoto, type AiSiteImportWords, type SiteImportLayout } from '../model/ai-site-import';
|
|
17
|
+
import { type AiSiteImportBuild, type AiSiteImportFinish, type AiSiteImportPageRole, type AiSiteImportPhoto, type AiSiteImportPlan, type AiSiteImportWords, type SiteImportLayout } from '../model/ai-site-import';
|
|
18
18
|
import type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html';
|
|
19
19
|
/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */
|
|
20
20
|
export declare const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = "importedSections";
|
|
@@ -52,6 +52,30 @@ export interface AiSiteImportDocument {
|
|
|
52
52
|
}> | null;
|
|
53
53
|
/** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */
|
|
54
54
|
videos?: SiteImportVideo[];
|
|
55
|
+
/** Redesigned from its ledger (AGL-4152): its wave was stamped generative. Absent, today's Improve it. */
|
|
56
|
+
generative?: true;
|
|
57
|
+
/** What the site says of itself, the same bytes on every page of an import: a redesign's cached digest (AGL-4152). */
|
|
58
|
+
siteLines?: string[];
|
|
59
|
+
/** The lines of the wave's other pages, which a redesign's facts may come from (AGL-4152). */
|
|
60
|
+
scope?: string[];
|
|
61
|
+
/** The site's plan, once a wave has one (AGL-4152). */
|
|
62
|
+
plan?: AiSiteImportPlan | null;
|
|
63
|
+
/** The theme's colors as its look drew them, where one was drawn (`SiteImportFidelityTheme`, AGL-4152). */
|
|
64
|
+
theme?: Record<string, unknown> | null;
|
|
65
|
+
/** The plan's proposed page (AGL-4152): new to the site, with no source to hold it to, and never kept as a fallback. */
|
|
66
|
+
proposed?: true;
|
|
67
|
+
/** What the page is for in the planned site (AGL-4152), as its plan says; absent, read from its address and what it holds. */
|
|
68
|
+
role?: AiSiteImportPageRole;
|
|
69
|
+
/** Source photos of the site's earlier pages that none of them placed, for a slot of this one (AGL-4152). */
|
|
70
|
+
sitePhotos?: AiSiteImportPhoto[];
|
|
71
|
+
/** A slot nothing else fills may take a generated picture: its owner said so, and it is quoted (AGL-4152). */
|
|
72
|
+
generatedPictures?: true;
|
|
73
|
+
/**
|
|
74
|
+
* Its wave was stamped with `release_video_embed_posters` (AGL-4140): a
|
|
75
|
+
* YouTube film whose poster the library could not hold is placed with no
|
|
76
|
+
* poster, and the published page draws YouTube's own still for it.
|
|
77
|
+
*/
|
|
78
|
+
videoPosters?: true;
|
|
55
79
|
}
|
|
56
80
|
/** The most characters a text element holds (the palette's ceiling for body copy). */
|
|
57
81
|
export declare const AI_SITE_IMPORT_TEXT_MAX_CHARS: 2000;
|
|
@@ -168,12 +168,7 @@ const clean = (text)=>String(text != null ? text : '').replace(/\s+/g, ' ').trim
|
|
|
168
168
|
});
|
|
169
169
|
const strings = (list)=>Array.isArray(list) ? list.filter((entry)=>typeof entry === 'string') : [];
|
|
170
170
|
const size = (value)=>typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0;
|
|
171
|
-
|
|
172
|
-
build,
|
|
173
|
-
title: typeof value['title'] === 'string' ? value['title'] : '',
|
|
174
|
-
url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',
|
|
175
|
-
blocks,
|
|
176
|
-
photos: (Array.isArray(value['photos']) ? value['photos'] : []).flatMap((entry)=>{
|
|
171
|
+
const photosOf = (list)=>(Array.isArray(list) ? list : []).flatMap((entry)=>{
|
|
177
172
|
const photo = entry;
|
|
178
173
|
return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string' ? [
|
|
179
174
|
_extends({
|
|
@@ -189,7 +184,13 @@ const clean = (text)=>String(text != null ? text : '').replace(/\s+/g, ' ').trim
|
|
|
189
184
|
from: photo['from']
|
|
190
185
|
} : {})
|
|
191
186
|
] : [];
|
|
192
|
-
})
|
|
187
|
+
});
|
|
188
|
+
return _extends({
|
|
189
|
+
build,
|
|
190
|
+
title: typeof value['title'] === 'string' ? value['title'] : '',
|
|
191
|
+
url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',
|
|
192
|
+
blocks,
|
|
193
|
+
photos: photosOf(value['photos']),
|
|
193
194
|
links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry)=>{
|
|
194
195
|
const link = entry;
|
|
195
196
|
return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [
|
|
@@ -204,6 +205,24 @@ const clean = (text)=>String(text != null ? text : '').replace(/\s+/g, ' ').trim
|
|
|
204
205
|
finish: value['finish']
|
|
205
206
|
} : {}, value['wording'] === 'kept' || value['wording'] === 'improved' ? {
|
|
206
207
|
wording: value['wording']
|
|
208
|
+
} : {}, value['generative'] === true ? {
|
|
209
|
+
generative: true
|
|
210
|
+
} : {}, Array.isArray(value['siteLines']) ? {
|
|
211
|
+
siteLines: strings(value['siteLines'])
|
|
212
|
+
} : {}, Array.isArray(value['scope']) ? {
|
|
213
|
+
scope: strings(value['scope'])
|
|
214
|
+
} : {}, value['plan'] && typeof value['plan'] === 'object' ? {
|
|
215
|
+
plan: value['plan']
|
|
216
|
+
} : {}, value['theme'] && typeof value['theme'] === 'object' ? {
|
|
217
|
+
theme: value['theme']
|
|
218
|
+
} : {}, value['proposed'] === true ? {
|
|
219
|
+
proposed: true
|
|
220
|
+
} : {}, Array.isArray(value['sitePhotos']) ? {
|
|
221
|
+
sitePhotos: photosOf(value['sitePhotos'])
|
|
222
|
+
} : {}, value['generatedPictures'] === true ? {
|
|
223
|
+
generatedPictures: true
|
|
224
|
+
} : {}, value['videoPosters'] === true ? {
|
|
225
|
+
videoPosters: true
|
|
207
226
|
} : {}, isLayout(value['layout']) ? {
|
|
208
227
|
layout: value['layout']
|
|
209
228
|
} : {}, Array.isArray(value['videos']) ? {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-document.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PAGE BROUGHT IN WORD FOR WORD (AGL-4084, AGL-4107).\n *\n * An imported page is never rewritten. Its words are the source's, as the\n * crawler read them (`AiSiteImportPageRead.blocks`), and how the source lays\n * them out is the reader's (`AiSiteImportPageRead.layout`, AGL-4106). This\n * module is the page as its job carries it: its blocks, its layout, its\n * photos and where its links go, read defensively off the job's inputs.\n *\n * - **Lines.** The page's main region, numbered: every heading, paragraph,\n * list item, quote, link and picture in source order. A link inside a\n * sentence is in its sentence already and is no line of its own.\n * - **Sections.** Where a read kept no layout (one made before the reader,\n * or one past its budget), one for the page's opening and one at each\n * second-level heading, as the source divides itself.\n *\n * The page is drawn by the site compiler (`ai-site-import-compile.ts`), with\n * every line on it exactly once and never a word that is not the source's.\n *=========================================*/\n\n\nimport {\n AI_SITE_IMPORT_LABEL_MAX_CHARS,\n AI_SITE_IMPORT_MAX_SECTIONS,\n type AiSiteImportBuild,\n type AiSiteImportFinish,\n type AiSiteImportPhoto,\n type AiSiteImportWords,\n type SiteImportLayout,\n} from '../model/ai-site-import'\nimport type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html'\nimport { siteImportLabel } from '../site-import/site-import-page'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\n\n/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */\nexport const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = 'importedSections'\n\n/** A page brought in, as the import step hands it to the page step. Untrusted data from the owner's site. */\nexport interface AiSiteImportDocument {\n build: AiSiteImportBuild\n /** The page's name on the new site: its h1 where the source shows no heading. */\n title: string\n /** Where the page is on the owner's website. */\n url: string\n /** The page's main region, in order. */\n blocks: SiteImportBlock[]\n /** Its photos as the library holds them, each by the source address it was read from. */\n photos: AiSiteImportPhoto[]\n /** The site's own pages a link may go to: the source path each was read from, and the page it is now. */\n links: Array<{ path: string; id: string }>\n /** The origins the old site answers on: a link to one of them is to a page of its own. */\n origins: string[]\n /**\n * How the source lays the page out (AGL-4106), over `blocks` by index;\n * absent on a read made before the reader, or one past its budget.\n */\n layout?: SiteImportLayout | null\n /** How the page's wave finishes it (AGL-4152); absent is `keep`. */\n finish?: AiSiteImportFinish | null\n /** Whether its words are improved (AGL-4152); absent is kept as written. */\n wording?: AiSiteImportWords | null\n /** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */\n videos?: SiteImportVideo[]\n}\n\n/** The most characters a text element holds (the palette's ceiling for body copy). */\nexport const AI_SITE_IMPORT_TEXT_MAX_CHARS = AI_TEXT_LIMITS.body\n\n/** The most characters a heading style holds; a longer heading is drawn in a subtitle style, still a heading. */\nexport const AI_SITE_IMPORT_HEADLINE_MAX_CHARS = AI_TEXT_LIMITS.headline\n\n/** The most characters a button's label holds; a longer link keeps its words as a line of text. */\nexport const AI_SITE_IMPORT_LABEL_CHARS = 40\n\n/**\n * What one page may weigh, inside the budget of a page of its owner's own\n * words (`AI_OWN_WORDS_PAGE_BUDGET`): a page that would run past it ends at\n * the section before, marked `cut`.\n */\nexport const AI_SITE_IMPORT_DOC_MAX_NODES = 1_400\nexport const AI_SITE_IMPORT_DOC_MAX_CHARS = 200_000\n\n/** One numbered line of a page. */\nexport interface AiSiteImportLine {\n /** 1-based, in source order. */\n n: number\n block: SiteImportBlock\n /** The section it belongs to, by plan index. */\n section: number\n}\n\nexport interface AiSiteImportDocSection {\n name: string\n /** Its lines' numbers, in order. */\n lines: number[]\n}\n\nexport interface AiSiteImportDocLines {\n lines: AiSiteImportLine[]\n sections: AiSiteImportDocSection[]\n}\n\nconst clean = (text: string) => String(text ?? '').replace(/\\s+/g, ' ').trim()\n\n/** Whether a block is a line of its own: a link inside a sentence is in its sentence already. */\nfunction isLine(block: SiteImportBlock): boolean {\n if (block.kind === 'image') return !!block.url\n if (block.kind === 'link') return !block.inline && !!clean(block.text)\n return !!clean(block.text)\n}\n\n/**\n * The page's lines and sections (AGL-4084): the opening, then one section\n * at each second-level heading, at most `AI_SITE_IMPORT_MAX_SECTIONS` (the\n * last holds whatever follows). A page that opens on a second-level heading\n * opens with it. Section names are the headings' words, neutralized and cut\n * to a label, since they travel outside a fence.\n */\nexport function aiSiteImportDocLines(blocks: readonly SiteImportBlock[], title: string): AiSiteImportDocLines {\n const lines: AiSiteImportLine[] = []\n const sections: AiSiteImportDocSection[] = []\n let current: AiSiteImportDocSection | null = null\n for (const block of blocks) {\n if (!isLine(block)) continue\n const starts = block.kind === 'heading' && block.level === 2 && sections.length < AI_SITE_IMPORT_MAX_SECTIONS\n if (!current || (starts && current.lines.length > 0)) {\n current = { name: '', lines: [] }\n sections.push(current)\n }\n const n = lines.length + 1\n lines.push({ n, block, section: sections.length - 1 })\n current.lines.push(n)\n }\n const named = new Set<string>()\n sections.forEach((section, index) => {\n const heading = section.lines.map((n) => lines[n - 1].block).find((block) => block.kind === 'heading')\n let name = siteImportLabel(heading && heading.kind === 'heading' ? heading.text : index === 0 ? title : '') || (index === 0 ? siteImportLabel(title) : '')\n if (!name) name = `Section ${index + 1}`\n // Two sections of one name are told apart, so a link to either finds it.\n let unique = name\n for (let attempt = 2; named.has(unique.toLowerCase()); attempt += 1) {\n unique = `${name.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 4)} (${attempt})`\n }\n named.add(unique.toLowerCase())\n section.name = unique\n })\n if (!sections.length) sections.push({ name: siteImportLabel(title) || 'Introduction', lines: [] })\n return { lines, sections }\n}\n\n/** The words a line shows: an image's are its description. */\nexport function aiSiteImportLineText(line: Pick<AiSiteImportLine, 'block'>): string {\n return line.block.kind === 'image' ? clean(line.block.alt) : clean(line.block.text)\n}\n\n/** How many words a line says: its runs of letters and digits, as the review counts them. */\nexport const aiSiteImportWordsIn = (text: string): number => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** The input a page job carries, read defensively; `null` on every other job. */\nexport function aiSiteImportDocumentOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportDocument | null {\n const raw = inputs?.[AI_LAYOUT_IMPORTED_SECTIONS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const build = value['build'] === 'copied' || value['build'] === 'arranged' ? value['build'] : null\n if (!build || !Array.isArray(value['blocks'])) return null\n const blocks = (value['blocks'] as unknown[]).flatMap((entry): SiteImportBlock[] => {\n if (!entry || typeof entry !== 'object') return []\n const block = entry as Record<string, unknown>\n const text = typeof block['text'] === 'string' ? block['text'] : ''\n const region = 'main' as const\n switch (block['kind']) {\n case 'heading': {\n const level = Number(block['level'])\n return [{ kind: 'heading', level: (Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2) as 1 | 2 | 3 | 4 | 5 | 6, text, region }]\n }\n case 'paragraph':\n case 'list-item':\n case 'quote':\n return [{ kind: block['kind'], text, region }]\n case 'image':\n return typeof block['url'] === 'string' ? [{ kind: 'image', url: block['url'], alt: typeof block['alt'] === 'string' ? block['alt'] : '', region }] : []\n case 'link':\n return typeof block['href'] === 'string'\n ? [{ kind: 'link', text, href: block['href'], region, ...(block['inline'] === true ? { inline: true as const } : {}) }]\n : []\n default:\n return []\n }\n })\n const strings = (list: unknown) => (Array.isArray(list) ? list.filter((entry): entry is string => typeof entry === 'string') : [])\n const size = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0)\n return {\n build,\n title: typeof value['title'] === 'string' ? value['title'] : '',\n url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',\n blocks,\n photos: (Array.isArray(value['photos']) ? value['photos'] : []).flatMap((entry): AiSiteImportPhoto[] => {\n const photo = entry as Record<string, unknown> | null\n return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string'\n ? [\n {\n mediaId: photo['mediaId'],\n src: photo['src'],\n // Its size, which frames it at its own shape where the source's tag gives none (AGL-4138).\n ...(size(photo['width']) ? { width: size(photo['width']) } : {}),\n ...(size(photo['height']) ? { height: size(photo['height']) } : {}),\n ...(typeof photo['alt'] === 'string' ? { alt: photo['alt'] } : {}),\n ...(typeof photo['from'] === 'string' ? { from: photo['from'] } : {}),\n },\n ]\n : []\n }),\n links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry) => {\n const link = entry as Record<string, unknown> | null\n return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [{ path: link['path'], id: link['id'] }] : []\n }),\n origins: strings(value['origins']),\n // How the page's wave finishes it and whether its words are improved (AGL-4152); anything else is absent: kept.\n ...(value['finish'] === 'keep' || value['finish'] === 'improve' ? { finish: value['finish'] } : {}),\n ...(value['wording'] === 'kept' || value['wording'] === 'improved' ? { wording: value['wording'] } : {}),\n ...(isLayout(value['layout']) ? { layout: value['layout'] } : {}),\n ...(Array.isArray(value['videos']) ? { videos: (value['videos'] as unknown[]).map(videoOf) } : {}),\n }\n}\n\n/**\n * A video as the read keeps it (AGL-4140), read defensively: every address\n * held to http(s), every fact to its kind. One that is no object keeps its\n * place in the list, so the layout's indexes still name the right one.\n */\nfunction videoOf(entry: unknown): SiteImportVideo {\n const video = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {}\n const address = (value: unknown): string | undefined => (typeof value === 'string' && /^https?:\\/\\//i.test(value.trim()) ? value.trim().slice(0, 2048) : undefined)\n const words = (value: unknown, max: number): string | undefined => (typeof value === 'string' && value.trim() ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : undefined)\n const src = address(video['src'])\n const embed = address(video['embed'])\n const poster = address(video['poster'])\n const description = words(video['description'], 2_000)\n const uploadDate = typeof video['uploadDate'] === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(video['uploadDate']) ? video['uploadDate'] : undefined\n const seconds = Number(video['durationSeconds'])\n const flag = (key: 'autoplay' | 'muted' | 'loop' | 'controls') => (video[key] === true ? { [key]: true as const } : {})\n return {\n ...(src ? { src } : {}),\n ...(embed ? { embed } : {}),\n ...(poster ? { poster } : {}),\n title: words(video['title'], 200) ?? '',\n ...(description ? { description } : {}),\n ...(uploadDate ? { uploadDate } : {}),\n ...(Number.isFinite(seconds) && seconds > 0 ? { durationSeconds: Math.round(seconds) } : {}),\n ...flag('autoplay'),\n ...flag('muted'),\n ...flag('loop'),\n ...flag('controls'),\n }\n}\n\n/** Whether a value is a layout as the reader writes one: its sections, icons and look. */\nfunction isLayout(value: unknown): value is SiteImportLayout {\n if (!value || typeof value !== 'object') return false\n const layout = value as Record<string, unknown>\n return (\n layout['v'] === 1 &&\n Array.isArray(layout['sections']) &&\n (layout['sections'] as unknown[]).every((section) => !!section && typeof section === 'object' && Array.isArray((section as Record<string, unknown>)['nodes'])) &&\n Array.isArray(layout['icons'])\n )\n}\n\n/*------------------------------------------\n * Words in parts a text element holds\n *-----------------------------------------*/\n\n/** A paragraph cut between sentences into parts a text element holds, every word kept in order. */\nexport function aiSiteImportTextParts(text: string, max = AI_SITE_IMPORT_TEXT_MAX_CHARS): string[] {\n const words = clean(text)\n if (words.length <= max) return words ? [words] : []\n const sentences = words.match(/[^.!?…]+(?:[.!?…]+[\"'”’)\\]]*\\s*|$)/g) ?? [words]\n const parts: string[] = []\n let part = ''\n const push = () => {\n if (part.trim()) parts.push(part.trim())\n part = ''\n }\n for (const sentence of sentences) {\n if ((part + sentence).trim().length <= max) {\n part += sentence\n continue\n }\n push()\n // One sentence longer than an element holds is cut between words.\n let rest = sentence.trim()\n while (rest.length > max) {\n const at = rest.lastIndexOf(' ', max)\n const cut = at > 0 ? at : max\n parts.push(rest.slice(0, cut).trim())\n rest = rest.slice(cut).trim()\n }\n part = rest ? `${rest} ` : ''\n }\n push()\n return parts\n}\n"],"names":["AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","siteImportLabel","AI_TEXT_LIMITS","AI_LAYOUT_IMPORTED_SECTIONS_INPUT","AI_SITE_IMPORT_TEXT_MAX_CHARS","body","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","headline","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_DOC_MAX_NODES","AI_SITE_IMPORT_DOC_MAX_CHARS","clean","text","String","replace","trim","isLine","block","kind","url","inline","aiSiteImportDocLines","blocks","title","lines","sections","current","starts","level","length","name","push","n","section","named","Set","forEach","index","heading","map","find","unique","attempt","has","toLowerCase","slice","add","aiSiteImportLineText","line","alt","aiSiteImportWordsIn","match","aiSiteImportDocumentOf","inputs","raw","value","build","Array","isArray","flatMap","entry","region","Number","isInteger","href","strings","list","filter","size","isFinite","Math","round","photos","photo","mediaId","src","width","height","from","links","link","path","id","origins","finish","wording","isLayout","layout","videos","videoOf","words","video","address","test","undefined","max","embed","poster","description","uploadDate","seconds","flag","key","durationSeconds","every","aiSiteImportTextParts","sentences","parts","part","sentence","rest","at","lastIndexOf","cut"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C,GAG3C,SACEA,8BAA8B,EAC9BC,2BAA2B,QAMtB,6BAAyB;AAEhC,SAASC,eAAe,QAAQ,qCAAiC;AACjE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,2GAA2G,GAC3G,OAAO,MAAMC,oCAAoC,mBAAkB;AAgCnE,oFAAoF,GACpF,OAAO,MAAMC,gCAAgCF,eAAeG,IAAI,CAAA;AAEhE,+GAA+G,GAC/G,OAAO,MAAMC,oCAAoCJ,eAAeK,QAAQ,CAAA;AAExE,iGAAiG,GACjG,OAAO,MAAMC,6BAA6B,GAAE;AAE5C;;;;CAIC,GACD,OAAO,MAAMC,+BAA+B,KAAK;AACjD,OAAO,MAAMC,+BAA+B,OAAO;AAsBnD,MAAMC,QAAQ,CAACC,OAAiBC,O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AY,YAAYwB,MAAMC,OAAO,CAAC,AAACzB,OAAmC,CAAC,QAAQ,MAC5JwB,MAAMC,OAAO,CAAC6B,MAAM,CAAC,QAAQ;AAEjC;AAEA;;2CAE2C,GAE3C,iGAAiG,GACjG,OAAO,SAASkB,sBAAsB7F,IAAY,EAAEmF,MAAM3F,6BAA6B;QAGnEsF;IAFlB,MAAMA,QAAQ/E,MAAMC;IACpB,IAAI8E,MAAM7D,MAAM,IAAIkE,KAAK,OAAOL,QAAQ;QAACA;KAAM,GAAG,EAAE;IACpD,MAAMgB,aAAYhB,eAAAA,MAAMvC,KAAK,CAAC,kDAAZuC,eAAsD;QAACA;KAAM;IAC/E,MAAMiB,QAAkB,EAAE;IAC1B,IAAIC,OAAO;IACX,MAAM7E,OAAO;QACX,IAAI6E,KAAK7F,IAAI,IAAI4F,MAAM5E,IAAI,CAAC6E,KAAK7F,IAAI;QACrC6F,OAAO;IACT;IACA,KAAK,MAAMC,YAAYH,UAAW;QAChC,IAAI,AAACE,CAAAA,OAAOC,QAAO,EAAG9F,IAAI,GAAGc,MAAM,IAAIkE,KAAK;YAC1Ca,QAAQC;YACR;QACF;QACA9E;QACA,kEAAkE;QAClE,IAAI+E,OAAOD,SAAS9F,IAAI;QACxB,MAAO+F,KAAKjF,MAAM,GAAGkE,IAAK;YACxB,MAAMgB,KAAKD,KAAKE,WAAW,CAAC,KAAKjB;YACjC,MAAMkB,MAAMF,KAAK,IAAIA,KAAKhB;YAC1BY,MAAM5E,IAAI,CAAC+E,KAAKjE,KAAK,CAAC,GAAGoE,KAAKlG,IAAI;YAClC+F,OAAOA,KAAKjE,KAAK,CAACoE,KAAKlG,IAAI;QAC7B;QACA6F,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACA/E;IACA,OAAO4E;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-document.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PAGE BROUGHT IN WORD FOR WORD (AGL-4084, AGL-4107).\n *\n * An imported page is never rewritten. Its words are the source's, as the\n * crawler read them (`AiSiteImportPageRead.blocks`), and how the source lays\n * them out is the reader's (`AiSiteImportPageRead.layout`, AGL-4106). This\n * module is the page as its job carries it: its blocks, its layout, its\n * photos and where its links go, read defensively off the job's inputs.\n *\n * - **Lines.** The page's main region, numbered: every heading, paragraph,\n * list item, quote, link and picture in source order. A link inside a\n * sentence is in its sentence already and is no line of its own.\n * - **Sections.** Where a read kept no layout (one made before the reader,\n * or one past its budget), one for the page's opening and one at each\n * second-level heading, as the source divides itself.\n *\n * The page is drawn by the site compiler (`ai-site-import-compile.ts`), with\n * every line on it exactly once and never a word that is not the source's.\n *=========================================*/\n\n\nimport {\n AI_SITE_IMPORT_LABEL_MAX_CHARS,\n AI_SITE_IMPORT_MAX_SECTIONS,\n type AiSiteImportBuild,\n type AiSiteImportFinish,\n type AiSiteImportPageRole,\n type AiSiteImportPhoto,\n type AiSiteImportPlan,\n type AiSiteImportWords,\n type SiteImportLayout,\n} from '../model/ai-site-import'\nimport type { SiteImportBlock, SiteImportVideo } from '../site-import/site-import-html'\nimport { siteImportLabel } from '../site-import/site-import-page'\nimport { AI_TEXT_LIMITS } from '../runtime/ai-palette'\n\n/** The unit input carrying a page brought in word for word: its lines, its photos and where its links go. */\nexport const AI_LAYOUT_IMPORTED_SECTIONS_INPUT = 'importedSections'\n\n/** A page brought in, as the import step hands it to the page step. Untrusted data from the owner's site. */\nexport interface AiSiteImportDocument {\n build: AiSiteImportBuild\n /** The page's name on the new site: its h1 where the source shows no heading. */\n title: string\n /** Where the page is on the owner's website. */\n url: string\n /** The page's main region, in order. */\n blocks: SiteImportBlock[]\n /** Its photos as the library holds them, each by the source address it was read from. */\n photos: AiSiteImportPhoto[]\n /** The site's own pages a link may go to: the source path each was read from, and the page it is now. */\n links: Array<{ path: string; id: string }>\n /** The origins the old site answers on: a link to one of them is to a page of its own. */\n origins: string[]\n /**\n * How the source lays the page out (AGL-4106), over `blocks` by index;\n * absent on a read made before the reader, or one past its budget.\n */\n layout?: SiteImportLayout | null\n /** How the page's wave finishes it (AGL-4152); absent is `keep`. */\n finish?: AiSiteImportFinish | null\n /** Whether its words are improved (AGL-4152); absent is kept as written. */\n wording?: AiSiteImportWords | null\n /** Each form of the read, by its index, and the saved form that takes its place (AGL-4083); absent on a page that asked for none. */\n forms?: Array<{ index: number; formId: string | null }> | null\n /** The page's videos (AGL-4140), which its layout places by index; absent on a page that shows none. */\n videos?: SiteImportVideo[]\n /** Redesigned from its ledger (AGL-4152): its wave was stamped generative. Absent, today's Improve it. */\n generative?: true\n /** What the site says of itself, the same bytes on every page of an import: a redesign's cached digest (AGL-4152). */\n siteLines?: string[]\n /** The lines of the wave's other pages, which a redesign's facts may come from (AGL-4152). */\n scope?: string[]\n /** The site's plan, once a wave has one (AGL-4152). */\n plan?: AiSiteImportPlan | null\n /** The theme's colors as its look drew them, where one was drawn (`SiteImportFidelityTheme`, AGL-4152). */\n theme?: Record<string, unknown> | null\n /** The plan's proposed page (AGL-4152): new to the site, with no source to hold it to, and never kept as a fallback. */\n proposed?: true\n /** What the page is for in the planned site (AGL-4152), as its plan says; absent, read from its address and what it holds. */\n role?: AiSiteImportPageRole\n /** Source photos of the site's earlier pages that none of them placed, for a slot of this one (AGL-4152). */\n sitePhotos?: AiSiteImportPhoto[]\n /** A slot nothing else fills may take a generated picture: its owner said so, and it is quoted (AGL-4152). */\n generatedPictures?: true\n /**\n * Its wave was stamped with `release_video_embed_posters` (AGL-4140): a\n * YouTube film whose poster the library could not hold is placed with no\n * poster, and the published page draws YouTube's own still for it.\n */\n videoPosters?: true\n}\n\n/** The most characters a text element holds (the palette's ceiling for body copy). */\nexport const AI_SITE_IMPORT_TEXT_MAX_CHARS = AI_TEXT_LIMITS.body\n\n/** The most characters a heading style holds; a longer heading is drawn in a subtitle style, still a heading. */\nexport const AI_SITE_IMPORT_HEADLINE_MAX_CHARS = AI_TEXT_LIMITS.headline\n\n/** The most characters a button's label holds; a longer link keeps its words as a line of text. */\nexport const AI_SITE_IMPORT_LABEL_CHARS = 40\n\n/**\n * What one page may weigh, inside the budget of a page of its owner's own\n * words (`AI_OWN_WORDS_PAGE_BUDGET`): a page that would run past it ends at\n * the section before, marked `cut`.\n */\nexport const AI_SITE_IMPORT_DOC_MAX_NODES = 1_400\nexport const AI_SITE_IMPORT_DOC_MAX_CHARS = 200_000\n\n/** One numbered line of a page. */\nexport interface AiSiteImportLine {\n /** 1-based, in source order. */\n n: number\n block: SiteImportBlock\n /** The section it belongs to, by plan index. */\n section: number\n}\n\nexport interface AiSiteImportDocSection {\n name: string\n /** Its lines' numbers, in order. */\n lines: number[]\n}\n\nexport interface AiSiteImportDocLines {\n lines: AiSiteImportLine[]\n sections: AiSiteImportDocSection[]\n}\n\nconst clean = (text: string) => String(text ?? '').replace(/\\s+/g, ' ').trim()\n\n/** Whether a block is a line of its own: a link inside a sentence is in its sentence already. */\nfunction isLine(block: SiteImportBlock): boolean {\n if (block.kind === 'image') return !!block.url\n if (block.kind === 'link') return !block.inline && !!clean(block.text)\n return !!clean(block.text)\n}\n\n/**\n * The page's lines and sections (AGL-4084): the opening, then one section\n * at each second-level heading, at most `AI_SITE_IMPORT_MAX_SECTIONS` (the\n * last holds whatever follows). A page that opens on a second-level heading\n * opens with it. Section names are the headings' words, neutralized and cut\n * to a label, since they travel outside a fence.\n */\nexport function aiSiteImportDocLines(blocks: readonly SiteImportBlock[], title: string): AiSiteImportDocLines {\n const lines: AiSiteImportLine[] = []\n const sections: AiSiteImportDocSection[] = []\n let current: AiSiteImportDocSection | null = null\n for (const block of blocks) {\n if (!isLine(block)) continue\n const starts = block.kind === 'heading' && block.level === 2 && sections.length < AI_SITE_IMPORT_MAX_SECTIONS\n if (!current || (starts && current.lines.length > 0)) {\n current = { name: '', lines: [] }\n sections.push(current)\n }\n const n = lines.length + 1\n lines.push({ n, block, section: sections.length - 1 })\n current.lines.push(n)\n }\n const named = new Set<string>()\n sections.forEach((section, index) => {\n const heading = section.lines.map((n) => lines[n - 1].block).find((block) => block.kind === 'heading')\n let name = siteImportLabel(heading && heading.kind === 'heading' ? heading.text : index === 0 ? title : '') || (index === 0 ? siteImportLabel(title) : '')\n if (!name) name = `Section ${index + 1}`\n // Two sections of one name are told apart, so a link to either finds it.\n let unique = name\n for (let attempt = 2; named.has(unique.toLowerCase()); attempt += 1) {\n unique = `${name.slice(0, AI_SITE_IMPORT_LABEL_MAX_CHARS - 4)} (${attempt})`\n }\n named.add(unique.toLowerCase())\n section.name = unique\n })\n if (!sections.length) sections.push({ name: siteImportLabel(title) || 'Introduction', lines: [] })\n return { lines, sections }\n}\n\n/** The words a line shows: an image's are its description. */\nexport function aiSiteImportLineText(line: Pick<AiSiteImportLine, 'block'>): string {\n return line.block.kind === 'image' ? clean(line.block.alt) : clean(line.block.text)\n}\n\n/** How many words a line says: its runs of letters and digits, as the review counts them. */\nexport const aiSiteImportWordsIn = (text: string): number => (text.match(/[\\p{L}\\p{N}]+/gu) ?? []).length\n\n/** The input a page job carries, read defensively; `null` on every other job. */\nexport function aiSiteImportDocumentOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiSiteImportDocument | null {\n const raw = inputs?.[AI_LAYOUT_IMPORTED_SECTIONS_INPUT]\n if (!raw || typeof raw !== 'object') return null\n const value = raw as Record<string, unknown>\n const build = value['build'] === 'copied' || value['build'] === 'arranged' ? value['build'] : null\n if (!build || !Array.isArray(value['blocks'])) return null\n const blocks = (value['blocks'] as unknown[]).flatMap((entry): SiteImportBlock[] => {\n if (!entry || typeof entry !== 'object') return []\n const block = entry as Record<string, unknown>\n const text = typeof block['text'] === 'string' ? block['text'] : ''\n const region = 'main' as const\n switch (block['kind']) {\n case 'heading': {\n const level = Number(block['level'])\n return [{ kind: 'heading', level: (Number.isInteger(level) && level >= 1 && level <= 6 ? level : 2) as 1 | 2 | 3 | 4 | 5 | 6, text, region }]\n }\n case 'paragraph':\n case 'list-item':\n case 'quote':\n return [{ kind: block['kind'], text, region }]\n case 'image':\n return typeof block['url'] === 'string' ? [{ kind: 'image', url: block['url'], alt: typeof block['alt'] === 'string' ? block['alt'] : '', region }] : []\n case 'link':\n return typeof block['href'] === 'string'\n ? [{ kind: 'link', text, href: block['href'], region, ...(block['inline'] === true ? { inline: true as const } : {}) }]\n : []\n default:\n return []\n }\n })\n const strings = (list: unknown) => (Array.isArray(list) ? list.filter((entry): entry is string => typeof entry === 'string') : [])\n const size = (value: unknown) => (typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.round(value) : 0)\n const photosOf = (list: unknown) =>\n (Array.isArray(list) ? list : []).flatMap((entry): AiSiteImportPhoto[] => {\n const photo = entry as Record<string, unknown> | null\n return photo && typeof photo['mediaId'] === 'string' && typeof photo['src'] === 'string'\n ? [\n {\n mediaId: photo['mediaId'],\n src: photo['src'],\n // Its size, which frames it at its own shape where the source's tag gives none (AGL-4138).\n ...(size(photo['width']) ? { width: size(photo['width']) } : {}),\n ...(size(photo['height']) ? { height: size(photo['height']) } : {}),\n ...(typeof photo['alt'] === 'string' ? { alt: photo['alt'] } : {}),\n ...(typeof photo['from'] === 'string' ? { from: photo['from'] } : {}),\n },\n ]\n : []\n })\n return {\n build,\n title: typeof value['title'] === 'string' ? value['title'] : '',\n url: typeof value['url'] === 'string' ? value['url'].slice(0, 2048) : '',\n blocks,\n photos: photosOf(value['photos']),\n links: (Array.isArray(value['links']) ? value['links'] : []).flatMap((entry) => {\n const link = entry as Record<string, unknown> | null\n return link && typeof link['path'] === 'string' && typeof link['id'] === 'string' ? [{ path: link['path'], id: link['id'] }] : []\n }),\n origins: strings(value['origins']),\n // How the page's wave finishes it and whether its words are improved (AGL-4152); anything else is absent: kept.\n ...(value['finish'] === 'keep' || value['finish'] === 'improve' ? { finish: value['finish'] } : {}),\n ...(value['wording'] === 'kept' || value['wording'] === 'improved' ? { wording: value['wording'] } : {}),\n ...(value['generative'] === true ? { generative: true as const } : {}),\n ...(Array.isArray(value['siteLines']) ? { siteLines: strings(value['siteLines']) } : {}),\n ...(Array.isArray(value['scope']) ? { scope: strings(value['scope']) } : {}),\n ...(value['plan'] && typeof value['plan'] === 'object' ? { plan: value['plan'] as AiSiteImportPlan } : {}),\n ...(value['theme'] && typeof value['theme'] === 'object' ? { theme: value['theme'] as Record<string, unknown> } : {}),\n ...(value['proposed'] === true ? { proposed: true as const } : {}),\n ...(Array.isArray(value['sitePhotos']) ? { sitePhotos: photosOf(value['sitePhotos']) } : {}),\n ...(value['generatedPictures'] === true ? { generatedPictures: true as const } : {}),\n ...(value['videoPosters'] === true ? { videoPosters: true as const } : {}),\n ...(isLayout(value['layout']) ? { layout: value['layout'] } : {}),\n ...(Array.isArray(value['videos']) ? { videos: (value['videos'] as unknown[]).map(videoOf) } : {}),\n }\n}\n\n/**\n * A video as the read keeps it (AGL-4140), read defensively: every address\n * held to http(s), every fact to its kind. One that is no object keeps its\n * place in the list, so the layout's indexes still name the right one.\n */\nfunction videoOf(entry: unknown): SiteImportVideo {\n const video = entry && typeof entry === 'object' ? (entry as Record<string, unknown>) : {}\n const address = (value: unknown): string | undefined => (typeof value === 'string' && /^https?:\\/\\//i.test(value.trim()) ? value.trim().slice(0, 2048) : undefined)\n const words = (value: unknown, max: number): string | undefined => (typeof value === 'string' && value.trim() ? value.replace(/\\s+/g, ' ').trim().slice(0, max) : undefined)\n const src = address(video['src'])\n const embed = address(video['embed'])\n const poster = address(video['poster'])\n const description = words(video['description'], 2_000)\n const uploadDate = typeof video['uploadDate'] === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(video['uploadDate']) ? video['uploadDate'] : undefined\n const seconds = Number(video['durationSeconds'])\n const flag = (key: 'autoplay' | 'muted' | 'loop' | 'controls') => (video[key] === true ? { [key]: true as const } : {})\n return {\n ...(src ? { src } : {}),\n ...(embed ? { embed } : {}),\n ...(poster ? { poster } : {}),\n title: words(video['title'], 200) ?? '',\n ...(description ? { description } : {}),\n ...(uploadDate ? { uploadDate } : {}),\n ...(Number.isFinite(seconds) && seconds > 0 ? { durationSeconds: Math.round(seconds) } : {}),\n ...flag('autoplay'),\n ...flag('muted'),\n ...flag('loop'),\n ...flag('controls'),\n }\n}\n\n/** Whether a value is a layout as the reader writes one: its sections, icons and look. */\nfunction isLayout(value: unknown): value is SiteImportLayout {\n if (!value || typeof value !== 'object') return false\n const layout = value as Record<string, unknown>\n return (\n layout['v'] === 1 &&\n Array.isArray(layout['sections']) &&\n (layout['sections'] as unknown[]).every((section) => !!section && typeof section === 'object' && Array.isArray((section as Record<string, unknown>)['nodes'])) &&\n Array.isArray(layout['icons'])\n )\n}\n\n/*------------------------------------------\n * Words in parts a text element holds\n *-----------------------------------------*/\n\n/** A paragraph cut between sentences into parts a text element holds, every word kept in order. */\nexport function aiSiteImportTextParts(text: string, max = AI_SITE_IMPORT_TEXT_MAX_CHARS): string[] {\n const words = clean(text)\n if (words.length <= max) return words ? [words] : []\n const sentences = words.match(/[^.!?…]+(?:[.!?…]+[\"'”’)\\]]*\\s*|$)/g) ?? [words]\n const parts: string[] = []\n let part = ''\n const push = () => {\n if (part.trim()) parts.push(part.trim())\n part = ''\n }\n for (const sentence of sentences) {\n if ((part + sentence).trim().length <= max) {\n part += sentence\n continue\n }\n push()\n // One sentence longer than an element holds is cut between words.\n let rest = sentence.trim()\n while (rest.length > max) {\n const at = rest.lastIndexOf(' ', max)\n const cut = at > 0 ? at : max\n parts.push(rest.slice(0, cut).trim())\n rest = rest.slice(cut).trim()\n }\n part = rest ? `${rest} ` : ''\n }\n push()\n return parts\n}\n"],"names":["AI_SITE_IMPORT_LABEL_MAX_CHARS","AI_SITE_IMPORT_MAX_SECTIONS","siteImportLabel","AI_TEXT_LIMITS","AI_LAYOUT_IMPORTED_SECTIONS_INPUT","AI_SITE_IMPORT_TEXT_MAX_CHARS","body","AI_SITE_IMPORT_HEADLINE_MAX_CHARS","headline","AI_SITE_IMPORT_LABEL_CHARS","AI_SITE_IMPORT_DOC_MAX_NODES","AI_SITE_IMPORT_DOC_MAX_CHARS","clean","text","String","replace","trim","isLine","block","kind","url","inline","aiSiteImportDocLines","blocks","title","lines","sections","current","starts","level","length","name","push","n","section","named","Set","forEach","index","heading","map","find","unique","attempt","has","toLowerCase","slice","add","aiSiteImportLineText","line","alt","aiSiteImportWordsIn","match","aiSiteImportDocumentOf","inputs","raw","value","build","Array","isArray","flatMap","entry","region","Number","isInteger","href","strings","list","filter","size","isFinite","Math","round","photosOf","photo","mediaId","src","width","height","from","photos","links","link","path","id","origins","finish","wording","generative","siteLines","scope","plan","theme","proposed","sitePhotos","generatedPictures","videoPosters","isLayout","layout","videos","videoOf","words","video","address","test","undefined","max","embed","poster","description","uploadDate","seconds","flag","key","durationSeconds","every","aiSiteImportTextParts","sentences","parts","part","sentence","rest","at","lastIndexOf","cut"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C,GAG3C,SACEA,8BAA8B,EAC9BC,2BAA2B,QAQtB,6BAAyB;AAEhC,SAASC,eAAe,QAAQ,qCAAiC;AACjE,SAASC,cAAc,QAAQ,2BAAuB;AAEtD,2GAA2G,GAC3G,OAAO,MAAMC,oCAAoC,mBAAkB;AAwDnE,oFAAoF,GACpF,OAAO,MAAMC,gCAAgCF,eAAeG,IAAI,CAAA;AAEhE,+GAA+G,GAC/G,OAAO,MAAMC,oCAAoCJ,eAAeK,QAAQ,CAAA;AAExE,iGAAiG,GACjG,OAAO,MAAMC,6BAA6B,GAAE;AAE5C;;;;CAIC,GACD,OAAO,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,MAAMC;IACpB,IAAIwF,MAAMvE,MAAM,IAAI4E,KAAK,OAAOL,QAAQ;QAACA;KAAM,GAAG,EAAE;IACpD,MAAMgB,aAAYhB,eAAAA,MAAMjD,KAAK,CAAC,kDAAZiD,eAAsD;QAACA;KAAM;IAC/E,MAAMiB,QAAkB,EAAE;IAC1B,IAAIC,OAAO;IACX,MAAMvF,OAAO;QACX,IAAIuF,KAAKvG,IAAI,IAAIsG,MAAMtF,IAAI,CAACuF,KAAKvG,IAAI;QACrCuG,OAAO;IACT;IACA,KAAK,MAAMC,YAAYH,UAAW;QAChC,IAAI,AAACE,CAAAA,OAAOC,QAAO,EAAGxG,IAAI,GAAGc,MAAM,IAAI4E,KAAK;YAC1Ca,QAAQC;YACR;QACF;QACAxF;QACA,kEAAkE;QAClE,IAAIyF,OAAOD,SAASxG,IAAI;QACxB,MAAOyG,KAAK3F,MAAM,GAAG4E,IAAK;YACxB,MAAMgB,KAAKD,KAAKE,WAAW,CAAC,KAAKjB;YACjC,MAAMkB,MAAMF,KAAK,IAAIA,KAAKhB;YAC1BY,MAAMtF,IAAI,CAACyF,KAAK3E,KAAK,CAAC,GAAG8E,KAAK5G,IAAI;YAClCyG,OAAOA,KAAK3E,KAAK,CAAC8E,KAAK5G,IAAI;QAC7B;QACAuG,OAAOE,OAAO,GAAGA,KAAK,CAAC,CAAC,GAAG;IAC7B;IACAzF;IACA,OAAOsF;AACT"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { AiLayoutBlock } from '../layout-language/ai-layout-language';
|
|
18
|
+
import { type SiteImportFactScope } from '../model/ai-site-import-fidelity';
|
|
19
|
+
import type { SiteImportLedger } from '../model/ai-site-import-ledger';
|
|
20
|
+
import { type AiCopyFraming, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators';
|
|
21
|
+
export declare const AI_SITE_IMPORT_INVENTED_FACT_CODE = "improve-invented-fact";
|
|
22
|
+
export declare const AI_SITE_IMPORT_DROPPED_ITEM_CODE = "improve-dropped-item";
|
|
23
|
+
/** A block a redesign answered: the layout language, or a `keep` of a ledger ref. */
|
|
24
|
+
export type AiSiteImportImprovedBlock = AiLayoutBlock | {
|
|
25
|
+
kind: 'keep';
|
|
26
|
+
ref: string;
|
|
27
|
+
col?: number;
|
|
28
|
+
};
|
|
29
|
+
/** A section a redesign answered. */
|
|
30
|
+
export interface AiSiteImportImprovedSection {
|
|
31
|
+
band?: 'plain' | 'soft' | 'brand' | 'dark';
|
|
32
|
+
cols?: number[];
|
|
33
|
+
align?: 'start' | 'center';
|
|
34
|
+
blocks: AiSiteImportImprovedBlock[];
|
|
35
|
+
}
|
|
36
|
+
/** What a redesign's copy is held against. */
|
|
37
|
+
export interface AiSiteImportHonestyScope {
|
|
38
|
+
ledger: SiteImportLedger;
|
|
39
|
+
/** Every line the import read: this page's, the wave's other pages', and what the home page says of the site. */
|
|
40
|
+
scope: readonly string[];
|
|
41
|
+
/** Where a link may go, as an answer writes it, and the ledger's links' own destinations. */
|
|
42
|
+
destinations: ReadonlyMap<string, string>;
|
|
43
|
+
framing?: AiCopyFraming | null;
|
|
44
|
+
}
|
|
45
|
+
/** Whether text is in the source's own words: its fact tokens, and whatever a scope says of it. */
|
|
46
|
+
export interface AiSiteImportHonestyFacts {
|
|
47
|
+
facts: SiteImportFactScope;
|
|
48
|
+
tokens: ReadonlySet<string>;
|
|
49
|
+
/** The source's words, as one text, for what a claim is checked against. */
|
|
50
|
+
said: string;
|
|
51
|
+
}
|
|
52
|
+
/** What every line of an answer is checked against. */
|
|
53
|
+
export declare function aiSiteImportHonestyFacts(scope: readonly string[]): AiSiteImportHonestyFacts;
|
|
54
|
+
/** What one line of new copy says that the source does not: a reason in words, or `null`. */
|
|
55
|
+
export declare function aiSiteImportInventedIn(text: string, held: AiSiteImportHonestyFacts): string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Every ledger ref an answer places, as often as it places it: each `keep`,
|
|
58
|
+
* each picture on an item, and what a group kept whole holds (AGL-4152).
|
|
59
|
+
*/
|
|
60
|
+
export declare function aiSiteImportImprovedPlaced(sections: readonly AiSiteImportImprovedSection[], ledger: Pick<SiteImportLedger, 'items'>): string[];
|
|
61
|
+
/**
|
|
62
|
+
* An answer held to what the import read, and to its ledger (AGL-4152). No
|
|
63
|
+
* violation is a redesign that may be built; each one names its line.
|
|
64
|
+
*/
|
|
65
|
+
export declare function aiSiteImportHonesty(sections: readonly AiSiteImportImprovedSection[], input: AiSiteImportHonestyScope): AiDoctrineViolation[];
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ /*==========================================
|
|
18
|
+
* NEW COPY MAY SAY WHAT THE SOURCE SUPPORTS, AND NOTHING IT DOES NOT (AGL-4152).
|
|
19
|
+
*
|
|
20
|
+
* A redesign may describe what the source says and what this kind of business
|
|
21
|
+
* generally does. It may not make up a name, number, price, date, testimonial,
|
|
22
|
+
* client, award, credential, address or guarantee, and it may not lose what
|
|
23
|
+
* the ledger holds. This is the gate, pure, one answer at a time:
|
|
24
|
+
*
|
|
25
|
+
* - `improve-invented-fact`: a word of its copy says a fact, a name, a
|
|
26
|
+
* credential or a guarantee outside what the import read, or a link goes
|
|
27
|
+
* somewhere the source does not.
|
|
28
|
+
* - `improve-dropped-item`: something the ledger holds is not on the page, or
|
|
29
|
+
* is on it twice.
|
|
30
|
+
*
|
|
31
|
+
* Each names the line, so the one re-ask can mend that line.
|
|
32
|
+
*=========================================*/ import { aiLayoutGuardContacts } from "../layout-language/ai-layout-copy.js";
|
|
33
|
+
import { siteImportFactScope, siteImportFactTokens } from "../model/ai-site-import-fidelity.js";
|
|
34
|
+
import { detectOffVoiceCopy } from "../runtime/ai-doctrine-validators.js";
|
|
35
|
+
import { aiPlaceholderTokens } from "../runtime/ai-placeholder-tokens.js";
|
|
36
|
+
export const AI_SITE_IMPORT_INVENTED_FACT_CODE = 'improve-invented-fact';
|
|
37
|
+
export const AI_SITE_IMPORT_DROPPED_ITEM_CODE = 'improve-dropped-item';
|
|
38
|
+
/** Words past a sentence's first that are no one's name, in any heading: the short form of a question list. */ const NO_NAMES = new Set([
|
|
39
|
+
'FAQ',
|
|
40
|
+
'FAQs',
|
|
41
|
+
'I'
|
|
42
|
+
]);
|
|
43
|
+
/**
|
|
44
|
+
* Credentials and guarantees: outside what the source says, each is a claim
|
|
45
|
+
* only its owner can make, however a sentence puts it.
|
|
46
|
+
*/ const CLAIMS = [
|
|
47
|
+
[
|
|
48
|
+
'licensed',
|
|
49
|
+
/\blicen[sc]ed\b/i
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
'certified',
|
|
53
|
+
/\b(?:board-)?certified\b/i
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
'accredited',
|
|
57
|
+
/\baccredited\b/i
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
'insured',
|
|
61
|
+
/\binsured\b/i
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
'bonded',
|
|
65
|
+
/\bbonded\b/i
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
'award',
|
|
69
|
+
/\baward(?:s|-winning)?\b/i
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
'guarantee',
|
|
73
|
+
/\bguarantee[ds]?\b/i
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
'warranty',
|
|
77
|
+
/\bwarrant(?:y|ies)\b/i
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
'money-back',
|
|
81
|
+
/\bmoney[- ]back\b/i
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
'top-rated',
|
|
85
|
+
/\btop[- ]rated\b/i
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
'five-star',
|
|
89
|
+
/\b(?:5|five)[- ]star\b/i
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
'voted',
|
|
93
|
+
/\bvoted\b/i
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'featured in',
|
|
97
|
+
/\bfeatured in\b/i
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
'trusted by',
|
|
101
|
+
/\btrusted by\b/i
|
|
102
|
+
]
|
|
103
|
+
];
|
|
104
|
+
/** A count no digit says: "hundreds of clients", "two decades", "ten years". */ const COUNTS = [
|
|
105
|
+
/\b(?:hundreds|thousands|millions|dozens|decades?|centur(?:y|ies))\b/i,
|
|
106
|
+
/\b(?:two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|fifteen|twenty|thirty|forty|fifty)\s+(?:years?|clients?|customers?|families|projects?|homes?|offices?|locations?|reviews?|stars?)\b/i
|
|
107
|
+
];
|
|
108
|
+
/** A word that opens a line in quotation marks and runs on: a testimonial, whoever is made to say it. */ const QUOTED = /^["“”'‘][^"“”]{15,}["“”]/;
|
|
109
|
+
/** What every line of an answer is checked against. */ export function aiSiteImportHonestyFacts(scope) {
|
|
110
|
+
const facts = siteImportFactScope(scope);
|
|
111
|
+
return {
|
|
112
|
+
facts,
|
|
113
|
+
tokens: new Set(scope.flatMap((text)=>siteImportFactTokens(text, facts, false))),
|
|
114
|
+
said: scope.join(' \n ')
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const shown = (token)=>`"${token.replace(/^[a-z]+:/, '')}"`;
|
|
118
|
+
/** What one line of new copy says that the source does not: a reason in words, or `null`. */ export function aiSiteImportInventedIn(text, held) {
|
|
119
|
+
const invented = siteImportFactTokens(text, held.facts, true).filter((token)=>!held.tokens.has(token) && !(token.startsWith('name:') && NO_NAMES.has(token.slice(5))));
|
|
120
|
+
if (invented.length) return `it says ${[
|
|
121
|
+
...new Set(invented)
|
|
122
|
+
].map(shown).join(', ')}, which nothing the site says supports. Say only names and figures the site gives; a heading is in sentence case, so a capital reads as a name.`;
|
|
123
|
+
for (const [claim, pattern] of CLAIMS){
|
|
124
|
+
if (pattern.test(text) && !pattern.test(held.said)) return `it claims ${shown(claim)}, which the site does not. Leave credentials, awards and guarantees to the owner.`;
|
|
125
|
+
}
|
|
126
|
+
for (const pattern of COUNTS){
|
|
127
|
+
var _pattern_exec;
|
|
128
|
+
const found = (_pattern_exec = pattern.exec(text)) == null ? void 0 : _pattern_exec[0];
|
|
129
|
+
if (found && !new RegExp(`\\b${found.replace(/\s+/g, '\\s+')}\\b`, 'i').test(held.said)) return `it says ${shown(found)}, a count the site does not give.`;
|
|
130
|
+
}
|
|
131
|
+
if (QUOTED.test(text.trim()) && !held.said.includes(text.trim().slice(1, 20))) return 'it reads as a testimonial the site does not have. Quote a customer only by keeping their quote.';
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
/** Each written line of a block, as its place on the page names it. */ function writtenLines(block, at) {
|
|
135
|
+
var _block_items;
|
|
136
|
+
const out = [];
|
|
137
|
+
if (block.text && block.kind !== 'image') out.push({
|
|
138
|
+
at,
|
|
139
|
+
text: block.text
|
|
140
|
+
});
|
|
141
|
+
((_block_items = block.items) != null ? _block_items : []).forEach((item, index)=>{
|
|
142
|
+
if (item.title.trim()) out.push({
|
|
143
|
+
at: `${at}, item ${index + 1}`,
|
|
144
|
+
text: item.title
|
|
145
|
+
});
|
|
146
|
+
if (item.text.trim()) out.push({
|
|
147
|
+
at: `${at}, item ${index + 1}`,
|
|
148
|
+
text: item.text
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
/** Where a block sends a visitor, its own and its items'. */ const linksOf = (block)=>{
|
|
154
|
+
var _block_items;
|
|
155
|
+
return [
|
|
156
|
+
...block.to ? [
|
|
157
|
+
block.to
|
|
158
|
+
] : [],
|
|
159
|
+
...((_block_items = block.items) != null ? _block_items : []).flatMap((item)=>item.to ? [
|
|
160
|
+
item.to
|
|
161
|
+
] : [])
|
|
162
|
+
];
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Every ledger ref an answer places, as often as it places it: each `keep`,
|
|
166
|
+
* each picture on an item, and what a group kept whole holds (AGL-4152).
|
|
167
|
+
*/ export function aiSiteImportImprovedPlaced(sections, ledger) {
|
|
168
|
+
const holds = new Map(ledger.items.map((item)=>{
|
|
169
|
+
var _item_holds;
|
|
170
|
+
return [
|
|
171
|
+
item.ref,
|
|
172
|
+
(_item_holds = item.holds) != null ? _item_holds : []
|
|
173
|
+
];
|
|
174
|
+
}));
|
|
175
|
+
return sections.flatMap((section)=>section.blocks.flatMap((block)=>{
|
|
176
|
+
var _holds_get, _block_items;
|
|
177
|
+
return block.kind === 'keep' ? [
|
|
178
|
+
block.ref,
|
|
179
|
+
...(_holds_get = holds.get(block.ref)) != null ? _holds_get : []
|
|
180
|
+
] : ((_block_items = block.items) != null ? _block_items : []).flatMap((item)=>item.ref ? [
|
|
181
|
+
item.ref
|
|
182
|
+
] : []);
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
const invented = (message, detail)=>_extends({
|
|
186
|
+
rule: 14,
|
|
187
|
+
code: AI_SITE_IMPORT_INVENTED_FACT_CODE,
|
|
188
|
+
message
|
|
189
|
+
}, detail ? {
|
|
190
|
+
detail
|
|
191
|
+
} : {});
|
|
192
|
+
const dropped = (message)=>({
|
|
193
|
+
rule: null,
|
|
194
|
+
code: AI_SITE_IMPORT_DROPPED_ITEM_CODE,
|
|
195
|
+
message
|
|
196
|
+
});
|
|
197
|
+
/**
|
|
198
|
+
* An answer held to what the import read, and to its ledger (AGL-4152). No
|
|
199
|
+
* violation is a redesign that may be built; each one names its line.
|
|
200
|
+
*/ export function aiSiteImportHonesty(sections, input) {
|
|
201
|
+
var _ref;
|
|
202
|
+
var _sections_;
|
|
203
|
+
const held = aiSiteImportHonestyFacts(input.scope);
|
|
204
|
+
const contacts = input.scope.join(' \n ');
|
|
205
|
+
const out = [];
|
|
206
|
+
const refs = new Map(input.ledger.items.map((item)=>[
|
|
207
|
+
item.ref,
|
|
208
|
+
item
|
|
209
|
+
]));
|
|
210
|
+
const placed = aiSiteImportImprovedPlaced(sections, input.ledger);
|
|
211
|
+
const links = new Set();
|
|
212
|
+
sections.forEach((section, index)=>{
|
|
213
|
+
section.blocks.forEach((raw, position)=>{
|
|
214
|
+
if (raw.kind === 'keep') return;
|
|
215
|
+
const block = raw;
|
|
216
|
+
const at = `section ${index + 1}, block ${position + 1}`;
|
|
217
|
+
for (const line of writtenLines(block, at)){
|
|
218
|
+
var _input_framing;
|
|
219
|
+
const reason = aiSiteImportInventedIn(line.text, held);
|
|
220
|
+
if (reason) out.push(invented(`${line.at}, "${line.text.slice(0, 80)}": ${reason}`));
|
|
221
|
+
else if (aiLayoutGuardContacts(line.text, contacts) !== line.text) out.push(invented(`${line.at}, "${line.text.slice(0, 80)}": it gives a phone number or email the site does not.`));
|
|
222
|
+
else if (/\[[^\]]*\]/.test(line.text) || aiPlaceholderTokens(line.text).length || detectOffVoiceCopy([
|
|
223
|
+
{
|
|
224
|
+
at: 'line',
|
|
225
|
+
text: line.text
|
|
226
|
+
}
|
|
227
|
+
], (_input_framing = input.framing) != null ? _input_framing : null).length) {
|
|
228
|
+
out.push(invented(`${line.at}, "${line.text.slice(0, 80)}": it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words.`));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for (const to of linksOf(block)){
|
|
232
|
+
if (input.destinations.has(to)) links.add(input.destinations.get(to));
|
|
233
|
+
else out.push(invented(`${at}: it links to "${to.slice(0, 80)}", which is not a page of this site, form, phone, email, a section as #n, or an address the source links.`));
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
// What the ledger holds: each thing that must land, once; no ref twice, and none it does not hold.
|
|
238
|
+
const inGroup = new Map(input.ledger.items.flatMap((item)=>{
|
|
239
|
+
var _item_holds;
|
|
240
|
+
return ((_item_holds = item.holds) != null ? _item_holds : []).map((held)=>[
|
|
241
|
+
held,
|
|
242
|
+
item.ref
|
|
243
|
+
]);
|
|
244
|
+
}));
|
|
245
|
+
for (const ref of new Set(placed)){
|
|
246
|
+
if (!refs.has(ref)) out.push(dropped(`keep "${ref.slice(0, 40)}" names nothing on this page. Use only the refs the page lists.`));
|
|
247
|
+
else if (placed.filter((entry)=>entry === ref).length > 1) {
|
|
248
|
+
const group = inGroup.get(ref);
|
|
249
|
+
out.push(dropped(`${ref} is placed ${placed.filter((entry)=>entry === ref).length} times${group && placed.includes(group) ? `: keeping ${group} whole places it already` : ''}. Place it once.`));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const item of input.ledger.items){
|
|
253
|
+
if (item.must && !placed.includes(item.ref)) out.push(dropped(`${item.ref} is not on the page. Place it with a keep block, exactly once${item.folded ? ': this page is long, so its groups are kept whole' : ''}.`));
|
|
254
|
+
}
|
|
255
|
+
// The page's own opening picture outranks a new one: a picture asked for in words never takes its place.
|
|
256
|
+
const opening = input.ledger.items.find((item)=>item.kind === 'picture' && item.section === 0);
|
|
257
|
+
const first = (_ref = (_sections_ = sections[0]) == null ? void 0 : _sections_.blocks) != null ? _ref : [];
|
|
258
|
+
if (opening && first.some((block)=>block.kind === 'image' && !block.picture) && !first.some((block)=>block.kind === 'keep' && block.ref === opening.ref)) {
|
|
259
|
+
out.push(dropped(`${opening.ref} is the page's own opening picture. Open with it, with a keep block, in place of a picture asked for in words.`));
|
|
260
|
+
}
|
|
261
|
+
const kept = new Set(placed);
|
|
262
|
+
const keptLines = new Set(input.ledger.items.filter((item)=>kept.has(item.ref)).flatMap((item)=>item.lines));
|
|
263
|
+
for (const link of input.ledger.links){
|
|
264
|
+
const to = input.destinations.get(link.ref);
|
|
265
|
+
if (!to || links.has(to) || keptLines.has(link.line)) continue;
|
|
266
|
+
out.push(dropped(`${link.ref} ("${link.text.slice(0, 60)}") goes nowhere on the page. Link to it from a button or an item.`));
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
//# sourceMappingURL=ai-site-import-honesty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-honesty.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * NEW COPY MAY SAY WHAT THE SOURCE SUPPORTS, AND NOTHING IT DOES NOT (AGL-4152).\n *\n * A redesign may describe what the source says and what this kind of business\n * generally does. It may not make up a name, number, price, date, testimonial,\n * client, award, credential, address or guarantee, and it may not lose what\n * the ledger holds. This is the gate, pure, one answer at a time:\n *\n * - `improve-invented-fact`: a word of its copy says a fact, a name, a\n * credential or a guarantee outside what the import read, or a link goes\n * somewhere the source does not.\n * - `improve-dropped-item`: something the ledger holds is not on the page, or\n * is on it twice.\n *\n * Each names the line, so the one re-ask can mend that line.\n *=========================================*/\n\nimport { aiLayoutGuardContacts } from '../layout-language/ai-layout-copy'\nimport type { AiLayoutBlock, AiLayoutItem } from '../layout-language/ai-layout-language'\nimport { siteImportFactScope, siteImportFactTokens, type SiteImportFactScope } from '../model/ai-site-import-fidelity'\nimport type { SiteImportLedger } from '../model/ai-site-import-ledger'\nimport { detectOffVoiceCopy, type AiCopyFraming, type AiDoctrineViolation } from '../runtime/ai-doctrine-validators'\nimport { aiPlaceholderTokens } from '../runtime/ai-placeholder-tokens'\n\nexport const AI_SITE_IMPORT_INVENTED_FACT_CODE = 'improve-invented-fact'\nexport const AI_SITE_IMPORT_DROPPED_ITEM_CODE = 'improve-dropped-item'\n\n/** A block a redesign answered: the layout language, or a `keep` of a ledger ref. */\nexport type AiSiteImportImprovedBlock = AiLayoutBlock | { kind: 'keep'; ref: string; col?: number }\n\n/** A section a redesign answered. */\nexport interface AiSiteImportImprovedSection {\n band?: 'plain' | 'soft' | 'brand' | 'dark'\n cols?: number[]\n align?: 'start' | 'center'\n blocks: AiSiteImportImprovedBlock[]\n}\n\n/** What a redesign's copy is held against. */\nexport interface AiSiteImportHonestyScope {\n ledger: SiteImportLedger\n /** Every line the import read: this page's, the wave's other pages', and what the home page says of the site. */\n scope: readonly string[]\n /** Where a link may go, as an answer writes it, and the ledger's links' own destinations. */\n destinations: ReadonlyMap<string, string>\n framing?: AiCopyFraming | null\n}\n\n/** Words past a sentence's first that are no one's name, in any heading: the short form of a question list. */\nconst NO_NAMES = new Set(['FAQ', 'FAQs', 'I'])\n\n/**\n * Credentials and guarantees: outside what the source says, each is a claim\n * only its owner can make, however a sentence puts it.\n */\nconst CLAIMS: ReadonlyArray<readonly [string, RegExp]> = [\n ['licensed', /\\blicen[sc]ed\\b/i],\n ['certified', /\\b(?:board-)?certified\\b/i],\n ['accredited', /\\baccredited\\b/i],\n ['insured', /\\binsured\\b/i],\n ['bonded', /\\bbonded\\b/i],\n ['award', /\\baward(?:s|-winning)?\\b/i],\n ['guarantee', /\\bguarantee[ds]?\\b/i],\n ['warranty', /\\bwarrant(?:y|ies)\\b/i],\n ['money-back', /\\bmoney[- ]back\\b/i],\n ['top-rated', /\\btop[- ]rated\\b/i],\n ['five-star', /\\b(?:5|five)[- ]star\\b/i],\n ['voted', /\\bvoted\\b/i],\n ['featured in', /\\bfeatured in\\b/i],\n ['trusted by', /\\btrusted by\\b/i],\n]\n\n/** A count no digit says: \"hundreds of clients\", \"two decades\", \"ten years\". */\nconst COUNTS = [\n /\\b(?:hundreds|thousands|millions|dozens|decades?|centur(?:y|ies))\\b/i,\n /\\b(?:two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|fifteen|twenty|thirty|forty|fifty)\\s+(?:years?|clients?|customers?|families|projects?|homes?|offices?|locations?|reviews?|stars?)\\b/i,\n]\n\n/** A word that opens a line in quotation marks and runs on: a testimonial, whoever is made to say it. */\nconst QUOTED = /^[\"“”'‘][^\"“”]{15,}[\"“”]/\n\n/** Whether text is in the source's own words: its fact tokens, and whatever a scope says of it. */\nexport interface AiSiteImportHonestyFacts {\n facts: SiteImportFactScope\n tokens: ReadonlySet<string>\n /** The source's words, as one text, for what a claim is checked against. */\n said: string\n}\n\n/** What every line of an answer is checked against. */\nexport function aiSiteImportHonestyFacts(scope: readonly string[]): AiSiteImportHonestyFacts {\n const facts = siteImportFactScope(scope)\n return { facts, tokens: new Set(scope.flatMap((text) => siteImportFactTokens(text, facts, false))), said: scope.join(' \\n ') }\n}\n\nconst shown = (token: string) => `\"${token.replace(/^[a-z]+:/, '')}\"`\n\n/** What one line of new copy says that the source does not: a reason in words, or `null`. */\nexport function aiSiteImportInventedIn(text: string, held: AiSiteImportHonestyFacts): string | null {\n const invented = siteImportFactTokens(text, held.facts, true).filter((token) => !held.tokens.has(token) && !(token.startsWith('name:') && NO_NAMES.has(token.slice(5))))\n if (invented.length) return `it says ${[...new Set(invented)].map(shown).join(', ')}, which nothing the site says supports. Say only names and figures the site gives; a heading is in sentence case, so a capital reads as a name.`\n for (const [claim, pattern] of CLAIMS) {\n if (pattern.test(text) && !pattern.test(held.said)) return `it claims ${shown(claim)}, which the site does not. Leave credentials, awards and guarantees to the owner.`\n }\n for (const pattern of COUNTS) {\n const found = pattern.exec(text)?.[0]\n if (found && !new RegExp(`\\\\b${found.replace(/\\s+/g, '\\\\s+')}\\\\b`, 'i').test(held.said)) return `it says ${shown(found)}, a count the site does not give.`\n }\n if (QUOTED.test(text.trim()) && !held.said.includes(text.trim().slice(1, 20))) return 'it reads as a testimonial the site does not have. Quote a customer only by keeping their quote.'\n return null\n}\n\n/** Each written line of a block, as its place on the page names it. */\nfunction writtenLines(block: AiLayoutBlock, at: string): Array<{ at: string; text: string }> {\n const out: Array<{ at: string; text: string }> = []\n if (block.text && block.kind !== 'image') out.push({ at, text: block.text })\n ;(block.items ?? []).forEach((item: AiLayoutItem, index) => {\n if (item.title.trim()) out.push({ at: `${at}, item ${index + 1}`, text: item.title })\n if (item.text.trim()) out.push({ at: `${at}, item ${index + 1}`, text: item.text })\n })\n return out\n}\n\n/** Where a block sends a visitor, its own and its items'. */\nconst linksOf = (block: AiLayoutBlock): string[] => [...(block.to ? [block.to] : []), ...(block.items ?? []).flatMap((item) => (item.to ? [item.to] : []))]\n\n/**\n * Every ledger ref an answer places, as often as it places it: each `keep`,\n * each picture on an item, and what a group kept whole holds (AGL-4152).\n */\nexport function aiSiteImportImprovedPlaced(sections: readonly AiSiteImportImprovedSection[], ledger: Pick<SiteImportLedger, 'items'>): string[] {\n const holds = new Map(ledger.items.map((item) => [item.ref, item.holds ?? []]))\n return sections.flatMap((section) =>\n section.blocks.flatMap((block) => (block.kind === 'keep' ? [block.ref, ...(holds.get(block.ref) ?? [])] : (block.items ?? []).flatMap((item) => (item.ref ? [item.ref] : [])))),\n )\n}\n\nconst invented = (message: string, detail?: string): AiDoctrineViolation => ({ rule: 14, code: AI_SITE_IMPORT_INVENTED_FACT_CODE, message, ...(detail ? { detail } : {}) })\nconst dropped = (message: string): AiDoctrineViolation => ({ rule: null, code: AI_SITE_IMPORT_DROPPED_ITEM_CODE, message })\n\n/**\n * An answer held to what the import read, and to its ledger (AGL-4152). No\n * violation is a redesign that may be built; each one names its line.\n */\nexport function aiSiteImportHonesty(sections: readonly AiSiteImportImprovedSection[], input: AiSiteImportHonestyScope): AiDoctrineViolation[] {\n const held = aiSiteImportHonestyFacts(input.scope)\n const contacts = input.scope.join(' \\n ')\n const out: AiDoctrineViolation[] = []\n const refs = new Map(input.ledger.items.map((item) => [item.ref, item]))\n const placed = aiSiteImportImprovedPlaced(sections, input.ledger)\n const links = new Set<string>()\n sections.forEach((section, index) => {\n section.blocks.forEach((raw, position) => {\n if (raw.kind === 'keep') return\n const block = raw\n const at = `section ${index + 1}, block ${position + 1}`\n for (const line of writtenLines(block, at)) {\n const reason = aiSiteImportInventedIn(line.text, held)\n if (reason) out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": ${reason}`))\n else if (aiLayoutGuardContacts(line.text, contacts) !== line.text) out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": it gives a phone number or email the site does not.`))\n else if (/\\[[^\\]]*\\]/.test(line.text) || aiPlaceholderTokens(line.text).length || detectOffVoiceCopy([{ at: 'line', text: line.text }], input.framing ?? null).length) {\n out.push(invented(`${line.at}, \"${line.text.slice(0, 80)}\": it holds filler, a placeholder or a word that calls the work simple or cheap. Write real words.`))\n }\n }\n for (const to of linksOf(block)) {\n if (input.destinations.has(to)) links.add(input.destinations.get(to) as string)\n else out.push(invented(`${at}: it links to \"${to.slice(0, 80)}\", which is not a page of this site, form, phone, email, a section as #n, or an address the source links.`))\n }\n })\n })\n // What the ledger holds: each thing that must land, once; no ref twice, and none it does not hold.\n const inGroup = new Map(input.ledger.items.flatMap((item) => (item.holds ?? []).map((held) => [held, item.ref] as const)))\n for (const ref of new Set(placed)) {\n if (!refs.has(ref)) out.push(dropped(`keep \"${ref.slice(0, 40)}\" names nothing on this page. Use only the refs the page lists.`))\n else if (placed.filter((entry) => entry === ref).length > 1) {\n const group = inGroup.get(ref)\n out.push(dropped(`${ref} is placed ${placed.filter((entry) => entry === ref).length} times${group && placed.includes(group) ? `: keeping ${group} whole places it already` : ''}. Place it once.`))\n }\n }\n for (const item of input.ledger.items) {\n if (item.must && !placed.includes(item.ref)) out.push(dropped(`${item.ref} is not on the page. Place it with a keep block, exactly once${item.folded ? ': this page is long, so its groups are kept whole' : ''}.`))\n }\n // The page's own opening picture outranks a new one: a picture asked for in words never takes its place.\n const opening = input.ledger.items.find((item) => item.kind === 'picture' && item.section === 0)\n const first = sections[0]?.blocks ?? []\n if (opening && first.some((block) => block.kind === 'image' && !block.picture) && !first.some((block) => block.kind === 'keep' && block.ref === opening.ref)) {\n out.push(dropped(`${opening.ref} is the page's own opening picture. Open with it, with a keep block, in place of a picture asked for in words.`))\n }\n const kept = new Set(placed)\n const keptLines = new Set(input.ledger.items.filter((item) => kept.has(item.ref)).flatMap((item) => item.lines))\n for (const link of input.ledger.links) {\n const to = input.destinations.get(link.ref)\n if (!to || links.has(to) || keptLines.has(link.line)) continue\n out.push(dropped(`${link.ref} (\"${link.text.slice(0, 60)}\") goes nowhere on the page. Link to it from a button or an item.`))\n }\n return out\n}\n"],"names":["aiLayoutGuardContacts","siteImportFactScope","siteImportFactTokens","detectOffVoiceCopy","aiPlaceholderTokens","AI_SITE_IMPORT_INVENTED_FACT_CODE","AI_SITE_IMPORT_DROPPED_ITEM_CODE","NO_NAMES","Set","CLAIMS","COUNTS","QUOTED","aiSiteImportHonestyFacts","scope","facts","tokens","flatMap","text","said","join","shown","token","replace","aiSiteImportInventedIn","held","invented","filter","has","startsWith","slice","length","map","claim","pattern","test","found","exec","RegExp","trim","includes","writtenLines","block","at","out","kind","push","items","forEach","item","index","title","linksOf","to","aiSiteImportImprovedPlaced","sections","ledger","holds","Map","ref","section","blocks","get","message","detail","rule","code","dropped","aiSiteImportHonesty","input","contacts","refs","placed","links","raw","position","line","reason","framing","destinations","add","inGroup","entry","group","must","folded","opening","find","first","some","picture","kept","keptLines","lines","link"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;2CAe2C,GAE3C,SAASA,qBAAqB,QAAQ,uCAAmC;AAEzE,SAASC,mBAAmB,EAAEC,oBAAoB,QAAkC,sCAAkC;AAEtH,SAASC,kBAAkB,QAAsD,uCAAmC;AACpH,SAASC,mBAAmB,QAAQ,sCAAkC;AAEtE,OAAO,MAAMC,oCAAoC,wBAAuB;AACxE,OAAO,MAAMC,mCAAmC,uBAAsB;AAuBtE,6GAA6G,GAC7G,MAAMC,WAAW,IAAIC,IAAI;IAAC;IAAO;IAAQ;CAAI;AAE7C;;;CAGC,GACD,MAAMC,SAAmD;IACvD;QAAC;QAAY;KAAmB;IAChC;QAAC;QAAa;KAA4B;IAC1C;QAAC;QAAc;KAAkB;IACjC;QAAC;QAAW;KAAe;IAC3B;QAAC;QAAU;KAAc;IACzB;QAAC;QAAS;KAA4B;IACtC;QAAC;QAAa;KAAsB;IACpC;QAAC;QAAY;KAAwB;IACrC;QAAC;QAAc;KAAqB;IACpC;QAAC;QAAa;KAAoB;IAClC;QAAC;QAAa;KAA0B;IACxC;QAAC;QAAS;KAAa;IACvB;QAAC;QAAe;KAAmB;IACnC;QAAC;QAAc;KAAkB;CAClC;AAED,8EAA8E,GAC9E,MAAMC,SAAS;IACb;IACA;CACD;AA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