@dxos/plugin-transcription 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (244) hide show
  1. package/dist/lib/browser/blueprints/index.mjs +31 -0
  2. package/dist/lib/browser/blueprints/index.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-5LWSJZTZ.mjs +17 -0
  4. package/dist/lib/browser/chunk-5LWSJZTZ.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-HOOPZ7EM.mjs +35 -0
  6. package/dist/lib/browser/chunk-HOOPZ7EM.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  8. package/dist/lib/browser/chunk-RIUSFL62.mjs +112 -0
  9. package/dist/lib/browser/chunk-RIUSFL62.mjs.map +7 -0
  10. package/dist/lib/browser/create-IZPB7VZW.mjs +19 -0
  11. package/dist/lib/browser/create-IZPB7VZW.mjs.map +7 -0
  12. package/dist/lib/browser/index.mjs +1178 -97
  13. package/dist/lib/browser/index.mjs.map +4 -4
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/open-SN5O5I6X.mjs +29 -0
  16. package/dist/lib/browser/open-SN5O5I6X.mjs.map +7 -0
  17. package/dist/lib/browser/operations/index.mjs +13 -0
  18. package/dist/lib/browser/operations/index.mjs.map +7 -0
  19. package/dist/lib/browser/summarize-5MZENAU5.mjs +71 -0
  20. package/dist/lib/browser/summarize-5MZENAU5.mjs.map +7 -0
  21. package/dist/lib/browser/types/index.mjs +4 -6
  22. package/dist/lib/node-esm/blueprints/index.mjs +32 -0
  23. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  24. package/dist/lib/node-esm/chunk-3GSFEN4L.mjs +113 -0
  25. package/dist/lib/node-esm/chunk-3GSFEN4L.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  27. package/dist/lib/node-esm/chunk-NVM2QUMX.mjs +37 -0
  28. package/dist/lib/node-esm/chunk-NVM2QUMX.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-X74WYCCE.mjs +19 -0
  30. package/dist/lib/node-esm/chunk-X74WYCCE.mjs.map +7 -0
  31. package/dist/lib/node-esm/create-TQDGXQBL.mjs +20 -0
  32. package/dist/lib/node-esm/create-TQDGXQBL.mjs.map +7 -0
  33. package/dist/lib/node-esm/index.mjs +1178 -97
  34. package/dist/lib/node-esm/index.mjs.map +4 -4
  35. package/dist/lib/node-esm/meta.json +1 -1
  36. package/dist/lib/node-esm/open-4GAAWWKJ.mjs +30 -0
  37. package/dist/lib/node-esm/open-4GAAWWKJ.mjs.map +7 -0
  38. package/dist/lib/node-esm/operations/index.mjs +14 -0
  39. package/dist/lib/node-esm/operations/index.mjs.map +7 -0
  40. package/dist/lib/node-esm/summarize-RVOSRHEC.mjs +72 -0
  41. package/dist/lib/node-esm/summarize-RVOSRHEC.mjs.map +7 -0
  42. package/dist/lib/node-esm/types/index.mjs +4 -6
  43. package/dist/types/src/TranscriptionPlugin.d.ts +2 -1
  44. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  45. package/dist/types/src/blueprints/index.d.ts +2 -0
  46. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  47. package/dist/types/src/blueprints/transcription-blueprint.d.ts +4 -0
  48. package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +1 -0
  49. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -4
  50. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
  51. package/dist/types/src/capabilities/index.d.ts +6 -5
  52. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  53. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  54. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  55. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  56. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/transcriber.d.ts +4 -3
  58. package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
  59. package/dist/types/src/components/Transcription/Transcription.d.ts +22 -0
  60. package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -0
  61. package/dist/types/src/components/{Transcript/Transcript.stories.d.ts → Transcription/Transcription.stories.d.ts} +13 -12
  62. package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +1 -0
  63. package/dist/types/src/components/Transcription/index.d.ts +2 -0
  64. package/dist/types/src/components/Transcription/index.d.ts.map +1 -0
  65. package/dist/types/src/components/{Transcript/transcript-extension.d.ts → Transcription/transcription-extension.d.ts} +3 -3
  66. package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +1 -0
  67. package/dist/types/src/components/index.d.ts +1 -3
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/components/stories/FileTranscription.stories.d.ts +3 -3
  70. package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -1
  71. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +2 -2
  72. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -1
  73. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +5 -5
  74. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -1
  75. package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +1 -1
  76. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts +6 -0
  77. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts.map +1 -0
  78. package/dist/types/src/containers/TranscriptionContainer/index.d.ts +2 -0
  79. package/dist/types/src/containers/TranscriptionContainer/index.d.ts.map +1 -0
  80. package/dist/types/src/containers/index.d.ts +3 -0
  81. package/dist/types/src/containers/index.d.ts.map +1 -0
  82. package/dist/types/src/hooks/useQueueModelAdapter.d.ts +1 -1
  83. package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +1 -1
  84. package/dist/types/src/hooks/useTranscriber.d.ts +1 -1
  85. package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
  86. package/dist/types/src/hooks/useVoiceInput.d.ts.map +1 -1
  87. package/dist/types/src/index.d.ts +1 -1
  88. package/dist/types/src/index.d.ts.map +1 -1
  89. package/dist/types/src/meta.d.ts +2 -2
  90. package/dist/types/src/meta.d.ts.map +1 -1
  91. package/dist/types/src/operations/create.d.ts +5 -0
  92. package/dist/types/src/operations/create.d.ts.map +1 -0
  93. package/dist/types/src/operations/definitions.d.ts +905 -0
  94. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  95. package/dist/types/src/operations/index.d.ts +4 -0
  96. package/dist/types/src/operations/index.d.ts.map +1 -0
  97. package/dist/types/src/operations/open.d.ts +5 -0
  98. package/dist/types/src/operations/open.d.ts.map +1 -0
  99. package/dist/types/src/operations/summarize.d.ts +8 -0
  100. package/dist/types/src/operations/summarize.d.ts.map +1 -0
  101. package/dist/types/src/segments-normalization/message-normalizer.d.ts +2 -2
  102. package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +1 -1
  103. package/dist/types/src/segments-normalization/normalization.d.ts +360 -474
  104. package/dist/types/src/segments-normalization/normalization.d.ts.map +1 -1
  105. package/dist/types/src/testing/testing.d.ts +4 -4
  106. package/dist/types/src/testing/testing.d.ts.map +1 -1
  107. package/dist/types/src/transcriber/media-stream-recorder.d.ts +2 -2
  108. package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
  109. package/dist/types/src/transcriber/transcriber.d.ts +2 -2
  110. package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
  111. package/dist/types/src/transcriber/transcription-manager.d.ts +6 -3
  112. package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
  113. package/dist/types/src/translations.d.ts +7 -7
  114. package/dist/types/src/translations.d.ts.map +1 -1
  115. package/dist/types/src/types/capabilities.d.ts +18 -0
  116. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  117. package/dist/types/src/types/index.d.ts +1 -2
  118. package/dist/types/src/types/index.d.ts.map +1 -1
  119. package/dist/types/src/util/index.d.ts +1 -0
  120. package/dist/types/src/util/index.d.ts.map +1 -1
  121. package/dist/types/src/util/render-byline.d.ts +4 -0
  122. package/dist/types/src/util/render-byline.d.ts.map +1 -0
  123. package/dist/types/tsconfig.tsbuildinfo +1 -1
  124. package/package.json +105 -72
  125. package/src/TranscriptionPlugin.tsx +40 -60
  126. package/src/blueprints/index.ts +5 -0
  127. package/src/blueprints/transcription-blueprint.ts +30 -0
  128. package/src/capabilities/blueprint-definition.ts +10 -24
  129. package/src/capabilities/index.ts +9 -7
  130. package/src/capabilities/operation-handler.ts +16 -0
  131. package/src/capabilities/react-surface.tsx +21 -14
  132. package/src/capabilities/transcriber.ts +52 -43
  133. package/src/components/{Transcript/Transcript.stories.tsx → Transcription/Transcription.stories.tsx} +52 -48
  134. package/src/components/Transcription/Transcription.tsx +64 -0
  135. package/src/components/{Transcript → Transcription}/index.ts +1 -1
  136. package/src/components/{Transcript/transcript-extension.ts → Transcription/transcription-extension.ts} +4 -4
  137. package/src/components/index.ts +1 -6
  138. package/src/components/stories/FileTranscription.stories.tsx +26 -33
  139. package/src/components/stories/KeyWordRecognition.stories.tsx +7 -7
  140. package/src/components/stories/MicrophoneTranscription.stories.tsx +50 -72
  141. package/src/components/stories/TranscriptionStory.tsx +7 -8
  142. package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +33 -0
  143. package/src/containers/TranscriptionContainer/index.ts +5 -0
  144. package/src/containers/index.ts +7 -0
  145. package/src/hooks/useQueueModelAdapter.ts +1 -1
  146. package/src/hooks/useTranscriber.ts +3 -2
  147. package/src/hooks/useVoiceInput.ts +2 -3
  148. package/src/index.ts +1 -1
  149. package/src/meta.ts +3 -3
  150. package/src/model/model.test.ts +9 -3
  151. package/src/operations/create.ts +22 -0
  152. package/src/operations/definitions.ts +102 -0
  153. package/src/operations/index.ts +13 -0
  154. package/src/operations/open.ts +31 -0
  155. package/src/{functions → operations}/summarize.ts +41 -47
  156. package/src/segments-normalization/message-normalizer.ts +12 -7
  157. package/src/segments-normalization/normalization.test.ts +2 -7
  158. package/src/segments-normalization/normalization.ts +33 -71
  159. package/src/testing/testing.ts +17 -22
  160. package/src/transcriber/media-stream-recorder.ts +3 -3
  161. package/src/transcriber/transcriber.browser.test.ts +1 -2
  162. package/src/transcriber/transcriber.ts +5 -5
  163. package/src/transcriber/transcription-manager.ts +15 -9
  164. package/src/translations.ts +7 -7
  165. package/src/{capabilities → types}/capabilities.ts +11 -10
  166. package/src/types/index.ts +1 -2
  167. package/src/util/index.ts +1 -0
  168. package/src/util/render-byline.ts +33 -0
  169. package/dist/lib/browser/TranscriptContainer-EKSP5DQ6.mjs +0 -11
  170. package/dist/lib/browser/blueprint-definition-WBWHO4OH.mjs +0 -150
  171. package/dist/lib/browser/blueprint-definition-WBWHO4OH.mjs.map +0 -7
  172. package/dist/lib/browser/chunk-3MKZ2MNQ.mjs +0 -16
  173. package/dist/lib/browser/chunk-3MKZ2MNQ.mjs.map +0 -7
  174. package/dist/lib/browser/chunk-EHT3TE6U.mjs +0 -738
  175. package/dist/lib/browser/chunk-EHT3TE6U.mjs.map +0 -7
  176. package/dist/lib/browser/chunk-OCI42DWB.mjs +0 -8
  177. package/dist/lib/browser/chunk-OCI42DWB.mjs.map +0 -7
  178. package/dist/lib/browser/chunk-PVU4XCKI.mjs +0 -466
  179. package/dist/lib/browser/chunk-PVU4XCKI.mjs.map +0 -7
  180. package/dist/lib/browser/chunk-VBUIO677.mjs +0 -29
  181. package/dist/lib/browser/chunk-VBUIO677.mjs.map +0 -7
  182. package/dist/lib/browser/chunk-W7WKZTM4.mjs +0 -63
  183. package/dist/lib/browser/chunk-W7WKZTM4.mjs.map +0 -7
  184. package/dist/lib/browser/intent-resolver-ZTKTEAQX.mjs +0 -25
  185. package/dist/lib/browser/intent-resolver-ZTKTEAQX.mjs.map +0 -7
  186. package/dist/lib/browser/react-surface-NARMYO2O.mjs +0 -34
  187. package/dist/lib/browser/react-surface-NARMYO2O.mjs.map +0 -7
  188. package/dist/lib/browser/transcriber-E2KAOXPS.mjs +0 -56
  189. package/dist/lib/browser/transcriber-E2KAOXPS.mjs.map +0 -7
  190. package/dist/lib/node-esm/TranscriptContainer-WU3EDQR3.mjs +0 -12
  191. package/dist/lib/node-esm/blueprint-definition-WUHZFRWZ.mjs +0 -151
  192. package/dist/lib/node-esm/blueprint-definition-WUHZFRWZ.mjs.map +0 -7
  193. package/dist/lib/node-esm/chunk-7XASA7DX.mjs +0 -739
  194. package/dist/lib/node-esm/chunk-7XASA7DX.mjs.map +0 -7
  195. package/dist/lib/node-esm/chunk-OLMSTF3M.mjs +0 -64
  196. package/dist/lib/node-esm/chunk-OLMSTF3M.mjs.map +0 -7
  197. package/dist/lib/node-esm/chunk-SWUVPFKR.mjs +0 -17
  198. package/dist/lib/node-esm/chunk-SWUVPFKR.mjs.map +0 -7
  199. package/dist/lib/node-esm/chunk-UVOYXXDJ.mjs +0 -467
  200. package/dist/lib/node-esm/chunk-UVOYXXDJ.mjs.map +0 -7
  201. package/dist/lib/node-esm/chunk-X5BKN32O.mjs +0 -10
  202. package/dist/lib/node-esm/chunk-X5BKN32O.mjs.map +0 -7
  203. package/dist/lib/node-esm/chunk-YVNQN2J6.mjs +0 -30
  204. package/dist/lib/node-esm/chunk-YVNQN2J6.mjs.map +0 -7
  205. package/dist/lib/node-esm/intent-resolver-55WH2GY6.mjs +0 -26
  206. package/dist/lib/node-esm/intent-resolver-55WH2GY6.mjs.map +0 -7
  207. package/dist/lib/node-esm/react-surface-5MQA3IUS.mjs +0 -35
  208. package/dist/lib/node-esm/react-surface-5MQA3IUS.mjs.map +0 -7
  209. package/dist/lib/node-esm/transcriber-ZPJM4U2W.mjs +0 -57
  210. package/dist/lib/node-esm/transcriber-ZPJM4U2W.mjs.map +0 -7
  211. package/dist/types/src/capabilities/capabilities.d.ts +0 -17
  212. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  213. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  214. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  215. package/dist/types/src/components/Transcript/Transcript.d.ts +0 -20
  216. package/dist/types/src/components/Transcript/Transcript.d.ts.map +0 -1
  217. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +0 -1
  218. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +0 -28
  219. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +0 -1
  220. package/dist/types/src/components/Transcript/index.d.ts +0 -2
  221. package/dist/types/src/components/Transcript/index.d.ts.map +0 -1
  222. package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +0 -1
  223. package/dist/types/src/components/TranscriptContainer.d.ts +0 -9
  224. package/dist/types/src/components/TranscriptContainer.d.ts.map +0 -1
  225. package/dist/types/src/functions/index.d.ts +0 -3
  226. package/dist/types/src/functions/index.d.ts.map +0 -1
  227. package/dist/types/src/functions/open.d.ts +0 -7
  228. package/dist/types/src/functions/open.d.ts.map +0 -1
  229. package/dist/types/src/functions/summarize.d.ts +0 -11
  230. package/dist/types/src/functions/summarize.d.ts.map +0 -1
  231. package/dist/types/src/types/Transcript.d.ts +0 -30
  232. package/dist/types/src/types/Transcript.d.ts.map +0 -1
  233. package/dist/types/src/types/TranscriptAction.d.ts +0 -23
  234. package/dist/types/src/types/TranscriptAction.d.ts.map +0 -1
  235. package/src/capabilities/intent-resolver.ts +0 -18
  236. package/src/components/Transcript/Transcript.tsx +0 -94
  237. package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
  238. package/src/components/TranscriptContainer.tsx +0 -37
  239. package/src/functions/index.ts +0 -6
  240. package/src/functions/open.ts +0 -39
  241. package/src/types/Transcript.ts +0 -44
  242. package/src/types/TranscriptAction.ts +0 -24
  243. /package/dist/lib/browser/{TranscriptContainer-EKSP5DQ6.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
  244. /package/dist/lib/node-esm/{TranscriptContainer-WU3EDQR3.mjs.map → chunk-HSLMI22Q.mjs.map} +0 -0
@@ -1,739 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- TranscriptionCapabilities
4
- } from "./chunk-SWUVPFKR.mjs";
5
-
6
- // src/components/TranscriptContainer.tsx
7
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
8
- import React2 from "react";
9
- import { getSpace } from "@dxos/client/echo";
10
- import { Obj } from "@dxos/echo";
11
- import { useMembers, useQueue } from "@dxos/react-client/echo";
12
- import { StackItem } from "@dxos/react-ui-stack";
13
-
14
- // src/hooks/useAudioFile.ts
15
- import { useEffect, useState } from "react";
16
- import { scheduleTask } from "@dxos/async";
17
- import { Context } from "@dxos/context";
18
- import { log } from "@dxos/log";
19
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useAudioFile.ts";
20
- var useAudioFile = (audioUrl, constraints) => {
21
- const [{ audio, stream, track }, setStream] = useState({});
22
- useEffect(() => {
23
- const ctx = new Context(void 0, {
24
- F: __dxlog_file,
25
- L: 20
26
- });
27
- scheduleTask(ctx, async () => {
28
- try {
29
- const response = await fetch(audioUrl);
30
- const blob = await response.blob();
31
- const objectUrl = URL.createObjectURL(blob);
32
- ctx.onDispose(() => {
33
- URL.revokeObjectURL(objectUrl);
34
- });
35
- const audio2 = new Audio();
36
- audio2.src = objectUrl;
37
- await new Promise((resolve, reject) => {
38
- audio2.addEventListener("error", (err) => {
39
- log.error("error", {
40
- err
41
- }, {
42
- F: __dxlog_file,
43
- L: 39,
44
- S: void 0,
45
- C: (f, a) => f(...a)
46
- });
47
- reject(err);
48
- }, {
49
- once: true
50
- });
51
- audio2.addEventListener("canplay", async () => {
52
- resolve();
53
- }, {
54
- once: true
55
- });
56
- audio2.load();
57
- });
58
- const audioCtx = new AudioContext();
59
- if (audioCtx.state === "suspended") {
60
- await audioCtx.resume();
61
- }
62
- const destination = audioCtx.createMediaStreamDestination();
63
- destination.channelCount = 1;
64
- const source = audioCtx.createMediaElementSource(audio2);
65
- source.connect(destination);
66
- const track2 = destination.stream.getAudioTracks()[0];
67
- if (constraints) {
68
- await track2.applyConstraints(constraints).catch((err) => log.catch(err, void 0, {
69
- F: __dxlog_file,
70
- L: 68,
71
- S: void 0,
72
- C: (f, a) => f(...a)
73
- }));
74
- }
75
- setStream({
76
- audio: audio2,
77
- stream: destination.stream,
78
- track: destination.stream.getAudioTracks()[0]
79
- });
80
- } catch (err) {
81
- log.catch(err, void 0, {
82
- F: __dxlog_file,
83
- L: 78,
84
- S: void 0,
85
- C: (f, a) => f(...a)
86
- });
87
- }
88
- });
89
- return () => {
90
- void ctx.dispose();
91
- };
92
- }, [
93
- audioUrl
94
- ]);
95
- return {
96
- audio,
97
- stream,
98
- track
99
- };
100
- };
101
-
102
- // src/hooks/useAudioTrack.ts
103
- import { useEffect as useEffect2, useState as useState2 } from "react";
104
- var useAudioTrack = (active, constraints) => {
105
- const [track, setTrack] = useState2();
106
- useEffect2(() => {
107
- if (!active) {
108
- track?.stop();
109
- setTrack(void 0);
110
- return;
111
- }
112
- const initAudio = async () => {
113
- const audio = new Audio();
114
- audio.srcObject = await navigator.mediaDevices.getUserMedia({
115
- audio: constraints ?? true
116
- });
117
- const [track2] = audio.srcObject.getAudioTracks();
118
- if (track2) {
119
- setTrack(track2);
120
- }
121
- };
122
- if (active) {
123
- void initAudio();
124
- }
125
- }, [
126
- active
127
- ]);
128
- return track;
129
- };
130
-
131
- // src/hooks/useQueueModelAdapter.ts
132
- import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
133
-
134
- // src/model/model.ts
135
- import { Text } from "@codemirror/state";
136
- import { Event } from "@dxos/async";
137
- import { invariant } from "@dxos/invariant";
138
- import { log as log2 } from "@dxos/log";
139
- var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/model/model.ts";
140
- var DocumentAdapter = class {
141
- _view;
142
- constructor(_view) {
143
- this._view = _view;
144
- }
145
- /** The document must always have at least one line. */
146
- lineCount() {
147
- return this._view.state.doc.lines - 1;
148
- }
149
- replaceLines(from, remove, insert) {
150
- log2("replaceLines", {
151
- count: this._view.state.doc.lines,
152
- from,
153
- remove,
154
- insert
155
- }, {
156
- F: __dxlog_file2,
157
- L: 39,
158
- S: this,
159
- C: (f, a) => f(...a)
160
- });
161
- const numLines = this._view.state.doc.lines;
162
- const posFrom = this._view.state.doc.line(from).from;
163
- const posTo = remove === 0 ? posFrom : this._view.state.doc.line(Math.min(numLines, from + remove)).from;
164
- let text = insert.join("\n");
165
- if (posTo === this._view.state.doc.length) {
166
- text += "\n";
167
- }
168
- this._view.dispatch({
169
- changes: {
170
- from: posFrom,
171
- to: posTo,
172
- insert: text
173
- }
174
- });
175
- }
176
- };
177
- var SerializationModel = class {
178
- _renderer;
179
- /** Ordered set of chunks. */
180
- _chunks = [];
181
- /** Map of chunk IDs to their current line counts. */
182
- _chunkLineCounts = /* @__PURE__ */ new Map();
183
- /** Map of line numbers to chunk IDs. */
184
- _lineToChunk = /* @__PURE__ */ new Map();
185
- /** Track chunk changes since last sync. */
186
- _changes = [];
187
- /** Emits when the document is updated. */
188
- update = new Event();
189
- constructor(_renderer, initialChunks = []) {
190
- this._renderer = _renderer;
191
- initialChunks.forEach((chunk) => {
192
- this.appendChunk(chunk);
193
- });
194
- }
195
- toJSON() {
196
- return {
197
- chunks: this._chunks.length,
198
- changes: this._changes.length
199
- };
200
- }
201
- get doc() {
202
- return Text.of([
203
- ...this._chunks.flatMap((chunk, index) => this._renderer(chunk, index)),
204
- ""
205
- ]);
206
- }
207
- get chunks() {
208
- return this._chunks;
209
- }
210
- /**
211
- * Get the block ID at the given line number.
212
- */
213
- getChunkAtLine(line) {
214
- return this._lineToChunk.get(line);
215
- }
216
- reset() {
217
- this._chunks.length = 0;
218
- this._chunkLineCounts.clear();
219
- this._lineToChunk.clear();
220
- this.update.emit();
221
- return this;
222
- }
223
- appendChunk(chunk) {
224
- const index = this._chunks.length;
225
- this._chunks.push(chunk);
226
- this._changes.push({
227
- type: "append",
228
- index,
229
- chunk
230
- });
231
- this.update.emit();
232
- return this;
233
- }
234
- updateChunk(chunk) {
235
- const index = this._chunks.findIndex((c) => c.id === chunk.id);
236
- invariant(index !== -1, void 0, {
237
- F: __dxlog_file2,
238
- L: 147,
239
- S: this,
240
- A: [
241
- "index !== -1",
242
- ""
243
- ]
244
- });
245
- this._chunks[index] = chunk;
246
- this._changes.push({
247
- type: "update",
248
- index,
249
- chunk
250
- });
251
- this.update.emit();
252
- return this;
253
- }
254
- deleteBlock(id) {
255
- const index = this._chunks.findIndex((c) => c.id === id);
256
- invariant(index !== -1, void 0, {
257
- F: __dxlog_file2,
258
- L: 156,
259
- S: this,
260
- A: [
261
- "index !== -1",
262
- ""
263
- ]
264
- });
265
- this._chunks.splice(index, 1);
266
- this._changes.push({
267
- type: "delete",
268
- index,
269
- id
270
- });
271
- this.update.emit();
272
- return this;
273
- }
274
- /**
275
- * Syncs the tracked changes with the ChunkDocument.
276
- */
277
- sync(document2) {
278
- log2("sync", {
279
- changes: this._changes
280
- }, {
281
- F: __dxlog_file2,
282
- L: 167,
283
- S: this,
284
- C: (f, a) => f(...a)
285
- });
286
- for (const change of this._changes) {
287
- switch (change.type) {
288
- case "append": {
289
- const lines = this._renderer(change.chunk, change.index);
290
- const lastLine = document2.lineCount();
291
- document2.replaceLines(lastLine + 1, 0, lines);
292
- break;
293
- }
294
- case "update": {
295
- let lineStart = 1;
296
- for (let i = 0; i < change.index; i++) {
297
- lineStart += this._chunkLineCounts.get(this._chunks[i].id);
298
- }
299
- const previousLineCount = this._chunkLineCounts.get(change.chunk.id);
300
- const newLines = this._renderer(change.chunk, change.index);
301
- document2.replaceLines(lineStart, previousLineCount, newLines);
302
- break;
303
- }
304
- case "delete": {
305
- let lineStart = 1;
306
- for (let i = 0; i < change.index; i++) {
307
- lineStart += this._chunkLineCounts.get(this._chunks[i].id);
308
- }
309
- const previousLineCount = this._chunkLineCounts.get(change.id);
310
- document2.replaceLines(lineStart, previousLineCount, []);
311
- break;
312
- }
313
- }
314
- }
315
- this._lineToChunk.clear();
316
- let currentLine = 1;
317
- for (const [index, chunk] of this._chunks.entries()) {
318
- const lineCount = this._renderer(chunk, index).length;
319
- this._chunkLineCounts.set(chunk.id, lineCount);
320
- this._lineToChunk.set(currentLine, chunk);
321
- currentLine += lineCount;
322
- }
323
- const chunkIds = new Set(this._chunks.map((chunk) => chunk.id));
324
- for (const id of this._chunkLineCounts.keys()) {
325
- if (!chunkIds.has(id)) {
326
- this._chunkLineCounts.delete(id);
327
- }
328
- }
329
- this._changes.length = 0;
330
- return this;
331
- }
332
- };
333
-
334
- // src/hooks/useQueueModelAdapter.ts
335
- var useQueueModelAdapter = (renderer, queue, initialChunks = []) => {
336
- const model = useMemo(() => new SerializationModel(renderer, initialChunks), [
337
- queue
338
- ]);
339
- const [loaded, setLoaded] = useState3(false);
340
- useEffect3(() => {
341
- if (!queue) {
342
- return;
343
- }
344
- const update = () => {
345
- for (const block of queue?.objects ?? []) {
346
- model.appendChunk(block);
347
- }
348
- setLoaded(true);
349
- };
350
- let i;
351
- if (queue.isLoading) {
352
- i = setInterval(() => {
353
- if (!queue?.isLoading) {
354
- clearInterval(i);
355
- update();
356
- }
357
- }, 1e3);
358
- } else {
359
- update();
360
- }
361
- return () => clearTimeout(i);
362
- }, [
363
- model,
364
- queue
365
- ]);
366
- useEffect3(() => {
367
- if (!loaded || !queue || model.chunks.length === queue.objects.length) {
368
- return;
369
- }
370
- const chunk = queue.objects.at(-1);
371
- if (chunk) {
372
- model.appendChunk(chunk);
373
- }
374
- }, [
375
- model,
376
- loaded,
377
- queue?.objects.length
378
- ]);
379
- return model;
380
- };
381
-
382
- // src/hooks/useTranscriber.ts
383
- import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
384
- import { useCapabilities } from "@dxos/app-framework/react";
385
-
386
- // src/capabilities/index.ts
387
- import { lazy } from "@dxos/app-framework";
388
- var BlueprintDefinition = lazy(() => import("./blueprint-definition-WUHZFRWZ.mjs"));
389
- var IntentResolver = lazy(() => import("./intent-resolver-55WH2GY6.mjs"));
390
- var ReactSurface = lazy(() => import("./react-surface-5MQA3IUS.mjs"));
391
- var Transcriber = lazy(() => import("./transcriber-ZPJM4U2W.mjs"));
392
-
393
- // src/hooks/useTranscriber.ts
394
- var useTranscriber = ({ audioStreamTrack, recorderConfig, transcriberConfig, onSegments }) => {
395
- const [getTranscriber] = useCapabilities(TranscriptionCapabilities.Transcriber);
396
- const transcriber = useMemo2(() => {
397
- if (!getTranscriber || !audioStreamTrack || !onSegments) {
398
- return void 0;
399
- }
400
- return getTranscriber({
401
- audioStreamTrack,
402
- recorderConfig,
403
- transcriberConfig,
404
- onSegments
405
- });
406
- }, [
407
- getTranscriber,
408
- audioStreamTrack,
409
- recorderConfig,
410
- transcriberConfig,
411
- onSegments
412
- ]);
413
- useEffect4(() => {
414
- return () => {
415
- void transcriber?.close();
416
- };
417
- }, [
418
- transcriber
419
- ]);
420
- return transcriber;
421
- };
422
-
423
- // src/hooks/useVoiceInput.ts
424
- import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
425
- import { scheduleMicroTask } from "@dxos/async";
426
- import { Context as Context2 } from "@dxos/context";
427
- import { log as log3 } from "@dxos/log";
428
- import { useSoundEffect } from "@dxos/react-ui-sfx";
429
- var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useVoiceInput.ts";
430
- var useVoiceInput = ({ active, onUpdate }) => {
431
- const soundStart = useSoundEffect("StartRecording");
432
- const soundStop = useSoundEffect("StopRecording");
433
- const handleSegments = useCallback(async (segments) => {
434
- const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, "")).join(" ");
435
- onUpdate(text);
436
- }, []);
437
- const [recording, setRecording] = useState4(false);
438
- const track = useAudioTrack(active);
439
- const transcriber = useTranscriber({
440
- audioStreamTrack: track,
441
- onSegments: handleSegments
442
- });
443
- useEffect5(() => {
444
- const ctx = new Context2(void 0, {
445
- F: __dxlog_file3,
446
- L: 44
447
- });
448
- scheduleMicroTask(ctx, async () => {
449
- if (active && transcriber) {
450
- await transcriber.open();
451
- log3.info("starting...", void 0, {
452
- F: __dxlog_file3,
453
- L: 48,
454
- S: void 0,
455
- C: (f, a) => f(...a)
456
- });
457
- setRecording(true);
458
- void soundStart.play();
459
- transcriber.startChunksRecording();
460
- } else if (!active && transcriber?.isOpen) {
461
- transcriber?.stopChunksRecording();
462
- await transcriber?.close();
463
- log3.info("stopped", void 0, {
464
- F: __dxlog_file3,
465
- L: 55,
466
- S: void 0,
467
- C: (f, a) => f(...a)
468
- });
469
- setRecording(false);
470
- void soundStop.play();
471
- }
472
- });
473
- return () => {
474
- void ctx.dispose();
475
- };
476
- }, [
477
- active,
478
- transcriber
479
- ]);
480
- return {
481
- recording
482
- };
483
- };
484
-
485
- // src/components/Transcript/Transcript.tsx
486
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
487
- import React from "react";
488
- import { useThemeContext } from "@dxos/react-ui";
489
- import { autoScroll, createBasicExtensions, createMarkdownExtensions, createThemeExtensions, decorateMarkdown, editorSlots, preview, useTextEditor } from "@dxos/react-ui-editor";
490
- import { mx } from "@dxos/react-ui-theme";
491
- import { isTruthy } from "@dxos/util";
492
-
493
- // src/components/Transcript/transcript-extension.ts
494
- import { RangeSetBuilder } from "@codemirror/state";
495
- import { EditorView, GutterMarker, ViewPlugin, gutter } from "@codemirror/view";
496
- import { format } from "date-fns/format";
497
- import { intervalToDuration } from "date-fns/intervalToDuration";
498
- import { addEventListener, combine } from "@dxos/async";
499
- var transcript = ({ model, started }) => {
500
- return [
501
- // Show timestamps in the gutter.
502
- gutter({
503
- class: "cm-timestamp-gutter",
504
- lineMarkerChange: (update) => update.docChanged || update.viewportChanged,
505
- markers: (view) => {
506
- const start = getStartTime(started, model.chunks[0]);
507
- const builder = new RangeSetBuilder();
508
- for (const { from, to } of view.visibleRanges) {
509
- let line = view.state.doc.lineAt(from);
510
- while (line.from <= to) {
511
- const block = model.getChunkAtLine(line.number)?.blocks[0];
512
- const timestamp = block?._tag === "transcript" && block.started;
513
- if (timestamp) {
514
- builder.add(line.from, line.from, new TimestampMarker(line.number, new Date(timestamp), start));
515
- }
516
- if (line.to + 1 > view.state.doc.length) {
517
- break;
518
- }
519
- line = view.state.doc.lineAt(line.to + 1);
520
- }
521
- }
522
- return builder.finish();
523
- }
524
- }),
525
- // Listen for model updates.
526
- ViewPlugin.fromClass(class {
527
- _controls;
528
- _cleanup;
529
- _adapter;
530
- _initialized = false;
531
- constructor(view) {
532
- this._adapter = new DocumentAdapter(view);
533
- const scroller = view.scrollDOM;
534
- let isAutoScrolling = false;
535
- let hasScrolled = false;
536
- let timeout;
537
- const scrollToBottom = (smooth = false) => {
538
- scroller.style.scrollBehavior = smooth ? "smooth" : "";
539
- scroller.classList.add("cm-hide-scrollbar");
540
- isAutoScrolling = true;
541
- clearTimeout(timeout);
542
- timeout = setTimeout(() => {
543
- this._controls?.classList.add("opacity-0");
544
- scroller.classList.remove("cm-hide-scrollbar");
545
- isAutoScrolling = false;
546
- }, 500);
547
- view.dispatch({
548
- effects: EditorView.scrollIntoView(view.state.doc.length, {
549
- y: "end"
550
- })
551
- });
552
- };
553
- this._cleanup = combine(addEventListener(view.scrollDOM, "scroll", () => {
554
- if (!isAutoScrolling) {
555
- hasScrolled = true;
556
- this._controls?.classList.remove("opacity-0");
557
- }
558
- }), model.update.on(() => {
559
- const autoScroll2 = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight === 0 || !hasScrolled;
560
- model.sync(this._adapter);
561
- if (autoScroll2) {
562
- scrollToBottom(true);
563
- }
564
- }));
565
- }
566
- update(_update) {
567
- if (!this._initialized) {
568
- this._initialized = true;
569
- setTimeout(() => {
570
- model.sync(this._adapter);
571
- });
572
- }
573
- }
574
- destroy() {
575
- this._controls?.remove();
576
- this._cleanup();
577
- }
578
- }),
579
- EditorView.theme({
580
- ".cm-gutters": {
581
- backgroundColor: "var(--dx-baseSurface)"
582
- },
583
- ".cm-timestamp-gutter": {
584
- width: "6rem",
585
- paddingLeft: "0.5rem",
586
- paddingRight: "1rem"
587
- },
588
- ".cm-timestamp-gutter > .cm-gutterElement > div": {
589
- display: "inline-flex",
590
- textAlign: "right",
591
- padding: "3px"
592
- }
593
- })
594
- ];
595
- };
596
- var TimestampMarker = class extends GutterMarker {
597
- _line;
598
- _timestamp;
599
- _started;
600
- constructor(_line, _timestamp, _started) {
601
- super(), this._line = _line, this._timestamp = _timestamp, this._started = _started;
602
- }
603
- eq(other) {
604
- return this._timestamp === other._timestamp;
605
- }
606
- toDOM(view) {
607
- const el = document.createElement("div");
608
- el.className = "text-sm text-subdued hover:bg-hoverSurface cursor-pointer";
609
- el.textContent = formatTimestamp(this._timestamp, this._started);
610
- el.onclick = () => {
611
- const pos = view.state.doc.line(this._line).from;
612
- view.dispatch({
613
- effects: EditorView.scrollIntoView(pos, {
614
- y: "start"
615
- })
616
- });
617
- };
618
- return el;
619
- }
620
- };
621
- var getStartTime = (started, message) => {
622
- if (started) {
623
- return started;
624
- }
625
- if (message?.blocks[0]?._tag === "transcript" && message.blocks[0].started) {
626
- return new Date(message.blocks[0].started);
627
- }
628
- return void 0;
629
- };
630
- var formatTimestamp = (timestamp, relative) => {
631
- if (relative) {
632
- const pad = (n = 0) => String(n).padStart(2, "0");
633
- const { hours, minutes, seconds } = intervalToDuration({
634
- start: relative,
635
- end: timestamp
636
- });
637
- return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
638
- } else {
639
- return format(timestamp, "HH:mm:ss");
640
- }
641
- };
642
-
643
- // src/components/Transcript/Transcript.tsx
644
- var renderByline = (identities) => (message, index, debug = false) => {
645
- if (message.sender.role === "assistant") {
646
- return [
647
- message.blocks.find((block) => block._tag === "transcript")?.text ?? "",
648
- ""
649
- ];
650
- }
651
- const identity = identities.find((identity2) => identity2.did === message.sender.identityDid);
652
- const name = identity?.profile?.displayName ?? message.sender.contact?.target?.fullName ?? message.sender.name ?? message.sender.email ?? message.sender.identityDid;
653
- const blocks = message.blocks.filter((block) => block._tag === "transcript");
654
- return [
655
- // TODO(thure): Use an XML tag with the bits needed here.
656
- `###### ${name}` + (debug ? ` [${index}]:${message.id}` : ""),
657
- blocks.map((block) => block.text.trim()).join(" "),
658
- ""
659
- ];
660
- };
661
- var TranscriptView = ({ classNames, space, transcript: object, model }) => {
662
- var _effect = _useSignals();
663
- try {
664
- const { themeMode } = useThemeContext();
665
- const { parentRef } = useTextEditor(() => {
666
- return {
667
- extensions: [
668
- createBasicExtensions({
669
- readOnly: true,
670
- lineWrapping: true,
671
- search: true
672
- }),
673
- createMarkdownExtensions(),
674
- createThemeExtensions({
675
- themeMode,
676
- slots: editorSlots
677
- }),
678
- decorateMarkdown(),
679
- preview(),
680
- transcript({
681
- model,
682
- started: object?.started ? new Date(object.started) : void 0
683
- }),
684
- autoScroll()
685
- ].filter(isTruthy)
686
- };
687
- }, [
688
- space,
689
- model
690
- ]);
691
- return /* @__PURE__ */ React.createElement("div", {
692
- ref: parentRef,
693
- className: mx("flex grow overflow-hidden container-max-width", classNames),
694
- "data-popover-collision-boundary": true
695
- });
696
- } finally {
697
- _effect.f();
698
- }
699
- };
700
-
701
- // src/components/TranscriptContainer.tsx
702
- var TranscriptionContainer = ({ transcript: transcript2 }) => {
703
- var _effect = _useSignals2();
704
- try {
705
- const attendableId = Obj.getDXN(transcript2).toString();
706
- const space = getSpace(transcript2);
707
- const members = useMembers(space?.key).map((member) => member.identity);
708
- const queue = useQueue(transcript2.queue.dxn, {
709
- pollInterval: 1e3
710
- });
711
- const model = useQueueModelAdapter(renderByline(members), queue);
712
- return /* @__PURE__ */ React2.createElement(StackItem.Content, null, /* @__PURE__ */ React2.createElement(TranscriptView, {
713
- attendableId,
714
- space,
715
- model,
716
- transcript: transcript2
717
- }));
718
- } finally {
719
- _effect.f();
720
- }
721
- };
722
- var TranscriptContainer_default = TranscriptionContainer;
723
-
724
- export {
725
- renderByline,
726
- TranscriptView,
727
- useAudioFile,
728
- useAudioTrack,
729
- useQueueModelAdapter,
730
- useTranscriber,
731
- useVoiceInput,
732
- TranscriptionContainer,
733
- TranscriptContainer_default,
734
- BlueprintDefinition,
735
- IntentResolver,
736
- ReactSurface,
737
- Transcriber
738
- };
739
- //# sourceMappingURL=chunk-7XASA7DX.mjs.map