@wenbin_wb/dsh-bridge 1.2.0 → 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 +38 -15
  2. package/package.json +1 -1
@@ -449,12 +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
- const meta = {
455
- cwd: this.config.cwd || process.cwd(),
456
- agentPreset: this.config.agentPreset || 'routing-suite',
457
- }
458
453
  const agentOptions = {}
459
454
  if (this.config.agentProvider) agentOptions.provider = this.config.agentProvider
460
455
  if (this.config.agentModel) agentOptions.model = this.config.agentModel
@@ -467,15 +462,40 @@ export class WechatConversationNode {
467
462
  }
468
463
  } catch { /* ignore */ }
469
464
  }
470
- const handle = await this.ctx.agents.create({
471
- sessionId: this.activeSessionId,
472
- meta,
473
- agentOptions,
474
- })
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
+ }
475
493
  agent = handle.agent
476
- 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'})`)
477
495
  } catch (err) {
478
- 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 <提示词> 新建一个会话。`)
479
499
  }
480
500
  }
481
501
  if (!agent) {
@@ -811,9 +831,12 @@ function foldTitle(events) {
811
831
  }
812
832
 
813
833
  // 列出会话:使用 DSH 官方 API(ctx.sessions + sessionPersistence),与 web 端一致。
814
- // 返回 [{ id, createdAt, events?, seq?, cwd?, title? }],按时间倒序。
834
+ // 屏蔽已归档会话。返回 [{ id, createdAt, events?, seq?, cwd?, title? }],按时间倒序。
815
835
  async function listSessions(node) {
816
- const live = [...(node.ctx.sessions?.list() ?? [])]
836
+ // 归档会话 ID 集合
837
+ let archived = new Set()
838
+ try { archived = new Set(node.ctx.workspaceRegistry?.archivedSessionIds ?? []) } catch { /* ignore */ }
839
+ const live = [...(node.ctx.sessions?.list() ?? [])].filter((s) => !archived.has(s.id))
817
840
  const liveIds = new Set(live.map((s) => s.id))
818
841
  // 内存活跃会话(带完整 events/title)
819
842
  const liveMapped = live.map((s) => {
@@ -828,7 +851,7 @@ async function listSessions(node) {
828
851
  try {
829
852
  const headers = await node.ctx.sessionPersistence?.list?.()
830
853
  if (Array.isArray(headers)) {
831
- const coldHeaders = headers.filter((h) => h && h.id && !liveIds.has(h.id) && h.cwd !== undefined)
854
+ const coldHeaders = headers.filter((h) => h && h.id && !liveIds.has(h.id) && h.cwd !== undefined && !archived.has(h.id))
832
855
  // 并行加载每个冷会话的 events 以提取标题
833
856
  cold = await Promise.all(coldHeaders.map(async (h) => {
834
857
  let title
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenbin_wb/dsh-bridge",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "手机扫码即可在移动端/公网继续用 DeepSeek Harness,人不在电脑前也能接着干。一键局域网二维码、Cloudflare 公网隧道、自建隧道与微信 Bot(多工作区/会话持久化/媒体/审批),无需自己搭公网服务器。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",