agent-loft 0.2.66 → 0.2.68
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 +5 -3
- package/package.json +1 -1
- package/src/channels/web/api.ts +35 -13
- package/src/channels/web/conv-pages.ts +1 -1
- package/src/channels/web/experts-api.ts +12 -4
- package/src/core/experts.ts +3 -3
- package/src/core/hub.ts +34 -6
- package/src/core/servers.ts +5 -3
- package/src/core/task-runner.ts +4 -4
- package/src/core/ui-prefs.ts +3 -3
- package/src/core/users.ts +32 -8
- package/web/css/settings.css +26 -0
- package/web/css/sidebar.css +43 -1
- package/web/lib/overlay.js +6 -9
- package/web/settings/agents.js +2 -1
- package/web/settings/security.js +11 -2
- package/web/settings/users.js +56 -4
- package/web/views/conv-actions.js +3 -6
- package/web/views/experts.js +5 -1
- package/web/views/layout.js +12 -15
- package/web/views/sidebar-nav.js +0 -4
- package/web/views/sidebar.js +154 -91
- package/web/views/topbar.js +1 -1
package/web/views/sidebar.js
CHANGED
|
@@ -240,15 +240,15 @@ function agentShort(id) {
|
|
|
240
240
|
return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
/**
|
|
244
|
-
export const sideState = { open: [], more: [], folded: [], forkFolded: [], order: [], ...JSON.parse(localStorage.getItem("aim.side") || "{}") };
|
|
243
|
+
/** 侧栏状态:order 混排目录路径和 feishu:<机器人 id>,兼容原有的目录顺序。 */
|
|
244
|
+
export const sideState = { open: [], botOpen: [], more: [], folded: [], forkFolded: [], order: [], ...JSON.parse(localStorage.getItem("aim.side") || "{}") };
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
247
|
+
* 项目和飞书分组共用 sideState.order,新消息不会改变分组位置。
|
|
248
|
+
* 顺序存在服务端、跟着账号走(换设备也一样);新出现的分组接在最后,
|
|
249
249
|
* 接上之后名次也就定了
|
|
250
250
|
*/
|
|
251
|
-
function
|
|
251
|
+
function orderSidebarGroups(dirs) {
|
|
252
252
|
const rank = new Map(sideState.order.map((d, i) => [d, i]));
|
|
253
253
|
const ranked = dirs.filter((d) => rank.has(d)).sort((a, b) => rank.get(a) - rank.get(b));
|
|
254
254
|
const fresh = dirs.filter((d) => !rank.has(d));
|
|
@@ -277,42 +277,95 @@ async function putDirOrder(body) {
|
|
|
277
277
|
scheduleSidebar();
|
|
278
278
|
}
|
|
279
279
|
} catch (err) {
|
|
280
|
-
toast(
|
|
280
|
+
toast(`保存侧栏顺序失败:${err.message}`);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
/**
|
|
285
|
-
export
|
|
286
|
-
/** 同一批目录按最近活跃的顺序(「按最近活跃重排」用) */
|
|
287
|
-
let projDirsByActivity = [];
|
|
284
|
+
/** 飞书的排序键与绝对目录路径分开,改机器人名称不会影响位置。 */
|
|
285
|
+
export const botGroupId = (id) => `feishu:${id}`;
|
|
288
286
|
|
|
289
|
-
/**
|
|
290
|
-
export
|
|
287
|
+
/** 当前侧栏里显示的混合顺序(拖拽 / 右键菜单用) */
|
|
288
|
+
export let sidebarGroups = [];
|
|
289
|
+
/** 同一批分组按最近活跃的顺序(「按最近活跃重排」用) */
|
|
290
|
+
let groupsByActivity = [];
|
|
291
|
+
|
|
292
|
+
/** 移到另一个分组前 / 后;target 为 null 时置顶。隐藏的分组仍保留在已存顺序中。 */
|
|
293
|
+
export function moveSidebarGroup(dir, target, after = false) {
|
|
291
294
|
if (dir === target) return;
|
|
292
|
-
const list =
|
|
295
|
+
const list = sidebarGroups.filter((d) => d !== dir);
|
|
293
296
|
const idx = target === null ? 0 : list.indexOf(target);
|
|
294
297
|
if (idx < 0) return;
|
|
295
298
|
list.splice(idx + (after ? 1 : 0), 0, dir);
|
|
296
299
|
// 暂时没显示出来的目录(会话都被隐藏了之类)保留原来的名次,排在后面
|
|
297
|
-
|
|
300
|
+
setSidebarGroupOrder([...list, ...sideState.order.filter((d) => !list.includes(d))]);
|
|
298
301
|
}
|
|
299
302
|
|
|
300
303
|
/** 按最近活跃重排一次,之后照样固定 */
|
|
301
|
-
export function
|
|
302
|
-
|
|
304
|
+
export function resetSidebarGroupOrder() {
|
|
305
|
+
setSidebarGroupOrder([...groupsByActivity, ...sideState.order.filter((d) => !groupsByActivity.includes(d))]);
|
|
303
306
|
}
|
|
304
307
|
|
|
305
|
-
function
|
|
308
|
+
function setSidebarGroupOrder(order) {
|
|
306
309
|
sideState.order = order;
|
|
307
310
|
saveSideState();
|
|
308
311
|
if (orderSynced) void putDirOrder({ order });
|
|
309
312
|
renderSidebar();
|
|
310
313
|
}
|
|
311
314
|
|
|
312
|
-
/**
|
|
313
|
-
let
|
|
315
|
+
/** 拖动过程中暂停重绘,防止被拖的元素被替换;结束后补上更新。 */
|
|
316
|
+
let groupDrag = null;
|
|
314
317
|
let sidebarStale = false;
|
|
315
318
|
|
|
319
|
+
function groupDragAttrs(id) {
|
|
320
|
+
const clearDrop = () => ui.convList.querySelectorAll(".drop-before, .drop-after").forEach((el) => el.classList.remove("drop-before", "drop-after"));
|
|
321
|
+
const isAfter = (e) => {
|
|
322
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
323
|
+
return e.clientY > r.top + r.height / 2;
|
|
324
|
+
};
|
|
325
|
+
const endDrag = () => {
|
|
326
|
+
groupDrag = null;
|
|
327
|
+
clearDrop();
|
|
328
|
+
if (sidebarStale) renderSidebar();
|
|
329
|
+
};
|
|
330
|
+
return {
|
|
331
|
+
draggable: "true",
|
|
332
|
+
ondragstart: (e) => {
|
|
333
|
+
groupDrag = id;
|
|
334
|
+
e.dataTransfer.effectAllowed = "move";
|
|
335
|
+
e.dataTransfer.setData("text/plain", id);
|
|
336
|
+
e.currentTarget.classList.add("dragging");
|
|
337
|
+
stopMarquee();
|
|
338
|
+
},
|
|
339
|
+
ondragend: (e) => {
|
|
340
|
+
e.currentTarget.classList.remove("dragging");
|
|
341
|
+
endDrag();
|
|
342
|
+
},
|
|
343
|
+
ondragover: (e) => {
|
|
344
|
+
if (!groupDrag) return;
|
|
345
|
+
e.preventDefault();
|
|
346
|
+
e.dataTransfer.dropEffect = "move";
|
|
347
|
+
const after = isAfter(e);
|
|
348
|
+
if (!e.currentTarget.classList.contains(after ? "drop-after" : "drop-before")) {
|
|
349
|
+
clearDrop();
|
|
350
|
+
if (groupDrag !== id) e.currentTarget.classList.add(after ? "drop-after" : "drop-before");
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
ondragleave: (e) => {
|
|
354
|
+
if (!e.currentTarget.contains(e.relatedTarget)) e.currentTarget.classList.remove("drop-before", "drop-after");
|
|
355
|
+
},
|
|
356
|
+
ondrop: (e) => {
|
|
357
|
+
if (!groupDrag) return;
|
|
358
|
+
e.preventDefault();
|
|
359
|
+
const from = groupDrag;
|
|
360
|
+
const after = isAfter(e);
|
|
361
|
+
groupDrag = null;
|
|
362
|
+
clearDrop();
|
|
363
|
+
if (from !== id) moveSidebarGroup(from, id, after);
|
|
364
|
+
else if (sidebarStale) renderSidebar();
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
316
369
|
function toggleSide(list, id) {
|
|
317
370
|
const set = new Set(sideState[list]);
|
|
318
371
|
set.has(id) ? set.delete(id) : set.add(id);
|
|
@@ -334,7 +387,7 @@ const MORE_STEP = 10;
|
|
|
334
387
|
// next:下一页的游标;null = 没有更多了;undefined = 这个目录还没拉过。
|
|
335
388
|
|
|
336
389
|
/** full:老版本服务端一次给了全部,不用再拉 */
|
|
337
|
-
const pages = { recent: { show: RECENT_LIMIT, next: null, loading: false }, dirs: new Map(), dirAt: new Map(), full: false };
|
|
390
|
+
const pages = { recent: { show: RECENT_LIMIT, next: null, loading: false }, dirs: new Map(), bots: new Map(), dirAt: new Map(), full: false };
|
|
338
391
|
|
|
339
392
|
function dirState(dir) {
|
|
340
393
|
let st = pages.dirs.get(dir);
|
|
@@ -342,6 +395,12 @@ function dirState(dir) {
|
|
|
342
395
|
return st;
|
|
343
396
|
}
|
|
344
397
|
|
|
398
|
+
function botState(id) {
|
|
399
|
+
let st = pages.bots.get(id);
|
|
400
|
+
if (!st) pages.bots.set(id, (st = { show: PROJECT_LIMIT, next: pages.full ? null : undefined, loading: false }));
|
|
401
|
+
return st;
|
|
402
|
+
}
|
|
403
|
+
|
|
345
404
|
/** /api/bootstrap 的参数:按现在显示了多少条要(重连后整份换掉时,已经展开的不会缩回去) */
|
|
346
405
|
export function bootstrapQuery() {
|
|
347
406
|
const q = new URLSearchParams({ recent: String(pages.recent.show), open: JSON.stringify(sideState.open.map((d) => [d, dirState(d).show])) });
|
|
@@ -355,6 +414,11 @@ export function applyBootstrap(data) {
|
|
|
355
414
|
S.sidebarNav = data.sidebarNav ?? null;
|
|
356
415
|
S.convs = new Map(data.conversations.map((c) => [c.key, c]));
|
|
357
416
|
pages.full = !data.sidebar;
|
|
417
|
+
// bootstrap 只带每个机器人最近的一条;展开的列表需要重新补齐。
|
|
418
|
+
for (const st of pages.bots.values()) {
|
|
419
|
+
st.next = pages.full ? null : undefined;
|
|
420
|
+
st.failed = false;
|
|
421
|
+
}
|
|
358
422
|
pages.recent.next = data.sidebar?.recent.next ?? null;
|
|
359
423
|
pages.dirAt = new Map((data.sidebar?.dirs ?? []).map((d) => [d.dir, d.at]));
|
|
360
424
|
const fetched = new Map((data.sidebar?.dirs ?? []).filter((d) => "next" in d).map((d) => [d.dir, d.next]));
|
|
@@ -439,7 +503,7 @@ export function reportDesktop() {
|
|
|
439
503
|
|
|
440
504
|
export function renderSidebar() {
|
|
441
505
|
if (!ui.convList) return;
|
|
442
|
-
if (
|
|
506
|
+
if (groupDrag) {
|
|
443
507
|
sidebarStale = true;
|
|
444
508
|
return;
|
|
445
509
|
}
|
|
@@ -479,32 +543,75 @@ export function renderSidebar() {
|
|
|
479
543
|
c.taskId ? h("span", { class: "brand-icon task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
|
|
480
544
|
);
|
|
481
545
|
|
|
482
|
-
|
|
483
|
-
|
|
546
|
+
// 飞书和项目共用排序,展开后的会话跟随所属分组。
|
|
547
|
+
if (cur?.channel === "feishu" && cur.key !== autoOpenedFor) {
|
|
548
|
+
autoOpenedFor = cur.key;
|
|
549
|
+
if (!sideState.botOpen.includes(cur.channelId)) {
|
|
550
|
+
sideState.botOpen.push(cur.channelId);
|
|
551
|
+
saveSideState();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
484
554
|
const botRows = [];
|
|
485
555
|
for (const bot of S.bots) {
|
|
486
556
|
const convs = visible.filter((c) => c.channel === "feishu" && c.channelId === bot.id);
|
|
487
557
|
if (bot.enabled === false && convs.length === 0) continue;
|
|
488
558
|
const latest = convs[0];
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
559
|
+
const expanded = sideState.botOpen.includes(bot.id);
|
|
560
|
+
const rows = [h(
|
|
561
|
+
"div",
|
|
562
|
+
{ class: "proj-row bot-row", "data-bot": bot.id, ...groupDragAttrs(botGroupId(bot.id)) },
|
|
563
|
+
h(
|
|
492
564
|
"button",
|
|
493
565
|
{
|
|
494
|
-
class:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
onclick: () => (
|
|
566
|
+
class: "conv-item proj",
|
|
567
|
+
title: `飞书 · ${bot.name}\n拖动可调整顺序,右键更多操作`,
|
|
568
|
+
"aria-expanded": String(expanded),
|
|
569
|
+
onclick: () => toggleSide("botOpen", bot.id),
|
|
498
570
|
},
|
|
499
571
|
h("span", { class: "title" }, bot.name),
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
h("span", { class: "brand-icon feishu-mark", title: "飞书", html: ICON.feishu }),
|
|
572
|
+
caret(!expanded),
|
|
573
|
+
expanded ? null : status(convs.map((c) => c.key)),
|
|
503
574
|
),
|
|
575
|
+
h(
|
|
576
|
+
"button",
|
|
577
|
+
{
|
|
578
|
+
class: "proj-new bot-new",
|
|
579
|
+
title: `使用 ${bot.name} 的专家和工作目录开新对话`,
|
|
580
|
+
"aria-label": `使用 ${bot.name} 的专家和工作目录开新对话`,
|
|
581
|
+
onclick: () => {
|
|
582
|
+
S.draftCwd = latest?.cwd && latest.cwd !== S.workspaceRoot ? latest.cwd : null;
|
|
583
|
+
S.draftCwdPicked = true;
|
|
584
|
+
const expert = latest?.expert?.id ?? latest?.agent ?? bot.agents?.[0];
|
|
585
|
+
if (expert) setDraftExpert(expert);
|
|
586
|
+
newDraft();
|
|
587
|
+
closeSide();
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
h("span", { class: "brand-icon feishu-mark", html: ICON.feishu, "aria-hidden": "true" }),
|
|
591
|
+
h("span", { class: "bot-plus", "aria-hidden": "true" }, icon("plus")),
|
|
592
|
+
),
|
|
593
|
+
)];
|
|
594
|
+
if (expanded) {
|
|
595
|
+
const st = botState(bot.id);
|
|
596
|
+
const load = (limit) => fetchPage(st, { scope: "bot", bot: bot.id, limit: String(limit) });
|
|
597
|
+
if (st.next === undefined && !st.loading && !st.failed) void load(st.show);
|
|
598
|
+
const forest = loadedPrefix(st, forkForest(convs));
|
|
599
|
+
for (const node of forest.slice(0, st.show)) {
|
|
600
|
+
rows.push(renderForkNode(node, (c, orphan, fold) => convRow(c, " sub", `${agentLabel(c.agent)} · ${c.cwd}`, orphan, fold)));
|
|
601
|
+
}
|
|
602
|
+
if (!convs.length && !st.loading && !st.failed) rows.push(h("div", { class: "conv-empty sub" }, "还没有会话"));
|
|
603
|
+
if (st.failed) rows.push(h("button", { class: "conv-more", onclick: () => { void load(st.show); renderSidebar(); } }, "加载失败,点击重试"));
|
|
604
|
+
const btn = moreButton(st, forest.length, PROJECT_LIMIT, load);
|
|
605
|
+
if (btn) rows.push(h("div", { class: "sub-more" }, btn));
|
|
606
|
+
}
|
|
607
|
+
botRows.push({
|
|
608
|
+
id: botGroupId(bot.id),
|
|
609
|
+
at: latest?.activeAt ?? 0,
|
|
610
|
+
rows,
|
|
504
611
|
});
|
|
505
612
|
}
|
|
506
613
|
|
|
507
|
-
// ---- Web 会话直接按工作目录分组,目录按用户排的顺序(见
|
|
614
|
+
// ---- Web 会话直接按工作目录分组,目录按用户排的顺序(见 orderSidebarGroups) ----
|
|
508
615
|
const byDir = new Map();
|
|
509
616
|
for (const c of visible.filter((c) => c.channel === "web")) {
|
|
510
617
|
if (!byDir.has(c.cwd)) byDir.set(c.cwd, []);
|
|
@@ -521,65 +628,21 @@ export function renderSidebar() {
|
|
|
521
628
|
// 目录行要全部显示:服务端给了每个目录最近的活跃时间,加上本地已有的(刚建的、刚变活跃的)
|
|
522
629
|
const dirAt = new Map(pages.dirAt);
|
|
523
630
|
for (const [dir, convs] of byDir) dirAt.set(dir, Math.max(dirAt.get(dir) ?? 0, convs[0].activeAt));
|
|
524
|
-
|
|
525
|
-
|
|
631
|
+
const dirsByActivity = [...dirAt.keys()].sort((a, b) => dirAt.get(b) - dirAt.get(a));
|
|
632
|
+
const groupRows = new Map(botRows.map((group) => [group.id, group.rows]));
|
|
633
|
+
const groupAt = new Map([...dirAt, ...botRows.map((group) => [group.id, group.at])]);
|
|
634
|
+
groupsByActivity = [...groupAt.keys()].sort((a, b) => groupAt.get(b) - groupAt.get(a));
|
|
635
|
+
sidebarGroups = orderSidebarGroups([...dirsByActivity, ...botRows.sort((a, b) => b.at - a.at).map((group) => group.id)]);
|
|
526
636
|
if (dirAt.size) {
|
|
527
|
-
|
|
528
|
-
const endDrag = () => {
|
|
529
|
-
dirDrag = null;
|
|
530
|
-
clearDrop();
|
|
531
|
-
if (sidebarStale) renderSidebar();
|
|
532
|
-
};
|
|
533
|
-
for (const dir of projDirs) {
|
|
637
|
+
for (const dir of dirsByActivity) {
|
|
534
638
|
const convs = byDir.get(dir) ?? [];
|
|
535
639
|
const expanded = sideState.open.includes(dir);
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return e.clientY > r.top + r.height / 2;
|
|
540
|
-
};
|
|
541
|
-
nodes.push(
|
|
640
|
+
const rows = [];
|
|
641
|
+
groupRows.set(dir, rows);
|
|
642
|
+
rows.push(
|
|
542
643
|
h(
|
|
543
644
|
"div",
|
|
544
|
-
{
|
|
545
|
-
class: "proj-row",
|
|
546
|
-
"data-dir": dir,
|
|
547
|
-
draggable: "true",
|
|
548
|
-
ondragstart: (e) => {
|
|
549
|
-
dirDrag = dir;
|
|
550
|
-
e.dataTransfer.effectAllowed = "move";
|
|
551
|
-
e.dataTransfer.setData("text/plain", dir);
|
|
552
|
-
e.currentTarget.classList.add("dragging");
|
|
553
|
-
stopMarquee();
|
|
554
|
-
},
|
|
555
|
-
ondragend: (e) => {
|
|
556
|
-
e.currentTarget.classList.remove("dragging");
|
|
557
|
-
endDrag();
|
|
558
|
-
},
|
|
559
|
-
ondragover: (e) => {
|
|
560
|
-
if (!dirDrag) return;
|
|
561
|
-
e.preventDefault();
|
|
562
|
-
e.dataTransfer.dropEffect = "move";
|
|
563
|
-
const after = isAfter(e, e.currentTarget);
|
|
564
|
-
if (!e.currentTarget.classList.contains(after ? "drop-after" : "drop-before")) {
|
|
565
|
-
clearDrop();
|
|
566
|
-
if (dirDrag !== dir) e.currentTarget.classList.add(after ? "drop-after" : "drop-before");
|
|
567
|
-
}
|
|
568
|
-
},
|
|
569
|
-
ondragleave: (e) => {
|
|
570
|
-
if (!e.currentTarget.contains(e.relatedTarget)) e.currentTarget.classList.remove("drop-before", "drop-after");
|
|
571
|
-
},
|
|
572
|
-
ondrop: (e) => {
|
|
573
|
-
if (!dirDrag) return;
|
|
574
|
-
e.preventDefault();
|
|
575
|
-
const from = dirDrag;
|
|
576
|
-
const after = isAfter(e, e.currentTarget);
|
|
577
|
-
dirDrag = null;
|
|
578
|
-
clearDrop();
|
|
579
|
-
if (from !== dir) moveProjectDir(from, dir, after);
|
|
580
|
-
else if (sidebarStale) renderSidebar();
|
|
581
|
-
},
|
|
582
|
-
},
|
|
645
|
+
{ class: "proj-row", "data-dir": dir, ...groupDragAttrs(dir) },
|
|
583
646
|
h(
|
|
584
647
|
"button",
|
|
585
648
|
{ class: "conv-item proj", title: `${dir}\n拖动可调整顺序,右键可置顶`, onclick: () => toggleSide("open", dir) },
|
|
@@ -630,13 +693,13 @@ export function renderSidebar() {
|
|
|
630
693
|
// 「展开显示」按主对话算条数,分叉跟着主对话一起出现
|
|
631
694
|
const forest = loadedPrefix(st, forkForest(convs));
|
|
632
695
|
for (const node of forest.slice(0, st.show)) {
|
|
633
|
-
|
|
696
|
+
rows.push(renderForkNode(node, (c, orphan, fold) => convRow(c, " sub", agentLabel(c.agent), orphan, fold)));
|
|
634
697
|
}
|
|
635
698
|
const btn = moreButton(st, forest.length, PROJECT_LIMIT, load);
|
|
636
|
-
if (btn)
|
|
699
|
+
if (btn) rows.push(h("div", { class: "sub-more" }, btn));
|
|
637
700
|
}
|
|
638
701
|
}
|
|
639
|
-
nodes.
|
|
702
|
+
const nodes = sidebarGroups.flatMap((id) => groupRows.get(id) ?? []);
|
|
640
703
|
if (!nodes.length) nodes.push(h("div", { class: "conv-empty" }, "还没有会话"));
|
|
641
704
|
paintList(nodes, askKeys.size);
|
|
642
705
|
}
|
package/web/views/topbar.js
CHANGED
|
@@ -546,7 +546,7 @@ async function continueInFeishu(key) {
|
|
|
546
546
|
);
|
|
547
547
|
}
|
|
548
548
|
|
|
549
|
-
/**
|
|
549
|
+
/** 飞书机器人的历史会话:独立于侧栏分页拉取,按活跃时间排,点一下打开 */
|
|
550
550
|
export async function openBotConversations(botId) {
|
|
551
551
|
const bot = S.bots.find((b) => b.id === botId);
|
|
552
552
|
const body = h("div", { class: "modal-body" }, h("span", { class: "spinner" }));
|