@aglyn/plugins-ai 1.0.0-beta.293 → 1.0.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 (64) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-job-links.d.ts +17 -3
  3. package/src/lib/components/ai-job-links.js +32 -5
  4. package/src/lib/components/ai-job-links.js.map +1 -1
  5. package/src/lib/components/ai-job-requests.d.ts +9 -0
  6. package/src/lib/components/ai-job-requests.js +34 -0
  7. package/src/lib/components/ai-job-requests.js.map +1 -1
  8. package/src/lib/components/ai-site-build-page.component.js +28 -2
  9. package/src/lib/components/ai-site-build-page.component.js.map +1 -1
  10. package/src/lib/components/assist-edit-canvas.d.ts +12 -6
  11. package/src/lib/components/assist-edit-canvas.js +86 -36
  12. package/src/lib/components/assist-edit-canvas.js.map +1 -1
  13. package/src/lib/components/assist-edit-card.component.js +9 -8
  14. package/src/lib/components/assist-edit-card.component.js.map +1 -1
  15. package/src/lib/components/assist-jobs-drawer.component.d.ts +7 -1
  16. package/src/lib/components/assist-jobs-drawer.component.js +20 -6
  17. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
  18. package/src/lib/components/assist-page-change-card.component.d.ts +44 -0
  19. package/src/lib/components/assist-page-change-card.component.js +166 -0
  20. package/src/lib/components/assist-page-change-card.component.js.map +1 -0
  21. package/src/lib/components/assist-panel.component.d.ts +105 -1
  22. package/src/lib/components/assist-panel.component.js +242 -36
  23. package/src/lib/components/assist-panel.component.js.map +1 -1
  24. package/src/lib/jobs/ai-job-edit-step.d.ts +82 -16
  25. package/src/lib/jobs/ai-job-edit-step.js +209 -62
  26. package/src/lib/jobs/ai-job-edit-step.js.map +1 -1
  27. package/src/lib/jobs/ai-job-navigation-step.js +4 -2
  28. package/src/lib/jobs/ai-job-navigation-step.js.map +1 -1
  29. package/src/lib/model/ai-edit-job.d.ts +33 -16
  30. package/src/lib/model/ai-edit-job.js +50 -34
  31. package/src/lib/model/ai-edit-job.js.map +1 -1
  32. package/src/lib/model/ai-job-activity.d.ts +6 -11
  33. package/src/lib/model/ai-job-activity.js +8 -15
  34. package/src/lib/model/ai-job-activity.js.map +1 -1
  35. package/src/lib/model/ai-job-notice.js +3 -1
  36. package/src/lib/model/ai-job-notice.js.map +1 -1
  37. package/src/lib/model/ai-jobs.types.d.ts +6 -0
  38. package/src/lib/model/ai-jobs.types.js.map +1 -1
  39. package/src/lib/model/ai-site-inventory.d.ts +6 -0
  40. package/src/lib/model/ai-site-inventory.js.map +1 -1
  41. package/src/lib/model/assist-edit.d.ts +19 -1
  42. package/src/lib/model/assist-edit.js +7 -0
  43. package/src/lib/model/assist-edit.js.map +1 -1
  44. package/src/lib/model/assist-page-change.d.ts +100 -0
  45. package/src/lib/model/assist-page-change.js +107 -0
  46. package/src/lib/model/assist-page-change.js.map +1 -0
  47. package/src/lib/runtime/ai-eval.js +3 -1
  48. package/src/lib/runtime/ai-eval.js.map +1 -1
  49. package/src/lib/runtime/ai-node-tree.d.ts +5 -0
  50. package/src/lib/runtime/ai-node-tree.js +18 -3
  51. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  52. package/src/lib/runtime/site-inventory.d.ts +8 -1
  53. package/src/lib/runtime/site-inventory.js +18 -0
  54. package/src/lib/runtime/site-inventory.js.map +1 -1
  55. package/src/lib/server/assist-build.js +2 -0
  56. package/src/lib/server/assist-build.js.map +1 -1
  57. package/src/lib/server/assist-chat.js +56 -3
  58. package/src/lib/server/assist-chat.js.map +1 -1
  59. package/src/lib/server/assist-edit.d.ts +61 -4
  60. package/src/lib/server/assist-edit.js +248 -38
  61. package/src/lib/server/assist-edit.js.map +1 -1
  62. package/src/lib/server/assist-page-change.d.ts +62 -0
  63. package/src/lib/server/assist-page-change.js +140 -0
  64. package/src/lib/server/assist-page-change.js.map +1 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/assist-edit-canvas.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 {\n screenSeoStageKey,\n type ScreenSeoTextField,\n} from '@aglyn/aglyn/app-utils/screen-seo-fields'\nimport {\n NODE_HIDE_IF_PROP,\n replaceSubtreeWithInstance,\n reusableComponentDefinitionFrom,\n} from '@aglyn/aglyn/app-utils/compose-reusable-components'\nimport { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport {\n NODE_MAX_INTERACTIONS,\n upsertNodeInteraction,\n type NodeInteraction,\n} from '@aglyn/aglyn/app-utils/node-interactions'\nimport type {\n ReusableComponentProp,\n ReusableComponentPropValue,\n} from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport {\n stageEditorSessionFields,\n type EditorSession,\n} from '@aglyn/aglyn/plugin-manager/editor-sessions'\nimport {\n ASSIST_EDIT_CONTEXT_MAX_NODES,\n ASSIST_EDIT_CONTEXT_MAX_PROPS,\n ASSIST_EDIT_OUTLINE_TEXT_CHARS,\n ASSIST_EDIT_SELECTED_TEXT_CHARS,\n assistEditOpCounts,\n type AssistEditCanvasContext,\n type AssistEditCanvasNode,\n type AssistEditInsertOp,\n type AssistEditInteractionSummary,\n type AssistEditOp,\n type AssistEditProposal,\n type AssistEditComponentProp,\n type AssistEditSaveAsComponentOp,\n} from '../model/assist-edit'\n\n/**\n * The edit rung's client half (AGL-2906): what the panel tells the server\n * about the open canvas, and how a confirmed proposal lands on it.\n *\n * Applying goes through the canvas's own guarded mutators — the same ones\n * the besigner's panels and the marketing appliers use — inside ONE\n * `batch`, so the whole proposal is one undo step and a guard that refuses\n * part-way leaves nothing behind. Every change is an unsaved edit on the\n * version the editor has open; saving it stays the author's act, with the\n * editor's own control. A version the live site serves is never edited:\n * the check refuses it, and the card offers the editor's own new-version\n * flow instead.\n */\n\n/** A node as the canvas holds it — the fields this module reads. */\nexport interface AssistEditCanvasNodeLike {\n $id?: string\n componentId?: string\n parentId?: string | null\n nodes?: string[]\n name?: string\n props?: unknown\n sx?: unknown\n /** The element's own interactions (AGL-3603), as the canvas holds them. */\n interactions?: unknown\n}\n\n/**\n * The slice of the besigner canvas the edit rung reads and drives. Every\n * member is one `CanvasManager` already has, so the panel hands over the\n * canvas itself and a spec hands over a real one.\n */\nexport interface AssistEditCanvas {\n getNode(id: string): AssistEditCanvasNodeLike | undefined\n batch<T>(mutate: () => T): T\n updateNodeProps(node: any, props: any): void\n updateNodeFields(node: any, patch: any): void\n reparentNode(node: any, parent: any, index?: number): unknown\n deleteNode(node: any): unknown\n addNodeFromNested(nested: any, parent: any, index?: number): unknown\n nodeAcceptsChildren(node: any): boolean\n /** The whole document, which a component save reads its definition out of. */\n toJSON(): { nodes: Record<string, unknown> }\n /** The document after a save: the promoted subtree swapped for an instance. */\n applyNodes(nodes: any): unknown\n}\n\nconst UNDESCRIBED_PROP = /^(html|sx|style|className|dangerouslySetInnerHTML|on[A-Z].*)$/\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * An observable's own keys as a plain object. A canvas node's `props` and\n * `sx` are observable proxies, and a spread of one is how a merge silently\n * copies nothing.\n */\nfunction plain(value: unknown): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n if (!value || typeof value !== 'object') return out\n for (const key in value as Record<string, unknown>) {\n out[key] = (value as Record<string, unknown>)[key]\n }\n return out\n}\n\nfunction describeProps(\n raw: unknown,\n textChars: number,\n): Record<string, string | number | boolean> | undefined {\n const props: Record<string, string | number | boolean> = {}\n let kept = 0\n for (const [name, value] of Object.entries(plain(raw))) {\n if (kept >= ASSIST_EDIT_CONTEXT_MAX_PROPS) break\n if (UNDESCRIBED_PROP.test(name)) continue\n if (typeof value === 'string') {\n if (!value.trim()) continue\n props[name] = value.slice(0, textChars)\n } else if (typeof value === 'number' && Number.isFinite(value)) {\n props[name] = value\n } else if (typeof value === 'boolean') {\n props[name] = value\n } else {\n continue\n }\n kept += 1\n }\n return kept ? props : undefined\n}\n\nfunction describeSx(raw: unknown): Record<string, unknown> | undefined {\n const sx: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(plain(raw))) {\n if (typeof value === 'string' || typeof value === 'number') sx[key] = value\n else if (isRecord(value)) sx[key] = plain(value)\n }\n return Object.keys(sx).length ? sx : undefined\n}\n\n/**\n * The selection's ancestors below the document root, top-level section first\n * and the selection last; null when its parents do not lead to the root,\n * which is not a chain the server can check.\n */\nfunction chainToRoot(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n selected: AssistEditCanvasNodeLike,\n): string[] | null {\n const chain: string[] = []\n const walked = new Set<string>()\n let current: AssistEditCanvasNodeLike | undefined = selected\n while (current?.$id && current.$id !== CANVAS_ROOT_ELEMENT_ID && !walked.has(current.$id)) {\n walked.add(current.$id)\n chain.unshift(current.$id)\n current = current.parentId ? canvas.getNode(current.parentId) : undefined\n }\n return current?.$id === CANVAS_ROOT_ELEMENT_ID ? chain : null\n}\n\n/** Elements one shape is taken over at most; a larger subtree is never called alike. */\nconst SHAPE_LIMIT = 200\n\n/**\n * How an element is built: its component and, in order, its children's —\n * what two cards of one row have in common whatever their text. Null past\n * `SHAPE_LIMIT` elements, or for a subtree that loops back on itself.\n */\nfunction shapeOf(canvas: Pick<AssistEditCanvas, 'getNode'>, rootId: string): string | null {\n let budget = SHAPE_LIMIT\n const walked = new Set<string>()\n const walk = (id: string): string | null => {\n const node = canvas.getNode(id)\n if (!node || walked.has(id) || --budget < 0) return null\n walked.add(id)\n const parts: string[] = []\n for (const child of node.nodes ?? []) {\n const part = walk(child)\n if (part === null) return null\n parts.push(part)\n }\n return `${String(node.componentId ?? '')}(${parts.join(',')})`\n }\n return walk(rootId)\n}\n\n/** Elements reachable from the document root through child lists, the root included. */\nfunction countElements(canvas: Pick<AssistEditCanvas, 'getNode'>): number {\n let count = 0\n const reached = new Set<string>([CANVAS_ROOT_ELEMENT_ID])\n const pending = [CANVAS_ROOT_ELEMENT_ID]\n while (pending.length) {\n const node = canvas.getNode(pending.pop() as string)\n if (!node) continue\n count += 1\n for (const child of node.nodes ?? []) {\n if (reached.has(child)) continue\n reached.add(child)\n pending.push(child)\n }\n }\n return count\n}\n\n/**\n * The canvas outline a question carries on the edit rung, in two tiers, until\n * the cap.\n *\n * Described in full, settings and all: the document root, the selection's\n * ancestors and the selection, the document's top-level sections, everything\n * inside the selection — what an edit to it changes — and its siblings.\n *\n * Described briefly, by place alone (`brief`): what surrounds that, so the\n * model knows it exists and asks for it rather than calling it missing —\n *\n * 1. what the selection's siblings hold, level by level (the icons beside a\n * selected link, in the card they share);\n * 2. the siblings of each ancestor below the top-level section, nearest\n * first (the other cards of the row, then what sits beside the row).\n *\n * An element built the same way as the selection, or as the ancestor it sits\n * beside, is marked `like` it and its contents are left out: one card\n * described, and every other card of the row says it holds the same.\n *\n * With nothing selected, it is the root, the top-level sections and one level\n * inside each: enough for a change to the page as a whole, and the prompt asks\n * for a selection before anything more specific.\n *\n * An element is only ever described after its parent, so every ancestor chain\n * the server checks is whole. `total` counts the document, and each element's\n * `childCount` stays its real one, so the server can tell the model what the\n * outline leaves out. The server holds this to its own limits before it quotes\n * a byte of it; null when the canvas has no document root loaded.\n */\nexport function describeAssistEditCanvas(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n selectedId: string | null,\n): AssistEditCanvasContext | null {\n const root = canvas.getNode(CANVAS_ROOT_ELEMENT_ID)\n if (!root) return null\n const order: string[] = []\n const seen = new Set<string>()\n const brief = new Set<string>()\n const like = new Map<string, string>()\n const full = (): boolean => order.length >= ASSIST_EDIT_CONTEXT_MAX_NODES\n const add = (id: string | undefined | null, briefly = false): void => {\n if (!id || seen.has(id) || full()) return\n if (!canvas.getNode(id)) return\n seen.add(id)\n order.push(id)\n if (briefly) brief.add(id)\n }\n const childrenOf = (id: string): string[] => canvas.getNode(id)?.nodes ?? []\n const shapes = new Map<string, string | null>()\n const shape = (id: string): string | null => {\n if (!shapes.has(id)) shapes.set(id, shapeOf(canvas, id))\n return shapes.get(id) ?? null\n }\n // Alike only when there are contents to leave out.\n const alike = (id: string, model: string): boolean =>\n childrenOf(id).length > 0 && shape(id) !== null && shape(id) === shape(model)\n\n add(CANVAS_ROOT_ELEMENT_ID)\n const selected =\n selectedId && selectedId !== CANVAS_ROOT_ELEMENT_ID ? canvas.getNode(selectedId) : undefined\n const chain = selected?.$id ? chainToRoot(canvas, selected) : null\n chain?.forEach((id) => add(id))\n if (selected?.$id && chain && seen.has(selected.$id)) {\n for (const id of root.nodes ?? []) add(id)\n const inside = new Set<string>([selected.$id])\n const queue = [...childrenOf(selected.$id)]\n while (queue.length && !full()) {\n const id = queue.shift() as string\n if (inside.has(id)) continue\n inside.add(id)\n add(id)\n queue.push(...childrenOf(id))\n }\n const siblings = selected.parentId\n ? childrenOf(selected.parentId).filter((id) => id !== selected.$id)\n : []\n const held: string[] = []\n for (const id of siblings) {\n add(id)\n // A sibling the cap left out takes its contents with it.\n if (!seen.has(id)) continue\n if (alike(id, selected.$id)) like.set(id, selected.$id)\n else held.push(...childrenOf(id))\n }\n const reached = new Set<string>([...inside, ...siblings, ...held])\n for (let level = held; level.length && !full(); ) {\n const deeper: string[] = []\n for (const id of level) {\n add(id, true)\n for (const child of childrenOf(id)) {\n if (reached.has(child)) continue\n reached.add(child)\n deeper.push(child)\n }\n }\n level = deeper\n }\n // Parent first; the top-level section's own siblings are the sections above.\n for (const ancestor of chain.slice(1, -1).reverse()) {\n const parentId = canvas.getNode(ancestor)?.parentId\n for (const id of parentId ? childrenOf(parentId) : []) {\n if (id === ancestor || seen.has(id)) continue\n add(id, true)\n if (seen.has(id) && alike(id, ancestor)) like.set(id, ancestor)\n }\n }\n } else {\n for (const id of root.nodes ?? []) add(id)\n for (const section of root.nodes ?? []) {\n for (const id of childrenOf(section)) add(id)\n }\n }\n\n const nodes: AssistEditCanvasNode[] = order.map((id) => {\n const node = canvas.getNode(id) as AssistEditCanvasNodeLike\n const isRoot = id === CANVAS_ROOT_ELEMENT_ID\n const parentId = isRoot ? null : (node.parentId ?? null)\n const parent = parentId ? canvas.getNode(parentId) : undefined\n const isSelected = id === selected?.$id\n const isBrief = brief.has(id)\n const props = isBrief\n ? undefined\n : describeProps(\n node.props,\n isSelected ? ASSIST_EDIT_SELECTED_TEXT_CHARS : ASSIST_EDIT_OUTLINE_TEXT_CHARS,\n )\n const sx = isSelected ? describeSx(node.sx) : undefined\n const model = like.get(id)\n return {\n id,\n componentId: String(node.componentId ?? ''),\n parentId,\n index: Math.max(0, parent?.nodes?.indexOf(id) ?? 0),\n childCount: node.nodes?.length ?? 0,\n ...(node.name ? { name: String(node.name) } : {}),\n ...(props ? { props } : {}),\n ...(sx ? { sx } : {}),\n ...(isBrief ? { brief: true } : {}),\n ...(model ? { like: model } : {}),\n ...(isSelected ? summarizeInteractions(node.interactions) : {}),\n }\n })\n return {\n selectedId: selected?.$id && seen.has(selected.$id) ? selected.$id : null,\n total: countElements(canvas),\n nodes,\n }\n}\n\n/**\n * The selected element's interactions as the outline carries them\n * (AGL-3603): name, event and the kinds of its steps — never a selector.\n */\nfunction summarizeInteractions(raw: unknown): { interactions?: AssistEditInteractionSummary[] } {\n if (!Array.isArray(raw) || !raw.length) return {}\n const interactions = raw\n .filter(isRecord)\n .slice(0, NODE_MAX_INTERACTIONS)\n .map((entry) => ({\n name: String(entry['name'] ?? ''),\n event: String(isRecord(entry['trigger']) ? (entry['trigger']['event'] ?? '') : ''),\n steps: (Array.isArray(entry['steps']) ? entry['steps'] : [])\n .filter(isRecord)\n .map((step) => String(step['type'] ?? '')),\n enabled: entry['enabled'] !== false,\n }))\n .filter((entry) => entry.event)\n return interactions.length ? { interactions } : {}\n}\n\n/** Why a proposal cannot land on the open editor as it stands. */\nexport type AssistEditRefusal =\n /** No editor is open. */\n | 'no-editor'\n /** The editor open is not the document the proposal was made for. */\n | 'other-document'\n /** The open version is the one the live site serves. */\n | 'live-version'\n /** An element the proposal names has gone or changed since. */\n | 'stale'\n /** The canvas's own guards refused part of the change. */\n | 'refused'\n\nexport type AssistEditCheck =\n | { ok: true }\n | { ok: false; reason: AssistEditRefusal; message: string }\n\nexport type AssistEditApplyResult =\n | {\n ok: true\n /** Applied ops, counted by kind for the activity row. */\n opCounts: Record<string, number>\n /** Editor fields staged, as the editor keys them. */\n staged: string[]\n }\n | { ok: false; reason: AssistEditRefusal; message: string }\n\n/** Ids of the subtree at `rootId`, the root included, through child lists only. */\nfunction subtreeIds(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n rootId: string,\n): Set<string> {\n const found = new Set<string>([rootId])\n const queue = [...(canvas.getNode(rootId)?.nodes ?? [])]\n while (queue.length) {\n const id = queue.shift() as string\n if (found.has(id) || !canvas.getNode(id)) continue\n found.add(id)\n queue.push(...(canvas.getNode(id)?.nodes ?? []))\n }\n return found\n}\n\nconst STALE: AssistEditCheck = {\n ok: false,\n reason: 'stale',\n message: 'The canvas has changed since this was proposed, so nothing was applied. Ask again.',\n}\n\n/**\n * Whether the proposal can land on the open editor as it stands — checked in\n * full before anything is touched, so a refusal never leaves half an edit.\n */\nexport function checkAssistEdit(\n canvas: Pick<AssistEditCanvas, 'getNode' | 'nodeAcceptsChildren'>,\n proposal: AssistEditProposal,\n session: EditorSession | undefined,\n): AssistEditCheck {\n if (!session) {\n return {\n ok: false,\n reason: 'no-editor',\n message: 'Open the editor this change was proposed for to apply it.',\n }\n }\n if (\n session.documentKind !== proposal.target.kind ||\n session.documentId !== proposal.target.documentId\n ) {\n return {\n ok: false,\n reason: 'other-document',\n message: 'This change was proposed for a different document than the one open.',\n }\n }\n if (session.isLiveVersion()) {\n return {\n ok: false,\n reason: 'live-version',\n message:\n 'This is the version your live site shows. Make a new version first, then apply the change there.',\n }\n }\n for (const op of proposal.ops) {\n switch (op.op) {\n case 'setSeo': {\n for (const field of Object.keys(op.fields) as ScreenSeoTextField[]) {\n if (typeof session.fields?.[screenSeoStageKey(field)] !== 'function') {\n return {\n ok: false,\n reason: 'other-document',\n message: 'This editor has no search fields to fill in.',\n }\n }\n }\n break\n }\n case 'insertSubtree': {\n const parent = canvas.getNode(op.parentId)\n if (!parent || parent.componentId !== op.parentComponentId) return STALE\n if (!canvas.nodeAcceptsChildren(parent)) return STALE\n break\n }\n case 'move': {\n const node = canvas.getNode(op.nodeId)\n const parent = canvas.getNode(op.parentId)\n if (!node || node.componentId !== op.componentId) return STALE\n if (!parent || parent.componentId !== op.parentComponentId) return STALE\n break\n }\n case 'saveAsComponent': {\n const node = canvas.getNode(op.nodeId)\n if (!node || node.componentId !== op.componentId) return STALE\n // The document itself is not a section of itself: promoting the root\n // would leave a document holding one instance of its own contents.\n if (op.nodeId === CANVAS_ROOT_ELEMENT_ID) return STALE\n const inside = subtreeIds(canvas, op.nodeId)\n for (const binding of op.bindings) {\n const bound = canvas.getNode(binding.nodeId)\n if (!bound || bound.componentId !== binding.componentId) return STALE\n // A closed world: a token outside the promoted subtree would bind a\n // property of the new component to an element it does not contain.\n if (!inside.has(binding.nodeId)) return STALE\n }\n break\n }\n case 'addInteraction': {\n const node = canvas.getNode(op.nodeId)\n if (!node || node.componentId !== op.componentId) return STALE\n if (Array.isArray(node.interactions) && node.interactions.length >= NODE_MAX_INTERACTIONS) {\n return {\n ok: false,\n reason: 'refused',\n message: `That element already does ${NODE_MAX_INTERACTIONS} things, the most one can. Remove one in Interactions first.`,\n }\n }\n // Every element a step acts on is still there, as it was.\n for (const target of op.targets) {\n const live = canvas.getNode(target.nodeId)\n if (!live || live.componentId !== target.componentId) return STALE\n }\n break\n }\n default: {\n const node = canvas.getNode(op.nodeId)\n if (!node || node.componentId !== op.componentId) return STALE\n }\n }\n }\n return { ok: true }\n}\n\n/**\n * Styles merged one key at a time. A responsive patch over a plain value\n * keeps that value as the base breakpoint, so \"more padding on wide screens\"\n * does not quietly remove the padding everywhere else.\n */\nfunction mergeSx(\n current: Record<string, unknown>,\n patch: Record<string, unknown>,\n): Record<string, unknown> {\n const out = { ...current }\n for (const [key, value] of Object.entries(patch)) {\n const existing = out[key]\n if (isRecord(value) && isRecord(existing)) {\n out[key] = { ...plain(existing), ...value }\n } else if (isRecord(value) && (typeof existing === 'string' || typeof existing === 'number')) {\n out[key] = { xs: existing, ...value }\n } else {\n out[key] = value\n }\n }\n return out\n}\n\n/** A validated flat subtree as the nested shape `addNodeFromNested` takes. */\nfunction nestSubtree(op: AssistEditInsertOp): Record<string, unknown> {\n const visited = new Set<string>()\n const build = (id: string): Record<string, unknown> => {\n visited.add(id)\n const node = op.nodes[id]\n return {\n componentId: node.componentId,\n ...(node.pluginId ? { pluginId: node.pluginId } : {}),\n props: { ...node.props },\n ...(node.sx ? { sx: { ...node.sx } } : {}),\n ...(node.hidden ? { hidden: true } : {}),\n nodes: node.nodes\n .filter((child) => op.nodes[child] && !visited.has(child))\n .map((child) => build(child)),\n }\n }\n return build(op.rootId)\n}\n\nfunction live(canvas: AssistEditCanvas, id: string): AssistEditCanvasNodeLike {\n const node = canvas.getNode(id)\n if (!node) throw new Error(`element ${id} is no longer on the canvas`)\n return node\n}\n\nfunction applyOne(canvas: AssistEditCanvas, op: AssistEditOp): void {\n switch (op.op) {\n case 'updateProps': {\n const node = live(canvas, op.nodeId)\n // Spread the props the element has: `updateNodeProps` REPLACES the bag,\n // and a patch of one setting would otherwise strip every other one.\n const next: Record<string, unknown> = { ...plain(node.props), ...op.props }\n // Rich text renders `html` over `children`; proposed text replaces it.\n if ('children' in op.props) delete next['html']\n canvas.updateNodeProps(node, next)\n return\n }\n case 'updateSx': {\n const node = live(canvas, op.nodeId)\n canvas.updateNodeFields(node, { sx: mergeSx(plain(node.sx), op.sx) })\n return\n }\n case 'move':\n canvas.reparentNode(live(canvas, op.nodeId), live(canvas, op.parentId), op.index ?? NaN)\n return\n case 'remove':\n canvas.deleteNode(live(canvas, op.nodeId))\n return\n case 'rename':\n canvas.updateNodeFields(live(canvas, op.nodeId), { name: op.name })\n return\n case 'addInteraction': {\n // Added beside what the element does already, never in place of it:\n // an id the element already uses is re-minted, so nothing is replaced.\n const node = live(canvas, op.nodeId)\n const current = (Array.isArray(node.interactions) ? node.interactions : []) as NodeInteraction[]\n let id = op.interaction.id\n while (current.some((entry) => entry.id === id)) id = `${op.interaction.id}${current.length}x`\n canvas.updateNodeFields(node, {\n interactions: upsertNodeInteraction(current, { ...op.interaction, id }),\n })\n return\n }\n case 'insertSubtree':\n canvas.addNodeFromNested(nestSubtree(op), live(canvas, op.parentId), op.index ?? NaN)\n return\n case 'setSeo':\n case 'saveAsComponent':\n // Both are applied outside the canvas batch: search fields are staged\n // into the editor's own form, and a component save mints a document\n // first and then swaps the subtree for an instance of it.\n return\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Save the selection as a reusable component (AGL-2908)\n * ------------------------------------------------------------------ */\n\n/** What the apply needs from the console to create the component. */\nexport interface AssistEditComponentWriter {\n /**\n * Creates the component through `POST /api/hosts/resources`, where the\n * plan's entitlement and the route's field allow-list are enforced, and\n * answers its id. The plugin never writes Firestore from the browser.\n */\n createComponent(input: {\n name: string\n rootId: string\n nodes: Record<string, unknown>\n props: ReusableComponentProp[]\n }): Promise<string>\n}\n\n/**\n * The value a bound field holds on the live canvas right now, which becomes\n * the property's default.\n *\n * `hideIf` is the exception: the part is on the page, so the property that\n * hides it starts at no. Every other field answers with what the author can\n * see, which is what makes the instance render exactly what was there.\n */\nfunction currentValue(\n node: AssistEditCanvasNodeLike,\n field: string,\n): ReusableComponentPropValue | undefined {\n if (field === NODE_HIDE_IF_PROP) return false\n const value = plain(node.props)[field]\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value\n }\n return undefined\n}\n\n/**\n * Whether a default the canvas gave is one the property's own control\n * offers. A Choice whose current value is not among its answers is a\n * selection that has changed since the proposal was made, and applying it\n * would declare a property no page could ever set back.\n */\nfunction defaultFitsProp(prop: AssistEditComponentProp, value: unknown): boolean {\n if (!prop.options?.length) return true\n return prop.options.some((option) => option.value === value)\n}\n\n/**\n * The definition the new component holds: the promoted subtree, with each\n * bound field replaced by its property's token.\n *\n * The defaults are read off the SAME fields a moment before they are\n * replaced, so the instance that takes the subtree's place renders what the\n * author was looking at. Returns null when a default no longer fits its\n * property, which is the stale case.\n */\nfunction componentDefinition(\n canvas: AssistEditCanvas,\n op: AssistEditSaveAsComponentOp,\n): { nodes: Record<string, unknown>; props: ReusableComponentProp[] } | null {\n const nodes = reusableComponentDefinitionFrom(\n canvas.toJSON().nodes as never,\n op.nodeId,\n ) as unknown as Record<string, Record<string, unknown>>\n const defaults = new Map<string, ReusableComponentPropValue | undefined>()\n for (const binding of op.bindings) {\n const live = canvas.getNode(binding.nodeId)\n const stored = nodes[binding.nodeId]\n if (!live || !stored) return null\n if (!defaults.has(binding.prop)) defaults.set(binding.prop, currentValue(live, binding.field))\n stored['props'] = { ...plain(stored['props']), [binding.field]: `{{prop.${binding.prop}}}` }\n }\n const props: ReusableComponentProp[] = []\n for (const declared of op.props) {\n const value = defaults.get(declared.name)\n if (!defaultFitsProp(declared, value)) return null\n props.push({ ...declared, ...(value === undefined ? {} : { defaultValue: value }) })\n }\n return { nodes, props }\n}\n\n/**\n * Lands a confirmed proposal on the open editor: the canvas ops as ONE batch\n * — one undo step, all or nothing — then any search fields staged into the\n * editor's own form. Nothing is saved.\n */\nexport function applyAssistEdit(\n canvas: AssistEditCanvas,\n proposal: AssistEditProposal,\n session: EditorSession | undefined,\n): AssistEditApplyResult {\n const check = checkAssistEdit(canvas, proposal, session)\n if (check.ok === false) return check\n const open = session as EditorSession\n const canvasOps = proposal.ops.filter((op) => op.op !== 'setSeo' && op.op !== 'saveAsComponent')\n if (canvasOps.length) {\n try {\n canvas.batch(() => {\n for (const op of canvasOps) applyOne(canvas, op)\n })\n } catch (error) {\n console.error('assist edit refused by the canvas', error)\n return {\n ok: false,\n reason: 'refused',\n message: 'The editor refused part of this change, so none of it was applied.',\n }\n }\n }\n const staged: string[] = []\n for (const op of proposal.ops) {\n if (op.op !== 'setSeo') continue\n const values: Record<string, string> = {}\n for (const [field, value] of Object.entries(op.fields)) {\n values[screenSeoStageKey(field as ScreenSeoTextField)] = String(value)\n }\n staged.push(...stageEditorSessionFields(open, values).staged)\n }\n return { ok: true, opCounts: assistEditOpCounts(proposal.ops), staged }\n}\n\n/**\n * Lands a proposal that saves the selection as a reusable component\n * (AGL-2908) — AGL-2866's recipe, in place, with no clipboard.\n *\n * The order is the manual action's order, and it matters:\n *\n * 1. the definition is read off the live subtree, each bound field replaced\n * by its token and its current value kept as that property's default;\n * 2. the component is created through the host resources route, where the\n * server enforces the plan's entitlement and its own allow-list — so a\n * refusal happens before the open document is touched at all;\n * 3. the subtree is swapped for an instance of what was just created, inside\n * ONE `batch` with the rest of the proposal's canvas ops: one undo step.\n *\n * The only document created is the component, exactly as Save as reusable\n * component creates one. The page change is an unsaved edit on the version\n * the editor has open, which the check has already refused to be a live one.\n * Nothing is published and nothing is saved.\n */\nexport async function applyAssistEditSavingComponent(\n canvas: AssistEditCanvas,\n proposal: AssistEditProposal,\n session: EditorSession | undefined,\n writer: AssistEditComponentWriter,\n): Promise<AssistEditApplyResult> {\n const save = proposal.ops.find(\n (op): op is AssistEditSaveAsComponentOp => op.op === 'saveAsComponent',\n )\n if (!save) return applyAssistEdit(canvas, proposal, session)\n const check = checkAssistEdit(canvas, proposal, session)\n if (check.ok === false) return check\n\n const definition = componentDefinition(canvas, save)\n if (!definition) return STALE as AssistEditApplyResult\n\n let componentId: string\n try {\n componentId = await writer.createComponent({\n name: save.name,\n rootId: save.nodeId,\n nodes: definition.nodes,\n props: definition.props,\n })\n } catch (error) {\n console.error('assist edit could not create the component', error)\n return {\n ok: false,\n reason: 'refused',\n message:\n error instanceof Error && error.message\n ? error.message\n : 'The component could not be saved, so nothing on this page was changed.',\n }\n }\n\n const canvasOps = proposal.ops.filter((op) => op.op !== 'setSeo' && op.op !== 'saveAsComponent')\n try {\n canvas.batch(() => {\n for (const op of canvasOps) applyOne(canvas, op)\n canvas.applyNodes(\n replaceSubtreeWithInstance(\n canvas.toJSON().nodes as never,\n save.nodeId,\n componentId,\n save.name,\n ),\n )\n })\n } catch (error) {\n console.error('assist edit refused by the canvas', error)\n return {\n ok: false,\n reason: 'refused',\n message:\n 'The component was saved, but the editor refused to swap this element for it. ' +\n 'Insert it from Your components instead.',\n }\n }\n return { ok: true, opCounts: assistEditOpCounts(proposal.ops), staged: [] }\n}\n"],"names":["screenSeoStageKey","NODE_HIDE_IF_PROP","replaceSubtreeWithInstance","reusableComponentDefinitionFrom","CANVAS_ROOT_ELEMENT_ID","NODE_MAX_INTERACTIONS","upsertNodeInteraction","stageEditorSessionFields","ASSIST_EDIT_CONTEXT_MAX_NODES","ASSIST_EDIT_CONTEXT_MAX_PROPS","ASSIST_EDIT_OUTLINE_TEXT_CHARS","ASSIST_EDIT_SELECTED_TEXT_CHARS","assistEditOpCounts","UNDESCRIBED_PROP","isRecord","value","Array","isArray","plain","out","key","describeProps","raw","textChars","props","kept","name","Object","entries","test","trim","slice","Number","isFinite","undefined","describeSx","sx","keys","length","chainToRoot","canvas","selected","chain","walked","Set","current","$id","has","add","unshift","parentId","getNode","SHAPE_LIMIT","shapeOf","rootId","budget","walk","id","node","parts","child","nodes","part","push","String","componentId","join","countElements","count","reached","pending","pop","describeAssistEditCanvas","selectedId","root","order","seen","brief","like","Map","full","briefly","childrenOf","shapes","shape","set","get","alike","model","forEach","inside","queue","shift","siblings","filter","held","level","deeper","ancestor","reverse","section","map","parent","isRoot","isSelected","isBrief","index","Math","max","indexOf","childCount","summarizeInteractions","interactions","total","entry","event","steps","step","enabled","subtreeIds","found","STALE","ok","reason","message","checkAssistEdit","proposal","session","documentKind","target","kind","documentId","isLiveVersion","op","ops","field","fields","parentComponentId","nodeAcceptsChildren","nodeId","binding","bindings","bound","targets","live","mergeSx","patch","existing","xs","nestSubtree","visited","build","pluginId","hidden","Error","applyOne","next","updateNodeProps","updateNodeFields","reparentNode","NaN","deleteNode","interaction","some","addNodeFromNested","currentValue","defaultFitsProp","prop","options","option","componentDefinition","toJSON","defaults","stored","declared","defaultValue","applyAssistEdit","check","open","canvasOps","batch","error","console","staged","values","opCounts","applyAssistEditSavingComponent","writer","save","find","definition","createComponent","applyNodes"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,iBAAiB,QAEZ,2CAA0C;AACjD,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,+BAA+B,QAC1B,qDAAoD;AAC3D,SAASC,sBAAsB,QAAQ,2CAA0C;AACjF,SACEC,qBAAqB,EACrBC,qBAAqB,QAEhB,2CAA0C;AAKjD,SACEC,wBAAwB,QAEnB,8CAA6C;AACpD,SACEC,6BAA6B,EAC7BC,6BAA6B,EAC7BC,8BAA8B,EAC9BC,+BAA+B,EAC/BC,kBAAkB,QASb,0BAAsB;AAiD7B,MAAMC,mBAAmB;AAEzB,MAAMC,WAAW,CAACC,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AAEhE;;;;CAIC,GACD,SAASG,MAAMH,KAAc;IAC3B,MAAMI,MAA+B,CAAC;IACtC,IAAI,CAACJ,SAAS,OAAOA,UAAU,UAAU,OAAOI;IAChD,IAAK,MAAMC,OAAOL,MAAkC;QAClDI,GAAG,CAACC,IAAI,GAAG,AAACL,KAAiC,CAACK,IAAI;IACpD;IACA,OAAOD;AACT;AAEA,SAASE,cACPC,GAAY,EACZC,SAAiB;IAEjB,MAAMC,QAAmD,CAAC;IAC1D,IAAIC,OAAO;IACX,KAAK,MAAM,CAACC,MAAMX,MAAM,IAAIY,OAAOC,OAAO,CAACV,MAAMI,MAAO;QACtD,IAAIG,QAAQhB,+BAA+B;QAC3C,IAAII,iBAA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OrE;IAExB,IAAIxD;IACJ,IAAI;QACFA,cAAc,MAAM0H,OAAOI,eAAe,CAAC;YACzCrK,MAAMkK,KAAKlK,IAAI;YACf4B,QAAQsI,KAAKjD,MAAM;YACnB9E,OAAOiI,WAAWjI,KAAK;YACvBrC,OAAOsK,WAAWtK,KAAK;QACzB;IACF,EAAE,OAAO6J,OAAO;QACdC,QAAQD,KAAK,CAAC,8CAA8CA;QAC5D,OAAO;YACL3D,IAAI;YACJC,QAAQ;YACRC,SACEyD,iBAAiB3B,SAAS2B,MAAMzD,OAAO,GACnCyD,MAAMzD,OAAO,GACb;QACR;IACF;IAEA,MAAMuD,YAAYrD,SAASQ,GAAG,CAACxC,MAAM,CAAC,CAACuC,KAAOA,GAAGA,EAAE,KAAK,YAAYA,GAAGA,EAAE,KAAK;IAC9E,IAAI;QACF7F,OAAO4I,KAAK,CAAC;YACX,KAAK,MAAM/C,MAAM8C,UAAWxB,SAASnH,QAAQ6F;YAC7C7F,OAAOwJ,UAAU,CACf9L,2BACEsC,OAAOmI,MAAM,GAAG9G,KAAK,EACrB+H,KAAKjD,MAAM,EACX1E,aACA2H,KAAKlK,IAAI;QAGf;IACF,EAAE,OAAO2J,OAAO;QACdC,QAAQD,KAAK,CAAC,qCAAqCA;QACnD,OAAO;YACL3D,IAAI;YACJC,QAAQ;YACRC,SACE,kFACA;QACJ;IACF;IACA,OAAO;QAAEF,IAAI;QAAM+D,UAAU7K,mBAAmBkH,SAASQ,GAAG;QAAGiD,QAAQ,EAAE;IAAC;AAC5E"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/assist-edit-canvas.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 {\n screenSeoStageKey,\n type ScreenSeoTextField,\n} from '@aglyn/aglyn/app-utils/screen-seo-fields'\nimport {\n NODE_HIDE_IF_PROP,\n replaceSubtreeWithInstance,\n reusableComponentDefinitionFrom,\n} from '@aglyn/aglyn/app-utils/compose-reusable-components'\nimport { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport {\n NODE_MAX_INTERACTIONS,\n upsertNodeInteraction,\n type NodeInteraction,\n} from '@aglyn/aglyn/app-utils/node-interactions'\nimport type {\n ReusableComponentProp,\n ReusableComponentPropValue,\n} from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport {\n stageEditorSessionFields,\n type EditorSession,\n} from '@aglyn/aglyn/plugin-manager/editor-sessions'\nimport {\n ASSIST_EDIT_CONTEXT_MAX_NODES,\n ASSIST_EDIT_CONTEXT_MAX_PROPS,\n ASSIST_EDIT_OUTLINE_TEXT_CHARS,\n ASSIST_EDIT_SELECTED_TEXT_CHARS,\n ASSIST_EDIT_WHOLE_MAX_NODES,\n assistEditOpCounts,\n type AssistEditCanvasContext,\n type AssistEditCanvasNode,\n type AssistEditInsertOp,\n type AssistEditInteractionSummary,\n type AssistEditOp,\n type AssistEditProposal,\n type AssistEditComponentProp,\n type AssistEditSaveAsComponentOp,\n} from '../model/assist-edit'\n\n/**\n * The edit rung's client half (AGL-2906): what the panel tells the server\n * about the open canvas, and how a confirmed proposal lands on it.\n *\n * Applying goes through the canvas's own guarded mutators — the same ones\n * the besigner's panels and the marketing appliers use — inside ONE\n * `batch`, so the whole proposal is one undo step and a guard that refuses\n * part-way leaves nothing behind. Every change is an unsaved edit on the\n * version the editor has open; saving it stays the author's act, with the\n * editor's own control. On a version the live site serves, that save writes\n * the page's draft and never the version, so a change lands there too and\n * reaches visitors only when the author publishes (AGL-4116).\n */\n\n/** A node as the canvas holds it — the fields this module reads. */\nexport interface AssistEditCanvasNodeLike {\n $id?: string\n componentId?: string\n parentId?: string | null\n nodes?: string[]\n name?: string\n props?: unknown\n sx?: unknown\n /** The element's own interactions (AGL-3603), as the canvas holds them. */\n interactions?: unknown\n}\n\n/**\n * The slice of the besigner canvas the edit rung reads and drives. Every\n * member is one `CanvasManager` already has, so the panel hands over the\n * canvas itself and a spec hands over a real one.\n */\nexport interface AssistEditCanvas {\n getNode(id: string): AssistEditCanvasNodeLike | undefined\n batch<T>(mutate: () => T): T\n updateNodeProps(node: any, props: any): void\n updateNodeFields(node: any, patch: any): void\n reparentNode(node: any, parent: any, index?: number): unknown\n deleteNode(node: any): unknown\n addNodeFromNested(nested: any, parent: any, index?: number): unknown\n nodeAcceptsChildren(node: any): boolean\n /** The whole document, which a component save reads its definition out of. */\n toJSON(): { nodes: Record<string, unknown> }\n /** The document after a save: the promoted subtree swapped for an instance. */\n applyNodes(nodes: any): unknown\n}\n\nconst UNDESCRIBED_PROP = /^(html|sx|style|className|dangerouslySetInnerHTML|on[A-Z].*)$/\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * An observable's own keys as a plain object. A canvas node's `props` and\n * `sx` are observable proxies, and a spread of one is how a merge silently\n * copies nothing.\n */\nfunction plain(value: unknown): Record<string, unknown> {\n const out: Record<string, unknown> = {}\n if (!value || typeof value !== 'object') return out\n for (const key in value as Record<string, unknown>) {\n out[key] = (value as Record<string, unknown>)[key]\n }\n return out\n}\n\nfunction describeProps(\n raw: unknown,\n textChars: number,\n): Record<string, string | number | boolean> | undefined {\n const props: Record<string, string | number | boolean> = {}\n let kept = 0\n for (const [name, value] of Object.entries(plain(raw))) {\n if (kept >= ASSIST_EDIT_CONTEXT_MAX_PROPS) break\n if (UNDESCRIBED_PROP.test(name)) continue\n if (typeof value === 'string') {\n if (!value.trim()) continue\n props[name] = value.slice(0, textChars)\n } else if (typeof value === 'number' && Number.isFinite(value)) {\n props[name] = value\n } else if (typeof value === 'boolean') {\n props[name] = value\n } else {\n continue\n }\n kept += 1\n }\n return kept ? props : undefined\n}\n\nfunction describeSx(raw: unknown): Record<string, unknown> | undefined {\n const sx: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(plain(raw))) {\n if (typeof value === 'string' || typeof value === 'number') sx[key] = value\n else if (isRecord(value)) sx[key] = plain(value)\n }\n return Object.keys(sx).length ? sx : undefined\n}\n\n/**\n * The selection's ancestors below the document root, top-level section first\n * and the selection last; null when its parents do not lead to the root,\n * which is not a chain the server can check.\n */\nfunction chainToRoot(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n selected: AssistEditCanvasNodeLike,\n): string[] | null {\n const chain: string[] = []\n const walked = new Set<string>()\n let current: AssistEditCanvasNodeLike | undefined = selected\n while (current?.$id && current.$id !== CANVAS_ROOT_ELEMENT_ID && !walked.has(current.$id)) {\n walked.add(current.$id)\n chain.unshift(current.$id)\n current = current.parentId ? canvas.getNode(current.parentId) : undefined\n }\n return current?.$id === CANVAS_ROOT_ELEMENT_ID ? chain : null\n}\n\n/** Elements one shape is taken over at most; a larger subtree is never called alike. */\nconst SHAPE_LIMIT = 200\n\n/**\n * How an element is built: its component and, in order, its children's —\n * what two cards of one row have in common whatever their text. Null past\n * `SHAPE_LIMIT` elements, or for a subtree that loops back on itself.\n */\nfunction shapeOf(canvas: Pick<AssistEditCanvas, 'getNode'>, rootId: string): string | null {\n let budget = SHAPE_LIMIT\n const walked = new Set<string>()\n const walk = (id: string): string | null => {\n const node = canvas.getNode(id)\n if (!node || walked.has(id) || --budget < 0) return null\n walked.add(id)\n const parts: string[] = []\n for (const child of node.nodes ?? []) {\n const part = walk(child)\n if (part === null) return null\n parts.push(part)\n }\n return `${String(node.componentId ?? '')}(${parts.join(',')})`\n }\n return walk(rootId)\n}\n\n/** Elements reachable from the document root through child lists, the root included. */\nfunction countElements(canvas: Pick<AssistEditCanvas, 'getNode'>): number {\n let count = 0\n const reached = new Set<string>([CANVAS_ROOT_ELEMENT_ID])\n const pending = [CANVAS_ROOT_ELEMENT_ID]\n while (pending.length) {\n const node = canvas.getNode(pending.pop() as string)\n if (!node) continue\n count += 1\n for (const child of node.nodes ?? []) {\n if (reached.has(child)) continue\n reached.add(child)\n pending.push(child)\n }\n }\n return count\n}\n\n/**\n * The canvas outline a question carries on the edit rung, in two tiers, until\n * the cap.\n *\n * Described in full, settings and all: the document root, the selection's\n * ancestors and the selection, the document's top-level sections, everything\n * inside the selection — what an edit to it changes — and its siblings.\n *\n * Described briefly, by place alone (`brief`): what surrounds that, so the\n * model knows it exists and asks for it rather than calling it missing —\n *\n * 1. what the selection's siblings hold, level by level (the icons beside a\n * selected link, in the card they share);\n * 2. the siblings of each ancestor below the top-level section, nearest\n * first (the other cards of the row, then what sits beside the row).\n *\n * An element built the same way as the selection, or as the ancestor it sits\n * beside, is marked `like` it and its contents are left out: one card\n * described, and every other card of the row says it holds the same.\n *\n * With nothing selected, it is the root, the top-level sections and one level\n * inside each: enough for a change to the page as a whole, and the prompt asks\n * for a selection before anything more specific.\n *\n * With `whole`, it is the whole document instead (AGL-4116), up to\n * `ASSIST_EDIT_WHOLE_MAX_NODES`: every element, in the order it reads on the\n * page, with its settings and its styles. That is what the chat in the\n * Besigner sends, so \"change the Get in touch button\" finds the button with\n * nothing selected. A document past the cap falls back to the two tiers.\n *\n * An element is only ever described after its parent, so every ancestor chain\n * the server checks is whole. `total` counts the document, and each element's\n * `childCount` stays its real one, so the server can tell the model what the\n * outline leaves out. The server holds this to its own limits before it quotes\n * a byte of it; null when the canvas has no document root loaded.\n */\nexport function describeAssistEditCanvas(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n selectedId: string | null,\n options: { whole?: boolean } = {},\n): AssistEditCanvasContext | null {\n const root = canvas.getNode(CANVAS_ROOT_ELEMENT_ID)\n if (!root) return null\n const whole = options.whole ? describeWholeCanvas(canvas, selectedId) : null\n if (whole) return whole\n const order: string[] = []\n const seen = new Set<string>()\n const brief = new Set<string>()\n const like = new Map<string, string>()\n const full = (): boolean => order.length >= ASSIST_EDIT_CONTEXT_MAX_NODES\n const add = (id: string | undefined | null, briefly = false): void => {\n if (!id || seen.has(id) || full()) return\n if (!canvas.getNode(id)) return\n seen.add(id)\n order.push(id)\n if (briefly) brief.add(id)\n }\n const childrenOf = (id: string): string[] => canvas.getNode(id)?.nodes ?? []\n const shapes = new Map<string, string | null>()\n const shape = (id: string): string | null => {\n if (!shapes.has(id)) shapes.set(id, shapeOf(canvas, id))\n return shapes.get(id) ?? null\n }\n // Alike only when there are contents to leave out.\n const alike = (id: string, model: string): boolean =>\n childrenOf(id).length > 0 && shape(id) !== null && shape(id) === shape(model)\n\n add(CANVAS_ROOT_ELEMENT_ID)\n const selected =\n selectedId && selectedId !== CANVAS_ROOT_ELEMENT_ID ? canvas.getNode(selectedId) : undefined\n const chain = selected?.$id ? chainToRoot(canvas, selected) : null\n chain?.forEach((id) => add(id))\n if (selected?.$id && chain && seen.has(selected.$id)) {\n for (const id of root.nodes ?? []) add(id)\n const inside = new Set<string>([selected.$id])\n const queue = [...childrenOf(selected.$id)]\n while (queue.length && !full()) {\n const id = queue.shift() as string\n if (inside.has(id)) continue\n inside.add(id)\n add(id)\n queue.push(...childrenOf(id))\n }\n const siblings = selected.parentId\n ? childrenOf(selected.parentId).filter((id) => id !== selected.$id)\n : []\n const held: string[] = []\n for (const id of siblings) {\n add(id)\n // A sibling the cap left out takes its contents with it.\n if (!seen.has(id)) continue\n if (alike(id, selected.$id)) like.set(id, selected.$id)\n else held.push(...childrenOf(id))\n }\n const reached = new Set<string>([...inside, ...siblings, ...held])\n for (let level = held; level.length && !full(); ) {\n const deeper: string[] = []\n for (const id of level) {\n add(id, true)\n for (const child of childrenOf(id)) {\n if (reached.has(child)) continue\n reached.add(child)\n deeper.push(child)\n }\n }\n level = deeper\n }\n // Parent first; the top-level section's own siblings are the sections above.\n for (const ancestor of chain.slice(1, -1).reverse()) {\n const parentId = canvas.getNode(ancestor)?.parentId\n for (const id of parentId ? childrenOf(parentId) : []) {\n if (id === ancestor || seen.has(id)) continue\n add(id, true)\n if (seen.has(id) && alike(id, ancestor)) like.set(id, ancestor)\n }\n }\n } else {\n for (const id of root.nodes ?? []) add(id)\n for (const section of root.nodes ?? []) {\n for (const id of childrenOf(section)) add(id)\n }\n }\n\n const nodes = order.map((id) => {\n const isSelected = id === selected?.$id\n return outlineElement(canvas, id, {\n selected: isSelected,\n brief: brief.has(id),\n like: like.get(id),\n textChars: isSelected ? ASSIST_EDIT_SELECTED_TEXT_CHARS : ASSIST_EDIT_OUTLINE_TEXT_CHARS,\n styles: isSelected,\n })\n })\n return {\n selectedId: selected?.$id && seen.has(selected.$id) ? selected.$id : null,\n total: countElements(canvas),\n nodes,\n }\n}\n\n/** One element as an outline carries it, at the tier it was described in. */\nfunction outlineElement(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n id: string,\n tier: { selected: boolean; brief?: boolean; like?: string; textChars: number; styles: boolean },\n): AssistEditCanvasNode {\n const node = canvas.getNode(id) as AssistEditCanvasNodeLike\n const parentId = id === CANVAS_ROOT_ELEMENT_ID ? null : (node.parentId ?? null)\n const parent = parentId ? canvas.getNode(parentId) : undefined\n const props = tier.brief ? undefined : describeProps(node.props, tier.textChars)\n const sx = tier.styles ? describeSx(node.sx) : undefined\n return {\n id,\n componentId: String(node.componentId ?? ''),\n parentId,\n index: Math.max(0, parent?.nodes?.indexOf(id) ?? 0),\n childCount: node.nodes?.length ?? 0,\n ...(node.name ? { name: String(node.name) } : {}),\n ...(props ? { props } : {}),\n ...(sx ? { sx } : {}),\n ...(tier.brief ? { brief: true } : {}),\n ...(tier.like ? { like: tier.like } : {}),\n ...(tier.selected ? summarizeInteractions(node.interactions) : {}),\n }\n}\n\n/**\n * The whole document as the chat in the Besigner sends it (AGL-4116): every\n * element depth first, children in their stored order, so the outline reads\n * as the page does and each element follows its parent. Null past the cap.\n */\nfunction describeWholeCanvas(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n selectedId: string | null,\n): AssistEditCanvasContext | null {\n const total = countElements(canvas)\n if (total > ASSIST_EDIT_WHOLE_MAX_NODES) return null\n const selected = selectedId !== CANVAS_ROOT_ELEMENT_ID ? selectedId : null\n const nodes: AssistEditCanvasNode[] = []\n const seen = new Set<string>([CANVAS_ROOT_ELEMENT_ID])\n const pending = [CANVAS_ROOT_ELEMENT_ID]\n while (pending.length) {\n const id = pending.pop() as string\n const node = canvas.getNode(id)\n if (!node) continue\n nodes.push(\n outlineElement(canvas, id, {\n selected: id === selected,\n textChars: ASSIST_EDIT_SELECTED_TEXT_CHARS,\n styles: true,\n }),\n )\n const children = node.nodes ?? []\n for (let index = children.length - 1; index >= 0; index -= 1) {\n if (seen.has(children[index])) continue\n seen.add(children[index])\n pending.push(children[index])\n }\n }\n return {\n selectedId: selected && nodes.some((node) => node.id === selected) ? selected : null,\n total,\n nodes,\n whole: true,\n }\n}\n\n/**\n * The selected element's interactions as the outline carries them\n * (AGL-3603): name, event and the kinds of its steps — never a selector.\n */\nfunction summarizeInteractions(raw: unknown): { interactions?: AssistEditInteractionSummary[] } {\n if (!Array.isArray(raw) || !raw.length) return {}\n const interactions = raw\n .filter(isRecord)\n .slice(0, NODE_MAX_INTERACTIONS)\n .map((entry) => ({\n name: String(entry['name'] ?? ''),\n event: String(isRecord(entry['trigger']) ? (entry['trigger']['event'] ?? '') : ''),\n steps: (Array.isArray(entry['steps']) ? entry['steps'] : [])\n .filter(isRecord)\n .map((step) => String(step['type'] ?? '')),\n enabled: entry['enabled'] !== false,\n }))\n .filter((entry) => entry.event)\n return interactions.length ? { interactions } : {}\n}\n\n/** Why a proposal cannot land on the open editor as it stands. */\nexport type AssistEditRefusal =\n /** No editor is open. */\n | 'no-editor'\n /** The editor open is not the document the proposal was made for. */\n | 'other-document'\n /** An element the proposal names has gone or changed since. */\n | 'stale'\n /** The canvas's own guards refused part of the change. */\n | 'refused'\n\nexport type AssistEditCheck =\n | { ok: true }\n | { ok: false; reason: AssistEditRefusal; message: string }\n\nexport type AssistEditApplyResult =\n | {\n ok: true\n /** Applied ops, counted by kind for the activity row. */\n opCounts: Record<string, number>\n /** Editor fields staged, as the editor keys them. */\n staged: string[]\n }\n | { ok: false; reason: AssistEditRefusal; message: string }\n\n/** Ids of the subtree at `rootId`, the root included, through child lists only. */\nfunction subtreeIds(\n canvas: Pick<AssistEditCanvas, 'getNode'>,\n rootId: string,\n): Set<string> {\n const found = new Set<string>([rootId])\n const queue = [...(canvas.getNode(rootId)?.nodes ?? [])]\n while (queue.length) {\n const id = queue.shift() as string\n if (found.has(id) || !canvas.getNode(id)) continue\n found.add(id)\n queue.push(...(canvas.getNode(id)?.nodes ?? []))\n }\n return found\n}\n\nconst STALE: AssistEditCheck = {\n ok: false,\n reason: 'stale',\n message: 'The canvas has changed since this was proposed, so nothing was applied. Ask again.',\n}\n\n/**\n * Whether the proposal can land on the open editor as it stands — checked in\n * full before anything is touched, so a refusal never leaves half an edit.\n */\nexport function checkAssistEdit(\n canvas: Pick<AssistEditCanvas, 'getNode' | 'nodeAcceptsChildren'>,\n proposal: AssistEditProposal,\n session: EditorSession | undefined,\n): AssistEditCheck {\n if (!session) {\n return {\n ok: false,\n reason: 'no-editor',\n message: 'Open the editor this change was proposed for to apply it.',\n }\n }\n if (\n session.documentKind !== proposal.target.kind ||\n session.documentId !== proposal.target.documentId\n ) {\n return {\n ok: false,\n reason: 'other-document',\n message: 'This change was proposed for a different document than the one open.',\n }\n }\n // The version the live site shows takes the change too (AGL-4116): it lands\n // as unsaved edits on the canvas, exactly as the author's own would, and the\n // Besigner's Save on that version writes the page's draft, never the version\n // visitors see. Publishing stays its own deliberate step.\n for (const op of proposal.ops) {\n switch (op.op) {\n case 'setSeo': {\n for (const field of Object.keys(op.fields) as ScreenSeoTextField[]) {\n if (typeof session.fields?.[screenSeoStageKey(field)] !== 'function') {\n return {\n ok: false,\n reason: 'other-document',\n message: 'This editor has no search fields to fill in.',\n }\n }\n }\n break\n }\n case 'insertSubtree': {\n const parent = canvas.getNode(op.parentId)\n if (!parent || parent.componentId !== op.parentComponentId) return STALE\n if (!canvas.nodeAcceptsChildren(parent)) return STALE\n break\n }\n case 'move': {\n const node = canvas.getNode(op.nodeId)\n const parent = canvas.getNode(op.parentId)\n if (!node || node.componentId !== op.componentId) return STALE\n if (!parent || parent.componentId !== op.parentComponentId) return STALE\n break\n }\n case 'saveAsComponent': {\n const node = canvas.getNode(op.nodeId)\n if (!node || node.componentId !== op.componentId) return STALE\n // The document itself is not a section of itself: promoting the root\n // would leave a document holding one instance of its own contents.\n if (op.nodeId === CANVAS_ROOT_ELEMENT_ID) return STALE\n const inside = subtreeIds(canvas, op.nodeId)\n for (const binding of op.bindings) {\n const bound = canvas.getNode(binding.nodeId)\n if (!bound || bound.componentId !== binding.componentId) return STALE\n // A closed world: a token outside the promoted subtree would bind a\n // property of the new component to an element it does not contain.\n if (!inside.has(binding.nodeId)) return STALE\n }\n break\n }\n case 'addInteraction': {\n const node = canvas.getNode(op.nodeId)\n if (!node || node.componentId !== op.componentId) return STALE\n if (Array.isArray(node.interactions) && node.interactions.length >= NODE_MAX_INTERACTIONS) {\n return {\n ok: false,\n reason: 'refused',\n message: `That element already does ${NODE_MAX_INTERACTIONS} things, the most one can. Remove one in Interactions first.`,\n }\n }\n // Every element a step acts on is still there, as it was.\n for (const target of op.targets) {\n const live = canvas.getNode(target.nodeId)\n if (!live || live.componentId !== target.componentId) return STALE\n }\n break\n }\n default: {\n const node = canvas.getNode(op.nodeId)\n if (!node || node.componentId !== op.componentId) return STALE\n }\n }\n }\n return { ok: true }\n}\n\n/**\n * Styles merged one key at a time. A responsive patch over a plain value\n * keeps that value as the base breakpoint, so \"more padding on wide screens\"\n * does not quietly remove the padding everywhere else.\n */\nfunction mergeSx(\n current: Record<string, unknown>,\n patch: Record<string, unknown>,\n): Record<string, unknown> {\n const out = { ...current }\n for (const [key, value] of Object.entries(patch)) {\n const existing = out[key]\n if (isRecord(value) && isRecord(existing)) {\n out[key] = { ...plain(existing), ...value }\n } else if (isRecord(value) && (typeof existing === 'string' || typeof existing === 'number')) {\n out[key] = { xs: existing, ...value }\n } else {\n out[key] = value\n }\n }\n return out\n}\n\n/** A validated flat subtree as the nested shape `addNodeFromNested` takes. */\nfunction nestSubtree(op: AssistEditInsertOp): Record<string, unknown> {\n const visited = new Set<string>()\n const build = (id: string): Record<string, unknown> => {\n visited.add(id)\n const node = op.nodes[id]\n return {\n componentId: node.componentId,\n ...(node.pluginId ? { pluginId: node.pluginId } : {}),\n props: { ...node.props },\n ...(node.sx ? { sx: { ...node.sx } } : {}),\n ...(node.hidden ? { hidden: true } : {}),\n nodes: node.nodes\n .filter((child) => op.nodes[child] && !visited.has(child))\n .map((child) => build(child)),\n }\n }\n return build(op.rootId)\n}\n\nfunction live(canvas: AssistEditCanvas, id: string): AssistEditCanvasNodeLike {\n const node = canvas.getNode(id)\n if (!node) throw new Error(`element ${id} is no longer on the canvas`)\n return node\n}\n\nfunction applyOne(canvas: AssistEditCanvas, op: AssistEditOp): void {\n switch (op.op) {\n case 'updateProps': {\n const node = live(canvas, op.nodeId)\n // Spread the props the element has: `updateNodeProps` REPLACES the bag,\n // and a patch of one setting would otherwise strip every other one.\n const next: Record<string, unknown> = { ...plain(node.props), ...op.props }\n // Rich text renders `html` over `children`; proposed text replaces it.\n if ('children' in op.props) delete next['html']\n canvas.updateNodeProps(node, next)\n return\n }\n case 'updateSx': {\n const node = live(canvas, op.nodeId)\n canvas.updateNodeFields(node, { sx: mergeSx(plain(node.sx), op.sx) })\n return\n }\n case 'move':\n canvas.reparentNode(live(canvas, op.nodeId), live(canvas, op.parentId), op.index ?? NaN)\n return\n case 'remove':\n canvas.deleteNode(live(canvas, op.nodeId))\n return\n case 'rename':\n canvas.updateNodeFields(live(canvas, op.nodeId), { name: op.name })\n return\n case 'addInteraction': {\n // Added beside what the element does already, never in place of it:\n // an id the element already uses is re-minted, so nothing is replaced.\n const node = live(canvas, op.nodeId)\n const current = (Array.isArray(node.interactions) ? node.interactions : []) as NodeInteraction[]\n let id = op.interaction.id\n while (current.some((entry) => entry.id === id)) id = `${op.interaction.id}${current.length}x`\n canvas.updateNodeFields(node, {\n interactions: upsertNodeInteraction(current, { ...op.interaction, id }),\n })\n return\n }\n case 'insertSubtree':\n canvas.addNodeFromNested(nestSubtree(op), live(canvas, op.parentId), op.index ?? NaN)\n return\n case 'setSeo':\n case 'saveAsComponent':\n // Both are applied outside the canvas batch: search fields are staged\n // into the editor's own form, and a component save mints a document\n // first and then swaps the subtree for an instance of it.\n return\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Save the selection as a reusable component (AGL-2908)\n * ------------------------------------------------------------------ */\n\n/** What the apply needs from the console to create the component. */\nexport interface AssistEditComponentWriter {\n /**\n * Creates the component through `POST /api/hosts/resources`, where the\n * plan's entitlement and the route's field allow-list are enforced, and\n * answers its id. The plugin never writes Firestore from the browser.\n */\n createComponent(input: {\n name: string\n rootId: string\n nodes: Record<string, unknown>\n props: ReusableComponentProp[]\n }): Promise<string>\n}\n\n/**\n * The value a bound field holds on the live canvas right now, which becomes\n * the property's default.\n *\n * `hideIf` is the exception: the part is on the page, so the property that\n * hides it starts at no. Every other field answers with what the author can\n * see, which is what makes the instance render exactly what was there.\n */\nfunction currentValue(\n node: AssistEditCanvasNodeLike,\n field: string,\n): ReusableComponentPropValue | undefined {\n if (field === NODE_HIDE_IF_PROP) return false\n const value = plain(node.props)[field]\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value\n }\n return undefined\n}\n\n/**\n * Whether a default the canvas gave is one the property's own control\n * offers. A Choice whose current value is not among its answers is a\n * selection that has changed since the proposal was made, and applying it\n * would declare a property no page could ever set back.\n */\nfunction defaultFitsProp(prop: AssistEditComponentProp, value: unknown): boolean {\n if (!prop.options?.length) return true\n return prop.options.some((option) => option.value === value)\n}\n\n/**\n * The definition the new component holds: the promoted subtree, with each\n * bound field replaced by its property's token.\n *\n * The defaults are read off the SAME fields a moment before they are\n * replaced, so the instance that takes the subtree's place renders what the\n * author was looking at. Returns null when a default no longer fits its\n * property, which is the stale case.\n */\nfunction componentDefinition(\n canvas: AssistEditCanvas,\n op: AssistEditSaveAsComponentOp,\n): { nodes: Record<string, unknown>; props: ReusableComponentProp[] } | null {\n const nodes = reusableComponentDefinitionFrom(\n canvas.toJSON().nodes as never,\n op.nodeId,\n ) as unknown as Record<string, Record<string, unknown>>\n const defaults = new Map<string, ReusableComponentPropValue | undefined>()\n for (const binding of op.bindings) {\n const live = canvas.getNode(binding.nodeId)\n const stored = nodes[binding.nodeId]\n if (!live || !stored) return null\n if (!defaults.has(binding.prop)) defaults.set(binding.prop, currentValue(live, binding.field))\n stored['props'] = { ...plain(stored['props']), [binding.field]: `{{prop.${binding.prop}}}` }\n }\n const props: ReusableComponentProp[] = []\n for (const declared of op.props) {\n const value = defaults.get(declared.name)\n if (!defaultFitsProp(declared, value)) return null\n props.push({ ...declared, ...(value === undefined ? {} : { defaultValue: value }) })\n }\n return { nodes, props }\n}\n\n/**\n * Lands a confirmed proposal on the open editor: the canvas ops as ONE batch\n * — one undo step, all or nothing — then any search fields staged into the\n * editor's own form. Nothing is saved.\n */\nexport function applyAssistEdit(\n canvas: AssistEditCanvas,\n proposal: AssistEditProposal,\n session: EditorSession | undefined,\n): AssistEditApplyResult {\n const check = checkAssistEdit(canvas, proposal, session)\n if (check.ok === false) return check\n const open = session as EditorSession\n const canvasOps = proposal.ops.filter((op) => op.op !== 'setSeo' && op.op !== 'saveAsComponent')\n if (canvasOps.length) {\n try {\n canvas.batch(() => {\n for (const op of canvasOps) applyOne(canvas, op)\n })\n } catch (error) {\n console.error('assist edit refused by the canvas', error)\n return {\n ok: false,\n reason: 'refused',\n message: 'The editor refused part of this change, so none of it was applied.',\n }\n }\n }\n const staged: string[] = []\n for (const op of proposal.ops) {\n if (op.op !== 'setSeo') continue\n const values: Record<string, string> = {}\n for (const [field, value] of Object.entries(op.fields)) {\n values[screenSeoStageKey(field as ScreenSeoTextField)] = String(value)\n }\n staged.push(...stageEditorSessionFields(open, values).staged)\n }\n return { ok: true, opCounts: assistEditOpCounts(proposal.ops), staged }\n}\n\n/**\n * Lands a proposal that saves the selection as a reusable component\n * (AGL-2908) — AGL-2866's recipe, in place, with no clipboard.\n *\n * The order is the manual action's order, and it matters:\n *\n * 1. the definition is read off the live subtree, each bound field replaced\n * by its token and its current value kept as that property's default;\n * 2. the component is created through the host resources route, where the\n * server enforces the plan's entitlement and its own allow-list — so a\n * refusal happens before the open document is touched at all;\n * 3. the subtree is swapped for an instance of what was just created, inside\n * ONE `batch` with the rest of the proposal's canvas ops: one undo step.\n *\n * The only document created is the component, exactly as Save as reusable\n * component creates one. The page change is an unsaved edit on the version\n * the editor has open, which the check has already refused to be a live one.\n * Nothing is published and nothing is saved.\n */\nexport async function applyAssistEditSavingComponent(\n canvas: AssistEditCanvas,\n proposal: AssistEditProposal,\n session: EditorSession | undefined,\n writer: AssistEditComponentWriter,\n): Promise<AssistEditApplyResult> {\n const save = proposal.ops.find(\n (op): op is AssistEditSaveAsComponentOp => op.op === 'saveAsComponent',\n )\n if (!save) return applyAssistEdit(canvas, proposal, session)\n const check = checkAssistEdit(canvas, proposal, session)\n if (check.ok === false) return check\n\n const definition = componentDefinition(canvas, save)\n if (!definition) return STALE as AssistEditApplyResult\n\n let componentId: string\n try {\n componentId = await writer.createComponent({\n name: save.name,\n rootId: save.nodeId,\n nodes: definition.nodes,\n props: definition.props,\n })\n } catch (error) {\n console.error('assist edit could not create the component', error)\n return {\n ok: false,\n reason: 'refused',\n message:\n error instanceof Error && error.message\n ? error.message\n : 'The component could not be saved, so nothing on this page was changed.',\n }\n }\n\n const canvasOps = proposal.ops.filter((op) => op.op !== 'setSeo' && op.op !== 'saveAsComponent')\n try {\n canvas.batch(() => {\n for (const op of canvasOps) applyOne(canvas, op)\n canvas.applyNodes(\n replaceSubtreeWithInstance(\n canvas.toJSON().nodes as never,\n save.nodeId,\n componentId,\n save.name,\n ),\n )\n })\n } catch (error) {\n console.error('assist edit refused by the canvas', error)\n return {\n ok: false,\n reason: 'refused',\n message:\n 'The component was saved, but the editor refused to swap this element for it. ' +\n 'Insert it from Your components instead.',\n }\n }\n return { ok: true, opCounts: assistEditOpCounts(proposal.ops), staged: [] }\n}\n"],"names":["screenSeoStageKey","NODE_HIDE_IF_PROP","replaceSubtreeWithInstance","reusableComponentDefinitionFrom","CANVAS_ROOT_ELEMENT_ID","NODE_MAX_INTERACTIONS","upsertNodeInteraction","stageEditorSessionFields","ASSIST_EDIT_CONTEXT_MAX_NODES","ASSIST_EDIT_CONTEXT_MAX_PROPS","ASSIST_EDIT_OUTLINE_TEXT_CHARS","ASSIST_EDIT_SELECTED_TEXT_CHARS","ASSIST_EDIT_WHOLE_MAX_NODES","assistEditOpCounts","UNDESCRIBED_PROP","isRecord","value","Array","isArray","plain","out","key","describeProps","raw","textChars","props","kept","name","Object","entries","test","trim","slice","Number","isFinite","undefined","describeSx","sx","keys","length","chainToRoot","canvas","selected","chain","walked","Set","current","$id","has","add","unshift","parentId","getNode","SHAPE_LIMIT","shapeOf","rootId","budget","walk","id","node","parts","child","nodes","part","push","String","componentId","join","countElements","count","reached","pending","pop","describeAssistEditCanvas","selectedId","options","root","whole","describeWholeCanvas","order","seen","brief","like","Map","full","briefly","childrenOf","shapes","shape","set","get","alike","model","forEach","inside","queue","shift","siblings","filter","held","level","deeper","ancestor","reverse","section","map","isSelected","outlineElement","styles","total","tier","parent","index","Math","max","indexOf","childCount","summarizeInteractions","interactions","children","some","entry","event","steps","step","enabled","subtreeIds","found","STALE","ok","reason","message","checkAssistEdit","proposal","session","documentKind","target","kind","documentId","op","ops","field","fields","parentComponentId","nodeAcceptsChildren","nodeId","binding","bindings","bound","targets","live","mergeSx","patch","existing","xs","nestSubtree","visited","build","pluginId","hidden","Error","applyOne","next","updateNodeProps","updateNodeFields","reparentNode","NaN","deleteNode","interaction","addNodeFromNested","currentValue","defaultFitsProp","prop","option","componentDefinition","toJSON","defaults","stored","declared","defaultValue","applyAssistEdit","check","open","canvasOps","batch","error","console","staged","values","opCounts","applyAssistEditSavingComponent","writer","save","find","definition","createComponent","applyNodes"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,iBAAiB,QAEZ,2CAA0C;AACjD,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,+BAA+B,QAC1B,qDAAoD;AAC3D,SAASC,sBAAsB,QAAQ,2CAA0C;AACjF,SACEC,qBAAqB,EACrBC,qBAAqB,QAEhB,2CAA0C;AAKjD,SACEC,wBAAwB,QAEnB,8CAA6C;AACpD,SACEC,6BAA6B,EAC7BC,6BAA6B,EAC7BC,8BAA8B,EAC9BC,+BAA+B,EAC/BC,2BAA2B,EAC3BC,kBAAkB,QASb,0BAAsB;AAiD7B,MAAMC,mBAAmB;AAEzB,MAAMC,WAAW,CAACC,QAChB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AAEhE;;;;CAIC,GACD,SAASG,MAAMH,KAAc;IAC3B,MAAMI,MAA+B,CAAC;IACtC,IAAI,CAACJ,SAAS,OAAOA,UAAU,UAAU,OAAOI;IAChD,IAAK,MAAMC,OAAOL,MAAkC;QAClDI,GAAG,CAACC,IAAI,GAAG,AAACL,KAAiC,CAACK,IAAI;IACpD;IACA,OAAOD;AACT;AAEA,SAASE,cACPC,GAAY,EACZC,SAAiB;IAEjB,MAAMC,QAAmD,CAAC;IAC1D,IAAIC,OAAO;IACX,KAAK,MAAM,CAACC,MAAMX,MAAM,IAAIY,OAAOC,OAAO,CAACV,MAAMI,MAAO;QACtD,IAAIG,QAAQjB,+BAA+B;QAC3C,IAAIK,iBAAiBgB,IAAI,CAACH,OAAO;QACjC,IAAI,OAAOX,UAAU,UAAU;YAC7B,IAAI,CAACA,MAAMe,IAAI,IAAI;YACnBN,KAAK,CAACE,KAAK,GAAGX,MAAMgB,KAAK,CAAC,GAAGR;QAC/B,OAAO,IAAI,OAAOR,U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KAAKrK,IAAI;YACf4B,QAAQyI,KAAK/C,MAAM;YACnBnF,OAAOoI,WAAWpI,KAAK;YACvBrC,OAAOyK,WAAWzK,KAAK;QACzB;IACF,EAAE,OAAOgK,OAAO;QACdC,QAAQD,KAAK,CAAC,8CAA8CA;QAC5D,OAAO;YACLxD,IAAI;YACJC,QAAQ;YACRC,SACEsD,iBAAiBzB,SAASyB,MAAMtD,OAAO,GACnCsD,MAAMtD,OAAO,GACb;QACR;IACF;IAEA,MAAMoD,YAAYlD,SAASO,GAAG,CAAC1C,MAAM,CAAC,CAACyC,KAAOA,GAAGA,EAAE,KAAK,YAAYA,GAAGA,EAAE,KAAK;IAC9E,IAAI;QACFlG,OAAO+I,KAAK,CAAC;YACX,KAAK,MAAM7C,MAAM4C,UAAWtB,SAASxH,QAAQkG;YAC7ClG,OAAO2J,UAAU,CACflM,2BACEuC,OAAOsI,MAAM,GAAGjH,KAAK,EACrBkI,KAAK/C,MAAM,EACX/E,aACA8H,KAAKrK,IAAI;QAGf;IACF,EAAE,OAAO8J,OAAO;QACdC,QAAQD,KAAK,CAAC,qCAAqCA;QACnD,OAAO;YACLxD,IAAI;YACJC,QAAQ;YACRC,SACE,kFACA;QACJ;IACF;IACA,OAAO;QAAEF,IAAI;QAAM4D,UAAUhL,mBAAmBwH,SAASO,GAAG;QAAG+C,QAAQ,EAAE;IAAC;AAC5E"}
@@ -26,11 +26,13 @@ import { describeAssistEditDiff } from "../model/assist-edit.js";
26
26
  * It says what would change — the counts, and what validation left out —
27
27
  * and offers exactly one way forward for the editor as it stands:
28
28
  *
29
- * - on the document the proposal was made for, on a version the live site
30
- * does not serve: **Apply as draft**, which the panel carries out through
31
- * the canvas's own mutators as one undoable, unsaved change;
32
- * - on the version the live site serves: **Make a new version**, the
33
- * editor's own flow, after which the same card offers Apply there;
29
+ * - on the document the proposal was made for: **Apply as draft**, which the
30
+ * panel carries out through the canvas's own mutators as one undoable,
31
+ * unsaved change. On the version the live site serves too (AGL-4116): the
32
+ * Besigner saves that version's changes into the page's draft, never the
33
+ * version itself, so the change is as safe there as an edit by hand, and
34
+ * **Make a new version** is offered beside it for an author who wants the
35
+ * change kept apart;
34
36
  * - anywhere else: nothing to press but **No thanks**.
35
37
  *
36
38
  * The card makes no request and holds no write of its own: its buttons call
@@ -137,7 +139,7 @@ export function AssistEditCard(props) {
137
139
  sx: {
138
140
  mt: 1
139
141
  },
140
- children: !onDocument ? `Open this ${noun} in the Besigner to apply the change.` : live ? `This is the version your live site shows. Make a new version first — the change is applied there, and the live ${noun} stays as it is.` : savesComponent ? `${brand} Assist changes nothing until you apply. Applying saves the component to your library, and swaps this element for one that follows it — an unsaved edit on the open canvas that undo takes back. Nothing is published.` : `${brand} Assist changes nothing until you apply. Applying adds these changes to the open canvas as unsaved edits: undo takes them back, and nothing is saved or published until you save.`
142
+ children: !onDocument ? `Open this ${noun} in the Besigner to apply the change.` : live && !savesComponent ? `${brand} Assist changes nothing until you apply. Applying adds these changes to the open canvas as unsaved edits that undo takes back. This is the version your live site shows: Save draft keeps them in this ${noun}’s draft, and visitors see them only when you publish.` : savesComponent ? `${brand} Assist changes nothing until you apply. Applying saves the component to your library, and swaps this element for one that follows it — an unsaved edit on the open canvas that undo takes back. Nothing is published.` : `${brand} Assist changes nothing until you apply. Applying adds these changes to the open canvas as unsaved edits: undo takes them back, and nothing is saved or published until you save.`
141
143
  }),
142
144
  failure ? /*#__PURE__*/ _jsx(Alert, {
143
145
  severity: "warning",
@@ -153,14 +155,13 @@ export function AssistEditCard(props) {
153
155
  mt: 1.5
154
156
  },
155
157
  children: [
156
- onDocument && !live ? /*#__PURE__*/ _jsx(Button, {
158
+ onDocument ? /*#__PURE__*/ _jsx(Button, {
157
159
  variant: "contained",
158
160
  size: "small",
159
161
  onClick: onApply,
160
162
  children: "Apply as draft"
161
163
  }) : null,
162
164
  onDocument && live && (session == null ? void 0 : session.createVersion) ? /*#__PURE__*/ _jsx(Button, {
163
- variant: "contained",
164
165
  size: "small",
165
166
  onClick: onCreateVersion,
166
167
  children: "Make a new version"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/assist-edit-card.component.tsx"],"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'use client'\n\nimport type { EditorSession } from '@aglyn/aglyn/plugin-manager/editor-sessions'\nimport { mdiChevronDown, mdiChevronUp } from '@aglyn/shared-data-mdi'\nimport { MdiIcon } from '@aglyn/shared-ui-jsx'\nimport {\n Alert,\n Box,\n Button,\n Collapse,\n Link,\n Paper,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useState } from 'react'\nimport {\n describeAssistEditDiff,\n type AssistEditDocumentKind,\n type AssistEditProposal,\n} from '../model/assist-edit'\n\n/**\n * The edit card (AGL-2906): a level-3 proposal as the author decides on it.\n *\n * It says what would change — the counts, and what validation left out —\n * and offers exactly one way forward for the editor as it stands:\n *\n * - on the document the proposal was made for, on a version the live site\n * does not serve: **Apply as draft**, which the panel carries out through\n * the canvas's own mutators as one undoable, unsaved change;\n * - on the version the live site serves: **Make a new version**, the\n * editor's own flow, after which the same card offers Apply there;\n * - anywhere else: nothing to press but **No thanks**.\n *\n * The card makes no request and holds no write of its own: its buttons call\n * back into the panel, which applies through the canvas and reports nothing\n * but the counts.\n */\n\nconst DOCUMENT_NOUNS: Readonly<Record<AssistEditDocumentKind, string>> = {\n screen: 'page',\n component: 'component',\n layout: 'layout',\n}\n\nexport interface AssistEditCardProps {\n proposal: AssistEditProposal\n /** The product's name as this org reads it. */\n brand: string\n /** The open editor, or `undefined` when none is open. */\n session: EditorSession | undefined\n /** Why the last attempt to apply was refused, when it was. */\n failure?: string | null\n onApply: () => void\n onCreateVersion: () => void\n onDismiss: () => void\n}\n\nexport function AssistEditCard(props: AssistEditCardProps) {\n const { proposal, brand, session, failure, onApply, onCreateVersion, onDismiss } = props\n const [showDropped, setShowDropped] = useState(false)\n const noun = DOCUMENT_NOUNS[proposal.target.kind] ?? 'document'\n const onDocument = Boolean(\n session &&\n session.documentKind === proposal.target.kind &&\n session.documentId === proposal.target.documentId,\n )\n const live = onDocument && Boolean(session?.isLiveVersion())\n const changes = describeAssistEditDiff(proposal.diff)\n // A component save creates one document (AGL-2908), which is the one thing\n // on this card that outlives an undo. The copy says so before Apply.\n const savesComponent = proposal.ops.some((op) => op.op === 'saveAsComponent')\n\n return (\n <Paper\n variant=\"outlined\"\n sx={{ mt: 1, p: 1.5, borderRadius: 2, bgcolor: 'background.paper' }}\n >\n <Typography variant=\"subtitle2\">Proposed change</Typography>\n {proposal.summary ? (\n <Typography variant=\"body2\" sx={{ mt: 0.5 }}>\n {proposal.summary}\n </Typography>\n ) : null}\n {changes.length > 0 && (\n <Stack component=\"ul\" sx={{ m: 0, mt: 1, pl: 2.5 }}>\n {changes.map((line) => (\n <Typography key={line} component=\"li\" variant=\"caption\">\n {line}\n </Typography>\n ))}\n </Stack>\n )}\n {proposal.dropped.length > 0 && (\n <Box sx={{ mt: 0.5 }}>\n <Link\n component=\"button\"\n type=\"button\"\n variant=\"caption\"\n underline=\"hover\"\n onClick={() => setShowDropped((prior) => !prior)}\n sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.25 }}\n >\n {`Left out (${proposal.dropped.length})`}\n <MdiIcon\n path={showDropped ? mdiChevronUp.path : mdiChevronDown.path}\n sx={{ fontSize: 14 }}\n />\n </Link>\n <Collapse in={showDropped} unmountOnExit>\n <Stack component=\"ul\" sx={{ m: 0, pl: 2.5 }}>\n {proposal.dropped.map((reason, index) => (\n <Typography\n key={index}\n component=\"li\"\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {reason}\n </Typography>\n ))}\n </Stack>\n </Collapse>\n </Box>\n )}\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n component=\"div\"\n sx={{ mt: 1 }}\n >\n {!onDocument\n ? `Open this ${noun} in the Besigner to apply the change.`\n : live\n ? `This is the version your live site shows. Make a new version first — the change is applied there, and the live ${noun} stays as it is.`\n : savesComponent\n ? `${brand} Assist changes nothing until you apply. Applying saves the component to your library, and swaps this element for one that follows it — an unsaved edit on the open canvas that undo takes back. Nothing is published.`\n : `${brand} Assist changes nothing until you apply. Applying adds these changes to the open canvas as unsaved edits: undo takes them back, and nothing is saved or published until you save.`}\n </Typography>\n {failure ? (\n <Alert severity=\"warning\" sx={{ mt: 1 }}>\n {failure}\n </Alert>\n ) : null}\n <Stack direction=\"row\" spacing={1} sx={{ mt: 1.5 }}>\n {onDocument && !live ? (\n <Button variant=\"contained\" size=\"small\" onClick={onApply}>\n Apply as draft\n </Button>\n ) : null}\n {onDocument && live && session?.createVersion ? (\n <Button variant=\"contained\" size=\"small\" onClick={onCreateVersion}>\n Make a new version\n </Button>\n ) : null}\n <Button size=\"small\" color=\"inherit\" onClick={onDismiss}>\n No thanks\n </Button>\n </Stack>\n </Paper>\n )\n}\n\nexport default AssistEditCard\n"],"names":["mdiChevronDown","mdiChevronUp","MdiIcon","Alert","Box","Button","Collapse","Link","Paper","Stack","Typography","useState","describeAssistEditDiff","DOCUMENT_NOUNS","screen","component","layout","AssistEditCard","props","proposal","brand","session","failure","onApply","onCreateVersion","onDismiss","showDropped","setShowDropped","noun","target","kind","onDocument","Boolean","documentKind","documentId","live","isLiveVersion","changes","diff","savesComponent","ops","some","op","variant","sx","mt","p","borderRadius","bgcolor","summary","length","m","pl","map","line","dropped","type","underline","onClick","prior","display","alignItems","gap","path","fontSize","in","unmountOnExit","reason","index","color","severity","direction","spacing","size","createVersion"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,cAAc,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MAAM,sNAAsN,CAAC,GAChO,GAAGA,MAAM,iLAAiL,CAAC;;YAEpME,wBACC,KAACnB;gBAAMmE,UAAS;gBAAU1B,IAAI;oBAAEC,IAAI;gBAAE;0BACnCvB;iBAED;0BACJ,MAACb;gBAAM8D,WAAU;gBAAMC,SAAS;gBAAG5B,IAAI;oBAAEC,IAAI;gBAAI;;oBAC9Cd,cAAc,CAACI,qBACd,KAAC9B;wBAAOsC,SAAQ;wBAAY8B,MAAK;wBAAQf,SAASnC;kCAAS;yBAGzD;oBACHQ,cAAcI,SAAQd,2BAAAA,QAASqD,aAAa,kBAC3C,KAACrE;wBAAOsC,SAAQ;wBAAY8B,MAAK;wBAAQf,SAASlC;kCAAiB;yBAGjE;kCACJ,KAACnB;wBAAOoE,MAAK;wBAAQJ,OAAM;wBAAUX,SAASjC;kCAAW;;;;;;AAMjE;AAEA,eAAeR,eAAc"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/assist-edit-card.component.tsx"],"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'use client'\n\nimport type { EditorSession } from '@aglyn/aglyn/plugin-manager/editor-sessions'\nimport { mdiChevronDown, mdiChevronUp } from '@aglyn/shared-data-mdi'\nimport { MdiIcon } from '@aglyn/shared-ui-jsx'\nimport {\n Alert,\n Box,\n Button,\n Collapse,\n Link,\n Paper,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useState } from 'react'\nimport {\n describeAssistEditDiff,\n type AssistEditDocumentKind,\n type AssistEditProposal,\n} from '../model/assist-edit'\n\n/**\n * The edit card (AGL-2906): a level-3 proposal as the author decides on it.\n *\n * It says what would change — the counts, and what validation left out —\n * and offers exactly one way forward for the editor as it stands:\n *\n * - on the document the proposal was made for: **Apply as draft**, which the\n * panel carries out through the canvas's own mutators as one undoable,\n * unsaved change. On the version the live site serves too (AGL-4116): the\n * Besigner saves that version's changes into the page's draft, never the\n * version itself, so the change is as safe there as an edit by hand, and\n * **Make a new version** is offered beside it for an author who wants the\n * change kept apart;\n * - anywhere else: nothing to press but **No thanks**.\n *\n * The card makes no request and holds no write of its own: its buttons call\n * back into the panel, which applies through the canvas and reports nothing\n * but the counts.\n */\n\nconst DOCUMENT_NOUNS: Readonly<Record<AssistEditDocumentKind, string>> = {\n screen: 'page',\n component: 'component',\n layout: 'layout',\n}\n\nexport interface AssistEditCardProps {\n proposal: AssistEditProposal\n /** The product's name as this org reads it. */\n brand: string\n /** The open editor, or `undefined` when none is open. */\n session: EditorSession | undefined\n /** Why the last attempt to apply was refused, when it was. */\n failure?: string | null\n onApply: () => void\n onCreateVersion: () => void\n onDismiss: () => void\n}\n\nexport function AssistEditCard(props: AssistEditCardProps) {\n const { proposal, brand, session, failure, onApply, onCreateVersion, onDismiss } = props\n const [showDropped, setShowDropped] = useState(false)\n const noun = DOCUMENT_NOUNS[proposal.target.kind] ?? 'document'\n const onDocument = Boolean(\n session &&\n session.documentKind === proposal.target.kind &&\n session.documentId === proposal.target.documentId,\n )\n const live = onDocument && Boolean(session?.isLiveVersion())\n const changes = describeAssistEditDiff(proposal.diff)\n // A component save creates one document (AGL-2908), which is the one thing\n // on this card that outlives an undo. The copy says so before Apply.\n const savesComponent = proposal.ops.some((op) => op.op === 'saveAsComponent')\n\n return (\n <Paper\n variant=\"outlined\"\n sx={{ mt: 1, p: 1.5, borderRadius: 2, bgcolor: 'background.paper' }}\n >\n <Typography variant=\"subtitle2\">Proposed change</Typography>\n {proposal.summary ? (\n <Typography variant=\"body2\" sx={{ mt: 0.5 }}>\n {proposal.summary}\n </Typography>\n ) : null}\n {changes.length > 0 && (\n <Stack component=\"ul\" sx={{ m: 0, mt: 1, pl: 2.5 }}>\n {changes.map((line) => (\n <Typography key={line} component=\"li\" variant=\"caption\">\n {line}\n </Typography>\n ))}\n </Stack>\n )}\n {proposal.dropped.length > 0 && (\n <Box sx={{ mt: 0.5 }}>\n <Link\n component=\"button\"\n type=\"button\"\n variant=\"caption\"\n underline=\"hover\"\n onClick={() => setShowDropped((prior) => !prior)}\n sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.25 }}\n >\n {`Left out (${proposal.dropped.length})`}\n <MdiIcon\n path={showDropped ? mdiChevronUp.path : mdiChevronDown.path}\n sx={{ fontSize: 14 }}\n />\n </Link>\n <Collapse in={showDropped} unmountOnExit>\n <Stack component=\"ul\" sx={{ m: 0, pl: 2.5 }}>\n {proposal.dropped.map((reason, index) => (\n <Typography\n key={index}\n component=\"li\"\n variant=\"caption\"\n color=\"text.secondary\"\n >\n {reason}\n </Typography>\n ))}\n </Stack>\n </Collapse>\n </Box>\n )}\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n component=\"div\"\n sx={{ mt: 1 }}\n >\n {!onDocument\n ? `Open this ${noun} in the Besigner to apply the change.`\n : live && !savesComponent\n ? `${brand} Assist changes nothing until you apply. Applying adds these changes to the open canvas as unsaved edits that undo takes back. This is the version your live site shows: Save draft keeps them in this ${noun}’s draft, and visitors see them only when you publish.`\n : savesComponent\n ? `${brand} Assist changes nothing until you apply. Applying saves the component to your library, and swaps this element for one that follows it — an unsaved edit on the open canvas that undo takes back. Nothing is published.`\n : `${brand} Assist changes nothing until you apply. Applying adds these changes to the open canvas as unsaved edits: undo takes them back, and nothing is saved or published until you save.`}\n </Typography>\n {failure ? (\n <Alert severity=\"warning\" sx={{ mt: 1 }}>\n {failure}\n </Alert>\n ) : null}\n <Stack direction=\"row\" spacing={1} sx={{ mt: 1.5 }}>\n {onDocument ? (\n <Button variant=\"contained\" size=\"small\" onClick={onApply}>\n Apply as draft\n </Button>\n ) : null}\n {onDocument && live && session?.createVersion ? (\n <Button size=\"small\" onClick={onCreateVersion}>\n Make a new version\n </Button>\n ) : null}\n <Button size=\"small\" color=\"inherit\" onClick={onDismiss}>\n No thanks\n </Button>\n </Stack>\n </Paper>\n )\n}\n\nexport default AssistEditCard\n"],"names":["mdiChevronDown","mdiChevronUp","MdiIcon","Alert","Box","Button","Collapse","Link","Paper","Stack","Typography","useState","describeAssistEditDiff","DOCUMENT_NOUNS","screen","component","layout","AssistEditCard","props","proposal","brand","session","failure","onApply","onCreateVersion","onDismiss","showDropped","setShowDropped","noun","target","kind","onDocument","Boolean","documentKind","documentId","live","isLiveVersion","changes","diff","savesComponent","ops","some","op","variant","sx","mt","p","borderRadius","bgcolor","summary","length","m","pl","map","line","dropped","type","underline","onClick","prior","display","alignItems","gap","path","fontSize","in","unmountOnExit","reason","index","color","severity","direction","spacing","size","createVersion"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,cAAc,EAAEC,YAAY,QAAQ,yBAAwB;AACrE,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,IAAI,EACJC,KAAK,EACLC,KAAK,EACLC,UAAU,QACL,gBAAe;AACtB,SAASC,QAAQ,QAAQ,QAAO;AAChC,SACEC,sBAAsB,QAGjB,0BAAsB;AAE7B;;;;;;;;;;;;;;;;;;CAkBC,GAED,MAAMC,iBAAmE;IACvEC,QAAQ;IACRC,WAAW;IACXC,QAAQ;AACV;AAeA,OAAO,SAASC,eAAeC,KAA0B;QAG1CL;IAFb,MAAM,EAAEM,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAEC,eAAe,EAAEC,SAAS,EAAE,GAAGP;IACnF,MAAM,CAACQ,aAAaC,eAAe,GAAGhB,SAAS;IAC/C,MAAMiB,QAAOf,uCAAAA,cAAc,CAACM,SAASU,MAAM,CAACC,IA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and highlighted.
77
77
  */
78
78
  focus?: AiJobsOpenRequest | null;
79
+ /**
80
+ * The AI jobs page of the site the console page is on (AGL-4116). With
81
+ * one, the list never opens inside the chat: the row counts the jobs and
82
+ * links to the page, where each has room to be read.
83
+ */
84
+ pageHref?: string | null;
79
85
  }
80
- export declare function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible, isStaff, hostId, insight, inFlight, focus, }: AssistJobsDrawerProps): JSX.Element | null;
86
+ export declare function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible, isStaff, hostId, insight, inFlight, focus, pageHref, }: AssistJobsDrawerProps): JSX.Element | null;
81
87
  export default AssistJobsDrawer;
@@ -127,7 +127,7 @@ export { aiJobOutputHref, aiJobPrimaryLink, readEventFrames };
127
127
  const label = navigation['label'];
128
128
  return typeof label === 'string' && label.trim() ? label.trim() : null;
129
129
  }
130
- export function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible, isStaff = false, hostId, insight, inFlight, focus }) {
130
+ export function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible, isStaff = false, hostId, insight, inFlight, focus, pageHref = null }) {
131
131
  var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
132
132
  const entitled = orgReady && checkEntitlement(org, 'aiGenerative');
133
133
  const [expanded, setExpanded] = useState(false);
@@ -226,11 +226,18 @@ export function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible,
226
226
  // Expanded by default while anything is moving or waiting (AGL-3593): a
227
227
  // plan waiting to be confirmed behind a collapsed row is a site that never
228
228
  // gets built. Otherwise collapsed, which reads nothing until asked.
229
+ // A site's jobs are read on its AI jobs page instead (AGL-4116).
229
230
  const anyInFlight = ((_ref = inFlight == null ? void 0 : inFlight.length) != null ? _ref : 0) > 0;
230
231
  useEffect(()=>{
231
- if (anyInFlight && !toggledRef.current) setExpanded(true);
232
+ if (anyInFlight && !toggledRef.current && !pageHref) setExpanded(true);
232
233
  }, [
233
- anyInFlight
234
+ anyInFlight,
235
+ pageHref
236
+ ]);
237
+ useEffect(()=>{
238
+ if (pageHref) setExpanded(false);
239
+ }, [
240
+ pageHref
234
241
  ]);
235
242
  // A request to open AI jobs (AGL-3593): expand, read the list again so a
236
243
  // job created a moment ago is in it, and highlight the job named.
@@ -239,7 +246,7 @@ export function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible,
239
246
  const expandedRef = useRef(expanded);
240
247
  expandedRef.current = expanded;
241
248
  useEffect(()=>{
242
- if (!focusSeq) return;
249
+ if (!focusSeq || pageHref) return;
243
250
  toggledRef.current = true;
244
251
  setHighlight(focusJobId);
245
252
  // An open list does not re-run the expand effect's read, so it reads here.
@@ -352,7 +359,9 @@ export function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible,
352
359
  if (!visible || !orgId || !entitled) return null;
353
360
  // Counted by state, never as one "running" figure (AGL-3593): a plan waiting
354
361
  // to be confirmed needs the person, and a stopped job is not moving.
355
- const chips = aiJobsHeaderChips(aiJobActivityCounts(inFlight != null ? inFlight : jobs));
362
+ // A row that links to a site's page counts that site's jobs (AGL-4116).
363
+ const counted = inFlight != null ? inFlight : jobs;
364
+ const chips = aiJobsHeaderChips(aiJobActivityCounts(pageHref && hostId ? counted.filter((job)=>job.hostId === hostId) : counted));
356
365
  return /*#__PURE__*/ _jsxs(Box, {
357
366
  sx: {
358
367
  mb: 2,
@@ -399,7 +408,12 @@ export function AssistJobsDrawer({ orgId, org, orgReady, orgSlug, user, visible,
399
408
  onClick: ()=>setDescribing(true),
400
409
  children: "Describe a page"
401
410
  }),
402
- /*#__PURE__*/ _jsx(IconButton, {
411
+ pageHref ? /*#__PURE__*/ _jsx(Button, {
412
+ size: "small",
413
+ component: AppLink,
414
+ href: pageHref,
415
+ children: 'View all'
416
+ }) : /*#__PURE__*/ _jsx(IconButton, {
403
417
  size: "small",
404
418
  "aria-label": expanded ? 'Hide AI jobs' : 'Show AI jobs',
405
419
  "aria-expanded": expanded,