agent-loft 0.2.43 → 0.2.45
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 +3 -1
- package/package.json +1 -1
- package/src/channels/web/api.ts +146 -3
- package/src/channels/web/http.ts +12 -0
- package/src/channels/web/push.ts +130 -6
- package/src/channels/web/server.ts +4 -3
- package/src/core/config.ts +36 -0
- package/src/core/hub.ts +14 -0
- package/src/core/reply-files.ts +142 -0
- package/src/core/servers.ts +134 -0
- package/src/core/uploads.ts +1 -1
- package/src/core/visualize.ts +123 -0
- package/web/css/messages.css +271 -0
- package/web/css/servers.css +265 -0
- package/web/index.html +1 -0
- package/web/lib/api.js +1 -0
- package/web/lib/markdown.js +5 -3
- package/web/lib/overlay.js +1 -1
- package/web/lib/push.js +8 -1
- package/web/lib/shell.js +691 -0
- package/web/lib/ws.js +7 -1
- package/web/settings/common.js +3 -0
- package/web/settings/index.js +2 -0
- package/web/settings/notify.js +7 -2
- package/web/settings/security.js +8 -3
- package/web/settings/servers.js +207 -0
- package/web/state.js +2 -0
- package/web/views/auth.js +3 -1
- package/web/views/composer.js +1 -1
- package/web/views/file-preview.js +342 -0
- package/web/views/layout.js +43 -5
- package/web/views/messages.js +5 -4
- package/web/views/remote.js +2 -2
- package/web/views/sidebar.js +6 -4
- package/web/views/tasks.js +1 -1
package/web/lib/ws.js
CHANGED
|
@@ -8,6 +8,7 @@ import { renderTopbar } from "../views/topbar.js";
|
|
|
8
8
|
import { applyEvent, openConversation } from "../views/messages.js";
|
|
9
9
|
import { upsertInteraction } from "../views/interaction.js";
|
|
10
10
|
import { setBusy } from "../views/composer.js";
|
|
11
|
+
import { shownHere } from "./shell.js";
|
|
11
12
|
import { renderScheduled } from "../views/schedule.js";
|
|
12
13
|
|
|
13
14
|
// ---------- WebSocket ----------
|
|
@@ -97,7 +98,8 @@ export const WS = {
|
|
|
97
98
|
* 窗口开着人走开了(电脑上停在这条会话、人在用手机),照样推
|
|
98
99
|
*/
|
|
99
100
|
presence() {
|
|
100
|
-
|
|
101
|
+
// 多服务器:外壳切到了别的服务器、或者这台被嵌着但没在显示,也算没在看
|
|
102
|
+
const visible = document.visibilityState === "visible" && document.hasFocus() && Date.now() - lastInput < IDLE_MS && shownHere();
|
|
101
103
|
// 在定时任务、远程控制页上:没在看哪条对话(远程控制页不清 S.current,回来时对话还在)
|
|
102
104
|
this.raw({ t: "presence", visible, key: S.view ? "" : (S.current ?? "") });
|
|
103
105
|
},
|
|
@@ -105,6 +107,10 @@ export const WS = {
|
|
|
105
107
|
|
|
106
108
|
// 切回窗口本身就算动了一下
|
|
107
109
|
window.addEventListener("focus", () => (markActive(), WS.presence()));
|
|
110
|
+
document.addEventListener("aim:shell-active", () => {
|
|
111
|
+
if (shownHere()) markActive();
|
|
112
|
+
WS.presence();
|
|
113
|
+
});
|
|
108
114
|
window.addEventListener("blur", () => WS.presence());
|
|
109
115
|
|
|
110
116
|
// ---------- 有没有人在动页面 ----------
|
package/web/settings/common.js
CHANGED
|
@@ -4,6 +4,7 @@ import { S } from "../state.js";
|
|
|
4
4
|
import { renderSidebar } from "../views/sidebar.js";
|
|
5
5
|
import { loadQuota, scheduleIdleQuota } from "../views/quota.js";
|
|
6
6
|
import { catalogCache, catalogDefaults, catalogLoaded, renderContext, renderTopbar } from "../views/topbar.js";
|
|
7
|
+
import { applyShellInfo } from "../lib/shell.js";
|
|
7
8
|
|
|
8
9
|
export async function saveConfig(cfg, patch) {
|
|
9
10
|
try {
|
|
@@ -18,6 +19,8 @@ export async function saveConfig(cfg, patch) {
|
|
|
18
19
|
S.agents = boot2.agents;
|
|
19
20
|
S.bots = boot2.bots;
|
|
20
21
|
S.workspaceRoot = boot2.workspaceRoot;
|
|
22
|
+
// 左上角切换的服务器可能改了
|
|
23
|
+
applyShellInfo(boot2.servers);
|
|
21
24
|
const quotaOn = boot2.quotaEnabled !== false;
|
|
22
25
|
if (boot2.quotaRefreshMin !== S.quotaRefreshMin || quotaOn !== S.quotaEnabled) {
|
|
23
26
|
const turnedOn = quotaOn && !S.quotaEnabled;
|
package/web/settings/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { accountTab } from "./security.js";
|
|
|
11
11
|
import { memoryTab } from "./memory.js";
|
|
12
12
|
import { skillsTab } from "./skills.js";
|
|
13
13
|
import { usageTab } from "./usage.js";
|
|
14
|
+
import { serversTab } from "./servers.js";
|
|
14
15
|
import { systemTab, usersTab } from "./users.js";
|
|
15
16
|
import { hasDirty, markDirty } from "./common.js";
|
|
16
17
|
|
|
@@ -50,6 +51,7 @@ function groupsFor(cfg) {
|
|
|
50
51
|
tabs: [
|
|
51
52
|
["飞书", (p) => feishuTab(cfg, p)],
|
|
52
53
|
["远程控制", (p) => remoteTab(cfg, p)],
|
|
54
|
+
["服务器", (p) => serversTab(cfg, p)],
|
|
53
55
|
],
|
|
54
56
|
},
|
|
55
57
|
{
|
package/web/settings/notify.js
CHANGED
|
@@ -2,6 +2,7 @@ import { fill, h, toast } from "../lib/dom.js";
|
|
|
2
2
|
import { api } from "../lib/api.js";
|
|
3
3
|
import { relTime } from "../lib/time.js";
|
|
4
4
|
import { currentPushSub, enablePush, pushSupport } from "../lib/push.js";
|
|
5
|
+
import { refreshShellPush } from "../lib/shell.js";
|
|
5
6
|
|
|
6
7
|
export async function notifyTab(panel) {
|
|
7
8
|
const support = pushSupport();
|
|
@@ -25,6 +26,8 @@ export async function notifyTab(panel) {
|
|
|
25
26
|
toast(err.message);
|
|
26
27
|
}
|
|
27
28
|
btn.disabled = false;
|
|
29
|
+
// 多服务器的外壳:开关通知后,转给各台的订阅跟着变
|
|
30
|
+
void refreshShellPush();
|
|
28
31
|
await render();
|
|
29
32
|
};
|
|
30
33
|
const onBtn = h("button", { class: "btn primary" }, "在此设备开启通知");
|
|
@@ -49,9 +52,11 @@ export async function notifyTab(panel) {
|
|
|
49
52
|
h("div", { class: "muted" }, "Web 对话里 agent 回复完成、出错、需要授权或向你提问时,推送到开启了通知的设备。正在前台看着那条对话的时候不推。飞书对话由飞书自己提醒。"),
|
|
50
53
|
support.ok
|
|
51
54
|
? h("div", { class: "row" }, here ? offBtn : onBtn, data.subscriptions.length ? testBtn : null)
|
|
52
|
-
:
|
|
55
|
+
: support.framed
|
|
56
|
+
? [h("div", { class: "muted" }, support.why), data.subscriptions.length ? h("div", { class: "row" }, testBtn) : null]
|
|
57
|
+
: h("div", { class: "error-text" }, support.why),
|
|
53
58
|
// 推送用不了(比如不是 HTTPS):至少让页面开着、切到别的窗口时能弹提醒
|
|
54
|
-
!support.ok && "Notification" in window && Notification.permission === "default"
|
|
59
|
+
!support.ok && !support.framed && "Notification" in window && Notification.permission === "default"
|
|
55
60
|
? h(
|
|
56
61
|
"div",
|
|
57
62
|
{ class: "row" },
|
package/web/settings/security.js
CHANGED
|
@@ -12,9 +12,14 @@ export async function accountTab(page) {
|
|
|
12
12
|
logout.onclick = async () => {
|
|
13
13
|
logout.disabled = true;
|
|
14
14
|
// 退出了就别再收这个账号的通知:换个人在这台设备上登录,不能收到上一个人的
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
try {
|
|
16
|
+
await dropPushSub();
|
|
17
|
+
await api("/api/logout", { method: "POST" });
|
|
18
|
+
location.reload();
|
|
19
|
+
} catch (err) {
|
|
20
|
+
toast(err.message);
|
|
21
|
+
logout.disabled = false;
|
|
22
|
+
}
|
|
18
23
|
};
|
|
19
24
|
const old = h("input", { type: "password", autocomplete: "current-password" });
|
|
20
25
|
const pw = h("input", { type: "password", autocomplete: "new-password" });
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { fill, h, icon, toast } from "../lib/dom.js";
|
|
2
|
+
import { canFrame, openForAuth } from "../lib/shell.js";
|
|
3
|
+
import { field, markDirty, saveButton, saveConfig } from "./common.js";
|
|
4
|
+
|
|
5
|
+
// ---------- 设置 → 服务器 ----------
|
|
6
|
+
// 左上角切换到别的 agent-loft(lib/shell.js、服务端 core/servers.ts)。两件事:
|
|
7
|
+
// - 这台能切到哪几台(这台当外壳);
|
|
8
|
+
// - 允许哪些地址把这台嵌进去(这台被别人切过来)。
|
|
9
|
+
|
|
10
|
+
const HINT =
|
|
11
|
+
"在左上角切换到别的 agent-loft,像 Codex 桌面端切换「Codex」和「ChatGPT」那样。别的服务器的页面原样嵌在这里,各自登录、直接连它自己的服务端,这台不中转。" +
|
|
12
|
+
"几台要在同一个主域名下(比如 mac.example.com、nas.example.com),都要用 HTTPS;对方还要允许这台嵌入:加好后点「授权」,在打开的页面里确认。";
|
|
13
|
+
|
|
14
|
+
export function serversTab(cfg, panel) {
|
|
15
|
+
fill(panel, listSection(cfg), embeddersSection(cfg));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 这台能切到哪几台 */
|
|
19
|
+
function listSection(cfg) {
|
|
20
|
+
const box = h("div", { class: "section", "data-form": "" });
|
|
21
|
+
const selfIcon = h("input", { class: "srv-emoji", value: cfg.servers.selfIcon, placeholder: "🖥️", maxlength: 16 });
|
|
22
|
+
const selfName = h("input", { value: cfg.servers.selfName, placeholder: "空着用主机名" });
|
|
23
|
+
const rows = h("div", { class: "srv-rows" });
|
|
24
|
+
let list = cfg.servers.list.map((s) => ({ ...s }));
|
|
25
|
+
|
|
26
|
+
const render = () => {
|
|
27
|
+
fill(
|
|
28
|
+
rows,
|
|
29
|
+
list.length === 0
|
|
30
|
+
? h("div", { class: "muted" }, "还没有加别的服务器")
|
|
31
|
+
: list.map((s, i) => {
|
|
32
|
+
let saved = cfg.servers.list.find((x) => x.id === s.id && x.url === s.url);
|
|
33
|
+
const authorize = h("button", {
|
|
34
|
+
class: "btn small",
|
|
35
|
+
disabled: !saved,
|
|
36
|
+
title: saved ? "在新标签页打开那台,允许这台嵌入" : "先保存",
|
|
37
|
+
onclick: () => saved && openForAuth(saved),
|
|
38
|
+
}, "授权");
|
|
39
|
+
const em = h("input", { class: "srv-emoji", value: s.icon, placeholder: "🗄️", maxlength: 16, oninput: () => (s.icon = em.value) });
|
|
40
|
+
const name = h("input", { value: s.name, placeholder: "名称", oninput: () => (s.name = name.value) });
|
|
41
|
+
const url = h("input", {
|
|
42
|
+
value: s.url,
|
|
43
|
+
placeholder: "https://nas.example.com",
|
|
44
|
+
autocapitalize: "off",
|
|
45
|
+
spellcheck: "false",
|
|
46
|
+
oninput: () => {
|
|
47
|
+
s.url = url.value;
|
|
48
|
+
saved = cfg.servers.list.find((x) => x.id === s.id && x.url === s.url);
|
|
49
|
+
authorize.disabled = !saved;
|
|
50
|
+
authorize.title = saved ? "在新标签页打开那台,允许这台嵌入" : "先保存";
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const move = (d) => () => {
|
|
54
|
+
[list[i], list[i + d]] = [list[i + d], list[i]];
|
|
55
|
+
markDirty(box);
|
|
56
|
+
render();
|
|
57
|
+
};
|
|
58
|
+
return h(
|
|
59
|
+
"div",
|
|
60
|
+
{ class: "srv-edit" },
|
|
61
|
+
h("div", { class: "srv-edit-fields" }, em, name, url),
|
|
62
|
+
h(
|
|
63
|
+
"div",
|
|
64
|
+
{ class: "srv-edit-actions" },
|
|
65
|
+
h("button", { class: "btn small", disabled: i === 0, title: "上移", onclick: move(-1) }, "↑"),
|
|
66
|
+
h("button", { class: "btn small", disabled: i === list.length - 1, title: "下移", onclick: move(1) }, "↓"),
|
|
67
|
+
// 没保存的地址先别去授权:那边确认后会通知这边重新加载,这边得已经有它
|
|
68
|
+
authorize,
|
|
69
|
+
h(
|
|
70
|
+
"button",
|
|
71
|
+
{
|
|
72
|
+
class: "icon-btn",
|
|
73
|
+
title: "移除",
|
|
74
|
+
onclick: () => {
|
|
75
|
+
list.splice(i, 1);
|
|
76
|
+
markDirty(box);
|
|
77
|
+
render();
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
icon("trash"),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
render();
|
|
88
|
+
|
|
89
|
+
const add = h(
|
|
90
|
+
"button",
|
|
91
|
+
{
|
|
92
|
+
class: "btn",
|
|
93
|
+
onclick: () => {
|
|
94
|
+
list.push({ id: "", name: "", icon: "", url: "" });
|
|
95
|
+
markDirty(box);
|
|
96
|
+
render();
|
|
97
|
+
rows.querySelectorAll(".srv-edit-fields input:nth-child(3)")[list.length - 1]?.focus();
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
icon("plus"),
|
|
101
|
+
"添加服务器",
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const save = async () => {
|
|
105
|
+
const clean = list.filter((s) => s.url.trim() || s.name.trim());
|
|
106
|
+
if (clean.some((s) => !s.url.trim())) {
|
|
107
|
+
toast("有一台没填地址");
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const ok = await saveConfig(cfg, { servers: { selfName: selfName.value, selfIcon: selfIcon.value, list: clean } });
|
|
111
|
+
if (!ok) return false;
|
|
112
|
+
// 新加的地址要刷新页面才嵌得进来(页面的 CSP 是加载时按旧列表出的)
|
|
113
|
+
if (cfg.servers.list.some((s) => !canFrame(s.url))) {
|
|
114
|
+
toast("已保存,刷新页面后生效…");
|
|
115
|
+
setTimeout(() => location.reload(), 900);
|
|
116
|
+
}
|
|
117
|
+
box.replaceWith(listSection(cfg));
|
|
118
|
+
return true;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
fill(
|
|
122
|
+
box,
|
|
123
|
+
h("h4", {}, "切换服务器"),
|
|
124
|
+
h("div", { class: "muted" }, HINT),
|
|
125
|
+
field("这台", h("div", { class: "srv-edit-fields self" }, selfIcon, selfName), "左上角列表里这台的图标(一个 emoji)和名字"),
|
|
126
|
+
h("div", { class: "field" }, h("span", {}, "其他服务器"), rows),
|
|
127
|
+
h("div", { class: "row" }, add, saveButton(save)),
|
|
128
|
+
);
|
|
129
|
+
return box;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 允许哪些地址把这台嵌进去 */
|
|
133
|
+
function embeddersSection(cfg) {
|
|
134
|
+
const box = h("div", { class: "section", "data-form": "" });
|
|
135
|
+
let list = [...cfg.servers.embedders];
|
|
136
|
+
const rows = h("div", {});
|
|
137
|
+
const input = h("input", { placeholder: "https://loft.example.com", autocapitalize: "off", spellcheck: "false" });
|
|
138
|
+
|
|
139
|
+
const render = () => {
|
|
140
|
+
fill(
|
|
141
|
+
rows,
|
|
142
|
+
list.length === 0
|
|
143
|
+
? h("div", { class: "muted" }, "还没有")
|
|
144
|
+
: list.map((origin, i) =>
|
|
145
|
+
h(
|
|
146
|
+
"div",
|
|
147
|
+
{ class: "list-item" },
|
|
148
|
+
h("div", { class: "grow" }, h("div", { class: "t" }, origin)),
|
|
149
|
+
h(
|
|
150
|
+
"button",
|
|
151
|
+
{
|
|
152
|
+
class: "btn small",
|
|
153
|
+
onclick: () => {
|
|
154
|
+
list.splice(i, 1);
|
|
155
|
+
markDirty(box);
|
|
156
|
+
render();
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
"移除",
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
render();
|
|
166
|
+
|
|
167
|
+
const addOne = () => {
|
|
168
|
+
const v = input.value.trim();
|
|
169
|
+
if (!v) return;
|
|
170
|
+
let origin;
|
|
171
|
+
try {
|
|
172
|
+
origin = new URL(/^[a-z]+:\/\//i.test(v) ? v : `https://${v}`).origin;
|
|
173
|
+
} catch {
|
|
174
|
+
toast("地址不对");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!list.includes(origin)) list.push(origin);
|
|
178
|
+
input.value = "";
|
|
179
|
+
markDirty(box);
|
|
180
|
+
render();
|
|
181
|
+
};
|
|
182
|
+
input.addEventListener("keydown", (e) => {
|
|
183
|
+
if (e.key === "Enter") {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
addOne();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const save = async () => {
|
|
190
|
+
const ok = await saveConfig(cfg, { servers: { embedders: list } });
|
|
191
|
+
if (ok) box.replaceWith(embeddersSection(cfg));
|
|
192
|
+
return ok;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
fill(
|
|
196
|
+
box,
|
|
197
|
+
h("h4", {}, "允许被嵌入"),
|
|
198
|
+
h(
|
|
199
|
+
"div",
|
|
200
|
+
{ class: "muted" },
|
|
201
|
+
`别的 agent-loft 要在左上角切到这台,得先允许它嵌入这台的页面。一般不用手填:在那边加上这台(${location.origin})后点「授权」,在打开的页面里确认就行。切过来时照样要登录这台的账号。`,
|
|
202
|
+
),
|
|
203
|
+
rows,
|
|
204
|
+
h("div", { class: "row" }, input, h("button", { class: "btn", onclick: addOne }, "添加"), saveButton(save)),
|
|
205
|
+
);
|
|
206
|
+
return box;
|
|
207
|
+
}
|
package/web/state.js
CHANGED
|
@@ -45,6 +45,8 @@ export const ui = {};
|
|
|
45
45
|
* 桌面端收不到 Web Push,系统通知、Dock 角标、菜单栏的待处理数都交给它。
|
|
46
46
|
*/
|
|
47
47
|
export const desktop = window.agentLoftDesktop ?? null;
|
|
48
|
+
/** 被别的 agent-loft 嵌在 iframe 里(多服务器,见 lib/shell.js)。只有服务端允许了的地址嵌得进来 */
|
|
49
|
+
export const framed = !desktop && window.parent !== window;
|
|
48
50
|
/** 新版桌面端:额度由它统一查好推过来,页面自己不查(老版本桌面端没有 onQuota,照旧自己查) */
|
|
49
51
|
export const desktopQuota = typeof desktop?.onQuota === "function";
|
|
50
52
|
// 桌面端里:顶栏、侧栏顶部可以按住拖动窗口(样式见 css/topbar.css 的 .in-desktop)
|
package/web/views/auth.js
CHANGED
|
@@ -2,6 +2,7 @@ import { $app, fill, h } from "../lib/dom.js";
|
|
|
2
2
|
import { api } from "../lib/api.js";
|
|
3
3
|
import { WS } from "../lib/ws.js";
|
|
4
4
|
import { boot } from "./layout.js";
|
|
5
|
+
import { mountSwitcher } from "../lib/shell.js";
|
|
5
6
|
|
|
6
7
|
// ---------- 登录 ----------
|
|
7
8
|
|
|
@@ -56,6 +57,7 @@ export async function showAuth() {
|
|
|
56
57
|
btn,
|
|
57
58
|
err,
|
|
58
59
|
);
|
|
59
|
-
|
|
60
|
+
// 被嵌在别的服务器的页面里(多服务器):左上角照样能切回去,不然手机上就困在登录页了
|
|
61
|
+
fill($app, h("div", { class: "auth" }, mountSwitcher("auth", h("div", { class: "auth-switch", hidden: true })), form));
|
|
60
62
|
(me.needsSetup ? token : askName ? name : pw).focus();
|
|
61
63
|
}
|
package/web/views/composer.js
CHANGED
|
@@ -225,7 +225,7 @@ export async function ensureConversation() {
|
|
|
225
225
|
S.current = info.key;
|
|
226
226
|
S.allowedAgents = S.agents.filter((a) => a.enabled).map((a) => a.id);
|
|
227
227
|
S.seq.set(info.key, 0);
|
|
228
|
-
history.replaceState(
|
|
228
|
+
history.replaceState(history.state, "", `#${encodeURIComponent(info.key)}`);
|
|
229
229
|
WS.presence();
|
|
230
230
|
fill(ui.msgInner, );
|
|
231
231
|
WS.subscribe(info.key, 0);
|