agent-loft 0.2.107 → 0.2.108
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/package.json +1 -1
- package/src/channels/web/api.ts +9 -7
- package/src/channels/web/conv-pages.ts +13 -3
- package/src/channels/web/experts-api.ts +13 -0
- package/src/core/ui-prefs.ts +17 -2
- package/web/css/experts.css +33 -0
- package/web/css/sidebar.css +9 -0
- package/web/settings/experts.js +82 -15
- package/web/state.js +2 -0
- package/web/views/experts.js +10 -3
- package/web/views/layout.js +1 -0
- package/web/views/sidebar.js +31 -8
package/package.json
CHANGED
package/src/channels/web/api.ts
CHANGED
|
@@ -32,7 +32,7 @@ import type { AttachmentInfo, SavedAttachment } from "../../core/types.js";
|
|
|
32
32
|
import { dailyUsage } from "../../core/usage.js";
|
|
33
33
|
import { localUsage } from "../../core/local-usage.js";
|
|
34
34
|
import { builtinAgentDefaults } from "../../core/builtin-agents.js";
|
|
35
|
-
import { appendDirOrder, getDirOrder, getSidebarNav, setDirOrder, setSidebarNav } from "../../core/ui-prefs.js";
|
|
35
|
+
import { appendDirOrder, getDirOrder, getExpertOrder, getSidebarNav, setDirOrder, setSidebarNav } from "../../core/ui-prefs.js";
|
|
36
36
|
import {
|
|
37
37
|
addMemoryItem,
|
|
38
38
|
clearMemory,
|
|
@@ -93,7 +93,7 @@ import {
|
|
|
93
93
|
takeAttempt,
|
|
94
94
|
} from "./auth.js";
|
|
95
95
|
import { canSeeConv, pushOwnedBy, sessionVisibleTo } from "./access.js";
|
|
96
|
-
import { clampLimit, dirsOf, inDir,
|
|
96
|
+
import { clampLimit, dirsOf, inDir, pageOf, parseCursor, recentPageOf, searchConvs } from "./conv-pages.js";
|
|
97
97
|
import { clientIp, cookies, HttpError, isHttps, readBody, readJsonBody, SECURITY_HEADERS, sendJson, setServerTiming } from "./http.js";
|
|
98
98
|
import { handleTasksApi } from "./tasks-api.js";
|
|
99
99
|
import { handleLibraryApi } from "./library-api.js";
|
|
@@ -665,12 +665,12 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
665
665
|
|
|
666
666
|
// ----- 总览 -----
|
|
667
667
|
if (p === "/api/bootstrap" && method === "GET") {
|
|
668
|
-
// 会话只给侧栏第一屏要的(见 conv-pages.ts):「最近」的前 recent
|
|
668
|
+
// 会话只给侧栏第一屏要的(见 conv-pages.ts):「最近」的前 recent 条、展开着的目录各自的前几棵树,
|
|
669
669
|
// 每个 IM 分组最近的一条(微信另含当前会话),再加上正在跑的、等你处理的。其余展开后分页拉取。
|
|
670
670
|
const startedAt = performance.now();
|
|
671
671
|
const all = hub.list(visible).filter((c) => !c.hidden);
|
|
672
672
|
const pending = interactions.listPending().filter((i) => visible(getConversation(i.convKey)));
|
|
673
|
-
const recent =
|
|
673
|
+
const recent = recentPageOf(all, null, clampLimit(url.searchParams.get("recent"), 5));
|
|
674
674
|
let open: [string, number][] = [];
|
|
675
675
|
try {
|
|
676
676
|
const raw: unknown = JSON.parse(url.searchParams.get("open") ?? "[]");
|
|
@@ -734,6 +734,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
734
734
|
bots: admin ? config().feishu.bots.map((b) => ({ id: b.id, name: b.name, agents: b.agents, enabled: b.enabled })) : [],
|
|
735
735
|
// 自己的和共享的专家(新对话、定时任务里选)。内置的 Claude Code / Codex 就是上面的 agents
|
|
736
736
|
experts: availableExperts(user.id).map(expertBrief),
|
|
737
|
+
expertOrder: getExpertOrder(user.id),
|
|
737
738
|
workspaceRoot: config().workspaceRoot,
|
|
738
739
|
quotaRefreshMin: config().web.quotaRefreshMin,
|
|
739
740
|
quotaEnabled: config().web.quotaEnabled,
|
|
@@ -900,7 +901,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
900
901
|
}
|
|
901
902
|
|
|
902
903
|
// ----- 会话 -----
|
|
903
|
-
// 侧栏按页拉:recent
|
|
904
|
+
// 侧栏按页拉:recent 逐条分页,dir / bot / weixin 按树分页。
|
|
904
905
|
if (p === "/api/conversations/page" && method === "GET") {
|
|
905
906
|
const all = hub.list(visible).filter((c) => !c.hidden);
|
|
906
907
|
const scope = url.searchParams.get("scope");
|
|
@@ -921,9 +922,10 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
|
|
|
921
922
|
return;
|
|
922
923
|
}
|
|
923
924
|
if (scope !== "recent" && scope !== "dir") throw new HttpError(400, "scope 只能是 recent / dir / bot / weixin");
|
|
924
|
-
const list = scope === "recent" ? all
|
|
925
|
+
const list = scope === "recent" ? all : all.filter(inDir(url.searchParams.get("dir") ?? ""));
|
|
925
926
|
const before = parseCursor(url.searchParams.get("at"), url.searchParams.get("key"));
|
|
926
|
-
|
|
927
|
+
const paginate = scope === "recent" ? recentPageOf : pageOf;
|
|
928
|
+
sendJson(res, 200, paginate(list, before, clampLimit(url.searchParams.get("limit"), scope === "recent" ? 5 : 10)));
|
|
927
929
|
return;
|
|
928
930
|
}
|
|
929
931
|
// 搜索会话(侧栏「搜索」弹窗):标题、目录名,再搜聊天内容(聊天记录索引,见 chat-history.ts)。
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// 侧栏会话列表分页:打开页面只拿第一页,点「展开显示」再按页拉。
|
|
2
2
|
//
|
|
3
|
-
// 一页按「树」算:主对话连同从它分叉出来的对话算一条(和前端 sidebar.js 的 forkForest 一样),
|
|
3
|
+
// 项目和 IM 一页按「树」算:主对话连同从它分叉出来的对话算一条(和前端 sidebar.js 的 forkForest 一样),
|
|
4
4
|
// 按整棵树里最近的活跃时间从新到旧排。翻页用游标(上一页最后一棵树的活跃时间 + 根的 key),
|
|
5
5
|
// 期间有会话变活跃、被删,也不会漏掉或重复一页的边界。
|
|
6
|
+
// 「最近」逐条按各自的活跃时间分页。
|
|
6
7
|
import type { ConversationInfo } from "../../core/hub.js";
|
|
7
8
|
|
|
8
9
|
export type Cursor = { at: number; key: string };
|
|
9
10
|
export type Page = { conversations: ConversationInfo[]; next: Cursor | null };
|
|
10
11
|
type Tree = { root: ConversationInfo; convs: ConversationInfo[]; at: number };
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
-
export const inRecent = (c: ConversationInfo): boolean => c.channel
|
|
13
|
+
/** 最近:所有 Web 会话(IM 渠道在侧栏单独分组) */
|
|
14
|
+
export const inRecent = (c: ConversationInfo): boolean => c.channel === "web";
|
|
14
15
|
/** 项目:Web 会话按工作目录分组 */
|
|
15
16
|
export const inDir = (dir: string) => (c: ConversationInfo): boolean => c.channel === "web" && c.cwd === dir;
|
|
16
17
|
|
|
@@ -50,6 +51,15 @@ export function pageOf(list: ConversationInfo[], before: Cursor | null, limit: n
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
/** 最近逐条分页,分叉独立按自己的活跃时间排序。 */
|
|
55
|
+
export function recentPageOf(list: ConversationInfo[], before: Cursor | null, limit: number): Page {
|
|
56
|
+
const sorted = list.filter(inRecent).sort((a, b) => b.activeAt - a.activeAt || (a.key < b.key ? 1 : -1));
|
|
57
|
+
const remaining = before ? sorted.filter((c) => c.activeAt < before.at || (c.activeAt === before.at && c.key < before.key)) : sorted;
|
|
58
|
+
const conversations = remaining.slice(0, limit);
|
|
59
|
+
const last = conversations.at(-1);
|
|
60
|
+
return { conversations, next: last && remaining.length > conversations.length ? { at: last.activeAt, key: last.key } : null };
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
/** 项目目录:每个目录最近的活跃时间(目录行本身要全部显示,会话再按需拉) */
|
|
54
64
|
export function dirsOf(list: ConversationInfo[]): { dir: string; at: number }[] {
|
|
55
65
|
const at = new Map<string, number>();
|
|
@@ -27,6 +27,7 @@ import { shellInfo } from "../../core/servers.js";
|
|
|
27
27
|
import { canUseMcp, claudeMachineMcp, createMcp, deleteMcp, getMcp, listUsableMcp, MACHINE_PREFIX, MCP_LIMITS, mcpView, setMcpUserValues, updateMcp, type McpInput, type McpServer } from "../../core/mcp.js";
|
|
28
28
|
import { activeSkills } from "../../core/skills.js";
|
|
29
29
|
import { getUser, isAdmin, type User } from "../../core/users.js";
|
|
30
|
+
import { getExpertOrder, setExpertOrder } from "../../core/ui-prefs.js";
|
|
30
31
|
import { HttpError, readJsonBody, sendJson } from "./http.js";
|
|
31
32
|
|
|
32
33
|
const bad = (err: unknown) => (err instanceof HttpError ? err : new HttpError(400, err instanceof Error ? err.message : String(err)));
|
|
@@ -130,6 +131,7 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
130
131
|
if (p === "/api/experts" && method === "GET") {
|
|
131
132
|
const enabled = hub.enabledAgents().map((d) => d.id);
|
|
132
133
|
sendJson(res, 200, {
|
|
134
|
+
expertOrder: getExpertOrder(user.id),
|
|
133
135
|
experts: availableExperts(user.id).map((e) => expertView(e, user.id)),
|
|
134
136
|
builtin: enabled.filter((id) => canUseExpert(user.id, id)).map((id) => ({ id, name: hub.label(id), engine: id })),
|
|
135
137
|
// 能建自定义专家的引擎(WorkBuddy、pi 只有内置专家)
|
|
@@ -146,6 +148,7 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
146
148
|
|
|
147
149
|
if (p === "/api/experts/brief" && method === "GET") {
|
|
148
150
|
sendJson(res, 200, {
|
|
151
|
+
expertOrder: getExpertOrder(user.id),
|
|
149
152
|
experts: availableExperts(user.id).map(expertBrief),
|
|
150
153
|
builtin: hub.enabledAgents().filter((d) => canUseExpert(user.id, d.id)).map((d) => d.id),
|
|
151
154
|
user: { id: user.id, name: user.name, role: user.role },
|
|
@@ -154,6 +157,16 @@ export async function handleExpertsApi(req: IncomingMessage, res: ServerResponse
|
|
|
154
157
|
return true;
|
|
155
158
|
}
|
|
156
159
|
|
|
160
|
+
if (p === "/api/experts/order" && method === "PUT") {
|
|
161
|
+
const body = await readJsonBody<{ order?: unknown }>(req);
|
|
162
|
+
try {
|
|
163
|
+
sendJson(res, 200, { order: setExpertOrder(user.id, body.order) });
|
|
164
|
+
} catch (err) {
|
|
165
|
+
throw bad(err);
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
157
170
|
if (p === "/api/experts" && method === "POST") {
|
|
158
171
|
const body = await readJsonBody<ExpertInput>(req, 1024 * 1024);
|
|
159
172
|
try {
|
package/src/core/ui-prefs.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { dataDir, readJson, writeJsonAtomic } from "../home.js";
|
|
|
5
5
|
|
|
6
6
|
export type SidebarNavItem = { id: string; visible: boolean };
|
|
7
7
|
const NAV_IDS = ["search", "tasks", "library", "remote", "settings"];
|
|
8
|
-
type Prefs = { dirOrder?: string[]; sidebarNav?: SidebarNavItem[] };
|
|
8
|
+
type Prefs = { dirOrder?: string[]; sidebarNav?: SidebarNavItem[]; expertOrder?: string[] };
|
|
9
9
|
|
|
10
10
|
const prefsPath = path.join(dataDir, "ui-prefs.json");
|
|
11
11
|
let cache: Record<string, Prefs> | null = null;
|
|
@@ -49,7 +49,8 @@ export function appendDirOrder(userId: string, dirs: unknown): string[] {
|
|
|
49
49
|
const cur = all[userId]?.dirOrder ?? [];
|
|
50
50
|
const add = cleanDirs(dirs).filter((d) => !cur.includes(d));
|
|
51
51
|
if (add.length === 0 && all[userId]?.dirOrder) return cur;
|
|
52
|
-
|
|
52
|
+
// 「最近」首次出现时默认置顶;已有位置时保留用户排序。
|
|
53
|
+
const dirOrder = [...add.filter((id) => id === "recent"), ...cur, ...add.filter((id) => id !== "recent")].slice(0, MAX_DIRS);
|
|
53
54
|
all[userId] = { ...all[userId], dirOrder };
|
|
54
55
|
save();
|
|
55
56
|
return dirOrder;
|
|
@@ -80,6 +81,20 @@ export function setSidebarNav(userId: string, value: unknown): SidebarNavItem[]
|
|
|
80
81
|
return sidebarNav;
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
/** 内置、自建和共享专家的混合顺序,只影响当前账号的展示。 */
|
|
85
|
+
export function getExpertOrder(userId: string): string[] {
|
|
86
|
+
return load()[userId]?.expertOrder ?? [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function setExpertOrder(userId: string, value: unknown): string[] {
|
|
90
|
+
if (!Array.isArray(value) || value.length > 2000 || value.some((id) => typeof id !== "string" || !id || id.length > 100)) throw new Error("专家顺序必须是专家 ID 列表");
|
|
91
|
+
const expertOrder = [...new Set(value as string[])];
|
|
92
|
+
const all = load();
|
|
93
|
+
all[userId] = { ...all[userId], expertOrder };
|
|
94
|
+
save();
|
|
95
|
+
return expertOrder;
|
|
96
|
+
}
|
|
97
|
+
|
|
83
98
|
export function deleteUiPrefs(userId: string): void {
|
|
84
99
|
const all = load();
|
|
85
100
|
if (!(userId in all)) return;
|
package/web/css/experts.css
CHANGED
|
@@ -23,6 +23,39 @@
|
|
|
23
23
|
min-width: 0;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
.expert-sort-card {
|
|
27
|
+
position: relative;
|
|
28
|
+
padding-left: 44px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.expert-sort-card.dragging {
|
|
32
|
+
opacity: 0.55;
|
|
33
|
+
outline: 1px solid var(--border);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.expert-sort-grip {
|
|
37
|
+
position: absolute;
|
|
38
|
+
top: 10px;
|
|
39
|
+
left: 6px;
|
|
40
|
+
width: 30px;
|
|
41
|
+
height: 34px;
|
|
42
|
+
color: var(--fg-faint);
|
|
43
|
+
cursor: grab;
|
|
44
|
+
touch-action: none;
|
|
45
|
+
user-select: none;
|
|
46
|
+
border-radius: 6px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.expert-sort-grip:hover,
|
|
50
|
+
.expert-sort-grip:focus-visible {
|
|
51
|
+
color: var(--fg);
|
|
52
|
+
background: var(--bg-hover);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.expert-sort-grip:active {
|
|
56
|
+
cursor: grabbing;
|
|
57
|
+
}
|
|
58
|
+
|
|
26
59
|
.tool-check-item > input,
|
|
27
60
|
.perm-list > .check-item > input {
|
|
28
61
|
flex-shrink: 0;
|
package/web/css/sidebar.css
CHANGED
|
@@ -286,7 +286,16 @@ button.conv-group:hover {
|
|
|
286
286
|
color: var(--fg);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
.recent-row:hover .conv-item.proj {
|
|
290
|
+
padding-right: 10px;
|
|
291
|
+
}
|
|
292
|
+
|
|
289
293
|
@media (pointer: coarse) {
|
|
294
|
+
/* 触屏的新建按钮常驻,首次打开侧栏时也要为它让出状态图标的位置。 */
|
|
295
|
+
.proj-row[data-dir] .conv-item.proj {
|
|
296
|
+
padding-right: 36px;
|
|
297
|
+
}
|
|
298
|
+
|
|
290
299
|
.proj-new {
|
|
291
300
|
display: grid;
|
|
292
301
|
}
|
package/web/settings/experts.js
CHANGED
|
@@ -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 { confirmDialog, modal, showMenu } from "../lib/overlay.js";
|
|
4
4
|
import { S } from "../state.js";
|
|
5
|
-
import { expertIcon, reloadExperts } from "../views/experts.js";
|
|
5
|
+
import { expertIcon, reloadExperts, sortExperts } from "../views/experts.js";
|
|
6
6
|
import { agentCatalog, baseName } from "../views/topbar.js";
|
|
7
7
|
import { changeCwd } from "../views/conv-actions.js";
|
|
8
8
|
|
|
@@ -35,6 +35,7 @@ export async function expertsTab(panel) {
|
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
if (!box.isConnected) return;
|
|
38
|
+
S.expertOrder = data.expertOrder ?? [];
|
|
38
39
|
render(box, data, load);
|
|
39
40
|
};
|
|
40
41
|
refreshExpertsPage = () => { if (box.isConnected) void load(); };
|
|
@@ -43,6 +44,84 @@ export async function expertsTab(panel) {
|
|
|
43
44
|
|
|
44
45
|
function render(box, data, reload) {
|
|
45
46
|
const add = h("button", { class: "btn primary", onclick: () => openEditor(data, null, reload) }, icon("plus"), "新建");
|
|
47
|
+
const choices = sortExperts([...data.builtin.map((b) => ({ ...b, builtin: true })), ...data.experts], data.expertOrder ?? []);
|
|
48
|
+
const list = h("div", { class: "task-list expert-sort-list", role: "list", "aria-label": "专家顺序" });
|
|
49
|
+
const rows = new Map();
|
|
50
|
+
let saving = false;
|
|
51
|
+
const ids = () => [...list.children].map((el) => el.dataset.expert);
|
|
52
|
+
const restore = (order) => order.forEach((id) => list.append(rows.get(id)));
|
|
53
|
+
const save = async (before) => {
|
|
54
|
+
const order = [...ids(), ...(data.expertOrder ?? []).filter((id) => !rows.has(id))];
|
|
55
|
+
if (ids().join("\n") === before.join("\n")) return;
|
|
56
|
+
saving = true;
|
|
57
|
+
for (const handle of list.querySelectorAll(".expert-sort-grip")) handle.disabled = true;
|
|
58
|
+
try {
|
|
59
|
+
const next = await api("/api/experts/order", { method: "PUT", body: { order } });
|
|
60
|
+
data.expertOrder = next.order;
|
|
61
|
+
S.expertOrder = next.order;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
restore(before);
|
|
64
|
+
toast(`保存专家顺序失败:${err.message}`);
|
|
65
|
+
} finally {
|
|
66
|
+
saving = false;
|
|
67
|
+
for (const handle of list.querySelectorAll(".expert-sort-grip")) handle.disabled = false;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const move = (row, to) => {
|
|
71
|
+
const others = [...list.children].filter((el) => el !== row);
|
|
72
|
+
list.insertBefore(row, others[Math.max(0, to)] ?? null);
|
|
73
|
+
};
|
|
74
|
+
for (const e of choices) {
|
|
75
|
+
const row = e.builtin ? h("div", { class: "task-card skill-card" },
|
|
76
|
+
h("div", { class: "task-top" }, h("span", { class: "task-title" }, agentIcon(e.engine, "expert-card-icon"), e.name), h("span", { class: "badge" }, "内置")),
|
|
77
|
+
h("div", { class: "task-prompt" }, `${e.name} 原装的样子:原装提示词、所有工具;默认技能和 MCP 在「设置 → Agent」里配置。`),
|
|
78
|
+
) : expertCard(data, e, reload);
|
|
79
|
+
row.dataset.expert = e.id;
|
|
80
|
+
row.setAttribute("role", "listitem");
|
|
81
|
+
row.classList.add("expert-sort-card");
|
|
82
|
+
let drag = null;
|
|
83
|
+
const end = (ev) => {
|
|
84
|
+
if (!drag) return;
|
|
85
|
+
const { before, pointer } = drag;
|
|
86
|
+
drag = null;
|
|
87
|
+
row.classList.remove("dragging");
|
|
88
|
+
if (handle.hasPointerCapture(pointer)) handle.releasePointerCapture(pointer);
|
|
89
|
+
if (ev.type === "pointercancel") restore(before);
|
|
90
|
+
else void save(before);
|
|
91
|
+
};
|
|
92
|
+
const handle = h("button", {
|
|
93
|
+
class: "expert-sort-grip", type: "button", title: "拖动排序,也可用上下方向键调整",
|
|
94
|
+
"aria-label": `调整${e.name}顺序`,
|
|
95
|
+
onpointerdown: (ev) => {
|
|
96
|
+
if (ev.button !== 0 || saving) return;
|
|
97
|
+
ev.preventDefault();
|
|
98
|
+
drag = { before: ids(), y: ev.clientY, pointer: ev.pointerId };
|
|
99
|
+
handle.setPointerCapture(ev.pointerId);
|
|
100
|
+
},
|
|
101
|
+
onpointermove: (ev) => {
|
|
102
|
+
if (!drag || Math.abs(ev.clientY - drag.y) < 4) return;
|
|
103
|
+
row.classList.add("dragging");
|
|
104
|
+
const others = [...list.children].filter((el) => el !== row);
|
|
105
|
+
const to = others.filter((el) => { const r = el.getBoundingClientRect(); return ev.clientY > r.top + r.height / 2; }).length;
|
|
106
|
+
move(row, to);
|
|
107
|
+
handle.setPointerCapture(ev.pointerId);
|
|
108
|
+
},
|
|
109
|
+
onpointerup: end, onpointercancel: end,
|
|
110
|
+
onkeydown: (ev) => {
|
|
111
|
+
if (saving || !["ArrowUp", "ArrowDown"].includes(ev.key)) return;
|
|
112
|
+
ev.preventDefault();
|
|
113
|
+
const before = ids();
|
|
114
|
+
const to = before.indexOf(e.id) + (ev.key === "ArrowUp" ? -1 : 1);
|
|
115
|
+
if (to < 0 || to >= before.length) return;
|
|
116
|
+
move(row, to);
|
|
117
|
+
handle.focus();
|
|
118
|
+
void save(before);
|
|
119
|
+
},
|
|
120
|
+
}, "⋮⋮");
|
|
121
|
+
row.prepend(handle);
|
|
122
|
+
rows.set(e.id, row);
|
|
123
|
+
list.append(row);
|
|
124
|
+
}
|
|
46
125
|
fill(
|
|
47
126
|
box,
|
|
48
127
|
h(
|
|
@@ -51,23 +130,11 @@ function render(box, data, reload) {
|
|
|
51
130
|
h(
|
|
52
131
|
"p",
|
|
53
132
|
{ class: "skill-note" },
|
|
54
|
-
"
|
|
133
|
+
"拖动卡片左侧手柄调整顺序,自动保存并用于选择智能体。专家决定引擎、提示词和能力。共享给所有账号后,设定由创建者维护,每个人的记忆、技能和 MCP 仍各自独立;点「我的工具」选择自己要用的工具。内置的 Claude Code、Codex 在「设置 → Agent」各自卡片的「默认加载」中选择技能和 MCP。",
|
|
55
134
|
),
|
|
56
135
|
h("div", { class: "skill-head-btns" }, add),
|
|
57
136
|
),
|
|
58
|
-
|
|
59
|
-
"div",
|
|
60
|
-
{ class: "task-list" },
|
|
61
|
-
data.builtin.map((b) =>
|
|
62
|
-
h(
|
|
63
|
-
"div",
|
|
64
|
-
{ class: "task-card skill-card" },
|
|
65
|
-
h("div", { class: "task-top" }, h("span", { class: "task-title" }, agentIcon(b.engine, "expert-card-icon"), b.name), h("span", { class: "badge" }, "内置")),
|
|
66
|
-
h("div", { class: "task-prompt" }, `${b.name} 原装的样子:原装提示词、所有工具;默认技能和 MCP 在「设置 → Agent」里配置。`),
|
|
67
|
-
),
|
|
68
|
-
),
|
|
69
|
-
data.experts.map((e) => expertCard(data, e, reload)),
|
|
70
|
-
),
|
|
137
|
+
list,
|
|
71
138
|
data.experts.length ? null : h("div", { class: "tasks-empty" }, h("div", { class: "t" }, "还没有自己的专家"), h("div", { class: "s" }, "点「新建」建一个。")),
|
|
72
139
|
);
|
|
73
140
|
}
|
package/web/state.js
CHANGED
|
@@ -18,6 +18,8 @@ export const S = {
|
|
|
18
18
|
draftExpert: localStorage.getItem("aim.expert") || null,
|
|
19
19
|
/** 自己的专家(bootstrap 里给,设置里改了重新拉) */
|
|
20
20
|
experts: [],
|
|
21
|
+
/** 内置、自建和共享专家的展示顺序,随账号保存。 */
|
|
22
|
+
expertOrder: [],
|
|
21
23
|
/** 新对话(还没发消息)选的工作目录,null 表示工作区根目录。顶部新建时继承最近会话的目录 */
|
|
22
24
|
draftCwd: null,
|
|
23
25
|
/** 这个新对话的目录是自己选的:换专家时不再改成专家的默认目录。建好会话后清掉 */
|
package/web/views/experts.js
CHANGED
|
@@ -15,13 +15,19 @@ function usableEngines() {
|
|
|
15
15
|
return (usable.length ? usable : enabled).map((a) => a.id);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/**
|
|
18
|
+
/** 按账号设置的混合顺序展示,新出现的专家接在末尾。 */
|
|
19
|
+
export function sortExperts(experts, order = S.expertOrder) {
|
|
20
|
+
const rank = new Map((order ?? []).map((id, i) => [id, i]));
|
|
21
|
+
return [...experts].sort((a, b) => (rank.get(a.id) ?? Infinity) - (rank.get(b.id) ?? Infinity));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 能选的专家:引擎能用且有权限,按「设置 → 专家」中的顺序。 */
|
|
19
25
|
export function expertChoices() {
|
|
20
26
|
const engines = usableEngines();
|
|
21
|
-
return [
|
|
27
|
+
return sortExperts([
|
|
22
28
|
...engines.filter((id) => S.agents.find((a) => a.id === id)?.allowed !== false).map((id) => ({ id, name: agentLabel(id), engine: id, builtin: true })),
|
|
23
29
|
...S.experts.filter((e) => engines.includes(e.engine)),
|
|
24
|
-
];
|
|
30
|
+
]);
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
export function findExpert(id) {
|
|
@@ -67,6 +73,7 @@ export async function reloadExperts() {
|
|
|
67
73
|
try {
|
|
68
74
|
const d = await api("/api/experts/brief");
|
|
69
75
|
S.experts = d.experts ?? [];
|
|
76
|
+
S.expertOrder = d.expertOrder ?? [];
|
|
70
77
|
if (Array.isArray(d.builtin)) for (const a of S.agents) a.allowed = d.builtin.includes(a.id);
|
|
71
78
|
if (d.user) S.user = d.user;
|
|
72
79
|
if ("servers" in d) applyShellInfo(d.servers);
|
package/web/views/layout.js
CHANGED
|
@@ -157,6 +157,7 @@ export async function boot() {
|
|
|
157
157
|
applyBootstrap(data);
|
|
158
158
|
S.pending = new Map(data.pending.map((i) => [i.id, i]));
|
|
159
159
|
S.experts = data.experts ?? [];
|
|
160
|
+
S.expertOrder = data.expertOrder ?? [];
|
|
160
161
|
syncDraftExpert();
|
|
161
162
|
renderLayout();
|
|
162
163
|
reportDesktop();
|
package/web/views/sidebar.js
CHANGED
|
@@ -253,12 +253,15 @@ function orderSidebarGroups(dirs) {
|
|
|
253
253
|
const rank = new Map(sideState.order.map((d, i) => [d, i]));
|
|
254
254
|
const ranked = dirs.filter((d) => rank.has(d)).sort((a, b) => rank.get(a) - rank.get(b));
|
|
255
255
|
const fresh = dirs.filter((d) => !rank.has(d));
|
|
256
|
+
// 首次恢复「最近」时放到顶部;之后沿用用户排好的位置。
|
|
257
|
+
const top = fresh.includes("recent") ? ["recent"] : [];
|
|
258
|
+
const tail = fresh.filter((d) => d !== "recent");
|
|
256
259
|
if (fresh.length && orderSynced) {
|
|
257
|
-
sideState.order = [...sideState.order, ...
|
|
260
|
+
sideState.order = [...top, ...sideState.order, ...tail];
|
|
258
261
|
saveSideState();
|
|
259
262
|
void putDirOrder({ append: fresh });
|
|
260
263
|
}
|
|
261
|
-
return [...ranked, ...
|
|
264
|
+
return [...top, ...ranked, ...tail];
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
/** 拿到服务端存的顺序之前不往上写,免得这台设备本地的旧顺序盖掉别处排好的 */
|
|
@@ -377,13 +380,13 @@ function toggleSide(list, id) {
|
|
|
377
380
|
}
|
|
378
381
|
|
|
379
382
|
let autoOpenedFor = null;
|
|
380
|
-
const RECENT_LIMIT =
|
|
383
|
+
const RECENT_LIMIT = 5;
|
|
381
384
|
const PROJECT_LIMIT = 5;
|
|
382
385
|
/** 「展开显示」一次多显示几条 */
|
|
383
386
|
const MORE_STEP = 10;
|
|
384
387
|
|
|
385
388
|
// ---------- 分页(服务端见 channels/web/conv-pages.ts) ----------
|
|
386
|
-
// 打开页面只拿「最近」的前
|
|
389
|
+
// 打开页面只拿「最近」的前 5 条会话、展开着的目录各自的前 5 棵分叉树,
|
|
387
390
|
// 正在跑的、等你处理的、每个飞书机器人最近的一条也都在;点「展开显示」多显示 10 条,本地不够再按页拉。
|
|
388
391
|
// 新出现的、变活跃的会话经 WebSocket 的 conv 消息补进 S.convs。
|
|
389
392
|
// next:下一页的游标;null = 没有更多了;undefined = 这个目录还没拉过。
|
|
@@ -676,9 +679,28 @@ export function renderSidebar() {
|
|
|
676
679
|
botRows.push({ id, at: convs[0].activeAt, rows });
|
|
677
680
|
}
|
|
678
681
|
|
|
679
|
-
//
|
|
682
|
+
// 「最近」逐条按活跃时间排序,分叉也独立占一条;项目中仍按分叉树展示。
|
|
683
|
+
const webConvs = visible.filter((c) => c.channel === "web").sort((a, b) => b.activeAt - a.activeAt || (a.key < b.key ? 1 : -1));
|
|
684
|
+
const recentExpanded = !sideState.folded.includes("recent");
|
|
685
|
+
const recentRows = [h("div", { class: "proj-row recent-row", ...groupDragAttrs("recent") },
|
|
686
|
+
h("button", {
|
|
687
|
+
class: "conv-item proj", title: "最近\n拖动可调整顺序,右键更多操作",
|
|
688
|
+
"aria-expanded": String(recentExpanded), onclick: () => toggleSide("folded", "recent"),
|
|
689
|
+
}, h("span", { class: "title" }, "最近"), caret(!recentExpanded), recentExpanded ? null : status(webConvs.map((c) => c.key))),
|
|
690
|
+
)];
|
|
691
|
+
if (recentExpanded) {
|
|
692
|
+
const st = pages.recent;
|
|
693
|
+
const list = st.next ? webConvs.filter((c) => c.activeAt > st.next.at || (c.activeAt === st.next.at && c.key >= st.next.key)) : webConvs;
|
|
694
|
+
const load = (limit) => fetchPage(st, { scope: "recent", limit: String(limit) });
|
|
695
|
+
for (const c of list.slice(0, st.show)) recentRows.push(convRow(c, " sub recent", `${agentLabel(c.agent)} · ${c.cwd}`, !!c.forkOf));
|
|
696
|
+
if (!list.length && !st.loading) recentRows.push(h("div", { class: "conv-empty sub" }, "还没有会话"));
|
|
697
|
+
const btn = moreButton(st, list.length, RECENT_LIMIT, load);
|
|
698
|
+
if (btn) recentRows.push(h("div", { class: "sub-more recent-more" }, btn));
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// ---- Web 会话按工作目录分组,目录按用户排的顺序(见 orderSidebarGroups) ----
|
|
680
702
|
const byDir = new Map();
|
|
681
|
-
for (const c of
|
|
703
|
+
for (const c of webConvs) {
|
|
682
704
|
if (!byDir.has(c.cwd)) byDir.set(c.cwd, []);
|
|
683
705
|
byDir.get(c.cwd).push(c);
|
|
684
706
|
}
|
|
@@ -695,9 +717,10 @@ export function renderSidebar() {
|
|
|
695
717
|
for (const [dir, convs] of byDir) dirAt.set(dir, Math.max(dirAt.get(dir) ?? 0, convs[0].activeAt));
|
|
696
718
|
const dirsByActivity = [...dirAt.keys()].sort((a, b) => dirAt.get(b) - dirAt.get(a));
|
|
697
719
|
const groupRows = new Map(botRows.map((group) => [group.id, group.rows]));
|
|
720
|
+
groupRows.set("recent", recentRows);
|
|
698
721
|
const groupAt = new Map([...dirAt, ...botRows.map((group) => [group.id, group.at])]);
|
|
699
|
-
groupsByActivity = [...groupAt.keys()].sort((a, b) => groupAt.get(b) - groupAt.get(a));
|
|
700
|
-
sidebarGroups = orderSidebarGroups([...dirsByActivity, ...botRows.sort((a, b) => b.at - a.at).map((group) => group.id)]);
|
|
722
|
+
groupsByActivity = ["recent", ...[...groupAt.keys()].sort((a, b) => groupAt.get(b) - groupAt.get(a))];
|
|
723
|
+
sidebarGroups = orderSidebarGroups(["recent", ...dirsByActivity, ...botRows.sort((a, b) => b.at - a.at).map((group) => group.id)]);
|
|
701
724
|
if (dirAt.size) {
|
|
702
725
|
for (const dir of dirsByActivity) {
|
|
703
726
|
const convs = byDir.get(dir) ?? [];
|