@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.
- package/README.md +89 -0
- package/dist/EphiaBinding-BvRmlqqC.d.ts +36 -0
- package/dist/EphiaFloatingButton-CxiF86VW.d.ts +65 -0
- package/dist/EphiaTextarea-B4_CAVUg.d.ts +183 -0
- package/dist/NativeBinding-ChG0GeSz.d.ts +53 -0
- package/dist/TargetBinding-BKGQwUMc.d.ts +89 -0
- package/dist/TiptapBinding-B-agfV2H.d.ts +45 -0
- package/dist/Transport-zdeA4Pou.d.ts +63 -0
- package/dist/audio-state-kZ3KSvux.d.ts +39 -0
- package/dist/chunk-35AJK2IO.js +1 -0
- package/dist/chunk-35AJK2IO.js.map +1 -0
- package/dist/chunk-3LXZODL4.js +886 -0
- package/dist/chunk-3LXZODL4.js.map +1 -0
- package/dist/chunk-5IK5TLSK.js +67 -0
- package/dist/chunk-5IK5TLSK.js.map +1 -0
- package/dist/chunk-7E43RY75.js +9 -0
- package/dist/chunk-7E43RY75.js.map +1 -0
- package/dist/chunk-A5UEXJ5R.js +183 -0
- package/dist/chunk-A5UEXJ5R.js.map +1 -0
- package/dist/chunk-AEE554FT.js +51 -0
- package/dist/chunk-AEE554FT.js.map +1 -0
- package/dist/chunk-DIEWY3IT.js +1332 -0
- package/dist/chunk-DIEWY3IT.js.map +1 -0
- package/dist/chunk-EGIAN7FH.js +18 -0
- package/dist/chunk-EGIAN7FH.js.map +1 -0
- package/dist/chunk-EMOEAPVU.js +486 -0
- package/dist/chunk-EMOEAPVU.js.map +1 -0
- package/dist/chunk-IDC7FHIZ.js +40 -0
- package/dist/chunk-IDC7FHIZ.js.map +1 -0
- package/dist/chunk-ITJFN3VM.js +601 -0
- package/dist/chunk-ITJFN3VM.js.map +1 -0
- package/dist/chunk-K24GNU27.js +22 -0
- package/dist/chunk-K24GNU27.js.map +1 -0
- package/dist/chunk-LXMCRXXF.js +778 -0
- package/dist/chunk-LXMCRXXF.js.map +1 -0
- package/dist/chunk-MJCEOOLW.js +122 -0
- package/dist/chunk-MJCEOOLW.js.map +1 -0
- package/dist/chunk-N7U5M3VZ.js +33 -0
- package/dist/chunk-N7U5M3VZ.js.map +1 -0
- package/dist/chunk-PSYX674B.js +27 -0
- package/dist/chunk-PSYX674B.js.map +1 -0
- package/dist/chunk-RFQRV7ML.js +33 -0
- package/dist/chunk-RFQRV7ML.js.map +1 -0
- package/dist/chunk-THNHRV2B.js +18 -0
- package/dist/chunk-THNHRV2B.js.map +1 -0
- package/dist/chunk-VSLGR64U.js +62 -0
- package/dist/chunk-VSLGR64U.js.map +1 -0
- package/dist/chunk-W2ZP674X.js +346 -0
- package/dist/chunk-W2ZP674X.js.map +1 -0
- package/dist/chunk-YWZUMUYE.js +695 -0
- package/dist/chunk-YWZUMUYE.js.map +1 -0
- package/dist/client-options-Uo6jXO8k.d.ts +64 -0
- package/dist/connection-state-Bk33YprE.d.ts +32 -0
- package/dist/core/bindings/index.d.ts +24 -0
- package/dist/core/bindings/index.js +1025 -0
- package/dist/core/bindings/index.js.map +1 -0
- package/dist/core/index.d.ts +383 -0
- package/dist/core/index.js +1284 -0
- package/dist/core/index.js.map +1 -0
- package/dist/createEphiaClient-BhdZ183V.d.ts +69 -0
- package/dist/devices/speechmike/index.d.ts +148 -0
- package/dist/devices/speechmike/index.js +40 -0
- package/dist/devices/speechmike/index.js.map +1 -0
- package/dist/headless/index.d.ts +10 -0
- package/dist/headless/index.js +25 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +38 -0
- package/dist/react/index.js +70 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rich-editor/index.d.ts +46 -0
- package/dist/rich-editor/index.js +13 -0
- package/dist/rich-editor/index.js.map +1 -0
- package/dist/schema-B2ycPlNB.d.ts +87 -0
- package/dist/session-APaXR48R.d.ts +12 -0
- package/dist/shared/index.d.ts +16 -0
- package/dist/shared/index.js +30 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/style.css +1093 -0
- package/dist/testing/index.d.ts +84 -0
- package/dist/testing/index.js +36 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/types-D5SXPSwR.d.ts +32 -0
- package/dist/ui/index.d.ts +30 -0
- package/dist/ui/index.js +34 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/useEphiaSpeechMike-CjD7DWnh.d.ts +64 -0
- package/package.json +110 -0
- package/src/core/audio/audio-worklet-source.ts +30 -0
- package/src/core/audio/index.ts +3 -0
- package/src/core/audio/voice-level-meter.test.ts +27 -0
- package/src/core/audio/voice-level-meter.ts +270 -0
- package/src/core/bindings/EphiaBinding.ts +41 -0
- package/src/core/bindings/SegmentBindingBridge.test.ts +422 -0
- package/src/core/bindings/SegmentBindingBridge.ts +377 -0
- package/src/core/bindings/TargetBinding.ts +142 -0
- package/src/core/bindings/adapters/NativeAdapter.test.ts +85 -0
- package/src/core/bindings/adapters/NativeAdapter.ts +216 -0
- package/src/core/bindings/adapters/ProseMirrorAdapter.ts +231 -0
- package/src/core/bindings/adapters/index.ts +2 -0
- package/src/core/bindings/binding-factory.ts +78 -0
- package/src/core/bindings/detect-editor-type.ts +87 -0
- package/src/core/bindings/index.ts +13 -0
- package/src/core/bindings/insertion-boundary.test.ts +38 -0
- package/src/core/bindings/insertion-boundary.ts +26 -0
- package/src/core/bindings/native/NativeBinding.test.ts +277 -0
- package/src/core/bindings/native/NativeBinding.ts +239 -0
- package/src/core/bindings/resolver.ts +18 -0
- package/src/core/bindings/targets/codemirror.binding.ts +293 -0
- package/src/core/bindings/targets/contenteditable.binding.ts +452 -0
- package/src/core/bindings/targets/index.ts +10 -0
- package/src/core/bindings/targets/monaco.binding.ts +315 -0
- package/src/core/bindings/targets/tiptap.binding.test.ts +417 -0
- package/src/core/bindings/targets/tiptap.binding.ts +1192 -0
- package/src/core/bindings/tiptap/TiptapBinding.test.ts +63 -0
- package/src/core/bindings/tiptap/TiptapBinding.ts +464 -0
- package/src/core/bindings/types.ts +41 -0
- package/src/core/client/EphiaAudioClient.ts +654 -0
- package/src/core/client/audio-capture.ts +263 -0
- package/src/core/client/client-options.ts +39 -0
- package/src/core/client/client-state.ts +18 -0
- package/src/core/client/constants.ts +23 -0
- package/src/core/client/session-api.ts +415 -0
- package/src/core/connection/connection-state.ts +78 -0
- package/src/core/connection/index.ts +6 -0
- package/src/core/index.ts +47 -0
- package/src/core/operations/textToDocumentOperations.test.ts +69 -0
- package/src/core/operations/textToDocumentOperations.ts +92 -0
- package/src/core/runtime/DictationRuntime.test.ts +578 -0
- package/src/core/runtime/DictationRuntime.ts +434 -0
- package/src/core/runtime/TranscriptApplier.test.ts +355 -0
- package/src/core/runtime/TranscriptApplier.ts +229 -0
- package/src/core/runtime/index.ts +18 -0
- package/src/core/session/index.ts +2 -0
- package/src/core/session/session-machine.test.ts +16 -0
- package/src/core/session/session-machine.ts +59 -0
- package/src/core/targets/EditorContextCollector.ts +71 -0
- package/src/core/targets/TargetManager.test.ts +194 -0
- package/src/core/targets/TargetManager.ts +194 -0
- package/src/core/targets/index.ts +10 -0
- package/src/core/text-processing/index.ts +11 -0
- package/src/core/text-processing/overlap.test.ts +35 -0
- package/src/core/text-processing/overlap.ts +101 -0
- package/src/core/text-processing/voice-formatting.normalizer.test.ts +132 -0
- package/src/core/text-processing/voice-formatting.normalizer.ts +284 -0
- package/src/core/transcript/client-transcript.reducer.ts +366 -0
- package/src/core/transcript/client-transcript.state.ts +25 -0
- package/src/core/transcript/index.ts +19 -0
- package/src/core/transcript/transcript.assembler.test.ts +205 -0
- package/src/core/transcript/transcript.assembler.ts +152 -0
- package/src/core/transcript/transcript.reducer.test.ts +199 -0
- package/src/core/transcript/transcript.reducer.ts +771 -0
- package/src/core/transcript/transcript.state.ts +123 -0
- package/src/core/transport/LiveKitTransport.publish.test.ts +226 -0
- package/src/core/transport/LiveKitTransport.ts +459 -0
- package/src/core/transport/MockTransport.ts +231 -0
- package/src/core/transport/Transport.ts +82 -0
- package/src/debug/sdk-debug-collector.ts +79 -0
- package/src/devices/index.ts +2 -0
- package/src/devices/speechmike/__tests__/EphiaSpeechMikeProvider.test.tsx +99 -0
- package/src/devices/speechmike/__tests__/speechmike-audio-resolver.test.ts +96 -0
- package/src/devices/speechmike/__tests__/speechmike-button-router.test.ts +66 -0
- package/src/devices/speechmike/__tests__/speechmike-device-manager.test.ts +201 -0
- package/src/devices/speechmike/__tests__/speechmike-led-controller.test.ts +68 -0
- package/src/devices/speechmike/browser.ts +80 -0
- package/src/devices/speechmike/constants.ts +74 -0
- package/src/devices/speechmike/dictation-support-loader.ts +81 -0
- package/src/devices/speechmike/index.ts +11 -0
- package/src/devices/speechmike/react/EphiaSpeechMikeContext.ts +34 -0
- package/src/devices/speechmike/react/EphiaSpeechMikeProvider.tsx +287 -0
- package/src/devices/speechmike/react/useEphiaSpeechMike.ts +26 -0
- package/src/devices/speechmike/speechmike-audio-resolver.ts +58 -0
- package/src/devices/speechmike/speechmike-button-router.ts +73 -0
- package/src/devices/speechmike/speechmike-device-manager.ts +461 -0
- package/src/devices/speechmike/speechmike-led-controller.ts +78 -0
- package/src/devices/speechmike/types.ts +96 -0
- package/src/dictation_support.d.ts +31 -0
- package/src/global.d.ts +10 -0
- package/src/headless/createEphiaClient.ts +220 -0
- package/src/headless/index.ts +18 -0
- package/src/index.ts +89 -0
- package/src/react/EphiaAuto.tsx +87 -0
- package/src/react/components/EphiaDictationButton.tsx +88 -0
- package/src/react/components/EphiaStatusBar.tsx +59 -0
- package/src/react/components/EphiaTextarea.tsx +295 -0
- package/src/react/ephia-react.css +318 -0
- package/src/react/hooks/targets/index.ts +3 -0
- package/src/react/hooks/targets/useEphiaCodemirror.ts +35 -0
- package/src/react/hooks/targets/useEphiaMonaco.ts +35 -0
- package/src/react/hooks/targets/useEphiaTiptap.ts +23 -0
- package/src/react/hooks/useEphia.lifecycle.test.tsx +389 -0
- package/src/react/hooks/useEphia.ts +367 -0
- package/src/react/hooks/useEphiaDiscardTarget.ts +53 -0
- package/src/react/hooks/useEphiaServerEvent.ts +33 -0
- package/src/react/hooks/useEphiaTarget.ts +47 -0
- package/src/react/hooks/useEphiaTranscript.ts +22 -0
- package/src/react/index.ts +58 -0
- package/src/react/provider/EphiaContext.ts +63 -0
- package/src/react/provider/EphiaInternalContext.ts +32 -0
- package/src/react/provider/EphiaProvider.tsx +373 -0
- package/src/react/registry/binding-factory.ts +7 -0
- package/src/react/registry/detect-editor-type.ts +2 -0
- package/src/react/registry/events.ts +37 -0
- package/src/react/registry/registries/CodeMirrorInstanceRegistry.ts +24 -0
- package/src/react/registry/registries/MonacoInstanceRegistry.ts +23 -0
- package/src/react/registry/registries/TargetRegistry.ts +327 -0
- package/src/react/registry/registries/TiptapInstanceRegistry.ts +43 -0
- package/src/react/registry/registries/index.ts +5 -0
- package/src/react/store/create-ephia-store.ts +36 -0
- package/src/react/store/types.ts +41 -0
- package/src/react/utils/flash-range.ts +24 -0
- package/src/react/utils/index.ts +1 -0
- package/src/rich-editor/adapters/tiptap.test.ts +86 -0
- package/src/rich-editor/adapters/tiptap.ts +23 -0
- package/src/rich-editor/index.ts +3 -0
- package/src/rich-editor/types.ts +24 -0
- package/src/rich-editor/use-ephia-rich-editor.test.tsx +202 -0
- package/src/rich-editor/use-ephia-rich-editor.ts +47 -0
- package/src/shared/config/endpoint.test.ts +45 -0
- package/src/shared/config/endpoint.ts +39 -0
- package/src/shared/config/schema.ts +32 -0
- package/src/shared/effective-text.ts +13 -0
- package/src/shared/errors/EphiaSdkError.ts +54 -0
- package/src/shared/errors/messages.ts +40 -0
- package/src/shared/index.ts +27 -0
- package/src/shared/state/audio-state.ts +45 -0
- package/src/shared/state/index.ts +2 -0
- package/src/shared/store/document-store.ts +32 -0
- package/src/shared/store/index.ts +2 -0
- package/src/shared/types/editors.ts +28 -0
- package/src/shared/types/session.ts +12 -0
- package/src/style.css +2 -0
- package/src/testing/index.tsx +60 -0
- package/src/ui/assets/ephia-logo.svg +4 -0
- package/src/ui/components/EphiaLogo.tsx +77 -0
- package/src/ui/index.ts +24 -0
- package/src/ui/primitives/Button.tsx +53 -0
- package/src/ui/primitives/Spinner.tsx +21 -0
- package/src/ui/primitives/index.ts +5 -0
- package/src/ui/recorder/EphiaFloatingButton.tsx +489 -0
- package/src/ui/recorder/MinimalProcessingBars.tsx +122 -0
- package/src/ui/recorder/StandardIntensityVisualizer.tsx +148 -0
- package/src/ui/recorder/appearance.ts +9 -0
- package/src/ui/recorder/index.ts +8 -0
- 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
|
+
});
|