@agentshouse/mdruntime 0.1.0-c94cfdbdb6f68 → 0.1.0-c95f0f04f2113
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 -16
- 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 +248 -0
- package/dist/adapter.d.ts +139 -85
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +7 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +40 -41
- 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 +30 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +319 -111
- 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 +12 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -89
- package/dist/change.d.ts +32 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat-types.d.ts +3 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +2 -0
- package/dist/client.d.ts +28 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +83 -7
- package/dist/collection.d.ts +11 -21
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +39 -321
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +717 -0
- package/dist/connection.d.ts +7 -137
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +98 -3600
- 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-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +47 -0
- package/dist/conversation.d.ts +36 -18
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +570 -287
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- 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 +7 -4
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +5 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +33 -29
- package/dist/figures.d.ts +48 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/host.d.ts +4 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +67 -39
- package/dist/identity.d.ts +0 -2
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -6
- package/dist/index.d.ts +30 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +560 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +267 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +175 -0
- package/dist/live.d.ts +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +165 -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/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +218 -0
- package/dist/memory.d.ts +14 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +237 -105
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +168 -0
- 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 +193 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +15 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +91 -2
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +56 -0
- package/dist/outcome.d.ts +41 -8
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +41 -2
- package/dist/overlay.d.ts +3 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +98 -172
- package/dist/{chat/parts.d.ts → parts.d.ts} +11 -9
- package/dist/parts.d.ts.map +1 -0
- package/dist/{chat/parts.js → parts.js} +45 -46
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -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 +21 -206
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -493
- package/dist/{chat/questions.d.ts → questions.d.ts} +3 -2
- package/dist/questions.d.ts.map +1 -0
- package/dist/{chat/questions.js → questions.js} +8 -1
- package/dist/reach.d.ts +20 -9
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +278 -103
- package/dist/react.d.ts +6 -2
- package/dist/react.d.ts.map +1 -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 +14 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +2 -8
- package/dist/reads.d.ts +35 -10
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +122 -84
- package/dist/recovery.d.ts +3 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +43 -8
- package/dist/refresh.d.ts +18 -15
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +143 -58
- 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 +54 -36
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +313 -188
- package/dist/room-draft.d.ts +25 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +158 -71
- 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/rows.d.ts +31 -31
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +59 -123
- package/dist/runtime.d.ts +42 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +52 -14
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +518 -185
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1004 -0
- package/dist/search.d.ts +12 -95
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -266
- 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 +7 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +119 -66
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +294 -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/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +81 -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 +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +408 -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 +106 -164
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +136 -752
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +637 -0
- package/dist/surface.d.ts +86 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +217 -0
- package/dist/sync.d.ts +20 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +531 -0
- package/dist/tables.d.ts +407 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +724 -0
- 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/turn.d.ts +4 -2
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +46 -22
- package/dist/validation.d.ts +29 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +104 -0
- package/dist/windows.d.ts +1 -16
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -79
- package/dist/wire.d.ts +33 -6
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +11 -2
- package/package.json +18 -19
- package/AGENTS.md +0 -299
- 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/input.d.ts +0 -9
- package/dist/chat/input.d.ts.map +0 -1
- package/dist/chat/input.js +0 -99
- 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 -27
- package/dist/chat/list.d.ts.map +0 -1
- package/dist/chat/list.js +0 -99
- package/dist/chat/markdown.d.ts +0 -20
- package/dist/chat/markdown.d.ts.map +0 -1
- package/dist/chat/markdown.js +0 -188
- package/dist/chat/message.d.ts +0 -6
- package/dist/chat/message.d.ts.map +0 -1
- package/dist/chat/message.js +0 -192
- package/dist/chat/messages.d.ts +0 -22
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -155
- package/dist/chat/name.d.ts +0 -6
- package/dist/chat/name.d.ts.map +0 -1
- package/dist/chat/name.js +0 -37
- package/dist/chat/opened.d.ts +0 -11
- package/dist/chat/opened.d.ts.map +0 -1
- package/dist/chat/opened.js +0 -17
- package/dist/chat/overlay.d.ts +0 -31
- package/dist/chat/overlay.d.ts.map +0 -1
- package/dist/chat/overlay.js +0 -97
- package/dist/chat/parts.d.ts.map +0 -1
- 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 -63
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -628
- 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 -34
- package/dist/chat/ready.d.ts.map +0 -1
- package/dist/chat/ready.js +0 -91
- package/dist/chat/style.d.ts +0 -4
- package/dist/chat/style.d.ts.map +0 -1
- package/dist/chat/style.js +0 -302
- package/dist/chat.d.ts +0 -14
- 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/read-side.d.ts +0 -27
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -824
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);
|
|
@@ -121,27 +164,43 @@ export function createMemoryAdapter(options = {}) {
|
|
|
121
164
|
roomVersion: room.roomVersion,
|
|
122
165
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
123
166
|
documents: named(room.documents ?? {}, taken),
|
|
167
|
+
facts: factsIn(room, taken),
|
|
124
168
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
125
169
|
...(room.fileIds === undefined
|
|
126
170
|
? {}
|
|
127
171
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
172
|
+
...(room.created === undefined
|
|
173
|
+
? {}
|
|
174
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
128
175
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
129
176
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
177
|
+
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
130
178
|
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
131
179
|
};
|
|
132
180
|
}
|
|
133
|
-
function
|
|
181
|
+
function foldersMoved(room, from) {
|
|
182
|
+
const now = new Set(room.folders ?? []);
|
|
183
|
+
const before = new Set(from.folders ?? []);
|
|
184
|
+
const folders = [...now].filter((folder) => !before.has(folder)).sort();
|
|
185
|
+
const folderRemovals = [...before].filter((folder) => !now.has(folder)).sort();
|
|
186
|
+
return {
|
|
187
|
+
...(folders.length === 0 ? {} : { folders }),
|
|
188
|
+
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function advancement(room, from, at, whole = false) {
|
|
134
192
|
const current = room.documents ?? {};
|
|
135
193
|
const previous = from.documents ?? {};
|
|
136
194
|
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
137
195
|
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
138
196
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
139
197
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
198
|
+
room.created?.[path] !== from.created?.[path] ||
|
|
140
199
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
141
200
|
const changed = Object.keys(current)
|
|
142
201
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
143
202
|
.sort();
|
|
144
|
-
const size = pageSize ?? changed.length;
|
|
203
|
+
const size = whole ? changed.length : (pageSize ?? changed.length);
|
|
145
204
|
const taken = changed.slice(at, at + size);
|
|
146
205
|
const next = at + taken.length;
|
|
147
206
|
const opening = at === 0;
|
|
@@ -157,12 +216,17 @@ export function createMemoryAdapter(options = {}) {
|
|
|
157
216
|
roomVersion: room.roomVersion,
|
|
158
217
|
...(models === undefined ? {} : { models }),
|
|
159
218
|
documents: named(current, taken),
|
|
219
|
+
facts: factsIn(room, taken),
|
|
160
220
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
161
221
|
...(room.fileIds === undefined
|
|
162
222
|
? {}
|
|
163
223
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
224
|
+
...(room.created === undefined
|
|
225
|
+
? {}
|
|
226
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
164
227
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
165
228
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
229
|
+
...(opening ? foldersMoved(room, from) : {}),
|
|
166
230
|
removals: opening
|
|
167
231
|
? [
|
|
168
232
|
...Object.keys(previous).filter((path) => !(path in current) && !currentTargets.has(path)),
|
|
@@ -172,6 +236,26 @@ export function createMemoryAdapter(options = {}) {
|
|
|
172
236
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
173
237
|
};
|
|
174
238
|
}
|
|
239
|
+
function carry(locator) {
|
|
240
|
+
const at = carried.get(locator);
|
|
241
|
+
const current = rooms.find((entry) => entry.locator === locator);
|
|
242
|
+
if (at === undefined || current === undefined || current.roomVersion === at)
|
|
243
|
+
return;
|
|
244
|
+
const from = served.get(locator)?.get(at);
|
|
245
|
+
carried.set(locator, current.roomVersion);
|
|
246
|
+
if (from === undefined)
|
|
247
|
+
return;
|
|
248
|
+
const page = advancement(current, from, 0, true);
|
|
249
|
+
for (const observer of observers) {
|
|
250
|
+
observer({
|
|
251
|
+
kind: 'room-change',
|
|
252
|
+
locator,
|
|
253
|
+
from: at,
|
|
254
|
+
roomVersion: current.roomVersion,
|
|
255
|
+
read: async () => page,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
175
259
|
function pageOf(conversation, after) {
|
|
176
260
|
const messages = conversation.messages ?? [];
|
|
177
261
|
const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
|
|
@@ -186,16 +270,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
186
270
|
: {}),
|
|
187
271
|
};
|
|
188
272
|
}
|
|
189
|
-
function historiesOf(
|
|
190
|
-
const asked = input?.conversations;
|
|
191
|
-
if (!Array.isArray(asked))
|
|
192
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
273
|
+
function historiesOf(request) {
|
|
193
274
|
const histories = [];
|
|
194
|
-
for (const entry of
|
|
195
|
-
const conversation =
|
|
275
|
+
for (const entry of request.conversations) {
|
|
276
|
+
const conversation = scripted.get(entry.conversation);
|
|
196
277
|
if (conversation === undefined)
|
|
197
278
|
continue;
|
|
198
|
-
const outcome = conversation.outcomes?.
|
|
279
|
+
const outcome = conversation.outcomes?.history;
|
|
199
280
|
if (outcome !== undefined)
|
|
200
281
|
return outcome;
|
|
201
282
|
histories.push(pageOf(conversation, entry.after));
|
|
@@ -206,15 +287,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
206
287
|
function conversationAction(request) {
|
|
207
288
|
const name = request.name;
|
|
208
289
|
const input = (request.input ?? {});
|
|
209
|
-
if (name === '
|
|
210
|
-
return historiesOf(request.input);
|
|
211
|
-
if (name === 'conversation.create') {
|
|
290
|
+
if (name === 'conversations/create') {
|
|
212
291
|
issued += 1;
|
|
213
292
|
const conversation = `conversation-${issued}`;
|
|
214
293
|
scripted.set(conversation, { conversation });
|
|
215
|
-
return { kind: 'action', result: { conversation } };
|
|
294
|
+
return { kind: 'action', result: { conversation_id: conversation } };
|
|
216
295
|
}
|
|
217
|
-
const named = typeof input.
|
|
296
|
+
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
218
297
|
const conversation = scripted.get(named);
|
|
219
298
|
if (conversation === undefined) {
|
|
220
299
|
return {
|
|
@@ -227,34 +306,28 @@ export function createMemoryAdapter(options = {}) {
|
|
|
227
306
|
const outcome = conversation.outcomes?.[name];
|
|
228
307
|
if (outcome !== undefined)
|
|
229
308
|
return outcome;
|
|
230
|
-
if (name === '
|
|
309
|
+
if (name === 'conversations/send') {
|
|
231
310
|
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
232
311
|
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
233
312
|
if (answered !== undefined)
|
|
234
|
-
return { kind: 'action', result: {
|
|
313
|
+
return { kind: 'action', result: { message_id: answered } };
|
|
235
314
|
issued += 1;
|
|
236
315
|
const turn = `turn-${issued}`;
|
|
237
|
-
unsealed.set(turn, named);
|
|
238
316
|
if (operation !== null)
|
|
239
317
|
sentTurns.set(operation, turn);
|
|
240
|
-
return { kind: 'action', result: { turn } };
|
|
318
|
+
return { kind: 'action', result: { message_id: turn } };
|
|
241
319
|
}
|
|
242
|
-
if (name === '
|
|
243
|
-
const turn = typeof input.turn === 'string' ? input.turn : '';
|
|
244
|
-
if (sealed.has(turn) || !unsealed.has(turn)) {
|
|
245
|
-
return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
|
|
246
|
-
}
|
|
247
|
-
unsealed.delete(turn);
|
|
248
|
-
return { kind: 'action', result: { turn, cancelled: true } };
|
|
249
|
-
}
|
|
250
|
-
if (name === 'conversation.delete')
|
|
320
|
+
if (name === 'conversations/delete')
|
|
251
321
|
scripted.delete(named);
|
|
252
|
-
return { kind: 'action', result: {
|
|
322
|
+
return { kind: 'action', result: { conversation_id: named } };
|
|
253
323
|
}
|
|
254
324
|
function announceList() {
|
|
255
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
256
|
-
|
|
257
|
-
|
|
325
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
326
|
+
? []
|
|
327
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
|
|
328
|
+
for (const listener of listeners) {
|
|
329
|
+
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
330
|
+
}
|
|
258
331
|
}
|
|
259
332
|
function discovery() {
|
|
260
333
|
return {
|
|
@@ -266,8 +339,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
266
339
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
267
340
|
};
|
|
268
341
|
}
|
|
342
|
+
function discovered() {
|
|
343
|
+
return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
|
|
344
|
+
if (answer.kind === 'discovery')
|
|
345
|
+
for (const room of answer.rooms)
|
|
346
|
+
note(room.locator, room);
|
|
347
|
+
return answer;
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
function opened(notify) {
|
|
351
|
+
const opening = ++openings;
|
|
352
|
+
notify({ kind: 'opened' });
|
|
353
|
+
void discovered()
|
|
354
|
+
.catch(() => ({ kind: 'transport-uncertainty' }))
|
|
355
|
+
.then((answer) => {
|
|
356
|
+
if (opening !== openings)
|
|
357
|
+
return;
|
|
358
|
+
if (answer.kind !== 'discovery') {
|
|
359
|
+
openings += 1;
|
|
360
|
+
carried.clear();
|
|
361
|
+
const revoked = answer.kind === 'revoked-authorization';
|
|
362
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
declaredRooms.clear();
|
|
366
|
+
for (const room of answer.rooms)
|
|
367
|
+
declaredRooms.add(room.locator);
|
|
368
|
+
notify({ kind: 'discovered', discovery: answer });
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function emitAll(event) {
|
|
372
|
+
for (const observer of observers)
|
|
373
|
+
observer(event);
|
|
374
|
+
}
|
|
269
375
|
return {
|
|
270
|
-
...(options.
|
|
376
|
+
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
377
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
271
378
|
setRooms(next) {
|
|
272
379
|
rooms = [...next];
|
|
273
380
|
retain(rooms);
|
|
@@ -276,33 +383,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
276
383
|
scriptConversations(next);
|
|
277
384
|
},
|
|
278
385
|
open() {
|
|
386
|
+
carried.clear();
|
|
279
387
|
announceList();
|
|
280
|
-
|
|
281
|
-
observer({ kind: 'opened' });
|
|
388
|
+
opened(emitAll);
|
|
282
389
|
},
|
|
283
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
284
|
-
|
|
285
|
-
|
|
390
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
391
|
+
openings += 1;
|
|
392
|
+
carried.clear();
|
|
393
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
286
394
|
},
|
|
287
395
|
expire(locators) {
|
|
288
396
|
expiring = [...locators];
|
|
289
397
|
},
|
|
290
|
-
notifyRoomVersion({ locator
|
|
291
|
-
|
|
292
|
-
observer({ kind: 'room-version', locator, roomVersion });
|
|
398
|
+
notifyRoomVersion({ locator }) {
|
|
399
|
+
carry(locator);
|
|
293
400
|
},
|
|
294
|
-
notifyAuthorityChanged(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
401
|
+
notifyAuthorityChanged(locators) {
|
|
402
|
+
const named = new Set(locators ?? [...declaredRooms, ...rooms.map((room) => room.locator)]);
|
|
403
|
+
const listed = rooms.filter((room) => named.has(room.locator));
|
|
404
|
+
const left = [...named].filter((locator) => !listed.some((room) => room.locator === locator));
|
|
405
|
+
for (const room of listed)
|
|
406
|
+
declaredRooms.add(room.locator);
|
|
407
|
+
for (const locator of left)
|
|
408
|
+
declaredRooms.delete(locator);
|
|
409
|
+
emitAll({
|
|
410
|
+
kind: 'authority-changed',
|
|
411
|
+
rooms: listed.map(declared),
|
|
412
|
+
left,
|
|
413
|
+
...(options.member === undefined ? {} : { member: options.member }),
|
|
414
|
+
});
|
|
300
415
|
},
|
|
301
416
|
notifyConversation(event) {
|
|
302
|
-
if (event.kind === 'accepted-message') {
|
|
303
|
-
sealed.add(event.message.turn);
|
|
304
|
-
unsealed.delete(event.message.turn);
|
|
305
|
-
}
|
|
306
417
|
for (const listener of listeners)
|
|
307
418
|
listener(event);
|
|
308
419
|
},
|
|
@@ -311,21 +422,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
311
422
|
observer(mode);
|
|
312
423
|
},
|
|
313
424
|
heldRooms() {
|
|
314
|
-
return
|
|
425
|
+
return [...carried.keys()].sort();
|
|
315
426
|
},
|
|
316
427
|
replicatedConversations() {
|
|
317
428
|
return replicated;
|
|
318
429
|
},
|
|
430
|
+
heldConversationCursor() {
|
|
431
|
+
return heldCursor;
|
|
432
|
+
},
|
|
319
433
|
conversations: {
|
|
320
434
|
replicate(next) {
|
|
321
435
|
replicated = [...next];
|
|
322
436
|
},
|
|
437
|
+
hold(cursor) {
|
|
438
|
+
heldCursor = cursor;
|
|
439
|
+
},
|
|
323
440
|
observe(notify) {
|
|
324
441
|
listeners.add(notify);
|
|
325
442
|
return () => {
|
|
326
443
|
listeners.delete(notify);
|
|
327
444
|
};
|
|
328
445
|
},
|
|
446
|
+
history: (request) => Promise.resolve(historiesOf(request)),
|
|
447
|
+
...(options.agents === undefined
|
|
448
|
+
? {}
|
|
449
|
+
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
329
450
|
},
|
|
330
451
|
serviceMode: {
|
|
331
452
|
observe(notify) {
|
|
@@ -337,44 +458,46 @@ export function createMemoryAdapter(options = {}) {
|
|
|
337
458
|
},
|
|
338
459
|
roomStream: {
|
|
339
460
|
hold(asked) {
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
expiring = [];
|
|
343
|
-
const moved = asked.flatMap((room) => {
|
|
461
|
+
const named = asked.map((room) => room.locator);
|
|
462
|
+
const unknown = asked.flatMap((room) => {
|
|
344
463
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
464
|
+
const version = room.roomVersion;
|
|
345
465
|
return current === undefined ||
|
|
346
|
-
|
|
347
|
-
|
|
466
|
+
(version !== null &&
|
|
467
|
+
(current.roomVersion === version || served.get(room.locator)?.has(version) === true))
|
|
348
468
|
? []
|
|
349
|
-
: [
|
|
469
|
+
: [room.locator];
|
|
350
470
|
});
|
|
471
|
+
const expired = [
|
|
472
|
+
...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
|
|
473
|
+
];
|
|
474
|
+
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
351
475
|
queueMicrotask(() => {
|
|
352
|
-
for (const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
476
|
+
for (const room of asked) {
|
|
477
|
+
if (expired.includes(room.locator) || room.roomVersion === null)
|
|
478
|
+
carried.delete(room.locator);
|
|
479
|
+
else {
|
|
480
|
+
carried.set(room.locator, room.roomVersion);
|
|
481
|
+
carry(room.locator);
|
|
482
|
+
}
|
|
356
483
|
}
|
|
484
|
+
emitAll({ kind: 'caught-up', expired });
|
|
357
485
|
});
|
|
358
486
|
},
|
|
359
|
-
reopen() {
|
|
360
|
-
queueMicrotask(() => {
|
|
361
|
-
for (const observer of observers) {
|
|
362
|
-
observer({ kind: 'closed', revoked: false, lost: false });
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
},
|
|
366
|
-
published() { },
|
|
367
487
|
observe(notify) {
|
|
368
488
|
observers.add(notify);
|
|
369
489
|
queueMicrotask(() => {
|
|
370
490
|
if (!observers.has(notify))
|
|
371
491
|
return;
|
|
372
492
|
if (options.unopened === true) {
|
|
373
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
493
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
374
494
|
return;
|
|
375
495
|
}
|
|
376
496
|
announceList();
|
|
377
|
-
|
|
497
|
+
opened((event) => {
|
|
498
|
+
if (observers.has(notify))
|
|
499
|
+
notify(event);
|
|
500
|
+
});
|
|
378
501
|
});
|
|
379
502
|
return () => {
|
|
380
503
|
observers.delete(notify);
|
|
@@ -391,12 +514,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
391
514
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
392
515
|
},
|
|
393
516
|
async discover(_authorization) {
|
|
394
|
-
return
|
|
395
|
-
if (answer.kind === 'discovery')
|
|
396
|
-
for (const room of answer.rooms)
|
|
397
|
-
note(room.locator, room);
|
|
398
|
-
return answer;
|
|
399
|
-
});
|
|
517
|
+
return discovered();
|
|
400
518
|
},
|
|
401
519
|
reached,
|
|
402
520
|
follows(locator, roomVersion, next) {
|
|
@@ -453,7 +571,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
453
571
|
retryable: false,
|
|
454
572
|
affected: {},
|
|
455
573
|
};
|
|
456
|
-
}, request).then((answer) =>
|
|
574
|
+
}, request).then((answer) => {
|
|
575
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
576
|
+
if (answer.kind === 'accepted' && answer.destination !== undefined && destination) {
|
|
577
|
+
note(destination, answer.destination);
|
|
578
|
+
}
|
|
579
|
+
return note(request.locator, answer);
|
|
580
|
+
});
|
|
457
581
|
},
|
|
458
582
|
async history(_authorization, request) {
|
|
459
583
|
return resolveScript(scripts.history, () => {
|
|
@@ -469,34 +593,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
469
593
|
},
|
|
470
594
|
async binary(_authorization, request) {
|
|
471
595
|
return resolveScript(scripts.binary, () => {
|
|
472
|
-
if (request.kind === 'reference') {
|
|
473
|
-
return { kind: 'rejected', code: 'unscripted-binary', fields: {}, retryable: false };
|
|
474
|
-
}
|
|
475
596
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
476
597
|
if (room === undefined)
|
|
477
598
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
478
|
-
const blob = room
|
|
599
|
+
const blob = heldBlob(room, request.path);
|
|
479
600
|
return blob === undefined
|
|
480
601
|
? { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false }
|
|
481
|
-
: { kind: 'binary', blob };
|
|
602
|
+
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
482
603
|
}, request);
|
|
483
604
|
},
|
|
484
605
|
async link(_authorization, request) {
|
|
485
|
-
return resolveScript(scripts.link, () =>
|
|
606
|
+
return resolveScript(scripts.link, () => {
|
|
607
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
608
|
+
if (room === undefined)
|
|
609
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
610
|
+
const blob = heldBlob(room, request.path);
|
|
611
|
+
if (blob === undefined) {
|
|
612
|
+
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
613
|
+
}
|
|
614
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
615
|
+
linked.set(blob, url);
|
|
616
|
+
return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
|
|
617
|
+
}, request);
|
|
486
618
|
},
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
return
|
|
495
|
-
|
|
619
|
+
async attach(_authorization, request) {
|
|
620
|
+
return resolveScript(scripts.attach, () => {
|
|
621
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
622
|
+
if (room === undefined)
|
|
623
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
624
|
+
const path = freePath(room, request.name);
|
|
625
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
626
|
+
return { kind: 'attached', path, revision: `attached-${attached.size}` };
|
|
627
|
+
}, request);
|
|
496
628
|
},
|
|
497
629
|
async action(_authorization, request) {
|
|
498
630
|
return resolveScript(scripts.action, () => {
|
|
499
|
-
if (request.name.startsWith('
|
|
631
|
+
if (request.name.startsWith('conversations/'))
|
|
500
632
|
return conversationAction(request);
|
|
501
633
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
502
634
|
}, request).then((answer) => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AcceptedMessage } from './adapter.js';
|
|
2
|
+
import type { JobMarker } from './job.js';
|
|
3
|
+
import type { Connection } from './tables.js';
|
|
4
|
+
export declare const MESSAGE_TABLES: readonly string[];
|
|
5
|
+
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 substr(asking.text, 1, 512) 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";
|
|
6
|
+
export declare const JOB_MARKERS = "SELECT json_extract(part.value, '$.text') AS said,\n json_extract(message, '$.accepted_at') AS at\n FROM conversation_messages, json_each(message, '$.parts') AS part\n WHERE conversation = ? AND instr(message, '\"marker\":\"job\"') > 0\n AND json_extract(part.value, '$.type') = 'marker'\n AND json_extract(part.value, '$.marker') = 'job'\n ORDER BY position, identity, part.key";
|
|
7
|
+
export type HeldConversation = {
|
|
8
|
+
readonly conversation: string;
|
|
9
|
+
readonly read: string | null | undefined;
|
|
10
|
+
readonly partial: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type MessageWindow = {
|
|
13
|
+
readonly messages: AcceptedMessage[];
|
|
14
|
+
readonly more: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type HeldSource = {
|
|
17
|
+
readonly source: unknown;
|
|
18
|
+
readonly sender: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type HeldRow = {
|
|
21
|
+
readonly conversation: string;
|
|
22
|
+
readonly said: {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly role: string | null;
|
|
25
|
+
readonly at: string | null;
|
|
26
|
+
} | null;
|
|
27
|
+
readonly failure: string | null;
|
|
28
|
+
readonly opened: HeldSource | null;
|
|
29
|
+
readonly asking: (HeldSource & {
|
|
30
|
+
readonly identity: string;
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly at: string | null;
|
|
33
|
+
}) | null;
|
|
34
|
+
};
|
|
35
|
+
export type ConversationWrite = {
|
|
36
|
+
readonly conversation: string;
|
|
37
|
+
readonly messages: readonly AcceptedMessage[];
|
|
38
|
+
readonly read?: {
|
|
39
|
+
readonly at: string | null;
|
|
40
|
+
readonly partial: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
|
|
44
|
+
export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
|
|
45
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
46
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
47
|
+
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
48
|
+
export declare function jobMarkers(connection: Connection, conversation: string): JobMarker[];
|
|
49
|
+
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
50
|
+
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
51
|
+
export declare function forgottenMessages(connection: Connection): void;
|
|
52
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"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"}
|