@dxos/plugin-transcription 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3
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.
- package/dist/lib/browser/TranscriptContainer-EKSP5DQ6.mjs +11 -0
- package/dist/lib/browser/{blueprint-definition-QQSGTX5F.mjs → blueprint-definition-WBWHO4OH.mjs} +24 -16
- package/dist/lib/browser/blueprint-definition-WBWHO4OH.mjs.map +7 -0
- package/dist/lib/browser/{chunk-TNEQFHIU.mjs → chunk-3MKZ2MNQ.mjs} +5 -5
- package/dist/lib/browser/chunk-3MKZ2MNQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5I4BMOGE.mjs → chunk-EHT3TE6U.mjs} +129 -174
- package/dist/lib/browser/chunk-EHT3TE6U.mjs.map +7 -0
- package/dist/lib/browser/{chunk-26XDG6GQ.mjs → chunk-OCI42DWB.mjs} +2 -2
- package/dist/lib/browser/{chunk-BA64VLLR.mjs → chunk-PVU4XCKI.mjs} +46 -66
- package/dist/lib/browser/chunk-PVU4XCKI.mjs.map +7 -0
- package/dist/lib/browser/{chunk-3X7HP44M.mjs → chunk-VBUIO677.mjs} +8 -5
- package/dist/lib/browser/chunk-VBUIO677.mjs.map +7 -0
- package/dist/lib/browser/{chunk-HXVGV7T6.mjs → chunk-W7WKZTM4.mjs} +4 -4
- package/dist/lib/browser/chunk-W7WKZTM4.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +13 -14
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-T3EGLS3L.mjs → intent-resolver-ZTKTEAQX.mjs} +5 -5
- package/dist/lib/browser/{intent-resolver-T3EGLS3L.mjs.map → intent-resolver-ZTKTEAQX.mjs.map} +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-QYX74JNG.mjs → react-surface-NARMYO2O.mjs} +8 -8
- package/dist/lib/browser/{react-surface-QYX74JNG.mjs.map → react-surface-NARMYO2O.mjs.map} +1 -1
- package/dist/lib/browser/{transcriber-JOOAQVYV.mjs → transcriber-E2KAOXPS.mjs} +7 -7
- package/dist/lib/browser/{transcriber-JOOAQVYV.mjs.map → transcriber-E2KAOXPS.mjs.map} +1 -1
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node-esm/{TranscriptContainer-BUWK63SI.mjs → TranscriptContainer-WU3EDQR3.mjs} +4 -4
- package/dist/lib/node-esm/{blueprint-definition-4PLCTH5Q.mjs → blueprint-definition-WUHZFRWZ.mjs} +24 -16
- package/dist/lib/node-esm/blueprint-definition-WUHZFRWZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-DT3AOC3E.mjs → chunk-7XASA7DX.mjs} +129 -174
- package/dist/lib/node-esm/chunk-7XASA7DX.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-W72HVQMD.mjs → chunk-OLMSTF3M.mjs} +4 -4
- package/dist/lib/node-esm/chunk-OLMSTF3M.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-3QAIZGMW.mjs → chunk-SWUVPFKR.mjs} +5 -5
- package/dist/lib/node-esm/chunk-SWUVPFKR.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-J5GQ3KGX.mjs → chunk-UVOYXXDJ.mjs} +46 -66
- package/dist/lib/node-esm/chunk-UVOYXXDJ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NWD757KH.mjs → chunk-X5BKN32O.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-QARUDLHN.mjs → chunk-YVNQN2J6.mjs} +8 -5
- package/dist/lib/node-esm/chunk-YVNQN2J6.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +13 -14
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-VDHCUAIO.mjs → intent-resolver-55WH2GY6.mjs} +5 -5
- package/dist/lib/node-esm/{intent-resolver-VDHCUAIO.mjs.map → intent-resolver-55WH2GY6.mjs.map} +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-TM7XOQBR.mjs → react-surface-5MQA3IUS.mjs} +8 -8
- package/dist/lib/node-esm/{react-surface-TM7XOQBR.mjs.map → react-surface-5MQA3IUS.mjs.map} +1 -1
- package/dist/lib/node-esm/{transcriber-QPS55YP2.mjs → transcriber-ZPJM4U2W.mjs} +7 -7
- package/dist/lib/node-esm/{transcriber-QPS55YP2.mjs.map → transcriber-ZPJM4U2W.mjs.map} +1 -1
- package/dist/lib/node-esm/types/index.mjs +2 -2
- package/dist/types/src/TranscriptionPlugin.d.ts +1 -1
- package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
- package/dist/types/src/components/Transcript/Transcript.d.ts +5 -5
- package/dist/types/src/components/Transcript/Transcript.d.ts.map +1 -1
- package/dist/types/src/components/Transcript/Transcript.stories.d.ts +3 -5
- package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +1 -1
- package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +1 -1
- package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +1 -1
- package/dist/types/src/components/Transcript/transcript-extension.d.ts +3 -7
- package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +1 -1
- package/dist/types/src/components/TranscriptContainer.d.ts.map +1 -1
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts +0 -2
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +0 -1
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +0 -2
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/TranscriptionStory.d.ts +3 -3
- package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +1 -1
- package/dist/types/src/functions/open.d.ts +1 -1
- package/dist/types/src/functions/open.d.ts.map +1 -1
- package/dist/types/src/functions/summarize.d.ts +1 -1
- package/dist/types/src/functions/summarize.d.ts.map +1 -1
- package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
- package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/segments-normalization/message-normalizer.d.ts +3 -3
- package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +1 -1
- package/dist/types/src/segments-normalization/normalization.d.ts +32 -17
- package/dist/types/src/segments-normalization/normalization.d.ts.map +1 -1
- package/dist/types/src/segments-normalization/utils.d.ts +2 -2
- package/dist/types/src/segments-normalization/utils.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +6 -6
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/transcriber/transcriber.d.ts +2 -2
- package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
- package/dist/types/src/transcriber/transcription-manager.d.ts +3 -3
- package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
- package/dist/types/src/types/Transcript.d.ts +3 -3
- package/dist/types/src/types/Transcript.d.ts.map +1 -1
- package/dist/types/src/types/TranscriptAction.d.ts +1 -1
- package/dist/types/src/types/TranscriptAction.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +64 -63
- package/src/TranscriptionPlugin.tsx +57 -57
- package/src/capabilities/capabilities.ts +3 -3
- package/src/components/Transcript/Transcript.stories.tsx +28 -24
- package/src/components/Transcript/Transcript.tsx +20 -27
- package/src/components/Transcript/deprecated/OldTranscript.tsx +5 -5
- package/src/components/Transcript/transcript-extension.ts +11 -44
- package/src/components/TranscriptContainer.tsx +8 -7
- package/src/components/stories/FileTranscription.stories.tsx +33 -31
- package/src/components/stories/KeyWordRecognition.stories.tsx +4 -6
- package/src/components/stories/MicrophoneTranscription.stories.tsx +40 -37
- package/src/components/stories/TranscriptionStory.tsx +8 -9
- package/src/functions/open.ts +8 -6
- package/src/functions/summarize.ts +10 -4
- package/src/hooks/useAudioFile.ts +50 -45
- package/src/hooks/useTranscriber.ts +7 -2
- package/src/meta.ts +7 -4
- package/src/model/model.test.ts +11 -11
- package/src/segments-normalization/message-normalizer.ts +6 -6
- package/src/segments-normalization/normalization.test.ts +6 -6
- package/src/segments-normalization/normalization.ts +7 -7
- package/src/segments-normalization/utils.ts +2 -2
- package/src/testing/testing.ts +25 -20
- package/src/transcriber/transcriber.browser.test.ts +3 -3
- package/src/transcriber/transcriber.ts +3 -3
- package/src/transcriber/transcription-manager.ts +6 -6
- package/src/types/Transcript.ts +1 -1
- package/src/types/TranscriptAction.ts +1 -1
- package/dist/lib/browser/TranscriptContainer-OX7OOODC.mjs +0 -11
- package/dist/lib/browser/blueprint-definition-QQSGTX5F.mjs.map +0 -7
- package/dist/lib/browser/chunk-3X7HP44M.mjs.map +0 -7
- package/dist/lib/browser/chunk-5I4BMOGE.mjs.map +0 -7
- package/dist/lib/browser/chunk-BA64VLLR.mjs.map +0 -7
- package/dist/lib/browser/chunk-HXVGV7T6.mjs.map +0 -7
- package/dist/lib/browser/chunk-TNEQFHIU.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-4PLCTH5Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3QAIZGMW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DT3AOC3E.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-J5GQ3KGX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QARUDLHN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-W72HVQMD.mjs.map +0 -7
- /package/dist/lib/browser/{TranscriptContainer-OX7OOODC.mjs.map → TranscriptContainer-EKSP5DQ6.mjs.map} +0 -0
- /package/dist/lib/browser/{chunk-26XDG6GQ.mjs.map → chunk-OCI42DWB.mjs.map} +0 -0
- /package/dist/lib/node-esm/{TranscriptContainer-BUWK63SI.mjs.map → TranscriptContainer-WU3EDQR3.mjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-NWD757KH.mjs.map → chunk-X5BKN32O.mjs.map} +0 -0
|
@@ -20,58 +20,63 @@ export const useAudioFile = (audioUrl: string, constraints?: MediaTrackConstrain
|
|
|
20
20
|
const ctx = new Context();
|
|
21
21
|
|
|
22
22
|
scheduleTask(ctx, async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
URL.
|
|
28
|
-
|
|
23
|
+
// TODO(wittjosiah): Fetch to external url fails in headless storybook test.
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch(audioUrl);
|
|
26
|
+
const blob = await response.blob();
|
|
27
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
28
|
+
ctx.onDispose(() => {
|
|
29
|
+
URL.revokeObjectURL(objectUrl);
|
|
30
|
+
});
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
const audio = new Audio();
|
|
33
|
+
audio.src = objectUrl;
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
await new Promise<void>((resolve, reject) => {
|
|
36
|
+
audio.addEventListener(
|
|
37
|
+
'error',
|
|
38
|
+
(err) => {
|
|
39
|
+
log.error('error', { err });
|
|
40
|
+
reject(err);
|
|
41
|
+
},
|
|
42
|
+
{ once: true },
|
|
43
|
+
);
|
|
44
|
+
audio.addEventListener(
|
|
45
|
+
'canplay',
|
|
46
|
+
async () => {
|
|
47
|
+
resolve();
|
|
48
|
+
},
|
|
49
|
+
{ once: true },
|
|
50
|
+
);
|
|
51
|
+
audio.load();
|
|
52
|
+
});
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
const audioCtx = new AudioContext();
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
// Resume AudioContext if it's suspended.
|
|
57
|
+
if (audioCtx.state === 'suspended') {
|
|
58
|
+
await audioCtx.resume();
|
|
59
|
+
}
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
const destination = audioCtx.createMediaStreamDestination();
|
|
62
|
+
destination.channelCount = 1;
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
const source = audioCtx.createMediaElementSource(audio);
|
|
65
|
+
source.connect(destination);
|
|
66
|
+
const track = destination.stream.getAudioTracks()[0];
|
|
67
|
+
if (constraints) {
|
|
68
|
+
await track.applyConstraints(constraints).catch((err) => log.catch(err));
|
|
69
|
+
}
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
// Also connect to speakers so audio is audible.
|
|
72
|
+
setStream({
|
|
73
|
+
audio,
|
|
74
|
+
stream: destination.stream,
|
|
75
|
+
track: destination.stream.getAudioTracks()[0],
|
|
76
|
+
});
|
|
77
|
+
} catch (err) {
|
|
78
|
+
log.catch(err);
|
|
79
|
+
}
|
|
75
80
|
});
|
|
76
81
|
|
|
77
82
|
return () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { useEffect, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { useCapabilities } from '@dxos/app-framework';
|
|
7
|
+
import { useCapabilities } from '@dxos/app-framework/react';
|
|
8
8
|
|
|
9
9
|
import { TranscriptionCapabilities } from '../capabilities';
|
|
10
10
|
import { type Transcriber } from '../transcriber';
|
|
@@ -26,7 +26,12 @@ export const useTranscriber = ({
|
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
return getTranscriber({
|
|
29
|
+
return getTranscriber({
|
|
30
|
+
audioStreamTrack,
|
|
31
|
+
recorderConfig,
|
|
32
|
+
transcriberConfig,
|
|
33
|
+
onSegments,
|
|
34
|
+
});
|
|
30
35
|
}, [getTranscriber, audioStreamTrack, recorderConfig, transcriberConfig, onSegments]);
|
|
31
36
|
|
|
32
37
|
useEffect(() => {
|
package/src/meta.ts
CHANGED
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PluginMeta } from '@dxos/app-framework';
|
|
6
|
-
|
|
7
|
-
export const TRANSCRIPTION_PLUGIN = 'dxos.org/plugin/transcription';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
8
7
|
|
|
9
8
|
export const meta: PluginMeta = {
|
|
10
|
-
id:
|
|
9
|
+
id: 'dxos.org/plugin/transcription',
|
|
11
10
|
name: 'Transcription',
|
|
12
|
-
description:
|
|
11
|
+
description: trim`
|
|
12
|
+
Real-time voice-to-text transcription service for capturing spoken content.
|
|
13
|
+
Convert audio input into searchable text that integrates seamlessly with notes and documents.
|
|
14
|
+
`,
|
|
13
15
|
icon: 'ph--microphone--regular',
|
|
16
|
+
iconHue: 'sky',
|
|
14
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-transcription',
|
|
15
18
|
tags: ['labs'],
|
|
16
19
|
screenshots: [],
|
package/src/model/model.test.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { describe, test } from 'vitest';
|
|
|
7
7
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
9
|
import type { ObjectId } from '@dxos/keys';
|
|
10
|
-
import {
|
|
10
|
+
import { Message } from '@dxos/types';
|
|
11
11
|
|
|
12
12
|
import { type ChunkRenderer, DocumentAdapter, SerializationModel } from './model';
|
|
13
13
|
|
|
14
|
-
const blockToMarkdown: ChunkRenderer<
|
|
15
|
-
message:
|
|
14
|
+
const blockToMarkdown: ChunkRenderer<Message.Message> = (
|
|
15
|
+
message: Message.Message,
|
|
16
16
|
index: number,
|
|
17
17
|
debug = true,
|
|
18
18
|
): string[] => {
|
|
@@ -27,12 +27,12 @@ const createDate = () => new Date().toISOString();
|
|
|
27
27
|
|
|
28
28
|
describe('SerializationModel', () => {
|
|
29
29
|
test('basic', ({ expect }) => {
|
|
30
|
-
const model = new SerializationModel<
|
|
30
|
+
const model = new SerializationModel<Message.Message>(blockToMarkdown);
|
|
31
31
|
expect(model.chunks.length).to.eq(0);
|
|
32
32
|
expect(model.doc.toString()).to.eq('');
|
|
33
33
|
|
|
34
34
|
// Create message.
|
|
35
|
-
const message = Obj.make(
|
|
35
|
+
const message = Obj.make(Message.Message, {
|
|
36
36
|
created: createDate(),
|
|
37
37
|
sender: { name: 'Alice' },
|
|
38
38
|
blocks: [
|
|
@@ -62,14 +62,14 @@ describe('SerializationModel', () => {
|
|
|
62
62
|
|
|
63
63
|
test('sync - append', ({ expect }) => {
|
|
64
64
|
const view = new EditorView({ extensions: [], doc: '' });
|
|
65
|
-
const model = new SerializationModel<
|
|
65
|
+
const model = new SerializationModel<Message.Message>(blockToMarkdown);
|
|
66
66
|
const adapter = new DocumentAdapter(view);
|
|
67
67
|
expect(adapter.lineCount()).to.eq(0);
|
|
68
68
|
expect(view.state.doc.toString()).to.eq('');
|
|
69
69
|
|
|
70
70
|
// Append message.
|
|
71
71
|
{
|
|
72
|
-
const message = Obj.make(
|
|
72
|
+
const message = Obj.make(Message.Message, {
|
|
73
73
|
created: createDate(),
|
|
74
74
|
sender: { name: 'Alice' },
|
|
75
75
|
blocks: [
|
|
@@ -87,7 +87,7 @@ describe('SerializationModel', () => {
|
|
|
87
87
|
|
|
88
88
|
// Append message.
|
|
89
89
|
{
|
|
90
|
-
const message = Obj.make(
|
|
90
|
+
const message = Obj.make(Message.Message, {
|
|
91
91
|
created: createDate(),
|
|
92
92
|
sender: { name: 'Bob' },
|
|
93
93
|
blocks: [
|
|
@@ -106,7 +106,7 @@ describe('SerializationModel', () => {
|
|
|
106
106
|
|
|
107
107
|
test('sync - append, update, delete', ({ expect }) => {
|
|
108
108
|
const view = new EditorView({ extensions: [], doc: '' });
|
|
109
|
-
const model = new SerializationModel<
|
|
109
|
+
const model = new SerializationModel<Message.Message>(blockToMarkdown);
|
|
110
110
|
const adapter = new DocumentAdapter(view);
|
|
111
111
|
expect(adapter.lineCount()).to.eq(0);
|
|
112
112
|
|
|
@@ -114,7 +114,7 @@ describe('SerializationModel', () => {
|
|
|
114
114
|
|
|
115
115
|
// Append message.
|
|
116
116
|
{
|
|
117
|
-
const message = Obj.make(
|
|
117
|
+
const message = Obj.make(Message.Message, {
|
|
118
118
|
created: createDate(),
|
|
119
119
|
sender: { name: 'Alice' },
|
|
120
120
|
blocks: [
|
|
@@ -147,7 +147,7 @@ describe('SerializationModel', () => {
|
|
|
147
147
|
|
|
148
148
|
// Append message.
|
|
149
149
|
{
|
|
150
|
-
const message = Obj.make(
|
|
150
|
+
const message = Obj.make(Message.Message, {
|
|
151
151
|
created: createDate(),
|
|
152
152
|
sender: { name: 'Bob' },
|
|
153
153
|
blocks: [{ _tag: 'transcript', started: createDate(), text: 'Hello again!' }],
|
|
@@ -11,11 +11,11 @@ import { effect } from '@preact/signals-core';
|
|
|
11
11
|
import { DeferredTask, asyncTimeout } from '@dxos/async';
|
|
12
12
|
import { LifecycleState, Resource } from '@dxos/context';
|
|
13
13
|
import { type Queue } from '@dxos/echo-db';
|
|
14
|
-
import { type FunctionExecutor } from '@dxos/functions';
|
|
14
|
+
import { type FunctionExecutor } from '@dxos/functions-runtime';
|
|
15
15
|
import { log } from '@dxos/log';
|
|
16
|
-
import { type
|
|
16
|
+
import { type Message } from '@dxos/types';
|
|
17
17
|
|
|
18
|
-
import { type MessageWithRangeId, sentenceNormalization } from './normalization';
|
|
18
|
+
import { type MessageWithRangeId, type NormalizationOutput, sentenceNormalization } from './normalization';
|
|
19
19
|
import { getActorId } from './utils';
|
|
20
20
|
|
|
21
21
|
const PROCESSING_TIMEOUT = 20_000; // ms
|
|
@@ -23,7 +23,7 @@ const MAX_RANGE_ID_COUNT = 10;
|
|
|
23
23
|
|
|
24
24
|
export type SegmentsNormalizerParams = {
|
|
25
25
|
functionExecutor: FunctionExecutor;
|
|
26
|
-
queue: Queue<
|
|
26
|
+
queue: Queue<Message.Message>;
|
|
27
27
|
startingCursor: QueueCursor;
|
|
28
28
|
};
|
|
29
29
|
|
|
@@ -36,7 +36,7 @@ export type QueueCursor = {
|
|
|
36
36
|
// TODO(mykola): .
|
|
37
37
|
export class MessageNormalizer extends Resource {
|
|
38
38
|
private readonly _functionExecutor: FunctionExecutor;
|
|
39
|
-
private _queue: Queue<
|
|
39
|
+
private _queue: Queue<Message.Message>;
|
|
40
40
|
private _cursor: QueueCursor;
|
|
41
41
|
private _messagesToProcess: MessageWithRangeId[] = [];
|
|
42
42
|
private _normalizationTask?: DeferredTask;
|
|
@@ -81,7 +81,7 @@ export class MessageNormalizer extends Resource {
|
|
|
81
81
|
|
|
82
82
|
try {
|
|
83
83
|
// TODO(mykola): Executor should support timeout.
|
|
84
|
-
const response = await asyncTimeout(
|
|
84
|
+
const response: NormalizationOutput = await asyncTimeout(
|
|
85
85
|
this._functionExecutor.invoke(sentenceNormalization, { messages }),
|
|
86
86
|
PROCESSING_TIMEOUT,
|
|
87
87
|
);
|
|
@@ -8,17 +8,17 @@ import { describe, test } from 'vitest';
|
|
|
8
8
|
import { scheduleTaskInterval } from '@dxos/async';
|
|
9
9
|
import { Context } from '@dxos/context';
|
|
10
10
|
import { Obj } from '@dxos/echo';
|
|
11
|
+
import { createQueueDXN } from '@dxos/echo/internal';
|
|
11
12
|
import { MemoryQueue } from '@dxos/echo-db';
|
|
12
|
-
import {
|
|
13
|
-
import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
|
|
13
|
+
import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
|
|
14
14
|
import { log } from '@dxos/log';
|
|
15
|
-
import {
|
|
15
|
+
import { type Actor, Message } from '@dxos/types';
|
|
16
16
|
|
|
17
17
|
import { MessageNormalizer } from './message-normalizer';
|
|
18
18
|
import { type MessageWithRangeId, sentenceNormalization } from './normalization';
|
|
19
19
|
import { getActorId } from './utils';
|
|
20
20
|
|
|
21
|
-
const sender:
|
|
21
|
+
const sender: Actor.Actor = {
|
|
22
22
|
identityDid: 'did:key:123',
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -48,7 +48,7 @@ const messages: MessageWithRangeId[] = [
|
|
|
48
48
|
// No punctuation.
|
|
49
49
|
'in classical physics objects have well-defined properties such as position speed and momentum',
|
|
50
50
|
].map((string, index) =>
|
|
51
|
-
Obj.make(
|
|
51
|
+
Obj.make(Message.Message, {
|
|
52
52
|
created: new Date(Date.now() + 1_000 * index).toISOString(),
|
|
53
53
|
sender,
|
|
54
54
|
blocks: [{ _tag: 'transcript', started: new Date(Date.now() + 1_000 * index).toISOString(), text: string }],
|
|
@@ -108,7 +108,7 @@ describe.skip('SentenceNormalization', () => {
|
|
|
108
108
|
test.only('queue', { timeout: 120_000 }, async () => {
|
|
109
109
|
// Create queue.
|
|
110
110
|
// TODO(dmaretskyi): Use space.queues.create() instead.
|
|
111
|
-
const queue = new MemoryQueue<
|
|
111
|
+
const queue = new MemoryQueue<Message.Message>(createQueueDXN());
|
|
112
112
|
const ctx = new Context();
|
|
113
113
|
let idx = 0;
|
|
114
114
|
scheduleTaskInterval(
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// ISSUE(burdon): defineFunction
|
|
6
6
|
// @ts-nocheck
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
9
9
|
|
|
10
10
|
import { AiService, DEFAULT_EDGE_MODEL } from '@dxos/ai';
|
|
11
11
|
import { AiSession } from '@dxos/assistant';
|
|
@@ -13,13 +13,13 @@ import { Obj } from '@dxos/echo';
|
|
|
13
13
|
import { defineFunction } from '@dxos/functions';
|
|
14
14
|
import { ObjectId } from '@dxos/keys';
|
|
15
15
|
import { log } from '@dxos/log';
|
|
16
|
-
import {
|
|
16
|
+
import { Message } from '@dxos/types';
|
|
17
17
|
import { trim } from '@dxos/util';
|
|
18
18
|
|
|
19
19
|
const MessageWithRangeId = Schema.extend(
|
|
20
|
-
|
|
20
|
+
Message.Message,
|
|
21
21
|
Schema.Struct({
|
|
22
|
-
// TODO(mykola): Move to meta in
|
|
22
|
+
// TODO(mykola): Move to meta in Message. Use `Message.Message` instead.
|
|
23
23
|
rangeId: Schema.optional(Schema.Array(Schema.String)).annotations({
|
|
24
24
|
description: 'The IDs of the messages that contain the sentences.',
|
|
25
25
|
}),
|
|
@@ -29,7 +29,7 @@ const MessageWithRangeId = Schema.extend(
|
|
|
29
29
|
export interface MessageWithRangeId extends Schema.Schema.Type<typeof MessageWithRangeId> {}
|
|
30
30
|
|
|
31
31
|
export const NormalizationInput = Schema.Struct({
|
|
32
|
-
// TODO(mykola): Move to meta in
|
|
32
|
+
// TODO(mykola): Move to meta in Message. Use `Message.Message` instead.
|
|
33
33
|
messages: Schema.Array(MessageWithRangeId).annotations({
|
|
34
34
|
description: 'Messages to normalize into sentences.',
|
|
35
35
|
}),
|
|
@@ -61,7 +61,7 @@ export const sentenceNormalization = defineFunction<NormalizationInput, Normaliz
|
|
|
61
61
|
tools: [],
|
|
62
62
|
artifacts: [],
|
|
63
63
|
history: [
|
|
64
|
-
Obj.make(
|
|
64
|
+
Obj.make(Message.Message, {
|
|
65
65
|
created: new Date().toISOString(),
|
|
66
66
|
sender: {
|
|
67
67
|
role: 'user',
|
|
@@ -89,7 +89,7 @@ const prompt = trim`
|
|
|
89
89
|
|
|
90
90
|
# Input Format:
|
|
91
91
|
- The input is an array of messages that contain transcription blocks.
|
|
92
|
-
- Each message is a
|
|
92
|
+
- Each message is a Message.Message, as described in the output format.
|
|
93
93
|
|
|
94
94
|
# Output Format:
|
|
95
95
|
- You have been provided with the tool that defines the output format; make sure to query it.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Actor } from '@dxos/types';
|
|
6
6
|
|
|
7
|
-
export const getActorId = (actor:
|
|
7
|
+
export const getActorId = (actor: Actor.Actor) => {
|
|
8
8
|
return actor.identityDid || actor.identityKey || actor.email || actor.name || '';
|
|
9
9
|
};
|
package/src/testing/testing.ts
CHANGED
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { useEffect, useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { extractionAnthropicFunction, processTranscriptMessage } from '@dxos/assistant/extraction';
|
|
9
9
|
import { scheduleTaskInterval } from '@dxos/async';
|
|
10
10
|
import { Filter, type Queue } from '@dxos/client/echo';
|
|
11
11
|
import { Context } from '@dxos/context';
|
|
12
12
|
import { type Key, Obj, Ref, Type } from '@dxos/echo';
|
|
13
|
-
import { createQueueDXN } from '@dxos/echo
|
|
14
|
-
import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
|
|
13
|
+
import { createQueueDXN } from '@dxos/echo/internal';
|
|
14
|
+
import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
|
|
15
15
|
import { IdentityDid } from '@dxos/keys';
|
|
16
16
|
import { log } from '@dxos/log';
|
|
17
17
|
import { faker } from '@dxos/random';
|
|
18
18
|
import { type Space, useQueue } from '@dxos/react-client/echo';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { Testing } from '@dxos/schema/testing';
|
|
20
|
+
import { type ContentBlock, Message, Organization, Person } from '@dxos/types';
|
|
21
|
+
import { seedTestData } from '@dxos/types/testing';
|
|
21
22
|
|
|
22
23
|
// TODO(burdon): Reconcile with plugin-markdown. Move to @dxos/schema/testing.
|
|
23
24
|
export const TestItem = Schema.Struct({
|
|
@@ -38,7 +39,7 @@ export const TestItem = Schema.Struct({
|
|
|
38
39
|
|
|
39
40
|
// TODO(wittjosiah): Make builder generic and reuse for all message types.
|
|
40
41
|
abstract class AbstractMessageBuilder {
|
|
41
|
-
abstract createMessage(numSegments?: number): Promise<
|
|
42
|
+
abstract createMessage(numSegments?: number): Promise<Message.Message>;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -59,22 +60,22 @@ export class MessageBuilder extends AbstractMessageBuilder {
|
|
|
59
60
|
super();
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
override async createMessage(numSegments = 1): Promise<
|
|
63
|
-
return Obj.make(
|
|
63
|
+
override async createMessage(numSegments = 1): Promise<Message.Message> {
|
|
64
|
+
return Obj.make(Message.Message, {
|
|
64
65
|
created: this.next().toISOString(),
|
|
65
66
|
sender: faker.helpers.arrayElement(this.users),
|
|
66
67
|
blocks: Array.from({ length: numSegments }).map(() => this.createBlock()),
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
createBlock():
|
|
71
|
+
createBlock(): ContentBlock.Transcript {
|
|
71
72
|
let text = faker.lorem.paragraph();
|
|
72
73
|
if (this._space) {
|
|
73
74
|
const label = faker.commerce.productName();
|
|
74
75
|
const obj = this._space.db.add(Obj.make(TestItem, { title: label, description: faker.lorem.paragraph() }));
|
|
75
76
|
const dxn = Ref.make(obj).dxn.toString();
|
|
76
77
|
const words = text.split(' ');
|
|
77
|
-
words.splice(Math.floor(Math.random() * words.length), 0, `[${label}]
|
|
78
|
+
words.splice(Math.floor(Math.random() * words.length), 0, `[${label}](${dxn})`);
|
|
78
79
|
text = words.join(' ');
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -103,7 +104,7 @@ class EntityExtractionMessageBuilder extends AbstractMessageBuilder {
|
|
|
103
104
|
|
|
104
105
|
space: Space | undefined;
|
|
105
106
|
currentMessage: number = 0;
|
|
106
|
-
transcriptMessages:
|
|
107
|
+
transcriptMessages: Message.Message[] = [];
|
|
107
108
|
|
|
108
109
|
async connect(space: Space): Promise<void> {
|
|
109
110
|
this.space = space;
|
|
@@ -111,14 +112,18 @@ class EntityExtractionMessageBuilder extends AbstractMessageBuilder {
|
|
|
111
112
|
this.transcriptMessages = transcriptMessages;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
override async createMessage(): Promise<
|
|
115
|
+
override async createMessage(): Promise<Message.Message> {
|
|
115
116
|
if (!this.space) {
|
|
116
117
|
throw new Error('Space not connected');
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
const { objects } = await this.space.db
|
|
120
121
|
.query(
|
|
121
|
-
Filter.or(
|
|
122
|
+
Filter.or(
|
|
123
|
+
Filter.type(Person.Person),
|
|
124
|
+
Filter.type(Organization.Organization),
|
|
125
|
+
Filter.type(Testing.DocumentType),
|
|
126
|
+
),
|
|
122
127
|
)
|
|
123
128
|
.run();
|
|
124
129
|
|
|
@@ -130,7 +135,7 @@ class EntityExtractionMessageBuilder extends AbstractMessageBuilder {
|
|
|
130
135
|
const { message: enhancedMessage } = await processTranscriptMessage({
|
|
131
136
|
input: { message },
|
|
132
137
|
executor: this.executor,
|
|
133
|
-
function:
|
|
138
|
+
function: extractionAnthropicFunction,
|
|
134
139
|
});
|
|
135
140
|
|
|
136
141
|
return enhancedMessage;
|
|
@@ -142,7 +147,7 @@ type UseTestTranscriptionQueue = (
|
|
|
142
147
|
queueId?: Key.ObjectId,
|
|
143
148
|
running?: boolean,
|
|
144
149
|
interval?: number,
|
|
145
|
-
) => Queue<
|
|
150
|
+
) => Queue<Message.Message> | undefined;
|
|
146
151
|
|
|
147
152
|
/**
|
|
148
153
|
* Test transcriptionqueue.
|
|
@@ -155,7 +160,7 @@ export const useTestTranscriptionQueue: UseTestTranscriptionQueue = (
|
|
|
155
160
|
) => {
|
|
156
161
|
// TODO(dmaretskyi): Use space.queues.create() instead.
|
|
157
162
|
const queueDxn = useMemo(() => (space ? createQueueDXN(space.id, queueId) : undefined), [space, queueId]);
|
|
158
|
-
const queue = useQueue<
|
|
163
|
+
const queue = useQueue<Message.Message>(queueDxn);
|
|
159
164
|
const builder = useMemo(() => new MessageBuilder(space), [space]);
|
|
160
165
|
|
|
161
166
|
useEffect(() => {
|
|
@@ -165,7 +170,7 @@ export const useTestTranscriptionQueue: UseTestTranscriptionQueue = (
|
|
|
165
170
|
|
|
166
171
|
const i = setInterval(() => {
|
|
167
172
|
void builder.createMessage(Math.ceil(Math.random() * 3)).then(async (message) => {
|
|
168
|
-
await queue.append([Obj.make(
|
|
173
|
+
await queue.append([Obj.make(Message.Message, message)]);
|
|
169
174
|
});
|
|
170
175
|
}, interval);
|
|
171
176
|
return () => clearInterval(i);
|
|
@@ -186,7 +191,7 @@ export const useTestTranscriptionQueueWithEntityExtraction: UseTestTranscription
|
|
|
186
191
|
) => {
|
|
187
192
|
// TODO(dmaretskyi): Use space.queues.create() instead.
|
|
188
193
|
const queueDxn = useMemo(() => (space ? createQueueDXN(space.id, queueId) : undefined), [space, queueId]);
|
|
189
|
-
const queue = useQueue<
|
|
194
|
+
const queue = useQueue<Message.Message>(queueDxn);
|
|
190
195
|
const [builder] = useState(() => new EntityExtractionMessageBuilder());
|
|
191
196
|
|
|
192
197
|
useEffect(() => {
|
|
@@ -203,7 +208,7 @@ export const useTestTranscriptionQueueWithEntityExtraction: UseTestTranscription
|
|
|
203
208
|
ctx,
|
|
204
209
|
async () => {
|
|
205
210
|
const message = await builder.createMessage();
|
|
206
|
-
void queue.append([Obj.make(
|
|
211
|
+
void queue.append([Obj.make(Message.Message, message)]);
|
|
207
212
|
},
|
|
208
213
|
interval,
|
|
209
214
|
);
|
|
@@ -10,9 +10,9 @@ import { WaveFile } from 'wavefile';
|
|
|
10
10
|
|
|
11
11
|
import { Trigger } from '@dxos/async';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
|
-
import { type DataType } from '@dxos/schema';
|
|
14
13
|
import { openAndClose } from '@dxos/test-utils';
|
|
15
14
|
import { TRACE_PROCESSOR, trace } from '@dxos/tracing';
|
|
15
|
+
import { type ContentBlock } from '@dxos/types';
|
|
16
16
|
|
|
17
17
|
import { type AudioChunk, type AudioRecorder, Transcriber } from '../transcriber';
|
|
18
18
|
import { mergeFloat64Arrays } from '../util';
|
|
@@ -94,7 +94,7 @@ describe.skip('Transcriber', () => {
|
|
|
94
94
|
});
|
|
95
95
|
|
|
96
96
|
test.skip('transcription of audio recording', { timeout: 10_000 }, async () => {
|
|
97
|
-
const trigger = new Trigger<
|
|
97
|
+
const trigger = new Trigger<ContentBlock.Transcript[]>({ autoReset: true });
|
|
98
98
|
const recorder = new MockAudioRecorder({
|
|
99
99
|
buffer: await readFile('test.wav'),
|
|
100
100
|
chunkDuration: 3_000,
|
|
@@ -128,7 +128,7 @@ describe.skip('Transcriber', () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test.skip('transcription of audio recording with overlapping chunks', { timeout: 20_000 }, async () => {
|
|
131
|
-
const trigger = new Trigger<
|
|
131
|
+
const trigger = new Trigger<ContentBlock.Transcript[]>({ autoReset: true });
|
|
132
132
|
const recorder = new MockAudioRecorder({
|
|
133
133
|
buffer: await readFile('test.wav'),
|
|
134
134
|
chunkDuration: 3_000,
|
|
@@ -7,8 +7,8 @@ import { WaveFile } from 'wavefile';
|
|
|
7
7
|
import { DeferredTask, Trigger } from '@dxos/async';
|
|
8
8
|
import { type Context, LifecycleState, Resource } from '@dxos/context';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
-
import { type DataType } from '@dxos/schema';
|
|
11
10
|
import { trace } from '@dxos/tracing';
|
|
11
|
+
import { type ContentBlock } from '@dxos/types';
|
|
12
12
|
|
|
13
13
|
import { TRANSCRIPTION_URL } from '../types';
|
|
14
14
|
import { mergeFloat64Arrays } from '../util';
|
|
@@ -70,7 +70,7 @@ export type TranscriberParams = {
|
|
|
70
70
|
* Callback to handle the transcribed segments, after all segment transformers are applied.
|
|
71
71
|
* @param segments - The transcribed segments.
|
|
72
72
|
*/
|
|
73
|
-
onSegments: (segments:
|
|
73
|
+
onSegments: (segments: ContentBlock.Transcript[]) => Promise<void>;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
/**
|
|
@@ -221,7 +221,7 @@ export class Transcriber extends Resource {
|
|
|
221
221
|
return segments;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
private _alignSegments(segments: WhisperSegment[], originalChunks: AudioChunk[]):
|
|
224
|
+
private _alignSegments(segments: WhisperSegment[], originalChunks: AudioChunk[]): ContentBlock.Transcript[] {
|
|
225
225
|
// Absolute zero for all relative timestamps in the segments.
|
|
226
226
|
const zeroTimestamp = originalChunks.at(0)!.timestamp;
|
|
227
227
|
|
|
@@ -9,7 +9,7 @@ import { Resource } from '@dxos/context';
|
|
|
9
9
|
import { Obj } from '@dxos/echo';
|
|
10
10
|
import { type Queue } from '@dxos/echo-db';
|
|
11
11
|
import { type EdgeHttpClient } from '@dxos/react-edge-client';
|
|
12
|
-
import {
|
|
12
|
+
import { type ContentBlock, Message } from '@dxos/types';
|
|
13
13
|
|
|
14
14
|
import { MediaStreamRecorder } from './media-stream-recorder';
|
|
15
15
|
import { Transcriber } from './transcriber';
|
|
@@ -30,7 +30,7 @@ const PREFIXED_CHUNKS_AMOUNT = 10;
|
|
|
30
30
|
*/
|
|
31
31
|
const TRANSCRIBE_AFTER_CHUNKS_AMOUNT = 50;
|
|
32
32
|
|
|
33
|
-
export type TranscriptMessageEnricher = (message:
|
|
33
|
+
export type TranscriptMessageEnricher = (message: Message.Message) => Promise<Message.Message>;
|
|
34
34
|
|
|
35
35
|
export type TranscriptionManagerOptions = {
|
|
36
36
|
edgeClient: EdgeHttpClient;
|
|
@@ -51,7 +51,7 @@ export class TranscriptionManager extends Resource {
|
|
|
51
51
|
private _identityDid?: string = undefined;
|
|
52
52
|
private _mediaRecorder?: MediaStreamRecorder = undefined;
|
|
53
53
|
private _transcriber?: Transcriber = undefined;
|
|
54
|
-
private _queue?: Queue<
|
|
54
|
+
private _queue?: Queue<Message.Message> = undefined;
|
|
55
55
|
private _enabled = signal(false);
|
|
56
56
|
|
|
57
57
|
constructor(options: TranscriptionManagerOptions) {
|
|
@@ -65,7 +65,7 @@ export class TranscriptionManager extends Resource {
|
|
|
65
65
|
return this._enabled.value;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
setQueue(queue: Queue<
|
|
68
|
+
setQueue(queue: Queue<Message.Message>): this {
|
|
69
69
|
this._queue = queue;
|
|
70
70
|
return this;
|
|
71
71
|
}
|
|
@@ -154,12 +154,12 @@ export class TranscriptionManager extends Resource {
|
|
|
154
154
|
await this._transcriber?.close();
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
private async _onSegments(segments:
|
|
157
|
+
private async _onSegments(segments: ContentBlock.Transcript[]): Promise<void> {
|
|
158
158
|
if (!this.isOpen || !this._queue) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
let block = Obj.make(
|
|
162
|
+
let block = Obj.make(Message.Message, {
|
|
163
163
|
created: new Date().toISOString(),
|
|
164
164
|
blocks: segments,
|
|
165
165
|
sender: { identityDid: this._identityDid },
|
package/src/types/Transcript.ts
CHANGED