bhg-helper 1.0.4 → 1.0.6

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.
Files changed (2) hide show
  1. package/cli/cli.js +29 -11
  2. package/package.json +1 -1
package/cli/cli.js CHANGED
@@ -184,9 +184,16 @@ async function apiPost(pathname) {
184
184
  }
185
185
 
186
186
  async function apiGet(pathname) {
187
- const res = await fetch(`${API_URL}${pathname}`)
188
- if (!res.ok) return null
189
- return await res.json().catch(() => null)
187
+ try {
188
+ const controller = new AbortController()
189
+ const timer = setTimeout(() => controller.abort(), 800)
190
+ const res = await fetch(`${API_URL}${pathname}`, { signal: controller.signal })
191
+ clearTimeout(timer)
192
+ if (!res.ok) return null
193
+ return await res.json().catch(() => null)
194
+ } catch {
195
+ return null
196
+ }
190
197
  }
191
198
 
192
199
  async function apiHealth() {
@@ -203,14 +210,25 @@ async function apiHealth() {
203
210
 
204
211
  async function ensureBackend() {
205
212
  if (await apiHealth()) return true
206
- const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'
207
- const child = spawn(npmCmd, ['run', 'server:raw'], {
208
- cwd: PROJECT_ROOT,
209
- detached: true,
210
- stdio: 'ignore',
211
- shell: false,
212
- })
213
- child.unref()
213
+ try {
214
+ if (process.platform === 'win32') {
215
+ execSync('start "" /min cmd /c "npm run server:raw"', {
216
+ cwd: PROJECT_ROOT,
217
+ stdio: 'ignore',
218
+ shell: true,
219
+ })
220
+ } else {
221
+ const child = spawn('npm', ['run', 'server:raw'], {
222
+ cwd: PROJECT_ROOT,
223
+ detached: true,
224
+ stdio: 'ignore',
225
+ shell: false,
226
+ })
227
+ child.unref()
228
+ }
229
+ } catch {
230
+ return false
231
+ }
214
232
  await new Promise(resolve => setTimeout(resolve, 1500))
215
233
  return await apiHealth()
216
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bhg-helper",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "BHG-helper:AI 编程工具 DeepSeek 中转 & 可视化配置工具",
5
5
  "type": "module",
6
6
  "bin": {