@nanocollective/roster 0.1.0-beta.2 → 0.1.0-beta.21
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 +8 -0
- package/dist/agents-POITEZRI.js +232 -0
- package/dist/chunk-FF2WBNNW.js +370 -0
- package/dist/chunk-GDAJPOHK.js +562 -0
- package/dist/cli.js +3187 -1105
- package/dist/compose-5DBEHSEV.js +17 -0
- package/dist/connectors-5E5ZMGZV.js +23 -0
- package/dist/worker/assets/assets/css/base.css +21 -2
- package/dist/worker/assets/assets/css/brain.css +20 -0
- package/dist/worker/assets/assets/css/connectors.css +50 -0
- package/dist/worker/assets/assets/css/home.css +141 -54
- package/dist/worker/assets/assets/css/inbox.css +11 -0
- package/dist/worker/assets/assets/css/layout.css +6 -0
- package/dist/worker/assets/assets/css/markdown.css +21 -0
- package/dist/worker/assets/assets/css/routines.css +40 -0
- package/dist/worker/assets/assets/js/api.js +33 -0
- package/dist/worker/assets/assets/js/app.js +47 -3
- package/dist/worker/assets/assets/js/homesort.js +28 -21
- package/dist/worker/assets/assets/js/icons.js +4 -0
- package/dist/worker/assets/assets/js/md.js +7 -2
- package/dist/worker/assets/assets/js/refcard.js +216 -0
- package/dist/worker/assets/assets/js/refresh.js +4 -2
- package/dist/worker/assets/assets/js/report.js +51 -0
- package/dist/worker/assets/assets/js/state.js +14 -1
- package/dist/worker/assets/assets/js/views/connectors.js +290 -0
- package/dist/worker/assets/assets/js/views/home.js +368 -152
- package/dist/worker/assets/assets/js/views/inbox.js +68 -16
- package/dist/worker/assets/assets/js/views/org.js +2 -0
- package/dist/worker/assets/assets/js/views/people.js +103 -0
- package/dist/worker/assets/assets/js/views/routines.js +378 -0
- package/dist/worker/assets/index.html +8 -0
- package/dist/worker/index.js +3972 -963
- package/docs/README.md +2 -0
- package/docs/architecture.md +23 -4
- package/docs/commands.md +111 -9
- package/docs/concepts.md +2 -1
- package/docs/connectors.md +157 -0
- package/docs/cost.md +1 -1
- package/docs/developing.md +3 -3
- package/docs/doctor-codes.md +8 -2
- package/docs/export.md +4 -3
- package/docs/extending.md +1 -1
- package/docs/getting-started.md +19 -2
- package/docs/hosting.md +42 -3
- package/docs/memory.md +3 -2
- package/docs/org-yaml.md +58 -5
- package/docs/portal.md +37 -6
- package/docs/prompts.md +3 -2
- package/docs/routines.md +65 -0
- package/docs/security.md +35 -4
- package/docs/session-workflow.md +31 -8
- package/docs/staff-yaml.md +7 -3
- package/docs/troubleshooting.md +1 -1
- package/docs/upgrading.md +1 -1
- package/docs/writing-a-charter.md +1 -1
- package/package.json +2 -1
- package/templates/brain/.gitattributes +3 -0
- package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +24 -15
- package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +12 -10
- package/templates/brain/CHARTER.md +2 -2
- package/templates/brain/STATE.md +16 -0
- package/templates/brain/memory/INDEX.md +1 -1
- package/templates/brain/staff.yaml +3 -0
- package/templates/ops/.gitattributes +3 -0
- package/templates/ops/.github/workflows/session.yaml +74 -13
- package/templates/ops/agents.mjs +38 -11
- package/templates/ops/compose.mjs +60 -2
- package/templates/ops/connectors.mjs +722 -0
- package/templates/ops/org/operating.md +10 -0
- package/templates/ops/org/voice.md +21 -3
- package/templates/ops/prompts/_identity.md +20 -0
- package/templates/ops/prompts/daily.md +70 -19
- package/templates/ops/prompts/mention.md +7 -2
- package/templates/ops/status-week.mjs +169 -0
- package/templates/portal/css/base.css +21 -2
- package/templates/portal/css/brain.css +20 -0
- package/templates/portal/css/connectors.css +50 -0
- package/templates/portal/css/home.css +141 -54
- package/templates/portal/css/inbox.css +11 -0
- package/templates/portal/css/layout.css +6 -0
- package/templates/portal/css/markdown.css +21 -0
- package/templates/portal/css/routines.css +40 -0
- package/templates/portal/index.html +8 -0
- package/templates/portal/js/api.js +33 -0
- package/templates/portal/js/app.js +47 -3
- package/templates/portal/js/homesort.js +28 -21
- package/templates/portal/js/icons.js +4 -0
- package/templates/portal/js/md.js +7 -2
- package/templates/portal/js/refcard.js +216 -0
- package/templates/portal/js/refresh.js +4 -2
- package/templates/portal/js/report.js +51 -0
- package/templates/portal/js/state.js +14 -1
- package/templates/portal/js/views/connectors.js +290 -0
- package/templates/portal/js/views/home.js +368 -152
- package/templates/portal/js/views/inbox.js +68 -16
- package/templates/portal/js/views/org.js +2 -0
- package/templates/portal/js/views/people.js +103 -0
- package/templates/portal/js/views/routines.js +378 -0
- package/templates/skill/SKILL.md +115 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/* What a #175 is, without leaving the page.
|
|
2
|
+
*
|
|
3
|
+
* Half of a status report is issue numbers, and the only way to find out what one was used to
|
|
4
|
+
* be a click through to GitHub, which is a new tab and the end of whatever you were reading.
|
|
5
|
+
* Hovering one now shows a card with its title, state and opening lines, the way GitHub does,
|
|
6
|
+
* and clicking it opens the thread in a side sheet over the page you were on.
|
|
7
|
+
*
|
|
8
|
+
* Only for the org's own repos: the server reads nothing else, so a chip pointing anywhere
|
|
9
|
+
* else stays a plain link. ⌘-click and middle-click still go to GitHub, as a link should.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { getRepos, getThread } from "./api.js";
|
|
13
|
+
import { ago, el, esc } from "./dom.js";
|
|
14
|
+
import { iconHTML } from "./icons.js";
|
|
15
|
+
import { openThread } from "./views/home.js";
|
|
16
|
+
import { tone } from "./views/inbox.js";
|
|
17
|
+
|
|
18
|
+
const REF_HREF = /^https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/(?:issues|pull)\/(\d+)/;
|
|
19
|
+
const SHOW_AFTER = 350;
|
|
20
|
+
const HIDE_AFTER = 200;
|
|
21
|
+
// Long enough to hover the same few numbers on a report without asking again; short enough
|
|
22
|
+
// that a card is not an hour out of date.
|
|
23
|
+
const FRESH_FOR = 5 * 60_000;
|
|
24
|
+
|
|
25
|
+
let known = null;
|
|
26
|
+
const cache = new Map();
|
|
27
|
+
let card = null;
|
|
28
|
+
let showing = null;
|
|
29
|
+
let showTimer = 0;
|
|
30
|
+
let hideTimer = 0;
|
|
31
|
+
|
|
32
|
+
export function installRefs() {
|
|
33
|
+
/* Read once, off disk. A failure leaves every chip a plain link, which is what they were. */
|
|
34
|
+
getRepos()
|
|
35
|
+
.then((r) => {
|
|
36
|
+
known = new Set((r?.repos ?? []).map((x) => x.owner + "/" + x.name));
|
|
37
|
+
})
|
|
38
|
+
.catch(() => {});
|
|
39
|
+
|
|
40
|
+
document.addEventListener?.("click", (e) => {
|
|
41
|
+
const ref = refOf(e.target);
|
|
42
|
+
if (!ref || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
hide();
|
|
45
|
+
openThread(ref);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
document.addEventListener?.("pointerover", (e) => {
|
|
49
|
+
if (e.pointerType === "touch") return;
|
|
50
|
+
if (card?.contains(e.target)) {
|
|
51
|
+
clearTimeout(hideTimer);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const a = e.target?.closest?.("a.ref");
|
|
55
|
+
const ref = refOf(e.target);
|
|
56
|
+
if (!ref) return;
|
|
57
|
+
clearTimeout(hideTimer);
|
|
58
|
+
if (showing === a) return;
|
|
59
|
+
// The card says everything the native tooltip did, and both at once is clutter.
|
|
60
|
+
a.removeAttribute("title");
|
|
61
|
+
clearTimeout(showTimer);
|
|
62
|
+
showTimer = setTimeout(() => show(a, ref), SHOW_AFTER);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
document.addEventListener?.("pointerout", (e) => {
|
|
66
|
+
const from = e.target?.closest?.("a.ref, .refcard");
|
|
67
|
+
if (!from || from.contains(e.relatedTarget)) return;
|
|
68
|
+
clearTimeout(showTimer);
|
|
69
|
+
hideTimer = setTimeout(hide, HIDE_AFTER);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
addEventListener?.("keydown", (e) => e.key === "Escape" && hide());
|
|
73
|
+
addEventListener?.("scroll", hide, true);
|
|
74
|
+
addEventListener?.("hashchange", hide);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The repo and number a chip points at, if it is one of the org's own. */
|
|
78
|
+
function refOf(target) {
|
|
79
|
+
const a = target?.closest?.("a.ref");
|
|
80
|
+
if (!a || !known) return null;
|
|
81
|
+
const m = REF_HREF.exec(a.getAttribute("href") ?? "");
|
|
82
|
+
if (!m || !known.has(m[1])) return null;
|
|
83
|
+
return { repo: m[1], number: Number(m[2]), kind: a.classList.contains("pr") ? "pr" : undefined };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function peek(ref) {
|
|
87
|
+
const key = ref.repo + "#" + ref.number;
|
|
88
|
+
const hit = cache.get(key);
|
|
89
|
+
if (hit && Date.now() - hit.at < FRESH_FOR) return hit.p;
|
|
90
|
+
const p = getThread(ref.repo, ref.number, ref.kind ?? "").then((t) => {
|
|
91
|
+
if (!t || t.error) throw new Error(t?.error ?? "could not read it");
|
|
92
|
+
return t;
|
|
93
|
+
});
|
|
94
|
+
// A failure is not kept: the next hover asks again.
|
|
95
|
+
p.catch(() => cache.delete(key));
|
|
96
|
+
cache.set(key, { at: Date.now(), p });
|
|
97
|
+
return p;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function show(a, ref) {
|
|
101
|
+
if (!a.isConnected) return;
|
|
102
|
+
showing = a;
|
|
103
|
+
ensureCard();
|
|
104
|
+
card.replaceChildren(
|
|
105
|
+
el("div", { className: "rcmeta", textContent: ref.repo + " #" + ref.number }),
|
|
106
|
+
el("div", { className: "sk sk-line" }),
|
|
107
|
+
el("div", { className: "sk sk-line" }),
|
|
108
|
+
);
|
|
109
|
+
open(a);
|
|
110
|
+
peek(ref)
|
|
111
|
+
.then((t) => {
|
|
112
|
+
if (showing === a) {
|
|
113
|
+
fill(t);
|
|
114
|
+
place(a);
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
.catch((e) => {
|
|
118
|
+
if (showing !== a) return;
|
|
119
|
+
card.replaceChildren(
|
|
120
|
+
el("div", { className: "rcmeta", textContent: ref.repo + " #" + ref.number }),
|
|
121
|
+
el("p", {
|
|
122
|
+
className: "rcbody",
|
|
123
|
+
// A bare #213 is read as this repo's, and the writer often meant another one.
|
|
124
|
+
textContent: /could not resolve|not found/i.test(e.message)
|
|
125
|
+
? "There is no #" + ref.number + " in " + ref.repo + "."
|
|
126
|
+
: "Couldn't read it: " + e.message,
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function fill(t) {
|
|
133
|
+
const merged = t.state === "MERGED";
|
|
134
|
+
const shut = t.state !== "OPEN";
|
|
135
|
+
const glyph = merged ? "merged" : t.draft ? "draft" : shut ? "issue-closed" : "issue-open";
|
|
136
|
+
const word = merged ? "Merged" : shut ? "Closed" : t.draft ? "Draft" : "Open";
|
|
137
|
+
const excerpt = plain(t.body);
|
|
138
|
+
const comments = t.commentCount ?? t.comments?.length ?? 0;
|
|
139
|
+
|
|
140
|
+
card.innerHTML =
|
|
141
|
+
'<div class="rcmeta">' +
|
|
142
|
+
'<span class="rcstate ' + (merged ? "merged" : shut ? "closed" : "open") + '">' +
|
|
143
|
+
iconHTML(glyph) + word + "</span>" +
|
|
144
|
+
"<span>" + esc(t.repo) + " " + (t.kind === "pr" ? "PR " : "") + "#" + t.number + "</span>" +
|
|
145
|
+
"</div>" +
|
|
146
|
+
'<div class="rctitle">' + esc(t.title) + "</div>" +
|
|
147
|
+
(excerpt ? '<p class="rcbody">' + esc(excerpt) + "</p>" : "") +
|
|
148
|
+
(t.labels?.length
|
|
149
|
+
? '<div class="rclabels">' +
|
|
150
|
+
t.labels.map((l) => '<span class="chip ' + tone(l) + '">' + esc(l) + "</span>").join("") +
|
|
151
|
+
"</div>"
|
|
152
|
+
: "") +
|
|
153
|
+
'<div class="rcfoot">' +
|
|
154
|
+
esc(t.author) + " · updated " + ago(t.updatedAt) +
|
|
155
|
+
(comments ? " · " + comments + (comments === 1 ? " comment" : " comments") : "") +
|
|
156
|
+
"</div>";
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The opening of a body as a sentence: no headings, tables, images or link syntax. */
|
|
160
|
+
function plain(body) {
|
|
161
|
+
const text = String(body ?? "")
|
|
162
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
163
|
+
.replace(/```[\s\S]*?```/g, " ")
|
|
164
|
+
.replace(/!\[[^\]]*\]\([^)]*\)/g, "")
|
|
165
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
|
|
166
|
+
.split("\n")
|
|
167
|
+
.map((l) => l.replace(/^\s*(#{1,6}\s+|>\s?|[-*+]\s+(\[[ x]\]\s+)?|\d+\.\s+)/i, "").trim())
|
|
168
|
+
.filter((l) => l && !/^\|/.test(l) && !/^[-|:\s]+$/.test(l))
|
|
169
|
+
.join(" ")
|
|
170
|
+
.replace(/[*_`]/g, "")
|
|
171
|
+
.replace(/\s+/g, " ")
|
|
172
|
+
.trim();
|
|
173
|
+
return text.length > 220 ? text.slice(0, 219).trimEnd() + "…" : text;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function ensureCard() {
|
|
177
|
+
if (card) return;
|
|
178
|
+
card = el("div", { className: "refcard", role: "tooltip" });
|
|
179
|
+
/* A popover goes in the top layer, so the card shows over an open side sheet too. A plain
|
|
180
|
+
fixed div would sit underneath a modal <dialog> however high its z-index. */
|
|
181
|
+
if (typeof card.showPopover === "function") card.setAttribute("popover", "manual");
|
|
182
|
+
document.body.append(card);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function open(a) {
|
|
186
|
+
// The top layer is ordered by when things were shown. Reopening puts the card above a
|
|
187
|
+
// sheet that opened after it last showed.
|
|
188
|
+
if (card.matches?.(":popover-open")) card.hidePopover();
|
|
189
|
+
if (typeof card.showPopover === "function") card.showPopover();
|
|
190
|
+
else card.hidden = false;
|
|
191
|
+
card.classList.add("on");
|
|
192
|
+
place(a);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Under the chip, or above it when there is no room below; never off the side. */
|
|
196
|
+
function place(a) {
|
|
197
|
+
const r = a.getBoundingClientRect();
|
|
198
|
+
const w = card.offsetWidth;
|
|
199
|
+
const h = card.offsetHeight;
|
|
200
|
+
const gap = 8;
|
|
201
|
+
const left = Math.max(12, Math.min(r.left, innerWidth - w - 12));
|
|
202
|
+
const below = r.bottom + gap + h <= innerHeight - 12;
|
|
203
|
+
const top = below ? r.bottom + gap : Math.max(12, r.top - gap - h);
|
|
204
|
+
card.style.left = left + "px";
|
|
205
|
+
card.style.top = top + "px";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function hide() {
|
|
209
|
+
clearTimeout(showTimer);
|
|
210
|
+
clearTimeout(hideTimer);
|
|
211
|
+
showing = null;
|
|
212
|
+
if (!card) return;
|
|
213
|
+
card.classList.remove("on");
|
|
214
|
+
if (card.matches?.(":popover-open")) card.hidePopover();
|
|
215
|
+
else if (typeof card.showPopover !== "function") card.hidden = true;
|
|
216
|
+
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { getInbox, getOrg, getSync } from "./api.js";
|
|
11
11
|
import { $, ago, el, esc } from "./dom.js";
|
|
12
12
|
import { render } from "./router.js";
|
|
13
|
-
import { sortHome } from "./homesort.js";
|
|
13
|
+
import { isFor, sortHome } from "./homesort.js";
|
|
14
14
|
import { humansOf, openCount, S, unreadCount } from "./state.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -75,7 +75,9 @@ export function stampCounts() {
|
|
|
75
75
|
/** What Home's "Needs you" holds, for the sidebar. */
|
|
76
76
|
function needsCount() {
|
|
77
77
|
if (!S.inbox || !S.data) return 0;
|
|
78
|
-
return sortHome(S.inbox.items ?? [], S.data.staff, humansOf(), S.live?.staff ?? []).needs.
|
|
78
|
+
return sortHome(S.inbox.items ?? [], S.data.staff, humansOf(), S.live?.staff ?? []).needs.filter(
|
|
79
|
+
(e) => isFor(e, S.me),
|
|
80
|
+
).length;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
export function countInBackground() {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* A staff member's report, the body of their status issue, taken apart for Home's card. */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A report, taken apart: the status line, and the Done, Working on, Needs you and Next
|
|
5
|
+
* sections the prompts ask for. A report written before that shape has none of them, and is
|
|
6
|
+
* shown as its opening lines instead.
|
|
7
|
+
*/
|
|
8
|
+
export function parseReport(body) {
|
|
9
|
+
const lines = String(body ?? "").replace(/\r/g, "").split("\n");
|
|
10
|
+
const out = { status: "", headline: "", sections: {} };
|
|
11
|
+
let at = null;
|
|
12
|
+
const intro = [];
|
|
13
|
+
for (const raw of lines) {
|
|
14
|
+
const line = raw.trim();
|
|
15
|
+
const h = /^#{2,3}\s+(.+?)\s*$/.exec(line);
|
|
16
|
+
if (h) {
|
|
17
|
+
at = sectionKey(h[1]);
|
|
18
|
+
if (at) out.sections[at] ??= [];
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (!at) {
|
|
22
|
+
if (/^_?updated\b/i.test(line)) continue;
|
|
23
|
+
const st = /^\**status:\s*(on track|needs you|stuck|blocked)\b[.!]?\**\s*[.:\u2013\u2014-]?\s*(.*)$/i.exec(line);
|
|
24
|
+
if (st && !out.status) {
|
|
25
|
+
out.status = st[1].trim().toLowerCase();
|
|
26
|
+
if (st[2]) out.headline = st[2].replace(/^\**\s*/, "").trim();
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (line) intro.push(line);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const item = /^[-*]\s+(.*)$/.exec(line) ?? /^\d+[.)]\s+(.*)$/.exec(line);
|
|
33
|
+
if (item) out.sections[at].push(item[1]);
|
|
34
|
+
else if (line && out.sections[at].length) out.sections[at][out.sections[at].length - 1] += " " + line;
|
|
35
|
+
else if (line) out.sections[at].push(line);
|
|
36
|
+
}
|
|
37
|
+
if (!out.headline && intro.length) out.headline = intro[0];
|
|
38
|
+
for (const k of Object.keys(out.sections)) {
|
|
39
|
+
out.sections[k] = out.sections[k].filter((x) => !/^nothing\.?$/i.test(x.trim()));
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function sectionKey(title) {
|
|
45
|
+
const t = title.toLowerCase();
|
|
46
|
+
if (/^(done|shipped|finished|completed)/.test(t)) return "done";
|
|
47
|
+
if (/^(working on|priorities|in progress)/.test(t)) return "working";
|
|
48
|
+
if (/^(needs you|on you|waiting on)/.test(t)) return "needs";
|
|
49
|
+
if (/^next/.test(t)) return "next";
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
@@ -22,7 +22,18 @@ export const VIEWS = [
|
|
|
22
22
|
export const VIEW_ALIAS = { memory: "brain" };
|
|
23
23
|
|
|
24
24
|
/** Screens that belong to the org rather than to one staff member. */
|
|
25
|
-
export const ORG_WIDE = new Set([
|
|
25
|
+
export const ORG_WIDE = new Set([
|
|
26
|
+
"setup",
|
|
27
|
+
"home",
|
|
28
|
+
"inbox",
|
|
29
|
+
"prs",
|
|
30
|
+
"runs",
|
|
31
|
+
"org",
|
|
32
|
+
"staff",
|
|
33
|
+
"connectors",
|
|
34
|
+
"routines",
|
|
35
|
+
"docs",
|
|
36
|
+
]);
|
|
26
37
|
|
|
27
38
|
/** The two screens that read the inbox, and so share its filters and its `?t=` thread. */
|
|
28
39
|
const INBOXY = new Set(["inbox", "prs"]);
|
|
@@ -32,6 +43,8 @@ export const S = {
|
|
|
32
43
|
data: null,
|
|
33
44
|
/** `{login}` on a hosted portal, null on your own machine. Hosted has no setup, hire or doctor. */
|
|
34
45
|
hosted: null,
|
|
46
|
+
/** The signed-in GitHub login, hosted or local. Null when it could not be read. */
|
|
47
|
+
me: null,
|
|
35
48
|
docs: null,
|
|
36
49
|
inbox: null,
|
|
37
50
|
/** /api/runs. Kept once read: it is minutes of downloads on a cold cache. */
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/* The Connectors screen: outside services the staff can use in their runs.
|
|
2
|
+
*
|
|
3
|
+
* What is connected, as cards, and what can be, as a grid. Picking one opens a sheet with how
|
|
4
|
+
* to get its key, the key, who gets it, and Save. A key is checked with the service before it is
|
|
5
|
+
* stored, goes to GitHub as a secret, and is never shown again. A service that only signs in
|
|
6
|
+
* (Notion) signs in through the hosted portal instead.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getConnectors, post } from "../api.js";
|
|
10
|
+
import { sheet } from "../dialog.js";
|
|
11
|
+
import { el } from "../dom.js";
|
|
12
|
+
import { icon } from "../icons.js";
|
|
13
|
+
import { render } from "../router.js";
|
|
14
|
+
|
|
15
|
+
/* The last answer, so a repaint after Save does not flash an empty screen. */
|
|
16
|
+
let last = null;
|
|
17
|
+
|
|
18
|
+
export function viewConnectors(m) {
|
|
19
|
+
m.append(el("h1", { textContent: "Connectors" }));
|
|
20
|
+
const notice = signInNotice();
|
|
21
|
+
if (notice) m.append(notice);
|
|
22
|
+
const body = el("div");
|
|
23
|
+
m.append(body);
|
|
24
|
+
if (last) draw(body, last);
|
|
25
|
+
else body.append(el("p", { className: "sub", textContent: "Loading…" }));
|
|
26
|
+
getConnectors()
|
|
27
|
+
.then((d) => {
|
|
28
|
+
if (d.error) throw new Error(d.error);
|
|
29
|
+
last = d;
|
|
30
|
+
body.replaceChildren();
|
|
31
|
+
draw(body, d);
|
|
32
|
+
})
|
|
33
|
+
.catch((err) => body.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) })));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A sign-in that came back with a problem says so once, from the URL it came back to. */
|
|
37
|
+
function signInNotice() {
|
|
38
|
+
const q = (location.hash.split("?")[1] ?? "");
|
|
39
|
+
const e = new URLSearchParams(q).get("e");
|
|
40
|
+
if (!e) return null;
|
|
41
|
+
history.replaceState?.(null, "", location.hash.replace(/\?.*$/, ""));
|
|
42
|
+
return el("p", { className: "err connerr", textContent: e });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function draw(body, d) {
|
|
46
|
+
const have = new Set(d.connectors.map((c) => c.catalogue ?? c.id));
|
|
47
|
+
|
|
48
|
+
if (d.connectors.length) {
|
|
49
|
+
const list = el("div", { className: "connlist" });
|
|
50
|
+
for (const c of d.connectors) list.append(row(c, d));
|
|
51
|
+
body.append(el("h2", { className: "connhead", textContent: "Connected" }), list);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const grid = el("div", { className: "conngrid" });
|
|
55
|
+
for (const e of d.catalogue) {
|
|
56
|
+
if (have.has(e.id)) continue;
|
|
57
|
+
// One Notion, whichever this portal can do: signing in where it keeps sign-ins, a key elsewhere.
|
|
58
|
+
if (e.auth === "oauth" && !d.signIn) continue;
|
|
59
|
+
if (e.id === "notion-key" && d.signIn && !have.has("notion-key")) continue;
|
|
60
|
+
const card = el("button", { className: "conncard" }, [
|
|
61
|
+
el("span", { className: "connicon" }, [icon("plug")]),
|
|
62
|
+
el("span", {}, [el("b", { textContent: shortName(e) }), el("small", { textContent: e.summary })]),
|
|
63
|
+
]);
|
|
64
|
+
card.onclick = () => open(e, null, d);
|
|
65
|
+
grid.append(card);
|
|
66
|
+
}
|
|
67
|
+
body.append(el("h2", { className: "connhead", textContent: d.connectors.length ? "Add another" : "Add a service" }), grid);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** "Notion (integration key)" is only Notion where it is the one Notion on offer. */
|
|
71
|
+
function shortName(e) {
|
|
72
|
+
return e.name.replace(/ \(.*\)$/, "");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function row(c, d) {
|
|
76
|
+
const e = d.catalogue.find((x) => x.id === (c.catalogue ?? c.id));
|
|
77
|
+
const status = c.problem
|
|
78
|
+
? el("span", { className: "chip hot", textContent: "Needs fixing" })
|
|
79
|
+
: c.auth === "oauth"
|
|
80
|
+
? c.signedIn
|
|
81
|
+
? el("span", { className: "chip ok", textContent: "Signed in" })
|
|
82
|
+
: el("span", { className: "chip warm", textContent: "Not signed in" })
|
|
83
|
+
: c.keys === "stored"
|
|
84
|
+
? el("span", { className: "chip ok", textContent: "Key stored" })
|
|
85
|
+
: c.keys === "unknown"
|
|
86
|
+
? el("span", { className: "chip", textContent: "Key not checked" })
|
|
87
|
+
: el("span", { className: "chip warm", textContent: c.keys === "partial" ? "Key on some repos" : "No key" });
|
|
88
|
+
|
|
89
|
+
const who = el("div", { className: "connwho" });
|
|
90
|
+
for (const h of c.staff) who.append(el("span", { className: "chip", textContent: h }));
|
|
91
|
+
if (c.readOnly) who.append(el("span", { className: "chip cool", textContent: "read only" }));
|
|
92
|
+
|
|
93
|
+
const edit = el("button", { className: "ghbtn", textContent: "Edit" });
|
|
94
|
+
edit.onclick = () => open(e ?? custom(c), c, d);
|
|
95
|
+
edit.disabled = !d.canWrite || !e;
|
|
96
|
+
const remove = el("button", { className: "ghbtn", textContent: "Remove" });
|
|
97
|
+
remove.disabled = !d.canWrite;
|
|
98
|
+
remove.onclick = () => confirmRemove(c, remove);
|
|
99
|
+
|
|
100
|
+
return el("div", { className: "connrow" }, [
|
|
101
|
+
el("span", { className: "connicon" }, [icon("plug")]),
|
|
102
|
+
el("div", { className: "conntext" }, [
|
|
103
|
+
el("b", { textContent: c.name }),
|
|
104
|
+
c.problem ? el("span", { className: "err", textContent: c.problem }) : who,
|
|
105
|
+
]),
|
|
106
|
+
status,
|
|
107
|
+
el("div", { className: "row connacts" }, [edit, remove]),
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A hand-written connector the catalogue does not describe: editable in org.yaml only. */
|
|
112
|
+
function custom(c) {
|
|
113
|
+
return { id: c.id, name: c.name, fields: [], steps: [], auth: c.auth };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function confirmRemove(c, btn) {
|
|
117
|
+
if (btn.dataset.sure !== "1") {
|
|
118
|
+
btn.dataset.sure = "1";
|
|
119
|
+
btn.textContent = "Remove " + c.name + "?";
|
|
120
|
+
btn.classList.add("danger");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
btn.disabled = true;
|
|
124
|
+
btn.textContent = "Removing…";
|
|
125
|
+
try {
|
|
126
|
+
await post({ id: c.id }, "/api/connectors/remove");
|
|
127
|
+
last = null;
|
|
128
|
+
render();
|
|
129
|
+
} catch (err) {
|
|
130
|
+
btn.textContent = String(err.message || err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* --------------------------------- the sheet --------------------------------- */
|
|
135
|
+
|
|
136
|
+
function open(e, c, d) {
|
|
137
|
+
let box = null;
|
|
138
|
+
const node = form(e, c, d, () => box?.close());
|
|
139
|
+
box = sheet({ node, onClose: () => {} });
|
|
140
|
+
if (!box) document.querySelector("#main")?.append(node);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function form(e, c, d, close) {
|
|
144
|
+
const out = el("div", { className: "connform" });
|
|
145
|
+
out.append(el("h2", { className: "sheettitle", textContent: (c ? "" : "Connect ") + shortName(e) }));
|
|
146
|
+
if (!c) out.append(el("p", { className: "sub", textContent: e.summary }));
|
|
147
|
+
|
|
148
|
+
const oauth = e.auth === "oauth";
|
|
149
|
+
if (!c && e.steps.length && !oauth) {
|
|
150
|
+
const ol = el("ol", { className: "connsteps" });
|
|
151
|
+
for (const s of e.steps) ol.append(el("li", { textContent: s }));
|
|
152
|
+
out.append(ol);
|
|
153
|
+
if (e.link) {
|
|
154
|
+
out.append(
|
|
155
|
+
el("a", { className: "ghbtn", href: e.link, target: "_blank", rel: "noopener", textContent: "Open " + shortName(e) }),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const fields = el("div", { className: "setupform" });
|
|
161
|
+
const inputs = {};
|
|
162
|
+
for (const f of e.fields) {
|
|
163
|
+
const input = el("input", {
|
|
164
|
+
type: f.secret ? "password" : "text",
|
|
165
|
+
autocomplete: "off",
|
|
166
|
+
spellcheck: false,
|
|
167
|
+
placeholder: f.secret && c ? "Leave empty to keep the stored key" : f.required ? "" : "Optional",
|
|
168
|
+
value: f.secret ? "" : (c?.settings?.[f.id] ?? ""),
|
|
169
|
+
});
|
|
170
|
+
inputs[f.id] = { input, f };
|
|
171
|
+
fields.append(el("label", { className: "field" }, [el("span", { textContent: f.label }), input]));
|
|
172
|
+
}
|
|
173
|
+
if (e.fields.length) out.append(fields);
|
|
174
|
+
|
|
175
|
+
const checked = el("div", { className: "conncheck" });
|
|
176
|
+
const secretInputs = Object.values(inputs).filter((x) => x.f.secret);
|
|
177
|
+
if (e.canCheck && secretInputs.length) {
|
|
178
|
+
const check = el("button", { className: "ghbtn", textContent: "Check key" });
|
|
179
|
+
check.onclick = async () => {
|
|
180
|
+
check.disabled = true;
|
|
181
|
+
check.textContent = "Checking…";
|
|
182
|
+
try {
|
|
183
|
+
const r = await post({ id: e.id, values: valuesOf(inputs) }, "/api/connectors/check");
|
|
184
|
+
checked.replaceChildren(result(r));
|
|
185
|
+
} catch (err) {
|
|
186
|
+
checked.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
|
|
187
|
+
} finally {
|
|
188
|
+
check.disabled = false;
|
|
189
|
+
check.textContent = "Check key";
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
out.append(el("div", { className: "row" }, [check]), checked);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const picked = new Set(c ? c.staff : (e.suggest ?? []).filter((h) => d.staff.some((s) => s.handle === h)));
|
|
196
|
+
if (!picked.size && d.staff.length === 1) picked.add(d.staff[0].handle);
|
|
197
|
+
const who = el("div", { className: "connstaff" });
|
|
198
|
+
for (const s of d.staff) {
|
|
199
|
+
const box = el("input", { type: "checkbox", checked: picked.has(s.handle) });
|
|
200
|
+
box.onchange = () => (box.checked ? picked.add(s.handle) : picked.delete(s.handle));
|
|
201
|
+
who.append(el("label", { className: "conntick" }, [box, el("span", { textContent: s.name })]));
|
|
202
|
+
}
|
|
203
|
+
out.append(el("h3", { className: "connsub", textContent: "Who can use it" }), who);
|
|
204
|
+
|
|
205
|
+
let ro = null;
|
|
206
|
+
if (e.readOnly) {
|
|
207
|
+
ro = el("input", { type: "checkbox", checked: Boolean(c?.readOnly) });
|
|
208
|
+
out.append(el("label", { className: "conntick" }, [ro, el("span", { textContent: "Read only" })]));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const status = el("div");
|
|
212
|
+
const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
|
|
213
|
+
cancel.onclick = close;
|
|
214
|
+
const save = el("button", { className: "ghbtn primary" });
|
|
215
|
+
|
|
216
|
+
if (oauth && !c?.signedIn) {
|
|
217
|
+
save.textContent = "Sign in to " + e.name;
|
|
218
|
+
save.disabled = !d.signIn || !d.canWrite;
|
|
219
|
+
if (!d.signIn) {
|
|
220
|
+
out.append(el("p", { className: "sub", textContent: "Signing in needs the hosted portal." }));
|
|
221
|
+
}
|
|
222
|
+
save.onclick = async () => {
|
|
223
|
+
if (!picked.size) return status.replaceChildren(el("p", { className: "err", textContent: "Pick at least one staff member." }));
|
|
224
|
+
save.disabled = true;
|
|
225
|
+
save.textContent = "Opening " + e.name + "…";
|
|
226
|
+
try {
|
|
227
|
+
const r = await post({ id: e.id, staff: [...picked], readOnly: Boolean(ro?.checked) }, "/api/connectors/signin");
|
|
228
|
+
location.href = r.url;
|
|
229
|
+
} catch (err) {
|
|
230
|
+
save.disabled = false;
|
|
231
|
+
save.textContent = "Sign in to " + e.name;
|
|
232
|
+
status.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
} else {
|
|
236
|
+
save.textContent = "Save";
|
|
237
|
+
save.disabled = !d.canWrite;
|
|
238
|
+
save.onclick = async () => {
|
|
239
|
+
if (!picked.size) return status.replaceChildren(el("p", { className: "err", textContent: "Pick at least one staff member." }));
|
|
240
|
+
save.disabled = true;
|
|
241
|
+
save.textContent = "Saving…";
|
|
242
|
+
try {
|
|
243
|
+
await post(
|
|
244
|
+
{
|
|
245
|
+
id: e.id,
|
|
246
|
+
staff: [...picked],
|
|
247
|
+
readOnly: Boolean(ro?.checked),
|
|
248
|
+
settings: settingsOf(inputs),
|
|
249
|
+
values: valuesOf(inputs, true),
|
|
250
|
+
},
|
|
251
|
+
"/api/connectors/save",
|
|
252
|
+
);
|
|
253
|
+
last = null;
|
|
254
|
+
close();
|
|
255
|
+
render();
|
|
256
|
+
} catch (err) {
|
|
257
|
+
save.disabled = false;
|
|
258
|
+
save.textContent = "Save";
|
|
259
|
+
status.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
out.append(status, el("div", { className: "row connfoot" }, [save, cancel]));
|
|
265
|
+
if (!d.canWrite) out.append(el("p", { className: "sub", textContent: "You are view-only, so you cannot change connectors." }));
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function result(r) {
|
|
270
|
+
if (r.state === "ok") return el("p", { className: "okline", textContent: "The key works." });
|
|
271
|
+
if (r.state === "limited") return el("p", { className: "okline", textContent: r.note });
|
|
272
|
+
if (r.state === "rejected") return el("p", { className: "err", textContent: r.note });
|
|
273
|
+
return el("p", { className: "sub", textContent: r.note });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Every field's value, for checking; only the keys, for storing. */
|
|
277
|
+
function valuesOf(inputs, keysOnly = false) {
|
|
278
|
+
const out = {};
|
|
279
|
+
for (const [id, { input, f }] of Object.entries(inputs)) {
|
|
280
|
+
if (keysOnly && !f.secret) continue;
|
|
281
|
+
out[id] = String(input.value ?? "").trim();
|
|
282
|
+
}
|
|
283
|
+
return out;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function settingsOf(inputs) {
|
|
287
|
+
const out = {};
|
|
288
|
+
for (const [id, { input, f }] of Object.entries(inputs)) if (!f.secret) out[id] = String(input.value ?? "").trim();
|
|
289
|
+
return out;
|
|
290
|
+
}
|