@copilotkit/shared 2.0.0-rc.4 → 2.0.0-rc.40

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 (562) hide show
  1. package/README.md +4 -15
  2. package/dist/a2ui-envelope.cjs +2 -2
  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 +2 -2
  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 +7 -7
  325. package/dist/generative-ui/types.d.cts.map +1 -1
  326. package/dist/generative-ui/types.d.mts +7 -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 +17 -16
  337. package/dist/index.d.cts.map +1 -1
  338. package/dist/index.d.mts +17 -16
  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 +4 -6
  383. package/dist/utils/index.d.cts.map +1 -1
  384. package/dist/utils/index.d.mts +4 -6
  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/package.json +19 -32
  413. package/scripts/verify-cjs-exports.cjs +1 -1
  414. package/src/__tests__/a2ui-envelope.test.ts +18 -13
  415. package/src/__tests__/a2ui-prompts.test.ts +47 -14
  416. package/src/__tests__/fixtures/prompt-goldens.json +354 -0
  417. package/src/__tests__/prompt-spec.test.ts +191 -0
  418. package/src/__tests__/root-entry-browser-safety.test.ts +5 -7
  419. package/src/__tests__/schema-render.test.ts +323 -0
  420. package/src/__tests__/standard-schema.test.ts +61 -101
  421. package/src/a2ui-envelope.ts +7 -6
  422. package/src/a2ui-prompts.ts +47 -96
  423. package/src/attachments/__tests__/utils.test.ts +22 -0
  424. package/src/attachments/types.ts +1 -3
  425. package/src/attachments/utils.ts +23 -5
  426. package/src/finalize-events.ts +16 -0
  427. package/src/generative-ui/__tests__/clone-value-differential.test.ts +480 -0
  428. package/src/generative-ui/__tests__/clone-value.test.ts +226 -0
  429. package/src/generative-ui/__tests__/render-ui-args.test.ts +7 -7
  430. package/src/generative-ui/__tests__/validate-operation.test.ts +19 -13
  431. package/src/generative-ui/base.ts +9 -0
  432. package/src/generative-ui/basic-functions.ts +1 -1
  433. package/src/generative-ui/catalog/catalog-export.ts +478 -0
  434. package/src/generative-ui/catalog/catalog.ts +1167 -0
  435. package/src/generative-ui/catalog/errors.ts +102 -0
  436. package/src/generative-ui/catalog/index.ts +6 -0
  437. package/src/generative-ui/catalog/json-schema.ts +14 -0
  438. package/src/generative-ui/catalog/refs.ts +87 -0
  439. package/src/generative-ui/catalog/schema.ts +107 -0
  440. package/src/generative-ui/child-refs.ts +5 -4
  441. package/src/generative-ui/clone-value.ts +511 -0
  442. package/src/generative-ui/compact-schema.ts +277 -0
  443. package/src/generative-ui/index.ts +14 -0
  444. package/src/generative-ui/is-record.ts +6 -1
  445. package/src/generative-ui/prompt-spec.ts +335 -0
  446. package/src/generative-ui/prompt.ts +25 -75
  447. package/src/generative-ui/render-ui-args.ts +3 -0
  448. package/src/generative-ui/schema-render.ts +378 -0
  449. package/src/generative-ui/standard/__tests__/standard-helpers.test.ts +407 -0
  450. package/src/generative-ui/standard/__tests__/theme.test.ts +61 -0
  451. package/src/generative-ui/standard/__tests__/tokens.test.ts +139 -0
  452. package/src/generative-ui/standard/chart-config.ts +434 -0
  453. package/src/generative-ui/standard/chart.ts +79 -0
  454. package/src/generative-ui/standard/checks.ts +98 -0
  455. package/src/generative-ui/standard/components.ts +35 -0
  456. package/src/generative-ui/standard/composites.ts +158 -0
  457. package/src/generative-ui/standard/data.ts +213 -0
  458. package/src/generative-ui/standard/declarations.ts +57 -0
  459. package/src/generative-ui/standard/feedback.ts +105 -0
  460. package/src/generative-ui/standard/index.ts +55 -0
  461. package/src/generative-ui/standard/inputs.ts +423 -0
  462. package/src/generative-ui/standard/layout.ts +312 -0
  463. package/src/generative-ui/standard/map-helpers.ts +155 -0
  464. package/src/generative-ui/standard/map.ts +32 -0
  465. package/src/generative-ui/standard/media.ts +265 -0
  466. package/src/generative-ui/standard/parameter-order.ts +155 -0
  467. package/src/generative-ui/standard/style-helpers.ts +170 -0
  468. package/src/generative-ui/standard/styles.ts +79 -0
  469. package/src/generative-ui/standard/text.ts +210 -0
  470. package/src/generative-ui/standard/theme.ts +198 -0
  471. package/src/generative-ui/standard/tokens.ts +317 -0
  472. package/src/generative-ui/standard/url.ts +51 -0
  473. package/src/generative-ui/thrown.ts +90 -0
  474. package/src/generative-ui/types.ts +10 -7
  475. package/src/generative-ui/validate-operation.ts +2 -2
  476. package/src/index.ts +9 -17
  477. package/src/standard-schema.ts +24 -27
  478. package/src/telemetry/lambda-client.ts +8 -3
  479. package/src/telemetry/model-host.test.ts +2 -5
  480. package/src/telemetry/telemetry-disabled.ts +0 -5
  481. package/src/types/message.ts +1 -19
  482. package/src/utils/__tests__/errors.test.ts +44 -0
  483. package/src/utils/__tests__/json-schema.test.ts +3 -479
  484. package/src/utils/__tests__/random-id.test.ts +37 -0
  485. package/src/utils/errors.ts +28 -85
  486. package/src/utils/index.ts +0 -2
  487. package/src/utils/inspector-visibility.test.ts +26 -0
  488. package/src/utils/inspector-visibility.ts +35 -3
  489. package/src/utils/json-schema.ts +5 -152
  490. package/src/utils/random-id.ts +17 -37
  491. package/tsconfig.json +3 -1
  492. package/tsdown.config.ts +2 -19
  493. package/dist/event-transforms/index.cjs +0 -15
  494. package/dist/event-transforms/index.d.cts +0 -4
  495. package/dist/event-transforms/index.d.mts +0 -4
  496. package/dist/event-transforms/index.mjs +0 -5
  497. package/dist/event-transforms/open-generative-ui-middleware.cjs +0 -286
  498. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +0 -1
  499. package/dist/event-transforms/open-generative-ui-middleware.d.cts +0 -60
  500. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +0 -1
  501. package/dist/event-transforms/open-generative-ui-middleware.d.mts +0 -60
  502. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +0 -1
  503. package/dist/event-transforms/open-generative-ui-middleware.mjs +0 -283
  504. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +0 -1
  505. package/dist/event-transforms/recorded-events.cjs +0 -59
  506. package/dist/event-transforms/recorded-events.cjs.map +0 -1
  507. package/dist/event-transforms/recorded-events.d.cts +0 -23
  508. package/dist/event-transforms/recorded-events.d.cts.map +0 -1
  509. package/dist/event-transforms/recorded-events.d.mts +0 -23
  510. package/dist/event-transforms/recorded-events.d.mts.map +0 -1
  511. package/dist/event-transforms/recorded-events.mjs +0 -58
  512. package/dist/event-transforms/recorded-events.mjs.map +0 -1
  513. package/dist/telemetry/events.d.cts +0 -72
  514. package/dist/telemetry/events.d.cts.map +0 -1
  515. package/dist/telemetry/events.d.mts +0 -72
  516. package/dist/telemetry/events.d.mts.map +0 -1
  517. package/dist/telemetry/index.cjs +0 -18
  518. package/dist/telemetry/index.d.cts +0 -5
  519. package/dist/telemetry/index.d.mts +0 -5
  520. package/dist/telemetry/index.mjs +0 -6
  521. package/dist/telemetry/telemetry-client.cjs +0 -165
  522. package/dist/telemetry/telemetry-client.cjs.map +0 -1
  523. package/dist/telemetry/telemetry-client.d.cts +0 -87
  524. package/dist/telemetry/telemetry-client.d.cts.map +0 -1
  525. package/dist/telemetry/telemetry-client.d.mts +0 -87
  526. package/dist/telemetry/telemetry-client.d.mts.map +0 -1
  527. package/dist/telemetry/telemetry-client.mjs +0 -164
  528. package/dist/telemetry/telemetry-client.mjs.map +0 -1
  529. package/dist/telemetry/utils.cjs +0 -14
  530. package/dist/telemetry/utils.cjs.map +0 -1
  531. package/dist/telemetry/utils.mjs +0 -13
  532. package/dist/telemetry/utils.mjs.map +0 -1
  533. package/dist/utils/conditions.cjs +0 -32
  534. package/dist/utils/conditions.cjs.map +0 -1
  535. package/dist/utils/conditions.d.cts +0 -31
  536. package/dist/utils/conditions.d.cts.map +0 -1
  537. package/dist/utils/conditions.d.mts +0 -31
  538. package/dist/utils/conditions.d.mts.map +0 -1
  539. package/dist/utils/conditions.mjs +0 -31
  540. package/dist/utils/conditions.mjs.map +0 -1
  541. package/dist/utils/console-styling.cjs +0 -91
  542. package/dist/utils/console-styling.cjs.map +0 -1
  543. package/dist/utils/console-styling.d.cts +0 -65
  544. package/dist/utils/console-styling.d.cts.map +0 -1
  545. package/dist/utils/console-styling.d.mts +0 -65
  546. package/dist/utils/console-styling.d.mts.map +0 -1
  547. package/dist/utils/console-styling.mjs +0 -85
  548. package/dist/utils/console-styling.mjs.map +0 -1
  549. package/src/__tests__/zod-regression.test.ts +0 -319
  550. package/src/event-transforms/index.ts +0 -5
  551. package/src/event-transforms/open-generative-ui-middleware.ts +0 -392
  552. package/src/event-transforms/recorded-events.test.ts +0 -166
  553. package/src/event-transforms/recorded-events.ts +0 -74
  554. package/src/telemetry/events.ts +0 -68
  555. package/src/telemetry/index.ts +0 -9
  556. package/src/telemetry/telemetry-blank-license-identity.test.ts +0 -128
  557. package/src/telemetry/telemetry-client.test.ts +0 -798
  558. package/src/telemetry/telemetry-client.ts +0 -328
  559. package/src/telemetry/utils.ts +0 -15
  560. package/src/utils/__tests__/conditions.test.ts +0 -161
  561. package/src/utils/conditions.ts +0 -116
  562. package/src/utils/console-styling.ts +0 -126
@@ -1,6 +1,8 @@
1
1
  const require_basic_functions = require('./basic-functions.cjs');
2
2
  const require_types = require('./types.cjs');
3
+ const require_prompt_spec = require('./prompt-spec.cjs');
3
4
  const require_a2ui_prompts = require('../a2ui-prompts.cjs');
5
+ const require_schema_render = require('./schema-render.cjs');
4
6
 
5
7
  //#region src/generative-ui/prompt.ts
6
8
  const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
@@ -15,19 +17,14 @@ function shorten(text) {
15
17
  * the `render_ui` rules, the targets, components, functions, and surfaces of
16
18
  * the manifest. It is in shared so that the inspector shows the same text.
17
19
  */
18
- function buildGenerativeUIPrompt(manifest) {
20
+ function buildGenerativeUIPrompt(manifest, spec = require_prompt_spec.defaultGenerativeUIPromptSpec()) {
19
21
  const targets = manifest.targets.map((t) => {
20
22
  const place = t.kind === "chat" ? "inside the chat transcript" : "a named area of the app";
21
23
  const limit = t.components ? `; only ${t.components.join(", ") || "no components"}` : "";
22
24
  const description = t.description ? `: ${t.description}` : "";
23
25
  return `- "${t.id}" (${place}${limit})${description}`;
24
26
  }).join("\n");
25
- const components = Object.entries(manifest.components).map(([name, c]) => {
26
- const lines = [`- **${name}**${c.description ? `: ${c.description}` : ""}`, ` props: ${JSON.stringify(c.props)}`];
27
- if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
28
- if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
29
- return lines.join("\n");
30
- }).join("\n");
27
+ const components = require_schema_render.renderGenerativeUIComponentList(manifest.components, spec.schema.tool);
31
28
  const functions = Object.entries(manifest.functions).map(([name, f]) => {
32
29
  const signature = f.parameters.description;
33
30
  const args = typeof signature === "string" && signature.startsWith("{") && Object.keys(f.parameters).length === 2 ? signature : JSON.stringify(f.parameters);
@@ -42,38 +39,15 @@ function buildGenerativeUIPrompt(manifest) {
42
39
  return lines.join("\n");
43
40
  }).join("\n");
44
41
  const surfaceNotes = Object.values(manifest.surfaces).some((s) => s.dataModel !== void 0 || (s.rejected?.length ?? 0) > 0) ? "User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\n" : "";
45
- const { functions: hasFunctions, events, templates, checks } = require_a2ui_prompts.generativeUIGuideFeatures(manifest);
46
- const agentCalls = hasFunctions && require_types.GENERATIVE_UI_AGENT_FUNCTION_CALLS;
47
- const operations = [
48
- "{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
49
- "{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
50
- "{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
51
- "{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
52
- ...agentCalls ? ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."] : []
53
- ];
54
- const rules = [
55
- "Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
56
- "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
57
- "Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
58
- "Updating a component replaces all of its props, so resend every prop.",
59
- "Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
60
- ...events ? [hasFunctions ? "Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below." : "Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."] : [],
61
- "To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
62
- "Never use a surfaceId again, also after deleteSurface.",
63
- "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
64
- "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.",
65
- "For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
66
- ...checks ? ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks."] : [],
67
- ...templates ? ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."] : [],
68
- ...agentCalls ? ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."] : []
69
- ];
42
+ const features = require_prompt_spec.generativeUIPromptFeatures(require_a2ui_prompts.generativeUIGuideFeatures(manifest));
43
+ const { intro, whenToShow } = spec.tool;
44
+ const operations = require_prompt_spec.selectPromptItems(spec.tool.operations ?? [], features);
45
+ const rules = require_prompt_spec.selectPromptItems(spec.tool.rules, features);
70
46
  return [
71
47
  `## Generative UI
72
- Call \`${require_types.GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).
73
-
74
- ${require_a2ui_prompts.GENERATIVE_UI_WHEN_TO_SHOW}
48
+ ${intro}
75
49
 
76
- Every operation has "version":"v1.0" and exactly one of:
50
+ ${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"1.0" and exactly one of:
77
51
  ${operations.map((op) => `- ${op}`).join("\n")}
78
52
 
79
53
  Rules:
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.cjs","names":["functionCallers","GENERATIVE_UI_AGENT_FUNCTION_CALLS","generativeUIGuideFeatures","GENERATIVE_UI_RENDER_TOOL","GENERATIVE_UI_WHEN_TO_SHOW"],"sources":["../../src/generative-ui/prompt.ts"],"sourcesContent":["import {\n GENERATIVE_UI_WHEN_TO_SHOW,\n generativeUIGuideFeatures,\n} from \"../a2ui-prompts\";\nimport { functionCallers } from \"./basic-functions\";\nimport {\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_RENDER_TOOL,\n} from \"./types\";\nimport type { GenerativeUIManifest } from \"./types\";\n\nexport const GENERATIVE_UI_CONTEXT_DESCRIPTION =\n \"Generative UI guide: available components, functions, targets, and how to call render_ui.\";\n\n/** Most characters of the user values of one surface in the guide. */\nconst MAX_USER_VALUES_LENGTH = 500;\n\n/** Cuts long text and marks the cut with \"...\". */\nfunction shorten(text: string) {\n return text.length > MAX_USER_VALUES_LENGTH\n ? `${text.slice(0, MAX_USER_VALUES_LENGTH)}...`\n : text;\n}\n\n/**\n * The guide that the runtime adds as a context entry to a tool-transport run:\n * the `render_ui` rules, the targets, components, functions, and surfaces of\n * the manifest. It is in shared so that the inspector shows the same text.\n */\nexport function buildGenerativeUIPrompt(manifest: GenerativeUIManifest) {\n const targets = manifest.targets\n .map((t) => {\n const place =\n t.kind === \"chat\"\n ? \"inside the chat transcript\"\n : \"a named area of the app\";\n const limit = t.components\n ? `; only ${t.components.join(\", \") || \"no components\"}`\n : \"\";\n const description = t.description ? `: ${t.description}` : \"\";\n return `- \"${t.id}\" (${place}${limit})${description}`;\n })\n .join(\"\\n\");\n const components = Object.entries(manifest.components)\n .map(([name, c]) => {\n const lines = [\n `- **${name}**${c.description ? `: ${c.description}` : \"\"}`,\n ` props: ${JSON.stringify(c.props)}`,\n ];\n if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);\n if (c.slots)\n lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n const functions = Object.entries(manifest.functions)\n .map(([name, f]) => {\n // A built-in function carries its short signature in the description\n // of its parameters; an app function has a JSON Schema.\n const signature = f.parameters.description;\n const args =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(f.parameters).length === 2\n ? signature\n : JSON.stringify(f.parameters);\n // A function is for the UI unless marked: the agent calls only what\n // the mark allows.\n const callers = functionCallers(f);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- **${name}**${who}${f.description ? `: ${f.description}` : \"\"}\\n args: ${args}`;\n })\n .join(\"\\n\");\n const surfaces = Object.entries(manifest.surfaces)\n .map(([id, s]) => {\n const state =\n s.status === \"deleted\"\n ? \", deleted: never use this id again\"\n : s.status === \"failed\"\n ? \", not created: send a corrected createSurface with this id\"\n : \"\";\n const lines = [`- \"${id}\" (target \"${s.target}\"${state})`];\n if (s.dataModel) {\n lines.push(` user values: ${shorten(JSON.stringify(s.dataModel))}`);\n }\n for (const rejection of s.rejected ?? []) {\n lines.push(` rejected: ${rejection}`);\n }\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n const hasSurfaceNotes = Object.values(manifest.surfaces).some(\n (s) => s.dataModel !== undefined || (s.rejected?.length ?? 0) > 0,\n );\n const surfaceNotes = hasSurfaceNotes\n ? \"User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\\n\"\n : \"\";\n\n // Rules for functions, events, and templates go only to runs whose manifest\n // has them, so the guide stays small.\n const {\n functions: hasFunctions,\n events,\n templates,\n checks,\n } = generativeUIGuideFeatures(manifest);\n // The agent calls functions only while that path is on.\n const agentCalls = hasFunctions && GENERATIVE_UI_AGENT_FUNCTION_CALLS;\n const operations = [\n '{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.',\n '{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.',\n '{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".',\n '{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.',\n ...(agentCalls\n ? [\n '{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface.',\n ]\n : []),\n ];\n const eventRule = hasFunctions\n ? 'Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below.'\n : 'Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".';\n const rules = [\n 'Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.',\n 'A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.',\n 'Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.',\n \"Updating a component replaces all of its props, so resend every prop.\",\n 'Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.',\n ...(events ? [eventRule] : []),\n \"To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.\",\n \"Never use a surfaceId again, also after deleteSurface.\",\n 'A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.',\n '${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.',\n \"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.\",\n ...(checks\n ? [\n 'Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks.',\n ]\n : []),\n ...(templates\n ? [\n 'To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1.',\n ]\n : []),\n ...(agentCalls\n ? [\n \"Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.\",\n 'The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it.',\n ]\n : []),\n ];\n\n return [\n `## Generative UI\nCall \\`${GENERATIVE_UI_RENDER_TOOL}\\` to show UI. Arguments: \\`target\\` first, then \\`operations\\` (A2UI v1.0 operations, applied in order).\n\n${GENERATIVE_UI_WHEN_TO_SHOW}\n\nEvery operation has \"version\":\"v1.0\" and exactly one of:\n${operations.map((op) => `- ${op}`).join(\"\\n\")}\n\nRules:\n${rules.map((rule, index) => `${index + 1}. ${rule}`).join(\"\\n\")}`,\n `### Targets\\n${targets || \"- none\"}`,\n `### Components\\n${components || \"- none\"}`,\n `### Functions\\n${functions || \"- none\"}`,\n `### Existing surfaces\\n${surfaceNotes}${surfaces || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n"],"mappings":";;;;;AAWA,MAAa,oCACX;;AAGF,MAAM,yBAAyB;;AAG/B,SAAS,QAAQ,MAAc;AAC7B,QAAO,KAAK,SAAS,yBACjB,GAAG,KAAK,MAAM,GAAG,uBAAuB,CAAC,OACzC;;;;;;;AAQN,SAAgB,wBAAwB,UAAgC;CACtE,MAAM,UAAU,SAAS,QACtB,KAAK,MAAM;EACV,MAAM,QACJ,EAAE,SAAS,SACP,+BACA;EACN,MAAM,QAAQ,EAAE,aACZ,UAAU,EAAE,WAAW,KAAK,KAAK,IAAI,oBACrC;EACJ,MAAM,cAAc,EAAE,cAAc,KAAK,EAAE,gBAAgB;AAC3D,SAAO,MAAM,EAAE,GAAG,KAAK,QAAQ,MAAM,GAAG;GACxC,CACD,KAAK,KAAK;CACb,MAAM,aAAa,OAAO,QAAQ,SAAS,WAAW,CACnD,KAAK,CAAC,MAAM,OAAO;EAClB,MAAM,QAAQ,CACZ,OAAO,KAAK,IAAI,EAAE,cAAc,KAAK,EAAE,gBAAgB,MACvD,YAAY,KAAK,UAAU,EAAE,MAAM,GACpC;AACD,MAAI,EAAE,OAAQ,OAAM,KAAK,kBAAkB,KAAK,UAAU,EAAE,OAAO,GAAG;AACtE,MAAI,EAAE,MACJ,OAAM,KAAK,iCAAiC,KAAK,UAAU,EAAE,MAAM,GAAG;AACxE,SAAO,MAAM,KAAK,KAAK;GACvB,CACD,KAAK,KAAK;CACb,MAAM,YAAY,OAAO,QAAQ,SAAS,UAAU,CACjD,KAAK,CAAC,MAAM,OAAO;EAGlB,MAAM,YAAY,EAAE,WAAW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,GAAI,aACA,CACE,6PACA,4TACD,GACD,EAAE;EACP;AAED,QAAO;EACL;SACKE,wCAA0B;;EAEjCC,gDAA2B;;;EAG3B,WAAW,KAAK,OAAO,KAAK,KAAK,CAAC,KAAK,KAAK,CAAC;;;EAG7C,MAAM,KAAK,MAAM,UAAU,GAAG,QAAQ,EAAE,IAAI,OAAO,CAAC,KAAK,KAAK;EAC5D,gBAAgB,WAAW;EAC3B,mBAAmB,cAAc;EACjC,kBAAkB,aAAa;EAC/B,0BAA0B,eAAe,YAAY;EACtD,CAAC,KAAK,OAAO"}
1
+ {"version":3,"file":"prompt.cjs","names":["defaultGenerativeUIPromptSpec","renderGenerativeUIComponentList","functionCallers","GENERATIVE_UI_AGENT_FUNCTION_CALLS","generativeUIPromptFeatures","generativeUIGuideFeatures","selectPromptItems"],"sources":["../../src/generative-ui/prompt.ts"],"sourcesContent":["import { generativeUIGuideFeatures } from \"../a2ui-prompts\";\nimport { functionCallers } from \"./basic-functions\";\nimport {\n defaultGenerativeUIPromptSpec,\n generativeUIPromptFeatures,\n selectPromptItems,\n} from \"./prompt-spec\";\nimport type { GenerativeUIPromptSpec } from \"./prompt-spec\";\nimport { renderGenerativeUIComponentList } from \"./schema-render\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type { GenerativeUIManifest } from \"./types\";\n\nexport const GENERATIVE_UI_CONTEXT_DESCRIPTION =\n \"Generative UI guide: available components, functions, targets, and how to call render_ui.\";\n\n/** Most characters of the user values of one surface in the guide. */\nconst MAX_USER_VALUES_LENGTH = 500;\n\n/** Cuts long text and marks the cut with \"...\". */\nfunction shorten(text: string) {\n return text.length > MAX_USER_VALUES_LENGTH\n ? `${text.slice(0, MAX_USER_VALUES_LENGTH)}...`\n : text;\n}\n\n/**\n * The guide that the runtime adds as a context entry to a tool-transport run:\n * the `render_ui` rules, the targets, components, functions, and surfaces of\n * the manifest. It is in shared so that the inspector shows the same text.\n */\nexport function buildGenerativeUIPrompt(\n manifest: GenerativeUIManifest,\n spec: GenerativeUIPromptSpec = defaultGenerativeUIPromptSpec(),\n) {\n const targets = manifest.targets\n .map((t) => {\n const place =\n t.kind === \"chat\"\n ? \"inside the chat transcript\"\n : \"a named area of the app\";\n const limit = t.components\n ? `; only ${t.components.join(\", \") || \"no components\"}`\n : \"\";\n const description = t.description ? `: ${t.description}` : \"\";\n return `- \"${t.id}\" (${place}${limit})${description}`;\n })\n .join(\"\\n\");\n const components = renderGenerativeUIComponentList(\n manifest.components,\n spec.schema.tool,\n );\n const functions = Object.entries(manifest.functions)\n .map(([name, f]) => {\n // A built-in function carries its short signature in the description\n // of its parameters; an app function has a JSON Schema.\n const signature = f.parameters.description;\n const args =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(f.parameters).length === 2\n ? signature\n : JSON.stringify(f.parameters);\n // A function is for the UI unless marked: the agent calls only what\n // the mark allows.\n const callers = functionCallers(f);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- **${name}**${who}${f.description ? `: ${f.description}` : \"\"}\\n args: ${args}`;\n })\n .join(\"\\n\");\n const surfaces = Object.entries(manifest.surfaces)\n .map(([id, s]) => {\n const state =\n s.status === \"deleted\"\n ? \", deleted: never use this id again\"\n : s.status === \"failed\"\n ? \", not created: send a corrected createSurface with this id\"\n : \"\";\n const lines = [`- \"${id}\" (target \"${s.target}\"${state})`];\n if (s.dataModel) {\n lines.push(` user values: ${shorten(JSON.stringify(s.dataModel))}`);\n }\n for (const rejection of s.rejected ?? []) {\n lines.push(` rejected: ${rejection}`);\n }\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n const hasSurfaceNotes = Object.values(manifest.surfaces).some(\n (s) => s.dataModel !== undefined || (s.rejected?.length ?? 0) > 0,\n );\n const surfaceNotes = hasSurfaceNotes\n ? \"User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\\n\"\n : \"\";\n\n // Rules for functions, events, and templates go only to runs whose manifest\n // has them, so the guide stays small.\n const features = generativeUIPromptFeatures(\n generativeUIGuideFeatures(manifest),\n );\n const { intro, whenToShow } = spec.tool;\n const operations = selectPromptItems(spec.tool.operations ?? [], features);\n const rules = selectPromptItems(spec.tool.rules, features);\n const when = whenToShow ? `${whenToShow}\\n\\n` : \"\";\n\n return [\n `## Generative UI\n${intro}\n\n${when}Every operation has \"version\":\"1.0\" and exactly one of:\n${operations.map((op) => `- ${op}`).join(\"\\n\")}\n\nRules:\n${rules.map((rule, index) => `${index + 1}. ${rule}`).join(\"\\n\")}`,\n `### Targets\\n${targets || \"- none\"}`,\n `### Components\\n${components || \"- none\"}`,\n `### Functions\\n${functions || \"- none\"}`,\n `### Existing surfaces\\n${surfaceNotes}${surfaces || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n"],"mappings":";;;;;;;AAYA,MAAa,oCACX;;AAGF,MAAM,yBAAyB;;AAG/B,SAAS,QAAQ,MAAc;AAC7B,QAAO,KAAK,SAAS,yBACjB,GAAG,KAAK,MAAM,GAAG,uBAAuB,CAAC,OACzC;;;;;;;AAQN,SAAgB,wBACd,UACA,OAA+BA,mDAA+B,EAC9D;CACA,MAAM,UAAU,SAAS,QACtB,KAAK,MAAM;EACV,MAAM,QACJ,EAAE,SAAS,SACP,+BACA;EACN,MAAM,QAAQ,EAAE,aACZ,UAAU,EAAE,WAAW,KAAK,KAAK,IAAI,oBACrC;EACJ,MAAM,cAAc,EAAE,cAAc,KAAK,EAAE,gBAAgB;AAC3D,SAAO,MAAM,EAAE,GAAG,KAAK,QAAQ,MAAM,GAAG;GACxC,CACD,KAAK,KAAK;CACb,MAAM,aAAaC,sDACjB,SAAS,YACT,KAAK,OAAO,KACb;CACD,MAAM,YAAY,OAAO,QAAQ,SAAS,UAAU,CACjD,KAAK,CAAC,MAAM,OAAO;EAGlB,MAAM,YAAY,EAAE,WAAW;EAC/B,MAA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AAI,OAAO,CAAC,KAAK,KAAK;EAC5D,gBAAgB,WAAW;EAC3B,mBAAmB,cAAc;EACjC,kBAAkB,aAAa;EAC/B,0BAA0B,eAAe,YAAY;EACtD,CAAC,KAAK,OAAO"}
@@ -1,4 +1,5 @@
1
1
  import { GenerativeUIManifest } from "./types.cjs";
2
+ import { GenerativeUIPromptSpec } from "./prompt-spec.cjs";
2
3
 
3
4
  //#region src/generative-ui/prompt.d.ts
4
5
  declare const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
@@ -7,7 +8,7 @@ declare const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: availabl
7
8
  * the `render_ui` rules, the targets, components, functions, and surfaces of
8
9
  * the manifest. It is in shared so that the inspector shows the same text.
9
10
  */
10
- declare function buildGenerativeUIPrompt(manifest: GenerativeUIManifest): string;
11
+ declare function buildGenerativeUIPrompt(manifest: GenerativeUIManifest, spec?: GenerativeUIPromptSpec): string;
11
12
  //#endregion
12
13
  export { GENERATIVE_UI_CONTEXT_DESCRIPTION, buildGenerativeUIPrompt };
13
14
  //# sourceMappingURL=prompt.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.cts","names":[],"sources":["../../src/generative-ui/prompt.ts"],"mappings":";;;cAWa,iCAAA;;AAAb;;;;iBAkBgB,uBAAA,CAAwB,QAAA,EAAU,oBAAA"}
1
+ {"version":3,"file":"prompt.d.cts","names":[],"sources":["../../src/generative-ui/prompt.ts"],"mappings":";;;;cAYa,iCAAA;;AAAb;;;;iBAkBgB,uBAAA,CACd,QAAA,EAAU,oBAAA,EACV,IAAA,GAAM,sBAAA"}
@@ -1,4 +1,5 @@
1
1
  import { GenerativeUIManifest } from "./types.mjs";
2
+ import { GenerativeUIPromptSpec } from "./prompt-spec.mjs";
2
3
 
3
4
  //#region src/generative-ui/prompt.d.ts
4
5
  declare const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
@@ -7,7 +8,7 @@ declare const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: availabl
7
8
  * the `render_ui` rules, the targets, components, functions, and surfaces of
8
9
  * the manifest. It is in shared so that the inspector shows the same text.
9
10
  */
10
- declare function buildGenerativeUIPrompt(manifest: GenerativeUIManifest): string;
11
+ declare function buildGenerativeUIPrompt(manifest: GenerativeUIManifest, spec?: GenerativeUIPromptSpec): string;
11
12
  //#endregion
12
13
  export { GENERATIVE_UI_CONTEXT_DESCRIPTION, buildGenerativeUIPrompt };
13
14
  //# sourceMappingURL=prompt.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.mts","names":[],"sources":["../../src/generative-ui/prompt.ts"],"mappings":";;;cAWa,iCAAA;;AAAb;;;;iBAkBgB,uBAAA,CAAwB,QAAA,EAAU,oBAAA"}
1
+ {"version":3,"file":"prompt.d.mts","names":[],"sources":["../../src/generative-ui/prompt.ts"],"mappings":";;;;cAYa,iCAAA;;AAAb;;;;iBAkBgB,uBAAA,CACd,QAAA,EAAU,oBAAA,EACV,IAAA,GAAM,sBAAA"}
@@ -1,6 +1,8 @@
1
1
  import { functionCallers } from "./basic-functions.mjs";
2
- import { GENERATIVE_UI_AGENT_FUNCTION_CALLS, GENERATIVE_UI_RENDER_TOOL } from "./types.mjs";
3
- import { GENERATIVE_UI_WHEN_TO_SHOW, generativeUIGuideFeatures } from "../a2ui-prompts.mjs";
2
+ import { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from "./types.mjs";
3
+ import { defaultGenerativeUIPromptSpec, generativeUIPromptFeatures, selectPromptItems } from "./prompt-spec.mjs";
4
+ import { generativeUIGuideFeatures } from "../a2ui-prompts.mjs";
5
+ import { renderGenerativeUIComponentList } from "./schema-render.mjs";
4
6
 
5
7
  //#region src/generative-ui/prompt.ts
6
8
  const GENERATIVE_UI_CONTEXT_DESCRIPTION = "Generative UI guide: available components, functions, targets, and how to call render_ui.";
@@ -15,19 +17,14 @@ function shorten(text) {
15
17
  * the `render_ui` rules, the targets, components, functions, and surfaces of
16
18
  * the manifest. It is in shared so that the inspector shows the same text.
17
19
  */
18
- function buildGenerativeUIPrompt(manifest) {
20
+ function buildGenerativeUIPrompt(manifest, spec = defaultGenerativeUIPromptSpec()) {
19
21
  const targets = manifest.targets.map((t) => {
20
22
  const place = t.kind === "chat" ? "inside the chat transcript" : "a named area of the app";
21
23
  const limit = t.components ? `; only ${t.components.join(", ") || "no components"}` : "";
22
24
  const description = t.description ? `: ${t.description}` : "";
23
25
  return `- "${t.id}" (${place}${limit})${description}`;
24
26
  }).join("\n");
25
- const components = Object.entries(manifest.components).map(([name, c]) => {
26
- const lines = [`- **${name}**${c.description ? `: ${c.description}` : ""}`, ` props: ${JSON.stringify(c.props)}`];
27
- if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);
28
- if (c.slots) lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);
29
- return lines.join("\n");
30
- }).join("\n");
27
+ const components = renderGenerativeUIComponentList(manifest.components, spec.schema.tool);
31
28
  const functions = Object.entries(manifest.functions).map(([name, f]) => {
32
29
  const signature = f.parameters.description;
33
30
  const args = typeof signature === "string" && signature.startsWith("{") && Object.keys(f.parameters).length === 2 ? signature : JSON.stringify(f.parameters);
@@ -42,38 +39,15 @@ function buildGenerativeUIPrompt(manifest) {
42
39
  return lines.join("\n");
43
40
  }).join("\n");
44
41
  const surfaceNotes = Object.values(manifest.surfaces).some((s) => s.dataModel !== void 0 || (s.rejected?.length ?? 0) > 0) ? "User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\n" : "";
45
- const { functions: hasFunctions, events, templates, checks } = generativeUIGuideFeatures(manifest);
46
- const agentCalls = hasFunctions && GENERATIVE_UI_AGENT_FUNCTION_CALLS;
47
- const operations = [
48
- "{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.",
49
- "{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.",
50
- "{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".",
51
- "{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.",
52
- ...agentCalls ? ["{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface."] : []
53
- ];
54
- const rules = [
55
- "Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.",
56
- "A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.",
57
- "Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.",
58
- "Updating a component replaces all of its props, so resend every prop.",
59
- "Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.",
60
- ...events ? [hasFunctions ? "Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below." : "Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\"."] : [],
61
- "To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.",
62
- "Never use a surfaceId again, also after deleteSurface.",
63
- "A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.",
64
- "${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.",
65
- "For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.",
66
- ...checks ? ["Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks."] : [],
67
- ...templates ? ["To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1."] : [],
68
- ...agentCalls ? ["Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.", "The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it."] : []
69
- ];
42
+ const features = generativeUIPromptFeatures(generativeUIGuideFeatures(manifest));
43
+ const { intro, whenToShow } = spec.tool;
44
+ const operations = selectPromptItems(spec.tool.operations ?? [], features);
45
+ const rules = selectPromptItems(spec.tool.rules, features);
70
46
  return [
71
47
  `## Generative UI
72
- Call \`${GENERATIVE_UI_RENDER_TOOL}\` to show UI. Arguments: \`target\` first, then \`operations\` (A2UI v1.0 operations, applied in order).
73
-
74
- ${GENERATIVE_UI_WHEN_TO_SHOW}
48
+ ${intro}
75
49
 
76
- Every operation has "version":"v1.0" and exactly one of:
50
+ ${whenToShow ? `${whenToShow}\n\n` : ""}Every operation has "version":"1.0" and exactly one of:
77
51
  ${operations.map((op) => `- ${op}`).join("\n")}
78
52
 
79
53
  Rules:
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.mjs","names":[],"sources":["../../src/generative-ui/prompt.ts"],"sourcesContent":["import {\n GENERATIVE_UI_WHEN_TO_SHOW,\n generativeUIGuideFeatures,\n} from \"../a2ui-prompts\";\nimport { functionCallers } from \"./basic-functions\";\nimport {\n GENERATIVE_UI_AGENT_FUNCTION_CALLS,\n GENERATIVE_UI_RENDER_TOOL,\n} from \"./types\";\nimport type { GenerativeUIManifest } from \"./types\";\n\nexport const GENERATIVE_UI_CONTEXT_DESCRIPTION =\n \"Generative UI guide: available components, functions, targets, and how to call render_ui.\";\n\n/** Most characters of the user values of one surface in the guide. */\nconst MAX_USER_VALUES_LENGTH = 500;\n\n/** Cuts long text and marks the cut with \"...\". */\nfunction shorten(text: string) {\n return text.length > MAX_USER_VALUES_LENGTH\n ? `${text.slice(0, MAX_USER_VALUES_LENGTH)}...`\n : text;\n}\n\n/**\n * The guide that the runtime adds as a context entry to a tool-transport run:\n * the `render_ui` rules, the targets, components, functions, and surfaces of\n * the manifest. It is in shared so that the inspector shows the same text.\n */\nexport function buildGenerativeUIPrompt(manifest: GenerativeUIManifest) {\n const targets = manifest.targets\n .map((t) => {\n const place =\n t.kind === \"chat\"\n ? \"inside the chat transcript\"\n : \"a named area of the app\";\n const limit = t.components\n ? `; only ${t.components.join(\", \") || \"no components\"}`\n : \"\";\n const description = t.description ? `: ${t.description}` : \"\";\n return `- \"${t.id}\" (${place}${limit})${description}`;\n })\n .join(\"\\n\");\n const components = Object.entries(manifest.components)\n .map(([name, c]) => {\n const lines = [\n `- **${name}**${c.description ? `: ${c.description}` : \"\"}`,\n ` props: ${JSON.stringify(c.props)}`,\n ];\n if (c.events) lines.push(` event props: ${JSON.stringify(c.events)}`);\n if (c.slots)\n lines.push(` slot props (component ids): ${JSON.stringify(c.slots)}`);\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n const functions = Object.entries(manifest.functions)\n .map(([name, f]) => {\n // A built-in function carries its short signature in the description\n // of its parameters; an app function has a JSON Schema.\n const signature = f.parameters.description;\n const args =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(f.parameters).length === 2\n ? signature\n : JSON.stringify(f.parameters);\n // A function is for the UI unless marked: the agent calls only what\n // the mark allows.\n const callers = functionCallers(f);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- **${name}**${who}${f.description ? `: ${f.description}` : \"\"}\\n args: ${args}`;\n })\n .join(\"\\n\");\n const surfaces = Object.entries(manifest.surfaces)\n .map(([id, s]) => {\n const state =\n s.status === \"deleted\"\n ? \", deleted: never use this id again\"\n : s.status === \"failed\"\n ? \", not created: send a corrected createSurface with this id\"\n : \"\";\n const lines = [`- \"${id}\" (target \"${s.target}\"${state})`];\n if (s.dataModel) {\n lines.push(` user values: ${shorten(JSON.stringify(s.dataModel))}`);\n }\n for (const rejection of s.rejected ?? []) {\n lines.push(` rejected: ${rejection}`);\n }\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n const hasSurfaceNotes = Object.values(manifest.surfaces).some(\n (s) => s.dataModel !== undefined || (s.rejected?.length ?? 0) > 0,\n );\n const surfaceNotes = hasSurfaceNotes\n ? \"User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\\n\"\n : \"\";\n\n // Rules for functions, events, and templates go only to runs whose manifest\n // has them, so the guide stays small.\n const {\n functions: hasFunctions,\n events,\n templates,\n checks,\n } = generativeUIGuideFeatures(manifest);\n // The agent calls functions only while that path is on.\n const agentCalls = hasFunctions && GENERATIVE_UI_AGENT_FUNCTION_CALLS;\n const operations = [\n '{\"version\":\"v1.0\",\"createSurface\":{\"surfaceId\":\"<new id>\",\"dataModel\":{...},\"components\":[{\"id\":\"root\",\"component\":\"<Name>\",\"children\":[\"<child id>\"]}]}}: the first operation of a new surface. \"dataModel\" and \"components\" are optional.',\n '{\"version\":\"v1.0\",\"updateComponents\":{\"surfaceId\":\"<id>\",\"components\":[<component>, ...]}}: add or replace components by id.',\n '{\"version\":\"v1.0\",\"updateDataModel\":{\"surfaceId\":\"<id>\",\"path\":\"/some/path\",\"value\":<json>}}: set the value at \"path\". Always give \"value\". \"value\":null deletes the key at \"path\".',\n '{\"version\":\"v1.0\",\"deleteSurface\":{\"surfaceId\":\"<id>\"}}: remove the surface.',\n ...(agentCalls\n ? [\n '{\"version\":\"v1.0\",\"callRendererFunction\":{\"functionCallId\":\"<unique id>\",\"callFunction\":{\"@call\":\"<function>\",\"args\":{...}}}}: run an app function now, with no click. It needs no surface.',\n ]\n : []),\n ];\n const eventRule = hasFunctions\n ? 'Event props take an action. {\"functionCall\":{\"@call\":\"<function>\",\"args\":{...}}} runs an app function in the browser immediately, and you are not told about it. {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\". Only call functions listed below.'\n : 'Event props take an action: {\"event\":{\"name\":\"<name>\",\"userMessage\":\"<text>\",\"context\":{...}}} sends the interaction back to you as a user message, with \"userMessage\" as its first line. \"userMessage\" is plain text: ${...} is not interpolated in it; put values in \"context\".';\n const rules = [\n 'Components are flat objects: {\"id\":\"...\",\"component\":\"<Name>\", ...props}. Every surface renders from the component with id \"root\". Reference children by id in slot props.',\n 'A component may take \"accessibility\":{\"label\":\"<1 to 3 words>\",\"description\":\"<what it does>\"} for screen readers: on the component it describes, when nothing visible names it. Not on every component, and \"live\":\"polite\" only on text that changes by itself.',\n 'Stream progressively: put the initial data in \"dataModel\" and the root in \"components\" of the createSurface operation, then send one updateComponents operation per child, so the UI appears while you are still writing. The root must already list the ids of its children in its slot props (for example \"children\":[\"card-1\",\"card-2\"]), even though the children come later. A component that no slot references is never shown.',\n \"Updating a component replaces all of its props, so resend every prop.\",\n 'Prop values are literals or data bindings {\"@path\":\"/data/path\"}. Never write {\"path\":\"/data/path\"} as a binding.',\n ...(events ? [eventRule] : []),\n \"To show a different view, create a new surface with a new surfaceId (for example, a checkout form after a cart summary). Update an existing surface only when the user asks to change that same view: then do not send createSurface, use its surfaceId, and pass its existing target. Never reuse an earlier chat surface for a different view, because that replaces the earlier UI and anything the user typed into it.\",\n \"Never use a surfaceId again, also after deleteSurface.\",\n 'A prop can also be a function value that updates with the data: {\"@call\":\"formatCurrency\",\"args\":{\"value\":{\"@path\":\"/total\"},\"currency\":\"EUR\"}}. Only call functions listed below. formatString interpolates ${/path} and ${fn(arg: value)} in its value.',\n '${...} is evaluated only in the value of formatString and in the item of series; in other strings it stays literal text. Inside formatString, ${...} does not support operators. For arithmetic use calc, with the values as named args: {\"@call\":\"calc\",\"args\":{\"expression\":\"seats * 29 * (annual ? 0.8 : 1)\",\"seats\":{\"@path\":\"/seats\"},\"annual\":{\"@path\":\"/annual\"}}}.',\n \"For a computed list (chart data, template items) use series. Its description under Functions gives the rules and an example.\",\n ...(checks\n ? [\n 'Validate an input with \"checks\": [{\"condition\":{\"@call\":\"email\",\"args\":{\"value\":{\"@path\":\"/form/email\"}}},\"message\":\"Enter a valid email\"}]. The check functions are required, regex, length, numeric and email. A failed check shows the message under the input and disables a Button that has the same checks.',\n ]\n : []),\n ...(templates\n ? [\n 'To repeat a component for each item of a list, give a multiple slot a template: \"children\":{\"componentId\":\"row\",\"path\":\"/items\"}. Inside the template, paths are relative to the item (\"name\", not \"/name\"). {\"@call\":\"@index\"} gives the position of the item, from 0; {\"@call\":\"@index\",\"args\":{\"offset\":1}} counts from 1.',\n ]\n : []),\n ...(agentCalls\n ? [\n \"Give every callRendererFunction a new functionCallId. Call only a function marked (UI or agent) or (agent only); a function with no mark is for the UI only. A function marked (agent only) is only for callRendererFunction: do not bind an event to it.\",\n 'The result of a callRendererFunction comes back to you in a new turn, as a developer message: {\"version\":\"v1.0\",\"rendererFunctionResponse\":{\"functionCallId\":\"<id>\",\"value\":...}}. If the call failed, it has \"error\" in place of \"value\". Do not wait for the result in this reply, and do not guess it.',\n ]\n : []),\n ];\n\n return [\n `## Generative UI\nCall \\`${GENERATIVE_UI_RENDER_TOOL}\\` to show UI. Arguments: \\`target\\` first, then \\`operations\\` (A2UI v1.0 operations, applied in order).\n\n${GENERATIVE_UI_WHEN_TO_SHOW}\n\nEvery operation has \"version\":\"v1.0\" and exactly one of:\n${operations.map((op) => `- ${op}`).join(\"\\n\")}\n\nRules:\n${rules.map((rule, index) => `${index + 1}. ${rule}`).join(\"\\n\")}`,\n `### Targets\\n${targets || \"- none\"}`,\n `### Components\\n${components || \"- none\"}`,\n `### Functions\\n${functions || \"- none\"}`,\n `### Existing surfaces\\n${surfaceNotes}${surfaces || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n"],"mappings":";;;;;AAWA,MAAa,oCACX;;AAGF,MAAM,yBAAyB;;AAG/B,SAAS,QAAQ,MAAc;AAC7B,QAAO,KAAK,SAAS,yBACjB,GAAG,KAAK,MAAM,GAAG,uBAAuB,CAAC,OACzC;;;;;;;AAQN,SAAgB,wBAAwB,UAAg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A;EACR,MAAM,QAAQ,CAAC,MAAM,GAAG,aAAa,EAAE,OAAO,GAAG,MAAM,GAAG;AAC1D,MAAI,EAAE,UACJ,OAAM,KAAK,kBAAkB,QAAQ,KAAK,UAAU,EAAE,UAAU,CAAC,GAAG;AAEtE,OAAK,MAAM,aAAa,EAAE,YAAY,EAAE,CACtC,OAAM,KAAK,eAAe,YAAY;AAExC,SAAO,MAAM,KAAK,KAAK;GACvB,CACD,KAAK,KAAK;CAIb,MAAM,eAHkB,OAAO,OAAO,SAAS,SAAS,CAAC,MACtD,MAAM,EAAE,cAAc,WAAc,EAAE,UAAU,UAAU,KAAK,EACjE,GAEG,wKACA;CAIJ,MAAM,EACJ,WAAW,cACX,QACA,WACA,WACE,0BAA0B,SAAS;CAEvC,MAAM,aAAa,gBAAgB;CACnC,MAAM,aAAa;EACjB;EACA;EACA;EACA;EACA,GAAI,aACA,CACE,gNACD,GACD,EAAE;EACP;CAID,MAAM,QAAQ;EACZ;EACA;EACA;EACA;EACA;EACA,GAAI,SAAS,CATG,eACd,udACA,sSAOsB,GAAG,EAAE;EAC7B;EACA;EACA;EACA;EACA;EACA,GAAI,SACA,CACE,wUACD,GACD,EAAE;EACN,GAAI,YACA,CACE,0VACD,GACD,EAAE;EACN,GAAI,aACA,CACE,6PACA,4TACD,GACD,EAAE;EACP;AAED,QAAO;EACL;SACK,0BAA0B;;EAEjC,2BAA2B;;;EAG3B,WAAW,KAAK,OAAO,KAAK,KAAK,CAAC,KAAK,KAAK,CAAC;;;EAG7C,MAAM,KAAK,MAAM,UAAU,GAAG,QAAQ,EAAE,IAAI,OAAO,CAAC,KAAK,KAAK;EAC5D,gBAAgB,WAAW;EAC3B,mBAAmB,cAAc;EACjC,kBAAkB,aAAa;EAC/B,0BAA0B,eAAe,YAAY;EACtD,CAAC,KAAK,OAAO"}
1
+ {"version":3,"file":"prompt.mjs","names":[],"sources":["../../src/generative-ui/prompt.ts"],"sourcesContent":["import { generativeUIGuideFeatures } from \"../a2ui-prompts\";\nimport { functionCallers } from \"./basic-functions\";\nimport {\n defaultGenerativeUIPromptSpec,\n generativeUIPromptFeatures,\n selectPromptItems,\n} from \"./prompt-spec\";\nimport type { GenerativeUIPromptSpec } from \"./prompt-spec\";\nimport { renderGenerativeUIComponentList } from \"./schema-render\";\nimport { GENERATIVE_UI_AGENT_FUNCTION_CALLS } from \"./types\";\nimport type { GenerativeUIManifest } from \"./types\";\n\nexport const GENERATIVE_UI_CONTEXT_DESCRIPTION =\n \"Generative UI guide: available components, functions, targets, and how to call render_ui.\";\n\n/** Most characters of the user values of one surface in the guide. */\nconst MAX_USER_VALUES_LENGTH = 500;\n\n/** Cuts long text and marks the cut with \"...\". */\nfunction shorten(text: string) {\n return text.length > MAX_USER_VALUES_LENGTH\n ? `${text.slice(0, MAX_USER_VALUES_LENGTH)}...`\n : text;\n}\n\n/**\n * The guide that the runtime adds as a context entry to a tool-transport run:\n * the `render_ui` rules, the targets, components, functions, and surfaces of\n * the manifest. It is in shared so that the inspector shows the same text.\n */\nexport function buildGenerativeUIPrompt(\n manifest: GenerativeUIManifest,\n spec: GenerativeUIPromptSpec = defaultGenerativeUIPromptSpec(),\n) {\n const targets = manifest.targets\n .map((t) => {\n const place =\n t.kind === \"chat\"\n ? \"inside the chat transcript\"\n : \"a named area of the app\";\n const limit = t.components\n ? `; only ${t.components.join(\", \") || \"no components\"}`\n : \"\";\n const description = t.description ? `: ${t.description}` : \"\";\n return `- \"${t.id}\" (${place}${limit})${description}`;\n })\n .join(\"\\n\");\n const components = renderGenerativeUIComponentList(\n manifest.components,\n spec.schema.tool,\n );\n const functions = Object.entries(manifest.functions)\n .map(([name, f]) => {\n // A built-in function carries its short signature in the description\n // of its parameters; an app function has a JSON Schema.\n const signature = f.parameters.description;\n const args =\n typeof signature === \"string\" &&\n signature.startsWith(\"{\") &&\n Object.keys(f.parameters).length === 2\n ? signature\n : JSON.stringify(f.parameters);\n // A function is for the UI unless marked: the agent calls only what\n // the mark allows.\n const callers = functionCallers(f);\n const who =\n callers.agent && GENERATIVE_UI_AGENT_FUNCTION_CALLS\n ? callers.renderer\n ? \" (UI or agent)\"\n : \" (agent only)\"\n : \"\";\n return `- **${name}**${who}${f.description ? `: ${f.description}` : \"\"}\\n args: ${args}`;\n })\n .join(\"\\n\");\n const surfaces = Object.entries(manifest.surfaces)\n .map(([id, s]) => {\n const state =\n s.status === \"deleted\"\n ? \", deleted: never use this id again\"\n : s.status === \"failed\"\n ? \", not created: send a corrected createSurface with this id\"\n : \"\";\n const lines = [`- \"${id}\" (target \"${s.target}\"${state})`];\n if (s.dataModel) {\n lines.push(` user values: ${shorten(JSON.stringify(s.dataModel))}`);\n }\n for (const rejection of s.rejected ?? []) {\n lines.push(` rejected: ${rejection}`);\n }\n return lines.join(\"\\n\");\n })\n .join(\"\\n\");\n const hasSurfaceNotes = Object.values(manifest.surfaces).some(\n (s) => s.dataModel !== undefined || (s.rejected?.length ?? 0) > 0,\n );\n const surfaceNotes = hasSurfaceNotes\n ? \"User values are what the user entered, by path. Your writes to those paths are ignored. Rejected operations were dropped: send them again with the problem fixed.\\n\"\n : \"\";\n\n // Rules for functions, events, and templates go only to runs whose manifest\n // has them, so the guide stays small.\n const features = generativeUIPromptFeatures(\n generativeUIGuideFeatures(manifest),\n );\n const { intro, whenToShow } = spec.tool;\n const operations = selectPromptItems(spec.tool.operations ?? [], features);\n const rules = selectPromptItems(spec.tool.rules, features);\n const when = whenToShow ? `${whenToShow}\\n\\n` : \"\";\n\n return [\n `## Generative UI\n${intro}\n\n${when}Every operation has \"version\":\"1.0\" and exactly one of:\n${operations.map((op) => `- ${op}`).join(\"\\n\")}\n\nRules:\n${rules.map((rule, index) => `${index + 1}. ${rule}`).join(\"\\n\")}`,\n `### Targets\\n${targets || \"- none\"}`,\n `### Components\\n${components || \"- none\"}`,\n `### Functions\\n${functions || \"- none\"}`,\n `### Existing surfaces\\n${surfaceNotes}${surfaces || \"- none\"}`,\n ].join(\"\\n\\n\");\n}\n"],"mappings":";;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EAAE,UAAU,CAAC,GAAG;AAEtE,OAAK,MAAM,aAAa,EAAE,YAAY,EAAE,CACtC,OAAM,KAAK,eAAe,YAAY;AAExC,SAAO,MAAM,KAAK,KAAK;GACvB,CACD,KAAK,KAAK;CAIb,MAAM,eAHkB,OAAO,OAAO,SAAS,SAAS,CAAC,MACtD,MAAM,EAAE,cAAc,WAAc,EAAE,UAAU,UAAU,KAAK,EACjE,GAEG,wKACA;CAIJ,MAAM,WAAW,2BACf,0BAA0B,SAAS,CACpC;CACD,MAAM,EAAE,OAAO,eAAe,KAAK;CACnC,MAAM,aAAa,kBAAkB,KAAK,KAAK,cAAc,EAAE,EAAE,SAAS;CAC1E,MAAM,QAAQ,kBAAkB,KAAK,KAAK,OAAO,SAAS;AAG1D,QAAO;EACL;EACF,MAAM;;EAJO,aAAa,GAAG,WAAW,QAAQ,GAM3C;EACL,WAAW,KAAK,OAAO,KAAK,KAAK,CAAC,KAAK,KAAK,CAAC;;;EAG7C,MAAM,KAAK,MAAM,UAAU,GAAG,QAAQ,EAAE,IAAI,OAAO,CAAC,KAAK,KAAK;EAC5D,gBAAgB,WAAW;EAC3B,mBAAmB,cAAc;EACjC,kBAAkB,aAAa;EAC/B,0BAA0B,eAAe,YAAY;EACtD,CAAC,KAAK,OAAO"}
@@ -98,6 +98,7 @@ var RenderUIArgsScanner = class {
98
98
  expectingValue = false;
99
99
  }
100
100
  break;
101
+ case void 0: break;
101
102
  }
102
103
  }
103
104
  this.inString = inString;
@@ -1 +1 @@
1
- {"version":3,"file":"render-ui-args.cjs","names":["isRecord"],"sources":["../../src/generative-ui/render-ui-args.ts"],"sourcesContent":["import { isRecord } from \"./is-record\";\nexport interface ExtractedRenderUIArgs {\n target?: string;\n /**\n * Complete elements of the `operations` array, in order. A balanced element\n * that is not a valid JSON object is returned as `null`.\n */\n operations: Array<Record<string, unknown> | null>;\n /**\n * Set when an `operations[]` element was opened but its closing brace never\n * arrived: the text ends mid-operation (still streaming, or truncated).\n */\n incompleteOperation?: boolean;\n}\n\n/**\n * Reads `target` and every complete `operations[]` element from a possibly\n * truncated `render_ui` argument string.\n */\nexport function extractRenderUIArgs(text: string) {\n return new RenderUIArgsScanner().scan(text);\n}\n\n/**\n * The parser of {@link extractRenderUIArgs}, with its state kept between\n * calls. Each call scans only the text after the text it scanned before, so\n * a streamed argument string is scanned once in total.\n */\nclass RenderUIArgsScanner {\n private readonly result: ExtractedRenderUIArgs = { operations: [] };\n private readonly stack: Array<\"{\" | \"[\"> = [];\n private inString = false;\n private escaped = false;\n private stringStart = -1;\n private pendingKey: string | null = null;\n private currentKey: string | null = null;\n private expectingValue = false;\n private inOperations = false;\n private elementStart = -1;\n private scanned = 0;\n\n /**\n * Scans `text` from where the last call stopped.\n *\n * @param text - The whole text so far. It starts with the text of the\n * last call.\n * @returns The result so far. It is the same object on each call.\n */\n scan(text: string) {\n const { result, stack } = this;\n let {\n inString,\n escaped,\n stringStart,\n pendingKey,\n currentKey,\n expectingValue,\n inOperations,\n elementStart,\n } = this;\n for (let i = this.scanned; i < text.length; i++) {\n const ch = text[i];\n if (inString) {\n if (escaped) {\n escaped = false;\n } else if (ch === \"\\\\\") {\n escaped = true;\n } else if (ch === '\"') {\n inString = false;\n if (stack.length === 1) {\n const literal = text.slice(stringStart, i + 1);\n if (expectingValue) {\n if (currentKey === \"target\") {\n try {\n result.target = JSON.parse(literal);\n } catch {\n // Unreachable for a closed literal; keep scanning.\n }\n }\n expectingValue = false;\n } else {\n pendingKey = literal;\n }\n }\n }\n continue;\n }\n switch (ch) {\n case '\"':\n inString = true;\n stringStart = i;\n break;\n case \":\":\n if (stack.length === 1 && pendingKey !== null) {\n try {\n currentKey = JSON.parse(pendingKey);\n } catch {\n currentKey = null;\n }\n pendingKey = null;\n expectingValue = true;\n }\n break;\n case \",\":\n if (stack.length === 1) {\n expectingValue = false;\n currentKey = null;\n }\n break;\n case \"{\":\n if (inOperations && stack.length === 2) elementStart = i;\n stack.push(\"{\");\n break;\n case \"[\":\n if (\n stack.length === 1 &&\n expectingValue &&\n currentKey === \"operations\"\n ) {\n inOperations = true;\n }\n stack.push(\"[\");\n break;\n case \"}\":\n case \"]\":\n stack.pop();\n if (\n ch === \"}\" &&\n inOperations &&\n stack.length === 2 &&\n elementStart >= 0\n ) {\n result.operations.push(\n parseObject(text.slice(elementStart, i + 1)),\n );\n elementStart = -1;\n }\n if (ch === \"]\" && inOperations && stack.length === 1) {\n inOperations = false;\n expectingValue = false;\n }\n break;\n }\n }\n this.inString = inString;\n this.escaped = escaped;\n this.stringStart = stringStart;\n this.pendingKey = pendingKey;\n this.currentKey = currentKey;\n this.expectingValue = expectingValue;\n this.inOperations = inOperations;\n this.elementStart = elementStart;\n this.scanned = text.length;\n if (elementStart >= 0) result.incompleteOperation = true;\n else delete result.incompleteOperation;\n return result;\n }\n}\n\nfunction parseObject(raw: string) {\n try {\n const value: unknown = JSON.parse(raw);\n return isRecord(value) ? value : null;\n } catch {\n return null;\n }\n}\n\n/** Feeds streamed argument deltas and reports operations not yet seen. */\nexport class RenderUIArgsStream {\n private buffer = \"\";\n private emitted = 0;\n private incomplete = false;\n private readonly scanner = new RenderUIArgsScanner();\n\n push(delta: string) {\n this.buffer += delta;\n const { target, operations, incompleteOperation } = this.scanner.scan(\n this.buffer,\n );\n const newOperations = operations.slice(this.emitted);\n this.emitted = operations.length;\n this.incomplete = incompleteOperation === true;\n return { target, newOperations };\n }\n\n /** Every argument delta received so far, concatenated. */\n get text() {\n return this.buffer;\n }\n\n /**\n * True when the text received so far ends inside an `operations[]` element.\n * Once the tool call has ended, that element was truncated.\n */\n get hasIncompleteOperation() {\n return this.incomplete;\n }\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,oBAAoB,MAAc;AAChD,QAAO,IAAI,qBAAqB,CAAC,KAAK,KAAK;;;;;;;AAQ7C,IAAM,sBAAN,MAA0B;;gBACyB,EAAE,YAAY,EAAE,EAAE;eACxB,EAAE;kBAC1B;iBACD;qBACI;oBACc;oBACA;wBACX;sBAC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AACf,uBAAiB;;AAEnB;;;AAGN,OAAK,WAAW;AAChB,OAAK,UAAU;AACf,OAAK,cAAc;AACnB,OAAK,aAAa;AAClB,OAAK,aAAa;AAClB,OAAK,iBAAiB;AACtB,OAAK,eAAe;AACpB,OAAK,eAAe;AACpB,OAAK,UAAU,KAAK;AACpB,MAAI,gBAAgB,EAAG,QAAO,sBAAsB;MAC/C,QAAO,OAAO;AACnB,SAAO;;;AAIX,SAAS,YAAY,KAAa;AAChC,KAAI;EACF,MAAM,QAAiB,KAAK,MAAM,IAAI;AACtC,SAAOA,2BAAS,MAAM,GAAG,QAAQ;SAC3B;AACN,SAAO;;;;AAKX,IAAa,qBAAb,MAAgC;;gBACb;iBACC;oBACG;iBACM,IAAI,qBAAqB;;CAEpD,KAAK,OAAe;AAClB,OAAK,UAAU;EACf,MAAM,EAAE,QAAQ,YAAY,wBAAwB,KAAK,QAAQ,KAC/D,KAAK,OACN;EACD,MAAM,gBAAgB,WAAW,MAAM,KAAK,QAAQ;AACpD,OAAK,UAAU,WAAW;AAC1B,OAAK,aAAa,wBAAwB;AAC1C,SAAO;GAAE;GAAQ;GAAe;;;CAIlC,IAAI,OAAO;AACT,SAAO,KAAK;;;;;;CAOd,IAAI,yBAAyB;AAC3B,SAAO,KAAK"}
1
+ {"version":3,"file":"render-ui-args.cjs","names":["isRecord"],"sources":["../../src/generative-ui/render-ui-args.ts"],"sourcesContent":["import { isRecord } from \"./is-record\";\nexport interface ExtractedRenderUIArgs {\n target?: string;\n /**\n * Complete elements of the `operations` array, in order. A balanced element\n * that is not a valid JSON object is returned as `null`.\n */\n operations: Array<Record<string, unknown> | null>;\n /**\n * Set when an `operations[]` element was opened but its closing brace never\n * arrived: the text ends mid-operation (still streaming, or truncated).\n */\n incompleteOperation?: boolean;\n}\n\n/**\n * Reads `target` and every complete `operations[]` element from a possibly\n * truncated `render_ui` argument string.\n */\nexport function extractRenderUIArgs(text: string) {\n return new RenderUIArgsScanner().scan(text);\n}\n\n/**\n * The parser of {@link extractRenderUIArgs}, with its state kept between\n * calls. Each call scans only the text after the text it scanned before, so\n * a streamed argument string is scanned once in total.\n */\nclass RenderUIArgsScanner {\n private readonly result: ExtractedRenderUIArgs = { operations: [] };\n private readonly stack: Array<\"{\" | \"[\"> = [];\n private inString = false;\n private escaped = false;\n private stringStart = -1;\n private pendingKey: string | null = null;\n private currentKey: string | null = null;\n private expectingValue = false;\n private inOperations = false;\n private elementStart = -1;\n private scanned = 0;\n\n /**\n * Scans `text` from where the last call stopped.\n *\n * @param text - The whole text so far. It starts with the text of the\n * last call.\n * @returns The result so far. It is the same object on each call.\n */\n scan(text: string) {\n const { result, stack } = this;\n let {\n inString,\n escaped,\n stringStart,\n pendingKey,\n currentKey,\n expectingValue,\n inOperations,\n elementStart,\n } = this;\n for (let i = this.scanned; i < text.length; i++) {\n const ch = text[i];\n if (inString) {\n if (escaped) {\n escaped = false;\n } else if (ch === \"\\\\\") {\n escaped = true;\n } else if (ch === '\"') {\n inString = false;\n if (stack.length === 1) {\n const literal = text.slice(stringStart, i + 1);\n if (expectingValue) {\n if (currentKey === \"target\") {\n try {\n result.target = JSON.parse(literal);\n } catch {\n // Unreachable for a closed literal; keep scanning.\n }\n }\n expectingValue = false;\n } else {\n pendingKey = literal;\n }\n }\n }\n continue;\n }\n switch (ch) {\n case '\"':\n inString = true;\n stringStart = i;\n break;\n case \":\":\n if (stack.length === 1 && pendingKey !== null) {\n try {\n currentKey = JSON.parse(pendingKey);\n } catch {\n currentKey = null;\n }\n pendingKey = null;\n expectingValue = true;\n }\n break;\n case \",\":\n if (stack.length === 1) {\n expectingValue = false;\n currentKey = null;\n }\n break;\n case \"{\":\n if (inOperations && stack.length === 2) elementStart = i;\n stack.push(\"{\");\n break;\n case \"[\":\n if (\n stack.length === 1 &&\n expectingValue &&\n currentKey === \"operations\"\n ) {\n inOperations = true;\n }\n stack.push(\"[\");\n break;\n case \"}\":\n case \"]\":\n stack.pop();\n if (\n ch === \"}\" &&\n inOperations &&\n stack.length === 2 &&\n elementStart >= 0\n ) {\n result.operations.push(\n parseObject(text.slice(elementStart, i + 1)),\n );\n elementStart = -1;\n }\n if (ch === \"]\" && inOperations && stack.length === 1) {\n inOperations = false;\n expectingValue = false;\n }\n break;\n case undefined:\n // Unreachable: `i < text.length`, so `text[i]` is always a char.\n break;\n }\n }\n this.inString = inString;\n this.escaped = escaped;\n this.stringStart = stringStart;\n this.pendingKey = pendingKey;\n this.currentKey = currentKey;\n this.expectingValue = expectingValue;\n this.inOperations = inOperations;\n this.elementStart = elementStart;\n this.scanned = text.length;\n if (elementStart >= 0) result.incompleteOperation = true;\n else delete result.incompleteOperation;\n return result;\n }\n}\n\nfunction parseObject(raw: string) {\n try {\n const value: unknown = JSON.parse(raw);\n return isRecord(value) ? value : null;\n } catch {\n return null;\n }\n}\n\n/** Feeds streamed argument deltas and reports operations not yet seen. */\nexport class RenderUIArgsStream {\n private buffer = \"\";\n private emitted = 0;\n private incomplete = false;\n private readonly scanner = new RenderUIArgsScanner();\n\n push(delta: string) {\n this.buffer += delta;\n const { target, operations, incompleteOperation } = this.scanner.scan(\n this.buffer,\n );\n const newOperations = operations.slice(this.emitted);\n this.emitted = operations.length;\n this.incomplete = incompleteOperation === true;\n return { target, newOperations };\n }\n\n /** Every argument delta received so far, concatenated. */\n get text() {\n return this.buffer;\n }\n\n /**\n * True when the text received so far ends inside an `operations[]` element.\n * Once the tool call has ended, that element was truncated.\n */\n get hasIncompleteOperation() {\n return this.incomplete;\n }\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,oBAAoB,MAAc;AAChD,QAAO,IAAI,qBAAqB,CAAC,KAAK,KAAK;;;;;;;AAQ7C,IAAM,sBAAN,MAA0B;;gBACyB,EAAE,YAAY,EAAE,EAAE;eACxB,EAAE;kBAC1B;iBACD;qBACI;oBACc;oBACA;wBACX;sBACF;sBACA;iBACL;;;;;;;;;CASlB,KAAK,MAAc;EACjB,MAAM,EAAE,QAAQ,UAAU;EAC1B,IAAI,EACF,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c;AACnB,OAAK,aAAa;AAClB,OAAK,aAAa;AAClB,OAAK,iBAAiB;AACtB,OAAK,eAAe;AACpB,OAAK,eAAe;AACpB,OAAK,UAAU,KAAK;AACpB,MAAI,gBAAgB,EAAG,QAAO,sBAAsB;MAC/C,QAAO,OAAO;AACnB,SAAO;;;AAIX,SAAS,YAAY,KAAa;AAChC,KAAI;EACF,MAAM,QAAiB,KAAK,MAAM,IAAI;AACtC,SAAOA,2BAAS,MAAM,GAAG,QAAQ;SAC3B;AACN,SAAO;;;;AAKX,IAAa,qBAAb,MAAgC;;gBACb;iBACC;oBACG;iBACM,IAAI,qBAAqB;;CAEpD,KAAK,OAAe;AAClB,OAAK,UAAU;EACf,MAAM,EAAE,QAAQ,YAAY,wBAAwB,KAAK,QAAQ,KAC/D,KAAK,OACN;EACD,MAAM,gBAAgB,WAAW,MAAM,KAAK,QAAQ;AACpD,OAAK,UAAU,WAAW;AAC1B,OAAK,aAAa,wBAAwB;AAC1C,SAAO;GAAE;GAAQ;GAAe;;;CAIlC,IAAI,OAAO;AACT,SAAO,KAAK;;;;;;CAOd,IAAI,yBAAyB;AAC3B,SAAO,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"render-ui-args.d.cts","names":[],"sources":["../../src/generative-ui/render-ui-args.ts"],"mappings":";UACiB,qBAAA;EACf,MAAA;EADoC;;;;EAMpC,UAAA,EAAY,KAAA,CAAM,MAAA;EAAN;;;;EAKZ,mBAAA;AAAA;;;;;iBAOc,mBAAA,CAAoB,IAAA,WAAY,qBAAA;;cAsJnC,kBAAA;EAAA,QACH,MAAA;EAAA,QACA,OAAA;EAAA,QACA,UAAA;EAAA,iBACS,OAAA;EAEjB,IAAA,CAAK,KAAA;;oBANwB,MAAA;EAAA;;MAkBzB,IAAA,CAAA;EAAA;;;;EAAA,IAQA,sBAAA,CAAA;AAAA"}
1
+ {"version":3,"file":"render-ui-args.d.cts","names":[],"sources":["../../src/generative-ui/render-ui-args.ts"],"mappings":";UACiB,qBAAA;EACf,MAAA;EADoC;;;;EAMpC,UAAA,EAAY,KAAA,CAAM,MAAA;EAAN;;;;EAKZ,mBAAA;AAAA;;;;;iBAOc,mBAAA,CAAoB,IAAA,WAAY,qBAAA;;cAyJnC,kBAAA;EAAA,QACH,MAAA;EAAA,QACA,OAAA;EAAA,QACA,UAAA;EAAA,iBACS,OAAA;EAEjB,IAAA,CAAK,KAAA;;oBANwB,MAAA;EAAA;;MAkBzB,IAAA,CAAA;EAAA;;;;EAAA,IAQA,sBAAA,CAAA;AAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"render-ui-args.d.mts","names":[],"sources":["../../src/generative-ui/render-ui-args.ts"],"mappings":";UACiB,qBAAA;EACf,MAAA;EADoC;;;;EAMpC,UAAA,EAAY,KAAA,CAAM,MAAA;EAAN;;;;EAKZ,mBAAA;AAAA;;;;;iBAOc,mBAAA,CAAoB,IAAA,WAAY,qBAAA;;cAsJnC,kBAAA;EAAA,QACH,MAAA;EAAA,QACA,OAAA;EAAA,QACA,UAAA;EAAA,iBACS,OAAA;EAEjB,IAAA,CAAK,KAAA;;oBANwB,MAAA;EAAA;;MAkBzB,IAAA,CAAA;EAAA;;;;EAAA,IAQA,sBAAA,CAAA;AAAA"}
1
+ {"version":3,"file":"render-ui-args.d.mts","names":[],"sources":["../../src/generative-ui/render-ui-args.ts"],"mappings":";UACiB,qBAAA;EACf,MAAA;EADoC;;;;EAMpC,UAAA,EAAY,KAAA,CAAM,MAAA;EAAN;;;;EAKZ,mBAAA;AAAA;;;;;iBAOc,mBAAA,CAAoB,IAAA,WAAY,qBAAA;;cAyJnC,kBAAA;EAAA,QACH,MAAA;EAAA,QACA,OAAA;EAAA,QACA,UAAA;EAAA,iBACS,OAAA;EAEjB,IAAA,CAAK,KAAA;;oBANwB,MAAA;EAAA;;MAkBzB,IAAA,CAAA;EAAA;;;;EAAA,IAQA,sBAAA,CAAA;AAAA"}
@@ -98,6 +98,7 @@ var RenderUIArgsScanner = class {
98
98
  expectingValue = false;
99
99
  }
100
100
  break;
101
+ case void 0: break;
101
102
  }
102
103
  }
103
104
  this.inString = inString;
@@ -1 +1 @@
1
- {"version":3,"file":"render-ui-args.mjs","names":[],"sources":["../../src/generative-ui/render-ui-args.ts"],"sourcesContent":["import { isRecord } from \"./is-record\";\nexport interface ExtractedRenderUIArgs {\n target?: string;\n /**\n * Complete elements of the `operations` array, in order. A balanced element\n * that is not a valid JSON object is returned as `null`.\n */\n operations: Array<Record<string, unknown> | null>;\n /**\n * Set when an `operations[]` element was opened but its closing brace never\n * arrived: the text ends mid-operation (still streaming, or truncated).\n */\n incompleteOperation?: boolean;\n}\n\n/**\n * Reads `target` and every complete `operations[]` element from a possibly\n * truncated `render_ui` argument string.\n */\nexport function extractRenderUIArgs(text: string) {\n return new RenderUIArgsScanner().scan(text);\n}\n\n/**\n * The parser of {@link extractRenderUIArgs}, with its state kept between\n * calls. Each call scans only the text after the text it scanned before, so\n * a streamed argument string is scanned once in total.\n */\nclass RenderUIArgsScanner {\n private readonly result: ExtractedRenderUIArgs = { operations: [] };\n private readonly stack: Array<\"{\" | \"[\"> = [];\n private inString = false;\n private escaped = false;\n private stringStart = -1;\n private pendingKey: string | null = null;\n private currentKey: string | null = null;\n private expectingValue = false;\n private inOperations = false;\n private elementStart = -1;\n private scanned = 0;\n\n /**\n * Scans `text` from where the last call stopped.\n *\n * @param text - The whole text so far. It starts with the text of the\n * last call.\n * @returns The result so far. It is the same object on each call.\n */\n scan(text: string) {\n const { result, stack } = this;\n let {\n inString,\n escaped,\n stringStart,\n pendingKey,\n currentKey,\n expectingValue,\n inOperations,\n elementStart,\n } = this;\n for (let i = this.scanned; i < text.length; i++) {\n const ch = text[i];\n if (inString) {\n if (escaped) {\n escaped = false;\n } else if (ch === \"\\\\\") {\n escaped = true;\n } else if (ch === '\"') {\n inString = false;\n if (stack.length === 1) {\n const literal = text.slice(stringStart, i + 1);\n if (expectingValue) {\n if (currentKey === \"target\") {\n try {\n result.target = JSON.parse(literal);\n } catch {\n // Unreachable for a closed literal; keep scanning.\n }\n }\n expectingValue = false;\n } else {\n pendingKey = literal;\n }\n }\n }\n continue;\n }\n switch (ch) {\n case '\"':\n inString = true;\n stringStart = i;\n break;\n case \":\":\n if (stack.length === 1 && pendingKey !== null) {\n try {\n currentKey = JSON.parse(pendingKey);\n } catch {\n currentKey = null;\n }\n pendingKey = null;\n expectingValue = true;\n }\n break;\n case \",\":\n if (stack.length === 1) {\n expectingValue = false;\n currentKey = null;\n }\n break;\n case \"{\":\n if (inOperations && stack.length === 2) elementStart = i;\n stack.push(\"{\");\n break;\n case \"[\":\n if (\n stack.length === 1 &&\n expectingValue &&\n currentKey === \"operations\"\n ) {\n inOperations = true;\n }\n stack.push(\"[\");\n break;\n case \"}\":\n case \"]\":\n stack.pop();\n if (\n ch === \"}\" &&\n inOperations &&\n stack.length === 2 &&\n elementStart >= 0\n ) {\n result.operations.push(\n parseObject(text.slice(elementStart, i + 1)),\n );\n elementStart = -1;\n }\n if (ch === \"]\" && inOperations && stack.length === 1) {\n inOperations = false;\n expectingValue = false;\n }\n break;\n }\n }\n this.inString = inString;\n this.escaped = escaped;\n this.stringStart = stringStart;\n this.pendingKey = pendingKey;\n this.currentKey = currentKey;\n this.expectingValue = expectingValue;\n this.inOperations = inOperations;\n this.elementStart = elementStart;\n this.scanned = text.length;\n if (elementStart >= 0) result.incompleteOperation = true;\n else delete result.incompleteOperation;\n return result;\n }\n}\n\nfunction parseObject(raw: string) {\n try {\n const value: unknown = JSON.parse(raw);\n return isRecord(value) ? value : null;\n } catch {\n return null;\n }\n}\n\n/** Feeds streamed argument deltas and reports operations not yet seen. */\nexport class RenderUIArgsStream {\n private buffer = \"\";\n private emitted = 0;\n private incomplete = false;\n private readonly scanner = new RenderUIArgsScanner();\n\n push(delta: string) {\n this.buffer += delta;\n const { target, operations, incompleteOperation } = this.scanner.scan(\n this.buffer,\n );\n const newOperations = operations.slice(this.emitted);\n this.emitted = operations.length;\n this.incomplete = incompleteOperation === true;\n return { target, newOperations };\n }\n\n /** Every argument delta received so far, concatenated. */\n get text() {\n return this.buffer;\n }\n\n /**\n * True when the text received so far ends inside an `operations[]` element.\n * Once the tool call has ended, that element was truncated.\n */\n get hasIncompleteOperation() {\n return this.incomplete;\n }\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,oBAAoB,MAAc;AAChD,QAAO,IAAI,qBAAqB,CAAC,KAAK,KAAK;;;;;;;AAQ7C,IAAM,sBAAN,MAA0B;;gBACyB,EAAE,YAAY,EAAE,EAAE;eACxB,EAAE;kBAC1B;iBACD;qBACI;oBACc;oBACA;wBACX;sBACF;sBACA;iBACL;;;;;;;;;CASlB,KAAK,MAAc;EACjB,MAAM,EAAE,QAAQ,UAAU;EAC1B,IAAI,EACF,UACA,SACA,aACA,YACA,YACA,gBACA,cACA,iBACE;AACJ,OAAK,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,QAAQ,KAAK;GAC/C,MAAM,KAAK,KAAK;AAChB,OAAI,UAAU;AACZ,QAAI,QACF,WAAU;aACD,OAAO,KAChB,WAAU;aACD,OAAO,MAAK;AACrB,gBAAW;AACX,SAAI,MAAM,WAAW,GAAG;MACtB,MAAM,UAAU,KAAK,MAAM,aAAa,IAAI,EAAE;AAC9C,UAAI,gBAAgB;AAClB,WAAI,eAAe,SACjB,KAAI;AACF,eAAO,SAAS,KAAK,MAAM,QAAQ;eAC7B;AAIV,wBAAiB;YAEjB,cAAa;;;AAInB;;AAEF,WAAQ,IAAR;IACE,KAAK;AACH,gBAAW;AACX,mBAAc;AACd;IACF,KAAK;AACH,SAAI,MAAM,WAAW,KAAK,eAAe,MAAM;AAC7C,UAAI;AACF,oBAAa,KAAK,MAAM,WAAW;cAC7B;AACN,oBAAa;;AAEf,mBAAa;AACb,uBAAiB;;AAEnB;IACF,KAAK;AACH,SAAI,MAAM,WAAW,GAAG;AACtB,uBAAiB;AACjB,mBAAa;;AAEf;IACF,KAAK;AACH,SAAI,gBAAgB,MAAM,WAAW,EAAG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"],"sourcesContent":["import { isRecord } from \"./is-record\";\nexport interface ExtractedRenderUIArgs {\n target?: string;\n /**\n * Complete elements of the `operations` array, in order. A balanced element\n * that is not a valid JSON object is returned as `null`.\n */\n operations: Array<Record<string, unknown> | null>;\n /**\n * Set when an `operations[]` element was opened but its closing brace never\n * arrived: the text ends mid-operation (still streaming, or truncated).\n */\n incompleteOperation?: boolean;\n}\n\n/**\n * Reads `target` and every complete `operations[]` element from a possibly\n * truncated `render_ui` argument string.\n */\nexport function extractRenderUIArgs(text: string) {\n return new RenderUIArgsScanner().scan(text);\n}\n\n/**\n * The parser of {@link extractRenderUIArgs}, with its state kept between\n * calls. Each call scans only the text after the text it scanned before, so\n * a streamed argument string is scanned once in total.\n */\nclass RenderUIArgsScanner {\n private readonly result: ExtractedRenderUIArgs = { operations: [] };\n private readonly stack: Array<\"{\" | \"[\"> = [];\n private inString = false;\n private escaped = false;\n private stringStart = -1;\n private pendingKey: string | null = null;\n private currentKey: string | null = null;\n private expectingValue = false;\n private inOperations = false;\n private elementStart = -1;\n private scanned = 0;\n\n /**\n * Scans `text` from where the last call stopped.\n *\n * @param text - The whole text so far. It starts with the text of the\n * last call.\n * @returns The result so far. It is the same object on each call.\n */\n scan(text: string) {\n const { result, stack } = this;\n let {\n inString,\n escaped,\n stringStart,\n pendingKey,\n currentKey,\n expectingValue,\n inOperations,\n elementStart,\n } = this;\n for (let i = this.scanned; i < text.length; i++) {\n const ch = text[i];\n if (inString) {\n if (escaped) {\n escaped = false;\n } else if (ch === \"\\\\\") {\n escaped = true;\n } else if (ch === '\"') {\n inString = false;\n if (stack.length === 1) {\n const literal = text.slice(stringStart, i + 1);\n if (expectingValue) {\n if (currentKey === \"target\") {\n try {\n result.target = JSON.parse(literal);\n } catch {\n // Unreachable for a closed literal; keep scanning.\n }\n }\n expectingValue = false;\n } else {\n pendingKey = literal;\n }\n }\n }\n continue;\n }\n switch (ch) {\n case '\"':\n inString = true;\n stringStart = i;\n break;\n case \":\":\n if (stack.length === 1 && pendingKey !== null) {\n try {\n currentKey = JSON.parse(pendingKey);\n } catch {\n currentKey = null;\n }\n pendingKey = null;\n expectingValue = true;\n }\n break;\n case \",\":\n if (stack.length === 1) {\n expectingValue = false;\n currentKey = null;\n }\n break;\n case \"{\":\n if (inOperations && stack.length === 2) elementStart = i;\n stack.push(\"{\");\n break;\n case \"[\":\n if (\n stack.length === 1 &&\n expectingValue &&\n currentKey === \"operations\"\n ) {\n inOperations = true;\n }\n stack.push(\"[\");\n break;\n case \"}\":\n case \"]\":\n stack.pop();\n if (\n ch === \"}\" &&\n inOperations &&\n stack.length === 2 &&\n elementStart >= 0\n ) {\n result.operations.push(\n parseObject(text.slice(elementStart, i + 1)),\n );\n elementStart = -1;\n }\n if (ch === \"]\" && inOperations && stack.length === 1) {\n inOperations = false;\n expectingValue = false;\n }\n break;\n case undefined:\n // Unreachable: `i < text.length`, so `text[i]` is always a char.\n break;\n }\n }\n this.inString = inString;\n this.escaped = escaped;\n this.stringStart = stringStart;\n this.pendingKey = pendingKey;\n this.currentKey = currentKey;\n this.expectingValue = expectingValue;\n this.inOperations = inOperations;\n this.elementStart = elementStart;\n this.scanned = text.length;\n if (elementStart >= 0) result.incompleteOperation = true;\n else delete result.incompleteOperation;\n return result;\n }\n}\n\nfunction parseObject(raw: string) {\n try {\n const value: unknown = JSON.parse(raw);\n return isRecord(value) ? value : null;\n } catch {\n return null;\n }\n}\n\n/** Feeds streamed argument deltas and reports operations not yet seen. */\nexport class RenderUIArgsStream {\n private buffer = \"\";\n private emitted = 0;\n private incomplete = false;\n private readonly scanner = new RenderUIArgsScanner();\n\n push(delta: string) {\n this.buffer += delta;\n const { target, operations, incompleteOperation } = this.scanner.scan(\n this.buffer,\n );\n const newOperations = operations.slice(this.emitted);\n this.emitted = operations.length;\n this.incomplete = incompleteOperation === true;\n return { target, newOperations };\n }\n\n /** Every argument delta received so far, concatenated. */\n get text() {\n return this.buffer;\n }\n\n /**\n * True when the text received so far ends inside an `operations[]` element.\n * Once the tool call has ended, that element was truncated.\n */\n get hasIncompleteOperation() {\n return this.incomplete;\n }\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,oBAAoB,MAAc;AAChD,QAAO,IAAI,qBAAqB,CAAC,KAAK,KAAK;;;;;;;AAQ7C,IAAM,sBAAN,MAA0B;;gBACyB,EAAE,YAAY,EAAE,EAAE;eACxB,EAAE;kBAC1B;iBACD;qBACI;oBACc;oBACA;wBACX;sBACF;sBACA;iBACL;;;;;;;;;CASlB,KAAK,MAAc;EACjB,MAAM,EAAE,QAAQ,UAAU;EAC1B,IAAI,EACF,UACA,SACA,aACA,YACA,YACA,gBACA,cACA,iBACE;AACJ,OAAK,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,QAAQ,KAAK;GAC/C,MAAM,KAAK,KAAK;AAChB,OAAI,UAAU;AACZ,QAAI,QACF,WAAU;aACD,OAAO,KAChB,WAAU;aACD,OAAO,MAAK;AACrB,gBAAW;AACX,SAAI,MAAM,WAAW,GAAG;MACtB,MAAM,UAAU,KAAK,MAAM,aAAa,IAAI,EAAE;AAC9C,UAAI,gBAAgB;AAClB,WAAI,eAAe,SACjB,KAAI;AACF,eAAO,SAAS,KAAK,MAAM,QAAQ;eAC7B;AAIV,wBAAiB;YAEjB,cAAa;;;AAInB;;AAEF,WAAQ,IAAR;IACE,KAAK;AACH,gBAAW;AACX,mBAAc;AACd;IACF,KAAK;AACH,SAAI,MAAM,WAAW,KAAK,eAAe,MAAM;AAC7C,UAAI;AACF,oBAAa,KAAK,MAAM,WAAW;cAC7B;AACN,oBAAa;;AAEf,mBAAa;AACb,uBAAiB;;AAEnB;IACF,KAAK;AACH,SAAI,MAAM,WAAW,GAAG;AACtB,uBAAiB;AACjB,mBAAa;;AAEf;IACF,KAAK;AACH,SAAI,gBAAgB,MAAM,WAAW,EAAG,gBAAe;AACvD,WAAM,KAAK,IAAI;AACf;IACF,KAAK;AACH,SACE,MAAM,WAAW,KACjB,kBACA,eAAe,aAEf,gBAAe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