mindcache 2.3.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.
- package/dist/{index-DXb0fL3e.d.mts → CloudAdapter-B04-OWx3.d.mts} +45 -8
- package/dist/{index-DXb0fL3e.d.ts → CloudAdapter-B04-OWx3.d.ts} +45 -8
- package/dist/cloud/index.d.mts +2 -2
- package/dist/cloud/index.d.ts +2 -2
- package/dist/cloud/index.js +366 -77
- package/dist/cloud/index.js.map +1 -1
- package/dist/cloud/index.mjs +366 -77
- package/dist/cloud/index.mjs.map +1 -1
- package/dist/index.d.mts +61 -1
- package/dist/index.d.ts +61 -1
- package/dist/index.js +405 -77
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +405 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
|
+
var react = require('react');
|
|
4
5
|
|
|
5
6
|
var __defProp = Object.defineProperty;
|
|
6
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -12,6 +13,157 @@ var __export = (target, all) => {
|
|
|
12
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
// src/local/IndexedDBAdapter.ts
|
|
17
|
+
var IndexedDBAdapter_exports = {};
|
|
18
|
+
__export(IndexedDBAdapter_exports, {
|
|
19
|
+
IndexedDBAdapter: () => exports.IndexedDBAdapter
|
|
20
|
+
});
|
|
21
|
+
exports.IndexedDBAdapter = void 0;
|
|
22
|
+
var init_IndexedDBAdapter = __esm({
|
|
23
|
+
"src/local/IndexedDBAdapter.ts"() {
|
|
24
|
+
exports.IndexedDBAdapter = class {
|
|
25
|
+
constructor(config = {}) {
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.dbName = config.dbName || "mindcache_db";
|
|
28
|
+
this.storeName = config.storeName || "mindcache_store";
|
|
29
|
+
this.key = config.key || "mindcache_data";
|
|
30
|
+
}
|
|
31
|
+
mindcache = null;
|
|
32
|
+
unsubscribe = null;
|
|
33
|
+
saveTimeout = null;
|
|
34
|
+
db = null;
|
|
35
|
+
dbName;
|
|
36
|
+
storeName;
|
|
37
|
+
key;
|
|
38
|
+
async attach(mc) {
|
|
39
|
+
if (this.mindcache) {
|
|
40
|
+
this.detach();
|
|
41
|
+
}
|
|
42
|
+
this.mindcache = mc;
|
|
43
|
+
await this.initDB();
|
|
44
|
+
await this.load();
|
|
45
|
+
const listener = () => {
|
|
46
|
+
if (this.mindcache && !this.mindcache.isRemoteUpdate()) {
|
|
47
|
+
this.scheduleSave();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
mc.subscribeToAll(listener);
|
|
51
|
+
this.unsubscribe = () => mc.unsubscribeFromAll(listener);
|
|
52
|
+
console.log("\u{1F5C4}\uFE0F IndexedDBAdapter: Attached to MindCache instance");
|
|
53
|
+
}
|
|
54
|
+
detach() {
|
|
55
|
+
if (this.unsubscribe) {
|
|
56
|
+
this.unsubscribe();
|
|
57
|
+
this.unsubscribe = null;
|
|
58
|
+
}
|
|
59
|
+
if (this.saveTimeout) {
|
|
60
|
+
clearTimeout(this.saveTimeout);
|
|
61
|
+
this.saveTimeout = null;
|
|
62
|
+
}
|
|
63
|
+
this.mindcache = null;
|
|
64
|
+
if (this.db) {
|
|
65
|
+
this.db.close();
|
|
66
|
+
this.db = null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
initDB() {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const request = indexedDB.open(this.dbName);
|
|
72
|
+
request.onerror = () => {
|
|
73
|
+
console.error("MindCache: IndexedDB error:", request.error);
|
|
74
|
+
reject(request.error);
|
|
75
|
+
};
|
|
76
|
+
request.onsuccess = () => {
|
|
77
|
+
const db = request.result;
|
|
78
|
+
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
79
|
+
const currentVersion = db.version;
|
|
80
|
+
db.close();
|
|
81
|
+
const upgradeRequest = indexedDB.open(this.dbName, currentVersion + 1);
|
|
82
|
+
upgradeRequest.onerror = () => {
|
|
83
|
+
console.error("MindCache: IndexedDB upgrade error:", upgradeRequest.error);
|
|
84
|
+
reject(upgradeRequest.error);
|
|
85
|
+
};
|
|
86
|
+
upgradeRequest.onupgradeneeded = () => {
|
|
87
|
+
const upgradeDb = upgradeRequest.result;
|
|
88
|
+
if (!upgradeDb.objectStoreNames.contains(this.storeName)) {
|
|
89
|
+
upgradeDb.createObjectStore(this.storeName);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
upgradeRequest.onsuccess = () => {
|
|
93
|
+
this.db = upgradeRequest.result;
|
|
94
|
+
resolve();
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
this.db = db;
|
|
98
|
+
resolve();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
request.onupgradeneeded = () => {
|
|
102
|
+
const db = request.result;
|
|
103
|
+
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
104
|
+
db.createObjectStore(this.storeName);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
load() {
|
|
110
|
+
if (!this.db || !this.mindcache) {
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
return new Promise((resolve) => {
|
|
114
|
+
try {
|
|
115
|
+
const transaction = this.db.transaction([this.storeName], "readonly");
|
|
116
|
+
const store = transaction.objectStore(this.storeName);
|
|
117
|
+
const request = store.get(this.key);
|
|
118
|
+
request.onsuccess = () => {
|
|
119
|
+
if (request.result) {
|
|
120
|
+
this.mindcache.deserialize(request.result);
|
|
121
|
+
console.log("\u{1F5C4}\uFE0F IndexedDBAdapter: Loaded data from IndexedDB");
|
|
122
|
+
}
|
|
123
|
+
resolve();
|
|
124
|
+
};
|
|
125
|
+
request.onerror = () => {
|
|
126
|
+
console.error("MindCache: Failed to load from IndexedDB:", request.error);
|
|
127
|
+
resolve();
|
|
128
|
+
};
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error("MindCache: Error accessing IndexedDB for load:", error);
|
|
131
|
+
resolve();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
scheduleSave() {
|
|
136
|
+
if (this.saveTimeout) {
|
|
137
|
+
clearTimeout(this.saveTimeout);
|
|
138
|
+
}
|
|
139
|
+
this.saveTimeout = setTimeout(() => {
|
|
140
|
+
this.save();
|
|
141
|
+
this.saveTimeout = null;
|
|
142
|
+
}, this.config.debounceMs ?? 1e3);
|
|
143
|
+
}
|
|
144
|
+
save() {
|
|
145
|
+
if (!this.db || !this.mindcache) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const data = this.mindcache.serialize();
|
|
150
|
+
const transaction = this.db.transaction([this.storeName], "readwrite");
|
|
151
|
+
const store = transaction.objectStore(this.storeName);
|
|
152
|
+
const request = store.put(data, this.key);
|
|
153
|
+
request.onsuccess = () => {
|
|
154
|
+
console.log("\u{1F5C4}\uFE0F IndexedDBAdapter: Saved to IndexedDB");
|
|
155
|
+
};
|
|
156
|
+
request.onerror = () => {
|
|
157
|
+
console.error("MindCache: Failed to save to IndexedDB:", request.error);
|
|
158
|
+
};
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error("MindCache: Error accessing IndexedDB for save:", error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
15
167
|
// src/cloud/CloudAdapter.ts
|
|
16
168
|
var CloudAdapter_exports = {};
|
|
17
169
|
__export(CloudAdapter_exports, {
|
|
@@ -330,8 +482,8 @@ var init_CloudAdapter = __esm({
|
|
|
330
482
|
var DEFAULT_KEY_ATTRIBUTES = {
|
|
331
483
|
type: "text",
|
|
332
484
|
contentTags: [],
|
|
333
|
-
systemTags: ["
|
|
334
|
-
// visible by default
|
|
485
|
+
systemTags: ["SystemPrompt", "LLMWrite"],
|
|
486
|
+
// visible in system prompt and writable by LLM by default
|
|
335
487
|
zIndex: 0,
|
|
336
488
|
// Legacy - derived from systemTags
|
|
337
489
|
readonly: false,
|
|
@@ -348,6 +500,65 @@ var MindCache = class {
|
|
|
348
500
|
globalListeners = [];
|
|
349
501
|
// Internal flag to prevent sync loops when receiving remote updates
|
|
350
502
|
_isRemoteUpdate = false;
|
|
503
|
+
/**
|
|
504
|
+
* Normalize system tags: migrate old tags to new ones
|
|
505
|
+
* - 'prompt' → 'SystemPrompt'
|
|
506
|
+
* - 'readonly' → remove 'LLMWrite' (or add if not readonly)
|
|
507
|
+
*/
|
|
508
|
+
normalizeSystemTags(tags) {
|
|
509
|
+
const normalized = [];
|
|
510
|
+
let hasSystemPrompt = false;
|
|
511
|
+
let hasLLMRead = false;
|
|
512
|
+
let hasLLMWrite = false;
|
|
513
|
+
let hasReadonly = false;
|
|
514
|
+
for (const tag of tags) {
|
|
515
|
+
if (tag === "SystemPrompt" || tag === "prompt") {
|
|
516
|
+
hasSystemPrompt = true;
|
|
517
|
+
} else if (tag === "LLMRead") {
|
|
518
|
+
hasLLMRead = true;
|
|
519
|
+
} else if (tag === "LLMWrite") {
|
|
520
|
+
hasLLMWrite = true;
|
|
521
|
+
} else if (tag === "readonly") {
|
|
522
|
+
hasReadonly = true;
|
|
523
|
+
} else if (tag === "protected") {
|
|
524
|
+
normalized.push(tag);
|
|
525
|
+
} else if (tag === "ApplyTemplate" || tag === "template") {
|
|
526
|
+
normalized.push("ApplyTemplate");
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (hasSystemPrompt) {
|
|
530
|
+
normalized.push("SystemPrompt");
|
|
531
|
+
}
|
|
532
|
+
if (hasLLMRead) {
|
|
533
|
+
normalized.push("LLMRead");
|
|
534
|
+
}
|
|
535
|
+
if (hasReadonly) {
|
|
536
|
+
normalized.push("readonly");
|
|
537
|
+
} else if (hasLLMWrite) {
|
|
538
|
+
normalized.push("LLMWrite");
|
|
539
|
+
} else {
|
|
540
|
+
normalized.push("LLMWrite");
|
|
541
|
+
}
|
|
542
|
+
return normalized;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Check if key should be visible in system prompt
|
|
546
|
+
*/
|
|
547
|
+
hasSystemPrompt(tags) {
|
|
548
|
+
return tags.includes("SystemPrompt") || tags.includes("prompt");
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Check if key can be read by LLM (has LLMRead or SystemPrompt)
|
|
552
|
+
*/
|
|
553
|
+
hasLLMRead(tags) {
|
|
554
|
+
return tags.includes("LLMRead") || tags.includes("SystemPrompt") || tags.includes("prompt");
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Check if key can be written by LLM (has LLMWrite and not readonly)
|
|
558
|
+
*/
|
|
559
|
+
hasLLMWrite(tags) {
|
|
560
|
+
return tags.includes("LLMWrite") && !tags.includes("readonly");
|
|
561
|
+
}
|
|
351
562
|
// Cloud sync state
|
|
352
563
|
_cloudAdapter = null;
|
|
353
564
|
_connectionState = "disconnected";
|
|
@@ -361,11 +572,28 @@ var MindCache = class {
|
|
|
361
572
|
if (options?.accessLevel) {
|
|
362
573
|
this._accessLevel = options.accessLevel;
|
|
363
574
|
}
|
|
575
|
+
if (options?.cloud && options?.indexedDB) {
|
|
576
|
+
throw new Error(
|
|
577
|
+
"MindCache: Cannot use both cloud and indexedDB together. Choose one persistence method to avoid data conflicts. Use cloud for real-time sync, or indexedDB for local-only persistence."
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
const initPromises = [];
|
|
364
581
|
if (options?.cloud) {
|
|
365
582
|
this._cloudConfig = options.cloud;
|
|
366
583
|
this._isLoaded = false;
|
|
367
584
|
this._connectionState = "disconnected";
|
|
368
|
-
|
|
585
|
+
initPromises.push(this._initCloud());
|
|
586
|
+
}
|
|
587
|
+
if (options?.indexedDB) {
|
|
588
|
+
this._isLoaded = false;
|
|
589
|
+
initPromises.push(this._initIndexedDB(options.indexedDB));
|
|
590
|
+
}
|
|
591
|
+
if (initPromises.length > 0) {
|
|
592
|
+
this._initPromise = Promise.all(initPromises).then(() => {
|
|
593
|
+
if (!this._cloudConfig) {
|
|
594
|
+
this._isLoaded = true;
|
|
595
|
+
}
|
|
596
|
+
});
|
|
369
597
|
}
|
|
370
598
|
}
|
|
371
599
|
/**
|
|
@@ -445,6 +673,19 @@ var MindCache = class {
|
|
|
445
673
|
this._isLoaded = true;
|
|
446
674
|
}
|
|
447
675
|
}
|
|
676
|
+
async _initIndexedDB(config) {
|
|
677
|
+
try {
|
|
678
|
+
const IndexedDBAdapter2 = await this._getIndexedDBAdapterClass();
|
|
679
|
+
const adapter = new IndexedDBAdapter2(config);
|
|
680
|
+
await adapter.attach(this);
|
|
681
|
+
} catch (error) {
|
|
682
|
+
console.error("MindCache: Failed to initialize IndexedDB:", error);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
async _getIndexedDBAdapterClass() {
|
|
686
|
+
const { IndexedDBAdapter: IndexedDBAdapter2 } = await Promise.resolve().then(() => (init_IndexedDBAdapter(), IndexedDBAdapter_exports));
|
|
687
|
+
return IndexedDBAdapter2;
|
|
688
|
+
}
|
|
448
689
|
/**
|
|
449
690
|
* Get the current cloud connection state
|
|
450
691
|
*/
|
|
@@ -563,7 +804,7 @@ var MindCache = class {
|
|
|
563
804
|
if (!entry) {
|
|
564
805
|
return void 0;
|
|
565
806
|
}
|
|
566
|
-
if (entry.attributes.template) {
|
|
807
|
+
if (entry.attributes.systemTags?.includes("ApplyTemplate") || entry.attributes.systemTags?.includes("template") || entry.attributes.template) {
|
|
567
808
|
const processingStack = _processingStack || /* @__PURE__ */ new Set();
|
|
568
809
|
if (processingStack.has(key)) {
|
|
569
810
|
return entry.value;
|
|
@@ -612,77 +853,87 @@ var MindCache = class {
|
|
|
612
853
|
...DEFAULT_KEY_ATTRIBUTES,
|
|
613
854
|
contentTags: [],
|
|
614
855
|
// Fresh array
|
|
615
|
-
systemTags: ["
|
|
856
|
+
systemTags: ["SystemPrompt", "LLMWrite"],
|
|
616
857
|
// Fresh array with default
|
|
617
858
|
tags: [],
|
|
618
859
|
// Fresh array
|
|
619
860
|
zIndex: 0
|
|
620
861
|
};
|
|
621
862
|
const finalAttributes = attributes ? { ...baseAttributes, ...attributes } : baseAttributes;
|
|
863
|
+
let systemTags = this.normalizeSystemTags(finalAttributes.systemTags || []);
|
|
622
864
|
if (attributes) {
|
|
623
|
-
let systemTags2 = [...finalAttributes.systemTags || []];
|
|
624
865
|
if ("readonly" in attributes) {
|
|
625
|
-
if (attributes.readonly
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
866
|
+
if (attributes.readonly) {
|
|
867
|
+
systemTags = systemTags.filter((t) => t !== "LLMWrite");
|
|
868
|
+
if (!systemTags.includes("readonly")) {
|
|
869
|
+
systemTags.push("readonly");
|
|
870
|
+
}
|
|
871
|
+
} else if (!wasHardcoded) {
|
|
872
|
+
if (!systemTags.includes("LLMWrite")) {
|
|
873
|
+
systemTags.push("LLMWrite");
|
|
874
|
+
}
|
|
875
|
+
systemTags = systemTags.filter((t) => t !== "readonly");
|
|
629
876
|
}
|
|
630
877
|
}
|
|
631
878
|
if ("visible" in attributes) {
|
|
632
|
-
if (attributes.visible
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
879
|
+
if (attributes.visible) {
|
|
880
|
+
if (!systemTags.includes("SystemPrompt")) {
|
|
881
|
+
systemTags.push("SystemPrompt");
|
|
882
|
+
}
|
|
883
|
+
systemTags = systemTags.filter((t) => t !== "prompt");
|
|
884
|
+
} else {
|
|
885
|
+
systemTags = systemTags.filter((t) => t !== "SystemPrompt" && t !== "prompt");
|
|
636
886
|
}
|
|
637
887
|
}
|
|
888
|
+
if ("systemTags" in attributes && Array.isArray(attributes.systemTags)) {
|
|
889
|
+
systemTags = this.normalizeSystemTags(attributes.systemTags);
|
|
890
|
+
}
|
|
638
891
|
if ("hardcoded" in attributes) {
|
|
639
|
-
if (attributes.hardcoded && !
|
|
640
|
-
|
|
892
|
+
if (attributes.hardcoded && !systemTags.includes("protected")) {
|
|
893
|
+
systemTags.push("protected");
|
|
641
894
|
} else if (!attributes.hardcoded && !wasHardcoded) {
|
|
642
|
-
|
|
895
|
+
systemTags = systemTags.filter((t) => t !== "protected");
|
|
643
896
|
}
|
|
644
|
-
if (wasHardcoded && !
|
|
645
|
-
|
|
897
|
+
if (wasHardcoded && !systemTags.includes("protected")) {
|
|
898
|
+
systemTags.push("protected");
|
|
646
899
|
}
|
|
647
900
|
} else if (wasHardcoded) {
|
|
648
|
-
if (!
|
|
649
|
-
|
|
901
|
+
if (!systemTags.includes("protected")) {
|
|
902
|
+
systemTags.push("protected");
|
|
650
903
|
}
|
|
651
904
|
}
|
|
652
905
|
if ("template" in attributes) {
|
|
653
|
-
if (attributes.template && !wasHardcoded && !
|
|
654
|
-
|
|
906
|
+
if (attributes.template && !wasHardcoded && !systemTags.includes("ApplyTemplate") && !systemTags.includes("template")) {
|
|
907
|
+
systemTags.push("ApplyTemplate");
|
|
655
908
|
} else if (!attributes.template || wasHardcoded) {
|
|
656
|
-
|
|
909
|
+
systemTags = systemTags.filter((t) => t !== "ApplyTemplate" && t !== "template");
|
|
657
910
|
}
|
|
658
911
|
}
|
|
659
|
-
finalAttributes.systemTags = systemTags2;
|
|
660
912
|
} else if (wasHardcoded) {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
systemTags2.push("protected");
|
|
913
|
+
if (!systemTags.includes("protected")) {
|
|
914
|
+
systemTags.push("protected");
|
|
664
915
|
}
|
|
665
|
-
|
|
666
|
-
|
|
916
|
+
systemTags = systemTags.filter((t) => t !== "LLMWrite");
|
|
917
|
+
if (!systemTags.includes("readonly")) {
|
|
918
|
+
systemTags.push("readonly");
|
|
667
919
|
}
|
|
668
|
-
|
|
669
|
-
finalAttributes.systemTags = systemTags2;
|
|
920
|
+
systemTags = systemTags.filter((t) => t !== "template");
|
|
670
921
|
}
|
|
671
|
-
let systemTags = finalAttributes.systemTags || [];
|
|
672
922
|
if (wasHardcoded && !systemTags.includes("protected")) {
|
|
673
|
-
systemTags
|
|
923
|
+
systemTags.push("protected");
|
|
674
924
|
}
|
|
675
925
|
if (systemTags.includes("protected")) {
|
|
926
|
+
systemTags = systemTags.filter((t) => t !== "LLMWrite");
|
|
676
927
|
if (!systemTags.includes("readonly")) {
|
|
677
|
-
systemTags
|
|
928
|
+
systemTags.push("readonly");
|
|
678
929
|
}
|
|
679
930
|
systemTags = systemTags.filter((t) => t !== "template");
|
|
680
|
-
finalAttributes.systemTags = systemTags;
|
|
681
931
|
}
|
|
682
|
-
finalAttributes.
|
|
683
|
-
finalAttributes.
|
|
932
|
+
finalAttributes.systemTags = systemTags;
|
|
933
|
+
finalAttributes.readonly = systemTags.includes("readonly") || !systemTags.includes("LLMWrite");
|
|
934
|
+
finalAttributes.visible = this.hasSystemPrompt(systemTags);
|
|
684
935
|
finalAttributes.hardcoded = wasHardcoded || systemTags.includes("protected");
|
|
685
|
-
finalAttributes.template = systemTags.includes("template");
|
|
936
|
+
finalAttributes.template = systemTags.includes("ApplyTemplate") || systemTags.includes("template");
|
|
686
937
|
if (attributes && "tags" in attributes && attributes.tags) {
|
|
687
938
|
finalAttributes.contentTags = [...attributes.tags];
|
|
688
939
|
}
|
|
@@ -703,21 +954,25 @@ var MindCache = class {
|
|
|
703
954
|
return;
|
|
704
955
|
}
|
|
705
956
|
this._isRemoteUpdate = true;
|
|
706
|
-
|
|
707
|
-
if (!attributes.systemTags) {
|
|
957
|
+
let systemTags = attributes.systemTags || [];
|
|
958
|
+
if (!attributes.systemTags || systemTags.length === 0) {
|
|
959
|
+
systemTags = [];
|
|
708
960
|
if (attributes.visible !== false) {
|
|
709
961
|
systemTags.push("prompt");
|
|
710
962
|
}
|
|
711
963
|
if (attributes.readonly) {
|
|
712
964
|
systemTags.push("readonly");
|
|
965
|
+
} else {
|
|
966
|
+
systemTags.push("LLMWrite");
|
|
713
967
|
}
|
|
714
968
|
if (attributes.hardcoded) {
|
|
715
969
|
systemTags.push("protected");
|
|
716
970
|
}
|
|
717
971
|
if (attributes.template) {
|
|
718
|
-
systemTags.push("
|
|
972
|
+
systemTags.push("ApplyTemplate");
|
|
719
973
|
}
|
|
720
974
|
}
|
|
975
|
+
systemTags = this.normalizeSystemTags(systemTags);
|
|
721
976
|
const contentTags = attributes.contentTags || attributes.tags || [];
|
|
722
977
|
this.stm[key] = {
|
|
723
978
|
value,
|
|
@@ -727,10 +982,11 @@ var MindCache = class {
|
|
|
727
982
|
systemTags,
|
|
728
983
|
zIndex: attributes.zIndex ?? 0,
|
|
729
984
|
tags: contentTags,
|
|
730
|
-
|
|
731
|
-
|
|
985
|
+
// Sync legacy attributes FROM normalized systemTags
|
|
986
|
+
readonly: systemTags.includes("readonly") || !systemTags.includes("LLMWrite"),
|
|
987
|
+
visible: this.hasSystemPrompt(systemTags),
|
|
732
988
|
hardcoded: systemTags.includes("protected"),
|
|
733
|
-
template: systemTags.includes("template")
|
|
989
|
+
template: systemTags.includes("ApplyTemplate") || systemTags.includes("template")
|
|
734
990
|
}
|
|
735
991
|
};
|
|
736
992
|
if (this.listeners[key]) {
|
|
@@ -785,39 +1041,55 @@ var MindCache = class {
|
|
|
785
1041
|
}
|
|
786
1042
|
}
|
|
787
1043
|
entry.attributes = { ...entry.attributes, ...allowedAttributes };
|
|
788
|
-
if ("readonly" in attributes || "visible" in attributes || "template" in attributes) {
|
|
789
|
-
let newSystemTags = [];
|
|
790
|
-
if (
|
|
791
|
-
newSystemTags.
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
1044
|
+
if ("readonly" in attributes || "visible" in attributes || "template" in attributes || "systemTags" in attributes) {
|
|
1045
|
+
let newSystemTags = entry.attributes.systemTags || [];
|
|
1046
|
+
if ("systemTags" in attributes && Array.isArray(attributes.systemTags)) {
|
|
1047
|
+
newSystemTags = this.normalizeSystemTags(attributes.systemTags);
|
|
1048
|
+
} else {
|
|
1049
|
+
newSystemTags = [];
|
|
1050
|
+
if (!entry.attributes.readonly) {
|
|
1051
|
+
newSystemTags.push("LLMWrite");
|
|
1052
|
+
} else {
|
|
1053
|
+
newSystemTags.push("readonly");
|
|
1054
|
+
}
|
|
1055
|
+
if (entry.attributes.visible) {
|
|
1056
|
+
newSystemTags.push("SystemPrompt");
|
|
1057
|
+
}
|
|
1058
|
+
if (entry.attributes.template) {
|
|
1059
|
+
newSystemTags.push("ApplyTemplate");
|
|
1060
|
+
}
|
|
1061
|
+
if (wasHardcoded || entry.attributes.hardcoded) {
|
|
1062
|
+
newSystemTags.push("protected");
|
|
1063
|
+
}
|
|
1064
|
+
newSystemTags = this.normalizeSystemTags(newSystemTags);
|
|
801
1065
|
}
|
|
802
1066
|
if (newSystemTags.includes("protected")) {
|
|
1067
|
+
newSystemTags = newSystemTags.filter((t) => t !== "LLMWrite");
|
|
803
1068
|
if (!newSystemTags.includes("readonly")) {
|
|
804
1069
|
newSystemTags.push("readonly");
|
|
805
1070
|
}
|
|
806
|
-
newSystemTags = newSystemTags.filter((t) => t !== "template");
|
|
1071
|
+
newSystemTags = newSystemTags.filter((t) => t !== "ApplyTemplate" && t !== "template");
|
|
807
1072
|
entry.attributes.readonly = true;
|
|
808
1073
|
entry.attributes.template = false;
|
|
809
1074
|
}
|
|
810
1075
|
entry.attributes.systemTags = newSystemTags;
|
|
1076
|
+
entry.attributes.readonly = newSystemTags.includes("readonly") || !newSystemTags.includes("LLMWrite");
|
|
1077
|
+
entry.attributes.visible = this.hasSystemPrompt(newSystemTags);
|
|
1078
|
+
entry.attributes.template = newSystemTags.includes("ApplyTemplate") || newSystemTags.includes("template");
|
|
811
1079
|
} else if (wasHardcoded) {
|
|
812
|
-
let systemTags =
|
|
1080
|
+
let systemTags = this.normalizeSystemTags(entry.attributes.systemTags || []);
|
|
813
1081
|
if (!systemTags.includes("protected")) {
|
|
814
1082
|
systemTags.push("protected");
|
|
815
1083
|
}
|
|
1084
|
+
systemTags = systemTags.filter((t) => t !== "LLMWrite");
|
|
816
1085
|
if (!systemTags.includes("readonly")) {
|
|
817
1086
|
systemTags.push("readonly");
|
|
818
1087
|
}
|
|
819
|
-
systemTags = systemTags.filter((t) => t !== "template");
|
|
1088
|
+
systemTags = systemTags.filter((t) => t !== "ApplyTemplate" && t !== "template");
|
|
820
1089
|
entry.attributes.systemTags = systemTags;
|
|
1090
|
+
entry.attributes.readonly = true;
|
|
1091
|
+
entry.attributes.visible = this.hasSystemPrompt(systemTags);
|
|
1092
|
+
entry.attributes.template = false;
|
|
821
1093
|
}
|
|
822
1094
|
if (wasHardcoded) {
|
|
823
1095
|
entry.attributes.hardcoded = true;
|
|
@@ -1059,8 +1331,9 @@ var MindCache = class {
|
|
|
1059
1331
|
const sortedKeys = this.getSortedKeys();
|
|
1060
1332
|
sortedKeys.forEach((key) => {
|
|
1061
1333
|
const entry = this.stm[key];
|
|
1062
|
-
if (entry.attributes.visible) {
|
|
1063
|
-
const
|
|
1334
|
+
if (this.hasLLMRead(entry.attributes.systemTags) || entry.attributes.visible) {
|
|
1335
|
+
const hasTemplate = entry.attributes.systemTags?.includes("ApplyTemplate") || entry.attributes.systemTags?.includes("template") || entry.attributes.template;
|
|
1336
|
+
const processedValue = hasTemplate ? this.get_value(key) : entry.value;
|
|
1064
1337
|
apiData.push({
|
|
1065
1338
|
key,
|
|
1066
1339
|
value: processedValue,
|
|
@@ -1086,7 +1359,7 @@ var MindCache = class {
|
|
|
1086
1359
|
const sortedKeys = this.getSortedKeys();
|
|
1087
1360
|
sortedKeys.forEach((key) => {
|
|
1088
1361
|
const entry = this.stm[key];
|
|
1089
|
-
if (entry.attributes.visible && entry.attributes.type === "image" && entry.attributes.contentType) {
|
|
1362
|
+
if ((this.hasLLMRead(entry.attributes.systemTags) || entry.attributes.visible) && entry.attributes.type === "image" && entry.attributes.contentType) {
|
|
1090
1363
|
const dataUrl = this.createDataUrl(entry.value, entry.attributes.contentType);
|
|
1091
1364
|
imageParts.push({
|
|
1092
1365
|
type: "file",
|
|
@@ -1125,6 +1398,7 @@ var MindCache = class {
|
|
|
1125
1398
|
}
|
|
1126
1399
|
deserialize(data) {
|
|
1127
1400
|
if (typeof data === "object" && data !== null) {
|
|
1401
|
+
this._isRemoteUpdate = true;
|
|
1128
1402
|
this.clear();
|
|
1129
1403
|
Object.entries(data).forEach(([key, entry]) => {
|
|
1130
1404
|
if (entry && typeof entry === "object" && "value" in entry && "attributes" in entry) {
|
|
@@ -1133,21 +1407,24 @@ var MindCache = class {
|
|
|
1133
1407
|
return;
|
|
1134
1408
|
}
|
|
1135
1409
|
let systemTags = attrs.systemTags || [];
|
|
1136
|
-
if (!attrs.systemTags) {
|
|
1410
|
+
if (!attrs.systemTags || systemTags.length === 0) {
|
|
1137
1411
|
systemTags = [];
|
|
1138
1412
|
if (attrs.visible !== false) {
|
|
1139
1413
|
systemTags.push("prompt");
|
|
1140
1414
|
}
|
|
1141
1415
|
if (attrs.readonly) {
|
|
1142
1416
|
systemTags.push("readonly");
|
|
1417
|
+
} else {
|
|
1418
|
+
systemTags.push("LLMWrite");
|
|
1143
1419
|
}
|
|
1144
1420
|
if (attrs.hardcoded) {
|
|
1145
1421
|
systemTags.push("protected");
|
|
1146
1422
|
}
|
|
1147
1423
|
if (attrs.template) {
|
|
1148
|
-
systemTags.push("
|
|
1424
|
+
systemTags.push("ApplyTemplate");
|
|
1149
1425
|
}
|
|
1150
1426
|
}
|
|
1427
|
+
systemTags = this.normalizeSystemTags(systemTags);
|
|
1151
1428
|
const contentTags = attrs.contentTags || attrs.tags || [];
|
|
1152
1429
|
this.stm[key] = {
|
|
1153
1430
|
value: entry.value,
|
|
@@ -1156,17 +1433,18 @@ var MindCache = class {
|
|
|
1156
1433
|
contentTags,
|
|
1157
1434
|
systemTags,
|
|
1158
1435
|
zIndex: attrs.zIndex ?? 0,
|
|
1159
|
-
// Sync legacy attributes
|
|
1436
|
+
// Sync legacy attributes FROM normalized systemTags
|
|
1160
1437
|
tags: contentTags,
|
|
1161
|
-
readonly: systemTags.includes("readonly"),
|
|
1162
|
-
visible:
|
|
1438
|
+
readonly: systemTags.includes("readonly") || !systemTags.includes("LLMWrite"),
|
|
1439
|
+
visible: this.hasSystemPrompt(systemTags),
|
|
1163
1440
|
hardcoded: systemTags.includes("protected"),
|
|
1164
|
-
template: systemTags.includes("template")
|
|
1441
|
+
template: systemTags.includes("ApplyTemplate") || systemTags.includes("template")
|
|
1165
1442
|
}
|
|
1166
1443
|
};
|
|
1167
1444
|
}
|
|
1168
1445
|
});
|
|
1169
1446
|
this.notifyGlobalListeners();
|
|
1447
|
+
this._isRemoteUpdate = false;
|
|
1170
1448
|
}
|
|
1171
1449
|
}
|
|
1172
1450
|
get_system_prompt() {
|
|
@@ -1175,13 +1453,14 @@ var MindCache = class {
|
|
|
1175
1453
|
const sortedKeys = this.getSortedKeys();
|
|
1176
1454
|
sortedKeys.forEach((key) => {
|
|
1177
1455
|
const entry = this.stm[key];
|
|
1178
|
-
if (entry.attributes.visible) {
|
|
1456
|
+
if (this.hasLLMRead(entry.attributes.systemTags) || entry.attributes.visible) {
|
|
1179
1457
|
if (entry.attributes.type === "image") {
|
|
1180
1458
|
promptLines.push(`image ${key} available`);
|
|
1181
1459
|
return;
|
|
1182
1460
|
}
|
|
1183
1461
|
if (entry.attributes.type === "file") {
|
|
1184
|
-
|
|
1462
|
+
const canWrite2 = this.hasLLMWrite(entry.attributes.systemTags) || !entry.attributes.readonly && !entry.attributes.systemTags.includes("readonly");
|
|
1463
|
+
if (!canWrite2) {
|
|
1185
1464
|
promptLines.push(`${key}: [${entry.attributes.type.toUpperCase()}] - ${entry.attributes.contentType || "unknown format"}`);
|
|
1186
1465
|
} else {
|
|
1187
1466
|
const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -1191,7 +1470,8 @@ var MindCache = class {
|
|
|
1191
1470
|
}
|
|
1192
1471
|
const value = this.get_value(key);
|
|
1193
1472
|
const formattedValue = typeof value === "object" && value !== null ? JSON.stringify(value) : String(value);
|
|
1194
|
-
|
|
1473
|
+
const canWrite = this.hasLLMWrite(entry.attributes.systemTags) || !entry.attributes.readonly && !entry.attributes.systemTags.includes("readonly");
|
|
1474
|
+
if (!canWrite) {
|
|
1195
1475
|
promptLines.push(`${key}: ${formattedValue}`);
|
|
1196
1476
|
} else {
|
|
1197
1477
|
const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -1219,7 +1499,7 @@ var MindCache = class {
|
|
|
1219
1499
|
const sortedKeys = this.getSortedKeys();
|
|
1220
1500
|
const writableKeys = sortedKeys.filter((key) => {
|
|
1221
1501
|
const entry = this.stm[key];
|
|
1222
|
-
return !entry.attributes.readonly;
|
|
1502
|
+
return this.hasLLMWrite(entry.attributes.systemTags) || !entry.attributes.readonly && !entry.attributes.systemTags.includes("readonly");
|
|
1223
1503
|
});
|
|
1224
1504
|
writableKeys.forEach((key) => {
|
|
1225
1505
|
const sanitizedKey = key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
@@ -1294,7 +1574,8 @@ var MindCache = class {
|
|
|
1294
1574
|
return null;
|
|
1295
1575
|
}
|
|
1296
1576
|
const entry = this.stm[originalKey];
|
|
1297
|
-
|
|
1577
|
+
const canWrite = entry && (this.hasLLMWrite(entry.attributes.systemTags) || !entry.attributes.readonly && !entry.attributes.systemTags.includes("readonly"));
|
|
1578
|
+
if (!canWrite) {
|
|
1298
1579
|
return null;
|
|
1299
1580
|
}
|
|
1300
1581
|
this.set_value(originalKey, value);
|
|
@@ -1541,7 +1822,7 @@ var MindCache = class {
|
|
|
1541
1822
|
entry.attributes.readonly = tags.includes("readonly");
|
|
1542
1823
|
entry.attributes.visible = tags.includes("prompt");
|
|
1543
1824
|
entry.attributes.hardcoded = tags.includes("protected");
|
|
1544
|
-
entry.attributes.template = tags.includes("template");
|
|
1825
|
+
entry.attributes.template = tags.includes("ApplyTemplate") || tags.includes("template");
|
|
1545
1826
|
}
|
|
1546
1827
|
toMarkdown() {
|
|
1547
1828
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -1782,6 +2063,8 @@ var MindCache = class {
|
|
|
1782
2063
|
}
|
|
1783
2064
|
if (attrs.readonly) {
|
|
1784
2065
|
systemTags.push("readonly");
|
|
2066
|
+
} else {
|
|
2067
|
+
systemTags.push("LLMWrite");
|
|
1785
2068
|
}
|
|
1786
2069
|
if (attrs.hardcoded) {
|
|
1787
2070
|
systemTags.push("protected");
|
|
@@ -1789,7 +2072,9 @@ var MindCache = class {
|
|
|
1789
2072
|
if (attrs.template) {
|
|
1790
2073
|
systemTags.push("template");
|
|
1791
2074
|
}
|
|
1792
|
-
attrs.systemTags = systemTags;
|
|
2075
|
+
attrs.systemTags = this.normalizeSystemTags(systemTags);
|
|
2076
|
+
} else {
|
|
2077
|
+
attrs.systemTags = this.normalizeSystemTags(attrs.systemTags);
|
|
1793
2078
|
}
|
|
1794
2079
|
if (!attrs.contentTags) {
|
|
1795
2080
|
attrs.contentTags = [];
|
|
@@ -1797,6 +2082,11 @@ var MindCache = class {
|
|
|
1797
2082
|
if (!attrs.tags) {
|
|
1798
2083
|
attrs.tags = [...attrs.contentTags];
|
|
1799
2084
|
}
|
|
2085
|
+
const normalizedTags = attrs.systemTags || [];
|
|
2086
|
+
attrs.readonly = normalizedTags.includes("readonly") || !normalizedTags.includes("LLMWrite");
|
|
2087
|
+
attrs.visible = this.hasSystemPrompt(normalizedTags);
|
|
2088
|
+
attrs.hardcoded = normalizedTags.includes("protected");
|
|
2089
|
+
attrs.template = normalizedTags.includes("ApplyTemplate") || normalizedTags.includes("template");
|
|
1800
2090
|
this.stm[key] = {
|
|
1801
2091
|
value: entry.value,
|
|
1802
2092
|
attributes: attrs
|
|
@@ -1812,8 +2102,46 @@ var mindcache = new MindCache();
|
|
|
1812
2102
|
init_CloudAdapter();
|
|
1813
2103
|
init_CloudAdapter();
|
|
1814
2104
|
|
|
2105
|
+
// src/local/index.ts
|
|
2106
|
+
init_IndexedDBAdapter();
|
|
2107
|
+
function useMindCache(options) {
|
|
2108
|
+
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
2109
|
+
const [error, setError] = react.useState(null);
|
|
2110
|
+
const mindcacheRef = react.useRef(null);
|
|
2111
|
+
const initializingRef = react.useRef(false);
|
|
2112
|
+
react.useEffect(() => {
|
|
2113
|
+
if (initializingRef.current) {
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
initializingRef.current = true;
|
|
2117
|
+
const initialize = async () => {
|
|
2118
|
+
try {
|
|
2119
|
+
const mc = new MindCache(options);
|
|
2120
|
+
mindcacheRef.current = mc;
|
|
2121
|
+
await mc.waitForSync();
|
|
2122
|
+
setIsLoaded(true);
|
|
2123
|
+
} catch (err) {
|
|
2124
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
2125
|
+
setIsLoaded(true);
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
initialize();
|
|
2129
|
+
return () => {
|
|
2130
|
+
if (mindcacheRef.current) {
|
|
2131
|
+
mindcacheRef.current.disconnect();
|
|
2132
|
+
}
|
|
2133
|
+
};
|
|
2134
|
+
}, []);
|
|
2135
|
+
return {
|
|
2136
|
+
mindcache: mindcacheRef.current,
|
|
2137
|
+
isLoaded,
|
|
2138
|
+
error
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
|
|
1815
2142
|
exports.DEFAULT_KEY_ATTRIBUTES = DEFAULT_KEY_ATTRIBUTES;
|
|
1816
2143
|
exports.MindCache = MindCache;
|
|
1817
2144
|
exports.mindcache = mindcache;
|
|
2145
|
+
exports.useMindCache = useMindCache;
|
|
1818
2146
|
//# sourceMappingURL=index.js.map
|
|
1819
2147
|
//# sourceMappingURL=index.js.map
|