@athenaintel/react 0.41.3 → 0.42.1

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 (439) hide show
  1. package/README.md +102 -9
  2. package/dist/agent-runtime/src/asset-attachment.d.ts +98 -0
  3. package/dist/agent-runtime/src/athena-asset-drag.d.ts +32 -0
  4. package/dist/agent-runtime/src/auth-denial.d.ts +29 -0
  5. package/dist/agent-runtime/src/chat-outbox-attachments.cjs +41 -0
  6. package/dist/agent-runtime/src/chat-outbox-attachments.cjs.map +1 -0
  7. package/dist/agent-runtime/src/chat-outbox-attachments.d.ts +38 -0
  8. package/dist/agent-runtime/src/chat-outbox-attachments.js +41 -0
  9. package/dist/agent-runtime/src/chat-outbox-attachments.js.map +1 -0
  10. package/dist/agent-runtime/src/chat-outbox-signals.cjs +63 -0
  11. package/dist/agent-runtime/src/chat-outbox-signals.cjs.map +1 -0
  12. package/dist/agent-runtime/src/chat-outbox-signals.d.ts +12 -0
  13. package/dist/agent-runtime/src/chat-outbox-signals.js +63 -0
  14. package/dist/agent-runtime/src/chat-outbox-signals.js.map +1 -0
  15. package/dist/agent-runtime/src/chat-outbox-store.cjs +509 -0
  16. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +1 -0
  17. package/dist/agent-runtime/src/chat-outbox-store.d.ts +203 -0
  18. package/dist/agent-runtime/src/chat-outbox-store.js +509 -0
  19. package/dist/agent-runtime/src/chat-outbox-store.js.map +1 -0
  20. package/dist/agent-runtime/src/chat-outbox-thread.cjs +136 -0
  21. package/dist/agent-runtime/src/chat-outbox-thread.cjs.map +1 -0
  22. package/dist/agent-runtime/src/chat-outbox-thread.d.ts +118 -0
  23. package/dist/agent-runtime/src/chat-outbox-thread.js +136 -0
  24. package/dist/agent-runtime/src/chat-outbox-thread.js.map +1 -0
  25. package/dist/agent-runtime/src/chat-outbox.cjs +696 -0
  26. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -0
  27. package/dist/agent-runtime/src/chat-outbox.d.ts +285 -0
  28. package/dist/agent-runtime/src/chat-outbox.js +696 -0
  29. package/dist/agent-runtime/src/chat-outbox.js.map +1 -0
  30. package/dist/agent-runtime/src/chat-socket-reachability.d.ts +45 -0
  31. package/dist/agent-runtime/src/client-tool-bridge.d.ts +152 -0
  32. package/dist/agent-runtime/src/client-tools.d.ts +133 -0
  33. package/dist/agent-runtime/src/composer-markdown.cjs +10 -0
  34. package/dist/agent-runtime/src/composer-markdown.cjs.map +1 -1
  35. package/dist/agent-runtime/src/composer-markdown.d.ts +108 -0
  36. package/dist/agent-runtime/src/composer-markdown.js +10 -0
  37. package/dist/agent-runtime/src/composer-markdown.js.map +1 -1
  38. package/dist/agent-runtime/src/config-mutations.d.ts +51 -0
  39. package/dist/agent-runtime/src/conversation-index.d.ts +110 -0
  40. package/dist/agent-runtime/src/conversation-list.d.ts +343 -0
  41. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs +3 -2
  42. package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs.map +1 -1
  43. package/dist/agent-runtime/src/deep-agent-transport-recipe.d.ts +166 -0
  44. package/dist/agent-runtime/src/deep-agent-transport-recipe.js +3 -2
  45. package/dist/agent-runtime/src/deep-agent-transport-recipe.js.map +1 -1
  46. package/dist/agent-runtime/src/desktop-handoff.d.ts +139 -0
  47. package/dist/agent-runtime/src/durable-thread-snapshot-cache.d.ts +60 -0
  48. package/dist/agent-runtime/src/edit-command.d.ts +156 -0
  49. package/dist/agent-runtime/src/errors.d.ts +174 -0
  50. package/dist/agent-runtime/src/execute-output.d.ts +31 -0
  51. package/dist/agent-runtime/src/generated/runconfig-contract.cjs +16 -2
  52. package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  53. package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +202 -0
  54. package/dist/agent-runtime/src/generated/runconfig-contract.js +16 -2
  55. package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  56. package/dist/agent-runtime/src/github-wake-event.d.ts +77 -0
  57. package/dist/agent-runtime/src/index.d.ts +74 -0
  58. package/dist/agent-runtime/src/interrupts.cjs +17 -0
  59. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  60. package/dist/agent-runtime/src/interrupts.d.ts +348 -0
  61. package/dist/agent-runtime/src/interrupts.js +17 -0
  62. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  63. package/dist/agent-runtime/src/lane-follow.d.ts +121 -0
  64. package/dist/agent-runtime/src/lane-history.cjs +209 -0
  65. package/dist/agent-runtime/src/lane-history.cjs.map +1 -0
  66. package/dist/agent-runtime/src/lane-history.d.ts +175 -0
  67. package/dist/agent-runtime/src/lane-history.js +209 -0
  68. package/dist/agent-runtime/src/lane-history.js.map +1 -0
  69. package/dist/agent-runtime/src/lane-images.d.ts +184 -0
  70. package/dist/agent-runtime/src/message-author.d.ts +43 -0
  71. package/dist/agent-runtime/src/message-text.cjs +15 -0
  72. package/dist/agent-runtime/src/message-text.cjs.map +1 -0
  73. package/dist/agent-runtime/src/message-text.d.ts +47 -0
  74. package/dist/agent-runtime/src/message-text.js +15 -0
  75. package/dist/agent-runtime/src/message-text.js.map +1 -0
  76. package/dist/agent-runtime/src/message-window.cjs +15 -1
  77. package/dist/agent-runtime/src/message-window.cjs.map +1 -1
  78. package/dist/agent-runtime/src/message-window.d.ts +159 -0
  79. package/dist/agent-runtime/src/message-window.js +16 -2
  80. package/dist/agent-runtime/src/message-window.js.map +1 -1
  81. package/dist/agent-runtime/src/messages.cjs +88 -4
  82. package/dist/agent-runtime/src/messages.cjs.map +1 -1
  83. package/dist/agent-runtime/src/messages.d.ts +603 -0
  84. package/dist/agent-runtime/src/messages.js +88 -4
  85. package/dist/agent-runtime/src/messages.js.map +1 -1
  86. package/dist/agent-runtime/src/model-context.d.ts +22 -0
  87. package/dist/agent-runtime/src/offline-status.d.ts +157 -0
  88. package/dist/agent-runtime/src/optimistic-content.d.ts +21 -0
  89. package/dist/agent-runtime/src/protocol.cjs +12 -4
  90. package/dist/agent-runtime/src/protocol.cjs.map +1 -1
  91. package/dist/agent-runtime/src/protocol.d.ts +119 -0
  92. package/dist/agent-runtime/src/protocol.js +13 -5
  93. package/dist/agent-runtime/src/protocol.js.map +1 -1
  94. package/dist/agent-runtime/src/ptc-subcalls.d.ts +51 -0
  95. package/dist/agent-runtime/src/queue.d.ts +138 -0
  96. package/dist/agent-runtime/src/quota-safe-local-storage-session.d.ts +154 -0
  97. package/dist/agent-runtime/src/running-tool-placeholder.cjs +11 -0
  98. package/dist/agent-runtime/src/running-tool-placeholder.cjs.map +1 -0
  99. package/dist/agent-runtime/src/running-tool-placeholder.d.ts +25 -0
  100. package/dist/agent-runtime/src/running-tool-placeholder.js +11 -0
  101. package/dist/agent-runtime/src/running-tool-placeholder.js.map +1 -0
  102. package/dist/agent-runtime/src/runtime-messages.d.ts +104 -0
  103. package/dist/agent-runtime/src/screen-point.d.ts +151 -0
  104. package/dist/agent-runtime/src/sealed-idb.cjs +112 -0
  105. package/dist/agent-runtime/src/sealed-idb.cjs.map +1 -0
  106. package/dist/agent-runtime/src/sealed-idb.d.ts +106 -0
  107. package/dist/agent-runtime/src/sealed-idb.js +112 -0
  108. package/dist/agent-runtime/src/sealed-idb.js.map +1 -0
  109. package/dist/agent-runtime/src/send-recovery.d.ts +40 -0
  110. package/dist/agent-runtime/src/statewire-attach-observer.d.ts +194 -0
  111. package/dist/agent-runtime/src/statewire-diagnostics.d.ts +74 -0
  112. package/dist/agent-runtime/src/statewire-state.d.ts +29 -0
  113. package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
  114. package/dist/agent-runtime/src/statewire-suspended.d.ts +27 -0
  115. package/dist/agent-runtime/src/statewire-suspended.js.map +1 -1
  116. package/dist/agent-runtime/src/statewire-transport.d.ts +40 -0
  117. package/dist/agent-runtime/src/streaming-markdown.d.ts +46 -0
  118. package/dist/agent-runtime/src/subagent-transcripts.cjs +209 -0
  119. package/dist/agent-runtime/src/subagent-transcripts.cjs.map +1 -0
  120. package/dist/agent-runtime/src/subagent-transcripts.d.ts +71 -0
  121. package/dist/agent-runtime/src/subagent-transcripts.js +209 -0
  122. package/dist/agent-runtime/src/subagent-transcripts.js.map +1 -0
  123. package/dist/agent-runtime/src/subagents.cjs +253 -0
  124. package/dist/agent-runtime/src/subagents.cjs.map +1 -0
  125. package/dist/agent-runtime/src/subagents.d.ts +311 -0
  126. package/dist/agent-runtime/src/subagents.js +253 -0
  127. package/dist/agent-runtime/src/subagents.js.map +1 -0
  128. package/dist/agent-runtime/src/subscription-wake-event.d.ts +111 -0
  129. package/dist/agent-runtime/src/thread-extras.d.ts +43 -0
  130. package/dist/agent-runtime/src/thread-handoff.d.ts +364 -0
  131. package/dist/agent-runtime/src/thread-prewarm-controller.d.ts +76 -0
  132. package/dist/agent-runtime/src/thread-prewarm.d.ts +118 -0
  133. package/dist/agent-runtime/src/thread-snapshot-cache.d.ts +99 -0
  134. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs +46 -117
  135. package/dist/agent-runtime/src/thread-snapshot-mirror.cjs.map +1 -1
  136. package/dist/agent-runtime/src/thread-snapshot-mirror.d.ts +101 -0
  137. package/dist/agent-runtime/src/thread-snapshot-mirror.js +17 -88
  138. package/dist/agent-runtime/src/thread-snapshot-mirror.js.map +1 -1
  139. package/dist/agent-runtime/src/thread-status.d.ts +53 -0
  140. package/dist/agent-runtime/src/tool-metadata.d.ts +146 -0
  141. package/dist/agent-runtime/src/tool-names.cjs +67 -0
  142. package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
  143. package/dist/agent-runtime/src/tool-names.d.ts +60 -0
  144. package/dist/agent-runtime/src/tool-names.js +68 -1
  145. package/dist/agent-runtime/src/tool-names.js.map +1 -1
  146. package/dist/agent-runtime/src/tool-outputs.d.ts +35 -0
  147. package/dist/agent-runtime/src/tool-result.cjs +1 -0
  148. package/dist/agent-runtime/src/tool-result.cjs.map +1 -1
  149. package/dist/agent-runtime/src/tool-result.d.ts +126 -0
  150. package/dist/agent-runtime/src/tool-result.js +1 -0
  151. package/dist/agent-runtime/src/tool-result.js.map +1 -1
  152. package/dist/agent-runtime/src/types.d.ts +159 -0
  153. package/dist/agent-runtime/src/use-conversation-list.d.ts +76 -0
  154. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +136 -0
  155. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -0
  156. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +64 -0
  157. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +136 -0
  158. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -0
  159. package/dist/agent-runtime/src/use-deep-agent-config.d.ts +169 -0
  160. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +13 -0
  161. package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
  162. package/dist/agent-runtime/src/use-deep-agent-edit-submit.d.ts +22 -0
  163. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js +13 -0
  164. package/dist/agent-runtime/src/use-deep-agent-edit-submit.js.map +1 -1
  165. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +20 -2
  166. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  167. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +168 -0
  168. package/dist/agent-runtime/src/use-deep-agent-runtime.js +20 -2
  169. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  170. package/dist/agent-runtime/src/use-deep-agent-thread.cjs +12 -4
  171. package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
  172. package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +320 -0
  173. package/dist/agent-runtime/src/use-deep-agent-thread.js +12 -4
  174. package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
  175. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +999 -0
  176. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -0
  177. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +409 -0
  178. package/dist/agent-runtime/src/use-deep-agent-voice.js +999 -0
  179. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -0
  180. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +102 -0
  181. package/dist/agent-runtime/src/use-historical-edit-attachments.d.ts +2 -0
  182. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +84 -0
  183. package/dist/agent-runtime/src/voice-presentation.d.ts +80 -0
  184. package/dist/agent-runtime/src/voice-turn-grouping.d.ts +28 -0
  185. package/dist/agent-runtime/src/voice-wire-types.d.ts +15 -0
  186. package/dist/agent-runtime/src/withdrawn-turns.d.ts +97 -0
  187. package/dist/chat/AthenaChat.cjs +72 -5
  188. package/dist/chat/AthenaChat.cjs.map +1 -1
  189. package/dist/chat/AthenaChat.js +73 -6
  190. package/dist/chat/AthenaChat.js.map +1 -1
  191. package/dist/chat/StatewireApprovalCard.d.ts +1 -1
  192. package/dist/chat/StatewireClientToolBridge.d.ts +1 -1
  193. package/dist/chat/StatewireQueuedMessages.cjs +11 -4
  194. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  195. package/dist/chat/StatewireQueuedMessages.d.ts +1 -1
  196. package/dist/chat/StatewireQueuedMessages.js +11 -4
  197. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  198. package/dist/chat/chat-outbox-rows.cjs +223 -0
  199. package/dist/chat/chat-outbox-rows.cjs.map +1 -0
  200. package/dist/chat/chat-outbox-rows.d.ts +29 -0
  201. package/dist/chat/chat-outbox-rows.js +223 -0
  202. package/dist/chat/chat-outbox-rows.js.map +1 -0
  203. package/dist/chat/statewire-approval.d.ts +1 -1
  204. package/dist/chat/statewire-client-tools.d.ts +1 -1
  205. package/dist/chat/super-grouping/SuperGroupingCard.cjs +3 -1
  206. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  207. package/dist/chat/super-grouping/SuperGroupingCard.d.ts +7 -1
  208. package/dist/chat/super-grouping/SuperGroupingCard.js +3 -1
  209. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  210. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +7 -2
  211. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  212. package/dist/chat/super-grouping/SuperGroupingTranscript.d.ts +2 -2
  213. package/dist/chat/super-grouping/SuperGroupingTranscript.js +7 -2
  214. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  215. package/dist/chat/super-grouping/activity-timeline.cjs +15 -8
  216. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  217. package/dist/chat/super-grouping/activity-timeline.d.ts +18 -8
  218. package/dist/chat/super-grouping/activity-timeline.js +15 -8
  219. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  220. package/dist/chat/use-statewire-approval-request.cjs +36 -0
  221. package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
  222. package/dist/chat/use-statewire-approval-request.d.ts +49 -1
  223. package/dist/chat/use-statewire-approval-request.js +39 -3
  224. package/dist/chat/use-statewire-approval-request.js.map +1 -1
  225. package/dist/chat-ui/composer/tiptap-composer.cjs +102 -3
  226. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  227. package/dist/chat-ui/composer/tiptap-composer.d.ts +32 -1
  228. package/dist/chat-ui/composer/tiptap-composer.js +103 -4
  229. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  230. package/dist/chat-ui/header/conversation-history-panel.d.ts +1 -1
  231. package/dist/chat-ui/index.d.ts +1 -1
  232. package/dist/chat-ui/messages/message-components.cjs +15 -0
  233. package/dist/chat-ui/messages/message-components.cjs.map +1 -1
  234. package/dist/chat-ui/messages/message-components.js +15 -0
  235. package/dist/chat-ui/messages/message-components.js.map +1 -1
  236. package/dist/chat-ui/messages/runtime-message.d.ts +1 -1
  237. package/dist/chat-ui/messages/statewire-continue-run.d.ts +1 -1
  238. package/dist/chat-ui/messages/user-edit-composer.cjs +15 -2
  239. package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
  240. package/dist/chat-ui/messages/user-edit-composer.d.ts +4 -2
  241. package/dist/chat-ui/messages/user-edit-composer.js +15 -2
  242. package/dist/chat-ui/messages/user-edit-composer.js.map +1 -1
  243. package/dist/chat-ui/messages/wake-marker.d.ts +1 -1
  244. package/dist/chat-ui/rich-text/chat-text-schema.cjs +1 -0
  245. package/dist/chat-ui/rich-text/chat-text-schema.cjs.map +1 -1
  246. package/dist/chat-ui/rich-text/chat-text-schema.d.ts +3 -0
  247. package/dist/chat-ui/rich-text/chat-text-schema.js +1 -0
  248. package/dist/chat-ui/rich-text/chat-text-schema.js.map +1 -1
  249. package/dist/chat-ui/statewire.cjs +1 -0
  250. package/dist/chat-ui/statewire.cjs.map +1 -1
  251. package/dist/chat-ui/statewire.d.ts +2 -2
  252. package/dist/chat-ui/statewire.js +2 -1
  253. package/dist/chat-ui/thread/statewire-history-edge.d.ts +1 -1
  254. package/dist/composer/AttachmentContext.cjs +8 -4
  255. package/dist/composer/AttachmentContext.cjs.map +1 -1
  256. package/dist/composer/AttachmentContext.d.ts +7 -0
  257. package/dist/composer/AttachmentContext.js +8 -4
  258. package/dist/composer/AttachmentContext.js.map +1 -1
  259. package/dist/composer/build-composed-message.cjs +34 -0
  260. package/dist/composer/build-composed-message.cjs.map +1 -1
  261. package/dist/composer/build-composed-message.d.ts +20 -0
  262. package/dist/composer/build-composed-message.js +35 -1
  263. package/dist/composer/build-composed-message.js.map +1 -1
  264. package/dist/composer/composer-handoff.cjs +39 -2
  265. package/dist/composer/composer-handoff.cjs.map +1 -1
  266. package/dist/composer/composer-handoff.d.ts +28 -3
  267. package/dist/composer/composer-handoff.js +39 -2
  268. package/dist/composer/composer-handoff.js.map +1 -1
  269. package/dist/composer/useAttachFiles.cjs +15 -2
  270. package/dist/composer/useAttachFiles.cjs.map +1 -1
  271. package/dist/composer/useAttachFiles.d.ts +11 -0
  272. package/dist/composer/useAttachFiles.js +15 -2
  273. package/dist/composer/useAttachFiles.js.map +1 -1
  274. package/dist/composer/useSendMessage.cjs.map +1 -1
  275. package/dist/composer/useSendMessage.d.ts +4 -3
  276. package/dist/composer/useSendMessage.js.map +1 -1
  277. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  278. package/dist/diagnostics/athena-diagnostics.d.ts +3 -1
  279. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  280. package/dist/index.cjs +13 -0
  281. package/dist/index.cjs.map +1 -1
  282. package/dist/index.d.ts +13 -6
  283. package/dist/index.js +14 -1
  284. package/dist/index.js.map +1 -1
  285. package/dist/offline/chat-outbox.cjs +57 -0
  286. package/dist/offline/chat-outbox.cjs.map +1 -0
  287. package/dist/offline/chat-outbox.d.ts +80 -0
  288. package/dist/offline/chat-outbox.js +57 -0
  289. package/dist/offline/chat-outbox.js.map +1 -0
  290. package/dist/offline/offline-history.d.ts +1 -1
  291. package/dist/provider/AthenaProvider.cjs +162 -8
  292. package/dist/provider/AthenaProvider.cjs.map +1 -1
  293. package/dist/provider/AthenaProvider.d.ts +15 -1
  294. package/dist/provider/AthenaProvider.js +163 -9
  295. package/dist/provider/AthenaProvider.js.map +1 -1
  296. package/dist/provider/statewire-window-context.d.ts +1 -1
  297. package/dist/react/package.json.cjs +1 -1
  298. package/dist/react/package.json.js +1 -1
  299. package/dist/references/src/anchors/file-line-range.d.ts +58 -0
  300. package/dist/references/src/anchors/format.d.ts +21 -0
  301. package/dist/references/src/anchors/message-anchors.d.ts +71 -0
  302. package/dist/references/src/anchors/parse.d.ts +8 -0
  303. package/dist/references/src/anchors/registry-contract.d.ts +24 -0
  304. package/dist/references/src/anchors/registry.d.ts +19 -0
  305. package/dist/references/src/anchors/schemas.d.ts +194 -0
  306. package/dist/references/src/anchors/serialize.d.ts +8 -0
  307. package/dist/references/src/anchors/time.d.ts +78 -0
  308. package/dist/references/src/anchors/types.d.ts +474 -0
  309. package/dist/references/src/asset-bounds.d.ts +27 -0
  310. package/dist/references/src/asset-links.d.ts +23 -0
  311. package/dist/references/src/asset-reference.d.ts +16 -0
  312. package/dist/references/src/formats/format-catalog.d.ts +79 -0
  313. package/dist/references/src/formats/markdown/parse-reference-markdown.d.ts +28 -0
  314. package/dist/references/src/formats/markdown/reference-display-name.d.ts +6 -0
  315. package/dist/references/src/formats/object/asset-object.d.ts +9 -0
  316. package/dist/references/src/formats/object/callable-object.d.ts +6 -0
  317. package/dist/references/src/formats/object/decode-reference-object-payload.d.ts +3 -0
  318. package/dist/references/src/formats/object/external-url-object.d.ts +9 -0
  319. package/dist/references/src/formats/object/group-object.d.ts +9 -0
  320. package/dist/references/src/formats/object/navigation-object.d.ts +9 -0
  321. package/dist/references/src/formats/object/parse-reference-object.d.ts +11 -0
  322. package/dist/references/src/formats/object/person-object.d.ts +9 -0
  323. package/dist/references/src/formats/uri/asset-mention-uri.d.ts +9 -0
  324. package/dist/references/src/formats/uri/asset-spaces-url.d.ts +9 -0
  325. package/dist/references/src/formats/uri/callable-mention-uris.d.ts +9 -0
  326. package/dist/references/src/formats/uri/detect-uri-wire.d.ts +9 -0
  327. package/dist/references/src/formats/uri/group-mention-uri.d.ts +12 -0
  328. package/dist/references/src/formats/uri/navigation-spaces-url.d.ts +14 -0
  329. package/dist/references/src/formats/uri/parse-reference-uri.d.ts +20 -0
  330. package/dist/references/src/formats/uri/person-mention-uri.d.ts +9 -0
  331. package/dist/references/src/formats/uri/template-placeholder.d.ts +12 -0
  332. package/dist/references/src/index.d.ts +47 -0
  333. package/dist/references/src/legacy/index.d.ts +14 -0
  334. package/dist/references/src/legacy/pre-reference-asset-url.d.ts +57 -0
  335. package/dist/references/src/legacy/pre-reference-citation-bridge.d.ts +22 -0
  336. package/dist/references/src/legacy/pre-reference-citation.d.ts +138 -0
  337. package/dist/references/src/legacy/pre-reference-external-url.d.ts +31 -0
  338. package/dist/references/src/legacy/pre-reference-format.d.ts +8 -0
  339. package/dist/references/src/legacy/pre-reference-mention.d.ts +27 -0
  340. package/dist/references/src/legacy/pre-reference-object.d.ts +8 -0
  341. package/dist/references/src/legacy/pre-reference-uri.d.ts +12 -0
  342. package/dist/references/src/legacy.d.ts +2 -0
  343. package/dist/references/src/mention-href-patterns.d.ts +19 -0
  344. package/dist/references/src/mention-node/index.d.ts +5 -0
  345. package/dist/references/src/mention-node/mention-node.d.ts +31 -0
  346. package/dist/references/src/mention-node/resolve-node-attrs.d.ts +27 -0
  347. package/dist/references/src/parse-reference.d.ts +23 -0
  348. package/dist/references/src/schemas.d.ts +463 -0
  349. package/dist/references/src/serialize-reference.d.ts +50 -0
  350. package/dist/references/src/sheet-name.d.ts +10 -0
  351. package/dist/references/src/tool-option-schemas.d.ts +597 -0
  352. package/dist/references/src/types.d.ts +125 -0
  353. package/dist/references/src/version-ref.d.ts +30 -0
  354. package/dist/runtime/statewire-lifecycle.d.ts +1 -1
  355. package/dist/runtime/statewire-model-lane.d.ts +1 -1
  356. package/dist/runtime/statewire-server-lane-context.d.ts +1 -1
  357. package/dist/runtime/statewire-session-key.cjs +7 -0
  358. package/dist/runtime/statewire-session-key.cjs.map +1 -1
  359. package/dist/runtime/statewire-session-key.d.ts +16 -0
  360. package/dist/runtime/statewire-session-key.js +8 -1
  361. package/dist/runtime/statewire-session-key.js.map +1 -1
  362. package/dist/runtime/statewire-session-lane.cjs +48 -0
  363. package/dist/runtime/statewire-session-lane.cjs.map +1 -0
  364. package/dist/runtime/statewire-session-lane.d.ts +29 -0
  365. package/dist/runtime/statewire-session-lane.js +48 -0
  366. package/dist/runtime/statewire-session-lane.js.map +1 -0
  367. package/dist/runtime/statewire-thread-config-lane.d.ts +1 -1
  368. package/dist/runtime/useAthenaStatewireRuntime.cjs +16 -5
  369. package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
  370. package/dist/runtime/useAthenaStatewireRuntime.d.ts +15 -1
  371. package/dist/runtime/useAthenaStatewireRuntime.js +17 -6
  372. package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
  373. package/dist/styles.css +1 -1
  374. package/dist/threads/api.d.ts +1 -1
  375. package/dist/threads/conversation-list-fetcher.d.ts +1 -1
  376. package/dist/threads/index-triggered-refresh.cjs +164 -0
  377. package/dist/threads/index-triggered-refresh.cjs.map +1 -0
  378. package/dist/threads/index-triggered-refresh.d.ts +70 -0
  379. package/dist/threads/index-triggered-refresh.js +164 -0
  380. package/dist/threads/index-triggered-refresh.js.map +1 -0
  381. package/dist/threads/offline-session-list.d.ts +1 -1
  382. package/dist/threads/pull-request-display.d.ts +1 -1
  383. package/dist/threads/session-list-model.d.ts +1 -1
  384. package/dist/threads/session-list-tab-share.cjs +150 -0
  385. package/dist/threads/session-list-tab-share.cjs.map +1 -0
  386. package/dist/threads/session-list-tab-share.d.ts +73 -0
  387. package/dist/threads/session-list-tab-share.js +150 -0
  388. package/dist/threads/session-list-tab-share.js.map +1 -0
  389. package/dist/threads/session-row-parts.d.ts +1 -1
  390. package/dist/threads/sessions-query.d.ts +1 -1
  391. package/dist/threads/statewire-thread-list.cjs +42 -16
  392. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  393. package/dist/threads/statewire-thread-list.d.ts +11 -2
  394. package/dist/threads/statewire-thread-list.js +43 -17
  395. package/dist/threads/statewire-thread-list.js.map +1 -1
  396. package/dist/threads/thread-prefetcher.d.ts +1 -1
  397. package/dist/threads/use-athena-session-attention.d.ts +1 -1
  398. package/dist/threads/use-athena-sessions.cjs +32 -22
  399. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  400. package/dist/threads/use-athena-sessions.js +33 -23
  401. package/dist/threads/use-athena-sessions.js.map +1 -1
  402. package/dist/threads/use-rest-conversation-history.d.ts +1 -1
  403. package/dist/threads/use-statewire-conversation-history.d.ts +5 -5
  404. package/dist/tiptap-markdown-table/src/markdown-table-serializer.d.ts +56 -0
  405. package/dist/tools/NestedPtcMessages.cjs +14 -9
  406. package/dist/tools/NestedPtcMessages.cjs.map +1 -1
  407. package/dist/tools/NestedPtcMessages.d.ts +9 -0
  408. package/dist/tools/NestedPtcMessages.js +6 -1
  409. package/dist/tools/NestedPtcMessages.js.map +1 -1
  410. package/dist/tools/index.d.ts +1 -1
  411. package/dist/tools/primitives.d.ts +1 -1
  412. package/dist/tools/subagent-task-tool-ui.cjs +494 -0
  413. package/dist/tools/subagent-task-tool-ui.cjs.map +1 -0
  414. package/dist/tools/subagent-task-tool-ui.d.ts +109 -0
  415. package/dist/tools/subagent-task-tool-ui.js +494 -0
  416. package/dist/tools/subagent-task-tool-ui.js.map +1 -0
  417. package/dist/tools/tool-fallback.d.ts +1 -1
  418. package/dist/tools/tool-icons.d.ts +1 -1
  419. package/dist/tools/tool-summary.d.ts +1 -1
  420. package/dist/tools/tool-uis.cjs +4 -0
  421. package/dist/tools/tool-uis.cjs.map +1 -1
  422. package/dist/tools/tool-uis.js +4 -0
  423. package/dist/tools/tool-uis.js.map +1 -1
  424. package/dist/voice/chat.cjs +6 -0
  425. package/dist/voice/chat.cjs.map +1 -0
  426. package/dist/voice/chat.d.ts +2 -0
  427. package/dist/voice/chat.js +6 -0
  428. package/dist/voice/chat.js.map +1 -0
  429. package/dist/voice/livekit-join.cjs +119 -0
  430. package/dist/voice/livekit-join.cjs.map +1 -0
  431. package/dist/voice/livekit-join.d.ts +8 -0
  432. package/dist/voice/livekit-join.js +119 -0
  433. package/dist/voice/livekit-join.js.map +1 -0
  434. package/dist/voice/livekit.cjs +32 -0
  435. package/dist/voice/livekit.cjs.map +1 -0
  436. package/dist/voice/livekit.d.ts +80 -0
  437. package/dist/voice/livekit.js +32 -0
  438. package/dist/voice/livekit.js.map +1 -0
  439. package/package.json +20 -10
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const idbGlobals = globalThis;
4
+ const SEALED_IV_BYTES = 12;
5
+ const encoder = new TextEncoder();
6
+ const decoder = new TextDecoder();
7
+ async function sha256Hex(value) {
8
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(value));
9
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
10
+ }
11
+ async function sealJson({
12
+ key,
13
+ value,
14
+ aad
15
+ }) {
16
+ const iv = crypto.getRandomValues(new Uint8Array(SEALED_IV_BYTES));
17
+ const ciphertext = new Uint8Array(
18
+ await crypto.subtle.encrypt(
19
+ { name: "AES-GCM", iv, additionalData: encoder.encode(aad) },
20
+ key,
21
+ encoder.encode(JSON.stringify(value))
22
+ )
23
+ );
24
+ const sealed = new Uint8Array(SEALED_IV_BYTES + ciphertext.byteLength);
25
+ sealed.set(iv, 0);
26
+ sealed.set(ciphertext, SEALED_IV_BYTES);
27
+ return sealed;
28
+ }
29
+ async function openJson({
30
+ key,
31
+ sealed,
32
+ aad
33
+ }) {
34
+ const iv = sealed.subarray(0, SEALED_IV_BYTES);
35
+ const plaintext = await crypto.subtle.decrypt(
36
+ { name: "AES-GCM", iv, additionalData: encoder.encode(aad) },
37
+ key,
38
+ sealed.subarray(SEALED_IV_BYTES)
39
+ );
40
+ return JSON.parse(decoder.decode(plaintext));
41
+ }
42
+ function requestToPromise(request) {
43
+ return new Promise((resolve, reject) => {
44
+ request.onsuccess = () => resolve(request.result);
45
+ request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
46
+ });
47
+ }
48
+ function transactionDone(tx) {
49
+ return new Promise((resolve, reject) => {
50
+ tx.oncomplete = () => resolve();
51
+ tx.onabort = () => reject(tx.error ?? new Error("IndexedDB transaction aborted"));
52
+ tx.onerror = () => reject(tx.error ?? new Error("IndexedDB transaction failed"));
53
+ });
54
+ }
55
+ function openSealedDatabase({
56
+ factory,
57
+ name,
58
+ version,
59
+ upgrade
60
+ }) {
61
+ return new Promise((resolve) => {
62
+ try {
63
+ const request = factory.open(name, version);
64
+ request.onupgradeneeded = () => upgrade(request.result);
65
+ request.onsuccess = () => {
66
+ const db = request.result;
67
+ db.onversionchange = () => db.close();
68
+ resolve(db);
69
+ };
70
+ request.onerror = () => resolve(null);
71
+ request.onblocked = () => resolve(null);
72
+ } catch {
73
+ resolve(null);
74
+ }
75
+ });
76
+ }
77
+ function lazySealedDatabase({
78
+ factory,
79
+ name,
80
+ version,
81
+ upgrade
82
+ }) {
83
+ let databasePromise = null;
84
+ return () => {
85
+ if (!factory || typeof crypto === "undefined" || !crypto.subtle) return Promise.resolve(null);
86
+ databasePromise ?? (databasePromise = openSealedDatabase({ factory, name, version, upgrade }).then(
87
+ (db) => {
88
+ if (db) {
89
+ const forget = () => {
90
+ databasePromise = null;
91
+ };
92
+ db.addEventListener("versionchange", forget);
93
+ db.addEventListener("close", forget);
94
+ } else {
95
+ databasePromise = null;
96
+ }
97
+ return db;
98
+ }
99
+ ));
100
+ return databasePromise;
101
+ };
102
+ }
103
+ exports.SEALED_IV_BYTES = SEALED_IV_BYTES;
104
+ exports.idbGlobals = idbGlobals;
105
+ exports.lazySealedDatabase = lazySealedDatabase;
106
+ exports.openJson = openJson;
107
+ exports.openSealedDatabase = openSealedDatabase;
108
+ exports.requestToPromise = requestToPromise;
109
+ exports.sealJson = sealJson;
110
+ exports.sha256Hex = sha256Hex;
111
+ exports.transactionDone = transactionDone;
112
+ //# sourceMappingURL=sealed-idb.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sealed-idb.cjs","sources":["../../../../agent-runtime/src/sealed-idb.ts"],"sourcesContent":["/**\n * The sealed-record toolkit the device stores in this package share (the thread snapshot mirror,\n * the chat outbox): AES-GCM-256 sealing with a fresh IV and additional data that binds a record to\n * where it is stored, SHA-256 names so a database names no one, and the part of IndexedDB they use.\n *\n * This package compiles without the DOM lib (React Native honesty, `globals.d.ts`), so IndexedDB is\n * described structurally here; the stores run only where it exists and degrade to nothing where it\n * does not.\n */\n\nexport type IdbListener = ((event?: unknown) => void) | null;\n\nexport interface IdbRequest<T> {\n readonly result: T;\n readonly error: unknown;\n onsuccess: IdbListener;\n onerror: IdbListener;\n}\n\nexport interface IdbOpenRequest extends IdbRequest<IdbDatabase> {\n onupgradeneeded: IdbListener;\n onblocked: IdbListener;\n}\n\nexport interface IdbFactory {\n open(name: string, version?: number): IdbOpenRequest;\n}\n\nexport interface IdbCursor {\n readonly primaryKey: unknown;\n continue(): void;\n}\n\nexport interface IdbIndex {\n getAll(query?: unknown): IdbRequest<unknown[]>;\n getAllKeys(query?: unknown): IdbRequest<unknown[]>;\n openKeyCursor(range?: unknown, direction?: string): IdbRequest<IdbCursor | null>;\n}\n\nexport interface IdbObjectStore {\n put(value: unknown): IdbRequest<unknown>;\n get(key: unknown): IdbRequest<unknown>;\n delete(key: unknown): IdbRequest<unknown>;\n clear(): IdbRequest<unknown>;\n index(name: string): IdbIndex;\n createIndex(name: string, keyPath: string | string[], options?: { unique?: boolean }): unknown;\n}\n\nexport interface IdbTransaction {\n objectStore(name: string): IdbObjectStore;\n readonly error: unknown;\n oncomplete: IdbListener;\n onabort: IdbListener;\n onerror: IdbListener;\n}\n\nexport interface IdbDatabase {\n readonly objectStoreNames: { contains(name: string): boolean };\n transaction(stores: string | string[], mode?: \"readonly\" | \"readwrite\"): IdbTransaction;\n createObjectStore(name: string, options?: { keyPath: string }): IdbObjectStore;\n onversionchange: IdbListener;\n addEventListener(type: string, listener: () => void): void;\n close(): void;\n}\n\nexport interface IdbKeyRangeStatic {\n bound(lower: unknown, upper: unknown): unknown;\n}\n\nexport const idbGlobals = globalThis as { indexedDB?: object; IDBKeyRange?: IdbKeyRangeStatic };\n\n/** The AES-GCM IV length, prefixed to every sealed payload. */\nexport const SEALED_IV_BYTES = 12;\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\nexport async function sha256Hex(value: string): Promise<string> {\n const digest = await crypto.subtle.digest(\"SHA-256\", encoder.encode(value));\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/** `value` as JSON, sealed under `key` with a fresh IV; `aad` binds it to where it is stored. */\nexport async function sealJson({\n key,\n value,\n aad,\n}: {\n key: CryptoKey;\n value: unknown;\n aad: string;\n}): Promise<Uint8Array> {\n const iv = crypto.getRandomValues(new Uint8Array(SEALED_IV_BYTES));\n const ciphertext = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv, additionalData: encoder.encode(aad) },\n key,\n encoder.encode(JSON.stringify(value)),\n ),\n );\n const sealed = new Uint8Array(SEALED_IV_BYTES + ciphertext.byteLength);\n sealed.set(iv, 0);\n sealed.set(ciphertext, SEALED_IV_BYTES);\n return sealed;\n}\n\n/** Opens what {@link sealJson} sealed; throws for the wrong key, the wrong `aad`, or a damaged record. */\nexport async function openJson({\n key,\n sealed,\n aad,\n}: {\n key: CryptoKey;\n sealed: Uint8Array;\n aad: string;\n}): Promise<unknown> {\n const iv = sealed.subarray(0, SEALED_IV_BYTES) as Uint8Array<ArrayBuffer>;\n const plaintext = await crypto.subtle.decrypt(\n { name: \"AES-GCM\", iv, additionalData: encoder.encode(aad) },\n key,\n sealed.subarray(SEALED_IV_BYTES) as Uint8Array<ArrayBuffer>,\n );\n return JSON.parse(decoder.decode(plaintext)) as unknown;\n}\n\nexport function requestToPromise<T>(request: IdbRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error ?? new Error(\"IndexedDB request failed\"));\n });\n}\n\nexport function transactionDone(tx: IdbTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n tx.oncomplete = () => resolve();\n tx.onabort = () => reject(tx.error ?? new Error(\"IndexedDB transaction aborted\"));\n tx.onerror = () => reject(tx.error ?? new Error(\"IndexedDB transaction failed\"));\n });\n}\n\n/**\n * Opens `name` at `version`, creating what `upgrade` creates. Resolves `null` instead of failing:\n * a database a newer build upgraded past this version, a blocked open, or no IndexedDB at all\n * (private browsing, SSR) all mean \"no store here\".\n */\nexport function openSealedDatabase({\n factory,\n name,\n version,\n upgrade,\n}: {\n factory: IdbFactory;\n name: string;\n version: number;\n upgrade: (db: IdbDatabase) => void;\n}): Promise<IdbDatabase | null> {\n return new Promise((resolve) => {\n try {\n const request = factory.open(name, version);\n request.onupgradeneeded = () => upgrade(request.result);\n request.onsuccess = () => {\n const db = request.result;\n // Another page deleting or upgrading the database: step aside.\n db.onversionchange = () => db.close();\n resolve(db);\n };\n request.onerror = () => resolve(null);\n request.onblocked = () => resolve(null);\n } catch {\n resolve(null);\n }\n });\n}\n\n/**\n * A lazily opened database handle that reopens after the browser (or another page's upgrade or\n * delete) closes it. `null` while there is no IndexedDB or Web Crypto here.\n */\nexport function lazySealedDatabase({\n factory,\n name,\n version,\n upgrade,\n}: {\n factory: object | undefined;\n name: string;\n version: number;\n upgrade: (db: IdbDatabase) => void;\n}): () => Promise<IdbDatabase | null> {\n let databasePromise: Promise<IdbDatabase | null> | null = null;\n return () => {\n if (!factory || typeof crypto === \"undefined\" || !crypto.subtle) return Promise.resolve(null);\n databasePromise ??= openSealedDatabase({ factory: factory as IdbFactory, name, version, upgrade }).then(\n (db) => {\n if (db) {\n const forget = () => {\n databasePromise = null;\n };\n db.addEventListener(\"versionchange\", forget);\n db.addEventListener(\"close\", forget);\n } else {\n databasePromise = null;\n }\n return db;\n },\n );\n return databasePromise;\n };\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The sealed-record toolkit the device stores in this package share (the thread snapshot mirror,
3
+ * the chat outbox): AES-GCM-256 sealing with a fresh IV and additional data that binds a record to
4
+ * where it is stored, SHA-256 names so a database names no one, and the part of IndexedDB they use.
5
+ *
6
+ * This package compiles without the DOM lib (React Native honesty, `globals.d.ts`), so IndexedDB is
7
+ * described structurally here; the stores run only where it exists and degrade to nothing where it
8
+ * does not.
9
+ */
10
+ export type IdbListener = ((event?: unknown) => void) | null;
11
+ export interface IdbRequest<T> {
12
+ readonly result: T;
13
+ readonly error: unknown;
14
+ onsuccess: IdbListener;
15
+ onerror: IdbListener;
16
+ }
17
+ export interface IdbOpenRequest extends IdbRequest<IdbDatabase> {
18
+ onupgradeneeded: IdbListener;
19
+ onblocked: IdbListener;
20
+ }
21
+ export interface IdbFactory {
22
+ open(name: string, version?: number): IdbOpenRequest;
23
+ }
24
+ export interface IdbCursor {
25
+ readonly primaryKey: unknown;
26
+ continue(): void;
27
+ }
28
+ export interface IdbIndex {
29
+ getAll(query?: unknown): IdbRequest<unknown[]>;
30
+ getAllKeys(query?: unknown): IdbRequest<unknown[]>;
31
+ openKeyCursor(range?: unknown, direction?: string): IdbRequest<IdbCursor | null>;
32
+ }
33
+ export interface IdbObjectStore {
34
+ put(value: unknown): IdbRequest<unknown>;
35
+ get(key: unknown): IdbRequest<unknown>;
36
+ delete(key: unknown): IdbRequest<unknown>;
37
+ clear(): IdbRequest<unknown>;
38
+ index(name: string): IdbIndex;
39
+ createIndex(name: string, keyPath: string | string[], options?: {
40
+ unique?: boolean;
41
+ }): unknown;
42
+ }
43
+ export interface IdbTransaction {
44
+ objectStore(name: string): IdbObjectStore;
45
+ readonly error: unknown;
46
+ oncomplete: IdbListener;
47
+ onabort: IdbListener;
48
+ onerror: IdbListener;
49
+ }
50
+ export interface IdbDatabase {
51
+ readonly objectStoreNames: {
52
+ contains(name: string): boolean;
53
+ };
54
+ transaction(stores: string | string[], mode?: "readonly" | "readwrite"): IdbTransaction;
55
+ createObjectStore(name: string, options?: {
56
+ keyPath: string;
57
+ }): IdbObjectStore;
58
+ onversionchange: IdbListener;
59
+ addEventListener(type: string, listener: () => void): void;
60
+ close(): void;
61
+ }
62
+ export interface IdbKeyRangeStatic {
63
+ bound(lower: unknown, upper: unknown): unknown;
64
+ }
65
+ export declare const idbGlobals: {
66
+ indexedDB?: object;
67
+ IDBKeyRange?: IdbKeyRangeStatic;
68
+ };
69
+ /** The AES-GCM IV length, prefixed to every sealed payload. */
70
+ export declare const SEALED_IV_BYTES = 12;
71
+ export declare function sha256Hex(value: string): Promise<string>;
72
+ /** `value` as JSON, sealed under `key` with a fresh IV; `aad` binds it to where it is stored. */
73
+ export declare function sealJson({ key, value, aad, }: {
74
+ key: CryptoKey;
75
+ value: unknown;
76
+ aad: string;
77
+ }): Promise<Uint8Array>;
78
+ /** Opens what {@link sealJson} sealed; throws for the wrong key, the wrong `aad`, or a damaged record. */
79
+ export declare function openJson({ key, sealed, aad, }: {
80
+ key: CryptoKey;
81
+ sealed: Uint8Array;
82
+ aad: string;
83
+ }): Promise<unknown>;
84
+ export declare function requestToPromise<T>(request: IdbRequest<T>): Promise<T>;
85
+ export declare function transactionDone(tx: IdbTransaction): Promise<void>;
86
+ /**
87
+ * Opens `name` at `version`, creating what `upgrade` creates. Resolves `null` instead of failing:
88
+ * a database a newer build upgraded past this version, a blocked open, or no IndexedDB at all
89
+ * (private browsing, SSR) all mean "no store here".
90
+ */
91
+ export declare function openSealedDatabase({ factory, name, version, upgrade, }: {
92
+ factory: IdbFactory;
93
+ name: string;
94
+ version: number;
95
+ upgrade: (db: IdbDatabase) => void;
96
+ }): Promise<IdbDatabase | null>;
97
+ /**
98
+ * A lazily opened database handle that reopens after the browser (or another page's upgrade or
99
+ * delete) closes it. `null` while there is no IndexedDB or Web Crypto here.
100
+ */
101
+ export declare function lazySealedDatabase({ factory, name, version, upgrade, }: {
102
+ factory: object | undefined;
103
+ name: string;
104
+ version: number;
105
+ upgrade: (db: IdbDatabase) => void;
106
+ }): () => Promise<IdbDatabase | null>;
@@ -0,0 +1,112 @@
1
+ const idbGlobals = globalThis;
2
+ const SEALED_IV_BYTES = 12;
3
+ const encoder = new TextEncoder();
4
+ const decoder = new TextDecoder();
5
+ async function sha256Hex(value) {
6
+ const digest = await crypto.subtle.digest("SHA-256", encoder.encode(value));
7
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
8
+ }
9
+ async function sealJson({
10
+ key,
11
+ value,
12
+ aad
13
+ }) {
14
+ const iv = crypto.getRandomValues(new Uint8Array(SEALED_IV_BYTES));
15
+ const ciphertext = new Uint8Array(
16
+ await crypto.subtle.encrypt(
17
+ { name: "AES-GCM", iv, additionalData: encoder.encode(aad) },
18
+ key,
19
+ encoder.encode(JSON.stringify(value))
20
+ )
21
+ );
22
+ const sealed = new Uint8Array(SEALED_IV_BYTES + ciphertext.byteLength);
23
+ sealed.set(iv, 0);
24
+ sealed.set(ciphertext, SEALED_IV_BYTES);
25
+ return sealed;
26
+ }
27
+ async function openJson({
28
+ key,
29
+ sealed,
30
+ aad
31
+ }) {
32
+ const iv = sealed.subarray(0, SEALED_IV_BYTES);
33
+ const plaintext = await crypto.subtle.decrypt(
34
+ { name: "AES-GCM", iv, additionalData: encoder.encode(aad) },
35
+ key,
36
+ sealed.subarray(SEALED_IV_BYTES)
37
+ );
38
+ return JSON.parse(decoder.decode(plaintext));
39
+ }
40
+ function requestToPromise(request) {
41
+ return new Promise((resolve, reject) => {
42
+ request.onsuccess = () => resolve(request.result);
43
+ request.onerror = () => reject(request.error ?? new Error("IndexedDB request failed"));
44
+ });
45
+ }
46
+ function transactionDone(tx) {
47
+ return new Promise((resolve, reject) => {
48
+ tx.oncomplete = () => resolve();
49
+ tx.onabort = () => reject(tx.error ?? new Error("IndexedDB transaction aborted"));
50
+ tx.onerror = () => reject(tx.error ?? new Error("IndexedDB transaction failed"));
51
+ });
52
+ }
53
+ function openSealedDatabase({
54
+ factory,
55
+ name,
56
+ version,
57
+ upgrade
58
+ }) {
59
+ return new Promise((resolve) => {
60
+ try {
61
+ const request = factory.open(name, version);
62
+ request.onupgradeneeded = () => upgrade(request.result);
63
+ request.onsuccess = () => {
64
+ const db = request.result;
65
+ db.onversionchange = () => db.close();
66
+ resolve(db);
67
+ };
68
+ request.onerror = () => resolve(null);
69
+ request.onblocked = () => resolve(null);
70
+ } catch {
71
+ resolve(null);
72
+ }
73
+ });
74
+ }
75
+ function lazySealedDatabase({
76
+ factory,
77
+ name,
78
+ version,
79
+ upgrade
80
+ }) {
81
+ let databasePromise = null;
82
+ return () => {
83
+ if (!factory || typeof crypto === "undefined" || !crypto.subtle) return Promise.resolve(null);
84
+ databasePromise ?? (databasePromise = openSealedDatabase({ factory, name, version, upgrade }).then(
85
+ (db) => {
86
+ if (db) {
87
+ const forget = () => {
88
+ databasePromise = null;
89
+ };
90
+ db.addEventListener("versionchange", forget);
91
+ db.addEventListener("close", forget);
92
+ } else {
93
+ databasePromise = null;
94
+ }
95
+ return db;
96
+ }
97
+ ));
98
+ return databasePromise;
99
+ };
100
+ }
101
+ export {
102
+ SEALED_IV_BYTES,
103
+ idbGlobals,
104
+ lazySealedDatabase,
105
+ openJson,
106
+ openSealedDatabase,
107
+ requestToPromise,
108
+ sealJson,
109
+ sha256Hex,
110
+ transactionDone
111
+ };
112
+ //# sourceMappingURL=sealed-idb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sealed-idb.js","sources":["../../../../agent-runtime/src/sealed-idb.ts"],"sourcesContent":["/**\n * The sealed-record toolkit the device stores in this package share (the thread snapshot mirror,\n * the chat outbox): AES-GCM-256 sealing with a fresh IV and additional data that binds a record to\n * where it is stored, SHA-256 names so a database names no one, and the part of IndexedDB they use.\n *\n * This package compiles without the DOM lib (React Native honesty, `globals.d.ts`), so IndexedDB is\n * described structurally here; the stores run only where it exists and degrade to nothing where it\n * does not.\n */\n\nexport type IdbListener = ((event?: unknown) => void) | null;\n\nexport interface IdbRequest<T> {\n readonly result: T;\n readonly error: unknown;\n onsuccess: IdbListener;\n onerror: IdbListener;\n}\n\nexport interface IdbOpenRequest extends IdbRequest<IdbDatabase> {\n onupgradeneeded: IdbListener;\n onblocked: IdbListener;\n}\n\nexport interface IdbFactory {\n open(name: string, version?: number): IdbOpenRequest;\n}\n\nexport interface IdbCursor {\n readonly primaryKey: unknown;\n continue(): void;\n}\n\nexport interface IdbIndex {\n getAll(query?: unknown): IdbRequest<unknown[]>;\n getAllKeys(query?: unknown): IdbRequest<unknown[]>;\n openKeyCursor(range?: unknown, direction?: string): IdbRequest<IdbCursor | null>;\n}\n\nexport interface IdbObjectStore {\n put(value: unknown): IdbRequest<unknown>;\n get(key: unknown): IdbRequest<unknown>;\n delete(key: unknown): IdbRequest<unknown>;\n clear(): IdbRequest<unknown>;\n index(name: string): IdbIndex;\n createIndex(name: string, keyPath: string | string[], options?: { unique?: boolean }): unknown;\n}\n\nexport interface IdbTransaction {\n objectStore(name: string): IdbObjectStore;\n readonly error: unknown;\n oncomplete: IdbListener;\n onabort: IdbListener;\n onerror: IdbListener;\n}\n\nexport interface IdbDatabase {\n readonly objectStoreNames: { contains(name: string): boolean };\n transaction(stores: string | string[], mode?: \"readonly\" | \"readwrite\"): IdbTransaction;\n createObjectStore(name: string, options?: { keyPath: string }): IdbObjectStore;\n onversionchange: IdbListener;\n addEventListener(type: string, listener: () => void): void;\n close(): void;\n}\n\nexport interface IdbKeyRangeStatic {\n bound(lower: unknown, upper: unknown): unknown;\n}\n\nexport const idbGlobals = globalThis as { indexedDB?: object; IDBKeyRange?: IdbKeyRangeStatic };\n\n/** The AES-GCM IV length, prefixed to every sealed payload. */\nexport const SEALED_IV_BYTES = 12;\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder();\n\nexport async function sha256Hex(value: string): Promise<string> {\n const digest = await crypto.subtle.digest(\"SHA-256\", encoder.encode(value));\n return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/** `value` as JSON, sealed under `key` with a fresh IV; `aad` binds it to where it is stored. */\nexport async function sealJson({\n key,\n value,\n aad,\n}: {\n key: CryptoKey;\n value: unknown;\n aad: string;\n}): Promise<Uint8Array> {\n const iv = crypto.getRandomValues(new Uint8Array(SEALED_IV_BYTES));\n const ciphertext = new Uint8Array(\n await crypto.subtle.encrypt(\n { name: \"AES-GCM\", iv, additionalData: encoder.encode(aad) },\n key,\n encoder.encode(JSON.stringify(value)),\n ),\n );\n const sealed = new Uint8Array(SEALED_IV_BYTES + ciphertext.byteLength);\n sealed.set(iv, 0);\n sealed.set(ciphertext, SEALED_IV_BYTES);\n return sealed;\n}\n\n/** Opens what {@link sealJson} sealed; throws for the wrong key, the wrong `aad`, or a damaged record. */\nexport async function openJson({\n key,\n sealed,\n aad,\n}: {\n key: CryptoKey;\n sealed: Uint8Array;\n aad: string;\n}): Promise<unknown> {\n const iv = sealed.subarray(0, SEALED_IV_BYTES) as Uint8Array<ArrayBuffer>;\n const plaintext = await crypto.subtle.decrypt(\n { name: \"AES-GCM\", iv, additionalData: encoder.encode(aad) },\n key,\n sealed.subarray(SEALED_IV_BYTES) as Uint8Array<ArrayBuffer>,\n );\n return JSON.parse(decoder.decode(plaintext)) as unknown;\n}\n\nexport function requestToPromise<T>(request: IdbRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error ?? new Error(\"IndexedDB request failed\"));\n });\n}\n\nexport function transactionDone(tx: IdbTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n tx.oncomplete = () => resolve();\n tx.onabort = () => reject(tx.error ?? new Error(\"IndexedDB transaction aborted\"));\n tx.onerror = () => reject(tx.error ?? new Error(\"IndexedDB transaction failed\"));\n });\n}\n\n/**\n * Opens `name` at `version`, creating what `upgrade` creates. Resolves `null` instead of failing:\n * a database a newer build upgraded past this version, a blocked open, or no IndexedDB at all\n * (private browsing, SSR) all mean \"no store here\".\n */\nexport function openSealedDatabase({\n factory,\n name,\n version,\n upgrade,\n}: {\n factory: IdbFactory;\n name: string;\n version: number;\n upgrade: (db: IdbDatabase) => void;\n}): Promise<IdbDatabase | null> {\n return new Promise((resolve) => {\n try {\n const request = factory.open(name, version);\n request.onupgradeneeded = () => upgrade(request.result);\n request.onsuccess = () => {\n const db = request.result;\n // Another page deleting or upgrading the database: step aside.\n db.onversionchange = () => db.close();\n resolve(db);\n };\n request.onerror = () => resolve(null);\n request.onblocked = () => resolve(null);\n } catch {\n resolve(null);\n }\n });\n}\n\n/**\n * A lazily opened database handle that reopens after the browser (or another page's upgrade or\n * delete) closes it. `null` while there is no IndexedDB or Web Crypto here.\n */\nexport function lazySealedDatabase({\n factory,\n name,\n version,\n upgrade,\n}: {\n factory: object | undefined;\n name: string;\n version: number;\n upgrade: (db: IdbDatabase) => void;\n}): () => Promise<IdbDatabase | null> {\n let databasePromise: Promise<IdbDatabase | null> | null = null;\n return () => {\n if (!factory || typeof crypto === \"undefined\" || !crypto.subtle) return Promise.resolve(null);\n databasePromise ??= openSealedDatabase({ factory: factory as IdbFactory, name, version, upgrade }).then(\n (db) => {\n if (db) {\n const forget = () => {\n databasePromise = null;\n };\n db.addEventListener(\"versionchange\", forget);\n db.addEventListener(\"close\", forget);\n } else {\n databasePromise = null;\n }\n return db;\n },\n );\n return databasePromise;\n };\n}\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,40 @@
1
+ import type { StatewireDiagnosticsCommandUpdate, StatewireDiagnosticsRecorder } from './statewire-diagnostics';
2
+ import type { StatewireFailedSendLane } from './thread-extras';
3
+ export interface DeepAgentSendRecoveryOptions {
4
+ /**
5
+ * Reads the thread's failed-send lane. `null` while it is unavailable (the
6
+ * client has not mounted yet, or its extras are not a statewire thread) —
7
+ * the controller stays armed and retries on the next state change.
8
+ */
9
+ lane: () => StatewireFailedSendLane | null;
10
+ /**
11
+ * Persisted failure stamps (message id → epoch ms of the original send) for
12
+ * the freshness gate. `null`/absent means no persistence is readable — every
13
+ * lane entry then counts as fresh (an in-memory failed lane can only hold
14
+ * failures from this page session).
15
+ */
16
+ failureStamps?: (() => ReadonlyMap<string, number> | null) | undefined;
17
+ /** Transport lifecycle recorder; read per event so a late-mounted recorder still sees retries. */
18
+ diagnostics?: (() => StatewireDiagnosticsRecorder | undefined) | undefined;
19
+ /** Injectable clock (tests). */
20
+ now?: () => number;
21
+ /** Sweep scheduler; defaults to `queueMicrotask` so a sweep never dispatches
22
+ * from inside a statewire flush or a React render. */
23
+ schedule?: (task: () => void) => void;
24
+ }
25
+ export interface DeepAgentSendRecovery {
26
+ /** Feed every (normalized) statewire state change; hydration arms the mount sweep. */
27
+ observeStateChange(state: unknown): void;
28
+ /** Feed every command-lifecycle update; a never-server-judged settle arms a sweep. */
29
+ observeCommand(update: StatewireDiagnosticsCommandUpdate): void;
30
+ /** Feed client notifications too: failed history can publish after the
31
+ * command settles, without any change to the canonical thread snapshot. */
32
+ observeFailedLaneChange(): void;
33
+ dispose(): void;
34
+ }
35
+ /** Whether a settle failure is a client-side death the recovery re-dispatches
36
+ * (the server never judged the command). Exported for host-side telemetry. */
37
+ export declare function shouldAutoRetryFailedSend(failure: {
38
+ fate: string;
39
+ } | undefined): boolean;
40
+ export declare function createDeepAgentSendRecovery(options: DeepAgentSendRecoveryOptions): DeepAgentSendRecovery;
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Attach-path instrumentation for the deep-agent statewire transport, wired
3
+ * through the two injection points statewire already exposes — the
4
+ * `webSocket` constructor (`StatewireClient.WebsocketOptions`) and `fetch`
5
+ * (`StatewireClient.HttpOptions`) — so the runtime can observe what the library
6
+ * does not surface:
7
+ *
8
+ * - socket open latency (`ws_open_ms`), the hello frame's size and its
9
+ * synchronous handler cost (`hello_bytes`, `hello_handler_ms`), and close
10
+ * codes/reasons, for the thread-switch telemetry;
11
+ * - a server `Retry-After` hint, honoured as a floor under the next dial.
12
+ *
13
+ * Retry-After today: statewire honours `retry-after` only on 429 command-frame
14
+ * refusals (folded into the refusal `syn.retry`); its attach paths treat a 503
15
+ * as a generic `HTTP 503` / `network` failure and back off exponentially with
16
+ * no server input. Browsers never expose the response headers of a refused
17
+ * WebSocket upgrade at all, so for the WS transport the hint can only ride
18
+ * something the client can read: the close frame. The contract this module
19
+ * reads is a close `reason` carrying `retry-after=<seconds>` (or
20
+ * `retry-after-ms=<ms>`) — the pinboard half of that contract is a separate
21
+ * change; until it lands the WS path simply sees no hint. The SSE attach
22
+ * (`POST …/stream`) is a plain fetch, so its `Retry-After` header is read here
23
+ * directly.
24
+ *
25
+ * This package compiles without the DOM lib (React Native honesty), so the
26
+ * browser surface is typed structurally and resolved through `globalThis`.
27
+ */
28
+ /**
29
+ * Who refused a wake (503/429), read off the response body against the two
30
+ * refusal vocabularies the iris scaler also classifies data-plane 503s by
31
+ * (`iris/scaler/src/v2AccessLog.ts`):
32
+ *
33
+ * - `"placement"` — the pinboard's own refusal, `{"error": …}` with one of its
34
+ * known strings ("no live workers for hostname", "registry cold start,
35
+ * retry", "takeover in progress, retry", …): the thread has no worker to
36
+ * dial right now.
37
+ * - `"worker"` — a pinned instance-lifecycle refusal, `{"detail": …}` with one
38
+ * of its known strings ("instance closing; retry", "activation queue full;
39
+ * retry", "host draining; retry", …): one instance on the worker the thread
40
+ * is already placed on, cleared in the time a teardown takes.
41
+ * - `"unknown"` — any other 503/429 body (unreadable, an unfamiliar string, a
42
+ * real worker failure such as "Thread history load failed"): treated
43
+ * conservatively — the full `Retry-After`, no dial dropped.
44
+ * - `null` — not a refusal status.
45
+ */
46
+ export type DeepAgentWakeRefusal = "placement" | "worker" | "unknown" | null;
47
+ export type DeepAgentAttachTimingEvent = {
48
+ type: "socket-open";
49
+ url: string;
50
+ openMs: number;
51
+ } | {
52
+ type: "hello";
53
+ url: string;
54
+ /** UTF-16 length of the hello frame — bytes for the ASCII JSON the wire carries. */
55
+ bytes: number;
56
+ /** Synchronous cost of statewire's message handler for the hello (parse + apply + flush). */
57
+ handlerMs: number;
58
+ /** Hello arrival relative to the socket open; `null` when the open was not observed. */
59
+ sinceOpenMs: number | null;
60
+ } | {
61
+ type: "socket-close";
62
+ url: string;
63
+ code: number | undefined;
64
+ reason: string | undefined;
65
+ sinceOpenMs: number | null;
66
+ } | {
67
+ type: "retry-after";
68
+ url: string;
69
+ delayMs: number;
70
+ source: "ws-close" | "http-header";
71
+ } | {
72
+ /** `POST …/prewarm` answered (see `wakeDeepAgentThread`). */
73
+ type: "wake";
74
+ url: string;
75
+ status: number;
76
+ durationMs: number;
77
+ /** How the host sourced the history: already resident (`warm`) or loaded by this call. */
78
+ history: "fresh_load" | "warm" | null;
79
+ /** Who refused a 503/429 (see {@link DeepAgentWakeRefusal}); `null` otherwise. */
80
+ refusal: DeepAgentWakeRefusal;
81
+ };
82
+ /** Longest server hint honoured — a buggy or hostile hint must not park a client. */
83
+ export declare const MAX_RETRY_AFTER_MS = 30000;
84
+ /**
85
+ * Parse an HTTP `Retry-After` header value: delta-seconds or an HTTP-date.
86
+ * Returns the delay in ms clamped to {@link MAX_RETRY_AFTER_MS}, or `null` when
87
+ * the value is absent or unparseable.
88
+ */
89
+ export declare function parseRetryAfterHeaderMs(value: string | null | undefined, now?: () => number): number | null;
90
+ /**
91
+ * Parse a retry hint off a WebSocket close reason: `retry-after=<seconds>` or
92
+ * `retry-after-ms=<ms>` anywhere in the reason text (case-insensitive, `=` or
93
+ * `:`). Returns ms clamped to {@link MAX_RETRY_AFTER_MS}, or `null`.
94
+ */
95
+ export declare function parseRetryAfterFromCloseReason(reason: string | undefined): number | null;
96
+ export interface AttachRetryGate {
97
+ /** Record a hint: no dial for `key` before `now + delayMs` (clamped). */
98
+ noteRetryAfter(key: string, delayMs: number): void;
99
+ /** Resolves once the recorded floor for `key` has passed (immediately when none). */
100
+ waitForDial(key: string): Promise<void>;
101
+ /** Remaining floor for `key` in ms (0 when none). */
102
+ remainingMs(key: string): number;
103
+ /** Drop one key's floor, or every floor. */
104
+ reset(key?: string): void;
105
+ }
106
+ /**
107
+ * Per-key dial floors. Keyed by the thread's attach URL so a hint delivered
108
+ * for one thread never delays another. The floor is a minimum under
109
+ * statewire's own backoff, never a replacement for it: the transport still
110
+ * schedules its retry, and the dial simply waits out the remainder inside the
111
+ * headers resolve (both attach paths resolve headers before they dial).
112
+ */
113
+ export declare function createAttachRetryGate({ now, wait, }?: {
114
+ now?: () => number;
115
+ wait?: (ms: number) => Promise<void>;
116
+ }): AttachRetryGate;
117
+ /** Process-wide gate shared by every deep-agent transport in the host. */
118
+ export declare const attachRetryGate: AttachRetryGate;
119
+ /** Structural subset of the browser `WebSocket` that statewire's WS transport touches. */
120
+ export interface AttachSocketLike {
121
+ readonly readyState: number;
122
+ readonly protocol: string;
123
+ onopen: ((event: unknown) => void) | null;
124
+ onmessage: ((event: {
125
+ data: unknown;
126
+ }) => void) | null;
127
+ onclose: ((event: {
128
+ code?: number;
129
+ reason?: string;
130
+ }) => void) | null;
131
+ onerror: ((event: unknown) => void) | null;
132
+ send(data: string): void;
133
+ close(code?: number, reason?: string): void;
134
+ }
135
+ export type AttachWebSocketConstructor = new (url: string, protocols?: string | string[]) => AttachSocketLike;
136
+ /**
137
+ * Wrap a socket in a forwarding facade whose handler setters time the events
138
+ * statewire attaches to (`onopen`, `onmessage`, `onclose`). A facade rather
139
+ * than a subclass so the same instrumentation works over any host `WebSocket`
140
+ * implementation, including test fakes.
141
+ */
142
+ export declare function instrumentAttachSocket({ socket, url, onEvent, now, }: {
143
+ socket: AttachSocketLike;
144
+ /** The thread attach URL the events are attributed to (not the socket URL). */
145
+ url: string;
146
+ onEvent: (event: DeepAgentAttachTimingEvent) => void;
147
+ now?: () => number;
148
+ }): AttachSocketLike;
149
+ /**
150
+ * A `WebSocket`-shaped constructor that dials through `Base` and reports the
151
+ * attach events for `url`. Constructor semantics (`new` returns the facade)
152
+ * match what statewire's `webSocket` option expects.
153
+ */
154
+ export declare function instrumentedWebSocketConstructor({ Base, url, onEvent, now, }: {
155
+ Base: AttachWebSocketConstructor;
156
+ url: string;
157
+ onEvent: (event: DeepAgentAttachTimingEvent) => void;
158
+ now?: () => number;
159
+ }): AttachWebSocketConstructor;
160
+ /** Structural `fetch` — what statewire's SSE transport calls. */
161
+ export type AttachFetch = (input: string | URL, init?: unknown) => Promise<{
162
+ ok: boolean;
163
+ status: number;
164
+ headers: {
165
+ get(name: string): string | null;
166
+ };
167
+ }>;
168
+ /**
169
+ * A `fetch` that reports a `Retry-After` header on refused attach requests
170
+ * (the SSE `POST …/stream`) before handing the response back untouched.
171
+ */
172
+ export declare function instrumentedAttachFetch<TFetch extends AttachFetch>({ baseFetch, url, onEvent, now, }: {
173
+ baseFetch: TFetch;
174
+ url: string;
175
+ onEvent: (event: DeepAgentAttachTimingEvent) => void;
176
+ now?: () => number;
177
+ }): TFetch;
178
+ /**
179
+ * The transport option overrides for one attach: an instrumented `webSocket`
180
+ * (WS) or `fetch` (SSE) that reports attach events for `url` and feeds
181
+ * `Retry-After` hints into the gate. Returns `{}` where the host has no such
182
+ * global (a server render, a non-browser runtime) so the transport keeps its
183
+ * defaults.
184
+ */
185
+ export declare function createAttachInstrumentation({ url, sse, onEvent, retryGate, now, }: {
186
+ url: string;
187
+ sse: boolean;
188
+ onEvent?: ((event: DeepAgentAttachTimingEvent) => void) | undefined;
189
+ retryGate?: AttachRetryGate;
190
+ now?: () => number;
191
+ }): {
192
+ webSocket?: AttachWebSocketConstructor;
193
+ fetch?: AttachFetch;
194
+ };