agent-loft 0.2.84 → 0.2.86
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 +10 -9
- package/package.json +1 -1
- package/src/channels/web/api.ts +55 -10
- package/src/channels/web/server.ts +6 -0
- package/src/core/hub.ts +1 -1
- package/web/css/experts.css +23 -0
- package/web/css/mobile.css +2 -2
- package/web/css/servers.css +23 -22
- package/web/css/settings.css +38 -4
- package/web/css/sidebar.css +12 -25
- package/web/css/topbar.css +6 -1
- package/web/lib/shell.js +4 -12
- package/web/lib/ws.js +4 -1
- package/web/settings/agents.js +74 -108
- package/web/settings/experts.js +3 -3
- package/web/settings/index.js +4 -5
- package/web/settings/memory.js +1 -0
- package/web/settings/notify.js +1 -1
- package/web/settings/security.js +46 -37
- package/web/settings/users.js +59 -54
- package/web/settings/weixin.js +2 -3
- package/web/views/conv-actions.js +51 -8
- package/web/views/layout.js +4 -4
- package/web/views/sidebar.js +36 -19
- package/web/views/terminal.js +30 -7
- package/web/views/topbar.js +7 -61
|
@@ -2,7 +2,7 @@ import { agentIcon, fill, h, icon, toast } from "../lib/dom.js";
|
|
|
2
2
|
import { api } from "../lib/api.js";
|
|
3
3
|
import { relTime } from "../lib/time.js";
|
|
4
4
|
import { S, ui } from "../state.js";
|
|
5
|
-
import { agentLabel, convTitle, renderSidebar } from "./sidebar.js";
|
|
5
|
+
import { agentLabel, convTitle, forgetProject, renderSidebar } from "./sidebar.js";
|
|
6
6
|
import { agentCatalog, baseName, catalogDefaults, draftPick, modelName, renderContext, renderTopbar, saveDraftPick, visibleModels } from "./topbar.js";
|
|
7
7
|
import { closeMenu, confirmDialog, modal, placePopover, showPopover } from "../lib/overlay.js";
|
|
8
8
|
import { newDraft, openConversation, renderEmpty } from "./messages.js";
|
|
@@ -246,6 +246,7 @@ export async function changeCwd(pick) {
|
|
|
246
246
|
let seq = 0;
|
|
247
247
|
let loading = false;
|
|
248
248
|
let creating = false;
|
|
249
|
+
let deleting = false;
|
|
249
250
|
|
|
250
251
|
const crumbs = h("div", { class: "dir-crumbs" });
|
|
251
252
|
const list = h("div", { class: "dir-list" });
|
|
@@ -280,12 +281,27 @@ export async function changeCwd(pick) {
|
|
|
280
281
|
folderName.focus();
|
|
281
282
|
},
|
|
282
283
|
}, icon("plus"), "新建文件夹");
|
|
284
|
+
const removeFolder = h("button", {
|
|
285
|
+
type: "button", class: "btn danger small", hidden: true,
|
|
286
|
+
onclick: async () => {
|
|
287
|
+
if (!listing || loading || creating || deleting) return;
|
|
288
|
+
const parent = listing.rel.split(/[\\/]/).slice(0, -1).join("/");
|
|
289
|
+
deleting = true;
|
|
290
|
+
syncActions();
|
|
291
|
+
try {
|
|
292
|
+
if (await deleteProject(listing.path)) await load(parent);
|
|
293
|
+
} finally {
|
|
294
|
+
deleting = false;
|
|
295
|
+
syncActions();
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
}, "删除文件夹…");
|
|
283
299
|
const body = h(
|
|
284
300
|
"div",
|
|
285
301
|
{ class: "modal-body" },
|
|
286
302
|
crumbs,
|
|
287
303
|
manual,
|
|
288
|
-
h("div", { class: "dir-actions" }, h("label", { class: "check" }, hiddenBox, "显示隐藏"), newFolder),
|
|
304
|
+
h("div", { class: "dir-actions" }, h("label", { class: "check" }, hiddenBox, "显示隐藏"), newFolder, removeFolder),
|
|
289
305
|
createForm,
|
|
290
306
|
list,
|
|
291
307
|
);
|
|
@@ -299,13 +315,13 @@ export async function changeCwd(pick) {
|
|
|
299
315
|
});
|
|
300
316
|
|
|
301
317
|
go.onclick = async () => {
|
|
302
|
-
if (!listing || loading || creating) return;
|
|
318
|
+
if (!listing || loading || creating || deleting) return;
|
|
303
319
|
close();
|
|
304
320
|
if (pick) {
|
|
305
321
|
pick.onPick(listing.path);
|
|
306
322
|
return;
|
|
307
323
|
}
|
|
308
|
-
if (draft) {
|
|
324
|
+
if (draft || !S.current) {
|
|
309
325
|
S.draftCwd = listing.path === listing.root ? null : listing.path;
|
|
310
326
|
S.draftCwdPicked = true;
|
|
311
327
|
preloadCommands();
|
|
@@ -316,9 +332,11 @@ export async function changeCwd(pick) {
|
|
|
316
332
|
};
|
|
317
333
|
|
|
318
334
|
function syncActions() {
|
|
319
|
-
go.disabled = loading || creating || !listing || listing.path === current;
|
|
320
|
-
newFolder.disabled = loading || creating || !listing;
|
|
321
|
-
|
|
335
|
+
go.disabled = loading || creating || deleting || !listing || listing.path === current;
|
|
336
|
+
newFolder.disabled = loading || creating || deleting || !listing;
|
|
337
|
+
removeFolder.hidden = !listing?.rel;
|
|
338
|
+
removeFolder.disabled = loading || creating || deleting || !listing;
|
|
339
|
+
create.disabled = loading || creating || deleting;
|
|
322
340
|
cancelCreate.disabled = creating;
|
|
323
341
|
folderName.disabled = creating;
|
|
324
342
|
create.textContent = creating ? "创建中…" : "创建";
|
|
@@ -326,7 +344,7 @@ export async function changeCwd(pick) {
|
|
|
326
344
|
|
|
327
345
|
async function createFolder() {
|
|
328
346
|
const name = folderName.value.trim();
|
|
329
|
-
if (!listing || loading || creating || !name) return;
|
|
347
|
+
if (!listing || loading || creating || deleting || !name) return;
|
|
330
348
|
const my = seq;
|
|
331
349
|
const parent = listing.path;
|
|
332
350
|
creating = true;
|
|
@@ -502,3 +520,28 @@ export async function deleteConv(key = S.current) {
|
|
|
502
520
|
toast(err.message);
|
|
503
521
|
}
|
|
504
522
|
}
|
|
523
|
+
|
|
524
|
+
const deletingProjects = new Set();
|
|
525
|
+
|
|
526
|
+
export async function deleteProject(dir) {
|
|
527
|
+
if (!dir || dir === S.workspaceRoot || deletingProjects.has(dir)) return false;
|
|
528
|
+
deletingProjects.add(dir);
|
|
529
|
+
try {
|
|
530
|
+
const sure = await confirmDialog({
|
|
531
|
+
title: "删除项目?",
|
|
532
|
+
sub: dir,
|
|
533
|
+
message: "将删除此文件夹及全部文件、子目录,同时删除其中的所有会话、附件、资料库文件和定时发送,包括尚未展开的会话及复用到其他会话的文件副本,无法恢复。agent 自己保存的会话记录仍会保留。",
|
|
534
|
+
confirmText: "删除项目",
|
|
535
|
+
danger: true,
|
|
536
|
+
});
|
|
537
|
+
if (!sure) return false;
|
|
538
|
+
const data = await api("/api/dirs", { method: "DELETE", body: { path: dir } });
|
|
539
|
+
forgetProject(data.path, data.keys);
|
|
540
|
+
return true;
|
|
541
|
+
} catch (err) {
|
|
542
|
+
toast(`删除项目失败:${err.message}`);
|
|
543
|
+
return false;
|
|
544
|
+
} finally {
|
|
545
|
+
deletingProjects.delete(dir);
|
|
546
|
+
}
|
|
547
|
+
}
|
package/web/views/layout.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
stopMarquee,
|
|
20
20
|
} from "./sidebar.js";
|
|
21
21
|
import { applyDesktopQuota, loadQuota, renderQuota } from "./quota.js";
|
|
22
|
-
import {
|
|
22
|
+
import { openConvContextMenu, runDesktopMenu } from "./topbar.js";
|
|
23
23
|
import { syncDraftExpert } from "./experts.js";
|
|
24
24
|
import { confirmDialog, showMenu } from "../lib/overlay.js";
|
|
25
25
|
import { applyShellInfo, handleAllowEmbed, HOME, mountSwitcher, refreshShellPush, routeToServer, shellBooted, switchServer } from "../lib/shell.js";
|
|
@@ -27,7 +27,7 @@ import { bindScrollWatch, latestConversation, newDraft, openConversation, scroll
|
|
|
27
27
|
import { bindFileDrop, renderComposer } from "./composer.js";
|
|
28
28
|
import { openSearch } from "./conv-search.js";
|
|
29
29
|
import { createNav } from "./msg-nav.js";
|
|
30
|
-
import { renameConv } from "./conv-actions.js";
|
|
30
|
+
import { deleteProject, renameConv } from "./conv-actions.js";
|
|
31
31
|
import { clearCommandCache, preloadCommands } from "./slash.js";
|
|
32
32
|
import { releaseForeignPushSub } from "../lib/push.js";
|
|
33
33
|
import { createSidebarNav } from "./sidebar-nav.js";
|
|
@@ -236,7 +236,7 @@ function renderLayout() {
|
|
|
236
236
|
});
|
|
237
237
|
ui.convList.addEventListener("contextmenu", (e) => {
|
|
238
238
|
// 项目和 IM 分组共用移动菜单;触屏也可以通过长按调整混合顺序。
|
|
239
|
-
const
|
|
239
|
+
const dir = e.target.closest?.("[data-dir]")?.dataset.dir;
|
|
240
240
|
const group = e.target.closest?.("[data-group]")?.dataset.group;
|
|
241
241
|
if (group) {
|
|
242
242
|
const i = sidebarGroups.indexOf(group);
|
|
@@ -246,7 +246,7 @@ function renderLayout() {
|
|
|
246
246
|
];
|
|
247
247
|
const reset = sidebarGroups.length > 1 ? [{ label: "按最近活跃重排", onclick: resetSidebarGroupOrder }] : [];
|
|
248
248
|
const items = moves.length && reset.length ? [...moves, "sep", ...reset] : [...moves, ...reset];
|
|
249
|
-
if (
|
|
249
|
+
if (dir && dir !== S.workspaceRoot) items.push(...(items.length ? ["sep"] : []), { label: "删除项目…", danger: true, onclick: () => deleteProject(dir) });
|
|
250
250
|
if (!items.length) return;
|
|
251
251
|
e.preventDefault();
|
|
252
252
|
showMenu({ x: e.clientX, y: e.clientY }, items);
|
package/web/views/sidebar.js
CHANGED
|
@@ -389,7 +389,33 @@ const MORE_STEP = 10;
|
|
|
389
389
|
// next:下一页的游标;null = 没有更多了;undefined = 这个目录还没拉过。
|
|
390
390
|
|
|
391
391
|
/** full:老版本服务端一次给了全部,不用再拉 */
|
|
392
|
-
const pages = { recent: { show: RECENT_LIMIT, next: null, loading: false }, dirs: new Map(), bots: new Map(), weixin: new Map(), dirAt: new Map(), full: false };
|
|
392
|
+
const pages = { recent: { show: RECENT_LIMIT, next: null, loading: false }, dirs: new Map(), bots: new Map(), weixin: new Map(), dirAt: new Map(), full: false, revision: 0 };
|
|
393
|
+
|
|
394
|
+
/** 项目删除后清掉分页目录、折叠和排序缓存,其他设备也通过 WebSocket 调用。 */
|
|
395
|
+
export function forgetProject(dir, keys) {
|
|
396
|
+
const within = (value) => value === dir || value?.startsWith(`${dir}/`) || value?.startsWith(`${dir}\\`);
|
|
397
|
+
const removed = new Set(keys);
|
|
398
|
+
pages.revision++;
|
|
399
|
+
for (const key of pages.dirAt.keys()) if (within(key)) pages.dirAt.delete(key);
|
|
400
|
+
for (const key of pages.dirs.keys()) if (within(key)) pages.dirs.delete(key);
|
|
401
|
+
for (const list of ["open", "more", "folded", "order"]) sideState[list] = sideState[list].filter((value) => !within(value));
|
|
402
|
+
sideState.forkFolded = sideState.forkFolded.filter((key) => !removed.has(key));
|
|
403
|
+
saveSideState();
|
|
404
|
+
for (const key of removed) {
|
|
405
|
+
const c = S.convs.get(key);
|
|
406
|
+
if (c) c.hidden = true;
|
|
407
|
+
}
|
|
408
|
+
const resetDraft = within(S.draftCwd);
|
|
409
|
+
if (resetDraft) {
|
|
410
|
+
S.draftCwd = null;
|
|
411
|
+
S.draftCwdPicked = false;
|
|
412
|
+
}
|
|
413
|
+
if (removed.has(S.current) || (!S.current && resetDraft)) {
|
|
414
|
+
S.loadToken++;
|
|
415
|
+
newDraft();
|
|
416
|
+
} else renderSidebar();
|
|
417
|
+
reportDesktop();
|
|
418
|
+
}
|
|
393
419
|
|
|
394
420
|
function dirState(dir) {
|
|
395
421
|
let st = pages.dirs.get(dir);
|
|
@@ -453,6 +479,7 @@ async function fetchPage(st, params) {
|
|
|
453
479
|
if (st.loading) return;
|
|
454
480
|
st.loading = true;
|
|
455
481
|
st.failed = false;
|
|
482
|
+
const revision = pages.revision;
|
|
456
483
|
try {
|
|
457
484
|
const q = new URLSearchParams(params);
|
|
458
485
|
if (st.next) {
|
|
@@ -460,6 +487,7 @@ async function fetchPage(st, params) {
|
|
|
460
487
|
q.set("key", st.next.key);
|
|
461
488
|
}
|
|
462
489
|
const data = await api(`/api/conversations/page?${q}`);
|
|
490
|
+
if (revision !== pages.revision) return;
|
|
463
491
|
for (const c of data.conversations) S.convs.set(c.key, c);
|
|
464
492
|
st.next = data.next;
|
|
465
493
|
} catch (err) {
|
|
@@ -561,9 +589,8 @@ export function renderSidebar() {
|
|
|
561
589
|
saveSideState();
|
|
562
590
|
}
|
|
563
591
|
}
|
|
564
|
-
//
|
|
565
|
-
const imGroupRow = ({ id, channel, name, convs, expanded, toggle,
|
|
566
|
-
const latest = convs[0];
|
|
592
|
+
// 飞书和微信共用分组标题、折叠状态提示及静态渠道标识,不提供 Web 新建入口。
|
|
593
|
+
const imGroupRow = ({ id, channel, name, convs, expanded, toggle, attrs = {} }) => {
|
|
567
594
|
const label = channel === "feishu" ? "飞书" : "微信";
|
|
568
595
|
return h(
|
|
569
596
|
"div",
|
|
@@ -581,22 +608,12 @@ export function renderSidebar() {
|
|
|
581
608
|
expanded ? null : status(convs.map((c) => c.key)),
|
|
582
609
|
),
|
|
583
610
|
h(
|
|
584
|
-
"
|
|
611
|
+
"span",
|
|
585
612
|
{
|
|
586
|
-
class: "
|
|
587
|
-
title:
|
|
588
|
-
"aria-label": `使用 ${name} 的专家和工作目录开新对话`,
|
|
589
|
-
onclick: () => {
|
|
590
|
-
S.draftCwd = latest?.cwd && latest.cwd !== S.workspaceRoot ? latest.cwd : null;
|
|
591
|
-
S.draftCwdPicked = true;
|
|
592
|
-
const expert = latest?.expert?.id ?? latest?.agent ?? agent;
|
|
593
|
-
if (expert) setDraftExpert(expert);
|
|
594
|
-
newDraft();
|
|
595
|
-
closeSide();
|
|
596
|
-
},
|
|
613
|
+
class: "bot-channel",
|
|
614
|
+
title: label,
|
|
597
615
|
},
|
|
598
616
|
h("span", { class: `brand-icon channel-mark ${channel}-mark`, html: ICON[channel], "aria-hidden": "true" }),
|
|
599
|
-
h("span", { class: "bot-plus", "aria-hidden": "true" }, icon("plus")),
|
|
600
617
|
),
|
|
601
618
|
);
|
|
602
619
|
};
|
|
@@ -608,7 +625,7 @@ export function renderSidebar() {
|
|
|
608
625
|
const expanded = sideState.botOpen.includes(bot.id);
|
|
609
626
|
const rows = [imGroupRow({
|
|
610
627
|
id: botGroupId(bot.id), channel: "feishu", name: bot.name, convs, expanded,
|
|
611
|
-
toggle: () => toggleSide("botOpen", bot.id),
|
|
628
|
+
toggle: () => toggleSide("botOpen", bot.id), attrs: { "data-bot": bot.id },
|
|
612
629
|
})];
|
|
613
630
|
if (expanded) {
|
|
614
631
|
const st = botState(bot.id);
|
|
@@ -692,7 +709,7 @@ export function renderSidebar() {
|
|
|
692
709
|
{ class: "proj-row", "data-dir": dir, ...groupDragAttrs(dir) },
|
|
693
710
|
h(
|
|
694
711
|
"button",
|
|
695
|
-
{ class: "conv-item proj", title: `${dir}\n
|
|
712
|
+
{ class: "conv-item proj", title: `${dir}\n拖动可调整顺序,右键更多操作`, onclick: () => toggleSide("open", dir) },
|
|
696
713
|
h("span", { class: "title" }, baseName(dir)),
|
|
697
714
|
caret(!expanded),
|
|
698
715
|
expanded ? null : status(convs.map((c) => c.key)),
|
package/web/views/terminal.js
CHANGED
|
@@ -12,7 +12,8 @@ import { attachTermTouch } from "./terminal-touch.js";
|
|
|
12
12
|
// ---------- 网页终端 ----------
|
|
13
13
|
// shell 跑在服务端(core/terminals.ts),这里每个标签一条 /ws/term 连接。
|
|
14
14
|
// 两种摆法:放在远程控制页里(embed),或者对话下面的底部面板(dock,Ctrl+`)。是同一块面板,挪个地方而已。
|
|
15
|
-
//
|
|
15
|
+
// 进来时不自动连接,点「连接终端」后按服务端列表接上,没有现成的才新建。
|
|
16
|
+
// 离开远程控制页、关掉面板、刷新页面都不结束 shell;刷新后仍需手动连接,点标签上的 × 才结束。
|
|
16
17
|
|
|
17
18
|
const T = {
|
|
18
19
|
/** closed:藏起来(shell 照常跑)/ dock:底部面板 / embed:在远程控制页里 */
|
|
@@ -23,6 +24,8 @@ const T = {
|
|
|
23
24
|
ctrl: false,
|
|
24
25
|
alt: false,
|
|
25
26
|
loaded: false,
|
|
27
|
+
want: false,
|
|
28
|
+
connecting: false,
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
const narrow = () => matchMedia("(max-width: 768px)").matches;
|
|
@@ -179,7 +182,12 @@ function renderEmptyPane() {
|
|
|
179
182
|
{ class: "term-empty" },
|
|
180
183
|
status.available === false
|
|
181
184
|
? h("div", { class: "error-text" }, status.reason ?? "这台服务器上终端用不了")
|
|
182
|
-
: [
|
|
185
|
+
: [
|
|
186
|
+
h("div", { class: "muted" }, T.want ? "没有开着的终端" : "终端未连接"),
|
|
187
|
+
T.want && !T.connecting
|
|
188
|
+
? h("button", { class: "btn", onclick: () => void newTab() }, icon("plus"), "新建终端")
|
|
189
|
+
: h("button", { class: "btn primary", disabled: T.connecting, onclick: () => void connectTerminals() }, icon("plug"), T.connecting ? "连接中…" : "连接终端"),
|
|
190
|
+
],
|
|
183
191
|
),
|
|
184
192
|
);
|
|
185
193
|
}
|
|
@@ -228,8 +236,21 @@ export function hide() {
|
|
|
228
236
|
|
|
229
237
|
// ---------- 标签 ----------
|
|
230
238
|
|
|
239
|
+
async function connectTerminals() {
|
|
240
|
+
if (T.connecting) return;
|
|
241
|
+
T.want = true;
|
|
242
|
+
T.connecting = true;
|
|
243
|
+
renderEmptyPane();
|
|
244
|
+
try {
|
|
245
|
+
await loadTabs({ create: true });
|
|
246
|
+
} finally {
|
|
247
|
+
T.connecting = false;
|
|
248
|
+
renderEmptyPane();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
231
252
|
/** 按服务端的列表对一下:别的设备开的接上,已经结束的标出来 */
|
|
232
|
-
async function loadTabs() {
|
|
253
|
+
async function loadTabs({ create = false } = {}) {
|
|
233
254
|
let data;
|
|
234
255
|
try {
|
|
235
256
|
data = await api("/api/terminals");
|
|
@@ -239,16 +260,16 @@ async function loadTabs() {
|
|
|
239
260
|
}
|
|
240
261
|
if (S.remote) S.remote.terminal = { enabled: data.enabled, allowed: data.allowed, available: data.available, reason: data.reason, keepAliveMin: data.keepAliveMin };
|
|
241
262
|
if (!data.allowed) return revoked();
|
|
263
|
+
T.loaded = true;
|
|
264
|
+
if (!T.want) return renderEmptyPane();
|
|
242
265
|
const ids = new Set(data.terminals.map((t) => t.id));
|
|
243
266
|
for (const tab of T.tabs) if (!ids.has(tab.id) && !tab.ended) ended(tab, "已经结束了");
|
|
244
267
|
for (const t of data.terminals) if (!T.tabs.some((tab) => tab.id === t.id)) addTab(t, false);
|
|
245
|
-
//
|
|
246
|
-
if (
|
|
247
|
-
T.loaded = true;
|
|
268
|
+
// 用户手动连接、一个都没有:开一个;打开页面和同步列表不新建。
|
|
269
|
+
if (create && T.tabs.length === 0 && data.available) {
|
|
248
270
|
await newTab();
|
|
249
271
|
return;
|
|
250
272
|
}
|
|
251
|
-
T.loaded = true;
|
|
252
273
|
if (!T.active && T.tabs.length) select(T.tabs[T.tabs.length - 1]);
|
|
253
274
|
renderHead();
|
|
254
275
|
renderEmptyPane();
|
|
@@ -256,6 +277,7 @@ async function loadTabs() {
|
|
|
256
277
|
|
|
257
278
|
async function newTab() {
|
|
258
279
|
ensureDock();
|
|
280
|
+
T.want = true;
|
|
259
281
|
// 先按面板现在的大小算好行列,shell 一开始就是对的宽度
|
|
260
282
|
const probe = T.active?.fit.proposeDimensions();
|
|
261
283
|
let info;
|
|
@@ -265,6 +287,7 @@ async function newTab() {
|
|
|
265
287
|
toast(err.message);
|
|
266
288
|
return;
|
|
267
289
|
}
|
|
290
|
+
T.loaded = true;
|
|
268
291
|
if (T.mode === "closed") {
|
|
269
292
|
if (narrow()) return void openRemote("terminal");
|
|
270
293
|
setMode("dock");
|
package/web/views/topbar.js
CHANGED
|
@@ -19,7 +19,7 @@ export function renderTopbar() {
|
|
|
19
19
|
const library = S.view === "library";
|
|
20
20
|
const showExpert = c && !tasks && !remote && !library;
|
|
21
21
|
// 老版本桌面端把菜单放在窗口顶栏;菜单没有内容时也不放。
|
|
22
|
-
const showMore = !desktopMenu &&
|
|
22
|
+
const showMore = !desktopMenu && topMenuItems().length > 0;
|
|
23
23
|
fill(ui.topbar,
|
|
24
24
|
h("button", { class: "icon-btn menu-btn", onclick: openSide, title: "会话列表" }, icon("menu")),
|
|
25
25
|
h(
|
|
@@ -89,7 +89,7 @@ function scheduleCardClose() {
|
|
|
89
89
|
}, HOVER_CLOSE_MS);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
/**
|
|
92
|
+
/** 专家信息卡:头像、名字、说明,引擎、模型、权限、工作目录,以及本会话 Token 用量。 */
|
|
93
93
|
function openExpertCard(anchor, key, pinned) {
|
|
94
94
|
const c = S.convs.get(key);
|
|
95
95
|
if (!c || !anchor.isConnected) return;
|
|
@@ -139,6 +139,7 @@ function openExpertCard(anchor, key, pinned) {
|
|
|
139
139
|
row("能力", abilities),
|
|
140
140
|
access === "web" ? null : row("工作目录", h("span", { class: "ec-cwd", title: c.cwd }, c.cwd)),
|
|
141
141
|
),
|
|
142
|
+
renderUsage(),
|
|
142
143
|
);
|
|
143
144
|
placePopover(pop, anchor);
|
|
144
145
|
}
|
|
@@ -154,12 +155,11 @@ function topMenuItems() {
|
|
|
154
155
|
return items;
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
/**
|
|
158
|
+
/** 顶栏右上角「更多」:当前会话的操作菜单。 */
|
|
158
159
|
function openTopMore(anchor) {
|
|
159
160
|
if (ui.menu?.anchor === anchor) return closeMenu();
|
|
160
161
|
const pop = showPopover(anchor, { place: "below", align: "right" });
|
|
161
162
|
pop.classList.add("top-menu");
|
|
162
|
-
const usage = renderUsage();
|
|
163
163
|
fill(
|
|
164
164
|
pop,
|
|
165
165
|
topMenuItems().map((it) =>
|
|
@@ -173,12 +173,11 @@ function openTopMore(anchor) {
|
|
|
173
173
|
it.checked ? h("span", { class: "check" }, "✓") : null,
|
|
174
174
|
),
|
|
175
175
|
),
|
|
176
|
-
usage ? [h("div", { class: "sep" }), usage] : null,
|
|
177
176
|
);
|
|
178
177
|
placePopover(pop, anchor);
|
|
179
178
|
}
|
|
180
179
|
|
|
181
|
-
// ---------- 当前会话的 token
|
|
180
|
+
// ---------- 当前会话的 token 用量(专家信息卡底部) ----------
|
|
182
181
|
|
|
183
182
|
/** 分布的各项,顺序和颜色固定(颜色见 css/topbar.css 的 --usage-*) */
|
|
184
183
|
const USAGE_PARTS = [
|
|
@@ -237,33 +236,19 @@ function renderUsage() {
|
|
|
237
236
|
);
|
|
238
237
|
}
|
|
239
238
|
|
|
240
|
-
/** 桌面端原生菜单里只能放文字:用量写成几行 */
|
|
241
|
-
function usageLines() {
|
|
242
|
-
const sum = usageSummary();
|
|
243
|
-
if (!sum) return [];
|
|
244
|
-
if (!sum.total) return ["本会话还没有 token 用量记录"];
|
|
245
|
-
const { total, parts, usage } = sum;
|
|
246
|
-
return [
|
|
247
|
-
`本会话 Token 共 ${fmtCount(total)}${usage.costUsd ? `(按 API 价格约 $${usage.costUsd.toFixed(2)})` : ""}`,
|
|
248
|
-
...parts.map(
|
|
249
|
-
(p) => ` ${p.label} ${fmtCount(p.n)} ${pctText(p.n, total)}${p.key === "output" && usage.reasoning ? `(含推理 ${fmtCount(usage.reasoning)})` : ""}`,
|
|
250
|
-
),
|
|
251
|
-
];
|
|
252
|
-
}
|
|
253
|
-
|
|
254
239
|
// ---------- 桌面端:菜单交给它的顶栏「更多」 ----------
|
|
255
240
|
|
|
256
241
|
let desktopActions = new Map();
|
|
257
242
|
let desktopMenuSig = "";
|
|
258
243
|
|
|
259
|
-
/**
|
|
244
|
+
/** 会话操作菜单变了就报给桌面端。 */
|
|
260
245
|
function syncDesktopMenu() {
|
|
261
246
|
if (!desktopMenu) return;
|
|
262
247
|
const items = topMenuItems();
|
|
263
248
|
desktopActions = new Map(items.filter((it) => it !== "sep").map((it) => [it.id, it.onclick]));
|
|
264
249
|
const menu = {
|
|
265
250
|
items: items.map((it) => (it === "sep" ? { type: "separator" } : { id: it.id, label: it.label, ...(it.checked !== undefined ? { checked: it.checked } : {}) })),
|
|
266
|
-
usage:
|
|
251
|
+
usage: [],
|
|
267
252
|
};
|
|
268
253
|
const sig = JSON.stringify(menu);
|
|
269
254
|
if (sig === desktopMenuSig) return;
|
|
@@ -583,42 +568,3 @@ async function continueInFeishu(key) {
|
|
|
583
568
|
}),
|
|
584
569
|
);
|
|
585
570
|
}
|
|
586
|
-
|
|
587
|
-
/** 飞书机器人的历史会话:独立于侧栏分页拉取,按活跃时间排,点一下打开 */
|
|
588
|
-
export async function openBotConversations(botId) {
|
|
589
|
-
const bot = S.bots.find((b) => b.id === botId);
|
|
590
|
-
const body = h("div", { class: "modal-body" }, h("span", { class: "spinner" }));
|
|
591
|
-
const close = modal({ title: `历史会话${bot ? ` · ${bot.name}` : ""}`, body });
|
|
592
|
-
let convs;
|
|
593
|
-
try {
|
|
594
|
-
convs = (await api(`/api/conversations/page?${new URLSearchParams({ scope: "bot", bot: botId })}`)).conversations;
|
|
595
|
-
} catch (err) {
|
|
596
|
-
fill(body, h("div", { class: "error-text" }, err.message));
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
for (const c of convs) S.convs.set(c.key, c);
|
|
600
|
-
fill(
|
|
601
|
-
body,
|
|
602
|
-
...(convs.length === 0
|
|
603
|
-
? [h("div", { class: "muted" }, "还没有会话")]
|
|
604
|
-
: convs.map((c) =>
|
|
605
|
-
h(
|
|
606
|
-
"button",
|
|
607
|
-
{
|
|
608
|
-
class: `list-item${c.key === S.current ? " on" : ""}`,
|
|
609
|
-
onclick: () => {
|
|
610
|
-
close();
|
|
611
|
-
if (c.key !== S.current) void openConversation(c.key);
|
|
612
|
-
},
|
|
613
|
-
},
|
|
614
|
-
h(
|
|
615
|
-
"div",
|
|
616
|
-
{ class: "grow" },
|
|
617
|
-
h("div", { class: "t" }, convTitle(c)),
|
|
618
|
-
h("div", { class: "s" }, `${relTime(c.activeAt)} · ${agentLabel(c.agent)} · ${c.cwd}`),
|
|
619
|
-
),
|
|
620
|
-
c.key === S.current ? "当前" : c.busy ? h("span", { class: "conv-spin", title: "进行中" }) : null,
|
|
621
|
-
),
|
|
622
|
-
)),
|
|
623
|
-
);
|
|
624
|
-
}
|