feat: bind bot chats to existing harness sessions

This commit is contained in:
xmanrui 2026-08-18 02:59:29 +08:00
parent 76d5430f1f
commit 1af8610cd5
21 changed files with 1807 additions and 130 deletions

View file

@ -2,6 +2,8 @@ import { spawn } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { isAbsolute } from 'node:path';
import { adoptRegisteredWorkspaceSession } from '../shared/harness-session-binding.mjs';
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
function workspacePaths(value) {
@ -250,6 +252,10 @@ export class HarnessClient {
return workspaceSessions(workspace, workspaceList.archivedSessionIds, sessionList);
}
async adoptWorkspaceSession(value, options = {}) {
return adoptRegisteredWorkspaceSession(this, value, options);
}
async workspaceId(options = {}) {
const workspace = options.workspace ?? this.#workspace;
const { items } = await this.rpc('workspace.list', {});

View file

@ -14,6 +14,7 @@ const HELP_TEXT = [
'/workspace 工作区绝对路径 切换工作区',
'/workspacelist 列出工作区绝对路径',
'/sessionlist [工作区序号或绝对路径] 列出会话 ID 和标题',
'/session Session ID 将当前聊天绑定到指定会话',
'/status 检查连接状态',
'/help 显示本帮助',
].join('\n');
@ -121,6 +122,7 @@ export class WeixinHarnessBridge {
}
const command = text.trim().toLowerCase();
const key = conversationKey(sender);
if (command === '/help') {
await this.#send(sender, HELP_TEXT, contextToken, runId);
await this.#state.markSeen(messageId);
@ -133,12 +135,12 @@ export class WeixinHarnessBridge {
return;
}
if (command === '/new') {
await this.#state.clearSession(conversationKey(sender));
await this.#state.clearSession(key);
await this.#send(sender, '已开启新会话。请发送你的问题。', contextToken, runId);
await this.#state.markSeen(messageId);
return;
}
const workspaceCommand = await runWorkspaceCommand(text, this.#harness);
const workspaceCommand = await runWorkspaceCommand(text, this.#harness, key);
if (workspaceCommand) {
for (const reply of workspaceCommand.messages ?? [workspaceCommand.message]) {
await this.#send(sender, reply, contextToken, runId);
@ -147,7 +149,6 @@ export class WeixinHarnessBridge {
return;
}
const key = conversationKey(sender);
const { answer } = await askInWorkspaceSession({
harness: this.#harness,
state: this.#state,