@aglyn/plugins-ai 1.27.0 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-credits-prompt.component.js +4 -1
  3. package/src/lib/components/ai-credits-prompt.component.js.map +1 -1
  4. package/src/lib/components/ai-site-import-job.component.js +5 -2
  5. package/src/lib/components/ai-site-import-job.component.js.map +1 -1
  6. package/src/lib/components/ai-site-start-card.component.js +6 -3
  7. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  8. package/src/lib/components/assist-build-card.component.js +4 -1
  9. package/src/lib/components/assist-build-card.component.js.map +1 -1
  10. package/src/lib/components/assist-edit-canvas.d.ts +12 -0
  11. package/src/lib/components/assist-edit-canvas.js +38 -7
  12. package/src/lib/components/assist-edit-canvas.js.map +1 -1
  13. package/src/lib/components/assist-jobs-drawer.component.js +4 -1
  14. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
  15. package/src/lib/components/assist-panel.component.js +5 -2
  16. package/src/lib/components/assist-panel.component.js.map +1 -1
  17. package/src/lib/declarations.server.js +17 -0
  18. package/src/lib/declarations.server.js.map +1 -1
  19. package/src/lib/jobs/ai-job-drafts.d.ts +5 -11
  20. package/src/lib/jobs/ai-job-drafts.js +8 -25
  21. package/src/lib/jobs/ai-job-drafts.js.map +1 -1
  22. package/src/lib/jobs/ai-job-edit-step.d.ts +95 -5
  23. package/src/lib/jobs/ai-job-edit-step.js +88 -17
  24. package/src/lib/jobs/ai-job-edit-step.js.map +1 -1
  25. package/src/lib/model/ai-edit-job.d.ts +27 -0
  26. package/src/lib/model/ai-edit-job.js +45 -23
  27. package/src/lib/model/ai-edit-job.js.map +1 -1
  28. package/src/lib/model/ai-layout-menus.d.ts +10 -0
  29. package/src/lib/model/ai-layout-menus.js +23 -2
  30. package/src/lib/model/ai-layout-menus.js.map +1 -1
  31. package/src/lib/model/assist-edit.d.ts +2 -0
  32. package/src/lib/model/assist-edit.js.map +1 -1
  33. package/src/lib/runtime/ai-node-tree.d.ts +25 -1
  34. package/src/lib/runtime/ai-node-tree.js +39 -14
  35. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  36. package/src/lib/runtime/ai-palette.generated.js +84 -2
  37. package/src/lib/runtime/ai-palette.generated.js.map +1 -1
  38. package/src/lib/server/ai-page-content.d.ts +83 -0
  39. package/src/lib/server/ai-page-content.js +765 -0
  40. package/src/lib/server/ai-page-content.js.map +1 -0
  41. package/src/lib/server/ai-usage.js +7 -1
  42. package/src/lib/server/ai-usage.js.map +1 -1
  43. package/src/lib/server/assist-edit.d.ts +136 -1
  44. package/src/lib/server/assist-edit.js +124 -47
  45. package/src/lib/server/assist-edit.js.map +1 -1
  46. package/src/lib/usage/ai-usage-wire.d.ts +15 -0
  47. package/src/lib/usage/ai-usage-wire.js +21 -0
  48. package/src/lib/usage/ai-usage-wire.js.map +1 -1
@@ -71,6 +71,27 @@ const NAV_MENU = 'muiNavMenu';
71
71
  const DRAWER = 'muiDrawer';
72
72
  /** The most items a menu may be asked to change in one go. */ export const AI_MENU_CHANGES_MAX = 12;
73
73
  /** The longest label a menu item takes. */ export const AI_MENU_LABEL_MAX = 40;
74
+ /**
75
+ * The trigger look a new Dropdown Menu takes from the links around it
76
+ * (AGL-4239): a link drawn as a button (Button, or Link with button styling,
77
+ * or unset, which is Button) gives the menu the button look with the same
78
+ * variant, size and color, so it matches them; a text link gives nothing,
79
+ * which leaves the plain label a menu beside text links should have.
80
+ */ export function aiMenuTriggerLookFrom(link) {
81
+ const props = link == null ? void 0 : link.props;
82
+ if (!props || props['renderAs'] === 'link') return {};
83
+ const look = {
84
+ renderAs: 'button'
85
+ };
86
+ for (const key of [
87
+ 'variant',
88
+ 'size',
89
+ 'color'
90
+ ]){
91
+ if (props[key] !== undefined && props[key] !== null) look[key] = props[key];
92
+ }
93
+ return look;
94
+ }
74
95
  const renders = (node, element)=>{
75
96
  var _node_props, _node_props1;
76
97
  return ((_node_props = node.props) == null ? void 0 : _node_props['element']) === element || ((_node_props1 = node.props) == null ? void 0 : _node_props1['component']) === element || node.componentId === element;
@@ -343,9 +364,9 @@ const same = (a, b)=>a.trim().toLowerCase() === b.trim().toLowerCase();
343
364
  componentId: NAV_MENU,
344
365
  pluginId: 'mui',
345
366
  parentId: list.$id,
346
- props: {
367
+ props: _extends({
347
368
  label: entry.parent.slice(0, AI_MENU_LABEL_MAX)
348
- },
369
+ }, aiMenuTriggerLookFrom(own ? map[own] : template)),
349
370
  nodes: own ? [
350
371
  own
351
372
  ] : []
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-layout-menus.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 SITE'S MENUS, CHANGED BY CODE (AGL-3728).\n *\n * A site's header and footer menus are not a separate document: they are the\n * Besigner's own elements in the layout's node tree — Page Links\n * (`muiScreenLink`) in a list in the header, the same list again in the phone\n * menu's Drawer, Dropdown Menus (`muiNavMenu`, `muiMegaMenu`) holding more\n * Page Links, and the footer's list of Page Links. That is what a person\n * edits in the Besigner, and what this edits, so a menu the AI changed opens\n * in the editor exactly as one a person changed.\n *\n * A change is planned as words — add \"About\", take \"Blog\" out, call\n * \"Services\" \"What we do\", link \"Shop\" to a page, put \"Contact\" last — and\n * applied here, in code, to every list of the menu it names:\n *\n * - THE HEADER's lists are the lists of links inside its App Bar (or an\n * element that renders `header`): the bar's own row and the phone menu's.\n * Where it has lists that render `nav`, only those are its menu, so the\n * brand and an account link beside it never are. Failing any list, a\n * Toolbar holding a link (the brand's counts), else the first Toolbar.\n * The brand (a link the compiler named `brand`) is never a menu item, and\n * an item added beside nothing but the brand goes after it.\n * - THE FOOTER's list is the longest list of links inside the element that\n * renders `footer`.\n *\n * Recognized the way a store's links are added to a layout\n * (`aiLayoutWithStoreLinks`, AGL-3676). A layout with no list for a menu is\n * left as it is, and the change says what to do by hand.\n *\n * A new link copies a link already in the list it joins — its look, and in\n * the phone menu the interaction that closes it — so it looks like its\n * neighbours. A link added under a parent (\"Services > Roofing\") goes into the\n * Dropdown Menu of that name in a bar's row, made where there is none (the\n * link of that name, if any, becoming its first entry); a phone menu and a\n * footer have no dropdowns, so there it joins the list after its parent.\n *\n * ONE implementation for every menu change the AI makes (AGL-3747): the\n * `navigation` op's (`ai-job-navigation-step.ts`), and the header entries a\n * guided site start adds to its layout when it publishes\n * (`aiLayoutWithNavigation` in `ai-site-publish.ts`), including the /blog\n * entry a retried posts part puts back.\n *\n * Pure: nodes in, nodes out.\n */\n\nimport { aiLayoutRepairFrameHollows } from '../layout-language/ai-layout-frame-hollows'\n\n/** A menu of a site's layout. */\nexport type AiMenuName = 'header' | 'footer'\n\nexport const AI_MENU_NAMES: readonly AiMenuName[] = ['header', 'footer']\n\n/** Where a menu item goes: one of the site's pages, by id, or an address. */\nexport type AiMenuTarget = { screenId: string } | { href: string }\n\n/** One entry a change names: a top-level item, or one under a parent dropdown. */\nexport interface AiMenuEntryRef {\n /** The dropdown it is under, by its label; `null` for a top-level item. */\n parent: string | null\n label: string\n}\n\n/** An entry to add, and where it goes. */\nexport type AiMenuAddition = AiMenuEntryRef & {\n to: AiMenuTarget\n /**\n * A top-level entry goes right after the first item linking one of these\n * (a page by id, an address), where the menu has one, instead of last. Set\n * by code, never read off a planner's words: the blog's entry, put back\n * second after Home (AGL-3747).\n */\n after?: readonly AiMenuTarget[]\n}\n\n/** What a navigation change does to a menu. */\nexport interface AiMenuChanges {\n add: AiMenuAddition[]\n remove: AiMenuEntryRef[]\n rename: Array<AiMenuEntryRef & { name: string }>\n relink: Array<AiMenuEntryRef & { to: AiMenuTarget }>\n /** Top-level labels, in the order wanted; the rest keep theirs, after them. */\n order: string[]\n}\n\n/** What applying a change came to. */\nexport interface AiMenusResult {\n /** The layout's nodes with the change made, or `null` where nothing changed. */\n nodes: Record<string, unknown> | null\n /** Whether the layout has a list for each menu asked about. */\n found: Partial<Record<AiMenuName, boolean>>\n /** What was done, as sentences. */\n done: string[]\n /** What could not be done, and why, as sentences. */\n notDone: string[]\n}\n\nconst LINK = 'muiScreenLink'\n/** The Besigner's Dropdown Menu and Mega Menu: a labelled item holding links. Persisted ids. */\nexport const AI_MENU_DROPDOWNS: readonly string[] = ['muiNavMenu', 'muiMegaMenu']\nconst NAV_MENU = 'muiNavMenu'\nconst DRAWER = 'muiDrawer'\n/** The most items a menu may be asked to change in one go. */\nexport const AI_MENU_CHANGES_MAX = 12\n/** The longest label a menu item takes. */\nexport const AI_MENU_LABEL_MAX = 40\n\ninterface Node {\n $id: string\n componentId?: string\n pluginId?: string\n parentId?: string | null\n nodes?: string[]\n props?: Record<string, unknown>\n sx?: Record<string, unknown>\n [key: string]: unknown\n}\n\nconst renders = (node: Node, element: string) =>\n node.props?.['element'] === element || node.props?.['component'] === element || node.componentId === element\n\nconst said = (value: unknown): string => (typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim() : '')\nconst same = (a: string, b: string) => a.trim().toLowerCase() === b.trim().toLowerCase()\n\n/** Where a menu change says an entry lives, in words: `Roofing`, `Services › Roofing`. */\nexport function aiMenuEntryName(entry: AiMenuEntryRef): string {\n return entry.parent ? `${entry.parent} › ${entry.label}` : entry.label\n}\n\n/**\n * The layout's nodes with a navigation change made to the menus named\n * (AGL-3728). Each menu's lists all take the same change, so the bar and the\n * phone menu never disagree. `newId` mints a node id; the default is a\n * counter under `ai_nav_`.\n */\nexport function aiLayoutWithMenuChanges(\n nodes: Readonly<Record<string, unknown>>,\n menus: readonly AiMenuName[],\n changes: AiMenuChanges,\n options: { newId?: () => string } = {},\n): AiMenusResult {\n const map: Record<string, Node> = {}\n for (const [id, raw] of Object.entries(nodes as Record<string, Node>)) {\n if (!raw || typeof raw !== 'object') continue\n map[id] = {\n ...raw,\n $id: typeof raw.$id === 'string' && raw.$id ? raw.$id : id,\n ...(raw.props ? { props: { ...raw.props } } : {}),\n ...(raw.nodes ? { nodes: [...raw.nodes] } : {}),\n }\n }\n let counter = 0\n const newId =\n options.newId ??\n (() => {\n counter += 1\n while (map[`ai_nav_${counter}`]) counter += 1\n return `ai_nav_${counter}`\n })\n const all = Object.values(map)\n const under = (roots: readonly Node[]): Set<string> => {\n const seen = new Set<string>()\n const queue = roots.map((root) => root.$id)\n while (queue.length) {\n const id = queue.shift() as string\n if (seen.has(id) || !map[id]) continue\n seen.add(id)\n queue.push(...(map[id].nodes ?? []))\n }\n return seen\n }\n const isBrand = (id: string) => /brand/i.test(id)\n const isLink = (id: string) => map[id]?.componentId === LINK && !isBrand(id)\n const isDropdown = (id: string) => AI_MENU_DROPDOWNS.includes(String(map[id]?.componentId))\n const isItem = (id: string) => isLink(id) || isDropdown(id)\n const itemsOf = (list: Node) => (list.nodes ?? []).filter(isItem)\n const labelOf = (id: string) => said(isDropdown(id) ? map[id]?.props?.['label'] : map[id]?.props?.['children'])\n\n // ── The lists each menu is ───────────────────────────────────────────\n const listsOf = (menu: AiMenuName): Node[] => {\n if (menu === 'footer') {\n const ids = under(all.filter((node) => renders(node, 'footer')))\n const longest = [...ids]\n .map((id) => map[id])\n .filter((node) => (node.nodes ?? []).filter(isLink).length >= 2)\n .sort((a, b) => (b.nodes ?? []).filter(isLink).length - (a.nodes ?? []).filter(isLink).length)[0]\n return longest ? [longest] : []\n }\n const ids = under(all.filter((node) => node.componentId === 'muiAppBar' || renders(node, 'header')))\n const lists = [...ids].map((id) => map[id]).filter((node) => itemsOf(node).length >= 2)\n const landmarks = lists.filter((node) => renders(node, 'nav'))\n if (landmarks.length) return landmarks\n if (lists.length) return lists\n // A bar's Toolbar holding a link, the brand's included (a starter's\n // header is a brand and a search), else its first Toolbar.\n const toolbars = all.filter((node) => node.componentId === 'muiToolbar')\n const toolbar = toolbars.find((node) => (node.nodes ?? []).some((id) => map[id]?.componentId === LINK)) ?? toolbars[0]\n return toolbar ? [toolbar] : []\n }\n // A phone menu (in a Drawer) and a footer hold no dropdowns: their entries stay flat.\n const drawerIds = under(all.filter((node) => node.componentId === DRAWER))\n const flat = (menu: AiMenuName, list: Node) => menu === 'footer' || drawerIds.has(list.$id)\n\n const found: Partial<Record<AiMenuName, boolean>> = {}\n const notDone = new Set<string>()\n // What each entry came to across a menu's lists: done where any list did it.\n const outcomes = new Map<string, { ok: boolean; done: string; failed: string }>()\n const mark = (key: string, ok: boolean, done: string, failed: string) => {\n const was = outcomes.get(key)\n outcomes.set(key, { ok: ok || (was?.ok ?? false), done, failed: was && !was.ok && !ok ? was.failed : failed })\n }\n let changed = false\n\n const removeTree = (id: string) => {\n for (const child of [...(map[id]?.nodes ?? [])]) removeTree(child)\n delete map[id]\n }\n const detach = (id: string) => {\n for (const node of Object.values(map)) {\n if (node.nodes?.includes(id)) node.nodes = node.nodes.filter((child) => child !== id)\n }\n }\n const setTarget = (node: Node, to: AiMenuTarget) => {\n const props = { ...(node.props ?? {}) }\n delete props['screenId']\n delete props['href']\n node.props = { ...props, ...to }\n }\n /** A new link like the list's own, else a plain one. */\n const linkLike = (template: Node | undefined, parentId: string, label: string, to: AiMenuTarget): string => {\n const id = newId()\n const props: Record<string, unknown> = template?.props\n ? { ...template.props }\n : { renderAs: 'link', color: 'inherit' }\n delete props['screenId']\n delete props['href']\n map[id] = {\n ...(template ?? { sx: { textDecoration: 'none', whiteSpace: 'nowrap' } }),\n $id: id,\n componentId: LINK,\n pluginId: template?.pluginId ?? 'mui',\n parentId,\n props: { ...props, children: label.slice(0, AI_MENU_LABEL_MAX), ...to },\n nodes: [],\n }\n return id\n }\n /** Whether a link opens a destination: the same page, or the same address. */\n const opens = (node: Node | undefined, to: AiMenuTarget) =>\n 'screenId' in to ? node?.props?.['screenId'] === to.screenId : node?.props?.['href'] === to.href\n /** Every link in a dropdown, at any depth (a Mega Menu's columns). */\n const linksIn = (dropdown: string) => [...under([map[dropdown]])].filter((id) => id !== dropdown && isLink(id))\n /** An entry in one list: a top-level item, or a link in a dropdown (or, in a flat list, the item itself). */\n const find = (list: Node, entry: AiMenuEntryRef, isFlat: boolean): string | null => {\n const top = itemsOf(list)\n if (!entry.parent) return top.find((id) => same(labelOf(id), entry.label)) ?? null\n const parent = top.find((id) => isDropdown(id) && same(labelOf(id), entry.parent as string))\n if (parent) return linksIn(parent).find((id) => same(labelOf(id), entry.label)) ?? null\n return isFlat ? (top.find((id) => isLink(id) && same(labelOf(id), entry.label)) ?? null) : null\n }\n\n for (const menu of menus) {\n const lists = listsOf(menu)\n found[menu] = lists.length > 0\n if (!lists.length) {\n notDone.add(`The ${menu} has no list of links to change: add them in the layout by hand.`)\n continue\n }\n for (const list of lists) {\n const isFlat = flat(menu, list)\n for (const entry of changes.remove) {\n const id = find(list, entry, isFlat)\n const key = `remove:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n mark(key, !!id, `Took “${aiMenuEntryName(entry)}” out of the ${menu}.`, `No “${aiMenuEntryName(entry)}” in the ${menu} to take out.`)\n if (!id) continue\n detach(id)\n removeTree(id)\n changed = true\n }\n for (const entry of changes.rename) {\n const id = find(list, entry, isFlat)\n const name = entry.name.slice(0, AI_MENU_LABEL_MAX)\n const key = `rename:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n mark(key, !!id, `Renamed “${aiMenuEntryName(entry)}” to “${name}” in the ${menu}.`, `No “${aiMenuEntryName(entry)}” in the ${menu} to rename.`)\n if (!id) continue\n map[id].props = { ...(map[id].props ?? {}), [isDropdown(id) ? 'label' : 'children']: name }\n changed = true\n }\n for (const entry of changes.relink) {\n const id = find(list, entry, isFlat)\n const key = `relink:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n mark(\n key,\n !!id && isLink(id),\n `Pointed “${aiMenuEntryName(entry)}” in the ${menu} somewhere new.`,\n id ? `“${aiMenuEntryName(entry)}” opens a dropdown, which links nowhere itself.` : `No “${aiMenuEntryName(entry)}” in the ${menu} to relink.`,\n )\n if (!id || !isLink(id)) continue\n setTarget(map[id], entry.to)\n changed = true\n }\n for (const entry of changes.add) {\n const key = `add:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n if (find(list, entry, isFlat)) {\n mark(key, true, `“${aiMenuEntryName(entry)}” was already in the ${menu}.`, '')\n continue\n }\n const children = list.nodes ?? []\n const template = map[children.filter(isLink).slice(-1)[0]]\n // After the list's last item, else after its brand: before a search,\n // a mode switch or a call to action that follows them.\n const lastOf = (test: (id: string) => boolean) => children.reduce((at, id, index) => (test(id) ? index : at), -1)\n const lastItem = lastOf(isItem) !== -1 ? lastOf(isItem) : lastOf((id) => map[id]?.componentId === LINK)\n if (!entry.parent || isFlat) {\n // After its parent in a flat list, else after the item it is to\n // follow, else after the list's last item.\n const parentAt = entry.parent ? children.findIndex((id) => isItem(id) && same(labelOf(id), entry.parent as string)) : -1\n const afterAt = !entry.parent && entry.after?.length ? children.findIndex((id) => isLink(id) && (entry.after ?? []).some((to) => opens(map[id], to))) : -1\n let at = parentAt !== -1 ? parentAt : afterAt !== -1 ? afterAt : lastItem\n if (parentAt !== -1) {\n // After the entries already following the parent from an earlier add.\n while (at + 1 < children.length && isLink(children[at + 1]) && String(children[at + 1]).startsWith('ai_nav_')) at += 1\n }\n const id = linkLike(template, list.$id, entry.label, entry.to)\n list.nodes = [...children.slice(0, at + 1), id, ...children.slice(at + 1)]\n } else {\n let dropdown = children.find((id) => isDropdown(id) && same(labelOf(id), entry.parent as string))\n if (!dropdown) {\n // A Dropdown Menu of that name, where its link of that name was, else last.\n dropdown = newId()\n const own = children.find((id) => isLink(id) && same(labelOf(id), entry.parent as string))\n map[dropdown] = {\n $id: dropdown,\n componentId: NAV_MENU,\n pluginId: 'mui',\n parentId: list.$id,\n props: { label: (entry.parent as string).slice(0, AI_MENU_LABEL_MAX) },\n nodes: own ? [own] : [],\n }\n if (own) {\n map[own].parentId = dropdown\n list.nodes = children.map((id) => (id === own ? (dropdown as string) : id))\n } else {\n list.nodes = [...children.slice(0, lastItem + 1), dropdown, ...children.slice(lastItem + 1)]\n }\n }\n const inside = map[dropdown]\n const id = linkLike(map[linksIn(dropdown)[0]] ?? template, dropdown, entry.label, entry.to)\n inside.nodes = [...(inside.nodes ?? []), id]\n }\n changed = true\n mark(key, true, `Added “${aiMenuEntryName(entry)}” to the ${menu}.`, '')\n }\n if (changes.order.length) {\n const children = list.nodes ?? []\n const slots = children.map((id, index) => (isItem(id) ? index : -1)).filter((index) => index !== -1)\n const items = slots.map((index) => children[index])\n const named = changes.order.flatMap((label) => items.filter((id) => same(labelOf(id), label)).slice(0, 1))\n const ordered = [...new Set([...named, ...items])]\n if (ordered.some((id, index) => id !== items[index])) {\n const next = [...children]\n slots.forEach((slot, index) => {\n next[slot] = ordered[index]\n })\n list.nodes = next\n changed = true\n }\n for (const label of changes.order) {\n mark(\n `order:${menu}:${label.toLowerCase()}`,\n items.some((id) => same(labelOf(id), label)),\n `Put “${label}” in its place in the ${menu}.`,\n `No “${label}” in the ${menu} to put in order.`,\n )\n }\n }\n }\n }\n // A link taken out leaves no dropdown with no link in it, and no footer\n // heading or column with nothing under it (AGL-3735).\n if (changed && changes.remove.length) aiLayoutRepairFrameHollows(map as unknown as Record<string, unknown>)\n const entries = [...outcomes.values()]\n return {\n nodes: changed ? (map as Record<string, unknown>) : null,\n found,\n done: [...new Set(entries.filter((entry) => entry.ok).map((entry) => entry.done))],\n notDone: [...notDone, ...new Set(entries.filter((entry) => !entry.ok).map((entry) => entry.failed))],\n }\n}\n\n// ── The change as an item's arguments carry it ───────────────────────────\n\n/** How an entry names a parent, a label and a destination: `Services > Roofing => /roofing`. */\nconst ARROW = /\\s*=>\\s*/\nconst PARENT = /\\s*>\\s*/\n\n/** What reading an item's arguments came to: the change, and what could not be read. */\nexport interface AiMenuChangesRead {\n changes: AiMenuChanges\n problems: string[]\n}\n\n/** An entry's parent and label: `Services > Roofing`, or `Roofing`. */\nfunction entryRefOf(text: string): AiMenuEntryRef | null {\n const parts = text.split(PARENT).map((part) => said(part)).filter(Boolean)\n if (!parts.length || parts.length > 2) return null\n const label = parts[parts.length - 1].slice(0, AI_MENU_LABEL_MAX)\n return { parent: parts.length === 2 ? parts[0].slice(0, AI_MENU_LABEL_MAX) : null, label }\n}\n\nconst list = (value: unknown): string[] =>\n Array.isArray(value) ? value.filter((one): one is string => typeof one === 'string').map(said).filter(Boolean).slice(0, AI_MENU_CHANGES_MAX) : []\n\n/**\n * A navigation item's change, read off its arguments (AGL-3728). Each entry\n * is words: `add` and `relink` take `Label => destination` (a parent first\n * as `Parent > Label`), `remove` the label, `rename` `Old => New`, `order`\n * labels. `target` turns a destination into a page or an address, or `null`\n * for one this site cannot link, which leaves that entry out with a sentence.\n */\nexport function aiMenuChangesOf(\n args: Readonly<Record<string, unknown>>,\n target: (destination: string) => AiMenuTarget | null,\n): AiMenuChangesRead {\n const problems: string[] = []\n const changes = aiNoMenuChanges()\n const linked = (entry: string, verb: 'add' | 'relink') => {\n const [name, destination, ...rest] = entry.split(ARROW)\n const ref = entryRefOf(name ?? '')\n if (!ref || !said(destination) || rest.length) {\n problems.push(`“${entry}” is not “Label => page or address”, so it was left out.`)\n return\n }\n const to = target(said(destination))\n if (!to) {\n problems.push(`“${aiMenuEntryName(ref)}” links “${said(destination)}”, which is no page or address on this site, so it was left out.`)\n return\n }\n changes[verb].push({ ...ref, to })\n }\n for (const entry of list(args['add'])) linked(entry, 'add')\n for (const entry of list(args['relink'])) linked(entry, 'relink')\n for (const entry of list(args['remove'])) {\n const ref = entryRefOf(entry)\n if (ref) changes.remove.push(ref)\n else problems.push(`“${entry}” names no menu item, so it was left out.`)\n }\n for (const entry of list(args['rename'])) {\n const [from, to, ...rest] = entry.split(ARROW)\n const ref = entryRefOf(from ?? '')\n const name = said(to)\n if (!ref || !name || rest.length) problems.push(`“${entry}” is not “Old name => New name”, so it was left out.`)\n else changes.rename.push({ ...ref, name: name.slice(0, AI_MENU_LABEL_MAX) })\n }\n changes.order = list(args['order']).map((label) => label.slice(0, AI_MENU_LABEL_MAX))\n return { changes, problems }\n}\n\n/** A change that does nothing, to build one from. */\nexport function aiNoMenuChanges(): AiMenuChanges {\n return { add: [], remove: [], rename: [], relink: [], order: [] }\n}\n\n/** Whether a change does anything at all. */\nexport function aiMenuChangesEmpty(changes: AiMenuChanges): boolean {\n return !changes.add.length && !changes.remove.length && !changes.rename.length && !changes.relink.length && !changes.order.length\n}\n\n/** The menus an item's `menu` names: the header, the footer, or both. */\nexport function aiMenusOf(value: unknown): AiMenuName[] {\n if (value === 'footer') return ['footer']\n if (value === 'both') return ['header', 'footer']\n return ['header']\n}\n\n/** The `new:` references an entry's destination makes: what the item must be built after. */\nexport function aiMenuNewRefs(args: Readonly<Record<string, unknown>>): string[] {\n const refs: string[] = []\n for (const key of ['add', 'relink'] as const) {\n for (const entry of list(args[key])) {\n const destination = said(entry.split(ARROW)[1])\n if (/^new:/i.test(destination) && !refs.includes(destination)) refs.push(destination)\n }\n }\n return refs\n}\n"],"names":["aiLayoutRepairFrameHollows","AI_MENU_NAMES","LINK","AI_MENU_DROPDOWNS","NAV_MENU","DRAWER","AI_MENU_CHANGES_MAX","AI_MENU_LABEL_MAX","renders","node","element","props","componentId","said","value","replace","trim","same","a","b","toLowerCase","aiMenuEntryName","entry","parent","label","aiLayoutWithMenuChanges","nodes","menus","changes","options","map","id","raw","Object","entries","$id","counter","newId","all","values","under","roots","seen","Set","queue","root","length","shift","has","add","push","isBrand","test","isLink","isDropdown","includes","String","isItem","itemsOf","list","filter","labelOf","listsOf","menu","toolbars","ids","longest","sort","lists","landmarks","toolbar","find","some","drawerIds","flat","found","notDone","outcomes","Map","mark","key","ok","done","failed","was","get","set","changed","removeTree","child","detach","setTarget","to","linkLike","template","parentId","renderAs","color","sx","textDecoration","whiteSpace","pluginId","children","slice","opens","screenId","href","linksIn","dropdown","isFlat","top","remove","rename","name","relink","lastOf","reduce","at","index","lastItem","parentAt","findIndex","afterAt","after","startsWith","inside","own","order","slots","items","named","flatMap","ordered","next","forEach","slot","ARROW","PARENT","entryRefOf","text","parts","split","part","Boolean","Array","isArray","one","aiMenuChangesOf","args","target","problems","aiNoMenuChanges","linked","verb","destination","rest","ref","from","aiMenuChangesEmpty","aiMenusOf","aiMenuNewRefs","refs"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CC,GAED,SAASA,0BAA0B,QAAQ,gDAA4C;AAKvF,OAAO,MAAMC,gBAAuC;IAAC;IAAU;CAAS,CAAA;AA8CxE,MAAMC,OAAO;AACb,8FAA8F,GAC9F,OAAO,MAAMC,oBAAuC;IAAC;IAAc;CAAc,CAAA;AACjF,MAAMC,WAAW;AACjB,MAAMC,SAAS;AACf,4DAA4D,GAC5D,OAAO,MAAMC,sBAAsB,GAAE;AACrC,yCAAyC,GACzC,OAAO,MAAMC,oBAAoB,GAAE;AAanC,MAAMC,UAAU,CAACC,MAAYC;QAC3BD,aAAuCA;WAAvCA,EAAAA,cAAAA,KAAKE,KAAK,qBAAVF,WAAY,CAAC,UAAU,MAAKC,WAAWD,EAAAA,eAAAA,KAAKE,KAAK,qBAAVF,YAAY,CAAC,YAAY,MAAKC,WAAWD,KAAKG,WAAW,KAAKF;;AAEvG,MAAMG,OAAO,CAACC,QAA4B,OAAOA,UAAU,WAAWA,MAAMC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAC1G,MAAMC,OAAO,CAACC,GAAWC,IAAcD,EAAEF,IAAI,GAAGI,WAAW,OAAOD,EAAEH,IAAI,GAAGI,WAAW;AAEtF,wFAAwF,GACxF,OAAO,SAASC,gBAAgBC,KAAqB;IACnD,OAAOA,MAAMC,MAAM,GAAG,GA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AQoF,MAAM,CAAClE,MAAM,IAAI,CAAClB,QAAQsF,MAAM,CAACpE,MAAM,IAAI,CAAClB,QAAQmG,KAAK,CAACjF,MAAM;AACnI;AAEA,uEAAuE,GACvE,OAAO,SAASiH,UAAUjJ,KAAc;IACtC,IAAIA,UAAU,UAAU,OAAO;QAAC;KAAS;IACzC,IAAIA,UAAU,QAAQ,OAAO;QAAC;QAAU;KAAS;IACjD,OAAO;QAAC;KAAS;AACnB;AAEA,2FAA2F,GAC3F,OAAO,SAASkJ,cAAcZ,IAAuC;IACnE,MAAMa,OAAiB,EAAE;IACzB,KAAK,MAAMjF,OAAO;QAAC;QAAO;KAAS,CAAW;QAC5C,KAAK,MAAM1D,SAASqC,KAAKyF,IAAI,CAACpE,IAAI,EAAG;YACnC,MAAM0E,cAAc7I,KAAKS,MAAMuH,KAAK,CAACL,MAAM,CAAC,EAAE;YAC9C,IAAI,SAASpF,IAAI,CAACsG,gBAAgB,CAACO,KAAK1G,QAAQ,CAACmG,cAAcO,KAAK/G,IAAI,CAACwG;QAC3E;IACF;IACA,OAAOO;AACT"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-layout-menus.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 SITE'S MENUS, CHANGED BY CODE (AGL-3728).\n *\n * A site's header and footer menus are not a separate document: they are the\n * Besigner's own elements in the layout's node tree — Page Links\n * (`muiScreenLink`) in a list in the header, the same list again in the phone\n * menu's Drawer, Dropdown Menus (`muiNavMenu`, `muiMegaMenu`) holding more\n * Page Links, and the footer's list of Page Links. That is what a person\n * edits in the Besigner, and what this edits, so a menu the AI changed opens\n * in the editor exactly as one a person changed.\n *\n * A change is planned as words — add \"About\", take \"Blog\" out, call\n * \"Services\" \"What we do\", link \"Shop\" to a page, put \"Contact\" last — and\n * applied here, in code, to every list of the menu it names:\n *\n * - THE HEADER's lists are the lists of links inside its App Bar (or an\n * element that renders `header`): the bar's own row and the phone menu's.\n * Where it has lists that render `nav`, only those are its menu, so the\n * brand and an account link beside it never are. Failing any list, a\n * Toolbar holding a link (the brand's counts), else the first Toolbar.\n * The brand (a link the compiler named `brand`) is never a menu item, and\n * an item added beside nothing but the brand goes after it.\n * - THE FOOTER's list is the longest list of links inside the element that\n * renders `footer`.\n *\n * Recognized the way a store's links are added to a layout\n * (`aiLayoutWithStoreLinks`, AGL-3676). A layout with no list for a menu is\n * left as it is, and the change says what to do by hand.\n *\n * A new link copies a link already in the list it joins — its look, and in\n * the phone menu the interaction that closes it — so it looks like its\n * neighbours. A link added under a parent (\"Services > Roofing\") goes into the\n * Dropdown Menu of that name in a bar's row, made where there is none (the\n * link of that name, if any, becoming its first entry); a phone menu and a\n * footer have no dropdowns, so there it joins the list after its parent.\n *\n * ONE implementation for every menu change the AI makes (AGL-3747): the\n * `navigation` op's (`ai-job-navigation-step.ts`), and the header entries a\n * guided site start adds to its layout when it publishes\n * (`aiLayoutWithNavigation` in `ai-site-publish.ts`), including the /blog\n * entry a retried posts part puts back.\n *\n * Pure: nodes in, nodes out.\n */\n\nimport { aiLayoutRepairFrameHollows } from '../layout-language/ai-layout-frame-hollows'\n\n/** A menu of a site's layout. */\nexport type AiMenuName = 'header' | 'footer'\n\nexport const AI_MENU_NAMES: readonly AiMenuName[] = ['header', 'footer']\n\n/** Where a menu item goes: one of the site's pages, by id, or an address. */\nexport type AiMenuTarget = { screenId: string } | { href: string }\n\n/** One entry a change names: a top-level item, or one under a parent dropdown. */\nexport interface AiMenuEntryRef {\n /** The dropdown it is under, by its label; `null` for a top-level item. */\n parent: string | null\n label: string\n}\n\n/** An entry to add, and where it goes. */\nexport type AiMenuAddition = AiMenuEntryRef & {\n to: AiMenuTarget\n /**\n * A top-level entry goes right after the first item linking one of these\n * (a page by id, an address), where the menu has one, instead of last. Set\n * by code, never read off a planner's words: the blog's entry, put back\n * second after Home (AGL-3747).\n */\n after?: readonly AiMenuTarget[]\n}\n\n/** What a navigation change does to a menu. */\nexport interface AiMenuChanges {\n add: AiMenuAddition[]\n remove: AiMenuEntryRef[]\n rename: Array<AiMenuEntryRef & { name: string }>\n relink: Array<AiMenuEntryRef & { to: AiMenuTarget }>\n /** Top-level labels, in the order wanted; the rest keep theirs, after them. */\n order: string[]\n}\n\n/** What applying a change came to. */\nexport interface AiMenusResult {\n /** The layout's nodes with the change made, or `null` where nothing changed. */\n nodes: Record<string, unknown> | null\n /** Whether the layout has a list for each menu asked about. */\n found: Partial<Record<AiMenuName, boolean>>\n /** What was done, as sentences. */\n done: string[]\n /** What could not be done, and why, as sentences. */\n notDone: string[]\n}\n\nconst LINK = 'muiScreenLink'\n/** The Besigner's Dropdown Menu and Mega Menu: a labelled item holding links. Persisted ids. */\nexport const AI_MENU_DROPDOWNS: readonly string[] = ['muiNavMenu', 'muiMegaMenu']\nconst NAV_MENU = 'muiNavMenu'\nconst DRAWER = 'muiDrawer'\n/** The most items a menu may be asked to change in one go. */\nexport const AI_MENU_CHANGES_MAX = 12\n/** The longest label a menu item takes. */\nexport const AI_MENU_LABEL_MAX = 40\n\ninterface Node {\n $id: string\n componentId?: string\n pluginId?: string\n parentId?: string | null\n nodes?: string[]\n props?: Record<string, unknown>\n sx?: Record<string, unknown>\n [key: string]: unknown\n}\n\n/**\n * The trigger look a new Dropdown Menu takes from the links around it\n * (AGL-4239): a link drawn as a button (Button, or Link with button styling,\n * or unset, which is Button) gives the menu the button look with the same\n * variant, size and color, so it matches them; a text link gives nothing,\n * which leaves the plain label a menu beside text links should have.\n */\nexport function aiMenuTriggerLookFrom(link: { props?: Record<string, unknown> } | undefined): Record<string, unknown> {\n const props = link?.props\n if (!props || props['renderAs'] === 'link') return {}\n const look: Record<string, unknown> = { renderAs: 'button' }\n for (const key of ['variant', 'size', 'color']) {\n if (props[key] !== undefined && props[key] !== null) look[key] = props[key]\n }\n return look\n}\n\nconst renders = (node: Node, element: string) =>\n node.props?.['element'] === element || node.props?.['component'] === element || node.componentId === element\n\nconst said = (value: unknown): string => (typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim() : '')\nconst same = (a: string, b: string) => a.trim().toLowerCase() === b.trim().toLowerCase()\n\n/** Where a menu change says an entry lives, in words: `Roofing`, `Services › Roofing`. */\nexport function aiMenuEntryName(entry: AiMenuEntryRef): string {\n return entry.parent ? `${entry.parent} › ${entry.label}` : entry.label\n}\n\n/**\n * The layout's nodes with a navigation change made to the menus named\n * (AGL-3728). Each menu's lists all take the same change, so the bar and the\n * phone menu never disagree. `newId` mints a node id; the default is a\n * counter under `ai_nav_`.\n */\nexport function aiLayoutWithMenuChanges(\n nodes: Readonly<Record<string, unknown>>,\n menus: readonly AiMenuName[],\n changes: AiMenuChanges,\n options: { newId?: () => string } = {},\n): AiMenusResult {\n const map: Record<string, Node> = {}\n for (const [id, raw] of Object.entries(nodes as Record<string, Node>)) {\n if (!raw || typeof raw !== 'object') continue\n map[id] = {\n ...raw,\n $id: typeof raw.$id === 'string' && raw.$id ? raw.$id : id,\n ...(raw.props ? { props: { ...raw.props } } : {}),\n ...(raw.nodes ? { nodes: [...raw.nodes] } : {}),\n }\n }\n let counter = 0\n const newId =\n options.newId ??\n (() => {\n counter += 1\n while (map[`ai_nav_${counter}`]) counter += 1\n return `ai_nav_${counter}`\n })\n const all = Object.values(map)\n const under = (roots: readonly Node[]): Set<string> => {\n const seen = new Set<string>()\n const queue = roots.map((root) => root.$id)\n while (queue.length) {\n const id = queue.shift() as string\n if (seen.has(id) || !map[id]) continue\n seen.add(id)\n queue.push(...(map[id].nodes ?? []))\n }\n return seen\n }\n const isBrand = (id: string) => /brand/i.test(id)\n const isLink = (id: string) => map[id]?.componentId === LINK && !isBrand(id)\n const isDropdown = (id: string) => AI_MENU_DROPDOWNS.includes(String(map[id]?.componentId))\n const isItem = (id: string) => isLink(id) || isDropdown(id)\n const itemsOf = (list: Node) => (list.nodes ?? []).filter(isItem)\n const labelOf = (id: string) => said(isDropdown(id) ? map[id]?.props?.['label'] : map[id]?.props?.['children'])\n\n // ── The lists each menu is ───────────────────────────────────────────\n const listsOf = (menu: AiMenuName): Node[] => {\n if (menu === 'footer') {\n const ids = under(all.filter((node) => renders(node, 'footer')))\n const longest = [...ids]\n .map((id) => map[id])\n .filter((node) => (node.nodes ?? []).filter(isLink).length >= 2)\n .sort((a, b) => (b.nodes ?? []).filter(isLink).length - (a.nodes ?? []).filter(isLink).length)[0]\n return longest ? [longest] : []\n }\n const ids = under(all.filter((node) => node.componentId === 'muiAppBar' || renders(node, 'header')))\n const lists = [...ids].map((id) => map[id]).filter((node) => itemsOf(node).length >= 2)\n const landmarks = lists.filter((node) => renders(node, 'nav'))\n if (landmarks.length) return landmarks\n if (lists.length) return lists\n // A bar's Toolbar holding a link, the brand's included (a starter's\n // header is a brand and a search), else its first Toolbar.\n const toolbars = all.filter((node) => node.componentId === 'muiToolbar')\n const toolbar = toolbars.find((node) => (node.nodes ?? []).some((id) => map[id]?.componentId === LINK)) ?? toolbars[0]\n return toolbar ? [toolbar] : []\n }\n // A phone menu (in a Drawer) and a footer hold no dropdowns: their entries stay flat.\n const drawerIds = under(all.filter((node) => node.componentId === DRAWER))\n const flat = (menu: AiMenuName, list: Node) => menu === 'footer' || drawerIds.has(list.$id)\n\n const found: Partial<Record<AiMenuName, boolean>> = {}\n const notDone = new Set<string>()\n // What each entry came to across a menu's lists: done where any list did it.\n const outcomes = new Map<string, { ok: boolean; done: string; failed: string }>()\n const mark = (key: string, ok: boolean, done: string, failed: string) => {\n const was = outcomes.get(key)\n outcomes.set(key, { ok: ok || (was?.ok ?? false), done, failed: was && !was.ok && !ok ? was.failed : failed })\n }\n let changed = false\n\n const removeTree = (id: string) => {\n for (const child of [...(map[id]?.nodes ?? [])]) removeTree(child)\n delete map[id]\n }\n const detach = (id: string) => {\n for (const node of Object.values(map)) {\n if (node.nodes?.includes(id)) node.nodes = node.nodes.filter((child) => child !== id)\n }\n }\n const setTarget = (node: Node, to: AiMenuTarget) => {\n const props = { ...(node.props ?? {}) }\n delete props['screenId']\n delete props['href']\n node.props = { ...props, ...to }\n }\n /** A new link like the list's own, else a plain one. */\n const linkLike = (template: Node | undefined, parentId: string, label: string, to: AiMenuTarget): string => {\n const id = newId()\n const props: Record<string, unknown> = template?.props\n ? { ...template.props }\n : { renderAs: 'link', color: 'inherit' }\n delete props['screenId']\n delete props['href']\n map[id] = {\n ...(template ?? { sx: { textDecoration: 'none', whiteSpace: 'nowrap' } }),\n $id: id,\n componentId: LINK,\n pluginId: template?.pluginId ?? 'mui',\n parentId,\n props: { ...props, children: label.slice(0, AI_MENU_LABEL_MAX), ...to },\n nodes: [],\n }\n return id\n }\n /** Whether a link opens a destination: the same page, or the same address. */\n const opens = (node: Node | undefined, to: AiMenuTarget) =>\n 'screenId' in to ? node?.props?.['screenId'] === to.screenId : node?.props?.['href'] === to.href\n /** Every link in a dropdown, at any depth (a Mega Menu's columns). */\n const linksIn = (dropdown: string) => [...under([map[dropdown]])].filter((id) => id !== dropdown && isLink(id))\n /** An entry in one list: a top-level item, or a link in a dropdown (or, in a flat list, the item itself). */\n const find = (list: Node, entry: AiMenuEntryRef, isFlat: boolean): string | null => {\n const top = itemsOf(list)\n if (!entry.parent) return top.find((id) => same(labelOf(id), entry.label)) ?? null\n const parent = top.find((id) => isDropdown(id) && same(labelOf(id), entry.parent as string))\n if (parent) return linksIn(parent).find((id) => same(labelOf(id), entry.label)) ?? null\n return isFlat ? (top.find((id) => isLink(id) && same(labelOf(id), entry.label)) ?? null) : null\n }\n\n for (const menu of menus) {\n const lists = listsOf(menu)\n found[menu] = lists.length > 0\n if (!lists.length) {\n notDone.add(`The ${menu} has no list of links to change: add them in the layout by hand.`)\n continue\n }\n for (const list of lists) {\n const isFlat = flat(menu, list)\n for (const entry of changes.remove) {\n const id = find(list, entry, isFlat)\n const key = `remove:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n mark(key, !!id, `Took “${aiMenuEntryName(entry)}” out of the ${menu}.`, `No “${aiMenuEntryName(entry)}” in the ${menu} to take out.`)\n if (!id) continue\n detach(id)\n removeTree(id)\n changed = true\n }\n for (const entry of changes.rename) {\n const id = find(list, entry, isFlat)\n const name = entry.name.slice(0, AI_MENU_LABEL_MAX)\n const key = `rename:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n mark(key, !!id, `Renamed “${aiMenuEntryName(entry)}” to “${name}” in the ${menu}.`, `No “${aiMenuEntryName(entry)}” in the ${menu} to rename.`)\n if (!id) continue\n map[id].props = { ...(map[id].props ?? {}), [isDropdown(id) ? 'label' : 'children']: name }\n changed = true\n }\n for (const entry of changes.relink) {\n const id = find(list, entry, isFlat)\n const key = `relink:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n mark(\n key,\n !!id && isLink(id),\n `Pointed “${aiMenuEntryName(entry)}” in the ${menu} somewhere new.`,\n id ? `“${aiMenuEntryName(entry)}” opens a dropdown, which links nowhere itself.` : `No “${aiMenuEntryName(entry)}” in the ${menu} to relink.`,\n )\n if (!id || !isLink(id)) continue\n setTarget(map[id], entry.to)\n changed = true\n }\n for (const entry of changes.add) {\n const key = `add:${menu}:${aiMenuEntryName(entry).toLowerCase()}`\n if (find(list, entry, isFlat)) {\n mark(key, true, `“${aiMenuEntryName(entry)}” was already in the ${menu}.`, '')\n continue\n }\n const children = list.nodes ?? []\n const template = map[children.filter(isLink).slice(-1)[0]]\n // After the list's last item, else after its brand: before a search,\n // a mode switch or a call to action that follows them.\n const lastOf = (test: (id: string) => boolean) => children.reduce((at, id, index) => (test(id) ? index : at), -1)\n const lastItem = lastOf(isItem) !== -1 ? lastOf(isItem) : lastOf((id) => map[id]?.componentId === LINK)\n if (!entry.parent || isFlat) {\n // After its parent in a flat list, else after the item it is to\n // follow, else after the list's last item.\n const parentAt = entry.parent ? children.findIndex((id) => isItem(id) && same(labelOf(id), entry.parent as string)) : -1\n const afterAt = !entry.parent && entry.after?.length ? children.findIndex((id) => isLink(id) && (entry.after ?? []).some((to) => opens(map[id], to))) : -1\n let at = parentAt !== -1 ? parentAt : afterAt !== -1 ? afterAt : lastItem\n if (parentAt !== -1) {\n // After the entries already following the parent from an earlier add.\n while (at + 1 < children.length && isLink(children[at + 1]) && String(children[at + 1]).startsWith('ai_nav_')) at += 1\n }\n const id = linkLike(template, list.$id, entry.label, entry.to)\n list.nodes = [...children.slice(0, at + 1), id, ...children.slice(at + 1)]\n } else {\n let dropdown = children.find((id) => isDropdown(id) && same(labelOf(id), entry.parent as string))\n if (!dropdown) {\n // A Dropdown Menu of that name, where its link of that name was, else last.\n dropdown = newId()\n const own = children.find((id) => isLink(id) && same(labelOf(id), entry.parent as string))\n map[dropdown] = {\n $id: dropdown,\n componentId: NAV_MENU,\n pluginId: 'mui',\n parentId: list.$id,\n props: {\n label: (entry.parent as string).slice(0, AI_MENU_LABEL_MAX),\n // Drawn like the links beside it (AGL-4239).\n ...aiMenuTriggerLookFrom(own ? map[own] : template),\n },\n nodes: own ? [own] : [],\n }\n if (own) {\n map[own].parentId = dropdown\n list.nodes = children.map((id) => (id === own ? (dropdown as string) : id))\n } else {\n list.nodes = [...children.slice(0, lastItem + 1), dropdown, ...children.slice(lastItem + 1)]\n }\n }\n const inside = map[dropdown]\n const id = linkLike(map[linksIn(dropdown)[0]] ?? template, dropdown, entry.label, entry.to)\n inside.nodes = [...(inside.nodes ?? []), id]\n }\n changed = true\n mark(key, true, `Added “${aiMenuEntryName(entry)}” to the ${menu}.`, '')\n }\n if (changes.order.length) {\n const children = list.nodes ?? []\n const slots = children.map((id, index) => (isItem(id) ? index : -1)).filter((index) => index !== -1)\n const items = slots.map((index) => children[index])\n const named = changes.order.flatMap((label) => items.filter((id) => same(labelOf(id), label)).slice(0, 1))\n const ordered = [...new Set([...named, ...items])]\n if (ordered.some((id, index) => id !== items[index])) {\n const next = [...children]\n slots.forEach((slot, index) => {\n next[slot] = ordered[index]\n })\n list.nodes = next\n changed = true\n }\n for (const label of changes.order) {\n mark(\n `order:${menu}:${label.toLowerCase()}`,\n items.some((id) => same(labelOf(id), label)),\n `Put “${label}” in its place in the ${menu}.`,\n `No “${label}” in the ${menu} to put in order.`,\n )\n }\n }\n }\n }\n // A link taken out leaves no dropdown with no link in it, and no footer\n // heading or column with nothing under it (AGL-3735).\n if (changed && changes.remove.length) aiLayoutRepairFrameHollows(map as unknown as Record<string, unknown>)\n const entries = [...outcomes.values()]\n return {\n nodes: changed ? (map as Record<string, unknown>) : null,\n found,\n done: [...new Set(entries.filter((entry) => entry.ok).map((entry) => entry.done))],\n notDone: [...notDone, ...new Set(entries.filter((entry) => !entry.ok).map((entry) => entry.failed))],\n }\n}\n\n// ── The change as an item's arguments carry it ───────────────────────────\n\n/** How an entry names a parent, a label and a destination: `Services > Roofing => /roofing`. */\nconst ARROW = /\\s*=>\\s*/\nconst PARENT = /\\s*>\\s*/\n\n/** What reading an item's arguments came to: the change, and what could not be read. */\nexport interface AiMenuChangesRead {\n changes: AiMenuChanges\n problems: string[]\n}\n\n/** An entry's parent and label: `Services > Roofing`, or `Roofing`. */\nfunction entryRefOf(text: string): AiMenuEntryRef | null {\n const parts = text.split(PARENT).map((part) => said(part)).filter(Boolean)\n if (!parts.length || parts.length > 2) return null\n const label = parts[parts.length - 1].slice(0, AI_MENU_LABEL_MAX)\n return { parent: parts.length === 2 ? parts[0].slice(0, AI_MENU_LABEL_MAX) : null, label }\n}\n\nconst list = (value: unknown): string[] =>\n Array.isArray(value) ? value.filter((one): one is string => typeof one === 'string').map(said).filter(Boolean).slice(0, AI_MENU_CHANGES_MAX) : []\n\n/**\n * A navigation item's change, read off its arguments (AGL-3728). Each entry\n * is words: `add` and `relink` take `Label => destination` (a parent first\n * as `Parent > Label`), `remove` the label, `rename` `Old => New`, `order`\n * labels. `target` turns a destination into a page or an address, or `null`\n * for one this site cannot link, which leaves that entry out with a sentence.\n */\nexport function aiMenuChangesOf(\n args: Readonly<Record<string, unknown>>,\n target: (destination: string) => AiMenuTarget | null,\n): AiMenuChangesRead {\n const problems: string[] = []\n const changes = aiNoMenuChanges()\n const linked = (entry: string, verb: 'add' | 'relink') => {\n const [name, destination, ...rest] = entry.split(ARROW)\n const ref = entryRefOf(name ?? '')\n if (!ref || !said(destination) || rest.length) {\n problems.push(`“${entry}” is not “Label => page or address”, so it was left out.`)\n return\n }\n const to = target(said(destination))\n if (!to) {\n problems.push(`“${aiMenuEntryName(ref)}” links “${said(destination)}”, which is no page or address on this site, so it was left out.`)\n return\n }\n changes[verb].push({ ...ref, to })\n }\n for (const entry of list(args['add'])) linked(entry, 'add')\n for (const entry of list(args['relink'])) linked(entry, 'relink')\n for (const entry of list(args['remove'])) {\n const ref = entryRefOf(entry)\n if (ref) changes.remove.push(ref)\n else problems.push(`“${entry}” names no menu item, so it was left out.`)\n }\n for (const entry of list(args['rename'])) {\n const [from, to, ...rest] = entry.split(ARROW)\n const ref = entryRefOf(from ?? '')\n const name = said(to)\n if (!ref || !name || rest.length) problems.push(`“${entry}” is not “Old name => New name”, so it was left out.`)\n else changes.rename.push({ ...ref, name: name.slice(0, AI_MENU_LABEL_MAX) })\n }\n changes.order = list(args['order']).map((label) => label.slice(0, AI_MENU_LABEL_MAX))\n return { changes, problems }\n}\n\n/** A change that does nothing, to build one from. */\nexport function aiNoMenuChanges(): AiMenuChanges {\n return { add: [], remove: [], rename: [], relink: [], order: [] }\n}\n\n/** Whether a change does anything at all. */\nexport function aiMenuChangesEmpty(changes: AiMenuChanges): boolean {\n return !changes.add.length && !changes.remove.length && !changes.rename.length && !changes.relink.length && !changes.order.length\n}\n\n/** The menus an item's `menu` names: the header, the footer, or both. */\nexport function aiMenusOf(value: unknown): AiMenuName[] {\n if (value === 'footer') return ['footer']\n if (value === 'both') return ['header', 'footer']\n return ['header']\n}\n\n/** The `new:` references an entry's destination makes: what the item must be built after. */\nexport function aiMenuNewRefs(args: Readonly<Record<string, unknown>>): string[] {\n const refs: string[] = []\n for (const key of ['add', 'relink'] as const) {\n for (const entry of list(args[key])) {\n const destination = said(entry.split(ARROW)[1])\n if (/^new:/i.test(destination) && !refs.includes(destination)) refs.push(destination)\n }\n }\n return refs\n}\n"],"names":["aiLayoutRepairFrameHollows","AI_MENU_NAMES","LINK","AI_MENU_DROPDOWNS","NAV_MENU","DRAWER","AI_MENU_CHANGES_MAX","AI_MENU_LABEL_MAX","aiMenuTriggerLookFrom","link","props","look","renderAs","key","undefined","renders","node","element","componentId","said","value","replace","trim","same","a","b","toLowerCase","aiMenuEntryName","entry","parent","label","aiLayoutWithMenuChanges","nodes","menus","changes","options","map","id","raw","Object","entries","$id","counter","newId","all","values","under","roots","seen","Set","queue","root","length","shift","has","add","push","isBrand","test","isLink","isDropdown","includes","String","isItem","itemsOf","list","filter","labelOf","listsOf","menu","toolbars","ids","longest","sort","lists","landmarks","toolbar","find","some","drawerIds","flat","found","notDone","outcomes","Map","mark","ok","done","failed","was","get","set","changed","removeTree","child","detach","setTarget","to","linkLike","template","parentId","color","sx","textDecoration","whiteSpace","pluginId","children","slice","opens","screenId","href","linksIn","dropdown","isFlat","top","remove","rename","name","relink","lastOf","reduce","at","index","lastItem","parentAt","findIndex","afterAt","after","startsWith","inside","own","order","slots","items","named","flatMap","ordered","next","forEach","slot","ARROW","PARENT","entryRefOf","text","parts","split","part","Boolean","Array","isArray","one","aiMenuChangesOf","args","target","problems","aiNoMenuChanges","linked","verb","destination","rest","ref","from","aiMenuChangesEmpty","aiMenusOf","aiMenuNewRefs","refs"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CC,GAED,SAASA,0BAA0B,QAAQ,gDAA4C;AAKvF,OAAO,MAAMC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B,QAAQkF,MAAM,CAAChE,MAAM,IAAI,CAAClB,QAAQoF,MAAM,CAAClE,MAAM,IAAI,CAAClB,QAAQiG,KAAK,CAAC/E,MAAM;AACnI;AAEA,uEAAuE,GACvE,OAAO,SAAS+G,UAAU/I,KAAc;IACtC,IAAIA,UAAU,UAAU,OAAO;QAAC;KAAS;IACzC,IAAIA,UAAU,QAAQ,OAAO;QAAC;QAAU;KAAS;IACjD,OAAO;QAAC;KAAS;AACnB;AAEA,2FAA2F,GAC3F,OAAO,SAASgJ,cAAcZ,IAAuC;IACnE,MAAMa,OAAiB,EAAE;IACzB,KAAK,MAAMxJ,OAAO;QAAC;QAAO;KAAS,CAAW;QAC5C,KAAK,MAAMe,SAASqC,KAAKuF,IAAI,CAAC3I,IAAI,EAAG;YACnC,MAAMiJ,cAAc3I,KAAKS,MAAMqH,KAAK,CAACL,MAAM,CAAC,EAAE;YAC9C,IAAI,SAASlF,IAAI,CAACoG,gBAAgB,CAACO,KAAKxG,QAAQ,CAACiG,cAAcO,KAAK7G,IAAI,CAACsG;QAC3E;IACF;IACA,OAAOO;AACT"}
@@ -160,6 +160,8 @@ export interface AssistEditNode {
160
160
  props: Record<string, unknown>;
161
161
  sx?: Record<string, unknown>;
162
162
  hidden?: boolean;
163
+ /** The layer name, when the request gave the new element one (AGL-4235). */
164
+ name?: string;
163
165
  }
164
166
  /**
165
167
  * Every op that acts on an element names the component the server validated
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/assist-edit.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 { ScreenSeoTextField } from '@aglyn/aglyn/app-utils/screen-seo-fields'\nimport type { ReusableComponentProp } from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport type { NodeInteraction } from '@aglyn/aglyn/app-utils/node-interactions'\n\n/**\n * Assist level 3, the edit contract (AGL-2906): what the chat door proposes\n * for a besigner canvas, and what the panel applies once the author says so.\n *\n * Shared by the server, which validates a model's proposal into these\n * shapes, and the client, which applies them. Pure data and pure functions,\n * so the panel imports it without pulling the palette or the runtime.\n *\n * ## The boundary\n *\n * A proposal is OPERATIONS, never a document. The server writes nothing: it\n * answers with ops that name elements already on the canvas, or a validated\n * subtree to insert, and the client applies them through the canvas's own\n * guarded mutators, on confirm, as one undoable step. Every change lands as\n * an unsaved edit on the version the editor has open — a draft — and on a\n * version the live site serves, the editor's own new-version flow runs first.\n */\n\n/** The nine operations a proposal may carry. */\nexport const ASSIST_EDIT_OP_KINDS = [\n 'insertSubtree',\n 'updateProps',\n 'updateSx',\n 'move',\n 'remove',\n 'setSeo',\n 'rename',\n 'saveAsComponent',\n 'addInteraction',\n] as const\n\nexport type AssistEditOpKind = (typeof ASSIST_EDIT_OP_KINDS)[number]\n\n/** The id of the besigner view's edit action — the one edit a view offers. */\nexport const ASSIST_EDIT_ACTION_ID = 'edit.canvas'\n\n/** The name of the structured-output tool a model proposes an edit through. */\nexport const ASSIST_EDIT_TOOL_NAME = 'propose_canvas_edit'\n\n/** The besigner documents the edit rung opens on: those that keep versions. */\nexport type AssistEditDocumentKind = 'screen' | 'component' | 'layout'\n\nexport const ASSIST_EDIT_DOCUMENT_KINDS: readonly AssistEditDocumentKind[] = [\n 'screen',\n 'component',\n 'layout',\n]\n\nconst COLLECTION_KINDS: Readonly<Record<string, AssistEditDocumentKind>> = {\n screens: 'screen',\n components: 'component',\n layouts: 'layout',\n}\n\nconst BESIGNER_DOCUMENT_ROUTE =\n /^\\/[^/]+\\/hosts\\/[^/]+\\/(screens|components|layouts)\\/([A-Za-z0-9_-]{1,64})\\/versions\\/([A-Za-z0-9_-]{1,64})\\/besigner\\/?$/\n\n/** The document a besigner route has open. */\nexport interface AssistEditDocument {\n kind: AssistEditDocumentKind\n documentId: string\n versionId: string\n}\n\n/**\n * The open document off a console path, or null off a route the edit rung\n * serves. Only the versioned editors qualify — a template or an email editor\n * has no version to make first, so the rung does not open there.\n */\nexport function assistEditDocumentOf(route: string): AssistEditDocument | null {\n const match = BESIGNER_DOCUMENT_ROUTE.exec(String(route ?? ''))\n if (!match) return null\n return {\n kind: COLLECTION_KINDS[match[1]],\n documentId: match[2],\n versionId: match[3],\n }\n}\n\n/* ------------------------------------------------------------------ *\n * What the client tells the server about the canvas\n * ------------------------------------------------------------------ */\n\n/** Elements a request describes at most — the selection, its surroundings, its subtree. */\nexport const ASSIST_EDIT_CONTEXT_MAX_NODES = 60\n/** Props described per element at most. */\nexport const ASSIST_EDIT_CONTEXT_MAX_PROPS = 16\n/** Characters of a string prop the selected element carries into a request. */\nexport const ASSIST_EDIT_SELECTED_TEXT_CHARS = 400\n/** Characters of a string prop every other element carries. */\nexport const ASSIST_EDIT_OUTLINE_TEXT_CHARS = 80\n/**\n * Elements a whole-document outline describes at most: one the server reads\n * from the stored document for an edit job, or the chat in the Besigner sends\n * of the open canvas (AGL-4116). Far past a page an AI build or a starter makes\n * (the starter home has 182), so in practice the model sees every element it\n * could be asked about.\n */\nexport const ASSIST_EDIT_WHOLE_MAX_NODES = 400\n\n/**\n * One element of the canvas outline a request carries. Ids, component ids\n * and short primitive values only — never a stored document, never markup.\n */\nexport interface AssistEditCanvasNode {\n id: string\n componentId: string\n /** Null for the document root. */\n parentId: string | null\n /** Position among the parent's children. */\n index: number\n childCount: number\n /** The layer name, when the author gave it one. */\n name?: string\n /** Primitive props, strings shortened. */\n props?: Record<string, string | number | boolean>\n /**\n * The element's own styles — carried for the selected element only, and\n * for every element of a whole-document outline.\n */\n sx?: Record<string, unknown>\n /**\n * Described by its place alone, without props: an element around the\n * selection, there so the model knows it exists and can ask for it.\n */\n brief?: boolean\n /**\n * An element described earlier whose contents this one's are built like,\n * the way the cards of a row are. Its own contents are left out.\n */\n like?: string\n /**\n * The interactions the element carries (AGL-3603), each by its name, the\n * event it listens for and its steps' kinds — carried for the selected\n * element only, so Assist can say what it does. Never a selector, a script\n * or HTML.\n */\n interactions?: AssistEditInteractionSummary[]\n}\n\n/** One interaction on an element, as an outline describes it. */\nexport interface AssistEditInteractionSummary {\n name: string\n event: string\n steps: string[]\n enabled: boolean\n}\n\n/* ------------------------------------------------------------------ *\n * The interactions Assist may add (AGL-3603)\n * ------------------------------------------------------------------ */\n\n/**\n * The events an interaction Assist adds may listen for: those that watch the\n * element it is added to, the way the Besigner's Interactions section offers\n * them on a selected element.\n */\nexport const ASSIST_EDIT_INTERACTION_EVENTS = [\n 'elementClick',\n 'elementHoverEnter',\n 'elementHoverLeave',\n 'elementVisible',\n 'scrollToElement',\n] as const\n\nexport type AssistEditInteractionEvent = (typeof ASSIST_EDIT_INTERACTION_EVENTS)[number]\n\n/**\n * The steps it may take: the platform's basic presentational client steps,\n * which run on every plan and touch no data. No script, no HTML, no\n * attribute, no overlay, no analytics event — and no server step.\n */\nexport const ASSIST_EDIT_INTERACTION_STEPS = [\n 'showElement',\n 'hideElement',\n 'toggleElement',\n 'addClass',\n 'removeClass',\n 'toggleClass',\n 'scrollTo',\n 'playVideo',\n 'openDrawer',\n 'closeDrawer',\n 'toggleDrawer',\n 'openMenu',\n 'closeMenu',\n 'toggleMenu',\n 'redirect',\n 'siteAlert',\n] as const\n\nexport type AssistEditInteractionStep = (typeof ASSIST_EDIT_INTERACTION_STEPS)[number]\n\nexport interface AssistEditCanvasContext {\n /** The element the author has selected, or null. */\n selectedId: string | null\n /**\n * Elements in the whole document, the root included, so the prompt can say\n * how much of it `nodes` leaves out. Absent from an outline sent by a panel\n * that predates it.\n */\n total?: number\n nodes: AssistEditCanvasNode[]\n /**\n * The whole document, every element in page order up to\n * {@link ASSIST_EDIT_WHOLE_MAX_NODES}, each with its settings and styles:\n * read from the store for a job, or from the open canvas for the chat in the\n * Besigner (AGL-4116).\n */\n whole?: true\n}\n\n/* ------------------------------------------------------------------ *\n * What the server proposes\n * ------------------------------------------------------------------ */\n\n/** An element of a validated subtree, in the flat shape the canvas stores. */\nexport interface AssistEditNode {\n $id: string\n componentId: string\n pluginId?: string\n parentId: string | null\n nodes: string[]\n props: Record<string, unknown>\n sx?: Record<string, unknown>\n hidden?: boolean\n}\n\n/**\n * Every op that acts on an element names the component the server validated\n * it as, so the client can refuse an element that has changed since.\n */\ninterface AssistEditNodeOpBase {\n nodeId: string\n componentId: string\n}\n\nexport interface AssistEditInsertOp {\n op: 'insertSubtree'\n parentId: string\n /** The component the parent was validated as. */\n parentComponentId: string\n /** Position among the parent's children; null appends. */\n index: number | null\n rootId: string\n nodes: Record<string, AssistEditNode>\n}\n\nexport interface AssistEditUpdatePropsOp extends AssistEditNodeOpBase {\n op: 'updateProps'\n /** Merged over the props the element has; nothing else it carries changes. */\n props: Record<string, unknown>\n}\n\nexport interface AssistEditUpdateSxOp extends AssistEditNodeOpBase {\n op: 'updateSx'\n /** Merged over the element's own styles, one key at a time. */\n sx: Record<string, unknown>\n}\n\nexport interface AssistEditMoveOp extends AssistEditNodeOpBase {\n op: 'move'\n parentId: string\n /** The component the new parent was validated as. */\n parentComponentId: string\n index: number | null\n}\n\nexport interface AssistEditRemoveOp extends AssistEditNodeOpBase {\n op: 'remove'\n}\n\nexport interface AssistEditRenameOp extends AssistEditNodeOpBase {\n op: 'rename'\n name: string\n}\n\nexport interface AssistEditSetSeoOp {\n op: 'setSeo'\n fields: Partial<Record<ScreenSeoTextField, string>>\n}\n\n/**\n * A property the promoted subtree declares (AGL-2908), in the shape the\n * Properties dialog stores one — without a default.\n *\n * The server never sees a full value: the outline it read the selection from\n * shortens every string. So the default is read off the live canvas at apply\n * time, from the very field the token is about to replace, which is what\n * makes the instance render what was there a moment before.\n */\nexport type AssistEditComponentProp = Omit<ReusableComponentProp, 'defaultValue'>\n\n/** Where one property's token goes: an element of the selection, and a field of it. */\nexport interface AssistEditPropBinding {\n nodeId: string\n /** The component the element was validated as, so a changed one is refused. */\n componentId: string\n /** A prop of that element, or `hideIf` for a part a Yes / no hides. */\n field: string\n /** The property whose `{{prop.<name>}}` token the field takes. */\n prop: string\n}\n\n/**\n * Save the selection as a reusable component (AGL-2908), with the properties\n * the model proposed and the tokens bound into the tree.\n *\n * The only op that creates a document. It creates exactly the one the manual\n * Save as reusable component creates, through the same host resources route,\n * where the plan's entitlement and the route's allow-list are enforced — and\n * it changes the open canvas the same way that action does, by swapping the\n * promoted subtree for an instance. Nothing is published and nothing is\n * saved: the swap is an unsaved edit on the version the editor has open.\n */\nexport interface AssistEditSaveAsComponentOp extends AssistEditNodeOpBase {\n op: 'saveAsComponent'\n /** The name the component is created under. */\n name: string\n props: AssistEditComponentProp[]\n bindings: AssistEditPropBinding[]\n}\n\n/**\n * Add one interaction to an element (AGL-3603), in the shape the element\n * stores it — its trigger with no selector, which the element's id derives.\n * It never replaces or removes one the element already carries.\n */\nexport interface AssistEditAddInteractionOp extends AssistEditNodeOpBase {\n op: 'addInteraction'\n interaction: NodeInteraction\n /** Every other element a step acts on, each with the component it was validated as. */\n targets: Array<{ nodeId: string; componentId: string }>\n}\n\nexport type AssistEditOp =\n | AssistEditAddInteractionOp\n | AssistEditInsertOp\n | AssistEditUpdatePropsOp\n | AssistEditUpdateSxOp\n | AssistEditMoveOp\n | AssistEditRemoveOp\n | AssistEditRenameOp\n | AssistEditSetSeoOp\n | AssistEditSaveAsComponentOp\n\n/** Where a proposal applies, as the server read it off the request. */\nexport interface AssistEditTarget extends AssistEditDocument {\n hostId: string\n}\n\n/** The counts the card shows before the author decides. */\nexport interface AssistEditDiff {\n /** Elements added, every element of every inserted subtree counted. */\n added: number\n /** Elements removed — each with whatever it contains. */\n removed: number\n propsChanged: number\n stylesChanged: number\n moved: number\n renamed: number\n /** Search fields filled in. */\n seoFields: number\n /** Properties the selection declares once it is saved as a component. */\n componentProps: number\n /** Selections saved as a reusable component — at most one per proposal. */\n componentsSaved: number\n /** Interactions added to elements. */\n interactionsAdded: number\n}\n\n/** The most reasons a proposal carries for the changes validation left out. */\nexport const ASSIST_EDIT_MAX_DROPPED_REASONS = 10\n\nexport interface AssistEditProposal {\n id: typeof ASSIST_EDIT_ACTION_ID\n /** One line, in the model's words, of what the edit does. */\n summary: string\n ops: AssistEditOp[]\n diff: AssistEditDiff\n /** Why each change the model wrote and validation refused was left out. */\n dropped: string[]\n target: AssistEditTarget\n}\n\n/** The counts for a list of ops. */\nexport function summarizeAssistEditOps(ops: readonly AssistEditOp[]): AssistEditDiff {\n const diff: AssistEditDiff = {\n added: 0,\n removed: 0,\n propsChanged: 0,\n stylesChanged: 0,\n moved: 0,\n renamed: 0,\n seoFields: 0,\n componentProps: 0,\n componentsSaved: 0,\n interactionsAdded: 0,\n }\n for (const op of ops) {\n switch (op.op) {\n case 'insertSubtree':\n diff.added += Object.keys(op.nodes).length\n break\n case 'remove':\n diff.removed += 1\n break\n case 'updateProps':\n diff.propsChanged += 1\n break\n case 'updateSx':\n diff.stylesChanged += 1\n break\n case 'move':\n diff.moved += 1\n break\n case 'rename':\n diff.renamed += 1\n break\n case 'setSeo':\n diff.seoFields += Object.keys(op.fields).length\n break\n case 'saveAsComponent':\n diff.componentsSaved += 1\n diff.componentProps += op.props.length\n break\n case 'addInteraction':\n diff.interactionsAdded += 1\n break\n }\n }\n return diff\n}\n\nconst plural = (count: number, one: string, many: string): string =>\n `${count} ${count === 1 ? one : many}`\n\n/** The diff as the lines a person reads, zero counts omitted. */\nexport function describeAssistEditDiff(diff: AssistEditDiff): string[] {\n const lines: string[] = []\n if (diff.added) lines.push(`${plural(diff.added, 'element', 'elements')} added`)\n if (diff.removed) lines.push(`${plural(diff.removed, 'element', 'elements')} removed`)\n if (diff.propsChanged) {\n lines.push(`${plural(diff.propsChanged, 'element’s settings', 'elements’ settings')} changed`)\n }\n if (diff.stylesChanged) {\n lines.push(`${plural(diff.stylesChanged, 'element', 'elements')} restyled`)\n }\n if (diff.moved) lines.push(`${plural(diff.moved, 'element', 'elements')} moved`)\n if (diff.renamed) lines.push(`${plural(diff.renamed, 'layer', 'layers')} renamed`)\n if (diff.seoFields) {\n lines.push(`${plural(diff.seoFields, 'search field', 'search fields')} filled in`)\n }\n if (diff.interactionsAdded) {\n lines.push(`${plural(diff.interactionsAdded, 'interaction', 'interactions')} added`)\n }\n if (diff.componentsSaved) {\n lines.push(\n `saved as a reusable component with ${plural(diff.componentProps, 'property', 'properties')}`,\n )\n }\n return lines\n}\n\n/** The word each op kind is counted under in the activity row. */\nconst OP_COUNT_WORDS: Readonly<Record<AssistEditOpKind, string>> = {\n updateProps: 'set',\n updateSx: 'restyle',\n insertSubtree: 'insert',\n move: 'move',\n remove: 'remove',\n rename: 'rename',\n setSeo: 'seo',\n saveAsComponent: 'component',\n addInteraction: 'interaction',\n}\n\n/** The applied ops counted by kind, as the activity row names them (`{ set: 3, insert: 1 }`). */\nexport function assistEditOpCounts(ops: readonly AssistEditOp[]): Record<string, number> {\n const counts: Record<string, number> = {}\n for (const op of ops) {\n const word = OP_COUNT_WORDS[op.op]\n if (word) counts[word] = (counts[word] ?? 0) + 1\n }\n return counts\n}\n\n/** The words `assistEditOpCounts` counts under, for a door that reads them back. */\nexport const ASSIST_EDIT_OP_COUNT_WORDS: readonly string[] = Object.values(OP_COUNT_WORDS)\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * Whether a `done` event's `edit` field is a proposal this client can apply.\n * The server built it, so this is a shape check rather than a validation: it\n * keeps a malformed or foreign payload from reaching the canvas mutators.\n */\nexport function isAssistEditProposal(value: unknown): value is AssistEditProposal {\n if (!isRecord(value) || value['id'] !== ASSIST_EDIT_ACTION_ID) return false\n const target = value['target']\n if (!isRecord(target)) return false\n if (!ASSIST_EDIT_DOCUMENT_KINDS.includes(target['kind'] as AssistEditDocumentKind)) return false\n if (typeof target['documentId'] !== 'string' || !target['documentId']) return false\n const ops = value['ops']\n if (!Array.isArray(ops) || !ops.length) return false\n return ops.every(\n (op) => isRecord(op) && ASSIST_EDIT_OP_KINDS.includes(op['op'] as AssistEditOpKind),\n )\n}\n\n/* ------------------------------------------------------------------ *\n * What the client reports once the author applied a proposal\n * ------------------------------------------------------------------ */\n\n/** The body of `POST /api/assist/edit-applied`. */\nexport interface AssistEditAppliedReport {\n orgId: string\n hostId: string\n /** The exchange whose answer carried the proposal. */\n exchangeId: string\n documentKind: AssistEditDocumentKind\n documentId: string\n /** The version the edits landed on — a new one when the open one was live. */\n versionId: string\n opCounts: Record<string, number>\n}\n"],"names":["ASSIST_EDIT_OP_KINDS","ASSIST_EDIT_ACTION_ID","ASSIST_EDIT_TOOL_NAME","ASSIST_EDIT_DOCUMENT_KINDS","COLLECTION_KINDS","screens","components","layouts","BESIGNER_DOCUMENT_ROUTE","assistEditDocumentOf","route","match","exec","String","kind","documentId","versionId","ASSIST_EDIT_CONTEXT_MAX_NODES","ASSIST_EDIT_CONTEXT_MAX_PROPS","ASSIST_EDIT_SELECTED_TEXT_CHARS","ASSIST_EDIT_OUTLINE_TEXT_CHARS","ASSIST_EDIT_WHOLE_MAX_NODES","ASSIST_EDIT_INTERACTION_EVENTS","ASSIST_EDIT_INTERACTION_STEPS","ASSIST_EDIT_MAX_DROPPED_REASONS","summarizeAssistEditOps","ops","diff","added","removed","propsChanged","stylesChanged","moved","renamed","seoFields","componentProps","componentsSaved","interactionsAdded","op","Object","keys","nodes","length","fields","props","plural","count","one","many","describeAssistEditDiff","lines","push","OP_COUNT_WORDS","updateProps","updateSx","insertSubtree","move","remove","rename","setSeo","saveAsComponent","addInteraction","assistEditOpCounts","counts","word","ASSIST_EDIT_OP_COUNT_WORDS","values","isRecord","value","Array","isArray","isAssistEditProposal","target","includes","every"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAMD;;;;;;;;;;;;;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AACC,KAAK,GAAG,EAACD,eAAAA,MAAM,CAACC,KAAK,YAAZD,eAAgB,KAAK;IACjD;IACA,OAAOA;AACT;AAEA,kFAAkF,GAClF,OAAO,MAAME,6BAAgD1B,OAAO2B,MAAM,CAACd,gBAAe;AAE1F,MAAMe,WAAW,CAACC,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AAEhE;;;;CAIC,GACD,OAAO,SAASG,qBAAqBH,KAAc;IACjD,IAAI,CAACD,SAASC,UAAUA,KAAK,CAAC,KAAK,KAAKnE,uBAAuB,OAAO;IACtE,MAAMuE,SAASJ,KAAK,CAAC,SAAS;IAC9B,IAAI,CAACD,SAASK,SAAS,OAAO;IAC9B,IAAI,CAACrE,2BAA2BsE,QAAQ,CAACD,MAAM,CAAC,OAAO,GAA6B,OAAO;IAC3F,IAAI,OAAOA,MAAM,CAAC,aAAa,KAAK,YAAY,CAACA,MAAM,CAAC,aAAa,EAAE,OAAO;IAC9E,MAAM9C,MAAM0C,KAAK,CAAC,MAAM;IACxB,IAAI,CAACC,MAAMC,OAAO,CAAC5C,QAAQ,CAACA,IAAIgB,MAAM,EAAE,OAAO;IAC/C,OAAOhB,IAAIgD,KAAK,CACd,CAACpC,KAAO6B,SAAS7B,OAAOtC,qBAAqByE,QAAQ,CAACnC,EAAE,CAAC,KAAK;AAElE"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/assist-edit.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 { ScreenSeoTextField } from '@aglyn/aglyn/app-utils/screen-seo-fields'\nimport type { ReusableComponentProp } from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport type { NodeInteraction } from '@aglyn/aglyn/app-utils/node-interactions'\n\n/**\n * Assist level 3, the edit contract (AGL-2906): what the chat door proposes\n * for a besigner canvas, and what the panel applies once the author says so.\n *\n * Shared by the server, which validates a model's proposal into these\n * shapes, and the client, which applies them. Pure data and pure functions,\n * so the panel imports it without pulling the palette or the runtime.\n *\n * ## The boundary\n *\n * A proposal is OPERATIONS, never a document. The server writes nothing: it\n * answers with ops that name elements already on the canvas, or a validated\n * subtree to insert, and the client applies them through the canvas's own\n * guarded mutators, on confirm, as one undoable step. Every change lands as\n * an unsaved edit on the version the editor has open — a draft — and on a\n * version the live site serves, the editor's own new-version flow runs first.\n */\n\n/** The nine operations a proposal may carry. */\nexport const ASSIST_EDIT_OP_KINDS = [\n 'insertSubtree',\n 'updateProps',\n 'updateSx',\n 'move',\n 'remove',\n 'setSeo',\n 'rename',\n 'saveAsComponent',\n 'addInteraction',\n] as const\n\nexport type AssistEditOpKind = (typeof ASSIST_EDIT_OP_KINDS)[number]\n\n/** The id of the besigner view's edit action — the one edit a view offers. */\nexport const ASSIST_EDIT_ACTION_ID = 'edit.canvas'\n\n/** The name of the structured-output tool a model proposes an edit through. */\nexport const ASSIST_EDIT_TOOL_NAME = 'propose_canvas_edit'\n\n/** The besigner documents the edit rung opens on: those that keep versions. */\nexport type AssistEditDocumentKind = 'screen' | 'component' | 'layout'\n\nexport const ASSIST_EDIT_DOCUMENT_KINDS: readonly AssistEditDocumentKind[] = [\n 'screen',\n 'component',\n 'layout',\n]\n\nconst COLLECTION_KINDS: Readonly<Record<string, AssistEditDocumentKind>> = {\n screens: 'screen',\n components: 'component',\n layouts: 'layout',\n}\n\nconst BESIGNER_DOCUMENT_ROUTE =\n /^\\/[^/]+\\/hosts\\/[^/]+\\/(screens|components|layouts)\\/([A-Za-z0-9_-]{1,64})\\/versions\\/([A-Za-z0-9_-]{1,64})\\/besigner\\/?$/\n\n/** The document a besigner route has open. */\nexport interface AssistEditDocument {\n kind: AssistEditDocumentKind\n documentId: string\n versionId: string\n}\n\n/**\n * The open document off a console path, or null off a route the edit rung\n * serves. Only the versioned editors qualify — a template or an email editor\n * has no version to make first, so the rung does not open there.\n */\nexport function assistEditDocumentOf(route: string): AssistEditDocument | null {\n const match = BESIGNER_DOCUMENT_ROUTE.exec(String(route ?? ''))\n if (!match) return null\n return {\n kind: COLLECTION_KINDS[match[1]],\n documentId: match[2],\n versionId: match[3],\n }\n}\n\n/* ------------------------------------------------------------------ *\n * What the client tells the server about the canvas\n * ------------------------------------------------------------------ */\n\n/** Elements a request describes at most — the selection, its surroundings, its subtree. */\nexport const ASSIST_EDIT_CONTEXT_MAX_NODES = 60\n/** Props described per element at most. */\nexport const ASSIST_EDIT_CONTEXT_MAX_PROPS = 16\n/** Characters of a string prop the selected element carries into a request. */\nexport const ASSIST_EDIT_SELECTED_TEXT_CHARS = 400\n/** Characters of a string prop every other element carries. */\nexport const ASSIST_EDIT_OUTLINE_TEXT_CHARS = 80\n/**\n * Elements a whole-document outline describes at most: one the server reads\n * from the stored document for an edit job, or the chat in the Besigner sends\n * of the open canvas (AGL-4116). Far past a page an AI build or a starter makes\n * (the starter home has 182), so in practice the model sees every element it\n * could be asked about.\n */\nexport const ASSIST_EDIT_WHOLE_MAX_NODES = 400\n\n/**\n * One element of the canvas outline a request carries. Ids, component ids\n * and short primitive values only — never a stored document, never markup.\n */\nexport interface AssistEditCanvasNode {\n id: string\n componentId: string\n /** Null for the document root. */\n parentId: string | null\n /** Position among the parent's children. */\n index: number\n childCount: number\n /** The layer name, when the author gave it one. */\n name?: string\n /** Primitive props, strings shortened. */\n props?: Record<string, string | number | boolean>\n /**\n * The element's own styles — carried for the selected element only, and\n * for every element of a whole-document outline.\n */\n sx?: Record<string, unknown>\n /**\n * Described by its place alone, without props: an element around the\n * selection, there so the model knows it exists and can ask for it.\n */\n brief?: boolean\n /**\n * An element described earlier whose contents this one's are built like,\n * the way the cards of a row are. Its own contents are left out.\n */\n like?: string\n /**\n * The interactions the element carries (AGL-3603), each by its name, the\n * event it listens for and its steps' kinds — carried for the selected\n * element only, so Assist can say what it does. Never a selector, a script\n * or HTML.\n */\n interactions?: AssistEditInteractionSummary[]\n}\n\n/** One interaction on an element, as an outline describes it. */\nexport interface AssistEditInteractionSummary {\n name: string\n event: string\n steps: string[]\n enabled: boolean\n}\n\n/* ------------------------------------------------------------------ *\n * The interactions Assist may add (AGL-3603)\n * ------------------------------------------------------------------ */\n\n/**\n * The events an interaction Assist adds may listen for: those that watch the\n * element it is added to, the way the Besigner's Interactions section offers\n * them on a selected element.\n */\nexport const ASSIST_EDIT_INTERACTION_EVENTS = [\n 'elementClick',\n 'elementHoverEnter',\n 'elementHoverLeave',\n 'elementVisible',\n 'scrollToElement',\n] as const\n\nexport type AssistEditInteractionEvent = (typeof ASSIST_EDIT_INTERACTION_EVENTS)[number]\n\n/**\n * The steps it may take: the platform's basic presentational client steps,\n * which run on every plan and touch no data. No script, no HTML, no\n * attribute, no overlay, no analytics event — and no server step.\n */\nexport const ASSIST_EDIT_INTERACTION_STEPS = [\n 'showElement',\n 'hideElement',\n 'toggleElement',\n 'addClass',\n 'removeClass',\n 'toggleClass',\n 'scrollTo',\n 'playVideo',\n 'openDrawer',\n 'closeDrawer',\n 'toggleDrawer',\n 'openMenu',\n 'closeMenu',\n 'toggleMenu',\n 'redirect',\n 'siteAlert',\n] as const\n\nexport type AssistEditInteractionStep = (typeof ASSIST_EDIT_INTERACTION_STEPS)[number]\n\nexport interface AssistEditCanvasContext {\n /** The element the author has selected, or null. */\n selectedId: string | null\n /**\n * Elements in the whole document, the root included, so the prompt can say\n * how much of it `nodes` leaves out. Absent from an outline sent by a panel\n * that predates it.\n */\n total?: number\n nodes: AssistEditCanvasNode[]\n /**\n * The whole document, every element in page order up to\n * {@link ASSIST_EDIT_WHOLE_MAX_NODES}, each with its settings and styles:\n * read from the store for a job, or from the open canvas for the chat in the\n * Besigner (AGL-4116).\n */\n whole?: true\n}\n\n/* ------------------------------------------------------------------ *\n * What the server proposes\n * ------------------------------------------------------------------ */\n\n/** An element of a validated subtree, in the flat shape the canvas stores. */\nexport interface AssistEditNode {\n $id: string\n componentId: string\n pluginId?: string\n parentId: string | null\n nodes: string[]\n props: Record<string, unknown>\n sx?: Record<string, unknown>\n hidden?: boolean\n /** The layer name, when the request gave the new element one (AGL-4235). */\n name?: string\n}\n\n/**\n * Every op that acts on an element names the component the server validated\n * it as, so the client can refuse an element that has changed since.\n */\ninterface AssistEditNodeOpBase {\n nodeId: string\n componentId: string\n}\n\nexport interface AssistEditInsertOp {\n op: 'insertSubtree'\n parentId: string\n /** The component the parent was validated as. */\n parentComponentId: string\n /** Position among the parent's children; null appends. */\n index: number | null\n rootId: string\n nodes: Record<string, AssistEditNode>\n}\n\nexport interface AssistEditUpdatePropsOp extends AssistEditNodeOpBase {\n op: 'updateProps'\n /** Merged over the props the element has; nothing else it carries changes. */\n props: Record<string, unknown>\n}\n\nexport interface AssistEditUpdateSxOp extends AssistEditNodeOpBase {\n op: 'updateSx'\n /** Merged over the element's own styles, one key at a time. */\n sx: Record<string, unknown>\n}\n\nexport interface AssistEditMoveOp extends AssistEditNodeOpBase {\n op: 'move'\n parentId: string\n /** The component the new parent was validated as. */\n parentComponentId: string\n index: number | null\n}\n\nexport interface AssistEditRemoveOp extends AssistEditNodeOpBase {\n op: 'remove'\n}\n\nexport interface AssistEditRenameOp extends AssistEditNodeOpBase {\n op: 'rename'\n name: string\n}\n\nexport interface AssistEditSetSeoOp {\n op: 'setSeo'\n fields: Partial<Record<ScreenSeoTextField, string>>\n}\n\n/**\n * A property the promoted subtree declares (AGL-2908), in the shape the\n * Properties dialog stores one — without a default.\n *\n * The server never sees a full value: the outline it read the selection from\n * shortens every string. So the default is read off the live canvas at apply\n * time, from the very field the token is about to replace, which is what\n * makes the instance render what was there a moment before.\n */\nexport type AssistEditComponentProp = Omit<ReusableComponentProp, 'defaultValue'>\n\n/** Where one property's token goes: an element of the selection, and a field of it. */\nexport interface AssistEditPropBinding {\n nodeId: string\n /** The component the element was validated as, so a changed one is refused. */\n componentId: string\n /** A prop of that element, or `hideIf` for a part a Yes / no hides. */\n field: string\n /** The property whose `{{prop.<name>}}` token the field takes. */\n prop: string\n}\n\n/**\n * Save the selection as a reusable component (AGL-2908), with the properties\n * the model proposed and the tokens bound into the tree.\n *\n * The only op that creates a document. It creates exactly the one the manual\n * Save as reusable component creates, through the same host resources route,\n * where the plan's entitlement and the route's allow-list are enforced — and\n * it changes the open canvas the same way that action does, by swapping the\n * promoted subtree for an instance. Nothing is published and nothing is\n * saved: the swap is an unsaved edit on the version the editor has open.\n */\nexport interface AssistEditSaveAsComponentOp extends AssistEditNodeOpBase {\n op: 'saveAsComponent'\n /** The name the component is created under. */\n name: string\n props: AssistEditComponentProp[]\n bindings: AssistEditPropBinding[]\n}\n\n/**\n * Add one interaction to an element (AGL-3603), in the shape the element\n * stores it — its trigger with no selector, which the element's id derives.\n * It never replaces or removes one the element already carries.\n */\nexport interface AssistEditAddInteractionOp extends AssistEditNodeOpBase {\n op: 'addInteraction'\n interaction: NodeInteraction\n /** Every other element a step acts on, each with the component it was validated as. */\n targets: Array<{ nodeId: string; componentId: string }>\n}\n\nexport type AssistEditOp =\n | AssistEditAddInteractionOp\n | AssistEditInsertOp\n | AssistEditUpdatePropsOp\n | AssistEditUpdateSxOp\n | AssistEditMoveOp\n | AssistEditRemoveOp\n | AssistEditRenameOp\n | AssistEditSetSeoOp\n | AssistEditSaveAsComponentOp\n\n/** Where a proposal applies, as the server read it off the request. */\nexport interface AssistEditTarget extends AssistEditDocument {\n hostId: string\n}\n\n/** The counts the card shows before the author decides. */\nexport interface AssistEditDiff {\n /** Elements added, every element of every inserted subtree counted. */\n added: number\n /** Elements removed — each with whatever it contains. */\n removed: number\n propsChanged: number\n stylesChanged: number\n moved: number\n renamed: number\n /** Search fields filled in. */\n seoFields: number\n /** Properties the selection declares once it is saved as a component. */\n componentProps: number\n /** Selections saved as a reusable component — at most one per proposal. */\n componentsSaved: number\n /** Interactions added to elements. */\n interactionsAdded: number\n}\n\n/** The most reasons a proposal carries for the changes validation left out. */\nexport const ASSIST_EDIT_MAX_DROPPED_REASONS = 10\n\nexport interface AssistEditProposal {\n id: typeof ASSIST_EDIT_ACTION_ID\n /** One line, in the model's words, of what the edit does. */\n summary: string\n ops: AssistEditOp[]\n diff: AssistEditDiff\n /** Why each change the model wrote and validation refused was left out. */\n dropped: string[]\n target: AssistEditTarget\n}\n\n/** The counts for a list of ops. */\nexport function summarizeAssistEditOps(ops: readonly AssistEditOp[]): AssistEditDiff {\n const diff: AssistEditDiff = {\n added: 0,\n removed: 0,\n propsChanged: 0,\n stylesChanged: 0,\n moved: 0,\n renamed: 0,\n seoFields: 0,\n componentProps: 0,\n componentsSaved: 0,\n interactionsAdded: 0,\n }\n for (const op of ops) {\n switch (op.op) {\n case 'insertSubtree':\n diff.added += Object.keys(op.nodes).length\n break\n case 'remove':\n diff.removed += 1\n break\n case 'updateProps':\n diff.propsChanged += 1\n break\n case 'updateSx':\n diff.stylesChanged += 1\n break\n case 'move':\n diff.moved += 1\n break\n case 'rename':\n diff.renamed += 1\n break\n case 'setSeo':\n diff.seoFields += Object.keys(op.fields).length\n break\n case 'saveAsComponent':\n diff.componentsSaved += 1\n diff.componentProps += op.props.length\n break\n case 'addInteraction':\n diff.interactionsAdded += 1\n break\n }\n }\n return diff\n}\n\nconst plural = (count: number, one: string, many: string): string =>\n `${count} ${count === 1 ? one : many}`\n\n/** The diff as the lines a person reads, zero counts omitted. */\nexport function describeAssistEditDiff(diff: AssistEditDiff): string[] {\n const lines: string[] = []\n if (diff.added) lines.push(`${plural(diff.added, 'element', 'elements')} added`)\n if (diff.removed) lines.push(`${plural(diff.removed, 'element', 'elements')} removed`)\n if (diff.propsChanged) {\n lines.push(`${plural(diff.propsChanged, 'element’s settings', 'elements’ settings')} changed`)\n }\n if (diff.stylesChanged) {\n lines.push(`${plural(diff.stylesChanged, 'element', 'elements')} restyled`)\n }\n if (diff.moved) lines.push(`${plural(diff.moved, 'element', 'elements')} moved`)\n if (diff.renamed) lines.push(`${plural(diff.renamed, 'layer', 'layers')} renamed`)\n if (diff.seoFields) {\n lines.push(`${plural(diff.seoFields, 'search field', 'search fields')} filled in`)\n }\n if (diff.interactionsAdded) {\n lines.push(`${plural(diff.interactionsAdded, 'interaction', 'interactions')} added`)\n }\n if (diff.componentsSaved) {\n lines.push(\n `saved as a reusable component with ${plural(diff.componentProps, 'property', 'properties')}`,\n )\n }\n return lines\n}\n\n/** The word each op kind is counted under in the activity row. */\nconst OP_COUNT_WORDS: Readonly<Record<AssistEditOpKind, string>> = {\n updateProps: 'set',\n updateSx: 'restyle',\n insertSubtree: 'insert',\n move: 'move',\n remove: 'remove',\n rename: 'rename',\n setSeo: 'seo',\n saveAsComponent: 'component',\n addInteraction: 'interaction',\n}\n\n/** The applied ops counted by kind, as the activity row names them (`{ set: 3, insert: 1 }`). */\nexport function assistEditOpCounts(ops: readonly AssistEditOp[]): Record<string, number> {\n const counts: Record<string, number> = {}\n for (const op of ops) {\n const word = OP_COUNT_WORDS[op.op]\n if (word) counts[word] = (counts[word] ?? 0) + 1\n }\n return counts\n}\n\n/** The words `assistEditOpCounts` counts under, for a door that reads them back. */\nexport const ASSIST_EDIT_OP_COUNT_WORDS: readonly string[] = Object.values(OP_COUNT_WORDS)\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * Whether a `done` event's `edit` field is a proposal this client can apply.\n * The server built it, so this is a shape check rather than a validation: it\n * keeps a malformed or foreign payload from reaching the canvas mutators.\n */\nexport function isAssistEditProposal(value: unknown): value is AssistEditProposal {\n if (!isRecord(value) || value['id'] !== ASSIST_EDIT_ACTION_ID) return false\n const target = value['target']\n if (!isRecord(target)) return false\n if (!ASSIST_EDIT_DOCUMENT_KINDS.includes(target['kind'] as AssistEditDocumentKind)) return false\n if (typeof target['documentId'] !== 'string' || !target['documentId']) return false\n const ops = value['ops']\n if (!Array.isArray(ops) || !ops.length) return false\n return ops.every(\n (op) => isRecord(op) && ASSIST_EDIT_OP_KINDS.includes(op['op'] as AssistEditOpKind),\n )\n}\n\n/* ------------------------------------------------------------------ *\n * What the client reports once the author applied a proposal\n * ------------------------------------------------------------------ */\n\n/** The body of `POST /api/assist/edit-applied`. */\nexport interface AssistEditAppliedReport {\n orgId: string\n hostId: string\n /** The exchange whose answer carried the proposal. */\n exchangeId: string\n documentKind: AssistEditDocumentKind\n documentId: string\n /** The version the edits landed on — a new one when the open one was live. */\n versionId: string\n opCounts: Record<string, number>\n}\n"],"names":["ASSIST_EDIT_OP_KINDS","ASSIST_EDIT_ACTION_ID","ASSIST_EDIT_TOOL_NAME","ASSIST_EDIT_DOCUMENT_KINDS","COLLECTION_KINDS","screens","components","layouts","BESIGNER_DOCUMENT_ROUTE","assistEditDocumentOf","route","match","exec","String","kind","documentId","versionId","ASSIST_EDIT_CONTEXT_MAX_NODES","ASSIST_EDIT_CONTEXT_MAX_PROPS","ASSIST_EDIT_SELECTED_TEXT_CHARS","ASSIST_EDIT_OUTLINE_TEXT_CHARS","ASSIST_EDIT_WHOLE_MAX_NODES","ASSIST_EDIT_INTERACTION_EVENTS","ASSIST_EDIT_INTERACTION_STEPS","ASSIST_EDIT_MAX_DROPPED_REASONS","summarizeAssistEditOps","ops","diff","added","removed","propsChanged","stylesChanged","moved","renamed","seoFields","componentProps","componentsSaved","interactionsAdded","op","Object","keys","nodes","length","fields","props","plural","count","one","many","describeAssistEditDiff","lines","push","OP_COUNT_WORDS","updateProps","updateSx","insertSubtree","move","remove","rename","setSeo","saveAsComponent","addInteraction","assistEditOpCounts","counts","word","ASSIST_EDIT_OP_COUNT_WORDS","values","isRecord","value","Array","isArray","isAssistEditProposal","target","includes","every"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAMD;;;;;;;;;;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M,CAACC,KAAK,GAAG,EAACD,eAAAA,MAAM,CAACC,KAAK,YAAZD,eAAgB,KAAK;IACjD;IACA,OAAOA;AACT;AAEA,kFAAkF,GAClF,OAAO,MAAME,6BAAgD1B,OAAO2B,MAAM,CAACd,gBAAe;AAE1F,MAAMe,WAAW,CAACC,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AAEhE;;;;CAIC,GACD,OAAO,SAASG,qBAAqBH,KAAc;IACjD,IAAI,CAACD,SAASC,UAAUA,KAAK,CAAC,KAAK,KAAKnE,uBAAuB,OAAO;IACtE,MAAMuE,SAASJ,KAAK,CAAC,SAAS;IAC9B,IAAI,CAACD,SAASK,SAAS,OAAO;IAC9B,IAAI,CAACrE,2BAA2BsE,QAAQ,CAACD,MAAM,CAAC,OAAO,GAA6B,OAAO;IAC3F,IAAI,OAAOA,MAAM,CAAC,aAAa,KAAK,YAAY,CAACA,MAAM,CAAC,aAAa,EAAE,OAAO;IAC9E,MAAM9C,MAAM0C,KAAK,CAAC,MAAM;IACxB,IAAI,CAACC,MAAMC,OAAO,CAAC5C,QAAQ,CAACA,IAAIgB,MAAM,EAAE,OAAO;IAC/C,OAAOhB,IAAIgD,KAAK,CACd,CAACpC,KAAO6B,SAAS7B,OAAOtC,qBAAqByE,QAAQ,CAACnC,EAAE,CAAC,KAAK;AAElE"}
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { type AiSurface } from './ai-palette';
17
+ import { type AiPaletteEntry, type AiSurface } from './ai-palette';
18
18
  import { type NodesMap } from '@aglyn/aglyn/types/nodes';
19
19
  import type { AiComponentPropTypes } from '../model/ai-site-inventory';
20
20
  /**
@@ -96,6 +96,21 @@ export interface AiNodeTreeContext {
96
96
  screenIds?: Iterable<string>;
97
97
  /** DAM media ids a `media` prop may reference. Absent: any well-formed reference. */
98
98
  assetIds?: Iterable<string>;
99
+ /**
100
+ * The media library scopes a `media:{scope}/{mediaId}` reference may name
101
+ * (AGL-4235): a site's own library and its workspace's, as the caller holds
102
+ * them. Held in the same check as `assetIds`, so a reference must pass both
103
+ * when both are given. Absent: any well-formed scope.
104
+ */
105
+ mediaScopes?: Iterable<string>;
106
+ /**
107
+ * Values are taken exactly as written (AGL-4235): a boolean must be a
108
+ * boolean, a number a number and text a string, where a model's answer
109
+ * would be coerced — `"true"` to `true`, `5` to `"5"`. A value that is not
110
+ * already the type is dropped and named in `repairs`, which a caller that
111
+ * refuses every repair reads as an error. Absent: coerced, as for a model.
112
+ */
113
+ exact?: boolean;
99
114
  /**
100
115
  * Reusable components an instance may place. Absent: no instance is
101
116
  * admitted, which is the palette's own rule for a tree nobody grounded.
@@ -156,6 +171,15 @@ export declare const HOSTILE_TEXT: RegExp;
156
171
  * a `url(`, a selector or a second declaration out.
157
172
  */
158
173
  export declare const SX_VALUE: RegExp;
174
+ /**
175
+ * One element's palette entry with the props every element carries (see
176
+ * {@link withNodeCapabilities}): what the validator holds an element's props
177
+ * to, for a reader that says which props an element takes. Null for an
178
+ * element the palette does not list.
179
+ */
180
+ export declare function aiPaletteEntryWithCapabilities(componentId: string): AiPaletteEntry | null;
181
+ /** The field an icon is picked with, which no caller but the site owner fills (see `sanitizeString`). */
182
+ export declare function aiPropIsIconPick(entry: AiPaletteEntry, name: string): boolean;
159
183
  /** An `https:` address that parses as one. */
160
184
  export declare function isHttpsUrl(value: string): boolean;
161
185
  /**
@@ -177,6 +177,31 @@ const typographyVariants = new Set(AI_SX_TOKENS.typographyVariants);
177
177
  function isRecord(value) {
178
178
  return typeof value === 'object' && value !== null && !Array.isArray(value);
179
179
  }
180
+ function mediaAdmissionOf(context) {
181
+ const ids = (context == null ? void 0 : context.assetIds) ? new Set(context.assetIds) : null;
182
+ const scopes = (context == null ? void 0 : context.mediaScopes) ? new Set(context.mediaScopes) : null;
183
+ return ids || scopes ? {
184
+ ids,
185
+ scopes
186
+ } : null;
187
+ }
188
+ /** Whether a parsed reference names media the caller admits; any, with nothing named. */ function mediaAdmitted(ref, media) {
189
+ if (!media) return true;
190
+ if (media.ids && !media.ids.has(ref.mediaId)) return false;
191
+ return !media.scopes || media.scopes.has(ref.scope);
192
+ }
193
+ /**
194
+ * One element's palette entry with the props every element carries (see
195
+ * {@link withNodeCapabilities}): what the validator holds an element's props
196
+ * to, for a reader that says which props an element takes. Null for an
197
+ * element the palette does not list.
198
+ */ export function aiPaletteEntryWithCapabilities(componentId) {
199
+ const entry = AI_PALETTE[componentId];
200
+ return entry ? withNodeCapabilities(entry) : null;
201
+ }
202
+ /** The field an icon is picked with, which no caller but the site owner fills (see `sanitizeString`). */ export function aiPropIsIconPick(entry, name) {
203
+ return entry.propFields[name] === ICON_PICKER_FIELD;
204
+ }
180
205
  /** An `https:` address that parses as one. */ export function isHttpsUrl(value) {
181
206
  if (!/^https:\/\//i.test(value)) return false;
182
207
  try {
@@ -286,7 +311,7 @@ function textLimitFor(entry, name, props) {
286
311
  * One string prop against its role. Returns the value to store, or
287
312
  * `undefined` with the reason pushed to `repairs`. A binding token the
288
313
  * caller admitted passes a `url` or `media` role whole.
289
- */ function sanitizeString(nodeId, entry, name, schema, raw, props, screenIds, assetIds, repairs, bindingTokens = null) {
314
+ */ function sanitizeString(nodeId, entry, name, schema, raw, props, screenIds, media, repairs, bindingTokens = null) {
290
315
  let value = raw.trim();
291
316
  if (HOSTILE_TEXT.test(value)) {
292
317
  repairs.push(`${nodeId}.${name} carried markup or script; dropped`);
@@ -332,7 +357,7 @@ function textLimitFor(entry, name, props) {
332
357
  if (bindingTokens == null ? void 0 : bindingTokens.has(value)) break;
333
358
  if (isHttpsUrl(value)) break;
334
359
  const ref = parseMediaRef(value);
335
- if (!ref || assetIds && !assetIds.has(ref.mediaId)) {
360
+ if (!ref || !mediaAdmitted(ref, media)) {
336
361
  repairs.push(`${nodeId}.${name} is neither a media reference this site holds nor an https: URL; dropped`);
337
362
  return undefined;
338
363
  }
@@ -404,7 +429,7 @@ function withNodeCapabilities(entry) {
404
429
  if (!text || parseMediaRef(text) || (bindingTokens == null ? void 0 : bindingTokens.has(text))) return null;
405
430
  return 'a player plays only audio from the owner’s own media library, never a recording from elsewhere';
406
431
  }
407
- function sanitizeProps(nodeId, paletteEntry, raw, screenIds, assetIds, repairs, bindingTokens = null) {
432
+ function sanitizeProps(nodeId, paletteEntry, raw, screenIds, media, repairs, bindingTokens = null, exact = false) {
408
433
  const entry = withNodeCapabilities(paletteEntry);
409
434
  const source = isRecord(raw) ? raw : {};
410
435
  const props = {};
@@ -446,7 +471,7 @@ function sanitizeProps(nodeId, paletteEntry, raw, screenIds, assetIds, repairs,
446
471
  switch(schema.type){
447
472
  case 'boolean':
448
473
  {
449
- const coerced = coerceBoolean(value);
474
+ const coerced = exact && typeof value !== 'boolean' ? undefined : coerceBoolean(value);
450
475
  if (coerced === undefined) {
451
476
  repairs.push(`${nodeId}.${name} is not a boolean; dropped`);
452
477
  continue;
@@ -457,7 +482,7 @@ function sanitizeProps(nodeId, paletteEntry, raw, screenIds, assetIds, repairs,
457
482
  case 'number':
458
483
  case 'integer':
459
484
  {
460
- const coerced = coerceNumber(schema, value);
485
+ const coerced = exact && typeof value !== 'number' ? undefined : coerceNumber(schema, value);
461
486
  if (coerced === undefined) {
462
487
  repairs.push(`${nodeId}.${name} is not a number in range; dropped`);
463
488
  continue;
@@ -467,12 +492,12 @@ function sanitizeProps(nodeId, paletteEntry, raw, screenIds, assetIds, repairs,
467
492
  }
468
493
  default:
469
494
  {
470
- const text = typeof value === 'string' ? value : typeof value === 'number' || typeof value === 'boolean' ? String(value) : undefined;
495
+ const text = typeof value === 'string' ? value : !exact && (typeof value === 'number' || typeof value === 'boolean') ? String(value) : undefined;
471
496
  if (text === undefined) {
472
497
  repairs.push(`${nodeId}.${name} is not text; dropped`);
473
498
  continue;
474
499
  }
475
- const cleaned = sanitizeString(nodeId, entry, name, schema, text, source, screenIds, assetIds, repairs, bindingTokens);
500
+ const cleaned = sanitizeString(nodeId, entry, name, schema, text, source, screenIds, media, repairs, bindingTokens);
476
501
  if (cleaned === undefined) continue;
477
502
  props[name] = cleaned;
478
503
  }
@@ -499,7 +524,7 @@ const FORM_COMPONENT_ID = 'form';
499
524
  * One value an instance fills in for a declared prop, held to what the
500
525
  * declaration's type can hold: a picture from the library, a link, a number,
501
526
  * a switch, or copy.
502
- */ function instancePropValue(nodeId, name, type, raw, assetIds, repairs) {
527
+ */ function instancePropValue(nodeId, name, type, raw, media, repairs) {
503
528
  if (type === 'number') {
504
529
  const parsed = typeof raw === 'number' ? raw : Number(raw);
505
530
  if (raw === '' || !Number.isFinite(parsed)) {
@@ -534,7 +559,7 @@ const FORM_COMPONENT_ID = 'form';
534
559
  if (type === 'image') {
535
560
  if (isHttpsUrl(value)) return value;
536
561
  const ref = parseMediaRef(value);
537
- if (!ref || assetIds && !assetIds.has(ref.mediaId)) {
562
+ if (!ref || !mediaAdmitted(ref, media)) {
538
563
  repairs.push(`${nodeId}.propValues.${name} is neither a media reference this site holds nor an https: URL; dropped`);
539
564
  return undefined;
540
565
  }
@@ -608,7 +633,7 @@ const FORM_COMPONENT_ID = 'form';
608
633
  values[name] = raw.trim();
609
634
  continue;
610
635
  }
611
- const value = instancePropValue(nodeId, name, (_ref = declared == null ? void 0 : declared[name]) != null ? _ref : 'text', raw, refs.assetIds, repairs);
636
+ const value = instancePropValue(nodeId, name, (_ref = declared == null ? void 0 : declared[name]) != null ? _ref : 'text', raw, refs.media, repairs);
612
637
  if (value !== undefined) values[name] = value;
613
638
  }
614
639
  if (Object.keys(values).length) kept[REUSABLE_INSTANCE_PROP_VALUES_KEY] = values;
@@ -712,7 +737,7 @@ export function validateAiNodeTree(input, surface, context) {
712
737
  propsSchema: _extends({}, entry.propsSchema, {
713
738
  required: []
714
739
  })
715
- }), patch.props, (context == null ? void 0 : context.screenIds) ? new Set(context.screenIds) : null, (context == null ? void 0 : context.assetIds) ? new Set(context.assetIds) : null, repairs);
740
+ }), patch.props, (context == null ? void 0 : context.screenIds) ? new Set(context.screenIds) : null, mediaAdmissionOf(context), repairs, null, (context == null ? void 0 : context.exact) === true);
716
741
  const sx = patch.sx === undefined ? undefined : sanitizeSx(componentId, patch.sx, repairs);
717
742
  return {
718
743
  ok: true,
@@ -855,7 +880,7 @@ function validate(input, surface, context) {
855
880
  componentProps: (_ref = context == null ? void 0 : context.componentProps) != null ? _ref : {},
856
881
  formIds: (context == null ? void 0 : context.formIds) ? new Set(context.formIds) : null,
857
882
  datasetIds: (context == null ? void 0 : context.datasetIds) ? new Set(context.datasetIds) : null,
858
- assetIds: (context == null ? void 0 : context.assetIds) ? new Set(context.assetIds) : null,
883
+ media: mediaAdmissionOf(context),
859
884
  definesComponent
860
885
  };
861
886
  // An instance is admitted only where the caller grounded it in the site's
@@ -882,7 +907,7 @@ function validate(input, surface, context) {
882
907
  };
883
908
  }
884
909
  const screenIds = (context == null ? void 0 : context.screenIds) ? new Set(context.screenIds) : null;
885
- const assetIds = refs.assetIds;
910
+ const media = refs.media;
886
911
  const repairs = [];
887
912
  const output = {};
888
913
  const rootIsWrapper = rootMatches('div', root.componentId) && definition.root === 'div';
@@ -1003,7 +1028,7 @@ function validate(input, surface, context) {
1003
1028
  propsSchema: _extends({}, entry.propsSchema, {
1004
1029
  required: entry.propsSchema.required.filter((name)=>boundProps[name] === undefined)
1005
1030
  })
1006
- }) : entry, reference.props, screenIds, assetIds, repairs, bindingTokens);
1031
+ }) : entry, reference.props, screenIds, media, repairs, bindingTokens, (context == null ? void 0 : context.exact) === true);
1007
1032
  if ('missing' in propsResult) {
1008
1033
  return {
1009
1034
  ok: false,