@agentshouse/mdruntime 0.1.0-ccbb89b0ca151 → 0.1.0-ccc0e3407f107
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 +1 -1
- package/dist/adapter.d.ts +74 -57
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +3 -10
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +29 -47
- package/dist/bootstrap.d.ts +11 -18
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +85 -108
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/collection.d.ts +7 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -17
- package/dist/compile.d.ts +1 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +91 -270
- package/dist/connection.d.ts +10 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1009 -1063
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation.d.ts +16 -13
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +229 -155
- package/dist/durability.d.ts +6 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -8
- package/dist/host.d.ts +3 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +22 -27
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/job.d.ts +14 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +28 -0
- package/dist/live.d.ts +2 -1
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +10 -7
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +27 -4
- package/dist/memory.d.ts +11 -5
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +167 -84
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +15 -16
- package/dist/model.d.ts +8 -8
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -12
- package/dist/observation.d.ts +3 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +8 -3
- package/dist/outcome.d.ts +0 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +4 -0
- package/dist/query.d.ts +4 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/reach.d.ts +9 -8
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +37 -48
- package/dist/react.d.ts +3 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +3 -17
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +4 -10
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +26 -0
- package/dist/refresh.d.ts +7 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +29 -5
- package/dist/replica.d.ts +10 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +29 -14
- package/dist/room-draft.d.ts +21 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +98 -51
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +48 -184
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +20 -12
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/shared.d.ts +0 -1
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +0 -10
- package/dist/status.d.ts +4 -3
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +3 -1
- package/dist/store.d.ts +21 -34
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +34 -77
- package/dist/stored.d.ts +11 -34
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +158 -241
- package/dist/tables.d.ts +23 -48
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +29 -66
- package/dist/transfer.d.ts +0 -5
- package/dist/transfer.d.ts.map +1 -1
- package/dist/validation.d.ts +3 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +42 -100
- package/dist/windows.d.ts +1 -12
- package/dist/windows.d.ts.map +1 -1
- package/dist/windows.js +2 -75
- package/dist/wire.d.ts +9 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -1
- package/package.json +2 -2
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -368
- package/dist/reads.d.ts +0 -11
- package/dist/reads.d.ts.map +0 -1
- package/dist/reads.js +0 -100
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -150
package/dist/memory.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ModelResult } from './model.js';
|
|
2
|
-
import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type
|
|
2
|
+
import { type AcceptedMessage, type ActionResult, type Adapter, type BinaryFile, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type SavedFacts, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode, type TypedPath } from './adapter.js';
|
|
3
3
|
export type MemoryRoom = DiscoveredRoom & {
|
|
4
4
|
model?: ModelResult;
|
|
5
5
|
documents?: Readonly<Record<string, string>>;
|
|
6
|
+
facts?: Readonly<Record<string, SavedFacts>>;
|
|
6
7
|
revisions?: Readonly<Record<string, string>>;
|
|
7
8
|
fileIds?: Readonly<Record<string, string>>;
|
|
8
9
|
changes?: Readonly<Record<string, HeadChange>>;
|
|
@@ -12,13 +13,14 @@ export type MemoryRoom = DiscoveredRoom & {
|
|
|
12
13
|
};
|
|
13
14
|
export type MemoryConversation = {
|
|
14
15
|
conversation: string;
|
|
15
|
-
listed?: Omit<ListedConversation, 'conversation'>;
|
|
16
|
+
listed?: Omit<ListedConversation, 'conversation' | 'newest'>;
|
|
16
17
|
messages?: readonly AcceptedMessage[];
|
|
17
|
-
outcomes?: Partial<Record<ConversationAction, ActionResult>>;
|
|
18
|
+
outcomes?: Partial<Record<ConversationAction | 'history', ActionResult>>;
|
|
18
19
|
};
|
|
19
20
|
export type MemoryAdapterOptions = {
|
|
20
21
|
rooms?: readonly MemoryRoom[];
|
|
21
22
|
conversations?: readonly MemoryConversation[];
|
|
23
|
+
agents?: readonly ListedAgent[];
|
|
22
24
|
historyPageSize?: number;
|
|
23
25
|
pageSize?: number;
|
|
24
26
|
capabilities?: readonly Capability[];
|
|
@@ -26,10 +28,12 @@ export type MemoryAdapterOptions = {
|
|
|
26
28
|
retention?: Retention;
|
|
27
29
|
member?: Member;
|
|
28
30
|
unopened?: boolean;
|
|
29
|
-
exhaustiveDiscovery?: true;
|
|
30
31
|
roomTypes?: string;
|
|
32
|
+
typedPaths?: readonly TypedPath[];
|
|
31
33
|
};
|
|
32
34
|
export type MemoryAdapter = Adapter & {
|
|
35
|
+
discover: NonNullable<Adapter['discover']>;
|
|
36
|
+
refresh: NonNullable<Adapter['refresh']>;
|
|
33
37
|
setRooms(rooms: readonly MemoryRoom[]): void;
|
|
34
38
|
setConversations(conversations: readonly MemoryConversation[]): void;
|
|
35
39
|
script(operation: keyof Adapter, answer: unknown): void;
|
|
@@ -37,17 +41,19 @@ export type MemoryAdapter = Adapter & {
|
|
|
37
41
|
close(closing?: {
|
|
38
42
|
revoked?: boolean;
|
|
39
43
|
lost?: boolean;
|
|
44
|
+
authorityChanged?: boolean;
|
|
40
45
|
}): void;
|
|
41
46
|
expire(locators: readonly string[]): void;
|
|
42
47
|
notifyRoomVersion(notification: {
|
|
43
48
|
locator: string;
|
|
44
49
|
roomVersion: string;
|
|
45
50
|
}): void;
|
|
46
|
-
notifyAuthorityChanged(
|
|
51
|
+
notifyAuthorityChanged(locators?: readonly string[]): void;
|
|
47
52
|
notifyConversation(event: ConversationEvent): void;
|
|
48
53
|
notifyServiceMode(mode: ServiceMode): void;
|
|
49
54
|
heldRooms(): readonly string[];
|
|
50
55
|
replicatedConversations(): readonly string[];
|
|
56
|
+
heldConversationCursor(): string | null;
|
|
51
57
|
};
|
|
52
58
|
export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
|
|
53
59
|
//# sourceMappingURL=memory.d.ts.map
|
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"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"}
|
package/dist/memory.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { documentFacts, parse } from '@agentshouse/mdmodel';
|
|
2
|
+
import { NO_ROOM_TYPES, schemaTypes } from './attached-model.js';
|
|
1
3
|
import { sameChange } from './overlay.js';
|
|
2
4
|
const ATTACHMENTS = 'attachments';
|
|
3
5
|
function lastName(path) {
|
|
@@ -5,7 +7,6 @@ function lastName(path) {
|
|
|
5
7
|
}
|
|
6
8
|
const FIXTURE_RETENTION = {
|
|
7
9
|
history: { kind: 'duration', seconds: 1 },
|
|
8
|
-
outcome: 604_800,
|
|
9
10
|
refreshHorizon: 1,
|
|
10
11
|
};
|
|
11
12
|
function declaredRetention(value) {
|
|
@@ -52,15 +53,16 @@ export function createMemoryAdapter(options = {}) {
|
|
|
52
53
|
const listeners = new Set();
|
|
53
54
|
const modeObservers = new Set();
|
|
54
55
|
const scripted = new Map();
|
|
55
|
-
const unsealed = new Map();
|
|
56
|
-
const sealed = new Set();
|
|
57
56
|
const sentTurns = new Map();
|
|
58
57
|
const historyPageSize = options.historyPageSize;
|
|
59
58
|
const attached = new Map();
|
|
60
59
|
const linked = new WeakMap();
|
|
61
|
-
|
|
60
|
+
const carried = new Map();
|
|
62
61
|
let expiring = [];
|
|
62
|
+
let openings = 0;
|
|
63
|
+
const declaredRooms = new Set();
|
|
63
64
|
let replicated = [];
|
|
65
|
+
let heldCursor = null;
|
|
64
66
|
let issued = 0;
|
|
65
67
|
function scriptConversations(entries) {
|
|
66
68
|
scripted.clear();
|
|
@@ -101,8 +103,35 @@ export function createMemoryAdapter(options = {}) {
|
|
|
101
103
|
return path;
|
|
102
104
|
}
|
|
103
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
|
+
}
|
|
104
131
|
function retain(entries) {
|
|
105
132
|
for (const room of entries) {
|
|
133
|
+
for (const [path, content] of Object.entries(room.documents ?? {}))
|
|
134
|
+
factsAt(room, path, content);
|
|
106
135
|
note(room.locator, room);
|
|
107
136
|
const versions = served.get(room.locator) ?? new Map();
|
|
108
137
|
versions.set(room.roomVersion, room);
|
|
@@ -135,6 +164,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
135
164
|
roomVersion: room.roomVersion,
|
|
136
165
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
137
166
|
documents: named(room.documents ?? {}, taken),
|
|
167
|
+
facts: factsIn(room, taken),
|
|
138
168
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
139
169
|
...(room.fileIds === undefined
|
|
140
170
|
? {}
|
|
@@ -155,7 +185,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
155
185
|
...(folderRemovals.length === 0 ? {} : { folderRemovals }),
|
|
156
186
|
};
|
|
157
187
|
}
|
|
158
|
-
function advancement(room, from, at) {
|
|
188
|
+
function advancement(room, from, at, whole = false) {
|
|
159
189
|
const current = room.documents ?? {};
|
|
160
190
|
const previous = from.documents ?? {};
|
|
161
191
|
const currentTargets = new Set(Object.keys(room.binaryFiles ?? {}));
|
|
@@ -166,7 +196,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
166
196
|
const changed = Object.keys(current)
|
|
167
197
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
168
198
|
.sort();
|
|
169
|
-
const size = pageSize ?? changed.length;
|
|
199
|
+
const size = whole ? changed.length : (pageSize ?? changed.length);
|
|
170
200
|
const taken = changed.slice(at, at + size);
|
|
171
201
|
const next = at + taken.length;
|
|
172
202
|
const opening = at === 0;
|
|
@@ -182,6 +212,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
182
212
|
roomVersion: room.roomVersion,
|
|
183
213
|
...(models === undefined ? {} : { models }),
|
|
184
214
|
documents: named(current, taken),
|
|
215
|
+
facts: factsIn(room, taken),
|
|
185
216
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
186
217
|
...(room.fileIds === undefined
|
|
187
218
|
? {}
|
|
@@ -198,6 +229,26 @@ export function createMemoryAdapter(options = {}) {
|
|
|
198
229
|
...(pageToken === undefined ? {} : { pageToken }),
|
|
199
230
|
};
|
|
200
231
|
}
|
|
232
|
+
function carry(locator) {
|
|
233
|
+
const at = carried.get(locator);
|
|
234
|
+
const current = rooms.find((entry) => entry.locator === locator);
|
|
235
|
+
if (at === undefined || current === undefined || current.roomVersion === at)
|
|
236
|
+
return;
|
|
237
|
+
const from = served.get(locator)?.get(at);
|
|
238
|
+
carried.set(locator, current.roomVersion);
|
|
239
|
+
if (from === undefined)
|
|
240
|
+
return;
|
|
241
|
+
const page = advancement(current, from, 0, true);
|
|
242
|
+
for (const observer of observers) {
|
|
243
|
+
observer({
|
|
244
|
+
kind: 'room-change',
|
|
245
|
+
locator,
|
|
246
|
+
from: at,
|
|
247
|
+
roomVersion: current.roomVersion,
|
|
248
|
+
read: async () => page,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
201
252
|
function pageOf(conversation, after) {
|
|
202
253
|
const messages = conversation.messages ?? [];
|
|
203
254
|
const first = typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;
|
|
@@ -212,16 +263,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
212
263
|
: {}),
|
|
213
264
|
};
|
|
214
265
|
}
|
|
215
|
-
function historiesOf(
|
|
216
|
-
const asked = input?.conversations;
|
|
217
|
-
if (!Array.isArray(asked))
|
|
218
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
266
|
+
function historiesOf(request) {
|
|
219
267
|
const histories = [];
|
|
220
|
-
for (const entry of
|
|
221
|
-
const conversation =
|
|
268
|
+
for (const entry of request.conversations) {
|
|
269
|
+
const conversation = scripted.get(entry.conversation);
|
|
222
270
|
if (conversation === undefined)
|
|
223
271
|
continue;
|
|
224
|
-
const outcome = conversation.outcomes?.
|
|
272
|
+
const outcome = conversation.outcomes?.history;
|
|
225
273
|
if (outcome !== undefined)
|
|
226
274
|
return outcome;
|
|
227
275
|
histories.push(pageOf(conversation, entry.after));
|
|
@@ -232,15 +280,13 @@ export function createMemoryAdapter(options = {}) {
|
|
|
232
280
|
function conversationAction(request) {
|
|
233
281
|
const name = request.name;
|
|
234
282
|
const input = (request.input ?? {});
|
|
235
|
-
if (name === '
|
|
236
|
-
return historiesOf(request.input);
|
|
237
|
-
if (name === 'conversation.create') {
|
|
283
|
+
if (name === 'conversations/create') {
|
|
238
284
|
issued += 1;
|
|
239
285
|
const conversation = `conversation-${issued}`;
|
|
240
286
|
scripted.set(conversation, { conversation });
|
|
241
|
-
return { kind: 'action', result: { conversation } };
|
|
287
|
+
return { kind: 'action', result: { conversation_id: conversation } };
|
|
242
288
|
}
|
|
243
|
-
const named = typeof input.
|
|
289
|
+
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
244
290
|
const conversation = scripted.get(named);
|
|
245
291
|
if (conversation === undefined) {
|
|
246
292
|
return {
|
|
@@ -253,34 +299,28 @@ export function createMemoryAdapter(options = {}) {
|
|
|
253
299
|
const outcome = conversation.outcomes?.[name];
|
|
254
300
|
if (outcome !== undefined)
|
|
255
301
|
return outcome;
|
|
256
|
-
if (name === '
|
|
302
|
+
if (name === 'conversations/send') {
|
|
257
303
|
const operation = typeof input.operation_id === 'string' ? input.operation_id : null;
|
|
258
304
|
const answered = operation === null ? undefined : sentTurns.get(operation);
|
|
259
305
|
if (answered !== undefined)
|
|
260
|
-
return { kind: 'action', result: {
|
|
306
|
+
return { kind: 'action', result: { message_id: answered } };
|
|
261
307
|
issued += 1;
|
|
262
308
|
const turn = `turn-${issued}`;
|
|
263
|
-
unsealed.set(turn, named);
|
|
264
309
|
if (operation !== null)
|
|
265
310
|
sentTurns.set(operation, turn);
|
|
266
|
-
return { kind: 'action', result: { turn } };
|
|
267
|
-
}
|
|
268
|
-
if (name === 'conversation.cancel') {
|
|
269
|
-
const turn = typeof input.turn === 'string' ? input.turn : '';
|
|
270
|
-
if (sealed.has(turn) || !unsealed.has(turn)) {
|
|
271
|
-
return { kind: 'rejected', code: 'turn-sealed', fields: { turn }, retryable: false };
|
|
272
|
-
}
|
|
273
|
-
unsealed.delete(turn);
|
|
274
|
-
return { kind: 'action', result: { turn, cancelled: true } };
|
|
311
|
+
return { kind: 'action', result: { message_id: turn } };
|
|
275
312
|
}
|
|
276
|
-
if (name === '
|
|
313
|
+
if (name === 'conversations/delete')
|
|
277
314
|
scripted.delete(named);
|
|
278
|
-
return { kind: 'action', result: {
|
|
315
|
+
return { kind: 'action', result: { conversation_id: named } };
|
|
279
316
|
}
|
|
280
317
|
function announceList() {
|
|
281
|
-
const entries = [...scripted.values()].flatMap(({ conversation, listed }) => listed === undefined
|
|
282
|
-
|
|
283
|
-
|
|
318
|
+
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
319
|
+
? []
|
|
320
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.position ?? null }]);
|
|
321
|
+
for (const listener of listeners) {
|
|
322
|
+
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
323
|
+
}
|
|
284
324
|
}
|
|
285
325
|
function discovery() {
|
|
286
326
|
return {
|
|
@@ -292,9 +332,42 @@ export function createMemoryAdapter(options = {}) {
|
|
|
292
332
|
...(options.member === undefined ? {} : { member: options.member }),
|
|
293
333
|
};
|
|
294
334
|
}
|
|
335
|
+
function discovered() {
|
|
336
|
+
return resolveScript(scripts.discover, discovery, undefined).then((answer) => {
|
|
337
|
+
if (answer.kind === 'discovery')
|
|
338
|
+
for (const room of answer.rooms)
|
|
339
|
+
note(room.locator, room);
|
|
340
|
+
return answer;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function opened(notify) {
|
|
344
|
+
const opening = ++openings;
|
|
345
|
+
notify({ kind: 'opened' });
|
|
346
|
+
void discovered()
|
|
347
|
+
.catch(() => ({ kind: 'transport-uncertainty' }))
|
|
348
|
+
.then((answer) => {
|
|
349
|
+
if (opening !== openings)
|
|
350
|
+
return;
|
|
351
|
+
if (answer.kind !== 'discovery') {
|
|
352
|
+
openings += 1;
|
|
353
|
+
carried.clear();
|
|
354
|
+
const revoked = answer.kind === 'revoked-authorization';
|
|
355
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
declaredRooms.clear();
|
|
359
|
+
for (const room of answer.rooms)
|
|
360
|
+
declaredRooms.add(room.locator);
|
|
361
|
+
notify({ kind: 'discovered', discovery: answer });
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function emitAll(event) {
|
|
365
|
+
for (const observer of observers)
|
|
366
|
+
observer(event);
|
|
367
|
+
}
|
|
295
368
|
return {
|
|
296
|
-
...(options.exhaustiveDiscovery === undefined ? {} : { exhaustiveDiscovery: true }),
|
|
297
369
|
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
370
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
298
371
|
setRooms(next) {
|
|
299
372
|
rooms = [...next];
|
|
300
373
|
retain(rooms);
|
|
@@ -303,33 +376,37 @@ export function createMemoryAdapter(options = {}) {
|
|
|
303
376
|
scriptConversations(next);
|
|
304
377
|
},
|
|
305
378
|
open() {
|
|
379
|
+
carried.clear();
|
|
306
380
|
announceList();
|
|
307
|
-
|
|
308
|
-
observer({ kind: 'opened' });
|
|
381
|
+
opened(emitAll);
|
|
309
382
|
},
|
|
310
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
311
|
-
|
|
312
|
-
|
|
383
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
384
|
+
openings += 1;
|
|
385
|
+
carried.clear();
|
|
386
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
313
387
|
},
|
|
314
388
|
expire(locators) {
|
|
315
389
|
expiring = [...locators];
|
|
316
390
|
},
|
|
317
|
-
notifyRoomVersion({ locator
|
|
318
|
-
|
|
319
|
-
observer({ kind: 'room-version', locator, roomVersion });
|
|
391
|
+
notifyRoomVersion({ locator }) {
|
|
392
|
+
carry(locator);
|
|
320
393
|
},
|
|
321
|
-
notifyAuthorityChanged(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
394
|
+
notifyAuthorityChanged(locators) {
|
|
395
|
+
const named = new Set(locators ?? [...declaredRooms, ...rooms.map((room) => room.locator)]);
|
|
396
|
+
const listed = rooms.filter((room) => named.has(room.locator));
|
|
397
|
+
const left = [...named].filter((locator) => !listed.some((room) => room.locator === locator));
|
|
398
|
+
for (const room of listed)
|
|
399
|
+
declaredRooms.add(room.locator);
|
|
400
|
+
for (const locator of left)
|
|
401
|
+
declaredRooms.delete(locator);
|
|
402
|
+
emitAll({
|
|
403
|
+
kind: 'authority-changed',
|
|
404
|
+
rooms: listed.map(declared),
|
|
405
|
+
left,
|
|
406
|
+
...(options.member === undefined ? {} : { member: options.member }),
|
|
407
|
+
});
|
|
327
408
|
},
|
|
328
409
|
notifyConversation(event) {
|
|
329
|
-
if (event.kind === 'accepted-message') {
|
|
330
|
-
sealed.add(event.message.turn);
|
|
331
|
-
unsealed.delete(event.message.turn);
|
|
332
|
-
}
|
|
333
410
|
for (const listener of listeners)
|
|
334
411
|
listener(event);
|
|
335
412
|
},
|
|
@@ -338,21 +415,31 @@ export function createMemoryAdapter(options = {}) {
|
|
|
338
415
|
observer(mode);
|
|
339
416
|
},
|
|
340
417
|
heldRooms() {
|
|
341
|
-
return
|
|
418
|
+
return [...carried.keys()].sort();
|
|
342
419
|
},
|
|
343
420
|
replicatedConversations() {
|
|
344
421
|
return replicated;
|
|
345
422
|
},
|
|
423
|
+
heldConversationCursor() {
|
|
424
|
+
return heldCursor;
|
|
425
|
+
},
|
|
346
426
|
conversations: {
|
|
347
427
|
replicate(next) {
|
|
348
428
|
replicated = [...next];
|
|
349
429
|
},
|
|
430
|
+
hold(cursor) {
|
|
431
|
+
heldCursor = cursor;
|
|
432
|
+
},
|
|
350
433
|
observe(notify) {
|
|
351
434
|
listeners.add(notify);
|
|
352
435
|
return () => {
|
|
353
436
|
listeners.delete(notify);
|
|
354
437
|
};
|
|
355
438
|
},
|
|
439
|
+
history: (request) => Promise.resolve(historiesOf(request)),
|
|
440
|
+
...(options.agents === undefined
|
|
441
|
+
? {}
|
|
442
|
+
: { agents: () => Promise.resolve(structuredClone(options.agents)) }),
|
|
356
443
|
},
|
|
357
444
|
serviceMode: {
|
|
358
445
|
observe(notify) {
|
|
@@ -364,44 +451,45 @@ export function createMemoryAdapter(options = {}) {
|
|
|
364
451
|
},
|
|
365
452
|
roomStream: {
|
|
366
453
|
hold(asked) {
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
expiring = [];
|
|
370
|
-
const moved = asked.flatMap((room) => {
|
|
454
|
+
const named = asked.map((room) => room.locator);
|
|
455
|
+
const unknown = asked.flatMap((room) => {
|
|
371
456
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
372
457
|
return current === undefined ||
|
|
373
|
-
|
|
374
|
-
|
|
458
|
+
current.roomVersion === room.roomVersion ||
|
|
459
|
+
served.get(room.locator)?.has(room.roomVersion) === true
|
|
375
460
|
? []
|
|
376
|
-
: [
|
|
461
|
+
: [room.locator];
|
|
377
462
|
});
|
|
463
|
+
const expired = [
|
|
464
|
+
...new Set([...expiring.filter((locator) => named.includes(locator)), ...unknown]),
|
|
465
|
+
];
|
|
466
|
+
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
378
467
|
queueMicrotask(() => {
|
|
379
|
-
for (const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
468
|
+
for (const room of asked) {
|
|
469
|
+
if (expired.includes(room.locator))
|
|
470
|
+
carried.delete(room.locator);
|
|
471
|
+
else {
|
|
472
|
+
carried.set(room.locator, room.roomVersion);
|
|
473
|
+
carry(room.locator);
|
|
474
|
+
}
|
|
383
475
|
}
|
|
476
|
+
emitAll({ kind: 'caught-up', expired });
|
|
384
477
|
});
|
|
385
478
|
},
|
|
386
|
-
reopen() {
|
|
387
|
-
queueMicrotask(() => {
|
|
388
|
-
for (const observer of observers) {
|
|
389
|
-
observer({ kind: 'closed', revoked: false, lost: false });
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
},
|
|
393
|
-
published() { },
|
|
394
479
|
observe(notify) {
|
|
395
480
|
observers.add(notify);
|
|
396
481
|
queueMicrotask(() => {
|
|
397
482
|
if (!observers.has(notify))
|
|
398
483
|
return;
|
|
399
484
|
if (options.unopened === true) {
|
|
400
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
485
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
401
486
|
return;
|
|
402
487
|
}
|
|
403
488
|
announceList();
|
|
404
|
-
|
|
489
|
+
opened((event) => {
|
|
490
|
+
if (observers.has(notify))
|
|
491
|
+
notify(event);
|
|
492
|
+
});
|
|
405
493
|
});
|
|
406
494
|
return () => {
|
|
407
495
|
observers.delete(notify);
|
|
@@ -418,12 +506,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
418
506
|
return resolveScript(scripts.authorize, () => ({}), undefined);
|
|
419
507
|
},
|
|
420
508
|
async discover(_authorization) {
|
|
421
|
-
return
|
|
422
|
-
if (answer.kind === 'discovery')
|
|
423
|
-
for (const room of answer.rooms)
|
|
424
|
-
note(room.locator, room);
|
|
425
|
-
return answer;
|
|
426
|
-
});
|
|
509
|
+
return discovered();
|
|
427
510
|
},
|
|
428
511
|
reached,
|
|
429
512
|
follows(locator, roomVersion, next) {
|
|
@@ -532,12 +615,12 @@ export function createMemoryAdapter(options = {}) {
|
|
|
532
615
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
533
616
|
const path = freePath(room, request.name);
|
|
534
617
|
attached.set(`${room.locator}\u0000${path}`, request.blob);
|
|
535
|
-
return { kind: 'attached', path };
|
|
618
|
+
return { kind: 'attached', path, revision: `attached-${attached.size}` };
|
|
536
619
|
}, request);
|
|
537
620
|
},
|
|
538
621
|
async action(_authorization, request) {
|
|
539
622
|
return resolveScript(scripts.action, () => {
|
|
540
|
-
if (request.name.startsWith('
|
|
623
|
+
if (request.name.startsWith('conversations/'))
|
|
541
624
|
return conversationAction(request);
|
|
542
625
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
543
626
|
}, request).then((answer) => {
|
package/dist/messages.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export type ConversationWrite = {
|
|
|
20
20
|
};
|
|
21
21
|
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
22
22
|
export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
|
|
23
|
-
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null): MessageWindow;
|
|
24
|
-
export declare function messageCount(connection: Connection, conversation: string): number;
|
|
23
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
24
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
25
25
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
26
|
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
27
|
export declare function forgottenMessages(connection: Connection): void;
|
package/dist/messages.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAE1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAM3C,CAAC;AAEF,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,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAC;IAC9C,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3E,CAAC;AAMF,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,gBAAgB,EAAE,CAmB5E;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,iBAAiB,GAClD,IAAI,CA+BN;AAkBD,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EACxC,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,aAAa,CAWf;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAOR;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAO/F;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAK9F;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAG9D"}
|
package/dist/messages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sql } from '@agentshouse/mdmodel';
|
|
2
2
|
export const MESSAGE_TABLES = [
|
|
3
3
|
'CREATE TABLE conversation_reads (conversation TEXT PRIMARY KEY, read TEXT, partial INTEGER NOT NULL) WITHOUT ROWID',
|
|
4
4
|
'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)',
|
|
@@ -36,17 +36,12 @@ export function keptMessages(connection, { conversation, messages, read }) {
|
|
|
36
36
|
JSON.stringify(message.message ?? null),
|
|
37
37
|
message.text,
|
|
38
38
|
];
|
|
39
|
-
let id;
|
|
40
39
|
if (held === undefined) {
|
|
41
40
|
connection.run('INSERT INTO conversation_messages (conversation, identity, turn, position, message, text) VALUES (?, ?, ?, ?, ?, ?)', [conversation, message.identity, ...record]);
|
|
42
|
-
id = Number(connection.rows('SELECT last_insert_rowid() AS id')[0].id);
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
|
-
id =
|
|
46
|
-
unindexMessages(connection, [id]);
|
|
47
|
-
connection.run('UPDATE conversation_messages SET turn = ?, position = ?, message = ?, text = ? WHERE id = ?', [...record, id]);
|
|
43
|
+
connection.run('UPDATE conversation_messages SET turn = ?, position = ?, message = ?, text = ? WHERE id = ?', [...record, held.id]);
|
|
48
44
|
}
|
|
49
|
-
indexMessage(connection, id, message.text);
|
|
50
45
|
}
|
|
51
46
|
if (read !== undefined) {
|
|
52
47
|
connection.run('INSERT OR REPLACE INTO conversation_reads (conversation, read, partial) VALUES (?, ?, ?)', [conversation, read.at, read.partial ? 1 : 0]);
|
|
@@ -62,14 +57,21 @@ function accepted(row) {
|
|
|
62
57
|
message: JSON.parse(text(row.message)),
|
|
63
58
|
};
|
|
64
59
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
?
|
|
68
|
-
:
|
|
60
|
+
function holding(phrase) {
|
|
61
|
+
return phrase === null
|
|
62
|
+
? { sql: '', bind: [] }
|
|
63
|
+
: { sql: ` AND ${sql.HOLDS_PHRASE}(text, ?)`, bind: [phrase.toLowerCase()] };
|
|
64
|
+
}
|
|
65
|
+
export function messageWindow(connection, conversation, limit, before, phrase) {
|
|
66
|
+
const held = holding(phrase);
|
|
67
|
+
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
|
|
68
|
+
? [conversation, ...held.bind, limit + 1]
|
|
69
|
+
: [conversation, ...held.bind, before[0], before[0], before[1], limit + 1]);
|
|
69
70
|
return { messages: rows.slice(0, limit).map(accepted).reverse(), more: rows.length > limit };
|
|
70
71
|
}
|
|
71
|
-
export function messageCount(connection, conversation) {
|
|
72
|
-
const
|
|
72
|
+
export function messageCount(connection, conversation, phrase) {
|
|
73
|
+
const held = holding(phrase);
|
|
74
|
+
const [counted] = connection.rows(`SELECT count(*) AS held FROM conversation_messages WHERE conversation = ?${held.sql}`, [conversation, ...held.bind]);
|
|
73
75
|
return Number(counted?.held ?? 0);
|
|
74
76
|
}
|
|
75
77
|
export function turnArrived(connection, conversation, turn) {
|
|
@@ -77,9 +79,6 @@ export function turnArrived(connection, conversation, turn) {
|
|
|
77
79
|
}
|
|
78
80
|
export function droppedMessages(connection, conversations) {
|
|
79
81
|
for (const conversation of conversations) {
|
|
80
|
-
unindexMessages(connection, connection
|
|
81
|
-
.rows('SELECT id FROM conversation_messages WHERE conversation = ?', [conversation])
|
|
82
|
-
.map((row) => Number(row.id)));
|
|
83
82
|
connection.run('DELETE FROM conversation_messages WHERE conversation = ?', [conversation]);
|
|
84
83
|
connection.run('DELETE FROM conversation_reads WHERE conversation = ?', [conversation]);
|
|
85
84
|
}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Definition,
|
|
1
|
+
import type { Definition, VerifiedModel } from '@agentshouse/mdmodel';
|
|
2
2
|
import type { Open } from './open.js';
|
|
3
3
|
export type ModelIdentity = {
|
|
4
4
|
identity: string;
|
|
@@ -8,7 +8,7 @@ export type ModelSnapshot = ModelIdentity & {
|
|
|
8
8
|
schema: string | null;
|
|
9
9
|
revision: string | null;
|
|
10
10
|
};
|
|
11
|
-
export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired'
|
|
11
|
+
export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired'>;
|
|
12
12
|
export type ModelResult = {
|
|
13
13
|
kind: 'model';
|
|
14
14
|
snapshot: ModelSnapshot;
|
|
@@ -20,20 +20,21 @@ export type MdType = Definition;
|
|
|
20
20
|
export type ModelState = {
|
|
21
21
|
status: 'unavailable';
|
|
22
22
|
reason: ModelUnavailableReason;
|
|
23
|
-
schema?: string | null;
|
|
24
|
-
revision?: string | null;
|
|
25
23
|
} | {
|
|
26
24
|
status: 'current' | 'cached';
|
|
27
25
|
snapshot: ModelSnapshot;
|
|
28
26
|
verifiedWith: ModelIdentity;
|
|
29
27
|
types: VerifiedModel['types'];
|
|
30
28
|
};
|
|
29
|
+
export type StoredModel = Extract<ModelState, {
|
|
30
|
+
status: 'unavailable';
|
|
31
|
+
}> | Omit<Extract<ModelState, {
|
|
32
|
+
status: 'current' | 'cached';
|
|
33
|
+
}>, 'types'>;
|
|
31
34
|
export type TypesResult = {
|
|
32
35
|
status: Open<'unavailable'>;
|
|
33
36
|
reason: ModelUnavailableReason;
|
|
34
37
|
types: null;
|
|
35
|
-
schema?: string | null;
|
|
36
|
-
revision?: string | null;
|
|
37
38
|
} | {
|
|
38
39
|
status: Open<'current' | 'cached'>;
|
|
39
40
|
identity: string;
|
|
@@ -51,8 +52,7 @@ export type ValidationReceipt = {
|
|
|
51
52
|
export declare const NO_MODEL: ModelState;
|
|
52
53
|
export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
|
|
53
54
|
export declare function modelTypes(state: ModelState): TypesResult;
|
|
55
|
+
export declare function storedModel(state: ModelState): StoredModel;
|
|
54
56
|
export declare function cached(state: ModelState): ModelState;
|
|
55
57
|
export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
|
|
56
|
-
export declare function sameTyping(left: ModelState, right: ModelState): boolean;
|
|
57
|
-
export declare function referenceField(facts: ValueFacts | undefined): boolean;
|
|
58
58
|
//# sourceMappingURL=model.d.ts.map
|