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