@agentshouse/mdruntime 0.1.0-c3903a68dcbbf → 0.1.0-c3c7796382e28
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 +25 -12
- package/dist/adapter.d.ts +216 -74
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -9
- package/dist/attached-model.d.ts +15 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +64 -0
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +70 -0
- package/dist/binary.d.ts +18 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +44 -7
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +224 -46
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -14
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -60
- package/dist/change.d.ts +45 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +34 -0
- package/dist/client.d.ts +37 -21
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +159 -35
- package/dist/collection.d.ts +14 -15
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +65 -63
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +765 -0
- package/dist/connection.d.ts +67 -42
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +4006 -1085
- package/dist/conversation.d.ts +59 -21
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +786 -243
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +5 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -0
- package/dist/entry.d.ts +19 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +151 -0
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/file.d.ts +2 -19
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +7 -122
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +368 -0
- package/dist/host.d.ts +21 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +165 -72
- package/dist/identity.d.ts +4 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +16 -1
- package/dist/index.d.ts +19 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +124 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +208 -0
- package/dist/memory.d.ts +22 -8
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +207 -48
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/model.d.ts +23 -14
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +22 -4
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +21 -1
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +128 -17
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +75 -21
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +81 -1
- package/dist/overlay.d.ts +15 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +136 -180
- package/dist/paths.d.ts +0 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +0 -16
- package/dist/query.d.ts +78 -7
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +126 -43
- package/dist/reach.d.ts +53 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +448 -0
- package/dist/react.d.ts +43 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +54 -0
- package/dist/readiness.d.ts +64 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +33 -0
- package/dist/reads.d.ts +11 -0
- package/dist/reads.d.ts.map +1 -0
- package/dist/reads.js +100 -0
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +198 -0
- package/dist/refresh.d.ts +19 -7
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +125 -53
- package/dist/replica.d.ts +59 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +324 -162
- package/dist/room-draft.d.ts +44 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +191 -40
- package/dist/rows.d.ts +39 -34
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +195 -81
- package/dist/save.d.ts +72 -6
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +889 -179
- package/dist/search.d.ts +41 -29
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +37 -105
- package/dist/seed.d.ts +16 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +75 -0
- package/dist/shared.d.ts +16 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +431 -0
- package/dist/status.d.ts +6 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +129 -70
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +373 -365
- package/dist/stored.d.ts +152 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +571 -0
- package/dist/tables.d.ts +354 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +624 -0
- package/dist/turn.d.ts +9 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +75 -0
- package/dist/validation.d.ts +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +194 -19
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +90 -67
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +150 -0
- package/package.json +33 -10
- package/AGENTS.md +0 -210
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
- package/dist/read-side.d.ts +0 -14
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -371
package/dist/host.js
CHANGED
|
@@ -1,40 +1,48 @@
|
|
|
1
1
|
import { composeRuntime, } from './connection.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { queryKey } from './query.js';
|
|
3
|
+
import { described } from './failure.js';
|
|
4
|
+
import { AUTHORIZATION_ENDED, request, WIRE, } from './wire.js';
|
|
5
|
+
const NARROWED = new Set(['within', 'whole']);
|
|
6
|
+
function answered(md, app, writtenBy, member, input) {
|
|
5
7
|
switch (member) {
|
|
6
8
|
case 'rooms':
|
|
7
9
|
return md.rooms();
|
|
8
|
-
case 'slots':
|
|
9
|
-
return md.slots();
|
|
10
10
|
case 'query':
|
|
11
11
|
return md.query(input[0]);
|
|
12
12
|
case 'search':
|
|
13
13
|
return md.search(input[0]);
|
|
14
14
|
case 'types':
|
|
15
15
|
return md.types(input[0]);
|
|
16
|
-
case 'syncStatus':
|
|
17
|
-
return md.syncStatus();
|
|
18
|
-
case 'serviceMode':
|
|
19
|
-
return md.serviceMode();
|
|
20
16
|
case 'save':
|
|
21
17
|
return md.save(input[0], input[1], writtenBy);
|
|
22
|
-
case '
|
|
23
|
-
return md.
|
|
18
|
+
case 'saveParts':
|
|
19
|
+
return md.saveParts(input[0], input[1], writtenBy);
|
|
24
20
|
case 'history':
|
|
25
21
|
return md.history(input[0], input[1], input[2]);
|
|
22
|
+
case 'resolve':
|
|
23
|
+
return md.resolve(input[0], input[1], input[2]);
|
|
24
|
+
case 'binaryFile.read':
|
|
25
|
+
return md.binaryFile.read(input[0], input[1], input[2]);
|
|
26
|
+
case 'binaryFile.link':
|
|
27
|
+
return md.binaryFile.link(input[0], input[1], input[2]);
|
|
28
|
+
case 'binaryFile.show':
|
|
29
|
+
return md.binaryFile.show(input[0], input[1], input[2]);
|
|
30
|
+
case 'binaryFile.attach':
|
|
31
|
+
return md.binaryFile.attach(input[0], input[1]);
|
|
32
|
+
case 'binaryFile.part':
|
|
33
|
+
return md.binaryFile.part(input[0], input[1]);
|
|
26
34
|
case 'call':
|
|
27
35
|
return md.call(input[0], input[1]);
|
|
28
36
|
case 'reached':
|
|
29
37
|
return md.reached(input[0], input[1], input[2]);
|
|
30
38
|
case 'log':
|
|
31
39
|
return md.log();
|
|
32
|
-
case '
|
|
33
|
-
return md.
|
|
34
|
-
case 'deploymentFacts':
|
|
35
|
-
return structuredClone(deploymentFacts);
|
|
40
|
+
case 'cleanUp':
|
|
41
|
+
return md.cleanUp();
|
|
36
42
|
case 'persistence':
|
|
37
43
|
return md.persistence();
|
|
44
|
+
case 'retry':
|
|
45
|
+
return md.retry();
|
|
38
46
|
case 'reauthorize':
|
|
39
47
|
return md.reauthorize();
|
|
40
48
|
case 'roomDraft.list':
|
|
@@ -42,13 +50,15 @@ function answered(md, app, writtenBy, member, input, deploymentFacts) {
|
|
|
42
50
|
case 'roomDraft.read':
|
|
43
51
|
return md.roomDraft.read(input[0], input[1]);
|
|
44
52
|
case 'roomDraft.write':
|
|
45
|
-
return md.roomDraft.write(input[0], input[1], input[2], input[3]);
|
|
53
|
+
return md.roomDraft.write(input[0], input[1], input[2], input[3], input[4]);
|
|
46
54
|
case 'roomDraft.discard':
|
|
47
55
|
return md.roomDraft.discard(input[0], input[1], input[2]);
|
|
48
56
|
case 'presentation.read':
|
|
49
57
|
return md.presentation.read(app);
|
|
50
58
|
case 'presentation.write':
|
|
51
59
|
return md.presentation.write(app, input[0]);
|
|
60
|
+
case 'presentation.edit':
|
|
61
|
+
return md.presentation.edit(app, input[0]);
|
|
52
62
|
case 'conversation.list':
|
|
53
63
|
return md.conversation.list();
|
|
54
64
|
case 'conversation.read':
|
|
@@ -56,7 +66,7 @@ function answered(md, app, writtenBy, member, input, deploymentFacts) {
|
|
|
56
66
|
case 'conversation.create':
|
|
57
67
|
return md.conversation.create(input[0]);
|
|
58
68
|
case 'conversation.send':
|
|
59
|
-
return md.conversation.send(input[0]);
|
|
69
|
+
return md.conversation.send(input[0], input[1], input[2]);
|
|
60
70
|
case 'conversation.answer':
|
|
61
71
|
return md.conversation.answer(input[0], input[1]);
|
|
62
72
|
case 'conversation.interrupt':
|
|
@@ -68,13 +78,31 @@ function answered(md, app, writtenBy, member, input, deploymentFacts) {
|
|
|
68
78
|
case 'conversation.delete':
|
|
69
79
|
return md.conversation.delete(input[0]);
|
|
70
80
|
case 'chatDraft.write':
|
|
71
|
-
return md.chatDraft.write(input[0], input[1]);
|
|
81
|
+
return md.chatDraft.write(input[0], input[1], input[2]);
|
|
82
|
+
case 'chatDraft.prepend':
|
|
83
|
+
return md.chatDraft.prepend(input[0], input[1]);
|
|
72
84
|
case 'chatDraft.discard':
|
|
73
85
|
return md.chatDraft.discard(input[0]);
|
|
74
86
|
}
|
|
75
87
|
}
|
|
88
|
+
function attempted(work) {
|
|
89
|
+
try {
|
|
90
|
+
return Promise.resolve(work());
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
return Promise.reject(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function answeredResult(value) {
|
|
97
|
+
return typeof value === 'object' && value !== null && !('pending' in value);
|
|
98
|
+
}
|
|
99
|
+
function answeredMessage(value) {
|
|
100
|
+
if (typeof value !== 'object' || value === null)
|
|
101
|
+
return false;
|
|
102
|
+
return !('result' in value) || answeredResult(value.result);
|
|
103
|
+
}
|
|
76
104
|
export function serveMdRuntime(options) {
|
|
77
|
-
|
|
105
|
+
const deploymentFacts = structuredClone(options.deploymentFacts);
|
|
78
106
|
const closing = new AbortController();
|
|
79
107
|
const close = () => {
|
|
80
108
|
closing.abort();
|
|
@@ -83,86 +111,104 @@ export function serveMdRuntime(options) {
|
|
|
83
111
|
if (options.signal?.aborted === true)
|
|
84
112
|
close();
|
|
85
113
|
const runtime = composeRuntime({ ...options, signal: closing.signal });
|
|
86
|
-
const { md
|
|
114
|
+
const { md } = runtime;
|
|
87
115
|
const attachments = new Map();
|
|
88
116
|
let authorized = true;
|
|
89
|
-
const factsObservers = new Set();
|
|
90
117
|
const watchFacts = (deliver) => {
|
|
91
|
-
factsObservers.add(deliver);
|
|
92
118
|
deliver(structuredClone(deploymentFacts));
|
|
93
|
-
return () => {
|
|
94
|
-
factsObservers.delete(deliver);
|
|
95
|
-
};
|
|
119
|
+
return () => { };
|
|
96
120
|
};
|
|
97
|
-
function attach(port, app, release) {
|
|
121
|
+
function attach(port, app, release, reach, code = 'stored', search = 'unused') {
|
|
98
122
|
if (!authorized)
|
|
99
123
|
throw new Error(AUTHORIZATION_ENDED);
|
|
100
124
|
const writtenBy = release === undefined ? undefined : { app, release };
|
|
101
|
-
|
|
125
|
+
let facts = { target: app, code, space: null, search };
|
|
126
|
+
const view = runtime.within(reach ?? null, facts);
|
|
127
|
+
const observations = new Map();
|
|
128
|
+
const followed = new Set();
|
|
129
|
+
const answeredKeys = new Set();
|
|
130
|
+
let awaited = null;
|
|
102
131
|
let serving = true;
|
|
132
|
+
const answeredQuery = (query) => {
|
|
133
|
+
answeredKeys.add(queryKey(query));
|
|
134
|
+
if (awaited === null || !awaited.keys.every((key) => answeredKeys.has(key)))
|
|
135
|
+
return;
|
|
136
|
+
const { done } = awaited;
|
|
137
|
+
awaited = null;
|
|
138
|
+
done();
|
|
139
|
+
};
|
|
103
140
|
const send = (message) => {
|
|
104
|
-
port.postMessage(
|
|
141
|
+
port.postMessage(message);
|
|
105
142
|
};
|
|
106
143
|
const detach = () => {
|
|
107
144
|
if (!serving)
|
|
108
145
|
return;
|
|
109
146
|
serving = false;
|
|
110
|
-
for (const end of
|
|
147
|
+
for (const end of observations.values())
|
|
148
|
+
end();
|
|
149
|
+
observations.clear();
|
|
150
|
+
for (const end of [...followed])
|
|
111
151
|
end();
|
|
112
|
-
subscriptions.clear();
|
|
113
152
|
attachments.delete(detach);
|
|
114
153
|
};
|
|
154
|
+
const observe = (id, topic, input) => {
|
|
155
|
+
let resolved = false;
|
|
156
|
+
const deliver = (value) => {
|
|
157
|
+
if (!serving)
|
|
158
|
+
return;
|
|
159
|
+
send(resolved ? { kind: 'event', id, value } : { kind: 'result', id, value });
|
|
160
|
+
resolved = true;
|
|
161
|
+
if (topic === 'query' && answeredMessage(value))
|
|
162
|
+
answeredQuery(input[0]);
|
|
163
|
+
};
|
|
164
|
+
observations.set(id, topic === 'deployment-facts'
|
|
165
|
+
? watchFacts(deliver)
|
|
166
|
+
: (NARROWED.has(WIRE.topics[topic]) ? view : runtime).watch(topic, topic === 'presentation' ? [app] : input, deliver));
|
|
167
|
+
};
|
|
168
|
+
const reply = async (id, query, pending) => {
|
|
169
|
+
try {
|
|
170
|
+
const value = await pending;
|
|
171
|
+
if (!serving)
|
|
172
|
+
return;
|
|
173
|
+
send({ kind: 'result', id, value });
|
|
174
|
+
if (query !== undefined && answeredResult(value))
|
|
175
|
+
answeredQuery(query);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (serving)
|
|
179
|
+
send({ kind: 'failure', id, ...described(error) });
|
|
180
|
+
}
|
|
181
|
+
};
|
|
115
182
|
const serve = async (message) => {
|
|
116
183
|
if (message.kind === 'hello')
|
|
117
184
|
return;
|
|
118
185
|
if (message.kind === 'stop') {
|
|
119
|
-
|
|
120
|
-
|
|
186
|
+
observations.get(message.id)?.();
|
|
187
|
+
observations.delete(message.id);
|
|
121
188
|
return;
|
|
122
189
|
}
|
|
123
190
|
try {
|
|
124
191
|
if (message.kind !== 'observe' || message.topic !== 'room-drafts')
|
|
125
192
|
await md.loaded();
|
|
126
193
|
if (message.kind === 'observe') {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const deliver = (value) => {
|
|
130
|
-
if (!serving)
|
|
131
|
-
return;
|
|
132
|
-
send(resolved ? { kind: 'event', id, value } : { kind: 'result', id, value });
|
|
133
|
-
resolved = true;
|
|
134
|
-
};
|
|
135
|
-
subscriptions.set(id, topic === 'deployment-facts'
|
|
136
|
-
? watchFacts(deliver)
|
|
137
|
-
: watch(topic, topic === 'presentation' ? [app] : message.input, deliver));
|
|
194
|
+
if (serving)
|
|
195
|
+
observe(message.id, message.topic, message.input);
|
|
138
196
|
return;
|
|
139
197
|
}
|
|
140
|
-
const value = await answered(md, app, writtenBy, message.member, message.input, deploymentFacts);
|
|
141
|
-
if (serving)
|
|
142
|
-
send({ kind: 'result', id: message.id, value });
|
|
143
198
|
}
|
|
144
199
|
catch (error) {
|
|
145
|
-
if (serving)
|
|
146
|
-
send({
|
|
147
|
-
|
|
148
|
-
id: message.id,
|
|
149
|
-
message: error instanceof Error ? error.message : String(error),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
200
|
+
if (serving)
|
|
201
|
+
send({ kind: 'failure', id: message.id, ...described(error) });
|
|
202
|
+
return;
|
|
152
203
|
}
|
|
204
|
+
const { id, member, input } = message;
|
|
205
|
+
const pending = attempted(() => answered(NARROWED.has(WIRE.members[member].reach) ? view.md : md, app, writtenBy, member, input));
|
|
206
|
+
return reply(id, member === 'query' ? input[0] : undefined, pending);
|
|
153
207
|
};
|
|
154
208
|
port.addEventListener('message', (event) => {
|
|
155
209
|
if (!serving)
|
|
156
210
|
return;
|
|
157
|
-
const
|
|
158
|
-
if (wire === null)
|
|
159
|
-
return;
|
|
160
|
-
if (!wire.matching) {
|
|
161
|
-
send({ kind: 'refusal', refusal: PROTOCOL_MISMATCH });
|
|
162
|
-
detach();
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const message = request(wire.message);
|
|
211
|
+
const message = request(event.data);
|
|
166
212
|
if (message === null)
|
|
167
213
|
return;
|
|
168
214
|
void serve(message);
|
|
@@ -170,29 +216,76 @@ export function serveMdRuntime(options) {
|
|
|
170
216
|
port.addEventListener('close', detach);
|
|
171
217
|
port.start();
|
|
172
218
|
attachments.set(detach, send);
|
|
173
|
-
return
|
|
219
|
+
return {
|
|
220
|
+
detach,
|
|
221
|
+
narrow(next) {
|
|
222
|
+
if (serving)
|
|
223
|
+
view.narrow(next);
|
|
224
|
+
},
|
|
225
|
+
code(next, space) {
|
|
226
|
+
if (!serving)
|
|
227
|
+
return;
|
|
228
|
+
facts = { ...facts, code: next, space };
|
|
229
|
+
view.facts(facts);
|
|
230
|
+
},
|
|
231
|
+
search(next) {
|
|
232
|
+
if (!serving)
|
|
233
|
+
return;
|
|
234
|
+
facts = { ...facts, search: next };
|
|
235
|
+
view.facts(facts);
|
|
236
|
+
},
|
|
237
|
+
answered(queries, done) {
|
|
238
|
+
const keys = queries.map(queryKey);
|
|
239
|
+
if (keys.every((key) => answeredKeys.has(key)))
|
|
240
|
+
done();
|
|
241
|
+
else
|
|
242
|
+
awaited = { keys, done };
|
|
243
|
+
},
|
|
244
|
+
readiness(deliver) {
|
|
245
|
+
if (!serving)
|
|
246
|
+
return () => { };
|
|
247
|
+
const stop = view.watch('readiness', [], (value) => {
|
|
248
|
+
if (serving)
|
|
249
|
+
deliver(value);
|
|
250
|
+
});
|
|
251
|
+
const end = () => {
|
|
252
|
+
followed.delete(end);
|
|
253
|
+
stop();
|
|
254
|
+
};
|
|
255
|
+
followed.add(end);
|
|
256
|
+
return end;
|
|
257
|
+
},
|
|
258
|
+
};
|
|
174
259
|
}
|
|
175
260
|
return {
|
|
176
261
|
attach,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
throw new Error(AUTHORIZATION_ENDED);
|
|
180
|
-
deploymentFacts = structuredClone(value);
|
|
181
|
-
for (const deliver of factsObservers)
|
|
182
|
-
deliver(structuredClone(deploymentFacts));
|
|
262
|
+
seed(entry) {
|
|
263
|
+
runtime.seed(entry);
|
|
183
264
|
},
|
|
184
|
-
|
|
265
|
+
persisted(answer) {
|
|
266
|
+
runtime.persisted(answer);
|
|
267
|
+
},
|
|
268
|
+
shown(onScreen) {
|
|
269
|
+
runtime.shown(onScreen);
|
|
270
|
+
},
|
|
271
|
+
async endAuthorization(holder) {
|
|
185
272
|
authorized = false;
|
|
186
273
|
for (const [detach, send] of [...attachments]) {
|
|
187
274
|
send({ kind: 'ended' });
|
|
188
275
|
detach();
|
|
189
276
|
}
|
|
190
277
|
close();
|
|
191
|
-
await
|
|
192
|
-
|
|
278
|
+
if (!(await options.database.ask({ kind: 'authored.end', holder: holder ?? null }))) {
|
|
279
|
+
await options.shell.dropGeneration();
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
lose(locators) {
|
|
283
|
+
return runtime.lose(locators);
|
|
193
284
|
},
|
|
194
285
|
stop() {
|
|
195
286
|
return runtime.stop();
|
|
196
287
|
},
|
|
197
288
|
};
|
|
198
289
|
}
|
|
290
|
+
export { entrySeedOf } from './seed.js';
|
|
291
|
+
export { createRecovery, retryDelay, } from './recovery.js';
|
package/dist/identity.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export declare function changeBatchIdentity(at?: number): string;
|
|
2
|
+
export declare function identityTime(identity: string): number;
|
|
2
3
|
export declare function roomDraftRevision(): string;
|
|
4
|
+
export declare function chatDraftRevision(): string;
|
|
5
|
+
export declare function transferIdentity(): string;
|
|
6
|
+
export declare function binaryLocalId(): string;
|
|
3
7
|
//# sourceMappingURL=identity.d.ts.map
|
package/dist/identity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAED,wBAAgB,iBAAiB,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,EAAE,GAAE,MAAmB,GAAG,MAAM,CAWnE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAQD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
|
package/dist/identity.js
CHANGED
|
@@ -10,8 +10,23 @@ export function changeBatchIdentity(at = Date.now()) {
|
|
|
10
10
|
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
11
11
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
12
12
|
}
|
|
13
|
-
export function
|
|
13
|
+
export function identityTime(identity) {
|
|
14
|
+
return Number.parseInt(identity.replaceAll('-', '').slice(0, 12), 16);
|
|
15
|
+
}
|
|
16
|
+
function randomIdentity() {
|
|
14
17
|
const bytes = new Uint8Array(16);
|
|
15
18
|
crypto.getRandomValues(bytes);
|
|
16
19
|
return [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
17
20
|
}
|
|
21
|
+
export function roomDraftRevision() {
|
|
22
|
+
return randomIdentity();
|
|
23
|
+
}
|
|
24
|
+
export function chatDraftRevision() {
|
|
25
|
+
return randomIdentity();
|
|
26
|
+
}
|
|
27
|
+
export function transferIdentity() {
|
|
28
|
+
return randomIdentity();
|
|
29
|
+
}
|
|
30
|
+
export function binaryLocalId() {
|
|
31
|
+
return randomIdentity();
|
|
32
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
export type { AcceptedMessage, ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, Authorization, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, ChangeAuthor, ContractUnavailable, ConversationAction,
|
|
2
|
-
export type { Change, ChangeBatch, Precondition, WrittenBy } from './change.js';
|
|
3
|
-
export type { ChatDraft, ChatDraftSurface, ConversationEntry, ConversationOptions, ConversationSurface, ConversationView,
|
|
4
|
-
export type {
|
|
5
|
-
export type { AppRoom, AppSlot, AppSlotEntry, AppTypedSelection, ConnectionRefusal, ConnectionRefusalReason, HistoryQuery, MdRuntime, MdRuntimeOptions, PresentationSurface, RoomDraftSurface, RoomTypes, SavedRoomDraft, SaveResult, } from './connection.js';
|
|
1
|
+
export type { AcceptedMessage, AcceptedRoom, ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, AttachRequest, AttachResult, Authorization, BinaryFile, BinaryLinkResult, BinaryRequest, BinaryResult, BootstrapInventory, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, ChangeAuthor, ContractUnavailable, ConversationAction, ConversationAgents, ConversationEvent, ConversationHistories, ConversationHistoryPage, ConversationHistoryRequest, ConversationMessage, ConversationStream, DiscoverResult, DiscoveredRoom, Discovery, DiscoveryScope, HistoryAuthor, HistoryRequest, HistoryResult, HistoryRetention, HistoryRevision, HeldContent, HeldFile, HeldRevisions, HeldRoom, KeptReceipt, ListedConversation, MdModelIdentity, Member, MutationRequest, MutationResult, PageToken, ProviderLimit, ProviderRefusal, RefreshPage, RefreshRequest, RefreshResult, Retention, RetryableRefusal, RevokedAuthorization, RoomModels, RoomNotReadable, RoomStream, RoomStreamEvent, RoomVersionAt, ServiceMode, ServiceModeSignal, StreamReceipts, TransportUncertainty, TurnContext, TurnOperation, TypedSelection, } from './adapter.js';
|
|
2
|
+
export type { Change, ChangeBatch, Precondition, RoomMove, WrittenBy } from './change.js';
|
|
3
|
+
export type { ChatDraft, ChatDraftSurface, ConversationAgent, ConversationEntry, ConversationOptions, ConversationState, ConversationSurface, ConversationView, RunningTurn, } from './conversation.js';
|
|
4
|
+
export type { AppRoom, AppTypedSelection, BinaryFileSurface, ConnectionRefusal, ConnectionRefusalCode, HistoryQuery, MdRuntime, MdRuntimeOptions, PresentationSurface, RoomDraftSurface, RoomSchemas, SavedParts, SavedRoomDraft, SaveResult, } from './connection.js';
|
|
6
5
|
export type { Observation } from './observation.js';
|
|
7
|
-
export type {
|
|
8
|
-
export type {
|
|
6
|
+
export type { AttachAnswer, BinaryAnswer, BinaryLinkAnswer, CallResult, DownloadAnswer, Failure, HistoryAnswer, Offline, QueueEntry, Resolution, Submission, } from './outcome.js';
|
|
7
|
+
export type { BinaryFileRecord } from './binary.js';
|
|
8
|
+
export type { RuntimeError } from './failure.js';
|
|
9
|
+
export type { ChangedPart, FieldValue, ReturnReason, RoomDraft, RoomDraftCreation, RoomDraftParts, RoomDraftWrite, TextParts, } from './room-draft.js';
|
|
9
10
|
export type { SaveRefusal } from './save.js';
|
|
10
|
-
export type { DocumentHit, DocumentPart, MessageHit, SearchRequest, SearchResult, } from './search.js';
|
|
11
|
+
export type { DocumentHit, DocumentPart, MessageHit, MessagePart, SearchCoverage, SearchHits, SearchPending, SearchRequest, SearchResult, SearchUndeclared, Snippet, } from './search.js';
|
|
12
|
+
export { departure } from './change.js';
|
|
13
|
+
export { partsAfter } from './room-draft.js';
|
|
14
|
+
export { cutName, nameFrom, transliterated } from './name.js';
|
|
15
|
+
export { HISTORY_CONVERSATIONS, SESSION_STARTED } from './conversation.js';
|
|
11
16
|
export { changeBatchIdentity } from './identity.js';
|
|
12
|
-
export {
|
|
17
|
+
export { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
18
|
+
export { entriesIn, patching, sortedKeys } from './shared.js';
|
|
19
|
+
export { attempts, identities, intentOf, type Answered, type Attempt, type Attempts, type Identities, } from './attempt.js';
|
|
20
|
+
export { expectedList, expecting, type ExpectedOf, type Expecting } from './expectation.js';
|
|
13
21
|
export type { RuntimeShell } from './durability.js';
|
|
22
|
+
export type { CodeAvailability, ConnectionAvailability, ConversationCoverage, Durability, HouseOutcome, Installation, InstallationAmount, InstallationPause, InstallationStep, Persistence, Readiness, ReadinessStatus, RefusedRoom, RoomCoverage, RoomPreparation, SearchObligation, Space, TargetCoverage, } from './readiness.js';
|
|
14
23
|
export type { AttentionEntry, SyncStatus } from './status.js';
|
|
15
|
-
export type { Backlink, Direction, DocumentQuery, DocumentResult, Filter, GroupQuery, GroupResult, Key, LocalQuery, OrderOptions, Predicate, QueryDocument, QueryGroup, QueryResult, Related, Select, Value, Where, } from './query.js';
|
|
24
|
+
export type { Awaits, Backlink, CoveredRoom, Direction, DocumentQuery, DocumentResult, Filter, GroupQuery, GroupResult, Key, LocalQuery, OrderOptions, PendingResult, PendingRoom, Predicate, QueryCoverage, QueryDocument, QueryGroup, QueryResult, QueryRows, Related, Select, Value, Where, } from './query.js';
|
|
16
25
|
export type { MdType, ModelIdentity, ModelSnapshot, ModelState, ModelResult, TypesResult, ValidationReceipt, } from './model.js';
|
|
17
26
|
export type { OperationScopes, ReplicaAdmission, ScopedRefusal } from './adapter.js';
|
|
18
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
export { departure } from './change.js';
|
|
2
|
+
export { partsAfter } from './room-draft.js';
|
|
3
|
+
export { cutName, nameFrom, transliterated } from './name.js';
|
|
4
|
+
export { HISTORY_CONVERSATIONS, SESSION_STARTED } from './conversation.js';
|
|
1
5
|
export { changeBatchIdentity } from './identity.js';
|
|
2
|
-
export {
|
|
6
|
+
export { paced, ROW_WEIGHT, stepped } from './turn.js';
|
|
7
|
+
export { entriesIn, patching, sortedKeys } from './shared.js';
|
|
8
|
+
export { attempts, identities, intentOf, } from './attempt.js';
|
|
9
|
+
export { expectedList, expecting } from './expectation.js';
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChangeSet } from './change-set.js';
|
|
2
|
+
import { type KeyedResult, type QueryMessage } from './observation.js';
|
|
3
|
+
import type { PendingResult, Plan, QueryCoverage } from './query.js';
|
|
4
|
+
import type { QueryRoom } from './tables.js';
|
|
5
|
+
export type Cover = {
|
|
6
|
+
coverage: QueryCoverage;
|
|
7
|
+
rooms: readonly QueryRoom[];
|
|
8
|
+
} | PendingResult;
|
|
9
|
+
export type Ran = KeyedResult & {
|
|
10
|
+
readonly current: () => boolean;
|
|
11
|
+
};
|
|
12
|
+
export type Run = (plan: Plan, cover: () => Cover) => Promise<Ran>;
|
|
13
|
+
type Listener = (message: QueryMessage) => void;
|
|
14
|
+
export type LiveQueries = {
|
|
15
|
+
touched(set: ChangeSet): void;
|
|
16
|
+
recover(): void;
|
|
17
|
+
watch(plan: Plan, identity: string, cover: () => Cover, deliver: Listener): () => void;
|
|
18
|
+
close(): void;
|
|
19
|
+
};
|
|
20
|
+
export declare function createLiveQueries(run: Run): LiveQueries;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=live.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"live.d.ts","sourceRoot":"","sources":["../src/live.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,KAAK,GAAG;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;CAAE,GAAG,aAAa,CAAC;AAE7F,MAAM,MAAM,GAAG,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAA;CAAE,CAAC;AAEpE,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEnE,KAAK,QAAQ,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;AAchD,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,IAAI,IAAI,CAAC;IAChB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,EAAE,OAAO,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACvF,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAoCF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAuFvD"}
|
package/dist/live.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { changeOf, digestOf, } from './observation.js';
|
|
2
|
+
import { roomOfKey } from './rows.js';
|
|
3
|
+
function narrowed(plan) {
|
|
4
|
+
return (plan.paths !== null &&
|
|
5
|
+
plan.hop === null &&
|
|
6
|
+
plan.backlinks === null &&
|
|
7
|
+
!(plan.shape.kind === 'documents' && plan.shape.backlinks));
|
|
8
|
+
}
|
|
9
|
+
function reads(plan, locator) {
|
|
10
|
+
if (plan.locked.includes(locator))
|
|
11
|
+
return false;
|
|
12
|
+
if (plan.rooms !== null && !plan.rooms.includes(locator))
|
|
13
|
+
return false;
|
|
14
|
+
if (plan.reach === null)
|
|
15
|
+
return true;
|
|
16
|
+
return (plan.reach.rooms.includes(locator) ||
|
|
17
|
+
plan.reach.documents.some((document) => roomOfKey(document) === locator) ||
|
|
18
|
+
plan.reach.areas.some((area) => area.room === locator && area.types.length > 0));
|
|
19
|
+
}
|
|
20
|
+
function affected(plan, set) {
|
|
21
|
+
if (set.rooms.some((locator) => reads(plan, locator)))
|
|
22
|
+
return true;
|
|
23
|
+
const paths = narrowed(plan) ? new Set(plan.paths) : null;
|
|
24
|
+
return set.documents.some(({ locator, path }) => reads(plan, locator) && (paths === null || path === null || paths.has(path)));
|
|
25
|
+
}
|
|
26
|
+
function shown(entry) {
|
|
27
|
+
const cover = entry.cover();
|
|
28
|
+
return JSON.stringify('pending' in cover ? cover : cover.coverage);
|
|
29
|
+
}
|
|
30
|
+
export function createLiveQueries(run) {
|
|
31
|
+
const entries = new Map();
|
|
32
|
+
let closed = false;
|
|
33
|
+
function deliver(entry, next) {
|
|
34
|
+
const previous = entry.digest;
|
|
35
|
+
entry.digest = digestOf(next);
|
|
36
|
+
entry.covered = JSON.stringify('pending' in next.result ? next.result : next.result.coverage);
|
|
37
|
+
const change = previous === undefined ? null : changeOf(previous, next);
|
|
38
|
+
if (change !== null) {
|
|
39
|
+
for (const listener of entry.ready)
|
|
40
|
+
listener(change);
|
|
41
|
+
}
|
|
42
|
+
for (const listener of entry.fresh) {
|
|
43
|
+
entry.ready.add(listener);
|
|
44
|
+
listener(next);
|
|
45
|
+
}
|
|
46
|
+
entry.fresh.clear();
|
|
47
|
+
}
|
|
48
|
+
function schedule(entry) {
|
|
49
|
+
if (closed || entry.listeners.size === 0)
|
|
50
|
+
return;
|
|
51
|
+
if (entry.running) {
|
|
52
|
+
entry.dirty = true;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
entry.running = true;
|
|
56
|
+
void (async () => {
|
|
57
|
+
try {
|
|
58
|
+
for (;;) {
|
|
59
|
+
entry.dirty = false;
|
|
60
|
+
const { current, ...next } = await run(entry.plan, entry.cover);
|
|
61
|
+
if (closed || entry.listeners.size === 0)
|
|
62
|
+
return;
|
|
63
|
+
deliver(entry, next);
|
|
64
|
+
if (!(entry.dirty && !current()) && shown(entry) === entry.covered)
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
entry.dirty = false;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
entry.running = false;
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
touched(set) {
|
|
78
|
+
for (const entry of entries.values()) {
|
|
79
|
+
if (affected(entry.plan, set))
|
|
80
|
+
schedule(entry);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
recover() {
|
|
84
|
+
for (const entry of entries.values()) {
|
|
85
|
+
if (entry.running)
|
|
86
|
+
continue;
|
|
87
|
+
if (entry.digest === undefined || shown(entry) !== entry.covered)
|
|
88
|
+
schedule(entry);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
watch(plan, identity, cover, listener) {
|
|
92
|
+
let entry = entries.get(identity);
|
|
93
|
+
if (entry === undefined) {
|
|
94
|
+
entry = {
|
|
95
|
+
plan,
|
|
96
|
+
cover,
|
|
97
|
+
listeners: new Set(),
|
|
98
|
+
fresh: new Set(),
|
|
99
|
+
ready: new Set(),
|
|
100
|
+
digest: undefined,
|
|
101
|
+
covered: '',
|
|
102
|
+
dirty: false,
|
|
103
|
+
running: false,
|
|
104
|
+
};
|
|
105
|
+
entries.set(identity, entry);
|
|
106
|
+
}
|
|
107
|
+
const held = entry;
|
|
108
|
+
held.listeners.add(listener);
|
|
109
|
+
held.fresh.add(listener);
|
|
110
|
+
schedule(held);
|
|
111
|
+
return () => {
|
|
112
|
+
held.listeners.delete(listener);
|
|
113
|
+
held.fresh.delete(listener);
|
|
114
|
+
held.ready.delete(listener);
|
|
115
|
+
if (held.listeners.size === 0 && entries.get(identity) === held)
|
|
116
|
+
entries.delete(identity);
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
close() {
|
|
120
|
+
closed = true;
|
|
121
|
+
entries.clear();
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MdRuntimeClient } from './client.js';
|
|
2
|
+
import type { ShownAnswer } from './outcome.js';
|
|
3
|
+
export declare const ROOM_MEDIA = "room-media";
|
|
4
|
+
type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
|
|
5
|
+
export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
|
|
6
|
+
export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient, registry?: CustomElementRegistry): void;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +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,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,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,CAC7B,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,EAClD,QAAQ,GAAE,qBAAsC,GAC/C,IAAI,CAkLN"}
|