@dxos/plugin-transcription 0.8.4-main.ae835ea → 0.8.4-main.bcb3aa67d6

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