@athenaintel/react 0.48.0 → 0.52.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 (255) hide show
  1. package/README.md +68 -10
  2. package/dist/agent-runtime/src/call-recap.cjs +319 -0
  3. package/dist/agent-runtime/src/call-recap.cjs.map +1 -0
  4. package/dist/agent-runtime/src/call-recap.d.ts +142 -0
  5. package/dist/agent-runtime/src/call-recap.js +319 -0
  6. package/dist/agent-runtime/src/call-recap.js.map +1 -0
  7. package/dist/agent-runtime/src/chat-outbox-store.cjs +1 -0
  8. package/dist/agent-runtime/src/chat-outbox-store.cjs.map +1 -1
  9. package/dist/agent-runtime/src/chat-outbox-store.d.ts +7 -0
  10. package/dist/agent-runtime/src/chat-outbox-store.js +1 -0
  11. package/dist/agent-runtime/src/chat-outbox-store.js.map +1 -1
  12. package/dist/agent-runtime/src/chat-outbox.cjs +46 -5
  13. package/dist/agent-runtime/src/chat-outbox.cjs.map +1 -1
  14. package/dist/agent-runtime/src/chat-outbox.d.ts +29 -0
  15. package/dist/agent-runtime/src/chat-outbox.js +46 -5
  16. package/dist/agent-runtime/src/chat-outbox.js.map +1 -1
  17. package/dist/agent-runtime/src/conversation-index.cjs.map +1 -1
  18. package/dist/agent-runtime/src/conversation-index.d.ts +7 -0
  19. package/dist/agent-runtime/src/conversation-index.js.map +1 -1
  20. package/dist/agent-runtime/src/conversation-list.cjs +2 -1
  21. package/dist/agent-runtime/src/conversation-list.cjs.map +1 -1
  22. package/dist/agent-runtime/src/conversation-list.d.ts +19 -3
  23. package/dist/agent-runtime/src/conversation-list.js +2 -1
  24. package/dist/agent-runtime/src/conversation-list.js.map +1 -1
  25. package/dist/agent-runtime/src/desktop-handoff.d.ts +10 -0
  26. package/dist/agent-runtime/src/edit-command.cjs +21 -0
  27. package/dist/agent-runtime/src/edit-command.cjs.map +1 -1
  28. package/dist/agent-runtime/src/edit-command.d.ts +8 -0
  29. package/dist/agent-runtime/src/edit-command.js +21 -0
  30. package/dist/agent-runtime/src/edit-command.js.map +1 -1
  31. package/dist/agent-runtime/src/handoff-arrival.cjs +19 -0
  32. package/dist/agent-runtime/src/handoff-arrival.cjs.map +1 -1
  33. package/dist/agent-runtime/src/handoff-arrival.d.ts +18 -3
  34. package/dist/agent-runtime/src/handoff-arrival.js +20 -1
  35. package/dist/agent-runtime/src/handoff-arrival.js.map +1 -1
  36. package/dist/agent-runtime/src/handoff-cursor-id.cjs +6 -0
  37. package/dist/agent-runtime/src/handoff-cursor-id.cjs.map +1 -0
  38. package/dist/agent-runtime/src/handoff-cursor-id.d.ts +12 -0
  39. package/dist/agent-runtime/src/handoff-cursor-id.js +6 -0
  40. package/dist/agent-runtime/src/handoff-cursor-id.js.map +1 -0
  41. package/dist/agent-runtime/src/handoff-cursor.cjs +88 -0
  42. package/dist/agent-runtime/src/handoff-cursor.cjs.map +1 -0
  43. package/dist/agent-runtime/src/handoff-cursor.d.ts +120 -0
  44. package/dist/agent-runtime/src/handoff-cursor.js +88 -0
  45. package/dist/agent-runtime/src/handoff-cursor.js.map +1 -0
  46. package/dist/agent-runtime/src/index.d.ts +9 -7
  47. package/dist/agent-runtime/src/interrupts.cjs +28 -1
  48. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  49. package/dist/agent-runtime/src/interrupts.d.ts +21 -1
  50. package/dist/agent-runtime/src/interrupts.js +28 -1
  51. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  52. package/dist/agent-runtime/src/model-context.cjs +3 -2
  53. package/dist/agent-runtime/src/model-context.cjs.map +1 -1
  54. package/dist/agent-runtime/src/model-context.d.ts +6 -1
  55. package/dist/agent-runtime/src/model-context.js +3 -2
  56. package/dist/agent-runtime/src/model-context.js.map +1 -1
  57. package/dist/agent-runtime/src/runtime.d.ts +3 -2
  58. package/dist/agent-runtime/src/send-recovery.cjs +37 -3
  59. package/dist/agent-runtime/src/send-recovery.cjs.map +1 -1
  60. package/dist/agent-runtime/src/send-recovery.d.ts +19 -0
  61. package/dist/agent-runtime/src/send-recovery.js +37 -3
  62. package/dist/agent-runtime/src/send-recovery.js.map +1 -1
  63. package/dist/agent-runtime/src/thread-handoff-flow-machine.d.ts +14 -8
  64. package/dist/agent-runtime/src/thread-handoff-protocol.d.ts +227 -5
  65. package/dist/agent-runtime/src/thread-handoff.d.ts +1 -1
  66. package/dist/agent-runtime/src/use-conversation-list.cjs +3 -2
  67. package/dist/agent-runtime/src/use-conversation-list.cjs.map +1 -1
  68. package/dist/agent-runtime/src/use-conversation-list.d.ts +6 -0
  69. package/dist/agent-runtime/src/use-conversation-list.js +3 -2
  70. package/dist/agent-runtime/src/use-conversation-list.js.map +1 -1
  71. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +21 -1
  72. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -1
  73. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +8 -2
  74. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +21 -1
  75. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -1
  76. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +24 -6
  77. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  78. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +17 -0
  79. package/dist/agent-runtime/src/use-deep-agent-runtime.js +24 -6
  80. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  81. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +44 -9
  82. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -1
  83. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +34 -1
  84. package/dist/agent-runtime/src/use-deep-agent-voice.js +44 -9
  85. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -1
  86. package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs +8 -3
  87. package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs.map +1 -1
  88. package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +7 -0
  89. package/dist/agent-runtime/src/use-deep-agent-window-sync.js +9 -4
  90. package/dist/agent-runtime/src/use-deep-agent-window-sync.js.map +1 -1
  91. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +13 -2
  92. package/dist/agent-runtime/src/voice-earcon.cjs +139 -0
  93. package/dist/agent-runtime/src/voice-earcon.cjs.map +1 -0
  94. package/dist/agent-runtime/src/voice-earcon.d.ts +38 -0
  95. package/dist/agent-runtime/src/voice-earcon.js +139 -0
  96. package/dist/agent-runtime/src/voice-earcon.js.map +1 -0
  97. package/dist/agent-runtime/src/voice-media.cjs.map +1 -1
  98. package/dist/agent-runtime/src/voice-media.d.ts +14 -0
  99. package/dist/agent-runtime/src/voice-media.js.map +1 -1
  100. package/dist/agent-runtime/src/voice-presentation.cjs +2 -0
  101. package/dist/agent-runtime/src/voice-presentation.cjs.map +1 -1
  102. package/dist/agent-runtime/src/voice-presentation.js +2 -0
  103. package/dist/agent-runtime/src/voice-presentation.js.map +1 -1
  104. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  105. package/dist/assets/AthenaAssetEmbed.d.ts +11 -5
  106. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  107. package/dist/assets/use-asset-embed.cjs.map +1 -1
  108. package/dist/assets/use-asset-embed.d.ts +12 -5
  109. package/dist/assets/use-asset-embed.js.map +1 -1
  110. package/dist/chat/AthenaChat.cjs +27 -12
  111. package/dist/chat/AthenaChat.cjs.map +1 -1
  112. package/dist/chat/AthenaChat.d.ts +13 -0
  113. package/dist/chat/AthenaChat.js +27 -12
  114. package/dist/chat/AthenaChat.js.map +1 -1
  115. package/dist/chat/AthenaPlanStrip.cjs +97 -0
  116. package/dist/chat/AthenaPlanStrip.cjs.map +1 -0
  117. package/dist/chat/AthenaPlanStrip.d.ts +15 -0
  118. package/dist/chat/AthenaPlanStrip.js +97 -0
  119. package/dist/chat/AthenaPlanStrip.js.map +1 -0
  120. package/dist/chat/StatewireApprovalCard.cjs +41 -6
  121. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  122. package/dist/chat/StatewireApprovalCard.d.ts +18 -1
  123. package/dist/chat/StatewireApprovalCard.js +42 -7
  124. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  125. package/dist/chat/StatewireQueuedMessages.cjs +56 -6
  126. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  127. package/dist/chat/StatewireQueuedMessages.d.ts +14 -0
  128. package/dist/chat/StatewireQueuedMessages.js +58 -8
  129. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  130. package/dist/chat/WaitingOnYouBanner.cjs +6 -2
  131. package/dist/chat/WaitingOnYouBanner.cjs.map +1 -1
  132. package/dist/chat/WaitingOnYouBanner.js +7 -3
  133. package/dist/chat/WaitingOnYouBanner.js.map +1 -1
  134. package/dist/chat/chat-voice-controls.cjs +3 -1
  135. package/dist/chat/chat-voice-controls.cjs.map +1 -1
  136. package/dist/chat/chat-voice-controls.d.ts +6 -1
  137. package/dist/chat/chat-voice-controls.js +3 -1
  138. package/dist/chat/chat-voice-controls.js.map +1 -1
  139. package/dist/chat/super-grouping/SuperGroupingCard.cjs +4 -2
  140. package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
  141. package/dist/chat/super-grouping/SuperGroupingCard.js +4 -2
  142. package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
  143. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +4 -2
  144. package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
  145. package/dist/chat/super-grouping/SuperGroupingTranscript.js +4 -2
  146. package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
  147. package/dist/chat/super-grouping/activity-timeline.cjs +6 -4
  148. package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
  149. package/dist/chat/super-grouping/activity-timeline.d.ts +9 -1
  150. package/dist/chat/super-grouping/activity-timeline.js +6 -4
  151. package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
  152. package/dist/chat/super-grouping/index.d.ts +1 -1
  153. package/dist/chat/super-grouping/use-earlier-steps-unloaded.cjs +17 -0
  154. package/dist/chat/super-grouping/use-earlier-steps-unloaded.cjs.map +1 -0
  155. package/dist/chat/super-grouping/use-earlier-steps-unloaded.d.ts +8 -0
  156. package/dist/chat/super-grouping/use-earlier-steps-unloaded.js +17 -0
  157. package/dist/chat/super-grouping/use-earlier-steps-unloaded.js.map +1 -0
  158. package/dist/chat-ui/index.cjs +11 -0
  159. package/dist/chat-ui/index.cjs.map +1 -1
  160. package/dist/chat-ui/index.d.ts +3 -1
  161. package/dist/chat-ui/index.js +12 -1
  162. package/dist/chat-ui/index.js.map +1 -1
  163. package/dist/chat-ui/messages/from-the-call-card.cjs +124 -0
  164. package/dist/chat-ui/messages/from-the-call-card.cjs.map +1 -0
  165. package/dist/chat-ui/messages/from-the-call-card.d.ts +17 -0
  166. package/dist/chat-ui/messages/from-the-call-card.js +124 -0
  167. package/dist/chat-ui/messages/from-the-call-card.js.map +1 -0
  168. package/dist/chat-ui/rich-text/chat-link.cjs +1 -0
  169. package/dist/chat-ui/rich-text/chat-link.cjs.map +1 -1
  170. package/dist/chat-ui/rich-text/chat-link.d.ts +4 -0
  171. package/dist/chat-ui/rich-text/chat-link.js +4 -3
  172. package/dist/chat-ui/rich-text/chat-link.js.map +1 -1
  173. package/dist/chat-ui/rich-text/chat-message-body.cjs +1 -0
  174. package/dist/chat-ui/rich-text/chat-message-body.cjs.map +1 -1
  175. package/dist/chat-ui/rich-text/chat-message-body.d.ts +12 -0
  176. package/dist/chat-ui/rich-text/chat-message-body.js +2 -1
  177. package/dist/chat-ui/rich-text/chat-message-body.js.map +1 -1
  178. package/dist/chat-ui/thread/chat-thread-shell.cjs +4 -0
  179. package/dist/chat-ui/thread/chat-thread-shell.cjs.map +1 -1
  180. package/dist/chat-ui/thread/chat-thread-shell.d.ts +4 -0
  181. package/dist/chat-ui/thread/chat-thread-shell.js +4 -0
  182. package/dist/chat-ui/thread/chat-thread-shell.js.map +1 -1
  183. package/dist/chat-ui/thread/handoff-cursor.cjs +216 -0
  184. package/dist/chat-ui/thread/handoff-cursor.cjs.map +1 -0
  185. package/dist/chat-ui/thread/handoff-cursor.d.ts +57 -0
  186. package/dist/chat-ui/thread/handoff-cursor.js +216 -0
  187. package/dist/chat-ui/thread/handoff-cursor.js.map +1 -0
  188. package/dist/chat-ui/thread/statewire-history-edge.cjs +2 -0
  189. package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
  190. package/dist/chat-ui/thread/statewire-history-edge.d.ts +2 -0
  191. package/dist/chat-ui/thread/statewire-history-edge.js +3 -1
  192. package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
  193. package/dist/collab/client.cjs +15 -3
  194. package/dist/collab/client.cjs.map +1 -1
  195. package/dist/collab/client.d.ts +4 -2
  196. package/dist/collab/client.js +16 -4
  197. package/dist/collab/client.js.map +1 -1
  198. package/dist/composer/index.d.ts +1 -1
  199. package/dist/composer/useReadComposerDraft.cjs +26 -7
  200. package/dist/composer/useReadComposerDraft.cjs.map +1 -1
  201. package/dist/composer/useReadComposerDraft.d.ts +23 -1
  202. package/dist/composer/useReadComposerDraft.js +27 -8
  203. package/dist/composer/useReadComposerDraft.js.map +1 -1
  204. package/dist/index.cjs +5 -0
  205. package/dist/index.cjs.map +1 -1
  206. package/dist/index.d.ts +5 -2
  207. package/dist/index.js +6 -1
  208. package/dist/index.js.map +1 -1
  209. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs +207 -0
  210. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs.map +1 -0
  211. package/dist/keryx-http/src/unconfirmed-update-attributions.d.ts +141 -0
  212. package/dist/keryx-http/src/unconfirmed-update-attributions.js +207 -0
  213. package/dist/keryx-http/src/unconfirmed-update-attributions.js.map +1 -0
  214. package/dist/keryx-http/src/update-attributions.cjs +34 -4
  215. package/dist/keryx-http/src/update-attributions.cjs.map +1 -1
  216. package/dist/keryx-http/src/update-attributions.d.ts +36 -4
  217. package/dist/keryx-http/src/update-attributions.js +35 -5
  218. package/dist/keryx-http/src/update-attributions.js.map +1 -1
  219. package/dist/provider/AthenaProvider.cjs +4 -0
  220. package/dist/provider/AthenaProvider.cjs.map +1 -1
  221. package/dist/provider/AthenaProvider.d.ts +11 -1
  222. package/dist/provider/AthenaProvider.js +4 -0
  223. package/dist/provider/AthenaProvider.js.map +1 -1
  224. package/dist/react/package.json.cjs +1 -1
  225. package/dist/react/package.json.js +1 -1
  226. package/dist/styles.css +1 -1
  227. package/dist/threads/api.cjs.map +1 -1
  228. package/dist/threads/api.d.ts +15 -0
  229. package/dist/threads/api.js.map +1 -1
  230. package/dist/threads/conversation-list-fetcher.cjs +13 -5
  231. package/dist/threads/conversation-list-fetcher.cjs.map +1 -1
  232. package/dist/threads/conversation-list-fetcher.d.ts +4 -1
  233. package/dist/threads/conversation-list-fetcher.js +13 -5
  234. package/dist/threads/conversation-list-fetcher.js.map +1 -1
  235. package/dist/threads/statewire-thread-list.cjs +28 -6
  236. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  237. package/dist/threads/statewire-thread-list.d.ts +20 -8
  238. package/dist/threads/statewire-thread-list.js +28 -6
  239. package/dist/threads/statewire-thread-list.js.map +1 -1
  240. package/dist/threads/use-athena-sessions.cjs +27 -5
  241. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  242. package/dist/threads/use-athena-sessions.d.ts +10 -5
  243. package/dist/threads/use-athena-sessions.js +28 -6
  244. package/dist/threads/use-athena-sessions.js.map +1 -1
  245. package/dist/threads/use-rest-conversation-history.d.ts +1 -0
  246. package/dist/tools/write-todos-tool-ui.cjs +8 -0
  247. package/dist/tools/write-todos-tool-ui.cjs.map +1 -1
  248. package/dist/tools/write-todos-tool-ui.d.ts +2 -0
  249. package/dist/tools/write-todos-tool-ui.js +8 -0
  250. package/dist/tools/write-todos-tool-ui.js.map +1 -1
  251. package/dist/workbench/session-workbench-panes.cjs +1 -8
  252. package/dist/workbench/session-workbench-panes.cjs.map +1 -1
  253. package/dist/workbench/session-workbench-panes.js +2 -9
  254. package/dist/workbench/session-workbench-panes.js.map +1 -1
  255. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"edit-command.js","sources":["../../../../agent-runtime/src/edit-command.ts"],"sourcesContent":["import type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { DEEP_AGENT_INTEREST_PROTOCOL } from './generated/runconfig-contract';\nimport {\n type DeepAgentMessageWindow,\n pageInterestRequests,\n readDeepAgentMessageWindow,\n} from './message-window';\nimport { hasStatewireThreadExtras } from './thread-extras';\n\n/**\n * Wire-accurate `run/edit` construction for deep-agent retry/edit, shared by\n * every surface that resubmits a user message.\n *\n * assistant-ui builds the command's `runAnchorMessageId` from the CONVERTED\n * thread messages (`resolveEditCommand`: `messages[index - 1].id`), but the\n * deep-agent host validates that anchor against the edited message's parent in\n * its RAW message list (`harness_sdk.linear_thread`: the entry before it in\n * `state[\"messages\"]`). Those two lists do not line up:\n *\n * - the converter chunks an assistant turn and its tool messages into ONE\n * thread message carrying only the FIRST wire id, so the anchor names the\n * head of the previous turn instead of its last tool message;\n * - `sanitizeLangChainMessages` drops hidden-from-frontend and unconvertible\n * entries, so a dropped tail message is invisible to the anchor too.\n *\n * Either way the host rejects the command with `wrong-anchor`\n * (`runAnchorMessageId … is not the source's parent`) AFTER the composer's\n * synchronous `send()` returned, so the retry/edit silently does nothing.\n *\n * Building the command here off the replicated raw state makes the anchor the\n * same value the host computes.\n *\n * The raw list is the loaded interest window, so the first loaded message's\n * parent is not in it while older messages exist — an edit there must not\n * anchor on `null` (the root, rejected `wrong-anchor`); a message below the\n * window has no parent on this client at all. {@link resolveDeepAgentEditCommand}\n * states older page interests until the parent is loaded.\n */\n\n/**\n * Host metadata frozen at submission, settling once the async capture does.\n * The message-metadata preparation surface — `prepareMessageMetadata`,\n * `discardPreparedMessageMetadata`, `sendPreparedEdit` and `sendCommand`'s\n * `preparedMetadata` option — is what the monorepo patches into\n * `@assistant-ui/react-statewire@0.31.0` (`patches/`). It is declared\n * structurally here rather than as `StatewireThread.Extras[...]` so that the\n * published sources also compile against the unpatched upstream typings, where\n * those members are absent and the edit path's optional calls never run.\n */\nexport type DeepAgentPreparedMessageMetadata = Promise<Record<string, unknown> | undefined>;\n\n/** The pieces of the statewire thread extras the edit path reads. */\nexport interface DeepAgentStatewireExtras {\n /** The library's dispatch; it resolves with the host's reply to the command. */\n sendCommand: (\n command: StatewireThread.Command,\n options?: { preparedMetadata?: DeepAgentPreparedMessageMetadata | undefined },\n ) => Promise<unknown> | void;\n /** Optional on older hosts; capture before loading an edit's history anchor. */\n prepareMessageMetadata?: (() => DeepAgentPreparedMessageMetadata) | undefined;\n discardPreparedMessageMetadata?:\n | ((prepared: DeepAgentPreparedMessageMetadata) => void)\n | undefined;\n sendPreparedEdit?:\n | ((sourceId: string, prepared: DeepAgentPreparedMessageMetadata) => void)\n | undefined;\n isPreparingSubmission?: boolean;\n /** The composed thread state — its `messages` are the raw wire messages of the loaded window. */\n state: { messages?: readonly { id?: unknown }[] } | null;\n /** The mounted documents (the interest window), absent on a wire without documents. */\n documents?: StatewireThread.Extras['documents'];\n invoke?: StatewireThread.Extras['invoke'];\n /** The live run, when one is in flight; `epoch` advances on each dispatch. */\n runs: { runId?: string | null; epoch?: number };\n /** The host's replicated run status; absent on a surface that predates it. */\n status?: StatewireThread.ThreadStatus;\n}\n\n/**\n * The statewire extras of the nearest aui thread, or `null` when the thread is\n * not a statewire thread (e.g. a read-only subagent transcript runtime).\n * Gated on {@link hasStatewireThreadExtras} for the same reason the approval\n * card is: the library's own hooks throw on a non-statewire thread.\n */\nexport function readDeepAgentStatewireExtras(extras: unknown): DeepAgentStatewireExtras | null {\n if (!hasStatewireThreadExtras(extras)) return null;\n return extras as DeepAgentStatewireExtras;\n}\n\n/**\n * The host's parent of `sourceId`: the raw wire message directly before it\n * (`null` when it is the first of the whole transcript). Returns `undefined`\n * when `sourceId` is not in the raw list at all — an optimistic bubble the\n * host has not settled yet, a message below the loaded window, or a surface\n * whose state this module cannot read — or when it is the first loaded\n * message while older ones exist (`hasOlder`), so the caller can load more or\n * fall back to the library's own path instead of asserting a wrong anchor.\n */\nexport function resolveWireAnchorMessageId({\n wireMessages,\n sourceId,\n hasOlder = false,\n}: {\n wireMessages: readonly { id?: unknown }[] | undefined;\n sourceId: string;\n hasOlder?: boolean;\n}): string | null | undefined {\n if (!wireMessages) return undefined;\n const index = wireMessages.findIndex((message) => message?.id === sourceId);\n if (index < 0) return undefined;\n if (index === 0) return hasOlder ? undefined : null;\n const parentId = wireMessages[index - 1]?.id;\n return typeof parentId === 'string' ? parentId : undefined;\n}\n\n/**\n * Whether `sourceId`'s parent lies below the loaded window: the message is\n * absent from the raw list, or its first entry, while older messages exist.\n * The caller loads older history before an edit can be anchored.\n */\nexport function isSourceBelowLoadedWindow({\n wireMessages,\n sourceId,\n window,\n}: {\n wireMessages: readonly { id?: unknown }[] | undefined;\n sourceId: string;\n window: DeepAgentMessageWindow | null;\n}): boolean {\n if (!wireMessages || window === null || !window.hasOlder) return false;\n const index = wireMessages.findIndex((message) => message?.id === sourceId);\n return index <= 0;\n}\n\nconst readWindow = (extras: DeepAgentStatewireExtras) =>\n readDeepAgentMessageWindow(extras.documents?.list());\n\n/**\n * A fresh command / message id (uniqueness, not secrecy). `crypto.randomUUID`\n * where the host runtime has it — every browser, Bun, Node and Hermes with\n * webcrypto — and a v4-shaped fallback elsewhere, so the shared path never\n * throws on a runtime without full webcrypto.\n */\nfunction mintCommandId(): string {\n const webcrypto = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (typeof webcrypto?.randomUUID === 'function') return webcrypto.randomUUID();\n const hex = (): string => Math.floor(Math.random() * 0x10000).toString(16).padStart(4, '0');\n return `${hex()}${hex()}-${hex()}-4${hex().slice(1)}-${hex()}-${hex()}${hex()}${hex()}`;\n}\n\n/**\n * The `run/edit` command for resubmitting `sourceId` with `text`, anchored on\n * the host's own parent. `null` when the anchor cannot be resolved from the\n * replicated state.\n */\nexport function buildDeepAgentEditCommand({\n extras,\n sourceId,\n text,\n}: {\n extras: DeepAgentStatewireExtras;\n sourceId: string;\n text: string;\n}): StatewireThread.RunEditCommand | null {\n const runAnchorMessageId = resolveWireAnchorMessageId({\n wireMessages: extras.state?.messages,\n sourceId,\n hasOlder: readWindow(extras)?.hasOlder ?? false,\n });\n if (runAnchorMessageId === undefined) return null;\n return {\n type: 'run/edit',\n runId: extras.runs.runId ?? mintCommandId(),\n message: { id: mintCommandId(), role: 'user', parts: [{ type: 'text', text }] },\n sourceId,\n runAnchorMessageId,\n };\n}\n\n/**\n * State one more page of older history for a windowed thread: the next page\n * past the loaded window's oldest message. Resolves `true` once the host has\n * mounted it (it answers the statement after mounting), `false` when there is\n * nothing older, the thread is not a windowed statewire thread, or no page can\n * be stated. For a reader that needs a message below the loaded window — a\n * search result revealing an older turn of a long conversation — and pages\n * until it renders.\n */\nexport async function loadOlderDeepAgentHistoryPage({\n readExtras,\n pageSize,\n}: {\n readExtras: () => DeepAgentStatewireExtras | null;\n pageSize?: number;\n}): Promise<boolean> {\n const extras = readExtras();\n if (!extras?.invoke) return false;\n const window = readWindow(extras);\n if (window === null || !window.hasOlder) return false;\n const requests = pageInterestRequests(window, pageSize);\n if (requests === null) return false;\n await extras.invoke(DEEP_AGENT_INTEREST_PROTOCOL, 'set', [requests]);\n return true;\n}\n\n/**\n * Pages of older history stated while looking for an edited message's host\n * parent. Each page is up to a window's worth of messages, so an edit reaches\n * this many windows below what was loaded before it gives up.\n */\nexport const MAX_EDIT_ANCHOR_HISTORY_LOADS = 5;\n\n/**\n * The anchored `run/edit` for `sourceId`, stating older page interests one at\n * a time when the message's parent lies below the loaded window. Every page\n * is read back from the live documents (`readExtras` — the host mounts them\n * before it answers the statement), so the anchor is always the host's own\n * parent id.\n *\n * Resolves `null` — the caller's cue for the library's composer path, whose\n * failure it reports — when the thread is not a statewire thread, the host has\n * not settled the message, the history is exhausted without it, or the page\n * budget ({@link MAX_EDIT_ANCHOR_HISTORY_LOADS}) is spent. A synchronous\n * resolution never awaits: the first read either anchors at once or decides\n * that pages are needed.\n */\nexport async function resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n pageSize,\n maxHistoryLoads = MAX_EDIT_ANCHOR_HISTORY_LOADS,\n}: {\n /** The live thread extras — re-read per page so each anchor attempt sees the widened window. */\n readExtras: () => DeepAgentStatewireExtras | null;\n sourceId: string;\n text: string;\n pageSize?: number;\n maxHistoryLoads?: number;\n}): Promise<StatewireThread.RunEditCommand | null> {\n for (let page = 0; page <= maxHistoryLoads; page += 1) {\n const extras = readExtras();\n if (!extras) return null;\n const command = buildDeepAgentEditCommand({ extras, sourceId, text });\n if (command) return command;\n if (page === maxHistoryLoads || !extras.invoke) return null;\n const window = readWindow(extras);\n if (!isSourceBelowLoadedWindow({ wireMessages: extras.state?.messages, sourceId, window })) {\n return null;\n }\n const requests = window === null ? null : pageInterestRequests(window, pageSize);\n if (requests === null) return null;\n await extras.invoke(DEEP_AGENT_INTEREST_PROTOCOL, 'set', [requests]);\n }\n return null;\n}\n"],"names":[],"mappings":";;;AAoFO,SAAS,6BAA6B,QAAkD;AAC7F,MAAI,CAAC,yBAAyB,MAAM,EAAG,QAAO;AAC9C,SAAO;AACT;AAWO,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAI8B;;AAC5B,MAAI,CAAC,aAAc,QAAO;AAC1B,QAAM,QAAQ,aAAa,UAAU,CAAC,aAAY,mCAAS,QAAO,QAAQ;AAC1E,MAAI,QAAQ,EAAG,QAAO;AACtB,MAAI,UAAU,EAAG,QAAO,WAAW,SAAY;AAC/C,QAAM,YAAW,kBAAa,QAAQ,CAAC,MAAtB,mBAAyB;AAC1C,SAAO,OAAO,aAAa,WAAW,WAAW;AACnD;AAOO,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAIY;AACV,MAAI,CAAC,gBAAgB,WAAW,QAAQ,CAAC,OAAO,SAAU,QAAO;AACjE,QAAM,QAAQ,aAAa,UAAU,CAAC,aAAY,mCAAS,QAAO,QAAQ;AAC1E,SAAO,SAAS;AAClB;AAEA,MAAM,aAAa,CAAC,WAAA;;AAClB,qCAA2B,YAAO,cAAP,mBAAkB,MAAM;AAAA;AAQrD,SAAS,gBAAwB;AAC/B,QAAM,YAAa,WAA0D;AAC7E,MAAI,QAAO,uCAAW,gBAAe,WAAY,QAAO,UAAU,WAAA;AAClE,QAAM,MAAM,MAAc,KAAK,MAAM,KAAK,OAAA,IAAW,KAAO,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAC1F,SAAO,GAAG,IAAA,CAAK,GAAG,IAAA,CAAK,IAAI,IAAA,CAAK,KAAK,MAAM,MAAM,CAAC,CAAC,IAAI,IAAA,CAAK,IAAI,KAAK,GAAG,IAAA,CAAK,GAAG,IAAA,CAAK;AACvF;AAOO,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAI0C;;AACxC,QAAM,qBAAqB,2BAA2B;AAAA,IACpD,eAAc,YAAO,UAAP,mBAAc;AAAA,IAC5B;AAAA,IACA,YAAU,gBAAW,MAAM,MAAjB,mBAAoB,aAAY;AAAA,EAAA,CAC3C;AACD,MAAI,uBAAuB,OAAW,QAAO;AAC7C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO,OAAO,KAAK,SAAS,cAAA;AAAA,IAC5B,SAAS,EAAE,IAAI,cAAA,GAAiB,MAAM,QAAQ,OAAO,CAAC,EAAE,MAAM,QAAQ,KAAA,CAAM,EAAA;AAAA,IAC5E;AAAA,IACA;AAAA,EAAA;AAEJ;AAiCO,MAAM,gCAAgC;AAgB7C,eAAsB,4BAA4B;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACpB,GAOmD;;AACjD,WAAS,OAAO,GAAG,QAAQ,iBAAiB,QAAQ,GAAG;AACrD,UAAM,SAAS,WAAA;AACf,QAAI,CAAC,OAAQ,QAAO;AACpB,UAAM,UAAU,0BAA0B,EAAE,QAAQ,UAAU,MAAM;AACpE,QAAI,QAAS,QAAO;AACpB,QAAI,SAAS,mBAAmB,CAAC,OAAO,OAAQ,QAAO;AACvD,UAAM,SAAS,WAAW,MAAM;AAChC,QAAI,CAAC,0BAA0B,EAAE,eAAc,YAAO,UAAP,mBAAc,UAAU,UAAU,OAAA,CAAQ,GAAG;AAC1F,aAAO;AAAA,IACT;AACA,UAAM,WAAW,WAAW,OAAO,OAAO,qBAAqB,QAAQ,QAAQ;AAC/E,QAAI,aAAa,KAAM,QAAO;AAC9B,UAAM,OAAO,OAAO,8BAA8B,OAAO,CAAC,QAAQ,CAAC;AAAA,EACrE;AACA,SAAO;AACT;"}
1
+ {"version":3,"file":"edit-command.js","sources":["../../../../agent-runtime/src/edit-command.ts"],"sourcesContent":["import type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { DEEP_AGENT_INTEREST_PROTOCOL } from './generated/runconfig-contract';\nimport {\n type DeepAgentMessageWindow,\n pageInterestRequests,\n readDeepAgentMessageWindow,\n} from './message-window';\nimport { hasStatewireThreadExtras } from './thread-extras';\n\n/**\n * Wire-accurate `run/edit` construction for deep-agent retry/edit, shared by\n * every surface that resubmits a user message.\n *\n * assistant-ui builds the command's `runAnchorMessageId` from the CONVERTED\n * thread messages (`resolveEditCommand`: `messages[index - 1].id`), but the\n * deep-agent host validates that anchor against the edited message's parent in\n * its RAW message list (`harness_sdk.linear_thread`: the entry before it in\n * `state[\"messages\"]`). Those two lists do not line up:\n *\n * - the converter chunks an assistant turn and its tool messages into ONE\n * thread message carrying only the FIRST wire id, so the anchor names the\n * head of the previous turn instead of its last tool message;\n * - `sanitizeLangChainMessages` drops hidden-from-frontend and unconvertible\n * entries, so a dropped tail message is invisible to the anchor too.\n *\n * Either way the host rejects the command with `wrong-anchor`\n * (`runAnchorMessageId … is not the source's parent`) AFTER the composer's\n * synchronous `send()` returned, so the retry/edit silently does nothing.\n *\n * Building the command here off the replicated raw state makes the anchor the\n * same value the host computes.\n *\n * The raw list is the loaded interest window, so the first loaded message's\n * parent is not in it while older messages exist — an edit there must not\n * anchor on `null` (the root, rejected `wrong-anchor`); a message below the\n * window has no parent on this client at all. {@link resolveDeepAgentEditCommand}\n * states older page interests until the parent is loaded.\n */\n\n/**\n * Host metadata frozen at submission, settling once the async capture does.\n * The message-metadata preparation surface — `prepareMessageMetadata`,\n * `discardPreparedMessageMetadata`, `sendPreparedEdit` and `sendCommand`'s\n * `preparedMetadata` option — is what the monorepo patches into\n * `@assistant-ui/react-statewire@0.31.0` (`patches/`). It is declared\n * structurally here rather than as `StatewireThread.Extras[...]` so that the\n * published sources also compile against the unpatched upstream typings, where\n * those members are absent and the edit path's optional calls never run.\n */\nexport type DeepAgentPreparedMessageMetadata = Promise<Record<string, unknown> | undefined>;\n\n/** The pieces of the statewire thread extras the edit path reads. */\nexport interface DeepAgentStatewireExtras {\n /** The library's dispatch; it resolves with the host's reply to the command. */\n sendCommand: (\n command: StatewireThread.Command,\n options?: { preparedMetadata?: DeepAgentPreparedMessageMetadata | undefined },\n ) => Promise<unknown> | void;\n /** Optional on older hosts; capture before loading an edit's history anchor. */\n prepareMessageMetadata?: (() => DeepAgentPreparedMessageMetadata) | undefined;\n discardPreparedMessageMetadata?:\n | ((prepared: DeepAgentPreparedMessageMetadata) => void)\n | undefined;\n sendPreparedEdit?:\n | ((sourceId: string, prepared: DeepAgentPreparedMessageMetadata) => void)\n | undefined;\n isPreparingSubmission?: boolean;\n /** The composed thread state — its `messages` are the raw wire messages of the loaded window. */\n state: { messages?: readonly { id?: unknown }[] } | null;\n /** The mounted documents (the interest window), absent on a wire without documents. */\n documents?: StatewireThread.Extras['documents'];\n invoke?: StatewireThread.Extras['invoke'];\n /** The live run, when one is in flight; `epoch` advances on each dispatch. */\n runs: { runId?: string | null; epoch?: number };\n /** The host's replicated run status; absent on a surface that predates it. */\n status?: StatewireThread.ThreadStatus;\n}\n\n/**\n * The statewire extras of the nearest aui thread, or `null` when the thread is\n * not a statewire thread (e.g. a read-only subagent transcript runtime).\n * Gated on {@link hasStatewireThreadExtras} for the same reason the approval\n * card is: the library's own hooks throw on a non-statewire thread.\n */\nexport function readDeepAgentStatewireExtras(extras: unknown): DeepAgentStatewireExtras | null {\n if (!hasStatewireThreadExtras(extras)) return null;\n return extras as DeepAgentStatewireExtras;\n}\n\n/**\n * The host's parent of `sourceId`: the raw wire message directly before it\n * (`null` when it is the first of the whole transcript). Returns `undefined`\n * when `sourceId` is not in the raw list at all — an optimistic bubble the\n * host has not settled yet, a message below the loaded window, or a surface\n * whose state this module cannot read — or when it is the first loaded\n * message while older ones exist (`hasOlder`), so the caller can load more or\n * fall back to the library's own path instead of asserting a wrong anchor.\n */\nexport function resolveWireAnchorMessageId({\n wireMessages,\n sourceId,\n hasOlder = false,\n}: {\n wireMessages: readonly { id?: unknown }[] | undefined;\n sourceId: string;\n hasOlder?: boolean;\n}): string | null | undefined {\n if (!wireMessages) return undefined;\n const index = wireMessages.findIndex((message) => message?.id === sourceId);\n if (index < 0) return undefined;\n if (index === 0) return hasOlder ? undefined : null;\n const parentId = wireMessages[index - 1]?.id;\n return typeof parentId === 'string' ? parentId : undefined;\n}\n\n/**\n * Whether `sourceId`'s parent lies below the loaded window: the message is\n * absent from the raw list, or its first entry, while older messages exist.\n * The caller loads older history before an edit can be anchored.\n */\nexport function isSourceBelowLoadedWindow({\n wireMessages,\n sourceId,\n window,\n}: {\n wireMessages: readonly { id?: unknown }[] | undefined;\n sourceId: string;\n window: DeepAgentMessageWindow | null;\n}): boolean {\n if (!wireMessages || window === null || !window.hasOlder) return false;\n const index = wireMessages.findIndex((message) => message?.id === sourceId);\n return index <= 0;\n}\n\nconst readWindow = (extras: DeepAgentStatewireExtras) =>\n readDeepAgentMessageWindow(extras.documents?.list());\n\n/**\n * A fresh command / message id (uniqueness, not secrecy). `crypto.randomUUID`\n * where the host runtime has it — every browser, Bun, Node and Hermes with\n * webcrypto — and a v4-shaped fallback elsewhere, so the shared path never\n * throws on a runtime without full webcrypto.\n */\nfunction mintCommandId(): string {\n const webcrypto = (globalThis as { crypto?: { randomUUID?: () => string } }).crypto;\n if (typeof webcrypto?.randomUUID === 'function') return webcrypto.randomUUID();\n const hex = (): string => Math.floor(Math.random() * 0x10000).toString(16).padStart(4, '0');\n return `${hex()}${hex()}-${hex()}-4${hex().slice(1)}-${hex()}-${hex()}${hex()}${hex()}`;\n}\n\n/**\n * The `run/edit` command for resubmitting `sourceId` with `text`, anchored on\n * the host's own parent. `null` when the anchor cannot be resolved from the\n * replicated state.\n */\nexport function buildDeepAgentEditCommand({\n extras,\n sourceId,\n text,\n}: {\n extras: DeepAgentStatewireExtras;\n sourceId: string;\n text: string;\n}): StatewireThread.RunEditCommand | null {\n const runAnchorMessageId = resolveWireAnchorMessageId({\n wireMessages: extras.state?.messages,\n sourceId,\n hasOlder: readWindow(extras)?.hasOlder ?? false,\n });\n if (runAnchorMessageId === undefined) return null;\n return {\n type: 'run/edit',\n runId: extras.runs.runId ?? mintCommandId(),\n message: { id: mintCommandId(), role: 'user', parts: [{ type: 'text', text }] },\n sourceId,\n runAnchorMessageId,\n };\n}\n\n/**\n * Whether a windowed statewire thread has older history than it has loaded:\n * `null` while that is not known yet (the head interest has not resolved; a\n * remembered transcript can show from cache before it does), and `false` for\n * a thread that is not a statewire thread, so a reader looking for an older\n * message waits for the window, or stops.\n */\nexport function deepAgentHistoryHasOlder(extras: unknown): boolean | null {\n const typed = readDeepAgentStatewireExtras(extras);\n if (typed === null) return false;\n return readWindow(typed)?.hasOlder ?? null;\n}\n\n/**\n * State one more page of older history for a windowed thread: the next page\n * past the loaded window's oldest message. Resolves `true` once the host has\n * mounted it (it answers the statement after mounting), `false` when there is\n * nothing older, the thread is not a windowed statewire thread, or no page can\n * be stated. For a reader that needs a message below the loaded window — a\n * search result revealing an older turn of a long conversation — and pages\n * until it renders.\n */\nexport async function loadOlderDeepAgentHistoryPage({\n readExtras,\n pageSize,\n}: {\n readExtras: () => DeepAgentStatewireExtras | null;\n pageSize?: number;\n}): Promise<boolean> {\n const extras = readExtras();\n if (!extras?.invoke) return false;\n const window = readWindow(extras);\n if (window === null || !window.hasOlder) return false;\n const requests = pageInterestRequests(window, pageSize);\n if (requests === null) return false;\n await extras.invoke(DEEP_AGENT_INTEREST_PROTOCOL, 'set', [requests]);\n return true;\n}\n\n/**\n * Pages of older history stated while looking for an edited message's host\n * parent. Each page is up to a window's worth of messages, so an edit reaches\n * this many windows below what was loaded before it gives up.\n */\nexport const MAX_EDIT_ANCHOR_HISTORY_LOADS = 5;\n\n/**\n * The anchored `run/edit` for `sourceId`, stating older page interests one at\n * a time when the message's parent lies below the loaded window. Every page\n * is read back from the live documents (`readExtras` — the host mounts them\n * before it answers the statement), so the anchor is always the host's own\n * parent id.\n *\n * Resolves `null` — the caller's cue for the library's composer path, whose\n * failure it reports — when the thread is not a statewire thread, the host has\n * not settled the message, the history is exhausted without it, or the page\n * budget ({@link MAX_EDIT_ANCHOR_HISTORY_LOADS}) is spent. A synchronous\n * resolution never awaits: the first read either anchors at once or decides\n * that pages are needed.\n */\nexport async function resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n pageSize,\n maxHistoryLoads = MAX_EDIT_ANCHOR_HISTORY_LOADS,\n}: {\n /** The live thread extras — re-read per page so each anchor attempt sees the widened window. */\n readExtras: () => DeepAgentStatewireExtras | null;\n sourceId: string;\n text: string;\n pageSize?: number;\n maxHistoryLoads?: number;\n}): Promise<StatewireThread.RunEditCommand | null> {\n for (let page = 0; page <= maxHistoryLoads; page += 1) {\n const extras = readExtras();\n if (!extras) return null;\n const command = buildDeepAgentEditCommand({ extras, sourceId, text });\n if (command) return command;\n if (page === maxHistoryLoads || !extras.invoke) return null;\n const window = readWindow(extras);\n if (!isSourceBelowLoadedWindow({ wireMessages: extras.state?.messages, sourceId, window })) {\n return null;\n }\n const requests = window === null ? null : pageInterestRequests(window, pageSize);\n if (requests === null) return null;\n await extras.invoke(DEEP_AGENT_INTEREST_PROTOCOL, 'set', [requests]);\n }\n return null;\n}\n"],"names":[],"mappings":";;;AAoFO,SAAS,6BAA6B,QAAkD;AAC7F,MAAI,CAAC,yBAAyB,MAAM,EAAG,QAAO;AAC9C,SAAO;AACT;AAWO,SAAS,2BAA2B;AAAA,EACzC;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAI8B;;AAC5B,MAAI,CAAC,aAAc,QAAO;AAC1B,QAAM,QAAQ,aAAa,UAAU,CAAC,aAAY,mCAAS,QAAO,QAAQ;AAC1E,MAAI,QAAQ,EAAG,QAAO;AACtB,MAAI,UAAU,EAAG,QAAO,WAAW,SAAY;AAC/C,QAAM,YAAW,kBAAa,QAAQ,CAAC,MAAtB,mBAAyB;AAC1C,SAAO,OAAO,aAAa,WAAW,WAAW;AACnD;AAOO,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAIY;AACV,MAAI,CAAC,gBAAgB,WAAW,QAAQ,CAAC,OAAO,SAAU,QAAO;AACjE,QAAM,QAAQ,aAAa,UAAU,CAAC,aAAY,mCAAS,QAAO,QAAQ;AAC1E,SAAO,SAAS;AAClB;AAEA,MAAM,aAAa,CAAC,WAAA;;AAClB,qCAA2B,YAAO,cAAP,mBAAkB,MAAM;AAAA;AAQrD,SAAS,gBAAwB;AAC/B,QAAM,YAAa,WAA0D;AAC7E,MAAI,QAAO,uCAAW,gBAAe,WAAY,QAAO,UAAU,WAAA;AAClE,QAAM,MAAM,MAAc,KAAK,MAAM,KAAK,OAAA,IAAW,KAAO,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAC1F,SAAO,GAAG,IAAA,CAAK,GAAG,IAAA,CAAK,IAAI,IAAA,CAAK,KAAK,MAAM,MAAM,CAAC,CAAC,IAAI,IAAA,CAAK,IAAI,KAAK,GAAG,IAAA,CAAK,GAAG,IAAA,CAAK;AACvF;AAOO,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAI0C;;AACxC,QAAM,qBAAqB,2BAA2B;AAAA,IACpD,eAAc,YAAO,UAAP,mBAAc;AAAA,IAC5B;AAAA,IACA,YAAU,gBAAW,MAAM,MAAjB,mBAAoB,aAAY;AAAA,EAAA,CAC3C;AACD,MAAI,uBAAuB,OAAW,QAAO;AAC7C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO,OAAO,KAAK,SAAS,cAAA;AAAA,IAC5B,SAAS,EAAE,IAAI,cAAA,GAAiB,MAAM,QAAQ,OAAO,CAAC,EAAE,MAAM,QAAQ,KAAA,CAAM,EAAA;AAAA,IAC5E;AAAA,IACA;AAAA,EAAA;AAEJ;AASO,SAAS,yBAAyB,QAAiC;;AACxE,QAAM,QAAQ,6BAA6B,MAAM;AACjD,MAAI,UAAU,KAAM,QAAO;AAC3B,WAAO,gBAAW,KAAK,MAAhB,mBAAmB,aAAY;AACxC;AAWA,eAAsB,8BAA8B;AAAA,EAClD;AAAA,EACA;AACF,GAGqB;AACnB,QAAM,SAAS,WAAA;AACf,MAAI,EAAC,iCAAQ,QAAQ,QAAO;AAC5B,QAAM,SAAS,WAAW,MAAM;AAChC,MAAI,WAAW,QAAQ,CAAC,OAAO,SAAU,QAAO;AAChD,QAAM,WAAW,qBAAqB,QAAQ,QAAQ;AACtD,MAAI,aAAa,KAAM,QAAO;AAC9B,QAAM,OAAO,OAAO,8BAA8B,OAAO,CAAC,QAAQ,CAAC;AACnE,SAAO;AACT;AAOO,MAAM,gCAAgC;AAgB7C,eAAsB,4BAA4B;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACpB,GAOmD;;AACjD,WAAS,OAAO,GAAG,QAAQ,iBAAiB,QAAQ,GAAG;AACrD,UAAM,SAAS,WAAA;AACf,QAAI,CAAC,OAAQ,QAAO;AACpB,UAAM,UAAU,0BAA0B,EAAE,QAAQ,UAAU,MAAM;AACpE,QAAI,QAAS,QAAO;AACpB,QAAI,SAAS,mBAAmB,CAAC,OAAO,OAAQ,QAAO;AACvD,UAAM,SAAS,WAAW,MAAM;AAChC,QAAI,CAAC,0BAA0B,EAAE,eAAc,YAAO,UAAP,mBAAc,UAAU,UAAU,OAAA,CAAQ,GAAG;AAC1F,aAAO;AAAA,IACT;AACA,UAAM,WAAW,WAAW,OAAO,OAAO,qBAAqB,QAAQ,QAAQ;AAC/E,QAAI,aAAa,KAAM,QAAO;AAC9B,UAAM,OAAO,OAAO,8BAA8B,OAAO,CAAC,QAAQ,CAAC;AAAA,EACrE;AACA,SAAO;AACT;"}
@@ -19,6 +19,23 @@ function subscribeHandoffArrivals(listener) {
19
19
  listeners.delete(listener);
20
20
  };
21
21
  }
22
+ function settleHandoffArrivalCursor(threadId) {
23
+ const { arrivals } = registry();
24
+ const arrival = arrivals.get(threadId);
25
+ if (!arrival || arrival.cursor === null) return;
26
+ arrivals.set(threadId, { ...arrival, cursor: null });
27
+ publish();
28
+ }
29
+ function useHandoffArrivalCursor(threadId) {
30
+ return require$$0.useSyncExternalStore(
31
+ subscribeHandoffArrivals,
32
+ () => {
33
+ var _a;
34
+ return ((_a = readHandoffArrival(threadId)) == null ? void 0 : _a.cursor) ?? null;
35
+ },
36
+ () => null
37
+ );
38
+ }
22
39
  function anchorHandoffArrival({
23
40
  threadId,
24
41
  afterMessageId
@@ -54,7 +71,9 @@ function useHandoffArrivalAfter(messageId) {
54
71
  exports.HandoffArrivalContext = HandoffArrivalContext;
55
72
  exports.anchorHandoffArrival = anchorHandoffArrival;
56
73
  exports.readHandoffArrival = readHandoffArrival;
74
+ exports.settleHandoffArrivalCursor = settleHandoffArrivalCursor;
57
75
  exports.subscribeHandoffArrivals = subscribeHandoffArrivals;
58
76
  exports.useHandoffArrival = useHandoffArrival;
59
77
  exports.useHandoffArrivalAfter = useHandoffArrivalAfter;
78
+ exports.useHandoffArrivalCursor = useHandoffArrivalCursor;
60
79
  //# sourceMappingURL=handoff-arrival.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"handoff-arrival.cjs","sources":["../../../../agent-runtime/src/handoff-arrival.ts"],"sourcesContent":["/**\n * Where a handed-off conversation arrived on this surface: a transcript divider\n * (\"Continued from your phone\") after the last message that was already there\n * when the person picked it up.\n *\n * Ephemeral and client-side. A host records an arrival when its pick-up lands\n * (`recordHandoffArrival`); its transcript anchors it to the thread's last\n * message once that history has loaded (`useHandoffArrival`) and renders the\n * divider after that message (`useHandoffArrivalAfter`). Nothing is sent to\n * Athena or persisted; a reload forgets it.\n */\nimport { createContext, useContext, useEffect, useSyncExternalStore } from 'react';\nimport { continuedFromLabel } from './thread-handoff-protocol';\n\nexport interface HandoffArrival {\n threadId: string;\n /** \"Continued from your phone\". */\n label: string;\n /**\n * The last message present when the conversation arrived; the divider goes\n * right after it. `null` until the transcript has anchored it.\n */\n afterMessageId: string | null;\n}\n\n/** Enough for every conversation one person picks up in a session. */\nexport const MAX_HANDOFF_ARRIVALS = 20;\n\n/**\n * The arrivals live on `globalThis`, not in module scope, because two copies of\n * this module can run in one page: the SDK bundles agent-runtime into its dist\n * while a host (Spaces, the Chrome extension, Midas) imports it directly. The\n * host records through its copy and the SDK transcript reads through its own.\n */\nconst HANDOFF_ARRIVALS = Symbol.for('@athenaintel/agent-runtime/handoff-arrivals');\n\ninterface ArrivalRegistry {\n arrivals: Map<string, HandoffArrival>;\n listeners: Set<() => void>;\n}\n\ntype ArrivalRegistryHost = typeof globalThis & { [HANDOFF_ARRIVALS]?: ArrivalRegistry };\n\n// process-local: this client only — what this surface picked up; nothing is persisted\nfunction registry(): ArrivalRegistry {\n const host = globalThis as ArrivalRegistryHost;\n return (host[HANDOFF_ARRIVALS] ??= { arrivals: new Map(), listeners: new Set() });\n}\n\nfunction publish(): void {\n for (const listener of registry().listeners) listener();\n}\n\n/**\n * A pick-up landed `threadId` here from `source` (`mobile`, `chrome`, …). A\n * second pick-up of the same thread moves the divider to the new arrival.\n */\nexport function recordHandoffArrival({\n threadId,\n source,\n}: {\n threadId: string;\n source: string;\n}): void {\n if (!threadId) return;\n const { arrivals } = registry();\n arrivals.delete(threadId);\n arrivals.set(threadId, { threadId, label: continuedFromLabel(source), afterMessageId: null });\n while (arrivals.size > MAX_HANDOFF_ARRIVALS) {\n const oldest = arrivals.keys().next().value;\n if (oldest === undefined) break;\n arrivals.delete(oldest);\n }\n publish();\n}\n\n/** The arrival recorded for `threadId`, anchored or not. */\nexport function readHandoffArrival(threadId: string | null | undefined): HandoffArrival | null {\n return (threadId && registry().arrivals.get(threadId)) || null;\n}\n\nexport function subscribeHandoffArrivals(listener: () => void): () => void {\n const { listeners } = registry();\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** Forgets the arrival of `threadId`: the pick-up never opened the conversation here. */\nexport function clearHandoffArrival(threadId: string): void {\n if (!registry().arrivals.delete(threadId)) return;\n publish();\n}\n\n/** The first anchor wins: later messages are what came after the arrival. */\nexport function anchorHandoffArrival({\n threadId,\n afterMessageId,\n}: {\n threadId: string;\n afterMessageId: string;\n}): void {\n const { arrivals } = registry();\n const arrival = arrivals.get(threadId);\n if (!arrival || arrival.afterMessageId !== null) return;\n arrivals.set(threadId, { ...arrival, afterMessageId });\n publish();\n}\n\n/**\n * The divider for the transcript of `threadId`, once anchored. The transcript\n * passes its last message id and whether its history is still loading; the\n * first time history has loaded with a message in it, the arrival anchors\n * after that message. A thread already on screen anchors at once.\n */\nexport function useHandoffArrival({\n threadId,\n lastMessageId,\n loading,\n}: {\n threadId: string | null | undefined;\n lastMessageId: string | null | undefined;\n loading: boolean;\n}): HandoffArrival | null {\n const arrival = useSyncExternalStore(\n subscribeHandoffArrivals,\n () => readHandoffArrival(threadId),\n () => null\n );\n const unanchored = arrival !== null && arrival.afterMessageId === null;\n useEffect(() => {\n if (!threadId || !unanchored || loading || !lastMessageId) return;\n anchorHandoffArrival({ threadId, afterMessageId: lastMessageId });\n }, [threadId, unanchored, loading, lastMessageId]);\n return arrival?.afterMessageId ? arrival : null;\n}\n\n/** The anchored arrival of the transcript being rendered, for its messages. */\nexport const HandoffArrivalContext = createContext<HandoffArrival | null>(null);\n\n/** The divider label when it goes right after `messageId`; `null` otherwise. */\nexport function useHandoffArrivalAfter(messageId: string | null | undefined): string | null {\n const arrival = useContext(HandoffArrivalContext);\n return arrival && messageId && arrival.afterMessageId === messageId ? arrival.label : null;\n}\n\nexport function resetHandoffArrivalsForTests(): void {\n registry().arrivals.clear();\n publish();\n}\n"],"names":["useSyncExternalStore","useEffect","createContext","useContext"],"mappings":";;;AAkCA,MAAM,mBAAmB,OAAO,IAAI,6CAA6C;AAUjF,SAAS,WAA4B;AACnC,QAAM,OAAO;AACb,SAAQ,oDAA2B,EAAE,UAAU,oBAAI,OAAO,WAAW,oBAAI,MAAI;AAC/E;AAEA,SAAS,UAAgB;AACvB,aAAW,YAAY,WAAW,UAAW,UAAA;AAC/C;AA0BO,SAAS,mBAAmB,UAA4D;AAC7F,SAAQ,YAAY,SAAA,EAAW,SAAS,IAAI,QAAQ,KAAM;AAC5D;AAEO,SAAS,yBAAyB,UAAkC;AACzE,QAAM,EAAE,UAAA,IAAc,SAAA;AACtB,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM;AACX,cAAU,OAAO,QAAQ;AAAA,EAC3B;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;AACP,QAAM,EAAE,SAAA,IAAa,SAAA;AACrB,QAAM,UAAU,SAAS,IAAI,QAAQ;AACrC,MAAI,CAAC,WAAW,QAAQ,mBAAmB,KAAM;AACjD,WAAS,IAAI,UAAU,EAAE,GAAG,SAAS,gBAAgB;AACrD,UAAA;AACF;AAQO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAI0B;AACxB,QAAM,UAAUA,WAAAA;AAAAA,IACd;AAAA,IACA,MAAM,mBAAmB,QAAQ;AAAA,IACjC,MAAM;AAAA,EAAA;AAER,QAAM,aAAa,YAAY,QAAQ,QAAQ,mBAAmB;AAClEC,aAAAA,UAAU,MAAM;AACd,QAAI,CAAC,YAAY,CAAC,cAAc,WAAW,CAAC,cAAe;AAC3D,yBAAqB,EAAE,UAAU,gBAAgB,cAAA,CAAe;AAAA,EAClE,GAAG,CAAC,UAAU,YAAY,SAAS,aAAa,CAAC;AACjD,UAAO,mCAAS,kBAAiB,UAAU;AAC7C;AAGO,MAAM,wBAAwBC,WAAAA,cAAqC,IAAI;AAGvE,SAAS,uBAAuB,WAAqD;AAC1F,QAAM,UAAUC,WAAAA,WAAW,qBAAqB;AAChD,SAAO,WAAW,aAAa,QAAQ,mBAAmB,YAAY,QAAQ,QAAQ;AACxF;;;;;;;"}
1
+ {"version":3,"file":"handoff-arrival.cjs","sources":["../../../../agent-runtime/src/handoff-arrival.ts"],"sourcesContent":["/**\n * Where a handed-off conversation arrived on this surface: a transcript divider\n * (\"Continued from your phone\") after the last message that was already there\n * when the person picked it up.\n *\n * Ephemeral and client-side. A host records an arrival when its pick-up lands\n * (`recordHandoffArrival`); its transcript anchors it to the thread's last\n * message once that history has loaded (`useHandoffArrival`) and renders the\n * divider after that message (`useHandoffArrivalAfter`). Nothing is sent to\n * Athena or persisted; a reload forgets it.\n *\n * The arrival also carries where the source was reading (`cursor`, a message\n * id): the transcript opens at that message instead of the bottom, then\n * settles it (`settleHandoffArrivalCursor`) so a remount never scrolls again.\n */\nimport { createContext, useContext, useEffect, useSyncExternalStore } from 'react';\nimport { continuedFromLabel, parseHandoffCursor } from './thread-handoff-protocol';\n\nexport interface HandoffArrival {\n threadId: string;\n /** \"Continued from your phone\". */\n label: string;\n /**\n * The last message present when the conversation arrived; the divider goes\n * right after it. `null` until the transcript has anchored it.\n */\n afterMessageId: string | null;\n /**\n * The message the source was reading, which the transcript opens at. `null`\n * when the source was at the bottom, or once the transcript settled it.\n */\n cursor: string | null;\n}\n\n/** Enough for every conversation one person picks up in a session. */\nexport const MAX_HANDOFF_ARRIVALS = 20;\n\n/**\n * The arrivals live on `globalThis`, not in module scope, because two copies of\n * this module can run in one page: the SDK bundles agent-runtime into its dist\n * while a host (Spaces, the Chrome extension, Midas) imports it directly. The\n * host records through its copy and the SDK transcript reads through its own.\n */\nconst HANDOFF_ARRIVALS = Symbol.for('@athenaintel/agent-runtime/handoff-arrivals');\n\ninterface ArrivalRegistry {\n arrivals: Map<string, HandoffArrival>;\n listeners: Set<() => void>;\n}\n\ntype ArrivalRegistryHost = typeof globalThis & { [HANDOFF_ARRIVALS]?: ArrivalRegistry };\n\n// process-local: this client only — what this surface picked up; nothing is persisted\nfunction registry(): ArrivalRegistry {\n const host = globalThis as ArrivalRegistryHost;\n return (host[HANDOFF_ARRIVALS] ??= { arrivals: new Map(), listeners: new Set() });\n}\n\nfunction publish(): void {\n for (const listener of registry().listeners) listener();\n}\n\n/**\n * A pick-up landed `threadId` here from `source` (`mobile`, `chrome`, …),\n * where the source was reading `cursor` (a message id; absent or `null` at the\n * bottom). A second pick-up of the same thread moves the divider to the new\n * arrival and replaces the cursor.\n */\nexport function recordHandoffArrival({\n threadId,\n source,\n cursor,\n}: {\n threadId: string;\n source: string;\n cursor?: string | null;\n}): void {\n if (!threadId) return;\n const { arrivals } = registry();\n arrivals.delete(threadId);\n arrivals.set(threadId, {\n threadId,\n label: continuedFromLabel(source),\n afterMessageId: null,\n cursor: parseHandoffCursor(cursor),\n });\n while (arrivals.size > MAX_HANDOFF_ARRIVALS) {\n const oldest = arrivals.keys().next().value;\n if (oldest === undefined) break;\n arrivals.delete(oldest);\n }\n publish();\n}\n\n/** The arrival recorded for `threadId`, anchored or not. */\nexport function readHandoffArrival(threadId: string | null | undefined): HandoffArrival | null {\n return (threadId && registry().arrivals.get(threadId)) || null;\n}\n\nexport function subscribeHandoffArrivals(listener: () => void): () => void {\n const { listeners } = registry();\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** Forgets the arrival of `threadId`: the pick-up never opened the conversation here. */\nexport function clearHandoffArrival(threadId: string): void {\n if (!registry().arrivals.delete(threadId)) return;\n publish();\n}\n\n/**\n * The transcript of `threadId` opened at its cursor (or gave up and stayed at\n * the bottom): forget the cursor so a remount never scrolls there again.\n */\nexport function settleHandoffArrivalCursor(threadId: string): void {\n const { arrivals } = registry();\n const arrival = arrivals.get(threadId);\n if (!arrival || arrival.cursor === null) return;\n arrivals.set(threadId, { ...arrival, cursor: null });\n publish();\n}\n\n/** Where the transcript of `threadId` should open: the cursor not yet settled, or `null`. */\nexport function useHandoffArrivalCursor(threadId: string | null | undefined): string | null {\n return useSyncExternalStore(\n subscribeHandoffArrivals,\n () => readHandoffArrival(threadId)?.cursor ?? null,\n () => null\n );\n}\n\n/** The first anchor wins: later messages are what came after the arrival. */\nexport function anchorHandoffArrival({\n threadId,\n afterMessageId,\n}: {\n threadId: string;\n afterMessageId: string;\n}): void {\n const { arrivals } = registry();\n const arrival = arrivals.get(threadId);\n if (!arrival || arrival.afterMessageId !== null) return;\n arrivals.set(threadId, { ...arrival, afterMessageId });\n publish();\n}\n\n/**\n * The divider for the transcript of `threadId`, once anchored. The transcript\n * passes its last message id and whether its history is still loading; the\n * first time history has loaded with a message in it, the arrival anchors\n * after that message. A thread already on screen anchors at once.\n */\nexport function useHandoffArrival({\n threadId,\n lastMessageId,\n loading,\n}: {\n threadId: string | null | undefined;\n lastMessageId: string | null | undefined;\n loading: boolean;\n}): HandoffArrival | null {\n const arrival = useSyncExternalStore(\n subscribeHandoffArrivals,\n () => readHandoffArrival(threadId),\n () => null\n );\n const unanchored = arrival !== null && arrival.afterMessageId === null;\n useEffect(() => {\n if (!threadId || !unanchored || loading || !lastMessageId) return;\n anchorHandoffArrival({ threadId, afterMessageId: lastMessageId });\n }, [threadId, unanchored, loading, lastMessageId]);\n return arrival?.afterMessageId ? arrival : null;\n}\n\n/** The anchored arrival of the transcript being rendered, for its messages. */\nexport const HandoffArrivalContext = createContext<HandoffArrival | null>(null);\n\n/** The divider label when it goes right after `messageId`; `null` otherwise. */\nexport function useHandoffArrivalAfter(messageId: string | null | undefined): string | null {\n const arrival = useContext(HandoffArrivalContext);\n return arrival && messageId && arrival.afterMessageId === messageId ? arrival.label : null;\n}\n\nexport function resetHandoffArrivalsForTests(): void {\n registry().arrivals.clear();\n publish();\n}\n"],"names":["useSyncExternalStore","useEffect","createContext","useContext"],"mappings":";;;AA2CA,MAAM,mBAAmB,OAAO,IAAI,6CAA6C;AAUjF,SAAS,WAA4B;AACnC,QAAM,OAAO;AACb,SAAQ,oDAA2B,EAAE,UAAU,oBAAI,OAAO,WAAW,oBAAI,MAAI;AAC/E;AAEA,SAAS,UAAgB;AACvB,aAAW,YAAY,WAAW,UAAW,UAAA;AAC/C;AAmCO,SAAS,mBAAmB,UAA4D;AAC7F,SAAQ,YAAY,SAAA,EAAW,SAAS,IAAI,QAAQ,KAAM;AAC5D;AAEO,SAAS,yBAAyB,UAAkC;AACzE,QAAM,EAAE,UAAA,IAAc,SAAA;AACtB,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM;AACX,cAAU,OAAO,QAAQ;AAAA,EAC3B;AACF;AAYO,SAAS,2BAA2B,UAAwB;AACjE,QAAM,EAAE,SAAA,IAAa,SAAA;AACrB,QAAM,UAAU,SAAS,IAAI,QAAQ;AACrC,MAAI,CAAC,WAAW,QAAQ,WAAW,KAAM;AACzC,WAAS,IAAI,UAAU,EAAE,GAAG,SAAS,QAAQ,MAAM;AACnD,UAAA;AACF;AAGO,SAAS,wBAAwB,UAAoD;AAC1F,SAAOA,WAAAA;AAAAA,IACL;AAAA,IACA,MAAA;;AAAM,uCAAmB,QAAQ,MAA3B,mBAA8B,WAAU;AAAA;AAAA,IAC9C,MAAM;AAAA,EAAA;AAEV;AAGO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;AACP,QAAM,EAAE,SAAA,IAAa,SAAA;AACrB,QAAM,UAAU,SAAS,IAAI,QAAQ;AACrC,MAAI,CAAC,WAAW,QAAQ,mBAAmB,KAAM;AACjD,WAAS,IAAI,UAAU,EAAE,GAAG,SAAS,gBAAgB;AACrD,UAAA;AACF;AAQO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAI0B;AACxB,QAAM,UAAUA,WAAAA;AAAAA,IACd;AAAA,IACA,MAAM,mBAAmB,QAAQ;AAAA,IACjC,MAAM;AAAA,EAAA;AAER,QAAM,aAAa,YAAY,QAAQ,QAAQ,mBAAmB;AAClEC,aAAAA,UAAU,MAAM;AACd,QAAI,CAAC,YAAY,CAAC,cAAc,WAAW,CAAC,cAAe;AAC3D,yBAAqB,EAAE,UAAU,gBAAgB,cAAA,CAAe;AAAA,EAClE,GAAG,CAAC,UAAU,YAAY,SAAS,aAAa,CAAC;AACjD,UAAO,mCAAS,kBAAiB,UAAU;AAC7C;AAGO,MAAM,wBAAwBC,WAAAA,cAAqC,IAAI;AAGvE,SAAS,uBAAuB,WAAqD;AAC1F,QAAM,UAAUC,WAAAA,WAAW,qBAAqB;AAChD,SAAO,WAAW,aAAa,QAAQ,mBAAmB,YAAY,QAAQ,QAAQ;AACxF;;;;;;;;;"}
@@ -7,22 +7,37 @@ export interface HandoffArrival {
7
7
  * right after it. `null` until the transcript has anchored it.
8
8
  */
9
9
  afterMessageId: string | null;
10
+ /**
11
+ * The message the source was reading, which the transcript opens at. `null`
12
+ * when the source was at the bottom, or once the transcript settled it.
13
+ */
14
+ cursor: string | null;
10
15
  }
11
16
  /** Enough for every conversation one person picks up in a session. */
12
17
  export declare const MAX_HANDOFF_ARRIVALS = 20;
13
18
  /**
14
- * A pick-up landed `threadId` here from `source` (`mobile`, `chrome`, …). A
15
- * second pick-up of the same thread moves the divider to the new arrival.
19
+ * A pick-up landed `threadId` here from `source` (`mobile`, `chrome`, …),
20
+ * where the source was reading `cursor` (a message id; absent or `null` at the
21
+ * bottom). A second pick-up of the same thread moves the divider to the new
22
+ * arrival and replaces the cursor.
16
23
  */
17
- export declare function recordHandoffArrival({ threadId, source, }: {
24
+ export declare function recordHandoffArrival({ threadId, source, cursor, }: {
18
25
  threadId: string;
19
26
  source: string;
27
+ cursor?: string | null;
20
28
  }): void;
21
29
  /** The arrival recorded for `threadId`, anchored or not. */
22
30
  export declare function readHandoffArrival(threadId: string | null | undefined): HandoffArrival | null;
23
31
  export declare function subscribeHandoffArrivals(listener: () => void): () => void;
24
32
  /** Forgets the arrival of `threadId`: the pick-up never opened the conversation here. */
25
33
  export declare function clearHandoffArrival(threadId: string): void;
34
+ /**
35
+ * The transcript of `threadId` opened at its cursor (or gave up and stayed at
36
+ * the bottom): forget the cursor so a remount never scrolls there again.
37
+ */
38
+ export declare function settleHandoffArrivalCursor(threadId: string): void;
39
+ /** Where the transcript of `threadId` should open: the cursor not yet settled, or `null`. */
40
+ export declare function useHandoffArrivalCursor(threadId: string | null | undefined): string | null;
26
41
  /** The first anchor wins: later messages are what came after the arrival. */
27
42
  export declare function anchorHandoffArrival({ threadId, afterMessageId, }: {
28
43
  threadId: string;
@@ -17,6 +17,23 @@ function subscribeHandoffArrivals(listener) {
17
17
  listeners.delete(listener);
18
18
  };
19
19
  }
20
+ function settleHandoffArrivalCursor(threadId) {
21
+ const { arrivals } = registry();
22
+ const arrival = arrivals.get(threadId);
23
+ if (!arrival || arrival.cursor === null) return;
24
+ arrivals.set(threadId, { ...arrival, cursor: null });
25
+ publish();
26
+ }
27
+ function useHandoffArrivalCursor(threadId) {
28
+ return useSyncExternalStore(
29
+ subscribeHandoffArrivals,
30
+ () => {
31
+ var _a;
32
+ return ((_a = readHandoffArrival(threadId)) == null ? void 0 : _a.cursor) ?? null;
33
+ },
34
+ () => null
35
+ );
36
+ }
20
37
  function anchorHandoffArrival({
21
38
  threadId,
22
39
  afterMessageId
@@ -53,8 +70,10 @@ export {
53
70
  HandoffArrivalContext,
54
71
  anchorHandoffArrival,
55
72
  readHandoffArrival,
73
+ settleHandoffArrivalCursor,
56
74
  subscribeHandoffArrivals,
57
75
  useHandoffArrival,
58
- useHandoffArrivalAfter
76
+ useHandoffArrivalAfter,
77
+ useHandoffArrivalCursor
59
78
  };
60
79
  //# sourceMappingURL=handoff-arrival.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handoff-arrival.js","sources":["../../../../agent-runtime/src/handoff-arrival.ts"],"sourcesContent":["/**\n * Where a handed-off conversation arrived on this surface: a transcript divider\n * (\"Continued from your phone\") after the last message that was already there\n * when the person picked it up.\n *\n * Ephemeral and client-side. A host records an arrival when its pick-up lands\n * (`recordHandoffArrival`); its transcript anchors it to the thread's last\n * message once that history has loaded (`useHandoffArrival`) and renders the\n * divider after that message (`useHandoffArrivalAfter`). Nothing is sent to\n * Athena or persisted; a reload forgets it.\n */\nimport { createContext, useContext, useEffect, useSyncExternalStore } from 'react';\nimport { continuedFromLabel } from './thread-handoff-protocol';\n\nexport interface HandoffArrival {\n threadId: string;\n /** \"Continued from your phone\". */\n label: string;\n /**\n * The last message present when the conversation arrived; the divider goes\n * right after it. `null` until the transcript has anchored it.\n */\n afterMessageId: string | null;\n}\n\n/** Enough for every conversation one person picks up in a session. */\nexport const MAX_HANDOFF_ARRIVALS = 20;\n\n/**\n * The arrivals live on `globalThis`, not in module scope, because two copies of\n * this module can run in one page: the SDK bundles agent-runtime into its dist\n * while a host (Spaces, the Chrome extension, Midas) imports it directly. The\n * host records through its copy and the SDK transcript reads through its own.\n */\nconst HANDOFF_ARRIVALS = Symbol.for('@athenaintel/agent-runtime/handoff-arrivals');\n\ninterface ArrivalRegistry {\n arrivals: Map<string, HandoffArrival>;\n listeners: Set<() => void>;\n}\n\ntype ArrivalRegistryHost = typeof globalThis & { [HANDOFF_ARRIVALS]?: ArrivalRegistry };\n\n// process-local: this client only — what this surface picked up; nothing is persisted\nfunction registry(): ArrivalRegistry {\n const host = globalThis as ArrivalRegistryHost;\n return (host[HANDOFF_ARRIVALS] ??= { arrivals: new Map(), listeners: new Set() });\n}\n\nfunction publish(): void {\n for (const listener of registry().listeners) listener();\n}\n\n/**\n * A pick-up landed `threadId` here from `source` (`mobile`, `chrome`, …). A\n * second pick-up of the same thread moves the divider to the new arrival.\n */\nexport function recordHandoffArrival({\n threadId,\n source,\n}: {\n threadId: string;\n source: string;\n}): void {\n if (!threadId) return;\n const { arrivals } = registry();\n arrivals.delete(threadId);\n arrivals.set(threadId, { threadId, label: continuedFromLabel(source), afterMessageId: null });\n while (arrivals.size > MAX_HANDOFF_ARRIVALS) {\n const oldest = arrivals.keys().next().value;\n if (oldest === undefined) break;\n arrivals.delete(oldest);\n }\n publish();\n}\n\n/** The arrival recorded for `threadId`, anchored or not. */\nexport function readHandoffArrival(threadId: string | null | undefined): HandoffArrival | null {\n return (threadId && registry().arrivals.get(threadId)) || null;\n}\n\nexport function subscribeHandoffArrivals(listener: () => void): () => void {\n const { listeners } = registry();\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** Forgets the arrival of `threadId`: the pick-up never opened the conversation here. */\nexport function clearHandoffArrival(threadId: string): void {\n if (!registry().arrivals.delete(threadId)) return;\n publish();\n}\n\n/** The first anchor wins: later messages are what came after the arrival. */\nexport function anchorHandoffArrival({\n threadId,\n afterMessageId,\n}: {\n threadId: string;\n afterMessageId: string;\n}): void {\n const { arrivals } = registry();\n const arrival = arrivals.get(threadId);\n if (!arrival || arrival.afterMessageId !== null) return;\n arrivals.set(threadId, { ...arrival, afterMessageId });\n publish();\n}\n\n/**\n * The divider for the transcript of `threadId`, once anchored. The transcript\n * passes its last message id and whether its history is still loading; the\n * first time history has loaded with a message in it, the arrival anchors\n * after that message. A thread already on screen anchors at once.\n */\nexport function useHandoffArrival({\n threadId,\n lastMessageId,\n loading,\n}: {\n threadId: string | null | undefined;\n lastMessageId: string | null | undefined;\n loading: boolean;\n}): HandoffArrival | null {\n const arrival = useSyncExternalStore(\n subscribeHandoffArrivals,\n () => readHandoffArrival(threadId),\n () => null\n );\n const unanchored = arrival !== null && arrival.afterMessageId === null;\n useEffect(() => {\n if (!threadId || !unanchored || loading || !lastMessageId) return;\n anchorHandoffArrival({ threadId, afterMessageId: lastMessageId });\n }, [threadId, unanchored, loading, lastMessageId]);\n return arrival?.afterMessageId ? arrival : null;\n}\n\n/** The anchored arrival of the transcript being rendered, for its messages. */\nexport const HandoffArrivalContext = createContext<HandoffArrival | null>(null);\n\n/** The divider label when it goes right after `messageId`; `null` otherwise. */\nexport function useHandoffArrivalAfter(messageId: string | null | undefined): string | null {\n const arrival = useContext(HandoffArrivalContext);\n return arrival && messageId && arrival.afterMessageId === messageId ? arrival.label : null;\n}\n\nexport function resetHandoffArrivalsForTests(): void {\n registry().arrivals.clear();\n publish();\n}\n"],"names":[],"mappings":";AAkCA,MAAM,mBAAmB,OAAO,IAAI,6CAA6C;AAUjF,SAAS,WAA4B;AACnC,QAAM,OAAO;AACb,SAAQ,oDAA2B,EAAE,UAAU,oBAAI,OAAO,WAAW,oBAAI,MAAI;AAC/E;AAEA,SAAS,UAAgB;AACvB,aAAW,YAAY,WAAW,UAAW,UAAA;AAC/C;AA0BO,SAAS,mBAAmB,UAA4D;AAC7F,SAAQ,YAAY,SAAA,EAAW,SAAS,IAAI,QAAQ,KAAM;AAC5D;AAEO,SAAS,yBAAyB,UAAkC;AACzE,QAAM,EAAE,UAAA,IAAc,SAAA;AACtB,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM;AACX,cAAU,OAAO,QAAQ;AAAA,EAC3B;AACF;AASO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;AACP,QAAM,EAAE,SAAA,IAAa,SAAA;AACrB,QAAM,UAAU,SAAS,IAAI,QAAQ;AACrC,MAAI,CAAC,WAAW,QAAQ,mBAAmB,KAAM;AACjD,WAAS,IAAI,UAAU,EAAE,GAAG,SAAS,gBAAgB;AACrD,UAAA;AACF;AAQO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAI0B;AACxB,QAAM,UAAU;AAAA,IACd;AAAA,IACA,MAAM,mBAAmB,QAAQ;AAAA,IACjC,MAAM;AAAA,EAAA;AAER,QAAM,aAAa,YAAY,QAAQ,QAAQ,mBAAmB;AAClE,YAAU,MAAM;AACd,QAAI,CAAC,YAAY,CAAC,cAAc,WAAW,CAAC,cAAe;AAC3D,yBAAqB,EAAE,UAAU,gBAAgB,cAAA,CAAe;AAAA,EAClE,GAAG,CAAC,UAAU,YAAY,SAAS,aAAa,CAAC;AACjD,UAAO,mCAAS,kBAAiB,UAAU;AAC7C;AAGO,MAAM,wBAAwB,cAAqC,IAAI;AAGvE,SAAS,uBAAuB,WAAqD;AAC1F,QAAM,UAAU,WAAW,qBAAqB;AAChD,SAAO,WAAW,aAAa,QAAQ,mBAAmB,YAAY,QAAQ,QAAQ;AACxF;"}
1
+ {"version":3,"file":"handoff-arrival.js","sources":["../../../../agent-runtime/src/handoff-arrival.ts"],"sourcesContent":["/**\n * Where a handed-off conversation arrived on this surface: a transcript divider\n * (\"Continued from your phone\") after the last message that was already there\n * when the person picked it up.\n *\n * Ephemeral and client-side. A host records an arrival when its pick-up lands\n * (`recordHandoffArrival`); its transcript anchors it to the thread's last\n * message once that history has loaded (`useHandoffArrival`) and renders the\n * divider after that message (`useHandoffArrivalAfter`). Nothing is sent to\n * Athena or persisted; a reload forgets it.\n *\n * The arrival also carries where the source was reading (`cursor`, a message\n * id): the transcript opens at that message instead of the bottom, then\n * settles it (`settleHandoffArrivalCursor`) so a remount never scrolls again.\n */\nimport { createContext, useContext, useEffect, useSyncExternalStore } from 'react';\nimport { continuedFromLabel, parseHandoffCursor } from './thread-handoff-protocol';\n\nexport interface HandoffArrival {\n threadId: string;\n /** \"Continued from your phone\". */\n label: string;\n /**\n * The last message present when the conversation arrived; the divider goes\n * right after it. `null` until the transcript has anchored it.\n */\n afterMessageId: string | null;\n /**\n * The message the source was reading, which the transcript opens at. `null`\n * when the source was at the bottom, or once the transcript settled it.\n */\n cursor: string | null;\n}\n\n/** Enough for every conversation one person picks up in a session. */\nexport const MAX_HANDOFF_ARRIVALS = 20;\n\n/**\n * The arrivals live on `globalThis`, not in module scope, because two copies of\n * this module can run in one page: the SDK bundles agent-runtime into its dist\n * while a host (Spaces, the Chrome extension, Midas) imports it directly. The\n * host records through its copy and the SDK transcript reads through its own.\n */\nconst HANDOFF_ARRIVALS = Symbol.for('@athenaintel/agent-runtime/handoff-arrivals');\n\ninterface ArrivalRegistry {\n arrivals: Map<string, HandoffArrival>;\n listeners: Set<() => void>;\n}\n\ntype ArrivalRegistryHost = typeof globalThis & { [HANDOFF_ARRIVALS]?: ArrivalRegistry };\n\n// process-local: this client only — what this surface picked up; nothing is persisted\nfunction registry(): ArrivalRegistry {\n const host = globalThis as ArrivalRegistryHost;\n return (host[HANDOFF_ARRIVALS] ??= { arrivals: new Map(), listeners: new Set() });\n}\n\nfunction publish(): void {\n for (const listener of registry().listeners) listener();\n}\n\n/**\n * A pick-up landed `threadId` here from `source` (`mobile`, `chrome`, …),\n * where the source was reading `cursor` (a message id; absent or `null` at the\n * bottom). A second pick-up of the same thread moves the divider to the new\n * arrival and replaces the cursor.\n */\nexport function recordHandoffArrival({\n threadId,\n source,\n cursor,\n}: {\n threadId: string;\n source: string;\n cursor?: string | null;\n}): void {\n if (!threadId) return;\n const { arrivals } = registry();\n arrivals.delete(threadId);\n arrivals.set(threadId, {\n threadId,\n label: continuedFromLabel(source),\n afterMessageId: null,\n cursor: parseHandoffCursor(cursor),\n });\n while (arrivals.size > MAX_HANDOFF_ARRIVALS) {\n const oldest = arrivals.keys().next().value;\n if (oldest === undefined) break;\n arrivals.delete(oldest);\n }\n publish();\n}\n\n/** The arrival recorded for `threadId`, anchored or not. */\nexport function readHandoffArrival(threadId: string | null | undefined): HandoffArrival | null {\n return (threadId && registry().arrivals.get(threadId)) || null;\n}\n\nexport function subscribeHandoffArrivals(listener: () => void): () => void {\n const { listeners } = registry();\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/** Forgets the arrival of `threadId`: the pick-up never opened the conversation here. */\nexport function clearHandoffArrival(threadId: string): void {\n if (!registry().arrivals.delete(threadId)) return;\n publish();\n}\n\n/**\n * The transcript of `threadId` opened at its cursor (or gave up and stayed at\n * the bottom): forget the cursor so a remount never scrolls there again.\n */\nexport function settleHandoffArrivalCursor(threadId: string): void {\n const { arrivals } = registry();\n const arrival = arrivals.get(threadId);\n if (!arrival || arrival.cursor === null) return;\n arrivals.set(threadId, { ...arrival, cursor: null });\n publish();\n}\n\n/** Where the transcript of `threadId` should open: the cursor not yet settled, or `null`. */\nexport function useHandoffArrivalCursor(threadId: string | null | undefined): string | null {\n return useSyncExternalStore(\n subscribeHandoffArrivals,\n () => readHandoffArrival(threadId)?.cursor ?? null,\n () => null\n );\n}\n\n/** The first anchor wins: later messages are what came after the arrival. */\nexport function anchorHandoffArrival({\n threadId,\n afterMessageId,\n}: {\n threadId: string;\n afterMessageId: string;\n}): void {\n const { arrivals } = registry();\n const arrival = arrivals.get(threadId);\n if (!arrival || arrival.afterMessageId !== null) return;\n arrivals.set(threadId, { ...arrival, afterMessageId });\n publish();\n}\n\n/**\n * The divider for the transcript of `threadId`, once anchored. The transcript\n * passes its last message id and whether its history is still loading; the\n * first time history has loaded with a message in it, the arrival anchors\n * after that message. A thread already on screen anchors at once.\n */\nexport function useHandoffArrival({\n threadId,\n lastMessageId,\n loading,\n}: {\n threadId: string | null | undefined;\n lastMessageId: string | null | undefined;\n loading: boolean;\n}): HandoffArrival | null {\n const arrival = useSyncExternalStore(\n subscribeHandoffArrivals,\n () => readHandoffArrival(threadId),\n () => null\n );\n const unanchored = arrival !== null && arrival.afterMessageId === null;\n useEffect(() => {\n if (!threadId || !unanchored || loading || !lastMessageId) return;\n anchorHandoffArrival({ threadId, afterMessageId: lastMessageId });\n }, [threadId, unanchored, loading, lastMessageId]);\n return arrival?.afterMessageId ? arrival : null;\n}\n\n/** The anchored arrival of the transcript being rendered, for its messages. */\nexport const HandoffArrivalContext = createContext<HandoffArrival | null>(null);\n\n/** The divider label when it goes right after `messageId`; `null` otherwise. */\nexport function useHandoffArrivalAfter(messageId: string | null | undefined): string | null {\n const arrival = useContext(HandoffArrivalContext);\n return arrival && messageId && arrival.afterMessageId === messageId ? arrival.label : null;\n}\n\nexport function resetHandoffArrivalsForTests(): void {\n registry().arrivals.clear();\n publish();\n}\n"],"names":[],"mappings":";AA2CA,MAAM,mBAAmB,OAAO,IAAI,6CAA6C;AAUjF,SAAS,WAA4B;AACnC,QAAM,OAAO;AACb,SAAQ,oDAA2B,EAAE,UAAU,oBAAI,OAAO,WAAW,oBAAI,MAAI;AAC/E;AAEA,SAAS,UAAgB;AACvB,aAAW,YAAY,WAAW,UAAW,UAAA;AAC/C;AAmCO,SAAS,mBAAmB,UAA4D;AAC7F,SAAQ,YAAY,SAAA,EAAW,SAAS,IAAI,QAAQ,KAAM;AAC5D;AAEO,SAAS,yBAAyB,UAAkC;AACzE,QAAM,EAAE,UAAA,IAAc,SAAA;AACtB,YAAU,IAAI,QAAQ;AACtB,SAAO,MAAM;AACX,cAAU,OAAO,QAAQ;AAAA,EAC3B;AACF;AAYO,SAAS,2BAA2B,UAAwB;AACjE,QAAM,EAAE,SAAA,IAAa,SAAA;AACrB,QAAM,UAAU,SAAS,IAAI,QAAQ;AACrC,MAAI,CAAC,WAAW,QAAQ,WAAW,KAAM;AACzC,WAAS,IAAI,UAAU,EAAE,GAAG,SAAS,QAAQ,MAAM;AACnD,UAAA;AACF;AAGO,SAAS,wBAAwB,UAAoD;AAC1F,SAAO;AAAA,IACL;AAAA,IACA,MAAA;;AAAM,uCAAmB,QAAQ,MAA3B,mBAA8B,WAAU;AAAA;AAAA,IAC9C,MAAM;AAAA,EAAA;AAEV;AAGO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA;AACF,GAGS;AACP,QAAM,EAAE,SAAA,IAAa,SAAA;AACrB,QAAM,UAAU,SAAS,IAAI,QAAQ;AACrC,MAAI,CAAC,WAAW,QAAQ,mBAAmB,KAAM;AACjD,WAAS,IAAI,UAAU,EAAE,GAAG,SAAS,gBAAgB;AACrD,UAAA;AACF;AAQO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAI0B;AACxB,QAAM,UAAU;AAAA,IACd;AAAA,IACA,MAAM,mBAAmB,QAAQ;AAAA,IACjC,MAAM;AAAA,EAAA;AAER,QAAM,aAAa,YAAY,QAAQ,QAAQ,mBAAmB;AAClE,YAAU,MAAM;AACd,QAAI,CAAC,YAAY,CAAC,cAAc,WAAW,CAAC,cAAe;AAC3D,yBAAqB,EAAE,UAAU,gBAAgB,cAAA,CAAe;AAAA,EAClE,GAAG,CAAC,UAAU,YAAY,SAAS,aAAa,CAAC;AACjD,UAAO,mCAAS,kBAAiB,UAAU;AAC7C;AAGO,MAAM,wBAAwB,cAAqC,IAAI;AAGvE,SAAS,uBAAuB,WAAqD;AAC1F,QAAM,UAAU,WAAW,qBAAqB;AAChD,SAAO,WAAW,aAAa,QAAQ,mBAAmB,YAAY,QAAQ,QAAQ;AACxF;"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const HANDOFF_CURSOR_PATTERN = /^[A-Za-z0-9._:-]{1,256}$/;
4
+ const parseHandoffCursor = (value) => value && HANDOFF_CURSOR_PATTERN.test(value) ? value : null;
5
+ exports.parseHandoffCursor = parseHandoffCursor;
6
+ //# sourceMappingURL=handoff-cursor-id.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff-cursor-id.cjs","sources":["../../../../agent-runtime/src/handoff-cursor-id.ts"],"sourcesContent":["/**\n * A handover's reading position: the id of the last message the source's\n * transcript showed (see `handoff-cursor`). An opaque id from the person's own\n * thread, never content; agora accepts this shape only.\n *\n * Kept free of zod (unlike `thread-handoff-protocol`, which re-exports it): the\n * React SDK bundles `handoff-cursor`, and a bundled zod would land under the\n * SDK's `dist/node_modules`, which npm never packs.\n */\nexport const MAX_HANDOFF_CURSOR_LENGTH = 256;\nconst HANDOFF_CURSOR_PATTERN = /^[A-Za-z0-9._:-]{1,256}$/;\n\n/** A message id a handover can carry as its reading position, or `null`. */\nexport const parseHandoffCursor = (value: string | null | undefined): string | null =>\n value && HANDOFF_CURSOR_PATTERN.test(value) ? value : null;\n"],"names":[],"mappings":";;AAUA,MAAM,yBAAyB;AAGxB,MAAM,qBAAqB,CAAC,UACjC,SAAS,uBAAuB,KAAK,KAAK,IAAI,QAAQ;;"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A handover's reading position: the id of the last message the source's
3
+ * transcript showed (see `handoff-cursor`). An opaque id from the person's own
4
+ * thread, never content; agora accepts this shape only.
5
+ *
6
+ * Kept free of zod (unlike `thread-handoff-protocol`, which re-exports it): the
7
+ * React SDK bundles `handoff-cursor`, and a bundled zod would land under the
8
+ * SDK's `dist/node_modules`, which npm never packs.
9
+ */
10
+ export declare const MAX_HANDOFF_CURSOR_LENGTH = 256;
11
+ /** A message id a handover can carry as its reading position, or `null`. */
12
+ export declare const parseHandoffCursor: (value: string | null | undefined) => string | null;
@@ -0,0 +1,6 @@
1
+ const HANDOFF_CURSOR_PATTERN = /^[A-Za-z0-9._:-]{1,256}$/;
2
+ const parseHandoffCursor = (value) => value && HANDOFF_CURSOR_PATTERN.test(value) ? value : null;
3
+ export {
4
+ parseHandoffCursor
5
+ };
6
+ //# sourceMappingURL=handoff-cursor-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff-cursor-id.js","sources":["../../../../agent-runtime/src/handoff-cursor-id.ts"],"sourcesContent":["/**\n * A handover's reading position: the id of the last message the source's\n * transcript showed (see `handoff-cursor`). An opaque id from the person's own\n * thread, never content; agora accepts this shape only.\n *\n * Kept free of zod (unlike `thread-handoff-protocol`, which re-exports it): the\n * React SDK bundles `handoff-cursor`, and a bundled zod would land under the\n * SDK's `dist/node_modules`, which npm never packs.\n */\nexport const MAX_HANDOFF_CURSOR_LENGTH = 256;\nconst HANDOFF_CURSOR_PATTERN = /^[A-Za-z0-9._:-]{1,256}$/;\n\n/** A message id a handover can carry as its reading position, or `null`. */\nexport const parseHandoffCursor = (value: string | null | undefined): string | null =>\n value && HANDOFF_CURSOR_PATTERN.test(value) ? value : null;\n"],"names":[],"mappings":"AAUA,MAAM,yBAAyB;AAGxB,MAAM,qBAAqB,CAAC,UACjC,SAAS,uBAAuB,KAAK,KAAK,IAAI,QAAQ;"}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const core = require("@assistant-ui/core");
4
+ const handoffCursorId = require("./handoff-cursor-id.cjs");
5
+ const READING_CURSOR_BOTTOM_TOLERANCE_PX = 48;
6
+ const READING_LINE_FRACTION = 1 / 3;
7
+ function readingCursorFromRows({
8
+ top,
9
+ bottom,
10
+ rows
11
+ }) {
12
+ var _a;
13
+ const line = top + (bottom - top) * READING_LINE_FRACTION;
14
+ let lastFull = null;
15
+ let atLine = null;
16
+ for (const row of rows) {
17
+ if (row.bottom <= row.top) continue;
18
+ if (row.top >= top - 1 && row.bottom <= bottom + 1) lastFull = row;
19
+ if (row.top <= line && row.bottom > line) atLine = row;
20
+ }
21
+ return handoffCursorId.parseHandoffCursor((_a = lastFull ?? atLine) == null ? void 0 : _a.id);
22
+ }
23
+ const MESSAGE_ROW_ID_ATTRIBUTE = "data-message-id";
24
+ function readingCursorOf({
25
+ viewport,
26
+ coveredBottomPx = 0,
27
+ idAttribute = MESSAGE_ROW_ID_ATTRIBUTE
28
+ }) {
29
+ const fromBottom = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;
30
+ if (fromBottom <= READING_CURSOR_BOTTOM_TOLERANCE_PX) return null;
31
+ const box = viewport.getBoundingClientRect();
32
+ const rows = Array.from(viewport.querySelectorAll(`[${idAttribute}]`), (row) => {
33
+ const rect = row.getBoundingClientRect();
34
+ return { id: row.getAttribute(idAttribute) ?? "", top: rect.top, bottom: rect.bottom };
35
+ });
36
+ return readingCursorFromRows({
37
+ top: box.top,
38
+ bottom: Math.max(box.top, box.bottom - coveredBottomPx),
39
+ rows
40
+ });
41
+ }
42
+ function handoffCursorMessageId({
43
+ messages,
44
+ cursor
45
+ }) {
46
+ for (const message of messages) {
47
+ if (message.id === cursor) return message.id;
48
+ }
49
+ for (const message of messages) {
50
+ const sources = core.getExternalStoreMessages(message);
51
+ if (!Array.isArray(sources)) continue;
52
+ for (const source of sources) {
53
+ if (source && typeof source === "object" && source.id === cursor) {
54
+ return message.id;
55
+ }
56
+ }
57
+ }
58
+ return null;
59
+ }
60
+ const HANDOFF_CURSOR_MAX_HISTORY_PAGES = 20;
61
+ const HANDOFF_CURSOR_WAIT_MS = 3e4;
62
+ const HANDOFF_CURSOR_HIGHLIGHT_MS = 2400;
63
+ const HANDOFF_CURSOR_SETTLE_MS = 1500;
64
+ function handoffCursorRevealStep({
65
+ found,
66
+ loading,
67
+ hasOlder,
68
+ pagesLoaded,
69
+ elapsedMs
70
+ }) {
71
+ if (found) return "reveal";
72
+ if (elapsedMs >= HANDOFF_CURSOR_WAIT_MS) return "bottom";
73
+ if (loading || hasOlder === null) return "wait";
74
+ if (hasOlder && pagesLoaded < HANDOFF_CURSOR_MAX_HISTORY_PAGES) return "page";
75
+ return "bottom";
76
+ }
77
+ exports.HANDOFF_CURSOR_HIGHLIGHT_MS = HANDOFF_CURSOR_HIGHLIGHT_MS;
78
+ exports.HANDOFF_CURSOR_MAX_HISTORY_PAGES = HANDOFF_CURSOR_MAX_HISTORY_PAGES;
79
+ exports.HANDOFF_CURSOR_SETTLE_MS = HANDOFF_CURSOR_SETTLE_MS;
80
+ exports.HANDOFF_CURSOR_WAIT_MS = HANDOFF_CURSOR_WAIT_MS;
81
+ exports.MESSAGE_ROW_ID_ATTRIBUTE = MESSAGE_ROW_ID_ATTRIBUTE;
82
+ exports.READING_CURSOR_BOTTOM_TOLERANCE_PX = READING_CURSOR_BOTTOM_TOLERANCE_PX;
83
+ exports.READING_LINE_FRACTION = READING_LINE_FRACTION;
84
+ exports.handoffCursorMessageId = handoffCursorMessageId;
85
+ exports.handoffCursorRevealStep = handoffCursorRevealStep;
86
+ exports.readingCursorFromRows = readingCursorFromRows;
87
+ exports.readingCursorOf = readingCursorOf;
88
+ //# sourceMappingURL=handoff-cursor.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff-cursor.cjs","sources":["../../../../agent-runtime/src/handoff-cursor.ts"],"sourcesContent":["/**\n * Where a handed-off conversation opens: at the message the source was\n * reading (\"the view at the last message the source showed\"), not just at the\n * bottom.\n *\n * The source reads its own transcript when the person issues the handover\n * (`readingCursorOf` on the web, the visible rows on the phone): `null` when\n * it was at the bottom, else the id of the last message fully in view or,\n * when one long message fills the view, the message at the reading line. The\n * id travels as the handover's `cursor` (an opaque id from the person's own\n * thread, never content). The destination records it with the arrival\n * (`recordHandoffArrival({ cursor })`) and its transcript reveals that message\n * once it has it, paging older history in when needed\n * (`handoffCursorRevealStep`), and highlights it briefly. A cursor it can't\n * find leaves the view at the bottom, as before: it is a hint, never a wait.\n */\nimport { getExternalStoreMessages, type ThreadMessage } from '@assistant-ui/core';\nimport { parseHandoffCursor } from './handoff-cursor-id';\n\n/** Whether older history is left to page in (`null` until the window is known). */\nexport { deepAgentHistoryHasOlder } from './edit-command';\n\n/** How far from the bottom still counts as \"at the bottom\": no cursor is sent. */\nexport const READING_CURSOR_BOTTOM_TOLERANCE_PX = 48;\n/** The reading line, as a fraction of the visible height from its top. */\nexport const READING_LINE_FRACTION = 1 / 3;\n\n/** One rendered message row, in the viewport's coordinates. */\nexport interface ReadingRow {\n id: string;\n top: number;\n bottom: number;\n}\n\n/**\n * The reading position among `rows` (in document order) visible between `top`\n * and `bottom`: the last row fully inside, else the row across the reading\n * line (a message taller than the view). `null` when neither is a message id.\n */\nexport function readingCursorFromRows({\n top,\n bottom,\n rows,\n}: {\n top: number;\n bottom: number;\n rows: readonly ReadingRow[];\n}): string | null {\n const line = top + (bottom - top) * READING_LINE_FRACTION;\n let lastFull: ReadingRow | null = null;\n let atLine: ReadingRow | null = null;\n for (const row of rows) {\n if (row.bottom <= row.top) continue;\n if (row.top >= top - 1 && row.bottom <= bottom + 1) lastFull = row;\n if (row.top <= line && row.bottom > line) atLine = row;\n }\n return parseHandoffCursor((lastFull ?? atLine)?.id);\n}\n\n/**\n * The reading position of a list that reports which rows are visible, in\n * order and partly visible ones included, but not where they sit (a native\n * list's viewability). Only the first and last visible rows can be cut off,\n * so with three or more the last fully visible one is the one before the\n * last; with fewer, the first (the one across the reading line, as far as the\n * list can tell). Callers check \"at the bottom\" themselves.\n */\nexport function readingCursorFromVisibleIds(ids: readonly string[]): string | null {\n return parseHandoffCursor(ids.length >= 3 ? ids[ids.length - 2] : ids[0]);\n}\n\ninterface BoxLike {\n getBoundingClientRect(): { top: number; bottom: number };\n}\n\ninterface RowLike extends BoxLike {\n getAttribute(name: string): string | null;\n}\n\n/** The scroll container of a web transcript (structural, so Core needs no DOM types). */\nexport interface ReadingViewportLike extends BoxLike {\n scrollTop: number;\n scrollHeight: number;\n clientHeight: number;\n querySelectorAll(selectors: string): ArrayLike<RowLike>;\n}\n\n/** assistant-ui stamps every message row with its id. */\nexport const MESSAGE_ROW_ID_ATTRIBUTE = 'data-message-id';\n\n/**\n * Where a web transcript is being read: `null` at the bottom, else the message\n * id `readingCursorFromRows` picks. `coveredBottomPx` is what a sticky footer\n * (the composer) hides at the bottom of the viewport.\n */\nexport function readingCursorOf({\n viewport,\n coveredBottomPx = 0,\n idAttribute = MESSAGE_ROW_ID_ATTRIBUTE,\n}: {\n viewport: ReadingViewportLike;\n coveredBottomPx?: number;\n idAttribute?: string;\n}): string | null {\n const fromBottom = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;\n if (fromBottom <= READING_CURSOR_BOTTOM_TOLERANCE_PX) return null;\n const box = viewport.getBoundingClientRect();\n const rows: ReadingRow[] = Array.from(viewport.querySelectorAll(`[${idAttribute}]`), (row) => {\n const rect = row.getBoundingClientRect();\n return { id: row.getAttribute(idAttribute) ?? '', top: rect.top, bottom: rect.bottom };\n });\n return readingCursorFromRows({\n top: box.top,\n bottom: Math.max(box.top, box.bottom - coveredBottomPx),\n rows,\n });\n}\n\n/**\n * The id of the displayed message that holds `cursor`. A displayed message is\n * one agent turn whose id is its first wire message's, and that id changes\n * when an older page folds into it, so the cursor is matched against every\n * wire message behind each row as well.\n */\nexport function handoffCursorMessageId({\n messages,\n cursor,\n}: {\n messages: readonly ThreadMessage[];\n cursor: string;\n}): string | null {\n for (const message of messages) {\n if (message.id === cursor) return message.id;\n }\n for (const message of messages) {\n const sources: unknown = getExternalStoreMessages(message);\n if (!Array.isArray(sources)) continue;\n for (const source of sources) {\n if (source && typeof source === 'object' && (source as { id?: unknown }).id === cursor) {\n return message.id;\n }\n }\n }\n return null;\n}\n\n/** Pages of older history one landing may load looking for its message. */\nexport const HANDOFF_CURSOR_MAX_HISTORY_PAGES = 20;\n/**\n * How long a landing waits without progress before staying at the bottom: a\n * transcript still attaching, or a page of older history that never lands.\n * Each page that lands starts the wait again, so a long conversation on a slow\n * connection still reaches its message within the page budget.\n */\nexport const HANDOFF_CURSOR_WAIT_MS = 30_000;\n/** How long the revealed message stays highlighted. */\nexport const HANDOFF_CURSOR_HIGHLIGHT_MS = 2_400;\n/**\n * How long the revealed message is held in view while the transcript settles\n * (an attaching thread can still scroll itself to the bottom). Any scroll the\n * person makes ends it at once.\n */\nexport const HANDOFF_CURSOR_SETTLE_MS = 1_500;\n\nexport type HandoffCursorRevealStep = 'reveal' | 'wait' | 'page' | 'bottom';\n\n/**\n * What a destination does next while opening at a cursor: `reveal` the message\n * it found; `wait` while the transcript (or a page it asked for) is loading or\n * whether older history exists is not known yet (`hasOlder: null`: a cached\n * transcript shows before its history window resolves); `page` older history\n * in while some is left and the budget allows; else stay at the `bottom`, the\n * fallback for a cursor that can't be found.\n */\nexport function handoffCursorRevealStep({\n found,\n loading,\n hasOlder,\n pagesLoaded,\n elapsedMs,\n}: {\n found: boolean;\n loading: boolean;\n hasOlder: boolean | null;\n pagesLoaded: number;\n /** Since the landing last made progress: it started, or a page of older history landed. */\n elapsedMs: number;\n}): HandoffCursorRevealStep {\n if (found) return 'reveal';\n if (elapsedMs >= HANDOFF_CURSOR_WAIT_MS) return 'bottom';\n if (loading || hasOlder === null) return 'wait';\n if (hasOlder && pagesLoaded < HANDOFF_CURSOR_MAX_HISTORY_PAGES) return 'page';\n return 'bottom';\n}\n"],"names":["parseHandoffCursor","getExternalStoreMessages"],"mappings":";;;;AAuBO,MAAM,qCAAqC;AAE3C,MAAM,wBAAwB,IAAI;AAclC,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACF,GAIkB;;AAChB,QAAM,OAAO,OAAO,SAAS,OAAO;AACpC,MAAI,WAA8B;AAClC,MAAI,SAA4B;AAChC,aAAW,OAAO,MAAM;AACtB,QAAI,IAAI,UAAU,IAAI,IAAK;AAC3B,QAAI,IAAI,OAAO,MAAM,KAAK,IAAI,UAAU,SAAS,EAAG,YAAW;AAC/D,QAAI,IAAI,OAAO,QAAQ,IAAI,SAAS,KAAM,UAAS;AAAA,EACrD;AACA,SAAOA,oCAAoB,iBAAY,WAAZ,mBAAqB,EAAE;AACpD;AA+BO,MAAM,2BAA2B;AAOjC,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA,kBAAkB;AAAA,EAClB,cAAc;AAChB,GAIkB;AAChB,QAAM,aAAa,SAAS,eAAe,SAAS,YAAY,SAAS;AACzE,MAAI,cAAc,mCAAoC,QAAO;AAC7D,QAAM,MAAM,SAAS,sBAAA;AACrB,QAAM,OAAqB,MAAM,KAAK,SAAS,iBAAiB,IAAI,WAAW,GAAG,GAAG,CAAC,QAAQ;AAC5F,UAAM,OAAO,IAAI,sBAAA;AACjB,WAAO,EAAE,IAAI,IAAI,aAAa,WAAW,KAAK,IAAI,KAAK,KAAK,KAAK,QAAQ,KAAK,OAAA;AAAA,EAChF,CAAC;AACD,SAAO,sBAAsB;AAAA,IAC3B,KAAK,IAAI;AAAA,IACT,QAAQ,KAAK,IAAI,IAAI,KAAK,IAAI,SAAS,eAAe;AAAA,IACtD;AAAA,EAAA,CACD;AACH;AAQO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AACF,GAGkB;AAChB,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,OAAO,OAAQ,QAAO,QAAQ;AAAA,EAC5C;AACA,aAAW,WAAW,UAAU;AAC9B,UAAM,UAAmBC,KAAAA,yBAAyB,OAAO;AACzD,QAAI,CAAC,MAAM,QAAQ,OAAO,EAAG;AAC7B,eAAW,UAAU,SAAS;AAC5B,UAAI,UAAU,OAAO,WAAW,YAAa,OAA4B,OAAO,QAAQ;AACtF,eAAO,QAAQ;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAGO,MAAM,mCAAmC;AAOzC,MAAM,yBAAyB;AAE/B,MAAM,8BAA8B;AAMpC,MAAM,2BAA2B;AAYjC,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAO4B;AAC1B,MAAI,MAAO,QAAO;AAClB,MAAI,aAAa,uBAAwB,QAAO;AAChD,MAAI,WAAW,aAAa,KAAM,QAAO;AACzC,MAAI,YAAY,cAAc,iCAAkC,QAAO;AACvE,SAAO;AACT;;;;;;;;;;;;"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Where a handed-off conversation opens: at the message the source was
3
+ * reading ("the view at the last message the source showed"), not just at the
4
+ * bottom.
5
+ *
6
+ * The source reads its own transcript when the person issues the handover
7
+ * (`readingCursorOf` on the web, the visible rows on the phone): `null` when
8
+ * it was at the bottom, else the id of the last message fully in view or,
9
+ * when one long message fills the view, the message at the reading line. The
10
+ * id travels as the handover's `cursor` (an opaque id from the person's own
11
+ * thread, never content). The destination records it with the arrival
12
+ * (`recordHandoffArrival({ cursor })`) and its transcript reveals that message
13
+ * once it has it, paging older history in when needed
14
+ * (`handoffCursorRevealStep`), and highlights it briefly. A cursor it can't
15
+ * find leaves the view at the bottom, as before: it is a hint, never a wait.
16
+ */
17
+ import { type ThreadMessage } from '@assistant-ui/core';
18
+ /** Whether older history is left to page in (`null` until the window is known). */
19
+ export { deepAgentHistoryHasOlder } from './edit-command';
20
+ /** How far from the bottom still counts as "at the bottom": no cursor is sent. */
21
+ export declare const READING_CURSOR_BOTTOM_TOLERANCE_PX = 48;
22
+ /** The reading line, as a fraction of the visible height from its top. */
23
+ export declare const READING_LINE_FRACTION: number;
24
+ /** One rendered message row, in the viewport's coordinates. */
25
+ export interface ReadingRow {
26
+ id: string;
27
+ top: number;
28
+ bottom: number;
29
+ }
30
+ /**
31
+ * The reading position among `rows` (in document order) visible between `top`
32
+ * and `bottom`: the last row fully inside, else the row across the reading
33
+ * line (a message taller than the view). `null` when neither is a message id.
34
+ */
35
+ export declare function readingCursorFromRows({ top, bottom, rows, }: {
36
+ top: number;
37
+ bottom: number;
38
+ rows: readonly ReadingRow[];
39
+ }): string | null;
40
+ /**
41
+ * The reading position of a list that reports which rows are visible, in
42
+ * order and partly visible ones included, but not where they sit (a native
43
+ * list's viewability). Only the first and last visible rows can be cut off,
44
+ * so with three or more the last fully visible one is the one before the
45
+ * last; with fewer, the first (the one across the reading line, as far as the
46
+ * list can tell). Callers check "at the bottom" themselves.
47
+ */
48
+ export declare function readingCursorFromVisibleIds(ids: readonly string[]): string | null;
49
+ interface BoxLike {
50
+ getBoundingClientRect(): {
51
+ top: number;
52
+ bottom: number;
53
+ };
54
+ }
55
+ interface RowLike extends BoxLike {
56
+ getAttribute(name: string): string | null;
57
+ }
58
+ /** The scroll container of a web transcript (structural, so Core needs no DOM types). */
59
+ export interface ReadingViewportLike extends BoxLike {
60
+ scrollTop: number;
61
+ scrollHeight: number;
62
+ clientHeight: number;
63
+ querySelectorAll(selectors: string): ArrayLike<RowLike>;
64
+ }
65
+ /** assistant-ui stamps every message row with its id. */
66
+ export declare const MESSAGE_ROW_ID_ATTRIBUTE = "data-message-id";
67
+ /**
68
+ * Where a web transcript is being read: `null` at the bottom, else the message
69
+ * id `readingCursorFromRows` picks. `coveredBottomPx` is what a sticky footer
70
+ * (the composer) hides at the bottom of the viewport.
71
+ */
72
+ export declare function readingCursorOf({ viewport, coveredBottomPx, idAttribute, }: {
73
+ viewport: ReadingViewportLike;
74
+ coveredBottomPx?: number;
75
+ idAttribute?: string;
76
+ }): string | null;
77
+ /**
78
+ * The id of the displayed message that holds `cursor`. A displayed message is
79
+ * one agent turn whose id is its first wire message's, and that id changes
80
+ * when an older page folds into it, so the cursor is matched against every
81
+ * wire message behind each row as well.
82
+ */
83
+ export declare function handoffCursorMessageId({ messages, cursor, }: {
84
+ messages: readonly ThreadMessage[];
85
+ cursor: string;
86
+ }): string | null;
87
+ /** Pages of older history one landing may load looking for its message. */
88
+ export declare const HANDOFF_CURSOR_MAX_HISTORY_PAGES = 20;
89
+ /**
90
+ * How long a landing waits without progress before staying at the bottom: a
91
+ * transcript still attaching, or a page of older history that never lands.
92
+ * Each page that lands starts the wait again, so a long conversation on a slow
93
+ * connection still reaches its message within the page budget.
94
+ */
95
+ export declare const HANDOFF_CURSOR_WAIT_MS = 30000;
96
+ /** How long the revealed message stays highlighted. */
97
+ export declare const HANDOFF_CURSOR_HIGHLIGHT_MS = 2400;
98
+ /**
99
+ * How long the revealed message is held in view while the transcript settles
100
+ * (an attaching thread can still scroll itself to the bottom). Any scroll the
101
+ * person makes ends it at once.
102
+ */
103
+ export declare const HANDOFF_CURSOR_SETTLE_MS = 1500;
104
+ export type HandoffCursorRevealStep = 'reveal' | 'wait' | 'page' | 'bottom';
105
+ /**
106
+ * What a destination does next while opening at a cursor: `reveal` the message
107
+ * it found; `wait` while the transcript (or a page it asked for) is loading or
108
+ * whether older history exists is not known yet (`hasOlder: null`: a cached
109
+ * transcript shows before its history window resolves); `page` older history
110
+ * in while some is left and the budget allows; else stay at the `bottom`, the
111
+ * fallback for a cursor that can't be found.
112
+ */
113
+ export declare function handoffCursorRevealStep({ found, loading, hasOlder, pagesLoaded, elapsedMs, }: {
114
+ found: boolean;
115
+ loading: boolean;
116
+ hasOlder: boolean | null;
117
+ pagesLoaded: number;
118
+ /** Since the landing last made progress: it started, or a page of older history landed. */
119
+ elapsedMs: number;
120
+ }): HandoffCursorRevealStep;
@@ -0,0 +1,88 @@
1
+ import { getExternalStoreMessages } from "@assistant-ui/core";
2
+ import { parseHandoffCursor } from "./handoff-cursor-id.js";
3
+ const READING_CURSOR_BOTTOM_TOLERANCE_PX = 48;
4
+ const READING_LINE_FRACTION = 1 / 3;
5
+ function readingCursorFromRows({
6
+ top,
7
+ bottom,
8
+ rows
9
+ }) {
10
+ var _a;
11
+ const line = top + (bottom - top) * READING_LINE_FRACTION;
12
+ let lastFull = null;
13
+ let atLine = null;
14
+ for (const row of rows) {
15
+ if (row.bottom <= row.top) continue;
16
+ if (row.top >= top - 1 && row.bottom <= bottom + 1) lastFull = row;
17
+ if (row.top <= line && row.bottom > line) atLine = row;
18
+ }
19
+ return parseHandoffCursor((_a = lastFull ?? atLine) == null ? void 0 : _a.id);
20
+ }
21
+ const MESSAGE_ROW_ID_ATTRIBUTE = "data-message-id";
22
+ function readingCursorOf({
23
+ viewport,
24
+ coveredBottomPx = 0,
25
+ idAttribute = MESSAGE_ROW_ID_ATTRIBUTE
26
+ }) {
27
+ const fromBottom = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;
28
+ if (fromBottom <= READING_CURSOR_BOTTOM_TOLERANCE_PX) return null;
29
+ const box = viewport.getBoundingClientRect();
30
+ const rows = Array.from(viewport.querySelectorAll(`[${idAttribute}]`), (row) => {
31
+ const rect = row.getBoundingClientRect();
32
+ return { id: row.getAttribute(idAttribute) ?? "", top: rect.top, bottom: rect.bottom };
33
+ });
34
+ return readingCursorFromRows({
35
+ top: box.top,
36
+ bottom: Math.max(box.top, box.bottom - coveredBottomPx),
37
+ rows
38
+ });
39
+ }
40
+ function handoffCursorMessageId({
41
+ messages,
42
+ cursor
43
+ }) {
44
+ for (const message of messages) {
45
+ if (message.id === cursor) return message.id;
46
+ }
47
+ for (const message of messages) {
48
+ const sources = getExternalStoreMessages(message);
49
+ if (!Array.isArray(sources)) continue;
50
+ for (const source of sources) {
51
+ if (source && typeof source === "object" && source.id === cursor) {
52
+ return message.id;
53
+ }
54
+ }
55
+ }
56
+ return null;
57
+ }
58
+ const HANDOFF_CURSOR_MAX_HISTORY_PAGES = 20;
59
+ const HANDOFF_CURSOR_WAIT_MS = 3e4;
60
+ const HANDOFF_CURSOR_HIGHLIGHT_MS = 2400;
61
+ const HANDOFF_CURSOR_SETTLE_MS = 1500;
62
+ function handoffCursorRevealStep({
63
+ found,
64
+ loading,
65
+ hasOlder,
66
+ pagesLoaded,
67
+ elapsedMs
68
+ }) {
69
+ if (found) return "reveal";
70
+ if (elapsedMs >= HANDOFF_CURSOR_WAIT_MS) return "bottom";
71
+ if (loading || hasOlder === null) return "wait";
72
+ if (hasOlder && pagesLoaded < HANDOFF_CURSOR_MAX_HISTORY_PAGES) return "page";
73
+ return "bottom";
74
+ }
75
+ export {
76
+ HANDOFF_CURSOR_HIGHLIGHT_MS,
77
+ HANDOFF_CURSOR_MAX_HISTORY_PAGES,
78
+ HANDOFF_CURSOR_SETTLE_MS,
79
+ HANDOFF_CURSOR_WAIT_MS,
80
+ MESSAGE_ROW_ID_ATTRIBUTE,
81
+ READING_CURSOR_BOTTOM_TOLERANCE_PX,
82
+ READING_LINE_FRACTION,
83
+ handoffCursorMessageId,
84
+ handoffCursorRevealStep,
85
+ readingCursorFromRows,
86
+ readingCursorOf
87
+ };
88
+ //# sourceMappingURL=handoff-cursor.js.map