@agentsignalnet/claude-plugin 0.2.59 → 0.2.61
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/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/scripts/chat-viewer.mjs +318 -52
package/package.json
CHANGED
package/scripts/chat-viewer.mjs
CHANGED
|
@@ -566,6 +566,37 @@ const PAGE = `<!doctype html>
|
|
|
566
566
|
/* The two names, stacked. min-width:0 is what lets the ellipsis inside
|
|
567
567
|
actually happen -- a flex child defaults to min-width:auto and refuses to
|
|
568
568
|
shrink below its content, so the row overflows instead of trimming. */
|
|
569
|
+
/* A CHANNEL AND ITS CONTENTS, which is what the nesting is for. The rule
|
|
570
|
+
that matters is the left border on the body: without a line, an indent
|
|
571
|
+
alone reads as ragged alignment rather than as containment. */
|
|
572
|
+
/* The company a group of channels belongs to. Quieter than the rail title
|
|
573
|
+
above it and louder than the channel rows beneath, so it reads as a
|
|
574
|
+
heading for them rather than as another thing to click. */
|
|
575
|
+
.company + .company { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
|
|
576
|
+
.company-name {
|
|
577
|
+
font-size: 12px; font-weight: 600; color: var(--fg);
|
|
578
|
+
margin: 0 0 6px; padding: 0 2px;
|
|
579
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
580
|
+
}
|
|
581
|
+
.chan { margin-bottom: 4px; }
|
|
582
|
+
.chan-head { display: flex; align-items: center; gap: 2px; }
|
|
583
|
+
.twist {
|
|
584
|
+
flex: 0 0 auto; width: 20px; height: 24px; padding: 0; cursor: pointer;
|
|
585
|
+
border: 1px solid transparent; border-radius: 6px; background: transparent;
|
|
586
|
+
color: var(--dim); font: inherit; font-size: 11px; line-height: 1;
|
|
587
|
+
}
|
|
588
|
+
.twist:hover { background: var(--accent-soft); color: var(--fg); }
|
|
589
|
+
.twist:focus-visible { outline: none; box-shadow: var(--focus); }
|
|
590
|
+
.chan-name { flex: 1; min-width: 0; }
|
|
591
|
+
.chan-body {
|
|
592
|
+
margin-left: 9px; padding-left: 10px; border-left: 1px solid var(--line);
|
|
593
|
+
margin-top: 1px;
|
|
594
|
+
}
|
|
595
|
+
/* The channel being read, said once and quietly. Every other row in here is
|
|
596
|
+
a link too, so the marker has to be weight rather than another colour. */
|
|
597
|
+
nav a.chan-name.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
|
|
598
|
+
.chan-body .none { font-size: 12px; color: var(--dim); font-style: italic; margin: 4px 8px; }
|
|
599
|
+
|
|
569
600
|
.stack { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
|
|
570
601
|
.alias {
|
|
571
602
|
font-size: 11px; color: var(--dim); line-height: 1.3;
|
|
@@ -811,9 +842,8 @@ const PAGE = `<!doctype html>
|
|
|
811
842
|
<span class="meta" style="margin-left:auto"><span class="dot" id="dot"></span> <span id="count">0</span> messages</span>
|
|
812
843
|
</header>
|
|
813
844
|
<div id="shell">
|
|
814
|
-
<aside id="side" aria-label="
|
|
815
|
-
<
|
|
816
|
-
<p class="rail-title">In this channel</p>
|
|
845
|
+
<aside id="side" aria-label="Channels">
|
|
846
|
+
<p class="rail-title">Channels</p>
|
|
817
847
|
<nav id="who-nav"></nav>
|
|
818
848
|
<details id="setup"><summary>This machine</summary><div id="setupbody">reading…</div></details>
|
|
819
849
|
</aside>
|
|
@@ -1028,6 +1058,15 @@ const PAGE = `<!doctype html>
|
|
|
1028
1058
|
const T = new URLSearchParams(location.search).get('t') || '';
|
|
1029
1059
|
const q = (path) => path + (path.includes('?') ? '&' : '?') + 't=' + encodeURIComponent(T);
|
|
1030
1060
|
|
|
1061
|
+
/** Every channel the server can open, from the poll. */
|
|
1062
|
+
let CHANNELS = [];
|
|
1063
|
+
/** Which of them are expanded in the rail. */
|
|
1064
|
+
const OPEN = new Set();
|
|
1065
|
+
/** The rendered agent tree per channel, so reopening one costs nothing. */
|
|
1066
|
+
const BRANCHES = new Map();
|
|
1067
|
+
/** Whether the channel being read has been opened for the first time yet. */
|
|
1068
|
+
let OPENED_ONCE = false;
|
|
1069
|
+
|
|
1031
1070
|
async function post(path, payload) {
|
|
1032
1071
|
const response = await fetch(q(path), {
|
|
1033
1072
|
method: 'POST',
|
|
@@ -1042,17 +1081,24 @@ const PAGE = `<!doctype html>
|
|
|
1042
1081
|
// answers to one question on one screen.
|
|
1043
1082
|
let ROSTER = [];
|
|
1044
1083
|
|
|
1045
|
-
|
|
1084
|
+
/**
|
|
1085
|
+
* ONE CHANNEL'S ROSTER, fetched and turned into a branch of the rail.
|
|
1086
|
+
*
|
|
1087
|
+
* Takes the channel rather than reading the URL, because the rail can now
|
|
1088
|
+
* show the members of a channel you are NOT looking at -- that is what
|
|
1089
|
+
* expanding one means. The active flag says whether this is the channel whose log
|
|
1090
|
+
* is on screen, which decides two things it would be wrong to do for the
|
|
1091
|
+
* others: filling the send box, and holding ROSTER for the log to read
|
|
1092
|
+
* names out of.
|
|
1093
|
+
*/
|
|
1094
|
+
async function roster(ref, active) {
|
|
1046
1095
|
let list;
|
|
1047
1096
|
try {
|
|
1048
|
-
|
|
1049
|
-
// reason the poll carries it.
|
|
1050
|
-
const on = new URLSearchParams(location.search).get('channel');
|
|
1051
|
-
list = await (await fetch(q('/agents' + (on ? '?channel=' + encodeURIComponent(on) : '')))).json();
|
|
1097
|
+
list = await (await fetch(q('/agents' + (ref ? '?channel=' + encodeURIComponent(ref) : '')))).json();
|
|
1052
1098
|
} catch {
|
|
1053
1099
|
return;
|
|
1054
1100
|
}
|
|
1055
|
-
ROSTER = list.recipients ?? [];
|
|
1101
|
+
if (active) ROSTER = list.recipients ?? [];
|
|
1056
1102
|
// People are listed too, and a person has no chat to open -- nothing is
|
|
1057
1103
|
// sent FROM a phone. Agents only.
|
|
1058
1104
|
const everyone = list.recipients ?? [];
|
|
@@ -1061,7 +1107,10 @@ const PAGE = `<!doctype html>
|
|
|
1061
1107
|
// a person's conversation -- nothing is sent from a phone -- but notifying
|
|
1062
1108
|
// one is the most useful thing this box does.
|
|
1063
1109
|
const to = document.getElementById('to');
|
|
1064
|
-
for
|
|
1110
|
+
// Only for the channel on screen. Expanding another channel to see who is
|
|
1111
|
+
// in it must not quietly add its members to the box that sends -- picking
|
|
1112
|
+
// one would deliver into a channel the composer is not looking at.
|
|
1113
|
+
for (const r of active ? everyone : []) {
|
|
1065
1114
|
const option = document.createElement('option');
|
|
1066
1115
|
option.value = r.key;
|
|
1067
1116
|
option.textContent = (who(r) || r.key) + (r.is_agent ? '' : ' (person)');
|
|
@@ -1120,8 +1169,13 @@ const PAGE = `<!doctype html>
|
|
|
1120
1169
|
* the top and this still caught me.
|
|
1121
1170
|
*/
|
|
1122
1171
|
const alias = a.name && a.name !== a.handle ? a.name : null;
|
|
1123
|
-
|
|
1124
|
-
|
|
1172
|
+
// The channel this agent is in, carried on the link so the rail can tell
|
|
1173
|
+
// a filter (same channel, no request) from a navigation (another
|
|
1174
|
+
// channel, which has no traffic loaded to filter). The href carries it
|
|
1175
|
+
// too, because following it must land on the right conversation.
|
|
1176
|
+
const at_channel = ref ? '?channel=' + encodeURIComponent(ref) : '';
|
|
1177
|
+
return '<a href="/a/' + encodeURIComponent(at) + at_channel + '" data-agent="' + esc(at) +
|
|
1178
|
+
'" data-channel="' + esc(ref ?? '') + '" data-key="' + esc(a.key) + '" class="' + state + on +
|
|
1125
1179
|
'" title="' + esc(name) + ' — last seen ' + esc(when) + '"><i></i>' +
|
|
1126
1180
|
'<span class="stack"><span class="nm">' + esc(a.handle ?? name) + '</span>' +
|
|
1127
1181
|
(alias ? '<small class="alias">' + esc(alias) + '</small>' : '') +
|
|
@@ -1178,11 +1232,17 @@ const PAGE = `<!doctype html>
|
|
|
1178
1232
|
.join('');
|
|
1179
1233
|
};
|
|
1180
1234
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1235
|
+
/**
|
|
1236
|
+
* Keyed by the ref the SERVER resolved, not the one we asked with.
|
|
1237
|
+
*
|
|
1238
|
+
* At boot there is no channel in the URL and no channel list yet, so the
|
|
1239
|
+
* fetch goes out unqualified and the server answers about its default.
|
|
1240
|
+
* Caching that under the empty string left the rail looking up the real
|
|
1241
|
+
* ref, finding nothing, and showing "reading..." forever under a channel
|
|
1242
|
+
* whose roster had already arrived.
|
|
1243
|
+
*/
|
|
1244
|
+
BRANCHES.set(list.channel?.ref ?? ref ?? '', branch(null, 0));
|
|
1245
|
+
drawRail();
|
|
1186
1246
|
}
|
|
1187
1247
|
|
|
1188
1248
|
/**
|
|
@@ -1199,25 +1259,147 @@ const PAGE = `<!doctype html>
|
|
|
1199
1259
|
* carried through, because dropping it is what made the agent links
|
|
1200
1260
|
* answer "Not found" before they stopped being links at all.
|
|
1201
1261
|
*/
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1262
|
+
/**
|
|
1263
|
+
* ONE TREE: every channel, each opening to show who is in it.
|
|
1264
|
+
*
|
|
1265
|
+
* It was two lists -- the channels, then "in this channel" -- which said the
|
|
1266
|
+
* same relationship twice and made the members look like a separate thing
|
|
1267
|
+
* rather than the contents of the row above them. Nesting is the honest
|
|
1268
|
+
* shape: an agent belongs to exactly one channel, and the rail should say so
|
|
1269
|
+
* by where it puts it.
|
|
1270
|
+
*
|
|
1271
|
+
* A channel you are not looking at can be opened. That costs one roster
|
|
1272
|
+
* fetch, once, and answers "who is in the other one" without leaving the
|
|
1273
|
+
* conversation you are reading.
|
|
1274
|
+
*/
|
|
1275
|
+
function drawRail() {
|
|
1276
|
+
const nav = document.getElementById('who-nav');
|
|
1277
|
+
if (!nav) return;
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* SECTIONED BY COMPANY, because a channel name means little on its own.
|
|
1281
|
+
*
|
|
1282
|
+
* "Default" is the name almost every account's first channel has, so two
|
|
1283
|
+
* companies produce two rows called the same thing and the rail becomes a
|
|
1284
|
+
* list you have to decode. Grouped under whose they are, the same two rows
|
|
1285
|
+
* read at a glance.
|
|
1286
|
+
*
|
|
1287
|
+
* Grouped on the account ID and LABELLED with the name: two companies may
|
|
1288
|
+
* choose the same name, and one renamed mid-session must not split into
|
|
1289
|
+
* two sections. A channel whose account is not known yet -- the key
|
|
1290
|
+
* context is cached for a minute, so this happens right after the column
|
|
1291
|
+
* was added -- groups under its own ref rather than being hidden.
|
|
1292
|
+
*
|
|
1293
|
+
* The heading is dropped when everything belongs to one company. A section
|
|
1294
|
+
* label that is the same for every row underneath it is furniture.
|
|
1295
|
+
*/
|
|
1296
|
+
const groups = [];
|
|
1297
|
+
for (const c of CHANNELS) {
|
|
1298
|
+
/**
|
|
1299
|
+
* UNKNOWN ACCOUNTS SHARE ONE BUCKET, they do not each get their own.
|
|
1300
|
+
*
|
|
1301
|
+
* The account arrives from the API, and an older one does not send it at
|
|
1302
|
+
* all -- as does a key whose context was cached before the field
|
|
1303
|
+
* existed. Keying those on the channel instead would give every channel
|
|
1304
|
+
* a section of its own, each headed "Unnamed company", which is the flat
|
|
1305
|
+
* list back again with a wrong label on every row.
|
|
1306
|
+
*/
|
|
1307
|
+
const at = c.account ?? '';
|
|
1308
|
+
let group = groups.find((g) => g.at === at);
|
|
1309
|
+
if (!group) {
|
|
1310
|
+
group = { at, company: c.company ?? null, channels: [] };
|
|
1311
|
+
groups.push(group);
|
|
1312
|
+
}
|
|
1313
|
+
// The first non-null name wins, so one channel answering before another
|
|
1314
|
+
// does not leave the section unlabelled.
|
|
1315
|
+
group.company = group.company ?? c.company ?? null;
|
|
1316
|
+
group.channels.push(c);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// Headings only when they distinguish something. One company, or a server
|
|
1320
|
+
// that does not say, and the rail stays the plain list it was.
|
|
1321
|
+
const sectioned = groups.length > 1 && groups.every((g) => g.at);
|
|
1322
|
+
|
|
1323
|
+
const rows = (list) => list.map((c) => {
|
|
1324
|
+
const ref = c.ref ?? '';
|
|
1325
|
+
const open = OPEN.has(ref);
|
|
1326
|
+
const branch = BRANCHES.get(ref);
|
|
1327
|
+
const href = c.ref ? q('/?channel=' + encodeURIComponent(c.ref)) : q('/');
|
|
1328
|
+
|
|
1329
|
+
const head =
|
|
1330
|
+
'<div class="chan-head">' +
|
|
1331
|
+
'<button type="button" class="twist" data-open="' + ref + '" ' +
|
|
1332
|
+
'aria-expanded="' + (open ? 'true' : 'false') + '" ' +
|
|
1333
|
+
'aria-label="' + (open ? 'Collapse ' : 'Expand ') + esc(c.name || ref) + '">' +
|
|
1334
|
+
(open ? '▾' : '▸') + '</button>' +
|
|
1335
|
+
'<a class="chan-name' + (c.active ? ' on' : '') + '" href="' + esc(href) + '" data-channel="' + ref + '">' +
|
|
1336
|
+
'<span class="stack"><span class="nm">' + esc(c.name || ref || 'channel') + '</span>' +
|
|
1337
|
+
(ref ? '<small class="alias">' + esc(ref) + '</small>' : '') +
|
|
1338
|
+
'</span></a></div>';
|
|
1339
|
+
|
|
1340
|
+
if (!open) return '<div class="chan">' + head + '</div>';
|
|
1341
|
+
|
|
1342
|
+
// "everything" clears the agent filter, and only means anything in the
|
|
1343
|
+
// channel being read -- in any other it is the link that switches to it.
|
|
1344
|
+
const all =
|
|
1345
|
+
'<a href="' + esc(href) + '" data-agent="" data-key="" data-channel="' + ref + '" ' +
|
|
1346
|
+
'class="whole' + (c.active && !AGENT ? ' on' : '') + '">' +
|
|
1347
|
+
'<span class="nm">everything here</span></a>';
|
|
1348
|
+
|
|
1349
|
+
const body = branch === undefined ? '<p class="none">reading…</p>' : all + branch;
|
|
1350
|
+
return '<div class="chan">' + head + '<div class="chan-body">' + body + '</div></div>';
|
|
1351
|
+
}).join('');
|
|
1352
|
+
|
|
1353
|
+
nav.innerHTML = groups
|
|
1354
|
+
.map((g) =>
|
|
1355
|
+
sectioned
|
|
1356
|
+
? '<div class="company"><p class="company-name">' +
|
|
1357
|
+
esc(g.company || 'Unnamed company') +
|
|
1358
|
+
'</p>' + rows(g.channels) + '</div>'
|
|
1359
|
+
: rows(g.channels),
|
|
1360
|
+
)
|
|
1361
|
+
.join('');
|
|
1362
|
+
|
|
1363
|
+
markNav();
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Open a channel, fetching its roster the first time.
|
|
1368
|
+
*
|
|
1369
|
+
* Drawn twice on purpose: once immediately so the twisty turns and a
|
|
1370
|
+
* "reading…" line appears, and again when the roster lands. Waiting for the
|
|
1371
|
+
* network before showing anything makes a click feel like it missed.
|
|
1372
|
+
*/
|
|
1373
|
+
async function openChannel(ref) {
|
|
1374
|
+
if (OPEN.has(ref)) {
|
|
1375
|
+
OPEN.delete(ref);
|
|
1376
|
+
drawRail();
|
|
1207
1377
|
return;
|
|
1208
1378
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1379
|
+
OPEN.add(ref);
|
|
1380
|
+
drawRail();
|
|
1381
|
+
if (!BRANCHES.has(ref)) {
|
|
1382
|
+
await roster(ref, ref === activeRef());
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/** The channel whose log is on screen. */
|
|
1387
|
+
function activeRef() {
|
|
1388
|
+
return new URLSearchParams(location.search).get('channel') ?? (CHANNELS[0]?.ref ?? '');
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
/** Keep the rail in step with what the poll says exists. */
|
|
1392
|
+
function renderChannels(list) {
|
|
1393
|
+
if (!list) return;
|
|
1394
|
+
CHANNELS = list;
|
|
1395
|
+
const active = list.find((c) => c.active);
|
|
1396
|
+
// The channel being read starts open, because its members are the ones
|
|
1397
|
+
// the log is about. The rest stay shut until asked for.
|
|
1398
|
+
if (active && !OPENED_ONCE) {
|
|
1399
|
+
OPEN.add(active.ref ?? '');
|
|
1400
|
+
OPENED_ONCE = true;
|
|
1401
|
+
}
|
|
1402
|
+
drawRail();
|
|
1221
1403
|
}
|
|
1222
1404
|
|
|
1223
1405
|
/** Whether a nav link is the one currently filtering. Key or handle, either may be in the URL. */
|
|
@@ -1228,10 +1410,26 @@ const PAGE = `<!doctype html>
|
|
|
1228
1410
|
return AGENT === at || ( AGENT !== '' && AGENT === key );
|
|
1229
1411
|
}
|
|
1230
1412
|
|
|
1413
|
+
/**
|
|
1414
|
+
* Whether a rail link is an agent filter at all.
|
|
1415
|
+
*
|
|
1416
|
+
* A channel row has no data-agent, and reading a missing one as the empty
|
|
1417
|
+
* string made every channel match the unfiltered view -- so both channels
|
|
1418
|
+
* lit up as selected at once, which is the one thing the highlight exists
|
|
1419
|
+
* to prevent.
|
|
1420
|
+
*/
|
|
1421
|
+
function isFilter(link) {
|
|
1422
|
+
return link.dataset.agent !== undefined;
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1231
1425
|
/** Move the highlight without re-rendering the roster, which would refetch /agents. */
|
|
1232
1426
|
function markNav() {
|
|
1233
1427
|
for (const link of document.querySelectorAll('#who-nav a')) {
|
|
1234
|
-
|
|
1428
|
+
if (!isFilter(link)) continue;
|
|
1429
|
+
// Only within the channel being read: an agent link in a channel you are
|
|
1430
|
+
// peeking into is a way to go there, not the current selection.
|
|
1431
|
+
const here = (link.dataset.channel ?? '') === activeRef();
|
|
1432
|
+
link.classList.toggle('on', here && matchesNav(link));
|
|
1235
1433
|
}
|
|
1236
1434
|
}
|
|
1237
1435
|
|
|
@@ -1345,6 +1543,12 @@ const PAGE = `<!doctype html>
|
|
|
1345
1543
|
document.getElementById('dot').style.background = '#3fb950';
|
|
1346
1544
|
SELF = data.self ?? SELF;
|
|
1347
1545
|
|
|
1546
|
+
// BEFORE the error check, for the same reason the server sends it anyway:
|
|
1547
|
+
// the channel you cannot read is the one where you most need the list of
|
|
1548
|
+
// the others. Returning first left the page knowing about two channels and
|
|
1549
|
+
// showing neither.
|
|
1550
|
+
renderChannels(data.channels);
|
|
1551
|
+
|
|
1348
1552
|
if (data.error) {
|
|
1349
1553
|
document.getElementById('log').className = 'empty';
|
|
1350
1554
|
document.getElementById('log').textContent = data.error;
|
|
@@ -1353,7 +1557,6 @@ const PAGE = `<!doctype html>
|
|
|
1353
1557
|
|
|
1354
1558
|
document.getElementById('channel').textContent =
|
|
1355
1559
|
data.channel ? data.channel.name + ' · ' + data.channel.ref : '';
|
|
1356
|
-
renderChannels(data.channels);
|
|
1357
1560
|
document.getElementById('count').textContent = data.messages.length;
|
|
1358
1561
|
|
|
1359
1562
|
const log = document.getElementById('log');
|
|
@@ -2055,10 +2258,30 @@ const PAGE = `<!doctype html>
|
|
|
2055
2258
|
// nothing a new tab could show that this does not. Somebody who wants one can copy the
|
|
2056
2259
|
// address bar, which has the token.
|
|
2057
2260
|
document.getElementById('who-nav').addEventListener('click', (event) => {
|
|
2058
|
-
|
|
2261
|
+
// The twisty opens and closes without going anywhere. Checked first
|
|
2262
|
+
// because it sits inside the same row as the link beside it.
|
|
2263
|
+
const twist = event.target.closest('.twist');
|
|
2264
|
+
if (twist) {
|
|
2265
|
+
event.preventDefault();
|
|
2266
|
+
openChannel(twist.dataset.open ?? '');
|
|
2267
|
+
return;
|
|
2268
|
+
}
|
|
2059
2269
|
|
|
2270
|
+
const link = event.target.closest('a');
|
|
2060
2271
|
if (!link) return;
|
|
2061
2272
|
|
|
2273
|
+
/**
|
|
2274
|
+
* AN AGENT IN ANOTHER CHANNEL IS A NAVIGATION, not a filter.
|
|
2275
|
+
*
|
|
2276
|
+
* Filtering in place is right within the channel on screen -- no request,
|
|
2277
|
+
* nothing to drop. It is wrong for a channel you are only peeking into:
|
|
2278
|
+
* there is no traffic loaded to filter, so the log would empty and look
|
|
2279
|
+
* broken. Let the browser follow the link instead; the page comes back on
|
|
2280
|
+
* that channel with that agent selected.
|
|
2281
|
+
*/
|
|
2282
|
+
const belongsTo = link.dataset.channel ?? '';
|
|
2283
|
+
if (belongsTo !== activeRef()) return;
|
|
2284
|
+
|
|
2062
2285
|
event.preventDefault();
|
|
2063
2286
|
filterTo(link.dataset.agent ?? '', true);
|
|
2064
2287
|
});
|
|
@@ -2067,7 +2290,7 @@ const PAGE = `<!doctype html>
|
|
|
2067
2290
|
// the navigations they replaced. No push: this IS the pop.
|
|
2068
2291
|
addEventListener('popstate', () => filterTo(agentFromPath(location.pathname), false));
|
|
2069
2292
|
|
|
2070
|
-
roster();
|
|
2293
|
+
roster(activeRef(), true);
|
|
2071
2294
|
setup();
|
|
2072
2295
|
pending();
|
|
2073
2296
|
setInterval(pending, 2000);
|
|
@@ -2974,6 +3197,12 @@ const server = createServer(async (req, res) => {
|
|
|
2974
3197
|
on.ref = body.channel.ref;
|
|
2975
3198
|
on.name = body.channel.name ?? on.name;
|
|
2976
3199
|
}
|
|
3200
|
+
// Whose channel it is, for the rail's sections. Kept on the channel
|
|
3201
|
+
// rather than looked up again: one poll already answered it.
|
|
3202
|
+
if (body.account?.id) {
|
|
3203
|
+
on.account = body.account.id;
|
|
3204
|
+
on.company = body.account.name ?? on.company;
|
|
3205
|
+
}
|
|
2977
3206
|
channelRef = on.ref ?? channelRef;
|
|
2978
3207
|
|
|
2979
3208
|
const fresh = (body.messages ?? []).map(keepable).filter(Boolean);
|
|
@@ -2985,17 +3214,37 @@ const server = createServer(async (req, res) => {
|
|
|
2985
3214
|
body.messages = writeHistory(on.ref ?? channelRef, [...byId.values()], settings().history_days);
|
|
2986
3215
|
// Every channel this viewer can open, so the page can offer them. The
|
|
2987
3216
|
// key never leaves this process -- only the ref and the name.
|
|
2988
|
-
|
|
2989
|
-
ref: c.ref,
|
|
2990
|
-
name: c.name ?? c.via,
|
|
2991
|
-
via: c.via,
|
|
2992
|
-
active: c === on,
|
|
2993
|
-
}));
|
|
3217
|
+
|
|
2994
3218
|
// What this call actually cost, so the page can say so rather than
|
|
2995
3219
|
// implying every refresh is free or that every refresh is billed.
|
|
2996
3220
|
body.fetched = fresh.length;
|
|
2997
3221
|
}
|
|
2998
3222
|
|
|
3223
|
+
/**
|
|
3224
|
+
* THE RAIL IS SENT EVEN WHEN THE READ FAILED.
|
|
3225
|
+
*
|
|
3226
|
+
* This used to live inside the success branch, so any channel whose poll
|
|
3227
|
+
* errored took the whole rail down with it -- no channels, no agents,
|
|
3228
|
+
* nothing to click. Which is precisely backwards: a channel you cannot
|
|
3229
|
+
* read is the moment you most need the list, because the other one in it
|
|
3230
|
+
* probably works and switching is the fix.
|
|
3231
|
+
*
|
|
3232
|
+
* Found by pointing the viewer at two accounts with no credit. Reading a
|
|
3233
|
+
* log costs a delivery, both polls came back 402, and a page that knew
|
|
3234
|
+
* about two channels rendered neither.
|
|
3235
|
+
*
|
|
3236
|
+
* The key never leaves this process -- only the ref, the name and whose
|
|
3237
|
+
* it is.
|
|
3238
|
+
*/
|
|
3239
|
+
body.channels = channels.map((c) => ({
|
|
3240
|
+
ref: c.ref,
|
|
3241
|
+
name: c.name ?? c.via,
|
|
3242
|
+
via: c.via,
|
|
3243
|
+
account: c.account ?? null,
|
|
3244
|
+
company: c.company ?? null,
|
|
3245
|
+
active: c === on,
|
|
3246
|
+
}));
|
|
3247
|
+
|
|
2999
3248
|
const agent = url.searchParams.get('agent');
|
|
3000
3249
|
|
|
3001
3250
|
// Filtered here rather than in the page, so the browser never holds
|
|
@@ -3081,19 +3330,36 @@ resolveSelf();
|
|
|
3081
3330
|
* is better than being quietly shown one channel and told nothing.
|
|
3082
3331
|
*/
|
|
3083
3332
|
async function nameChannels() {
|
|
3084
|
-
const now = new Date().toISOString();
|
|
3085
3333
|
await Promise.all(
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3334
|
+
/**
|
|
3335
|
+
* ALL OF THEM, including the one the page opens on.
|
|
3336
|
+
*
|
|
3337
|
+
* It used to skip the first, because its own poll named it and asking
|
|
3338
|
+
* twice cost a delivery. That reasoning went with the endpoint: the
|
|
3339
|
+
* directory is free, and the poll does NOT always answer -- an account
|
|
3340
|
+
* with no credit gets a 402 for its log, so the channel it is looking at
|
|
3341
|
+
* stayed labelled by whichever key opened it while every other channel
|
|
3342
|
+
* was named properly.
|
|
3343
|
+
*/
|
|
3344
|
+
channels.map(async (c) => {
|
|
3345
|
+
if (c.name && c.account) return;
|
|
3346
|
+
/**
|
|
3347
|
+
* THE DIRECTORY, not the log.
|
|
3348
|
+
*
|
|
3349
|
+
* Reading messages costs a delivery. Naming the rail should not, and for
|
|
3350
|
+
* an account holding no credit it could not: the call 402s and the
|
|
3351
|
+
* channel stays labelled by whichever server's key opened it. The
|
|
3352
|
+
* directory answers the same two questions for nothing.
|
|
3353
|
+
*/
|
|
3354
|
+
const body = await upstream('/v1/recipients', c.key);
|
|
3093
3355
|
if (body?.channel?.name) {
|
|
3094
3356
|
c.name = body.channel.name;
|
|
3095
3357
|
c.ref = body.channel.ref ?? c.ref;
|
|
3096
3358
|
}
|
|
3359
|
+
if (body?.account?.id) {
|
|
3360
|
+
c.account = body.account.id;
|
|
3361
|
+
c.company = body.account.name ?? null;
|
|
3362
|
+
}
|
|
3097
3363
|
}),
|
|
3098
3364
|
);
|
|
3099
3365
|
}
|