@copilotkit/shared 2.0.0-rc.5 → 2.0.0-rc.51

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 (569) hide show
  1. package/README.md +4 -15
  2. package/dist/a2ui-envelope.cjs +3 -3
  3. package/dist/a2ui-envelope.cjs.map +1 -1
  4. package/dist/a2ui-envelope.d.cts +1 -1
  5. package/dist/a2ui-envelope.d.cts.map +1 -1
  6. package/dist/a2ui-envelope.d.mts +1 -1
  7. package/dist/a2ui-envelope.d.mts.map +1 -1
  8. package/dist/a2ui-envelope.mjs +3 -3
  9. package/dist/a2ui-envelope.mjs.map +1 -1
  10. package/dist/a2ui-prompts.cjs +21 -62
  11. package/dist/a2ui-prompts.cjs.map +1 -1
  12. package/dist/a2ui-prompts.d.cts +8 -1
  13. package/dist/a2ui-prompts.d.cts.map +1 -1
  14. package/dist/a2ui-prompts.d.mts +8 -1
  15. package/dist/a2ui-prompts.d.mts.map +1 -1
  16. package/dist/a2ui-prompts.mjs +22 -62
  17. package/dist/a2ui-prompts.mjs.map +1 -1
  18. package/dist/attachments/types.d.cts +1 -3
  19. package/dist/attachments/types.d.cts.map +1 -1
  20. package/dist/attachments/types.d.mts +1 -3
  21. package/dist/attachments/types.d.mts.map +1 -1
  22. package/dist/attachments/utils.cjs +16 -5
  23. package/dist/attachments/utils.cjs.map +1 -1
  24. package/dist/attachments/utils.d.cts +3 -1
  25. package/dist/attachments/utils.d.cts.map +1 -1
  26. package/dist/attachments/utils.d.mts +3 -1
  27. package/dist/attachments/utils.d.mts.map +1 -1
  28. package/dist/attachments/utils.mjs +16 -5
  29. package/dist/attachments/utils.mjs.map +1 -1
  30. package/dist/finalize-events.cjs +16 -0
  31. package/dist/finalize-events.cjs.map +1 -1
  32. package/dist/finalize-events.d.cts.map +1 -1
  33. package/dist/finalize-events.d.mts.map +1 -1
  34. package/dist/finalize-events.mjs +16 -0
  35. package/dist/finalize-events.mjs.map +1 -1
  36. package/dist/generative-ui/basic-functions.cjs +1 -1
  37. package/dist/generative-ui/basic-functions.cjs.map +1 -1
  38. package/dist/generative-ui/basic-functions.mjs +1 -1
  39. package/dist/generative-ui/basic-functions.mjs.map +1 -1
  40. package/dist/generative-ui/catalog/catalog-export.cjs +329 -0
  41. package/dist/generative-ui/catalog/catalog-export.cjs.map +1 -0
  42. package/dist/generative-ui/catalog/catalog-export.d.cts +92 -0
  43. package/dist/generative-ui/catalog/catalog-export.d.cts.map +1 -0
  44. package/dist/generative-ui/catalog/catalog-export.d.mts +92 -0
  45. package/dist/generative-ui/catalog/catalog-export.d.mts.map +1 -0
  46. package/dist/generative-ui/catalog/catalog-export.mjs +328 -0
  47. package/dist/generative-ui/catalog/catalog-export.mjs.map +1 -0
  48. package/dist/generative-ui/catalog/catalog.cjs +315 -0
  49. package/dist/generative-ui/catalog/catalog.cjs.map +1 -0
  50. package/dist/generative-ui/catalog/catalog.d.cts +407 -0
  51. package/dist/generative-ui/catalog/catalog.d.cts.map +1 -0
  52. package/dist/generative-ui/catalog/catalog.d.mts +407 -0
  53. package/dist/generative-ui/catalog/catalog.d.mts.map +1 -0
  54. package/dist/generative-ui/catalog/catalog.mjs +312 -0
  55. package/dist/generative-ui/catalog/catalog.mjs.map +1 -0
  56. package/dist/generative-ui/catalog/errors.cjs +13 -0
  57. package/dist/generative-ui/catalog/errors.cjs.map +1 -0
  58. package/dist/generative-ui/catalog/errors.d.cts +46 -0
  59. package/dist/generative-ui/catalog/errors.d.cts.map +1 -0
  60. package/dist/generative-ui/catalog/errors.d.mts +46 -0
  61. package/dist/generative-ui/catalog/errors.d.mts.map +1 -0
  62. package/dist/generative-ui/catalog/errors.mjs +12 -0
  63. package/dist/generative-ui/catalog/errors.mjs.map +1 -0
  64. package/dist/generative-ui/catalog/index.d.mts +6 -0
  65. package/dist/generative-ui/catalog/json-schema.cjs +16 -0
  66. package/dist/generative-ui/catalog/json-schema.cjs.map +1 -0
  67. package/dist/generative-ui/catalog/json-schema.d.cts +12 -0
  68. package/dist/generative-ui/catalog/json-schema.d.cts.map +1 -0
  69. package/dist/generative-ui/catalog/json-schema.d.mts +12 -0
  70. package/dist/generative-ui/catalog/json-schema.d.mts.map +1 -0
  71. package/dist/generative-ui/catalog/json-schema.mjs +16 -0
  72. package/dist/generative-ui/catalog/json-schema.mjs.map +1 -0
  73. package/dist/generative-ui/catalog/refs.cjs +21 -0
  74. package/dist/generative-ui/catalog/refs.cjs.map +1 -0
  75. package/dist/generative-ui/catalog/refs.d.cts +55 -0
  76. package/dist/generative-ui/catalog/refs.d.cts.map +1 -0
  77. package/dist/generative-ui/catalog/refs.d.mts +55 -0
  78. package/dist/generative-ui/catalog/refs.d.mts.map +1 -0
  79. package/dist/generative-ui/catalog/refs.mjs +18 -0
  80. package/dist/generative-ui/catalog/refs.mjs.map +1 -0
  81. package/dist/generative-ui/catalog/schema.cjs +74 -0
  82. package/dist/generative-ui/catalog/schema.cjs.map +1 -0
  83. package/dist/generative-ui/catalog/schema.d.cts +43 -0
  84. package/dist/generative-ui/catalog/schema.d.cts.map +1 -0
  85. package/dist/generative-ui/catalog/schema.d.mts +43 -0
  86. package/dist/generative-ui/catalog/schema.d.mts.map +1 -0
  87. package/dist/generative-ui/catalog/schema.mjs +68 -0
  88. package/dist/generative-ui/catalog/schema.mjs.map +1 -0
  89. package/dist/generative-ui/child-refs.cjs +3 -3
  90. package/dist/generative-ui/child-refs.cjs.map +1 -1
  91. package/dist/generative-ui/child-refs.d.cts.map +1 -1
  92. package/dist/generative-ui/child-refs.d.mts.map +1 -1
  93. package/dist/generative-ui/child-refs.mjs +3 -3
  94. package/dist/generative-ui/child-refs.mjs.map +1 -1
  95. package/dist/generative-ui/clone-value.cjs +364 -0
  96. package/dist/generative-ui/clone-value.cjs.map +1 -0
  97. package/dist/generative-ui/clone-value.d.cts +51 -0
  98. package/dist/generative-ui/clone-value.d.cts.map +1 -0
  99. package/dist/generative-ui/clone-value.d.mts +51 -0
  100. package/dist/generative-ui/clone-value.d.mts.map +1 -0
  101. package/dist/generative-ui/clone-value.mjs +363 -0
  102. package/dist/generative-ui/clone-value.mjs.map +1 -0
  103. package/dist/generative-ui/compact-schema.cjs +187 -0
  104. package/dist/generative-ui/compact-schema.cjs.map +1 -0
  105. package/dist/generative-ui/compact-schema.d.cts +55 -0
  106. package/dist/generative-ui/compact-schema.d.cts.map +1 -0
  107. package/dist/generative-ui/compact-schema.d.mts +55 -0
  108. package/dist/generative-ui/compact-schema.d.mts.map +1 -0
  109. package/dist/generative-ui/compact-schema.mjs +185 -0
  110. package/dist/generative-ui/compact-schema.mjs.map +1 -0
  111. package/dist/generative-ui/index.cjs +286 -0
  112. package/dist/generative-ui/index.d.cts +39 -0
  113. package/dist/generative-ui/index.d.mts +41 -0
  114. package/dist/generative-ui/index.mjs +40 -0
  115. package/dist/generative-ui/is-record.cjs +6 -1
  116. package/dist/generative-ui/is-record.cjs.map +1 -1
  117. package/dist/generative-ui/is-record.d.cts +8 -0
  118. package/dist/generative-ui/is-record.d.cts.map +1 -0
  119. package/dist/generative-ui/is-record.d.mts +8 -0
  120. package/dist/generative-ui/is-record.d.mts.map +1 -0
  121. package/dist/generative-ui/is-record.mjs +6 -2
  122. package/dist/generative-ui/is-record.mjs.map +1 -1
  123. package/dist/generative-ui/prompt-spec.cjs +225 -0
  124. package/dist/generative-ui/prompt-spec.cjs.map +1 -0
  125. package/dist/generative-ui/prompt-spec.d.cts +94 -0
  126. package/dist/generative-ui/prompt-spec.d.cts.map +1 -0
  127. package/dist/generative-ui/prompt-spec.d.mts +94 -0
  128. package/dist/generative-ui/prompt-spec.d.mts.map +1 -0
  129. package/dist/generative-ui/prompt-spec.mjs +220 -0
  130. package/dist/generative-ui/prompt-spec.mjs.map +1 -0
  131. package/dist/generative-ui/prompt.cjs +10 -36
  132. package/dist/generative-ui/prompt.cjs.map +1 -1
  133. package/dist/generative-ui/prompt.d.cts +2 -1
  134. package/dist/generative-ui/prompt.d.cts.map +1 -1
  135. package/dist/generative-ui/prompt.d.mts +2 -1
  136. package/dist/generative-ui/prompt.d.mts.map +1 -1
  137. package/dist/generative-ui/prompt.mjs +12 -38
  138. package/dist/generative-ui/prompt.mjs.map +1 -1
  139. package/dist/generative-ui/render-ui-args.cjs +1 -0
  140. package/dist/generative-ui/render-ui-args.cjs.map +1 -1
  141. package/dist/generative-ui/render-ui-args.d.cts.map +1 -1
  142. package/dist/generative-ui/render-ui-args.d.mts.map +1 -1
  143. package/dist/generative-ui/render-ui-args.mjs +1 -0
  144. package/dist/generative-ui/render-ui-args.mjs.map +1 -1
  145. package/dist/generative-ui/schema-render.cjs +243 -0
  146. package/dist/generative-ui/schema-render.cjs.map +1 -0
  147. package/dist/generative-ui/schema-render.d.cts +44 -0
  148. package/dist/generative-ui/schema-render.d.cts.map +1 -0
  149. package/dist/generative-ui/schema-render.d.mts +44 -0
  150. package/dist/generative-ui/schema-render.d.mts.map +1 -0
  151. package/dist/generative-ui/schema-render.mjs +240 -0
  152. package/dist/generative-ui/schema-render.mjs.map +1 -0
  153. package/dist/generative-ui/standard/chart-config.cjs +347 -0
  154. package/dist/generative-ui/standard/chart-config.cjs.map +1 -0
  155. package/dist/generative-ui/standard/chart-config.d.cts +97 -0
  156. package/dist/generative-ui/standard/chart-config.d.cts.map +1 -0
  157. package/dist/generative-ui/standard/chart-config.d.mts +97 -0
  158. package/dist/generative-ui/standard/chart-config.d.mts.map +1 -0
  159. package/dist/generative-ui/standard/chart-config.mjs +342 -0
  160. package/dist/generative-ui/standard/chart-config.mjs.map +1 -0
  161. package/dist/generative-ui/standard/chart.cjs +56 -0
  162. package/dist/generative-ui/standard/chart.cjs.map +1 -0
  163. package/dist/generative-ui/standard/chart.d.cts +62 -0
  164. package/dist/generative-ui/standard/chart.d.cts.map +1 -0
  165. package/dist/generative-ui/standard/chart.d.mts +62 -0
  166. package/dist/generative-ui/standard/chart.d.mts.map +1 -0
  167. package/dist/generative-ui/standard/chart.mjs +54 -0
  168. package/dist/generative-ui/standard/chart.mjs.map +1 -0
  169. package/dist/generative-ui/standard/checks.cjs +74 -0
  170. package/dist/generative-ui/standard/checks.cjs.map +1 -0
  171. package/dist/generative-ui/standard/checks.d.cts +56 -0
  172. package/dist/generative-ui/standard/checks.d.cts.map +1 -0
  173. package/dist/generative-ui/standard/checks.d.mts +56 -0
  174. package/dist/generative-ui/standard/checks.d.mts.map +1 -0
  175. package/dist/generative-ui/standard/checks.mjs +71 -0
  176. package/dist/generative-ui/standard/checks.mjs.map +1 -0
  177. package/dist/generative-ui/standard/components.cjs +23 -0
  178. package/dist/generative-ui/standard/components.cjs.map +1 -0
  179. package/dist/generative-ui/standard/components.d.cts +24 -0
  180. package/dist/generative-ui/standard/components.d.cts.map +1 -0
  181. package/dist/generative-ui/standard/components.d.mts +24 -0
  182. package/dist/generative-ui/standard/components.d.mts.map +1 -0
  183. package/dist/generative-ui/standard/components.mjs +22 -0
  184. package/dist/generative-ui/standard/components.mjs.map +1 -0
  185. package/dist/generative-ui/standard/composites.cjs +143 -0
  186. package/dist/generative-ui/standard/composites.cjs.map +1 -0
  187. package/dist/generative-ui/standard/composites.d.cts +233 -0
  188. package/dist/generative-ui/standard/composites.d.cts.map +1 -0
  189. package/dist/generative-ui/standard/composites.d.mts +233 -0
  190. package/dist/generative-ui/standard/composites.d.mts.map +1 -0
  191. package/dist/generative-ui/standard/composites.mjs +132 -0
  192. package/dist/generative-ui/standard/composites.mjs.map +1 -0
  193. package/dist/generative-ui/standard/data.cjs +176 -0
  194. package/dist/generative-ui/standard/data.cjs.map +1 -0
  195. package/dist/generative-ui/standard/data.d.cts +365 -0
  196. package/dist/generative-ui/standard/data.d.cts.map +1 -0
  197. package/dist/generative-ui/standard/data.d.mts +365 -0
  198. package/dist/generative-ui/standard/data.d.mts.map +1 -0
  199. package/dist/generative-ui/standard/data.mjs +167 -0
  200. package/dist/generative-ui/standard/data.mjs.map +1 -0
  201. package/dist/generative-ui/standard/declarations.cjs +40 -0
  202. package/dist/generative-ui/standard/declarations.cjs.map +1 -0
  203. package/dist/generative-ui/standard/declarations.d.cts +2570 -0
  204. package/dist/generative-ui/standard/declarations.d.cts.map +1 -0
  205. package/dist/generative-ui/standard/declarations.d.mts +2571 -0
  206. package/dist/generative-ui/standard/declarations.d.mts.map +1 -0
  207. package/dist/generative-ui/standard/declarations.mjs +39 -0
  208. package/dist/generative-ui/standard/declarations.mjs.map +1 -0
  209. package/dist/generative-ui/standard/feedback.cjs +97 -0
  210. package/dist/generative-ui/standard/feedback.cjs.map +1 -0
  211. package/dist/generative-ui/standard/feedback.d.cts +133 -0
  212. package/dist/generative-ui/standard/feedback.d.cts.map +1 -0
  213. package/dist/generative-ui/standard/feedback.d.mts +133 -0
  214. package/dist/generative-ui/standard/feedback.d.mts.map +1 -0
  215. package/dist/generative-ui/standard/feedback.mjs +90 -0
  216. package/dist/generative-ui/standard/feedback.mjs.map +1 -0
  217. package/dist/generative-ui/standard/index.d.mts +20 -0
  218. package/dist/generative-ui/standard/inputs.cjs +333 -0
  219. package/dist/generative-ui/standard/inputs.cjs.map +1 -0
  220. package/dist/generative-ui/standard/inputs.d.cts +1128 -0
  221. package/dist/generative-ui/standard/inputs.d.cts.map +1 -0
  222. package/dist/generative-ui/standard/inputs.d.mts +1128 -0
  223. package/dist/generative-ui/standard/inputs.d.mts.map +1 -0
  224. package/dist/generative-ui/standard/inputs.mjs +318 -0
  225. package/dist/generative-ui/standard/inputs.mjs.map +1 -0
  226. package/dist/generative-ui/standard/layout.cjs +289 -0
  227. package/dist/generative-ui/standard/layout.cjs.map +1 -0
  228. package/dist/generative-ui/standard/layout.d.cts +1974 -0
  229. package/dist/generative-ui/standard/layout.d.cts.map +1 -0
  230. package/dist/generative-ui/standard/layout.d.mts +1975 -0
  231. package/dist/generative-ui/standard/layout.d.mts.map +1 -0
  232. package/dist/generative-ui/standard/layout.mjs +269 -0
  233. package/dist/generative-ui/standard/layout.mjs.map +1 -0
  234. package/dist/generative-ui/standard/map-helpers.cjs +104 -0
  235. package/dist/generative-ui/standard/map-helpers.cjs.map +1 -0
  236. package/dist/generative-ui/standard/map-helpers.d.cts +88 -0
  237. package/dist/generative-ui/standard/map-helpers.d.cts.map +1 -0
  238. package/dist/generative-ui/standard/map-helpers.d.mts +88 -0
  239. package/dist/generative-ui/standard/map-helpers.d.mts.map +1 -0
  240. package/dist/generative-ui/standard/map-helpers.mjs +95 -0
  241. package/dist/generative-ui/standard/map-helpers.mjs.map +1 -0
  242. package/dist/generative-ui/standard/map.cjs +27 -0
  243. package/dist/generative-ui/standard/map.cjs.map +1 -0
  244. package/dist/generative-ui/standard/map.d.cts +31 -0
  245. package/dist/generative-ui/standard/map.d.cts.map +1 -0
  246. package/dist/generative-ui/standard/map.d.mts +31 -0
  247. package/dist/generative-ui/standard/map.d.mts.map +1 -0
  248. package/dist/generative-ui/standard/map.mjs +25 -0
  249. package/dist/generative-ui/standard/map.mjs.map +1 -0
  250. package/dist/generative-ui/standard/media.cjs +215 -0
  251. package/dist/generative-ui/standard/media.cjs.map +1 -0
  252. package/dist/generative-ui/standard/media.d.cts +396 -0
  253. package/dist/generative-ui/standard/media.d.cts.map +1 -0
  254. package/dist/generative-ui/standard/media.d.mts +396 -0
  255. package/dist/generative-ui/standard/media.d.mts.map +1 -0
  256. package/dist/generative-ui/standard/media.mjs +205 -0
  257. package/dist/generative-ui/standard/media.mjs.map +1 -0
  258. package/dist/generative-ui/standard/parameter-order.cjs +231 -0
  259. package/dist/generative-ui/standard/parameter-order.cjs.map +1 -0
  260. package/dist/generative-ui/standard/parameter-order.d.cts +84 -0
  261. package/dist/generative-ui/standard/parameter-order.d.cts.map +1 -0
  262. package/dist/generative-ui/standard/parameter-order.d.mts +84 -0
  263. package/dist/generative-ui/standard/parameter-order.d.mts.map +1 -0
  264. package/dist/generative-ui/standard/parameter-order.mjs +230 -0
  265. package/dist/generative-ui/standard/parameter-order.mjs.map +1 -0
  266. package/dist/generative-ui/standard/style-helpers.cjs +151 -0
  267. package/dist/generative-ui/standard/style-helpers.cjs.map +1 -0
  268. package/dist/generative-ui/standard/style-helpers.d.cts +56 -0
  269. package/dist/generative-ui/standard/style-helpers.d.cts.map +1 -0
  270. package/dist/generative-ui/standard/style-helpers.d.mts +56 -0
  271. package/dist/generative-ui/standard/style-helpers.d.mts.map +1 -0
  272. package/dist/generative-ui/standard/style-helpers.mjs +142 -0
  273. package/dist/generative-ui/standard/style-helpers.mjs.map +1 -0
  274. package/dist/generative-ui/standard/styles.cjs +62 -0
  275. package/dist/generative-ui/standard/styles.cjs.map +1 -0
  276. package/dist/generative-ui/standard/styles.d.cts +17 -0
  277. package/dist/generative-ui/standard/styles.d.cts.map +1 -0
  278. package/dist/generative-ui/standard/styles.d.mts +17 -0
  279. package/dist/generative-ui/standard/styles.d.mts.map +1 -0
  280. package/dist/generative-ui/standard/styles.mjs +60 -0
  281. package/dist/generative-ui/standard/styles.mjs.map +1 -0
  282. package/dist/generative-ui/standard/text.cjs +226 -0
  283. package/dist/generative-ui/standard/text.cjs.map +1 -0
  284. package/dist/generative-ui/standard/text.d.cts +522 -0
  285. package/dist/generative-ui/standard/text.d.cts.map +1 -0
  286. package/dist/generative-ui/standard/text.d.mts +522 -0
  287. package/dist/generative-ui/standard/text.d.mts.map +1 -0
  288. package/dist/generative-ui/standard/text.mjs +209 -0
  289. package/dist/generative-ui/standard/text.mjs.map +1 -0
  290. package/dist/generative-ui/standard/theme.cjs +115 -0
  291. package/dist/generative-ui/standard/theme.cjs.map +1 -0
  292. package/dist/generative-ui/standard/theme.d.cts +60 -0
  293. package/dist/generative-ui/standard/theme.d.cts.map +1 -0
  294. package/dist/generative-ui/standard/theme.d.mts +60 -0
  295. package/dist/generative-ui/standard/theme.d.mts.map +1 -0
  296. package/dist/generative-ui/standard/theme.mjs +112 -0
  297. package/dist/generative-ui/standard/theme.mjs.map +1 -0
  298. package/dist/generative-ui/standard/tokens.cjs +336 -0
  299. package/dist/generative-ui/standard/tokens.cjs.map +1 -0
  300. package/dist/generative-ui/standard/tokens.d.cts +76 -0
  301. package/dist/generative-ui/standard/tokens.d.cts.map +1 -0
  302. package/dist/generative-ui/standard/tokens.d.mts +76 -0
  303. package/dist/generative-ui/standard/tokens.d.mts.map +1 -0
  304. package/dist/generative-ui/standard/tokens.mjs +305 -0
  305. package/dist/generative-ui/standard/tokens.mjs.map +1 -0
  306. package/dist/generative-ui/standard/url.cjs +54 -0
  307. package/dist/generative-ui/standard/url.cjs.map +1 -0
  308. package/dist/generative-ui/standard/url.d.cts +32 -0
  309. package/dist/generative-ui/standard/url.d.cts.map +1 -0
  310. package/dist/generative-ui/standard/url.d.mts +32 -0
  311. package/dist/generative-ui/standard/url.d.mts.map +1 -0
  312. package/dist/generative-ui/standard/url.mjs +50 -0
  313. package/dist/generative-ui/standard/url.mjs.map +1 -0
  314. package/dist/generative-ui/thrown.cjs +69 -0
  315. package/dist/generative-ui/thrown.cjs.map +1 -0
  316. package/dist/generative-ui/thrown.d.cts +21 -0
  317. package/dist/generative-ui/thrown.d.cts.map +1 -0
  318. package/dist/generative-ui/thrown.d.mts +21 -0
  319. package/dist/generative-ui/thrown.d.mts.map +1 -0
  320. package/dist/generative-ui/thrown.mjs +67 -0
  321. package/dist/generative-ui/thrown.mjs.map +1 -0
  322. package/dist/generative-ui/types.cjs +2 -2
  323. package/dist/generative-ui/types.cjs.map +1 -1
  324. package/dist/generative-ui/types.d.cts +20 -7
  325. package/dist/generative-ui/types.d.cts.map +1 -1
  326. package/dist/generative-ui/types.d.mts +20 -7
  327. package/dist/generative-ui/types.d.mts.map +1 -1
  328. package/dist/generative-ui/types.mjs +2 -2
  329. package/dist/generative-ui/types.mjs.map +1 -1
  330. package/dist/generative-ui/validate-operation.cjs +2 -2
  331. package/dist/generative-ui/validate-operation.cjs.map +1 -1
  332. package/dist/generative-ui/validate-operation.mjs +2 -2
  333. package/dist/generative-ui/validate-operation.mjs.map +1 -1
  334. package/dist/index.cjs +18 -15
  335. package/dist/index.cjs.map +1 -1
  336. package/dist/index.d.cts +18 -17
  337. package/dist/index.d.cts.map +1 -1
  338. package/dist/index.d.mts +18 -17
  339. package/dist/index.d.mts.map +1 -1
  340. package/dist/index.mjs +10 -8
  341. package/dist/index.mjs.map +1 -1
  342. package/dist/index.umd.js +1233 -456
  343. package/dist/index.umd.js.map +1 -1
  344. package/dist/package.cjs +1 -1
  345. package/dist/package.mjs +1 -1
  346. package/dist/standard-schema.cjs +20 -7
  347. package/dist/standard-schema.cjs.map +1 -1
  348. package/dist/standard-schema.d.cts +15 -16
  349. package/dist/standard-schema.d.cts.map +1 -1
  350. package/dist/standard-schema.d.mts +15 -16
  351. package/dist/standard-schema.d.mts.map +1 -1
  352. package/dist/standard-schema.mjs +20 -8
  353. package/dist/standard-schema.mjs.map +1 -1
  354. package/dist/telemetry/lambda-client.cjs +1 -1
  355. package/dist/telemetry/lambda-client.cjs.map +1 -1
  356. package/dist/telemetry/lambda-client.d.cts.map +1 -1
  357. package/dist/telemetry/lambda-client.d.mts.map +1 -1
  358. package/dist/telemetry/lambda-client.mjs +1 -1
  359. package/dist/telemetry/lambda-client.mjs.map +1 -1
  360. package/dist/telemetry/telemetry-disabled.cjs +0 -5
  361. package/dist/telemetry/telemetry-disabled.cjs.map +1 -1
  362. package/dist/telemetry/telemetry-disabled.d.cts +0 -5
  363. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -1
  364. package/dist/telemetry/telemetry-disabled.d.mts +0 -5
  365. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -1
  366. package/dist/telemetry/telemetry-disabled.mjs +0 -5
  367. package/dist/telemetry/telemetry-disabled.mjs.map +1 -1
  368. package/dist/types/message.d.cts +1 -18
  369. package/dist/types/message.d.cts.map +1 -1
  370. package/dist/types/message.d.mts +1 -18
  371. package/dist/types/message.d.mts.map +1 -1
  372. package/dist/utils/errors.cjs +5 -42
  373. package/dist/utils/errors.cjs.map +1 -1
  374. package/dist/utils/errors.d.cts +16 -34
  375. package/dist/utils/errors.d.cts.map +1 -1
  376. package/dist/utils/errors.d.mts +16 -34
  377. package/dist/utils/errors.d.mts.map +1 -1
  378. package/dist/utils/errors.mjs +6 -41
  379. package/dist/utils/errors.mjs.map +1 -1
  380. package/dist/utils/index.cjs +0 -2
  381. package/dist/utils/index.cjs.map +1 -1
  382. package/dist/utils/index.d.cts +5 -7
  383. package/dist/utils/index.d.cts.map +1 -1
  384. package/dist/utils/index.d.mts +5 -7
  385. package/dist/utils/index.d.mts.map +1 -1
  386. package/dist/utils/index.mjs +4 -6
  387. package/dist/utils/index.mjs.map +1 -1
  388. package/dist/utils/inspector-visibility.cjs +25 -3
  389. package/dist/utils/inspector-visibility.cjs.map +1 -1
  390. package/dist/utils/inspector-visibility.d.cts +26 -3
  391. package/dist/utils/inspector-visibility.d.cts.map +1 -1
  392. package/dist/utils/inspector-visibility.d.mts +26 -3
  393. package/dist/utils/inspector-visibility.d.mts.map +1 -1
  394. package/dist/utils/inspector-visibility.mjs +25 -4
  395. package/dist/utils/inspector-visibility.mjs.map +1 -1
  396. package/dist/utils/json-schema.cjs +4 -79
  397. package/dist/utils/json-schema.cjs.map +1 -1
  398. package/dist/utils/json-schema.d.cts +1 -4
  399. package/dist/utils/json-schema.d.cts.map +1 -1
  400. package/dist/utils/json-schema.d.mts +1 -4
  401. package/dist/utils/json-schema.d.mts.map +1 -1
  402. package/dist/utils/json-schema.mjs +5 -78
  403. package/dist/utils/json-schema.mjs.map +1 -1
  404. package/dist/utils/random-id.cjs +13 -26
  405. package/dist/utils/random-id.cjs.map +1 -1
  406. package/dist/utils/random-id.d.cts +6 -3
  407. package/dist/utils/random-id.d.cts.map +1 -1
  408. package/dist/utils/random-id.d.mts +6 -3
  409. package/dist/utils/random-id.d.mts.map +1 -1
  410. package/dist/utils/random-id.mjs +14 -25
  411. package/dist/utils/random-id.mjs.map +1 -1
  412. package/dist/utils/types.cjs.map +1 -1
  413. package/dist/utils/types.d.cts +5 -12
  414. package/dist/utils/types.d.cts.map +1 -1
  415. package/dist/utils/types.d.mts +5 -12
  416. package/dist/utils/types.d.mts.map +1 -1
  417. package/dist/utils/types.mjs.map +1 -1
  418. package/package.json +19 -32
  419. package/scripts/verify-cjs-exports.cjs +1 -1
  420. package/src/__tests__/a2ui-envelope.test.ts +38 -13
  421. package/src/__tests__/a2ui-prompts.test.ts +47 -14
  422. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  423. package/src/__tests__/prompt-spec.test.ts +191 -0
  424. package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
  425. package/src/__tests__/schema-render.test.ts +323 -0
  426. package/src/__tests__/standard-schema.test.ts +61 -101
  427. package/src/a2ui-envelope.ts +9 -7
  428. package/src/a2ui-prompts.ts +47 -96
  429. package/src/attachments/__tests__/utils.test.ts +22 -0
  430. package/src/attachments/types.ts +1 -3
  431. package/src/attachments/utils.ts +23 -5
  432. package/src/finalize-events.ts +16 -0
  433. package/src/generative-ui/__tests__/clone-value-differential.test.ts +480 -0
  434. package/src/generative-ui/__tests__/clone-value.test.ts +226 -0
  435. package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
  436. package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
  437. package/src/generative-ui/base.ts +9 -0
  438. package/src/generative-ui/basic-functions.ts +1 -1
  439. package/src/generative-ui/catalog/catalog-export.ts +478 -0
  440. package/src/generative-ui/catalog/catalog.ts +1167 -0
  441. package/src/generative-ui/catalog/errors.ts +102 -0
  442. package/src/generative-ui/catalog/index.ts +6 -0
  443. package/src/generative-ui/catalog/json-schema.ts +14 -0
  444. package/src/generative-ui/catalog/refs.ts +87 -0
  445. package/src/generative-ui/catalog/schema.ts +107 -0
  446. package/src/generative-ui/child-refs.ts +5 -4
  447. package/src/generative-ui/clone-value.ts +511 -0
  448. package/src/generative-ui/compact-schema.ts +277 -0
  449. package/src/generative-ui/index.ts +14 -0
  450. package/src/generative-ui/is-record.ts +6 -1
  451. package/src/generative-ui/prompt-spec.ts +335 -0
  452. package/src/generative-ui/prompt.ts +25 -75
  453. package/src/generative-ui/render-ui-args.ts +3 -0
  454. package/src/generative-ui/schema-render.ts +378 -0
  455. package/src/generative-ui/standard/__tests__/standard-helpers.test.ts +407 -0
  456. package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
  457. package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
  458. package/src/generative-ui/standard/chart-config.ts +434 -0
  459. package/src/generative-ui/standard/chart.ts +79 -0
  460. package/src/generative-ui/standard/checks.ts +98 -0
  461. package/src/generative-ui/standard/components.ts +35 -0
  462. package/src/generative-ui/standard/composites.ts +158 -0
  463. package/src/generative-ui/standard/data.ts +213 -0
  464. package/src/generative-ui/standard/declarations.ts +57 -0
  465. package/src/generative-ui/standard/feedback.ts +105 -0
  466. package/src/generative-ui/standard/index.ts +55 -0
  467. package/src/generative-ui/standard/inputs.ts +423 -0
  468. package/src/generative-ui/standard/layout.ts +312 -0
  469. package/src/generative-ui/standard/map-helpers.ts +155 -0
  470. package/src/generative-ui/standard/map.ts +32 -0
  471. package/src/generative-ui/standard/media.ts +265 -0
  472. package/src/generative-ui/standard/parameter-order.ts +155 -0
  473. package/src/generative-ui/standard/style-helpers.ts +170 -0
  474. package/src/generative-ui/standard/styles.ts +79 -0
  475. package/src/generative-ui/standard/text.ts +210 -0
  476. package/src/generative-ui/standard/theme.ts +198 -0
  477. package/src/generative-ui/standard/tokens.ts +317 -0
  478. package/src/generative-ui/standard/url.ts +51 -0
  479. package/src/generative-ui/thrown.ts +90 -0
  480. package/src/generative-ui/types.ts +23 -7
  481. package/src/generative-ui/validate-operation.ts +2 -2
  482. package/src/index.ts +9 -17
  483. package/src/standard-schema.ts +24 -27
  484. package/src/telemetry/lambda-client.ts +8 -3
  485. package/src/telemetry/model-host.test.ts +2 -5
  486. package/src/telemetry/telemetry-disabled.ts +0 -5
  487. package/src/types/message.ts +1 -19
  488. package/src/utils/__tests__/errors.test.ts +44 -0
  489. package/src/utils/__tests__/json-schema.test.ts +3 -479
  490. package/src/utils/__tests__/random-id.test.ts +37 -0
  491. package/src/utils/errors.ts +28 -85
  492. package/src/utils/index.ts +0 -2
  493. package/src/utils/inspector-visibility.test.ts +26 -0
  494. package/src/utils/inspector-visibility.ts +35 -3
  495. package/src/utils/json-schema.ts +5 -152
  496. package/src/utils/random-id.ts +17 -37
  497. package/src/utils/types.ts +4 -11
  498. package/tsconfig.json +3 -1
  499. package/tsdown.config.ts +2 -19
  500. package/dist/event-transforms/index.cjs +0 -15
  501. package/dist/event-transforms/index.d.cts +0 -4
  502. package/dist/event-transforms/index.d.mts +0 -4
  503. package/dist/event-transforms/index.mjs +0 -5
  504. package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
  505. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
  506. package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
  507. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
  508. package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
  509. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
  510. package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
  511. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
  512. package/dist/event-transforms/recorded-events.cjs +0 -59
  513. package/dist/event-transforms/recorded-events.cjs.map +0 -1
  514. package/dist/event-transforms/recorded-events.d.cts +0 -23
  515. package/dist/event-transforms/recorded-events.d.cts.map +0 -1
  516. package/dist/event-transforms/recorded-events.d.mts +0 -23
  517. package/dist/event-transforms/recorded-events.d.mts.map +0 -1
  518. package/dist/event-transforms/recorded-events.mjs +0 -58
  519. package/dist/event-transforms/recorded-events.mjs.map +0 -1
  520. package/dist/telemetry/events.d.cts +0 -72
  521. package/dist/telemetry/events.d.cts.map +0 -1
  522. package/dist/telemetry/events.d.mts +0 -72
  523. package/dist/telemetry/events.d.mts.map +0 -1
  524. package/dist/telemetry/index.cjs +0 -18
  525. package/dist/telemetry/index.d.cts +0 -5
  526. package/dist/telemetry/index.d.mts +0 -5
  527. package/dist/telemetry/index.mjs +0 -6
  528. package/dist/telemetry/telemetry-client.cjs +0 -165
  529. package/dist/telemetry/telemetry-client.cjs.map +0 -1
  530. package/dist/telemetry/telemetry-client.d.cts +0 -87
  531. package/dist/telemetry/telemetry-client.d.cts.map +0 -1
  532. package/dist/telemetry/telemetry-client.d.mts +0 -87
  533. package/dist/telemetry/telemetry-client.d.mts.map +0 -1
  534. package/dist/telemetry/telemetry-client.mjs +0 -164
  535. package/dist/telemetry/telemetry-client.mjs.map +0 -1
  536. package/dist/telemetry/utils.cjs +0 -14
  537. package/dist/telemetry/utils.cjs.map +0 -1
  538. package/dist/telemetry/utils.mjs +0 -13
  539. package/dist/telemetry/utils.mjs.map +0 -1
  540. package/dist/utils/conditions.cjs +0 -32
  541. package/dist/utils/conditions.cjs.map +0 -1
  542. package/dist/utils/conditions.d.cts +0 -31
  543. package/dist/utils/conditions.d.cts.map +0 -1
  544. package/dist/utils/conditions.d.mts +0 -31
  545. package/dist/utils/conditions.d.mts.map +0 -1
  546. package/dist/utils/conditions.mjs +0 -31
  547. package/dist/utils/conditions.mjs.map +0 -1
  548. package/dist/utils/console-styling.cjs +0 -91
  549. package/dist/utils/console-styling.cjs.map +0 -1
  550. package/dist/utils/console-styling.d.cts +0 -65
  551. package/dist/utils/console-styling.d.cts.map +0 -1
  552. package/dist/utils/console-styling.d.mts +0 -65
  553. package/dist/utils/console-styling.d.mts.map +0 -1
  554. package/dist/utils/console-styling.mjs +0 -85
  555. package/dist/utils/console-styling.mjs.map +0 -1
  556. package/src/__tests__/zod-regression.test.ts +0 -319
  557. package/src/event-transforms/index.ts +0 -5
  558. package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
  559. package/src/event-transforms/recorded-events.test.ts +0 -166
  560. package/src/event-transforms/recorded-events.ts +0 -74
  561. package/src/telemetry/events.ts +0 -68
  562. package/src/telemetry/index.ts +0 -9
  563. package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
  564. package/src/telemetry/telemetry-client.test.ts +0 -798
  565. package/src/telemetry/telemetry-client.ts +0 -328
  566. package/src/telemetry/utils.ts +0 -15
  567. package/src/utils/__tests__/conditions.test.ts +0 -161
  568. package/src/utils/conditions.ts +0 -116
  569. package/src/utils/console-styling.ts +0 -126
@@ -1 +1 @@
1
- {"version":3,"file":"child-refs.mjs","names":[],"sources":["../../src/generative-ui/child-refs.ts"],"sourcesContent":["import type { GenerativeUIJSONSchema } from \"./types\";\nimport { isRecord } from \"./is-record\";\n\n/**\n * How A2UI 1.0 marks a prop that holds a component reference: the JSON\n * Schema of the prop is a `$ref` to one of these two common types.\n * Validators and renderers find the children of a component by these refs,\n * at any depth of the props schema.\n */\nexport const A2UI_COMPONENT_ID_REF = \"common_types.json#/$defs/ComponentId\";\nexport const A2UI_CHILD_LIST_REF = \"common_types.json#/$defs/ChildList\";\n\n/**\n * The start of the `description` that marks a schema as a component\n * reference before it is turned into JSON Schema. `child()` and\n * `childList()` set it; a schema from another library can set a description\n * that starts with the same mark to get the same effect. What follows the\n * mark (after a space) stays as the description of the reference.\n */\nexport const A2UI_COMPONENT_ID_MARK = \"@a2ui/ComponentId\";\nexport const A2UI_CHILD_LIST_MARK = \"@a2ui/ChildList\";\n\nexport type ChildRefKind = \"single\" | \"multiple\";\n\n/** One component reference in a props schema. */\nexport interface ChildRef {\n /**\n * The keys from the props root to the reference. `\"*\"` stands for the\n * items of an array. `[\"tabs\", \"*\", \"child\"]` is the `child` of each\n * entry of `tabs`.\n */\n path: readonly string[];\n kind: ChildRefKind;\n}\n\n/** The ref kind of a JSON Schema node, or `undefined` for a plain value. */\nexport function childRefKind(\n schema: GenerativeUIJSONSchema,\n): ChildRefKind | undefined {\n const ref = schema.$ref;\n if (ref === A2UI_COMPONENT_ID_REF) return \"single\";\n if (ref === A2UI_CHILD_LIST_REF) return \"multiple\";\n return undefined;\n}\n\n/**\n * Turns the reference marks of a JSON Schema into A2UI `$ref`s, in place of\n * the marked node. The mark is the `description` set by `child()` and\n * `childList()`; after this, the node is `{ \"$ref\": \"common_types.json#/...\" }`.\n */\nexport function applyChildRefMarks(\n schema: GenerativeUIJSONSchema,\n): GenerativeUIJSONSchema {\n const marked = (description: unknown, mark: string, ref: string) => {\n if (typeof description !== \"string\" || !description.startsWith(mark)) {\n return undefined;\n }\n const rest = description.slice(mark.length).trim();\n return rest === \"\" ? { $ref: ref } : { $ref: ref, description: rest };\n };\n const visit = (node: unknown): unknown => {\n if (Array.isArray(node)) return node.map(visit);\n if (!isRecord(node)) return node;\n const reference =\n marked(node.description, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF) ??\n marked(node.description, A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF);\n if (reference) return reference;\n return Object.fromEntries(\n Object.entries(node).map(([key, value]) => [key, visit(value)]),\n );\n };\n return visit(schema) as GenerativeUIJSONSchema;\n}\n\n/**\n * Every component reference in a props schema, with its path. Walks\n * `properties`, array `items`, and the variants of `anyOf` / `oneOf` /\n * `allOf`. A union counts as a reference only when every alternative is\n * one of the same kind: a prop that is text in one branch and a child in\n * another cannot be told apart from its value, so it stays data.\n */\nexport function collectChildRefs(schema: GenerativeUIJSONSchema): ChildRef[] {\n const refs: ChildRef[] = [];\n const seen = new Set<string>();\n const add = (path: string[], kind: ChildRefKind) => {\n const key = path.join(\"\\u0000\");\n if (seen.has(key)) return;\n seen.add(key);\n refs.push({ path, kind });\n };\n const visit = (node: unknown, path: string[]) => {\n if (!isRecord(node)) return;\n const kind = childRefKind(node);\n if (kind) return add(path, kind);\n for (const list of [node.anyOf, node.oneOf]) {\n if (!Array.isArray(list) || list.length === 0) continue;\n const kinds = list.map((variant) =>\n isRecord(variant) ? childRefKind(variant) : undefined,\n );\n const [first] = kinds;\n if (first && kinds.every((k) => k === first)) add(path, first);\n else if (kinds.every((k) => k === undefined)) {\n // Objects in a union: a nested reference counts only when every\n // alternative has it at the same path with the same kind.\n const perVariant = list.map((variant) =>\n collectChildRefs(variant as GenerativeUIJSONSchema),\n );\n const key = (ref: ChildRef) =>\n `${ref.kind}\\u0000${ref.path.join(\"\\u0000\")}`;\n const shared = perVariant[0].filter((ref) =>\n perVariant.every((refs) => refs.some((r) => key(r) === key(ref))),\n );\n shared.forEach((ref) => add([...path, ...ref.path], ref.kind));\n }\n }\n if (Array.isArray(node.allOf)) {\n node.allOf.forEach((variant) => visit(variant, path));\n }\n if (isRecord(node.properties)) {\n for (const [key, value] of Object.entries(node.properties)) {\n visit(value, [...path, key]);\n }\n }\n if (isRecord(node.items)) visit(node.items, [...path, \"*\"]);\n };\n visit(schema, []);\n return refs;\n}\n\n/**\n * The component ids at the references of one component node: a string id,\n * a list of ids, or the `componentId` of a template, at every ref path.\n * Bound or computed values are not ids and are left out.\n */\nexport function childIdsAtRefs(\n component: Record<string, unknown>,\n refs: readonly ChildRef[],\n): string[] {\n const ids: string[] = [];\n const collect = (value: unknown) => {\n if (typeof value === \"string\") ids.push(value);\n else if (Array.isArray(value)) {\n value.forEach((id) => typeof id === \"string\" && ids.push(id));\n } else if (isRecord(value) && typeof value.componentId === \"string\") {\n ids.push(value.componentId);\n }\n };\n const visit = (value: unknown, path: readonly string[]) => {\n if (path.length === 0) return collect(value);\n const [head, ...rest] = path;\n if (head === \"*\") {\n if (Array.isArray(value)) value.forEach((item) => visit(item, rest));\n return;\n }\n if (isRecord(value) && Object.prototype.hasOwnProperty.call(value, head)) {\n visit(value[head], rest);\n }\n };\n for (const ref of refs) visit(component, ref.path);\n return ids;\n}\n\n/**\n * True when a reference of the component is bound or computed (`{\"@path\"}`,\n * `{\"@call\"}`) at the ref itself or above it, so its ids are known only\n * at render time.\n */\nexport function hasBoundChildRef(\n component: Record<string, unknown>,\n refs: readonly ChildRef[],\n): boolean {\n const isDynamic = (value: unknown) =>\n isRecord(value) && (\"@path\" in value || \"@call\" in value);\n const visit = (value: unknown, path: readonly string[]): boolean => {\n if (isDynamic(value)) return true;\n if (path.length === 0) return false;\n const [head, ...rest] = path;\n if (head === \"*\") {\n return Array.isArray(value) && value.some((item) => visit(item, rest));\n }\n return (\n isRecord(value) &&\n Object.prototype.hasOwnProperty.call(value, head) &&\n visit(value[head], rest)\n );\n };\n return refs.some((ref) => visit(component, ref.path));\n}\n\n/**\n * Walks `value` along a ref path and replaces what sits at the end with\n * `replace(found)`. Objects and arrays on the way are copied; everything\n * else keeps its identity. Missing keys are left alone.\n */\nexport function mapAtChildRef(\n value: unknown,\n path: readonly string[],\n replace: (found: unknown) => unknown,\n): unknown {\n if (path.length === 0) return replace(value);\n const [head, ...rest] = path;\n if (head === \"*\") {\n if (!Array.isArray(value)) return value;\n return value.map((item) => mapAtChildRef(item, rest, replace));\n }\n if (!isRecord(value) || !Object.prototype.hasOwnProperty.call(value, head)) {\n return value;\n }\n return { ...value, [head]: mapAtChildRef(value[head], rest, replace) };\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,wBAAwB;AACrC,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,yBAAyB;AACtC,MAAa,uBAAuB;;AAgBpC,SAAgB,aACd,QAC0B;CAC1B,MAAM,MAAM,OAAO;AACnB,KAAI,QAAQ,sBAAuB,QAAO;AAC1C,KAAI,QAAQ,oBAAqB,QAAO;;;;;;;AAS1C,SAAgB,mBACd,QACwB;CACxB,MAAM,UAAU,aAAsB,MAAc,QAAgB;AAClE,MAAI,OAAO,gBAAgB,YAAY,CAAC,YAAY,WAAW,KAAK,CAClE;EAEF,MAAM,OAAO,YAAY,MAAM,KAAK,OAAO,CAAC,MAAM;AAClD,SAAO,SAAS,KAAK,EAAE,MAAM,KAAK,GAAG;GAAE,MAAM;GAAK,aAAa;GAAM;;CAEvE,MAAM,SAAS,SAA2B;AACxC,MAAI,MAAM,QAAQ,KAAK,CAAE,QAAO,KAAK,IAAI,MAAM;AAC/C,MAAI,CAAC,SAAS,KAAK,CAAE,QAAO;EAC5B,MAAM,YACJ,OAAO,KAAK,aAAa,wBAAwB,sBAAsB,IACvE,OAAO,KAAK,aAAa,sBAAsB,oBAAoB;AACrE,MAAI,UAAW,QAAO;AACtB,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AAC7B,MAAI,KAAK,WAAW,EAAG,QAAO;EAC9B,MAAM,CAAC,MAAM,GAAG,QAAQ;AACxB,MAAI,SAAS,IACX,QAAO,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAM,SAAS,MAAM,MAAM,KAAK,CAAC;AAExE,SACE,SAAS,MAAM,IACf,OAAO,UAAU,eAAe,KAAK,OAAO,KAAK,IACjD,MAAM,MAAM,OAAO,KAAK;;AAG5B,QAAO,KAAK,MAAM,QAAQ,MAAM,WAAW,IAAI,KAAK,CAAC;;;;;;;AAQvD,SAAgB,cACd,OACA,MACA,SACS;AACT,KAAI,KAAK,WAAW,EAAG,QAAO,QAAQ,MAAM;CAC5C,MAAM,CAAC,MAAM,GAAG,QAAQ;AACxB,KAAI,SAAS,KAAK;AAChB,MAAI,CAAC,MAAM,QAAQ,MAAM,CAAE,QAAO;AAClC,SAAO,MAAM,KAAK,SAAS,cAAc,MAAM,MAAM,QAAQ,CAAC;;AAEhE,KAAI,CAAC,SAAS,MAAM,IAAI,CAAC,OAAO,UAAU,eAAe,KAAK,OAAO,KAAK,CACxE,QAAO;AAET,QAAO;EAAE,GAAG;GAAQ,OAAO,cAAc,MAAM,OAAO,MAAM,QAAQ;EAAE"}
1
+ {"version":3,"file":"child-refs.mjs","names":[],"sources":["../../src/generative-ui/child-refs.ts"],"sourcesContent":["import type { GenerativeUIJSONSchema } from \"./types\";\nimport { isRecord } from \"./is-record\";\n\n/**\n * How A2UI 1.0 marks a prop that holds a component reference: the JSON\n * Schema of the prop is a `$ref` to one of these two common types.\n * Validators and renderers find the children of a component by these refs,\n * at any depth of the props schema.\n */\nexport const A2UI_COMPONENT_ID_REF = \"common_types.json#/$defs/ComponentId\";\nexport const A2UI_CHILD_LIST_REF = \"common_types.json#/$defs/ChildList\";\n\n/**\n * The start of the `description` that marks a schema as a component\n * reference before it is turned into JSON Schema. `child()` and\n * `childList()` set it; a schema from another library can set a description\n * that starts with the same mark to get the same effect. What follows the\n * mark (after a space) stays as the description of the reference.\n */\nexport const A2UI_COMPONENT_ID_MARK = \"@a2ui/ComponentId\";\nexport const A2UI_CHILD_LIST_MARK = \"@a2ui/ChildList\";\n\nexport type ChildRefKind = \"single\" | \"multiple\";\n\n/** One component reference in a props schema. */\nexport interface ChildRef {\n /**\n * The keys from the props root to the reference. `\"*\"` stands for the\n * items of an array. `[\"tabs\", \"*\", \"child\"]` is the `child` of each\n * entry of `tabs`.\n */\n path: readonly string[];\n kind: ChildRefKind;\n}\n\n/** The ref kind of a JSON Schema node, or `undefined` for a plain value. */\nexport function childRefKind(\n schema: GenerativeUIJSONSchema,\n): ChildRefKind | undefined {\n const ref = schema.$ref;\n if (ref === A2UI_COMPONENT_ID_REF) return \"single\";\n if (ref === A2UI_CHILD_LIST_REF) return \"multiple\";\n return undefined;\n}\n\n/**\n * Turns the reference marks of a JSON Schema into A2UI `$ref`s, in place of\n * the marked node. The mark is the `description` set by `child()` and\n * `childList()`; after this, the node is `{ \"$ref\": \"common_types.json#/...\" }`.\n */\nexport function applyChildRefMarks(\n schema: GenerativeUIJSONSchema,\n): GenerativeUIJSONSchema {\n const marked = (description: unknown, mark: string, ref: string) => {\n if (typeof description !== \"string\" || !description.startsWith(mark)) {\n return undefined;\n }\n const rest = description.slice(mark.length).trim();\n return rest === \"\" ? { $ref: ref } : { $ref: ref, description: rest };\n };\n const visit = (node: unknown): unknown => {\n if (Array.isArray(node)) return node.map(visit);\n if (!isRecord(node)) return node;\n const reference =\n marked(node.description, A2UI_COMPONENT_ID_MARK, A2UI_COMPONENT_ID_REF) ??\n marked(node.description, A2UI_CHILD_LIST_MARK, A2UI_CHILD_LIST_REF);\n if (reference) return reference;\n return Object.fromEntries(\n Object.entries(node).map(([key, value]) => [key, visit(value)]),\n );\n };\n return visit(schema) as GenerativeUIJSONSchema;\n}\n\n/**\n * Every component reference in a props schema, with its path. Walks\n * `properties`, array `items`, and the variants of `anyOf` / `oneOf` /\n * `allOf`. A union counts as a reference only when every alternative is\n * one of the same kind: a prop that is text in one branch and a child in\n * another cannot be told apart from its value, so it stays data.\n */\nexport function collectChildRefs(schema: GenerativeUIJSONSchema): ChildRef[] {\n const refs: ChildRef[] = [];\n const seen = new Set<string>();\n const add = (path: string[], kind: ChildRefKind) => {\n const key = path.join(\"\\u0000\");\n if (seen.has(key)) return;\n seen.add(key);\n refs.push({ path, kind });\n };\n const visit = (node: unknown, path: string[]) => {\n if (!isRecord(node)) return;\n const kind = childRefKind(node);\n if (kind) return add(path, kind);\n for (const list of [node.anyOf, node.oneOf]) {\n if (!Array.isArray(list) || list.length === 0) continue;\n const kinds = list.map((variant) =>\n isRecord(variant) ? childRefKind(variant) : undefined,\n );\n const [first] = kinds;\n if (first && kinds.every((k) => k === first)) add(path, first);\n else if (kinds.every((k) => k === undefined)) {\n // Objects in a union: a nested reference counts only when every\n // alternative has it at the same path with the same kind.\n const perVariant = list.map((variant) =>\n collectChildRefs(variant as GenerativeUIJSONSchema),\n );\n const key = (ref: ChildRef) =>\n `${ref.kind}\\u0000${ref.path.join(\"\\u0000\")}`;\n // `list` is not empty (checked above), so `perVariant` is not empty.\n const shared = perVariant[0]!.filter((ref) =>\n perVariant.every((refs) => refs.some((r) => key(r) === key(ref))),\n );\n shared.forEach((ref) => add([...path, ...ref.path], ref.kind));\n }\n }\n if (Array.isArray(node.allOf)) {\n node.allOf.forEach((variant) => visit(variant, path));\n }\n if (isRecord(node.properties)) {\n for (const [key, value] of Object.entries(node.properties)) {\n visit(value, [...path, key]);\n }\n }\n if (isRecord(node.items)) visit(node.items, [...path, \"*\"]);\n };\n visit(schema, []);\n return refs;\n}\n\n/**\n * The component ids at the references of one component node: a string id,\n * a list of ids, or the `componentId` of a template, at every ref path.\n * Bound or computed values are not ids and are left out.\n */\nexport function childIdsAtRefs(\n component: Record<string, unknown>,\n refs: readonly ChildRef[],\n): string[] {\n const ids: string[] = [];\n const collect = (value: unknown) => {\n if (typeof value === \"string\") ids.push(value);\n else if (Array.isArray(value)) {\n value.forEach((id) => typeof id === \"string\" && ids.push(id));\n } else if (isRecord(value) && typeof value.componentId === \"string\") {\n ids.push(value.componentId);\n }\n };\n const visit = (value: unknown, path: readonly string[]) => {\n const [head, ...rest] = path;\n if (head === undefined) return collect(value);\n if (head === \"*\") {\n if (Array.isArray(value)) value.forEach((item) => visit(item, rest));\n return;\n }\n if (isRecord(value) && Object.prototype.hasOwnProperty.call(value, head)) {\n visit(value[head], rest);\n }\n };\n for (const ref of refs) visit(component, ref.path);\n return ids;\n}\n\n/**\n * True when a reference of the component is bound or computed (`{\"@path\"}`,\n * `{\"@call\"}`) at the ref itself or above it, so its ids are known only\n * at render time.\n */\nexport function hasBoundChildRef(\n component: Record<string, unknown>,\n refs: readonly ChildRef[],\n): boolean {\n const isDynamic = (value: unknown) =>\n isRecord(value) && (\"@path\" in value || \"@call\" in value);\n const visit = (value: unknown, path: readonly string[]): boolean => {\n if (isDynamic(value)) return true;\n const [head, ...rest] = path;\n if (head === undefined) return false;\n if (head === \"*\") {\n return Array.isArray(value) && value.some((item) => visit(item, rest));\n }\n return (\n isRecord(value) &&\n Object.prototype.hasOwnProperty.call(value, head) &&\n visit(value[head], rest)\n );\n };\n return refs.some((ref) => visit(component, ref.path));\n}\n\n/**\n * Walks `value` along a ref path and replaces what sits at the end with\n * `replace(found)`. Objects and arrays on the way are copied; everything\n * else keeps its identity. Missing keys are left alone.\n */\nexport function mapAtChildRef(\n value: unknown,\n path: readonly string[],\n replace: (found: unknown) => unknown,\n): unknown {\n const [head, ...rest] = path;\n if (head === undefined) return replace(value);\n if (head === \"*\") {\n if (!Array.isArray(value)) return value;\n return value.map((item) => mapAtChildRef(item, rest, replace));\n }\n if (!isRecord(value) || !Object.prototype.hasOwnProperty.call(value, head)) {\n return value;\n }\n return { ...value, [head]: mapAtChildRef(value[head], rest, replace) };\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,wBAAwB;AACrC,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,yBAAyB;AACtC,MAAa,uBAAuB;;AA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CAAC,SAAS,MAAM,IAAI,CAAC,OAAO,UAAU,eAAe,KAAK,OAAO,KAAK,CACxE,QAAO;AAET,QAAO;EAAE,GAAG;GAAQ,OAAO,cAAc,MAAM,OAAO,MAAM,QAAQ;EAAE"}
@@ -0,0 +1,364 @@
1
+
2
+ //#region src/generative-ui/clone-value.ts
3
+ /**
4
+ * A deep copy of `value` with `structuredClone` semantics. Uses the global
5
+ * `structuredClone` when there is one. Hermes (React Native) has none, so
6
+ * there a local copy runs. It decides the kind of an object by the same
7
+ * internal slots that `structuredClone` reads (brand checks), not by
8
+ * `instanceof` or `Symbol.toStringTag`, and gives what the native
9
+ * `structuredClone` of V8 gives:
10
+ *
11
+ * - `undefined`, `null`, strings, booleans, numbers (also `NaN`,
12
+ * `Infinity` and `-0`) and bigints are returned as they are.
13
+ * - Arrays and ordinary objects are copied deeply: own enumerable string
14
+ * keys only, so a class instance, or an object with its own
15
+ * `Symbol.toStringTag`, becomes a plain object. A sparse array keeps its
16
+ * holes and its length.
17
+ * - `Date`, `RegExp`, `Map`, `Set`, boxed primitives, `ArrayBuffer`s (a
18
+ * resizable one stays resizable), typed arrays (as the base type, never a
19
+ * subclass), `DataView`s, `Blob`s and `File`s are copied.
20
+ * - An `Error` becomes an `Error` of its standard type (a custom name or
21
+ * `AggregateError` becomes `Error`), with its own `message`, its `stack`
22
+ * and its own `cause`. A `DOMException` stays one where the global exists.
23
+ * - A `SharedArrayBuffer` is shared, not copied, like `structuredClone`.
24
+ * - Cycles and shared references are kept: an object reached twice is
25
+ * copied once.
26
+ * - Functions, symbols, `Symbol` wrappers, `arguments`, `WeakMap`,
27
+ * `WeakSet`, `WeakRef`, `Promise`, iterators, generators and the web
28
+ * platform objects that cannot be cloned (`URL`, `Headers`, streams...)
29
+ * throw an error named `"DataCloneError"`: a `DOMException` where the
30
+ * global exists, else an `Error` (Hermes has no `DOMException`).
31
+ *
32
+ * Two differences are left. A `Proxy` cannot be told from its target in
33
+ * JavaScript, so the local copy reads it through its traps, where the
34
+ * native one throws. And an ordinary object takes a fast path that runs no
35
+ * brand check (each failed one throws and catches an exception, slow on
36
+ * Hermes), so a `Map`, `Set`, `Promise` or other object whose prototype
37
+ * was changed to `Object.prototype` or `null` is copied as a plain object.
38
+ *
39
+ * It never installs a global `structuredClone`, and it does not use the
40
+ * JSON round trip of `structuredClone_` from `@ag-ui/client`, which turns
41
+ * `undefined` into `{}` and drops or changes values JSON cannot hold.
42
+ *
43
+ * @param value - The value to copy.
44
+ * @returns A copy that shares no object with `value`, except a
45
+ * `SharedArrayBuffer`.
46
+ * @throws An error named `"DataCloneError"` for a value that cannot be
47
+ * cloned.
48
+ */
49
+ function cloneValue(value) {
50
+ const native = globalThis.structuredClone;
51
+ if (typeof native === "function") return native(value);
52
+ return cloneInto(value, /* @__PURE__ */ new Map());
53
+ }
54
+ /** A global, or `undefined` when this engine does not have it. */
55
+ function globalNamed(name) {
56
+ return globalThis[name];
57
+ }
58
+ /** True when `method` accepts `value` as its `this`: a brand check. */
59
+ function hasBrand(value, method, ...args) {
60
+ if (typeof method !== "function") return false;
61
+ try {
62
+ method.call(value, ...args);
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ /** The getter of `key` on `proto`, for a brand check. */
69
+ function getterOf(proto, key) {
70
+ if (!proto) return void 0;
71
+ return Object.getOwnPropertyDescriptor(proto, key)?.get;
72
+ }
73
+ function protoOf(name) {
74
+ return (globalNamed(name) ?? {}).prototype;
75
+ }
76
+ function methodOf(name, key) {
77
+ return protoOf(name)?.[key];
78
+ }
79
+ const ERROR_NAMES = new Set([
80
+ "Error",
81
+ "EvalError",
82
+ "RangeError",
83
+ "ReferenceError",
84
+ "SyntaxError",
85
+ "TypeError",
86
+ "URIError"
87
+ ]);
88
+ /** Web platform objects that `structuredClone` refuses, where they exist. */
89
+ const PLATFORM_UNCLONEABLE = [
90
+ "URL",
91
+ "URLSearchParams",
92
+ "Headers",
93
+ "Request",
94
+ "Response",
95
+ "FormData",
96
+ "ReadableStream",
97
+ "WritableStream",
98
+ "TransformStream",
99
+ "MessagePort"
100
+ ];
101
+ function* emptyGenerator() {}
102
+ /** The prototypes of the built-in iterators and generators. */
103
+ function iteratorPrototypes() {
104
+ const protos = [];
105
+ const add = (iterator) => {
106
+ const proto = iterator && Object.getPrototypeOf(iterator);
107
+ if (proto) protos.push(proto);
108
+ };
109
+ add([][Symbol.iterator]());
110
+ add((/* @__PURE__ */ new Map())[Symbol.iterator]());
111
+ add((/* @__PURE__ */ new Set())[Symbol.iterator]());
112
+ add(""[Symbol.iterator]());
113
+ protos.push(Object.getPrototypeOf(emptyGenerator.prototype));
114
+ const matchAllKey = Symbol.matchAll;
115
+ const matchAll = matchAllKey ? RegExp.prototype[matchAllKey] : void 0;
116
+ if (typeof matchAll === "function") add(matchAll.call(/a/g, ""));
117
+ return protos;
118
+ }
119
+ let iteratorProtos;
120
+ function inheritsFrom(value, protos) {
121
+ for (let proto = Object.getPrototypeOf(value); proto !== null; proto = Object.getPrototypeOf(proto)) if (protos.includes(proto)) return true;
122
+ return false;
123
+ }
124
+ function dataCloneError(what) {
125
+ const message = `${what} could not be cloned.`;
126
+ const DOMExceptionClass = globalNamed("DOMException");
127
+ if (typeof DOMExceptionClass === "function") return new DOMExceptionClass(message, "DataCloneError");
128
+ const error = new Error(message);
129
+ error.name = "DataCloneError";
130
+ return error;
131
+ }
132
+ function describe(value) {
133
+ if (typeof value === "function") return value.name ? `function ${value.name}` : "A function";
134
+ if (typeof value === "symbol") return String(value);
135
+ return Object.prototype.toString.call(value);
136
+ }
137
+ /** True for an object with the [[ErrorData]] slot. */
138
+ function isError(value) {
139
+ const isErrorCheck = Error.isError;
140
+ if (typeof isErrorCheck === "function") return isErrorCheck.call(Error, value) === true;
141
+ if (!(Symbol.toStringTag in value)) return Object.prototype.toString.call(value) === "[object Error]";
142
+ return value instanceof Error;
143
+ }
144
+ function isDOMException(value) {
145
+ return hasBrand(value, getterOf(protoOf("DOMException"), "code"));
146
+ }
147
+ /** The name of the base typed-array type of a view, or `undefined`. */
148
+ function typedArrayName(value) {
149
+ const getter = getterOf(Object.getPrototypeOf(Uint8Array.prototype), Symbol.toStringTag);
150
+ if (!getter) return void 0;
151
+ const name = getter.call(value);
152
+ return typeof name === "string" ? name : void 0;
153
+ }
154
+ function cloneArrayBuffer(value) {
155
+ const source = value;
156
+ if (source.resizable === true) {
157
+ const copy = new ArrayBuffer(source.byteLength, { maxByteLength: source.maxByteLength });
158
+ new Uint8Array(copy).set(new Uint8Array(source));
159
+ return copy;
160
+ }
161
+ return ArrayBuffer.prototype.slice.call(value, 0);
162
+ }
163
+ function cloneError(value, seen) {
164
+ let copy;
165
+ const own = (key) => Object.prototype.hasOwnProperty.call(value, key);
166
+ const messageDescriptor = Object.getOwnPropertyDescriptor(value, "message");
167
+ const message = messageDescriptor && "value" in messageDescriptor ? `${messageDescriptor.value}` : void 0;
168
+ if (isDOMException(value)) copy = new (globalNamed("DOMException"))(value.message, value.name);
169
+ else {
170
+ const ErrorClass = globalNamed(ERROR_NAMES.has(value.name) ? value.name : "Error") ?? Error;
171
+ copy = message === void 0 ? new ErrorClass() : new ErrorClass(message);
172
+ }
173
+ seen.set(value, copy);
174
+ if (typeof value.stack === "string") copy.stack = value.stack;
175
+ if (!isDOMException(value)) {
176
+ const causeDescriptor = Object.getOwnPropertyDescriptor(value, "cause");
177
+ if (own("cause") && causeDescriptor && "value" in causeDescriptor) Object.defineProperty(copy, "cause", {
178
+ value: cloneInto(causeDescriptor.value, seen),
179
+ writable: true,
180
+ enumerable: false,
181
+ configurable: true
182
+ });
183
+ }
184
+ return copy;
185
+ }
186
+ function cloneInto(value, seen) {
187
+ if (typeof value === "function" || typeof value === "symbol") throw dataCloneError(describe(value));
188
+ if (typeof value !== "object" || value === null) return value;
189
+ const known = seen.get(value);
190
+ if (known !== void 0) return known;
191
+ if (Array.isArray(value)) {
192
+ const copy = [];
193
+ copy.length = value.length;
194
+ seen.set(value, copy);
195
+ copyKeys(value, copy, seen);
196
+ return copy;
197
+ }
198
+ if (isPlainObject(value)) {
199
+ const copy = {};
200
+ seen.set(value, copy);
201
+ copyKeys(value, copy, seen);
202
+ return copy;
203
+ }
204
+ if (hasBrand(value, Date.prototype.getTime)) {
205
+ const copy = new Date(Date.prototype.getTime.call(value));
206
+ seen.set(value, copy);
207
+ return copy;
208
+ }
209
+ if (hasBrand(value, getterOf(RegExp.prototype, "source"))) {
210
+ const source = getterOf(RegExp.prototype, "source").call(value);
211
+ const flags = getterOf(RegExp.prototype, "flags").call(value);
212
+ const copy = new RegExp(source, flags);
213
+ seen.set(value, copy);
214
+ return copy;
215
+ }
216
+ if (hasBrand(value, Map.prototype.has, void 0)) {
217
+ const copy = /* @__PURE__ */ new Map();
218
+ seen.set(value, copy);
219
+ const entries = [];
220
+ Map.prototype.forEach.call(value, (entry, key) => {
221
+ entries.push([key, entry]);
222
+ });
223
+ for (const [key, entry] of entries) copy.set(cloneInto(key, seen), cloneInto(entry, seen));
224
+ return copy;
225
+ }
226
+ if (hasBrand(value, Set.prototype.has, void 0)) {
227
+ const copy = /* @__PURE__ */ new Set();
228
+ seen.set(value, copy);
229
+ const entries = [];
230
+ Set.prototype.forEach.call(value, (entry) => {
231
+ entries.push(entry);
232
+ });
233
+ for (const entry of entries) copy.add(cloneInto(entry, seen));
234
+ return copy;
235
+ }
236
+ if (hasBrand(value, getterOf(ArrayBuffer.prototype, "byteLength"))) {
237
+ const copy = cloneArrayBuffer(value);
238
+ seen.set(value, copy);
239
+ return copy;
240
+ }
241
+ if (hasBrand(value, getterOf(protoOf("SharedArrayBuffer"), "byteLength"))) {
242
+ seen.set(value, value);
243
+ return value;
244
+ }
245
+ if (ArrayBuffer.isView(value)) {
246
+ const view = value;
247
+ const buffer = cloneInto(view.buffer, seen);
248
+ const isDataView = hasBrand(value, getterOf(DataView.prototype, "byteLength"));
249
+ let copy;
250
+ if (isDataView) copy = new DataView(buffer, view.byteOffset, view.byteLength);
251
+ else {
252
+ const name = typedArrayName(value);
253
+ const TypedArray = name ? globalNamed(name) : void 0;
254
+ if (!TypedArray) throw dataCloneError(describe(value));
255
+ const proto = Object.getPrototypeOf(Uint8Array.prototype);
256
+ copy = new TypedArray(buffer, getterOf(proto, "byteOffset").call(value), getterOf(proto, "length").call(value));
257
+ }
258
+ seen.set(value, copy);
259
+ return copy;
260
+ }
261
+ if (isError(value)) return cloneError(value, seen);
262
+ for (const [name, Boxed] of [
263
+ ["Boolean", Boolean],
264
+ ["Number", Number],
265
+ ["String", String],
266
+ ["BigInt", globalNamed("BigInt")]
267
+ ]) {
268
+ const valueOf = methodOf(name, "valueOf");
269
+ if (Boxed && hasBrand(value, valueOf)) {
270
+ const copy = Object(valueOf.call(value));
271
+ seen.set(value, copy);
272
+ return copy;
273
+ }
274
+ }
275
+ if (hasBrand(value, methodOf("Symbol", "valueOf"))) throw dataCloneError(describe(value));
276
+ const BlobClass = globalNamed("Blob");
277
+ if (typeof BlobClass === "function" && value instanceof BlobClass) {
278
+ const copy = cloneBlob(value);
279
+ seen.set(value, copy);
280
+ return copy;
281
+ }
282
+ if (isUncloneable(value)) throw dataCloneError(describe(value));
283
+ const copy = {};
284
+ seen.set(value, copy);
285
+ copyKeys(value, copy, seen);
286
+ return copy;
287
+ }
288
+ function cloneBlob(value) {
289
+ const FileClass = globalNamed("File");
290
+ if (typeof FileClass === "function" && value instanceof FileClass) {
291
+ const file = value;
292
+ return new FileClass([value], file.name, {
293
+ type: value.type,
294
+ lastModified: file.lastModified
295
+ });
296
+ }
297
+ return new (globalNamed("Blob"))([value], { type: value.type });
298
+ }
299
+ /**
300
+ * True for an ordinary object of this realm: its prototype is
301
+ * `Object.prototype` or `null`, it has no `Symbol.toStringTag`, and its
302
+ * built-in tag is "Object" (so not `arguments`, an `Error`, a `Date`, a
303
+ * `RegExp` or a boxed primitive, whatever their prototype). Throws nothing.
304
+ * An object with another slot (a `Map`, a `Set`, a `Promise`...) whose
305
+ * prototype was changed to one of those passes too; only a brand check,
306
+ * which throws, could tell, so it is copied as a plain object.
307
+ */
308
+ function isPlainObject(value) {
309
+ const proto = Object.getPrototypeOf(value);
310
+ if (proto !== Object.prototype && proto !== null) return false;
311
+ if (Symbol.toStringTag in value) return false;
312
+ if (ArrayBuffer.isView(value)) return false;
313
+ return Object.prototype.toString.call(value) === "[object Object]";
314
+ }
315
+ /** The globals of PLATFORM_UNCLONEABLE and their prototypes, when last read. */
316
+ let platformCache;
317
+ /**
318
+ * The prototypes of the PLATFORM_UNCLONEABLE globals that exist. Kept
319
+ * between calls, and built again only when one of the globals changed (a
320
+ * polyfill installed late).
321
+ */
322
+ function platformPrototypes() {
323
+ const globals = globalThis;
324
+ const cached = platformCache;
325
+ if (cached && PLATFORM_UNCLONEABLE.every((name, index) => globals[name] === cached.classes[index])) return cached.protos;
326
+ const classes = PLATFORM_UNCLONEABLE.map((name) => globals[name]);
327
+ const protos = PLATFORM_UNCLONEABLE.map(protoOf).filter((proto) => proto !== void 0);
328
+ platformCache = {
329
+ classes,
330
+ protos
331
+ };
332
+ return protos;
333
+ }
334
+ /** An object that structuredClone refuses, though it has no data slot. */
335
+ function isUncloneable(value) {
336
+ if (!(Symbol.toStringTag in value) && Object.prototype.toString.call(value) === "[object Arguments]") return true;
337
+ if (hasBrand(value, methodOf("WeakMap", "has"), {}) || hasBrand(value, methodOf("WeakSet", "has"), {}) || hasBrand(value, methodOf("WeakRef", "deref")) || hasBrand(value, methodOf("FinalizationRegistry", "unregister"), {})) return true;
338
+ const PromiseClass = globalNamed("Promise");
339
+ if (PromiseClass && value instanceof PromiseClass) return true;
340
+ if (!iteratorProtos) iteratorProtos = iteratorPrototypes();
341
+ if (inheritsFrom(value, iteratorProtos)) return true;
342
+ return inheritsFrom(value, platformPrototypes());
343
+ }
344
+ /** Copies the own enumerable string keys, as structuredClone does. */
345
+ function copyKeys(source, target, seen) {
346
+ for (const key of Object.keys(source)) assign(target, key, cloneInto(source[key], seen));
347
+ }
348
+ /**
349
+ * Sets an own property. A plain assignment of "__proto__" would change the
350
+ * prototype of the copy instead (JSON.parse makes "__proto__" an own key).
351
+ */
352
+ function assign(target, key, value) {
353
+ if (key === "__proto__") Object.defineProperty(target, key, {
354
+ value,
355
+ enumerable: true,
356
+ configurable: true,
357
+ writable: true
358
+ });
359
+ else target[key] = value;
360
+ }
361
+
362
+ //#endregion
363
+ exports.cloneValue = cloneValue;
364
+ //# sourceMappingURL=clone-value.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone-value.cjs","names":[],"sources":["../../src/generative-ui/clone-value.ts"],"sourcesContent":["/**\n * A deep copy of `value` with `structuredClone` semantics. Uses the global\n * `structuredClone` when there is one. Hermes (React Native) has none, so\n * there a local copy runs. It decides the kind of an object by the same\n * internal slots that `structuredClone` reads (brand checks), not by\n * `instanceof` or `Symbol.toStringTag`, and gives what the native\n * `structuredClone` of V8 gives:\n *\n * - `undefined`, `null`, strings, booleans, numbers (also `NaN`,\n * `Infinity` and `-0`) and bigints are returned as they are.\n * - Arrays and ordinary objects are copied deeply: own enumerable string\n * keys only, so a class instance, or an object with its own\n * `Symbol.toStringTag`, becomes a plain object. A sparse array keeps its\n * holes and its length.\n * - `Date`, `RegExp`, `Map`, `Set`, boxed primitives, `ArrayBuffer`s (a\n * resizable one stays resizable), typed arrays (as the base type, never a\n * subclass), `DataView`s, `Blob`s and `File`s are copied.\n * - An `Error` becomes an `Error` of its standard type (a custom name or\n * `AggregateError` becomes `Error`), with its own `message`, its `stack`\n * and its own `cause`. A `DOMException` stays one where the global exists.\n * - A `SharedArrayBuffer` is shared, not copied, like `structuredClone`.\n * - Cycles and shared references are kept: an object reached twice is\n * copied once.\n * - Functions, symbols, `Symbol` wrappers, `arguments`, `WeakMap`,\n * `WeakSet`, `WeakRef`, `Promise`, iterators, generators and the web\n * platform objects that cannot be cloned (`URL`, `Headers`, streams...)\n * throw an error named `\"DataCloneError\"`: a `DOMException` where the\n * global exists, else an `Error` (Hermes has no `DOMException`).\n *\n * Two differences are left. A `Proxy` cannot be told from its target in\n * JavaScript, so the local copy reads it through its traps, where the\n * native one throws. And an ordinary object takes a fast path that runs no\n * brand check (each failed one throws and catches an exception, slow on\n * Hermes), so a `Map`, `Set`, `Promise` or other object whose prototype\n * was changed to `Object.prototype` or `null` is copied as a plain object.\n *\n * It never installs a global `structuredClone`, and it does not use the\n * JSON round trip of `structuredClone_` from `@ag-ui/client`, which turns\n * `undefined` into `{}` and drops or changes values JSON cannot hold.\n *\n * @param value - The value to copy.\n * @returns A copy that shares no object with `value`, except a\n * `SharedArrayBuffer`.\n * @throws An error named `\"DataCloneError\"` for a value that cannot be\n * cloned.\n */\nexport function cloneValue<T>(value: T): T {\n const native = (globalThis as { structuredClone?: <V>(value: V) => V })\n .structuredClone;\n if (typeof native === \"function\") return native(value);\n return cloneInto(value, new Map()) as T;\n}\n\ntype AnyFunction = (this: unknown, ...args: unknown[]) => unknown;\ntype Constructor = new (...args: unknown[]) => unknown;\n\n/** A global, or `undefined` when this engine does not have it. */\nfunction globalNamed<T = Constructor>(name: string): T | undefined {\n return (globalThis as unknown as Record<string, T | undefined>)[name];\n}\n\n/** True when `method` accepts `value` as its `this`: a brand check. */\nfunction hasBrand(\n value: object,\n method: AnyFunction | undefined,\n ...args: unknown[]\n) {\n if (typeof method !== \"function\") return false;\n try {\n method.call(value, ...args);\n return true;\n } catch {\n return false;\n }\n}\n\n/** The getter of `key` on `proto`, for a brand check. */\nfunction getterOf(proto: object | undefined, key: PropertyKey) {\n if (!proto) return undefined;\n return Object.getOwnPropertyDescriptor(proto, key)?.get as\n | AnyFunction\n | undefined;\n}\n\nfunction protoOf(name: string): object | undefined {\n return (globalNamed<{ prototype?: object }>(name) ?? {}).prototype;\n}\n\nfunction methodOf(name: string, key: string): AnyFunction | undefined {\n const proto = protoOf(name) as Record<string, AnyFunction> | undefined;\n return proto?.[key];\n}\n\nconst ERROR_NAMES = new Set([\n \"Error\",\n \"EvalError\",\n \"RangeError\",\n \"ReferenceError\",\n \"SyntaxError\",\n \"TypeError\",\n \"URIError\",\n]);\n\n/** Web platform objects that `structuredClone` refuses, where they exist. */\nconst PLATFORM_UNCLONEABLE = [\n \"URL\",\n \"URLSearchParams\",\n \"Headers\",\n \"Request\",\n \"Response\",\n \"FormData\",\n \"ReadableStream\",\n \"WritableStream\",\n \"TransformStream\",\n \"MessagePort\",\n];\n\nfunction* emptyGenerator() {\n // Only its prototype chain is used.\n}\n\n/** The prototypes of the built-in iterators and generators. */\nfunction iteratorPrototypes(): object[] {\n const protos: object[] = [];\n const add = (iterator: unknown) => {\n const proto = iterator && Object.getPrototypeOf(iterator);\n if (proto) protos.push(proto);\n };\n add([][Symbol.iterator]());\n add(new Map()[Symbol.iterator]());\n add(new Set()[Symbol.iterator]());\n add(\"\"[Symbol.iterator]());\n // The prototype of a generator object is its function's own `prototype`;\n // the shared one is above it.\n protos.push(Object.getPrototypeOf(emptyGenerator.prototype) as object);\n const matchAllKey = (Symbol as unknown as Record<string, symbol | undefined>)\n .matchAll;\n const matchAll = matchAllKey\n ? (RegExp.prototype as unknown as Record<symbol, AnyFunction | undefined>)[\n matchAllKey\n ]\n : undefined;\n if (typeof matchAll === \"function\") add(matchAll.call(/a/g, \"\"));\n return protos;\n}\n\nlet iteratorProtos: object[] | undefined;\n\nfunction inheritsFrom(value: object, protos: readonly object[]) {\n for (\n let proto = Object.getPrototypeOf(value);\n proto !== null;\n proto = Object.getPrototypeOf(proto)\n ) {\n if (protos.includes(proto)) return true;\n }\n return false;\n}\n\nfunction dataCloneError(what: string): Error {\n const message = `${what} could not be cloned.`;\n const DOMExceptionClass =\n globalNamed<new (message: string, name: string) => Error>(\"DOMException\");\n if (typeof DOMExceptionClass === \"function\") {\n return new DOMExceptionClass(message, \"DataCloneError\");\n }\n const error = new Error(message);\n error.name = \"DataCloneError\";\n return error;\n}\n\nfunction describe(value: unknown): string {\n if (typeof value === \"function\") {\n return value.name ? `function ${value.name}` : \"A function\";\n }\n if (typeof value === \"symbol\") return String(value);\n return Object.prototype.toString.call(value);\n}\n\n/** True for an object with the [[ErrorData]] slot. */\nfunction isError(value: object) {\n const isErrorCheck = (Error as unknown as { isError?: AnyFunction }).isError;\n if (typeof isErrorCheck === \"function\") {\n return isErrorCheck.call(Error, value) === true;\n }\n // Without Error.isError the built-in tag shows the slot, unless a\n // Symbol.toStringTag hides it (a DOMException has one).\n if (!(Symbol.toStringTag in value)) {\n return Object.prototype.toString.call(value) === \"[object Error]\";\n }\n return value instanceof Error;\n}\n\nfunction isDOMException(value: object) {\n return hasBrand(value, getterOf(protoOf(\"DOMException\"), \"code\"));\n}\n\n/** The name of the base typed-array type of a view, or `undefined`. */\nfunction typedArrayName(value: object): string | undefined {\n const TypedArrayProto = Object.getPrototypeOf(Uint8Array.prototype) as object;\n const getter = getterOf(TypedArrayProto, Symbol.toStringTag);\n if (!getter) return undefined;\n const name = getter.call(value);\n return typeof name === \"string\" ? name : undefined;\n}\n\nfunction cloneArrayBuffer(value: ArrayBuffer): ArrayBuffer {\n const source = value as ArrayBuffer & {\n resizable?: boolean;\n maxByteLength?: number;\n };\n if (source.resizable === true) {\n const ArrayBufferClass = ArrayBuffer as unknown as new (\n length: number,\n options: { maxByteLength: number },\n ) => ArrayBuffer;\n const copy = new ArrayBufferClass(source.byteLength, {\n maxByteLength: source.maxByteLength as number,\n });\n new Uint8Array(copy).set(new Uint8Array(source));\n return copy;\n }\n return ArrayBuffer.prototype.slice.call(value, 0) as ArrayBuffer;\n}\n\nfunction cloneError(value: Error, seen: Map<object, unknown>): Error {\n let copy: Error;\n const own = (key: string) => Object.prototype.hasOwnProperty.call(value, key);\n const messageDescriptor = Object.getOwnPropertyDescriptor(value, \"message\");\n const message =\n messageDescriptor && \"value\" in messageDescriptor\n ? `${messageDescriptor.value}`\n : undefined;\n if (isDOMException(value)) {\n const DOMExceptionClass =\n globalNamed<new (message?: string, name?: string) => Error>(\n \"DOMException\",\n )!;\n copy = new DOMExceptionClass(value.message, value.name);\n } else {\n const name = ERROR_NAMES.has(value.name) ? value.name : \"Error\";\n const ErrorClass = globalNamed<ErrorConstructor>(name) ?? Error;\n copy = message === undefined ? new ErrorClass() : new ErrorClass(message);\n }\n seen.set(value, copy);\n if (typeof value.stack === \"string\") copy.stack = value.stack;\n if (!isDOMException(value)) {\n const causeDescriptor = Object.getOwnPropertyDescriptor(value, \"cause\");\n if (own(\"cause\") && causeDescriptor && \"value\" in causeDescriptor) {\n // Defined, not passed as an option: Hermes may not read ErrorOptions.\n Object.defineProperty(copy, \"cause\", {\n value: cloneInto(causeDescriptor.value, seen),\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n }\n return copy;\n}\n\nfunction cloneInto(value: unknown, seen: Map<object, unknown>): unknown {\n if (typeof value === \"function\" || typeof value === \"symbol\") {\n throw dataCloneError(describe(value));\n }\n if (typeof value !== \"object\" || value === null) return value;\n const known = seen.get(value);\n if (known !== undefined) return known;\n\n if (Array.isArray(value)) {\n // The same length, so a sparse array keeps its holes.\n const copy: unknown[] = [];\n copy.length = value.length;\n seen.set(value, copy);\n copyKeys(value, copy, seen);\n return copy;\n }\n // The common case, before the brand checks below: each one that fails\n // throws and catches an exception, which is slow on Hermes.\n if (isPlainObject(value)) {\n const copy: Record<string, unknown> = {};\n seen.set(value, copy);\n copyKeys(value, copy, seen);\n return copy;\n }\n if (hasBrand(value, Date.prototype.getTime as AnyFunction)) {\n const copy = new Date(Date.prototype.getTime.call(value));\n seen.set(value, copy);\n return copy;\n }\n if (hasBrand(value, getterOf(RegExp.prototype, \"source\"))) {\n const source = getterOf(RegExp.prototype, \"source\")!.call(value) as string;\n const flags = getterOf(RegExp.prototype, \"flags\")!.call(value) as string;\n const copy = new RegExp(source, flags);\n seen.set(value, copy);\n return copy;\n }\n if (hasBrand(value, Map.prototype.has as AnyFunction, undefined)) {\n const copy = new Map<unknown, unknown>();\n seen.set(value, copy);\n const entries: [unknown, unknown][] = [];\n Map.prototype.forEach.call(value, (entry: unknown, key: unknown) => {\n entries.push([key, entry]);\n });\n for (const [key, entry] of entries) {\n copy.set(cloneInto(key, seen), cloneInto(entry, seen));\n }\n return copy;\n }\n if (hasBrand(value, Set.prototype.has as AnyFunction, undefined)) {\n const copy = new Set<unknown>();\n seen.set(value, copy);\n const entries: unknown[] = [];\n Set.prototype.forEach.call(value, (entry: unknown) => {\n entries.push(entry);\n });\n for (const entry of entries) copy.add(cloneInto(entry, seen));\n return copy;\n }\n if (hasBrand(value, getterOf(ArrayBuffer.prototype, \"byteLength\"))) {\n const copy = cloneArrayBuffer(value as ArrayBuffer);\n seen.set(value, copy);\n return copy;\n }\n if (hasBrand(value, getterOf(protoOf(\"SharedArrayBuffer\"), \"byteLength\"))) {\n // structuredClone shares the memory of a SharedArrayBuffer.\n seen.set(value, value);\n return value;\n }\n if (ArrayBuffer.isView(value)) {\n const view = value as ArrayBufferView;\n const buffer = cloneInto(view.buffer, seen) as ArrayBuffer;\n const isDataView = hasBrand(\n value,\n getterOf(DataView.prototype, \"byteLength\"),\n );\n let copy: ArrayBufferView;\n if (isDataView) {\n copy = new DataView(buffer, view.byteOffset, view.byteLength);\n } else {\n const name = typedArrayName(value);\n const TypedArray = name\n ? globalNamed<\n new (\n buffer: ArrayBuffer,\n byteOffset: number,\n length: number,\n ) => ArrayBufferView\n >(name)\n : undefined;\n if (!TypedArray) throw dataCloneError(describe(value));\n const proto = Object.getPrototypeOf(Uint8Array.prototype) as object;\n const offset = getterOf(proto, \"byteOffset\")!.call(value) as number;\n const length = getterOf(proto, \"length\")!.call(value) as number;\n copy = new TypedArray(buffer, offset, length);\n }\n seen.set(value, copy);\n return copy;\n }\n if (isError(value)) return cloneError(value as Error, seen);\n\n for (const [name, Boxed] of [\n [\"Boolean\", Boolean],\n [\"Number\", Number],\n [\"String\", String],\n [\"BigInt\", globalNamed(\"BigInt\")],\n ] as const) {\n const valueOf = methodOf(name, \"valueOf\");\n if (Boxed && hasBrand(value, valueOf)) {\n const copy = Object(valueOf!.call(value));\n seen.set(value, copy);\n return copy;\n }\n }\n if (hasBrand(value, methodOf(\"Symbol\", \"valueOf\"))) {\n throw dataCloneError(describe(value));\n }\n const BlobClass = globalNamed<{ prototype: Blob }>(\"Blob\");\n if (typeof BlobClass === \"function\" && value instanceof BlobClass) {\n const copy = cloneBlob(value as Blob);\n seen.set(value, copy);\n return copy;\n }\n if (isUncloneable(value)) throw dataCloneError(describe(value));\n\n const copy: Record<string, unknown> = {};\n seen.set(value, copy);\n copyKeys(value, copy, seen);\n return copy;\n}\n\nfunction cloneBlob(value: Blob): Blob {\n const FileClass =\n globalNamed<\n new (\n parts: Blob[],\n name: string,\n options: { type: string; lastModified: number },\n ) => Blob\n >(\"File\");\n if (typeof FileClass === \"function\" && value instanceof FileClass) {\n const file = value as Blob & { name: string; lastModified: number };\n return new FileClass([value], file.name, {\n type: value.type,\n lastModified: file.lastModified,\n });\n }\n const BlobClass =\n globalNamed<new (parts: Blob[], options: { type: string }) => Blob>(\n \"Blob\",\n )!;\n return new BlobClass([value], { type: value.type });\n}\n\n/**\n * True for an ordinary object of this realm: its prototype is\n * `Object.prototype` or `null`, it has no `Symbol.toStringTag`, and its\n * built-in tag is \"Object\" (so not `arguments`, an `Error`, a `Date`, a\n * `RegExp` or a boxed primitive, whatever their prototype). Throws nothing.\n * An object with another slot (a `Map`, a `Set`, a `Promise`...) whose\n * prototype was changed to one of those passes too; only a brand check,\n * which throws, could tell, so it is copied as a plain object.\n */\nfunction isPlainObject(value: object): boolean {\n const proto = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto !== null) return false;\n if (Symbol.toStringTag in value) return false;\n if (ArrayBuffer.isView(value)) return false;\n return Object.prototype.toString.call(value) === \"[object Object]\";\n}\n\n/** The globals of PLATFORM_UNCLONEABLE and their prototypes, when last read. */\nlet platformCache: { classes: unknown[]; protos: object[] } | undefined;\n\n/**\n * The prototypes of the PLATFORM_UNCLONEABLE globals that exist. Kept\n * between calls, and built again only when one of the globals changed (a\n * polyfill installed late).\n */\nfunction platformPrototypes(): object[] {\n const globals = globalThis as unknown as Record<string, unknown>;\n const cached = platformCache;\n if (\n cached &&\n PLATFORM_UNCLONEABLE.every(\n (name, index) => globals[name] === cached.classes[index],\n )\n ) {\n return cached.protos;\n }\n const classes = PLATFORM_UNCLONEABLE.map((name) => globals[name]);\n const protos = PLATFORM_UNCLONEABLE.map(protoOf).filter(\n (proto): proto is object => proto !== undefined,\n );\n platformCache = { classes, protos };\n return protos;\n}\n\n/** An object that structuredClone refuses, though it has no data slot. */\nfunction isUncloneable(value: object) {\n // An arguments object: V8 refuses it. Only the built-in tag says so; an\n // object that only claims the tag is a plain object.\n if (\n !(Symbol.toStringTag in value) &&\n Object.prototype.toString.call(value) === \"[object Arguments]\"\n ) {\n return true;\n }\n if (\n hasBrand(value, methodOf(\"WeakMap\", \"has\"), {}) ||\n hasBrand(value, methodOf(\"WeakSet\", \"has\"), {}) ||\n hasBrand(value, methodOf(\"WeakRef\", \"deref\")) ||\n hasBrand(value, methodOf(\"FinalizationRegistry\", \"unregister\"), {})\n ) {\n return true;\n }\n const PromiseClass = globalNamed<{ prototype: object }>(\"Promise\");\n if (PromiseClass && value instanceof (PromiseClass as unknown as Constructor))\n return true;\n if (!iteratorProtos) iteratorProtos = iteratorPrototypes();\n if (inheritsFrom(value, iteratorProtos)) return true;\n return inheritsFrom(value, platformPrototypes());\n}\n\n/** Copies the own enumerable string keys, as structuredClone does. */\nfunction copyKeys(source: object, target: object, seen: Map<object, unknown>) {\n for (const key of Object.keys(source)) {\n assign(\n target as Record<string, unknown>,\n key,\n cloneInto((source as Record<string, unknown>)[key], seen),\n );\n }\n}\n\n/**\n * Sets an own property. A plain assignment of \"__proto__\" would change the\n * prototype of the copy instead (JSON.parse makes \"__proto__\" an own key).\n */\nfunction assign(target: Record<string, unknown>, key: string, value: unknown) {\n if (key === \"__proto__\") {\n Object.defineProperty(target, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: true,\n });\n } else {\n target[key] = value;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAO,QAAQ,OACnD,CAED,QAAO,OAAO;CAEhB,MAAM,UAAU,qBAAqB,KAAK,SAAS,QAAQ,MAAM;CACjE,MAAM,SAAS,qBAAqB,IAAI,QAAQ,CAAC,QAC9C,UAA2B,UAAU,OACvC;AACD,iBAAgB;EAAE;EAAS;EAAQ;AACnC,QAAO;;;AAIT,SAAS,cAAc,OAAe;AAGpC,KACE,EAAE,OAAO,eAAe,UACxB,OAAO,UAAU,SAAS,KAAK,MAAM,KAAK,qBAE1C,QAAO;AAET,KACE,SAAS,OAAO,SAAS,WAAW,MAAM,EAAE,EAAE,CAAC,IAC/C,SAAS,OAAO,SAAS,WAAW,MAAM,EAAE,EAAE,CAAC,IAC/C,SAAS,OAAO,SAAS,WAAW,QAAQ,CAAC,IAC7C,SAAS,OAAO,SAAS,wBAAwB,aAAa,EAAE,EAAE,CAAC,CAEnE,QAAO;CAET,MAAM,eAAe,YAAmC,UAAU;AAClE,KAAI,gBAAgB,iBAAkB,aACpC,QAAO;AACT,KAAI,CAAC,eAAgB,kBAAiB,oBAAoB;AAC1D,KAAI,aAAa,OAAO,eAAe,CAAE,QAAO;AAChD,QAAO,aAAa,OAAO,oBAAoB,CAAC;;;AAIlD,SAAS,SAAS,QAAgB,QAAgB,MAA4B;AAC5E,MAAK,MAAM,OAAO,OAAO,KAAK,OAAO,CACnC,QACE,QACA,KACA,UAAW,OAAmC,MAAM,KAAK,CAC1D;;;;;;AAQL,SAAS,OAAO,QAAiC,KAAa,OAAgB;AAC5E,KAAI,QAAQ,YACV,QAAO,eAAe,QAAQ,KAAK;EACjC;EACA,YAAY;EACZ,cAAc;EACd,UAAU;EACX,CAAC;KAEF,QAAO,OAAO"}
@@ -0,0 +1,51 @@
1
+ //#region src/generative-ui/clone-value.d.ts
2
+ /**
3
+ * A deep copy of `value` with `structuredClone` semantics. Uses the global
4
+ * `structuredClone` when there is one. Hermes (React Native) has none, so
5
+ * there a local copy runs. It decides the kind of an object by the same
6
+ * internal slots that `structuredClone` reads (brand checks), not by
7
+ * `instanceof` or `Symbol.toStringTag`, and gives what the native
8
+ * `structuredClone` of V8 gives:
9
+ *
10
+ * - `undefined`, `null`, strings, booleans, numbers (also `NaN`,
11
+ * `Infinity` and `-0`) and bigints are returned as they are.
12
+ * - Arrays and ordinary objects are copied deeply: own enumerable string
13
+ * keys only, so a class instance, or an object with its own
14
+ * `Symbol.toStringTag`, becomes a plain object. A sparse array keeps its
15
+ * holes and its length.
16
+ * - `Date`, `RegExp`, `Map`, `Set`, boxed primitives, `ArrayBuffer`s (a
17
+ * resizable one stays resizable), typed arrays (as the base type, never a
18
+ * subclass), `DataView`s, `Blob`s and `File`s are copied.
19
+ * - An `Error` becomes an `Error` of its standard type (a custom name or
20
+ * `AggregateError` becomes `Error`), with its own `message`, its `stack`
21
+ * and its own `cause`. A `DOMException` stays one where the global exists.
22
+ * - A `SharedArrayBuffer` is shared, not copied, like `structuredClone`.
23
+ * - Cycles and shared references are kept: an object reached twice is
24
+ * copied once.
25
+ * - Functions, symbols, `Symbol` wrappers, `arguments`, `WeakMap`,
26
+ * `WeakSet`, `WeakRef`, `Promise`, iterators, generators and the web
27
+ * platform objects that cannot be cloned (`URL`, `Headers`, streams...)
28
+ * throw an error named `"DataCloneError"`: a `DOMException` where the
29
+ * global exists, else an `Error` (Hermes has no `DOMException`).
30
+ *
31
+ * Two differences are left. A `Proxy` cannot be told from its target in
32
+ * JavaScript, so the local copy reads it through its traps, where the
33
+ * native one throws. And an ordinary object takes a fast path that runs no
34
+ * brand check (each failed one throws and catches an exception, slow on
35
+ * Hermes), so a `Map`, `Set`, `Promise` or other object whose prototype
36
+ * was changed to `Object.prototype` or `null` is copied as a plain object.
37
+ *
38
+ * It never installs a global `structuredClone`, and it does not use the
39
+ * JSON round trip of `structuredClone_` from `@ag-ui/client`, which turns
40
+ * `undefined` into `{}` and drops or changes values JSON cannot hold.
41
+ *
42
+ * @param value - The value to copy.
43
+ * @returns A copy that shares no object with `value`, except a
44
+ * `SharedArrayBuffer`.
45
+ * @throws An error named `"DataCloneError"` for a value that cannot be
46
+ * cloned.
47
+ */
48
+ declare function cloneValue<T>(value: T): T;
49
+ //#endregion
50
+ export { cloneValue };
51
+ //# sourceMappingURL=clone-value.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone-value.d.cts","names":[],"sources":["../../src/generative-ui/clone-value.ts"],"mappings":";;AA8CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,UAAA,GAAA,CAAc,KAAA,EAAO,CAAA,GAAI,CAAA"}
@@ -0,0 +1,51 @@
1
+ //#region src/generative-ui/clone-value.d.ts
2
+ /**
3
+ * A deep copy of `value` with `structuredClone` semantics. Uses the global
4
+ * `structuredClone` when there is one. Hermes (React Native) has none, so
5
+ * there a local copy runs. It decides the kind of an object by the same
6
+ * internal slots that `structuredClone` reads (brand checks), not by
7
+ * `instanceof` or `Symbol.toStringTag`, and gives what the native
8
+ * `structuredClone` of V8 gives:
9
+ *
10
+ * - `undefined`, `null`, strings, booleans, numbers (also `NaN`,
11
+ * `Infinity` and `-0`) and bigints are returned as they are.
12
+ * - Arrays and ordinary objects are copied deeply: own enumerable string
13
+ * keys only, so a class instance, or an object with its own
14
+ * `Symbol.toStringTag`, becomes a plain object. A sparse array keeps its
15
+ * holes and its length.
16
+ * - `Date`, `RegExp`, `Map`, `Set`, boxed primitives, `ArrayBuffer`s (a
17
+ * resizable one stays resizable), typed arrays (as the base type, never a
18
+ * subclass), `DataView`s, `Blob`s and `File`s are copied.
19
+ * - An `Error` becomes an `Error` of its standard type (a custom name or
20
+ * `AggregateError` becomes `Error`), with its own `message`, its `stack`
21
+ * and its own `cause`. A `DOMException` stays one where the global exists.
22
+ * - A `SharedArrayBuffer` is shared, not copied, like `structuredClone`.
23
+ * - Cycles and shared references are kept: an object reached twice is
24
+ * copied once.
25
+ * - Functions, symbols, `Symbol` wrappers, `arguments`, `WeakMap`,
26
+ * `WeakSet`, `WeakRef`, `Promise`, iterators, generators and the web
27
+ * platform objects that cannot be cloned (`URL`, `Headers`, streams...)
28
+ * throw an error named `"DataCloneError"`: a `DOMException` where the
29
+ * global exists, else an `Error` (Hermes has no `DOMException`).
30
+ *
31
+ * Two differences are left. A `Proxy` cannot be told from its target in
32
+ * JavaScript, so the local copy reads it through its traps, where the
33
+ * native one throws. And an ordinary object takes a fast path that runs no
34
+ * brand check (each failed one throws and catches an exception, slow on
35
+ * Hermes), so a `Map`, `Set`, `Promise` or other object whose prototype
36
+ * was changed to `Object.prototype` or `null` is copied as a plain object.
37
+ *
38
+ * It never installs a global `structuredClone`, and it does not use the
39
+ * JSON round trip of `structuredClone_` from `@ag-ui/client`, which turns
40
+ * `undefined` into `{}` and drops or changes values JSON cannot hold.
41
+ *
42
+ * @param value - The value to copy.
43
+ * @returns A copy that shares no object with `value`, except a
44
+ * `SharedArrayBuffer`.
45
+ * @throws An error named `"DataCloneError"` for a value that cannot be
46
+ * cloned.
47
+ */
48
+ declare function cloneValue<T>(value: T): T;
49
+ //#endregion
50
+ export { cloneValue };
51
+ //# sourceMappingURL=clone-value.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone-value.d.mts","names":[],"sources":["../../src/generative-ui/clone-value.ts"],"mappings":";;AA8CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,UAAA,GAAA,CAAc,KAAA,EAAO,CAAA,GAAI,CAAA"}