@goodandready/dsh-voice 0.9.0 → 0.9.1
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 +2 -1
- package/README.ru.md +1 -1
- package/README.zh.md +6 -0
- package/lib/audio-guard.js +133 -0
- package/lib/client.js +4 -2
- package/lib/http-util.js +3 -2
- package/lib/index.js +8 -3
- package/lib/sensevoice-installer.js +18 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -211,7 +211,7 @@ Open **Settings → Plugins → Plugin settings → Voice** in the Web UI:
|
|
|
211
211
|
## 🤖 Agent Tool & HTTP API
|
|
212
212
|
|
|
213
213
|
### Agent Tool (`transcribe_audio`)
|
|
214
|
-
Registers `transcribe_audio(file_path, language?)` in `ctx.tools`, allowing agents to analyze audio files, interview recordings, and voice notes directly from disk.
|
|
214
|
+
Registers `transcribe_audio(file_path, language?)` in `ctx.tools`, allowing agents to analyze audio files, interview recordings, and voice notes directly from disk. Path containment is strictly enforced against allowed directories (`allowedAudioDirs`, `~/.dsh`, `tmpdir`, `cwd`) with symlink traversal escape prevention and magic-byte audio format validation.
|
|
215
215
|
|
|
216
216
|
### Internal HTTP Endpoints
|
|
217
217
|
* `POST /dsh-voice/transcribe` — `{ dataBase64, mimeType, mode }` → `{ ok, text, provider, tookMs }`
|
|
@@ -219,6 +219,7 @@ Registers `transcribe_audio(file_path, language?)` in `ctx.tools`, allowing agen
|
|
|
219
219
|
* `GET /dsh-voice/status` — Returns daemon status, active chains, SenseVoice.
|
|
220
220
|
* `GET /dsh-voice/config` — Returns live plugin configuration snapshot.
|
|
221
221
|
* `PUT /dsh-voice/config` — Updates and persists plugin configuration across network.
|
|
222
|
+
* `GET/POST /dsh-voice/sensevoice-installer` — SenseVoice 1-click model installation status and trigger (protected by `isTrustedCaller`, model paths redacted).
|
|
222
223
|
|
|
223
224
|
---
|
|
224
225
|
|
package/README.ru.md
CHANGED
|
@@ -211,7 +211,7 @@ dsh plugin --profile web add @goodandready/dsh-voice
|
|
|
211
211
|
## 🤖 Инструмент агента и HTTP API
|
|
212
212
|
|
|
213
213
|
### Инструмент агента (`transcribe_audio`)
|
|
214
|
-
Регистрирует `transcribe_audio(file_path, language?)` в `ctx.tools`, позволяя агентам распознавать аудиофайлы, интервью и записи с диска.
|
|
214
|
+
Регистрирует `transcribe_audio(file_path, language?)` в `ctx.tools` (с проверкой границ разрешённых каталогов `allowedAudioDirs` / `~/.dsh` / `tmpdir` / `cwd`, защитой от симлинков и валидацией сигнатур аудиофайлов), позволяя агентам распознавать аудиофайлы, интервью и записи с диска.
|
|
215
215
|
|
|
216
216
|
### Внутренние HTTP эндпоинты
|
|
217
217
|
* `POST /dsh-voice/transcribe` — `{ dataBase64, mimeType, mode }` → `{ ok, text, provider, tookMs }`
|
package/README.zh.md
CHANGED
|
@@ -131,11 +131,17 @@ v0.8.18 质量审查后的修复批次(Gitea #79–#87,PR #88):
|
|
|
131
131
|
|
|
132
132
|
## 🤖 智能体工具与 HTTP 端点
|
|
133
133
|
|
|
134
|
+
### 智能体工具 (`transcribe_audio`)
|
|
135
|
+
在 `ctx.tools` 中注册 `transcribe_audio(file_path, language?)`,允许智能体直接读取和转写本地音频文件。包含严格的目录边界检查(`allowedAudioDirs`、`~/.dsh`、`tmpdir`、`cwd`)、符号链接越界防护以及音频特征码(magic bytes)校验。
|
|
136
|
+
|
|
137
|
+
### 内部 HTTP 端点
|
|
138
|
+
|
|
134
139
|
* `POST /dsh-voice/transcribe` — 音频转写:`{ dataBase64, mimeType, mode }` → `{ ok, text, provider, tookMs }`
|
|
135
140
|
* `POST /dsh-voice/polish` — 文本模型润色:`{ text }` → `{ ok, text }`
|
|
136
141
|
* `GET /dsh-voice/status` — 查询后端状态、服务商健康度与 SenseVoice
|
|
137
142
|
* `GET /dsh-voice/config` — 获取插件运行时配置快照
|
|
138
143
|
* `PUT /dsh-voice/config` — 跨网络安全持久化更新插件配置
|
|
144
|
+
* `GET/POST /dsh-voice/sensevoice-installer` — SenseVoice 一键模型安装状态与触发接口(受 `isTrustedCaller` 保护,绝对路径脱敏)
|
|
139
145
|
|
|
140
146
|
---
|
|
141
147
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import { realpath } from 'node:fs/promises'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check whether a target path is strictly located within any of the allowed root directories.
|
|
7
|
+
* Boundary-aware prefix match: /tmp does not allow /tmp-other.
|
|
8
|
+
* @param {string} targetPath
|
|
9
|
+
* @param {string[]} allowedRoots
|
|
10
|
+
* @returns {boolean}
|
|
11
|
+
*/
|
|
12
|
+
export function isPathUnderRoots(targetPath, allowedRoots) {
|
|
13
|
+
if (!targetPath || !Array.isArray(allowedRoots) || allowedRoots.length === 0) return false
|
|
14
|
+
const normalized = path.resolve(targetPath)
|
|
15
|
+
|
|
16
|
+
return allowedRoots.some((root) => {
|
|
17
|
+
if (!root) return false
|
|
18
|
+
const normRoot = path.resolve(root)
|
|
19
|
+
if (normalized === normRoot) return true
|
|
20
|
+
const prefix = normRoot.endsWith(path.sep) ? normRoot : normRoot + path.sep
|
|
21
|
+
return normalized.startsWith(prefix)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Return allowed root directories for the transcribe_audio tool.
|
|
27
|
+
* Combines configured audio directories with standard safe locations (.dsh, tmpdir, cwd).
|
|
28
|
+
* @param {object} [cfg]
|
|
29
|
+
* @returns {string[]}
|
|
30
|
+
*/
|
|
31
|
+
export function getAllowedAudioRoots(cfg) {
|
|
32
|
+
const custom = Array.isArray(cfg?.allowedAudioDirs) ? cfg.allowedAudioDirs : []
|
|
33
|
+
const defaults = [
|
|
34
|
+
os.tmpdir(),
|
|
35
|
+
path.join(os.homedir(), '.dsh'),
|
|
36
|
+
process.cwd(),
|
|
37
|
+
]
|
|
38
|
+
return [...custom, ...defaults].map((d) => path.resolve(String(d)))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Validate audio path before access:
|
|
43
|
+
* 1. Checks lexical path boundary before calling stat or read.
|
|
44
|
+
* 2. Checks realpath to prevent symlink traversal escapes.
|
|
45
|
+
* @param {string} filePath
|
|
46
|
+
* @param {string[]} allowedRoots
|
|
47
|
+
* @returns {Promise<{ resolved: string, real: string }>}
|
|
48
|
+
*/
|
|
49
|
+
export async function validateAudioPath(filePath, allowedRoots) {
|
|
50
|
+
const raw = String(filePath || '').trim()
|
|
51
|
+
if (!raw) {
|
|
52
|
+
throw new Error('transcribe_audio: file_path is required')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const resolved = path.resolve(raw)
|
|
56
|
+
if (!isPathUnderRoots(resolved, allowedRoots)) {
|
|
57
|
+
throw new Error(`transcribe_audio: path is outside allowed audio directories: ${raw}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let real = ''
|
|
61
|
+
try {
|
|
62
|
+
real = await realpath(resolved)
|
|
63
|
+
} catch (err) {
|
|
64
|
+
throw new Error(`transcribe_audio: file not found: ${raw}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!isPathUnderRoots(real, allowedRoots)) {
|
|
68
|
+
throw new Error(`transcribe_audio: resolved symlink is outside allowed audio directories: ${raw}`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { resolved, real }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Sniff audio format from magic bytes.
|
|
76
|
+
* Supports WAV, MP3, OGG, FLAC, WebM, and M4A/MP4.
|
|
77
|
+
* @param {Buffer|Uint8Array} buffer
|
|
78
|
+
* @returns {string|null} Detected MIME type or null
|
|
79
|
+
*/
|
|
80
|
+
export function sniffAudioFormat(buffer) {
|
|
81
|
+
if (!buffer || buffer.length < 4) return null
|
|
82
|
+
|
|
83
|
+
// WAV: 'RIFF' .... 'WAVE'
|
|
84
|
+
if (buffer.length >= 12) {
|
|
85
|
+
const riff = String.fromCharCode(buffer[0], buffer[1], buffer[2], buffer[3])
|
|
86
|
+
const wave = String.fromCharCode(buffer[8], buffer[9], buffer[10], buffer[11])
|
|
87
|
+
if (riff === 'RIFF' && wave === 'WAVE') return 'audio/wav'
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// OGG: 'OggS'
|
|
91
|
+
if (String.fromCharCode(buffer[0], buffer[1], buffer[2], buffer[3]) === 'OggS') {
|
|
92
|
+
return 'audio/ogg'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// FLAC: 'fLaC'
|
|
96
|
+
if (String.fromCharCode(buffer[0], buffer[1], buffer[2], buffer[3]) === 'fLaC') {
|
|
97
|
+
return 'audio/flac'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// WebM / Matroska: 0x1A 0x45 0xDF 0xA3 (EBML)
|
|
101
|
+
if (buffer[0] === 0x1a && buffer[1] === 0x45 && buffer[2] === 0xdf && buffer[3] === 0xa3) {
|
|
102
|
+
return 'audio/webm'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// MP3: ID3 header or frame sync 0xFF 0xFB/F3/F2
|
|
106
|
+
if (buffer.length >= 3 && String.fromCharCode(buffer[0], buffer[1], buffer[2]) === 'ID3') {
|
|
107
|
+
return 'audio/mpeg'
|
|
108
|
+
}
|
|
109
|
+
if (buffer[0] === 0xff && (buffer[1] & 0xe0) === 0xe0) {
|
|
110
|
+
return 'audio/mpeg'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// M4A / MP4: '....ftyp'
|
|
114
|
+
if (buffer.length >= 8) {
|
|
115
|
+
const ftyp = String.fromCharCode(buffer[4], buffer[5], buffer[6], buffer[7])
|
|
116
|
+
if (ftyp === 'ftyp') return 'audio/mp4'
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Enforce audio MIME/content validation independently of file extension.
|
|
124
|
+
* @param {Buffer|Uint8Array} buffer
|
|
125
|
+
* @returns {string} Detected audio MIME type
|
|
126
|
+
*/
|
|
127
|
+
export function validateAudioContent(buffer) {
|
|
128
|
+
const mime = sniffAudioFormat(buffer)
|
|
129
|
+
if (!mime) {
|
|
130
|
+
throw new Error('transcribe_audio: unsupported or invalid audio file format (magic bytes check failed)')
|
|
131
|
+
}
|
|
132
|
+
return mime
|
|
133
|
+
}
|
package/lib/client.js
CHANGED
|
@@ -225,6 +225,7 @@ window.__ModuleLoader__.load({
|
|
|
225
225
|
'jargonAdd': 'Add replacement',
|
|
226
226
|
'jargonFrom': 'Spoken slang',
|
|
227
227
|
'jargonTo': 'Correct spelling',
|
|
228
|
+
'jargonPlaceholder': 'k8s -> kubernetes\npr -> pull request',
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
const zh = {
|
|
@@ -418,6 +419,7 @@ window.__ModuleLoader__.load({
|
|
|
418
419
|
'jargonAdd': '添加替换项',
|
|
419
420
|
'jargonFrom': '口语词汇',
|
|
420
421
|
'jargonTo': '标准拼写',
|
|
422
|
+
'jargonPlaceholder': 'k8s -> kubernetes\npr -> pull request',
|
|
421
423
|
}
|
|
422
424
|
|
|
423
425
|
// Strings are also needed outside components — in recording handlers and
|
|
@@ -3025,7 +3027,7 @@ window.__ModuleLoader__.load({
|
|
|
3025
3027
|
React.createElement('textarea', {
|
|
3026
3028
|
rows: 3,
|
|
3027
3029
|
disabled: !writable,
|
|
3028
|
-
placeholder: '
|
|
3030
|
+
placeholder: t('jargonPlaceholder'),
|
|
3029
3031
|
value: Array.isArray(draft && draft.jargonDictionary)
|
|
3030
3032
|
? draft.jargonDictionary.map((item) => item && item.from ? `${item.from} -> ${item.to}` : '').filter(Boolean).join('\n')
|
|
3031
3033
|
: '',
|
|
@@ -3108,7 +3110,7 @@ window.__ModuleLoader__.load({
|
|
|
3108
3110
|
React.createElement('div', { className: 'cb-section-desc' }, t('versionHint')),
|
|
3109
3111
|
React.createElement('div', { className: 'cb-row', style: { alignItems: 'center', gap: '12px' } },
|
|
3110
3112
|
React.createElement('span', { className: 'cb-badge cb-badge-ok' },
|
|
3111
|
-
'v' + ((updaterStatus && updaterStatus.currentVersion) || '0.9.
|
|
3113
|
+
'v' + ((updaterStatus && updaterStatus.currentVersion) || '0.9.1')
|
|
3112
3114
|
),
|
|
3113
3115
|
updaterStatus && updaterStatus.updateAvailable
|
|
3114
3116
|
? React.createElement('span', { className: 'cb-badge cb-badge-warn' },
|
package/lib/http-util.js
CHANGED
|
@@ -50,8 +50,7 @@ export function isTrustedCaller(req) {
|
|
|
50
50
|
if (isLoopback(remote)) return true
|
|
51
51
|
|
|
52
52
|
const secSite = String(req.headers?.['sec-fetch-site'] || '').toLowerCase()
|
|
53
|
-
if (secSite === '
|
|
54
|
-
if (secSite === 'cross-site') return false
|
|
53
|
+
if (secSite === 'cross-site' || secSite === 'same-site') return false
|
|
55
54
|
|
|
56
55
|
const host = String(req.headers?.host || '').toLowerCase()
|
|
57
56
|
const origin = String(req.headers?.origin || '').trim().toLowerCase()
|
|
@@ -63,6 +62,8 @@ export function isTrustedCaller(req) {
|
|
|
63
62
|
return false
|
|
64
63
|
}
|
|
65
64
|
|
|
65
|
+
if (secSite === 'same-origin') return true
|
|
66
|
+
|
|
66
67
|
const referer = String(req.headers?.referer || '').trim().toLowerCase()
|
|
67
68
|
if (referer) {
|
|
68
69
|
try {
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import { registerPluginUpdater } from './updater.js'
|
|
|
30
30
|
import { registerSensevoiceInstaller } from './sensevoice-installer.js'
|
|
31
31
|
import { createConfigReader } from './config-compat.js'
|
|
32
32
|
import { registerConfigRoutes } from './config-routes.js'
|
|
33
|
+
import { getAllowedAudioRoots, validateAudioPath, validateAudioContent } from './audio-guard.js'
|
|
33
34
|
|
|
34
35
|
function isAutoLang(lang) {
|
|
35
36
|
return !lang || lang === 'auto' || String(lang).includes(',')
|
|
@@ -136,6 +137,7 @@ const BaseConfig = z.object({
|
|
|
136
137
|
ffmpegBin: z.string().default('ffmpeg')
|
|
137
138
|
.description('ffmpeg used to convert browser webm/opus into the WAV that whisper.cpp requires.'),
|
|
138
139
|
timeoutMs: z.number().default(120000),
|
|
140
|
+
allowedAudioDirs: z.array(z.string()).default([]),
|
|
139
141
|
maxFileBytes: z.number().default(25 * 1024 * 1024),
|
|
140
142
|
normalizeTranscript: z.boolean().default(false)
|
|
141
143
|
.description('transcribe_audio: convert spoken numbers to digits and tidy punctuation.'),
|
|
@@ -624,14 +626,17 @@ export function apply(ctx, baseConfig) {
|
|
|
624
626
|
const cfg = live()
|
|
625
627
|
const filePath = String(args.file_path || '').trim()
|
|
626
628
|
if (!filePath) throw new Error('transcribe_audio: file_path is required')
|
|
627
|
-
const
|
|
629
|
+
const allowedRoots = getAllowedAudioRoots(cfg)
|
|
630
|
+
const { real } = await validateAudioPath(filePath, allowedRoots)
|
|
631
|
+
const info = await stat(real).catch(() => null)
|
|
628
632
|
if (!info) throw new Error(`transcribe_audio: file not found: ${filePath}`)
|
|
629
633
|
if (info.size > cfg.maxFileBytes) {
|
|
630
634
|
throw new Error(`transcribe_audio: file too large (${info.size} bytes, max ${cfg.maxFileBytes})`)
|
|
631
635
|
}
|
|
632
636
|
if (info.size < 44) throw new Error('transcribe_audio: file is empty or too small')
|
|
633
|
-
const
|
|
634
|
-
const
|
|
637
|
+
const bytes = await readFile(real)
|
|
638
|
+
const sniffedMime = validateAudioContent(bytes)
|
|
639
|
+
const mime = sniffedMime || MIME_BY_EXT[path.extname(real).toLowerCase()] || 'audio/wav'
|
|
635
640
|
const modeCfg = { ...cfg.message, language: String(args.language || cfg.message.language) }
|
|
636
641
|
let raw = await transcribe(modeCfg, bytes, mime, exec.signal)
|
|
637
642
|
if (raw && raw.text) raw = { ...raw, text: await polishText(raw.text, modeCfg, exec.signal) }
|
|
@@ -41,6 +41,13 @@ export function findModelFile(dir) {
|
|
|
41
41
|
return null
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
export function redactModelPath(filePath) {
|
|
45
|
+
if (!filePath) return ""
|
|
46
|
+
const str = String(filePath).replace(/\\/g, "/")
|
|
47
|
+
const idx = str.indexOf(".dsh/models/")
|
|
48
|
+
if (idx !== -1) return "~/" + str.slice(idx)
|
|
49
|
+
return path.basename(str)
|
|
50
|
+
}
|
|
44
51
|
export function findTokensFile(dir) {
|
|
45
52
|
if (!dir || !existsSync(dir)) return null
|
|
46
53
|
try {
|
|
@@ -68,8 +75,9 @@ export async function getSensevoiceStatus(cfg, isAliveFn) {
|
|
|
68
75
|
return {
|
|
69
76
|
installed,
|
|
70
77
|
running,
|
|
71
|
-
modelPath: modelFile
|
|
72
|
-
tokensPath: tokensFile
|
|
78
|
+
modelPath: redactModelPath(modelFile),
|
|
79
|
+
tokensPath: redactModelPath(tokensFile),
|
|
80
|
+
path: installed ? '~/.dsh/models/sensevoice' : '',
|
|
73
81
|
installing: installerState.installing,
|
|
74
82
|
progress: installerState.progress,
|
|
75
83
|
step: installerState.step,
|
|
@@ -189,6 +197,11 @@ export function registerSensevoiceInstaller(ctx, { liveConfig, isAlive, updateCo
|
|
|
189
197
|
kind: 'exact',
|
|
190
198
|
path: '/dsh-voice/sensevoice-installer',
|
|
191
199
|
handler: async (req, res) => {
|
|
200
|
+
if (!isTrustedCaller(req)) {
|
|
201
|
+
writeJson(res, 403, { ok: false, error: 'Forbidden: untrusted caller' })
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
192
205
|
if (req.method === 'GET') {
|
|
193
206
|
const status = await getSensevoiceStatus(liveConfig(), isAlive)
|
|
194
207
|
writeJson(res, 200, status)
|
|
@@ -196,13 +209,9 @@ export function registerSensevoiceInstaller(ctx, { liveConfig, isAlive, updateCo
|
|
|
196
209
|
}
|
|
197
210
|
|
|
198
211
|
if (req.method === 'POST') {
|
|
199
|
-
|
|
200
|
-
writeJson(res, 403, { ok: false, error: 'Forbidden: untrusted caller' })
|
|
201
|
-
return
|
|
202
|
-
}
|
|
203
|
-
|
|
212
|
+
const safeState = { ...installerState, modelPath: redactModelPath(installerState.modelPath) }
|
|
204
213
|
if (installerState.installing) {
|
|
205
|
-
writeJson(res, 409, { ok: false, error: 'Installation already in progress', state:
|
|
214
|
+
writeJson(res, 409, { ok: false, error: 'Installation already in progress', state: safeState })
|
|
206
215
|
return
|
|
207
216
|
}
|
|
208
217
|
|
|
@@ -211,7 +220,7 @@ export function registerSensevoiceInstaller(ctx, { liveConfig, isAlive, updateCo
|
|
|
211
220
|
ctx.logger?.warn?.(`SenseVoice 1-click install error: ${String(err)}`)
|
|
212
221
|
})
|
|
213
222
|
|
|
214
|
-
writeJson(res, 202, { ok: true, message: 'SenseVoice installation started', state:
|
|
223
|
+
writeJson(res, 202, { ok: true, message: 'SenseVoice installation started', state: safeState })
|
|
215
224
|
return
|
|
216
225
|
}
|
|
217
226
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-voice",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
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",
|