@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.
Files changed (243) hide show
  1. package/dist/lib/browser/blueprints/index.mjs +31 -0
  2. package/dist/lib/browser/blueprints/index.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-5LWSJZTZ.mjs +17 -0
  4. package/dist/lib/browser/chunk-5LWSJZTZ.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-HOOPZ7EM.mjs +35 -0
  6. package/dist/lib/browser/chunk-HOOPZ7EM.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  8. package/dist/lib/browser/chunk-KOX4WNAR.mjs +111 -0
  9. package/dist/lib/browser/chunk-KOX4WNAR.mjs.map +7 -0
  10. package/dist/lib/browser/create-BTWYQ6IM.mjs +21 -0
  11. package/dist/lib/browser/create-BTWYQ6IM.mjs.map +7 -0
  12. package/dist/lib/browser/index.mjs +1181 -93
  13. package/dist/lib/browser/index.mjs.map +4 -4
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/open-CYRYIEZI.mjs +27 -0
  16. package/dist/lib/browser/open-CYRYIEZI.mjs.map +7 -0
  17. package/dist/lib/browser/operations/index.mjs +13 -0
  18. package/dist/lib/browser/operations/index.mjs.map +7 -0
  19. package/dist/lib/browser/summarize-X2ZYTN7S.mjs +79 -0
  20. package/dist/lib/browser/summarize-X2ZYTN7S.mjs.map +7 -0
  21. package/dist/lib/browser/types/index.mjs +4 -8
  22. package/dist/lib/node-esm/blueprints/index.mjs +32 -0
  23. package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
  24. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  25. package/dist/lib/node-esm/chunk-MT5I4NH5.mjs +112 -0
  26. package/dist/lib/node-esm/chunk-MT5I4NH5.mjs.map +7 -0
  27. package/dist/lib/node-esm/chunk-NVM2QUMX.mjs +37 -0
  28. package/dist/lib/node-esm/chunk-NVM2QUMX.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-X74WYCCE.mjs +19 -0
  30. package/dist/lib/node-esm/chunk-X74WYCCE.mjs.map +7 -0
  31. package/dist/lib/node-esm/create-MLUFPST2.mjs +22 -0
  32. package/dist/lib/node-esm/create-MLUFPST2.mjs.map +7 -0
  33. package/dist/lib/node-esm/index.mjs +1181 -93
  34. package/dist/lib/node-esm/index.mjs.map +4 -4
  35. package/dist/lib/node-esm/meta.json +1 -1
  36. package/dist/lib/node-esm/open-5IOC2U4Z.mjs +28 -0
  37. package/dist/lib/node-esm/open-5IOC2U4Z.mjs.map +7 -0
  38. package/dist/lib/node-esm/operations/index.mjs +14 -0
  39. package/dist/lib/node-esm/operations/index.mjs.map +7 -0
  40. package/dist/lib/node-esm/summarize-IORITU7T.mjs +80 -0
  41. package/dist/lib/node-esm/summarize-IORITU7T.mjs.map +7 -0
  42. package/dist/lib/node-esm/types/index.mjs +4 -8
  43. package/dist/types/src/TranscriptionPlugin.d.ts +2 -1
  44. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  45. package/dist/types/src/blueprints/index.d.ts +2 -0
  46. package/dist/types/src/blueprints/index.d.ts.map +1 -0
  47. package/dist/types/src/blueprints/transcription-blueprint.d.ts +4 -0
  48. package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +1 -0
  49. package/dist/types/src/capabilities/blueprint-definition.d.ts +6 -0
  50. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  51. package/dist/types/src/capabilities/index.d.ts +6 -4
  52. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  53. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  54. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  55. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  56. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/transcriber.d.ts +4 -3
  58. package/dist/types/src/capabilities/transcriber.d.ts.map +1 -1
  59. package/dist/types/src/components/Transcription/Transcription.d.ts +18 -0
  60. package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -0
  61. package/dist/types/src/components/Transcription/Transcription.stories.d.ts +40 -0
  62. package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +1 -0
  63. package/dist/types/src/components/Transcription/index.d.ts +2 -0
  64. package/dist/types/src/components/Transcription/index.d.ts.map +1 -0
  65. package/dist/types/src/components/Transcription/transcription-extension.d.ts +15 -0
  66. package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +1 -0
  67. package/dist/types/src/components/index.d.ts +1 -3
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/components/stories/FileTranscription.stories.d.ts +8 -7
  70. package/dist/types/src/components/stories/FileTranscription.stories.d.ts.map +1 -1
  71. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts +10 -6
  72. package/dist/types/src/components/stories/KeyWordRecognition.stories.d.ts.map +1 -1
  73. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts +11 -10
  74. package/dist/types/src/components/stories/MicrophoneTranscription.stories.d.ts.map +1 -1
  75. package/dist/types/src/components/stories/TranscriptionStory.d.ts +4 -3
  76. package/dist/types/src/components/stories/TranscriptionStory.d.ts.map +1 -1
  77. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts +6 -0
  78. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts.map +1 -0
  79. package/dist/types/src/containers/TranscriptionContainer/index.d.ts +2 -0
  80. package/dist/types/src/containers/TranscriptionContainer/index.d.ts.map +1 -0
  81. package/dist/types/src/containers/index.d.ts +3 -0
  82. package/dist/types/src/containers/index.d.ts.map +1 -0
  83. package/dist/types/src/hooks/useAudioFile.d.ts.map +1 -1
  84. package/dist/types/src/hooks/useQueueModelAdapter.d.ts +1 -1
  85. package/dist/types/src/hooks/useQueueModelAdapter.d.ts.map +1 -1
  86. package/dist/types/src/hooks/useTranscriber.d.ts +1 -1
  87. package/dist/types/src/hooks/useTranscriber.d.ts.map +1 -1
  88. package/dist/types/src/index.d.ts +1 -1
  89. package/dist/types/src/index.d.ts.map +1 -1
  90. package/dist/types/src/meta.d.ts +2 -3
  91. package/dist/types/src/meta.d.ts.map +1 -1
  92. package/dist/types/src/operations/create.d.ts +5 -0
  93. package/dist/types/src/operations/create.d.ts.map +1 -0
  94. package/dist/types/src/operations/definitions.d.ts +917 -0
  95. package/dist/types/src/operations/definitions.d.ts.map +1 -0
  96. package/dist/types/src/operations/index.d.ts +4 -0
  97. package/dist/types/src/operations/index.d.ts.map +1 -0
  98. package/dist/types/src/operations/open.d.ts +5 -0
  99. package/dist/types/src/operations/open.d.ts.map +1 -0
  100. package/dist/types/src/operations/summarize.d.ts +8 -0
  101. package/dist/types/src/operations/summarize.d.ts.map +1 -0
  102. package/dist/types/src/segments-normalization/message-normalizer.d.ts +5 -5
  103. package/dist/types/src/segments-normalization/message-normalizer.d.ts.map +1 -1
  104. package/dist/types/src/segments-normalization/normalization.d.ts +363 -328
  105. package/dist/types/src/segments-normalization/normalization.d.ts.map +1 -1
  106. package/dist/types/src/segments-normalization/utils.d.ts +2 -2
  107. package/dist/types/src/segments-normalization/utils.d.ts.map +1 -1
  108. package/dist/types/src/testing/testing.d.ts +10 -10
  109. package/dist/types/src/testing/testing.d.ts.map +1 -1
  110. package/dist/types/src/transcriber/index.d.ts +1 -1
  111. package/dist/types/src/transcriber/index.d.ts.map +1 -1
  112. package/dist/types/src/transcriber/media-stream-recorder.d.ts +3 -3
  113. package/dist/types/src/transcriber/media-stream-recorder.d.ts.map +1 -1
  114. package/dist/types/src/transcriber/transcriber.d.ts +4 -4
  115. package/dist/types/src/transcriber/transcriber.d.ts.map +1 -1
  116. package/dist/types/src/transcriber/transcription-manager.d.ts +12 -13
  117. package/dist/types/src/transcriber/transcription-manager.d.ts.map +1 -1
  118. package/dist/types/src/translations.d.ts +7 -7
  119. package/dist/types/src/translations.d.ts.map +1 -1
  120. package/dist/types/src/types/capabilities.d.ts +18 -0
  121. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  122. package/dist/types/src/types/index.d.ts +1 -1
  123. package/dist/types/src/types/index.d.ts.map +1 -1
  124. package/dist/types/src/types/types.d.ts +0 -26
  125. package/dist/types/src/types/types.d.ts.map +1 -1
  126. package/dist/types/src/util/index.d.ts +1 -0
  127. package/dist/types/src/util/index.d.ts.map +1 -1
  128. package/dist/types/src/util/render-byline.d.ts +4 -0
  129. package/dist/types/src/util/render-byline.d.ts.map +1 -0
  130. package/dist/types/tsconfig.tsbuildinfo +1 -1
  131. package/package.json +109 -73
  132. package/src/TranscriptionPlugin.tsx +46 -59
  133. package/src/blueprints/index.ts +5 -0
  134. package/src/blueprints/transcription-blueprint.ts +30 -0
  135. package/src/capabilities/blueprint-definition.ts +17 -0
  136. package/src/capabilities/index.ts +9 -6
  137. package/src/capabilities/operation-handler.ts +16 -0
  138. package/src/capabilities/react-surface.tsx +23 -14
  139. package/src/capabilities/transcriber.ts +52 -42
  140. package/src/components/{Transcript/Transcript.stories.tsx → Transcription/Transcription.stories.tsx} +73 -66
  141. package/src/components/Transcription/Transcription.tsx +64 -0
  142. package/src/components/{Transcript → Transcription}/index.ts +1 -1
  143. package/src/components/{Transcript/transcript-extension.ts → Transcription/transcription-extension.ts} +15 -48
  144. package/src/components/index.ts +1 -6
  145. package/src/components/stories/FileTranscription.stories.tsx +78 -70
  146. package/src/components/stories/KeyWordRecognition.stories.tsx +17 -13
  147. package/src/components/stories/MicrophoneTranscription.stories.tsx +84 -100
  148. package/src/components/stories/TranscriptionStory.tsx +15 -13
  149. package/src/containers/TranscriptionContainer/TranscriptionContainer.tsx +35 -0
  150. package/src/containers/TranscriptionContainer/index.ts +5 -0
  151. package/src/containers/index.ts +7 -0
  152. package/src/hooks/useAudioFile.ts +49 -53
  153. package/src/hooks/useQueueModelAdapter.ts +1 -1
  154. package/src/hooks/useTranscriber.ts +9 -3
  155. package/src/hooks/useVoiceInput.ts +3 -3
  156. package/src/index.ts +1 -1
  157. package/src/meta.ts +9 -6
  158. package/src/model/model.test.ts +27 -21
  159. package/src/operations/create.ts +24 -0
  160. package/src/operations/definitions.ts +101 -0
  161. package/src/operations/index.ts +13 -0
  162. package/src/operations/open.ts +28 -0
  163. package/src/operations/summarize.ts +102 -0
  164. package/src/segments-normalization/message-normalizer.ts +19 -14
  165. package/src/segments-normalization/normalization.test.ts +26 -33
  166. package/src/segments-normalization/normalization.ts +67 -96
  167. package/src/segments-normalization/utils.ts +2 -2
  168. package/src/testing/testing.ts +41 -41
  169. package/src/transcriber/index.ts +1 -1
  170. package/src/transcriber/media-stream-recorder.ts +4 -4
  171. package/src/transcriber/transcriber.browser.test.ts +5 -5
  172. package/src/transcriber/transcriber.ts +10 -12
  173. package/src/transcriber/transcription-manager.ts +37 -52
  174. package/src/translations.ts +7 -7
  175. package/src/types/capabilities.ts +34 -0
  176. package/src/types/index.ts +1 -1
  177. package/src/types/types.ts +0 -23
  178. package/src/util/index.ts +1 -0
  179. package/src/util/render-byline.ts +33 -0
  180. package/dist/lib/browser/TranscriptContainer-E5NBJPAY.mjs +0 -11
  181. package/dist/lib/browser/chunk-5WH45KBY.mjs +0 -19
  182. package/dist/lib/browser/chunk-5WH45KBY.mjs.map +0 -7
  183. package/dist/lib/browser/chunk-EQBICGOD.mjs +0 -8
  184. package/dist/lib/browser/chunk-EQBICGOD.mjs.map +0 -7
  185. package/dist/lib/browser/chunk-F2WY3YTD.mjs +0 -764
  186. package/dist/lib/browser/chunk-F2WY3YTD.mjs.map +0 -7
  187. package/dist/lib/browser/chunk-R7INNNUQ.mjs +0 -55
  188. package/dist/lib/browser/chunk-R7INNNUQ.mjs.map +0 -7
  189. package/dist/lib/browser/chunk-U6QBOGTN.mjs +0 -16
  190. package/dist/lib/browser/chunk-U6QBOGTN.mjs.map +0 -7
  191. package/dist/lib/browser/chunk-VDKDOZRR.mjs +0 -495
  192. package/dist/lib/browser/chunk-VDKDOZRR.mjs.map +0 -7
  193. package/dist/lib/browser/intent-resolver-3O33MMP5.mjs +0 -30
  194. package/dist/lib/browser/intent-resolver-3O33MMP5.mjs.map +0 -7
  195. package/dist/lib/browser/react-surface-FJTMNF3K.mjs +0 -34
  196. package/dist/lib/browser/react-surface-FJTMNF3K.mjs.map +0 -7
  197. package/dist/lib/browser/transcriber-YVOTUBKQ.mjs +0 -56
  198. package/dist/lib/browser/transcriber-YVOTUBKQ.mjs.map +0 -7
  199. package/dist/lib/node-esm/TranscriptContainer-UOS7JG72.mjs +0 -12
  200. package/dist/lib/node-esm/chunk-DN522SAP.mjs +0 -10
  201. package/dist/lib/node-esm/chunk-DN522SAP.mjs.map +0 -7
  202. package/dist/lib/node-esm/chunk-HSCG4XPR.mjs +0 -496
  203. package/dist/lib/node-esm/chunk-HSCG4XPR.mjs.map +0 -7
  204. package/dist/lib/node-esm/chunk-Q3JKLPTW.mjs +0 -765
  205. package/dist/lib/node-esm/chunk-Q3JKLPTW.mjs.map +0 -7
  206. package/dist/lib/node-esm/chunk-RHF2ALML.mjs +0 -17
  207. package/dist/lib/node-esm/chunk-RHF2ALML.mjs.map +0 -7
  208. package/dist/lib/node-esm/chunk-U65ZWK3L.mjs +0 -56
  209. package/dist/lib/node-esm/chunk-U65ZWK3L.mjs.map +0 -7
  210. package/dist/lib/node-esm/chunk-XMUCZBP3.mjs +0 -21
  211. package/dist/lib/node-esm/chunk-XMUCZBP3.mjs.map +0 -7
  212. package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs +0 -31
  213. package/dist/lib/node-esm/intent-resolver-YMN5SXNC.mjs.map +0 -7
  214. package/dist/lib/node-esm/react-surface-57TSIDR2.mjs +0 -35
  215. package/dist/lib/node-esm/react-surface-57TSIDR2.mjs.map +0 -7
  216. package/dist/lib/node-esm/transcriber-GPBV52ZR.mjs +0 -57
  217. package/dist/lib/node-esm/transcriber-GPBV52ZR.mjs.map +0 -7
  218. package/dist/types/src/capabilities/capabilities.d.ts +0 -17
  219. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  220. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  221. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  222. package/dist/types/src/components/Transcript/Transcript.d.ts +0 -20
  223. package/dist/types/src/components/Transcript/Transcript.d.ts.map +0 -1
  224. package/dist/types/src/components/Transcript/Transcript.stories.d.ts +0 -24
  225. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +0 -1
  226. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +0 -28
  227. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +0 -1
  228. package/dist/types/src/components/Transcript/index.d.ts +0 -2
  229. package/dist/types/src/components/Transcript/index.d.ts.map +0 -1
  230. package/dist/types/src/components/Transcript/transcript-extension.d.ts +0 -19
  231. package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +0 -1
  232. package/dist/types/src/components/TranscriptContainer.d.ts +0 -9
  233. package/dist/types/src/components/TranscriptContainer.d.ts.map +0 -1
  234. package/dist/types/src/types/schema.d.ts +0 -41
  235. package/dist/types/src/types/schema.d.ts.map +0 -1
  236. package/src/capabilities/capabilities.ts +0 -33
  237. package/src/capabilities/intent-resolver.ts +0 -24
  238. package/src/components/Transcript/Transcript.tsx +0 -100
  239. package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
  240. package/src/components/TranscriptContainer.tsx +0 -35
  241. package/src/types/schema.ts +0 -41
  242. /package/dist/lib/browser/{TranscriptContainer-E5NBJPAY.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
  243. /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 { effect } from '@preact/signals-core';
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 DataType } from '@dxos/schema';
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 SegmentsNormalizerParams = {
22
+ export type SegmentsNormalizerProps = {
25
23
  functionExecutor: FunctionExecutor;
26
- queue: Queue<DataType.Message>;
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<DataType.Message>;
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 }: SegmentsNormalizerParams) {
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
- const unsubscribe = effect(() => {
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
- this._ctx.onDispose(() => unsubscribe());
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-schema';
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 { DataType } from '@dxos/schema';
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: DataType.Actor = {
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(DataType.Message, {
54
- created: new Date(Date.now() + 1000 * index).toISOString(),
50
+ Obj.make(Message.Message, {
51
+ created: new Date(Date.now() + 1_000 * index).toISOString(),
55
52
  sender,
56
- blocks: [{ type: 'transcription', started: new Date(Date.now() + 1000 * index).toISOString(), text: string }],
57
- rangeId: [],
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
- client: REMOTE_AI
69
- ? new EdgeAiServiceClient({
70
- endpoint: AI_SERVICE_ENDPOINT.REMOTE,
71
- defaultGenerationOptions: {
72
- model: '@anthropic/claude-3-5-sonnet-20241022',
73
- },
74
- })
75
- : new OllamaAiServiceClient({
76
- overrides: {
77
- model: 'llama3.1:8b',
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
- originalMessages: JSON.stringify(messages, null, 2),
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<DataType.Message>(createQueueDXN());
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 { Schema } from 'effect';
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 { DataType } from '@dxos/schema';
14
-
15
- const MessageWithRangeId = Schema.extend(
16
- DataType.Message,
17
- Schema.Struct({
18
- // TODO(mykola): Move to meta in DataType.Message. Use `DataType.Message` instead.
19
- rangeId: Schema.optional(Schema.Array(Schema.String)).annotations({
20
- description: 'The IDs of the messages that contain the sentences.',
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
- export interface MessageWithRangeId extends Schema.Schema.Type<typeof MessageWithRangeId> {}
26
-
27
- export const NormalizationInput = Schema.Struct({
28
- // TODO(mykola): Move to meta in DataType.Message. Use `DataType.Message` instead.
29
- messages: Schema.Array(MessageWithRangeId).annotations({
30
- description: 'Messages to normalize into sentences.',
31
- }),
32
- });
33
- export interface NormalizationInput extends Schema.Schema.Type<typeof NormalizationInput> {}
34
-
35
- export const NormalizationOutput = Schema.Struct({
36
- sentences: Schema.Array(MessageWithRangeId.pipe(Schema.mutable)).pipe(Schema.mutable).annotations({
37
- description: 'The sentences of the transcript.',
38
- }),
39
- });
40
- export interface NormalizationOutput extends Schema.Schema.Type<typeof NormalizationOutput> {}
41
-
42
- const prompt = `
43
- You are observing a real-time transcript of a single person speaking.
44
- 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.
45
-
46
- # Task Description:
47
- - Your task is to detect and reconstruct broken or incomplete sentences by merging segments into coherent, grammatically correct sentences where appropriate.
48
-
49
- # Input Format:
50
- - The input is an array of messages that contain transcription blocks.
51
- - Each message is a DataType.Message, as described in the output format.
52
-
53
- # Output Format:
54
- - You have been provided with the tool that defines the output format; make sure to query it.
55
- - Do not output anything other than the expected format.
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 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
  };