@vibefield/rosetta-room 0.1.1 → 0.1.3
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 +82 -4
- package/dist/HistoryRoom.d.ts +15 -2
- package/dist/HistoryRoom.js +84 -27
- package/dist/TranscriptReader.d.ts +7 -0
- package/dist/TranscriptReader.js +4 -4
- package/dist/components/ColdStart.js +1 -1
- package/dist/components/IngestStatus.d.ts +13 -0
- package/dist/components/IngestStatus.js +40 -3
- package/dist/components/IngestionControls.d.ts +6 -0
- package/dist/components/IngestionControls.js +75 -0
- package/dist/components/ListActivityNotice.d.ts +9 -1
- package/dist/components/ListActivityNotice.js +9 -2
- package/dist/components/SummaryPanels.d.ts +5 -0
- package/dist/components/SummaryPanels.js +16 -5
- package/dist/components/Transcript.d.ts +5 -0
- package/dist/components/Transcript.js +20 -5
- package/dist/components/artifacts/ArtifactLibrary.d.ts +14 -0
- package/dist/components/artifacts/ArtifactLibrary.js +156 -0
- package/dist/components/artifacts/content.d.ts +8 -0
- package/dist/components/artifacts/content.js +27 -0
- package/dist/components/artifacts/load-all.d.ts +5 -0
- package/dist/components/artifacts/load-all.js +31 -0
- package/dist/components/artifacts/preview.d.ts +4 -0
- package/dist/components/artifacts/preview.js +37 -0
- package/dist/components/artifacts/thumbnails.d.ts +13 -0
- package/dist/components/artifacts/thumbnails.js +43 -0
- package/dist/components/projects/ProjectList.d.ts +9 -3
- package/dist/components/projects/ProjectList.js +3 -3
- package/dist/components/projects/ProjectListItem.d.ts +9 -3
- package/dist/components/projects/ProjectListItem.js +18 -12
- package/dist/components/projects/ProjectsColumn.d.ts +4 -1
- package/dist/components/projects/ProjectsColumn.js +23 -9
- package/dist/components/search/SearchSheet.d.ts +39 -2
- package/dist/components/search/SearchSheet.js +82 -17
- package/dist/components/sessions/SessionList.d.ts +6 -1
- package/dist/components/sessions/SessionList.js +50 -20
- package/dist/components/sessions/SessionListItem.d.ts +3 -1
- package/dist/components/sessions/SessionListItem.js +17 -7
- package/dist/components/sessions/SessionsColumn.d.ts +3 -1
- package/dist/components/sessions/SessionsColumn.js +2 -2
- package/dist/components/sessions/session-display.d.ts +4 -1
- package/dist/components/sessions/session-display.js +13 -2
- package/dist/components/transcript/Attachments.js +6 -1
- package/dist/components/transcript/Document.d.ts +6 -1
- package/dist/components/transcript/Document.js +19 -6
- package/dist/components/transcript/ImportState.d.ts +35 -0
- package/dist/components/transcript/ImportState.js +86 -0
- package/dist/components/transcript/TranscriptLoading.js +15 -5
- package/dist/components/transcript/attachment-file-source.d.ts +2 -0
- package/dist/components/transcript/attachment-file-source.js +6 -6
- package/dist/components/transcript/attachment-gallery.d.ts +2 -1
- package/dist/components/transcript/attachment-gallery.js +2 -1
- package/dist/components/transcript/detail-parts.js +7 -6
- package/dist/components/transcript/timeline-meta-file-source.d.ts +2 -1
- package/dist/components/transcript/timeline-meta-file-source.js +45 -5
- package/dist/components/ui/EmptyState.d.ts +5 -1
- package/dist/components/ui/EmptyState.js +2 -2
- package/dist/components/ui/Meter.d.ts +8 -0
- package/dist/components/ui/Meter.js +9 -0
- package/dist/components/ui/SegmentedControl.d.ts +2 -0
- package/dist/components/ui/SegmentedControl.js +1 -1
- package/dist/components/ui/Veil.d.ts +2 -1
- package/dist/components/ui/Veil.js +9 -2
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/fixtures/cold-import-corpus.d.ts +76 -0
- package/dist/fixtures/cold-import-corpus.js +349 -0
- package/dist/fixtures/cold-import-daemon.d.ts +25 -0
- package/dist/fixtures/cold-import-daemon.js +82 -0
- package/dist/fixtures/cold-import-schedule.d.ts +74 -0
- package/dist/fixtures/cold-import-schedule.js +191 -0
- package/dist/fixtures/cold-import.d.ts +151 -0
- package/dist/fixtures/cold-import.js +786 -0
- package/dist/fixtures/index.d.ts +2 -0
- package/dist/fixtures/index.js +21 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -0
- package/dist/lib/activity-order.d.ts +15 -0
- package/dist/lib/activity-order.js +24 -1
- package/dist/lib/conversation-readiness.d.ts +48 -0
- package/dist/lib/conversation-readiness.js +149 -0
- package/dist/lib/figure-order.d.ts +35 -0
- package/dist/lib/figure-order.js +68 -0
- package/dist/lib/hooks.d.ts +32 -10
- package/dist/lib/hooks.js +122 -55
- package/dist/lib/image-media.d.ts +12 -2
- package/dist/lib/image-media.js +40 -6
- package/dist/lib/import-state.d.ts +98 -0
- package/dist/lib/import-state.js +129 -0
- package/dist/lib/ingest-activity.d.ts +52 -0
- package/dist/lib/ingest-activity.js +127 -12
- package/dist/lib/ingest.d.ts +3 -0
- package/dist/lib/ingest.js +10 -0
- package/dist/lib/model.d.ts +16 -0
- package/dist/lib/model.js +27 -1
- package/dist/lib/search-sheet.d.ts +43 -0
- package/dist/lib/search-sheet.js +56 -7
- package/dist/lib/session-activity.d.ts +4 -1
- package/dist/lib/session-activity.js +4 -1
- package/dist/lib/title-search.d.ts +82 -0
- package/dist/lib/title-search.js +194 -0
- package/dist/lib/transcript/images.js +2 -2
- package/dist/lib/use-deferred-list-order.d.ts +6 -0
- package/dist/lib/use-deferred-list-order.js +8 -1
- package/dist/lib/use-ingest-activity.d.ts +5 -1
- package/dist/lib/use-ingest-activity.js +56 -20
- package/dist/ports.d.ts +21 -2
- package/dist/room-context.d.ts +1 -0
- package/dist/room-context.js +3 -2
- package/dist/styles/artifacts.css +66 -0
- package/dist/styles/history-room.css +1 -0
- package/dist/styles/ingest.css +32 -3
- package/dist/styles/room.css +15 -0
- package/dist/styles/search.css +17 -0
- package/package.json +2 -2
package/dist/lib/hooks.js
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
// The room's data spine: one meta subscription for who/what exists, REST for
|
|
2
2
|
// figures, and one session subscription for the transcript being read. Every
|
|
3
3
|
// hook reads through the port it is handed; none of them dials anything.
|
|
4
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { startTransition, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { CursorExpiredError } from "@vibefield/rosetta-protocol";
|
|
6
6
|
import { getActivityGridStartTimestamp, getViewerUtcOffsetMinutes } from "./model.js";
|
|
7
|
+
import { figureRetryDelay } from "./figure-order.js";
|
|
7
8
|
import { conversationStart, readConversationPage } from "./transcript/history-window.js";
|
|
8
9
|
import { EARLIER_FAILED_MESSAGE, EARLIER_PAGE_SIZE, earlierAboveOf, earlierState, initialEarlierModel, reduceEarlier, } from "./transcript/head-state.js";
|
|
9
|
-
export function useMeta(catalog) {
|
|
10
|
+
export function useMeta(catalog, options = {}) {
|
|
10
11
|
const [feed, setFeed] = useState({
|
|
11
12
|
meta: null, snapshotVersion: 0,
|
|
12
13
|
});
|
|
13
14
|
const [status, setStatus] = useState("connecting");
|
|
14
15
|
const [error, setError] = useState(null);
|
|
16
|
+
// Read at delivery, so turning it on or off never resubscribes.
|
|
17
|
+
const transition = useRef(options.transition === true);
|
|
18
|
+
transition.current = options.transition === true;
|
|
15
19
|
useEffect(() => {
|
|
20
|
+
// Status and errors travel the same way as the rows, so a "live" never
|
|
21
|
+
// commits ahead of the snapshot it announces.
|
|
22
|
+
const deliver = (apply) => {
|
|
23
|
+
if (transition.current)
|
|
24
|
+
startTransition(apply);
|
|
25
|
+
else
|
|
26
|
+
apply();
|
|
27
|
+
};
|
|
16
28
|
const sub = catalog.subscribeMeta({
|
|
17
|
-
onChange: (meta, source) => {
|
|
29
|
+
onChange: (meta, source) => deliver(() => {
|
|
18
30
|
setFeed((previous) => ({
|
|
19
31
|
meta,
|
|
20
32
|
snapshotVersion: previous.snapshotVersion + (source === "snapshot" ? 1 : 0),
|
|
21
33
|
}));
|
|
22
34
|
setError(null);
|
|
23
|
-
},
|
|
24
|
-
onStatus: setStatus,
|
|
25
|
-
onError: setError,
|
|
35
|
+
}),
|
|
36
|
+
onStatus: (next) => deliver(() => setStatus(next)),
|
|
37
|
+
onError: (next) => deliver(() => setError(next)),
|
|
26
38
|
});
|
|
27
39
|
return () => sub.close();
|
|
28
40
|
}, [catalog]);
|
|
@@ -31,9 +43,18 @@ export function useMeta(catalog) {
|
|
|
31
43
|
/** The daemon's status surface. It answers from the daemon's first breath —
|
|
32
44
|
* before the projection is even readable — so it is the room's connectivity
|
|
33
45
|
* truth during a cold start. Polls fast through canonical publication and
|
|
34
|
-
* search preparation, then quietly once both are ready.
|
|
35
|
-
|
|
46
|
+
* search preparation, then quietly once both are ready. A connection change,
|
|
47
|
+
* or a new `asked` (the host knows the daemon's state moved: it granted
|
|
48
|
+
* consent), drops the wait and the ask in flight and asks again at once.
|
|
49
|
+
* After a new `asked`, an answer still awaiting consent is the grant not
|
|
50
|
+
* yet visible, not the user choosing: the room asks again every 100 ms, not
|
|
51
|
+
* at the consent pause's 2.5 s, until the phase moves on. */
|
|
52
|
+
/** How many 100 ms re-asks a status refresh may make while the grant is unshown. */
|
|
53
|
+
const BRISK_REASKS = 50;
|
|
54
|
+
export function useDaemonStatus(catalog, asked = 0) {
|
|
36
55
|
const [connectionRevision, setConnectionRevision] = useState(0);
|
|
56
|
+
// The last `asked` whose move the daemon has shown.
|
|
57
|
+
const shown = useRef(0);
|
|
37
58
|
useEffect(() => catalog.onConnectionChange?.(() => setConnectionRevision((value) => value + 1)), [catalog]);
|
|
38
59
|
const [feed, setFeed] = useState({
|
|
39
60
|
connectionError: null,
|
|
@@ -50,6 +71,10 @@ export function useDaemonStatus(catalog) {
|
|
|
50
71
|
let controller;
|
|
51
72
|
let timer;
|
|
52
73
|
let deadline;
|
|
74
|
+
// Brisk re-asks after a refresh are bounded: 50 (about 5 s), then the
|
|
75
|
+
// ordinary consent pause, so a grant that never moves the phase costs
|
|
76
|
+
// nothing more than a cadence.
|
|
77
|
+
let briskLeft = BRISK_REASKS;
|
|
53
78
|
const poll = async () => {
|
|
54
79
|
const request = new AbortController();
|
|
55
80
|
controller = request;
|
|
@@ -70,11 +95,21 @@ export function useDaemonStatus(catalog) {
|
|
|
70
95
|
receivedAt: Date.now(),
|
|
71
96
|
});
|
|
72
97
|
const phase = status.ingest?.phase;
|
|
98
|
+
if (phase !== "awaiting_consent")
|
|
99
|
+
shown.current = asked;
|
|
100
|
+
// rosettad answers a grant a moment before its phase leaves
|
|
101
|
+
// awaiting_consent: re-ask briskly until it does.
|
|
102
|
+
const unshown = phase === "awaiting_consent" && shown.current !== asked && briskLeft > 0;
|
|
103
|
+
if (unshown)
|
|
104
|
+
briskLeft -= 1;
|
|
73
105
|
// Keep search visible after canonical publication. Audit/consent are
|
|
74
106
|
// intentional pauses; an unanswered first request retries promptly.
|
|
75
|
-
const paused =
|
|
107
|
+
const paused = status.ingest?.run?.state === "paused" || status.ingest?.run?.state === "failed" ||
|
|
108
|
+
phase === "metadata_ready" || phase === "awaiting_consent";
|
|
76
109
|
const complete = status.canonicalReady && status.searchReadiness === "ready";
|
|
77
|
-
|
|
110
|
+
// An unshown grant comes first: a daemon awaiting consent may still
|
|
111
|
+
// report a complete archive from before, and must not wait 30 s.
|
|
112
|
+
delay = unshown ? 100 : complete ? 30_000 : paused ? 2_500 : 500;
|
|
78
113
|
}
|
|
79
114
|
catch (error) {
|
|
80
115
|
if (!cancelled)
|
|
@@ -98,15 +133,22 @@ export function useDaemonStatus(catalog) {
|
|
|
98
133
|
window.clearTimeout(deadline);
|
|
99
134
|
window.clearTimeout(timer);
|
|
100
135
|
};
|
|
101
|
-
}, [catalog, connectionRevision]);
|
|
136
|
+
}, [catalog, connectionRevision, asked]);
|
|
102
137
|
return feed;
|
|
103
138
|
}
|
|
139
|
+
const NO_FAILURES = new Set();
|
|
104
140
|
/** Per-project heatmaps and contributions. These are global derived reads,
|
|
105
141
|
* so they begin only after the daemon's canonical publication gate. Four
|
|
106
|
-
* workers hydrate the list progressively
|
|
107
|
-
*
|
|
108
|
-
|
|
142
|
+
* workers hydrate the list progressively — the selected project first, then
|
|
143
|
+
* the cards on screen, then the rest (`priority`) — and unbounded
|
|
144
|
+
* Promise.all here once launched two full-corpus queries per project and
|
|
145
|
+
* starved cold ingestion. A project that fails is asked again on its own,
|
|
146
|
+
* with backoff; the others wait for the quiet periodic refresh. */
|
|
147
|
+
export function useProjectStats(catalog, projectIds, ready = false, priority) {
|
|
109
148
|
const [stats, setStats] = useState(new Map());
|
|
149
|
+
const [failed, setFailed] = useState(NO_FAILURES);
|
|
150
|
+
const priorityRef = useRef(priority);
|
|
151
|
+
priorityRef.current = priority;
|
|
110
152
|
const key = projectIds.join("\n");
|
|
111
153
|
useEffect(() => {
|
|
112
154
|
let cancelled = false;
|
|
@@ -115,78 +157,97 @@ export function useProjectStats(catalog, projectIds, ready = false) {
|
|
|
115
157
|
const ids = key === "" ? [] : key.split("\n");
|
|
116
158
|
if (!ready || ids.length === 0) {
|
|
117
159
|
setStats(new Map());
|
|
160
|
+
setFailed(NO_FAILURES);
|
|
118
161
|
return () => {
|
|
119
162
|
cancelled = true;
|
|
120
163
|
controller.abort();
|
|
121
164
|
};
|
|
122
165
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
166
|
+
const land = (answered) => {
|
|
167
|
+
if (cancelled || answered.size === 0)
|
|
168
|
+
return;
|
|
169
|
+
setStats((current) => {
|
|
170
|
+
const next = new Map(current);
|
|
171
|
+
for (const [id, figures] of answered)
|
|
172
|
+
next.set(id, figures);
|
|
173
|
+
return next;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
/** One ask of every target; resolves to the ones that failed. */
|
|
177
|
+
async function round(targets) {
|
|
178
|
+
const span = { sinceMs: getActivityGridStartTimestamp(Date.now()), offsetMinutes: getViewerUtcOffsetMinutes() };
|
|
179
|
+
const missed = new Set();
|
|
126
180
|
// A host that answers every project at once is asked once.
|
|
127
181
|
if (catalog.projectStatsBatch !== undefined) {
|
|
128
|
-
let missing = true;
|
|
129
182
|
try {
|
|
130
|
-
const answer = await catalog.projectStatsBatch(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
next.set(id, figures);
|
|
139
|
-
}
|
|
140
|
-
return next;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
183
|
+
const answer = await catalog.projectStatsBatch([...targets], span, controller.signal);
|
|
184
|
+
for (const id of targets)
|
|
185
|
+
if (!answer.has(id))
|
|
186
|
+
missed.add(id);
|
|
187
|
+
land(new Map(targets.flatMap((id) => {
|
|
188
|
+
const figures = answer.get(id);
|
|
189
|
+
return figures === undefined ? [] : [[id, figures]];
|
|
190
|
+
})));
|
|
143
191
|
}
|
|
144
192
|
catch {
|
|
145
193
|
// as below: unfigured projects degrade honestly and earn a retry
|
|
194
|
+
for (const id of targets)
|
|
195
|
+
missed.add(id);
|
|
146
196
|
}
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
timer = window.setTimeout(loadAll, missing ? 8_000 : 5 * 60_000);
|
|
150
|
-
return;
|
|
197
|
+
return missed;
|
|
151
198
|
}
|
|
152
|
-
const
|
|
153
|
-
|
|
199
|
+
const left = new Set(targets);
|
|
200
|
+
const drawn = priorityRef.current?.order() ?? [];
|
|
201
|
+
const next = () => {
|
|
202
|
+
const first = priorityRef.current?.first ?? null;
|
|
203
|
+
if (first !== null && left.delete(first))
|
|
204
|
+
return first;
|
|
205
|
+
for (const id of drawn)
|
|
206
|
+
if (left.delete(id))
|
|
207
|
+
return id;
|
|
208
|
+
const rest = left.values().next();
|
|
209
|
+
if (rest.done)
|
|
210
|
+
return undefined;
|
|
211
|
+
left.delete(rest.value);
|
|
212
|
+
return rest.value;
|
|
213
|
+
};
|
|
154
214
|
async function worker() {
|
|
155
215
|
while (!cancelled) {
|
|
156
|
-
const id =
|
|
216
|
+
const id = next();
|
|
157
217
|
if (id === undefined)
|
|
158
218
|
return;
|
|
159
219
|
try {
|
|
160
|
-
|
|
161
|
-
if (!cancelled) {
|
|
162
|
-
setStats((current) => {
|
|
163
|
-
const next = new Map(current);
|
|
164
|
-
next.set(id, figures);
|
|
165
|
-
return next;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
220
|
+
land(new Map([[id, await catalog.projectStats(id, span, controller.signal)]]));
|
|
168
221
|
}
|
|
169
222
|
catch {
|
|
170
223
|
// an unfigured project degrades honestly — and earns a retry
|
|
171
|
-
|
|
224
|
+
missed.add(id);
|
|
172
225
|
}
|
|
173
226
|
}
|
|
174
227
|
}
|
|
175
|
-
await Promise.all(Array.from({ length: Math.min(4,
|
|
228
|
+
await Promise.all(Array.from({ length: Math.min(4, targets.length) }, () => worker()));
|
|
229
|
+
return missed;
|
|
230
|
+
}
|
|
231
|
+
async function load(targets, failures) {
|
|
232
|
+
const missed = await round(targets);
|
|
176
233
|
if (cancelled)
|
|
177
234
|
return;
|
|
178
|
-
|
|
179
|
-
//
|
|
180
|
-
|
|
235
|
+
setFailed(missed.size === 0 ? NO_FAILURES : missed);
|
|
236
|
+
// A failed figure (a daemon mid-restart, a dropped socket) is asked
|
|
237
|
+
// again on its own, in seconds and then less often. Stable canonical
|
|
238
|
+
// figures need only a quiet periodic refresh of every project.
|
|
239
|
+
timer = missed.size > 0
|
|
240
|
+
? window.setTimeout(() => load([...missed], failures + 1), figureRetryDelay(failures + 1))
|
|
241
|
+
: window.setTimeout(() => load(ids, 0), 5 * 60_000);
|
|
181
242
|
}
|
|
182
|
-
|
|
243
|
+
load(ids, 0);
|
|
183
244
|
return () => {
|
|
184
245
|
cancelled = true;
|
|
185
246
|
controller.abort();
|
|
186
247
|
window.clearTimeout(timer);
|
|
187
248
|
};
|
|
188
249
|
}, [catalog, key, ready]);
|
|
189
|
-
return stats;
|
|
250
|
+
return useMemo(() => ({ stats, failed }), [stats, failed]);
|
|
190
251
|
}
|
|
191
252
|
/** The selected project's usage decomposition — per-model days and the
|
|
192
253
|
* hour-of-day profile, over the same 53-week window the heatmap draws. */
|
|
@@ -222,6 +283,7 @@ export function useProjectUsage(catalog, projectId, ready = false) {
|
|
|
222
283
|
}, [catalog, projectId, ready]);
|
|
223
284
|
return usage;
|
|
224
285
|
}
|
|
286
|
+
// @atlas step live.render
|
|
225
287
|
export function useTimeline(sessions, sessionId) {
|
|
226
288
|
const [owner, setOwner] = useState(sessionId);
|
|
227
289
|
const [attempt, setAttempt] = useState(0);
|
|
@@ -554,13 +616,18 @@ export function useTeamTimelines(sessions, sessionIds) {
|
|
|
554
616
|
}, [ids, revision, retry]);
|
|
555
617
|
}
|
|
556
618
|
export const SEARCH_LIMIT = 200;
|
|
619
|
+
// @atlas step search-query.feed
|
|
557
620
|
/**
|
|
558
621
|
* One ranked search per settled query. The previous response stays on screen
|
|
559
622
|
* while its successor is in flight — a list that blanks on every keystroke
|
|
560
623
|
* reads as a search that keeps failing — and only the newest request may
|
|
561
624
|
* land: a superseded one is aborted and its late result ignored.
|
|
625
|
+
*
|
|
626
|
+
* A change of `askAgain` re-asks an unchanged query. The room passes whether
|
|
627
|
+
* full text can answer, so the empty answer an unpublished index gave is
|
|
628
|
+
* replaced as soon as the index can answer.
|
|
562
629
|
*/
|
|
563
|
-
export function useSearch(catalog, query, facets = {}) {
|
|
630
|
+
export function useSearch(catalog, query, facets = {}, askAgain = 0) {
|
|
564
631
|
const [response, setResponse] = useState(null);
|
|
565
632
|
const [error, setError] = useState(null);
|
|
566
633
|
const [searching, setSearching] = useState(false);
|
|
@@ -603,6 +670,6 @@ export function useSearch(catalog, query, facets = {}) {
|
|
|
603
670
|
clearTimeout(timer);
|
|
604
671
|
controller.abort();
|
|
605
672
|
};
|
|
606
|
-
}, [catalog, query, project, kind, agent]);
|
|
673
|
+
}, [catalog, query, project, kind, agent, askAgain]);
|
|
607
674
|
return { query: query.trim(), response, error, searching };
|
|
608
675
|
}
|
|
@@ -2,5 +2,15 @@ import type { AssetRef } from "@vibefield/rosetta-protocol";
|
|
|
2
2
|
/** File-format hints for image targets without a filename extension or MIME type.
|
|
3
3
|
* This only selects the existing viewer; the browser still validates/decodes it. */
|
|
4
4
|
export declare function imageMediaTypeFromBytes(bytes: Uint8Array): string | null;
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/** The member extension of a recorded image format, or undefined for any
|
|
6
|
+
* other media type. */
|
|
7
|
+
export declare function recordedImageExtension(mediaType: string): string | undefined;
|
|
8
|
+
/** A complete WebP bundle: the member and its four renditions, all encoded
|
|
9
|
+
* by ingestion before deferred renditions (projections built earlier). */
|
|
10
|
+
export declare function isLegacyImageBundle(asset: AssetRef): boolean;
|
|
11
|
+
/** A transcript image the room may show: a recorded original (a member in one
|
|
12
|
+
* of the six formats with no rendition map) or a complete legacy WebP bundle.
|
|
13
|
+
* One transcript may hold both. Either is drawn only through the daemon's
|
|
14
|
+
* WebP renditions (`AssetSource.imageAssetUrl`); the room never draws the
|
|
15
|
+
* recorded bytes themselves. */
|
|
16
|
+
export declare function isRecordedImageAsset(asset: AssetRef): boolean;
|
package/dist/lib/image-media.js
CHANGED
|
@@ -21,10 +21,44 @@ export function imageMediaTypeFromBytes(bytes) {
|
|
|
21
21
|
return "image/svg+xml";
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
/** The six recorded image formats ingestion keeps as verified originals, each
|
|
25
|
+
* with the one extension its content-addressed member name carries. */
|
|
26
|
+
const RECORDED_IMAGE_EXTENSION = new Map([
|
|
27
|
+
["image/png", "png"],
|
|
28
|
+
["image/jpeg", "jpg"],
|
|
29
|
+
["image/gif", "gif"],
|
|
30
|
+
["image/webp", "webp"],
|
|
31
|
+
["image/bmp", "bmp"],
|
|
32
|
+
["image/x-icon", "ico"],
|
|
33
|
+
]);
|
|
34
|
+
const BUNDLE_VARIANTS = ["rail", "tile", "tile2x", "preview"];
|
|
35
|
+
/** The member extension of a recorded image format, or undefined for any
|
|
36
|
+
* other media type. */
|
|
37
|
+
export function recordedImageExtension(mediaType) {
|
|
38
|
+
return RECORDED_IMAGE_EXTENSION.get(mediaType);
|
|
39
|
+
}
|
|
40
|
+
/** One content-addressed projection member: `/api/assets/<digest>.<extension>`. */
|
|
41
|
+
function isMember(value, mediaType, extension) {
|
|
42
|
+
return value?.media_type === mediaType && value.byte_len > 0 && /^[a-f0-9]{64}$/.test(value.digest)
|
|
43
|
+
&& value.url === `/api/assets/${value.digest}.${extension}`;
|
|
44
|
+
}
|
|
45
|
+
/** A complete WebP bundle: the member and its four renditions, all encoded
|
|
46
|
+
* by ingestion before deferred renditions (projections built earlier). */
|
|
47
|
+
export function isLegacyImageBundle(asset) {
|
|
48
|
+
const member = (value) => isMember(value, "image/webp", "webp");
|
|
49
|
+
return member(asset) && BUNDLE_VARIANTS.every(variant => member(asset.image_variants?.[variant]));
|
|
50
|
+
}
|
|
51
|
+
/** A transcript image the room may show: a recorded original (a member in one
|
|
52
|
+
* of the six formats with no rendition map) or a complete legacy WebP bundle.
|
|
53
|
+
* One transcript may hold both. Either is drawn only through the daemon's
|
|
54
|
+
* WebP renditions (`AssetSource.imageAssetUrl`); the room never draws the
|
|
55
|
+
* recorded bytes themselves. */
|
|
56
|
+
export function isRecordedImageAsset(asset) {
|
|
57
|
+
// A malformed row's missing asset is refused, never a render-time throw.
|
|
58
|
+
if (asset == null)
|
|
59
|
+
return false;
|
|
60
|
+
if (asset.image_variants != null)
|
|
61
|
+
return isLegacyImageBundle(asset);
|
|
62
|
+
const extension = recordedImageExtension(asset.media_type);
|
|
63
|
+
return extension !== undefined && isMember(asset, asset.media_type, extension);
|
|
30
64
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { IngestProgress, SessionRow, StreamState } from "@vibefield/rosetta-protocol";
|
|
2
|
+
import type { ListPosition } from "./use-deferred-list-order.js";
|
|
3
|
+
/** Where a session stands with the import, for the words the room uses.
|
|
4
|
+
* - `not-imported`: the import is running and has not reached it yet.
|
|
5
|
+
* - `unavailable`: no import will reach it, because its own transcript was
|
|
6
|
+
* never found (see `isMetadataOnly`).
|
|
7
|
+
* - `null`: nothing to say; the session reads as it always did. */
|
|
8
|
+
export type ImportStanding = "not-imported" | "unavailable" | null;
|
|
9
|
+
/** The foot group's header, in place of a date. */
|
|
10
|
+
export declare const NOT_IMPORTED_LABEL = "Not imported yet";
|
|
11
|
+
/** The top group's header: not-imported sessions newer than every readable one. */
|
|
12
|
+
export declare const STILL_IMPORTING_LABEL = "Still importing";
|
|
13
|
+
/** A row the metadata pass made only because a descendant names it as its
|
|
14
|
+
* parent or root. Its own transcript was not found, so the row is Pending
|
|
15
|
+
* with no cwd, title, summary or delegation, and no import will ever reach
|
|
16
|
+
* it. Children are what tell it apart from a real session whose head said
|
|
17
|
+
* nothing: every such row has a direct child, since a root made for a
|
|
18
|
+
* grandchild comes with the missing parent between them, which names it. */
|
|
19
|
+
export declare function isMetadataOnly(session: SessionRow, hasChildren: boolean): boolean;
|
|
20
|
+
export declare function importStanding(session: SessionRow, duringBackfill: boolean, hasChildren: boolean): ImportStanding;
|
|
21
|
+
/** When the import opens a session it has not reached yet, as far as the
|
|
22
|
+
* daemon's course for the session's runtime promises
|
|
23
|
+
* (`RuntimeBackfill.admission_course`). None names an order or a position.
|
|
24
|
+
* - `newest-first` (`per_tree`): a fresh build admits the runtime per
|
|
25
|
+
* conversation tree, newer trees first; most open as they close, but a
|
|
26
|
+
* bound one waits for the runtime's close, so this promises no time.
|
|
27
|
+
* - `runtime-close` (`at_runtime_close`): the runtime is admitted whole, so
|
|
28
|
+
* the session opens when its agent finishes importing.
|
|
29
|
+
* - `resumed` (`at_publication`): a resumed build, across a launch or after
|
|
30
|
+
* a pause, withholds every session it has not opened before until it
|
|
31
|
+
* publishes, so they open when it finishes.
|
|
32
|
+
* - `stopped`: a paused or failed run reaches nothing until it continues. */
|
|
33
|
+
export type ImportCourse = "newest-first" | "runtime-close" | "resumed" | "stopped";
|
|
34
|
+
/** `resumed` is the room's own inference for a daemon that names no course
|
|
35
|
+
* (`resumedRun`: a restoring phase seen). */
|
|
36
|
+
export declare function importCourse(ingest: IngestProgress | null | undefined, runtimeId: string | null, resumed: boolean): ImportCourse;
|
|
37
|
+
/** The ids some session names as its parent: the sessions with children. */
|
|
38
|
+
export declare function parentIds(sessions: readonly SessionRow[]): ReadonlySet<string>;
|
|
39
|
+
/** The list's draw order during an import: the not-imported rows `above`
|
|
40
|
+
* picks first, then every other row where the room's order put it, then the
|
|
41
|
+
* rest of the not-imported rows; both groups ordered by `compare`. */
|
|
42
|
+
export declare function notImportedAround<T>(rows: readonly T[], notImported: (row: T) => boolean, above: (row: T) => boolean, compare: (left: T, right: T) => number): T[];
|
|
43
|
+
/** Every not-imported row at the foot (`notImportedAround` with no top group). */
|
|
44
|
+
export declare function notImportedLast<T>(rows: readonly T[], notImported: (row: T) => boolean, compare: (left: T, right: T) => number): T[];
|
|
45
|
+
/** The newest source among the readable rows, the line the top group's rows
|
|
46
|
+
* are newer than; null while none is readable, when every not-imported row
|
|
47
|
+
* is newer. Both sides are `updated_at`, the source's freshness: it places a
|
|
48
|
+
* row in a date-free group and never claims a day or a time. */
|
|
49
|
+
export declare function newestReadableSource(rows: readonly SessionRow[], readable: (row: SessionRow) => boolean): number | null;
|
|
50
|
+
/** Conversations a held list still draws in the not-imported group while
|
|
51
|
+
* the wanted order draws them as imported. */
|
|
52
|
+
export interface ImportArrivals {
|
|
53
|
+
readonly count: number;
|
|
54
|
+
/** Every arrival lands below the row the reader is looking at. */
|
|
55
|
+
readonly older: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* What arrived while the reader held the list.
|
|
59
|
+
*
|
|
60
|
+
* `anchorIds` are the rows at the top of the reader's view, nearest first; an
|
|
61
|
+
* empty list means the view is at the top, so its first row is the anchor.
|
|
62
|
+
* Null when no held not-imported row was imported.
|
|
63
|
+
*/
|
|
64
|
+
export declare function importArrivals(held: readonly ListPosition[], wanted: readonly ListPosition[], anchorIds: readonly string[]): ImportArrivals | null;
|
|
65
|
+
/** "3 older conversations imported", or without "older" when one lands above. */
|
|
66
|
+
export declare function arrivalsLabel(arrivals: ImportArrivals): string;
|
|
67
|
+
/**
|
|
68
|
+
* Which rows the transcript holds, and whether they were delivered while its
|
|
69
|
+
* session was Pending.
|
|
70
|
+
*
|
|
71
|
+
* A Pending session's socket delivers no rows. When its tree opens, the
|
|
72
|
+
* catalog announces the new `stream_state` and the session socket resyncs,
|
|
73
|
+
* on separate sockets, so either can land first. Until rows delivered after
|
|
74
|
+
* the flip replace the empty Pending ones, the transcript keeps its
|
|
75
|
+
* not-imported face rather than "Nothing readable yet".
|
|
76
|
+
*/
|
|
77
|
+
export interface ImportWatch {
|
|
78
|
+
readonly sessionId: string;
|
|
79
|
+
/** The delivered rows, by identity; null before a snapshot arrives. */
|
|
80
|
+
readonly delivered: readonly unknown[] | null;
|
|
81
|
+
readonly pendingEra: boolean;
|
|
82
|
+
}
|
|
83
|
+
/** `delivered` must keep its identity until the feed delivers again: pass a
|
|
84
|
+
* feed's rows only once its snapshot is ready, and null before. */
|
|
85
|
+
export declare function watchImport(previous: ImportWatch | null, sessionId: string, streamState: StreamState, delivered: readonly unknown[] | null): ImportWatch;
|
|
86
|
+
/** The session has opened, but its rows are still the empty Pending ones. */
|
|
87
|
+
export declare function holdsImport(watch: ImportWatch, streamState: StreamState): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The words a full command's disclosure says when it cannot load.
|
|
90
|
+
*
|
|
91
|
+
* The daemon answers `not_ready` while the archive is unpublished: for a
|
|
92
|
+
* conversation still importing (its message says "importing"), or for one
|
|
93
|
+
* that is open but whose raw record is not saved yet (it says "saving", or
|
|
94
|
+
* names publication). Any other failure, including a `not_ready` that no
|
|
95
|
+
* wait will cure (a server with no raw-ledger reader), keeps the room's own
|
|
96
|
+
* words.
|
|
97
|
+
*/
|
|
98
|
+
export declare function commandFailureLabel(error: unknown): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** The foot group's header, in place of a date. */
|
|
2
|
+
export const NOT_IMPORTED_LABEL = "Not imported yet";
|
|
3
|
+
/** The top group's header: not-imported sessions newer than every readable one. */
|
|
4
|
+
export const STILL_IMPORTING_LABEL = "Still importing";
|
|
5
|
+
/** A row the metadata pass made only because a descendant names it as its
|
|
6
|
+
* parent or root. Its own transcript was not found, so the row is Pending
|
|
7
|
+
* with no cwd, title, summary or delegation, and no import will ever reach
|
|
8
|
+
* it. Children are what tell it apart from a real session whose head said
|
|
9
|
+
* nothing: every such row has a direct child, since a root made for a
|
|
10
|
+
* grandchild comes with the missing parent between them, which names it. */
|
|
11
|
+
export function isMetadataOnly(session, hasChildren) {
|
|
12
|
+
return hasChildren && session.stream_state === "pending" && session.cwd === null &&
|
|
13
|
+
session.title === null && session.summary === null && session.delegation === null;
|
|
14
|
+
}
|
|
15
|
+
export function importStanding(session, duringBackfill, hasChildren) {
|
|
16
|
+
if (isMetadataOnly(session, hasChildren))
|
|
17
|
+
return "unavailable";
|
|
18
|
+
return duringBackfill && session.stream_state === "pending" ? "not-imported" : null;
|
|
19
|
+
}
|
|
20
|
+
/** `resumed` is the room's own inference for a daemon that names no course
|
|
21
|
+
* (`resumedRun`: a restoring phase seen). */
|
|
22
|
+
export function importCourse(ingest, runtimeId, resumed) {
|
|
23
|
+
const run = ingest?.run;
|
|
24
|
+
if (run?.state === "paused" || run?.state === "pausing" || run?.state === "failed")
|
|
25
|
+
return "stopped";
|
|
26
|
+
const own = runtimeId === null ? undefined
|
|
27
|
+
: ingest?.runtimes.find((row) => row.runtime_id === runtimeId)?.admission_course;
|
|
28
|
+
if (own === "at_publication")
|
|
29
|
+
return "resumed";
|
|
30
|
+
if (own === "at_runtime_close")
|
|
31
|
+
return "runtime-close";
|
|
32
|
+
if (own === "per_tree")
|
|
33
|
+
return "newest-first";
|
|
34
|
+
return resumed ? "resumed" : "newest-first";
|
|
35
|
+
}
|
|
36
|
+
/** The ids some session names as its parent: the sessions with children. */
|
|
37
|
+
export function parentIds(sessions) {
|
|
38
|
+
const ids = new Set();
|
|
39
|
+
for (const session of sessions) {
|
|
40
|
+
if (session.parent_session_id !== null)
|
|
41
|
+
ids.add(session.parent_session_id);
|
|
42
|
+
}
|
|
43
|
+
return ids;
|
|
44
|
+
}
|
|
45
|
+
/** The list's draw order during an import: the not-imported rows `above`
|
|
46
|
+
* picks first, then every other row where the room's order put it, then the
|
|
47
|
+
* rest of the not-imported rows; both groups ordered by `compare`. */
|
|
48
|
+
export function notImportedAround(rows, notImported, above, compare) {
|
|
49
|
+
const waiting = rows.filter(notImported);
|
|
50
|
+
if (waiting.length === 0)
|
|
51
|
+
return [...rows];
|
|
52
|
+
const top = waiting.filter(above);
|
|
53
|
+
const foot = waiting.filter((row) => !above(row));
|
|
54
|
+
return [...top.sort(compare), ...rows.filter((row) => !notImported(row)), ...foot.sort(compare)];
|
|
55
|
+
}
|
|
56
|
+
/** Every not-imported row at the foot (`notImportedAround` with no top group). */
|
|
57
|
+
export function notImportedLast(rows, notImported, compare) {
|
|
58
|
+
return notImportedAround(rows, notImported, () => false, compare);
|
|
59
|
+
}
|
|
60
|
+
/** The newest source among the readable rows, the line the top group's rows
|
|
61
|
+
* are newer than; null while none is readable, when every not-imported row
|
|
62
|
+
* is newer. Both sides are `updated_at`, the source's freshness: it places a
|
|
63
|
+
* row in a date-free group and never claims a day or a time. */
|
|
64
|
+
export function newestReadableSource(rows, readable) {
|
|
65
|
+
let newest = null;
|
|
66
|
+
for (const row of rows) {
|
|
67
|
+
if (readable(row) && Number.isFinite(row.updated_at))
|
|
68
|
+
newest = newest === null ? row.updated_at : Math.max(newest, row.updated_at);
|
|
69
|
+
}
|
|
70
|
+
return newest;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* What arrived while the reader held the list.
|
|
74
|
+
*
|
|
75
|
+
* `anchorIds` are the rows at the top of the reader's view, nearest first; an
|
|
76
|
+
* empty list means the view is at the top, so its first row is the anchor.
|
|
77
|
+
* Null when no held not-imported row was imported.
|
|
78
|
+
*/
|
|
79
|
+
export function importArrivals(held, wanted, anchorIds) {
|
|
80
|
+
const waiting = new Set(held.flatMap((item) => (item.pending === true ? [item.id] : [])));
|
|
81
|
+
if (waiting.size === 0)
|
|
82
|
+
return null;
|
|
83
|
+
const rank = new Map(wanted.map((item, at) => [item.id, at]));
|
|
84
|
+
const landed = wanted.flatMap((item, at) => (waiting.has(item.id) && item.pending !== true ? [at] : []));
|
|
85
|
+
if (landed.length === 0)
|
|
86
|
+
return null;
|
|
87
|
+
const anchor = [...anchorIds, ...(held[0] === undefined ? [] : [held[0].id])]
|
|
88
|
+
.map((id) => rank.get(id))
|
|
89
|
+
.find((at) => at !== undefined);
|
|
90
|
+
return { count: landed.length, older: anchor !== undefined && landed.every((at) => at > anchor) };
|
|
91
|
+
}
|
|
92
|
+
/** "3 older conversations imported", or without "older" when one lands above. */
|
|
93
|
+
export function arrivalsLabel(arrivals) {
|
|
94
|
+
const noun = arrivals.count === 1 ? "conversation" : "conversations";
|
|
95
|
+
return `${arrivals.count.toLocaleString()} ${arrivals.older ? "older " : ""}${noun} imported`;
|
|
96
|
+
}
|
|
97
|
+
/** `delivered` must keep its identity until the feed delivers again: pass a
|
|
98
|
+
* feed's rows only once its snapshot is ready, and null before. */
|
|
99
|
+
export function watchImport(previous, sessionId, streamState, delivered) {
|
|
100
|
+
if (previous !== null && previous.sessionId === sessionId && previous.delivered === delivered) {
|
|
101
|
+
return previous;
|
|
102
|
+
}
|
|
103
|
+
return { sessionId, delivered, pendingEra: delivered !== null && streamState === "pending" };
|
|
104
|
+
}
|
|
105
|
+
/** The session has opened, but its rows are still the empty Pending ones. */
|
|
106
|
+
export function holdsImport(watch, streamState) {
|
|
107
|
+
return watch.pendingEra && streamState !== "pending" &&
|
|
108
|
+
watch.delivered !== null && watch.delivered.length === 0;
|
|
109
|
+
}
|
|
110
|
+
/* ── a full command asked for during the import ───────────────────────── */
|
|
111
|
+
/**
|
|
112
|
+
* The words a full command's disclosure says when it cannot load.
|
|
113
|
+
*
|
|
114
|
+
* The daemon answers `not_ready` while the archive is unpublished: for a
|
|
115
|
+
* conversation still importing (its message says "importing"), or for one
|
|
116
|
+
* that is open but whose raw record is not saved yet (it says "saving", or
|
|
117
|
+
* names publication). Any other failure, including a `not_ready` that no
|
|
118
|
+
* wait will cure (a server with no raw-ledger reader), keeps the room's own
|
|
119
|
+
* words.
|
|
120
|
+
*/
|
|
121
|
+
export function commandFailureLabel(error) {
|
|
122
|
+
const code = typeof error === "object" && error !== null && "code" in error ? error.code : null;
|
|
123
|
+
if (code !== "not_ready")
|
|
124
|
+
return "couldn’t load · retry";
|
|
125
|
+
const message = error instanceof Error ? error.message : "";
|
|
126
|
+
if (/\bimport/i.test(message))
|
|
127
|
+
return "available when imported · retry";
|
|
128
|
+
return /\b(?:sav|publi)/i.test(message) ? "still saving · retry" : "couldn’t load · retry";
|
|
129
|
+
}
|