@agentshouse/mdruntime 0.1.0-cc7bd7a53214e → 0.1.0-cd3486bd400ed
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 +106 -31
- package/README.md +11 -10
- package/dist/adapter.d.ts +65 -28
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +47 -0
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +57 -0
- package/dist/bootstrap.d.ts +20 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +89 -35
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +13 -7
- package/dist/change.d.ts +4 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +57 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +637 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat.d.ts +7 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +2 -0
- package/dist/client.d.ts +11 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +58 -25
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +18 -13
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +679 -568
- package/dist/conversation.d.ts +27 -8
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +210 -81
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +8 -19
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/memory.d.ts +12 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +108 -36
- package/dist/model.d.ts +13 -12
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -3
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +22 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +35 -1
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +19 -15
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +3 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +74 -33
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +29 -35
- package/dist/react.d.ts +41 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +64 -0
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +102 -46
- package/dist/refresh.d.ts +12 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +35 -22
- package/dist/replica.d.ts +6 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +53 -39
- package/dist/room-draft.d.ts +8 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +13 -22
- package/dist/rows.d.ts +4 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +82 -39
- package/dist/save.d.ts +4 -3
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +127 -68
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +26 -2
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +206 -90
- package/dist/wire.d.ts +6 -15
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +14 -17
- package/package.json +14 -2
package/dist/store.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { transferIdentity } from './identity.js';
|
|
1
2
|
import { sameChange } from './overlay.js';
|
|
2
3
|
const DATABASE = 'mdruntime';
|
|
3
4
|
const ROOMS = 'rooms';
|
|
4
5
|
const DOCUMENTS = 'documents';
|
|
5
6
|
const BINARY_TARGETS = 'binaryTargets';
|
|
6
7
|
const ATTACHMENTS = 'attachments';
|
|
8
|
+
const TRANSFERS = 'transfers';
|
|
7
9
|
const PENDING_CHANGES = 'pendingChanges';
|
|
8
10
|
const DECLARATIONS = 'declarations';
|
|
9
11
|
const ROOM_DRAFTS = 'roomDrafts';
|
|
@@ -12,7 +14,10 @@ const CONVERSATIONS = 'conversations';
|
|
|
12
14
|
const MESSAGES = 'messages';
|
|
13
15
|
const CHAT_DRAFTS = 'chatDrafts';
|
|
14
16
|
const CURRENT = 'current';
|
|
15
|
-
const
|
|
17
|
+
const MEMBER = 'member';
|
|
18
|
+
export const STORE_SCHEMA = 21;
|
|
19
|
+
const PATH_KEYED_SCHEMA = 20;
|
|
20
|
+
const READ_BATCH = 256;
|
|
16
21
|
function settled(request) {
|
|
17
22
|
return new Promise((resolve, reject) => {
|
|
18
23
|
request.onsuccess = () => resolve(request.result);
|
|
@@ -60,6 +65,97 @@ function roomRecord(record, queue) {
|
|
|
60
65
|
const { documents, binaryTargets, revisions, changes, written, attachments, ...room } = record;
|
|
61
66
|
return { ...room, order: queue.map((batch) => batch.id) };
|
|
62
67
|
}
|
|
68
|
+
function underTransfer(locator, transfer, after) {
|
|
69
|
+
return after === undefined
|
|
70
|
+
? IDBKeyRange.bound([locator, transfer], [locator, transfer, []])
|
|
71
|
+
: IDBKeyRange.bound([locator, transfer, after], [locator, transfer, []], true);
|
|
72
|
+
}
|
|
73
|
+
function underRoom(locator) {
|
|
74
|
+
return IDBKeyRange.bound([locator], [locator, []]);
|
|
75
|
+
}
|
|
76
|
+
async function readTransfer(store, locator, transfer, receive) {
|
|
77
|
+
let range = underTransfer(locator, transfer);
|
|
78
|
+
for (;;) {
|
|
79
|
+
const batch = await settled(store.getAll(range, READ_BATCH));
|
|
80
|
+
for (const record of batch)
|
|
81
|
+
receive(record);
|
|
82
|
+
if (batch.length < READ_BATCH)
|
|
83
|
+
return;
|
|
84
|
+
range = underTransfer(locator, transfer, batch[batch.length - 1].path);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function emptyLayer() {
|
|
88
|
+
return { documents: {}, binaryTargets: [], revisions: {}, changes: {}, written: {} };
|
|
89
|
+
}
|
|
90
|
+
async function readLayer(transaction, locator, transfer) {
|
|
91
|
+
const layer = emptyLayer();
|
|
92
|
+
const head = (held) => {
|
|
93
|
+
if (held.revision !== null)
|
|
94
|
+
layer.revisions[held.path] = held.revision;
|
|
95
|
+
if (held.change !== null)
|
|
96
|
+
layer.changes[held.path] = held.change;
|
|
97
|
+
};
|
|
98
|
+
await readTransfer(transaction.objectStore(DOCUMENTS), locator, transfer, (document) => {
|
|
99
|
+
layer.documents[document.path] = document.content;
|
|
100
|
+
if (document.written !== null)
|
|
101
|
+
layer.written[document.path] = document.written;
|
|
102
|
+
head(document);
|
|
103
|
+
});
|
|
104
|
+
await readTransfer(transaction.objectStore(BINARY_TARGETS), locator, transfer, (target) => {
|
|
105
|
+
layer.binaryTargets.push(target.path);
|
|
106
|
+
head(target);
|
|
107
|
+
});
|
|
108
|
+
return layer;
|
|
109
|
+
}
|
|
110
|
+
function documentRecord(locator, transfer, layer, path) {
|
|
111
|
+
return {
|
|
112
|
+
locator,
|
|
113
|
+
transfer,
|
|
114
|
+
path,
|
|
115
|
+
content: layer.documents[path],
|
|
116
|
+
revision: layer.revisions[path] ?? null,
|
|
117
|
+
change: layer.changes[path] ?? null,
|
|
118
|
+
written: layer.written[path] ?? null,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function targetRecord(locator, transfer, layer, path) {
|
|
122
|
+
return {
|
|
123
|
+
locator,
|
|
124
|
+
transfer,
|
|
125
|
+
path,
|
|
126
|
+
revision: layer.revisions[path] ?? null,
|
|
127
|
+
change: layer.changes[path] ?? null,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function writeLayer(transaction, locator, transfer, next, base) {
|
|
131
|
+
const documents = transaction.objectStore(DOCUMENTS);
|
|
132
|
+
for (const path of Object.keys(base?.documents ?? {})) {
|
|
133
|
+
if (next.documents[path] === undefined)
|
|
134
|
+
documents.delete([locator, transfer, path]);
|
|
135
|
+
}
|
|
136
|
+
for (const [path, content] of Object.entries(next.documents)) {
|
|
137
|
+
if (base?.documents[path] === content &&
|
|
138
|
+
base.revisions[path] === next.revisions[path] &&
|
|
139
|
+
base.written[path] === next.written[path] &&
|
|
140
|
+
sameChange(base.changes[path], next.changes[path]))
|
|
141
|
+
continue;
|
|
142
|
+
documents.put(documentRecord(locator, transfer, next, path));
|
|
143
|
+
}
|
|
144
|
+
const targets = transaction.objectStore(BINARY_TARGETS);
|
|
145
|
+
const beforeTargets = new Set(base?.binaryTargets ?? []);
|
|
146
|
+
const afterTargets = new Set(next.binaryTargets);
|
|
147
|
+
for (const path of beforeTargets) {
|
|
148
|
+
if (!afterTargets.has(path))
|
|
149
|
+
targets.delete([locator, transfer, path]);
|
|
150
|
+
}
|
|
151
|
+
for (const path of afterTargets) {
|
|
152
|
+
if (!beforeTargets.has(path) ||
|
|
153
|
+
base?.revisions[path] !== next.revisions[path] ||
|
|
154
|
+
!sameChange(base?.changes[path], next.changes[path])) {
|
|
155
|
+
targets.put(targetRecord(locator, transfer, next, path));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
63
159
|
function removeRoomEntries(store, locator) {
|
|
64
160
|
const keys = store.getAllKeys();
|
|
65
161
|
keys.onsuccess = () => {
|
|
@@ -76,15 +172,59 @@ export function removeRuntimeStore() {
|
|
|
76
172
|
removal.onerror = () => reject(removal.error);
|
|
77
173
|
});
|
|
78
174
|
}
|
|
175
|
+
function keyByTransfer(database, upgrade) {
|
|
176
|
+
database.createObjectStore(TRANSFERS, { keyPath: 'locator' });
|
|
177
|
+
const moves = [DOCUMENTS, BINARY_TARGETS].map((name) => {
|
|
178
|
+
const from = upgrade.objectStore(name);
|
|
179
|
+
from.name = `${name}-${PATH_KEYED_SCHEMA}`;
|
|
180
|
+
return {
|
|
181
|
+
from,
|
|
182
|
+
to: database.createObjectStore(name, { keyPath: ['locator', 'transfer', 'path'] }),
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
const transfers = new Map();
|
|
186
|
+
const rooms = upgrade.objectStore(ROOMS).openCursor();
|
|
187
|
+
rooms.onsuccess = () => {
|
|
188
|
+
const room = rooms.result;
|
|
189
|
+
if (room !== null) {
|
|
190
|
+
const record = room.value;
|
|
191
|
+
const transfer = transferIdentity();
|
|
192
|
+
transfers.set(record.locator, transfer);
|
|
193
|
+
room.update({ ...record, transfer });
|
|
194
|
+
room.continue();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
for (const { from, to } of moves) {
|
|
198
|
+
const held = from.openCursor();
|
|
199
|
+
held.onsuccess = () => {
|
|
200
|
+
const entry = held.result;
|
|
201
|
+
if (entry === null) {
|
|
202
|
+
database.deleteObjectStore(from.name);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const record = entry.value;
|
|
206
|
+
const transfer = transfers.get(record.locator);
|
|
207
|
+
if (transfer !== undefined)
|
|
208
|
+
to.put({ ...record, transfer });
|
|
209
|
+
entry.continue();
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
79
214
|
export async function openRuntimeStore() {
|
|
80
|
-
const opening = indexedDB.open(DATABASE,
|
|
81
|
-
opening.onupgradeneeded = () => {
|
|
215
|
+
const opening = indexedDB.open(DATABASE, STORE_SCHEMA);
|
|
216
|
+
opening.onupgradeneeded = (event) => {
|
|
82
217
|
const database = opening.result;
|
|
218
|
+
if (event.oldVersion === PATH_KEYED_SCHEMA && opening.transaction !== null) {
|
|
219
|
+
keyByTransfer(database, opening.transaction);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
83
222
|
for (const name of [...database.objectStoreNames])
|
|
84
223
|
database.deleteObjectStore(name);
|
|
85
224
|
database.createObjectStore(ROOMS, { keyPath: 'locator' });
|
|
86
|
-
database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });
|
|
87
|
-
database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });
|
|
225
|
+
database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'transfer', 'path'] });
|
|
226
|
+
database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'transfer', 'path'] });
|
|
227
|
+
database.createObjectStore(TRANSFERS, { keyPath: 'locator' });
|
|
88
228
|
database.createObjectStore(ATTACHMENTS, { keyPath: ['locator', 'reference'] });
|
|
89
229
|
database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });
|
|
90
230
|
database.createObjectStore(DECLARATIONS);
|
|
@@ -101,99 +241,33 @@ export async function openRuntimeStore() {
|
|
|
101
241
|
return {
|
|
102
242
|
async all() {
|
|
103
243
|
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS], 'readonly');
|
|
104
|
-
const [rooms,
|
|
244
|
+
const [rooms, attachments] = await Promise.all([
|
|
105
245
|
settled(transaction.objectStore(ROOMS).getAll()),
|
|
106
|
-
settled(transaction.objectStore(DOCUMENTS).getAll()),
|
|
107
|
-
settled(transaction.objectStore(BINARY_TARGETS).getAll()),
|
|
108
246
|
settled(transaction.objectStore(ATTACHMENTS).getAll()),
|
|
109
247
|
]);
|
|
110
|
-
const
|
|
248
|
+
const records = [];
|
|
111
249
|
for (const { order, ...room } of rooms) {
|
|
112
|
-
|
|
250
|
+
const layer = await readLayer(transaction, room.locator, room.transfer);
|
|
251
|
+
records.push({
|
|
113
252
|
...room,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
changes: {},
|
|
117
|
-
written: {},
|
|
118
|
-
binaryTargets: [],
|
|
119
|
-
attachments: [],
|
|
253
|
+
...layer,
|
|
254
|
+
attachments: attachments.flatMap(({ locator, ...attachment }) => locator === room.locator ? [attachment] : []),
|
|
120
255
|
});
|
|
121
256
|
}
|
|
122
|
-
|
|
123
|
-
if (held.revision !== null) {
|
|
124
|
-
room.revisions[held.path] = held.revision;
|
|
125
|
-
}
|
|
126
|
-
if (held.change !== null) {
|
|
127
|
-
room.changes[held.path] = held.change;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
for (const document of documents) {
|
|
131
|
-
const room = byRoom.get(document.locator);
|
|
132
|
-
if (room === undefined)
|
|
133
|
-
continue;
|
|
134
|
-
room.documents[document.path] = document.content;
|
|
135
|
-
if (document.written !== null) {
|
|
136
|
-
room.written[document.path] = document.written;
|
|
137
|
-
}
|
|
138
|
-
head(room, document);
|
|
139
|
-
}
|
|
140
|
-
for (const target of targets) {
|
|
141
|
-
const room = byRoom.get(target.locator);
|
|
142
|
-
if (room === undefined)
|
|
143
|
-
continue;
|
|
144
|
-
room.binaryTargets.push(target.path);
|
|
145
|
-
head(room, target);
|
|
146
|
-
}
|
|
147
|
-
for (const { locator, ...attachment } of attachments) {
|
|
148
|
-
const room = byRoom.get(locator);
|
|
149
|
-
if (room === undefined)
|
|
150
|
-
continue;
|
|
151
|
-
room.attachments.push(attachment);
|
|
152
|
-
}
|
|
153
|
-
return [...byRoom.values()];
|
|
257
|
+
return records;
|
|
154
258
|
},
|
|
155
|
-
async write({ next, previous, queue, previousQueue, saved, roomDrafts, consumedRoomDrafts }) {
|
|
156
|
-
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
259
|
+
async write({ next, previous, stored, queue, previousQueue, saved, roomDrafts, consumedRoomDrafts, }) {
|
|
260
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, TRANSFERS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
157
261
|
transaction.objectStore(ROOMS).put(roomRecord(next, queue));
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
for (const [path, content] of Object.entries(next.documents)) {
|
|
164
|
-
if (previous?.documents[path] === content &&
|
|
165
|
-
previous.revisions[path] === next.revisions[path] &&
|
|
166
|
-
previous.written[path] === next.written[path] &&
|
|
167
|
-
sameChange(previous.changes[path], next.changes[path]))
|
|
168
|
-
continue;
|
|
169
|
-
documents.put({
|
|
170
|
-
locator: next.locator,
|
|
171
|
-
path,
|
|
172
|
-
content,
|
|
173
|
-
revision: next.revisions[path] ?? null,
|
|
174
|
-
change: next.changes[path] ?? null,
|
|
175
|
-
written: next.written[path] ?? null,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const targets = transaction.objectStore(BINARY_TARGETS);
|
|
179
|
-
const beforeTargets = new Set(previous?.binaryTargets ?? []);
|
|
180
|
-
const afterTargets = new Set(next.binaryTargets);
|
|
181
|
-
for (const path of beforeTargets) {
|
|
182
|
-
if (!afterTargets.has(path))
|
|
183
|
-
targets.delete([next.locator, path]);
|
|
184
|
-
}
|
|
185
|
-
for (const path of afterTargets) {
|
|
186
|
-
if (!beforeTargets.has(path) ||
|
|
187
|
-
previous?.revisions[path] !== next.revisions[path] ||
|
|
188
|
-
!sameChange(previous?.changes[path], next.changes[path])) {
|
|
189
|
-
targets.put({
|
|
190
|
-
locator: next.locator,
|
|
191
|
-
path,
|
|
192
|
-
revision: next.revisions[path] ?? null,
|
|
193
|
-
change: next.changes[path] ?? null,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
262
|
+
const moved = previous?.transfer !== next.transfer;
|
|
263
|
+
if (moved && previous !== null) {
|
|
264
|
+
const range = underTransfer(previous.locator, previous.transfer);
|
|
265
|
+
transaction.objectStore(DOCUMENTS).delete(range);
|
|
266
|
+
transaction.objectStore(BINARY_TARGETS).delete(range);
|
|
196
267
|
}
|
|
268
|
+
if (moved)
|
|
269
|
+
transaction.objectStore(TRANSFERS).delete(next.locator);
|
|
270
|
+
writeLayer(transaction, next.locator, next.transfer, next, moved ? (stored ?? null) : previous);
|
|
197
271
|
const attachments = transaction.objectStore(ATTACHMENTS);
|
|
198
272
|
const held = new Map((previous?.attachments ?? []).map((attachment) => [attachment.reference, attachment]));
|
|
199
273
|
const declared = new Set(next.attachments.map((attachment) => attachment.reference));
|
|
@@ -262,6 +336,16 @@ export async function openRuntimeStore() {
|
|
|
262
336
|
capabilities,
|
|
263
337
|
}));
|
|
264
338
|
},
|
|
339
|
+
async member() {
|
|
340
|
+
const transaction = database.transaction(DECLARATIONS, 'readonly');
|
|
341
|
+
const held = await settled(transaction.objectStore(DECLARATIONS).get(MEMBER));
|
|
342
|
+
return held ?? null;
|
|
343
|
+
},
|
|
344
|
+
async keepMember(member) {
|
|
345
|
+
const transaction = database.transaction(DECLARATIONS, 'readwrite');
|
|
346
|
+
transaction.objectStore(DECLARATIONS).put(member, MEMBER);
|
|
347
|
+
await completed(transaction);
|
|
348
|
+
},
|
|
265
349
|
async queues() {
|
|
266
350
|
const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');
|
|
267
351
|
const [rooms, pending] = await Promise.all([
|
|
@@ -373,15 +457,47 @@ export async function openRuntimeStore() {
|
|
|
373
457
|
await completed(transaction);
|
|
374
458
|
},
|
|
375
459
|
async dropRooms(locators) {
|
|
376
|
-
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
460
|
+
const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS, ATTACHMENTS, TRANSFERS, PENDING_CHANGES, ROOM_DRAFTS], 'readwrite');
|
|
377
461
|
for (const locator of locators) {
|
|
378
462
|
transaction.objectStore(ROOMS).delete(locator);
|
|
379
|
-
|
|
463
|
+
transaction.objectStore(TRANSFERS).delete(locator);
|
|
464
|
+
transaction.objectStore(DOCUMENTS).delete(underRoom(locator));
|
|
465
|
+
transaction.objectStore(BINARY_TARGETS).delete(underRoom(locator));
|
|
466
|
+
for (const name of [ATTACHMENTS, PENDING_CHANGES, ROOM_DRAFTS]) {
|
|
380
467
|
removeRoomEntries(transaction.objectStore(name), locator);
|
|
381
468
|
}
|
|
382
469
|
}
|
|
383
470
|
await completed(transaction);
|
|
384
471
|
},
|
|
472
|
+
async transfers() {
|
|
473
|
+
const transaction = database.transaction(TRANSFERS, 'readonly');
|
|
474
|
+
return settled(transaction.objectStore(TRANSFERS).getAll());
|
|
475
|
+
},
|
|
476
|
+
staged(record) {
|
|
477
|
+
const transaction = database.transaction([DOCUMENTS, BINARY_TARGETS], 'readonly');
|
|
478
|
+
return readLayer(transaction, record.locator, record.transfer);
|
|
479
|
+
},
|
|
480
|
+
async stage(record, page) {
|
|
481
|
+
const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_TARGETS], 'readwrite');
|
|
482
|
+
writeLayer(transaction, record.locator, record.transfer, page, null);
|
|
483
|
+
transaction.objectStore(TRANSFERS).put(record);
|
|
484
|
+
await completed(transaction);
|
|
485
|
+
},
|
|
486
|
+
async abandon(locator) {
|
|
487
|
+
const transaction = database.transaction([TRANSFERS, DOCUMENTS, BINARY_TARGETS], 'readwrite');
|
|
488
|
+
const transfers = transaction.objectStore(TRANSFERS);
|
|
489
|
+
const held = transfers.get(locator);
|
|
490
|
+
held.onsuccess = () => {
|
|
491
|
+
const record = held.result;
|
|
492
|
+
if (record === undefined)
|
|
493
|
+
return;
|
|
494
|
+
transfers.delete(locator);
|
|
495
|
+
const range = underTransfer(locator, record.transfer);
|
|
496
|
+
transaction.objectStore(DOCUMENTS).delete(range);
|
|
497
|
+
transaction.objectStore(BINARY_TARGETS).delete(range);
|
|
498
|
+
};
|
|
499
|
+
await completed(transaction);
|
|
500
|
+
},
|
|
385
501
|
async generation() {
|
|
386
502
|
return (await declaration(database)).generation;
|
|
387
503
|
},
|
package/dist/wire.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ConnectionRefusal } from './connection.js';
|
|
2
|
-
|
|
3
|
-
export declare const PROTOCOL_MISMATCH: ConnectionRefusal;
|
|
2
|
+
import type { Described } from './failure.js';
|
|
4
3
|
export type RuntimePort = {
|
|
5
4
|
postMessage(message: unknown): void;
|
|
6
5
|
addEventListener(type: 'message' | 'close', listener: (event: {
|
|
@@ -46,11 +45,14 @@ declare const TOPICS: {
|
|
|
46
45
|
readonly 'deployment-facts': 'runtime';
|
|
47
46
|
readonly 'sync-status': 'within';
|
|
48
47
|
readonly 'service-mode': 'runtime';
|
|
48
|
+
readonly member: 'runtime';
|
|
49
49
|
readonly query: 'within';
|
|
50
50
|
readonly queue: 'within';
|
|
51
51
|
readonly 'room-drafts': 'within';
|
|
52
52
|
readonly presentation: 'app';
|
|
53
53
|
readonly conversation: 'within';
|
|
54
|
+
readonly conversations: 'within';
|
|
55
|
+
readonly agents: 'within';
|
|
54
56
|
};
|
|
55
57
|
export declare const WIRE_REACH: {
|
|
56
58
|
readonly members: Readonly<Record<string, WireReach>>;
|
|
@@ -78,11 +80,10 @@ export type WireAnswer = {
|
|
|
78
80
|
kind: 'result';
|
|
79
81
|
id: number;
|
|
80
82
|
value: unknown;
|
|
81
|
-
} | {
|
|
83
|
+
} | ({
|
|
82
84
|
kind: 'failure';
|
|
83
85
|
id: number;
|
|
84
|
-
|
|
85
|
-
} | {
|
|
86
|
+
} & Described) | {
|
|
86
87
|
kind: 'event';
|
|
87
88
|
id: number;
|
|
88
89
|
value: unknown;
|
|
@@ -94,16 +95,6 @@ export type WireAnswer = {
|
|
|
94
95
|
};
|
|
95
96
|
export declare const AUTHORIZATION_ENDED = "the host authorization ended";
|
|
96
97
|
export declare const PORT_CLOSED = "the port closed";
|
|
97
|
-
export type WireEnvelope = {
|
|
98
|
-
mdRuntime: number;
|
|
99
|
-
message: WireRequest | WireAnswer;
|
|
100
|
-
};
|
|
101
|
-
export type Carried = {
|
|
102
|
-
matching: boolean;
|
|
103
|
-
message: unknown;
|
|
104
|
-
};
|
|
105
|
-
export declare function envelope(message: WireRequest | WireAnswer): WireEnvelope;
|
|
106
|
-
export declare function carried(data: unknown): Carried | null;
|
|
107
98
|
export declare function request(message: unknown): WireRequest | null;
|
|
108
99
|
export declare function answer(message: unknown): WireAnswer | null;
|
|
109
100
|
export {};
|
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;
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,SAA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G,UAAU,GAAG,IAAI,CAgC1D"}
|
package/dist/wire.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export const RUNTIME_WIRE_PROTOCOL = 8;
|
|
2
|
-
export const PROTOCOL_MISMATCH = {
|
|
3
|
-
reason: 'client-host-protocol-mismatch',
|
|
4
|
-
reauthorizationOffered: false,
|
|
5
|
-
refusal: null,
|
|
6
|
-
};
|
|
7
1
|
const MEMBERS = {
|
|
8
2
|
rooms: 'within',
|
|
9
3
|
query: 'within',
|
|
@@ -41,24 +35,18 @@ const TOPICS = {
|
|
|
41
35
|
'deployment-facts': 'runtime',
|
|
42
36
|
'sync-status': 'within',
|
|
43
37
|
'service-mode': 'runtime',
|
|
38
|
+
member: 'runtime',
|
|
44
39
|
query: 'within',
|
|
45
40
|
queue: 'within',
|
|
46
41
|
'room-drafts': 'within',
|
|
47
42
|
presentation: 'app',
|
|
48
43
|
conversation: 'within',
|
|
44
|
+
conversations: 'within',
|
|
45
|
+
agents: 'within',
|
|
49
46
|
};
|
|
50
47
|
export const WIRE_REACH = { members: MEMBERS, topics: TOPICS };
|
|
51
48
|
export const AUTHORIZATION_ENDED = 'the host authorization ended';
|
|
52
49
|
export const PORT_CLOSED = 'the port closed';
|
|
53
|
-
export function envelope(message) {
|
|
54
|
-
return { mdRuntime: RUNTIME_WIRE_PROTOCOL, message };
|
|
55
|
-
}
|
|
56
|
-
export function carried(data) {
|
|
57
|
-
if (typeof data !== 'object' || data === null || !('mdRuntime' in data))
|
|
58
|
-
return null;
|
|
59
|
-
const record = data;
|
|
60
|
-
return { matching: record.mdRuntime === RUNTIME_WIRE_PROTOCOL, message: record.message };
|
|
61
|
-
}
|
|
62
50
|
function body(message) {
|
|
63
51
|
if (typeof message !== 'object' || message === null)
|
|
64
52
|
return null;
|
|
@@ -116,8 +104,17 @@ export function answer(message) {
|
|
|
116
104
|
return { kind: 'result', id: shape.id, value: record.value };
|
|
117
105
|
if (shape.kind === 'event')
|
|
118
106
|
return { kind: 'event', id: shape.id, value: record.value };
|
|
119
|
-
if (shape.kind === 'failure' &&
|
|
120
|
-
|
|
107
|
+
if (shape.kind === 'failure' &&
|
|
108
|
+
typeof record.message === 'string' &&
|
|
109
|
+
typeof record.code === 'string' &&
|
|
110
|
+
typeof record.retryable === 'boolean') {
|
|
111
|
+
return {
|
|
112
|
+
kind: 'failure',
|
|
113
|
+
id: shape.id,
|
|
114
|
+
message: record.message,
|
|
115
|
+
code: record.code,
|
|
116
|
+
retryable: record.retryable,
|
|
117
|
+
};
|
|
121
118
|
}
|
|
122
119
|
return null;
|
|
123
120
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-cd3486bd400ed",
|
|
4
4
|
"description": "The headless core of MD App",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
"types": "./dist/memory.d.ts",
|
|
29
29
|
"import": "./dist/memory.js"
|
|
30
30
|
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"types": "./dist/react.d.ts",
|
|
33
|
+
"import": "./dist/react.js"
|
|
34
|
+
},
|
|
35
|
+
"./chat": {
|
|
36
|
+
"types": "./dist/chat.d.ts",
|
|
37
|
+
"import": "./dist/chat.js"
|
|
38
|
+
},
|
|
31
39
|
"./package.json": "./package.json"
|
|
32
40
|
},
|
|
33
41
|
"files": [
|
|
@@ -37,8 +45,12 @@
|
|
|
37
45
|
"LICENSE"
|
|
38
46
|
],
|
|
39
47
|
"dependencies": {
|
|
40
|
-
"@agentshouse/mdmodel": "0.1.0-
|
|
48
|
+
"@agentshouse/mdmodel": "0.1.0-cc9fa0498a7f7",
|
|
41
49
|
"@tanstack/db": "0.9.2",
|
|
42
50
|
"minisearch": "7.2.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@assistant-ui/react": "^0.15.22",
|
|
54
|
+
"react": ">=18"
|
|
43
55
|
}
|
|
44
56
|
}
|