dsh-message-router:在 DSH 會話與外部渠道之間做消息路由

前言

在 DeepSeek Harness(DSH)裏做智能體,常見需求是把本地 Session 裏的對話和 QQ、遠程網關等外部通道連起來,同時又要分清「誰發的」「哪條 binding 負責的」,避免混綁、誤發。若只在自己進程裏拼 RPC 或手寫轉發,很難和 DSH 原生 inbox、提交語義對齊。

下面介紹社區獨立 Host 插件 jensentsts/dsh-message-router(npm 包名 dsh-super-agent-io,0.0.1)。它在 DSH 0.2.2-rc.1 上註冊 superAgentIo 適配服務,把原生 Session 與已註冊的外部 transport/binding 接起來;QQ 與遠程適配器可作爲可選消費者,通過同一套契約收發。

這是什麼

一句話:在 DSH 會話與外部渠道之間做消息路由,並支持可持久化的投遞迴執(durable delivery receipts)。插件集導航見 dsh-independent-plugins。

環境要求

package.json 中約定:

  • Node.js >=24.9
  • DSH >=0.2.2-rc.1 <0.3.0
  • 對等依賴含 @deepseek-ai/dsh-tools、@deepseek-ai/dsh-storage-domain 等 0.2.2-rc.1 線

適配服務標識:superAgentIo(契約版本 1);可選只讀監控服務 superAgentIoMonitor(owner)。Loader 入口爲 independent-super-agent-io,存儲域 super_agent_io 版本 1。類型與校驗分別見倉庫 index.d.ts、contract.mjs。

核心能力

安全默認值與收發門控

enabled 與 sendEnabled 默認均爲 false。出站適配器綁定需同時滿足 enabled 和 sendEnabled;接收則要求已啓用的 IO 與已啓用的 binding。Preview 爲只讀。Host 插件對外部請求自行鑑權;模型可在 owner 發起的 DSH turn 中顯式發送,並受上述開關約束。

僅收消息的 binding 可設 receiveOnly: true:已提交輸入與本地模型回覆留在 canonical Session,IO 不爲該 binding 持有出站投遞並強制關閉其 send 開關。

適配器契約(superAgentIo)

已有適配器通過 ctx.superAgentIo 註冊 transport、建立 binding,並調用 receive / 投遞 API。README 給出最小接入順序:獲取服務 → 註冊 transport → putBinding → 可選 preload → receive。

const io = ctx.get('superAgentIo')
if (!io || io.contractVersion !== 1) throw new Error('Compatible IO service unavailable')
const remove = io.registerTransport({
  id: 'my-transport',
  async deliver(delivery, { signal, idempotencyKey }) {
    // Authenticate sender/target and preserve signal/idempotencyKey in your adapter.
    // One delivery is one real committed assistant message, NOT a sentence fragment.
    return { state: 'delivered', externalMessageId: 'confirmed-platform-message-id' }
  },
})
ctx.effect(() => remove)
await io.putBinding({
  id: 'my-binding', transport: 'my-transport', endpoint: 'private:123',
  sessionId: 'existing-session-full-id', enabled: true, sendEnabled: false,
  mode: 'auto', preload: true,
})
await io.preload('my-binding') // official resolveAgent, never create-on-error
const receipt = await io.receive({
  bindingId: 'my-binding', externalMessageId: 'platform-input-id', senderId: '123',
  content: [{ type: 'text', text: 'Hello' }], replyTo: 'quoted-platform-input-id',
})

要點(均出自 README):

  • registerTransport:非空 ID、最長 128 字符、不可重複;返回冪等 disposer;密鑰放在適配器 credentials 服務,不要寫進 endpoint 或內容。
  • putBinding:持久化的是 sidecar 狀態,不是 profile 配置;已用過的 binding ID 不能換 endpoint/session。
  • receive:state:'accepted' 只表示原生方法返回;messageCommitted 初始爲 false;僅當匹配的 user/message 提交後纔爲 true。可用 receipt(traceId) 輪詢;超時/卸載可能爲 unknown,不會假成功或自動重發。
  • 入站內容限於公開 text,或已通過 DSH 准入的 image/file 持久引用;角色爲 user,來源爲 kind:'super-agent-io'。

Session 動作與調度

  • preload(bindingId):用官方 sessionController.resolveAgent 恢復綁定 Session;不會在找不到/session 異常時靜默 createSession。
  • createSession({cwd?,agentPreset?}):顯式 Host 動作,preview/准入不會當作回退。
  • preview:冷讀 Session,不含隱藏上下文、推理與工具;不恢復 Agent、不發模型請求。
  • 隊列用 followup,轉向用 steer;cancel 爲 trusted-Host,可停 live Agent 並取消該 Session 相關 pending 投遞。

已提交輸出與路由

Host 只消費已提交的 Session 事件。每條公開的已提交 assistant/message 爲獨立有序回覆;推理與工具塊不導出。路由根據 canonical 事件重建 inbox 與 turn 歸屬:僅能唯一歸因到某一已知 binding 的 turn 纔會從該 binding 出站;混綁、本地輸入、未知外部生產者等會抑制外部投遞並記錄原因。本插件不拆句、不解析 [QQ] 標籤。

可信適配器可用有界的 replySource(actor、provider、model、來源 session/message ID 與 sequence/turn/step)發送已提交的外部回覆;IO 在保留正文的同時記錄這些事實,供展示層渲染生產者身份。

安裝與啓用

當前提供的 README 與 package.json 未給出單獨的 dsh plugin add … 一行命令。安裝與啓用請以 SkillHub 目錄頁 與 GitHub README 爲準;安裝前建議閱讀源碼與 MIT 許可證。插件以當前 DSH 進程權限運行,對外 binding 與 transport 需自行完成鑑權與密鑰管理。

啓用 binding 時務必理解默認 enabled: false、sendEnabled: false;需要出站時再顯式打開 sendEnabled。

典型用法(適配器開發者)

  1. 在 Cordis 上下文中取得 superAgentIo,校驗 contractVersion === 1。
  2. 在插件 effect 內 registerTransport,實現 deliver:一次投遞對應一條真實已提交的 assistant 消息,保留 signal 與 idempotencyKey。
  3. putBinding 綁定已有 sessionId、transport、endpoint;按需設置 mode、preload、receiveOnly。
  4. 外部消息到達時調用 receive,用 receipt 跟蹤 messageCommitted 與持久化屏障。
  5. 需要只看歷史、不跑模型時調用 preview;需要恢復會話時先 preload。

倉庫提供 node --test tests/*.test.mjs 與 node build.mjs --check;README 說明離線測試覆蓋 Cordis/Session、Gateway 權限等,真實 QQ/對等投遞與完整 GUI 安裝需另行驗證。

適用場景與注意

適合:要在 DSH 0.2.2-rc.1 上爲 Session 做正規外部通道接入的適配器/工作流作者;需要 binding 級收發門控、投遞迴執與 turn 級路由審計的場景。

注意:

  • 同一 Session 多 binding 共享取消範圍,不保證隔離隱私上下文;不同對話應使用不同 Session。
  • 共享 Session 不等於多個獨立人類發送者;普通 runtime-context 不會當作第二發件人暴露在歷史中。
  • SkillHub 爲社區獨立目錄,與 DeepSeek / 幻方無官方從屬關係;星標等頁面元數據以目錄爲準(當前線索爲 0)。

結尾

dsh-message-router(dsh-super-agent-io)把 DSH 原生 Session 與外部 transport 收到同一套 superAgentIo 契約裏,默認關閘、提交後才路由出站,並保留可追溯的投遞語義。進一步瞭解請查看 目錄頁 與 GitHub 倉庫。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜