@mcviseron/dsh-qq-bridge 0.3.4 → 0.3.5

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/lib/index.js +22 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * approval.
9
9
  */
10
10
  import { randomUUID } from 'node:crypto'
11
- import { readFileSync } from 'node:fs'
11
+ import { existsSync, readFileSync } from 'node:fs'
12
12
  import { appendFile, mkdir } from 'node:fs/promises'
13
13
  import { dirname, join, resolve } from 'node:path'
14
14
  import { fileURLToPath } from 'node:url'
@@ -34,12 +34,13 @@ export const DEFAULT_CONFIG = {
34
34
  quoteContextChars: 300,
35
35
  historyMax: 200,
36
36
  autoGroup: true,
37
- autoGroupRoot: 'D:\\dsh-qqbot-temp',
37
+ // 这些路径不能写死某台机器:留空则用插件数据目录,或由「一键安装」写下的 install.json 提供
38
+ autoGroupRoot: '',
38
39
  streamEnabled: true,
39
40
  streamIntervalMs: 250,
40
41
  autoStartBot: true,
41
- botDir: 'D:/Program/QQ-Bot-Class/dsh-bot/bot',
42
- pythonPath: 'C:/Users/25639/.conda/envs/ChatClone-BotPy/python.exe',
42
+ botDir: '',
43
+ pythonPath: '',
43
44
  modelProvider: '',
44
45
  model: '',
45
46
  reasoningEffort: '',
@@ -134,6 +135,7 @@ export function apply(ctx, rawConfig) {
134
135
  stdio: 'ignore',
135
136
  windowsHide: true,
136
137
  })
138
+ child.on('error', (error) => log(`bot supervisor spawn failed: ${error.message}`))
137
139
  child.unref()
138
140
  log(`bot supervisor spawned after install (pid ${child.pid})`)
139
141
  return child.pid
@@ -165,7 +167,7 @@ export function apply(ctx, rawConfig) {
165
167
  const workspaceFor = async (convKey, overrides) => {
166
168
  const enabled = overrides?.autoGroup === undefined ? config.autoGroup === true : overrides.autoGroup === true
167
169
  if (!enabled) return config.cwd
168
- const root = String(overrides?.autoGroupRoot || config.autoGroupRoot || 'D:\\dsh-qqbot-temp')
170
+ const root = String(overrides?.autoGroupRoot || config.autoGroupRoot || join(config.dataDir, 'auto-group'))
169
171
  const name = convKey.replace(/[^A-Za-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60) || 'qq'
170
172
  const dir = join(root, name)
171
173
  try {
@@ -813,6 +815,19 @@ export function apply(ctx, rawConfig) {
813
815
  const installed = await readInstall(config.dataDir)
814
816
  const pythonPath = typeof installed?.pythonPath === 'string' && installed.pythonPath !== '' ? installed.pythonPath : config.pythonPath
815
817
  const botDir = typeof installed?.botDir === 'string' && installed.botDir !== '' ? installed.botDir : config.botDir
818
+ // 没配置 / 路径不存在就明确跳过:spawn 的 ENOENT 是异步 'error' 事件,抛不进 try/catch,会直接崩掉宿主
819
+ if (pythonPath === '' || botDir === '') {
820
+ log('bot autostart skipped: pythonPath/botDir 未配置(用设置页的「下载 / 配置机器人」装一次)')
821
+ return
822
+ }
823
+ if (!existsSync(join(botDir, 'main.py'))) {
824
+ log(`bot autostart skipped: 找不到 ${join(botDir, 'main.py')}`)
825
+ return
826
+ }
827
+ if (!existsSync(pythonPath)) {
828
+ log(`bot autostart skipped: 解释器不存在 ${pythonPath}`)
829
+ return
830
+ }
816
831
  const { spawn } = await import('node:child_process')
817
832
  const child = spawn(pythonPath, ['-u', 'main.py', '--supervise'], {
818
833
  cwd: botDir,
@@ -820,6 +835,7 @@ export function apply(ctx, rawConfig) {
820
835
  stdio: 'ignore',
821
836
  windowsHide: true,
822
837
  })
838
+ child.on('error', (error) => log(`bot autostart failed: ${error.message}`))
823
839
  child.unref()
824
840
  log(`bot supervisor spawned (pid ${child.pid})`)
825
841
  } catch (error) {
@@ -1053,7 +1069,7 @@ export function apply(ctx, rawConfig) {
1053
1069
 
1054
1070
  const readMembers = () => {
1055
1071
  try {
1056
- const file = join(String(config.botDir || "."), "state", "members.json")
1072
+ const file = join(String(config.botDir || join(config.dataDir, 'bot')), "state", "members.json")
1057
1073
  const raw = readFileSync(file, "utf8")
1058
1074
  return JSON.parse(raw)
1059
1075
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcviseron/dsh-qq-bridge",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "DeepSeek Harness plugin: bridge QQ conversations (driven by an external viseron-botpy bot) to DSH sessions — injects user messages, captures assistant replies, streams C2C answers, and relays tool approvals to the bot owner.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",