@copilotkit/shared 2.0.0-next.1 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (592) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +93 -12
  3. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/a2ui-envelope.cjs +154 -0
  5. package/dist/a2ui-envelope.cjs.map +1 -0
  6. package/dist/a2ui-envelope.d.cts +101 -0
  7. package/dist/a2ui-envelope.d.cts.map +1 -0
  8. package/dist/a2ui-envelope.d.mts +101 -0
  9. package/dist/a2ui-envelope.d.mts.map +1 -0
  10. package/dist/a2ui-envelope.mjs +151 -0
  11. package/dist/a2ui-envelope.mjs.map +1 -0
  12. package/dist/a2ui-prompts.cjs +259 -0
  13. package/dist/a2ui-prompts.cjs.map +1 -0
  14. package/dist/a2ui-prompts.d.cts +79 -0
  15. package/dist/a2ui-prompts.d.cts.map +1 -0
  16. package/dist/a2ui-prompts.d.mts +79 -0
  17. package/dist/a2ui-prompts.d.mts.map +1 -0
  18. package/dist/a2ui-prompts.mjs +251 -0
  19. package/dist/a2ui-prompts.mjs.map +1 -0
  20. package/dist/attachments/content.cjs +17 -0
  21. package/dist/attachments/content.cjs.map +1 -0
  22. package/dist/attachments/content.d.cts +9 -0
  23. package/dist/attachments/content.d.cts.map +1 -0
  24. package/dist/attachments/content.d.mts +9 -0
  25. package/dist/attachments/content.d.mts.map +1 -0
  26. package/dist/attachments/content.mjs +16 -0
  27. package/dist/attachments/content.mjs.map +1 -0
  28. package/dist/attachments/types.d.cts +64 -0
  29. package/dist/attachments/types.d.cts.map +1 -0
  30. package/dist/attachments/types.d.mts +64 -0
  31. package/dist/attachments/types.d.mts.map +1 -0
  32. package/dist/attachments/utils.cjs +137 -0
  33. package/dist/attachments/utils.cjs.map +1 -0
  34. package/dist/attachments/utils.d.cts +44 -0
  35. package/dist/attachments/utils.d.cts.map +1 -0
  36. package/dist/attachments/utils.d.mts +44 -0
  37. package/dist/attachments/utils.d.mts.map +1 -0
  38. package/dist/attachments/utils.mjs +129 -0
  39. package/dist/attachments/utils.mjs.map +1 -0
  40. package/dist/constants/index.cjs +25 -0
  41. package/dist/constants/index.cjs.map +1 -0
  42. package/dist/constants/index.d.cts +17 -0
  43. package/dist/constants/index.d.cts.map +1 -0
  44. package/dist/constants/index.d.mts +17 -0
  45. package/dist/constants/index.d.mts.map +1 -0
  46. package/dist/constants/index.mjs +17 -12
  47. package/dist/constants/index.mjs.map +1 -1
  48. package/dist/debug-event-envelope.d.cts +13 -0
  49. package/dist/debug-event-envelope.d.cts.map +1 -0
  50. package/dist/debug-event-envelope.d.mts +13 -0
  51. package/dist/debug-event-envelope.d.mts.map +1 -0
  52. package/dist/debug.cjs +38 -0
  53. package/dist/debug.cjs.map +1 -0
  54. package/dist/debug.d.cts +29 -0
  55. package/dist/debug.d.cts.map +1 -0
  56. package/dist/debug.d.mts +29 -0
  57. package/dist/debug.d.mts.map +1 -0
  58. package/dist/debug.mjs +37 -0
  59. package/dist/debug.mjs.map +1 -0
  60. package/dist/event-transforms/index.cjs +15 -0
  61. package/dist/event-transforms/index.d.cts +4 -0
  62. package/dist/event-transforms/index.d.mts +4 -0
  63. package/dist/event-transforms/index.mjs +5 -0
  64. package/dist/event-transforms/open-generative-ui-middleware.cjs +286 -0
  65. package/dist/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
  66. package/dist/event-transforms/open-generative-ui-middleware.d.cts +60 -0
  67. package/dist/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
  68. package/dist/event-transforms/open-generative-ui-middleware.d.mts +60 -0
  69. package/dist/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
  70. package/dist/event-transforms/open-generative-ui-middleware.mjs +283 -0
  71. package/dist/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
  72. package/dist/event-transforms/recorded-events.cjs +59 -0
  73. package/dist/event-transforms/recorded-events.cjs.map +1 -0
  74. package/dist/event-transforms/recorded-events.d.cts +23 -0
  75. package/dist/event-transforms/recorded-events.d.cts.map +1 -0
  76. package/dist/event-transforms/recorded-events.d.mts +23 -0
  77. package/dist/event-transforms/recorded-events.d.mts.map +1 -0
  78. package/dist/event-transforms/recorded-events.mjs +58 -0
  79. package/dist/event-transforms/recorded-events.mjs.map +1 -0
  80. package/dist/finalize-events.cjs +186 -0
  81. package/dist/finalize-events.cjs.map +1 -0
  82. package/dist/finalize-events.d.cts +40 -0
  83. package/dist/finalize-events.d.cts.map +1 -0
  84. package/dist/finalize-events.d.mts +40 -0
  85. package/dist/finalize-events.d.mts.map +1 -0
  86. package/dist/finalize-events.mjs +184 -0
  87. package/dist/finalize-events.mjs.map +1 -0
  88. package/dist/generative-ui/basic-functions.cjs +177 -0
  89. package/dist/generative-ui/basic-functions.cjs.map +1 -0
  90. package/dist/generative-ui/basic-functions.d.cts +108 -0
  91. package/dist/generative-ui/basic-functions.d.cts.map +1 -0
  92. package/dist/generative-ui/basic-functions.d.mts +108 -0
  93. package/dist/generative-ui/basic-functions.d.mts.map +1 -0
  94. package/dist/generative-ui/basic-functions.mjs +167 -0
  95. package/dist/generative-ui/basic-functions.mjs.map +1 -0
  96. package/dist/generative-ui/child-refs.cjs +161 -0
  97. package/dist/generative-ui/child-refs.cjs.map +1 -0
  98. package/dist/generative-ui/child-refs.d.cts +68 -0
  99. package/dist/generative-ui/child-refs.d.cts.map +1 -0
  100. package/dist/generative-ui/child-refs.d.mts +68 -0
  101. package/dist/generative-ui/child-refs.d.mts.map +1 -0
  102. package/dist/generative-ui/child-refs.mjs +152 -0
  103. package/dist/generative-ui/child-refs.mjs.map +1 -0
  104. package/dist/generative-ui/is-record.cjs +10 -0
  105. package/dist/generative-ui/is-record.cjs.map +1 -0
  106. package/dist/generative-ui/is-record.mjs +9 -0
  107. package/dist/generative-ui/is-record.mjs.map +1 -0
  108. package/dist/generative-ui/prompt.cjs +91 -0
  109. package/dist/generative-ui/prompt.cjs.map +1 -0
  110. package/dist/generative-ui/prompt.d.cts +13 -0
  111. package/dist/generative-ui/prompt.d.cts.map +1 -0
  112. package/dist/generative-ui/prompt.d.mts +13 -0
  113. package/dist/generative-ui/prompt.d.mts.map +1 -0
  114. package/dist/generative-ui/prompt.mjs +90 -0
  115. package/dist/generative-ui/prompt.mjs.map +1 -0
  116. package/dist/generative-ui/render-ui-args.cjs +160 -0
  117. package/dist/generative-ui/render-ui-args.cjs.map +1 -0
  118. package/dist/generative-ui/render-ui-args.d.cts +40 -0
  119. package/dist/generative-ui/render-ui-args.d.cts.map +1 -0
  120. package/dist/generative-ui/render-ui-args.d.mts +40 -0
  121. package/dist/generative-ui/render-ui-args.d.mts.map +1 -0
  122. package/dist/generative-ui/render-ui-args.mjs +159 -0
  123. package/dist/generative-ui/render-ui-args.mjs.map +1 -0
  124. package/dist/generative-ui/types.cjs +101 -0
  125. package/dist/generative-ui/types.cjs.map +1 -0
  126. package/dist/generative-ui/types.d.cts +270 -0
  127. package/dist/generative-ui/types.d.cts.map +1 -0
  128. package/dist/generative-ui/types.d.mts +270 -0
  129. package/dist/generative-ui/types.d.mts.map +1 -0
  130. package/dist/generative-ui/types.mjs +86 -0
  131. package/dist/generative-ui/types.mjs.map +1 -0
  132. package/dist/generative-ui/validate-operation.cjs +405 -0
  133. package/dist/generative-ui/validate-operation.cjs.map +1 -0
  134. package/dist/generative-ui/validate-operation.d.cts +86 -0
  135. package/dist/generative-ui/validate-operation.d.cts.map +1 -0
  136. package/dist/generative-ui/validate-operation.d.mts +86 -0
  137. package/dist/generative-ui/validate-operation.d.mts.map +1 -0
  138. package/dist/generative-ui/validate-operation.mjs +399 -0
  139. package/dist/generative-ui/validate-operation.mjs.map +1 -0
  140. package/dist/index.cjs +233 -0
  141. package/dist/index.cjs.map +1 -0
  142. package/dist/index.d.cts +80 -0
  143. package/dist/index.d.cts.map +1 -0
  144. package/dist/index.d.mts +80 -0
  145. package/dist/index.d.mts.map +1 -0
  146. package/dist/index.mjs +78 -123
  147. package/dist/index.mjs.map +1 -1
  148. package/dist/index.umd.js +3979 -0
  149. package/dist/index.umd.js.map +1 -0
  150. package/dist/intelligence-routing-fields.cjs +35 -0
  151. package/dist/intelligence-routing-fields.cjs.map +1 -0
  152. package/dist/intelligence-routing-fields.d.cts +18 -0
  153. package/dist/intelligence-routing-fields.d.cts.map +1 -0
  154. package/dist/intelligence-routing-fields.d.mts +18 -0
  155. package/dist/intelligence-routing-fields.d.mts.map +1 -0
  156. package/dist/intelligence-routing-fields.mjs +34 -0
  157. package/dist/intelligence-routing-fields.mjs.map +1 -0
  158. package/dist/logger.cjs +7 -0
  159. package/dist/logger.cjs.map +1 -0
  160. package/dist/logger.d.cts +5 -0
  161. package/dist/logger.d.cts.map +1 -0
  162. package/dist/logger.d.mts +5 -0
  163. package/dist/logger.d.mts.map +1 -0
  164. package/dist/logger.mjs +6 -0
  165. package/dist/logger.mjs.map +1 -0
  166. package/dist/open-generative-ui-prompts.cjs +8 -0
  167. package/dist/open-generative-ui-prompts.cjs.map +1 -0
  168. package/dist/open-generative-ui-prompts.d.cts +6 -0
  169. package/dist/open-generative-ui-prompts.d.cts.map +1 -0
  170. package/dist/open-generative-ui-prompts.d.mts +6 -0
  171. package/dist/open-generative-ui-prompts.d.mts.map +1 -0
  172. package/dist/open-generative-ui-prompts.mjs +7 -0
  173. package/dist/open-generative-ui-prompts.mjs.map +1 -0
  174. package/dist/package.cjs +12 -0
  175. package/dist/package.cjs.map +1 -0
  176. package/dist/package.mjs +6 -0
  177. package/dist/package.mjs.map +1 -0
  178. package/dist/standard-schema.cjs +31 -0
  179. package/dist/standard-schema.cjs.map +1 -0
  180. package/dist/standard-schema.d.cts +33 -0
  181. package/dist/standard-schema.d.cts.map +1 -0
  182. package/dist/standard-schema.d.mts +33 -0
  183. package/dist/standard-schema.d.mts.map +1 -0
  184. package/dist/standard-schema.mjs +30 -0
  185. package/dist/standard-schema.mjs.map +1 -0
  186. package/dist/telemetry/events.d.cts +72 -0
  187. package/dist/telemetry/events.d.cts.map +1 -0
  188. package/dist/telemetry/events.d.mts +72 -0
  189. package/dist/telemetry/events.d.mts.map +1 -0
  190. package/dist/telemetry/index.cjs +18 -0
  191. package/dist/telemetry/index.d.cts +5 -0
  192. package/dist/telemetry/index.d.mts +5 -0
  193. package/dist/telemetry/index.mjs +6 -12
  194. package/dist/telemetry/lambda-client.cjs +91 -0
  195. package/dist/telemetry/lambda-client.cjs.map +1 -0
  196. package/dist/telemetry/lambda-client.d.cts +31 -0
  197. package/dist/telemetry/lambda-client.d.cts.map +1 -0
  198. package/dist/telemetry/lambda-client.d.mts +31 -0
  199. package/dist/telemetry/lambda-client.d.mts.map +1 -0
  200. package/dist/telemetry/lambda-client.mjs +87 -0
  201. package/dist/telemetry/lambda-client.mjs.map +1 -0
  202. package/dist/telemetry/model-host.cjs +104 -0
  203. package/dist/telemetry/model-host.cjs.map +1 -0
  204. package/dist/telemetry/model-host.d.cts +26 -0
  205. package/dist/telemetry/model-host.d.cts.map +1 -0
  206. package/dist/telemetry/model-host.d.mts +26 -0
  207. package/dist/telemetry/model-host.d.mts.map +1 -0
  208. package/dist/telemetry/model-host.mjs +102 -0
  209. package/dist/telemetry/model-host.mjs.map +1 -0
  210. package/dist/telemetry/sampling.cjs +50 -0
  211. package/dist/telemetry/sampling.cjs.map +1 -0
  212. package/dist/telemetry/sampling.d.cts +57 -0
  213. package/dist/telemetry/sampling.d.cts.map +1 -0
  214. package/dist/telemetry/sampling.d.mts +57 -0
  215. package/dist/telemetry/sampling.d.mts.map +1 -0
  216. package/dist/telemetry/sampling.mjs +44 -0
  217. package/dist/telemetry/sampling.mjs.map +1 -0
  218. package/dist/telemetry/telemetry-client.cjs +165 -0
  219. package/dist/telemetry/telemetry-client.cjs.map +1 -0
  220. package/dist/telemetry/telemetry-client.d.cts +87 -0
  221. package/dist/telemetry/telemetry-client.d.cts.map +1 -0
  222. package/dist/telemetry/telemetry-client.d.mts +87 -0
  223. package/dist/telemetry/telemetry-client.d.mts.map +1 -0
  224. package/dist/telemetry/telemetry-client.mjs +162 -9
  225. package/dist/telemetry/telemetry-client.mjs.map +1 -1
  226. package/dist/telemetry/telemetry-disabled.cjs +20 -0
  227. package/dist/telemetry/telemetry-disabled.cjs.map +1 -0
  228. package/dist/telemetry/telemetry-disabled.d.cts +16 -0
  229. package/dist/telemetry/telemetry-disabled.d.cts.map +1 -0
  230. package/dist/telemetry/telemetry-disabled.d.mts +16 -0
  231. package/dist/telemetry/telemetry-disabled.d.mts.map +1 -0
  232. package/dist/telemetry/telemetry-disabled.mjs +19 -0
  233. package/dist/telemetry/telemetry-disabled.mjs.map +1 -0
  234. package/dist/telemetry/utils.cjs +14 -0
  235. package/dist/telemetry/utils.cjs.map +1 -0
  236. package/dist/telemetry/utils.mjs +12 -8
  237. package/dist/telemetry/utils.mjs.map +1 -1
  238. package/dist/transcription-errors.cjs +84 -0
  239. package/dist/transcription-errors.cjs.map +1 -0
  240. package/dist/transcription-errors.d.cts +52 -0
  241. package/dist/transcription-errors.d.cts.map +1 -0
  242. package/dist/transcription-errors.d.mts +52 -0
  243. package/dist/transcription-errors.d.mts.map +1 -0
  244. package/dist/transcription-errors.mjs +82 -0
  245. package/dist/transcription-errors.mjs.map +1 -0
  246. package/dist/types/{action.d.ts → action.d.cts} +32 -32
  247. package/dist/types/action.d.cts.map +1 -0
  248. package/dist/types/action.d.mts +59 -0
  249. package/dist/types/action.d.mts.map +1 -0
  250. package/dist/types/copilot-cloud-config.d.cts +15 -0
  251. package/dist/types/copilot-cloud-config.d.cts.map +1 -0
  252. package/dist/types/copilot-cloud-config.d.mts +15 -0
  253. package/dist/types/copilot-cloud-config.d.mts.map +1 -0
  254. package/dist/types/error.d.cts +57 -0
  255. package/dist/types/error.d.cts.map +1 -0
  256. package/dist/types/error.d.mts +57 -0
  257. package/dist/types/error.d.mts.map +1 -0
  258. package/dist/types/message.d.cts +42 -0
  259. package/dist/types/message.d.cts.map +1 -0
  260. package/dist/types/message.d.mts +42 -0
  261. package/dist/types/message.d.mts.map +1 -0
  262. package/dist/types/openai-assistant.d.cts +55 -0
  263. package/dist/types/openai-assistant.d.cts.map +1 -0
  264. package/dist/types/openai-assistant.d.mts +55 -0
  265. package/dist/types/openai-assistant.d.mts.map +1 -0
  266. package/dist/types/utility.d.cts +6 -0
  267. package/dist/types/utility.d.cts.map +1 -0
  268. package/dist/types/utility.d.mts +6 -0
  269. package/dist/types/utility.d.mts.map +1 -0
  270. package/dist/utils/clipboard.cjs +28 -0
  271. package/dist/utils/clipboard.cjs.map +1 -0
  272. package/dist/utils/clipboard.d.cts +14 -0
  273. package/dist/utils/clipboard.d.cts.map +1 -0
  274. package/dist/utils/clipboard.d.mts +14 -0
  275. package/dist/utils/clipboard.d.mts.map +1 -0
  276. package/dist/utils/clipboard.mjs +27 -0
  277. package/dist/utils/clipboard.mjs.map +1 -0
  278. package/dist/utils/conditions.cjs +32 -0
  279. package/dist/utils/conditions.cjs.map +1 -0
  280. package/dist/utils/{conditions.d.ts → conditions.d.cts} +16 -11
  281. package/dist/utils/conditions.d.cts.map +1 -0
  282. package/dist/utils/conditions.d.mts +31 -0
  283. package/dist/utils/conditions.d.mts.map +1 -0
  284. package/dist/utils/conditions.mjs +30 -6
  285. package/dist/utils/conditions.mjs.map +1 -1
  286. package/dist/utils/console-styling.cjs +91 -0
  287. package/dist/utils/console-styling.cjs.map +1 -0
  288. package/dist/utils/console-styling.d.cts +65 -0
  289. package/dist/utils/console-styling.d.cts.map +1 -0
  290. package/dist/utils/console-styling.d.mts +65 -0
  291. package/dist/utils/console-styling.d.mts.map +1 -0
  292. package/dist/utils/console-styling.mjs +83 -15
  293. package/dist/utils/console-styling.mjs.map +1 -1
  294. package/dist/utils/dashboard-url.cjs +19 -0
  295. package/dist/utils/dashboard-url.cjs.map +1 -0
  296. package/dist/utils/dashboard-url.mjs +18 -0
  297. package/dist/utils/dashboard-url.mjs.map +1 -0
  298. package/dist/utils/errors.cjs +439 -0
  299. package/dist/utils/errors.cjs.map +1 -0
  300. package/dist/utils/{errors.d.ts → errors.d.cts} +188 -156
  301. package/dist/utils/errors.d.cts.map +1 -0
  302. package/dist/utils/errors.d.mts +312 -0
  303. package/dist/utils/errors.d.mts.map +1 -0
  304. package/dist/utils/errors.mjs +416 -63
  305. package/dist/utils/errors.mjs.map +1 -1
  306. package/dist/utils/index.cjs +105 -0
  307. package/dist/utils/index.cjs.map +1 -0
  308. package/dist/utils/index.d.cts +58 -0
  309. package/dist/utils/index.d.cts.map +1 -0
  310. package/dist/utils/index.d.mts +58 -0
  311. package/dist/utils/index.d.mts.map +1 -0
  312. package/dist/utils/index.mjs +97 -107
  313. package/dist/utils/index.mjs.map +1 -1
  314. package/dist/utils/inspector-learning.cjs +217 -0
  315. package/dist/utils/inspector-learning.cjs.map +1 -0
  316. package/dist/utils/inspector-learning.d.cts +104 -0
  317. package/dist/utils/inspector-learning.d.cts.map +1 -0
  318. package/dist/utils/inspector-learning.d.mts +104 -0
  319. package/dist/utils/inspector-learning.d.mts.map +1 -0
  320. package/dist/utils/inspector-learning.mjs +215 -0
  321. package/dist/utils/inspector-learning.mjs.map +1 -0
  322. package/dist/utils/inspector-metadata.cjs +146 -0
  323. package/dist/utils/inspector-metadata.cjs.map +1 -0
  324. package/dist/utils/inspector-metadata.d.cts +55 -0
  325. package/dist/utils/inspector-metadata.d.cts.map +1 -0
  326. package/dist/utils/inspector-metadata.d.mts +55 -0
  327. package/dist/utils/inspector-metadata.d.mts.map +1 -0
  328. package/dist/utils/inspector-metadata.mjs +146 -0
  329. package/dist/utils/inspector-metadata.mjs.map +1 -0
  330. package/dist/utils/inspector-visibility.cjs +13 -0
  331. package/dist/utils/inspector-visibility.cjs.map +1 -0
  332. package/dist/utils/inspector-visibility.d.cts +18 -0
  333. package/dist/utils/inspector-visibility.d.cts.map +1 -0
  334. package/dist/utils/inspector-visibility.d.mts +18 -0
  335. package/dist/utils/inspector-visibility.d.mts.map +1 -0
  336. package/dist/utils/inspector-visibility.mjs +12 -0
  337. package/dist/utils/inspector-visibility.mjs.map +1 -0
  338. package/dist/utils/json-schema.cjs +215 -0
  339. package/dist/utils/json-schema.cjs.map +1 -0
  340. package/dist/utils/{json-schema.d.ts → json-schema.d.cts} +20 -18
  341. package/dist/utils/json-schema.d.cts.map +1 -0
  342. package/dist/utils/json-schema.d.mts +36 -0
  343. package/dist/utils/json-schema.d.mts.map +1 -0
  344. package/dist/utils/json-schema.mjs +210 -12
  345. package/dist/utils/json-schema.mjs.map +1 -1
  346. package/dist/utils/random-id.cjs +38 -0
  347. package/dist/utils/random-id.cjs.map +1 -0
  348. package/dist/utils/{random-id.d.ts → random-id.d.cts} +3 -1
  349. package/dist/utils/random-id.d.cts.map +1 -0
  350. package/dist/utils/random-id.d.mts +8 -0
  351. package/dist/utils/random-id.d.mts.map +1 -0
  352. package/dist/utils/random-id.mjs +33 -12
  353. package/dist/utils/random-id.mjs.map +1 -1
  354. package/dist/utils/requests.cjs +58 -0
  355. package/dist/utils/requests.cjs.map +1 -0
  356. package/dist/utils/{requests.d.ts → requests.d.cts} +3 -1
  357. package/dist/utils/requests.d.cts.map +1 -0
  358. package/dist/utils/requests.d.mts +12 -0
  359. package/dist/utils/requests.d.mts.map +1 -0
  360. package/dist/utils/requests.mjs +56 -6
  361. package/dist/utils/requests.mjs.map +1 -1
  362. package/dist/utils/row-render-keys.cjs +206 -0
  363. package/dist/utils/row-render-keys.cjs.map +1 -0
  364. package/dist/utils/row-render-keys.d.cts +65 -0
  365. package/dist/utils/row-render-keys.d.cts.map +1 -0
  366. package/dist/utils/row-render-keys.d.mts +65 -0
  367. package/dist/utils/row-render-keys.d.mts.map +1 -0
  368. package/dist/utils/row-render-keys.mjs +201 -0
  369. package/dist/utils/row-render-keys.mjs.map +1 -0
  370. package/dist/utils/types.cjs +9 -0
  371. package/dist/utils/types.cjs.map +1 -0
  372. package/dist/utils/types.d.cts +122 -0
  373. package/dist/utils/types.d.cts.map +1 -0
  374. package/dist/utils/types.d.mts +122 -0
  375. package/dist/utils/types.d.mts.map +1 -0
  376. package/dist/utils/types.mjs +6 -1
  377. package/dist/utils/types.mjs.map +1 -1
  378. package/package.json +74 -40
  379. package/scripts/verify-cjs-exports.cjs +16 -0
  380. package/src/__tests__/a2ui-envelope.test.ts +434 -0
  381. package/src/__tests__/a2ui-prompts.test.ts +362 -0
  382. package/src/__tests__/debug.test.ts +116 -0
  383. package/src/__tests__/license-context.test.ts +253 -0
  384. package/src/__tests__/root-entry-browser-safety.test.ts +91 -0
  385. package/src/__tests__/standard-schema-types.test.ts +144 -0
  386. package/src/__tests__/standard-schema.test.ts +359 -0
  387. package/src/__tests__/zod-regression.test.ts +319 -0
  388. package/src/a2ui-envelope.ts +309 -0
  389. package/src/a2ui-prompts.ts +322 -0
  390. package/src/attachments/__tests__/utils.test.ts +214 -0
  391. package/src/attachments/content.test.ts +48 -0
  392. package/src/attachments/content.ts +16 -0
  393. package/src/attachments/index.ts +21 -0
  394. package/src/attachments/types.ts +77 -0
  395. package/src/attachments/utils.ts +169 -0
  396. package/src/constants/index.ts +14 -1
  397. package/src/debug-event-envelope.ts +9 -0
  398. package/src/debug.ts +55 -0
  399. package/src/event-transforms/index.ts +5 -0
  400. package/src/event-transforms/open-generative-ui-middleware.ts +392 -0
  401. package/src/event-transforms/recorded-events.test.ts +166 -0
  402. package/src/event-transforms/recorded-events.ts +74 -0
  403. package/src/finalize-events.test.ts +284 -0
  404. package/src/finalize-events.ts +260 -0
  405. package/src/generative-ui/__tests__/render-ui-args.test.ts +175 -0
  406. package/src/generative-ui/__tests__/validate-operation.test.ts +977 -0
  407. package/src/generative-ui/basic-functions.ts +282 -0
  408. package/src/generative-ui/child-refs.ts +210 -0
  409. package/src/generative-ui/index.ts +6 -0
  410. package/src/generative-ui/is-record.ts +4 -0
  411. package/src/generative-ui/prompt.ts +174 -0
  412. package/src/generative-ui/render-ui-args.ts +199 -0
  413. package/src/generative-ui/types.ts +314 -0
  414. package/src/generative-ui/validate-operation.ts +723 -0
  415. package/src/index.ts +190 -1
  416. package/src/intelligence-routing-fields.test.ts +51 -0
  417. package/src/intelligence-routing-fields.ts +40 -0
  418. package/src/logger.ts +1 -0
  419. package/src/open-generative-ui-prompts.ts +20 -0
  420. package/src/standard-schema.ts +82 -0
  421. package/src/telemetry/events.ts +37 -10
  422. package/src/telemetry/index.ts +8 -0
  423. package/src/telemetry/lambda-client.test.ts +446 -0
  424. package/src/telemetry/lambda-client.ts +194 -0
  425. package/src/telemetry/model-host.test.ts +145 -0
  426. package/src/telemetry/model-host.ts +156 -0
  427. package/src/telemetry/sampling.test.ts +65 -0
  428. package/src/telemetry/sampling.ts +103 -0
  429. package/src/telemetry/telemetry-blank-license-identity.test.ts +128 -0
  430. package/src/telemetry/telemetry-client.test.ts +798 -0
  431. package/src/telemetry/telemetry-client.ts +223 -37
  432. package/src/telemetry/telemetry-disabled.ts +22 -0
  433. package/src/telemetry/utils.ts +0 -24
  434. package/src/transcription-errors.ts +99 -0
  435. package/src/types/__tests__/message.test.ts +62 -0
  436. package/src/types/action.ts +9 -5
  437. package/src/types/error.ts +11 -2
  438. package/src/types/message.ts +33 -5
  439. package/src/types/openai-assistant.ts +6 -2
  440. package/src/utils/__tests__/clipboard.test.ts +87 -0
  441. package/src/utils/__tests__/conditions.test.ts +161 -0
  442. package/src/utils/__tests__/json-schema.test.ts +812 -0
  443. package/src/utils/__tests__/row-render-keys.test.ts +388 -0
  444. package/src/utils/clipboard.ts +23 -0
  445. package/src/utils/conditions.ts +27 -9
  446. package/src/utils/console-styling.ts +10 -8
  447. package/src/utils/dashboard-url.ts +17 -0
  448. package/src/utils/errors.ts +55 -22
  449. package/src/utils/index.ts +70 -1
  450. package/src/utils/inspector-learning.test.ts +423 -0
  451. package/src/utils/inspector-learning.ts +523 -0
  452. package/src/utils/inspector-metadata.test.ts +743 -0
  453. package/src/utils/inspector-metadata.ts +263 -0
  454. package/src/utils/inspector-visibility.test.ts +43 -0
  455. package/src/utils/inspector-visibility.ts +17 -0
  456. package/src/utils/json-schema.ts +156 -12
  457. package/src/utils/random-id.ts +5 -2
  458. package/src/utils/requests.ts +3 -1
  459. package/src/utils/row-render-keys.ts +263 -0
  460. package/src/utils/types.ts +128 -1
  461. package/src/utils.test.ts +137 -0
  462. package/tsconfig.json +10 -2
  463. package/tsdown.config.ts +49 -0
  464. package/vitest.config.mjs +11 -0
  465. package/CHANGELOG.md +0 -1817
  466. package/dist/chunk-2OJ5OJ2D.mjs +0 -1
  467. package/dist/chunk-2OJ5OJ2D.mjs.map +0 -1
  468. package/dist/chunk-64DYJ27R.mjs +0 -201
  469. package/dist/chunk-64DYJ27R.mjs.map +0 -1
  470. package/dist/chunk-6QGXWNS5.mjs +0 -34
  471. package/dist/chunk-6QGXWNS5.mjs.map +0 -1
  472. package/dist/chunk-6W2UEO2M.mjs +0 -94
  473. package/dist/chunk-6W2UEO2M.mjs.map +0 -1
  474. package/dist/chunk-7DJDTRNX.mjs +0 -426
  475. package/dist/chunk-7DJDTRNX.mjs.map +0 -1
  476. package/dist/chunk-A66772CV.mjs +0 -107
  477. package/dist/chunk-A66772CV.mjs.map +0 -1
  478. package/dist/chunk-BOKE4OKY.mjs +0 -41
  479. package/dist/chunk-BOKE4OKY.mjs.map +0 -1
  480. package/dist/chunk-FCCOSO5L.mjs +0 -1
  481. package/dist/chunk-FCCOSO5L.mjs.map +0 -1
  482. package/dist/chunk-GYZIHHE6.mjs +0 -13
  483. package/dist/chunk-GYZIHHE6.mjs.map +0 -1
  484. package/dist/chunk-IAFBVORQ.mjs +0 -1
  485. package/dist/chunk-IAFBVORQ.mjs.map +0 -1
  486. package/dist/chunk-JAAUCDUR.mjs +0 -38
  487. package/dist/chunk-JAAUCDUR.mjs.map +0 -1
  488. package/dist/chunk-MSUB6DGR.mjs +0 -1
  489. package/dist/chunk-MSUB6DGR.mjs.map +0 -1
  490. package/dist/chunk-N5EP5OD5.mjs +0 -1
  491. package/dist/chunk-N5EP5OD5.mjs.map +0 -1
  492. package/dist/chunk-NAFEBKSO.mjs +0 -1
  493. package/dist/chunk-NAFEBKSO.mjs.map +0 -1
  494. package/dist/chunk-P7STFMPO.mjs +0 -1
  495. package/dist/chunk-P7STFMPO.mjs.map +0 -1
  496. package/dist/chunk-PL5WNHFZ.mjs +0 -50
  497. package/dist/chunk-PL5WNHFZ.mjs.map +0 -1
  498. package/dist/chunk-UYARLQNA.mjs +0 -1
  499. package/dist/chunk-UYARLQNA.mjs.map +0 -1
  500. package/dist/chunk-XEMZTHQZ.mjs +0 -67
  501. package/dist/chunk-XEMZTHQZ.mjs.map +0 -1
  502. package/dist/chunk-XTHC46M2.mjs +0 -1
  503. package/dist/chunk-XTHC46M2.mjs.map +0 -1
  504. package/dist/constants/index.d.ts +0 -6
  505. package/dist/constants/index.js +0 -40
  506. package/dist/constants/index.js.map +0 -1
  507. package/dist/index.d.ts +0 -25
  508. package/dist/index.js +0 -1098
  509. package/dist/index.js.map +0 -1
  510. package/dist/telemetry/events.d.ts +0 -45
  511. package/dist/telemetry/events.js +0 -19
  512. package/dist/telemetry/events.js.map +0 -1
  513. package/dist/telemetry/events.mjs +0 -1
  514. package/dist/telemetry/events.mjs.map +0 -1
  515. package/dist/telemetry/index.d.ts +0 -3
  516. package/dist/telemetry/index.js +0 -188
  517. package/dist/telemetry/index.js.map +0 -1
  518. package/dist/telemetry/index.mjs.map +0 -1
  519. package/dist/telemetry/scarf-client.d.ts +0 -7
  520. package/dist/telemetry/scarf-client.js +0 -59
  521. package/dist/telemetry/scarf-client.js.map +0 -1
  522. package/dist/telemetry/scarf-client.mjs +0 -7
  523. package/dist/telemetry/scarf-client.mjs.map +0 -1
  524. package/dist/telemetry/security-check.d.ts +0 -2
  525. package/dist/telemetry/security-check.js +0 -2
  526. package/dist/telemetry/security-check.js.map +0 -1
  527. package/dist/telemetry/security-check.mjs +0 -1
  528. package/dist/telemetry/security-check.mjs.map +0 -1
  529. package/dist/telemetry/telemetry-client.d.ts +0 -40
  530. package/dist/telemetry/telemetry-client.js +0 -186
  531. package/dist/telemetry/telemetry-client.js.map +0 -1
  532. package/dist/telemetry/utils.d.ts +0 -8
  533. package/dist/telemetry/utils.js +0 -69
  534. package/dist/telemetry/utils.js.map +0 -1
  535. package/dist/types/action.js +0 -19
  536. package/dist/types/action.js.map +0 -1
  537. package/dist/types/action.mjs +0 -2
  538. package/dist/types/action.mjs.map +0 -1
  539. package/dist/types/copilot-cloud-config.d.ts +0 -13
  540. package/dist/types/copilot-cloud-config.js +0 -19
  541. package/dist/types/copilot-cloud-config.js.map +0 -1
  542. package/dist/types/copilot-cloud-config.mjs +0 -2
  543. package/dist/types/copilot-cloud-config.mjs.map +0 -1
  544. package/dist/types/error.d.ts +0 -55
  545. package/dist/types/error.js +0 -19
  546. package/dist/types/error.js.map +0 -1
  547. package/dist/types/error.mjs +0 -2
  548. package/dist/types/error.mjs.map +0 -1
  549. package/dist/types/index.d.ts +0 -7
  550. package/dist/types/index.js +0 -19
  551. package/dist/types/index.js.map +0 -1
  552. package/dist/types/index.mjs +0 -8
  553. package/dist/types/index.mjs.map +0 -1
  554. package/dist/types/message.d.ts +0 -26
  555. package/dist/types/message.js +0 -19
  556. package/dist/types/message.js.map +0 -1
  557. package/dist/types/message.mjs +0 -2
  558. package/dist/types/message.mjs.map +0 -1
  559. package/dist/types/openai-assistant.d.ts +0 -53
  560. package/dist/types/openai-assistant.js +0 -19
  561. package/dist/types/openai-assistant.js.map +0 -1
  562. package/dist/types/openai-assistant.mjs +0 -2
  563. package/dist/types/openai-assistant.mjs.map +0 -1
  564. package/dist/types/utility.d.ts +0 -6
  565. package/dist/types/utility.js +0 -19
  566. package/dist/types/utility.js.map +0 -1
  567. package/dist/types/utility.mjs +0 -2
  568. package/dist/types/utility.mjs.map +0 -1
  569. package/dist/utils/conditions.js +0 -74
  570. package/dist/utils/conditions.js.map +0 -1
  571. package/dist/utils/console-styling.d.ts +0 -84
  572. package/dist/utils/console-styling.js +0 -123
  573. package/dist/utils/console-styling.js.map +0 -1
  574. package/dist/utils/errors.js +0 -443
  575. package/dist/utils/errors.js.map +0 -1
  576. package/dist/utils/index.d.ts +0 -32
  577. package/dist/utils/index.js +0 -927
  578. package/dist/utils/index.js.map +0 -1
  579. package/dist/utils/json-schema.js +0 -228
  580. package/dist/utils/json-schema.js.map +0 -1
  581. package/dist/utils/random-id.js +0 -68
  582. package/dist/utils/random-id.js.map +0 -1
  583. package/dist/utils/requests.js +0 -91
  584. package/dist/utils/requests.js.map +0 -1
  585. package/dist/utils/types.d.ts +0 -20
  586. package/dist/utils/types.js +0 -19
  587. package/dist/utils/types.js.map +0 -1
  588. package/jest.config.js +0 -5
  589. package/src/telemetry/scarf-client.ts +0 -39
  590. package/src/telemetry/security-check.ts +0 -0
  591. package/src/utils/json-schema.test.ts +0 -383
  592. package/tsup.config.ts +0 -11
@@ -1,7 +1,57 @@
1
- import {
2
- readBody
3
- } from "../chunk-XEMZTHQZ.mjs";
4
- export {
5
- readBody
6
- };
1
+ //#region src/utils/requests.ts
2
+ /**
3
+ * Safely read a Response/Request body with sensible defaults:
4
+ * - clones the response/request to avoid consuming the original response/request
5
+ * - Skips GET/HEAD
6
+ * - Tries JSON first regardless of content-type
7
+ * - Falls back to text and optionally parses when it "looks" like JSON
8
+ */
9
+ async function readBody(r) {
10
+ const method = "method" in r ? r.method.toUpperCase() : void 0;
11
+ if (method === "GET" || method === "HEAD") return;
12
+ if (!("body" in r) || r.body == null) return;
13
+ try {
14
+ return await r.clone().json();
15
+ } catch {
16
+ try {
17
+ const text = await r.clone().text();
18
+ const trimmed = text.trim();
19
+ if (trimmed.length === 0) return text;
20
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) try {
21
+ return JSON.parse(trimmed);
22
+ } catch {
23
+ return text;
24
+ }
25
+ return text;
26
+ } catch {
27
+ try {
28
+ const stream = r.clone().body ?? null;
29
+ if (!stream) return void 0;
30
+ const reader = stream.getReader();
31
+ const decoder = new TextDecoder();
32
+ let out = "";
33
+ while (true) {
34
+ const { done, value } = await reader.read();
35
+ if (done) break;
36
+ if (typeof value === "string") out += value;
37
+ else out += decoder.decode(value, { stream: true });
38
+ }
39
+ out += decoder.decode();
40
+ const trimmed = out.trim();
41
+ if (trimmed.length === 0) return out;
42
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) try {
43
+ return JSON.parse(trimmed);
44
+ } catch {
45
+ return out;
46
+ }
47
+ return out;
48
+ } catch {
49
+ return;
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ //#endregion
56
+ export { readBody };
7
57
  //# sourceMappingURL=requests.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"requests.mjs","names":[],"sources":["../../src/utils/requests.ts"],"sourcesContent":["/**\n * Safely read a Response/Request body with sensible defaults:\n * - clones the response/request to avoid consuming the original response/request\n * - Skips GET/HEAD\n * - Tries JSON first regardless of content-type\n * - Falls back to text and optionally parses when it \"looks\" like JSON\n */\nexport async function readBody<T extends Response | Request>(\n r: T,\n): Promise<unknown> {\n // skip GET/HEAD requests (unchanged)\n const method = \"method\" in r ? r.method.toUpperCase() : undefined;\n if (method === \"GET\" || method === \"HEAD\") {\n return undefined;\n }\n\n // no body at all → undefined (unchanged)\n if (!(\"body\" in r) || r.body == null) {\n return undefined;\n }\n\n // 1) try JSON (unchanged)\n try {\n return await r.clone().json();\n } catch {\n // 2) try text (unchanged + your whitespace/JSON-heuristic)\n try {\n const text = await r.clone().text();\n const trimmed = text.trim();\n\n if (trimmed.length === 0) return text;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return text;\n }\n }\n return text;\n } catch {\n // 3) FINAL FALLBACK: manual read that accepts string or bytes\n try {\n const c = r.clone();\n const stream: ReadableStream | null = c.body ?? null;\n if (!stream) return undefined;\n\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let out = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (typeof value === \"string\") {\n out += value; // accept string chunks\n } else {\n out += decoder.decode(value, { stream: true }); // bytes\n }\n }\n out += decoder.decode(); // flush\n\n const trimmed = out.trim();\n if (trimmed.length === 0) return out;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return out;\n }\n }\n return out;\n } catch {\n return undefined; // same \"give up\" behavior you had\n }\n }\n }\n}\n"],"mappings":";;;;;;;;AAOA,eAAsB,SACpB,GACkB;CAElB,MAAM,SAAS,YAAY,IAAI,EAAE,OAAO,aAAa,GAAG;AACxD,KAAI,WAAW,SAAS,WAAW,OACjC;AAIF,KAAI,EAAE,UAAU,MAAM,EAAE,QAAQ,KAC9B;AAIF,KAAI;AACF,SAAO,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB;AAEN,MAAI;GACF,MAAM,OAAO,MAAM,EAAE,OAAO,CAAC,MAAM;GACnC,MAAM,UAAU,KAAK,MAAM;AAE3B,OAAI,QAAQ,WAAW,EAAG,QAAO;AAEjC,OAAI,QAAQ,WAAW,IAAI,IAAI,QAAQ,WAAW,IAAI,CACpD,KAAI;AACF,WAAO,KAAK,MAAM,QAAQ;WACpB;AACN,WAAO;;AAGX,UAAO;UACD;AAEN,OAAI;IAEF,MAAM,SADI,EAAE,OAAO,CACqB,QAAQ;AAChD,QAAI,CAAC,OAAQ,QAAO;IAEpB,MAAM,SAAS,OAAO,WAAW;IACjC,MAAM,UAAU,IAAI,aAAa;IACjC,IAAI,MAAM;AAEV,WAAO,MAAM;KACX,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,MAAM;AAC3C,SAAI,KAAM;AACV,SAAI,OAAO,UAAU,SACnB,QAAO;SAEP,QAAO,QAAQ,OAAO,OAAO,EAAE,QAAQ,MAAM,CAAC;;AAGlD,WAAO,QAAQ,QAAQ;IAEvB,MAAM,UAAU,IAAI,MAAM;AAC1B,QAAI,QAAQ,WAAW,EAAG,QAAO;AAEjC,QAAI,QAAQ,WAAW,IAAI,IAAI,QAAQ,WAAW,IAAI,CACpD,KAAI;AACF,YAAO,KAAK,MAAM,QAAQ;YACpB;AACN,YAAO;;AAGX,WAAO;WACD;AACN"}
@@ -0,0 +1,206 @@
1
+
2
+ //#region src/utils/row-render-keys.ts
3
+ /**
4
+ * Stable per-row view keys for chat transcripts, across backends that re-key a
5
+ * message mid-stream. Shared by every frontend package, because the defect and
6
+ * the correlation signal are in the message stream, not in any one framework.
7
+ *
8
+ * ## The problem
9
+ *
10
+ * A message's canonical `id` is not stable within a turn. LangChain stamps a
11
+ * placeholder id on the first streamed chunk when the provider didn't supply
12
+ * one (`chat_models.py`: `if chunk.message.id is None: chunk.message.id =
13
+ * "lc_run-" + "-" + run_id`), then prefers any provider-assigned id it sees
14
+ * while merging chunks (`messages/ai.py`, "Ranks are defined by the order of
15
+ * preference"). The `MESSAGES_SNAPSHOT` therefore carries the provider's final
16
+ * id (e.g. `resp_…`) for a message the client already knows as `lc_run--…`.
17
+ *
18
+ * Every framework destroys and recreates a row whose key changes, so keying
19
+ * rows by `id` turned that swap into the visible HITL chat flash, where a
20
+ * rendered approval card appears to reset during a tool's
21
+ * `executing → complete` transition.
22
+ *
23
+ * This is provider-conditional: providers that stamp an id on every chunk (so
24
+ * `chunk.message.id is None` never holds) never trigger a rename.
25
+ *
26
+ * ## The approach
27
+ *
28
+ * Tool-call ids survive the rename, so they are used as *anchors*: the first
29
+ * message seen carrying a given tool call records the key it was assigned, and
30
+ * any later message carrying that same tool call reuses it. The store is an
31
+ * override table consulted before falling back to `message.id`. Resolving only
32
+ * reads it; each render that reaches the DOM then records what it rendered:
33
+ *
34
+ * ```text
35
+ * render 1 id=lc_run--1 no tools key = message.id = lc_run--1
36
+ * commit 1 store {}
37
+ * render 2 id=lc_run--1 tc call_A key = message.id = lc_run--1
38
+ * commit 2 store { tc:call_A -> lc_run--1 }
39
+ * render 3 id=resp_1 tc call_A key = store[tc:call_A]
40
+ * = lc_run--1 (row survives)
41
+ * commit 3 store unchanged
42
+ * ```
43
+ *
44
+ * Recording the anchor at commit 2 — while the id is still stable — is what
45
+ * makes render 3 resolvable. Note the fix does not depend on render 2
46
+ * existing: a message born already carrying a tool call anchors on the first
47
+ * render that commits it, under whatever id it holds then.
48
+ *
49
+ * ## Why an override table rather than keying rows by tool-call id
50
+ *
51
+ * Deriving the key from the tool call directly (`tc:<id>` whenever a tool call
52
+ * is present) needs no state, but changes the key the moment a tool call
53
+ * *appears* — so an assistant message that streams text and then calls a tool
54
+ * is torn down on that transition, for every provider, whether or not it
55
+ * renames. That trades a conditional flash for an unconditional one. Recording
56
+ * an override keeps the key the row already had.
57
+ *
58
+ * ## Cost
59
+ *
60
+ * The store holds only `tc:<toolCallId>` entries, so a conversation with no
61
+ * tool calls keeps an empty store and behaviour byte-identical to keying by
62
+ * `id`. Size is bounded to the tool calls of the currently-rendered messages
63
+ * (see `pruneRowKeyStore`), not the conversation length. Deleting the store
64
+ * reverts to plain `id` keying.
65
+ *
66
+ * ## Known gaps
67
+ *
68
+ * - A text-only assistant message has no anchor, so it still re-keys. No
69
+ * client-side correlation signal exists for it; the fix is stable ids
70
+ * upstream.
71
+ * - If the tool call's arrival and the id swap land in the same update, the
72
+ * intermediate state never renders, the anchor is never recorded, and the
73
+ * row is recreated as before. Correlating in the event-apply layer (i.e. in
74
+ * the AG-UI client, which observes every intermediate state) would be immune.
75
+ */
76
+ const TOOL_ANCHOR_PREFIX = "tc:";
77
+ function createRowKeyStore() {
78
+ return {
79
+ overrides: /* @__PURE__ */ new Map(),
80
+ ambiguous: /* @__PURE__ */ new Set()
81
+ };
82
+ }
83
+ /**
84
+ * Anchors a message contributes. Only assistant tool calls qualify: LangChain's
85
+ * id preference applies when merging `AIMessageChunk`s, so user message ids are
86
+ * not renamed, and `role: "tool"` messages are not rendered as rows. Every tool
87
+ * call is used (not just the first) so the anchor survives tool-call reordering
88
+ * between snapshots.
89
+ */
90
+ function toolAnchorsOf(message) {
91
+ if (message?.role !== "assistant") return [];
92
+ const toolCalls = message.toolCalls;
93
+ if (!toolCalls?.length) return [];
94
+ const anchors = [];
95
+ for (const toolCall of toolCalls) if (toolCall?.id) anchors.push(`${TOOL_ANCHOR_PREFIX}${toolCall.id}`);
96
+ return anchors;
97
+ }
98
+ /**
99
+ * Resolves the row key for every message, returned by position.
100
+ *
101
+ * Pure: it reads `store` and never writes to it. Every framework here may
102
+ * evaluate a render pass whose result never reaches the DOM — an abandoned
103
+ * concurrent render in React, a discarded `computed` evaluation in Vue or
104
+ * Angular. An anchor recorded by such a pass would vend its key to the pass
105
+ * that does render, re-keying the row the user is looking at, which is the
106
+ * teardown this module exists to prevent. Anchors are recorded by
107
+ * `commitRowKeyStore`, from whichever phase each framework runs after the DOM
108
+ * is updated.
109
+ *
110
+ * Uniqueness is structural rather than assumed: a caller that does not
111
+ * deduplicate can pass two rows with the same id, and an override can vend a
112
+ * key equal to a later message's own id.
113
+ */
114
+ function resolveRowRenderKeys(store, messages) {
115
+ const keys = [];
116
+ const claimed = /* @__PURE__ */ new Set();
117
+ messages.forEach((message, index) => {
118
+ const anchors = toolAnchorsOf(message);
119
+ let key;
120
+ for (const anchor of anchors) {
121
+ if (store.ambiguous.has(anchor)) continue;
122
+ const recorded = store.overrides.get(anchor);
123
+ if (recorded !== void 0 && !claimed.has(recorded)) {
124
+ key = recorded;
125
+ break;
126
+ }
127
+ }
128
+ key ??= message?.id || `index-${index}`;
129
+ if (claimed.has(key)) {
130
+ let suffix = 2;
131
+ while (claimed.has(`${key}:${suffix}`)) suffix += 1;
132
+ key = `${key}:${suffix}`;
133
+ }
134
+ keys.push(key);
135
+ claimed.add(key);
136
+ });
137
+ return keys;
138
+ }
139
+ /**
140
+ * `message.id` → row key, for callers that render by message rather than by
141
+ * position. `messages` must be deduplicated: duplicate ids would overwrite
142
+ * each other in the returned map.
143
+ */
144
+ function resolveRowRenderKeysById(store, messages) {
145
+ const keys = resolveRowRenderKeys(store, messages);
146
+ const byId = /* @__PURE__ */ new Map();
147
+ messages.forEach((message, index) => {
148
+ const key = keys[index];
149
+ if (key !== void 0) byId.set(message.id, key);
150
+ });
151
+ return byId;
152
+ }
153
+ /**
154
+ * Records the anchors of a rendered list, then bounds the store to it. Call
155
+ * from the phase that runs after the DOM is updated, never while resolving —
156
+ * see `resolveRowRenderKeys`.
157
+ *
158
+ * Re-resolving here reproduces the keys the rows were rendered with, because
159
+ * the store cannot change between a render and its own post-render phase.
160
+ *
161
+ * An anchor carried by two rows in the same list is marked ambiguous rather
162
+ * than recorded. Recording it would give the first row's key to whichever row
163
+ * outlived the other, and with it that row's DOM and component state.
164
+ */
165
+ function commitRowKeyStore(store, messages) {
166
+ const keys = resolveRowRenderKeys(store, messages);
167
+ const anchorCounts = /* @__PURE__ */ new Map();
168
+ for (const message of messages) for (const anchor of toolAnchorsOf(message)) anchorCounts.set(anchor, (anchorCounts.get(anchor) ?? 0) + 1);
169
+ store.ambiguous.clear();
170
+ for (const [anchor, count] of anchorCounts) if (count > 1) {
171
+ store.ambiguous.add(anchor);
172
+ store.overrides.delete(anchor);
173
+ }
174
+ messages.forEach((message, index) => {
175
+ const key = keys[index];
176
+ if (key === void 0) return;
177
+ for (const anchor of toolAnchorsOf(message)) {
178
+ if (store.ambiguous.has(anchor)) continue;
179
+ if (!store.overrides.has(anchor)) store.overrides.set(anchor, key);
180
+ }
181
+ });
182
+ pruneRowKeyStore(store, messages);
183
+ }
184
+ /**
185
+ * Drops anchors no longer present in `messages`, bounding the store to the
186
+ * tool calls of the currently-rendered messages. Called by
187
+ * `commitRowKeyStore`; like it, this writes to the store and so belongs after
188
+ * the DOM is updated, never while resolving.
189
+ *
190
+ * Pruned entries are unreachable by construction: `resolveRowRenderKeys` only
191
+ * looks up anchors belonging to messages in the list it is given.
192
+ */
193
+ function pruneRowKeyStore(store, messages) {
194
+ const live = /* @__PURE__ */ new Set();
195
+ for (const message of messages) for (const anchor of toolAnchorsOf(message)) live.add(anchor);
196
+ for (const anchor of store.overrides.keys()) if (!live.has(anchor)) store.overrides.delete(anchor);
197
+ for (const anchor of store.ambiguous) if (!live.has(anchor)) store.ambiguous.delete(anchor);
198
+ }
199
+
200
+ //#endregion
201
+ exports.commitRowKeyStore = commitRowKeyStore;
202
+ exports.createRowKeyStore = createRowKeyStore;
203
+ exports.pruneRowKeyStore = pruneRowKeyStore;
204
+ exports.resolveRowRenderKeys = resolveRowRenderKeys;
205
+ exports.resolveRowRenderKeysById = resolveRowRenderKeysById;
206
+ //# sourceMappingURL=row-render-keys.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"row-render-keys.cjs","names":[],"sources":["../../src/utils/row-render-keys.ts"],"sourcesContent":["import type { AssistantMessage, Message } from \"@ag-ui/core\";\n\n/**\n * Stable per-row view keys for chat transcripts, across backends that re-key a\n * message mid-stream. Shared by every frontend package, because the defect and\n * the correlation signal are in the message stream, not in any one framework.\n *\n * ## The problem\n *\n * A message's canonical `id` is not stable within a turn. LangChain stamps a\n * placeholder id on the first streamed chunk when the provider didn't supply\n * one (`chat_models.py`: `if chunk.message.id is None: chunk.message.id =\n * \"lc_run-\" + \"-\" + run_id`), then prefers any provider-assigned id it sees\n * while merging chunks (`messages/ai.py`, \"Ranks are defined by the order of\n * preference\"). The `MESSAGES_SNAPSHOT` therefore carries the provider's final\n * id (e.g. `resp_…`) for a message the client already knows as `lc_run--…`.\n *\n * Every framework destroys and recreates a row whose key changes, so keying\n * rows by `id` turned that swap into the visible HITL chat flash, where a\n * rendered approval card appears to reset during a tool's\n * `executing → complete` transition.\n *\n * This is provider-conditional: providers that stamp an id on every chunk (so\n * `chunk.message.id is None` never holds) never trigger a rename.\n *\n * ## The approach\n *\n * Tool-call ids survive the rename, so they are used as *anchors*: the first\n * message seen carrying a given tool call records the key it was assigned, and\n * any later message carrying that same tool call reuses it. The store is an\n * override table consulted before falling back to `message.id`. Resolving only\n * reads it; each render that reaches the DOM then records what it rendered:\n *\n * ```text\n * render 1 id=lc_run--1 no tools key = message.id = lc_run--1\n * commit 1 store {}\n * render 2 id=lc_run--1 tc call_A key = message.id = lc_run--1\n * commit 2 store { tc:call_A -> lc_run--1 }\n * render 3 id=resp_1 tc call_A key = store[tc:call_A]\n * = lc_run--1 (row survives)\n * commit 3 store unchanged\n * ```\n *\n * Recording the anchor at commit 2 — while the id is still stable — is what\n * makes render 3 resolvable. Note the fix does not depend on render 2\n * existing: a message born already carrying a tool call anchors on the first\n * render that commits it, under whatever id it holds then.\n *\n * ## Why an override table rather than keying rows by tool-call id\n *\n * Deriving the key from the tool call directly (`tc:<id>` whenever a tool call\n * is present) needs no state, but changes the key the moment a tool call\n * *appears* — so an assistant message that streams text and then calls a tool\n * is torn down on that transition, for every provider, whether or not it\n * renames. That trades a conditional flash for an unconditional one. Recording\n * an override keeps the key the row already had.\n *\n * ## Cost\n *\n * The store holds only `tc:<toolCallId>` entries, so a conversation with no\n * tool calls keeps an empty store and behaviour byte-identical to keying by\n * `id`. Size is bounded to the tool calls of the currently-rendered messages\n * (see `pruneRowKeyStore`), not the conversation length. Deleting the store\n * reverts to plain `id` keying.\n *\n * ## Known gaps\n *\n * - A text-only assistant message has no anchor, so it still re-keys. No\n * client-side correlation signal exists for it; the fix is stable ids\n * upstream.\n * - If the tool call's arrival and the id swap land in the same update, the\n * intermediate state never renders, the anchor is never recorded, and the\n * row is recreated as before. Correlating in the event-apply layer (i.e. in\n * the AG-UI client, which observes every intermediate state) would be immune.\n */\n\nconst TOOL_ANCHOR_PREFIX = \"tc:\";\n\nexport interface RowKeyStore {\n /**\n * `tc:<toolCallId>` → the row key first assigned to a message carrying that\n * tool call. Populated only for assistant messages that carry tool calls.\n */\n overrides: Map<string, string>;\n /**\n * Anchors carried by more than one message in the last rendered list. Such\n * an anchor identifies no single row, so it is never used to vend a key.\n */\n ambiguous: Set<string>;\n}\n\nexport function createRowKeyStore(): RowKeyStore {\n return { overrides: new Map(), ambiguous: new Set() };\n}\n\n/**\n * Anchors a message contributes. Only assistant tool calls qualify: LangChain's\n * id preference applies when merging `AIMessageChunk`s, so user message ids are\n * not renamed, and `role: \"tool\"` messages are not rendered as rows. Every tool\n * call is used (not just the first) so the anchor survives tool-call reordering\n * between snapshots.\n */\nfunction toolAnchorsOf(message: Message | undefined): string[] {\n if (message?.role !== \"assistant\") return [];\n const toolCalls = (message as AssistantMessage).toolCalls;\n if (!toolCalls?.length) return [];\n\n const anchors: string[] = [];\n for (const toolCall of toolCalls) {\n if (toolCall?.id) anchors.push(`${TOOL_ANCHOR_PREFIX}${toolCall.id}`);\n }\n return anchors;\n}\n\n/**\n * Resolves the row key for every message, returned by position.\n *\n * Pure: it reads `store` and never writes to it. Every framework here may\n * evaluate a render pass whose result never reaches the DOM — an abandoned\n * concurrent render in React, a discarded `computed` evaluation in Vue or\n * Angular. An anchor recorded by such a pass would vend its key to the pass\n * that does render, re-keying the row the user is looking at, which is the\n * teardown this module exists to prevent. Anchors are recorded by\n * `commitRowKeyStore`, from whichever phase each framework runs after the DOM\n * is updated.\n *\n * Uniqueness is structural rather than assumed: a caller that does not\n * deduplicate can pass two rows with the same id, and an override can vend a\n * key equal to a later message's own id.\n */\nexport function resolveRowRenderKeys(\n store: RowKeyStore,\n messages: readonly (Message | undefined)[],\n): string[] {\n const keys: string[] = [];\n const claimed = new Set<string>();\n\n messages.forEach((message, index) => {\n const anchors = toolAnchorsOf(message);\n\n // Reuse the key recorded for any of this message's anchors. An override\n // pointing at a key another row already claimed this pass is skipped: two\n // messages can share a tool-call id (upstream bug, or replayed state), and\n // the later one falls back to its own id instead.\n let key: string | undefined;\n for (const anchor of anchors) {\n if (store.ambiguous.has(anchor)) continue;\n const recorded = store.overrides.get(anchor);\n if (recorded !== undefined && !claimed.has(recorded)) {\n key = recorded;\n break;\n }\n }\n\n // The index fallback covers a message with no usable id.\n key ??= message?.id || `index-${index}`;\n\n if (claimed.has(key)) {\n let suffix = 2;\n while (claimed.has(`${key}:${suffix}`)) suffix += 1;\n key = `${key}:${suffix}`;\n }\n\n keys.push(key);\n claimed.add(key);\n });\n\n return keys;\n}\n\n/**\n * `message.id` → row key, for callers that render by message rather than by\n * position. `messages` must be deduplicated: duplicate ids would overwrite\n * each other in the returned map.\n */\nexport function resolveRowRenderKeysById(\n store: RowKeyStore,\n messages: readonly Message[],\n): Map<string, string> {\n const keys = resolveRowRenderKeys(store, messages);\n const byId = new Map<string, string>();\n messages.forEach((message, index) => {\n const key = keys[index];\n if (key !== undefined) byId.set(message.id, key);\n });\n return byId;\n}\n\n/**\n * Records the anchors of a rendered list, then bounds the store to it. Call\n * from the phase that runs after the DOM is updated, never while resolving —\n * see `resolveRowRenderKeys`.\n *\n * Re-resolving here reproduces the keys the rows were rendered with, because\n * the store cannot change between a render and its own post-render phase.\n *\n * An anchor carried by two rows in the same list is marked ambiguous rather\n * than recorded. Recording it would give the first row's key to whichever row\n * outlived the other, and with it that row's DOM and component state.\n */\nexport function commitRowKeyStore(\n store: RowKeyStore,\n messages: readonly (Message | undefined)[],\n): void {\n const keys = resolveRowRenderKeys(store, messages);\n\n const anchorCounts = new Map<string, number>();\n for (const message of messages) {\n for (const anchor of toolAnchorsOf(message)) {\n anchorCounts.set(anchor, (anchorCounts.get(anchor) ?? 0) + 1);\n }\n }\n\n // Ambiguity is a property of the rendered list, so it is recomputed rather\n // than accumulated: an anchor left alone by the row that shadowed it becomes\n // usable again.\n store.ambiguous.clear();\n for (const [anchor, count] of anchorCounts) {\n if (count > 1) {\n store.ambiguous.add(anchor);\n store.overrides.delete(anchor);\n }\n }\n\n // First claimant of an anchor owns it, so a re-keyed message resolves to the\n // key the row already had rather than overwriting it.\n messages.forEach((message, index) => {\n const key = keys[index];\n if (key === undefined) return;\n for (const anchor of toolAnchorsOf(message)) {\n if (store.ambiguous.has(anchor)) continue;\n if (!store.overrides.has(anchor)) store.overrides.set(anchor, key);\n }\n });\n\n pruneRowKeyStore(store, messages);\n}\n\n/**\n * Drops anchors no longer present in `messages`, bounding the store to the\n * tool calls of the currently-rendered messages. Called by\n * `commitRowKeyStore`; like it, this writes to the store and so belongs after\n * the DOM is updated, never while resolving.\n *\n * Pruned entries are unreachable by construction: `resolveRowRenderKeys` only\n * looks up anchors belonging to messages in the list it is given.\n */\nexport function pruneRowKeyStore(\n store: RowKeyStore,\n messages: readonly (Message | undefined)[],\n): void {\n const live = new Set<string>();\n for (const message of messages) {\n for (const anchor of toolAnchorsOf(message)) live.add(anchor);\n }\n\n for (const anchor of store.overrides.keys()) {\n if (!live.has(anchor)) store.overrides.delete(anchor);\n }\n for (const anchor of store.ambiguous) {\n if (!live.has(anchor)) store.ambiguous.delete(anchor);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EA,MAAM,qBAAqB;AAe3B,SAAgB,oBAAiC;AAC/C,QAAO;EAAE,2BAAW,IAAI,KAAK;EAAE,2BAAW,IAAI,KAAK;EAAE;;;;;;;;;AAUvD,SAAS,cAAc,SAAwC;AAC7D,KAAI,SAAS,SAAS,YAAa,QAAO,EAAE;CAC5C,MAAM,YAAa,QAA6B;AAChD,KAAI,CAAC,WAAW,OAAQ,QAAO,EAAE;CAEjC,MAAM,UAAoB,EAAE;AAC5B,MAAK,MAAM,YAAY,UACrB,KAAI,UAAU,GAAI,SAAQ,KAAK,GAAG,qBAAqB,SAAS,KAAK;AAEvE,QAAO;;;;;;;;;;;;;;;;;;AAmBT,SAAgB,qBACd,OACA,UACU;CACV,MAAM,OAAiB,EAAE;CACzB,MAAM,0BAAU,IAAI,KAAa;AAEjC,UAAS,SAAS,SAAS,UAAU;EACnC,MAAM,UAAU,cAAc,QAAQ;EAMtC,IAAI;AACJ,OAAK,MAAM,UAAU,SAAS;AAC5B,OAAI,MAAM,UAAU,IAAI,OAAO,CAAE;GACjC,MAAM,WAAW,MAAM,UAAU,IAAI,OAAO;AAC5C,OAAI,aAAa,UAAa,CAAC,QAAQ,IAAI,SAAS,EAAE;AACpD,UAAM;AACN;;;AAKJ,UAAQ,SAAS,MAAM,SAAS;AAEhC,MAAI,QAAQ,IAAI,IAAI,EAAE;GACpB,IAAI,SAAS;AACb,UAAO,QAAQ,IAAI,GAAG,IAAI,GAAG,SAAS,CAAE,WAAU;AAClD,SAAM,GAAG,IAAI,GAAG;;AAGlB,OAAK,KAAK,IAAI;AACd,UAAQ,IAAI,IAAI;GAChB;AAEF,QAAO;;;;;;;AAQT,SAAgB,yBACd,OACA,UACqB;CACrB,MAAM,OAAO,qBAAqB,OAAO,SAAS;CAClD,MAAM,uBAAO,IAAI,KAAqB;AACtC,UAAS,SAAS,SAAS,UAAU;EACnC,MAAM,MAAM,KAAK;AACjB,MAAI,QAAQ,OAAW,MAAK,IAAI,QAAQ,IAAI,IAAI;GAChD;AACF,QAAO;;;;;;;;;;;;;;AAeT,SAAgB,kBACd,OACA,UACM;CACN,MAAM,OAAO,qBAAqB,OAAO,SAAS;CAElD,MAAM,+BAAe,IAAI,KAAqB;AAC9C,MAAK,MAAM,WAAW,SACpB,MAAK,MAAM,UAAU,cAAc,QAAQ,CACzC,cAAa,IAAI,SAAS,aAAa,IAAI,OAAO,IAAI,KAAK,EAAE;AAOjE,OAAM,UAAU,OAAO;AACvB,MAAK,MAAM,CAAC,QAAQ,UAAU,aAC5B,KAAI,QAAQ,GAAG;AACb,QAAM,UAAU,IAAI,OAAO;AAC3B,QAAM,UAAU,OAAO,OAAO;;AAMlC,UAAS,SAAS,SAAS,UAAU;EACnC,MAAM,MAAM,KAAK;AACjB,MAAI,QAAQ,OAAW;AACvB,OAAK,MAAM,UAAU,cAAc,QAAQ,EAAE;AAC3C,OAAI,MAAM,UAAU,IAAI,OAAO,CAAE;AACjC,OAAI,CAAC,MAAM,UAAU,IAAI,OAAO,CAAE,OAAM,UAAU,IAAI,QAAQ,IAAI;;GAEpE;AAEF,kBAAiB,OAAO,SAAS;;;;;;;;;;;AAYnC,SAAgB,iBACd,OACA,UACM;CACN,MAAM,uBAAO,IAAI,KAAa;AAC9B,MAAK,MAAM,WAAW,SACpB,MAAK,MAAM,UAAU,cAAc,QAAQ,CAAE,MAAK,IAAI,OAAO;AAG/D,MAAK,MAAM,UAAU,MAAM,UAAU,MAAM,CACzC,KAAI,CAAC,KAAK,IAAI,OAAO,CAAE,OAAM,UAAU,OAAO,OAAO;AAEvD,MAAK,MAAM,UAAU,MAAM,UACzB,KAAI,CAAC,KAAK,IAAI,OAAO,CAAE,OAAM,UAAU,OAAO,OAAO"}
@@ -0,0 +1,65 @@
1
+ import { Message } from "@ag-ui/core";
2
+
3
+ //#region src/utils/row-render-keys.d.ts
4
+ interface RowKeyStore {
5
+ /**
6
+ * `tc:<toolCallId>` → the row key first assigned to a message carrying that
7
+ * tool call. Populated only for assistant messages that carry tool calls.
8
+ */
9
+ overrides: Map<string, string>;
10
+ /**
11
+ * Anchors carried by more than one message in the last rendered list. Such
12
+ * an anchor identifies no single row, so it is never used to vend a key.
13
+ */
14
+ ambiguous: Set<string>;
15
+ }
16
+ declare function createRowKeyStore(): RowKeyStore;
17
+ /**
18
+ * Resolves the row key for every message, returned by position.
19
+ *
20
+ * Pure: it reads `store` and never writes to it. Every framework here may
21
+ * evaluate a render pass whose result never reaches the DOM — an abandoned
22
+ * concurrent render in React, a discarded `computed` evaluation in Vue or
23
+ * Angular. An anchor recorded by such a pass would vend its key to the pass
24
+ * that does render, re-keying the row the user is looking at, which is the
25
+ * teardown this module exists to prevent. Anchors are recorded by
26
+ * `commitRowKeyStore`, from whichever phase each framework runs after the DOM
27
+ * is updated.
28
+ *
29
+ * Uniqueness is structural rather than assumed: a caller that does not
30
+ * deduplicate can pass two rows with the same id, and an override can vend a
31
+ * key equal to a later message's own id.
32
+ */
33
+ declare function resolveRowRenderKeys(store: RowKeyStore, messages: readonly (Message | undefined)[]): string[];
34
+ /**
35
+ * `message.id` → row key, for callers that render by message rather than by
36
+ * position. `messages` must be deduplicated: duplicate ids would overwrite
37
+ * each other in the returned map.
38
+ */
39
+ declare function resolveRowRenderKeysById(store: RowKeyStore, messages: readonly Message[]): Map<string, string>;
40
+ /**
41
+ * Records the anchors of a rendered list, then bounds the store to it. Call
42
+ * from the phase that runs after the DOM is updated, never while resolving —
43
+ * see `resolveRowRenderKeys`.
44
+ *
45
+ * Re-resolving here reproduces the keys the rows were rendered with, because
46
+ * the store cannot change between a render and its own post-render phase.
47
+ *
48
+ * An anchor carried by two rows in the same list is marked ambiguous rather
49
+ * than recorded. Recording it would give the first row's key to whichever row
50
+ * outlived the other, and with it that row's DOM and component state.
51
+ */
52
+ declare function commitRowKeyStore(store: RowKeyStore, messages: readonly (Message | undefined)[]): void;
53
+ /**
54
+ * Drops anchors no longer present in `messages`, bounding the store to the
55
+ * tool calls of the currently-rendered messages. Called by
56
+ * `commitRowKeyStore`; like it, this writes to the store and so belongs after
57
+ * the DOM is updated, never while resolving.
58
+ *
59
+ * Pruned entries are unreachable by construction: `resolveRowRenderKeys` only
60
+ * looks up anchors belonging to messages in the list it is given.
61
+ */
62
+ declare function pruneRowKeyStore(store: RowKeyStore, messages: readonly (Message | undefined)[]): void;
63
+ //#endregion
64
+ export { RowKeyStore, commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById };
65
+ //# sourceMappingURL=row-render-keys.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"row-render-keys.d.cts","names":[],"sources":["../../src/utils/row-render-keys.ts"],"mappings":";;;UA8EiB,WAAA;;AAAjB;;;EAKE,SAAA,EAAW,GAAA;EAAX;;;;EAKA,SAAA,EAAW,GAAA;AAAA;AAAA,iBAGG,iBAAA,CAAA,GAAqB,WAAA;;;;;AAuCrC;;;;;;;;;;AA6CA;;iBA7CgB,oBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,YAAoB,OAAA;;;;;;iBA2CN,wBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,WAAmB,OAAA,KAClB,GAAA;;;;;;;AAsBH;;;;;;iBAAgB,iBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,YAAoB,OAAA;;;;AA6CtB;;;;;;iBAAgB,gBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,YAAoB,OAAA"}
@@ -0,0 +1,65 @@
1
+ import { Message } from "@ag-ui/core";
2
+
3
+ //#region src/utils/row-render-keys.d.ts
4
+ interface RowKeyStore {
5
+ /**
6
+ * `tc:<toolCallId>` → the row key first assigned to a message carrying that
7
+ * tool call. Populated only for assistant messages that carry tool calls.
8
+ */
9
+ overrides: Map<string, string>;
10
+ /**
11
+ * Anchors carried by more than one message in the last rendered list. Such
12
+ * an anchor identifies no single row, so it is never used to vend a key.
13
+ */
14
+ ambiguous: Set<string>;
15
+ }
16
+ declare function createRowKeyStore(): RowKeyStore;
17
+ /**
18
+ * Resolves the row key for every message, returned by position.
19
+ *
20
+ * Pure: it reads `store` and never writes to it. Every framework here may
21
+ * evaluate a render pass whose result never reaches the DOM — an abandoned
22
+ * concurrent render in React, a discarded `computed` evaluation in Vue or
23
+ * Angular. An anchor recorded by such a pass would vend its key to the pass
24
+ * that does render, re-keying the row the user is looking at, which is the
25
+ * teardown this module exists to prevent. Anchors are recorded by
26
+ * `commitRowKeyStore`, from whichever phase each framework runs after the DOM
27
+ * is updated.
28
+ *
29
+ * Uniqueness is structural rather than assumed: a caller that does not
30
+ * deduplicate can pass two rows with the same id, and an override can vend a
31
+ * key equal to a later message's own id.
32
+ */
33
+ declare function resolveRowRenderKeys(store: RowKeyStore, messages: readonly (Message | undefined)[]): string[];
34
+ /**
35
+ * `message.id` → row key, for callers that render by message rather than by
36
+ * position. `messages` must be deduplicated: duplicate ids would overwrite
37
+ * each other in the returned map.
38
+ */
39
+ declare function resolveRowRenderKeysById(store: RowKeyStore, messages: readonly Message[]): Map<string, string>;
40
+ /**
41
+ * Records the anchors of a rendered list, then bounds the store to it. Call
42
+ * from the phase that runs after the DOM is updated, never while resolving —
43
+ * see `resolveRowRenderKeys`.
44
+ *
45
+ * Re-resolving here reproduces the keys the rows were rendered with, because
46
+ * the store cannot change between a render and its own post-render phase.
47
+ *
48
+ * An anchor carried by two rows in the same list is marked ambiguous rather
49
+ * than recorded. Recording it would give the first row's key to whichever row
50
+ * outlived the other, and with it that row's DOM and component state.
51
+ */
52
+ declare function commitRowKeyStore(store: RowKeyStore, messages: readonly (Message | undefined)[]): void;
53
+ /**
54
+ * Drops anchors no longer present in `messages`, bounding the store to the
55
+ * tool calls of the currently-rendered messages. Called by
56
+ * `commitRowKeyStore`; like it, this writes to the store and so belongs after
57
+ * the DOM is updated, never while resolving.
58
+ *
59
+ * Pruned entries are unreachable by construction: `resolveRowRenderKeys` only
60
+ * looks up anchors belonging to messages in the list it is given.
61
+ */
62
+ declare function pruneRowKeyStore(store: RowKeyStore, messages: readonly (Message | undefined)[]): void;
63
+ //#endregion
64
+ export { RowKeyStore, commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById };
65
+ //# sourceMappingURL=row-render-keys.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"row-render-keys.d.mts","names":[],"sources":["../../src/utils/row-render-keys.ts"],"mappings":";;;UA8EiB,WAAA;;AAAjB;;;EAKE,SAAA,EAAW,GAAA;EAAX;;;;EAKA,SAAA,EAAW,GAAA;AAAA;AAAA,iBAGG,iBAAA,CAAA,GAAqB,WAAA;;;;;AAuCrC;;;;;;;;;;AA6CA;;iBA7CgB,oBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,YAAoB,OAAA;;;;;;iBA2CN,wBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,WAAmB,OAAA,KAClB,GAAA;;;;;;;AAsBH;;;;;;iBAAgB,iBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,YAAoB,OAAA;;;;AA6CtB;;;;;;iBAAgB,gBAAA,CACd,KAAA,EAAO,WAAA,EACP,QAAA,YAAoB,OAAA"}
@@ -0,0 +1,201 @@
1
+ //#region src/utils/row-render-keys.ts
2
+ /**
3
+ * Stable per-row view keys for chat transcripts, across backends that re-key a
4
+ * message mid-stream. Shared by every frontend package, because the defect and
5
+ * the correlation signal are in the message stream, not in any one framework.
6
+ *
7
+ * ## The problem
8
+ *
9
+ * A message's canonical `id` is not stable within a turn. LangChain stamps a
10
+ * placeholder id on the first streamed chunk when the provider didn't supply
11
+ * one (`chat_models.py`: `if chunk.message.id is None: chunk.message.id =
12
+ * "lc_run-" + "-" + run_id`), then prefers any provider-assigned id it sees
13
+ * while merging chunks (`messages/ai.py`, "Ranks are defined by the order of
14
+ * preference"). The `MESSAGES_SNAPSHOT` therefore carries the provider's final
15
+ * id (e.g. `resp_…`) for a message the client already knows as `lc_run--…`.
16
+ *
17
+ * Every framework destroys and recreates a row whose key changes, so keying
18
+ * rows by `id` turned that swap into the visible HITL chat flash, where a
19
+ * rendered approval card appears to reset during a tool's
20
+ * `executing → complete` transition.
21
+ *
22
+ * This is provider-conditional: providers that stamp an id on every chunk (so
23
+ * `chunk.message.id is None` never holds) never trigger a rename.
24
+ *
25
+ * ## The approach
26
+ *
27
+ * Tool-call ids survive the rename, so they are used as *anchors*: the first
28
+ * message seen carrying a given tool call records the key it was assigned, and
29
+ * any later message carrying that same tool call reuses it. The store is an
30
+ * override table consulted before falling back to `message.id`. Resolving only
31
+ * reads it; each render that reaches the DOM then records what it rendered:
32
+ *
33
+ * ```text
34
+ * render 1 id=lc_run--1 no tools key = message.id = lc_run--1
35
+ * commit 1 store {}
36
+ * render 2 id=lc_run--1 tc call_A key = message.id = lc_run--1
37
+ * commit 2 store { tc:call_A -> lc_run--1 }
38
+ * render 3 id=resp_1 tc call_A key = store[tc:call_A]
39
+ * = lc_run--1 (row survives)
40
+ * commit 3 store unchanged
41
+ * ```
42
+ *
43
+ * Recording the anchor at commit 2 — while the id is still stable — is what
44
+ * makes render 3 resolvable. Note the fix does not depend on render 2
45
+ * existing: a message born already carrying a tool call anchors on the first
46
+ * render that commits it, under whatever id it holds then.
47
+ *
48
+ * ## Why an override table rather than keying rows by tool-call id
49
+ *
50
+ * Deriving the key from the tool call directly (`tc:<id>` whenever a tool call
51
+ * is present) needs no state, but changes the key the moment a tool call
52
+ * *appears* — so an assistant message that streams text and then calls a tool
53
+ * is torn down on that transition, for every provider, whether or not it
54
+ * renames. That trades a conditional flash for an unconditional one. Recording
55
+ * an override keeps the key the row already had.
56
+ *
57
+ * ## Cost
58
+ *
59
+ * The store holds only `tc:<toolCallId>` entries, so a conversation with no
60
+ * tool calls keeps an empty store and behaviour byte-identical to keying by
61
+ * `id`. Size is bounded to the tool calls of the currently-rendered messages
62
+ * (see `pruneRowKeyStore`), not the conversation length. Deleting the store
63
+ * reverts to plain `id` keying.
64
+ *
65
+ * ## Known gaps
66
+ *
67
+ * - A text-only assistant message has no anchor, so it still re-keys. No
68
+ * client-side correlation signal exists for it; the fix is stable ids
69
+ * upstream.
70
+ * - If the tool call's arrival and the id swap land in the same update, the
71
+ * intermediate state never renders, the anchor is never recorded, and the
72
+ * row is recreated as before. Correlating in the event-apply layer (i.e. in
73
+ * the AG-UI client, which observes every intermediate state) would be immune.
74
+ */
75
+ const TOOL_ANCHOR_PREFIX = "tc:";
76
+ function createRowKeyStore() {
77
+ return {
78
+ overrides: /* @__PURE__ */ new Map(),
79
+ ambiguous: /* @__PURE__ */ new Set()
80
+ };
81
+ }
82
+ /**
83
+ * Anchors a message contributes. Only assistant tool calls qualify: LangChain's
84
+ * id preference applies when merging `AIMessageChunk`s, so user message ids are
85
+ * not renamed, and `role: "tool"` messages are not rendered as rows. Every tool
86
+ * call is used (not just the first) so the anchor survives tool-call reordering
87
+ * between snapshots.
88
+ */
89
+ function toolAnchorsOf(message) {
90
+ if (message?.role !== "assistant") return [];
91
+ const toolCalls = message.toolCalls;
92
+ if (!toolCalls?.length) return [];
93
+ const anchors = [];
94
+ for (const toolCall of toolCalls) if (toolCall?.id) anchors.push(`${TOOL_ANCHOR_PREFIX}${toolCall.id}`);
95
+ return anchors;
96
+ }
97
+ /**
98
+ * Resolves the row key for every message, returned by position.
99
+ *
100
+ * Pure: it reads `store` and never writes to it. Every framework here may
101
+ * evaluate a render pass whose result never reaches the DOM — an abandoned
102
+ * concurrent render in React, a discarded `computed` evaluation in Vue or
103
+ * Angular. An anchor recorded by such a pass would vend its key to the pass
104
+ * that does render, re-keying the row the user is looking at, which is the
105
+ * teardown this module exists to prevent. Anchors are recorded by
106
+ * `commitRowKeyStore`, from whichever phase each framework runs after the DOM
107
+ * is updated.
108
+ *
109
+ * Uniqueness is structural rather than assumed: a caller that does not
110
+ * deduplicate can pass two rows with the same id, and an override can vend a
111
+ * key equal to a later message's own id.
112
+ */
113
+ function resolveRowRenderKeys(store, messages) {
114
+ const keys = [];
115
+ const claimed = /* @__PURE__ */ new Set();
116
+ messages.forEach((message, index) => {
117
+ const anchors = toolAnchorsOf(message);
118
+ let key;
119
+ for (const anchor of anchors) {
120
+ if (store.ambiguous.has(anchor)) continue;
121
+ const recorded = store.overrides.get(anchor);
122
+ if (recorded !== void 0 && !claimed.has(recorded)) {
123
+ key = recorded;
124
+ break;
125
+ }
126
+ }
127
+ key ??= message?.id || `index-${index}`;
128
+ if (claimed.has(key)) {
129
+ let suffix = 2;
130
+ while (claimed.has(`${key}:${suffix}`)) suffix += 1;
131
+ key = `${key}:${suffix}`;
132
+ }
133
+ keys.push(key);
134
+ claimed.add(key);
135
+ });
136
+ return keys;
137
+ }
138
+ /**
139
+ * `message.id` → row key, for callers that render by message rather than by
140
+ * position. `messages` must be deduplicated: duplicate ids would overwrite
141
+ * each other in the returned map.
142
+ */
143
+ function resolveRowRenderKeysById(store, messages) {
144
+ const keys = resolveRowRenderKeys(store, messages);
145
+ const byId = /* @__PURE__ */ new Map();
146
+ messages.forEach((message, index) => {
147
+ const key = keys[index];
148
+ if (key !== void 0) byId.set(message.id, key);
149
+ });
150
+ return byId;
151
+ }
152
+ /**
153
+ * Records the anchors of a rendered list, then bounds the store to it. Call
154
+ * from the phase that runs after the DOM is updated, never while resolving —
155
+ * see `resolveRowRenderKeys`.
156
+ *
157
+ * Re-resolving here reproduces the keys the rows were rendered with, because
158
+ * the store cannot change between a render and its own post-render phase.
159
+ *
160
+ * An anchor carried by two rows in the same list is marked ambiguous rather
161
+ * than recorded. Recording it would give the first row's key to whichever row
162
+ * outlived the other, and with it that row's DOM and component state.
163
+ */
164
+ function commitRowKeyStore(store, messages) {
165
+ const keys = resolveRowRenderKeys(store, messages);
166
+ const anchorCounts = /* @__PURE__ */ new Map();
167
+ for (const message of messages) for (const anchor of toolAnchorsOf(message)) anchorCounts.set(anchor, (anchorCounts.get(anchor) ?? 0) + 1);
168
+ store.ambiguous.clear();
169
+ for (const [anchor, count] of anchorCounts) if (count > 1) {
170
+ store.ambiguous.add(anchor);
171
+ store.overrides.delete(anchor);
172
+ }
173
+ messages.forEach((message, index) => {
174
+ const key = keys[index];
175
+ if (key === void 0) return;
176
+ for (const anchor of toolAnchorsOf(message)) {
177
+ if (store.ambiguous.has(anchor)) continue;
178
+ if (!store.overrides.has(anchor)) store.overrides.set(anchor, key);
179
+ }
180
+ });
181
+ pruneRowKeyStore(store, messages);
182
+ }
183
+ /**
184
+ * Drops anchors no longer present in `messages`, bounding the store to the
185
+ * tool calls of the currently-rendered messages. Called by
186
+ * `commitRowKeyStore`; like it, this writes to the store and so belongs after
187
+ * the DOM is updated, never while resolving.
188
+ *
189
+ * Pruned entries are unreachable by construction: `resolveRowRenderKeys` only
190
+ * looks up anchors belonging to messages in the list it is given.
191
+ */
192
+ function pruneRowKeyStore(store, messages) {
193
+ const live = /* @__PURE__ */ new Set();
194
+ for (const message of messages) for (const anchor of toolAnchorsOf(message)) live.add(anchor);
195
+ for (const anchor of store.overrides.keys()) if (!live.has(anchor)) store.overrides.delete(anchor);
196
+ for (const anchor of store.ambiguous) if (!live.has(anchor)) store.ambiguous.delete(anchor);
197
+ }
198
+
199
+ //#endregion
200
+ export { commitRowKeyStore, createRowKeyStore, pruneRowKeyStore, resolveRowRenderKeys, resolveRowRenderKeysById };
201
+ //# sourceMappingURL=row-render-keys.mjs.map