mindcache 2.2.0 → 2.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.
@@ -6,12 +6,17 @@
6
6
  type AccessLevel = 'user' | 'system';
7
7
  /**
8
8
  * Known system tags that control key behavior
9
- * - 'prompt': Include in system prompt (replaces visible)
10
- * - 'readonly': Cannot be modified by AI tools (replaces readonly)
9
+ * - 'SystemPrompt': Include in system prompt
10
+ * - 'LLMRead': LLM can read this key (visible to LLMs)
11
+ * - 'LLMWrite': LLM can write to this key via tools
11
12
  * - 'protected': Cannot be deleted (replaces hardcoded)
12
- * - 'template': Process value through template injection
13
+ * - 'ApplyTemplate': Process value through template injection
14
+ *
15
+ * @deprecated 'prompt' - Use 'SystemPrompt' instead
16
+ * @deprecated 'readonly' - Use absence of 'LLMWrite' instead (if LLMWrite not present, readonly=true)
17
+ * @deprecated 'template' - Use 'ApplyTemplate' instead
13
18
  */
14
- type SystemTag = 'prompt' | 'readonly' | 'protected' | 'template';
19
+ type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate' | 'prompt' | 'readonly' | 'template';
15
20
  /**
16
21
  * Attributes that can be set on a MindCache key
17
22
  */
@@ -26,13 +31,13 @@ interface KeyAttributes {
26
31
  systemTags: SystemTag[];
27
32
  /** Z-index for ordering keys (lower values appear first) */
28
33
  zIndex: number;
29
- /** @deprecated Use systemTags.includes('readonly') instead */
34
+ /** @deprecated Use !systemTags.includes('LLMWrite') instead */
30
35
  readonly: boolean;
31
- /** @deprecated Use systemTags.includes('prompt') instead */
36
+ /** @deprecated Use systemTags.includes('SystemPrompt') instead */
32
37
  visible: boolean;
33
38
  /** @deprecated Use systemTags.includes('protected') instead */
34
39
  hardcoded: boolean;
35
- /** @deprecated Use systemTags.includes('template') instead */
40
+ /** @deprecated Use systemTags.includes('ApplyTemplate') instead */
36
41
  template: boolean;
37
42
  /** @deprecated Use contentTags instead */
38
43
  tags?: string[];
@@ -80,12 +85,24 @@ interface MindCacheCloudOptions {
80
85
  /** WebSocket base URL (defaults to production) */
81
86
  baseUrl?: string;
82
87
  }
88
+ interface MindCacheIndexedDBOptions {
89
+ /** Database name (defaults to 'mindcache_db') */
90
+ dbName?: string;
91
+ /** Store name (defaults to 'mindcache_store') */
92
+ storeName?: string;
93
+ /** Storage key (defaults to 'mindcache_data') */
94
+ key?: string;
95
+ /** Debounce time in ms for saving (defaults to 1000) */
96
+ debounceMs?: number;
97
+ }
83
98
  /**
84
99
  * Constructor options for MindCache
85
100
  */
86
101
  interface MindCacheOptions {
87
102
  /** Cloud sync configuration. If omitted, runs in local-only mode. */
88
103
  cloud?: MindCacheCloudOptions;
104
+ /** IndexedDB configuration */
105
+ indexedDB?: MindCacheIndexedDBOptions;
89
106
  /** Access level for tag operations. 'system' allows managing system tags. */
90
107
  accessLevel?: AccessLevel;
91
108
  }
@@ -95,11 +112,30 @@ declare class MindCache {
95
112
  private listeners;
96
113
  private globalListeners;
97
114
  private _isRemoteUpdate;
115
+ /**
116
+ * Normalize system tags: migrate old tags to new ones
117
+ * - 'prompt' → 'SystemPrompt'
118
+ * - 'readonly' → remove 'LLMWrite' (or add if not readonly)
119
+ */
120
+ private normalizeSystemTags;
121
+ /**
122
+ * Check if key should be visible in system prompt
123
+ */
124
+ private hasSystemPrompt;
125
+ /**
126
+ * Check if key can be read by LLM (has LLMRead or SystemPrompt)
127
+ */
128
+ private hasLLMRead;
129
+ /**
130
+ * Check if key can be written by LLM (has LLMWrite and not readonly)
131
+ */
132
+ private hasLLMWrite;
98
133
  private _cloudAdapter;
99
134
  private _connectionState;
100
135
  private _isLoaded;
101
136
  private _cloudConfig;
102
137
  private _accessLevel;
138
+ private _initPromise;
103
139
  constructor(options?: MindCacheOptions);
104
140
  /**
105
141
  * Get the current access level
@@ -110,6 +146,8 @@ declare class MindCache {
110
146
  */
111
147
  get hasSystemAccess(): boolean;
112
148
  private _initCloud;
149
+ private _initIndexedDB;
150
+ protected _getIndexedDBAdapterClass(): Promise<any>;
113
151
  /**
114
152
  * Get the current cloud connection state
115
153
  */
@@ -118,10 +156,20 @@ declare class MindCache {
118
156
  * Check if data is loaded (true for local, true after sync for cloud)
119
157
  */
120
158
  get isLoaded(): boolean;
159
+ /**
160
+ * Protected method to load CloudAdapter class.
161
+ * Can be overridden/mocked for testing.
162
+ */
163
+ protected _getCloudAdapterClass(): Promise<any>;
121
164
  /**
122
165
  * Check if this instance is connected to cloud
123
166
  */
124
167
  get isCloud(): boolean;
168
+ /**
169
+ * Wait for initial sync to complete (or resolve immediately if already synced/local).
170
+ * Useful for scripts or linear execution flows.
171
+ */
172
+ waitForSync(): Promise<void>;
125
173
  /**
126
174
  * Disconnect from cloud (if connected)
127
175
  */
@@ -302,9 +350,15 @@ interface CloudAdapterEvents {
302
350
  * CloudAdapter connects a MindCache instance to the cloud service
303
351
  * for real-time sync and persistence.
304
352
  *
305
- * Auth modes:
306
- * 1. Token (recommended): Pass a short-lived token from /api/ws-token
307
- * 2. API Key (server-to-server): Pass apiKey for direct connections
353
+ * Auth flow:
354
+ * 1. SDK calls POST /api/ws-token with apiKey to get short-lived token
355
+ * 2. SDK connects to WebSocket with token in query string
356
+ * 3. Server validates token and upgrades to WebSocket
357
+ *
358
+ * Usage patterns:
359
+ * - apiKey: SDK fetches tokens automatically (simple, good for demos)
360
+ * - tokenEndpoint: Your backend fetches tokens (secure, apiKey stays server-side)
361
+ * - tokenProvider: Custom token logic (advanced)
308
362
  */
309
363
  declare class CloudAdapter {
310
364
  private config;
@@ -340,6 +394,16 @@ declare class CloudAdapter {
340
394
  * Detach from the MindCache instance
341
395
  */
342
396
  detach(): void;
397
+ /**
398
+ * Fetch a short-lived WebSocket token from the API using the API key.
399
+ * This keeps the API key secure by only using it for a single HTTPS request,
400
+ * then using the short-lived token for the WebSocket connection.
401
+ *
402
+ * Supports two key formats:
403
+ * - API keys: mc_live_xxx or mc_test_xxx → Bearer token
404
+ * - Delegate keys: del_xxx:sec_xxx → ApiKey format
405
+ */
406
+ private fetchTokenWithApiKey;
343
407
  /**
344
408
  * Connect to the cloud service
345
409
  */
@@ -368,4 +432,4 @@ declare class CloudAdapter {
368
432
  private syncLocalChanges;
369
433
  }
370
434
 
371
- export { type CloudConfig as C, type DeleteOperation as D, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type STM as e, type STMEntry as f, type MindCacheOptions as g, type MindCacheCloudOptions as h, DEFAULT_KEY_ATTRIBUTES as i, mindcache as m };
435
+ export { CloudAdapter as C, DEFAULT_KEY_ATTRIBUTES as D, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type STM as S, type MindCacheOptions as a, type STMEntry as b, type MindCacheCloudOptions as c, type MindCacheIndexedDBOptions as d, type CloudConfig as e, type ConnectionState as f, type CloudAdapterEvents as g, type SetOperation as h, type DeleteOperation as i, type ClearOperation as j, mindcache as m };
@@ -6,12 +6,17 @@
6
6
  type AccessLevel = 'user' | 'system';
7
7
  /**
8
8
  * Known system tags that control key behavior
9
- * - 'prompt': Include in system prompt (replaces visible)
10
- * - 'readonly': Cannot be modified by AI tools (replaces readonly)
9
+ * - 'SystemPrompt': Include in system prompt
10
+ * - 'LLMRead': LLM can read this key (visible to LLMs)
11
+ * - 'LLMWrite': LLM can write to this key via tools
11
12
  * - 'protected': Cannot be deleted (replaces hardcoded)
12
- * - 'template': Process value through template injection
13
+ * - 'ApplyTemplate': Process value through template injection
14
+ *
15
+ * @deprecated 'prompt' - Use 'SystemPrompt' instead
16
+ * @deprecated 'readonly' - Use absence of 'LLMWrite' instead (if LLMWrite not present, readonly=true)
17
+ * @deprecated 'template' - Use 'ApplyTemplate' instead
13
18
  */
14
- type SystemTag = 'prompt' | 'readonly' | 'protected' | 'template';
19
+ type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate' | 'prompt' | 'readonly' | 'template';
15
20
  /**
16
21
  * Attributes that can be set on a MindCache key
17
22
  */
@@ -26,13 +31,13 @@ interface KeyAttributes {
26
31
  systemTags: SystemTag[];
27
32
  /** Z-index for ordering keys (lower values appear first) */
28
33
  zIndex: number;
29
- /** @deprecated Use systemTags.includes('readonly') instead */
34
+ /** @deprecated Use !systemTags.includes('LLMWrite') instead */
30
35
  readonly: boolean;
31
- /** @deprecated Use systemTags.includes('prompt') instead */
36
+ /** @deprecated Use systemTags.includes('SystemPrompt') instead */
32
37
  visible: boolean;
33
38
  /** @deprecated Use systemTags.includes('protected') instead */
34
39
  hardcoded: boolean;
35
- /** @deprecated Use systemTags.includes('template') instead */
40
+ /** @deprecated Use systemTags.includes('ApplyTemplate') instead */
36
41
  template: boolean;
37
42
  /** @deprecated Use contentTags instead */
38
43
  tags?: string[];
@@ -80,12 +85,24 @@ interface MindCacheCloudOptions {
80
85
  /** WebSocket base URL (defaults to production) */
81
86
  baseUrl?: string;
82
87
  }
88
+ interface MindCacheIndexedDBOptions {
89
+ /** Database name (defaults to 'mindcache_db') */
90
+ dbName?: string;
91
+ /** Store name (defaults to 'mindcache_store') */
92
+ storeName?: string;
93
+ /** Storage key (defaults to 'mindcache_data') */
94
+ key?: string;
95
+ /** Debounce time in ms for saving (defaults to 1000) */
96
+ debounceMs?: number;
97
+ }
83
98
  /**
84
99
  * Constructor options for MindCache
85
100
  */
86
101
  interface MindCacheOptions {
87
102
  /** Cloud sync configuration. If omitted, runs in local-only mode. */
88
103
  cloud?: MindCacheCloudOptions;
104
+ /** IndexedDB configuration */
105
+ indexedDB?: MindCacheIndexedDBOptions;
89
106
  /** Access level for tag operations. 'system' allows managing system tags. */
90
107
  accessLevel?: AccessLevel;
91
108
  }
@@ -95,11 +112,30 @@ declare class MindCache {
95
112
  private listeners;
96
113
  private globalListeners;
97
114
  private _isRemoteUpdate;
115
+ /**
116
+ * Normalize system tags: migrate old tags to new ones
117
+ * - 'prompt' → 'SystemPrompt'
118
+ * - 'readonly' → remove 'LLMWrite' (or add if not readonly)
119
+ */
120
+ private normalizeSystemTags;
121
+ /**
122
+ * Check if key should be visible in system prompt
123
+ */
124
+ private hasSystemPrompt;
125
+ /**
126
+ * Check if key can be read by LLM (has LLMRead or SystemPrompt)
127
+ */
128
+ private hasLLMRead;
129
+ /**
130
+ * Check if key can be written by LLM (has LLMWrite and not readonly)
131
+ */
132
+ private hasLLMWrite;
98
133
  private _cloudAdapter;
99
134
  private _connectionState;
100
135
  private _isLoaded;
101
136
  private _cloudConfig;
102
137
  private _accessLevel;
138
+ private _initPromise;
103
139
  constructor(options?: MindCacheOptions);
104
140
  /**
105
141
  * Get the current access level
@@ -110,6 +146,8 @@ declare class MindCache {
110
146
  */
111
147
  get hasSystemAccess(): boolean;
112
148
  private _initCloud;
149
+ private _initIndexedDB;
150
+ protected _getIndexedDBAdapterClass(): Promise<any>;
113
151
  /**
114
152
  * Get the current cloud connection state
115
153
  */
@@ -118,10 +156,20 @@ declare class MindCache {
118
156
  * Check if data is loaded (true for local, true after sync for cloud)
119
157
  */
120
158
  get isLoaded(): boolean;
159
+ /**
160
+ * Protected method to load CloudAdapter class.
161
+ * Can be overridden/mocked for testing.
162
+ */
163
+ protected _getCloudAdapterClass(): Promise<any>;
121
164
  /**
122
165
  * Check if this instance is connected to cloud
123
166
  */
124
167
  get isCloud(): boolean;
168
+ /**
169
+ * Wait for initial sync to complete (or resolve immediately if already synced/local).
170
+ * Useful for scripts or linear execution flows.
171
+ */
172
+ waitForSync(): Promise<void>;
125
173
  /**
126
174
  * Disconnect from cloud (if connected)
127
175
  */
@@ -302,9 +350,15 @@ interface CloudAdapterEvents {
302
350
  * CloudAdapter connects a MindCache instance to the cloud service
303
351
  * for real-time sync and persistence.
304
352
  *
305
- * Auth modes:
306
- * 1. Token (recommended): Pass a short-lived token from /api/ws-token
307
- * 2. API Key (server-to-server): Pass apiKey for direct connections
353
+ * Auth flow:
354
+ * 1. SDK calls POST /api/ws-token with apiKey to get short-lived token
355
+ * 2. SDK connects to WebSocket with token in query string
356
+ * 3. Server validates token and upgrades to WebSocket
357
+ *
358
+ * Usage patterns:
359
+ * - apiKey: SDK fetches tokens automatically (simple, good for demos)
360
+ * - tokenEndpoint: Your backend fetches tokens (secure, apiKey stays server-side)
361
+ * - tokenProvider: Custom token logic (advanced)
308
362
  */
309
363
  declare class CloudAdapter {
310
364
  private config;
@@ -340,6 +394,16 @@ declare class CloudAdapter {
340
394
  * Detach from the MindCache instance
341
395
  */
342
396
  detach(): void;
397
+ /**
398
+ * Fetch a short-lived WebSocket token from the API using the API key.
399
+ * This keeps the API key secure by only using it for a single HTTPS request,
400
+ * then using the short-lived token for the WebSocket connection.
401
+ *
402
+ * Supports two key formats:
403
+ * - API keys: mc_live_xxx or mc_test_xxx → Bearer token
404
+ * - Delegate keys: del_xxx:sec_xxx → ApiKey format
405
+ */
406
+ private fetchTokenWithApiKey;
343
407
  /**
344
408
  * Connect to the cloud service
345
409
  */
@@ -368,4 +432,4 @@ declare class CloudAdapter {
368
432
  private syncLocalChanges;
369
433
  }
370
434
 
371
- export { type CloudConfig as C, type DeleteOperation as D, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type STM as e, type STMEntry as f, type MindCacheOptions as g, type MindCacheCloudOptions as h, DEFAULT_KEY_ATTRIBUTES as i, mindcache as m };
435
+ export { CloudAdapter as C, DEFAULT_KEY_ATTRIBUTES as D, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type STM as S, type MindCacheOptions as a, type STMEntry as b, type MindCacheCloudOptions as c, type MindCacheIndexedDBOptions as d, type CloudConfig as e, type ConnectionState as f, type CloudAdapterEvents as g, type SetOperation as h, type DeleteOperation as i, type ClearOperation as j, mindcache as m };
@@ -1,5 +1,5 @@
1
- import { M as MindCache, C as CloudConfig, a as CloudAdapter } from '../index-XM7bmK7C.mjs';
2
- export { d as ClearOperation, c as CloudAdapterEvents, b as ConnectionState, D as DeleteOperation, O as Operation, S as SetOperation } from '../index-XM7bmK7C.mjs';
1
+ import { M as MindCache, e as CloudConfig, C as CloudAdapter } from '../CloudAdapter-B04-OWx3.mjs';
2
+ export { j as ClearOperation, g as CloudAdapterEvents, f as ConnectionState, i as DeleteOperation, O as Operation, h as SetOperation } from '../CloudAdapter-B04-OWx3.mjs';
3
3
 
4
4
  /**
5
5
  * Connect a MindCache instance to the cloud for real-time sync.
@@ -1,5 +1,5 @@
1
- import { M as MindCache, C as CloudConfig, a as CloudAdapter } from '../index-XM7bmK7C.js';
2
- export { d as ClearOperation, c as CloudAdapterEvents, b as ConnectionState, D as DeleteOperation, O as Operation, S as SetOperation } from '../index-XM7bmK7C.js';
1
+ import { M as MindCache, e as CloudConfig, C as CloudAdapter } from '../CloudAdapter-B04-OWx3.js';
2
+ export { j as ClearOperation, g as CloudAdapterEvents, f as ConnectionState, i as DeleteOperation, O as Operation, h as SetOperation } from '../CloudAdapter-B04-OWx3.js';
3
3
 
4
4
  /**
5
5
  * Connect a MindCache instance to the cloud for real-time sync.