@agentshouse/mdruntime 0.1.0-cf08ada271a7f → 0.1.0-cf08df9b663d8
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 +21 -19
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +57 -38
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +173 -83
- package/dist/adapter.d.ts +210 -30
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +29 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +49 -64
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +88 -44
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +32 -17
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +26 -11
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +24 -11
- package/dist/conversation-row.d.ts +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +45 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +337 -203
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +46 -48
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -1
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/holdings.d.ts.map +1 -1
- package/dist/holdings.js +5 -3
- package/dist/host.d.ts +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +94 -30
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +27 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -9
- package/dist/install.d.ts +10 -5
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +49 -55
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +74 -51
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +13 -0
- package/dist/listing.d.ts +27 -20
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +68 -69
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +10 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +8 -20
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +181 -34
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +99 -37
- package/dist/messages.d.ts +21 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +48 -16
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +10 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +18 -35
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +6 -6
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +4 -4
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +22 -10
- package/dist/outcome.d.ts +33 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +36 -6
- package/dist/overlay.d.ts +21 -7
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +112 -39
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +5 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +207 -96
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +137 -79
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +2 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +76 -49
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +196 -37
- package/dist/react.d.ts +17 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +5 -3
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +26 -14
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +31 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -36
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +25 -11
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +11 -5
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +120 -135
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +116 -65
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -4
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +8 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +95 -67
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +9 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +17 -16
- package/dist/source.d.ts +42 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +76 -9
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +31 -7
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -24
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +24 -14
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +49 -17
- package/dist/stored.d.ts +41 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +215 -57
- package/dist/surface.d.ts +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +66 -32
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +109 -82
- package/dist/tables.d.ts +40 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +109 -326
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +3 -4
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +68 -8
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +28 -11
- package/package.json +4 -4
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- package/dist/job.d.ts +0 -5
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -7
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -41
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/memory.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { definitionAt, documentFacts, parse } from '@agentshouse/mdmodel';
|
|
1
|
+
import { definitionAt, documentFacts, keyedDestination, linkKey, parse, writeRoomPath, } from '@agentshouse/mdmodel';
|
|
2
2
|
import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
|
|
3
|
+
import { selected } from './collection.js';
|
|
4
|
+
import { declaredType } from './outcome.js';
|
|
3
5
|
import { sameChange } from './overlay.js';
|
|
4
6
|
const ATTACHMENTS = 'attachments';
|
|
7
|
+
const UNFOUND = {
|
|
8
|
+
kind: 'rejected',
|
|
9
|
+
code: 'not_found',
|
|
10
|
+
fields: {},
|
|
11
|
+
retryable: false,
|
|
12
|
+
};
|
|
5
13
|
function lastName(path) {
|
|
6
14
|
return path.slice(path.lastIndexOf('/') + 1);
|
|
7
15
|
}
|
|
@@ -53,9 +61,10 @@ export function createMemoryAdapter(options = {}) {
|
|
|
53
61
|
const listeners = new Set();
|
|
54
62
|
const modeObservers = new Set();
|
|
55
63
|
const scripted = new Map();
|
|
56
|
-
const
|
|
64
|
+
const repeats = new Map();
|
|
57
65
|
const historyPageSize = options.historyPageSize;
|
|
58
66
|
const attached = new Map();
|
|
67
|
+
const keyed = new Map();
|
|
59
68
|
const linked = new WeakMap();
|
|
60
69
|
const carried = new Map();
|
|
61
70
|
let expiring = [];
|
|
@@ -63,6 +72,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
63
72
|
const declaredRooms = new Set();
|
|
64
73
|
let replicated = [];
|
|
65
74
|
let heldCursor = null;
|
|
75
|
+
let agents = structuredClone(options.agents ?? []);
|
|
66
76
|
let issued = 0;
|
|
67
77
|
function scriptConversations(entries) {
|
|
68
78
|
scripted.clear();
|
|
@@ -90,22 +100,47 @@ export function createMemoryAdapter(options = {}) {
|
|
|
90
100
|
const wanted = ordinals.get(`${locator}\u0000${target}`);
|
|
91
101
|
return held !== undefined && wanted !== undefined && held >= wanted;
|
|
92
102
|
}
|
|
93
|
-
function
|
|
103
|
+
function heldBytes(room, path) {
|
|
94
104
|
return attached.get(`${room.locator}\u0000${path}`) ?? room.blobs?.[path];
|
|
95
105
|
}
|
|
106
|
+
function linkTo(room, path) {
|
|
107
|
+
const blob = room === undefined ? undefined : heldBytes(room, path);
|
|
108
|
+
if (blob === undefined)
|
|
109
|
+
return UNFOUND;
|
|
110
|
+
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
111
|
+
linked.set(blob, url);
|
|
112
|
+
return { kind: 'link', url, name: lastName(path), mediaType: declaredType(blob) };
|
|
113
|
+
}
|
|
114
|
+
function attachedKeyed(request) {
|
|
115
|
+
const room = rooms.find((entry) => entry.locator === options.privateRoom);
|
|
116
|
+
if (room === undefined) {
|
|
117
|
+
return { kind: 'rejected', code: 'room_not_found', fields: {}, retryable: false };
|
|
118
|
+
}
|
|
119
|
+
const path = freePath(room, request.name);
|
|
120
|
+
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
121
|
+
const key = `memory-${keyed.size + 1}`;
|
|
122
|
+
keyed.set(key, { locator: room.locator, path });
|
|
123
|
+
return {
|
|
124
|
+
kind: 'linked',
|
|
125
|
+
link: keyedDestination(writeRoomPath({ handle: room.handle, path }), key),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
96
128
|
function freePath(room, name) {
|
|
97
129
|
const dot = name.lastIndexOf('.');
|
|
98
130
|
const stem = dot > 0 ? name.slice(0, dot) : name;
|
|
99
131
|
const extension = dot > 0 ? name.slice(dot) : '';
|
|
100
132
|
for (let count = 1;; count += 1) {
|
|
101
133
|
const path = `${ATTACHMENTS}/${count === 1 ? stem : `${stem}-${count}`}${extension}`;
|
|
102
|
-
if (
|
|
134
|
+
if (heldBytes(room, path) === undefined && room.documents?.[path] === undefined)
|
|
103
135
|
return path;
|
|
104
136
|
}
|
|
105
137
|
}
|
|
106
138
|
const saved = new WeakMap();
|
|
139
|
+
const roomTypes = options.roomTypes ?? NO_ROOM_TYPES;
|
|
107
140
|
function factsAt(room, path, content) {
|
|
108
|
-
const types =
|
|
141
|
+
const types = selected({ selection: room.typedSelection ?? null }, path)
|
|
142
|
+
? roomTypes.types
|
|
143
|
+
: schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, roomTypes);
|
|
109
144
|
let held = saved.get(types);
|
|
110
145
|
if (held === undefined) {
|
|
111
146
|
held = new Map();
|
|
@@ -161,7 +196,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
161
196
|
const size = pageSize ?? paths.length;
|
|
162
197
|
const taken = paths.slice(from, from + size);
|
|
163
198
|
const next = from + taken.length;
|
|
164
|
-
const targets = opening ? Object.keys(room.
|
|
199
|
+
const targets = opening ? Object.keys(room.attachments ?? {}) : [];
|
|
165
200
|
return {
|
|
166
201
|
kind: 'bootstrap',
|
|
167
202
|
roomVersion: room.roomVersion,
|
|
@@ -176,7 +211,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
176
211
|
? {}
|
|
177
212
|
: { created: named(room.created, [...taken, ...targets]) }),
|
|
178
213
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
179
|
-
|
|
214
|
+
attachments: named(room.attachments ?? {}, targets),
|
|
180
215
|
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
181
216
|
...(next < paths.length ? { pageToken: taken.at(-1) } : {}),
|
|
182
217
|
};
|
|
@@ -194,8 +229,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
194
229
|
function advancement(room, from, at, whole = false) {
|
|
195
230
|
const current = room.documents ?? {};
|
|
196
231
|
const previous = from.documents ?? {};
|
|
197
|
-
const currentTargets = new Set(Object.keys(room.
|
|
198
|
-
const previousTargets = new Set(Object.keys(from.
|
|
232
|
+
const currentTargets = new Set(Object.keys(room.attachments ?? {}));
|
|
233
|
+
const previousTargets = new Set(Object.keys(from.attachments ?? {}));
|
|
199
234
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
200
235
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
201
236
|
room.created?.[path] !== from.created?.[path] ||
|
|
@@ -228,7 +263,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
228
263
|
? {}
|
|
229
264
|
: { created: named(room.created, [...taken, ...targets]) }),
|
|
230
265
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
231
|
-
|
|
266
|
+
attachments: named(room.attachments ?? {}, targets),
|
|
232
267
|
...(opening ? foldersMoved(room, from) : {}),
|
|
233
268
|
removals: opening
|
|
234
269
|
? [
|
|
@@ -261,16 +296,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
261
296
|
}
|
|
262
297
|
function pageOf(conversation, after) {
|
|
263
298
|
const messages = conversation.messages ?? [];
|
|
264
|
-
const first = typeof after === 'string' ? messages.findIndex((message) => message.
|
|
299
|
+
const first = typeof after === 'string' ? messages.findIndex((message) => message.change > after) : 0;
|
|
265
300
|
const from = first === -1 ? messages.length : first;
|
|
266
301
|
const page = messages.slice(from, from + (historyPageSize ?? messages.length));
|
|
267
302
|
const last = page.at(-1);
|
|
268
303
|
return {
|
|
269
304
|
conversation: conversation.conversation,
|
|
270
305
|
messages: page,
|
|
271
|
-
...(last !== undefined && from + page.length < messages.length
|
|
272
|
-
? { next: last.position }
|
|
273
|
-
: {}),
|
|
306
|
+
...(last !== undefined && from + page.length < messages.length ? { next: last.change } : {}),
|
|
274
307
|
};
|
|
275
308
|
}
|
|
276
309
|
function historiesOf(request) {
|
|
@@ -290,11 +323,20 @@ export function createMemoryAdapter(options = {}) {
|
|
|
290
323
|
function conversationAction(request) {
|
|
291
324
|
const name = request.name;
|
|
292
325
|
const input = (request.input ?? {});
|
|
326
|
+
const operation = typeof input.operation_id === 'string' ? `${name}\u0000${input.operation_id}` : null;
|
|
327
|
+
const first = (answer) => {
|
|
328
|
+
if (operation !== null)
|
|
329
|
+
repeats.set(operation, answer);
|
|
330
|
+
return answer;
|
|
331
|
+
};
|
|
332
|
+
const repeated = operation === null ? undefined : repeats.get(operation);
|
|
293
333
|
if (name === 'conversations/create') {
|
|
334
|
+
if (repeated !== undefined)
|
|
335
|
+
return repeated;
|
|
294
336
|
issued += 1;
|
|
295
337
|
const conversation = `conversation-${issued}`;
|
|
296
338
|
scripted.set(conversation, { conversation });
|
|
297
|
-
return { kind: 'action', result: { conversation_id: conversation } };
|
|
339
|
+
return first({ kind: 'action', result: { conversation_id: conversation } });
|
|
298
340
|
}
|
|
299
341
|
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
300
342
|
const conversation = scripted.get(named);
|
|
@@ -310,26 +352,39 @@ export function createMemoryAdapter(options = {}) {
|
|
|
310
352
|
if (outcome !== undefined)
|
|
311
353
|
return outcome;
|
|
312
354
|
if (name === 'conversations/send') {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (answered !== undefined)
|
|
316
|
-
return { kind: 'action', result: { message_id: answered } };
|
|
355
|
+
if (repeated !== undefined)
|
|
356
|
+
return repeated;
|
|
317
357
|
issued += 1;
|
|
318
|
-
|
|
319
|
-
if (operation !== null)
|
|
320
|
-
sentTurns.set(operation, turn);
|
|
321
|
-
return { kind: 'action', result: { message_id: turn } };
|
|
358
|
+
return first({ kind: 'action', result: { message_id: `turn-${issued}` } });
|
|
322
359
|
}
|
|
323
360
|
if (name === 'conversations/delete')
|
|
324
361
|
scripted.delete(named);
|
|
325
362
|
return { kind: 'action', result: { conversation_id: named } };
|
|
326
363
|
}
|
|
364
|
+
function decided(request) {
|
|
365
|
+
const { request: asked, message, decision, } = (request.input ?? {});
|
|
366
|
+
return {
|
|
367
|
+
kind: 'action',
|
|
368
|
+
result: {
|
|
369
|
+
request: asked,
|
|
370
|
+
...(message === undefined ? {} : { message }),
|
|
371
|
+
state: decision === 'approve' ? 'started' : 'declined',
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
}
|
|
327
375
|
function announceList() {
|
|
328
376
|
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
329
377
|
? []
|
|
330
|
-
: [{ conversation, ...listed, newest: messages.at(-1)?.
|
|
378
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.change ?? null }]);
|
|
331
379
|
for (const listener of listeners) {
|
|
332
|
-
listener({
|
|
380
|
+
listener({
|
|
381
|
+
kind: 'list',
|
|
382
|
+
agents: structuredClone(agents),
|
|
383
|
+
entries,
|
|
384
|
+
whole: true,
|
|
385
|
+
more: false,
|
|
386
|
+
cursor: null,
|
|
387
|
+
});
|
|
333
388
|
}
|
|
334
389
|
}
|
|
335
390
|
function discovery() {
|
|
@@ -340,6 +395,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
340
395
|
providerLimits,
|
|
341
396
|
retention,
|
|
342
397
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
398
|
+
...(options.timeZone === undefined ? {} : { timeZone: options.timeZone }),
|
|
343
399
|
};
|
|
344
400
|
}
|
|
345
401
|
function discovered() {
|
|
@@ -385,6 +441,9 @@ export function createMemoryAdapter(options = {}) {
|
|
|
385
441
|
setConversations(next) {
|
|
386
442
|
scriptConversations(next);
|
|
387
443
|
},
|
|
444
|
+
setAgents(next) {
|
|
445
|
+
agents = structuredClone(next);
|
|
446
|
+
},
|
|
388
447
|
open() {
|
|
389
448
|
carried.clear();
|
|
390
449
|
announceList();
|
|
@@ -414,6 +473,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
414
473
|
rooms: listed.map(declared),
|
|
415
474
|
left,
|
|
416
475
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
476
|
+
...(options.timeZone === undefined ? {} : { timeZone: options.timeZone }),
|
|
417
477
|
});
|
|
418
478
|
},
|
|
419
479
|
notifyConversation(event) {
|
|
@@ -447,9 +507,6 @@ export function createMemoryAdapter(options = {}) {
|
|
|
447
507
|
};
|
|
448
508
|
},
|
|
449
509
|
history: (request) => Promise.resolve(historiesOf(request)),
|
|
450
|
-
...(options.agents === undefined
|
|
451
|
-
? {}
|
|
452
|
-
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
453
510
|
},
|
|
454
511
|
serviceMode: {
|
|
455
512
|
observe(notify) {
|
|
@@ -599,28 +656,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
599
656
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
600
657
|
if (room === undefined)
|
|
601
658
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
602
|
-
const blob =
|
|
659
|
+
const blob = heldBytes(room, request.path);
|
|
603
660
|
return blob === undefined
|
|
604
661
|
? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
|
|
605
|
-
: { kind: 'binary', body: blob.stream(), mediaType: blob
|
|
662
|
+
: { kind: 'binary', body: blob.stream(), mediaType: declaredType(blob) };
|
|
606
663
|
}, request);
|
|
607
664
|
},
|
|
608
665
|
async link(_authorization, request) {
|
|
609
666
|
return resolveScript(scripts.link, () => {
|
|
667
|
+
if (request.kind === 'key') {
|
|
668
|
+
const key = linkKey(request.link);
|
|
669
|
+
const named = key === null ? undefined : keyed.get(key);
|
|
670
|
+
if (named === undefined)
|
|
671
|
+
return UNFOUND;
|
|
672
|
+
return linkTo(rooms.find((entry) => entry.locator === named.locator), named.path);
|
|
673
|
+
}
|
|
610
674
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
611
675
|
if (room === undefined)
|
|
612
676
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
613
|
-
|
|
614
|
-
if (blob === undefined) {
|
|
615
|
-
return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
|
|
616
|
-
}
|
|
617
|
-
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
618
|
-
linked.set(blob, url);
|
|
619
|
-
return { kind: 'link', url, name: lastName(request.path), mediaType: blob.type };
|
|
677
|
+
return linkTo(room, request.path);
|
|
620
678
|
}, request);
|
|
621
679
|
},
|
|
622
680
|
async attach(_authorization, request) {
|
|
623
681
|
return resolveScript(scripts.attach, () => {
|
|
682
|
+
if (request.locator === undefined)
|
|
683
|
+
return attachedKeyed(request);
|
|
624
684
|
const room = rooms.find((entry) => entry.locator === request.locator);
|
|
625
685
|
if (room === undefined)
|
|
626
686
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
@@ -633,6 +693,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
633
693
|
return resolveScript(scripts.action, () => {
|
|
634
694
|
if (request.name.startsWith('conversations/'))
|
|
635
695
|
return conversationAction(request);
|
|
696
|
+
if (request.name === 'agent-functions/decide')
|
|
697
|
+
return decided(request);
|
|
636
698
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
637
699
|
}, request).then((answer) => {
|
|
638
700
|
if (answer.kind === 'action' && answer.at !== undefined)
|
package/dist/messages.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { SessionState } from '@agentshouse/session-content';
|
|
1
2
|
import type { AcceptedMessage } from './adapter.js';
|
|
2
3
|
import type { Connection } from './tables.js';
|
|
3
4
|
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";
|
|
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 (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.source.kind') = 'instructions_proposal' AND json_extract(message, '$.source.state') = 'waiting' ORDER BY position DESC, identity DESC LIMIT 1) AS proposing\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 answer.turn AS answered,\n json_extract(answer.message, '$.content.state') AS saved_state,\n json_extract(answer.message, '$.accepted_at') AS saved_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n COALESCE(\n (SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn'),\n CASE WHEN julianday(json_extract(answer.message, '$.accepted_at')) < (SELECT julianday(json_extract(value, '$')) FROM replica_facts WHERE name = 'readUntil') THEN answer.turn END\n ) AS opened_turn,\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 json_extract(proposing.message, '$.source') AS proposing_source,\n json_extract(proposing.message, '$.accepted_at') AS proposing_at\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\n LEFT JOIN conversation_messages proposing ON proposing.id = chosen.proposing";
|
|
5
6
|
export type HeldConversation = {
|
|
6
7
|
readonly conversation: string;
|
|
7
8
|
readonly read: string | null | undefined;
|
|
@@ -22,6 +23,12 @@ export type HeldRow = {
|
|
|
22
23
|
readonly role: string | null;
|
|
23
24
|
readonly at: string | null;
|
|
24
25
|
} | null;
|
|
26
|
+
readonly answered: string | null;
|
|
27
|
+
readonly saved: {
|
|
28
|
+
readonly state: SessionState;
|
|
29
|
+
readonly at: string;
|
|
30
|
+
} | null;
|
|
31
|
+
readonly openedTurn: string | null;
|
|
25
32
|
readonly failure: string | null;
|
|
26
33
|
readonly opened: HeldSource | null;
|
|
27
34
|
readonly asking: (HeldSource & {
|
|
@@ -29,6 +36,16 @@ export type HeldRow = {
|
|
|
29
36
|
readonly text: string;
|
|
30
37
|
readonly at: string | null;
|
|
31
38
|
}) | null;
|
|
39
|
+
readonly proposing: {
|
|
40
|
+
readonly source: unknown;
|
|
41
|
+
readonly at: string | null;
|
|
42
|
+
} | null;
|
|
43
|
+
};
|
|
44
|
+
export type ConversationFact = 'openedTurn' | 'dismissedSuggestion';
|
|
45
|
+
export type HeldFact = {
|
|
46
|
+
readonly conversation: string;
|
|
47
|
+
readonly name: ConversationFact;
|
|
48
|
+
readonly value: string;
|
|
32
49
|
};
|
|
33
50
|
export type ConversationWrite = {
|
|
34
51
|
readonly conversation: string;
|
|
@@ -44,6 +61,7 @@ export declare function messageWindow(connection: Connection, conversation: stri
|
|
|
44
61
|
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
45
62
|
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
46
63
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
47
|
-
export declare function
|
|
48
|
-
export declare function
|
|
64
|
+
export declare function conversationFacts(connection: Connection): HeldFact[];
|
|
65
|
+
export declare function keptFact(connection: Connection, { conversation, name, value }: HeldFact): null;
|
|
66
|
+
export declare function forgottenConversations(connection: Connection): void;
|
|
49
67
|
//# sourceMappingURL=messages.d.ts.map
|
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAQ1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAQ3C,CAAC;AAUF,eAAO,MAAM,IAAI,4wFAmC8D,CAAC;AAEhF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAE7F,MAAM,MAAM,UAAU,GAAG;IAAE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MAAM,GAAG,OAAO,CAO/F;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,EAAE,CAMpE;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,QAAQ,GAAG,IAAI,CAM9F;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAEnE"}
|
package/dist/messages.js
CHANGED
|
@@ -1,46 +1,59 @@
|
|
|
1
1
|
import { sql } from '@agentshouse/mdmodel';
|
|
2
|
+
import { text } from './column.js';
|
|
2
3
|
import { EXCERPT } from './read.js';
|
|
4
|
+
import { tablesOf } from './stored.js';
|
|
3
5
|
const SAID_BY_HOUSE = `json_extract(message, '$.role') = 'house'`;
|
|
4
6
|
const ANSWERS_THE_TURN = `json_extract(message, '$.role') = 'assistant'`;
|
|
7
|
+
const WAITING_PROPOSAL = `json_extract(message, '$.source.kind') = 'instructions_proposal' AND json_extract(message, '$.source.state') = 'waiting'`;
|
|
5
8
|
export const MESSAGE_TABLES = [
|
|
6
9
|
'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
|
|
7
|
-
'CREATE TABLE conversation_messages (id INTEGER PRIMARY KEY, conversation TEXT NOT NULL, identity TEXT NOT NULL, turn TEXT NOT NULL, position TEXT NOT NULL, message TEXT NOT NULL, text TEXT NOT NULL)',
|
|
10
|
+
'CREATE TABLE conversation_messages (id INTEGER PRIMARY KEY, conversation TEXT NOT NULL, identity TEXT NOT NULL, turn TEXT NOT NULL, position TEXT NOT NULL, change TEXT NOT NULL, message TEXT NOT NULL, text TEXT NOT NULL)',
|
|
8
11
|
'CREATE UNIQUE INDEX conversation_messages_identity ON conversation_messages (conversation, identity)',
|
|
9
12
|
'CREATE INDEX conversation_messages_position ON conversation_messages (conversation, position, identity)',
|
|
10
13
|
'CREATE INDEX conversation_messages_turn ON conversation_messages (conversation, turn)',
|
|
11
14
|
`CREATE INDEX conversation_messages_house ON conversation_messages (conversation, position, identity) WHERE ${SAID_BY_HOUSE}`,
|
|
15
|
+
'CREATE TABLE conversation_facts (conversation TEXT NOT NULL, name TEXT NOT NULL, value TEXT NOT NULL, PRIMARY KEY (conversation, name)) WITHOUT ROWID',
|
|
12
16
|
];
|
|
13
17
|
const NEWEST_FIRST = 'ORDER BY position DESC, identity DESC LIMIT 1';
|
|
14
18
|
const OLDEST_FIRST = 'ORDER BY position, identity LIMIT 1';
|
|
15
19
|
const OF_THE_ROW = 'SELECT id FROM conversation_messages WHERE conversation = listed.value';
|
|
20
|
+
const READ_UNTIL = `(SELECT julianday(json_extract(value, '$')) FROM replica_facts WHERE name = 'readUntil')`;
|
|
16
21
|
export const ROWS = `WITH chosen AS (
|
|
17
22
|
SELECT listed.value AS conversation,
|
|
18
23
|
(${OF_THE_ROW} AND ${ANSWERS_THE_TURN} ${NEWEST_FIRST}) AS answer,
|
|
19
24
|
(${OF_THE_ROW} AND text <> '' ${NEWEST_FIRST}) AS said,
|
|
20
25
|
(${OF_THE_ROW} AND ${SAID_BY_HOUSE} ${OLDEST_FIRST}) AS opened,
|
|
21
|
-
(${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND json_extract(message, '$.waiting') = 1 ${OLDEST_FIRST}) AS asking
|
|
26
|
+
(${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND json_extract(message, '$.waiting') = 1 ${OLDEST_FIRST}) AS asking,
|
|
27
|
+
(${OF_THE_ROW} AND ${SAID_BY_HOUSE} AND ${WAITING_PROPOSAL} ${NEWEST_FIRST}) AS proposing
|
|
22
28
|
FROM json_each(?) AS listed
|
|
23
29
|
)
|
|
24
30
|
SELECT chosen.conversation AS conversation,
|
|
25
31
|
substr(said.text, 1, ${EXCERPT}) AS said_text,
|
|
26
32
|
json_extract(said.message, '$.role') AS said_role,
|
|
27
33
|
json_extract(said.message, '$.accepted_at') AS said_at,
|
|
34
|
+
answer.turn AS answered,
|
|
35
|
+
json_extract(answer.message, '$.content.state') AS saved_state,
|
|
36
|
+
json_extract(answer.message, '$.accepted_at') AS saved_at,
|
|
28
37
|
substr(json_extract(answer.message, '$.failure'), 1, ${EXCERPT}) AS failure,
|
|
38
|
+
COALESCE(
|
|
39
|
+
(SELECT value FROM conversation_facts WHERE conversation = chosen.conversation AND name = 'openedTurn'),
|
|
40
|
+
CASE WHEN julianday(json_extract(answer.message, '$.accepted_at')) < ${READ_UNTIL} THEN answer.turn END
|
|
41
|
+
) AS opened_turn,
|
|
29
42
|
json_extract(opened.message, '$.source') AS opened_source,
|
|
30
43
|
json_extract(opened.message, '$.sender') AS opened_sender,
|
|
31
44
|
asking.identity AS asking_identity,
|
|
32
45
|
asking.text AS asking_text,
|
|
33
46
|
json_extract(asking.message, '$.accepted_at') AS asking_at,
|
|
34
47
|
json_extract(asking.message, '$.source') AS asking_source,
|
|
35
|
-
json_extract(asking.message, '$.sender') AS asking_sender
|
|
48
|
+
json_extract(asking.message, '$.sender') AS asking_sender,
|
|
49
|
+
json_extract(proposing.message, '$.source') AS proposing_source,
|
|
50
|
+
json_extract(proposing.message, '$.accepted_at') AS proposing_at
|
|
36
51
|
FROM chosen
|
|
37
52
|
LEFT JOIN conversation_messages said ON said.id = chosen.said
|
|
38
53
|
LEFT JOIN conversation_messages answer ON answer.id = chosen.answer
|
|
39
54
|
LEFT JOIN conversation_messages opened ON opened.id = chosen.opened
|
|
40
|
-
LEFT JOIN conversation_messages asking ON asking.id = chosen.asking
|
|
41
|
-
|
|
42
|
-
return typeof value === 'string' ? value : String(value);
|
|
43
|
-
}
|
|
55
|
+
LEFT JOIN conversation_messages asking ON asking.id = chosen.asking
|
|
56
|
+
LEFT JOIN conversation_messages proposing ON proposing.id = chosen.proposing`;
|
|
44
57
|
export function heldConversations(connection, conversations) {
|
|
45
58
|
const named = conversations === null ? '' : ' AND conversation IN (SELECT value FROM json_each(?))';
|
|
46
59
|
const bound = conversations === null ? [] : [JSON.stringify(conversations)];
|
|
@@ -63,11 +76,12 @@ export function heldConversations(connection, conversations) {
|
|
|
63
76
|
}
|
|
64
77
|
export function keptMessages(connection, { conversation, messages, read }) {
|
|
65
78
|
for (const message of messages) {
|
|
66
|
-
connection.run('INSERT INTO conversation_messages (conversation, identity, turn, position, message, text) VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT (conversation, identity) DO UPDATE SET turn = excluded.turn, position = excluded.position, message = excluded.message, text = excluded.text', [
|
|
79
|
+
connection.run('INSERT INTO conversation_messages (conversation, identity, turn, position, change, message, text) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (conversation, identity) DO UPDATE SET turn = excluded.turn, position = excluded.position, change = excluded.change, message = excluded.message, text = excluded.text', [
|
|
67
80
|
conversation,
|
|
68
81
|
message.identity,
|
|
69
82
|
message.turn,
|
|
70
83
|
message.position,
|
|
84
|
+
message.change,
|
|
71
85
|
JSON.stringify(message.message ?? null),
|
|
72
86
|
message.text,
|
|
73
87
|
]);
|
|
@@ -82,6 +96,7 @@ function accepted(row) {
|
|
|
82
96
|
identity: text(row.identity),
|
|
83
97
|
turn: text(row.turn),
|
|
84
98
|
position: text(row.position),
|
|
99
|
+
change: text(row.change),
|
|
85
100
|
text: text(row.text),
|
|
86
101
|
message: JSON.parse(text(row.message)),
|
|
87
102
|
};
|
|
@@ -93,7 +108,7 @@ function holding(phrase) {
|
|
|
93
108
|
}
|
|
94
109
|
export function messageWindow(connection, conversation, limit, before, phrase) {
|
|
95
110
|
const held = holding(phrase);
|
|
96
|
-
const rows = connection.rows(`SELECT identity, turn, position, message, text FROM conversation_messages WHERE conversation = ?${held.sql}${before === null ? '' : ' AND (position < ? OR (position = ? AND identity < ?))'} ORDER BY position DESC, identity DESC LIMIT ?`, before === null
|
|
111
|
+
const rows = connection.rows(`SELECT identity, turn, position, change, message, text FROM conversation_messages WHERE conversation = ?${held.sql}${before === null ? '' : ' AND (position < ? OR (position = ? AND identity < ?))'} ORDER BY position DESC, identity DESC LIMIT ?`, before === null
|
|
97
112
|
? [conversation, ...held.bind, limit + 1]
|
|
98
113
|
: [conversation, ...held.bind, before[0], before[0], before[1], limit + 1]);
|
|
99
114
|
return { messages: rows.slice(0, limit).map(accepted).reverse(), more: rows.length > limit };
|
|
@@ -122,6 +137,11 @@ export function conversationRows(connection, conversations) {
|
|
|
122
137
|
role: textOrNull(row.said_role),
|
|
123
138
|
at: textOrNull(row.said_at),
|
|
124
139
|
},
|
|
140
|
+
answered: textOrNull(row.answered),
|
|
141
|
+
saved: row.saved_state === null || row.saved_at === null
|
|
142
|
+
? null
|
|
143
|
+
: { state: JSON.parse(text(row.saved_state)), at: text(row.saved_at) },
|
|
144
|
+
openedTurn: textOrNull(row.opened_turn),
|
|
125
145
|
failure: textOrNull(row.failure),
|
|
126
146
|
opened: row.opened_source === null ? null : heldSource(row.opened_source, row.opened_sender),
|
|
127
147
|
asking: row.asking_identity === null
|
|
@@ -132,17 +152,29 @@ export function conversationRows(connection, conversations) {
|
|
|
132
152
|
text: text(row.asking_text),
|
|
133
153
|
at: textOrNull(row.asking_at),
|
|
134
154
|
},
|
|
155
|
+
proposing: row.proposing_source === null
|
|
156
|
+
? null
|
|
157
|
+
: {
|
|
158
|
+
source: JSON.parse(text(row.proposing_source)),
|
|
159
|
+
at: textOrNull(row.proposing_at),
|
|
160
|
+
},
|
|
135
161
|
}));
|
|
136
162
|
}
|
|
137
163
|
export function turnArrived(connection, conversation, turn) {
|
|
138
164
|
return (connection.rows('SELECT 1 FROM conversation_messages WHERE conversation = ? AND turn = ? LIMIT 1', [conversation, turn]).length > 0);
|
|
139
165
|
}
|
|
140
|
-
export function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
166
|
+
export function conversationFacts(connection) {
|
|
167
|
+
return connection.rows('SELECT conversation, name, value FROM conversation_facts').map((row) => ({
|
|
168
|
+
conversation: text(row.conversation),
|
|
169
|
+
name: text(row.name),
|
|
170
|
+
value: text(row.value),
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
export function keptFact(connection, { conversation, name, value }) {
|
|
174
|
+
connection.run('INSERT OR REPLACE INTO conversation_facts (conversation, name, value) VALUES (?, ?, ?)', [conversation, name, value]);
|
|
175
|
+
return null;
|
|
144
176
|
}
|
|
145
|
-
export function
|
|
146
|
-
|
|
147
|
-
|
|
177
|
+
export function forgottenConversations(connection) {
|
|
178
|
+
for (const table of tablesOf(MESSAGE_TABLES))
|
|
179
|
+
connection.run(`DELETE FROM ${table}`);
|
|
148
180
|
}
|
package/dist/modal.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":"AAMA,wBAAgB,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAI1D"}
|
package/dist/modal.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function unfocused(page) {
|
|
2
|
+
let held = page.activeElement;
|
|
3
|
+
while (held?.shadowRoot?.activeElement)
|
|
4
|
+
held = held.shadowRoot.activeElement;
|
|
5
|
+
held.blur();
|
|
6
|
+
}
|
|
7
|
+
export function shownModal(dialog) {
|
|
8
|
+
unfocused(dialog.ownerDocument);
|
|
9
|
+
dialog.showModal();
|
|
10
|
+
unfocused(dialog.ownerDocument);
|
|
11
|
+
}
|
package/dist/model.d.ts
CHANGED
|
@@ -17,21 +17,22 @@ export type ModelResult = {
|
|
|
17
17
|
reason: ModelUnavailableReason;
|
|
18
18
|
};
|
|
19
19
|
export type MdType = Definition;
|
|
20
|
-
export type
|
|
20
|
+
export type StoredModel = {
|
|
21
21
|
status: 'unavailable';
|
|
22
22
|
reason: ModelUnavailableReason;
|
|
23
23
|
} | {
|
|
24
24
|
status: 'current' | 'cached';
|
|
25
25
|
snapshot: ModelSnapshot;
|
|
26
26
|
verifiedWith: ModelIdentity;
|
|
27
|
-
types: VerifiedModel['types'];
|
|
28
27
|
};
|
|
29
|
-
export type
|
|
28
|
+
export type ModelState = Extract<StoredModel, {
|
|
30
29
|
status: 'unavailable';
|
|
31
|
-
}> |
|
|
30
|
+
}> | (Extract<StoredModel, {
|
|
32
31
|
status: 'current' | 'cached';
|
|
33
|
-
}
|
|
34
|
-
|
|
32
|
+
}> & {
|
|
33
|
+
types: VerifiedModel['types'];
|
|
34
|
+
});
|
|
35
|
+
export type TypesResult<Types = readonly MdType[]> = {
|
|
35
36
|
status: Open<'unavailable'>;
|
|
36
37
|
reason: ModelUnavailableReason;
|
|
37
38
|
types: null;
|
|
@@ -40,7 +41,7 @@ export type TypesResult = {
|
|
|
40
41
|
identity: string;
|
|
41
42
|
version: string;
|
|
42
43
|
verifiedWith: ModelIdentity;
|
|
43
|
-
types:
|
|
44
|
+
types: Types;
|
|
44
45
|
schema: string | null;
|
|
45
46
|
revision: string | null;
|
|
46
47
|
};
|
|
@@ -50,6 +51,8 @@ export type ValidationReceipt = {
|
|
|
50
51
|
source: Open<'current' | 'cached'>;
|
|
51
52
|
};
|
|
52
53
|
export declare const NO_MODEL: ModelState;
|
|
54
|
+
export declare function sortedTypes(types: VerifiedModel['types']): readonly MdType[];
|
|
53
55
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
56
|
+
export declare function modelResult<Types>(state: ModelState, types: (held: VerifiedModel['types']) => Types): TypesResult<Types>;
|
|
54
57
|
export declare function storedModel(state: ModelState): StoredModel;
|
|
55
58
|
//# sourceMappingURL=model.d.ts.map
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO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AC,OAAO,CAAC,GAAG,SAAS,MAAM,EAAE,CAI5E;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAEzD;AACD,wBAAgB,WAAW,CAAC,KAAK,EAC/B,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,KAAK,KAAK,GAC7C,WAAW,CAAC,KAAK,CAAC,CAYpB;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAI1D"}
|
package/dist/model.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export const NO_MODEL = { status: 'unavailable', reason: 'not-acquired' };
|
|
2
|
+
export function sortedTypes(types) {
|
|
3
|
+
return Object.values(types).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
4
|
+
}
|
|
2
5
|
export function modelTypes(state) {
|
|
6
|
+
return modelResult(state, sortedTypes);
|
|
7
|
+
}
|
|
8
|
+
export function modelResult(state, types) {
|
|
3
9
|
return state.status === 'unavailable'
|
|
4
10
|
? { ...state, types: null }
|
|
5
11
|
: {
|
|
@@ -9,7 +15,7 @@ export function modelTypes(state) {
|
|
|
9
15
|
verifiedWith: { ...state.verifiedWith },
|
|
10
16
|
schema: state.snapshot.schema,
|
|
11
17
|
revision: state.snapshot.revision,
|
|
12
|
-
types:
|
|
18
|
+
types: types(state.types),
|
|
13
19
|
};
|
|
14
20
|
}
|
|
15
21
|
export function storedModel(state) {
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAOnE,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAGvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,C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