@wenbin_wb/dsh-bridge 1.2.1 → 1.2.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.
Files changed (2) hide show
  1. package/lib/wechat/node.js +32 -20
  2. package/package.json +1 -1
@@ -449,20 +449,7 @@ export class WechatConversationNode {
449
449
  let agent = this.activeAgent()
450
450
  if (!agent && this.activeSessionId) {
451
451
  // agent 不在内存(DSH 重启后或切换到持久化会话)→ re-attach。
452
- // agents.create(sessionId) 对已持久化的 session 会自动采纳其历史,对不存在的则新建。
453
452
  try {
454
- // 读取持久化会话的 cwd,避免 cwd 冲突
455
- let sessionCwd = this.config.cwd || process.cwd()
456
- try {
457
- const headers = await this.ctx.sessionPersistence?.list?.()
458
- const header = headers?.find?.((h) => h?.id === this.activeSessionId)
459
- if (header?.cwd) sessionCwd = header.cwd
460
- } catch { /* 读取失败则用 fallback */ }
461
-
462
- const meta = {
463
- cwd: sessionCwd,
464
- agentPreset: this.config.agentPreset || 'routing-suite',
465
- }
466
453
  const agentOptions = {}
467
454
  if (this.config.agentProvider) agentOptions.provider = this.config.agentProvider
468
455
  if (this.config.agentModel) agentOptions.model = this.config.agentModel
@@ -475,15 +462,40 @@ export class WechatConversationNode {
475
462
  }
476
463
  } catch { /* ignore */ }
477
464
  }
478
- const handle = await this.ctx.agents.create({
479
- sessionId: this.activeSessionId,
480
- meta,
481
- agentOptions,
482
- })
465
+
466
+ // 判断该 session 是否已持久化:已持久化 → agents.resume(从持久化加载历史恢复,
467
+ // 避免 agents.create 用空 seed 与已持久化事件冲突);未持久化 → agents.create。
468
+ let persisted = false
469
+ try {
470
+ const headers = await this.ctx.sessionPersistence?.list?.()
471
+ persisted = Array.isArray(headers) && headers.some((h) => h?.id === this.activeSessionId)
472
+ } catch { /* 读取失败则按未持久化处理 */ }
473
+
474
+ let handle
475
+ if (persisted) {
476
+ handle = await this.ctx.agents.resume({
477
+ resumeSessionId: this.activeSessionId,
478
+ agentOptions,
479
+ })
480
+ } else {
481
+ // 读取持久化会话的 cwd 做 fallback(新建会话时用)
482
+ let sessionCwd = this.config.cwd || process.cwd()
483
+ const meta = {
484
+ cwd: sessionCwd,
485
+ agentPreset: this.config.agentPreset || 'routing-suite',
486
+ }
487
+ handle = await this.ctx.agents.create({
488
+ sessionId: this.activeSessionId,
489
+ meta,
490
+ agentOptions,
491
+ })
492
+ }
483
493
  agent = handle.agent
484
- this.logger?.info?.(`[dsh-bridge wechat] re-attached agent to session ${this.activeSessionId}`)
494
+ this.logger?.info?.(`[dsh-bridge wechat] re-attached agent to session ${this.activeSessionId} (${persisted ? 'resume' : 'create'})`)
485
495
  } catch (err) {
486
- this.logger?.warn?.(`[dsh-bridge wechat] failed to re-attach agent: ${err?.message ?? err}`)
496
+ const reason = err instanceof Error ? err.message : String(err)
497
+ this.logger?.warn?.(`[dsh-bridge wechat] failed to re-attach agent: ${reason}`)
498
+ await sendTextToPeer(this, `${MARK.err} 恢复会话失败: ${reason}。发送 /new <提示词> 新建一个会话。`)
487
499
  }
488
500
  }
489
501
  if (!agent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenbin_wb/dsh-bridge",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "手机扫码即可在移动端/公网继续用 DeepSeek Harness,人不在电脑前也能接着干。一键局域网二维码、Cloudflare 公网隧道、自建隧道与微信 Bot(多工作区/会话持久化/媒体/审批),无需自己搭公网服务器。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",