daftari 3.3.0 → 3.5.0
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/CHANGELOG.md +18 -0
- package/README.md +34 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +6 -0
- package/dist/cli.js.map +1 -1
- package/dist/search/contested.d.ts +1 -1
- package/dist/search/contested.d.ts.map +1 -1
- package/dist/search/contested.js +4 -3
- package/dist/search/contested.js.map +1 -1
- package/dist/tools/backlinks.d.ts +6 -0
- package/dist/tools/backlinks.d.ts.map +1 -1
- package/dist/tools/backlinks.js +55 -1
- package/dist/tools/backlinks.js.map +1 -1
- package/dist/view/doc-view.d.ts +21 -0
- package/dist/view/doc-view.d.ts.map +1 -0
- package/dist/view/doc-view.js +53 -0
- package/dist/view/doc-view.js.map +1 -0
- package/dist/view/graph.d.ts +52 -0
- package/dist/view/graph.d.ts.map +1 -0
- package/dist/view/graph.js +133 -0
- package/dist/view/graph.js.map +1 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.d.ts.map +1 -0
- package/dist/view/index.js +70 -0
- package/dist/view/index.js.map +1 -0
- package/dist/view/pages.d.ts +63 -0
- package/dist/view/pages.d.ts.map +1 -0
- package/dist/view/pages.js +478 -0
- package/dist/view/pages.js.map +1 -0
- package/dist/view/render.d.ts +15 -0
- package/dist/view/render.d.ts.map +1 -0
- package/dist/view/render.js +117 -0
- package/dist/view/render.js.map +1 -0
- package/dist/view/server.d.ts +16 -0
- package/dist/view/server.d.ts.map +1 -0
- package/dist/view/server.js +302 -0
- package/dist/view/server.js.map +1 -0
- package/dist/view/status-view.d.ts +32 -0
- package/dist/view/status-view.d.ts.map +1 -0
- package/dist/view/status-view.js +39 -0
- package/dist/view/status-view.js.map +1 -0
- package/package.json +10 -4
- package/templates/view/cytoscape.min.js +31 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Pure knowledge-graph builder for `daftari view`. Takes already-loaded inputs
|
|
2
|
+
// (docs + the reverse maps, derives_from edges, contested pairs, and the decayed
|
|
3
|
+
// set) and returns a {nodes, edges} graph — no IO, so it is unit-testable
|
|
4
|
+
// without a vault. The server route wires the IO (loadDocuments, vaultEdges,
|
|
5
|
+
// listTensions, computeDecay) and calls this. This is the JSON the /api/graph
|
|
6
|
+
// endpoint serves and the graph client renders (the B-seam: one contract, two
|
|
7
|
+
// consumers).
|
|
8
|
+
export const DEFAULT_NODE_CAP = 600;
|
|
9
|
+
// Forward edges from a reverse map: reverse maps are target -> [referrers], so a
|
|
10
|
+
// forward edge runs referrer -> target. Only edges whose BOTH endpoints are
|
|
11
|
+
// known documents are kept (a dangling reference is not a graph edge).
|
|
12
|
+
function edgesFromReverse(reverse, kind, known) {
|
|
13
|
+
const out = [];
|
|
14
|
+
for (const [target, referrers] of reverse) {
|
|
15
|
+
if (!known.has(target))
|
|
16
|
+
continue;
|
|
17
|
+
for (const from of referrers) {
|
|
18
|
+
if (from === target || !known.has(from))
|
|
19
|
+
continue;
|
|
20
|
+
out.push({ from, to: target, kind });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
// Undirected adjacency for ego BFS and (optionally) degree-ranked capping.
|
|
26
|
+
function adjacency(edges) {
|
|
27
|
+
const adj = new Map();
|
|
28
|
+
const link = (a, b) => {
|
|
29
|
+
const s = adj.get(a) ?? new Set();
|
|
30
|
+
s.add(b);
|
|
31
|
+
adj.set(a, s);
|
|
32
|
+
};
|
|
33
|
+
for (const e of edges) {
|
|
34
|
+
link(e.from, e.to);
|
|
35
|
+
link(e.to, e.from);
|
|
36
|
+
}
|
|
37
|
+
return adj;
|
|
38
|
+
}
|
|
39
|
+
export function buildGraph(input, opts) {
|
|
40
|
+
const known = new Set(input.docs.map((d) => d.path));
|
|
41
|
+
// All edges, deduped (a pair may be both source and link — keep both kinds
|
|
42
|
+
// but never the same kind twice), endpoints restricted to known docs.
|
|
43
|
+
const rawEdges = [
|
|
44
|
+
...edgesFromReverse(input.reverseSource, "source", known),
|
|
45
|
+
...edgesFromReverse(input.reverseLink, "link", known),
|
|
46
|
+
...input.derivesEdges
|
|
47
|
+
.filter((e) => e.from !== e.to && known.has(e.from) && known.has(e.to))
|
|
48
|
+
.map((e) => ({ from: e.from, to: e.to, kind: "derives_from" })),
|
|
49
|
+
...input.contestedPairs
|
|
50
|
+
.filter((p) => p.a !== p.b && known.has(p.a) && known.has(p.b))
|
|
51
|
+
// canonical order so the undirected contested edge dedupes stably
|
|
52
|
+
.map((p) => {
|
|
53
|
+
const [from, to] = p.a < p.b ? [p.a, p.b] : [p.b, p.a];
|
|
54
|
+
return { from, to, kind: "contested" };
|
|
55
|
+
}),
|
|
56
|
+
];
|
|
57
|
+
const seen = new Set();
|
|
58
|
+
let allEdges = [];
|
|
59
|
+
for (const e of rawEdges) {
|
|
60
|
+
const key = `${e.kind}|${e.from}|${e.to}`;
|
|
61
|
+
if (seen.has(key))
|
|
62
|
+
continue;
|
|
63
|
+
seen.add(key);
|
|
64
|
+
allEdges.push(e);
|
|
65
|
+
}
|
|
66
|
+
const contestedNodes = new Set();
|
|
67
|
+
for (const e of allEdges) {
|
|
68
|
+
if (e.kind === "contested") {
|
|
69
|
+
contestedNodes.add(e.from);
|
|
70
|
+
contestedNodes.add(e.to);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Node universe, optionally narrowed to an ego neighborhood via undirected BFS.
|
|
74
|
+
let nodePaths = new Set(known);
|
|
75
|
+
if (opts.scope === "ego") {
|
|
76
|
+
const root = opts.root ?? "";
|
|
77
|
+
nodePaths = new Set();
|
|
78
|
+
if (known.has(root)) {
|
|
79
|
+
const depth = Math.max(0, opts.depth ?? 1);
|
|
80
|
+
const adj = adjacency(allEdges);
|
|
81
|
+
let frontier = new Set([root]);
|
|
82
|
+
nodePaths.add(root);
|
|
83
|
+
for (let d = 0; d < depth; d++) {
|
|
84
|
+
const next = new Set();
|
|
85
|
+
for (const n of frontier) {
|
|
86
|
+
for (const m of adj.get(n) ?? []) {
|
|
87
|
+
if (!nodePaths.has(m)) {
|
|
88
|
+
next.add(m);
|
|
89
|
+
nodePaths.add(m);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (next.size === 0)
|
|
94
|
+
break;
|
|
95
|
+
frontier = next;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const total = nodePaths.size;
|
|
100
|
+
// Cap (R8): if over the cap, keep the highest-degree nodes (most connected =
|
|
101
|
+
// most informative), deterministic tiebreak by path. The root, if any, is
|
|
102
|
+
// always retained.
|
|
103
|
+
const cap = opts.cap ?? DEFAULT_NODE_CAP;
|
|
104
|
+
let truncated = false;
|
|
105
|
+
if (nodePaths.size > cap) {
|
|
106
|
+
truncated = true;
|
|
107
|
+
const adj = adjacency(allEdges.filter((e) => nodePaths.has(e.from) && nodePaths.has(e.to)));
|
|
108
|
+
const ranked = [...nodePaths].sort((a, b) => {
|
|
109
|
+
const da = adj.get(a)?.size ?? 0;
|
|
110
|
+
const db = adj.get(b)?.size ?? 0;
|
|
111
|
+
return db - da || a.localeCompare(b);
|
|
112
|
+
});
|
|
113
|
+
const keep = new Set(ranked.slice(0, cap));
|
|
114
|
+
if (opts.scope === "ego" && opts.root && known.has(opts.root))
|
|
115
|
+
keep.add(opts.root);
|
|
116
|
+
nodePaths = keep;
|
|
117
|
+
}
|
|
118
|
+
const nodes = input.docs
|
|
119
|
+
.filter((d) => nodePaths.has(d.path))
|
|
120
|
+
.map((d) => ({
|
|
121
|
+
path: d.path,
|
|
122
|
+
title: d.title,
|
|
123
|
+
collection: d.collection,
|
|
124
|
+
tier: d.tier,
|
|
125
|
+
status: d.status,
|
|
126
|
+
decayed: input.decayed.has(d.path),
|
|
127
|
+
contested: contestedNodes.has(d.path),
|
|
128
|
+
}))
|
|
129
|
+
.sort((a, b) => (a.title || a.path).localeCompare(b.title || b.path));
|
|
130
|
+
allEdges = allEdges.filter((e) => nodePaths.has(e.from) && nodePaths.has(e.to));
|
|
131
|
+
return { nodes, edges: allEdges, total, shown: nodes.length, truncated };
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/view/graph.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,iFAAiF;AACjF,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,cAAc;AAsDd,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAEpC,iFAAiF;AACjF,4EAA4E;AAC5E,uEAAuE;AACvE,SAAS,gBAAgB,CACvB,OAAsC,EACtC,IAAmB,EACnB,KAAkB;IAElB,MAAM,GAAG,GAAgB,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,OAAO,EAAE,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,SAAS;QACjC,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,SAAS;YAClD,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,2EAA2E;AAC3E,SAAS,SAAS,CAAC,KAAkB;IACnC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC3C,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;QACpC,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,EAAU,CAAC;QAC1C,CAAC,CA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,CAAC,CAmC7D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Top-level entry for `daftari view` — start the read-only browse portal.
|
|
2
|
+
//
|
|
3
|
+
// Loopback only: the viewer renders your whole vault with no auth, so it must
|
|
4
|
+
// never bind a routable interface. There is deliberately no --bind flag.
|
|
5
|
+
//
|
|
6
|
+
// Exit codes (the audit convention):
|
|
7
|
+
// 0 — clean shutdown (SIGINT/SIGTERM)
|
|
8
|
+
// 2 — usage error
|
|
9
|
+
// 3 — listen failure
|
|
10
|
+
import { resolve } from "node:path";
|
|
11
|
+
import { createViewServer } from "./server.js";
|
|
12
|
+
export const DEFAULT_VIEW_PORT = 8788;
|
|
13
|
+
const BIND = "127.0.0.1";
|
|
14
|
+
const HELP = `daftari view — a read-only web portal over the vault.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
daftari view [--vault <path>] [--port <n>]
|
|
18
|
+
daftari view --help
|
|
19
|
+
|
|
20
|
+
Serves an index of documents by collection and a page per document (rendered
|
|
21
|
+
markdown, frontmatter, and backlinks). Loopback only (${BIND}); read-only — no
|
|
22
|
+
editing, no mutation routes. Stop with Ctrl-C.
|
|
23
|
+
|
|
24
|
+
Flags:
|
|
25
|
+
--vault <path> Vault root (default: current directory).
|
|
26
|
+
--port <n> Port (default: ${DEFAULT_VIEW_PORT}).
|
|
27
|
+
|
|
28
|
+
Exit codes:
|
|
29
|
+
0 — clean shutdown 2 — usage error 3 — listen failure
|
|
30
|
+
`;
|
|
31
|
+
function readStringArg(argv, flag) {
|
|
32
|
+
const raw = argv.find((a) => a === flag || a.startsWith(`${flag}=`));
|
|
33
|
+
if (raw === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
const idx = argv.indexOf(raw);
|
|
36
|
+
return raw.includes("=") ? raw.slice(raw.indexOf("=") + 1) : argv[idx + 1];
|
|
37
|
+
}
|
|
38
|
+
export async function runView(argv) {
|
|
39
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
40
|
+
process.stdout.write(HELP);
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
const vaultRoot = resolve(readStringArg(argv, "--vault") ?? ".");
|
|
44
|
+
let port = DEFAULT_VIEW_PORT;
|
|
45
|
+
const rawPort = readStringArg(argv, "--port");
|
|
46
|
+
if (rawPort !== undefined) {
|
|
47
|
+
const n = Number(rawPort);
|
|
48
|
+
if (!Number.isInteger(n) || n < 1 || n > 65535) {
|
|
49
|
+
process.stderr.write("daftari view: --port must be an integer in 1..65535\n");
|
|
50
|
+
return 2;
|
|
51
|
+
}
|
|
52
|
+
port = n;
|
|
53
|
+
}
|
|
54
|
+
const server = createViewServer(vaultRoot);
|
|
55
|
+
return new Promise((resolveCode) => {
|
|
56
|
+
server.on("error", (e) => {
|
|
57
|
+
process.stderr.write(`daftari view: ${e.message}\n`);
|
|
58
|
+
resolveCode(3);
|
|
59
|
+
});
|
|
60
|
+
server.listen(port, BIND, () => {
|
|
61
|
+
process.stdout.write(`daftari view: http://${BIND}:${port} (vault: ${vaultRoot})\n`);
|
|
62
|
+
});
|
|
63
|
+
const shutdown = () => {
|
|
64
|
+
server.close(() => resolveCode(0));
|
|
65
|
+
};
|
|
66
|
+
process.once("SIGINT", shutdown);
|
|
67
|
+
process.once("SIGTERM", shutdown);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/view/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AACzE,EAAE;AACF,qCAAqC;AACrC,wCAAwC;AACxC,oBAAoB;AACpB,uBAAuB;AAEvB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;A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AAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC;YAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;YAC9E,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,GAAG,CAAC,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAE3C,OAAO,IAAI,OAAO,CAAS,CAAC,WAAW,EAAE,EAAE;QACzC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC;YACrD,WAAW,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;YAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,IAAI,IAAI,IAAI,aAAa,SAAS,KAAK,CAAC,CAAC;QACxF,CAAC,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { GraphOptions } from "./graph.js";
|
|
2
|
+
import { type TocEntry } from "./render.js";
|
|
3
|
+
import type { StatusView } from "./status-view.js";
|
|
4
|
+
export declare function layout(title: string, bodyHtml: string, query?: string): string;
|
|
5
|
+
export interface DocFrontmatterView {
|
|
6
|
+
title: string;
|
|
7
|
+
collection: string;
|
|
8
|
+
status: string;
|
|
9
|
+
confidence: string;
|
|
10
|
+
provenance: string;
|
|
11
|
+
tier: string | null;
|
|
12
|
+
tags: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface DocBacklinkView {
|
|
15
|
+
doc: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
export interface DocTensionView {
|
|
19
|
+
counterpart: string;
|
|
20
|
+
kind: string;
|
|
21
|
+
claimSelf: string;
|
|
22
|
+
claimOther: string;
|
|
23
|
+
loggedAt: string;
|
|
24
|
+
}
|
|
25
|
+
export type DocBannerKind = "decay" | "structural" | "upstream" | "anchor" | "validity";
|
|
26
|
+
export interface DocBannerView {
|
|
27
|
+
kind: DocBannerKind;
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function renderDocPage(args: {
|
|
31
|
+
path: string;
|
|
32
|
+
frontmatter: DocFrontmatterView;
|
|
33
|
+
bodyHtml: string;
|
|
34
|
+
backlinks: DocBacklinkView[];
|
|
35
|
+
tensions?: DocTensionView[];
|
|
36
|
+
banners?: DocBannerView[];
|
|
37
|
+
validity?: string | null;
|
|
38
|
+
decayLevel?: string | null;
|
|
39
|
+
contestedCount?: number;
|
|
40
|
+
toc?: TocEntry[];
|
|
41
|
+
}): string;
|
|
42
|
+
export interface IndexEntry {
|
|
43
|
+
path: string;
|
|
44
|
+
title: string;
|
|
45
|
+
status?: string;
|
|
46
|
+
confidence?: string;
|
|
47
|
+
tier?: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface IndexGroup {
|
|
50
|
+
collection: string;
|
|
51
|
+
docs: IndexEntry[];
|
|
52
|
+
}
|
|
53
|
+
export declare function renderIndexPage(groups: IndexGroup[]): string;
|
|
54
|
+
export interface SearchHitView {
|
|
55
|
+
path: string;
|
|
56
|
+
title: string;
|
|
57
|
+
collection: string;
|
|
58
|
+
snippet: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function renderSearchPage(query: string, hits: SearchHitView[]): string;
|
|
61
|
+
export declare function renderGraphPage(opts: GraphOptions): string;
|
|
62
|
+
export declare function renderDashboardPage(s: StatusView): string;
|
|
63
|
+
//# sourceMappingURL=pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/view/pages.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAqLnD,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAS1E;AAmCD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;AAExF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,aAAa,CAAC;IACp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