环境
- 系统:macOS(Darwin)
- DSH 桌面版(虹灵),Node v24
- 插件:
dsh-usage-stats@1.0.0
根因
lib/index.js 的 fetchBalance() 通过 subprocess.spawn 调用 curl.exe 与 powershell.exe 查询 https://api.deepseek.com/user/balance。这两个可执行文件是 Windows 专属(macOS 只有不带 .exe 的 curl,也没有 powershell.exe),因此在非 Windows 平台 spawn 直接失败,两次尝试都落到「无法启动查询进程」。
修复
改用 Node 原生 fetch(Node 18+ 全局可用,跨平台),去掉对 subprocess / curl.exe / powershell.exe 的依赖,并保留原有错误语义(401 / 超时 / 空响应 / is_available=false)。
const url = 'https://api.deepseek.com/user/balance'
let lastDiag = ''
try {
const response = await fetch(url, {
method: 'GET',
headers: { accept: 'application/json', authorization: 'Bearer ' + key },
signal: AbortSignal.timeout(30000),
})
const body = (await response.text()).trim()
if (!response.ok) {
lastDiag = 'HTTP ' + response.status + ': ' + body.slice(0, 200)
} else if (body.length === 0) {
lastDiag = 'DeepSeek 接口返回空响应'
} else {
const parsed = parseBalance(body)
if (parsed !== null && parsed.unavailable) {
const payload = { status: 'unavailable', message: 'DeepSeek 接口返回余额不可用(is_available=false)' }
balanceCache = { fetchedAt: now, payload }
return payload
}
if (parsed !== null && parsed.currencies.length > 0) {
const payload = { status: 'ok', currencies: parsed.currencies, fetchedAt: now }
balanceCache = { fetchedAt: now, payload }
return payload
}
lastDiag = body.slice(0, 300)
}
} catch (err) {
lastDiag = err instanceof Error ? (err.name === 'TimeoutError' || err.name === 'AbortError' ? '查询超时(30 秒)' : err.message) : String(err)
}
附完整 patch 文件:dsh-usage-stats-macos-balance.patch(可 git apply)。
环境
dsh-usage-stats@1.0.0根因
lib/index.js的fetchBalance()通过subprocess.spawn调用curl.exe与powershell.exe查询https://api.deepseek.com/user/balance。这两个可执行文件是 Windows 专属(macOS 只有不带.exe的curl,也没有powershell.exe),因此在非 Windows 平台 spawn 直接失败,两次尝试都落到「无法启动查询进程」。修复
改用 Node 原生
fetch(Node 18+ 全局可用,跨平台),去掉对 subprocess / curl.exe / powershell.exe 的依赖,并保留原有错误语义(401 / 超时 / 空响应 / is_available=false)。附完整 patch 文件:
dsh-usage-stats-macos-balance.patch(可git apply)。