agent-loft 0.2.126 → 0.2.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/bin/cli.js +40 -19
- package/package.json +7 -2
- package/src/agents/claude/session.ts +8 -5
- package/src/agents/codex/driver.ts +42 -17
- package/src/agents/codex/session.ts +5 -4
- package/src/agents/dsh/session.ts +3 -1
- package/src/agents/pi/session.ts +4 -3
- package/src/agents/workbuddy/session.ts +6 -3
- package/src/channels/web/api.ts +12 -1
- package/src/channels/web/memo-collab.ts +183 -0
- package/src/channels/web/memo-file.ts +30 -0
- package/src/channels/web/memo-storage.ts +172 -0
- package/src/channels/web/memos-api.ts +129 -0
- package/src/channels/web/server.ts +2 -0
- package/src/cli/service.ts +3 -1
- package/src/core/db.ts +18 -0
- package/src/core/expert-prompt.ts +2 -1
- package/src/core/hub.ts +4 -0
- package/src/core/mcp.ts +2 -2
- package/src/core/memo-index.ts +154 -0
- package/src/core/memo-sources.ts +82 -0
- package/src/core/memo-versions.ts +26 -0
- package/src/core/memos-bridge.ts +63 -0
- package/src/core/personal.ts +2 -0
- package/src/core/tasks-bridge.ts +6 -0
- package/src/core/tasks-mcp.ts +7 -0
- package/src/core/types.ts +2 -0
- package/src/core/ui-prefs.ts +1 -1
- package/src/core/upgrade-health.ts +21 -0
- package/src/core/upgrade-launcher.ts +94 -0
- package/src/core/upgrade-releases.ts +103 -0
- package/src/core/upgrade.ts +54 -18
- package/src/main.ts +14 -0
- package/src/mcp/memo-tools.ts +26 -0
- package/src/mcp/tasks-server.ts +5 -4
- package/web/css/memos.css +50 -0
- package/web/css/sidebar.css +1 -19
- package/web/index.html +1 -0
- package/web/lib/api.js +3 -2
- package/web/lib/markdown.js +9 -2
- package/web/settings/users.js +41 -15
- package/web/vendor-built/codemirror.js +20 -20
- package/web/views/file-editor.js +39 -7
- package/web/views/layout.js +6 -1
- package/web/views/memo-dialogs.js +147 -0
- package/web/views/memos.js +537 -0
- package/web/views/remote.js +2 -1
- package/web/views/sidebar-nav.js +1 -0
- package/web/views/topbar.js +4 -6
package/README.md
CHANGED
|
@@ -102,6 +102,9 @@ Logo 是白底的三向汇合:橘红、暖橙和珊瑚红三个单元,表达
|
|
|
102
102
|
- **工作区面板**:会话右上角「更多 → 文件」打开或折叠,菜单中用绿色新增行数、红色删除行数显示当前分支的改动,在对话旁边(手机上全屏)看和改这条会话工作目录里的文件。「文件」页签是一棵按需展开的文件树,图片、PDF、音视频、Markdown、网页、代码直接预览,CSV / TSV 显示成表格;文本文件(1 MB 以内、UTF-8)可以编辑,Ctrl / ⌘ + S 保存,Markdown 和 CSV 能预览没保存的内容。还能新建、重命名、上传(点按钮或拖到面板上)、删除。保存时如果文件在你编辑期间被 agent 或别人改过,不会覆盖,由你选覆盖还是重新加载;没保存的内容存在本机,换会话、刷新页面都不丢。「改动」页签是 Git 仓库的已暂存 / 未暂存 / 未跟踪文件,点开看 diff,宽度够时可以切并排;顶栏的分支标记显示当前分支和改动数,点面板里的分支行能查看和切换本地、远程分支,也能新建分支。文件行上可以暂存、取消暂存、丢弃改动,写好说明提交已暂存的内容(默认不运行 Git 钩子,要用的话勾上);「历史」页签看提交记录和每个提交的 diff。推送、拉取、合并、变基请交给 agent 或终端。一轮结束、切回窗口时自动刷新。
|
|
103
103
|
- 管理员能用;成员要管理员在 设置 → 用户 里单独「开通工作区面板」。
|
|
104
104
|
- 分支栏下面可以获取、拉取、推送,用的是服务器上配置的 Git 凭据。拉取只做快进,推送从不强制。成员默认没有这个权限,要管理员再单独「开通 Git 远程操作」。
|
|
105
|
+
- **备忘录**。从侧栏进入「备忘录 → 连接笔记库」,选择 WebDAV 目录,或填写 S3 存储桶、区域和可选前缀。可连接多个笔记库,按文件夹浏览、新建和编辑 Markdown、TXT、JSON、YAML、CSV 等 UTF-8 文本。编辑时粘贴图片会写入当前文件夹的 `assets/`,并插入相对链接。在同一台 Agent Loft 服务上,各账号以相同存储地址、目录和凭据打开同一文件即可实时合写,编辑中的输入会自动合并并写回,阅读视图也会跟随更新。预览支持相对链接。「版本历史」可以查看并恢复这条连接下每份文本最近 50 个修改前的版本,保存在 Agent Loft 的本地数据库。浏览器通过 Agent Loft 的 HTTP 接口提交修改,用长轮询接收协作更新。Obsidian 等外部客户端直接写入存储时,重新打开文件会读取最新正文,写回冲突时可保留草稿并另存副本。文本上限 2 MB,每张图片上限 12 MB。连接凭据按账号保存在服务端,内网端点可用管理员账号连接。
|
|
106
|
+
- **让智能体查笔记或改笔记**。在连接表单或笔记库旁的「智能体访问」中选「只读」或「读写」,新旧库默认关闭。授权后可在自己的对话里按文件名和正文搜索、浏览目录、读取笔记;读写库还支持新建、追加和精确替换一处原文。只有你表达了留存或更新笔记的意图,智能体才会写入。比如你说「把刚才的排查过程留着下次用」,智能体会根据对话整理正文,优先更新已有笔记,也可以自己起名新建,并在保存后告诉你位置。保存后,正在编辑的网页会收到更新,原文可在版本历史中查看。计划模式只读。
|
|
107
|
+
- 授权后服务器在本地建立全文索引。网页和智能体保存后更新索引;外部修改每 10 分钟扫描一次,也可以在「智能体访问」里查看进度和最近成功时间,或立即刷新。首次扫描期间搜索只覆盖已收录内容。关闭授权或断开连接会清除该库的搜索索引。
|
|
105
108
|
- **资料库**:像 ChatGPT 的资料库,侧栏的「资料库」。对话里发过的附件、agent 回复里给出的、这一轮新写出来的图片 / 文档 / 音视频(复制一份收进来,之后原文件改了删了不影响)都汇总在这里:按图片 / 文档 / 音视频筛、按文件名搜,点开看大图或下载,「在新对话里用」,单个或批量删除(文件从磁盘上删掉)。从资料库拿到对话里的文件硬链接进那条对话的上传目录,不占双份空间,agent 照常能读。按人隔离,规则同对话:自己的;没主人的对话(飞书群聊等)的归管理员。上传了一直没发出去的一天后清掉;删除会话时立即清理该会话的上传文件和资料库记录,删除原件也会清理复用到其他会话的副本。agent 侧的会话记录仍保留,恢复会话不会恢复已删除的文件。
|
|
106
109
|
- **远程控制**:侧栏「定时任务」下面的「远程控制」,直接操作这台机器的**桌面**和**终端**,上面一键切换;切回对话时连接留在后台(侧栏入口上亮个小绿点),再进来接着用。这台机器没有图形桌面(服务器、NAS)时只有终端。
|
|
107
110
|
- 桌面:走 VNC 协议,网页里用 noVNC 显示,鼠标、键盘、剪贴板都能用,进来时不自动连、点「连接桌面」才连,工具栏上选画质:流畅 / 标准(默认)/ 高清由服务端把画面缩小到长边 1280 / 1920 / 2560、只把变了的地方压成 JPEG 发过来(macOS 屏幕共享只给无损的 ZRLE,5K 屏一整屏 30MB,原样转发隔着公网几秒一帧),原画是原样转发、只适合局域网;远程那边接了几块屏时可以只看其中一块(按系统里的显示器名称选,服务端只截那块再缩,比几块屏拼在一起缩小清楚得多;macOS 的各块屏位置要从屏幕共享发来的画面里学,第一次连上要几秒,原画下不能选);可以缩放到窗口或按原始大小看、全屏(手机上也能,iPhone 上是铺满页面)、「只看不控制」、发送 Ctrl+Alt+Del 之类的组合键。手机上有两种手势(右上角切换,「?」看说明):**触控板模式**(默认)屏幕上有个指针,单指滑动移动、轻点单击、双指轻点右键、长按后拖动是按住左键拖、双指滑动滚动;**触摸模式**点哪就点哪。两种模式都能双指捏合在本地放大画面(放大后小按钮也点得准,右下角「还原」),画面下面一排 Esc / Tab / Ctrl / Alt / Win / 方向键,Ctrl、Alt、Win 点一下会粘住,带给下一个按键或点击;键盘按钮弹出软键盘打字,中文输入法也能用。Linux 上 agent-loft 在有人连时用 x11vnc 共享当前的桌面(Xorg 会话;只听 127.0.0.1、随机端口、每次随机密码,需要 `sudo apt install x11vnc`),没人连着 30 分钟后停掉;macOS 上在 设置 → 远程控制 里改用「已有的 VNC 服务」,接系统自带的屏幕共享:填 VNC 密码,或者屏幕共享没开 VNC 密码时填 Mac 的用户名和登录密码(苹果认证,由服务端登录)。
|
|
@@ -126,7 +129,7 @@ agent-loft service install # 注册为开机自启服务(systemd / laun
|
|
|
126
129
|
|
|
127
130
|
打开 `http://<机器 IP>:8800`(本机用 `http://localhost:8800`):第一次需要输入日志里的设置码,然后建一个管理员账号(用户名默认 `admin`)。设置码找不到的话,直接运行 `agent-loft passwd` 设密码。
|
|
128
131
|
|
|
129
|
-
到 设置 → Agent 检查 Claude Code、Codex 装好、登录了没有:Claude Code 随 agent-loft 一起安装,只需在服务端终端里登录;Codex 可以点「直接在服务器上安装」。设置 → 系统
|
|
132
|
+
到 设置 → Agent 检查 Claude Code、Codex 装好、登录了没有:Claude Code 随 agent-loft 一起安装,只需在服务端终端里登录;Codex 可以点「直接在服务器上安装」。设置 → 系统 里能看到服务端版本,有新版本时点「升级」,服务会在独立目录下载并检查新版,期间旧版仍可使用。系统服务会自动重启,前台运行时需手动重启。新版启动并通过首页、JS、CSS 和 API 检查后生效,验证失败会自动回到原版本。网页显示实际运行版本,`npm ls -g` 显示全局启动入口的安装版本。
|
|
130
133
|
|
|
131
134
|
在外面只用飞书的话不需要任何网络配置(机器人由服务端主动连向飞书)。在外面用网页、系统推送和语音输入需要 HTTPS,见下面的「安全」和[产品介绍里的「从外网访问」](docs/产品介绍.md#从外网访问)。
|
|
132
135
|
|
package/bin/cli.js
CHANGED
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
// 统一入口:agent-loft <start|import|pair|passwd|user|service|doctor>
|
|
3
3
|
//
|
|
4
4
|
// 源码是 TypeScript,用 tsx 的 ESM loader 直接加载,装完即可运行,不需要先 build。
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
5
7
|
import { register } from "tsx/esm/api";
|
|
6
8
|
|
|
9
|
+
// 监督进程被强制终止时,试运行的子进程也应释放端口。
|
|
10
|
+
if (process.env.AGENT_LOFT_UPGRADE_TRIAL && process.connected) {
|
|
11
|
+
process.once("disconnect", () => process.kill(process.pid, "SIGTERM"));
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
const COMMANDS = {
|
|
8
15
|
start: "../src/main.ts",
|
|
9
16
|
import: "../src/cli/import.ts",
|
|
@@ -28,27 +35,41 @@ const USAGE = `agent-loft —— 用飞书 / Web 驱动本机的 Claude Code 和
|
|
|
28
35
|
配置目录:~/.agent-loft(可用 AGENT_LOFT_HOME 覆盖;已有旧的 ~/.im-agent 会继续沿用)
|
|
29
36
|
`;
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
// npm 的命令链接和系统服务始终使用这个入口。源码和普通安装直接启动。
|
|
39
|
+
const releases = fileURLToPath(new URL("../.agent-loft-releases/", import.meta.url));
|
|
40
|
+
const hasReleases = existsSync(releases);
|
|
41
|
+
let handled = false;
|
|
42
|
+
if (hasReleases) {
|
|
43
|
+
register();
|
|
44
|
+
const { launchRelease } = await import("../src/core/upgrade-launcher.ts");
|
|
45
|
+
handled = await launchRelease(releases);
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
process.
|
|
43
|
-
|
|
48
|
+
if (!handled) await runCommand();
|
|
49
|
+
|
|
50
|
+
async function runCommand() {
|
|
51
|
+
const [, , rawCommand, ...rest] = process.argv;
|
|
52
|
+
const command = rawCommand ?? "start";
|
|
53
|
+
|
|
54
|
+
if (command === "-h" || command === "--help" || command === "help") {
|
|
55
|
+
process.stdout.write(USAGE);
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const target = COMMANDS[command];
|
|
60
|
+
if (!target) {
|
|
61
|
+
process.stderr.write(`未知命令:${command}\n\n${USAGE}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
44
64
|
|
|
45
|
-
process.argv = [process.argv[0], process.argv[1], ...rest];
|
|
65
|
+
process.argv = [process.argv[0], process.argv[1], ...rest];
|
|
46
66
|
|
|
47
|
-
register();
|
|
48
|
-
try {
|
|
49
|
-
|
|
50
|
-
} catch (err) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
if (!hasReleases) register();
|
|
68
|
+
try {
|
|
69
|
+
await import(new URL(target, import.meta.url).href);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if (process.env.AGENT_LOFT_DEBUG || process.env.IM_AGENT_DEBUG) throw err;
|
|
72
|
+
process.stderr.write(`${err instanceof Error ? err.message : err}\n`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
54
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-loft",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.128",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
|
|
6
6
|
"keywords": [
|
|
@@ -47,16 +47,22 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@anthropic-ai/claude-agent-sdk": "^0.3.302",
|
|
50
|
+
"@codemirror/collab": "^6.1.1",
|
|
51
|
+
"@codemirror/state": "^6.7.6",
|
|
50
52
|
"@earendil-works/pi-ai": "1.5.0",
|
|
51
53
|
"@earendil-works/pi-coding-agent": "1.5.0",
|
|
52
54
|
"@highlightjs/cdn-assets": "^11.12.0",
|
|
53
55
|
"@larksuiteoapi/node-sdk": "^1.73.0",
|
|
54
56
|
"@novnc/novnc": "^1.7.0",
|
|
57
|
+
"@smithy/core": "^3.39.0",
|
|
58
|
+
"@smithy/signature-v4": "^5.7.5",
|
|
55
59
|
"@tencent-ai/agent-sdk": "^0.3.301",
|
|
60
|
+
"@xmldom/xmldom": "^0.9.12",
|
|
56
61
|
"@xterm/addon-fit": "^0.11.0",
|
|
57
62
|
"@xterm/xterm": "^6.0.0",
|
|
58
63
|
"dompurify": "^3.2.0",
|
|
59
64
|
"echarts": "^6.1.0",
|
|
65
|
+
"ipaddr.js": "^2.5.0",
|
|
60
66
|
"marked": "^16.0.0",
|
|
61
67
|
"mermaid": "^12.2.0",
|
|
62
68
|
"opusscript": "^0.1.1",
|
|
@@ -83,7 +89,6 @@
|
|
|
83
89
|
"@codemirror/lang-yaml": "^6.1.3",
|
|
84
90
|
"@codemirror/language": "^6.13.1",
|
|
85
91
|
"@codemirror/legacy-modes": "^6.5.5",
|
|
86
|
-
"@codemirror/state": "^6.7.6",
|
|
87
92
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
88
93
|
"@codemirror/view": "^6.43.15",
|
|
89
94
|
"@types/node": "^24.10.1",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MEMO_TOOLS } from "../../mcp/memo-tools.js";
|
|
1
2
|
// 一条会话 ↔ 一个常驻的 Claude query。
|
|
2
3
|
//
|
|
3
4
|
// 必须用「流式输入」模式:setModel / interrupt / supportedModels / applyFlagSettings
|
|
@@ -22,7 +23,7 @@ import { usageOf } from "../../core/usage.js";
|
|
|
22
23
|
import { expertAppend, expertSystemPrompt, RICH_REPLY_LINES, searchLabel } from "../../core/expert-prompt.js";
|
|
23
24
|
import { ACCESS_LEVELS, type ExpertAccess } from "../../core/experts.js";
|
|
24
25
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
25
|
-
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
26
|
+
import { MEMOS_MCP_NAME, memosMcpSpawn, SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
26
27
|
import type { PermissionLevel } from "../../core/permission.js";
|
|
27
28
|
import { PLUGIN_NAME, projectCommandNames } from "../../core/skill-runtime.js";
|
|
28
29
|
import { describeAttachments, inlineTextBlocks, readTextAttachments } from "../../core/uploads.js";
|
|
@@ -152,6 +153,7 @@ const MEMORY_TOOLS = new Set(["remember", "forget", "update_memory", "search_mem
|
|
|
152
153
|
/** 定时任务工具:要用户确认的那几个由 agent-loft 自己弹卡(tasks-bridge.ts),这里不再问一遍 */
|
|
153
154
|
const TASK_TOOLS = new Set(["list_tasks", "create_task", "update_task", "delete_task"].map((t) => `mcp__${TASKS_MCP_NAME}__${t}`));
|
|
154
155
|
/** 技能工具:建、改技能前由 agent-loft 自己弹卡(skills-bridge.ts) */
|
|
156
|
+
const MEMO_TOOL_NAMES = new Set(MEMO_TOOLS.map(t => `mcp__${MEMOS_MCP_NAME}__${t.name}`));
|
|
155
157
|
const SKILL_TOOLS = new Set(["list_skills", "get_skill", "create_skill", "update_skill", "skill_request"].map((t) => `mcp__${SKILLS_MCP_NAME}__${t}`));
|
|
156
158
|
/**
|
|
157
159
|
* Claude Code 自带的命令和技能名(supportedCommands 里标了 builtin 的),driver 读命令表时顺手记下。
|
|
@@ -204,6 +206,7 @@ function loftMcp(opts: SessionOptions): Record<string, McpServerConfig> {
|
|
|
204
206
|
? {
|
|
205
207
|
[TASKS_MCP_NAME]: { type: "stdio", ...tasksMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "claude") },
|
|
206
208
|
[SKILLS_MCP_NAME]: { type: "stdio", ...skillsMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "claude") },
|
|
209
|
+
[MEMOS_MCP_NAME]: { type: "stdio", ...memosMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "claude") },
|
|
207
210
|
}
|
|
208
211
|
: {}),
|
|
209
212
|
};
|
|
@@ -232,7 +235,7 @@ export function expertOptions(opts: SessionOptions): Partial<Options> {
|
|
|
232
235
|
const expert = opts.expert;
|
|
233
236
|
if (!expert) {
|
|
234
237
|
const mcpServers = { ...opts.builtinMcp?.mcp, ...loftMcp(opts) };
|
|
235
|
-
const append = [RICH_REPLY_LINES.join("\n"), memory?.prompt, skills?.prompt].filter(Boolean).join("\n\n");
|
|
238
|
+
const append = [RICH_REPLY_LINES.join("\n"), memory?.prompt, skills?.prompt, opts.memoPrompt].filter(Boolean).join("\n\n");
|
|
236
239
|
return {
|
|
237
240
|
systemPrompt: { type: "preset", preset: "claude_code", append, snapshot: false },
|
|
238
241
|
...(opts.builtinMcp && !opts.builtinMcp.inheritMachine ? { strictMcpConfig: true, mcpServers } : Object.keys(mcpServers).length ? { mcpServers } : {}),
|
|
@@ -253,10 +256,10 @@ export function expertOptions(opts: SessionOptions): Partial<Options> {
|
|
|
253
256
|
? {
|
|
254
257
|
type: "preset",
|
|
255
258
|
preset: "claude_code",
|
|
256
|
-
append: [expertAppend(prompt, search, opts.cwd), memory?.prompt, skills?.prompt].filter(Boolean).join("\n\n"),
|
|
259
|
+
append: [expertAppend(prompt, search, opts.cwd), memory?.prompt, skills?.prompt, opts.memoPrompt].filter(Boolean).join("\n\n"),
|
|
257
260
|
snapshot: false,
|
|
258
261
|
}
|
|
259
|
-
: { type: "custom", prompt: expertSystemPrompt(prompt, search, opts.cwd, [memory?.prompt, skills?.prompt].filter(Boolean).join("\n\n") || undefined), snapshot: false };
|
|
262
|
+
: { type: "custom", prompt: expertSystemPrompt(prompt, search, opts.cwd, [memory?.prompt, skills?.prompt, opts.memoPrompt].filter(Boolean).join("\n\n") || undefined), snapshot: false };
|
|
260
263
|
return {
|
|
261
264
|
systemPrompt,
|
|
262
265
|
...plan,
|
|
@@ -554,7 +557,7 @@ export class ClaudeSession implements AgentSession {
|
|
|
554
557
|
// 自家的记忆工具,以及自定义专家配好的联网工具、MCP(没标「调用前询问」的):不问。
|
|
555
558
|
// 不用 allowedTools 放行 —— SDK 会对每个会话打一条「canUseTool 被绕过」的警告
|
|
556
559
|
if (MEMORY_TOOLS.has(toolName) && this.opts.memory) return { behavior: "allow", updatedInput: input };
|
|
557
|
-
if ((TASK_TOOLS.has(toolName) || SKILL_TOOLS.has(toolName)) && this.opts.tasks) return { behavior: "allow", updatedInput: input };
|
|
560
|
+
if ((TASK_TOOLS.has(toolName) || SKILL_TOOLS.has(toolName) || MEMO_TOOL_NAMES.has(toolName)) && this.opts.tasks) return { behavior: "allow", updatedInput: input };
|
|
558
561
|
if (this.expertPreApproved(toolName)) return { behavior: "allow", updatedInput: input };
|
|
559
562
|
|
|
560
563
|
// 提问不是授权:它问的是「你选哪个」
|
|
@@ -45,6 +45,13 @@ type HistoryItem = {
|
|
|
45
45
|
summary?: string[];
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
type HistoryTurn = {
|
|
49
|
+
id?: string;
|
|
50
|
+
items?: HistoryItem[];
|
|
51
|
+
startedAt?: number | null;
|
|
52
|
+
completedAt?: number | null;
|
|
53
|
+
};
|
|
54
|
+
|
|
48
55
|
export class CodexDriver implements AgentDriver {
|
|
49
56
|
readonly id = "codex";
|
|
50
57
|
readonly label = "Codex";
|
|
@@ -122,10 +129,33 @@ export class CodexDriver implements AgentDriver {
|
|
|
122
129
|
/** 本进程里已经生成过(或试过)名称的线程:失败了也不反复重试,每轮结束都会来问 */
|
|
123
130
|
private titled = new Set<string>();
|
|
124
131
|
|
|
132
|
+
private async *readTurns(id: string, itemsView: "full" | "notLoaded" = "full"): AsyncGenerator<HistoryTurn, void> {
|
|
133
|
+
const { thread } = await appServer.call<{
|
|
134
|
+
thread: { historyMode?: string; turns?: HistoryTurn[] };
|
|
135
|
+
}>("thread/read", { threadId: id, includeTurns: true });
|
|
136
|
+
if (thread.historyMode !== "paginated") {
|
|
137
|
+
yield* thread.turns ?? [];
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 分页历史的 thread/read 即使带 includeTurns 也只返回元数据。
|
|
142
|
+
let cursor: string | null = null;
|
|
143
|
+
do {
|
|
144
|
+
const page: { data: HistoryTurn[]; nextCursor: string | null } = await appServer.call("thread/turns/list", {
|
|
145
|
+
threadId: id,
|
|
146
|
+
sortDirection: "asc",
|
|
147
|
+
itemsView,
|
|
148
|
+
...(cursor ? { cursor } : {}),
|
|
149
|
+
});
|
|
150
|
+
yield* page.data;
|
|
151
|
+
cursor = page.nextCursor;
|
|
152
|
+
} while (cursor);
|
|
153
|
+
}
|
|
154
|
+
|
|
125
155
|
/** 按第一轮的问答起个短标题,写回线程(thread/name/set),Codex App 里也能看到 */
|
|
126
156
|
private async generateTitle(id: string, model: string): Promise<string | undefined> {
|
|
127
|
-
const
|
|
128
|
-
const items =
|
|
157
|
+
const { value: turn } = await this.readTurns(id).next();
|
|
158
|
+
const items = turn?.items ?? [];
|
|
129
159
|
const user = items
|
|
130
160
|
.filter((i) => i.type === "userMessage")
|
|
131
161
|
.flatMap((i) => (i.content ?? []).map((c) => (c.type === "text" ? (c.text ?? "") : "")))
|
|
@@ -133,7 +163,7 @@ export class CodexDriver implements AgentDriver {
|
|
|
133
163
|
const question = splitAttachmentNote(stripContext(user)).text.trim();
|
|
134
164
|
if (!question) return undefined;
|
|
135
165
|
const answer = items
|
|
136
|
-
.filter((i) => i.type === "agentMessage" && i.phase !== "commentary"
|
|
166
|
+
.filter((i) => i.text && (i.type === "plan" || (i.type === "agentMessage" && i.phase !== "commentary")))
|
|
137
167
|
.map((i) => i.text)
|
|
138
168
|
.join("\n\n");
|
|
139
169
|
const out = (await this.complete({
|
|
@@ -154,14 +184,8 @@ export class CodexDriver implements AgentDriver {
|
|
|
154
184
|
}
|
|
155
185
|
|
|
156
186
|
async readHistory(id: string): Promise<HistoryMessage[]> {
|
|
157
|
-
const res = await appServer.call<{
|
|
158
|
-
thread: { turns?: { id?: string; items?: HistoryItem[]; startedAt?: number | null; completedAt?: number | null }[] };
|
|
159
|
-
}>(
|
|
160
|
-
"thread/read",
|
|
161
|
-
{ threadId: id, includeTurns: true },
|
|
162
|
-
);
|
|
163
187
|
const out: HistoryMessage[] = [];
|
|
164
|
-
for (const turn of
|
|
188
|
+
for await (const turn of this.readTurns(id)) {
|
|
165
189
|
let assistant: HistoryMessage | null = null;
|
|
166
190
|
const ts = turn.startedAt ? turn.startedAt * 1000 : undefined;
|
|
167
191
|
for (const item of turn.items ?? []) {
|
|
@@ -183,8 +207,8 @@ export class CodexDriver implements AgentDriver {
|
|
|
183
207
|
continue;
|
|
184
208
|
}
|
|
185
209
|
assistant ??= { role: "assistant", text: "", steps: [] };
|
|
186
|
-
if (item.type === "agentMessage" && item.text?.trim()) {
|
|
187
|
-
if (item.phase === "commentary") assistant.steps!.push(`💬 ${summarize(item.text)}`);
|
|
210
|
+
if ((item.type === "agentMessage" || item.type === "plan") && item.text?.trim()) {
|
|
211
|
+
if (item.type === "agentMessage" && item.phase === "commentary") assistant.steps!.push(`💬 ${summarize(item.text)}`);
|
|
188
212
|
else assistant.text += (assistant.text ? "\n\n" : "") + item.text;
|
|
189
213
|
} else if (item.type === "commandExecution" && item.command) {
|
|
190
214
|
assistant.steps!.push(`🔧 ${summarize(item.command, 70)}`);
|
|
@@ -220,11 +244,12 @@ export class CodexDriver implements AgentDriver {
|
|
|
220
244
|
}
|
|
221
245
|
|
|
222
246
|
async rewindTo(id: string, cwd: string, anchor: string): Promise<string | undefined> {
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
247
|
+
let previous: string | undefined;
|
|
248
|
+
for await (const turn of this.readTurns(id, "notLoaded")) {
|
|
249
|
+
if (turn.id === anchor) return previous ? this.forkAt(id, cwd, previous) : undefined;
|
|
250
|
+
previous = turn.id;
|
|
251
|
+
}
|
|
252
|
+
throw new Error("在会话记录里找不到这条消息,请刷新后重试");
|
|
228
253
|
}
|
|
229
254
|
|
|
230
255
|
async listModels(): Promise<ModelInfo[]> {
|
|
@@ -8,7 +8,7 @@ import { config } from "../../core/config.js";
|
|
|
8
8
|
import { contextBlock, stripContext, VOICE_MARK } from "../../core/expert-prompt.js";
|
|
9
9
|
import { ACCESS_LEVELS, type CodexTool, type ExpertAccess, type ExpertRuntime } from "../../core/experts.js";
|
|
10
10
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
11
|
-
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASK_TOOL_TIMEOUT_SEC, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
11
|
+
import { MEMOS_MCP_NAME, memosMcpSpawn, SKILLS_MCP_NAME, skillsMcpSpawn, TASK_TOOL_TIMEOUT_SEC, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
12
12
|
import type { PermissionLevel } from "../../core/permission.js";
|
|
13
13
|
import { codexSkillLines } from "../../core/skill-runtime.js";
|
|
14
14
|
import { describeAttachments, inlineTextBlocks, readTextAttachments } from "../../core/uploads.js";
|
|
@@ -176,7 +176,7 @@ export async function userMcpServers(): Promise<string[]> {
|
|
|
176
176
|
if (userMcpCache && Date.now() - userMcpCache.at < 60_000) return userMcpCache.names;
|
|
177
177
|
try {
|
|
178
178
|
const res = await appServer.call<{ config?: { mcp_servers?: Record<string, unknown> | null } }>("config/read", {});
|
|
179
|
-
const names = Object.keys(res.config?.mcp_servers ?? {}).filter((n) => n !== MEMORY_MCP_NAME && n !== TASKS_MCP_NAME && n !== SKILLS_MCP_NAME);
|
|
179
|
+
const names = Object.keys(res.config?.mcp_servers ?? {}).filter((n) => n !== MEMORY_MCP_NAME && n !== TASKS_MCP_NAME && n !== SKILLS_MCP_NAME && n !== MEMOS_MCP_NAME);
|
|
180
180
|
userMcpCache = { names, at: Date.now() };
|
|
181
181
|
return names;
|
|
182
182
|
} catch (err) {
|
|
@@ -488,6 +488,7 @@ export class CodexSession implements AgentSession {
|
|
|
488
488
|
? {
|
|
489
489
|
[`mcp_servers.${TASKS_MCP_NAME}`]: { ...tasksMcpSpawn(tasks.userId, tasks.convKey, "codex"), tool_timeout_sec: TASK_TOOL_TIMEOUT_SEC },
|
|
490
490
|
[`mcp_servers.${SKILLS_MCP_NAME}`]: { ...skillsMcpSpawn(tasks.userId, tasks.convKey, "codex"), tool_timeout_sec: TASK_TOOL_TIMEOUT_SEC },
|
|
491
|
+
[`mcp_servers.${MEMOS_MCP_NAME}`]: { ...memosMcpSpawn(tasks.userId, tasks.convKey, "codex"), tool_timeout_sec: TASK_TOOL_TIMEOUT_SEC },
|
|
491
492
|
}
|
|
492
493
|
: {}),
|
|
493
494
|
};
|
|
@@ -649,7 +650,7 @@ export class CodexSession implements AgentSession {
|
|
|
649
650
|
// 放在最后:Codex 拿第一条消息的开头当会话预览,不能被这段背景占掉
|
|
650
651
|
const expert = this.opts.expert;
|
|
651
652
|
const context = this.contextPending
|
|
652
|
-
? contextBlock(expert ? { prompt: expert, cwd: this.opts.cwd } : undefined, this.opts.memory?.prompt, codexSkillLines(this.opts.skills))
|
|
653
|
+
? contextBlock(expert ? { prompt: expert, cwd: this.opts.cwd } : undefined, this.opts.memory?.prompt, codexSkillLines(this.opts.skills), this.opts.memoPrompt)
|
|
653
654
|
: "";
|
|
654
655
|
const text = [input.text, note, texts, context].filter(Boolean).join("\n\n");
|
|
655
656
|
const images = input.attachments.filter((a) => a.kind === "image").map((a) => a.path);
|
|
@@ -839,7 +840,7 @@ export class CodexSession implements AgentSession {
|
|
|
839
840
|
// 专家、记忆、技能清单:打字的第一轮会附在消息后面;语音先开口的话,在这里交给背后的 Codex
|
|
840
841
|
const expert = this.opts.expert;
|
|
841
842
|
const context = this.contextPending
|
|
842
|
-
? contextBlock(expert ? { prompt: expert, cwd: this.opts.cwd } : undefined, this.opts.memory?.prompt, codexSkillLines(this.opts.skills))
|
|
843
|
+
? contextBlock(expert ? { prompt: expert, cwd: this.opts.cwd } : undefined, this.opts.memory?.prompt, codexSkillLines(this.opts.skills), this.opts.memoPrompt)
|
|
843
844
|
: "";
|
|
844
845
|
const answer = new Promise<string>((resolve, reject) => {
|
|
845
846
|
this.rt = { answer: resolve, fail: reject };
|
|
@@ -12,7 +12,7 @@ import { RICH_REPLY_LINES } from "../../core/expert-prompt.js";
|
|
|
12
12
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
13
13
|
import type { PermissionLevel } from "../../core/permission.js";
|
|
14
14
|
import { codexSkillLines } from "../../core/skill-runtime.js";
|
|
15
|
-
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
15
|
+
import { MEMOS_MCP_NAME, memosMcpSpawn, SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
16
16
|
import type {
|
|
17
17
|
AgentEvents,
|
|
18
18
|
AgentSession,
|
|
@@ -46,6 +46,7 @@ export function appendPrompt(opts: SessionOptions): string {
|
|
|
46
46
|
RICH_REPLY_LINES.join("\n"),
|
|
47
47
|
"ask_user_question 工具在这里用不了(没有提问界面):需要用户拿主意时,直接在回复里问,然后结束这一轮。",
|
|
48
48
|
opts.memory?.prompt,
|
|
49
|
+
opts.memoPrompt,
|
|
49
50
|
codexSkillLines(opts.skills).join("\n"),
|
|
50
51
|
opts.plan ? PLAN_LINES.join("\n") : "",
|
|
51
52
|
]
|
|
@@ -67,6 +68,7 @@ export function mcpServersOf(opts: SessionOptions): { servers: McpServer[]; skip
|
|
|
67
68
|
if (opts.tasks) {
|
|
68
69
|
stdio(TASKS_MCP_NAME, tasksMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "dsh"));
|
|
69
70
|
stdio(SKILLS_MCP_NAME, skillsMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "dsh"));
|
|
71
|
+
stdio(MEMOS_MCP_NAME, memosMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "dsh"));
|
|
70
72
|
}
|
|
71
73
|
const builtin = opts.builtinMcp;
|
|
72
74
|
for (const [name, spec] of Object.entries(builtin?.mcp ?? {})) {
|
package/src/agents/pi/session.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { ACCESS_LEVELS, type ExpertAccess } from "../../core/experts.js";
|
|
|
17
17
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
18
18
|
import type { PermissionLevel } from "../../core/permission.js";
|
|
19
19
|
import { codexSkillLines } from "../../core/skill-runtime.js";
|
|
20
|
-
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
20
|
+
import { MEMOS_MCP_NAME, memosMcpSpawn, SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
21
21
|
import { describeAttachments, inlineTextBlocks, readTextAttachments } from "../../core/uploads.js";
|
|
22
22
|
import type {
|
|
23
23
|
AgentEvents,
|
|
@@ -58,7 +58,7 @@ export function userMcp(opts: Pick<SessionOptions, "expert" | "builtinMcp">): {
|
|
|
58
58
|
return opts.builtinMcp ? { mcp: opts.builtinMcp.mcp, askMcp: opts.builtinMcp.askMcp } : undefined;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const AGENT_LOFT_MCP = new Set([MEMORY_MCP_NAME, TASKS_MCP_NAME, SKILLS_MCP_NAME]);
|
|
61
|
+
const AGENT_LOFT_MCP = new Set([MEMORY_MCP_NAME, TASKS_MCP_NAME, SKILLS_MCP_NAME, MEMOS_MCP_NAME]);
|
|
62
62
|
|
|
63
63
|
const PLAN_LINES = [
|
|
64
64
|
"## 计划模式",
|
|
@@ -157,7 +157,7 @@ export function buildPrompt(input: UserInput, images: boolean, plan: boolean, no
|
|
|
157
157
|
*/
|
|
158
158
|
export function promptParts(opts: SessionOptions): { system?: string; append: string } {
|
|
159
159
|
const e = opts.expert;
|
|
160
|
-
const skills = codexSkillLines(opts.skills).join("\n");
|
|
160
|
+
const skills = [...codexSkillLines(opts.skills), opts.memoPrompt].filter(Boolean).join("\n");
|
|
161
161
|
const join = (parts: (string | undefined)[]) => parts.filter(Boolean).join("\n\n");
|
|
162
162
|
if (!e) return { append: join([RICH_REPLY_LINES.join("\n"), opts.memory?.prompt, skills]) };
|
|
163
163
|
// pi 没有联网搜索 / 读网页的工具(要联网就给专家挂 MCP)
|
|
@@ -181,6 +181,7 @@ export function mcpServers(opts: SessionOptions): McpEntry[] {
|
|
|
181
181
|
if (opts.tasks) {
|
|
182
182
|
add(TASKS_MCP_NAME, { type: "stdio", ...tasksMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "pi") });
|
|
183
183
|
add(SKILLS_MCP_NAME, { type: "stdio", ...skillsMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "pi") });
|
|
184
|
+
add(MEMOS_MCP_NAME, { type: "stdio", ...memosMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "pi") });
|
|
184
185
|
}
|
|
185
186
|
return out;
|
|
186
187
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MEMO_TOOLS } from "../../mcp/memo-tools.js";
|
|
1
2
|
// 一条会话 ↔ 一个常驻的 WorkBuddy(CodeBuddy Code)CLI 进程。
|
|
2
3
|
//
|
|
3
4
|
// 用的是 SDK 的 V2 会话(unstable_v2_createSession / resumeSession),不是 query():
|
|
@@ -13,7 +14,7 @@ import fs from "node:fs";
|
|
|
13
14
|
import type { McpServerConfig, Message, PermissionMode, PermissionResult, SessionOptions as SdkSessionOptions, UserMessage } from "@tencent-ai/agent-sdk";
|
|
14
15
|
import { RICH_REPLY_LINES } from "../../core/expert-prompt.js";
|
|
15
16
|
import { MEMORY_MCP_NAME, memoryMcpSpawn } from "../../core/memory-mcp.js";
|
|
16
|
-
import { SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
17
|
+
import { MEMOS_MCP_NAME, memosMcpSpawn, SKILLS_MCP_NAME, skillsMcpSpawn, TASKS_MCP_NAME, tasksMcpSpawn } from "../../core/tasks-mcp.js";
|
|
17
18
|
import type { PermissionLevel } from "../../core/permission.js";
|
|
18
19
|
import { codexSkillLines } from "../../core/skill-runtime.js";
|
|
19
20
|
import { describeAttachments } from "../../core/uploads.js";
|
|
@@ -62,6 +63,7 @@ function buildContent(input: UserInput): string | ContentBlock[] {
|
|
|
62
63
|
|
|
63
64
|
const MEMORY_TOOLS = new Set(["remember", "forget", "update_memory", "search_memory", "search_past_chats", "read_past_chat", "memory_timeline"].map((t) => `mcp__${MEMORY_MCP_NAME}__${t}`));
|
|
64
65
|
const TASK_TOOLS = new Set(["list_tasks", "create_task", "update_task", "delete_task"].map((t) => `mcp__${TASKS_MCP_NAME}__${t}`));
|
|
66
|
+
const MEMO_TOOL_NAMES = new Set(MEMO_TOOLS.map(t => `mcp__${MEMOS_MCP_NAME}__${t.name}`));
|
|
65
67
|
const SKILL_TOOLS = new Set(["list_skills", "get_skill", "create_skill", "update_skill", "skill_request"].map((t) => `mcp__${SKILLS_MCP_NAME}__${t}`));
|
|
66
68
|
|
|
67
69
|
/** 内置专家的会话选项:读不读本机 CodeBuddy 配置、挂哪些 MCP、系统提示后面追加什么 */
|
|
@@ -77,10 +79,11 @@ export function sessionOptions(opts: SessionOptions): Partial<SdkSessionOptions>
|
|
|
77
79
|
? {
|
|
78
80
|
[TASKS_MCP_NAME]: { type: "stdio", ...tasksMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "workbuddy") },
|
|
79
81
|
[SKILLS_MCP_NAME]: { type: "stdio", ...skillsMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "workbuddy") },
|
|
82
|
+
[MEMOS_MCP_NAME]: { type: "stdio", ...memosMcpSpawn(opts.tasks.userId, opts.tasks.convKey, "workbuddy") },
|
|
80
83
|
}
|
|
81
84
|
: {}),
|
|
82
85
|
};
|
|
83
|
-
const append = [RICH_REPLY_LINES.join("\n"), memory?.prompt, codexSkillLines(skills).join("\n")].filter(Boolean).join("\n\n");
|
|
86
|
+
const append = [RICH_REPLY_LINES.join("\n"), memory?.prompt, codexSkillLines(skills).join("\n"), opts.memoPrompt].filter(Boolean).join("\n\n");
|
|
84
87
|
// SDK 默认什么本地配置都不读。管理员(或没主人的对话)读全部,和直接用 CLI 一样;
|
|
85
88
|
// 成员只读项目里的 —— 机器主人的 ~/.codebuddy 里的 MCP、技能、规则不给成员用(和 Claude 那边一致)
|
|
86
89
|
const machine = !skills || (skills.admin && skills.machineSkills !== false);
|
|
@@ -304,7 +307,7 @@ export class WorkBuddySession implements AgentSession {
|
|
|
304
307
|
|
|
305
308
|
private async canUseTool(toolName: string, input: Record<string, unknown>): Promise<PermissionResult> {
|
|
306
309
|
if (MEMORY_TOOLS.has(toolName) && this.opts.memory) return { behavior: "allow", updatedInput: input };
|
|
307
|
-
if ((TASK_TOOLS.has(toolName) || SKILL_TOOLS.has(toolName)) && this.opts.tasks) return { behavior: "allow", updatedInput: input };
|
|
310
|
+
if ((TASK_TOOLS.has(toolName) || SKILL_TOOLS.has(toolName) || MEMO_TOOL_NAMES.has(toolName)) && this.opts.tasks) return { behavior: "allow", updatedInput: input };
|
|
308
311
|
const mcp = /^mcp__(.+?)__/.exec(toolName)?.[1];
|
|
309
312
|
const builtin = this.opts.builtinMcp;
|
|
310
313
|
const configured = !!builtin && !!mcp && mcp in builtin.mcp;
|
package/src/channels/web/api.ts
CHANGED
|
@@ -70,7 +70,7 @@ import { WORKBUDDY_ENVIRONMENTS } from "../../agents/workbuddy/sdk.js";
|
|
|
70
70
|
import { listProviders as piProviders, removeCredential as piRemoveCredential, setApiKey as piSetApiKey } from "../../agents/pi/sdk.js";
|
|
71
71
|
import { CUSTOM_APIS as PI_CUSTOM_APIS, deleteCustom as piDeleteCustom, discoverModels as piDiscoverModels, listCustom as piListCustom, saveCustom as piSaveCustom } from "../../agents/pi/custom.js";
|
|
72
72
|
import { answerOAuth as piAnswerOAuth, cancelOAuth as piCancelOAuth, oauthState as piOAuthState, startOAuth as piStartOAuth } from "../../agents/pi/oauth.js";
|
|
73
|
-
import { installCodex, upgrade, useInstalledCodex, versionInfo } from "../../core/upgrade.js";
|
|
73
|
+
import { beginUpgrade, installCodex, upgrade, upgradeStatus, useInstalledCodex, versionInfo } from "../../core/upgrade.js";
|
|
74
74
|
import { feishuBots } from "../feishu/index.js";
|
|
75
75
|
import { weixinStatus } from "../weixin/index.js";
|
|
76
76
|
import { ensureWeixinConversation, weixinExpertChoices } from "../weixin/conversation.js";
|
|
@@ -98,6 +98,7 @@ import { clampLimit, dirsOf, inDir, pageOf, parseCursor, recentPageOf, searchCon
|
|
|
98
98
|
import { clientIp, cookies, HttpError, isHttps, readBody, readJsonBody, SECURITY_HEADERS, sendJson, setServerTiming } from "./http.js";
|
|
99
99
|
import { syncApi } from "./memory-sync-api.js";
|
|
100
100
|
import { handleTasksApi } from "./tasks-api.js";
|
|
101
|
+
import { handleMemosApi } from "./memos-api.js";
|
|
101
102
|
import { handleLibraryApi } from "./library-api.js";
|
|
102
103
|
import { attachToConversation, canSeeFile, deleteConversationFiles, getLibraryFile } from "../../core/library.js";
|
|
103
104
|
import { handleSkillsApi } from "./skills-api.js";
|
|
@@ -844,6 +845,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
844
845
|
|
|
845
846
|
// ----- 定时任务 -----
|
|
846
847
|
if (p.startsWith("/api/tasks") && (await handleTasksApi(req, res, p, user))) return;
|
|
848
|
+
if (p.startsWith("/api/memos/")) return handleMemosApi(req, res, url, user, () => currentUser(req));
|
|
847
849
|
if (p.startsWith("/api/library") && (await handleLibraryApi(req, res, p, user))) return;
|
|
848
850
|
if (p.startsWith("/api/skills") && (await handleSkillsApi(req, res, url, user))) return;
|
|
849
851
|
if ((p === "/api/agents/defaults" || p.startsWith("/api/experts") || p.startsWith("/api/mcp")) && (await handleExpertsApi(req, res, p, user))) return;
|
|
@@ -1319,7 +1321,16 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
1319
1321
|
sendJson(res, 200, await versionInfo(url.searchParams.get("refresh") === "1"));
|
|
1320
1322
|
return;
|
|
1321
1323
|
}
|
|
1324
|
+
if (p === "/api/server/upgrade" && method === "GET") {
|
|
1325
|
+
sendJson(res, 200, upgradeStatus());
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1322
1328
|
if (p === "/api/server/upgrade" && method === "POST") {
|
|
1329
|
+
if (url.searchParams.has("background")) {
|
|
1330
|
+
beginUpgrade();
|
|
1331
|
+
sendJson(res, 202, upgradeStatus());
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1323
1334
|
sendJson(res, 200, await upgrade().catch((err) => {
|
|
1324
1335
|
throw new HttpError(400, err instanceof Error ? err.message : String(err));
|
|
1325
1336
|
}));
|