diff --git a/lib/deliver.js b/lib/deliver.js index 90bdea2..cb9bb40 100644 --- a/lib/deliver.js +++ b/lib/deliver.js @@ -53,6 +53,9 @@ export class MailDeliverer { const id = sessionId; const live = this.ctx.agents.get(id); if (live) { + if (this.ctx.sessions.get(id) !== live.session) { + throw new Error(`会话 ${sessionId} 未进入全局 SessionStore`); + } const borrowed = { agent: live, off: this.watch(live), @@ -67,10 +70,20 @@ export class MailDeliverer { handle = await this.ctx.agents.resume({ resumeSessionId: id }); } catch { - handle = await this.ctx.agents.create({ sessionId: id }); + // 与 ACP 的外部会话创建路径一致:cwd 是持久会话的工作区元数据。 + handle = await this.ctx.agents.create({ + sessionId: id, + meta: { cwd: process.cwd() }, + }); created = true; } this.onLog?.(`[mail] ${sessionId} 会话已${created ? '创建' : '恢复'}`); + // DeepSeek 请求扩展通过全局 SessionStore 上传 dsh_session_log。若这里不可见, + // 继续 followup 只会让服务端按 sessionId 加载一份不存在的历史。 + if (this.ctx.sessions.get(id) !== handle.agent.session) { + await handle.dispose(); + throw new Error(`会话 ${sessionId} 创建后未进入全局 SessionStore`); + } const owned = { agent: handle.agent, off: this.watch(handle.agent), diff --git a/lib/index.js b/lib/index.js index 08685ca..e4ed9c3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,7 @@ import { MailGateway } from './gateway.js'; import { MailGatewayService } from './service.js'; export { Config } from './config.js'; export const name = 'dsh-mail-sender'; -export const inject = ['agents', 'settings']; +export const inject = ['agents', 'sessions', 'settings']; /** * 常驻入口:邮件驱动会话,而不是等待模型调用的 Tool。 * 所有 IMAP/SMTP 资源与监听都收在 ctx.effect 里按序回收。 diff --git a/src/deliver.ts b/src/deliver.ts index 3d93b2a..1540ae9 100644 --- a/src/deliver.ts +++ b/src/deliver.ts @@ -69,6 +69,9 @@ export class MailDeliverer { const id = sessionId as SessionId const live = this.ctx.agents.get(id) if (live) { + if (this.ctx.sessions.get(id) !== live.session) { + throw new Error(`会话 ${sessionId} 未进入全局 SessionStore`) + } const borrowed: DriveHandle = { agent: live, off: this.watch(live), @@ -83,11 +86,22 @@ export class MailDeliverer { try { handle = await this.ctx.agents.resume({ resumeSessionId: id }) } catch { - handle = await this.ctx.agents.create({ sessionId: id }) + // 与 ACP 的外部会话创建路径一致:cwd 是持久会话的工作区元数据。 + handle = await this.ctx.agents.create({ + sessionId: id, + meta: { cwd: process.cwd() }, + }) created = true } this.onLog?.(`[mail] ${sessionId} 会话已${created ? '创建' : '恢复'}`) + // DeepSeek 请求扩展通过全局 SessionStore 上传 dsh_session_log。若这里不可见, + // 继续 followup 只会让服务端按 sessionId 加载一份不存在的历史。 + if (this.ctx.sessions.get(id) !== handle.agent.session) { + await handle.dispose() + throw new Error(`会话 ${sessionId} 创建后未进入全局 SessionStore`) + } + const owned: DriveHandle = { agent: handle.agent, off: this.watch(handle.agent), diff --git a/src/index.ts b/src/index.ts index d5c0447..b7993d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { MailGatewayService } from './service.js' export { Config } from './config.js' export const name = 'dsh-mail-sender' -export const inject = ['agents', 'settings'] +export const inject = ['agents', 'sessions', 'settings'] /** * 常驻入口:邮件驱动会话,而不是等待模型调用的 Tool。