dsh-live-voice 0.6.2 → 0.7.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/deploy/attendee/README.md +34 -0
- package/deploy/attendee/audio_bridge.py +186 -0
- package/deploy/attendee/compose.dsh-audio.yaml +54 -0
- package/deploy/attendee/cross_runtime_fixture.py +46 -0
- package/deploy/attendee/test_audio_bridge.py +170 -0
- package/lib/asr/asr.worker.js +1 -1
- package/lib/asr/manifest.json +1 -1
- package/lib/client.js +14848 -11796
- package/lib/server.js +1051 -14
- package/lib/vad/manifest.json +2 -2
- package/lib/vad/vad.worker.js +1 -1
- package/package.json +5 -3
- package/src/app/ARCHITECTURE.md +2 -0
- package/src/app/client/apply.tsx +74 -15
- package/src/app/client/i18n/catalogs/base.ts +87 -1
- package/src/app/client/i18n/catalogs/en.ts +119 -3
- package/src/app/client/i18n/catalogs/es.ts +120 -4
- package/src/app/client/i18n/catalogs/fr.ts +121 -4
- package/src/app/client/i18n/catalogs/hi.ts +118 -4
- package/src/app/client/i18n/catalogs/pt-BR.ts +119 -3
- package/src/app/client/i18n/catalogs/zh.ts +114 -3
- package/src/app/server/apply.ts +5 -0
- package/src/app/server/attendeeConnection.ts +133 -0
- package/src/app/server/attendeeCredentials.ts +144 -0
- package/src/app/server/attendeeRelay.ts +104 -0
- package/src/app/server/attendeeRoutes.ts +476 -0
- package/src/app/server/chatterboxRoutes.ts +73 -0
- package/src/modules/conversation/ARCHITECTURE.md +1 -0
- package/src/modules/conversation/components/AttendeeControls.tsx +376 -0
- package/src/modules/conversation/components/AutoPlaybackToggle.tsx +32 -13
- package/src/modules/conversation/components/ConversationControls.tsx +8 -5
- package/src/modules/conversation/components/ConversationStatusBar.tsx +18 -2
- package/src/modules/conversation/components/DevicePopover.tsx +31 -0
- package/src/modules/conversation/components/MeetingControls.tsx +102 -15
- package/src/modules/conversation/components/MicrophoneButton.tsx +1 -1
- package/src/modules/conversation/components/RecoveryFeedback.tsx +39 -0
- package/src/modules/conversation/components/SpeechStatusBar.tsx +15 -3
- package/src/modules/conversation/components/conversationStatus.ts +7 -0
- package/src/modules/conversation/components/createConversationComponents.tsx +6 -1
- package/src/modules/conversation/models/AttendeeClient.ts +742 -0
- package/src/modules/conversation/models/AttendeeHub.ts +98 -0
- package/src/modules/conversation/models/ParticipantPcmMeter.ts +58 -0
- package/src/modules/conversation/models/attendeeProtocol.ts +53 -0
- package/src/modules/conversation/models/meeting.ts +244 -41
- package/src/modules/conversation/models/meetingTranscript.ts +14 -3
- package/src/modules/core/ARCHITECTURE.md +2 -0
- package/src/modules/core/coordinator.ts +305 -22
- package/src/modules/core/engineSelection.ts +2 -2
- package/src/modules/core/networkFailure.ts +10 -0
- package/src/modules/core/recovery.ts +26 -0
- package/src/modules/core/settings.ts +16 -1
- package/src/modules/recognition/engines/browser/BrowserRecognitionEngine.ts +1 -1
- package/src/modules/recognition/engines/browser/transcribeRecording.ts +241 -0
- package/src/modules/recognition/engines/whisper/WhisperRecognitionEngine.ts +5 -1
- package/src/modules/recognition/engines/whisper/whisperRecognitionHost.ts +5 -2
- package/src/modules/recognition/recordingTranscriber.ts +143 -0
- package/src/modules/recording/ARCHITECTURE.md +12 -1
- package/src/modules/recording/RecordingRecognition.ts +95 -16
- package/src/modules/recording/repository.ts +279 -16
- package/src/modules/recording/requestMetadata.ts +30 -0
- package/src/modules/recording/storage.ts +61 -0
- package/src/modules/recording/types.ts +63 -1
- package/src/modules/settings/ARCHITECTURE.md +2 -0
- package/src/modules/settings/components/AudioDeviceField.tsx +43 -0
- package/src/modules/settings/models/browserVoiceSelection.ts +15 -0
- package/src/modules/settings/sections/conversation/ConversationSettingsSection.tsx +3 -0
- package/src/modules/settings/sections/conversation/MeetingSourceSettings.tsx +14 -2
- package/src/modules/settings/sections/recognition/RecognitionEngineSettings.tsx +4 -11
- package/src/modules/settings/sections/recognition/RecognitionSettingsSection.tsx +0 -2
- package/src/modules/settings/sections/speak/SpeechAdvancedSettings.tsx +6 -20
- package/src/modules/settings/sections/speak/SpeechEngineSettings.tsx +5 -0
- package/src/modules/speak/ARCHITECTURE.md +3 -1
- package/src/modules/speak/chatterbox/ChatterboxVoiceSettings.tsx +60 -0
- package/src/modules/speak/engines/audio/HostAudioEngine.ts +105 -38
- package/src/modules/speak/engines/chatterbox/ChatterboxHttpHost.ts +130 -0
- package/src/modules/speak/engines/chatterbox/ChatterboxSpeakingEngine.ts +14 -0
- package/src/modules/speak/index.ts +1 -0
- package/src/shared/ARCHITECTURE.md +2 -0
- package/src/shared/design-system/feedback/ContextPopover.tsx +107 -0
- package/src/styles/index.ts +6 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { open, mkdir, rename, rm } from 'node:fs/promises';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { validateAttendeeApi } from './attendeeConnection.js';
|
|
7
|
+
|
|
8
|
+
const queues = new Map<string, Promise<unknown>>();
|
|
9
|
+
const invalid = () => new Error('credential-storage-invalid');
|
|
10
|
+
export function validateAttendeeKey(value: unknown): string {
|
|
11
|
+
if (
|
|
12
|
+
typeof value !== 'string' ||
|
|
13
|
+
value.length < 8 ||
|
|
14
|
+
value.length > 512 ||
|
|
15
|
+
/[\x00-\x20\x7f]/.test(value)
|
|
16
|
+
)
|
|
17
|
+
throw new Error('invalid-api');
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
/** Host-only plaintext credentials. File permissions are not encryption or OS-keychain protection. */
|
|
21
|
+
export function createAttendeeCredentialStore(
|
|
22
|
+
path = join(homedir(), '.dsh', 'dsh-live-voice.attendee-credentials.json'),
|
|
23
|
+
) {
|
|
24
|
+
path = resolve(path);
|
|
25
|
+
const serial = <T>(run: () => Promise<T>): Promise<T> => {
|
|
26
|
+
const next = (queues.get(path) ?? Promise.resolve()).then(run);
|
|
27
|
+
const tail = next.then(
|
|
28
|
+
() => {},
|
|
29
|
+
() => {},
|
|
30
|
+
);
|
|
31
|
+
queues.set(path, tail);
|
|
32
|
+
void tail.then(() => {
|
|
33
|
+
if (queues.get(path) === tail) queues.delete(path);
|
|
34
|
+
});
|
|
35
|
+
return next;
|
|
36
|
+
};
|
|
37
|
+
async function load(): Promise<Record<string, string>> {
|
|
38
|
+
let file;
|
|
39
|
+
try {
|
|
40
|
+
file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
41
|
+
const stat = await file.stat();
|
|
42
|
+
if (
|
|
43
|
+
!stat.isFile() ||
|
|
44
|
+
stat.size > 65536 ||
|
|
45
|
+
(stat.mode & 0o777) !== 0o600 ||
|
|
46
|
+
(process.getuid && stat.uid !== process.getuid())
|
|
47
|
+
)
|
|
48
|
+
throw invalid();
|
|
49
|
+
const buffer = Buffer.alloc(65537);
|
|
50
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
51
|
+
if (bytesRead > 65536) throw invalid();
|
|
52
|
+
const doc = JSON.parse(buffer.subarray(0, bytesRead).toString('utf8'));
|
|
53
|
+
if (
|
|
54
|
+
!doc ||
|
|
55
|
+
typeof doc !== 'object' ||
|
|
56
|
+
Array.isArray(doc) ||
|
|
57
|
+
Object.keys(doc).sort().join(',') !== 'origins,version' ||
|
|
58
|
+
doc.version !== 1 ||
|
|
59
|
+
!doc.origins ||
|
|
60
|
+
typeof doc.origins !== 'object' ||
|
|
61
|
+
Array.isArray(doc.origins)
|
|
62
|
+
)
|
|
63
|
+
throw invalid();
|
|
64
|
+
const entries = Object.entries(doc.origins);
|
|
65
|
+
if (entries.length > 32) throw invalid();
|
|
66
|
+
const origins = Object.create(null);
|
|
67
|
+
for (const [origin, key] of entries) {
|
|
68
|
+
try {
|
|
69
|
+
if (origin.length > 256 || validateAttendeeApi(origin) !== origin) throw invalid();
|
|
70
|
+
origins[origin] = validateAttendeeKey(key);
|
|
71
|
+
} catch {
|
|
72
|
+
throw invalid();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return origins;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return Object.create(null);
|
|
78
|
+
if (
|
|
79
|
+
(error as Error).message === 'credential-storage-invalid' ||
|
|
80
|
+
error instanceof SyntaxError ||
|
|
81
|
+
(error as Error).message === 'invalid-api' ||
|
|
82
|
+
(error as NodeJS.ErrnoException).code === 'ELOOP'
|
|
83
|
+
)
|
|
84
|
+
throw invalid();
|
|
85
|
+
throw new Error('credential-storage-unavailable');
|
|
86
|
+
} finally {
|
|
87
|
+
await file?.close().catch(() => {});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function origin(value: string) {
|
|
91
|
+
try {
|
|
92
|
+
const normalized = validateAttendeeApi(value);
|
|
93
|
+
if (normalized.length > 256) throw Error();
|
|
94
|
+
return normalized;
|
|
95
|
+
} catch {
|
|
96
|
+
throw new Error('invalid-api');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function mutate(apiUrl: string, key?: string) {
|
|
100
|
+
const normalized = origin(apiUrl);
|
|
101
|
+
const validated = key === undefined ? undefined : validateAttendeeKey(key);
|
|
102
|
+
return serial(async () => {
|
|
103
|
+
const origins = await load();
|
|
104
|
+
if (validated === undefined) delete origins[normalized];
|
|
105
|
+
else origins[normalized] = validated;
|
|
106
|
+
if (Object.keys(origins).length > 32) throw invalid();
|
|
107
|
+
const data = JSON.stringify({ version: 1, origins }) + '\n';
|
|
108
|
+
if (Buffer.byteLength(data) > 65536) throw invalid();
|
|
109
|
+
const temporary = path + '.' + randomUUID() + '.tmp';
|
|
110
|
+
try {
|
|
111
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
112
|
+
const file = await open(temporary, 'wx', 0o600);
|
|
113
|
+
try {
|
|
114
|
+
await file.writeFile(data);
|
|
115
|
+
await file.sync();
|
|
116
|
+
} finally {
|
|
117
|
+
await file.close();
|
|
118
|
+
}
|
|
119
|
+
await rename(temporary, path);
|
|
120
|
+
} catch {
|
|
121
|
+
throw new Error('credential-storage-unavailable');
|
|
122
|
+
} finally {
|
|
123
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
124
|
+
}
|
|
125
|
+
return { hasSavedKey: validated !== undefined };
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
metadata(apiUrl: string) {
|
|
130
|
+
const normalized = origin(apiUrl);
|
|
131
|
+
return serial(async () => ({ hasSavedKey: Object.hasOwn(await load(), normalized) }));
|
|
132
|
+
},
|
|
133
|
+
get(apiUrl: string) {
|
|
134
|
+
const normalized = origin(apiUrl);
|
|
135
|
+
return serial(async () => {
|
|
136
|
+
const key = (await load())[normalized];
|
|
137
|
+
if (!key) throw new Error('credential-missing');
|
|
138
|
+
return key;
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
save: (apiUrl: string, key: string) => mutate(apiUrl, key),
|
|
142
|
+
remove: (apiUrl: string) => mutate(apiUrl),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import { X509Certificate } from 'node:crypto';
|
|
3
|
+
/** Local descriptor is a loopback bootstrap, not a public PKI or a global trust change. */
|
|
4
|
+
export async function connectAttendeeRelay(apiKey, hub, session, loadWs, fetcher, abort) {
|
|
5
|
+
const timeout = AbortSignal.timeout(5000);
|
|
6
|
+
const signal = AbortSignal.any([timeout, abort.signal]);
|
|
7
|
+
const response = await fetcher('http://127.0.0.1:18766/v1/descriptor', {
|
|
8
|
+
redirect: 'error',
|
|
9
|
+
signal,
|
|
10
|
+
});
|
|
11
|
+
if (!response.ok) throw new Error('relay-unavailable');
|
|
12
|
+
const reader = response.body.getReader();
|
|
13
|
+
let bytes = 0;
|
|
14
|
+
const chunks = [];
|
|
15
|
+
try {
|
|
16
|
+
while (true) {
|
|
17
|
+
const { value, done } = await reader.read();
|
|
18
|
+
if (done) break;
|
|
19
|
+
bytes += value.byteLength;
|
|
20
|
+
if (bytes > 16000) throw Error('relay-unavailable');
|
|
21
|
+
chunks.push(Buffer.from(value));
|
|
22
|
+
}
|
|
23
|
+
} finally {
|
|
24
|
+
await reader.cancel().catch(() => {});
|
|
25
|
+
}
|
|
26
|
+
const descriptor = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
27
|
+
if (descriptor.protocol !== 'dsh-attendee-relay-v1' || typeof descriptor.certificate !== 'string')
|
|
28
|
+
throw Error('relay-unavailable');
|
|
29
|
+
const cert = new X509Certificate(descriptor.certificate);
|
|
30
|
+
if (!cert.checkIP('127.0.0.1') || Date.parse(cert.validTo) <= Date.now())
|
|
31
|
+
throw Error('relay-unavailable');
|
|
32
|
+
const module = await loadWs();
|
|
33
|
+
const WebSocket = module.WebSocket || module.default;
|
|
34
|
+
if (abort.signal.aborted || hub.session !== session) throw Error('closed');
|
|
35
|
+
const ws = new WebSocket('wss://127.0.0.1:18765/v1/receive', {
|
|
36
|
+
ca: descriptor.certificate,
|
|
37
|
+
rejectUnauthorized: true,
|
|
38
|
+
headers: { Authorization: 'Token ' + apiKey },
|
|
39
|
+
maxPayload: 128000,
|
|
40
|
+
perMessageDeflate: false,
|
|
41
|
+
handshakeTimeout: 5000,
|
|
42
|
+
});
|
|
43
|
+
session.socket = ws;
|
|
44
|
+
return await new Promise((resolve, reject) => {
|
|
45
|
+
let ready = false,
|
|
46
|
+
settled = false;
|
|
47
|
+
const stop = () => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
abort.signal.removeEventListener('abort', stop);
|
|
50
|
+
ws.terminate();
|
|
51
|
+
if (!settled) {
|
|
52
|
+
settled = true;
|
|
53
|
+
reject(Error('closed'));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
abort.signal.addEventListener('abort', stop, { once: true });
|
|
57
|
+
const timer = setTimeout(() => {
|
|
58
|
+
stop();
|
|
59
|
+
}, 6000);
|
|
60
|
+
const failed = () => {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
abort.signal.removeEventListener('abort', stop);
|
|
63
|
+
if (!settled) {
|
|
64
|
+
settled = true;
|
|
65
|
+
reject(Error('relay-unavailable'));
|
|
66
|
+
} else if (hub.session === session && !session.error) hub.fail('connection');
|
|
67
|
+
};
|
|
68
|
+
ws.on('error', failed);
|
|
69
|
+
ws.on('close', failed);
|
|
70
|
+
ws.on('message', (data, binary) => {
|
|
71
|
+
if (hub.session !== session) return;
|
|
72
|
+
try {
|
|
73
|
+
if (binary) throw Error('invalid-audio');
|
|
74
|
+
const value = JSON.parse(data.toString());
|
|
75
|
+
if (!ready) {
|
|
76
|
+
const url = new URL(value.ingestUrl);
|
|
77
|
+
if (
|
|
78
|
+
value.type !== 'ready' ||
|
|
79
|
+
url.origin !== 'wss://dsh-audio-bridge:18765' ||
|
|
80
|
+
url.pathname !== '/ingest' ||
|
|
81
|
+
!/^\?token=[a-f0-9]{64}$/.test(url.search) ||
|
|
82
|
+
url.username ||
|
|
83
|
+
url.password ||
|
|
84
|
+
url.hash
|
|
85
|
+
)
|
|
86
|
+
throw Error('relay-unavailable');
|
|
87
|
+
ready = true;
|
|
88
|
+
settled = true;
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
resolve(url.href);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
hub.ingest(value);
|
|
94
|
+
} catch {
|
|
95
|
+
hub.fail('invalid-audio');
|
|
96
|
+
if (!settled) {
|
|
97
|
+
settled = true;
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
reject(Error('relay-unavailable'));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|