@totalreclaw/mcp-server 3.2.0-rc.19 → 3.2.1
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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -168
- package/dist/index.js.map +1 -1
- package/dist/prompts.d.ts +2 -2
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +2 -6
- package/dist/prompts.js.map +1 -1
- package/dist/session-id.d.ts +17 -0
- package/dist/session-id.d.ts.map +1 -0
- package/dist/session-id.js +26 -0
- package/dist/session-id.js.map +1 -0
- package/dist/subgraph/confirm-indexed.d.ts +37 -0
- package/dist/subgraph/confirm-indexed.d.ts.map +1 -0
- package/dist/subgraph/confirm-indexed.js +99 -0
- package/dist/subgraph/confirm-indexed.js.map +1 -0
- package/dist/subgraph/reranker.d.ts +49 -134
- package/dist/subgraph/reranker.d.ts.map +1 -1
- package/dist/subgraph/reranker.js +84 -376
- package/dist/subgraph/reranker.js.map +1 -1
- package/dist/tools/pin.d.ts +12 -0
- package/dist/tools/pin.d.ts.map +1 -1
- package/dist/tools/pin.js +14 -0
- package/dist/tools/pin.js.map +1 -1
- package/dist/tools/retype.d.ts +15 -0
- package/dist/tools/retype.d.ts.map +1 -1
- package/dist/tools/retype.js +17 -0
- package/dist/tools/retype.js.map +1 -1
- package/dist/tools/status.d.ts.map +1 -1
- package/dist/tools/status.js +19 -5
- package/dist/tools/status.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Read-after-write primitive for the MCP server — confirm a fact id has been
|
|
4
|
+
* indexed by the subgraph after an on-chain mutation.
|
|
5
|
+
*
|
|
6
|
+
* Wraps the pure-compute halves exported by `@totalreclaw/core`
|
|
7
|
+
* (`wasmConfirmIndexedQuery`, `wasmConfirmIndexedParse`) in a host-side
|
|
8
|
+
* polling loop. The subgraph indexer typically lags 5-30s behind L1 inclusion
|
|
9
|
+
* on Gnosis production; without this wait, mutation tools (set_scope,
|
|
10
|
+
* retype, pin, unpin, forget) can return success before a follow-up
|
|
11
|
+
* recall/export sees the new state.
|
|
12
|
+
*
|
|
13
|
+
* Mnemonic isolation: this helper never touches the mnemonic, encryption
|
|
14
|
+
* key, or any decrypted blob.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.confirmIndexed = confirmIndexed;
|
|
18
|
+
const client_id_js_1 = require("../client-id.js");
|
|
19
|
+
// Loaded lazily so the server doesn't bind to the WASM module unless an
|
|
20
|
+
// on-chain mutation is actually exercised.
|
|
21
|
+
let _wasm = null;
|
|
22
|
+
async function getWasm() {
|
|
23
|
+
if (!_wasm) {
|
|
24
|
+
_wasm = (await import('@totalreclaw/core'));
|
|
25
|
+
}
|
|
26
|
+
return _wasm;
|
|
27
|
+
}
|
|
28
|
+
async function confirmIndexed(factId, options) {
|
|
29
|
+
// WASM bindings may be unavailable (core@<2.3.0 not yet published).
|
|
30
|
+
// Confirm step is observational; chain write has already succeeded.
|
|
31
|
+
// Return `indexed: false` so callers surface partial=true rather than fail.
|
|
32
|
+
let wasm;
|
|
33
|
+
let query;
|
|
34
|
+
let pollIntervalMs;
|
|
35
|
+
let timeoutMs;
|
|
36
|
+
try {
|
|
37
|
+
wasm = await getWasm();
|
|
38
|
+
pollIntervalMs =
|
|
39
|
+
options.pollIntervalMs ?? Number(wasm.wasmConfirmIndexedDefaultPollMs?.() ?? 1000);
|
|
40
|
+
timeoutMs =
|
|
41
|
+
options.timeoutMs ?? Number(wasm.wasmConfirmIndexedDefaultTimeoutMs?.() ?? 30000);
|
|
42
|
+
query = wasm.wasmConfirmIndexedQuery();
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
return {
|
|
46
|
+
indexed: false,
|
|
47
|
+
attempts: 0,
|
|
48
|
+
elapsedMs: 0,
|
|
49
|
+
lastError: `confirm-indexed wasm bindings unavailable: ${err instanceof Error ? err.message : String(err)}`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const headers = {
|
|
53
|
+
'Content-Type': 'application/json',
|
|
54
|
+
'X-TotalReclaw-Client': (0, client_id_js_1.getClientId)(),
|
|
55
|
+
};
|
|
56
|
+
if (options.authKeyHex)
|
|
57
|
+
headers['Authorization'] = `Bearer ${options.authKeyHex}`;
|
|
58
|
+
const body = JSON.stringify({ query, variables: { id: factId } });
|
|
59
|
+
const poster = options.poster ??
|
|
60
|
+
(async (url, b, h) => {
|
|
61
|
+
const r = await fetch(url, { method: 'POST', headers: h, body: b });
|
|
62
|
+
return { ok: r.ok, status: r.status, text: () => r.text() };
|
|
63
|
+
});
|
|
64
|
+
const expect = options.expect ?? 'active';
|
|
65
|
+
const start = Date.now();
|
|
66
|
+
let attempts = 0;
|
|
67
|
+
let lastError;
|
|
68
|
+
while (Date.now() - start < timeoutMs) {
|
|
69
|
+
attempts++;
|
|
70
|
+
try {
|
|
71
|
+
const r = await poster(options.subgraphUrl, body, headers);
|
|
72
|
+
if (r.ok) {
|
|
73
|
+
const txt = await r.text();
|
|
74
|
+
try {
|
|
75
|
+
const isActive = wasm.wasmConfirmIndexedParse(txt);
|
|
76
|
+
const resolved = expect === 'active' ? isActive : !isActive;
|
|
77
|
+
if (resolved) {
|
|
78
|
+
return { indexed: true, attempts, elapsedMs: Date.now() - start };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (parseErr) {
|
|
82
|
+
lastError = parseErr instanceof Error ? parseErr.message : String(parseErr);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
lastError = `HTTP ${r.status}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
lastError = err instanceof Error ? err.message : String(err);
|
|
91
|
+
}
|
|
92
|
+
const remaining = timeoutMs - (Date.now() - start);
|
|
93
|
+
if (remaining <= 0)
|
|
94
|
+
break;
|
|
95
|
+
await new Promise((res) => setTimeout(res, Math.min(pollIntervalMs, remaining)));
|
|
96
|
+
}
|
|
97
|
+
return { indexed: false, attempts, elapsedMs: Date.now() - start, lastError };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=confirm-indexed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-indexed.js","sourceRoot":"","sources":["../../src/subgraph/confirm-indexed.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAgDH,wCA0EC;AAxHD,kDAA8C;AAa9C,wEAAwE;AACxE,2CAA2C;AAC3C,IAAI,KAAK,GAA8B,IAAI,CAAC;AAC5C,KAAK,UAAU,OAAO;IACpB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAkC,CAAC;IAC/E,CAAC;IACD,OAAO,KAAM,CAAC;AAChB,CAAC;AAyBM,KAAK,UAAU,cAAc,CAClC,MAAc,EACd,OAA8B;IAE9B,oEAAoE;IACpE,oEAAoE;IACpE,4EAA4E;IAC5E,IAAI,IAAwB,CAAC;IAC7B,IAAI,KAAa,CAAC;IAClB,IAAI,cAAsB,CAAC;IAC3B,IAAI,SAAiB,CAAC;IACtB,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,OAAO,EAAE,CAAC;QACvB,cAAc;YACZ,OAAO,CAAC,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC;QACrF,SAAS;YACP,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,IAAI,KAAK,CAAC,CAAC;QACpF,KAAK,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,OAAO,EAAE,KAAK;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AAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -1,159 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TotalReclaw MCP
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* f(qi, D) = frequency of term qi in document D
|
|
28
|
-
* |D| = length of document D (in tokens)
|
|
29
|
-
* avgdl = average document length across the corpus
|
|
30
|
-
* N = total number of documents
|
|
31
|
-
* n(qi) = number of documents containing term qi
|
|
32
|
-
*
|
|
33
|
-
* @param queryTerms - Tokenized query terms
|
|
34
|
-
* @param docTerms - Tokenized document terms
|
|
35
|
-
* @param avgDocLen - Average document length (in tokens) across the candidate corpus
|
|
36
|
-
* @param docCount - Total number of documents in the candidate corpus
|
|
37
|
-
* @param termDocFreqs - Map from term to number of documents containing that term
|
|
38
|
-
* @param k1 - BM25 k1 parameter (default 1.2)
|
|
39
|
-
* @param b - BM25 b parameter (default 0.75)
|
|
40
|
-
*/
|
|
41
|
-
export declare function bm25Score(queryTerms: string[], docTerms: string[], avgDocLen: number, docCount: number, termDocFreqs: Map<string, number>, k1?: number, b?: number): number;
|
|
42
|
-
/**
|
|
43
|
-
* Compute cosine similarity between two vectors.
|
|
44
|
-
*
|
|
45
|
-
* Delegates to the Rust WASM core for performance.
|
|
46
|
-
* Returns dot(a, b) / (||a|| * ||b||).
|
|
47
|
-
* Returns 0 if either vector is empty or vectors have different lengths.
|
|
2
|
+
* TotalReclaw MCP -- Reranker (thin wrapper around `@totalreclaw/core`).
|
|
3
|
+
*
|
|
4
|
+
* As of rc.22 the MCP server no longer ships its own BM25 / RRF / source-weight
|
|
5
|
+
* implementation. All ranking decisions are delegated to the canonical Rust
|
|
6
|
+
* core (`rerankWithConfig`, `cosineSimilarity`, `sourceWeight`,
|
|
7
|
+
* `legacyClaimFallbackWeight`) so plugin / Hermes / MCP runtimes share one
|
|
8
|
+
* source of truth and cannot drift again (rc.18 cosine-gate divergence).
|
|
9
|
+
*
|
|
10
|
+
* The previous client-side pipeline added importance, recency, and MMR
|
|
11
|
+
* signals on top of BM25 + cosine. Those signals are dropped here:
|
|
12
|
+
* core's intent-weighted RRF + source-weighted final score is the
|
|
13
|
+
* canonical Pipeline G + Tier 1 mix that benchmark E13 calibrated. The
|
|
14
|
+
* extra TS-side passes were not part of the validated baseline and were a
|
|
15
|
+
* source of cross-client divergence.
|
|
16
|
+
*
|
|
17
|
+
* Public surface kept for callers (mcp/src/index.ts, mcp/src/consolidation.ts):
|
|
18
|
+
* - `rerank(query, queryEmbedding, candidates, topK, _legacyWeights, applySourceWeights)`
|
|
19
|
+
* - `cosineSimilarity(a, b)`
|
|
20
|
+
* - `getSourceWeight(source)`
|
|
21
|
+
* - `detectQueryIntent(query)` and `INTENT_WEIGHTS`
|
|
22
|
+
* (kept as no-ops for callers that pass them in -- core handles
|
|
23
|
+
* intent-weighting internally now, so the legacy weights argument is
|
|
24
|
+
* ignored.)
|
|
25
|
+
* - Types: `RerankerCandidate`, `RerankerResult`, `RankingWeights`,
|
|
26
|
+
* `QueryIntent`.
|
|
48
27
|
*/
|
|
49
28
|
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
50
|
-
export
|
|
51
|
-
|
|
52
|
-
score: number;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Fuse multiple ranking lists using Reciprocal Rank Fusion.
|
|
56
|
-
*
|
|
57
|
-
* For each document d appearing in any ranking list:
|
|
58
|
-
* rrfScore(d) = SUM_i 1 / (k + rank_i(d))
|
|
59
|
-
*
|
|
60
|
-
* where rank_i(d) is the 1-based rank of document d in the i-th list.
|
|
61
|
-
* Documents not present in a list are not penalized (they simply receive
|
|
62
|
-
* no contribution from that list).
|
|
63
|
-
*
|
|
64
|
-
* @param rankings - Array of ranking lists, each sorted by score descending.
|
|
65
|
-
* Each item has an `id` and a `score`.
|
|
66
|
-
* @param k - RRF smoothing constant (default 60, per the original paper).
|
|
67
|
-
* @returns - Fused ranking sorted by RRF score descending.
|
|
68
|
-
*/
|
|
69
|
-
export declare function rrfFuse(rankings: RankedItem[][], k?: number): RankedItem[];
|
|
70
|
-
/**
|
|
71
|
-
* Fuse multiple ranking lists using Weighted Reciprocal Rank Fusion.
|
|
72
|
-
*
|
|
73
|
-
* Like standard RRF, but each ranking list's contribution is multiplied by
|
|
74
|
-
* its weight, allowing callers to emphasize or de-emphasize specific signals.
|
|
75
|
-
*
|
|
76
|
-
* @param rankings - Array of ranking lists, each sorted by score descending.
|
|
77
|
-
* @param weights - Weight for each ranking list (same length as rankings).
|
|
78
|
-
* @param k - RRF smoothing constant (default 60).
|
|
79
|
-
* @returns - Fused ranking sorted by weighted RRF score descending.
|
|
80
|
-
*/
|
|
81
|
-
export declare function weightedRrfFuse(rankings: RankedItem[][], weights: number[], k?: number): RankedItem[];
|
|
29
|
+
export declare function getSourceWeight(source: string | undefined): number;
|
|
30
|
+
export type QueryIntent = 'factual' | 'temporal' | 'semantic';
|
|
82
31
|
export interface RankingWeights {
|
|
83
32
|
bm25: number;
|
|
84
33
|
cosine: number;
|
|
85
34
|
importance: number;
|
|
86
35
|
recency: number;
|
|
87
36
|
}
|
|
88
|
-
export declare const DEFAULT_WEIGHTS: RankingWeights;
|
|
89
|
-
/** The detected intent of a user query. */
|
|
90
|
-
export type QueryIntent = 'factual' | 'temporal' | 'semantic';
|
|
91
|
-
/** Ranking weights tuned for each query intent. */
|
|
92
37
|
export declare const INTENT_WEIGHTS: Record<QueryIntent, RankingWeights>;
|
|
93
|
-
/**
|
|
94
|
-
* Classify a query into one of three intent types using lightweight heuristics.
|
|
95
|
-
* Temporal is checked first so "What did we discuss yesterday?" -> temporal.
|
|
96
|
-
*/
|
|
97
38
|
export declare function detectQueryIntent(query: string): QueryIntent;
|
|
98
39
|
export interface RerankerCandidate {
|
|
99
40
|
id: string;
|
|
100
41
|
text: string;
|
|
101
42
|
embedding?: number[];
|
|
43
|
+
/** Unused now -- core ignores importance. Kept for API stability. */
|
|
102
44
|
importance?: number;
|
|
45
|
+
/** Unused now -- core ignores recency. Kept for API stability. */
|
|
103
46
|
createdAt?: number;
|
|
47
|
+
/** Memory Taxonomy v1 source ("user" | "user-inferred" | ... ). */
|
|
48
|
+
source?: string;
|
|
104
49
|
}
|
|
105
50
|
export interface RerankerResult extends RerankerCandidate {
|
|
51
|
+
/** Final fused score from core (post source-weight multiplication). */
|
|
106
52
|
rrfScore: number;
|
|
107
53
|
cosineSimilarity?: number;
|
|
54
|
+
/** Source weight multiplier applied (1.0 if no weighting). */
|
|
55
|
+
sourceWeight?: number;
|
|
108
56
|
}
|
|
109
57
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @param topK - Number of results to return (default 8)
|
|
125
|
-
* @returns - Re-ordered candidates with diversity
|
|
126
|
-
*/
|
|
127
|
-
export declare function applyMMR(candidates: RerankerCandidate[], lambda?: number, topK?: number): RerankerCandidate[];
|
|
128
|
-
/**
|
|
129
|
-
* Re-rank decrypted candidates using BM25 + Cosine + Importance + Recency
|
|
130
|
-
* with Weighted RRF fusion and MMR diversity.
|
|
131
|
-
*
|
|
132
|
-
* Pipeline:
|
|
133
|
-
* 1. Tokenize query and all candidate texts
|
|
134
|
-
* 2. Build corpus statistics (term document frequencies, average doc length)
|
|
135
|
-
* 3. Score each candidate with BM25
|
|
136
|
-
* 4. Score each candidate with cosine similarity (if embedding available)
|
|
137
|
-
* 5. Score each candidate by importance
|
|
138
|
-
* 6. Score each candidate by recency
|
|
139
|
-
* 7. Fuse all 4 rankings with weighted RRF
|
|
140
|
-
* 8. Apply MMR for diversity
|
|
141
|
-
* 9. Return top-k candidates sorted by fused score
|
|
142
|
-
*
|
|
143
|
-
* Backward compatibility:
|
|
144
|
-
* - Candidates without embeddings get cosine score = 0 and are excluded
|
|
145
|
-
* from the cosine ranking list. They can still rank well via other signals.
|
|
146
|
-
* - If NO candidates have embeddings, cosine ranking is omitted.
|
|
147
|
-
* - Candidates without importance get neutral score (0.5).
|
|
148
|
-
* - Candidates without createdAt get neutral recency score (0.5).
|
|
149
|
-
* - topK defaults to 8, weights default to equal (0.25 each).
|
|
150
|
-
*
|
|
151
|
-
* @param query - The user's search query (plaintext)
|
|
152
|
-
* @param queryEmbedding - Embedding vector for the query
|
|
153
|
-
* @param candidates - Decrypted candidates with text and optional embeddings
|
|
154
|
-
* @param topK - Number of results to return (default 8)
|
|
155
|
-
* @param weights - Optional partial ranking weights (merged with defaults)
|
|
156
|
-
* @returns - Top-k candidates sorted by fused score, with scores attached
|
|
58
|
+
* Re-rank decrypted candidates by delegating to core's `rerankWithConfig`.
|
|
59
|
+
*
|
|
60
|
+
* @param query The user's plaintext search query.
|
|
61
|
+
* @param queryEmbedding Embedding vector for the query.
|
|
62
|
+
* @param candidates Decrypted candidates with text and optional
|
|
63
|
+
* embeddings + v1 source.
|
|
64
|
+
* @param topK Top-K to return (default 8).
|
|
65
|
+
* @param _legacyWeights IGNORED -- kept for API stability so existing
|
|
66
|
+
* callers still compile. Core handles
|
|
67
|
+
* intent-weighting internally based on per-candidate
|
|
68
|
+
* cosine scores.
|
|
69
|
+
* @param applySourceWeights When true, multiply the final fused score by
|
|
70
|
+
* the v1 source-weight (Retrieval v2 Tier 1).
|
|
71
|
+
* Default true at all production call sites.
|
|
157
72
|
*/
|
|
158
|
-
export declare function rerank(query: string, queryEmbedding: number[], candidates: RerankerCandidate[], topK?: number,
|
|
73
|
+
export declare function rerank(query: string, queryEmbedding: number[], candidates: RerankerCandidate[], topK?: number, _legacyWeights?: Partial<RankingWeights>, applySourceWeights?: boolean): RerankerResult[];
|
|
159
74
|
//# sourceMappingURL=reranker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reranker.d.ts","sourceRoot":"","sources":["../../src/subgraph/reranker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"reranker.d.ts","sourceRoot":"","sources":["../../src/subgraph/reranker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAQH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAIjE;AAMD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAGlE;AAYD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE9D,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAKD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAI9D,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAI5D;AAMD,MAAM,WAAW,iBAAiB;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