agent-loft 0.2.58 → 0.2.60
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 -8
- package/package.json +2 -2
- package/src/channels/web/api.ts +26 -3
- package/src/channels/web/library-api.ts +59 -0
- package/src/core/chat-history.ts +92 -71
- package/src/core/db.ts +367 -0
- package/src/core/experts.ts +60 -2
- package/src/core/footers.ts +21 -43
- package/src/core/hub.ts +3 -16
- package/src/core/library.ts +401 -0
- package/src/core/memory.ts +34 -60
- package/src/core/store.ts +47 -19
- package/src/core/uploads.ts +3 -46
- package/src/core/usage.ts +62 -72
- package/src/main.ts +7 -6
- package/src/mcp/memory-server.ts +4 -7
- package/web/css/library.css +266 -0
- package/web/index.html +1 -0
- package/web/lib/dom.js +2 -0
- package/web/state.js +7 -4
- package/web/views/composer.js +36 -1
- package/web/views/layout.js +11 -0
- package/web/views/library.js +309 -0
- package/web/views/messages.js +3 -3
- package/web/views/remote.js +2 -1
- package/web/views/sidebar.js +1 -0
- package/web/views/topbar.js +7 -4
package/src/core/uploads.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 附件落盘:每条会话一个上传目录。发出去的附件收进资料库(见 library.ts),开新会话也不删;
|
|
2
|
+
// 对话没了、或者上传了一直没发的,启动时清掉(library.ts 的 tidyLibrary)。
|
|
2
3
|
//
|
|
3
4
|
// 放在家目录下而不是项目目录里,免得弄脏用户的仓库。agent 需要能直接读这些文件:
|
|
4
5
|
// Claude 通过 additionalDirectories 放行,Codex 的沙箱本来就允许读。
|
|
@@ -19,50 +20,6 @@ export function ensureUploadsDir(key: string): string {
|
|
|
19
20
|
return dir;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
/**
|
|
23
|
-
* keep:要保留的文件(绝对路径)。
|
|
24
|
-
* olderThan:只删修改时间早于它的(毫秒时间戳)—— 切换会话时用,保住切换途中刚收到的附件。
|
|
25
|
-
*/
|
|
26
|
-
export function clearUploads(key: string, keep: string[] = [], olderThan?: number): void {
|
|
27
|
-
try {
|
|
28
|
-
const dir = uploadsDirFor(key);
|
|
29
|
-
if (keep.length === 0 && olderThan === undefined) {
|
|
30
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const kept = new Set(keep.map((p) => path.resolve(p)));
|
|
34
|
-
for (const entry of fs.readdirSync(dir)) {
|
|
35
|
-
const full = path.join(dir, entry);
|
|
36
|
-
if (kept.has(full)) continue;
|
|
37
|
-
if (olderThan !== undefined && fs.statSync(full).mtimeMs >= olderThan) continue;
|
|
38
|
-
fs.rmSync(full, { recursive: true, force: true });
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
if ((err as NodeJS.ErrnoException).code === "ENOENT") return;
|
|
42
|
-
console.warn(`[附件] 清理 ${key} 的上传目录失败:`, err);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** 启动时清理:会话没了、或闲置过期的,目录一并删掉。 */
|
|
47
|
-
export function sweepUploads(isAlive: (key: string) => boolean): void {
|
|
48
|
-
let entries: string[];
|
|
49
|
-
try {
|
|
50
|
-
entries = fs.readdirSync(uploadsRoot);
|
|
51
|
-
} catch {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
for (const entry of entries) {
|
|
55
|
-
let key: string;
|
|
56
|
-
try {
|
|
57
|
-
key = decodeURIComponent(entry);
|
|
58
|
-
} catch {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (isAlive(key)) continue;
|
|
62
|
-
fs.rmSync(path.join(uploadsRoot, entry), { recursive: true, force: true });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
23
|
/** 去掉路径分隔符和控制字符,防止文件名把文件写到目录外面去。 */
|
|
67
24
|
export function safeName(name: string): string {
|
|
68
25
|
const cleaned = path
|
|
@@ -96,7 +53,7 @@ export function uniquePath(dir: string, name: string): string {
|
|
|
96
53
|
return candidate;
|
|
97
54
|
}
|
|
98
55
|
|
|
99
|
-
function kindOf(mediaType: string | undefined): AttachmentKind {
|
|
56
|
+
export function kindOf(mediaType: string | undefined): AttachmentKind {
|
|
100
57
|
if (mediaType?.startsWith("image/")) return "image";
|
|
101
58
|
if (mediaType?.startsWith("audio/")) return "audio";
|
|
102
59
|
if (mediaType?.startsWith("video/")) return "video";
|
package/src/core/usage.ts
CHANGED
|
@@ -5,52 +5,35 @@
|
|
|
5
5
|
// 按 agent 会话算,不按对话:/new、恢复旧会话、切 agent 之后显示的都是现在这个会话的。
|
|
6
6
|
// Codex 升级前跑过的轮次没有记录,从升级后开始算。
|
|
7
7
|
//
|
|
8
|
-
//
|
|
8
|
+
// 另外按天记一本账(设置 →「用量」按日 / 月 / 年统计):每次报上来的增量记到当天、
|
|
9
9
|
// 按「谁的对话 + 哪个 agent + 什么模型」分开。只从有这本账开始算,之前的用量没有日期,不补。
|
|
10
10
|
// 没报费用的(Codex)查的时候按模型单价估一个(见 pricing.ts)。
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
//
|
|
12
|
+
// 两本账都在数据库里(见 db.ts):usage_sessions 一个会话一行,usage_daily 一天一人一 agent 一模型一行。
|
|
13
|
+
import { sql, transaction } from "./db.js";
|
|
13
14
|
import { estimateCost } from "./pricing.js";
|
|
14
15
|
import type { TokenUsage } from "./types.js";
|
|
15
16
|
|
|
16
17
|
export type UsageTotals = Required<Omit<TokenUsage, "costUsd">> & { costUsd?: number; at: number };
|
|
17
|
-
type Store = Record<string, UsageTotals>;
|
|
18
18
|
|
|
19
19
|
/** 一天里某个人用某个 agent 的合计 */
|
|
20
20
|
export type DailyTotals = Required<Omit<TokenUsage, "costUsd">> & { costUsd?: number };
|
|
21
|
-
/** 按天的账:日期(服务器本地时间 YYYY-MM-DD)→「owner\tagent\tmodel」→ 合计。没有主人、不知道模型的是空串 */
|
|
22
|
-
type Ledger = Record<string, Record<string, DailyTotals>>;
|
|
23
21
|
/** 查询结果的一行。estimated:costUsd 是按单价估的,不是 agent 报的 */
|
|
24
22
|
export type DailyRow = DailyTotals & { day: string; owner?: string; agent: string; model?: string; estimated?: true };
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
const DAILY_FILE = () => path.join(dataDir, "usage-daily.json");
|
|
28
|
-
const MAX_SESSIONS = 1000;
|
|
29
|
-
/** 按天的账留多久(天) */
|
|
30
|
-
const MAX_DAYS = 3 * 366;
|
|
31
|
-
|
|
32
|
-
let store: Store | null = null;
|
|
33
|
-
let ledger: Ledger | null = null;
|
|
34
|
-
let timer: NodeJS.Timeout | null = null;
|
|
35
|
-
|
|
36
|
-
function load(): Store {
|
|
37
|
-
return (store ??= readJson<Store>(FILE(), {}));
|
|
38
|
-
}
|
|
24
|
+
type TotalsRow = { input: number; cache_read: number; cache_write: number; output: number; reasoning: number; cost_usd: number | null };
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
return (ledger ??= readJson<Ledger>(DAILY_FILE(), {}));
|
|
42
|
-
}
|
|
26
|
+
const TOTALS = "input, cache_read, cache_write, output, reasoning, cost_usd";
|
|
43
27
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
writeJsonAtomic(DAILY_FILE(), l);
|
|
28
|
+
function fromRow<T extends TotalsRow>(r: T): DailyTotals {
|
|
29
|
+
return {
|
|
30
|
+
input: r.input,
|
|
31
|
+
cacheRead: r.cache_read,
|
|
32
|
+
cacheWrite: r.cache_write,
|
|
33
|
+
output: r.output,
|
|
34
|
+
reasoning: r.reasoning,
|
|
35
|
+
...(r.cost_usd ? { costUsd: r.cost_usd } : {}),
|
|
36
|
+
};
|
|
54
37
|
}
|
|
55
38
|
|
|
56
39
|
/** 本地时间的 YYYY-MM-DD */
|
|
@@ -59,23 +42,6 @@ export function dayOf(ms: number): string {
|
|
|
59
42
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
60
43
|
}
|
|
61
44
|
|
|
62
|
-
function persistSoon(): void {
|
|
63
|
-
if (timer) return;
|
|
64
|
-
timer = setTimeout(() => {
|
|
65
|
-
timer = null;
|
|
66
|
-
write();
|
|
67
|
-
}, 1000);
|
|
68
|
-
timer.unref();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** 退出前把还没写的落盘 */
|
|
72
|
-
export function flushUsage(): void {
|
|
73
|
-
if (!timer) return;
|
|
74
|
-
clearTimeout(timer);
|
|
75
|
-
timer = null;
|
|
76
|
-
write();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
45
|
const num = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) && v > 0 ? v : 0);
|
|
80
46
|
|
|
81
47
|
const FIELDS = ["input", "cacheRead", "cacheWrite", "output", "reasoning"] as const;
|
|
@@ -92,8 +58,26 @@ export function recordUsage(
|
|
|
92
58
|
by?: { owner?: string; agent: string; model?: string },
|
|
93
59
|
): void {
|
|
94
60
|
if (!sessionId) return;
|
|
95
|
-
|
|
96
|
-
|
|
61
|
+
transaction(() => {
|
|
62
|
+
const t = usageOf(sessionId) ?? { input: 0, cacheRead: 0, cacheWrite: 0, output: 0, reasoning: 0, at: 0 };
|
|
63
|
+
const delta = accumulate(t, usage, cumulative);
|
|
64
|
+
t.at = Date.now();
|
|
65
|
+
sql(`INSERT OR REPLACE INTO usage_sessions (session_id, ${TOTALS}, at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(
|
|
66
|
+
sessionId,
|
|
67
|
+
t.input,
|
|
68
|
+
t.cacheRead,
|
|
69
|
+
t.cacheWrite,
|
|
70
|
+
t.output,
|
|
71
|
+
t.reasoning,
|
|
72
|
+
t.costUsd ?? null,
|
|
73
|
+
t.at,
|
|
74
|
+
);
|
|
75
|
+
if (by) addDaily(t.at, by, delta);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 把这次报上来的加进会话的总数(就地改 t),返回比原来多了多少 */
|
|
80
|
+
function accumulate(t: UsageTotals, usage: TokenUsage, cumulative: boolean): DailyTotals {
|
|
97
81
|
const delta: DailyTotals = { input: 0, cacheRead: 0, cacheWrite: 0, output: 0, reasoning: 0 };
|
|
98
82
|
for (const f of FIELDS) {
|
|
99
83
|
const next = cumulative ? Math.max(t[f], num(usage[f])) : t[f] + num(usage[f]);
|
|
@@ -106,39 +90,45 @@ export function recordUsage(
|
|
|
106
90
|
if (next > (t.costUsd ?? 0)) delta.costUsd = next - (t.costUsd ?? 0);
|
|
107
91
|
t.costUsd = next;
|
|
108
92
|
}
|
|
109
|
-
|
|
110
|
-
if (by) addDaily(t.at, by, delta);
|
|
111
|
-
persistSoon();
|
|
93
|
+
return delta;
|
|
112
94
|
}
|
|
113
95
|
|
|
114
96
|
function addDaily(at: number, by: { owner?: string; agent: string; model?: string }, delta: DailyTotals): void {
|
|
115
97
|
if (!FIELDS.some((f) => delta[f] > 0) && !delta.costUsd) return;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
98
|
+
sql(
|
|
99
|
+
`INSERT INTO usage_daily (day, owner, agent, model, ${TOTALS}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
100
|
+
ON CONFLICT (day, owner, agent, model) DO UPDATE SET
|
|
101
|
+
input = input + excluded.input, cache_read = cache_read + excluded.cache_read,
|
|
102
|
+
cache_write = cache_write + excluded.cache_write, output = output + excluded.output,
|
|
103
|
+
reasoning = reasoning + excluded.reasoning,
|
|
104
|
+
cost_usd = CASE WHEN excluded.cost_usd IS NULL THEN cost_usd ELSE coalesce(cost_usd, 0) + excluded.cost_usd END`,
|
|
105
|
+
).run(dayOf(at), by.owner ?? "", by.agent, by.model ?? "", delta.input, delta.cacheRead, delta.cacheWrite, delta.output, delta.reasoning, delta.costUsd ?? null);
|
|
120
106
|
}
|
|
121
107
|
|
|
122
108
|
/** 按天的账里 from ~ to(含两头,YYYY-MM-DD)的行;visible 按主人过滤 */
|
|
123
109
|
export function dailyUsage(from: string, to: string, visible?: (owner: string | undefined) => boolean): DailyRow[] {
|
|
110
|
+
const found = sql(`SELECT day, owner, agent, model, ${TOTALS} FROM usage_daily WHERE day >= ? AND day <= ? ORDER BY day`).all(from, to) as (TotalsRow & {
|
|
111
|
+
day: string;
|
|
112
|
+
owner: string;
|
|
113
|
+
agent: string;
|
|
114
|
+
model: string;
|
|
115
|
+
})[];
|
|
124
116
|
const rows: DailyRow[] = [];
|
|
125
|
-
for (const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!row.costUsd) {
|
|
133
|
-
const est = estimateCost(model, row);
|
|
134
|
-
if (est) Object.assign(row, { costUsd: est, estimated: true });
|
|
135
|
-
}
|
|
136
|
-
rows.push(row);
|
|
117
|
+
for (const r of found) {
|
|
118
|
+
const owner = r.owner || undefined;
|
|
119
|
+
if (visible && !visible(owner)) continue;
|
|
120
|
+
const row: DailyRow = { day: r.day, ...(owner ? { owner } : {}), agent: r.agent, ...(r.model ? { model: r.model } : {}), ...fromRow(r) };
|
|
121
|
+
if (!row.costUsd) {
|
|
122
|
+
const est = estimateCost(r.model, row);
|
|
123
|
+
if (est) Object.assign(row, { costUsd: est, estimated: true });
|
|
137
124
|
}
|
|
125
|
+
rows.push(row);
|
|
138
126
|
}
|
|
139
|
-
return rows
|
|
127
|
+
return rows;
|
|
140
128
|
}
|
|
141
129
|
|
|
142
130
|
export function usageOf(sessionId: string | undefined): UsageTotals | undefined {
|
|
143
|
-
|
|
131
|
+
if (!sessionId) return undefined;
|
|
132
|
+
const r = sql(`SELECT ${TOTALS}, at FROM usage_sessions WHERE session_id = ?`).get(sessionId) as (TotalsRow & { at: number }) | undefined;
|
|
133
|
+
return r ? { ...fromRow(r), at: r.at } : undefined;
|
|
144
134
|
}
|
package/src/main.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// 入口:拉起 agent 驱动、飞书机器人和 Web 服务。
|
|
2
2
|
import { config, loadConfig, onConfigChange } from "./core/config.js";
|
|
3
3
|
import { hub } from "./core/hub.js";
|
|
4
|
-
import { flushStore, getConversation
|
|
5
|
-
import {
|
|
4
|
+
import { flushStore, getConversation } from "./core/store.js";
|
|
5
|
+
import { backfillLibrary, startLibraryCapture, tidyLibrary } from "./core/library.js";
|
|
6
6
|
import { ClaudeDriver } from "./agents/claude/driver.js";
|
|
7
7
|
import { CodexDriver } from "./agents/codex/driver.js";
|
|
8
8
|
import { agentHealth } from "./agents/health.js";
|
|
@@ -40,10 +40,11 @@ async function main(): Promise<void> {
|
|
|
40
40
|
if (next.agents.codex.enabled && !prev.agents.codex.enabled) void startDriver("codex");
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// 资料库:升级时把已有的附件收进来(只一次),再清掉对话没了的、上传了一直没发的
|
|
44
|
+
const backfilled = backfillLibrary();
|
|
45
|
+
if (backfilled) console.log(`[资料库] 已收录上传目录里原有的 ${backfilled} 个文件`);
|
|
46
|
+
tidyLibrary();
|
|
47
|
+
startLibraryCapture();
|
|
47
48
|
|
|
48
49
|
// 聊天记录索引和聊完后的记忆整理
|
|
49
50
|
migrateMemoryDefault(listUsers().map((u) => u.id));
|
package/src/mcp/memory-server.ts
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
//
|
|
6
6
|
// 只实现 MCP 里用得到的那一小块:initialize、tools/list、tools/call、ping。
|
|
7
7
|
// 传输是一行一条 JSON(MCP stdio 的规定),stdout 只能写协议消息,日志一律走 stderr。
|
|
8
|
-
import path from "node:path";
|
|
9
8
|
import { addMemoryEntry, localDate, MEMORY_LIMITS, removeMemoryItem } from "../core/memory.js";
|
|
10
9
|
import { searchHistory } from "../core/chat-history.js";
|
|
11
|
-
import {
|
|
10
|
+
import { conversationLabels } from "../core/store.js";
|
|
12
11
|
|
|
13
12
|
const userId = process.env.AGENT_LOFT_MEMORY_USER ?? "";
|
|
14
13
|
const via = process.env.AGENT_LOFT_MEMORY_VIA ?? "";
|
|
@@ -60,20 +59,18 @@ const TOOLS = [
|
|
|
60
59
|
},
|
|
61
60
|
].filter((t) => t.name !== "search_past_chats" || searchEnabled);
|
|
62
61
|
|
|
63
|
-
type ConvMeta = { title?: string; hidden?: boolean; agent?: string };
|
|
64
|
-
|
|
65
62
|
function search(query: string, limit: number) {
|
|
66
63
|
if (!searchEnabled) return text("没有开启「参考以前的聊天」。", true);
|
|
67
64
|
if (!query.trim()) return text("要给关键词。", true);
|
|
68
65
|
// 每次现读:用户在 Web 上删掉的对话(隐藏)立刻搜不到
|
|
69
|
-
const convs =
|
|
66
|
+
const convs = conversationLabels();
|
|
70
67
|
const hits = searchHistory(userId, query, {
|
|
71
68
|
limit: Math.max(1, Math.min(15, Math.round(limit) || 6)),
|
|
72
|
-
skip: (k) => k === currentConv || !!convs
|
|
69
|
+
skip: (k) => k === currentConv || !!convs.get(k)?.hidden,
|
|
73
70
|
});
|
|
74
71
|
if (hits.length === 0) return text(`以前的聊天里没找到「${query}」相关的内容。可以换个说法再搜。`);
|
|
75
72
|
const blocks = hits.map((h, i) => {
|
|
76
|
-
const title = convs
|
|
73
|
+
const title = convs.get(h.key)?.title ?? (h.key.startsWith("feishu:") ? "飞书私聊" : "未命名对话");
|
|
77
74
|
return [
|
|
78
75
|
`[${i + 1}] ${localDate(h.ts)} · 「${title}」`,
|
|
79
76
|
...(h.user ? [`用户:${h.user}`] : []),
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/* ---------- 资料库 ---------- */
|
|
2
|
+
/* 页面沿用定时任务页的外框(.tasks-page / .tasks-head),这里只管文件网格。弹窗「从资料库选」用同一套 */
|
|
3
|
+
|
|
4
|
+
.lib-page .tasks-head p .lib-status {
|
|
5
|
+
margin-left: 6px;
|
|
6
|
+
color: var(--fg-faint);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.lib-browser {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
gap: 14px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.lib-bar {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: 12px;
|
|
19
|
+
flex-wrap: wrap;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.lib-tabs {
|
|
23
|
+
display: flex;
|
|
24
|
+
gap: 4px;
|
|
25
|
+
padding: 3px;
|
|
26
|
+
background: var(--bg-soft);
|
|
27
|
+
border-radius: 10px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.lib-tab {
|
|
31
|
+
padding: 5px 12px;
|
|
32
|
+
border: none;
|
|
33
|
+
border-radius: 8px;
|
|
34
|
+
background: transparent;
|
|
35
|
+
color: var(--fg-soft);
|
|
36
|
+
font: inherit;
|
|
37
|
+
font-size: 13px;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.lib-tab.active {
|
|
42
|
+
background: var(--bg);
|
|
43
|
+
color: var(--fg);
|
|
44
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.lib-search {
|
|
48
|
+
flex: 1;
|
|
49
|
+
min-width: 160px;
|
|
50
|
+
max-width: 280px;
|
|
51
|
+
margin-left: auto;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.lib-grid {
|
|
55
|
+
display: grid;
|
|
56
|
+
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
|
57
|
+
gap: 12px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.lib-empty {
|
|
61
|
+
grid-column: 1 / -1;
|
|
62
|
+
display: flex;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
padding: 48px 12px;
|
|
65
|
+
color: var(--fg-faint);
|
|
66
|
+
font-size: 14px;
|
|
67
|
+
text-align: center;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.lib-tile {
|
|
71
|
+
position: relative;
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-direction: column;
|
|
74
|
+
min-width: 0;
|
|
75
|
+
border: 1px solid var(--border);
|
|
76
|
+
border-radius: 12px;
|
|
77
|
+
background: var(--bg);
|
|
78
|
+
overflow: hidden;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.lib-tile.selected {
|
|
82
|
+
border-color: var(--accent);
|
|
83
|
+
box-shadow: 0 0 0 1px var(--accent);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.lib-thumb {
|
|
87
|
+
display: grid;
|
|
88
|
+
place-items: center;
|
|
89
|
+
aspect-ratio: 4 / 3;
|
|
90
|
+
width: 100%;
|
|
91
|
+
padding: 0;
|
|
92
|
+
border: none;
|
|
93
|
+
background: var(--bg-soft);
|
|
94
|
+
cursor: pointer;
|
|
95
|
+
overflow: hidden;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.lib-thumb img {
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: 100%;
|
|
101
|
+
object-fit: cover;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.lib-ext {
|
|
105
|
+
font-size: 15px;
|
|
106
|
+
font-weight: 600;
|
|
107
|
+
letter-spacing: 0.04em;
|
|
108
|
+
color: var(--fg-soft);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.lib-meta {
|
|
112
|
+
display: flex;
|
|
113
|
+
flex-direction: column;
|
|
114
|
+
gap: 2px;
|
|
115
|
+
padding: 8px 10px 9px;
|
|
116
|
+
min-width: 0;
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.lib-name {
|
|
121
|
+
font-size: 13px;
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
overflow: hidden;
|
|
124
|
+
text-overflow: ellipsis;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.lib-sub,
|
|
128
|
+
.lib-conv {
|
|
129
|
+
display: flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
gap: 6px;
|
|
132
|
+
font-size: 12px;
|
|
133
|
+
color: var(--fg-faint);
|
|
134
|
+
white-space: nowrap;
|
|
135
|
+
overflow: hidden;
|
|
136
|
+
text-overflow: ellipsis;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.lib-conv {
|
|
140
|
+
display: block;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.lib-badge {
|
|
144
|
+
flex: none;
|
|
145
|
+
padding: 0 5px;
|
|
146
|
+
border-radius: 4px;
|
|
147
|
+
background: var(--ask-bg);
|
|
148
|
+
color: var(--fg-soft);
|
|
149
|
+
font-size: 11px;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* 右上角:菜单按钮(鼠标停上去才出来,触屏一直在)、选择框 */
|
|
153
|
+
.lib-menu {
|
|
154
|
+
position: absolute;
|
|
155
|
+
top: 6px;
|
|
156
|
+
right: 6px;
|
|
157
|
+
width: 28px;
|
|
158
|
+
height: 28px;
|
|
159
|
+
background: var(--bg);
|
|
160
|
+
border-radius: 8px;
|
|
161
|
+
box-shadow: var(--shadow);
|
|
162
|
+
opacity: 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.lib-tile:hover .lib-menu,
|
|
166
|
+
.lib-menu:focus-visible {
|
|
167
|
+
opacity: 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@media (pointer: coarse) {
|
|
171
|
+
.lib-menu {
|
|
172
|
+
opacity: 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.lib-check {
|
|
177
|
+
position: absolute;
|
|
178
|
+
top: 8px;
|
|
179
|
+
left: 8px;
|
|
180
|
+
display: grid;
|
|
181
|
+
place-items: center;
|
|
182
|
+
width: 22px;
|
|
183
|
+
height: 22px;
|
|
184
|
+
border: 2px solid #fff;
|
|
185
|
+
border-radius: 50%;
|
|
186
|
+
background: rgba(0, 0, 0, 0.25);
|
|
187
|
+
color: #fff;
|
|
188
|
+
cursor: pointer;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.lib-tile.selected .lib-check {
|
|
192
|
+
background: var(--accent);
|
|
193
|
+
border-color: var(--accent);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.lib-check svg {
|
|
197
|
+
width: 14px;
|
|
198
|
+
height: 14px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.lib-more {
|
|
202
|
+
align-self: center;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.lib-more[hidden] {
|
|
206
|
+
display: none;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* 选择模式下贴在页面底部的操作条 */
|
|
210
|
+
.lib-selbar {
|
|
211
|
+
position: sticky;
|
|
212
|
+
bottom: 12px;
|
|
213
|
+
display: flex;
|
|
214
|
+
align-items: center;
|
|
215
|
+
gap: 8px;
|
|
216
|
+
padding: 10px 12px;
|
|
217
|
+
border: 1px solid var(--border);
|
|
218
|
+
border-radius: 12px;
|
|
219
|
+
background: var(--bg);
|
|
220
|
+
box-shadow: var(--shadow);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.lib-selbar[hidden] {
|
|
224
|
+
display: none;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.lib-selbar .grow {
|
|
228
|
+
flex: 1;
|
|
229
|
+
font-size: 13px;
|
|
230
|
+
color: var(--fg-soft);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* 弹窗:网格在中间滚,筛选条和底部按钮不动 */
|
|
234
|
+
.lib-pick .modal-body {
|
|
235
|
+
flex: 1;
|
|
236
|
+
display: flex;
|
|
237
|
+
flex-direction: column;
|
|
238
|
+
min-height: 0;
|
|
239
|
+
overflow: auto;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.lib-pick .modal-foot {
|
|
243
|
+
align-items: center;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.lib-pick .lib-grid {
|
|
247
|
+
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.lib-pick .modal-foot .grow {
|
|
251
|
+
font-size: 13px;
|
|
252
|
+
color: var(--fg-faint);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* 窄屏:搜索框换到下一行时占满一行 */
|
|
256
|
+
@media (max-width: 600px) {
|
|
257
|
+
.lib-search {
|
|
258
|
+
flex-basis: 100%;
|
|
259
|
+
max-width: none;
|
|
260
|
+
margin-left: 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.lib-grid {
|
|
264
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
265
|
+
}
|
|
266
|
+
}
|
package/web/index.html
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
<link rel="stylesheet" href="/css/schedule.css" />
|
|
28
28
|
<link rel="stylesheet" href="/css/todos.css" />
|
|
29
29
|
<link rel="stylesheet" href="/css/tasks.css" />
|
|
30
|
+
<link rel="stylesheet" href="/css/library.css" />
|
|
30
31
|
<link rel="stylesheet" href="/css/skills.css" />
|
|
31
32
|
<link rel="stylesheet" href="/css/experts.css" />
|
|
32
33
|
<link rel="stylesheet" href="/css/terminal.css" />
|
package/web/lib/dom.js
CHANGED
|
@@ -47,6 +47,8 @@ export const ICON = {
|
|
|
47
47
|
x: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M18 6 6 18M6 6l12 12"/></svg>',
|
|
48
48
|
plus: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M12 5v14M5 12h14"/></svg>',
|
|
49
49
|
trash: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M8 6V4h8v2"/><path d="M19 6l-1 14H6L5 6"/><path d="M10 11v6M14 11v6"/></svg>',
|
|
50
|
+
library: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="7" width="14" height="14" rx="2"/><path d="M7 3h12a2 2 0 0 1 2 2v12"/><path d="m3 17 4-4 3 3 2-2 5 5"/></svg>',
|
|
51
|
+
check: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12.5 4.5 4.5L19 7.5"/></svg>',
|
|
50
52
|
folder: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7.5A2.5 2.5 0 0 1 5.5 5h3.6l2 2.2h7.4A2.5 2.5 0 0 1 21 9.7v7.8a2.5 2.5 0 0 1-2.5 2.5h-13A2.5 2.5 0 0 1 3 17.5Z"/><path d="M3 10h18"/></svg>',
|
|
51
53
|
folderOpen: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 17.5V7.5A2.5 2.5 0 0 1 5.5 5h3.6l2 2.2h6.4A2.5 2.5 0 0 1 20 9.7V11"/><path d="M3 17.5 5.6 12a2 2 0 0 1 1.8-1.1h13a1 1 0 0 1 .9 1.4l-2.4 6.2a2.2 2.2 0 0 1-2 1.5H5.5A2.5 2.5 0 0 1 3 17.5Z"/></svg>',
|
|
52
54
|
terminal: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/></svg>',
|
package/web/state.js
CHANGED
|
@@ -30,7 +30,7 @@ export const S = {
|
|
|
30
30
|
remote: null,
|
|
31
31
|
/** 远程控制在后台连着的:桌面连着没、开着几个终端(侧栏「远程控制」上的小绿点) */
|
|
32
32
|
remoteLive: { desktop: false, terminals: 0 },
|
|
33
|
-
/** 主区域在显示什么:null 是对话(或新对话),"tasks" 是定时任务页,"remote" 是远程控制 */
|
|
33
|
+
/** 主区域在显示什么:null 是对话(或新对话),"tasks" 是定时任务页,"library" 是资料库,"remote" 是远程控制 */
|
|
34
34
|
view: null,
|
|
35
35
|
};
|
|
36
36
|
|
|
@@ -57,9 +57,12 @@ export const desktopQuota = typeof desktop?.onQuota === "function";
|
|
|
57
57
|
// 桌面端里:顶栏、侧栏顶部可以按住拖动窗口(样式见 css/topbar.css 的 .in-desktop)
|
|
58
58
|
if (desktop) document.documentElement.classList.add("in-desktop");
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
60
|
+
* 桌面端 0.1.18 及以前的顶栏能打开每台服务器的设置(「更多」或设置按钮的菜单里):页面「更多」里的设置就不放了。
|
|
61
|
+
* 更老的和 0.1.19 起的桌面端没有这个入口(不给 onOpenSettings),照旧放。
|
|
62
62
|
*/
|
|
63
63
|
export const desktopSettings = typeof desktop?.onOpenSettings === "function";
|
|
64
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* 桌面端 0.1.9 ~ 0.1.17:页面右上角的「更多」整个交给桌面端顶栏的「更多」(排在最上面),页面上不显示这个按钮。
|
|
66
|
+
* 0.1.18 起桌面端去掉了自己的「更多」,不再给 setMenu,页面照常显示
|
|
67
|
+
*/
|
|
65
68
|
export const desktopMenu = typeof desktop?.setMenu === "function";
|