@agentshouse/mdruntime 0.1.0-cff1b70c6ad46 → 0.1.0-cffcba9cd9c2f
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/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +48 -124
- package/dist/actions.js +2 -2
- package/dist/adapter.d.ts +16 -44
- package/dist/adapter.d.ts.map +1 -1
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -19
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -3
- package/dist/collection.d.ts +22 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +12 -2
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +13 -13
- package/dist/conversation-live.d.ts +3 -4
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +2 -3
- package/dist/conversation.d.ts +4 -6
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +43 -71
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +5 -3
- package/dist/failure.d.ts +1 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -0
- package/dist/host.d.ts +17 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +16 -4
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/install.d.ts +0 -1
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +46 -57
- package/dist/job.d.ts +1 -29
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +2 -49
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +9 -6
- package/dist/listing.d.ts +3 -4
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +14 -22
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -1
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +2 -1
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +3 -3
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +8 -6
- package/dist/messages.d.ts +0 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +0 -14
- package/dist/model.d.ts +0 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +0 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +101 -126
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +6 -4
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +32 -21
- package/dist/parts.d.ts +3 -52
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +15 -120
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +10 -3
- package/dist/queue.d.ts +32 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +402 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +5 -4
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +4 -1
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +3 -1
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +12 -14
- package/dist/room-draft.d.ts +3 -2
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +33 -20
- package/dist/room-drafts.js +3 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -4
- package/dist/runtime.d.ts +5 -16
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +5 -10
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +59 -56
- package/dist/saves.d.ts +2 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +23 -349
- package/dist/shown.d.ts +2 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +13 -6
- package/dist/socket/rooms.d.ts +1 -4
- package/dist/socket/rooms.d.ts.map +1 -1
- package/dist/socket.d.ts +0 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/store/records.d.ts +0 -2
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +0 -3
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +3 -3
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +2 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +18 -20
- package/dist/tables.d.ts +0 -4
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +1 -4
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -2
- package/dist/wire.d.ts +4 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +3 -3
- package/package.json +3 -2
package/dist/parts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../src/parts.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../src/parts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAGnF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,GAAG,IAAI,CAMjE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,QAAQ,EAAE,CAOtE"}
|
package/dist/parts.js
CHANGED
|
@@ -1,126 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { excerpt
|
|
3
|
-
const MARKERS = ['mode', 'compaction', 'retry', 'model', 'job'];
|
|
4
|
-
function partOf(raw) {
|
|
5
|
-
const part = record(raw);
|
|
6
|
-
switch (text(part, 'type')) {
|
|
7
|
-
case 'text':
|
|
8
|
-
case 'reasoning': {
|
|
9
|
-
const said = text(part, 'text');
|
|
10
|
-
return said === null ? null : { type: part.type, text: said };
|
|
11
|
-
}
|
|
12
|
-
case 'commands':
|
|
13
|
-
return typeof part.count === 'number' ? { type: 'commands', count: part.count } : null;
|
|
14
|
-
case 'subagent':
|
|
15
|
-
return {
|
|
16
|
-
type: 'subagent',
|
|
17
|
-
description: text(part, 'description') ?? '',
|
|
18
|
-
done: part.status === 'done',
|
|
19
|
-
result: text(part, 'result'),
|
|
20
|
-
};
|
|
21
|
-
case 'message': {
|
|
22
|
-
const command = text(part, 'command');
|
|
23
|
-
return command === null ? null : { type: 'message', command, target: text(part, 'target') };
|
|
24
|
-
}
|
|
25
|
-
case 'image': {
|
|
26
|
-
const path = text(part, 'file');
|
|
27
|
-
const name = text(part, 'name');
|
|
28
|
-
return path === null || name === null
|
|
29
|
-
? null
|
|
30
|
-
: { type: 'image', path, name, mediaType: text(part, 'media_type') ?? '' };
|
|
31
|
-
}
|
|
32
|
-
case 'marker': {
|
|
33
|
-
const marker = text(part, 'marker');
|
|
34
|
-
return marker === null || !MARKERS.includes(marker)
|
|
35
|
-
? null
|
|
36
|
-
: { type: 'marker', marker: marker, text: text(part, 'text') ?? '' };
|
|
37
|
-
}
|
|
38
|
-
case 'plan':
|
|
39
|
-
return {
|
|
40
|
-
type: 'plan',
|
|
41
|
-
steps: list(part, 'entries').flatMap((entry) => {
|
|
42
|
-
const step = record(entry);
|
|
43
|
-
const content = text(step, 'content');
|
|
44
|
-
return content === null ? [] : [{ content, status: text(step, 'status') ?? '' }];
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
default:
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function partsOf(raw) {
|
|
52
|
-
return raw.flatMap((one) => partOf(one) ?? []);
|
|
53
|
-
}
|
|
54
|
-
export function contextIn(raw) {
|
|
55
|
-
const held = record(raw);
|
|
56
|
-
return typeof held.used === 'number' && typeof held.window === 'number' && held.window > 0
|
|
57
|
-
? { used: held.used, window: held.window }
|
|
58
|
-
: null;
|
|
59
|
-
}
|
|
60
|
-
const TOKEN_KINDS = ['input', 'output', 'cache_read', 'cache_write'];
|
|
61
|
-
export function tokensIn(raw) {
|
|
62
|
-
const held = record(raw);
|
|
63
|
-
const counts = TOKEN_KINDS.map((kind) => held[kind]);
|
|
64
|
-
return counts.every((count) => typeof count === 'number')
|
|
65
|
-
? counts.reduce((sum, count) => sum + count, 0)
|
|
66
|
-
: null;
|
|
67
|
-
}
|
|
1
|
+
import { isOwn } from '@agentshouse/session-content';
|
|
2
|
+
import { excerpt } from './read.js';
|
|
68
3
|
export function counted(count) {
|
|
69
4
|
return count === 1 ? '1 command' : `${count} commands`;
|
|
70
5
|
}
|
|
71
|
-
export function runningLine(
|
|
72
|
-
const
|
|
73
|
-
const note =
|
|
6
|
+
export function runningLine(parts) {
|
|
7
|
+
const newest = parts.filter(isOwn).reverse();
|
|
8
|
+
const note = newest.find((part) => part.type === 'text' && part.text.trim() !== '');
|
|
74
9
|
if (note?.type === 'text')
|
|
75
10
|
return excerpt(note.text);
|
|
76
|
-
const
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
export function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const open = [];
|
|
87
|
-
for (const { turn, parts, ended } of turns) {
|
|
88
|
-
for (const part of parts) {
|
|
89
|
-
if (part.type === 'subagent') {
|
|
90
|
-
const key = `subagent\u0000${part.description}`;
|
|
91
|
-
if (part.done)
|
|
92
|
-
closeLast(open, key);
|
|
93
|
-
else if (ended) {
|
|
94
|
-
open.push({
|
|
95
|
-
turn,
|
|
96
|
-
key,
|
|
97
|
-
work: { kind: 'subagent', title: part.description, next: null, activity: null },
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (part.type !== 'marker' || part.marker !== 'job')
|
|
103
|
-
continue;
|
|
104
|
-
markerMoved(open, part.text, (job, key) => ended
|
|
105
|
-
? {
|
|
106
|
-
turn,
|
|
107
|
-
key,
|
|
108
|
-
work: {
|
|
109
|
-
kind: job.kind === 'started' ? 'job' : 'schedule',
|
|
110
|
-
title: job.label,
|
|
111
|
-
next: job.next,
|
|
112
|
-
activity: null,
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
: null);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const doing = [...subagents];
|
|
119
|
-
const under = new Map();
|
|
120
|
-
for (const { turn, work } of open) {
|
|
121
|
-
const at = work.kind === 'subagent' ? doing.findIndex((one) => one.description === work.title) : -1;
|
|
122
|
-
const shown = at === -1 ? work : { ...work, activity: doing.splice(at, 1)[0].activity };
|
|
123
|
-
under.set(turn, [...(under.get(turn) ?? []), shown]);
|
|
124
|
-
}
|
|
125
|
-
return under;
|
|
11
|
+
const call = newest.find((part) => part.type === 'call');
|
|
12
|
+
return call?.type === 'call' && call.line !== '' ? call.line : null;
|
|
13
|
+
}
|
|
14
|
+
export function workOf(state) {
|
|
15
|
+
return (state?.running ?? []).map(({ kind, label, progress, next }) => ({
|
|
16
|
+
kind: kind === 'subagent' || kind === 'schedule' ? kind : 'job',
|
|
17
|
+
title: label,
|
|
18
|
+
next,
|
|
19
|
+
activity: progress,
|
|
20
|
+
}));
|
|
126
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preparation.d.ts","sourceRoot":"","sources":["../src/preparation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preparation.d.ts","sourceRoot":"","sources":["../src/preparation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAE3B,KAAK,SAAS,EAEf,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAK5C,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CAClD,CAAC;AAuCF,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,GAAE,SAAS,MAAM,EAAO,QA+BzE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAElE;AAmDD,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAMrF;AAmFD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,cAAc,EAAE,iBAI3F;AAED,wBAAgB,cAAc,CAC5B,EAAE,KAAK,EAAE,EAAE,OAAO,EAClB,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,GACtC,MAAM,IAAI,CAQZ;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,QAMtC"}
|
package/dist/preparation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { changeSet } from './change-set.js';
|
|
2
|
+
import { uncaught } from './failure.js';
|
|
2
3
|
import { installationOf } from './install.js';
|
|
3
4
|
import { listedLocators } from './listing.js';
|
|
4
5
|
import { planReach } from './reach.js';
|
|
@@ -57,8 +58,9 @@ export function prepare(runtime, locators = []) {
|
|
|
57
58
|
await prepareReplica(runtime, waiting).catch((error) => unpreparedBy(runtime, waiting, error));
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
catch {
|
|
61
|
+
catch (error) {
|
|
61
62
|
journal.record('preparation failed');
|
|
63
|
+
uncaught(error);
|
|
62
64
|
}
|
|
63
65
|
finally {
|
|
64
66
|
device.set({ preparing: false });
|
|
@@ -165,8 +167,9 @@ function establish(runtime, name) {
|
|
|
165
167
|
.then(() => {
|
|
166
168
|
store.readiness.queue();
|
|
167
169
|
void probeEachMinute(runtime);
|
|
168
|
-
}, () => {
|
|
170
|
+
}, (error) => {
|
|
169
171
|
journal.record(`target record failed ${name}`);
|
|
172
|
+
uncaught(error);
|
|
170
173
|
})
|
|
171
174
|
.finally(() => {
|
|
172
175
|
const establishing = new Set(device.now().establishing);
|
|
@@ -218,7 +221,11 @@ async function probeEachMinute(runtime) {
|
|
|
218
221
|
const idle = () => !space.full() || space.probing() || socket.closed();
|
|
219
222
|
if (idle())
|
|
220
223
|
return;
|
|
221
|
-
|
|
224
|
+
const installed = await installedTarget(runtime).catch((error) => {
|
|
225
|
+
uncaught(error);
|
|
226
|
+
return false;
|
|
227
|
+
});
|
|
228
|
+
if (!installed)
|
|
222
229
|
return;
|
|
223
230
|
if (idle())
|
|
224
231
|
return;
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MutationResult } from './adapter.js';
|
|
2
|
+
import { type ChangeBatch } from './change.js';
|
|
3
|
+
import { type HeldReplica, type ReplicaRecord, type Returned, type Slice, type VisibleLayer } from './replica.js';
|
|
4
|
+
import type { Runtime } from './runtime.js';
|
|
5
|
+
import type { PendingState, RoomCommit, Store, View, Work } from './store.js';
|
|
6
|
+
export type Queueing = Pick<Runtime, 'store' | 'journal' | 'localSaves'> & {
|
|
7
|
+
readonly socket: Pick<Runtime['socket'], 'continuing'>;
|
|
8
|
+
};
|
|
9
|
+
export type Restand = {
|
|
10
|
+
readonly locator: string;
|
|
11
|
+
readonly record: ReplicaRecord;
|
|
12
|
+
readonly accepted?: string;
|
|
13
|
+
readonly adopted?: Returned;
|
|
14
|
+
readonly installed?: Pick<RoomCommit, 'published' | 'refreshed'>;
|
|
15
|
+
readonly refused?: true;
|
|
16
|
+
readonly after?: () => void;
|
|
17
|
+
};
|
|
18
|
+
type Answer = Extract<MutationResult, {
|
|
19
|
+
kind: 'conflicted' | 'rejected';
|
|
20
|
+
}>;
|
|
21
|
+
export declare function withdrawable(states: ReadonlyMap<string, PendingState>): (batch: ChangeBatch) => boolean;
|
|
22
|
+
export declare function sliceAt(store: Store, record: ReplicaRecord, view: View, queue: readonly ChangeBatch[], extra?: Iterable<string>, moved?: Iterable<string>): Promise<Slice>;
|
|
23
|
+
export declare function replayed(store: Store, record: ReplicaRecord, confirmedLayer: Slice, queue: readonly ChangeBatch[]): import("./turn.js").Later<import("./replica.js").Replayed>;
|
|
24
|
+
export declare function overlayDiff(record: ReplicaRecord, before: HeldReplica | undefined, visible: VisibleLayer, touched: ReadonlySet<string>): Promise<{
|
|
25
|
+
overlay: NonNullable<RoomCommit['overlay']>;
|
|
26
|
+
touched: ReadonlySet<string>;
|
|
27
|
+
}>;
|
|
28
|
+
export declare function settle(runtime: Queueing, locators: readonly string[], decide: (held: ReadonlyMap<string, Work>) => Promise<readonly Restand[]>): Promise<void>;
|
|
29
|
+
export declare function answered(runtime: Queueing, locator: string, head: ChangeBatch, answer: Answer): Promise<void>;
|
|
30
|
+
export declare function unpair(runtime: Queueing): Promise<void>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAmC,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAGhF,OAAO,EAUL,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAGV,YAAY,EACZ,UAAU,EAEV,KAAK,EACL,IAAI,EACJ,IAAI,EACL,MAAM,YAAY,CAAC;AAGpB,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,YAAY,CAAC,GAAG;IACzE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,C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SAAS,MAAM,EAAE,EAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,OAAO,CAAC,SAAS,OAAO,EAAE,CAAC,GACvE,OAAO,CAAC,IAAI,CAAC,CAoCf;AAED,wBAAgB,QAAQ,CACtB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAiDf;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvD"}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { changeSet, mergeChangeSets } from './change-set.js';
|
|
2
|
+
import { leaving as leavingIn, partnerOf } from './change.js';
|
|
3
|
+
import { composedOf, definitionsAt } from './collection.js';
|
|
4
|
+
import { roomDraftRevision } from './identity.js';
|
|
5
|
+
import { landed, movedBy, overlayOf, replaying, slicing, slicingWith, standing, storedRecord, touchedBy, } from './replica.js';
|
|
6
|
+
import { returnedBy, returnedInto } from './room-draft.js';
|
|
7
|
+
import { documentKey } from './rows.js';
|
|
8
|
+
import { stepped } from './turn.js';
|
|
9
|
+
export function withdrawable(states) {
|
|
10
|
+
return (batch) => {
|
|
11
|
+
const state = states.get(batch.id);
|
|
12
|
+
return state !== undefined && state.submission.state !== 'submitted' && !state.lost;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export async function sliceAt(store, record, view, queue, extra = [], moved = []) {
|
|
16
|
+
const local = await store.open();
|
|
17
|
+
const needed = new Set([...touchedBy(queue), ...extra]);
|
|
18
|
+
const movedPaths = [...new Set([...movedBy(queue, record.locator), ...moved])];
|
|
19
|
+
if (movedPaths.length > 0) {
|
|
20
|
+
for (const { path } of await local.referrers(record.key, view, movedPaths)) {
|
|
21
|
+
needed.add(path);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const paths = [...needed];
|
|
25
|
+
return stepped(slicing(await local.entries(record.key, view, paths), paths));
|
|
26
|
+
}
|
|
27
|
+
async function landedWhole(store, record, batch, confirmedLayer, current) {
|
|
28
|
+
if (!landed(batch, confirmedLayer, store.composed(record), current))
|
|
29
|
+
return false;
|
|
30
|
+
const partner = partnerOf(batch, record.locator);
|
|
31
|
+
if (partner === null)
|
|
32
|
+
return true;
|
|
33
|
+
const other = await store.replica(partner);
|
|
34
|
+
const half = other?.queue.find((one) => one.id === batch.id);
|
|
35
|
+
if (other === undefined || half === undefined)
|
|
36
|
+
return false;
|
|
37
|
+
return landed(half, await sliceAt(store, other.record, 'confirmed', [half]), store.composed(other.record));
|
|
38
|
+
}
|
|
39
|
+
async function returnedDrafts(store, locator, work, leaving, composition) {
|
|
40
|
+
const written = new Map();
|
|
41
|
+
for (const { batch, returned } of leaving) {
|
|
42
|
+
if (returned === null || batch.between?.destination.room === locator)
|
|
43
|
+
continue;
|
|
44
|
+
for (const saved of work.states.get(batch.id)?.drafts ?? []) {
|
|
45
|
+
const existing = written.get(saved.path) ?? (await store.draft(locator, saved.path));
|
|
46
|
+
written.set(saved.path, {
|
|
47
|
+
locator,
|
|
48
|
+
path: saved.path,
|
|
49
|
+
revision: roomDraftRevision(),
|
|
50
|
+
parts: returnedInto(existing?.parts, saved.parts, composition === undefined ? undefined : definitionsAt(composition, saved.path)),
|
|
51
|
+
returned,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return written;
|
|
56
|
+
}
|
|
57
|
+
async function carriedBack(store, locator, unlanded, written) {
|
|
58
|
+
const back = new Map();
|
|
59
|
+
const taken = [];
|
|
60
|
+
for (const batch of unlanded) {
|
|
61
|
+
const between = batch.between;
|
|
62
|
+
if (between === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
const source = between.source.room;
|
|
65
|
+
const destination = between.destination.room;
|
|
66
|
+
const local = await store.open();
|
|
67
|
+
const arrived = (await local.pending(destination, batch.id)).state?.drafts ?? [];
|
|
68
|
+
for (const { path: to } of arrived) {
|
|
69
|
+
const record = await store.draft(destination, to);
|
|
70
|
+
const path = between.moves.find((move) => move.to === to)?.path;
|
|
71
|
+
if (record === undefined || path === undefined)
|
|
72
|
+
continue;
|
|
73
|
+
const [into, key] = source === locator ? [written, path] : [back, documentKey(source, path)];
|
|
74
|
+
const existing = into.get(key) ?? (await store.draft(source, path));
|
|
75
|
+
const held = await store.record(source);
|
|
76
|
+
taken.push({ locator: destination, path: to });
|
|
77
|
+
into.set(key, {
|
|
78
|
+
locator: source,
|
|
79
|
+
path,
|
|
80
|
+
revision: roomDraftRevision(),
|
|
81
|
+
parts: returnedInto(existing?.parts, record.parts, held === undefined ? undefined : definitionsAt(store.composed(held), path)),
|
|
82
|
+
returned: existing?.returned ?? null,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const records = [...back.values()];
|
|
87
|
+
const elsewhere = taken.filter((one) => one.locator !== locator);
|
|
88
|
+
const rooms = new Set([...records, ...elsewhere].map((one) => one.locator));
|
|
89
|
+
return {
|
|
90
|
+
taken: taken.filter((one) => one.locator === locator).map(({ path }) => path),
|
|
91
|
+
writes: [...rooms].map((room) => ({
|
|
92
|
+
locator: room,
|
|
93
|
+
roomDrafts: records.filter((record) => record.locator === room),
|
|
94
|
+
consumedRoomDrafts: elsewhere.filter((one) => one.locator === room).map(({ path }) => path),
|
|
95
|
+
})),
|
|
96
|
+
changes: [...rooms].map((room) => changeSet(room, {
|
|
97
|
+
drafts: [...records, ...elsewhere]
|
|
98
|
+
.filter((one) => one.locator === room)
|
|
99
|
+
.map(({ path }) => path),
|
|
100
|
+
})),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function confirmedAgain(store, locator) {
|
|
104
|
+
store.installs.change(locator, (held) => ({
|
|
105
|
+
...held,
|
|
106
|
+
confirmations: held.confirmations + 1,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
export function replayed(store, record, confirmedLayer, queue) {
|
|
110
|
+
return stepped(replaying(confirmedLayer, queue, record.locator, store.composed(record)));
|
|
111
|
+
}
|
|
112
|
+
export async function overlayDiff(record, before, visible, touched) {
|
|
113
|
+
const kept = before !== undefined && before.record.key === record.key ? before.overlaid : new Set();
|
|
114
|
+
return {
|
|
115
|
+
overlay: {
|
|
116
|
+
set: await stepped(overlayOf(visible, touched)),
|
|
117
|
+
cleared: [...kept].filter((path) => !touched.has(path)),
|
|
118
|
+
},
|
|
119
|
+
touched,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function unsent(state, batch, locator) {
|
|
123
|
+
if (state === undefined)
|
|
124
|
+
return false;
|
|
125
|
+
return !leavingIn(batch, locator) || withdrawable(new Map([[batch.id, state]]))(batch);
|
|
126
|
+
}
|
|
127
|
+
async function together(runtime, local, settlements) {
|
|
128
|
+
const settled = new Set(settlements.map(({ locator }) => locator));
|
|
129
|
+
const all = [...settlements];
|
|
130
|
+
for (let wave = settlements; wave.length > 0;) {
|
|
131
|
+
const partnered = new Map();
|
|
132
|
+
for (const { locator, left } of wave) {
|
|
133
|
+
for (const batch of left) {
|
|
134
|
+
const partner = partnerOf(batch, locator);
|
|
135
|
+
if (partner === null ||
|
|
136
|
+
settled.has(partner) ||
|
|
137
|
+
!unsent((await local.pending(partner, batch.id)).state, batch, partner)) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
partnered.set(partner, [...(partnered.get(partner) ?? []), batch]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const partners = [];
|
|
144
|
+
for (const [partner, batches] of partnered) {
|
|
145
|
+
settled.add(partner);
|
|
146
|
+
partners.push(await unpairing(runtime, local, partner, batches));
|
|
147
|
+
}
|
|
148
|
+
all.push(...partners);
|
|
149
|
+
wave = partners;
|
|
150
|
+
}
|
|
151
|
+
const answer = await local.commit({
|
|
152
|
+
rooms: all.flatMap(({ commit }) => commit.rooms),
|
|
153
|
+
writes: all.flatMap(({ commit }) => commit.writes),
|
|
154
|
+
});
|
|
155
|
+
return mergeChangeSets(all.map((one) => one.apply(answer)));
|
|
156
|
+
}
|
|
157
|
+
async function settlement(runtime, local, locator, work, record, queue, settling = {}) {
|
|
158
|
+
const { store, journal, localSaves } = runtime;
|
|
159
|
+
const before = work.replica;
|
|
160
|
+
const view = settling.view ?? 'confirmed';
|
|
161
|
+
const previousQueue = work.queue;
|
|
162
|
+
const overrides = settling.changes;
|
|
163
|
+
const read = await sliceAt(store, record, view, queue, [
|
|
164
|
+
...(before !== undefined && before.record.key === record.key ? before.overlaid : []),
|
|
165
|
+
...(overrides?.set.map(({ path }) => path) ?? []),
|
|
166
|
+
...(overrides?.removed ?? []),
|
|
167
|
+
]);
|
|
168
|
+
const confirmedLayer = overrides === undefined
|
|
169
|
+
? read
|
|
170
|
+
: await stepped(slicingWith(read, overrides.set, overrides.removed));
|
|
171
|
+
const composition = store.composed(record);
|
|
172
|
+
const shown = queue.filter((batch) => {
|
|
173
|
+
const held = store.landed.of(locator, batch.id);
|
|
174
|
+
return (held !== undefined &&
|
|
175
|
+
Object.entries(held).some(([path, revision]) => confirmedLayer.revisions[path] !== revision));
|
|
176
|
+
});
|
|
177
|
+
const unshown = queue.filter((batch) => !shown.includes(batch));
|
|
178
|
+
const { withdrawn, kept } = await stepped(standing(confirmedLayer, unshown, withdrawable(work.states), localSaves, locator, composition));
|
|
179
|
+
const founded = kept.filter((batch) => !unshown.includes(batch));
|
|
180
|
+
const queueChanged = kept.length !== previousQueue.length || founded.length > 0;
|
|
181
|
+
const unqueued = shown.map((batch) => ({ batch, landed: true }));
|
|
182
|
+
for (const batch of withdrawn) {
|
|
183
|
+
unqueued.push({ batch, landed: await landedWhole(store, record, batch, confirmedLayer) });
|
|
184
|
+
}
|
|
185
|
+
const returning = [
|
|
186
|
+
...[...unqueued].reverse().map(({ batch, landed: held }) => ({
|
|
187
|
+
batch,
|
|
188
|
+
returned: localSaves || held ? null : returnedBy(),
|
|
189
|
+
})),
|
|
190
|
+
...(settling.leaving ?? []),
|
|
191
|
+
];
|
|
192
|
+
const written = await returnedDrafts(store, locator, work, returning, composition);
|
|
193
|
+
const carried = await carriedBack(store, locator, [
|
|
194
|
+
...[...unqueued].reverse().flatMap(({ batch, landed: held }) => (held ? [] : [batch])),
|
|
195
|
+
...(settling.leaving ?? []).flatMap(({ batch, returned }) => returned === null ? [] : [batch]),
|
|
196
|
+
], written);
|
|
197
|
+
const replayedLayer = await replayed(store, record, confirmedLayer, kept);
|
|
198
|
+
const { overlay } = await overlayDiff(record, before, replayedLayer.visible, replayedLayer.touched);
|
|
199
|
+
const commit = {
|
|
200
|
+
rooms: [
|
|
201
|
+
{
|
|
202
|
+
locator,
|
|
203
|
+
key: record.key,
|
|
204
|
+
record: storedRecord(record),
|
|
205
|
+
roots: record.declaration.typedSelection?.roots ?? [],
|
|
206
|
+
composed: composedOf(composition),
|
|
207
|
+
...settling.commit,
|
|
208
|
+
...(overrides === undefined
|
|
209
|
+
? {}
|
|
210
|
+
: { confirmed: { set: overrides.set, removed: overrides.removed } }),
|
|
211
|
+
overlay,
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
writes: [
|
|
215
|
+
{
|
|
216
|
+
locator,
|
|
217
|
+
queue: kept,
|
|
218
|
+
stored: previousQueue,
|
|
219
|
+
founded,
|
|
220
|
+
roomDrafts: [...written.values()],
|
|
221
|
+
consumedRoomDrafts: carried.taken,
|
|
222
|
+
},
|
|
223
|
+
...carried.writes,
|
|
224
|
+
],
|
|
225
|
+
};
|
|
226
|
+
const staying = new Set(kept.map((batch) => batch.id));
|
|
227
|
+
return {
|
|
228
|
+
locator,
|
|
229
|
+
left: previousQueue.filter((batch) => !staying.has(batch.id)),
|
|
230
|
+
commit,
|
|
231
|
+
apply: (answer) => {
|
|
232
|
+
for (const batch of previousQueue) {
|
|
233
|
+
if (!staying.has(batch.id))
|
|
234
|
+
store.landed.drop(locator, batch.id);
|
|
235
|
+
}
|
|
236
|
+
const drafts = [...written.keys(), ...carried.taken];
|
|
237
|
+
for (const { batch, landed: held } of unqueued) {
|
|
238
|
+
const outcome = localSaves ? 'dropped' : held ? 'landed' : 'withdrawn';
|
|
239
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
240
|
+
}
|
|
241
|
+
const changed = answer.changed[locator];
|
|
242
|
+
if (settling.commit?.published !== undefined ||
|
|
243
|
+
settling.commit?.refreshed === true ||
|
|
244
|
+
overrides !== undefined) {
|
|
245
|
+
confirmedAgain(store, locator);
|
|
246
|
+
}
|
|
247
|
+
return mergeChangeSets([
|
|
248
|
+
changeSet(locator, {
|
|
249
|
+
documents: changed === undefined ? [] : changed,
|
|
250
|
+
room: settling.room,
|
|
251
|
+
queue: queueChanged,
|
|
252
|
+
drafts,
|
|
253
|
+
unindexed: answer.indexed[locator] === false,
|
|
254
|
+
due: kept.length > 0 && settling.refused !== true,
|
|
255
|
+
}),
|
|
256
|
+
...carried.changes,
|
|
257
|
+
]);
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
async function unpairing(runtime, local, locator, batches) {
|
|
262
|
+
const { store, journal, localSaves } = runtime;
|
|
263
|
+
const ids = new Set(batches.map(({ id }) => id));
|
|
264
|
+
const leaving = batches.map((batch) => ({
|
|
265
|
+
batch,
|
|
266
|
+
returned: !localSaves && leavingIn(batch, locator) ? returnedBy() : null,
|
|
267
|
+
}));
|
|
268
|
+
const outcome = localSaves ? 'dropped' : 'unpaired';
|
|
269
|
+
const work = await store.work(locator);
|
|
270
|
+
const current = work.replica;
|
|
271
|
+
if (current !== undefined) {
|
|
272
|
+
const settled = await settlement(runtime, local, locator, work, current.record, current.queue.filter((one) => !ids.has(one.id)), { leaving });
|
|
273
|
+
return {
|
|
274
|
+
...settled,
|
|
275
|
+
apply(answer) {
|
|
276
|
+
for (const batch of batches)
|
|
277
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
278
|
+
return settled.apply(answer);
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const queue = work.queue.filter((one) => !ids.has(one.id));
|
|
283
|
+
const written = await returnedDrafts(store, locator, work, leaving, undefined);
|
|
284
|
+
const carried = await carriedBack(store, locator, leaving.flatMap(({ batch, returned }) => (returned === null ? [] : [batch])), written);
|
|
285
|
+
return {
|
|
286
|
+
locator,
|
|
287
|
+
left: batches,
|
|
288
|
+
commit: {
|
|
289
|
+
rooms: [],
|
|
290
|
+
writes: [
|
|
291
|
+
{
|
|
292
|
+
locator,
|
|
293
|
+
queue,
|
|
294
|
+
stored: work.queue,
|
|
295
|
+
roomDrafts: [...written.values()],
|
|
296
|
+
consumedRoomDrafts: carried.taken,
|
|
297
|
+
},
|
|
298
|
+
...carried.writes,
|
|
299
|
+
],
|
|
300
|
+
},
|
|
301
|
+
apply() {
|
|
302
|
+
for (const batch of batches)
|
|
303
|
+
journal.record(`outcome ${locator} ${batch.id} ${outcome}`);
|
|
304
|
+
return mergeChangeSets([
|
|
305
|
+
changeSet(locator, {
|
|
306
|
+
queue: true,
|
|
307
|
+
drafts: [...written.keys(), ...carried.taken],
|
|
308
|
+
due: queue.length > 0,
|
|
309
|
+
}),
|
|
310
|
+
...carried.changes,
|
|
311
|
+
]);
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
async function orphaned(local) {
|
|
316
|
+
const { queued, moving } = await local.moving();
|
|
317
|
+
const halves = new Map();
|
|
318
|
+
for (const { locator, batch, state } of moving) {
|
|
319
|
+
const partner = partnerOf(batch, locator);
|
|
320
|
+
if (partner === null || queued.get(partner)?.includes(batch.id) === true)
|
|
321
|
+
continue;
|
|
322
|
+
if (unsent(state, batch, locator))
|
|
323
|
+
halves.set(locator, [...(halves.get(locator) ?? []), batch]);
|
|
324
|
+
}
|
|
325
|
+
return halves;
|
|
326
|
+
}
|
|
327
|
+
async function sweep(runtime, local) {
|
|
328
|
+
if (!runtime.socket.continuing())
|
|
329
|
+
return;
|
|
330
|
+
const halves = await orphaned(local);
|
|
331
|
+
if (halves.size === 0)
|
|
332
|
+
return;
|
|
333
|
+
const settlements = [];
|
|
334
|
+
for (const [locator, batches] of halves) {
|
|
335
|
+
settlements.push(await unpairing(runtime, local, locator, batches));
|
|
336
|
+
}
|
|
337
|
+
void runtime.store.changed(await together(runtime, local, settlements));
|
|
338
|
+
}
|
|
339
|
+
async function settled(runtime, local, settlements, steps) {
|
|
340
|
+
const set = await together(runtime, local, settlements);
|
|
341
|
+
for (const step of steps)
|
|
342
|
+
step();
|
|
343
|
+
void runtime.store.changed(set);
|
|
344
|
+
await sweep(runtime, local);
|
|
345
|
+
}
|
|
346
|
+
export function settle(runtime, locators, decide) {
|
|
347
|
+
const { store } = runtime;
|
|
348
|
+
return store.exclusive(async () => {
|
|
349
|
+
const local = await store.open();
|
|
350
|
+
const held = new Map();
|
|
351
|
+
for (const locator of locators)
|
|
352
|
+
held.set(locator, await store.work(locator));
|
|
353
|
+
const decided = await decide(held);
|
|
354
|
+
if (decided.length === 0)
|
|
355
|
+
return;
|
|
356
|
+
const settlements = [];
|
|
357
|
+
for (const { locator, record, accepted, adopted, installed, refused } of decided) {
|
|
358
|
+
const work = held.get(locator) ?? (await store.work(locator));
|
|
359
|
+
settlements.push(await settlement(runtime, local, locator, work, record, work.queue.filter((batch) => batch.id !== accepted), {
|
|
360
|
+
room: true,
|
|
361
|
+
view: installed?.refreshed === true ? 'refreshed' : 'confirmed',
|
|
362
|
+
...(installed === undefined ? {} : { commit: installed }),
|
|
363
|
+
...(adopted === undefined ? {} : { changes: adopted }),
|
|
364
|
+
...(refused === undefined ? {} : { refused }),
|
|
365
|
+
}));
|
|
366
|
+
}
|
|
367
|
+
await settled(runtime, local, settlements, decided.flatMap(({ after }) => (after === undefined ? [] : [after])));
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
export function answered(runtime, locator, head, answer) {
|
|
371
|
+
const { store, socket } = runtime;
|
|
372
|
+
return store.exclusive(async () => {
|
|
373
|
+
if (!socket.continuing())
|
|
374
|
+
return;
|
|
375
|
+
const local = await store.open();
|
|
376
|
+
const work = await store.work(locator);
|
|
377
|
+
const current = work.replica;
|
|
378
|
+
if (current === undefined || !current.queue.some((batch) => batch.id === head.id))
|
|
379
|
+
return;
|
|
380
|
+
const confirmedLayer = await sliceAt(store, current.record, 'confirmed', [head]);
|
|
381
|
+
const held = answer.kind === 'conflicted' &&
|
|
382
|
+
(await landedWhole(store, current.record, head, confirmedLayer, answer.affected));
|
|
383
|
+
if (held &&
|
|
384
|
+
partnerOf(head, locator) === null &&
|
|
385
|
+
!landed(head, confirmedLayer, store.composed(current.record))) {
|
|
386
|
+
store.landed.hold(locator, head.id, Object.fromEntries([...touchedBy([head])].map((path) => [path, confirmedLayer.revisions[path]])));
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const returned = {
|
|
390
|
+
kind: answer.kind,
|
|
391
|
+
code: answer.code,
|
|
392
|
+
fields: answer.fields,
|
|
393
|
+
retryable: answer.retryable,
|
|
394
|
+
};
|
|
395
|
+
await settled(runtime, local, [
|
|
396
|
+
await settlement(runtime, local, locator, work, current.record, current.queue.filter((batch) => batch.id !== head.id), { leaving: [{ batch: head, returned: held ? null : returned }] }),
|
|
397
|
+
], []);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
export function unpair(runtime) {
|
|
401
|
+
return runtime.store.durably((local) => sweep(runtime, local));
|
|
402
|
+
}
|
package/dist/reach.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reach.d.ts","sourceRoot":"","sources":["../src/reach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":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