@agentshouse/mdruntime 0.1.0-cf04ede9fb796 → 0.1.0-cf08df9b663d8
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 +21 -19
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +105 -166
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +175 -85
- package/dist/adapter.d.ts +226 -74
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -19
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +30 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -68
- package/dist/collection.d.ts +27 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -10
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +101 -63
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +42 -27
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +29 -15
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +26 -14
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +48 -16
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +368 -262
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/expectation.d.ts +26 -13
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +72 -19
- package/dist/failure.d.ts +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +8 -0
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +24 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +108 -32
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +29 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -9
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +92 -111
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +80 -54
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -79
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +97 -39
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +12 -39
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +20 -4
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +184 -37
- package/dist/memory.d.ts +10 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +105 -41
- package/dist/messages.d.ts +21 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +53 -41
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +10 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +97 -139
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +217 -85
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +7 -7
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +24 -10
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +23 -8
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +132 -48
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +6 -59
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +32 -122
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +210 -92
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +138 -80
- package/dist/query.d.ts +2 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +482 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +200 -40
- package/dist/react.d.ts +17 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -3
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +30 -15
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +6 -6
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -6
- package/dist/replica.d.ts +6 -17
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +18 -20
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +32 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +282 -72
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +29 -23
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +28 -15
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +15 -20
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +43 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +338 -236
- package/dist/saves.d.ts +9 -45
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +208 -752
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -5
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shared.d.ts +0 -5
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +4 -90
- package/dist/shown.d.ts +10 -6
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +105 -73
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -2
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +9 -7
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +19 -18
- package/dist/source.d.ts +42 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +81 -13
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +32 -10
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +71 -28
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store/space.d.ts +1 -1
- package/dist/store/space.d.ts.map +1 -1
- package/dist/store/space.js +0 -2
- package/dist/store/watchers.js +1 -2
- package/dist/store.d.ts +25 -15
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +42 -17
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +220 -62
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +70 -35
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +134 -109
- package/dist/tables.d.ts +40 -57
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +114 -334
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +8 -9
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +51 -11
- package/dist/wire.d.ts +72 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +31 -14
- package/package.json +4 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -44
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/parts.js
CHANGED
|
@@ -1,126 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { excerpt
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case 'marker': {
|
|
33
|
-
const marker = text(part, 'marker');
|
|
34
|
-
return marker === null || !MARKERS.includes(marker)
|
|
35
|
-
? null
|
|
36
|
-
: { type: 'marker', marker: marker, text: text(part, 'text') ?? '' };
|
|
37
|
-
}
|
|
38
|
-
case 'plan':
|
|
39
|
-
return {
|
|
40
|
-
type: 'plan',
|
|
41
|
-
steps: list(part, 'entries').flatMap((entry) => {
|
|
42
|
-
const step = record(entry);
|
|
43
|
-
const content = text(step, 'content');
|
|
44
|
-
return content === null ? [] : [{ content, status: text(step, 'status') ?? '' }];
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
default:
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function partsOf(raw) {
|
|
52
|
-
return raw.flatMap((one) => partOf(one) ?? []);
|
|
53
|
-
}
|
|
54
|
-
export function contextIn(raw) {
|
|
55
|
-
const held = record(raw);
|
|
56
|
-
return typeof held.used === 'number' && typeof held.window === 'number' && held.window > 0
|
|
57
|
-
? { used: held.used, window: held.window }
|
|
58
|
-
: null;
|
|
59
|
-
}
|
|
60
|
-
const TOKEN_KINDS = ['input', 'output', 'cache_read', 'cache_write'];
|
|
61
|
-
export function tokensIn(raw) {
|
|
62
|
-
const held = record(raw);
|
|
63
|
-
const counts = TOKEN_KINDS.map((kind) => held[kind]);
|
|
64
|
-
return counts.every((count) => typeof count === 'number')
|
|
65
|
-
? counts.reduce((sum, count) => sum + count, 0)
|
|
66
|
-
: null;
|
|
67
|
-
}
|
|
68
|
-
export function counted(count) {
|
|
69
|
-
return count === 1 ? '1 command' : `${count} commands`;
|
|
70
|
-
}
|
|
71
|
-
export function runningLine(raw) {
|
|
72
|
-
const parts = partsOf(raw);
|
|
1
|
+
import { turnCounts } from '@agentshouse/session-content';
|
|
2
|
+
import { excerpt } from './read.js';
|
|
3
|
+
export const WORKING = 'Working';
|
|
4
|
+
function said(count, one, many) {
|
|
5
|
+
if (count === 0)
|
|
6
|
+
return null;
|
|
7
|
+
return count === 1 ? one : many(count);
|
|
8
|
+
}
|
|
9
|
+
export function linesWords(added, removed) {
|
|
10
|
+
return `+${added} −${removed}`;
|
|
11
|
+
}
|
|
12
|
+
export function capitalized(words) {
|
|
13
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
14
|
+
}
|
|
15
|
+
export function turnLine(parts, lead) {
|
|
16
|
+
const counts = turnCounts(parts);
|
|
17
|
+
const kinds = [
|
|
18
|
+
said(counts.commands, 'ran 1 command', (count) => `ran ${count} commands`),
|
|
19
|
+
said(counts.edited, 'edited 1 file', (count) => `edited ${count} files`),
|
|
20
|
+
said(counts.other, 'made 1 other call', (count) => `made ${count} other calls`),
|
|
21
|
+
].filter((one) => one !== null);
|
|
22
|
+
if (kinds.length === 0)
|
|
23
|
+
return null;
|
|
24
|
+
const changed = counts.added === 0 && counts.removed === 0 ? null : linesWords(counts.added, counts.removed);
|
|
25
|
+
const failed = counts.failed === 0 ? null : `${counts.failed} failed`;
|
|
26
|
+
const words = kinds.join(' · ');
|
|
27
|
+
return [lead === null ? capitalized(words) : `${lead} · ${words}`, changed, failed]
|
|
28
|
+
.filter((one) => one !== null)
|
|
29
|
+
.join(' · ');
|
|
30
|
+
}
|
|
31
|
+
export function runningLine(parts) {
|
|
73
32
|
const note = [...parts].reverse().find((part) => part.type === 'text' && part.text.trim() !== '');
|
|
74
33
|
if (note?.type === 'text')
|
|
75
34
|
return excerpt(note.text);
|
|
76
|
-
|
|
77
|
-
return commands === 0 ? null : counted(commands);
|
|
78
|
-
}
|
|
79
|
-
export function jobsOf(markers, turn) {
|
|
80
|
-
const running = (turn === null ? [] : partsOf(turn.parts)).flatMap((part) => part.type === 'marker' && part.marker === 'job'
|
|
81
|
-
? [{ said: part.text, at: turn?.started ?? null }]
|
|
82
|
-
: []);
|
|
83
|
-
return openJobs([...markers, ...running]);
|
|
84
|
-
}
|
|
85
|
-
export function stillRunning(turns, subagents) {
|
|
86
|
-
const open = [];
|
|
87
|
-
for (const { turn, parts, ended } of turns) {
|
|
88
|
-
for (const part of parts) {
|
|
89
|
-
if (part.type === 'subagent') {
|
|
90
|
-
const key = `subagent\u0000${part.description}`;
|
|
91
|
-
if (part.done)
|
|
92
|
-
closeLast(open, key);
|
|
93
|
-
else if (ended) {
|
|
94
|
-
open.push({
|
|
95
|
-
turn,
|
|
96
|
-
key,
|
|
97
|
-
work: { kind: 'subagent', title: part.description, next: null, activity: null },
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (part.type !== 'marker' || part.marker !== 'job')
|
|
103
|
-
continue;
|
|
104
|
-
markerMoved(open, part.text, (job, key) => ended
|
|
105
|
-
? {
|
|
106
|
-
turn,
|
|
107
|
-
key,
|
|
108
|
-
work: {
|
|
109
|
-
kind: job.kind === 'started' ? 'job' : 'schedule',
|
|
110
|
-
title: job.label,
|
|
111
|
-
next: job.next,
|
|
112
|
-
activity: null,
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
: null);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const doing = [...subagents];
|
|
119
|
-
const under = new Map();
|
|
120
|
-
for (const { turn, work } of open) {
|
|
121
|
-
const at = work.kind === 'subagent' ? doing.findIndex((one) => one.description === work.title) : -1;
|
|
122
|
-
const shown = at === -1 ? work : { ...work, activity: doing.splice(at, 1)[0].activity };
|
|
123
|
-
under.set(turn, [...(under.get(turn) ?? []), shown]);
|
|
124
|
-
}
|
|
125
|
-
return under;
|
|
35
|
+
return turnLine(parts, null);
|
|
126
36
|
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare function normalize(path: string): string | null;
|
|
2
2
|
export declare function beneath(prefix: string, path: string): boolean;
|
|
3
3
|
export declare function covered(prefixes: readonly string[], path: string): boolean;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function documentAt(patterns: readonly string[], path: string): boolean;
|
|
5
5
|
export declare function ancestors(path: string): readonly string[];
|
|
6
6
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/paths.js
CHANGED
|
@@ -41,7 +41,7 @@ function matched(pattern, path) {
|
|
|
41
41
|
return ((open ? names.length > fixed.length : names.length === fixed.length) &&
|
|
42
42
|
fixed.every((one, at) => named(one, names[at])));
|
|
43
43
|
}
|
|
44
|
-
export function
|
|
44
|
+
export function documentAt(patterns, path) {
|
|
45
45
|
return patterns.some((pattern) => matched(pattern, path));
|
|
46
46
|
}
|
|
47
47
|
export function ancestors(path) {
|
package/dist/preparation.d.ts
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type InstallShare } from './install.js';
|
|
2
|
+
import { type ReadinessChange } from './observation.js';
|
|
2
3
|
import { type PortReach } from './reach.js';
|
|
3
|
-
import { type CodeAvailability, type ConnectionAvailability, type Readiness } from './readiness.js';
|
|
4
|
+
import { type CodeAvailability, type ConnectionAvailability, type FirstTier, type Readiness, type RoomCoverage } from './readiness.js';
|
|
4
5
|
import type { Runtime } from './runtime.js';
|
|
5
6
|
export type ReadinessPort = {
|
|
6
7
|
readonly target: string;
|
|
7
8
|
readonly code: CodeAvailability;
|
|
9
|
+
readonly first: FirstTier | null;
|
|
10
|
+
readonly inboxed: readonly string[] | null;
|
|
8
11
|
};
|
|
12
|
+
export type ReadinessMessage = Readiness | ReadinessChange;
|
|
9
13
|
export type ReadinessWatch = {
|
|
10
14
|
readonly port: ReadinessPort;
|
|
11
15
|
readonly reach: PortReach | null;
|
|
12
|
-
readonly deliver: (readiness:
|
|
16
|
+
readonly deliver: (readiness: ReadinessMessage) => void;
|
|
17
|
+
};
|
|
18
|
+
type Share = InstallShare & {
|
|
19
|
+
readonly coverage: RoomCoverage;
|
|
20
|
+
};
|
|
21
|
+
type Settled = {
|
|
22
|
+
acquiring: number;
|
|
23
|
+
unsettled: number;
|
|
24
|
+
};
|
|
25
|
+
type Totals = Settled & {
|
|
26
|
+
installing: number;
|
|
27
|
+
downloading: number;
|
|
28
|
+
done: number;
|
|
29
|
+
total: number;
|
|
30
|
+
};
|
|
31
|
+
export type ReadinessShowing = {
|
|
32
|
+
readonly listing: number;
|
|
33
|
+
readonly roomsListed: boolean;
|
|
34
|
+
readonly named: ReadonlySet<string> | null;
|
|
35
|
+
readonly rooms: Map<string, Share>;
|
|
36
|
+
readonly first: Map<string, string>;
|
|
37
|
+
readonly totals: Totals;
|
|
38
|
+
shown: string;
|
|
13
39
|
};
|
|
14
40
|
export declare function prepare(runtime: Runtime, locators?: readonly string[]): void;
|
|
15
|
-
export declare function roomsOfReach(reach: PlanReach): ReadonlySet<string>;
|
|
16
41
|
export declare function connectionNow(runtime: Runtime): Promise<ConnectionAvailability>;
|
|
17
|
-
export declare function deliverOwedReadiness(runtime: Runtime, owed: readonly ReadinessWatch[]): Promise<void>;
|
|
18
|
-
export declare function watchReadiness({ store }: Runtime, port: ReadinessPort, reach: PortReach | null, deliver: (readiness:
|
|
19
|
-
export declare function filled(
|
|
42
|
+
export declare function deliverOwedReadiness(runtime: Runtime, owed: readonly ReadinessWatch[], touched: ReadonlySet<string> | null): Promise<void>;
|
|
43
|
+
export declare function watchReadiness({ store }: Runtime, port: ReadinessPort, reach: PortReach | null, deliver: (readiness: ReadinessMessage) => void): () => void;
|
|
44
|
+
export declare function filled({ store, socket }: Runtime): void;
|
|
45
|
+
export {};
|
|
20
46
|
//# sourceMappingURL=preparation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preparation.d.ts","sourceRoot":"","sources":["../src/preparation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preparation.d.ts","sourceRoot":"","sources":["../src/preparation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAE3B,KAAK,SAAS,EACd,KAAK,SAAS,EAEd,KAAK,YAAY,EAGlB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,eAAe,CAAC;AAE3D,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,gBAAgB,KAAK,IAAI,CAAC;CACzD,CAAC;AAEF,KAAK,KAAK,GAAG,YAAY,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,CAAC;AAEhE,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,MAAM,GAAG,OAAO,GAAG;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAwCF,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,GAAE,SAAS,MAAM,EAAO,QA4BzE;AAqGD,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAOrF;AA8MD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,SAAS,cAAc,EAAE,EAC/B,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,iBAKpC;AAED,wBAAgB,cAAc,CAC5B,EAAE,KAAK,EAAE,EAAE,OAAO,EAClB,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,OAAO,EAAE,CAAC,SAAS,EAAE,gBAAgB,KAAK,IAAI,GAC7C,MAAM,IAAI,CAWZ;AAED,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,QAGhD"}
|
package/dist/preparation.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { changeSet } from './change-set.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
3
|
+
import { installationOf, installShare } from './install.js';
|
|
4
|
+
import { listedLocators, listedOrHeld } from './listing.js';
|
|
5
|
+
import { keyedAt, keyedChange, unchanged, } from './observation.js';
|
|
4
6
|
import { planReach } from './reach.js';
|
|
5
|
-
import { readinessOf, } from './readiness.js';
|
|
6
|
-
import {
|
|
7
|
+
import { COMPLETE_ROOMS, readinessOf, } from './readiness.js';
|
|
8
|
+
import { roomsOfReach } from './rows.js';
|
|
7
9
|
import { recoverReads } from './shown.js';
|
|
8
10
|
import { yielded } from './turn.js';
|
|
9
11
|
async function prepareReplica(runtime, locator) {
|
|
@@ -22,22 +24,23 @@ async function prepareReplica(runtime, locator) {
|
|
|
22
24
|
if ((await store.rooms([locator])).get(locator)?.record.key !== key)
|
|
23
25
|
continue;
|
|
24
26
|
store.changed(changeSet(locator, { documents: null }));
|
|
25
|
-
recoverReads(runtime);
|
|
26
|
-
store.readiness.queue();
|
|
27
|
+
recoverReads(runtime, [locator]);
|
|
28
|
+
store.readiness.queue([locator]);
|
|
27
29
|
return;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
async function unprepared({ store
|
|
32
|
+
async function unprepared({ store }) {
|
|
31
33
|
const held = (await store.covering()).rooms;
|
|
32
|
-
|
|
34
|
+
const { unpreparedDemand, unpreparable } = store.device.now();
|
|
35
|
+
return [...unpreparedDemand, ...held.keys()].find((locator) => !(held.get(locator)?.indexed ?? false) && !unpreparable.has(locator));
|
|
33
36
|
}
|
|
34
|
-
function unpreparedBy({ store
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
store.readiness.queue();
|
|
37
|
+
function unpreparedBy({ store }, locator) {
|
|
38
|
+
const { unpreparable } = store.device.now();
|
|
39
|
+
store.device.set({ unpreparable: new Set([...unpreparable, locator]) });
|
|
40
|
+
store.readiness.queue([locator]);
|
|
38
41
|
}
|
|
39
42
|
export function prepare(runtime, locators = []) {
|
|
40
|
-
const { store, socket
|
|
43
|
+
const { store, socket } = runtime;
|
|
41
44
|
const { device } = store;
|
|
42
45
|
if (locators.length > 0) {
|
|
43
46
|
device.set({ unpreparedDemand: new Set([...device.now().unpreparedDemand, ...locators]) });
|
|
@@ -54,37 +57,31 @@ export function prepare(runtime, locators = []) {
|
|
|
54
57
|
const demand = new Set(device.now().unpreparedDemand);
|
|
55
58
|
demand.delete(waiting);
|
|
56
59
|
device.set({ unpreparedDemand: demand });
|
|
57
|
-
await prepareReplica(runtime, waiting).catch((
|
|
60
|
+
await prepareReplica(runtime, waiting).catch(() => unpreparedBy(runtime, waiting));
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
|
-
catch {
|
|
61
|
-
|
|
63
|
+
catch (error) {
|
|
64
|
+
uncaught(error);
|
|
62
65
|
}
|
|
63
66
|
finally {
|
|
64
67
|
device.set({ preparing: false });
|
|
65
68
|
}
|
|
66
69
|
})();
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return { listed: named.every((room) => held.has(room)), rooms: named };
|
|
81
|
-
}
|
|
82
|
-
function roomState({ socket }, locator, held) {
|
|
83
|
-
const listedRoom = socket.rooms.discovered(locator);
|
|
71
|
+
function requires(runtime, named, held, room) {
|
|
72
|
+
const listed = listedOrHeld(runtime, held, room);
|
|
73
|
+
if (named === null)
|
|
74
|
+
return listed;
|
|
75
|
+
return named.has(room) && (!runtime.socket.session.now().roomsListed || listed);
|
|
76
|
+
}
|
|
77
|
+
function requiredRooms(runtime, named, held) {
|
|
78
|
+
return [...(named ?? listedLocators(runtime, held))]
|
|
79
|
+
.filter((room) => requires(runtime, named, held, room))
|
|
80
|
+
.sort();
|
|
81
|
+
}
|
|
82
|
+
function roomState({ socket, presence }, locator, held) {
|
|
84
83
|
if (socket.session.now().roomsListed &&
|
|
85
|
-
(
|
|
86
|
-
listedRoom.replica.admission !== 'admitted' ||
|
|
87
|
-
socket.rooms.standing(locator).unreadable))
|
|
84
|
+
(presence.room(locator) === undefined || !presence.available(locator)))
|
|
88
85
|
return 'unadmitted';
|
|
89
86
|
const stored = held.get(locator);
|
|
90
87
|
if (stored === undefined)
|
|
@@ -101,6 +98,41 @@ function conversationCoverage({ socket, conversations }, reach) {
|
|
|
101
98
|
return 'acquiring';
|
|
102
99
|
return 'complete';
|
|
103
100
|
}
|
|
101
|
+
function listCoverage({ socket, conversations }, first) {
|
|
102
|
+
if (!first.conversations || socket.conversations() === undefined)
|
|
103
|
+
return 'undeclared';
|
|
104
|
+
return conversations.listHeld() ? 'complete' : 'acquiring';
|
|
105
|
+
}
|
|
106
|
+
function tierOf(roomsListed, named, { acquiring, unsettled }, conversations) {
|
|
107
|
+
return { listed: roomsListed || (named && acquiring === 0), unsettled, conversations };
|
|
108
|
+
}
|
|
109
|
+
function placed({ presence }, tier, first, room, held) {
|
|
110
|
+
if (tier === null)
|
|
111
|
+
return;
|
|
112
|
+
const handle = presence.room(room)?.handle ?? held.get(room)?.handle;
|
|
113
|
+
if (handle !== undefined && tier.handles.includes(handle))
|
|
114
|
+
first.set(handle, room);
|
|
115
|
+
}
|
|
116
|
+
function firstOf(runtime, tier, inboxed, { roomsListed, rooms, first }) {
|
|
117
|
+
const settled = { acquiring: 0, unsettled: 0 };
|
|
118
|
+
const counted = (room) => {
|
|
119
|
+
const share = room === undefined ? undefined : rooms.get(room);
|
|
120
|
+
if (share !== undefined)
|
|
121
|
+
settledBy(settled, share.coverage.state, 1);
|
|
122
|
+
else if (!roomsListed)
|
|
123
|
+
settledBy(settled, 'acquiring', 1);
|
|
124
|
+
};
|
|
125
|
+
for (const handle of tier.handles)
|
|
126
|
+
counted(first.get(handle));
|
|
127
|
+
if (tier.inboxes) {
|
|
128
|
+
if (inboxed === null)
|
|
129
|
+
settledBy(settled, 'acquiring', 1);
|
|
130
|
+
else
|
|
131
|
+
for (const room of inboxed)
|
|
132
|
+
counted(room);
|
|
133
|
+
}
|
|
134
|
+
return tierOf(roomsListed, true, settled, listCoverage(runtime, tier));
|
|
135
|
+
}
|
|
104
136
|
function connectionOf({ socket }, lastCompleted) {
|
|
105
137
|
if (socket.isOpen())
|
|
106
138
|
return 'connected';
|
|
@@ -113,30 +145,103 @@ export async function connectionNow(runtime) {
|
|
|
113
145
|
if (socket.isOpen() || socket.session.now().moving.providerUnreachable || socket.streamed) {
|
|
114
146
|
return connectionOf(runtime, null);
|
|
115
147
|
}
|
|
116
|
-
|
|
148
|
+
if (!store.needed())
|
|
149
|
+
return connectionOf(runtime, socket.session.now().lastCompleted);
|
|
150
|
+
return connectionOf(runtime, (await (await store.open()).facts(['lastCompleted'])).lastCompleted);
|
|
117
151
|
}
|
|
118
|
-
async function readinessHeld({ store }) {
|
|
152
|
+
async function readinessHeld({ store, socket }) {
|
|
153
|
+
if (!store.needed()) {
|
|
154
|
+
return {
|
|
155
|
+
held: new Map(),
|
|
156
|
+
facts: { lastCompleted: socket.session.now().lastCompleted, targets: {} },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
119
159
|
const local = await store.open();
|
|
120
|
-
const [held, facts] = await Promise.all([
|
|
160
|
+
const [held, facts] = await Promise.all([
|
|
161
|
+
store.covering(),
|
|
162
|
+
local.facts(['lastCompleted', 'targets']),
|
|
163
|
+
]);
|
|
121
164
|
return { held: held.rooms, facts };
|
|
122
165
|
}
|
|
123
|
-
function
|
|
124
|
-
const {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
166
|
+
function shareOf(runtime, room, held) {
|
|
167
|
+
const coverage = Object.freeze({ room, state: roomState(runtime, room, held) });
|
|
168
|
+
return { ...installShare(runtime.store, coverage, held), coverage };
|
|
169
|
+
}
|
|
170
|
+
function sameState(was, now) {
|
|
171
|
+
return was.coverage.state === now.coverage.state;
|
|
172
|
+
}
|
|
173
|
+
function coverageOf(change) {
|
|
174
|
+
return {
|
|
175
|
+
...change,
|
|
176
|
+
changed: change.changed.map(([room, share]) => [room, share.coverage]),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function settledBy(settled, state, sign) {
|
|
180
|
+
settled.acquiring += state === 'acquiring' ? sign : 0;
|
|
181
|
+
settled.unsettled += COMPLETE_ROOMS.has(state) ? 0 : sign;
|
|
182
|
+
}
|
|
183
|
+
function counted(totals, share, sign) {
|
|
184
|
+
totals.installing += share.installing ? sign : 0;
|
|
185
|
+
totals.downloading += share.downloading ? sign : 0;
|
|
186
|
+
settledBy(totals, share.coverage.state, sign);
|
|
187
|
+
totals.done += sign * share.bytes.done;
|
|
188
|
+
totals.total += sign * share.bytes.total;
|
|
189
|
+
}
|
|
190
|
+
function showingOf(runtime, { port, reach }, held) {
|
|
191
|
+
const planned = planReach(reach);
|
|
192
|
+
const named = planned === null ? null : roomsOfReach(planned);
|
|
193
|
+
const totals = { installing: 0, downloading: 0, acquiring: 0, unsettled: 0, done: 0, total: 0 };
|
|
194
|
+
const rooms = new Map();
|
|
195
|
+
const first = new Map();
|
|
196
|
+
for (const room of requiredRooms(runtime, named, held)) {
|
|
197
|
+
const share = shareOf(runtime, room, held);
|
|
198
|
+
rooms.set(room, share);
|
|
199
|
+
placed(runtime, port.first, first, room, held);
|
|
200
|
+
counted(totals, share, 1);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
listing: runtime.presence.listing(),
|
|
204
|
+
roomsListed: runtime.socket.session.now().roomsListed,
|
|
205
|
+
named,
|
|
206
|
+
rooms,
|
|
207
|
+
first,
|
|
208
|
+
totals,
|
|
209
|
+
shown: '',
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function moved(runtime, { port }, showing, held, touched) {
|
|
213
|
+
const at = new Map();
|
|
214
|
+
for (const room of touched) {
|
|
215
|
+
at.set(room, requires(runtime, showing.named, held, room) ? shareOf(runtime, room, held) : null);
|
|
216
|
+
}
|
|
217
|
+
const change = keyedAt(showing.rooms, at, sameState);
|
|
218
|
+
if (change === null || change.removed.length > 0)
|
|
219
|
+
return null;
|
|
220
|
+
for (const [room, share] of at) {
|
|
221
|
+
if (share === null)
|
|
222
|
+
continue;
|
|
223
|
+
counted(showing.totals, showing.rooms.get(room), -1);
|
|
224
|
+
counted(showing.totals, share, 1);
|
|
225
|
+
showing.rooms.set(room, share);
|
|
226
|
+
placed(runtime, port.first, showing.first, room, held);
|
|
227
|
+
}
|
|
228
|
+
return change;
|
|
229
|
+
}
|
|
230
|
+
function preparingIn(runtime, showing, rooms) {
|
|
231
|
+
const { unpreparable } = runtime.store.device.now();
|
|
232
|
+
const preparing = [...rooms].filter((room) => showing.rooms.get(room)?.coverage.state === 'preparing' && !unpreparable.has(room));
|
|
130
233
|
if (preparing.length > 0)
|
|
131
234
|
prepare(runtime, preparing);
|
|
132
|
-
|
|
235
|
+
}
|
|
236
|
+
function shownOf(runtime, { port, reach }, showing, { facts }) {
|
|
237
|
+
const { store, socket } = runtime;
|
|
238
|
+
const { persistence, storageLoss } = store.device.now();
|
|
239
|
+
const { named, totals, roomsListed } = showing;
|
|
240
|
+
const coverage = tierOf(roomsListed, named !== null, totals, conversationCoverage(runtime, reach));
|
|
133
241
|
return readinessOf({
|
|
134
242
|
code: port.code,
|
|
135
|
-
coverage
|
|
136
|
-
|
|
137
|
-
rooms: coverage,
|
|
138
|
-
conversations: conversationCoverage(runtime, reach),
|
|
139
|
-
},
|
|
243
|
+
coverage,
|
|
244
|
+
first: port.first === null ? coverage : firstOf(runtime, port.first, port.inboxed, showing),
|
|
140
245
|
persistence,
|
|
141
246
|
connection: connectionOf(runtime, facts.lastCompleted),
|
|
142
247
|
house: socket.session.now().refusal !== null
|
|
@@ -145,82 +250,95 @@ function readinessFor(runtime, port, reach, { held, facts }) {
|
|
|
145
250
|
? 'write-halted'
|
|
146
251
|
: 'open',
|
|
147
252
|
space: store.space.full() ? 'full' : null,
|
|
148
|
-
installation: installationOf(
|
|
253
|
+
installation: installationOf(totals.installing, totals.downloading, {
|
|
254
|
+
done: totals.done,
|
|
255
|
+
total: totals.total,
|
|
256
|
+
}),
|
|
149
257
|
lost: storageLoss !== null,
|
|
150
|
-
established: facts.targets[port.target]?.established === true
|
|
151
|
-
(heldWhenOpened && usableWhenHeld.includes(port.target)),
|
|
258
|
+
established: facts.targets[port.target]?.established === true,
|
|
152
259
|
});
|
|
153
260
|
}
|
|
154
|
-
function establish(
|
|
155
|
-
const { store, journal } = runtime;
|
|
261
|
+
function establish({ store }, name) {
|
|
156
262
|
const { device } = store;
|
|
157
|
-
if (device.now().establishing.has(name))
|
|
263
|
+
if (device.now().establishing.has(name) || !store.needed())
|
|
158
264
|
return;
|
|
159
265
|
device.set({ establishing: new Set([...device.now().establishing, name]) });
|
|
160
266
|
void store
|
|
161
267
|
.durably(async (local) => {
|
|
162
|
-
const { targets } = await local.facts();
|
|
268
|
+
const { targets } = await local.facts(['targets']);
|
|
163
269
|
await local.fact('targets', { ...targets, [name]: { established: true } });
|
|
164
270
|
})
|
|
165
|
-
.then(() =>
|
|
166
|
-
store.readiness.queue();
|
|
167
|
-
void probeEachMinute(runtime);
|
|
168
|
-
}, () => {
|
|
169
|
-
journal.record(`target record failed ${name}`);
|
|
170
|
-
})
|
|
271
|
+
.then(() => store.readiness.queue([]), uncaught)
|
|
171
272
|
.finally(() => {
|
|
172
273
|
const establishing = new Set(device.now().establishing);
|
|
173
274
|
establishing.delete(name);
|
|
174
275
|
device.set({ establishing });
|
|
175
276
|
});
|
|
176
277
|
}
|
|
177
|
-
function deliverReadiness(runtime, watch, held) {
|
|
178
|
-
|
|
278
|
+
function deliverReadiness(runtime, watch, held, touched) {
|
|
279
|
+
const { readiness } = runtime.store;
|
|
280
|
+
if (!readiness.held(watch))
|
|
179
281
|
return;
|
|
180
|
-
const
|
|
181
|
-
|
|
282
|
+
const kept = readiness.kept(watch);
|
|
283
|
+
const patched = kept === undefined ||
|
|
284
|
+
touched === null ||
|
|
285
|
+
kept.listing !== runtime.presence.listing() ||
|
|
286
|
+
kept.roomsListed !== runtime.socket.session.now().roomsListed
|
|
287
|
+
? null
|
|
288
|
+
: moved(runtime, watch, kept, held.held, touched);
|
|
289
|
+
const showing = patched === null ? showingOf(runtime, watch, held.held) : kept;
|
|
290
|
+
preparingIn(runtime, showing, patched === null ? showing.rooms.keys() : touched);
|
|
291
|
+
const shown = shownOf(runtime, watch, showing, held);
|
|
292
|
+
if (shown.usable)
|
|
293
|
+
probeEachMinute(runtime);
|
|
294
|
+
if (shown.ready && held.facts.targets[watch.port.target]?.established !== true) {
|
|
182
295
|
establish(runtime, watch.port.target);
|
|
183
296
|
}
|
|
184
|
-
|
|
297
|
+
const text = JSON.stringify(shown);
|
|
298
|
+
const before = kept?.shown;
|
|
299
|
+
showing.shown = text;
|
|
300
|
+
readiness.keep(watch, showing);
|
|
301
|
+
if (kept === undefined) {
|
|
302
|
+
watch.deliver({
|
|
303
|
+
...shown,
|
|
304
|
+
coverage: {
|
|
305
|
+
...shown.coverage,
|
|
306
|
+
rooms: [...showing.rooms.values()].map(({ coverage }) => coverage),
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const rooms = coverageOf(patched ??
|
|
312
|
+
keyedChange(kept.rooms, [...showing.rooms.keys()], [...showing.rooms.values()], sameState));
|
|
313
|
+
if (text === before && unchanged(rooms))
|
|
185
314
|
return;
|
|
186
|
-
watch.deliver(
|
|
315
|
+
watch.deliver({ shown, rooms });
|
|
187
316
|
}
|
|
188
|
-
export async function deliverOwedReadiness(runtime, owed) {
|
|
317
|
+
export async function deliverOwedReadiness(runtime, owed, touched) {
|
|
189
318
|
const held = await readinessHeld(runtime);
|
|
190
319
|
if (runtime.socket.closed())
|
|
191
320
|
return;
|
|
192
321
|
for (const watch of owed)
|
|
193
|
-
deliverReadiness(runtime, watch, held);
|
|
322
|
+
deliverReadiness(runtime, watch, held, touched);
|
|
194
323
|
}
|
|
195
324
|
export function watchReadiness({ store }, port, reach, deliver) {
|
|
196
325
|
const watch = { port, reach, deliver };
|
|
197
326
|
const stop = store.readiness.add(watch);
|
|
198
|
-
|
|
327
|
+
if (!store.needed())
|
|
328
|
+
store.readiness.owe([watch]);
|
|
329
|
+
else {
|
|
330
|
+
void store.open().then(() => store.readiness.owe([watch]), () => store.readiness.owe([watch]));
|
|
331
|
+
}
|
|
199
332
|
return stop;
|
|
200
333
|
}
|
|
201
|
-
export function filled(
|
|
202
|
-
const { store, socket, journal } = runtime;
|
|
334
|
+
export function filled({ store, socket }) {
|
|
203
335
|
if (socket.closed() || !store.space.fill())
|
|
204
336
|
return;
|
|
205
|
-
|
|
206
|
-
store.readiness.queue();
|
|
207
|
-
void probeEachMinute(runtime);
|
|
337
|
+
store.readiness.queue([]);
|
|
208
338
|
}
|
|
209
|
-
|
|
210
|
-
if (store.device.now().heldWhenOpened && usableWhenHeld.length > 0)
|
|
211
|
-
return true;
|
|
212
|
-
const { targets } = await (await store.open()).facts();
|
|
213
|
-
return Object.values(targets).some((target) => target.established);
|
|
214
|
-
}
|
|
215
|
-
async function probeEachMinute(runtime) {
|
|
216
|
-
const { store, socket } = runtime;
|
|
339
|
+
function probeEachMinute({ store, socket }) {
|
|
217
340
|
const { space } = store;
|
|
218
|
-
|
|
219
|
-
if (idle())
|
|
220
|
-
return;
|
|
221
|
-
if (!(await installedTarget(runtime).catch(() => false)))
|
|
222
|
-
return;
|
|
223
|
-
if (idle())
|
|
341
|
+
if (!space.full() || space.probing() || socket.closed())
|
|
224
342
|
return;
|
|
225
343
|
space.probeEachMinute();
|
|
226
344
|
}
|