面板:跨大脑记忆共享——WorkBuddy首次会话注入前端历史(DeepSeek聊过的内容切WB也记得)

This commit is contained in:
Zhuyuan Operations 2026-08-04 01:54:47 +08:00
parent 961caed3e2
commit 954b9c73ec

View File

@ -2915,11 +2915,12 @@ class Handler(http.server.BaseHTTPRequestHandler):
_save_oc_sess()
return acc
def _stream_workbuddy(self, message, model, eed_sid, token):
def _stream_workbuddy(self, message, model, eed_sid, token, history=None):
"""WorkBuddy 免费积分大脑:codebuddy CLI 路径(苍耳 2026-08-04 接入)。
model 形如 wb/<实际模型id>。多轮会话靠 codebuddy 自己的会话文件续聊:
① 本场 sid 已在 codebuddy 开过(WB_SESS 有记录)→ --resume 接续记忆;
② 没开过 → --session-id 开新场并记录,下次就能 resume。
② 没开过 → --session-id 开新场,并把前端传来的 history(含 DeepSeek 聊过的内容)
拼进消息前缀 → WorkBuddy 一上来就知道之前聊过什么(跨大脑记忆共享)。
(2026-08-04 修复:之前靠猜 jsonl 路径判断 resume,路径不对 → 每次当新会话 → 完全失忆)"""
# wb/ 前缀剥掉,得到 codebuddy 认识的模型 id(hy3 / glm-5.2 / kimi-k3-1 ...)
cb_model = model.split("/", 1)[1] if "/" in model else model
@ -2931,6 +2932,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
"--system-prompt", EED_SYS]
if sid in WB_SESS:
return self._stream_cmd(cmd + ["--resume", sid, "-p", message], token)
# 全新会话:把之前的对话历史带过去(跨大脑共享记忆),再开 codebuddy 场
if history:
message = build_prompt(history, message)
acc = self._stream_cmd(cmd + ["--session-id", sid, "-p", message], token)
WB_SESS[sid] = {"ts": time.time()}
_save_wb_sess()
@ -3107,6 +3111,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
model = DEFAULT_MODEL
sid = str(data.get("session_id", "")).strip()
token = str(data.get("token", ""))[:64]
history = data.get("history") or []
if not isinstance(history, list):
history = []
if not message:
self._send(400, json.dumps({"reply": "(没收到内容)"}).encode("utf-8")); return
@ -3130,7 +3137,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
if model in WB_MODELS:
# WorkBuddy 免费积分大脑:走 codebuddy CLI(不花 DeepSeek 余额)
acc = self._stream_workbuddy(message, model, sid, token)
acc = self._stream_workbuddy(message, model, sid, token, history)
else:
acc = self._stream_opencode(message, model, sid, token)
if not acc: