@agentshouse/mdruntime 0.1.0-c835af48a82d3 → 0.1.0-c83bc1fac9b35
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 +3 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +299 -0
- 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 +26 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +321 -0
- package/dist/adapter.d.ts +115 -57
- 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 +0 -5
- 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 -18
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- 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 +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +7 -2
- package/dist/chat-types.d.ts +2 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +11 -2
- package/dist/client.d.ts +26 -22
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +45 -58
- package/dist/collection.d.ts +26 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +28 -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 +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +31 -25
- package/dist/connection.d.ts +5 -149
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +112 -5364
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +152 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +261 -0
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +22 -3
- package/dist/conversation.d.ts +57 -45
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +977 -1031
- 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 +12 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- 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 +14 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +5 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +23 -12
- 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 -0
- 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 +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +24 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +87 -20
- package/dist/house-query.d.ts +21 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +41 -0
- package/dist/index.d.ts +30 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- package/dist/install.d.ts +60 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +537 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +290 -0
- package/dist/listing.d.ts +60 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +168 -0
- package/dist/live.d.ts +5 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +74 -33
- package/dist/loaded.d.ts +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -0
- package/dist/locks.d.ts +7 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +34 -0
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +49 -0
- package/dist/media.d.ts +19 -2
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +105 -27
- package/dist/memory.d.ts +9 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +94 -32
- package/dist/messages.d.ts +12 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +35 -39
- 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 +4 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +10 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +153 -0
- 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 +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +69 -0
- package/dist/outcome.d.ts +16 -2
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +32 -2
- package/dist/overlay.d.ts +6 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +37 -24
- 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 +5 -58
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +28 -110
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +45 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +335 -0
- 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 +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +287 -0
- package/dist/query.d.ts +0 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +3 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +4 -6
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +15 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +164 -33
- package/dist/react.d.ts +18 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +33 -1
- package/dist/readiness.d.ts +16 -5
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +10 -10
- package/dist/reads.d.ts +6 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +61 -11
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +5 -13
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +17 -18
- 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 +31 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +273 -66
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +220 -0
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +9 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +35 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +42 -86
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +326 -225
- package/dist/saves.d.ts +34 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +437 -0
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +35 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +326 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +28 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +103 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/session.d.ts +41 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +26 -0
- package/dist/socket.d.ts +68 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +165 -0
- package/dist/source.d.ts +5 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +18 -6
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +40 -0
- package/dist/store/readiness.d.ts +11 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +68 -0
- package/dist/store/records.d.ts +227 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +468 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- 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 +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +119 -204
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +170 -394
- package/dist/stored.d.ts +26 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +101 -36
- package/dist/surface.d.ts +94 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +255 -0
- package/dist/sync.d.ts +21 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +557 -0
- package/dist/tables.d.ts +28 -59
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +106 -331
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +6 -7
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +4 -10
- package/dist/wire.d.ts +68 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +26 -9
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- 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 -5
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
package/dist/parts.js
CHANGED
|
@@ -1,118 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { excerpt
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
case 'reasoning': {
|
|
9
|
-
const said = text(part, 'text');
|
|
10
|
-
return said === null ? null : { type: part.type, text: said };
|
|
11
|
-
}
|
|
12
|
-
case 'commands':
|
|
13
|
-
return typeof part.count === 'number' ? { type: 'commands', count: part.count } : null;
|
|
14
|
-
case 'subagent':
|
|
15
|
-
return {
|
|
16
|
-
type: 'subagent',
|
|
17
|
-
description: text(part, 'description') ?? '',
|
|
18
|
-
done: part.status === 'done',
|
|
19
|
-
result: text(part, 'result'),
|
|
20
|
-
};
|
|
21
|
-
case 'message': {
|
|
22
|
-
const command = text(part, 'command');
|
|
23
|
-
return command === null ? null : { type: 'message', command, target: text(part, 'target') };
|
|
24
|
-
}
|
|
25
|
-
case 'image': {
|
|
26
|
-
const path = text(part, 'file');
|
|
27
|
-
const name = text(part, 'name');
|
|
28
|
-
return path === null || name === null
|
|
29
|
-
? null
|
|
30
|
-
: { type: 'image', path, name, mediaType: text(part, 'media_type') ?? '' };
|
|
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
|
-
}
|
|
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);
|
|
50
8
|
}
|
|
51
|
-
export function
|
|
52
|
-
return
|
|
9
|
+
export function linesWords(added, removed) {
|
|
10
|
+
return `+${added} −${removed}`;
|
|
53
11
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return typeof held.used === 'number' && typeof held.window === 'number' && held.window > 0
|
|
57
|
-
? { used: held.used, window: held.window }
|
|
58
|
-
: null;
|
|
12
|
+
function capitalized(words) {
|
|
13
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
59
14
|
}
|
|
60
|
-
export function
|
|
61
|
-
|
|
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(' · ');
|
|
62
30
|
}
|
|
63
|
-
export function runningLine(
|
|
64
|
-
const parts = partsOf(raw);
|
|
31
|
+
export function runningLine(parts) {
|
|
65
32
|
const note = [...parts].reverse().find((part) => part.type === 'text' && part.text.trim() !== '');
|
|
66
33
|
if (note?.type === 'text')
|
|
67
34
|
return excerpt(note.text);
|
|
68
|
-
|
|
69
|
-
return commands === 0 ? null : counted(commands);
|
|
70
|
-
}
|
|
71
|
-
export function jobsOf(markers, turn) {
|
|
72
|
-
const running = (turn === null ? [] : partsOf(turn.parts)).flatMap((part) => part.type === 'marker' && part.marker === 'job'
|
|
73
|
-
? [{ said: part.text, at: turn?.started ?? null }]
|
|
74
|
-
: []);
|
|
75
|
-
return openJobs([...markers, ...running]);
|
|
76
|
-
}
|
|
77
|
-
export function stillRunning(turns, subagents) {
|
|
78
|
-
const open = [];
|
|
79
|
-
for (const { turn, parts, ended } of turns) {
|
|
80
|
-
for (const part of parts) {
|
|
81
|
-
if (part.type === 'subagent') {
|
|
82
|
-
const key = `subagent\u0000${part.description}`;
|
|
83
|
-
if (part.done)
|
|
84
|
-
closeLast(open, key);
|
|
85
|
-
else if (ended) {
|
|
86
|
-
open.push({
|
|
87
|
-
turn,
|
|
88
|
-
key,
|
|
89
|
-
work: { kind: 'subagent', title: part.description, next: null, activity: null },
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (part.type !== 'marker' || part.marker !== 'job')
|
|
95
|
-
continue;
|
|
96
|
-
markerMoved(open, part.text, (job, key) => ended
|
|
97
|
-
? {
|
|
98
|
-
turn,
|
|
99
|
-
key,
|
|
100
|
-
work: {
|
|
101
|
-
kind: job.kind === 'started' ? 'job' : 'schedule',
|
|
102
|
-
title: job.label,
|
|
103
|
-
next: job.next,
|
|
104
|
-
activity: null,
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
: null);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const doing = [...subagents];
|
|
111
|
-
const under = new Map();
|
|
112
|
-
for (const { turn, work } of open) {
|
|
113
|
-
const at = work.kind === 'subagent' ? doing.findIndex((one) => one.description === work.title) : -1;
|
|
114
|
-
const shown = at === -1 ? work : { ...work, activity: doing.splice(at, 1)[0].activity };
|
|
115
|
-
under.set(turn, [...(under.get(turn) ?? []), shown]);
|
|
116
|
-
}
|
|
117
|
-
return under;
|
|
35
|
+
return turnLine(parts, null);
|
|
118
36
|
}
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,5 +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 authoredAt(patterns: readonly string[], path: string): boolean;
|
|
4
5
|
export declare function ancestors(path: string): readonly string[];
|
|
5
6
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAK1E;AAwBD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAGzD"}
|
package/dist/paths.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDocumentPath } from '@agentshouse/mdmodel';
|
|
1
2
|
export function normalize(path) {
|
|
2
3
|
const parts = [];
|
|
3
4
|
for (const part of path.split('/')) {
|
|
@@ -22,6 +23,27 @@ export function covered(prefixes, path) {
|
|
|
22
23
|
return normalized !== null && (normalized === '' || beneath(normalized, path));
|
|
23
24
|
});
|
|
24
25
|
}
|
|
26
|
+
function named(pattern, name) {
|
|
27
|
+
const star = pattern.indexOf('*');
|
|
28
|
+
if (star === -1)
|
|
29
|
+
return pattern === name;
|
|
30
|
+
const before = pattern.slice(0, star);
|
|
31
|
+
const after = pattern.slice(star + 1);
|
|
32
|
+
return (name.length > before.length + after.length && name.startsWith(before) && name.endsWith(after));
|
|
33
|
+
}
|
|
34
|
+
function matched(pattern, path) {
|
|
35
|
+
if (pattern === '/')
|
|
36
|
+
return isDocumentPath(path);
|
|
37
|
+
const wanted = pattern.split('/');
|
|
38
|
+
const names = path.split('/');
|
|
39
|
+
const open = wanted.at(-1) === '**';
|
|
40
|
+
const fixed = open ? wanted.slice(0, -1) : wanted;
|
|
41
|
+
return ((open ? names.length > fixed.length : names.length === fixed.length) &&
|
|
42
|
+
fixed.every((one, at) => named(one, names[at])));
|
|
43
|
+
}
|
|
44
|
+
export function authoredAt(patterns, path) {
|
|
45
|
+
return patterns.some((pattern) => matched(pattern, path));
|
|
46
|
+
}
|
|
25
47
|
export function ancestors(path) {
|
|
26
48
|
const parts = path.split('/');
|
|
27
49
|
return parts.slice(1).map((_, at) => parts.slice(0, at + 1).join('/'));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type InstallShare } from './install.js';
|
|
2
|
+
import { type ReadinessChange } from './observation.js';
|
|
3
|
+
import { type PortReach } from './reach.js';
|
|
4
|
+
import { type CodeAvailability, type ConnectionAvailability, type FirstTier, type Readiness, type RoomCoverage } from './readiness.js';
|
|
5
|
+
import type { Runtime } from './runtime.js';
|
|
6
|
+
export type ReadinessPort = {
|
|
7
|
+
readonly target: string;
|
|
8
|
+
readonly code: CodeAvailability;
|
|
9
|
+
readonly first: FirstTier | null;
|
|
10
|
+
};
|
|
11
|
+
export type ReadinessMessage = Readiness | ReadinessChange;
|
|
12
|
+
export type ReadinessWatch = {
|
|
13
|
+
readonly port: ReadinessPort;
|
|
14
|
+
readonly reach: PortReach | null;
|
|
15
|
+
readonly deliver: (readiness: ReadinessMessage) => void;
|
|
16
|
+
};
|
|
17
|
+
type Share = InstallShare & {
|
|
18
|
+
readonly coverage: RoomCoverage;
|
|
19
|
+
};
|
|
20
|
+
type Settled = {
|
|
21
|
+
acquiring: number;
|
|
22
|
+
unsettled: number;
|
|
23
|
+
};
|
|
24
|
+
type Totals = Settled & {
|
|
25
|
+
installing: number;
|
|
26
|
+
downloading: number;
|
|
27
|
+
done: number;
|
|
28
|
+
total: number;
|
|
29
|
+
};
|
|
30
|
+
export type ReadinessShowing = {
|
|
31
|
+
readonly listing: number;
|
|
32
|
+
readonly roomsListed: boolean;
|
|
33
|
+
readonly named: ReadonlySet<string> | null;
|
|
34
|
+
readonly rooms: Map<string, Share>;
|
|
35
|
+
readonly first: Map<string, string>;
|
|
36
|
+
readonly totals: Totals;
|
|
37
|
+
shown: string;
|
|
38
|
+
};
|
|
39
|
+
export declare function prepare(runtime: Runtime, locators?: readonly string[]): void;
|
|
40
|
+
export declare function connectionNow(runtime: Runtime): Promise<ConnectionAvailability>;
|
|
41
|
+
export declare function deliverOwedReadiness(runtime: Runtime, owed: readonly ReadinessWatch[], touched: ReadonlySet<string> | null): Promise<void>;
|
|
42
|
+
export declare function watchReadiness({ store }: Runtime, port: ReadinessPort, reach: PortReach | null, deliver: (readiness: ReadinessMessage) => void): () => void;
|
|
43
|
+
export declare function filled({ store, socket }: Runtime): void;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=preparation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EACr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K,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;AA+FD,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"}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { changeSet } from './change-set.js';
|
|
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';
|
|
6
|
+
import { planReach } from './reach.js';
|
|
7
|
+
import { COMPLETE_ROOMS, readinessOf, } from './readiness.js';
|
|
8
|
+
import { roomsOfReach } from './rows.js';
|
|
9
|
+
import { recoverReads } from './shown.js';
|
|
10
|
+
import { yielded } from './turn.js';
|
|
11
|
+
async function prepareReplica(runtime, locator) {
|
|
12
|
+
const { store, socket } = runtime;
|
|
13
|
+
for (;;) {
|
|
14
|
+
const held = (await store.rooms([locator])).get(locator);
|
|
15
|
+
if (held === undefined || socket.closed() || held.indexed)
|
|
16
|
+
return;
|
|
17
|
+
const key = held.record.key;
|
|
18
|
+
const done = await store.exclusive(async () => {
|
|
19
|
+
const local = await store.open();
|
|
20
|
+
return store.rederive(local, key, store.composed(held.record));
|
|
21
|
+
});
|
|
22
|
+
if (!done.done)
|
|
23
|
+
continue;
|
|
24
|
+
if ((await store.rooms([locator])).get(locator)?.record.key !== key)
|
|
25
|
+
continue;
|
|
26
|
+
store.changed(changeSet(locator, { documents: null }));
|
|
27
|
+
recoverReads(runtime, [locator]);
|
|
28
|
+
store.readiness.queue([locator]);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function unprepared({ store }) {
|
|
33
|
+
const held = (await store.covering()).rooms;
|
|
34
|
+
const { unpreparedDemand, unpreparable } = store.device.now();
|
|
35
|
+
return [...unpreparedDemand, ...held.keys()].find((locator) => !(held.get(locator)?.indexed ?? false) && !unpreparable.has(locator));
|
|
36
|
+
}
|
|
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]);
|
|
41
|
+
}
|
|
42
|
+
export function prepare(runtime, locators = []) {
|
|
43
|
+
const { store, socket } = runtime;
|
|
44
|
+
const { device } = store;
|
|
45
|
+
if (locators.length > 0) {
|
|
46
|
+
device.set({ unpreparedDemand: new Set([...device.now().unpreparedDemand, ...locators]) });
|
|
47
|
+
}
|
|
48
|
+
if (device.now().preparing)
|
|
49
|
+
return;
|
|
50
|
+
device.set({ preparing: true });
|
|
51
|
+
void (async () => {
|
|
52
|
+
try {
|
|
53
|
+
for (let waiting = await unprepared(runtime); waiting !== undefined; waiting = await unprepared(runtime)) {
|
|
54
|
+
await yielded();
|
|
55
|
+
if (socket.closed())
|
|
56
|
+
return;
|
|
57
|
+
const demand = new Set(device.now().unpreparedDemand);
|
|
58
|
+
demand.delete(waiting);
|
|
59
|
+
device.set({ unpreparedDemand: demand });
|
|
60
|
+
await prepareReplica(runtime, waiting).catch(() => unpreparedBy(runtime, waiting));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
uncaught(error);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
device.set({ preparing: false });
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
70
|
+
}
|
|
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) {
|
|
83
|
+
if (socket.session.now().roomsListed &&
|
|
84
|
+
(presence.room(locator) === undefined || !presence.available(locator)))
|
|
85
|
+
return 'unadmitted';
|
|
86
|
+
const stored = held.get(locator);
|
|
87
|
+
if (stored === undefined)
|
|
88
|
+
return 'acquiring';
|
|
89
|
+
if (!stored.indexed)
|
|
90
|
+
return 'preparing';
|
|
91
|
+
return 'complete';
|
|
92
|
+
}
|
|
93
|
+
function conversationCoverage({ socket, conversations }, reach) {
|
|
94
|
+
const declaredConversations = reach === null || reach.conversations;
|
|
95
|
+
if (!declaredConversations || socket.conversations() === undefined)
|
|
96
|
+
return 'undeclared';
|
|
97
|
+
if (!conversations.known() || !conversations.current())
|
|
98
|
+
return 'acquiring';
|
|
99
|
+
return 'complete';
|
|
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, { roomsListed, rooms, first }) {
|
|
117
|
+
const settled = { acquiring: 0, unsettled: 0 };
|
|
118
|
+
for (const handle of tier.handles) {
|
|
119
|
+
const room = first.get(handle);
|
|
120
|
+
if (room !== undefined)
|
|
121
|
+
settledBy(settled, rooms.get(room).coverage.state, 1);
|
|
122
|
+
else if (!roomsListed)
|
|
123
|
+
settledBy(settled, 'acquiring', 1);
|
|
124
|
+
}
|
|
125
|
+
return tierOf(roomsListed, true, settled, listCoverage(runtime, tier));
|
|
126
|
+
}
|
|
127
|
+
function connectionOf({ socket }, lastCompleted) {
|
|
128
|
+
if (socket.isOpen())
|
|
129
|
+
return 'connected';
|
|
130
|
+
if (socket.session.now().moving.providerUnreachable)
|
|
131
|
+
return 'unreachable';
|
|
132
|
+
return !socket.streamed && lastCompleted !== null ? 'connected' : 'connecting';
|
|
133
|
+
}
|
|
134
|
+
export async function connectionNow(runtime) {
|
|
135
|
+
const { store, socket } = runtime;
|
|
136
|
+
if (socket.isOpen() || socket.session.now().moving.providerUnreachable || socket.streamed) {
|
|
137
|
+
return connectionOf(runtime, null);
|
|
138
|
+
}
|
|
139
|
+
if (!store.needed())
|
|
140
|
+
return connectionOf(runtime, socket.session.now().lastCompleted);
|
|
141
|
+
return connectionOf(runtime, (await (await store.open()).facts(['lastCompleted'])).lastCompleted);
|
|
142
|
+
}
|
|
143
|
+
async function readinessHeld({ store, socket }) {
|
|
144
|
+
if (!store.needed()) {
|
|
145
|
+
return {
|
|
146
|
+
held: new Map(),
|
|
147
|
+
facts: { lastCompleted: socket.session.now().lastCompleted, targets: {} },
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const local = await store.open();
|
|
151
|
+
const [held, facts] = await Promise.all([
|
|
152
|
+
store.covering(),
|
|
153
|
+
local.facts(['lastCompleted', 'targets']),
|
|
154
|
+
]);
|
|
155
|
+
return { held: held.rooms, facts };
|
|
156
|
+
}
|
|
157
|
+
function shareOf(runtime, room, held) {
|
|
158
|
+
const coverage = Object.freeze({ room, state: roomState(runtime, room, held) });
|
|
159
|
+
return { ...installShare(runtime.store, coverage, held), coverage };
|
|
160
|
+
}
|
|
161
|
+
function sameState(was, now) {
|
|
162
|
+
return was.coverage.state === now.coverage.state;
|
|
163
|
+
}
|
|
164
|
+
function coverageOf(change) {
|
|
165
|
+
return {
|
|
166
|
+
...change,
|
|
167
|
+
changed: change.changed.map(([room, share]) => [room, share.coverage]),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function settledBy(settled, state, sign) {
|
|
171
|
+
settled.acquiring += state === 'acquiring' ? sign : 0;
|
|
172
|
+
settled.unsettled += COMPLETE_ROOMS.has(state) ? 0 : sign;
|
|
173
|
+
}
|
|
174
|
+
function counted(totals, share, sign) {
|
|
175
|
+
totals.installing += share.installing ? sign : 0;
|
|
176
|
+
totals.downloading += share.downloading ? sign : 0;
|
|
177
|
+
settledBy(totals, share.coverage.state, sign);
|
|
178
|
+
totals.done += sign * share.bytes.done;
|
|
179
|
+
totals.total += sign * share.bytes.total;
|
|
180
|
+
}
|
|
181
|
+
function showingOf(runtime, { port, reach }, held) {
|
|
182
|
+
const planned = planReach(reach);
|
|
183
|
+
const named = planned === null ? null : roomsOfReach(planned);
|
|
184
|
+
const totals = { installing: 0, downloading: 0, acquiring: 0, unsettled: 0, done: 0, total: 0 };
|
|
185
|
+
const rooms = new Map();
|
|
186
|
+
const first = new Map();
|
|
187
|
+
for (const room of requiredRooms(runtime, named, held)) {
|
|
188
|
+
const share = shareOf(runtime, room, held);
|
|
189
|
+
rooms.set(room, share);
|
|
190
|
+
placed(runtime, port.first, first, room, held);
|
|
191
|
+
counted(totals, share, 1);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
listing: runtime.presence.listing(),
|
|
195
|
+
roomsListed: runtime.socket.session.now().roomsListed,
|
|
196
|
+
named,
|
|
197
|
+
rooms,
|
|
198
|
+
first,
|
|
199
|
+
totals,
|
|
200
|
+
shown: '',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function moved(runtime, { port }, showing, held, touched) {
|
|
204
|
+
const at = new Map();
|
|
205
|
+
for (const room of touched) {
|
|
206
|
+
at.set(room, requires(runtime, showing.named, held, room) ? shareOf(runtime, room, held) : null);
|
|
207
|
+
}
|
|
208
|
+
const change = keyedAt(showing.rooms, at, sameState);
|
|
209
|
+
if (change === null || change.removed.length > 0)
|
|
210
|
+
return null;
|
|
211
|
+
for (const [room, share] of at) {
|
|
212
|
+
if (share === null)
|
|
213
|
+
continue;
|
|
214
|
+
counted(showing.totals, showing.rooms.get(room), -1);
|
|
215
|
+
counted(showing.totals, share, 1);
|
|
216
|
+
showing.rooms.set(room, share);
|
|
217
|
+
placed(runtime, port.first, showing.first, room, held);
|
|
218
|
+
}
|
|
219
|
+
return change;
|
|
220
|
+
}
|
|
221
|
+
function preparingIn(runtime, showing, rooms) {
|
|
222
|
+
const { unpreparable } = runtime.store.device.now();
|
|
223
|
+
const preparing = [...rooms].filter((room) => showing.rooms.get(room)?.coverage.state === 'preparing' && !unpreparable.has(room));
|
|
224
|
+
if (preparing.length > 0)
|
|
225
|
+
prepare(runtime, preparing);
|
|
226
|
+
}
|
|
227
|
+
function shownOf(runtime, { port, reach }, showing, { facts }) {
|
|
228
|
+
const { store, socket } = runtime;
|
|
229
|
+
const { persistence, storageLoss } = store.device.now();
|
|
230
|
+
const { named, totals, roomsListed } = showing;
|
|
231
|
+
const coverage = tierOf(roomsListed, named !== null, totals, conversationCoverage(runtime, reach));
|
|
232
|
+
return readinessOf({
|
|
233
|
+
code: port.code,
|
|
234
|
+
coverage,
|
|
235
|
+
first: port.first === null ? coverage : firstOf(runtime, port.first, showing),
|
|
236
|
+
persistence,
|
|
237
|
+
connection: connectionOf(runtime, facts.lastCompleted),
|
|
238
|
+
house: socket.session.now().refusal !== null
|
|
239
|
+
? 'refused'
|
|
240
|
+
: socket.writesHeld()
|
|
241
|
+
? 'write-halted'
|
|
242
|
+
: 'open',
|
|
243
|
+
space: store.space.full() ? 'full' : null,
|
|
244
|
+
installation: installationOf(totals.installing, totals.downloading, {
|
|
245
|
+
done: totals.done,
|
|
246
|
+
total: totals.total,
|
|
247
|
+
}),
|
|
248
|
+
lost: storageLoss !== null,
|
|
249
|
+
established: facts.targets[port.target]?.established === true,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function establish({ store }, name) {
|
|
253
|
+
const { device } = store;
|
|
254
|
+
if (device.now().establishing.has(name) || !store.needed())
|
|
255
|
+
return;
|
|
256
|
+
device.set({ establishing: new Set([...device.now().establishing, name]) });
|
|
257
|
+
void store
|
|
258
|
+
.durably(async (local) => {
|
|
259
|
+
const { targets } = await local.facts(['targets']);
|
|
260
|
+
await local.fact('targets', { ...targets, [name]: { established: true } });
|
|
261
|
+
})
|
|
262
|
+
.then(() => store.readiness.queue([]), uncaught)
|
|
263
|
+
.finally(() => {
|
|
264
|
+
const establishing = new Set(device.now().establishing);
|
|
265
|
+
establishing.delete(name);
|
|
266
|
+
device.set({ establishing });
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
function deliverReadiness(runtime, watch, held, touched) {
|
|
270
|
+
const { readiness } = runtime.store;
|
|
271
|
+
if (!readiness.held(watch))
|
|
272
|
+
return;
|
|
273
|
+
const kept = readiness.kept(watch);
|
|
274
|
+
const patched = kept === undefined ||
|
|
275
|
+
touched === null ||
|
|
276
|
+
kept.listing !== runtime.presence.listing() ||
|
|
277
|
+
kept.roomsListed !== runtime.socket.session.now().roomsListed
|
|
278
|
+
? null
|
|
279
|
+
: moved(runtime, watch, kept, held.held, touched);
|
|
280
|
+
const showing = patched === null ? showingOf(runtime, watch, held.held) : kept;
|
|
281
|
+
preparingIn(runtime, showing, patched === null ? showing.rooms.keys() : touched);
|
|
282
|
+
const shown = shownOf(runtime, watch, showing, held);
|
|
283
|
+
if (shown.usable)
|
|
284
|
+
probeEachMinute(runtime);
|
|
285
|
+
if (shown.ready && held.facts.targets[watch.port.target]?.established !== true) {
|
|
286
|
+
establish(runtime, watch.port.target);
|
|
287
|
+
}
|
|
288
|
+
const text = JSON.stringify(shown);
|
|
289
|
+
const before = kept?.shown;
|
|
290
|
+
showing.shown = text;
|
|
291
|
+
readiness.keep(watch, showing);
|
|
292
|
+
if (kept === undefined) {
|
|
293
|
+
watch.deliver({
|
|
294
|
+
...shown,
|
|
295
|
+
coverage: {
|
|
296
|
+
...shown.coverage,
|
|
297
|
+
rooms: [...showing.rooms.values()].map(({ coverage }) => coverage),
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const rooms = coverageOf(patched ??
|
|
303
|
+
keyedChange(kept.rooms, [...showing.rooms.keys()], [...showing.rooms.values()], sameState));
|
|
304
|
+
if (text === before && unchanged(rooms))
|
|
305
|
+
return;
|
|
306
|
+
watch.deliver({ shown, rooms });
|
|
307
|
+
}
|
|
308
|
+
export async function deliverOwedReadiness(runtime, owed, touched) {
|
|
309
|
+
const held = await readinessHeld(runtime);
|
|
310
|
+
if (runtime.socket.closed())
|
|
311
|
+
return;
|
|
312
|
+
for (const watch of owed)
|
|
313
|
+
deliverReadiness(runtime, watch, held, touched);
|
|
314
|
+
}
|
|
315
|
+
export function watchReadiness({ store }, port, reach, deliver) {
|
|
316
|
+
const watch = { port, reach, deliver };
|
|
317
|
+
const stop = store.readiness.add(watch);
|
|
318
|
+
if (!store.needed())
|
|
319
|
+
store.readiness.owe([watch]);
|
|
320
|
+
else {
|
|
321
|
+
void store.open().then(() => store.readiness.owe([watch]), () => store.readiness.owe([watch]));
|
|
322
|
+
}
|
|
323
|
+
return stop;
|
|
324
|
+
}
|
|
325
|
+
export function filled({ store, socket }) {
|
|
326
|
+
if (socket.closed() || !store.space.fill())
|
|
327
|
+
return;
|
|
328
|
+
store.readiness.queue([]);
|
|
329
|
+
}
|
|
330
|
+
function probeEachMinute({ store, socket }) {
|
|
331
|
+
const { space } = store;
|
|
332
|
+
if (!space.full() || space.probing() || socket.closed())
|
|
333
|
+
return;
|
|
334
|
+
space.probeEachMinute();
|
|
335
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { DiscoveredRoom, ProviderRefusal, ScopedRefusal } from './adapter.js';
|
|
2
|
+
import type { ModelState } from './model.js';
|
|
3
|
+
type Repairable = {
|
|
4
|
+
readonly reset: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
type Standing = {
|
|
7
|
+
readonly stale: boolean;
|
|
8
|
+
readonly repairable: Repairable | null;
|
|
9
|
+
readonly repairing: boolean;
|
|
10
|
+
readonly reloadDue: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function lockingMode(mode: string | undefined): boolean;
|
|
13
|
+
type Listing = {
|
|
14
|
+
readonly whole: boolean;
|
|
15
|
+
readonly live: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type Presence = {
|
|
18
|
+
list(found: readonly DiscoveredRoom[], how: Listing): readonly DiscoveredRoom[];
|
|
19
|
+
room(locator: string): DiscoveredRoom | undefined;
|
|
20
|
+
rooms(): readonly DiscoveredRoom[];
|
|
21
|
+
available(locator: string, selection?: string): boolean;
|
|
22
|
+
refusal(locator: string): ProviderRefusal | null;
|
|
23
|
+
unheldModel(locator: string): ModelState | null;
|
|
24
|
+
refused(locator: string, refusal: ScopedRefusal | null): void;
|
|
25
|
+
readable(locator: string): boolean;
|
|
26
|
+
modelled(locator: string, model: ModelState | null): void;
|
|
27
|
+
installed(locator: string, bootstrapped: boolean): void;
|
|
28
|
+
locked(locator: string, stored: () => Promise<string | null>): Promise<boolean>;
|
|
29
|
+
lockedAmong(stored: ReadonlyMap<string, {
|
|
30
|
+
readonly offline: string;
|
|
31
|
+
}>, locking: ReadonlySet<string>): readonly string[];
|
|
32
|
+
lockedAs(locator: string, mode: string | undefined): boolean;
|
|
33
|
+
connectionLost(lapsed: () => void): void;
|
|
34
|
+
connectionLive(): void;
|
|
35
|
+
lapse(): void;
|
|
36
|
+
stood(locator: string, stale: boolean, repairable?: Repairable | null): void;
|
|
37
|
+
repairing(locator: string, running: boolean): void;
|
|
38
|
+
reload(locator: string, due: boolean): void;
|
|
39
|
+
standing(locator: string): Standing;
|
|
40
|
+
settled(): boolean;
|
|
41
|
+
repairsOwed(): readonly string[];
|
|
42
|
+
askAgain(locator: string, ask: () => void): void;
|
|
43
|
+
stopAsking(locator?: string): void;
|
|
44
|
+
lose(locator: string, during: number): boolean;
|
|
45
|
+
writing(locator: string): boolean;
|
|
46
|
+
unwritten(locator: string): void;
|
|
47
|
+
lost(locator: string): boolean;
|
|
48
|
+
losing(): boolean;
|
|
49
|
+
listing(): number;
|
|
50
|
+
losses(): number;
|
|
51
|
+
lostSince(locator: string, losses: number): boolean;
|
|
52
|
+
liftable(locator: string, discovery: number): boolean;
|
|
53
|
+
lift(locator: string, discovery: number, unfenced: boolean): void;
|
|
54
|
+
close(): void;
|
|
55
|
+
};
|
|
56
|
+
export declare function createPresence(notReadyWaitMs: (asked: number) => number): Presence;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.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