@athenaintel/react 0.48.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +48 -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/index.d.ts +6 -5
  26. package/dist/agent-runtime/src/interrupts.cjs +28 -1
  27. package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
  28. package/dist/agent-runtime/src/interrupts.d.ts +21 -1
  29. package/dist/agent-runtime/src/interrupts.js +28 -1
  30. package/dist/agent-runtime/src/interrupts.js.map +1 -1
  31. package/dist/agent-runtime/src/model-context.cjs +3 -2
  32. package/dist/agent-runtime/src/model-context.cjs.map +1 -1
  33. package/dist/agent-runtime/src/model-context.d.ts +6 -1
  34. package/dist/agent-runtime/src/model-context.js +3 -2
  35. package/dist/agent-runtime/src/model-context.js.map +1 -1
  36. package/dist/agent-runtime/src/runtime.d.ts +3 -2
  37. package/dist/agent-runtime/src/send-recovery.cjs +37 -3
  38. package/dist/agent-runtime/src/send-recovery.cjs.map +1 -1
  39. package/dist/agent-runtime/src/send-recovery.d.ts +19 -0
  40. package/dist/agent-runtime/src/send-recovery.js +37 -3
  41. package/dist/agent-runtime/src/send-recovery.js.map +1 -1
  42. package/dist/agent-runtime/src/thread-handoff-flow-machine.d.ts +8 -8
  43. package/dist/agent-runtime/src/thread-handoff-protocol.d.ts +113 -1
  44. package/dist/agent-runtime/src/thread-handoff.d.ts +1 -1
  45. package/dist/agent-runtime/src/use-conversation-list.cjs +3 -2
  46. package/dist/agent-runtime/src/use-conversation-list.cjs.map +1 -1
  47. package/dist/agent-runtime/src/use-conversation-list.d.ts +6 -0
  48. package/dist/agent-runtime/src/use-conversation-list.js +3 -2
  49. package/dist/agent-runtime/src/use-conversation-list.js.map +1 -1
  50. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +21 -1
  51. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -1
  52. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +8 -2
  53. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +21 -1
  54. package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -1
  55. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +24 -6
  56. package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
  57. package/dist/agent-runtime/src/use-deep-agent-runtime.d.ts +17 -0
  58. package/dist/agent-runtime/src/use-deep-agent-runtime.js +24 -6
  59. package/dist/agent-runtime/src/use-deep-agent-runtime.js.map +1 -1
  60. package/dist/agent-runtime/src/use-deep-agent-voice.cjs +44 -9
  61. package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -1
  62. package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +34 -1
  63. package/dist/agent-runtime/src/use-deep-agent-voice.js +44 -9
  64. package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -1
  65. package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +8 -2
  66. package/dist/agent-runtime/src/voice-earcon.cjs +139 -0
  67. package/dist/agent-runtime/src/voice-earcon.cjs.map +1 -0
  68. package/dist/agent-runtime/src/voice-earcon.d.ts +38 -0
  69. package/dist/agent-runtime/src/voice-earcon.js +139 -0
  70. package/dist/agent-runtime/src/voice-earcon.js.map +1 -0
  71. package/dist/agent-runtime/src/voice-media.cjs.map +1 -1
  72. package/dist/agent-runtime/src/voice-media.d.ts +14 -0
  73. package/dist/agent-runtime/src/voice-media.js.map +1 -1
  74. package/dist/agent-runtime/src/voice-presentation.cjs +2 -0
  75. package/dist/agent-runtime/src/voice-presentation.cjs.map +1 -1
  76. package/dist/agent-runtime/src/voice-presentation.js +2 -0
  77. package/dist/agent-runtime/src/voice-presentation.js.map +1 -1
  78. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  79. package/dist/assets/AthenaAssetEmbed.d.ts +11 -5
  80. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  81. package/dist/assets/use-asset-embed.cjs.map +1 -1
  82. package/dist/assets/use-asset-embed.d.ts +12 -5
  83. package/dist/assets/use-asset-embed.js.map +1 -1
  84. package/dist/chat/StatewireApprovalCard.cjs +41 -6
  85. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  86. package/dist/chat/StatewireApprovalCard.d.ts +18 -1
  87. package/dist/chat/StatewireApprovalCard.js +42 -7
  88. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  89. package/dist/chat/StatewireQueuedMessages.cjs +56 -6
  90. package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
  91. package/dist/chat/StatewireQueuedMessages.d.ts +14 -0
  92. package/dist/chat/StatewireQueuedMessages.js +58 -8
  93. package/dist/chat/StatewireQueuedMessages.js.map +1 -1
  94. package/dist/chat/WaitingOnYouBanner.cjs +6 -2
  95. package/dist/chat/WaitingOnYouBanner.cjs.map +1 -1
  96. package/dist/chat/WaitingOnYouBanner.js +7 -3
  97. package/dist/chat/WaitingOnYouBanner.js.map +1 -1
  98. package/dist/chat/chat-voice-controls.cjs +3 -1
  99. package/dist/chat/chat-voice-controls.cjs.map +1 -1
  100. package/dist/chat/chat-voice-controls.d.ts +6 -1
  101. package/dist/chat/chat-voice-controls.js +3 -1
  102. package/dist/chat/chat-voice-controls.js.map +1 -1
  103. package/dist/chat-ui/index.cjs +3 -0
  104. package/dist/chat-ui/index.cjs.map +1 -1
  105. package/dist/chat-ui/index.d.ts +1 -0
  106. package/dist/chat-ui/index.js +3 -0
  107. package/dist/chat-ui/index.js.map +1 -1
  108. package/dist/chat-ui/messages/from-the-call-card.cjs +124 -0
  109. package/dist/chat-ui/messages/from-the-call-card.cjs.map +1 -0
  110. package/dist/chat-ui/messages/from-the-call-card.d.ts +17 -0
  111. package/dist/chat-ui/messages/from-the-call-card.js +124 -0
  112. package/dist/chat-ui/messages/from-the-call-card.js.map +1 -0
  113. package/dist/chat-ui/rich-text/chat-link.cjs +1 -0
  114. package/dist/chat-ui/rich-text/chat-link.cjs.map +1 -1
  115. package/dist/chat-ui/rich-text/chat-link.d.ts +4 -0
  116. package/dist/chat-ui/rich-text/chat-link.js +4 -3
  117. package/dist/chat-ui/rich-text/chat-link.js.map +1 -1
  118. package/dist/chat-ui/rich-text/chat-message-body.cjs +1 -0
  119. package/dist/chat-ui/rich-text/chat-message-body.cjs.map +1 -1
  120. package/dist/chat-ui/rich-text/chat-message-body.d.ts +12 -0
  121. package/dist/chat-ui/rich-text/chat-message-body.js +2 -1
  122. package/dist/chat-ui/rich-text/chat-message-body.js.map +1 -1
  123. package/dist/chat-ui/thread/chat-thread-shell.cjs +2 -0
  124. package/dist/chat-ui/thread/chat-thread-shell.cjs.map +1 -1
  125. package/dist/chat-ui/thread/chat-thread-shell.js +2 -0
  126. package/dist/chat-ui/thread/chat-thread-shell.js.map +1 -1
  127. package/dist/collab/client.cjs +15 -3
  128. package/dist/collab/client.cjs.map +1 -1
  129. package/dist/collab/client.d.ts +4 -2
  130. package/dist/collab/client.js +16 -4
  131. package/dist/collab/client.js.map +1 -1
  132. package/dist/composer/index.d.ts +1 -1
  133. package/dist/composer/useReadComposerDraft.cjs +26 -7
  134. package/dist/composer/useReadComposerDraft.cjs.map +1 -1
  135. package/dist/composer/useReadComposerDraft.d.ts +23 -1
  136. package/dist/composer/useReadComposerDraft.js +27 -8
  137. package/dist/composer/useReadComposerDraft.js.map +1 -1
  138. package/dist/index.cjs +3 -0
  139. package/dist/index.cjs.map +1 -1
  140. package/dist/index.d.ts +3 -1
  141. package/dist/index.js +4 -1
  142. package/dist/index.js.map +1 -1
  143. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs +190 -0
  144. package/dist/keryx-http/src/unconfirmed-update-attributions.cjs.map +1 -0
  145. package/dist/keryx-http/src/unconfirmed-update-attributions.d.ts +132 -0
  146. package/dist/keryx-http/src/unconfirmed-update-attributions.js +190 -0
  147. package/dist/keryx-http/src/unconfirmed-update-attributions.js.map +1 -0
  148. package/dist/keryx-http/src/update-attributions.cjs +34 -4
  149. package/dist/keryx-http/src/update-attributions.cjs.map +1 -1
  150. package/dist/keryx-http/src/update-attributions.d.ts +36 -4
  151. package/dist/keryx-http/src/update-attributions.js +35 -5
  152. package/dist/keryx-http/src/update-attributions.js.map +1 -1
  153. package/dist/provider/AthenaProvider.cjs +4 -0
  154. package/dist/provider/AthenaProvider.cjs.map +1 -1
  155. package/dist/provider/AthenaProvider.d.ts +11 -1
  156. package/dist/provider/AthenaProvider.js +4 -0
  157. package/dist/provider/AthenaProvider.js.map +1 -1
  158. package/dist/react/package.json.cjs +1 -1
  159. package/dist/react/package.json.js +1 -1
  160. package/dist/threads/api.cjs.map +1 -1
  161. package/dist/threads/api.d.ts +15 -0
  162. package/dist/threads/api.js.map +1 -1
  163. package/dist/threads/conversation-list-fetcher.cjs +13 -5
  164. package/dist/threads/conversation-list-fetcher.cjs.map +1 -1
  165. package/dist/threads/conversation-list-fetcher.d.ts +4 -1
  166. package/dist/threads/conversation-list-fetcher.js +13 -5
  167. package/dist/threads/conversation-list-fetcher.js.map +1 -1
  168. package/dist/threads/statewire-thread-list.cjs +28 -6
  169. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  170. package/dist/threads/statewire-thread-list.d.ts +20 -8
  171. package/dist/threads/statewire-thread-list.js +28 -6
  172. package/dist/threads/statewire-thread-list.js.map +1 -1
  173. package/dist/threads/use-athena-sessions.cjs +27 -5
  174. package/dist/threads/use-athena-sessions.cjs.map +1 -1
  175. package/dist/threads/use-athena-sessions.d.ts +10 -5
  176. package/dist/threads/use-athena-sessions.js +28 -6
  177. package/dist/threads/use-athena-sessions.js.map +1 -1
  178. package/dist/threads/use-rest-conversation-history.d.ts +1 -0
  179. package/package.json +1 -1
@@ -1,6 +1,28 @@
1
+ import { type ComposerHandoffStore } from './composer-handoff';
2
+ /**
3
+ * The composer's text, or `null` when there is no draft to read. Inside `AthenaProvider` (a
4
+ * `store`), the runtime's text is the person's draft only while the editor is mounted (it
5
+ * registers `focusEnd`) and no write made before it mounted is still waiting: until then the
6
+ * runtime holds an empty text that is not what the person sees. A read that throws (no composer
7
+ * in scope) is `null` too.
8
+ */
9
+ export declare function tryReadComposerText({ read, store, }: {
10
+ read: () => {
11
+ text?: string | null;
12
+ };
13
+ store: Pick<ComposerHandoffStore, 'focusEnd' | 'pending'> | null;
14
+ }): string | null;
15
+ /**
16
+ * Reads the composer's draft (its text) when called, or `null` when there is no draft to read:
17
+ * the editor has not mounted, a write is still waiting for it, or the read fails. For a host that
18
+ * must tell a blank composer (`''`) from one it could not read, such as "Continue on…", where a
19
+ * blank composer clears the draft of a reused handover ticket and an unread one must leave it as
20
+ * it was.
21
+ */
22
+ export declare function useTryReadComposerDraft(): () => string | null;
1
23
  /**
2
24
  * Reads the composer's draft (its text) when called, for a host that hands the chat elsewhere and
3
25
  * carries what was not sent yet along (a launcher window's "open in the app"). An empty string
4
- * before the composer exists.
26
+ * before the composer exists; {@link useTryReadComposerDraft} tells that case apart.
5
27
  */
6
28
  export declare function useReadComposerDraft(): () => string;
@@ -1,16 +1,35 @@
1
1
  import { useCallback } from "react";
2
2
  import { useAui } from "@assistant-ui/react";
3
+ import { useComposerHandoffStore } from "./composer-handoff.js";
4
+ function tryReadComposerText({
5
+ read,
6
+ store
7
+ }) {
8
+ if (store !== null && (store.focusEnd === null || store.pending.length > 0)) return null;
9
+ try {
10
+ return read().text ?? null;
11
+ } catch {
12
+ return null;
13
+ }
14
+ }
15
+ function useTryReadComposerDraft() {
16
+ const aui = useAui();
17
+ const store = useComposerHandoffStore();
18
+ return useCallback(
19
+ () => tryReadComposerText({ read: () => aui.composer.getState(), store }),
20
+ [aui, store]
21
+ );
22
+ }
3
23
  function useReadComposerDraft() {
4
24
  const aui = useAui();
5
- return useCallback(() => {
6
- try {
7
- return aui.composer.getState().text ?? "";
8
- } catch {
9
- return "";
10
- }
11
- }, [aui]);
25
+ return useCallback(
26
+ () => tryReadComposerText({ read: () => aui.composer.getState(), store: null }) ?? "",
27
+ [aui]
28
+ );
12
29
  }
13
30
  export {
14
- useReadComposerDraft
31
+ tryReadComposerText,
32
+ useReadComposerDraft,
33
+ useTryReadComposerDraft
15
34
  };
16
35
  //# sourceMappingURL=useReadComposerDraft.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useReadComposerDraft.js","sources":["../../src/composer/useReadComposerDraft.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useAui } from '@assistant-ui/react';\n\n/**\n * Reads the composer's draft (its text) when called, for a host that hands the chat elsewhere and\n * carries what was not sent yet along (a launcher window's \"open in the app\"). An empty string\n * before the composer exists.\n */\nexport function useReadComposerDraft(): () => string {\n const aui = useAui();\n return useCallback(() => {\n try {\n return aui.composer.getState().text ?? '';\n } catch {\n return '';\n }\n }, [aui]);\n}\n"],"names":[],"mappings":";;AAQO,SAAS,uBAAqC;AACnD,QAAM,MAAM,OAAA;AACZ,SAAO,YAAY,MAAM;AACvB,QAAI;AACF,aAAO,IAAI,SAAS,SAAA,EAAW,QAAQ;AAAA,IACzC,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACV;"}
1
+ {"version":3,"file":"useReadComposerDraft.js","sources":["../../src/composer/useReadComposerDraft.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useAui } from '@assistant-ui/react';\nimport { type ComposerHandoffStore, useComposerHandoffStore } from './composer-handoff';\n\n/**\n * The composer's text, or `null` when there is no draft to read. Inside `AthenaProvider` (a\n * `store`), the runtime's text is the person's draft only while the editor is mounted (it\n * registers `focusEnd`) and no write made before it mounted is still waiting: until then the\n * runtime holds an empty text that is not what the person sees. A read that throws (no composer\n * in scope) is `null` too.\n */\nexport function tryReadComposerText({\n read,\n store,\n}: {\n read: () => { text?: string | null };\n store: Pick<ComposerHandoffStore, 'focusEnd' | 'pending'> | null;\n}): string | null {\n if (store !== null && (store.focusEnd === null || store.pending.length > 0)) return null;\n try {\n return read().text ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Reads the composer's draft (its text) when called, or `null` when there is no draft to read:\n * the editor has not mounted, a write is still waiting for it, or the read fails. For a host that\n * must tell a blank composer (`''`) from one it could not read, such as \"Continue on…\", where a\n * blank composer clears the draft of a reused handover ticket and an unread one must leave it as\n * it was.\n */\nexport function useTryReadComposerDraft(): () => string | null {\n const aui = useAui();\n const store = useComposerHandoffStore();\n return useCallback(\n () => tryReadComposerText({ read: () => aui.composer.getState(), store }),\n [aui, store]\n );\n}\n\n/**\n * Reads the composer's draft (its text) when called, for a host that hands the chat elsewhere and\n * carries what was not sent yet along (a launcher window's \"open in the app\"). An empty string\n * before the composer exists; {@link useTryReadComposerDraft} tells that case apart.\n */\nexport function useReadComposerDraft(): () => string {\n const aui = useAui();\n return useCallback(\n () => tryReadComposerText({ read: () => aui.composer.getState(), store: null }) ?? '',\n [aui]\n );\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGkB;AAChB,MAAI,UAAU,SAAS,MAAM,aAAa,QAAQ,MAAM,QAAQ,SAAS,GAAI,QAAO;AACpF,MAAI;AACF,WAAO,KAAA,EAAO,QAAQ;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AASO,SAAS,0BAA+C;AAC7D,QAAM,MAAM,OAAA;AACZ,QAAM,QAAQ,wBAAA;AACd,SAAO;AAAA,IACL,MAAM,oBAAoB,EAAE,MAAM,MAAM,IAAI,SAAS,SAAA,GAAY,OAAO;AAAA,IACxE,CAAC,KAAK,KAAK;AAAA,EAAA;AAEf;AAOO,SAAS,uBAAqC;AACnD,QAAM,MAAM,OAAA;AACZ,SAAO;AAAA,IACL,MAAM,oBAAoB,EAAE,MAAM,MAAM,IAAI,SAAS,SAAA,GAAY,OAAO,KAAA,CAAM,KAAK;AAAA,IACnF,CAAC,GAAG;AAAA,EAAA;AAER;"}
package/dist/index.cjs CHANGED
@@ -109,6 +109,7 @@ const dictationEngine = require("./dictation/dictation-engine.cjs");
109
109
  const recordedDictationEngine = require("./dictation/recorded-dictation-engine.cjs");
110
110
  const useAthenaDictationEngine = require("./dictation/use-athena-dictation-engine.cjs");
111
111
  const dictationState = require("./dictation/dictation-state.cjs");
112
+ const useChatVoiceEnabled = require("./voice/use-chat-voice-enabled.cjs");
112
113
  const useAppendToComposer = require("./composer/useAppendToComposer.cjs");
113
114
  const composerHandoff = require("./composer/composer-handoff.cjs");
114
115
  const useReadComposerDraft = require("./composer/useReadComposerDraft.cjs");
@@ -477,10 +478,12 @@ exports.createRecordedDictationEngine = recordedDictationEngine.createRecordedDi
477
478
  exports.useAthenaDictationEngine = useAthenaDictationEngine.useAthenaDictationEngine;
478
479
  exports.DICTATION_STATUSES = dictationState.DICTATION_STATUSES;
479
480
  exports.composeDictationDraft = dictationState.composeDictationDraft;
481
+ exports.useChatVoiceEnabled = useChatVoiceEnabled.useChatVoiceEnabled;
480
482
  exports.useAppendToComposer = useAppendToComposer.useAppendToComposer;
481
483
  exports.useComposerReady = composerHandoff.useComposerReady;
482
484
  exports.useFocusComposer = composerHandoff.useFocusComposer;
483
485
  exports.useReadComposerDraft = useReadComposerDraft.useReadComposerDraft;
486
+ exports.useTryReadComposerDraft = useReadComposerDraft.useTryReadComposerDraft;
484
487
  exports.useSendMessage = useSendMessage.useSendMessage;
485
488
  exports.useComposerAttachment = useComposerAttachment.useComposerAttachment;
486
489
  exports.ChatAgentPicker = chatPickers.ChatAgentPicker;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -189,10 +189,12 @@ export { useAthenaDictationEngine } from './dictation/use-athena-dictation-engin
189
189
  export { composeDictationDraft, DICTATION_STATUSES } from './dictation/dictation-state';
190
190
  export type { DictationStatus, DictationTranscript } from './dictation/dictation-state';
191
191
  export type { AthenaChatComposerSlots, AthenaChatContinueByVoice, AthenaChatDictationOptions, } from './chat/AthenaChat';
192
+ /** Whether the chat's voice control shows for this sign-in: the gate `AthenaChat`'s mic uses. */
193
+ export { useChatVoiceEnabled } from './voice/use-chat-voice-enabled';
192
194
  export { useAppendToComposer } from './composer/useAppendToComposer';
193
195
  export type { AppendToComposerOptions } from './composer/useAppendToComposer';
194
196
  export { useComposerReady, useFocusComposer } from './composer/composer-handoff';
195
- export { useReadComposerDraft } from './composer/useReadComposerDraft';
197
+ export { useReadComposerDraft, useTryReadComposerDraft } from './composer/useReadComposerDraft';
196
198
  export { useSendMessage } from './composer/useSendMessage';
197
199
  export type { SendMessageOptions } from './composer/useSendMessage';
198
200
  export { useComposerAttachment } from './composer/useComposerAttachment';
package/dist/index.js CHANGED
@@ -107,9 +107,10 @@ import { DICTATION_ENGINE_ERROR_KINDS, createWebSpeechDictationEngine } from "./
107
107
  import { createRecordedDictationEngine } from "./dictation/recorded-dictation-engine.js";
108
108
  import { useAthenaDictationEngine } from "./dictation/use-athena-dictation-engine.js";
109
109
  import { DICTATION_STATUSES, composeDictationDraft } from "./dictation/dictation-state.js";
110
+ import { useChatVoiceEnabled } from "./voice/use-chat-voice-enabled.js";
110
111
  import { useAppendToComposer } from "./composer/useAppendToComposer.js";
111
112
  import { useComposerReady, useFocusComposer } from "./composer/composer-handoff.js";
112
- import { useReadComposerDraft } from "./composer/useReadComposerDraft.js";
113
+ import { useReadComposerDraft, useTryReadComposerDraft } from "./composer/useReadComposerDraft.js";
113
114
  import { useSendMessage } from "./composer/useSendMessage.js";
114
115
  import { useComposerAttachment } from "./composer/useComposerAttachment.js";
115
116
  import { ChatAgentPicker, ChatModePicker, ChatModelPicker } from "./catalog/chat-pickers.js";
@@ -538,6 +539,7 @@ export {
538
539
  useAthenaVoiceLive,
539
540
  useAttachments,
540
541
  useBrowserDecisionConfirmer,
542
+ useChatVoiceEnabled,
541
543
  useComposerAttachment,
542
544
  useComposerReady,
543
545
  useDeviceOperationReader,
@@ -566,6 +568,7 @@ export {
566
568
  useStatewireToolOutputs,
567
569
  useToolAppearance,
568
570
  useToolPartPlacement,
571
+ useTryReadComposerDraft,
569
572
  useTurnToolCallsAwaitingApproval,
570
573
  windowInFrontSignal,
571
574
  withCaptureGateBypass,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const Y = require("@y/y");
7
+ const updateAttributions = require("./update-attributions.cjs");
8
+ const MESSAGE_SYNC = 0;
9
+ const SYNC_STEP_2 = 1;
10
+ const SYNC_UPDATE = 2;
11
+ const MAX_ATTRIBUTED_RUNS = 64;
12
+ function noIds(ids) {
13
+ return ids.inserts.isEmpty() && ids.deletes.isEmpty();
14
+ }
15
+ function sameAttributions(a, b) {
16
+ return a.length === b.length && a.every((pair, index) => {
17
+ var _a, _b;
18
+ return pair.k === ((_a = b[index]) == null ? void 0 : _a.k) && pair.v === ((_b = b[index]) == null ? void 0 : _b.v);
19
+ });
20
+ }
21
+ function readSyncFrame(frame) {
22
+ const type = updateAttributions.readVarUint({ bytes: frame, start: 0 });
23
+ if ((type == null ? void 0 : type.value) !== MESSAGE_SYNC) return null;
24
+ const syncType = updateAttributions.readVarUint({ bytes: frame, start: type.next });
25
+ if (syncType === null) return null;
26
+ const length = updateAttributions.readVarUint({ bytes: frame, start: syncType.next });
27
+ if (length === null || length.next + length.value !== frame.length) return null;
28
+ return { syncType: syncType.value, payload: frame.subarray(length.next) };
29
+ }
30
+ function syncFrame({ syncType, payload }) {
31
+ const head = [];
32
+ updateAttributions.writeVarUint({ out: head, value: MESSAGE_SYNC });
33
+ updateAttributions.writeVarUint({ out: head, value: syncType });
34
+ updateAttributions.writeVarUint({ out: head, value: payload.length });
35
+ const frame = new Uint8Array(head.length + payload.length);
36
+ frame.set(head, 0);
37
+ frame.set(payload, head.length);
38
+ return frame;
39
+ }
40
+ function idsOf(update) {
41
+ try {
42
+ return Y.createContentIdsFromUpdate(update);
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+ function copyOf({ ids, attributions }) {
48
+ return { ids, attributions: attributions.map(({ k, v }) => ({ k, v })) };
49
+ }
50
+ function bounded(runs) {
51
+ return runs.length > MAX_ATTRIBUTED_RUNS ? runs.slice(runs.length - MAX_ATTRIBUTED_RUNS) : runs;
52
+ }
53
+ const ROOMS = Symbol.for("@athenaintel/keryx-http/unconfirmed-update-attributions");
54
+ function rooms() {
55
+ const host = globalThis;
56
+ return host[ROOMS] ?? (host[ROOMS] = { live: /* @__PURE__ */ new WeakMap(), left: /* @__PURE__ */ new WeakMap() });
57
+ }
58
+ class UnconfirmedUpdateAttributions {
59
+ constructor({
60
+ doc,
61
+ attributionsFor,
62
+ isRemoteOrigin
63
+ }) {
64
+ __publicField(this, "runs");
65
+ __publicField(this, "doc");
66
+ __publicField(this, "attributionsFor");
67
+ __publicField(this, "isRemoteOrigin");
68
+ __publicField(this, "handleUpdate", (update, origin) => {
69
+ if (this.isRemoteOrigin(origin)) return;
70
+ const attributions = this.attributionsFor();
71
+ if (!attributions || attributions.length === 0) return;
72
+ const ids = idsOf(update);
73
+ if (!ids || noIds(ids)) return;
74
+ const last = this.runs.at(-1);
75
+ if (last && sameAttributions(last.attributions, attributions)) {
76
+ last.ids = Y.mergeContentIds([last.ids, ids]);
77
+ return;
78
+ }
79
+ this.runs = bounded([...this.runs, copyOf({ ids, attributions })]);
80
+ });
81
+ this.doc = doc;
82
+ this.attributionsFor = attributionsFor;
83
+ this.isRemoteOrigin = isRemoteOrigin;
84
+ const { live, left } = rooms();
85
+ this.runs = left.get(doc) ?? [];
86
+ left.delete(doc);
87
+ live.set(doc, this);
88
+ doc.on("update", this.handleUpdate);
89
+ }
90
+ /** The attributed writes Keryx has not acknowledged, oldest first. */
91
+ get pending() {
92
+ return this.runs.map(copyOf);
93
+ }
94
+ /** Writes an earlier session kept, older than any written here: they go out first. */
95
+ restore(writes) {
96
+ this.runs = bounded([...writes.map(copyOf), ...this.runs]);
97
+ }
98
+ /**
99
+ * One socket of the room. While the room keeps writes, the socket's sync step 2 (its answer to
100
+ * Keryx's sync step 1) waits for the next frame Keryx sends, its whole document, which drops what
101
+ * Keryx already holds before the answer is split (see the module comment); every frame sent
102
+ * meanwhile waits behind it, in order. Nothing kept, or a socket that cannot hear Keryx: every
103
+ * frame goes out as it is sent.
104
+ */
105
+ connect({
106
+ send,
107
+ hears
108
+ }) {
109
+ let held = null;
110
+ const sendNow = (frame) => {
111
+ for (const out of this.framesFor(frame)) send(out);
112
+ };
113
+ return {
114
+ received: (frame) => {
115
+ this.received(frame);
116
+ if (held === null) return;
117
+ const waiting = held;
118
+ held = null;
119
+ for (const next of waiting) sendNow(next);
120
+ },
121
+ send: (frame) => {
122
+ var _a;
123
+ if (held !== null) {
124
+ held.push(frame);
125
+ return;
126
+ }
127
+ if (hears && this.runs.length > 0 && ((_a = readSyncFrame(frame)) == null ? void 0 : _a.syncType) === SYNC_STEP_2) {
128
+ held = [frame];
129
+ return;
130
+ }
131
+ sendNow(frame);
132
+ }
133
+ };
134
+ }
135
+ /** Keryx sent `frame`: the ids it carries are Keryx's, kept no longer. */
136
+ received(frame) {
137
+ if (this.runs.length === 0) return;
138
+ const message = readSyncFrame(frame);
139
+ if (message === null) return;
140
+ if (message.syncType !== SYNC_STEP_2 && message.syncType !== SYNC_UPDATE) return;
141
+ const held = idsOf(message.payload);
142
+ if (!held) return;
143
+ this.runs = this.runs.map(({ ids, attributions }) => ({ ids: Y.excludeContentIds(ids, held), attributions })).filter((run) => !noIds(run.ids));
144
+ }
145
+ /**
146
+ * What goes out in place of `frame`: `[frame]` itself, except a sync step 2 carrying kept writes,
147
+ * which goes out behind each of them as its own marked sync update.
148
+ */
149
+ framesFor(frame) {
150
+ if (this.runs.length === 0) return [frame];
151
+ const message = readSyncFrame(frame);
152
+ if (message === null || message.syncType !== SYNC_STEP_2) return [frame];
153
+ const answer = message.payload;
154
+ const all = idsOf(answer);
155
+ if (!all) return [frame];
156
+ const frames = [];
157
+ const marked = [];
158
+ for (const run of this.runs) {
159
+ const part = Y.intersectContentIds(run.ids, all);
160
+ if (noIds(part)) continue;
161
+ frames.push(
162
+ updateAttributions.withUpdateAttributionsTrailer({
163
+ message: syncFrame({
164
+ syncType: SYNC_UPDATE,
165
+ payload: Y.intersectUpdateWithContentIds(answer, part)
166
+ }),
167
+ attributions: run.attributions
168
+ })
169
+ );
170
+ marked.push(part);
171
+ }
172
+ if (marked.length === 0) return [frame];
173
+ const rest = Y.excludeContentIds(all, Y.mergeContentIds(marked));
174
+ frames.push(
175
+ syncFrame({ syncType: SYNC_STEP_2, payload: Y.intersectUpdateWithContentIds(answer, rest) })
176
+ );
177
+ return frames;
178
+ }
179
+ /** Stops keeping; what is still kept waits for the next tracker made for the document. */
180
+ destroy() {
181
+ this.doc.off("update", this.handleUpdate);
182
+ const { live, left } = rooms();
183
+ if (live.get(this.doc) === this) live.delete(this.doc);
184
+ if (this.runs.length > 0) left.set(this.doc, this.runs);
185
+ this.runs = [];
186
+ }
187
+ }
188
+ exports.MAX_ATTRIBUTED_RUNS = MAX_ATTRIBUTED_RUNS;
189
+ exports.UnconfirmedUpdateAttributions = UnconfirmedUpdateAttributions;
190
+ //# sourceMappingURL=unconfirmed-update-attributions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unconfirmed-update-attributions.cjs","sources":["../../../../keryx-http/src/unconfirmed-update-attributions.ts"],"sourcesContent":["/**\n * The attributed writes a room has not seen Keryx acknowledge, kept so that a write made while the\n * room's socket is closed still reaches Keryx with its attributions.\n *\n * A write made inside `runWithDocUpdateAttributions` leaves as its own sync update followed by the\n * attributions trailer (`attributingWebSocket`), but only if the room's socket is open as it is\n * made. One made while it is closed (offline, reconnecting, before the first connection) reaches\n * Keryx inside the reconnect's sync step 2: the client's answer to Keryx's sync step 1, everything\n * it holds that Keryx lacks. Keryx reads no trailer after a sync step 2, so it would count the\n * write as the person's edit.\n *\n * So the room keeps the content ids of every write made in a scope, with the scope's attributions,\n * until Keryx sends those ids back: the echo of the update that carried them, or the whole document\n * Keryx sends when a socket opens (`received`; `@y/websocket` confirms its own unconfirmed updates\n * the same way). When the socket sends a sync step 2, each kept write's part of it goes out first,\n * oldest first, as its own sync update with its trailer, and the sync step 2 follows without those\n * ids (`framesFor`). The parts are cut from the sync step 2 itself, which already holds only what\n * Keryx lacks past its state vector. One socket keeps the order, so Keryx appends each marked update\n * before the person's sync step 2.\n *\n * That answer waits for Keryx's document (`connect`). Keryx sends its sync step 1 and, in the same\n * cork, its whole document, but `@y/websocket` answers the sync step 1 as it arrives. A kept write\n * Keryx already appended (its echo lost with the socket) is still kept then, and the sync step 2\n * holds the client's whole delete set, so its deletes would go out again as a marked update, which\n * Keryx appends: it drops what it holds from the first sync step 2 only. Held until the next frame,\n * the answer is split once Keryx's document has dropped what it holds.\n *\n * What Keryx records (`patches/@y%2Fhub@0.10.1.patch`):\n * - An update's content map attributes every id it carries, inserts and deletes, read from its\n * bytes: an update that cannot integrate yet (an item next to one the person typed offline, the\n * next clocks of the person's own client) is attributed like any other. Peers hold it until the\n * sync step 2 behind it brings what it needs.\n * - An id is attributed by the first stream entry that carries it (`getDoc`'s `excludeContentMap`),\n * so a later copy changes no merged history. The live change notices read each entry's own\n * content map, though (keryx/src/doc-watcher.ts), and the first sync step 2's strip of what Keryx\n * holds reads the known ids when the frame arrives, possibly before the update ahead of it is in\n * the stream (one whose content map the compute pool builds). A copy inside the sync step 2\n * would then be announced as the person's: the sync step 2 never carries a kept write's ids.\n *\n * Bounded: consecutive writes of one scope merge into one run, and past\n * {@link MAX_ATTRIBUTED_RUNS} runs the oldest is let go (its content then reaches Keryx in a sync\n * step 2, as the person's). A room's local copy keeps them across sessions\n * ({@link unconfirmedAttributedWritesOf}, {@link restoreUnconfirmedAttributedWrites}); without one,\n * a write the room kept is forgotten with the page.\n */\nimport {\n type ContentIds,\n createContentIdsFromUpdate,\n type Doc,\n excludeContentIds,\n intersectContentIds,\n intersectUpdateWithContentIds,\n mergeContentIds,\n} from '@y/y';\nimport {\n type AttributedWritesSocket,\n readVarUint,\n type UnconfirmedAttributedWrites,\n type UpdateAttribution,\n withUpdateAttributionsTrailer,\n writeVarUint,\n} from './update-attributions.js';\n\n/** y-protocols: a sync message, and the sub-types that carry content. */\nconst MESSAGE_SYNC = 0;\nconst SYNC_STEP_2 = 1;\nconst SYNC_UPDATE = 2;\n\n/** Writes made in one attribution scope, by the content ids they wrote (inserts and deletes). */\nexport interface AttributedWrites {\n ids: ContentIds;\n attributions: readonly UpdateAttribution[];\n}\n\n/**\n * The most runs a room keeps; a run is one scope's writes since a write of another scope. Housekeeping\n * all shares one scope, so runs pile up only as Quick Edit steps interleave with it.\n */\nexport const MAX_ATTRIBUTED_RUNS = 64;\n\nfunction noIds(ids: ContentIds): boolean {\n return ids.inserts.isEmpty() && ids.deletes.isEmpty();\n}\n\nfunction sameAttributions(\n a: readonly UpdateAttribution[],\n b: readonly UpdateAttribution[]\n): boolean {\n return (\n a.length === b.length &&\n a.every((pair, index) => pair.k === b[index]?.k && pair.v === b[index]?.v)\n );\n}\n\n/** The sync message `frame` is, when it is exactly one (nothing after its payload). */\nfunction readSyncFrame(frame: Uint8Array): { syncType: number; payload: Uint8Array } | null {\n const type = readVarUint({ bytes: frame, start: 0 });\n if (type?.value !== MESSAGE_SYNC) return null;\n const syncType = readVarUint({ bytes: frame, start: type.next });\n if (syncType === null) return null;\n const length = readVarUint({ bytes: frame, start: syncType.next });\n if (length === null || length.next + length.value !== frame.length) return null;\n return { syncType: syncType.value, payload: frame.subarray(length.next) };\n}\n\n/** A sync message of `syncType` carrying `payload`, as y-protocols writes one. */\nfunction syncFrame({ syncType, payload }: { syncType: number; payload: Uint8Array }): Uint8Array {\n const head: number[] = [];\n writeVarUint({ out: head, value: MESSAGE_SYNC });\n writeVarUint({ out: head, value: syncType });\n writeVarUint({ out: head, value: payload.length });\n const frame = new Uint8Array(head.length + payload.length);\n frame.set(head, 0);\n frame.set(payload, head.length);\n return frame;\n}\n\n/** The content ids an update carries, or `null` for bytes that are not one. */\nfunction idsOf(update: Uint8Array): ContentIds | null {\n try {\n return createContentIdsFromUpdate(update);\n } catch {\n return null;\n }\n}\n\nfunction copyOf({ ids, attributions }: AttributedWrites): AttributedWrites {\n return { ids, attributions: attributions.map(({ k, v }) => ({ k, v })) };\n}\n\n/** `runs` without the oldest past {@link MAX_ATTRIBUTED_RUNS}. */\nfunction bounded(runs: AttributedWrites[]): AttributedWrites[] {\n return runs.length > MAX_ATTRIBUTED_RUNS ? runs.slice(runs.length - MAX_ATTRIBUTED_RUNS) : runs;\n}\n\n/** What a page reads of a room's tracker, whichever copy of this module made it. */\ninterface KeptWrites {\n readonly pending: readonly AttributedWrites[];\n restore(writes: readonly AttributedWrites[]): void;\n}\n\n/**\n * Each document's tracker in the page, and what a destroyed one still kept for the next tracker made\n * for the same document (a transport rebuilt over a retained document; a local copy read into a\n * document before its room's transport exists). On `globalThis`, not in module scope, for the reason\n * the scopes are (`update-attributions.ts`): the SDK's dist inlines its own copy of this module, and\n * a local copy reading a room through another copy must find the same tracker. Weak: each entry goes\n * with its document.\n */\nconst ROOMS = Symbol.for('@athenaintel/keryx-http/unconfirmed-update-attributions');\n\ninterface Rooms {\n live: WeakMap<object, KeptWrites>;\n left: WeakMap<object, AttributedWrites[]>;\n}\n\ntype RoomsHost = typeof globalThis & {\n [ROOMS]?: Rooms;\n};\n\n// process-local: browser-only, each entry keyed by the document whose writes it holds\nfunction rooms(): Rooms {\n const host = globalThis as RoomsHost;\n return (host[ROOMS] ??= { live: new WeakMap(), left: new WeakMap() });\n}\n\n/**\n * The attributed writes Keryx has not acknowledged for `doc`, oldest first: its room's, or what a\n * destroyed room left for the next. What a room's local copy keeps of them.\n */\nexport function unconfirmedAttributedWritesOf(doc: object): readonly AttributedWrites[] {\n const { live, left } = rooms();\n return live.get(doc)?.pending ?? left.get(doc)?.map(copyOf) ?? [];\n}\n\n/**\n * Hands `doc`'s room attributed writes an earlier session kept (the room's local copy), or keeps\n * them for the next tracker made for it. They are older than anything written since, so they go\n * out first.\n */\nexport function restoreUnconfirmedAttributedWrites({\n doc,\n writes,\n}: {\n doc: object;\n writes: readonly AttributedWrites[];\n}): void {\n if (writes.length === 0) return;\n const { live, left } = rooms();\n const room = live.get(doc);\n if (room) {\n room.restore(writes);\n return;\n }\n left.set(doc, bounded([...writes.map(copyOf), ...(left.get(doc) ?? [])]));\n}\n\n/**\n * The two above, as a page hands them to its local copies (`@athenaintel/local-copy`'s\n * `openLocalCopyStore({ attributedWrites })`, `createLocalCopiesPage({ attributedWrites })`): the\n * copy records a room's kept writes with its edits and restores an ended session's to its room.\n */\nexport const roomAttributedWrites = {\n of: unconfirmedAttributedWritesOf,\n restore: restoreUnconfirmedAttributedWrites,\n};\n\n/**\n * One room's attributed writes Keryx has not acknowledged (see the module comment). Made once per\n * room by its transport, which hands it to every socket it opens (`attributingWebSocket`'s\n * `unconfirmed`) and destroys it with the room; a tracker made for the same document later takes\n * over what it still kept, and what its local copy kept from an earlier session\n * ({@link restoreUnconfirmedAttributedWrites}). Not for a room that only listens: its socket sends\n * nothing to split.\n */\nexport class UnconfirmedUpdateAttributions implements UnconfirmedAttributedWrites, KeptWrites {\n private runs: AttributedWrites[];\n private readonly doc: Doc;\n private readonly attributionsFor: () => readonly UpdateAttribution[] | undefined;\n private readonly isRemoteOrigin: (origin: unknown) => boolean;\n\n constructor({\n doc,\n attributionsFor,\n isRemoteOrigin,\n }: {\n doc: Doc;\n /** The attributions of the update being written now: what the socket's trailer reads. */\n attributionsFor: () => readonly UpdateAttribution[] | undefined;\n /** True for a transaction the transport applied (Keryx's state, a peer's edit). */\n isRemoteOrigin: (origin: unknown) => boolean;\n }) {\n this.doc = doc;\n this.attributionsFor = attributionsFor;\n this.isRemoteOrigin = isRemoteOrigin;\n const { live, left } = rooms();\n this.runs = left.get(doc) ?? [];\n left.delete(doc);\n live.set(doc, this);\n doc.on('update', this.handleUpdate);\n }\n\n private readonly handleUpdate = (update: Uint8Array, origin: unknown): void => {\n if (this.isRemoteOrigin(origin)) return;\n const attributions = this.attributionsFor();\n if (!attributions || attributions.length === 0) return;\n const ids = idsOf(update);\n if (!ids || noIds(ids)) return;\n const last = this.runs.at(-1);\n if (last && sameAttributions(last.attributions, attributions)) {\n last.ids = mergeContentIds([last.ids, ids]);\n return;\n }\n this.runs = bounded([...this.runs, copyOf({ ids, attributions })]);\n };\n\n /** The attributed writes Keryx has not acknowledged, oldest first. */\n get pending(): readonly AttributedWrites[] {\n return this.runs.map(copyOf);\n }\n\n /** Writes an earlier session kept, older than any written here: they go out first. */\n restore(writes: readonly AttributedWrites[]): void {\n this.runs = bounded([...writes.map(copyOf), ...this.runs]);\n }\n\n /**\n * One socket of the room. While the room keeps writes, the socket's sync step 2 (its answer to\n * Keryx's sync step 1) waits for the next frame Keryx sends, its whole document, which drops what\n * Keryx already holds before the answer is split (see the module comment); every frame sent\n * meanwhile waits behind it, in order. Nothing kept, or a socket that cannot hear Keryx: every\n * frame goes out as it is sent.\n */\n connect({\n send,\n hears,\n }: {\n send: (frame: Uint8Array) => void;\n hears: boolean;\n }): AttributedWritesSocket {\n let held: Uint8Array[] | null = null;\n const sendNow = (frame: Uint8Array) => {\n for (const out of this.framesFor(frame)) send(out);\n };\n return {\n received: (frame) => {\n this.received(frame);\n if (held === null) return;\n const waiting = held;\n held = null;\n for (const next of waiting) sendNow(next);\n },\n send: (frame) => {\n if (held !== null) {\n held.push(frame);\n return;\n }\n if (hears && this.runs.length > 0 && readSyncFrame(frame)?.syncType === SYNC_STEP_2) {\n held = [frame];\n return;\n }\n sendNow(frame);\n },\n };\n }\n\n /** Keryx sent `frame`: the ids it carries are Keryx's, kept no longer. */\n received(frame: Uint8Array): void {\n if (this.runs.length === 0) return;\n const message = readSyncFrame(frame);\n if (message === null) return;\n if (message.syncType !== SYNC_STEP_2 && message.syncType !== SYNC_UPDATE) return;\n const held = idsOf(message.payload);\n if (!held) return;\n this.runs = this.runs\n .map(({ ids, attributions }) => ({ ids: excludeContentIds(ids, held), attributions }))\n .filter((run) => !noIds(run.ids));\n }\n\n /**\n * What goes out in place of `frame`: `[frame]` itself, except a sync step 2 carrying kept writes,\n * which goes out behind each of them as its own marked sync update.\n */\n framesFor(frame: Uint8Array): readonly Uint8Array[] {\n if (this.runs.length === 0) return [frame];\n const message = readSyncFrame(frame);\n if (message === null || message.syncType !== SYNC_STEP_2) return [frame];\n const answer = message.payload;\n const all = idsOf(answer);\n if (!all) return [frame];\n const frames: Uint8Array[] = [];\n const marked: ContentIds[] = [];\n for (const run of this.runs) {\n const part = intersectContentIds(run.ids, all);\n if (noIds(part)) continue;\n frames.push(\n withUpdateAttributionsTrailer({\n message: syncFrame({\n syncType: SYNC_UPDATE,\n payload: intersectUpdateWithContentIds(answer, part),\n }),\n attributions: run.attributions,\n })\n );\n marked.push(part);\n }\n if (marked.length === 0) return [frame];\n const rest = excludeContentIds(all, mergeContentIds(marked));\n frames.push(\n syncFrame({ syncType: SYNC_STEP_2, payload: intersectUpdateWithContentIds(answer, rest) })\n );\n return frames;\n }\n\n /** Stops keeping; what is still kept waits for the next tracker made for the document. */\n destroy(): void {\n this.doc.off('update', this.handleUpdate);\n const { live, left } = rooms();\n if (live.get(this.doc) === this) live.delete(this.doc);\n if (this.runs.length > 0) left.set(this.doc, this.runs);\n this.runs = [];\n }\n}\n"],"names":["readVarUint","writeVarUint","createContentIdsFromUpdate","mergeContentIds","excludeContentIds","intersectContentIds","withUpdateAttributionsTrailer","intersectUpdateWithContentIds"],"mappings":";;;;;;;AAgEA,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,cAAc;AAYb,MAAM,sBAAsB;AAEnC,SAAS,MAAM,KAA0B;AACvC,SAAO,IAAI,QAAQ,QAAA,KAAa,IAAI,QAAQ,QAAA;AAC9C;AAEA,SAAS,iBACP,GACA,GACS;AACT,SACE,EAAE,WAAW,EAAE,UACf,EAAE,MAAM,CAAC,MAAM,UAAA;;AAAU,gBAAK,QAAM,OAAE,KAAK,MAAP,mBAAU,MAAK,KAAK,QAAM,OAAE,KAAK,MAAP,mBAAU;AAAA,GAAC;AAE7E;AAGA,SAAS,cAAc,OAAqE;AAC1F,QAAM,OAAOA,mBAAAA,YAAY,EAAE,OAAO,OAAO,OAAO,GAAG;AACnD,OAAI,6BAAM,WAAU,aAAc,QAAO;AACzC,QAAM,WAAWA,mBAAAA,YAAY,EAAE,OAAO,OAAO,OAAO,KAAK,MAAM;AAC/D,MAAI,aAAa,KAAM,QAAO;AAC9B,QAAM,SAASA,mBAAAA,YAAY,EAAE,OAAO,OAAO,OAAO,SAAS,MAAM;AACjE,MAAI,WAAW,QAAQ,OAAO,OAAO,OAAO,UAAU,MAAM,OAAQ,QAAO;AAC3E,SAAO,EAAE,UAAU,SAAS,OAAO,SAAS,MAAM,SAAS,OAAO,IAAI,EAAA;AACxE;AAGA,SAAS,UAAU,EAAE,UAAU,WAAkE;AAC/F,QAAM,OAAiB,CAAA;AACvBC,qBAAAA,aAAa,EAAE,KAAK,MAAM,OAAO,cAAc;AAC/CA,qBAAAA,aAAa,EAAE,KAAK,MAAM,OAAO,UAAU;AAC3CA,qBAAAA,aAAa,EAAE,KAAK,MAAM,OAAO,QAAQ,QAAQ;AAC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,EAAA,CAAG;AAAA,IAAA;AAE3F,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,UAAgB;AACd,SAAK,IAAI,IAAI,UAAU,KAAK,YAAY;AACxC,UAAM,EAAE,MAAM,KAAA,IAAS,MAAA;AACvB,QAAI,KAAK,IAAI,KAAK,GAAG,MAAM,KAAM,MAAK,OAAO,KAAK,GAAG;AACrD,QAAI,KAAK,KAAK,SAAS,QAAQ,IAAI,KAAK,KAAK,KAAK,IAAI;AACtD,SAAK,OAAO,CAAA;AAAA,EACd;AACF;;;"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * The attributed writes a room has not seen Keryx acknowledge, kept so that a write made while the
3
+ * room's socket is closed still reaches Keryx with its attributions.
4
+ *
5
+ * A write made inside `runWithDocUpdateAttributions` leaves as its own sync update followed by the
6
+ * attributions trailer (`attributingWebSocket`), but only if the room's socket is open as it is
7
+ * made. One made while it is closed (offline, reconnecting, before the first connection) reaches
8
+ * Keryx inside the reconnect's sync step 2: the client's answer to Keryx's sync step 1, everything
9
+ * it holds that Keryx lacks. Keryx reads no trailer after a sync step 2, so it would count the
10
+ * write as the person's edit.
11
+ *
12
+ * So the room keeps the content ids of every write made in a scope, with the scope's attributions,
13
+ * until Keryx sends those ids back: the echo of the update that carried them, or the whole document
14
+ * Keryx sends when a socket opens (`received`; `@y/websocket` confirms its own unconfirmed updates
15
+ * the same way). When the socket sends a sync step 2, each kept write's part of it goes out first,
16
+ * oldest first, as its own sync update with its trailer, and the sync step 2 follows without those
17
+ * ids (`framesFor`). The parts are cut from the sync step 2 itself, which already holds only what
18
+ * Keryx lacks past its state vector. One socket keeps the order, so Keryx appends each marked update
19
+ * before the person's sync step 2.
20
+ *
21
+ * That answer waits for Keryx's document (`connect`). Keryx sends its sync step 1 and, in the same
22
+ * cork, its whole document, but `@y/websocket` answers the sync step 1 as it arrives. A kept write
23
+ * Keryx already appended (its echo lost with the socket) is still kept then, and the sync step 2
24
+ * holds the client's whole delete set, so its deletes would go out again as a marked update, which
25
+ * Keryx appends: it drops what it holds from the first sync step 2 only. Held until the next frame,
26
+ * the answer is split once Keryx's document has dropped what it holds.
27
+ *
28
+ * What Keryx records (`patches/@y%2Fhub@0.10.1.patch`):
29
+ * - An update's content map attributes every id it carries, inserts and deletes, read from its
30
+ * bytes: an update that cannot integrate yet (an item next to one the person typed offline, the
31
+ * next clocks of the person's own client) is attributed like any other. Peers hold it until the
32
+ * sync step 2 behind it brings what it needs.
33
+ * - An id is attributed by the first stream entry that carries it (`getDoc`'s `excludeContentMap`),
34
+ * so a later copy changes no merged history. The live change notices read each entry's own
35
+ * content map, though (keryx/src/doc-watcher.ts), and the first sync step 2's strip of what Keryx
36
+ * holds reads the known ids when the frame arrives, possibly before the update ahead of it is in
37
+ * the stream (one whose content map the compute pool builds). A copy inside the sync step 2
38
+ * would then be announced as the person's: the sync step 2 never carries a kept write's ids.
39
+ *
40
+ * Bounded: consecutive writes of one scope merge into one run, and past
41
+ * {@link MAX_ATTRIBUTED_RUNS} runs the oldest is let go (its content then reaches Keryx in a sync
42
+ * step 2, as the person's). A room's local copy keeps them across sessions
43
+ * ({@link unconfirmedAttributedWritesOf}, {@link restoreUnconfirmedAttributedWrites}); without one,
44
+ * a write the room kept is forgotten with the page.
45
+ */
46
+ import { type ContentIds, type Doc } from '@y/y';
47
+ import { type AttributedWritesSocket, type UnconfirmedAttributedWrites, type UpdateAttribution } from './update-attributions.js';
48
+ /** Writes made in one attribution scope, by the content ids they wrote (inserts and deletes). */
49
+ export interface AttributedWrites {
50
+ ids: ContentIds;
51
+ attributions: readonly UpdateAttribution[];
52
+ }
53
+ /**
54
+ * The most runs a room keeps; a run is one scope's writes since a write of another scope. Housekeeping
55
+ * all shares one scope, so runs pile up only as Quick Edit steps interleave with it.
56
+ */
57
+ export declare const MAX_ATTRIBUTED_RUNS = 64;
58
+ /** What a page reads of a room's tracker, whichever copy of this module made it. */
59
+ interface KeptWrites {
60
+ readonly pending: readonly AttributedWrites[];
61
+ restore(writes: readonly AttributedWrites[]): void;
62
+ }
63
+ /**
64
+ * The attributed writes Keryx has not acknowledged for `doc`, oldest first: its room's, or what a
65
+ * destroyed room left for the next. What a room's local copy keeps of them.
66
+ */
67
+ export declare function unconfirmedAttributedWritesOf(doc: object): readonly AttributedWrites[];
68
+ /**
69
+ * Hands `doc`'s room attributed writes an earlier session kept (the room's local copy), or keeps
70
+ * them for the next tracker made for it. They are older than anything written since, so they go
71
+ * out first.
72
+ */
73
+ export declare function restoreUnconfirmedAttributedWrites({ doc, writes, }: {
74
+ doc: object;
75
+ writes: readonly AttributedWrites[];
76
+ }): void;
77
+ /**
78
+ * The two above, as a page hands them to its local copies (`@athenaintel/local-copy`'s
79
+ * `openLocalCopyStore({ attributedWrites })`, `createLocalCopiesPage({ attributedWrites })`): the
80
+ * copy records a room's kept writes with its edits and restores an ended session's to its room.
81
+ */
82
+ export declare const roomAttributedWrites: {
83
+ of: typeof unconfirmedAttributedWritesOf;
84
+ restore: typeof restoreUnconfirmedAttributedWrites;
85
+ };
86
+ /**
87
+ * One room's attributed writes Keryx has not acknowledged (see the module comment). Made once per
88
+ * room by its transport, which hands it to every socket it opens (`attributingWebSocket`'s
89
+ * `unconfirmed`) and destroys it with the room; a tracker made for the same document later takes
90
+ * over what it still kept, and what its local copy kept from an earlier session
91
+ * ({@link restoreUnconfirmedAttributedWrites}). Not for a room that only listens: its socket sends
92
+ * nothing to split.
93
+ */
94
+ export declare class UnconfirmedUpdateAttributions implements UnconfirmedAttributedWrites, KeptWrites {
95
+ private runs;
96
+ private readonly doc;
97
+ private readonly attributionsFor;
98
+ private readonly isRemoteOrigin;
99
+ constructor({ doc, attributionsFor, isRemoteOrigin, }: {
100
+ doc: Doc;
101
+ /** The attributions of the update being written now: what the socket's trailer reads. */
102
+ attributionsFor: () => readonly UpdateAttribution[] | undefined;
103
+ /** True for a transaction the transport applied (Keryx's state, a peer's edit). */
104
+ isRemoteOrigin: (origin: unknown) => boolean;
105
+ });
106
+ private readonly handleUpdate;
107
+ /** The attributed writes Keryx has not acknowledged, oldest first. */
108
+ get pending(): readonly AttributedWrites[];
109
+ /** Writes an earlier session kept, older than any written here: they go out first. */
110
+ restore(writes: readonly AttributedWrites[]): void;
111
+ /**
112
+ * One socket of the room. While the room keeps writes, the socket's sync step 2 (its answer to
113
+ * Keryx's sync step 1) waits for the next frame Keryx sends, its whole document, which drops what
114
+ * Keryx already holds before the answer is split (see the module comment); every frame sent
115
+ * meanwhile waits behind it, in order. Nothing kept, or a socket that cannot hear Keryx: every
116
+ * frame goes out as it is sent.
117
+ */
118
+ connect({ send, hears, }: {
119
+ send: (frame: Uint8Array) => void;
120
+ hears: boolean;
121
+ }): AttributedWritesSocket;
122
+ /** Keryx sent `frame`: the ids it carries are Keryx's, kept no longer. */
123
+ received(frame: Uint8Array): void;
124
+ /**
125
+ * What goes out in place of `frame`: `[frame]` itself, except a sync step 2 carrying kept writes,
126
+ * which goes out behind each of them as its own marked sync update.
127
+ */
128
+ framesFor(frame: Uint8Array): readonly Uint8Array[];
129
+ /** Stops keeping; what is still kept waits for the next tracker made for the document. */
130
+ destroy(): void;
131
+ }
132
+ export {};