agent-loft 0.2.50 → 0.2.52
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 +11 -9
- 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 +76 -8
- package/src/core/chat-history.ts +19 -0
- package/src/core/hub.ts +125 -18
- package/src/core/memory-curator.ts +1 -1
- package/src/core/types.ts +8 -2
- package/web/css/experts.css +3 -13
- package/web/css/messages.css +167 -6
- package/web/css/overlay.css +49 -11
- package/web/css/search.css +28 -7
- package/web/css/sidebar.css +55 -2
- package/web/css/topbar.css +13 -17
- package/web/lib/dom.js +1 -0
- 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 +7 -8
- package/web/views/composer.js +5 -0
- package/web/views/conv-actions.js +70 -7
- package/web/views/interaction.js +1 -1
- package/web/views/layout.js +4 -1
- package/web/views/messages.js +88 -9
- package/web/views/msg-nav.js +134 -6
- package/web/views/sidebar.js +23 -38
- package/web/views/slash.js +63 -12
- package/web/views/topbar.js +4 -16
package/web/views/sidebar.js
CHANGED
|
@@ -3,6 +3,7 @@ import { api } from "../lib/api.js";
|
|
|
3
3
|
import { desktop, remoteTabs, S, ui } from "../state.js";
|
|
4
4
|
import { baseName } from "./topbar.js";
|
|
5
5
|
import { newDraft, openConversation } from "./messages.js";
|
|
6
|
+
import { convExpert, expertIcon } from "./experts.js";
|
|
6
7
|
import { leaveRemote } from "./remote.js";
|
|
7
8
|
import { reportShellState } from "../lib/shell.js";
|
|
8
9
|
|
|
@@ -227,6 +228,13 @@ export function agentLabel(id) {
|
|
|
227
228
|
return S.agents.find((a) => a.id === id)?.label ?? id;
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
/** 会话名后面的专家图标,鼠标悬停在会话行上时显示 */
|
|
232
|
+
function convExpertMark(c) {
|
|
233
|
+
if (!c) return null;
|
|
234
|
+
const expert = convExpert(c);
|
|
235
|
+
return h("span", { class: "expert-mark", title: `专家:${expert.name}` }, expertIcon(expert, "expert-mark-icon"));
|
|
236
|
+
}
|
|
237
|
+
|
|
230
238
|
function agentShort(id) {
|
|
231
239
|
return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id;
|
|
232
240
|
}
|
|
@@ -304,15 +312,6 @@ function setProjectOrder(order) {
|
|
|
304
312
|
let dirDrag = null;
|
|
305
313
|
let sidebarStale = false;
|
|
306
314
|
|
|
307
|
-
/** 「最近」「项目」分组标题:点击折叠 / 展开,hover 时显示箭头 */
|
|
308
|
-
function groupHead(label, id, folded) {
|
|
309
|
-
return h(
|
|
310
|
-
"button",
|
|
311
|
-
{ class: `conv-group${folded ? " collapsed" : ""}`, title: folded ? "展开" : "折叠", onclick: () => toggleSide("folded", id) },
|
|
312
|
-
label,
|
|
313
|
-
h("span", { class: "chev", html: ICON.down }),
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
315
|
function toggleSide(list, id) {
|
|
317
316
|
const set = new Set(sideState[list]);
|
|
318
317
|
set.has(id) ? set.delete(id) : set.add(id);
|
|
@@ -476,28 +475,21 @@ export function renderSidebar() {
|
|
|
476
475
|
onclick: () => open(c.key),
|
|
477
476
|
},
|
|
478
477
|
orphan ? h("span", { class: "brand-icon lead fork-mark", html: ICON.fork }) : null,
|
|
479
|
-
// 定时任务的专用对话
|
|
480
|
-
c.taskId ? h("span", { class: "brand-icon lead task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
|
|
481
|
-
// 自定义专家的对话:前面挂专家的头像(以前的是 emoji)
|
|
482
|
-
(c.expert?.avatar || c.expert?.icon) && !c.expert.builtin
|
|
483
|
-
? h("span", { class: "brand-icon lead expert-mark", title: `专家:${c.expert.name}` }, c.expert.avatar ? h("img", { src: c.expert.avatar, alt: "" }) : c.expert.icon)
|
|
484
|
-
: null,
|
|
485
478
|
h("span", { class: "title" }, convTitle(c)),
|
|
486
479
|
fold ? caret(fold.folded, fold.toggle) : null,
|
|
487
480
|
status(fold?.folded ? fold.keys : [c.key]),
|
|
481
|
+
convExpertMark(c),
|
|
482
|
+
c.taskId ? h("span", { class: "brand-icon task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
|
|
488
483
|
);
|
|
489
484
|
|
|
490
|
-
|
|
491
|
-
//
|
|
492
|
-
const
|
|
493
|
-
for (const node of forkForest(visible.filter((c) => c.channel !== "feishu"))) {
|
|
494
|
-
recent.push({ at: node.at, el: renderForkNode(node, (c, orphan, fold) => convRow(c, "", `${agentLabel(c.agent)} · ${c.cwd}`, orphan, fold)) });
|
|
495
|
-
}
|
|
485
|
+
const nodes = [];
|
|
486
|
+
// 飞书机器人独立显示在文件夹后面,点击打开它最近活跃的聊天
|
|
487
|
+
const botRows = [];
|
|
496
488
|
for (const bot of S.bots) {
|
|
497
489
|
const convs = visible.filter((c) => c.channel === "feishu" && c.channelId === bot.id);
|
|
498
490
|
if (bot.enabled === false && convs.length === 0) continue;
|
|
499
491
|
const latest = convs[0];
|
|
500
|
-
|
|
492
|
+
botRows.push({
|
|
501
493
|
at: latest?.activeAt ?? 0,
|
|
502
494
|
el: h(
|
|
503
495
|
"button",
|
|
@@ -510,22 +502,12 @@ export function renderSidebar() {
|
|
|
510
502
|
h("span", { class: "brand-icon lead", title: "飞书", html: ICON.feishu }),
|
|
511
503
|
h("span", { class: "title" }, bot.name),
|
|
512
504
|
status(convs.map((c) => c.key)),
|
|
505
|
+
convExpertMark(latest),
|
|
513
506
|
),
|
|
514
507
|
});
|
|
515
508
|
}
|
|
516
|
-
recent.sort((a, b) => b.at - a.at);
|
|
517
|
-
const recentFolded = sideState.folded.includes("@recent");
|
|
518
|
-
const nodes = [groupHead("最近", "@recent", recentFolded)];
|
|
519
|
-
if (!recentFolded) {
|
|
520
|
-
const rs = pages.recent;
|
|
521
|
-
const shown = loadedPrefix(rs, recent);
|
|
522
|
-
if (shown.length === 0 && !rs.loading) nodes.push(h("div", { class: "conv-empty" }, "还没有会话"));
|
|
523
|
-
nodes.push(...shown.slice(0, rs.show).map((r) => r.el));
|
|
524
|
-
const btn = moreButton(rs, shown.length, RECENT_LIMIT, (limit) => fetchPage(rs, { scope: "recent", limit: String(limit) }));
|
|
525
|
-
if (btn) nodes.push(btn);
|
|
526
|
-
}
|
|
527
509
|
|
|
528
|
-
// ----
|
|
510
|
+
// ---- Web 会话直接按工作目录分组,目录按用户排的顺序(见 orderProjectDirs) ----
|
|
529
511
|
const byDir = new Map();
|
|
530
512
|
for (const c of visible.filter((c) => c.channel === "web")) {
|
|
531
513
|
if (!byDir.has(c.cwd)) byDir.set(c.cwd, []);
|
|
@@ -542,11 +524,9 @@ export function renderSidebar() {
|
|
|
542
524
|
// 目录行要全部显示:服务端给了每个目录最近的活跃时间,加上本地已有的(刚建的、刚变活跃的)
|
|
543
525
|
const dirAt = new Map(pages.dirAt);
|
|
544
526
|
for (const [dir, convs] of byDir) dirAt.set(dir, Math.max(dirAt.get(dir) ?? 0, convs[0].activeAt));
|
|
545
|
-
const projFolded = sideState.folded.includes("@projects");
|
|
546
|
-
if (dirAt.size) nodes.push(groupHead("项目", "@projects", projFolded));
|
|
547
527
|
projDirsByActivity = [...dirAt.keys()].sort((a, b) => dirAt.get(b) - dirAt.get(a));
|
|
548
528
|
projDirs = orderProjectDirs(projDirsByActivity);
|
|
549
|
-
if (dirAt.size
|
|
529
|
+
if (dirAt.size) {
|
|
550
530
|
const clearDrop = () => ui.convList.querySelectorAll(".drop-before, .drop-after").forEach((el) => el.classList.remove("drop-before", "drop-after"));
|
|
551
531
|
const endDrag = () => {
|
|
552
532
|
dirDrag = null;
|
|
@@ -640,6 +620,8 @@ export function renderSidebar() {
|
|
|
640
620
|
if (btn) nodes.push(h("div", { class: "sub-more" }, btn));
|
|
641
621
|
}
|
|
642
622
|
}
|
|
623
|
+
nodes.push(...botRows.sort((a, b) => b.at - a.at).map((r) => r.el));
|
|
624
|
+
if (!nodes.length) nodes.push(h("div", { class: "conv-empty" }, "还没有会话"));
|
|
643
625
|
paintList(nodes, askKeys.size);
|
|
644
626
|
}
|
|
645
627
|
|
|
@@ -652,8 +634,11 @@ function paintList(nodes, asks) {
|
|
|
652
634
|
markClipped();
|
|
653
635
|
if (!clipObserver) {
|
|
654
636
|
clipObserver = new ResizeObserver(() => markClipped());
|
|
655
|
-
clipObserver.observe(ui.convList);
|
|
656
637
|
}
|
|
638
|
+
clipObserver.disconnect();
|
|
639
|
+
clipObserver.observe(ui.convList);
|
|
640
|
+
// hover 显示专家图标时,标题的可用宽度也会变化
|
|
641
|
+
for (const el of ui.convList.querySelectorAll(".conv-item .title")) clipObserver.observe(el);
|
|
657
642
|
if (hovered) {
|
|
658
643
|
requestAnimationFrame(() => {
|
|
659
644
|
const el = ui.convList.querySelector(".conv-item:hover .title");
|
package/web/views/slash.js
CHANGED
|
@@ -8,9 +8,10 @@ import { autosize, hideKeyboardForMenu, sendMessage, updateSendBtn } from "./com
|
|
|
8
8
|
// ---------- 斜杠命令补全 ----------
|
|
9
9
|
//
|
|
10
10
|
// 输入框里只有「/xxx」(还没打空格)时弹出命令表,顺序就是设置 → 命令里排好的。
|
|
11
|
-
// 列表按 agent +
|
|
11
|
+
// 列表按 agent + 工作目录缓存:提前加载,过期后先用已有列表、后台刷新。
|
|
12
12
|
|
|
13
|
-
export const slash = { open: false, shown: false, items: [], index: 0, cache: new Map(), token: 0 };
|
|
13
|
+
export const slash = { open: false, shown: false, items: [], index: 0, cache: new Map(), pending: new Map(), token: 0, contextKey: null };
|
|
14
|
+
let cacheEpoch = 0;
|
|
14
15
|
|
|
15
16
|
export function commandUsage(c) {
|
|
16
17
|
return `/${c.name}${c.args ? ` ${c.args}` : ""}`;
|
|
@@ -26,15 +27,62 @@ export function currentAgentId() {
|
|
|
26
27
|
return c?.agent ?? S.draftAgent ?? usableAgents()[0]?.id ?? "claude";
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
function commandContext(agent = currentAgentId()) {
|
|
31
|
+
const conv = S.current ? S.convs.get(S.current) : null;
|
|
32
|
+
const cwd = conv?.cwd ?? S.draftCwd ?? S.workspaceRoot ?? "";
|
|
33
|
+
const query = new URLSearchParams({ channel: "web" });
|
|
34
|
+
if (conv) query.set("key", conv.key);
|
|
35
|
+
else if (cwd) query.set("cwd", cwd);
|
|
36
|
+
return { cacheKey: JSON.stringify([agent, cwd]), url: `/api/agents/${agent}/commands?${query}` };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function refreshCommands({ cacheKey, url }) {
|
|
40
|
+
const pending = slash.pending.get(cacheKey);
|
|
41
|
+
if (pending) return pending;
|
|
42
|
+
const epoch = cacheEpoch;
|
|
43
|
+
const request = api(url).then((data) => {
|
|
44
|
+
const list = data.commands.filter((c) => !c.hidden);
|
|
45
|
+
if (epoch === cacheEpoch) {
|
|
46
|
+
slash.cache.set(cacheKey, { at: Date.now(), list });
|
|
47
|
+
if (slash.open && ui.input?.isConnected && commandContext().cacheKey === cacheKey) void updateSlashMenu();
|
|
48
|
+
}
|
|
49
|
+
return list;
|
|
50
|
+
}).finally(() => {
|
|
51
|
+
if (slash.pending.get(cacheKey) === request) slash.pending.delete(cacheKey);
|
|
52
|
+
});
|
|
53
|
+
slash.pending.set(cacheKey, request);
|
|
54
|
+
return request;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function loadCommands(agent) {
|
|
58
|
+
const context = commandContext(agent);
|
|
59
|
+
const hit = slash.cache.get(context.cacheKey);
|
|
60
|
+
if (hit && Date.now() - hit.at < 60_000) return Promise.resolve(hit.list);
|
|
61
|
+
const request = refreshCommands(context);
|
|
62
|
+
if (hit) {
|
|
63
|
+
void request.catch(() => {});
|
|
64
|
+
return Promise.resolve(hit.list);
|
|
65
|
+
}
|
|
66
|
+
return request;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 后台预加载,不阻塞页面;输入 / 时复用同一份进行中的请求 */
|
|
70
|
+
export function preloadCommands() {
|
|
71
|
+
const agent = currentAgentId();
|
|
72
|
+
if (!usableAgents().some((a) => a.id === agent)) return;
|
|
73
|
+
void loadCommands(agent).catch(() => {});
|
|
74
|
+
if (slash.open && slash.contextKey !== commandContext(agent).cacheKey) {
|
|
75
|
+
closeSlashMenu();
|
|
76
|
+
void updateSlashMenu();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 换账号、修改命令设置时作废旧缓存和在途请求的结果 */
|
|
81
|
+
export function clearCommandCache() {
|
|
82
|
+
cacheEpoch++;
|
|
83
|
+
slash.cache.clear();
|
|
84
|
+
slash.pending.clear();
|
|
85
|
+
closeSlashMenu();
|
|
38
86
|
}
|
|
39
87
|
|
|
40
88
|
function slashQuery() {
|
|
@@ -60,6 +108,8 @@ export async function updateSlashMenu() {
|
|
|
60
108
|
const q = slashQuery();
|
|
61
109
|
if (q === null) return closeSlashMenu();
|
|
62
110
|
const token = ++slash.token;
|
|
111
|
+
const contextKey = commandContext().cacheKey;
|
|
112
|
+
slash.contextKey = contextKey;
|
|
63
113
|
if (!slash.open) renderSlashMenu(null);
|
|
64
114
|
let list;
|
|
65
115
|
try {
|
|
@@ -69,7 +119,7 @@ export async function updateSlashMenu() {
|
|
|
69
119
|
return;
|
|
70
120
|
}
|
|
71
121
|
// 等待期间又打了字:以最新的那次为准
|
|
72
|
-
if (token !== slash.token || slashQuery() === null) return;
|
|
122
|
+
if (token !== slash.token || slashQuery() === null || commandContext().cacheKey !== contextKey) return;
|
|
73
123
|
const items = matchCommands(list, slashQuery());
|
|
74
124
|
if (items.length === 0) return closeSlashMenu();
|
|
75
125
|
slash.items = items;
|
|
@@ -133,6 +183,7 @@ export function closeSlashMenu() {
|
|
|
133
183
|
slash.shown = false;
|
|
134
184
|
slash.items = [];
|
|
135
185
|
slash.index = 0;
|
|
186
|
+
slash.contextKey = null;
|
|
136
187
|
slash.token++;
|
|
137
188
|
if (ui.slashMenu) ui.slashMenu.hidden = true;
|
|
138
189
|
}
|
package/web/views/topbar.js
CHANGED
|
@@ -133,13 +133,7 @@ function openExpertCard(anchor, key, pinned) {
|
|
|
133
133
|
row("引擎", agentLabel(c.agent)),
|
|
134
134
|
row("模型", [model ?? "默认", effort ? ` · ${effort}` : ""].join("")),
|
|
135
135
|
row("能力", abilities),
|
|
136
|
-
access === "web"
|
|
137
|
-
? null
|
|
138
|
-
: row(
|
|
139
|
-
"工作目录",
|
|
140
|
-
h("span", { class: "ec-cwd", title: c.cwd }, c.cwd),
|
|
141
|
-
h("button", { class: "ec-link", onclick: () => (closeMenu(), changeCwd()) }, "切换"),
|
|
142
|
-
),
|
|
136
|
+
access === "web" ? null : row("工作目录", h("span", { class: "ec-cwd", title: c.cwd }, c.cwd)),
|
|
143
137
|
),
|
|
144
138
|
);
|
|
145
139
|
placePopover(pop, anchor);
|
|
@@ -302,7 +296,7 @@ export function usableAgents() {
|
|
|
302
296
|
return usable.length ? usable : enabled;
|
|
303
297
|
}
|
|
304
298
|
|
|
305
|
-
/**
|
|
299
|
+
/** 新对话里选专家:统一列表,简介在悬停时显示(新建、管理在「设置 → 专家」里) */
|
|
306
300
|
function pickExpertMenu(anchor) {
|
|
307
301
|
if (ui.menu?.dataset.for === "expert") return closeMenu();
|
|
308
302
|
const pop = showPopover(anchor, { align: "left" });
|
|
@@ -314,16 +308,10 @@ function pickExpertMenu(anchor) {
|
|
|
314
308
|
"button",
|
|
315
309
|
{ class: `pop-item${e.id === S.draftExpert ? " on" : ""}`, title: e.description || "", onclick: () => (closeMenu(), switchAgent(e.id)) },
|
|
316
310
|
expertIcon(e),
|
|
317
|
-
h("span", { class: "grow" }, h("span", { class: "t" }, e.name)
|
|
311
|
+
h("span", { class: "grow" }, h("span", { class: "t" }, e.name)),
|
|
318
312
|
e.id === S.draftExpert ? h("span", { class: "check" }, "✓") : null,
|
|
319
313
|
);
|
|
320
|
-
|
|
321
|
-
const own = choices.filter((e) => !e.builtin);
|
|
322
|
-
fill(
|
|
323
|
-
pop,
|
|
324
|
-
builtin.map(item),
|
|
325
|
-
own.length ? [h("div", { class: "sep" }), h("div", { class: "pop-head" }, "我的专家"), own.map(item)] : null,
|
|
326
|
-
);
|
|
314
|
+
fill(pop, choices.map(item));
|
|
327
315
|
placePopover(pop, anchor);
|
|
328
316
|
}
|
|
329
317
|
|