@metamorph-labs/polymorph 1.0.18 → 1.0.19

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 (319) hide show
  1. package/CHANGELOG.md +242 -0
  2. package/dist/design/systems/desktop.json +1 -1
  3. package/dist/design/systems/dew.json +1 -1
  4. package/dist/design/systems/flint.json +1 -1
  5. package/dist/design/systems/glassmorphic.json +1 -1
  6. package/dist/design/systems/harbor.json +1 -1
  7. package/dist/design/systems/journal.json +1 -1
  8. package/dist/design/systems/pastel.json +1 -1
  9. package/dist/design/systems/pebble.json +1 -1
  10. package/dist/design/systems/plain.json +1 -1
  11. package/dist/design/systems/pop.json +1 -1
  12. package/dist/design/systems/press.json +1 -1
  13. package/dist/packages/angular-ui/src/ai/ArtifactPane.ts +15 -4
  14. package/dist/packages/angular-ui/src/ai/PromptInput.ts +3 -1
  15. package/dist/packages/angular-ui/src/archetypes/Dashboard.ts +38 -20
  16. package/dist/packages/angular-ui/src/archetypes/dashboard.states.ts +52 -0
  17. package/dist/packages/angular-ui/src/controls/ColorInput.ts +62 -34
  18. package/dist/packages/angular-ui/src/controls/Combobox.ts +28 -7
  19. package/dist/packages/angular-ui/src/controls/DatePicker.ts +12 -11
  20. package/dist/packages/angular-ui/src/controls/DateRangePicker.ts +22 -17
  21. package/dist/packages/angular-ui/src/controls/DateRangePickerRangeCalendar.ts +3 -2
  22. package/dist/packages/angular-ui/src/controls/FileUpload.ts +18 -12
  23. package/dist/packages/angular-ui/src/controls/FileUploadRow.ts +24 -4
  24. package/dist/packages/angular-ui/src/controls/MultiSelect.ts +49 -12
  25. package/dist/packages/angular-ui/src/controls/NumberInput.ts +27 -3
  26. package/dist/packages/angular-ui/src/controls/PhoneInput.ts +9 -5
  27. package/dist/packages/angular-ui/src/controls/Select.ts +36 -7
  28. package/dist/packages/angular-ui/src/controls/TagInput.ts +61 -7
  29. package/dist/packages/angular-ui/src/controls/TimeInput.ts +15 -1
  30. package/dist/packages/angular-ui/src/controls/select.states.ts +79 -58
  31. package/dist/packages/angular-ui/src/overlays/Command.ts +50 -13
  32. package/dist/packages/angular-ui/src/overlays/CommandPanel.ts +11 -7
  33. package/dist/packages/angular-ui/src/overlays/ToastViewport.ts +1 -1
  34. package/dist/packages/angular-ui/src/structure/CodeBlock.ts +18 -4
  35. package/dist/packages/angular-ui/src/structure/Stat.ts +295 -84
  36. package/dist/packages/angular-ui/src/structure/stat.states.ts +116 -0
  37. package/dist/packages/cli/src/agents.js +4 -3
  38. package/dist/packages/cli/src/apply.js +43 -18
  39. package/dist/packages/cli/src/check.js +4 -0
  40. package/dist/packages/cli/src/cli.js +6 -2
  41. package/dist/packages/cli/src/elements.js +12 -2
  42. package/dist/packages/cli/src/emit.js +43 -8
  43. package/dist/packages/cli/src/readings.js +29 -3
  44. package/dist/packages/cli/src/skills/bridge.js +1197 -0
  45. package/dist/packages/cli/src/skills/facts.js +190 -0
  46. package/dist/packages/cli/src/skills/native.js +1580 -0
  47. package/dist/packages/cli/src/skills/rules.js +199 -0
  48. package/dist/packages/cli/src/skills/runtime.js +1020 -0
  49. package/dist/packages/cli/src/skills/screen-charts.js +334 -0
  50. package/dist/packages/cli/src/skills/screen-chat.js +247 -0
  51. package/dist/packages/cli/src/skills/screen-code.js +565 -0
  52. package/dist/packages/cli/src/skills/screen-rich-text.js +305 -0
  53. package/dist/packages/cli/src/skills/screen.js +378 -0
  54. package/dist/packages/cli/src/skills/setup-packages.js +307 -0
  55. package/dist/packages/cli/src/skills/setup.js +125 -0
  56. package/dist/packages/cli/src/skills/theme-documents.js +351 -0
  57. package/dist/packages/cli/src/skills/theme.js +208 -0
  58. package/dist/packages/cli/src/skills.js +13 -794
  59. package/dist/packages/cli/src/theme.js +42 -1
  60. package/dist/packages/cli/src/tool-verbs.js +19 -4
  61. package/dist/packages/cli/src/verbs.js +28 -2
  62. package/dist/packages/elements-ui/dist/cdn/chunks/{AppShellUserCard-0eCCnnN_.js → AppShellUserCard-XT4br4fr.js} +1 -1
  63. package/dist/packages/elements-ui/dist/cdn/chunks/{AreaChart-DftfzLG0.js → AreaChart-CXNFfbJ8.js} +1 -1
  64. package/dist/packages/elements-ui/dist/cdn/chunks/ArtifactPane-Pr9_K2uM.js +1 -0
  65. package/dist/packages/elements-ui/dist/cdn/chunks/{Avatar-DcdMgxgY.js → Avatar-3WXoBPLv.js} +1 -1
  66. package/dist/packages/elements-ui/dist/cdn/chunks/{Avatar-DcuvZwe7.js → Avatar-BKqjM8qW.js} +1 -1
  67. package/dist/packages/elements-ui/dist/cdn/chunks/{AvatarButton-D5XKVduu.js → AvatarButton-BasMQCSM.js} +1 -1
  68. package/dist/packages/elements-ui/dist/cdn/chunks/{AvatarGroup-DgFwJUNO.js → AvatarGroup-COch2-O0.js} +1 -1
  69. package/dist/packages/elements-ui/dist/cdn/chunks/{BarChart-myuR0aHc.js → BarChart-ugae8zfr.js} +1 -1
  70. package/dist/packages/elements-ui/dist/cdn/chunks/{ChatMessage-CgQ1h_JP.js → ChatMessage-Bx4yrF2x.js} +1 -1
  71. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-B_e5ma3K.js +1 -0
  72. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-Fgtr48Vb.js +1 -0
  73. package/dist/packages/elements-ui/dist/cdn/chunks/ColorInput-CD7rsWRp.js +1 -0
  74. package/dist/packages/elements-ui/dist/cdn/chunks/Combobox-CUw7z6TS.js +1 -0
  75. package/dist/packages/elements-ui/dist/cdn/chunks/{Combobox-DB2FT7so.js → Combobox-hWIFU9X_.js} +1 -1
  76. package/dist/packages/elements-ui/dist/cdn/chunks/Command-BXgqRd3I.js +1 -0
  77. package/dist/packages/elements-ui/dist/cdn/chunks/{ConfirmDialog-BtQOAHY2.js → ConfirmDialog-CAaBRKxl.js} +1 -1
  78. package/dist/packages/elements-ui/dist/cdn/chunks/{Dashboard-ChMPH4_Q.js → Dashboard-DwNw5Wnd.js} +1 -1
  79. package/dist/packages/elements-ui/dist/cdn/chunks/DatePicker-DjqtswQR.js +1 -0
  80. package/dist/packages/elements-ui/dist/cdn/chunks/DateRangePicker-LsXFHOzm.js +1 -0
  81. package/dist/packages/elements-ui/dist/cdn/chunks/{DonutChart-BEK89BeL.js → DonutChart-DYXx6eTe.js} +1 -1
  82. package/dist/packages/elements-ui/dist/cdn/chunks/FileUpload-3gbZTSSx.js +1 -0
  83. package/dist/packages/elements-ui/dist/cdn/chunks/{FormField-PlLLDKqc.js → FormField-Bvw4cLBc.js} +1 -1
  84. package/dist/packages/elements-ui/dist/cdn/chunks/{FormField-C6L3vYp4.js → FormField-DzhcinED.js} +1 -1
  85. package/dist/packages/elements-ui/dist/cdn/chunks/{FunnelChart-DVQz_gad.js → FunnelChart-D24XhrGw.js} +1 -1
  86. package/dist/packages/elements-ui/dist/cdn/chunks/{Heading-fAcu6Vrw.js → Heading-Cvfyu8pc.js} +1 -1
  87. package/dist/packages/elements-ui/dist/cdn/chunks/{Heading-CgzEi9OQ.js → Heading-XDJzlwt9.js} +1 -1
  88. package/dist/packages/elements-ui/dist/cdn/chunks/{Heatmap-BRwR-n-V.js → Heatmap-BQoUS6gY.js} +1 -1
  89. package/dist/packages/elements-ui/dist/cdn/chunks/{Hero-CV2YWeb4.js → Hero-CXuuFceS.js} +1 -1
  90. package/dist/packages/elements-ui/dist/cdn/chunks/{Histogram-CCYwlinB.js → Histogram-DW_ZPHpR.js} +1 -1
  91. package/dist/packages/elements-ui/dist/cdn/chunks/{LineChart-BH6Pq1P1.js → LineChart-kf-zlNWe.js} +1 -1
  92. package/dist/packages/elements-ui/dist/cdn/chunks/{Markdown-DmZEch4i.js → Markdown-C3rjhIbt.js} +1 -1
  93. package/dist/packages/elements-ui/dist/cdn/chunks/ModeSwitch-DQ86CK9h.js +1 -0
  94. package/dist/packages/elements-ui/dist/cdn/chunks/MultiSelect-DbSx9QtV.js +1 -0
  95. package/dist/packages/elements-ui/dist/cdn/chunks/NumberInput-B4ZZOGLl.js +7 -0
  96. package/dist/packages/elements-ui/dist/cdn/chunks/PhoneInput-BsMfbNi6.js +210 -0
  97. package/dist/packages/elements-ui/dist/cdn/chunks/PromptInput-l_-zAXSZ.js +1 -0
  98. package/dist/packages/elements-ui/dist/cdn/chunks/{RadarChart-Coje7Sb0.js → RadarChart-CwJAWRki.js} +1 -1
  99. package/dist/packages/elements-ui/dist/cdn/chunks/{RichTextContent-CufjptHF.js → RichTextContent-D51UfuWk.js} +1 -1
  100. package/dist/packages/elements-ui/dist/cdn/chunks/{RichTextInput-Dz7yBFUA.js → RichTextInput-B32fN_p9.js} +3 -3
  101. package/dist/packages/elements-ui/dist/cdn/chunks/{ScatterChart-Do5tQTC5.js → ScatterChart-Mps7l5-i.js} +1 -1
  102. package/dist/packages/elements-ui/dist/cdn/chunks/Select-CpsRP0NR.js +1 -0
  103. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-CXR6bP7X.js +1 -0
  104. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-DGcx2ZZq.js +1 -0
  105. package/dist/packages/elements-ui/dist/cdn/chunks/TagInput-BhkLU4gE.js +1 -0
  106. package/dist/packages/elements-ui/dist/cdn/chunks/TimeInput-r2jNTOLN.js +1 -0
  107. package/dist/packages/elements-ui/dist/cdn/chunks/{Toast-CAYGbn7g.js → Toast-BTfcZn0I.js} +1 -1
  108. package/dist/packages/elements-ui/dist/cdn/chunks/{ToastViewport-CFslglYc.js → ToastViewport-BBQMRCQT.js} +1 -1
  109. package/dist/packages/elements-ui/dist/cdn/chunks/{ToolCall-DUCoKsoE.js → ToolCall-DNU5kk9_.js} +1 -1
  110. package/dist/packages/elements-ui/dist/cdn/chunks/{Treemap-Bh3ruYGJ.js → Treemap-BV8TlZHB.js} +1 -1
  111. package/dist/packages/elements-ui/dist/cdn/chunks/agent-DfOqpL9c.js +1 -0
  112. package/dist/packages/elements-ui/dist/cdn/chunks/api-DJBiUXxK.js +4 -0
  113. package/dist/packages/elements-ui/dist/cdn/chunks/avatar.module-D4YdFevY.js +1 -0
  114. package/dist/packages/elements-ui/dist/cdn/chunks/cap-DA71oFHt.js +1 -0
  115. package/dist/packages/elements-ui/dist/cdn/chunks/{cartesian-I5uPfyqv.js → cartesian-CEn2lJCc.js} +1 -1
  116. package/dist/packages/elements-ui/dist/cdn/chunks/{chart-annotations.module-xUExw4pu.js → chart-annotations.module-hA_KO_Pe.js} +1 -1
  117. package/dist/packages/elements-ui/dist/cdn/chunks/chart-brush.module-C_8txUW5.js +1 -0
  118. package/dist/packages/elements-ui/dist/cdn/chunks/chart-twin.module-BpfyTQ9R.js +1 -0
  119. package/dist/packages/elements-ui/dist/cdn/chunks/check-CHvc4yHL.js +1 -0
  120. package/dist/packages/elements-ui/dist/cdn/chunks/css-vars-DeZ4TCna.js +1 -0
  121. package/dist/packages/elements-ui/dist/cdn/chunks/draw-BiQ3Of6N.js +1 -0
  122. package/dist/packages/elements-ui/dist/cdn/chunks/drawing-nhJNBahV.js +1 -0
  123. package/dist/packages/elements-ui/dist/cdn/chunks/field-labels-Df5HuYC5.js +1 -0
  124. package/dist/packages/elements-ui/dist/cdn/chunks/frame-CtTY4oCn.js +1 -0
  125. package/dist/packages/elements-ui/dist/cdn/chunks/on-call-YKLF3-FH.js +1 -0
  126. package/dist/packages/elements-ui/dist/cdn/chunks/runtime-QRQ3CjZg.js +1 -0
  127. package/dist/packages/elements-ui/dist/cdn/chunks/series-uUg6_JtL.js +1 -0
  128. package/dist/packages/elements-ui/dist/cdn/chunks/src-XnWjGSDr.js +67 -0
  129. package/dist/packages/elements-ui/dist/cdn/chunks/toast-pwGvxH2T.js +1 -0
  130. package/dist/packages/elements-ui/dist/cdn/chunks/urls-Qks0KJ_p.js +6 -0
  131. package/dist/packages/elements-ui/dist/cdn/chunks/webmcp-Dro53ATH.js +1 -0
  132. package/dist/packages/elements-ui/dist/cdn/polymorph-all.js +52 -50
  133. package/dist/packages/elements-ui/dist/cdn/polymorph.css +1 -1
  134. package/dist/packages/elements-ui/dist/cdn/polymorph.js +1 -1
  135. package/dist/packages/elements-ui/dist/cdn/prepaint.js +1 -1
  136. package/dist/packages/elements-ui/dist/cdn/themes/desktop.css +5 -4
  137. package/dist/packages/elements-ui/dist/cdn/themes/dew.css +5 -4
  138. package/dist/packages/elements-ui/dist/cdn/themes/flint.css +5 -4
  139. package/dist/packages/elements-ui/dist/cdn/themes/glassmorphic.css +5 -4
  140. package/dist/packages/elements-ui/dist/cdn/themes/harbor.css +5 -4
  141. package/dist/packages/elements-ui/dist/cdn/themes/journal.css +5 -4
  142. package/dist/packages/elements-ui/dist/cdn/themes/pastel.css +5 -4
  143. package/dist/packages/elements-ui/dist/cdn/themes/pebble.css +5 -4
  144. package/dist/packages/elements-ui/dist/cdn/themes/plain.css +5 -4
  145. package/dist/packages/elements-ui/dist/cdn/themes/pop.css +5 -4
  146. package/dist/packages/elements-ui/dist/cdn/themes/press.css +5 -4
  147. package/dist/packages/elements-ui/dist/cdn/themes/terminal.css +5 -4
  148. package/dist/packages/elements-ui/src/ai/ArtifactPane.ts +2 -0
  149. package/dist/packages/elements-ui/src/archetypes/dashboard.states.ts +9 -0
  150. package/dist/packages/elements-ui/src/controls/ColorInput.ts +2 -0
  151. package/dist/packages/elements-ui/src/controls/NumberInput.ts +2 -0
  152. package/dist/packages/elements-ui/src/controls/TagInput.ts +4 -0
  153. package/dist/packages/elements-ui/src/controls/TimeInput.ts +2 -0
  154. package/dist/packages/elements-ui/src/controls/select.states.ts +10 -0
  155. package/dist/packages/elements-ui/src/overlays/Command.ts +2 -0
  156. package/dist/packages/elements-ui/src/structure/CodeBlock.ts +5 -2
  157. package/dist/packages/elements-ui/src/structure/Stat.ts +6 -0
  158. package/dist/packages/elements-ui/src/structure/stat.states.ts +33 -0
  159. package/dist/packages/mcp/src/propose.js +92 -15
  160. package/dist/packages/mcp/src/server.js +19 -8
  161. package/dist/packages/mcp/src/tools.js +80 -5
  162. package/dist/packages/mcp/src/write.js +95 -13
  163. package/dist/packages/react-ui/src/ai/ArtifactPane.tsx +5 -2
  164. package/dist/packages/react-ui/src/ai/PromptInput.tsx +5 -2
  165. package/dist/packages/react-ui/src/archetypes/dashboard.states.tsx +28 -0
  166. package/dist/packages/react-ui/src/controls/ColorInput.tsx +69 -13
  167. package/dist/packages/react-ui/src/controls/Combobox.tsx +13 -5
  168. package/dist/packages/react-ui/src/controls/DatePicker.tsx +3 -0
  169. package/dist/packages/react-ui/src/controls/DateRangePicker.tsx +22 -5
  170. package/dist/packages/react-ui/src/controls/FileUpload.tsx +2 -0
  171. package/dist/packages/react-ui/src/controls/MultiSelect.tsx +30 -6
  172. package/dist/packages/react-ui/src/controls/NumberInput.tsx +19 -1
  173. package/dist/packages/react-ui/src/controls/PhoneInput.tsx +3 -3
  174. package/dist/packages/react-ui/src/controls/Select.tsx +59 -23
  175. package/dist/packages/react-ui/src/controls/TagInput.tsx +43 -10
  176. package/dist/packages/react-ui/src/controls/TimeInput.tsx +10 -0
  177. package/dist/packages/react-ui/src/controls/date-segments.tsx +16 -0
  178. package/dist/packages/react-ui/src/controls/select.states.tsx +13 -0
  179. package/dist/packages/react-ui/src/overlays/Command.tsx +23 -2
  180. package/dist/packages/react-ui/src/overlays/Toaster.tsx +2 -2
  181. package/dist/packages/react-ui/src/structure/CodeBlock.tsx +7 -3
  182. package/dist/packages/react-ui/src/structure/Stat.tsx +90 -13
  183. package/dist/packages/react-ui/src/structure/stat.states.tsx +68 -0
  184. package/dist/packages/recipes/src/ai/artifact-pane.module.css +4 -4
  185. package/dist/packages/recipes/src/controls/rich-text-input.module.css +1 -1
  186. package/dist/packages/recipes/src/structure/avatar.module.css +3 -1
  187. package/dist/packages/recipes/src/structure/heading.module.css +5 -4
  188. package/dist/packages/recipes/src/structure/hero.module.css +3 -1
  189. package/dist/packages/recipes/src/structure/stat.module.css +7 -0
  190. package/dist/packages/registry/src/card.js +4 -3
  191. package/dist/packages/registry/src/frameworks.js +28 -1
  192. package/dist/packages/registry/src/runtime-card.js +300 -0
  193. package/dist/packages/registry/src/runtime-members.js +176 -0
  194. package/dist/packages/registry/src/screen-table.js +166 -0
  195. package/dist/packages/rules/package.js +1 -1
  196. package/dist/packages/solid-ui/src/ai/ArtifactPane.tsx +11 -3
  197. package/dist/packages/solid-ui/src/ai/PromptInput.tsx +3 -1
  198. package/dist/packages/solid-ui/src/archetypes/Dashboard.tsx +3 -0
  199. package/dist/packages/solid-ui/src/archetypes/dashboard.states.tsx +39 -0
  200. package/dist/packages/solid-ui/src/controls/ColorInput.tsx +38 -17
  201. package/dist/packages/solid-ui/src/controls/Combobox.tsx +27 -6
  202. package/dist/packages/solid-ui/src/controls/DatePicker.tsx +12 -11
  203. package/dist/packages/solid-ui/src/controls/DateRangePicker.tsx +21 -16
  204. package/dist/packages/solid-ui/src/controls/DateRangePickerRangeCalendar.tsx +3 -4
  205. package/dist/packages/solid-ui/src/controls/FileUpload.tsx +1 -0
  206. package/dist/packages/solid-ui/src/controls/FileUploadRow.tsx +6 -0
  207. package/dist/packages/solid-ui/src/controls/MultiSelect.tsx +51 -11
  208. package/dist/packages/solid-ui/src/controls/NumberInput.tsx +21 -2
  209. package/dist/packages/solid-ui/src/controls/PhoneInput.tsx +8 -4
  210. package/dist/packages/solid-ui/src/controls/Select.tsx +37 -6
  211. package/dist/packages/solid-ui/src/controls/TagInput.tsx +26 -5
  212. package/dist/packages/solid-ui/src/controls/TimeInput.tsx +10 -1
  213. package/dist/packages/solid-ui/src/controls/select.states.tsx +18 -0
  214. package/dist/packages/solid-ui/src/overlays/Command.tsx +15 -2
  215. package/dist/packages/solid-ui/src/overlays/CommandPanel.tsx +7 -7
  216. package/dist/packages/solid-ui/src/overlays/ToastViewport.tsx +1 -1
  217. package/dist/packages/solid-ui/src/structure/CodeBlock.tsx +9 -5
  218. package/dist/packages/solid-ui/src/structure/Stat.tsx +86 -25
  219. package/dist/packages/solid-ui/src/structure/stat.states.tsx +73 -0
  220. package/dist/packages/svelte-ui/src/ai/ArtifactPane.svelte +8 -2
  221. package/dist/packages/svelte-ui/src/ai/PromptInput.svelte +3 -1
  222. package/dist/packages/svelte-ui/src/archetypes/Dashboard.svelte +3 -0
  223. package/dist/packages/svelte-ui/src/archetypes/dashboard.states.svelte +2 -0
  224. package/dist/packages/svelte-ui/src/controls/ColorInput.svelte +29 -8
  225. package/dist/packages/svelte-ui/src/controls/Combobox.svelte +26 -5
  226. package/dist/packages/svelte-ui/src/controls/DatePicker.svelte +7 -5
  227. package/dist/packages/svelte-ui/src/controls/DateRangePicker.svelte +15 -9
  228. package/dist/packages/svelte-ui/src/controls/DateRangePickerRangeCalendar.svelte +3 -2
  229. package/dist/packages/svelte-ui/src/controls/FileUpload.svelte +1 -0
  230. package/dist/packages/svelte-ui/src/controls/FileUploadRow.svelte +8 -1
  231. package/dist/packages/svelte-ui/src/controls/MultiSelect.svelte +36 -10
  232. package/dist/packages/svelte-ui/src/controls/NumberInput.svelte +14 -1
  233. package/dist/packages/svelte-ui/src/controls/PhoneInput.svelte +3 -3
  234. package/dist/packages/svelte-ui/src/controls/Select.svelte +20 -6
  235. package/dist/packages/svelte-ui/src/controls/TagInput.svelte +21 -3
  236. package/dist/packages/svelte-ui/src/controls/TimeInput.svelte +11 -1
  237. package/dist/packages/svelte-ui/src/controls/select.states.svelte +26 -24
  238. package/dist/packages/svelte-ui/src/overlays/Command.svelte +13 -1
  239. package/dist/packages/svelte-ui/src/overlays/CommandPanel.svelte +11 -6
  240. package/dist/packages/svelte-ui/src/overlays/ToastViewport.svelte +1 -1
  241. package/dist/packages/svelte-ui/src/structure/CodeBlock.svelte +7 -2
  242. package/dist/packages/svelte-ui/src/structure/Stat.svelte +70 -17
  243. package/dist/packages/svelte-ui/src/structure/stat.states.svelte +27 -0
  244. package/dist/packages/theme/src/admit.js +6 -3
  245. package/dist/packages/theme/src/color/resolve.js +19 -2
  246. package/dist/packages/theme/src/derive.js +13 -6
  247. package/dist/packages/theme/src/emit.js +1 -1
  248. package/dist/packages/theme/src/runtime.js +58 -0
  249. package/dist/packages/theme/src/seeds.js +30 -4
  250. package/dist/packages/theme/src/systems.js +1 -1
  251. package/dist/packages/theme/src/tokens.js +15 -6
  252. package/dist/packages/vue-ui/src/ai/ArtifactPane.vue +11 -2
  253. package/dist/packages/vue-ui/src/ai/PromptInput.vue +3 -1
  254. package/dist/packages/vue-ui/src/archetypes/Dashboard.vue +3 -0
  255. package/dist/packages/vue-ui/src/archetypes/dashboard.states.ts +49 -0
  256. package/dist/packages/vue-ui/src/controls/ColorInput.vue +33 -12
  257. package/dist/packages/vue-ui/src/controls/Combobox.vue +26 -5
  258. package/dist/packages/vue-ui/src/controls/DatePicker.vue +12 -11
  259. package/dist/packages/vue-ui/src/controls/DateRangePicker.vue +20 -15
  260. package/dist/packages/vue-ui/src/controls/DateRangePickerRangeCalendar.vue +3 -4
  261. package/dist/packages/vue-ui/src/controls/FileUpload.vue +1 -0
  262. package/dist/packages/vue-ui/src/controls/FileUploadRow.vue +6 -0
  263. package/dist/packages/vue-ui/src/controls/MultiSelect.vue +37 -10
  264. package/dist/packages/vue-ui/src/controls/NumberInput.vue +17 -1
  265. package/dist/packages/vue-ui/src/controls/PhoneInput.vue +7 -3
  266. package/dist/packages/vue-ui/src/controls/Select.vue +22 -7
  267. package/dist/packages/vue-ui/src/controls/TagInput.vue +21 -3
  268. package/dist/packages/vue-ui/src/controls/TimeInput.vue +10 -1
  269. package/dist/packages/vue-ui/src/controls/select.states.ts +17 -0
  270. package/dist/packages/vue-ui/src/overlays/Command.vue +13 -1
  271. package/dist/packages/vue-ui/src/overlays/CommandPanel.vue +7 -7
  272. package/dist/packages/vue-ui/src/overlays/ToastViewport.vue +1 -1
  273. package/dist/packages/vue-ui/src/structure/CodeBlock.vue +7 -2
  274. package/dist/packages/vue-ui/src/structure/Stat.vue +71 -18
  275. package/dist/packages/vue-ui/src/structure/stat.states.ts +67 -0
  276. package/dist/platforms/android/ui/src/generated/kotlin/dev/polymorph/ui/Contracts.kt +144 -33
  277. package/dist/platforms/android/ui/src/generated/kotlin/dev/polymorph/ui/Members.kt +17 -7
  278. package/dist/platforms/ios/Sources/PolymorphUI/Generated/Contracts.swift +204 -31
  279. package/dist/registry/registry.json +371 -75
  280. package/dist/screen/assets/{screen-CuQbskb8.css → screen-B22PTPwF.css} +1 -1
  281. package/dist/screen/assets/screen-Cpbh7XMb.js +372 -0
  282. package/dist/screen/screen.html +3 -3
  283. package/package.json +1 -1
  284. package/dist/packages/elements-ui/dist/cdn/chunks/ArtifactPane-DsmRlr6d.js +0 -1
  285. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-BqP8HZKM.js +0 -1
  286. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-D8VARz0a.js +0 -1
  287. package/dist/packages/elements-ui/dist/cdn/chunks/ColorInput-BrzZOVeL.js +0 -1
  288. package/dist/packages/elements-ui/dist/cdn/chunks/Combobox-BiUq0h-w.js +0 -1
  289. package/dist/packages/elements-ui/dist/cdn/chunks/Command-hmxVRdFg.js +0 -1
  290. package/dist/packages/elements-ui/dist/cdn/chunks/DatePicker-C8prGbJ2.js +0 -1
  291. package/dist/packages/elements-ui/dist/cdn/chunks/DateRangePicker-CO1ioqwN.js +0 -1
  292. package/dist/packages/elements-ui/dist/cdn/chunks/FileUpload-HPQe-ttb.js +0 -1
  293. package/dist/packages/elements-ui/dist/cdn/chunks/ModeSwitch-CerqbGv3.js +0 -1
  294. package/dist/packages/elements-ui/dist/cdn/chunks/MultiSelect-CQq7jPgI.js +0 -1
  295. package/dist/packages/elements-ui/dist/cdn/chunks/NumberInput-Dre9GwBy.js +0 -7
  296. package/dist/packages/elements-ui/dist/cdn/chunks/PhoneInput-D6_J6Es_.js +0 -210
  297. package/dist/packages/elements-ui/dist/cdn/chunks/PromptInput-BXcsUQ5W.js +0 -1
  298. package/dist/packages/elements-ui/dist/cdn/chunks/Select-DxGQgv2q.js +0 -1
  299. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-FsMUWigK.js +0 -1
  300. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-WS8v6BQv.js +0 -1
  301. package/dist/packages/elements-ui/dist/cdn/chunks/TagInput-D-uIQEGS.js +0 -1
  302. package/dist/packages/elements-ui/dist/cdn/chunks/TimeInput-Dho571vA.js +0 -1
  303. package/dist/packages/elements-ui/dist/cdn/chunks/agent-DBDk4wLH.js +0 -1
  304. package/dist/packages/elements-ui/dist/cdn/chunks/api-B9sGZiYn.js +0 -4
  305. package/dist/packages/elements-ui/dist/cdn/chunks/avatar.module-CQwnWhWo.js +0 -1
  306. package/dist/packages/elements-ui/dist/cdn/chunks/cap-Ct4k7zNC.js +0 -1
  307. package/dist/packages/elements-ui/dist/cdn/chunks/chart-brush.module-DycBfben.js +0 -1
  308. package/dist/packages/elements-ui/dist/cdn/chunks/chart-twin.module-Cks7VwS5.js +0 -1
  309. package/dist/packages/elements-ui/dist/cdn/chunks/check-dOfCSYFA.js +0 -1
  310. package/dist/packages/elements-ui/dist/cdn/chunks/draw-DclRgiWM.js +0 -1
  311. package/dist/packages/elements-ui/dist/cdn/chunks/drawing-DjkZr0z8.js +0 -1
  312. package/dist/packages/elements-ui/dist/cdn/chunks/frame-BSvl4y47.js +0 -1
  313. package/dist/packages/elements-ui/dist/cdn/chunks/on-call-Jk1sYJc_.js +0 -1
  314. package/dist/packages/elements-ui/dist/cdn/chunks/receivers-BpRfF6dV.js +0 -4
  315. package/dist/packages/elements-ui/dist/cdn/chunks/series-C_1TNd2n.js +0 -1
  316. package/dist/packages/elements-ui/dist/cdn/chunks/src-Bub3C9YP.js +0 -67
  317. package/dist/packages/elements-ui/dist/cdn/chunks/toast-AarMGYJn.js +0 -1
  318. package/dist/packages/elements-ui/dist/cdn/chunks/webmcp-eEPzSqph.js +0 -1
  319. package/dist/screen/assets/screen-Clj2u6_s.js +0 -372
@@ -0,0 +1,1197 @@
1
+ import { renderSystemCard } from "../../../registry/src/card.js";
2
+ import { Facts, SkillFactError, all, commands, either, skill } from "./facts.js";
3
+ //#region ../cli/src/skills/bridge.ts
4
+ /**
5
+ * What the texts say an agent may read from a member and do with it, read from
6
+ * the registry's agent contracts and from the card the reader has. A state, an
7
+ * action or a segment the registry lacks throws, so a renamed action stops the
8
+ * texts from being written rather than reaching a model.
9
+ */
10
+ var AgentFacts = class {
11
+ registry;
12
+ f;
13
+ /** Each member's `agent:` segment, as the web card writes it. */
14
+ segments = /* @__PURE__ */ new Map();
15
+ constructor(registry, f) {
16
+ this.registry = registry;
17
+ this.f = f;
18
+ for (const line of renderSystemCard(registry).split("\n")) {
19
+ const name = /^- \*\*(\w+)\*\* — /.exec(line)?.[1];
20
+ const segment = line.split(" · ").find((part) => part.startsWith("agent:"));
21
+ if (name !== void 0 && segment !== void 0) this.segments.set(name, segment);
22
+ }
23
+ }
24
+ contract(member) {
25
+ const found = this.registry.components.find((entry) => entry.name === member);
26
+ if (found === void 0) throw new SkillFactError(`no member called ${member}`);
27
+ if (found.agent === null) throw new SkillFactError(`${member} declares nothing for an agent`);
28
+ return found.agent;
29
+ }
30
+ /** The member's `agent:` segment in code font, as the card writes it. */
31
+ segment(member) {
32
+ this.contract(member);
33
+ const found = this.segments.get(member);
34
+ if (found === void 0) throw new SkillFactError(`the card gives ${member} no agent segment`);
35
+ return `\`${found}\``;
36
+ }
37
+ /** `state` in code font, once the member's contract reads it. */
38
+ state(member, state) {
39
+ if (!this.contract(member).states.some((entry) => entry.name === state)) throw new SkillFactError(`${member}'s agent reads no state ${state}`);
40
+ return `\`${state}\``;
41
+ }
42
+ /** `action` in code font, once the member's contract runs it, taking `argument` when given. */
43
+ action(member, action, argument) {
44
+ const found = this.contract(member).actions.find((entry) => entry.name === action);
45
+ if (found === void 0) throw new SkillFactError(`${member}'s agent runs no action ${action}`);
46
+ if (argument !== void 0 && found.argument !== argument) throw new SkillFactError(`${member}'s ${action} takes ${found.argument ?? "nothing"}`);
47
+ return `\`${action}\``;
48
+ }
49
+ /** The member in code font, once its spec declares nothing for an agent. */
50
+ hidden(member) {
51
+ const found = this.registry.components.find((entry) => entry.name === member);
52
+ if (found === void 0 || found.agent !== null) throw new SkillFactError(`${member} is not a member hidden from agents`);
53
+ return this.f.m(member);
54
+ }
55
+ /** Every member whose contract `test` holds, in code font, in the registry's order. */
56
+ members(test) {
57
+ const found = this.registry.components.filter((entry) => entry.agent !== null && test(entry.agent)).map((entry) => this.f.m(entry.name));
58
+ if (found.length === 0) throw new SkillFactError("no member has that agent contract");
59
+ return found;
60
+ }
61
+ };
62
+ /** `name(args)` in code font, once the module or the file `from` declares `name`. */
63
+ function call(f, name, from, args) {
64
+ return `${f.x(name, from).slice(0, -1)}(${args})\``;
65
+ }
66
+ /**
67
+ * `polymorph-agent-bridge`: an agent on a running page reads and operates the
68
+ * mounted members through `@polymorph/engine/agent`, its tools and WebMCP.
69
+ * The procedure is the application's side of `docs/agents.md`, written for a
70
+ * reader in another repository; the API is in `references/api.md` and the
71
+ * members that need care in `references/members.md`.
72
+ */
73
+ function bridgeSkill(registry, run) {
74
+ const f = new Facts(registry);
75
+ const a = new AgentFacts(registry, f);
76
+ const agent = "@polymorph/engine/agent";
77
+ const webmcp = "@polymorph/engine/webmcp";
78
+ const secrets = all(a.members((contract) => contract.states.some((state) => state.secret)));
79
+ const body = `
80
+ # Let an agent on the page read and operate the members
81
+
82
+ The agent bridge, \`${agent}\`, lets an agent on a running page read the polymorph members the
83
+ page shows and operate them: an assistant inside the product, an agent in the browser that calls
84
+ the page's WebMCP tools, or you. Each member whose spec declares an agent section registers with
85
+ the bridge while it is mounted, in every web framework and in the \`poly-*\` elements. The bridge
86
+ reports the states that declaration names and runs the actions it names, and nothing else.
87
+
88
+ Every command in this skill starts with the same words, the polymorph tools run from a shell.
89
+ \`<framework>\` is the app's: the \`polymorph-screen\` skill says how to tell it.
90
+
91
+ ## 1. Check that the bridge is the tool
92
+
93
+ | The job | Use |
94
+ | --- | --- |
95
+ | An assistant in the product reads the screen, fills fields, chooses and presses | the page's bridge as the assistant's tools: steps 3 to 6 |
96
+ | An agent in the browser operates the page through WebMCP | the page's bridge, registered with WebMCP: steps 3 to 5 |
97
+ | You drive a page built with polymorph and want a surer way than the DOM | the tools the page registered: step 7 |
98
+ | The agent shows the person a form or a choice of its own | a run-time screen: the \`polymorph-runtime-screen\` skill |
99
+ | The agent needs a record's data, or an operation no member offers | a tool of the application's own: step 9 |
100
+ | A SwiftUI or Compose screen | nothing: native members do not register, and there is no bridge |
101
+
102
+ For each member it lists, the bridge gives an id, the member's name, its control's accessible
103
+ name and description (a field's hint and error), the member it is \`within\`, its declared states
104
+ and the actions it allows now. It never gives:
105
+
106
+ - A member that declares nothing, such as ${all([
107
+ "Text",
108
+ "Heading",
109
+ "FormField",
110
+ "Tooltip",
111
+ "CopyButton"
112
+ ].map(a.hidden, a))}, or anything that is not a member: a plain
113
+ element in a ${f.m("Bespoke")} zone, a component inside ${f.m("ThirdParty")}, the page's text.
114
+ - A member whose element is absent or inside content marked \`hidden\` (a closed ${f.m("Dialog")},
115
+ a collapsed panel), or one another member withholds (${f.m("ConfirmDialog")}'s confirm).
116
+ - A secret: ${secrets} read their value as \`{ secret: true }\`, and every password field's value
117
+ is removed from every output. Every other field's value is read, an ${f.m("Input")} that holds
118
+ a card number included: step 5 keeps such a field out.
119
+ - What a member shows beyond its states: a ${f.m("Table")} reads its sort, never its cells.
120
+ - An action of a member whose \`disabled\` state is true.
121
+
122
+ ## 2. Read what each member lets an agent do
123
+
124
+ ${commands(run, "card --framework <framework>")}
125
+
126
+ A member an agent can see ends its card line with an \`agent:\` segment: the actions an agent may
127
+ run, then, after \`|\`, the states it reads. A \`(secret)\` state reads \`{ secret: true }\`. A
128
+ member with no segment is hidden from agents.
129
+
130
+ - ${f.m("Checkbox")}: ${a.segment("Checkbox")}.
131
+ - ${f.m("Select")}: ${a.segment("Select")}. ${a.action("Select", "choose", "id")} takes the id of
132
+ one of its ${a.state("Select", "options")}, which is the ${f.field("SelectOption", "value")} of an
133
+ option the app passed.
134
+ - ${f.m("PasswordInput")}: ${a.segment("PasswordInput")}. An agent runs nothing.
135
+
136
+ The JSON answer adds the types:
137
+
138
+ ${commands(run, "component Select --framework <framework> --json")}
139
+
140
+ Under \`component.agent\`, each action gives its \`argument\` (\`boolean\`, \`number\`, \`text\`,
141
+ \`id\` or \`ids\`), the \`among\` state its ids name, and the state it \`sets\`. \`destructive\` and
142
+ \`destructiveOptions\` say what waits for a person, such as ${f.m("Button")}'s
143
+ ${f.v("Button", "tone", "danger")}. [references/members.md](references/members.md) says what each
144
+ member's ids are, and how the members that need care read and act.
145
+
146
+ ## 3. Choose how the page loads the bridge
147
+
148
+ A bundled app, in any framework, imports the bridge from \`@polymorph/engine\`, which \`init\`
149
+ installs. If \`package.json\` does not list it, add it as the other \`@polymorph/*\` packages are
150
+ listed, at their release. The members write to a registry inside that package, so the app must
151
+ resolve one copy of it: a second copy holds an empty registry. No foundation has a hook or a
152
+ component for the bridge, and nothing in a bundled app reads \`data-agent\`.
153
+
154
+ What a module imports from \`${agent}\` with a static \`import\` is in that module's chunk, and
155
+ ${f.x("createAgentBridge", agent)} is the bridge. An \`import type\` adds nothing.
156
+ \`${webmcp}\` holds the tools' definitions and their registration, and none of the bridge. So a
157
+ page that loads the bridge on its first use, by the assistant or by a WebMCP call, imports it with
158
+ \`import('${agent}')\` and registers with ${f.x("registerWebMCPOnCall", webmcp)} (step 4). A page
159
+ that loads it at once imports \`createAgentBridge\` and ${f.x("registerWebMCP", agent)}
160
+ statically. To see where the bridge went, build the app and find the file that holds
161
+ \`polymorph:agentchange\`, which only the bridge holds:
162
+ [references/testing.md](references/testing.md) has the check.
163
+
164
+ A page with no build writes no script. \`<html data-agent="on-call">\` registers the three tools
165
+ with WebMCP at load and fetches the bridge on the first call, and \`"eager"\` fetches it at load.
166
+ Without the attribute the page registers nothing, because exposing a page is its owner's
167
+ decision. The setting's bridge has no \`confirm\` and no policy, so a page that asks a person or
168
+ narrows what an agent may do creates its own: [references/no-build.md](references/no-build.md).
169
+
170
+ ## 4. Create one bridge for the page
171
+
172
+ One bridge serves the product's assistant and the browser's WebMCP agents. A bridge runs one
173
+ \`act\` at a time and asks the person inside it, so the page asks one question at a time. Two
174
+ bridges each ask, and two questions can then be open at once. This module loads the bridge on the
175
+ first call from either side:
176
+
177
+ \`\`\`ts
178
+ // src/agent/page-agent.ts
179
+ import type { AgentBridge, AgentConfirmRequest } from '${agent}'
180
+ import { registerWebMCPOnCall } from '${webmcp}'
181
+
182
+ import { policy } from './policy'
183
+
184
+ export interface PageAgent {
185
+ bridge: () => Promise<AgentBridge>
186
+ stop: () => void
187
+ }
188
+
189
+ /** Starts one bridge for the page, which the product's assistant and WebMCP share. */
190
+ export function startPageAgent(ask: (request: AgentConfirmRequest) => Promise<boolean>): PageAgent {
191
+ let stopped = false
192
+ let loading: Promise<AgentBridge> | undefined
193
+ const bridge = () =>
194
+ (loading ??= import('${agent}').then(
195
+ ({ createAgentBridge }) => {
196
+ if (stopped) throw new Error('The page agent has stopped.')
197
+ return createAgentBridge({ confirm: ask, policy })
198
+ },
199
+ (error: unknown) => {
200
+ loading = undefined // the next call loads again
201
+ throw error
202
+ },
203
+ ))
204
+ const unregister = registerWebMCPOnCall({ bridge })
205
+ return {
206
+ bridge,
207
+ stop: () => {
208
+ stopped = true
209
+ unregister()
210
+ void loading?.then((made) => made.dispose(), () => {})
211
+ },
212
+ }
213
+ }
214
+ \`\`\`
215
+
216
+ - ${call(f, "registerWebMCPOnCall", webmcp, "{ bridge }")} registers the three tools now, calls
217
+ \`bridge\` on the first call, once, and runs every call on what it resolves to: the assistant's
218
+ bridge. Unregistering removes the tools and never disposes of a bridge it did not create, so
219
+ \`stop\` disposes of it.
220
+ - Where the browser has no WebMCP API, nothing registers, and the assistant still loads the
221
+ bridge. While another registration of the tools stands on the page, such as \`data-agent\`, it
222
+ registers nothing and warns in the console.
223
+ - A page that loads the bridge at once creates it with the same options, calls
224
+ ${call(f, "registerWebMCP", agent, "bridge")}, which returns the function that unregisters, and
225
+ hands the same bridge to the assistant.
226
+
227
+ Start it in the browser once the page has mounted, keep what it returns where the assistant can
228
+ reach it, and call its \`stop\` when the page unmounts. \`ask\` asks the person, resolves \`true\`
229
+ for yes, and keeps its identity. [references/asking.md](references/asking.md) has the React
230
+ component that does this through a ${f.m("ConfirmDialog")}, and
231
+ [references/api.md](references/api.md) the call in Vue, Svelte, Solid and Angular, and each
232
+ option, field, error and event.
233
+
234
+ ## 5. Write the policy
235
+
236
+ \`policy.hide(member)\` returns \`true\` to take a member out of every output and every step, and
237
+ \`policy.deny(member, action)\` returns \`true\` to take one action away. A policy only narrows: it
238
+ cannot add a member, a state or an action. A function that throws hides or denies. The bridge
239
+ calls both on every read and step, and only about a member whose element is in the document, so
240
+ keep them cheap. \`member\` is a frozen ${f.x("AgentPolicyMember", agent)}:
241
+
242
+ | Field | What it is | Stable |
243
+ | --- | --- | --- |
244
+ | \`id\` | the bridge's id for this mount of the member | no: each mount gets a new one, which the app does not choose |
245
+ | \`member\` | the member's name, such as \`Input\` | yes, and it names every instance |
246
+ | \`name\` | its control's accessible name: the label as the page shows it | no: it changes with the language and the wording |
247
+ | \`element\` | the member's control: an ${f.m("Input")}'s \`<input>\`, a ${f.m("Button")}'s \`<button>\`, a ${f.m("Select")}'s trigger | its attributes are the ones the page sets |
248
+ | \`keys\` | the \`data-agent-key\` of each element around the control, the nearest first | yes: the page writes them |
249
+
250
+ So name a member by a key. Write \`data-agent-key\` on a plain element around the member, which
251
+ takes the member's place in the layout, or on the \`poly-*\` element itself on a page with no
252
+ build. No member takes a prop for it, so it works the same in every framework. A key names every
253
+ member inside its element, and \`keys\` holds each key around a member, so one key on a form
254
+ names its fields. ${f.m("Dialog")}, ${f.m("Drawer")} and ${f.m("Popover")} draw their panel at
255
+ the end of the document: a key around one names nothing, and a key inside its content names the
256
+ members there.
257
+
258
+ \`\`\`tsx
259
+ <div data-agent-key="place-order">
260
+ <Button label={t('Place order')} onClick={placeOrder} />
261
+ </div>
262
+ \`\`\`
263
+
264
+ \`\`\`ts
265
+ // src/agent/policy.ts
266
+ import type { AgentPolicy } from '${agent}'
267
+
268
+ export const policy: AgentPolicy = {
269
+ // Every card field, by the autocomplete token the page gives it.
270
+ hide: ({ element }) => element?.getAttribute('autocomplete')?.startsWith('cc-') === true,
271
+ // A person places the order: the page writes data-agent-key="place-order" around its Button.
272
+ deny: ({ keys = [] }, action) => keys.includes('place-order') && action === 'press',
273
+ }
274
+ \`\`\`
275
+
276
+ Read \`keys\` as \`{ keys = [] }\`: the bridge always gives them, and the type marks them optional.
277
+ An attribute a member passes to its control works too: an ${f.m("Input")}'s
278
+ ${f.p("Input", "autoComplete")} reaches its \`<input>\`. The page's code reads keys in the
279
+ policy, \`confirm\` and the change event; no output an agent reads carries them.
280
+
281
+ Card data belongs in the payment provider's own hosted field, inside a ${f.m("ThirdParty")}
282
+ boundary: it is outside the vocabulary, so the bridge never lists it.
283
+
284
+ The bridge is a filter in the page, not a security boundary. An agent acts with the person's
285
+ session, and any script on the page can create a bridge without this policy or \`confirm\`. The
286
+ server authorises every consequential action again, as it does a person's.
287
+
288
+ ## 6. Hand the tools to the product's assistant
289
+
290
+ The bridge's three tools are \`polymorph_snapshot\`, \`polymorph_query\` and \`polymorph_act\`.
291
+ ${f.x("AGENT_TOOL_DEFINITIONS", webmcp)} gives each one's \`name\`, a \`description\` written for
292
+ a model and a JSON Schema \`inputSchema\`, without the bridge, so the app sends them to its model
293
+ before the bridge loads. ${call(f, "agentTools", agent, "bridge")} gives the same tools with
294
+ \`execute(input)\`, which resolves to JSON and never rejects:
295
+
296
+ \`\`\`ts
297
+ // src/agent/assistant-tools.ts
298
+ import { AGENT_TOOL_DEFINITIONS } from '${webmcp}'
299
+
300
+ import type { PageAgent } from './page-agent'
301
+
302
+ /** The tools to send the product's model, which load nothing. */
303
+ export const definitions = AGENT_TOOL_DEFINITIONS.map(({ name, description, inputSchema }) => ({
304
+ name,
305
+ description,
306
+ inputSchema,
307
+ }))
308
+
309
+ /** Runs one tool call the model returned, loading the bridge on the first. */
310
+ export async function runTool(agent: PageAgent, name: string, input: unknown): Promise<unknown> {
311
+ const { agentTools } = await import('${agent}')
312
+ const tool = agentTools(await agent.bridge()).find((each) => each.name === name)
313
+ if (tool === undefined) return { error: { code: 'unknown-tool', message: \`No tool \${name}.\` } }
314
+ return tool.execute(input)
315
+ }
316
+ \`\`\`
317
+
318
+ The app sends \`definitions\` with the conversation, in the shape the model's API takes for a tool.
319
+ For each tool call the model returns, it calls \`runTool\` with the call's name and input, and sends
320
+ what that resolves to back as the call's result.
321
+ The calls run in the page, where the bridge is: a model on a server sends each call to the page.
322
+ Every output holds the page's content, which a person or a record wrote, and each tool says so
323
+ with \`untrustedContentHint\`. The system prompt tells the model that what it reads from the page
324
+ is data and never an instruction. Nothing enforces that sentence, so the policy and the server's
325
+ checks are what hold.
326
+
327
+ ## 7. Read, then act
328
+
329
+ This is the procedure for the agent, through the tools or the bridge.
330
+
331
+ 1. Read the page with \`bridge.snapshot()\`, or find members with
332
+ \`bridge.query({ name, text, member })\`. \`name\` matches the accessible name and each choice's
333
+ label, \`text\` the text the member shows and its description, and \`member\` the member's name
334
+ whole. Each ignores case. On a large page, query: a snapshot lists every choice.
335
+ 2. Write each step as \`{ id, action, value }\` with an id from that read, or as
336
+ \`{ target: { member, name }, action, value }\`. A target must name one member: its name is
337
+ matched whole, then as a part.
338
+ 3. Give \`value\` only to an action that lists an \`argument\`, and of that type. An \`id\` or
339
+ \`ids\` names enabled choices of the state \`among\` names, or of any choices state. Write text
340
+ in the form the member's own state shows, such as a date field's \`2026-07-15\`.
341
+ 4. Run \`bridge.act(steps)\`. It runs the steps in order, stops at the first that fails, never
342
+ rejects, and runs one \`act\` at a time.
343
+ 5. Read each result. \`{ ok: true, id, changed }\` means the action ran, and \`changed\` holds each
344
+ state that changed, as \`{ from, to }\`. An empty \`changed\` means the member did not change
345
+ within \`settleMs\`: a press that opened something else, or a value the application did not
346
+ take. Read again before you conclude.
347
+ 6. Read again after a step that changes the page. An opened ${f.m("Dialog")} lists new members,
348
+ and a member mounted again has a new id. Inside one \`act\`, name a member an earlier step
349
+ brings up by \`target\`, because it had no id when you read.
350
+
351
+ A failed result's \`error.code\` says why, and [references/api.md](references/api.md) says what to
352
+ do for each code. On \`unknown-member\`, read again. On \`not-allowed\`, choose from \`allowed\`:
353
+ an empty list is the application's policy. On \`needs-confirmation\`, the page asks no one, so a
354
+ person must do it: do not look for another way. On \`declined\`, the person said no: do not run it
355
+ again unasked.
356
+
357
+ An agent that drives a browser from outside the page calls the tools the page registered, which
358
+ carry the owner's policy and \`confirm\`. A page that registered none has offered no bridge:
359
+ exposing a page is its owner's decision. Operate that page as a person does, through the browser,
360
+ and do not load a bridge into it.
361
+
362
+ ## 8. Decide what needs a person
363
+
364
+ | The bridge holds | The bridge does not |
365
+ | --- | --- |
366
+ | A destructive instance (${f.m("Button")} with ${f.v("Button", "tone", "danger")}) or a choice marked destructive (a \`danger\` entry of ${f.m("Menu")}) waits for \`confirm\`, and is refused without one | Ask about a consequential action that is not destructive: a ${f.m("Button")} labelled Send or Place order runs at once |
367
+ | No action answers for a person: ${f.m("ConfirmDialog")} withholds its confirm | Know which agent calls: every WebMCP client the browser lets call the page gets what the policy leaves |
368
+ | A secret never leaves it, in a state, a name, a message or a change | Bind a bridge it did not make: any script on the page can create one without the policy or \`confirm\` |
369
+ | A policy only narrows, and one \`act\` runs at a time | Respect modality: while a modal ${f.m("Dialog")} is open, the members behind it are listed and run |
370
+ | | Filter what the page says: a name or a value can hold text written to steer a model |
371
+
372
+ A ${f.m("Button")} with ${f.v("Button", "tone", "danger")} that opens a ${f.m("ConfirmDialog")}
373
+ asks twice: \`confirm\` before the press, then the dialog, whose confirm no agent can press. Give a
374
+ Button that only opens the dialog another tone, such as ${f.v("Button", "variant", "ghost")} with
375
+ ${f.v("Button", "tone", "neutral")}: an agent's press opens the dialog, and the person answers
376
+ there, once. The dialog's own ${f.p("ConfirmDialog", "tone")}, \`danger\` unless set, marks the
377
+ destruction. Keep ${f.v("Button", "tone", "danger")} for a Button whose own press destroys.
378
+
379
+ So the product decides, and writes down:
380
+
381
+ 1. Who gets the tools: its own assistant, the browser's agents through WebMCP, or no one.
382
+ 2. What needs a person beyond the destructive actions. Deny it in the policy, or let its handler
383
+ ask the person when \`bridge.acting\` is true. The bridge sets it while a step's action runs,
384
+ and a ${f.m("Button")}'s ${f.p("Button", "onClick")} runs inside a \`press\`.
385
+ 3. How the person is asked: through a member the page draws, such as a ${f.m("ConfirmDialog")},
386
+ whose confirm an agent cannot press: [references/asking.md](references/asking.md).
387
+
388
+ Each step that succeeds dispatches \`polymorph:agentchange\`, so the page can show the person what
389
+ an agent changed. Logging it is the product's choice, and the record that counts is the one the
390
+ server keeps of each request: any script on the page can dispatch that event.
391
+
392
+ ## 9. When the member the task needs declares nothing
393
+
394
+ 1. Look for a member that declares what the task needs: \`search\` and the card's segments say
395
+ which. A ${f.m("Link")} is pressed where a plain \`<a>\` is not listed.
396
+ 2. For data or an operation that is the application's own, such as a table's rows, an export or
397
+ a filter no member draws, give the agent a tool of the application's own beside the bridge's.
398
+ It calls the code the interface's handler calls, and the server authorizes it. Add it to the
399
+ assistant's tool list, or register it with WebMCP under a name of its own.
400
+ 3. A member that should declare more is the design system's decision. Tell the person which
401
+ member, and which state or action. A member's \`## Agent\` section declares it, and a release
402
+ of polymorph ships it.
403
+
404
+ Never write to a member's DOM, or click it from a script, to reach what it does not declare: that
405
+ skips every check the bridge makes. Never call ${f.x("agentMember", "@polymorph/engine")} or
406
+ ${f.x("useAgentMember", "@polymorph/react")} from application code: a handle the application
407
+ writes is held to no spec, and the bridge would list it as a member. Take step 2 instead.
408
+
409
+ ## 10. Test it
410
+
411
+ Test the bridge in a real browser, as polymorph does, with Vitest's browser mode and Playwright:
412
+ the bridge reads the rendered page, its accessible names and what is in the document.
413
+ [references/testing.md](references/testing.md) has the setup, a test to copy, the traps, and how
414
+ to check that the bridge is not in what the page loads at start. \`validate\` and \`check\` read
415
+ the red rules and not prop values, so run the project's typecheck as well.
416
+ `;
417
+ return [
418
+ {
419
+ path: "polymorph-agent-bridge/SKILL.md",
420
+ contents: skill("polymorph-agent-bridge", "Let an AI agent on a running page read and operate the polymorph members through the agent bridge, instead of scraping the DOM or clicking coordinates. Use when asked to let an in-app assistant or chatbot fill a form or operate a screen, make a page usable by an AI agent or a browser agent, expose a page’s actions as tools for a model, add WebMCP (document.modelContext) tools, keep a field such as a card number or an action such as placing an order from an agent (data-agent-key), ask the person before an agent acts, put data-agent on a page with no build, read the agent segment of the polymorph system card, or drive a page built with polymorph from an agent. Covers @polymorph/engine/agent (createAgentBridge, snapshot, query, act, confirm, the policy, secrets, agentTools, registerWebMCP), @polymorph/engine/webmcp (registerWebMCPOnCall, applyAgentSetting, AGENT_TOOL_DEFINITIONS), one bridge shared by an assistant and WebMCP and loaded on its first use, loadAgentBridge in polymorph.js, and testing a bridge.", body)
421
+ },
422
+ {
423
+ path: "polymorph-agent-bridge/references/api.md",
424
+ contents: apiReference(registry)
425
+ },
426
+ {
427
+ path: "polymorph-agent-bridge/references/members.md",
428
+ contents: membersReference(registry, run)
429
+ },
430
+ {
431
+ path: "polymorph-agent-bridge/references/asking.md",
432
+ contents: askingReference(registry)
433
+ },
434
+ {
435
+ path: "polymorph-agent-bridge/references/testing.md",
436
+ contents: testingReference(registry)
437
+ },
438
+ {
439
+ path: "polymorph-agent-bridge/references/no-build.md",
440
+ contents: noBuildReference(registry)
441
+ }
442
+ ];
443
+ }
444
+ /** The bridge's API, entry point by entry point, as the published packages export it. */
445
+ function apiReference(registry) {
446
+ const f = new Facts(registry);
447
+ const agent = "@polymorph/engine/agent";
448
+ const webmcp = "@polymorph/engine/webmcp";
449
+ const testing = "@polymorph/engine/testing";
450
+ const types = [
451
+ "AgentBridge",
452
+ "AgentBridgeOptions",
453
+ "AgentConfirmRequest",
454
+ "AgentPolicy",
455
+ "AgentPolicyMember",
456
+ "AgentSnapshot",
457
+ "AgentSnapshotMember",
458
+ "AgentSnapshotAction",
459
+ "AgentQuery",
460
+ "AgentMatch",
461
+ "AgentStep",
462
+ "AgentStepResult",
463
+ "AgentActResult",
464
+ "AgentChange",
465
+ "AgentChangeDetail",
466
+ "AgentError",
467
+ "AgentErrorCode",
468
+ "AgentTool",
469
+ "AgentToolName",
470
+ "AgentToolAnnotations"
471
+ ].map((name) => f.x(name, agent));
472
+ return `# The agent bridge's API
473
+
474
+ What each entry point exports, as the published packages have them. \`@polymorph/engine\` is
475
+ installed under that name, as an alias of \`@metamorph-labs/polymorph-engine\`.
476
+
477
+ ## \`${agent}\`
478
+
479
+ A static import of a value from this entry point puts it in the importing module's chunk:
480
+ \`createAgentBridge\` is the bridge. A page that loads the bridge on its first use imports it with
481
+ \`import('${agent}')\`, and imports only types from it statically.
482
+
483
+ | Export | What it is |
484
+ | --- | --- |
485
+ | ${call(f, "createAgentBridge", agent, "options?")} | a bridge over the members mounted on the page. Two bridges read the same registry and report the same ids, and each runs its own acts and asks its own questions |
486
+ | ${call(f, "agentTools", agent, "bridge")} | the bridge as three tools, for the application's own agent |
487
+ | ${call(f, "registerWebMCP", agent, "bridge")} | registers those tools with the browser's WebMCP API, and returns the function that unregisters them |
488
+ | ${f.x("AGENT_CHANGE_EVENT", agent)} | \`'polymorph:agentchange'\` |
489
+ | ${f.x("AGENT_KEY_ATTRIBUTE", agent)} | \`'data-agent-key'\`, the attribute whose value a policy reads in \`keys\` |
490
+ | ${f.x("AGENT_SETTLE_MS", agent)} | \`150\`, the default \`settleMs\` |
491
+
492
+ Types: ${all(types)}.
493
+
494
+ ### The bridge
495
+
496
+ | Member | What it does |
497
+ | --- | --- |
498
+ | \`snapshot()\` | \`{ members }\`: each listed member, in document order |
499
+ | \`query(query)\` | the members that match, each \`{ id, member, name, option? }\` |
500
+ | \`act(steps)\` | runs the steps in order and resolves to \`{ results }\`, stopping at the first that fails. It never rejects. One \`act\` runs at a time: the next waits for it, also while it waits for \`confirm\` |
501
+ | \`subscribe(listener)\` | calls \`listener\` after each step that succeeds, and returns the function that stops it. A listener that throws does not fail the step |
502
+ | \`acting\` | \`true\` while a step's action runs |
503
+ | \`dispose()\` | stops the bridge: it lists nothing after this, and a step answers \`unknown-member\` |
504
+
505
+ ### Options
506
+
507
+ | Option | What it takes |
508
+ | --- | --- |
509
+ | \`confirm\` | \`(request) => boolean \\| Promise<boolean>\`. \`request\` is \`{ id, member, name, action, value?, keys }\`. Only \`true\` is yes. A \`confirm\` that throws or rejects is a no. The state is read again after the answer, and a member removed while the person was asked answers \`unknown-member\` |
510
+ | \`policy.hide\` | \`(member) => boolean\`. \`member\` is \`{ id, member, name, element, keys }\`, frozen: the bridge's id for this mount, the member's name, its control's accessible name, its control, and the \`data-agent-key\` of each element around the control, the nearest first. A truthy answer takes the member out of every output and every step. The bridge asks only about a member whose element is in the document and not inside \`hidden\` content, and never about one another member withholds |
511
+ | \`policy.deny\` | \`(member, action) => boolean\`, with the same \`member\`. A truthy answer takes the action away, and a step that names it answers \`not-allowed\`. Either function that throws hides or denies |
512
+ | \`settleMs\` | milliseconds a step waits for the member's state to change after its action. The bridge reads the state again every few milliseconds and stops at the first change |
513
+
514
+ ### Starting the page agent in each framework
515
+
516
+ \`startPageAgent\` is the function of step 4 of the skill. Call it where the framework runs code in
517
+ the browser after mounting, keep what it returns for the assistant, and call its \`stop\` when the
518
+ page unmounts:
519
+
520
+ \`\`\`ts
521
+ // React: the component in references/asking.md.
522
+
523
+ // Vue, in <script setup>
524
+ let agent: PageAgent | undefined
525
+ onMounted(() => {
526
+ agent = startPageAgent(ask)
527
+ })
528
+ onBeforeUnmount(() => agent?.stop())
529
+
530
+ // Svelte, in <script>
531
+ onMount(() => startPageAgent(ask).stop)
532
+
533
+ // Solid, in a component
534
+ onMount(() => onCleanup(startPageAgent(ask).stop))
535
+
536
+ // Angular, in a component's constructor. afterNextRender runs in the browser only.
537
+ const destroyRef = inject(DestroyRef)
538
+ afterNextRender(() => destroyRef.onDestroy(startPageAgent(ask).stop))
539
+ \`\`\`
540
+
541
+ ### A snapshot entry
542
+
543
+ | Field | What it holds |
544
+ | --- | --- |
545
+ | \`id\` | the instance's id, stable while it is mounted. A member mounted again has a new one |
546
+ | \`member\` | the member's name |
547
+ | \`name\` | the accessible name of its control: from \`aria-labelledby\`, \`aria-label\`, its \`<label>\`, \`alt\`, its text or \`title\`. A table is named by its caption, never its cells |
548
+ | \`description\` | the text its control's \`aria-describedby\` names: a field's hint and error. Absent when empty, and for a member that holds a secret |
549
+ | \`within\` | the id of the nearest listed member whose element contains this one's |
550
+ | \`state\` | the declared states, read now. A secret one, and one that holds a secret, is \`{ secret: true }\` |
551
+ | \`actions\` | each action allowed now: \`{ name, argument?, among?, confirm? }\`. \`confirm: true\` means a person must confirm it. A disabled member lists none |
552
+
553
+ A snapshot has no size limit of its own: it lists every listed member with every choice of each,
554
+ such as every option of a long ${f.m("Select")}. Only a chart caps its marks. To keep what a model
555
+ reads small, use \`query\`, hide the members outside the region the agent works in with
556
+ \`policy.hide\`, or page the content the members show.
557
+
558
+ ### A step and its result
559
+
560
+ A step is \`{ id?, target?: { member?, name? }, action, value? }\`. A result is
561
+ \`{ ok: true, id, changed }\`, where \`changed\` maps each state that changed to \`{ from, to }\`, or
562
+ \`{ ok: false, id?, error: { code, message, allowed? } }\`. A state that holds a secret is left out
563
+ of \`changed\`.
564
+
565
+ | Code | When | Do |
566
+ | --- | --- | --- |
567
+ | \`unknown-member\` | the id names no listed member, the target names none, or the member was removed while the person was asked | read again: the member is gone, closed, hidden, withheld or declares nothing |
568
+ | \`ambiguous-target\` | the target names more than one member. The message lists their ids | name it by one of those ids |
569
+ | \`not-allowed\` | the member does not declare the action, or the policy denies it. \`allowed\` lists the actions it allows now | choose from \`allowed\`. An empty list is the application's policy |
570
+ | \`disabled\` | the member's \`disabled\` state is true | do what enables it, or tell the person |
571
+ | \`invalid-value\` | the value is not of the argument's type, names no enabled choice, or the step is not an object | read the action's argument and the member's choices again |
572
+ | \`needs-confirmation\` | the action needs a person, and the bridge has no \`confirm\` | leave it to a person. Do not look for another way |
573
+ | \`declined\` | the person said no, or \`confirm\` failed | do not run it again unasked |
574
+ | \`failed\` | the action threw, with the member's message, any secret replaced | read the message, such as a read-only field's refusal |
575
+
576
+ ### Change events
577
+
578
+ A step that succeeds dispatches \`polymorph:agentchange\`, bubbling, on the element its member names
579
+ after the step; when that is gone, on the element it named before, while that is in the document;
580
+ and otherwise on the document. The detail is
581
+ \`{ id, member, action, changed, source: 'agent', keys }\`, the same object \`subscribe\` hands its listeners. A step whose \`changed\` is empty dispatches one
582
+ too, and a step that fails dispatches none. \`references/asking.md\` shows a listener.
583
+
584
+ ### The tools
585
+
586
+ | Name | Title | Input | Annotations |
587
+ | --- | --- | --- | --- |
588
+ | \`polymorph_snapshot\` | Read the page | \`{}\` | \`readOnlyHint\`, \`untrustedContentHint\` |
589
+ | \`polymorph_query\` | Find controls on the page | \`{ name?, text?, member? }\`, strings | \`readOnlyHint\`, \`untrustedContentHint\` |
590
+ | \`polymorph_act\` | Operate controls on the page | \`{ steps }\`, each \`{ id?, target?, action, value? }\` | \`consequentialHint\`, \`untrustedContentHint\` |
591
+
592
+ Each tool's \`execute(input)\` resolves to JSON and never rejects. A malformed input is answered:
593
+ \`polymorph_act\` given no list of steps resolves to one \`invalid-value\` result. The tools'
594
+ definitions alone are \`AGENT_TOOL_DEFINITIONS\` in \`${webmcp}\`, which holds none of the bridge.
595
+
596
+ ## \`${webmcp}\`
597
+
598
+ It holds the tools' definitions and their registration, and none of the bridge, so importing it
599
+ keeps the bridge out of the bundle.
600
+
601
+ | Export | What it does |
602
+ | --- | --- |
603
+ | ${call(f, "registerWebMCPOnCall", webmcp, "load, options?")} | registers the three tools now. On the first call it runs \`load\` once and creates the bridge with \`options\` from what \`load\` resolves to: \`${agent}\`, or an object with its \`createAgentBridge\` and \`agentTools\`. Calls that arrive while it loads wait for it. A failed load answers each waiting call with \`{ error: { code: 'failed', message } }\`, and the next call loads again. Returns the function that unregisters the tools and disposes of the bridge it created |
604
+ | ${call(f, "registerWebMCPOnCall", webmcp, "{ bridge }")} | the same registration on a bridge the page already has: \`bridge\` is the bridge, or a function that returns it or a promise of it, called once on the first call and again on the next call after it fails or gives no bridge. Returns the function that unregisters the tools, which never disposes of that bridge |
605
+ | ${call(f, "applyAgentSetting", webmcp, "value")} | does what a \`data-agent\` value says: \`null\` registers nothing, \`'on-call'\` registers as \`registerWebMCPOnCall\` does, \`'eager'\` also loads the bridge at once, and another value warns. The bridge has no options. Returns the function that unregisters |
606
+ | ${f.x("AGENT_ATTRIBUTE", webmcp)} | \`'data-agent'\` |
607
+ | ${f.x("AGENT_TOOL_DEFINITIONS", webmcp)} | the three tools' \`name\`, \`title\`, \`description\`, \`inputSchema\` and \`annotations\`, frozen, in the order \`agentTools\` lists them |
608
+
609
+ Types: ${f.x("AgentSetting", webmcp)}, ${f.x("AgentBridgeModule", webmcp)},
610
+ ${f.x("SharedAgentBridge", webmcp)} and ${f.x("AgentToolDefinition", webmcp)}.
611
+
612
+ A page whose only agents are the browser's registers in an effect and returns what unregisters.
613
+ The bundler puts the bridge in a chunk the page fetches on the first call:
614
+
615
+ \`\`\`tsx
616
+ 'use client'
617
+
618
+ import { useEffect } from 'react'
619
+ import { registerWebMCPOnCall } from '${webmcp}'
620
+
621
+ /** Registers the tools now, and fetches and creates the bridge on the first call. */
622
+ export function OnCallAgent({ ask }: { ask: (question: string) => Promise<boolean> }) {
623
+ useEffect(
624
+ () =>
625
+ registerWebMCPOnCall(() => import('${agent}'), {
626
+ confirm: (request) => ask(\`\${request.action} “\${request.name}”?\`),
627
+ }),
628
+ [ask],
629
+ )
630
+ return null
631
+ }
632
+ \`\`\`
633
+
634
+ A bundled app that wants the no-build setting's behaviour reads the attribute itself:
635
+
636
+ \`\`\`ts
637
+ import { AGENT_ATTRIBUTE, applyAgentSetting } from '${webmcp}'
638
+
639
+ const stop = applyAgentSetting(document.documentElement.getAttribute(AGENT_ATTRIBUTE))
640
+ \`\`\`
641
+
642
+ Every registration needs the browser's WebMCP API: \`document.modelContext\`, or
643
+ \`navigator.modelContext\` in earlier builds. Where neither exists, nothing registers or loads.
644
+
645
+ ## \`${testing}\`
646
+
647
+ | Export | What it does |
648
+ | --- | --- |
649
+ | ${call(f, "agentRegistrations", testing, "")} | every registered member as \`{ id, member, element, withholds }\`, withheld ones included, with no state and no action |
650
+ | ${call(f, "installTestTheme", testing, "")} | installs a theme, so a member's computed style reads a token |
651
+ | ${call(f, "fixedWidthHost", testing, "width?")} | a host element of a fixed width in the body |
652
+ `;
653
+ }
654
+ /** The data type a member's prop takes a list of, as the registry names it. */
655
+ function listType(registry, member, prop) {
656
+ const found = (registry.components.find((entry) => entry.name === member)?.props.find((entry) => entry.name === prop)?.type)?.match(/\w+/g)?.find((word) => registry.dataTypes.some((entry) => entry.name === word));
657
+ if (found === void 0) throw new SkillFactError(`${member}'s ${prop} takes no declared type`);
658
+ return found;
659
+ }
660
+ /** How the members that need care read and act, each name read from its agent contract. */
661
+ function membersReference(registry, run) {
662
+ const f = new Facts(registry);
663
+ const a = new AgentFacts(registry, f);
664
+ const menus = all(a.members((contract) => contract.destructiveOptions.length > 0));
665
+ const charts = a.members((contract) => contract.states.some((state) => state.name === "count"));
666
+ const legends = a.members((contract) => contract.actions.some((each) => each.name === "toggle"));
667
+ const brushes = a.members((contract) => contract.actions.some((each) => each.name === "brush"));
668
+ const emptyOption = [f.p("Select", "emptyOption"), f.p("TreeSelect", "emptyOption")][0];
669
+ const ids = [
670
+ [
671
+ "Select",
672
+ "options",
673
+ "id",
674
+ "value"
675
+ ],
676
+ [
677
+ "Combobox",
678
+ "options",
679
+ "id",
680
+ "value"
681
+ ],
682
+ [
683
+ "MultiSelect",
684
+ "options",
685
+ "ids",
686
+ "value"
687
+ ],
688
+ [
689
+ "TreeSelect",
690
+ "items",
691
+ "id",
692
+ "id"
693
+ ],
694
+ [
695
+ "RadioGroup",
696
+ "options",
697
+ "id",
698
+ "value"
699
+ ],
700
+ [
701
+ "CheckboxGroup",
702
+ "options",
703
+ "ids",
704
+ "value"
705
+ ],
706
+ [
707
+ "SegmentedControl",
708
+ "options",
709
+ "id",
710
+ "value"
711
+ ],
712
+ [
713
+ "ChoiceCard",
714
+ "options",
715
+ "ids",
716
+ "value"
717
+ ],
718
+ [
719
+ "Tabs",
720
+ "tabs",
721
+ "id",
722
+ "value"
723
+ ]
724
+ ].map(([member, prop, argument, field]) => {
725
+ const type = listType(registry, member, prop);
726
+ a.action(member, "choose", argument);
727
+ const takes = argument === "id" ? "one id" : "the whole set of ids";
728
+ return `| ${f.m(member)} | ${takes} | the ${f.field(type, field)} of an entry of ${f.p(member, prop)}, a ${f.x(type, "@polymorph/react-ui")} |`;
729
+ });
730
+ return `# How the members read and act
731
+
732
+ The card names each member's actions and states. This file says what the names mean where a
733
+ caller can go wrong. The JSON answer of \`component\` gives each one's type:
734
+
735
+ ${commands(run, "component LineChart --framework <framework> --json")}
736
+
737
+ ## What holds for every member
738
+
739
+ - **A choice** is \`{ id, label }\`, with \`disabled: true\` on one a person cannot pick and
740
+ \`destructive: true\` on one that waits for a person. An action that takes \`id\` names one
741
+ choice, and one that takes \`ids\` names the whole set. A repeated id takes \` (2)\` after it.
742
+ - **The application owns a controlled value.** A member whose value the application holds changes
743
+ when the application passes the new value back. Until it does, a step succeeds with an empty
744
+ \`changed\`.
745
+ - **A press is a person's press.** An action that presses a link takes the path a person's click
746
+ takes: \`onNavigate\` routes it, or the browser leaves the page, and the step may never return.
747
+ - **A refusal is a \`failed\` step** with the member's reason: a read-only field refuses
748
+ ${a.action("Input", "fill", "text")}, and a ${f.m("Dialog")} that is not dismissible refuses
749
+ ${a.action("Dialog", "close")}.
750
+
751
+ ## What an id names
752
+
753
+ A member drawn from a list the application passes names each choice by a field of the entry. The
754
+ text answer of \`${run} component <Name> --framework <framework>\` prints that entry's fields under
755
+ Types.
756
+
757
+ | Member | \`choose\` takes | Each id is |
758
+ | --- | --- | --- |
759
+ ${ids.join("\n")}
760
+
761
+ - ${f.m("Select")} and ${f.m("TreeSelect")} with ${emptyOption} list the empty choice as \`''\`.
762
+ - An entry with \`disabled: true\` is listed with that flag, and a step that names it answers
763
+ \`invalid-value\`.
764
+ - Another member names its choices as it says below, such as a ${f.m("Menu")} entry by its label.
765
+
766
+ ## Fields
767
+
768
+ - ${f.m("Input")}, ${f.m("Textarea")} and ${f.m("SearchInput")}: ${a.action("Input", "fill", "text")}
769
+ writes the whole value, as typing it does, and ${a.action("Input", "clear")} empties it. Their
770
+ value is read, whatever the field holds: only ${f.m("PasswordInput")}, ${f.m("OTPInput")} and a
771
+ password field keep a value secret.
772
+ - ${f.m("NumberInput")}: ${a.action("NumberInput", "set", "number")} commits a number held within
773
+ its bounds, and ${a.action("NumberInput", "clear")} commits \`null\`.
774
+ - ${f.m("Slider")}: ${a.action("Slider", "set", "number")} moves the first thumb and
775
+ ${a.action("Slider", "set-high", "number")} the second of a range.
776
+ - A field that holds formatted text takes the form its own ${a.state("DatePicker", "value")}
777
+ shows, and refuses another form with the reason. ${f.m("DatePicker")} takes \`2026-07-15\`, or
778
+ \`2026-07-15T09:30:00\` at a time granularity. ${f.m("DateRangePicker")} takes
779
+ \`2026-06-01/2026-06-14\`. ${f.m("TimeInput")} takes \`09:30:00\`. ${f.m("PhoneInput")} takes a
780
+ number with its \`+\` code or the national number, and reads the E.164 value.
781
+ - ${f.m("FormField")} declares nothing. Its label names the control, and its hint and its error are
782
+ the control's \`description\`, which an agent reads after a fill.
783
+ - ${f.m("PasswordInput")} and ${f.m("OTPInput")} run nothing. A person types a secret.
784
+ - ${f.m("FileUpload")} runs ${a.action("FileUpload", "remove", "id")} and
785
+ ${a.action("FileUpload", "retry", "id")} on the ${a.state("FileUpload", "rows")} ids, and adds
786
+ no file: a file is on the person's disk.
787
+
788
+ ## Choices
789
+
790
+ - A choice made while a list is closed needs no \`open\` first.
791
+ - ${f.m("Combobox")}: ${a.action("Combobox", "choose", "id")} picks among every option the
792
+ application passed, not only those the typed text leaves, and
793
+ ${a.action("Combobox", "fill", "text")} types the query, which the application hears as typing.
794
+ - ${f.m("MultiSelect")}: ${a.action("MultiSelect", "choose", "ids")} sets the whole selection, and
795
+ \`[]\` clears it.
796
+ - ${menus}: \`choose\` runs an entry by its id, without opening the menu. The id is the entry's
797
+ label, after each enclosing submenu's label and, on a ${f.m("Menubar")}, its menu's title, joined
798
+ by \` / \` (\`Move to / Billing\`, \`File / Save\`). A \`danger\` entry waits for a person.
799
+
800
+ ## Overlays and disclosure
801
+
802
+ - A closed ${f.m("Dialog")}, ${f.m("Drawer")} or ${f.m("Popover")} is not listed. Press the
803
+ control that opens it, usually a ${f.m("Button")}, then read again. An open one runs
804
+ \`close\`. A ${f.m("Dialog")} that is not dismissible is answered with one of its own Buttons.
805
+ - ${f.m("ConfirmDialog")} runs ${a.action("ConfirmDialog", "cancel")} only. Its confirm is the
806
+ person's. The Button that opens it is the application's, and an agent presses it: a
807
+ ${f.v("Button", "tone", "danger")} one asks \`confirm\` first, so the person is asked twice.
808
+ - Content in a closed ${f.m("Accordion")} item, ${f.m("Collapsible")} or tab is not listed. Run
809
+ ${a.action("Accordion", "expand", "id")}, ${a.action("Collapsible", "open")} or
810
+ ${a.action("Tabs", "choose", "id")} first, then read again.
811
+ - A modal does not hide the page behind it from the bridge, and neither does a stylesheet: only
812
+ an absent element and content marked \`hidden\` are left out. Read \`within\` to tell the members
813
+ inside an open ${f.m("Dialog")} from the ones behind it.
814
+
815
+ ## Tables, lists and paging
816
+
817
+ - ${f.m("Table")}: ${a.state("Table", "columns")} lists the sortable headers, each by its label.
818
+ ${a.action("Table", "sort", "id")} presses a header once, and the application decides the order,
819
+ so read ${a.state("Table", "sort-key")} and ${a.state("Table", "sort-direction")} afterwards.
820
+ - ${f.m("DataTable")}: ${a.action("DataTable", "sort-ascending", "id")} and
821
+ ${a.action("DataTable", "sort-descending", "id")} take a column's key. Its row Checkboxes and
822
+ disclosure Buttons are members listed \`within\` it, and ${a.state("DataTable", "selection")}
823
+ and ${a.state("DataTable", "expanded")} read row ids.
824
+ - No table reads its cells. A model that needs the rows gets them from a tool of the
825
+ application's own.
826
+ - ${f.m("List")}: ${a.action("List", "choose", "id")} presses an item, whose id is its \`href\`, or
827
+ its title when it has none. An item that is only read is not a choice.
828
+ - ${f.m("Pagination")}: ${a.action("Pagination", "set", "number")} asks for a page by its number.
829
+
830
+ ## Charts
831
+
832
+ A chart is listed while a person has something to operate in it: ${f.p("LineChart", "onSelect")}
833
+ on ${all(charts)}, a legend that hides and shows a series on ${all(legends)}, or a brush on
834
+ ${all(brushes)}. Without \`onSelect\`, ${a.state("LineChart", "items")} is empty.
835
+
836
+ - \`items\` lists at most ${f.x("CHART_MARK_CAP", "@polymorph/engine")} marks: the whole positions
837
+ around the reading position. ${a.state("LineChart", "position")} is the reading position, and
838
+ ${a.state("LineChart", "count")} how many positions the chart has.
839
+ - ${a.action("LineChart", "read", "number")} moves the reading, which brings other marks into
840
+ \`items\`. ${a.action("LineChart", "choose", "id")} picks a listed mark as Enter does, so
841
+ \`onSelect\` receives what a person's press reports.
842
+ - ${a.action("LineChart", "toggle", "id")} hides or shows one of ${a.state("LineChart", "series")},
843
+ and ${a.state("LineChart", "hidden")} lists the hidden ones. \`choose\` and \`toggle\` each name,
844
+ as \`among\`, the list their id belongs to, and each refuses an id of the other list.
845
+ - ${a.action("LineChart", "brush", "number")} takes the row a range ends on and commits the range,
846
+ and ${a.state("LineChart", "range-start")} and ${a.state("LineChart", "range-end")} read it.
847
+
848
+ ## Toasts and the app shell
849
+
850
+ - ${f.m("Toast")} is one member on the viewport. ${a.state("Toast", "notices")} lists the notices
851
+ on screen by their ids, ${a.state("Toast", "details")} says what each holds, and
852
+ ${a.action("Toast", "dismiss", "id")} and ${a.action("Toast", "act", "id")} answer one. Neither
853
+ waits for a person.
854
+ - ${f.m("AppShell")}: ${a.action("AppShell", "go", "id")} presses one of
855
+ ${a.state("AppShell", "destinations")}, and ${a.state("AppShell", "current")} is where the person
856
+ is. ${a.action("AppShell", "collapse")} and ${a.action("AppShell", "expand")} work the rail,
857
+ and ${a.action("AppShell", "open")} and ${a.action("AppShell", "close")} the drawer below its
858
+ breakpoint.
859
+
860
+ ## What no agent does
861
+
862
+ - Type a secret, or reveal one.
863
+ - Add a file to ${f.m("FileUpload")}, or start a ${f.m("RecordButton")}, which runs
864
+ ${a.action("RecordButton", "stop")} only.
865
+ - Confirm for a person: ${f.m("ConfirmDialog")}'s confirm and ${f.m("ApprovalCard")}'s answers are
866
+ withheld.
867
+ - Press a ${f.m("Link")} that opens a new tab: a browser opens one only in a person's own gesture.
868
+ - Read or run ${either([
869
+ "CopyButton",
870
+ "Tooltip",
871
+ "HoverCard",
872
+ "Plan",
873
+ "ChatMessage"
874
+ ].map((name) => a.hidden(name)))},
875
+ which declare nothing.
876
+ `;
877
+ }
878
+ /** How the person is asked, and how an application records what an agent did. */
879
+ function askingReference(registry) {
880
+ const f = new Facts(registry);
881
+ const agent = "@polymorph/engine/agent";
882
+ return `# Asking the person
883
+
884
+ \`confirm\` is the application's, and it asks the person at the page. The bridge calls it with
885
+ \`{ id, member, name, action, value?, keys }\` before an action that needs a person, and runs the action
886
+ only when it resolves \`true\`. An agent cannot answer it, and a \`confirm\` that throws is a no.
887
+
888
+ ## In React, through a ${f.m("ConfirmDialog")}
889
+
890
+ This component starts the page's one bridge with \`startPageAgent\` from step 4 of the skill, hands
891
+ what that returns to \`onStart\`, and asks through a ${f.m("ConfirmDialog")}. The dialog withholds
892
+ its confirm, so no agent presses Allow.
893
+
894
+ \`\`\`tsx
895
+ 'use client'
896
+
897
+ import { useCallback, useEffect, useRef, useState } from 'react'
898
+ import type { AgentConfirmRequest } from '${agent}'
899
+ import { ConfirmDialog } from '@polymorph/react-ui'
900
+
901
+ import { startPageAgent, type PageAgent } from './page-agent'
902
+
903
+ /** Starts the page's one bridge, hands it to \`onStart\`, and asks the person through a ConfirmDialog. */
904
+ export function PageAgentHost({ onStart }: { onStart: (agent: PageAgent | null) => void }) {
905
+ const [asking, setAsking] = useState<AgentConfirmRequest | null>(null)
906
+ const answer = useRef<(yes: boolean) => void>(() => {})
907
+ const ask = useCallback(
908
+ (request: AgentConfirmRequest) =>
909
+ new Promise<boolean>((resolve) => {
910
+ answer.current = (yes) => {
911
+ // Once: the close ConfirmDialog makes after Allow finds nothing left to answer.
912
+ answer.current = () => {}
913
+ setAsking(null)
914
+ resolve(yes)
915
+ }
916
+ setAsking(request)
917
+ }),
918
+ [],
919
+ )
920
+ useEffect(() => {
921
+ const agent = startPageAgent(ask)
922
+ onStart(agent)
923
+ return () => {
924
+ onStart(null)
925
+ agent.stop()
926
+ answer.current(false)
927
+ }
928
+ }, [ask, onStart])
929
+ return (
930
+ <ConfirmDialog
931
+ open={asking !== null}
932
+ title="Let the assistant do this?"
933
+ description={asking === null ? '' : \`The assistant asks to \${asking.action} “\${asking.name}”.\`}
934
+ confirmLabel="Allow"
935
+ onConfirm={() => answer.current(true)}
936
+ onOpenChange={(open) => {
937
+ if (!open) answer.current(false)
938
+ }}
939
+ />
940
+ )
941
+ }
942
+ \`\`\`
943
+
944
+ - Render it once on the page. Give it an \`onStart\` that keeps its identity, such as a state
945
+ setter, and hand the agent it receives to the assistant (\`runTool(agent, name, input)\`, step
946
+ 6). It receives \`null\` once the page unmounts.
947
+ - One question is open at a time. The page has one bridge, the bridge asks inside the one \`act\`
948
+ it runs, and the next \`act\`, from the assistant or from WebMCP, waits.
949
+ - \`answer\` runs once per question. ${f.m("ConfirmDialog")} calls
950
+ ${f.p("ConfirmDialog", "onOpenChange")} with \`false\` after ${f.p("ConfirmDialog", "onConfirm")},
951
+ and that close finds nothing left to answer.
952
+ - Closing the dialog any other way, and unmounting the page while the person is asked, answer no.
953
+ - \`ask\` keeps its identity, so the bridge is made once.
954
+ - \`request.name\` is the member's accessible name on this page, and \`request.value\` is what the
955
+ agent asked to set or choose. Say both in the question, so the person knows what they allow.
956
+ \`request.keys\` are the page's keys for the member, for a question worded per control.
957
+ - Other frameworks do the same with their own state and the framework's ${f.m("ConfirmDialog")}.
958
+ A page with no build can ask with \`window.confirm\`, as \`references/no-build.md\` shows.
959
+
960
+ ## Recording what an agent did
961
+
962
+ Each step that succeeds dispatches ${f.x("AGENT_CHANGE_EVENT", agent)}, \`polymorph:agentchange\`,
963
+ bubbling, on its member's element, or on the document when the step removed that element. The
964
+ detail is \`{ id, member, action, changed, source: 'agent', keys }\`. \`bridge.subscribe(listener)\` hands
965
+ a listener the same object, and returns the function that stops it.
966
+
967
+ \`\`\`ts
968
+ document.addEventListener('polymorph:agentchange', (event) => {
969
+ const { id, member, action, changed, keys } = (event as CustomEvent).detail
970
+ console.info('the agent ran', action, 'on', member, id, keys, changed)
971
+ })
972
+ \`\`\`
973
+
974
+ A step whose \`changed\` is empty dispatches one too, and a step that fails dispatches none. The
975
+ event is for the page's own code: to tell the person what the agent changed, or to log it, which is
976
+ the product's choice. It is no audit record. Any script on the page can dispatch an event of that
977
+ name, so the record that counts is the one the server keeps of each request it authorises.
978
+
979
+ ## Telling an agent's change from a person's
980
+
981
+ \`bridge.acting\` is \`true\` while a step's action runs. A member's handler keeps its signature, so
982
+ ${f.m("Checkbox")}'s ${f.p("Checkbox", "onCheckedChange")} receives the same value from an agent's
983
+ \`check\` as from a person's press. A handler that must treat the two apart reads \`bridge.acting\`
984
+ when it is called: a ${f.m("Button")}'s ${f.p("Button", "onClick")} runs inside the agent's
985
+ \`press\`, so it reads \`true\` there. Such a handler can ask the person before it places an order,
986
+ in place of a policy that denies the press.
987
+ `;
988
+ }
989
+ /** How a consumer tests a bridge over its own screens. */
990
+ function testingReference(registry) {
991
+ const f = new Facts(registry);
992
+ const agent = "@polymorph/engine/agent";
993
+ const testing = "@polymorph/engine/testing";
994
+ return `# Testing the bridge
995
+
996
+ The bridge reads the rendered page: each control's accessible name, whether its element is in the
997
+ document and drawn, and the state the member reads from it. A test of it renders the screen in a
998
+ real browser. polymorph tests its members this way, in Chromium through Playwright, with Vitest's
999
+ browser mode.
1000
+
1001
+ ## Set it up
1002
+
1003
+ Install Vitest, its Playwright provider and Playwright, and a browser for Playwright. The provider
1004
+ package takes the same version as \`vitest\`. A React app adds Testing Library and React's Vite
1005
+ plugin, as below; another framework adds its own.
1006
+
1007
+ \`\`\`sh
1008
+ npm install --save-dev vitest @vitest/browser-playwright playwright @testing-library/react @vitejs/plugin-react
1009
+ npx playwright install chromium
1010
+ \`\`\`
1011
+
1012
+ Declare the browser in the Vitest config. If the app has a \`vite.config.ts\`, put \`test\` there,
1013
+ so the tests build the members as the app does.
1014
+
1015
+ \`\`\`ts
1016
+ // vitest.config.ts
1017
+ import react from '@vitejs/plugin-react'
1018
+ import { playwright } from '@vitest/browser-playwright'
1019
+ import { defineConfig } from 'vitest/config'
1020
+
1021
+ export default defineConfig({
1022
+ plugins: [react()],
1023
+ test: {
1024
+ browser: {
1025
+ enabled: true,
1026
+ headless: true,
1027
+ provider: playwright(),
1028
+ instances: [{ browser: 'chromium' }],
1029
+ // Vitest's default viewport is a phone's. This is the wide layout.
1030
+ viewport: { width: 1280, height: 800 },
1031
+ },
1032
+ },
1033
+ })
1034
+ \`\`\`
1035
+
1036
+ A project that also has tests for Node lists each kind as an entry of \`test.projects\`, with its
1037
+ own \`name\` and \`include\`, as polymorph's own config does.
1038
+
1039
+ ## A test
1040
+
1041
+ \`\`\`tsx
1042
+ import { render } from '@testing-library/react'
1043
+ import { expect, it } from 'vitest'
1044
+ import { createAgentBridge } from '${agent}'
1045
+ import { installTestTheme } from '${testing}'
1046
+
1047
+ import { TicketForm } from './TicketForm'
1048
+
1049
+ it('lets an agent fill the ticket form', async () => {
1050
+ installTestTheme()
1051
+ render(<TicketForm onSubmit={() => {}} />)
1052
+ const bridge = createAgentBridge()
1053
+ try {
1054
+ const { results } = await bridge.act([
1055
+ { target: { member: 'Input', name: 'Subject' }, action: 'fill', value: 'Refund' },
1056
+ { target: { name: 'Priority' }, action: 'choose', value: 'urgent' },
1057
+ ])
1058
+ expect(results.every((result) => result.ok)).toBe(true)
1059
+ const subject = bridge.snapshot().members.find((member) => member.name === 'Subject')
1060
+ expect(subject?.state['value']).toBe('Refund')
1061
+ } finally {
1062
+ bridge.dispose()
1063
+ }
1064
+ })
1065
+ \`\`\`
1066
+
1067
+ - Never wrap \`bridge.act\` in Testing Library's \`act()\`. React holds the render until that scope
1068
+ ends, so the bridge sees no change and reports an empty \`changed\`.
1069
+ - Dispose of each bridge in the test that made it.
1070
+ - A step on a member that does not change waits the whole \`settleMs\`. A test may pass a smaller
1071
+ one, such as \`createAgentBridge({ settleMs: 60 })\`.
1072
+ - A test of the policy creates the bridge with it and reads the snapshot: a hidden member is
1073
+ absent, and a denied action is missing from \`actions\` and answers \`not-allowed\`.
1074
+ - ${f.x("agentRegistrations", testing)} lists every registered member, withheld ones included,
1075
+ so a test can tell a member the bridge withholds from one that never registered.
1076
+ - ${f.x("installTestTheme", testing)} installs a theme, so the members render as on the page.
1077
+
1078
+ ## The WebMCP registration
1079
+
1080
+ Stand in for the browser's API with an object on \`document.modelContext\` that keeps each tool
1081
+ until its signal aborts, then call a tool's \`execute\`:
1082
+
1083
+ \`\`\`ts
1084
+ const tools = new Map<string, (input: unknown) => Promise<unknown>>()
1085
+ Object.defineProperty(document, 'modelContext', {
1086
+ configurable: true,
1087
+ value: {
1088
+ registerTool: (
1089
+ tool: { name: string; execute: (input: unknown) => Promise<unknown> },
1090
+ options?: { signal?: AbortSignal },
1091
+ ) => {
1092
+ tools.set(tool.name, tool.execute)
1093
+ options?.signal?.addEventListener('abort', () => tools.delete(tool.name))
1094
+ return Promise.resolve()
1095
+ },
1096
+ },
1097
+ })
1098
+
1099
+ // After the test:
1100
+ delete (document as { modelContext?: unknown }).modelContext
1101
+ \`\`\`
1102
+
1103
+ Mount the component that registers, check that \`tools\` holds the three names, call
1104
+ \`tools.get('polymorph_snapshot')?.({})\`, and check that unmounting empties \`tools\`.
1105
+
1106
+ ## What a test cannot show: where the bridge is bundled
1107
+
1108
+ Vitest's browser mode serves each module as Vite's dev server does, without the chunks of a build.
1109
+ No test can show that the bridge stays out of what the page loads at start. Check the build:
1110
+
1111
+ 1. Build the app as it ships.
1112
+ 2. Find the built file that holds \`polymorph:agentchange\`. Only the bridge holds that text, and a
1113
+ minifier keeps it. Vite writes the files to \`dist/assets/\`:
1114
+
1115
+ \`\`\`sh
1116
+ grep -l 'polymorph:agentchange' dist/assets/*.js
1117
+ \`\`\`
1118
+
1119
+ 3. Check that the page does not load that file at start. With Vite, \`build.manifest: true\` writes
1120
+ \`dist/.vite/manifest.json\`. Follow \`imports\` from the entry's record: no record it reaches
1121
+ has that file as its \`file\`, and the bridge's record is reached through \`dynamicImports\`.
1122
+ With another bundler, load the built page and check that its network list holds no such file
1123
+ until the first use.
1124
+
1125
+ A file that holds the text and loads at start has a static value import from \`${agent}\` in its
1126
+ module graph. Make it an \`import()\` or an \`import type\`.
1127
+ `;
1128
+ }
1129
+ /** What a page with no build does: the setting, a module script, and a script run from outside. */
1130
+ function noBuildReference(registry) {
1131
+ return `# A page with no build
1132
+
1133
+ A page that loads the elements' no-build files, \`polymorph.js\` or \`polymorph-all.js\`, reaches the
1134
+ bridge through its \`data-agent\` setting or through a module script of its own. Both files export
1135
+ ${call(new Facts(registry), "loadAgentBridge", "packages/elements-ui/src/cdn/polymorph.ts", "")}, which resolves to
1136
+ \`@polymorph/engine/agent\`, built with the members the page loaded.
1137
+
1138
+ ## The setting
1139
+
1140
+ \`\`\`html
1141
+ <html lang="en" data-system="…" data-palette="…" data-agent="on-call">
1142
+ \`\`\`
1143
+
1144
+ | \`data-agent\` | The page |
1145
+ | --- | --- |
1146
+ | absent | registers nothing and fetches nothing more. Exposing a page is its owner's decision, so this is the default |
1147
+ | \`on-call\` | registers the three tools with WebMCP at load, and fetches and creates the bridge on the first call |
1148
+ | \`eager\` | fetches and creates the bridge at load, and registers its tools |
1149
+
1150
+ The bridge either value creates has no \`confirm\` and no policy, so a step that needs a person
1151
+ answers \`needs-confirmation\`. The file reads the attribute once, as it runs, so a value a script
1152
+ sets later is not read. In a browser without WebMCP neither value registers or fetches anything.
1153
+
1154
+ | The page loads | \`on-call\` fetches | \`eager\` fetches | \`loadAgentBridge()\` fetches |
1155
+ | --- | --- | --- | --- |
1156
+ | \`polymorph.js\` | two small chunks at load, the bridge on the first call | all three at load | the bridge's chunk |
1157
+ | \`polymorph-all.js\` | nothing more | nothing more | nothing more |
1158
+
1159
+ A call that cannot load the bridge answers \`{ error: { code: 'failed', message } }\`, and the next
1160
+ call loads it again. The console says why a setting registered nothing:
1161
+
1162
+ - \`polymorph: data-agent="…" is neither on-call nor eager, so no agent tools are registered\`
1163
+ - \`polymorph: registerWebMCP registers nothing, because data-agent="on-call" already registered the agent tools on this page\`
1164
+
1165
+ ## A module script
1166
+
1167
+ A page that asks a person, or narrows what an agent may do, states no \`data-agent\` and creates
1168
+ its bridge in a module script:
1169
+
1170
+ \`\`\`html
1171
+ <script type="module">
1172
+ import { loadAgentBridge } from './polymorph/polymorph.js'
1173
+
1174
+ const { createAgentBridge, registerWebMCP } = await loadAgentBridge()
1175
+ const bridge = createAgentBridge({
1176
+ confirm: (request) => Promise.resolve(window.confirm(\`\${request.action} “\${request.name}”?\`)),
1177
+ // The page writes data-agent-key="place-order" on that poly-button.
1178
+ policy: { deny: ({ keys = [] }) => keys.includes('place-order') },
1179
+ })
1180
+ registerWebMCP(bridge)
1181
+ <\/script>
1182
+ \`\`\`
1183
+
1184
+ The key is an attribute of the element: \`<poly-button data-agent-key="place-order" label="…">\`.
1185
+ The element keeps it and draws no box, and its control is inside it, so the policy reads the key
1186
+ in every language the label is written in.
1187
+
1188
+ - Import it from the file the page loads, at the same path. A copy from anywhere else reads a
1189
+ registry of its own, which holds nothing.
1190
+ - The elements register as they render, so a member whose code is still loading is not listed
1191
+ yet. Read the page when the agent asks, never once at load.
1192
+ - A page that states \`data-agent\` and also calls \`registerWebMCP\` keeps the setting's
1193
+ registration: the second registers nothing and warns.
1194
+ `;
1195
+ }
1196
+ //#endregion
1197
+ export { bridgeSkill };