@dxos/plugin-transcription 0.8.4-main.2e9d522 → 0.8.4-main.548089c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/lib/browser/TranscriptContainer-EKSP5DQ6.mjs +11 -0
  2. package/dist/lib/browser/blueprint-definition-WBWHO4OH.mjs +150 -0
  3. package/dist/lib/browser/blueprint-definition-WBWHO4OH.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-U6QBOGTN.mjs → chunk-3MKZ2MNQ.mjs} +5 -5
  5. package/dist/lib/browser/chunk-3MKZ2MNQ.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-5KPYIC3N.mjs → chunk-EHT3TE6U.mjs} +341 -366
  7. package/dist/lib/browser/chunk-EHT3TE6U.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-4FJIYH7T.mjs → chunk-OCI42DWB.mjs} +2 -2
  9. package/dist/lib/browser/{chunk-FFEPEPCU.mjs → chunk-PVU4XCKI.mjs} +51 -80
  10. package/dist/lib/browser/chunk-PVU4XCKI.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-VBUIO677.mjs +29 -0
  12. package/dist/lib/browser/chunk-VBUIO677.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-W7WKZTM4.mjs +63 -0
  14. package/dist/lib/browser/chunk-W7WKZTM4.mjs.map +7 -0
  15. package/dist/lib/browser/index.mjs +25 -20
  16. package/dist/lib/browser/index.mjs.map +3 -3
  17. package/dist/lib/browser/intent-resolver-ZTKTEAQX.mjs +25 -0
  18. package/dist/lib/browser/intent-resolver-ZTKTEAQX.mjs.map +7 -0
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/{react-surface-E5D5AE3F.mjs → react-surface-NARMYO2O.mjs} +10 -10
  21. package/dist/lib/browser/react-surface-NARMYO2O.mjs.map +7 -0
  22. package/dist/lib/browser/{transcriber-PXT4QBFY.mjs → transcriber-E2KAOXPS.mjs} +7 -7
  23. package/dist/lib/browser/transcriber-E2KAOXPS.mjs.map +7 -0
  24. package/dist/lib/browser/types/index.mjs +6 -8
  25. package/dist/lib/node-esm/{TranscriptContainer-VBAOM5DG.mjs → TranscriptContainer-WU3EDQR3.mjs} +4 -4
  26. package/dist/lib/node-esm/blueprint-definition-WUHZFRWZ.mjs +151 -0
  27. package/dist/lib/node-esm/blueprint-definition-WUHZFRWZ.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-TJKAO7VR.mjs → chunk-7XASA7DX.mjs} +341 -366
  29. package/dist/lib/node-esm/chunk-7XASA7DX.mjs.map +7 -0
  30. package/dist/lib/node-esm/chunk-OLMSTF3M.mjs +64 -0
  31. package/dist/lib/node-esm/chunk-OLMSTF3M.mjs.map +7 -0
  32. package/dist/lib/node-esm/{chunk-RHF2ALML.mjs → chunk-SWUVPFKR.mjs} +5 -5
  33. package/dist/lib/node-esm/chunk-SWUVPFKR.mjs.map +7 -0
  34. package/dist/lib/node-esm/{chunk-HT3W7LDP.mjs → chunk-UVOYXXDJ.mjs} +51 -80
  35. package/dist/lib/node-esm/chunk-UVOYXXDJ.mjs.map +7 -0
  36. package/dist/lib/node-esm/{chunk-Y2B4HWSS.mjs → chunk-X5BKN32O.mjs} +2 -2
  37. package/dist/lib/node-esm/chunk-YVNQN2J6.mjs +30 -0
  38. package/dist/lib/node-esm/chunk-YVNQN2J6.mjs.map +7 -0
  39. package/dist/lib/node-esm/index.mjs +25 -20
  40. package/dist/lib/node-esm/index.mjs.map +3 -3
  41. package/dist/lib/node-esm/intent-resolver-55WH2GY6.mjs +26 -0
  42. package/dist/lib/node-esm/intent-resolver-55WH2GY6.mjs.map +7 -0
  43. package/dist/lib/node-esm/meta.json +1 -1
  44. package/dist/lib/node-esm/{react-surface-QRDJOHN5.mjs → react-surface-5MQA3IUS.mjs} +10 -10
  45. package/dist/lib/node-esm/react-surface-5MQA3IUS.mjs.map +7 -0
  46. package/dist/lib/node-esm/{transcriber-YUTEVANE.mjs → transcriber-ZPJM4U2W.mjs} +7 -7
  47. package/dist/lib/node-esm/transcriber-ZPJM4U2W.mjs.map +7 -0
  48. package/dist/lib/node-esm/types/index.mjs +6 -8
  49. package/dist/types/src/TranscriptionPlugin.d.ts +1 -1
  50. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  51. package/dist/types/src/capabilities/blueprint-definition.d.ts +5 -0
  52. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  53. package/dist/types/src/capabilities/capabilities.d.ts +1 -1
  54. package/dist/types/src/capabilities/capabilities.d.ts.map +1 -1
  55. package/dist/types/src/capabilities/index.d.ts +3 -2
  56. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  58. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  59. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  60. package/dist/types/src/capabilities/transcriber.d.ts +1 -1
  61. package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
  62. package/dist/types/src/components/Transcript/Transcript.d.ts +7 -7
  63. package/dist/types/src/components/Transcript/Transcript.d.ts.map +1 -1
  64. package/dist/types/src/components/Transcript/Transcript.stories.d.ts +33 -18
  65. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +1 -1
  66. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +3 -3
  67. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +1 -1
  68. package/dist/types/src/components/Transcript/transcript-extension.d.ts +3 -7
  69. package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +1 -1
  70. package/dist/types/src/components/TranscriptContainer.d.ts +2 -2
  71. package/dist/types/src/components/TranscriptContainer.d.ts.map +1 -1
  72. package/dist/types/src/components/stories/FileTranscription.stories.d.ts +5 -4
  73. package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -1
  74. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +10 -6
  75. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -1
  76. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +7 -6
  77. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -1
  78. package/dist/types/src/components/stories/TranscriptionStory.d.ts +4 -3
  79. package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +1 -1
  80. package/dist/types/src/functions/index.d.ts +3 -0
  81. package/dist/types/src/functions/index.d.ts.map +1 -0
  82. package/dist/types/src/functions/open.d.ts +7 -0
  83. package/dist/types/src/functions/open.d.ts.map +1 -0
  84. package/dist/types/src/functions/summarize.d.ts +11 -0
  85. package/dist/types/src/functions/summarize.d.ts.map +1 -0
  86. package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
  87. package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
  88. package/dist/types/src/hooks/useVoiceInput.d.ts.map +1 -1
  89. package/dist/types/src/meta.d.ts +0 -1
  90. package/dist/types/src/meta.d.ts.map +1 -1
  91. package/dist/types/src/segments-normalization/message-normalizer.d.ts +3 -3
  92. package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +1 -1
  93. package/dist/types/src/segments-normalization/normalization.d.ts +388 -328
  94. package/dist/types/src/segments-normalization/normalization.d.ts.map +1 -1
  95. package/dist/types/src/segments-normalization/utils.d.ts +2 -2
  96. package/dist/types/src/segments-normalization/utils.d.ts.map +1 -1
  97. package/dist/types/src/testing/testing.d.ts +7 -7
  98. package/dist/types/src/testing/testing.d.ts.map +1 -1
  99. package/dist/types/src/transcriber/media-stream-recorder.d.ts +1 -1
  100. package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
  101. package/dist/types/src/transcriber/transcriber.d.ts +2 -2
  102. package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
  103. package/dist/types/src/transcriber/transcription-manager.d.ts +6 -10
  104. package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
  105. package/dist/types/src/types/Transcript.d.ts +30 -0
  106. package/dist/types/src/types/Transcript.d.ts.map +1 -0
  107. package/dist/types/src/types/TranscriptAction.d.ts +23 -0
  108. package/dist/types/src/types/TranscriptAction.d.ts.map +1 -0
  109. package/dist/types/src/types/index.d.ts +2 -1
  110. package/dist/types/src/types/index.d.ts.map +1 -1
  111. package/dist/types/src/types/types.d.ts +0 -26
  112. package/dist/types/src/types/types.d.ts.map +1 -1
  113. package/dist/types/tsconfig.tsbuildinfo +1 -1
  114. package/package.json +66 -63
  115. package/src/TranscriptionPlugin.tsx +59 -54
  116. package/src/capabilities/blueprint-definition.ts +31 -0
  117. package/src/capabilities/capabilities.ts +6 -6
  118. package/src/capabilities/index.ts +1 -0
  119. package/src/capabilities/intent-resolver.ts +5 -11
  120. package/src/capabilities/react-surface.tsx +2 -2
  121. package/src/capabilities/transcriber.ts +3 -2
  122. package/src/components/Transcript/Transcript.stories.tsx +37 -34
  123. package/src/components/Transcript/Transcript.tsx +25 -31
  124. package/src/components/Transcript/deprecated/OldTranscript.tsx +9 -9
  125. package/src/components/Transcript/transcript-extension.ts +11 -44
  126. package/src/components/TranscriptContainer.tsx +12 -10
  127. package/src/components/stories/FileTranscription.stories.tsx +54 -42
  128. package/src/components/stories/KeyWordRecognition.stories.tsx +15 -11
  129. package/src/components/stories/MicrophoneTranscription.stories.tsx +49 -45
  130. package/src/components/stories/TranscriptionStory.tsx +12 -8
  131. package/src/functions/index.ts +6 -0
  132. package/src/functions/open.ts +39 -0
  133. package/src/functions/summarize.ts +103 -0
  134. package/src/hooks/useAudioFile.ts +49 -53
  135. package/src/hooks/useTranscriber.ts +7 -2
  136. package/src/hooks/useVoiceInput.ts +3 -2
  137. package/src/meta.ts +7 -4
  138. package/src/model/model.test.ts +12 -12
  139. package/src/segments-normalization/message-normalizer.ts +7 -7
  140. package/src/segments-normalization/normalization.test.ts +10 -10
  141. package/src/segments-normalization/normalization.ts +43 -42
  142. package/src/segments-normalization/utils.ts +2 -2
  143. package/src/testing/testing.ts +27 -22
  144. package/src/transcriber/media-stream-recorder.ts +1 -1
  145. package/src/transcriber/transcriber.browser.test.ts +5 -4
  146. package/src/transcriber/transcriber.ts +5 -4
  147. package/src/transcriber/transcription-manager.ts +23 -44
  148. package/src/types/{schema.ts → Transcript.ts} +12 -9
  149. package/src/types/TranscriptAction.ts +24 -0
  150. package/src/types/index.ts +2 -1
  151. package/src/types/types.ts +0 -23
  152. package/dist/lib/browser/TranscriptContainer-6WCKCXQ6.mjs +0 -11
  153. package/dist/lib/browser/chunk-5KPYIC3N.mjs.map +0 -7
  154. package/dist/lib/browser/chunk-5WH45KBY.mjs +0 -19
  155. package/dist/lib/browser/chunk-5WH45KBY.mjs.map +0 -7
  156. package/dist/lib/browser/chunk-FFEPEPCU.mjs.map +0 -7
  157. package/dist/lib/browser/chunk-R7INNNUQ.mjs +0 -55
  158. package/dist/lib/browser/chunk-R7INNNUQ.mjs.map +0 -7
  159. package/dist/lib/browser/chunk-U6QBOGTN.mjs.map +0 -7
  160. package/dist/lib/browser/intent-resolver-3O33MMP5.mjs +0 -30
  161. package/dist/lib/browser/intent-resolver-3O33MMP5.mjs.map +0 -7
  162. package/dist/lib/browser/react-surface-E5D5AE3F.mjs.map +0 -7
  163. package/dist/lib/browser/transcriber-PXT4QBFY.mjs.map +0 -7
  164. package/dist/lib/node-esm/chunk-HT3W7LDP.mjs.map +0 -7
  165. package/dist/lib/node-esm/chunk-RHF2ALML.mjs.map +0 -7
  166. package/dist/lib/node-esm/chunk-TJKAO7VR.mjs.map +0 -7
  167. package/dist/lib/node-esm/chunk-U65ZWK3L.mjs +0 -56
  168. package/dist/lib/node-esm/chunk-U65ZWK3L.mjs.map +0 -7
  169. package/dist/lib/node-esm/chunk-XMUCZBP3.mjs +0 -21
  170. package/dist/lib/node-esm/chunk-XMUCZBP3.mjs.map +0 -7
  171. package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs +0 -31
  172. package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs.map +0 -7
  173. package/dist/lib/node-esm/react-surface-QRDJOHN5.mjs.map +0 -7
  174. package/dist/lib/node-esm/transcriber-YUTEVANE.mjs.map +0 -7
  175. package/dist/types/src/types/schema.d.ts +0 -41
  176. package/dist/types/src/types/schema.d.ts.map +0 -1
  177. /package/dist/lib/browser/{TranscriptContainer-6WCKCXQ6.mjs.map → TranscriptContainer-EKSP5DQ6.mjs.map} +0 -0
  178. /package/dist/lib/browser/{chunk-4FJIYH7T.mjs.map → chunk-OCI42DWB.mjs.map} +0 -0
  179. /package/dist/lib/node-esm/{TranscriptContainer-VBAOM5DG.mjs.map → TranscriptContainer-WU3EDQR3.mjs.map} +0 -0
  180. /package/dist/lib/node-esm/{chunk-Y2B4HWSS.mjs.map → chunk-X5BKN32O.mjs.map} +0 -0
@@ -8,14 +8,14 @@
8
8
 
9
9
  import { effect } from '@preact/signals-core';
10
10
 
11
- import { asyncTimeout, DeferredTask } from '@dxos/async';
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 DataType } from '@dxos/schema';
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<DataType.Message>;
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<DataType.Message>;
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 { createQueueDXN } from '@dxos/echo-schema';
13
- import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
13
+ import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
14
14
  import { log } from '@dxos/log';
15
- import { DataType } from '@dxos/schema';
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: DataType.Actor = {
21
+ const sender: Actor.Actor = {
22
22
  identityDid: 'did:key:123',
23
23
  };
24
24
 
@@ -48,15 +48,14 @@ 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(DataType.Message, {
52
- created: new Date(Date.now() + 1000 * index).toISOString(),
51
+ Obj.make(Message.Message, {
52
+ created: new Date(Date.now() + 1_000 * index).toISOString(),
53
53
  sender,
54
- blocks: [{ _tag: 'transcript', started: new Date(Date.now() + 1000 * index).toISOString(), text: string }],
54
+ blocks: [{ _tag: 'transcript', started: new Date(Date.now() + 1_000 * index).toISOString(), text: string }],
55
55
  }),
56
56
  );
57
57
 
58
- // eslint-disable-next-line no-unused-vars
59
- const _REMOTE_AI = true;
58
+ // const REMOTE_AI = true;
60
59
 
61
60
  describe.skip('SentenceNormalization', () => {
62
61
  const getExecutor = () => {
@@ -98,6 +97,7 @@ describe.skip('SentenceNormalization', () => {
98
97
  buffer = sentences.slice(activeSentenceIndex);
99
98
  }
100
99
  }
100
+
101
101
  log.info('sentences', {
102
102
  originalMessages: JSON.stringify(messages, null, 2),
103
103
  sentences: JSON.stringify(sentences, null, 2),
@@ -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<DataType.Message>(createQueueDXN());
111
+ const queue = new MemoryQueue<Message.Message>(createQueueDXN());
112
112
  const ctx = new Context();
113
113
  let idx = 0;
114
114
  scheduleTaskInterval(
@@ -2,23 +2,24 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- // TODO(burdon): Needs refactoring.
5
+ // ISSUE(burdon): defineFunction
6
6
  // @ts-nocheck
7
7
 
8
- import { Schema } from 'effect';
8
+ import * as Schema from 'effect/Schema';
9
9
 
10
- import { DEFAULT_EDGE_MODEL, AiService } from '@dxos/ai';
10
+ import { AiService, DEFAULT_EDGE_MODEL } from '@dxos/ai';
11
11
  import { AiSession } from '@dxos/assistant';
12
12
  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 { DataType } from '@dxos/schema';
16
+ import { Message } from '@dxos/types';
17
+ import { trim } from '@dxos/util';
17
18
 
18
19
  const MessageWithRangeId = Schema.extend(
19
- DataType.Message,
20
+ Message.Message,
20
21
  Schema.Struct({
21
- // TODO(mykola): Move to meta in DataType.Message. Use `DataType.Message` instead.
22
+ // TODO(mykola): Move to meta in Message. Use `Message.Message` instead.
22
23
  rangeId: Schema.optional(Schema.Array(Schema.String)).annotations({
23
24
  description: 'The IDs of the messages that contain the sentences.',
24
25
  }),
@@ -28,7 +29,7 @@ const MessageWithRangeId = Schema.extend(
28
29
  export interface MessageWithRangeId extends Schema.Schema.Type<typeof MessageWithRangeId> {}
29
30
 
30
31
  export const NormalizationInput = Schema.Struct({
31
- // TODO(mykola): Move to meta in DataType.Message. Use `DataType.Message` instead.
32
+ // TODO(mykola): Move to meta in Message. Use `Message.Message` instead.
32
33
  messages: Schema.Array(MessageWithRangeId).annotations({
33
34
  description: 'Messages to normalize into sentences.',
34
35
  }),
@@ -42,40 +43,6 @@ export const NormalizationOutput = Schema.Struct({
42
43
  });
43
44
  export interface NormalizationOutput extends Schema.Schema.Type<typeof NormalizationOutput> {}
44
45
 
45
- const prompt = `
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 DataType.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.
77
- `;
78
-
79
46
  export const sentenceNormalization = defineFunction<NormalizationInput, NormalizationOutput>({
80
47
  description: 'Post process of transcription for sentence normalization',
81
48
  inputSchema: NormalizationInput,
@@ -94,7 +61,7 @@ export const sentenceNormalization = defineFunction<NormalizationInput, Normaliz
94
61
  tools: [],
95
62
  artifacts: [],
96
63
  history: [
97
- Obj.make(DataType.Message, {
64
+ Obj.make(Message.Message, {
98
65
  created: new Date().toISOString(),
99
66
  sender: {
100
67
  role: 'user',
@@ -112,3 +79,37 @@ export const sentenceNormalization = defineFunction<NormalizationInput, Normaliz
112
79
  return response;
113
80
  },
114
81
  });
82
+
83
+ const prompt = trim`
84
+ You are observing a real-time transcript of a single person speaking.
85
+ 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.
86
+
87
+ # Task Description:
88
+ - Your task is to detect and reconstruct broken or incomplete sentences by merging segments into coherent, grammatically correct sentences where appropriate.
89
+
90
+ # Input Format:
91
+ - The input is an array of messages that contain transcription blocks.
92
+ - Each message is a Message.Message, as described in the output format.
93
+
94
+ # Output Format:
95
+ - You have been provided with the tool that defines the output format; make sure to query it.
96
+ - Do not output anything other than the expected format.
97
+
98
+ # Segment Handling Rules:
99
+ - Sort messages by timestamp.
100
+ - Leave ID of the first message in a sentence.
101
+ - Each divided sentence should be added to the output as a separate message or block within existing messages, preserving the original order.
102
+ - If one message contains multiple sentences, you should not split them.
103
+ - The last sentence may be incomplete; it should still be output as a separate block or message.
104
+ - 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.
105
+ - 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.
106
+
107
+ # Punctuation and Capitalization:
108
+ - Do not rely on the original punctuation and capitalization—they may be incorrect.
109
+ - Use logical reasoning to apply appropriate punctuation (e.g., period, comma, question mark, exclamation mark) and capitalization.
110
+
111
+ # Restrictions:
112
+ - Do not alter the order of the original messages; maintain the natural flow of speech.
113
+ - Do not interpret or infer meaning beyond reconstructing sentences.
114
+ - Do not add or remove any words or phrases.
115
+ `;
@@ -2,8 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type DataType } from '@dxos/schema';
5
+ import { type Actor } from '@dxos/types';
6
6
 
7
- export const getActorId = (actor: DataType.Actor) => {
7
+ export const getActorId = (actor: Actor.Actor) => {
8
8
  return actor.identityDid || actor.identityKey || actor.email || actor.name || '';
9
9
  };
@@ -2,22 +2,23 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
  import { useEffect, useMemo, useState } from 'react';
7
7
 
8
- import { extractionAnthropicFn, processTranscriptMessage } from '@dxos/assistant';
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
- import { Obj, Ref, Type, type Key } from '@dxos/echo';
13
- import { createQueueDXN } from '@dxos/echo-schema';
14
- import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
12
+ import { type Key, Obj, Ref, Type } from '@dxos/echo';
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
- import { useQueue, type Space } from '@dxos/react-client/echo';
19
- import { DataType } from '@dxos/schema';
20
- import { Testing, seedTestData } from '@dxos/schema/testing';
18
+ import { type Space, useQueue } from '@dxos/react-client/echo';
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<DataType.Message>;
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<DataType.Message> {
63
- return Obj.make(DataType.Message, {
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(): DataType.MessageBlock.Transcript {
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}][${dxn}]`);
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: DataType.Message[] = [];
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<DataType.Message> {
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(Filter.type(DataType.Person), Filter.type(DataType.Organization), Filter.type(Testing.DocumentType)),
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: extractionAnthropicFn,
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<DataType.Message> | undefined;
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<DataType.Message>(queueDxn);
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(DataType.Message, message)]);
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<DataType.Message>(queueDxn);
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(DataType.Message, message)]);
211
+ void queue.append([Obj.make(Message.Message, message)]);
207
212
  },
208
213
  interval,
209
214
  );
@@ -10,7 +10,7 @@ import { invariant } from '@dxos/invariant';
10
10
  import { log } from '@dxos/log';
11
11
  import { trace } from '@dxos/tracing';
12
12
 
13
- import { type WavConfig, type AudioChunk, type AudioRecorder } from './audio-recorder';
13
+ import { type AudioChunk, type AudioRecorder, type WavConfig } from './audio-recorder';
14
14
 
15
15
  let initializingPromise: Promise<void> | undefined;
16
16
 
@@ -4,14 +4,15 @@
4
4
 
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
+
7
8
  import { describe, expect, test } from 'vitest';
8
9
  import { WaveFile } from 'wavefile';
9
10
 
10
11
  import { Trigger } from '@dxos/async';
11
12
  import { log } from '@dxos/log';
12
- import { type DataType } from '@dxos/schema';
13
13
  import { openAndClose } from '@dxos/test-utils';
14
- import { trace, TRACE_PROCESSOR } from '@dxos/tracing';
14
+ import { TRACE_PROCESSOR, trace } from '@dxos/tracing';
15
+ import { type ContentBlock } from '@dxos/types';
15
16
 
16
17
  import { type AudioChunk, type AudioRecorder, Transcriber } from '../transcriber';
17
18
  import { mergeFloat64Arrays } from '../util';
@@ -93,7 +94,7 @@ describe.skip('Transcriber', () => {
93
94
  });
94
95
 
95
96
  test.skip('transcription of audio recording', { timeout: 10_000 }, async () => {
96
- const trigger = new Trigger<DataType.MessageBlock.Transcript[]>({ autoReset: true });
97
+ const trigger = new Trigger<ContentBlock.Transcript[]>({ autoReset: true });
97
98
  const recorder = new MockAudioRecorder({
98
99
  buffer: await readFile('test.wav'),
99
100
  chunkDuration: 3_000,
@@ -127,7 +128,7 @@ describe.skip('Transcriber', () => {
127
128
  });
128
129
 
129
130
  test.skip('transcription of audio recording with overlapping chunks', { timeout: 20_000 }, async () => {
130
- const trigger = new Trigger<DataType.MessageBlock.Transcript[]>({ autoReset: true });
131
+ const trigger = new Trigger<ContentBlock.Transcript[]>({ autoReset: true });
131
132
  const recorder = new MockAudioRecorder({
132
133
  buffer: await readFile('test.wav'),
133
134
  chunkDuration: 3_000,
@@ -7,13 +7,14 @@ 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
- import { type AudioRecorder, type AudioChunk } from './audio-recorder';
14
13
  import { TRANSCRIPTION_URL } from '../types';
15
14
  import { mergeFloat64Arrays } from '../util';
16
15
 
16
+ import { type AudioChunk, type AudioRecorder } from './audio-recorder';
17
+
17
18
  type WhisperWord = {
18
19
  word: string;
19
20
 
@@ -69,7 +70,7 @@ export type TranscriberParams = {
69
70
  * Callback to handle the transcribed segments, after all segment transformers are applied.
70
71
  * @param segments - The transcribed segments.
71
72
  */
72
- onSegments: (segments: DataType.MessageBlock.Transcript[]) => Promise<void>;
73
+ onSegments: (segments: ContentBlock.Transcript[]) => Promise<void>;
73
74
  };
74
75
 
75
76
  /**
@@ -220,7 +221,7 @@ export class Transcriber extends Resource {
220
221
  return segments;
221
222
  }
222
223
 
223
- private _alignSegments(segments: WhisperSegment[], originalChunks: AudioChunk[]): DataType.MessageBlock.Transcript[] {
224
+ private _alignSegments(segments: WhisperSegment[], originalChunks: AudioChunk[]): ContentBlock.Transcript[] {
224
225
  // Absolute zero for all relative timestamps in the segments.
225
226
  const zeroTimestamp = originalChunks.at(0)!.timestamp;
226
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 { DataType } from '@dxos/schema';
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: DataType.Message) => Promise<DataType.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<DataType.Message> = undefined;
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<DataType.Message>): this {
68
+ setQueue(queue: Queue<Message.Message>): this {
69
69
  this._queue = queue;
70
70
  return this;
71
71
  }
@@ -90,19 +90,17 @@ export class TranscriptionManager extends Resource {
90
90
  return this;
91
91
  }
92
92
 
93
- /**
94
- * Enable or disable transcription.
95
- * @param enabled - Whether to enable transcription.
96
- */
97
- @synchronized
98
- async setEnabled(enabled?: boolean): Promise<void> {
93
+ async setEnabled(enabled: boolean): Promise<void> {
99
94
  if (this._enabled.value === enabled) {
100
95
  return;
101
96
  }
102
97
 
103
98
  this._enabled.value = enabled ?? false;
104
- // TODO(burdon): Why is toggle called here?
105
- this.isOpen && (await this._toggleTranscriber());
99
+ if (enabled) {
100
+ await this._maybeRestartTranscriber();
101
+ } else {
102
+ await this._stopTranscriber();
103
+ }
106
104
  }
107
105
 
108
106
  @synchronized
@@ -112,44 +110,19 @@ export class TranscriptionManager extends Resource {
112
110
  }
113
111
 
114
112
  this._audioStreamTrack = track;
115
- this.isOpen && (await this._toggleTranscriber());
113
+ await this._maybeRestartTranscriber();
116
114
  }
117
115
 
118
116
  protected override async _open(): Promise<void> {
119
- await this._toggleTranscriber();
117
+ await this._maybeRestartTranscriber();
120
118
  }
121
119
 
122
120
  protected override async _close(): Promise<void> {
123
- void this._transcriber?.close();
124
- }
125
-
126
- // TODO(burdon): Change this to setEnables (explicit), not toggle.
127
- private async _toggleTranscriber(): Promise<void> {
128
- await this._maybeReinitTranscriber();
129
-
130
- // Open or close transcriber if transcription is enabled or disabled.
131
- if (this._enabled.value) {
132
- await this._transcriber?.open();
133
- // TODO(burdon): Started and stopped blocks appear twice.
134
- const block = Obj.make(DataType.Message, {
135
- created: new Date().toISOString(),
136
- blocks: [{ _tag: 'transcript', text: 'Started', started: new Date().toISOString() }],
137
- sender: { role: 'assistant' },
138
- });
139
- await this._queue?.append([block]);
140
- } else {
141
- await this._transcriber?.close();
142
- const block = Obj.make(DataType.Message, {
143
- created: new Date().toISOString(),
144
- blocks: [{ _tag: 'transcript', text: 'Stopped', started: new Date().toISOString() }],
145
- sender: { role: 'assistant' },
146
- });
147
- await this._queue?.append([block]);
148
- }
121
+ await this._stopTranscriber();
149
122
  }
150
123
 
151
- private async _maybeReinitTranscriber(): Promise<void> {
152
- if (!this._audioStreamTrack || !this._enabled.value) {
124
+ private async _maybeRestartTranscriber(): Promise<void> {
125
+ if (!this._audioStreamTrack || !this._enabled.value || !this.isOpen) {
153
126
  return;
154
127
  }
155
128
 
@@ -172,15 +145,21 @@ export class TranscriptionManager extends Resource {
172
145
  recorder: this._mediaRecorder,
173
146
  onSegments: (segments) => this._onSegments(segments),
174
147
  });
148
+
149
+ await this._transcriber?.open();
175
150
  }
176
151
  }
177
152
 
178
- private async _onSegments(segments: DataType.MessageBlock.Transcript[]): Promise<void> {
153
+ private async _stopTranscriber(): Promise<void> {
154
+ await this._transcriber?.close();
155
+ }
156
+
157
+ private async _onSegments(segments: ContentBlock.Transcript[]): Promise<void> {
179
158
  if (!this.isOpen || !this._queue) {
180
159
  return;
181
160
  }
182
161
 
183
- let block = Obj.make(DataType.Message, {
162
+ let block = Obj.make(Message.Message, {
184
163
  created: new Date().toISOString(),
185
164
  blocks: segments,
186
165
  sender: { identityDid: this._identityDid },
@@ -2,16 +2,15 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
7
  import { Queue } from '@dxos/client/echo';
8
- import { Type } from '@dxos/echo';
9
- import { TypedObject } from '@dxos/echo-schema';
8
+ import { type DXN, Obj, Ref, Type } from '@dxos/echo';
10
9
 
11
10
  /**
12
11
  * Root transcript object created when the user starts a transcription.
13
12
  */
14
- export const TranscriptSchema = Schema.Struct({
13
+ export const Transcript = Schema.Struct({
15
14
  // TODO(wittjosiah): Remove?
16
15
  // TODO(burdon): Use Date or string?
17
16
  started: Schema.optional(Schema.String),
@@ -21,12 +20,14 @@ export const TranscriptSchema = Schema.Struct({
21
20
  * Queue containing TranscriptBlock objects.
22
21
  */
23
22
  queue: Type.Ref(Queue),
24
- });
23
+ }).pipe(
24
+ Type.Obj({
25
+ typename: 'dxos.org/type/Transcript',
26
+ version: '0.1.0',
27
+ }),
28
+ );
25
29
 
26
- export class TranscriptType extends TypedObject({
27
- typename: 'dxos.org/type/Transcript',
28
- version: '0.1.0',
29
- })(TranscriptSchema.fields) {}
30
+ export type Transcript = Schema.Schema.Type<typeof Transcript>;
30
31
 
31
32
  // TODO(burdon): Do these need to be kept in sync with EDGE?
32
33
 
@@ -39,3 +40,5 @@ const TranscriptHeader = Schema.Struct({
39
40
  });
40
41
 
41
42
  export type TranscriptHeader = Schema.Schema.Type<typeof TranscriptHeader>;
43
+
44
+ export const makeTranscript = (queueDxn: DXN) => Obj.make(Transcript, { queue: Ref.fromDXN(queueDxn) });