@vibelord/lanes 1.7.3 → 1.7.5
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 +9 -0
- package/package.json +1 -1
- package/payload/lanes/VERSION +1 -1
- package/payload/lanes/bin/lanes +128 -24
- package/payload/lanes/bin/lanes-site-serve +15 -0
- package/payload/lanes/bin-rs/BINARIES.json +5 -0
- package/payload/lanes/container/lane-mcp +108 -5
- package/payload/lanes/container/lane_core.py +116 -0
- package/payload/lanes/container/throttle-pulse +159 -14
- package/payload/lanes/docs/ARCHITECTURE.md +132 -13
- package/payload/lanes/docs/DESIGN.md +10 -8
- package/payload/lanes/docs/INSTALL.md +1 -1
- package/payload/lanes/docs/RUNBOOK.md +436 -8
- package/payload/lanes/docs/USERGUIDE.md +82 -9
- package/payload/lanes/install/host-install.sh +35 -4
- package/payload/lanes/libexec/adopt.py +364 -0
- package/payload/lanes/libexec/attach.py +35 -5
- package/payload/lanes/libexec/cutover.py +656 -0
- package/payload/lanes/libexec/docsd.py +12 -8
- package/payload/lanes/libexec/doctor_lanes2.py +284 -0
- package/payload/lanes/libexec/economy_poll.py +87 -2
- package/payload/lanes/libexec/gc_unregistered.py +407 -0
- package/payload/lanes/libexec/lanes_lib.py +474 -2
- package/payload/lanes/libexec/native.sh +38 -0
- package/payload/lanes/libexec/native_bin.py +670 -0
- package/payload/lanes/libexec/session_actions.py +85 -7
- package/payload/lanes/libexec/shadow.py +1311 -0
- package/payload/lanes/libexec/sidebar.py +252 -30
- package/payload/lanes/libexec/sidebar_status.py +373 -25
- package/payload/lanes/libexec/statusd.py +67 -3
- package/payload/lanes/libexec/tokens.py +99 -131
- package/payload/lanes/libexec/tokens.sh +1 -1
- package/payload/lanes/libexec/update.py +78 -8
- package/payload/lanes/libexec/users.py +282 -0
- package/payload/lanes/site/README.md +9 -0
- package/payload/lanes/site/conformance.py +280 -0
- package/payload/lanes/site/protocol.py +368 -0
- package/payload/lanes/site/server.py +314 -0
- package/payload/lanes/systemd/lanes-gc.service +1 -1
- package/payload/lanes/systemd/lanes-gc.timer +14 -3
- package/payload/lanes/tokens/README.md +156 -0
- package/payload/lanes/tokens/generate.py +930 -0
- package/payload/lanes/tokens/generated/parity.v1.tsv +489 -0
- package/payload/lanes/tokens/generated/tokens.resolved.json +835 -0
- package/payload/lanes/tokens/tokens.v1.json +763 -0
- package/payload/lanes/tokens/tokens.v1.schema.json +143 -0
- package/payload/lanes/web/Caddyfile +11 -0
- package/payload/lanes/web/README.md +253 -4
- package/payload/lanes/web/directory.css +95 -0
- package/payload/lanes/web/directory.js +951 -0
- package/payload/lanes/web/generated/README.md +107 -0
- package/payload/lanes/web/generated/lanes2_protocol.d.mts +1162 -0
- package/payload/lanes/web/generated/lanes2_protocol.mjs +2333 -0
- package/payload/lanes/web/inbox.js +1140 -0
- package/payload/lanes/web/mobile.js +35 -45
- package/payload/lanes/web/tokens.css +137 -0
- package/payload/manifest.json +7 -4
|
@@ -0,0 +1,1140 @@
|
|
|
1
|
+
// Phone Operations views (lanes2 W30-B; P09-P12, E33), loaded only by the inbox/schedule/results fragment.
|
|
2
|
+
// S3's shared inbox fixture and S5's builds-panel fixture own ids, order, words and evidence; directory.css owns style.
|
|
3
|
+
// Type explicitly grants input. Owner updates wait while typing; desktop/tablet opening focuses a control, never text.
|
|
4
|
+
// The private scope coexists with directory.js. Source contracts and custody rules: web/README.md, "Phone inbox".
|
|
5
|
+
(() => {
|
|
6
|
+
'use strict';
|
|
7
|
+
const VIEWS = ['needs_you', 'unread', 'waiting', 'scheduled', 'history'];
|
|
8
|
+
const VIEW_TITLES = {needs_you: 'Needs you', unread: 'Unread', waiting: 'Waiting', scheduled: 'Scheduled', history: 'History'};
|
|
9
|
+
// DeliveryState::label (crates/lanes-protocol inbox.rs): the state word and its consequence, readable without colour.
|
|
10
|
+
const LABELS = {
|
|
11
|
+
draft: 'draft (not sent)', scheduled: 'scheduled (held for its trigger)', waiting: 'waiting (held for a condition)',
|
|
12
|
+
ready: 'ready (in custody, not yet claimed)', claimed: 'claimed (delivery started, no evidence yet)',
|
|
13
|
+
submitted: 'submitted (no acknowledgement yet)', native_accepted: 'native accepted (not acknowledged)',
|
|
14
|
+
acknowledged: 'acknowledged (received; work not implied)', failed: 'failed (not delivered; never resent blindly)',
|
|
15
|
+
expired: 'expired (time to live passed)', cancelled: 'cancelled', uncertain: 'UNCERTAIN (may have arrived; held, never resent)',
|
|
16
|
+
};
|
|
17
|
+
const ATTENTION = {human_question: 'asked you a question', needs_input: 'needs your input',
|
|
18
|
+
delivery_uncertain: 'your message may not have arrived'};
|
|
19
|
+
const WAITING = {peer: 'waiting for a reply', human: 'waiting for a person', dependency: 'waiting for a dependency',
|
|
20
|
+
delivery: 'waiting for delivery', capacity: 'waiting for capacity', build: 'waiting for a build'};
|
|
21
|
+
const ENUMS = {
|
|
22
|
+
custody: ['draft', 'scheduled', 'waiting', 'ready', 'claimed', 'expired', 'cancelled', 'failed'],
|
|
23
|
+
native: ['not_offered', 'submitted', 'native_accepted', 'rejected', 'uncertain'],
|
|
24
|
+
receipt: ['not_requested', 'pending', 'acknowledged'],
|
|
25
|
+
fulfillment: ['open', 'accepted', 'in_progress', 'completed', 'declined', 'superseded'],
|
|
26
|
+
actor: ['human', 'agent'], completeness: ['complete', 'incomplete'],
|
|
27
|
+
availability: ['available', 'unsupported', 'unconfigured', 'unauthorized', 'unqualified', 'unhealthy'],
|
|
28
|
+
};
|
|
29
|
+
const PEER_FILTERS = {all: 'All traffic', without_peer_traffic: 'Without peer traffic', peer_traffic_only: 'Peer traffic only'};
|
|
30
|
+
const SEND_NOW = 'send_now', AFTER_TURN = 'after_turn';
|
|
31
|
+
const AFTER_TURN_REASON = 'after turn needs Throttle next-turn delivery, which stays off until M8 (BEY-6848)';
|
|
32
|
+
const PEER_READ_ONLY = 'Peer traffic between agents is read-only here; compose to one of the lanes instead.';
|
|
33
|
+
const EXPIRED_TEXT = '[message text expired; metadata kept]';
|
|
34
|
+
const NO_MESSAGES = 'no messages yet';
|
|
35
|
+
const WITNESSES = {inbox_commit: "committed to the owner's inbox", shaped_attempt_released: 'attempt released upstream',
|
|
36
|
+
upstream_accepted: 'upstream accepted the attempt', inbox_delivered_mark: "owner's delivery mark",
|
|
37
|
+
recipient_ack: 'recipient acknowledged', inbox_ack_observed: 'acknowledgement observed'};
|
|
38
|
+
const CHANNELS = {peer_socket: 'peer socket', codex_queue: 'Codex queue', throttle_turn: 'Throttle turn', typed: 'typed input',
|
|
39
|
+
queued: 'lane inbox queue'};
|
|
40
|
+
const SNOOZE_MS = 60 * 60 * 1000;
|
|
41
|
+
const TEXT_MAX = 4096, LABEL_MAX = 256, PAGE_MAX = 500, LIST_MAX = 64, DRAFTS_MAX = 32, TOKEN_MAX = 512;
|
|
42
|
+
const THREAD_ACTIONS = [['mark_read', 'Mark read'], ['mark_unread', 'Mark unread'], ['snooze', 'Snooze 1 h'],
|
|
43
|
+
['unsnooze', 'Unsnooze'], ['archive', 'Archive'], ['unarchive', 'Unarchive']];
|
|
44
|
+
const TABS = {inbox: 'Inbox', schedule: 'Schedule', results: 'Results'};
|
|
45
|
+
const SCHEDULE_UNAVAILABLE = {code: 'schedule_read_absent', reason: 'lanes.api/1 carries no schedule read yet: schedules '
|
|
46
|
+
+ 'and occurrences stay in the host store (S4) and reach no client before gate I1'};
|
|
47
|
+
const REASONS = {
|
|
48
|
+
not_connected: 'Not connected: this host does not serve inbox commands to the browser yet',
|
|
49
|
+
stale_snapshot: 'Only a current inbox snapshot authorizes a write; this one is stale',
|
|
50
|
+
peer_traffic_read_only: PEER_READ_ONLY,
|
|
51
|
+
page_read_absent: 'Unavailable (page_read_absent): this host serves the browser no inbox page or earlier entries yet',
|
|
52
|
+
outcome_lookup_absent: "Unavailable (outcome_lookup_absent): lanes.api/1 serves the browser no lookup of a command's "
|
|
53
|
+
+ 'outcome by its operation id before the E7 gateway',
|
|
54
|
+
unreadable: 'The retained command cannot be read on this device; it can only be discarded',
|
|
55
|
+
};
|
|
56
|
+
const NOTES = {
|
|
57
|
+
not_here: 'That record is not here', filter_cleared: 'The filter was cleared to show the linked record.',
|
|
58
|
+
updates_wait: 'Updates arrived while you type; they show when you finish typing.',
|
|
59
|
+
discard: 'Discarding forgets the operation id: if the owner already has that command, sending it again may duplicate it.',
|
|
60
|
+
};
|
|
61
|
+
const ACTION_WORDS = Object.fromEntries(THREAD_ACTIONS);
|
|
62
|
+
|
|
63
|
+
class InboxError extends Error {}
|
|
64
|
+
const bad = what => { throw new InboxError(what); };
|
|
65
|
+
const has = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
66
|
+
const isInt = value => Number.isSafeInteger(value) && value >= 0;
|
|
67
|
+
const bytes = text => { let n = 0; for (const ch of text) { const c = ch.codePointAt(0); n += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4; } return n; };
|
|
68
|
+
const isId = (value, max = 128) => typeof value === 'string' && value.length > 0 && value.length <= max && /^[!#-[\]-~]+$/.test(value);
|
|
69
|
+
// lanes-protocol Text (Label, LongText): non-empty, bounded, no control character but a newline or a tab
|
|
70
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/;
|
|
71
|
+
const isText = (value, max) => typeof value === 'string' && value !== '' && bytes(value) <= max && !CONTROL.test(value);
|
|
72
|
+
|
|
73
|
+
function deliveryState(e) {
|
|
74
|
+
if (e.native === 'uncertain') return 'uncertain';
|
|
75
|
+
if (e.receipt === 'acknowledged') return 'acknowledged';
|
|
76
|
+
if (['draft', 'expired', 'cancelled', 'failed'].includes(e.custody)) return e.custody;
|
|
77
|
+
if (e.native === 'native_accepted' || e.native === 'submitted') return e.native;
|
|
78
|
+
if (['scheduled', 'waiting', 'ready'].includes(e.custody)) return e.custody;
|
|
79
|
+
return 'claimed';
|
|
80
|
+
}
|
|
81
|
+
function evidenceProblem(e) {
|
|
82
|
+
const held = ['draft', 'scheduled', 'waiting'].includes(e.custody);
|
|
83
|
+
if (e.custody === 'draft' && !(e.native === 'not_offered' && e.receipt === 'not_requested' && e.fulfillment === 'open')) {
|
|
84
|
+
return 'a draft has offered nothing, requested no receipt and reports no work';
|
|
85
|
+
}
|
|
86
|
+
if (held && e.receipt === 'acknowledged') return 'a message nobody sent cannot have been acknowledged';
|
|
87
|
+
if (['submitted', 'native_accepted', 'uncertain'].includes(e.native) && (held || e.custody === 'ready')) {
|
|
88
|
+
return 'a delivery attempt needs a claim: custody is claimed or terminal';
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function latestProblem(latest) {
|
|
93
|
+
const problem = evidenceProblem(latest.delivery);
|
|
94
|
+
if (problem) return problem;
|
|
95
|
+
if (latest.delivery_state !== deliveryState(latest.delivery)) return 'a delivery state is the summary of its evidence, never a friendlier word';
|
|
96
|
+
if (latest.text_expired && latest.preview != null) return 'an expired payload has no preview; it is shown as missing';
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
function rowProblem(row) {
|
|
100
|
+
if (row.latest == null) {
|
|
101
|
+
if (row.entries !== 0) return 'a thread with entries shows its newest one';
|
|
102
|
+
const signal = row.attention === 'needs_input' && !row.peer_traffic && row.unread === 0 && row.waiting_for == null && !row.scheduled;
|
|
103
|
+
if (!signal) return "a thread without entries is a lane's needs-input signal and nothing else";
|
|
104
|
+
} else {
|
|
105
|
+
if (row.entries === 0) return 'a thread with a newest entry has entries';
|
|
106
|
+
const problem = latestProblem(row.latest);
|
|
107
|
+
if (problem) return problem;
|
|
108
|
+
if (row.latest.at_unix_ms > row.activity_unix_ms) return "a thread's activity is never older than its newest entry";
|
|
109
|
+
}
|
|
110
|
+
if (row.unread > row.entries) return 'a thread cannot have more unread entries than entries';
|
|
111
|
+
if (row.peer_traffic && row.attention != null) return 'routine peer traffic raises no human attention (C05)';
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const snoozed = (row, asOf) => row.snoozed_until_unix_ms != null && row.snoozed_until_unix_ms > asOf;
|
|
115
|
+
function inView(row, view, asOf) {
|
|
116
|
+
const quiet = snoozed(row, asOf), active = !row.archived && !quiet;
|
|
117
|
+
const attention = row.attention != null, waiting = row.waiting_for != null;
|
|
118
|
+
if (view === 'needs_you') return active && attention;
|
|
119
|
+
if (view === 'unread') return active && row.unread > 0;
|
|
120
|
+
if (view === 'waiting') return active && waiting;
|
|
121
|
+
if (view === 'scheduled') return !row.archived && (row.scheduled || quiet);
|
|
122
|
+
if (view === 'history') return row.archived || (active && !attention && row.unread === 0 && !waiting && !row.scheduled);
|
|
123
|
+
return bad(`no inbox view ${view}`);
|
|
124
|
+
}
|
|
125
|
+
function admits(row, {workspace = null, peer = 'all', text = ''} = {}) {
|
|
126
|
+
const peerOk = peer === 'all' || (peer === 'peer_traffic_only') === !!row.peer_traffic;
|
|
127
|
+
const textOk = !text || row.subject.toLowerCase().includes(text.toLowerCase());
|
|
128
|
+
return (workspace == null || row.workspace_id === workspace) && peerOk && textOk;
|
|
129
|
+
}
|
|
130
|
+
const visible = (projection, view, filter) => projection.rows.filter(row => inView(row, view, projection.as_of_unix_ms) && admits(row, filter));
|
|
131
|
+
const utcText = ms => `${new Date(Math.floor(ms / 1000) * 1000).toISOString().slice(0, 16).replace('T', ' ')}Z`;
|
|
132
|
+
function rowWords(row, asOf) {
|
|
133
|
+
const parts = [row.subject.replace(/\n/g, ' '), row.latest ? LABELS[row.latest.delivery_state] : NO_MESSAGES];
|
|
134
|
+
if (row.attention != null) parts.push(`needs you: ${ATTENTION[row.attention]}`);
|
|
135
|
+
if (row.waiting_for != null) parts.push(WAITING[row.waiting_for]);
|
|
136
|
+
if (snoozed(row, asOf)) parts.push(`snoozed until ${utcText(row.snoozed_until_unix_ms)}`);
|
|
137
|
+
if (row.archived) parts.push('archived');
|
|
138
|
+
if (row.unread > 0) parts.push(`${row.unread} unread`);
|
|
139
|
+
if (row.peer_traffic) parts.push('peer traffic');
|
|
140
|
+
if (row.latest && row.latest.preview != null) parts.push(row.latest.preview.replace(/\n/g, ' '));
|
|
141
|
+
else if (row.latest && row.latest.text_expired) parts.push(EXPIRED_TEXT);
|
|
142
|
+
return parts.join(' · ');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function shape(value, keys, optional, what) {
|
|
146
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) bad(`${what} is not an object`);
|
|
147
|
+
for (const key of Object.keys(value)) if (!keys.includes(key)) bad(`${what}.${key} is not a field`);
|
|
148
|
+
for (const key of keys) if (!optional.includes(key) && !has(value, key)) bad(`${what}.${key} is missing`);
|
|
149
|
+
}
|
|
150
|
+
const want = (ok, what) => ok || bad(what);
|
|
151
|
+
const oneOf = (value, list, what) => want(list.includes(value), `${what} ${JSON.stringify(value)} is not one of ${list.join(', ')}`);
|
|
152
|
+
function evidence(e, what) {
|
|
153
|
+
shape(e, ['custody', 'native', 'receipt', 'fulfillment'], [], what);
|
|
154
|
+
for (const key of ['custody', 'native', 'receipt', 'fulfillment']) oneOf(e[key], ENUMS[key], `${what}.${key}`);
|
|
155
|
+
const problem = evidenceProblem(e);
|
|
156
|
+
if (problem) bad(`${what}: ${problem}`);
|
|
157
|
+
}
|
|
158
|
+
const ROW_KEYS = ['v', 'thread', 'subject', 'peer', 'workspace_id', 'peer_traffic', 'entries', 'unread', 'activity_unix_ms',
|
|
159
|
+
'latest', 'attention', 'waiting_for', 'scheduled', 'snoozed_until_unix_ms', 'archived'];
|
|
160
|
+
const ROW_OPTIONAL = ['latest', 'attention', 'waiting_for', 'snoozed_until_unix_ms'];
|
|
161
|
+
function decodeLatest(latest, what) {
|
|
162
|
+
shape(latest, ['at_unix_ms', 'from_kind', 'preview', 'text_expired', 'delivery', 'delivery_state'], ['preview'], what);
|
|
163
|
+
want(isInt(latest.at_unix_ms), `${what}.at_unix_ms is not a time`);
|
|
164
|
+
oneOf(latest.from_kind, ENUMS.actor, `${what}.from_kind`);
|
|
165
|
+
want(latest.preview == null || isText(latest.preview, LABEL_MAX), `${what}.preview is not a label`);
|
|
166
|
+
want(typeof latest.text_expired === 'boolean', `${what}.text_expired is not a boolean`);
|
|
167
|
+
evidence(latest.delivery, `${what}.delivery`);
|
|
168
|
+
oneOf(latest.delivery_state, Object.keys(LABELS), `${what}.delivery_state`);
|
|
169
|
+
}
|
|
170
|
+
function decodeRow(row, what) {
|
|
171
|
+
shape(row, ROW_KEYS, ROW_OPTIONAL, what);
|
|
172
|
+
want(row.v === 1, `${what}.v is not 1`);
|
|
173
|
+
for (const key of ['thread', 'peer', 'workspace_id']) want(isId(row[key]), `${what}.${key} is not a wire id`);
|
|
174
|
+
want(isText(row.subject, LABEL_MAX), `${what}.subject is not a label`);
|
|
175
|
+
for (const key of ['peer_traffic', 'scheduled', 'archived']) want(typeof row[key] === 'boolean', `${what}.${key} is not a boolean`);
|
|
176
|
+
for (const key of ['entries', 'unread', 'activity_unix_ms']) want(isInt(row[key]), `${what}.${key} is not a count`);
|
|
177
|
+
if (row.latest != null) decodeLatest(row.latest, `${what}.latest`);
|
|
178
|
+
if (row.attention != null) oneOf(row.attention, Object.keys(ATTENTION), `${what}.attention`);
|
|
179
|
+
if (row.waiting_for != null) oneOf(row.waiting_for, Object.keys(WAITING), `${what}.waiting_for`);
|
|
180
|
+
want(row.snoozed_until_unix_ms == null || isInt(row.snoozed_until_unix_ms), `${what}.snoozed_until_unix_ms is not a time`);
|
|
181
|
+
const problem = rowProblem(row);
|
|
182
|
+
if (problem) bad(`${what}: ${problem}`);
|
|
183
|
+
}
|
|
184
|
+
function actionsOf(list, what) {
|
|
185
|
+
want(Array.isArray(list) && list.length <= LIST_MAX, `${what} is not a list of at most ${LIST_MAX}`);
|
|
186
|
+
list.forEach((a, i) => {
|
|
187
|
+
shape(a, ['action', 'availability', 'reason'], ['reason'], `${what}[${i}]`);
|
|
188
|
+
want(isId(a.action, 64), `${what}[${i}].action is not a name`);
|
|
189
|
+
oneOf(a.availability, ENUMS.availability, `${what}[${i}].availability`);
|
|
190
|
+
want(a.reason == null || isText(a.reason, LABEL_MAX), `${what}[${i}].reason is not a label`);
|
|
191
|
+
if (a.availability !== 'available' && a.reason == null) bad('an unavailable action must say why');
|
|
192
|
+
if (list.slice(0, i).some(b => b.action === a.action)) bad('an action is listed twice in an inbox projection');
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
function decodeInbox(p) {
|
|
196
|
+
shape(p, ['v', 'principal_id', 'revision', 'as_of_unix_ms', 'completeness', 'rows', 'omitted', 'omitted_by_view', 'next_page',
|
|
197
|
+
'actions'], ['next_page'], 'inbox');
|
|
198
|
+
want(p.v === 1, 'inbox.v is not 1');
|
|
199
|
+
want(isId(p.principal_id), 'inbox.principal_id is not a wire id');
|
|
200
|
+
for (const key of ['revision', 'as_of_unix_ms', 'omitted']) want(isInt(p[key]), `inbox.${key} is not a count`);
|
|
201
|
+
oneOf(p.completeness, ENUMS.completeness, 'inbox.completeness');
|
|
202
|
+
want(Array.isArray(p.rows) && p.rows.length <= PAGE_MAX, `inbox.rows is not a list of at most ${PAGE_MAX}`);
|
|
203
|
+
p.rows.forEach((row, i) => {
|
|
204
|
+
decodeRow(row, `inbox.rows[${i}]`);
|
|
205
|
+
if (p.rows.slice(0, i).some(earlier => earlier.thread === row.thread)) bad('a thread appears once per inbox projection');
|
|
206
|
+
});
|
|
207
|
+
if (p.omitted > 0 && p.completeness === 'complete') bad('a projection that leaves threads out cannot claim completeness');
|
|
208
|
+
want(p.next_page == null || isId(p.next_page, TOKEN_MAX), 'inbox.next_page is not a token');
|
|
209
|
+
if (p.next_page != null && p.omitted === 0) bad('a next page needs threads this page leaves out');
|
|
210
|
+
shape(p.omitted_by_view, VIEWS, [], 'inbox.omitted_by_view');
|
|
211
|
+
for (const view of VIEWS) want(isInt(p.omitted_by_view[view]), `inbox.omitted_by_view.${view} is not a count`);
|
|
212
|
+
if (VIEWS.some(view => p.omitted_by_view[view] > p.omitted)) bad('a view cannot leave out more threads than the page does');
|
|
213
|
+
actionsOf(p.actions, 'inbox.actions');
|
|
214
|
+
return p;
|
|
215
|
+
}
|
|
216
|
+
function decodeThread(t) {
|
|
217
|
+
shape(t, ['v', 'thread', 'revision', 'entries', 'earlier_omitted', 'earlier_page'], ['earlier_page'], 'thread');
|
|
218
|
+
want(t.v === 1 && isId(t.thread) && isInt(t.revision) && isInt(t.earlier_omitted), 'thread header is malformed');
|
|
219
|
+
want(Array.isArray(t.entries) && t.entries.length <= PAGE_MAX, 'thread.entries is not a list');
|
|
220
|
+
t.entries.forEach((e, i) => {
|
|
221
|
+
const what = `thread.entries[${i}]`;
|
|
222
|
+
shape(e, ['v', 'message_id', 'from', 'from_kind', 'to', 'at_unix_ms', 'text', 'delivery', 'delivery_state', 'owner_evidence',
|
|
223
|
+
'lanes_evidence'], ['text', 'owner_evidence', 'lanes_evidence'], what);
|
|
224
|
+
want(e.v === 1 && isId(e.message_id) && isId(e.from) && isId(e.to) && isInt(e.at_unix_ms), `${what} is malformed`);
|
|
225
|
+
oneOf(e.from_kind, ENUMS.actor, `${what}.from_kind`);
|
|
226
|
+
want(e.text == null || isText(e.text, TEXT_MAX), `${what}.text is not a text`);
|
|
227
|
+
evidence(e.delivery, `${what}.delivery`);
|
|
228
|
+
if (e.delivery_state !== deliveryState(e.delivery)) bad('a delivery state is the summary of its evidence, never a friendlier word');
|
|
229
|
+
if (e.owner_evidence != null) {
|
|
230
|
+
shape(e.owner_evidence, ['witness', 'target_generation'], ['target_generation'], `${what}.owner_evidence`);
|
|
231
|
+
oneOf(e.owner_evidence.witness, Object.keys(WITNESSES), `${what}.owner_evidence.witness`);
|
|
232
|
+
want(e.owner_evidence.target_generation == null || isText(e.owner_evidence.target_generation, LABEL_MAX), `${what}.owner_evidence.target_generation is not a label`);
|
|
233
|
+
}
|
|
234
|
+
if (e.lanes_evidence != null) {
|
|
235
|
+
shape(e.lanes_evidence, ['channel', 'target_generation', 'reached_generation'], ['reached_generation'], `${what}.lanes_evidence`);
|
|
236
|
+
oneOf(e.lanes_evidence.channel, Object.keys(CHANNELS), `${what}.lanes_evidence.channel`);
|
|
237
|
+
want(isId(e.lanes_evidence.target_generation) && (e.lanes_evidence.reached_generation == null || isId(e.lanes_evidence.reached_generation)),
|
|
238
|
+
`${what}.lanes_evidence generations are not wire ids`);
|
|
239
|
+
}
|
|
240
|
+
if (['draft', 'scheduled', 'waiting'].includes(e.delivery.custody) && (e.owner_evidence != null || e.lanes_evidence != null)) {
|
|
241
|
+
bad('a message the Lanes host still holds has no delivery witness');
|
|
242
|
+
}
|
|
243
|
+
if (i && t.entries[i - 1].at_unix_ms > e.at_unix_ms) bad('thread entries are ordered oldest first');
|
|
244
|
+
if (t.entries.slice(0, i).some(earlier => earlier.message_id === e.message_id)) bad('a message appears once per thread');
|
|
245
|
+
});
|
|
246
|
+
want(t.earlier_page == null || isId(t.earlier_page, TOKEN_MAX), 'thread.earlier_page is not a token');
|
|
247
|
+
if ((t.earlier_page != null) !== (t.earlier_omitted > 0)) bad('a thread page offers an earlier page exactly when it leaves entries out');
|
|
248
|
+
return t;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const ageText = s => (s >= 3600 ? `${Math.floor(s / 3600)}h ${Math.floor((s % 3600) / 60)}m` : s >= 60 ? `${Math.floor(s / 60)}m ${s % 60}s` : `${s}s`);
|
|
252
|
+
const stateText = job => (job.label.toLowerCase() === job.state.toLowerCase() ? job.label : `${job.label} (${job.state})`);
|
|
253
|
+
function consequenceOf(job) {
|
|
254
|
+
if (job.wait) return job.wait.reason;
|
|
255
|
+
const code = job.receipt && job.receipt.exit_code, artifact = job.receipt && job.receipt.artifact_sha256;
|
|
256
|
+
if (code != null) return artifact != null ? `exit ${code}; artifact recorded` : `exit ${code}`;
|
|
257
|
+
return job.priority;
|
|
258
|
+
}
|
|
259
|
+
function detailLines(job) {
|
|
260
|
+
const code = job.receipt && job.receipt.exit_code, artifact = job.receipt && job.receipt.artifact_sha256;
|
|
261
|
+
const lines = [`${job.label} (buildctl: ${job.state}) · stage ${job.stage}`,
|
|
262
|
+
`Lane ${job.lane} · profile ${job.profile} · worker ${job.worker ?? '-'}`,
|
|
263
|
+
`Source snapshot ${job.snapshot} · revision ${job.source_revision ?? '-'}`, `Submitted ${ageText(job.age_s)} ago`];
|
|
264
|
+
if (job.wait) lines.push(`Waiting: ${job.wait.reason}`, `Provenance: ${job.wait.provenance}`);
|
|
265
|
+
lines.push(...job.priority_detail, `Log: ${job.log.length} verified bytes (${job.log.identity})`);
|
|
266
|
+
if (code != null || artifact != null) lines.push(`Receipt: exit ${code ?? '-'} · artifact ${artifact ?? '-'}`);
|
|
267
|
+
lines.push('Actions:', ...job.actions.map(a => (a.available ? ` ${a.label}: available` : ` ${a.label}: unavailable (${a.code}): ${a.reason}`)));
|
|
268
|
+
return lines;
|
|
269
|
+
}
|
|
270
|
+
const str = (v, what) => want(typeof v === 'string', `${what} is not a string`);
|
|
271
|
+
const optStr = (v, what) => want(v === null || typeof v === 'string', `${what} is not a string or null`);
|
|
272
|
+
const obj = (v, what) => want(v && typeof v === 'object' && !Array.isArray(v), `${what} is not an object`);
|
|
273
|
+
const strings = (v, what) => want(Array.isArray(v) && v.every(l => typeof l === 'string'), `${what} is not a list of strings`);
|
|
274
|
+
// crates/lanes-terminal/src/ops/builds/decode.rs, field for field: a document it refuses is refused here
|
|
275
|
+
function decodeJob(job, what) {
|
|
276
|
+
obj(job, what);
|
|
277
|
+
for (const key of ['id', 'title', 'state', 'label', 'stage', 'lane', 'profile', 'snapshot', 'priority']) str(job[key], `${what}.${key}`);
|
|
278
|
+
for (const key of ['worker', 'source_revision']) optStr(job[key], `${what}.${key}`);
|
|
279
|
+
want(isInt(job.age_s), `${what}.age_s is not a nonnegative integer`);
|
|
280
|
+
want(isId(job.id), `job id ${JSON.stringify(job.id)} is not a record id`);
|
|
281
|
+
if (job.wait !== null) { obj(job.wait, `${what}.wait`); str(job.wait.reason, `${what}.wait.reason`); str(job.wait.provenance, `${what}.wait.provenance`); }
|
|
282
|
+
strings(job.priority_detail, `${what}.priority_detail`);
|
|
283
|
+
obj(job.log, `${what}.log`);
|
|
284
|
+
want(typeof job.log.identity === 'string' && isInt(job.log.length), `${what}.log is malformed`);
|
|
285
|
+
if (job.receipt !== null) {
|
|
286
|
+
obj(job.receipt, `${what}.receipt`);
|
|
287
|
+
want(job.receipt.exit_code == null || Number.isSafeInteger(job.receipt.exit_code), `${what}.receipt.exit_code is not an integer`);
|
|
288
|
+
optStr(job.receipt.artifact_sha256, `${what}.receipt.artifact_sha256`);
|
|
289
|
+
}
|
|
290
|
+
want(Array.isArray(job.actions), `${what}.actions is not a list`);
|
|
291
|
+
for (const a of job.actions) {
|
|
292
|
+
want(a && typeof a.action === 'string' && typeof a.label === 'string' && typeof a.available === 'boolean', `${what} action is malformed`);
|
|
293
|
+
optStr(a.code, `${what} action code`);
|
|
294
|
+
optStr(a.reason, `${what} action reason`);
|
|
295
|
+
if (!a.available && (a.code === null || a.reason === null)) bad(`unavailable action ${a.action} carries no code and reason`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const LANE_WAIT = ['lane', 'job', 'attempt_ref', 'state', 'reason', 'provenance'];
|
|
299
|
+
function decodeBuilds(doc) {
|
|
300
|
+
want(doc && typeof doc === 'object' && doc.schema === 'lanes2.builds-panel/1', 'builds: schema');
|
|
301
|
+
obj(doc.source, 'builds.source');
|
|
302
|
+
want(typeof doc.source.adapter === 'string' && typeof doc.source.events_capability === 'boolean', 'builds.source is malformed');
|
|
303
|
+
obj(doc.completeness, 'builds.completeness');
|
|
304
|
+
want(typeof doc.completeness.complete === 'boolean', 'builds.completeness is malformed');
|
|
305
|
+
optStr(doc.completeness.label, 'builds.completeness.label');
|
|
306
|
+
want(has(doc, 'unavailable') && (doc.unavailable === null || (typeof doc.unavailable.code === 'string' && typeof doc.unavailable.reason === 'string')), 'builds.unavailable is malformed');
|
|
307
|
+
if (!doc.completeness.complete && doc.completeness.label === null && !doc.unavailable) bad('an incomplete queue carries no label');
|
|
308
|
+
str(doc.observed_at, 'builds.observed_at');
|
|
309
|
+
for (const key of ['jobs', 'recent', 'lane_waits']) want(Array.isArray(doc[key]), `builds.${key} is not a list`);
|
|
310
|
+
doc.jobs.forEach((job, i) => decodeJob(job, `builds.jobs[${i}]`));
|
|
311
|
+
doc.recent.forEach((job, i) => decodeJob(job, `builds.recent[${i}]`));
|
|
312
|
+
doc.lane_waits.forEach((wait, i) => { obj(wait, `builds.lane_waits[${i}]`); for (const key of LANE_WAIT) str(wait[key], `builds.lane_waits[${i}].${key}`); });
|
|
313
|
+
strings(doc.resources, 'builds.resources');
|
|
314
|
+
return doc;
|
|
315
|
+
}
|
|
316
|
+
// records.rs lane_wait_lines and lane_wait_detail
|
|
317
|
+
const laneWait = wait => ({line: `${wait.lane}: ${wait.reason}`, detail: [`Lane ${wait.lane} waits on build ${wait.job} (${wait.state})`,
|
|
318
|
+
wait.reason, `Provenance: ${wait.provenance}`, `Attempt: ${wait.attempt_ref}`]});
|
|
319
|
+
const record = (job, kind) => ({id: job.id, kind, title: job.title, state: stateText(job), when: `${ageText(job.age_s)} ago`,
|
|
320
|
+
consequence: consequenceOf(job), lines: detailLines(job)});
|
|
321
|
+
const buildRecords = panel => [...panel.jobs.map(job => record(job, 'build')), ...panel.recent.map(job => record(job, 'result'))];
|
|
322
|
+
function buildsHeader(panel) {
|
|
323
|
+
const lines = [];
|
|
324
|
+
if (!panel.completeness.complete && panel.completeness.label) lines.push(panel.completeness.label);
|
|
325
|
+
if (panel.unavailable) lines.push(`Builds unavailable (${panel.unavailable.code}): ${panel.unavailable.reason}`);
|
|
326
|
+
lines.push(`Source: ${panel.source.adapter} · protocol ${panel.source.protocol ?? 'unknown'} · read ${panel.observed_at}`);
|
|
327
|
+
return lines;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function parseLink(hash) {
|
|
331
|
+
const m = /^#(inbox|schedule|results)(?:=(.*))?$/.exec(String(hash || ''));
|
|
332
|
+
if (!m) return null;
|
|
333
|
+
if (m[2] === undefined) return {tab: m[1], id: null};
|
|
334
|
+
let id = null;
|
|
335
|
+
try { id = decodeURIComponent(m[2]); } catch {}
|
|
336
|
+
return isId(id) ? {tab: m[1], id} : {tab: m[1], id: null, invalid: true};
|
|
337
|
+
}
|
|
338
|
+
const linkFor = (tab, id) => `#${tab}=${encodeURIComponent(id)}`;
|
|
339
|
+
const PREFIX = 'lanes:inbox:';
|
|
340
|
+
function deviceLocal(storage) {
|
|
341
|
+
const key = (principal, field) => `${PREFIX}${encodeURIComponent(principal)}:${field}`;
|
|
342
|
+
const keys = () => { try { return Array.from({length: storage.length}, (_, i) => storage.key(i)); } catch { return []; } };
|
|
343
|
+
// A purge keeps every principal's `outgoing`: an unresolved command keeps its operation id until its own principal
|
|
344
|
+
// has a receipt or a refusal for it (or discards it), so an account change never turns a retry into a duplicate.
|
|
345
|
+
const drop = test => { for (const k of keys()) if (typeof k === 'string' && k.startsWith(PREFIX) && !k.endsWith(':outgoing') && test(k)) try { storage.removeItem(k); } catch {} };
|
|
346
|
+
return {
|
|
347
|
+
read(principal, field) {
|
|
348
|
+
try { const raw = storage && storage.getItem(key(principal, field)); return raw == null ? null : JSON.parse(raw); } catch { return field === 'outgoing' ? {invalid: true} : null; }
|
|
349
|
+
},
|
|
350
|
+
slot(principal) {
|
|
351
|
+
let raw;
|
|
352
|
+
try { raw = storage.getItem(key(principal, 'outgoing')); return {raw, value: raw == null ? null : JSON.parse(raw)}; }
|
|
353
|
+
catch { return {raw, value: {invalid: true}}; }
|
|
354
|
+
},
|
|
355
|
+
write(principal, field, value) {
|
|
356
|
+
if (!storage) return false;
|
|
357
|
+
const k = key(principal, field);
|
|
358
|
+
try {
|
|
359
|
+
const encoded = value == null ? null : JSON.stringify(value);
|
|
360
|
+
if (encoded == null) storage.removeItem(k); else storage.setItem(k, encoded);
|
|
361
|
+
return storage.getItem(k) === encoded;
|
|
362
|
+
} catch { return false; }
|
|
363
|
+
},
|
|
364
|
+
purge: principal => storage && drop(k => k.startsWith(key(principal, ''))),
|
|
365
|
+
purgeOthers: principal => storage && drop(k => !k.startsWith(key(principal, ''))),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function threadCommand(row, action, now, operation_id) {
|
|
370
|
+
const command = {v: 1, operation_id, thread: row.thread, action};
|
|
371
|
+
if (action === 'snooze') command.snooze_until_unix_ms = now + SNOOZE_MS;
|
|
372
|
+
if (action === 'mark_read' || action === 'archive') command.seen_through_unix_ms = row.activity_unix_ms;
|
|
373
|
+
return command;
|
|
374
|
+
}
|
|
375
|
+
function composeCommand({operation_id, to, text, reply_to = null, target_generation = null}) {
|
|
376
|
+
const command = {v: 1, operation_id, to, text, timing: 'now'};
|
|
377
|
+
if (reply_to) command.reply_to = reply_to;
|
|
378
|
+
if (target_generation) command.target_generation = target_generation;
|
|
379
|
+
return command;
|
|
380
|
+
}
|
|
381
|
+
let minted = 0;
|
|
382
|
+
const mint = () => `op-${globalThis.crypto?.randomUUID?.() || `${Date.now().toString(36)}.${Math.random().toString(36).slice(2, 10)}`}.${++minted}`;
|
|
383
|
+
|
|
384
|
+
const sameIntent = (a, b) => a.kind === b.kind && ['to', 'text', 'reply_to', 'target_generation', 'thread', 'action'].every(k => a.body[k] === b.body[k]);
|
|
385
|
+
function savedRequest(request) {
|
|
386
|
+
if (request == null) return null;
|
|
387
|
+
try {
|
|
388
|
+
shape(request, ['kind', 'body'], [], 'saved command');
|
|
389
|
+
const b = request.body;
|
|
390
|
+
if (request.kind === 'inbox_compose') {
|
|
391
|
+
shape(b, ['v', 'operation_id', 'to', 'text', 'timing', 'reply_to', 'target_generation'], ['reply_to', 'target_generation'], 'saved compose');
|
|
392
|
+
want(isId(b.to) && isText(b.text, TEXT_MAX) && b.text.trim() && b.timing === 'now', 'invalid saved compose');
|
|
393
|
+
for (const key of ['reply_to', 'target_generation']) want(b[key] == null || isId(b[key]), 'invalid saved target');
|
|
394
|
+
} else {
|
|
395
|
+
want(request.kind === 'inbox_thread', 'unknown saved command');
|
|
396
|
+
shape(b, ['v', 'operation_id', 'thread', 'action', 'snooze_until_unix_ms', 'seen_through_unix_ms'], ['snooze_until_unix_ms', 'seen_through_unix_ms'], 'saved action');
|
|
397
|
+
want(isId(b.thread) && THREAD_ACTIONS.some(([name]) => name === b.action), 'invalid saved action');
|
|
398
|
+
for (const [key, required] of [['snooze_until_unix_ms', b.action === 'snooze'], ['seen_through_unix_ms', ['mark_read', 'archive'].includes(b.action)]]) {
|
|
399
|
+
want(required ? isInt(b[key]) : b[key] == null, 'invalid saved activity');
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
want(b.v === 1 && isId(b.operation_id), 'invalid saved operation');
|
|
403
|
+
return request;
|
|
404
|
+
} catch { return {invalid: true}; }
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Source port: subscribe(frames), optional readPage/readThread, send(command). onChange names user/frame cause.
|
|
408
|
+
function createInbox({source = null, storage = null, now = () => Date.now(), onChange = () => {}, locks = globalThis.navigator?.locks} = {}) {
|
|
409
|
+
const local = deviceLocal(storage);
|
|
410
|
+
const fresh = () => ({state: source ? 'loading' : 'unavailable', doc: null, reason: '', stale: false});
|
|
411
|
+
const st = {tab: 'inbox', link: null, notice: '', principal: null, seenPrincipal: false, stream: 0, cancel: null, drop: null,
|
|
412
|
+
inbox: fresh(), builds: fresh(), threads: new Map(), view: 'needs_you', filter: {workspace: null, peer: 'all', text: ''},
|
|
413
|
+
selection: {inbox: null, schedule: null, results: null}, composer: null, pending: null, uncertain: null, discarding: false,
|
|
414
|
+
paging: false, drafts: {}};
|
|
415
|
+
const changed = (cause = 'user') => { onChange(api, cause); return api; };
|
|
416
|
+
const arrived = () => changed('frame');
|
|
417
|
+
const place = (field, value) => st.principal && local.write(st.principal, field, value);
|
|
418
|
+
const can = name => !!source && typeof source[name] === 'function';
|
|
419
|
+
const ask = (name, request) => { if (can(name)) try { source[name](request); } catch {} };
|
|
420
|
+
const loadThread = thread => ask('readThread', {v: 1, thread});
|
|
421
|
+
|
|
422
|
+
function connect(next) {
|
|
423
|
+
if (st.cancel) try { st.cancel(); } catch {}
|
|
424
|
+
if (st.drop) st.drop(); // a send still waiting on the replaced source ends unknown and lets go of its lock
|
|
425
|
+
source = next || null;
|
|
426
|
+
Object.assign(st, {cancel: null, drop: null, inbox: fresh(), builds: fresh(), threads: new Map(), pending: null, paging: false});
|
|
427
|
+
const stream = ++st.stream;
|
|
428
|
+
if (source && typeof source.subscribe === 'function') {
|
|
429
|
+
const cancel = source.subscribe(frame => { if (stream === st.stream) receive(frame); });
|
|
430
|
+
if (stream === st.stream) st.cancel = typeof cancel === 'function' ? cancel : null;
|
|
431
|
+
else if (typeof cancel === 'function') try { cancel(); } catch {}
|
|
432
|
+
}
|
|
433
|
+
return arrived();
|
|
434
|
+
}
|
|
435
|
+
function adopt(principal) {
|
|
436
|
+
if (st.principal) local.purge(st.principal);
|
|
437
|
+
else if (!st.seenPrincipal) local.purgeOthers(principal);
|
|
438
|
+
st.seenPrincipal = true;
|
|
439
|
+
Object.assign(st, {principal, threads: new Map(), builds: fresh(), composer: null, pending: null, discarding: false, paging: false,
|
|
440
|
+
uncertain: savedRequest(local.read(principal, 'outgoing')),
|
|
441
|
+
selection: {inbox: null, schedule: null, results: null}, notice: ''});
|
|
442
|
+
const view = local.read(principal, 'view'), filter = local.read(principal, 'filter'), drafts = local.read(principal, 'drafts');
|
|
443
|
+
st.view = VIEWS.includes(view) ? view : 'needs_you';
|
|
444
|
+
st.filter = filter && typeof filter === 'object' ? {workspace: isId(filter.workspace) ? filter.workspace : null,
|
|
445
|
+
peer: has(PEER_FILTERS, filter.peer) ? filter.peer : 'all', text: typeof filter.text === 'string' ? filter.text : ''}
|
|
446
|
+
: {workspace: null, peer: 'all', text: ''};
|
|
447
|
+
st.drafts = drafts && typeof drafts === 'object' ? drafts : {};
|
|
448
|
+
const saved = local.read(principal, 'selection');
|
|
449
|
+
if (saved && has(st.selection, saved.tab) && isId(saved.id)) st.selection[saved.tab] = saved.id;
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
452
|
+
function receive(frame) {
|
|
453
|
+
if (!frame || typeof frame !== 'object') return;
|
|
454
|
+
if (frame.frame === 'inbox') return inbox(frame.body);
|
|
455
|
+
if (frame.frame === 'thread') return thread(frame.body);
|
|
456
|
+
if (frame.frame === 'builds') return builds(frame.body);
|
|
457
|
+
if (frame.frame === 'refused') return refused(frame.section, frame.body || {});
|
|
458
|
+
}
|
|
459
|
+
function inbox(body) {
|
|
460
|
+
let doc;
|
|
461
|
+
try { doc = decodeInbox(body); } catch (error) {
|
|
462
|
+
if (!(error instanceof InboxError)) throw error;
|
|
463
|
+
if (st.inbox.doc) Object.assign(st.inbox, {stale: true, reason: error.message});
|
|
464
|
+
else Object.assign(st.inbox, {state: 'malformed', reason: error.message});
|
|
465
|
+
return arrived();
|
|
466
|
+
}
|
|
467
|
+
const adopted = doc.principal_id !== st.principal && adopt(doc.principal_id);
|
|
468
|
+
if (!adopted && st.inbox.doc && doc.revision < st.inbox.doc.revision) return api; // an older answer never refills
|
|
469
|
+
const paged = st.paging, restored = adopted && {...st.selection};
|
|
470
|
+
st.paging = false;
|
|
471
|
+
st.inbox = {state: 'ready', doc, reason: '', stale: false};
|
|
472
|
+
for (const id of [...st.threads.keys()]) if (!doc.rows.some(row => row.thread === id)) st.threads.delete(id);
|
|
473
|
+
const linked = follow('inbox', doc.rows.map(row => row.thread), paged);
|
|
474
|
+
// a selection restored on this device opens its record: its entries are asked for, as a tap would
|
|
475
|
+
if (restored) for (const key of ['inbox', 'schedule']) if (restored[key] && restored[key] !== linked && st.selection[key] === restored[key]) loadThread(restored[key]);
|
|
476
|
+
return arrived();
|
|
477
|
+
}
|
|
478
|
+
function thread(body) {
|
|
479
|
+
let doc;
|
|
480
|
+
try { doc = decodeThread(body); } catch (error) { if (error instanceof InboxError) return api; throw error; }
|
|
481
|
+
if (!st.inbox.doc || !st.inbox.doc.rows.some(row => row.thread === doc.thread)) return api;
|
|
482
|
+
st.threads.set(doc.thread, doc);
|
|
483
|
+
return arrived();
|
|
484
|
+
}
|
|
485
|
+
function builds(body) {
|
|
486
|
+
let doc, records;
|
|
487
|
+
try { doc = decodeBuilds(body); records = buildRecords(doc); } catch (error) {
|
|
488
|
+
if (!(error instanceof InboxError)) throw error;
|
|
489
|
+
if (st.builds.doc) Object.assign(st.builds, {stale: true, reason: error.message});
|
|
490
|
+
else Object.assign(st.builds, {state: 'malformed', reason: error.message});
|
|
491
|
+
return arrived();
|
|
492
|
+
}
|
|
493
|
+
// an older panel never replaces a newer one (records.rs applies a panel at its revision)
|
|
494
|
+
if (st.builds.doc && Date.parse(doc.observed_at) < Date.parse(st.builds.doc.observed_at)) return api;
|
|
495
|
+
st.builds = {state: 'ready', doc, records, reason: '', stale: false};
|
|
496
|
+
follow('results', records.map(r => r.id));
|
|
497
|
+
return arrived();
|
|
498
|
+
}
|
|
499
|
+
function refused(section, {code = '', reason = ''}) {
|
|
500
|
+
const key = section === 'builds' ? 'builds' : 'inbox';
|
|
501
|
+
const words = reason || code || 'refused';
|
|
502
|
+
if (code === 'denied' || code === 'unauthorized') {
|
|
503
|
+
st[key] = {state: 'denied', doc: null, records: [], reason: words, stale: false};
|
|
504
|
+
if (key === 'inbox') Object.assign(st, {threads: new Map(), composer: null, pending: null});
|
|
505
|
+
st.selection[key === 'builds' ? 'results' : 'inbox'] = null;
|
|
506
|
+
if (key === 'inbox') st.selection.schedule = null;
|
|
507
|
+
} else if (st[key].doc) Object.assign(st[key], {stale: true, reason: words});
|
|
508
|
+
else Object.assign(st[key], {state: 'refused', reason: words});
|
|
509
|
+
return arrived();
|
|
510
|
+
}
|
|
511
|
+
// A link opens its record once the owner lists it (the record is shown, selected and, for a thread, its entries
|
|
512
|
+
// asked for); a selection whose record left the list goes, said unless the person paged away from it.
|
|
513
|
+
function follow(tab, ids, quiet = false) {
|
|
514
|
+
let linked = null;
|
|
515
|
+
const wanted = st.link && (st.link.tab === tab || (tab === 'inbox' && st.link.tab === 'schedule')) ? st.link : null;
|
|
516
|
+
if (wanted && ids.includes(wanted.id)) {
|
|
517
|
+
st.link = null;
|
|
518
|
+
if (tab === 'results') st.selection.results = wanted.id;
|
|
519
|
+
else if (reveal(wanted.tab, rowOf(wanted.id))) {
|
|
520
|
+
st.selection[wanted.tab] = linked = wanted.id;
|
|
521
|
+
place('selection', {tab: wanted.tab, id: linked});
|
|
522
|
+
loadThread(linked);
|
|
523
|
+
} else st.notice = NOTES.not_here;
|
|
524
|
+
} else if (wanted && complete(tab)) {
|
|
525
|
+
st.notice = NOTES.not_here;
|
|
526
|
+
st.link = null;
|
|
527
|
+
}
|
|
528
|
+
for (const key of tab === 'inbox' ? ['inbox', 'schedule'] : ['results']) {
|
|
529
|
+
const id = st.selection[key];
|
|
530
|
+
if (id && !ids.includes(id)) {
|
|
531
|
+
if (!quiet) st.notice = `This record is no longer listed (${id}).`;
|
|
532
|
+
st.selection[key] = null;
|
|
533
|
+
if (st.composer && st.composer.thread === id) st.composer = null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return linked;
|
|
537
|
+
}
|
|
538
|
+
// A linked thread is drawn: in the view that holds it (Scheduled only, for #schedule), with a filter that hid it
|
|
539
|
+
// cleared, and said. A #schedule link to a thread that is not scheduled names nothing here.
|
|
540
|
+
function reveal(tab, row) {
|
|
541
|
+
const here = view => inView(row, view, st.inbox.doc.as_of_unix_ms);
|
|
542
|
+
const view = tab === 'schedule' ? here('scheduled') && st.view : here(st.view) ? st.view : VIEWS.find(here);
|
|
543
|
+
if (!view) return false;
|
|
544
|
+
if (view !== st.view) { st.view = view; place('view', view); }
|
|
545
|
+
if (!admits(row, st.filter)) { st.filter = {workspace: null, peer: 'all', text: ''}; place('filter', st.filter); st.notice = NOTES.filter_cleared; }
|
|
546
|
+
return true;
|
|
547
|
+
}
|
|
548
|
+
const complete = tab => (tab === 'results' ? !!st.builds.doc && st.builds.doc.completeness.complete
|
|
549
|
+
: !!st.inbox.doc && st.inbox.doc.completeness === 'complete' && !st.inbox.stale);
|
|
550
|
+
const rowOf = id => st.inbox.doc && st.inbox.doc.rows.find(row => row.thread === id);
|
|
551
|
+
|
|
552
|
+
function open(link) {
|
|
553
|
+
st.tab = link.tab;
|
|
554
|
+
st.notice = link.invalid ? 'That link names no record' : '';
|
|
555
|
+
if (link.id) {
|
|
556
|
+
st.link = link;
|
|
557
|
+
if (link.tab === 'results' && st.builds.records) follow('results', st.builds.records.map(r => r.id));
|
|
558
|
+
else if (link.tab !== 'results' && st.inbox.doc) follow('inbox', st.inbox.doc.rows.map(row => row.thread));
|
|
559
|
+
}
|
|
560
|
+
return changed();
|
|
561
|
+
}
|
|
562
|
+
function select(tab, id) {
|
|
563
|
+
st.notice = '';
|
|
564
|
+
st.selection[tab] = st.selection[tab] === id ? null : id;
|
|
565
|
+
if (st.composer && st.composer.thread !== st.selection[tab]) release(true);
|
|
566
|
+
if (tab !== 'results') place('selection', st.selection[tab] ? {tab, id} : null);
|
|
567
|
+
if (st.selection[tab] && tab !== 'results') loadThread(id);
|
|
568
|
+
return changed();
|
|
569
|
+
}
|
|
570
|
+
function setView(view) {
|
|
571
|
+
if (!VIEWS.includes(view)) return api;
|
|
572
|
+
st.view = view;
|
|
573
|
+
place('view', view);
|
|
574
|
+
return changed();
|
|
575
|
+
}
|
|
576
|
+
function setFilter(patch) {
|
|
577
|
+
st.filter = {...st.filter, ...patch};
|
|
578
|
+
place('filter', st.filter);
|
|
579
|
+
return changed();
|
|
580
|
+
}
|
|
581
|
+
// The terminal's `n` (InboxPageRequest{after}) and `e` (InboxThreadRequest{before}): the owner's token, passed through;
|
|
582
|
+
// its answer replaces the page shown.
|
|
583
|
+
function pageControl() {
|
|
584
|
+
const doc = st.inbox.doc;
|
|
585
|
+
if (!doc || (doc.next_page == null && !doc.omitted)) return null;
|
|
586
|
+
const request = doc.next_page == null ? {v: 1} : {v: 1, after: doc.next_page};
|
|
587
|
+
return {label: request.after ? 'Next page' : 'First page', request, available: can('readPage'),
|
|
588
|
+
reason: can('readPage') ? null : REASONS.page_read_absent};
|
|
589
|
+
}
|
|
590
|
+
function nextPage() {
|
|
591
|
+
const page = pageControl();
|
|
592
|
+
if (!page || !page.available) { st.notice = page ? page.reason : 'Every thread is on this page.'; return changed(); }
|
|
593
|
+
st.paging = true;
|
|
594
|
+
st.notice = page.request.after ? 'Loading the next page.' : 'Loading the first page.';
|
|
595
|
+
ask('readPage', page.request);
|
|
596
|
+
return changed();
|
|
597
|
+
}
|
|
598
|
+
function earlier(id) {
|
|
599
|
+
const held = st.threads.get(id);
|
|
600
|
+
if (!held || held.earlier_page == null) return api;
|
|
601
|
+
if (!can('readThread')) { st.notice = REASONS.page_read_absent; return changed(); }
|
|
602
|
+
st.notice = 'Loading earlier entries.';
|
|
603
|
+
ask('readThread', {v: 1, thread: id, before: held.earlier_page});
|
|
604
|
+
return changed();
|
|
605
|
+
}
|
|
606
|
+
function availability(action, row = null) {
|
|
607
|
+
const no = (code, reason = REASONS[code]) => ({available: false, code, reason});
|
|
608
|
+
if (action === AFTER_TURN) return no(AFTER_TURN, AFTER_TURN_REASON);
|
|
609
|
+
if (!source || typeof source.send !== 'function') return no('not_connected');
|
|
610
|
+
if (st.inbox.state !== 'ready' || st.inbox.stale) return no('stale_snapshot');
|
|
611
|
+
if (row && row.peer_traffic && action === SEND_NOW) return no('peer_traffic_read_only');
|
|
612
|
+
const offered = st.inbox.doc.actions.find(a => a.action === action);
|
|
613
|
+
if (!offered && action === SEND_NOW) return no('not_offered', 'The owner has not offered Send now');
|
|
614
|
+
if (offered && offered.availability !== 'available') return no(offered.availability, offered.reason);
|
|
615
|
+
return {available: true, code: null, reason: null};
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function reply(id) {
|
|
619
|
+
const row = rowOf(id);
|
|
620
|
+
if (!row) return api;
|
|
621
|
+
if (row.peer_traffic) { st.notice = PEER_READ_ONLY; return changed(); }
|
|
622
|
+
st.composer = {thread: id, to: row.peer, text: typeof st.drafts[id] === 'string' ? st.drafts[id] : '', owned: false,
|
|
623
|
+
reviewing: false};
|
|
624
|
+
st.notice = '';
|
|
625
|
+
return changed();
|
|
626
|
+
}
|
|
627
|
+
function own() {
|
|
628
|
+
if (!st.composer || st.composer.reviewing) return api;
|
|
629
|
+
st.composer.owned = true;
|
|
630
|
+
return changed();
|
|
631
|
+
}
|
|
632
|
+
function release(quiet = false) {
|
|
633
|
+
if (st.composer) st.composer.owned = false;
|
|
634
|
+
return quiet ? api : changed();
|
|
635
|
+
}
|
|
636
|
+
function edit(text) {
|
|
637
|
+
const c = st.composer;
|
|
638
|
+
if (!c || !c.owned || typeof text !== 'string') return false;
|
|
639
|
+
c.text = text.replace(/\r\n?/g, '\n');
|
|
640
|
+
const drafts = {...st.drafts};
|
|
641
|
+
delete drafts[c.thread];
|
|
642
|
+
if (c.text) drafts[c.thread] = c.text;
|
|
643
|
+
const kept = Object.keys(drafts);
|
|
644
|
+
for (const old of kept.slice(0, Math.max(0, kept.length - DRAFTS_MAX))) delete drafts[old];
|
|
645
|
+
st.drafts = drafts;
|
|
646
|
+
place('drafts', drafts);
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
function review() {
|
|
650
|
+
const c = st.composer;
|
|
651
|
+
if (!c) return api;
|
|
652
|
+
if (!c.text.trim()) st.notice = 'The message is empty; nothing to review.';
|
|
653
|
+
else if (bytes(c.text) > TEXT_MAX) st.notice = `The message is longer than ${TEXT_MAX} bytes; shorten it to send.`;
|
|
654
|
+
else if (CONTROL.test(c.text)) st.notice = 'The message holds a control character the owner refuses; remove it to send.';
|
|
655
|
+
else {
|
|
656
|
+
Object.assign(c, {reviewing: true, owned: false});
|
|
657
|
+
st.notice = '';
|
|
658
|
+
}
|
|
659
|
+
return changed();
|
|
660
|
+
}
|
|
661
|
+
function back() {
|
|
662
|
+
if (st.composer) st.composer.reviewing = false;
|
|
663
|
+
return changed();
|
|
664
|
+
}
|
|
665
|
+
function cancelCompose() {
|
|
666
|
+
st.composer = null;
|
|
667
|
+
return changed();
|
|
668
|
+
}
|
|
669
|
+
async function sendNow() {
|
|
670
|
+
const c = st.composer, row = c && rowOf(c.thread);
|
|
671
|
+
if (!c || !c.reviewing || !row || st.pending) return api;
|
|
672
|
+
const able = availability(SEND_NOW, row);
|
|
673
|
+
if (!able.available) { st.notice = able.reason; return changed(); }
|
|
674
|
+
return answer({kind: 'inbox_compose', body: composeCommand({operation_id: mint(), to: c.to, text: c.text, reply_to: c.thread})});
|
|
675
|
+
}
|
|
676
|
+
async function act(id, action) {
|
|
677
|
+
const row = rowOf(id);
|
|
678
|
+
if (!row || !THREAD_ACTIONS.some(([name]) => name === action) || st.pending) return api;
|
|
679
|
+
const able = availability(action, row);
|
|
680
|
+
if (!able.available) { st.notice = able.reason; return changed(); }
|
|
681
|
+
return answer({kind: 'inbox_thread', body: threadCommand(row, action, now(), mint())});
|
|
682
|
+
}
|
|
683
|
+
// Retry sends the retained command unchanged, whether or not its thread is still listed.
|
|
684
|
+
function retry() {
|
|
685
|
+
if (st.pending) return api;
|
|
686
|
+
if (!can('send')) { st.notice = REASONS.not_connected; return changed(); }
|
|
687
|
+
return answer(null);
|
|
688
|
+
}
|
|
689
|
+
// Discarding asks first: it forgets the one duplicate guard the owner has for that command.
|
|
690
|
+
function discard(confirmed = false) {
|
|
691
|
+
if (!st.uncertain || st.pending) return api;
|
|
692
|
+
if (!confirmed) {
|
|
693
|
+
const slot = local.slot(st.principal);
|
|
694
|
+
st.uncertain = savedRequest(slot.value);
|
|
695
|
+
st.discarding = slot.raw !== undefined && slot.raw !== null && slot;
|
|
696
|
+
st.notice = st.discarding ? NOTES.discard : 'The retained command could not be read; nothing was discarded.';
|
|
697
|
+
return changed();
|
|
698
|
+
}
|
|
699
|
+
if (!st.discarding) return api;
|
|
700
|
+
const expected = st.discarding.raw;
|
|
701
|
+
st.discarding = false;
|
|
702
|
+
return locked(() => {
|
|
703
|
+
// BEY-7130: confirmation names one exact slot, including malformed JSON.
|
|
704
|
+
const current = local.slot(st.principal);
|
|
705
|
+
if (current.raw === undefined || current.raw !== expected) {
|
|
706
|
+
st.uncertain = savedRequest(current.value);
|
|
707
|
+
st.notice = 'The retained command changed or cannot be read. Nothing was discarded; review it again.';
|
|
708
|
+
return changed();
|
|
709
|
+
}
|
|
710
|
+
if (place('outgoing', null)) Object.assign(st, {uncertain: null, notice: 'Discarded on this device; nothing was resent.'});
|
|
711
|
+
else st.notice = 'The retained command could not be removed from this device.';
|
|
712
|
+
return changed();
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
function keepRetained() {
|
|
716
|
+
st.discarding = false;
|
|
717
|
+
st.notice = '';
|
|
718
|
+
return changed();
|
|
719
|
+
}
|
|
720
|
+
function landed({kind, body}) {
|
|
721
|
+
if (kind !== 'inbox_compose') return 'Done: the next inbox snapshot shows it.';
|
|
722
|
+
const drafts = {...st.drafts};
|
|
723
|
+
if (drafts[body.reply_to] === body.text) delete drafts[body.reply_to];
|
|
724
|
+
st.drafts = drafts;
|
|
725
|
+
place('drafts', drafts);
|
|
726
|
+
if (st.composer?.thread === body.reply_to && st.composer.text === body.text) st.composer = null;
|
|
727
|
+
return `Sent to custody: the owner took the message (operation ${body.operation_id}). Delivery is shown on the thread.`;
|
|
728
|
+
}
|
|
729
|
+
async function locked(work) {
|
|
730
|
+
const principal = st.principal, stream = st.stream;
|
|
731
|
+
if (!locks || typeof locks.request !== 'function') {
|
|
732
|
+
st.notice = 'Safe retry storage is unavailable in this browser; nothing was sent.';
|
|
733
|
+
return changed();
|
|
734
|
+
}
|
|
735
|
+
try {
|
|
736
|
+
return await locks.request(PREFIX + encodeURIComponent(principal) + ':outgoing', {ifAvailable: true}, async lock => {
|
|
737
|
+
if (principal !== st.principal || stream !== st.stream) return api;
|
|
738
|
+
if (!lock) { st.notice = 'Another tab is sending; wait for its outcome before retrying.'; return changed(); }
|
|
739
|
+
return work(principal, stream);
|
|
740
|
+
});
|
|
741
|
+
} catch {
|
|
742
|
+
st.notice = 'Retry storage could not be locked; no outcome was confirmed.';
|
|
743
|
+
return changed();
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
const answer = request => locked((principal, stream) => dispatch(request, principal, stream));
|
|
747
|
+
async function dispatch(request, principal, stream) {
|
|
748
|
+
const held = st.uncertain = savedRequest(local.read(principal, 'outgoing'));
|
|
749
|
+
if (!request && (!held || held.invalid)) { st.notice = held ? REASONS.unreadable : 'No command is waiting for an outcome.'; return changed(); }
|
|
750
|
+
if (request && held && (held.invalid || !sameIntent(held, request))) {
|
|
751
|
+
st.notice = 'An earlier command has an unknown outcome. Retry that command before starting another.';
|
|
752
|
+
return changed();
|
|
753
|
+
}
|
|
754
|
+
request = held || request;
|
|
755
|
+
if (!place('outgoing', request)) {
|
|
756
|
+
st.notice = 'Cannot retain the retry identity on this device; nothing was sent.';
|
|
757
|
+
return changed();
|
|
758
|
+
}
|
|
759
|
+
st.uncertain = request;
|
|
760
|
+
st.pending = request;
|
|
761
|
+
changed();
|
|
762
|
+
let reply;
|
|
763
|
+
try { reply = await Promise.race([source.send(request), new Promise(resolve => { st.drop = resolve; })]); } catch {}
|
|
764
|
+
st.drop = null;
|
|
765
|
+
if (st.pending === request) st.pending = null;
|
|
766
|
+
if (principal !== st.principal || stream !== st.stream) return arrived();
|
|
767
|
+
if (reply && ['receipt', 'refused'].includes(reply.frame)) {
|
|
768
|
+
if (place('outgoing', null)) st.uncertain = null;
|
|
769
|
+
st.notice = reply.frame === 'receipt' ? landed(request) : `The owner refused it: ${(reply.body && (reply.body.reason || reply.body.code)) || 'no reason given'}`;
|
|
770
|
+
} else st.notice = `Outcome unknown: the owner may have accepted operation ${request.body.operation_id}. Retry uses that same operation; no refusal was received.`;
|
|
771
|
+
return arrived();
|
|
772
|
+
}
|
|
773
|
+
function unresolved() {
|
|
774
|
+
const u = st.uncertain, lookup = {available: false, code: 'outcome_lookup_absent', reason: REASONS.outcome_lookup_absent};
|
|
775
|
+
if (!u || st.pending) return null; // in flight from this page: not unknown yet
|
|
776
|
+
if (u.invalid) return {invalid: true, discarding: !!st.discarding, retry: {available: false, reason: REASONS.unreadable}, lookup};
|
|
777
|
+
const b = u.body, text = b.text && b.text.replace(/\s+/g, ' ');
|
|
778
|
+
const what = u.kind === 'inbox_compose' ? `message to ${b.to}${b.reply_to ? ` in ${b.reply_to}` : ''}: "${text.length > 60 ? `${text.slice(0, 60)}…` : text}"`
|
|
779
|
+
: `${ACTION_WORDS[b.action]} on ${b.thread}`;
|
|
780
|
+
return {invalid: false, kind: u.kind, operation_id: b.operation_id, what, discarding: !!st.discarding, lookup,
|
|
781
|
+
retry: can('send') ? {available: true, reason: null} : {available: false, reason: REASONS.not_connected}};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function view() {
|
|
785
|
+
const doc = st.inbox.doc, filter = st.filter, b = st.builds.doc;
|
|
786
|
+
const counts = Object.fromEntries(VIEWS.map(v => [v, doc ? visible(doc, v, filter).length : 0]));
|
|
787
|
+
const selected = st.selection[st.tab], page = pageControl();
|
|
788
|
+
return {
|
|
789
|
+
tab: st.tab, notice: st.notice, connected: !!source, principal: st.principal, pending: !!st.pending,
|
|
790
|
+
reads: {thread: can('readThread'), page: can('readPage')}, uncertain: unresolved(),
|
|
791
|
+
inbox: {state: st.inbox.state, stale: st.inbox.stale, reason: st.inbox.reason, view: st.view, filter, counts,
|
|
792
|
+
rows: doc ? visible(doc, st.view, filter) : [], asOf: doc ? doc.as_of_unix_ms : 0,
|
|
793
|
+
workspaces: doc ? [...new Set(doc.rows.map(row => row.workspace_id))].sort() : [],
|
|
794
|
+
incomplete: !!doc && doc.completeness !== 'complete', omitted: doc ? doc.omitted : 0,
|
|
795
|
+
omittedByView: doc ? doc.omitted_by_view : {}, page: page && {label: page.label, available: page.available, reason: page.reason}},
|
|
796
|
+
schedule: {unavailable: SCHEDULE_UNAVAILABLE, rows: doc ? visible(doc, 'scheduled', filter) : []},
|
|
797
|
+
results: {state: st.builds.state, stale: st.builds.stale, reason: st.builds.reason, records: st.builds.records || [],
|
|
798
|
+
header: b ? buildsHeader(b) : [], waits: b ? b.lane_waits.map(laneWait) : [], resources: b ? b.resources : []},
|
|
799
|
+
selected, thread: selected && st.tab !== 'results' ? st.threads.get(selected) || null : null,
|
|
800
|
+
row: selected && st.tab !== 'results' ? rowOf(selected) || null : null,
|
|
801
|
+
composer: st.composer && {...st.composer}, after: availability(AFTER_TURN),
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
const api = {connect, receive, open, select, setView, setFilter, nextPage, earlier, reply, own, release, edit, review, back,
|
|
805
|
+
cancelCompose, sendNow, act, retry, discard, keepRetained, availability, view, link: (tab, id) => linkFor(tab, id),
|
|
806
|
+
scroll: () => (st.principal && local.read(st.principal, 'scroll')) || 0, setScroll: px => place('scroll', Math.max(0, Math.round(px) || 0))};
|
|
807
|
+
if (source) connect(source);
|
|
808
|
+
return api;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// Draws the view into `root` and returns the drawn controls by their `data-focus` key, so the page can keep the
|
|
812
|
+
// keyboard on the same control across a redraw. The reply field has no key: nothing focuses it.
|
|
813
|
+
function renderInbox(doc, root, v, ui, keep = {}) {
|
|
814
|
+
const focus = new Map();
|
|
815
|
+
const el = (tag, cls, text) => {
|
|
816
|
+
const node = doc.createElement(tag);
|
|
817
|
+
if (cls) node.className = cls;
|
|
818
|
+
if (text !== undefined) node.textContent = text;
|
|
819
|
+
return node;
|
|
820
|
+
};
|
|
821
|
+
const keyed = (node, key) => { node.setAttribute('data-focus', key); focus.set(key, node); return node; };
|
|
822
|
+
const btn = (cls, text, label, action, disabled = null, key = text) => {
|
|
823
|
+
const b = keyed(el('button', cls, text), key);
|
|
824
|
+
b.type = 'button';
|
|
825
|
+
if (label) b.setAttribute('aria-label', label);
|
|
826
|
+
b.addEventListener('click', action);
|
|
827
|
+
if (disabled != null) { b.disabled = true; b.setAttribute('title', disabled); }
|
|
828
|
+
return b;
|
|
829
|
+
};
|
|
830
|
+
const say = (cls, text) => { const p = el('p', cls, text); p.setAttribute('role', 'status'); return p; };
|
|
831
|
+
const parts = [];
|
|
832
|
+
const head = el('header', 'lanes-directory-head');
|
|
833
|
+
const title = el('h2', '', TABS[v.tab]);
|
|
834
|
+
title.id = 'lanes-ops-title';
|
|
835
|
+
const count = el('p', 'lanes-directory-count');
|
|
836
|
+
if (v.tab === 'inbox' && v.inbox.state === 'ready') count.textContent = `${VIEW_TITLES[v.inbox.view]} ${v.inbox.counts[v.inbox.view]} · ${v.inbox.counts.needs_you} need you`;
|
|
837
|
+
if (v.tab === 'results' && v.results.state === 'ready') count.textContent = `${v.results.records.length} records`;
|
|
838
|
+
head.append(title, count, btn('lanes-directory-close', '×', 'Close', () => ui.close(), null, 'close'));
|
|
839
|
+
const tabs = el('nav', 'lanes-ops-tabs');
|
|
840
|
+
tabs.setAttribute('aria-label', 'Operations');
|
|
841
|
+
for (const [tab, name] of Object.entries(TABS)) {
|
|
842
|
+
const b = btn('lanes-directory-toggle lanes-ops-tab', name, '', () => ui.go(tab), null, `tab:${tab}`);
|
|
843
|
+
b.setAttribute('aria-pressed', String(tab === v.tab));
|
|
844
|
+
tabs.append(b);
|
|
845
|
+
}
|
|
846
|
+
parts.push(head, tabs);
|
|
847
|
+
if (v.notice) parts.push(say('lanes-directory-notice', v.notice));
|
|
848
|
+
const list = el('div', 'lanes-directory-list');
|
|
849
|
+
list.setAttribute('role', 'list');
|
|
850
|
+
list.setAttribute('aria-labelledby', 'lanes-ops-title');
|
|
851
|
+
const STATES = {
|
|
852
|
+
unavailable: 'Not connected: this host does not serve the inbox to the browser yet.',
|
|
853
|
+
loading: 'Loading: no answer from the source yet.',
|
|
854
|
+
malformed: `The inbox could not be read: ${v.inbox.reason}. Nothing was changed.`,
|
|
855
|
+
refused: `The host refused the inbox: ${v.inbox.reason}`, denied: `Not permitted to read this: ${v.inbox.reason}.`,
|
|
856
|
+
};
|
|
857
|
+
// The one command whose outcome is unknown: what it is, Retry (unchanged), the outcome lookup (unavailable, with its
|
|
858
|
+
// code, until E7 serves one) and an explicit, confirmed discard.
|
|
859
|
+
const unresolved = u => {
|
|
860
|
+
if (!u) return;
|
|
861
|
+
const box = el('div', 'lanes-directory-detail');
|
|
862
|
+
box.append(say('lanes-directory-notice is-stale', u.invalid ? REASONS.unreadable
|
|
863
|
+
: `Outcome unknown: ${u.what} (operation ${u.operation_id}). Retry sends it unchanged; no other command is sent until it is resolved.`));
|
|
864
|
+
const actions = el('div', 'lanes-directory-actions');
|
|
865
|
+
actions.append(btn('lanes-directory-act is-retry', 'Retry unchanged', 'Retry the retained command unchanged', () => ui.retry(), u.retry.available ? null : u.retry.reason, 'retry'),
|
|
866
|
+
btn('lanes-directory-act is-lookup', 'Look up outcome', 'Look up the outcome by its operation id', () => {}, u.lookup.reason, 'lookup'));
|
|
867
|
+
if (u.discarding) {
|
|
868
|
+
actions.append(btn('lanes-directory-act is-discard', 'Confirm discard', NOTES.discard, () => ui.discard(true), null, 'confirm'),
|
|
869
|
+
btn('lanes-directory-act', 'Keep', 'Keep the retained command', () => ui.keepRetained(), null, 'keep'));
|
|
870
|
+
} else actions.append(btn('lanes-directory-act is-discard', 'Discard…', 'Discard the retained command (it may duplicate)', () => ui.discard(), null, 'discard'));
|
|
871
|
+
actions.append(el('small', 'lanes-directory-reason', u.lookup.reason));
|
|
872
|
+
box.append(actions);
|
|
873
|
+
parts.push(box);
|
|
874
|
+
};
|
|
875
|
+
const inboxState = () => {
|
|
876
|
+
if (v.inbox.state !== 'ready') { parts.push(say(`lanes-directory-empty is-${v.inbox.state}`, STATES[v.inbox.state])); return false; }
|
|
877
|
+
if (v.inbox.stale) parts.push(say('lanes-directory-notice is-stale', `The latest update could not be read (${v.inbox.reason}): showing the last good snapshot, marked stale.`));
|
|
878
|
+
if (v.inbox.incomplete) parts.push(say('lanes-directory-notice is-stale', `Some threads are not listed${v.inbox.omitted ? ` (${v.inbox.omitted} left out)` : ''}; counts cover the listed threads.`));
|
|
879
|
+
return true;
|
|
880
|
+
};
|
|
881
|
+
const filters = () => {
|
|
882
|
+
const bar = el('div', 'lanes-directory-filter');
|
|
883
|
+
const pick = (label, options, current, apply) => {
|
|
884
|
+
const s = keyed(el('select', 'lanes-directory-pick'), `pick:${label}`);
|
|
885
|
+
s.setAttribute('aria-label', label);
|
|
886
|
+
for (const [value, text] of options) {
|
|
887
|
+
const o = el('option', '', text);
|
|
888
|
+
o.value = value;
|
|
889
|
+
o.selected = value === current;
|
|
890
|
+
s.append(o);
|
|
891
|
+
}
|
|
892
|
+
s.addEventListener('change', () => apply(s.value));
|
|
893
|
+
bar.append(s);
|
|
894
|
+
};
|
|
895
|
+
pick('Workspace', [['', 'All workspaces'], ...v.inbox.workspaces.map(w => [w, w])], v.inbox.filter.workspace || '',
|
|
896
|
+
value => ui.setFilter({workspace: value || null}));
|
|
897
|
+
pick('Peer traffic', Object.entries(PEER_FILTERS), v.inbox.filter.peer, value => ui.setFilter({peer: value}));
|
|
898
|
+
const filtered = v.inbox.filter.workspace || v.inbox.filter.peer !== 'all' || v.inbox.filter.text;
|
|
899
|
+
if (filtered) bar.append(btn('lanes-directory-clear', 'Clear filter', 'Clear the filter', () => ui.setFilter({workspace: null, peer: 'all', text: ''})));
|
|
900
|
+
parts.push(bar);
|
|
901
|
+
};
|
|
902
|
+
const pager = () => {
|
|
903
|
+
const page = v.inbox.page;
|
|
904
|
+
if (page) parts.push(btn('lanes-directory-act is-page', page.label, `${page.label} of the inbox`, () => ui.nextPage(), page.available ? null : page.reason, 'page'));
|
|
905
|
+
};
|
|
906
|
+
const threadRow = row => {
|
|
907
|
+
const item = el('div', `lanes-directory-row${row.thread === v.selected ? ' is-selected' : ''}`);
|
|
908
|
+
item.setAttribute('role', 'listitem');
|
|
909
|
+
item.setAttribute('data-record', row.thread);
|
|
910
|
+
if (row.attention != null || (row.latest && row.latest.delivery_state === 'uncertain')) item.setAttribute('data-tone', 'tone-attention');
|
|
911
|
+
const pick = btn('lanes-directory-pick-row', '', rowWords(row, v.inbox.asOf), () => ui.select(v.tab, row.thread), null, `row:${row.thread}`);
|
|
912
|
+
if (row.thread === v.selected) pick.setAttribute('aria-current', 'true');
|
|
913
|
+
pick.append(el('span', 'lanes-directory-glyph', row.unread ? String(row.unread) : ' '), el('span', 'lanes-directory-name', row.subject),
|
|
914
|
+
el('span', 'lanes-directory-state', row.latest ? LABELS[row.latest.delivery_state] : NO_MESSAGES),
|
|
915
|
+
el('span', 'lanes-directory-where', [row.workspace_id, ...rowWords(row, v.inbox.asOf).split(' · ').slice(2)].join(' · ')));
|
|
916
|
+
item.append(pick);
|
|
917
|
+
if (row.thread === v.selected) item.append(threadDetail(row));
|
|
918
|
+
return item;
|
|
919
|
+
};
|
|
920
|
+
function threadDetail(row) {
|
|
921
|
+
const box = el('div', 'lanes-directory-detail');
|
|
922
|
+
box.append(el('p', 'lanes-directory-facts', `${row.thread} · ${row.peer} · ${row.workspace_id} · ${row.entries} entries`));
|
|
923
|
+
const link = keyed(el('a', 'lanes-directory-link', 'Link to this thread'), 'link');
|
|
924
|
+
link.href = ui.link(v.tab, row.thread);
|
|
925
|
+
box.append(link);
|
|
926
|
+
if (v.thread) {
|
|
927
|
+
if (v.thread.earlier_omitted) box.append(el('p', 'lanes-directory-facts', `${v.thread.earlier_omitted} earlier entries not shown`));
|
|
928
|
+
if (v.thread.earlier_page != null) {
|
|
929
|
+
box.append(btn('lanes-directory-act is-earlier', 'Load earlier entries', `Load earlier entries of ${row.subject}`, () => ui.earlier(row.thread),
|
|
930
|
+
v.reads.thread ? null : REASONS.page_read_absent, 'earlier'));
|
|
931
|
+
}
|
|
932
|
+
for (const e of v.thread.entries) {
|
|
933
|
+
const lines = [`${utcText(e.at_unix_ms)} · from @${e.from} (${e.from_kind}) to @${e.to} · ${LABELS[e.delivery_state]}`];
|
|
934
|
+
const owner = e.owner_evidence, lanes = e.lanes_evidence;
|
|
935
|
+
if (owner) lines.push(`owner witness: ${WITNESSES[owner.witness]}${owner.target_generation ? ` · offered to ${owner.target_generation}` : ''}`);
|
|
936
|
+
if (lanes) lines.push(`lanes attempt: ${CHANNELS[lanes.channel]} · bound to ${lanes.target_generation}${lanes.reached_generation ? ` · reached ${lanes.reached_generation}` : ''}`);
|
|
937
|
+
const entry = el('p', 'lanes-ops-body', `${lines.join('\n')}\n${e.text ?? EXPIRED_TEXT}`);
|
|
938
|
+
entry.setAttribute('data-message', e.message_id);
|
|
939
|
+
box.append(entry);
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
const latest = row.latest;
|
|
943
|
+
box.append(el('p', 'lanes-ops-body', !latest ? NO_MESSAGES : latest.preview ?? (latest.text_expired ? EXPIRED_TEXT : 'Entries are not loaded.')));
|
|
944
|
+
}
|
|
945
|
+
const actions = el('div', 'lanes-directory-actions');
|
|
946
|
+
for (const [action, text] of THREAD_ACTIONS) {
|
|
947
|
+
const a = ui.availability(action, row);
|
|
948
|
+
actions.append(btn(`lanes-directory-act is-${action}`, text, `${text}: ${row.subject}`, () => ui.act(row.thread, action), a.available ? null : a.reason));
|
|
949
|
+
}
|
|
950
|
+
const replying = v.composer && v.composer.thread === row.thread;
|
|
951
|
+
if (!replying) {
|
|
952
|
+
actions.append(btn('lanes-directory-act is-reply', 'Reply', `Reply to ${row.peer}`, () => ui.reply(row.thread), row.peer_traffic ? PEER_READ_ONLY : null));
|
|
953
|
+
}
|
|
954
|
+
box.append(actions);
|
|
955
|
+
if (replying) box.append(composer(row));
|
|
956
|
+
return box;
|
|
957
|
+
}
|
|
958
|
+
function composer(row) {
|
|
959
|
+
const c = v.composer, box = el('div', 'lanes-ops-composer');
|
|
960
|
+
box.append(el('p', 'lanes-directory-facts', `To ${c.to} · reply in ${c.thread}`));
|
|
961
|
+
const actions = el('div', 'lanes-directory-actions');
|
|
962
|
+
if (c.reviewing) {
|
|
963
|
+
box.append(el('p', 'lanes-ops-body', c.text));
|
|
964
|
+
const send = ui.availability(SEND_NOW, row);
|
|
965
|
+
actions.append(btn('lanes-directory-act is-send', v.pending ? 'Sending…' : 'Send now', `Send now to ${c.to}`, () => ui.sendNow(), send.available ? null : send.reason, 'send'),
|
|
966
|
+
btn('lanes-directory-act is-after-turn', 'After turn', 'Send after the recipient\'s turn', () => {}, v.after.reason),
|
|
967
|
+
btn('lanes-directory-act is-edit', 'Edit', 'Back to the text', () => ui.back()));
|
|
968
|
+
if (!send.available) actions.append(el('small', 'lanes-directory-reason', send.reason));
|
|
969
|
+
actions.append(el('small', 'lanes-directory-reason', v.after.reason));
|
|
970
|
+
} else {
|
|
971
|
+
const field = keep.field || (keep.field = el('textarea', 'lanes-ops-compose'));
|
|
972
|
+
field.readOnly = !c.owned;
|
|
973
|
+
field.setAttribute('aria-label', `Reply to ${c.to}`);
|
|
974
|
+
field.setAttribute('placeholder', c.owned ? 'Tap here and write' : 'Tap Type to write here');
|
|
975
|
+
if (field.value !== c.text && doc.activeElement !== field) field.value = c.text;
|
|
976
|
+
if (!keep.wired) {
|
|
977
|
+
keep.wired = true;
|
|
978
|
+
field.addEventListener('input', () => ui.edit(field.value));
|
|
979
|
+
// Escape here ends typing only; it does not also reach the dialog's Escape, which closes it
|
|
980
|
+
field.addEventListener('keydown', ev => { if (ev.key === 'Escape') { ev.stopPropagation(); ui.release(); } });
|
|
981
|
+
}
|
|
982
|
+
box.append(field);
|
|
983
|
+
actions.append(c.owned ? btn('lanes-directory-act is-type', 'Done typing', 'Stop typing here', () => ui.release(), null, 'type')
|
|
984
|
+
: btn('lanes-directory-act is-type', 'Type', 'Type a reply here', () => ui.own(), null, 'type'),
|
|
985
|
+
btn('lanes-directory-act is-review', 'Review', 'Review before sending', () => ui.review()),
|
|
986
|
+
btn('lanes-directory-act is-cancel', 'Cancel', 'Close the reply; the draft stays on this device', () => ui.cancelCompose()));
|
|
987
|
+
}
|
|
988
|
+
box.append(actions);
|
|
989
|
+
return box;
|
|
990
|
+
}
|
|
991
|
+
const empty = (text, cls = 'is-empty') => list.append(el('p', `lanes-directory-empty ${cls}`, text));
|
|
992
|
+
const facts = lines => { for (const line of lines) parts.push(el('p', 'lanes-directory-facts', line)); };
|
|
993
|
+
|
|
994
|
+
if (v.tab === 'inbox') {
|
|
995
|
+
unresolved(v.uncertain);
|
|
996
|
+
if (inboxState()) {
|
|
997
|
+
filters();
|
|
998
|
+
const views = el('nav', 'lanes-ops-views');
|
|
999
|
+
views.setAttribute('aria-label', 'Inbox views');
|
|
1000
|
+
for (const view of VIEWS) {
|
|
1001
|
+
const more = v.inbox.omittedByView[view] ? ` (+${v.inbox.omittedByView[view]} not shown)` : '';
|
|
1002
|
+
const b = btn('lanes-directory-toggle lanes-ops-view', `${VIEW_TITLES[view]} ${v.inbox.counts[view]}${more}`, '', () => ui.setView(view), null, `view:${view}`);
|
|
1003
|
+
b.setAttribute('aria-pressed', String(view === v.inbox.view));
|
|
1004
|
+
views.append(b);
|
|
1005
|
+
}
|
|
1006
|
+
parts.push(views);
|
|
1007
|
+
for (const row of v.inbox.rows) list.append(threadRow(row));
|
|
1008
|
+
if (!v.inbox.rows.length) empty(`Nothing in ${VIEW_TITLES[v.inbox.view]}${v.inbox.filter.workspace || v.inbox.filter.peer !== 'all' ? ' under this filter' : ''}.`);
|
|
1009
|
+
parts.push(list);
|
|
1010
|
+
pager();
|
|
1011
|
+
}
|
|
1012
|
+
} else if (v.tab === 'schedule') {
|
|
1013
|
+
parts.push(say('lanes-directory-notice is-unavailable', `Schedules and occurrences: unavailable (${v.schedule.unavailable.code}): ${v.schedule.unavailable.reason}.`));
|
|
1014
|
+
unresolved(v.uncertain);
|
|
1015
|
+
if (inboxState()) {
|
|
1016
|
+
filters();
|
|
1017
|
+
list.append(el('h3', 'lanes-directory-section', `Messages held for a trigger (${v.schedule.rows.length})`));
|
|
1018
|
+
for (const row of v.schedule.rows) list.append(threadRow(row));
|
|
1019
|
+
if (!v.schedule.rows.length) empty('No message is held for a trigger.');
|
|
1020
|
+
parts.push(list);
|
|
1021
|
+
pager();
|
|
1022
|
+
}
|
|
1023
|
+
} else {
|
|
1024
|
+
const r = v.results;
|
|
1025
|
+
const RESULT_STATES = {unavailable: 'Not connected: this host does not serve the builds panel to the browser yet.',
|
|
1026
|
+
loading: 'Loading: no answer from the source yet.', malformed: `The builds panel could not be read: ${r.reason}. Nothing was changed.`,
|
|
1027
|
+
refused: `The host refused the builds panel: ${r.reason}`, denied: `Not permitted to read this: ${r.reason}.`};
|
|
1028
|
+
if (r.state !== 'ready') parts.push(say(`lanes-directory-empty is-${r.state}`, RESULT_STATES[r.state]));
|
|
1029
|
+
else {
|
|
1030
|
+
if (r.stale) parts.push(say('lanes-directory-notice is-stale', `The latest update could not be read (${r.reason}): showing the last good panel, marked stale.`));
|
|
1031
|
+
facts(r.header);
|
|
1032
|
+
// records.rs: one line per lane waiting on a build (its detail on opening it), then the read-only resource lines
|
|
1033
|
+
for (const wait of r.waits) {
|
|
1034
|
+
const box = el('details', 'lanes-directory-facts');
|
|
1035
|
+
box.append(el('summary', '', wait.line));
|
|
1036
|
+
for (const line of wait.detail) box.append(el('p', 'lanes-directory-facts', line));
|
|
1037
|
+
parts.push(box);
|
|
1038
|
+
}
|
|
1039
|
+
facts(r.resources);
|
|
1040
|
+
for (const rec of r.records) {
|
|
1041
|
+
const item = el('div', `lanes-directory-row${rec.id === v.selected ? ' is-selected' : ''}`);
|
|
1042
|
+
item.setAttribute('role', 'listitem');
|
|
1043
|
+
item.setAttribute('data-record', rec.id);
|
|
1044
|
+
item.setAttribute('data-kind', rec.kind);
|
|
1045
|
+
const pick = btn('lanes-directory-pick-row', '', `${rec.kind}: ${rec.title}, ${rec.state}, ${rec.consequence}`, () => ui.select('results', rec.id), null, `row:${rec.id}`);
|
|
1046
|
+
pick.append(el('span', 'lanes-directory-glyph', ' '), el('span', 'lanes-directory-name', rec.title), el('span', 'lanes-directory-state', rec.state),
|
|
1047
|
+
el('span', 'lanes-directory-where', `${rec.kind} · ${rec.when} · ${rec.consequence}`));
|
|
1048
|
+
item.append(pick);
|
|
1049
|
+
if (rec.id === v.selected) {
|
|
1050
|
+
const box = el('div', 'lanes-directory-detail');
|
|
1051
|
+
for (const line of rec.lines) box.append(el('p', 'lanes-directory-facts', line));
|
|
1052
|
+
const link = keyed(el('a', 'lanes-directory-link', 'Link to this record'), 'link');
|
|
1053
|
+
link.href = ui.link('results', rec.id);
|
|
1054
|
+
box.append(link);
|
|
1055
|
+
item.append(box);
|
|
1056
|
+
}
|
|
1057
|
+
list.append(item);
|
|
1058
|
+
}
|
|
1059
|
+
if (!r.records.length) empty('No builds or results in the panel.');
|
|
1060
|
+
parts.push(list);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
root.replaceChildren(...parts);
|
|
1064
|
+
return focus;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
const api = {VIEWS, VIEW_TITLES, LABELS, ATTENTION, WAITING, PEER_FILTERS, AFTER_TURN_REASON, PEER_READ_ONLY, EXPIRED_TEXT, NO_MESSAGES,
|
|
1068
|
+
SCHEDULE_UNAVAILABLE, REASONS, NOTES, InboxError, deliveryState, evidenceProblem, rowProblem, inView, admits, visible, rowWords,
|
|
1069
|
+
decodeInbox, decodeThread, decodeBuilds, buildRecords, stateText, consequenceOf, ageText, parseLink, linkFor, deviceLocal,
|
|
1070
|
+
threadCommand, composeCommand, createInbox, renderInbox};
|
|
1071
|
+
if (typeof module === 'object' && module) module.exports = api;
|
|
1072
|
+
|
|
1073
|
+
const w = globalThis;
|
|
1074
|
+
if (!w.document || w.lanesInbox) return;
|
|
1075
|
+
const doc = w.document, mode = doc.documentElement.dataset.lanesShell || 'desktop';
|
|
1076
|
+
let storage = null;
|
|
1077
|
+
try { storage = w.localStorage; } catch {}
|
|
1078
|
+
doc.head.append(Object.assign(doc.createElement('link'), {rel: 'stylesheet', href: '/lanes-assets/directory.css'}),
|
|
1079
|
+
Object.assign(doc.createElement('style'), {textContent: '.lanes-ops-tabs, .lanes-ops-views { display: flex; flex-wrap: wrap; gap: 6px; }\n'
|
|
1080
|
+
+ '.lanes-ops-tab[aria-pressed="true"], .lanes-ops-view[aria-pressed="true"] { border-color: var(--lanes-accent); background: var(--lanes-accent-wash); }\n'
|
|
1081
|
+
+ '.lanes-ops-compose { box-sizing: border-box; width: 100%; min-height: 6em; padding: 8px; border: 1px solid var(--lanes-line); border-radius: 8px; background: var(--lanes-surface); color: var(--lanes-ink); font: 16px/1.35 system-ui, sans-serif; }\n'
|
|
1082
|
+
+ '.lanes-ops-compose[readonly] { color: var(--lanes-ink-dim); }\n'
|
|
1083
|
+
+ '.lanes-ops-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }\n'}));
|
|
1084
|
+
const root = Object.assign(doc.createElement('section'), {className: `lanes-directory lanes-directory-${mode} lanes-ops`, hidden: true});
|
|
1085
|
+
root.setAttribute('role', 'dialog');
|
|
1086
|
+
root.setAttribute('aria-modal', 'true');
|
|
1087
|
+
root.setAttribute('aria-labelledby', 'lanes-ops-title');
|
|
1088
|
+
doc.body.append(root);
|
|
1089
|
+
const keep = {};
|
|
1090
|
+
let drawn = new Map();
|
|
1091
|
+
const list = () => root.querySelector('.lanes-directory-list');
|
|
1092
|
+
// An owner's answer that arrives while the person types (the reply field theirs, in the page) is not drawn: moving a
|
|
1093
|
+
// focused field out of the page blurs it and closes a phone's keyboard. One line, appended outside the field, says
|
|
1094
|
+
// that updates wait; Done typing, Escape, Review or any other action of the person's draws them.
|
|
1095
|
+
const typing = v => v.composer && v.composer.owned && keep.field && root.contains(keep.field);
|
|
1096
|
+
const draw = (_, cause) => {
|
|
1097
|
+
if (root.hidden) return;
|
|
1098
|
+
const v = ui.view();
|
|
1099
|
+
if (cause === 'frame' && typing(v)) {
|
|
1100
|
+
if (!keep.note || !root.contains(keep.note)) root.append(keep.note = Object.assign(doc.createElement('p'), {className: 'lanes-directory-notice is-stale', textContent: NOTES.updates_wait}));
|
|
1101
|
+
keep.note.setAttribute('role', 'status');
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
// A redraw keeps the keyboard on the control it was on (from the reply field, on Type), never on the field itself.
|
|
1105
|
+
const active = doc.activeElement, inside = !!active && active !== root && root.contains(active);
|
|
1106
|
+
const key = inside && active !== keep.field ? active.getAttribute('data-focus') : 'type';
|
|
1107
|
+
const top = list() ? list().scrollTop : null;
|
|
1108
|
+
drawn = renderInbox(doc, root, v, ui, keep);
|
|
1109
|
+
if (list()) list().scrollTop = top ?? ui.scroll();
|
|
1110
|
+
if (inside && mode !== 'phone') (drawn.get(key) || drawn.get('close')).focus();
|
|
1111
|
+
};
|
|
1112
|
+
const ui = createInbox({storage, onChange: draw});
|
|
1113
|
+
const hide = () => {
|
|
1114
|
+
if (root.hidden) return;
|
|
1115
|
+
if (list()) ui.setScroll(list().scrollTop);
|
|
1116
|
+
ui.release(true);
|
|
1117
|
+
root.hidden = true;
|
|
1118
|
+
if (mode === 'desktop') w.term?.focus?.();
|
|
1119
|
+
};
|
|
1120
|
+
ui.close = () => {
|
|
1121
|
+
if (w.history && w.history.replaceState) w.history.replaceState(null, '', `${w.location.pathname || ''}${w.location.search || ''}`);
|
|
1122
|
+
hide();
|
|
1123
|
+
};
|
|
1124
|
+
ui.go = tab => { w.location.hash = `#${tab}`; route(); };
|
|
1125
|
+
// Opening takes the keyboard into the dialog on a tablet or a desktop, where the terminal had it (its selected row,
|
|
1126
|
+
// else Close; never the reply field); a phone's view fills the screen and opens no keyboard.
|
|
1127
|
+
const route = () => {
|
|
1128
|
+
const link = parseLink(w.location.hash);
|
|
1129
|
+
if (!link) return hide();
|
|
1130
|
+
const opening = root.hidden;
|
|
1131
|
+
root.hidden = false;
|
|
1132
|
+
ui.open(link);
|
|
1133
|
+
if (opening && mode !== 'phone') (drawn.get(`row:${ui.view().selected}`) || drawn.get('close')).focus();
|
|
1134
|
+
};
|
|
1135
|
+
root.addEventListener('keydown', ev => ev.key === 'Escape' && ui.close());
|
|
1136
|
+
w.addEventListener('hashchange', route);
|
|
1137
|
+
w.lanesInbox = {connect: next => ui.connect(next), ui};
|
|
1138
|
+
if (w.lanesInboxSource) ui.connect(w.lanesInboxSource);
|
|
1139
|
+
route();
|
|
1140
|
+
})();
|