@volter/teams 0.1.63 → 0.1.65
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/package.json +1 -1
- package/session-follow.mjs +48 -16
- package/viewer/session-view.css +12 -1
- package/viewer/session-view.mjs +35 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/teams",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.65",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
|
|
6
6
|
"license": "MIT",
|
package/session-follow.mjs
CHANGED
|
@@ -15,29 +15,41 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export function followTeamSession({ origin, teamId, sessionId, token, tail = 300, onSnapshot, onLive = () => {}, onError = () => {}, onDeleted = () => {}, fetchImpl = globalThis.fetch, retryMs = 2000 }) {
|
|
17
17
|
const base = `${origin}/api/v1/teams/${encodeURIComponent(teamId)}/sessions/${encodeURIComponent(sessionId)}`;
|
|
18
|
-
const decoder = new TextDecoder();
|
|
19
18
|
const controller = new AbortController();
|
|
20
19
|
const headers = async () => ({ Authorization: `Bearer ${await token()}` });
|
|
21
20
|
const failure = (stage, status, message) => Object.assign(new Error(message), { stage, status });
|
|
22
|
-
let reading = null;
|
|
23
|
-
const read = () =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
let reading = null, requested = false;
|
|
22
|
+
const read = () => {
|
|
23
|
+
requested = true;
|
|
24
|
+
return reading ??= (async () => {
|
|
25
|
+
let snapshot;
|
|
26
|
+
do {
|
|
27
|
+
requested = false;
|
|
28
|
+
const response = await fetchImpl(`${base}/messages?tail=${tail}`, { headers: await headers(), signal: AbortSignal.any([controller.signal, AbortSignal.timeout(15000)]) });
|
|
29
|
+
if (!response.ok) throw failure('read', response.status, `reading the session failed (${response.status})`);
|
|
30
|
+
const body = await response.json();
|
|
31
|
+
if (controller.signal.aborted) throw new DOMException('Session follow stopped', 'AbortError');
|
|
32
|
+
snapshot = body.data ?? body;
|
|
33
|
+
onSnapshot(snapshot);
|
|
34
|
+
// A change during the HTTP read may be newer than the capture it
|
|
35
|
+
// returned. Coalesce the callers, but do not drop that invalidation.
|
|
36
|
+
} while (requested);
|
|
37
|
+
return snapshot;
|
|
38
|
+
})().finally(() => { reading = null; });
|
|
39
|
+
};
|
|
32
40
|
(async () => {
|
|
33
|
-
let cursor = null;
|
|
41
|
+
let cursor = null, following = null, watched = null;
|
|
34
42
|
while (!controller.signal.aborted) {
|
|
43
|
+
const connection = new AbortController();
|
|
44
|
+
following = connection;
|
|
45
|
+
let reader;
|
|
35
46
|
try {
|
|
36
47
|
if (!cursor) cursor = String((await read()).event_cursor ?? '') || null;
|
|
37
|
-
const response = await fetchImpl(`${base}/events?${cursor ? `after=${encodeURIComponent(cursor)}` : 'tail=1'}`, { headers: await headers(), signal: controller.signal });
|
|
48
|
+
const response = await fetchImpl(`${base}/events?${cursor ? `after=${encodeURIComponent(cursor)}` : 'tail=1'}`, { headers: await headers(), signal: AbortSignal.any([controller.signal, connection.signal]) });
|
|
38
49
|
if (!response.ok) throw failure('follow', response.status, `following the session failed (${response.status})`);
|
|
39
50
|
onLive(true);
|
|
40
|
-
|
|
51
|
+
reader = response.body.getReader();
|
|
52
|
+
const decoder = new TextDecoder();
|
|
41
53
|
let buffer = '';
|
|
42
54
|
for (;;) {
|
|
43
55
|
const { value, done } = await reader.read();
|
|
@@ -54,13 +66,33 @@ export function followTeamSession({ origin, teamId, sessionId, token, tail = 300
|
|
|
54
66
|
// The server ends a stream it can no longer resume (a slow reader, a retired cursor): start from a snapshot.
|
|
55
67
|
if (event.terminal && event.type === 'resync_required') cursor = null;
|
|
56
68
|
if (event.type === 'snapshot') onSnapshot(event.data);
|
|
57
|
-
else if (event.type === 'session_changed')
|
|
69
|
+
else if (event.type === 'session_changed') {
|
|
70
|
+
const refresh = read();
|
|
71
|
+
// One recovery handler per coalesced read, including when a
|
|
72
|
+
// token-expiry reconnect overtakes the unfinished HTTP read.
|
|
73
|
+
if (watched !== refresh) {
|
|
74
|
+
watched = refresh;
|
|
75
|
+
void refresh.then(() => { if (watched === refresh) watched = null; }, (error) => {
|
|
76
|
+
if (watched === refresh) watched = null;
|
|
77
|
+
if (controller.signal.aborted) return;
|
|
78
|
+
// Its event cursor advanced, but its snapshot was not read.
|
|
79
|
+
// Recover even if no further message arrives.
|
|
80
|
+
cursor = null;
|
|
81
|
+
following?.abort();
|
|
82
|
+
onError({ stage: error.stage ?? 'read', status: error.status ?? null, message: error.message, snapshot: true });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
58
86
|
else if (event.type === 'session_deleted') { onLive(false); onDeleted(); return; }
|
|
59
87
|
}
|
|
60
88
|
}
|
|
61
89
|
} catch (error) {
|
|
62
90
|
if (controller.signal.aborted) return;
|
|
63
|
-
onError({ stage: error.stage ?? 'follow', status: error.status ?? null, message: error.message, snapshot: Boolean(cursor) });
|
|
91
|
+
if (!connection.signal.aborted) onError({ stage: error.stage ?? 'follow', status: error.status ?? null, message: error.message, snapshot: Boolean(cursor) });
|
|
92
|
+
} finally {
|
|
93
|
+
if (following === connection) following = null;
|
|
94
|
+
connection.abort();
|
|
95
|
+
await reader?.cancel().catch(() => {});
|
|
64
96
|
}
|
|
65
97
|
onLive(false);
|
|
66
98
|
await new Promise((resolve) => setTimeout(resolve, retryMs));
|
package/viewer/session-view.css
CHANGED
|
@@ -383,6 +383,8 @@
|
|
|
383
383
|
.scui-message { position:relative; display:var(--scui-message-display, block); grid-template-columns:var(--scui-message-columns, none); column-gap:var(--scui-message-column-gap, 0); align-items:start; min-width:0; max-width:100%; overflow-wrap:anywhere }
|
|
384
384
|
/* A timeline column of time and speaker; a look sets --scui-message-display: grid and columns to show it. */
|
|
385
385
|
.scui-message-actor { display:var(--scui-message-actor-display, none); grid-row:1 / span 9; grid-template-columns:var(--scui-message-actor-columns, auto auto); gap:calc(10px * var(--scui-scaling)); align-items:baseline; color:var(--scui-muted); font:var(--scui-text-xs) var(--scui-font-mono) }
|
|
386
|
+
.scui-message-actor-anonymous { width:18px; height:18px; flex:none; background:currentColor; mask:url("https://brand.volter.ai/icon/user-round/svg?size=18") center / contain no-repeat }
|
|
387
|
+
.scui-message-actor-source { padding:0 var(--scui-space-1, 4px); border:1px solid var(--scui-border); border-radius:var(--scui-radius-sm); color:var(--scui-muted); font:inherit }
|
|
386
388
|
.scui-message-actor-time { white-space:nowrap }
|
|
387
389
|
.scui-message-actor-name { display:inline-flex; align-items:center; gap:calc(8px * var(--scui-scaling)); color:var(--scui-fg); white-space:nowrap }
|
|
388
390
|
/* A host's picture carries its own shape (a brand face is round, an agent's mark a rounded square): never cropped. */
|
|
@@ -456,6 +458,15 @@
|
|
|
456
458
|
.scui-activity { min-width:0; margin-left:var(--scui-entry-inset, 0); color:var(--scui-muted) }
|
|
457
459
|
/* Entries that are not messages line up under a timeline's content column. */
|
|
458
460
|
.scui-reasoning { margin-left:var(--scui-entry-inset, 0) }
|
|
461
|
+
.scui-mail { margin-left:var(--scui-entry-inset, 0); color:var(--scui-muted); font-size:var(--scui-text-sm); border:1px solid var(--scui-border); border-radius:var(--scui-radius-sm); min-width:0 }
|
|
462
|
+
.scui-mail-summary { cursor:pointer; padding:var(--scui-space-2, 8px); overflow-wrap:anywhere }
|
|
463
|
+
.scui-mail-heading { display:inline-flex; vertical-align:middle; align-items:center; gap:var(--volter-space-2, 8px); width:calc(100% - 24px); min-width:0 }
|
|
464
|
+
.scui-mail-avatar { width:24px; height:24px; flex:none; border-radius:var(--scui-radius-sm) }
|
|
465
|
+
.scui-mail-name { color:var(--scui-fg); font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:35% }
|
|
466
|
+
.scui-mail-kind { overflow:hidden; text-overflow:ellipsis; white-space:nowrap }
|
|
467
|
+
.scui-mail-time { margin-left:auto; white-space:nowrap; flex:none; font-variant-numeric:tabular-nums }
|
|
468
|
+
.scui-mail-subject { display:block; margin-left:var(--volter-space-6, 24px); margin-top:var(--volter-space-1, 4px); color:var(--scui-fg); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:500 }
|
|
469
|
+
.scui-mail-body { padding:var(--scui-space-2, 8px); border-top:1px solid var(--scui-border); color:var(--scui-fg) }
|
|
459
470
|
.scui-plan { margin-left:var(--scui-entry-inset, 0) }
|
|
460
471
|
.scui-activity-head,.scui-tool-head { display:flex; align-items:center; gap:calc(6px * var(--scui-scaling)); box-sizing:border-box; width:100%; min-height:calc(27px * var(--scui-scaling)); padding:0 calc(3px * var(--scui-scaling)); border:0; background:transparent; color:inherit; text-align:left }
|
|
461
472
|
.scui-activity-head { cursor:pointer }
|
|
@@ -889,5 +900,5 @@
|
|
|
889
900
|
.scui-team-mode { display:flex; flex:none; gap:calc(4px * var(--scui-scaling)) }
|
|
890
901
|
.scui-team-mode-option { font-size:var(--scui-text-sm) }
|
|
891
902
|
.scui-team-mode-option[aria-pressed="true"] { border-color:var(--scui-border-strong); background:var(--scui-fill); color:var(--scui-fg) }
|
|
892
|
-
.scui-team-terminal-body { display:flex; flex:1; min-height:0; flex-direction:column; padding:var(--scui-team-terminal-padding, calc(6px * var(--scui-scaling)) calc(8px * var(--scui-scaling)) calc(8px * var(--scui-scaling))); border:var(--scui-team-terminal-border, 0); border-radius:var(--scui-team-terminal-radius, 0); background:var(--scui-team-terminal-bg, var(--scui-terminal-bg, var(--volter-
|
|
903
|
+
.scui-team-terminal-body { display:flex; flex:1; min-height:0; flex-direction:column; padding:var(--scui-team-terminal-padding, calc(6px * var(--scui-scaling)) calc(8px * var(--scui-scaling)) calc(8px * var(--scui-scaling))); border:var(--scui-team-terminal-border, 0); border-radius:var(--scui-team-terminal-radius, 0); background:var(--scui-team-terminal-bg, var(--scui-terminal-bg, var(--volter-terminal-background, light-dark(#ffffff, #1e1e1e)))); color:var(--scui-team-terminal-fg, var(--scui-terminal-fg, var(--volter-terminal-foreground, light-dark(#000000, #ffffff)))); color-scheme:light dark }
|
|
893
904
|
}
|