agent-loft 0.2.122 → 0.2.123
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 +0 -15
- package/package.json +1 -1
- package/src/channels/feishu/bot.ts +12 -29
- package/src/channels/feishu/cards.ts +2 -6
- package/src/channels/feishu/client.ts +3 -3
- package/src/channels/web/api.ts +3 -64
- package/src/channels/web/server.ts +0 -9
- package/src/channels/web/tasks-api.ts +2 -6
- package/src/core/backup.ts +0 -6
- package/src/core/command-catalog.ts +0 -1
- package/src/core/db.ts +1 -16
- package/src/core/hub.ts +11 -13
- package/src/core/personal.ts +0 -2
- package/src/core/store.ts +3 -3
- package/src/core/tasks-bridge.ts +2 -8
- package/src/core/tasks.ts +2 -8
- package/src/core/ui-prefs.ts +1 -1
- package/src/main.ts +0 -3
- package/web/css/tasks.css +0 -8
- package/web/lib/ws.js +0 -3
- package/web/views/layout.js +4 -11
- package/web/views/sidebar-nav.js +0 -1
- package/web/views/tasks.js +4 -7
- package/src/bot-event-runner.ts +0 -131
- package/src/channels/web/bot-events-api.ts +0 -82
- package/src/core/bot-events.ts +0 -88
- package/web/views/assistants.js +0 -82
- package/web/views/bot-events.js +0 -96
package/web/views/bot-events.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { api } from "../lib/api.js";
|
|
2
|
-
import { fill, h, toast } from "../lib/dom.js";
|
|
3
|
-
import { confirmDialog, modal } from "../lib/overlay.js";
|
|
4
|
-
import { openConversation } from "./messages.js";
|
|
5
|
-
|
|
6
|
-
const path = "/api/bot-events";
|
|
7
|
-
const state = { inbox: "已记入事件记录", pending: "等待投递", sent: "已投递", failed: "投递失败", cancelled: "已取消" };
|
|
8
|
-
const option = (value, label) => h("option", { value }, label);
|
|
9
|
-
const button = (label, onclick) => h("button", { class: "btn", type: "button", onclick }, label);
|
|
10
|
-
|
|
11
|
-
function credentials(token) {
|
|
12
|
-
const field = h("input", { "aria-label": "Webhook 令牌", type: "password", readonly: true, value: token, autocomplete: "off" });
|
|
13
|
-
const reveal = button("显示令牌", () => {
|
|
14
|
-
field.type = field.type === "password" ? "text" : "password";
|
|
15
|
-
reveal.textContent = field.type === "password" ? "显示令牌" : "隐藏令牌";
|
|
16
|
-
field.select();
|
|
17
|
-
});
|
|
18
|
-
modal({ title: "接入备份作业", body: h("div", { class: "modal-body assistant-list" },
|
|
19
|
-
h("label", {}, "上报地址", h("input", { readonly: true, value: location.origin + path + "/receive" })),
|
|
20
|
-
h("label", {}, "Webhook 令牌(仅本次可查看)", field), reveal,
|
|
21
|
-
h("small", {}, "作业结束时用 POST 提交 JSON,请求头使用 Authorization: Bearer <令牌>。同一次运行重试时沿用 runId。"),
|
|
22
|
-
h("code", {}, '{"runId":"backup-001","status":"failed","reason":"disk_full"}')) });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function addForm(settings, reload) {
|
|
26
|
-
const name = h("input", { required: true, maxlength: 60, placeholder: "例如:NAS 夜间备份" });
|
|
27
|
-
const source = h("select", {}, option("webhook", "外部备份 Webhook"), settings.admin ? option("backup", "本机数据库备份") : null);
|
|
28
|
-
const destination = h("select", {}, option("inbox", "只写入事件记录"), option("web", "Web 系统推送"),
|
|
29
|
-
settings.feishu.map((b) => option("feishu:" + b.id, "飞书 · " + b.name)));
|
|
30
|
-
const analyze = h("input", { type: "checkbox" });
|
|
31
|
-
const save = h("button", { class: "btn primary", type: "submit" }, "创建监听");
|
|
32
|
-
const form = h("form", { class: "modal-body assistant-list" },
|
|
33
|
-
h("label", {}, "名称", name), h("label", {}, "来源", source), h("label", {}, "发现新失败时", destination),
|
|
34
|
-
h("label", {}, analyze, " 同时让 bot 分析故障"), save);
|
|
35
|
-
const close = modal({ title: "新增事件监听", body: form });
|
|
36
|
-
form.addEventListener("submit", async (e) => {
|
|
37
|
-
e.preventDefault();
|
|
38
|
-
if (save.disabled) return;
|
|
39
|
-
save.disabled = true;
|
|
40
|
-
try {
|
|
41
|
-
const { token } = await api(path, { method: "POST", body: { key: settings.key, name: name.value, source: source.value, destination: destination.value, analyze: analyze.checked } });
|
|
42
|
-
close();
|
|
43
|
-
if (token) credentials(token);
|
|
44
|
-
void reload();
|
|
45
|
-
} catch (err) { toast(err.message); save.disabled = false; }
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function openBotEvents(query) {
|
|
50
|
-
const body = h("div", { class: "modal-body assistant-list", "aria-live": "polite" }, "正在读取事件…");
|
|
51
|
-
const controller = new AbortController();
|
|
52
|
-
const dismiss = modal({ title: "bot 事件监听", body, beforeClose: () => controller.abort() });
|
|
53
|
-
let generation = 0;
|
|
54
|
-
async function retry(w, e) {
|
|
55
|
-
try { await api(path + "/" + w.id + "/retry/" + e.id, { method: "POST" }); await load(); }
|
|
56
|
-
catch (err) { toast(err.message); }
|
|
57
|
-
}
|
|
58
|
-
function incident(w, e) {
|
|
59
|
-
return h("div", { class: "assistant-task" }, h("div", { class: "grow" },
|
|
60
|
-
h("strong", {}, e.reason), h("small", {}, new Date(e.at).toLocaleString() + " · " + e.run),
|
|
61
|
-
h("small", {}, [state[e.delivery], e.error, e.analysis === "error" ? "分析启动失败" : null].filter(Boolean).join(" · "))),
|
|
62
|
-
e.analysisKey ? button("查看分析", () => { controller.abort(); dismiss(); void openConversation(e.analysisKey); }) : null,
|
|
63
|
-
e.delivery === "failed" ? button("重试投递", () => void retry(w, e)) : null);
|
|
64
|
-
}
|
|
65
|
-
async function remove(w, key) {
|
|
66
|
-
if (!await confirmDialog({ title: "删除监听?", message: "会停止接收这项作业的结果,并清除该监听的事件记录。", confirmText: "删除" })) return;
|
|
67
|
-
try {
|
|
68
|
-
await api(path + "/" + w.id, { method: "DELETE" });
|
|
69
|
-
query = { key };
|
|
70
|
-
await load();
|
|
71
|
-
} catch (err) { toast(err.message); }
|
|
72
|
-
}
|
|
73
|
-
async function load() {
|
|
74
|
-
const current = ++generation;
|
|
75
|
-
try {
|
|
76
|
-
const data = await api(path + "?" + new URLSearchParams(query));
|
|
77
|
-
if (current !== generation || !body.isConnected) return;
|
|
78
|
-
const watches = data.watches.slice().sort((a, b) => Number(b.id === query.watch) - Number(a.id === query.watch));
|
|
79
|
-
fill(body, data.unavailable ? h("p", {}, data.unavailable) : button("新增监听", () => addForm(data, load)),
|
|
80
|
-
watches.length ? watches.map((w) => {
|
|
81
|
-
const dest = w.destination === "web" ? "Web 系统推送" : w.destination === "inbox" ? "只记入事件记录" :
|
|
82
|
-
"飞书 · " + (data.feishu.find((b) => "feishu:" + b.id === w.destination)?.name || "绑定不可用");
|
|
83
|
-
const latest = w.lastSeen ? "最近上报" + (w.lastStatus === "ok" ? "成功" : "失败") + " · " + new Date(w.lastSeen).toLocaleString() : "尚未收到上报";
|
|
84
|
-
return h("section", { class: "assistant-card" }, h("div", { class: "assistant-row" },
|
|
85
|
-
h("strong", { class: "grow" }, w.name), button("删除监听", () => void remove(w, data.key))),
|
|
86
|
-
h("small", {}, [w.source === "backup" ? "本机数据库备份" : "外部备份 Webhook", dest, w.analyze ? "自动分析" : null].filter(Boolean).join(" · ")),
|
|
87
|
-
h("small", {}, latest), w.events.map((e) => incident(w, e)));
|
|
88
|
-
}) : h("p", {}, "暂无监听。添加备份作业后,可以在这里查看最近的失败记录。"),
|
|
89
|
-
button("刷新记录", load));
|
|
90
|
-
} catch (err) {
|
|
91
|
-
if (body.isConnected && current === generation) fill(body, h("p", {}, err.message), button("重新加载", load));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
document.addEventListener("aim:bot-events", load, { signal: controller.signal });
|
|
95
|
-
void load();
|
|
96
|
-
}
|