@aglyn/plugins-ai 1.0.0-beta.230 → 1.0.0-beta.231

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 (139) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-assist-provider-on-host.component.d.ts +66 -0
  3. package/src/lib/components/ai-assist-provider-on-host.component.js +78 -0
  4. package/src/lib/components/ai-assist-provider-on-host.component.js.map +1 -0
  5. package/src/lib/components/ai-assist-provider.component.js +9 -10
  6. package/src/lib/components/ai-assist-provider.component.js.map +1 -1
  7. package/src/lib/components/ai-job-plan.component.js +3 -1
  8. package/src/lib/components/ai-job-plan.component.js.map +1 -1
  9. package/src/lib/components/ai-permissions-on-host.component.d.ts +3 -46
  10. package/src/lib/components/ai-permissions-on-host.component.js +5 -53
  11. package/src/lib/components/ai-permissions-on-host.component.js.map +1 -1
  12. package/src/lib/components/ai-site-build-page.component.js +20 -8
  13. package/src/lib/components/ai-site-build-page.component.js.map +1 -1
  14. package/src/lib/jobs/ai-build-unit-outcome.js +4 -2
  15. package/src/lib/jobs/ai-build-unit-outcome.js.map +1 -1
  16. package/src/lib/jobs/ai-job-auto-confirm.d.ts +8 -0
  17. package/src/lib/jobs/ai-job-auto-confirm.js +30 -6
  18. package/src/lib/jobs/ai-job-auto-confirm.js.map +1 -1
  19. package/src/lib/jobs/ai-job-build-step.js +11 -0
  20. package/src/lib/jobs/ai-job-build-step.js.map +1 -1
  21. package/src/lib/jobs/ai-job-generation.d.ts +8 -0
  22. package/src/lib/jobs/ai-job-generation.js +13 -2
  23. package/src/lib/jobs/ai-job-generation.js.map +1 -1
  24. package/src/lib/jobs/ai-job-insight-step.js +8 -1
  25. package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
  26. package/src/lib/jobs/ai-job-layout-language.d.ts +73 -0
  27. package/src/lib/jobs/ai-job-layout-language.js +194 -0
  28. package/src/lib/jobs/ai-job-layout-language.js.map +1 -0
  29. package/src/lib/jobs/ai-job-layout-site-pages.d.ts +13 -2
  30. package/src/lib/jobs/ai-job-layout-site-pages.js +18 -2
  31. package/src/lib/jobs/ai-job-layout-site-pages.js.map +1 -1
  32. package/src/lib/jobs/ai-job-layout-step.d.ts +5 -0
  33. package/src/lib/jobs/ai-job-layout-step.js +105 -5
  34. package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
  35. package/src/lib/jobs/ai-job-page-language.d.ts +149 -0
  36. package/src/lib/jobs/ai-job-page-language.js +355 -0
  37. package/src/lib/jobs/ai-job-page-language.js.map +1 -0
  38. package/src/lib/jobs/ai-job-page-sections.d.ts +37 -1
  39. package/src/lib/jobs/ai-job-page-sections.js +93 -11
  40. package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
  41. package/src/lib/jobs/ai-job-page-step.d.ts +4 -4
  42. package/src/lib/jobs/ai-job-page-step.js +105 -14
  43. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  44. package/src/lib/jobs/ai-job-plan-step.d.ts +1 -1
  45. package/src/lib/jobs/ai-job-plan-step.js +8 -2
  46. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  47. package/src/lib/jobs/ai-job-site-step.d.ts +4 -0
  48. package/src/lib/jobs/ai-job-site-step.js +20 -3
  49. package/src/lib/jobs/ai-job-site-step.js.map +1 -1
  50. package/src/lib/jobs/ai-job-workflow-step.js +2 -2
  51. package/src/lib/jobs/ai-job-workflow-step.js.map +1 -1
  52. package/src/lib/jobs/ai-jobs.d.ts +1 -1
  53. package/src/lib/jobs/ai-jobs.js +17 -8
  54. package/src/lib/jobs/ai-jobs.js.map +1 -1
  55. package/src/lib/jobs/ai-layout-full-height.d.ts +40 -0
  56. package/src/lib/jobs/ai-layout-full-height.js +82 -0
  57. package/src/lib/jobs/ai-layout-full-height.js.map +1 -0
  58. package/src/lib/jobs/ai-layout-site-facts.d.ts +54 -0
  59. package/src/lib/jobs/ai-layout-site-facts.js +153 -0
  60. package/src/lib/jobs/ai-layout-site-facts.js.map +1 -0
  61. package/src/lib/layout-language/ai-layout-compiler.d.ts +145 -0
  62. package/src/lib/layout-language/ai-layout-compiler.js +1148 -0
  63. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -0
  64. package/src/lib/layout-language/ai-layout-copy.d.ts +73 -0
  65. package/src/lib/layout-language/ai-layout-copy.js +137 -0
  66. package/src/lib/layout-language/ai-layout-copy.js.map +1 -0
  67. package/src/lib/layout-language/ai-layout-frame.d.ts +52 -0
  68. package/src/lib/layout-language/ai-layout-frame.js +457 -0
  69. package/src/lib/layout-language/ai-layout-frame.js.map +1 -0
  70. package/src/lib/layout-language/ai-layout-gaps.d.ts +63 -0
  71. package/src/lib/layout-language/ai-layout-gaps.js +345 -0
  72. package/src/lib/layout-language/ai-layout-gaps.js.map +1 -0
  73. package/src/lib/layout-language/ai-layout-language.d.ts +161 -0
  74. package/src/lib/layout-language/ai-layout-language.js +446 -0
  75. package/src/lib/layout-language/ai-layout-language.js.map +1 -0
  76. package/src/lib/layout-language/ai-layout-links.d.ts +80 -0
  77. package/src/lib/layout-language/ai-layout-links.js +109 -0
  78. package/src/lib/layout-language/ai-layout-links.js.map +1 -0
  79. package/src/lib/layout-language/ai-layout-store.d.ts +39 -0
  80. package/src/lib/layout-language/ai-layout-store.js +69 -0
  81. package/src/lib/layout-language/ai-layout-store.js.map +1 -0
  82. package/src/lib/layout-language/ai-layout-tree.d.ts +59 -0
  83. package/src/lib/layout-language/ai-layout-tree.js +84 -0
  84. package/src/lib/layout-language/ai-layout-tree.js.map +1 -0
  85. package/src/lib/lazy-widget.d.ts +45 -0
  86. package/src/lib/lazy-widget.js +53 -0
  87. package/src/lib/lazy-widget.js.map +1 -0
  88. package/src/lib/model/ai-build-job.js +2 -1
  89. package/src/lib/model/ai-build-job.js.map +1 -1
  90. package/src/lib/model/ai-build-progress.d.ts +20 -3
  91. package/src/lib/model/ai-build-progress.js +48 -6
  92. package/src/lib/model/ai-build-progress.js.map +1 -1
  93. package/src/lib/model/ai-host-publish-context.d.ts +51 -0
  94. package/src/lib/model/ai-host-publish-context.js +104 -0
  95. package/src/lib/model/ai-host-publish-context.js.map +1 -0
  96. package/src/lib/model/ai-job-activity.d.ts +22 -0
  97. package/src/lib/model/ai-job-activity.js +22 -1
  98. package/src/lib/model/ai-job-activity.js.map +1 -1
  99. package/src/lib/model/ai-job-failure-copy.d.ts +38 -1
  100. package/src/lib/model/ai-job-failure-copy.js +56 -1
  101. package/src/lib/model/ai-job-failure-copy.js.map +1 -1
  102. package/src/lib/model/ai-job-notice.d.ts +3 -1
  103. package/src/lib/model/ai-job-notice.js +31 -9
  104. package/src/lib/model/ai-job-notice.js.map +1 -1
  105. package/src/lib/model/ai-jobs.types.d.ts +19 -0
  106. package/src/lib/model/ai-jobs.types.js.map +1 -1
  107. package/src/lib/model/ai-site-build-progress.d.ts +5 -1
  108. package/src/lib/model/ai-site-build-progress.js +27 -4
  109. package/src/lib/model/ai-site-build-progress.js.map +1 -1
  110. package/src/lib/model/ai-site-job.d.ts +8 -0
  111. package/src/lib/model/ai-site-job.js +9 -0
  112. package/src/lib/model/ai-site-job.js.map +1 -1
  113. package/src/lib/model/ai-site-start-seo.d.ts +1 -1
  114. package/src/lib/model/ai-site-start.d.ts +5 -2
  115. package/src/lib/model/ai-site-start.js +5 -2
  116. package/src/lib/model/ai-site-start.js.map +1 -1
  117. package/src/lib/plugin.js +79 -47
  118. package/src/lib/plugin.js.map +1 -1
  119. package/src/lib/providers/catalog.d.ts +1 -1
  120. package/src/lib/providers/catalog.js +3 -3
  121. package/src/lib/providers/catalog.js.map +1 -1
  122. package/src/lib/runtime/ai-doctrine-validators.d.ts +82 -0
  123. package/src/lib/runtime/ai-doctrine-validators.js +436 -4
  124. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  125. package/src/lib/runtime/ai-doctrine.js +12 -3
  126. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  127. package/src/lib/runtime/ai-icon-library.d.ts +257 -0
  128. package/src/lib/runtime/ai-icon-library.js +254 -0
  129. package/src/lib/runtime/ai-icon-library.js.map +1 -0
  130. package/src/lib/runtime/ai-node-tree.d.ts +9 -0
  131. package/src/lib/runtime/ai-node-tree.js +30 -4
  132. package/src/lib/runtime/ai-node-tree.js.map +1 -1
  133. package/src/lib/runtime/ai-palette.d.ts +6 -0
  134. package/src/lib/runtime/ai-palette.generated.js +70 -0
  135. package/src/lib/runtime/ai-palette.generated.js.map +1 -1
  136. package/src/lib/runtime/ai-palette.js.map +1 -1
  137. package/src/lib/tools/ai-workflow-tool.d.ts +6 -2
  138. package/src/lib/tools/ai-workflow-tool.js +16 -14
  139. package/src/lib/tools/ai-workflow-tool.js.map +1 -1
@@ -1,4 +1,5 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
2
3
  /**
3
4
  * @license
4
5
  * Copyright 2026 Aglyn LLC
@@ -23,6 +24,7 @@ import { COMPONENT_PROP_NAME_PATTERN, REUSABLE_INSTANCE_COMPONENT_ID, REUSABLE_I
23
24
  import { createIdUrlSafe } from "@aglyn/aglyn/foundation/constants/app";
24
25
  import { CANVAS_ROOT_ELEMENT_ID } from "@aglyn/aglyn/foundation/constants/canvas";
25
26
  import { NodeType } from "@aglyn/aglyn/types/nodes";
27
+ import { AI_ICON_COMPONENT_ID, aiIconOfId } from "./ai-icon-library.js";
26
28
  import { AI_COMPONENT_VISIBILITY_PROPS, isAiComponentPropToken } from "./ai-component-bindings.js";
27
29
  import { sanitizePortableDefinition } from "@aglyn/aglyn/app-utils/node-definition-sanitizer";
28
30
  /**
@@ -644,7 +646,7 @@ export function validateAiNodeTree(input, surface, context) {
644
646
  };
645
647
  }
646
648
  function validate(input, surface, context) {
647
- var _ref;
649
+ var _ref, _definition_codeOnly;
648
650
  const definition = AI_SURFACES[surface];
649
651
  if (!definition) {
650
652
  return {
@@ -703,8 +705,11 @@ function validate(input, surface, context) {
703
705
  // is no value a dropdown, a switch, an address or a visibility directive
704
706
  // admits. Copy keeps its tokens without lifting, as the text they are.
705
707
  const definesComponent = (context == null ? void 0 : context.definesComponent) === true;
708
+ const codeBuilt = (context == null ? void 0 : context.codeBuilt) === true;
706
709
  const mediaByNodeId = new Map();
707
710
  const boundByNodeId = new Map();
711
+ // A code-built Icon's drawing, from the library by the id it names (AGL-3660).
712
+ const iconByNodeId = new Map();
708
713
  const forSanitizer = {};
709
714
  for (const [id, node] of Object.entries(nodes)){
710
715
  var _ref1;
@@ -712,6 +717,22 @@ function validate(input, surface, context) {
712
717
  forSanitizer[id] = node;
713
718
  continue;
714
719
  }
720
+ if (codeBuilt && node.componentId === AI_ICON_COMPONENT_ID) {
721
+ const _node_props = node.props, { iconId } = _node_props, props = _object_without_properties_loose(_node_props, [
722
+ "iconId"
723
+ ]);
724
+ const rest = _extends({}, props);
725
+ delete rest['iconPath'];
726
+ const icon = aiIconOfId(iconId);
727
+ if (icon) iconByNodeId.set(id, {
728
+ iconId: icon.id,
729
+ iconPath: icon.path
730
+ });
731
+ forSanitizer[id] = _extends({}, node, {
732
+ props: rest
733
+ });
734
+ continue;
735
+ }
715
736
  const entry = AI_PALETTE[String(node.componentId)];
716
737
  const roles = (_ref1 = entry == null ? void 0 : entry.propRoles) != null ? _ref1 : {};
717
738
  const props = _extends({}, node.props);
@@ -746,10 +767,14 @@ function validate(input, surface, context) {
746
767
  };
747
768
  // An instance is admitted only where the caller grounded it in the site's
748
769
  // components; the reference itself is checked on the node below.
749
- const allow = refs.componentIds && INSTANCE_SURFACES.has(surface) ? [
770
+ const surfaceAllow = codeBuilt ? [
750
771
  ...definition.allow,
751
- REUSABLE_INSTANCE_COMPONENT_ID
772
+ ...(_definition_codeOnly = definition.codeOnly) != null ? _definition_codeOnly : []
752
773
  ] : definition.allow;
774
+ const allow = refs.componentIds && INSTANCE_SURFACES.has(surface) ? [
775
+ ...surfaceAllow,
776
+ REUSABLE_INSTANCE_COMPONENT_ID
777
+ ] : surfaceAllow;
753
778
  const sanitized = sanitizePortableDefinition({
754
779
  rootId,
755
780
  nodes: forSanitizer
@@ -818,6 +843,7 @@ function validate(input, surface, context) {
818
843
  const kept = (_boundByNodeId_get = boundByNodeId.get(id)) != null ? _boundByNodeId_get : {};
819
844
  for (const key of Object.keys(raw.props)){
820
845
  var _node_props;
846
+ if (iconByNodeId.has(id) && (key === 'iconId' || key === 'iconPath')) continue;
821
847
  if (key !== 'sx' && lifted[key] === undefined && kept[key] === undefined && ((_node_props = node.props) == null ? void 0 : _node_props[key]) === undefined && raw.props[key] !== undefined) {
822
848
  repairs.push(`${id}.${key} was an unsafe handler, address or markup; dropped`);
823
849
  }
@@ -899,7 +925,7 @@ function validate(input, surface, context) {
899
925
  pluginId: entry.pluginId,
900
926
  parentId,
901
927
  nodes: children,
902
- props: _extends({}, propsResult.props, reference.kept, boundProps)
928
+ props: _extends({}, propsResult.props, reference.kept, boundProps, iconByNodeId.get(id))
903
929
  }, sx ? {
904
930
  sx
905
931
  } : {}, hiddenByNodeId.has(id) ? {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/runtime/ai-node-tree.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 AI_TEXT_LIMITS,\n isHeadlineVariant,\n nodeCapabilityProps,\n type AiPaletteEntry,\n type AiPropSchema,\n type AiSurface,\n} from './ai-palette'\nimport {\n AI_NODE_CAPABILITIES,\n AI_PALETTE,\n AI_SURFACES,\n AI_SX_TOKENS,\n} from './ai-palette.generated'\nimport { linealRelationshipPermits } from '@aglyn/aglyn/app-utils/lineal-order'\nimport {\n NODE_MAP_MAX_BYTES,\n nodeMapBytes,\n} from '@aglyn/aglyn/app-utils/measure-node-map'\nimport { parseMediaRef } from '@aglyn/aglyn/app-utils/media-ref'\nimport {\n COMPONENT_PROP_NAME_PATTERN,\n REUSABLE_INSTANCE_COMPONENT_ID,\n REUSABLE_INSTANCE_PROP_VALUES_KEY,\n} from '@aglyn/aglyn/app-utils/reusable-component-keys'\nimport { createIdUrlSafe } from '@aglyn/aglyn/foundation/constants/app'\nimport { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport { NodeType, type NodesMap } from '@aglyn/aglyn/types/nodes'\nimport type { AiComponentPropTypes } from '../model/ai-site-inventory'\nimport {\n AI_COMPONENT_VISIBILITY_PROPS,\n isAiComponentPropToken,\n} from './ai-component-bindings'\n\nimport { sanitizePortableDefinition } from '@aglyn/aglyn/app-utils/node-definition-sanitizer'\n\n/**\n * The one path an AI-emitted node tree takes into storage (AGL-2905).\n *\n * A model answers with a flat node map in the shape the canvas persists.\n * Nothing about that map is trusted: the component ids, the parent/child\n * pairs, every prop and every `sx` key are what the model chose to write,\n * and the renderer spreads props onto the DOM. So the tree is first held to\n * the same sanitizer a marketplace install passes — reachability from the\n * root, the surface's component allowlist, the persisted node keys, `href`\n * and `src` protocols, a size cap — and then to what a listing never needed\n * checking because a human authored it in the editor:\n *\n * - the parent/child restrictions the besigner enforces on drop\n * (`restrictChildren` / `restrictParent`), and whether an element can hold\n * children at all;\n * - every prop against the generated palette's schema — unknown props are\n * dropped, enum values coerced case-insensitively, a required prop that is\n * missing refuses the tree;\n * - `sx` against a fixed key set and a value grammar of theme tokens, numbers\n * and CSS lengths or keywords, with nothing that can reach a URL or a\n * stylesheet;\n * - copy length by role — a headline, a paragraph, a button label;\n * - links to a screen the host has, a root-relative path or an `https:` URL,\n * and media to a DAM reference or an `https:` URL;\n * - the stored-node-map byte ceiling, measured the way the save measures it.\n *\n * ## The site's own records, when the caller names them (AGL-2935)\n *\n * A reusable-component instance, a form picked on the Forms page and a\n * dataset are each \"a reference into another document\", which is why the\n * palette leaves them off: from a description alone a model can only invent\n * an id. A generator that has read the site's inventory can name real ones,\n * and the building doctrine requires it to — a repeat is placed as\n * instances of one component, and a form is bound by id rather than drawn\n * inline. So the three are admitted exactly as screen links are: only\n * against the ids the caller supplies. With no `componentIds` an instance is\n * still refused; with no `formIds` or `datasetIds` the binding is dropped.\n *\n * What comes out is the flat `NodesMap` `encodeStoredNodes` takes, with every\n * id minted fresh the way a preset graft mints them, so nothing the model\n * wrote can collide with a node already on the canvas. `sourceIds` maps each\n * minted id back to the id the model wrote, so a caller can quote a refused\n * subtree in the model's own words. Every drop is listed in `repairs`; every\n * refusal names its `code`. The function never throws.\n */\n\nexport type AiNodeTreeRefusalCode =\n /** Not an object with a `rootId` and a `nodes` map, or an unknown surface. */\n | 'invalid-input'\n /** The root node carries a component the surface does not start with. */\n | 'root'\n /** A structural failure the sanitizer named: missing node, empty tree. */\n | 'structure'\n /** A component id outside the surface's allowlist. */\n | 'component'\n /** A parent/child pair the besigner would refuse on drop. */\n | 'lineage'\n /** A prop the palette marks required is absent. */\n | 'required-prop'\n /** Over the sanitizer's or the stored-node-map's byte ceiling. */\n | 'too-large'\n /** A component instance naming a component the site does not have. */\n | 'reference'\n\nexport type AiNodeTreeResult =\n | {\n ok: true\n rootId: string\n nodes: NodesMap\n repairs: string[]\n /** Each minted id → the id the model wrote for that node. */\n sourceIds: Record<string, string>\n }\n | { ok: false; error: string; code: AiNodeTreeRefusalCode }\n\nexport interface AiNodeTreeContext {\n /** Screen ids a `screen` prop may name. Absent: any well-formed id. */\n screenIds?: Iterable<string>\n /** DAM media ids a `media` prop may reference. Absent: any well-formed reference. */\n assetIds?: Iterable<string>\n /**\n * Reusable components an instance may place. Absent: no instance is\n * admitted, which is the palette's own rule for a tree nobody grounded.\n */\n componentIds?: Iterable<string>\n /** Declared props per component id, which an instance's values are held to. */\n componentProps?: Record<string, AiComponentPropTypes>\n /** Forms on the Forms page a Form element may bind by `formId`. */\n formIds?: Iterable<string>\n /** Datasets a Form element may write to by `datasetId`. */\n datasetIds?: Iterable<string>\n /**\n * Binding tokens a `url` or `media` prop may hold whole — an Image whose\n * `src` is `{{entry.coverImage}}` on a page template, filled per record\n * when the page renders (AGL-2909). Absent: a token in either role is\n * dropped like any other value that is not an address.\n */\n bindingTokens?: Iterable<string>\n /**\n * The tree defines a reusable component (AGL-2908). A field that is not\n * copy — a switch, a dropdown, a screen, an address, a picture, a number —\n * and the `hideIf` and `hideUnless` directives may then hold one of the\n * component's own `{{prop.<name>}}` tokens as their whole value, and a\n * placed component may be handed one in its `propValues`; each is kept as\n * written. Which property a token names, and whether its kind binds to that\n * field, is the component step's check (`ai-component-bindings.ts`).\n * Absent: such a token is dropped like any value the field cannot hold.\n */\n definesComponent?: boolean\n}\n\n/**\n * `sx` keys a model may set: spacing, color, typography, layout, borders,\n * display, flex and grid. Fixed rather than derived — MUI's system accepts\n * far more (pseudo-selectors, nested selectors, arbitrary CSS properties)\n * and every one of those is a way to reach outside the element.\n */\nexport const AI_SX_ALLOWED_KEYS: ReadonlySet<string> = new Set([\n // spacing\n 'm',\n 'mt',\n 'mr',\n 'mb',\n 'ml',\n 'mx',\n 'my',\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'p',\n 'pt',\n 'pr',\n 'pb',\n 'pl',\n 'px',\n 'py',\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'gap',\n 'rowGap',\n 'columnGap',\n // color\n 'color',\n 'bgcolor',\n 'backgroundColor',\n 'borderColor',\n 'opacity',\n // typography\n 'typography',\n 'fontSize',\n 'fontWeight',\n 'fontFamily',\n 'fontStyle',\n 'lineHeight',\n 'letterSpacing',\n 'textAlign',\n 'textTransform',\n 'textDecoration',\n 'whiteSpace',\n 'textOverflow',\n 'overflowWrap',\n 'wordBreak',\n // layout\n 'width',\n 'minWidth',\n 'maxWidth',\n 'height',\n 'minHeight',\n 'maxHeight',\n 'boxSizing',\n 'overflow',\n 'overflowX',\n 'overflowY',\n 'position',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'zIndex',\n 'aspectRatio',\n 'objectFit',\n // borders\n 'border',\n 'borderTop',\n 'borderRight',\n 'borderBottom',\n 'borderLeft',\n 'borderWidth',\n 'borderStyle',\n 'borderRadius',\n 'boxShadow',\n // display\n 'display',\n 'visibility',\n // flex\n 'flexDirection',\n 'flexWrap',\n 'justifyContent',\n 'alignItems',\n 'alignContent',\n 'alignSelf',\n 'justifySelf',\n 'flex',\n 'flexGrow',\n 'flexShrink',\n 'flexBasis',\n 'order',\n // grid\n 'gridTemplateColumns',\n 'gridTemplateRows',\n 'gridColumn',\n 'gridRow',\n 'gridArea',\n 'gridAutoFlow',\n 'gridAutoColumns',\n 'gridAutoRows',\n 'justifyItems',\n 'placeItems',\n 'placeContent',\n])\n\n/**\n * Substrings no string a model wrote may carry, in a prop or an `sx` value.\n * Exported for the theme tool's component style values (AGL-2938), which are\n * the same kind of CSS value written into a theme instead of a node.\n */\nexport const HOSTILE_TEXT =\n /<\\s*\\/?\\s*(script|iframe|object|embed|svg|style|link|meta|base|frame|form|input|img)\\b|javascript:|vbscript:|data:text\\/html|expression\\s*\\(|url\\s*\\(|@import|!important|\\bon[a-z]+\\s*=/i\n\n/**\n * A CSS value a model may write into `sx`: lengths, numbers, keywords,\n * shorthands (`1px solid`), functions with plain arguments (`repeat(3, 1fr)`,\n * `rgba(0, 0, 0, 0.2)`), hex colors and theme tokens. No quotes, no\n * semicolons, no braces, no angle brackets, no colons — which is what keeps\n * a `url(`, a selector or a second declaration out.\n */\nexport const SX_VALUE = /^[A-Za-z0-9#.,%()\\s\\-_/+*]{1,100}$/\n\n/**\n * Node fields the sanitizer strips that a model has no business writing —\n * each is a way to reach past the node's own box, and each is named in\n * `repairs` so a route can tell the model what it lost.\n */\nconst STRIPPED_NODE_KEYS = [\n 'className',\n 'interactions',\n 'styleOverrides',\n 'attrOverrides',\n 'presetRef',\n] as const\n\nconst SCREEN_ID = /^[A-Za-z0-9_-]{1,64}$/\n/** The field an icon is picked with; its value carries a drawing no model can write. */\nconst ICON_PICKER_FIELD = 'icon-picker'\nconst MAX_SX_KEYS = 40\n/** A string prop with no role of its own — a color, a CSS length, an icon id. */\nconst PLAIN_STRING_MAX = 500\n\nconst paletteTokens = new Set<string>(AI_SX_TOKENS.palette)\nconst breakpoints = new Set<string>(AI_SX_TOKENS.breakpoints)\nconst typographyVariants = new Set<string>(AI_SX_TOKENS.typographyVariants)\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** An `https:` address that parses as one. */\nexport function isHttpsUrl(value: string): boolean {\n if (!/^https:\\/\\//i.test(value)) return false\n try {\n return new URL(value).protocol === 'https:'\n } catch {\n return false\n }\n}\n\n/** A path on this site: one leading slash, never a scheme-relative `//`. */\nexport function isRootRelativePath(value: string): boolean {\n return /^\\/(?!\\/)[^\\s<>\"'`\\\\]*$/.test(value)\n}\n\nfunction sxValueAllowed(key: string, value: unknown): boolean {\n if (typeof value === 'number') return Number.isFinite(value)\n if (typeof value !== 'string') return false\n const trimmed = value.trim()\n if (!trimmed || HOSTILE_TEXT.test(trimmed)) return false\n if (paletteTokens.has(trimmed)) return true\n if (key === 'typography' && typographyVariants.has(trimmed)) return true\n return SX_VALUE.test(trimmed)\n}\n\n/**\n * The allowed slice of an `sx` object, with a line per key or value dropped.\n * Responsive objects keep only breakpoint keys; anything deeper — a\n * pseudo-selector, a nested selector, an array — is not a value at all.\n */\nfunction sanitizeSx(\n nodeId: string,\n sx: unknown,\n repairs: string[],\n): Record<string, unknown> | undefined {\n if (!isRecord(sx)) {\n if (sx !== undefined)\n repairs.push(`${nodeId}: sx is not an object; dropped`)\n return undefined\n }\n const out: Record<string, unknown> = {}\n let kept = 0\n for (const [key, value] of Object.entries(sx)) {\n if (!AI_SX_ALLOWED_KEYS.has(key)) {\n repairs.push(`${nodeId}: sx.${key} is not an allowed style; dropped`)\n continue\n }\n if (kept >= MAX_SX_KEYS) {\n repairs.push(\n `${nodeId}: sx.${key} is past the ${MAX_SX_KEYS}-key ceiling; dropped`,\n )\n continue\n }\n if (isRecord(value)) {\n const responsive: Record<string, unknown> = {}\n for (const [breakpoint, inner] of Object.entries(value)) {\n if (!breakpoints.has(breakpoint)) {\n repairs.push(\n `${nodeId}: sx.${key}.${breakpoint} is not a breakpoint; dropped`,\n )\n continue\n }\n if (!sxValueAllowed(key, inner)) {\n repairs.push(\n `${nodeId}: sx.${key}.${breakpoint} is not an allowed value; dropped`,\n )\n continue\n }\n responsive[breakpoint] =\n typeof inner === 'string' ? inner.trim() : inner\n }\n if (Object.keys(responsive).length) {\n out[key] = responsive\n kept += 1\n }\n continue\n }\n if (!sxValueAllowed(key, value)) {\n repairs.push(`${nodeId}: sx.${key} is not an allowed value; dropped`)\n continue\n }\n out[key] = typeof value === 'string' ? value.trim() : value\n kept += 1\n }\n return kept ? out : undefined\n}\n\nfunction coerceEnum(schema: AiPropSchema, value: unknown): string | undefined {\n if (typeof value !== 'string' || !schema.enum) return undefined\n const wanted = value.trim().toLowerCase()\n return schema.enum.find((option) => option.toLowerCase() === wanted)\n}\n\nfunction coerceBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') return value\n if (value === 'true') return true\n if (value === 'false') return false\n return undefined\n}\n\nfunction coerceNumber(\n schema: AiPropSchema,\n value: unknown,\n): number | undefined {\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.trim() !== ''\n ? Number(value)\n : NaN\n if (!Number.isFinite(parsed)) return undefined\n if (schema.type === 'integer' && !Number.isInteger(parsed)) return undefined\n if (schema.minimum !== undefined && parsed < schema.minimum) return undefined\n if (schema.maximum !== undefined && parsed > schema.maximum) return undefined\n return parsed\n}\n\nfunction textLimitFor(\n entry: AiPaletteEntry,\n name: string,\n props: Record<string, unknown>,\n): number {\n const declared = entry.textLimits[name]\n // A heading's copy is held to the headline ceiling, decided by the variant\n // the same node carries; anything else keeps the ceiling the palette\n // assigned to the prop.\n if (name === 'children' && isHeadlineVariant(props.variant)) {\n return Math.min(declared ?? AI_TEXT_LIMITS.body, AI_TEXT_LIMITS.headline)\n }\n return declared ?? AI_TEXT_LIMITS.body\n}\n\n/**\n * One string prop against its role. Returns the value to store, or\n * `undefined` with the reason pushed to `repairs`. A binding token the\n * caller admitted passes a `url` or `media` role whole.\n */\nfunction sanitizeString(\n nodeId: string,\n entry: AiPaletteEntry,\n name: string,\n schema: AiPropSchema,\n raw: string,\n props: Record<string, unknown>,\n screenIds: Set<string> | null,\n assetIds: Set<string> | null,\n repairs: string[],\n bindingTokens: ReadonlySet<string> | null = null,\n): string | undefined {\n let value = raw.trim()\n if (HOSTILE_TEXT.test(value)) {\n repairs.push(`${nodeId}.${name} carried markup or script; dropped`)\n return undefined\n }\n // An icon is drawn from the path its picker stores beside the id, which a\n // model can never supply, so an icon a model names draws nothing where the\n // page is published (AGL-3054). The site owner picks it.\n if (entry.propFields[name] === ICON_PICKER_FIELD) {\n repairs.push(`${nodeId}.${name} is an icon, which the site owner picks from the library; dropped`)\n return undefined\n }\n const role = entry.propRoles[name]\n switch (role) {\n case 'text': {\n const limit = textLimitFor(entry, name, props)\n if (value.length > limit) {\n value = value.slice(0, limit).trimEnd()\n repairs.push(\n `${nodeId}.${name} was over ${limit} characters; truncated`,\n )\n }\n break\n }\n case 'url': {\n if (bindingTokens?.has(value)) break\n if (!isHttpsUrl(value) && !isRootRelativePath(value)) {\n repairs.push(\n `${nodeId}.${name} is neither an https: URL nor a path on this site; dropped`,\n )\n return undefined\n }\n break\n }\n case 'screen': {\n if (screenIds ? !screenIds.has(value) : !SCREEN_ID.test(value)) {\n repairs.push(\n `${nodeId}.${name} names a page this site does not have; dropped`,\n )\n return undefined\n }\n break\n }\n case 'media': {\n if (bindingTokens?.has(value)) break\n if (isHttpsUrl(value)) break\n const ref = parseMediaRef(value)\n if (!ref || (assetIds && !assetIds.has(ref.mediaId))) {\n repairs.push(\n `${nodeId}.${name} is neither a media reference this site holds nor an https: URL; dropped`,\n )\n return undefined\n }\n break\n }\n default: {\n if (value.length > PLAIN_STRING_MAX) {\n repairs.push(\n `${nodeId}.${name} is over ${PLAIN_STRING_MAX} characters; dropped`,\n )\n return undefined\n }\n }\n }\n if (schema.pattern && !new RegExp(schema.pattern).test(value)) {\n repairs.push(`${nodeId}.${name} does not match its pattern; dropped`)\n return undefined\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) {\n repairs.push(\n `${nodeId}.${name} is shorter than ${schema.minLength} characters; dropped`,\n )\n return undefined\n }\n if (schema.maxLength !== undefined && value.length > schema.maxLength) {\n value = value.slice(0, schema.maxLength).trimEnd()\n repairs.push(\n `${nodeId}.${name} was over ${schema.maxLength} characters; truncated`,\n )\n }\n return value\n}\n\n/**\n * The element's own declarations plus the node capabilities every element\n * carries (AGL-3156) — repeating, today. Two shapes only, so they are built\n * once each rather than per node: a capability prop is the same on every\n * element with the same child contract.\n *\n * The element wins a name collision. A component that declared a prop of its\n * own under a capability's name would be describing its own attribute, and the\n * validator has to hold it to that.\n */\nconst CAPABLE_ENTRIES = new WeakMap<AiPaletteEntry, AiPaletteEntry>()\n\nfunction withNodeCapabilities(entry: AiPaletteEntry): AiPaletteEntry {\n const cached = CAPABLE_ENTRIES.get(entry)\n if (cached) return cached\n const capability = nodeCapabilityProps(\n AI_NODE_CAPABILITIES,\n entry.acceptsChildren,\n )\n const merged: AiPaletteEntry = {\n ...entry,\n propsSchema: {\n ...entry.propsSchema,\n properties: {\n ...capability.properties,\n ...entry.propsSchema.properties,\n },\n },\n propRoles: { ...capability.propRoles, ...entry.propRoles },\n textLimits: { ...capability.textLimits, ...entry.textLimits },\n }\n CAPABLE_ENTRIES.set(entry, merged)\n return merged\n}\n\nfunction sanitizeProps(\n nodeId: string,\n paletteEntry: AiPaletteEntry,\n raw: unknown,\n screenIds: Set<string> | null,\n assetIds: Set<string> | null,\n repairs: string[],\n bindingTokens: ReadonlySet<string> | null = null,\n): { props: Record<string, unknown> } | { missing: string } {\n const entry = withNodeCapabilities(paletteEntry)\n const source = isRecord(raw) ? raw : {}\n const props: Record<string, unknown> = {}\n const declared = entry.propsSchema.properties\n for (const [name, value] of Object.entries(source)) {\n // `sx` is read off the node instead; a model that put it here meant the\n // same thing, and the caller has already moved it.\n if (name === 'sx' || value === undefined || value === null) continue\n const schema = declared[name]\n if (!schema) {\n repairs.push(\n `${nodeId}.${name} is not a prop of ${entry.displayName}; dropped`,\n )\n continue\n }\n if (schema.enum) {\n const coerced = coerceEnum(schema, value)\n if (coerced === undefined) {\n repairs.push(\n `${nodeId}.${name} is not one of ${schema.enum.join('|')}; dropped`,\n )\n continue\n }\n if (coerced !== value) {\n repairs.push(\n `${nodeId}.${name} was spelled \"${String(value)}\"; normalized to \"${coerced}\"`,\n )\n }\n props[name] = coerced\n continue\n }\n switch (schema.type) {\n case 'boolean': {\n const coerced = coerceBoolean(value)\n if (coerced === undefined) {\n repairs.push(`${nodeId}.${name} is not a boolean; dropped`)\n continue\n }\n props[name] = coerced\n break\n }\n case 'number':\n case 'integer': {\n const coerced = coerceNumber(schema, value)\n if (coerced === undefined) {\n repairs.push(`${nodeId}.${name} is not a number in range; dropped`)\n continue\n }\n props[name] = coerced\n break\n }\n default: {\n const text =\n typeof value === 'string'\n ? value\n : typeof value === 'number' || typeof value === 'boolean'\n ? String(value)\n : undefined\n if (text === undefined) {\n repairs.push(`${nodeId}.${name} is not text; dropped`)\n continue\n }\n const cleaned = sanitizeString(\n nodeId,\n entry,\n name,\n schema,\n text,\n source,\n screenIds,\n assetIds,\n repairs,\n bindingTokens,\n )\n if (cleaned === undefined) continue\n props[name] = cleaned\n }\n }\n }\n for (const name of entry.propsSchema.required) {\n if (props[name] === undefined) return { missing: name }\n }\n return { props }\n}\n\n/** Surfaces that compose page elements, and so may place a component instance. */\nconst INSTANCE_SURFACES: ReadonlySet<AiSurface> = new Set([\n 'screen',\n 'layout',\n 'component',\n])\n\nconst FORM_COMPONENT_ID = 'form'\n\n/** The instance prop naming the component it places; stored on every instance node. */\nexport const AI_INSTANCE_REF_PROP = 'refId'\n\ninterface ReferenceSets {\n componentIds: Set<string> | null\n componentProps: Record<string, AiComponentPropTypes>\n formIds: Set<string> | null\n datasetIds: Set<string> | null\n assetIds: Set<string> | null\n /** The tree defines a reusable component, which may hand its own property tokens on. */\n definesComponent: boolean\n}\n\n/**\n * One value an instance fills in for a declared prop, held to what the\n * declaration's type can hold: a picture from the library, a link, a number,\n * a switch, or copy.\n */\nfunction instancePropValue(\n nodeId: string,\n name: string,\n type: string,\n raw: unknown,\n assetIds: Set<string> | null,\n repairs: string[],\n): unknown {\n if (type === 'number') {\n const parsed = typeof raw === 'number' ? raw : Number(raw)\n if (raw === '' || !Number.isFinite(parsed)) {\n repairs.push(`${nodeId}.propValues.${name} is not a number; dropped`)\n return undefined\n }\n return parsed\n }\n if (type === 'boolean') {\n const coerced = coerceBoolean(raw)\n if (coerced === undefined) {\n repairs.push(`${nodeId}.propValues.${name} is not a boolean; dropped`)\n }\n return coerced\n }\n if (type === 'icon') {\n // A page cannot fill an icon: the pick is an id and the path drawn from\n // it, and a word in its place draws nothing (AGL-3054). The property is\n // left for the site owner to pick.\n repairs.push(`${nodeId}.propValues.${name} is an icon, which the site owner picks from the library; dropped`)\n return undefined\n }\n if (typeof raw !== 'string' && typeof raw !== 'number' && typeof raw !== 'boolean') {\n repairs.push(`${nodeId}.propValues.${name} is not a value; dropped`)\n return undefined\n }\n const value = String(raw).trim()\n if (HOSTILE_TEXT.test(value)) {\n repairs.push(`${nodeId}.propValues.${name} carried markup or script; dropped`)\n return undefined\n }\n if (type === 'image') {\n if (isHttpsUrl(value)) return value\n const ref = parseMediaRef(value)\n if (!ref || (assetIds && !assetIds.has(ref.mediaId))) {\n repairs.push(\n `${nodeId}.propValues.${name} is neither a media reference this site holds nor an https: URL; dropped`,\n )\n return undefined\n }\n return value\n }\n if (type === 'href') {\n if (isHttpsUrl(value) || isRootRelativePath(value)) return value\n repairs.push(\n `${nodeId}.propValues.${name} is neither an https: URL nor a path on this site; dropped`,\n )\n return undefined\n }\n if (value.length > AI_TEXT_LIMITS.body) {\n repairs.push(\n `${nodeId}.propValues.${name} was over ${AI_TEXT_LIMITS.body} characters; truncated`,\n )\n return value.slice(0, AI_TEXT_LIMITS.body).trimEnd()\n }\n return value\n}\n\n/**\n * The site-record props of one node — an instance's `refId` and\n * `propValues`, a Form's `formId` and `datasetId` — checked against the ids\n * the caller supplied. They leave `props` before the palette pass, which\n * would drop them as undeclared, and come back in `kept` once checked.\n */\nfunction sanitizeReferenceProps(\n nodeId: string,\n componentId: string,\n props: Record<string, unknown>,\n refs: ReferenceSets,\n repairs: string[],\n): { props: Record<string, unknown>; kept: Record<string, unknown> } | { refusal: string } {\n const rest: Record<string, unknown> = { ...props }\n const kept: Record<string, unknown> = {}\n if (componentId === REUSABLE_INSTANCE_COMPONENT_ID) {\n const refId = typeof rest[AI_INSTANCE_REF_PROP] === 'string' ? String(rest[AI_INSTANCE_REF_PROP]).trim() : ''\n delete rest[AI_INSTANCE_REF_PROP]\n if (!refId || !refs.componentIds?.has(refId)) {\n return {\n refusal: `Reusable Component (${nodeId}) names a component this site does not have`,\n }\n }\n kept[AI_INSTANCE_REF_PROP] = refId\n const rawValues = rest[REUSABLE_INSTANCE_PROP_VALUES_KEY]\n delete rest[REUSABLE_INSTANCE_PROP_VALUES_KEY]\n if (rawValues !== undefined && !isRecord(rawValues)) {\n repairs.push(`${nodeId}.propValues is not an object; dropped`)\n }\n const declared = refs.componentProps[refId]\n const values: Record<string, unknown> = {}\n for (const [name, raw] of Object.entries(isRecord(rawValues) ? rawValues : {})) {\n if (raw === undefined || raw === null) continue\n if (!COMPONENT_PROP_NAME_PATTERN.test(name)) {\n repairs.push(`${nodeId}.propValues.${name} is not a prop name; dropped`)\n continue\n }\n if (declared && !(name in declared)) {\n repairs.push(`${nodeId}.propValues.${name} is not a prop of that component; dropped`)\n continue\n }\n if (refs.definesComponent && isAiComponentPropToken(raw)) {\n // A property of the component being defined, handed on whole; the\n // component step's check holds it to the kind this prop declares.\n values[name] = raw.trim()\n continue\n }\n const value = instancePropValue(\n nodeId,\n name,\n declared?.[name] ?? 'text',\n raw,\n refs.assetIds,\n repairs,\n )\n if (value !== undefined) values[name] = value\n }\n if (Object.keys(values).length) kept[REUSABLE_INSTANCE_PROP_VALUES_KEY] = values\n return { props: rest, kept }\n }\n if (componentId === FORM_COMPONENT_ID) {\n const bindings: Array<[prop: string, ids: Set<string> | null, record: string]> = [\n ['formId', refs.formIds, 'form'],\n ['datasetId', refs.datasetIds, 'dataset'],\n ]\n for (const [prop, ids, record] of bindings) {\n const raw = rest[prop]\n delete rest[prop]\n if (raw === undefined || raw === null || raw === '') continue\n const id = typeof raw === 'string' ? raw.trim() : ''\n if (id && ids?.has(id)) {\n kept[prop] = id\n } else {\n repairs.push(`${nodeId}.${prop} names a ${record} this site does not have; dropped`)\n }\n }\n }\n return { props: rest, kept }\n}\n\nfunction refusalCode(error: string): AiNodeTreeRefusalCode {\n if (/too large/i.test(error)) return 'too-large'\n if (/cannot be published/i.test(error)) return 'component'\n return 'structure'\n}\n\n/**\n * Whether the root the model wrote is the surface's root: the canvas wrapper\n * for a document surface (which the sanitizer exempts by the same shape), or\n * the named component otherwise.\n */\nfunction rootMatches(surfaceRoot: string, componentId: unknown): boolean {\n if (surfaceRoot === 'div') {\n return componentId == null || componentId === '' || componentId === 'div'\n }\n return componentId === surfaceRoot\n}\n\nexport function validateAiNodeTree(\n input: unknown,\n surface: AiSurface,\n context?: AiNodeTreeContext,\n): AiNodeTreeResult {\n try {\n return validate(input, surface, context)\n } catch (error) {\n return {\n ok: false,\n code: 'invalid-input',\n error: `The tree could not be read: ${error instanceof Error ? error.message : String(error)}`,\n }\n }\n}\n\nexport type AiNodePatchResult =\n | {\n ok: true\n props: Record<string, unknown>\n sx: Record<string, unknown> | undefined\n repairs: string[]\n }\n | { ok: false; error: string; code: AiNodeTreeRefusalCode }\n\n/**\n * One element's prop and style patch, held to the rules `validateAiNodeTree`\n * holds an element it places — for an edit to an element already on the\n * canvas, where there is no tree to validate.\n *\n * The same passes run: unknown props dropped, enums coerced, every string\n * held to its role and screened for markup, `sx` held to the key set and the\n * value grammar. The one difference is `required`: a patch is merged over the\n * props the element already has, so a required prop the patch does not name\n * is not missing.\n */\nexport function validateAiNodePatch(\n componentId: string,\n patch: { props?: unknown; sx?: unknown },\n context?: AiNodeTreeContext,\n): AiNodePatchResult {\n const entry = AI_PALETTE[componentId]\n if (!entry) {\n return {\n ok: false,\n code: 'component',\n error: `Component \"${componentId}\" is not in the palette`,\n }\n }\n const repairs: string[] = []\n const props = sanitizeProps(\n componentId,\n { ...entry, propsSchema: { ...entry.propsSchema, required: [] } },\n patch.props,\n context?.screenIds ? new Set(context.screenIds) : null,\n context?.assetIds ? new Set(context.assetIds) : null,\n repairs,\n )\n const sx =\n patch.sx === undefined ? undefined : sanitizeSx(componentId, patch.sx, repairs)\n return {\n ok: true,\n props: 'props' in props ? props.props : {},\n sx,\n repairs,\n }\n}\n\nfunction validate(\n input: unknown,\n surface: AiSurface,\n context: AiNodeTreeContext | undefined,\n): AiNodeTreeResult {\n const definition = AI_SURFACES[surface]\n if (!definition) {\n return {\n ok: false,\n code: 'invalid-input',\n error: `Unknown surface \"${surface}\"`,\n }\n }\n if (\n !isRecord(input) ||\n typeof input.rootId !== 'string' ||\n !isRecord(input.nodes)\n ) {\n return {\n ok: false,\n code: 'invalid-input',\n error: 'Expected an object with a string rootId and a nodes map',\n }\n }\n const rootId = input.rootId\n const nodes = input.nodes as Record<string, unknown>\n const root = nodes[rootId]\n if (!isRecord(root)) {\n return {\n ok: false,\n code: 'structure',\n error: 'Definition has no root node',\n }\n }\n if (!rootMatches(definition.root, root.componentId)) {\n return {\n ok: false,\n code: 'root',\n error: `A ${surface} starts with ${definition.root === 'div' ? 'the document wrapper' : `\"${definition.root}\"`}, not \"${String(root.componentId)}\"`,\n }\n }\n\n // The sanitizer keeps only the persisted node keys, and `sx` is not one of\n // them for a listing. Read it off every node first — from the node field\n // or from `props.sx`, which a model writes just as readily — and put it\n // back, checked, on the nodes that survive.\n const sxByNodeId = new Map<string, unknown>()\n const hiddenByNodeId = new Set<string>()\n for (const [id, node] of Object.entries(nodes)) {\n if (!isRecord(node)) continue\n const sx =\n node.sx !== undefined\n ? node.sx\n : isRecord(node.props)\n ? node.props.sx\n : undefined\n if (sx !== undefined) sxByNodeId.set(id, sx)\n if (node.hidden === true) hiddenByNodeId.add(id)\n }\n\n // A DAM reference (a `media:` value) is not a URL the sanitizer's\n // `src` policy admits — a listing must not carry another tenant's asset —\n // but on the tenant's own page it is exactly what an image should name.\n // Lift those values out before sanitizing and hand them back to the prop\n // pass, which holds them to the asset set the caller supplied.\n // A binding token the caller admitted (AGL-2909) is lifted the same way:\n // `{{entry.coverImage}}` is no address the sanitizer knows, and the prop\n // pass holds it to the tokens the caller named.\n const bindingTokens = context?.bindingTokens ? new Set(context.bindingTokens) : null\n // A reusable component's own property tokens (AGL-2908) are lifted too, and\n // kept as written rather than handed back to the prop pass: `{{prop.variant}}`\n // is no value a dropdown, a switch, an address or a visibility directive\n // admits. Copy keeps its tokens without lifting, as the text they are.\n const definesComponent = context?.definesComponent === true\n const mediaByNodeId = new Map<string, Record<string, string>>()\n const boundByNodeId = new Map<string, Record<string, string>>()\n const forSanitizer: Record<string, unknown> = {}\n for (const [id, node] of Object.entries(nodes)) {\n if (!isRecord(node) || !isRecord(node.props)) {\n forSanitizer[id] = node\n continue\n }\n const entry = AI_PALETTE[String(node.componentId)]\n const roles = entry?.propRoles ?? {}\n const props: Record<string, unknown> = { ...node.props }\n const lifted: Record<string, string> = {}\n const bound: Record<string, string> = {}\n for (const [key, value] of Object.entries(props)) {\n if (typeof value !== 'string') continue\n const role = roles[key]\n if (\n definesComponent &&\n isAiComponentPropToken(value) &&\n (AI_COMPONENT_VISIBILITY_PROPS.includes(key) ||\n (entry?.propsSchema.properties[key] !== undefined && role !== 'text'))\n ) {\n bound[key] = value.trim()\n delete props[key]\n continue\n }\n if (\n (role === 'media' && parseMediaRef(value.trim())) ||\n ((role === 'media' || role === 'url') && bindingTokens?.has(value.trim()))\n ) {\n lifted[key] = value\n delete props[key]\n }\n }\n if (Object.keys(lifted).length) mediaByNodeId.set(id, lifted)\n if (Object.keys(bound).length) boundByNodeId.set(id, bound)\n forSanitizer[id] = { ...node, props }\n }\n\n const refs: ReferenceSets = {\n componentIds: context?.componentIds ? new Set(context.componentIds) : null,\n componentProps: context?.componentProps ?? {},\n formIds: context?.formIds ? new Set(context.formIds) : null,\n datasetIds: context?.datasetIds ? new Set(context.datasetIds) : null,\n assetIds: context?.assetIds ? new Set(context.assetIds) : null,\n definesComponent,\n }\n // An instance is admitted only where the caller grounded it in the site's\n // components; the reference itself is checked on the node below.\n const allow =\n refs.componentIds && INSTANCE_SURFACES.has(surface)\n ? [...definition.allow, REUSABLE_INSTANCE_COMPONENT_ID]\n : definition.allow\n const sanitized = sanitizePortableDefinition(\n { rootId, nodes: forSanitizer },\n { componentIds: allow },\n )\n if (sanitized.ok === false) {\n return {\n ok: false,\n code: refusalCode(sanitized.error),\n error: sanitized.error,\n }\n }\n\n const screenIds = context?.screenIds ? new Set(context.screenIds) : null\n const assetIds = refs.assetIds\n const repairs: string[] = []\n const output: NodesMap = {}\n const rootIsWrapper =\n rootMatches('div', root.componentId) && definition.root === 'div'\n const minted = new Map<string, string>()\n const mint = (id: string): string => {\n const fresh =\n id === rootId && rootIsWrapper\n ? CANVAS_ROOT_ELEMENT_ID\n : createIdUrlSafe()\n minted.set(id, fresh)\n return fresh\n }\n\n /** Each visited node's parent by the model's own ids, for the parentId check. */\n const parentOf = new Map<string, string>()\n const queue: Array<{ id: string; parentId: string | null }> = [\n { id: rootId, parentId: null },\n ]\n mint(rootId)\n while (queue.length) {\n const { id, parentId } = queue.shift() as {\n id: string\n parentId: string | null\n }\n const node = sanitized.nodes[id]\n const entry = AI_PALETTE[node.componentId]\n if (!entry) {\n return {\n ok: false,\n code: 'component',\n error: `Component \"${node.componentId}\" is not in the palette`,\n }\n }\n const newId = minted.get(id) as string\n const raw = nodes[id]\n if (isRecord(raw)) {\n // The sanitizer drops silently; the model is told what went.\n for (const key of STRIPPED_NODE_KEYS) {\n if (raw[key] !== undefined) {\n repairs.push(\n `${id}.${key} is not something a generated node may set; dropped`,\n )\n }\n }\n if (raw.hidden !== undefined && typeof raw.hidden !== 'boolean') {\n repairs.push(`${id}.hidden is not a boolean; dropped`)\n }\n if (raw.nodes !== undefined && !Array.isArray(raw.nodes)) {\n repairs.push(\n `${id}.nodes is not a list of child ids; its children were dropped`,\n )\n }\n if (\n raw.parentId !== undefined &&\n raw.parentId !== null &&\n raw.parentId !== (parentId === null ? null : parentOf.get(id))\n ) {\n repairs.push(\n `${id}.parentId disagreed with where the tree places it; recomputed`,\n )\n }\n if (isRecord(raw.props)) {\n const lifted = mediaByNodeId.get(id) ?? {}\n const kept = boundByNodeId.get(id) ?? {}\n for (const key of Object.keys(raw.props)) {\n if (\n key !== 'sx' &&\n lifted[key] === undefined &&\n kept[key] === undefined &&\n node.props?.[key] === undefined &&\n raw.props[key] !== undefined\n ) {\n repairs.push(\n `${id}.${key} was an unsafe handler, address or markup; dropped`,\n )\n }\n }\n }\n }\n const children: string[] = []\n for (const childId of node.nodes ?? []) {\n if (minted.has(childId)) {\n repairs.push(\n `${childId} was listed under more than one parent; the later listing was dropped`,\n )\n continue\n }\n const child = sanitized.nodes[childId]\n if (!child) continue\n const childEntry = AI_PALETTE[child.componentId]\n if (!childEntry) {\n return {\n ok: false,\n code: 'component',\n error: `Component \"${child.componentId}\" is not in the palette`,\n }\n }\n if (!entry.acceptsChildren) {\n return {\n ok: false,\n code: 'lineage',\n error: `${entry.displayName} (${id}) cannot hold other elements, but lists ${childId}`,\n }\n }\n if (\n !linealRelationshipPermits(\n {\n componentId: child.componentId,\n pluginId: childEntry.pluginId,\n restrictParent: childEntry.restrictParent,\n },\n {\n componentId: node.componentId,\n pluginId: entry.pluginId,\n restrictChildren: entry.restrictChildren,\n },\n )\n ) {\n return {\n ok: false,\n code: 'lineage',\n error: `${childEntry.displayName} (${childId}) cannot be placed inside ${entry.displayName} (${id})`,\n }\n }\n children.push(mint(childId))\n parentOf.set(childId, id)\n queue.push({ id: childId, parentId: newId })\n }\n\n const reference = sanitizeReferenceProps(\n id,\n node.componentId,\n { ...node.props, ...mediaByNodeId.get(id) },\n refs,\n repairs,\n )\n if ('refusal' in reference) {\n return { ok: false, code: 'reference', error: reference.refusal }\n }\n // A required prop the component binds is present: its value is the token.\n const boundProps = boundByNodeId.get(id)\n const propsResult = sanitizeProps(\n id,\n boundProps\n ? {\n ...entry,\n propsSchema: {\n ...entry.propsSchema,\n required: entry.propsSchema.required.filter((name) => boundProps[name] === undefined),\n },\n }\n : entry,\n reference.props,\n screenIds,\n assetIds,\n repairs,\n bindingTokens,\n )\n if ('missing' in propsResult) {\n return {\n ok: false,\n code: 'required-prop',\n error: `${entry.displayName} (${id}) is missing its required \"${propsResult.missing}\" prop`,\n }\n }\n const sx = sanitizeSx(id, sxByNodeId.get(id), repairs)\n output[newId] = {\n $id: newId,\n type: NodeType.NODE,\n componentId: node.componentId,\n pluginId: entry.pluginId,\n parentId,\n nodes: children,\n props: { ...propsResult.props, ...reference.kept, ...boundProps },\n ...(sx ? { sx } : {}),\n ...(hiddenByNodeId.has(id) ? { hidden: true } : {}),\n }\n }\n\n // The save's own measurement (msgpack), not a JSON string length: the\n // ceiling is stated in those bytes, and a UTF-16 length reads multi-byte\n // copy as smaller than the document the save will refuse.\n const bytes = nodeMapBytes(output)\n if (bytes > NODE_MAP_MAX_BYTES) {\n return {\n ok: false,\n code: 'too-large',\n error: `The tree is ${bytes} bytes; the stored ceiling is ${NODE_MAP_MAX_BYTES}`,\n }\n }\n const sourceIds: Record<string, string> = {}\n for (const [source, fresh] of minted) sourceIds[fresh] = source\n return {\n ok: true,\n rootId: minted.get(rootId) as string,\n nodes: output,\n repairs,\n sourceIds,\n }\n}\n"],"names":["AI_TEXT_LIMITS","isHeadlineVariant","nodeCapabilityProps","AI_NODE_CAPABILITIES","AI_PALETTE","AI_SURFACES","AI_SX_TOKENS","linealRelationshipPermits","NODE_MAP_MAX_BYTES","nodeMapBytes","parseMediaRef","COMPONENT_PROP_NAME_PATTERN","REUSABLE_INSTANCE_COMPONENT_ID","REUSABLE_INSTANCE_PROP_VALUES_KEY","createIdUrlSafe","CANVAS_ROOT_ELEMENT_ID","NodeType","AI_COMPONENT_VISIBILITY_PROPS","isAiComponentPropToken","sanitizePortableDefinition","AI_SX_ALLOWED_KEYS","Set","HOSTILE_TEXT","SX_VALUE","STRIPPED_NODE_KEYS","SCREEN_ID","ICON_PICKER_FIELD","MAX_SX_KEYS","PLAIN_STRING_MAX","paletteTokens","palette","breakpoints","typographyVariants","isRecord","value","Array","isArray","isHttpsUrl","test","URL","protocol","isRootRelativePath","sxValueAllowed","key","Number","isFinite","trimmed","trim","has","sanitizeSx","nodeId","sx","repairs","undefined","push","out","kept","Object","entries","responsive","breakpoint","inner","keys","length","coerceEnum","schema","enum","wanted","toLowerCase","find","option","coerceBoolean","coerceNumber","parsed","NaN","type","isInteger","minimum","maximum","textLimitFor","entry","name","props","declared","textLimits","variant","Math","min","body","headline","sanitizeString","raw","screenIds","assetIds","bindingTokens","propFields","role","propRoles","limit","slice","trimEnd","ref","mediaId","pattern","RegExp","minLength","maxLength","CAPABLE_ENTRIES","WeakMap","withNodeCapabilities","cached","get","capability","acceptsChildren","merged","propsSchema","properties","set","sanitizeProps","paletteEntry","source","displayName","coerced","join","String","text","cleaned","required","missing","INSTANCE_SURFACES","FORM_COMPONENT_ID","AI_INSTANCE_REF_PROP","instancePropValue","sanitizeReferenceProps","componentId","refs","rest","refId","componentIds","refusal","rawValues","componentProps","values","definesComponent","bindings","formIds","datasetIds","prop","ids","record","id","refusalCode","error","rootMatches","surfaceRoot","validateAiNodeTree","input","surface","context","validate","ok","code","Error","message","validateAiNodePatch","patch","definition","rootId","nodes","root","sxByNodeId","Map","hiddenByNodeId","node","hidden","add","mediaByNodeId","boundByNodeId","forSanitizer","roles","lifted","bound","includes","allow","sanitized","output","rootIsWrapper","minted","mint","fresh","parentOf","queue","parentId","shift","newId","children","childId","child","childEntry","pluginId","restrictParent","restrictChildren","reference","boundProps","propsResult","filter","$id","NODE","bytes","sourceIds"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,QAId,kBAAc;AACrB,SACEC,oBAAoB,EACpBC,UAAU,EACVC,WAAW,EACXC,YAAY,QACP,4BAAwB;AAC/B,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SACEC,kBAAkB,EAClBC,YAAY,QACP,0CAAyC;AAChD,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SACEC,2BAA2B,EAC3BC,8BAA8B,EAC9BC,iCAAiC,QAC5B,iDAAgD;AACvD,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,sBAAsB,QAAQ,2CAA0C;AACjF,SAASC,QAAQ,QAAuB,2BAA0B;AAElE,SACEC,6BAA6B,EAC7BC,sBAAsB,QACjB,6BAAyB;AAEhC,SAASC,0BAA0B,QAAQ,mDAAkD;AAiH7F;;;;;CAKC,GACD,OAAO,MAAMC,qBAA0C,IAAIC,IAAI;IAC7D,UAAU;IACV;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,QAAQ;IACR;IACA;IACA;IACA;IACA;IACA,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,SAAS;IACT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAC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AAM,GAAG;YACdY,KAAKZ;YACLvH,MAAM3D,SAAS+L,IAAI;YACnBzE,aAAauC,KAAKvC,WAAW;YAC7BiE,UAAUvH,MAAMuH,QAAQ;YACxBP;YACAxB,OAAO2B;YACPjH,OAAO,aAAK0H,YAAY1H,KAAK,EAAKwH,UAAUlJ,IAAI,EAAKmJ;WACjDxJ,KAAK;YAAEA;QAAG,IAAI,CAAC,GACfyH,eAAe5H,GAAG,CAACsG,MAAM;YAAEwB,QAAQ;QAAK,IAAI,CAAC;IAErD;IAEA,sEAAsE;IACtE,yEAAyE;IACzE,0DAA0D;IAC1D,MAAMkC,QAAQvM,aAAagL;IAC3B,IAAIuB,QAAQxM,oBAAoB;QAC9B,OAAO;YACLwJ,IAAI;YACJC,MAAM;YACNT,OAAO,CAAC,YAAY,EAAEwD,MAAM,8BAA8B,EAAExM,oBAAoB;QAClF;IACF;IACA,MAAMyM,YAAoC,CAAC;IAC3C,KAAK,MAAM,CAACzF,QAAQqE,MAAM,IAAIF,OAAQsB,SAAS,CAACpB,MAAM,GAAGrE;IACzD,OAAO;QACLwC,IAAI;QACJO,QAAQoB,OAAO5E,GAAG,CAACwD;QACnBC,OAAOiB;QACPrI;QACA6J;IACF;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/runtime/ai-node-tree.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 AI_TEXT_LIMITS,\n isHeadlineVariant,\n nodeCapabilityProps,\n type AiPaletteEntry,\n type AiPropSchema,\n type AiSurface,\n} from './ai-palette'\nimport {\n AI_NODE_CAPABILITIES,\n AI_PALETTE,\n AI_SURFACES,\n AI_SX_TOKENS,\n} from './ai-palette.generated'\nimport { linealRelationshipPermits } from '@aglyn/aglyn/app-utils/lineal-order'\nimport {\n NODE_MAP_MAX_BYTES,\n nodeMapBytes,\n} from '@aglyn/aglyn/app-utils/measure-node-map'\nimport { parseMediaRef } from '@aglyn/aglyn/app-utils/media-ref'\nimport {\n COMPONENT_PROP_NAME_PATTERN,\n REUSABLE_INSTANCE_COMPONENT_ID,\n REUSABLE_INSTANCE_PROP_VALUES_KEY,\n} from '@aglyn/aglyn/app-utils/reusable-component-keys'\nimport { createIdUrlSafe } from '@aglyn/aglyn/foundation/constants/app'\nimport { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport { NodeType, type NodesMap } from '@aglyn/aglyn/types/nodes'\nimport type { AiComponentPropTypes } from '../model/ai-site-inventory'\nimport { AI_ICON_COMPONENT_ID, aiIconOfId } from './ai-icon-library'\nimport {\n AI_COMPONENT_VISIBILITY_PROPS,\n isAiComponentPropToken,\n} from './ai-component-bindings'\n\nimport { sanitizePortableDefinition } from '@aglyn/aglyn/app-utils/node-definition-sanitizer'\n\n/**\n * The one path an AI-emitted node tree takes into storage (AGL-2905).\n *\n * A model answers with a flat node map in the shape the canvas persists.\n * Nothing about that map is trusted: the component ids, the parent/child\n * pairs, every prop and every `sx` key are what the model chose to write,\n * and the renderer spreads props onto the DOM. So the tree is first held to\n * the same sanitizer a marketplace install passes — reachability from the\n * root, the surface's component allowlist, the persisted node keys, `href`\n * and `src` protocols, a size cap — and then to what a listing never needed\n * checking because a human authored it in the editor:\n *\n * - the parent/child restrictions the besigner enforces on drop\n * (`restrictChildren` / `restrictParent`), and whether an element can hold\n * children at all;\n * - every prop against the generated palette's schema — unknown props are\n * dropped, enum values coerced case-insensitively, a required prop that is\n * missing refuses the tree;\n * - `sx` against a fixed key set and a value grammar of theme tokens, numbers\n * and CSS lengths or keywords, with nothing that can reach a URL or a\n * stylesheet;\n * - copy length by role — a headline, a paragraph, a button label;\n * - links to a screen the host has, a root-relative path or an `https:` URL,\n * and media to a DAM reference or an `https:` URL;\n * - the stored-node-map byte ceiling, measured the way the save measures it.\n *\n * ## The site's own records, when the caller names them (AGL-2935)\n *\n * A reusable-component instance, a form picked on the Forms page and a\n * dataset are each \"a reference into another document\", which is why the\n * palette leaves them off: from a description alone a model can only invent\n * an id. A generator that has read the site's inventory can name real ones,\n * and the building doctrine requires it to — a repeat is placed as\n * instances of one component, and a form is bound by id rather than drawn\n * inline. So the three are admitted exactly as screen links are: only\n * against the ids the caller supplies. With no `componentIds` an instance is\n * still refused; with no `formIds` or `datasetIds` the binding is dropped.\n *\n * What comes out is the flat `NodesMap` `encodeStoredNodes` takes, with every\n * id minted fresh the way a preset graft mints them, so nothing the model\n * wrote can collide with a node already on the canvas. `sourceIds` maps each\n * minted id back to the id the model wrote, so a caller can quote a refused\n * subtree in the model's own words. Every drop is listed in `repairs`; every\n * refusal names its `code`. The function never throws.\n */\n\nexport type AiNodeTreeRefusalCode =\n /** Not an object with a `rootId` and a `nodes` map, or an unknown surface. */\n | 'invalid-input'\n /** The root node carries a component the surface does not start with. */\n | 'root'\n /** A structural failure the sanitizer named: missing node, empty tree. */\n | 'structure'\n /** A component id outside the surface's allowlist. */\n | 'component'\n /** A parent/child pair the besigner would refuse on drop. */\n | 'lineage'\n /** A prop the palette marks required is absent. */\n | 'required-prop'\n /** Over the sanitizer's or the stored-node-map's byte ceiling. */\n | 'too-large'\n /** A component instance naming a component the site does not have. */\n | 'reference'\n\nexport type AiNodeTreeResult =\n | {\n ok: true\n rootId: string\n nodes: NodesMap\n repairs: string[]\n /** Each minted id → the id the model wrote for that node. */\n sourceIds: Record<string, string>\n }\n | { ok: false; error: string; code: AiNodeTreeRefusalCode }\n\nexport interface AiNodeTreeContext {\n /** Screen ids a `screen` prop may name. Absent: any well-formed id. */\n screenIds?: Iterable<string>\n /** DAM media ids a `media` prop may reference. Absent: any well-formed reference. */\n assetIds?: Iterable<string>\n /**\n * Reusable components an instance may place. Absent: no instance is\n * admitted, which is the palette's own rule for a tree nobody grounded.\n */\n componentIds?: Iterable<string>\n /** Declared props per component id, which an instance's values are held to. */\n componentProps?: Record<string, AiComponentPropTypes>\n /** Forms on the Forms page a Form element may bind by `formId`. */\n formIds?: Iterable<string>\n /** Datasets a Form element may write to by `datasetId`. */\n datasetIds?: Iterable<string>\n /**\n * Binding tokens a `url` or `media` prop may hold whole — an Image whose\n * `src` is `{{entry.coverImage}}` on a page template, filled per record\n * when the page renders (AGL-2909). Absent: a token in either role is\n * dropped like any other value that is not an address.\n */\n bindingTokens?: Iterable<string>\n /**\n * The tree defines a reusable component (AGL-2908). A field that is not\n * copy — a switch, a dropdown, a screen, an address, a picture, a number —\n * and the `hideIf` and `hideUnless` directives may then hold one of the\n * component's own `{{prop.<name>}}` tokens as their whole value, and a\n * placed component may be handed one in its `propValues`; each is kept as\n * written. Which property a token names, and whether its kind binds to that\n * field, is the component step's check (`ai-component-bindings.ts`).\n * Absent: such a token is dropped like any value the field cannot hold.\n */\n definesComponent?: boolean\n /**\n * The tree was composed by the platform's own code — the layout language\n * compiler (AGL-3660) — and not written by a model. The surface's code-only\n * elements are then admitted (an Icon, and a layout's Drawer with its Menu\n * Button), and an Icon keeps the id and the path the icon library gives\n * the id it names (`ai-icon-library.ts`): the path is the library's, never\n * the tree's. Absent: a model's tree, held to the surface's catalog.\n */\n codeBuilt?: boolean\n}\n\n/**\n * `sx` keys a model may set: spacing, color, typography, layout, borders,\n * display, flex and grid. Fixed rather than derived — MUI's system accepts\n * far more (pseudo-selectors, nested selectors, arbitrary CSS properties)\n * and every one of those is a way to reach outside the element.\n */\nexport const AI_SX_ALLOWED_KEYS: ReadonlySet<string> = new Set([\n // spacing\n 'm',\n 'mt',\n 'mr',\n 'mb',\n 'ml',\n 'mx',\n 'my',\n 'margin',\n 'marginTop',\n 'marginRight',\n 'marginBottom',\n 'marginLeft',\n 'p',\n 'pt',\n 'pr',\n 'pb',\n 'pl',\n 'px',\n 'py',\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'gap',\n 'rowGap',\n 'columnGap',\n // color\n 'color',\n 'bgcolor',\n 'backgroundColor',\n 'borderColor',\n 'opacity',\n // typography\n 'typography',\n 'fontSize',\n 'fontWeight',\n 'fontFamily',\n 'fontStyle',\n 'lineHeight',\n 'letterSpacing',\n 'textAlign',\n 'textTransform',\n 'textDecoration',\n 'whiteSpace',\n 'textOverflow',\n 'overflowWrap',\n 'wordBreak',\n // layout\n 'width',\n 'minWidth',\n 'maxWidth',\n 'height',\n 'minHeight',\n 'maxHeight',\n 'boxSizing',\n 'overflow',\n 'overflowX',\n 'overflowY',\n 'position',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'zIndex',\n 'aspectRatio',\n 'objectFit',\n // borders\n 'border',\n 'borderTop',\n 'borderRight',\n 'borderBottom',\n 'borderLeft',\n 'borderWidth',\n 'borderStyle',\n 'borderRadius',\n 'boxShadow',\n // display\n 'display',\n 'visibility',\n // flex\n 'flexDirection',\n 'flexWrap',\n 'justifyContent',\n 'alignItems',\n 'alignContent',\n 'alignSelf',\n 'justifySelf',\n 'flex',\n 'flexGrow',\n 'flexShrink',\n 'flexBasis',\n 'order',\n // grid\n 'gridTemplateColumns',\n 'gridTemplateRows',\n 'gridColumn',\n 'gridRow',\n 'gridArea',\n 'gridAutoFlow',\n 'gridAutoColumns',\n 'gridAutoRows',\n 'justifyItems',\n 'placeItems',\n 'placeContent',\n])\n\n/**\n * Substrings no string a model wrote may carry, in a prop or an `sx` value.\n * Exported for the theme tool's component style values (AGL-2938), which are\n * the same kind of CSS value written into a theme instead of a node.\n */\nexport const HOSTILE_TEXT =\n /<\\s*\\/?\\s*(script|iframe|object|embed|svg|style|link|meta|base|frame|form|input|img)\\b|javascript:|vbscript:|data:text\\/html|expression\\s*\\(|url\\s*\\(|@import|!important|\\bon[a-z]+\\s*=/i\n\n/**\n * A CSS value a model may write into `sx`: lengths, numbers, keywords,\n * shorthands (`1px solid`), functions with plain arguments (`repeat(3, 1fr)`,\n * `rgba(0, 0, 0, 0.2)`), hex colors and theme tokens. No quotes, no\n * semicolons, no braces, no angle brackets, no colons — which is what keeps\n * a `url(`, a selector or a second declaration out.\n */\nexport const SX_VALUE = /^[A-Za-z0-9#.,%()\\s\\-_/+*]{1,100}$/\n\n/**\n * Node fields the sanitizer strips that a model has no business writing —\n * each is a way to reach past the node's own box, and each is named in\n * `repairs` so a route can tell the model what it lost.\n */\nconst STRIPPED_NODE_KEYS = [\n 'className',\n 'interactions',\n 'styleOverrides',\n 'attrOverrides',\n 'presetRef',\n] as const\n\nconst SCREEN_ID = /^[A-Za-z0-9_-]{1,64}$/\n/** The field an icon is picked with; its value carries a drawing no model can write. */\nconst ICON_PICKER_FIELD = 'icon-picker'\nconst MAX_SX_KEYS = 40\n/** A string prop with no role of its own — a color, a CSS length, an icon id. */\nconst PLAIN_STRING_MAX = 500\n\nconst paletteTokens = new Set<string>(AI_SX_TOKENS.palette)\nconst breakpoints = new Set<string>(AI_SX_TOKENS.breakpoints)\nconst typographyVariants = new Set<string>(AI_SX_TOKENS.typographyVariants)\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** An `https:` address that parses as one. */\nexport function isHttpsUrl(value: string): boolean {\n if (!/^https:\\/\\//i.test(value)) return false\n try {\n return new URL(value).protocol === 'https:'\n } catch {\n return false\n }\n}\n\n/** A path on this site: one leading slash, never a scheme-relative `//`. */\nexport function isRootRelativePath(value: string): boolean {\n return /^\\/(?!\\/)[^\\s<>\"'`\\\\]*$/.test(value)\n}\n\nfunction sxValueAllowed(key: string, value: unknown): boolean {\n if (typeof value === 'number') return Number.isFinite(value)\n if (typeof value !== 'string') return false\n const trimmed = value.trim()\n if (!trimmed || HOSTILE_TEXT.test(trimmed)) return false\n if (paletteTokens.has(trimmed)) return true\n if (key === 'typography' && typographyVariants.has(trimmed)) return true\n return SX_VALUE.test(trimmed)\n}\n\n/**\n * The allowed slice of an `sx` object, with a line per key or value dropped.\n * Responsive objects keep only breakpoint keys; anything deeper — a\n * pseudo-selector, a nested selector, an array — is not a value at all.\n */\nfunction sanitizeSx(\n nodeId: string,\n sx: unknown,\n repairs: string[],\n): Record<string, unknown> | undefined {\n if (!isRecord(sx)) {\n if (sx !== undefined)\n repairs.push(`${nodeId}: sx is not an object; dropped`)\n return undefined\n }\n const out: Record<string, unknown> = {}\n let kept = 0\n for (const [key, value] of Object.entries(sx)) {\n if (!AI_SX_ALLOWED_KEYS.has(key)) {\n repairs.push(`${nodeId}: sx.${key} is not an allowed style; dropped`)\n continue\n }\n if (kept >= MAX_SX_KEYS) {\n repairs.push(\n `${nodeId}: sx.${key} is past the ${MAX_SX_KEYS}-key ceiling; dropped`,\n )\n continue\n }\n if (isRecord(value)) {\n const responsive: Record<string, unknown> = {}\n for (const [breakpoint, inner] of Object.entries(value)) {\n if (!breakpoints.has(breakpoint)) {\n repairs.push(\n `${nodeId}: sx.${key}.${breakpoint} is not a breakpoint; dropped`,\n )\n continue\n }\n if (!sxValueAllowed(key, inner)) {\n repairs.push(\n `${nodeId}: sx.${key}.${breakpoint} is not an allowed value; dropped`,\n )\n continue\n }\n responsive[breakpoint] =\n typeof inner === 'string' ? inner.trim() : inner\n }\n if (Object.keys(responsive).length) {\n out[key] = responsive\n kept += 1\n }\n continue\n }\n if (!sxValueAllowed(key, value)) {\n repairs.push(`${nodeId}: sx.${key} is not an allowed value; dropped`)\n continue\n }\n out[key] = typeof value === 'string' ? value.trim() : value\n kept += 1\n }\n return kept ? out : undefined\n}\n\nfunction coerceEnum(schema: AiPropSchema, value: unknown): string | undefined {\n if (typeof value !== 'string' || !schema.enum) return undefined\n const wanted = value.trim().toLowerCase()\n return schema.enum.find((option) => option.toLowerCase() === wanted)\n}\n\nfunction coerceBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') return value\n if (value === 'true') return true\n if (value === 'false') return false\n return undefined\n}\n\nfunction coerceNumber(\n schema: AiPropSchema,\n value: unknown,\n): number | undefined {\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string' && value.trim() !== ''\n ? Number(value)\n : NaN\n if (!Number.isFinite(parsed)) return undefined\n if (schema.type === 'integer' && !Number.isInteger(parsed)) return undefined\n if (schema.minimum !== undefined && parsed < schema.minimum) return undefined\n if (schema.maximum !== undefined && parsed > schema.maximum) return undefined\n return parsed\n}\n\nfunction textLimitFor(\n entry: AiPaletteEntry,\n name: string,\n props: Record<string, unknown>,\n): number {\n const declared = entry.textLimits[name]\n // A heading's copy is held to the headline ceiling, decided by the variant\n // the same node carries; anything else keeps the ceiling the palette\n // assigned to the prop.\n if (name === 'children' && isHeadlineVariant(props.variant)) {\n return Math.min(declared ?? AI_TEXT_LIMITS.body, AI_TEXT_LIMITS.headline)\n }\n return declared ?? AI_TEXT_LIMITS.body\n}\n\n/**\n * One string prop against its role. Returns the value to store, or\n * `undefined` with the reason pushed to `repairs`. A binding token the\n * caller admitted passes a `url` or `media` role whole.\n */\nfunction sanitizeString(\n nodeId: string,\n entry: AiPaletteEntry,\n name: string,\n schema: AiPropSchema,\n raw: string,\n props: Record<string, unknown>,\n screenIds: Set<string> | null,\n assetIds: Set<string> | null,\n repairs: string[],\n bindingTokens: ReadonlySet<string> | null = null,\n): string | undefined {\n let value = raw.trim()\n if (HOSTILE_TEXT.test(value)) {\n repairs.push(`${nodeId}.${name} carried markup or script; dropped`)\n return undefined\n }\n // An icon is drawn from the path its picker stores beside the id, which a\n // model can never supply, so an icon a model names draws nothing where the\n // page is published (AGL-3054). The site owner picks it.\n if (entry.propFields[name] === ICON_PICKER_FIELD) {\n repairs.push(`${nodeId}.${name} is an icon, which the site owner picks from the library; dropped`)\n return undefined\n }\n const role = entry.propRoles[name]\n switch (role) {\n case 'text': {\n const limit = textLimitFor(entry, name, props)\n if (value.length > limit) {\n value = value.slice(0, limit).trimEnd()\n repairs.push(\n `${nodeId}.${name} was over ${limit} characters; truncated`,\n )\n }\n break\n }\n case 'url': {\n if (bindingTokens?.has(value)) break\n if (!isHttpsUrl(value) && !isRootRelativePath(value)) {\n repairs.push(\n `${nodeId}.${name} is neither an https: URL nor a path on this site; dropped`,\n )\n return undefined\n }\n break\n }\n case 'screen': {\n if (screenIds ? !screenIds.has(value) : !SCREEN_ID.test(value)) {\n repairs.push(\n `${nodeId}.${name} names a page this site does not have; dropped`,\n )\n return undefined\n }\n break\n }\n case 'media': {\n if (bindingTokens?.has(value)) break\n if (isHttpsUrl(value)) break\n const ref = parseMediaRef(value)\n if (!ref || (assetIds && !assetIds.has(ref.mediaId))) {\n repairs.push(\n `${nodeId}.${name} is neither a media reference this site holds nor an https: URL; dropped`,\n )\n return undefined\n }\n break\n }\n default: {\n if (value.length > PLAIN_STRING_MAX) {\n repairs.push(\n `${nodeId}.${name} is over ${PLAIN_STRING_MAX} characters; dropped`,\n )\n return undefined\n }\n }\n }\n if (schema.pattern && !new RegExp(schema.pattern).test(value)) {\n repairs.push(`${nodeId}.${name} does not match its pattern; dropped`)\n return undefined\n }\n if (schema.minLength !== undefined && value.length < schema.minLength) {\n repairs.push(\n `${nodeId}.${name} is shorter than ${schema.minLength} characters; dropped`,\n )\n return undefined\n }\n if (schema.maxLength !== undefined && value.length > schema.maxLength) {\n value = value.slice(0, schema.maxLength).trimEnd()\n repairs.push(\n `${nodeId}.${name} was over ${schema.maxLength} characters; truncated`,\n )\n }\n return value\n}\n\n/**\n * The element's own declarations plus the node capabilities every element\n * carries (AGL-3156) — repeating, today. Two shapes only, so they are built\n * once each rather than per node: a capability prop is the same on every\n * element with the same child contract.\n *\n * The element wins a name collision. A component that declared a prop of its\n * own under a capability's name would be describing its own attribute, and the\n * validator has to hold it to that.\n */\nconst CAPABLE_ENTRIES = new WeakMap<AiPaletteEntry, AiPaletteEntry>()\n\nfunction withNodeCapabilities(entry: AiPaletteEntry): AiPaletteEntry {\n const cached = CAPABLE_ENTRIES.get(entry)\n if (cached) return cached\n const capability = nodeCapabilityProps(\n AI_NODE_CAPABILITIES,\n entry.acceptsChildren,\n )\n const merged: AiPaletteEntry = {\n ...entry,\n propsSchema: {\n ...entry.propsSchema,\n properties: {\n ...capability.properties,\n ...entry.propsSchema.properties,\n },\n },\n propRoles: { ...capability.propRoles, ...entry.propRoles },\n textLimits: { ...capability.textLimits, ...entry.textLimits },\n }\n CAPABLE_ENTRIES.set(entry, merged)\n return merged\n}\n\nfunction sanitizeProps(\n nodeId: string,\n paletteEntry: AiPaletteEntry,\n raw: unknown,\n screenIds: Set<string> | null,\n assetIds: Set<string> | null,\n repairs: string[],\n bindingTokens: ReadonlySet<string> | null = null,\n): { props: Record<string, unknown> } | { missing: string } {\n const entry = withNodeCapabilities(paletteEntry)\n const source = isRecord(raw) ? raw : {}\n const props: Record<string, unknown> = {}\n const declared = entry.propsSchema.properties\n for (const [name, value] of Object.entries(source)) {\n // `sx` is read off the node instead; a model that put it here meant the\n // same thing, and the caller has already moved it.\n if (name === 'sx' || value === undefined || value === null) continue\n const schema = declared[name]\n if (!schema) {\n repairs.push(\n `${nodeId}.${name} is not a prop of ${entry.displayName}; dropped`,\n )\n continue\n }\n if (schema.enum) {\n const coerced = coerceEnum(schema, value)\n if (coerced === undefined) {\n repairs.push(\n `${nodeId}.${name} is not one of ${schema.enum.join('|')}; dropped`,\n )\n continue\n }\n if (coerced !== value) {\n repairs.push(\n `${nodeId}.${name} was spelled \"${String(value)}\"; normalized to \"${coerced}\"`,\n )\n }\n props[name] = coerced\n continue\n }\n switch (schema.type) {\n case 'boolean': {\n const coerced = coerceBoolean(value)\n if (coerced === undefined) {\n repairs.push(`${nodeId}.${name} is not a boolean; dropped`)\n continue\n }\n props[name] = coerced\n break\n }\n case 'number':\n case 'integer': {\n const coerced = coerceNumber(schema, value)\n if (coerced === undefined) {\n repairs.push(`${nodeId}.${name} is not a number in range; dropped`)\n continue\n }\n props[name] = coerced\n break\n }\n default: {\n const text =\n typeof value === 'string'\n ? value\n : typeof value === 'number' || typeof value === 'boolean'\n ? String(value)\n : undefined\n if (text === undefined) {\n repairs.push(`${nodeId}.${name} is not text; dropped`)\n continue\n }\n const cleaned = sanitizeString(\n nodeId,\n entry,\n name,\n schema,\n text,\n source,\n screenIds,\n assetIds,\n repairs,\n bindingTokens,\n )\n if (cleaned === undefined) continue\n props[name] = cleaned\n }\n }\n }\n for (const name of entry.propsSchema.required) {\n if (props[name] === undefined) return { missing: name }\n }\n return { props }\n}\n\n/** Surfaces that compose page elements, and so may place a component instance. */\nconst INSTANCE_SURFACES: ReadonlySet<AiSurface> = new Set([\n 'screen',\n 'layout',\n 'component',\n])\n\nconst FORM_COMPONENT_ID = 'form'\n\n/** The instance prop naming the component it places; stored on every instance node. */\nexport const AI_INSTANCE_REF_PROP = 'refId'\n\ninterface ReferenceSets {\n componentIds: Set<string> | null\n componentProps: Record<string, AiComponentPropTypes>\n formIds: Set<string> | null\n datasetIds: Set<string> | null\n assetIds: Set<string> | null\n /** The tree defines a reusable component, which may hand its own property tokens on. */\n definesComponent: boolean\n}\n\n/**\n * One value an instance fills in for a declared prop, held to what the\n * declaration's type can hold: a picture from the library, a link, a number,\n * a switch, or copy.\n */\nfunction instancePropValue(\n nodeId: string,\n name: string,\n type: string,\n raw: unknown,\n assetIds: Set<string> | null,\n repairs: string[],\n): unknown {\n if (type === 'number') {\n const parsed = typeof raw === 'number' ? raw : Number(raw)\n if (raw === '' || !Number.isFinite(parsed)) {\n repairs.push(`${nodeId}.propValues.${name} is not a number; dropped`)\n return undefined\n }\n return parsed\n }\n if (type === 'boolean') {\n const coerced = coerceBoolean(raw)\n if (coerced === undefined) {\n repairs.push(`${nodeId}.propValues.${name} is not a boolean; dropped`)\n }\n return coerced\n }\n if (type === 'icon') {\n // A page cannot fill an icon: the pick is an id and the path drawn from\n // it, and a word in its place draws nothing (AGL-3054). The property is\n // left for the site owner to pick.\n repairs.push(`${nodeId}.propValues.${name} is an icon, which the site owner picks from the library; dropped`)\n return undefined\n }\n if (typeof raw !== 'string' && typeof raw !== 'number' && typeof raw !== 'boolean') {\n repairs.push(`${nodeId}.propValues.${name} is not a value; dropped`)\n return undefined\n }\n const value = String(raw).trim()\n if (HOSTILE_TEXT.test(value)) {\n repairs.push(`${nodeId}.propValues.${name} carried markup or script; dropped`)\n return undefined\n }\n if (type === 'image') {\n if (isHttpsUrl(value)) return value\n const ref = parseMediaRef(value)\n if (!ref || (assetIds && !assetIds.has(ref.mediaId))) {\n repairs.push(\n `${nodeId}.propValues.${name} is neither a media reference this site holds nor an https: URL; dropped`,\n )\n return undefined\n }\n return value\n }\n if (type === 'href') {\n if (isHttpsUrl(value) || isRootRelativePath(value)) return value\n repairs.push(\n `${nodeId}.propValues.${name} is neither an https: URL nor a path on this site; dropped`,\n )\n return undefined\n }\n if (value.length > AI_TEXT_LIMITS.body) {\n repairs.push(\n `${nodeId}.propValues.${name} was over ${AI_TEXT_LIMITS.body} characters; truncated`,\n )\n return value.slice(0, AI_TEXT_LIMITS.body).trimEnd()\n }\n return value\n}\n\n/**\n * The site-record props of one node — an instance's `refId` and\n * `propValues`, a Form's `formId` and `datasetId` — checked against the ids\n * the caller supplied. They leave `props` before the palette pass, which\n * would drop them as undeclared, and come back in `kept` once checked.\n */\nfunction sanitizeReferenceProps(\n nodeId: string,\n componentId: string,\n props: Record<string, unknown>,\n refs: ReferenceSets,\n repairs: string[],\n): { props: Record<string, unknown>; kept: Record<string, unknown> } | { refusal: string } {\n const rest: Record<string, unknown> = { ...props }\n const kept: Record<string, unknown> = {}\n if (componentId === REUSABLE_INSTANCE_COMPONENT_ID) {\n const refId = typeof rest[AI_INSTANCE_REF_PROP] === 'string' ? String(rest[AI_INSTANCE_REF_PROP]).trim() : ''\n delete rest[AI_INSTANCE_REF_PROP]\n if (!refId || !refs.componentIds?.has(refId)) {\n return {\n refusal: `Reusable Component (${nodeId}) names a component this site does not have`,\n }\n }\n kept[AI_INSTANCE_REF_PROP] = refId\n const rawValues = rest[REUSABLE_INSTANCE_PROP_VALUES_KEY]\n delete rest[REUSABLE_INSTANCE_PROP_VALUES_KEY]\n if (rawValues !== undefined && !isRecord(rawValues)) {\n repairs.push(`${nodeId}.propValues is not an object; dropped`)\n }\n const declared = refs.componentProps[refId]\n const values: Record<string, unknown> = {}\n for (const [name, raw] of Object.entries(isRecord(rawValues) ? rawValues : {})) {\n if (raw === undefined || raw === null) continue\n if (!COMPONENT_PROP_NAME_PATTERN.test(name)) {\n repairs.push(`${nodeId}.propValues.${name} is not a prop name; dropped`)\n continue\n }\n if (declared && !(name in declared)) {\n repairs.push(`${nodeId}.propValues.${name} is not a prop of that component; dropped`)\n continue\n }\n if (refs.definesComponent && isAiComponentPropToken(raw)) {\n // A property of the component being defined, handed on whole; the\n // component step's check holds it to the kind this prop declares.\n values[name] = raw.trim()\n continue\n }\n const value = instancePropValue(\n nodeId,\n name,\n declared?.[name] ?? 'text',\n raw,\n refs.assetIds,\n repairs,\n )\n if (value !== undefined) values[name] = value\n }\n if (Object.keys(values).length) kept[REUSABLE_INSTANCE_PROP_VALUES_KEY] = values\n return { props: rest, kept }\n }\n if (componentId === FORM_COMPONENT_ID) {\n const bindings: Array<[prop: string, ids: Set<string> | null, record: string]> = [\n ['formId', refs.formIds, 'form'],\n ['datasetId', refs.datasetIds, 'dataset'],\n ]\n for (const [prop, ids, record] of bindings) {\n const raw = rest[prop]\n delete rest[prop]\n if (raw === undefined || raw === null || raw === '') continue\n const id = typeof raw === 'string' ? raw.trim() : ''\n if (id && ids?.has(id)) {\n kept[prop] = id\n } else {\n repairs.push(`${nodeId}.${prop} names a ${record} this site does not have; dropped`)\n }\n }\n }\n return { props: rest, kept }\n}\n\nfunction refusalCode(error: string): AiNodeTreeRefusalCode {\n if (/too large/i.test(error)) return 'too-large'\n if (/cannot be published/i.test(error)) return 'component'\n return 'structure'\n}\n\n/**\n * Whether the root the model wrote is the surface's root: the canvas wrapper\n * for a document surface (which the sanitizer exempts by the same shape), or\n * the named component otherwise.\n */\nfunction rootMatches(surfaceRoot: string, componentId: unknown): boolean {\n if (surfaceRoot === 'div') {\n return componentId == null || componentId === '' || componentId === 'div'\n }\n return componentId === surfaceRoot\n}\n\nexport function validateAiNodeTree(\n input: unknown,\n surface: AiSurface,\n context?: AiNodeTreeContext,\n): AiNodeTreeResult {\n try {\n return validate(input, surface, context)\n } catch (error) {\n return {\n ok: false,\n code: 'invalid-input',\n error: `The tree could not be read: ${error instanceof Error ? error.message : String(error)}`,\n }\n }\n}\n\nexport type AiNodePatchResult =\n | {\n ok: true\n props: Record<string, unknown>\n sx: Record<string, unknown> | undefined\n repairs: string[]\n }\n | { ok: false; error: string; code: AiNodeTreeRefusalCode }\n\n/**\n * One element's prop and style patch, held to the rules `validateAiNodeTree`\n * holds an element it places — for an edit to an element already on the\n * canvas, where there is no tree to validate.\n *\n * The same passes run: unknown props dropped, enums coerced, every string\n * held to its role and screened for markup, `sx` held to the key set and the\n * value grammar. The one difference is `required`: a patch is merged over the\n * props the element already has, so a required prop the patch does not name\n * is not missing.\n */\nexport function validateAiNodePatch(\n componentId: string,\n patch: { props?: unknown; sx?: unknown },\n context?: AiNodeTreeContext,\n): AiNodePatchResult {\n const entry = AI_PALETTE[componentId]\n if (!entry) {\n return {\n ok: false,\n code: 'component',\n error: `Component \"${componentId}\" is not in the palette`,\n }\n }\n const repairs: string[] = []\n const props = sanitizeProps(\n componentId,\n { ...entry, propsSchema: { ...entry.propsSchema, required: [] } },\n patch.props,\n context?.screenIds ? new Set(context.screenIds) : null,\n context?.assetIds ? new Set(context.assetIds) : null,\n repairs,\n )\n const sx =\n patch.sx === undefined ? undefined : sanitizeSx(componentId, patch.sx, repairs)\n return {\n ok: true,\n props: 'props' in props ? props.props : {},\n sx,\n repairs,\n }\n}\n\nfunction validate(\n input: unknown,\n surface: AiSurface,\n context: AiNodeTreeContext | undefined,\n): AiNodeTreeResult {\n const definition = AI_SURFACES[surface]\n if (!definition) {\n return {\n ok: false,\n code: 'invalid-input',\n error: `Unknown surface \"${surface}\"`,\n }\n }\n if (\n !isRecord(input) ||\n typeof input.rootId !== 'string' ||\n !isRecord(input.nodes)\n ) {\n return {\n ok: false,\n code: 'invalid-input',\n error: 'Expected an object with a string rootId and a nodes map',\n }\n }\n const rootId = input.rootId\n const nodes = input.nodes as Record<string, unknown>\n const root = nodes[rootId]\n if (!isRecord(root)) {\n return {\n ok: false,\n code: 'structure',\n error: 'Definition has no root node',\n }\n }\n if (!rootMatches(definition.root, root.componentId)) {\n return {\n ok: false,\n code: 'root',\n error: `A ${surface} starts with ${definition.root === 'div' ? 'the document wrapper' : `\"${definition.root}\"`}, not \"${String(root.componentId)}\"`,\n }\n }\n\n // The sanitizer keeps only the persisted node keys, and `sx` is not one of\n // them for a listing. Read it off every node first — from the node field\n // or from `props.sx`, which a model writes just as readily — and put it\n // back, checked, on the nodes that survive.\n const sxByNodeId = new Map<string, unknown>()\n const hiddenByNodeId = new Set<string>()\n for (const [id, node] of Object.entries(nodes)) {\n if (!isRecord(node)) continue\n const sx =\n node.sx !== undefined\n ? node.sx\n : isRecord(node.props)\n ? node.props.sx\n : undefined\n if (sx !== undefined) sxByNodeId.set(id, sx)\n if (node.hidden === true) hiddenByNodeId.add(id)\n }\n\n // A DAM reference (a `media:` value) is not a URL the sanitizer's\n // `src` policy admits — a listing must not carry another tenant's asset —\n // but on the tenant's own page it is exactly what an image should name.\n // Lift those values out before sanitizing and hand them back to the prop\n // pass, which holds them to the asset set the caller supplied.\n // A binding token the caller admitted (AGL-2909) is lifted the same way:\n // `{{entry.coverImage}}` is no address the sanitizer knows, and the prop\n // pass holds it to the tokens the caller named.\n const bindingTokens = context?.bindingTokens ? new Set(context.bindingTokens) : null\n // A reusable component's own property tokens (AGL-2908) are lifted too, and\n // kept as written rather than handed back to the prop pass: `{{prop.variant}}`\n // is no value a dropdown, a switch, an address or a visibility directive\n // admits. Copy keeps its tokens without lifting, as the text they are.\n const definesComponent = context?.definesComponent === true\n const codeBuilt = context?.codeBuilt === true\n const mediaByNodeId = new Map<string, Record<string, string>>()\n const boundByNodeId = new Map<string, Record<string, string>>()\n // A code-built Icon's drawing, from the library by the id it names (AGL-3660).\n const iconByNodeId = new Map<string, { iconId: string; iconPath: string }>()\n const forSanitizer: Record<string, unknown> = {}\n for (const [id, node] of Object.entries(nodes)) {\n if (!isRecord(node) || !isRecord(node.props)) {\n forSanitizer[id] = node\n continue\n }\n if (codeBuilt && node.componentId === AI_ICON_COMPONENT_ID) {\n const { iconId, ...props } = node.props\n const rest = { ...props }\n delete rest['iconPath']\n const icon = aiIconOfId(iconId)\n if (icon) iconByNodeId.set(id, { iconId: icon.id, iconPath: icon.path })\n forSanitizer[id] = { ...node, props: rest }\n continue\n }\n const entry = AI_PALETTE[String(node.componentId)]\n const roles = entry?.propRoles ?? {}\n const props: Record<string, unknown> = { ...node.props }\n const lifted: Record<string, string> = {}\n const bound: Record<string, string> = {}\n for (const [key, value] of Object.entries(props)) {\n if (typeof value !== 'string') continue\n const role = roles[key]\n if (\n definesComponent &&\n isAiComponentPropToken(value) &&\n (AI_COMPONENT_VISIBILITY_PROPS.includes(key) ||\n (entry?.propsSchema.properties[key] !== undefined && role !== 'text'))\n ) {\n bound[key] = value.trim()\n delete props[key]\n continue\n }\n if (\n (role === 'media' && parseMediaRef(value.trim())) ||\n ((role === 'media' || role === 'url') && bindingTokens?.has(value.trim()))\n ) {\n lifted[key] = value\n delete props[key]\n }\n }\n if (Object.keys(lifted).length) mediaByNodeId.set(id, lifted)\n if (Object.keys(bound).length) boundByNodeId.set(id, bound)\n forSanitizer[id] = { ...node, props }\n }\n\n const refs: ReferenceSets = {\n componentIds: context?.componentIds ? new Set(context.componentIds) : null,\n componentProps: context?.componentProps ?? {},\n formIds: context?.formIds ? new Set(context.formIds) : null,\n datasetIds: context?.datasetIds ? new Set(context.datasetIds) : null,\n assetIds: context?.assetIds ? new Set(context.assetIds) : null,\n definesComponent,\n }\n // An instance is admitted only where the caller grounded it in the site's\n // components; the reference itself is checked on the node below.\n const surfaceAllow = codeBuilt ? [...definition.allow, ...(definition.codeOnly ?? [])] : definition.allow\n const allow =\n refs.componentIds && INSTANCE_SURFACES.has(surface)\n ? [...surfaceAllow, REUSABLE_INSTANCE_COMPONENT_ID]\n : surfaceAllow\n const sanitized = sanitizePortableDefinition(\n { rootId, nodes: forSanitizer },\n { componentIds: allow },\n )\n if (sanitized.ok === false) {\n return {\n ok: false,\n code: refusalCode(sanitized.error),\n error: sanitized.error,\n }\n }\n\n const screenIds = context?.screenIds ? new Set(context.screenIds) : null\n const assetIds = refs.assetIds\n const repairs: string[] = []\n const output: NodesMap = {}\n const rootIsWrapper =\n rootMatches('div', root.componentId) && definition.root === 'div'\n const minted = new Map<string, string>()\n const mint = (id: string): string => {\n const fresh =\n id === rootId && rootIsWrapper\n ? CANVAS_ROOT_ELEMENT_ID\n : createIdUrlSafe()\n minted.set(id, fresh)\n return fresh\n }\n\n /** Each visited node's parent by the model's own ids, for the parentId check. */\n const parentOf = new Map<string, string>()\n const queue: Array<{ id: string; parentId: string | null }> = [\n { id: rootId, parentId: null },\n ]\n mint(rootId)\n while (queue.length) {\n const { id, parentId } = queue.shift() as {\n id: string\n parentId: string | null\n }\n const node = sanitized.nodes[id]\n const entry = AI_PALETTE[node.componentId]\n if (!entry) {\n return {\n ok: false,\n code: 'component',\n error: `Component \"${node.componentId}\" is not in the palette`,\n }\n }\n const newId = minted.get(id) as string\n const raw = nodes[id]\n if (isRecord(raw)) {\n // The sanitizer drops silently; the model is told what went.\n for (const key of STRIPPED_NODE_KEYS) {\n if (raw[key] !== undefined) {\n repairs.push(\n `${id}.${key} is not something a generated node may set; dropped`,\n )\n }\n }\n if (raw.hidden !== undefined && typeof raw.hidden !== 'boolean') {\n repairs.push(`${id}.hidden is not a boolean; dropped`)\n }\n if (raw.nodes !== undefined && !Array.isArray(raw.nodes)) {\n repairs.push(\n `${id}.nodes is not a list of child ids; its children were dropped`,\n )\n }\n if (\n raw.parentId !== undefined &&\n raw.parentId !== null &&\n raw.parentId !== (parentId === null ? null : parentOf.get(id))\n ) {\n repairs.push(\n `${id}.parentId disagreed with where the tree places it; recomputed`,\n )\n }\n if (isRecord(raw.props)) {\n const lifted = mediaByNodeId.get(id) ?? {}\n const kept = boundByNodeId.get(id) ?? {}\n for (const key of Object.keys(raw.props)) {\n if (iconByNodeId.has(id) && (key === 'iconId' || key === 'iconPath')) continue\n if (\n key !== 'sx' &&\n lifted[key] === undefined &&\n kept[key] === undefined &&\n node.props?.[key] === undefined &&\n raw.props[key] !== undefined\n ) {\n repairs.push(\n `${id}.${key} was an unsafe handler, address or markup; dropped`,\n )\n }\n }\n }\n }\n const children: string[] = []\n for (const childId of node.nodes ?? []) {\n if (minted.has(childId)) {\n repairs.push(\n `${childId} was listed under more than one parent; the later listing was dropped`,\n )\n continue\n }\n const child = sanitized.nodes[childId]\n if (!child) continue\n const childEntry = AI_PALETTE[child.componentId]\n if (!childEntry) {\n return {\n ok: false,\n code: 'component',\n error: `Component \"${child.componentId}\" is not in the palette`,\n }\n }\n if (!entry.acceptsChildren) {\n return {\n ok: false,\n code: 'lineage',\n error: `${entry.displayName} (${id}) cannot hold other elements, but lists ${childId}`,\n }\n }\n if (\n !linealRelationshipPermits(\n {\n componentId: child.componentId,\n pluginId: childEntry.pluginId,\n restrictParent: childEntry.restrictParent,\n },\n {\n componentId: node.componentId,\n pluginId: entry.pluginId,\n restrictChildren: entry.restrictChildren,\n },\n )\n ) {\n return {\n ok: false,\n code: 'lineage',\n error: `${childEntry.displayName} (${childId}) cannot be placed inside ${entry.displayName} (${id})`,\n }\n }\n children.push(mint(childId))\n parentOf.set(childId, id)\n queue.push({ id: childId, parentId: newId })\n }\n\n const reference = sanitizeReferenceProps(\n id,\n node.componentId,\n { ...node.props, ...mediaByNodeId.get(id) },\n refs,\n repairs,\n )\n if ('refusal' in reference) {\n return { ok: false, code: 'reference', error: reference.refusal }\n }\n // A required prop the component binds is present: its value is the token.\n const boundProps = boundByNodeId.get(id)\n const propsResult = sanitizeProps(\n id,\n boundProps\n ? {\n ...entry,\n propsSchema: {\n ...entry.propsSchema,\n required: entry.propsSchema.required.filter((name) => boundProps[name] === undefined),\n },\n }\n : entry,\n reference.props,\n screenIds,\n assetIds,\n repairs,\n bindingTokens,\n )\n if ('missing' in propsResult) {\n return {\n ok: false,\n code: 'required-prop',\n error: `${entry.displayName} (${id}) is missing its required \"${propsResult.missing}\" prop`,\n }\n }\n const sx = sanitizeSx(id, sxByNodeId.get(id), repairs)\n output[newId] = {\n $id: newId,\n type: NodeType.NODE,\n componentId: node.componentId,\n pluginId: entry.pluginId,\n parentId,\n nodes: children,\n props: { ...propsResult.props, ...reference.kept, ...boundProps, ...iconByNodeId.get(id) },\n ...(sx ? { sx } : {}),\n ...(hiddenByNodeId.has(id) ? { hidden: true } : {}),\n }\n }\n\n // The save's own measurement (msgpack), not a JSON string length: the\n // ceiling is stated in those bytes, and a UTF-16 length reads multi-byte\n // copy as smaller than the document the save will refuse.\n const bytes = nodeMapBytes(output)\n if (bytes > NODE_MAP_MAX_BYTES) {\n return {\n ok: false,\n code: 'too-large',\n error: `The tree is ${bytes} bytes; the stored ceiling is ${NODE_MAP_MAX_BYTES}`,\n }\n }\n const sourceIds: Record<string, string> = {}\n for (const [source, fresh] of minted) sourceIds[fresh] = source\n return {\n ok: true,\n rootId: minted.get(rootId) as string,\n nodes: output,\n repairs,\n sourceIds,\n }\n}\n"],"names":["AI_TEXT_LIMITS","isHeadlineVariant","nodeCapabilityProps","AI_NODE_CAPABILITIES","AI_PALETTE","AI_SURFACES","AI_SX_TOKENS","linealRelationshipPermits","NODE_MAP_MAX_BYTES","nodeMapBytes","parseMediaRef","COMPONENT_PROP_NAME_PATTERN","REUSABLE_INSTANCE_COMPONENT_ID","REUSABLE_INSTANCE_PROP_VALUES_KEY","createIdUrlSafe","CANVAS_ROOT_ELEMENT_ID","NodeType","AI_ICON_COMPONENT_ID","aiIconOfId","AI_COMPONENT_VISIBILITY_PROPS","isAiComponentPropToken","sanitizePortableDefinition","AI_SX_ALLOWED_KEYS","Set","HOSTILE_TEXT","SX_VALUE","STRIPPED_NODE_KEYS","SCREEN_ID","ICON_PICKER_FIELD","MAX_SX_KEYS","PLAIN_STRING_MAX","paletteTokens","palette","breakpoints","typographyVariants","isRecord","value","Array","isArray","isHttpsUrl","test","URL","protocol","isRootRelativePath","sxValueAllowed","key","Number","isFinite","trimmed","trim","has","sanitizeSx","nodeId","sx","repairs","undefined","push","out","kept","Object","entries","responsive","breakpoint","inner","keys","length","coerceEnum","schema","enum","wanted","toLowerCase","find","option","coerceBoolean","coerceNumber","parsed","NaN","type","isInteger","minimum","maximum","textLimitFor","entry","name","props","declared","textLimits","variant","Math","min","body","headline","sanitizeString","raw","screenIds","assetIds","bindingTokens","propFields","role","propRoles","limit","slice","trimEnd","ref","mediaId","pattern","RegExp","minLength","maxLength","CAPABLE_ENTRIES","WeakMap","withNodeCapabilities","cached","get","capability","acceptsChildren","merged","propsSchema","properties","set","sanitizeProps","paletteEntry","source","displayName","coerced","join","String","text","cleaned","required","missing","INSTANCE_SURFACES","FORM_COMPONENT_ID","AI_INSTANCE_REF_PROP","instancePropValue","sanitizeReferenceProps","componentId","refs","rest","refId","componentIds","refusal","rawValues","componentProps","values","definesComponent","bindings","formIds","datasetIds","prop","ids","record","id","refusalCode","error","rootMatches","surfaceRoot","validateAiNodeTree","input","surface","context","validate","ok","code","Error","message","validateAiNodePatch","patch","definition","rootId","nodes","root","sxByNodeId","Map","hiddenByNodeId","node","hidden","add","codeBuilt","mediaByNodeId","boundByNodeId","iconByNodeId","forSanitizer","iconId","icon","iconPath","path","roles","lifted","bound","includes","surfaceAllow","allow","codeOnly","sanitized","output","rootIsWrapper","minted","mint","fresh","parentOf","queue","parentId","shift","newId","children","childId","child","childEntry","pluginId","restrictParent","restrictChildren","reference","boundProps","propsResult","filter","$id","NODE","bytes","sourceIds"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,QAId,kBAAc;AACrB,SACEC,oBAAoB,EACpBC,UAAU,EACVC,WAAW,EACXC,YAAY,QACP,4BAAwB;AAC/B,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SACEC,kBAAkB,EAClBC,YAAY,QACP,0CAAyC;AAChD,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SACEC,2BAA2B,EAC3BC,8BAA8B,EAC9BC,iCAAiC,QAC5B,iDAAgD;AACvD,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,sBAAsB,QAAQ,2CAA0C;AACjF,SAASC,QAAQ,QAAuB,2BAA0B;AAElE,SAASC,oBAAoB,EAAEC,UAAU,QAAQ,uBAAmB;AACpE,SACEC,6BAA6B,EAC7BC,sBAAsB,QACjB,6BAAyB;AAEhC,SAASC,0BAA0B,QAAQ,mDAAkD;AA0H7F;;;;;CAKC,GACD,OAAO,MAAMC,qBAA0C,IAAIC,IAAI;IAC7D,UAAU;IACV;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,QAAQ;IACR;IACA;IACA;IACA;IACA;IACA,aAAa;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,SAAS;IACT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,UAAU;IACV;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,UAAU;IACV;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAC;AAEF;;;;CAIC,GACD,OAAO,MAAMC,eACX,2LA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IACF;AACF"}
@@ -154,6 +154,12 @@ export interface AiSurfaceDefinition {
154
154
  root: string;
155
155
  /** Every component id a node in this surface may carry. */
156
156
  allow: readonly string[];
157
+ /**
158
+ * Component ids admitted only in a tree the platform's own code composed
159
+ * (AGL-3660), never listed in the surface's catalog: see
160
+ * `AiNodeTreeContext.codeBuilt`.
161
+ */
162
+ codeOnly?: readonly string[];
157
163
  }
158
164
  /**
159
165
  * Theme vocabulary an `sx` value may name, read off the theme sources so the
@@ -3969,6 +3969,37 @@
3969
3969
  'Newsletter signup'
3970
3970
  ]
3971
3971
  },
3972
+ 'order-status': {
3973
+ pluginId: 'commerce',
3974
+ kind: 'element',
3975
+ category: 'Commerce',
3976
+ displayName: 'Order status',
3977
+ summary: 'A buyer’s order, shipments and tracking, opened from the link in their order emails.',
3978
+ acceptsChildren: false,
3979
+ propsSchema: {
3980
+ type: 'object',
3981
+ properties: {
3982
+ heading: {
3983
+ type: 'string',
3984
+ maxLength: 200
3985
+ }
3986
+ },
3987
+ required: [],
3988
+ additionalProperties: false
3989
+ },
3990
+ propRoles: {
3991
+ heading: 'text'
3992
+ },
3993
+ propFields: {
3994
+ heading: 'text-field'
3995
+ },
3996
+ textLimits: {
3997
+ heading: 200
3998
+ },
3999
+ presets: [
4000
+ 'Order status'
4001
+ ]
4002
+ },
3972
4003
  product: {
3973
4004
  pluginId: 'mui',
3974
4005
  kind: 'element',
@@ -4308,6 +4339,37 @@
4308
4339
  'Reservation widget'
4309
4340
  ]
4310
4341
  },
4342
+ 'return-request': {
4343
+ pluginId: 'commerce',
4344
+ kind: 'element',
4345
+ category: 'Commerce',
4346
+ displayName: 'Return request',
4347
+ summary: 'The buyer’s return form for one order, opened from their account or the order’s status page.',
4348
+ acceptsChildren: false,
4349
+ propsSchema: {
4350
+ type: 'object',
4351
+ properties: {
4352
+ heading: {
4353
+ type: 'string',
4354
+ maxLength: 200
4355
+ }
4356
+ },
4357
+ required: [],
4358
+ additionalProperties: false
4359
+ },
4360
+ propRoles: {
4361
+ heading: 'text'
4362
+ },
4363
+ propFields: {
4364
+ heading: 'text-field'
4365
+ },
4366
+ textLimits: {
4367
+ heading: 200
4368
+ },
4369
+ presets: [
4370
+ 'Return request'
4371
+ ]
4372
+ },
4311
4373
  reusableInstance: {
4312
4374
  pluginId: 'mui',
4313
4375
  kind: 'element',
@@ -4861,6 +4923,9 @@
4861
4923
  'socialLinks',
4862
4924
  'video',
4863
4925
  'videoEmbed'
4926
+ ],
4927
+ codeOnly: [
4928
+ 'icon'
4864
4929
  ]
4865
4930
  },
4866
4931
  email: {
@@ -4926,6 +4991,11 @@
4926
4991
  'socialLinks',
4927
4992
  'video',
4928
4993
  'videoEmbed'
4994
+ ],
4995
+ codeOnly: [
4996
+ 'icon',
4997
+ 'muiDrawer',
4998
+ 'muiDrawerToggle'
4929
4999
  ]
4930
5000
  },
4931
5001
  component: {