@ephia/dova-sdk 1.0.0

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 (247) hide show
  1. package/README.md +89 -0
  2. package/dist/EphiaBinding-BvRmlqqC.d.ts +36 -0
  3. package/dist/EphiaFloatingButton-CxiF86VW.d.ts +65 -0
  4. package/dist/EphiaTextarea-B4_CAVUg.d.ts +183 -0
  5. package/dist/NativeBinding-ChG0GeSz.d.ts +53 -0
  6. package/dist/TargetBinding-BKGQwUMc.d.ts +89 -0
  7. package/dist/TiptapBinding-B-agfV2H.d.ts +45 -0
  8. package/dist/Transport-zdeA4Pou.d.ts +63 -0
  9. package/dist/audio-state-kZ3KSvux.d.ts +39 -0
  10. package/dist/chunk-35AJK2IO.js +1 -0
  11. package/dist/chunk-35AJK2IO.js.map +1 -0
  12. package/dist/chunk-3LXZODL4.js +886 -0
  13. package/dist/chunk-3LXZODL4.js.map +1 -0
  14. package/dist/chunk-5IK5TLSK.js +67 -0
  15. package/dist/chunk-5IK5TLSK.js.map +1 -0
  16. package/dist/chunk-7E43RY75.js +9 -0
  17. package/dist/chunk-7E43RY75.js.map +1 -0
  18. package/dist/chunk-A5UEXJ5R.js +183 -0
  19. package/dist/chunk-A5UEXJ5R.js.map +1 -0
  20. package/dist/chunk-AEE554FT.js +51 -0
  21. package/dist/chunk-AEE554FT.js.map +1 -0
  22. package/dist/chunk-DIEWY3IT.js +1332 -0
  23. package/dist/chunk-DIEWY3IT.js.map +1 -0
  24. package/dist/chunk-EGIAN7FH.js +18 -0
  25. package/dist/chunk-EGIAN7FH.js.map +1 -0
  26. package/dist/chunk-EMOEAPVU.js +486 -0
  27. package/dist/chunk-EMOEAPVU.js.map +1 -0
  28. package/dist/chunk-IDC7FHIZ.js +40 -0
  29. package/dist/chunk-IDC7FHIZ.js.map +1 -0
  30. package/dist/chunk-ITJFN3VM.js +601 -0
  31. package/dist/chunk-ITJFN3VM.js.map +1 -0
  32. package/dist/chunk-K24GNU27.js +22 -0
  33. package/dist/chunk-K24GNU27.js.map +1 -0
  34. package/dist/chunk-LXMCRXXF.js +778 -0
  35. package/dist/chunk-LXMCRXXF.js.map +1 -0
  36. package/dist/chunk-MJCEOOLW.js +122 -0
  37. package/dist/chunk-MJCEOOLW.js.map +1 -0
  38. package/dist/chunk-N7U5M3VZ.js +33 -0
  39. package/dist/chunk-N7U5M3VZ.js.map +1 -0
  40. package/dist/chunk-PSYX674B.js +27 -0
  41. package/dist/chunk-PSYX674B.js.map +1 -0
  42. package/dist/chunk-RFQRV7ML.js +33 -0
  43. package/dist/chunk-RFQRV7ML.js.map +1 -0
  44. package/dist/chunk-THNHRV2B.js +18 -0
  45. package/dist/chunk-THNHRV2B.js.map +1 -0
  46. package/dist/chunk-VSLGR64U.js +62 -0
  47. package/dist/chunk-VSLGR64U.js.map +1 -0
  48. package/dist/chunk-W2ZP674X.js +346 -0
  49. package/dist/chunk-W2ZP674X.js.map +1 -0
  50. package/dist/chunk-YWZUMUYE.js +695 -0
  51. package/dist/chunk-YWZUMUYE.js.map +1 -0
  52. package/dist/client-options-Uo6jXO8k.d.ts +64 -0
  53. package/dist/connection-state-Bk33YprE.d.ts +32 -0
  54. package/dist/core/bindings/index.d.ts +24 -0
  55. package/dist/core/bindings/index.js +1025 -0
  56. package/dist/core/bindings/index.js.map +1 -0
  57. package/dist/core/index.d.ts +383 -0
  58. package/dist/core/index.js +1284 -0
  59. package/dist/core/index.js.map +1 -0
  60. package/dist/createEphiaClient-BhdZ183V.d.ts +69 -0
  61. package/dist/devices/speechmike/index.d.ts +148 -0
  62. package/dist/devices/speechmike/index.js +40 -0
  63. package/dist/devices/speechmike/index.js.map +1 -0
  64. package/dist/headless/index.d.ts +10 -0
  65. package/dist/headless/index.js +25 -0
  66. package/dist/headless/index.js.map +1 -0
  67. package/dist/index.d.ts +18 -0
  68. package/dist/index.js +119 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/react/index.d.ts +38 -0
  71. package/dist/react/index.js +70 -0
  72. package/dist/react/index.js.map +1 -0
  73. package/dist/rich-editor/index.d.ts +46 -0
  74. package/dist/rich-editor/index.js +13 -0
  75. package/dist/rich-editor/index.js.map +1 -0
  76. package/dist/schema-B2ycPlNB.d.ts +87 -0
  77. package/dist/session-APaXR48R.d.ts +12 -0
  78. package/dist/shared/index.d.ts +16 -0
  79. package/dist/shared/index.js +30 -0
  80. package/dist/shared/index.js.map +1 -0
  81. package/dist/style.css +1093 -0
  82. package/dist/testing/index.d.ts +84 -0
  83. package/dist/testing/index.js +36 -0
  84. package/dist/testing/index.js.map +1 -0
  85. package/dist/types-D5SXPSwR.d.ts +32 -0
  86. package/dist/ui/index.d.ts +30 -0
  87. package/dist/ui/index.js +34 -0
  88. package/dist/ui/index.js.map +1 -0
  89. package/dist/useEphiaSpeechMike-CjD7DWnh.d.ts +64 -0
  90. package/package.json +110 -0
  91. package/src/core/audio/audio-worklet-source.ts +30 -0
  92. package/src/core/audio/index.ts +3 -0
  93. package/src/core/audio/voice-level-meter.test.ts +27 -0
  94. package/src/core/audio/voice-level-meter.ts +270 -0
  95. package/src/core/bindings/EphiaBinding.ts +41 -0
  96. package/src/core/bindings/SegmentBindingBridge.test.ts +422 -0
  97. package/src/core/bindings/SegmentBindingBridge.ts +377 -0
  98. package/src/core/bindings/TargetBinding.ts +142 -0
  99. package/src/core/bindings/adapters/NativeAdapter.test.ts +85 -0
  100. package/src/core/bindings/adapters/NativeAdapter.ts +216 -0
  101. package/src/core/bindings/adapters/ProseMirrorAdapter.ts +231 -0
  102. package/src/core/bindings/adapters/index.ts +2 -0
  103. package/src/core/bindings/binding-factory.ts +78 -0
  104. package/src/core/bindings/detect-editor-type.ts +87 -0
  105. package/src/core/bindings/index.ts +13 -0
  106. package/src/core/bindings/insertion-boundary.test.ts +38 -0
  107. package/src/core/bindings/insertion-boundary.ts +26 -0
  108. package/src/core/bindings/native/NativeBinding.test.ts +277 -0
  109. package/src/core/bindings/native/NativeBinding.ts +239 -0
  110. package/src/core/bindings/resolver.ts +18 -0
  111. package/src/core/bindings/targets/codemirror.binding.ts +293 -0
  112. package/src/core/bindings/targets/contenteditable.binding.ts +452 -0
  113. package/src/core/bindings/targets/index.ts +10 -0
  114. package/src/core/bindings/targets/monaco.binding.ts +315 -0
  115. package/src/core/bindings/targets/tiptap.binding.test.ts +417 -0
  116. package/src/core/bindings/targets/tiptap.binding.ts +1192 -0
  117. package/src/core/bindings/tiptap/TiptapBinding.test.ts +63 -0
  118. package/src/core/bindings/tiptap/TiptapBinding.ts +464 -0
  119. package/src/core/bindings/types.ts +41 -0
  120. package/src/core/client/EphiaAudioClient.ts +654 -0
  121. package/src/core/client/audio-capture.ts +263 -0
  122. package/src/core/client/client-options.ts +39 -0
  123. package/src/core/client/client-state.ts +18 -0
  124. package/src/core/client/constants.ts +23 -0
  125. package/src/core/client/session-api.ts +415 -0
  126. package/src/core/connection/connection-state.ts +78 -0
  127. package/src/core/connection/index.ts +6 -0
  128. package/src/core/index.ts +47 -0
  129. package/src/core/operations/textToDocumentOperations.test.ts +69 -0
  130. package/src/core/operations/textToDocumentOperations.ts +92 -0
  131. package/src/core/runtime/DictationRuntime.test.ts +578 -0
  132. package/src/core/runtime/DictationRuntime.ts +434 -0
  133. package/src/core/runtime/TranscriptApplier.test.ts +355 -0
  134. package/src/core/runtime/TranscriptApplier.ts +229 -0
  135. package/src/core/runtime/index.ts +18 -0
  136. package/src/core/session/index.ts +2 -0
  137. package/src/core/session/session-machine.test.ts +16 -0
  138. package/src/core/session/session-machine.ts +59 -0
  139. package/src/core/targets/EditorContextCollector.ts +71 -0
  140. package/src/core/targets/TargetManager.test.ts +194 -0
  141. package/src/core/targets/TargetManager.ts +194 -0
  142. package/src/core/targets/index.ts +10 -0
  143. package/src/core/text-processing/index.ts +11 -0
  144. package/src/core/text-processing/overlap.test.ts +35 -0
  145. package/src/core/text-processing/overlap.ts +101 -0
  146. package/src/core/text-processing/voice-formatting.normalizer.test.ts +132 -0
  147. package/src/core/text-processing/voice-formatting.normalizer.ts +284 -0
  148. package/src/core/transcript/client-transcript.reducer.ts +366 -0
  149. package/src/core/transcript/client-transcript.state.ts +25 -0
  150. package/src/core/transcript/index.ts +19 -0
  151. package/src/core/transcript/transcript.assembler.test.ts +205 -0
  152. package/src/core/transcript/transcript.assembler.ts +152 -0
  153. package/src/core/transcript/transcript.reducer.test.ts +199 -0
  154. package/src/core/transcript/transcript.reducer.ts +771 -0
  155. package/src/core/transcript/transcript.state.ts +123 -0
  156. package/src/core/transport/LiveKitTransport.publish.test.ts +226 -0
  157. package/src/core/transport/LiveKitTransport.ts +459 -0
  158. package/src/core/transport/MockTransport.ts +231 -0
  159. package/src/core/transport/Transport.ts +82 -0
  160. package/src/debug/sdk-debug-collector.ts +79 -0
  161. package/src/devices/index.ts +2 -0
  162. package/src/devices/speechmike/__tests__/EphiaSpeechMikeProvider.test.tsx +99 -0
  163. package/src/devices/speechmike/__tests__/speechmike-audio-resolver.test.ts +96 -0
  164. package/src/devices/speechmike/__tests__/speechmike-button-router.test.ts +66 -0
  165. package/src/devices/speechmike/__tests__/speechmike-device-manager.test.ts +201 -0
  166. package/src/devices/speechmike/__tests__/speechmike-led-controller.test.ts +68 -0
  167. package/src/devices/speechmike/browser.ts +80 -0
  168. package/src/devices/speechmike/constants.ts +74 -0
  169. package/src/devices/speechmike/dictation-support-loader.ts +81 -0
  170. package/src/devices/speechmike/index.ts +11 -0
  171. package/src/devices/speechmike/react/EphiaSpeechMikeContext.ts +34 -0
  172. package/src/devices/speechmike/react/EphiaSpeechMikeProvider.tsx +287 -0
  173. package/src/devices/speechmike/react/useEphiaSpeechMike.ts +26 -0
  174. package/src/devices/speechmike/speechmike-audio-resolver.ts +58 -0
  175. package/src/devices/speechmike/speechmike-button-router.ts +73 -0
  176. package/src/devices/speechmike/speechmike-device-manager.ts +461 -0
  177. package/src/devices/speechmike/speechmike-led-controller.ts +78 -0
  178. package/src/devices/speechmike/types.ts +96 -0
  179. package/src/dictation_support.d.ts +31 -0
  180. package/src/global.d.ts +10 -0
  181. package/src/headless/createEphiaClient.ts +220 -0
  182. package/src/headless/index.ts +18 -0
  183. package/src/index.ts +89 -0
  184. package/src/react/EphiaAuto.tsx +87 -0
  185. package/src/react/components/EphiaDictationButton.tsx +88 -0
  186. package/src/react/components/EphiaStatusBar.tsx +59 -0
  187. package/src/react/components/EphiaTextarea.tsx +295 -0
  188. package/src/react/ephia-react.css +318 -0
  189. package/src/react/hooks/targets/index.ts +3 -0
  190. package/src/react/hooks/targets/useEphiaCodemirror.ts +35 -0
  191. package/src/react/hooks/targets/useEphiaMonaco.ts +35 -0
  192. package/src/react/hooks/targets/useEphiaTiptap.ts +23 -0
  193. package/src/react/hooks/useEphia.lifecycle.test.tsx +389 -0
  194. package/src/react/hooks/useEphia.ts +367 -0
  195. package/src/react/hooks/useEphiaDiscardTarget.ts +53 -0
  196. package/src/react/hooks/useEphiaServerEvent.ts +33 -0
  197. package/src/react/hooks/useEphiaTarget.ts +47 -0
  198. package/src/react/hooks/useEphiaTranscript.ts +22 -0
  199. package/src/react/index.ts +58 -0
  200. package/src/react/provider/EphiaContext.ts +63 -0
  201. package/src/react/provider/EphiaInternalContext.ts +32 -0
  202. package/src/react/provider/EphiaProvider.tsx +373 -0
  203. package/src/react/registry/binding-factory.ts +7 -0
  204. package/src/react/registry/detect-editor-type.ts +2 -0
  205. package/src/react/registry/events.ts +37 -0
  206. package/src/react/registry/registries/CodeMirrorInstanceRegistry.ts +24 -0
  207. package/src/react/registry/registries/MonacoInstanceRegistry.ts +23 -0
  208. package/src/react/registry/registries/TargetRegistry.ts +327 -0
  209. package/src/react/registry/registries/TiptapInstanceRegistry.ts +43 -0
  210. package/src/react/registry/registries/index.ts +5 -0
  211. package/src/react/store/create-ephia-store.ts +36 -0
  212. package/src/react/store/types.ts +41 -0
  213. package/src/react/utils/flash-range.ts +24 -0
  214. package/src/react/utils/index.ts +1 -0
  215. package/src/rich-editor/adapters/tiptap.test.ts +86 -0
  216. package/src/rich-editor/adapters/tiptap.ts +23 -0
  217. package/src/rich-editor/index.ts +3 -0
  218. package/src/rich-editor/types.ts +24 -0
  219. package/src/rich-editor/use-ephia-rich-editor.test.tsx +202 -0
  220. package/src/rich-editor/use-ephia-rich-editor.ts +47 -0
  221. package/src/shared/config/endpoint.test.ts +45 -0
  222. package/src/shared/config/endpoint.ts +39 -0
  223. package/src/shared/config/schema.ts +32 -0
  224. package/src/shared/effective-text.ts +13 -0
  225. package/src/shared/errors/EphiaSdkError.ts +54 -0
  226. package/src/shared/errors/messages.ts +40 -0
  227. package/src/shared/index.ts +27 -0
  228. package/src/shared/state/audio-state.ts +45 -0
  229. package/src/shared/state/index.ts +2 -0
  230. package/src/shared/store/document-store.ts +32 -0
  231. package/src/shared/store/index.ts +2 -0
  232. package/src/shared/types/editors.ts +28 -0
  233. package/src/shared/types/session.ts +12 -0
  234. package/src/style.css +2 -0
  235. package/src/testing/index.tsx +60 -0
  236. package/src/ui/assets/ephia-logo.svg +4 -0
  237. package/src/ui/components/EphiaLogo.tsx +77 -0
  238. package/src/ui/index.ts +24 -0
  239. package/src/ui/primitives/Button.tsx +53 -0
  240. package/src/ui/primitives/Spinner.tsx +21 -0
  241. package/src/ui/primitives/index.ts +5 -0
  242. package/src/ui/recorder/EphiaFloatingButton.tsx +489 -0
  243. package/src/ui/recorder/MinimalProcessingBars.tsx +122 -0
  244. package/src/ui/recorder/StandardIntensityVisualizer.tsx +148 -0
  245. package/src/ui/recorder/appearance.ts +9 -0
  246. package/src/ui/recorder/index.ts +8 -0
  247. package/src/ui/theme.css +775 -0
@@ -0,0 +1,123 @@
1
+ import type { EphiaAudioEvent, TranscriptSafetyMeta, TranscriptLayoutMeta } from "ephia-protocol";
2
+
3
+ export type LiveTranscriptStatus =
4
+ | "idle"
5
+ | "connecting"
6
+ | "recording"
7
+ | "finalizing"
8
+ | "ended"
9
+ | "error";
10
+
11
+ export type LiveTranscriptChunkStatus =
12
+ | "opened"
13
+ | "processing"
14
+ | "preview"
15
+ | "done"
16
+ | "error";
17
+
18
+ export type LiveTranscriptChunk = {
19
+ segmentId: string;
20
+ segmentSeq: number;
21
+ status: LiveTranscriptChunkStatus;
22
+ text: string;
23
+ previewText?: string;
24
+ previewContinuesPreviousWord?: boolean;
25
+ stablePrefix?: string;
26
+ previewDelta?: string;
27
+ finalizedText?: string;
28
+ committedText?: string;
29
+ revision: number;
30
+ startedAtMs?: number;
31
+ audioClosedAtMs?: number;
32
+ endedAtMs?: number;
33
+ durationMs?: number;
34
+ provider?: string;
35
+ error?: string;
36
+ uncertain?: boolean;
37
+ reason?: string;
38
+ reasonCodes?: string[];
39
+ parseFallback?: boolean;
40
+ source?: string;
41
+ mergedWith?: string | string[];
42
+
43
+ // P1 backend : métadonnées additives — text/committedText/status restent
44
+ // la vérité affichable, ces champs ne servent qu'au debug/observabilité.
45
+ effectiveSource?: string;
46
+ correctionPending?: boolean;
47
+ correctionAccepted?: boolean;
48
+ correctionRejectedReason?: string | null;
49
+ commandsApplied?: string[];
50
+ normalizationsApplied?: string[];
51
+ safety?: TranscriptSafetyMeta;
52
+ layout?: TranscriptLayoutMeta;
53
+ rawStt?: string;
54
+ realtimeText?: string;
55
+ hintSentToSmall?: string | null;
56
+ fallbackText?: string | null;
57
+ smallRawText?: string;
58
+ correctionOutcome?: string;
59
+ debug?: Record<string, unknown>;
60
+ };
61
+
62
+ export type LiveTranscriptDiagnostics = {
63
+ mode?: "time" | "vad";
64
+ eventsCount: number;
65
+ chunksCount: number;
66
+ processingChunks: number;
67
+ doneChunks: number;
68
+ errorChunks: number;
69
+ seqValid: boolean;
70
+ lastProvider?: string;
71
+ lastLatencyMs?: number;
72
+ averageLatencyMs?: number;
73
+ finalTextLength: number;
74
+ previewActive: boolean;
75
+ uncertainChunks?: number;
76
+ parseFallbackChunks?: number;
77
+ contextChars?: number;
78
+ };
79
+
80
+ export type LiveTranscriptState = {
81
+ sessionId: string | null;
82
+ status: LiveTranscriptStatus;
83
+ events: EphiaAudioEvent[];
84
+ chunks: Record<string, LiveTranscriptChunk>;
85
+ orderedSegmentIds: string[];
86
+ finalText: string;
87
+ previewText: string;
88
+ displayText: string;
89
+ documentText: string;
90
+ lastEvent: EphiaAudioEvent | null;
91
+ diagnostics: LiveTranscriptDiagnostics;
92
+ error: { code: string; message: string } | null;
93
+ spinnerTick: number;
94
+ finalizedBeforeReset?: Record<string, true>;
95
+ };
96
+
97
+ export const initialLiveTranscriptState: LiveTranscriptState = {
98
+ sessionId: null,
99
+ status: "idle",
100
+ events: [],
101
+ chunks: {},
102
+ orderedSegmentIds: [],
103
+ finalText: "",
104
+ previewText: "",
105
+ displayText: "",
106
+ documentText: "",
107
+ lastEvent: null,
108
+ diagnostics: {
109
+ eventsCount: 0,
110
+ chunksCount: 0,
111
+ processingChunks: 0,
112
+ doneChunks: 0,
113
+ errorChunks: 0,
114
+ seqValid: true,
115
+ finalTextLength: 0,
116
+ previewActive: false,
117
+ uncertainChunks: 0,
118
+ parseFallbackChunks: 0,
119
+ contextChars: 0,
120
+ },
121
+ error: null,
122
+ spinnerTick: 0,
123
+ };
@@ -0,0 +1,226 @@
1
+ import { ConnectionState, Track } from "livekit-client";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import type { EphiaAudioEvent, EphiaServerEvent } from "ephia-protocol";
4
+ import { LiveKitTransport } from "./LiveKitTransport";
5
+
6
+ describe("LiveKitTransport publishAudio", () => {
7
+ it("publishes microphone track with Track.Source.Microphone", async () => {
8
+ const publishTrack = vi.fn(async () => ({ track: { label: "mic" } }));
9
+ const transport = new LiveKitTransport();
10
+ (transport as unknown as { room: unknown }).room = {
11
+ state: ConnectionState.Connected,
12
+ localParticipant: { publishTrack },
13
+ };
14
+
15
+ const mediaTrack = { label: "Default - MacBook Air Microphone" } as MediaStreamTrack;
16
+ await transport.publishAudio(mediaTrack);
17
+
18
+ expect(publishTrack).toHaveBeenCalledTimes(1);
19
+ const [, options] = publishTrack.mock.calls[0] as unknown as [MediaStreamTrack, { source?: Track.Source }];
20
+ expect(options.source).toBe(Track.Source.Microphone);
21
+ });
22
+ });
23
+
24
+ describe("LiveKitTransport client control wire", () => {
25
+ it("publishes sendMessage as a reliable V2 envelope on ephia.client.control", async () => {
26
+ const publishData = vi.fn(async () => undefined);
27
+ const transport = new LiveKitTransport();
28
+ (transport as unknown as { room: unknown; _sessionId: string }).room = {
29
+ state: ConnectionState.Connected,
30
+ localParticipant: { publishData },
31
+ };
32
+ (transport as unknown as { _sessionId: string })._sessionId = "session-1";
33
+
34
+ await transport.sendMessage({ type: "session.reset", payload: { contextOnly: true } });
35
+
36
+ expect(publishData).toHaveBeenCalledTimes(1);
37
+ const [encoded, options] = publishData.mock.calls[0] as unknown as [
38
+ Uint8Array,
39
+ { reliable?: boolean; topic?: string },
40
+ ];
41
+ const envelope = JSON.parse(new TextDecoder().decode(encoded));
42
+ expect(options).toEqual({ reliable: true, topic: "ephia.client.control" });
43
+ expect(envelope).toMatchObject({
44
+ protocolVersion: 2,
45
+ type: "session.reset",
46
+ sessionId: "session-1",
47
+ payload: { scope: "global", reason: "user_explicit" },
48
+ });
49
+ expect(envelope.clientSeq).toBe(1);
50
+ });
51
+ });
52
+
53
+ describe("LiveKitTransport session.reset wire payload", () => {
54
+ it("preserves scope=target, targetId and reason", async () => {
55
+ const publishData = vi.fn(async () => undefined);
56
+ const transport = new LiveKitTransport();
57
+ (transport as unknown as { room: unknown; _sessionId: string }).room = {
58
+ state: ConnectionState.Connected,
59
+ localParticipant: { publishData },
60
+ };
61
+ (transport as unknown as { _sessionId: string })._sessionId = "session-1";
62
+
63
+ await transport.sendMessage({
64
+ type: "session.reset",
65
+ payload: { scope: "target", targetId: "report", reason: "manual_edit" },
66
+ } as any);
67
+
68
+ expect(publishData).toHaveBeenCalledTimes(1);
69
+ const [encoded] = publishData.mock.calls[0] as unknown as [Uint8Array];
70
+ const envelope = JSON.parse(new TextDecoder().decode(encoded));
71
+ expect(envelope.payload).toEqual({ scope: "target", targetId: "report", reason: "manual_edit" });
72
+ });
73
+
74
+ it("preserves scope=global and reason", async () => {
75
+ const publishData = vi.fn(async () => undefined);
76
+ const transport = new LiveKitTransport();
77
+ (transport as unknown as { room: unknown; _sessionId: string }).room = {
78
+ state: ConnectionState.Connected,
79
+ localParticipant: { publishData },
80
+ };
81
+ (transport as unknown as { _sessionId: string })._sessionId = "session-1";
82
+
83
+ await transport.sendMessage({
84
+ type: "session.reset",
85
+ payload: { scope: "global", reason: "editor_empty" },
86
+ } as any);
87
+
88
+ const [encoded] = publishData.mock.calls[0] as unknown as [Uint8Array];
89
+ const envelope = JSON.parse(new TextDecoder().decode(encoded));
90
+ expect(envelope.payload).toEqual({ scope: "global", reason: "editor_empty" });
91
+ });
92
+
93
+ it("throws when scope=target is missing targetId", async () => {
94
+ const publishData = vi.fn(async () => undefined);
95
+ const transport = new LiveKitTransport();
96
+ (transport as unknown as { room: unknown; _sessionId: string }).room = {
97
+ state: ConnectionState.Connected,
98
+ localParticipant: { publishData },
99
+ };
100
+ (transport as unknown as { _sessionId: string })._sessionId = "session-1";
101
+
102
+ await expect(
103
+ transport.sendMessage({
104
+ type: "session.reset",
105
+ payload: { scope: "target", reason: "user_explicit" },
106
+ } as any)
107
+ ).rejects.toThrow();
108
+ });
109
+ });
110
+
111
+ describe("LiveKitTransport wire event routing", () => {
112
+ it("forwards V2 segment.operation via onServerEvent without legacy synthesis", () => {
113
+ const transport = new LiveKitTransport();
114
+ const serverEvents: EphiaServerEvent[] = [];
115
+ const legacyEvents: EphiaAudioEvent[] = [];
116
+ transport.onServerEvent((event) => serverEvents.push(event));
117
+ transport.onEvent((event) => legacyEvents.push(event));
118
+
119
+ (transport as unknown as {
120
+ _handleWireServerEvent(event: unknown): void;
121
+ })._handleWireServerEvent(
122
+ {
123
+ protocolVersion: 2,
124
+ type: "segment.operation",
125
+ eventId: "evt-1",
126
+ sessionId: "session-1",
127
+ serverSeq: 9,
128
+ sentAt: "2026-06-17T00:00:00+00:00",
129
+ payload: {
130
+ segmentId: "seg-1",
131
+ segmentSeq: 1,
132
+ segmentRevision: 9,
133
+ targetId: "report",
134
+ operation: "upsert",
135
+ stage: "canonical",
136
+ text: "Compte rendu.",
137
+ textForInsertion: "Compte rendu.",
138
+ source: "dova-medical",
139
+ safety: { decision: "accept", score: 0 },
140
+ debug: { rawStt: "compte rendu" },
141
+ },
142
+ }
143
+ );
144
+
145
+ expect(serverEvents).toHaveLength(1);
146
+ expect(serverEvents[0]?.type).toBe("segment.operation");
147
+ expect(legacyEvents).toHaveLength(0);
148
+ });
149
+
150
+ it("emits raw EphiaServerEvent via onServerEvent (V2 path, no inference)", () => {
151
+ const transport = new LiveKitTransport();
152
+ const serverEvents: EphiaServerEvent[] = [];
153
+ transport.onServerEvent((event) => serverEvents.push(event));
154
+
155
+ const wireEvent = {
156
+ protocolVersion: 2 as const,
157
+ type: "segment.operation" as const,
158
+ eventId: "evt-2",
159
+ sessionId: "session-1",
160
+ serverSeq: 10,
161
+ sentAt: "2026-06-17T00:00:00+00:00",
162
+ payload: {
163
+ segmentId: "seg-2",
164
+ segmentSeq: 2,
165
+ segmentRevision: 1,
166
+ targetId: "report",
167
+ operation: "upsert" as const,
168
+ stage: "provisional" as const,
169
+ text: "Acquisition.",
170
+ textForInsertion: "Acquisition.",
171
+ source: "dova-real-time" as const,
172
+ },
173
+ };
174
+
175
+ (transport as unknown as {
176
+ _handleWireServerEvent(event: unknown): void;
177
+ })._handleWireServerEvent(wireEvent);
178
+
179
+ expect(serverEvents).toHaveLength(1);
180
+ const emitted = serverEvents[0]!;
181
+ expect(emitted.type).toBe("segment.operation");
182
+ if (emitted.type === "segment.operation") {
183
+ expect(emitted.payload.segmentId).toBe("seg-2");
184
+ expect(emitted.payload.stage).toBe("provisional");
185
+ expect(emitted.payload.targetId).toBe("report");
186
+ expect(emitted.serverSeq).toBe(10);
187
+ }
188
+ });
189
+
190
+ it("emits segment.operation with absorbedSegmentIds via onServerEvent", () => {
191
+ const transport = new LiveKitTransport();
192
+ const serverEvents: EphiaServerEvent[] = [];
193
+ transport.onServerEvent((event) => serverEvents.push(event));
194
+
195
+ (transport as unknown as {
196
+ _handleWireServerEvent(event: unknown): void;
197
+ })._handleWireServerEvent(
198
+ {
199
+ protocolVersion: 2,
200
+ type: "segment.operation",
201
+ eventId: "evt-3",
202
+ sessionId: "session-1",
203
+ serverSeq: 11,
204
+ sentAt: "2026-06-17T00:00:00+00:00",
205
+ payload: {
206
+ segmentId: "seg-prev",
207
+ segmentSeq: 3,
208
+ segmentRevision: 2,
209
+ targetId: "report",
210
+ operation: "upsert",
211
+ stage: "canonical",
212
+ text: "Texte fusionné.",
213
+ textForInsertion: "Texte fusionné.",
214
+ source: "dova-medical",
215
+ absorbedSegmentIds: ["seg-cur"],
216
+ },
217
+ }
218
+ );
219
+
220
+ const emitted = serverEvents[0];
221
+ expect(emitted?.type).toBe("segment.operation");
222
+ if (emitted?.type === "segment.operation") {
223
+ expect(emitted.payload.absorbedSegmentIds).toEqual(["seg-cur"]);
224
+ }
225
+ });
226
+ });