mindcache 3.4.1 → 3.4.3

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.
@@ -8,17 +8,13 @@ import * as Y from 'yjs';
8
8
  type AccessLevel = 'user' | 'system';
9
9
  /**
10
10
  * Known system tags that control key behavior
11
- * - 'SystemPrompt': Include in system prompt
12
- * - 'LLMRead': LLM can read this key (visible to LLMs)
11
+ * - 'SystemPrompt': Include in system prompt (visible to LLM context)
12
+ * - 'LLMRead': LLM can read this key via tools
13
13
  * - 'LLMWrite': LLM can write to this key via tools
14
- * - 'protected': Cannot be deleted (replaces hardcoded)
14
+ * - 'protected': Cannot be deleted
15
15
  * - 'ApplyTemplate': Process value through template injection
16
- *
17
- * @deprecated 'prompt' - Use 'SystemPrompt' instead
18
- * @deprecated 'readonly' - Use absence of 'LLMWrite' instead (if LLMWrite not present, readonly=true)
19
- * @deprecated 'template' - Use 'ApplyTemplate' instead
20
16
  */
21
- type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate' | 'prompt' | 'readonly' | 'template';
17
+ type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate';
22
18
  /**
23
19
  * Type of value stored in a MindCache key
24
20
  */
@@ -37,17 +33,11 @@ interface KeyAttributes {
37
33
  systemTags: SystemTag[];
38
34
  /** Z-index for ordering keys (lower values appear first) */
39
35
  zIndex: number;
40
- /** @deprecated Use !systemTags.includes('LLMWrite') instead */
41
- readonly: boolean;
42
- /** @deprecated Use systemTags.includes('SystemPrompt') instead */
43
- visible: boolean;
44
- /** @deprecated Use systemTags.includes('protected') instead */
45
- hardcoded: boolean;
46
- /** @deprecated Use systemTags.includes('ApplyTemplate') instead */
47
- template: boolean;
48
- /** @deprecated Use contentTags instead */
49
- tags?: string[];
50
36
  }
37
+ /**
38
+ * Default attributes for new keys
39
+ */
40
+ declare const DEFAULT_KEY_ATTRIBUTES: KeyAttributes;
51
41
  /**
52
42
  * A single entry in the MindCache store
53
43
  */
@@ -71,10 +61,6 @@ type Listener = (value: unknown) => void;
71
61
  * Called when any key changes (no parameters - use getAll() to get current state)
72
62
  */
73
63
  type GlobalListener = () => void;
74
- /**
75
- * Default attributes for new keys
76
- */
77
- declare const DEFAULT_KEY_ATTRIBUTES: KeyAttributes;
78
64
  /**
79
65
  * A single entry in the global history log
80
66
  */
@@ -95,6 +81,21 @@ interface HistoryOptions {
95
81
  /** Save full snapshot every N entries for fast restore (default: 10) */
96
82
  snapshotInterval?: number;
97
83
  }
84
+ /**
85
+ * Helper functions for working with system tags
86
+ */
87
+ declare const SystemTagHelpers: {
88
+ /** Check if key is writable by LLM */
89
+ isLLMWritable: (attrs: KeyAttributes) => boolean;
90
+ /** Check if key is readable by LLM (in context or via tools) */
91
+ isLLMReadable: (attrs: KeyAttributes) => boolean;
92
+ /** Check if key is included in system prompt */
93
+ isInSystemPrompt: (attrs: KeyAttributes) => boolean;
94
+ /** Check if key is protected from deletion */
95
+ isProtected: (attrs: KeyAttributes) => boolean;
96
+ /** Check if key uses template injection */
97
+ hasTemplateInjection: (attrs: KeyAttributes) => boolean;
98
+ };
98
99
 
99
100
  /**
100
101
  * Cloud configuration options for MindCache constructor
@@ -135,6 +136,8 @@ interface MindCacheOptions {
135
136
  history?: HistoryOptions;
136
137
  /** Access level for tag operations. 'system' allows managing system tags. */
137
138
  accessLevel?: AccessLevel;
139
+ /** Optional existing Y.Doc instance (for server-side hydration) */
140
+ doc?: Y.Doc;
138
141
  }
139
142
  type ConnectionState$1 = 'disconnected' | 'connecting' | 'connected' | 'error';
140
143
  declare class MindCache {
@@ -245,6 +248,16 @@ declare class MindCache {
245
248
  */
246
249
  set_attributes(key: string, attributes: Partial<KeyAttributes>): void;
247
250
  set_value(key: string, value: any, attributes?: Partial<KeyAttributes>): void;
251
+ /**
252
+ * LLM-safe method to write a value to a key.
253
+ * This method:
254
+ * - Only updates the value, never modifies attributes/systemTags
255
+ * - Checks LLMWrite permission before writing
256
+ * - Returns false if key doesn't exist or lacks LLMWrite permission
257
+ *
258
+ * Used by create_vercel_ai_tools() to prevent LLMs from escalating privileges.
259
+ */
260
+ llm_set_key(key: string, value: any): boolean;
248
261
  delete_key(key: string): void;
249
262
  clear(): void;
250
263
  /**
@@ -427,6 +440,14 @@ declare class MindCache {
427
440
  /**
428
441
  * Generate Vercel AI SDK compatible tools for writable keys.
429
442
  * For document type keys, generates additional tools: append_, insert_, edit_
443
+ *
444
+ * Security: All tools use llm_set_key internally which:
445
+ * - Only modifies VALUES, never attributes/systemTags
446
+ * - Prevents LLMs from escalating privileges
447
+ */
448
+ create_vercel_ai_tools(): Record<string, any>;
449
+ /**
450
+ * @deprecated Use create_vercel_ai_tools() instead
430
451
  */
431
452
  get_aisdk_tools(): Record<string, any>;
432
453
  /**
@@ -509,6 +530,7 @@ declare class CloudAdapter {
509
530
  private token;
510
531
  private handleOnline;
511
532
  private handleOffline;
533
+ private _synced;
512
534
  constructor(config: CloudConfig);
513
535
  /** Browser network status - instantly updated via navigator.onLine */
514
536
  get isOnline(): boolean;
@@ -530,4 +552,4 @@ declare class CloudAdapter {
530
552
  private scheduleReconnect;
531
553
  }
532
554
 
533
- 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 };
555
+ export { type AccessLevel as A, type CloudConfig as C, type DeleteOperation 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 SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type MindCacheOptions as e, type KeyType as f, type SystemTag as g, type STM as h, type STMEntry as i, type HistoryOptions as j, type MindCacheCloudOptions as k, type MindCacheIndexedDBOptions as l, DEFAULT_KEY_ATTRIBUTES as m, SystemTagHelpers as n };
@@ -8,17 +8,13 @@ import * as Y from 'yjs';
8
8
  type AccessLevel = 'user' | 'system';
9
9
  /**
10
10
  * Known system tags that control key behavior
11
- * - 'SystemPrompt': Include in system prompt
12
- * - 'LLMRead': LLM can read this key (visible to LLMs)
11
+ * - 'SystemPrompt': Include in system prompt (visible to LLM context)
12
+ * - 'LLMRead': LLM can read this key via tools
13
13
  * - 'LLMWrite': LLM can write to this key via tools
14
- * - 'protected': Cannot be deleted (replaces hardcoded)
14
+ * - 'protected': Cannot be deleted
15
15
  * - 'ApplyTemplate': Process value through template injection
16
- *
17
- * @deprecated 'prompt' - Use 'SystemPrompt' instead
18
- * @deprecated 'readonly' - Use absence of 'LLMWrite' instead (if LLMWrite not present, readonly=true)
19
- * @deprecated 'template' - Use 'ApplyTemplate' instead
20
16
  */
21
- type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate' | 'prompt' | 'readonly' | 'template';
17
+ type SystemTag = 'SystemPrompt' | 'LLMRead' | 'LLMWrite' | 'protected' | 'ApplyTemplate';
22
18
  /**
23
19
  * Type of value stored in a MindCache key
24
20
  */
@@ -37,17 +33,11 @@ interface KeyAttributes {
37
33
  systemTags: SystemTag[];
38
34
  /** Z-index for ordering keys (lower values appear first) */
39
35
  zIndex: number;
40
- /** @deprecated Use !systemTags.includes('LLMWrite') instead */
41
- readonly: boolean;
42
- /** @deprecated Use systemTags.includes('SystemPrompt') instead */
43
- visible: boolean;
44
- /** @deprecated Use systemTags.includes('protected') instead */
45
- hardcoded: boolean;
46
- /** @deprecated Use systemTags.includes('ApplyTemplate') instead */
47
- template: boolean;
48
- /** @deprecated Use contentTags instead */
49
- tags?: string[];
50
36
  }
37
+ /**
38
+ * Default attributes for new keys
39
+ */
40
+ declare const DEFAULT_KEY_ATTRIBUTES: KeyAttributes;
51
41
  /**
52
42
  * A single entry in the MindCache store
53
43
  */
@@ -71,10 +61,6 @@ type Listener = (value: unknown) => void;
71
61
  * Called when any key changes (no parameters - use getAll() to get current state)
72
62
  */
73
63
  type GlobalListener = () => void;
74
- /**
75
- * Default attributes for new keys
76
- */
77
- declare const DEFAULT_KEY_ATTRIBUTES: KeyAttributes;
78
64
  /**
79
65
  * A single entry in the global history log
80
66
  */
@@ -95,6 +81,21 @@ interface HistoryOptions {
95
81
  /** Save full snapshot every N entries for fast restore (default: 10) */
96
82
  snapshotInterval?: number;
97
83
  }
84
+ /**
85
+ * Helper functions for working with system tags
86
+ */
87
+ declare const SystemTagHelpers: {
88
+ /** Check if key is writable by LLM */
89
+ isLLMWritable: (attrs: KeyAttributes) => boolean;
90
+ /** Check if key is readable by LLM (in context or via tools) */
91
+ isLLMReadable: (attrs: KeyAttributes) => boolean;
92
+ /** Check if key is included in system prompt */
93
+ isInSystemPrompt: (attrs: KeyAttributes) => boolean;
94
+ /** Check if key is protected from deletion */
95
+ isProtected: (attrs: KeyAttributes) => boolean;
96
+ /** Check if key uses template injection */
97
+ hasTemplateInjection: (attrs: KeyAttributes) => boolean;
98
+ };
98
99
 
99
100
  /**
100
101
  * Cloud configuration options for MindCache constructor
@@ -135,6 +136,8 @@ interface MindCacheOptions {
135
136
  history?: HistoryOptions;
136
137
  /** Access level for tag operations. 'system' allows managing system tags. */
137
138
  accessLevel?: AccessLevel;
139
+ /** Optional existing Y.Doc instance (for server-side hydration) */
140
+ doc?: Y.Doc;
138
141
  }
139
142
  type ConnectionState$1 = 'disconnected' | 'connecting' | 'connected' | 'error';
140
143
  declare class MindCache {
@@ -245,6 +248,16 @@ declare class MindCache {
245
248
  */
246
249
  set_attributes(key: string, attributes: Partial<KeyAttributes>): void;
247
250
  set_value(key: string, value: any, attributes?: Partial<KeyAttributes>): void;
251
+ /**
252
+ * LLM-safe method to write a value to a key.
253
+ * This method:
254
+ * - Only updates the value, never modifies attributes/systemTags
255
+ * - Checks LLMWrite permission before writing
256
+ * - Returns false if key doesn't exist or lacks LLMWrite permission
257
+ *
258
+ * Used by create_vercel_ai_tools() to prevent LLMs from escalating privileges.
259
+ */
260
+ llm_set_key(key: string, value: any): boolean;
248
261
  delete_key(key: string): void;
249
262
  clear(): void;
250
263
  /**
@@ -427,6 +440,14 @@ declare class MindCache {
427
440
  /**
428
441
  * Generate Vercel AI SDK compatible tools for writable keys.
429
442
  * For document type keys, generates additional tools: append_, insert_, edit_
443
+ *
444
+ * Security: All tools use llm_set_key internally which:
445
+ * - Only modifies VALUES, never attributes/systemTags
446
+ * - Prevents LLMs from escalating privileges
447
+ */
448
+ create_vercel_ai_tools(): Record<string, any>;
449
+ /**
450
+ * @deprecated Use create_vercel_ai_tools() instead
430
451
  */
431
452
  get_aisdk_tools(): Record<string, any>;
432
453
  /**
@@ -509,6 +530,7 @@ declare class CloudAdapter {
509
530
  private token;
510
531
  private handleOnline;
511
532
  private handleOffline;
533
+ private _synced;
512
534
  constructor(config: CloudConfig);
513
535
  /** Browser network status - instantly updated via navigator.onLine */
514
536
  get isOnline(): boolean;
@@ -530,4 +552,4 @@ declare class CloudAdapter {
530
552
  private scheduleReconnect;
531
553
  }
532
554
 
533
- 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 };
555
+ export { type AccessLevel as A, type CloudConfig as C, type DeleteOperation 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 SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type MindCacheOptions as e, type KeyType as f, type SystemTag as g, type STM as h, type STMEntry as i, type HistoryOptions as j, type MindCacheCloudOptions as k, type MindCacheIndexedDBOptions as l, DEFAULT_KEY_ATTRIBUTES as m, SystemTagHelpers as n };
@@ -1,5 +1,5 @@
1
- import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-C0UyG6OY.mjs';
2
- export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-C0UyG6OY.mjs';
1
+ import { M as MindCache, C as CloudConfig, a as CloudAdapter } from '../CloudAdapter-CJS3Sh4f.mjs';
2
+ export { d as ClearOperation, c as CloudAdapterEvents, b as ConnectionState, D as DeleteOperation, O as Operation, S as SetOperation } from '../CloudAdapter-CJS3Sh4f.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-C0UyG6OY.js';
2
- export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-C0UyG6OY.js';
1
+ import { M as MindCache, C as CloudConfig, a as CloudAdapter } from '../CloudAdapter-CJS3Sh4f.js';
2
+ export { d as ClearOperation, c as CloudAdapterEvents, b as ConnectionState, D as DeleteOperation, O as Operation, S as SetOperation } from '../CloudAdapter-CJS3Sh4f.js';
3
3
  import 'yjs';
4
4
 
5
5
  /**