@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c3903a68dcbbf
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 +210 -0
- package/README.md +44 -0
- package/dist/adapter.d.ts +155 -12
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +2 -3
- package/dist/attachment.d.ts +3 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +8 -0
- package/dist/bootstrap.d.ts +3 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +29 -27
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +87 -0
- package/dist/change.d.ts +9 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +6 -5
- package/dist/client.d.ts +40 -28
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +121 -177
- package/dist/collection.d.ts +15 -16
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +54 -87
- package/dist/connection.d.ts +57 -35
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1475 -964
- package/dist/conversation.d.ts +41 -19
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +483 -327
- package/dist/durability.js +6 -6
- package/dist/file.d.ts +2 -2
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +48 -71
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +100 -102
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -9
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/log.js +5 -6
- package/dist/memory.d.ts +6 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +206 -210
- package/dist/model.d.ts +10 -25
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +18 -21
- package/dist/observation.d.ts +25 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +85 -0
- package/dist/outcome.d.ts +17 -20
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -23
- package/dist/overlay.d.ts +9 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +187 -43
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +12 -19
- package/dist/query.d.ts +210 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +420 -15
- package/dist/read-side.d.ts +14 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +371 -0
- package/dist/refresh.d.ts +4 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +45 -30
- package/dist/replica.d.ts +25 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +232 -38
- package/dist/room-draft.d.ts +124 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +327 -0
- package/dist/rows.d.ts +41 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +100 -0
- package/dist/save.d.ts +8 -4
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +265 -350
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +125 -0
- package/dist/status.d.ts +4 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +9 -13
- package/dist/store.d.ts +68 -30
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +360 -134
- package/dist/transfer.d.ts +5 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/transfer.js +1 -5
- package/dist/wire.d.ts +4 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +50 -65
- package/package.json +6 -12
- package/dist/adapter.js.map +0 -1
- package/dist/bootstrap.js.map +0 -1
- package/dist/change.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/collection.js.map +0 -1
- package/dist/connection.js.map +0 -1
- package/dist/conversation.js.map +0 -1
- package/dist/durability.js.map +0 -1
- package/dist/file.js.map +0 -1
- package/dist/host.js.map +0 -1
- package/dist/identity.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/memory.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/outcome.js.map +0 -1
- package/dist/overlay.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/query.js.map +0 -1
- package/dist/refresh.js.map +0 -1
- package/dist/replica.js.map +0 -1
- package/dist/save.js.map +0 -1
- package/dist/status.js.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/transfer.js.map +0 -1
- package/dist/wire.js.map +0 -1
package/dist/store.js
CHANGED
|
@@ -1,191 +1,417 @@
|
|
|
1
|
+
import { sameChange } from './overlay.js';
|
|
1
2
|
const DATABASE = 'mdruntime';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const ROOMS = 'rooms';
|
|
4
|
+
const DOCUMENTS = 'documents';
|
|
5
|
+
const BINARY_TARGETS = 'binaryTargets';
|
|
6
|
+
const ATTACHMENTS = 'attachments';
|
|
7
|
+
const PENDING_CHANGES = 'pendingChanges';
|
|
8
|
+
const OUTCOMES = 'outcomes';
|
|
9
|
+
const DECLARATIONS = 'declarations';
|
|
10
|
+
const ROOM_DRAFTS = 'roomDrafts';
|
|
7
11
|
const PRESENTATION = 'presentation';
|
|
8
12
|
const CONVERSATIONS = 'conversations';
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const SCHEMA = 8;
|
|
13
|
+
const MESSAGES = 'messages';
|
|
14
|
+
const CHAT_DRAFTS = 'chatDrafts';
|
|
15
|
+
const CURRENT = 'current';
|
|
16
|
+
const SCHEMA = 19;
|
|
14
17
|
function settled(request) {
|
|
15
|
-
return new Promise((resolve, reject)=>{
|
|
16
|
-
request.onsuccess = ()=>resolve(request.result);
|
|
17
|
-
request.onerror = ()=>reject(request.error);
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
request.onsuccess = () => resolve(request.result);
|
|
20
|
+
request.onerror = () => reject(request.error);
|
|
18
21
|
});
|
|
19
22
|
}
|
|
20
23
|
function completed(transaction) {
|
|
21
|
-
return new Promise((resolve, reject)=>{
|
|
22
|
-
transaction.oncomplete = ()=>resolve();
|
|
23
|
-
transaction.onerror = ()=>reject(transaction.error);
|
|
24
|
-
transaction.onabort = ()=>reject(transaction.error);
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
transaction.oncomplete = () => resolve();
|
|
26
|
+
transaction.onerror = () => reject(transaction.error);
|
|
27
|
+
transaction.onabort = () => reject(transaction.error);
|
|
25
28
|
});
|
|
26
29
|
}
|
|
30
|
+
const EMPTY_DECLARATIONS = {
|
|
31
|
+
lastCompleted: null,
|
|
32
|
+
generation: null,
|
|
33
|
+
providerLimits: [],
|
|
34
|
+
capabilities: [],
|
|
35
|
+
slots: [],
|
|
36
|
+
};
|
|
37
|
+
function declaration(database) {
|
|
38
|
+
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
39
|
+
return settled(transaction.objectStore(DECLARATIONS).get(CURRENT)).then((record) => record ?? EMPTY_DECLARATIONS);
|
|
40
|
+
}
|
|
41
|
+
function updateDeclaration(database, update) {
|
|
42
|
+
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
43
|
+
const store = transaction.objectStore(DECLARATIONS);
|
|
44
|
+
const prior = store.get(CURRENT);
|
|
45
|
+
prior.onsuccess = () => {
|
|
46
|
+
store.put(update(prior.result ?? EMPTY_DECLARATIONS), CURRENT);
|
|
47
|
+
};
|
|
48
|
+
return completed(transaction);
|
|
49
|
+
}
|
|
50
|
+
function amendPending(database, locator, id, amendment) {
|
|
51
|
+
const transaction = database.transaction(PENDING_CHANGES, 'readwrite');
|
|
52
|
+
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
53
|
+
const request = pending.get([locator, id]);
|
|
54
|
+
request.onsuccess = () => {
|
|
55
|
+
const record = request.result;
|
|
56
|
+
if (record !== undefined)
|
|
57
|
+
pending.put({ ...record, ...amendment });
|
|
58
|
+
};
|
|
59
|
+
return completed(transaction);
|
|
60
|
+
}
|
|
61
|
+
function roomRecord(record, queue) {
|
|
62
|
+
const { documents, binaryTargets, revisions, changes, written, attachments, ...room } = record;
|
|
63
|
+
return { ...room, order: queue.map((batch) => batch.id) };
|
|
64
|
+
}
|
|
65
|
+
function removeRoomEntries(store, locator) {
|
|
66
|
+
const keys = store.getAllKeys();
|
|
67
|
+
keys.onsuccess = () => {
|
|
68
|
+
for (const key of keys.result) {
|
|
69
|
+
if (Array.isArray(key) && key[0] === locator)
|
|
70
|
+
store.delete(key);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
27
74
|
export function removeRuntimeStore() {
|
|
28
|
-
return new Promise((resolve, reject)=>{
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
29
76
|
const removal = indexedDB.deleteDatabase(DATABASE);
|
|
30
|
-
removal.onsuccess = ()=>resolve();
|
|
31
|
-
removal.onerror = ()=>reject(removal.error);
|
|
77
|
+
removal.onsuccess = () => resolve();
|
|
78
|
+
removal.onerror = () => reject(removal.error);
|
|
32
79
|
});
|
|
33
80
|
}
|
|
34
|
-
function discardEveryEarlierStore(database) {
|
|
35
|
-
for (const name of [
|
|
36
|
-
...database.objectStoreNames
|
|
37
|
-
])database.deleteObjectStore(name);
|
|
38
|
-
}
|
|
39
81
|
export async function openRuntimeStore() {
|
|
40
82
|
const opening = indexedDB.open(DATABASE, SCHEMA);
|
|
41
|
-
opening.onupgradeneeded = ()=>{
|
|
83
|
+
opening.onupgradeneeded = () => {
|
|
42
84
|
const database = opening.result;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
database.createObjectStore(
|
|
48
|
-
database.createObjectStore(
|
|
49
|
-
database.createObjectStore(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
database.createObjectStore(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
database.createObjectStore(PRESENTATION, {
|
|
59
|
-
keyPath: 'app'
|
|
60
|
-
});
|
|
61
|
-
database.createObjectStore(CONVERSATIONS, {
|
|
62
|
-
keyPath: 'conversation'
|
|
63
|
-
});
|
|
64
|
-
database.createObjectStore(INSTRUCTIONS, {
|
|
65
|
-
keyPath: 'conversation'
|
|
85
|
+
for (const name of [...database.objectStoreNames])
|
|
86
|
+
database.deleteObjectStore(name);
|
|
87
|
+
database.createObjectStore(ROOMS, { keyPath: 'locator' });
|
|
88
|
+
database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });
|
|
89
|
+
database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });
|
|
90
|
+
database.createObjectStore(ATTACHMENTS, { keyPath: ['locator', 'reference'] });
|
|
91
|
+
database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });
|
|
92
|
+
const outcomes = database.createObjectStore(OUTCOMES, { keyPath: 'id' });
|
|
93
|
+
outcomes.createIndex('locator', 'locator');
|
|
94
|
+
database.createObjectStore(DECLARATIONS);
|
|
95
|
+
database.createObjectStore(ROOM_DRAFTS, { keyPath: ['locator', 'path'] });
|
|
96
|
+
database.createObjectStore(PRESENTATION, { keyPath: 'app' });
|
|
97
|
+
database.createObjectStore(CONVERSATIONS, { keyPath: 'conversation' });
|
|
98
|
+
const messages = database.createObjectStore(MESSAGES, {
|
|
99
|
+
keyPath: ['conversation', 'identity'],
|
|
66
100
|
});
|
|
101
|
+
messages.createIndex('conversation', 'conversation');
|
|
102
|
+
database.createObjectStore(CHAT_DRAFTS, { keyPath: 'conversation' });
|
|
67
103
|
};
|
|
68
104
|
const database = await settled(opening);
|
|
69
105
|
return {
|
|
70
|
-
async all
|
|
71
|
-
const transaction = database.transaction(
|
|
72
|
-
|
|
106
|
+
async all() {
|
|
107
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS], 'readonly');
|
|
108
|
+
const [rooms, documents, targets, attachments] = await Promise.all([
|
|
109
|
+
settled(transaction.objectStore(ROOMS).getAll()),
|
|
110
|
+
settled(transaction.objectStore(DOCUMENTS).getAll()),
|
|
111
|
+
settled(transaction.objectStore(BINARY_TARGETS).getAll()),
|
|
112
|
+
settled(transaction.objectStore(ATTACHMENTS).getAll()),
|
|
113
|
+
]);
|
|
114
|
+
const byRoom = new Map();
|
|
115
|
+
for (const { order, ...room } of rooms) {
|
|
116
|
+
byRoom.set(room.locator, {
|
|
117
|
+
...room,
|
|
118
|
+
documents: {},
|
|
119
|
+
revisions: {},
|
|
120
|
+
changes: {},
|
|
121
|
+
written: {},
|
|
122
|
+
binaryTargets: [],
|
|
123
|
+
attachments: [],
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const head = (room, held) => {
|
|
127
|
+
if (held.revision !== null) {
|
|
128
|
+
room.revisions[held.path] = held.revision;
|
|
129
|
+
}
|
|
130
|
+
if (held.change !== null) {
|
|
131
|
+
room.changes[held.path] = held.change;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
for (const document of documents) {
|
|
135
|
+
const room = byRoom.get(document.locator);
|
|
136
|
+
if (room === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
room.documents[document.path] = document.content;
|
|
139
|
+
if (document.written !== null) {
|
|
140
|
+
room.written[document.path] = document.written;
|
|
141
|
+
}
|
|
142
|
+
head(room, document);
|
|
143
|
+
}
|
|
144
|
+
for (const target of targets) {
|
|
145
|
+
const room = byRoom.get(target.locator);
|
|
146
|
+
if (room === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
room.binaryTargets.push(target.path);
|
|
149
|
+
head(room, target);
|
|
150
|
+
}
|
|
151
|
+
for (const { locator, ...attachment } of attachments) {
|
|
152
|
+
const room = byRoom.get(locator);
|
|
153
|
+
if (room === undefined)
|
|
154
|
+
continue;
|
|
155
|
+
room.attachments.push(attachment);
|
|
156
|
+
}
|
|
157
|
+
return [...byRoom.values()];
|
|
73
158
|
},
|
|
74
|
-
async
|
|
75
|
-
const transaction = database.transaction(
|
|
76
|
-
transaction.objectStore(
|
|
159
|
+
async write({ next, previous, queue, previousQueue, saved, outcomes, roomDrafts, consumedRoomDrafts, }) {
|
|
160
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, OUTCOMES, ROOM_DRAFTS], 'readwrite');
|
|
161
|
+
transaction.objectStore(ROOMS).put(roomRecord(next, queue));
|
|
162
|
+
const documents = transaction.objectStore(DOCUMENTS);
|
|
163
|
+
for (const path of Object.keys(previous?.documents ?? {})) {
|
|
164
|
+
if (next.documents[path] === undefined)
|
|
165
|
+
documents.delete([next.locator, path]);
|
|
166
|
+
}
|
|
167
|
+
for (const [path, content] of Object.entries(next.documents)) {
|
|
168
|
+
if (previous?.documents[path] === content &&
|
|
169
|
+
previous.revisions[path] === next.revisions[path] &&
|
|
170
|
+
previous.written[path] === next.written[path] &&
|
|
171
|
+
sameChange(previous.changes[path], next.changes[path]))
|
|
172
|
+
continue;
|
|
173
|
+
documents.put({
|
|
174
|
+
locator: next.locator,
|
|
175
|
+
path,
|
|
176
|
+
content,
|
|
177
|
+
revision: next.revisions[path] ?? null,
|
|
178
|
+
change: next.changes[path] ?? null,
|
|
179
|
+
written: next.written[path] ?? null,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const targets = transaction.objectStore(BINARY_TARGETS);
|
|
183
|
+
const beforeTargets = new Set(previous?.binaryTargets ?? []);
|
|
184
|
+
const afterTargets = new Set(next.binaryTargets);
|
|
185
|
+
for (const path of beforeTargets) {
|
|
186
|
+
if (!afterTargets.has(path))
|
|
187
|
+
targets.delete([next.locator, path]);
|
|
188
|
+
}
|
|
189
|
+
for (const path of afterTargets) {
|
|
190
|
+
if (!beforeTargets.has(path) ||
|
|
191
|
+
previous?.revisions[path] !== next.revisions[path] ||
|
|
192
|
+
!sameChange(previous?.changes[path], next.changes[path])) {
|
|
193
|
+
targets.put({
|
|
194
|
+
locator: next.locator,
|
|
195
|
+
path,
|
|
196
|
+
revision: next.revisions[path] ?? null,
|
|
197
|
+
change: next.changes[path] ?? null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const attachments = transaction.objectStore(ATTACHMENTS);
|
|
202
|
+
const held = new Map((previous?.attachments ?? []).map((attachment) => [attachment.reference, attachment]));
|
|
203
|
+
const declared = new Set(next.attachments.map((attachment) => attachment.reference));
|
|
204
|
+
for (const reference of held.keys()) {
|
|
205
|
+
if (!declared.has(reference))
|
|
206
|
+
attachments.delete([next.locator, reference]);
|
|
207
|
+
}
|
|
208
|
+
for (const attachment of next.attachments) {
|
|
209
|
+
if (held.get(attachment.reference) === attachment)
|
|
210
|
+
continue;
|
|
211
|
+
attachments.put({ ...attachment, locator: next.locator });
|
|
212
|
+
}
|
|
213
|
+
if (previousQueue !== undefined) {
|
|
214
|
+
const pending = transaction.objectStore(PENDING_CHANGES);
|
|
215
|
+
const before = new Set(previousQueue.map((batch) => batch.id));
|
|
216
|
+
const after = new Set(queue.map((batch) => batch.id));
|
|
217
|
+
for (const id of before) {
|
|
218
|
+
if (!after.has(id))
|
|
219
|
+
pending.delete([next.locator, id]);
|
|
220
|
+
}
|
|
221
|
+
for (const batch of queue) {
|
|
222
|
+
if (!before.has(batch.id)) {
|
|
223
|
+
pending.put({
|
|
224
|
+
locator: next.locator,
|
|
225
|
+
id: batch.id,
|
|
226
|
+
batch,
|
|
227
|
+
drafts: saved ?? [],
|
|
228
|
+
submission: { state: 'waiting' },
|
|
229
|
+
lost: false,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const outcomeStore = transaction.objectStore(OUTCOMES);
|
|
235
|
+
for (const entry of outcomes ?? []) {
|
|
236
|
+
if (entry.outcome === null)
|
|
237
|
+
outcomeStore.delete(entry.id);
|
|
238
|
+
else
|
|
239
|
+
outcomeStore.put({ locator: next.locator, id: entry.id, outcome: entry.outcome });
|
|
240
|
+
}
|
|
241
|
+
const draftStore = transaction.objectStore(ROOM_DRAFTS);
|
|
242
|
+
for (const path of consumedRoomDrafts ?? [])
|
|
243
|
+
draftStore.delete([next.locator, path]);
|
|
244
|
+
for (const record of roomDrafts ?? [])
|
|
245
|
+
draftStore.put(record);
|
|
77
246
|
await completed(transaction);
|
|
78
247
|
},
|
|
79
|
-
async
|
|
80
|
-
const transaction = database.transaction(
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
transaction.objectStore(SYNCHRONIZATION).put(at, LAST_COMPLETED);
|
|
248
|
+
async revokeModels(records) {
|
|
249
|
+
const transaction = database.transaction(ROOMS, 'readwrite');
|
|
250
|
+
const rooms = transaction.objectStore(ROOMS);
|
|
251
|
+
const revoked = { status: 'unavailable', reason: 'revoked' };
|
|
252
|
+
for (const { record, queue } of records) {
|
|
253
|
+
rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }, queue));
|
|
254
|
+
}
|
|
87
255
|
await completed(transaction);
|
|
88
256
|
},
|
|
89
|
-
async
|
|
90
|
-
|
|
91
|
-
const value = await settled(transaction.objectStore(DISCOVERY).get(PROVIDER_LIMITS));
|
|
92
|
-
return value ?? [];
|
|
257
|
+
async lastCompleted() {
|
|
258
|
+
return (await declaration(database)).lastCompleted;
|
|
93
259
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
260
|
+
complete(at) {
|
|
261
|
+
return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));
|
|
262
|
+
},
|
|
263
|
+
async providerLimits() {
|
|
264
|
+
return (await declaration(database)).providerLimits;
|
|
265
|
+
},
|
|
266
|
+
async capabilities() {
|
|
267
|
+
return (await declaration(database)).capabilities;
|
|
268
|
+
},
|
|
269
|
+
async slots() {
|
|
270
|
+
return (await declaration(database)).slots;
|
|
271
|
+
},
|
|
272
|
+
declare(limits, capabilities, slots) {
|
|
273
|
+
return updateDeclaration(database, (record) => ({
|
|
274
|
+
...record,
|
|
275
|
+
providerLimits: limits,
|
|
276
|
+
capabilities,
|
|
277
|
+
slots,
|
|
278
|
+
}));
|
|
279
|
+
},
|
|
280
|
+
async queues() {
|
|
281
|
+
const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');
|
|
282
|
+
const [rooms, pending] = await Promise.all([
|
|
283
|
+
settled(transaction.objectStore(ROOMS).getAll()),
|
|
284
|
+
settled(transaction.objectStore(PENDING_CHANGES).getAll()),
|
|
285
|
+
]);
|
|
286
|
+
const byId = new Map(pending.map((record) => [`${record.locator}\0${record.id}`, record]));
|
|
287
|
+
return rooms.map((room) => ({
|
|
288
|
+
locator: room.locator,
|
|
289
|
+
pending: room.order.map((id) => {
|
|
290
|
+
const record = byId.get(`${room.locator}\0${id}`);
|
|
291
|
+
if (record === undefined)
|
|
292
|
+
throw new Error(`Missing Pending Change ${room.locator}/${id}`);
|
|
293
|
+
const { batch, drafts, submission, lost, upload } = record;
|
|
294
|
+
return { batch, state: { drafts, submission, lost, upload } };
|
|
295
|
+
}),
|
|
296
|
+
}));
|
|
297
|
+
},
|
|
298
|
+
async outcomes() {
|
|
299
|
+
const transaction = database.transaction(OUTCOMES, 'readonly');
|
|
300
|
+
return settled(transaction.objectStore(OUTCOMES).getAll());
|
|
301
|
+
},
|
|
302
|
+
submit(locator, id, submission, lost) {
|
|
303
|
+
return amendPending(database, locator, id, { submission, lost });
|
|
98
304
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return settled(transaction.objectStore(QUEUES).getAll());
|
|
305
|
+
keepUpload(locator, id, upload) {
|
|
306
|
+
return amendPending(database, locator, id, { upload });
|
|
102
307
|
},
|
|
103
|
-
async
|
|
104
|
-
const transaction = database.transaction(
|
|
105
|
-
return settled(transaction.objectStore(
|
|
308
|
+
async roomDrafts() {
|
|
309
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readonly');
|
|
310
|
+
return settled(transaction.objectStore(ROOM_DRAFTS).getAll());
|
|
106
311
|
},
|
|
107
|
-
async presentation
|
|
312
|
+
async presentation() {
|
|
108
313
|
const transaction = database.transaction(PRESENTATION, 'readonly');
|
|
109
314
|
return settled(transaction.objectStore(PRESENTATION).getAll());
|
|
110
315
|
},
|
|
111
|
-
async present
|
|
316
|
+
async present(record) {
|
|
112
317
|
const transaction = database.transaction(PRESENTATION, 'readwrite');
|
|
113
318
|
transaction.objectStore(PRESENTATION).put(record);
|
|
114
319
|
await completed(transaction);
|
|
115
320
|
},
|
|
116
|
-
async conversations
|
|
117
|
-
const transaction = database.transaction(CONVERSATIONS, 'readonly');
|
|
118
|
-
|
|
321
|
+
async conversations() {
|
|
322
|
+
const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');
|
|
323
|
+
const [reads, messages] = await Promise.all([
|
|
324
|
+
settled(transaction.objectStore(CONVERSATIONS).getAll()),
|
|
325
|
+
settled(transaction.objectStore(MESSAGES).getAll()),
|
|
326
|
+
]);
|
|
327
|
+
const held = new Map();
|
|
328
|
+
for (const { conversation, read } of reads) {
|
|
329
|
+
held.set(conversation, { conversation, read, messages: [] });
|
|
330
|
+
}
|
|
331
|
+
for (const { conversation, ...message } of messages) {
|
|
332
|
+
const entry = held.get(conversation) ?? { conversation, read: undefined, messages: [] };
|
|
333
|
+
entry.messages.push(message);
|
|
334
|
+
held.set(conversation, entry);
|
|
335
|
+
}
|
|
336
|
+
return [...held.values()];
|
|
119
337
|
},
|
|
120
|
-
async
|
|
121
|
-
const transaction = database.transaction(CONVERSATIONS, 'readwrite');
|
|
122
|
-
transaction.objectStore(
|
|
338
|
+
async keepMessages({ conversation, messages, read, sealed }) {
|
|
339
|
+
const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');
|
|
340
|
+
const stored = transaction.objectStore(MESSAGES);
|
|
341
|
+
for (const message of messages) {
|
|
342
|
+
stored.put({ ...message, conversation });
|
|
343
|
+
}
|
|
344
|
+
if (read !== undefined) {
|
|
345
|
+
transaction
|
|
346
|
+
.objectStore(CONVERSATIONS)
|
|
347
|
+
.put({ conversation, read });
|
|
348
|
+
}
|
|
349
|
+
if (sealed === true)
|
|
350
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
123
351
|
await completed(transaction);
|
|
124
352
|
},
|
|
125
|
-
async
|
|
126
|
-
const transaction = database.transaction(CONVERSATIONS, 'readwrite');
|
|
127
|
-
transaction.objectStore(
|
|
353
|
+
async dropConversations(conversations) {
|
|
354
|
+
const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');
|
|
355
|
+
const messages = transaction.objectStore(MESSAGES);
|
|
356
|
+
for (const conversation of conversations) {
|
|
357
|
+
transaction.objectStore(CONVERSATIONS).delete(conversation);
|
|
358
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
359
|
+
const keys = messages.index('conversation').getAllKeys(conversation);
|
|
360
|
+
keys.onsuccess = () => {
|
|
361
|
+
for (const key of keys.result)
|
|
362
|
+
messages.delete(key);
|
|
363
|
+
};
|
|
364
|
+
}
|
|
128
365
|
await completed(transaction);
|
|
129
366
|
},
|
|
130
|
-
async
|
|
131
|
-
const transaction = database.transaction(
|
|
132
|
-
return settled(transaction.objectStore(
|
|
133
|
-
},
|
|
134
|
-
async keepInstruction (record) {
|
|
135
|
-
const transaction = database.transaction(INSTRUCTIONS, 'readwrite');
|
|
136
|
-
transaction.objectStore(INSTRUCTIONS).put(record);
|
|
137
|
-
await completed(transaction);
|
|
367
|
+
async chatDrafts() {
|
|
368
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readonly');
|
|
369
|
+
return settled(transaction.objectStore(CHAT_DRAFTS).getAll());
|
|
138
370
|
},
|
|
139
|
-
async
|
|
140
|
-
const transaction = database.transaction(
|
|
141
|
-
transaction.objectStore(
|
|
371
|
+
async keepChatDraft(record) {
|
|
372
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
373
|
+
transaction.objectStore(CHAT_DRAFTS).put(record);
|
|
142
374
|
await completed(transaction);
|
|
143
375
|
},
|
|
144
|
-
async
|
|
145
|
-
const transaction = database.transaction(
|
|
146
|
-
transaction.objectStore(
|
|
376
|
+
async dropChatDraft(conversation) {
|
|
377
|
+
const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');
|
|
378
|
+
transaction.objectStore(CHAT_DRAFTS).delete(conversation);
|
|
147
379
|
await completed(transaction);
|
|
148
380
|
},
|
|
149
|
-
async
|
|
150
|
-
const transaction = database.transaction(
|
|
151
|
-
transaction.objectStore(
|
|
152
|
-
locator,
|
|
153
|
-
path
|
|
154
|
-
]);
|
|
381
|
+
async keepRoomDraft(record) {
|
|
382
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
383
|
+
transaction.objectStore(ROOM_DRAFTS).put(record);
|
|
155
384
|
await completed(transaction);
|
|
156
385
|
},
|
|
157
|
-
async
|
|
158
|
-
const transaction = database.transaction(
|
|
159
|
-
|
|
160
|
-
DRAFTS
|
|
161
|
-
], 'readwrite');
|
|
162
|
-
transaction.objectStore(QUEUES).put(queue);
|
|
163
|
-
const drafts = transaction.objectStore(DRAFTS);
|
|
164
|
-
for (const path of consumed)drafts.delete([
|
|
165
|
-
queue.locator,
|
|
166
|
-
path
|
|
167
|
-
]);
|
|
386
|
+
async discardRoomDraft(locator, path) {
|
|
387
|
+
const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');
|
|
388
|
+
transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);
|
|
168
389
|
await completed(transaction);
|
|
169
390
|
},
|
|
170
|
-
async
|
|
171
|
-
const transaction = database.transaction(
|
|
172
|
-
|
|
391
|
+
async dropRooms(locators) {
|
|
392
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, OUTCOMES, ROOM_DRAFTS], 'readwrite');
|
|
393
|
+
for (const locator of locators) {
|
|
394
|
+
transaction.objectStore(ROOMS).delete(locator);
|
|
395
|
+
for (const name of [DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS]) {
|
|
396
|
+
removeRoomEntries(transaction.objectStore(name), locator);
|
|
397
|
+
}
|
|
398
|
+
const outcomes = transaction.objectStore(OUTCOMES);
|
|
399
|
+
const ids = outcomes.index('locator').getAllKeys(locator);
|
|
400
|
+
ids.onsuccess = () => {
|
|
401
|
+
for (const id of ids.result)
|
|
402
|
+
outcomes.delete(id);
|
|
403
|
+
};
|
|
404
|
+
}
|
|
173
405
|
await completed(transaction);
|
|
174
406
|
},
|
|
175
|
-
async generation
|
|
176
|
-
|
|
177
|
-
const value = await settled(transaction.objectStore(SYNCHRONIZATION).get(GENERATION));
|
|
178
|
-
return value ?? null;
|
|
407
|
+
async generation() {
|
|
408
|
+
return (await declaration(database)).generation;
|
|
179
409
|
},
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
transaction.objectStore(SYNCHRONIZATION).put(value, GENERATION);
|
|
183
|
-
await completed(transaction);
|
|
410
|
+
rememberGeneration(value) {
|
|
411
|
+
return updateDeclaration(database, (record) => ({ ...record, generation: value }));
|
|
184
412
|
},
|
|
185
|
-
close
|
|
413
|
+
close() {
|
|
186
414
|
database.close();
|
|
187
|
-
}
|
|
415
|
+
},
|
|
188
416
|
};
|
|
189
417
|
}
|
|
190
|
-
|
|
191
|
-
//# sourceMappingURL=store.js.map
|
package/dist/transfer.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { Refusal } from '@agentshouse/mdmodel';
|
|
1
2
|
export type Unconfirmed = {
|
|
2
3
|
kind: 'unconfirmed';
|
|
3
4
|
};
|
|
5
|
+
export type Refused = {
|
|
6
|
+
kind: 'refused';
|
|
7
|
+
refusal: Refusal;
|
|
8
|
+
};
|
|
4
9
|
export declare const unconfirmed: Unconfirmed;
|
|
5
10
|
//# sourceMappingURL=transfer.d.ts.map
|
package/dist/transfer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,WAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"transfer.d.ts","sourceRoot":"","sources":["../src/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5D,eAAO,MAAM,WAAW,EAAE,WAAqC,CAAC"}
|
package/dist/transfer.js
CHANGED
package/dist/wire.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConnectionRefusal } from './connection.js';
|
|
2
|
-
export declare const RUNTIME_WIRE_PROTOCOL =
|
|
2
|
+
export declare const RUNTIME_WIRE_PROTOCOL = 8;
|
|
3
3
|
export declare const PROTOCOL_MISMATCH: ConnectionRefusal;
|
|
4
4
|
export type RuntimePort = {
|
|
5
5
|
postMessage(message: unknown): void;
|
|
@@ -8,8 +8,8 @@ export type RuntimePort = {
|
|
|
8
8
|
}) => void): void;
|
|
9
9
|
start(): void;
|
|
10
10
|
};
|
|
11
|
-
declare const MEMBERS: readonly ['rooms', 'query', 'types', 'syncStatus', 'save', 'outcome', 'history', 'call', 'log', 'storageLoss', 'persistence', '
|
|
12
|
-
declare const TOPICS: readonly ['rooms', 'connection-refusal', 'storage-loss', 'sync-status', 'query', 'queue', 'drafts', 'presentation', 'conversation'];
|
|
11
|
+
declare const MEMBERS: readonly ['rooms', 'slots', 'query', 'search', 'types', 'syncStatus', 'serviceMode', 'save', 'outcome', 'history', 'call', 'reached', 'log', 'storageLoss', 'persistence', 'deploymentFacts', 'reauthorize', 'roomDraft.list', 'roomDraft.read', 'roomDraft.write', 'roomDraft.discard', 'presentation.read', 'presentation.write', 'conversation.list', 'conversation.read', 'conversation.create', 'conversation.send', 'conversation.answer', 'conversation.interrupt', 'conversation.kill', 'conversation.cancel', 'conversation.delete', 'chatDraft.write', 'chatDraft.discard'];
|
|
12
|
+
declare const TOPICS: readonly ['rooms', 'connection-refusal', 'storage-loss', 'deployment-facts', 'sync-status', 'service-mode', 'query', 'queue', 'room-drafts', 'presentation', 'conversation'];
|
|
13
13
|
export type WireMember = (typeof MEMBERS)[number];
|
|
14
14
|
export type WireTopic = (typeof TOPICS)[number];
|
|
15
15
|
export type WireRequest = {
|
|
@@ -47,6 +47,7 @@ export type WireAnswer = {
|
|
|
47
47
|
kind: 'ended';
|
|
48
48
|
};
|
|
49
49
|
export declare const AUTHORIZATION_ENDED = "the host authorization ended";
|
|
50
|
+
export declare const PORT_CLOSED = "the port closed";
|
|
50
51
|
export type WireEnvelope = {
|
|
51
52
|
mdRuntime: number;
|
|
52
53
|
message: WireRequest | WireAnswer;
|
package/dist/wire.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,iBAAiB,EAAE,iBAI/B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,gBAAgB,CAAC,IA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