@agentshouse/mdruntime 0.1.0-cf24798931067 → 0.1.0-cf281e8224a5d
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 +22 -10
- 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 +177 -54
- 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/attempt.d.ts.map +1 -1
- package/dist/attempt.js +14 -1
- package/dist/binary.d.ts +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +31 -11
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +324 -92
- 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 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -62
- package/dist/change.d.ts +42 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +36 -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 +50 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +110 -9
- package/dist/collection.d.ts +11 -7
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +38 -79
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +711 -0
- package/dist/connection.d.ts +8 -111
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +104 -2219
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- 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 +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +57 -40
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +992 -543
- 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 +19 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +20 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +161 -0
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- 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 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- 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 +12 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +132 -18
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +3 -0
- package/dist/index.d.ts +35 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +554 -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 +268 -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 +23 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +163 -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 +21 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +271 -91
- package/dist/messages.d.ts +52 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +162 -0
- package/dist/model.d.ts +11 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -10
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +195 -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 +22 -4
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +127 -26
- 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 +57 -0
- package/dist/outcome.d.ts +56 -5
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +49 -0
- package/dist/overlay.d.ts +16 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +140 -177
- package/dist/{chat/parts.d.ts → parts.d.ts} +12 -9
- package/dist/parts.d.ts.map +1 -0
- package/dist/{chat/parts.js → parts.js} +53 -46
- 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 +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 +51 -183
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -464
- 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 +21 -5
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +291 -69
- package/dist/react.d.ts +20 -6
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +17 -18
- 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 +49 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +27 -0
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +171 -0
- package/dist/recovery.d.ts +26 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +232 -0
- package/dist/refresh.d.ts +17 -14
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +143 -56
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +55 -0
- package/dist/replica.d.ts +59 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +342 -158
- package/dist/room-draft.d.ts +54 -8
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +268 -63
- 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 +30 -35
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +59 -124
- 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 +74 -3
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +812 -153
- 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 +15 -55
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +10 -121
- package/dist/seed.d.ts +25 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +145 -0
- package/dist/shared.d.ts +10 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +339 -0
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +292 -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 +5 -2
- 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 +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 +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 +106 -117
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +137 -496
- package/dist/stored.d.ts +156 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +649 -0
- 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 +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +532 -0
- package/dist/tables.d.ts +416 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +740 -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 +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- 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 +11 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +16 -0
- package/dist/wire.d.ts +181 -31
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +62 -29
- package/package.json +26 -15
- package/AGENTS.md +0 -290
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/chat/acts.d.ts +0 -34
- package/dist/chat/acts.d.ts.map +0 -1
- package/dist/chat/acts.js +0 -36
- package/dist/chat/messages.d.ts +0 -21
- package/dist/chat/messages.d.ts.map +0 -1
- package/dist/chat/messages.js +0 -151
- 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 -57
- package/dist/chat/provider.d.ts.map +0 -1
- package/dist/chat/provider.js +0 -637
- package/dist/chat/questions.d.ts.map +0 -1
- package/dist/chat/read.d.ts.map +0 -1
- package/dist/chat.d.ts +0 -7
- package/dist/chat.d.ts.map +0 -1
- package/dist/chat.js +0 -2
- package/dist/read-side.d.ts +0 -18
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -433
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: 1,
|
|
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,12 +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
|
|
57
|
-
const sealed = new Set();
|
|
56
|
+
const sentTurns = new Map();
|
|
58
57
|
const historyPageSize = options.historyPageSize;
|
|
59
|
-
|
|
58
|
+
const attached = new Map();
|
|
59
|
+
const linked = new WeakMap();
|
|
60
|
+
const carried = new Map();
|
|
60
61
|
let expiring = [];
|
|
62
|
+
let openings = 0;
|
|
63
|
+
const declaredRooms = new Set();
|
|
61
64
|
let replicated = [];
|
|
65
|
+
let heldCursor = null;
|
|
62
66
|
let issued = 0;
|
|
63
67
|
function scriptConversations(entries) {
|
|
64
68
|
scripted.clear();
|
|
@@ -86,8 +90,48 @@ export function createMemoryAdapter(options = {}) {
|
|
|
86
90
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
87
91
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
88
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
|
+
}
|
|
89
131
|
function retain(entries) {
|
|
90
132
|
for (const room of entries) {
|
|
133
|
+
for (const [path, content] of Object.entries(room.documents ?? {}))
|
|
134
|
+
factsAt(room, path, content);
|
|
91
135
|
note(room.locator, room);
|
|
92
136
|
const versions = served.get(room.locator) ?? new Map();
|
|
93
137
|
versions.set(room.roomVersion, room);
|
|
@@ -105,6 +149,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
105
149
|
replica: room.replica,
|
|
106
150
|
...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
|
|
107
151
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
152
|
+
authoredPaths: room.authoredPaths,
|
|
108
153
|
};
|
|
109
154
|
}
|
|
110
155
|
function page(room, after) {
|
|
@@ -114,30 +159,49 @@ export function createMemoryAdapter(options = {}) {
|
|
|
114
159
|
const size = pageSize ?? paths.length;
|
|
115
160
|
const taken = paths.slice(from, from + size);
|
|
116
161
|
const next = from + taken.length;
|
|
117
|
-
const targets = opening ? (room.
|
|
162
|
+
const targets = opening ? Object.keys(room.binaryFiles ?? {}) : [];
|
|
118
163
|
return {
|
|
119
164
|
kind: 'bootstrap',
|
|
120
165
|
roomVersion: room.roomVersion,
|
|
121
166
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
122
167
|
documents: named(room.documents ?? {}, taken),
|
|
123
|
-
|
|
168
|
+
facts: factsIn(room, taken),
|
|
169
|
+
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
170
|
+
...(room.fileIds === undefined
|
|
171
|
+
? {}
|
|
172
|
+
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
173
|
+
...(room.created === undefined
|
|
174
|
+
? {}
|
|
175
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
124
176
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
125
|
-
|
|
126
|
-
...(opening && room.
|
|
177
|
+
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
178
|
+
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
127
179
|
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
128
180
|
};
|
|
129
181
|
}
|
|
130
|
-
function
|
|
182
|
+
function foldersMoved(room, from) {
|
|
183
|
+
const now = new Set(room.folders ?? []);
|
|
184
|
+
const before = new Set(from.folders ?? []);
|
|
185
|
+
const folders = [...now].filter((folder) => !before.has(folder)).sort();
|
|
186
|
+
const folderRemovals = [...before].filter((folder) => !now.has(folder)).sort();
|
|
187
|
+
return {
|
|
188
|
+
...(folders.length === 0 ? {} : { folders }),
|
|
189
|
+
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function advancement(room, from, at, whole = false) {
|
|
131
193
|
const current = room.documents ?? {};
|
|
132
194
|
const previous = from.documents ?? {};
|
|
133
|
-
const currentTargets = new Set(room.
|
|
134
|
-
const previousTargets = new Set(from.
|
|
195
|
+
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
196
|
+
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
135
197
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
198
|
+
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
199
|
+
room.created?.[path] !== from.created?.[path] ||
|
|
136
200
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
137
201
|
const changed = Object.keys(current)
|
|
138
202
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
139
203
|
.sort();
|
|
140
|
-
const size = pageSize ?? changed.length;
|
|
204
|
+
const size = whole ? changed.length : (pageSize ?? changed.length);
|
|
141
205
|
const taken = changed.slice(at, at + size);
|
|
142
206
|
const next = at + taken.length;
|
|
143
207
|
const opening = at === 0;
|
|
@@ -147,27 +211,52 @@ export function createMemoryAdapter(options = {}) {
|
|
|
147
211
|
const targets = opening
|
|
148
212
|
? [...currentTargets].filter((target) => !previousTargets.has(target) || headMoved(target))
|
|
149
213
|
: [];
|
|
150
|
-
const attachments = room.attachments ?? [];
|
|
151
|
-
const declared = opening && JSON.stringify(attachments) !== JSON.stringify(from.attachments ?? []);
|
|
152
214
|
const models = opening ? changedModels(room, from) : undefined;
|
|
153
215
|
return {
|
|
154
216
|
kind: 'net-advancement',
|
|
155
217
|
roomVersion: room.roomVersion,
|
|
156
218
|
...(models === undefined ? {} : { models }),
|
|
157
219
|
documents: named(current, taken),
|
|
158
|
-
|
|
220
|
+
facts: factsIn(room, taken),
|
|
221
|
+
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
222
|
+
...(room.fileIds === undefined
|
|
223
|
+
? {}
|
|
224
|
+
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
225
|
+
...(room.created === undefined
|
|
226
|
+
? {}
|
|
227
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
159
228
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
160
|
-
|
|
229
|
+
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
230
|
+
...(opening ? foldersMoved(room, from) : {}),
|
|
161
231
|
removals: opening
|
|
162
232
|
? [
|
|
163
233
|
...Object.keys(previous).filter((path) => !(path in current) && !currentTargets.has(path)),
|
|
164
234
|
...[...previousTargets].filter((target) => !currentTargets.has(target) && !(target in current)),
|
|
165
235
|
].sort()
|
|
166
236
|
: [],
|
|
167
|
-
...(declared ? { attachments } : {}),
|
|
168
237
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
169
238
|
};
|
|
170
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
|
+
}
|
|
171
260
|
function pageOf(conversation, after) {
|
|
172
261
|
const messages = conversation.messages ?? [];
|
|
173
262
|
const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
|
|
@@ -182,16 +271,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
182
271
|
: {}),
|
|
183
272
|
};
|
|
184
273
|
}
|
|
185
|
-
function historiesOf(
|
|
186
|
-
const asked = input?.conversations;
|
|
187
|
-
if (!Array.isArray(asked))
|
|
188
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
274
|
+
function historiesOf(request) {
|
|
189
275
|
const histories = [];
|
|
190
|
-
for (const entry of
|
|
191
|
-
const conversation =
|
|
276
|
+
for (const entry of request.conversations) {
|
|
277
|
+
const conversation = scripted.get(entry.conversation);
|
|
192
278
|
if (conversation === undefined)
|
|
193
279
|
continue;
|
|
194
|
-
const outcome = conversation.outcomes?.
|
|
280
|
+
const outcome = conversation.outcomes?.history;
|
|
195
281
|
if (outcome !== undefined)
|
|
196
282
|
return outcome;
|
|
197
283
|
histories.push(pageOf(conversation, entry.after));
|
|
@@ -202,15 +288,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
202
288
|
function conversationAction(request) {
|
|
203
289
|
const name = request.name;
|
|
204
290
|
const input = (request.input ?? {});
|
|
205
|
-
if (name === '
|
|
206
|
-
return historiesOf(request.input);
|
|
207
|
-
if (name === 'conversation.create') {
|
|
291
|
+
if (name === 'conversations/create') {
|
|
208
292
|
issued += 1;
|
|
209
293
|
const conversation = `conversation-${issued}`;
|
|
210
294
|
scripted.set(conversation, { conversation });
|
|
211
|
-
return { kind: 'action', result: { conversation } };
|
|
295
|
+
return { kind: 'action', result: { conversation_id: conversation } };
|
|
212
296
|
}
|
|
213
|
-
const named = typeof input.
|
|
297
|
+
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
214
298
|
const conversation = scripted.get(named);
|
|
215
299
|
if (conversation === undefined) {
|
|
216
300
|
return {
|
|
@@ -223,28 +307,28 @@ export function createMemoryAdapter(options = {}) {
|
|
|
223
307
|
const outcome = conversation.outcomes?.[name];
|
|
224
308
|
if (outcome !== undefined)
|
|
225
309
|
return outcome;
|
|
226
|
-
if (name === '
|
|
310
|
+
if (name === 'conversations/send') {
|
|
311
|
+
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
312
|
+
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
313
|
+
if (answered !== undefined)
|
|
314
|
+
return { kind: 'action', result: { message_id: answered } };
|
|
227
315
|
issued += 1;
|
|
228
316
|
const turn = `turn-${issued}`;
|
|
229
|
-
|
|
230
|
-
|
|
317
|
+
if (operation !== null)
|
|
318
|
+
sentTurns.set(operation, turn);
|
|
319
|
+
return { kind: 'action', result: { message_id: turn } };
|
|
231
320
|
}
|
|
232
|
-
if (name === '
|
|
233
|
-
const turn = typeof input.turn === 'string' ? input.turn : '';
|
|
234
|
-
if (sealed.has(turn) || !unsealed.has(turn)) {
|
|
235
|
-
return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
|
|
236
|
-
}
|
|
237
|
-
unsealed.delete(turn);
|
|
238
|
-
return { kind: 'action', result: { turn, cancelled: true } };
|
|
239
|
-
}
|
|
240
|
-
if (name === 'conversation.delete')
|
|
321
|
+
if (name === 'conversations/delete')
|
|
241
322
|
scripted.delete(named);
|
|
242
|
-
return { kind: 'action', result: {
|
|
323
|
+
return { kind: 'action', result: { conversation_id: named } };
|
|
243
324
|
}
|
|
244
325
|
function announceList() {
|
|
245
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
246
|
-
|
|
247
|
-
|
|
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
|
+
}
|
|
248
332
|
}
|
|
249
333
|
function discovery() {
|
|
250
334
|
return {
|
|
@@ -256,7 +340,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
256
340
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
257
341
|
};
|
|
258
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
|
+
}
|
|
259
376
|
return {
|
|
377
|
+
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
378
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
260
379
|
setRooms(next) {
|
|
261
380
|
rooms = [...next];
|
|
262
381
|
retain(rooms);
|
|
@@ -265,26 +384,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
265
384
|
scriptConversations(next);
|
|
266
385
|
},
|
|
267
386
|
open() {
|
|
387
|
+
carried.clear();
|
|
268
388
|
announceList();
|
|
269
|
-
|
|
270
|
-
observer({ kind: 'opened' });
|
|
389
|
+
opened(emitAll);
|
|
271
390
|
},
|
|
272
|
-
close(revoked = false) {
|
|
273
|
-
|
|
274
|
-
|
|
391
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
392
|
+
openings += 1;
|
|
393
|
+
carried.clear();
|
|
394
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
275
395
|
},
|
|
276
396
|
expire(locators) {
|
|
277
397
|
expiring = [...locators];
|
|
278
398
|
},
|
|
279
|
-
notifyRoomVersion({ locator
|
|
280
|
-
|
|
281
|
-
|
|
399
|
+
notifyRoomVersion({ locator }) {
|
|
400
|
+
carry(locator);
|
|
401
|
+
},
|
|
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
|
+
});
|
|
282
416
|
},
|
|
283
417
|
notifyConversation(event) {
|
|
284
|
-
if (event.kind === 'accepted-message') {
|
|
285
|
-
sealed.add(event.message.turn);
|
|
286
|
-
unsealed.delete(event.message.turn);
|
|
287
|
-
}
|
|
288
418
|
for (const listener of listeners)
|
|
289
419
|
listener(event);
|
|
290
420
|
},
|
|
@@ -293,21 +423,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
293
423
|
observer(mode);
|
|
294
424
|
},
|
|
295
425
|
heldRooms() {
|
|
296
|
-
return
|
|
426
|
+
return [...carried.keys()].sort();
|
|
297
427
|
},
|
|
298
428
|
replicatedConversations() {
|
|
299
429
|
return replicated;
|
|
300
430
|
},
|
|
431
|
+
heldConversationCursor() {
|
|
432
|
+
return heldCursor;
|
|
433
|
+
},
|
|
301
434
|
conversations: {
|
|
302
435
|
replicate(next) {
|
|
303
436
|
replicated = [...next];
|
|
304
437
|
},
|
|
438
|
+
hold(cursor) {
|
|
439
|
+
heldCursor = cursor;
|
|
440
|
+
},
|
|
305
441
|
observe(notify) {
|
|
306
442
|
listeners.add(notify);
|
|
307
443
|
return () => {
|
|
308
444
|
listeners.delete(notify);
|
|
309
445
|
};
|
|
310
446
|
},
|
|
447
|
+
history: (request) => Promise.resolve(historiesOf(request)),
|
|
448
|
+
...(options.agents === undefined
|
|
449
|
+
? {}
|
|
450
|
+
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
311
451
|
},
|
|
312
452
|
serviceMode: {
|
|
313
453
|
observe(notify) {
|
|
@@ -319,29 +459,30 @@ export function createMemoryAdapter(options = {}) {
|
|
|
319
459
|
},
|
|
320
460
|
roomStream: {
|
|
321
461
|
hold(asked) {
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
expiring = [];
|
|
325
|
-
const moved = asked.flatMap((room) => {
|
|
462
|
+
const named = asked.map((room) => room.locator);
|
|
463
|
+
const unknown = asked.flatMap((room) => {
|
|
326
464
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
465
|
+
const version = room.roomVersion;
|
|
327
466
|
return current === undefined ||
|
|
328
|
-
|
|
329
|
-
|
|
467
|
+
(version !== null &&
|
|
468
|
+
(current.roomVersion === version || served.get(room.locator)?.has(version) === true))
|
|
330
469
|
? []
|
|
331
|
-
: [
|
|
470
|
+
: [room.locator];
|
|
332
471
|
});
|
|
472
|
+
const expired = [
|
|
473
|
+
...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
|
|
474
|
+
];
|
|
475
|
+
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
333
476
|
queueMicrotask(() => {
|
|
334
|
-
for (const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
}
|
|
338
484
|
}
|
|
339
|
-
|
|
340
|
-
},
|
|
341
|
-
reopen() {
|
|
342
|
-
queueMicrotask(() => {
|
|
343
|
-
for (const observer of observers)
|
|
344
|
-
observer({ kind: 'closed', revoked: false });
|
|
485
|
+
emitAll({ kind: 'caught-up', expired });
|
|
345
486
|
});
|
|
346
487
|
},
|
|
347
488
|
observe(notify) {
|
|
@@ -350,11 +491,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
350
491
|
if (!observers.has(notify))
|
|
351
492
|
return;
|
|
352
493
|
if (options.unopened === true) {
|
|
353
|
-
notify({ kind: 'closed', revoked: false });
|
|
494
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
354
495
|
return;
|
|
355
496
|
}
|
|
356
497
|
announceList();
|
|
357
|
-
|
|
498
|
+
opened((event) => {
|
|
499
|
+
if (observers.has(notify))
|
|
500
|
+
notify(event);
|
|
501
|
+
});
|
|
358
502
|
});
|
|
359
503
|
return () => {
|
|
360
504
|
observers.delete(notify);
|
|
@@ -371,12 +515,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
371
515
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
372
516
|
},
|
|
373
517
|
async discover(_authorization) {
|
|
374
|
-
return
|
|
375
|
-
if (answer.kind === 'discovery')
|
|
376
|
-
for (const room of answer.rooms)
|
|
377
|
-
note(room.locator, room);
|
|
378
|
-
return answer;
|
|
379
|
-
});
|
|
518
|
+
return discovered();
|
|
380
519
|
},
|
|
381
520
|
reached,
|
|
382
521
|
follows(locator, roomVersion, next) {
|
|
@@ -433,7 +572,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
433
572
|
retryable: false,
|
|
434
573
|
affected: {},
|
|
435
574
|
};
|
|
436
|
-
}, request).then((answer) =>
|
|
575
|
+
}, request).then((answer) => {
|
|
576
|
+
const destination = request.changeBatch.between?.destination.room;
|
|
577
|
+
if (answer.kind === 'accepted' && answer.destination !== undefined && destination) {
|
|
578
|
+
note(destination, answer.destination);
|
|
579
|
+
}
|
|
580
|
+
return note(request.locator, answer);
|
|
581
|
+
});
|
|
437
582
|
},
|
|
438
583
|
async history(_authorization, request) {
|
|
439
584
|
return resolveScript(scripts.history, () => {
|
|
@@ -447,9 +592,44 @@ export function createMemoryAdapter(options = {}) {
|
|
|
447
592
|
};
|
|
448
593
|
}, request);
|
|
449
594
|
},
|
|
595
|
+
async binary(_authorization, request) {
|
|
596
|
+
return resolveScript(scripts.binary, () => {
|
|
597
|
+
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
598
|
+
if (room === undefined)
|
|
599
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
600
|
+
const blob = heldBlob(room, request.path);
|
|
601
|
+
return blob === undefined
|
|
602
|
+
? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
|
|
603
|
+
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
604
|
+
}, request);
|
|
605
|
+
},
|
|
606
|
+
async link(_authorization, request) {
|
|
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);
|
|
619
|
+
},
|
|
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);
|
|
629
|
+
},
|
|
450
630
|
async action(_authorization, request) {
|
|
451
631
|
return resolveScript(scripts.action, () => {
|
|
452
|
-
if (request.name.startsWith('
|
|
632
|
+
if (request.name.startsWith('conversations/'))
|
|
453
633
|
return conversationAction(request);
|
|
454
634
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
455
635
|
}, 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 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";
|
|
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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"}
|