@athenaintel/react 0.43.0 → 0.50.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 (746) hide show
  1. package/README.md +258 -8
  2. package/dist/agent-runtime/src/answer-label.cjs +137 -0
  3. package/dist/agent-runtime/src/answer-label.cjs.map +1 -0
  4. package/dist/agent-runtime/src/answer-label.d.ts +104 -0
  5. package/dist/agent-runtime/src/answer-label.js +137 -0
  6. package/dist/agent-runtime/src/answer-label.js.map +1 -0
  7. package/dist/agent-runtime/src/answer-rows.cjs +180 -0
  8. package/dist/agent-runtime/src/answer-rows.cjs.map +1 -0
  9. package/dist/agent-runtime/src/answer-rows.d.ts +86 -0
  10. package/dist/agent-runtime/src/answer-rows.js +180 -0
  11. package/dist/agent-runtime/src/answer-rows.js.map +1 -0
  12. package/dist/agent-runtime/src/call-recap.cjs +319 -0
  13. package/dist/agent-runtime/src/call-recap.cjs.map +1 -0
  14. package/dist/agent-runtime/src/call-recap.d.ts +142 -0
  15. package/dist/agent-runtime/src/call-recap.js +319 -0
  16. package/dist/agent-runtime/src/call-recap.js.map +1 -0
  17. package/dist/agent-runtime/src/chat-outbox-store.cjs +1 -0
  18. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +1 -1
  19. package/dist/agent-runtime/src/chat-outbox-store.d.ts +7 -0
  20. package/dist/agent-runtime/src/chat-outbox-store.js +1 -0
  21. package/dist/agent-runtime/src/chat-outbox-store.js.map +1 -1
  22. package/dist/agent-runtime/src/chat-outbox.cjs +46 -5
  23. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -1
  24. package/dist/agent-runtime/src/chat-outbox.d.ts +29 -0
  25. package/dist/agent-runtime/src/chat-outbox.js +46 -5
  26. package/dist/agent-runtime/src/chat-outbox.js.map +1 -1
  27. package/dist/agent-runtime/src/client-tool-bridge.cjs +15 -15
  28. package/dist/agent-runtime/src/client-tool-bridge.cjs.map +1 -1
  29. package/dist/agent-runtime/src/conversation-index.cjs +8 -8
  30. package/dist/agent-runtime/src/conversation-index.cjs.map +1 -1
  31. package/dist/agent-runtime/src/conversation-index.d.ts +7 -0
  32. package/dist/agent-runtime/src/conversation-index.js.map +1 -1
  33. package/dist/agent-runtime/src/conversation-list.cjs +2 -1
  34. package/dist/agent-runtime/src/conversation-list.cjs.map +1 -1
  35. package/dist/agent-runtime/src/conversation-list.d.ts +19 -3
  36. package/dist/agent-runtime/src/conversation-list.js +2 -1
  37. package/dist/agent-runtime/src/conversation-list.js.map +1 -1
  38. package/dist/agent-runtime/src/decision-checks.cjs +207 -0
  39. package/dist/agent-runtime/src/decision-checks.cjs.map +1 -0
  40. package/dist/agent-runtime/src/decision-checks.d.ts +142 -0
  41. package/dist/agent-runtime/src/decision-checks.js +207 -0
  42. package/dist/agent-runtime/src/decision-checks.js.map +1 -0
  43. package/dist/agent-runtime/src/desktop-handoff.d.ts +12 -0
  44. package/dist/agent-runtime/src/errors.cjs +18 -0
  45. package/dist/agent-runtime/src/errors.cjs.map +1 -1
  46. package/dist/agent-runtime/src/errors.d.ts +7 -0
  47. package/dist/agent-runtime/src/errors.js +18 -0
  48. package/dist/agent-runtime/src/errors.js.map +1 -1
  49. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +12 -0
  50. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  51. package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +6 -6
  52. package/dist/agent-runtime/src/generated/runconfig-contract.js +12 -0
  53. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  54. package/dist/agent-runtime/src/handoff-arrival.cjs +60 -0
  55. package/dist/agent-runtime/src/handoff-arrival.cjs.map +1 -0
  56. package/dist/agent-runtime/src/handoff-arrival.d.ts +46 -0
  57. package/dist/agent-runtime/src/handoff-arrival.js +60 -0
  58. package/dist/agent-runtime/src/handoff-arrival.js.map +1 -0
  59. package/dist/agent-runtime/src/index.d.ts +16 -9
  60. package/dist/agent-runtime/src/interrupts.cjs +71 -19
  61. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  62. package/dist/agent-runtime/src/interrupts.d.ts +40 -3
  63. package/dist/agent-runtime/src/interrupts.js +56 -4
  64. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  65. package/dist/agent-runtime/src/lane-history.cjs +8 -8
  66. package/dist/agent-runtime/src/lane-history.cjs.map +1 -1
  67. package/dist/agent-runtime/src/messages.cjs +43 -8
  68. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  69. package/dist/agent-runtime/src/messages.d.ts +25 -3
  70. package/dist/agent-runtime/src/messages.js +43 -8
  71. package/dist/agent-runtime/src/messages.js.map +1 -1
  72. package/dist/agent-runtime/src/model-context.cjs +3 -2
  73. package/dist/agent-runtime/src/model-context.cjs.map +1 -1
  74. package/dist/agent-runtime/src/model-context.d.ts +6 -1
  75. package/dist/agent-runtime/src/model-context.js +3 -2
  76. package/dist/agent-runtime/src/model-context.js.map +1 -1
  77. package/dist/agent-runtime/src/offline-status.cjs +36 -0
  78. package/dist/agent-runtime/src/offline-status.cjs.map +1 -0
  79. package/dist/agent-runtime/src/offline-status.d.ts +118 -3
  80. package/dist/agent-runtime/src/offline-status.js +36 -0
  81. package/dist/agent-runtime/src/offline-status.js.map +1 -0
  82. package/dist/agent-runtime/src/queue.cjs +0 -9
  83. package/dist/agent-runtime/src/queue.cjs.map +1 -1
  84. package/dist/agent-runtime/src/queue.js +0 -9
  85. package/dist/agent-runtime/src/queue.js.map +1 -1
  86. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs +9 -9
  87. package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs.map +1 -1
  88. package/dist/agent-runtime/src/runtime-catalog.cjs +42 -0
  89. package/dist/agent-runtime/src/runtime-catalog.cjs.map +1 -0
  90. package/dist/agent-runtime/src/runtime-catalog.d.ts +35 -0
  91. package/dist/agent-runtime/src/runtime-catalog.js +42 -0
  92. package/dist/agent-runtime/src/runtime-catalog.js.map +1 -0
  93. package/dist/agent-runtime/src/runtime-messages.cjs.map +1 -1
  94. package/dist/agent-runtime/src/runtime-messages.d.ts +1 -1
  95. package/dist/agent-runtime/src/runtime-messages.js.map +1 -1
  96. package/dist/agent-runtime/src/runtime.d.ts +41 -0
  97. package/dist/agent-runtime/src/send-recovery.cjs +37 -3
  98. package/dist/agent-runtime/src/send-recovery.cjs.map +1 -1
  99. package/dist/agent-runtime/src/send-recovery.d.ts +19 -0
  100. package/dist/agent-runtime/src/send-recovery.js +37 -3
  101. package/dist/agent-runtime/src/send-recovery.js.map +1 -1
  102. package/dist/agent-runtime/src/statewire-suspended.cjs +3 -3
  103. package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
  104. package/dist/agent-runtime/src/subagents.cjs +32 -2
  105. package/dist/agent-runtime/src/subagents.cjs.map +1 -1
  106. package/dist/agent-runtime/src/subagents.d.ts +9 -0
  107. package/dist/agent-runtime/src/subagents.js +30 -0
  108. package/dist/agent-runtime/src/subagents.js.map +1 -1
  109. package/dist/agent-runtime/src/thread-driver.cjs +67 -0
  110. package/dist/agent-runtime/src/thread-driver.cjs.map +1 -0
  111. package/dist/agent-runtime/src/thread-driver.d.ts +49 -0
  112. package/dist/agent-runtime/src/thread-driver.js +67 -0
  113. package/dist/agent-runtime/src/thread-driver.js.map +1 -0
  114. package/dist/agent-runtime/src/thread-handoff-flow-machine.d.ts +172 -0
  115. package/dist/agent-runtime/src/thread-handoff-protocol.d.ts +868 -0
  116. package/dist/agent-runtime/src/thread-handoff-qr.d.ts +11 -0
  117. package/dist/agent-runtime/src/thread-handoff.d.ts +3 -364
  118. package/dist/agent-runtime/src/thread-status.cjs +3 -3
  119. package/dist/agent-runtime/src/thread-status.cjs.map +1 -1
  120. package/dist/agent-runtime/src/tool-metadata.cjs +210 -25
  121. package/dist/agent-runtime/src/tool-metadata.cjs.map +1 -1
  122. package/dist/agent-runtime/src/tool-metadata.d.ts +12 -0
  123. package/dist/agent-runtime/src/tool-metadata.js +210 -25
  124. package/dist/agent-runtime/src/tool-metadata.js.map +1 -1
  125. package/dist/agent-runtime/src/tool-names.cjs +2 -0
  126. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  127. package/dist/agent-runtime/src/tool-names.d.ts +2 -0
  128. package/dist/agent-runtime/src/tool-names.js +2 -0
  129. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  130. package/dist/agent-runtime/src/types.d.ts +10 -2
  131. package/dist/agent-runtime/src/use-conversation-list.cjs +14 -13
  132. package/dist/agent-runtime/src/use-conversation-list.cjs.map +1 -1
  133. package/dist/agent-runtime/src/use-conversation-list.d.ts +6 -0
  134. package/dist/agent-runtime/src/use-conversation-list.js +3 -2
  135. package/dist/agent-runtime/src/use-conversation-list.js.map +1 -1
  136. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +45 -20
  137. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -1
  138. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +10 -3
  139. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +27 -2
  140. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -1
  141. package/dist/agent-runtime/src/use-deep-agent-config.cjs +14 -14
  142. package/dist/agent-runtime/src/use-deep-agent-config.cjs.map +1 -1
  143. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +6 -6
  144. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
  145. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +40 -22
  146. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  147. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +17 -0
  148. package/dist/agent-runtime/src/use-deep-agent-runtime.js +24 -6
  149. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  150. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +45 -45
  151. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  152. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +588 -130
  153. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -1
  154. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +162 -10
  155. package/dist/agent-runtime/src/use-deep-agent-voice.js +529 -71
  156. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -1
  157. package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs +26 -26
  158. package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs.map +1 -1
  159. package/dist/agent-runtime/src/use-historical-edit-attachments.cjs +4 -4
  160. package/dist/agent-runtime/src/use-historical-edit-attachments.cjs.map +1 -1
  161. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +34 -26
  162. package/dist/agent-runtime/src/voice-earcon.cjs +139 -0
  163. package/dist/agent-runtime/src/voice-earcon.cjs.map +1 -0
  164. package/dist/agent-runtime/src/voice-earcon.d.ts +38 -0
  165. package/dist/agent-runtime/src/voice-earcon.js +139 -0
  166. package/dist/agent-runtime/src/voice-earcon.js.map +1 -0
  167. package/dist/agent-runtime/src/voice-media.cjs +117 -0
  168. package/dist/agent-runtime/src/voice-media.cjs.map +1 -0
  169. package/dist/agent-runtime/src/voice-media.d.ts +63 -0
  170. package/dist/agent-runtime/src/voice-media.js +117 -0
  171. package/dist/agent-runtime/src/voice-media.js.map +1 -0
  172. package/dist/agent-runtime/src/voice-presentation.cjs +2 -0
  173. package/dist/agent-runtime/src/voice-presentation.cjs.map +1 -1
  174. package/dist/agent-runtime/src/voice-presentation.js +2 -0
  175. package/dist/agent-runtime/src/voice-presentation.js.map +1 -1
  176. package/dist/agent-runtime/src/voice-wire-types.d.ts +32 -0
  177. package/dist/assets/AssetPanel.cjs +11 -11
  178. package/dist/assets/AssetPanel.cjs.map +1 -1
  179. package/dist/assets/AthenaAssetEmbed.cjs +11 -9
  180. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  181. package/dist/assets/AthenaAssetEmbed.d.ts +18 -5
  182. package/dist/assets/AthenaAssetEmbed.js +4 -2
  183. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  184. package/dist/assets/AthenaLayout.cjs +16 -16
  185. package/dist/assets/AthenaLayout.cjs.map +1 -1
  186. package/dist/assets/use-asset-content.cjs +4 -4
  187. package/dist/assets/use-asset-content.cjs.map +1 -1
  188. package/dist/assets/use-asset-embed.cjs +14 -7
  189. package/dist/assets/use-asset-embed.cjs.map +1 -1
  190. package/dist/assets/use-asset-embed.d.ts +23 -6
  191. package/dist/assets/use-asset-embed.js +10 -3
  192. package/dist/assets/use-asset-embed.js.map +1 -1
  193. package/dist/auth/AthenaAuthContext.cjs +3 -3
  194. package/dist/auth/AthenaAuthContext.cjs.map +1 -1
  195. package/dist/auth/AthenaAuthProvider.cjs +8 -8
  196. package/dist/auth/AthenaAuthProvider.cjs.map +1 -1
  197. package/dist/auth/AthenaCredentialSourceContext.cjs +5 -5
  198. package/dist/auth/AthenaCredentialSourceContext.cjs.map +1 -1
  199. package/dist/auth/AthenaSSOProvider.cjs +14 -14
  200. package/dist/auth/AthenaSSOProvider.cjs.map +1 -1
  201. package/dist/auth/credential-source.cjs +26 -13
  202. package/dist/auth/credential-source.cjs.map +1 -1
  203. package/dist/auth/credential-source.d.ts +8 -0
  204. package/dist/auth/credential-source.js +26 -13
  205. package/dist/auth/credential-source.js.map +1 -1
  206. package/dist/catalog/agent-model-options.cjs +25 -17
  207. package/dist/catalog/agent-model-options.cjs.map +1 -1
  208. package/dist/catalog/agent-model-options.d.ts +38 -5
  209. package/dist/catalog/agent-model-options.js +25 -17
  210. package/dist/catalog/agent-model-options.js.map +1 -1
  211. package/dist/catalog/channel-refusal.cjs +36 -0
  212. package/dist/catalog/channel-refusal.cjs.map +1 -0
  213. package/dist/catalog/channel-refusal.d.ts +29 -0
  214. package/dist/catalog/channel-refusal.js +36 -0
  215. package/dist/catalog/channel-refusal.js.map +1 -0
  216. package/dist/catalog/chat-pickers.cjs +60 -24
  217. package/dist/catalog/chat-pickers.cjs.map +1 -1
  218. package/dist/catalog/chat-pickers.d.ts +12 -2
  219. package/dist/catalog/chat-pickers.js +56 -20
  220. package/dist/catalog/chat-pickers.js.map +1 -1
  221. package/dist/catalog/runtime-catalog.cjs +89 -23
  222. package/dist/catalog/runtime-catalog.cjs.map +1 -1
  223. package/dist/catalog/runtime-catalog.d.ts +8 -2
  224. package/dist/catalog/runtime-catalog.js +83 -17
  225. package/dist/catalog/runtime-catalog.js.map +1 -1
  226. package/dist/catalog/use-athena-chat-mode.cjs +12 -12
  227. package/dist/catalog/use-athena-chat-mode.cjs.map +1 -1
  228. package/dist/chat/AthenaChat.cjs +155 -67
  229. package/dist/chat/AthenaChat.cjs.map +1 -1
  230. package/dist/chat/AthenaChat.d.ts +42 -2
  231. package/dist/chat/AthenaChat.js +106 -18
  232. package/dist/chat/AthenaChat.js.map +1 -1
  233. package/dist/chat/AthenaChatErrorBoundary.cjs +3 -3
  234. package/dist/chat/AthenaChatErrorBoundary.cjs.map +1 -1
  235. package/dist/chat/DrivingOnChip.cjs +23 -0
  236. package/dist/chat/DrivingOnChip.cjs.map +1 -0
  237. package/dist/chat/DrivingOnChip.d.ts +17 -0
  238. package/dist/chat/DrivingOnChip.js +23 -0
  239. package/dist/chat/DrivingOnChip.js.map +1 -0
  240. package/dist/chat/StatewireApprovalCard.cjs +166 -37
  241. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  242. package/dist/chat/StatewireApprovalCard.d.ts +91 -2
  243. package/dist/chat/StatewireApprovalCard.js +156 -27
  244. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  245. package/dist/chat/StatewireClientToolBridge.cjs +2 -2
  246. package/dist/chat/StatewireClientToolBridge.cjs.map +1 -1
  247. package/dist/chat/StatewireQueuedMessages.cjs +81 -69
  248. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  249. package/dist/chat/StatewireQueuedMessages.d.ts +25 -13
  250. package/dist/chat/StatewireQueuedMessages.js +73 -61
  251. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  252. package/dist/chat/WaitingOnYouBanner.cjs +9 -5
  253. package/dist/chat/WaitingOnYouBanner.cjs.map +1 -1
  254. package/dist/chat/WaitingOnYouBanner.js +7 -3
  255. package/dist/chat/WaitingOnYouBanner.js.map +1 -1
  256. package/dist/chat/athena-chat-welcome.cjs +2 -2
  257. package/dist/chat/athena-chat-welcome.cjs.map +1 -1
  258. package/dist/chat/athena-citation-links.cjs +5 -5
  259. package/dist/chat/athena-citation-links.cjs.map +1 -1
  260. package/dist/chat/athena-composer-controls.cjs +26 -16
  261. package/dist/chat/athena-composer-controls.cjs.map +1 -1
  262. package/dist/chat/athena-composer-controls.d.ts +6 -0
  263. package/dist/chat/athena-composer-controls.js +26 -16
  264. package/dist/chat/athena-composer-controls.js.map +1 -1
  265. package/dist/chat/athena-turn-end-status.cjs +42 -0
  266. package/dist/chat/athena-turn-end-status.cjs.map +1 -0
  267. package/dist/chat/athena-turn-end-status.d.ts +24 -0
  268. package/dist/chat/athena-turn-end-status.js +42 -0
  269. package/dist/chat/athena-turn-end-status.js.map +1 -0
  270. package/dist/chat/browser-decision-check.cjs +131 -0
  271. package/dist/chat/browser-decision-check.cjs.map +1 -0
  272. package/dist/chat/browser-decision-check.d.ts +61 -0
  273. package/dist/chat/browser-decision-check.js +131 -0
  274. package/dist/chat/browser-decision-check.js.map +1 -0
  275. package/dist/chat/chat-outbox-rows.cjs +3 -3
  276. package/dist/chat/chat-outbox-rows.cjs.map +1 -1
  277. package/dist/chat/chat-voice-controls.cjs +96 -29
  278. package/dist/chat/chat-voice-controls.cjs.map +1 -1
  279. package/dist/chat/chat-voice-controls.d.ts +42 -3
  280. package/dist/chat/chat-voice-controls.js +92 -25
  281. package/dist/chat/chat-voice-controls.js.map +1 -1
  282. package/dist/chat/composer-keyboard-hint.cjs +5 -5
  283. package/dist/chat/composer-keyboard-hint.cjs.map +1 -1
  284. package/dist/chat/device-operation.cjs +29 -0
  285. package/dist/chat/device-operation.cjs.map +1 -0
  286. package/dist/chat/device-operation.d.ts +34 -0
  287. package/dist/chat/device-operation.js +29 -0
  288. package/dist/chat/device-operation.js.map +1 -0
  289. package/dist/chat/super-grouping/CollapsibleGroup.cjs +14 -14
  290. package/dist/chat/super-grouping/CollapsibleGroup.cjs.map +1 -1
  291. package/dist/chat/super-grouping/GroupedMessageParts.cjs +4 -4
  292. package/dist/chat/super-grouping/GroupedMessageParts.cjs.map +1 -1
  293. package/dist/chat/super-grouping/SuperGroupingCard.cjs +52 -36
  294. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  295. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +19 -4
  296. package/dist/chat/super-grouping/SuperGroupingCard.js +29 -13
  297. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  298. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +32 -32
  299. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  300. package/dist/chat/super-grouping/SuperGroupingTranscript.js +3 -3
  301. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  302. package/dist/chat/super-grouping/ToolTimeline.cjs +73 -40
  303. package/dist/chat/super-grouping/ToolTimeline.cjs.map +1 -1
  304. package/dist/chat/super-grouping/ToolTimeline.d.ts +10 -2
  305. package/dist/chat/super-grouping/ToolTimeline.js +69 -36
  306. package/dist/chat/super-grouping/ToolTimeline.js.map +1 -1
  307. package/dist/chat/super-grouping/activity-timeline.cjs +47 -12
  308. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  309. package/dist/chat/super-grouping/activity-timeline.d.ts +21 -0
  310. package/dist/chat/super-grouping/activity-timeline.js +47 -12
  311. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  312. package/dist/chat/super-grouping/grouping-function.cjs +4 -0
  313. package/dist/chat/super-grouping/grouping-function.cjs.map +1 -1
  314. package/dist/chat/super-grouping/grouping-function.d.ts +7 -0
  315. package/dist/chat/super-grouping/grouping-function.js +5 -1
  316. package/dist/chat/super-grouping/grouping-function.js.map +1 -1
  317. package/dist/chat/super-grouping/index.cjs +6 -0
  318. package/dist/chat/super-grouping/index.cjs.map +1 -1
  319. package/dist/chat/super-grouping/index.d.ts +5 -2
  320. package/dist/chat/super-grouping/index.js +7 -1
  321. package/dist/chat/super-grouping/index.js.map +1 -1
  322. package/dist/chat/super-grouping/tool-part-placement.cjs +17 -0
  323. package/dist/chat/super-grouping/tool-part-placement.cjs.map +1 -0
  324. package/dist/chat/super-grouping/tool-part-placement.d.ts +22 -0
  325. package/dist/chat/super-grouping/tool-part-placement.js +17 -0
  326. package/dist/chat/super-grouping/tool-part-placement.js.map +1 -0
  327. package/dist/chat/thread-scroll-to-bottom.cjs +2 -2
  328. package/dist/chat/thread-scroll-to-bottom.cjs.map +1 -1
  329. package/dist/chat/thread-scroll-to-bottom.d.ts +10 -7
  330. package/dist/chat/thread-scroll-to-bottom.js +2 -2
  331. package/dist/chat/thread-scroll-to-bottom.js.map +1 -1
  332. package/dist/chat/tooltip-icon-button.cjs +2 -2
  333. package/dist/chat/tooltip-icon-button.cjs.map +1 -1
  334. package/dist/chat/use-athena-voice-live.cjs +11 -0
  335. package/dist/chat/use-athena-voice-live.cjs.map +1 -0
  336. package/dist/chat/use-athena-voice-live.d.ts +11 -0
  337. package/dist/chat/use-athena-voice-live.js +11 -0
  338. package/dist/chat/use-athena-voice-live.js.map +1 -0
  339. package/dist/chat/use-statewire-approval-request.cjs +56 -24
  340. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  341. package/dist/chat/use-statewire-approval-request.d.ts +33 -4
  342. package/dist/chat/use-statewire-approval-request.js +41 -9
  343. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  344. package/dist/chat-ui/auth/sign-in-card.cjs +2 -2
  345. package/dist/chat-ui/auth/sign-in-card.cjs.map +1 -1
  346. package/dist/chat-ui/composer/tiptap-composer.cjs +138 -107
  347. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  348. package/dist/chat-ui/composer/tiptap-composer.d.ts +20 -4
  349. package/dist/chat-ui/composer/tiptap-composer.js +85 -54
  350. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  351. package/dist/chat-ui/header/conversation-history-panel.cjs +49 -23
  352. package/dist/chat-ui/header/conversation-history-panel.cjs.map +1 -1
  353. package/dist/chat-ui/header/conversation-history-panel.d.ts +12 -1
  354. package/dist/chat-ui/header/conversation-history-panel.js +38 -12
  355. package/dist/chat-ui/header/conversation-history-panel.js.map +1 -1
  356. package/dist/chat-ui/index.cjs +21 -0
  357. package/dist/chat-ui/index.cjs.map +1 -1
  358. package/dist/chat-ui/index.d.ts +8 -1
  359. package/dist/chat-ui/index.js +21 -0
  360. package/dist/chat-ui/index.js.map +1 -1
  361. package/dist/chat-ui/mentions/mention-chip.cjs +4 -4
  362. package/dist/chat-ui/mentions/mention-chip.cjs.map +1 -1
  363. package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.cjs +10 -9
  364. package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.cjs.map +1 -1
  365. package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.js +3 -2
  366. package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.js.map +1 -1
  367. package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-popup.cjs +2 -2
  368. package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-popup.cjs.map +1 -1
  369. package/dist/chat-ui/mentions/suggestions/components/menu-list.cjs +29 -6
  370. package/dist/chat-ui/mentions/suggestions/components/menu-list.cjs.map +1 -1
  371. package/dist/chat-ui/mentions/suggestions/components/menu-list.d.ts +7 -1
  372. package/dist/chat-ui/mentions/suggestions/components/menu-list.js +25 -2
  373. package/dist/chat-ui/mentions/suggestions/components/menu-list.js.map +1 -1
  374. package/dist/chat-ui/mentions/suggestions/components/use-keyboard-navigation.cjs +2 -2
  375. package/dist/chat-ui/mentions/suggestions/components/use-keyboard-navigation.cjs.map +1 -1
  376. package/dist/chat-ui/mentions/suggestions/components/use-menu-navigation.cjs +2 -2
  377. package/dist/chat-ui/mentions/suggestions/components/use-menu-navigation.cjs.map +1 -1
  378. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs +3 -3
  379. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs.map +1 -1
  380. package/dist/chat-ui/mentions/suggestions/data/orchestrator.cjs +56 -2
  381. package/dist/chat-ui/mentions/suggestions/data/orchestrator.cjs.map +1 -1
  382. package/dist/chat-ui/mentions/suggestions/data/orchestrator.d.ts +12 -0
  383. package/dist/chat-ui/mentions/suggestions/data/orchestrator.js +56 -2
  384. package/dist/chat-ui/mentions/suggestions/data/orchestrator.js.map +1 -1
  385. package/dist/chat-ui/mentions/suggestions/data/sources/index.cjs +24 -3
  386. package/dist/chat-ui/mentions/suggestions/data/sources/index.cjs.map +1 -1
  387. package/dist/chat-ui/mentions/suggestions/data/sources/index.d.ts +7 -0
  388. package/dist/chat-ui/mentions/suggestions/data/sources/index.js +24 -3
  389. package/dist/chat-ui/mentions/suggestions/data/sources/index.js.map +1 -1
  390. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.cjs +35 -13
  391. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.cjs.map +1 -1
  392. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.d.ts +15 -1
  393. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.js +28 -6
  394. package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.js.map +1 -1
  395. package/dist/chat-ui/mentions/suggestions/data/use-menu-items.cjs +9 -6
  396. package/dist/chat-ui/mentions/suggestions/data/use-menu-items.cjs.map +1 -1
  397. package/dist/chat-ui/mentions/suggestions/data/use-menu-items.d.ts +3 -0
  398. package/dist/chat-ui/mentions/suggestions/data/use-menu-items.js +5 -2
  399. package/dist/chat-ui/mentions/suggestions/data/use-menu-items.js.map +1 -1
  400. package/dist/chat-ui/mentions/use-account-workspace-id.cjs +45 -10
  401. package/dist/chat-ui/mentions/use-account-workspace-id.cjs.map +1 -1
  402. package/dist/chat-ui/mentions/use-account-workspace-id.d.ts +24 -1
  403. package/dist/chat-ui/mentions/use-account-workspace-id.js +46 -11
  404. package/dist/chat-ui/mentions/use-account-workspace-id.js.map +1 -1
  405. package/dist/chat-ui/mentions/use-member-avatar.cjs +4 -4
  406. package/dist/chat-ui/mentions/use-member-avatar.cjs.map +1 -1
  407. package/dist/chat-ui/mentions/use-mention-asset.cjs +3 -3
  408. package/dist/chat-ui/mentions/use-mention-asset.cjs.map +1 -1
  409. package/dist/chat-ui/messages/answer-label.cjs +42 -0
  410. package/dist/chat-ui/messages/answer-label.cjs.map +1 -0
  411. package/dist/chat-ui/messages/answer-label.d.ts +33 -0
  412. package/dist/chat-ui/messages/answer-label.js +42 -0
  413. package/dist/chat-ui/messages/answer-label.js.map +1 -0
  414. package/dist/chat-ui/messages/arrival-animation.cjs +13 -0
  415. package/dist/chat-ui/messages/arrival-animation.cjs.map +1 -0
  416. package/dist/chat-ui/messages/arrival-animation.d.ts +14 -0
  417. package/dist/chat-ui/messages/arrival-animation.js +13 -0
  418. package/dist/chat-ui/messages/arrival-animation.js.map +1 -0
  419. package/dist/chat-ui/messages/continue-pill.cjs +5 -5
  420. package/dist/chat-ui/messages/continue-pill.cjs.map +1 -1
  421. package/dist/chat-ui/messages/from-the-call-card.cjs +124 -0
  422. package/dist/chat-ui/messages/from-the-call-card.cjs.map +1 -0
  423. package/dist/chat-ui/messages/from-the-call-card.d.ts +17 -0
  424. package/dist/chat-ui/messages/from-the-call-card.js +124 -0
  425. package/dist/chat-ui/messages/from-the-call-card.js.map +1 -0
  426. package/dist/chat-ui/messages/handoff-arrival-divider.cjs +44 -0
  427. package/dist/chat-ui/messages/handoff-arrival-divider.cjs.map +1 -0
  428. package/dist/chat-ui/messages/handoff-arrival-divider.d.ts +17 -0
  429. package/dist/chat-ui/messages/handoff-arrival-divider.js +44 -0
  430. package/dist/chat-ui/messages/handoff-arrival-divider.js.map +1 -0
  431. package/dist/chat-ui/messages/message-actions-config.cjs +3 -3
  432. package/dist/chat-ui/messages/message-actions-config.cjs.map +1 -1
  433. package/dist/chat-ui/messages/message-components.cjs +8 -4
  434. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  435. package/dist/chat-ui/messages/message-components.js +5 -1
  436. package/dist/chat-ui/messages/message-components.js.map +1 -1
  437. package/dist/chat-ui/messages/message-images.cjs +66 -0
  438. package/dist/chat-ui/messages/message-images.cjs.map +1 -0
  439. package/dist/chat-ui/messages/message-images.d.ts +16 -0
  440. package/dist/chat-ui/messages/message-images.js +66 -0
  441. package/dist/chat-ui/messages/message-images.js.map +1 -0
  442. package/dist/chat-ui/messages/user-edit-composer.cjs +2 -2
  443. package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
  444. package/dist/chat-ui/messages/wake-marker.cjs +3 -3
  445. package/dist/chat-ui/messages/wake-marker.cjs.map +1 -1
  446. package/dist/chat-ui/rich-text/chat-link.cjs +3 -2
  447. package/dist/chat-ui/rich-text/chat-link.cjs.map +1 -1
  448. package/dist/chat-ui/rich-text/chat-link.d.ts +4 -0
  449. package/dist/chat-ui/rich-text/chat-link.js +4 -3
  450. package/dist/chat-ui/rich-text/chat-link.js.map +1 -1
  451. package/dist/chat-ui/rich-text/chat-message-body.cjs +9 -8
  452. package/dist/chat-ui/rich-text/chat-message-body.cjs.map +1 -1
  453. package/dist/chat-ui/rich-text/chat-message-body.d.ts +12 -0
  454. package/dist/chat-ui/rich-text/chat-message-body.js +2 -1
  455. package/dist/chat-ui/rich-text/chat-message-body.js.map +1 -1
  456. package/dist/chat-ui/rich-text/chat-node-views.cjs +6 -6
  457. package/dist/chat-ui/rich-text/chat-node-views.cjs.map +1 -1
  458. package/dist/chat-ui/rich-text/dom-output-spec.cjs +2 -2
  459. package/dist/chat-ui/rich-text/dom-output-spec.cjs.map +1 -1
  460. package/dist/chat-ui/statewire.cjs +3 -0
  461. package/dist/chat-ui/statewire.cjs.map +1 -1
  462. package/dist/chat-ui/statewire.d.ts +2 -1
  463. package/dist/chat-ui/statewire.js +3 -0
  464. package/dist/chat-ui/statewire.js.map +1 -1
  465. package/dist/chat-ui/thread/chat-thread-shell.cjs +45 -14
  466. package/dist/chat-ui/thread/chat-thread-shell.cjs.map +1 -1
  467. package/dist/chat-ui/thread/chat-thread-shell.d.ts +16 -2
  468. package/dist/chat-ui/thread/chat-thread-shell.js +37 -6
  469. package/dist/chat-ui/thread/chat-thread-shell.js.map +1 -1
  470. package/dist/chat-ui/thread/composer-send-or-stop.cjs +30 -20
  471. package/dist/chat-ui/thread/composer-send-or-stop.cjs.map +1 -1
  472. package/dist/chat-ui/thread/composer-send-or-stop.d.ts +8 -0
  473. package/dist/chat-ui/thread/composer-send-or-stop.js +29 -19
  474. package/dist/chat-ui/thread/composer-send-or-stop.js.map +1 -1
  475. package/dist/chat-ui/thread/statewire-history-edge.cjs +20 -21
  476. package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
  477. package/dist/chat-ui/thread/statewire-history-edge.js +3 -4
  478. package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
  479. package/dist/chat-ui/thread/thread-loading-overlay.cjs +5 -5
  480. package/dist/chat-ui/thread/thread-loading-overlay.cjs.map +1 -1
  481. package/dist/collab/client.cjs +52 -3
  482. package/dist/collab/client.cjs.map +1 -1
  483. package/dist/collab/client.d.ts +27 -0
  484. package/dist/collab/client.js +52 -3
  485. package/dist/collab/client.js.map +1 -1
  486. package/dist/collab/document-status.cjs +150 -0
  487. package/dist/collab/document-status.cjs.map +1 -0
  488. package/dist/collab/document-status.d.ts +68 -0
  489. package/dist/collab/document-status.js +150 -0
  490. package/dist/collab/document-status.js.map +1 -0
  491. package/dist/collab/index.cjs +7 -0
  492. package/dist/collab/index.cjs.map +1 -1
  493. package/dist/collab/index.d.ts +6 -1
  494. package/dist/collab/index.js +7 -0
  495. package/dist/collab/index.js.map +1 -1
  496. package/dist/collab/presence-react.cjs +11 -11
  497. package/dist/collab/presence-react.cjs.map +1 -1
  498. package/dist/collab/react.cjs +6 -6
  499. package/dist/collab/react.cjs.map +1 -1
  500. package/dist/composer/AttachmentContext.cjs +24 -11
  501. package/dist/composer/AttachmentContext.cjs.map +1 -1
  502. package/dist/composer/AttachmentContext.js +18 -5
  503. package/dist/composer/AttachmentContext.js.map +1 -1
  504. package/dist/composer/ComposerAttachmentPreview.cjs +78 -23
  505. package/dist/composer/ComposerAttachmentPreview.cjs.map +1 -1
  506. package/dist/composer/ComposerAttachmentPreview.d.ts +5 -3
  507. package/dist/composer/ComposerAttachmentPreview.js +79 -24
  508. package/dist/composer/ComposerAttachmentPreview.js.map +1 -1
  509. package/dist/composer/ComposerDropZone.cjs +7 -7
  510. package/dist/composer/ComposerDropZone.cjs.map +1 -1
  511. package/dist/composer/FileUploadButton.cjs +37 -22
  512. package/dist/composer/FileUploadButton.cjs.map +1 -1
  513. package/dist/composer/FileUploadButton.d.ts +6 -0
  514. package/dist/composer/FileUploadButton.js +34 -19
  515. package/dist/composer/FileUploadButton.js.map +1 -1
  516. package/dist/composer/QuoteContext.cjs +8 -8
  517. package/dist/composer/QuoteContext.cjs.map +1 -1
  518. package/dist/composer/composer-handoff.cjs +4 -4
  519. package/dist/composer/composer-handoff.cjs.map +1 -1
  520. package/dist/composer/index.d.ts +1 -1
  521. package/dist/composer/useAppendToComposer.cjs +4 -4
  522. package/dist/composer/useAppendToComposer.cjs.map +1 -1
  523. package/dist/composer/useAttachFiles.cjs +23 -6
  524. package/dist/composer/useAttachFiles.cjs.map +1 -1
  525. package/dist/composer/useAttachFiles.d.ts +15 -7
  526. package/dist/composer/useAttachFiles.js +22 -5
  527. package/dist/composer/useAttachFiles.js.map +1 -1
  528. package/dist/composer/useComposerAttachment.cjs +4 -4
  529. package/dist/composer/useComposerAttachment.cjs.map +1 -1
  530. package/dist/composer/useFileUpload.cjs +21 -16
  531. package/dist/composer/useFileUpload.cjs.map +1 -1
  532. package/dist/composer/useFileUpload.d.ts +12 -0
  533. package/dist/composer/useFileUpload.js +12 -7
  534. package/dist/composer/useFileUpload.js.map +1 -1
  535. package/dist/composer/useReadComposerDraft.cjs +27 -8
  536. package/dist/composer/useReadComposerDraft.cjs.map +1 -1
  537. package/dist/composer/useReadComposerDraft.d.ts +23 -1
  538. package/dist/composer/useReadComposerDraft.js +27 -8
  539. package/dist/composer/useReadComposerDraft.js.map +1 -1
  540. package/dist/composer/useSendMessage.cjs +4 -4
  541. package/dist/composer/useSendMessage.cjs.map +1 -1
  542. package/dist/diagnostics/useAthenaDiagnostics.cjs +4 -4
  543. package/dist/diagnostics/useAthenaDiagnostics.cjs.map +1 -1
  544. package/dist/dictation/audio-level-history.cjs +3 -3
  545. package/dist/dictation/audio-level-history.cjs.map +1 -1
  546. package/dist/dictation/dictation-controls.cjs +24 -20
  547. package/dist/dictation/dictation-controls.cjs.map +1 -1
  548. package/dist/dictation/dictation-controls.d.ts +6 -1
  549. package/dist/dictation/dictation-controls.js +24 -20
  550. package/dist/dictation/dictation-controls.js.map +1 -1
  551. package/dist/dictation/use-athena-dictation-engine.cjs +3 -3
  552. package/dist/dictation/use-athena-dictation-engine.cjs.map +1 -1
  553. package/dist/dictation/use-dictation.cjs +22 -22
  554. package/dist/dictation/use-dictation.cjs.map +1 -1
  555. package/dist/index.cjs +29 -2
  556. package/dist/index.cjs.map +1 -1
  557. package/dist/index.d.ts +18 -4
  558. package/dist/index.js +30 -3
  559. package/dist/index.js.map +1 -1
  560. package/dist/keryx-http/src/receive-only-socket.cjs +40 -0
  561. package/dist/keryx-http/src/receive-only-socket.cjs.map +1 -0
  562. package/dist/keryx-http/src/receive-only-socket.d.ts +27 -0
  563. package/dist/keryx-http/src/receive-only-socket.js +40 -0
  564. package/dist/keryx-http/src/receive-only-socket.js.map +1 -0
  565. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs +190 -0
  566. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs.map +1 -0
  567. package/dist/keryx-http/src/unconfirmed-update-attributions.d.ts +132 -0
  568. package/dist/keryx-http/src/unconfirmed-update-attributions.js +190 -0
  569. package/dist/keryx-http/src/unconfirmed-update-attributions.js.map +1 -0
  570. package/dist/keryx-http/src/update-attributions.cjs +141 -0
  571. package/dist/keryx-http/src/update-attributions.cjs.map +1 -0
  572. package/dist/keryx-http/src/update-attributions.d.ts +107 -0
  573. package/dist/keryx-http/src/update-attributions.js +141 -0
  574. package/dist/keryx-http/src/update-attributions.js.map +1 -0
  575. package/dist/lib/owner-document.cjs +6 -6
  576. package/dist/lib/owner-document.cjs.map +1 -1
  577. package/dist/lib/use-athena-rest-query.cjs +4 -4
  578. package/dist/lib/use-athena-rest-query.cjs.map +1 -1
  579. package/dist/lib/use-document-active.cjs +4 -4
  580. package/dist/lib/use-document-active.cjs.map +1 -1
  581. package/dist/lib/use-prefers-reduced-motion.cjs +2 -2
  582. package/dist/lib/use-prefers-reduced-motion.cjs.map +1 -1
  583. package/dist/offline/offline-history.cjs +7 -7
  584. package/dist/offline/offline-history.cjs.map +1 -1
  585. package/dist/provider/AthenaContext.cjs +3 -3
  586. package/dist/provider/AthenaContext.cjs.map +1 -1
  587. package/dist/provider/AthenaProvider.cjs +120 -79
  588. package/dist/provider/AthenaProvider.cjs.map +1 -1
  589. package/dist/provider/AthenaProvider.d.ts +11 -1
  590. package/dist/provider/AthenaProvider.js +44 -3
  591. package/dist/provider/AthenaProvider.js.map +1 -1
  592. package/dist/provider/PostHogProvider.cjs +2 -2
  593. package/dist/provider/PostHogProvider.cjs.map +1 -1
  594. package/dist/provider/agent-selection-context.cjs +2 -2
  595. package/dist/provider/agent-selection-context.cjs.map +1 -1
  596. package/dist/provider/chat-mode-context.cjs +2 -2
  597. package/dist/provider/chat-mode-context.cjs.map +1 -1
  598. package/dist/provider/session-persistence-context.cjs +10 -0
  599. package/dist/provider/session-persistence-context.cjs.map +1 -0
  600. package/dist/provider/session-persistence-context.d.ts +15 -0
  601. package/dist/provider/session-persistence-context.js +10 -0
  602. package/dist/provider/session-persistence-context.js.map +1 -0
  603. package/dist/provider/statewire-history-context.cjs +4 -4
  604. package/dist/provider/statewire-history-context.cjs.map +1 -1
  605. package/dist/provider/statewire-lifecycle-context.cjs +3 -3
  606. package/dist/provider/statewire-lifecycle-context.cjs.map +1 -1
  607. package/dist/provider/statewire-window-context.cjs +3 -3
  608. package/dist/provider/statewire-window-context.cjs.map +1 -1
  609. package/dist/provider/theme-style-context.cjs +3 -3
  610. package/dist/provider/theme-style-context.cjs.map +1 -1
  611. package/dist/react/package.json.cjs +1 -1
  612. package/dist/react/package.json.js +1 -1
  613. package/dist/runtime/StatewireThreadConfigLaneSync.cjs +10 -10
  614. package/dist/runtime/StatewireThreadConfigLaneSync.cjs.map +1 -1
  615. package/dist/runtime/auth-refusal-restart.cjs +7 -7
  616. package/dist/runtime/auth-refusal-restart.cjs.map +1 -1
  617. package/dist/runtime/auth.cjs +13 -13
  618. package/dist/runtime/auth.cjs.map +1 -1
  619. package/dist/runtime/statewire-lifecycle.cjs +1 -0
  620. package/dist/runtime/statewire-lifecycle.cjs.map +1 -1
  621. package/dist/runtime/statewire-lifecycle.d.ts +3 -1
  622. package/dist/runtime/statewire-lifecycle.js +2 -1
  623. package/dist/runtime/statewire-lifecycle.js.map +1 -1
  624. package/dist/runtime/statewire-server-lane-context.cjs +2 -2
  625. package/dist/runtime/statewire-server-lane-context.cjs.map +1 -1
  626. package/dist/runtime/statewire-session-lane.cjs +4 -4
  627. package/dist/runtime/statewire-session-lane.cjs.map +1 -1
  628. package/dist/runtime/useAthenaStatewireRuntime.cjs +10 -8
  629. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  630. package/dist/runtime/useAthenaStatewireRuntime.d.ts +2 -0
  631. package/dist/runtime/useAthenaStatewireRuntime.js +2 -0
  632. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  633. package/dist/styles.css +1 -1
  634. package/dist/threads/Inbox.cjs +8 -8
  635. package/dist/threads/Inbox.cjs.map +1 -1
  636. package/dist/threads/SessionList.cjs +9 -9
  637. package/dist/threads/SessionList.cjs.map +1 -1
  638. package/dist/threads/SessionsPage.cjs +11 -11
  639. package/dist/threads/SessionsPage.cjs.map +1 -1
  640. package/dist/threads/api.cjs.map +1 -1
  641. package/dist/threads/api.d.ts +15 -0
  642. package/dist/threads/api.js.map +1 -1
  643. package/dist/threads/conversation-list-fetcher.cjs +13 -5
  644. package/dist/threads/conversation-list-fetcher.cjs.map +1 -1
  645. package/dist/threads/conversation-list-fetcher.d.ts +4 -1
  646. package/dist/threads/conversation-list-fetcher.js +13 -5
  647. package/dist/threads/conversation-list-fetcher.js.map +1 -1
  648. package/dist/threads/index-triggered-refresh.cjs +10 -10
  649. package/dist/threads/index-triggered-refresh.cjs.map +1 -1
  650. package/dist/threads/mark-viewed-thread-read.cjs +12 -12
  651. package/dist/threads/mark-viewed-thread-read.cjs.map +1 -1
  652. package/dist/threads/offline-session-list.cjs +3 -3
  653. package/dist/threads/offline-session-list.cjs.map +1 -1
  654. package/dist/threads/session-list-tab-share.cjs +5 -5
  655. package/dist/threads/session-list-tab-share.cjs.map +1 -1
  656. package/dist/threads/statewire-thread-list.cjs +79 -57
  657. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  658. package/dist/threads/statewire-thread-list.d.ts +20 -8
  659. package/dist/threads/statewire-thread-list.js +28 -6
  660. package/dist/threads/statewire-thread-list.js.map +1 -1
  661. package/dist/threads/thread-id-context.cjs +5 -5
  662. package/dist/threads/thread-id-context.cjs.map +1 -1
  663. package/dist/threads/use-athena-session-attention.cjs +2 -2
  664. package/dist/threads/use-athena-session-attention.cjs.map +1 -1
  665. package/dist/threads/use-athena-sessions.cjs +37 -15
  666. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  667. package/dist/threads/use-athena-sessions.d.ts +10 -5
  668. package/dist/threads/use-athena-sessions.js +28 -6
  669. package/dist/threads/use-athena-sessions.js.map +1 -1
  670. package/dist/threads/use-athena-thread-model.cjs +3 -3
  671. package/dist/threads/use-athena-thread-model.cjs.map +1 -1
  672. package/dist/threads/use-rest-conversation-history.cjs +3 -3
  673. package/dist/threads/use-rest-conversation-history.cjs.map +1 -1
  674. package/dist/threads/use-rest-conversation-history.d.ts +1 -0
  675. package/dist/threads/use-statewire-conversation-history.cjs +8 -8
  676. package/dist/threads/use-statewire-conversation-history.cjs.map +1 -1
  677. package/dist/threads/use-thread-archive.cjs +9 -9
  678. package/dist/threads/use-thread-archive.cjs.map +1 -1
  679. package/dist/threads/use-thread-favorite.cjs +2 -2
  680. package/dist/threads/use-thread-favorite.cjs.map +1 -1
  681. package/dist/threads/use-thread-field-override.cjs +20 -20
  682. package/dist/threads/use-thread-field-override.cjs.map +1 -1
  683. package/dist/threads/use-thread-read-state.cjs +4 -4
  684. package/dist/threads/use-thread-read-state.cjs.map +1 -1
  685. package/dist/threads/use-thread-rename.cjs +2 -2
  686. package/dist/threads/use-thread-rename.cjs.map +1 -1
  687. package/dist/threads/useAthenaThreadManager.cjs +2 -2
  688. package/dist/threads/useAthenaThreadManager.cjs.map +1 -1
  689. package/dist/tools/NestedPtcMessages.cjs +6 -6
  690. package/dist/tools/NestedPtcMessages.cjs.map +1 -1
  691. package/dist/tools/append-document-tool-ui.cjs +7 -7
  692. package/dist/tools/append-document-tool-ui.cjs.map +1 -1
  693. package/dist/tools/file-tool-uis.cjs +2 -2
  694. package/dist/tools/file-tool-uis.cjs.map +1 -1
  695. package/dist/tools/misc-tool-uis.cjs +2 -2
  696. package/dist/tools/misc-tool-uis.cjs.map +1 -1
  697. package/dist/tools/primitives.cjs +6 -6
  698. package/dist/tools/primitives.cjs.map +1 -1
  699. package/dist/tools/read-asset-tool-ui.cjs +6 -6
  700. package/dist/tools/read-asset-tool-ui.cjs.map +1 -1
  701. package/dist/tools/subagent-task-tool-ui.cjs +21 -21
  702. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -1
  703. package/dist/tools/test-recording-tool-uis.cjs +16 -16
  704. package/dist/tools/test-recording-tool-uis.cjs.map +1 -1
  705. package/dist/tools/todo-plan-store.cjs +4 -4
  706. package/dist/tools/todo-plan-store.cjs.map +1 -1
  707. package/dist/tools/tool-appearance.cjs +3 -3
  708. package/dist/tools/tool-appearance.cjs.map +1 -1
  709. package/dist/tools/tool-fallback.cjs +14 -14
  710. package/dist/tools/tool-fallback.cjs.map +1 -1
  711. package/dist/tools/tool-uis.cjs +74 -74
  712. package/dist/tools/tool-uis.cjs.map +1 -1
  713. package/dist/tools/use-elapsed-seconds.cjs +3 -3
  714. package/dist/tools/use-elapsed-seconds.cjs.map +1 -1
  715. package/dist/tools/write-todos-tool-ui.cjs +9 -9
  716. package/dist/tools/write-todos-tool-ui.cjs.map +1 -1
  717. package/dist/ui/image-viewer.cjs +382 -0
  718. package/dist/ui/image-viewer.cjs.map +1 -0
  719. package/dist/ui/image-viewer.d.ts +50 -0
  720. package/dist/ui/image-viewer.js +382 -0
  721. package/dist/ui/image-viewer.js.map +1 -0
  722. package/dist/voice/chat.cjs +6 -0
  723. package/dist/voice/chat.cjs.map +1 -1
  724. package/dist/voice/chat.d.ts +1 -1
  725. package/dist/voice/chat.js +8 -2
  726. package/dist/voice/livekit-join.cjs +52 -101
  727. package/dist/voice/livekit-join.cjs.map +1 -1
  728. package/dist/voice/livekit-join.d.ts +1 -6
  729. package/dist/voice/livekit-join.js +52 -101
  730. package/dist/voice/livekit-join.js.map +1 -1
  731. package/dist/voice/livekit.cjs.map +1 -1
  732. package/dist/voice/livekit.d.ts +11 -1
  733. package/dist/voice/livekit.js.map +1 -1
  734. package/dist/voice/use-athena-voice-session.cjs +34 -34
  735. package/dist/voice/use-athena-voice-session.cjs.map +1 -1
  736. package/dist/workbench/ComputerLiveDesktop.cjs +13 -13
  737. package/dist/workbench/ComputerLiveDesktop.cjs.map +1 -1
  738. package/dist/workbench/SessionWorkbench.cjs +22 -22
  739. package/dist/workbench/SessionWorkbench.cjs.map +1 -1
  740. package/dist/workbench/session-workbench-context.cjs +3 -3
  741. package/dist/workbench/session-workbench-context.cjs.map +1 -1
  742. package/dist/workbench/session-workbench-panes.cjs +8 -8
  743. package/dist/workbench/session-workbench-panes.cjs.map +1 -1
  744. package/dist/workbench/workbench-layout-context.cjs +3 -3
  745. package/dist/workbench/workbench-layout-context.cjs.map +1 -1
  746. package/package.json +2 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unconfirmed-update-attributions.js","sources":["../../../../keryx-http/src/unconfirmed-update-attributions.ts"],"sourcesContent":["/**\n * The attributed writes a room has not seen Keryx acknowledge, kept so that a write made while the\n * room's socket is closed still reaches Keryx with its attributions.\n *\n * A write made inside `runWithDocUpdateAttributions` leaves as its own sync update followed by the\n * attributions trailer (`attributingWebSocket`), but only if the room's socket is open as it is\n * made. One made while it is closed (offline, reconnecting, before the first connection) reaches\n * Keryx inside the reconnect's sync step 2: the client's answer to Keryx's sync step 1, everything\n * it holds that Keryx lacks. Keryx reads no trailer after a sync step 2, so it would count the\n * write as the person's edit.\n *\n * So the room keeps the content ids of every write made in a scope, with the scope's attributions,\n * until Keryx sends those ids back: the echo of the update that carried them, or the whole document\n * Keryx sends when a socket opens (`received`; `@y/websocket` confirms its own unconfirmed updates\n * the same way). When the socket sends a sync step 2, each kept write's part of it goes out first,\n * oldest first, as its own sync update with its trailer, and the sync step 2 follows without those\n * ids (`framesFor`). The parts are cut from the sync step 2 itself, which already holds only what\n * Keryx lacks past its state vector. One socket keeps the order, so Keryx appends each marked update\n * before the person's sync step 2.\n *\n * That answer waits for Keryx's document (`connect`). Keryx sends its sync step 1 and, in the same\n * cork, its whole document, but `@y/websocket` answers the sync step 1 as it arrives. A kept write\n * Keryx already appended (its echo lost with the socket) is still kept then, and the sync step 2\n * holds the client's whole delete set, so its deletes would go out again as a marked update, which\n * Keryx appends: it drops what it holds from the first sync step 2 only. Held until the next frame,\n * the answer is split once Keryx's document has dropped what it holds.\n *\n * What Keryx records (`patches/@y%2Fhub@0.10.1.patch`):\n * - An update's content map attributes every id it carries, inserts and deletes, read from its\n * bytes: an update that cannot integrate yet (an item next to one the person typed offline, the\n * next clocks of the person's own client) is attributed like any other. Peers hold it until the\n * sync step 2 behind it brings what it needs.\n * - An id is attributed by the first stream entry that carries it (`getDoc`'s `excludeContentMap`),\n * so a later copy changes no merged history. The live change notices read each entry's own\n * content map, though (keryx/src/doc-watcher.ts), and the first sync step 2's strip of what Keryx\n * holds reads the known ids when the frame arrives, possibly before the update ahead of it is in\n * the stream (one whose content map the compute pool builds). A copy inside the sync step 2\n * would then be announced as the person's: the sync step 2 never carries a kept write's ids.\n *\n * Bounded: consecutive writes of one scope merge into one run, and past\n * {@link MAX_ATTRIBUTED_RUNS} runs the oldest is let go (its content then reaches Keryx in a sync\n * step 2, as the person's). A room's local copy keeps them across sessions\n * ({@link unconfirmedAttributedWritesOf}, {@link restoreUnconfirmedAttributedWrites}); without one,\n * a write the room kept is forgotten with the page.\n */\nimport {\n type ContentIds,\n createContentIdsFromUpdate,\n type Doc,\n excludeContentIds,\n intersectContentIds,\n intersectUpdateWithContentIds,\n mergeContentIds,\n} from '@y/y';\nimport {\n type AttributedWritesSocket,\n readVarUint,\n type UnconfirmedAttributedWrites,\n type UpdateAttribution,\n withUpdateAttributionsTrailer,\n writeVarUint,\n} from './update-attributions.js';\n\n/** y-protocols: a sync message, and the sub-types that carry content. */\nconst MESSAGE_SYNC = 0;\nconst SYNC_STEP_2 = 1;\nconst SYNC_UPDATE = 2;\n\n/** Writes made in one attribution scope, by the content ids they wrote (inserts and deletes). */\nexport interface AttributedWrites {\n ids: ContentIds;\n attributions: readonly UpdateAttribution[];\n}\n\n/**\n * The most runs a room keeps; a run is one scope's writes since a write of another scope. Housekeeping\n * all shares one scope, so runs pile up only as Quick Edit steps interleave with it.\n */\nexport const MAX_ATTRIBUTED_RUNS = 64;\n\nfunction noIds(ids: ContentIds): boolean {\n return ids.inserts.isEmpty() && ids.deletes.isEmpty();\n}\n\nfunction sameAttributions(\n a: readonly UpdateAttribution[],\n b: readonly UpdateAttribution[]\n): boolean {\n return (\n a.length === b.length &&\n a.every((pair, index) => pair.k === b[index]?.k && pair.v === b[index]?.v)\n );\n}\n\n/** The sync message `frame` is, when it is exactly one (nothing after its payload). */\nfunction readSyncFrame(frame: Uint8Array): { syncType: number; payload: Uint8Array } | null {\n const type = readVarUint({ bytes: frame, start: 0 });\n if (type?.value !== MESSAGE_SYNC) return null;\n const syncType = readVarUint({ bytes: frame, start: type.next });\n if (syncType === null) return null;\n const length = readVarUint({ bytes: frame, start: syncType.next });\n if (length === null || length.next + length.value !== frame.length) return null;\n return { syncType: syncType.value, payload: frame.subarray(length.next) };\n}\n\n/** A sync message of `syncType` carrying `payload`, as y-protocols writes one. */\nfunction syncFrame({ syncType, payload }: { syncType: number; payload: Uint8Array }): Uint8Array {\n const head: number[] = [];\n writeVarUint({ out: head, value: MESSAGE_SYNC });\n writeVarUint({ out: head, value: syncType });\n writeVarUint({ out: head, value: payload.length });\n const frame = new Uint8Array(head.length + payload.length);\n frame.set(head, 0);\n frame.set(payload, head.length);\n return frame;\n}\n\n/** The content ids an update carries, or `null` for bytes that are not one. */\nfunction idsOf(update: Uint8Array): ContentIds | null {\n try {\n return createContentIdsFromUpdate(update);\n } catch {\n return null;\n }\n}\n\nfunction copyOf({ ids, attributions }: AttributedWrites): AttributedWrites {\n return { ids, attributions: attributions.map(({ k, v }) => ({ k, v })) };\n}\n\n/** `runs` without the oldest past {@link MAX_ATTRIBUTED_RUNS}. */\nfunction bounded(runs: AttributedWrites[]): AttributedWrites[] {\n return runs.length > MAX_ATTRIBUTED_RUNS ? runs.slice(runs.length - MAX_ATTRIBUTED_RUNS) : runs;\n}\n\n/** What a page reads of a room's tracker, whichever copy of this module made it. */\ninterface KeptWrites {\n readonly pending: readonly AttributedWrites[];\n restore(writes: readonly AttributedWrites[]): void;\n}\n\n/**\n * Each document's tracker in the page, and what a destroyed one still kept for the next tracker made\n * for the same document (a transport rebuilt over a retained document; a local copy read into a\n * document before its room's transport exists). On `globalThis`, not in module scope, for the reason\n * the scopes are (`update-attributions.ts`): the SDK's dist inlines its own copy of this module, and\n * a local copy reading a room through another copy must find the same tracker. Weak: each entry goes\n * with its document.\n */\nconst ROOMS = Symbol.for('@athenaintel/keryx-http/unconfirmed-update-attributions');\n\ninterface Rooms {\n live: WeakMap<object, KeptWrites>;\n left: WeakMap<object, AttributedWrites[]>;\n}\n\ntype RoomsHost = typeof globalThis & {\n [ROOMS]?: Rooms;\n};\n\n// process-local: browser-only, each entry keyed by the document whose writes it holds\nfunction rooms(): Rooms {\n const host = globalThis as RoomsHost;\n return (host[ROOMS] ??= { live: new WeakMap(), left: new WeakMap() });\n}\n\n/**\n * The attributed writes Keryx has not acknowledged for `doc`, oldest first: its room's, or what a\n * destroyed room left for the next. What a room's local copy keeps of them.\n */\nexport function unconfirmedAttributedWritesOf(doc: object): readonly AttributedWrites[] {\n const { live, left } = rooms();\n return live.get(doc)?.pending ?? left.get(doc)?.map(copyOf) ?? [];\n}\n\n/**\n * Hands `doc`'s room attributed writes an earlier session kept (the room's local copy), or keeps\n * them for the next tracker made for it. They are older than anything written since, so they go\n * out first.\n */\nexport function restoreUnconfirmedAttributedWrites({\n doc,\n writes,\n}: {\n doc: object;\n writes: readonly AttributedWrites[];\n}): void {\n if (writes.length === 0) return;\n const { live, left } = rooms();\n const room = live.get(doc);\n if (room) {\n room.restore(writes);\n return;\n }\n left.set(doc, bounded([...writes.map(copyOf), ...(left.get(doc) ?? [])]));\n}\n\n/**\n * The two above, as a page hands them to its local copies (`@athenaintel/local-copy`'s\n * `openLocalCopyStore({ attributedWrites })`, `createLocalCopiesPage({ attributedWrites })`): the\n * copy records a room's kept writes with its edits and restores an ended session's to its room.\n */\nexport const roomAttributedWrites = {\n of: unconfirmedAttributedWritesOf,\n restore: restoreUnconfirmedAttributedWrites,\n};\n\n/**\n * One room's attributed writes Keryx has not acknowledged (see the module comment). Made once per\n * room by its transport, which hands it to every socket it opens (`attributingWebSocket`'s\n * `unconfirmed`) and destroys it with the room; a tracker made for the same document later takes\n * over what it still kept, and what its local copy kept from an earlier session\n * ({@link restoreUnconfirmedAttributedWrites}). Not for a room that only listens: its socket sends\n * nothing to split.\n */\nexport class UnconfirmedUpdateAttributions implements UnconfirmedAttributedWrites, KeptWrites {\n private runs: AttributedWrites[];\n private readonly doc: Doc;\n private readonly attributionsFor: () => readonly UpdateAttribution[] | undefined;\n private readonly isRemoteOrigin: (origin: unknown) => boolean;\n\n constructor({\n doc,\n attributionsFor,\n isRemoteOrigin,\n }: {\n doc: Doc;\n /** The attributions of the update being written now: what the socket's trailer reads. */\n attributionsFor: () => readonly UpdateAttribution[] | undefined;\n /** True for a transaction the transport applied (Keryx's state, a peer's edit). */\n isRemoteOrigin: (origin: unknown) => boolean;\n }) {\n this.doc = doc;\n this.attributionsFor = attributionsFor;\n this.isRemoteOrigin = isRemoteOrigin;\n const { live, left } = rooms();\n this.runs = left.get(doc) ?? [];\n left.delete(doc);\n live.set(doc, this);\n doc.on('update', this.handleUpdate);\n }\n\n private readonly handleUpdate = (update: Uint8Array, origin: unknown): void => {\n if (this.isRemoteOrigin(origin)) return;\n const attributions = this.attributionsFor();\n if (!attributions || attributions.length === 0) return;\n const ids = idsOf(update);\n if (!ids || noIds(ids)) return;\n const last = this.runs.at(-1);\n if (last && sameAttributions(last.attributions, attributions)) {\n last.ids = mergeContentIds([last.ids, ids]);\n return;\n }\n this.runs = bounded([...this.runs, copyOf({ ids, attributions })]);\n };\n\n /** The attributed writes Keryx has not acknowledged, oldest first. */\n get pending(): readonly AttributedWrites[] {\n return this.runs.map(copyOf);\n }\n\n /** Writes an earlier session kept, older than any written here: they go out first. */\n restore(writes: readonly AttributedWrites[]): void {\n this.runs = bounded([...writes.map(copyOf), ...this.runs]);\n }\n\n /**\n * One socket of the room. While the room keeps writes, the socket's sync step 2 (its answer to\n * Keryx's sync step 1) waits for the next frame Keryx sends, its whole document, which drops what\n * Keryx already holds before the answer is split (see the module comment); every frame sent\n * meanwhile waits behind it, in order. Nothing kept, or a socket that cannot hear Keryx: every\n * frame goes out as it is sent.\n */\n connect({\n send,\n hears,\n }: {\n send: (frame: Uint8Array) => void;\n hears: boolean;\n }): AttributedWritesSocket {\n let held: Uint8Array[] | null = null;\n const sendNow = (frame: Uint8Array) => {\n for (const out of this.framesFor(frame)) send(out);\n };\n return {\n received: (frame) => {\n this.received(frame);\n if (held === null) return;\n const waiting = held;\n held = null;\n for (const next of waiting) sendNow(next);\n },\n send: (frame) => {\n if (held !== null) {\n held.push(frame);\n return;\n }\n if (hears && this.runs.length > 0 && readSyncFrame(frame)?.syncType === SYNC_STEP_2) {\n held = [frame];\n return;\n }\n sendNow(frame);\n },\n };\n }\n\n /** Keryx sent `frame`: the ids it carries are Keryx's, kept no longer. */\n received(frame: Uint8Array): void {\n if (this.runs.length === 0) return;\n const message = readSyncFrame(frame);\n if (message === null) return;\n if (message.syncType !== SYNC_STEP_2 && message.syncType !== SYNC_UPDATE) return;\n const held = idsOf(message.payload);\n if (!held) return;\n this.runs = this.runs\n .map(({ ids, attributions }) => ({ ids: excludeContentIds(ids, held), attributions }))\n .filter((run) => !noIds(run.ids));\n }\n\n /**\n * What goes out in place of `frame`: `[frame]` itself, except a sync step 2 carrying kept writes,\n * which goes out behind each of them as its own marked sync update.\n */\n framesFor(frame: Uint8Array): readonly Uint8Array[] {\n if (this.runs.length === 0) return [frame];\n const message = readSyncFrame(frame);\n if (message === null || message.syncType !== SYNC_STEP_2) return [frame];\n const answer = message.payload;\n const all = idsOf(answer);\n if (!all) return [frame];\n const frames: Uint8Array[] = [];\n const marked: ContentIds[] = [];\n for (const run of this.runs) {\n const part = intersectContentIds(run.ids, all);\n if (noIds(part)) continue;\n frames.push(\n withUpdateAttributionsTrailer({\n message: syncFrame({\n syncType: SYNC_UPDATE,\n payload: intersectUpdateWithContentIds(answer, part),\n }),\n attributions: run.attributions,\n })\n );\n marked.push(part);\n }\n if (marked.length === 0) return [frame];\n const rest = excludeContentIds(all, mergeContentIds(marked));\n frames.push(\n syncFrame({ syncType: SYNC_STEP_2, payload: intersectUpdateWithContentIds(answer, rest) })\n );\n return frames;\n }\n\n /** Stops keeping; what is still kept waits for the next tracker made for the document. */\n destroy(): void {\n this.doc.off('update', this.handleUpdate);\n const { live, left } = rooms();\n if (live.get(this.doc) === this) live.delete(this.doc);\n if (this.runs.length > 0) left.set(this.doc, this.runs);\n this.runs = [];\n }\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const BACKGROUND_UPDATE_ATTRIBUTIONS = [
4
+ { k: "origin", v: "background" }
5
+ ];
6
+ const UPDATE_ATTRIBUTIONS_TRAILER_V1 = 1;
7
+ const MESSAGE_SYNC = 0;
8
+ const MESSAGE_SYNC_UPDATE = 2;
9
+ const DOC_SCOPES = Symbol.for("@athenaintel/keryx-http/update-attribution-scopes");
10
+ function docScopes() {
11
+ const host = globalThis;
12
+ return host[DOC_SCOPES] ?? (host[DOC_SCOPES] = /* @__PURE__ */ new WeakMap());
13
+ }
14
+ function runWithDocUpdateAttributions({
15
+ doc,
16
+ attributions,
17
+ run
18
+ }) {
19
+ const scopes = docScopes();
20
+ const outer = scopes.get(doc);
21
+ scopes.set(doc, attributions);
22
+ try {
23
+ return run();
24
+ } finally {
25
+ if (outer === void 0) scopes.delete(doc);
26
+ else scopes.set(doc, outer);
27
+ }
28
+ }
29
+ function docUpdateAttributions(doc) {
30
+ return docScopes().get(doc);
31
+ }
32
+ function readVarUint({
33
+ bytes,
34
+ start
35
+ }) {
36
+ let value = 0;
37
+ let multiplier = 1;
38
+ for (let pos = start; pos < bytes.length; pos += 1) {
39
+ const byte = bytes[pos];
40
+ if (byte === void 0) return null;
41
+ value += (byte & 127) * multiplier;
42
+ if (byte < 128) return { value, next: pos + 1 };
43
+ multiplier *= 128;
44
+ if (multiplier > Number.MAX_SAFE_INTEGER) return null;
45
+ }
46
+ return null;
47
+ }
48
+ function writeVarUint({ out, value }) {
49
+ let rest = value;
50
+ while (rest > 127) {
51
+ out.push(128 | rest % 128);
52
+ rest = Math.floor(rest / 128);
53
+ }
54
+ out.push(rest);
55
+ }
56
+ function isBareSyncUpdate(message) {
57
+ const type = readVarUint({ bytes: message, start: 0 });
58
+ if ((type == null ? void 0 : type.value) !== MESSAGE_SYNC) return false;
59
+ const syncType = readVarUint({ bytes: message, start: type.next });
60
+ if ((syncType == null ? void 0 : syncType.value) !== MESSAGE_SYNC_UPDATE) return false;
61
+ const length = readVarUint({ bytes: message, start: syncType.next });
62
+ return length !== null && length.next + length.value === message.length;
63
+ }
64
+ function withUpdateAttributionsTrailer({
65
+ message,
66
+ attributions
67
+ }) {
68
+ if (attributions.length === 0 || !isBareSyncUpdate(message)) return message;
69
+ const trailer = [];
70
+ writeVarUint({ out: trailer, value: UPDATE_ATTRIBUTIONS_TRAILER_V1 });
71
+ writeVarUint({ out: trailer, value: attributions.length });
72
+ const utf8 = new TextEncoder();
73
+ for (const { k, v } of attributions) {
74
+ for (const text of [k, v]) {
75
+ const bytes = utf8.encode(text);
76
+ writeVarUint({ out: trailer, value: bytes.length });
77
+ for (const byte of bytes) trailer.push(byte);
78
+ }
79
+ }
80
+ const out = new Uint8Array(message.length + trailer.length);
81
+ out.set(message, 0);
82
+ out.set(trailer, message.length);
83
+ return out;
84
+ }
85
+ function receivedBytes(data) {
86
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
87
+ if (ArrayBuffer.isView(data))
88
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
89
+ return null;
90
+ }
91
+ function listenToFrames({
92
+ socket,
93
+ onFrame
94
+ }) {
95
+ if (!("addEventListener" in socket) || typeof socket.addEventListener !== "function") {
96
+ return false;
97
+ }
98
+ socket.addEventListener("message", (event) => {
99
+ const frame = receivedBytes(event.data);
100
+ if (frame) onFrame(frame);
101
+ });
102
+ return true;
103
+ }
104
+ function attributingWebSocket({
105
+ Base,
106
+ attributionsFor,
107
+ unconfirmed
108
+ }) {
109
+ if (typeof Base !== "function") return Base;
110
+ return new Proxy(Base, {
111
+ construct(target, args) {
112
+ const socket = Reflect.construct(target, args);
113
+ const send = socket.send.bind(socket);
114
+ let connection = null;
115
+ if (unconfirmed) {
116
+ const hears = listenToFrames({ socket, onFrame: (frame) => connection == null ? void 0 : connection.received(frame) });
117
+ connection = unconfirmed.connect({ send, hears });
118
+ }
119
+ socket.send = (data) => {
120
+ if (!(data instanceof Uint8Array)) {
121
+ send(data);
122
+ return;
123
+ }
124
+ const attributions = attributionsFor();
125
+ const message = attributions ? withUpdateAttributionsTrailer({ message: data, attributions }) : data;
126
+ if (connection) connection.send(message);
127
+ else send(message);
128
+ };
129
+ return socket;
130
+ }
131
+ });
132
+ }
133
+ exports.BACKGROUND_UPDATE_ATTRIBUTIONS = BACKGROUND_UPDATE_ATTRIBUTIONS;
134
+ exports.UPDATE_ATTRIBUTIONS_TRAILER_V1 = UPDATE_ATTRIBUTIONS_TRAILER_V1;
135
+ exports.attributingWebSocket = attributingWebSocket;
136
+ exports.docUpdateAttributions = docUpdateAttributions;
137
+ exports.readVarUint = readVarUint;
138
+ exports.runWithDocUpdateAttributions = runWithDocUpdateAttributions;
139
+ exports.withUpdateAttributionsTrailer = withUpdateAttributionsTrailer;
140
+ exports.writeVarUint = writeVarUint;
141
+ //# sourceMappingURL=update-attributions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-attributions.cjs","sources":["../../../../keryx-http/src/update-attributions.ts"],"sourcesContent":["/**\n * Attributions one Keryx socket update carries of its own.\n *\n * A Keryx connection's attributions are fixed when its socket opens, so every update a client\n * sends is attributed to the person whose client it is. A write the client makes on its own (the\n * sheet leader re-issuing `=AOP` formulas or re-pushing `=IMPORTRANGE` values, a restored result,\n * an editor binding re-keying what an older binding stored) read as that person's edit and woke\n * \"people only\" subscriptions. Keryx reads a trailer after the update in a sync update message\n * (`readUpdateAttributions` in `patches/@y%2Fhub@0.10.1.patch`): `varUint(1)`, `varUint(n)`, then\n * `n` pairs of `varString` key and value. It accepts only `origin: background`, which it counts as\n * system work (`actorOf` in `keryx/src/compaction-activity.ts`), and the pairs that name a Quick\n * Edit step (`@athenaintel/keryx-http/quick-edit`: `session_id`/`run_kind` on the apply,\n * `quick_edit_undo`/`quick_edit_redo` with `quick_edit_op` on an undo or redo), each value in\n * exactly its shape. A Keryx without that hunk reads the update and ignores the bytes after it, so\n * a trailer never costs an update; a pair it does not allow is dropped and the rest kept.\n *\n * A writer marks its writes by making them inside {@link runWithDocUpdateAttributions} for the\n * doc; the transport's socket ({@link attributingWebSocket}) appends the trailer to each sync\n * update it sends while that scope is open. Both Keryx transports wrap their sockets with it:\n * Olympus's rooms (`KeryxYjsProviderV14`) and `@athenaintel/react/collab`'s `connectGenericDoc`\n * (Midas, the phone's editor page). y-websocket sends a local update from inside the doc's\n * `update` event, which fires inside the write itself, so the trailer always rides on the update\n * the scope wrote. A write made while the socket is closed is not sent then: it reaches Keryx in\n * the reconnect's sync step 2, which can carry no trailer. A transport that hands its socket the\n * room's {@link UnconfirmedAttributedWrites} (`@athenaintel/keryx-http/unconfirmed-update-attributions`)\n * sends each such write ahead of that sync step 2 as its own marked update; without one it stays\n * the person's.\n */\n\n/** One custom attribution, as Keryx stores it on the items an update wrote. */\nexport interface UpdateAttribution {\n k: string;\n v: string;\n}\n\n/** The pair a housekeeping write carries; Agora and Keryx spell it the same way. */\nexport const BACKGROUND_UPDATE_ATTRIBUTIONS: readonly UpdateAttribution[] = [\n { k: 'origin', v: 'background' },\n];\n\n/** The trailer format Keryx reads (`updateAttributionsTrailerV1`). */\nexport const UPDATE_ATTRIBUTIONS_TRAILER_V1 = 1;\n\n/** y-protocols: a sync message, and its update sub-type. */\nconst MESSAGE_SYNC = 0;\nconst MESSAGE_SYNC_UPDATE = 2;\n\n/**\n * The open scopes live on `globalThis`, not in module scope, because two copies of this module can\n * run in one page: `@athenaintel/react` bundles it into its dist (this package is private, so the\n * published SDK must inline it) while a host may import it from this package. A scope a writer\n * opens through one copy must be the one the transport's socket reads through the other.\n */\nconst DOC_SCOPES = Symbol.for('@athenaintel/keryx-http/update-attribution-scopes');\n\ntype DocScopesHost = typeof globalThis & {\n [DOC_SCOPES]?: WeakMap<object, readonly UpdateAttribution[]>;\n};\n\n// process-local: browser-only scopes, each keyed by the doc it guards and cleared in the same synchronous call that set it\nfunction docScopes(): WeakMap<object, readonly UpdateAttribution[]> {\n const host = globalThis as DocScopesHost;\n return (host[DOC_SCOPES] ??= new WeakMap());\n}\n\n/**\n * Run `run` with every update it writes into `doc` marked with `attributions`. Synchronous only:\n * the scope ends when `run` returns. Nested scopes restore the outer one.\n */\nexport function runWithDocUpdateAttributions<T>({\n doc,\n attributions,\n run,\n}: {\n doc: object;\n attributions: readonly UpdateAttribution[];\n run: () => T;\n}): T {\n const scopes = docScopes();\n const outer = scopes.get(doc);\n scopes.set(doc, attributions);\n try {\n return run();\n } finally {\n if (outer === undefined) scopes.delete(doc);\n else scopes.set(doc, outer);\n }\n}\n\n/** The attributions the update being written into `doc` right now carries, if any. */\nexport function docUpdateAttributions(doc: object): readonly UpdateAttribution[] | undefined {\n return docScopes().get(doc);\n}\n\n/** The lib0 varUint at `start` in `bytes` and where the next field begins; `null` past the end. */\nexport function readVarUint({\n bytes,\n start,\n}: {\n bytes: Uint8Array;\n start: number;\n}): { value: number; next: number } | null {\n let value = 0;\n let multiplier = 1;\n for (let pos = start; pos < bytes.length; pos += 1) {\n const byte = bytes[pos];\n if (byte === undefined) return null;\n value += (byte & 0x7f) * multiplier;\n if (byte < 0x80) return { value, next: pos + 1 };\n multiplier *= 0x80;\n if (multiplier > Number.MAX_SAFE_INTEGER) return null;\n }\n return null;\n}\n\n/** Append `value` to `out` as a lib0 varUint. */\nexport function writeVarUint({ out, value }: { out: number[]; value: number }): void {\n let rest = value;\n while (rest > 0x7f) {\n out.push(0x80 | (rest % 0x80));\n rest = Math.floor(rest / 0x80);\n }\n out.push(rest);\n}\n\n/** Exactly one sync update message, with nothing after the update. */\nfunction isBareSyncUpdate(message: Uint8Array): boolean {\n const type = readVarUint({ bytes: message, start: 0 });\n if (type?.value !== MESSAGE_SYNC) return false;\n const syncType = readVarUint({ bytes: message, start: type.next });\n if (syncType?.value !== MESSAGE_SYNC_UPDATE) return false;\n const length = readVarUint({ bytes: message, start: syncType.next });\n return length !== null && length.next + length.value === message.length;\n}\n\n/**\n * `message` with the trailer for `attributions` appended, when it is a bare sync update message;\n * any other message (sync step 1 or 2, awareness, one that already ends in a trailer) is returned\n * as it is.\n */\nexport function withUpdateAttributionsTrailer({\n message,\n attributions,\n}: {\n message: Uint8Array;\n attributions: readonly UpdateAttribution[];\n}): Uint8Array {\n if (attributions.length === 0 || !isBareSyncUpdate(message)) return message;\n const trailer: number[] = [];\n writeVarUint({ out: trailer, value: UPDATE_ATTRIBUTIONS_TRAILER_V1 });\n writeVarUint({ out: trailer, value: attributions.length });\n const utf8 = new TextEncoder();\n for (const { k, v } of attributions) {\n for (const text of [k, v]) {\n const bytes = utf8.encode(text);\n writeVarUint({ out: trailer, value: bytes.length });\n for (const byte of bytes) trailer.push(byte);\n }\n }\n const out = new Uint8Array(message.length + trailer.length);\n out.set(message, 0);\n out.set(trailer, message.length);\n return out;\n}\n\n/** What {@link attributingWebSocket} needs of a socket: the `send` y-websocket writes frames with. */\nexport interface SendingSocket {\n send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;\n}\n\n/** One socket of a room, as the room's attributed writes Keryx has not acknowledged see it. */\nexport interface AttributedWritesSocket {\n /** Keryx sent `frame` on the socket: what it carries, Keryx holds. */\n received(frame: Uint8Array): void;\n /** The socket sends `frame` (now, or once Keryx has sent what it holds; see the implementation). */\n send(frame: Uint8Array): void;\n}\n\n/**\n * The room's attributed writes Keryx has not acknowledged yet, as its sockets see them\n * (`UnconfirmedUpdateAttributions` in `@athenaintel/keryx-http/unconfirmed-update-attributions`).\n */\nexport interface UnconfirmedAttributedWrites {\n /**\n * A socket opened, sending through `send`. `hears`: the socket hands it every frame Keryx sends\n * (`received`), ahead of the transport.\n */\n connect(params: { send: (frame: Uint8Array) => void; hears: boolean }): AttributedWritesSocket;\n}\n\n/** The bytes of a binary frame a socket received, or `null` for one that is not (a string, a `Blob`). */\nfunction receivedBytes(data: unknown): Uint8Array | null {\n if (data instanceof ArrayBuffer) return new Uint8Array(data);\n if (ArrayBuffer.isView(data))\n return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n return null;\n}\n\n/**\n * Hands `onFrame` every binary frame `socket` receives; whether it can. A listener added before\n * y-websocket sets `onmessage` runs ahead of it. A socket without `addEventListener` hands nothing.\n */\nfunction listenToFrames({\n socket,\n onFrame,\n}: {\n socket: SendingSocket;\n onFrame: (frame: Uint8Array) => void;\n}): boolean {\n if (!('addEventListener' in socket) || typeof socket.addEventListener !== 'function') {\n return false;\n }\n socket.addEventListener('message', (event: { data?: unknown }) => {\n const frame = receivedBytes(event.data);\n if (frame) onFrame(frame);\n });\n return true;\n}\n\n/**\n * `Base` with `send` appending the trailer of `attributionsFor()` to each sync update it sends.\n * With the room's `unconfirmed` attributed writes, each socket also tells them every frame Keryx\n * sends and sends its frames through them, so a sync step 2 goes out behind the kept writes it\n * carries. A `Proxy` keeps the constructor's statics and type, so it drops in as y-websocket's\n * `WebSocketPolyfill`.\n */\nexport function attributingWebSocket<TBase extends new (...args: never[]) => SendingSocket>({\n Base,\n attributionsFor,\n unconfirmed,\n}: {\n Base: TBase;\n attributionsFor: () => readonly UpdateAttribution[] | undefined;\n unconfirmed?: UnconfirmedAttributedWrites;\n}): TBase {\n // No WebSocket where the provider is built (server render, a test without one): nothing to wrap,\n // and the transport fails at connect as it always did.\n if (typeof Base !== 'function') return Base;\n return new Proxy(Base, {\n construct(target, args) {\n const socket: SendingSocket = Reflect.construct(target, args);\n const send = socket.send.bind(socket);\n let connection: AttributedWritesSocket | null = null;\n if (unconfirmed) {\n const hears = listenToFrames({ socket, onFrame: (frame) => connection?.received(frame) });\n connection = unconfirmed.connect({ send, hears });\n }\n socket.send = (data) => {\n if (!(data instanceof Uint8Array)) {\n send(data);\n return;\n }\n const attributions = attributionsFor();\n const message = attributions\n ? withUpdateAttributionsTrailer({ message: data, attributions })\n : data;\n if (connection) connection.send(message);\n else send(message);\n };\n return socket;\n },\n });\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Attributions one Keryx socket update carries of its own.
3
+ *
4
+ * A Keryx connection's attributions are fixed when its socket opens, so every update a client
5
+ * sends is attributed to the person whose client it is. A write the client makes on its own (the
6
+ * sheet leader re-issuing `=AOP` formulas or re-pushing `=IMPORTRANGE` values, a restored result,
7
+ * an editor binding re-keying what an older binding stored) read as that person's edit and woke
8
+ * "people only" subscriptions. Keryx reads a trailer after the update in a sync update message
9
+ * (`readUpdateAttributions` in `patches/@y%2Fhub@0.10.1.patch`): `varUint(1)`, `varUint(n)`, then
10
+ * `n` pairs of `varString` key and value. It accepts only `origin: background`, which it counts as
11
+ * system work (`actorOf` in `keryx/src/compaction-activity.ts`), and the pairs that name a Quick
12
+ * Edit step (`@athenaintel/keryx-http/quick-edit`: `session_id`/`run_kind` on the apply,
13
+ * `quick_edit_undo`/`quick_edit_redo` with `quick_edit_op` on an undo or redo), each value in
14
+ * exactly its shape. A Keryx without that hunk reads the update and ignores the bytes after it, so
15
+ * a trailer never costs an update; a pair it does not allow is dropped and the rest kept.
16
+ *
17
+ * A writer marks its writes by making them inside {@link runWithDocUpdateAttributions} for the
18
+ * doc; the transport's socket ({@link attributingWebSocket}) appends the trailer to each sync
19
+ * update it sends while that scope is open. Both Keryx transports wrap their sockets with it:
20
+ * Olympus's rooms (`KeryxYjsProviderV14`) and `@athenaintel/react/collab`'s `connectGenericDoc`
21
+ * (Midas, the phone's editor page). y-websocket sends a local update from inside the doc's
22
+ * `update` event, which fires inside the write itself, so the trailer always rides on the update
23
+ * the scope wrote. A write made while the socket is closed is not sent then: it reaches Keryx in
24
+ * the reconnect's sync step 2, which can carry no trailer. A transport that hands its socket the
25
+ * room's {@link UnconfirmedAttributedWrites} (`@athenaintel/keryx-http/unconfirmed-update-attributions`)
26
+ * sends each such write ahead of that sync step 2 as its own marked update; without one it stays
27
+ * the person's.
28
+ */
29
+ /** One custom attribution, as Keryx stores it on the items an update wrote. */
30
+ export interface UpdateAttribution {
31
+ k: string;
32
+ v: string;
33
+ }
34
+ /** The pair a housekeeping write carries; Agora and Keryx spell it the same way. */
35
+ export declare const BACKGROUND_UPDATE_ATTRIBUTIONS: readonly UpdateAttribution[];
36
+ /** The trailer format Keryx reads (`updateAttributionsTrailerV1`). */
37
+ export declare const UPDATE_ATTRIBUTIONS_TRAILER_V1 = 1;
38
+ /**
39
+ * Run `run` with every update it writes into `doc` marked with `attributions`. Synchronous only:
40
+ * the scope ends when `run` returns. Nested scopes restore the outer one.
41
+ */
42
+ export declare function runWithDocUpdateAttributions<T>({ doc, attributions, run, }: {
43
+ doc: object;
44
+ attributions: readonly UpdateAttribution[];
45
+ run: () => T;
46
+ }): T;
47
+ /** The attributions the update being written into `doc` right now carries, if any. */
48
+ export declare function docUpdateAttributions(doc: object): readonly UpdateAttribution[] | undefined;
49
+ /** The lib0 varUint at `start` in `bytes` and where the next field begins; `null` past the end. */
50
+ export declare function readVarUint({ bytes, start, }: {
51
+ bytes: Uint8Array;
52
+ start: number;
53
+ }): {
54
+ value: number;
55
+ next: number;
56
+ } | null;
57
+ /** Append `value` to `out` as a lib0 varUint. */
58
+ export declare function writeVarUint({ out, value }: {
59
+ out: number[];
60
+ value: number;
61
+ }): void;
62
+ /**
63
+ * `message` with the trailer for `attributions` appended, when it is a bare sync update message;
64
+ * any other message (sync step 1 or 2, awareness, one that already ends in a trailer) is returned
65
+ * as it is.
66
+ */
67
+ export declare function withUpdateAttributionsTrailer({ message, attributions, }: {
68
+ message: Uint8Array;
69
+ attributions: readonly UpdateAttribution[];
70
+ }): Uint8Array;
71
+ /** What {@link attributingWebSocket} needs of a socket: the `send` y-websocket writes frames with. */
72
+ export interface SendingSocket {
73
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
74
+ }
75
+ /** One socket of a room, as the room's attributed writes Keryx has not acknowledged see it. */
76
+ export interface AttributedWritesSocket {
77
+ /** Keryx sent `frame` on the socket: what it carries, Keryx holds. */
78
+ received(frame: Uint8Array): void;
79
+ /** The socket sends `frame` (now, or once Keryx has sent what it holds; see the implementation). */
80
+ send(frame: Uint8Array): void;
81
+ }
82
+ /**
83
+ * The room's attributed writes Keryx has not acknowledged yet, as its sockets see them
84
+ * (`UnconfirmedUpdateAttributions` in `@athenaintel/keryx-http/unconfirmed-update-attributions`).
85
+ */
86
+ export interface UnconfirmedAttributedWrites {
87
+ /**
88
+ * A socket opened, sending through `send`. `hears`: the socket hands it every frame Keryx sends
89
+ * (`received`), ahead of the transport.
90
+ */
91
+ connect(params: {
92
+ send: (frame: Uint8Array) => void;
93
+ hears: boolean;
94
+ }): AttributedWritesSocket;
95
+ }
96
+ /**
97
+ * `Base` with `send` appending the trailer of `attributionsFor()` to each sync update it sends.
98
+ * With the room's `unconfirmed` attributed writes, each socket also tells them every frame Keryx
99
+ * sends and sends its frames through them, so a sync step 2 goes out behind the kept writes it
100
+ * carries. A `Proxy` keeps the constructor's statics and type, so it drops in as y-websocket's
101
+ * `WebSocketPolyfill`.
102
+ */
103
+ export declare function attributingWebSocket<TBase extends new (...args: never[]) => SendingSocket>({ Base, attributionsFor, unconfirmed, }: {
104
+ Base: TBase;
105
+ attributionsFor: () => readonly UpdateAttribution[] | undefined;
106
+ unconfirmed?: UnconfirmedAttributedWrites;
107
+ }): TBase;
@@ -0,0 +1,141 @@
1
+ const BACKGROUND_UPDATE_ATTRIBUTIONS = [
2
+ { k: "origin", v: "background" }
3
+ ];
4
+ const UPDATE_ATTRIBUTIONS_TRAILER_V1 = 1;
5
+ const MESSAGE_SYNC = 0;
6
+ const MESSAGE_SYNC_UPDATE = 2;
7
+ const DOC_SCOPES = Symbol.for("@athenaintel/keryx-http/update-attribution-scopes");
8
+ function docScopes() {
9
+ const host = globalThis;
10
+ return host[DOC_SCOPES] ?? (host[DOC_SCOPES] = /* @__PURE__ */ new WeakMap());
11
+ }
12
+ function runWithDocUpdateAttributions({
13
+ doc,
14
+ attributions,
15
+ run
16
+ }) {
17
+ const scopes = docScopes();
18
+ const outer = scopes.get(doc);
19
+ scopes.set(doc, attributions);
20
+ try {
21
+ return run();
22
+ } finally {
23
+ if (outer === void 0) scopes.delete(doc);
24
+ else scopes.set(doc, outer);
25
+ }
26
+ }
27
+ function docUpdateAttributions(doc) {
28
+ return docScopes().get(doc);
29
+ }
30
+ function readVarUint({
31
+ bytes,
32
+ start
33
+ }) {
34
+ let value = 0;
35
+ let multiplier = 1;
36
+ for (let pos = start; pos < bytes.length; pos += 1) {
37
+ const byte = bytes[pos];
38
+ if (byte === void 0) return null;
39
+ value += (byte & 127) * multiplier;
40
+ if (byte < 128) return { value, next: pos + 1 };
41
+ multiplier *= 128;
42
+ if (multiplier > Number.MAX_SAFE_INTEGER) return null;
43
+ }
44
+ return null;
45
+ }
46
+ function writeVarUint({ out, value }) {
47
+ let rest = value;
48
+ while (rest > 127) {
49
+ out.push(128 | rest % 128);
50
+ rest = Math.floor(rest / 128);
51
+ }
52
+ out.push(rest);
53
+ }
54
+ function isBareSyncUpdate(message) {
55
+ const type = readVarUint({ bytes: message, start: 0 });
56
+ if ((type == null ? void 0 : type.value) !== MESSAGE_SYNC) return false;
57
+ const syncType = readVarUint({ bytes: message, start: type.next });
58
+ if ((syncType == null ? void 0 : syncType.value) !== MESSAGE_SYNC_UPDATE) return false;
59
+ const length = readVarUint({ bytes: message, start: syncType.next });
60
+ return length !== null && length.next + length.value === message.length;
61
+ }
62
+ function withUpdateAttributionsTrailer({
63
+ message,
64
+ attributions
65
+ }) {
66
+ if (attributions.length === 0 || !isBareSyncUpdate(message)) return message;
67
+ const trailer = [];
68
+ writeVarUint({ out: trailer, value: UPDATE_ATTRIBUTIONS_TRAILER_V1 });
69
+ writeVarUint({ out: trailer, value: attributions.length });
70
+ const utf8 = new TextEncoder();
71
+ for (const { k, v } of attributions) {
72
+ for (const text of [k, v]) {
73
+ const bytes = utf8.encode(text);
74
+ writeVarUint({ out: trailer, value: bytes.length });
75
+ for (const byte of bytes) trailer.push(byte);
76
+ }
77
+ }
78
+ const out = new Uint8Array(message.length + trailer.length);
79
+ out.set(message, 0);
80
+ out.set(trailer, message.length);
81
+ return out;
82
+ }
83
+ function receivedBytes(data) {
84
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
85
+ if (ArrayBuffer.isView(data))
86
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
87
+ return null;
88
+ }
89
+ function listenToFrames({
90
+ socket,
91
+ onFrame
92
+ }) {
93
+ if (!("addEventListener" in socket) || typeof socket.addEventListener !== "function") {
94
+ return false;
95
+ }
96
+ socket.addEventListener("message", (event) => {
97
+ const frame = receivedBytes(event.data);
98
+ if (frame) onFrame(frame);
99
+ });
100
+ return true;
101
+ }
102
+ function attributingWebSocket({
103
+ Base,
104
+ attributionsFor,
105
+ unconfirmed
106
+ }) {
107
+ if (typeof Base !== "function") return Base;
108
+ return new Proxy(Base, {
109
+ construct(target, args) {
110
+ const socket = Reflect.construct(target, args);
111
+ const send = socket.send.bind(socket);
112
+ let connection = null;
113
+ if (unconfirmed) {
114
+ const hears = listenToFrames({ socket, onFrame: (frame) => connection == null ? void 0 : connection.received(frame) });
115
+ connection = unconfirmed.connect({ send, hears });
116
+ }
117
+ socket.send = (data) => {
118
+ if (!(data instanceof Uint8Array)) {
119
+ send(data);
120
+ return;
121
+ }
122
+ const attributions = attributionsFor();
123
+ const message = attributions ? withUpdateAttributionsTrailer({ message: data, attributions }) : data;
124
+ if (connection) connection.send(message);
125
+ else send(message);
126
+ };
127
+ return socket;
128
+ }
129
+ });
130
+ }
131
+ export {
132
+ BACKGROUND_UPDATE_ATTRIBUTIONS,
133
+ UPDATE_ATTRIBUTIONS_TRAILER_V1,
134
+ attributingWebSocket,
135
+ docUpdateAttributions,
136
+ readVarUint,
137
+ runWithDocUpdateAttributions,
138
+ withUpdateAttributionsTrailer,
139
+ writeVarUint
140
+ };
141
+ //# sourceMappingURL=update-attributions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-attributions.js","sources":["../../../../keryx-http/src/update-attributions.ts"],"sourcesContent":["/**\n * Attributions one Keryx socket update carries of its own.\n *\n * A Keryx connection's attributions are fixed when its socket opens, so every update a client\n * sends is attributed to the person whose client it is. A write the client makes on its own (the\n * sheet leader re-issuing `=AOP` formulas or re-pushing `=IMPORTRANGE` values, a restored result,\n * an editor binding re-keying what an older binding stored) read as that person's edit and woke\n * \"people only\" subscriptions. Keryx reads a trailer after the update in a sync update message\n * (`readUpdateAttributions` in `patches/@y%2Fhub@0.10.1.patch`): `varUint(1)`, `varUint(n)`, then\n * `n` pairs of `varString` key and value. It accepts only `origin: background`, which it counts as\n * system work (`actorOf` in `keryx/src/compaction-activity.ts`), and the pairs that name a Quick\n * Edit step (`@athenaintel/keryx-http/quick-edit`: `session_id`/`run_kind` on the apply,\n * `quick_edit_undo`/`quick_edit_redo` with `quick_edit_op` on an undo or redo), each value in\n * exactly its shape. A Keryx without that hunk reads the update and ignores the bytes after it, so\n * a trailer never costs an update; a pair it does not allow is dropped and the rest kept.\n *\n * A writer marks its writes by making them inside {@link runWithDocUpdateAttributions} for the\n * doc; the transport's socket ({@link attributingWebSocket}) appends the trailer to each sync\n * update it sends while that scope is open. Both Keryx transports wrap their sockets with it:\n * Olympus's rooms (`KeryxYjsProviderV14`) and `@athenaintel/react/collab`'s `connectGenericDoc`\n * (Midas, the phone's editor page). y-websocket sends a local update from inside the doc's\n * `update` event, which fires inside the write itself, so the trailer always rides on the update\n * the scope wrote. A write made while the socket is closed is not sent then: it reaches Keryx in\n * the reconnect's sync step 2, which can carry no trailer. A transport that hands its socket the\n * room's {@link UnconfirmedAttributedWrites} (`@athenaintel/keryx-http/unconfirmed-update-attributions`)\n * sends each such write ahead of that sync step 2 as its own marked update; without one it stays\n * the person's.\n */\n\n/** One custom attribution, as Keryx stores it on the items an update wrote. */\nexport interface UpdateAttribution {\n k: string;\n v: string;\n}\n\n/** The pair a housekeeping write carries; Agora and Keryx spell it the same way. */\nexport const BACKGROUND_UPDATE_ATTRIBUTIONS: readonly UpdateAttribution[] = [\n { k: 'origin', v: 'background' },\n];\n\n/** The trailer format Keryx reads (`updateAttributionsTrailerV1`). */\nexport const UPDATE_ATTRIBUTIONS_TRAILER_V1 = 1;\n\n/** y-protocols: a sync message, and its update sub-type. */\nconst MESSAGE_SYNC = 0;\nconst MESSAGE_SYNC_UPDATE = 2;\n\n/**\n * The open scopes live on `globalThis`, not in module scope, because two copies of this module can\n * run in one page: `@athenaintel/react` bundles it into its dist (this package is private, so the\n * published SDK must inline it) while a host may import it from this package. A scope a writer\n * opens through one copy must be the one the transport's socket reads through the other.\n */\nconst DOC_SCOPES = Symbol.for('@athenaintel/keryx-http/update-attribution-scopes');\n\ntype DocScopesHost = typeof globalThis & {\n [DOC_SCOPES]?: WeakMap<object, readonly UpdateAttribution[]>;\n};\n\n// process-local: browser-only scopes, each keyed by the doc it guards and cleared in the same synchronous call that set it\nfunction docScopes(): WeakMap<object, readonly UpdateAttribution[]> {\n const host = globalThis as DocScopesHost;\n return (host[DOC_SCOPES] ??= new WeakMap());\n}\n\n/**\n * Run `run` with every update it writes into `doc` marked with `attributions`. Synchronous only:\n * the scope ends when `run` returns. Nested scopes restore the outer one.\n */\nexport function runWithDocUpdateAttributions<T>({\n doc,\n attributions,\n run,\n}: {\n doc: object;\n attributions: readonly UpdateAttribution[];\n run: () => T;\n}): T {\n const scopes = docScopes();\n const outer = scopes.get(doc);\n scopes.set(doc, attributions);\n try {\n return run();\n } finally {\n if (outer === undefined) scopes.delete(doc);\n else scopes.set(doc, outer);\n }\n}\n\n/** The attributions the update being written into `doc` right now carries, if any. */\nexport function docUpdateAttributions(doc: object): readonly UpdateAttribution[] | undefined {\n return docScopes().get(doc);\n}\n\n/** The lib0 varUint at `start` in `bytes` and where the next field begins; `null` past the end. */\nexport function readVarUint({\n bytes,\n start,\n}: {\n bytes: Uint8Array;\n start: number;\n}): { value: number; next: number } | null {\n let value = 0;\n let multiplier = 1;\n for (let pos = start; pos < bytes.length; pos += 1) {\n const byte = bytes[pos];\n if (byte === undefined) return null;\n value += (byte & 0x7f) * multiplier;\n if (byte < 0x80) return { value, next: pos + 1 };\n multiplier *= 0x80;\n if (multiplier > Number.MAX_SAFE_INTEGER) return null;\n }\n return null;\n}\n\n/** Append `value` to `out` as a lib0 varUint. */\nexport function writeVarUint({ out, value }: { out: number[]; value: number }): void {\n let rest = value;\n while (rest > 0x7f) {\n out.push(0x80 | (rest % 0x80));\n rest = Math.floor(rest / 0x80);\n }\n out.push(rest);\n}\n\n/** Exactly one sync update message, with nothing after the update. */\nfunction isBareSyncUpdate(message: Uint8Array): boolean {\n const type = readVarUint({ bytes: message, start: 0 });\n if (type?.value !== MESSAGE_SYNC) return false;\n const syncType = readVarUint({ bytes: message, start: type.next });\n if (syncType?.value !== MESSAGE_SYNC_UPDATE) return false;\n const length = readVarUint({ bytes: message, start: syncType.next });\n return length !== null && length.next + length.value === message.length;\n}\n\n/**\n * `message` with the trailer for `attributions` appended, when it is a bare sync update message;\n * any other message (sync step 1 or 2, awareness, one that already ends in a trailer) is returned\n * as it is.\n */\nexport function withUpdateAttributionsTrailer({\n message,\n attributions,\n}: {\n message: Uint8Array;\n attributions: readonly UpdateAttribution[];\n}): Uint8Array {\n if (attributions.length === 0 || !isBareSyncUpdate(message)) return message;\n const trailer: number[] = [];\n writeVarUint({ out: trailer, value: UPDATE_ATTRIBUTIONS_TRAILER_V1 });\n writeVarUint({ out: trailer, value: attributions.length });\n const utf8 = new TextEncoder();\n for (const { k, v } of attributions) {\n for (const text of [k, v]) {\n const bytes = utf8.encode(text);\n writeVarUint({ out: trailer, value: bytes.length });\n for (const byte of bytes) trailer.push(byte);\n }\n }\n const out = new Uint8Array(message.length + trailer.length);\n out.set(message, 0);\n out.set(trailer, message.length);\n return out;\n}\n\n/** What {@link attributingWebSocket} needs of a socket: the `send` y-websocket writes frames with. */\nexport interface SendingSocket {\n send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;\n}\n\n/** One socket of a room, as the room's attributed writes Keryx has not acknowledged see it. */\nexport interface AttributedWritesSocket {\n /** Keryx sent `frame` on the socket: what it carries, Keryx holds. */\n received(frame: Uint8Array): void;\n /** The socket sends `frame` (now, or once Keryx has sent what it holds; see the implementation). */\n send(frame: Uint8Array): void;\n}\n\n/**\n * The room's attributed writes Keryx has not acknowledged yet, as its sockets see them\n * (`UnconfirmedUpdateAttributions` in `@athenaintel/keryx-http/unconfirmed-update-attributions`).\n */\nexport interface UnconfirmedAttributedWrites {\n /**\n * A socket opened, sending through `send`. `hears`: the socket hands it every frame Keryx sends\n * (`received`), ahead of the transport.\n */\n connect(params: { send: (frame: Uint8Array) => void; hears: boolean }): AttributedWritesSocket;\n}\n\n/** The bytes of a binary frame a socket received, or `null` for one that is not (a string, a `Blob`). */\nfunction receivedBytes(data: unknown): Uint8Array | null {\n if (data instanceof ArrayBuffer) return new Uint8Array(data);\n if (ArrayBuffer.isView(data))\n return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);\n return null;\n}\n\n/**\n * Hands `onFrame` every binary frame `socket` receives; whether it can. A listener added before\n * y-websocket sets `onmessage` runs ahead of it. A socket without `addEventListener` hands nothing.\n */\nfunction listenToFrames({\n socket,\n onFrame,\n}: {\n socket: SendingSocket;\n onFrame: (frame: Uint8Array) => void;\n}): boolean {\n if (!('addEventListener' in socket) || typeof socket.addEventListener !== 'function') {\n return false;\n }\n socket.addEventListener('message', (event: { data?: unknown }) => {\n const frame = receivedBytes(event.data);\n if (frame) onFrame(frame);\n });\n return true;\n}\n\n/**\n * `Base` with `send` appending the trailer of `attributionsFor()` to each sync update it sends.\n * With the room's `unconfirmed` attributed writes, each socket also tells them every frame Keryx\n * sends and sends its frames through them, so a sync step 2 goes out behind the kept writes it\n * carries. A `Proxy` keeps the constructor's statics and type, so it drops in as y-websocket's\n * `WebSocketPolyfill`.\n */\nexport function attributingWebSocket<TBase extends new (...args: never[]) => SendingSocket>({\n Base,\n attributionsFor,\n unconfirmed,\n}: {\n Base: TBase;\n attributionsFor: () => readonly UpdateAttribution[] | undefined;\n unconfirmed?: UnconfirmedAttributedWrites;\n}): TBase {\n // No WebSocket where the provider is built (server render, a test without one): nothing to wrap,\n // and the transport fails at connect as it always did.\n if (typeof Base !== 'function') return Base;\n return new Proxy(Base, {\n construct(target, args) {\n const socket: SendingSocket = Reflect.construct(target, args);\n const send = socket.send.bind(socket);\n let connection: AttributedWritesSocket | null = null;\n if (unconfirmed) {\n const hears = listenToFrames({ socket, onFrame: (frame) => connection?.received(frame) });\n connection = unconfirmed.connect({ send, hears });\n }\n socket.send = (data) => {\n if (!(data instanceof Uint8Array)) {\n send(data);\n return;\n }\n const attributions = attributionsFor();\n const message = attributions\n ? withUpdateAttributionsTrailer({ message: data, attributions })\n : data;\n if (connection) connection.send(message);\n else send(message);\n };\n return socket;\n },\n });\n}\n"],"names":[],"mappings":"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"}
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
- const react = require("react");
5
- const OwnerDocumentContext = react.createContext(null);
4
+ const require$$0 = require("react");
5
+ const OwnerDocumentContext = require$$0.createContext(null);
6
6
  function OwnerDocumentProvider({ document: doc, children }) {
7
7
  return /* @__PURE__ */ jsxRuntime.jsx(OwnerDocumentContext.Provider, { value: doc, children });
8
8
  }
9
9
  function useOwnerDocument() {
10
- const provided = react.useContext(OwnerDocumentContext);
10
+ const provided = require$$0.useContext(OwnerDocumentContext);
11
11
  if (provided) return provided;
12
12
  return typeof document !== "undefined" ? document : null;
13
13
  }
14
14
  function useIsInPopoutDocument() {
15
- const provided = react.useContext(OwnerDocumentContext);
15
+ const provided = require$$0.useContext(OwnerDocumentContext);
16
16
  return provided !== null && typeof document !== "undefined" && provided !== document;
17
17
  }
18
18
  function usePortalContainer() {
19
- const provided = react.useContext(OwnerDocumentContext);
20
- return react.useMemo(() => {
19
+ const provided = require$$0.useContext(OwnerDocumentContext);
20
+ return require$$0.useMemo(() => {
21
21
  var _a;
22
22
  if (!provided) return void 0;
23
23
  if (typeof document !== "undefined" && provided === document) return void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"owner-document.cjs","sources":["../../src/lib/owner-document.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\n/**\n * Which browser document a component is rendered into.\n *\n * A host pops a pane out by portaling it into a second browser window (Olympus's\n * Spaces popouts, a desktop shell's pop-out windows): the React tree keeps\n * running in the main window while its DOM lives in the popout's document.\n * Anything that reaches for the global `document` then talks to the wrong\n * window — most visibly Radix/shadcn portals, which mount menus, dialogs and\n * tooltips into the MAIN window's body while their trigger sits in the popout.\n *\n * `OwnerDocumentProvider` is mounted by the host around every popped-out\n * subtree (Olympus's Spaces popout frame wraps every tab and the popout\n * window's own layout chrome). The SDK's own portaled UI (popover, tooltip,\n * the composer's mention menu) and the host's portals read the same context.\n * In the main window nothing is provided and the hooks fall back to the\n * globals, with `usePortalContainer()` returning `undefined` so every library\n * keeps its default container.\n */\nconst OwnerDocumentContext = createContext<Document | null>(null);\n\nexport interface OwnerDocumentProviderProps {\n /** The document hosting this subtree; `null` for the main window. */\n document: Document | null;\n children: ReactNode;\n}\n\nexport function OwnerDocumentProvider({ document: doc, children }: OwnerDocumentProviderProps) {\n return <OwnerDocumentContext.Provider value={doc}>{children}</OwnerDocumentContext.Provider>;\n}\n\n/** The document this subtree renders into, or the global document when not in a popout. */\nexport function useOwnerDocument(): Document | null {\n const provided = useContext(OwnerDocumentContext);\n if (provided) return provided;\n return typeof document !== 'undefined' ? document : null;\n}\n\n/** `true` when the subtree is hosted by a popout window rather than the main document. */\nexport function useIsInPopoutDocument(): boolean {\n const provided = useContext(OwnerDocumentContext);\n return provided !== null && typeof document !== 'undefined' && provided !== document;\n}\n\n/**\n * The `container` to hand a portal so it opens in the window its trigger is\n * in: the popout's `body`, or `undefined` in the main window so the library\n * default applies. Guards against a since-closed popout window.\n */\nexport function usePortalContainer(): HTMLElement | undefined {\n const provided = useContext(OwnerDocumentContext);\n return useMemo(() => {\n if (!provided) return undefined;\n if (typeof document !== 'undefined' && provided === document) return undefined;\n if (provided.defaultView?.closed) return undefined;\n return provided.body;\n }, [provided]);\n}\n"],"names":["createContext","useContext","useMemo"],"mappings":";;;;AAsBA,MAAM,uBAAuBA,MAAAA,cAA+B,IAAI;AAQzD,SAAS,sBAAsB,EAAE,UAAU,KAAK,YAAwC;AAC7F,wCAAQ,qBAAqB,UAArB,EAA8B,OAAO,KAAM,UAAS;AAC9D;AAGO,SAAS,mBAAoC;AAClD,QAAM,WAAWC,MAAAA,WAAW,oBAAoB;AAChD,MAAI,SAAU,QAAO;AACrB,SAAO,OAAO,aAAa,cAAc,WAAW;AACtD;AAGO,SAAS,wBAAiC;AAC/C,QAAM,WAAWA,MAAAA,WAAW,oBAAoB;AAChD,SAAO,aAAa,QAAQ,OAAO,aAAa,eAAe,aAAa;AAC9E;AAOO,SAAS,qBAA8C;AAC5D,QAAM,WAAWA,MAAAA,WAAW,oBAAoB;AAChD,SAAOC,MAAAA,QAAQ,MAAM;;AACnB,QAAI,CAAC,SAAU,QAAO;AACtB,QAAI,OAAO,aAAa,eAAe,aAAa,SAAU,QAAO;AACrE,SAAI,cAAS,gBAAT,mBAAsB,OAAQ,QAAO;AACzC,WAAO,SAAS;AAAA,EAClB,GAAG,CAAC,QAAQ,CAAC;AACf;;;;;"}
1
+ {"version":3,"file":"owner-document.cjs","sources":["../../src/lib/owner-document.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\n/**\n * Which browser document a component is rendered into.\n *\n * A host pops a pane out by portaling it into a second browser window (Olympus's\n * Spaces popouts, a desktop shell's pop-out windows): the React tree keeps\n * running in the main window while its DOM lives in the popout's document.\n * Anything that reaches for the global `document` then talks to the wrong\n * window — most visibly Radix/shadcn portals, which mount menus, dialogs and\n * tooltips into the MAIN window's body while their trigger sits in the popout.\n *\n * `OwnerDocumentProvider` is mounted by the host around every popped-out\n * subtree (Olympus's Spaces popout frame wraps every tab and the popout\n * window's own layout chrome). The SDK's own portaled UI (popover, tooltip,\n * the composer's mention menu) and the host's portals read the same context.\n * In the main window nothing is provided and the hooks fall back to the\n * globals, with `usePortalContainer()` returning `undefined` so every library\n * keeps its default container.\n */\nconst OwnerDocumentContext = createContext<Document | null>(null);\n\nexport interface OwnerDocumentProviderProps {\n /** The document hosting this subtree; `null` for the main window. */\n document: Document | null;\n children: ReactNode;\n}\n\nexport function OwnerDocumentProvider({ document: doc, children }: OwnerDocumentProviderProps) {\n return <OwnerDocumentContext.Provider value={doc}>{children}</OwnerDocumentContext.Provider>;\n}\n\n/** The document this subtree renders into, or the global document when not in a popout. */\nexport function useOwnerDocument(): Document | null {\n const provided = useContext(OwnerDocumentContext);\n if (provided) return provided;\n return typeof document !== 'undefined' ? document : null;\n}\n\n/** `true` when the subtree is hosted by a popout window rather than the main document. */\nexport function useIsInPopoutDocument(): boolean {\n const provided = useContext(OwnerDocumentContext);\n return provided !== null && typeof document !== 'undefined' && provided !== document;\n}\n\n/**\n * The `container` to hand a portal so it opens in the window its trigger is\n * in: the popout's `body`, or `undefined` in the main window so the library\n * default applies. Guards against a since-closed popout window.\n */\nexport function usePortalContainer(): HTMLElement | undefined {\n const provided = useContext(OwnerDocumentContext);\n return useMemo(() => {\n if (!provided) return undefined;\n if (typeof document !== 'undefined' && provided === document) return undefined;\n if (provided.defaultView?.closed) return undefined;\n return provided.body;\n }, [provided]);\n}\n"],"names":["createContext","useContext","useMemo"],"mappings":";;;;AAsBA,MAAM,uBAAuBA,WAAAA,cAA+B,IAAI;AAQzD,SAAS,sBAAsB,EAAE,UAAU,KAAK,YAAwC;AAC7F,wCAAQ,qBAAqB,UAArB,EAA8B,OAAO,KAAM,UAAS;AAC9D;AAGO,SAAS,mBAAoC;AAClD,QAAM,WAAWC,WAAAA,WAAW,oBAAoB;AAChD,MAAI,SAAU,QAAO;AACrB,SAAO,OAAO,aAAa,cAAc,WAAW;AACtD;AAGO,SAAS,wBAAiC;AAC/C,QAAM,WAAWA,WAAAA,WAAW,oBAAoB;AAChD,SAAO,aAAa,QAAQ,OAAO,aAAa,eAAe,aAAa;AAC9E;AAOO,SAAS,qBAA8C;AAC5D,QAAM,WAAWA,WAAAA,WAAW,oBAAoB;AAChD,SAAOC,WAAAA,QAAQ,MAAM;;AACnB,QAAI,CAAC,SAAU,QAAO;AACtB,QAAI,OAAO,aAAa,eAAe,aAAa,SAAU,QAAO;AACrE,SAAI,cAAS,gBAAT,mBAAsB,OAAQ,QAAO;AACzC,WAAO,SAAS;AAAA,EAClB,GAAG,CAAC,QAAQ,CAAC;AACf;;;;;"}
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const reactQuery = require("@tanstack/react-query");
4
- const react = require("react");
4
+ const require$$0 = require("react");
5
5
  const AthenaAuthContext = require("../auth/AthenaAuthContext.cjs");
6
6
  function useAthenaQueryClient() {
7
- const contextClient = react.useContext(reactQuery.QueryClientContext);
8
- const fallbackRef = react.useRef(null);
7
+ const contextClient = require$$0.useContext(reactQuery.QueryClientContext);
8
+ const fallbackRef = require$$0.useRef(null);
9
9
  if (contextClient) return contextClient;
10
10
  fallbackRef.current ?? (fallbackRef.current = new reactQuery.QueryClient());
11
11
  return fallbackRef.current;
@@ -28,7 +28,7 @@ function credentialFingerprint(auth) {
28
28
  }
29
29
  function useAthenaQueryIdentity(auth) {
30
30
  var _a, _b;
31
- const principal = ((_b = (_a = react.useContext(AthenaAuthContext.AthenaAuthContext)) == null ? void 0 : _a.user) == null ? void 0 : _b.userId) ?? "";
31
+ const principal = ((_b = (_a = require$$0.useContext(AthenaAuthContext.AthenaAuthContext)) == null ? void 0 : _a.user) == null ? void 0 : _b.userId) ?? "";
32
32
  return [principal, credentialFingerprint(auth)];
33
33
  }
34
34
  exports.credentialFingerprint = credentialFingerprint;
@@ -1 +1 @@
1
- {"version":3,"file":"use-athena-rest-query.cjs","sources":["../../src/lib/use-athena-rest-query.ts"],"sourcesContent":["/**\n * The two pieces every SDK hook that reads an Agora REST route through\n * TanStack Query needs: a `QueryClient` under any `<AthenaProvider>`, and a\n * query-key component naming who the read is made as — without ever putting\n * the credential itself in a key.\n */\nimport { QueryClient, QueryClientContext } from '@tanstack/react-query';\nimport { useContext, useRef } from 'react';\nimport { AthenaAuthContext } from '../auth/AthenaAuthContext';\nimport type { StatewireAuthSource } from '../runtime/statewire-auth-headers';\n\n/**\n * The host's `QueryClient` when one is in context (`enableThreadList` mounts\n * the SDK's own), else a client scoped to the calling hook's component.\n */\nexport function useAthenaQueryClient(): QueryClient {\n const contextClient = useContext(QueryClientContext);\n const fallbackRef = useRef<QueryClient | null>(null);\n if (contextClient) return contextClient;\n fallbackRef.current ??= new QueryClient();\n return fallbackRef.current;\n}\n\n/** 32-bit FNV-1a of `text`, as hex. */\nfunction fnv1a(text: string): string {\n let hash = 0x811c9dc5;\n for (let index = 0; index < text.length; index += 1) {\n hash ^= text.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16).padStart(8, '0');\n}\n\n/**\n * A one-way fingerprint of a query-key part that can carry a credential (an\n * opaque token or an API key inside an identity string), so the key names\n * whose it is without holding the secret.\n */\nexport function keyPartFingerprint(text: string): string {\n return fnv1a(text);\n}\n\n/**\n * A short, one-way fingerprint of the credential a request presents (the API\n * key, the token the host holds, whether a live `getToken` resolves it). It is\n * the same for every hook and every mount that reads with the same\n * credential, and different once the credential changes, so a cache entry\n * written with one credential is never read with another — while the key\n * itself carries 32 bits of hash, never the secret.\n */\nexport function credentialFingerprint(auth: StatewireAuthSource): string {\n return fnv1a(\n [auth.apiKey ?? '', auth.token ?? '', auth.getToken === undefined ? '0' : '1'].join('\\u0000'),\n );\n}\n\n/**\n * Who a query reads as, for its key: the signed-in principal (`''` when the\n * provider knows none) and the credential fingerprint. The principal covers\n * an identity switch the credential cannot show — a stable `getToken`, or a\n * same-origin cookie; the fingerprint covers a swapped API key or token. Both\n * are stable across mounts, so a pane mounted after a switch never reads the\n * previous account's cached answer.\n */\nexport function useAthenaQueryIdentity(auth: StatewireAuthSource): readonly [string, string] {\n const principal = useContext(AthenaAuthContext)?.user?.userId ?? '';\n return [principal, credentialFingerprint(auth)];\n}\n"],"names":["useContext","QueryClientContext","useRef","QueryClient","AthenaAuthContext"],"mappings":";;;;;AAeO,SAAS,uBAAoC;AAClD,QAAM,gBAAgBA,MAAAA,WAAWC,6BAAkB;AACnD,QAAM,cAAcC,MAAAA,OAA2B,IAAI;AACnD,MAAI,cAAe,QAAO;AAC1B,cAAY,YAAZ,YAAY,UAAY,IAAIC,uBAAA;AAC5B,SAAO,YAAY;AACrB;AAGA,SAAS,MAAM,MAAsB;AACnC,MAAI,OAAO;AACX,WAAS,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;AACnD,YAAQ,KAAK,WAAW,KAAK;AAC7B,WAAO,KAAK,KAAK,MAAM,QAAU;AAAA,EACnC;AACA,UAAQ,SAAS,GAAG,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAClD;AAOO,SAAS,mBAAmB,MAAsB;AACvD,SAAO,MAAM,IAAI;AACnB;AAUO,SAAS,sBAAsB,MAAmC;AACvE,SAAO;AAAA,IACL,CAAC,KAAK,UAAU,IAAI,KAAK,SAAS,IAAI,KAAK,aAAa,SAAY,MAAM,GAAG,EAAE,KAAK,IAAQ;AAAA,EAAA;AAEhG;AAUO,SAAS,uBAAuB,MAAsD;;AAC3F,QAAM,cAAYH,iBAAAA,WAAWI,kBAAAA,iBAAiB,MAA5BJ,mBAA+B,SAA/BA,mBAAqC,WAAU;AACjE,SAAO,CAAC,WAAW,sBAAsB,IAAI,CAAC;AAChD;;;;;"}
1
+ {"version":3,"file":"use-athena-rest-query.cjs","sources":["../../src/lib/use-athena-rest-query.ts"],"sourcesContent":["/**\n * The two pieces every SDK hook that reads an Agora REST route through\n * TanStack Query needs: a `QueryClient` under any `<AthenaProvider>`, and a\n * query-key component naming who the read is made as — without ever putting\n * the credential itself in a key.\n */\nimport { QueryClient, QueryClientContext } from '@tanstack/react-query';\nimport { useContext, useRef } from 'react';\nimport { AthenaAuthContext } from '../auth/AthenaAuthContext';\nimport type { StatewireAuthSource } from '../runtime/statewire-auth-headers';\n\n/**\n * The host's `QueryClient` when one is in context (`enableThreadList` mounts\n * the SDK's own), else a client scoped to the calling hook's component.\n */\nexport function useAthenaQueryClient(): QueryClient {\n const contextClient = useContext(QueryClientContext);\n const fallbackRef = useRef<QueryClient | null>(null);\n if (contextClient) return contextClient;\n fallbackRef.current ??= new QueryClient();\n return fallbackRef.current;\n}\n\n/** 32-bit FNV-1a of `text`, as hex. */\nfunction fnv1a(text: string): string {\n let hash = 0x811c9dc5;\n for (let index = 0; index < text.length; index += 1) {\n hash ^= text.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16).padStart(8, '0');\n}\n\n/**\n * A one-way fingerprint of a query-key part that can carry a credential (an\n * opaque token or an API key inside an identity string), so the key names\n * whose it is without holding the secret.\n */\nexport function keyPartFingerprint(text: string): string {\n return fnv1a(text);\n}\n\n/**\n * A short, one-way fingerprint of the credential a request presents (the API\n * key, the token the host holds, whether a live `getToken` resolves it). It is\n * the same for every hook and every mount that reads with the same\n * credential, and different once the credential changes, so a cache entry\n * written with one credential is never read with another — while the key\n * itself carries 32 bits of hash, never the secret.\n */\nexport function credentialFingerprint(auth: StatewireAuthSource): string {\n return fnv1a(\n [auth.apiKey ?? '', auth.token ?? '', auth.getToken === undefined ? '0' : '1'].join('\\u0000'),\n );\n}\n\n/**\n * Who a query reads as, for its key: the signed-in principal (`''` when the\n * provider knows none) and the credential fingerprint. The principal covers\n * an identity switch the credential cannot show — a stable `getToken`, or a\n * same-origin cookie; the fingerprint covers a swapped API key or token. Both\n * are stable across mounts, so a pane mounted after a switch never reads the\n * previous account's cached answer.\n */\nexport function useAthenaQueryIdentity(auth: StatewireAuthSource): readonly [string, string] {\n const principal = useContext(AthenaAuthContext)?.user?.userId ?? '';\n return [principal, credentialFingerprint(auth)];\n}\n"],"names":["useContext","QueryClientContext","useRef","QueryClient","AthenaAuthContext"],"mappings":";;;;;AAeO,SAAS,uBAAoC;AAClD,QAAM,gBAAgBA,WAAAA,WAAWC,6BAAkB;AACnD,QAAM,cAAcC,WAAAA,OAA2B,IAAI;AACnD,MAAI,cAAe,QAAO;AAC1B,cAAY,YAAZ,YAAY,UAAY,IAAIC,uBAAA;AAC5B,SAAO,YAAY;AACrB;AAGA,SAAS,MAAM,MAAsB;AACnC,MAAI,OAAO;AACX,WAAS,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;AACnD,YAAQ,KAAK,WAAW,KAAK;AAC7B,WAAO,KAAK,KAAK,MAAM,QAAU;AAAA,EACnC;AACA,UAAQ,SAAS,GAAG,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAClD;AAOO,SAAS,mBAAmB,MAAsB;AACvD,SAAO,MAAM,IAAI;AACnB;AAUO,SAAS,sBAAsB,MAAmC;AACvE,SAAO;AAAA,IACL,CAAC,KAAK,UAAU,IAAI,KAAK,SAAS,IAAI,KAAK,aAAa,SAAY,MAAM,GAAG,EAAE,KAAK,IAAQ;AAAA,EAAA;AAEhG;AAUO,SAAS,uBAAuB,MAAsD;;AAC3F,QAAM,cAAYH,sBAAAA,WAAWI,kBAAAA,iBAAiB,MAA5BJ,mBAA+B,SAA/BA,mBAAqC,WAAU;AACjE,SAAO,CAAC,WAAW,sBAAsB,IAAI,CAAC;AAChD;;;;;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const react = require("react");
3
+ const require$$0 = require("react");
4
4
  function isActive(doc) {
5
5
  if (!doc) return false;
6
6
  return doc.visibilityState === "visible" && doc.hasFocus();
@@ -32,9 +32,9 @@ function subscribeTo(doc, onChange) {
32
32
  };
33
33
  }
34
34
  function useDocumentActive(doc) {
35
- const subscribe = react.useCallback((onChange) => subscribeTo(doc, onChange), [doc]);
36
- const getSnapshot = react.useCallback(() => isActive(doc), [doc]);
37
- return react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
35
+ const subscribe = require$$0.useCallback((onChange) => subscribeTo(doc, onChange), [doc]);
36
+ const getSnapshot = require$$0.useCallback(() => isActive(doc), [doc]);
37
+ return require$$0.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
38
38
  }
39
39
  exports.useDocumentActive = useDocumentActive;
40
40
  //# sourceMappingURL=use-document-active.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-document-active.cjs","sources":["../../src/lib/use-document-active.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\n\nfunction isActive(doc: Document | null): boolean {\n if (!doc) return false;\n return doc.visibilityState === 'visible' && doc.hasFocus();\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\nfunction subscribeTo(doc: Document | null, onChange: () => void): () => void {\n const view = doc?.defaultView;\n if (!doc || !view) return () => {};\n let afterBlur: ReturnType<typeof setTimeout> | null = null;\n // `blur` fires before focus has landed. Focus that moved into a frame of\n // this page (a computer's live desktop, an embedded asset) leaves the\n // document focused, so it is read again once the browser has moved it.\n const onBlur = () => {\n onChange();\n if (afterBlur !== null) clearTimeout(afterBlur);\n afterBlur = setTimeout(() => {\n afterBlur = null;\n onChange();\n }, 0);\n };\n view.addEventListener('focus', onChange);\n view.addEventListener('blur', onBlur);\n doc.addEventListener('visibilitychange', onChange);\n return () => {\n view.removeEventListener('focus', onChange);\n view.removeEventListener('blur', onBlur);\n doc.removeEventListener('visibilitychange', onChange);\n if (afterBlur !== null) clearTimeout(afterBlur);\n };\n}\n\n/**\n * Whether `doc` is in front of the person: visible and focused\n * (`hasFocus()`, which stays true while focus is inside a frame of the page).\n * Pass the document a subtree renders into (`useOwnerDocument()`), so a pane\n * popped out into another window reads that window. Re-read on its window's\n * `focus` / `blur` and its `visibilitychange`; nothing polls. `false` on the\n * server and without a document.\n */\nexport function useDocumentActive(doc: Document | null): boolean {\n const subscribe = useCallback((onChange: () => void) => subscribeTo(doc, onChange), [doc]);\n const getSnapshot = useCallback(() => isActive(doc), [doc]);\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"],"names":["useCallback","useSyncExternalStore"],"mappings":";;;AAEA,SAAS,SAAS,KAA+B;AAC/C,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,IAAI,oBAAoB,aAAa,IAAI,SAAA;AAClD;AAEA,SAAS,oBAA6B;AACpC,SAAO;AACT;AAEA,SAAS,YAAY,KAAsB,UAAkC;AAC3E,QAAM,OAAO,2BAAK;AAClB,MAAI,CAAC,OAAO,CAAC,aAAa,MAAM;AAAA,EAAC;AACjC,MAAI,YAAkD;AAItD,QAAM,SAAS,MAAM;AACnB,aAAA;AACA,QAAI,cAAc,KAAM,cAAa,SAAS;AAC9C,gBAAY,WAAW,MAAM;AAC3B,kBAAY;AACZ,eAAA;AAAA,IACF,GAAG,CAAC;AAAA,EACN;AACA,OAAK,iBAAiB,SAAS,QAAQ;AACvC,OAAK,iBAAiB,QAAQ,MAAM;AACpC,MAAI,iBAAiB,oBAAoB,QAAQ;AACjD,SAAO,MAAM;AACX,SAAK,oBAAoB,SAAS,QAAQ;AAC1C,SAAK,oBAAoB,QAAQ,MAAM;AACvC,QAAI,oBAAoB,oBAAoB,QAAQ;AACpD,QAAI,cAAc,KAAM,cAAa,SAAS;AAAA,EAChD;AACF;AAUO,SAAS,kBAAkB,KAA+B;AAC/D,QAAM,YAAYA,kBAAY,CAAC,aAAyB,YAAY,KAAK,QAAQ,GAAG,CAAC,GAAG,CAAC;AACzF,QAAM,cAAcA,MAAAA,YAAY,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC;AAC1D,SAAOC,2BAAqB,WAAW,aAAa,iBAAiB;AACvE;;"}
1
+ {"version":3,"file":"use-document-active.cjs","sources":["../../src/lib/use-document-active.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\n\nfunction isActive(doc: Document | null): boolean {\n if (!doc) return false;\n return doc.visibilityState === 'visible' && doc.hasFocus();\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\nfunction subscribeTo(doc: Document | null, onChange: () => void): () => void {\n const view = doc?.defaultView;\n if (!doc || !view) return () => {};\n let afterBlur: ReturnType<typeof setTimeout> | null = null;\n // `blur` fires before focus has landed. Focus that moved into a frame of\n // this page (a computer's live desktop, an embedded asset) leaves the\n // document focused, so it is read again once the browser has moved it.\n const onBlur = () => {\n onChange();\n if (afterBlur !== null) clearTimeout(afterBlur);\n afterBlur = setTimeout(() => {\n afterBlur = null;\n onChange();\n }, 0);\n };\n view.addEventListener('focus', onChange);\n view.addEventListener('blur', onBlur);\n doc.addEventListener('visibilitychange', onChange);\n return () => {\n view.removeEventListener('focus', onChange);\n view.removeEventListener('blur', onBlur);\n doc.removeEventListener('visibilitychange', onChange);\n if (afterBlur !== null) clearTimeout(afterBlur);\n };\n}\n\n/**\n * Whether `doc` is in front of the person: visible and focused\n * (`hasFocus()`, which stays true while focus is inside a frame of the page).\n * Pass the document a subtree renders into (`useOwnerDocument()`), so a pane\n * popped out into another window reads that window. Re-read on its window's\n * `focus` / `blur` and its `visibilitychange`; nothing polls. `false` on the\n * server and without a document.\n */\nexport function useDocumentActive(doc: Document | null): boolean {\n const subscribe = useCallback((onChange: () => void) => subscribeTo(doc, onChange), [doc]);\n const getSnapshot = useCallback(() => isActive(doc), [doc]);\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n}\n"],"names":["useCallback","useSyncExternalStore"],"mappings":";;;AAEA,SAAS,SAAS,KAA+B;AAC/C,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,IAAI,oBAAoB,aAAa,IAAI,SAAA;AAClD;AAEA,SAAS,oBAA6B;AACpC,SAAO;AACT;AAEA,SAAS,YAAY,KAAsB,UAAkC;AAC3E,QAAM,OAAO,2BAAK;AAClB,MAAI,CAAC,OAAO,CAAC,aAAa,MAAM;AAAA,EAAC;AACjC,MAAI,YAAkD;AAItD,QAAM,SAAS,MAAM;AACnB,aAAA;AACA,QAAI,cAAc,KAAM,cAAa,SAAS;AAC9C,gBAAY,WAAW,MAAM;AAC3B,kBAAY;AACZ,eAAA;AAAA,IACF,GAAG,CAAC;AAAA,EACN;AACA,OAAK,iBAAiB,SAAS,QAAQ;AACvC,OAAK,iBAAiB,QAAQ,MAAM;AACpC,MAAI,iBAAiB,oBAAoB,QAAQ;AACjD,SAAO,MAAM;AACX,SAAK,oBAAoB,SAAS,QAAQ;AAC1C,SAAK,oBAAoB,QAAQ,MAAM;AACvC,QAAI,oBAAoB,oBAAoB,QAAQ;AACpD,QAAI,cAAc,KAAM,cAAa,SAAS;AAAA,EAChD;AACF;AAUO,SAAS,kBAAkB,KAA+B;AAC/D,QAAM,YAAYA,uBAAY,CAAC,aAAyB,YAAY,KAAK,QAAQ,GAAG,CAAC,GAAG,CAAC;AACzF,QAAM,cAAcA,WAAAA,YAAY,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC;AAC1D,SAAOC,gCAAqB,WAAW,aAAa,iBAAiB;AACvE;;"}