mindcache 3.1.0 → 3.3.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.
@@ -19,12 +19,16 @@ type AccessLevel = 'user' | 'system';
19
19
  * @deprecated 'template' - Use 'ApplyTemplate' instead
20
20
  */
21
21
  type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate' | 'prompt' | 'readonly' | 'template';
22
+ /**
23
+ * Type of value stored in a MindCache key
24
+ */
25
+ type KeyType = 'text' | 'image' | 'file' | 'json' | 'document';
22
26
  /**
23
27
  * Attributes that can be set on a MindCache key
24
28
  */
25
29
  interface KeyAttributes {
26
30
  /** The type of value stored */
27
- type: 'text' | 'image' | 'file' | 'json' | 'document';
31
+ type: KeyType;
28
32
  /** MIME type for files/images */
29
33
  contentType?: string;
30
34
  /** User-defined tags for organizing keys */
@@ -102,6 +106,8 @@ interface MindCacheCloudOptions {
102
106
  projectId?: string;
103
107
  /** API endpoint to fetch WS token (recommended for browser) */
104
108
  tokenEndpoint?: string;
109
+ /** Function to fetch token dynamically (overrides tokenEndpoint) */
110
+ tokenProvider?: () => Promise<string>;
105
111
  /** Direct API key (server-side only, never expose in browser!) */
106
112
  apiKey?: string;
107
113
  /** WebSocket base URL (defaults to production) */
@@ -214,13 +220,171 @@ declare class MindCache {
214
220
  private encodeFileToBase64;
215
221
  private createDataUrl;
216
222
  private validateContentType;
217
- private injectSTM;
218
- getAll(): STM;
223
+ private _injectSTMInternal;
224
+ /**
225
+ * Replace {{key}} placeholders in a template string with values from MindCache.
226
+ * @param template The template string with {{key}} placeholders
227
+ * @returns The template with placeholders replaced by values
228
+ */
229
+ injectSTM(template: string): string;
230
+ getAll(): Record<string, any>;
231
+ /**
232
+ * Get all entries with their full structure (value + attributes).
233
+ * Use this for UI/admin interfaces that need to display key properties.
234
+ * Unlike serialize(), this format is stable and won't change.
235
+ */
236
+ getAllEntries(): STM;
219
237
  get_value(key: string, _processingStack?: Set<string>): any;
220
238
  get_attributes(key: string): KeyAttributes | undefined;
239
+ /**
240
+ * Update only the attributes of a key without modifying the value.
241
+ * Useful for updating tags, permissions etc. on document type keys.
242
+ */
243
+ set_attributes(key: string, attributes: Partial<KeyAttributes>): void;
221
244
  set_value(key: string, value: any, attributes?: Partial<KeyAttributes>): void;
222
245
  delete_key(key: string): void;
223
246
  clear(): void;
247
+ /**
248
+ * Check if a key exists in MindCache.
249
+ */
250
+ has(key: string): boolean;
251
+ /**
252
+ * Delete a key from MindCache.
253
+ * @returns true if the key existed and was deleted
254
+ */
255
+ delete(key: string): boolean;
256
+ /** @deprecated Use get_value instead */
257
+ get(key: string): any;
258
+ /** @deprecated Use set_value instead */
259
+ set(key: string, value: any): void;
260
+ /**
261
+ * Update multiple values at once from an object.
262
+ * @deprecated Use set_value for individual keys
263
+ */
264
+ update(data: Record<string, any>): void;
265
+ /**
266
+ * Get the number of keys in MindCache.
267
+ */
268
+ size(): number;
269
+ /**
270
+ * Get all keys in MindCache (including temporal keys).
271
+ */
272
+ keys(): string[];
273
+ /**
274
+ * Get all values in MindCache (including temporal values).
275
+ */
276
+ values(): any[];
277
+ /**
278
+ * Get all key-value entries (including temporal entries).
279
+ */
280
+ entries(): Array<[string, any]>;
281
+ /**
282
+ * Unsubscribe from key changes.
283
+ * @deprecated Use the cleanup function returned by subscribe() instead
284
+ */
285
+ unsubscribe(key: string, listener: Listener): void;
286
+ /**
287
+ * Get the STM as a formatted string for LLM context.
288
+ * @deprecated Use get_system_prompt() instead
289
+ */
290
+ getSTM(): string;
291
+ /**
292
+ * Get the STM as an object with values directly (no attributes).
293
+ * Includes system keys ($date, $time).
294
+ * @deprecated Use getAll() for full STM format
295
+ */
296
+ getSTMObject(): Record<string, any>;
297
+ /**
298
+ * Add a content tag to a key.
299
+ * @returns true if the tag was added, false if key doesn't exist or tag already exists
300
+ */
301
+ addTag(key: string, tag: string): boolean;
302
+ /**
303
+ * Remove a content tag from a key.
304
+ * @returns true if the tag was removed
305
+ */
306
+ removeTag(key: string, tag: string): boolean;
307
+ /**
308
+ * Get all content tags for a key.
309
+ */
310
+ getTags(key: string): string[];
311
+ /**
312
+ * Get all unique content tags across all keys.
313
+ */
314
+ getAllTags(): string[];
315
+ /**
316
+ * Check if a key has a specific content tag.
317
+ */
318
+ hasTag(key: string, tag: string): boolean;
319
+ /**
320
+ * Get all keys with a specific content tag as formatted string.
321
+ */
322
+ getTagged(tag: string): string;
323
+ /**
324
+ * Get array of keys with a specific content tag.
325
+ */
326
+ getKeysByTag(tag: string): string[];
327
+ /**
328
+ * Add a system tag to a key (requires system access).
329
+ * System tags: 'SystemPrompt', 'LLMRead', 'LLMWrite', 'readonly', 'protected', 'ApplyTemplate'
330
+ */
331
+ systemAddTag(key: string, tag: SystemTag): boolean;
332
+ /**
333
+ * Remove a system tag from a key (requires system access).
334
+ */
335
+ systemRemoveTag(key: string, tag: SystemTag): boolean;
336
+ /**
337
+ * Get all system tags for a key (requires system access).
338
+ */
339
+ systemGetTags(key: string): SystemTag[];
340
+ /**
341
+ * Check if a key has a specific system tag (requires system access).
342
+ */
343
+ systemHasTag(key: string, tag: SystemTag): boolean;
344
+ /**
345
+ * Set all system tags for a key at once (requires system access).
346
+ */
347
+ systemSetTags(key: string, tags: SystemTag[]): boolean;
348
+ /**
349
+ * Get all keys with a specific system tag (requires system access).
350
+ */
351
+ systemGetKeysByTag(tag: SystemTag): string[];
352
+ /**
353
+ * Helper to get sorted keys (by zIndex).
354
+ */
355
+ private getSortedKeys;
356
+ /**
357
+ * Serialize to JSON string.
358
+ */
359
+ toJSON(): string;
360
+ /**
361
+ * Deserialize from JSON string.
362
+ */
363
+ fromJSON(jsonString: string): void;
364
+ /**
365
+ * Export to Markdown format.
366
+ */
367
+ toMarkdown(): string;
368
+ /**
369
+ * Import from Markdown format.
370
+ */
371
+ fromMarkdown(markdown: string): void;
372
+ /**
373
+ * Set base64 binary data.
374
+ */
375
+ set_base64(key: string, base64Data: string, contentType: string, type?: 'image' | 'file', attributes?: Partial<KeyAttributes>): void;
376
+ /**
377
+ * Add an image from base64 data.
378
+ */
379
+ add_image(key: string, base64Data: string, contentType?: string, attributes?: Partial<KeyAttributes>): void;
380
+ /**
381
+ * Get the data URL for an image or file key.
382
+ */
383
+ get_data_url(key: string): string | undefined;
384
+ /**
385
+ * Get the base64 data for an image or file key.
386
+ */
387
+ get_base64(key: string): string | undefined;
224
388
  set_file(key: string, file: File, attributes?: Partial<KeyAttributes>): Promise<void>;
225
389
  set_image(key: string, file: File, attributes?: Partial<KeyAttributes>): Promise<void>;
226
390
  /**
@@ -363,4 +527,4 @@ declare class CloudAdapter {
363
527
  private scheduleReconnect;
364
528
  }
365
529
 
366
- 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 };
530
+ export { type AccessLevel as A, CloudAdapter as C, DEFAULT_KEY_ATTRIBUTES as D, type GlobalListener as G, type HistoryEntry as H, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SystemTag as S, type MindCacheOptions as a, type KeyType as b, type STM as c, type STMEntry as d, type HistoryOptions as e, type MindCacheCloudOptions as f, type MindCacheIndexedDBOptions as g, type CloudConfig as h, type ConnectionState as i, type CloudAdapterEvents as j, type SetOperation as k, type DeleteOperation as l, type ClearOperation as m };
@@ -19,12 +19,16 @@ type AccessLevel = 'user' | 'system';
19
19
  * @deprecated 'template' - Use 'ApplyTemplate' instead
20
20
  */
21
21
  type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate' | 'prompt' | 'readonly' | 'template';
22
+ /**
23
+ * Type of value stored in a MindCache key
24
+ */
25
+ type KeyType = 'text' | 'image' | 'file' | 'json' | 'document';
22
26
  /**
23
27
  * Attributes that can be set on a MindCache key
24
28
  */
25
29
  interface KeyAttributes {
26
30
  /** The type of value stored */
27
- type: 'text' | 'image' | 'file' | 'json' | 'document';
31
+ type: KeyType;
28
32
  /** MIME type for files/images */
29
33
  contentType?: string;
30
34
  /** User-defined tags for organizing keys */
@@ -102,6 +106,8 @@ interface MindCacheCloudOptions {
102
106
  projectId?: string;
103
107
  /** API endpoint to fetch WS token (recommended for browser) */
104
108
  tokenEndpoint?: string;
109
+ /** Function to fetch token dynamically (overrides tokenEndpoint) */
110
+ tokenProvider?: () => Promise<string>;
105
111
  /** Direct API key (server-side only, never expose in browser!) */
106
112
  apiKey?: string;
107
113
  /** WebSocket base URL (defaults to production) */
@@ -214,13 +220,171 @@ declare class MindCache {
214
220
  private encodeFileToBase64;
215
221
  private createDataUrl;
216
222
  private validateContentType;
217
- private injectSTM;
218
- getAll(): STM;
223
+ private _injectSTMInternal;
224
+ /**
225
+ * Replace {{key}} placeholders in a template string with values from MindCache.
226
+ * @param template The template string with {{key}} placeholders
227
+ * @returns The template with placeholders replaced by values
228
+ */
229
+ injectSTM(template: string): string;
230
+ getAll(): Record<string, any>;
231
+ /**
232
+ * Get all entries with their full structure (value + attributes).
233
+ * Use this for UI/admin interfaces that need to display key properties.
234
+ * Unlike serialize(), this format is stable and won't change.
235
+ */
236
+ getAllEntries(): STM;
219
237
  get_value(key: string, _processingStack?: Set<string>): any;
220
238
  get_attributes(key: string): KeyAttributes | undefined;
239
+ /**
240
+ * Update only the attributes of a key without modifying the value.
241
+ * Useful for updating tags, permissions etc. on document type keys.
242
+ */
243
+ set_attributes(key: string, attributes: Partial<KeyAttributes>): void;
221
244
  set_value(key: string, value: any, attributes?: Partial<KeyAttributes>): void;
222
245
  delete_key(key: string): void;
223
246
  clear(): void;
247
+ /**
248
+ * Check if a key exists in MindCache.
249
+ */
250
+ has(key: string): boolean;
251
+ /**
252
+ * Delete a key from MindCache.
253
+ * @returns true if the key existed and was deleted
254
+ */
255
+ delete(key: string): boolean;
256
+ /** @deprecated Use get_value instead */
257
+ get(key: string): any;
258
+ /** @deprecated Use set_value instead */
259
+ set(key: string, value: any): void;
260
+ /**
261
+ * Update multiple values at once from an object.
262
+ * @deprecated Use set_value for individual keys
263
+ */
264
+ update(data: Record<string, any>): void;
265
+ /**
266
+ * Get the number of keys in MindCache.
267
+ */
268
+ size(): number;
269
+ /**
270
+ * Get all keys in MindCache (including temporal keys).
271
+ */
272
+ keys(): string[];
273
+ /**
274
+ * Get all values in MindCache (including temporal values).
275
+ */
276
+ values(): any[];
277
+ /**
278
+ * Get all key-value entries (including temporal entries).
279
+ */
280
+ entries(): Array<[string, any]>;
281
+ /**
282
+ * Unsubscribe from key changes.
283
+ * @deprecated Use the cleanup function returned by subscribe() instead
284
+ */
285
+ unsubscribe(key: string, listener: Listener): void;
286
+ /**
287
+ * Get the STM as a formatted string for LLM context.
288
+ * @deprecated Use get_system_prompt() instead
289
+ */
290
+ getSTM(): string;
291
+ /**
292
+ * Get the STM as an object with values directly (no attributes).
293
+ * Includes system keys ($date, $time).
294
+ * @deprecated Use getAll() for full STM format
295
+ */
296
+ getSTMObject(): Record<string, any>;
297
+ /**
298
+ * Add a content tag to a key.
299
+ * @returns true if the tag was added, false if key doesn't exist or tag already exists
300
+ */
301
+ addTag(key: string, tag: string): boolean;
302
+ /**
303
+ * Remove a content tag from a key.
304
+ * @returns true if the tag was removed
305
+ */
306
+ removeTag(key: string, tag: string): boolean;
307
+ /**
308
+ * Get all content tags for a key.
309
+ */
310
+ getTags(key: string): string[];
311
+ /**
312
+ * Get all unique content tags across all keys.
313
+ */
314
+ getAllTags(): string[];
315
+ /**
316
+ * Check if a key has a specific content tag.
317
+ */
318
+ hasTag(key: string, tag: string): boolean;
319
+ /**
320
+ * Get all keys with a specific content tag as formatted string.
321
+ */
322
+ getTagged(tag: string): string;
323
+ /**
324
+ * Get array of keys with a specific content tag.
325
+ */
326
+ getKeysByTag(tag: string): string[];
327
+ /**
328
+ * Add a system tag to a key (requires system access).
329
+ * System tags: 'SystemPrompt', 'LLMRead', 'LLMWrite', 'readonly', 'protected', 'ApplyTemplate'
330
+ */
331
+ systemAddTag(key: string, tag: SystemTag): boolean;
332
+ /**
333
+ * Remove a system tag from a key (requires system access).
334
+ */
335
+ systemRemoveTag(key: string, tag: SystemTag): boolean;
336
+ /**
337
+ * Get all system tags for a key (requires system access).
338
+ */
339
+ systemGetTags(key: string): SystemTag[];
340
+ /**
341
+ * Check if a key has a specific system tag (requires system access).
342
+ */
343
+ systemHasTag(key: string, tag: SystemTag): boolean;
344
+ /**
345
+ * Set all system tags for a key at once (requires system access).
346
+ */
347
+ systemSetTags(key: string, tags: SystemTag[]): boolean;
348
+ /**
349
+ * Get all keys with a specific system tag (requires system access).
350
+ */
351
+ systemGetKeysByTag(tag: SystemTag): string[];
352
+ /**
353
+ * Helper to get sorted keys (by zIndex).
354
+ */
355
+ private getSortedKeys;
356
+ /**
357
+ * Serialize to JSON string.
358
+ */
359
+ toJSON(): string;
360
+ /**
361
+ * Deserialize from JSON string.
362
+ */
363
+ fromJSON(jsonString: string): void;
364
+ /**
365
+ * Export to Markdown format.
366
+ */
367
+ toMarkdown(): string;
368
+ /**
369
+ * Import from Markdown format.
370
+ */
371
+ fromMarkdown(markdown: string): void;
372
+ /**
373
+ * Set base64 binary data.
374
+ */
375
+ set_base64(key: string, base64Data: string, contentType: string, type?: 'image' | 'file', attributes?: Partial<KeyAttributes>): void;
376
+ /**
377
+ * Add an image from base64 data.
378
+ */
379
+ add_image(key: string, base64Data: string, contentType?: string, attributes?: Partial<KeyAttributes>): void;
380
+ /**
381
+ * Get the data URL for an image or file key.
382
+ */
383
+ get_data_url(key: string): string | undefined;
384
+ /**
385
+ * Get the base64 data for an image or file key.
386
+ */
387
+ get_base64(key: string): string | undefined;
224
388
  set_file(key: string, file: File, attributes?: Partial<KeyAttributes>): Promise<void>;
225
389
  set_image(key: string, file: File, attributes?: Partial<KeyAttributes>): Promise<void>;
226
390
  /**
@@ -363,4 +527,4 @@ declare class CloudAdapter {
363
527
  private scheduleReconnect;
364
528
  }
365
529
 
366
- 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 };
530
+ export { type AccessLevel as A, CloudAdapter as C, DEFAULT_KEY_ATTRIBUTES as D, type GlobalListener as G, type HistoryEntry as H, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SystemTag as S, type MindCacheOptions as a, type KeyType as b, type STM as c, type STMEntry as d, type HistoryOptions as e, type MindCacheCloudOptions as f, type MindCacheIndexedDBOptions as g, type CloudConfig as h, type ConnectionState as i, type CloudAdapterEvents as j, type SetOperation as k, type DeleteOperation as l, type ClearOperation as m };
@@ -1,5 +1,5 @@
1
- import { M as MindCache, e as CloudConfig, C as CloudAdapter } from '../CloudAdapter-Bx-ITNdi.mjs';
2
- export { j as ClearOperation, g as CloudAdapterEvents, f as ConnectionState, i as DeleteOperation, O as Operation, h as SetOperation } from '../CloudAdapter-Bx-ITNdi.mjs';
1
+ import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CSncOr3V.mjs';
2
+ export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CSncOr3V.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { M as MindCache, e as CloudConfig, C as CloudAdapter } from '../CloudAdapter-Bx-ITNdi.js';
2
- export { j as ClearOperation, g as CloudAdapterEvents, f as ConnectionState, i as DeleteOperation, O as Operation, h as SetOperation } from '../CloudAdapter-Bx-ITNdi.js';
1
+ import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CSncOr3V.js';
2
+ export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CSncOr3V.js';
3
3
  import 'yjs';
4
4
 
5
5
  /**