@agentshouse/mdruntime 0.1.0-c2aaa9c0e3ca4 → 0.1.0-c2e8a6f99866d
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/AGENTS.md +289 -276
- package/README.md +9 -8
- package/dist/adapter.d.ts +91 -23
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +13 -3
- package/dist/attempt.d.ts.map +1 -1
- package/dist/attempt.js +14 -1
- package/dist/bootstrap.d.ts +16 -8
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +102 -47
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -8
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +10 -59
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat/acts.d.ts +3 -4
- package/dist/chat/acts.d.ts.map +1 -1
- package/dist/chat/acts.js +10 -10
- package/dist/chat/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -0
- package/dist/chat/house.d.ts +25 -0
- package/dist/chat/house.d.ts.map +1 -0
- package/dist/chat/house.js +38 -0
- package/dist/chat/input.d.ts +3 -1
- package/dist/chat/input.d.ts.map +1 -1
- package/dist/chat/input.js +11 -18
- package/dist/chat/kit.d.ts +2 -1
- package/dist/chat/kit.d.ts.map +1 -1
- package/dist/chat/kit.js +3 -3
- package/dist/chat/list.d.ts +9 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +53 -9
- package/dist/chat/markdown.d.ts +3 -1
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +85 -26
- package/dist/chat/message.d.ts +1 -0
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +65 -13
- package/dist/chat/messages.d.ts +10 -1
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +70 -23
- package/dist/chat/name.d.ts +1 -0
- package/dist/chat/name.d.ts.map +1 -1
- package/dist/chat/name.js +1 -1
- package/dist/chat/opened.d.ts +1 -0
- package/dist/chat/opened.d.ts.map +1 -1
- package/dist/chat/opened.js +2 -0
- package/dist/chat/overlay.d.ts +1 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +11 -5
- package/dist/chat/parts.d.ts +1 -0
- package/dist/chat/parts.d.ts.map +1 -1
- package/dist/chat/parts.js +3 -2
- package/dist/chat/pieces.d.ts +62 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +1110 -0
- package/dist/chat/provider.d.ts +9 -2
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +146 -156
- package/dist/chat/question.d.ts +1 -1
- package/dist/chat/question.d.ts.map +1 -1
- package/dist/chat/question.js +7 -18
- package/dist/chat/ready.d.ts +5 -1
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +9 -7
- package/dist/chat/room-file.d.ts +8 -0
- package/dist/chat/room-file.d.ts.map +1 -0
- package/dist/chat/room-file.js +72 -0
- package/dist/chat/steady.d.ts +3 -0
- package/dist/chat/steady.d.ts.map +1 -0
- package/dist/chat/steady.js +26 -0
- package/dist/chat/style.d.ts.map +1 -1
- package/dist/chat/style.js +8 -4
- package/dist/chat.d.ts +3 -2
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/client.d.ts +22 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +48 -8
- package/dist/collection.d.ts +7 -6
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +31 -77
- package/dist/compile.d.ts +11 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +712 -0
- package/dist/connection.d.ts +41 -13
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +3264 -690
- package/dist/conversation.d.ts +28 -9
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +520 -176
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +8 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +19 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +151 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/host.d.ts +15 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +103 -13
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +6 -0
- package/dist/index.d.ts +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -0
- package/dist/memory.d.ts +9 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +55 -12
- package/dist/model.d.ts +4 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -1
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +19 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +113 -12
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +39 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +29 -0
- package/dist/overlay.d.ts +3 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +99 -181
- package/dist/query.d.ts +57 -4
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +37 -7
- package/dist/reach.d.ts +11 -4
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +182 -51
- package/dist/react.d.ts +8 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +7 -17
- package/dist/readiness.d.ts +53 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +98 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +198 -0
- package/dist/refresh.d.ts +12 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +74 -44
- package/dist/replica.d.ts +55 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +295 -149
- package/dist/room-draft.d.ts +16 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +32 -25
- package/dist/rows.d.ts +28 -37
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +113 -72
- package/dist/save.d.ts +50 -9
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +528 -166
- package/dist/search.d.ts +50 -7
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +273 -45
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +16 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +431 -0
- package/dist/status.d.ts +4 -0
- package/dist/status.d.ts.map +1 -1
- package/dist/store.d.ts +128 -67
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +537 -432
- package/dist/stored.d.ts +143 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +561 -0
- package/dist/tables.d.ts +320 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +537 -0
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +168 -32
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +56 -31
- package/package.json +10 -3
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -440
package/dist/bootstrap.js
CHANGED
|
@@ -1,42 +1,94 @@
|
|
|
1
1
|
import { transferIdentity } from './identity.js';
|
|
2
2
|
import { advancement } from './refresh.js';
|
|
3
|
-
import { acceptedBinaries } from './overlay.js';
|
|
4
|
-
import { readStaged } from './replica.js';
|
|
5
3
|
import { unconfirmed } from './transfer.js';
|
|
6
4
|
const RESUMABLE = new Set([
|
|
7
5
|
'transport-uncertainty',
|
|
8
6
|
'retryable-refusal',
|
|
9
7
|
'unconfirmed',
|
|
10
8
|
]);
|
|
11
|
-
function
|
|
9
|
+
function pageOf(page) {
|
|
10
|
+
const entries = [];
|
|
11
|
+
for (const [path, content] of Object.entries(page.documents)) {
|
|
12
|
+
entries.push({
|
|
13
|
+
path,
|
|
14
|
+
content,
|
|
15
|
+
binary: null,
|
|
16
|
+
revision: page.revisions[path] ?? null,
|
|
17
|
+
fileId: page.fileIds?.[path] ?? null,
|
|
18
|
+
change: page.changes[path] ?? null,
|
|
19
|
+
written: page.roomVersion,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
for (const [path, file] of Object.entries(page.binaryFiles)) {
|
|
23
|
+
entries.push({
|
|
24
|
+
path,
|
|
25
|
+
content: null,
|
|
26
|
+
binary: { state: 'accepted', ...file },
|
|
27
|
+
revision: page.revisions[path] ?? null,
|
|
28
|
+
fileId: page.fileIds?.[path] ?? null,
|
|
29
|
+
change: page.changes[path] ?? null,
|
|
30
|
+
written: null,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return { entries, folders: page.folders ?? [] };
|
|
34
|
+
}
|
|
35
|
+
function heldTogether(first, second) {
|
|
36
|
+
if (first === null)
|
|
37
|
+
return second;
|
|
12
38
|
return {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
39
|
+
async files(after, limit) {
|
|
40
|
+
const [left, right] = await Promise.all([
|
|
41
|
+
first.files(after, limit),
|
|
42
|
+
second.files(after, limit),
|
|
43
|
+
]);
|
|
44
|
+
const merged = new Map([...left, ...right].map((file) => [file.path, file]));
|
|
45
|
+
return [...merged.values()]
|
|
46
|
+
.sort((one, other) => (one.path < other.path ? -1 : one.path > other.path ? 1 : 0))
|
|
47
|
+
.slice(0, limit);
|
|
48
|
+
},
|
|
49
|
+
async contents(paths) {
|
|
50
|
+
const [left, right] = await Promise.all([first.contents(paths), second.contents(paths)]);
|
|
51
|
+
return new Map([...left, ...right]);
|
|
52
|
+
},
|
|
18
53
|
};
|
|
19
54
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
55
|
+
const NO_CONTENT = {
|
|
56
|
+
files: () => Promise.resolve([]),
|
|
57
|
+
contents: () => Promise.resolve(new Map()),
|
|
58
|
+
};
|
|
59
|
+
export async function bootstrapRoom(adapter, authorization, room, held, remodel, continuing, staging, reuse) {
|
|
60
|
+
const kept = staging.held(room.locator);
|
|
61
|
+
const resumed = kept !== null && kept.selection === room.replica.selection ? kept : null;
|
|
62
|
+
if (kept !== null && resumed === null)
|
|
63
|
+
await staging.abandon(room.locator);
|
|
64
|
+
const first = await bundle(adapter, authorization, room, held, remodel, continuing, staging, resumed, reuse);
|
|
65
|
+
if (first.kind !== 'expired')
|
|
66
|
+
return first;
|
|
67
|
+
await staging.setAside(room.locator);
|
|
68
|
+
try {
|
|
69
|
+
const replacement = await bundle(adapter, authorization, room, held, remodel, continuing, staging, null, heldTogether(reuse, first.held));
|
|
70
|
+
if (replacement.kind !== 'expired')
|
|
71
|
+
return replacement;
|
|
72
|
+
await staging.abandon(room.locator);
|
|
73
|
+
return unconfirmed;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
if (first.key !== null)
|
|
77
|
+
await staging.release(first.key);
|
|
26
78
|
}
|
|
27
|
-
await staging.abandon(room.locator);
|
|
28
|
-
return null;
|
|
29
79
|
}
|
|
30
|
-
|
|
80
|
+
function compositionFor(room, models) {
|
|
81
|
+
return {
|
|
82
|
+
model: models.collection,
|
|
83
|
+
selection: room.typedSelection === undefined
|
|
84
|
+
? null
|
|
85
|
+
: { roots: room.typedSelection.roots, model: models.selection },
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function bundle(adapter, authorization, room, held, remodel, continuing, staging, kept, pool) {
|
|
31
89
|
const locator = room.locator;
|
|
32
90
|
const selection = room.replica.selection;
|
|
33
|
-
|
|
34
|
-
const documents = { ...kept?.layer.documents };
|
|
35
|
-
const revisions = { ...kept?.layer.revisions };
|
|
36
|
-
const changes = { ...kept?.layer.changes };
|
|
37
|
-
const written = { ...kept?.layer.written };
|
|
38
|
-
const binaries = { ...kept?.layer.binaries };
|
|
39
|
-
let transfer = kept?.record ?? null;
|
|
91
|
+
let transfer = kept;
|
|
40
92
|
while (transfer === null || transfer.pageToken !== null) {
|
|
41
93
|
if (!continuing())
|
|
42
94
|
return unconfirmed;
|
|
@@ -44,29 +96,35 @@ export async function bootstrapRoom(adapter, authorization, room, held, remodel,
|
|
|
44
96
|
locator,
|
|
45
97
|
selection,
|
|
46
98
|
...(transfer?.pageToken == null ? {} : { pageToken: transfer.pageToken }),
|
|
99
|
+
...(pool === null ? {} : { held: pool }),
|
|
47
100
|
});
|
|
101
|
+
if (page.kind === 'beyond-horizon') {
|
|
102
|
+
const key = transfer?.key ?? null;
|
|
103
|
+
return { kind: 'expired', held: key === null ? NO_CONTENT : staging.content(key), key };
|
|
104
|
+
}
|
|
48
105
|
if (page.kind !== 'bootstrap') {
|
|
49
106
|
if (!RESUMABLE.has(page.kind))
|
|
50
107
|
await staging.abandon(locator);
|
|
51
108
|
return page;
|
|
52
109
|
}
|
|
53
|
-
|
|
110
|
+
const next = {
|
|
54
111
|
locator,
|
|
55
112
|
transfer: transfer?.transfer ?? transferIdentity(),
|
|
56
113
|
selection,
|
|
57
|
-
from: transfer
|
|
58
|
-
|
|
114
|
+
from: transfer !== null && adapter.reached(locator, page.roomVersion, transfer.from)
|
|
115
|
+
? transfer.from
|
|
116
|
+
: page.roomVersion,
|
|
117
|
+
last: transfer !== null && !adapter.reached(locator, page.roomVersion, transfer.last)
|
|
118
|
+
? transfer.last
|
|
119
|
+
: page.roomVersion,
|
|
59
120
|
pageToken: page.pageToken ?? null,
|
|
60
121
|
models: remodel(page.models, transfer?.models ?? held),
|
|
122
|
+
key: transfer?.key ?? null,
|
|
61
123
|
};
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
124
|
+
const key = await staging.stage(next, pageOf(page), compositionFor(room, next.models));
|
|
125
|
+
if (key === null)
|
|
64
126
|
return unconfirmed;
|
|
65
|
-
|
|
66
|
-
Object.assign(revisions, staged.revisions);
|
|
67
|
-
Object.assign(changes, staged.changes);
|
|
68
|
-
Object.assign(written, staged.written);
|
|
69
|
-
Object.assign(binaries, staged.binaries);
|
|
127
|
+
transfer = { ...next, key };
|
|
70
128
|
}
|
|
71
129
|
const record = {
|
|
72
130
|
locator,
|
|
@@ -80,26 +138,23 @@ export async function bootstrapRoom(adapter, authorization, room, held, remodel,
|
|
|
80
138
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
81
139
|
roomVersion: transfer.from,
|
|
82
140
|
transfer: transfer.transfer,
|
|
83
|
-
|
|
84
|
-
binaries,
|
|
85
|
-
revisions,
|
|
86
|
-
changes,
|
|
87
|
-
written,
|
|
141
|
+
key: transfer.key,
|
|
88
142
|
};
|
|
89
|
-
const reconciled = transfer.last === transfer.from
|
|
143
|
+
const reconciled = transfer.last === transfer.from && adapter.reached(locator, transfer.last, room.roomVersion)
|
|
90
144
|
? { kind: 'still-current' }
|
|
91
|
-
: await advancement(adapter, authorization, record, remodel, continuing);
|
|
145
|
+
: await advancement(adapter, authorization, record, remodel, continuing, await staging.refreshing(record.key));
|
|
92
146
|
if (reconciled.kind === 'advanced' || reconciled.kind === 'still-current') {
|
|
93
|
-
const
|
|
94
|
-
|
|
147
|
+
const refreshed = reconciled.kind === 'advanced';
|
|
148
|
+
const result = refreshed ? reconciled.record : record;
|
|
149
|
+
const refused = await staging.validate(result, refreshed ? 'refreshed' : 'confirmed');
|
|
150
|
+
if (refused !== null) {
|
|
95
151
|
await staging.abandon(locator);
|
|
96
|
-
return
|
|
152
|
+
return refused;
|
|
97
153
|
}
|
|
98
|
-
return { kind: 'staged',
|
|
154
|
+
return { kind: 'staged', record: result, refreshed };
|
|
99
155
|
}
|
|
100
156
|
if (reconciled.kind === 'beyond-horizon') {
|
|
101
|
-
|
|
102
|
-
return unconfirmed;
|
|
157
|
+
return { kind: 'expired', held: staging.content(record.key), key: record.key };
|
|
103
158
|
}
|
|
104
159
|
if (!RESUMABLE.has(reconciled.kind))
|
|
105
160
|
await staging.abandon(locator);
|
package/dist/chain.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from './client.js';
|
|
2
|
+
import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
|
|
3
|
+
type Rows = DocumentResult | GroupResult;
|
|
4
|
+
export type WindowAnswer = Rows | PendingResult;
|
|
5
|
+
export type WindowChain = {
|
|
6
|
+
want(count: number): void;
|
|
7
|
+
close(): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function chainedWindows(runtime: MdRuntimeClient, query: DocumentQuery | GroupQuery, count: number, publish: (answers: readonly (WindowAnswer | null)[], settled: boolean) => void): WindowChain;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,KAAK,IAAI,GAAG,cAAc,GAAG,WAAW,CAAC;AAEzC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,aAAa,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAaF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAC7E,WAAW,CAkEb"}
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function answered(answer) {
|
|
2
|
+
return answer !== null && !('pending' in answer);
|
|
3
|
+
}
|
|
4
|
+
export function chainedWindows(runtime, query, count, publish) {
|
|
5
|
+
let links = [];
|
|
6
|
+
let wanted = count;
|
|
7
|
+
let closed = false;
|
|
8
|
+
const observe = runtime.observe;
|
|
9
|
+
const open = (after, shown) => {
|
|
10
|
+
const link = { after, observation: null, value: shown, fresh: false };
|
|
11
|
+
void observe('query', after === undefined ? query : { ...query, after }).then((observation) => {
|
|
12
|
+
if (closed || !links.includes(link)) {
|
|
13
|
+
observation.close();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
link.observation = observation;
|
|
17
|
+
const take = (value) => {
|
|
18
|
+
link.value = value;
|
|
19
|
+
link.fresh = true;
|
|
20
|
+
settle();
|
|
21
|
+
};
|
|
22
|
+
observation.subscribe(take);
|
|
23
|
+
take(observation.current());
|
|
24
|
+
}, () => { });
|
|
25
|
+
return link;
|
|
26
|
+
};
|
|
27
|
+
const settle = () => {
|
|
28
|
+
if (closed)
|
|
29
|
+
return;
|
|
30
|
+
const next = [];
|
|
31
|
+
for (let at = 0; at < wanted; at += 1) {
|
|
32
|
+
const before = next[at - 1];
|
|
33
|
+
if (before !== undefined && !before.fresh) {
|
|
34
|
+
next.push(...links.slice(at, wanted));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (before !== undefined && (!answered(before.value) || before.value.next === undefined)) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
const after = before === undefined ? undefined : before.value.next;
|
|
41
|
+
const held = links[at];
|
|
42
|
+
next.push(held !== undefined && held.after === after ? held : open(after, held?.value ?? null));
|
|
43
|
+
}
|
|
44
|
+
for (const link of links)
|
|
45
|
+
if (!next.includes(link))
|
|
46
|
+
link.observation?.close();
|
|
47
|
+
links = next;
|
|
48
|
+
publish(links.map((link) => link.value), links.every((link) => link.fresh));
|
|
49
|
+
};
|
|
50
|
+
settle();
|
|
51
|
+
return {
|
|
52
|
+
want(count) {
|
|
53
|
+
if (count === wanted)
|
|
54
|
+
return;
|
|
55
|
+
wanted = count;
|
|
56
|
+
settle();
|
|
57
|
+
},
|
|
58
|
+
close() {
|
|
59
|
+
closed = true;
|
|
60
|
+
for (const link of links)
|
|
61
|
+
link.observation?.close();
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/change-set.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { type Replica } from './replica.js';
|
|
2
|
-
import { type Row } from './rows.js';
|
|
3
1
|
export type DocumentChange = {
|
|
4
|
-
locator: string;
|
|
5
|
-
path: string;
|
|
6
|
-
before: readonly Row[];
|
|
7
|
-
after: readonly Row[];
|
|
2
|
+
readonly locator: string;
|
|
3
|
+
readonly path: string | null;
|
|
8
4
|
};
|
|
9
5
|
export type MessageChange = {
|
|
10
6
|
conversation: string;
|
|
11
7
|
identity: string;
|
|
8
|
+
text: string | null;
|
|
12
9
|
};
|
|
13
10
|
export type ChangeSet = {
|
|
14
11
|
documents: readonly DocumentChange[];
|
|
@@ -22,12 +19,16 @@ export type ChangeSet = {
|
|
|
22
19
|
messages: readonly MessageChange[];
|
|
23
20
|
conversations: readonly string[];
|
|
24
21
|
};
|
|
25
|
-
|
|
22
|
+
type Changed = {
|
|
23
|
+
documents?: readonly string[] | null;
|
|
26
24
|
drafts?: readonly string[];
|
|
27
25
|
room?: boolean;
|
|
28
26
|
queue?: boolean;
|
|
29
27
|
presentation?: string;
|
|
30
|
-
}
|
|
28
|
+
};
|
|
29
|
+
export declare function changeSet(locator: string, changed?: Changed): ChangeSet;
|
|
31
30
|
export declare function conversationChangeSet(messages: readonly MessageChange[], conversations: readonly string[]): ChangeSet;
|
|
32
31
|
export declare function mergeChangeSets(sets: readonly ChangeSet[]): ChangeSet;
|
|
32
|
+
export declare function touches(set: ChangeSet, locator: string, path: string): boolean;
|
|
33
|
+
export {};
|
|
33
34
|
//# sourceMappingURL=change-set.d.ts.map
|
package/dist/change-set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../src/change-set.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAExF,MAAM,MAAM,aAAa,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE5F,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IACrC,MAAM,EAAE,SAAS;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACrD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IACnC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACrC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,GAAG,SAAS,CAgB3E;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,SAAS,CAUX;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,SAAS,CAUrE;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI9E"}
|
package/dist/change-set.js
CHANGED
|
@@ -1,63 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { sameBinary, sameChange } from './overlay.js';
|
|
4
|
-
import { beneath } from './paths.js';
|
|
5
|
-
import { compositionOf, sameMembership } from './replica.js';
|
|
6
|
-
import { markdownPath, rowsOf } from './rows.js';
|
|
7
|
-
function rowsAt(locator, replica, path) {
|
|
8
|
-
if (replica === null)
|
|
9
|
-
return [];
|
|
10
|
-
const visible = replica.visible;
|
|
11
|
-
const document = markdownPath(path) ? passingDocument(visible.collection, path) : null;
|
|
12
|
-
const held = visible.documents[path] !== undefined && document !== undefined;
|
|
13
|
-
const binary = visible.binaries[path];
|
|
14
|
-
if (!held && binary === undefined)
|
|
15
|
-
return [];
|
|
16
|
-
return rowsOf(locator, path, document ?? null, compositionOf(replica.confirmed.record), visible.changes[path] ?? null, binary === undefined ? null : binaryRecord(path, binary, visible.revisions[path]));
|
|
17
|
-
}
|
|
18
|
-
function modelShape(model) {
|
|
19
|
-
return model.status === 'unavailable' ? 'unavailable' : JSON.stringify(model.types);
|
|
20
|
-
}
|
|
21
|
-
export function changeSet(locator, before, after, changed = {}) {
|
|
22
|
-
const paths = new Set([
|
|
23
|
-
...Object.keys(before?.visible.documents ?? {}),
|
|
24
|
-
...Object.keys(after?.visible.documents ?? {}),
|
|
25
|
-
...Object.keys(before?.visible.binaries ?? {}),
|
|
26
|
-
...Object.keys(after?.visible.binaries ?? {}),
|
|
27
|
-
]);
|
|
28
|
-
const documents = [];
|
|
29
|
-
const oldRoom = before?.confirmed.record;
|
|
30
|
-
const newRoom = after?.confirmed.record;
|
|
31
|
-
const collectionChanged = oldRoom !== undefined &&
|
|
32
|
-
newRoom !== undefined &&
|
|
33
|
-
modelShape(oldRoom.model) !== modelShape(newRoom.model);
|
|
34
|
-
const selectionChanged = oldRoom !== undefined &&
|
|
35
|
-
newRoom !== undefined &&
|
|
36
|
-
modelShape(oldRoom.selectionModel) !== modelShape(newRoom.selectionModel);
|
|
37
|
-
const reclassified = oldRoom !== undefined && newRoom !== undefined && !sameMembership(oldRoom, newRoom);
|
|
38
|
-
for (const path of paths) {
|
|
39
|
-
const selected = newRoom?.typedSelection?.roots.some((root) => beneath(root, path)) ?? false;
|
|
40
|
-
const retyped = selected ? selectionChanged : collectionChanged;
|
|
41
|
-
if (before?.visible.documents[path] === after?.visible.documents[path] &&
|
|
42
|
-
sameBinary(before?.visible.binaries[path], after?.visible.binaries[path]) &&
|
|
43
|
-
before?.visible.revisions[path] === after?.visible.revisions[path] &&
|
|
44
|
-
sameChange(before?.visible.changes[path], after?.visible.changes[path]) &&
|
|
45
|
-
!retyped &&
|
|
46
|
-
!reclassified)
|
|
47
|
-
continue;
|
|
48
|
-
documents.push({
|
|
49
|
-
locator,
|
|
50
|
-
path,
|
|
51
|
-
get before() {
|
|
52
|
-
return rowsAt(locator, before, path);
|
|
53
|
-
},
|
|
54
|
-
get after() {
|
|
55
|
-
return rowsAt(locator, after, path);
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
}
|
|
1
|
+
export function changeSet(locator, changed = {}) {
|
|
2
|
+
const documents = changed.documents;
|
|
59
3
|
return {
|
|
60
|
-
documents
|
|
4
|
+
documents: documents === undefined
|
|
5
|
+
? []
|
|
6
|
+
: documents === null
|
|
7
|
+
? [{ locator, path: null }]
|
|
8
|
+
: documents.map((path) => ({ locator, path })),
|
|
61
9
|
drafts: (changed.drafts ?? []).map((path) => ({ locator, path })),
|
|
62
10
|
rooms: changed.room ? [locator] : [],
|
|
63
11
|
queues: changed.queue ? [locator] : [],
|
|
@@ -88,3 +36,6 @@ export function mergeChangeSets(sets) {
|
|
|
88
36
|
conversations: [...new Set(sets.flatMap((set) => set.conversations))],
|
|
89
37
|
};
|
|
90
38
|
}
|
|
39
|
+
export function touches(set, locator, path) {
|
|
40
|
+
return set.documents.some((change) => change.locator === locator && (change.path === null || change.path === path));
|
|
41
|
+
}
|
package/dist/change.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BinaryFile, HeadChange } from './adapter.js';
|
|
1
2
|
export type Change = {
|
|
2
3
|
readonly kind: 'field';
|
|
3
4
|
readonly path: string;
|
|
@@ -29,7 +30,6 @@ export type Change = {
|
|
|
29
30
|
readonly kind: 'binary';
|
|
30
31
|
readonly path: string;
|
|
31
32
|
readonly localId: string;
|
|
32
|
-
readonly blob: Blob;
|
|
33
33
|
readonly byteLength: number;
|
|
34
34
|
readonly mediaType: string;
|
|
35
35
|
readonly sha256: string;
|
|
@@ -40,6 +40,32 @@ export type Change = {
|
|
|
40
40
|
} | {
|
|
41
41
|
readonly kind: 'remove';
|
|
42
42
|
readonly path: string;
|
|
43
|
+
} | (Arriving & {
|
|
44
|
+
readonly content: string;
|
|
45
|
+
}) | (Arriving & {
|
|
46
|
+
readonly binary: BinaryFile;
|
|
47
|
+
});
|
|
48
|
+
type Arriving = {
|
|
49
|
+
readonly kind: 'arrival';
|
|
50
|
+
readonly path: string;
|
|
51
|
+
readonly revision?: string;
|
|
52
|
+
readonly fileId?: string;
|
|
53
|
+
readonly change?: HeadChange;
|
|
54
|
+
};
|
|
55
|
+
export type RoomMove = {
|
|
56
|
+
readonly source: {
|
|
57
|
+
readonly room: string;
|
|
58
|
+
readonly baseRoomVersion: string;
|
|
59
|
+
};
|
|
60
|
+
readonly destination: {
|
|
61
|
+
readonly room: string;
|
|
62
|
+
readonly baseRoomVersion: string;
|
|
63
|
+
readonly handle: string;
|
|
64
|
+
};
|
|
65
|
+
readonly moves: readonly {
|
|
66
|
+
readonly path: string;
|
|
67
|
+
readonly to: string;
|
|
68
|
+
}[];
|
|
43
69
|
};
|
|
44
70
|
export type Precondition = {
|
|
45
71
|
readonly kind: 'field';
|
|
@@ -81,9 +107,13 @@ export type ChangeBatch = {
|
|
|
81
107
|
readonly changes: readonly Change[];
|
|
82
108
|
readonly preconditions: readonly Precondition[];
|
|
83
109
|
readonly writtenBy?: WrittenBy;
|
|
110
|
+
readonly between?: RoomMove;
|
|
84
111
|
};
|
|
85
112
|
export declare function immutable(batch: ChangeBatch): ChangeBatch;
|
|
113
|
+
export declare function partnerOf(batch: ChangeBatch, locator: string): string | null;
|
|
114
|
+
export declare function leaving(batch: ChangeBatch, locator: string): boolean;
|
|
86
115
|
export declare function landing(changes: readonly Change[], index: number, path: string): string | null;
|
|
87
116
|
export declare function departure(changes: readonly Change[], index: number): string;
|
|
88
117
|
export declare function queuedFile(batch: ChangeBatch, path: string, localId: string): number;
|
|
118
|
+
export {};
|
|
89
119
|
//# sourceMappingURL=change.d.ts.map
|
package/dist/change.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../src/change.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC5E;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACrD,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5E;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QA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AAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAM3E;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOpF"}
|
package/dist/change.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function frozen(value) {
|
|
2
2
|
if (Array.isArray(value))
|
|
3
3
|
return Object.freeze(value.map((item) => frozen(item)));
|
|
4
|
-
if (value === null || typeof value !== 'object'
|
|
4
|
+
if (value === null || typeof value !== 'object')
|
|
5
5
|
return value;
|
|
6
6
|
const copy = {};
|
|
7
7
|
for (const [name, item] of Object.entries(value))
|
|
@@ -11,6 +11,15 @@ function frozen(value) {
|
|
|
11
11
|
export function immutable(batch) {
|
|
12
12
|
return frozen(batch);
|
|
13
13
|
}
|
|
14
|
+
export function partnerOf(batch, locator) {
|
|
15
|
+
const between = batch.between;
|
|
16
|
+
if (between === undefined)
|
|
17
|
+
return null;
|
|
18
|
+
return between.source.room === locator ? between.destination.room : between.source.room;
|
|
19
|
+
}
|
|
20
|
+
export function leaving(batch, locator) {
|
|
21
|
+
return batch.between?.source.room === locator;
|
|
22
|
+
}
|
|
14
23
|
export function landing(changes, index, path) {
|
|
15
24
|
let at = path;
|
|
16
25
|
for (const change of changes.slice(index + 1)) {
|
package/dist/chat/acts.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { type Answered } from '../attempt.js';
|
|
2
|
-
import { type CallResult } from '../outcome.js';
|
|
2
|
+
import { type CallResult, type Offline } from '../outcome.js';
|
|
3
3
|
import type { Expected } from './overlay.js';
|
|
4
|
-
export type ChatResult = CallResult |
|
|
5
|
-
readonly kind: 'offline';
|
|
6
|
-
};
|
|
4
|
+
export type ChatResult = CallResult | Offline;
|
|
7
5
|
export type ChatOutcome = {
|
|
8
6
|
readonly state: 'sending';
|
|
9
7
|
} | {
|
|
@@ -20,6 +18,7 @@ export declare function outcomeOf(result: ChatResult): ChatOutcome | null;
|
|
|
20
18
|
export declare function answeredOf(result: ChatResult): Answered;
|
|
21
19
|
export type Sender = {
|
|
22
20
|
carried(name: string, about: unknown, sending: (operation: string) => Promise<CallResult>): Promise<ChatResult>;
|
|
21
|
+
numbered(name: string, about: unknown, sending: (operation: string) => Promise<ChatResult>): Promise<ChatResult>;
|
|
23
22
|
expect(expected: Expected): void;
|
|
24
23
|
draw(expected: Expected): void;
|
|
25
24
|
};
|
package/dist/chat/acts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acts.d.ts","sourceRoot":"","sources":["../../src/chat/acts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"acts.d.ts","sourceRoot":"","sources":["../../src/chat/acts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAa,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AAE9C,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE9D,wBAAgB,QAAQ,CACtB,MAAM,EAAE,UAAU,GACjB,MAAM,IAAI,OAAO,CAAC,UAAU,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAE5D;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAEtD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,CAGhE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAIvD;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,CAAC;IACvB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACjC,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,OAAO,GAAG,MAAM,CAe1E"}
|
package/dist/chat/acts.js
CHANGED
|
@@ -19,17 +19,17 @@ export function answeredOf(result) {
|
|
|
19
19
|
return unanswered(result) ? 'unanswered' : 'refused';
|
|
20
20
|
}
|
|
21
21
|
export function sender({ online, identity, expect, draw }) {
|
|
22
|
+
const numbered = async (name, about, sending) => {
|
|
23
|
+
try {
|
|
24
|
+
return await sending(identity(intentOf(name, about)));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return UNCERTAIN;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
22
30
|
return {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return { kind: 'offline' };
|
|
26
|
-
try {
|
|
27
|
-
return await sending(identity(intentOf(name, about)));
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return UNCERTAIN;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
31
|
+
carried: (name, about, sending) => online ? numbered(name, about, sending) : Promise.resolve({ kind: 'offline' }),
|
|
32
|
+
numbered,
|
|
33
33
|
expect,
|
|
34
34
|
draw,
|
|
35
35
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from '../client.js';
|
|
2
|
+
import type { ConversationView } from '../conversation.js';
|
|
3
|
+
export declare const CHAT_WINDOW = 50;
|
|
4
|
+
export type Paged = {
|
|
5
|
+
readonly view: ConversationView | null;
|
|
6
|
+
readonly hasEarlier: boolean;
|
|
7
|
+
loadEarlier(): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export declare function useEarlier(client: MdRuntimeClient, thread: string | null, held: ConversationView | null): Paged;
|
|
10
|
+
//# sourceMappingURL=earlier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"earlier.d.ts","sourceRoot":"","sources":["../../src/chat/earlier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,eAAO,MAAM,WAAW,KAAK,CAAC;AAU9B,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAuBF,wBAAgB,UAAU,CACxB,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAC5B,KAAK,CA8BP"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
export const CHAT_WINDOW = 50;
|
|
3
|
+
function slidOut(before, after) {
|
|
4
|
+
if (before === null || before.conversation !== after.conversation)
|
|
5
|
+
return [];
|
|
6
|
+
const kept = new Set(after.messages.map((one) => one.identity));
|
|
7
|
+
const left = [];
|
|
8
|
+
for (const message of before.messages) {
|
|
9
|
+
if (kept.has(message.identity))
|
|
10
|
+
break;
|
|
11
|
+
left.push(message);
|
|
12
|
+
}
|
|
13
|
+
return left;
|
|
14
|
+
}
|
|
15
|
+
function joined(held, earlier) {
|
|
16
|
+
const { next: _live, ...view } = held;
|
|
17
|
+
const live = new Set(held.messages.map((one) => one.identity));
|
|
18
|
+
return {
|
|
19
|
+
...view,
|
|
20
|
+
messages: [...earlier.messages.filter((one) => !live.has(one.identity)), ...held.messages],
|
|
21
|
+
...(earlier.next === undefined ? {} : { next: earlier.next }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function useEarlier(client, thread, held) {
|
|
25
|
+
const [earlier, setEarlier] = useState(null);
|
|
26
|
+
const [seen, setSeen] = useState(held);
|
|
27
|
+
const whole = held !== null && held.next === undefined;
|
|
28
|
+
let current = earlier !== null && earlier.thread === thread && !whole ? earlier : null;
|
|
29
|
+
if (current !== earlier)
|
|
30
|
+
setEarlier(current);
|
|
31
|
+
if (seen !== held) {
|
|
32
|
+
setSeen(held);
|
|
33
|
+
const carried = held === null ? [] : slidOut(seen, held);
|
|
34
|
+
if (thread !== null && carried.length > 0) {
|
|
35
|
+
const base = current ?? { thread, messages: [], next: seen?.next };
|
|
36
|
+
current = { ...base, messages: [...base.messages, ...carried] };
|
|
37
|
+
setEarlier(current);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const view = useMemo(() => (held === null || current === null ? held : joined(held, current)), [held, current]);
|
|
41
|
+
const next = current === null ? held?.next : current.next;
|
|
42
|
+
const loadEarlier = useCallback(async () => {
|
|
43
|
+
if (thread === null || next === undefined)
|
|
44
|
+
return;
|
|
45
|
+
const older = await client.conversation.read(thread, { limit: CHAT_WINDOW, after: next });
|
|
46
|
+
setEarlier((now) => {
|
|
47
|
+
const base = now !== null && now.thread === thread ? now : { thread, messages: [], next };
|
|
48
|
+
if (base.next !== next)
|
|
49
|
+
return now;
|
|
50
|
+
return { thread, messages: [...older.messages, ...base.messages], next: older.next };
|
|
51
|
+
});
|
|
52
|
+
}, [client, thread, next]);
|
|
53
|
+
return { view, hasEarlier: next !== undefined, loadEarlier };
|
|
54
|
+
}
|