@aglyn/plugins-ai 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/components/ai-site-start-card.component.d.ts +1 -1
- package/src/lib/components/ai-site-start-card.component.js +40 -13
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/components/ai-site-start-steps.component.d.ts +17 -1
- package/src/lib/components/ai-site-start-steps.component.js +30 -7
- package/src/lib/components/ai-site-start-steps.component.js.map +1 -1
- package/src/lib/components/assist-panel.component.js +8 -12
- package/src/lib/components/assist-panel.component.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.d.ts +3 -0
- package/src/lib/jobs/ai-job-drafts.js +5 -0
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.d.ts +10 -0
- package/src/lib/jobs/ai-job-layout-language.js +38 -2
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +3 -3
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +15 -7
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/layout-language/ai-layout-compiler.js +39 -1
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame.d.ts +6 -0
- package/src/lib/layout-language/ai-layout-frame.js +85 -30
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +5 -0
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +175 -0
- package/src/lib/model/ai-site-import-fidelity.js +941 -0
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -0
- package/src/lib/model/ai-site-start.d.ts +27 -0
- package/src/lib/model/ai-site-start.js +41 -0
- package/src/lib/model/ai-site-start.js.map +1 -1
- package/src/lib/model/assist-page-change.d.ts +26 -6
- package/src/lib/model/assist-page-change.js +32 -10
- package/src/lib/model/assist-page-change.js.map +1 -1
- package/src/lib/runtime/ai-node-tree.js +18 -2
- package/src/lib/runtime/ai-node-tree.js.map +1 -1
- package/src/lib/server/assist-chat.d.ts +5 -0
- package/src/lib/server/assist-chat.js +11 -2
- package/src/lib/server/assist-chat.js.map +1 -1
- package/src/lib/server/assist-page-change.d.ts +12 -0
- package/src/lib/server/assist-page-change.js +23 -1
- package/src/lib/server/assist-page-change.js.map +1 -1
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +62 -0
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +374 -0
- package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/layout-language/ai-layout-language.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\nimport type { AiTool } from '../providers/contract'\nimport { AI_ICON_WORDS } from '../runtime/ai-icon-library'\n\n/**\n * The compact layout language (AGL-3660): what a model designs a page, and a\n * site's header and footer, in — and the one place its shape is declared.\n *\n * ── Why a language, not a tree ───────────────────────────────────────────\n *\n * A page used to be asked for as a raw element tree, packed as escaped JSON\n * text inside a tool call and held to the doctrine's building rules: Grid\n * items sized as strings, every child attached, one h1, a destination on\n * every button, headings under their ceiling. A real model kept about half\n * of a page's sections on the first try, and a Free section was cut off at\n * its token ceiling. The founder chose a language over a library of section\n * templates (10/7): every page is designed for its own request, so no two\n * sites come out alike, and the rules hold because CODE writes the tree.\n *\n * So the model says WHAT each section is and how it is arranged, in a few\n * words of structure, and writes every word a visitor reads; the compiler\n * (`ai-layout-compiler.ts`) turns that into the element tree with the\n * palette's elements and the theme's tokens, by construction.\n *\n * ── The shape ────────────────────────────────────────────────────────────\n *\n * A page is its plan's sections, in order. A SECTION is\n * - `band` — its background: `plain` (the page), `soft` (a paper band),\n * `brand` (the brand color) or `dark` (always dark);\n * - `cols` — a row of columns by relative width, as `[7, 5]` or `[1, 1, 1]`,\n * up to four; absent, one column;\n * - `align` — `start` or `center`;\n * - `blocks` — what it shows, top to bottom.\n *\n * A BLOCK is one thing a visitor reads or uses. Its `kind` is one of\n * `AI_LAYOUT_BLOCK_KINDS`; `col` places it in a column of the row (0 first),\n * and a block with no `col` spans the section — above the row when it comes\n * before the first placed block, below it when it comes after. `text` is its\n * words, `to` where it goes, `style` its emphasis and `icon` a word from the\n * icon library. A group — `list`, `cards`, `steps`, `stats`, `quotes`,\n * `faq` — carries its `items`, each a `title`, a `text`, and optionally its\n * own `to` and `icon`.\n *\n * Where a block goes (`to`): `page:<id>` for a page of this site (its label\n * works too), `#<n>` for section n of this page, `form` for the site's form,\n * `phone` or `email` for the phone number or email the brief gives (a link\n * that calls or writes, AGL-3979), a form's or a component's id for a `form`\n * or `component` block, or an `https:` address the brief gave.\n *\n * A site's header and footer are two sections in the same language\n * (`AI_LAYOUT_FRAME_TOOL`): the header's brand and navigation are the\n * site's own and written by the compiler, so the model gives the header its\n * band, its alignment and an optional call-to-action button; the footer is\n * a section like any other.\n *\n * ── Cheap by shape ───────────────────────────────────────────────────────\n *\n * The schema is a structured object in the tool input (never JSON text in a\n * string), small enough for a strict tool (`tool-schema-limits.spec.ts`), and\n * the language's instructions ride in the cached prefix. A section is a few\n * dozen words of structure beside its copy, so a whole page is one answer.\n */\n\n/** Every kind of block, in the order the schema lists them. */\nexport const AI_LAYOUT_BLOCK_KINDS = [\n 'eyebrow',\n 'heading',\n 'lede',\n 'text',\n 'note',\n 'list',\n 'button',\n 'image',\n 'cards',\n 'steps',\n 'stats',\n 'quotes',\n 'faq',\n 'form',\n 'component',\n] as const\n\nexport type AiLayoutBlockKind = (typeof AI_LAYOUT_BLOCK_KINDS)[number]\n\n/** The kinds that carry `items`. */\nexport const AI_LAYOUT_GROUP_KINDS: ReadonlySet<string> = new Set<AiLayoutBlockKind>([\n 'list',\n 'cards',\n 'steps',\n 'stats',\n 'quotes',\n 'faq',\n])\n\nexport const AI_LAYOUT_BANDS = ['plain', 'soft', 'brand', 'dark'] as const\nexport type AiLayoutBand = (typeof AI_LAYOUT_BANDS)[number]\n\nexport const AI_LAYOUT_ALIGNS = ['start', 'center'] as const\nexport type AiLayoutAlign = (typeof AI_LAYOUT_ALIGNS)[number]\n\nexport const AI_LAYOUT_STYLES = [\n 'primary',\n 'secondary',\n 'quiet',\n 'large',\n] as const\nexport type AiLayoutStyle = (typeof AI_LAYOUT_STYLES)[number]\n\n/** The most columns a row holds; a fifth is folded into the fourth. */\nexport const AI_LAYOUT_MAX_COLS = 4\n\n/**\n * The most items a group shows: one under the eight copies rule 8 reads as a\n * list typed out by hand, which belongs in a dataset.\n */\nexport const AI_LAYOUT_MAX_ITEMS = 7\n\n/** The most quotes a group shows: each is a gap the owner fills with a real one. */\nexport const AI_LAYOUT_MAX_QUOTES = 3\n\nexport interface AiLayoutItem {\n title: string\n text: string\n to?: string\n icon?: string\n // ── A page brought in (AGL-4107): what the source's item shows beside its\n // title and text, every word as written. No model writes these: no tool\n // schema names them, and the compiler draws them only on a verbatim page.\n /** Its own icon, the source's drawing as a path on the 24-unit square. */\n iconPath?: string\n /** A figure that leads it: a step's number, a plan's price. */\n figure?: string\n /** Its further paragraphs, each its own line. */\n more?: string[]\n /** Its bullet points (a plan's features). */\n list?: string[]\n /** The mark each bullet carries, as a path on the 24-unit square. */\n listIconPath?: string\n /** Its own calls to action, last in it. */\n links?: AiLayoutLink[]\n /** The picture over it, from the site's library. */\n picture?: AiLayoutPicture\n}\n\n/** A link of a page brought in (AGL-4107): its words and where it goes, `page:<id>`, `https:`, `mailto:` or `tel:`. */\nexport interface AiLayoutLink {\n text: string\n to?: string\n style?: AiLayoutStyle\n}\n\n/** A picture of a page brought in (AGL-4107): the library's copy of the source's own. */\nexport interface AiLayoutPicture {\n src: string\n alt: string\n /** Its width over its height, where the library knows them. */\n ratio?: number\n /** Where pressing it goes. */\n to?: string\n /** A byline's portrait beside a few words, drawn small. */\n small?: boolean\n}\n\n/**\n * The block kinds only a page brought in draws (AGL-4107), never in a tool\n * schema: a TABLE of rows of cells, TABS whose panels hold blocks, and a\n * strip of LOGOS — pictures, or short words as chips.\n */\nexport const AI_LAYOUT_IMPORT_BLOCK_KINDS = ['table', 'tabs', 'logos'] as const\nexport type AiLayoutImportBlockKind = (typeof AI_LAYOUT_IMPORT_BLOCK_KINDS)[number]\n\n/** A tab of a page brought in: its label and the blocks its panel shows. */\nexport interface AiLayoutTab {\n label: string\n /** The tab the source shows open. */\n selected?: boolean\n blocks: AiLayoutBlock[]\n}\n\nexport interface AiLayoutBlock {\n kind: AiLayoutBlockKind | AiLayoutImportBlockKind\n col?: number\n text?: string\n to?: string\n style?: AiLayoutStyle\n icon?: string\n items?: AiLayoutItem[]\n // ── A page brought in (AGL-4107), never in a tool schema ──\n /** An image block's picture, the source's own. */\n picture?: AiLayoutPicture\n /** A table's rows, each its cells' words; `header` when its first row names the columns. */\n rows?: Array<{ cells: string[] }>\n header?: boolean\n /** A tab strip's tabs. */\n tabs?: AiLayoutTab[]\n /** How a group is drawn, as the page's design answer chose (`submit_design`). */\n variant?: AiLayoutGroupStyle\n /** The columns the source lays a group's items out in on a wide screen. */\n columns?: number\n}\n\n/** How a group of a page brought in is drawn (AGL-4107): the compiler's group variants a source can show. */\nexport const AI_LAYOUT_GROUP_STYLES = ['cards', 'ruled', 'icons', 'pictures', 'articles'] as const\nexport type AiLayoutGroupStyle = (typeof AI_LAYOUT_GROUP_STYLES)[number]\n\n/** The heroes a page brought in may open with (AGL-4107): each lays the source's own picture beside, behind or under its words. */\nexport const AI_LAYOUT_IMPORT_HEROES = ['split', 'bleed', 'cover', 'poster', 'column', 'editorial', 'panel'] as const\nexport type AiLayoutImportHero = (typeof AI_LAYOUT_IMPORT_HEROES)[number]\n\nexport interface AiLayoutSection {\n band?: AiLayoutBand\n cols?: number[]\n align?: AiLayoutAlign\n blocks: AiLayoutBlock[]\n /** A page brought in (AGL-4107): the hero its first section opens as, around the source's picture. */\n hero?: AiLayoutImportHero\n}\n\n/** A page: its plan's sections, in order. */\nexport interface AiLayoutPageDoc {\n sections: AiLayoutSection[]\n}\n\n/** A site's frame: the header and the footer every page renders between. */\nexport interface AiLayoutFrameDoc {\n header: AiLayoutSection\n footer: AiLayoutSection\n}\n\nconst ITEM_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['title', 'text', 'to', 'icon'],\n properties: {\n title: { type: 'string' },\n text: { type: 'string' },\n to: { type: 'string' },\n icon: { type: 'string' },\n },\n} as const\n\nconst BLOCK_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['kind', 'col', 'text', 'to', 'style', 'icon', 'items'],\n properties: {\n kind: { type: 'string', enum: [...AI_LAYOUT_BLOCK_KINDS] },\n col: { type: 'integer' },\n text: { type: 'string' },\n to: { type: 'string' },\n style: { type: 'string', enum: [...AI_LAYOUT_STYLES, 'none'] },\n icon: { type: 'string' },\n items: { type: 'array', items: ITEM_SCHEMA },\n },\n} as const\n\nconst SECTION_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['band', 'cols', 'align', 'blocks'],\n properties: {\n band: { type: 'string', enum: [...AI_LAYOUT_BANDS] },\n cols: { type: 'array', items: { type: 'integer' } },\n align: { type: 'string', enum: [...AI_LAYOUT_ALIGNS] },\n blocks: { type: 'array', items: BLOCK_SCHEMA },\n },\n} as const\n\n/** The page tool: every section of one page, in plan order, in one answer. */\nexport const AI_LAYOUT_PAGE_TOOL: AiTool = {\n name: 'submit_page',\n description:\n 'Submit the page: one entry in sections for each planned section, in order, in the layout language.',\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['sections'],\n properties: { sections: { type: 'array', items: SECTION_SCHEMA } },\n },\n}\n\n/** The frame tool: the site's header and footer, in the same language. */\nexport const AI_LAYOUT_FRAME_TOOL: AiTool = {\n name: 'submit_frame',\n description:\n \"Submit the site's header and footer, each as a section in the layout language.\",\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['header', 'footer'],\n properties: { header: SECTION_SCHEMA, footer: SECTION_SCHEMA },\n },\n}\n\n/**\n * The language as a model is taught it: the cached instructions both doors\n * share. Every word of copy is the model's; this says only how a design is\n * written down and what each word becomes.\n */\nexport const AI_LAYOUT_LANGUAGE_TEXT = [\n \"You design web pages in a compact layout language. You decide the structure and write every word; the platform turns your design into the page, with the site's theme, spacing and type, so never describe styling beyond the words below.\",\n '',\n 'A page is a list of sections, one for each section the plan names, in that order. A section has:',\n '- band: plain (the page background), soft (a light band), brand (the brand color) or dark (always dark). Vary the bands down a page so neighboring sections read apart; keep brand and dark to one or two sections a page.',\n '- cols: relative column widths for a row, such as [1, 1] for halves, [7, 5] for a wide and a narrow column, or [1, 1, 1]; at most 4. [] for one column.',\n '- align: start or center.',\n '- blocks: what the section shows, top to bottom. A block with col 0 or more goes in that column of the row (0 is the first); a block with col -1 spans the whole section, above the row when it comes first and below it when it comes last.',\n 'Every field is always written: a block that does not use one writes \"\" (text, to, icon), \"none\" (style), -1 (col) or [] (items); an item that does not use one writes \"\".',\n '',\n 'Block kinds:',\n \"- eyebrow: a short label above a heading. heading: a heading; the first heading of the page's first section is the page's title, and the first heading of every other section is that section's heading. lede: the larger sentence under a heading. text: a paragraph. note: small print.\",\n '- button: text is the label and to says where it goes; style primary, secondary or quiet. Two buttons in a row read as a pair.',\n '- image: text describes the picture to place, which becomes its alt text; the owner adds the picture. icon names a drawing to show until then. to lightbox opens it large when pressed.',\n '- list: items are the lines (title only; text may be empty).',\n \"- cards, steps, stats, faq: items, each with a title and a text. cards are features or services; steps are numbered; stats are a figure (title) with its label (text), only for figures the brief gives; faq items are a question (title) and its answer (text). Use no quotes block: the site has no customer's words to show.\",\n \"- form: places a saved form by its id in to. component: places a reusable component by its id in to; its items fill the component's props, title the prop name and text the value.\",\n '- style large on a heading makes the page title display-sized. icon (on a block or an item) is one of: ' +\n AI_ICON_WORDS.join(', ') +\n '.',\n '',\n \"Where a link goes (to): page:<page id> for a page of this site; #<n> for section n of this page (counted from 1); form for the site's form; phone or email to call or write to the phone number or email the brief gives; or an https: address the brief gives. A button the page has nowhere to send is left out. A to value is never written into words: in text, name a page by its title.\",\n '',\n \"Writing: plain, specific copy in the site's voice, from the brief, the business and its audience, never filler. Keep a page title under 70 characters and a section heading under 80. The site is published exactly as you write it, so where the brief leaves out a fact such as a price, a figure, a name, a phone number, an email, an address or opening hours, leave it out: write the sentence without it, and make no list line, card or contact row for it. Never write a placeholder or a gap in square brackets, and never invent the fact. Never invent a customer, a review, an award or a statistic.\",\n '',\n 'Design each page for this business and this request: choose the bands, the rows and the blocks that tell its story best, so no two sites read alike.',\n].join('\\n')\n\n// ── Reading an answer ────────────────────────────────────────────────────\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction text(value: unknown): string | undefined {\n return typeof value === 'string' && value.trim() ? value : undefined\n}\n\nfunction oneOf<T extends string>(\n value: unknown,\n values: readonly T[],\n): T | undefined {\n return typeof value === 'string' &&\n (values as readonly string[]).includes(value)\n ? (value as T)\n : undefined\n}\n\n/** What the reader settled on its own, for the job's record and the specs. */\nexport interface AiLayoutSettlement {\n /** Where: `sections[2].blocks[1]`, `header`. */\n at: string\n what: string\n}\n\nfunction readItem(raw: unknown): AiLayoutItem | null {\n if (!isRecord(raw)) return null\n const item: AiLayoutItem = {\n title: typeof raw['title'] === 'string' ? raw['title'] : '',\n text: typeof raw['text'] === 'string' ? raw['text'] : '',\n }\n if (!item.title.trim() && !item.text.trim()) return null\n const to = text(raw['to'])\n const icon = text(raw['icon'])\n return { ...item, ...(to ? { to } : {}), ...(icon ? { icon } : {}) }\n}\n\nfunction readBlock(\n raw: unknown,\n at: string,\n settled: AiLayoutSettlement[],\n): AiLayoutBlock | null {\n if (!isRecord(raw)) {\n settled.push({ at, what: 'not a block; left out' })\n return null\n }\n const kind = oneOf(raw['kind'], AI_LAYOUT_BLOCK_KINDS)\n if (!kind) {\n settled.push({\n at,\n what: `unknown kind ${JSON.stringify(raw['kind'] ?? null)}; left out`,\n })\n return null\n }\n const block: AiLayoutBlock = { kind }\n if (\n typeof raw['col'] === 'number' &&\n Number.isInteger(raw['col']) &&\n raw['col'] >= 0\n )\n block.col = raw['col']\n const words = text(raw['text'])\n if (words) block.text = words\n const to = text(raw['to'])\n if (to) block.to = to.trim()\n const style = oneOf(raw['style'], AI_LAYOUT_STYLES)\n if (style) block.style = style\n const icon = text(raw['icon'])\n if (icon) block.icon = icon.trim().toLowerCase()\n if (AI_LAYOUT_GROUP_KINDS.has(kind) || kind === 'component') {\n const items = (Array.isArray(raw['items']) ? raw['items'] : [])\n .map(readItem)\n .filter((item): item is AiLayoutItem => !!item)\n const most =\n kind === 'quotes'\n ? AI_LAYOUT_MAX_QUOTES\n : kind === 'component'\n ? Infinity\n : AI_LAYOUT_MAX_ITEMS\n if (items.length > most)\n settled.push({\n at,\n what: `${items.length} items; the first ${most} kept`,\n })\n if (items.length) block.items = items.slice(0, most)\n }\n // A block with nothing to show is no block: a group with no items, words\n // with no words. A form or a component may name its record alone.\n const empty = AI_LAYOUT_GROUP_KINDS.has(kind)\n ? !block.items?.length\n : kind === 'form' || kind === 'component'\n ? false\n : !block.text\n if (empty) {\n settled.push({ at, what: `an empty ${kind}; left out` })\n return null\n }\n return block\n}\n\n/** A section read from an answer, or `null` with why it could not be. */\nexport function aiReadLayoutSection(\n raw: unknown,\n at: string,\n settled: AiLayoutSettlement[],\n): AiLayoutSection | null {\n if (!isRecord(raw)) return null\n const section: AiLayoutSection = { blocks: [] }\n const band = oneOf(raw['band'], AI_LAYOUT_BANDS)\n if (band) section.band = band\n const align = oneOf(raw['align'], AI_LAYOUT_ALIGNS)\n if (align) section.align = align\n if (Array.isArray(raw['cols'])) {\n const cols = raw['cols'].filter(\n (value): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0,\n )\n if (cols.length > AI_LAYOUT_MAX_COLS) {\n settled.push({\n at: `${at}.cols`,\n what: `${cols.length} columns; the first ${AI_LAYOUT_MAX_COLS} kept`,\n })\n }\n if (cols.length >= 2)\n section.cols = cols\n .slice(0, AI_LAYOUT_MAX_COLS)\n .map((value) => Math.min(12, Math.max(1, Math.round(value))))\n }\n const blocks = Array.isArray(raw['blocks']) ? raw['blocks'] : []\n blocks.forEach((entry, index) => {\n const block = readBlock(entry, `${at}.blocks[${index}]`, settled)\n if (!block) return\n if (\n block.col !== undefined &&\n section.cols &&\n block.col >= section.cols.length\n ) {\n settled.push({\n at: `${at}.blocks[${index}]`,\n what: `column ${block.col} of ${section.cols.length}; placed in the last`,\n })\n block.col = section.cols.length - 1\n }\n if (block.col !== undefined && !section.cols) delete block.col\n section.blocks.push(block)\n })\n return section.blocks.length ? section : null\n}\n\n/** A page answer read: the sections it gave, by plan position, and the positions it could not. */\nexport interface AiLayoutPageReading {\n /** One entry per planned section; `null` where the answer gave nothing usable. */\n sections: Array<AiLayoutSection | null>\n settled: AiLayoutSettlement[]\n}\n\n/** What a planned section is, as the reader matches an answer's sections to it. */\nexport interface AiLayoutPlannedSection {\n name: string\n items: number\n /** What the plan places in it: a form it binds there is one of these. */\n uses?: readonly string[]\n}\n\n/** A planned section's name that asks for a form: a contact, an inquiry, a booking. */\nconst FORM_SECTION =\n /\\b(form|contact|get in touch|reach|write|message|inquir(?:y|ies|e)|enquir(?:y|ies|e)|book(?:ing|ings)?|reserv(?:e|ation|ations)|quote|appointments?|rsvp|sign ?up|subscribe|newsletter|apply|application|register)\\b/i\n\n/** Whether a planned section is one a form may fill: it names one, or the plan binds a form there. */\nfunction takesForm(planned: AiLayoutPlannedSection): boolean {\n return FORM_SECTION.test(planned.name) || (planned.uses ?? []).some((ref) => /\\bform\\b/i.test(ref))\n}\n\n/** What a form's section scores against a planned section that asks for no form: never chosen while another fits. */\nconst AI_LAYOUT_FORM_MISFIT = -100\n\n/**\n * A word as a heading and a plan's name are compared: letters in any script,\n * with their accents (AGL-3791). As ASCII, \"Menú\" was \"men\", which every\n * \"mensajes\" began with, and \"galería\" was \"galer\" and \"a\".\n */\nconst WORD = /[\\p{L}\\p{M}\\p{N}]+/gu\nconst STOP = new Set(['a', 'an', 'and', 'the', 'of', 'for', 'to', 'our', 'your', 'with', 'in', 'on', 'we', 'us', 'you'])\nconst wordsOf = (text: string) => new Set((text.toLowerCase().match(WORD) ?? []).filter((word) => !STOP.has(word)))\n\n/** The kinds that show a section's repeated items. */\nconst ITEM_KINDS = new Set(['list', 'cards', 'steps', 'stats', 'quotes', 'faq', 'component'])\n\n/**\n * How well an answer's section fits a planned one: the words its headings\n * share with the plan's name, and whether it shows items where the plan\n * asked for them and none where it asked for none.\n *\n * A shared heading word outweighs the items (AGL-3660): a live portfolio's\n * plan gave \"Works Gallery\" no items, and its \"Selected works\" cards lost the\n * place to an inquiry form that shared no word with it. A section holding a\n * form fills only a planned section that asks for one — by its name, or a\n * form the plan binds there — so the form is never a page's stand-in.\n */\nfunction fit(raw: unknown, planned: AiLayoutPlannedSection): number {\n const blocks = isRecord(raw) && Array.isArray(raw['blocks']) ? raw['blocks'].filter(isRecord) : []\n const said = wordsOf(\n blocks\n .filter((block) => block['kind'] === 'heading' || block['kind'] === 'eyebrow')\n .map((block) => String(block['text'] ?? ''))\n .join(' '),\n )\n const named = wordsOf(planned.name)\n let shared = 0\n for (const word of named) if (said.has(word) || [...said].some((other) => other.startsWith(word) || word.startsWith(other))) shared += 1\n const showsItems = blocks.some((block) => ITEM_KINDS.has(String(block['kind'])) && (block['kind'] === 'component' || (Array.isArray(block['items']) && block['items'].length > 0)))\n const wantsItems = planned.items > 0\n const holdsForm = blocks.some((block) => block['kind'] === 'form')\n if (holdsForm && !takesForm(planned)) return AI_LAYOUT_FORM_MISFIT\n return shared * 2 + (wantsItems === showsItems ? 0.5 : -0.5)\n}\n\n/**\n * The answer's sections that best match the plan, in order, where it gave\n * more than the plan names (AGL-3660): a model that opened a page with a\n * hero of its own, or closed it with a call to action, shifted every planned\n * section by one, and the cut fell on the plan's last sections — the ones\n * that carried its items. Each planned section takes the answer's section\n * that fits it best, keeping the answer's order.\n */\nfunction alignSections(given: readonly unknown[], planned: readonly AiLayoutPlannedSection[]): number[] {\n const n = given.length\n const m = planned.length\n // best[i][j]: the best score placing plan sections j.. on answer sections i..\n const best: number[][] = Array.from({ length: n + 1 }, () => Array(m + 1).fill(-Infinity))\n for (let i = 0; i <= n; i += 1) best[i][m] = 0\n for (let i = n - 1; i >= 0; i -= 1) {\n for (let j = m - 1; j >= 0; j -= 1) {\n if (n - i < m - j) continue\n best[i][j] = Math.max(best[i + 1][j], fit(given[i], planned[j]) + best[i + 1][j + 1])\n }\n }\n const picked: number[] = []\n let i = 0\n for (let j = 0; j < m; j += 1) {\n while (i < n && best[i][j] !== fit(given[i], planned[j]) + best[i + 1][j + 1]) i += 1\n picked.push(i)\n i += 1\n }\n return picked\n}\n\n/**\n * The page an answer describes, against the sections its plan names: each\n * planned section takes the answer's section at its position — or, where the\n * answer gave more sections than the plan names and the plan's sections are\n * given, the one that fits it best (`alignSections`) — an answer's extra\n * sections are left out, and a planned section the answer left empty or out\n * is `null` — the one thing a re-ask asks for again.\n */\nexport function aiReadLayoutPage(\n raw: unknown,\n planned: number,\n plan?: readonly AiLayoutPlannedSection[],\n): AiLayoutPageReading {\n const settled: AiLayoutSettlement[] = []\n const given =\n isRecord(raw) && Array.isArray(raw['sections']) ? raw['sections'] : []\n const aligned =\n given.length > planned && plan && plan.length === planned\n ? alignSections(given, plan)\n : Array.from({ length: planned }, (_, index) => index)\n if (given.length > planned) {\n settled.push({\n at: 'sections',\n what: `${given.length} sections for a plan of ${planned}; ${\n aligned.every((at, index) => at === index) ? 'the extra left out' : `sections ${aligned.map((at) => at + 1).join(', ')} kept as the plan's`\n }`,\n })\n }\n const sections = aligned.map((at, index) =>\n aiReadLayoutSection(given[at], `sections[${index}]`, settled),\n )\n return { sections, settled }\n}\n\n/** A frame answer read: a header and a footer, either `null` where it was not usable. */\nexport function aiReadLayoutFrame(raw: unknown): {\n header: AiLayoutSection | null\n footer: AiLayoutSection | null\n settled: AiLayoutSettlement[]\n} {\n const settled: AiLayoutSettlement[] = []\n const record = isRecord(raw) ? raw : {}\n // A header needs no block of its own: its brand and navigation are the\n // site's, so an empty one is a plain bar.\n const header = isRecord(record['header'])\n ? (aiReadLayoutSection(record['header'], 'header', settled) ??\n readBare(record['header']))\n : null\n const footer = aiReadLayoutSection(record['footer'], 'footer', settled)\n return { header, footer, settled }\n}\n\n/** A section with no usable block, keeping only its band and alignment. */\nfunction readBare(raw: Record<string, unknown>): AiLayoutSection {\n const band = oneOf(raw['band'], AI_LAYOUT_BANDS)\n const align = oneOf(raw['align'], AI_LAYOUT_ALIGNS)\n return { ...(band ? { band } : {}), ...(align ? { align } : {}), blocks: [] }\n}\n\n// ── The design of a page brought in (AGL-4107) ───────────────────────────\n\n/**\n * A page brought in from its owner's own website is laid out as its source\n * lays it out (AGL-4107): the reader reads its sections, bands, rows, groups,\n * pictures and icons (`site-import/site-import-layout.ts`), and code compiles\n * that structure with every word as written (`jobs/ai-site-import-compile.ts`).\n * The one question left for a model is the page's DESIGN, over the structure\n * it is shown: which hero the opening becomes around its picture, how each\n * group is drawn, a band where the source gave none, the kind of a group the\n * reader could not tell, and an alignment. The schema below names only those\n * choices, so no word of copy, no line and no structure has anywhere to go.\n */\n\n/** A section's choice where the source's own stands: its band, its alignment, a group's kind. */\nexport const AI_LAYOUT_DESIGN_SOURCE = 'source'\n\n/** The kinds a group the reader could not tell may be read as. */\nexport const AI_LAYOUT_DESIGN_GROUP_KINDS = ['cards', 'steps', 'stats', 'list'] as const\nexport type AiLayoutDesignGroupKind = (typeof AI_LAYOUT_DESIGN_GROUP_KINDS)[number]\n\n/** The bands a design answer may give a section the source drew on no band of its own. */\nexport const AI_LAYOUT_DESIGN_BANDS = ['plain', 'soft', 'dark'] as const\n\nexport interface AiLayoutDesignGroup {\n /** The group's kind, where the answer reads it otherwise than the reader did. */\n kind?: AiLayoutDesignGroupKind\n style?: AiLayoutGroupStyle\n}\n\nexport interface AiLayoutDesignSection {\n /** The hero the opening becomes, or `none` to keep it as the source lays it out. */\n hero?: AiLayoutImportHero | 'none'\n band?: (typeof AI_LAYOUT_DESIGN_BANDS)[number]\n align?: AiLayoutAlign\n /** One for each group of the section, in order. */\n groups: AiLayoutDesignGroup[]\n}\n\n/** A design answer read: one entry per section of the page, `null` where it gave none. */\nexport interface AiLayoutDesignAnswer {\n sections: Array<AiLayoutDesignSection | null>\n}\n\nconst DESIGN_GROUP_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['kind', 'style'],\n properties: {\n kind: { type: 'string', enum: [AI_LAYOUT_DESIGN_SOURCE, ...AI_LAYOUT_DESIGN_GROUP_KINDS] },\n style: { type: 'string', enum: [...AI_LAYOUT_GROUP_STYLES] },\n },\n} as const\n\nconst DESIGN_SECTION_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['hero', 'band', 'align', 'groups'],\n properties: {\n hero: { type: 'string', enum: ['none', ...AI_LAYOUT_IMPORT_HEROES] },\n band: { type: 'string', enum: [AI_LAYOUT_DESIGN_SOURCE, ...AI_LAYOUT_DESIGN_BANDS] },\n align: { type: 'string', enum: [AI_LAYOUT_DESIGN_SOURCE, ...AI_LAYOUT_ALIGNS] },\n groups: { type: 'array', items: DESIGN_GROUP_SCHEMA },\n },\n} as const\n\n/** The design tool: one entry per section of a page brought in, in order, naming design choices only. */\nexport const AI_LAYOUT_DESIGN_TOOL: AiTool = {\n name: 'submit_design',\n description: \"Submit the page's design: one entry in sections for each section of the page, in order, with one entry in groups for each of its groups.\",\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['sections'],\n properties: { sections: { type: 'array', items: DESIGN_SECTION_SCHEMA } },\n },\n}\n\nfunction readDesignSection(raw: unknown): AiLayoutDesignSection | null {\n if (!isRecord(raw)) return null\n const section: AiLayoutDesignSection = { groups: [] }\n const hero = oneOf(raw['hero'], ['none', ...AI_LAYOUT_IMPORT_HEROES] as const)\n if (hero) section.hero = hero\n const band = oneOf(raw['band'], AI_LAYOUT_DESIGN_BANDS)\n if (band) section.band = band\n const align = oneOf(raw['align'], AI_LAYOUT_ALIGNS)\n if (align) section.align = align\n for (const entry of Array.isArray(raw['groups']) ? raw['groups'] : []) {\n const group: AiLayoutDesignGroup = {}\n if (isRecord(entry)) {\n const kind = oneOf(entry['kind'], AI_LAYOUT_DESIGN_GROUP_KINDS)\n if (kind) group.kind = kind\n const style = oneOf(entry['style'], AI_LAYOUT_GROUP_STYLES)\n if (style) group.style = style\n }\n section.groups.push(group)\n }\n return section\n}\n\n/**\n * A design answer read (AGL-4107): each section's choices by position, and\n * `null` for one it gave nothing usable for, which is then drawn as its\n * source has it. An answer carries no words, and none would be read.\n */\nexport function aiReadLayoutDesign(raw: unknown, sections: number): AiLayoutDesignAnswer {\n const given = isRecord(raw) && Array.isArray(raw['sections']) ? raw['sections'] : []\n return { sections: Array.from({ length: Math.max(0, sections) }, (_, index) => readDesignSection(given[index])) }\n}\n"],"names":["AI_ICON_WORDS","AI_LAYOUT_BLOCK_KINDS","AI_LAYOUT_GROUP_KINDS","Set","AI_LAYOUT_BANDS","AI_LAYOUT_ALIGNS","AI_LAYOUT_STYLES","AI_LAYOUT_MAX_COLS","AI_LAYOUT_MAX_ITEMS","AI_LAYOUT_MAX_QUOTES","AI_LAYOUT_IMPORT_BLOCK_KINDS","AI_LAYOUT_GROUP_STYLES","AI_LAYOUT_IMPORT_HEROES","ITEM_SCHEMA","type","additionalProperties","required","properties","title","text","to","icon","BLOCK_SCHEMA","kind","enum","col","style","items","SECTION_SCHEMA","band","cols","align","blocks","AI_LAYOUT_PAGE_TOOL","name","description","strict","inputSchema","sections","AI_LAYOUT_FRAME_TOOL","header","footer","AI_LAYOUT_LANGUAGE_TEXT","join","isRecord","value","Array","isArray","trim","undefined","oneOf","values","includes","readItem","raw","item","readBlock","at","settled","block","push","what","JSON","stringify","Number","isInteger","words","toLowerCase","has","map","filter","most","Infinity","length","slice","empty","aiReadLayoutSection","section","isFinite","Math","min","max","round","forEach","entry","index","FORM_SECTION","takesForm","planned","test","uses","some","ref","AI_LAYOUT_FORM_MISFIT","WORD","STOP","wordsOf","match","word","ITEM_KINDS","fit","said","String","named","shared","other","startsWith","showsItems","wantsItems","holdsForm","alignSections","given","n","m","best","from","fill","i","j","picked","aiReadLayoutPage","plan","aligned","_","every","aiReadLayoutFrame","record","readBare","AI_LAYOUT_DESIGN_SOURCE","AI_LAYOUT_DESIGN_GROUP_KINDS","AI_LAYOUT_DESIGN_BANDS","DESIGN_GROUP_SCHEMA","DESIGN_SECTION_SCHEMA","hero","groups","AI_LAYOUT_DESIGN_TOOL","readDesignSection","group","aiReadLayoutDesign"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,aAAa,QAAQ,gCAA4B;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDC,GAED,6DAA6D,GAC7D,OAAO,MAAMC,wBAAwB;IACnC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAIV,kCAAkC,GAClC,OAAO,MAAMC,wBAA6C,IAAIC,IAAuB;IACnF;IACA;IACA;IACA;IACA;IACA;CACD,EAAC;AAEF,OAAO,MAAMC,kBAAkB;IAAC;IAAS;IAAQ;IAAS;CAAO,CAAS;AAG1E,OAAO,MAAMC,mBAAmB;IAAC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F,GAAY,EAAEhB,QAAgB;IAC/D,MAAMyE,QAAQnE,SAASU,QAAQR,MAAMC,OAAO,CAACO,GAAG,CAAC,WAAW,IAAIA,GAAG,CAAC,WAAW,GAAG,EAAE;IACpF,OAAO;QAAEhB,UAAUQ,MAAMqE,IAAI,CAAC;YAAE1C,QAAQM,KAAKE,GAAG,CAAC,GAAG3C;QAAU,GAAG,CAACqF,GAAGtC,QAAUmD,kBAAkBzB,KAAK,CAAC1B,MAAM;IAAG;AAClH"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/layout-language/ai-layout-language.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\nimport type { AiTool } from '../providers/contract'\nimport { AI_ICON_WORDS } from '../runtime/ai-icon-library'\n\n/**\n * The compact layout language (AGL-3660): what a model designs a page, and a\n * site's header and footer, in — and the one place its shape is declared.\n *\n * ── Why a language, not a tree ───────────────────────────────────────────\n *\n * A page used to be asked for as a raw element tree, packed as escaped JSON\n * text inside a tool call and held to the doctrine's building rules: Grid\n * items sized as strings, every child attached, one h1, a destination on\n * every button, headings under their ceiling. A real model kept about half\n * of a page's sections on the first try, and a Free section was cut off at\n * its token ceiling. The founder chose a language over a library of section\n * templates (10/7): every page is designed for its own request, so no two\n * sites come out alike, and the rules hold because CODE writes the tree.\n *\n * So the model says WHAT each section is and how it is arranged, in a few\n * words of structure, and writes every word a visitor reads; the compiler\n * (`ai-layout-compiler.ts`) turns that into the element tree with the\n * palette's elements and the theme's tokens, by construction.\n *\n * ── The shape ────────────────────────────────────────────────────────────\n *\n * A page is its plan's sections, in order. A SECTION is\n * - `band` — its background: `plain` (the page), `soft` (a paper band),\n * `brand` (the brand color) or `dark` (always dark);\n * - `cols` — a row of columns by relative width, as `[7, 5]` or `[1, 1, 1]`,\n * up to four; absent, one column;\n * - `align` — `start` or `center`;\n * - `blocks` — what it shows, top to bottom.\n *\n * A BLOCK is one thing a visitor reads or uses. Its `kind` is one of\n * `AI_LAYOUT_BLOCK_KINDS`; `col` places it in a column of the row (0 first),\n * and a block with no `col` spans the section — above the row when it comes\n * before the first placed block, below it when it comes after. `text` is its\n * words, `to` where it goes, `style` its emphasis and `icon` a word from the\n * icon library. A group — `list`, `cards`, `steps`, `stats`, `quotes`,\n * `faq` — carries its `items`, each a `title`, a `text`, and optionally its\n * own `to` and `icon`.\n *\n * Where a block goes (`to`): `page:<id>` for a page of this site (its label\n * works too), `#<n>` for section n of this page, `form` for the site's form,\n * `phone` or `email` for the phone number or email the brief gives (a link\n * that calls or writes, AGL-3979), a form's or a component's id for a `form`\n * or `component` block, or an `https:` address the brief gave.\n *\n * A site's header and footer are two sections in the same language\n * (`AI_LAYOUT_FRAME_TOOL`): the header's brand and navigation are the\n * site's own and written by the compiler, so the model gives the header its\n * band, its alignment and an optional call-to-action button; the footer is\n * a section like any other.\n *\n * ── Cheap by shape ───────────────────────────────────────────────────────\n *\n * The schema is a structured object in the tool input (never JSON text in a\n * string), small enough for a strict tool (`tool-schema-limits.spec.ts`), and\n * the language's instructions ride in the cached prefix. A section is a few\n * dozen words of structure beside its copy, so a whole page is one answer.\n */\n\n/** Every kind of block, in the order the schema lists them. */\nexport const AI_LAYOUT_BLOCK_KINDS = [\n 'eyebrow',\n 'heading',\n 'lede',\n 'text',\n 'note',\n 'list',\n 'button',\n 'image',\n 'cards',\n 'steps',\n 'stats',\n 'quotes',\n 'faq',\n 'form',\n 'component',\n] as const\n\nexport type AiLayoutBlockKind = (typeof AI_LAYOUT_BLOCK_KINDS)[number]\n\n/** The kinds that carry `items`. */\nexport const AI_LAYOUT_GROUP_KINDS: ReadonlySet<string> = new Set<AiLayoutBlockKind>([\n 'list',\n 'cards',\n 'steps',\n 'stats',\n 'quotes',\n 'faq',\n])\n\nexport const AI_LAYOUT_BANDS = ['plain', 'soft', 'brand', 'dark'] as const\nexport type AiLayoutBand = (typeof AI_LAYOUT_BANDS)[number]\n\nexport const AI_LAYOUT_ALIGNS = ['start', 'center'] as const\nexport type AiLayoutAlign = (typeof AI_LAYOUT_ALIGNS)[number]\n\nexport const AI_LAYOUT_STYLES = [\n 'primary',\n 'secondary',\n 'quiet',\n 'large',\n] as const\nexport type AiLayoutStyle = (typeof AI_LAYOUT_STYLES)[number]\n\n/** The most columns a row holds; a fifth is folded into the fourth. */\nexport const AI_LAYOUT_MAX_COLS = 4\n\n/**\n * The most items a group shows: one under the eight copies rule 8 reads as a\n * list typed out by hand, which belongs in a dataset.\n */\nexport const AI_LAYOUT_MAX_ITEMS = 7\n\n/** The most quotes a group shows: each is a gap the owner fills with a real one. */\nexport const AI_LAYOUT_MAX_QUOTES = 3\n\nexport interface AiLayoutItem {\n title: string\n text: string\n to?: string\n icon?: string\n // ── A page brought in (AGL-4107): what the source's item shows beside its\n // title and text, every word as written. No model writes these: no tool\n // schema names them, and the compiler draws them only on a verbatim page.\n /** Its own icon, the source's drawing as a path on the 24-unit square. */\n iconPath?: string\n /** A figure that leads it: a step's number, a plan's price. */\n figure?: string\n /** Its further paragraphs, each its own line. */\n more?: string[]\n /** Its bullet points (a plan's features). */\n list?: string[]\n /** The mark each bullet carries, as a path on the 24-unit square. */\n listIconPath?: string\n /** Its own calls to action, last in it. */\n links?: AiLayoutLink[]\n /** The picture over it, from the site's library. */\n picture?: AiLayoutPicture\n}\n\n/** A link of a page brought in (AGL-4107): its words and where it goes, `page:<id>`, `https:`, `mailto:` or `tel:`. */\nexport interface AiLayoutLink {\n text: string\n to?: string\n style?: AiLayoutStyle\n}\n\n/** A picture of a page brought in (AGL-4107): the library's copy of the source's own. */\nexport interface AiLayoutPicture {\n src: string\n alt: string\n /** Its width over its height, where the library knows them. */\n ratio?: number\n /** Where pressing it goes. */\n to?: string\n /** A byline's portrait beside a few words, drawn small. */\n small?: boolean\n}\n\n/**\n * The block kinds only a page brought in draws (AGL-4107), never in a tool\n * schema: a TABLE of rows of cells, TABS whose panels hold blocks, and a\n * strip of LOGOS — pictures, or short words as chips.\n */\nexport const AI_LAYOUT_IMPORT_BLOCK_KINDS = ['table', 'tabs', 'logos'] as const\nexport type AiLayoutImportBlockKind = (typeof AI_LAYOUT_IMPORT_BLOCK_KINDS)[number]\n\n/** A tab of a page brought in: its label and the blocks its panel shows. */\nexport interface AiLayoutTab {\n label: string\n /** The tab the source shows open. */\n selected?: boolean\n blocks: AiLayoutBlock[]\n /**\n * The row of columns the source sets in the panel (AGL-4114), as a\n * section's `cols`: relative widths, its blocks placed by `col`.\n */\n cols?: number[]\n}\n\nexport interface AiLayoutBlock {\n kind: AiLayoutBlockKind | AiLayoutImportBlockKind\n col?: number\n text?: string\n to?: string\n style?: AiLayoutStyle\n icon?: string\n items?: AiLayoutItem[]\n // ── A page brought in (AGL-4107), never in a tool schema ──\n /** An image block's picture, the source's own. */\n picture?: AiLayoutPicture\n /** A table's rows, each its cells' words; `header` when its first row names the columns. */\n rows?: Array<{ cells: string[] }>\n header?: boolean\n /** A tab strip's tabs. */\n tabs?: AiLayoutTab[]\n /** How a group is drawn, as the page's design answer chose (`submit_design`). */\n variant?: AiLayoutGroupStyle\n /** The columns the source lays a group's items out in on a wide screen. */\n columns?: number\n}\n\n/** How a group of a page brought in is drawn (AGL-4107): the compiler's group variants a source can show. */\nexport const AI_LAYOUT_GROUP_STYLES = ['cards', 'ruled', 'icons', 'pictures', 'articles'] as const\nexport type AiLayoutGroupStyle = (typeof AI_LAYOUT_GROUP_STYLES)[number]\n\n/** The heroes a page brought in may open with (AGL-4107): each lays the source's own picture beside, behind or under its words. */\nexport const AI_LAYOUT_IMPORT_HEROES = ['split', 'bleed', 'cover', 'poster', 'column', 'editorial', 'panel'] as const\nexport type AiLayoutImportHero = (typeof AI_LAYOUT_IMPORT_HEROES)[number]\n\nexport interface AiLayoutSection {\n band?: AiLayoutBand\n cols?: number[]\n align?: AiLayoutAlign\n blocks: AiLayoutBlock[]\n /** A page brought in (AGL-4107): the hero its first section opens as, around the source's picture. */\n hero?: AiLayoutImportHero\n}\n\n/** A page: its plan's sections, in order. */\nexport interface AiLayoutPageDoc {\n sections: AiLayoutSection[]\n}\n\n/** A site's frame: the header and the footer every page renders between. */\nexport interface AiLayoutFrameDoc {\n header: AiLayoutSection\n footer: AiLayoutSection\n}\n\nconst ITEM_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['title', 'text', 'to', 'icon'],\n properties: {\n title: { type: 'string' },\n text: { type: 'string' },\n to: { type: 'string' },\n icon: { type: 'string' },\n },\n} as const\n\nconst BLOCK_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['kind', 'col', 'text', 'to', 'style', 'icon', 'items'],\n properties: {\n kind: { type: 'string', enum: [...AI_LAYOUT_BLOCK_KINDS] },\n col: { type: 'integer' },\n text: { type: 'string' },\n to: { type: 'string' },\n style: { type: 'string', enum: [...AI_LAYOUT_STYLES, 'none'] },\n icon: { type: 'string' },\n items: { type: 'array', items: ITEM_SCHEMA },\n },\n} as const\n\nconst SECTION_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['band', 'cols', 'align', 'blocks'],\n properties: {\n band: { type: 'string', enum: [...AI_LAYOUT_BANDS] },\n cols: { type: 'array', items: { type: 'integer' } },\n align: { type: 'string', enum: [...AI_LAYOUT_ALIGNS] },\n blocks: { type: 'array', items: BLOCK_SCHEMA },\n },\n} as const\n\n/** The page tool: every section of one page, in plan order, in one answer. */\nexport const AI_LAYOUT_PAGE_TOOL: AiTool = {\n name: 'submit_page',\n description:\n 'Submit the page: one entry in sections for each planned section, in order, in the layout language.',\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['sections'],\n properties: { sections: { type: 'array', items: SECTION_SCHEMA } },\n },\n}\n\n/** The frame tool: the site's header and footer, in the same language. */\nexport const AI_LAYOUT_FRAME_TOOL: AiTool = {\n name: 'submit_frame',\n description:\n \"Submit the site's header and footer, each as a section in the layout language.\",\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['header', 'footer'],\n properties: { header: SECTION_SCHEMA, footer: SECTION_SCHEMA },\n },\n}\n\n/**\n * The language as a model is taught it: the cached instructions both doors\n * share. Every word of copy is the model's; this says only how a design is\n * written down and what each word becomes.\n */\nexport const AI_LAYOUT_LANGUAGE_TEXT = [\n \"You design web pages in a compact layout language. You decide the structure and write every word; the platform turns your design into the page, with the site's theme, spacing and type, so never describe styling beyond the words below.\",\n '',\n 'A page is a list of sections, one for each section the plan names, in that order. A section has:',\n '- band: plain (the page background), soft (a light band), brand (the brand color) or dark (always dark). Vary the bands down a page so neighboring sections read apart; keep brand and dark to one or two sections a page.',\n '- cols: relative column widths for a row, such as [1, 1] for halves, [7, 5] for a wide and a narrow column, or [1, 1, 1]; at most 4. [] for one column.',\n '- align: start or center.',\n '- blocks: what the section shows, top to bottom. A block with col 0 or more goes in that column of the row (0 is the first); a block with col -1 spans the whole section, above the row when it comes first and below it when it comes last.',\n 'Every field is always written: a block that does not use one writes \"\" (text, to, icon), \"none\" (style), -1 (col) or [] (items); an item that does not use one writes \"\".',\n '',\n 'Block kinds:',\n \"- eyebrow: a short label above a heading. heading: a heading; the first heading of the page's first section is the page's title, and the first heading of every other section is that section's heading. lede: the larger sentence under a heading. text: a paragraph. note: small print.\",\n '- button: text is the label and to says where it goes; style primary, secondary or quiet. Two buttons in a row read as a pair.',\n '- image: text describes the picture to place, which becomes its alt text; the owner adds the picture. icon names a drawing to show until then. to lightbox opens it large when pressed.',\n '- list: items are the lines (title only; text may be empty).',\n \"- cards, steps, stats, faq: items, each with a title and a text. cards are features or services; steps are numbered; stats are a figure (title) with its label (text), only for figures the brief gives; faq items are a question (title) and its answer (text). Use no quotes block: the site has no customer's words to show.\",\n \"- form: places a saved form by its id in to. component: places a reusable component by its id in to; its items fill the component's props, title the prop name and text the value.\",\n '- style large on a heading makes the page title display-sized. icon (on a block or an item) is one of: ' +\n AI_ICON_WORDS.join(', ') +\n '.',\n '',\n \"Where a link goes (to): page:<page id> for a page of this site; #<n> for section n of this page (counted from 1); form for the site's form; phone or email to call or write to the phone number or email the brief gives; or an https: address the brief gives. A button the page has nowhere to send is left out. A to value is never written into words: in text, name a page by its title.\",\n '',\n \"Writing: plain, specific copy in the site's voice, from the brief, the business and its audience, never filler. Keep a page title under 70 characters and a section heading under 80. The site is published exactly as you write it, so where the brief leaves out a fact such as a price, a figure, a name, a phone number, an email, an address or opening hours, leave it out: write the sentence without it, and make no list line, card or contact row for it. Never write a placeholder or a gap in square brackets, and never invent the fact. Never invent a customer, a review, an award or a statistic.\",\n '',\n 'Design each page for this business and this request: choose the bands, the rows and the blocks that tell its story best, so no two sites read alike.',\n].join('\\n')\n\n// ── Reading an answer ────────────────────────────────────────────────────\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction text(value: unknown): string | undefined {\n return typeof value === 'string' && value.trim() ? value : undefined\n}\n\nfunction oneOf<T extends string>(\n value: unknown,\n values: readonly T[],\n): T | undefined {\n return typeof value === 'string' &&\n (values as readonly string[]).includes(value)\n ? (value as T)\n : undefined\n}\n\n/** What the reader settled on its own, for the job's record and the specs. */\nexport interface AiLayoutSettlement {\n /** Where: `sections[2].blocks[1]`, `header`. */\n at: string\n what: string\n}\n\nfunction readItem(raw: unknown): AiLayoutItem | null {\n if (!isRecord(raw)) return null\n const item: AiLayoutItem = {\n title: typeof raw['title'] === 'string' ? raw['title'] : '',\n text: typeof raw['text'] === 'string' ? raw['text'] : '',\n }\n if (!item.title.trim() && !item.text.trim()) return null\n const to = text(raw['to'])\n const icon = text(raw['icon'])\n return { ...item, ...(to ? { to } : {}), ...(icon ? { icon } : {}) }\n}\n\nfunction readBlock(\n raw: unknown,\n at: string,\n settled: AiLayoutSettlement[],\n): AiLayoutBlock | null {\n if (!isRecord(raw)) {\n settled.push({ at, what: 'not a block; left out' })\n return null\n }\n const kind = oneOf(raw['kind'], AI_LAYOUT_BLOCK_KINDS)\n if (!kind) {\n settled.push({\n at,\n what: `unknown kind ${JSON.stringify(raw['kind'] ?? null)}; left out`,\n })\n return null\n }\n const block: AiLayoutBlock = { kind }\n if (\n typeof raw['col'] === 'number' &&\n Number.isInteger(raw['col']) &&\n raw['col'] >= 0\n )\n block.col = raw['col']\n const words = text(raw['text'])\n if (words) block.text = words\n const to = text(raw['to'])\n if (to) block.to = to.trim()\n const style = oneOf(raw['style'], AI_LAYOUT_STYLES)\n if (style) block.style = style\n const icon = text(raw['icon'])\n if (icon) block.icon = icon.trim().toLowerCase()\n if (AI_LAYOUT_GROUP_KINDS.has(kind) || kind === 'component') {\n const items = (Array.isArray(raw['items']) ? raw['items'] : [])\n .map(readItem)\n .filter((item): item is AiLayoutItem => !!item)\n const most =\n kind === 'quotes'\n ? AI_LAYOUT_MAX_QUOTES\n : kind === 'component'\n ? Infinity\n : AI_LAYOUT_MAX_ITEMS\n if (items.length > most)\n settled.push({\n at,\n what: `${items.length} items; the first ${most} kept`,\n })\n if (items.length) block.items = items.slice(0, most)\n }\n // A block with nothing to show is no block: a group with no items, words\n // with no words. A form or a component may name its record alone.\n const empty = AI_LAYOUT_GROUP_KINDS.has(kind)\n ? !block.items?.length\n : kind === 'form' || kind === 'component'\n ? false\n : !block.text\n if (empty) {\n settled.push({ at, what: `an empty ${kind}; left out` })\n return null\n }\n return block\n}\n\n/** A section read from an answer, or `null` with why it could not be. */\nexport function aiReadLayoutSection(\n raw: unknown,\n at: string,\n settled: AiLayoutSettlement[],\n): AiLayoutSection | null {\n if (!isRecord(raw)) return null\n const section: AiLayoutSection = { blocks: [] }\n const band = oneOf(raw['band'], AI_LAYOUT_BANDS)\n if (band) section.band = band\n const align = oneOf(raw['align'], AI_LAYOUT_ALIGNS)\n if (align) section.align = align\n if (Array.isArray(raw['cols'])) {\n const cols = raw['cols'].filter(\n (value): value is number =>\n typeof value === 'number' && Number.isFinite(value) && value > 0,\n )\n if (cols.length > AI_LAYOUT_MAX_COLS) {\n settled.push({\n at: `${at}.cols`,\n what: `${cols.length} columns; the first ${AI_LAYOUT_MAX_COLS} kept`,\n })\n }\n if (cols.length >= 2)\n section.cols = cols\n .slice(0, AI_LAYOUT_MAX_COLS)\n .map((value) => Math.min(12, Math.max(1, Math.round(value))))\n }\n const blocks = Array.isArray(raw['blocks']) ? raw['blocks'] : []\n blocks.forEach((entry, index) => {\n const block = readBlock(entry, `${at}.blocks[${index}]`, settled)\n if (!block) return\n if (\n block.col !== undefined &&\n section.cols &&\n block.col >= section.cols.length\n ) {\n settled.push({\n at: `${at}.blocks[${index}]`,\n what: `column ${block.col} of ${section.cols.length}; placed in the last`,\n })\n block.col = section.cols.length - 1\n }\n if (block.col !== undefined && !section.cols) delete block.col\n section.blocks.push(block)\n })\n return section.blocks.length ? section : null\n}\n\n/** A page answer read: the sections it gave, by plan position, and the positions it could not. */\nexport interface AiLayoutPageReading {\n /** One entry per planned section; `null` where the answer gave nothing usable. */\n sections: Array<AiLayoutSection | null>\n settled: AiLayoutSettlement[]\n}\n\n/** What a planned section is, as the reader matches an answer's sections to it. */\nexport interface AiLayoutPlannedSection {\n name: string\n items: number\n /** What the plan places in it: a form it binds there is one of these. */\n uses?: readonly string[]\n}\n\n/** A planned section's name that asks for a form: a contact, an inquiry, a booking. */\nconst FORM_SECTION =\n /\\b(form|contact|get in touch|reach|write|message|inquir(?:y|ies|e)|enquir(?:y|ies|e)|book(?:ing|ings)?|reserv(?:e|ation|ations)|quote|appointments?|rsvp|sign ?up|subscribe|newsletter|apply|application|register)\\b/i\n\n/** Whether a planned section is one a form may fill: it names one, or the plan binds a form there. */\nfunction takesForm(planned: AiLayoutPlannedSection): boolean {\n return FORM_SECTION.test(planned.name) || (planned.uses ?? []).some((ref) => /\\bform\\b/i.test(ref))\n}\n\n/** What a form's section scores against a planned section that asks for no form: never chosen while another fits. */\nconst AI_LAYOUT_FORM_MISFIT = -100\n\n/**\n * A word as a heading and a plan's name are compared: letters in any script,\n * with their accents (AGL-3791). As ASCII, \"Menú\" was \"men\", which every\n * \"mensajes\" began with, and \"galería\" was \"galer\" and \"a\".\n */\nconst WORD = /[\\p{L}\\p{M}\\p{N}]+/gu\nconst STOP = new Set(['a', 'an', 'and', 'the', 'of', 'for', 'to', 'our', 'your', 'with', 'in', 'on', 'we', 'us', 'you'])\nconst wordsOf = (text: string) => new Set((text.toLowerCase().match(WORD) ?? []).filter((word) => !STOP.has(word)))\n\n/** The kinds that show a section's repeated items. */\nconst ITEM_KINDS = new Set(['list', 'cards', 'steps', 'stats', 'quotes', 'faq', 'component'])\n\n/**\n * How well an answer's section fits a planned one: the words its headings\n * share with the plan's name, and whether it shows items where the plan\n * asked for them and none where it asked for none.\n *\n * A shared heading word outweighs the items (AGL-3660): a live portfolio's\n * plan gave \"Works Gallery\" no items, and its \"Selected works\" cards lost the\n * place to an inquiry form that shared no word with it. A section holding a\n * form fills only a planned section that asks for one — by its name, or a\n * form the plan binds there — so the form is never a page's stand-in.\n */\nfunction fit(raw: unknown, planned: AiLayoutPlannedSection): number {\n const blocks = isRecord(raw) && Array.isArray(raw['blocks']) ? raw['blocks'].filter(isRecord) : []\n const said = wordsOf(\n blocks\n .filter((block) => block['kind'] === 'heading' || block['kind'] === 'eyebrow')\n .map((block) => String(block['text'] ?? ''))\n .join(' '),\n )\n const named = wordsOf(planned.name)\n let shared = 0\n for (const word of named) if (said.has(word) || [...said].some((other) => other.startsWith(word) || word.startsWith(other))) shared += 1\n const showsItems = blocks.some((block) => ITEM_KINDS.has(String(block['kind'])) && (block['kind'] === 'component' || (Array.isArray(block['items']) && block['items'].length > 0)))\n const wantsItems = planned.items > 0\n const holdsForm = blocks.some((block) => block['kind'] === 'form')\n if (holdsForm && !takesForm(planned)) return AI_LAYOUT_FORM_MISFIT\n return shared * 2 + (wantsItems === showsItems ? 0.5 : -0.5)\n}\n\n/**\n * The answer's sections that best match the plan, in order, where it gave\n * more than the plan names (AGL-3660): a model that opened a page with a\n * hero of its own, or closed it with a call to action, shifted every planned\n * section by one, and the cut fell on the plan's last sections — the ones\n * that carried its items. Each planned section takes the answer's section\n * that fits it best, keeping the answer's order.\n */\nfunction alignSections(given: readonly unknown[], planned: readonly AiLayoutPlannedSection[]): number[] {\n const n = given.length\n const m = planned.length\n // best[i][j]: the best score placing plan sections j.. on answer sections i..\n const best: number[][] = Array.from({ length: n + 1 }, () => Array(m + 1).fill(-Infinity))\n for (let i = 0; i <= n; i += 1) best[i][m] = 0\n for (let i = n - 1; i >= 0; i -= 1) {\n for (let j = m - 1; j >= 0; j -= 1) {\n if (n - i < m - j) continue\n best[i][j] = Math.max(best[i + 1][j], fit(given[i], planned[j]) + best[i + 1][j + 1])\n }\n }\n const picked: number[] = []\n let i = 0\n for (let j = 0; j < m; j += 1) {\n while (i < n && best[i][j] !== fit(given[i], planned[j]) + best[i + 1][j + 1]) i += 1\n picked.push(i)\n i += 1\n }\n return picked\n}\n\n/**\n * The page an answer describes, against the sections its plan names: each\n * planned section takes the answer's section at its position — or, where the\n * answer gave more sections than the plan names and the plan's sections are\n * given, the one that fits it best (`alignSections`) — an answer's extra\n * sections are left out, and a planned section the answer left empty or out\n * is `null` — the one thing a re-ask asks for again.\n */\nexport function aiReadLayoutPage(\n raw: unknown,\n planned: number,\n plan?: readonly AiLayoutPlannedSection[],\n): AiLayoutPageReading {\n const settled: AiLayoutSettlement[] = []\n const given =\n isRecord(raw) && Array.isArray(raw['sections']) ? raw['sections'] : []\n const aligned =\n given.length > planned && plan && plan.length === planned\n ? alignSections(given, plan)\n : Array.from({ length: planned }, (_, index) => index)\n if (given.length > planned) {\n settled.push({\n at: 'sections',\n what: `${given.length} sections for a plan of ${planned}; ${\n aligned.every((at, index) => at === index) ? 'the extra left out' : `sections ${aligned.map((at) => at + 1).join(', ')} kept as the plan's`\n }`,\n })\n }\n const sections = aligned.map((at, index) =>\n aiReadLayoutSection(given[at], `sections[${index}]`, settled),\n )\n return { sections, settled }\n}\n\n/** A frame answer read: a header and a footer, either `null` where it was not usable. */\nexport function aiReadLayoutFrame(raw: unknown): {\n header: AiLayoutSection | null\n footer: AiLayoutSection | null\n settled: AiLayoutSettlement[]\n} {\n const settled: AiLayoutSettlement[] = []\n const record = isRecord(raw) ? raw : {}\n // A header needs no block of its own: its brand and navigation are the\n // site's, so an empty one is a plain bar.\n const header = isRecord(record['header'])\n ? (aiReadLayoutSection(record['header'], 'header', settled) ??\n readBare(record['header']))\n : null\n const footer = aiReadLayoutSection(record['footer'], 'footer', settled)\n return { header, footer, settled }\n}\n\n/** A section with no usable block, keeping only its band and alignment. */\nfunction readBare(raw: Record<string, unknown>): AiLayoutSection {\n const band = oneOf(raw['band'], AI_LAYOUT_BANDS)\n const align = oneOf(raw['align'], AI_LAYOUT_ALIGNS)\n return { ...(band ? { band } : {}), ...(align ? { align } : {}), blocks: [] }\n}\n\n// ── The design of a page brought in (AGL-4107) ───────────────────────────\n\n/**\n * A page brought in from its owner's own website is laid out as its source\n * lays it out (AGL-4107): the reader reads its sections, bands, rows, groups,\n * pictures and icons (`site-import/site-import-layout.ts`), and code compiles\n * that structure with every word as written (`jobs/ai-site-import-compile.ts`).\n * The one question left for a model is the page's DESIGN, over the structure\n * it is shown: which hero the opening becomes around its picture, how each\n * group is drawn, a band where the source gave none, the kind of a group the\n * reader could not tell, and an alignment. The schema below names only those\n * choices, so no word of copy, no line and no structure has anywhere to go.\n */\n\n/** A section's choice where the source's own stands: its band, its alignment, a group's kind. */\nexport const AI_LAYOUT_DESIGN_SOURCE = 'source'\n\n/** The kinds a group the reader could not tell may be read as. */\nexport const AI_LAYOUT_DESIGN_GROUP_KINDS = ['cards', 'steps', 'stats', 'list'] as const\nexport type AiLayoutDesignGroupKind = (typeof AI_LAYOUT_DESIGN_GROUP_KINDS)[number]\n\n/** The bands a design answer may give a section the source drew on no band of its own. */\nexport const AI_LAYOUT_DESIGN_BANDS = ['plain', 'soft', 'dark'] as const\n\nexport interface AiLayoutDesignGroup {\n /** The group's kind, where the answer reads it otherwise than the reader did. */\n kind?: AiLayoutDesignGroupKind\n style?: AiLayoutGroupStyle\n}\n\nexport interface AiLayoutDesignSection {\n /** The hero the opening becomes, or `none` to keep it as the source lays it out. */\n hero?: AiLayoutImportHero | 'none'\n band?: (typeof AI_LAYOUT_DESIGN_BANDS)[number]\n align?: AiLayoutAlign\n /** One for each group of the section, in order. */\n groups: AiLayoutDesignGroup[]\n}\n\n/** A design answer read: one entry per section of the page, `null` where it gave none. */\nexport interface AiLayoutDesignAnswer {\n sections: Array<AiLayoutDesignSection | null>\n}\n\nconst DESIGN_GROUP_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['kind', 'style'],\n properties: {\n kind: { type: 'string', enum: [AI_LAYOUT_DESIGN_SOURCE, ...AI_LAYOUT_DESIGN_GROUP_KINDS] },\n style: { type: 'string', enum: [...AI_LAYOUT_GROUP_STYLES] },\n },\n} as const\n\nconst DESIGN_SECTION_SCHEMA = {\n type: 'object',\n additionalProperties: false,\n required: ['hero', 'band', 'align', 'groups'],\n properties: {\n hero: { type: 'string', enum: ['none', ...AI_LAYOUT_IMPORT_HEROES] },\n band: { type: 'string', enum: [AI_LAYOUT_DESIGN_SOURCE, ...AI_LAYOUT_DESIGN_BANDS] },\n align: { type: 'string', enum: [AI_LAYOUT_DESIGN_SOURCE, ...AI_LAYOUT_ALIGNS] },\n groups: { type: 'array', items: DESIGN_GROUP_SCHEMA },\n },\n} as const\n\n/** The design tool: one entry per section of a page brought in, in order, naming design choices only. */\nexport const AI_LAYOUT_DESIGN_TOOL: AiTool = {\n name: 'submit_design',\n description: \"Submit the page's design: one entry in sections for each section of the page, in order, with one entry in groups for each of its groups.\",\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['sections'],\n properties: { sections: { type: 'array', items: DESIGN_SECTION_SCHEMA } },\n },\n}\n\nfunction readDesignSection(raw: unknown): AiLayoutDesignSection | null {\n if (!isRecord(raw)) return null\n const section: AiLayoutDesignSection = { groups: [] }\n const hero = oneOf(raw['hero'], ['none', ...AI_LAYOUT_IMPORT_HEROES] as const)\n if (hero) section.hero = hero\n const band = oneOf(raw['band'], AI_LAYOUT_DESIGN_BANDS)\n if (band) section.band = band\n const align = oneOf(raw['align'], AI_LAYOUT_ALIGNS)\n if (align) section.align = align\n for (const entry of Array.isArray(raw['groups']) ? raw['groups'] : []) {\n const group: AiLayoutDesignGroup = {}\n if (isRecord(entry)) {\n const kind = oneOf(entry['kind'], AI_LAYOUT_DESIGN_GROUP_KINDS)\n if (kind) group.kind = kind\n const style = oneOf(entry['style'], AI_LAYOUT_GROUP_STYLES)\n if (style) group.style = style\n }\n section.groups.push(group)\n }\n return section\n}\n\n/**\n * A design answer read (AGL-4107): each section's choices by position, and\n * `null` for one it gave nothing usable for, which is then drawn as its\n * source has it. An answer carries no words, and none would be read.\n */\nexport function aiReadLayoutDesign(raw: unknown, sections: number): AiLayoutDesignAnswer {\n const given = isRecord(raw) && Array.isArray(raw['sections']) ? raw['sections'] : []\n return { sections: Array.from({ length: Math.max(0, sections) }, (_, index) => readDesignSection(given[index])) }\n}\n"],"names":["AI_ICON_WORDS","AI_LAYOUT_BLOCK_KINDS","AI_LAYOUT_GROUP_KINDS","Set","AI_LAYOUT_BANDS","AI_LAYOUT_ALIGNS","AI_LAYOUT_STYLES","AI_LAYOUT_MAX_COLS","AI_LAYOUT_MAX_ITEMS","AI_LAYOUT_MAX_QUOTES","AI_LAYOUT_IMPORT_BLOCK_KINDS","AI_LAYOUT_GROUP_STYLES","AI_LAYOUT_IMPORT_HEROES","ITEM_SCHEMA","type","additionalProperties","required","properties","title","text","to","icon","BLOCK_SCHEMA","kind","enum","col","style","items","SECTION_SCHEMA","band","cols","align","blocks","AI_LAYOUT_PAGE_TOOL","name","description","strict","inputSchema","sections","AI_LAYOUT_FRAME_TOOL","header","footer","AI_LAYOUT_LANGUAGE_TEXT","join","isRecord","value","Array","isArray","trim","undefined","oneOf","values","includes","readItem","raw","item","readBlock","at","settled","block","push","what","JSON","stringify","Number","isInteger","words","toLowerCase","has","map","filter","most","Infinity","length","slice","empty","aiReadLayoutSection","section","isFinite","Math","min","max","round","forEach","entry","index","FORM_SECTION","takesForm","planned","test","uses","some","ref","AI_LAYOUT_FORM_MISFIT","WORD","STOP","wordsOf","match","word","ITEM_KINDS","fit","said","String","named","shared","other","startsWith","showsItems","wantsItems","holdsForm","alignSections","given","n","m","best","from","fill","i","j","picked","aiReadLayoutPage","plan","aligned","_","every","aiReadLayoutFrame","record","readBare","AI_LAYOUT_DESIGN_SOURCE","AI_LAYOUT_DESIGN_GROUP_KINDS","AI_LAYOUT_DESIGN_BANDS","DESIGN_GROUP_SCHEMA","DESIGN_SECTION_SCHEMA","hero","groups","AI_LAYOUT_DESIGN_TOOL","readDesignSection","group","aiReadLayoutDesign"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,aAAa,QAAQ,gCAA4B;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDC,GAED,6DAA6D,GAC7D,OAAO,MAAMC,wBAAwB;IACnC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAIV,kCAAkC,GAClC,OAAO,MAAMC,wBAA6C,IAAIC,IAAuB;IACnF;IACA;IACA;IACA;IACA;IACA;CACD,EAAC;AAEF,OAAO,MAAMC,kBAAkB;IAAC;IAAS;IAAQ;IAAS;CAAO,CAAS;AAG1E,OAAO,MAAMC,mBAAmB;IAAC;IAAS;CAAS,CAAS;AAG5D,OAAO,MAAMC,mBAAmB;IAC9B;IACA;IACA;IACA;CACD,CAAS;AAGV,qEAAqE,GACrE,OAAO,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AAG,CAAC,WAAW,GAAG,EAAE;IACpF,OAAO;QAAEhB,UAAUQ,MAAMqE,IAAI,CAAC;YAAE1C,QAAQM,KAAKE,GAAG,CAAC,GAAG3C;QAAU,GAAG,CAACqF,GAAGtC,QAAUmD,kBAAkBzB,KAAK,CAAC1B,MAAM;IAAG;AAClH"}
|
|
@@ -0,0 +1,175 @@
|
|
|
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 { SiteImportBlock } from '../site-import/site-import-html';
|
|
18
|
+
import type { SiteImportBand, SiteImportFooter, SiteImportGroupKind, SiteImportLayout, SiteImportNavTree } from './ai-site-import';
|
|
19
|
+
/** The lowest score of structure a page brought in ships at (AGL-4109); words are held at exactly 1. */
|
|
20
|
+
export declare const SITE_IMPORT_FIDELITY_THRESHOLD = 0.9;
|
|
21
|
+
/** A node of a page or a layout, as the compiler draws it or Firestore stores it, decoded. */
|
|
22
|
+
export interface SiteImportFidelityNode {
|
|
23
|
+
componentId?: string;
|
|
24
|
+
props?: Record<string, unknown> | null;
|
|
25
|
+
sx?: Record<string, unknown> | null;
|
|
26
|
+
nodes?: readonly string[] | null;
|
|
27
|
+
parentId?: string | null;
|
|
28
|
+
interactions?: readonly unknown[] | null;
|
|
29
|
+
}
|
|
30
|
+
/** A built page or layout: its nodes and the one they hang from. */
|
|
31
|
+
export interface SiteImportFidelityTree {
|
|
32
|
+
rootId: string;
|
|
33
|
+
nodes: Readonly<Record<string, SiteImportFidelityNode>>;
|
|
34
|
+
}
|
|
35
|
+
/** What the source had, what the built page kept of it, and the share kept. */
|
|
36
|
+
export interface SiteImportFidelityCount {
|
|
37
|
+
source: number;
|
|
38
|
+
built: number;
|
|
39
|
+
ratio: number;
|
|
40
|
+
}
|
|
41
|
+
/** The words of a page: every one of the source's, as written, exactly once, and none of its own. */
|
|
42
|
+
export interface SiteImportFidelityWords {
|
|
43
|
+
/** Words the source's lines hold. */
|
|
44
|
+
source: number;
|
|
45
|
+
/** Words the built page shows. */
|
|
46
|
+
built: number;
|
|
47
|
+
/** The source's words the page does not show (counted as often as they are missing). */
|
|
48
|
+
missing: number;
|
|
49
|
+
/** Words the page shows that are not the source's, or are shown more often than the source says them. */
|
|
50
|
+
extra: number;
|
|
51
|
+
/** Words shown once each, over the larger of the two. */
|
|
52
|
+
ratio: number;
|
|
53
|
+
/** A few of the missing and extra words, for a report. */
|
|
54
|
+
examples: {
|
|
55
|
+
missing: string[];
|
|
56
|
+
extra: string[];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface SiteImportFidelityGroup {
|
|
60
|
+
/** Groups of the kind kept whole: every item of them its own element, with its parts. */
|
|
61
|
+
groups: SiteImportFidelityCount;
|
|
62
|
+
/** Items of the kind kept, each its own element with its parts. */
|
|
63
|
+
items: SiteImportFidelityCount;
|
|
64
|
+
}
|
|
65
|
+
/** A page brought in, scored against its source. */
|
|
66
|
+
export interface SiteImportPageFidelity {
|
|
67
|
+
/** The lowest ratio of the structure: what the page ships on, at `SITE_IMPORT_FIDELITY_THRESHOLD` or above. */
|
|
68
|
+
score: number;
|
|
69
|
+
/** The measure that set the score; `null` when every measure is whole. */
|
|
70
|
+
lowest: string | null;
|
|
71
|
+
words: SiteImportFidelityWords;
|
|
72
|
+
sections: SiteImportFidelityCount;
|
|
73
|
+
/** Sections drawn in the source's band, in order. */
|
|
74
|
+
bands: SiteImportFidelityCount & {
|
|
75
|
+
read: SiteImportBand[];
|
|
76
|
+
drawn: SiteImportBand[];
|
|
77
|
+
};
|
|
78
|
+
/** The source's rows of two or more columns, set side by side on the page. */
|
|
79
|
+
rows: SiteImportFidelityCount;
|
|
80
|
+
/** The source's groups by kind. A group of lines that only share a shape (`text`) is drawn as its lines, and is not scored. */
|
|
81
|
+
groups: Partial<Record<SiteImportGroupKind, SiteImportFidelityGroup>>;
|
|
82
|
+
tables: SiteImportFidelityCount;
|
|
83
|
+
tabs: SiteImportFidelityCount;
|
|
84
|
+
/** The source's pictures placed on the page. */
|
|
85
|
+
pictures: SiteImportFidelityCount;
|
|
86
|
+
/**
|
|
87
|
+
* The source's icons drawn: each group item's own, each bullet's mark. An
|
|
88
|
+
* icon standing alone in the source (a video's play mark) is no word and no
|
|
89
|
+
* picture of the page, and the build leaves it out (AGL-4107): it is
|
|
90
|
+
* counted in `lone` and not scored.
|
|
91
|
+
*/
|
|
92
|
+
icons: SiteImportFidelityCount & {
|
|
93
|
+
lone: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The lines the source draws as buttons that go somewhere (a page, an
|
|
97
|
+
* address, an email, a phone), drawn as buttons of the same style with
|
|
98
|
+
* their destinations. A button that goes nowhere a page can send a visitor
|
|
99
|
+
* (a film's play button its script runs) is kept as its words: counted in
|
|
100
|
+
* `unlinked`, not scored.
|
|
101
|
+
*/
|
|
102
|
+
buttons: SiteImportFidelityCount & {
|
|
103
|
+
unlinked: number;
|
|
104
|
+
};
|
|
105
|
+
/** The source's headings, drawn as headings. */
|
|
106
|
+
headings: SiteImportFidelityCount;
|
|
107
|
+
/** The source's forms, where the site has a form a page places. */
|
|
108
|
+
forms: SiteImportFidelityCount;
|
|
109
|
+
}
|
|
110
|
+
/** A page's source as the import read it: its layout over its main-region blocks, and its photos as the library holds them. */
|
|
111
|
+
export interface SiteImportFidelitySource {
|
|
112
|
+
layout: SiteImportLayout;
|
|
113
|
+
/** The page's main-region blocks, which the layout's lines are indexes of. */
|
|
114
|
+
blocks: readonly SiteImportBlock[];
|
|
115
|
+
/** The source's pictures as the site's library holds them (`from` → `src`); without them a picture is counted, not placed. */
|
|
116
|
+
photos?: ReadonlyArray<{
|
|
117
|
+
from?: string;
|
|
118
|
+
src: string;
|
|
119
|
+
}>;
|
|
120
|
+
}
|
|
121
|
+
/** A section's band as the compiler draws it: a dark scheme, the paper ground, the brand fill, else plain. */
|
|
122
|
+
export declare function siteImportFidelityBandOf(node: SiteImportFidelityNode | undefined): SiteImportBand;
|
|
123
|
+
/** The node a stored page or layout hangs from: the canvas root, else the one with no parent. */
|
|
124
|
+
export declare function siteImportFidelityTreeOf(nodes: Readonly<Record<string, SiteImportFidelityNode>>): SiteImportFidelityTree;
|
|
125
|
+
/**
|
|
126
|
+
* A built page scored against its source (AGL-4109): the words, each once;
|
|
127
|
+
* the sections and their bands; the rows of columns; the groups by kind, each
|
|
128
|
+
* item an element of its own with its parts; the tables, tabs, pictures,
|
|
129
|
+
* icons, buttons, headings and forms. The score is the lowest ratio of the
|
|
130
|
+
* structure.
|
|
131
|
+
*/
|
|
132
|
+
export declare function siteImportFidelity(source: SiteImportFidelitySource, tree: SiteImportFidelityTree): SiteImportPageFidelity;
|
|
133
|
+
/** A built header and footer, scored against the source's. */
|
|
134
|
+
export interface SiteImportFrameFidelity {
|
|
135
|
+
/** The lowest ratio of the header's and footer's measures. */
|
|
136
|
+
score: number;
|
|
137
|
+
lowest: string | null;
|
|
138
|
+
/** The source's top-level items, in the header's row, over the larger of the two (a row of page titles scores low). */
|
|
139
|
+
items: SiteImportFidelityCount;
|
|
140
|
+
/** Whether the row's items are in the source's order. */
|
|
141
|
+
inOrder: boolean;
|
|
142
|
+
/** The source's menus drawn as menus under their names. */
|
|
143
|
+
menus: SiteImportFidelityCount;
|
|
144
|
+
/** The source's menu entries, each a link in its menu. */
|
|
145
|
+
entries: SiteImportFidelityCount;
|
|
146
|
+
/** The lines under entries and their icons, in their menus. */
|
|
147
|
+
details: SiteImportFidelityCount;
|
|
148
|
+
/** The header's buttons, drawn as the source draws them, each with its destination. */
|
|
149
|
+
ctas: SiteImportFidelityCount;
|
|
150
|
+
/** Everything of the row in the phone menu: each menu's name and entries, the links, the buttons. */
|
|
151
|
+
drawer: SiteImportFidelityCount;
|
|
152
|
+
/** A menu button shown where the row is not, opening the phone menu. */
|
|
153
|
+
phone: SiteImportFidelityCount;
|
|
154
|
+
/** The row's labels held to one line. */
|
|
155
|
+
nowrap: SiteImportFidelityCount;
|
|
156
|
+
/** The footer's columns under their headings. */
|
|
157
|
+
columns: SiteImportFidelityCount;
|
|
158
|
+
/** The footer's links, its columns' and its own. */
|
|
159
|
+
links: SiteImportFidelityCount;
|
|
160
|
+
/** Its profiles on other sites. */
|
|
161
|
+
social: SiteImportFidelityCount;
|
|
162
|
+
/** Its words, address, phone, email and © line, word for word. */
|
|
163
|
+
facts: SiteImportFidelityCount;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A built header and footer scored against the source's (AGL-4109): the
|
|
167
|
+
* header's top-level items in order, each menu's entries with the lines and
|
|
168
|
+
* icons under them, its buttons, the phone menu holding all of it, the row's
|
|
169
|
+
* labels on one line; the footer's columns, links, profiles and facts. The
|
|
170
|
+
* score is the lowest ratio.
|
|
171
|
+
*/
|
|
172
|
+
export declare function siteImportFrameFidelity(source: {
|
|
173
|
+
nav: SiteImportNavTree | null | undefined;
|
|
174
|
+
footer: SiteImportFooter | null | undefined;
|
|
175
|
+
}, tree: SiteImportFidelityTree): SiteImportFrameFidelity;
|