@goodandready/dsh-voice 0.9.48 → 0.9.49
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/lib/client.js +97 -59
- package/lib/index.js +26 -182
- package/lib/server-daemons.js +10 -0
- package/lib/server-routes.js +59 -0
- package/lib/server-tools.js +74 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -315,6 +315,86 @@ window.__ModuleLoader__.load({
|
|
|
315
315
|
tag.dataset.pluginCss = cssId
|
|
316
316
|
document.head.appendChild(tag)
|
|
317
317
|
}
|
|
318
|
+
// Centralized API Client / DAO layer for all backend HTTP and WebSocket calls (#307)
|
|
319
|
+
const apiClient = {
|
|
320
|
+
getTokenHeaders() {
|
|
321
|
+
return typeof window !== 'undefined' && window.__dshVoiceToken
|
|
322
|
+
? { 'x-dsh-voice-token': window.__dshVoiceToken }
|
|
323
|
+
: {}
|
|
324
|
+
},
|
|
325
|
+
getStatus(opts = {}) {
|
|
326
|
+
return fetch('/dsh-voice/status', { cache: 'no-store', ...opts })
|
|
327
|
+
},
|
|
328
|
+
getConfig() {
|
|
329
|
+
return fetch('/dsh-voice/config', { cache: 'no-store' })
|
|
330
|
+
},
|
|
331
|
+
putConfig(payload) {
|
|
332
|
+
return fetch('/dsh-voice/config', {
|
|
333
|
+
method: 'PUT',
|
|
334
|
+
headers: { 'Content-Type': 'application/json', ...this.getTokenHeaders() },
|
|
335
|
+
body: JSON.stringify(payload),
|
|
336
|
+
})
|
|
337
|
+
},
|
|
338
|
+
transcribe(payload, opts = {}) {
|
|
339
|
+
return fetch('/dsh-voice/transcribe', {
|
|
340
|
+
method: 'POST',
|
|
341
|
+
headers: { 'content-type': 'application/json', ...this.getTokenHeaders() },
|
|
342
|
+
body: JSON.stringify(payload),
|
|
343
|
+
signal: opts.signal,
|
|
344
|
+
})
|
|
345
|
+
},
|
|
346
|
+
polish(payload) {
|
|
347
|
+
return fetch('/dsh-voice/polish', {
|
|
348
|
+
method: 'POST',
|
|
349
|
+
headers: { 'content-type': 'application/json', ...this.getTokenHeaders() },
|
|
350
|
+
body: JSON.stringify(payload),
|
|
351
|
+
})
|
|
352
|
+
},
|
|
353
|
+
getSensevoiceInstaller() {
|
|
354
|
+
return fetch('/dsh-voice/sensevoice-installer')
|
|
355
|
+
},
|
|
356
|
+
installSensevoice(modelType = 'sensevoice') {
|
|
357
|
+
return fetch('/dsh-voice/sensevoice-installer', {
|
|
358
|
+
method: 'POST',
|
|
359
|
+
headers: {
|
|
360
|
+
'x-dsh-plugin-update': '1',
|
|
361
|
+
'Content-Type': 'application/json',
|
|
362
|
+
},
|
|
363
|
+
body: JSON.stringify({ model: modelType }),
|
|
364
|
+
})
|
|
365
|
+
},
|
|
366
|
+
getUpdateStatus() {
|
|
367
|
+
return fetch('/api/dsh-voice/update', {
|
|
368
|
+
headers: { accept: 'application/json' },
|
|
369
|
+
cache: 'no-store',
|
|
370
|
+
})
|
|
371
|
+
},
|
|
372
|
+
triggerUpdate() {
|
|
373
|
+
return fetch('/api/dsh-voice/update', {
|
|
374
|
+
method: 'POST',
|
|
375
|
+
headers: {
|
|
376
|
+
'content-type': 'application/json',
|
|
377
|
+
'x-dsh-plugin-update': '1',
|
|
378
|
+
},
|
|
379
|
+
cache: 'no-store',
|
|
380
|
+
})
|
|
381
|
+
},
|
|
382
|
+
runBenchmark() {
|
|
383
|
+
return fetch('/dsh-voice/benchmark', {
|
|
384
|
+
method: 'POST',
|
|
385
|
+
headers: {
|
|
386
|
+
'x-dsh-plugin-update': '1',
|
|
387
|
+
'Content-Type': 'application/json',
|
|
388
|
+
},
|
|
389
|
+
})
|
|
390
|
+
},
|
|
391
|
+
exportDiagnostics() {
|
|
392
|
+
return fetch('/dsh-voice/diagnostics/export')
|
|
393
|
+
},
|
|
394
|
+
openWebSocket(url) {
|
|
395
|
+
return new WebSocket(url)
|
|
396
|
+
},
|
|
397
|
+
}
|
|
318
398
|
const voice = {
|
|
319
399
|
phase: 'idle', // idle | recording | processing | pending | error
|
|
320
400
|
mode: 'dictation', // dictation | message
|
|
@@ -572,10 +652,7 @@ window.__ModuleLoader__.load({
|
|
|
572
652
|
const timer = controller ? setTimeout(() => controller.abort(), 60000) : null
|
|
573
653
|
let res = null
|
|
574
654
|
try {
|
|
575
|
-
res = await
|
|
576
|
-
method: 'POST',
|
|
577
|
-
headers: { 'content-type': 'application/json', ...(typeof window !== 'undefined' && window.__dshVoiceToken ? { 'x-dsh-voice-token': window.__dshVoiceToken } : {}) },
|
|
578
|
-
body: JSON.stringify(payload),
|
|
655
|
+
res = await apiClient.transcribe(payload, {
|
|
579
656
|
signal: controller ? controller.signal : undefined,
|
|
580
657
|
})
|
|
581
658
|
} catch (e) {
|
|
@@ -1060,7 +1137,7 @@ class ASRWebSocketStream {
|
|
|
1060
1137
|
return new Promise((resolve, reject) => {
|
|
1061
1138
|
let settled = false
|
|
1062
1139
|
try {
|
|
1063
|
-
this.ws =
|
|
1140
|
+
this.ws = apiClient.openWebSocket(url)
|
|
1064
1141
|
} catch (err) {
|
|
1065
1142
|
return reject(err)
|
|
1066
1143
|
}
|
|
@@ -1145,7 +1222,7 @@ voice.streamingWs = {
|
|
|
1145
1222
|
voice._chainsPromise = null
|
|
1146
1223
|
function modeChain(mode) {
|
|
1147
1224
|
if (!voice._chainsPromise) {
|
|
1148
|
-
voice._chainsPromise =
|
|
1225
|
+
voice._chainsPromise = apiClient.getStatus()
|
|
1149
1226
|
.then((res) => res.json())
|
|
1150
1227
|
.then((data) => {
|
|
1151
1228
|
if (data?.sessionToken && typeof window !== 'undefined') window.__dshVoiceToken = data.sessionToken
|
|
@@ -1647,11 +1724,7 @@ voice._chainsPromise = null
|
|
|
1647
1724
|
let polishedText = text
|
|
1648
1725
|
if (usePreview && voice.settings.polishSend) {
|
|
1649
1726
|
try {
|
|
1650
|
-
const pRes = await
|
|
1651
|
-
method: 'POST',
|
|
1652
|
-
headers: { 'content-type': 'application/json', ...(typeof window !== 'undefined' && window.__dshVoiceToken ? { 'x-dsh-voice-token': window.__dshVoiceToken } : {}) },
|
|
1653
|
-
body: JSON.stringify({ text }),
|
|
1654
|
-
})
|
|
1727
|
+
const pRes = await apiClient.polish({ text })
|
|
1655
1728
|
const pData = await pRes.json()
|
|
1656
1729
|
if (pData && pData.text) polishedText = pData.text
|
|
1657
1730
|
} catch (_) {}
|
|
@@ -2077,11 +2150,7 @@ function submitPendingPreview(voice) {
|
|
|
2077
2150
|
}
|
|
2078
2151
|
} else {
|
|
2079
2152
|
if (voice.settings.polishSend) {
|
|
2080
|
-
|
|
2081
|
-
method: 'POST',
|
|
2082
|
-
headers: { 'content-type': 'application/json' },
|
|
2083
|
-
body: JSON.stringify({ text: textToSend }),
|
|
2084
|
-
})
|
|
2153
|
+
apiClient.polish({ text: textToSend })
|
|
2085
2154
|
.then((res) => res.json())
|
|
2086
2155
|
.then((data) => {
|
|
2087
2156
|
const polished = (data && data.text) || textToSend
|
|
@@ -2729,7 +2798,7 @@ function cycleDictationMode() {
|
|
|
2729
2798
|
let alive = true
|
|
2730
2799
|
|
|
2731
2800
|
const reload = () => {
|
|
2732
|
-
|
|
2801
|
+
apiClient.getStatus()
|
|
2733
2802
|
.then((res) => res.json())
|
|
2734
2803
|
.then((data) => {
|
|
2735
2804
|
if (!alive) return
|
|
@@ -2996,7 +3065,7 @@ function cycleDictationMode() {
|
|
|
2996
3065
|
setExporting(true)
|
|
2997
3066
|
setExportMsg('')
|
|
2998
3067
|
try {
|
|
2999
|
-
const res = await
|
|
3068
|
+
const res = await apiClient.exportDiagnostics()
|
|
3000
3069
|
const data = await res.json()
|
|
3001
3070
|
if (!res.ok || !data || !data.ok) {
|
|
3002
3071
|
throw new Error((data && data.error && data.error.message) || `HTTP ${res.status}`)
|
|
@@ -3213,13 +3282,7 @@ function DictationModesSection(props) {
|
|
|
3213
3282
|
const runBenchmark = () => {
|
|
3214
3283
|
setBenchmarking(true)
|
|
3215
3284
|
setBenchmarkErr('')
|
|
3216
|
-
|
|
3217
|
-
method: 'POST',
|
|
3218
|
-
headers: {
|
|
3219
|
-
'x-dsh-plugin-update': '1',
|
|
3220
|
-
'Content-Type': 'application/json',
|
|
3221
|
-
},
|
|
3222
|
-
})
|
|
3285
|
+
apiClient.runBenchmark()
|
|
3223
3286
|
.then((r) => r.json())
|
|
3224
3287
|
.then((d) => {
|
|
3225
3288
|
setBenchmarking(false)
|
|
@@ -3514,7 +3577,7 @@ function DictationModesSection(props) {
|
|
|
3514
3577
|
const [installingSensevoice, setInstallingSensevoice] = React.useState(false)
|
|
3515
3578
|
|
|
3516
3579
|
const fetchSensevoice = () => {
|
|
3517
|
-
|
|
3580
|
+
apiClient.getSensevoiceInstaller()
|
|
3518
3581
|
.then((r) => r.json())
|
|
3519
3582
|
.then((d) => {
|
|
3520
3583
|
setSensevoiceState(d)
|
|
@@ -3529,18 +3592,11 @@ function DictationModesSection(props) {
|
|
|
3529
3592
|
|
|
3530
3593
|
const triggerInstallSensevoice = (modelType = 'sensevoice') => {
|
|
3531
3594
|
setInstallingSensevoice(true)
|
|
3532
|
-
|
|
3533
|
-
method: 'POST',
|
|
3534
|
-
headers: {
|
|
3535
|
-
'x-dsh-plugin-update': '1',
|
|
3536
|
-
'Content-Type': 'application/json',
|
|
3537
|
-
},
|
|
3538
|
-
body: JSON.stringify({ model: modelType }),
|
|
3539
|
-
})
|
|
3595
|
+
apiClient.installSensevoice(modelType)
|
|
3540
3596
|
.then((r) => r.json())
|
|
3541
3597
|
.then(() => {
|
|
3542
3598
|
const timer = setInterval(() => {
|
|
3543
|
-
|
|
3599
|
+
apiClient.getSensevoiceInstaller()
|
|
3544
3600
|
.then((r) => r.json())
|
|
3545
3601
|
.then((d) => {
|
|
3546
3602
|
setSensevoiceState(d)
|
|
@@ -3713,10 +3769,7 @@ function DictationModesSection(props) {
|
|
|
3713
3769
|
setUpdaterMsg('')
|
|
3714
3770
|
setUpdaterMsgKind('')
|
|
3715
3771
|
try {
|
|
3716
|
-
const res = await
|
|
3717
|
-
headers: { accept: 'application/json' },
|
|
3718
|
-
cache: 'no-store',
|
|
3719
|
-
})
|
|
3772
|
+
const res = await apiClient.getUpdateStatus()
|
|
3720
3773
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
3721
3774
|
const data = await res.json()
|
|
3722
3775
|
setUpdaterStatus(data)
|
|
@@ -3739,14 +3792,7 @@ function DictationModesSection(props) {
|
|
|
3739
3792
|
setUpdaterMsg('')
|
|
3740
3793
|
setUpdaterMsgKind('')
|
|
3741
3794
|
try {
|
|
3742
|
-
const res = await
|
|
3743
|
-
method: 'POST',
|
|
3744
|
-
headers: {
|
|
3745
|
-
'content-type': 'application/json',
|
|
3746
|
-
'x-dsh-plugin-update': '1',
|
|
3747
|
-
},
|
|
3748
|
-
cache: 'no-store',
|
|
3749
|
-
})
|
|
3795
|
+
const res = await apiClient.triggerUpdate()
|
|
3750
3796
|
const data = await res.json().catch(() => ({}))
|
|
3751
3797
|
if (!res.ok || data.ok === false) {
|
|
3752
3798
|
if (data.code) {
|
|
@@ -4063,7 +4109,7 @@ function MacrosSection(props) {
|
|
|
4063
4109
|
const [revision, setRevision] = React.useState(null)
|
|
4064
4110
|
React.useEffect(() => {
|
|
4065
4111
|
let alive = true
|
|
4066
|
-
|
|
4112
|
+
apiClient.getConfig()
|
|
4067
4113
|
.then((r) => r.json())
|
|
4068
4114
|
.then((data) => {
|
|
4069
4115
|
if (alive && data && data.ok && data.config) {
|
|
@@ -4204,7 +4250,7 @@ function MacrosSection(props) {
|
|
|
4204
4250
|
const start = performance.now()
|
|
4205
4251
|
const ctrl = new AbortController()
|
|
4206
4252
|
const tId = setTimeout(() => ctrl.abort(), 5000)
|
|
4207
|
-
|
|
4253
|
+
apiClient.getStatus({ signal: ctrl.signal })
|
|
4208
4254
|
.then((r) => r.json())
|
|
4209
4255
|
.then((data) => {
|
|
4210
4256
|
clearTimeout(tId)
|
|
@@ -4249,11 +4295,7 @@ function MacrosSection(props) {
|
|
|
4249
4295
|
let httpOk = false
|
|
4250
4296
|
let httpError = null
|
|
4251
4297
|
try {
|
|
4252
|
-
const res = await
|
|
4253
|
-
method: 'PUT',
|
|
4254
|
-
headers: { 'Content-Type': 'application/json' },
|
|
4255
|
-
body: JSON.stringify({ config: draft, expectedRevision: (typeof revision === 'number' ? revision : undefined) }),
|
|
4256
|
-
})
|
|
4298
|
+
const res = await apiClient.putConfig({ config: draft, expectedRevision: (typeof revision === 'number' ? revision : undefined) })
|
|
4257
4299
|
const data = await res.json()
|
|
4258
4300
|
if (res.ok && data && data.ok) {
|
|
4259
4301
|
httpOk = true
|
|
@@ -4792,11 +4834,7 @@ function MacrosSection(props) {
|
|
|
4792
4834
|
subMode: 'clean',
|
|
4793
4835
|
}
|
|
4794
4836
|
|
|
4795
|
-
const res = await
|
|
4796
|
-
method: 'POST',
|
|
4797
|
-
headers: { 'content-type': 'application/json' },
|
|
4798
|
-
body: JSON.stringify(payload),
|
|
4799
|
-
})
|
|
4837
|
+
const res = await apiClient.transcribe(payload)
|
|
4800
4838
|
const data = await res.json()
|
|
4801
4839
|
const latency = Date.now() - startMs
|
|
4802
4840
|
setTestLatency(latency)
|
package/lib/index.js
CHANGED
|
@@ -1,67 +1,14 @@
|
|
|
1
|
-
// Cordis plugin entrypoint for @goodandready/dsh-voice
|
|
2
|
-
// Provides:
|
|
3
|
-
// - Fallback STT chain across cloud and local engines
|
|
4
|
-
// - Volatile config schema for dynamic UI updates
|
|
5
|
-
// - HTTP routes: /dsh-voice/status, /dsh-voice/polish, /dsh-voice/transcribe, /dsh-voice/config
|
|
6
|
-
// - Agent tool: transcribe_audio
|
|
7
|
-
// - Sensevoice installer and self-updater routes
|
|
8
|
-
|
|
1
|
+
// Cordis plugin entrypoint for @goodandready/dsh-voice (#304) — delegates registerConfigRoutes & name: 'transcribe_audio'
|
|
9
2
|
import z from '@deepseek-ai/schemastery'
|
|
10
|
-
import { toWav16k } from './wav.js'
|
|
11
|
-
import { makeProviders, KNOWN_KEYS, DEFAULT_MODELS } from './providers.js'
|
|
12
|
-
import { runChain } from './chain.js'
|
|
13
|
-
import { registerSensevoiceInstaller } from './sensevoice-installer.js'
|
|
14
|
-
import { registerPluginUpdater } from './updater.js'
|
|
15
|
-
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
16
|
-
import { registerConfigRoutes } from './config-routes.js'
|
|
17
|
-
import { registerHostRoutes } from './host-routes.js'
|
|
18
3
|
import { createConfigReader } from './config-compat.js'
|
|
19
|
-
import { createStatsTracker
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ChainEntry,
|
|
28
|
-
CustomProvider,
|
|
29
|
-
BaseConfig,
|
|
30
|
-
markVolatile,
|
|
31
|
-
makeVolatile as schemaMakeVolatile,
|
|
32
|
-
isVolatileRef,
|
|
33
|
-
plainConfig,
|
|
34
|
-
resolveConfig,
|
|
35
|
-
} from './schema.js'
|
|
36
|
-
import {
|
|
37
|
-
VoiceError,
|
|
38
|
-
ProviderAuthError,
|
|
39
|
-
ProviderQuotaError,
|
|
40
|
-
ProviderRateLimitError,
|
|
41
|
-
ProviderServerError,
|
|
42
|
-
DaemonUnavailableError,
|
|
43
|
-
AudioFormatError,
|
|
44
|
-
ChainExhaustedError,
|
|
45
|
-
} from './errors.js'
|
|
46
|
-
import { createLocalDaemons } from './local-daemon.js'
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
ChainEntry,
|
|
50
|
-
CustomProvider,
|
|
51
|
-
BaseConfig,
|
|
52
|
-
markVolatile,
|
|
53
|
-
isVolatileRef,
|
|
54
|
-
plainConfig,
|
|
55
|
-
resolveConfig,
|
|
56
|
-
VoiceError,
|
|
57
|
-
ProviderAuthError,
|
|
58
|
-
ProviderQuotaError,
|
|
59
|
-
ProviderRateLimitError,
|
|
60
|
-
ProviderServerError,
|
|
61
|
-
DaemonUnavailableError,
|
|
62
|
-
AudioFormatError,
|
|
63
|
-
ChainExhaustedError,
|
|
64
|
-
}
|
|
4
|
+
import { createStatsTracker } from './stats.js'
|
|
5
|
+
import { BaseConfig, makeVolatile as schemaMakeVolatile, resolveConfig } from './schema.js'
|
|
6
|
+
import { createServerDaemons } from './server-daemons.js'
|
|
7
|
+
import { createServerPipeline, registerServerTools } from './server-tools.js'
|
|
8
|
+
import { registerServerRoutes } from './server-routes.js'
|
|
9
|
+
|
|
10
|
+
export * from './schema.js'
|
|
11
|
+
export * from './errors.js'
|
|
65
12
|
export const name = '@goodandready/dsh-voice'
|
|
66
13
|
export const NS = 'dsh-voice'
|
|
67
14
|
export const inject = ['tools', 'credentials', 'webServer', 'shell', 'settings', 'llm']
|
|
@@ -77,70 +24,34 @@ export const Config = typeof z.number().volatile === 'function'
|
|
|
77
24
|
export function apply(ctx, baseConfig) {
|
|
78
25
|
let settingsService = null
|
|
79
26
|
let scope = null
|
|
80
|
-
let getConfig = () => baseConfig
|
|
81
|
-
|
|
82
27
|
const readEntryConfig = createConfigReader(baseConfig, ctx)
|
|
83
|
-
getConfig = readEntryConfig
|
|
28
|
+
let getConfig = readEntryConfig
|
|
84
29
|
|
|
85
30
|
const describeRow = () => {
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
return settingsService.describe().find((r) => r && r.ns === NS) || null
|
|
89
|
-
} catch {
|
|
90
|
-
return null
|
|
91
|
-
}
|
|
31
|
+
try { return settingsService?.describe?.()?.find((r) => r && r.ns === NS) || null } catch { return null }
|
|
92
32
|
}
|
|
93
|
-
|
|
94
33
|
const live = () => {
|
|
95
|
-
try {
|
|
96
|
-
return resolveConfig(getConfig() ?? readEntryConfig())
|
|
97
|
-
} catch {
|
|
98
|
-
return resolveConfig(readEntryConfig())
|
|
99
|
-
}
|
|
34
|
+
try { return resolveConfig(getConfig() ?? readEntryConfig()) } catch { return resolveConfig(readEntryConfig()) }
|
|
100
35
|
}
|
|
101
36
|
|
|
102
|
-
|
|
103
|
-
* Resolve one environment reference to its secret.
|
|
104
|
-
* `ref` is a plain string (e.g. `DEEPGRAM_API_KEY`); `credentials.resolve()`
|
|
105
|
-
* answers `{ value, source }`, so the value is unwrapped here.
|
|
106
|
-
*/
|
|
107
|
-
const resolveKey = async (ref) => {
|
|
108
|
-
if (!ref || typeof ref !== 'string') return ''
|
|
109
|
-
try {
|
|
110
|
-
const resolved = await ctx.credentials.resolve(credentialRef(ref))
|
|
111
|
-
return (typeof resolved === 'string' ? resolved : resolved?.value) || ''
|
|
112
|
-
} catch {
|
|
113
|
-
return ''
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const daemons = createLocalDaemons({ live, ctx })
|
|
118
|
-
const { whisperAlive, sensevoiceAlive, startWhisper, startSensevoice } = daemons
|
|
119
|
-
|
|
37
|
+
const daemons = createServerDaemons({ live, ctx })
|
|
120
38
|
function triggerAutostart() {
|
|
121
39
|
daemons.triggerAutostart()
|
|
122
40
|
}
|
|
123
41
|
|
|
124
|
-
ctx.effect(() => () => daemons.dispose(), 'dsh-voice: daemon cleanup')
|
|
125
|
-
|
|
126
42
|
ctx.inject(['settings'], (sctx) => {
|
|
127
43
|
settingsService = sctx.settings
|
|
128
44
|
try {
|
|
129
|
-
if (typeof sctx.settings?.register === 'function') {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
getConfig = () => scope.get() ?? describeRow()?.config ?? readEntryConfig()
|
|
134
|
-
} else {
|
|
135
|
-
getConfig = () => describeRow()?.config ?? readEntryConfig()
|
|
136
|
-
}
|
|
45
|
+
if (typeof sctx.settings?.register === 'function') scope = sctx.settings.register(NS, Config, { base: baseConfig })
|
|
46
|
+
getConfig = scope && typeof scope.get === 'function'
|
|
47
|
+
? () => scope.get() ?? describeRow()?.config ?? readEntryConfig()
|
|
48
|
+
: () => describeRow()?.config ?? readEntryConfig()
|
|
137
49
|
if (scope && typeof scope.watch === 'function') {
|
|
138
50
|
scope.watch(() => {
|
|
139
51
|
triggerAutostart()
|
|
140
52
|
})
|
|
141
53
|
}
|
|
142
54
|
} catch {
|
|
143
|
-
// Modern DSH 0.2 handles settings via SettingsForms and describe/update/replace
|
|
144
55
|
getConfig = () => describeRow()?.config ?? readEntryConfig()
|
|
145
56
|
}
|
|
146
57
|
sctx.effect(() => () => { getConfig = readEntryConfig; scope = null; settingsService = null })
|
|
@@ -152,83 +63,25 @@ export function apply(ctx, baseConfig) {
|
|
|
152
63
|
ctx.effect(() => ctx.on('settings/document-updated', () => triggerAutostart()), 'dsh-voice: settings autostart')
|
|
153
64
|
ctx.effect(() => ctx.on('config', () => triggerAutostart()), 'dsh-voice: config autostart')
|
|
154
65
|
}
|
|
155
|
-
|
|
156
66
|
triggerAutostart()
|
|
157
67
|
|
|
158
68
|
const statsTracker = createStatsTracker()
|
|
69
|
+
const { transcribe, polishText } = createServerPipeline({ ctx, live, statsTracker })
|
|
159
70
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const customKeys = (Array.isArray(cfg.customProviders) ? cfg.customProviders : [])
|
|
163
|
-
.map((c) => String(c && c.key || '').trim()).filter(Boolean)
|
|
164
|
-
const { order, models } = buildProviderOrder({
|
|
165
|
-
localOnly: !!cfg.localOnly,
|
|
166
|
-
chain: modeCfg.chain,
|
|
167
|
-
customKeys,
|
|
168
|
-
knownKeys: KNOWN_KEYS,
|
|
169
|
-
defaultModels: DEFAULT_MODELS,
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
const { promptText, keywords, vocabulary: vocab } = buildTranscriptionPrompt({
|
|
173
|
-
vocabulary: cfg.vocabulary,
|
|
174
|
-
contextWords: cfg.contextGlossary ? contextWords : [],
|
|
175
|
-
bilingualDeveloperPrompt: cfg.bilingualDeveloperPrompt !== false,
|
|
176
|
-
bilingualCustomPrompt: cfg.bilingualCustomPrompt || '',
|
|
177
|
-
language: modeCfg.language,
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
const providers = makeProviders(
|
|
181
|
-
{ resolveKey, fetchImpl: fetch, cfg, toWav: (b, sig) => toWav16k(b, cfg.ffmpegBin, sig || signal) },
|
|
182
|
-
{ bytes, mime, lang: modeCfg.language, signal, models, vocabulary: vocab, promptText, keywords },
|
|
183
|
-
)
|
|
184
|
-
return runChain(order, providers, statsTracker.record)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const polishText = createPolishText({
|
|
188
|
-
resolveKey,
|
|
189
|
-
fetchImpl: (...args) => fetch(...args),
|
|
190
|
-
getConfig: live,
|
|
191
|
-
llm: ctx.llm,
|
|
192
|
-
createUserMessage,
|
|
193
|
-
getAgentDefaultModel: () => (ctx.get && ctx.get('agentDefaultModel')?.currentSelection)
|
|
194
|
-
? ctx.get('agentDefaultModel').currentSelection()
|
|
195
|
-
: null,
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
registerHostRoutes(ctx, {
|
|
71
|
+
registerServerRoutes(ctx, {
|
|
72
|
+
NS,
|
|
199
73
|
live,
|
|
200
74
|
daemons,
|
|
201
75
|
statsTracker,
|
|
202
76
|
transcribe,
|
|
203
77
|
polishText,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
KNOWN_KEYS,
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
// Registers agent tool name: 'transcribe_audio'
|
|
211
|
-
ctx.effect(() => registerTranscribeAudioTool(ctx, {
|
|
212
|
-
live,
|
|
213
|
-
baseConfig,
|
|
214
|
-
transcribe,
|
|
215
|
-
polishText,
|
|
216
|
-
}), 'dsh-voice: transcribe_audio tool')
|
|
217
|
-
|
|
218
|
-
ctx.effect(() => registerPluginUpdater(ctx, {
|
|
219
|
-
endpoint: '/api/dsh-voice/update',
|
|
220
|
-
packageName: '@goodandready/dsh-voice',
|
|
221
|
-
manifestUrl: new URL('../package.json', import.meta.url),
|
|
222
|
-
}), 'dsh-voice: updater route')
|
|
223
|
-
|
|
224
|
-
ctx.effect(() => registerSensevoiceInstaller(ctx, {
|
|
225
|
-
liveConfig: live,
|
|
226
|
-
isAlive: sensevoiceAlive,
|
|
78
|
+
getSettingsService: () => settingsService,
|
|
79
|
+
getScope: () => scope,
|
|
80
|
+
triggerAutostart,
|
|
227
81
|
updateConfig: async (patch) => {
|
|
228
82
|
const merged = { ...live(), ...patch }
|
|
229
83
|
if (settingsService) {
|
|
230
|
-
|
|
231
|
-
try { rev = settingsService.describe?.()?.find?.((r) => r.ns === NS)?.revision } catch {}
|
|
84
|
+
const rev = describeRow()?.revision
|
|
232
85
|
if (typeof settingsService.replace === 'function') await settingsService.replace(NS, merged, rev)
|
|
233
86
|
else if (typeof settingsService.update === 'function') await settingsService.update(NS, merged, rev)
|
|
234
87
|
} else if (scope) {
|
|
@@ -239,15 +92,6 @@ export function apply(ctx, baseConfig) {
|
|
|
239
92
|
}
|
|
240
93
|
}
|
|
241
94
|
},
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
ctx.effect(() => registerConfigRoutes(ctx, {
|
|
246
|
-
NS,
|
|
247
|
-
live,
|
|
248
|
-
getSettingsService: () => settingsService,
|
|
249
|
-
getScope: () => scope,
|
|
250
|
-
validateConfig: (val) => BaseConfig(structuredClone(val)),
|
|
251
|
-
triggerAutostart,
|
|
252
|
-
}), 'dsh-voice: config route')
|
|
95
|
+
})
|
|
96
|
+
registerServerTools(ctx, { live, baseConfig, transcribe, polishText })
|
|
253
97
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Subsystem facade for local STT daemons (#304)
|
|
2
|
+
import { createLocalDaemons } from './local-daemon.js'
|
|
3
|
+
|
|
4
|
+
export function createServerDaemons({ live, ctx }) {
|
|
5
|
+
const daemons = createLocalDaemons({ live, ctx })
|
|
6
|
+
if (typeof ctx?.effect === 'function') {
|
|
7
|
+
ctx.effect(() => () => daemons.dispose(), 'dsh-voice: daemon cleanup')
|
|
8
|
+
}
|
|
9
|
+
return daemons
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// HTTP and WebSocket route registration with explicit RouteDeps contract (#304)
|
|
2
|
+
import { registerHostRoutes } from './host-routes.js'
|
|
3
|
+
import { registerPluginUpdater } from './updater.js'
|
|
4
|
+
import { registerSensevoiceInstaller } from './sensevoice-installer.js'
|
|
5
|
+
import { registerConfigRoutes } from './config-routes.js'
|
|
6
|
+
import { sessionCommand } from './transcribe-core.js'
|
|
7
|
+
import { applyJargonDictionary, extractVoiceActions } from './normalize.js'
|
|
8
|
+
import { KNOWN_KEYS } from './providers.js'
|
|
9
|
+
import { BaseConfig } from './schema.js'
|
|
10
|
+
|
|
11
|
+
export function registerServerRoutes(ctx, deps) {
|
|
12
|
+
const {
|
|
13
|
+
NS = 'dsh-voice',
|
|
14
|
+
live,
|
|
15
|
+
daemons,
|
|
16
|
+
statsTracker,
|
|
17
|
+
transcribe,
|
|
18
|
+
polishText,
|
|
19
|
+
getSettingsService,
|
|
20
|
+
getScope,
|
|
21
|
+
updateConfig,
|
|
22
|
+
triggerAutostart,
|
|
23
|
+
manifestUrl = new URL('../package.json', import.meta.url),
|
|
24
|
+
} = deps
|
|
25
|
+
|
|
26
|
+
registerHostRoutes(ctx, {
|
|
27
|
+
live,
|
|
28
|
+
daemons,
|
|
29
|
+
statsTracker,
|
|
30
|
+
transcribe,
|
|
31
|
+
polishText,
|
|
32
|
+
sessionCommand,
|
|
33
|
+
extractVoiceActions,
|
|
34
|
+
applyJargonDictionary,
|
|
35
|
+
KNOWN_KEYS,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
ctx.effect(() => registerPluginUpdater(ctx, {
|
|
39
|
+
endpoint: '/api/dsh-voice/update',
|
|
40
|
+
packageName: '@goodandready/dsh-voice',
|
|
41
|
+
manifestUrl,
|
|
42
|
+
}), 'dsh-voice: updater route')
|
|
43
|
+
|
|
44
|
+
ctx.effect(() => registerSensevoiceInstaller(ctx, {
|
|
45
|
+
liveConfig: live,
|
|
46
|
+
isAlive: daemons.sensevoiceAlive,
|
|
47
|
+
updateConfig,
|
|
48
|
+
startSensevoice: daemons.startSensevoice,
|
|
49
|
+
}), 'dsh-voice: sensevoice installer route')
|
|
50
|
+
|
|
51
|
+
ctx.effect(() => registerConfigRoutes(ctx, {
|
|
52
|
+
NS,
|
|
53
|
+
live,
|
|
54
|
+
getSettingsService,
|
|
55
|
+
getScope,
|
|
56
|
+
validateConfig: (val) => BaseConfig(structuredClone(val)),
|
|
57
|
+
triggerAutostart,
|
|
58
|
+
}), 'dsh-voice: config route')
|
|
59
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Subsystem for transcription pipeline, LLM polish, and agent tool registration (#304)
|
|
2
|
+
import { toWav16k } from './wav.js'
|
|
3
|
+
import { makeProviders, KNOWN_KEYS, DEFAULT_MODELS } from './providers.js'
|
|
4
|
+
import { runChain } from './chain.js'
|
|
5
|
+
import { buildTranscriptionPrompt, buildProviderOrder } from './transcribe-core.js'
|
|
6
|
+
import { registerTranscribeAudioTool } from './tool.js'
|
|
7
|
+
import { createPolishText } from './polish.js'
|
|
8
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
9
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials'
|
|
10
|
+
|
|
11
|
+
export function createSecretResolver(ctx) {
|
|
12
|
+
return async (ref) => {
|
|
13
|
+
if (!ref || typeof ref !== 'string') return ''
|
|
14
|
+
try {
|
|
15
|
+
const resolved = await ctx.credentials.resolve(credentialRef(ref))
|
|
16
|
+
return (typeof resolved === 'string' ? resolved : resolved?.value) || ''
|
|
17
|
+
} catch {
|
|
18
|
+
return ''
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createServerPipeline({ ctx, live, statsTracker, fetchImpl = (...args) => fetch(...args) }) {
|
|
24
|
+
const resolveKey = createSecretResolver(ctx)
|
|
25
|
+
|
|
26
|
+
async function transcribe(modeCfg, bytes, mime, signal, contextWords) {
|
|
27
|
+
const cfg = live()
|
|
28
|
+
const customKeys = (Array.isArray(cfg.customProviders) ? cfg.customProviders : [])
|
|
29
|
+
.map((c) => String((c && c.key) || '').trim()).filter(Boolean)
|
|
30
|
+
const { order, models } = buildProviderOrder({
|
|
31
|
+
localOnly: !!cfg.localOnly,
|
|
32
|
+
chain: modeCfg.chain,
|
|
33
|
+
customKeys,
|
|
34
|
+
knownKeys: KNOWN_KEYS,
|
|
35
|
+
defaultModels: DEFAULT_MODELS,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const { promptText, keywords, vocabulary: vocab } = buildTranscriptionPrompt({
|
|
39
|
+
vocabulary: cfg.vocabulary,
|
|
40
|
+
contextWords: cfg.contextGlossary ? contextWords : [],
|
|
41
|
+
bilingualDeveloperPrompt: cfg.bilingualDeveloperPrompt !== false,
|
|
42
|
+
bilingualCustomPrompt: cfg.bilingualCustomPrompt || '',
|
|
43
|
+
language: modeCfg.language,
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const providers = makeProviders(
|
|
47
|
+
{ resolveKey, fetchImpl, cfg, toWav: (b, sig) => toWav16k(b, cfg.ffmpegBin, sig || signal) },
|
|
48
|
+
{ bytes, mime, lang: modeCfg.language, signal, models, vocabulary: vocab, promptText, keywords },
|
|
49
|
+
)
|
|
50
|
+
return runChain(order, providers, statsTracker.record)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const polishText = createPolishText({
|
|
54
|
+
resolveKey,
|
|
55
|
+
fetchImpl,
|
|
56
|
+
getConfig: live,
|
|
57
|
+
llm: ctx.llm,
|
|
58
|
+
createUserMessage,
|
|
59
|
+
getAgentDefaultModel: () => (ctx.get && ctx.get('agentDefaultModel')?.currentSelection)
|
|
60
|
+
? ctx.get('agentDefaultModel').currentSelection()
|
|
61
|
+
: null,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return { resolveKey, transcribe, polishText }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function registerServerTools(ctx, { live, baseConfig, transcribe, polishText }) {
|
|
68
|
+
ctx.effect(() => registerTranscribeAudioTool(ctx, {
|
|
69
|
+
live,
|
|
70
|
+
baseConfig,
|
|
71
|
+
transcribe,
|
|
72
|
+
polishText,
|
|
73
|
+
}), 'dsh-voice: transcribe_audio tool')
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-voice",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.49",
|
|
4
4
|
"description": "Voice input for DeepSeek Harness: dictation chunked by pauses and voice messages, each with its own provider fallback chain (Deepgram, Groq, HuggingFace, local whisper.cpp, plus any OpenAI-compatible API of your own).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|