@agentshouse/mdruntime 0.1.0-cee9c8aa4cd86 → 0.1.0-cef76ea952695
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 +19 -17
- package/dist/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +385 -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 +111 -109
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +5 -11
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +36 -47
- 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 +22 -10
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +303 -123
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- 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 +30 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -10
- 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 +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +290 -297
- package/dist/connection.d.ts +6 -142
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +105 -4827
- 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-live.d.ts +135 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +247 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +42 -46
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +901 -815
- 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 +15 -4
- 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 +18 -8
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -11
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +6 -4
- 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 +4 -6
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +59 -38
- 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 +30 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +556 -0
- package/dist/job.d.ts +5 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +270 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +176 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +63 -21
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +62 -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/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +13 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +219 -102
- package/dist/messages.d.ts +24 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +89 -31
- package/dist/model.d.ts +8 -10
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -18
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +197 -0
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +15 -15
- package/dist/opened.js +3 -3
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +60 -0
- package/dist/outcome.d.ts +17 -7
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +19 -5
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +12 -1
- package/dist/parts.d.ts +11 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +21 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +26 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -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 +19 -206
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -494
- package/dist/{chat/questions.d.ts → questions.d.ts} +5 -2
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +13 -2
- package/dist/reach.d.ts +20 -13
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +204 -135
- package/dist/react.d.ts +14 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -1
- package/dist/{chat/read.d.ts → read.d.ts} +2 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/{chat/read.js → read.js} +4 -0
- package/dist/readiness.d.ts +12 -16
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/reads.d.ts +36 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +159 -83
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +35 -1
- package/dist/refresh.d.ts +10 -4
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +92 -30
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +11 -10
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +56 -23
- package/dist/room-draft.d.ts +22 -7
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +134 -54
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +18 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +45 -153
- 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 +7 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +46 -27
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1005 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -105
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -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 +44 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +38 -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/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +4 -5
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -7
- 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 +210 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +428 -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 +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -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 +105 -149
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +143 -390
- package/dist/stored.d.ts +67 -49
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +358 -253
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +224 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +532 -0
- package/dist/tables.d.ts +140 -60
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +268 -101
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- 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 +42 -100
- 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 +22 -10
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +9 -3
- package/package.json +12 -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.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- 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/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- 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,12 @@
|
|
|
1
|
+
import { documentFacts, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
|
|
1
3
|
import { sameChange } from './overlay.js';
|
|
4
|
+
const ATTACHMENTS = 'attachments';
|
|
5
|
+
function lastName(path) {
|
|
6
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
7
|
+
}
|
|
2
8
|
const FIXTURE_RETENTION = {
|
|
3
9
|
history: { kind: 'duration', seconds: 1 },
|
|
4
|
-
outcome: 604_800,
|
|
5
10
|
refreshHorizon: 1,
|
|
6
11
|
};
|
|
7
12
|
function declaredRetention(value) {
|
|
@@ -15,12 +20,7 @@ function declaredRetention(value) {
|
|
|
15
20
|
}
|
|
16
21
|
const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
|
|
17
22
|
function modelsOf(room) {
|
|
18
|
-
return {
|
|
19
|
-
collection: room.model ?? MODEL_ABSENT,
|
|
20
|
-
...(room.typedSelection === undefined
|
|
21
|
-
? {}
|
|
22
|
-
: { selection: room.selectionModel ?? MODEL_ABSENT }),
|
|
23
|
-
};
|
|
23
|
+
return { collection: room.model ?? MODEL_ABSENT };
|
|
24
24
|
}
|
|
25
25
|
function changedModels(room, from) {
|
|
26
26
|
const now = modelsOf(room);
|
|
@@ -53,13 +53,16 @@ export function createMemoryAdapter(options = {}) {
|
|
|
53
53
|
const listeners = new Set();
|
|
54
54
|
const modeObservers = new Set();
|
|
55
55
|
const scripted = new Map();
|
|
56
|
-
const unsealed = new Map();
|
|
57
|
-
const sealed = new Set();
|
|
58
56
|
const sentTurns = new Map();
|
|
59
57
|
const historyPageSize = options.historyPageSize;
|
|
60
|
-
|
|
58
|
+
const attached = new Map();
|
|
59
|
+
const linked = new WeakMap();
|
|
60
|
+
const carried = new Map();
|
|
61
61
|
let expiring = [];
|
|
62
|
+
let openings = 0;
|
|
63
|
+
const declaredRooms = new Set();
|
|
62
64
|
let replicated = [];
|
|
65
|
+
let heldCursor = null;
|
|
63
66
|
let issued = 0;
|
|
64
67
|
function scriptConversations(entries) {
|
|
65
68
|
scripted.clear();
|
|
@@ -87,8 +90,48 @@ export function createMemoryAdapter(options = {}) {
|
|
|
87
90
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
88
91
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
89
92
|
}
|
|
93
|
+
function heldBlob(room, path) {
|
|
94
|
+
return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
|
|
95
|
+
}
|
|
96
|
+
function freePath(room, name) {
|
|
97
|
+
const dot = name.lastIndexOf('.');
|
|
98
|
+
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
99
|
+
const extension = dot > 0 ? name.slice(dot) : '';
|
|
100
|
+
for (let count = 1;; count += 1) {
|
|
101
|
+
const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
|
|
102
|
+
if (heldBlob(room, path) === undefined && room.documents?.[path] === undefined)
|
|
103
|
+
return path;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const saved = new WeakMap();
|
|
107
|
+
function factsAt(room, path, content) {
|
|
108
|
+
const types = schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, NO_ROOM_TYPES);
|
|
109
|
+
let held = saved.get(types);
|
|
110
|
+
if (held === undefined) {
|
|
111
|
+
held = new Map();
|
|
112
|
+
saved.set(types, held);
|
|
113
|
+
}
|
|
114
|
+
const key = `${path}\u0000${content}`;
|
|
115
|
+
if (!held.has(key)) {
|
|
116
|
+
const facts = documentFacts(path, parse(content, path), { types });
|
|
117
|
+
held.set(key, facts === null ? null : JSON.parse(JSON.stringify(facts)));
|
|
118
|
+
}
|
|
119
|
+
return held.get(key);
|
|
120
|
+
}
|
|
121
|
+
function factsIn(room, paths) {
|
|
122
|
+
const facts = {};
|
|
123
|
+
for (const path of paths) {
|
|
124
|
+
const content = room.documents?.[path];
|
|
125
|
+
const held = room.facts?.[path] ?? (content === undefined ? null : factsAt(room, path, content));
|
|
126
|
+
if (held !== null)
|
|
127
|
+
facts[path] = held;
|
|
128
|
+
}
|
|
129
|
+
return facts;
|
|
130
|
+
}
|
|
90
131
|
function retain(entries) {
|
|
91
132
|
for (const room of entries) {
|
|
133
|
+
for (const [path, content] of Object.entries(room.documents ?? {}))
|
|
134
|
+
factsAt(room, path, content);
|
|
92
135
|
note(room.locator, room);
|
|
93
136
|
const versions = served.get(room.locator) ?? new Map();
|
|
94
137
|
versions.set(room.roomVersion, room);
|
|
@@ -106,6 +149,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
106
149
|
replica: room.replica,
|
|
107
150
|
...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
|
|
108
151
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
152
|
+
authoredPaths: room.authoredPaths,
|
|
109
153
|
};
|
|
110
154
|
}
|
|
111
155
|
function page(room, after) {
|
|
@@ -121,10 +165,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
121
165
|
roomVersion: room.roomVersion,
|
|
122
166
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
123
167
|
documents: named(room.documents ?? {}, taken),
|
|
168
|
+
facts: factsIn(room, taken),
|
|
124
169
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
125
170
|
...(room.fileIds === undefined
|
|
126
171
|
? {}
|
|
127
172
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
173
|
+
...(room.created === undefined
|
|
174
|
+
? {}
|
|
175
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
128
176
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
129
177
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
130
178
|
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
@@ -141,18 +189,19 @@ export function createMemoryAdapter(options = {}) {
|
|
|
141
189
|
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
142
190
|
};
|
|
143
191
|
}
|
|
144
|
-
function advancement(room, from, at) {
|
|
192
|
+
function advancement(room, from, at, whole = false) {
|
|
145
193
|
const current = room.documents ?? {};
|
|
146
194
|
const previous = from.documents ?? {};
|
|
147
195
|
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
148
196
|
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
149
197
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
150
198
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
199
|
+
room.created?.[path] !== from.created?.[path] ||
|
|
151
200
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
152
201
|
const changed = Object.keys(current)
|
|
153
202
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
154
203
|
.sort();
|
|
155
|
-
const size = pageSize ?? changed.length;
|
|
204
|
+
const size = whole ? changed.length : (pageSize ?? changed.length);
|
|
156
205
|
const taken = changed.slice(at, at + size);
|
|
157
206
|
const next = at + taken.length;
|
|
158
207
|
const opening = at === 0;
|
|
@@ -168,10 +217,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
168
217
|
roomVersion: room.roomVersion,
|
|
169
218
|
...(models === undefined ? {} : { models }),
|
|
170
219
|
documents: named(current, taken),
|
|
220
|
+
facts: factsIn(room, taken),
|
|
171
221
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
172
222
|
...(room.fileIds === undefined
|
|
173
223
|
? {}
|
|
174
224
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
225
|
+
...(room.created === undefined
|
|
226
|
+
? {}
|
|
227
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
175
228
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
176
229
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
177
230
|
...(opening ? foldersMoved(room, from) : {}),
|
|
@@ -184,6 +237,26 @@ export function createMemoryAdapter(options = {}) {
|
|
|
184
237
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
185
238
|
};
|
|
186
239
|
}
|
|
240
|
+
function carry(locator) {
|
|
241
|
+
const at = carried.get(locator);
|
|
242
|
+
const current = rooms.find((entry) => entry.locator === locator);
|
|
243
|
+
if (at === undefined || current === undefined || current.roomVersion === at)
|
|
244
|
+
return;
|
|
245
|
+
const from = served.get(locator)?.get(at);
|
|
246
|
+
carried.set(locator, current.roomVersion);
|
|
247
|
+
if (from === undefined)
|
|
248
|
+
return;
|
|
249
|
+
const page = advancement(current, from, 0, true);
|
|
250
|
+
for (const observer of observers) {
|
|
251
|
+
observer({
|
|
252
|
+
kind: 'room-change',
|
|
253
|
+
locator,
|
|
254
|
+
from: at,
|
|
255
|
+
roomVersion: current.roomVersion,
|
|
256
|
+
read: async () => page,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
}
|
|
187
260
|
function pageOf(conversation, after) {
|
|
188
261
|
const messages = conversation.messages ?? [];
|
|
189
262
|
const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
|
|
@@ -198,16 +271,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
198
271
|
: {}),
|
|
199
272
|
};
|
|
200
273
|
}
|
|
201
|
-
function historiesOf(
|
|
202
|
-
const asked = input?.conversations;
|
|
203
|
-
if (!Array.isArray(asked))
|
|
204
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
274
|
+
function historiesOf(request) {
|
|
205
275
|
const histories = [];
|
|
206
|
-
for (const entry of
|
|
207
|
-
const conversation =
|
|
276
|
+
for (const entry of request.conversations) {
|
|
277
|
+
const conversation = scripted.get(entry.conversation);
|
|
208
278
|
if (conversation === undefined)
|
|
209
279
|
continue;
|
|
210
|
-
const outcome = conversation.outcomes?.
|
|
280
|
+
const outcome = conversation.outcomes?.history;
|
|
211
281
|
if (outcome !== undefined)
|
|
212
282
|
return outcome;
|
|
213
283
|
histories.push(pageOf(conversation, entry.after));
|
|
@@ -218,15 +288,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
218
288
|
function conversationAction(request) {
|
|
219
289
|
const name = request.name;
|
|
220
290
|
const input = (request.input ?? {});
|
|
221
|
-
if (name === '
|
|
222
|
-
return historiesOf(request.input);
|
|
223
|
-
if (name === 'conversation.create') {
|
|
291
|
+
if (name === 'conversations/create') {
|
|
224
292
|
issued += 1;
|
|
225
293
|
const conversation = `conversation-${issued}`;
|
|
226
294
|
scripted.set(conversation, { conversation });
|
|
227
|
-
return { kind: 'action', result: { conversation } };
|
|
295
|
+
return { kind: 'action', result: { conversation_id: conversation } };
|
|
228
296
|
}
|
|
229
|
-
const named = typeof input.
|
|
297
|
+
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
230
298
|
const conversation = scripted.get(named);
|
|
231
299
|
if (conversation === undefined) {
|
|
232
300
|
return {
|
|
@@ -239,34 +307,28 @@ export function createMemoryAdapter(options = {}) {
|
|
|
239
307
|
const outcome = conversation.outcomes?.[name];
|
|
240
308
|
if (outcome !== undefined)
|
|
241
309
|
return outcome;
|
|
242
|
-
if (name === '
|
|
310
|
+
if (name === 'conversations/send') {
|
|
243
311
|
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
244
312
|
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
245
313
|
if (answered !== undefined)
|
|
246
|
-
return { kind: 'action', result: {
|
|
314
|
+
return { kind: 'action', result: { message_id: answered } };
|
|
247
315
|
issued += 1;
|
|
248
316
|
const turn = `turn-${issued}`;
|
|
249
|
-
unsealed.set(turn, named);
|
|
250
317
|
if (operation !== null)
|
|
251
318
|
sentTurns.set(operation, turn);
|
|
252
|
-
return { kind: 'action', result: { turn } };
|
|
253
|
-
}
|
|
254
|
-
if (name === 'conversation.cancel') {
|
|
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 } };
|
|
319
|
+
return { kind: 'action', result: { message_id: turn } };
|
|
261
320
|
}
|
|
262
|
-
if (name === '
|
|
321
|
+
if (name === 'conversations/delete')
|
|
263
322
|
scripted.delete(named);
|
|
264
|
-
return { kind: 'action', result: {
|
|
323
|
+
return { kind: 'action', result: { conversation_id: named } };
|
|
265
324
|
}
|
|
266
325
|
function announceList() {
|
|
267
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
268
|
-
|
|
269
|
-
|
|
326
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
327
|
+
? []
|
|
328
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
|
|
329
|
+
for (const listener of listeners) {
|
|
330
|
+
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
331
|
+
}
|
|
270
332
|
}
|
|
271
333
|
function discovery() {
|
|
272
334
|
return {
|
|
@@ -278,8 +340,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
278
340
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
279
341
|
};
|
|
280
342
|
}
|
|
343
|
+
function discovered() {
|
|
344
|
+
return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
|
|
345
|
+
if (answer.kind === 'discovery')
|
|
346
|
+
for (const room of answer.rooms)
|
|
347
|
+
note(room.locator, room);
|
|
348
|
+
return answer;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function opened(notify) {
|
|
352
|
+
const opening = ++openings;
|
|
353
|
+
notify({ kind: 'opened' });
|
|
354
|
+
void discovered()
|
|
355
|
+
.catch(() => ({ kind: 'transport-uncertainty' }))
|
|
356
|
+
.then((answer) => {
|
|
357
|
+
if (opening !== openings)
|
|
358
|
+
return;
|
|
359
|
+
if (answer.kind !== 'discovery') {
|
|
360
|
+
openings += 1;
|
|
361
|
+
carried.clear();
|
|
362
|
+
const revoked = answer.kind === 'revoked-authorization';
|
|
363
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
declaredRooms.clear();
|
|
367
|
+
for (const room of answer.rooms)
|
|
368
|
+
declaredRooms.add(room.locator);
|
|
369
|
+
notify({ kind: 'discovered', discovery: answer });
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function emitAll(event) {
|
|
373
|
+
for (const observer of observers)
|
|
374
|
+
observer(event);
|
|
375
|
+
}
|
|
281
376
|
return {
|
|
282
|
-
...(options.
|
|
377
|
+
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
378
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
283
379
|
setRooms(next) {
|
|
284
380
|
rooms = [...next];
|
|
285
381
|
retain(rooms);
|
|
@@ -288,33 +384,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
288
384
|
scriptConversations(next);
|
|
289
385
|
},
|
|
290
386
|
open() {
|
|
387
|
+
carried.clear();
|
|
291
388
|
announceList();
|
|
292
|
-
|
|
293
|
-
observer({ kind: 'opened' });
|
|
389
|
+
opened(emitAll);
|
|
294
390
|
},
|
|
295
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
296
|
-
|
|
297
|
-
|
|
391
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
392
|
+
openings += 1;
|
|
393
|
+
carried.clear();
|
|
394
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
298
395
|
},
|
|
299
396
|
expire(locators) {
|
|
300
397
|
expiring = [...locators];
|
|
301
398
|
},
|
|
302
|
-
notifyRoomVersion({ locator
|
|
303
|
-
|
|
304
|
-
observer({ kind: 'room-version', locator, roomVersion });
|
|
399
|
+
notifyRoomVersion({ locator }) {
|
|
400
|
+
carry(locator);
|
|
305
401
|
},
|
|
306
|
-
notifyAuthorityChanged(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
402
|
+
notifyAuthorityChanged(locators) {
|
|
403
|
+
const named = new Set(locators ?? [...declaredRooms, ...rooms.map((room) => room.locator)]);
|
|
404
|
+
const listed = rooms.filter((room) => named.has(room.locator));
|
|
405
|
+
const left = [...named].filter((locator) => !listed.some((room) => room.locator === locator));
|
|
406
|
+
for (const room of listed)
|
|
407
|
+
declaredRooms.add(room.locator);
|
|
408
|
+
for (const locator of left)
|
|
409
|
+
declaredRooms.delete(locator);
|
|
410
|
+
emitAll({
|
|
411
|
+
kind: 'authority-changed',
|
|
412
|
+
rooms: listed.map(declared),
|
|
413
|
+
left,
|
|
414
|
+
...(options.member === undefined ? {} : { member: options.member }),
|
|
415
|
+
});
|
|
312
416
|
},
|
|
313
417
|
notifyConversation(event) {
|
|
314
|
-
if (event.kind === 'accepted-message') {
|
|
315
|
-
sealed.add(event.message.turn);
|
|
316
|
-
unsealed.delete(event.message.turn);
|
|
317
|
-
}
|
|
318
418
|
for (const listener of listeners)
|
|
319
419
|
listener(event);
|
|
320
420
|
},
|
|
@@ -323,21 +423,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
323
423
|
observer(mode);
|
|
324
424
|
},
|
|
325
425
|
heldRooms() {
|
|
326
|
-
return
|
|
426
|
+
return [...carried.keys()].sort();
|
|
327
427
|
},
|
|
328
428
|
replicatedConversations() {
|
|
329
429
|
return replicated;
|
|
330
430
|
},
|
|
431
|
+
heldConversationCursor() {
|
|
432
|
+
return heldCursor;
|
|
433
|
+
},
|
|
331
434
|
conversations: {
|
|
332
435
|
replicate(next) {
|
|
333
436
|
replicated = [...next];
|
|
334
437
|
},
|
|
438
|
+
hold(cursor) {
|
|
439
|
+
heldCursor = cursor;
|
|
440
|
+
},
|
|
335
441
|
observe(notify) {
|
|
336
442
|
listeners.add(notify);
|
|
337
443
|
return () => {
|
|
338
444
|
listeners.delete(notify);
|
|
339
445
|
};
|
|
340
446
|
},
|
|
447
|
+
history: (request) => Promise.resolve(historiesOf(request)),
|
|
448
|
+
...(options.agents === undefined
|
|
449
|
+
? {}
|
|
450
|
+
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
341
451
|
},
|
|
342
452
|
serviceMode: {
|
|
343
453
|
observe(notify) {
|
|
@@ -349,44 +459,46 @@ export function createMemoryAdapter(options = {}) {
|
|
|
349
459
|
},
|
|
350
460
|
roomStream: {
|
|
351
461
|
hold(asked) {
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
expiring = [];
|
|
355
|
-
const moved = asked.flatMap((room) => {
|
|
462
|
+
const named = asked.map((room) => room.locator);
|
|
463
|
+
const unknown = asked.flatMap((room) => {
|
|
356
464
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
465
|
+
const version = room.roomVersion;
|
|
357
466
|
return current === undefined ||
|
|
358
|
-
|
|
359
|
-
|
|
467
|
+
(version !== null &&
|
|
468
|
+
(current.roomVersion === version || served.get(room.locator)?.has(version) === true))
|
|
360
469
|
? []
|
|
361
|
-
: [
|
|
470
|
+
: [room.locator];
|
|
362
471
|
});
|
|
472
|
+
const expired = [
|
|
473
|
+
...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
|
|
474
|
+
];
|
|
475
|
+
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
363
476
|
queueMicrotask(() => {
|
|
364
|
-
for (const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
477
|
+
for (const room of asked) {
|
|
478
|
+
if (expired.includes(room.locator) || room.roomVersion === null)
|
|
479
|
+
carried.delete(room.locator);
|
|
480
|
+
else {
|
|
481
|
+
carried.set(room.locator, room.roomVersion);
|
|
482
|
+
carry(room.locator);
|
|
483
|
+
}
|
|
368
484
|
}
|
|
485
|
+
emitAll({ kind: 'caught-up', expired });
|
|
369
486
|
});
|
|
370
487
|
},
|
|
371
|
-
reopen() {
|
|
372
|
-
queueMicrotask(() => {
|
|
373
|
-
for (const observer of observers) {
|
|
374
|
-
observer({ kind: 'closed', revoked: false, lost: false });
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
},
|
|
378
|
-
published() { },
|
|
379
488
|
observe(notify) {
|
|
380
489
|
observers.add(notify);
|
|
381
490
|
queueMicrotask(() => {
|
|
382
491
|
if (!observers.has(notify))
|
|
383
492
|
return;
|
|
384
493
|
if (options.unopened === true) {
|
|
385
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
494
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
386
495
|
return;
|
|
387
496
|
}
|
|
388
497
|
announceList();
|
|
389
|
-
|
|
498
|
+
opened((event) => {
|
|
499
|
+
if (observers.has(notify))
|
|
500
|
+
notify(event);
|
|
501
|
+
});
|
|
390
502
|
});
|
|
391
503
|
return () => {
|
|
392
504
|
observers.delete(notify);
|
|
@@ -403,12 +515,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
403
515
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
404
516
|
},
|
|
405
517
|
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
|
-
});
|
|
518
|
+
return discovered();
|
|
412
519
|
},
|
|
413
520
|
reached,
|
|
414
521
|
follows(locator, roomVersion, next) {
|
|
@@ -487,32 +594,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
487
594
|
},
|
|
488
595
|
async binary(_authorization, request) {
|
|
489
596
|
return resolveScript(scripts.binary, () => {
|
|
490
|
-
if (request.kind === 'reference') {
|
|
491
|
-
return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
|
|
492
|
-
}
|
|
493
597
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
494
598
|
if (room === undefined)
|
|
495
599
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
496
|
-
const blob = room
|
|
600
|
+
const blob = heldBlob(room, request.path);
|
|
497
601
|
return blob === undefined
|
|
498
|
-
? { kind: 'rejected', code: '
|
|
602
|
+
? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
|
|
499
603
|
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
500
604
|
}, request);
|
|
501
605
|
},
|
|
502
606
|
async link(_authorization, request) {
|
|
503
|
-
return resolveScript(scripts.link, () =>
|
|
607
|
+
return resolveScript(scripts.link, () => {
|
|
608
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
609
|
+
if (room === undefined)
|
|
610
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
611
|
+
const blob = heldBlob(room, request.path);
|
|
612
|
+
if (blob === undefined) {
|
|
613
|
+
return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
|
|
614
|
+
}
|
|
615
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
616
|
+
linked.set(blob, url);
|
|
617
|
+
return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
|
|
618
|
+
}, request);
|
|
504
619
|
},
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
620
|
+
async attach(_authorization, request) {
|
|
621
|
+
return resolveScript(scripts.attach, () => {
|
|
622
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
623
|
+
if (room === undefined)
|
|
624
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
625
|
+
const path = freePath(room, request.name);
|
|
626
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
627
|
+
return { kind: 'attached', path, revision: `attached-${attached.size}` };
|
|
628
|
+
}, request);
|
|
512
629
|
},
|
|
513
630
|
async action(_authorization, request) {
|
|
514
631
|
return resolveScript(scripts.action, () => {
|
|
515
|
-
if (request.name.startsWith('
|
|
632
|
+
if (request.name.startsWith('conversations/'))
|
|
516
633
|
return conversationAction(request);
|
|
517
634
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
518
635
|
}, request).then((answer) => {
|
package/dist/messages.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AcceptedMessage } from './adapter.js';
|
|
2
2
|
import type { Connection } from './tables.js';
|
|
3
3
|
export declare const MESSAGE_TABLES: readonly string[];
|
|
4
|
+
export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n asking.text AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
|
|
4
5
|
export type HeldConversation = {
|
|
5
6
|
readonly conversation: string;
|
|
6
7
|
readonly read: string | null | undefined;
|
|
@@ -10,6 +11,25 @@ export type MessageWindow = {
|
|
|
10
11
|
readonly messages: AcceptedMessage[];
|
|
11
12
|
readonly more: boolean;
|
|
12
13
|
};
|
|
14
|
+
export type HeldSource = {
|
|
15
|
+
readonly source: unknown;
|
|
16
|
+
readonly sender: string | null;
|
|
17
|
+
};
|
|
18
|
+
export type HeldRow = {
|
|
19
|
+
readonly conversation: string;
|
|
20
|
+
readonly said: {
|
|
21
|
+
readonly text: string;
|
|
22
|
+
readonly role: string | null;
|
|
23
|
+
readonly at: string | null;
|
|
24
|
+
} | null;
|
|
25
|
+
readonly failure: string | null;
|
|
26
|
+
readonly opened: HeldSource | null;
|
|
27
|
+
readonly asking: (HeldSource & {
|
|
28
|
+
readonly identity: string;
|
|
29
|
+
readonly text: string;
|
|
30
|
+
readonly at: string | null;
|
|
31
|
+
}) | null;
|
|
32
|
+
};
|
|
13
33
|
export type ConversationWrite = {
|
|
14
34
|
readonly conversation: string;
|
|
15
35
|
readonly messages: readonly AcceptedMessage[];
|
|
@@ -18,10 +38,11 @@ export type ConversationWrite = {
|
|
|
18
38
|
readonly partial: boolean;
|
|
19
39
|
};
|
|
20
40
|
};
|
|
21
|
-
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
41
|
+
export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
|
|
22
42
|
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;
|
|
43
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
44
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
45
|
+
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
25
46
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
47
|
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
48
|
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":"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"}
|