@dxos/plugin-transcription 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446

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 (251) hide show
  1. package/dist/lib/browser/{TranscriptContainer-CXA4ZBHW.mjs → TranscriptContainer-JQ3HFHLQ.mjs} +2 -3
  2. package/dist/lib/browser/app-graph-builder-VDQOVX7P.mjs +191 -0
  3. package/dist/lib/browser/app-graph-builder-VDQOVX7P.mjs.map +7 -0
  4. package/dist/lib/browser/chunk-G4B6CPC2.mjs +253 -0
  5. package/dist/lib/browser/chunk-G4B6CPC2.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-KLD7O5GJ.mjs → chunk-GU2BNYKZ.mjs} +12 -2
  7. package/dist/lib/browser/chunk-GU2BNYKZ.mjs.map +7 -0
  8. package/dist/lib/browser/chunk-K7FOYAXO.mjs +8 -0
  9. package/dist/lib/browser/chunk-K7FOYAXO.mjs.map +7 -0
  10. package/dist/lib/browser/chunk-OGNXNGJB.mjs +73 -0
  11. package/dist/lib/browser/chunk-OGNXNGJB.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-3TKXI6TQ.mjs → chunk-YCZISX63.mjs} +81 -108
  13. package/dist/lib/browser/chunk-YCZISX63.mjs.map +7 -0
  14. package/dist/lib/browser/{chunk-LTIQFX4W.mjs → chunk-YEPT334A.mjs} +1 -1
  15. package/dist/lib/browser/chunk-YEPT334A.mjs.map +7 -0
  16. package/dist/lib/browser/index.mjs +210 -47
  17. package/dist/lib/browser/index.mjs.map +4 -4
  18. package/dist/lib/browser/{intent-resolver-DZ62CJPC.mjs → intent-resolver-4R66ZCKT.mjs} +8 -8
  19. package/dist/lib/browser/intent-resolver-4R66ZCKT.mjs.map +7 -0
  20. package/dist/lib/browser/{meeting-transcription-state-MNA2XROE.mjs → meeting-transcription-state-DLFHQK72.mjs} +4 -4
  21. package/dist/lib/browser/meeting-transcription-state-DLFHQK72.mjs.map +7 -0
  22. package/dist/lib/browser/meta.json +1 -1
  23. package/dist/lib/browser/{react-surface-PUXZNAZL.mjs → react-surface-FQUHU5G7.mjs} +6 -18
  24. package/dist/lib/browser/react-surface-FQUHU5G7.mjs.map +7 -0
  25. package/dist/lib/browser/{transcriber-YWWIV6KP.mjs → transcriber-LGMIWDYI.mjs} +7 -8
  26. package/dist/lib/browser/{transcriber-YWWIV6KP.mjs.map → transcriber-LGMIWDYI.mjs.map} +3 -3
  27. package/dist/lib/browser/types/index.mjs +3 -3
  28. package/dist/lib/node/{TranscriptContainer-SSJVLRM6.cjs → TranscriptContainer-QEYTTT2V.cjs} +7 -8
  29. package/dist/lib/node/TranscriptContainer-QEYTTT2V.cjs.map +7 -0
  30. package/dist/lib/node/app-graph-builder-IFSIVNUR.cjs +200 -0
  31. package/dist/lib/node/app-graph-builder-IFSIVNUR.cjs.map +7 -0
  32. package/dist/lib/node/{chunk-J72PUQ3C.cjs → chunk-3KHUSQNW.cjs} +15 -6
  33. package/dist/lib/node/chunk-3KHUSQNW.cjs.map +7 -0
  34. package/dist/lib/node/{chunk-JUGOXWES.cjs → chunk-CZMLKKWT.cjs} +4 -4
  35. package/dist/lib/node/chunk-CZMLKKWT.cjs.map +7 -0
  36. package/dist/lib/node/{chunk-WKZLGVEJ.cjs → chunk-FCCJALOT.cjs} +83 -111
  37. package/dist/lib/node/chunk-FCCJALOT.cjs.map +7 -0
  38. package/dist/lib/node/{chunk-L27AK6FQ.cjs → chunk-LP4FG423.cjs} +8 -23
  39. package/dist/lib/node/chunk-LP4FG423.cjs.map +7 -0
  40. package/dist/lib/node/{chunk-EJWB53WK.cjs → chunk-P4VVD6ZO.cjs} +34 -24
  41. package/dist/lib/node/chunk-P4VVD6ZO.cjs.map +7 -0
  42. package/dist/lib/node/chunk-UOFHT4GZ.cjs +280 -0
  43. package/dist/lib/node/chunk-UOFHT4GZ.cjs.map +7 -0
  44. package/dist/lib/node/index.cjs +238 -66
  45. package/dist/lib/node/index.cjs.map +4 -4
  46. package/dist/lib/node/{intent-resolver-TRBKI24D.cjs → intent-resolver-WMMCOUEH.cjs} +10 -11
  47. package/dist/lib/node/intent-resolver-WMMCOUEH.cjs.map +7 -0
  48. package/dist/lib/node/{meeting-transcription-state-5XLTMWPA.cjs → meeting-transcription-state-URIYILEQ.cjs} +7 -7
  49. package/dist/lib/node/meeting-transcription-state-URIYILEQ.cjs.map +7 -0
  50. package/dist/lib/node/meta.json +1 -1
  51. package/dist/lib/node/{react-surface-SZAMHCX7.cjs → react-surface-WI2MGWCC.cjs} +10 -20
  52. package/dist/lib/node/react-surface-WI2MGWCC.cjs.map +7 -0
  53. package/dist/lib/node/{transcriber-AFUXFHCR.cjs → transcriber-QG5WPKX4.cjs} +13 -14
  54. package/dist/lib/node/{transcriber-AFUXFHCR.cjs.map → transcriber-QG5WPKX4.cjs.map} +3 -3
  55. package/dist/lib/node/types/index.cjs +8 -8
  56. package/dist/lib/node/types/index.cjs.map +1 -1
  57. package/dist/lib/node-esm/{TranscriptContainer-M53LI2TX.mjs → TranscriptContainer-ZXUCOWGY.mjs} +2 -3
  58. package/dist/lib/node-esm/app-graph-builder-UL6XLIZY.mjs +192 -0
  59. package/dist/lib/node-esm/app-graph-builder-UL6XLIZY.mjs.map +7 -0
  60. package/dist/lib/node-esm/chunk-6X7X2UZF.mjs +254 -0
  61. package/dist/lib/node-esm/chunk-6X7X2UZF.mjs.map +7 -0
  62. package/dist/lib/node-esm/chunk-GIO6J6FE.mjs +74 -0
  63. package/dist/lib/node-esm/chunk-GIO6J6FE.mjs.map +7 -0
  64. package/dist/lib/node-esm/{chunk-QMHMEKB3.mjs → chunk-HKATMD34.mjs} +12 -2
  65. package/dist/lib/node-esm/chunk-HKATMD34.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-J4D2RBBH.mjs +10 -0
  67. package/dist/lib/node-esm/chunk-J4D2RBBH.mjs.map +7 -0
  68. package/dist/lib/node-esm/{chunk-5E2MR5XK.mjs → chunk-PTZHDZ36.mjs} +1 -1
  69. package/dist/lib/node-esm/chunk-PTZHDZ36.mjs.map +7 -0
  70. package/dist/lib/node-esm/{chunk-V5IWBPYO.mjs → chunk-YQYBLFNI.mjs} +81 -108
  71. package/dist/lib/node-esm/chunk-YQYBLFNI.mjs.map +7 -0
  72. package/dist/lib/node-esm/index.mjs +210 -47
  73. package/dist/lib/node-esm/index.mjs.map +4 -4
  74. package/dist/lib/node-esm/{intent-resolver-HFVAL274.mjs → intent-resolver-QN2LO5TX.mjs} +8 -8
  75. package/dist/lib/node-esm/intent-resolver-QN2LO5TX.mjs.map +7 -0
  76. package/dist/lib/node-esm/{meeting-transcription-state-3WOZ52BQ.mjs → meeting-transcription-state-ZYVRAW6Y.mjs} +4 -4
  77. package/dist/lib/node-esm/meeting-transcription-state-ZYVRAW6Y.mjs.map +7 -0
  78. package/dist/lib/node-esm/meta.json +1 -1
  79. package/dist/lib/node-esm/{react-surface-UEJELL7I.mjs → react-surface-PCH6NTVB.mjs} +6 -18
  80. package/dist/lib/node-esm/react-surface-PCH6NTVB.mjs.map +7 -0
  81. package/dist/lib/node-esm/{transcriber-7RJEFPDI.mjs → transcriber-TMPYZ5L4.mjs} +7 -8
  82. package/dist/lib/node-esm/{transcriber-7RJEFPDI.mjs.map → transcriber-TMPYZ5L4.mjs.map} +3 -3
  83. package/dist/lib/node-esm/types/index.mjs +3 -3
  84. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  85. package/dist/types/src/capabilities/app-graph-builder.d.ts +179 -2
  86. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  87. package/dist/types/src/capabilities/capabilities.d.ts +7 -5
  88. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  89. package/dist/types/src/capabilities/index.d.ts +182 -4
  90. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  91. package/dist/types/src/capabilities/intent-resolver.d.ts +2 -2
  92. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  93. package/dist/types/src/capabilities/meeting-transcription-state.d.ts +4 -2
  94. package/dist/types/src/capabilities/meeting-transcription-state.d.ts.map +1 -1
  95. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  96. package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
  97. package/dist/types/src/components/Transcript/Transcript.d.ts +4 -14
  98. package/dist/types/src/components/Transcript/Transcript.d.ts.map +1 -1
  99. package/dist/types/src/components/Transcript/Transcript.stories.d.ts +4 -19
  100. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +1 -1
  101. package/dist/types/src/components/TranscriptContainer.d.ts.map +1 -1
  102. package/dist/types/src/components/index.d.ts +0 -1
  103. package/dist/types/src/components/index.d.ts.map +1 -1
  104. package/dist/types/src/components/transcription.stories.d.ts +3 -6
  105. package/dist/types/src/components/transcription.stories.d.ts.map +1 -1
  106. package/dist/types/src/hooks/index.d.ts +0 -1
  107. package/dist/types/src/hooks/index.d.ts.map +1 -1
  108. package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
  109. package/dist/types/src/hooks/useAudioTrack.d.ts.map +1 -1
  110. package/dist/types/src/hooks/useTranscriber.d.ts +1 -1
  111. package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
  112. package/dist/types/src/hooks/useVoiceInput.d.ts.map +1 -1
  113. package/dist/types/src/transcriber/transcriber.d.ts +2 -2
  114. package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
  115. package/dist/types/src/transcriber/transcriber.test.d.ts +2 -0
  116. package/dist/types/src/transcriber/transcriber.test.d.ts.map +1 -0
  117. package/dist/types/src/transcriber/transcription-manager.d.ts +15 -17
  118. package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
  119. package/dist/types/src/translations.d.ts +18 -3
  120. package/dist/types/src/translations.d.ts.map +1 -1
  121. package/dist/types/src/types/schema.d.ts +40 -26
  122. package/dist/types/src/types/schema.d.ts.map +1 -1
  123. package/dist/types/src/types/types.d.ts +7 -18
  124. package/dist/types/src/types/types.d.ts.map +1 -1
  125. package/dist/types/src/util/array.d.ts.map +1 -1
  126. package/dist/types/src/util/get-time-str.d.ts.map +1 -1
  127. package/dist/types/src/util/index.d.ts +1 -0
  128. package/dist/types/src/util/index.d.ts.map +1 -1
  129. package/dist/types/src/util/monitor-audio-level.d.ts.map +1 -1
  130. package/dist/types/src/util/random-queue-dxn.d.ts +3 -0
  131. package/dist/types/src/util/random-queue-dxn.d.ts.map +1 -0
  132. package/dist/types/tsconfig.tsbuildinfo +1 -1
  133. package/package.json +40 -57
  134. package/src/TranscriptionPlugin.tsx +13 -30
  135. package/src/capabilities/app-graph-builder.ts +111 -192
  136. package/src/capabilities/capabilities.ts +3 -4
  137. package/src/capabilities/index.ts +0 -1
  138. package/src/capabilities/intent-resolver.ts +7 -8
  139. package/src/capabilities/meeting-transcription-state.ts +2 -2
  140. package/src/capabilities/react-surface.tsx +4 -12
  141. package/src/capabilities/transcriber.ts +1 -2
  142. package/src/components/Transcript/Transcript.stories.tsx +43 -201
  143. package/src/components/Transcript/Transcript.tsx +208 -83
  144. package/src/components/TranscriptContainer.tsx +6 -11
  145. package/src/components/index.ts +0 -1
  146. package/src/components/transcription.stories.tsx +65 -164
  147. package/src/hooks/index.ts +0 -1
  148. package/src/hooks/useTranscriber.ts +2 -3
  149. package/src/transcriber/{transcriber.browser.test.ts → transcriber.test.ts} +3 -3
  150. package/src/transcriber/transcriber.ts +11 -20
  151. package/src/transcriber/transcription-manager.ts +58 -67
  152. package/src/translations.ts +0 -2
  153. package/src/types/schema.ts +32 -11
  154. package/src/types/types.ts +9 -19
  155. package/src/util/index.ts +1 -0
  156. package/src/util/random-queue-dxn.ts +9 -0
  157. package/dist/lib/browser/app-graph-builder-REQZ5SC5.mjs +0 -351
  158. package/dist/lib/browser/app-graph-builder-REQZ5SC5.mjs.map +0 -7
  159. package/dist/lib/browser/chunk-3TKXI6TQ.mjs.map +0 -7
  160. package/dist/lib/browser/chunk-JHWEZRWC.mjs +0 -63
  161. package/dist/lib/browser/chunk-JHWEZRWC.mjs.map +0 -7
  162. package/dist/lib/browser/chunk-K2LS2QOM.mjs +0 -720
  163. package/dist/lib/browser/chunk-K2LS2QOM.mjs.map +0 -7
  164. package/dist/lib/browser/chunk-KLD7O5GJ.mjs.map +0 -7
  165. package/dist/lib/browser/chunk-LCTMCTYY.mjs +0 -27
  166. package/dist/lib/browser/chunk-LCTMCTYY.mjs.map +0 -7
  167. package/dist/lib/browser/chunk-LTIQFX4W.mjs.map +0 -7
  168. package/dist/lib/browser/intent-resolver-DZ62CJPC.mjs.map +0 -7
  169. package/dist/lib/browser/meeting-transcription-state-MNA2XROE.mjs.map +0 -7
  170. package/dist/lib/browser/react-surface-PUXZNAZL.mjs.map +0 -7
  171. package/dist/lib/browser/settings-JWDS4J3F.mjs +0 -24
  172. package/dist/lib/browser/settings-JWDS4J3F.mjs.map +0 -7
  173. package/dist/lib/node/TranscriptContainer-SSJVLRM6.cjs.map +0 -7
  174. package/dist/lib/node/app-graph-builder-OAPU4GDH.cjs +0 -352
  175. package/dist/lib/node/app-graph-builder-OAPU4GDH.cjs.map +0 -7
  176. package/dist/lib/node/chunk-EJWB53WK.cjs.map +0 -7
  177. package/dist/lib/node/chunk-EVE3H46F.cjs +0 -737
  178. package/dist/lib/node/chunk-EVE3H46F.cjs.map +0 -7
  179. package/dist/lib/node/chunk-J72PUQ3C.cjs.map +0 -7
  180. package/dist/lib/node/chunk-JUGOXWES.cjs.map +0 -7
  181. package/dist/lib/node/chunk-L27AK6FQ.cjs.map +0 -7
  182. package/dist/lib/node/chunk-WKZLGVEJ.cjs.map +0 -7
  183. package/dist/lib/node/intent-resolver-TRBKI24D.cjs.map +0 -7
  184. package/dist/lib/node/meeting-transcription-state-5XLTMWPA.cjs.map +0 -7
  185. package/dist/lib/node/react-surface-SZAMHCX7.cjs.map +0 -7
  186. package/dist/lib/node/settings-AWWMOSCV.cjs +0 -38
  187. package/dist/lib/node/settings-AWWMOSCV.cjs.map +0 -7
  188. package/dist/lib/node-esm/app-graph-builder-UBP6EOBR.mjs +0 -352
  189. package/dist/lib/node-esm/app-graph-builder-UBP6EOBR.mjs.map +0 -7
  190. package/dist/lib/node-esm/chunk-4KC3E5T4.mjs +0 -721
  191. package/dist/lib/node-esm/chunk-4KC3E5T4.mjs.map +0 -7
  192. package/dist/lib/node-esm/chunk-5E2MR5XK.mjs.map +0 -7
  193. package/dist/lib/node-esm/chunk-MHQP2PAF.mjs +0 -28
  194. package/dist/lib/node-esm/chunk-MHQP2PAF.mjs.map +0 -7
  195. package/dist/lib/node-esm/chunk-QMHMEKB3.mjs.map +0 -7
  196. package/dist/lib/node-esm/chunk-QYG2FOXA.mjs +0 -64
  197. package/dist/lib/node-esm/chunk-QYG2FOXA.mjs.map +0 -7
  198. package/dist/lib/node-esm/chunk-V5IWBPYO.mjs.map +0 -7
  199. package/dist/lib/node-esm/intent-resolver-HFVAL274.mjs.map +0 -7
  200. package/dist/lib/node-esm/meeting-transcription-state-3WOZ52BQ.mjs.map +0 -7
  201. package/dist/lib/node-esm/react-surface-UEJELL7I.mjs.map +0 -7
  202. package/dist/lib/node-esm/settings-QFNFGFJ5.mjs +0 -25
  203. package/dist/lib/node-esm/settings-QFNFGFJ5.mjs.map +0 -7
  204. package/dist/types/src/capabilities/settings.d.ts +0 -4
  205. package/dist/types/src/capabilities/settings.d.ts.map +0 -1
  206. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +0 -27
  207. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +0 -1
  208. package/dist/types/src/components/Transcript/transcript-extension.d.ts +0 -19
  209. package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +0 -1
  210. package/dist/types/src/components/TranscriptionSettings/TranscriptionSettings.d.ts +0 -6
  211. package/dist/types/src/components/TranscriptionSettings/TranscriptionSettings.d.ts.map +0 -1
  212. package/dist/types/src/components/TranscriptionSettings/index.d.ts +0 -2
  213. package/dist/types/src/components/TranscriptionSettings/index.d.ts.map +0 -1
  214. package/dist/types/src/entity-extraction/entity-extraction.d.ts +0 -42
  215. package/dist/types/src/entity-extraction/entity-extraction.d.ts.map +0 -1
  216. package/dist/types/src/entity-extraction/entity-extraction.test.d.ts +0 -2
  217. package/dist/types/src/entity-extraction/entity-extraction.test.d.ts.map +0 -1
  218. package/dist/types/src/entity-extraction/index.d.ts +0 -2
  219. package/dist/types/src/entity-extraction/index.d.ts.map +0 -1
  220. package/dist/types/src/hooks/useQueueModelAdapter.d.ts +0 -7
  221. package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +0 -1
  222. package/dist/types/src/model/index.d.ts +0 -2
  223. package/dist/types/src/model/index.d.ts.map +0 -1
  224. package/dist/types/src/model/model.d.ts +0 -68
  225. package/dist/types/src/model/model.d.ts.map +0 -1
  226. package/dist/types/src/model/model.test.d.ts +0 -2
  227. package/dist/types/src/model/model.test.d.ts.map +0 -1
  228. package/dist/types/src/testing/index.d.ts +0 -2
  229. package/dist/types/src/testing/index.d.ts.map +0 -1
  230. package/dist/types/src/testing/testing.d.ts +0 -40
  231. package/dist/types/src/testing/testing.d.ts.map +0 -1
  232. package/dist/types/src/transcriber/transcriber.browser.test.d.ts +0 -2
  233. package/dist/types/src/transcriber/transcriber.browser.test.d.ts.map +0 -1
  234. package/src/capabilities/settings.ts +0 -20
  235. package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
  236. package/src/components/Transcript/transcript-extension.ts +0 -236
  237. package/src/components/TranscriptionSettings/TranscriptionSettings.tsx +0 -26
  238. package/src/components/TranscriptionSettings/index.ts +0 -5
  239. package/src/entity-extraction/entity-extraction.test.ts +0 -97
  240. package/src/entity-extraction/entity-extraction.ts +0 -149
  241. package/src/entity-extraction/index.ts +0 -5
  242. package/src/entity-extraction/system-prompt.tpl +0 -38
  243. package/src/entity-extraction/types.d.ts +0 -8
  244. package/src/hooks/useQueueModelAdapter.ts +0 -63
  245. package/src/model/index.ts +0 -5
  246. package/src/model/model.test.ts +0 -169
  247. package/src/model/model.ts +0 -229
  248. package/src/testing/index.ts +0 -5
  249. package/src/testing/testing.ts +0 -216
  250. /package/dist/lib/browser/{TranscriptContainer-CXA4ZBHW.mjs.map → TranscriptContainer-JQ3HFHLQ.mjs.map} +0 -0
  251. /package/dist/lib/node-esm/{TranscriptContainer-M53LI2TX.mjs.map → TranscriptContainer-ZXUCOWGY.mjs.map} +0 -0
@@ -1,229 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Text } from '@codemirror/state';
6
- import { type EditorView } from '@codemirror/view';
7
-
8
- import { Event } from '@dxos/async';
9
- import { invariant } from '@dxos/invariant';
10
- import { log } from '@dxos/log';
11
-
12
- export type Chunk = { id: string };
13
-
14
- /**
15
- * Covert block to a set of markdown lines.
16
- */
17
- export type ChunkRenderer<T extends Chunk> = (chunk: T, index: number, debug?: boolean) => string[];
18
-
19
- /**
20
- * Abstract representation of the document model.
21
- */
22
- export interface ChunkDocument {
23
- lineCount(): number;
24
- replaceLines(from: number, remove: number, insert: string[]): void;
25
- }
26
-
27
- /**
28
- * Codemirror document adapter.
29
- */
30
- export class DocumentAdapter implements ChunkDocument {
31
- constructor(private readonly _view: EditorView) {}
32
-
33
- /** The document must always have at least one line. */
34
- lineCount(): number {
35
- return this._view.state.doc.lines - 1;
36
- }
37
-
38
- replaceLines(from: number, remove: number, insert: string[]): void {
39
- log('replaceLines', { count: this._view.state.doc.lines, from, remove, insert });
40
-
41
- const numLines = this._view.state.doc.lines;
42
- const posFrom = this._view.state.doc.line(from).from;
43
- const posTo = remove === 0 ? posFrom : this._view.state.doc.line(Math.min(numLines, from + remove)).from;
44
-
45
- // Don't remove the last line.
46
- let text = insert.join('\n');
47
- if (posTo === this._view.state.doc.length) {
48
- text += '\n';
49
- }
50
-
51
- this._view.dispatch({
52
- changes: { from: posFrom, to: posTo, insert: text },
53
- });
54
- }
55
- }
56
-
57
- type ChunkChange<T extends Chunk> =
58
- | {
59
- type: 'append';
60
- index: number;
61
- chunk: T;
62
- }
63
- | {
64
- type: 'update';
65
- index: number;
66
- chunk: T;
67
- }
68
- | {
69
- type: 'delete';
70
- index: number;
71
- id: string;
72
- };
73
-
74
- /**
75
- * Each Chunk can be converted into a set of lines.
76
- * Chunks can be added, updated or deleted from the Queue.
77
- * A Document is an immutable projection that represents a flat list of lines corresponding to the Queue.
78
- *
79
- * Ideally we would implement a custom virtual Text model for the View, but this currently isn't possible in Codemirror.
80
- * Instead this model tracks changes and syncs them with the ChunkDocument.
81
- */
82
- export class SerializationModel<T extends Chunk> {
83
- /** Ordered set of chunks. */
84
- private readonly _chunks: T[] = [];
85
-
86
- /** Map of chunk IDs to their current line counts. */
87
- private readonly _chunkLineCounts = new Map<string, number>();
88
-
89
- /** Map of line numbers to chunk IDs. */
90
- private readonly _lineToChunk = new Map<number, T>();
91
-
92
- /** Track chunk changes since last sync. */
93
- private readonly _changes: Array<ChunkChange<T>> = [];
94
-
95
- /** Emits when the document is updated. */
96
- public readonly update = new Event<void>();
97
-
98
- constructor(
99
- private readonly _renderer: ChunkRenderer<T>,
100
- initialChunks: T[] = [],
101
- ) {
102
- initialChunks.forEach((chunk) => {
103
- this.appendChunk(chunk);
104
- });
105
- }
106
-
107
- toJSON() {
108
- return {
109
- chunks: this._chunks.length,
110
- changes: this._changes.length,
111
- };
112
- }
113
-
114
- get doc() {
115
- return Text.of([...this._chunks.flatMap((chunk, index) => this._renderer(chunk, index)), '']);
116
- }
117
-
118
- get chunks() {
119
- return this._chunks;
120
- }
121
-
122
- /**
123
- * Get the block ID at the given line number.
124
- */
125
- getChunkAtLine(line: number): T | undefined {
126
- return this._lineToChunk.get(line);
127
- }
128
-
129
- reset(): this {
130
- this._chunks.length = 0;
131
- this._chunkLineCounts.clear();
132
- this._lineToChunk.clear();
133
- this.update.emit();
134
- return this;
135
- }
136
-
137
- appendChunk(chunk: T): this {
138
- const index = this._chunks.length;
139
- this._chunks.push(chunk);
140
- this._changes.push({ type: 'append', index, chunk });
141
- this.update.emit();
142
- return this;
143
- }
144
-
145
- updateChunk(chunk: T): this {
146
- const index = this._chunks.findIndex((c) => c.id === chunk.id);
147
- invariant(index !== -1);
148
- this._chunks[index] = chunk;
149
- this._changes.push({ type: 'update', index, chunk });
150
- this.update.emit();
151
- return this;
152
- }
153
-
154
- deleteBlock(id: string): this {
155
- const index = this._chunks.findIndex((c) => c.id === id);
156
- invariant(index !== -1);
157
- this._chunks.splice(index, 1);
158
- this._changes.push({ type: 'delete', index, id });
159
- this.update.emit();
160
- return this;
161
- }
162
-
163
- /**
164
- * Syncs the tracked changes with the ChunkDocument.
165
- */
166
- sync(document: ChunkDocument): this {
167
- log('sync', { changes: this._changes });
168
-
169
- // Process each change in order.
170
- for (const change of this._changes) {
171
- switch (change.type) {
172
- case 'append': {
173
- // For appends, convert block to lines and add at the end.
174
- const lines = this._renderer(change.chunk, change.index);
175
- const lastLine = document.lineCount();
176
- document.replaceLines(lastLine + 1, 0, lines);
177
- break;
178
- }
179
-
180
- case 'update': {
181
- // For updates, find the block's line range and replace with new lines.
182
- let lineStart = 1;
183
- for (let i = 0; i < change.index; i++) {
184
- lineStart += this._chunkLineCounts.get(this._chunks[i].id)!;
185
- }
186
- const previousLineCount = this._chunkLineCounts.get(change.chunk.id)!;
187
- const newLines = this._renderer(change.chunk, change.index);
188
- document.replaceLines(lineStart, previousLineCount, newLines);
189
- break;
190
- }
191
-
192
- case 'delete': {
193
- // For deletes, find the block's line range and remove those lines.
194
- let lineStart = 1;
195
- for (let i = 0; i < change.index; i++) {
196
- lineStart += this._chunkLineCounts.get(this._chunks[i].id)!;
197
- }
198
- const previousLineCount = this._chunkLineCounts.get(change.id)!;
199
- document.replaceLines(lineStart, previousLineCount, []);
200
- break;
201
- }
202
- }
203
- }
204
-
205
- // Clear the line-to-block mapping.
206
- this._lineToChunk.clear();
207
-
208
- // Update all block line counts and line-to-block mapping after processing changes.
209
- let currentLine = 1;
210
- for (const [index, chunk] of this._chunks.entries()) {
211
- const lineCount = this._renderer(chunk, index).length;
212
- this._chunkLineCounts.set(chunk.id, lineCount);
213
- this._lineToChunk.set(currentLine, chunk);
214
- currentLine += lineCount;
215
- }
216
-
217
- // Clean up deleted blocks.
218
- const chunkIds = new Set(this._chunks.map((chunk) => chunk.id));
219
- for (const id of this._chunkLineCounts.keys()) {
220
- if (!chunkIds.has(id)) {
221
- this._chunkLineCounts.delete(id);
222
- }
223
- }
224
-
225
- // Clear changes after sync.
226
- this._changes.length = 0;
227
- return this;
228
- }
229
- }
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './testing';
@@ -1,216 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema, SchemaAST } from 'effect';
6
- import { useEffect, useMemo, useState } from 'react';
7
-
8
- import { AIServiceEdgeClient } from '@dxos/assistant';
9
- import { AI_SERVICE_ENDPOINT } from '@dxos/assistant/testing';
10
- import { scheduleTaskInterval } from '@dxos/async';
11
- import { Filter, type Queue } from '@dxos/client/echo';
12
- import { Context } from '@dxos/context';
13
- import { Type } from '@dxos/echo';
14
- import { create, createQueueDxn, ObjectId } from '@dxos/echo-schema';
15
- import { IdentityDid } from '@dxos/keys';
16
- import { log } from '@dxos/log';
17
- import { faker } from '@dxos/random';
18
- import { live, makeRef, useQueue, type Space } from '@dxos/react-client/echo';
19
- import { DataType } from '@dxos/schema';
20
- import { Testing, seedTestData } from '@dxos/schema/testing';
21
-
22
- import { processTranscriptMessage } from '../entity-extraction';
23
-
24
- // TODO(burdon): Reconcile with plugin-markdown. Move to @dxos/schema/testing.
25
- export const TestItem = Schema.Struct({
26
- title: Schema.String.annotations({
27
- [SchemaAST.TitleAnnotationId]: 'Title',
28
- [SchemaAST.DescriptionAnnotationId]: 'Product title',
29
- }),
30
- description: Schema.String.annotations({
31
- [SchemaAST.TitleAnnotationId]: 'Description',
32
- [SchemaAST.DescriptionAnnotationId]: 'Product description',
33
- }),
34
- }).pipe(
35
- Type.def({
36
- typename: 'dxos.org/type/Test',
37
- version: '0.1.0',
38
- }),
39
- );
40
-
41
- // TODO(wittjosiah): Make builder generic and reuse for all message types.
42
- abstract class AbstractMessageBuilder {
43
- abstract createMessage(numSegments?: number): Promise<DataType.Message>;
44
- }
45
-
46
- /**
47
- * Generator of transcript messages.
48
- */
49
- export class MessageBuilder extends AbstractMessageBuilder {
50
- static readonly singleton = new MessageBuilder();
51
-
52
- users = Array.from({ length: 5 }, () => ({
53
- identityDid: IdentityDid.random().toString(),
54
- name: faker.person.fullName(),
55
- email: faker.internet.email(),
56
- }));
57
-
58
- start = new Date(Date.now() - 24 * 60 * 60 * 10_000);
59
-
60
- constructor(private readonly _space?: Space) {
61
- super();
62
- }
63
-
64
- override async createMessage(numSegments = 1): Promise<DataType.Message> {
65
- return {
66
- id: ObjectId.random().toString(),
67
- created: this.next().toISOString(),
68
- sender: faker.helpers.arrayElement(this.users),
69
- blocks: Array.from({ length: numSegments }).map(() => this.createBlock()),
70
- };
71
- }
72
-
73
- createBlock(): DataType.MessageBlock.Transcription {
74
- let text = faker.lorem.paragraph();
75
- if (this._space) {
76
- const label = faker.commerce.productName();
77
- const obj = this._space.db.add(live(TestItem, { title: label, description: faker.lorem.paragraph() }));
78
- const dxn = makeRef(obj).dxn.toString();
79
- const words = text.split(' ');
80
- words.splice(Math.floor(Math.random() * words.length), 0, `[${label}][${dxn}]`);
81
- text = words.join(' ');
82
- }
83
-
84
- return {
85
- type: 'transcription',
86
- started: this.next().toISOString(),
87
- text,
88
- };
89
- }
90
-
91
- next() {
92
- this.start = new Date(this.start.getTime() + Math.random() * 10_000);
93
- return this.start;
94
- }
95
- }
96
-
97
- // TODO(burdon): Reconcile with BlockBuilder.
98
- class EntityExtractionMessageBuilder extends AbstractMessageBuilder {
99
- aiService = new AIServiceEdgeClient({
100
- endpoint: AI_SERVICE_ENDPOINT.REMOTE,
101
- });
102
-
103
- space: Space | undefined;
104
- currentMessage: number = 0;
105
- transcriptMessages: DataType.Message[] = [];
106
-
107
- async connect(space: Space) {
108
- this.space = space;
109
- const { transcriptMessages } = await seedTestData(space);
110
- this.transcriptMessages = transcriptMessages;
111
- }
112
-
113
- override async createMessage(): Promise<DataType.Message> {
114
- if (!this.space) {
115
- throw new Error('Space not connected');
116
- }
117
-
118
- const { objects } = await this.space.db
119
- .query(
120
- Filter.or(Filter.type(DataType.Person), Filter.type(DataType.Organization), Filter.type(Testing.DocumentType)),
121
- )
122
- .run();
123
-
124
- log.info('context', { objects });
125
- const message = this.transcriptMessages[this.currentMessage];
126
- this.currentMessage++;
127
- this.currentMessage = this.currentMessage % this.transcriptMessages.length;
128
-
129
- const { message: enhancedMessage } = await processTranscriptMessage({
130
- message,
131
- aiService: this.aiService,
132
- context: {
133
- objects,
134
- },
135
- });
136
-
137
- return enhancedMessage;
138
- }
139
- }
140
-
141
- type UseTestTranscriptionQueue = (
142
- space: Space | undefined,
143
- queueId?: ObjectId,
144
- running?: boolean,
145
- interval?: number,
146
- ) => Queue<DataType.Message> | undefined;
147
-
148
- /**
149
- * Test transcriptionqueue.
150
- */
151
- export const useTestTranscriptionQueue: UseTestTranscriptionQueue = (
152
- space: Space | undefined,
153
- queueId?: ObjectId,
154
- running = true,
155
- interval = 1_000,
156
- ) => {
157
- const queueDxn = useMemo(() => (space ? createQueueDxn(space.id, queueId) : undefined), [space, queueId]);
158
- const queue = useQueue<DataType.Message>(queueDxn);
159
- const builder = useMemo(() => new MessageBuilder(space), [space]);
160
-
161
- useEffect(() => {
162
- if (!queue || !running) {
163
- return;
164
- }
165
-
166
- const i = setInterval(() => {
167
- void builder.createMessage(Math.ceil(Math.random() * 3)).then((message) => {
168
- queue.append([create(DataType.Message, message)]);
169
- });
170
- }, interval);
171
- return () => clearInterval(i);
172
- }, [queue, running, interval]);
173
-
174
- return queue;
175
- };
176
-
177
- /**
178
- * Test transcription queue.
179
- */
180
- // TODO(burdon): Reconcile with useTestTranscriptionQueue.
181
- export const useTestTranscriptionQueueWithEntityExtraction: UseTestTranscriptionQueue = (
182
- space: Space | undefined,
183
- queueId?: ObjectId,
184
- running = true,
185
- interval = 1_000,
186
- ) => {
187
- const queueDxn = useMemo(() => (space ? createQueueDxn(space.id, queueId) : undefined), [space, queueId]);
188
- const queue = useQueue<DataType.Message>(queueDxn);
189
- const [builder] = useState(() => new EntityExtractionMessageBuilder());
190
-
191
- useEffect(() => {
192
- if (!queue || !running) {
193
- return;
194
- }
195
-
196
- if (space) {
197
- void builder.connect(space);
198
- }
199
-
200
- const ctx = new Context();
201
- scheduleTaskInterval(
202
- ctx,
203
- async () => {
204
- const message = await builder.createMessage();
205
- queue.append([create(DataType.Message, message)]);
206
- },
207
- interval,
208
- );
209
-
210
- return () => {
211
- void ctx.dispose();
212
- };
213
- }, [space, queue, running, interval]);
214
-
215
- return queue;
216
- };