rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:Naiqey-Star/dsh-aichat-bridge
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
把一个 DeepSeek Harness(DSH)会话 暴露成 OpenAI 兼容接口,让游戏里的聊天 Mod(例如 Chill With You 的 AIChat)可以直接把对话交给 DSH 处理。
解决的问题很具体:
桥接把两者接起来:人设和回复格式仍由 Mod 决定(作为系统提示词整段替换掉 DSH 的默认人设),文件和模型调用交给 DSH,每次请求写入同一个稳定会话,你可以在 DSH 界面里翻看这段对话、往里丢资料。
游戏 AIChat ──POST /aichat/v1/chat/completions──▶ DSH 插件(本机 127.0.0.1)
│
├─ 把 system 消息作为该会话的完整系统提示词
├─ 打开(或新建)固定 sessionId 的会话
├─ 投递一条 user 消息,等这一轮跑完
├─ 模型可调用 read_file 读取 readRoots 内的文件
└─ 把最后的 assistant 文本包成 chat.completion 返回
cwd 不够,插件会用 workspaceRegistry 把会话 attach 到路径匹配的工作区(其余情况才落在「未分组」)。/health 里的 workspaces[].attached 可以直接看出有没有挂上。complete: true 的段落整段替换,DSH 的人设、编码助手框架不会混进来;工具说明由桥接自己补一小段。read_file 工具,只认 readRoots 里的目录。# 把包放进 profile 的 node_modules(或发布到 npm 后用 dsh plugin add)
dsh plugin --profile <你的 profile> add dsh-aichat-bridge
然后在这个 profile 的 cordis.patch.yml 里加一段(或直接改包内 cordis.patch.yml 后重装):
- insert:
- id: aichat-bridge
name: dsh-aichat-bridge
config:
sessionId: aichat-bridge
provider: deepseek-account
model: deepseek-flash
readRoots:
- D:/我的资料
token: ""
重启 DSH(或让 Loader 热加载该行),日志里会出现:
[aichat-bridge] serving /aichat/v1/chat/completions on session "aichat-bridge" (...)
curl http://127.0.0.1:<DSH 端口>/aichat/health
{"ok":true,"service":"dsh-aichat-bridge","version":"0.1.0","sessionId":"aichat-bridge","provider":"deepseek-account","model":"deepseek-flash","readRoots":["D:\\我的资料"],"listenPort":47821,"cwd":"D:\\DSH_WORK","agentLive":true}
DSH 桌面端每次启动的 Web 端口可能不同(实测换过一次),如果客户端写死「DSH 当前端口」,重启后就会连到正在退出的旧实例上——表现就是 502 Bad Gateway。
所以插件默认另外监听一个固定的回环端口 47821,游戏端永远连这个地址:
http://127.0.0.1:47821/aichat/v1/chat/completions
listenPort: 0 可以关掉它,只保留 DSH 自身 Web 端口上的路由(http://127.0.0.1:<DSH 端口>/aichat/...)。
把包手工拷进 profiles/<名称>/node_modules 是不持久的:DSH 重启或装插件时会按 package.json 重新 pnpm install,多余目录会被清掉(实测发生过)。要么正式 dsh plugin add,要么在补丁行里直接写文件 URL:
- insert:
- id: aichat-bridge
name: file:///D:/path/to/dsh-aichat-bridge/lib/index.js
config: { ... }
这样加载器按绝对路径 import,pnpm 清理不会影响它。
| 字段 | 默认 | 说明 |
|---|---|---|
path |
/aichat |
挂在 DSH Web 服务上的路径前缀(仅本机回环) |
token |
"" |
客户端要带的 Bearer 口令;空 = 不校验。建议设置,避免本机其他程序误用 |
sessionId |
aichat-bridge |
固定会话 id,就是这个「频道」;在 DSH 会话列表里可见 |
provider / model |
deepseek-account / deepseek-flash |
桥接轮次使用的模型路由 |
readRoots |
[] |
允许 read_file 读取的绝对目录(可列多个) |
allowAllDrives |
false |
true = 本机所有可见磁盘都可读(只读),仍受 denyPaths 限制 |
denyPaths |
[] |
明确排除的目录,优先于上面两项 |
maxReadBytes |
200000 |
单文件大小上限,超过直接拒绝 |
listenPort |
47821 |
固定回环端口;0 表示只保留 DSH 自身 Web 端口上的路由 |
cwd |
空(用 DSH 默认工作目录) | 写进会话头的项目目录;空着会让会话落到 _no-cwd,侧边栏看不到 |
timeoutMs |
180000 |
单轮硬超时,超时会取消该轮并返回 504 |
debugLog |
"" |
非空时写入 NDJSON 诊断轨迹(排查用) |
| 方法 | 路径 | 说明 |
|---|---|---|
GET |
{path}/health |
健康信息,不需要口令 |
GET |
{path}/v1/models |
返回配置里的模型名,方便客户端探测 |
POST |
{path}/v1/chat/completions |
主接口,body 为 OpenAI Chat Completions 格式 |
请求示例:
{
"model": "dsh-bridge",
"messages": [
{ "role": "system", "content": "[情绪]|||语音文本|||字幕文本 格式说明 + 角色人设" },
{ "role": "user", "content": "读一下 D:\\我的资料\\设定.txt,把里面的暗号念给我听" }
]
}
响应是标准 chat.completion,choices[0].message.content 就是角色这一轮说的话。usage 目前是 0 占位(真实用量看 DSH 侧)。
/aichat/health 正常。UseDshBridge = TrueDshBridgeUrl = http://127.0.0.1:2617/aichat/v1/chat/completions(端口以 DSH 实际监听为准)DshBridgeToken = 与插件 token 一致,或都留空DshBridgeModel = dsh-bridge(仅用于标识)UseDshBridge 就回到原来的 API 流程,两套配置互不影响。read_file 在 readRoots 内做 realpath 解析后再比对,..、符号链接都逃不出去;只读,不提供写入/删除/执行命令的能力。token:本机任何进程都能访问回环端口。默认什么都不给。按需开放,有两种写法:
# 1) 精确列出想要的目录
readRoots:
- D:/图片
- C:/Users/PC/Documents
- E:/参考资料
# 2) 干脆全盘只读,再排除敏感目录
allowAllDrives: true
denyPaths:
- C:/Users/PC/.ssh
- C:/Users/PC/.dsh
- C:/Users/PC/AppData/Roaming/@deepseek-ai
几点说明:
denyPaths 先于 readRoots 判断,被排除的路径连 realpath 之后的比对也逃不掉。maxReadBytes 调整。DSH 把会话按项目目录分组存放(sessions/<项目>/<会话>)。如果创建会话时没写 cwd,它会落到 sessions/_no-cwd/,而界面只列当前工作区的会话,于是"有对话但看不到"。
插件现在会把 cwd(配置项,默认取 DSH 的工作目录默认值)写进会话头,会话就会和普通会话一样出现在对应工作区里。已经存在的旧会话不会被改写——改过 cwd 后需要删掉旧的 sessions/_no-cwd/<sessionId> 目录,下一次请求会按新目录重建。
409 SESSION_IN_USE;在同一个界面里打开、发消息不受影响。stream: true 会收到一次性 JSON,AIChat 本身不用流式。node --test test/bridge.test.mjs # 契约测试,用桩上下文,不需要 DSH
目录:
lib/index.js 插件入口:路由、会话生命周期、系统提示词、read_file
lib/openai.js 线格式:请求解析、响应/错误构造、Bearer 校验
test/ 契约测试
仓库已按社区 bundle 规范整理好,发布时只需要:
package.json 里补 repository / homepage / bugs 三个地址;git remote add origin https://github.com/<你的账号>/dsh-aichat-bridge.git
git push -u origin main
npm publish(包名 dsh-aichat-bridge),之后就能在 DSH 里 dsh plugin --profile <名称> add dsh-aichat-bridge。MIT
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek-harness、openai-compatible。