@goodandready/dsh-voice 0.9.48 → 0.9.50
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 +4932 -5117
- 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/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.50",
|
|
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",
|