@agentshouse/mdruntime 0.1.0-c49444f2a8fc6 → 0.1.0-c4ef58fbdca7b
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/dist/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +389 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +5 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +12 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -0
- package/dist/compile.d.ts +5 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +186 -55
- package/dist/connection.d.ts +5 -143
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +101 -5309
- package/dist/conversation-live.d.ts +136 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +248 -0
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +7 -1
- package/dist/conversation.d.ts +22 -35
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +827 -972
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- package/dist/durability.d.ts +9 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +1 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +7 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +556 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +268 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +175 -0
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +61 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +61 -0
- package/dist/messages.d.ts +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +1 -1
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +193 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +57 -0
- package/dist/outcome.d.ts +4 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +226 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -0
- package/dist/query.d.ts +10 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +2 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +4 -0
- package/dist/reach.d.ts +3 -1
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +11 -0
- package/dist/react.d.ts +7 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +0 -1
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +171 -0
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +56 -0
- package/dist/replica.d.ts +0 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -1
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +216 -0
- package/dist/runtime.d.ts +43 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +3 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +7 -5
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1006 -0
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -0
- package/dist/shared.d.ts +1 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +9 -5
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +295 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/rooms.d.ts +43 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +39 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -0
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +431 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +43 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +57 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +111 -206
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +142 -398
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +22 -8
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +223 -0
- package/dist/sync.d.ts +20 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +532 -0
- package/dist/tables.d.ts +32 -3
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +36 -2
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/wire.d.ts +8 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +4 -0
- package/package.json +2 -2
package/dist/stored.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { sql } from '@agentshouse/mdmodel';
|
|
1
|
+
import { instantKey, sql } from '@agentshouse/mdmodel';
|
|
2
2
|
import { composedOf } from './collection.js';
|
|
3
3
|
import { described, derived, heldOf } from './rows.js';
|
|
4
4
|
export const REPLICA_TABLES = [
|
|
5
5
|
'CREATE TABLE replica_keys (key INTEGER PRIMARY KEY AUTOINCREMENT, locator TEXT NOT NULL, transfer TEXT NOT NULL, fingerprint TEXT NOT NULL, rederiving INTEGER)',
|
|
6
6
|
'CREATE TABLE replica_rooms (locator TEXT PRIMARY KEY, key INTEGER NOT NULL, record TEXT NOT NULL, documents INTEGER NOT NULL DEFAULT 0) WITHOUT ROWID',
|
|
7
|
+
"CREATE INDEX replica_rooms_model ON replica_rooms (json_extract(record, '$.model.snapshot.identity'), json_extract(record, '$.model.snapshot.version'))",
|
|
7
8
|
'CREATE TABLE replica_models (identity TEXT NOT NULL, version TEXT NOT NULL, schema TEXT NOT NULL, PRIMARY KEY (identity, version)) WITHOUT ROWID',
|
|
8
|
-
"CREATE TABLE replica_entries (id INTEGER PRIMARY KEY, key INTEGER NOT NULL, layer INTEGER NOT NULL, path TEXT NOT NULL, visible INTEGER NOT NULL, present INTEGER NOT NULL, queried INTEGER NOT NULL, binary TEXT, revision TEXT, file_id TEXT, change TEXT, written TEXT, type TEXT, declared TEXT, folder TEXT NOT NULL, fields TEXT, links TEXT, part TEXT, created TEXT, bytes INTEGER GENERATED ALWAYS AS (CASE WHEN binary IS NULL THEN length(CAST(content AS BLOB)) ELSE binary ->> '$.byteLength' END) STORED, content TEXT)",
|
|
9
|
+
"CREATE TABLE replica_entries (id INTEGER PRIMARY KEY, key INTEGER NOT NULL, layer INTEGER NOT NULL, path TEXT NOT NULL, visible INTEGER NOT NULL, present INTEGER NOT NULL, queried INTEGER NOT NULL, binary TEXT, revision TEXT, file_id TEXT, change TEXT, written TEXT, type TEXT, declared TEXT, folder TEXT NOT NULL, fields TEXT, links TEXT, part TEXT, created TEXT, created_instant TEXT, changed_instant TEXT, bytes INTEGER GENERATED ALWAYS AS (CASE WHEN binary IS NULL THEN length(CAST(content AS BLOB)) ELSE binary ->> '$.byteLength' END) STORED, content TEXT)",
|
|
9
10
|
'CREATE UNIQUE INDEX replica_entries_path ON replica_entries (key, layer, path)',
|
|
10
11
|
'CREATE INDEX replica_entries_visible ON replica_entries (key, visible, present, path, binary)',
|
|
11
12
|
'CREATE INDEX replica_entries_folder ON replica_entries (key, folder, path)',
|
|
@@ -77,7 +78,7 @@ function removeEntry(connection, key, layer, path) {
|
|
|
77
78
|
connection.run('DELETE FROM replica_entries WHERE id = ?', [id]);
|
|
78
79
|
}
|
|
79
80
|
function insertEntry(connection, key, layer, entry, present, made, part = null) {
|
|
80
|
-
connection.run('INSERT INTO replica_entries (key, layer, path, visible, present, queried, content, binary, revision, file_id, created, change, written, type, declared, folder, fields, links, part) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
|
81
|
+
connection.run('INSERT INTO replica_entries (key, layer, path, visible, present, queried, content, binary, revision, file_id, created, created_instant, change, changed_instant, written, type, declared, folder, fields, links, part) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
|
81
82
|
key,
|
|
82
83
|
layer,
|
|
83
84
|
entry.path,
|
|
@@ -89,7 +90,9 @@ function insertEntry(connection, key, layer, entry, present, made, part = null)
|
|
|
89
90
|
entry.revision,
|
|
90
91
|
entry.fileId,
|
|
91
92
|
entry.created,
|
|
93
|
+
instantKey(entry.created),
|
|
92
94
|
entry.change === null ? null : JSON.stringify(entry.change),
|
|
95
|
+
instantKey(entry.change?.time),
|
|
93
96
|
entry.written,
|
|
94
97
|
made.type,
|
|
95
98
|
made.declared,
|
|
@@ -212,7 +215,7 @@ export function resume(connection, request) {
|
|
|
212
215
|
if (copied.length > 0 && request.published !== null) {
|
|
213
216
|
owing(connection, key);
|
|
214
217
|
const named = JSON.stringify(copied);
|
|
215
|
-
connection.run(`INSERT INTO replica_entries (key, layer, path, visible, present, queried, content, binary, revision, file_id, created, change, written, type, declared, folder, fields, links, part) SELECT ?, ${CONFIRMED}, path, 1, 1, queried, content, binary, revision, file_id, created, change, written, type, declared, folder, fields, links, part FROM replica_entries WHERE key = ? AND layer = ${CONFIRMED} AND present = 1 AND part IN (SELECT value FROM json_each(?)) ORDER BY path`, [key, request.published, named]);
|
|
218
|
+
connection.run(`INSERT INTO replica_entries (key, layer, path, visible, present, queried, content, binary, revision, file_id, created, created_instant, change, changed_instant, written, type, declared, folder, fields, links, part) SELECT ?, ${CONFIRMED}, path, 1, 1, queried, content, binary, revision, file_id, created, created_instant, change, changed_instant, written, type, declared, folder, fields, links, part FROM replica_entries WHERE key = ? AND layer = ${CONFIRMED} AND present = 1 AND part IN (SELECT value FROM json_each(?)) ORDER BY path`, [key, request.published, named]);
|
|
216
219
|
connection.run(`INSERT OR REPLACE INTO replica_folders (key, layer, path, present, part) SELECT ?, ${CONFIRMED}, path, 1, part FROM replica_folders WHERE key = ? AND layer = ${CONFIRMED} AND present = 1 AND part IN (SELECT value FROM json_each(?))`, [key, request.published, named]);
|
|
217
220
|
}
|
|
218
221
|
return { key, transfer: held?.transfer ?? request.transfer, staged: [...kept, ...copied] };
|
|
@@ -338,8 +341,10 @@ function commitRoom(connection, room) {
|
|
|
338
341
|
const changed = [...touched];
|
|
339
342
|
revealed(connection, room.key, changed);
|
|
340
343
|
if (room.record !== undefined) {
|
|
344
|
+
const replaced = heldModel(connection, room.locator);
|
|
341
345
|
connection.run(KEEP_MODEL, [room.record, room.record, room.record, room.record]);
|
|
342
346
|
connection.run(`INSERT OR REPLACE INTO replica_rooms (locator, key, record) VALUES (?, ?, ${MODEL_LEFT})`, [room.locator, room.key, room.record, room.record, room.record]);
|
|
347
|
+
letGo(connection, replaced);
|
|
343
348
|
}
|
|
344
349
|
return room.published === undefined ? changed : null;
|
|
345
350
|
}
|
|
@@ -349,11 +354,21 @@ const KEEP_MODEL = `INSERT OR IGNORE INTO replica_models (identity, version, sch
|
|
|
349
354
|
json_extract(?, '${SCHEMA}')
|
|
350
355
|
WHERE json_type(?, '${SCHEMA}') = 'text'`;
|
|
351
356
|
const MODEL_LEFT = `CASE WHEN json_type(?, '${SCHEMA}') = 'text' THEN json_set(?, '${SCHEMA}', json('null')) ELSE ? END`;
|
|
352
|
-
const
|
|
357
|
+
const HELD_MODEL = `SELECT json_extract(record, '$.model.snapshot.identity') AS identity,
|
|
358
|
+
json_extract(record, '$.model.snapshot.version') AS version
|
|
359
|
+
FROM replica_rooms WHERE locator = ?`;
|
|
360
|
+
const UNHELD_MODEL = `DELETE FROM replica_models WHERE identity = ? AND version = ? AND NOT EXISTS (
|
|
353
361
|
SELECT 1 FROM replica_rooms r
|
|
354
362
|
WHERE json_extract(r.record, '$.model.snapshot.identity') = replica_models.identity
|
|
355
363
|
AND json_extract(r.record, '$.model.snapshot.version') = replica_models.version
|
|
356
364
|
)`;
|
|
365
|
+
function heldModel(connection, locator) {
|
|
366
|
+
return connection.rows(HELD_MODEL, [locator])[0];
|
|
367
|
+
}
|
|
368
|
+
function letGo(connection, model) {
|
|
369
|
+
if (model !== undefined)
|
|
370
|
+
connection.run(UNHELD_MODEL, [model.identity, model.version]);
|
|
371
|
+
}
|
|
357
372
|
const HELD_RECORDS = `SELECT r.locator, r.key, CASE WHEN m.schema IS NULL THEN r.record
|
|
358
373
|
ELSE json_set(r.record, '${SCHEMA}', m.schema) END AS record
|
|
359
374
|
FROM replica_rooms r
|
|
@@ -373,8 +388,6 @@ export function commit(connection, rooms) {
|
|
|
373
388
|
const [held] = connection.rows('SELECT rederiving FROM replica_keys WHERE key = ?', [room.key]);
|
|
374
389
|
indexed[room.locator] = held !== undefined && held.rederiving === null;
|
|
375
390
|
}
|
|
376
|
-
if (rooms.some((room) => room.record !== undefined))
|
|
377
|
-
connection.run(UNHELD_MODELS);
|
|
378
391
|
return { changed, indexed };
|
|
379
392
|
}
|
|
380
393
|
function rootsOf(connection, locator) {
|
|
@@ -387,9 +400,10 @@ export function fenceRooms(connection, locators) {
|
|
|
387
400
|
for (const row of connection.rows('SELECT key FROM replica_keys WHERE locator = ? UNION SELECT key FROM replica_rooms WHERE locator = ?', [locator, locator])) {
|
|
388
401
|
erasing(connection, number(row.key), locator);
|
|
389
402
|
}
|
|
403
|
+
const replaced = heldModel(connection, locator);
|
|
390
404
|
connection.run('DELETE FROM replica_rooms WHERE locator = ?', [locator]);
|
|
405
|
+
letGo(connection, replaced);
|
|
391
406
|
}
|
|
392
|
-
connection.run(UNHELD_MODELS);
|
|
393
407
|
return null;
|
|
394
408
|
}
|
|
395
409
|
export function abandon(connection, locator) {
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { DocumentQuery, GroupQuery } from '@agentshouse/mdmodel';
|
|
2
|
+
import { type HistoryQuery } from './actions.js';
|
|
3
|
+
import type { Member, ServiceMode } from './adapter.js';
|
|
4
|
+
import type { WrittenBy } from './change.js';
|
|
5
|
+
import { type ChatDraftSurface, type ConversationEntry, type ConversationAgent, type ConversationOptions, type ConversationSurface, type ConversationView } from './conversation.js';
|
|
6
|
+
import type { UnsentWork } from './durability.js';
|
|
7
|
+
import type { FiguresResult } from './figures.js';
|
|
8
|
+
import { type Holdings } from './holdings.js';
|
|
9
|
+
import { type AppRoom } from './listing.js';
|
|
10
|
+
import { type TypesResult } from './model.js';
|
|
11
|
+
import { type Observation } from './observation.js';
|
|
12
|
+
import type { HistoryAnswer, QueueEntry, Resolution, CallResult } from './outcome.js';
|
|
13
|
+
import { type ReadinessPort } from './preparation.js';
|
|
14
|
+
import type { DocumentResult, GroupResult, PendingResult } from './query.js';
|
|
15
|
+
import { type NarrowedView, type PortReach, type RuntimeView } from './reach.js';
|
|
16
|
+
import type { Persistence, Readiness } from './readiness.js';
|
|
17
|
+
import type { ObservedRead } from './reads.js';
|
|
18
|
+
import type { RoomDraft } from './room-draft.js';
|
|
19
|
+
import { type PresentationSurface, type RoomDraftSurface } from './room-drafts.js';
|
|
20
|
+
import type { Runtime } from './runtime.js';
|
|
21
|
+
import { type BinaryFileSurface, type SavedParts, type SavedRoomDraft, type SaveResult } from './saves.js';
|
|
22
|
+
import type { SearchRequest, SearchResult } from './search.js';
|
|
23
|
+
import { type EntrySeed } from './seed.js';
|
|
24
|
+
import type { ConnectionRefusal } from './socket.js';
|
|
25
|
+
import type { SyncStatus } from './status.js';
|
|
26
|
+
export type RoomSchemas = {
|
|
27
|
+
collection: TypesResult;
|
|
28
|
+
typedSelection: TypesResult | null;
|
|
29
|
+
};
|
|
30
|
+
export type MdRuntime = {
|
|
31
|
+
loaded(): Promise<void>;
|
|
32
|
+
rooms(): Promise<readonly AppRoom[]>;
|
|
33
|
+
query: {
|
|
34
|
+
(query: DocumentQuery): Promise<DocumentResult | PendingResult>;
|
|
35
|
+
(query: GroupQuery): Promise<GroupResult | PendingResult>;
|
|
36
|
+
};
|
|
37
|
+
search(request: SearchRequest): Promise<SearchResult>;
|
|
38
|
+
types(locator: string): Promise<RoomSchemas>;
|
|
39
|
+
roomDraft: RoomDraftSurface;
|
|
40
|
+
conversation: ConversationSurface;
|
|
41
|
+
chatDraft: ChatDraftSurface;
|
|
42
|
+
presentation: PresentationSurface;
|
|
43
|
+
save(room: string, roomDrafts: readonly SavedRoomDraft[], writtenBy?: WrittenBy): Promise<SaveResult>;
|
|
44
|
+
saveParts(room: string, parts: readonly SavedParts[], writtenBy?: WrittenBy): Promise<SaveResult>;
|
|
45
|
+
history(locator: string, path: string, query?: HistoryQuery): Promise<HistoryAnswer>;
|
|
46
|
+
resolve(room: string, path: string, destination: string): Promise<Resolution>;
|
|
47
|
+
binaryFile: BinaryFileSurface;
|
|
48
|
+
call(name: string, input: unknown): Promise<CallResult>;
|
|
49
|
+
reached(locator: string, roomVersion: string, path?: string): Promise<boolean>;
|
|
50
|
+
log(): string;
|
|
51
|
+
persistence(): boolean;
|
|
52
|
+
retry(): Promise<void>;
|
|
53
|
+
cleanUp(): Promise<number>;
|
|
54
|
+
unsent(): Promise<readonly UnsentWork[]>;
|
|
55
|
+
reset(): Promise<void>;
|
|
56
|
+
readAgain(): Promise<void>;
|
|
57
|
+
observe: {
|
|
58
|
+
(topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
|
|
59
|
+
(topic: 'readiness'): Promise<Observation<Readiness>>;
|
|
60
|
+
(topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
|
|
61
|
+
(topic: 'storage-loss'): Promise<Observation<string | null>>;
|
|
62
|
+
(topic: 'sync-status'): Promise<Observation<SyncStatus>>;
|
|
63
|
+
(topic: 'service-mode'): Promise<Observation<ServiceMode>>;
|
|
64
|
+
(topic: 'member'): Promise<Observation<Member | null>>;
|
|
65
|
+
(topic: 'authority-changes'): Promise<Observation<number>>;
|
|
66
|
+
(topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
|
|
67
|
+
(topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
|
|
68
|
+
(topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
|
|
69
|
+
(topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
|
|
70
|
+
(topic: 'presentation', app: string): Promise<Observation<unknown>>;
|
|
71
|
+
(topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
|
|
72
|
+
(topic: 'conversations'): Promise<Observation<readonly ConversationEntry[]>>;
|
|
73
|
+
(topic: 'agents'): Promise<Observation<readonly ConversationAgent[]>>;
|
|
74
|
+
(topic: 'figures'): Promise<Observation<FiguresResult>>;
|
|
75
|
+
(topic: 'holdings'): Promise<Observation<Holdings>>;
|
|
76
|
+
(topic: 'read', name: string, input: unknown): Promise<Observation<ObservedRead>>;
|
|
77
|
+
};
|
|
78
|
+
reauthorize(): Promise<void>;
|
|
79
|
+
};
|
|
80
|
+
export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'authority-changes' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents' | 'figures' | 'holdings' | 'read';
|
|
81
|
+
export type ComposedRuntime = RuntimeView & {
|
|
82
|
+
seed(entry: EntrySeed): void;
|
|
83
|
+
stop(): Promise<void>;
|
|
84
|
+
persisted(answer: Persistence): void;
|
|
85
|
+
within(reach: PortReach | null, port: ReadinessPort): NarrowedView;
|
|
86
|
+
};
|
|
87
|
+
export declare function composedRuntime(runtime: Runtime): ComposedRuntime;
|
|
88
|
+
//# sourceMappingURL=surface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surface.d.ts","sourceRoot":"","sources":["../src/surface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAkD,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAML,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAgC,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5E,OAAO,EAAkD,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5F,OAAO,EAAwB,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAQ,MAAM,YAAY,CAAC;AACnF,OAAO,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AI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IACrC,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;CACpE,CAAC;AA4KF,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAyCjE"}
|
package/dist/surface.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { called, located, readHistory, resolveReference } from './actions.js';
|
|
2
|
+
import { chatDraftSurface, conversationSurface, watchConversation, watchConversationAgents, watchConversationList, } from './conversation.js';
|
|
3
|
+
import { CLEANED_TOPIC, watchHoldings } from './holdings.js';
|
|
4
|
+
import { reachedBy, writtenAfter } from './install.js';
|
|
5
|
+
import { declarationOf, listingNow, modelIn, shownRooms } from './listing.js';
|
|
6
|
+
import { stop } from './lifecycle.js';
|
|
7
|
+
import { locked, lockedRooms, watchLocks } from './locks.js';
|
|
8
|
+
import { modelTypes, NO_MODEL } from './model.js';
|
|
9
|
+
import { observing } from './observation.js';
|
|
10
|
+
import { watchReadiness } from './preparation.js';
|
|
11
|
+
import { planned, rowsQuery, searched, watchPlan, watchPlanned } from './queries.js';
|
|
12
|
+
import { narrowed, } from './reach.js';
|
|
13
|
+
import { presentationSurface, roomDraftSurface, watchPresentation, watchRoomDrafts, } from './room-drafts.js';
|
|
14
|
+
import { binaryFileSurface, saveParts, saveRoomDrafts, } from './saves.js';
|
|
15
|
+
import { keepEntrySeed } from './seed.js';
|
|
16
|
+
import { AUTHORITY_TOPIC, emitKnownRooms, entriesOf, MEMBER_TOPIC, queueTopic, REFUSAL_TOPIC, ROOMS_TOPIC, SERVICE_MODE_TOPIC, STATUS_TOPIC, STORAGE_LOSS_TOPIC, } from './shown.js';
|
|
17
|
+
import { OPENING_LANE, sync } from './sync.js';
|
|
18
|
+
function told(store, topic, deliver, current) {
|
|
19
|
+
const watcher = store.watch(topic, deliver);
|
|
20
|
+
deliver(current);
|
|
21
|
+
return watcher.stop;
|
|
22
|
+
}
|
|
23
|
+
function watchRooms(runtime, deliver) {
|
|
24
|
+
const { store } = runtime;
|
|
25
|
+
const watcher = store.watch(ROOMS_TOPIC, deliver);
|
|
26
|
+
emitKnownRooms(runtime);
|
|
27
|
+
return () => {
|
|
28
|
+
watcher.stop();
|
|
29
|
+
if (store.watching(ROOMS_TOPIC, 'ready').length === 0)
|
|
30
|
+
store.device.set({ roomsShown: null });
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function watchMember({ store }, deliver) {
|
|
34
|
+
const watcher = store.watch(MEMBER_TOPIC, deliver);
|
|
35
|
+
void store
|
|
36
|
+
.open()
|
|
37
|
+
.then((local) => local.facts())
|
|
38
|
+
.then(({ member }) => {
|
|
39
|
+
if (watcher.held())
|
|
40
|
+
deliver(member);
|
|
41
|
+
}, () => { });
|
|
42
|
+
return watcher.stop;
|
|
43
|
+
}
|
|
44
|
+
function watchQueue(runtime, locator, deliver) {
|
|
45
|
+
const { store } = runtime;
|
|
46
|
+
const watcher = store.watch(queueTopic(locator), deliver);
|
|
47
|
+
void store.publication(async () => {
|
|
48
|
+
if (!watcher.held())
|
|
49
|
+
return;
|
|
50
|
+
const entries = await entriesOf(runtime, locator);
|
|
51
|
+
if (watcher.held())
|
|
52
|
+
watcher.answer(entries);
|
|
53
|
+
});
|
|
54
|
+
return watcher.stop;
|
|
55
|
+
}
|
|
56
|
+
function watching(runtime) {
|
|
57
|
+
const { store, socket, conversations, figures, lastAnswers } = runtime;
|
|
58
|
+
return (topic, input, deliver, fail) => {
|
|
59
|
+
const session = socket.session.now();
|
|
60
|
+
if (topic === 'room-drafts')
|
|
61
|
+
return watchRoomDrafts(runtime, deliver);
|
|
62
|
+
if (topic === 'conversation') {
|
|
63
|
+
return watchConversation(conversations, input[0], input[1], deliver);
|
|
64
|
+
}
|
|
65
|
+
if (topic === 'conversations')
|
|
66
|
+
return watchConversationList(conversations, deliver);
|
|
67
|
+
if (topic === 'agents')
|
|
68
|
+
return watchConversationAgents(conversations, deliver);
|
|
69
|
+
if (topic === 'figures')
|
|
70
|
+
return figures.watch(deliver, fail);
|
|
71
|
+
if (topic === 'holdings')
|
|
72
|
+
return watchHoldings(runtime, deliver, fail);
|
|
73
|
+
if (topic === 'read')
|
|
74
|
+
return lastAnswers.watch(input[0], input[1], deliver);
|
|
75
|
+
if (topic === 'presentation')
|
|
76
|
+
return watchPresentation(runtime, input[0], deliver);
|
|
77
|
+
if (topic === 'readiness') {
|
|
78
|
+
return watchReadiness(runtime, { target: '', code: 'stored' }, null, deliver);
|
|
79
|
+
}
|
|
80
|
+
if (topic === 'rooms')
|
|
81
|
+
return watchRooms(runtime, deliver);
|
|
82
|
+
if (topic === 'connection-refusal') {
|
|
83
|
+
return told(store, REFUSAL_TOPIC, deliver, session.refusal);
|
|
84
|
+
}
|
|
85
|
+
if (topic === 'storage-loss') {
|
|
86
|
+
return told(store, STORAGE_LOSS_TOPIC, deliver, store.device.now().storageLoss);
|
|
87
|
+
}
|
|
88
|
+
if (topic === 'sync-status') {
|
|
89
|
+
return told(store, STATUS_TOPIC, deliver, store.device.now().status);
|
|
90
|
+
}
|
|
91
|
+
if (topic === 'service-mode') {
|
|
92
|
+
return told(store, SERVICE_MODE_TOPIC, deliver, session.serviceMode);
|
|
93
|
+
}
|
|
94
|
+
if (topic === 'member')
|
|
95
|
+
return watchMember(runtime, deliver);
|
|
96
|
+
if (topic === 'authority-changes') {
|
|
97
|
+
return told(store, AUTHORITY_TOPIC, deliver, session.authorityChanges);
|
|
98
|
+
}
|
|
99
|
+
if (topic === 'queue')
|
|
100
|
+
return watchQueue(runtime, input[0], deliver);
|
|
101
|
+
return watchPlanned(runtime, planned(runtime, input[0], null), deliver, fail);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function roomsOnce(runtime) {
|
|
105
|
+
const { store, socket } = runtime;
|
|
106
|
+
if (socket.closed())
|
|
107
|
+
return Promise.resolve([]);
|
|
108
|
+
return new Promise((settle) => {
|
|
109
|
+
const watcher = store.watch(ROOMS_TOPIC, (value) => {
|
|
110
|
+
watcher.stop();
|
|
111
|
+
settle(value);
|
|
112
|
+
});
|
|
113
|
+
emitKnownRooms(runtime);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async function typesOf(runtime, locator) {
|
|
117
|
+
const { store, builtIn } = runtime;
|
|
118
|
+
const held = (await store.rooms([locator])).get(locator);
|
|
119
|
+
const fenced = store.fences.has(locator);
|
|
120
|
+
const room = fenced ? undefined : declarationOf(runtime, locator, held)?.room;
|
|
121
|
+
return {
|
|
122
|
+
collection: modelTypes(fenced ? NO_MODEL : modelIn(runtime, locator, held)),
|
|
123
|
+
typedSelection: (room?.typedSelection ?? null) === null ? null : modelTypes(builtIn),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async function reauthorized(runtime) {
|
|
127
|
+
const { store, socket, journal } = runtime;
|
|
128
|
+
const { refusal } = socket.session.now();
|
|
129
|
+
if (refusal === null || !refusal.reauthorizationOffered)
|
|
130
|
+
return;
|
|
131
|
+
journal.record('connection reauthorize');
|
|
132
|
+
await socket.lanes.current();
|
|
133
|
+
await store.written();
|
|
134
|
+
socket.session.set({ authorization: undefined, paused: false });
|
|
135
|
+
if (!socket.streamed)
|
|
136
|
+
await sync(runtime, 'unstreamed', null);
|
|
137
|
+
else
|
|
138
|
+
await socket.lanes.task(OPENING_LANE, () => socket.authorize());
|
|
139
|
+
}
|
|
140
|
+
function mdRuntime(runtime, watch) {
|
|
141
|
+
const { store, socket, journal, shell, conversations, lastAnswers } = runtime;
|
|
142
|
+
return {
|
|
143
|
+
loaded: () => store.open().then(() => undefined),
|
|
144
|
+
rooms: () => roomsOnce(runtime),
|
|
145
|
+
query: ((input) => planned(runtime, input, null).then((plan) => rowsQuery(runtime, plan))),
|
|
146
|
+
search: (input) => searched(runtime, input, null),
|
|
147
|
+
types: (locator) => typesOf(runtime, locator),
|
|
148
|
+
roomDraft: roomDraftSurface(runtime),
|
|
149
|
+
conversation: conversationSurface(conversations),
|
|
150
|
+
chatDraft: chatDraftSurface(conversations),
|
|
151
|
+
presentation: presentationSurface(runtime),
|
|
152
|
+
save: (room, named, writtenBy) => store.exclusive(() => saveRoomDrafts(runtime, room, named, writtenBy)),
|
|
153
|
+
saveParts: (room, parts, writtenBy) => store.exclusive(() => saveParts(runtime, room, parts, writtenBy)),
|
|
154
|
+
history: (locator, path, query) => readHistory(runtime, locator, path, query),
|
|
155
|
+
resolve: (room, path, destination) => resolveReference(runtime, room, path, destination),
|
|
156
|
+
binaryFile: binaryFileSurface(runtime),
|
|
157
|
+
call: (name, input) => called(runtime, name, input),
|
|
158
|
+
async reached(locator, roomVersion, path) {
|
|
159
|
+
return path === undefined
|
|
160
|
+
? reachedBy(runtime, locator, roomVersion)
|
|
161
|
+
: writtenAfter(runtime, locator, roomVersion, path);
|
|
162
|
+
},
|
|
163
|
+
log: () => journal.export(),
|
|
164
|
+
async cleanUp() {
|
|
165
|
+
const freed = await store.ask({ kind: 'opened.clean' });
|
|
166
|
+
const tidied = (await shell.cleanUp?.()) ?? 0;
|
|
167
|
+
store.tell(CLEANED_TOPIC, undefined);
|
|
168
|
+
return freed + tidied;
|
|
169
|
+
},
|
|
170
|
+
unsent: () => store.ask({ kind: 'authored.unsent' }),
|
|
171
|
+
reset: () => shell.reset(),
|
|
172
|
+
async readAgain() {
|
|
173
|
+
lastAnswers.again();
|
|
174
|
+
},
|
|
175
|
+
persistence: () => store.device.now().persistence === 'granted',
|
|
176
|
+
async retry() {
|
|
177
|
+
journal.record('retry');
|
|
178
|
+
socket.rooms.standAll({ unpreparable: false });
|
|
179
|
+
store.readiness.queue();
|
|
180
|
+
if (store.space.full())
|
|
181
|
+
await store.space.probe();
|
|
182
|
+
},
|
|
183
|
+
observe: observing(watch),
|
|
184
|
+
reauthorize: () => reauthorized(runtime),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export function composedRuntime(runtime) {
|
|
188
|
+
const { store, journal } = runtime;
|
|
189
|
+
const watch = watching(runtime);
|
|
190
|
+
const md = mdRuntime(runtime, watch);
|
|
191
|
+
const reachable = {
|
|
192
|
+
md,
|
|
193
|
+
watch,
|
|
194
|
+
plan: (input, reach) => planned(runtime, input, reach),
|
|
195
|
+
query: (plan) => rowsQuery(runtime, plan),
|
|
196
|
+
watchPlan: (plan, deliver, fail) => watchPlan(runtime, plan, deliver, fail),
|
|
197
|
+
search: (input, reach) => searched(runtime, input, reach),
|
|
198
|
+
watchReadiness: (port, reach, deliver) => watchReadiness(runtime, port, reach, deliver),
|
|
199
|
+
locked: (locator) => locked(runtime, locator),
|
|
200
|
+
lockedRooms: () => lockedRooms(runtime),
|
|
201
|
+
watchLocks: (notify) => watchLocks(runtime, notify),
|
|
202
|
+
located: (room, path, destination) => located(runtime, room, path, destination),
|
|
203
|
+
room: async (locator) => shownRooms(runtime, await listingNow(runtime)).find((one) => one.locator === locator),
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
md,
|
|
207
|
+
seed: (entry) => keepEntrySeed(store, entry),
|
|
208
|
+
stop: () => stop(runtime),
|
|
209
|
+
watch,
|
|
210
|
+
persisted(answer) {
|
|
211
|
+
if (answer === store.device.now().persistence)
|
|
212
|
+
return;
|
|
213
|
+
store.device.set({ persistence: answer });
|
|
214
|
+
journal.record(`persistence ${answer}`);
|
|
215
|
+
store.readiness.queue();
|
|
216
|
+
},
|
|
217
|
+
within(reach, port) {
|
|
218
|
+
if (store.space.full())
|
|
219
|
+
void store.space.probe();
|
|
220
|
+
return narrowed(reachable, reach, port);
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
package/dist/sync.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Authorization, AuthorityChange, DiscoveredRoom, Discovery, RoomChange } from './adapter.js';
|
|
2
|
+
import { type Unheld, type Withheld } from './install.js';
|
|
3
|
+
import type { Runtime } from './runtime.js';
|
|
4
|
+
import type { Live } from './socket.js';
|
|
5
|
+
import type { CycleProgress } from './status.js';
|
|
6
|
+
import type { RuntimeStore } from './store.js';
|
|
7
|
+
export type Attempt = 'opened' | 'unstreamed' | 'authorized';
|
|
8
|
+
export declare const OPENING_LANE = "opening";
|
|
9
|
+
export declare function advanced(runtime: Runtime, room: DiscoveredRoom, local: RuntimeStore, authorized: Authorization): Promise<Withheld | null>;
|
|
10
|
+
export declare function withhold(runtime: Runtime, withheld: Withheld, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress): Promise<void>;
|
|
11
|
+
export declare function synchronize(runtime: Runtime, listed: readonly DiscoveredRoom[], local: RuntimeStore, progress: CycleProgress, attempt: Attempt, live: Live): Promise<void>;
|
|
12
|
+
export declare function loadRoom(runtime: Runtime, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress, live: Live, unheld?: Unheld): Promise<void>;
|
|
13
|
+
export declare function reload(runtime: Runtime, room: DiscoveredRoom, local: RuntimeStore, progress: CycleProgress, live: Live): Promise<void>;
|
|
14
|
+
export declare function finishOpening(runtime: Runtime, progress: CycleProgress, live: Live): Promise<void>;
|
|
15
|
+
export declare function sync(runtime: Runtime, attempt: Attempt, found: Discovery | null): Promise<void>;
|
|
16
|
+
export declare function resynchronize(runtime: Runtime): Promise<void>;
|
|
17
|
+
export declare function countAuthorityChange({ store, socket, lastAnswers }: Runtime): void;
|
|
18
|
+
export declare function changeAuthority(runtime: Runtime, change: AuthorityChange): Promise<void>;
|
|
19
|
+
export declare function applyRoom(runtime: Runtime, change: RoomChange): Promise<void>;
|
|
20
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,cAAc,EACd,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAC;AAUtB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