agent-loft 0.2.29 → 0.2.31
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 -0
- package/package.json +1 -1
- package/src/agents/claude/driver.ts +3 -2
- package/src/agents/claude/session.ts +11 -4
- package/src/agents/codex/session.ts +9 -3
- package/src/channels/feishu/bot.ts +8 -4
- package/src/channels/feishu/turn-stream.ts +3 -2
- package/src/channels/web/api.ts +4 -0
- package/src/channels/web/server.ts +14 -2
- package/src/channels/web/tasks-api.ts +94 -0
- package/src/core/chat-mode.ts +14 -14
- package/src/core/hub.ts +95 -16
- package/src/core/memory-mcp.ts +1 -1
- package/src/core/personal.ts +3 -1
- package/src/core/store.ts +2 -0
- package/src/core/task-prompt.ts +38 -0
- package/src/core/task-runner.ts +232 -0
- package/src/core/task-schedule.ts +250 -0
- package/src/core/tasks-bridge.ts +252 -0
- package/src/core/tasks-mcp.ts +55 -0
- package/src/core/tasks.ts +281 -0
- package/src/core/types.ts +2 -0
- package/src/main.ts +8 -0
- package/src/mcp/tasks-server.ts +206 -0
- package/web/app.js +8 -5560
- package/web/css/base.css +291 -0
- package/web/css/composer.css +506 -0
- package/web/css/loader.css +196 -0
- package/web/css/messages.css +734 -0
- package/web/css/mobile.css +100 -0
- package/web/css/overlay.css +437 -0
- package/web/css/schedule.css +93 -0
- package/web/css/settings.css +335 -0
- package/web/css/sidebar.css +593 -0
- package/web/css/tasks.css +455 -0
- package/web/css/topbar.css +205 -0
- package/web/index.html +12 -1
- package/web/lib/api.js +26 -0
- package/web/lib/dom.js +101 -0
- package/web/lib/markdown.js +52 -0
- package/web/lib/overlay.js +144 -0
- package/web/lib/push.js +70 -0
- package/web/lib/time.js +60 -0
- package/web/lib/ws.js +236 -0
- package/web/settings/agents.js +210 -0
- package/web/settings/commands.js +411 -0
- package/web/settings/common.js +42 -0
- package/web/settings/feishu.js +181 -0
- package/web/settings/general.js +184 -0
- package/web/settings/index.js +63 -0
- package/web/settings/memory.js +366 -0
- package/web/settings/notify.js +80 -0
- package/web/settings/security.js +188 -0
- package/web/settings/users.js +189 -0
- package/web/state.js +46 -0
- package/web/views/auth.js +61 -0
- package/web/views/composer.js +324 -0
- package/web/views/conv-actions.js +412 -0
- package/web/views/interaction.js +140 -0
- package/web/views/layout.js +197 -0
- package/web/views/messages.js +531 -0
- package/web/views/quota.js +145 -0
- package/web/views/schedule.js +120 -0
- package/web/views/sidebar.js +458 -0
- package/web/views/slash.js +185 -0
- package/web/views/tasks.js +460 -0
- package/web/views/topbar.js +400 -0
- package/web/views/voice.js +189 -0
- package/web/style.css +0 -3500
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { fill, h, toast } from "../lib/dom.js";
|
|
2
|
+
import { api } from "../lib/api.js";
|
|
3
|
+
import { relTime } from "../lib/time.js";
|
|
4
|
+
import { copyText } from "../lib/markdown.js";
|
|
5
|
+
import { agentCatalog } from "../views/topbar.js";
|
|
6
|
+
import { confirmDialog } from "../lib/overlay.js";
|
|
7
|
+
import { field } from "./common.js";
|
|
8
|
+
|
|
9
|
+
// ---------- 记忆(每个人自己的) ----------
|
|
10
|
+
|
|
11
|
+
export async function memoryTab(panel) {
|
|
12
|
+
const box = h("div", { class: "section" }, h("h4", {}, "记忆"), h("span", { class: "spinner" }));
|
|
13
|
+
fill(panel, box);
|
|
14
|
+
let mem;
|
|
15
|
+
try {
|
|
16
|
+
mem = await api("/api/account/memory");
|
|
17
|
+
} catch (err) {
|
|
18
|
+
fill(box, h("h4", {}, "记忆"), h("div", { class: "error-text" }, err.message));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const reload = () => void memoryTab(panel);
|
|
22
|
+
const run = (btn, fn) => async () => {
|
|
23
|
+
btn.disabled = true;
|
|
24
|
+
try {
|
|
25
|
+
if ((await fn()) !== false) reload();
|
|
26
|
+
} catch (err) {
|
|
27
|
+
toast(err.message);
|
|
28
|
+
btn.disabled = false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const enabled = h("input", { type: "checkbox", checked: mem.enabled });
|
|
33
|
+
enabled.onchange = async () => {
|
|
34
|
+
try {
|
|
35
|
+
await api("/api/account/memory", { method: "PUT", body: { enabled: enabled.checked } });
|
|
36
|
+
toast(enabled.checked ? "记忆已开启" : "记忆已关闭,已有的内容保留");
|
|
37
|
+
} catch (err) {
|
|
38
|
+
enabled.checked = !enabled.checked;
|
|
39
|
+
toast(err.message);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** 一个开关:改了立刻存 */
|
|
44
|
+
const toggle = (key, label, on, off) => {
|
|
45
|
+
const box = h("input", { type: "checkbox", checked: mem[key] });
|
|
46
|
+
box.onchange = async () => {
|
|
47
|
+
try {
|
|
48
|
+
await api("/api/account/memory", { method: "PUT", body: { [key]: box.checked } });
|
|
49
|
+
toast(box.checked ? on : off);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
box.checked = !box.checked;
|
|
52
|
+
toast(err.message);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return h("label", { class: "check" }, box, label);
|
|
56
|
+
};
|
|
57
|
+
const history = await api("/api/account/history").catch(() => null);
|
|
58
|
+
const clearHistory = h("button", { class: "btn small" }, "清空聊天记录索引");
|
|
59
|
+
clearHistory.onclick = run(clearHistory, async () => {
|
|
60
|
+
const sure = await confirmDialog({
|
|
61
|
+
title: "清空聊天记录索引?",
|
|
62
|
+
message: "agent 将搜不到以前的聊天(对话本身不删,侧栏里照样能打开)。之后的聊天还会继续记进来。",
|
|
63
|
+
confirmText: "清空",
|
|
64
|
+
danger: true,
|
|
65
|
+
});
|
|
66
|
+
if (!sure) return false;
|
|
67
|
+
await api("/api/account/history", { method: "DELETE" });
|
|
68
|
+
toast("已清空");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const about = h("textarea", { rows: 5, maxlength: mem.limits.about, placeholder: "比如:我叫小明,在深圳做后端开发,家里有台 QNAP NAS。回答尽量简短,代码用 TypeScript。" });
|
|
72
|
+
about.value = mem.about;
|
|
73
|
+
const saveAbout = h("button", { class: "btn primary" }, "保存");
|
|
74
|
+
saveAbout.onclick = run(saveAbout, async () => {
|
|
75
|
+
await api("/api/account/memory", { method: "PUT", body: { about: about.value } });
|
|
76
|
+
toast("已保存,之后的对话会用上");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const newItem = h("input", { maxlength: mem.limits.item, style: { flex: "1", minWidth: "0" }, placeholder: "手动加一条,比如:我的软路由是 iStoreOS,地址 192.168.8.2" });
|
|
80
|
+
const addBtn = h("button", { class: "btn" }, "添加");
|
|
81
|
+
addBtn.onclick = run(addBtn, async () => {
|
|
82
|
+
if (!newItem.value.trim()) return false;
|
|
83
|
+
await api("/api/account/memory/items", { method: "POST", body: { text: newItem.value } });
|
|
84
|
+
});
|
|
85
|
+
newItem.onkeydown = (e) => {
|
|
86
|
+
if (e.key === "Enter" && !e.isComposing) addBtn.click();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const items = [...mem.items].sort((a, b) => b.updatedAt - a.updatedAt);
|
|
90
|
+
const itemRow = (it) => {
|
|
91
|
+
const from = { user: "你加的", agent: "agent 在聊天里记的", auto: "聊完后自动整理的" }[it.source] ?? "agent 记的";
|
|
92
|
+
const body = h("div", { class: "grow" }, h("div", { class: "t", style: { whiteSpace: "pre-wrap" } }, it.text), h("div", { class: "s" }, `${from} · ${relTime(it.updatedAt)}`));
|
|
93
|
+
const edit = h("button", { class: "btn small" }, "编辑");
|
|
94
|
+
const del = h("button", { class: "btn small danger" }, "删除");
|
|
95
|
+
edit.onclick = () => {
|
|
96
|
+
const input = h("textarea", { rows: 2, maxlength: mem.limits.item });
|
|
97
|
+
input.value = it.text;
|
|
98
|
+
const ok = h("button", { class: "btn small primary" }, "保存");
|
|
99
|
+
ok.onclick = run(ok, () => api(`/api/account/memory/items/${it.id}`, { method: "PATCH", body: { text: input.value } }));
|
|
100
|
+
fill(body, input, h("div", { class: "row" }, ok, h("button", { class: "btn small", onclick: reload }, "取消")));
|
|
101
|
+
input.focus();
|
|
102
|
+
};
|
|
103
|
+
del.onclick = run(del, () => api(`/api/account/memory/items/${it.id}`, { method: "DELETE" }));
|
|
104
|
+
return h("div", { class: "list-item" }, body, edit, del);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const clearBtn = h("button", { class: "btn danger" }, "清空全部记忆");
|
|
108
|
+
clearBtn.onclick = run(clearBtn, async () => {
|
|
109
|
+
const sure = await confirmDialog({
|
|
110
|
+
title: "清空全部记忆?",
|
|
111
|
+
message: "「关于我」和所有记住的事都会删除,不能恢复。",
|
|
112
|
+
confirmText: "清空",
|
|
113
|
+
danger: true,
|
|
114
|
+
});
|
|
115
|
+
if (!sure) return false;
|
|
116
|
+
await api("/api/account/memory", { method: "DELETE" });
|
|
117
|
+
toast("已清空");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
fill(
|
|
121
|
+
panel,
|
|
122
|
+
h(
|
|
123
|
+
"div",
|
|
124
|
+
{ class: "section" },
|
|
125
|
+
h("h4", {}, "记忆", h("span", { class: "grow" }), h("label", { class: "check" }, enabled, "开启")),
|
|
126
|
+
h(
|
|
127
|
+
"div",
|
|
128
|
+
{ class: "muted" },
|
|
129
|
+
"像 ChatGPT 的记忆:对话时 agent 会参考你的「关于我」和记住的事,聊天里遇到长期有用的信息也会主动记一条(会在回复里告诉你)。Claude 和 Codex、Web 和飞书共用这一份。",
|
|
130
|
+
),
|
|
131
|
+
h(
|
|
132
|
+
"div",
|
|
133
|
+
{ class: "muted" },
|
|
134
|
+
"用在哪些对话:你在 Web 上的对话;在「账号」里绑定了飞书后,和机器人的私聊也会用。飞书群聊不用。别人(包括管理员)看不到你的记忆,管理员只能清空它。",
|
|
135
|
+
),
|
|
136
|
+
),
|
|
137
|
+
h(
|
|
138
|
+
"div",
|
|
139
|
+
{ class: "section" },
|
|
140
|
+
h("h4", {}, "自动"),
|
|
141
|
+
curateSection(mem, reload),
|
|
142
|
+
toggle("chatHistory", "参考以前的聊天", "已开启:agent 能搜你以前的聊天了", "已关闭:agent 不再搜以前的聊天"),
|
|
143
|
+
h(
|
|
144
|
+
"div",
|
|
145
|
+
{ class: "muted" },
|
|
146
|
+
`agent 遇到「上次说的那个……」时,可以搜你以前的聊天(只有你自己的对话,被删掉的对话不算)。${history ? `现在收录了 ${history.conversations} 段对话、${history.count} 句话。` : ""}`,
|
|
147
|
+
),
|
|
148
|
+
h("div", { class: "row" }, clearHistory),
|
|
149
|
+
),
|
|
150
|
+
h("div", { class: "section" }, h("h4", {}, "关于我"), field("写给 agent 看的自我介绍:你是谁、在做什么、希望它怎么回答", about, `每次对话都会带上,最多 ${mem.limits.about} 字`), h("div", { class: "row" }, saveAbout)),
|
|
151
|
+
h(
|
|
152
|
+
"div",
|
|
153
|
+
{ class: "section" },
|
|
154
|
+
h("h4", {}, `记住的事(${items.length})`),
|
|
155
|
+
h("div", { class: "row" }, newItem, addBtn),
|
|
156
|
+
items.length ? items.map(itemRow) : h("div", { class: "muted" }, "还没有。聊天时说「记住……」,或者在上面手动加。"),
|
|
157
|
+
),
|
|
158
|
+
h(
|
|
159
|
+
"div",
|
|
160
|
+
{ class: "section" },
|
|
161
|
+
h("div", { class: "muted" }, "注意:和多用户一样,这不是安全隔离 —— 工作模式下 agent 能读到这台机器上的文件,也包括记忆文件。"),
|
|
162
|
+
h("div", { class: "row" }, clearBtn),
|
|
163
|
+
),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 记忆页里的「整理记忆」:什么时候整理、用哪个 agent 的哪个模型、现在整理、上次的结果 */
|
|
168
|
+
function curateSection(mem, reload) {
|
|
169
|
+
const c = { ...mem.curate };
|
|
170
|
+
const box = h("div");
|
|
171
|
+
const save = async (patch) => {
|
|
172
|
+
try {
|
|
173
|
+
await api("/api/account/memory", { method: "PUT", body: { curate: patch } });
|
|
174
|
+
Object.assign(c, patch);
|
|
175
|
+
if (patch.agent === "auto") c.model = "";
|
|
176
|
+
render();
|
|
177
|
+
toast("已保存");
|
|
178
|
+
} catch (err) {
|
|
179
|
+
toast(err.message);
|
|
180
|
+
render();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
const select = (value, options, onchange) =>
|
|
184
|
+
h("select", { onchange: (e) => onchange(e.target.value) }, options.map(([v, label]) => h("option", { value: v, selected: String(v) === String(value) }, label)));
|
|
185
|
+
|
|
186
|
+
const render = () => {
|
|
187
|
+
const when = select(
|
|
188
|
+
c.when,
|
|
189
|
+
[
|
|
190
|
+
["daily", "每天一次,把当天聊过的合起来整理(推荐)"],
|
|
191
|
+
["idle", "每段对话聊完后就整理"],
|
|
192
|
+
["manual", "只在我点「现在整理」时"],
|
|
193
|
+
["off", "不整理"],
|
|
194
|
+
],
|
|
195
|
+
(v) => save({ when: v }),
|
|
196
|
+
);
|
|
197
|
+
// 换了范围,等着整理的段数也跟着变:重新读一遍
|
|
198
|
+
const scope = select(
|
|
199
|
+
c.scope,
|
|
200
|
+
[
|
|
201
|
+
["all", "全部对话"],
|
|
202
|
+
["chat", "只整理聊天模式的对话"],
|
|
203
|
+
["work", "只整理工作模式的对话"],
|
|
204
|
+
],
|
|
205
|
+
(v) => save({ scope: v }).then(reload),
|
|
206
|
+
);
|
|
207
|
+
const timing =
|
|
208
|
+
c.when === "idle"
|
|
209
|
+
? field("停下来多久算聊完", select(c.idleMinutes, [10, 30, 60, 120, 240].map((m) => [m, m < 60 ? `${m} 分钟` : `${m / 60} 小时`]), (v) => save({ idleMinutes: Number(v) })))
|
|
210
|
+
: c.when === "daily"
|
|
211
|
+
? field(
|
|
212
|
+
"几点整理(服务器所在时区)",
|
|
213
|
+
select(c.dailyHour, Array.from({ length: 24 }, (_, i) => [i, `${i} 点`]), (v) => save({ dailyHour: Number(v) })),
|
|
214
|
+
"这个点之后第一次检查时整理;服务器那会儿没开机的话,开机后补上",
|
|
215
|
+
)
|
|
216
|
+
: null;
|
|
217
|
+
const agent = select(
|
|
218
|
+
c.agent,
|
|
219
|
+
[
|
|
220
|
+
["auto", "自动:有 Claude 就用 Claude,否则 Codex"],
|
|
221
|
+
["claude", "Claude Code"],
|
|
222
|
+
["codex", "Codex"],
|
|
223
|
+
],
|
|
224
|
+
(v) => save({ agent: v, model: "" }),
|
|
225
|
+
);
|
|
226
|
+
const model =
|
|
227
|
+
c.agent === "auto"
|
|
228
|
+
? null
|
|
229
|
+
: (() => {
|
|
230
|
+
const sel = h("select", { onchange: (e) => save({ model: e.target.value }) }, h("option", { value: "" }, c.agent === "claude" ? "默认:Haiku(最省)" : "默认模型,思考程度 low(最省)"));
|
|
231
|
+
if (c.model) sel.append(h("option", { value: c.model, selected: true }, c.model));
|
|
232
|
+
agentCatalog(c.agent)
|
|
233
|
+
.then((models) => {
|
|
234
|
+
for (const m of models) {
|
|
235
|
+
if (m.id === "default" || m.id === c.model) continue;
|
|
236
|
+
sel.append(h("option", { value: m.id }, m.label || m.id));
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
.catch(() => sel.append(h("option", { value: "", disabled: true }, "(这个 agent 没启用,读不到模型列表)")));
|
|
240
|
+
return field("模型", sel, "整理只是读一遍对话、改几条记忆,用便宜的模型就够了;贵的模型会多占订阅额度");
|
|
241
|
+
})();
|
|
242
|
+
|
|
243
|
+
const nowBtn = h("button", { class: "btn small", disabled: c.when === "off" || !mem.enabled }, "现在整理");
|
|
244
|
+
nowBtn.onclick = async () => {
|
|
245
|
+
nowBtn.disabled = true;
|
|
246
|
+
nowBtn.textContent = "整理中…";
|
|
247
|
+
try {
|
|
248
|
+
const r = await api("/api/account/memory/curate", { method: "POST" });
|
|
249
|
+
toast(
|
|
250
|
+
r.error
|
|
251
|
+
? `整理失败:${r.error}`
|
|
252
|
+
: r.conversations
|
|
253
|
+
? `整理了 ${r.conversations} 段对话:新增 ${r.added.length}、更新 ${r.updated.length}、删除 ${r.removed}`
|
|
254
|
+
: "没有需要整理的对话(正在回复的那段先不整理)",
|
|
255
|
+
);
|
|
256
|
+
reload();
|
|
257
|
+
} catch (err) {
|
|
258
|
+
toast(err.message);
|
|
259
|
+
nowBtn.disabled = false;
|
|
260
|
+
nowBtn.textContent = "现在整理";
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const last = mem.lastCuration;
|
|
264
|
+
const lastText = last
|
|
265
|
+
? last.error
|
|
266
|
+
? `上次整理(${relTime(last.at)})没成功:${last.error}`
|
|
267
|
+
: `上次整理:${relTime(last.at)},${last.conversations} 段对话${last.by ? `,用 ${last.by}` : ""},新增 ${last.added.length}、更新 ${last.updated.length}、删除 ${last.removed}`
|
|
268
|
+
: "还没整理过";
|
|
269
|
+
|
|
270
|
+
fill(
|
|
271
|
+
box,
|
|
272
|
+
field("整理记忆", when),
|
|
273
|
+
h(
|
|
274
|
+
"div",
|
|
275
|
+
{ class: "muted" },
|
|
276
|
+
{
|
|
277
|
+
daily: "攒一天再整理:每次整理都要把你现有的记忆整份带上,合起来一次最省额度,几段对话放在一起看也更容易合并重复。改了什么只显示在这里,不打扰对话。",
|
|
278
|
+
idle: "每段对话停下来就整理一次,改了什么会在那条对话里告诉你。最及时,但聊得多时调用次数也多。",
|
|
279
|
+
manual: "聊过的内容会攒着,你点「现在整理」时一次整理完。",
|
|
280
|
+
off: "不整理,聊过的内容也不攒着。聊天里 agent 照样可以自己用 remember 记东西。",
|
|
281
|
+
}[c.when],
|
|
282
|
+
),
|
|
283
|
+
timing,
|
|
284
|
+
c.when === "off" ? null : field("整理哪些对话", scope, "按整理时对话所在的模式算;不在范围里的对话直接跳过,之后改回来也不会补整理"),
|
|
285
|
+
c.when === "off" ? null : field("用哪个 agent", agent),
|
|
286
|
+
c.when === "off" ? null : model,
|
|
287
|
+
h("div", { class: "row", style: { alignItems: "center", gap: "10px" } }, nowBtn, h("span", { class: "muted" }, `${mem.pending ? `有 ${mem.pending} 段对话等着整理。` : ""}${lastText}`)),
|
|
288
|
+
h("div", { class: "muted" }, "整理时会对照现有记忆补充、更新或删掉过时的条目;你自己加的条目它不会动。"),
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
render();
|
|
292
|
+
return box;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** 「账号」页里的飞书绑定:Web 上生成绑定码,再在飞书私聊里发 /bind,两边都证明是本人 */
|
|
296
|
+
export function feishuLinkSection() {
|
|
297
|
+
const box = h("div", { class: "section" });
|
|
298
|
+
const load = async () => {
|
|
299
|
+
let data;
|
|
300
|
+
try {
|
|
301
|
+
data = await api("/api/account/feishu");
|
|
302
|
+
} catch (err) {
|
|
303
|
+
fill(box, h("h4", {}, "飞书账号"), h("div", { class: "error-text" }, err.message));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// 没有飞书机器人、也没绑过:整节不显示
|
|
307
|
+
if (!data.bots.length && !data.links.length) return fill(box);
|
|
308
|
+
const codeBox = h("div");
|
|
309
|
+
const gen = h("button", { class: "btn" }, data.links.length ? "再绑一个" : "生成绑定码");
|
|
310
|
+
gen.onclick = async () => {
|
|
311
|
+
gen.disabled = true;
|
|
312
|
+
try {
|
|
313
|
+
const { code, expiresAt } = await api("/api/account/feishu/code", { method: "POST" });
|
|
314
|
+
const cmd = `/bind ${code}`;
|
|
315
|
+
const copy = h("button", { class: "btn small" }, "复制");
|
|
316
|
+
copy.onclick = () => copyText(cmd, copy);
|
|
317
|
+
fill(
|
|
318
|
+
codeBox,
|
|
319
|
+
h(
|
|
320
|
+
"div",
|
|
321
|
+
{ class: "list-item" },
|
|
322
|
+
h(
|
|
323
|
+
"div",
|
|
324
|
+
{ class: "grow" },
|
|
325
|
+
h("div", { class: "t" }, h("code", {}, cmd)),
|
|
326
|
+
h("div", { class: "s" }, `在飞书里私聊机器人(${data.bots.map((b) => b.name).join("、") || "飞书机器人"})发这条消息,${Math.round((expiresAt - Date.now()) / 60000)} 分钟内有效。没用过机器人的话,要先让管理员批准你的配对码。`),
|
|
327
|
+
),
|
|
328
|
+
copy,
|
|
329
|
+
),
|
|
330
|
+
);
|
|
331
|
+
} catch (err) {
|
|
332
|
+
toast(err.message);
|
|
333
|
+
}
|
|
334
|
+
gen.disabled = false;
|
|
335
|
+
};
|
|
336
|
+
fill(
|
|
337
|
+
box,
|
|
338
|
+
h("h4", {}, "飞书账号"),
|
|
339
|
+
h("div", { class: "muted" }, "绑定后,你和飞书机器人的私聊就是你的个人会话:用你的记忆,/sessions 只列你的会话,/web 能接上你自己的 Web 会话。群聊不受影响。"),
|
|
340
|
+
data.links.map((l) => {
|
|
341
|
+
const rm = h("button", { class: "btn small danger" }, "解除绑定");
|
|
342
|
+
rm.onclick = async () => {
|
|
343
|
+
rm.disabled = true;
|
|
344
|
+
try {
|
|
345
|
+
await api("/api/account/feishu", { method: "DELETE", body: { botId: l.botId, openId: l.openId } });
|
|
346
|
+
toast("已解除,那个私聊不再用你的记忆");
|
|
347
|
+
void load();
|
|
348
|
+
} catch (err) {
|
|
349
|
+
toast(err.message);
|
|
350
|
+
rm.disabled = false;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
return h(
|
|
354
|
+
"div",
|
|
355
|
+
{ class: "list-item" },
|
|
356
|
+
h("div", { class: "grow" }, h("div", { class: "t" }, l.botName), h("div", { class: "s" }, `${l.openIdShort} · 绑定于 ${relTime(l.boundAt)}`)),
|
|
357
|
+
rm,
|
|
358
|
+
);
|
|
359
|
+
}),
|
|
360
|
+
h("div", { class: "row" }, gen),
|
|
361
|
+
codeBox,
|
|
362
|
+
);
|
|
363
|
+
};
|
|
364
|
+
void load();
|
|
365
|
+
return box;
|
|
366
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { fill, h, toast } from "../lib/dom.js";
|
|
2
|
+
import { api } from "../lib/api.js";
|
|
3
|
+
import { relTime } from "../lib/time.js";
|
|
4
|
+
import { currentPushSub, enablePush, pushSupport } from "../lib/push.js";
|
|
5
|
+
|
|
6
|
+
export async function notifyTab(panel) {
|
|
7
|
+
const support = pushSupport();
|
|
8
|
+
const box = h("div", { class: "section" }, h("h4", {}, "系统通知"), h("span", { class: "spinner" }));
|
|
9
|
+
fill(panel, box);
|
|
10
|
+
const render = async () => {
|
|
11
|
+
let data = { subscriptions: [] };
|
|
12
|
+
try {
|
|
13
|
+
data = await api("/api/push");
|
|
14
|
+
} catch (err) {
|
|
15
|
+
fill(box, h("h4", {}, "系统通知"), h("div", { class: "error-text" }, err.message));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const mine = await currentPushSub();
|
|
19
|
+
const here = mine && data.subscriptions.some((d) => d.endpoint === mine.endpoint);
|
|
20
|
+
const busy = (btn, fn) => async () => {
|
|
21
|
+
btn.disabled = true;
|
|
22
|
+
try {
|
|
23
|
+
await fn();
|
|
24
|
+
} catch (err) {
|
|
25
|
+
toast(err.message);
|
|
26
|
+
}
|
|
27
|
+
btn.disabled = false;
|
|
28
|
+
await render();
|
|
29
|
+
};
|
|
30
|
+
const onBtn = h("button", { class: "btn primary" }, "在此设备开启通知");
|
|
31
|
+
onBtn.onclick = busy(onBtn, async () => {
|
|
32
|
+
await enablePush();
|
|
33
|
+
toast("已开启,可以发一条测试通知看看");
|
|
34
|
+
});
|
|
35
|
+
const offBtn = h("button", { class: "btn" }, "关闭此设备的通知");
|
|
36
|
+
offBtn.onclick = busy(offBtn, async () => {
|
|
37
|
+
await api("/api/push/unsubscribe", { method: "POST", body: { endpoint: mine.endpoint } });
|
|
38
|
+
await mine.unsubscribe().catch(() => {});
|
|
39
|
+
toast("已关闭");
|
|
40
|
+
});
|
|
41
|
+
const testBtn = h("button", { class: "btn" }, "发送测试通知");
|
|
42
|
+
testBtn.onclick = busy(testBtn, async () => {
|
|
43
|
+
const r = await api("/api/push/test", { method: "POST" });
|
|
44
|
+
toast(`已发送到 ${r.sent} 台设备`);
|
|
45
|
+
});
|
|
46
|
+
fill(
|
|
47
|
+
box,
|
|
48
|
+
h("h4", {}, "系统通知"),
|
|
49
|
+
h("div", { class: "muted" }, "Web 对话里 agent 回复完成、出错、需要授权或向你提问时,推送到开启了通知的设备。正在前台看着那条对话的时候不推。飞书对话由飞书自己提醒。"),
|
|
50
|
+
support.ok
|
|
51
|
+
? h("div", { class: "row" }, here ? offBtn : onBtn, data.subscriptions.length ? testBtn : null)
|
|
52
|
+
: h("div", { class: "error-text" }, support.why),
|
|
53
|
+
support.ok && Notification.permission === "denied"
|
|
54
|
+
? h("div", { class: "error-text" }, "这个设备的通知权限已被拒绝,需要到系统设置(iPhone:设置 → 通知 → Agent Loft)里重新打开。")
|
|
55
|
+
: null,
|
|
56
|
+
h("h4", {}, "已开启通知的设备"),
|
|
57
|
+
data.subscriptions.length === 0
|
|
58
|
+
? h("div", { class: "muted" }, "还没有")
|
|
59
|
+
: data.subscriptions.map((d) => {
|
|
60
|
+
const rm = h("button", { class: "btn small" }, "移除");
|
|
61
|
+
rm.onclick = busy(rm, async () => {
|
|
62
|
+
await api("/api/push/unsubscribe", { method: "POST", body: { endpoint: d.endpoint } });
|
|
63
|
+
if (mine && mine.endpoint === d.endpoint) await mine.unsubscribe().catch(() => {});
|
|
64
|
+
});
|
|
65
|
+
return h(
|
|
66
|
+
"div",
|
|
67
|
+
{ class: "list-item" },
|
|
68
|
+
h(
|
|
69
|
+
"div",
|
|
70
|
+
{ class: "grow" },
|
|
71
|
+
h("div", { class: "t" }, d.label, mine && mine.endpoint === d.endpoint ? "(本设备)" : ""),
|
|
72
|
+
h("div", { class: "s" }, `开启于 ${relTime(d.createdAt)}${d.lastOkAt ? ` · 上次送达 ${relTime(d.lastOkAt)}` : ""}`),
|
|
73
|
+
),
|
|
74
|
+
rm,
|
|
75
|
+
);
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
await render();
|
|
80
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { fill, h, toast } from "../lib/dom.js";
|
|
2
|
+
import { api } from "../lib/api.js";
|
|
3
|
+
import { relTime } from "../lib/time.js";
|
|
4
|
+
import { isAdmin, S } from "../state.js";
|
|
5
|
+
import { dropPushSub } from "../lib/push.js";
|
|
6
|
+
import { field } from "./common.js";
|
|
7
|
+
import { feishuLinkSection } from "./memory.js";
|
|
8
|
+
|
|
9
|
+
export async function authTab(panel) {
|
|
10
|
+
const [pairs, allowlist] = await Promise.all([api("/api/pairing"), api("/api/claude/allowlist")]);
|
|
11
|
+
const botName = (id) => S.bots.find((b) => b.id === id)?.name ?? id;
|
|
12
|
+
const allowText = h("textarea", { rows: 8 });
|
|
13
|
+
allowText.value = allowlist.join("\n");
|
|
14
|
+
panel.append(
|
|
15
|
+
h(
|
|
16
|
+
"div",
|
|
17
|
+
{ class: "section" },
|
|
18
|
+
h("h4", {}, "待批准的配对"),
|
|
19
|
+
pairs.pending.length === 0
|
|
20
|
+
? h("div", { class: "muted" }, "没有待批准的请求。陌生人给机器人发消息时会出现在这里。")
|
|
21
|
+
: pairs.pending.map(({ channelId, request }) =>
|
|
22
|
+
h(
|
|
23
|
+
"div",
|
|
24
|
+
{ class: "list-item" },
|
|
25
|
+
h("div", { class: "grow" }, h("div", { class: "t" }, `${request.code} · ${botName(channelId)}`), h("div", { class: "s" }, `${request.userId} · ${relTime(request.createdAt)}`)),
|
|
26
|
+
h(
|
|
27
|
+
"button",
|
|
28
|
+
{
|
|
29
|
+
class: "btn small accent",
|
|
30
|
+
onclick: async () => {
|
|
31
|
+
try {
|
|
32
|
+
await api("/api/pairing/approve", { method: "POST", body: { code: request.code } });
|
|
33
|
+
toast("已批准");
|
|
34
|
+
fill(panel, );
|
|
35
|
+
void authTab(panel);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
toast(err.message);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
"批准",
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
h(
|
|
47
|
+
"div",
|
|
48
|
+
{ class: "section" },
|
|
49
|
+
h("h4", {}, "已配对的用户"),
|
|
50
|
+
pairs.approved.length === 0
|
|
51
|
+
? h("div", { class: "muted" }, "无")
|
|
52
|
+
: pairs.approved.map(({ channelId, userId }) =>
|
|
53
|
+
h(
|
|
54
|
+
"div",
|
|
55
|
+
{ class: "list-item" },
|
|
56
|
+
h("div", { class: "grow" }, h("div", { class: "t" }, userId), h("div", { class: "s" }, botName(channelId))),
|
|
57
|
+
h(
|
|
58
|
+
"button",
|
|
59
|
+
{
|
|
60
|
+
class: "btn small danger",
|
|
61
|
+
onclick: async () => {
|
|
62
|
+
await api("/api/pairing/revoke", { method: "POST", body: { channelId, userId } });
|
|
63
|
+
fill(panel, );
|
|
64
|
+
void authTab(panel);
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
"撤销",
|
|
68
|
+
),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
h(
|
|
73
|
+
"div",
|
|
74
|
+
{ class: "section" },
|
|
75
|
+
h("h4", {}, "Claude「总是允许」名单"),
|
|
76
|
+
h("div", { class: "muted" }, "点过「总是允许」的会记在这里。Bash:git 表示 git 开头的命令都放行;Edit:/路径 表示该目录下的修改都放行。一行一条,删掉即撤销。"),
|
|
77
|
+
allowText,
|
|
78
|
+
h(
|
|
79
|
+
"div",
|
|
80
|
+
{ class: "row" },
|
|
81
|
+
h(
|
|
82
|
+
"button",
|
|
83
|
+
{
|
|
84
|
+
class: "btn primary",
|
|
85
|
+
onclick: async () => {
|
|
86
|
+
await api("/api/claude/allowlist", { method: "PUT", body: { list: allowText.value.split("\n") } });
|
|
87
|
+
toast("已保存");
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
"保存",
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function securityTab(panel) {
|
|
98
|
+
const old = h("input", { type: "password", autocomplete: "current-password" });
|
|
99
|
+
const pw = h("input", { type: "password", autocomplete: "new-password" });
|
|
100
|
+
const sessions = await api("/api/web-sessions");
|
|
101
|
+
// 管理员看到的是所有人的设备:不止一个人时标上是谁的
|
|
102
|
+
const owners = new Set(sessions.map((s) => s.userId));
|
|
103
|
+
const showOwner = isAdmin() && owners.size > 1;
|
|
104
|
+
panel.append(
|
|
105
|
+
S.user
|
|
106
|
+
? h(
|
|
107
|
+
"div",
|
|
108
|
+
{ class: "section" },
|
|
109
|
+
h("h4", {}, "当前账号"),
|
|
110
|
+
h("div", {}, S.user.name, " ", h("span", { class: "status-tag" }, S.user.role === "admin" ? "管理员" : "成员")),
|
|
111
|
+
)
|
|
112
|
+
: null,
|
|
113
|
+
h(
|
|
114
|
+
"div",
|
|
115
|
+
{ class: "section" },
|
|
116
|
+
h("h4", {}, "修改登录密码"),
|
|
117
|
+
field("原密码", old),
|
|
118
|
+
field("新密码(至少 8 位)", pw),
|
|
119
|
+
h(
|
|
120
|
+
"div",
|
|
121
|
+
{ class: "row" },
|
|
122
|
+
h(
|
|
123
|
+
"button",
|
|
124
|
+
{
|
|
125
|
+
class: "btn primary",
|
|
126
|
+
onclick: async () => {
|
|
127
|
+
try {
|
|
128
|
+
await api("/api/password", { method: "POST", body: { old: old.value, password: pw.value } });
|
|
129
|
+
toast("密码已修改,你的其它设备已下线");
|
|
130
|
+
old.value = pw.value = "";
|
|
131
|
+
} catch (err) {
|
|
132
|
+
toast(err.message);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
"修改",
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
feishuLinkSection(),
|
|
141
|
+
h(
|
|
142
|
+
"div",
|
|
143
|
+
{ class: "section" },
|
|
144
|
+
h("h4", {}, showOwner ? "已登录的设备(所有用户)" : "已登录的设备"),
|
|
145
|
+
sessions.map((s) =>
|
|
146
|
+
h(
|
|
147
|
+
"div",
|
|
148
|
+
{ class: "list-item" },
|
|
149
|
+
h(
|
|
150
|
+
"div",
|
|
151
|
+
{ class: "grow" },
|
|
152
|
+
h("div", { class: "t" }, s.userAgent.slice(0, 80) || "未知设备"),
|
|
153
|
+
h("div", { class: "s" }, `${showOwner ? `${s.userName ?? "已删除的用户"} · ` : ""}${s.ip} · 最近活动 ${relTime(s.lastSeen)}`),
|
|
154
|
+
),
|
|
155
|
+
h(
|
|
156
|
+
"button",
|
|
157
|
+
{
|
|
158
|
+
class: "btn small danger",
|
|
159
|
+
onclick: async () => {
|
|
160
|
+
await api("/api/web-sessions/revoke", { method: "POST", body: { id: s.id } });
|
|
161
|
+
fill(panel, );
|
|
162
|
+
void securityTab(panel);
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
"下线",
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
),
|
|
169
|
+
),
|
|
170
|
+
h(
|
|
171
|
+
"div",
|
|
172
|
+
{ class: "row" },
|
|
173
|
+
h(
|
|
174
|
+
"button",
|
|
175
|
+
{
|
|
176
|
+
class: "btn danger",
|
|
177
|
+
onclick: async () => {
|
|
178
|
+
// 退出了就别再收这个账号的通知:换个人在这台设备上登录,不能收到上一个人的
|
|
179
|
+
await dropPushSub().catch(() => {});
|
|
180
|
+
await api("/api/logout", { method: "POST" });
|
|
181
|
+
location.reload();
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
"退出登录",
|
|
185
|
+
),
|
|
186
|
+
),
|
|
187
|
+
);
|
|
188
|
+
}
|