omni-notify-mcp 1.3.366 → 1.3.367
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/dist/agentGateway.js +296 -0
- package/dist/daemon.js +131 -0
- package/dist/gateway/chatPage.js +727 -0
- package/dist/gateway/conversations.js +792 -0
- package/dist/gateway/lanProbe.js +86 -0
- package/dist/gateway/mcpDoor.js +390 -0
- package/dist/gateway/mcpEvents.js +448 -0
- package/dist/gateway/nativeTerminalWorker.js +170 -0
- package/dist/gateway/notifyDoor.js +165 -0
- package/dist/gateway/oauthDoor.js +345 -0
- package/dist/gateway/opencodeEvents.mjs +13 -0
- package/dist/gateway/opencodeProvider.js +249 -0
- package/dist/gateway/panel.js +189 -0
- package/dist/gateway/panelPage.js +214 -0
- package/dist/gateway/providers.js +16 -0
- package/dist/gateway/publicAccess.js +374 -0
- package/dist/gateway/restDoor.js +283 -0
- package/dist/gateway/sessionDriver.js +1014 -0
- package/dist/gateway/terminalDoor.js +247 -0
- package/dist/gateway/terminalPage.js +306 -0
- package/dist/gateway/tunnel.js +166 -0
- package/dist/messaging/emailInbound.js +292 -0
- package/dist/notify.js +2846 -0
- package/dist/shared/webhost/autoSwitch.cjs +1762 -0
- package/dist/shared/webhost/bullseyeWebHost.js +1329 -0
- package/dist/shared/webhost/originHandover.js +552 -0
- package/dist/shared/webhost/package.json +1 -0
- package/dist/shared/webhost/webviewShim.js +342 -0
- package/dist/shared/webhost/workspaceList.js +633 -0
- package/package.json +1 -1
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
import { PACKAGE_VERSION } from "../notify.js";
|
|
2
|
+
import { ICON_HEAD } from "./iconDoor.js";
|
|
3
|
+
import { PASSKEY_SCRIPT } from "./passkeyDoor.js";
|
|
4
|
+
import { PROOF_WAYS } from "./passkeyClient.js";
|
|
5
|
+
/** The ancestors allowed to frame this page, and nothing else. VS Code's own webview shell shows the one shared
|
|
6
|
+
* interface inside the extension panel (#2726); a scheme source admits any documentation of that scheme and no site.
|
|
7
|
+
* The same page is also framed in a browser (#3081): the Bullseye dashboard's web shell writes the panel's own HTML
|
|
8
|
+
* into an iframe on its OWN origin — the loopback web host, whose port is dynamic (`WebHost#url` at
|
|
9
|
+
* `~/.bullseye/webhost`), never a fixed one — so the frame it draws here is refused unless loopback is admitted too.
|
|
10
|
+
* A host of `127.0.0.1` or `localhost` with a port wildcard is the panel's own origin on any port it is actually
|
|
11
|
+
* served from, and no host off this machine. `x-frame-options` is not sent at all: it can only say DENY or SAMEORIGIN
|
|
12
|
+
* (its ALLOW-FROM origin list is dead), so a DENY here would contradict the policy below and be ignored by every
|
|
13
|
+
* browser that reads it — the two agree by the only rule both can express. */
|
|
14
|
+
export const CHAT_FRAME_ANCESTORS = "vscode-webview: vscode-file: https://*.vscode-cdn.net http://127.0.0.1:* http://localhost:*";
|
|
15
|
+
export const CHAT_HEADERS = {
|
|
16
|
+
"content-type": "text/html; charset=utf-8", "cache-control": "no-store, no-transform", "referrer-policy": "no-referrer",
|
|
17
|
+
"content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src 'self'; img-src 'self'; frame-ancestors ${CHAT_FRAME_ANCESTORS}`,
|
|
18
|
+
};
|
|
19
|
+
/** An event's own stored timestamp as a full date and time to the millisecond — `2026-10-25 15:04:07.412` — in this
|
|
20
|
+
* reader's timezone but read from the stored instant, never from a clock of the reader's. The fraction is taken
|
|
21
|
+
* from the string exactly as stored, so a ts that carries no milliseconds shows none instead of a padded `000`. */
|
|
22
|
+
export function storedStamp(iso) {
|
|
23
|
+
const at = new Date(iso);
|
|
24
|
+
const two = (n) => (n < 10 ? "0" : "") + n;
|
|
25
|
+
const fraction = /T\d{2}:\d{2}:\d{2}(\.\d+)/.exec(iso);
|
|
26
|
+
return `${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}:${two(at.getSeconds())}${fraction === null ? "" : fraction[1]}`;
|
|
27
|
+
}
|
|
28
|
+
/** When THIS process started, read from its own uptime once at load. Read once because a figure taken from a drifting
|
|
29
|
+
* float would differ by a millisecond between two reads of one page, and the start time is a fact about the process,
|
|
30
|
+
* not about the request — while a different process is a different load and prints its own. */
|
|
31
|
+
const PROCESS_STARTED_AT = new Date(Date.now() - Math.round(process.uptime() * 1000)).toISOString();
|
|
32
|
+
/** The process answering this page — the build its own code was loaded from, its pid, and the instant that process
|
|
33
|
+
* started. Never the installed extension's number and never a build-time stamp: a page that names a build it was not
|
|
34
|
+
* loaded from is exactly what this exists to prevent. */
|
|
35
|
+
export function servingIdentity() {
|
|
36
|
+
return { build: PACKAGE_VERSION, pid: process.pid, startedAt: PROCESS_STARTED_AT };
|
|
37
|
+
}
|
|
38
|
+
/** The line under the header naming the process that answered this page, built per request, so a page reloaded after
|
|
39
|
+
* the daemon replaced itself shows the build that is answering now. Shared by every page of the door (#2873). */
|
|
40
|
+
export function servingLine() {
|
|
41
|
+
const me = servingIdentity();
|
|
42
|
+
const line = `BN ${me.build} · pid ${me.pid} · started ${storedStamp(me.startedAt)}`;
|
|
43
|
+
return `<div id="serving" class="idbar" data-be-tip="The process that answered this page — the build its own code was loaded from, its process id, and when that process started — and when this page's sign-in expires"><span class="srv">${line}</span><small id="expires" hidden></small></div>`;
|
|
44
|
+
}
|
|
45
|
+
/** The look every page of the door shares (#2873): BN's page and each service page the public gateway serves. */
|
|
46
|
+
export const PAGE_STYLE = `:root{--bg:#fff;--fg:#111;--mut:#667;--line:#d8dce2;--me:#0b5fff;--agent:#eef1f5;--bad:#a40000}
|
|
47
|
+
@media(prefers-color-scheme:dark){:root{--bg:#14171c;--fg:#e8eaed;--mut:#9aa3b0;--line:#2b313b;--agent:#222831;--me:#2f6df0;--bad:#ff8a80}}
|
|
48
|
+
*{box-sizing:border-box}html,body{height:100%;margin:0}body{height:100dvh;font:16px system-ui,sans-serif;background:var(--bg);color:var(--fg);display:flex;flex-direction:column}
|
|
49
|
+
header{display:flex;flex-wrap:wrap;align-items:center;gap:3px;padding:3px 8px;min-height:26px;border-bottom:1px solid var(--line)}
|
|
50
|
+
header h1{font-size:14px;margin:0;flex:1 1 0;min-width:44px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
51
|
+
header button{flex:none;padding:3px 7px;font-size:13px;white-space:nowrap}
|
|
52
|
+
button{font:inherit;padding:8px 12px;border:1px solid var(--line);border-radius:8px;background:var(--agent);color:var(--fg)}
|
|
53
|
+
button.go{background:var(--me);border-color:var(--me);color:#fff}button:disabled{opacity:.5}
|
|
54
|
+
main{flex:1;min-height:0;overflow-y:auto;padding:10px 12px}
|
|
55
|
+
input,textarea{font:inherit;width:100%;padding:10px;border:1px solid var(--line);border-radius:8px;background:var(--bg);color:var(--fg)}
|
|
56
|
+
label{display:block;margin:10px 0 4px;color:var(--mut);font-size:14px}
|
|
57
|
+
.convscroll{max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch}
|
|
58
|
+
.conv{border-collapse:separate;border-spacing:0;font-size:14px;table-layout:fixed}
|
|
59
|
+
.conv th,.conv td{border-bottom:1px solid var(--line);border-right:1px solid var(--line);padding:6px 8px;text-align:left;vertical-align:middle;overflow:hidden}
|
|
60
|
+
.conv th:last-child,.conv td:last-child{border-right:0}
|
|
61
|
+
.conv thead th{color:var(--mut);font-size:12px;font-weight:600;letter-spacing:.03em;background:var(--agent);position:relative}
|
|
62
|
+
.conv th.sortable{cursor:pointer;user-select:none;padding-right:18px}
|
|
63
|
+
.conv th.sortable:focus-visible{outline:2px solid var(--me);outline-offset:-2px}
|
|
64
|
+
.sortmark{margin-left:6px;font-size:10px;opacity:.45}
|
|
65
|
+
.conv th[aria-sort="ascending"] .sortmark,.conv th[aria-sort="descending"] .sortmark{opacity:1;color:var(--fg)}
|
|
66
|
+
.colresize{position:absolute;top:0;right:-4px;width:9px;height:100%;cursor:col-resize;z-index:3;user-select:none;touch-action:none}
|
|
67
|
+
.colresize:hover,.colresize:active{background:var(--me);opacity:.3}
|
|
68
|
+
.conv tbody tr{cursor:pointer}.conv tbody tr:hover{background:rgba(127,127,127,.08)}
|
|
69
|
+
.conv tbody tr:focus-visible{outline:2px solid var(--me);outline-offset:-2px}
|
|
70
|
+
.conv tbody tr.sel{background:rgba(11,95,255,.12)}
|
|
71
|
+
.conv td{white-space:nowrap;text-overflow:ellipsis}
|
|
72
|
+
.conv td.statecell{white-space:normal;overflow-wrap:normal}
|
|
73
|
+
.conv td.timecell{font-size:12px;font-variant-numeric:tabular-nums}
|
|
74
|
+
.conv td.checkcell,.conv th.checkcell{text-align:center;padding:4px 6px}
|
|
75
|
+
.conv input[type=checkbox]{width:15px;height:15px;margin:0;cursor:pointer;vertical-align:middle}
|
|
76
|
+
.conv td.actions{white-space:normal}
|
|
77
|
+
.conv td.empty{color:var(--mut);text-align:center;padding:14px 8px;white-space:normal}
|
|
78
|
+
.idrow{display:flex;align-items:center;gap:6px;min-width:0;overflow:hidden}
|
|
79
|
+
.actrow{display:flex;gap:8px;align-items:center;flex-wrap:wrap;min-width:0}
|
|
80
|
+
.acts{display:flex;gap:4px;flex-wrap:wrap;margin:0}.acts button{padding:6px 8px;font-size:14px}
|
|
81
|
+
.listbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:0 0 8px;padding:6px 8px;border:1px solid var(--line);border-radius:10px;background:var(--agent)}
|
|
82
|
+
.listbar .count{font-size:13px;color:var(--mut);min-width:0;white-space:normal}
|
|
83
|
+
.listbar .spacer{flex:1 1 auto;min-width:0}
|
|
84
|
+
.listbar button{padding:6px 10px;font-size:13px}
|
|
85
|
+
.listbar .notice{flex:1 1 100%;font-size:13px;color:var(--mut);white-space:normal;overflow-wrap:anywhere;margin:0}
|
|
86
|
+
.listbar .notice.err{color:var(--bad)}
|
|
87
|
+
.listbar .pick{max-width:none}
|
|
88
|
+
.bad{color:var(--bad)}
|
|
89
|
+
.rowmeta{color:var(--mut);font-size:13px;white-space:normal;margin:1px 0}
|
|
90
|
+
.idline{display:flex;align-items:center;gap:6px;min-width:0;margin:2px 0}
|
|
91
|
+
.idline .tag{flex:none;color:var(--mut);font-size:11px;letter-spacing:.06em}
|
|
92
|
+
.conv-id{flex:0 1 auto;min-width:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px}
|
|
93
|
+
.copyid{flex:none;padding:1px 7px;border:1px solid var(--line);border-radius:6px;background:var(--agent);color:var(--fg);font-size:12px;cursor:pointer;user-select:none}
|
|
94
|
+
.copyid:active{transform:translateY(1px)}
|
|
95
|
+
.timeline{display:flex;flex-wrap:wrap;gap:4px 12px;color:var(--mut);font-size:12px;white-space:normal;margin:1px 0}
|
|
96
|
+
.timeline .t{font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
97
|
+
.convmeta{border:1px solid var(--line);border-radius:10px;padding:6px 10px;margin:0 0 10px}
|
|
98
|
+
.idbar{flex:none;display:flex;align-items:baseline;gap:8px;padding:2px 8px;border-bottom:1px solid var(--line);color:var(--mut);font-size:11px;line-height:15px;white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
99
|
+
.idbar .srv{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis}
|
|
100
|
+
.idbar #expires{flex:none}
|
|
101
|
+
.body{white-space:pre-wrap;overflow-wrap:anywhere;max-width:100%}
|
|
102
|
+
.body p{margin:0 0 6px}.body p:last-child{margin-bottom:0}
|
|
103
|
+
.body h1,.body h2,.body h3,.body h4,.body h5,.body h6{margin:10px 0 4px;line-height:1.25}
|
|
104
|
+
.body h1{font-size:1.35em}.body h2{font-size:1.22em}.body h3{font-size:1.12em}.body h4,.body h5,.body h6{font-size:1em}
|
|
105
|
+
.body ul,.body ol{margin:4px 0;padding-left:22px}.body li{margin:2px 0}
|
|
106
|
+
.body blockquote{margin:6px 0;padding:2px 10px;border-left:3px solid var(--line);color:var(--mut)}
|
|
107
|
+
.body pre{margin:6px 0;padding:8px 10px;border-radius:8px;background:rgba(127,127,127,.16);overflow-x:auto;max-width:100%}
|
|
108
|
+
.body pre code{background:none;padding:0;white-space:pre}
|
|
109
|
+
.body code{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:.92em;background:rgba(127,127,127,.16);padding:0 3px;border-radius:3px}
|
|
110
|
+
.body a{color:var(--me);text-decoration:underline}
|
|
111
|
+
.body hr{border:0;border-top:1px solid var(--line);margin:10px 0}
|
|
112
|
+
.body .tbl{max-width:100%;overflow-x:auto;margin:6px 0}
|
|
113
|
+
.body table{border-collapse:collapse;font-size:.94em;max-width:100%}
|
|
114
|
+
.body th,.body td{border:1px solid var(--line);padding:3px 7px;text-align:left;vertical-align:top;white-space:normal;overflow-wrap:anywhere}
|
|
115
|
+
.body th{background:rgba(127,127,127,.16);font-weight:700}
|
|
116
|
+
.user .body code,.user .body pre{background:rgba(255,255,255,.2)}.user .body a{color:#fff}
|
|
117
|
+
.msg{max-width:88%;margin:0 0 8px;padding:8px 12px;border-radius:14px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
118
|
+
.user{margin-left:auto;background:var(--me);color:#fff}.agent{background:var(--agent)}.system{color:var(--mut);font-size:14px;background:none;padding:2px 0}
|
|
119
|
+
.when{display:block;margin:0 0 2px;font-size:12px;opacity:.75;white-space:normal}.err{color:var(--bad);margin:8px 0}footer{display:flex;gap:8px;padding:4px 8px max(4px,env(safe-area-inset-bottom));border-top:1px solid var(--line)}footer textarea{height:44px;resize:none;min-width:0}
|
|
120
|
+
.tm{margin:6px 0 0;white-space:normal;font-size:13px}.tm summary{cursor:pointer;color:inherit;opacity:.85}.tm .box{overflow-x:auto;max-width:100%;margin-top:4px}
|
|
121
|
+
.tm table{border-collapse:collapse;width:100%}.tm td{padding:2px 4px;border-top:1px solid var(--line);vertical-align:top;overflow-wrap:anywhere}
|
|
122
|
+
.tm .tmbar{display:flex;justify-content:flex-end;align-items:center;margin:4px 0 0}.tm .tmbar button{padding:2px 8px;font-size:12px}.tm .tmbar .copynote{color:var(--mut);font-size:12px;margin-right:8px}
|
|
123
|
+
.tm td.ms{text-align:right;white-space:nowrap;font-variant-numeric:tabular-nums}.tm tr.part td:first-child{padding-left:16px;opacity:.8}.tm tr.sum td{font-weight:600}
|
|
124
|
+
@media(min-width:900px){main{padding:16px max(16px,calc(50% - 440px))}body.wide main{padding-left:16px;padding-right:16px}footer{padding-left:max(12px,calc(50% - 440px));padding-right:max(12px,calc(50% - 440px))}.msg{max-width:75%}}
|
|
125
|
+
.pick{display:flex;gap:4px;align-items:center;flex-wrap:wrap;min-width:0;max-width:200px}
|
|
126
|
+
.pick select{font:inherit;font-size:14px;padding:6px;border:1px solid var(--line);border-radius:8px;background:var(--agent);color:var(--fg);min-width:0;flex:1 1 auto;max-width:180px}
|
|
127
|
+
.pick input{flex:1 1 auto;min-width:0;max-width:240px;padding:6px}
|
|
128
|
+
.pick small{flex:1 1 100%;color:var(--bad);font-size:12px;overflow-wrap:anywhere}
|
|
129
|
+
[hidden]{display:none!important}`;
|
|
130
|
+
/** The sign-in half every page of the door shares (#2873): the kept session and its expiry, Logout, the sign-in screen and the
|
|
131
|
+
* check of a kept session on load. The page around it defines `main`, `el(tag, cls, text)`, `show(name, heading)` and
|
|
132
|
+
* `home()`, the screen a signed-in visitor lands on, and loads PASSKEY_SCRIPT before it. */
|
|
133
|
+
export const SIGN_IN_SCRIPT = `var KEY = "bn-chat-token";
|
|
134
|
+
var token = "";
|
|
135
|
+
var expiresAt = 0, expiryTimer;
|
|
136
|
+
var btnLogout = document.getElementById("logout"), expiryNotice = document.getElementById("expires");
|
|
137
|
+
try { token = localStorage.getItem(KEY) || ""; expiresAt = Number(localStorage.getItem(KEY + "-expires")) || 0; } catch (e) { token = ""; }
|
|
138
|
+
function armExpiry() {
|
|
139
|
+
clearTimeout(expiryTimer);
|
|
140
|
+
expiryNotice.textContent = expiresAt ? "⏳ Expires " + new Date(expiresAt).toLocaleString() : "";
|
|
141
|
+
if (expiresAt) expiryTimer = setTimeout(function () { signIn("Your sign-in expired. Sign in again."); }, Math.max(0, expiresAt - Date.now()));
|
|
142
|
+
}
|
|
143
|
+
function keep(value, deadline) {
|
|
144
|
+
expiresAt = value ? (deadline || 0) : 0;
|
|
145
|
+
try { if (value) localStorage.setItem(KEY, value); else localStorage.removeItem(KEY);
|
|
146
|
+
if (expiresAt) localStorage.setItem(KEY + "-expires", String(expiresAt)); else localStorage.removeItem(KEY + "-expires");
|
|
147
|
+
} catch (e) { return; } finally { armExpiry(); }
|
|
148
|
+
}
|
|
149
|
+
document.addEventListener("visibilitychange", function () { if (document.visibilityState === "visible" && expiresAt && Date.now() >= expiresAt) signIn("Your sign-in expired. Sign in again."); });
|
|
150
|
+
btnLogout.onclick = function () { var mine = view; btnLogout.disabled = true; pkSignOut(token).then(function () { if (mine === view) signIn("Signed out."); }, function (err) { if (mine !== view) return; btnLogout.disabled = false; main.append(el("div", "err", err.message)); }); };
|
|
151
|
+
|
|
152
|
+
async function signIn(notice) {
|
|
153
|
+
var mine = show("signin", "Sign in");
|
|
154
|
+
keep("");
|
|
155
|
+
token = "";
|
|
156
|
+
btnLogout.disabled = false;
|
|
157
|
+
var door;
|
|
158
|
+
try { door = await (await fetch("/passkey/state")).json(); }
|
|
159
|
+
catch (e) { if (mine === view) main.append(el("div", "err", "The gateway did not say how to sign in: " + e.message)); return; }
|
|
160
|
+
if (mine !== view) return;
|
|
161
|
+
var message = el("div", "err", notice || "");
|
|
162
|
+
if (door.enrolled && !door.local) {
|
|
163
|
+
signInMethods(main, door, function (session, deadline) { if (mine !== view) return; token = session; keep(session, deadline); home(); },
|
|
164
|
+
function (text) { message.textContent = text; });
|
|
165
|
+
}
|
|
166
|
+
if (!door.enrolled || door.local) {
|
|
167
|
+
var input = el("input"); input.type = "password"; input.autocomplete = "off";
|
|
168
|
+
var go = el("button", "go", "Sign in with token"); go.style.marginTop = "12px";
|
|
169
|
+
var submit = function () { token = input.value.trim(); if (token) { keep(token); home(); } };
|
|
170
|
+
go.onclick = submit;
|
|
171
|
+
input.onkeydown = function (e) { if (e.key === "Enter") submit(); };
|
|
172
|
+
main.append(el("label", "", "Gateway token (agentGateway.token)"), input, go);
|
|
173
|
+
var add = el("a", "", door.local ? "Add a passkey for your phone" : "Add a passkey (fingerprint)");
|
|
174
|
+
add.href = door.local ? "/passkey/setup" : "/passkey/enrol";
|
|
175
|
+
var hint = el("p", "system"); hint.append(add);
|
|
176
|
+
main.append(hint);
|
|
177
|
+
if (!door.local) main.append(el("p", "system", ${JSON.stringify(PROOF_WAYS.link)}));
|
|
178
|
+
input.focus();
|
|
179
|
+
}
|
|
180
|
+
main.append(message);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function resumeSignIn() {
|
|
184
|
+
var response = await fetch("/passkey/session", {headers:{authorization:"Bearer " + token}});
|
|
185
|
+
if (!response.ok) { signIn("Your sign-in expired or was revoked. Sign in again."); return; }
|
|
186
|
+
var session = await response.json();
|
|
187
|
+
keep(token, session.expiresIn === null ? 0 : Date.now() + session.expiresIn * 1000);
|
|
188
|
+
home();
|
|
189
|
+
}
|
|
190
|
+
function startSignIn() { if (token) resumeSignIn().catch(function (err) { signIn("Could not check sign-in: " + err.message); }); else signIn(""); }`;
|
|
191
|
+
/**
|
|
192
|
+
* The conversations half of BN's one page: the list he manages — the table, its per-row actions and the project picker.
|
|
193
|
+
* It is carried from the deleted Conversations page (#3401) into the native CLI page because that capability lives
|
|
194
|
+
* nowhere else. The transcript view is NOT carried and is gone (#3640): every conversation now opens on the provider's
|
|
195
|
+
* own full interactive CLI, so what was the record's reading view is the terminal itself. Its ONE creation control (the
|
|
196
|
+
* New form and `POST /v1/conversations`) is NOT carried either: the native CLI page's New Agent is the one way to
|
|
197
|
+
* create an agent. The functions here rely on the page's shared `el`, `api`, `base`, `main`, `show` and `storedStamp`,
|
|
198
|
+
* provided by the page's own script, and on the header buttons it builds (`btnBack`, `btnShelf`).
|
|
199
|
+
*/
|
|
200
|
+
export const CONVERSATIONS_VIEWS = `
|
|
201
|
+
/** The one way this page puts text on the clipboard, calling back with what happened. */
|
|
202
|
+
function copyText(value, copied, failed) {
|
|
203
|
+
var place = function () {
|
|
204
|
+
var area = document.createElement("textarea"); area.value = value; area.setAttribute("readonly", ""); area.style.position = "fixed"; area.style.opacity = "0";
|
|
205
|
+
document.body.append(area); area.select();
|
|
206
|
+
var done = false;
|
|
207
|
+
try { done = document.execCommand("copy"); } finally { area.remove(); }
|
|
208
|
+
if (done) copied(); else failed();
|
|
209
|
+
};
|
|
210
|
+
if (navigator.clipboard && window.isSecureContext) navigator.clipboard.writeText(value).then(copied, place); else place();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function copyValue(value, control) {
|
|
214
|
+
copyText(value,
|
|
215
|
+
function () { control.textContent = "Copied"; setTimeout(function () { control.textContent = "Copy ID"; }, 1400); },
|
|
216
|
+
function () { control.textContent = "Copy failed"; });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function copyControl(id) {
|
|
220
|
+
var control = el("span", "copyid", "Copy ID");
|
|
221
|
+
control.setAttribute("role", "button"); control.setAttribute("tabindex", "0");
|
|
222
|
+
control.setAttribute("aria-label", "Copy the full conversation id " + id);
|
|
223
|
+
control.title = "Copies the full id: " + id;
|
|
224
|
+
var copy = function (e) { e.stopPropagation(); e.preventDefault(); copyValue(id, control); };
|
|
225
|
+
control.onclick = copy;
|
|
226
|
+
control.onkeydown = function (e) { if (e.key === "Enter" || e.key === " ") copy(e); };
|
|
227
|
+
return control;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function idLine(id) {
|
|
231
|
+
var line = el("div", "idline");
|
|
232
|
+
var shown = el("code", "conv-id", id);
|
|
233
|
+
shown.title = id;
|
|
234
|
+
line.append(el("span", "tag", "ID"), shown, copyControl(id));
|
|
235
|
+
return line;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function timeLine(record) {
|
|
239
|
+
var line = el("div", "timeline");
|
|
240
|
+
line.append(el("span", "t", "opened " + storedStamp(record.createdAt)), el("span", "t", "updated " + storedStamp(record.updatedAt)));
|
|
241
|
+
return line;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** What a conversation runs on, in the words its own start line uses, and the model when the record carries one (#3353). */
|
|
245
|
+
function agentLine(record) {
|
|
246
|
+
var agent = AGENTS.filter(function (a) { return a.name === record.provider; })[0];
|
|
247
|
+
return record.state + " · " + (agent ? agent.label : record.provider) + (record.model ? " · " + record.model : "");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The project picker on a conversation's row (#2723, #2900): only the allowed projects BN lists that hold a board, no typed path.
|
|
252
|
+
* The pick posts the project NAME to POST /v1/conversations/{id}/project, and the row shows the new project once the
|
|
253
|
+
* record carries it; a refusal — a turn running, a folder that is not there — says why beside the picker.
|
|
254
|
+
*/
|
|
255
|
+
function projectPicker(c, folders, after) {
|
|
256
|
+
var box = el("span", "pick");
|
|
257
|
+
var pick = el("select");
|
|
258
|
+
pick.setAttribute("aria-label", "project folder");
|
|
259
|
+
var choices = [{ name: c.project ? base(c.project) : "no project", path: c.project || "" }].concat(folders);
|
|
260
|
+
var seen = {};
|
|
261
|
+
choices.forEach(function (choice) {
|
|
262
|
+
if (seen[choice.path]) return;
|
|
263
|
+
seen[choice.path] = true;
|
|
264
|
+
var option = el("option", "", choice.name);
|
|
265
|
+
option.value = choice.path;
|
|
266
|
+
pick.append(option);
|
|
267
|
+
});
|
|
268
|
+
pick.value = c.project || "";
|
|
269
|
+
var note = null;
|
|
270
|
+
var write = async function (folder) {
|
|
271
|
+
pick.disabled = true;
|
|
272
|
+
try { await api("POST", "/v1/conversations/" + c.id + "/project", { project: base(folder) }); await after(); pick.disabled = false; }
|
|
273
|
+
catch (err) {
|
|
274
|
+
pick.disabled = false;
|
|
275
|
+
pick.value = c.project || "";
|
|
276
|
+
if (note !== null) note.remove();
|
|
277
|
+
if (err.message !== "signed out") { note = el("small", "err", err.message); box.append(note); }
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
pick.onchange = function () {
|
|
281
|
+
if (pick.value) write(pick.value);
|
|
282
|
+
else pick.value = c.project || "";
|
|
283
|
+
};
|
|
284
|
+
box.append(pick);
|
|
285
|
+
box.onclick = function (e) { e.stopPropagation(); };
|
|
286
|
+
box.pick = pick;
|
|
287
|
+
return box;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async function listView(shelf) {
|
|
291
|
+
var archived = shelf === "archived";
|
|
292
|
+
var mine = show(archived ? "archived" : "list", archived ? "Archived" : "Conversations");
|
|
293
|
+
// Shown on the live list only (#3610): on the archived shelf the control that returns to the live list takes its place.
|
|
294
|
+
btnShelf.onclick = function () { go("archived"); };
|
|
295
|
+
var timer;
|
|
296
|
+
var rows = [];
|
|
297
|
+
var sort = { key: "updated", dir: -1 };
|
|
298
|
+
var widths = {};
|
|
299
|
+
var picked = {};
|
|
300
|
+
var anchor = null;
|
|
301
|
+
var folders = [];
|
|
302
|
+
var foldersNote = "";
|
|
303
|
+
try { folders = (await api("GET", "/v1/projects")).projects.filter(function (p) { return p.board; }).map(function (p) { return { name: p.name, path: p.path }; }); }
|
|
304
|
+
catch (err) { if (err.message === "signed out") return; foldersNote = "The project folders could not be read — " + err.message + "."; }
|
|
305
|
+
if (mine !== view) return;
|
|
306
|
+
var act = async function (button, method, path) {
|
|
307
|
+
button.disabled = true;
|
|
308
|
+
try { await api(method, path); await paint(); }
|
|
309
|
+
catch (err) { if (err.message !== "signed out") { button.disabled = false; main.append(el("div", "err", err.message)); } }
|
|
310
|
+
};
|
|
311
|
+
var cols = [
|
|
312
|
+
{ key: "", check: true, name: "", min: 34, weight: 0 },
|
|
313
|
+
{ key: "project", name: "Project", min: 104, weight: 1.3 },
|
|
314
|
+
{ key: "state", name: "State", min: 96, weight: 1.1, state: true },
|
|
315
|
+
{ key: "origin", name: "From", min: 72, weight: 0.7 },
|
|
316
|
+
{ key: "provider", name: "Provider", min: 88, weight: 0.9 },
|
|
317
|
+
{ key: "id", name: "Conversation ID", min: 190, weight: 1.5 },
|
|
318
|
+
{ key: "process", name: "Process ID", min: 96, weight: 0.8 },
|
|
319
|
+
{ key: "opened", name: "Opened", min: 152, weight: 1, time: true },
|
|
320
|
+
{ key: "updated", name: "Updated", min: 152, weight: 1, time: true },
|
|
321
|
+
{ key: "actions", name: "Actions", min: 216, weight: 0, plain: true }
|
|
322
|
+
];
|
|
323
|
+
var keyOf = function (col) { return col.key || "_check"; };
|
|
324
|
+
var value = function (c, key) {
|
|
325
|
+
if (key === "project") return c.project ? base(c.project).toLowerCase() : "";
|
|
326
|
+
if (key === "state") return c.state;
|
|
327
|
+
if (key === "provider") return c.provider;
|
|
328
|
+
if (key === "origin") return originOf(c);
|
|
329
|
+
if (key === "id") return c.id;
|
|
330
|
+
if (key === "process") return typeof c.pid === "number" ? c.pid : -1;
|
|
331
|
+
if (key === "opened") return Date.parse(c.createdAt);
|
|
332
|
+
if (key === "updated") return Date.parse(c.updatedAt);
|
|
333
|
+
return "";
|
|
334
|
+
};
|
|
335
|
+
var ordered = function () {
|
|
336
|
+
if (sort.dir === 0) return rows.slice();
|
|
337
|
+
var key = sort.key;
|
|
338
|
+
return rows.slice().sort(function (a, b) {
|
|
339
|
+
var x = value(a, key), y = value(b, key);
|
|
340
|
+
var cmp = typeof x === "number" && typeof y === "number" ? x - y : x < y ? -1 : x > y ? 1 : 0;
|
|
341
|
+
return cmp * sort.dir;
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
var stateText = function (c) { return c.state; };
|
|
345
|
+
var textOf = function (c, col) {
|
|
346
|
+
if (col.key === "project") return c.project ? base(c.project) : "No project";
|
|
347
|
+
if (col.key === "state") return stateText(c);
|
|
348
|
+
if (col.key === "provider") return c.provider;
|
|
349
|
+
if (col.key === "origin") return originOf(c);
|
|
350
|
+
if (col.key === "id") return c.id;
|
|
351
|
+
if (col.key === "process") return typeof c.pid === "number" ? String(c.pid) : "no process";
|
|
352
|
+
if (col.key === "opened") return storedStamp(c.createdAt);
|
|
353
|
+
if (col.key === "updated") return storedStamp(c.updatedAt);
|
|
354
|
+
return "";
|
|
355
|
+
};
|
|
356
|
+
var titleOf = function (c, col) {
|
|
357
|
+
if (col.key === "project") return c.project || "";
|
|
358
|
+
if (col.key === "provider") return c.provider;
|
|
359
|
+
if (col.key === "id") return c.id;
|
|
360
|
+
return "";
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
var scroll = null, table = null, headRow = null, body = null, countEl = null, noticeEl = null, selectAll = null, emptyRow = null;
|
|
364
|
+
/** Whether this row's stop slot has anything to act on — the ONE rule both the row's button and the batch button use, so a row the batch would not act on is never offered as one it would. */
|
|
365
|
+
var stoppable = function (c) {
|
|
366
|
+
return c.state !== "closed";
|
|
367
|
+
};
|
|
368
|
+
var haltState = function (button, c) {
|
|
369
|
+
button.disabled = !stoppable(c);
|
|
370
|
+
button.title = button.disabled ? "This conversation is already stopped. A message resumes it." : "Stops this conversation — it runs no further turn, and a later message resumes it.";
|
|
371
|
+
};
|
|
372
|
+
var colEls = [], ths = [], buttons = {};
|
|
373
|
+
var dom = {};
|
|
374
|
+
var shown = [];
|
|
375
|
+
|
|
376
|
+
var layout = function () {
|
|
377
|
+
if (table === null) return;
|
|
378
|
+
var W = scroll.clientWidth || 900;
|
|
379
|
+
var sumMin = 0, pinned = 0, flexMin = 0, flexW = 0;
|
|
380
|
+
cols.forEach(function (col) {
|
|
381
|
+
sumMin += col.min;
|
|
382
|
+
var set = widths[keyOf(col)];
|
|
383
|
+
if (set !== undefined) pinned += set;
|
|
384
|
+
else if (col.weight) { flexMin += col.min; flexW += col.weight; }
|
|
385
|
+
else pinned += col.min;
|
|
386
|
+
});
|
|
387
|
+
var extra = Math.max(0, Math.max(W, sumMin) - pinned - flexMin);
|
|
388
|
+
var total = 0;
|
|
389
|
+
cols.forEach(function (col, i) {
|
|
390
|
+
var w = widths[keyOf(col)];
|
|
391
|
+
if (w === undefined) w = col.weight ? col.min + (flexW ? extra * col.weight / flexW : 0) : col.min;
|
|
392
|
+
w = Math.round(w);
|
|
393
|
+
colEls[i].style.width = w + "px";
|
|
394
|
+
total += w;
|
|
395
|
+
});
|
|
396
|
+
table.style.width = total + "px";
|
|
397
|
+
};
|
|
398
|
+
var setWidth = function (i, w) { widths[keyOf(cols[i])] = Math.max(cols[i].min, Math.round(w)); layout(); };
|
|
399
|
+
var resizeHandle = function (i) {
|
|
400
|
+
var grip = el("span", "colresize");
|
|
401
|
+
grip.setAttribute("aria-hidden", "true");
|
|
402
|
+
grip.addEventListener("mousedown", function (e) {
|
|
403
|
+
e.preventDefault(); e.stopPropagation();
|
|
404
|
+
var x0 = e.clientX, w0 = ths[i].getBoundingClientRect().width;
|
|
405
|
+
var move = function (ev) { setWidth(i, w0 + ev.clientX - x0); };
|
|
406
|
+
var up = function () { document.removeEventListener("mousemove", move); document.removeEventListener("mouseup", up); document.body.style.cursor = ""; document.body.style.userSelect = ""; };
|
|
407
|
+
document.addEventListener("mousemove", move); document.addEventListener("mouseup", up);
|
|
408
|
+
document.body.style.cursor = "col-resize"; document.body.style.userSelect = "none";
|
|
409
|
+
});
|
|
410
|
+
grip.onclick = function (e) { e.stopPropagation(); };
|
|
411
|
+
return grip;
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
var indexOfNode = function (node) { for (var i = 0; i < shown.length; i++) if (shown[i].id === node.c.id) return i; return -1; };
|
|
415
|
+
var fromRow = function (node, checked, shift) {
|
|
416
|
+
var i = indexOfNode(node);
|
|
417
|
+
if (shift && anchor !== null) {
|
|
418
|
+
var a = Math.min(anchor, i), b = Math.max(anchor, i);
|
|
419
|
+
for (var k = a; k <= b; k++) { if (checked) picked[shown[k].id] = true; else delete picked[shown[k].id]; }
|
|
420
|
+
} else if (checked) picked[node.c.id] = true; else delete picked[node.c.id];
|
|
421
|
+
anchor = i;
|
|
422
|
+
render();
|
|
423
|
+
};
|
|
424
|
+
var extendRange = function (node) {
|
|
425
|
+
var i = indexOfNode(node);
|
|
426
|
+
if (anchor === null) { picked[node.c.id] = true; anchor = i; }
|
|
427
|
+
else { var a = Math.min(anchor, i), b = Math.max(anchor, i); for (var k = a; k <= b; k++) picked[shown[k].id] = true; }
|
|
428
|
+
render();
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
var createNode = function (first) {
|
|
432
|
+
var tr = el("tr");
|
|
433
|
+
tr.tabIndex = 0;
|
|
434
|
+
tr.setAttribute("aria-label", "Open conversation " + first.id);
|
|
435
|
+
var node = { tr: tr, cells: [], c: first };
|
|
436
|
+
cols.forEach(function (col, i) {
|
|
437
|
+
if (col.check) {
|
|
438
|
+
var td = el("td", "checkcell");
|
|
439
|
+
var box = el("input"); box.type = "checkbox";
|
|
440
|
+
box.setAttribute("aria-label", "Select conversation " + first.id);
|
|
441
|
+
box.onclick = function (e) { e.stopPropagation(); fromRow(node, box.checked, e.shiftKey); };
|
|
442
|
+
td.append(box);
|
|
443
|
+
tr.append(td);
|
|
444
|
+
node.cells.push({ td: td, box: box, col: col });
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
var cls = col.state ? "statecell" : col.time ? "timecell" : col.plain ? "actions" : "";
|
|
448
|
+
var cell = el("td", cls);
|
|
449
|
+
cell.dataset.label = col.name;
|
|
450
|
+
if (col.key === "id") {
|
|
451
|
+
var idrow = el("div", "idrow");
|
|
452
|
+
var code = el("code", "conv-id");
|
|
453
|
+
idrow.append(code, copyControl(first.id));
|
|
454
|
+
cell.append(idrow);
|
|
455
|
+
tr.append(cell);
|
|
456
|
+
node.cells.push({ td: cell, code: code, col: col });
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (col.plain) {
|
|
460
|
+
// ONE action row for every session (#3614, #3916): Open, Stop, Archive/Restore, Delete, then the project slot.
|
|
461
|
+
var actrow = el("div", "actrow");
|
|
462
|
+
var acts = el("div", "acts");
|
|
463
|
+
var open = el("button", "", "📂 Open");
|
|
464
|
+
open.onclick = function (e) { e.stopPropagation(); go("term", node.c.id); };
|
|
465
|
+
acts.append(open);
|
|
466
|
+
// A conversation is STOPPED — its CLI ends, it runs no further turn and a later message resumes the same session.
|
|
467
|
+
var halt = el("button", "halt", "⏹ Stop");
|
|
468
|
+
halt.onclick = function (e) {
|
|
469
|
+
e.stopPropagation();
|
|
470
|
+
act(halt, "DELETE", "/v1/conversations/" + node.c.id);
|
|
471
|
+
};
|
|
472
|
+
acts.append(halt);
|
|
473
|
+
node.halt = halt;
|
|
474
|
+
var move = el("button", "", archived ? "Restore" : "Archive");
|
|
475
|
+
move.onclick = function (e) { e.stopPropagation(); act(move, "POST", "/v1/conversations/" + node.c.id + (archived ? "/unarchive" : "/archive")); };
|
|
476
|
+
var drop = el("button", "bad", "Delete");
|
|
477
|
+
drop.onclick = function (e) { e.stopPropagation(); act(drop, "POST", "/v1/conversations/" + node.c.id + "/delete"); };
|
|
478
|
+
acts.append(move, drop);
|
|
479
|
+
actrow.append(acts);
|
|
480
|
+
node.pick = projectPicker(node.c, folders, paint);
|
|
481
|
+
actrow.append(node.pick);
|
|
482
|
+
cell.append(actrow);
|
|
483
|
+
tr.append(cell);
|
|
484
|
+
node.cells.push({ td: cell, col: col });
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
tr.append(cell);
|
|
488
|
+
node.cells.push({ td: cell, col: col });
|
|
489
|
+
});
|
|
490
|
+
tr.onclick = function (e) { if (e.shiftKey) { e.preventDefault(); extendRange(node); return; } go("term", node.c.id); };
|
|
491
|
+
tr.onkeydown = function (e) { if (e.target === tr && (e.key === "Enter" || e.key === " ")) { e.preventDefault(); go("term", node.c.id); } };
|
|
492
|
+
return node;
|
|
493
|
+
};
|
|
494
|
+
var updateNode = function (node, c) {
|
|
495
|
+
Object.keys(node.c).forEach(function (k) { if (!(k in c)) delete node.c[k]; });
|
|
496
|
+
Object.keys(c).forEach(function (k) { node.c[k] = c[k]; });
|
|
497
|
+
node.tr.className = picked[c.id] ? "sel" : "";
|
|
498
|
+
cols.forEach(function (col, i) {
|
|
499
|
+
var cell = node.cells[i];
|
|
500
|
+
if (col.check) { cell.box.checked = !!picked[c.id]; return; }
|
|
501
|
+
if (col.plain) {
|
|
502
|
+
if (node.halt) haltState(node.halt, c);
|
|
503
|
+
if (node.pick) {
|
|
504
|
+
var sel = node.pick.pick;
|
|
505
|
+
var wanted = c.project || "";
|
|
506
|
+
var has = Array.prototype.some.call(sel.options, function (o) { return o.value === wanted; });
|
|
507
|
+
if (!has) { var opt = el("option", "", wanted ? base(wanted) : "no project"); opt.value = wanted; sel.insertBefore(opt, sel.firstChild); }
|
|
508
|
+
if (sel.value !== wanted) sel.value = wanted;
|
|
509
|
+
}
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (col.key === "id") { if (cell.code.textContent !== c.id) cell.code.textContent = c.id; cell.code.title = c.id; return; }
|
|
513
|
+
var text = textOf(c, col);
|
|
514
|
+
if (cell.td.textContent !== text) cell.td.textContent = text;
|
|
515
|
+
var tip = titleOf(c, col);
|
|
516
|
+
if (tip) { if (cell.td.title !== tip) cell.td.title = tip; } else cell.td.title = "";
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
var render = function () {
|
|
520
|
+
shown = ordered();
|
|
521
|
+
var want = {};
|
|
522
|
+
shown.forEach(function (c) { want[c.id] = true; });
|
|
523
|
+
Object.keys(dom).forEach(function (id) { if (!want[id]) { dom[id].tr.remove(); delete dom[id]; } });
|
|
524
|
+
shown.forEach(function (c) {
|
|
525
|
+
var node = dom[c.id];
|
|
526
|
+
if (node === undefined) { node = createNode(c); dom[c.id] = node; }
|
|
527
|
+
updateNode(node, c);
|
|
528
|
+
body.append(node.tr);
|
|
529
|
+
});
|
|
530
|
+
if (shown.length === 0) {
|
|
531
|
+
if (emptyRow === null) {
|
|
532
|
+
emptyRow = el("tr");
|
|
533
|
+
var cell = el("td", "empty", archived ? "Nothing archived." : "No conversations yet. Open one from the CLI page.");
|
|
534
|
+
cell.colSpan = cols.length;
|
|
535
|
+
emptyRow.append(cell);
|
|
536
|
+
}
|
|
537
|
+
body.append(emptyRow);
|
|
538
|
+
} else if (emptyRow !== null && emptyRow.parentNode) emptyRow.remove();
|
|
539
|
+
cols.forEach(function (col, i) {
|
|
540
|
+
if (!col.key || col.plain) return;
|
|
541
|
+
var th = ths[i];
|
|
542
|
+
var active = sort.key === col.key && sort.dir !== 0;
|
|
543
|
+
th.setAttribute("aria-sort", active ? (sort.dir > 0 ? "ascending" : "descending") : "none");
|
|
544
|
+
var mark = th.querySelector(".sortmark");
|
|
545
|
+
if (mark !== null) mark.textContent = sort.key !== col.key ? "↕" : sort.dir > 0 ? "▲" : sort.dir < 0 ? "▼" : "↕";
|
|
546
|
+
});
|
|
547
|
+
var n = 0;
|
|
548
|
+
shown.forEach(function (c) { if (picked[c.id]) n++; });
|
|
549
|
+
countEl.textContent = n === 0 ? "Select conversations to act on them." : n + " selected";
|
|
550
|
+
if (selectAll !== null) { selectAll.checked = shown.length > 0 && n === shown.length; selectAll.indeterminate = n > 0 && n < shown.length; }
|
|
551
|
+
[buttons.move, buttons.delete, buttons.clear].forEach(function (b) { if (b) b.disabled = n === 0; });
|
|
552
|
+
// Stop is offered only when at least one picked row has something to stop (#3614): a conversation already stopped has none.
|
|
553
|
+
if (buttons.stop) buttons.stop.disabled = !shown.some(function (c) { return picked[c.id] === true && stoppable(c); });
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
/** Puts what happened to one conversation on that conversation's own row — a null why clears it — so a conversation the action could not change is named with its reason instead of lost in a count. */
|
|
557
|
+
var markRowFailed = function (id, why) {
|
|
558
|
+
var node = dom[id];
|
|
559
|
+
if (node === undefined) return;
|
|
560
|
+
var cell = node.cells[cols.length - 1].td;
|
|
561
|
+
var stale = cell.querySelector ? cell.querySelector(".rowfail") : null;
|
|
562
|
+
if (stale) stale.remove();
|
|
563
|
+
if (why) cell.append(el("small", "err rowfail", why));
|
|
564
|
+
};
|
|
565
|
+
var runBatch = async function (which) {
|
|
566
|
+
var chosen = shown.filter(function (c) { return picked[c.id]; });
|
|
567
|
+
if (chosen.length === 0) return;
|
|
568
|
+
// The batch applies to each row the SAME act that row's own button applies (#3614).
|
|
569
|
+
var call = function (c) {
|
|
570
|
+
if (which !== "stop") return api("POST", "/v1/conversations/" + c.id + (which === "delete" ? "/delete" : archived ? "/unarchive" : "/archive"));
|
|
571
|
+
return api("DELETE", "/v1/conversations/" + c.id);
|
|
572
|
+
};
|
|
573
|
+
var word = which === "stop" ? "stopped" : which === "delete" ? "deleted" : archived ? "restored" : "archived";
|
|
574
|
+
// A row with nothing to stop is left alone and named as having nothing to stop — never called and then reported as
|
|
575
|
+
// a failure for refusing, which is what a 404 for an already-ended CLI would look like (#3614).
|
|
576
|
+
var acts = which === "stop" ? chosen.filter(stoppable) : chosen;
|
|
577
|
+
var untouched = chosen.filter(function (c) { return !acts.includes(c); });
|
|
578
|
+
noticeEl.className = "notice";
|
|
579
|
+
noticeEl.textContent = (which === "delete" ? "Deleting " : which === "stop" ? "Stopping " : which === "move" ? (archived ? "Restoring " : "Archiving ") : "Working on ") + acts.length + (acts.length === 1 ? " conversation…" : " conversations…");
|
|
580
|
+
var done = 0, failed = [];
|
|
581
|
+
for (var i = 0; i < acts.length; i++) {
|
|
582
|
+
markRowFailed(acts[i].id, null);
|
|
583
|
+
try { await call(acts[i]); done++; }
|
|
584
|
+
catch (err) { if (err.message === "signed out") return; failed.push({ id: acts[i].id, why: err.message }); }
|
|
585
|
+
}
|
|
586
|
+
picked = {}; anchor = null;
|
|
587
|
+
await paint();
|
|
588
|
+
failed.forEach(function (f) { markRowFailed(f.id, f.why); });
|
|
589
|
+
untouched.forEach(function (c) { markRowFailed(c.id, "Nothing to stop here — this conversation is already stopped."); });
|
|
590
|
+
noticeEl.textContent = done + " of " + chosen.length + " " + word
|
|
591
|
+
+ (untouched.length ? " — " + untouched.length + (untouched.length === 1 ? " had" : " had") + " nothing to stop" : "")
|
|
592
|
+
+ (failed.length ? " — " + failed.length + (failed.length === 1 ? " was" : " were") + " not " + word + ", with the reason on " + (failed.length === 1 ? "its row" : "their rows") : "");
|
|
593
|
+
noticeEl.className = failed.length ? "notice err" : "notice";
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
var build = function () {
|
|
597
|
+
main.replaceChildren();
|
|
598
|
+
dom = {};
|
|
599
|
+
var bar = el("div", "listbar");
|
|
600
|
+
countEl = el("span", "count", "");
|
|
601
|
+
bar.append(countEl, el("span", "spacer"));
|
|
602
|
+
var mkButton = function (label, cls, key) {
|
|
603
|
+
var b = el("button", cls, label);
|
|
604
|
+
b.disabled = true;
|
|
605
|
+
b.onclick = function () { runBatch(key); };
|
|
606
|
+
buttons[key] = b;
|
|
607
|
+
bar.append(b);
|
|
608
|
+
return b;
|
|
609
|
+
};
|
|
610
|
+
if (!archived) mkButton("Stop", "", "stop");
|
|
611
|
+
mkButton(archived ? "Restore" : "Archive", "", "move");
|
|
612
|
+
mkButton("Delete", "bad", "delete");
|
|
613
|
+
buttons.clear = el("button", "", "Clear");
|
|
614
|
+
buttons.clear.disabled = true;
|
|
615
|
+
buttons.clear.onclick = function () { picked = {}; anchor = null; render(); };
|
|
616
|
+
bar.append(buttons.clear);
|
|
617
|
+
noticeEl = el("span", "notice", "");
|
|
618
|
+
bar.append(noticeEl);
|
|
619
|
+
main.append(bar);
|
|
620
|
+
|
|
621
|
+
scroll = el("div", "convscroll");
|
|
622
|
+
table = el("table", "conv");
|
|
623
|
+
var colgroup = el("colgroup");
|
|
624
|
+
colEls = cols.map(function () { var cc = el("col"); colgroup.append(cc); return cc; });
|
|
625
|
+
table.append(colgroup);
|
|
626
|
+
var head = el("thead");
|
|
627
|
+
headRow = el("tr");
|
|
628
|
+
ths = cols.map(function (col, i) {
|
|
629
|
+
var th = el("th", col.check ? "checkcell" : "");
|
|
630
|
+
if (col.check) {
|
|
631
|
+
selectAll = el("input"); selectAll.type = "checkbox";
|
|
632
|
+
selectAll.setAttribute("aria-label", "Select all conversations");
|
|
633
|
+
selectAll.onclick = function (e) {
|
|
634
|
+
e.stopPropagation();
|
|
635
|
+
var on = selectAll.checked;
|
|
636
|
+
shown.forEach(function (c) { if (on) picked[c.id] = true; else delete picked[c.id]; });
|
|
637
|
+
anchor = null;
|
|
638
|
+
render();
|
|
639
|
+
};
|
|
640
|
+
th.append(selectAll);
|
|
641
|
+
} else if (col.key && !col.plain) {
|
|
642
|
+
th.className = "sortable k-" + col.key;
|
|
643
|
+
th.tabIndex = 0;
|
|
644
|
+
th.append(el("span", "", col.name), el("span", "sortmark", "↕"));
|
|
645
|
+
th.onclick = function () { sort = { key: col.key, dir: sort.key !== col.key ? 1 : sort.dir === 1 ? -1 : sort.dir === -1 ? 0 : 1 }; render(); };
|
|
646
|
+
th.onkeydown = function (e) { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); th.click(); } };
|
|
647
|
+
th.append(resizeHandle(i));
|
|
648
|
+
} else th.append(el("span", "", col.name));
|
|
649
|
+
headRow.append(th);
|
|
650
|
+
return th;
|
|
651
|
+
});
|
|
652
|
+
head.append(headRow);
|
|
653
|
+
table.append(head);
|
|
654
|
+
body = el("tbody");
|
|
655
|
+
table.append(body);
|
|
656
|
+
scroll.append(table);
|
|
657
|
+
main.append(scroll);
|
|
658
|
+
if (foldersNote) main.append(el("div", "err", foldersNote));
|
|
659
|
+
layout();
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
var paint = function () {
|
|
663
|
+
return api("GET", "/v1/conversations" + (archived ? "?shelf=archived" : "")).then(function (data) {
|
|
664
|
+
if (mine !== view) return;
|
|
665
|
+
rows = data.conversations.slice();
|
|
666
|
+
if (table === null) build();
|
|
667
|
+
render();
|
|
668
|
+
});
|
|
669
|
+
};
|
|
670
|
+
var again = function () { timer = setTimeout(run, 8000); };
|
|
671
|
+
var picking = function () { var at = document.activeElement; return at !== null && at.closest && at.closest(".pick") !== null; };
|
|
672
|
+
var run = function () { if (mine !== view) return; if (picking()) { again(); return; } paint().then(again, function (err) { fail(err); again(); }); };
|
|
673
|
+
var fail = function (err) { if (mine === view && err.message !== "signed out") { table = null; main.replaceChildren(el("div", "err", err.message)); } };
|
|
674
|
+
if (listResize !== null) window.removeEventListener("resize", listResize);
|
|
675
|
+
listResize = function () { if (mine === view) layout(); };
|
|
676
|
+
window.addEventListener("resize", listResize);
|
|
677
|
+
run();
|
|
678
|
+
}
|
|
679
|
+
`;
|
|
680
|
+
/** A service page's own half (#3849): once signed in, the gateway's `/screen/open` keeps the sign-in for the page's own
|
|
681
|
+
* requests and names the one page this host's own service draws, and the visitor goes straight to it — no VS Code
|
|
682
|
+
* window is chosen or needed. */
|
|
683
|
+
const SERVICE_SCRIPT = String.raw `
|
|
684
|
+
var main = document.getElementById("main"), title = document.getElementById("title"), btnRefresh = document.getElementById("refresh");
|
|
685
|
+
var view = 0;
|
|
686
|
+
function el(tag, cls, content) { var node = document.createElement(tag); if (cls) node.className = cls; if (content !== undefined) node.textContent = content; return node; }
|
|
687
|
+
function show(name, heading) {
|
|
688
|
+
view++;
|
|
689
|
+
title.textContent = heading;
|
|
690
|
+
btnRefresh.hidden = name !== "screens";
|
|
691
|
+
btnLogout.hidden = name === "signin";
|
|
692
|
+
expiryNotice.hidden = name === "signin";
|
|
693
|
+
main.replaceChildren();
|
|
694
|
+
return view;
|
|
695
|
+
}
|
|
696
|
+
async function home() {
|
|
697
|
+
var mine = show("screens", TITLE);
|
|
698
|
+
btnRefresh.onclick = function () { home(); };
|
|
699
|
+
var said = el("p", "system", "⏳ Opening " + TITLE + "…");
|
|
700
|
+
main.append(said);
|
|
701
|
+
try {
|
|
702
|
+
var res = await fetch("/screen/open", { method: "POST", headers: { authorization: "Bearer " + token } });
|
|
703
|
+
if (res.status === 401) { signIn("You are signed out. Sign in again."); return; }
|
|
704
|
+
if (!res.ok) throw new Error("The gateway answered " + res.status + ": " + await res.text());
|
|
705
|
+
var opened = await res.json();
|
|
706
|
+
if (mine === view) location.replace(opened.page);
|
|
707
|
+
} catch (err) { if (!(err instanceof Error)) throw err; if (mine === view) said.replaceWith(el("div", "err", err.message)); }
|
|
708
|
+
}
|
|
709
|
+
`;
|
|
710
|
+
/** The page each service host of the public gateway serves (#2873): BN's look and BN's sign-in, then the page the
|
|
711
|
+
* service's daemon draws. The line under the header names the process that answered. */
|
|
712
|
+
export function serviceHtml({ name, host }) {
|
|
713
|
+
const me = servingIdentity();
|
|
714
|
+
const safe = (text) => text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
715
|
+
const facts = JSON.stringify({ name }).replace(/</g, "\\u003c");
|
|
716
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
|
|
717
|
+
<title>${safe(name)}</title>${ICON_HEAD}<style>${PAGE_STYLE}</style></head><body>
|
|
718
|
+
<header><h1 id="title">${safe(name)}</h1><button id="refresh" hidden>🔄 Refresh</button><button id="logout" hidden>🚪 Logout</button></header>
|
|
719
|
+
<div id="serving" class="idbar" data-be-tip="The process that answered this page — its process id, when it started and the sign-in build its code was loaded from — and when this page's sign-in expires"><span class="srv">${safe(host)} · pid ${me.pid} · started ${storedStamp(me.startedAt)} · sign-in BN ${safe(me.build)}</span><small id="expires" hidden></small></div>
|
|
720
|
+
<main id="main"></main>
|
|
721
|
+
<script>var FACTS = ${facts}, TITLE = FACTS.name;
|
|
722
|
+
${PASSKEY_SCRIPT}
|
|
723
|
+
${SIGN_IN_SCRIPT}
|
|
724
|
+
${SERVICE_SCRIPT}
|
|
725
|
+
startSignIn();
|
|
726
|
+
</script></body></html>`;
|
|
727
|
+
}
|