@agentshouse/mdruntime 0.1.0-cf08ada271a7f → 0.1.0-cf0c43fc48aad
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 +12 -12
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +25 -35
- 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 +116 -65
- package/dist/adapter.d.ts +11 -4
- package/dist/adapter.d.ts.map +1 -1
- package/dist/client.d.ts +6 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +26 -11
- package/dist/compile.d.ts +2 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +17 -4
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +15 -10
- package/dist/conversation-live.d.ts +7 -2
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +6 -3
- package/dist/conversation.d.ts +25 -5
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +157 -76
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +18 -45
- package/dist/durability.d.ts +3 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.js +1 -1
- 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 +3 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +29 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/install.d.ts +2 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +9 -22
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +32 -26
- package/dist/listing.d.ts +4 -9
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +21 -51
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +8 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +7 -19
- package/dist/media.js +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +36 -17
- package/dist/messages.d.ts +9 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +20 -10
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +15 -32
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +3 -9
- package/dist/outcome.d.ts +3 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +15 -0
- package/dist/overlay.d.ts +3 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +8 -4
- 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 +2 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +6 -14
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +15 -21
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +23 -13
- package/dist/questions.d.ts +0 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +0 -7
- package/dist/queue.d.ts +2 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +26 -31
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +62 -18
- package/dist/react.d.ts +5 -4
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/reads.d.ts +3 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +5 -1
- package/dist/recovery.d.ts +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +29 -7
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -4
- 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 +2 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +24 -19
- package/dist/runtime.d.ts +4 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -55
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +8 -11
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +2 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +14 -23
- 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.d.ts +3 -5
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +3 -14
- package/dist/source.d.ts +0 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/store/records.d.ts +7 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +12 -2
- package/dist/store.d.ts +10 -5
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +37 -12
- package/dist/stored.d.ts +1 -0
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +5 -5
- package/dist/surface.d.ts +1 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +9 -13
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +63 -58
- package/dist/tables.d.ts +6 -3
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +34 -10
- package/dist/wire.d.ts +47 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +12 -1
- package/package.json +3 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- 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/lifecycle.js
CHANGED
|
@@ -9,6 +9,7 @@ import { refuse } from './refusal.js';
|
|
|
9
9
|
import { moveTo, recoverReads, rest, SERVICE_MODE_TOPIC, show, submissionDue, transferring, } from './shown.js';
|
|
10
10
|
import { applyRoom, changeAuthority, countAuthorityChange, finishOpening, loadRoom, OPENING_LANE, reload, resynchronize, sync, } from './sync.js';
|
|
11
11
|
const CONVERSATION_LANE = 'conversations';
|
|
12
|
+
const RELOADING = 'reloading';
|
|
12
13
|
function closing(runtime, opened) {
|
|
13
14
|
const { store, socket } = runtime;
|
|
14
15
|
return socket.lanes.task(OPENING_LANE, async (live) => {
|
|
@@ -21,10 +22,10 @@ function closing(runtime, opened) {
|
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
function closedSocket(runtime, lapsed, lost, opened) {
|
|
24
|
-
const { socket, conversations } = runtime;
|
|
25
|
+
const { socket, presence, conversations } = runtime;
|
|
25
26
|
const { session } = socket;
|
|
26
27
|
socket.notifyReady();
|
|
27
|
-
|
|
28
|
+
presence.stopAsking();
|
|
28
29
|
connectionLost(runtime);
|
|
29
30
|
if (lost)
|
|
30
31
|
conversations.lost();
|
|
@@ -44,9 +45,9 @@ function closedSocket(runtime, lapsed, lost, opened) {
|
|
|
44
45
|
void closing(runtime, opened);
|
|
45
46
|
}
|
|
46
47
|
function owedReloads(runtime, expired, held) {
|
|
47
|
-
const { store,
|
|
48
|
-
const reloading =
|
|
49
|
-
.
|
|
48
|
+
const { store, presence } = runtime;
|
|
49
|
+
const reloading = presence
|
|
50
|
+
.rooms()
|
|
50
51
|
.filter((room) => !expired.includes(room.locator) && revoked(held.get(room.locator)?.record.model))
|
|
51
52
|
.map((room) => room.locator);
|
|
52
53
|
for (const locator of reloading)
|
|
@@ -55,15 +56,15 @@ function owedReloads(runtime, expired, held) {
|
|
|
55
56
|
return reloading;
|
|
56
57
|
}
|
|
57
58
|
async function reloadNow(runtime, replacing, progress, held, installing) {
|
|
58
|
-
const { store, socket } = runtime;
|
|
59
|
-
const {
|
|
60
|
-
const discovered = rooms
|
|
59
|
+
const { store, socket, presence } = runtime;
|
|
60
|
+
const { lanes } = socket;
|
|
61
|
+
const discovered = presence.rooms();
|
|
61
62
|
const reloaded = discovered.filter((room) => held.has(room.locator) && !installing.has(room.locator) && replacing(room));
|
|
62
63
|
const acquired = discovered.filter((room) => (!held.has(room.locator) || installing.has(room.locator)) &&
|
|
63
64
|
room.replica.admission === 'admitted' &&
|
|
64
65
|
replacing(room));
|
|
65
66
|
for (const room of reloaded)
|
|
66
|
-
|
|
67
|
+
presence.reload(room.locator, true);
|
|
67
68
|
try {
|
|
68
69
|
const local = await store.open();
|
|
69
70
|
const kept = acquired.length === 0 ? new Set() : (await local.held()).staged;
|
|
@@ -78,15 +79,17 @@ async function reloadNow(runtime, replacing, progress, held, installing) {
|
|
|
78
79
|
.roomTask(room.locator, (live) => loadRoom(runtime, room, local, progress, live, unheld))
|
|
79
80
|
.then(() => rest(runtime, progress));
|
|
80
81
|
}
|
|
82
|
+
runtime.retries.succeeded('download', RELOADING);
|
|
81
83
|
}
|
|
82
|
-
catch {
|
|
84
|
+
catch (error) {
|
|
85
|
+
runtime.retries.failed('download', RELOADING, error);
|
|
83
86
|
for (const room of reloaded)
|
|
84
|
-
|
|
87
|
+
presence.reload(room.locator, false);
|
|
85
88
|
progress.reachable = false;
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
function caughtUpRooms(runtime, expired) {
|
|
89
|
-
const { store, socket } = runtime;
|
|
92
|
+
const { store, socket, presence } = runtime;
|
|
90
93
|
const { session } = socket;
|
|
91
94
|
const progress = session.now().underway;
|
|
92
95
|
session.set({ underway: null });
|
|
@@ -113,15 +116,17 @@ function caughtUpRooms(runtime, expired) {
|
|
|
113
116
|
if (progress.reachable) {
|
|
114
117
|
const stored = await held;
|
|
115
118
|
const owed = await reloading;
|
|
116
|
-
await settleModels(runtime, new Map(
|
|
117
|
-
.
|
|
119
|
+
await settleModels(runtime, new Map(presence
|
|
120
|
+
.rooms()
|
|
118
121
|
.filter((room) => stored.has(room.locator) &&
|
|
119
122
|
!expired.includes(room.locator) &&
|
|
120
123
|
!owed.includes(room.locator))
|
|
121
124
|
.map((room) => [room.locator, declared(room)])), 'current', local);
|
|
122
125
|
}
|
|
126
|
+
runtime.retries.succeeded('download', OPENING_LANE);
|
|
123
127
|
}
|
|
124
|
-
catch {
|
|
128
|
+
catch (error) {
|
|
129
|
+
runtime.retries.failed('download', OPENING_LANE, error);
|
|
125
130
|
progress.complete = false;
|
|
126
131
|
progress.reachable = false;
|
|
127
132
|
}
|
|
@@ -130,7 +135,7 @@ function caughtUpRooms(runtime, expired) {
|
|
|
130
135
|
});
|
|
131
136
|
}
|
|
132
137
|
function signalled(runtime, mode) {
|
|
133
|
-
const { store, socket
|
|
138
|
+
const { store, socket } = runtime;
|
|
134
139
|
const { session } = socket;
|
|
135
140
|
const { closed, serviceMode, haltedRefusal, openSignals } = session.now();
|
|
136
141
|
if (closed)
|
|
@@ -143,7 +148,6 @@ function signalled(runtime, mode) {
|
|
|
143
148
|
if (mode !== serviceMode) {
|
|
144
149
|
session.set({ serviceMode: mode });
|
|
145
150
|
store.readiness.queue();
|
|
146
|
-
journal.record(`service mode ${mode}`);
|
|
147
151
|
store.tell(SERVICE_MODE_TOPIC, mode);
|
|
148
152
|
}
|
|
149
153
|
if (releasing)
|
|
@@ -168,8 +172,10 @@ async function runCurrency(runtime, live) {
|
|
|
168
172
|
moveTo(runtime, transferring(runtime));
|
|
169
173
|
try {
|
|
170
174
|
await catchUpConversations(conversations, progress);
|
|
175
|
+
runtime.retries.succeeded('conversations', CONVERSATION_LANE);
|
|
171
176
|
}
|
|
172
|
-
catch {
|
|
177
|
+
catch (error) {
|
|
178
|
+
runtime.retries.failed('conversations', CONVERSATION_LANE, error);
|
|
173
179
|
progress.reachable = false;
|
|
174
180
|
}
|
|
175
181
|
await rest(runtime, progress, live);
|
|
@@ -183,9 +189,8 @@ export function scheduleCurrency(runtime) {
|
|
|
183
189
|
void socket.lanes.task(CONVERSATION_LANE, (live) => runCurrency(runtime, live));
|
|
184
190
|
}
|
|
185
191
|
export function spaceFreed(runtime) {
|
|
186
|
-
const { store, socket
|
|
187
|
-
|
|
188
|
-
journal.record('space freed');
|
|
192
|
+
const { store, socket } = runtime;
|
|
193
|
+
store.prepareAgain();
|
|
189
194
|
store.readiness.queue();
|
|
190
195
|
const { closed, authorization } = socket.session.now();
|
|
191
196
|
if (closed || authorization === undefined)
|
|
@@ -195,10 +200,11 @@ export function spaceFreed(runtime) {
|
|
|
195
200
|
else
|
|
196
201
|
void resynchronize(runtime);
|
|
197
202
|
}
|
|
198
|
-
export function close({ store, socket, conversations, recovery, liveQueries, figures }) {
|
|
203
|
+
export function close({ store, socket, presence, conversations, recovery, liveQueries, figures, }) {
|
|
199
204
|
if (socket.closed())
|
|
200
205
|
return;
|
|
201
206
|
socket.close();
|
|
207
|
+
presence.close();
|
|
202
208
|
conversations.close();
|
|
203
209
|
void recovery.retire();
|
|
204
210
|
liveQueries.close();
|
|
@@ -206,9 +212,9 @@ export function close({ store, socket, conversations, recovery, liveQueries, fig
|
|
|
206
212
|
store.close();
|
|
207
213
|
}
|
|
208
214
|
export async function stop(runtime) {
|
|
209
|
-
const { store, socket, recovery } = runtime;
|
|
215
|
+
const { store, socket, presence, recovery } = runtime;
|
|
210
216
|
socket.session.set({ stopping: true });
|
|
211
|
-
|
|
217
|
+
presence.stopAsking();
|
|
212
218
|
socket.stopReads();
|
|
213
219
|
await recovery.retire();
|
|
214
220
|
await socket.lanes.finished();
|
|
@@ -216,7 +222,7 @@ export async function stop(runtime) {
|
|
|
216
222
|
close(runtime);
|
|
217
223
|
}
|
|
218
224
|
export function start(runtime, signal) {
|
|
219
|
-
const { store, socket, conversations, lastAnswers, recovery } = runtime;
|
|
225
|
+
const { store, socket, presence, conversations, lastAnswers, recovery } = runtime;
|
|
220
226
|
const closeRuntime = () => close(runtime);
|
|
221
227
|
socket.observeServiceMode((mode) => signalled(runtime, mode));
|
|
222
228
|
socket.observeConversations((event) => {
|
|
@@ -233,7 +239,7 @@ export function start(runtime, signal) {
|
|
|
233
239
|
closeRuntime();
|
|
234
240
|
socket.observe((event) => {
|
|
235
241
|
if (event.kind === 'opened') {
|
|
236
|
-
|
|
242
|
+
presence.connectionLive();
|
|
237
243
|
conversations.reopened();
|
|
238
244
|
lastAnswers.reopened();
|
|
239
245
|
recovery.resume();
|
package/dist/listing.d.ts
CHANGED
|
@@ -31,22 +31,17 @@ type ListedEntry = ListedRoom & {
|
|
|
31
31
|
readonly documents: number;
|
|
32
32
|
};
|
|
33
33
|
export type Listing = ReadonlyMap<string, ListedEntry>;
|
|
34
|
-
export declare function modelIn({ socket }: Runtime, locator: string, stored: Stored | undefined): ModelState;
|
|
34
|
+
export declare function modelIn({ socket, presence }: Runtime, locator: string, stored: Stored | undefined): ModelState;
|
|
35
35
|
export declare function compositionFor(runtime: Runtime, record: ReplicaRecord): Composition;
|
|
36
|
-
export declare function declarationOf({
|
|
36
|
+
export declare function declarationOf({ presence }: Runtime, locator: string, stored: Stored | undefined): {
|
|
37
37
|
readonly room: RoomDeclaration;
|
|
38
38
|
readonly available: boolean;
|
|
39
39
|
} | undefined;
|
|
40
|
-
export declare function listedLocators({
|
|
40
|
+
export declare function listedLocators({ presence }: Runtime, held: ReadonlyMap<string, unknown>): string[];
|
|
41
41
|
export declare function patchedListing(runtime: Runtime, changed: ReadonlySet<string>): Promise<Listing | null>;
|
|
42
42
|
export declare function listingNow(runtime: Runtime): Promise<Listing>;
|
|
43
|
-
export declare function shownRooms(
|
|
43
|
+
export declare function shownRooms({ presence }: Runtime, listing: Listing): readonly AppRoom[];
|
|
44
44
|
export declare function roomFacts(runtime: Runtime, reach?: PortReach | null): Promise<HeldRooms>;
|
|
45
|
-
export declare function list({ store, socket }: Runtime, locator: string, declaration: RoomDeclaration, synchronizationAvailable: boolean): void;
|
|
46
|
-
export declare function listHeld({ store, socket }: Runtime, locator: string): void;
|
|
47
|
-
export declare function admitted({ socket }: Runtime, locator: string, declaration: RoomDeclaration): boolean;
|
|
48
|
-
export declare function readable(runtime: Runtime, room: DiscoveredRoom): void;
|
|
49
|
-
export declare function usable(runtime: Runtime, room: DiscoveredRoom): void;
|
|
50
45
|
export declare function heldRooms({ store }: Runtime, listed: readonly DiscoveredRoom[]): Promise<HeldRoom[]>;
|
|
51
46
|
export declare function name(runtime: Runtime, locator: string): Promise<void>;
|
|
52
47
|
export {};
|
package/dist/listing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listing.d.ts","sourceRoot":"","sources":["../src/listing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EACV,cAAc,EACd,QAAQ,EACR,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAwB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,M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AE,MAAM,iBAO3D"}
|
package/dist/listing.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { declared } from './declaration.js';
|
|
2
2
|
import { modelTypes, NO_MODEL } from './model.js';
|
|
3
3
|
import { governs, holds } from './reach.js';
|
|
4
|
-
export function modelIn({ socket }, locator, stored) {
|
|
4
|
+
export function modelIn({ socket, presence }, locator, stored) {
|
|
5
5
|
if (socket.session.now().refusal?.code === 'revoked-authorization')
|
|
6
6
|
return { status: 'unavailable', reason: 'revoked' };
|
|
7
|
-
return stored?.record.model ??
|
|
7
|
+
return stored?.record.model ?? presence.unheldModel(locator) ?? NO_MODEL;
|
|
8
8
|
}
|
|
9
9
|
export function compositionFor(runtime, record) {
|
|
10
10
|
return runtime.store.composed({
|
|
@@ -12,20 +12,19 @@ export function compositionFor(runtime, record) {
|
|
|
12
12
|
model: modelIn(runtime, record.locator, { record, indexed: true, documents: 0 }),
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
export function declarationOf({
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
export function declarationOf({ presence }, locator, stored) {
|
|
16
|
+
const listed = presence.room(locator);
|
|
17
|
+
const room = stored?.record.declaration ?? (listed === undefined ? undefined : declared(listed));
|
|
18
|
+
if (room === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
return {
|
|
21
|
+
room,
|
|
22
|
+
available: presence.available(locator, stored?.record.declaration.replica.selection),
|
|
23
|
+
};
|
|
22
24
|
}
|
|
23
|
-
export function listedLocators({
|
|
24
|
-
const
|
|
25
|
-
return [
|
|
26
|
-
...declared.keys(),
|
|
27
|
-
...[...held.keys()].filter((locator) => !declared.has(locator)),
|
|
28
|
-
].filter((locator) => !store.fences.has(locator));
|
|
25
|
+
export function listedLocators({ presence }, held) {
|
|
26
|
+
const listed = presence.rooms().map(({ locator }) => locator);
|
|
27
|
+
return [...new Set([...listed, ...held.keys()])];
|
|
29
28
|
}
|
|
30
29
|
function selectionModel({ socket, builtIn }) {
|
|
31
30
|
return socket.session.now().refusal?.code === 'revoked-authorization'
|
|
@@ -52,7 +51,7 @@ function listedRoom(runtime, locator, stored) {
|
|
|
52
51
|
authoredPaths: room.authoredPaths,
|
|
53
52
|
roomVersion: stored?.record.roomVersion ?? null,
|
|
54
53
|
synchronizationAvailable: available,
|
|
55
|
-
refusal: runtime.
|
|
54
|
+
refusal: runtime.presence.refusal(locator),
|
|
56
55
|
documents: stored?.documents ?? 0,
|
|
57
56
|
};
|
|
58
57
|
}
|
|
@@ -73,9 +72,7 @@ export async function patchedListing(runtime, changed) {
|
|
|
73
72
|
const held = await store.rooms([...changed]);
|
|
74
73
|
const listing = new Map(roomsShown);
|
|
75
74
|
for (const locator of changed) {
|
|
76
|
-
const room =
|
|
77
|
-
? undefined
|
|
78
|
-
: listedRoom(runtime, locator, held.get(locator));
|
|
75
|
+
const room = listedRoom(runtime, locator, held.get(locator));
|
|
79
76
|
if (room === undefined || !listing.has(locator))
|
|
80
77
|
return null;
|
|
81
78
|
listing.set(locator, room);
|
|
@@ -85,11 +82,9 @@ export async function patchedListing(runtime, changed) {
|
|
|
85
82
|
export async function listingNow(runtime) {
|
|
86
83
|
return listingOf(runtime, await runtime.store.rooms());
|
|
87
84
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
export function shownRooms(runtime, listing) {
|
|
92
|
-
return structuredClone([...listing.values()].map(({ documents, ...room }) => lockedIn(runtime, listing, room.locator)
|
|
85
|
+
export function shownRooms({ presence }, listing) {
|
|
86
|
+
const locked = new Set(presence.lockedAmong(new Map([...listing].map(([locator, room]) => [locator, room.replica.offline]))));
|
|
87
|
+
return structuredClone([...listing.values()].map(({ documents, ...room }) => locked.has(room.locator)
|
|
93
88
|
? {
|
|
94
89
|
...room,
|
|
95
90
|
model: modelTypes(NO_MODEL),
|
|
@@ -118,31 +113,6 @@ export async function roomFacts(runtime, reach = null) {
|
|
|
118
113
|
});
|
|
119
114
|
return { listed: socket.session.now().roomsListed, rooms };
|
|
120
115
|
}
|
|
121
|
-
export function list({ store, socket }, locator, declaration, synchronizationAvailable) {
|
|
122
|
-
if (store.fences.has(locator))
|
|
123
|
-
return;
|
|
124
|
-
socket.rooms.declare(locator, { room: declaration, available: synchronizationAvailable });
|
|
125
|
-
}
|
|
126
|
-
export function listHeld({ store, socket }, locator) {
|
|
127
|
-
if (store.fences.has(locator))
|
|
128
|
-
return;
|
|
129
|
-
socket.rooms.declare(locator, { room: null, available: false });
|
|
130
|
-
}
|
|
131
|
-
export function admitted({ socket }, locator, declaration) {
|
|
132
|
-
return declaration.replica.admission === 'admitted' && !socket.rooms.standing(locator).unreadable;
|
|
133
|
-
}
|
|
134
|
-
export function readable(runtime, room) {
|
|
135
|
-
runtime.socket.rooms.stand(room.locator, { unreadable: false });
|
|
136
|
-
list(runtime, room.locator, declared(room), true);
|
|
137
|
-
}
|
|
138
|
-
export function usable(runtime, room) {
|
|
139
|
-
const { rooms } = runtime.socket;
|
|
140
|
-
rooms.stand(room.locator, { stale: false, unpreparable: false });
|
|
141
|
-
if (rooms.standing(room.locator).unreadable) {
|
|
142
|
-
rooms.stand(room.locator, { unreadable: false, refusal: null });
|
|
143
|
-
}
|
|
144
|
-
list(runtime, room.locator, declared(room), true);
|
|
145
|
-
}
|
|
146
116
|
export async function heldRooms({ store }, listed) {
|
|
147
117
|
const stored = await store.rooms(listed.map((room) => room.locator));
|
|
148
118
|
return listed.flatMap((room) => {
|
|
@@ -158,8 +128,8 @@ export async function heldRooms({ store }, listed) {
|
|
|
158
128
|
});
|
|
159
129
|
}
|
|
160
130
|
export async function name(runtime, locator) {
|
|
161
|
-
const { socket } = runtime;
|
|
162
|
-
const room =
|
|
131
|
+
const { socket, presence } = runtime;
|
|
132
|
+
const room = presence.room(locator);
|
|
163
133
|
if (!socket.streamed || room === undefined || !socket.isOpen() || !socket.isHanded())
|
|
164
134
|
return;
|
|
165
135
|
const [held] = await heldRooms(runtime, [room]);
|
package/dist/locks.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { DiscoveredRoom } from './adapter.js';
|
|
2
1
|
import type { Runtime } from './runtime.js';
|
|
3
|
-
export declare function locked({ store,
|
|
4
|
-
export declare function lockedRooms(
|
|
2
|
+
export declare function locked({ store, presence }: Runtime, locator: string): Promise<boolean>;
|
|
3
|
+
export declare function lockedRooms({ store, presence }: Runtime): Promise<readonly string[]>;
|
|
5
4
|
export declare function relocked(runtime: Runtime, before: readonly string[]): Promise<void>;
|
|
6
|
-
export declare function confirmLocks({ socket }: Runtime, listed: readonly DiscoveredRoom[]): void;
|
|
7
5
|
export declare function connectionLost(runtime: Runtime): void;
|
|
8
6
|
export declare function watchLocks({ store }: Runtime, notify: () => void): () => void;
|
|
9
7
|
//# sourceMappingURL=locks.d.ts.map
|
package/dist/locks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAE5F;AAED,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAK1F;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAKzE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,QAU9C;AAED,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAE7E"}
|
package/dist/locks.js
CHANGED
|
@@ -1,58 +1,28 @@
|
|
|
1
1
|
import { uncaught } from './failure.js';
|
|
2
2
|
import { emitRooms, LOCKS_TOPIC } from './shown.js';
|
|
3
|
-
async function
|
|
4
|
-
|
|
5
|
-
for (const [locator, { room }] of socket.rooms.declarations()) {
|
|
6
|
-
const declaration = room ?? socket.rooms.discovered(locator);
|
|
7
|
-
if (declaration !== undefined)
|
|
8
|
-
modes.set(locator, declaration.replica.offline);
|
|
9
|
-
}
|
|
10
|
-
for (const [locator, { offline }] of (await store.covering()).rooms)
|
|
11
|
-
modes.set(locator, offline);
|
|
12
|
-
return modes;
|
|
3
|
+
export async function locked({ store, presence }, locator) {
|
|
4
|
+
return presence.locked(locator, async () => (await store.open()).offline(locator));
|
|
13
5
|
}
|
|
14
|
-
export async function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const held = socket.rooms.declared(locator)?.room ?? socket.rooms.discovered(locator);
|
|
18
|
-
const mode = (await (await store.open()).offline(locator)) ?? held?.replica.offline;
|
|
19
|
-
return mode === 'locked';
|
|
20
|
-
}
|
|
21
|
-
export async function lockedRooms(runtime) {
|
|
22
|
-
const { store, socket } = runtime;
|
|
23
|
-
return [...(await offlineModes(runtime))]
|
|
24
|
-
.filter(([locator, mode]) => mode === 'locked' &&
|
|
25
|
-
!socket.rooms.standing(locator).confirmed &&
|
|
26
|
-
!store.fences.has(locator))
|
|
27
|
-
.map(([locator]) => locator)
|
|
28
|
-
.sort();
|
|
6
|
+
export async function lockedRooms({ store, presence }) {
|
|
7
|
+
const held = (await store.covering()).rooms;
|
|
8
|
+
return presence.lockedAmong(new Map([...held].map(([locator, { offline }]) => [locator, offline])));
|
|
29
9
|
}
|
|
30
10
|
export async function relocked(runtime, before) {
|
|
31
11
|
const after = await lockedRooms(runtime);
|
|
32
12
|
if (JSON.stringify(after) === JSON.stringify(before))
|
|
33
13
|
return;
|
|
34
|
-
runtime.journal.record(`locked ${after.length}`);
|
|
35
14
|
emitRooms(runtime);
|
|
36
15
|
runtime.store.tell(LOCKS_TOPIC, undefined);
|
|
37
16
|
}
|
|
38
|
-
export function confirmLocks({ socket }, listed) {
|
|
39
|
-
if (!socket.isOpen())
|
|
40
|
-
return;
|
|
41
|
-
for (const room of listed) {
|
|
42
|
-
if (room.replica.admission === 'admitted') {
|
|
43
|
-
socket.rooms.stand(room.locator, { confirmed: true });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
17
|
export function connectionLost(runtime) {
|
|
48
|
-
const { socket } = runtime;
|
|
18
|
+
const { socket, presence } = runtime;
|
|
49
19
|
if (socket.closed())
|
|
50
20
|
return;
|
|
51
|
-
|
|
21
|
+
presence.connectionLost(() => {
|
|
52
22
|
if (socket.isOpen() || socket.closed())
|
|
53
23
|
return;
|
|
54
24
|
void lockedRooms(runtime).then((before) => {
|
|
55
|
-
|
|
25
|
+
presence.lapse();
|
|
56
26
|
return relocked(runtime, before);
|
|
57
27
|
}, uncaught);
|
|
58
28
|
});
|
package/dist/lost.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,wBAAsB,WAAW,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAIhF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,QAMtE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBA+B5E"}
|
package/dist/lost.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
|
-
import { ERASE_BATCH
|
|
2
|
+
import { ERASE_BATCH } from './install.js';
|
|
3
3
|
import { unpair } from './queue.js';
|
|
4
4
|
import { recoverReads } from './shown.js';
|
|
5
5
|
import { yielded } from './turn.js';
|
|
6
|
-
function forget({ store, socket }, locator) {
|
|
7
|
-
forgetInstall(store, locator);
|
|
8
|
-
socket.rooms.forget(locator);
|
|
9
|
-
store.forget(locator);
|
|
10
|
-
}
|
|
11
6
|
export async function eraseFenced({ store }, locators) {
|
|
12
7
|
for (const locator of locators) {
|
|
13
8
|
while (await store.durably((local) => local.erase(locator, ERASE_BATCH)))
|
|
@@ -15,24 +10,17 @@ export async function eraseFenced({ store }, locators) {
|
|
|
15
10
|
}
|
|
16
11
|
}
|
|
17
12
|
export function fenceLive(runtime, locators) {
|
|
18
|
-
const { store, socket,
|
|
13
|
+
const { store, socket, presence } = runtime;
|
|
19
14
|
for (const locator of new Set(locators)) {
|
|
20
|
-
if (!
|
|
15
|
+
if (!presence.lose(locator, socket.session.now().discoveries))
|
|
21
16
|
continue;
|
|
22
|
-
forget(
|
|
23
|
-
journal.record(`room lost ${locator}`);
|
|
17
|
+
store.forget(locator);
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
export async function loseRooms(runtime, locators) {
|
|
27
|
-
const { store } = runtime;
|
|
21
|
+
const { store, presence } = runtime;
|
|
28
22
|
fenceLive(runtime, locators);
|
|
29
|
-
const fresh = [...new Set(locators)].filter((locator) =>
|
|
30
|
-
const fence = store.fences.of(locator);
|
|
31
|
-
if (fence === undefined || fence.written)
|
|
32
|
-
return false;
|
|
33
|
-
store.fences.mark(locator, true);
|
|
34
|
-
return true;
|
|
35
|
-
});
|
|
23
|
+
const fresh = [...new Set(locators)].filter((locator) => presence.writing(locator));
|
|
36
24
|
if (fresh.length === 0)
|
|
37
25
|
return;
|
|
38
26
|
let held = [];
|
|
@@ -44,7 +32,7 @@ export async function loseRooms(runtime, locators) {
|
|
|
44
32
|
}
|
|
45
33
|
catch (error) {
|
|
46
34
|
for (const locator of fresh)
|
|
47
|
-
|
|
35
|
+
presence.unwritten(locator);
|
|
48
36
|
throw error;
|
|
49
37
|
}
|
|
50
38
|
finally {
|
package/dist/media.js
CHANGED
|
@@ -179,7 +179,7 @@ export function defineRoomMedia(client) {
|
|
|
179
179
|
if (drawn instanceof HTMLMediaElement) {
|
|
180
180
|
drawn.controls = true;
|
|
181
181
|
drawn.preload = 'metadata';
|
|
182
|
-
if (drawn instanceof HTMLVideoElement)
|
|
182
|
+
if (drawn instanceof HTMLVideoElement && 'playsInline' in drawn)
|
|
183
183
|
drawn.playsInline = true;
|
|
184
184
|
}
|
|
185
185
|
drawn.addEventListener(drawn instanceof HTMLImageElement ? 'load' : 'loadedmetadata', () => {
|
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":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EAMf,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAKtB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EAGf,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,MAAM,EAGX,KAAK,aAAa,EAIlB,KAAK,SAAS,EAGd,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,cAAc,C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QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC1C,iBAAiB,CAAC,YAAY,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChF,sBAAsB,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3D,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnD,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,SAAS,IAAI,SAAS,MAAM,EAAE,CAAC;IAC/B,uBAAuB,IAAI,SAAS,MAAM,EAAE,CAAC;IAC7C,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAAC;CACzC,CAAC;AA0CF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CA2qBrF"}
|
package/dist/memory.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { definitionAt, documentFacts, parse } from '@agentshouse/mdmodel';
|
|
2
|
-
import {
|
|
2
|
+
import { roomTypesOf, schemaTypes } from './attached-model.js';
|
|
3
|
+
import { selected } from './collection.js';
|
|
3
4
|
import { sameChange } from './overlay.js';
|
|
4
5
|
const ATTACHMENTS = 'attachments';
|
|
5
6
|
function lastName(path) {
|
|
@@ -53,7 +54,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
53
54
|
const listeners = new Set();
|
|
54
55
|
const modeObservers = new Set();
|
|
55
56
|
const scripted = new Map();
|
|
56
|
-
const
|
|
57
|
+
const repeats = new Map();
|
|
57
58
|
const historyPageSize = options.historyPageSize;
|
|
58
59
|
const attached = new Map();
|
|
59
60
|
const linked = new WeakMap();
|
|
@@ -104,8 +105,11 @@ export function createMemoryAdapter(options = {}) {
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
const saved = new WeakMap();
|
|
108
|
+
const roomTypes = roomTypesOf(options.roomTypes);
|
|
107
109
|
function factsAt(room, path, content) {
|
|
108
|
-
const types =
|
|
110
|
+
const types = selected({ selection: room.typedSelection ?? null }, path)
|
|
111
|
+
? roomTypes.types
|
|
112
|
+
: schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, roomTypes);
|
|
109
113
|
let held = saved.get(types);
|
|
110
114
|
if (held === undefined) {
|
|
111
115
|
held = new Map();
|
|
@@ -261,16 +265,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
261
265
|
}
|
|
262
266
|
function pageOf(conversation, after) {
|
|
263
267
|
const messages = conversation.messages ?? [];
|
|
264
|
-
const first = typeof after === 'string' ? messages.findIndex((message) => message.
|
|
268
|
+
const first = typeof after === 'string' ? messages.findIndex((message) => message.change > after) : 0;
|
|
265
269
|
const from = first === -1 ? messages.length : first;
|
|
266
270
|
const page = messages.slice(from, from + (historyPageSize ?? messages.length));
|
|
267
271
|
const last = page.at(-1);
|
|
268
272
|
return {
|
|
269
273
|
conversation: conversation.conversation,
|
|
270
274
|
messages: page,
|
|
271
|
-
...(last !== undefined && from + page.length < messages.length
|
|
272
|
-
? { next: last.position }
|
|
273
|
-
: {}),
|
|
275
|
+
...(last !== undefined && from + page.length < messages.length ? { next: last.change } : {}),
|
|
274
276
|
};
|
|
275
277
|
}
|
|
276
278
|
function historiesOf(request) {
|
|
@@ -290,11 +292,20 @@ export function createMemoryAdapter(options = {}) {
|
|
|
290
292
|
function conversationAction(request) {
|
|
291
293
|
const name = request.name;
|
|
292
294
|
const input = (request.input ?? {});
|
|
295
|
+
const operation = typeof input.operation_id === 'string' ? `${name}\u0000${input.operation_id}` : null;
|
|
296
|
+
const first = (answer) => {
|
|
297
|
+
if (operation !== null)
|
|
298
|
+
repeats.set(operation, answer);
|
|
299
|
+
return answer;
|
|
300
|
+
};
|
|
301
|
+
const repeated = operation === null ? undefined : repeats.get(operation);
|
|
293
302
|
if (name === 'conversations/create') {
|
|
303
|
+
if (repeated !== undefined)
|
|
304
|
+
return repeated;
|
|
294
305
|
issued += 1;
|
|
295
306
|
const conversation = `conversation-${issued}`;
|
|
296
307
|
scripted.set(conversation, { conversation });
|
|
297
|
-
return { kind: 'action', result: { conversation_id: conversation } };
|
|
308
|
+
return first({ kind: 'action', result: { conversation_id: conversation } });
|
|
298
309
|
}
|
|
299
310
|
const named = typeof input.conversation_id === 'string' ? input.conversation_id : '';
|
|
300
311
|
const conversation = scripted.get(named);
|
|
@@ -310,24 +321,30 @@ export function createMemoryAdapter(options = {}) {
|
|
|
310
321
|
if (outcome !== undefined)
|
|
311
322
|
return outcome;
|
|
312
323
|
if (name === 'conversations/send') {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (answered !== undefined)
|
|
316
|
-
return { kind: 'action', result: { message_id: answered } };
|
|
324
|
+
if (repeated !== undefined)
|
|
325
|
+
return repeated;
|
|
317
326
|
issued += 1;
|
|
318
|
-
|
|
319
|
-
if (operation !== null)
|
|
320
|
-
sentTurns.set(operation, turn);
|
|
321
|
-
return { kind: 'action', result: { message_id: turn } };
|
|
327
|
+
return first({ kind: 'action', result: { message_id: `turn-${issued}` } });
|
|
322
328
|
}
|
|
323
329
|
if (name === 'conversations/delete')
|
|
324
330
|
scripted.delete(named);
|
|
325
331
|
return { kind: 'action', result: { conversation_id: named } };
|
|
326
332
|
}
|
|
333
|
+
function decided(request) {
|
|
334
|
+
const { request: asked, message, decision, } = (request.input ?? {});
|
|
335
|
+
return {
|
|
336
|
+
kind: 'action',
|
|
337
|
+
result: {
|
|
338
|
+
request: asked,
|
|
339
|
+
...(message === undefined ? {} : { message }),
|
|
340
|
+
state: decision === 'approve' ? 'started' : 'declined',
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
327
344
|
function announceList() {
|
|
328
345
|
const entries = [...scripted.values()].flatMap(({ conversation, listed, messages = [] }) => listed === undefined
|
|
329
346
|
? []
|
|
330
|
-
: [{ conversation, ...listed, newest: messages.at(-1)?.
|
|
347
|
+
: [{ conversation, ...listed, newest: messages.at(-1)?.change ?? null }]);
|
|
331
348
|
for (const listener of listeners) {
|
|
332
349
|
listener({ kind: 'list', entries, whole: true, more: false, cursor: null });
|
|
333
350
|
}
|
|
@@ -633,6 +650,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
633
650
|
return resolveScript(scripts.action, () => {
|
|
634
651
|
if (request.name.startsWith('conversations/'))
|
|
635
652
|
return conversationAction(request);
|
|
653
|
+
if (request.name === 'agent-functions/decide')
|
|
654
|
+
return decided(request);
|
|
636
655
|
return { kind: 'rejected', code: 'unscripted-action', fields: {}, retryable: false };
|
|
637
656
|
}, request).then((answer) => {
|
|
638
657
|
if (answer.kind === 'action' && answer.at !== undefined)
|