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.
package/dist/index.d.mts CHANGED
@@ -1,35 +1,8 @@
1
- import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-C0UyG6OY.mjs';
2
- export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-C0UyG6OY.mjs';
1
+ import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-CJS3Sh4f.mjs';
2
+ export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, m as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, j as HistoryOptions, K as KeyAttributes, i as KeyEntry, f as KeyType, L as Listener, k as MindCacheCloudOptions, l as MindCacheIndexedDBOptions, h as STM, i as STMEntry, g as SystemTag, n as SystemTagHelpers } from './CloudAdapter-CJS3Sh4f.mjs';
3
+ export { IndexedDBAdapter, IndexedDBConfig } from './server.mjs';
3
4
  import 'yjs';
4
5
 
5
- interface IndexedDBConfig {
6
- /** Database name (defaults to 'mindcache_db') */
7
- dbName?: string;
8
- /** Store name (defaults to 'mindcache_store') */
9
- storeName?: string;
10
- /** Storage key (defaults to 'mindcache_data') */
11
- key?: string;
12
- /** Debounce time in ms for saving (defaults to 1000) */
13
- debounceMs?: number;
14
- }
15
- declare class IndexedDBAdapter {
16
- private config;
17
- private mindcache;
18
- private unsubscribe;
19
- private saveTimeout;
20
- private db;
21
- private dbName;
22
- private storeName;
23
- private key;
24
- constructor(config?: IndexedDBConfig);
25
- attach(mc: MindCache): Promise<void>;
26
- detach(): void;
27
- private initDB;
28
- private load;
29
- private scheduleSave;
30
- private save;
31
- }
32
-
33
6
  interface UseMindCacheResult {
34
7
  /** The MindCache instance, null until loaded */
35
8
  mindcache: MindCache | null;
@@ -61,4 +34,4 @@ declare function useMindCache(options?: MindCacheOptions): UseMindCacheResult;
61
34
 
62
35
  declare const mindcache: MindCache;
63
36
 
64
- export { IndexedDBAdapter, type IndexedDBConfig, MindCache, MindCacheOptions, type UseMindCacheResult, mindcache, useMindCache };
37
+ export { MindCache, MindCacheOptions, type UseMindCacheResult, mindcache, useMindCache };
package/dist/index.d.ts CHANGED
@@ -1,35 +1,8 @@
1
- import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-C0UyG6OY.js';
2
- export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-C0UyG6OY.js';
1
+ import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-CJS3Sh4f.js';
2
+ export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, m as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, j as HistoryOptions, K as KeyAttributes, i as KeyEntry, f as KeyType, L as Listener, k as MindCacheCloudOptions, l as MindCacheIndexedDBOptions, h as STM, i as STMEntry, g as SystemTag, n as SystemTagHelpers } from './CloudAdapter-CJS3Sh4f.js';
3
+ export { IndexedDBAdapter, IndexedDBConfig } from './server.js';
3
4
  import 'yjs';
4
5
 
5
- interface IndexedDBConfig {
6
- /** Database name (defaults to 'mindcache_db') */
7
- dbName?: string;
8
- /** Store name (defaults to 'mindcache_store') */
9
- storeName?: string;
10
- /** Storage key (defaults to 'mindcache_data') */
11
- key?: string;
12
- /** Debounce time in ms for saving (defaults to 1000) */
13
- debounceMs?: number;
14
- }
15
- declare class IndexedDBAdapter {
16
- private config;
17
- private mindcache;
18
- private unsubscribe;
19
- private saveTimeout;
20
- private db;
21
- private dbName;
22
- private storeName;
23
- private key;
24
- constructor(config?: IndexedDBConfig);
25
- attach(mc: MindCache): Promise<void>;
26
- detach(): void;
27
- private initDB;
28
- private load;
29
- private scheduleSave;
30
- private save;
31
- }
32
-
33
6
  interface UseMindCacheResult {
34
7
  /** The MindCache instance, null until loaded */
35
8
  mindcache: MindCache | null;
@@ -61,4 +34,4 @@ declare function useMindCache(options?: MindCacheOptions): UseMindCacheResult;
61
34
 
62
35
  declare const mindcache: MindCache;
63
36
 
64
- export { IndexedDBAdapter, type IndexedDBConfig, MindCache, MindCacheOptions, type UseMindCacheResult, mindcache, useMindCache };
37
+ export { MindCache, MindCacheOptions, type UseMindCacheResult, mindcache, useMindCache };
package/dist/index.js CHANGED
@@ -206,6 +206,7 @@ var init_CloudAdapter = __esm({
206
206
  RECONNECT_DELAY = 1e3;
207
207
  MAX_RECONNECT_DELAY = 3e4;
208
208
  exports.CloudAdapter = class {
209
+ // Track if initial sync is complete
209
210
  constructor(config) {
210
211
  this.config = config;
211
212
  if (!config.baseUrl) {
@@ -225,6 +226,7 @@ var init_CloudAdapter = __esm({
225
226
  token = null;
226
227
  handleOnline = null;
227
228
  handleOffline = null;
229
+ _synced = false;
228
230
  /** Browser network status - instantly updated via navigator.onLine */
229
231
  get isOnline() {
230
232
  return this._isOnline;
@@ -407,10 +409,14 @@ var init_CloudAdapter = __esm({
407
409
  const encoder = encoding__namespace.createEncoder();
408
410
  const decoder = decoding__namespace.createDecoder(new Uint8Array(event.data));
409
411
  if (this.mindcache) {
410
- syncProtocol__namespace.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
412
+ const messageType = syncProtocol__namespace.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
411
413
  if (encoding__namespace.length(encoder) > 0) {
412
414
  this.sendBinary(encoding__namespace.toUint8Array(encoder));
413
415
  }
416
+ if (!this._synced && (messageType === 1 || messageType === 2)) {
417
+ this._synced = true;
418
+ this.emit("synced");
419
+ }
414
420
  }
415
421
  }
416
422
  } catch (error) {
@@ -454,15 +460,21 @@ var init_CloudAdapter = __esm({
454
460
  var DEFAULT_KEY_ATTRIBUTES = {
455
461
  type: "text",
456
462
  contentTags: [],
457
- systemTags: ["SystemPrompt", "LLMWrite"],
458
- // visible in system prompt and writable by LLM by default
459
- zIndex: 0,
460
- // Legacy - derived from systemTags
461
- readonly: false,
462
- visible: true,
463
- hardcoded: false,
464
- template: false,
465
- tags: []
463
+ systemTags: [],
464
+ // Keys are private by default - explicitly add SystemPrompt/LLMRead/LLMWrite to enable LLM access
465
+ zIndex: 0
466
+ };
467
+ var SystemTagHelpers = {
468
+ /** Check if key is writable by LLM */
469
+ isLLMWritable: (attrs) => attrs.systemTags.includes("LLMWrite"),
470
+ /** Check if key is readable by LLM (in context or via tools) */
471
+ isLLMReadable: (attrs) => attrs.systemTags.includes("SystemPrompt") || attrs.systemTags.includes("LLMRead"),
472
+ /** Check if key is included in system prompt */
473
+ isInSystemPrompt: (attrs) => attrs.systemTags.includes("SystemPrompt"),
474
+ /** Check if key is protected from deletion */
475
+ isProtected: (attrs) => attrs.systemTags.includes("protected"),
476
+ /** Check if key uses template injection */
477
+ hasTemplateInjection: (attrs) => attrs.systemTags.includes("ApplyTemplate")
466
478
  };
467
479
 
468
480
  // src/core/MindCache.ts
@@ -480,35 +492,14 @@ var MindCache = class {
480
492
  // (Less critical with Yjs but kept for API compat)
481
493
  normalizeSystemTags(tags) {
482
494
  const normalized = [];
483
- let hasSystemPrompt = false;
484
- let hasLLMRead = false;
485
- let hasLLMWrite = false;
486
- let hasReadonly = false;
495
+ const seen = /* @__PURE__ */ new Set();
487
496
  for (const tag of tags) {
488
- if (tag === "SystemPrompt" || tag === "prompt") {
489
- hasSystemPrompt = true;
490
- } else if (tag === "LLMRead") {
491
- hasLLMRead = true;
492
- } else if (tag === "LLMWrite") {
493
- hasLLMWrite = true;
494
- } else if (tag === "readonly") {
495
- hasReadonly = true;
496
- } else if (tag === "protected") {
497
- normalized.push(tag);
498
- } else if (tag === "ApplyTemplate" || tag === "template") {
499
- normalized.push("ApplyTemplate");
500
- }
501
- }
502
- if (hasSystemPrompt) {
503
- normalized.push("SystemPrompt");
504
- }
505
- if (hasLLMRead) {
506
- normalized.push("LLMRead");
507
- }
508
- if (hasReadonly) {
509
- normalized.push("readonly");
510
- } else if (hasLLMWrite) {
511
- normalized.push("LLMWrite");
497
+ if (["SystemPrompt", "LLMRead", "LLMWrite", "protected", "ApplyTemplate"].includes(tag)) {
498
+ if (!seen.has(tag)) {
499
+ seen.add(tag);
500
+ normalized.push(tag);
501
+ }
502
+ }
512
503
  }
513
504
  return normalized;
514
505
  }
@@ -532,7 +523,7 @@ var MindCache = class {
532
523
  _historyOptions = { maxEntries: 100, snapshotInterval: 10 };
533
524
  _historyEnabled = false;
534
525
  constructor(options) {
535
- this.doc = new Y__namespace.Doc();
526
+ this.doc = options?.doc || new Y__namespace.Doc();
536
527
  this.rootMap = this.doc.getMap("mindcache");
537
528
  this.rootMap.observeDeep((events) => {
538
529
  const keysAffected = /* @__PURE__ */ new Set();
@@ -935,16 +926,10 @@ var MindCache = class {
935
926
  const attrs = entry.attributes || {};
936
927
  const normalizedAttrs = {
937
928
  type: attrs.type || "text",
929
+ contentType: attrs.contentType,
938
930
  contentTags: attrs.contentTags || [],
939
- systemTags: attrs.systemTags || this.normalizeSystemTags(attrs.visible !== false ? ["prompt"] : []),
940
- zIndex: attrs.zIndex ?? 0,
941
- // Legacy fields
942
- readonly: attrs.readonly ?? false,
943
- visible: attrs.visible ?? true,
944
- hardcoded: attrs.hardcoded ?? false,
945
- template: attrs.template ?? false,
946
- tags: attrs.tags || [],
947
- contentType: attrs.contentType
931
+ systemTags: this.normalizeSystemTags(attrs.systemTags || []),
932
+ zIndex: attrs.zIndex ?? 0
948
933
  };
949
934
  entryMap.set("attributes", normalizedAttrs);
950
935
  }
@@ -1049,7 +1034,7 @@ var MindCache = class {
1049
1034
  if (_processingStack && _processingStack.has(key)) {
1050
1035
  return `{{${key}}}`;
1051
1036
  }
1052
- if (attributes?.systemTags?.includes("ApplyTemplate") || attributes?.systemTags?.includes("template") || attributes?.template) {
1037
+ if (attributes?.systemTags?.includes("ApplyTemplate")) {
1053
1038
  if (typeof value === "string") {
1054
1039
  const stack = _processingStack || /* @__PURE__ */ new Set();
1055
1040
  stack.add(key);
@@ -1063,13 +1048,8 @@ var MindCache = class {
1063
1048
  return {
1064
1049
  type: "text",
1065
1050
  contentTags: [],
1066
- systemTags: ["prompt", "readonly", "protected"],
1067
- zIndex: 999999,
1068
- readonly: true,
1069
- visible: true,
1070
- hardcoded: true,
1071
- template: false,
1072
- tags: []
1051
+ systemTags: ["SystemPrompt", "protected"],
1052
+ zIndex: 999999
1073
1053
  };
1074
1054
  }
1075
1055
  const entryMap = this.rootMap.get(key);
@@ -1136,22 +1116,13 @@ var MindCache = class {
1136
1116
  this.getUndoManager(key);
1137
1117
  this.doc.transact(() => {
1138
1118
  const oldAttributes = isNewEntry ? {
1139
- ...DEFAULT_KEY_ATTRIBUTES,
1140
- contentTags: [],
1141
- systemTags: ["SystemPrompt", "LLMWrite"],
1142
- tags: [],
1143
- zIndex: 0
1119
+ ...DEFAULT_KEY_ATTRIBUTES
1144
1120
  } : entryMap.get("attributes");
1145
1121
  const finalAttributes = attributes ? { ...oldAttributes, ...attributes } : oldAttributes;
1146
1122
  let normalizedAttributes = { ...finalAttributes };
1147
1123
  if (finalAttributes.systemTags) {
1148
1124
  normalizedAttributes.systemTags = this.normalizeSystemTags(finalAttributes.systemTags);
1149
1125
  }
1150
- if (finalAttributes.template) {
1151
- if (!normalizedAttributes.systemTags.includes("template")) {
1152
- normalizedAttributes.systemTags.push("template");
1153
- }
1154
- }
1155
1126
  let valueToSet = value;
1156
1127
  if (normalizedAttributes.type === "document" && !(valueToSet instanceof Y__namespace.Text)) {
1157
1128
  valueToSet = new Y__namespace.Text(typeof value === "string" ? value : String(value ?? ""));
@@ -1162,6 +1133,38 @@ var MindCache = class {
1162
1133
  entryMap.set("attributes", normalizedAttributes);
1163
1134
  });
1164
1135
  }
1136
+ /**
1137
+ * LLM-safe method to write a value to a key.
1138
+ * This method:
1139
+ * - Only updates the value, never modifies attributes/systemTags
1140
+ * - Checks LLMWrite permission before writing
1141
+ * - Returns false if key doesn't exist or lacks LLMWrite permission
1142
+ *
1143
+ * Used by create_vercel_ai_tools() to prevent LLMs from escalating privileges.
1144
+ */
1145
+ llm_set_key(key, value) {
1146
+ if (key === "$date" || key === "$time" || key === "$version") {
1147
+ return false;
1148
+ }
1149
+ const entryMap = this.rootMap.get(key);
1150
+ if (!entryMap) {
1151
+ return false;
1152
+ }
1153
+ const attributes = entryMap.get("attributes");
1154
+ if (!attributes?.systemTags?.includes("LLMWrite")) {
1155
+ return false;
1156
+ }
1157
+ if (attributes.type === "document") {
1158
+ if (typeof value === "string") {
1159
+ this._replaceDocumentText(key, value);
1160
+ }
1161
+ return true;
1162
+ }
1163
+ this.doc.transact(() => {
1164
+ entryMap.set("value", value);
1165
+ });
1166
+ return true;
1167
+ }
1165
1168
  delete_key(key) {
1166
1169
  if (key === "$date" || key === "$time") {
1167
1170
  return;
@@ -1606,15 +1609,13 @@ var MindCache = class {
1606
1609
  }
1607
1610
  const attributes = entryMap.get("attributes");
1608
1611
  const value = entryMap.get("value");
1609
- if (attributes?.hardcoded) {
1612
+ if (attributes?.systemTags?.includes("protected")) {
1610
1613
  return;
1611
1614
  }
1612
1615
  lines.push(`### ${key}`);
1613
1616
  const entryType = attributes?.type || "text";
1614
1617
  lines.push(`- **Type**: \`${entryType}\``);
1615
- lines.push(`- **Readonly**: \`${attributes?.readonly ?? false}\``);
1616
- lines.push(`- **Visible**: \`${attributes?.visible ?? true}\``);
1617
- lines.push(`- **Template**: \`${attributes?.template ?? false}\``);
1618
+ lines.push(`- **System Tags**: \`${attributes?.systemTags?.join(", ") || "none"}\``);
1618
1619
  lines.push(`- **Z-Index**: \`${attributes?.zIndex ?? 0}\``);
1619
1620
  if (attributes?.contentTags && attributes.contentTags.length > 0) {
1620
1621
  lines.push(`- **Tags**: \`${attributes.contentTags.join("`, `")}\``);
@@ -1644,7 +1645,10 @@ var MindCache = class {
1644
1645
  }
1645
1646
  lines.push("```");
1646
1647
  } else {
1647
- lines.push(`- **Value**: ${value}`);
1648
+ lines.push("- **Value**:");
1649
+ lines.push("```");
1650
+ lines.push(String(value));
1651
+ lines.push("```");
1648
1652
  }
1649
1653
  lines.push("");
1650
1654
  });
@@ -1679,7 +1683,7 @@ var MindCache = class {
1679
1683
  for (const line of lines) {
1680
1684
  if (line.startsWith("### ") && !line.startsWith("### Appendix")) {
1681
1685
  if (currentKey && currentValue !== null) {
1682
- this.set_value(currentKey, currentValue, currentAttributes);
1686
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1683
1687
  }
1684
1688
  currentKey = line.substring(4).trim();
1685
1689
  currentAttributes = {};
@@ -1700,16 +1704,11 @@ var MindCache = class {
1700
1704
  }
1701
1705
  continue;
1702
1706
  }
1703
- if (line.startsWith("- **Readonly**:")) {
1704
- currentAttributes.readonly = line.includes("`true`");
1705
- continue;
1706
- }
1707
- if (line.startsWith("- **Visible**:")) {
1708
- currentAttributes.visible = line.includes("`true`");
1709
- continue;
1710
- }
1711
- if (line.startsWith("- **Template**:")) {
1712
- currentAttributes.template = line.includes("`true`");
1707
+ if (line.startsWith("- **System Tags**:")) {
1708
+ const tagsStr = line.match(/`([^`]+)`/)?.[1] || "";
1709
+ if (tagsStr !== "none") {
1710
+ currentAttributes.systemTags = tagsStr.split(", ").filter((t) => t);
1711
+ }
1713
1712
  continue;
1714
1713
  }
1715
1714
  if (line.startsWith("- **Z-Index**:")) {
@@ -1720,7 +1719,6 @@ var MindCache = class {
1720
1719
  if (line.startsWith("- **Tags**:")) {
1721
1720
  const tags = line.match(/`([^`]+)`/g)?.map((t) => t.slice(1, -1)) || [];
1722
1721
  currentAttributes.contentTags = tags;
1723
- currentAttributes.tags = tags;
1724
1722
  continue;
1725
1723
  }
1726
1724
  if (line.startsWith("- **Content Type**:")) {
@@ -1728,10 +1726,24 @@ var MindCache = class {
1728
1726
  continue;
1729
1727
  }
1730
1728
  if (line.startsWith("- **Value**:") && !line.includes("[See Appendix")) {
1731
- currentValue = line.substring(12).trim();
1729
+ const afterValue = line.substring(12).trim();
1730
+ if (afterValue === "") {
1731
+ currentValue = "";
1732
+ } else if (afterValue === "```" || afterValue === "```json") {
1733
+ inCodeBlock = true;
1734
+ codeBlockContent = [];
1735
+ currentValue = "";
1736
+ } else if (afterValue.startsWith("```")) {
1737
+ inCodeBlock = true;
1738
+ codeBlockContent = [afterValue.substring(3)];
1739
+ currentValue = "";
1740
+ } else {
1741
+ currentValue = afterValue;
1742
+ }
1732
1743
  continue;
1733
1744
  }
1734
- if (line === "```json" || line === "```") {
1745
+ const trimmedLine = line.trim();
1746
+ if (trimmedLine === "```json" || trimmedLine === "```") {
1735
1747
  if (inCodeBlock) {
1736
1748
  inCodeBlock = false;
1737
1749
  if (currentKey && codeBlockContent.length > 0) {
@@ -1740,15 +1752,27 @@ var MindCache = class {
1740
1752
  codeBlockContent = [];
1741
1753
  } else {
1742
1754
  inCodeBlock = true;
1755
+ codeBlockContent = [];
1743
1756
  }
1744
1757
  continue;
1745
1758
  }
1746
1759
  if (inCodeBlock) {
1747
1760
  codeBlockContent.push(line);
1761
+ } else if (currentKey && currentValue !== null) {
1762
+ currentValue += "\n" + line;
1748
1763
  }
1749
1764
  }
1750
1765
  if (currentKey && currentValue !== null) {
1751
- this.set_value(currentKey, currentValue, currentAttributes);
1766
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1767
+ }
1768
+ const hasParsedKeys = lines.some((line) => line.startsWith("### ") && !line.startsWith("### Appendix"));
1769
+ if (!hasParsedKeys && markdown.trim().length > 0) {
1770
+ this.set_value("imported_content", markdown.trim(), {
1771
+ type: "text",
1772
+ systemTags: ["SystemPrompt", "LLMWrite"],
1773
+ // Default assumptions
1774
+ zIndex: 0
1775
+ });
1752
1776
  }
1753
1777
  }
1754
1778
  /**
@@ -1976,8 +2000,12 @@ var MindCache = class {
1976
2000
  /**
1977
2001
  * Generate Vercel AI SDK compatible tools for writable keys.
1978
2002
  * For document type keys, generates additional tools: append_, insert_, edit_
2003
+ *
2004
+ * Security: All tools use llm_set_key internally which:
2005
+ * - Only modifies VALUES, never attributes/systemTags
2006
+ * - Prevents LLMs from escalating privileges
1979
2007
  */
1980
- get_aisdk_tools() {
2008
+ create_vercel_ai_tools() {
1981
2009
  const tools = {};
1982
2010
  for (const [key, val] of this.rootMap) {
1983
2011
  if (key.startsWith("$")) {
@@ -1985,7 +2013,7 @@ var MindCache = class {
1985
2013
  }
1986
2014
  const entryMap = val;
1987
2015
  const attributes = entryMap.get("attributes");
1988
- const isWritable = !attributes?.readonly && (attributes?.systemTags?.includes("LLMWrite") || !attributes?.systemTags);
2016
+ const isWritable = attributes?.systemTags?.includes("LLMWrite");
1989
2017
  if (!isWritable) {
1990
2018
  continue;
1991
2019
  }
@@ -2001,15 +2029,18 @@ var MindCache = class {
2001
2029
  required: ["value"]
2002
2030
  },
2003
2031
  execute: async ({ value }) => {
2004
- if (isDocument) {
2005
- this._replaceDocumentText(key, value);
2006
- } else {
2007
- this.set_value(key, value);
2032
+ const success = this.llm_set_key(key, value);
2033
+ if (success) {
2034
+ return {
2035
+ result: `Successfully wrote "${value}" to ${key}`,
2036
+ key,
2037
+ value
2038
+ };
2008
2039
  }
2009
2040
  return {
2010
- result: `Successfully wrote "${value}" to ${key}`,
2041
+ result: `Failed to write to ${key} - permission denied or key not found`,
2011
2042
  key,
2012
- value
2043
+ error: true
2013
2044
  };
2014
2045
  }
2015
2046
  };
@@ -2024,6 +2055,9 @@ var MindCache = class {
2024
2055
  required: ["text"]
2025
2056
  },
2026
2057
  execute: async ({ text }) => {
2058
+ if (!attributes?.systemTags?.includes("LLMWrite")) {
2059
+ return { result: `Permission denied for ${key}`, key, error: true };
2060
+ }
2027
2061
  const yText = this.get_document(key);
2028
2062
  if (yText) {
2029
2063
  yText.insert(yText.length, text);
@@ -2047,6 +2081,9 @@ var MindCache = class {
2047
2081
  required: ["index", "text"]
2048
2082
  },
2049
2083
  execute: async ({ index, text }) => {
2084
+ if (!attributes?.systemTags?.includes("LLMWrite")) {
2085
+ return { result: `Permission denied for ${key}`, key, error: true };
2086
+ }
2050
2087
  this.insert_text(key, index, text);
2051
2088
  return {
2052
2089
  result: `Successfully inserted text at position ${index} in ${key}`,
@@ -2067,6 +2104,9 @@ var MindCache = class {
2067
2104
  required: ["find", "replace"]
2068
2105
  },
2069
2106
  execute: async ({ find, replace }) => {
2107
+ if (!attributes?.systemTags?.includes("LLMWrite")) {
2108
+ return { result: `Permission denied for ${key}`, key, error: true };
2109
+ }
2070
2110
  const yText = this.get_document(key);
2071
2111
  if (yText) {
2072
2112
  const text = yText.toString();
@@ -2091,6 +2131,12 @@ var MindCache = class {
2091
2131
  }
2092
2132
  return tools;
2093
2133
  }
2134
+ /**
2135
+ * @deprecated Use create_vercel_ai_tools() instead
2136
+ */
2137
+ get_aisdk_tools() {
2138
+ return this.create_vercel_ai_tools();
2139
+ }
2094
2140
  /**
2095
2141
  * Generate a system prompt containing all visible STM keys and their values.
2096
2142
  * Indicates which tools can be used to modify writable keys.
@@ -2103,13 +2149,13 @@ var MindCache = class {
2103
2149
  }
2104
2150
  const entryMap = val;
2105
2151
  const attributes = entryMap.get("attributes");
2106
- const isVisible = attributes?.visible !== false && (attributes?.systemTags?.includes("prompt") || attributes?.systemTags?.includes("SystemPrompt") || !attributes?.systemTags);
2152
+ const isVisible = attributes?.systemTags?.includes("SystemPrompt") || attributes?.systemTags?.includes("LLMRead");
2107
2153
  if (!isVisible) {
2108
2154
  continue;
2109
2155
  }
2110
2156
  const value = this.get_value(key);
2111
2157
  const displayValue = typeof value === "object" ? JSON.stringify(value) : value;
2112
- const isWritable = !attributes?.readonly && (attributes?.systemTags?.includes("LLMWrite") || !attributes?.systemTags);
2158
+ const isWritable = attributes?.systemTags?.includes("LLMWrite");
2113
2159
  const isDocument = attributes?.type === "document";
2114
2160
  const sanitizedKey = this.sanitizeKeyForTool(key);
2115
2161
  if (isWritable) {
@@ -2150,7 +2196,7 @@ var MindCache = class {
2150
2196
  return null;
2151
2197
  }
2152
2198
  const attributes = entryMap.get("attributes");
2153
- const isWritable = !attributes?.readonly && (attributes?.systemTags?.includes("LLMWrite") || !attributes?.systemTags);
2199
+ const isWritable = attributes?.systemTags?.includes("LLMWrite");
2154
2200
  if (!isWritable) {
2155
2201
  return null;
2156
2202
  }
@@ -2267,6 +2313,7 @@ var mindcache = new MindCache();
2267
2313
 
2268
2314
  exports.DEFAULT_KEY_ATTRIBUTES = DEFAULT_KEY_ATTRIBUTES;
2269
2315
  exports.MindCache = MindCache;
2316
+ exports.SystemTagHelpers = SystemTagHelpers;
2270
2317
  exports.mindcache = mindcache;
2271
2318
  exports.useMindCache = useMindCache;
2272
2319
  //# sourceMappingURL=index.js.map