@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,698 +0,0 @@
1
- import {
2
- renderByline
3
- } from "./chunk-HOOPZ7EM.mjs";
4
- import {
5
- TranscriptionCapabilities
6
- } from "./chunk-Q5OC3WVG.mjs";
7
-
8
- // src/components/TranscriptContainer.tsx
9
- import React2 from "react";
10
- import { Obj } from "@dxos/echo";
11
- import { useMembers, useQueue } from "@dxos/react-client/echo";
12
- import { Layout } from "@dxos/react-ui-mosaic";
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
- var useTranscriber = ({ audioStreamTrack, recorderConfig, transcriberConfig, onSegments }) => {
386
- const [getTranscriber] = useCapabilities(TranscriptionCapabilities.Transcriber);
387
- const transcriber = useMemo2(() => {
388
- if (!getTranscriber || !audioStreamTrack || !onSegments) {
389
- return void 0;
390
- }
391
- return getTranscriber({
392
- audioStreamTrack,
393
- recorderConfig,
394
- transcriberConfig,
395
- onSegments
396
- });
397
- }, [
398
- getTranscriber,
399
- audioStreamTrack,
400
- recorderConfig,
401
- transcriberConfig,
402
- onSegments
403
- ]);
404
- useEffect4(() => {
405
- return () => {
406
- void transcriber?.close();
407
- };
408
- }, [
409
- transcriber
410
- ]);
411
- return transcriber;
412
- };
413
-
414
- // src/hooks/useVoiceInput.ts
415
- import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
416
- import { scheduleMicroTask } from "@dxos/async";
417
- import { Context as Context2 } from "@dxos/context";
418
- import { log as log3 } from "@dxos/log";
419
- import { useSoundEffect } from "@dxos/react-ui-sfx";
420
- var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useVoiceInput.ts";
421
- var useVoiceInput = ({ active, onUpdate }) => {
422
- const soundStart = useSoundEffect("StartRecording");
423
- const soundStop = useSoundEffect("StopRecording");
424
- const handleSegments = useCallback(async (segments) => {
425
- const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, "")).join(" ");
426
- onUpdate(text);
427
- }, []);
428
- const [recording, setRecording] = useState4(false);
429
- const track = useAudioTrack(active);
430
- const transcriber = useTranscriber({
431
- audioStreamTrack: track,
432
- onSegments: handleSegments
433
- });
434
- useEffect5(() => {
435
- const ctx = new Context2(void 0, {
436
- F: __dxlog_file3,
437
- L: 44
438
- });
439
- scheduleMicroTask(ctx, async () => {
440
- if (active && transcriber) {
441
- await transcriber.open();
442
- log3.info("starting...", void 0, {
443
- F: __dxlog_file3,
444
- L: 48,
445
- S: void 0,
446
- C: (f, a) => f(...a)
447
- });
448
- setRecording(true);
449
- void soundStart.play();
450
- transcriber.startChunksRecording();
451
- } else if (!active && transcriber?.isOpen) {
452
- transcriber?.stopChunksRecording();
453
- await transcriber?.close();
454
- log3.info("stopped", void 0, {
455
- F: __dxlog_file3,
456
- L: 55,
457
- S: void 0,
458
- C: (f, a) => f(...a)
459
- });
460
- setRecording(false);
461
- void soundStop.play();
462
- }
463
- });
464
- return () => {
465
- void ctx.dispose();
466
- };
467
- }, [
468
- active,
469
- transcriber
470
- ]);
471
- return {
472
- recording
473
- };
474
- };
475
-
476
- // src/components/Transcript/Transcript.tsx
477
- import React from "react";
478
- import { useThemeContext } from "@dxos/react-ui";
479
- import { useTextEditor } from "@dxos/react-ui-editor";
480
- import { autoScroll, createBasicExtensions, createMarkdownExtensions, createThemeExtensions, decorateMarkdown, editorSlots, preview } from "@dxos/ui-editor";
481
- import { mx } from "@dxos/ui-theme";
482
- import { isTruthy } from "@dxos/util";
483
-
484
- // src/components/Transcript/transcript-extension.ts
485
- import { RangeSetBuilder } from "@codemirror/state";
486
- import { EditorView, GutterMarker, ViewPlugin, gutter } from "@codemirror/view";
487
- import { format } from "date-fns/format";
488
- import { intervalToDuration } from "date-fns/intervalToDuration";
489
- import { addEventListener, combine } from "@dxos/async";
490
- var transcript = ({ model, started }) => {
491
- return [
492
- // Show timestamps in the gutter.
493
- gutter({
494
- class: "cm-timestamp-gutter",
495
- lineMarkerChange: (update) => update.docChanged || update.viewportChanged,
496
- markers: (view) => {
497
- const start = getStartTime(started, model.chunks[0]);
498
- const builder = new RangeSetBuilder();
499
- for (const { from, to } of view.visibleRanges) {
500
- let line = view.state.doc.lineAt(from);
501
- while (line.from <= to) {
502
- const block = model.getChunkAtLine(line.number)?.blocks[0];
503
- const timestamp = block?._tag === "transcript" && block.started;
504
- if (timestamp) {
505
- builder.add(line.from, line.from, new TimestampMarker(line.number, new Date(timestamp), start));
506
- }
507
- if (line.to + 1 > view.state.doc.length) {
508
- break;
509
- }
510
- line = view.state.doc.lineAt(line.to + 1);
511
- }
512
- }
513
- return builder.finish();
514
- }
515
- }),
516
- // Listen for model updates.
517
- ViewPlugin.fromClass(class {
518
- _controls;
519
- _cleanup;
520
- _adapter;
521
- _initialized = false;
522
- constructor(view) {
523
- this._adapter = new DocumentAdapter(view);
524
- const scroller = view.scrollDOM;
525
- let isAutoScrolling = false;
526
- let hasScrolled = false;
527
- let timeout;
528
- const scrollToBottom = (smooth = false) => {
529
- scroller.style.scrollBehavior = smooth ? "smooth" : "";
530
- scroller.classList.add("cm-hide-scrollbar");
531
- isAutoScrolling = true;
532
- clearTimeout(timeout);
533
- timeout = setTimeout(() => {
534
- this._controls?.classList.add("opacity-0");
535
- scroller.classList.remove("cm-hide-scrollbar");
536
- isAutoScrolling = false;
537
- }, 500);
538
- view.dispatch({
539
- effects: EditorView.scrollIntoView(view.state.doc.length, {
540
- y: "end"
541
- })
542
- });
543
- };
544
- this._cleanup = combine(addEventListener(view.scrollDOM, "scroll", () => {
545
- if (!isAutoScrolling) {
546
- hasScrolled = true;
547
- this._controls?.classList.remove("opacity-0");
548
- }
549
- }), model.update.on(() => {
550
- const autoScroll2 = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight === 0 || !hasScrolled;
551
- model.sync(this._adapter);
552
- if (autoScroll2) {
553
- scrollToBottom(true);
554
- }
555
- }));
556
- }
557
- update(_update) {
558
- if (!this._initialized) {
559
- this._initialized = true;
560
- setTimeout(() => {
561
- model.sync(this._adapter);
562
- });
563
- }
564
- }
565
- destroy() {
566
- this._controls?.remove();
567
- this._cleanup();
568
- }
569
- }),
570
- EditorView.theme({
571
- ".cm-gutters": {
572
- backgroundColor: "var(--dx-baseSurface)"
573
- },
574
- ".cm-timestamp-gutter": {
575
- width: "6rem",
576
- paddingLeft: "0.5rem",
577
- paddingRight: "1rem"
578
- },
579
- ".cm-timestamp-gutter > .cm-gutterElement > div": {
580
- display: "inline-flex",
581
- textAlign: "right",
582
- padding: "3px"
583
- }
584
- })
585
- ];
586
- };
587
- var TimestampMarker = class extends GutterMarker {
588
- _line;
589
- _timestamp;
590
- _started;
591
- constructor(_line, _timestamp, _started) {
592
- super(), this._line = _line, this._timestamp = _timestamp, this._started = _started;
593
- }
594
- eq(other) {
595
- return this._timestamp === other._timestamp;
596
- }
597
- toDOM(view) {
598
- const el = document.createElement("div");
599
- el.className = "text-sm text-subdued hover:bg-hoverSurface cursor-pointer";
600
- el.textContent = formatTimestamp(this._timestamp, this._started);
601
- el.onclick = () => {
602
- const pos = view.state.doc.line(this._line).from;
603
- view.dispatch({
604
- effects: EditorView.scrollIntoView(pos, {
605
- y: "start"
606
- })
607
- });
608
- };
609
- return el;
610
- }
611
- };
612
- var getStartTime = (started, message) => {
613
- if (started) {
614
- return started;
615
- }
616
- if (message?.blocks[0]?._tag === "transcript" && message.blocks[0].started) {
617
- return new Date(message.blocks[0].started);
618
- }
619
- return void 0;
620
- };
621
- var formatTimestamp = (timestamp, relative) => {
622
- if (relative) {
623
- const pad = (n = 0) => String(n).padStart(2, "0");
624
- const { hours, minutes, seconds } = intervalToDuration({
625
- start: relative,
626
- end: timestamp
627
- });
628
- return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
629
- } else {
630
- return format(timestamp, "HH:mm:ss");
631
- }
632
- };
633
-
634
- // src/components/Transcript/Transcript.tsx
635
- var TranscriptView = ({ classNames, transcript: object, model }) => {
636
- const { themeMode } = useThemeContext();
637
- const { parentRef } = useTextEditor(() => {
638
- return {
639
- extensions: [
640
- createBasicExtensions({
641
- readOnly: true,
642
- lineWrapping: true,
643
- search: true
644
- }),
645
- createMarkdownExtensions(),
646
- createThemeExtensions({
647
- themeMode,
648
- slots: editorSlots
649
- }),
650
- decorateMarkdown(),
651
- preview(),
652
- transcript({
653
- model,
654
- started: object?.started ? new Date(object.started) : void 0
655
- }),
656
- autoScroll()
657
- ].filter(isTruthy)
658
- };
659
- }, [
660
- model
661
- ]);
662
- return /* @__PURE__ */ React.createElement("div", {
663
- ref: parentRef,
664
- className: mx("flex grow overflow-hidden container-max-width", classNames),
665
- "data-popover-collision-boundary": true
666
- });
667
- };
668
-
669
- // src/components/TranscriptContainer.tsx
670
- var TranscriptionContainer = ({ role, subject: transcript2 }) => {
671
- const attendableId = Obj.getDXN(transcript2).toString();
672
- const db = Obj.getDatabase(transcript2);
673
- const members = useMembers(db?.spaceId).map((member) => member.identity);
674
- const queue = useQueue(transcript2.queue.dxn, {
675
- pollInterval: 1e3
676
- });
677
- const model = useQueueModelAdapter(renderByline(members), queue);
678
- return /* @__PURE__ */ React2.createElement(Layout.Main, {
679
- role
680
- }, /* @__PURE__ */ React2.createElement(TranscriptView, {
681
- attendableId,
682
- model,
683
- transcript: transcript2
684
- }));
685
- };
686
- var TranscriptContainer_default = TranscriptionContainer;
687
-
688
- export {
689
- TranscriptView,
690
- useAudioFile,
691
- useAudioTrack,
692
- useQueueModelAdapter,
693
- useTranscriber,
694
- useVoiceInput,
695
- TranscriptionContainer,
696
- TranscriptContainer_default
697
- };
698
- //# sourceMappingURL=chunk-ICM7JRCO.mjs.map