@aglyn/plugins-ai 1.21.0 → 1.22.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.
Files changed (38) hide show
  1. package/package.json +18 -18
  2. package/src/lib/jobs/ai-job-import-step.d.ts +8 -0
  3. package/src/lib/jobs/ai-job-import-step.js +19 -2
  4. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  5. package/src/lib/jobs/ai-job-page-language.d.ts +8 -0
  6. package/src/lib/jobs/ai-job-page-language.js +127 -26
  7. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  8. package/src/lib/jobs/ai-job-page-step.d.ts +10 -0
  9. package/src/lib/jobs/ai-job-page-step.js +23 -1
  10. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  11. package/src/lib/jobs/ai-site-import-actions.d.ts +12 -3
  12. package/src/lib/jobs/ai-site-import-actions.js +43 -18
  13. package/src/lib/jobs/ai-site-import-actions.js.map +1 -1
  14. package/src/lib/jobs/ai-site-import-improve.d.ts +170 -5
  15. package/src/lib/jobs/ai-site-import-improve.js +508 -46
  16. package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
  17. package/src/lib/layout-language/ai-layout-compiler.d.ts +6 -0
  18. package/src/lib/layout-language/ai-layout-compiler.js +10 -4
  19. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  20. package/src/lib/layout-language/ai-layout-frame.js +11 -2
  21. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  22. package/src/lib/layout-language/ai-layout-gaps.d.ts +27 -0
  23. package/src/lib/layout-language/ai-layout-gaps.js +124 -0
  24. package/src/lib/layout-language/ai-layout-gaps.js.map +1 -1
  25. package/src/lib/layout-language/ai-layout-language.d.ts +5 -0
  26. package/src/lib/layout-language/ai-layout-language.js +46 -1
  27. package/src/lib/layout-language/ai-layout-language.js.map +1 -1
  28. package/src/lib/model/ai-site-import-fidelity.d.ts +14 -1
  29. package/src/lib/model/ai-site-import-fidelity.js +25 -1
  30. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  31. package/src/lib/runtime/ai-doctrine.d.ts +3 -1
  32. package/src/lib/runtime/ai-doctrine.js +4 -1
  33. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  34. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +9 -8
  35. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  36. package/src/lib/site-import/site-import-page.d.ts +2 -2
  37. package/src/lib/site-import/site-import-page.js +42 -2
  38. package/src/lib/site-import/site-import-page.js.map +1 -1
@@ -23,6 +23,18 @@
23
23
  import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
24
24
  const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : '';
25
25
  /** A button's words and where it goes, as one key: two that share it are the same action. */ const actionKey = (text, to)=>`${clean(text).toLowerCase()}\u0000${to != null ? to : ''}`;
26
+ /** How strongly a button asks: filled 0, outlined 1, quiet 2. */ const strength = (block)=>filled(block) ? 0 : block.style === 'secondary' ? 1 : 2;
27
+ /**
28
+ * Where a button goes, as two that go to one place share it (AGL-4152): a
29
+ * phone by its digits, an email and a web address in any case and without a
30
+ * trailing slash, anything else as written.
31
+ */ export function aiSiteImportDestinationKey(to) {
32
+ const value = to.trim();
33
+ if (/^tel:/i.test(value)) return `tel:${value.slice(4).replace(/[^\d+]/g, '')}`;
34
+ if (/^mailto:/i.test(value)) return value.toLowerCase();
35
+ if (/^https?:\/\//i.test(value)) return value.toLowerCase().replace(/^http:/, 'https:').replace(/[/?#]+$/, '');
36
+ return value;
37
+ }
26
38
  /** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */ const filled = (block)=>block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large');
27
39
  /**
28
40
  * A redesigned section's calls to action, each once and each where it belongs
@@ -37,9 +49,12 @@ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim(
37
49
  * group, unless the section already has that button. Where only some items
38
50
  * carry it, each is that item's own action and stays.
39
51
  * - The same button twice in a section is shown once, the first.
40
- * - Two buttons side by side to the same place are one: the one with the
41
- * header's words where one has them, else the first. Of buttons side by
42
- * side, only the first is filled; the rest are outlined.
52
+ * - Buttons anywhere in a section to the same place are one: the strongest,
53
+ * filled over outlined over quiet, the first of equals, with the header's
54
+ * words where one of them has them. A call and a page are two places. A
55
+ * closing band's "Contact us" and "Request a quote", both to the contact
56
+ * page with a call between them, read as a mistake.
57
+ * - Of buttons side by side, only the first is filled; the rest are outlined.
43
58
  */ export function aiSiteImportSectionActions(section, cta) {
44
59
  let { cols, blocks } = section;
45
60
  // Buttons in columns under a group across the row.
@@ -173,8 +188,32 @@ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim(
173
188
  seen.add(key);
174
189
  return true;
175
190
  });
176
- // Buttons side by side: one to each place, the first filled.
191
+ // Buttons anywhere in the section to one place: one, the strongest (filled over outlined over quiet), the first of
192
+ // equals, in its own place; with the header's words where one of them has them. A call and a page are two places.
177
193
  const wanted = clean(cta).toLowerCase();
194
+ const kept = new Map();
195
+ const worded = new Map();
196
+ for (const block of blocks){
197
+ if (block.kind !== 'button' || !block.to) continue;
198
+ const key = aiSiteImportDestinationKey(block.to);
199
+ const was = kept.get(key);
200
+ if (!was || strength(block) < strength(was)) kept.set(key, block);
201
+ if (wanted && clean(block.text).toLowerCase() === wanted && !worded.has(key)) worded.set(key, block);
202
+ }
203
+ blocks = blocks.flatMap((block)=>{
204
+ if (block.kind !== 'button' || !block.to) return [
205
+ block
206
+ ];
207
+ const key = aiSiteImportDestinationKey(block.to);
208
+ if (kept.get(key) !== block) return [];
209
+ const words = worded.get(key);
210
+ return [
211
+ words && clean(block.text).toLowerCase() !== wanted ? _extends({}, block, {
212
+ text: words.text
213
+ }) : block
214
+ ];
215
+ });
216
+ // Buttons side by side, each to its own place: the first filled.
178
217
  const out = [];
179
218
  for (const block of blocks){
180
219
  const before = out[out.length - 1];
@@ -184,20 +223,6 @@ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim(
184
223
  let start = out.length - 1;
185
224
  while(start > 0 && ((_out_ = out[start - 1]) == null ? void 0 : _out_.kind) === 'button' && ((_out_1 = out[start - 1]) == null ? void 0 : _out_1.col) === block.col)start -= 1;
186
225
  const run = out.slice(start);
187
- const same = block.to ? run.findIndex((entry)=>entry.to === block.to) : -1;
188
- if (same !== -1) {
189
- // The header's words win the place; the run keeps its first button's place and fill.
190
- const kept = run[same];
191
- if (wanted && clean(block.text).toLowerCase() === wanted && clean(kept.text).toLowerCase() !== wanted) {
192
- const { style: _style } = block, words = _object_without_properties_loose(block, [
193
- "style"
194
- ]);
195
- out[start + same] = _extends({}, words, kept.style ? {
196
- style: kept.style
197
- } : {});
198
- }
199
- continue;
200
- }
201
226
  out.push(run.some(filled) && filled(block) ? _extends({}, block, {
202
227
  style: 'secondary'
203
228
  }) : block);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-actions.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'S CALLS TO ACTION UNDER IMPROVE IT (AGL-4152).\n *\n * The mechanical tidying of a section's buttons, the same whether a\n * redesign drew the page or the page kept its source's layout: each call to\n * action once, where it belongs. No model is asked; nothing is reworded.\n *=========================================*/\n\nimport type { AiLayoutBlock, AiLayoutItem, AiLayoutSection } from '../layout-language/ai-layout-language'\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** A button's words and where it goes, as one key: two that share it are the same action. */\nconst actionKey = (text: string | undefined, to: string | undefined): string => `${clean(text).toLowerCase()}\\u0000${to ?? ''}`\n\n/** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */\nconst filled = (block: AiLayoutBlock): boolean => block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large')\n\n/**\n * A redesigned section's calls to action, each once and each where it belongs\n * (AGL-4152), whatever the answer and the source's kept groups gave:\n *\n * - Buttons placed in a row's columns under a group that runs the row's width,\n * with nothing else in those columns, sit in the cards they go to where each\n * goes where exactly one card does, else together under the group: a row of\n * two buttons under three cards read as a grid half filled.\n * - A link with the same words to the same place on every item of a group\n * (each review's \"See more reviews\") is shown once, as a button after the\n * group, unless the section already has that button. Where only some items\n * carry it, each is that item's own action and stays.\n * - The same button twice in a section is shown once, the first.\n * - Two buttons side by side to the same place are one: the one with the\n * header's words where one has them, else the first. Of buttons side by\n * side, only the first is filled; the rest are outlined.\n */\nexport function aiSiteImportSectionActions(section: Pick<AiLayoutSection, 'cols' | 'blocks'>, cta?: string | null): Pick<AiLayoutSection, 'cols' | 'blocks'> {\n let { cols, blocks } = section\n // Buttons in columns under a group across the row.\n const placed = blocks.filter((block) => block.col !== undefined)\n const group = blocks.find((block) => block.col === undefined && (block.items?.length ?? 0) >= 2 && block.kind !== 'list' && block.kind !== 'faq')\n if (cols && cols.length >= 2 && group && placed.length && placed.every((block) => block.kind === 'button')) {\n const items = group.items as AiLayoutItem[]\n const cards = placed.map((button) => items.flatMap((item, at) => (button.to && item.to === button.to && !item.links?.length ? [at] : [])))\n const own = cards.every((found) => found.length === 1) && new Set(cards.map((found) => found[0])).size === cards.length\n if (own) {\n const into = new Map(placed.map((button, at) => [cards[at]?.[0] as number, button]))\n const carded = { ...group, items: items.map((item, at) => (into.has(at) ? { ...item, links: [{ text: into.get(at)?.text ?? '', to: item.to as string, style: 'secondary' as const }] } : item)) }\n blocks = blocks.flatMap((block) => (block === group ? [carded] : placed.includes(block) ? [] : [block]))\n } else blocks = blocks.map((block) => (placed.includes(block) ? (({ col: _col, ...rest }) => rest)(block) : block))\n cols = undefined\n }\n // A link repeated across a group's items, once after the group.\n const buttons = new Set(blocks.flatMap((block) => (block.kind === 'button' ? [actionKey(block.text, block.to)] : [])))\n blocks = blocks.flatMap((block) => {\n const items = block.items\n if (!items || items.length < 2) return [block]\n const counted = new Map<string, { text: string; to?: string; style?: AiLayoutBlock['style']; on: number }>()\n for (const item of items) {\n for (const key of new Set((item.links ?? []).map((link) => actionKey(link.text, link.to)))) {\n const link = item.links?.find((entry) => actionKey(entry.text, entry.to) === key)\n const was = counted.get(key)\n if (link) counted.set(key, { text: link.text, ...(link.to ? { to: link.to } : {}), ...(link.style ? { style: link.style } : {}), on: (was?.on ?? 0) + 1 })\n }\n }\n const repeated = new Map([...counted].filter(([, entry]) => entry.on === items.length))\n if (!repeated.size) return [block]\n const stripped = items.map((item) => {\n if (!item.links?.length) return item\n const links = item.links.filter((link) => !repeated.has(actionKey(link.text, link.to)))\n const { links: _links, ...rest } = item\n return links.length ? { ...rest, links } : rest\n })\n const after = [...repeated].flatMap(([key, entry]): AiLayoutBlock[] => {\n if (buttons.has(key)) return []\n buttons.add(key)\n return [{ kind: 'button', text: entry.text, ...(entry.to ? { to: entry.to } : {}), ...(entry.style ? { style: entry.style } : {}), ...(block.col !== undefined ? { col: block.col } : {}) }]\n })\n return [{ ...block, items: stripped }, ...after]\n })\n // The same button twice, once.\n const seen = new Set<string>()\n blocks = blocks.filter((block) => {\n if (block.kind !== 'button' || !block.to) return true\n const key = actionKey(block.text, block.to)\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n // Buttons side by side: one to each place, the first filled.\n const wanted = clean(cta).toLowerCase()\n const out: AiLayoutBlock[] = []\n for (const block of blocks) {\n const before = out[out.length - 1]\n if (block.kind === 'button' && before?.kind === 'button' && before.col === block.col) {\n // Back over the run this button stands in.\n let start = out.length - 1\n while (start > 0 && out[start - 1]?.kind === 'button' && out[start - 1]?.col === block.col) start -= 1\n const run = out.slice(start)\n const same = block.to ? run.findIndex((entry) => entry.to === block.to) : -1\n if (same !== -1) {\n // The header's words win the place; the run keeps its first button's place and fill.\n const kept = run[same] as AiLayoutBlock\n if (wanted && clean(block.text).toLowerCase() === wanted && clean(kept.text).toLowerCase() !== wanted) {\n const { style: _style, ...words } = block\n out[start + same] = { ...words, ...(kept.style ? { style: kept.style } : {}) }\n }\n continue\n }\n out.push(run.some(filled) && filled(block) ? { ...block, style: 'secondary' } : block)\n continue\n }\n out.push(block)\n }\n return { ...(cols ? { cols } : {}), blocks: out }\n}\n"],"names":["clean","text","replace","trim","actionKey","to","toLowerCase","filled","block","kind","style","undefined","aiSiteImportSectionActions","section","cta","cols","blocks","placed","filter","col","group","find","items","length","every","cards","map","button","flatMap","item","at","links","own","found","Set","size","into","Map","carded","has","get","includes","_col","rest","buttons","counted","key","link","entry","was","set","on","repeated","stripped","_links","after","add","seen","wanted","out","before","start","run","slice","same","findIndex","kept","_style","words","push","some"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;2CAM2C;;AAI3C,MAAMA,QAAQ,CAACC,OAA2B,OAAOA,SAAS,WAAWA,KAAKC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAExG,2FAA2F,GAC3F,MAAMC,YAAY,CAACH,MAA0BI,KAAmC,GAAGL,MAAMC,MAAMK,WAAW,GAAG,MAAM,EAAED,aAAAA,KAAM,IAAI;AAE/H,oFAAoF,GACpF,MAAME,SAAS,CAACC,QAAkCA,MAAMC,IAAI,KAAK,YAAaD,CAAAA,MAAME,KAAK,KAAKC,aAAaH,MAAME,KAAK,KAAK,aAAaF,MAAME,KAAK,KAAK,OAAM;AAE9J;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASE,2BAA2BC,OAAiD,EAAEC,GAAmB;IAC/G,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAE,GAAGH;I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MH,EAAE,IAAI,CAAC;YAC3E,IAAI2D,SAAS,CAAC,GAAG;gBACf,qFAAqF;gBACrF,MAAME,OAAOJ,GAAG,CAACE,KAAK;gBACtB,IAAIN,UAAU1D,MAAMQ,MAAMP,IAAI,EAAEK,WAAW,OAAOoD,UAAU1D,MAAMkE,KAAKjE,IAAI,EAAEK,WAAW,OAAOoD,QAAQ;oBACrG,MAAM,EAAEhD,OAAOyD,MAAM,EAAY,GAAG3D,OAAV4D,yCAAU5D;;;oBACpCmD,GAAG,CAACE,QAAQG,KAAK,GAAG,aAAKI,OAAWF,KAAKxD,KAAK,GAAG;wBAAEA,OAAOwD,KAAKxD,KAAK;oBAAC,IAAI,CAAC;gBAC5E;gBACA;YACF;YACAiD,IAAIU,IAAI,CAACP,IAAIQ,IAAI,CAAC/D,WAAWA,OAAOC,SAAS,aAAKA;gBAAOE,OAAO;iBAAgBF;YAChF;QACF;QACAmD,IAAIU,IAAI,CAAC7D;IACX;IACA,OAAO,aAAMO,OAAO;QAAEA;IAAK,IAAI,CAAC;QAAIC,QAAQ2C;;AAC9C"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-actions.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'S CALLS TO ACTION UNDER IMPROVE IT (AGL-4152).\n *\n * The mechanical tidying of a section's buttons, the same whether a\n * redesign drew the page or the page kept its source's layout: each call to\n * action once, where it belongs. No model is asked; nothing is reworded.\n *=========================================*/\n\nimport type { AiLayoutBlock, AiLayoutItem, AiLayoutSection } from '../layout-language/ai-layout-language'\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** A button's words and where it goes, as one key: two that share it are the same action. */\nconst actionKey = (text: string | undefined, to: string | undefined): string => `${clean(text).toLowerCase()}\\u0000${to ?? ''}`\n\n/** How strongly a button asks: filled 0, outlined 1, quiet 2. */\nconst strength = (block: AiLayoutBlock): number => (filled(block) ? 0 : block.style === 'secondary' ? 1 : 2)\n\n/**\n * Where a button goes, as two that go to one place share it (AGL-4152): a\n * phone by its digits, an email and a web address in any case and without a\n * trailing slash, anything else as written.\n */\nexport function aiSiteImportDestinationKey(to: string): string {\n const value = to.trim()\n if (/^tel:/i.test(value)) return `tel:${value.slice(4).replace(/[^\\d+]/g, '')}`\n if (/^mailto:/i.test(value)) return value.toLowerCase()\n if (/^https?:\\/\\//i.test(value)) return value.toLowerCase().replace(/^http:/, 'https:').replace(/[/?#]+$/, '')\n return value\n}\n\n/** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */\nconst filled = (block: AiLayoutBlock): boolean => block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large')\n\n/**\n * A redesigned section's calls to action, each once and each where it belongs\n * (AGL-4152), whatever the answer and the source's kept groups gave:\n *\n * - Buttons placed in a row's columns under a group that runs the row's width,\n * with nothing else in those columns, sit in the cards they go to where each\n * goes where exactly one card does, else together under the group: a row of\n * two buttons under three cards read as a grid half filled.\n * - A link with the same words to the same place on every item of a group\n * (each review's \"See more reviews\") is shown once, as a button after the\n * group, unless the section already has that button. Where only some items\n * carry it, each is that item's own action and stays.\n * - The same button twice in a section is shown once, the first.\n * - Buttons anywhere in a section to the same place are one: the strongest,\n * filled over outlined over quiet, the first of equals, with the header's\n * words where one of them has them. A call and a page are two places. A\n * closing band's \"Contact us\" and \"Request a quote\", both to the contact\n * page with a call between them, read as a mistake.\n * - Of buttons side by side, only the first is filled; the rest are outlined.\n */\nexport function aiSiteImportSectionActions(section: Pick<AiLayoutSection, 'cols' | 'blocks'>, cta?: string | null): Pick<AiLayoutSection, 'cols' | 'blocks'> {\n let { cols, blocks } = section\n // Buttons in columns under a group across the row.\n const placed = blocks.filter((block) => block.col !== undefined)\n const group = blocks.find((block) => block.col === undefined && (block.items?.length ?? 0) >= 2 && block.kind !== 'list' && block.kind !== 'faq')\n if (cols && cols.length >= 2 && group && placed.length && placed.every((block) => block.kind === 'button')) {\n const items = group.items as AiLayoutItem[]\n const cards = placed.map((button) => items.flatMap((item, at) => (button.to && item.to === button.to && !item.links?.length ? [at] : [])))\n const own = cards.every((found) => found.length === 1) && new Set(cards.map((found) => found[0])).size === cards.length\n if (own) {\n const into = new Map(placed.map((button, at) => [cards[at]?.[0] as number, button]))\n const carded = { ...group, items: items.map((item, at) => (into.has(at) ? { ...item, links: [{ text: into.get(at)?.text ?? '', to: item.to as string, style: 'secondary' as const }] } : item)) }\n blocks = blocks.flatMap((block) => (block === group ? [carded] : placed.includes(block) ? [] : [block]))\n } else blocks = blocks.map((block) => (placed.includes(block) ? (({ col: _col, ...rest }) => rest)(block) : block))\n cols = undefined\n }\n // A link repeated across a group's items, once after the group.\n const buttons = new Set(blocks.flatMap((block) => (block.kind === 'button' ? [actionKey(block.text, block.to)] : [])))\n blocks = blocks.flatMap((block) => {\n const items = block.items\n if (!items || items.length < 2) return [block]\n const counted = new Map<string, { text: string; to?: string; style?: AiLayoutBlock['style']; on: number }>()\n for (const item of items) {\n for (const key of new Set((item.links ?? []).map((link) => actionKey(link.text, link.to)))) {\n const link = item.links?.find((entry) => actionKey(entry.text, entry.to) === key)\n const was = counted.get(key)\n if (link) counted.set(key, { text: link.text, ...(link.to ? { to: link.to } : {}), ...(link.style ? { style: link.style } : {}), on: (was?.on ?? 0) + 1 })\n }\n }\n const repeated = new Map([...counted].filter(([, entry]) => entry.on === items.length))\n if (!repeated.size) return [block]\n const stripped = items.map((item) => {\n if (!item.links?.length) return item\n const links = item.links.filter((link) => !repeated.has(actionKey(link.text, link.to)))\n const { links: _links, ...rest } = item\n return links.length ? { ...rest, links } : rest\n })\n const after = [...repeated].flatMap(([key, entry]): AiLayoutBlock[] => {\n if (buttons.has(key)) return []\n buttons.add(key)\n return [{ kind: 'button', text: entry.text, ...(entry.to ? { to: entry.to } : {}), ...(entry.style ? { style: entry.style } : {}), ...(block.col !== undefined ? { col: block.col } : {}) }]\n })\n return [{ ...block, items: stripped }, ...after]\n })\n // The same button twice, once.\n const seen = new Set<string>()\n blocks = blocks.filter((block) => {\n if (block.kind !== 'button' || !block.to) return true\n const key = actionKey(block.text, block.to)\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n // Buttons anywhere in the section to one place: one, the strongest (filled over outlined over quiet), the first of\n // equals, in its own place; with the header's words where one of them has them. A call and a page are two places.\n const wanted = clean(cta).toLowerCase()\n const kept = new Map<string, AiLayoutBlock>()\n const worded = new Map<string, AiLayoutBlock>()\n for (const block of blocks) {\n if (block.kind !== 'button' || !block.to) continue\n const key = aiSiteImportDestinationKey(block.to)\n const was = kept.get(key)\n if (!was || strength(block) < strength(was)) kept.set(key, block)\n if (wanted && clean(block.text).toLowerCase() === wanted && !worded.has(key)) worded.set(key, block)\n }\n blocks = blocks.flatMap((block) => {\n if (block.kind !== 'button' || !block.to) return [block]\n const key = aiSiteImportDestinationKey(block.to)\n if (kept.get(key) !== block) return []\n const words = worded.get(key)\n return [words && clean(block.text).toLowerCase() !== wanted ? { ...block, text: words.text } : block]\n })\n // Buttons side by side, each to its own place: the first filled.\n const out: AiLayoutBlock[] = []\n for (const block of blocks) {\n const before = out[out.length - 1]\n if (block.kind === 'button' && before?.kind === 'button' && before.col === block.col) {\n // Back over the run this button stands in.\n let start = out.length - 1\n while (start > 0 && out[start - 1]?.kind === 'button' && out[start - 1]?.col === block.col) start -= 1\n const run = out.slice(start)\n out.push(run.some(filled) && filled(block) ? { ...block, style: 'secondary' } : block)\n continue\n }\n out.push(block)\n }\n return { ...(cols ? { cols } : {}), blocks: out }\n}\n"],"names":["clean","text","replace","trim","actionKey","to","toLowerCase","strength","block","filled","style","aiSiteImportDestinationKey","value","test","slice","kind","undefined","aiSiteImportSectionActions","section","cta","cols","blocks","placed","filter","col","group","find","items","length","every","cards","map","button","flatMap","item","at","links","own","found","Set","size","into","Map","carded","has","get","includes","_col","rest","buttons","counted","key","link","entry","was","set","on","repeated","stripped","_links","after","add","seen","wanted","kept","worded","words","out","before","start","run","push","some"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;2CAM2C;;AAI3C,MAAMA,QAAQ,CAACC,OAA2B,OAAOA,SAAS,WAAWA,KAAKC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAExG,2FAA2F,GAC3F,MAAMC,YAAY,CAACH,MAA0BI,KAAmC,GAAGL,MAAMC,MAAMK,WAAW,GAAG,MAAM,EAAED,aAAAA,KAAM,IAAI;AAE/H,+DAA+D,GAC/D,MAAME,WAAW,CAACC,QAAkCC,OAAOD,SAAS,IAAIA,MAAME,KAAK,KAAK,cAAc,IAAI;AAE1G;;;;CAIC,GACD,OAAO,SAASC,2BAA2BN,EAAU;IACnD,MAAMO,QAAQP,GAAGF,IAAI;IACrB,IAAI,SAASU,IAAI,CAACD,QAAQ,OAAO,CAAC,IAAI,EAAEA,MAAME,KAAK,CAAC,GAAGZ,OAAO,CAAC,WAAW,KAAK;IAC/E,IAAI,YAAYW,IAAI,CAACD,QAAQ,OAAOA,MAAMN,WAAW;IACrD,IAAI,gBAAgBO,IAAI,CAACD,QAAQ,OAAOA,MAAMN,WAAW,GAAGJ,OAAO,CAAC,UAAU,UAAUA,OAAO,CAAC,WAAW;IAC3G,OAAOU;AACT;AAEA,oFAAoF,GACpF,MAAMH,SAAS,CAACD,QAAkCA,MAAMO,IAAI,KAAK,YAAaP,CAAAA,MAAME,KAAK,KAAKM,aAAaR,MAAME,KAAK,KAAK,aAAaF,MAAME,KAAK,KAAK,OAAM;AAE9J;;;;;;;;;;;;;;;;;;;CA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what it needs (`aiSiteImportImproveRoleLines`). */
98
98
  roleLines?: readonly string[];
99
+ /** How much page its answer has room for, and whether it is thin (`aiSiteImportImproveSizeLines`). */
100
+ sizeLines?: readonly string[];
99
101
  }): string;
100
102
  /**
101
103
  * How many new sections a page of each role is asked for (AGL-4152): a home
@@ -211,6 +213,8 @@ export interface AiSiteImportImprovedPage {
211
213
  written: string[];
212
214
  added: AiSiteImportAddedSection[];
213
215
  pictures: AiSiteImportPagePictures;
216
+ /** What code mended of the answer before it was drawn (AGL-4152): sections left a heading alone, card rows evened. For the page's log. */
217
+ mended: string[];
214
218
  }
215
219
  /**
216
220
  * The opening of a redesign without a brand's mark for its photo (AGL-4152):
@@ -225,6 +229,46 @@ export declare function aiSiteImportOpeningPhoto(answer: readonly AiSiteImportIm
225
229
  doc: Pick<AiSiteImportDocument, 'blocks' | 'photos'>;
226
230
  ledger: Pick<SiteImportLedger, 'items'>;
227
231
  }): AiSiteImportImprovedSection[];
232
+ /**
233
+ * A redesign's sections with none left a heading alone (AGL-4152). A section
234
+ * after the opening whose blocks are only a heading or an eyebrow (or a
235
+ * `keep` that draws nothing) is, in order:
236
+ *
237
+ * 1. refilled from the old section its heading names, where that section's
238
+ * things are on the page nowhere: its group of like items kept whole, else
239
+ * its lines as written, as a list. A thin page's "What we handle" over its
240
+ * four kinds of work came out the heading alone, the work nowhere.
241
+ * 2. else handed to the next section, as its heading, where that one has none.
242
+ * 3. else left out.
243
+ *
244
+ * What was done to each is said in `hollow`, for the page's log.
245
+ */
246
+ export declare function aiSiteImportFilledSections(answer: readonly AiSiteImportImprovedSection[], input: {
247
+ doc: Pick<AiSiteImportDocument, 'blocks'>;
248
+ ledger: Pick<SiteImportLedger, 'items' | 'lines'>;
249
+ }): {
250
+ sections: AiSiteImportImprovedSection[];
251
+ hollow: string[];
252
+ asWritten: Set<AiSiteImportImprovedBlock>;
253
+ };
254
+ /**
255
+ * How many cards of a row show a picture (AGL-4152): every card or none, as
256
+ * most of them do, and none on a tie. Each card's picture is its own ref, else
257
+ * the one `carded` gave it; a row most of whose cards show one gives the rest
258
+ * the page's own photos no section places first, the photos whose words they
259
+ * say before any other, and a slot the page step fills (its unplaced photos,
260
+ * then stock, then one generated only where pictures are on) for any left.
261
+ * Icons the same way: on every card or on none.
262
+ */
263
+ export declare function aiSiteImportEvenCards(answer: readonly AiSiteImportImprovedSection[], input: {
264
+ doc: Pick<AiSiteImportDocument, 'blocks' | 'photos'>;
265
+ ledger: Pick<SiteImportLedger, 'items' | 'lines'>;
266
+ carded: ReadonlyMap<AiSiteImportImprovedBlock, string[]>;
267
+ }): {
268
+ sections: AiSiteImportImprovedSection[];
269
+ slots: Map<AiSiteImportImprovedBlock, Set<number>>;
270
+ evened: string[];
271
+ };
228
272
  /** The sections a redesign holds, in the compiler's language: every `keep` expanded to the source's own blocks, every link resolved. */
229
273
  export declare function aiSiteImportImprovedPage(given: readonly AiSiteImportImprovedSection[], input: AiSiteImportImproveCompileInput): AiSiteImportImprovedPage;
230
274
  /** The most an answer may ask for, whatever the page and the model: a whole page's design and words, with its thinking. */
@@ -241,12 +285,28 @@ export declare const AI_SITE_IMPORT_LISTING_ROOM_CREDITS = 10;
241
285
  * ceiling buys, and a re-ask it cannot pay for is not asked.
242
286
  */
243
287
  export declare const AI_SITE_IMPORT_IMPROVE_CEILING_CREDITS: number;
244
- /** What a request reads before it is sent, at worst: its system blocks written to the cache, its turn as input. */
288
+ /**
289
+ * The provider's own words that ride every request offering a tool, ahead of
290
+ * the tools, in the cached prefix: its published count for the tool-use
291
+ * prompt of recent models is under 350 tokens.
292
+ */
293
+ export declare const AI_TOOL_USE_PROMPT_TOKENS = 350;
294
+ /**
295
+ * What a request reads before it is sent, at worst (AGL-4152): every byte of
296
+ * it, as the provider bills it on a cold cache. The tools and the platform's
297
+ * blocks up to its last shared marker are written to the cache at the
298
+ * route's lifetime (at the hour, twice the input rate); the site's block
299
+ * after them at five minutes; anything after the last marker, and the turn,
300
+ * as input. `system` is the blocks as sent, the doctrine's own first
301
+ * (`aiDoctrineSystemBlocks`), and `toolChars` the tool's definition.
302
+ */
245
303
  export declare function aiSiteImportImproveInputUsage(input: {
246
- systemChars: number;
304
+ system: readonly AiSystemBlock[];
305
+ toolChars: number;
247
306
  promptChars: number;
307
+ hour?: boolean;
248
308
  }): AiUsage;
249
- /** What a usage is billed in credits on a model. */
309
+ /** What a usage is billed in credits on a model, an hour-long cache write at its own rate, as the meter bills it. */
250
310
  export declare function aiSiteImportImproveCredits(usage: AiUsage, model: string): number;
251
311
  /**
252
312
  * The most output tokens a request may write (AGL-4152) with `spent` already
@@ -262,25 +322,130 @@ export declare function aiSiteImportImproveTokensWithin(input: {
262
322
  }): number;
263
323
  /** The least share of the last answer's length a re-ask must have room for: less, and it would be cut off. */
264
324
  export declare const AI_SITE_IMPORT_REASK_ROOM = 0.9;
325
+ /**
326
+ * The least share of a cut-off answer's length its re-ask must have room for
327
+ * (AGL-4152): the re-ask asks for a page about half as long
328
+ * (`AI_SITE_IMPORT_IMPROVE_CUT_OFF_SMALLER`), so it needs room for that page,
329
+ * not for the one that was cut off.
330
+ */
331
+ export declare const AI_SITE_IMPORT_CUT_OFF_REASK_ROOM = 0.6;
332
+ /** The least room the re-ask of a page cut off is asked in: an opening, a group and a closing, with their words. */
333
+ export declare const AI_SITE_IMPORT_IMPROVE_LEAST_TOKENS = 1200;
334
+ /** What the re-ask of a cut-off page is told makes it smaller (AGL-4152), in one sentence. */
335
+ export declare const AI_SITE_IMPORT_IMPROVE_CUT_OFF_SMALLER = "Write a page about half as long as the one cut off: fewer sections, shorter copy, and each long group of the ledger kept whole with keep rather than written again.";
336
+ /**
337
+ * What a re-ask reads (AGL-4152), from what its first request was billed:
338
+ * its turn again with the re-ask's words, and everything the first request
339
+ * read from the cache or wrote to it, now read from it. The re-ask is sent
340
+ * seconds after its first request, inside the five minutes the shortest
341
+ * entry lives, so its prefix is a read: pricing it as a second write starved
342
+ * the re-ask of a long home whose first request wrote the cache of about 13
343
+ * credits, some 900 tokens.
344
+ */
345
+ export declare function aiSiteImportImproveReaskInput(spent: AiUsage): AiUsage;
265
346
  /**
266
347
  * Whether a redesign's re-ask fits its page's ceiling (AGL-4152): the most
267
348
  * tokens it may ask, given what the first answer spent, or 0 where the room
268
- * left is under what the first answer wrote, and the page falls back with
269
- * no re-ask rather than pass its ceiling.
349
+ * left is under what the re-ask must write, and the page falls back with no
350
+ * re-ask rather than pass its ceiling. A re-ask for a miss writes the page
351
+ * again, at about its first length; a re-ask for a page cut off asks for one
352
+ * about half as long, so it needs room for that.
270
353
  */
271
354
  export declare function aiSiteImportImproveReaskTokens(input: {
272
355
  model: string;
273
356
  spent: AiUsage;
274
357
  lastOutput: number;
358
+ cutOff?: boolean;
275
359
  most: number;
276
360
  ceiling?: number;
277
361
  }): number;
362
+ /** The least room a re-ask after an answer of `lastOutput` tokens must have (AGL-4152). */
363
+ export declare function aiSiteImportImproveReaskNeeds(lastOutput: number, cutOff?: boolean): number;
364
+ /**
365
+ * The share of its room a page is planned to (AGL-4152): a model sizes its
366
+ * answer in words and sections, not in tokens, so a quarter of the room is
367
+ * held back for what it writes past them.
368
+ */
369
+ export declare const AI_SITE_IMPORT_ROOM_SHARE = 0.75;
370
+ /** Tokens a section costs in the tool's shape before its words: its fields, three or four blocks', and a few items'. */
371
+ export declare const AI_SITE_IMPORT_SECTION_TOKENS = 160;
372
+ /** Tokens a word of copy costs, inside the answer's strings. */
373
+ export declare const AI_SITE_IMPORT_WORD_TOKENS = 1.4;
374
+ /** The fewest sections a page is told it has room for: an opening, what it offers, a closing. */
375
+ export declare const AI_SITE_IMPORT_LEAST_SECTIONS = 3;
376
+ /** The least a page is planned to, where its room holds it (AGL-4152): six sections and about 450 words. */
377
+ export declare const AI_SITE_IMPORT_LEAST_PAGE_TOKENS = 1600;
378
+ /** A page whose old lines say fewer words than this is thin (AGL-4152): it stays short, and pads nothing. */
379
+ export declare const AI_SITE_IMPORT_THIN_PAGE_WORDS = 150;
380
+ /** The most sections a thin page is planned to. */
381
+ export declare const AI_SITE_IMPORT_THIN_MOST_SECTIONS = 6;
382
+ /**
383
+ * The share of the old page's own words, outside its groups, a page is told
384
+ * it has room for at the least (AGL-4152): a redesign keeps
385
+ * `SITE_IMPORT_IMPROVED_MEANING` of what the owner says, and a rewrite says
386
+ * less than all of a line it keeps. A group is kept whole by keep, its words
387
+ * with it, so it asks for none.
388
+ */
389
+ export declare const AI_SITE_IMPORT_MEANING_WORDS_SHARE = 0.8;
390
+ /** How many words the old page says, over its lines. */
391
+ export declare function aiSiteImportLedgerWords(ledger: Pick<SiteImportLedger, 'lines'>): number;
392
+ /** What a page's first answer may write, and what it is planned to. */
393
+ export interface AiSiteImportImproveRoom {
394
+ /** The most output tokens the first answer is asked at (`max_tokens`). */
395
+ first: number;
396
+ /** What its input was priced at, before it is sent. */
397
+ estimated: AiUsage;
398
+ /**
399
+ * The size the page is planned to, in tokens: where the room holds it, one
400
+ * whose answer and a full re-ask of it both fit the ceiling, so a miss can
401
+ * still be mended; never under `AI_SITE_IMPORT_LEAST_PAGE_TOKENS`, or what
402
+ * it must say to keep the owner's meaning, where the room holds that; and
403
+ * never over `AI_SITE_IMPORT_ROOM_SHARE` of the room.
404
+ */
405
+ target: number;
406
+ /** The most sections, and about how many words, the page is told it has room for. */
407
+ sections: number;
408
+ words: number;
409
+ /** The old page's words, where it is thin. */
410
+ thin: number | null;
411
+ }
412
+ /**
413
+ * The room a page's redesign has (AGL-4152): its first answer's ceiling from
414
+ * what the page's credit ceiling buys after its input, and the page it is
415
+ * planned to inside it, in sections and words a model can plan by.
416
+ */
417
+ export declare function aiSiteImportImproveRoom(input: {
418
+ model: string;
419
+ spent: AiUsage;
420
+ system: readonly AiSystemBlock[];
421
+ toolChars: number;
422
+ promptChars: number;
423
+ hour?: boolean;
424
+ most: number;
425
+ ledger: Pick<SiteImportLedger, 'lines'>;
426
+ /** A page the site's plan proposed: it has no old lines, and is never thin. */
427
+ proposed?: boolean;
428
+ ceiling?: number;
429
+ }): AiSiteImportImproveRoom;
430
+ /**
431
+ * The lines a page's request says of its size (AGL-4152), in plain words:
432
+ * where its room is under the most an answer may ask, the sections and words
433
+ * it has room for, so it plans a page that fits rather than being cut off;
434
+ * and on a thin page, that it stays short and says no figure the site does
435
+ * not. Never the platform's vocabulary: its numbers are no one's fact.
436
+ */
437
+ export declare function aiSiteImportImproveSizeLines(room: AiSiteImportImproveRoom, input: {
438
+ most: number;
439
+ groups: boolean;
440
+ }): string[];
278
441
  /** What a redesign settled: the page built, what it added and what it shows. */
279
442
  export interface AiSiteImportImproved<T> {
280
443
  built: T;
281
444
  page: AiSiteImportImprovedPage;
282
445
  /** The design lines it was taken with still missed, by code (`AI_SITE_IMPORT_IMPROVE_SOFT_CODES`): only where no re-ask was left. */
283
446
  missed?: string[];
447
+ /** What reading the answer settled on its own (AGL-4152): a block left out and why, a list read from its text. */
448
+ read?: AiLayoutSettlement[];
284
449
  }
285
450
  /**
286
451
  * What a redesign may still miss when no re-ask is left and be taken all the