@agentshouse/mdruntime 0.1.0-cd507e16e5fc0 → 0.1.0-cd71aba4d0215
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 +8 -8
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +74 -145
- package/dist/act-lanes.d.ts +33 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +177 -0
- package/dist/actions.d.ts +7 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +40 -30
- package/dist/adapter.d.ts +27 -45
- 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/change.d.ts.map +1 -1
- package/dist/change.js +4 -2
- package/dist/client.d.ts +7 -12
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -14
- package/dist/collection.d.ts +22 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +12 -2
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +15 -21
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +26 -16
- package/dist/conversation-live.d.ts +8 -6
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +7 -6
- package/dist/conversation.d.ts +23 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +127 -102
- 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 +18 -40
- package/dist/durability.d.ts +3 -0
- package/dist/durability.d.ts.map +1 -1
- 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 +3 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -0
- package/dist/host.d.ts +17 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +39 -9
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/install.d.ts +1 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +48 -65
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +38 -27
- package/dist/listing.d.ts +6 -11
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +25 -62
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +3 -3
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +10 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +10 -21
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +4 -4
- package/dist/memory.d.ts +4 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +38 -21
- package/dist/messages.d.ts +0 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +13 -31
- 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 +97 -136
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +12 -17
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +5 -5
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +6 -4
- package/dist/outcome.d.ts +3 -0
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +15 -0
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +32 -21
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +3 -51
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +14 -111
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +22 -15
- package/dist/presence.d.ts +52 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +220 -0
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +5 -7
- package/dist/query.d.ts +0 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.js +1 -1
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +455 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +27 -8
- package/dist/react.d.ts +11 -0
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +15 -1
- package/dist/reads.d.ts +3 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +9 -2
- package/dist/recovery.d.ts +3 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +29 -7
- package/dist/refresh.js +2 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +5 -4
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +13 -15
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +4 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +36 -52
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +17 -16
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +3 -4
- package/dist/runtime.d.ts +9 -16
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +41 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +233 -116
- package/dist/saves.d.ts +2 -40
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +107 -702
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -3
- package/dist/shared.d.ts +0 -5
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +4 -90
- package/dist/shown.d.ts +4 -3
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +26 -31
- package/dist/socket/lanes.d.ts +2 -1
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +5 -2
- package/dist/socket/session.d.ts +0 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket.d.ts +2 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -8
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +5 -4
- package/dist/store/records.d.ts +3 -3
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +4 -5
- package/dist/store/space.d.ts +1 -1
- package/dist/store/space.d.ts.map +1 -1
- package/dist/store/space.js +0 -2
- package/dist/store/watchers.js +1 -2
- package/dist/store.d.ts +10 -5
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +38 -13
- package/dist/stored.d.ts +1 -1
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +6 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +8 -8
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +86 -78
- package/dist/tables.d.ts +0 -5
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +8 -11
- package/dist/tallies.js +5 -5
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +2 -2
- package/dist/wire.d.ts +40 -4
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +12 -3
- package/package.json +3 -2
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/socket/rooms.d.ts +0 -44
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const PAGE_METADATA_WORDS: {
|
|
2
|
+
readonly heading: 'Page metadata';
|
|
3
|
+
readonly app: 'App';
|
|
4
|
+
readonly address: 'Address';
|
|
5
|
+
readonly queries: 'Local Queries';
|
|
6
|
+
};
|
|
7
|
+
export declare function pageMetadataBlock(app: string, address: string, queries: readonly unknown[]): string;
|
|
8
|
+
//# sourceMappingURL=page-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-metadata.d.ts","sourceRoot":"","sources":["../src/page-metadata.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;aAC9B,OAAO,EAAE,eAAe;aACxB,GAAG,EAAE,KAAK;aACV,OAAO,EAAE,SAAS;aAClB,OAAO,EAAE,eAAe;CAChB,CAAC;AAIX,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,OAAO,EAAE,GAC1B,MAAM,CAUR"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { queryKey } from '@agentshouse/mdmodel';
|
|
2
|
+
export const PAGE_METADATA_WORDS = {
|
|
3
|
+
heading: 'Page metadata',
|
|
4
|
+
app: 'App',
|
|
5
|
+
address: 'Address',
|
|
6
|
+
queries: 'Local Queries',
|
|
7
|
+
};
|
|
8
|
+
const PAGE_METADATA_QUERIES = 10;
|
|
9
|
+
export function pageMetadataBlock(app, address, queries) {
|
|
10
|
+
const held = [...new Set(queries.map(queryKey))];
|
|
11
|
+
return [
|
|
12
|
+
PAGE_METADATA_WORDS.heading,
|
|
13
|
+
`${PAGE_METADATA_WORDS.app}: ${app}`,
|
|
14
|
+
`${PAGE_METADATA_WORDS.address}: ${address}`,
|
|
15
|
+
...(held.length === 0 || held.length > PAGE_METADATA_QUERIES
|
|
16
|
+
? []
|
|
17
|
+
: [`${PAGE_METADATA_WORDS.queries}:`, ...held]),
|
|
18
|
+
].join('\n');
|
|
19
|
+
}
|
package/dist/parts.d.ts
CHANGED
|
@@ -1,48 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type JobMarker, type OpenJob } from './job.js';
|
|
3
|
-
export type PlanStep = {
|
|
4
|
-
readonly content: string;
|
|
5
|
-
readonly status: string;
|
|
6
|
-
};
|
|
7
|
-
export type Marker = 'mode' | 'compaction' | 'retry' | 'model' | 'job';
|
|
8
|
-
export type Part = {
|
|
9
|
-
readonly type: 'text';
|
|
10
|
-
readonly text: string;
|
|
11
|
-
} | {
|
|
12
|
-
readonly type: 'reasoning';
|
|
13
|
-
readonly text: string;
|
|
14
|
-
} | {
|
|
15
|
-
readonly type: 'commands';
|
|
16
|
-
readonly count: number;
|
|
17
|
-
} | {
|
|
18
|
-
readonly type: 'subagent';
|
|
19
|
-
readonly description: string;
|
|
20
|
-
readonly done: boolean;
|
|
21
|
-
readonly result: string | null;
|
|
22
|
-
} | {
|
|
23
|
-
readonly type: 'message';
|
|
24
|
-
readonly command: string;
|
|
25
|
-
readonly target: string | null;
|
|
26
|
-
} | {
|
|
27
|
-
readonly type: 'image';
|
|
28
|
-
readonly path: string;
|
|
29
|
-
readonly name: string;
|
|
30
|
-
readonly mediaType: string;
|
|
31
|
-
} | {
|
|
32
|
-
readonly type: 'marker';
|
|
33
|
-
readonly marker: Marker;
|
|
34
|
-
readonly text: string;
|
|
35
|
-
} | {
|
|
36
|
-
readonly type: 'plan';
|
|
37
|
-
readonly steps: readonly PlanStep[];
|
|
38
|
-
};
|
|
39
|
-
export declare function partsOf(raw: readonly unknown[]): readonly Part[];
|
|
40
|
-
export declare function contextIn(raw: unknown): TurnContext | null;
|
|
41
|
-
export type Turn = {
|
|
42
|
-
readonly turn: string;
|
|
43
|
-
readonly parts: readonly Part[];
|
|
44
|
-
readonly ended: boolean;
|
|
45
|
-
};
|
|
1
|
+
import { type Part, type SessionState } from '@agentshouse/session-content';
|
|
46
2
|
export type ChatWork = {
|
|
47
3
|
readonly kind: 'job' | 'schedule' | 'subagent';
|
|
48
4
|
readonly title: string;
|
|
@@ -50,10 +6,6 @@ export type ChatWork = {
|
|
|
50
6
|
readonly activity: string | null;
|
|
51
7
|
};
|
|
52
8
|
export declare function counted(count: number): string;
|
|
53
|
-
export declare function runningLine(
|
|
54
|
-
export declare function
|
|
55
|
-
readonly started: string | null;
|
|
56
|
-
readonly parts: readonly unknown[];
|
|
57
|
-
} | null): readonly OpenJob[];
|
|
58
|
-
export declare function stillRunning(turns: readonly Turn[], subagents: readonly RunningSubagent[]): ReadonlyMap<string, readonly ChatWork[]>;
|
|
9
|
+
export declare function runningLine(parts: readonly Part[]): string | null;
|
|
10
|
+
export declare function workOf(state: SessionState | null): readonly ChatWork[];
|
|
59
11
|
//# sourceMappingURL=parts.d.ts.map
|
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,118 +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
|
-
}
|
|
1
|
+
import { isOwn } from '@agentshouse/session-content';
|
|
2
|
+
import { excerpt } from './read.js';
|
|
60
3
|
export function counted(count) {
|
|
61
4
|
return count === 1 ? '1 command' : `${count} commands`;
|
|
62
5
|
}
|
|
63
|
-
export function runningLine(
|
|
64
|
-
const
|
|
65
|
-
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() !== '');
|
|
66
9
|
if (note?.type === 'text')
|
|
67
10
|
return excerpt(note.text);
|
|
68
|
-
const
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
export function jobsOf(markers, turn) {
|
|
72
|
-
const running = (turn === null ? [] : partsOf(turn.parts)).flatMap((part) => part.type === 'marker' && part.marker === 'job'
|
|
73
|
-
? [{ said: part.text, at: turn?.started ?? null }]
|
|
74
|
-
: []);
|
|
75
|
-
return openJobs([...markers, ...running]);
|
|
11
|
+
const call = newest.find((part) => part.type === 'call');
|
|
12
|
+
return call?.type === 'call' && call.line !== '' ? call.line : null;
|
|
76
13
|
}
|
|
77
|
-
export function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
closeLast(open, key);
|
|
85
|
-
else if (ended) {
|
|
86
|
-
open.push({
|
|
87
|
-
turn,
|
|
88
|
-
key,
|
|
89
|
-
work: { kind: 'subagent', title: part.description, next: null, activity: null },
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (part.type !== 'marker' || part.marker !== 'job')
|
|
95
|
-
continue;
|
|
96
|
-
markerMoved(open, part.text, (job, key) => ended
|
|
97
|
-
? {
|
|
98
|
-
turn,
|
|
99
|
-
key,
|
|
100
|
-
work: {
|
|
101
|
-
kind: job.kind === 'started' ? 'job' : 'schedule',
|
|
102
|
-
title: job.label,
|
|
103
|
-
next: job.next,
|
|
104
|
-
activity: null,
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
: null);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const doing = [...subagents];
|
|
111
|
-
const under = new Map();
|
|
112
|
-
for (const { turn, work } of open) {
|
|
113
|
-
const at = work.kind === 'subagent' ? doing.findIndex((one) => one.description === work.title) : -1;
|
|
114
|
-
const shown = at === -1 ? work : { ...work, activity: doing.splice(at, 1)[0].activity };
|
|
115
|
-
under.set(turn, [...(under.get(turn) ?? []), shown]);
|
|
116
|
-
}
|
|
117
|
-
return under;
|
|
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
|
+
}));
|
|
118
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;AAC5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|
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';
|
|
@@ -27,12 +28,14 @@ async function prepareReplica(runtime, locator) {
|
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
async function unprepared({ store
|
|
31
|
+
async function unprepared({ store }) {
|
|
31
32
|
const held = (await store.covering()).rooms;
|
|
32
|
-
|
|
33
|
+
const { unpreparedDemand, unpreparable } = store.device.now();
|
|
34
|
+
return [...unpreparedDemand, ...held.keys()].find((locator) => !(held.get(locator)?.indexed ?? false) && !unpreparable.has(locator));
|
|
33
35
|
}
|
|
34
|
-
function unpreparedBy({ store,
|
|
35
|
-
|
|
36
|
+
function unpreparedBy({ store, journal }, locator, error) {
|
|
37
|
+
const { unpreparable } = store.device.now();
|
|
38
|
+
store.device.set({ unpreparable: new Set([...unpreparable, locator]) });
|
|
36
39
|
journal.record(`preparation failed ${locator} ${error instanceof Error ? error.name : 'unknown'}`);
|
|
37
40
|
store.readiness.queue();
|
|
38
41
|
}
|
|
@@ -57,8 +60,9 @@ export function prepare(runtime, locators = []) {
|
|
|
57
60
|
await prepareReplica(runtime, waiting).catch((error) => unpreparedBy(runtime, waiting, error));
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
|
-
catch {
|
|
63
|
+
catch (error) {
|
|
61
64
|
journal.record('preparation failed');
|
|
65
|
+
uncaught(error);
|
|
62
66
|
}
|
|
63
67
|
finally {
|
|
64
68
|
device.set({ preparing: false });
|
|
@@ -79,12 +83,9 @@ function requiredRooms(runtime, given, held) {
|
|
|
79
83
|
return { listed: true, rooms: named.filter((room) => listed.has(room)) };
|
|
80
84
|
return { listed: named.every((room) => held.has(room)), rooms: named };
|
|
81
85
|
}
|
|
82
|
-
function roomState({ socket }, locator, held) {
|
|
83
|
-
const listedRoom = socket.rooms.discovered(locator);
|
|
86
|
+
function roomState({ socket, presence }, locator, held) {
|
|
84
87
|
if (socket.session.now().roomsListed &&
|
|
85
|
-
(
|
|
86
|
-
listedRoom.replica.admission !== 'admitted' ||
|
|
87
|
-
socket.rooms.standing(locator).unreadable))
|
|
88
|
+
(presence.room(locator) === undefined || !presence.available(locator)))
|
|
88
89
|
return 'unadmitted';
|
|
89
90
|
const stored = held.get(locator);
|
|
90
91
|
if (stored === undefined)
|
|
@@ -124,8 +125,9 @@ function readinessFor(runtime, port, reach, { held, facts }) {
|
|
|
124
125
|
const { store, socket, usableWhenHeld } = runtime;
|
|
125
126
|
const required = requiredRooms(runtime, reach, held);
|
|
126
127
|
const coverage = required.rooms.map((room) => ({ room, state: roomState(runtime, room, held) }));
|
|
128
|
+
const { unpreparable } = store.device.now();
|
|
127
129
|
const preparing = coverage
|
|
128
|
-
.filter((room) => room.state === 'preparing' && !
|
|
130
|
+
.filter((room) => room.state === 'preparing' && !unpreparable.has(room.room))
|
|
129
131
|
.map(({ room }) => room);
|
|
130
132
|
if (preparing.length > 0)
|
|
131
133
|
prepare(runtime, preparing);
|
|
@@ -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);
|
|
@@ -206,8 +209,8 @@ export function filled(runtime) {
|
|
|
206
209
|
store.readiness.queue();
|
|
207
210
|
void probeEachMinute(runtime);
|
|
208
211
|
}
|
|
209
|
-
async function installedTarget({ store
|
|
210
|
-
if (store.device.now().heldWhenOpened
|
|
212
|
+
async function installedTarget({ store }) {
|
|
213
|
+
if (store.device.now().heldWhenOpened)
|
|
211
214
|
return true;
|
|
212
215
|
const { targets } = await (await store.open()).facts();
|
|
213
216
|
return Object.values(targets).some((target) => target.established);
|
|
@@ -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;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { DiscoveredRoom, ProviderRefusal, ScopedRefusal } from './adapter.js';
|
|
2
|
+
import type { ModelState } from './model.js';
|
|
3
|
+
type Repairable = {
|
|
4
|
+
readonly reset: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
type Standing = {
|
|
7
|
+
readonly stale: boolean;
|
|
8
|
+
readonly repairable: Repairable | null;
|
|
9
|
+
readonly repairing: boolean;
|
|
10
|
+
readonly reloadDue: boolean;
|
|
11
|
+
};
|
|
12
|
+
type Listing = {
|
|
13
|
+
readonly whole: boolean;
|
|
14
|
+
readonly live: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type Presence = {
|
|
17
|
+
list(found: readonly DiscoveredRoom[], how: Listing): readonly DiscoveredRoom[];
|
|
18
|
+
room(locator: string): DiscoveredRoom | undefined;
|
|
19
|
+
rooms(): readonly DiscoveredRoom[];
|
|
20
|
+
available(locator: string, selection?: string): boolean;
|
|
21
|
+
refusal(locator: string): ProviderRefusal | null;
|
|
22
|
+
unheldModel(locator: string): ModelState | null;
|
|
23
|
+
refused(locator: string, refusal: ScopedRefusal | null): void;
|
|
24
|
+
readable(locator: string): boolean;
|
|
25
|
+
modelled(locator: string, model: ModelState | null): void;
|
|
26
|
+
installed(locator: string, bootstrapped: boolean): void;
|
|
27
|
+
locked(locator: string, stored: () => Promise<string | null>): Promise<boolean>;
|
|
28
|
+
lockedAmong(stored: ReadonlyMap<string, string>): readonly string[];
|
|
29
|
+
connectionLost(lapsed: () => void): void;
|
|
30
|
+
connectionLive(): void;
|
|
31
|
+
lapse(): void;
|
|
32
|
+
stood(locator: string, stale: boolean, repairable?: Repairable | null): void;
|
|
33
|
+
repairing(locator: string, running: boolean): void;
|
|
34
|
+
reload(locator: string, due: boolean): void;
|
|
35
|
+
standing(locator: string): Standing;
|
|
36
|
+
settled(): boolean;
|
|
37
|
+
repairsOwed(): readonly string[];
|
|
38
|
+
askAgain(locator: string, ask: () => void): void;
|
|
39
|
+
stopAsking(locator?: string): void;
|
|
40
|
+
lose(locator: string, during: number): boolean;
|
|
41
|
+
writing(locator: string): boolean;
|
|
42
|
+
unwritten(locator: string): void;
|
|
43
|
+
lost(locator: string): boolean;
|
|
44
|
+
losses(): number;
|
|
45
|
+
lostSince(locator: string, losses: number): boolean;
|
|
46
|
+
liftable(locator: string, discovery: number): boolean;
|
|
47
|
+
lift(locator: string, discovery: number, unfenced: boolean): void;
|
|
48
|
+
close(): void;
|
|
49
|
+
};
|
|
50
|
+
export declare function createPresence(): Presence;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,KAAK,UAAU,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEzD,KAAK,QAAQ,GAAG;IACd,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,SAAS,EA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
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
const UNANSWERED = {
|
|
2
|
+
stale: false,
|
|
3
|
+
repairable: null,
|
|
4
|
+
repairing: false,
|
|
5
|
+
reloadDue: false,
|
|
6
|
+
refusal: null,
|
|
7
|
+
unreading: false,
|
|
8
|
+
unreadable: false,
|
|
9
|
+
unheldModel: null,
|
|
10
|
+
confirmed: false,
|
|
11
|
+
};
|
|
12
|
+
// A Room the Provider answers not ready is asked again after these waits, the last repeating, so a chunk build that catches up within seconds installs at once and a long one is asked every 15 seconds.
|
|
13
|
+
const NOT_READY_MS = [1_000, 2_000, 3_000, 5_000, 8_000, 11_000, 15_000];
|
|
14
|
+
// A Room that locks offline stays readable this long after the connection drops, so a laptop waking or changing network keeps working while a disconnected device locks soon after.
|
|
15
|
+
const LOCK_GRACE_MS = 120_000;
|
|
16
|
+
export function createPresence() {
|
|
17
|
+
const listed = new Map();
|
|
18
|
+
const answered = new Map();
|
|
19
|
+
const marks = new Map();
|
|
20
|
+
const lastLost = new Map();
|
|
21
|
+
const unready = new Map();
|
|
22
|
+
let lossCount = 0;
|
|
23
|
+
let lockGrace = null;
|
|
24
|
+
function answer(locator) {
|
|
25
|
+
return answered.get(locator) ?? UNANSWERED;
|
|
26
|
+
}
|
|
27
|
+
function change(locator, next) {
|
|
28
|
+
answered.set(locator, { ...answer(locator), ...next });
|
|
29
|
+
}
|
|
30
|
+
function heard(locator, next) {
|
|
31
|
+
if (!marks.has(locator))
|
|
32
|
+
change(locator, next);
|
|
33
|
+
}
|
|
34
|
+
function readied(locator) {
|
|
35
|
+
const held = unready.get(locator);
|
|
36
|
+
if (held === undefined)
|
|
37
|
+
return;
|
|
38
|
+
if (held.timer !== null)
|
|
39
|
+
clearTimeout(held.timer);
|
|
40
|
+
unready.delete(locator);
|
|
41
|
+
}
|
|
42
|
+
function stopAsking(locator) {
|
|
43
|
+
for (const held of locator === undefined ? [...unready.keys()] : [locator])
|
|
44
|
+
readied(held);
|
|
45
|
+
}
|
|
46
|
+
function connectionLive() {
|
|
47
|
+
if (lockGrace !== null)
|
|
48
|
+
clearTimeout(lockGrace);
|
|
49
|
+
lockGrace = null;
|
|
50
|
+
}
|
|
51
|
+
function readable(locator) {
|
|
52
|
+
const { unreadable, unreading } = answer(locator);
|
|
53
|
+
if (!unreadable || marks.has(locator))
|
|
54
|
+
return false;
|
|
55
|
+
change(locator, {
|
|
56
|
+
unreadable: false,
|
|
57
|
+
...(unreading ? { refusal: null, unreading: false } : {}),
|
|
58
|
+
});
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
function locks(locator, mode) {
|
|
62
|
+
return mode === 'locked' && !answer(locator).confirmed && !marks.has(locator);
|
|
63
|
+
}
|
|
64
|
+
function liftable(locator, discovery) {
|
|
65
|
+
const mark = marks.get(locator);
|
|
66
|
+
return mark === undefined || mark.during < discovery;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
list(found, { whole, live }) {
|
|
70
|
+
const kept = found.filter(({ locator }) => !marks.has(locator));
|
|
71
|
+
if (whole)
|
|
72
|
+
listed.clear();
|
|
73
|
+
for (const room of kept) {
|
|
74
|
+
listed.set(room.locator, room);
|
|
75
|
+
change(room.locator, {
|
|
76
|
+
refusal: null,
|
|
77
|
+
unreading: false,
|
|
78
|
+
...(live && room.replica.admission === 'admitted' ? { confirmed: true } : {}),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return kept;
|
|
82
|
+
},
|
|
83
|
+
room: (locator) => listed.get(locator),
|
|
84
|
+
rooms: () => [...listed.values()],
|
|
85
|
+
available(locator, selection) {
|
|
86
|
+
if (marks.has(locator))
|
|
87
|
+
return false;
|
|
88
|
+
const room = listed.get(locator);
|
|
89
|
+
if (room === undefined)
|
|
90
|
+
return true;
|
|
91
|
+
return ((selection === undefined || selection === room.replica.selection) &&
|
|
92
|
+
room.replica.admission === 'admitted' &&
|
|
93
|
+
!answer(locator).unreadable);
|
|
94
|
+
},
|
|
95
|
+
refusal: (locator) => answer(locator).refusal,
|
|
96
|
+
unheldModel: (locator) => answer(locator).unheldModel,
|
|
97
|
+
refused(locator, refusal) {
|
|
98
|
+
if (refusal === null) {
|
|
99
|
+
heard(locator, { unreadable: true });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const unreading = refusal.scope !== 'operation' && refusal.scope !== 'model';
|
|
103
|
+
heard(locator, {
|
|
104
|
+
refusal: { code: refusal.code, fields: refusal.fields, retryable: refusal.retryable },
|
|
105
|
+
unreading,
|
|
106
|
+
...(unreading ? { unreadable: true } : {}),
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
readable,
|
|
110
|
+
modelled(locator, model) {
|
|
111
|
+
heard(locator, { unheldModel: model });
|
|
112
|
+
},
|
|
113
|
+
installed(locator, bootstrapped) {
|
|
114
|
+
if (marks.has(locator))
|
|
115
|
+
return;
|
|
116
|
+
if (bootstrapped) {
|
|
117
|
+
readied(locator);
|
|
118
|
+
change(locator, { unheldModel: null });
|
|
119
|
+
}
|
|
120
|
+
change(locator, { stale: false });
|
|
121
|
+
readable(locator);
|
|
122
|
+
},
|
|
123
|
+
async locked(locator, stored) {
|
|
124
|
+
if (marks.has(locator) || answer(locator).confirmed)
|
|
125
|
+
return false;
|
|
126
|
+
return locks(locator, (await stored()) ?? listed.get(locator)?.replica.offline);
|
|
127
|
+
},
|
|
128
|
+
lockedAmong(stored) {
|
|
129
|
+
const modes = new Map([...listed].map(([locator, room]) => [locator, room.replica.offline]));
|
|
130
|
+
for (const [locator, mode] of stored)
|
|
131
|
+
modes.set(locator, mode);
|
|
132
|
+
return [...modes]
|
|
133
|
+
.filter(([locator, mode]) => locks(locator, mode))
|
|
134
|
+
.map(([locator]) => locator)
|
|
135
|
+
.sort();
|
|
136
|
+
},
|
|
137
|
+
connectionLost(lapsed) {
|
|
138
|
+
if (lockGrace !== null)
|
|
139
|
+
return;
|
|
140
|
+
lockGrace = setTimeout(() => {
|
|
141
|
+
lockGrace = null;
|
|
142
|
+
lapsed();
|
|
143
|
+
}, LOCK_GRACE_MS);
|
|
144
|
+
},
|
|
145
|
+
connectionLive,
|
|
146
|
+
lapse() {
|
|
147
|
+
for (const [locator, held] of answered) {
|
|
148
|
+
if (held.confirmed)
|
|
149
|
+
answered.set(locator, { ...held, confirmed: false });
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
stood(locator, stale, repairable) {
|
|
153
|
+
heard(locator, { stale, ...(repairable === undefined ? {} : { repairable }) });
|
|
154
|
+
},
|
|
155
|
+
repairing(locator, running) {
|
|
156
|
+
change(locator, { repairing: running });
|
|
157
|
+
},
|
|
158
|
+
reload(locator, due) {
|
|
159
|
+
change(locator, { reloadDue: due });
|
|
160
|
+
},
|
|
161
|
+
standing(locator) {
|
|
162
|
+
const { stale, repairable, repairing, reloadDue } = answer(locator);
|
|
163
|
+
return { stale, repairable, repairing, reloadDue };
|
|
164
|
+
},
|
|
165
|
+
settled: () => ![...answered].some(([locator, { stale }]) => stale && !marks.has(locator)),
|
|
166
|
+
repairsOwed: () => [...answered]
|
|
167
|
+
.filter(([locator, { stale, repairable }]) => stale && repairable !== null && !marks.has(locator))
|
|
168
|
+
.map(([locator]) => locator),
|
|
169
|
+
askAgain(locator, ask) {
|
|
170
|
+
const held = unready.get(locator) ?? { tries: 0, timer: null };
|
|
171
|
+
unready.set(locator, held);
|
|
172
|
+
if (held.timer !== null)
|
|
173
|
+
return;
|
|
174
|
+
const wait = NOT_READY_MS[Math.min(held.tries, NOT_READY_MS.length - 1)];
|
|
175
|
+
held.tries += 1;
|
|
176
|
+
held.timer = setTimeout(() => {
|
|
177
|
+
held.timer = null;
|
|
178
|
+
ask();
|
|
179
|
+
}, wait);
|
|
180
|
+
},
|
|
181
|
+
stopAsking,
|
|
182
|
+
lose(locator, during) {
|
|
183
|
+
if (marks.has(locator))
|
|
184
|
+
return false;
|
|
185
|
+
marks.set(locator, { during, written: false });
|
|
186
|
+
lastLost.set(locator, ++lossCount);
|
|
187
|
+
listed.delete(locator);
|
|
188
|
+
readied(locator);
|
|
189
|
+
const { repairing, reloadDue } = answer(locator);
|
|
190
|
+
answered.set(locator, { ...UNANSWERED, repairing, reloadDue });
|
|
191
|
+
return true;
|
|
192
|
+
},
|
|
193
|
+
writing(locator) {
|
|
194
|
+
const mark = marks.get(locator);
|
|
195
|
+
if (mark === undefined || mark.written)
|
|
196
|
+
return false;
|
|
197
|
+
marks.set(locator, { ...mark, written: true });
|
|
198
|
+
return true;
|
|
199
|
+
},
|
|
200
|
+
unwritten(locator) {
|
|
201
|
+
const mark = marks.get(locator);
|
|
202
|
+
if (mark !== undefined)
|
|
203
|
+
marks.set(locator, { ...mark, written: false });
|
|
204
|
+
},
|
|
205
|
+
lost: (locator) => marks.has(locator),
|
|
206
|
+
losses: () => lossCount,
|
|
207
|
+
lostSince: (locator, losses) => marks.has(locator) || (lastLost.get(locator) ?? 0) > losses,
|
|
208
|
+
liftable,
|
|
209
|
+
lift(locator, discovery, unfenced) {
|
|
210
|
+
const mark = marks.get(locator);
|
|
211
|
+
if (mark !== undefined && liftable(locator, discovery) && (unfenced || !mark.written)) {
|
|
212
|
+
marks.delete(locator);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
close() {
|
|
216
|
+
stopAsking();
|
|
217
|
+
connectionLive();
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
package/dist/queries.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function figuresCover(runtime: Runtime): Promise<FiguresCover>;
|
|
|
9
9
|
export declare function answeredPlan(runtime: Runtime, plan: Plan, cover: () => Promise<Cover>): Promise<Ran>;
|
|
10
10
|
export declare function rowsQuery(runtime: Runtime, plan: Plan): Promise<QueryResult>;
|
|
11
11
|
export declare function planned(runtime: Runtime, input: unknown, reach: PortReach | null): Promise<Plan>;
|
|
12
|
-
export declare function roomTallies(runtime: Runtime, rooms: readonly QueryRoom[], since: string): Promise<readonly import("./tallies.
|
|
12
|
+
export declare function roomTallies(runtime: Runtime, rooms: readonly QueryRoom[], since: string): Promise<readonly import("./tallies.ts").RoomTally[]>;
|
|
13
13
|
export declare function watchPlan(runtime: Runtime, plan: Plan, deliver: Deliver, fail: Fail): () => void;
|
|
14
14
|
export declare function watchPlanned(runtime: Runtime, planning: Promise<Plan>, deliver: Deliver, fail: Fail): () => void;
|
|
15
15
|
export declare function searched(runtime: Runtime, input: unknown, reach: PortReach | null): Promise<SearchResult>;
|
package/dist/queries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAK5C,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGhF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,KAAK,EAAa,SAAS,EAAgB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAK5C,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,WAAW,EAEjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGhF,OAAO,KAAK,EAAE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