llmtxt 2026.4.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +21 -0
  3. package/README.md +64 -0
  4. package/dist/cache.d.ts +155 -0
  5. package/dist/cache.d.ts.map +1 -0
  6. package/dist/cache.js +193 -0
  7. package/dist/cache.js.map +1 -0
  8. package/dist/client.d.ts +80 -0
  9. package/dist/client.d.ts.map +1 -0
  10. package/dist/client.js +143 -0
  11. package/dist/client.js.map +1 -0
  12. package/dist/compression.d.ts +9 -0
  13. package/dist/compression.d.ts.map +1 -0
  14. package/dist/compression.js +8 -0
  15. package/dist/compression.js.map +1 -0
  16. package/dist/disclosure.d.ts +215 -0
  17. package/dist/disclosure.d.ts.map +1 -0
  18. package/dist/disclosure.js +532 -0
  19. package/dist/disclosure.js.map +1 -0
  20. package/dist/graph.d.ts +76 -0
  21. package/dist/graph.d.ts.map +1 -0
  22. package/dist/graph.js +137 -0
  23. package/dist/graph.js.map +1 -0
  24. package/dist/index.d.ts +38 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +31 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/patch.d.ts +8 -0
  29. package/dist/patch.d.ts.map +1 -0
  30. package/dist/patch.js +8 -0
  31. package/dist/patch.js.map +1 -0
  32. package/dist/schemas.d.ts +290 -0
  33. package/dist/schemas.d.ts.map +1 -0
  34. package/dist/schemas.js +154 -0
  35. package/dist/schemas.js.map +1 -0
  36. package/dist/sdk/attribution.d.ts +59 -0
  37. package/dist/sdk/attribution.d.ts.map +1 -0
  38. package/dist/sdk/attribution.js +99 -0
  39. package/dist/sdk/attribution.js.map +1 -0
  40. package/dist/sdk/consensus.d.ts +73 -0
  41. package/dist/sdk/consensus.d.ts.map +1 -0
  42. package/dist/sdk/consensus.js +110 -0
  43. package/dist/sdk/consensus.js.map +1 -0
  44. package/dist/sdk/document.d.ts +92 -0
  45. package/dist/sdk/document.d.ts.map +1 -0
  46. package/dist/sdk/document.js +182 -0
  47. package/dist/sdk/document.js.map +1 -0
  48. package/dist/sdk/index.d.ts +22 -0
  49. package/dist/sdk/index.d.ts.map +1 -0
  50. package/dist/sdk/index.js +15 -0
  51. package/dist/sdk/index.js.map +1 -0
  52. package/dist/sdk/lifecycle.d.ts +66 -0
  53. package/dist/sdk/lifecycle.d.ts.map +1 -0
  54. package/dist/sdk/lifecycle.js +80 -0
  55. package/dist/sdk/lifecycle.js.map +1 -0
  56. package/dist/sdk/retrieval.d.ts +64 -0
  57. package/dist/sdk/retrieval.d.ts.map +1 -0
  58. package/dist/sdk/retrieval.js +102 -0
  59. package/dist/sdk/retrieval.js.map +1 -0
  60. package/dist/sdk/storage-adapter.d.ts +53 -0
  61. package/dist/sdk/storage-adapter.d.ts.map +1 -0
  62. package/dist/sdk/storage-adapter.js +2 -0
  63. package/dist/sdk/storage-adapter.js.map +1 -0
  64. package/dist/sdk/storage.d.ts +86 -0
  65. package/dist/sdk/storage.d.ts.map +1 -0
  66. package/dist/sdk/storage.js +69 -0
  67. package/dist/sdk/storage.js.map +1 -0
  68. package/dist/sdk/versions.d.ts +107 -0
  69. package/dist/sdk/versions.d.ts.map +1 -0
  70. package/dist/sdk/versions.js +129 -0
  71. package/dist/sdk/versions.js.map +1 -0
  72. package/dist/signed-url.d.ts +90 -0
  73. package/dist/signed-url.d.ts.map +1 -0
  74. package/dist/signed-url.js +159 -0
  75. package/dist/signed-url.js.map +1 -0
  76. package/dist/similarity.d.ts +57 -0
  77. package/dist/similarity.d.ts.map +1 -0
  78. package/dist/similarity.js +134 -0
  79. package/dist/similarity.js.map +1 -0
  80. package/dist/snapshot.d.ts +54 -0
  81. package/dist/snapshot.d.ts.map +1 -0
  82. package/dist/snapshot.js +94 -0
  83. package/dist/snapshot.js.map +1 -0
  84. package/dist/types.d.ts +92 -0
  85. package/dist/types.d.ts.map +1 -0
  86. package/dist/types.js +8 -0
  87. package/dist/types.js.map +1 -0
  88. package/dist/validation.d.ts +146 -0
  89. package/dist/validation.d.ts.map +1 -0
  90. package/dist/validation.js +285 -0
  91. package/dist/validation.js.map +1 -0
  92. package/dist/wasm.d.ts +28 -0
  93. package/dist/wasm.d.ts.map +1 -0
  94. package/dist/wasm.js +92 -0
  95. package/dist/wasm.js.map +1 -0
  96. package/package.json +98 -0
  97. package/wasm/LICENSE +21 -0
  98. package/wasm/README.md +63 -0
  99. package/wasm/llmtxt_core.d.ts +176 -0
  100. package/wasm/llmtxt_core.js +719 -0
  101. package/wasm/llmtxt_core_bg.wasm +0 -0
  102. package/wasm/llmtxt_core_bg.wasm.d.ts +37 -0
  103. package/wasm/package.json +25 -0
package/dist/client.js ADDED
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Lightweight llmtxt client for agents.
3
+ * Wraps the ClawMsgr attachment API with typed helpers.
4
+ * No framework dependencies — uses native fetch.
5
+ *
6
+ * When `@cleocode/lafs` is installed, responses are validated
7
+ * against the LAFS envelope schema. Without it, raw JSON is parsed directly.
8
+ */
9
+ import { createPatch } from './patch.js';
10
+ // ── LAFS integration (optional) ─────────────────────────────────
11
+ /** Lazy-loaded LAFS parser. Cached after first resolution. */
12
+ let lafsParser;
13
+ /**
14
+ * Attempt to load parseLafsResponse from @cleocode/lafs.
15
+ * Returns the parser function, or false if LAFS is not installed.
16
+ */
17
+ async function getLafsParser() {
18
+ if (lafsParser !== undefined)
19
+ return lafsParser;
20
+ try {
21
+ const lafs = await import('@cleocode/lafs');
22
+ lafsParser = lafs.parseLafsResponse;
23
+ return lafsParser;
24
+ }
25
+ catch {
26
+ lafsParser = false;
27
+ return false;
28
+ }
29
+ }
30
+ /**
31
+ * Parse a JSON response, using LAFS envelope validation when available.
32
+ */
33
+ async function parseResponse(json) {
34
+ const envelope = json;
35
+ const parser = await getLafsParser();
36
+ if (parser && '$schema' in envelope) {
37
+ return parser(json);
38
+ }
39
+ if (envelope.success === false) {
40
+ const err = envelope.error;
41
+ throw new Error(err?.message ?? 'Request failed');
42
+ }
43
+ return (envelope.result ?? envelope.data);
44
+ }
45
+ // ── Client ──────────────────────────────────────────────────────
46
+ export function createClient(config) {
47
+ const headers = {
48
+ Authorization: `Bearer ${config.apiKey}`,
49
+ 'X-Agent-Id': config.agentId,
50
+ 'Content-Type': 'application/json',
51
+ };
52
+ return {
53
+ /** Upload content as an attachment to a conversation. */
54
+ async upload(conversationId, content, options = {}) {
55
+ const { format = 'markdown', title, expiresIn = 3600 } = options;
56
+ const res = await fetch(`${config.apiBase}/conversations/${conversationId}/attachments`, {
57
+ method: 'POST',
58
+ headers,
59
+ body: JSON.stringify({ content, format, title, expiresIn }),
60
+ });
61
+ if (!res.ok)
62
+ throw new Error(`Upload failed (${res.status}): ${await res.text()}`);
63
+ return parseResponse(await res.json());
64
+ },
65
+ /** Fetch content from a signed URL. */
66
+ async fetch(signedUrl) {
67
+ const res = await fetch(signedUrl, { headers });
68
+ if (!res.ok)
69
+ throw new Error(`Fetch failed (${res.status}): ${await res.text()}`);
70
+ return parseResponse(await res.json());
71
+ },
72
+ /** Fetch an attachment shared in a conversation without needing a signed URL. */
73
+ async fetchFromConversation(slug, conversationId) {
74
+ const url = new URL(`${config.apiBase}/attachments/${slug}`);
75
+ url.searchParams.set('conv', conversationId);
76
+ const res = await fetch(url, { headers });
77
+ if (!res.ok) {
78
+ throw new Error(`Conversation fetch failed (${res.status}): ${await res.text()}`);
79
+ }
80
+ return parseResponse(await res.json());
81
+ },
82
+ /** Fetch an attachment owned by the current agent. */
83
+ async fetchOwned(slug) {
84
+ const res = await fetch(`${config.apiBase}/attachments/${slug}`, { headers });
85
+ if (!res.ok)
86
+ throw new Error(`Owner fetch failed (${res.status}): ${await res.text()}`);
87
+ return parseResponse(await res.json());
88
+ },
89
+ /**
90
+ * Change how an attachment is shared. For `signed_url` mode the API may
91
+ * return a fresh `signedUrl`; for `conversation`/`public` it may not.
92
+ */
93
+ async reshare(slug, options = {}) {
94
+ const { expiresIn = 3600, mode = 'signed_url' } = options;
95
+ const res = await fetch(`${config.apiBase}/attachments/${slug}/reshare`, {
96
+ method: 'POST',
97
+ headers,
98
+ body: JSON.stringify({ expiresIn, mode }),
99
+ });
100
+ if (!res.ok)
101
+ throw new Error(`Reshare failed (${res.status}): ${await res.text()}`);
102
+ return parseResponse(await res.json());
103
+ },
104
+ /** Backward-compatible alias for older API wording. Prefer `reshare`. */
105
+ async resign(slug, options = {}) {
106
+ return this.reshare(slug, options);
107
+ },
108
+ /** Build a version patch locally using the Rust/WASM core. */
109
+ createVersionPatch(original, updated) {
110
+ return createPatch(original, updated);
111
+ },
112
+ /** Submit a patch as the next version for an attachment slug. */
113
+ async addVersion(slug, patchText, options = {}) {
114
+ const res = await fetch(`${config.apiBase}/attachments/${slug}/versions`, {
115
+ method: 'POST',
116
+ headers,
117
+ body: JSON.stringify({ patchText, ...options }),
118
+ });
119
+ if (!res.ok)
120
+ throw new Error(`Add version failed (${res.status}): ${await res.text()}`);
121
+ return parseResponse(await res.json());
122
+ },
123
+ /** Convenience helper that diffs local content then appends the new version. */
124
+ async addVersionFromContent(slug, original, updated, options = {}) {
125
+ const patchText = createPatch(original, updated);
126
+ return this.addVersion(slug, patchText, options);
127
+ },
128
+ /** Check if a signed URL is still valid without fetching content. */
129
+ isValid(signedUrl) {
130
+ try {
131
+ const url = new URL(signedUrl);
132
+ const exp = url.searchParams.get('exp');
133
+ if (!exp)
134
+ return false;
135
+ return Date.now() < parseInt(exp, 10);
136
+ }
137
+ catch {
138
+ return false;
139
+ }
140
+ },
141
+ };
142
+ }
143
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAsDzC,mEAAmE;AAEnE,8DAA8D;AAC9D,IAAI,UAAgE,CAAC;AAErE;;;GAGG;AACH,KAAK,UA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,GAAG;oBAAE,OAAO,KAAK,CAAC;gBACvB,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Compression, encoding, hashing, and token estimation.
3
+ *
4
+ * All portable primitives delegate to the Rust WASM module — single
5
+ * source of truth, zero drift between TypeScript and Rust consumers.
6
+ */
7
+ export { encodeBase62, decodeBase62, compress, decompress, generateId, hashContent, calculateTokens, calculateCompressionRatio, computeDiff, } from './wasm.js';
8
+ export type { DiffResult } from './wasm.js';
9
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,yBAAyB,EACzB,WAAW,GACZ,MAAM,WAAW,CAAC;AAEnB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Compression, encoding, hashing, and token estimation.
3
+ *
4
+ * All portable primitives delegate to the Rust WASM module — single
5
+ * source of truth, zero drift between TypeScript and Rust consumers.
6
+ */
7
+ export { encodeBase62, decodeBase62, compress, decompress, generateId, hashContent, calculateTokens, calculateCompressionRatio, computeDiff, } from './wasm.js';
8
+ //# sourceMappingURL=compression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.js","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,eAAe,EACf,yBAAyB,EACzB,WAAW,GACZ,MAAM,WAAW,CAAC"}
@@ -0,0 +1,215 @@
1
+ /**
2
+ * A logical section identified within a document.
3
+ *
4
+ * @remarks
5
+ * Sections are detected by format-specific heuristics (headings in
6
+ * markdown, top-level keys in JSON, function/class declarations in code).
7
+ */
8
+ export interface Section {
9
+ /** Display title of the section (heading text, JSON key, or symbol name). */
10
+ title: string;
11
+ /** Nesting depth (0-based). Headings use depth = level - 1. */
12
+ depth: number;
13
+ /** 1-based line number where the section begins. */
14
+ startLine: number;
15
+ /** 1-based line number where the section ends (inclusive). */
16
+ endLine: number;
17
+ /** Estimated token count for the section content. */
18
+ tokenCount: number;
19
+ /** The structural type of the section. */
20
+ type: 'heading' | 'json-key' | 'code-block' | 'function' | 'class';
21
+ }
22
+ /**
23
+ * High-level structural overview of a document.
24
+ *
25
+ * @remarks
26
+ * Produced by {@link generateOverview}. Provides format detection,
27
+ * token counts, section listings, and format-specific extras (JSON keys
28
+ * or a markdown table of contents).
29
+ */
30
+ export interface DocumentOverview {
31
+ /** The detected document format. */
32
+ format: 'json' | 'markdown' | 'code' | 'text';
33
+ /** Total number of lines in the document. */
34
+ lineCount: number;
35
+ /** Estimated total token count for the entire document. */
36
+ tokenCount: number;
37
+ /** Ordered list of sections found in the document. */
38
+ sections: Section[];
39
+ /** Top-level JSON keys with type info and preview (JSON documents only). */
40
+ keys?: Array<{
41
+ key: string;
42
+ type: string;
43
+ preview: string;
44
+ }>;
45
+ /** Markdown table of contents entries (markdown documents only). */
46
+ toc?: Array<{
47
+ title: string;
48
+ depth: number;
49
+ line: number;
50
+ }>;
51
+ }
52
+ /**
53
+ * A single match returned by {@link searchContent}.
54
+ */
55
+ export interface SearchResult {
56
+ /** 1-based line number of the matching line. */
57
+ line: number;
58
+ /** The full text of the matching line. */
59
+ content: string;
60
+ /** Lines immediately preceding the match (up to `contextLines`). */
61
+ contextBefore: string[];
62
+ /** Lines immediately following the match (up to `contextLines`). */
63
+ contextAfter: string[];
64
+ }
65
+ /**
66
+ * Result of extracting a line range from a document via {@link getLineRange}.
67
+ */
68
+ export interface LineRangeResult {
69
+ /** 1-based line number where the extracted range begins. */
70
+ startLine: number;
71
+ /** 1-based line number where the extracted range ends (inclusive). */
72
+ endLine: number;
73
+ /** The extracted text content for the requested line range. */
74
+ content: string;
75
+ /** Estimated token count for the extracted content. */
76
+ tokenCount: number;
77
+ /** Total number of lines in the full document. */
78
+ totalLines: number;
79
+ /** Estimated total token count for the full document. */
80
+ totalTokens: number;
81
+ /** Number of tokens saved by extracting only this range. */
82
+ tokensSaved: number;
83
+ }
84
+ /**
85
+ * Extract a range of lines from a document, returning content and token statistics.
86
+ *
87
+ * @remarks
88
+ * Line numbers are 1-based and clamped to the document boundaries. This
89
+ * enables agents to request only the portion of a document they need,
90
+ * reducing token consumption.
91
+ *
92
+ * @param content - The full document content.
93
+ * @param start - The 1-based starting line number.
94
+ * @param end - The 1-based ending line number (inclusive).
95
+ * @returns A {@link LineRangeResult} with the extracted content and token savings.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const range = getLineRange(doc, 10, 25);
100
+ * console.log(`Saved ${range.tokensSaved} tokens`);
101
+ * ```
102
+ */
103
+ export declare function getLineRange(content: string, start: number, end: number): LineRangeResult;
104
+ /**
105
+ * Search document content for lines matching a query string or regex.
106
+ *
107
+ * @remarks
108
+ * Supports plain-text substring matching (case-insensitive) and regex
109
+ * patterns delimited with slashes (e.g. `/pattern/i`). Results include
110
+ * configurable surrounding context lines to help agents understand each
111
+ * match in context.
112
+ *
113
+ * @param content - The full document content to search.
114
+ * @param query - A plain-text substring or `/regex/flags` pattern.
115
+ * @param contextLines - Number of context lines before and after each match (default: 2).
116
+ * @param maxResults - Maximum number of matches to return (default: 20).
117
+ * @returns An array of {@link SearchResult} objects for each matching line.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const hits = searchContent(doc, 'TODO', 3, 10);
122
+ * ```
123
+ */
124
+ export declare function searchContent(content: string, query: string, contextLines?: number, maxResults?: number): SearchResult[];
125
+ /**
126
+ * Detect the structural format of a document using content heuristics.
127
+ *
128
+ * @remarks
129
+ * Applies the following precedence: JSON (valid `JSON.parse`), then
130
+ * markdown (2+ markdown signals such as headings, lists, or links), then
131
+ * code (2+ code signals such as `import`, `function`, or arrow syntax),
132
+ * and finally falls back to plain text.
133
+ *
134
+ * @param content - The document content to classify.
135
+ * @returns The detected format: `"json"`, `"markdown"`, `"code"`, or `"text"`.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * detectDocumentFormat('# Title\n- item'); // "markdown"
140
+ * ```
141
+ */
142
+ export declare function detectDocumentFormat(content: string): 'json' | 'markdown' | 'code' | 'text';
143
+ /**
144
+ * Generate a structural overview of a document for progressive disclosure.
145
+ *
146
+ * @remarks
147
+ * Detects the document format, splits it into logical sections, computes
148
+ * token counts, and extracts format-specific metadata (JSON keys or
149
+ * markdown table of contents). The overview allows agents to decide
150
+ * which sections to request in full, minimizing total token usage.
151
+ *
152
+ * @param content - The full document content to analyze.
153
+ * @returns A {@link DocumentOverview} with format, sections, and token counts.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const overview = generateOverview(markdownDoc);
158
+ * console.log(`${overview.sections.length} sections, ${overview.tokenCount} tokens`);
159
+ * ```
160
+ */
161
+ export declare function generateOverview(content: string): DocumentOverview;
162
+ /**
163
+ * Execute a JSONPath-style query against JSON content.
164
+ *
165
+ * @remarks
166
+ * Parses the content as JSON and resolves the dot/bracket path (e.g.
167
+ * `$.messages[0].content` or `data.items`). Supports wildcard (`*`) for
168
+ * arrays and objects. Throws on invalid JSON or missing keys to provide
169
+ * clear error messages to calling agents.
170
+ *
171
+ * @param content - A valid JSON string to query.
172
+ * @param path - A JSONPath expression (e.g. `"$.key"`, `"items[0].name"`).
173
+ * @returns An object containing the resolved `result`, its `tokenCount`, and the original `path`.
174
+ * @throws Error if the JSON is invalid or the path cannot be resolved.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * const { result } = queryJsonPath('{"a":{"b":42}}', '$.a.b');
179
+ * // result === 42
180
+ * ```
181
+ */
182
+ export declare function queryJsonPath(content: string, path: string): {
183
+ result: unknown;
184
+ tokenCount: number;
185
+ path: string;
186
+ };
187
+ /**
188
+ * Extract a named section from a document by title.
189
+ *
190
+ * @remarks
191
+ * Searches the document's sections (from {@link generateOverview}) for a
192
+ * matching title using progressively looser comparisons: exact match,
193
+ * substring match, and alphanumeric-only substring match. When
194
+ * `depthAll` is `true`, child sections at deeper nesting levels are
195
+ * included in the extracted content.
196
+ *
197
+ * @param content - The full document content.
198
+ * @param sectionName - The section title (or substring) to search for.
199
+ * @param depthAll - When `true`, include all child sections nested under the match (default: `false`).
200
+ * @returns An object with the matched section, extracted content, and token savings, or `null` if not found.
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * const section = getSection(doc, 'Installation', true);
205
+ * if (section) console.log(section.content);
206
+ * ```
207
+ */
208
+ export declare function getSection(content: string, sectionName: string, depthAll?: boolean): {
209
+ section: Section;
210
+ content: string;
211
+ tokenCount: number;
212
+ totalTokens: number;
213
+ tokensSaved: number;
214
+ } | null;
215
+ //# sourceMappingURL=disclosure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disclosure.d.ts","sourceRoot":"","sources":["../src/disclosure.ts"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC;CACpE;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,M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