agent-loft 0.2.49 → 0.2.51
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 +19 -14
- package/package.json +1 -1
- package/src/agents/claude/driver.ts +11 -0
- package/src/agents/claude/session.ts +9 -0
- package/src/agents/codex/driver.ts +9 -0
- package/src/agents/codex/session.ts +10 -0
- package/src/channels/web/api.ts +96 -7
- package/src/channels/web/conv-pages.ts +37 -0
- package/src/channels/web/experts-api.ts +20 -2
- package/src/core/chat-history.ts +19 -0
- package/src/core/experts.ts +23 -1
- package/src/core/hub.ts +117 -4
- package/src/core/memory-curator.ts +7 -11
- package/src/core/types.ts +8 -2
- package/web/css/experts.css +121 -0
- package/web/css/messages.css +40 -2
- package/web/css/overlay.css +49 -11
- package/web/css/search.css +218 -0
- package/web/css/sidebar.css +100 -54
- package/web/css/topbar.css +131 -4
- package/web/index.html +1 -0
- package/web/lib/dom.js +7 -14
- package/web/lib/overlay.js +2 -2
- package/web/lib/time.js +6 -2
- package/web/settings/commands.js +5 -2
- package/web/settings/experts.js +222 -44
- package/web/settings/memory.js +2 -2
- package/web/state.js +2 -0
- package/web/views/composer.js +32 -13
- package/web/views/conv-actions.js +71 -7
- package/web/views/conv-search.js +206 -0
- package/web/views/experts.js +4 -3
- package/web/views/layout.js +9 -2
- package/web/views/messages.js +74 -7
- package/web/views/msg-nav.js +26 -3
- package/web/views/quota.js +13 -10
- package/web/views/sidebar.js +87 -49
- package/web/views/slash.js +63 -12
- package/web/views/topbar.js +106 -13
package/src/core/hub.ts
CHANGED
|
@@ -11,6 +11,7 @@ import crypto from "node:crypto";
|
|
|
11
11
|
import { EventEmitter } from "node:events";
|
|
12
12
|
import { config, onConfigChange, resolveWorkspacePath } from "./config.js";
|
|
13
13
|
import { attachFooters, copyFooters, formatDuration, recordFooter } from "./footers.js";
|
|
14
|
+
import { removeHistoryRecord, replaceConversationRecords } from "./chat-history.js";
|
|
14
15
|
import { flushUsage, recordUsage, usageOf, type UsageTotals } from "./usage.js";
|
|
15
16
|
import { interactions, SETTLEMENT_LABEL } from "./interactions.js";
|
|
16
17
|
import {
|
|
@@ -49,7 +50,7 @@ import { buildCatalog, expandCustomCommand, type AgentCommand, type CommandEntry
|
|
|
49
50
|
import { helpText, type ParsedCommand } from "./commands.js";
|
|
50
51
|
import { listScheduled } from "./scheduled.js";
|
|
51
52
|
import { expertSystemPrompt, searchLabel, stripContext } from "./expert-prompt.js";
|
|
52
|
-
import { expertEvents, expertRuntime, getExpert, isBuiltin, listExperts, type ExpertRuntime } from "./experts.js";
|
|
53
|
+
import { avatarUrl, expertEvents, expertRuntime, getExpert, isBuiltin, listExperts, type ExpertRuntime } from "./experts.js";
|
|
53
54
|
import { mcpEvents } from "./mcp.js";
|
|
54
55
|
import { isMachineCommand, sessionSkills } from "./skill-runtime.js";
|
|
55
56
|
import { skillEvents } from "./skills.js";
|
|
@@ -72,7 +73,9 @@ export type ConvEvent =
|
|
|
72
73
|
/** id:这条消息的编号,后面的 queue 事件按它对上;queued:收到时前面还有在跑 / 在等的,要排队 */
|
|
73
74
|
| { type: "user"; text: string; attachments: string[]; files?: AttachmentInfo[]; origin: Origin; id?: string; queued?: boolean }
|
|
74
75
|
/** 排队的消息:轮到它了(started,或者被当成提问的回答用掉了),或者没发出去(dropped:停止、会话切换…) */
|
|
75
|
-
| { type: "queue"; id: string; state: "started" | "dropped" }
|
|
76
|
+
| { type: "queue"; id: string; state: "started" | "dropped" | "removed" }
|
|
77
|
+
| { type: "user_anchor"; id: string; anchor: string }
|
|
78
|
+
| { type: "history_reset" }
|
|
76
79
|
/**
|
|
77
80
|
* 这里弹出过一张授权 / 提问卡(内容和状态在 interactions 里按 id 查)。只是给卡片在对话里占个位置:
|
|
78
81
|
* 刷新页面时进行中的这一轮靠重放事件画出来,没有它卡片就丢了
|
|
@@ -181,6 +184,8 @@ export type ExpertBadge = {
|
|
|
181
184
|
id: string;
|
|
182
185
|
name: string;
|
|
183
186
|
icon?: string;
|
|
187
|
+
/** 头像地址(/api/experts/<id>/avatar?v=...) */
|
|
188
|
+
avatar?: string;
|
|
184
189
|
color?: string;
|
|
185
190
|
builtin?: true;
|
|
186
191
|
/** 自定义专家的权限(只能联网的不显示工作目录) */
|
|
@@ -227,9 +232,10 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
227
232
|
* 用来告诉页面哪条消息轮到了 / 被丢了,以及「打断并发送」时把哪条挪到前面
|
|
228
233
|
*/
|
|
229
234
|
private turnFifo = new Map<string, { id: string; input: UserInput; queued: boolean }[]>();
|
|
235
|
+
private pendingInputs = new Map<string, Map<string, { input: UserInput; cancelled: boolean }>>();
|
|
236
|
+
private rewinding = new Set<string>();
|
|
230
237
|
/** 收到了、还在串行队列里没交给 agent 的消息数:这时再来的消息也算排队 */
|
|
231
238
|
private waitingSends = new Map<string, number>();
|
|
232
|
-
private msgSeq = 0;
|
|
233
239
|
private announced = new Set<string>();
|
|
234
240
|
/** 每条会话因缓冲区溢出被丢掉的最后一个 seq */
|
|
235
241
|
private truncated = new Map<string, number>();
|
|
@@ -400,6 +406,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
400
406
|
name: e.name,
|
|
401
407
|
access: e.access,
|
|
402
408
|
...(e.icon ? { icon: e.icon } : {}),
|
|
409
|
+
...(e.avatar ? { avatar: avatarUrl(e) } : {}),
|
|
403
410
|
...(e.color ? { color: e.color } : {}),
|
|
404
411
|
...(e.welcome ? { welcome: e.welcome } : {}),
|
|
405
412
|
...(e.quickPrompts.length ? { quickPrompts: e.quickPrompts } : {}),
|
|
@@ -662,6 +669,10 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
662
669
|
...(skills ? { skills } : {}),
|
|
663
670
|
},
|
|
664
671
|
{
|
|
672
|
+
onUserAnchor: (input, anchor) => {
|
|
673
|
+
if (!alive() || !input.id) return;
|
|
674
|
+
this.emitEvent(key, { type: "user_anchor", id: input.id, anchor });
|
|
675
|
+
},
|
|
665
676
|
onTurnStart: () => {
|
|
666
677
|
if (!alive()) return;
|
|
667
678
|
this.emitEvent(key, { type: "turn_start" });
|
|
@@ -920,6 +931,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
920
931
|
* 才调到这里时必须传:下载期间点了停止,这条消息就不该再发出去。
|
|
921
932
|
*/
|
|
922
933
|
send(key: string, input: UserInput, origin: Origin, gen?: InputGen, opts: { task?: TaskTurn } = {}): void {
|
|
934
|
+
if (this.rewinding.has(key)) throw new Error("会话正在回退,请稍后发送");
|
|
923
935
|
const conv = getConversation(key);
|
|
924
936
|
if (!conv) throw new Error(`会话不存在:${key}`);
|
|
925
937
|
const task = opts.task;
|
|
@@ -956,9 +968,10 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
956
968
|
attachments: input.attachments.map((a) => `${KIND_LABEL[a.kind]} ${a.name}`),
|
|
957
969
|
files: input.attachments.map(attachmentInfo),
|
|
958
970
|
origin,
|
|
959
|
-
id:
|
|
971
|
+
id: crypto.randomUUID(),
|
|
960
972
|
queued: false,
|
|
961
973
|
};
|
|
974
|
+
input = { ...input, id: shown.id };
|
|
962
975
|
const by = `${origin.name ?? "用户"}以消息作答`;
|
|
963
976
|
|
|
964
977
|
/**
|
|
@@ -995,6 +1008,10 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
995
1008
|
// 前面有在跑的、或者还在串行队列里等着的:这条要排队
|
|
996
1009
|
shown.queued = this.isBusy(key) || (this.waitingSends.get(key) ?? 0) > 0;
|
|
997
1010
|
this.emitEvent(key, shown);
|
|
1011
|
+
const waiting = { input, cancelled: false };
|
|
1012
|
+
let pendingInputs = this.pendingInputs.get(key);
|
|
1013
|
+
if (!pendingInputs) this.pendingInputs.set(key, (pendingInputs = new Map()));
|
|
1014
|
+
pendingInputs.set(shown.id, waiting);
|
|
998
1015
|
const dropped = () => this.emitEvent(key, { type: "queue", id: shown.id, state: "dropped" });
|
|
999
1016
|
const gone = (text: string) => {
|
|
1000
1017
|
dropped();
|
|
@@ -1003,6 +1020,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1003
1020
|
this.waitingSends.set(key, (this.waitingSends.get(key) ?? 0) + 1);
|
|
1004
1021
|
void this.serial(key, async () => {
|
|
1005
1022
|
try {
|
|
1023
|
+
if (waiting.cancelled) return;
|
|
1006
1024
|
if (cancelled()) return gone("没有发出(停止了或者会话被切换了)");
|
|
1007
1025
|
if (questionAtEntry && tryAnswer(questionAtEntry)) {
|
|
1008
1026
|
// 被当成提问的回答用掉了:不再排队
|
|
@@ -1016,16 +1034,20 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1016
1034
|
const expired = !task && !switchedAfterEntry && ttl > 0 && Date.now() - lastActive > ttl;
|
|
1017
1035
|
if (expired) {
|
|
1018
1036
|
await this.expireNow(key);
|
|
1037
|
+
if (waiting.cancelled) return;
|
|
1019
1038
|
// 清理要等旧会话 dispose,期间可能又点了停止
|
|
1020
1039
|
if (cancelled()) return dropped();
|
|
1021
1040
|
}
|
|
1022
1041
|
const blocked = await this.blockedSlash(key, input.text);
|
|
1042
|
+
if (waiting.cancelled) return;
|
|
1023
1043
|
if (blocked) {
|
|
1024
1044
|
this.emitEvent(key, { type: "notice", text: blocked });
|
|
1025
1045
|
return gone(blocked);
|
|
1026
1046
|
}
|
|
1027
1047
|
this.sendNow(key, input, task ?? null, { id: shown.id, queued: shown.queued });
|
|
1028
1048
|
} finally {
|
|
1049
|
+
pendingInputs.delete(shown.id);
|
|
1050
|
+
if (!pendingInputs.size) this.pendingInputs.delete(key);
|
|
1029
1051
|
this.waitingSends.set(key, Math.max(0, (this.waitingSends.get(key) ?? 1) - 1));
|
|
1030
1052
|
}
|
|
1031
1053
|
});
|
|
@@ -1358,6 +1380,97 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
|
|
|
1358
1380
|
return `已换成专家「${hit.label}」,开了新会话。`;
|
|
1359
1381
|
}
|
|
1360
1382
|
|
|
1383
|
+
/** 撤销一条还没开始的输入;当前回复和其他排队消息继续 */
|
|
1384
|
+
cancelQueued(key: string, id: string): { text: string; attachments: AttachmentInfo[] } {
|
|
1385
|
+
if (this.rewinding.has(key)) throw new Error("会话正在回退,请稍后重试");
|
|
1386
|
+
const fifo = this.turnFifo.get(key) ?? [];
|
|
1387
|
+
const index = fifo.findIndex((entry) => entry.id === id);
|
|
1388
|
+
let input: UserInput;
|
|
1389
|
+
if (index >= 0) {
|
|
1390
|
+
if (index === 0 || !this.live.get(key)?.session.cancelQueued?.(fifo[index]!.input)) {
|
|
1391
|
+
throw new Error("这条消息已经开始处理了,请使用「回退到此处」");
|
|
1392
|
+
}
|
|
1393
|
+
input = fifo.splice(index, 1)[0]!.input;
|
|
1394
|
+
const tag = this.turnTags.get(key)?.splice(index, 1)[0];
|
|
1395
|
+
if (tag) this.emit("task", { ...tag, key, status: "interrupted", text: "排队消息已撤销" });
|
|
1396
|
+
this.setInflight(key, (this.inflight.get(key) ?? 1) - 1);
|
|
1397
|
+
} else {
|
|
1398
|
+
const waiting = this.pendingInputs.get(key)?.get(id);
|
|
1399
|
+
const shown = (this.buffers.get(key) ?? []).find((e) => e.ev.type === "user" && e.ev.id === id);
|
|
1400
|
+
if (!waiting || waiting.cancelled || shown?.ev.type !== "user" || !shown.ev.queued) {
|
|
1401
|
+
throw new Error("这条消息已经不在排队了");
|
|
1402
|
+
}
|
|
1403
|
+
waiting.cancelled = true;
|
|
1404
|
+
input = waiting.input;
|
|
1405
|
+
}
|
|
1406
|
+
this.buffers.set(key, (this.buffers.get(key) ?? []).filter(({ ev }) => !("id" in ev && ev.id === id && ["user", "queue", "user_anchor"].includes(ev.type))));
|
|
1407
|
+
const conv = getConversation(key);
|
|
1408
|
+
const owner = conv && memoryOwnerOf(conv);
|
|
1409
|
+
if (owner) removeHistoryRecord(owner, key, id);
|
|
1410
|
+
this.emitEvent(key, { type: "queue", id, state: "removed" });
|
|
1411
|
+
return { text: stripContext(input.text), attachments: input.attachments.map(attachmentInfo) };
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
/** 回退的是对话上下文,已经执行过的文件修改不在此操作里回滚 */
|
|
1415
|
+
async rewind(key: string, target: { id?: string; anchor?: string; sessionId?: string }): Promise<{ text: string; attachments: AttachmentInfo[]; queued?: boolean }> {
|
|
1416
|
+
if (this.rewinding.has(key)) throw new Error("会话正在回退,请稍后重试");
|
|
1417
|
+
const fifo = this.turnFifo.get(key) ?? [];
|
|
1418
|
+
const queued = target.id && (fifo.findIndex((entry) => entry.id === target.id) > 0 || this.pendingInputs.get(key)?.has(target.id));
|
|
1419
|
+
if (queued) {
|
|
1420
|
+
const users = (this.buffers.get(key) ?? []).flatMap(({ ev }) => ev.type === "user" && ev.id ? [ev.id] : []);
|
|
1421
|
+
const index = users.indexOf(target.id!);
|
|
1422
|
+
if (index < 0) throw new Error("找不到这条排队消息,请刷新后重试");
|
|
1423
|
+
const draft = this.cancelQueued(key, target.id!);
|
|
1424
|
+
for (const id of users.slice(index + 1)) {
|
|
1425
|
+
if (fifo.findIndex((entry) => entry.id === id) > 0 || this.pendingInputs.get(key)?.has(id)) this.cancelQueued(key, id);
|
|
1426
|
+
}
|
|
1427
|
+
return { ...draft, queued: true };
|
|
1428
|
+
}
|
|
1429
|
+
this.rewinding.add(key);
|
|
1430
|
+
try {
|
|
1431
|
+
return await this.switchOp(key, async (op) => {
|
|
1432
|
+
const conv = getConversation(key);
|
|
1433
|
+
if (!conv) throw new Error("会话不存在");
|
|
1434
|
+
const driver = this.requireDriver(conv.agent);
|
|
1435
|
+
if (!driver.rewindTo) throw new Error(`${driver.label} 暂不支持回退`);
|
|
1436
|
+
const source = agentBinding(conv).sessionId;
|
|
1437
|
+
if (target.sessionId && target.sessionId !== source) throw new Error("会话已经变化,请刷新后重试");
|
|
1438
|
+
const buf = this.buffers.get(key) ?? [];
|
|
1439
|
+
const anchorEvent = buf.findLast(({ ev }) => ev.type === "user_anchor" && ev.id === target.id)?.ev;
|
|
1440
|
+
const anchor = target.anchor ?? (anchorEvent?.type === "user_anchor" ? anchorEvent.anchor : undefined);
|
|
1441
|
+
const history = source ? attachFooters(source, await withTimeout(driver.readHistory(source, conv.cwd), "读取回退位置")) : [];
|
|
1442
|
+
const index = anchor ? history.findIndex((m) => m.role === "user" && m.anchor === anchor) : -1;
|
|
1443
|
+
const live = buf.find(({ ev }) => ev.type === "user" && ev.id === target.id)?.ev;
|
|
1444
|
+
// 第一条尚未写入 agent 记录:清空当前会话即可,不丢失更早的上下文
|
|
1445
|
+
const firstUnwritten = history.length === 0 && live?.type === "user";
|
|
1446
|
+
if (index < 0 && !firstUnwritten) throw new Error("在会话记录里找不到这条消息,请稍后刷新重试");
|
|
1447
|
+
const message = index >= 0 ? history[index]! : { text: live!.type === "user" ? live!.text : "", attachments: live!.type === "user" ? live!.files : [] };
|
|
1448
|
+
const kept = index >= 0 ? history.slice(0, index) : [];
|
|
1449
|
+
await this.drop(key, "对话已回退");
|
|
1450
|
+
const sessionId = index > 0 && source && anchor ? await withTimeout(driver.rewindTo(source, conv.cwd, anchor), "回退会话") : undefined;
|
|
1451
|
+
this.markSwitched(key, op.seq);
|
|
1452
|
+
updateAgentBinding(key, conv.agent, { sessionId, forkFrom: undefined });
|
|
1453
|
+
if (sessionId) {
|
|
1454
|
+
recordSessionOwner(sessionId, conv.owner);
|
|
1455
|
+
for (const m of kept) if (m.footer) recordFooter(sessionId, m.text, m.footer);
|
|
1456
|
+
}
|
|
1457
|
+
const owner = memoryOwnerOf(conv);
|
|
1458
|
+
if (owner) replaceConversationRecords(owner, key, kept.flatMap((m) => {
|
|
1459
|
+
if (m.role === "question") return [];
|
|
1460
|
+
const text = [m.text, m.attachments?.length ? `(附件:${m.attachments.map((a) => a.name).join("、")})` : ""].filter(Boolean).join("\n");
|
|
1461
|
+
return text.trim() ? [{ k: key, a: conv.agent, r: m.role === "user" ? "u" as const : "a" as const, t: text, ts: m.ts ?? conv.createdAt }] : [];
|
|
1462
|
+
}));
|
|
1463
|
+
this.buffers.delete(key);
|
|
1464
|
+
this.truncated.set(key, this.currentSeq());
|
|
1465
|
+
this.emitEvent(key, { type: "history_reset" });
|
|
1466
|
+
this.emitEvent(key, { type: "meta" });
|
|
1467
|
+
return { text: message.text, attachments: message.attachments ?? [] };
|
|
1468
|
+
});
|
|
1469
|
+
} finally {
|
|
1470
|
+
this.rewinding.delete(key);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1361
1474
|
async stop(key: string): Promise<string> {
|
|
1362
1475
|
// 不进串行队列:停止要立刻生效。排队中还没送出的消息靠代次作废
|
|
1363
1476
|
this.stopGen.set(key, (this.stopGen.get(key) ?? 0) + 1);
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 三件事:
|
|
4
4
|
// 1. 录入(startHistoryCapture):hub 的事件流里,有主人的对话的每句话(用户说的、agent 的最终回复)
|
|
5
|
-
// 记进主人的聊天记录索引(chat-history.ts
|
|
5
|
+
// 记进主人的聊天记录索引(chat-history.ts)。不管开没开记忆都记:侧栏的「搜索」要搜聊天内容。
|
|
6
|
+
// 没开记忆(或者关了整理)时记进来的话随即标成整理过了,之后再打开记忆也不会一下子整理一大堆旧的。
|
|
6
7
|
// 2. 回填(backfill):第一次用时,把已有对话从 agent 的记录里读一遍进索引,每人只做一次。
|
|
7
8
|
// 回填进来的只供搜索,不拿去整理 —— 一次整理几百段旧对话太费额度。
|
|
8
9
|
// 3. 整理:把上次整理之后新说的话交给模型(用户在记忆设置里选 agent 和模型,默认最省的),
|
|
@@ -51,11 +52,6 @@ const MAX_CHANGES = 5;
|
|
|
51
52
|
|
|
52
53
|
let capturing = false;
|
|
53
54
|
|
|
54
|
-
/** 记不记这个用户的聊天:开着记忆,并且整理和「参考以前的聊天」至少开了一个 */
|
|
55
|
-
function wants(memory: UserMemory): boolean {
|
|
56
|
-
return memory.enabled && (memory.curate.when !== "off" || memory.chatHistory);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
55
|
export function startHistoryCapture(): void {
|
|
60
56
|
if (capturing) return;
|
|
61
57
|
capturing = true;
|
|
@@ -66,13 +62,13 @@ export function startHistoryCapture(): void {
|
|
|
66
62
|
const conv = hub.conversation(env.key);
|
|
67
63
|
if (!conv || conv.hidden) return;
|
|
68
64
|
const owner = memoryOwnerOf(conv);
|
|
69
|
-
if (!owner
|
|
65
|
+
if (!owner) return;
|
|
70
66
|
const text =
|
|
71
67
|
ev.type === "user"
|
|
72
68
|
? [ev.text, ev.attachments.length ? `(附件:${ev.attachments.join("、")})` : ""].filter(Boolean).join("\n")
|
|
73
69
|
: ev.text;
|
|
74
70
|
if (!text.trim()) return;
|
|
75
|
-
appendRecords(owner, [{ k: env.key, a: conv.agent, r: ev.type === "user" ? "u" : "a", t: text, ts: env.ts }]);
|
|
71
|
+
appendRecords(owner, [{ k: env.key, a: conv.agent, r: ev.type === "user" ? "u" : "a", t: text, ts: env.ts, ...(ev.type === "user" && ev.id ? { id: ev.id } : {}) }]);
|
|
76
72
|
} catch (err) {
|
|
77
73
|
console.warn("[记忆] 记录聊天失败:", err instanceof Error ? err.message : err);
|
|
78
74
|
}
|
|
@@ -396,11 +392,11 @@ export function sweepOnce(opts: { now?: number } = {}): Promise<void> {
|
|
|
396
392
|
const now = opts.now ?? Date.now();
|
|
397
393
|
for (const user of activeUsers()) {
|
|
398
394
|
try {
|
|
395
|
+
// 回填不看记忆开关:侧栏搜索也要搜以前的聊天
|
|
396
|
+
if (!readMeta(user.id).backfilled) await backfill(user.id);
|
|
399
397
|
const memory = readMemory(user.id);
|
|
400
|
-
if (!memory.enabled) continue;
|
|
401
|
-
if (memory.chatHistory && !readMeta(user.id).backfilled) await backfill(user.id);
|
|
402
398
|
const c = memory.curate;
|
|
403
|
-
if (c.when === "off") {
|
|
399
|
+
if (!memory.enabled || c.when === "off") {
|
|
404
400
|
// 不整理:聊过的不攒着,之后再打开也不会一下子整理一大堆旧的
|
|
405
401
|
for (const p of pendingConversations(user.id, 0, now)) markExtracted(user.id, p.key, p.last);
|
|
406
402
|
} else if (c.when === "idle") {
|
package/src/core/types.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type SavedAttachment = {
|
|
|
17
17
|
durationMs?: number;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type UserInput = { text: string; attachments: SavedAttachment[] };
|
|
20
|
+
export type UserInput = { text: string; attachments: SavedAttachment[]; id?: string };
|
|
21
21
|
|
|
22
22
|
/** 给前端展示用的附件:能预览 / 下载(path 只在上传目录里有效,见 uploads.resolveUploadFile) */
|
|
23
23
|
export type AttachmentInfo = { kind: AttachmentKind; name: string; path: string; size?: number };
|
|
@@ -88,6 +88,8 @@ export type TurnResult = {
|
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
export type AgentEvents = {
|
|
91
|
+
/** 用户消息在 agent 记录里的位置,用于回退 */
|
|
92
|
+
onUserAnchor?: (input: UserInput, anchor: string) => void;
|
|
91
93
|
/** 一轮开始(agent 真正开始处理) */
|
|
92
94
|
onTurnStart?: () => void;
|
|
93
95
|
/** 过程信息:思考、工具调用等,一行摘要 */
|
|
@@ -178,7 +180,7 @@ export type HistoryMessage = {
|
|
|
178
180
|
todos?: TodoItem[];
|
|
179
181
|
/** 毫秒时间戳;助手消息是这一轮结束的时间 */
|
|
180
182
|
ts?: number;
|
|
181
|
-
/**
|
|
183
|
+
/** 消息在 agent 记录里的位置:用户消息用于回退,助手消息用于分叉 */
|
|
182
184
|
anchor?: string;
|
|
183
185
|
/** 助手消息:这一轮的用时 / 费用 / tokens(agent-loft 自己记的,agent 记录里没有) */
|
|
184
186
|
footer?: string;
|
|
@@ -242,6 +244,8 @@ export type InterruptOptions = { keepQueue?: boolean; first?: UserInput };
|
|
|
242
244
|
export interface AgentSession {
|
|
243
245
|
readonly sessionId: string | undefined;
|
|
244
246
|
send(input: UserInput): void;
|
|
247
|
+
/** 仅移除尚未开始的指定输入,不中断当前回复 */
|
|
248
|
+
cancelQueued?(input: UserInput): boolean;
|
|
245
249
|
interrupt(opts?: InterruptOptions): Promise<void>;
|
|
246
250
|
setModel(model?: string, effort?: string): Promise<void>;
|
|
247
251
|
describeRuntime(): Promise<RuntimeInfo>;
|
|
@@ -279,6 +283,8 @@ export interface AgentDriver {
|
|
|
279
283
|
* 那条回复为止(含),不给就整条复制。原会话不受影响。
|
|
280
284
|
*/
|
|
281
285
|
forkAt?(id: string, cwd: string, anchor?: string): Promise<string>;
|
|
286
|
+
/** 保留指定用户消息之前的上下文;第一条返回 undefined,下一次发送新建会话 */
|
|
287
|
+
rewindTo?(id: string, cwd: string, anchor: string): Promise<string | undefined>;
|
|
282
288
|
/** 有的 agent(Claude)要借一个活着的会话才能问到模型列表 */
|
|
283
289
|
listModels(session: AgentSession): Promise<ModelInfo[]>;
|
|
284
290
|
/** 不依赖会话的模型列表,设置页的下拉框用 */
|
package/web/css/experts.css
CHANGED
|
@@ -101,3 +101,124 @@
|
|
|
101
101
|
.field-group {
|
|
102
102
|
display: contents;
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
/* ---- 专家头像 ---- */
|
|
106
|
+
|
|
107
|
+
/* 头像在哪儿都是圆的,默认和引擎图标一样大(18px),各处再按需要调 */
|
|
108
|
+
.expert-avatar {
|
|
109
|
+
display: inline-grid;
|
|
110
|
+
place-items: center;
|
|
111
|
+
flex-shrink: 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.expert-avatar img {
|
|
115
|
+
display: block;
|
|
116
|
+
width: 18px;
|
|
117
|
+
height: 18px;
|
|
118
|
+
border-radius: 50%;
|
|
119
|
+
object-fit: cover;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.hero-logo.expert-avatar img {
|
|
123
|
+
width: 64px;
|
|
124
|
+
height: 64px;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.ctx-item .expert-avatar img,
|
|
128
|
+
.hit-icon .expert-avatar img {
|
|
129
|
+
width: 16px;
|
|
130
|
+
height: 16px;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.search-chip .expert-avatar img,
|
|
134
|
+
.dialog-sub .expert-avatar img {
|
|
135
|
+
width: 14px;
|
|
136
|
+
height: 14px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.conv-item .expert-mark img {
|
|
140
|
+
display: block;
|
|
141
|
+
width: 14px;
|
|
142
|
+
height: 14px;
|
|
143
|
+
border-radius: 50%;
|
|
144
|
+
object-fit: cover;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@media (max-width: 768px) {
|
|
148
|
+
.hero-logo.expert-avatar img {
|
|
149
|
+
width: 52px;
|
|
150
|
+
height: 52px;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* 设置页卡片标题前的图标 */
|
|
155
|
+
.expert-card-icon {
|
|
156
|
+
display: inline-grid;
|
|
157
|
+
vertical-align: -3px;
|
|
158
|
+
margin-right: 8px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.expert-card-icon svg,
|
|
162
|
+
.expert-card-icon img {
|
|
163
|
+
width: 18px;
|
|
164
|
+
height: 18px;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.expert-card-icon.expert-emoji {
|
|
168
|
+
font-size: 15px;
|
|
169
|
+
width: auto;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* 编辑器里的头像:圆形预览,点一下上传 */
|
|
173
|
+
.expert-form .avatar-row > .field:first-child {
|
|
174
|
+
flex: 0 0 auto;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.avatar-field {
|
|
178
|
+
display: flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
gap: 10px;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.avatar-preview {
|
|
184
|
+
width: 56px;
|
|
185
|
+
height: 56px;
|
|
186
|
+
border-radius: 50%;
|
|
187
|
+
border: 1px dashed var(--border);
|
|
188
|
+
background: var(--bg-soft);
|
|
189
|
+
display: grid;
|
|
190
|
+
place-items: center;
|
|
191
|
+
overflow: hidden;
|
|
192
|
+
flex-shrink: 0;
|
|
193
|
+
color: var(--fg-soft);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.avatar-preview:hover {
|
|
197
|
+
border-color: var(--fg-faint);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.avatar-preview img {
|
|
201
|
+
width: 100%;
|
|
202
|
+
height: 100%;
|
|
203
|
+
object-fit: cover;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.avatar-preview svg {
|
|
207
|
+
width: 28px;
|
|
208
|
+
height: 28px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.avatar-emoji {
|
|
212
|
+
font-size: 28px;
|
|
213
|
+
line-height: 1;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.avatar-btns {
|
|
217
|
+
display: flex;
|
|
218
|
+
flex-direction: column;
|
|
219
|
+
gap: 6px;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.avatar-btns .btn[hidden] {
|
|
223
|
+
display: none;
|
|
224
|
+
}
|
package/web/css/messages.css
CHANGED
|
@@ -1042,9 +1042,36 @@ a.att-file:hover {
|
|
|
1042
1042
|
font-weight: 500;
|
|
1043
1043
|
}
|
|
1044
1044
|
|
|
1045
|
-
/*
|
|
1046
|
-
@media (max-width: 768px) {
|
|
1045
|
+
/* 手机和触屏:滚动时显示,停止后淡出;点击刻度直接跳转 */
|
|
1046
|
+
@media (max-width: 768px), (hover: none) {
|
|
1047
1047
|
.msg-nav {
|
|
1048
|
+
right: max(2px, env(safe-area-inset-right));
|
|
1049
|
+
opacity: 0;
|
|
1050
|
+
visibility: hidden;
|
|
1051
|
+
pointer-events: none;
|
|
1052
|
+
transition: opacity 0.2s, visibility 0.2s;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
.msg-nav.scrolling {
|
|
1056
|
+
opacity: 1;
|
|
1057
|
+
visibility: visible;
|
|
1058
|
+
pointer-events: auto;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
.msg-nav-ticks {
|
|
1062
|
+
max-height: 45dvh;
|
|
1063
|
+
padding: 4px;
|
|
1064
|
+
border-radius: 8px;
|
|
1065
|
+
background: color-mix(in srgb, var(--bg) 85%, transparent);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
.msg-nav-tick {
|
|
1069
|
+
width: 28px;
|
|
1070
|
+
height: 18px;
|
|
1071
|
+
touch-action: manipulation;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
.msg-nav-panel {
|
|
1048
1075
|
display: none;
|
|
1049
1076
|
}
|
|
1050
1077
|
}
|
|
@@ -1057,6 +1084,17 @@ a.att-file:hover {
|
|
|
1057
1084
|
margin-top: -2px;
|
|
1058
1085
|
font-size: 12px;
|
|
1059
1086
|
color: var(--fg-faint);
|
|
1087
|
+
flex-wrap: wrap;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
.queue-note .icon-btn {
|
|
1091
|
+
width: 24px;
|
|
1092
|
+
height: 24px;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
.queue-note .icon-btn svg {
|
|
1096
|
+
width: 14px;
|
|
1097
|
+
height: 14px;
|
|
1060
1098
|
}
|
|
1061
1099
|
|
|
1062
1100
|
.queue-note.dropped {
|
package/web/css/overlay.css
CHANGED
|
@@ -234,12 +234,50 @@ button.list-item:hover {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
/* ----- 目录选择器 ----- */
|
|
237
|
+
.modal.dir-picker {
|
|
238
|
+
height: min(600px, 86dvh);
|
|
239
|
+
max-height: calc(100dvh - 32px);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.dir-picker .modal-head,
|
|
243
|
+
.dir-picker .modal-foot {
|
|
244
|
+
flex-shrink: 0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.dir-picker .modal-body {
|
|
248
|
+
flex: 1;
|
|
249
|
+
min-height: 0;
|
|
250
|
+
overflow-y: auto;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.dir-picker .modal-body > :not(.dir-list) {
|
|
254
|
+
flex: 0 0 auto;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
.dir-actions,
|
|
258
|
+
.dir-create {
|
|
259
|
+
display: flex;
|
|
260
|
+
align-items: center;
|
|
261
|
+
gap: 8px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.dir-actions {
|
|
265
|
+
justify-content: space-between;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.dir-create[hidden] {
|
|
269
|
+
display: none;
|
|
270
|
+
}
|
|
271
|
+
|
|
237
272
|
.dir-crumbs {
|
|
238
273
|
display: flex;
|
|
239
274
|
flex-wrap: wrap;
|
|
240
275
|
align-items: center;
|
|
241
276
|
gap: 2px;
|
|
242
277
|
font-size: 14px;
|
|
278
|
+
max-height: 72px;
|
|
279
|
+
overflow-y: auto;
|
|
280
|
+
overflow-wrap: anywhere;
|
|
243
281
|
}
|
|
244
282
|
|
|
245
283
|
.dir-crumbs .crumb {
|
|
@@ -265,12 +303,13 @@ button.list-item:hover {
|
|
|
265
303
|
display: flex;
|
|
266
304
|
flex-direction: column;
|
|
267
305
|
gap: 6px;
|
|
268
|
-
|
|
269
|
-
|
|
306
|
+
flex: 1;
|
|
307
|
+
min-height: 0;
|
|
270
308
|
overflow-y: auto;
|
|
271
309
|
}
|
|
272
310
|
|
|
273
311
|
.dir-item {
|
|
312
|
+
flex-shrink: 0;
|
|
274
313
|
padding: 8px 12px;
|
|
275
314
|
}
|
|
276
315
|
|
|
@@ -286,7 +325,9 @@ button.list-item:hover {
|
|
|
286
325
|
|
|
287
326
|
.dir-manual {
|
|
288
327
|
flex: 1;
|
|
289
|
-
min-width:
|
|
328
|
+
min-width: 0;
|
|
329
|
+
width: 100%;
|
|
330
|
+
font-size: 16px;
|
|
290
331
|
padding: 8px 12px;
|
|
291
332
|
border: 1px solid var(--border);
|
|
292
333
|
border-radius: 10px;
|
|
@@ -298,6 +339,10 @@ button.list-item:hover {
|
|
|
298
339
|
border-color: var(--accent);
|
|
299
340
|
}
|
|
300
341
|
|
|
342
|
+
.dir-picker .modal-foot .muted {
|
|
343
|
+
font-size: 12px;
|
|
344
|
+
}
|
|
345
|
+
|
|
301
346
|
.modal-foot .grow {
|
|
302
347
|
flex: 1;
|
|
303
348
|
}
|
|
@@ -436,14 +481,7 @@ button.list-item:hover {
|
|
|
436
481
|
white-space: pre-wrap;
|
|
437
482
|
}
|
|
438
483
|
|
|
439
|
-
/*
|
|
484
|
+
/* 选专家 */
|
|
440
485
|
.popover.expert-pop {
|
|
441
486
|
max-width: 340px;
|
|
442
487
|
}
|
|
443
|
-
|
|
444
|
-
.popover.expert-pop .pop-item .s {
|
|
445
|
-
display: -webkit-box;
|
|
446
|
-
-webkit-line-clamp: 2;
|
|
447
|
-
-webkit-box-orient: vertical;
|
|
448
|
-
overflow: hidden;
|
|
449
|
-
}
|