@dxos/plugin-transcription 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5
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/blueprints/index.mjs +31 -0
- package/dist/lib/browser/blueprints/index.mjs.map +7 -0
- package/dist/lib/browser/chunk-5LWSJZTZ.mjs +17 -0
- package/dist/lib/browser/chunk-5LWSJZTZ.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/chunk-KOX4WNAR.mjs +111 -0
- package/dist/lib/browser/chunk-KOX4WNAR.mjs.map +7 -0
- package/dist/lib/browser/create-BTWYQ6IM.mjs +21 -0
- package/dist/lib/browser/create-BTWYQ6IM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1181 -93
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/open-CYRYIEZI.mjs +27 -0
- package/dist/lib/browser/open-CYRYIEZI.mjs.map +7 -0
- package/dist/lib/browser/operations/index.mjs +13 -0
- package/dist/lib/browser/operations/index.mjs.map +7 -0
- package/dist/lib/browser/summarize-X2ZYTN7S.mjs +79 -0
- package/dist/lib/browser/summarize-X2ZYTN7S.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -8
- package/dist/lib/node-esm/blueprints/index.mjs +32 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-MT5I4NH5.mjs +112 -0
- package/dist/lib/node-esm/chunk-MT5I4NH5.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/chunk-X74WYCCE.mjs +19 -0
- package/dist/lib/node-esm/chunk-X74WYCCE.mjs.map +7 -0
- package/dist/lib/node-esm/create-MLUFPST2.mjs +22 -0
- package/dist/lib/node-esm/create-MLUFPST2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1181 -93
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/open-5IOC2U4Z.mjs +28 -0
- package/dist/lib/node-esm/open-5IOC2U4Z.mjs.map +7 -0
- package/dist/lib/node-esm/operations/index.mjs +14 -0
- package/dist/lib/node-esm/operations/index.mjs.map +7 -0
- package/dist/lib/node-esm/summarize-IORITU7T.mjs +80 -0
- package/dist/lib/node-esm/summarize-IORITU7T.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +4 -8
- 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.d.ts +6 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +6 -4
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/transcriber.d.ts +4 -3
- package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
- package/dist/types/src/components/Transcription/Transcription.d.ts +18 -0
- package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -0
- package/dist/types/src/components/Transcription/Transcription.stories.d.ts +40 -0
- 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 +8 -7
- package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +10 -6
- package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +11 -10
- package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -1
- package/dist/types/src/components/stories/TranscriptionStory.d.ts +4 -3
- 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 +2 -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/hooks/useAudioFile.d.ts.map +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 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/create.d.ts +5 -0
- package/dist/types/src/operations/create.d.ts.map +1 -0
- package/dist/types/src/operations/definitions.d.ts +917 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/open.d.ts +5 -0
- package/dist/types/src/operations/open.d.ts.map +1 -0
- package/dist/types/src/operations/summarize.d.ts +8 -0
- package/dist/types/src/operations/summarize.d.ts.map +1 -0
- 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 +363 -328
- 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 +10 -10
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/transcriber/index.d.ts +1 -1
- package/dist/types/src/transcriber/index.d.ts.map +1 -1
- package/dist/types/src/transcriber/media-stream-recorder.d.ts +3 -3
- 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 +12 -13
- package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +7 -7
- package/dist/types/src/translations.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 +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +0 -26
- package/dist/types/src/types/types.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 +109 -73
- package/src/TranscriptionPlugin.tsx +46 -59
- package/src/blueprints/index.ts +5 -0
- package/src/blueprints/transcription-blueprint.ts +30 -0
- package/src/capabilities/blueprint-definition.ts +17 -0
- package/src/capabilities/index.ts +9 -6
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +23 -14
- package/src/capabilities/transcriber.ts +52 -42
- package/src/components/{Transcript/Transcript.stories.tsx → Transcription/Transcription.stories.tsx} +73 -66
- package/src/components/Transcription/Transcription.tsx +64 -0
- package/src/components/{Transcript → Transcription}/index.ts +1 -1
- package/src/components/{Transcript/transcript-extension.ts → Transcription/transcription-extension.ts} +15 -48
- package/src/components/index.ts +1 -6
- package/src/components/stories/FileTranscription.stories.tsx +78 -70
- package/src/components/stories/KeyWordRecognition.stories.tsx +17 -13
- package/src/components/stories/MicrophoneTranscription.stories.tsx +84 -100
- package/src/components/stories/TranscriptionStory.tsx +15 -13
- package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +35 -0
- package/src/containers/TranscriptionContainer/index.ts +5 -0
- package/src/containers/index.ts +7 -0
- package/src/hooks/useAudioFile.ts +49 -53
- package/src/hooks/useQueueModelAdapter.ts +1 -1
- package/src/hooks/useTranscriber.ts +9 -3
- package/src/hooks/useVoiceInput.ts +3 -3
- package/src/index.ts +1 -1
- package/src/meta.ts +9 -6
- package/src/model/model.test.ts +27 -21
- package/src/operations/create.ts +24 -0
- package/src/operations/definitions.ts +101 -0
- package/src/operations/index.ts +13 -0
- package/src/operations/open.ts +28 -0
- package/src/operations/summarize.ts +102 -0
- package/src/segments-normalization/message-normalizer.ts +19 -14
- package/src/segments-normalization/normalization.test.ts +26 -33
- package/src/segments-normalization/normalization.ts +67 -96
- package/src/segments-normalization/utils.ts +2 -2
- package/src/testing/testing.ts +41 -41
- package/src/transcriber/index.ts +1 -1
- package/src/transcriber/media-stream-recorder.ts +4 -4
- package/src/transcriber/transcriber.browser.test.ts +5 -5
- package/src/transcriber/transcriber.ts +10 -12
- package/src/transcriber/transcription-manager.ts +37 -52
- package/src/translations.ts +7 -7
- package/src/types/capabilities.ts +34 -0
- package/src/types/index.ts +1 -1
- package/src/types/types.ts +0 -23
- package/src/util/index.ts +1 -0
- package/src/util/render-byline.ts +33 -0
- package/dist/lib/browser/TranscriptContainer-E5NBJPAY.mjs +0 -11
- package/dist/lib/browser/chunk-5WH45KBY.mjs +0 -19
- package/dist/lib/browser/chunk-5WH45KBY.mjs.map +0 -7
- package/dist/lib/browser/chunk-EQBICGOD.mjs +0 -8
- package/dist/lib/browser/chunk-EQBICGOD.mjs.map +0 -7
- package/dist/lib/browser/chunk-F2WY3YTD.mjs +0 -764
- package/dist/lib/browser/chunk-F2WY3YTD.mjs.map +0 -7
- package/dist/lib/browser/chunk-R7INNNUQ.mjs +0 -55
- package/dist/lib/browser/chunk-R7INNNUQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-U6QBOGTN.mjs +0 -16
- package/dist/lib/browser/chunk-U6QBOGTN.mjs.map +0 -7
- package/dist/lib/browser/chunk-VDKDOZRR.mjs +0 -495
- package/dist/lib/browser/chunk-VDKDOZRR.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-3O33MMP5.mjs +0 -30
- package/dist/lib/browser/intent-resolver-3O33MMP5.mjs.map +0 -7
- package/dist/lib/browser/react-surface-FJTMNF3K.mjs +0 -34
- package/dist/lib/browser/react-surface-FJTMNF3K.mjs.map +0 -7
- package/dist/lib/browser/transcriber-YVOTUBKQ.mjs +0 -56
- package/dist/lib/browser/transcriber-YVOTUBKQ.mjs.map +0 -7
- package/dist/lib/node-esm/TranscriptContainer-UOS7JG72.mjs +0 -12
- package/dist/lib/node-esm/chunk-DN522SAP.mjs +0 -10
- package/dist/lib/node-esm/chunk-DN522SAP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSCG4XPR.mjs +0 -496
- package/dist/lib/node-esm/chunk-HSCG4XPR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Q3JKLPTW.mjs +0 -765
- package/dist/lib/node-esm/chunk-Q3JKLPTW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RHF2ALML.mjs +0 -17
- package/dist/lib/node-esm/chunk-RHF2ALML.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-U65ZWK3L.mjs +0 -56
- package/dist/lib/node-esm/chunk-U65ZWK3L.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XMUCZBP3.mjs +0 -21
- package/dist/lib/node-esm/chunk-XMUCZBP3.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs +0 -31
- package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-57TSIDR2.mjs +0 -35
- package/dist/lib/node-esm/react-surface-57TSIDR2.mjs.map +0 -7
- package/dist/lib/node-esm/transcriber-GPBV52ZR.mjs +0 -57
- package/dist/lib/node-esm/transcriber-GPBV52ZR.mjs.map +0 -7
- 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/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 +0 -24
- 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 -19
- 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/schema.d.ts +0 -41
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/capabilities/capabilities.ts +0 -33
- package/src/capabilities/intent-resolver.ts +0 -24
- package/src/components/Transcript/Transcript.tsx +0 -100
- package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
- package/src/components/TranscriptContainer.tsx +0 -35
- package/src/types/schema.ts +0 -41
- /package/dist/lib/browser/{TranscriptContainer-E5NBJPAY.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/node-esm/{TranscriptContainer-UOS7JG72.mjs.map → chunk-HSLMI22Q.mjs.map} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Function from 'effect/Function';
|
|
8
|
+
import * as Layer from 'effect/Layer';
|
|
9
|
+
import * as Option from 'effect/Option';
|
|
10
|
+
|
|
11
|
+
import { AiService, ConsolePrinter, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
12
|
+
import { AiRequest, GenerationObserver } from '@dxos/assistant';
|
|
13
|
+
import { Database } from '@dxos/echo';
|
|
14
|
+
import * as Trace from '@dxos/functions/Trace';
|
|
15
|
+
import { Operation, OperationRegistry } from '@dxos/operation';
|
|
16
|
+
import { trim } from '@dxos/util';
|
|
17
|
+
|
|
18
|
+
import { Summarize } from './definitions';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Summarize a transcript of a meeting.
|
|
22
|
+
*/
|
|
23
|
+
const handler: Operation.WithHandler<typeof Summarize> = Summarize.pipe(
|
|
24
|
+
Operation.withHandler(
|
|
25
|
+
Effect.fnUntraced(
|
|
26
|
+
function* ({ transcript, notes }) {
|
|
27
|
+
const result = yield* new AiRequest({
|
|
28
|
+
observer: GenerationObserver.fromPrinter(new ConsolePrinter({ tag: 'summarize' })),
|
|
29
|
+
}).run({
|
|
30
|
+
prompt: `Transcript: ${transcript}\n\nNotes: ${notes}`,
|
|
31
|
+
history: [],
|
|
32
|
+
system: systemPrompt,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const summary = Function.pipe(
|
|
36
|
+
result,
|
|
37
|
+
Array.findLast((msg) => msg.sender.role === 'assistant' && msg.blocks.some((block) => block._tag === 'text')),
|
|
38
|
+
Option.flatMap((msg) =>
|
|
39
|
+
Function.pipe(
|
|
40
|
+
msg.blocks,
|
|
41
|
+
Array.findLast((block) => block._tag === 'text'),
|
|
42
|
+
Option.map((block) => block.text),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
Option.getOrThrowWith(() => new Error('No summary found')),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return { summary };
|
|
49
|
+
},
|
|
50
|
+
Effect.provide(
|
|
51
|
+
Layer.mergeAll(
|
|
52
|
+
AiService.model('@anthropic/claude-sonnet-4-0'),
|
|
53
|
+
ToolResolverService.layerEmpty,
|
|
54
|
+
ToolExecutionService.layerEmpty,
|
|
55
|
+
Trace.writerLayerNoop,
|
|
56
|
+
Database.notAvailable,
|
|
57
|
+
Layer.succeed(Operation.Service, {
|
|
58
|
+
invoke: () => Effect.die('Not available.'),
|
|
59
|
+
schedule: () => Effect.die('Not available.'),
|
|
60
|
+
invokePromise: async () => ({ error: new Error('Not available.') }),
|
|
61
|
+
} as any),
|
|
62
|
+
Layer.succeed(OperationRegistry.Service, { resolve: () => Effect.succeed(undefined) } as any),
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
export default handler;
|
|
70
|
+
|
|
71
|
+
const systemPrompt = trim`
|
|
72
|
+
You are a helpful assistant that summarizes transcripts of meetings.
|
|
73
|
+
|
|
74
|
+
# Goal
|
|
75
|
+
Create a markdown summary of the meeting transcript with text notes provided.
|
|
76
|
+
Notes are very important so make sure to include them in the summary if they contain meaningful information.
|
|
77
|
+
|
|
78
|
+
# Formatting
|
|
79
|
+
- Format the summary as a markdown document without extra comments like "Here is the summary of the transcript:".
|
|
80
|
+
- Use markdown formatting for headings and bullet points.
|
|
81
|
+
- Format the summary as a list of key points and takeaways.
|
|
82
|
+
- All names of people should be in bold.
|
|
83
|
+
|
|
84
|
+
# Note Taking
|
|
85
|
+
- Correlate items in the summary with the person of origin to build a coherent narrative.
|
|
86
|
+
- Include short quotes verbatim where appropriate. Especially when concerned with design decisions and problem descriptions.
|
|
87
|
+
|
|
88
|
+
# Tasks
|
|
89
|
+
At the end of the summary include tasks.
|
|
90
|
+
Extract only the tasks that are:
|
|
91
|
+
- Directly actionable.
|
|
92
|
+
- Clearly assigned to a person or team (or can easily be inferred).
|
|
93
|
+
- Strongly implied by the conversation and/or user note (no speculative tasks).
|
|
94
|
+
- Specific enough that someone reading them would know exactly what to do next.
|
|
95
|
+
|
|
96
|
+
Format all tasks as markdown checkboxes using the syntax:
|
|
97
|
+
- [ ] Task description.
|
|
98
|
+
|
|
99
|
+
Additional information can be included (indented).
|
|
100
|
+
|
|
101
|
+
If no actionable tasks are found, omit this tasks section.
|
|
102
|
+
`;
|
|
@@ -6,24 +6,22 @@
|
|
|
6
6
|
// Copyright 2025 DXOS.org
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { asyncTimeout, DeferredTask } from '@dxos/async';
|
|
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
|
);
|
|
@@ -2,25 +2,22 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { effect } from '@preact/signals-core';
|
|
6
5
|
import { describe, test } from 'vitest';
|
|
7
6
|
|
|
8
|
-
import { EdgeAiServiceClient, OllamaAiServiceClient } from '@dxos/ai';
|
|
9
|
-
import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
|
|
10
7
|
import { scheduleTaskInterval } from '@dxos/async';
|
|
11
8
|
import { Context } from '@dxos/context';
|
|
12
9
|
import { Obj } from '@dxos/echo';
|
|
13
10
|
import { MemoryQueue } from '@dxos/echo-db';
|
|
14
|
-
import { createQueueDXN } from '@dxos/echo
|
|
15
|
-
import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
|
|
11
|
+
import { createQueueDXN } from '@dxos/echo/internal';
|
|
12
|
+
import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
|
|
16
13
|
import { log } from '@dxos/log';
|
|
17
|
-
import {
|
|
14
|
+
import { type Actor, Message } from '@dxos/types';
|
|
18
15
|
|
|
19
16
|
import { MessageNormalizer } from './message-normalizer';
|
|
20
17
|
import { type MessageWithRangeId, sentenceNormalization } from './normalization';
|
|
21
18
|
import { getActorId } from './utils';
|
|
22
19
|
|
|
23
|
-
const sender:
|
|
20
|
+
const sender: Actor.Actor = {
|
|
24
21
|
identityDid: 'did:key:123',
|
|
25
22
|
};
|
|
26
23
|
|
|
@@ -50,34 +47,33 @@ const messages: MessageWithRangeId[] = [
|
|
|
50
47
|
// No punctuation.
|
|
51
48
|
'in classical physics objects have well-defined properties such as position speed and momentum',
|
|
52
49
|
].map((string, index) =>
|
|
53
|
-
Obj.make(
|
|
54
|
-
created: new Date(Date.now() +
|
|
50
|
+
Obj.make(Message.Message, {
|
|
51
|
+
created: new Date(Date.now() + 1_000 * index).toISOString(),
|
|
55
52
|
sender,
|
|
56
|
-
blocks: [{
|
|
57
|
-
|
|
58
|
-
} as any),
|
|
53
|
+
blocks: [{ _tag: 'transcript', started: new Date(Date.now() + 1_000 * index).toISOString(), text: string }],
|
|
54
|
+
}),
|
|
59
55
|
);
|
|
60
56
|
|
|
61
|
-
const REMOTE_AI = true;
|
|
57
|
+
// const REMOTE_AI = true;
|
|
62
58
|
|
|
63
59
|
describe.skip('SentenceNormalization', () => {
|
|
64
60
|
const getExecutor = () => {
|
|
65
61
|
return new FunctionExecutor(
|
|
66
62
|
new ServiceContainer().setServices({
|
|
67
|
-
ai: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
63
|
+
// ai: {
|
|
64
|
+
// client: REMOTE_AI
|
|
65
|
+
// ? new Edge AiServiceClient({
|
|
66
|
+
// endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
67
|
+
// defaultGenerationOptions: {
|
|
68
|
+
// model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
69
|
+
// },
|
|
70
|
+
// })
|
|
71
|
+
// : new Ollama AiServiceClient({
|
|
72
|
+
// overrides: {
|
|
73
|
+
// model: 'llama3.1:8b',
|
|
74
|
+
// },
|
|
75
|
+
// }),
|
|
76
|
+
// },
|
|
81
77
|
}),
|
|
82
78
|
);
|
|
83
79
|
};
|
|
@@ -100,8 +96,9 @@ describe.skip('SentenceNormalization', () => {
|
|
|
100
96
|
buffer = sentences.slice(activeSentenceIndex);
|
|
101
97
|
}
|
|
102
98
|
}
|
|
99
|
+
|
|
103
100
|
log.info('sentences', {
|
|
104
|
-
|
|
101
|
+
messages: JSON.stringify(messages, null, 2),
|
|
105
102
|
sentences: JSON.stringify(sentences, null, 2),
|
|
106
103
|
});
|
|
107
104
|
throw new Error('test');
|
|
@@ -110,7 +107,7 @@ describe.skip('SentenceNormalization', () => {
|
|
|
110
107
|
test.only('queue', { timeout: 120_000 }, async () => {
|
|
111
108
|
// Create queue.
|
|
112
109
|
// TODO(dmaretskyi): Use space.queues.create() instead.
|
|
113
|
-
const queue = new MemoryQueue<
|
|
110
|
+
const queue = new MemoryQueue<Message.Message>(createQueueDXN());
|
|
114
111
|
const ctx = new Context();
|
|
115
112
|
let idx = 0;
|
|
116
113
|
scheduleTaskInterval(
|
|
@@ -135,10 +132,6 @@ describe.skip('SentenceNormalization', () => {
|
|
|
135
132
|
|
|
136
133
|
// Start normalizer.
|
|
137
134
|
await normalizer.open();
|
|
138
|
-
effect(() => {
|
|
139
|
-
log.info('normalizer');
|
|
140
|
-
log.info(JSON.stringify(queue.objects, null, 2));
|
|
141
|
-
});
|
|
142
135
|
|
|
143
136
|
await new Promise(() => {});
|
|
144
137
|
});
|
|
@@ -2,105 +2,76 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
6
7
|
|
|
7
|
-
import { DEFAULT_EDGE_MODEL, Message } from '@dxos/ai';
|
|
8
|
-
import { AISession } from '@dxos/assistant';
|
|
9
|
-
import { Obj } from '@dxos/echo';
|
|
10
|
-
import { AiService, defineFunction, ToolResolverService } from '@dxos/functions';
|
|
11
|
-
import { ObjectId } from '@dxos/keys';
|
|
12
8
|
import { log } from '@dxos/log';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
10
|
+
import { trim } from '@dxos/util';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
SentenceNormalization,
|
|
14
|
+
SentenceNormalizationOutput,
|
|
15
|
+
type MessageWithRangeIdType,
|
|
16
|
+
type SentenceNormalizationInputType,
|
|
17
|
+
} from '../operations/definitions';
|
|
18
|
+
|
|
19
|
+
export type MessageWithRangeId = MessageWithRangeIdType;
|
|
20
|
+
|
|
21
|
+
/** @deprecated Use SentenceNormalizationInputType */
|
|
22
|
+
export type NormalizationInput = SentenceNormalizationInputType;
|
|
23
|
+
|
|
24
|
+
/** @deprecated Use SentenceNormalizationOutput */
|
|
25
|
+
export type NormalizationOutput = Schema.Schema.Type<typeof SentenceNormalizationOutput>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sentence normalization for transcription.
|
|
29
|
+
* TODO(dmaretskyi): Reimplement using AiRequest.run or LanguageModel.generateObject - runStructured was removed.
|
|
30
|
+
*/
|
|
31
|
+
export const sentenceNormalization = SentenceNormalization.pipe(
|
|
32
|
+
Operation.withHandler(
|
|
33
|
+
Effect.fn(function* ({ messages }) {
|
|
34
|
+
log.info('input', { messages });
|
|
35
|
+
// TODO(dmaretskyi): runStructured was removed from AiRequest. Reimplement using new API.
|
|
36
|
+
return yield* Effect.die(
|
|
37
|
+
new Error(
|
|
38
|
+
'Sentence normalization needs to be reimplemented - runStructured was removed from AiRequest. Use AiRequest.run or LanguageModel.generateObject.',
|
|
39
|
+
),
|
|
40
|
+
);
|
|
21
41
|
}),
|
|
22
|
-
|
|
42
|
+
),
|
|
23
43
|
);
|
|
24
44
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# Segment Handling Rules:
|
|
58
|
-
- Sort messages by timestamp.
|
|
59
|
-
- Leave ID of the first message in a sentence.
|
|
60
|
-
- Each divided sentence should be added to the output as a separate message or block within existing messages, preserving the original order.
|
|
61
|
-
- If one message contains multiple sentences, you should not split them.
|
|
62
|
-
- The last sentence may be incomplete; it should still be output as a separate block or message.
|
|
63
|
-
- Keep track of the original timestamps of the messages and blocks and, use the timestamp of the first message/block of a sentence as the 'started' field of the merged message.
|
|
64
|
-
- The 'rangeId' field of the merged message should include 'messageId'-s and 'rangeId'-s of all messages that have been used to construct this message.
|
|
65
|
-
|
|
66
|
-
# Punctuation and Capitalization:
|
|
67
|
-
- Do not rely on the original punctuation and capitalization—they may be incorrect.
|
|
68
|
-
- Use logical reasoning to apply appropriate punctuation (e.g., period, comma, question mark, exclamation mark) and capitalization.
|
|
69
|
-
|
|
70
|
-
# Restrictions:
|
|
71
|
-
- Do not alter the order of the original messages; maintain the natural flow of speech.
|
|
72
|
-
- Do not interpret or infer meaning beyond reconstructing sentences.
|
|
73
|
-
- Do not add or remove any words or phrases.
|
|
45
|
+
const _unusedPrompt = trim`
|
|
46
|
+
You are observing a real-time transcript of a single person speaking.
|
|
47
|
+
The transcription is delivered in chunks of 10 seconds or less. As a result, individual sentences may be split across multiple messages, or multiple sentences may appear within a single message. Additionally, because this is real-time transcription, punctuation and capitalization may be incorrect or missing.
|
|
48
|
+
|
|
49
|
+
# Task Description:
|
|
50
|
+
- Your task is to detect and reconstruct broken or incomplete sentences by merging segments into coherent, grammatically correct sentences where appropriate.
|
|
51
|
+
|
|
52
|
+
# Input Format:
|
|
53
|
+
- The input is an array of messages that contain transcription blocks.
|
|
54
|
+
- Each message is a Message.Message, as described in the output format.
|
|
55
|
+
|
|
56
|
+
# Output Format:
|
|
57
|
+
- You have been provided with the tool that defines the output format; make sure to query it.
|
|
58
|
+
- Do not output anything other than the expected format.
|
|
59
|
+
|
|
60
|
+
# Segment Handling Rules:
|
|
61
|
+
- Sort messages by timestamp.
|
|
62
|
+
- Leave ID of the first message in a sentence.
|
|
63
|
+
- Each divided sentence should be added to the output as a separate message or block within existing messages, preserving the original order.
|
|
64
|
+
- If one message contains multiple sentences, you should not split them.
|
|
65
|
+
- The last sentence may be incomplete; it should still be output as a separate block or message.
|
|
66
|
+
- Keep track of the original timestamps of the messages and blocks and, use the timestamp of the first message/block of a sentence as the 'started' field of the merged message.
|
|
67
|
+
- The 'rangeId' field of the merged message should include 'messageId'-s and 'rangeId'-s of all messages that have been used to construct this message.
|
|
68
|
+
|
|
69
|
+
# Punctuation and Capitalization:
|
|
70
|
+
- Do not rely on the original punctuation and capitalization—they may be incorrect.
|
|
71
|
+
- Use logical reasoning to apply appropriate punctuation (e.g., period, comma, question mark, exclamation mark) and capitalization.
|
|
72
|
+
|
|
73
|
+
# Restrictions:
|
|
74
|
+
- Do not alter the order of the original messages; maintain the natural flow of speech.
|
|
75
|
+
- Do not interpret or infer meaning beyond reconstructing sentences.
|
|
76
|
+
- Do not add or remove any words or phrases.
|
|
74
77
|
`;
|
|
75
|
-
|
|
76
|
-
export const sentenceNormalization = defineFunction<NormalizationInput, NormalizationOutput>({
|
|
77
|
-
description: 'Post process of transcription for sentence normalization',
|
|
78
|
-
inputSchema: NormalizationInput,
|
|
79
|
-
outputSchema: NormalizationOutput,
|
|
80
|
-
handler: async ({ data: { messages }, context }) => {
|
|
81
|
-
log.info('input', { messages });
|
|
82
|
-
const ai = context.getService(AiService);
|
|
83
|
-
const session = new AISession({ operationModel: 'configured' });
|
|
84
|
-
|
|
85
|
-
const response = await session.runStructured(NormalizationOutput, {
|
|
86
|
-
generationOptions: { model: DEFAULT_EDGE_MODEL },
|
|
87
|
-
client: ai.client,
|
|
88
|
-
tools: [],
|
|
89
|
-
artifacts: [],
|
|
90
|
-
history: [
|
|
91
|
-
Obj.make(Message, {
|
|
92
|
-
role: 'user',
|
|
93
|
-
content: messages.map((message) => ({ type: 'text', text: JSON.stringify(message) }) as const),
|
|
94
|
-
}),
|
|
95
|
-
],
|
|
96
|
-
prompt,
|
|
97
|
-
toolResolver: context.getService(ToolResolverService).toolResolver,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
response.sentences.forEach((sentence) => {
|
|
101
|
-
sentence.id = ObjectId.random();
|
|
102
|
-
});
|
|
103
|
-
log.info('response', { response });
|
|
104
|
-
return response;
|
|
105
|
-
},
|
|
106
|
-
});
|
|
@@ -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
|
};
|