@psiclawops/hypermem 0.1.0 → 0.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.
Files changed (93) hide show
  1. package/ARCHITECTURE.md +4 -3
  2. package/README.md +457 -174
  3. package/package.json +15 -5
  4. package/dist/background-indexer.d.ts +0 -117
  5. package/dist/background-indexer.d.ts.map +0 -1
  6. package/dist/background-indexer.js +0 -732
  7. package/dist/compaction-fence.d.ts +0 -89
  8. package/dist/compaction-fence.d.ts.map +0 -1
  9. package/dist/compaction-fence.js +0 -153
  10. package/dist/compositor.d.ts +0 -139
  11. package/dist/compositor.d.ts.map +0 -1
  12. package/dist/compositor.js +0 -1109
  13. package/dist/cross-agent.d.ts +0 -57
  14. package/dist/cross-agent.d.ts.map +0 -1
  15. package/dist/cross-agent.js +0 -254
  16. package/dist/db.d.ts +0 -131
  17. package/dist/db.d.ts.map +0 -1
  18. package/dist/db.js +0 -398
  19. package/dist/desired-state-store.d.ts +0 -100
  20. package/dist/desired-state-store.d.ts.map +0 -1
  21. package/dist/desired-state-store.js +0 -212
  22. package/dist/doc-chunk-store.d.ts +0 -115
  23. package/dist/doc-chunk-store.d.ts.map +0 -1
  24. package/dist/doc-chunk-store.js +0 -278
  25. package/dist/doc-chunker.d.ts +0 -99
  26. package/dist/doc-chunker.d.ts.map +0 -1
  27. package/dist/doc-chunker.js +0 -324
  28. package/dist/episode-store.d.ts +0 -48
  29. package/dist/episode-store.d.ts.map +0 -1
  30. package/dist/episode-store.js +0 -135
  31. package/dist/fact-store.d.ts +0 -57
  32. package/dist/fact-store.d.ts.map +0 -1
  33. package/dist/fact-store.js +0 -175
  34. package/dist/fleet-store.d.ts +0 -144
  35. package/dist/fleet-store.d.ts.map +0 -1
  36. package/dist/fleet-store.js +0 -276
  37. package/dist/hybrid-retrieval.d.ts +0 -60
  38. package/dist/hybrid-retrieval.d.ts.map +0 -1
  39. package/dist/hybrid-retrieval.js +0 -340
  40. package/dist/index.d.ts +0 -611
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -1042
  43. package/dist/knowledge-graph.d.ts +0 -110
  44. package/dist/knowledge-graph.d.ts.map +0 -1
  45. package/dist/knowledge-graph.js +0 -305
  46. package/dist/knowledge-store.d.ts +0 -72
  47. package/dist/knowledge-store.d.ts.map +0 -1
  48. package/dist/knowledge-store.js +0 -241
  49. package/dist/library-schema.d.ts +0 -22
  50. package/dist/library-schema.d.ts.map +0 -1
  51. package/dist/library-schema.js +0 -717
  52. package/dist/message-store.d.ts +0 -76
  53. package/dist/message-store.d.ts.map +0 -1
  54. package/dist/message-store.js +0 -273
  55. package/dist/preference-store.d.ts +0 -54
  56. package/dist/preference-store.d.ts.map +0 -1
  57. package/dist/preference-store.js +0 -109
  58. package/dist/preservation-gate.d.ts +0 -82
  59. package/dist/preservation-gate.d.ts.map +0 -1
  60. package/dist/preservation-gate.js +0 -150
  61. package/dist/provider-translator.d.ts +0 -40
  62. package/dist/provider-translator.d.ts.map +0 -1
  63. package/dist/provider-translator.js +0 -349
  64. package/dist/rate-limiter.d.ts +0 -76
  65. package/dist/rate-limiter.d.ts.map +0 -1
  66. package/dist/rate-limiter.js +0 -179
  67. package/dist/redis.d.ts +0 -188
  68. package/dist/redis.d.ts.map +0 -1
  69. package/dist/redis.js +0 -534
  70. package/dist/schema.d.ts +0 -15
  71. package/dist/schema.d.ts.map +0 -1
  72. package/dist/schema.js +0 -203
  73. package/dist/secret-scanner.d.ts +0 -51
  74. package/dist/secret-scanner.d.ts.map +0 -1
  75. package/dist/secret-scanner.js +0 -248
  76. package/dist/seed.d.ts +0 -108
  77. package/dist/seed.d.ts.map +0 -1
  78. package/dist/seed.js +0 -177
  79. package/dist/system-store.d.ts +0 -73
  80. package/dist/system-store.d.ts.map +0 -1
  81. package/dist/system-store.js +0 -182
  82. package/dist/topic-store.d.ts +0 -45
  83. package/dist/topic-store.d.ts.map +0 -1
  84. package/dist/topic-store.js +0 -136
  85. package/dist/types.d.ts +0 -329
  86. package/dist/types.d.ts.map +0 -1
  87. package/dist/types.js +0 -9
  88. package/dist/vector-store.d.ts +0 -132
  89. package/dist/vector-store.d.ts.map +0 -1
  90. package/dist/vector-store.js +0 -498
  91. package/dist/work-store.d.ts +0 -112
  92. package/dist/work-store.d.ts.map +0 -1
  93. package/dist/work-store.js +0 -273
package/dist/types.d.ts DELETED
@@ -1,329 +0,0 @@
1
- /**
2
- * HyperMem Core Types
3
- *
4
- * Provider-neutral message format and compositor interfaces.
5
- * These types are the internal representation — never sent directly to an LLM.
6
- * Provider translators convert to/from provider-specific formats at the boundary.
7
- */
8
- export type MessageRole = 'user' | 'assistant' | 'system';
9
- /**
10
- * Provider-neutral tool call representation.
11
- * Stored as JSON in the tool_calls column.
12
- */
13
- export interface NeutralToolCall {
14
- id: string;
15
- name: string;
16
- arguments: string;
17
- }
18
- /**
19
- * Provider-neutral tool result representation.
20
- * Stored as JSON in the tool_results column.
21
- */
22
- export interface NeutralToolResult {
23
- callId: string;
24
- name: string;
25
- content: string;
26
- isError?: boolean;
27
- }
28
- /**
29
- * Provider-neutral message — the canonical storage format.
30
- */
31
- export interface NeutralMessage {
32
- role: MessageRole;
33
- textContent: string | null;
34
- toolCalls: NeutralToolCall[] | null;
35
- toolResults: NeutralToolResult[] | null;
36
- metadata?: Record<string, unknown>;
37
- }
38
- /**
39
- * Stored message with database fields.
40
- */
41
- export interface StoredMessage extends NeutralMessage {
42
- id: number;
43
- conversationId: number;
44
- agentId: string;
45
- messageIndex: number;
46
- tokenCount: number | null;
47
- isHeartbeat: boolean;
48
- createdAt: string;
49
- }
50
- export type ChannelType = 'webchat' | 'discord' | 'telegram' | 'signal' | 'subagent' | 'heartbeat' | 'other';
51
- export type ConversationStatus = 'active' | 'ended' | 'archived';
52
- export interface Conversation {
53
- id: number;
54
- sessionKey: string;
55
- sessionId: string | null;
56
- agentId: string;
57
- channelType: ChannelType;
58
- channelId: string | null;
59
- provider: string | null;
60
- model: string | null;
61
- status: ConversationStatus;
62
- messageCount: number;
63
- tokenCountIn: number;
64
- tokenCountOut: number;
65
- createdAt: string;
66
- updatedAt: string;
67
- endedAt: string | null;
68
- }
69
- export type FactScope = 'agent' | 'session' | 'user';
70
- /**
71
- * Memory visibility levels:
72
- * - private: Only the owning agent can read. Identity, SOUL, personal reflections.
73
- * - org: Agents in the same org (e.g., Forge's directors: Pylon, Vigil, Plane).
74
- * - council: All council seats can read.
75
- * - fleet: Any agent in the fleet can read.
76
- */
77
- export type MemoryVisibility = 'private' | 'org' | 'council' | 'fleet';
78
- /**
79
- * Cross-agent query request. The requesting agent declares who they are;
80
- * the access layer filters results by visibility.
81
- */
82
- export interface CrossAgentQuery {
83
- /** The agent making the request */
84
- requesterId: string;
85
- /** The agent whose memory is being queried */
86
- targetAgentId: string;
87
- /** What to search for */
88
- query?: string;
89
- /** Filter by domain */
90
- domain?: string;
91
- /** Filter by memory type */
92
- memoryType?: 'facts' | 'knowledge' | 'topics' | 'episodes' | 'messages';
93
- /** Max results */
94
- limit?: number;
95
- }
96
- /**
97
- * Defines an agent's org and tier for visibility resolution.
98
- */
99
- export interface AgentIdentity {
100
- agentId: string;
101
- tier: 'council' | 'director' | 'specialist' | 'worker';
102
- org?: string;
103
- councilLead?: string;
104
- }
105
- export interface Fact {
106
- id: number;
107
- agentId: string;
108
- scope: FactScope;
109
- domain: string | null;
110
- content: string;
111
- confidence: number;
112
- visibility: string;
113
- sourceType: string;
114
- sourceSessionKey: string | null;
115
- sourceRef: string | null;
116
- createdAt: string;
117
- updatedAt: string;
118
- expiresAt: string | null;
119
- supersededBy: number | null;
120
- decayScore: number;
121
- }
122
- export type TopicStatus = 'active' | 'dormant' | 'closed';
123
- export interface Topic {
124
- id: number;
125
- agentId: string;
126
- name: string;
127
- description: string | null;
128
- status: TopicStatus;
129
- visibility: string;
130
- lastSessionKey: string | null;
131
- messageCount: number;
132
- createdAt: string;
133
- updatedAt: string;
134
- }
135
- export interface Knowledge {
136
- id: number;
137
- agentId: string;
138
- domain: string;
139
- key: string;
140
- content: string;
141
- confidence: number;
142
- sourceType: string;
143
- sourceRef: string | null;
144
- createdAt: string;
145
- updatedAt: string;
146
- expiresAt: string | null;
147
- supersededBy: number | null;
148
- }
149
- export type EpisodeType = 'decision' | 'incident' | 'discovery' | 'interaction' | 'milestone' | 'deployment' | 'config_change';
150
- export interface Episode {
151
- id: number;
152
- agentId: string;
153
- eventType: EpisodeType;
154
- summary: string;
155
- significance: number;
156
- visibility: string;
157
- participants: string[] | null;
158
- sessionKey: string | null;
159
- createdAt: string;
160
- decayScore: number;
161
- }
162
- export interface ComposeRequest {
163
- agentId: string;
164
- sessionKey: string;
165
- tokenBudget: number;
166
- provider?: string;
167
- model?: string;
168
- /** Agent tier (council/director/specialist) — used for tier-scoped doc chunk retrieval */
169
- tier?: string;
170
- includeHistory?: boolean;
171
- /** Whether to include demand-loaded doc chunks based on conversation triggers */
172
- includeDocChunks?: boolean;
173
- historyDepth?: number;
174
- includeFacts?: boolean;
175
- includeContext?: boolean;
176
- includeLibrary?: boolean;
177
- /**
178
- * The current-turn prompt text. Used as the retrieval query for semantic recall
179
- * and doc chunk trigger matching. When provided, this is preferred over reading
180
- * the last user message from the assembled history (which is one turn stale).
181
- *
182
- * Without this, retrieval fires against the previously-recorded user message,
183
- * meaning first-turn retrieval is blind and all retrieval lags by one turn.
184
- */
185
- prompt?: string;
186
- /**
187
- * When true, skip provider-specific translation and return NeutralMessage[]
188
- * instead of ProviderMessage[]. Used by the context engine plugin, which
189
- * returns messages to the OpenClaw runtime for its own provider translation.
190
- */
191
- skipProviderTranslation?: boolean;
192
- }
193
- export interface SlotTokenCounts {
194
- system: number;
195
- identity: number;
196
- history: number;
197
- facts: number;
198
- context: number;
199
- library: number;
200
- }
201
- export interface ComposeResult {
202
- messages: ProviderMessage[];
203
- tokenCount: number;
204
- slots: SlotTokenCounts;
205
- /** True only when token budget was exceeded (remaining < 0). */
206
- truncated: boolean;
207
- /** True when any non-fatal warnings were emitted (soft failures, truncated slots, etc.). */
208
- hasWarnings: boolean;
209
- warnings: string[];
210
- /**
211
- * The assembled context block (facts, recall, episodes) as a plain string.
212
- * Used by the plugin to pass as systemPromptAddition to the OpenClaw runtime.
213
- * Omitted when no context was assembled.
214
- */
215
- contextBlock?: string;
216
- }
217
- /**
218
- * Provider-specific message format (output of compositor).
219
- * This is what gets sent to the LLM API.
220
- * The exact shape depends on the provider translator.
221
- */
222
- export interface ProviderMessage {
223
- role: string;
224
- content: unknown;
225
- [key: string]: unknown;
226
- }
227
- /**
228
- * Tracks the most recently composed submission window boundary.
229
- * Written by compose() after every assembly, read by the background indexer
230
- * to identify high-signal unprocessed messages.
231
- *
232
- * Stored in Redis (hm:{a}:s:{s}:cursor) with dual-write to SQLite for
233
- * durability across Redis eviction (Compass Gate 2).
234
- */
235
- export interface SessionCursor {
236
- /** StoredMessage.id of the newest message included in the last window */
237
- lastSentId: number;
238
- /** messageIndex of the newest message — for ordering guarantees */
239
- lastSentIndex: number;
240
- /** ISO timestamp of when the window was composed */
241
- lastSentAt: string;
242
- /** Number of messages in the composed window */
243
- windowSize: number;
244
- /** Token count of the composed window */
245
- tokenCount: number;
246
- }
247
- export interface SessionSlots {
248
- system: string | null;
249
- identity: string | null;
250
- history: StoredMessage[];
251
- context: string | null;
252
- facts: string | null;
253
- tools: string | null;
254
- meta: SessionMeta;
255
- }
256
- export interface SessionMeta {
257
- agentId: string;
258
- sessionKey: string;
259
- provider: string | null;
260
- model: string | null;
261
- channelType: ChannelType;
262
- tokenCount: number;
263
- lastActive: string;
264
- status: ConversationStatus;
265
- }
266
- export interface HyperMemConfig {
267
- enabled: boolean;
268
- dataDir: string;
269
- redis: RedisConfig;
270
- compositor: CompositorConfig;
271
- indexer: IndexerConfig;
272
- embedding: EmbeddingProviderConfig;
273
- }
274
- export interface EmbeddingProviderConfig {
275
- /** Ollama base URL. Default: http://localhost:11434 */
276
- ollamaUrl: string;
277
- /** Embedding model name. Default: nomic-embed-text */
278
- model: string;
279
- /** Embedding dimensions. Default: 768 */
280
- dimensions: number;
281
- /** Request timeout ms. Default: 10000 */
282
- timeout: number;
283
- /** Max texts per batch request. Default: 32 */
284
- batchSize: number;
285
- }
286
- export interface RedisConfig {
287
- host: string;
288
- port: number;
289
- password?: string;
290
- keyPrefix: string;
291
- sessionTTL: number;
292
- historyTTL: number;
293
- flushInterval: number;
294
- }
295
- export interface CompositorConfig {
296
- defaultTokenBudget: number;
297
- maxHistoryMessages: number;
298
- maxFacts: number;
299
- maxCrossSessionContext: number;
300
- /**
301
- * How many recent tool call/result pairs to keep verbatim in history.
302
- * Tool call/result content beyond this threshold gets prose-stub treatment.
303
- * Default: 3
304
- */
305
- maxRecentToolPairs: number;
306
- /**
307
- * How many tool pairs beyond the verbatim threshold to convert to heuristic
308
- * prose stubs (e.g. "Read /src/foo.ts (1.2KB)"). Pairs beyond this are
309
- * dropped entirely (text content preserved, tool payloads nulled).
310
- * Default: 10
311
- */
312
- maxProseToolPairs: number;
313
- /**
314
- * Fraction of defaultTokenBudget to allocate for history during warm bootstrap.
315
- * Replaces the old WARM_BOOTSTRAP_CAP message-count constant.
316
- * Default: 0.4 (40% of defaultTokenBudget)
317
- */
318
- warmHistoryBudgetFraction: number;
319
- }
320
- export interface IndexerConfig {
321
- enabled: boolean;
322
- factExtractionMode: 'off' | 'pattern' | 'tiered';
323
- topicDormantAfter: string;
324
- topicClosedAfter: string;
325
- factDecayRate: number;
326
- episodeSignificanceThreshold: number;
327
- periodicInterval: number;
328
- }
329
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS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AiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,4BAA4B,EAAE,MAAM,CAAC;IACrC,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
package/dist/types.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * HyperMem Core Types
3
- *
4
- * Provider-neutral message format and compositor interfaces.
5
- * These types are the internal representation — never sent directly to an LLM.
6
- * Provider translators convert to/from provider-specific formats at the boundary.
7
- */
8
- export {};
9
- //# sourceMappingURL=types.js.map
@@ -1,132 +0,0 @@
1
- /**
2
- * HyperMem Vector Store — Semantic Search via sqlite-vec
3
- *
4
- * Provides embedding-backed KNN search over facts, knowledge, episodes,
5
- * and session registry entries. Uses Ollama (local) for embeddings,
6
- * sqlite-vec for vector indexing, and coexists with existing FTS5.
7
- *
8
- * Architecture:
9
- * - One vec0 virtual table per indexed content type
10
- * - Embeddings generated via local Ollama (nomic-embed-text, 768d)
11
- * - Vectors stored alongside content in the same agent DB
12
- * - Embedding cache to avoid redundant API calls
13
- * - Batch embedding support for bulk indexing
14
- */
15
- import type { DatabaseSync } from 'node:sqlite';
16
- export interface EmbeddingConfig {
17
- /** Ollama base URL. Default: http://localhost:11434 */
18
- ollamaUrl: string;
19
- /** Embedding model name. Default: nomic-embed-text */
20
- model: string;
21
- /** Embedding dimensions. Default: 768 */
22
- dimensions: number;
23
- /** Request timeout ms. Default: 10000 */
24
- timeout: number;
25
- /** Max texts per batch request. Default: 32 */
26
- batchSize: number;
27
- }
28
- export interface VectorSearchResult {
29
- rowid: number;
30
- distance: number;
31
- sourceTable: string;
32
- sourceId: number;
33
- content: string;
34
- domain?: string;
35
- agentId?: string;
36
- metadata?: string;
37
- }
38
- export interface VectorIndexStats {
39
- totalVectors: number;
40
- tableBreakdown: Record<string, number>;
41
- lastIndexedAt: string | null;
42
- }
43
- /**
44
- * Generate embeddings via Ollama API.
45
- * Supports single and batch embedding.
46
- */
47
- export declare function generateEmbeddings(texts: string[], config?: EmbeddingConfig): Promise<Float32Array[]>;
48
- /**
49
- * VectorStore — manages vector indexes in an agent's vector database.
50
- *
51
- * The vector DB (vectors.db) stores vec0 virtual tables and the index map.
52
- * Source content (facts, knowledge, episodes) lives in the library DB.
53
- * The VectorStore needs both: vectorDb for indexes, libraryDb for content.
54
- */
55
- export declare class VectorStore {
56
- private readonly db;
57
- private readonly libraryDb;
58
- private readonly config;
59
- constructor(db: DatabaseSync, config?: Partial<EmbeddingConfig>, libraryDb?: DatabaseSync);
60
- /**
61
- * Create vector index tables if they don't exist.
62
- * Safe to call multiple times (idempotent).
63
- */
64
- ensureTables(): void;
65
- /**
66
- * Index a single content item. Generates embedding and stores in vec table.
67
- * Skips if content hasn't changed (based on hash).
68
- */
69
- /** Allowlisted source tables for vector indexing. Prevents SQL injection via table name interpolation. */
70
- private static readonly ALLOWED_SOURCE_TABLES;
71
- private validateSourceTable;
72
- indexItem(sourceTable: string, sourceId: number, content: string, domain?: string): Promise<boolean>;
73
- /**
74
- * Batch index multiple items. More efficient than individual calls.
75
- */
76
- indexBatch(items: Array<{
77
- sourceTable: string;
78
- sourceId: number;
79
- content: string;
80
- domain?: string;
81
- }>): Promise<{
82
- indexed: number;
83
- skipped: number;
84
- }>;
85
- /**
86
- * Semantic KNN search across one or all vector tables.
87
- */
88
- search(query: string, opts?: {
89
- tables?: string[];
90
- limit?: number;
91
- maxDistance?: number;
92
- }): Promise<VectorSearchResult[]>;
93
- /**
94
- * Get content from a source table by id.
95
- */
96
- private getSourceContent;
97
- /**
98
- * Index all un-indexed content in the agent's database.
99
- * Called by the background indexer.
100
- */
101
- indexAll(agentId: string): Promise<{
102
- indexed: number;
103
- skipped: number;
104
- }>;
105
- /**
106
- * Remove vector index entries for deleted source rows.
107
- */
108
- pruneOrphans(): number;
109
- /**
110
- * Tombstone vector entries for superseded facts and knowledge.
111
- *
112
- * When fact A is superseded by fact B (facts.superseded_by = B.id), the old
113
- * vector for A should not surface in semantic recall. Without this, recalled
114
- * context can include contradicted/outdated facts alongside their replacements.
115
- *
116
- * Strategy: find all indexed facts/knowledge with superseded_by IS NOT NULL
117
- * and delete their vec_index_map entries + vec table rows. The source row
118
- * stays in library.db (audit trail) but disappears from recall.
119
- *
120
- * @returns Number of vector entries tombstoned.
121
- */
122
- tombstoneSuperseded(): number;
123
- /**
124
- * Get index statistics.
125
- */
126
- getStats(): VectorIndexStats;
127
- }
128
- /**
129
- * Create vector tables in a library database for session registry search.
130
- */
131
- export declare function ensureSessionVecTable(db: DatabaseSync, dimensions?: number): void;
132
- //# sourceMappingURL=vector-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vector-store.d.ts","sourceRoot":"","sources":["../src/vector-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAG/D,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,aA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