@agentshouse/mdruntime 0.1.0-c0ffc146f48dd → 0.1.0-c112fd663ab59
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 +10 -10
- package/dist/acceptance.d.ts +6 -0
- package/dist/acceptance.d.ts.map +1 -0
- package/dist/acceptance.js +385 -0
- package/dist/actions.d.ts +20 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +251 -0
- package/dist/adapter.d.ts +45 -25
- 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 +21 -56
- package/dist/bootstrap.d.ts +8 -4
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +210 -78
- package/dist/cell.d.ts +6 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +9 -0
- package/dist/chain.d.ts +2 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/chat-types.d.ts +5 -0
- package/dist/chat-types.d.ts.map +1 -0
- package/dist/chat-types.js +13 -0
- package/dist/client.d.ts +22 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7 -2
- package/dist/collection.d.ts +2 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/compile.d.ts +6 -6
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +240 -315
- package/dist/connection.d.ts +5 -142
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +103 -5071
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +7 -0
- package/dist/conversation-live.d.ts +136 -0
- package/dist/conversation-live.d.ts.map +1 -0
- package/dist/conversation-live.js +248 -0
- package/dist/conversation-row.d.ts +33 -0
- package/dist/conversation-row.d.ts.map +1 -0
- package/dist/conversation-row.js +53 -0
- package/dist/conversation.d.ts +34 -38
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +861 -850
- package/dist/discovery.d.ts +10 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +175 -0
- package/dist/durability.d.ts +15 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +2 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +17 -7
- package/dist/expectation.d.ts +4 -2
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +33 -11
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/figures.d.ts +49 -0
- package/dist/figures.d.ts.map +1 -0
- package/dist/figures.js +197 -0
- package/dist/holdings.d.ts +29 -0
- package/dist/holdings.d.ts.map +1 -0
- package/dist/holdings.js +95 -0
- package/dist/host.d.ts +4 -5
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +23 -22
- 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 +25 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +556 -0
- package/dist/job.d.ts +33 -0
- package/dist/job.d.ts.map +1 -0
- package/dist/job.js +54 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +270 -0
- package/dist/listing.d.ts +53 -0
- package/dist/listing.d.ts.map +1 -0
- package/dist/listing.js +176 -0
- package/dist/live.d.ts +5 -4
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +63 -21
- package/dist/locks.d.ts +9 -0
- package/dist/locks.d.ts.map +1 -0
- package/dist/locks.js +62 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/lost.d.ts +5 -0
- package/dist/lost.d.ts.map +1 -0
- package/dist/lost.js +61 -0
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +3 -3
- package/dist/memory.d.ts +5 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +50 -10
- package/dist/messages.d.ts +27 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +103 -31
- package/dist/model.d.ts +2 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -9
- package/dist/models.d.ts +14 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +197 -0
- package/dist/observation.d.ts +2 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +14 -14
- package/dist/opened.js +3 -3
- package/dist/opening.d.ts +4 -0
- package/dist/opening.d.ts.map +1 -0
- package/dist/opening.js +60 -0
- package/dist/outcome.d.ts +4 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +3 -0
- package/dist/overlay.d.ts +1 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -0
- package/dist/parts.d.ts +60 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +126 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/preparation.d.ts +20 -0
- package/dist/preparation.d.ts.map +1 -0
- package/dist/preparation.js +233 -0
- package/dist/queries.d.ts +16 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +272 -0
- package/dist/query.d.ts +13 -209
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +3 -505
- package/dist/questions.d.ts +34 -0
- package/dist/questions.d.ts.map +1 -0
- package/dist/questions.js +122 -0
- package/dist/reach.d.ts +14 -12
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +167 -114
- package/dist/react.d.ts +13 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -1
- package/dist/read.d.ts +7 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +17 -0
- package/dist/readiness.d.ts +0 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/reads.d.ts +37 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +174 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +9 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +7 -0
- package/dist/refusal.d.ts +5 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +57 -0
- package/dist/replica.d.ts +9 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +53 -17
- package/dist/room-draft.d.ts +3 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +7 -7
- package/dist/room-drafts.d.ts +24 -0
- package/dist/room-drafts.d.ts.map +1 -0
- package/dist/room-drafts.js +217 -0
- package/dist/rows.d.ts +14 -21
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +48 -184
- package/dist/runtime.d.ts +43 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +1 -0
- package/dist/save.d.ts +5 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +34 -21
- package/dist/saves.d.ts +70 -0
- package/dist/saves.d.ts.map +1 -0
- package/dist/saves.js +1005 -0
- package/dist/search.d.ts +12 -63
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +9 -52
- package/dist/seed.d.ts +11 -2
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +71 -1
- package/dist/shared.d.ts +1 -6
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +13 -95
- package/dist/shown.d.ts +31 -0
- package/dist/shown.d.ts.map +1 -0
- package/dist/shown.js +290 -0
- package/dist/socket/admission.d.ts +7 -0
- package/dist/socket/admission.d.ts.map +1 -0
- package/dist/socket/admission.js +39 -0
- package/dist/socket/answers.d.ts +6 -0
- package/dist/socket/answers.d.ts.map +1 -0
- package/dist/socket/answers.js +20 -0
- package/dist/socket/lanes.d.ts +20 -0
- package/dist/socket/lanes.d.ts.map +1 -0
- package/dist/socket/lanes.js +77 -0
- package/dist/socket/reads.d.ts +10 -0
- package/dist/socket/reads.d.ts.map +1 -0
- package/dist/socket/reads.js +31 -0
- package/dist/socket/rooms.d.ts +44 -0
- package/dist/socket/rooms.d.ts.map +1 -0
- package/dist/socket/rooms.js +90 -0
- package/dist/socket/session.d.ts +38 -0
- package/dist/socket/session.d.ts.map +1 -0
- package/dist/socket/session.js +23 -0
- package/dist/socket.d.ts +70 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +175 -0
- package/dist/source.d.ts +61 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +82 -0
- package/dist/status.d.ts +0 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -6
- package/dist/store/fences.d.ts +16 -0
- package/dist/store/fences.d.ts.map +1 -0
- package/dist/store/fences.js +26 -0
- package/dist/store/installs.d.ts +30 -0
- package/dist/store/installs.d.ts.map +1 -0
- package/dist/store/installs.js +34 -0
- package/dist/store/readiness.d.ts +10 -0
- package/dist/store/readiness.d.ts.map +1 -0
- package/dist/store/readiness.js +52 -0
- package/dist/store/records.d.ts +212 -0
- package/dist/store/records.d.ts.map +1 -0
- package/dist/store/records.js +431 -0
- package/dist/store/room-held.d.ts +8 -0
- package/dist/store/room-held.d.ts.map +1 -0
- package/dist/store/room-held.js +17 -0
- package/dist/store/space.d.ts +11 -0
- package/dist/store/space.d.ts.map +1 -0
- package/dist/store/space.js +41 -0
- package/dist/store/watchers.d.ts +17 -0
- package/dist/store/watchers.d.ts.map +1 -0
- package/dist/store/watchers.js +56 -0
- package/dist/store/writes.d.ts +24 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +125 -0
- package/dist/store.d.ts +107 -145
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +143 -366
- package/dist/stored.d.ts +59 -33
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +278 -189
- package/dist/surface.d.ts +88 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +224 -0
- package/dist/sync.d.ts +19 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +532 -0
- package/dist/tables.d.ts +120 -29
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +216 -54
- package/dist/tallies.d.ts +18 -0
- package/dist/tallies.d.ts.map +1 -0
- package/dist/tallies.js +129 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +7 -4
- 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 +16 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +6 -0
- package/package.json +2 -2
- package/dist/fence.d.ts +0 -6
- package/dist/fence.d.ts.map +0 -1
- package/dist/fence.js +0 -10
- package/dist/fulltext.d.ts +0 -27
- package/dist/fulltext.d.ts.map +0 -1
- package/dist/fulltext.js +0 -370
- package/dist/words.d.ts +0 -19
- package/dist/words.d.ts.map +0 -1
- package/dist/words.js +0 -156
package/dist/live.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { changeOf, digestOf, } from './observation.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
2
3
|
import { roomOfKey } from './rows.js';
|
|
3
4
|
function narrowed(plan) {
|
|
4
5
|
return (plan.paths !== null &&
|
|
@@ -22,13 +23,15 @@ function affected(plan, set) {
|
|
|
22
23
|
const paths = narrowed(plan) ? new Set(plan.paths) : null;
|
|
23
24
|
return set.documents.some(({ locator, path }) => reads(plan, locator) && (paths === null || path === null || paths.has(path)));
|
|
24
25
|
}
|
|
25
|
-
function shown(entry) {
|
|
26
|
-
const cover = entry.cover();
|
|
26
|
+
function shown(entry, held) {
|
|
27
|
+
const cover = entry.cover(held);
|
|
27
28
|
return JSON.stringify('pending' in cover ? cover : cover.coverage);
|
|
28
29
|
}
|
|
29
|
-
export function createLiveQueries(run) {
|
|
30
|
+
export function createLiveQueries(run, holding) {
|
|
30
31
|
const entries = new Map();
|
|
31
32
|
let closed = false;
|
|
33
|
+
let recovering = false;
|
|
34
|
+
let recoverAgain = false;
|
|
32
35
|
function deliver(entry, next) {
|
|
33
36
|
const previous = entry.digest;
|
|
34
37
|
entry.digest = digestOf(next);
|
|
@@ -38,12 +41,19 @@ export function createLiveQueries(run) {
|
|
|
38
41
|
for (const listener of entry.ready)
|
|
39
42
|
listener(change);
|
|
40
43
|
}
|
|
41
|
-
for (const listener of entry.fresh) {
|
|
44
|
+
for (const listener of entry.fresh.keys()) {
|
|
42
45
|
entry.ready.add(listener);
|
|
43
46
|
listener(next);
|
|
44
47
|
}
|
|
45
48
|
entry.fresh.clear();
|
|
46
49
|
}
|
|
50
|
+
async function delivered(entry) {
|
|
51
|
+
const { current, ...next } = await run(entry.plan, async () => entry.cover(await holding()));
|
|
52
|
+
if (closed || entry.listeners.size === 0)
|
|
53
|
+
return null;
|
|
54
|
+
deliver(entry, next);
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
47
57
|
function schedule(entry) {
|
|
48
58
|
if (closed || entry.listeners.size === 0)
|
|
49
59
|
return;
|
|
@@ -56,22 +66,61 @@ export function createLiveQueries(run) {
|
|
|
56
66
|
try {
|
|
57
67
|
for (;;) {
|
|
58
68
|
entry.dirty = false;
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
69
|
+
const current = await delivered(entry);
|
|
70
|
+
if (current === null)
|
|
61
71
|
return;
|
|
62
|
-
|
|
63
|
-
if (
|
|
72
|
+
const held = await holding();
|
|
73
|
+
if (entry.fresh.size > 0 || (entry.dirty && !current()))
|
|
74
|
+
continue;
|
|
75
|
+
if (shown(entry, held) === entry.covered)
|
|
64
76
|
break;
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
|
-
catch {
|
|
68
|
-
|
|
79
|
+
catch (error) {
|
|
80
|
+
const unanswered = [...entry.fresh.values()];
|
|
81
|
+
entry.fresh.clear();
|
|
82
|
+
for (const failed of unanswered)
|
|
83
|
+
failed(error);
|
|
69
84
|
}
|
|
70
85
|
finally {
|
|
71
86
|
entry.running = false;
|
|
72
87
|
}
|
|
73
88
|
})();
|
|
74
89
|
}
|
|
90
|
+
function recovered() {
|
|
91
|
+
if (recovering) {
|
|
92
|
+
recoverAgain = true;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
recovering = true;
|
|
96
|
+
void (async () => {
|
|
97
|
+
try {
|
|
98
|
+
do {
|
|
99
|
+
recoverAgain = false;
|
|
100
|
+
for (const entry of entries.values()) {
|
|
101
|
+
if (entry.running)
|
|
102
|
+
entry.dirty = true;
|
|
103
|
+
}
|
|
104
|
+
const waiting = [...entries.values()].filter((entry) => !entry.running);
|
|
105
|
+
if (waiting.length === 0 || closed)
|
|
106
|
+
continue;
|
|
107
|
+
const held = await holding();
|
|
108
|
+
for (const entry of waiting) {
|
|
109
|
+
if (entry.running)
|
|
110
|
+
continue;
|
|
111
|
+
if (entry.digest === undefined || shown(entry, held) !== entry.covered)
|
|
112
|
+
schedule(entry);
|
|
113
|
+
}
|
|
114
|
+
} while (recoverAgain && !closed);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
uncaught(error);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
recovering = false;
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
}
|
|
75
124
|
return {
|
|
76
125
|
touched(set) {
|
|
77
126
|
for (const entry of entries.values()) {
|
|
@@ -79,22 +128,15 @@ export function createLiveQueries(run) {
|
|
|
79
128
|
schedule(entry);
|
|
80
129
|
}
|
|
81
130
|
},
|
|
82
|
-
recover
|
|
83
|
-
|
|
84
|
-
if (entry.running)
|
|
85
|
-
continue;
|
|
86
|
-
if (entry.digest === undefined || shown(entry) !== entry.covered)
|
|
87
|
-
schedule(entry);
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
watch(plan, identity, cover, listener) {
|
|
131
|
+
recover: recovered,
|
|
132
|
+
watch(plan, identity, cover, listener, failed) {
|
|
91
133
|
let entry = entries.get(identity);
|
|
92
134
|
if (entry === undefined) {
|
|
93
135
|
entry = {
|
|
94
136
|
plan,
|
|
95
137
|
cover,
|
|
96
138
|
listeners: new Set(),
|
|
97
|
-
fresh: new
|
|
139
|
+
fresh: new Map(),
|
|
98
140
|
ready: new Set(),
|
|
99
141
|
digest: undefined,
|
|
100
142
|
covered: '',
|
|
@@ -105,7 +147,7 @@ export function createLiveQueries(run) {
|
|
|
105
147
|
}
|
|
106
148
|
const held = entry;
|
|
107
149
|
held.listeners.add(listener);
|
|
108
|
-
held.fresh.
|
|
150
|
+
held.fresh.set(listener, failed);
|
|
109
151
|
schedule(held);
|
|
110
152
|
return () => {
|
|
111
153
|
held.listeners.delete(listener);
|
package/dist/locks.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DiscoveredRoom } from './adapter.js';
|
|
2
|
+
import type { Runtime } from './runtime.js';
|
|
3
|
+
export declare function locked({ store, socket }: Runtime, locator: string): Promise<boolean>;
|
|
4
|
+
export declare function lockedRooms(runtime: Runtime): Promise<readonly string[]>;
|
|
5
|
+
export declare function relocked(runtime: Runtime, before: readonly string[]): Promise<void>;
|
|
6
|
+
export declare function confirmLocks({ socket }: Runtime, listed: readonly DiscoveredRoom[]): void;
|
|
7
|
+
export declare function connectionLost(runtime: Runtime): void;
|
|
8
|
+
export declare function watchLocks({ store }: Runtime, notify: () => void): () => void;
|
|
9
|
+
//# sourceMappingURL=locks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locks.d.ts","sourceRoot":"","sources":["../src/locks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAa5C,wBAAsB,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK1F;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAW9E;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,iBAMzE;AAED,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,cAAc,EAAE,QAOlF;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
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { uncaught } from './failure.js';
|
|
2
|
+
import { emitRooms, LOCKS_TOPIC } from './shown.js';
|
|
3
|
+
async function offlineModes({ store, socket }) {
|
|
4
|
+
const modes = new Map();
|
|
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;
|
|
13
|
+
}
|
|
14
|
+
export async function locked({ store, socket }, locator) {
|
|
15
|
+
if (store.fences.has(locator) || socket.rooms.standing(locator).confirmed)
|
|
16
|
+
return false;
|
|
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();
|
|
29
|
+
}
|
|
30
|
+
export async function relocked(runtime, before) {
|
|
31
|
+
const after = await lockedRooms(runtime);
|
|
32
|
+
if (JSON.stringify(after) === JSON.stringify(before))
|
|
33
|
+
return;
|
|
34
|
+
runtime.journal.record(`locked ${after.length}`);
|
|
35
|
+
emitRooms(runtime);
|
|
36
|
+
runtime.store.tell(LOCKS_TOPIC, undefined);
|
|
37
|
+
}
|
|
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
|
+
export function connectionLost(runtime) {
|
|
48
|
+
const { socket } = runtime;
|
|
49
|
+
if (socket.closed())
|
|
50
|
+
return;
|
|
51
|
+
socket.rooms.connectionLost(() => {
|
|
52
|
+
if (socket.isOpen() || socket.closed())
|
|
53
|
+
return;
|
|
54
|
+
void lockedRooms(runtime).then((before) => {
|
|
55
|
+
socket.rooms.standAll({ confirmed: false });
|
|
56
|
+
return relocked(runtime, before);
|
|
57
|
+
}, uncaught);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function watchLocks({ store }, notify) {
|
|
61
|
+
return store.watch(LOCKS_TOPIC, notify).stop;
|
|
62
|
+
}
|
package/dist/log.d.ts
CHANGED
package/dist/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT"}
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS;IAGrB,MAAM,QAAQ,MAAM;IAIpB,MAAM;EAIT;AAED,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/lost.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Runtime } from './runtime.js';
|
|
2
|
+
export declare function eraseFenced({ store }: Runtime, locators: readonly string[]): Promise<void>;
|
|
3
|
+
export declare function fenceLive(runtime: Runtime, locators: readonly string[]): void;
|
|
4
|
+
export declare function loseRooms(runtime: Runtime, locators: readonly string[]): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=lost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lost.d.ts","sourceRoot":"","sources":["../src/lost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAU5C,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,QAOtE;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,iBAqC5E"}
|
package/dist/lost.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
|
+
import { ERASE_BATCH, forgetInstall } from './install.js';
|
|
3
|
+
import { recoverReads, statusShown } from './shown.js';
|
|
4
|
+
import { yielded } from './turn.js';
|
|
5
|
+
function forget({ store, socket }, locator) {
|
|
6
|
+
forgetInstall(store, locator);
|
|
7
|
+
socket.rooms.forget(locator);
|
|
8
|
+
store.forget(locator);
|
|
9
|
+
}
|
|
10
|
+
export async function eraseFenced({ store }, locators) {
|
|
11
|
+
for (const locator of locators) {
|
|
12
|
+
while (await store.durably((local) => local.erase(locator, ERASE_BATCH)))
|
|
13
|
+
await yielded();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function fenceLive(runtime, locators) {
|
|
17
|
+
const { store, socket, journal } = runtime;
|
|
18
|
+
for (const locator of new Set(locators)) {
|
|
19
|
+
if (!store.fences.raise(locator, socket.session.now().discoveries))
|
|
20
|
+
continue;
|
|
21
|
+
forget(runtime, locator);
|
|
22
|
+
journal.record(`room lost ${locator}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function loseRooms(runtime, locators) {
|
|
26
|
+
const { store } = runtime;
|
|
27
|
+
fenceLive(runtime, locators);
|
|
28
|
+
const fresh = [...new Set(locators)].filter((locator) => {
|
|
29
|
+
const fence = store.fences.of(locator);
|
|
30
|
+
if (fence === undefined || fence.written)
|
|
31
|
+
return false;
|
|
32
|
+
store.fences.mark(locator, true);
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
if (fresh.length === 0)
|
|
36
|
+
return;
|
|
37
|
+
let held = [];
|
|
38
|
+
try {
|
|
39
|
+
await store.durably(async (local) => {
|
|
40
|
+
held = await local.roomDrafts();
|
|
41
|
+
await local.fence(fresh);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
for (const locator of fresh)
|
|
46
|
+
store.fences.mark(locator, false);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
store.changed(mergeChangeSets(fresh.map((locator) => changeSet(locator, {
|
|
51
|
+
documents: null,
|
|
52
|
+
room: true,
|
|
53
|
+
queue: true,
|
|
54
|
+
drafts: held.filter((draft) => draft.locator === locator).map(({ path }) => path),
|
|
55
|
+
}))));
|
|
56
|
+
recoverReads(runtime);
|
|
57
|
+
statusShown(runtime);
|
|
58
|
+
}
|
|
59
|
+
await store.durably((local) => runtime.unpair(local));
|
|
60
|
+
await eraseFenced(runtime, fresh);
|
|
61
|
+
}
|
package/dist/media.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { type ShownAnswer } from './outcome.js';
|
|
|
3
3
|
export declare const ROOM_MEDIA = "room-media";
|
|
4
4
|
type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
|
|
5
5
|
export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
|
|
6
|
-
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient
|
|
6
|
+
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient): void;
|
|
7
7
|
export {};
|
|
8
8
|
//# sourceMappingURL=media.d.ts.map
|
package/dist/media.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,eAAO,MAAM,UAAU,eAAe,CAAC;AAwBvC,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAIpF,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAG5E;AAsBD,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,IAAI,CA0LxF"}
|
package/dist/media.js
CHANGED
|
@@ -37,8 +37,8 @@ function drawnFor(mediaType) {
|
|
|
37
37
|
return 'audio';
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
|
-
export function defineRoomMedia(client
|
|
41
|
-
if (
|
|
40
|
+
export function defineRoomMedia(client) {
|
|
41
|
+
if (customElements.get(ROOM_MEDIA) !== undefined)
|
|
42
42
|
return;
|
|
43
43
|
const connected = Promise.resolve(client);
|
|
44
44
|
class RoomMedia extends HTMLElement {
|
|
@@ -214,5 +214,5 @@ export function defineRoomMedia(client, registry = customElements) {
|
|
|
214
214
|
void this.#load();
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
customElements.define(ROOM_MEDIA, RoomMedia);
|
|
218
218
|
}
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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 DiscoveredRoom, type HeadChange, type ListedAgent, type ListedConversation, type Member, type ProviderLimit, type Retention, type ServiceMode } from './adapter.js';
|
|
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>>;
|
|
9
|
+
created?: Readonly<Record<string, string>>;
|
|
8
10
|
changes?: Readonly<Record<string, HeadChange>>;
|
|
9
11
|
binaryFiles?: Readonly<Record<string, BinaryFile>>;
|
|
10
12
|
folders?: readonly string[];
|
|
@@ -28,6 +30,7 @@ export type MemoryAdapterOptions = {
|
|
|
28
30
|
member?: Member;
|
|
29
31
|
unopened?: boolean;
|
|
30
32
|
roomTypes?: string;
|
|
33
|
+
typedPaths?: readonly TypedPath[];
|
|
31
34
|
};
|
|
32
35
|
export type MemoryAdapter = Adapter & {
|
|
33
36
|
discover: NonNullable<Adapter['discover']>;
|
|
@@ -39,6 +42,7 @@ export type MemoryAdapter = Adapter & {
|
|
|
39
42
|
close(closing?: {
|
|
40
43
|
revoked?: boolean;
|
|
41
44
|
lost?: boolean;
|
|
45
|
+
authorityChanged?: boolean;
|
|
42
46
|
}): void;
|
|
43
47
|
expire(locators: readonly string[]): void;
|
|
44
48
|
notifyRoomVersion(notification: {
|
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":"AAEA,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,i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B,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IACzF,MAAM,CAAC,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,CAipBrF"}
|
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) {
|
|
@@ -102,8 +103,35 @@ export function createMemoryAdapter(options = {}) {
|
|
|
102
103
|
return path;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
106
|
+
const saved = new WeakMap();
|
|
107
|
+
function factsAt(room, path, content) {
|
|
108
|
+
const types = schemaTypes(room.model?.kind === 'model' ? room.model.snapshot.schema : null, NO_ROOM_TYPES);
|
|
109
|
+
let held = saved.get(types);
|
|
110
|
+
if (held === undefined) {
|
|
111
|
+
held = new Map();
|
|
112
|
+
saved.set(types, held);
|
|
113
|
+
}
|
|
114
|
+
const key = `${path}\u0000${content}`;
|
|
115
|
+
if (!held.has(key)) {
|
|
116
|
+
const facts = documentFacts(path, parse(content, path), { types });
|
|
117
|
+
held.set(key, facts === null ? null : JSON.parse(JSON.stringify(facts)));
|
|
118
|
+
}
|
|
119
|
+
return held.get(key);
|
|
120
|
+
}
|
|
121
|
+
function factsIn(room, paths) {
|
|
122
|
+
const facts = {};
|
|
123
|
+
for (const path of paths) {
|
|
124
|
+
const content = room.documents?.[path];
|
|
125
|
+
const held = room.facts?.[path] ?? (content === undefined ? null : factsAt(room, path, content));
|
|
126
|
+
if (held !== null)
|
|
127
|
+
facts[path] = held;
|
|
128
|
+
}
|
|
129
|
+
return facts;
|
|
130
|
+
}
|
|
105
131
|
function retain(entries) {
|
|
106
132
|
for (const room of entries) {
|
|
133
|
+
for (const [path, content] of Object.entries(room.documents ?? {}))
|
|
134
|
+
factsAt(room, path, content);
|
|
107
135
|
note(room.locator, room);
|
|
108
136
|
const versions = served.get(room.locator) ?? new Map();
|
|
109
137
|
versions.set(room.roomVersion, room);
|
|
@@ -121,6 +149,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
121
149
|
replica: room.replica,
|
|
122
150
|
...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),
|
|
123
151
|
providerOwnedPaths: room.providerOwnedPaths,
|
|
152
|
+
authoredPaths: room.authoredPaths,
|
|
124
153
|
};
|
|
125
154
|
}
|
|
126
155
|
function page(room, after) {
|
|
@@ -136,10 +165,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
136
165
|
roomVersion: room.roomVersion,
|
|
137
166
|
...(opening ? { models: modelsOf(room) } : {}),
|
|
138
167
|
documents: named(room.documents ?? {}, taken),
|
|
168
|
+
facts: factsIn(room, taken),
|
|
139
169
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
140
170
|
...(room.fileIds === undefined
|
|
141
171
|
? {}
|
|
142
172
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
173
|
+
...(room.created === undefined
|
|
174
|
+
? {}
|
|
175
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
143
176
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
144
177
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
145
178
|
...(opening && room.folders !== undefined ? { folders: room.folders } : {}),
|
|
@@ -163,6 +196,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
163
196
|
const previousTargets = new Set(Object.keys(from.binaryFiles ?? {}));
|
|
164
197
|
const headMoved = (path) => room.revisions?.[path] !== from.revisions?.[path] ||
|
|
165
198
|
room.fileIds?.[path] !== from.fileIds?.[path] ||
|
|
199
|
+
room.created?.[path] !== from.created?.[path] ||
|
|
166
200
|
!sameChange(room.changes?.[path], from.changes?.[path]);
|
|
167
201
|
const changed = Object.keys(current)
|
|
168
202
|
.filter((path) => current[path] !== previous[path] || headMoved(path))
|
|
@@ -183,10 +217,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
183
217
|
roomVersion: room.roomVersion,
|
|
184
218
|
...(models === undefined ? {} : { models }),
|
|
185
219
|
documents: named(current, taken),
|
|
220
|
+
facts: factsIn(room, taken),
|
|
186
221
|
revisions: named(room.revisions ?? {}, [...taken, ...targets]),
|
|
187
222
|
...(room.fileIds === undefined
|
|
188
223
|
? {}
|
|
189
224
|
: { fileIds: named(room.fileIds, [...taken, ...targets]) }),
|
|
225
|
+
...(room.created === undefined
|
|
226
|
+
? {}
|
|
227
|
+
: { created: named(room.created, [...taken, ...targets]) }),
|
|
190
228
|
changes: named(room.changes ?? {}, [...taken, ...targets]),
|
|
191
229
|
binaryFiles: named(room.binaryFiles ?? {}, targets),
|
|
192
230
|
...(opening ? foldersMoved(room, from) : {}),
|
|
@@ -322,7 +360,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
322
360
|
openings += 1;
|
|
323
361
|
carried.clear();
|
|
324
362
|
const revoked = answer.kind === 'revoked-authorization';
|
|
325
|
-
notify({ kind: 'closed', revoked, lost: !revoked });
|
|
363
|
+
notify({ kind: 'closed', revoked, lost: !revoked, authorityChanged: false });
|
|
326
364
|
return;
|
|
327
365
|
}
|
|
328
366
|
declaredRooms.clear();
|
|
@@ -337,6 +375,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
337
375
|
}
|
|
338
376
|
return {
|
|
339
377
|
...(options.roomTypes === undefined ? {} : { roomTypes: options.roomTypes }),
|
|
378
|
+
...(options.typedPaths === undefined ? {} : { typedPaths: options.typedPaths }),
|
|
340
379
|
setRooms(next) {
|
|
341
380
|
rooms = [...next];
|
|
342
381
|
retain(rooms);
|
|
@@ -349,10 +388,10 @@ export function createMemoryAdapter(options = {}) {
|
|
|
349
388
|
announceList();
|
|
350
389
|
opened(emitAll);
|
|
351
390
|
},
|
|
352
|
-
close({ revoked = false, lost = !revoked } = {}) {
|
|
391
|
+
close({ revoked = false, lost = !revoked, authorityChanged = false } = {}) {
|
|
353
392
|
openings += 1;
|
|
354
393
|
carried.clear();
|
|
355
|
-
emitAll({ kind: 'closed', revoked, lost });
|
|
394
|
+
emitAll({ kind: 'closed', revoked, lost, authorityChanged });
|
|
356
395
|
},
|
|
357
396
|
expire(locators) {
|
|
358
397
|
expiring = [...locators];
|
|
@@ -423,9 +462,10 @@ export function createMemoryAdapter(options = {}) {
|
|
|
423
462
|
const named = asked.map((room) => room.locator);
|
|
424
463
|
const unknown = asked.flatMap((room) => {
|
|
425
464
|
const current = rooms.find((entry) => entry.locator === room.locator);
|
|
465
|
+
const version = room.roomVersion;
|
|
426
466
|
return current === undefined ||
|
|
427
|
-
|
|
428
|
-
|
|
467
|
+
(version !== null &&
|
|
468
|
+
(current.roomVersion === version || served.get(room.locator)?.has(version) === true))
|
|
429
469
|
? []
|
|
430
470
|
: [room.locator];
|
|
431
471
|
});
|
|
@@ -435,7 +475,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
435
475
|
expiring = expiring.filter((locator) => !named.includes(locator));
|
|
436
476
|
queueMicrotask(() => {
|
|
437
477
|
for (const room of asked) {
|
|
438
|
-
if (expired.includes(room.locator))
|
|
478
|
+
if (expired.includes(room.locator) || room.roomVersion === null)
|
|
439
479
|
carried.delete(room.locator);
|
|
440
480
|
else {
|
|
441
481
|
carried.set(room.locator, room.roomVersion);
|
|
@@ -451,7 +491,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
451
491
|
if (!observers.has(notify))
|
|
452
492
|
return;
|
|
453
493
|
if (options.unopened === true) {
|
|
454
|
-
notify({ kind: 'closed', revoked: false, lost: true });
|
|
494
|
+
notify({ kind: 'closed', revoked: false, lost: true, authorityChanged: false });
|
|
455
495
|
return;
|
|
456
496
|
}
|
|
457
497
|
announceList();
|
|
@@ -559,7 +599,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
559
599
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
560
600
|
const blob = heldBlob(room, request.path);
|
|
561
601
|
return blob === undefined
|
|
562
|
-
? { kind: 'rejected', code: '
|
|
602
|
+
? { kind: 'rejected', code: 'not_found', fields: {}, retryable: false }
|
|
563
603
|
: { kind: 'binary', body: blob.stream(), mediaType: blob.type };
|
|
564
604
|
}, request);
|
|
565
605
|
},
|
|
@@ -570,7 +610,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
570
610
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
571
611
|
const blob = heldBlob(room, request.path);
|
|
572
612
|
if (blob === undefined) {
|
|
573
|
-
return { kind: 'rejected', code: '
|
|
613
|
+
return { kind: 'rejected', code: 'not_found', fields: {}, retryable: false };
|
|
574
614
|
}
|
|
575
615
|
const url = linked.get(blob) ?? URL.createObjectURL(blob);
|
|
576
616
|
linked.set(blob, url);
|
package/dist/messages.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { AcceptedMessage } from './adapter.js';
|
|
2
|
+
import type { JobMarker } from './job.js';
|
|
2
3
|
import type { Connection } from './tables.js';
|
|
3
4
|
export declare const MESSAGE_TABLES: readonly string[];
|
|
5
|
+
export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n asking.text AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
|
|
6
|
+
export declare const JOB_MARKERS = "SELECT json_extract(part.value, '$.text') AS said,\n json_extract(message, '$.accepted_at') AS at\n FROM conversation_messages, json_each(message, '$.parts') AS part\n WHERE conversation = ? AND instr(message, '\"marker\":\"job\"') > 0\n AND json_extract(part.value, '$.type') = 'marker'\n AND json_extract(part.value, '$.marker') = 'job'\n ORDER BY position, identity, part.key";
|
|
4
7
|
export type HeldConversation = {
|
|
5
8
|
readonly conversation: string;
|
|
6
9
|
readonly read: string | null | undefined;
|
|
@@ -10,6 +13,25 @@ export type MessageWindow = {
|
|
|
10
13
|
readonly messages: AcceptedMessage[];
|
|
11
14
|
readonly more: boolean;
|
|
12
15
|
};
|
|
16
|
+
export type HeldSource = {
|
|
17
|
+
readonly source: unknown;
|
|
18
|
+
readonly sender: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type HeldRow = {
|
|
21
|
+
readonly conversation: string;
|
|
22
|
+
readonly said: {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly role: string | null;
|
|
25
|
+
readonly at: string | null;
|
|
26
|
+
} | null;
|
|
27
|
+
readonly failure: string | null;
|
|
28
|
+
readonly opened: HeldSource | null;
|
|
29
|
+
readonly asking: (HeldSource & {
|
|
30
|
+
readonly identity: string;
|
|
31
|
+
readonly text: string;
|
|
32
|
+
readonly at: string | null;
|
|
33
|
+
}) | null;
|
|
34
|
+
};
|
|
13
35
|
export type ConversationWrite = {
|
|
14
36
|
readonly conversation: string;
|
|
15
37
|
readonly messages: readonly AcceptedMessage[];
|
|
@@ -18,10 +40,12 @@ export type ConversationWrite = {
|
|
|
18
40
|
readonly partial: boolean;
|
|
19
41
|
};
|
|
20
42
|
};
|
|
21
|
-
export declare function heldConversations(connection: Connection): HeldConversation[];
|
|
43
|
+
export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
|
|
22
44
|
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;
|
|
45
|
+
export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
|
|
46
|
+
export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
|
|
47
|
+
export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
|
|
48
|
+
export declare function jobMarkers(connection: Connection, conversation: string): JobMarker[];
|
|
25
49
|
export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
|
|
26
50
|
export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
|
|
27
51
|
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,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAQ1D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAQ3C,CAAC;AAQF,eAAO,MAAM,IAAI,qwDAwBqD,CAAC;AAEvE,eAAO,MAAM,WAAW,2YAMgB,CAAC;AAEzC,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;IAA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