@dxos/plugin-transcription 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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/TranscriptionContainer-RBFHP2AV.mjs +41 -0
- package/dist/lib/browser/TranscriptionContainer-RBFHP2AV.mjs.map +7 -0
- package/dist/lib/browser/blueprint-definition-C6XA2SVZ.mjs +18 -0
- package/dist/lib/browser/blueprint-definition-C6XA2SVZ.mjs.map +7 -0
- package/dist/lib/browser/blueprints/index.mjs +9 -0
- package/dist/lib/browser/chunk-2B74LZZD.mjs +22 -0
- package/dist/lib/browser/chunk-2B74LZZD.mjs.map +7 -0
- package/dist/lib/browser/{chunk-COBQIZ6B.mjs → chunk-EV5ZYKET.mjs} +60 -86
- package/dist/lib/browser/chunk-EV5ZYKET.mjs.map +7 -0
- package/dist/lib/browser/chunk-GH4IIQ6C.mjs +54 -0
- package/dist/lib/browser/chunk-GH4IIQ6C.mjs.map +7 -0
- package/dist/lib/browser/chunk-HOOPZ7EM.mjs +35 -0
- package/dist/lib/browser/chunk-HOOPZ7EM.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/{blueprint-definition-GO6GTEBT.mjs → chunk-O7ILGNBZ.mjs} +39 -41
- package/dist/lib/browser/chunk-O7ILGNBZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ZS2FXKEF.mjs → chunk-XLMRCOQN.mjs} +383 -470
- package/dist/lib/browser/chunk-XLMRCOQN.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +62 -77
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-5BLRH4XE.mjs +23 -0
- package/dist/lib/browser/operation-resolver-5BLRH4XE.mjs.map +7 -0
- package/dist/lib/browser/react-surface-U2SI74JK.mjs +36 -0
- package/dist/lib/browser/react-surface-U2SI74JK.mjs.map +7 -0
- package/dist/lib/browser/{transcriber-NG5MRCP6.mjs → transcriber-WCPHHJYY.mjs} +19 -14
- package/dist/lib/browser/transcriber-WCPHHJYY.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +8 -5
- package/dist/lib/node-esm/TranscriptionContainer-3OOID5KH.mjs +42 -0
- package/dist/lib/node-esm/TranscriptionContainer-3OOID5KH.mjs.map +7 -0
- package/dist/lib/node-esm/blueprint-definition-TLXDUXIQ.mjs +19 -0
- package/dist/lib/node-esm/blueprint-definition-TLXDUXIQ.mjs.map +7 -0
- package/dist/lib/node-esm/blueprints/index.mjs +10 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6GW5NZYG.mjs +55 -0
- package/dist/lib/node-esm/chunk-6GW5NZYG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-A6SB234F.mjs → chunk-7UE7G6DE.mjs} +60 -86
- package/dist/lib/node-esm/chunk-7UE7G6DE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PEZRQYKO.mjs → chunk-DYUGYQCB.mjs} +383 -470
- package/dist/lib/node-esm/chunk-DYUGYQCB.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-KLTPFUKN.mjs → chunk-F47HK7GT.mjs} +7 -8
- package/dist/lib/node-esm/chunk-F47HK7GT.mjs.map +7 -0
- package/dist/lib/node-esm/{blueprint-definition-6SU7GLBR.mjs → chunk-H3MXHMQL.mjs} +39 -41
- package/dist/lib/node-esm/chunk-H3MXHMQL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NVM2QUMX.mjs +37 -0
- package/dist/lib/node-esm/chunk-NVM2QUMX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +62 -77
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/operation-resolver-CVZB7BF4.mjs +24 -0
- package/dist/lib/node-esm/operation-resolver-CVZB7BF4.mjs.map +7 -0
- package/dist/lib/node-esm/react-surface-2ICJPBPX.mjs +37 -0
- package/dist/lib/node-esm/react-surface-2ICJPBPX.mjs.map +7 -0
- package/dist/lib/node-esm/{transcriber-SMU7HD6F.mjs → transcriber-2RIHUEX4.mjs} +19 -14
- package/dist/lib/node-esm/transcriber-2RIHUEX4.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +8 -5
- package/dist/types/src/TranscriptionPlugin.d.ts +2 -1
- package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +2 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/transcription-blueprint.d.ts +4 -0
- package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +6 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +4 -5
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-handler/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts +5 -0
- package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/transcriber/index.d.ts +3 -0
- package/dist/types/src/capabilities/transcriber/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/transcriber/transcriber.d.ts +9 -0
- package/dist/types/src/capabilities/transcriber/transcriber.d.ts.map +1 -0
- package/dist/types/src/components/Transcription/Transcription.d.ts +17 -0
- package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -0
- package/dist/types/src/components/{Transcript/Transcript.stories.d.ts → Transcription/Transcription.stories.d.ts} +7 -6
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +1 -0
- package/dist/types/src/components/Transcription/index.d.ts +2 -0
- package/dist/types/src/components/Transcription/index.d.ts.map +1 -0
- package/dist/types/src/components/Transcription/transcription-extension.d.ts +15 -0
- package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts +3 -6
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +0 -3
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +3 -6
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/TranscriptionStory.d.ts +2 -2
- package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +1 -1
- package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts +6 -0
- package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts.map +1 -0
- package/dist/types/src/containers/TranscriptionContainer/index.d.ts +3 -0
- package/dist/types/src/containers/TranscriptionContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +3 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/functions/index.d.ts +17 -2
- package/dist/types/src/functions/index.d.ts.map +1 -1
- package/dist/types/src/functions/open.d.ts +6 -2
- 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/hooks/useQueueModelAdapter.d.ts +1 -1
- package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +1 -1
- package/dist/types/src/hooks/useTranscriber.d.ts +1 -1
- package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/segments-normalization/message-normalizer.d.ts +5 -5
- package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +1 -1
- package/dist/types/src/segments-normalization/normalization.d.ts +515 -448
- 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 +9 -9
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/transcriber/media-stream-recorder.d.ts +2 -2
- package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
- package/dist/types/src/transcriber/transcriber.d.ts +4 -4
- package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
- package/dist/types/src/transcriber/transcription-manager.d.ts +9 -6
- package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
- package/dist/types/src/types/TranscriptAction.d.ts +22 -20
- package/dist/types/src/types/TranscriptAction.d.ts.map +1 -1
- package/dist/types/src/types/capabilities.d.ts +18 -0
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/render-byline.d.ts +4 -0
- package/dist/types/src/util/render-byline.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +84 -69
- package/src/TranscriptionPlugin.tsx +35 -57
- package/src/blueprints/index.ts +5 -0
- package/src/blueprints/transcription-blueprint.ts +33 -0
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +17 -0
- package/src/capabilities/blueprint-definition/index.ts +7 -0
- package/src/capabilities/index.ts +4 -8
- package/src/capabilities/operation-handler/index.ts +7 -0
- package/src/capabilities/operation-handler/operation-handler.ts +25 -0
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +25 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +28 -0
- package/src/capabilities/transcriber/index.ts +7 -0
- package/src/capabilities/transcriber/transcriber.ts +85 -0
- package/src/components/{Transcript/Transcript.stories.tsx → Transcription/Transcription.stories.tsx} +42 -41
- package/src/components/Transcription/Transcription.tsx +63 -0
- package/src/components/{Transcript → Transcription}/index.ts +1 -1
- package/src/components/{Transcript/transcript-extension.ts → Transcription/transcription-extension.ts} +13 -9
- package/src/components/index.ts +1 -6
- package/src/components/stories/FileTranscription.stories.tsx +30 -36
- package/src/components/stories/KeyWordRecognition.stories.tsx +5 -8
- package/src/components/stories/MicrophoneTranscription.stories.tsx +50 -55
- package/src/components/stories/TranscriptionStory.tsx +7 -11
- package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +33 -0
- package/src/containers/TranscriptionContainer/index.ts +7 -0
- package/src/containers/index.ts +7 -0
- package/src/functions/index.ts +7 -2
- package/src/functions/open.ts +9 -11
- package/src/hooks/useQueueModelAdapter.ts +1 -1
- package/src/hooks/useTranscriber.ts +8 -3
- package/src/hooks/useVoiceInput.ts +2 -2
- package/src/index.ts +1 -1
- package/src/meta.ts +8 -3
- package/src/model/model.test.ts +20 -14
- package/src/segments-normalization/message-normalizer.ts +18 -13
- package/src/segments-normalization/normalization.test.ts +6 -11
- package/src/segments-normalization/normalization.ts +6 -6
- package/src/segments-normalization/utils.ts +2 -2
- package/src/testing/testing.ts +28 -18
- package/src/transcriber/media-stream-recorder.ts +3 -3
- package/src/transcriber/transcriber.browser.test.ts +4 -4
- package/src/transcriber/transcriber.ts +6 -6
- package/src/transcriber/transcription-manager.ts +21 -15
- package/src/types/TranscriptAction.ts +21 -13
- package/src/{capabilities → types}/capabilities.ts +8 -8
- package/src/types/index.ts +2 -1
- package/src/util/index.ts +1 -0
- package/src/util/render-byline.ts +33 -0
- package/dist/lib/browser/TranscriptContainer-QN5WUMWJ.mjs +0 -11
- package/dist/lib/browser/blueprint-definition-GO6GTEBT.mjs.map +0 -7
- package/dist/lib/browser/chunk-77NWYLC6.mjs +0 -8
- package/dist/lib/browser/chunk-77NWYLC6.mjs.map +0 -7
- package/dist/lib/browser/chunk-7LNCQDTT.mjs +0 -24
- package/dist/lib/browser/chunk-7LNCQDTT.mjs.map +0 -7
- package/dist/lib/browser/chunk-COBQIZ6B.mjs.map +0 -7
- package/dist/lib/browser/chunk-GGHMOEKZ.mjs +0 -63
- package/dist/lib/browser/chunk-GGHMOEKZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-LCK3YRQF.mjs +0 -16
- package/dist/lib/browser/chunk-LCK3YRQF.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZS2FXKEF.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-52EPFRMR.mjs +0 -25
- package/dist/lib/browser/intent-resolver-52EPFRMR.mjs.map +0 -7
- package/dist/lib/browser/react-surface-LCP2D2MF.mjs +0 -34
- package/dist/lib/browser/react-surface-LCP2D2MF.mjs.map +0 -7
- package/dist/lib/browser/transcriber-NG5MRCP6.mjs.map +0 -7
- package/dist/lib/node-esm/TranscriptContainer-WCUWVVSD.mjs +0 -12
- package/dist/lib/node-esm/blueprint-definition-6SU7GLBR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-A6SB234F.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-FTTZ4YSX.mjs +0 -64
- package/dist/lib/node-esm/chunk-FTTZ4YSX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KLTPFUKN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-N5Z4SKPH.mjs +0 -10
- package/dist/lib/node-esm/chunk-N5Z4SKPH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PEZRQYKO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RWRG3S2O.mjs +0 -17
- package/dist/lib/node-esm/chunk-RWRG3S2O.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-DZBQQRHN.mjs +0 -26
- package/dist/lib/node-esm/intent-resolver-DZBQQRHN.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-7UC2YXX2.mjs +0 -35
- package/dist/lib/node-esm/react-surface-7UC2YXX2.mjs.map +0 -7
- package/dist/lib/node-esm/transcriber-SMU7HD6F.mjs.map +0 -7
- package/dist/types/src/capabilities/blueprint-definition.d.ts +0 -5
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/capabilities.d.ts +0 -17
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/capabilities/transcriber.d.ts +0 -8
- package/dist/types/src/capabilities/transcriber.d.ts.map +0 -1
- package/dist/types/src/components/Transcript/Transcript.d.ts +0 -20
- package/dist/types/src/components/Transcript/Transcript.d.ts.map +0 -1
- package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +0 -1
- package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +0 -28
- package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +0 -1
- package/dist/types/src/components/Transcript/index.d.ts +0 -2
- package/dist/types/src/components/Transcript/index.d.ts.map +0 -1
- package/dist/types/src/components/Transcript/transcript-extension.d.ts +0 -15
- package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +0 -1
- package/dist/types/src/components/TranscriptContainer.d.ts +0 -9
- package/dist/types/src/components/TranscriptContainer.d.ts.map +0 -1
- package/dist/types/src/types/Transcript.d.ts +0 -30
- package/dist/types/src/types/Transcript.d.ts.map +0 -1
- package/src/capabilities/blueprint-definition.ts +0 -31
- package/src/capabilities/intent-resolver.ts +0 -18
- package/src/capabilities/react-surface.tsx +0 -22
- package/src/capabilities/transcriber.ts +0 -77
- package/src/components/Transcript/Transcript.tsx +0 -93
- package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
- package/src/components/TranscriptContainer.tsx +0 -36
- package/src/types/Transcript.ts +0 -44
- /package/dist/lib/browser/{TranscriptContainer-QN5WUMWJ.mjs.map → blueprints/index.mjs.map} +0 -0
- /package/dist/lib/{node-esm/TranscriptContainer-WCUWVVSD.mjs.map → browser/chunk-J5LGTIGS.mjs.map} +0 -0
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
6
7
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
7
8
|
|
|
8
|
-
import { Events, IntentPlugin, SettingsPlugin } from '@dxos/app-framework';
|
|
9
9
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
|
+
import { AppActivationEvents } from '@dxos/app-toolkit';
|
|
10
11
|
import {
|
|
11
12
|
type ExtractionFunction,
|
|
12
13
|
extractionAnthropicFunction,
|
|
@@ -14,28 +15,26 @@ import {
|
|
|
14
15
|
getNer,
|
|
15
16
|
processTranscriptMessage,
|
|
16
17
|
} from '@dxos/assistant/extraction';
|
|
17
|
-
import { Filter,
|
|
18
|
+
import { Filter, type Obj } from '@dxos/echo';
|
|
18
19
|
import { createQueueDXN } from '@dxos/echo/internal';
|
|
19
20
|
import { MemoryQueue } from '@dxos/echo-db';
|
|
20
|
-
import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
|
|
21
|
+
import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
|
|
21
22
|
import { invariant } from '@dxos/invariant';
|
|
22
23
|
import { log } from '@dxos/log';
|
|
23
24
|
import { ClientPlugin } from '@dxos/plugin-client';
|
|
24
25
|
import { PreviewPlugin } from '@dxos/plugin-preview';
|
|
25
|
-
import {
|
|
26
|
-
import { StorybookLayoutPlugin } from '@dxos/plugin-storybook-layout';
|
|
27
|
-
import { ThemePlugin } from '@dxos/plugin-theme';
|
|
26
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
28
27
|
import { IndexKind, useSpace } from '@dxos/react-client/echo';
|
|
29
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
28
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
29
|
+
import { TestSchema } from '@dxos/schema/testing';
|
|
30
|
+
import { Message, Organization, Person } from '@dxos/types';
|
|
31
|
+
import { seedTestData } from '@dxos/types/testing';
|
|
33
32
|
|
|
34
33
|
import { useAudioTrack, useQueueModelAdapter, useTranscriber } from '../../hooks';
|
|
35
34
|
import { TestItem } from '../../testing';
|
|
36
|
-
import { type
|
|
35
|
+
import { type MediaStreamRecorderProps, type TranscriberProps } from '../../transcriber';
|
|
37
36
|
import { TranscriptionPlugin } from '../../TranscriptionPlugin';
|
|
38
|
-
import { renderByline } from '
|
|
37
|
+
import { renderByline } from '../../util';
|
|
39
38
|
|
|
40
39
|
import { TranscriptionStory } from './TranscriptionStory';
|
|
41
40
|
import { useIsSpeaking } from './useIsSpeaking';
|
|
@@ -51,8 +50,8 @@ const RECORDER_CONFIG = {
|
|
|
51
50
|
|
|
52
51
|
type StoryProps = {
|
|
53
52
|
detectSpeaking?: boolean;
|
|
54
|
-
transcriberConfig:
|
|
55
|
-
recorderConfig:
|
|
53
|
+
transcriberConfig: TranscriberProps['config'];
|
|
54
|
+
recorderConfig: MediaStreamRecorderProps['config'];
|
|
56
55
|
audioConstraints?: MediaTrackConstraints;
|
|
57
56
|
entityExtraction: 'none' | 'ner' | 'llm';
|
|
58
57
|
};
|
|
@@ -75,7 +74,7 @@ const DefaultStory = ({
|
|
|
75
74
|
// Queue.
|
|
76
75
|
// TODO(dmaretskyi): Use space.queues.create() instead.
|
|
77
76
|
const queueDxn = useMemo(() => createQueueDXN(), []);
|
|
78
|
-
const queue = useMemo(() => new MemoryQueue<
|
|
77
|
+
const queue = useMemo(() => new MemoryQueue<Message.Message>(queueDxn), [queueDxn]);
|
|
79
78
|
const model = useQueueModelAdapter(renderByline([]), queue);
|
|
80
79
|
const space = useSpace();
|
|
81
80
|
|
|
@@ -94,7 +93,7 @@ const DefaultStory = ({
|
|
|
94
93
|
|
|
95
94
|
let executor: FunctionExecutor | undefined;
|
|
96
95
|
let extractionFunction: ExtractionFunction | undefined;
|
|
97
|
-
let objects: Promise<
|
|
96
|
+
let objects: Promise<Obj.Unknown[]> | undefined;
|
|
98
97
|
|
|
99
98
|
if (entityExtraction === 'ner') {
|
|
100
99
|
// Init model loading. Takes time.
|
|
@@ -105,13 +104,12 @@ const DefaultStory = ({
|
|
|
105
104
|
objects = space.db
|
|
106
105
|
.query(
|
|
107
106
|
Filter.or(
|
|
108
|
-
Filter.type(
|
|
109
|
-
Filter.type(
|
|
110
|
-
Filter.type(
|
|
107
|
+
Filter.type(Person.Person),
|
|
108
|
+
Filter.type(Organization.Organization),
|
|
109
|
+
Filter.type(TestSchema.DocumentType),
|
|
111
110
|
),
|
|
112
111
|
)
|
|
113
|
-
.run()
|
|
114
|
-
.then((result) => result.objects);
|
|
112
|
+
.run();
|
|
115
113
|
}
|
|
116
114
|
if (entityExtraction !== 'none') {
|
|
117
115
|
executor = new FunctionExecutor(
|
|
@@ -130,9 +128,9 @@ const DefaultStory = ({
|
|
|
130
128
|
}, [entityExtraction, space]);
|
|
131
129
|
|
|
132
130
|
// Transcriber.
|
|
133
|
-
const handleSegments = useCallback<
|
|
131
|
+
const handleSegments = useCallback<TranscriberProps['onSegments']>(
|
|
134
132
|
async (blocks) => {
|
|
135
|
-
const message =
|
|
133
|
+
const message = Message.make({
|
|
136
134
|
sender: { name: 'You' },
|
|
137
135
|
created: new Date().toISOString(),
|
|
138
136
|
blocks,
|
|
@@ -192,50 +190,47 @@ const DefaultStory = ({
|
|
|
192
190
|
};
|
|
193
191
|
|
|
194
192
|
const meta = {
|
|
195
|
-
title: 'plugins/plugin-transcription/MicrophoneTranscription',
|
|
193
|
+
title: 'plugins/plugin-transcription/components/MicrophoneTranscription',
|
|
196
194
|
render: DefaultStory,
|
|
197
195
|
decorators: [
|
|
198
|
-
withTheme,
|
|
196
|
+
withTheme(),
|
|
197
|
+
withLayout({ layout: 'column' }),
|
|
199
198
|
withPluginManager({
|
|
200
199
|
plugins: [
|
|
200
|
+
...corePlugins(),
|
|
201
|
+
StorybookPlugin({}),
|
|
201
202
|
ClientPlugin({
|
|
202
|
-
types: [TestItem,
|
|
203
|
-
onClientInitialized:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
203
|
+
types: [TestItem, Person.Person, Organization.Organization, TestSchema.DocumentType],
|
|
204
|
+
onClientInitialized: ({ client }) =>
|
|
205
|
+
Effect.gen(function* () {
|
|
206
|
+
yield* Effect.promise(() => client.halo.createIdentity());
|
|
207
|
+
yield* Effect.promise(() => client.spaces.waitUntilReady());
|
|
208
|
+
yield* Effect.promise(() => client.spaces.default.waitUntilReady());
|
|
209
|
+
// TODO(mykola): Make API easier to use.
|
|
210
|
+
// TODO(mykola): Delete after enabling vector indexing by default.
|
|
211
|
+
// Enable vector indexing.
|
|
212
|
+
yield* Effect.promise(() =>
|
|
213
|
+
client.services.services.QueryService!.setConfig({
|
|
214
|
+
enabled: true,
|
|
215
|
+
indexes: [
|
|
216
|
+
//
|
|
217
|
+
{ kind: IndexKind.Kind.SCHEMA_MATCH },
|
|
218
|
+
{ kind: IndexKind.Kind.GRAPH },
|
|
219
|
+
{ kind: IndexKind.Kind.VECTOR },
|
|
220
|
+
],
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
yield* Effect.promise(() => client.services.services.QueryService!.reindex());
|
|
224
|
+
yield* Effect.promise(() => seedTestData(client.spaces.default));
|
|
225
|
+
}),
|
|
222
226
|
}),
|
|
223
|
-
SpacePlugin({}),
|
|
224
|
-
IntentPlugin(),
|
|
225
|
-
SettingsPlugin(),
|
|
226
227
|
|
|
227
|
-
// UI
|
|
228
|
-
ThemePlugin({ tx: defaultTx }),
|
|
229
228
|
PreviewPlugin(),
|
|
230
229
|
TranscriptionPlugin(),
|
|
231
|
-
StorybookLayoutPlugin({}),
|
|
232
230
|
],
|
|
233
|
-
fireEvents: [
|
|
231
|
+
fireEvents: [AppActivationEvents.SetupAppGraph],
|
|
234
232
|
}),
|
|
235
233
|
],
|
|
236
|
-
parameters: {
|
|
237
|
-
layout: 'column',
|
|
238
|
-
},
|
|
239
234
|
} satisfies Meta<typeof DefaultStory>;
|
|
240
235
|
|
|
241
236
|
export default meta;
|
|
@@ -6,23 +6,19 @@ import '@dxos-theme';
|
|
|
6
6
|
|
|
7
7
|
import React, { type Dispatch, type FC, type RefObject, type SetStateAction } from 'react';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { ScrollContainer } from '@dxos/react-ui-components';
|
|
12
|
-
import { type DataType } from '@dxos/schema';
|
|
9
|
+
import { IconButton, ScrollContainer, Toolbar } from '@dxos/react-ui';
|
|
10
|
+
import { type Message } from '@dxos/types';
|
|
13
11
|
|
|
14
12
|
import { type SerializationModel } from '../../model';
|
|
15
|
-
import {
|
|
13
|
+
import { Transcription } from '../Transcription';
|
|
16
14
|
|
|
17
15
|
export const TranscriptionStory: FC<{
|
|
18
|
-
model: SerializationModel<
|
|
16
|
+
model: SerializationModel<Message.Message>;
|
|
19
17
|
disabled?: boolean;
|
|
20
18
|
running: boolean;
|
|
21
19
|
onRunningChange: Dispatch<SetStateAction<boolean>>;
|
|
22
20
|
audioRef?: RefObject<HTMLAudioElement | null>;
|
|
23
21
|
}> = ({ model, running, onRunningChange, audioRef, disabled }) => {
|
|
24
|
-
const space = useSpace();
|
|
25
|
-
|
|
26
22
|
return (
|
|
27
23
|
<div className='flex flex-col w-[30rem]'>
|
|
28
24
|
{audioRef && <audio ref={audioRef} autoPlay />}
|
|
@@ -36,9 +32,9 @@ export const TranscriptionStory: FC<{
|
|
|
36
32
|
/>
|
|
37
33
|
</Toolbar.Root>
|
|
38
34
|
<ScrollContainer.Root pin>
|
|
39
|
-
<ScrollContainer.
|
|
40
|
-
<
|
|
41
|
-
</ScrollContainer.
|
|
35
|
+
<ScrollContainer.Viewport>
|
|
36
|
+
<Transcription model={model} />
|
|
37
|
+
</ScrollContainer.Viewport>
|
|
42
38
|
</ScrollContainer.Root>
|
|
43
39
|
</div>
|
|
44
40
|
);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type SurfaceComponentProps } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
9
|
+
import { useMembers, useQueue } from '@dxos/react-client/echo';
|
|
10
|
+
import { Panel } from '@dxos/react-ui';
|
|
11
|
+
import { type Message, type Transcript } from '@dxos/types';
|
|
12
|
+
|
|
13
|
+
import { Transcription } from '../../components';
|
|
14
|
+
import { useQueueModelAdapter } from '../../hooks';
|
|
15
|
+
import { renderByline } from '../../util';
|
|
16
|
+
|
|
17
|
+
export type TranscriptionContainerProps = SurfaceComponentProps<Transcript.Transcript>;
|
|
18
|
+
|
|
19
|
+
export const TranscriptionContainer = ({ role, subject: transcript }: TranscriptionContainerProps) => {
|
|
20
|
+
const attendableId = Obj.getDXN(transcript).toString();
|
|
21
|
+
const db = Obj.getDatabase(transcript);
|
|
22
|
+
const members = useMembers(db?.spaceId).map((member) => member.identity);
|
|
23
|
+
const queue = useQueue<Message.Message>(transcript.queue.dxn, { pollInterval: 1_000 });
|
|
24
|
+
const model = useQueueModelAdapter(renderByline(members), queue);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Panel.Root role={role}>
|
|
28
|
+
<Panel.Content asChild>
|
|
29
|
+
<Transcription attendableId={attendableId} model={model} transcript={transcript} />
|
|
30
|
+
</Panel.Content>
|
|
31
|
+
</Panel.Root>
|
|
32
|
+
);
|
|
33
|
+
};
|
package/src/functions/index.ts
CHANGED
|
@@ -2,5 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import Open from './open';
|
|
6
|
+
import Summarize from './summarize';
|
|
7
|
+
|
|
8
|
+
export const TranscriptionFunctions = {
|
|
9
|
+
Open,
|
|
10
|
+
Summarize,
|
|
11
|
+
};
|
package/src/functions/open.ts
CHANGED
|
@@ -5,33 +5,31 @@
|
|
|
5
5
|
import * as Effect from 'effect/Effect';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { DataType } from '@dxos/schema';
|
|
8
|
+
import { Database, Obj, Ref } from '@dxos/echo';
|
|
9
|
+
import { QueueService, defineFunction } from '@dxos/functions';
|
|
10
|
+
import { Message, Transcript } from '@dxos/types';
|
|
12
11
|
|
|
13
|
-
import { renderByline } from '../
|
|
14
|
-
import { Transcript } from '../types';
|
|
12
|
+
import { renderByline } from '../util';
|
|
15
13
|
|
|
16
14
|
export default defineFunction({
|
|
17
15
|
key: 'dxos.org/function/transcription/open',
|
|
18
16
|
name: 'Open',
|
|
19
17
|
description: 'Opens and reads the contents of a transcription object.',
|
|
20
18
|
inputSchema: Schema.Struct({
|
|
21
|
-
|
|
19
|
+
transcript: Ref.Ref(Transcript.Transcript).annotations({
|
|
22
20
|
description: 'The ID of the transcription object.',
|
|
23
21
|
}),
|
|
24
22
|
}),
|
|
25
23
|
outputSchema: Schema.Struct({
|
|
26
24
|
content: Schema.String,
|
|
27
25
|
}),
|
|
28
|
-
handler: Effect.fn(function* ({ data: {
|
|
29
|
-
const
|
|
30
|
-
const { dxn } = yield* Effect.promise(() =>
|
|
26
|
+
handler: Effect.fn(function* ({ data: { transcript } }) {
|
|
27
|
+
const transcriptObj = yield* Database.load(transcript);
|
|
28
|
+
const { dxn } = yield* Effect.promise(() => transcriptObj.queue.load());
|
|
31
29
|
const queue = yield* QueueService.getQueue(dxn);
|
|
32
30
|
yield* Effect.promise(() => queue?.queryObjects());
|
|
33
31
|
const content = queue?.objects
|
|
34
|
-
.filter((message) => Obj.instanceOf(
|
|
32
|
+
.filter((message) => Obj.instanceOf(Message.Message, message))
|
|
35
33
|
.flatMap((message, index) => renderByline([])(message, index))
|
|
36
34
|
.join('\n\n');
|
|
37
35
|
return { content };
|
|
@@ -12,7 +12,7 @@ import { type ChunkRenderer, SerializationModel } from '../model';
|
|
|
12
12
|
/**
|
|
13
13
|
* Model adapter for a queue.
|
|
14
14
|
*/
|
|
15
|
-
export const useQueueModelAdapter = <T extends Obj.
|
|
15
|
+
export const useQueueModelAdapter = <T extends Obj.Unknown>(
|
|
16
16
|
renderer: ChunkRenderer<T>,
|
|
17
17
|
queue: Queue<T> | undefined,
|
|
18
18
|
initialChunks: T[] = [],
|
|
@@ -4,10 +4,10 @@
|
|
|
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/ui';
|
|
8
8
|
|
|
9
|
-
import { TranscriptionCapabilities } from '../capabilities';
|
|
10
9
|
import { type Transcriber } from '../transcriber';
|
|
10
|
+
import { TranscriptionCapabilities } from '../types';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Records audio while user is speaking and transcribes it after user is done speaking.
|
|
@@ -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(() => {
|
|
@@ -9,7 +9,7 @@ import { Context } from '@dxos/context';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { useSoundEffect } from '@dxos/react-ui-sfx';
|
|
11
11
|
|
|
12
|
-
import { type
|
|
12
|
+
import { type TranscriberProps } from '../transcriber';
|
|
13
13
|
|
|
14
14
|
import { useAudioTrack } from './useAudioTrack';
|
|
15
15
|
import { useTranscriber } from './useTranscriber';
|
|
@@ -26,7 +26,7 @@ export const useVoiceInput = ({ active, onUpdate }: UseVoiceInputProps) => {
|
|
|
26
26
|
const soundStart = useSoundEffect('StartRecording');
|
|
27
27
|
const soundStop = useSoundEffect('StopRecording');
|
|
28
28
|
|
|
29
|
-
const handleSegments = useCallback<
|
|
29
|
+
const handleSegments = useCallback<TranscriberProps['onSegments']>(async (segments) => {
|
|
30
30
|
const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, '')).join(' ');
|
|
31
31
|
onUpdate(text);
|
|
32
32
|
}, []);
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
6
7
|
|
|
7
|
-
export const meta:
|
|
8
|
+
export const meta: Plugin.Meta = {
|
|
8
9
|
id: 'dxos.org/plugin/transcription',
|
|
9
10
|
name: 'Transcription',
|
|
10
|
-
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
|
+
`,
|
|
11
15
|
icon: 'ph--microphone--regular',
|
|
16
|
+
iconHue: 'sky',
|
|
12
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-transcription',
|
|
13
18
|
tags: ['labs'],
|
|
14
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: [
|
|
@@ -51,7 +51,9 @@ describe('SerializationModel', () => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Update message.
|
|
54
|
-
|
|
54
|
+
Obj.change(message, (m) => {
|
|
55
|
+
m.blocks.push({ _tag: 'transcript', started: createDate(), text: 'Hello again!' });
|
|
56
|
+
});
|
|
55
57
|
model.updateChunk(message);
|
|
56
58
|
{
|
|
57
59
|
const text = model.doc.toString();
|
|
@@ -62,14 +64,14 @@ describe('SerializationModel', () => {
|
|
|
62
64
|
|
|
63
65
|
test('sync - append', ({ expect }) => {
|
|
64
66
|
const view = new EditorView({ extensions: [], doc: '' });
|
|
65
|
-
const model = new SerializationModel<
|
|
67
|
+
const model = new SerializationModel<Message.Message>(blockToMarkdown);
|
|
66
68
|
const adapter = new DocumentAdapter(view);
|
|
67
69
|
expect(adapter.lineCount()).to.eq(0);
|
|
68
70
|
expect(view.state.doc.toString()).to.eq('');
|
|
69
71
|
|
|
70
72
|
// Append message.
|
|
71
73
|
{
|
|
72
|
-
const message = Obj.make(
|
|
74
|
+
const message = Obj.make(Message.Message, {
|
|
73
75
|
created: createDate(),
|
|
74
76
|
sender: { name: 'Alice' },
|
|
75
77
|
blocks: [
|
|
@@ -87,7 +89,7 @@ describe('SerializationModel', () => {
|
|
|
87
89
|
|
|
88
90
|
// Append message.
|
|
89
91
|
{
|
|
90
|
-
const message = Obj.make(
|
|
92
|
+
const message = Obj.make(Message.Message, {
|
|
91
93
|
created: createDate(),
|
|
92
94
|
sender: { name: 'Bob' },
|
|
93
95
|
blocks: [
|
|
@@ -106,7 +108,7 @@ describe('SerializationModel', () => {
|
|
|
106
108
|
|
|
107
109
|
test('sync - append, update, delete', ({ expect }) => {
|
|
108
110
|
const view = new EditorView({ extensions: [], doc: '' });
|
|
109
|
-
const model = new SerializationModel<
|
|
111
|
+
const model = new SerializationModel<Message.Message>(blockToMarkdown);
|
|
110
112
|
const adapter = new DocumentAdapter(view);
|
|
111
113
|
expect(adapter.lineCount()).to.eq(0);
|
|
112
114
|
|
|
@@ -114,7 +116,7 @@ describe('SerializationModel', () => {
|
|
|
114
116
|
|
|
115
117
|
// Append message.
|
|
116
118
|
{
|
|
117
|
-
const message = Obj.make(
|
|
119
|
+
const message = Obj.make(Message.Message, {
|
|
118
120
|
created: createDate(),
|
|
119
121
|
sender: { name: 'Alice' },
|
|
120
122
|
blocks: [
|
|
@@ -131,13 +133,17 @@ describe('SerializationModel', () => {
|
|
|
131
133
|
expect(view.state.doc.toString()).to.eq('###### Alice\nHello world!\n\n');
|
|
132
134
|
|
|
133
135
|
// Update message (add block).
|
|
134
|
-
|
|
136
|
+
Obj.change(message, (m) => {
|
|
137
|
+
m.blocks.push({ _tag: 'transcript', started: createDate(), text: 'Hello again!' });
|
|
138
|
+
});
|
|
135
139
|
model.updateChunk(message);
|
|
136
140
|
model.sync(adapter);
|
|
137
141
|
expect(view.state.doc.toString()).to.eq('###### Alice\nHello world!\nHello again!\n\n');
|
|
138
142
|
|
|
139
143
|
// Update message (remove block).
|
|
140
|
-
|
|
144
|
+
Obj.change(message, (m) => {
|
|
145
|
+
m.blocks.splice(0, 1);
|
|
146
|
+
});
|
|
141
147
|
model.updateChunk(message);
|
|
142
148
|
model.sync(adapter);
|
|
143
149
|
expect(view.state.doc.toString()).to.eq('###### Alice\nHello again!\n\n');
|
|
@@ -147,7 +153,7 @@ describe('SerializationModel', () => {
|
|
|
147
153
|
|
|
148
154
|
// Append message.
|
|
149
155
|
{
|
|
150
|
-
const message = Obj.make(
|
|
156
|
+
const message = Obj.make(Message.Message, {
|
|
151
157
|
created: createDate(),
|
|
152
158
|
sender: { name: 'Bob' },
|
|
153
159
|
blocks: [{ _tag: 'transcript', started: createDate(), text: 'Hello again!' }],
|
|
@@ -6,24 +6,22 @@
|
|
|
6
6
|
// Copyright 2025 DXOS.org
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
import { effect } from '@preact/signals-core';
|
|
10
|
-
|
|
11
9
|
import { DeferredTask, asyncTimeout } from '@dxos/async';
|
|
12
10
|
import { LifecycleState, Resource } from '@dxos/context';
|
|
13
11
|
import { type Queue } from '@dxos/echo-db';
|
|
14
|
-
import { type FunctionExecutor } from '@dxos/functions';
|
|
12
|
+
import { type FunctionExecutor } from '@dxos/functions-runtime';
|
|
15
13
|
import { log } from '@dxos/log';
|
|
16
|
-
import { type
|
|
14
|
+
import { type Message } from '@dxos/types';
|
|
17
15
|
|
|
18
|
-
import { type MessageWithRangeId, sentenceNormalization } from './normalization';
|
|
16
|
+
import { type MessageWithRangeId, type NormalizationOutput, sentenceNormalization } from './normalization';
|
|
19
17
|
import { getActorId } from './utils';
|
|
20
18
|
|
|
21
19
|
const PROCESSING_TIMEOUT = 20_000; // ms
|
|
22
20
|
const MAX_RANGE_ID_COUNT = 10;
|
|
23
21
|
|
|
24
|
-
export type
|
|
22
|
+
export type SegmentsNormalizerProps = {
|
|
25
23
|
functionExecutor: FunctionExecutor;
|
|
26
|
-
queue: Queue<
|
|
24
|
+
queue: Queue<Message.Message>;
|
|
27
25
|
startingCursor: QueueCursor;
|
|
28
26
|
};
|
|
29
27
|
|
|
@@ -36,13 +34,13 @@ export type QueueCursor = {
|
|
|
36
34
|
// TODO(mykola): .
|
|
37
35
|
export class MessageNormalizer extends Resource {
|
|
38
36
|
private readonly _functionExecutor: FunctionExecutor;
|
|
39
|
-
private _queue: Queue<
|
|
37
|
+
private _queue: Queue<Message.Message>;
|
|
40
38
|
private _cursor: QueueCursor;
|
|
41
39
|
private _messagesToProcess: MessageWithRangeId[] = [];
|
|
42
40
|
private _normalizationTask?: DeferredTask;
|
|
43
41
|
private _lastProcessedMessageIds?: string[];
|
|
44
42
|
|
|
45
|
-
constructor({ functionExecutor, queue, startingCursor }:
|
|
43
|
+
constructor({ functionExecutor, queue, startingCursor }: SegmentsNormalizerProps) {
|
|
46
44
|
super();
|
|
47
45
|
this._functionExecutor = functionExecutor;
|
|
48
46
|
this._queue = queue;
|
|
@@ -51,7 +49,8 @@ export class MessageNormalizer extends Resource {
|
|
|
51
49
|
|
|
52
50
|
protected override async _open(): Promise<void> {
|
|
53
51
|
this._normalizationTask = new DeferredTask(this._ctx, () => this._processMessages());
|
|
54
|
-
|
|
52
|
+
|
|
53
|
+
const updateMessages = () => {
|
|
55
54
|
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
56
55
|
return;
|
|
57
56
|
}
|
|
@@ -62,8 +61,14 @@ export class MessageNormalizer extends Resource {
|
|
|
62
61
|
});
|
|
63
62
|
|
|
64
63
|
this._normalizationTask!.schedule();
|
|
65
|
-
}
|
|
66
|
-
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Initial update.
|
|
67
|
+
updateMessages();
|
|
68
|
+
|
|
69
|
+
// Subscribe to queue changes.
|
|
70
|
+
const unsubscribe = this._queue.subscribe(updateMessages);
|
|
71
|
+
this._ctx.onDispose(unsubscribe);
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
// Need to unpack strings from blocks from messages run them through the function and then pack them back into blocks into messages.
|
|
@@ -81,7 +86,7 @@ export class MessageNormalizer extends Resource {
|
|
|
81
86
|
|
|
82
87
|
try {
|
|
83
88
|
// TODO(mykola): Executor should support timeout.
|
|
84
|
-
const response = await asyncTimeout(
|
|
89
|
+
const response: NormalizationOutput = await asyncTimeout(
|
|
85
90
|
this._functionExecutor.invoke(sentenceNormalization, { messages }),
|
|
86
91
|
PROCESSING_TIMEOUT,
|
|
87
92
|
);
|