@agentshouse/mdruntime 0.1.0-cee9c8aa4cd86 → 0.1.0-cef5833f6c689
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -9
- package/dist/adapter.d.ts +96 -67
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +2 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +28 -4
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +17 -9
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +143 -94
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +12 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +54 -8
- package/dist/collection.d.ts +7 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +24 -19
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +118 -247
- package/dist/connection.d.ts +11 -11
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1598 -1248
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/{chat/context.js → context.js} +1 -4
- package/dist/conversation.d.ts +18 -15
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +268 -171
- package/dist/durability.d.ts +1 -5
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +15 -6
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- package/dist/host.d.ts +3 -6
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +49 -35
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +15 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +9 -5
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +11 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +178 -101
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +7 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -13
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +8 -3
- package/dist/outcome.d.ts +13 -6
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +16 -5
- package/dist/overlay.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +10 -205
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -494
- package/dist/reach.d.ts +14 -9
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +81 -71
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +13 -16
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +10 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +104 -30
- package/dist/replica.d.ts +6 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +8 -7
- package/dist/room-draft.d.ts +22 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +131 -51
- package/dist/rows.d.ts +8 -15
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +51 -151
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +13 -7
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +4 -3
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +32 -31
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +67 -63
- package/dist/stored.d.ts +42 -18
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +193 -194
- package/dist/tables.d.ts +60 -40
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +78 -62
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +39 -97
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +6 -9
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -3
- package/package.json +11 -18
- package/AGENTS.md +0 -320
- package/dist/chat/acts.d.ts +0 -33
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/context.d.ts +0 -3
- package/dist/chat/context.d.ts.map +0 -1
- package/dist/chat/earlier.d.ts +0 -10
- package/dist/chat/earlier.d.ts.map +0 -1
- package/dist/chat/earlier.js +0 -54
- package/dist/chat/house.d.ts +0 -25
- package/dist/chat/house.d.ts.map +0 -1
- package/dist/chat/house.js +0 -38
- package/dist/chat/input.d.ts +0 -11
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -92
- package/dist/chat/kit.d.ts +0 -61
- package/dist/chat/kit.d.ts.map +0 -1
- package/dist/chat/kit.js +0 -123
- package/dist/chat/lasting.d.ts +0 -6
- package/dist/chat/lasting.d.ts.map +0 -1
- package/dist/chat/lasting.js +0 -19
- package/dist/chat/list.d.ts +0 -28
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -103
- package/dist/chat/markdown.d.ts +0 -21
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -246
- package/dist/chat/message.d.ts +0 -7
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -254
- package/dist/chat/messages.d.ts +0 -35
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -210
- package/dist/chat/name.d.ts +0 -7
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -12
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -19
- package/dist/chat/overlay.d.ts +0 -32
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -103
- package/dist/chat/parts.d.ts +0 -58
- package/dist/chat/parts.d.ts.map +0 -1
- package/dist/chat/parts.js +0 -120
- package/dist/chat/pieces.d.ts +0 -62
- package/dist/chat/pieces.d.ts.map +0 -1
- package/dist/chat/pieces.js +0 -1110
- package/dist/chat/process.d.ts +0 -20
- package/dist/chat/process.d.ts.map +0 -1
- package/dist/chat/process.js +0 -32
- package/dist/chat/provider.d.ts +0 -70
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -635
- package/dist/chat/question.d.ts +0 -9
- package/dist/chat/question.d.ts.map +0 -1
- package/dist/chat/question.js +0 -69
- package/dist/chat/questions.d.ts +0 -31
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/questions.js +0 -111
- package/dist/chat/read.d.ts +0 -5
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat/read.js +0 -13
- package/dist/chat/ready.d.ts +0 -37
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -93
- package/dist/chat/room-file.d.ts +0 -8
- package/dist/chat/room-file.d.ts.map +0 -1
- package/dist/chat/room-file.js +0 -72
- package/dist/chat/steady.d.ts +0 -3
- package/dist/chat/steady.d.ts.map +0 -1
- package/dist/chat/steady.js +0 -26
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -307
- package/dist/chat.d.ts +0 -15
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -8
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -98
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/memory.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { sameChange } from './overlay.js';
|
|
2
|
+
const ATTACHMENTS = 'attachments';
|
|
3
|
+
function lastName(path) {
|
|
4
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
5
|
+
}
|
|
2
6
|
const FIXTURE_RETENTION = {
|
|
3
7
|
history: { kind: 'duration', seconds: 1 },
|
|
4
|
-
outcome: 604_800,
|
|
5
8
|
refreshHorizon: 1,
|
|
6
9
|
};
|
|
7
10
|
function declaredRetention(value) {
|
|
@@ -15,12 +18,7 @@ function declaredRetention(value) {
|
|
|
15
18
|
}
|
|
16
19
|
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
20
|
function modelsOf(room) {
|
|
18
|
-
return {
|
|
19
|
-
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
-
...(room.typedSelection === undefined
|
|
21
|
-
? {}
|
|
22
|
-
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
-
};
|
|
21
|
+
return { collection: room.model ?? MODEL_ABSENT };
|
|
24
22
|
}
|
|
25
23
|
function changedModels(room, from) {
|
|
26
24
|
const now = modelsOf(room);
|
|
@@ -53,13 +51,16 @@ export function createMemoryAdapter(options = {}) {
|
|
|
53
51
|
const listeners = new Set();
|
|
54
52
|
const modeObservers = new Set();
|
|
55
53
|
const scripted = new Map();
|
|
56
|
-
const unsealed = new Map();
|
|
57
|
-
const sealed = new Set();
|
|
58
54
|
const sentTurns = new Map();
|
|
59
55
|
const historyPageSize = options.historyPageSize;
|
|
60
|
-
|
|
56
|
+
const attached = new Map();
|
|
57
|
+
const linked = new WeakMap();
|
|
58
|
+
const carried = new Map();
|
|
61
59
|
let expiring = [];
|
|
60
|
+
let openings = 0;
|
|
61
|
+
const declaredRooms = new Set();
|
|
62
62
|
let replicated = [];
|
|
63
|
+
let heldCursor = null;
|
|
63
64
|
let issued = 0;
|
|
64
65
|
function scriptConversations(entries) {
|
|
65
66
|
scripted.clear();
|
|
@@ -87,6 +88,19 @@ export function createMemoryAdapter(options = {}) {
|
|
|
87
88
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
88
89
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
89
90
|
}
|
|
91
|
+
function heldBlob(room, path) {
|
|
92
|
+
return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
|
|
93
|
+
}
|
|
94
|
+
function freePath(room, name) {
|
|
95
|
+
const dot = name.lastIndexOf('.');
|
|
96
|
+
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
97
|
+
const extension = dot > 0 ? name.slice(dot) : '';
|
|
98
|
+
for (let count = 1;; count += 1) {
|
|
99
|
+
const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
|
|
100
|
+
if (heldBlob(room, path) === undefined && room.documents?.[path] === undefined)
|
|
101
|
+
return path;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
90
104
|
function retain(entries) {
|
|
91
105
|
for (const room of entries) {
|
|
92
106
|
note(room.locator, room);
|
|
@@ -141,7 +155,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
141
155
|
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
142
156
|
};
|
|
143
157
|
}
|
|
144
|
-
function advancement(room, from, at) {
|
|
158
|
+
function advancement(room, from, at, whole = false) {
|
|
145
159
|
const current = room.documents ?? {};
|
|
146
160
|
const previous = from.documents ?? {};
|
|
147
161
|
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
@@ -152,7 +166,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
152
166
|
const changed = Object.keys(current)
|
|
153
167
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
154
168
|
.sort();
|
|
155
|
-
const size = pageSize ?? changed.length;
|
|
169
|
+
const size = whole ? changed.length : (pageSize ?? changed.length);
|
|
156
170
|
const taken = changed.slice(at, at + size);
|
|
157
171
|
const next = at + taken.length;
|
|
158
172
|
const opening = at === 0;
|
|
@@ -184,6 +198,26 @@ export function createMemoryAdapter(options = {}) {
|
|
|
184
198
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
185
199
|
};
|
|
186
200
|
}
|
|
201
|
+
function carry(locator) {
|
|
202
|
+
const at = carried.get(locator);
|
|
203
|
+
const current = rooms.find((entry) => entry.locator === locator);
|
|
204
|
+
if (at === undefined || current === undefined || current.roomVersion === at)
|
|
205
|
+
return;
|
|
206
|
+
const from = served.get(locator)?.get(at);
|
|
207
|
+
carried.set(locator, current.roomVersion);
|
|
208
|
+
if (from === undefined)
|
|
209
|
+
return;
|
|
210
|
+
const page = advancement(current, from, 0, true);
|
|
211
|
+
for (const observer of observers) {
|
|
212
|
+
observer({
|
|
213
|
+
kind: 'room-change',
|
|
214
|
+
locator,
|
|
215
|
+
from: at,
|
|
216
|
+
roomVersion: current.roomVersion,
|
|
217
|
+
read: async () => page,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
187
221
|
function pageOf(conversation, after) {
|
|
188
222
|
const messages = conversation.messages ?? [];
|
|
189
223
|
const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
|
|
@@ -198,16 +232,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
198
232
|
: {}),
|
|
199
233
|
};
|
|
200
234
|
}
|
|
201
|
-
function historiesOf(
|
|
202
|
-
const asked = input?.conversations;
|
|
203
|
-
if (!Array.isArray(asked))
|
|
204
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
235
|
+
function historiesOf(request) {
|
|
205
236
|
const histories = [];
|
|
206
|
-
for (const entry of
|
|
207
|
-
const conversation =
|
|
237
|
+
for (const entry of request.conversations) {
|
|
238
|
+
const conversation = scripted.get(entry.conversation);
|
|
208
239
|
if (conversation === undefined)
|
|
209
240
|
continue;
|
|
210
|
-
const outcome = conversation.outcomes?.
|
|
241
|
+
const outcome = conversation.outcomes?.history;
|
|
211
242
|
if (outcome !== undefined)
|
|
212
243
|
return outcome;
|
|
213
244
|
histories.push(pageOf(conversation, entry.after));
|
|
@@ -218,15 +249,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
218
249
|
function conversationAction(request) {
|
|
219
250
|
const name = request.name;
|
|
220
251
|
const input = (request.input ?? {});
|
|
221
|
-
if (name === '
|
|
222
|
-
return historiesOf(request.input);
|
|
223
|
-
if (name === 'conversation.create') {
|
|
252
|
+
if (name === 'conversations/create') {
|
|
224
253
|
issued += 1;
|
|
225
254
|
const conversation = `conversation-${issued}`;
|
|
226
255
|
scripted.set(conversation, { conversation });
|
|
227
|
-
return { kind: 'action', result: { conversation } };
|
|
256
|
+
return { kind: 'action', result: { conversation_id: conversation } };
|
|
228
257
|
}
|
|
229
|
-
const named = typeof input.
|
|
258
|
+
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
230
259
|
const conversation = scripted.get(named);
|
|
231
260
|
if (conversation === undefined) {
|
|
232
261
|
return {
|
|
@@ -239,34 +268,28 @@ export function createMemoryAdapter(options = {}) {
|
|
|
239
268
|
const outcome = conversation.outcomes?.[name];
|
|
240
269
|
if (outcome !== undefined)
|
|
241
270
|
return outcome;
|
|
242
|
-
if (name === '
|
|
271
|
+
if (name === 'conversations/send') {
|
|
243
272
|
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
244
273
|
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
245
274
|
if (answered !== undefined)
|
|
246
|
-
return { kind: 'action', result: {
|
|
275
|
+
return { kind: 'action', result: { message_id: answered } };
|
|
247
276
|
issued += 1;
|
|
248
277
|
const turn = `turn-${issued}`;
|
|
249
|
-
unsealed.set(turn, named);
|
|
250
278
|
if (operation !== null)
|
|
251
279
|
sentTurns.set(operation, turn);
|
|
252
|
-
return { kind: 'action', result: { turn } };
|
|
280
|
+
return { kind: 'action', result: { message_id: turn } };
|
|
253
281
|
}
|
|
254
|
-
if (name === '
|
|
255
|
-
const turn = typeof input.turn === 'string' ? input.turn : '';
|
|
256
|
-
if (sealed.has(turn) || !unsealed.has(turn)) {
|
|
257
|
-
return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
|
|
258
|
-
}
|
|
259
|
-
unsealed.delete(turn);
|
|
260
|
-
return { kind: 'action', result: { turn, cancelled: true } };
|
|
261
|
-
}
|
|
262
|
-
if (name === 'conversation.delete')
|
|
282
|
+
if (name === 'conversations/delete')
|
|
263
283
|
scripted.delete(named);
|
|
264
|
-
return { kind: 'action', result: {
|
|
284
|
+
return { kind: 'action', result: { conversation_id: named } };
|
|
265
285
|
}
|
|
266
286
|
function announceList() {
|
|
267
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
268
|
-
|
|
269
|
-
|
|
287
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
288
|
+
? []
|
|
289
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
|
|
290
|
+
for (const listener of listeners) {
|
|
291
|
+
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
292
|
+
}
|
|
270
293
|
}
|
|
271
294
|
function discovery() {
|
|
272
295
|
return {
|
|
@@ -278,8 +301,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
278
301
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
279
302
|
};
|
|
280
303
|
}
|
|
304
|
+
function discovered() {
|
|
305
|
+
return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
|
|
306
|
+
if (answer.kind === 'discovery')
|
|
307
|
+
for (const room of answer.rooms)
|
|
308
|
+
note(room.locator, room);
|
|
309
|
+
return answer;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function opened(notify) {
|
|
313
|
+
const opening = ++openings;
|
|
314
|
+
notify({ kind: 'opened' });
|
|
315
|
+
void discovered()
|
|
316
|
+
.catch(() => ({ kind: 'transport-uncertainty' }))
|
|
317
|
+
.then((answer) => {
|
|
318
|
+
if (opening !== openings)
|
|
319
|
+
return;
|
|
320
|
+
if (answer.kind !== 'discovery') {
|
|
321
|
+
openings += 1;
|
|
322
|
+
carried.clear();
|
|
323
|
+
const revoked = answer.kind === 'revoked-authorization';
|
|
324
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
declaredRooms.clear();
|
|
328
|
+
for (const room of answer.rooms)
|
|
329
|
+
declaredRooms.add(room.locator);
|
|
330
|
+
notify({ kind: 'discovered', discovery: answer });
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function emitAll(event) {
|
|
334
|
+
for (const observer of observers)
|
|
335
|
+
observer(event);
|
|
336
|
+
}
|
|
281
337
|
return {
|
|
282
|
-
...(options.
|
|
338
|
+
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
339
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
283
340
|
setRooms(next) {
|
|
284
341
|
rooms = [...next];
|
|
285
342
|
retain(rooms);
|
|
@@ -288,33 +345,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
288
345
|
scriptConversations(next);
|
|
289
346
|
},
|
|
290
347
|
open() {
|
|
348
|
+
carried.clear();
|
|
291
349
|
announceList();
|
|
292
|
-
|
|
293
|
-
observer({ kind: 'opened' });
|
|
350
|
+
opened(emitAll);
|
|
294
351
|
},
|
|
295
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
296
|
-
|
|
297
|
-
|
|
352
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
353
|
+
openings += 1;
|
|
354
|
+
carried.clear();
|
|
355
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
298
356
|
},
|
|
299
357
|
expire(locators) {
|
|
300
358
|
expiring = [...locators];
|
|
301
359
|
},
|
|
302
|
-
notifyRoomVersion({ locator
|
|
303
|
-
|
|
304
|
-
observer({ kind: 'room-version', locator, roomVersion });
|
|
360
|
+
notifyRoomVersion({ locator }) {
|
|
361
|
+
carry(locator);
|
|
305
362
|
},
|
|
306
|
-
notifyAuthorityChanged(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
363
|
+
notifyAuthorityChanged(locators) {
|
|
364
|
+
const named = new Set(locators ?? [...declaredRooms, ...rooms.map((room) => room.locator)]);
|
|
365
|
+
const listed = rooms.filter((room) => named.has(room.locator));
|
|
366
|
+
const left = [...named].filter((locator) => !listed.some((room) => room.locator === locator));
|
|
367
|
+
for (const room of listed)
|
|
368
|
+
declaredRooms.add(room.locator);
|
|
369
|
+
for (const locator of left)
|
|
370
|
+
declaredRooms.delete(locator);
|
|
371
|
+
emitAll({
|
|
372
|
+
kind: 'authority-changed',
|
|
373
|
+
rooms: listed.map(declared),
|
|
374
|
+
left,
|
|
375
|
+
...(options.member === undefined ? {} : { member: options.member }),
|
|
376
|
+
});
|
|
312
377
|
},
|
|
313
378
|
notifyConversation(event) {
|
|
314
|
-
if (event.kind === 'accepted-message') {
|
|
315
|
-
sealed.add(event.message.turn);
|
|
316
|
-
unsealed.delete(event.message.turn);
|
|
317
|
-
}
|
|
318
379
|
for (const listener of listeners)
|
|
319
380
|
listener(event);
|
|
320
381
|
},
|
|
@@ -323,21 +384,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
323
384
|
observer(mode);
|
|
324
385
|
},
|
|
325
386
|
heldRooms() {
|
|
326
|
-
return
|
|
387
|
+
return [...carried.keys()].sort();
|
|
327
388
|
},
|
|
328
389
|
replicatedConversations() {
|
|
329
390
|
return replicated;
|
|
330
391
|
},
|
|
392
|
+
heldConversationCursor() {
|
|
393
|
+
return heldCursor;
|
|
394
|
+
},
|
|
331
395
|
conversations: {
|
|
332
396
|
replicate(next) {
|
|
333
397
|
replicated = [...next];
|
|
334
398
|
},
|
|
399
|
+
hold(cursor) {
|
|
400
|
+
heldCursor = cursor;
|
|
401
|
+
},
|
|
335
402
|
observe(notify) {
|
|
336
403
|
listeners.add(notify);
|
|
337
404
|
return () => {
|
|
338
405
|
listeners.delete(notify);
|
|
339
406
|
};
|
|
340
407
|
},
|
|
408
|
+
history: (request) => Promise.resolve(historiesOf(request)),
|
|
409
|
+
...(options.agents === undefined
|
|
410
|
+
? {}
|
|
411
|
+
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
341
412
|
},
|
|
342
413
|
serviceMode: {
|
|
343
414
|
observe(notify) {
|
|
@@ -349,44 +420,45 @@ export function createMemoryAdapter(options = {}) {
|
|
|
349
420
|
},
|
|
350
421
|
roomStream: {
|
|
351
422
|
hold(asked) {
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
expiring = [];
|
|
355
|
-
const moved = asked.flatMap((room) => {
|
|
423
|
+
const named = asked.map((room) => room.locator);
|
|
424
|
+
const unknown = asked.flatMap((room) => {
|
|
356
425
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
357
426
|
return current === undefined ||
|
|
358
|
-
|
|
359
|
-
|
|
427
|
+
current.roomVersion === room.roomVersion ||
|
|
428
|
+
served.get(room.locator)?.has(room.roomVersion) === true
|
|
360
429
|
? []
|
|
361
|
-
: [
|
|
362
|
-
});
|
|
363
|
-
queueMicrotask(() => {
|
|
364
|
-
for (const observer of observers) {
|
|
365
|
-
for (const room of moved)
|
|
366
|
-
observer({ kind: 'room-version', ...room });
|
|
367
|
-
observer({ kind: 'opening', expired });
|
|
368
|
-
}
|
|
430
|
+
: [room.locator];
|
|
369
431
|
});
|
|
370
|
-
|
|
371
|
-
|
|
432
|
+
const expired = [
|
|
433
|
+
...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
|
|
434
|
+
];
|
|
435
|
+
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
372
436
|
queueMicrotask(() => {
|
|
373
|
-
for (const
|
|
374
|
-
|
|
437
|
+
for (const room of asked) {
|
|
438
|
+
if (expired.includes(room.locator))
|
|
439
|
+
carried.delete(room.locator);
|
|
440
|
+
else {
|
|
441
|
+
carried.set(room.locator, room.roomVersion);
|
|
442
|
+
carry(room.locator);
|
|
443
|
+
}
|
|
375
444
|
}
|
|
445
|
+
emitAll({ kind: 'caught-up', expired });
|
|
376
446
|
});
|
|
377
447
|
},
|
|
378
|
-
published() { },
|
|
379
448
|
observe(notify) {
|
|
380
449
|
observers.add(notify);
|
|
381
450
|
queueMicrotask(() => {
|
|
382
451
|
if (!observers.has(notify))
|
|
383
452
|
return;
|
|
384
453
|
if (options.unopened === true) {
|
|
385
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
454
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
386
455
|
return;
|
|
387
456
|
}
|
|
388
457
|
announceList();
|
|
389
|
-
|
|
458
|
+
opened((event) => {
|
|
459
|
+
if (observers.has(notify))
|
|
460
|
+
notify(event);
|
|
461
|
+
});
|
|
390
462
|
});
|
|
391
463
|
return () => {
|
|
392
464
|
observers.delete(notify);
|
|
@@ -403,12 +475,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
403
475
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
404
476
|
},
|
|
405
477
|
async discover(_authorization) {
|
|
406
|
-
return
|
|
407
|
-
if (answer.kind === 'discovery')
|
|
408
|
-
for (const room of answer.rooms)
|
|
409
|
-
note(room.locator, room);
|
|
410
|
-
return answer;
|
|
411
|
-
});
|
|
478
|
+
return discovered();
|
|
412
479
|
},
|
|
413
480
|
reached,
|
|
414
481
|
follows(locator, roomVersion, next) {
|
|
@@ -487,32 +554,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
487
554
|
},
|
|
488
555
|
async binary(_authorization, request) {
|
|
489
556
|
return resolveScript(scripts.binary, () => {
|
|
490
|
-
if (request.kind === 'reference') {
|
|
491
|
-
return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
|
|
492
|
-
}
|
|
493
557
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
494
558
|
if (room === undefined)
|
|
495
559
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
496
|
-
const blob = room
|
|
560
|
+
const blob = heldBlob(room, request.path);
|
|
497
561
|
return blob === undefined
|
|
498
562
|
? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
|
|
499
563
|
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
500
564
|
}, request);
|
|
501
565
|
},
|
|
502
566
|
async link(_authorization, request) {
|
|
503
|
-
return resolveScript(scripts.link, () =>
|
|
567
|
+
return resolveScript(scripts.link, () => {
|
|
568
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
569
|
+
if (room === undefined)
|
|
570
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
571
|
+
const blob = heldBlob(room, request.path);
|
|
572
|
+
if (blob === undefined) {
|
|
573
|
+
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
574
|
+
}
|
|
575
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
576
|
+
linked.set(blob, url);
|
|
577
|
+
return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
|
|
578
|
+
}, request);
|
|
504
579
|
},
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
580
|
+
async attach(_authorization, request) {
|
|
581
|
+
return resolveScript(scripts.attach, () => {
|
|
582
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
583
|
+
if (room === undefined)
|
|
584
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
585
|
+
const path = freePath(room, request.name);
|
|
586
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
587
|
+
return { kind: 'attached', path, revision: `attached-${attached.size}` };
|
|
588
|
+
}, request);
|
|
512
589
|
},
|
|
513
590
|
async action(_authorization, request) {
|
|
514
591
|
return resolveScript(scripts.action, () => {
|
|
515
|
-
if (request.name.startsWith('
|
|
592
|
+
if (request.name.startsWith('conversations/'))
|
|
516
593
|
return conversationAction(request);
|
|
517
594
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
518
595
|
}, request).then((answer) => {
|
package/dist/messages.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export type ConversationWrite = {
|
|
|
20
20
|
};
|
|
21
21
|
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
22
22
|
export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
|
|
23
|
-
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null): MessageWindow;
|
|
24
|
-
export declare function messageCount(connection: Connection, conversation: string): number;
|
|
23
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
24
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
25
25
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
26
|
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
27
|
export declare function forgottenMessages(connection: Connection): void;
|
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAE1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAM3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAC;IAC9C,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3E,CAAC;AAMF,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAmB5E;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,iBAAiB,GAClD,IAAI,CA+BN;AAkBD,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EACxC,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,aAAa,CAWf;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAOR;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAO/F;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAK9F;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAG9D"}
|
package/dist/messages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sql } from '@agentshouse/mdmodel';
|
|
2
2
|
export const MESSAGE_TABLES = [
|
|
3
3
|
'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
|
|
4
4
|
'CREATE TABLE conversation_messages (id INTEGER PRIMARY KEY, conversation TEXT NOT NULL, identity TEXT NOT NULL, turn TEXT NOT NULL, position TEXT NOT NULL, message TEXT NOT NULL, text TEXT NOT NULL)',
|
|
@@ -36,17 +36,12 @@ export function keptMessages(connection, { conversation, messages, read }) {
|
|
|
36
36
|
JSON.stringify(message.message ?? null),
|
|
37
37
|
message.text,
|
|
38
38
|
];
|
|
39
|
-
let id;
|
|
40
39
|
if (held === undefined) {
|
|
41
40
|
connection.run('INSERT INTO conversation_messages (conversation, identity, turn, position, message, text) VALUES (?, ?, ?, ?, ?, ?)', [conversation, message.identity, ...record]);
|
|
42
|
-
id = Number(connection.rows('SELECT last_insert_rowid() AS id')[0].id);
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
|
-
id =
|
|
46
|
-
unindexMessages(connection, [id]);
|
|
47
|
-
connection.run('UPDATE conversation_messages SET turn = ?, position = ?, message = ?, text = ? WHERE id = ?', [...record, id]);
|
|
43
|
+
connection.run('UPDATE conversation_messages SET turn = ?, position = ?, message = ?, text = ? WHERE id = ?', [...record, held.id]);
|
|
48
44
|
}
|
|
49
|
-
indexMessage(connection, id, message.text);
|
|
50
45
|
}
|
|
51
46
|
if (read !== undefined) {
|
|
52
47
|
connection.run('INSERT OR REPLACE INTO conversation_reads (conversation, read, partial) VALUES (?, ?, ?)', [conversation, read.at, read.partial ? 1 : 0]);
|
|
@@ -62,14 +57,21 @@ function accepted(row) {
|
|
|
62
57
|
message: JSON.parse(text(row.message)),
|
|
63
58
|
};
|
|
64
59
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
?
|
|
68
|
-
:
|
|
60
|
+
function holding(phrase) {
|
|
61
|
+
return phrase === null
|
|
62
|
+
? { sql: '', bind: [] }
|
|
63
|
+
: { sql: ` AND ${sql.HOLDS_PHRASE}(text, ?)`, bind: [phrase.toLowerCase()] };
|
|
64
|
+
}
|
|
65
|
+
export function messageWindow(connection, conversation, limit, before, phrase) {
|
|
66
|
+
const held = holding(phrase);
|
|
67
|
+
const rows = connection.rows(`SELECT identity, turn, position, message, text FROM conversation_messages WHERE conversation = ?${held.sql}${before === null ? '' : ' AND (position < ? OR (position = ? AND identity < ?))'} ORDER BY position DESC, identity DESC LIMIT ?`, before === null
|
|
68
|
+
? [conversation, ...held.bind, limit + 1]
|
|
69
|
+
: [conversation, ...held.bind, before[0], before[0], before[1], limit + 1]);
|
|
69
70
|
return { messages: rows.slice(0, limit).map(accepted).reverse(), more: rows.length > limit };
|
|
70
71
|
}
|
|
71
|
-
export function messageCount(connection, conversation) {
|
|
72
|
-
const
|
|
72
|
+
export function messageCount(connection, conversation, phrase) {
|
|
73
|
+
const held = holding(phrase);
|
|
74
|
+
const [counted] = connection.rows(`SELECT count(*) AS held FROM conversation_messages WHERE conversation = ?${held.sql}`, [conversation, ...held.bind]);
|
|
73
75
|
return Number(counted?.held ?? 0);
|
|
74
76
|
}
|
|
75
77
|
export function turnArrived(connection, conversation, turn) {
|
|
@@ -77,9 +79,6 @@ export function turnArrived(connection, conversation, turn) {
|
|
|
77
79
|
}
|
|
78
80
|
export function droppedMessages(connection, conversations) {
|
|
79
81
|
for (const conversation of conversations) {
|
|
80
|
-
unindexMessages(connection, connection
|
|
81
|
-
.rows('SELECT id FROM conversation_messages WHERE conversation = ?', [conversation])
|
|
82
|
-
.map((row) => Number(row.id)));
|
|
83
82
|
connection.run('DELETE FROM conversation_messages WHERE conversation = ?', [conversation]);
|
|
84
83
|
connection.run('DELETE FROM conversation_reads WHERE conversation = ?', [conversation]);
|
|
85
84
|
}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Definition,
|
|
1
|
+
import type { Definition, VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { Open } from './open.js';
|
|
3
3
|
export type ModelIdentity = {
|
|
4
4
|
identity: string;
|
|
@@ -28,6 +28,11 @@ export type ModelState = {
|
|
|
28
28
|
verifiedWith: ModelIdentity;
|
|
29
29
|
types: VerifiedModel['types'];
|
|
30
30
|
};
|
|
31
|
+
export type StoredModel = Extract<ModelState, {
|
|
32
|
+
status: 'unavailable';
|
|
33
|
+
}> | Omit<Extract<ModelState, {
|
|
34
|
+
status: 'current' | 'cached';
|
|
35
|
+
}>, 'types'>;
|
|
31
36
|
export type TypesResult = {
|
|
32
37
|
status: Open<'unavailable'>;
|
|
33
38
|
reason: ModelUnavailableReason;
|
|
@@ -51,8 +56,7 @@ export type ValidationReceipt = {
|
|
|
51
56
|
export declare const NO_MODEL: ModelState;
|
|
52
57
|
export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
|
|
53
58
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
59
|
+
export declare function storedModel(state: ModelState): StoredModel;
|
|
54
60
|
export declare function cached(state: ModelState): ModelState;
|
|
55
61
|
export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
|
|
56
|
-
export declare function sameTyping(left: ModelState, right: ModelState): boolean;
|
|
57
|
-
export declare function referenceField(facts: ValueFacts | undefined): boolean;
|
|
58
62
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"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"}
|
package/dist/model.js
CHANGED
|
@@ -14,24 +14,18 @@ export function modelTypes(state) {
|
|
|
14
14
|
verifiedWith: { ...state.verifiedWith },
|
|
15
15
|
schema: state.snapshot.schema,
|
|
16
16
|
revision: state.snapshot.revision,
|
|
17
|
-
types:
|
|
17
|
+
types: Object.values(state.types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0),
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
export function storedModel(state) {
|
|
21
|
+
if (state.status === 'unavailable')
|
|
22
|
+
return state;
|
|
23
|
+
const { types: _types, ...stored } = state;
|
|
24
|
+
return stored;
|
|
25
|
+
}
|
|
20
26
|
export function cached(state) {
|
|
21
27
|
return state.status === 'unavailable' ? state : { ...state, status: 'cached' };
|
|
22
28
|
}
|
|
23
29
|
export function sameModel(left, right) {
|
|
24
30
|
return left.identity === right.identity && left.version === right.version;
|
|
25
31
|
}
|
|
26
|
-
export function sameTyping(left, right) {
|
|
27
|
-
if (left === right)
|
|
28
|
-
return true;
|
|
29
|
-
if (left.status === 'unavailable' || right.status === 'unavailable') {
|
|
30
|
-
return left.status === right.status;
|
|
31
|
-
}
|
|
32
|
-
return (left.snapshot.schema === right.snapshot.schema &&
|
|
33
|
-
sameModel(left.verifiedWith, right.verifiedWith));
|
|
34
|
-
}
|
|
35
|
-
export function referenceField(facts) {
|
|
36
|
-
return facts?.reference !== undefined || facts?.items?.reference !== undefined;
|
|
37
|
-
}
|
package/dist/observation.d.ts
CHANGED
|
@@ -27,8 +27,8 @@ export declare function rowsOf(result: QueryResult): readonly (QueryDocument | Q
|
|
|
27
27
|
export declare function whole(message: QueryMessage): message is KeyedResult;
|
|
28
28
|
export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
|
|
29
29
|
export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
|
|
30
|
-
export declare function opened(watch: (deliver: (message: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
31
|
-
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
30
|
+
export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
|
|
31
|
+
export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
|
|
32
32
|
export type Digest = {
|
|
33
33
|
readonly pending: string;
|
|
34
34
|
} | {
|
|
@@ -38,6 +38,7 @@ export type Digest = {
|
|
|
38
38
|
readonly next: string | undefined;
|
|
39
39
|
readonly total: number | undefined;
|
|
40
40
|
};
|
|
41
|
+
export declare function hashed(text: string): number;
|
|
41
42
|
export declare function digestOf({ result, keys }: KeyedResult): Digest;
|
|
42
43
|
export declare function digestApplied(digest: Digest, message: QueryMessage): Digest;
|
|
43
44
|
export declare function changeOf(previous: Digest, next: KeyedResult): QueryMessage | null;
|