better-dsh-pet 0.3.1 → 0.3.2
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 +1 -1
- package/package.json +1 -1
- package/scripts/download-sensevoice.mjs +32 -14
- package/scripts/ensure-electron.mjs +10 -12
package/README.md
CHANGED
|
@@ -276,7 +276,7 @@ dsh plugin --profile web add better-dsh-pet
|
|
|
276
276
|
> 如果刚发布新版本不到 24 小时,pnpm 11 的 `minimumReleaseAge` 安全策略可能不会自动选最新版,而是退回旧版。此时请指定精确版本安装:
|
|
277
277
|
>
|
|
278
278
|
> ```bash
|
|
279
|
-
> dsh plugin --profile web add better-dsh-pet@0.3.
|
|
279
|
+
> dsh plugin --profile web add better-dsh-pet@0.3.2
|
|
280
280
|
> ```
|
|
281
281
|
>
|
|
282
282
|
> pnpm 会自动把该版本加入 `minimumReleaseAgeExclude` 并完成安装;也可以等待 24 小时后直接用上面的普通命令。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-dsh-pet",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "A desktop-native pet bubble driven by DeepSeek Harness session events: transparent always-on-top Electron window, status-aware animations, voice chat/wake, real DSH task execution, emotion, festival, balance, pomodoro, roast, and DSH settings card.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -11,12 +11,21 @@ import { appendFileSync, createWriteStream, existsSync, mkdirSync, readdirSync,
|
|
|
11
11
|
import { join, resolve } from 'node:path'
|
|
12
12
|
import { homedir } from 'node:os'
|
|
13
13
|
import { spawnSync } from 'node:child_process'
|
|
14
|
+
import { Transform } from 'node:stream'
|
|
15
|
+
import { pipeline } from 'node:stream/promises'
|
|
14
16
|
import { fileURLToPath } from 'node:url'
|
|
15
17
|
|
|
16
18
|
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
|
17
19
|
const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
18
20
|
const MODEL_DIR = process.env.DSH_VOICE_MODEL_DIR || join(DSH_HOME, 'voice', 'sensevoice')
|
|
19
|
-
const
|
|
21
|
+
const DEFAULT_MODEL_URL = 'https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-int8-2024-07-17.tar.bz2'
|
|
22
|
+
const MODEL_URLS = [
|
|
23
|
+
process.env.DSH_VOICE_MODEL_URL,
|
|
24
|
+
DEFAULT_MODEL_URL,
|
|
25
|
+
`https://ghproxy.net/${DEFAULT_MODEL_URL}`,
|
|
26
|
+
`https://ghfast.top/${DEFAULT_MODEL_URL}`,
|
|
27
|
+
`https://gh-proxy.com/${DEFAULT_MODEL_URL}`,
|
|
28
|
+
].filter((url, index, arr) => typeof url === 'string' && url.trim() !== '' && arr.indexOf(url) === index)
|
|
20
29
|
const REQUIRED = ['model.int8.onnx', 'tokens.txt']
|
|
21
30
|
const LOG_FILE = join(DSH_HOME, 'logs', 'better-dsh-pet-sensevoice.log')
|
|
22
31
|
|
|
@@ -47,17 +56,12 @@ async function download(url, dest, label = 'download') {
|
|
|
47
56
|
const response = await fetch(url, { redirect: 'follow' })
|
|
48
57
|
if (!response.ok) throw new Error(`HTTP ${response.status} ${response.statusText}`)
|
|
49
58
|
const total = Number(response.headers.get('content-length')) || 0
|
|
50
|
-
const file = createWriteStream(dest)
|
|
51
|
-
const reader = response.body.getReader()
|
|
52
59
|
let received = 0
|
|
53
60
|
let lastLoggedAt = 0
|
|
54
61
|
let lastPercent = -1
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (done) break
|
|
59
|
-
received += value.length
|
|
60
|
-
file.write(value)
|
|
62
|
+
const progress = new Transform({
|
|
63
|
+
transform(chunk, _encoding, callback) {
|
|
64
|
+
received += chunk.length
|
|
61
65
|
const percent = total ? Math.floor((received / total) * 100) : 0
|
|
62
66
|
const shouldLog = total
|
|
63
67
|
? (percent !== lastPercent && (percent % 10 === 0 || percent === 100))
|
|
@@ -69,10 +73,10 @@ async function download(url, dest, label = 'download') {
|
|
|
69
73
|
const totalMb = total ? ` / ${(total / 1024 / 1024).toFixed(1)}MB` : ''
|
|
70
74
|
log(`[${label}] ${total ? `${percent}%` : mb} (${mb}MB${totalMb})`)
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
callback(null, chunk)
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
await pipeline(response.body, progress, createWriteStream(dest))
|
|
76
80
|
log(`[${label}] 下载完成:${(received / 1024 / 1024).toFixed(1)}MB`)
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -102,9 +106,23 @@ async function main() {
|
|
|
102
106
|
mkdirSync(MODEL_DIR, { recursive: true })
|
|
103
107
|
const archive = join(MODEL_DIR, 'sensevoice.tar.bz2')
|
|
104
108
|
const extractDir = join(MODEL_DIR, '.extract')
|
|
109
|
+
try { rmSync(archive, { force: true }) } catch { /* 清理残留压缩包 */ }
|
|
105
110
|
log(`[download-sensevoice] downloading model (约 230MB) ...`)
|
|
106
111
|
try {
|
|
107
|
-
|
|
112
|
+
let lastError
|
|
113
|
+
for (const url of MODEL_URLS) {
|
|
114
|
+
log(`[download-sensevoice] trying: ${url}`)
|
|
115
|
+
try {
|
|
116
|
+
await download(url, archive, 'SenseVoice')
|
|
117
|
+
lastError = undefined
|
|
118
|
+
break
|
|
119
|
+
} catch (error) {
|
|
120
|
+
lastError = error
|
|
121
|
+
log(`[download-sensevoice] mirror failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
122
|
+
try { rmSync(archive, { force: true }) } catch { /* ignore */ }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (lastError) throw lastError
|
|
108
126
|
ok('downloaded archive')
|
|
109
127
|
rmSync(extractDir, { recursive: true, force: true })
|
|
110
128
|
extract(archive, extractDir)
|
|
@@ -18,6 +18,8 @@ import { appendFileSync, createWriteStream, existsSync, mkdirSync, rmSync } from
|
|
|
18
18
|
import { tmpdir } from 'node:os'
|
|
19
19
|
import { join, resolve } from 'node:path'
|
|
20
20
|
import { spawnSync } from 'node:child_process'
|
|
21
|
+
import { Transform } from 'node:stream'
|
|
22
|
+
import { pipeline } from 'node:stream/promises'
|
|
21
23
|
|
|
22
24
|
const HOME = process.env.DSH_HOME || join(process.env.USERPROFILE || process.env.HOME || '', '.dsh')
|
|
23
25
|
const VERSION = process.env.DSH_PET_ELECTRON_VERSION || '43.3.0'
|
|
@@ -50,17 +52,12 @@ async function download(url, dest, label = 'download') {
|
|
|
50
52
|
throw new Error(`download failed: ${response.status} ${response.statusText} (${url})`)
|
|
51
53
|
}
|
|
52
54
|
const total = Number(response.headers.get('content-length')) || 0
|
|
53
|
-
const file = createWriteStream(dest)
|
|
54
|
-
const reader = response.body.getReader()
|
|
55
55
|
let received = 0
|
|
56
56
|
let lastLoggedAt = 0
|
|
57
57
|
let lastPercent = -1
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (done) break
|
|
62
|
-
received += value.length
|
|
63
|
-
file.write(value)
|
|
58
|
+
const progress = new Transform({
|
|
59
|
+
transform(chunk, _encoding, callback) {
|
|
60
|
+
received += chunk.length
|
|
64
61
|
const percent = total ? Math.floor((received / total) * 100) : 0
|
|
65
62
|
const shouldLog = total
|
|
66
63
|
? (percent !== lastPercent && (percent % 10 === 0 || percent === 100))
|
|
@@ -72,10 +69,10 @@ async function download(url, dest, label = 'download') {
|
|
|
72
69
|
const totalMb = total ? ` / ${(total / 1024 / 1024).toFixed(1)}MB` : ''
|
|
73
70
|
log(`[${label}] ${total ? `${percent}%` : mb} (${mb}MB${totalMb})`)
|
|
74
71
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
callback(null, chunk)
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
await pipeline(response.body, progress, createWriteStream(dest))
|
|
79
76
|
log(`[${label}] 下载完成:${(received / 1024 / 1024).toFixed(1)}MB`)
|
|
80
77
|
}
|
|
81
78
|
|
|
@@ -113,6 +110,7 @@ async function main() {
|
|
|
113
110
|
const zipName = `electron-v${VERSION}-win32-x64.zip`
|
|
114
111
|
const url = `${MIRROR.replace(/\/$/, '')}/${VERSION}/${zipName}`
|
|
115
112
|
const zipPath = join(tmpdir(), zipName)
|
|
113
|
+
try { rmSync(zipPath, { force: true }) } catch { /* 清理残留 zip */ }
|
|
116
114
|
|
|
117
115
|
try {
|
|
118
116
|
log(`[ensure-electron] ${url}`)
|