mindcache 3.2.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.
- package/dist/{CloudAdapter-BcKF4Yaf.d.mts → CloudAdapter-CSncOr3V.d.mts} +161 -4
- package/dist/{CloudAdapter-BcKF4Yaf.d.ts → CloudAdapter-CSncOr3V.d.ts} +161 -4
- package/dist/cloud/index.d.mts +2 -2
- package/dist/cloud/index.d.ts +2 -2
- package/dist/cloud/index.js +695 -12
- package/dist/cloud/index.js.map +1 -1
- package/dist/cloud/index.mjs +695 -12
- package/dist/cloud/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +699 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +699 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/cloud/index.mjs
CHANGED
|
@@ -800,18 +800,35 @@ var MindCache = class {
|
|
|
800
800
|
}
|
|
801
801
|
// Deserialize state (for IndexedDBAdapter compatibility)
|
|
802
802
|
deserialize(data) {
|
|
803
|
+
if (!data || typeof data !== "object") {
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
803
806
|
this.doc.transact(() => {
|
|
807
|
+
for (const key of this.rootMap.keys()) {
|
|
808
|
+
this.rootMap.delete(key);
|
|
809
|
+
}
|
|
804
810
|
for (const [key, entry] of Object.entries(data)) {
|
|
805
811
|
if (key.startsWith("$")) {
|
|
806
812
|
continue;
|
|
807
813
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
entryMap = new Y.Map();
|
|
811
|
-
this.rootMap.set(key, entryMap);
|
|
812
|
-
}
|
|
814
|
+
const entryMap = new Y.Map();
|
|
815
|
+
this.rootMap.set(key, entryMap);
|
|
813
816
|
entryMap.set("value", entry.value);
|
|
814
|
-
|
|
817
|
+
const attrs = entry.attributes || {};
|
|
818
|
+
const normalizedAttrs = {
|
|
819
|
+
type: attrs.type || "text",
|
|
820
|
+
contentTags: attrs.contentTags || [],
|
|
821
|
+
systemTags: attrs.systemTags || this.normalizeSystemTags(attrs.visible !== false ? ["prompt"] : []),
|
|
822
|
+
zIndex: attrs.zIndex ?? 0,
|
|
823
|
+
// Legacy fields
|
|
824
|
+
readonly: attrs.readonly ?? false,
|
|
825
|
+
visible: attrs.visible ?? true,
|
|
826
|
+
hardcoded: attrs.hardcoded ?? false,
|
|
827
|
+
template: attrs.template ?? false,
|
|
828
|
+
tags: attrs.tags || [],
|
|
829
|
+
contentType: attrs.contentType
|
|
830
|
+
};
|
|
831
|
+
entryMap.set("attributes", normalizedAttrs);
|
|
815
832
|
}
|
|
816
833
|
});
|
|
817
834
|
}
|
|
@@ -849,16 +866,46 @@ var MindCache = class {
|
|
|
849
866
|
}
|
|
850
867
|
return false;
|
|
851
868
|
}
|
|
852
|
-
// InjectSTM replacement
|
|
853
|
-
|
|
869
|
+
// InjectSTM replacement (private helper)
|
|
870
|
+
_injectSTMInternal(template, _processingStack) {
|
|
854
871
|
return template.replace(/\{\{([^}]+)\}\}/g, (_, key) => {
|
|
855
872
|
const val = this.get_value(key.trim(), _processingStack);
|
|
856
873
|
return val !== void 0 ? String(val) : `{{${key}}}`;
|
|
857
874
|
});
|
|
858
875
|
}
|
|
876
|
+
/**
|
|
877
|
+
* Replace {{key}} placeholders in a template string with values from MindCache.
|
|
878
|
+
* @param template The template string with {{key}} placeholders
|
|
879
|
+
* @returns The template with placeholders replaced by values
|
|
880
|
+
*/
|
|
881
|
+
injectSTM(template) {
|
|
882
|
+
return this._injectSTMInternal(template, /* @__PURE__ */ new Set());
|
|
883
|
+
}
|
|
859
884
|
// Public API Methods
|
|
860
885
|
getAll() {
|
|
861
|
-
|
|
886
|
+
const result = {};
|
|
887
|
+
for (const [key] of this.rootMap) {
|
|
888
|
+
result[key] = this.get_value(key);
|
|
889
|
+
}
|
|
890
|
+
result["$date"] = this.get_value("$date");
|
|
891
|
+
result["$time"] = this.get_value("$time");
|
|
892
|
+
return result;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Get all entries with their full structure (value + attributes).
|
|
896
|
+
* Use this for UI/admin interfaces that need to display key properties.
|
|
897
|
+
* Unlike serialize(), this format is stable and won't change.
|
|
898
|
+
*/
|
|
899
|
+
getAllEntries() {
|
|
900
|
+
const result = {};
|
|
901
|
+
for (const [key] of this.rootMap) {
|
|
902
|
+
const value = this.get_value(key);
|
|
903
|
+
const attributes = this.get_attributes(key);
|
|
904
|
+
if (attributes) {
|
|
905
|
+
result[key] = { value, attributes };
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return result;
|
|
862
909
|
}
|
|
863
910
|
get_value(key, _processingStack) {
|
|
864
911
|
if (key === "$date") {
|
|
@@ -888,7 +935,7 @@ var MindCache = class {
|
|
|
888
935
|
if (typeof value === "string") {
|
|
889
936
|
const stack = _processingStack || /* @__PURE__ */ new Set();
|
|
890
937
|
stack.add(key);
|
|
891
|
-
return this.
|
|
938
|
+
return this._injectSTMInternal(value, stack);
|
|
892
939
|
}
|
|
893
940
|
}
|
|
894
941
|
return value;
|
|
@@ -986,6 +1033,638 @@ var MindCache = class {
|
|
|
986
1033
|
keys.forEach((k) => this.rootMap.delete(k));
|
|
987
1034
|
});
|
|
988
1035
|
}
|
|
1036
|
+
// ============================================
|
|
1037
|
+
// Restored Methods (from v2.x)
|
|
1038
|
+
// ============================================
|
|
1039
|
+
/**
|
|
1040
|
+
* Check if a key exists in MindCache.
|
|
1041
|
+
*/
|
|
1042
|
+
has(key) {
|
|
1043
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
return this.rootMap.has(key);
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Delete a key from MindCache.
|
|
1050
|
+
* @returns true if the key existed and was deleted
|
|
1051
|
+
*/
|
|
1052
|
+
delete(key) {
|
|
1053
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1054
|
+
return false;
|
|
1055
|
+
}
|
|
1056
|
+
if (!this.rootMap.has(key)) {
|
|
1057
|
+
return false;
|
|
1058
|
+
}
|
|
1059
|
+
this.rootMap.delete(key);
|
|
1060
|
+
this.notifyGlobalListeners();
|
|
1061
|
+
if (this.listeners[key]) {
|
|
1062
|
+
this.listeners[key].forEach((listener) => listener(void 0));
|
|
1063
|
+
}
|
|
1064
|
+
return true;
|
|
1065
|
+
}
|
|
1066
|
+
/** @deprecated Use get_value instead */
|
|
1067
|
+
get(key) {
|
|
1068
|
+
return this.get_value(key);
|
|
1069
|
+
}
|
|
1070
|
+
/** @deprecated Use set_value instead */
|
|
1071
|
+
set(key, value) {
|
|
1072
|
+
this.set_value(key, value);
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Update multiple values at once from an object.
|
|
1076
|
+
* @deprecated Use set_value for individual keys
|
|
1077
|
+
*/
|
|
1078
|
+
update(data) {
|
|
1079
|
+
this.doc.transact(() => {
|
|
1080
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1081
|
+
if (key !== "$date" && key !== "$time" && key !== "$version") {
|
|
1082
|
+
this.set_value(key, value);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
this.notifyGlobalListeners();
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Get the number of keys in MindCache.
|
|
1090
|
+
*/
|
|
1091
|
+
size() {
|
|
1092
|
+
return this.rootMap.size + 2;
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Get all keys in MindCache (including temporal keys).
|
|
1096
|
+
*/
|
|
1097
|
+
keys() {
|
|
1098
|
+
const keys = Array.from(this.rootMap.keys());
|
|
1099
|
+
keys.push("$date", "$time");
|
|
1100
|
+
return keys;
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Get all values in MindCache (including temporal values).
|
|
1104
|
+
*/
|
|
1105
|
+
values() {
|
|
1106
|
+
const result = [];
|
|
1107
|
+
for (const [key] of this.rootMap) {
|
|
1108
|
+
result.push(this.get_value(key));
|
|
1109
|
+
}
|
|
1110
|
+
result.push(this.get_value("$date"));
|
|
1111
|
+
result.push(this.get_value("$time"));
|
|
1112
|
+
return result;
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Get all key-value entries (including temporal entries).
|
|
1116
|
+
*/
|
|
1117
|
+
entries() {
|
|
1118
|
+
const result = [];
|
|
1119
|
+
for (const [key] of this.rootMap) {
|
|
1120
|
+
result.push([key, this.get_value(key)]);
|
|
1121
|
+
}
|
|
1122
|
+
result.push(["$date", this.get_value("$date")]);
|
|
1123
|
+
result.push(["$time", this.get_value("$time")]);
|
|
1124
|
+
return result;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Unsubscribe from key changes.
|
|
1128
|
+
* @deprecated Use the cleanup function returned by subscribe() instead
|
|
1129
|
+
*/
|
|
1130
|
+
unsubscribe(key, listener) {
|
|
1131
|
+
if (this.listeners[key]) {
|
|
1132
|
+
this.listeners[key] = this.listeners[key].filter((l) => l !== listener);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Get the STM as a formatted string for LLM context.
|
|
1137
|
+
* @deprecated Use get_system_prompt() instead
|
|
1138
|
+
*/
|
|
1139
|
+
getSTM() {
|
|
1140
|
+
return this.get_system_prompt();
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Get the STM as an object with values directly (no attributes).
|
|
1144
|
+
* Includes system keys ($date, $time).
|
|
1145
|
+
* @deprecated Use getAll() for full STM format
|
|
1146
|
+
*/
|
|
1147
|
+
getSTMObject() {
|
|
1148
|
+
const result = {};
|
|
1149
|
+
for (const [key] of this.rootMap) {
|
|
1150
|
+
result[key] = this.get_value(key);
|
|
1151
|
+
}
|
|
1152
|
+
result["$date"] = this.get_value("$date");
|
|
1153
|
+
result["$time"] = this.get_value("$time");
|
|
1154
|
+
return result;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Add a content tag to a key.
|
|
1158
|
+
* @returns true if the tag was added, false if key doesn't exist or tag already exists
|
|
1159
|
+
*/
|
|
1160
|
+
addTag(key, tag) {
|
|
1161
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1162
|
+
return false;
|
|
1163
|
+
}
|
|
1164
|
+
const entryMap = this.rootMap.get(key);
|
|
1165
|
+
if (!entryMap) {
|
|
1166
|
+
return false;
|
|
1167
|
+
}
|
|
1168
|
+
const attributes = entryMap.get("attributes");
|
|
1169
|
+
const contentTags = attributes?.contentTags || [];
|
|
1170
|
+
if (contentTags.includes(tag)) {
|
|
1171
|
+
return false;
|
|
1172
|
+
}
|
|
1173
|
+
this.doc.transact(() => {
|
|
1174
|
+
const newContentTags = [...contentTags, tag];
|
|
1175
|
+
entryMap.set("attributes", {
|
|
1176
|
+
...attributes,
|
|
1177
|
+
contentTags: newContentTags,
|
|
1178
|
+
tags: newContentTags
|
|
1179
|
+
// Sync legacy tags array
|
|
1180
|
+
});
|
|
1181
|
+
});
|
|
1182
|
+
this.notifyGlobalListeners();
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Remove a content tag from a key.
|
|
1187
|
+
* @returns true if the tag was removed
|
|
1188
|
+
*/
|
|
1189
|
+
removeTag(key, tag) {
|
|
1190
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1191
|
+
return false;
|
|
1192
|
+
}
|
|
1193
|
+
const entryMap = this.rootMap.get(key);
|
|
1194
|
+
if (!entryMap) {
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
const attributes = entryMap.get("attributes");
|
|
1198
|
+
const contentTags = attributes?.contentTags || [];
|
|
1199
|
+
const tagIndex = contentTags.indexOf(tag);
|
|
1200
|
+
if (tagIndex === -1) {
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
this.doc.transact(() => {
|
|
1204
|
+
const newContentTags = contentTags.filter((t) => t !== tag);
|
|
1205
|
+
entryMap.set("attributes", {
|
|
1206
|
+
...attributes,
|
|
1207
|
+
contentTags: newContentTags,
|
|
1208
|
+
tags: newContentTags
|
|
1209
|
+
// Sync legacy tags array
|
|
1210
|
+
});
|
|
1211
|
+
});
|
|
1212
|
+
this.notifyGlobalListeners();
|
|
1213
|
+
return true;
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Get all content tags for a key.
|
|
1217
|
+
*/
|
|
1218
|
+
getTags(key) {
|
|
1219
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1220
|
+
return [];
|
|
1221
|
+
}
|
|
1222
|
+
const entryMap = this.rootMap.get(key);
|
|
1223
|
+
if (!entryMap) {
|
|
1224
|
+
return [];
|
|
1225
|
+
}
|
|
1226
|
+
const attributes = entryMap.get("attributes");
|
|
1227
|
+
return attributes?.contentTags || [];
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Get all unique content tags across all keys.
|
|
1231
|
+
*/
|
|
1232
|
+
getAllTags() {
|
|
1233
|
+
const allTags = /* @__PURE__ */ new Set();
|
|
1234
|
+
for (const [, val] of this.rootMap) {
|
|
1235
|
+
const entryMap = val;
|
|
1236
|
+
const attributes = entryMap.get("attributes");
|
|
1237
|
+
if (attributes?.contentTags) {
|
|
1238
|
+
attributes.contentTags.forEach((tag) => allTags.add(tag));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
return Array.from(allTags);
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Check if a key has a specific content tag.
|
|
1245
|
+
*/
|
|
1246
|
+
hasTag(key, tag) {
|
|
1247
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
const entryMap = this.rootMap.get(key);
|
|
1251
|
+
if (!entryMap) {
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
const attributes = entryMap.get("attributes");
|
|
1255
|
+
return attributes?.contentTags?.includes(tag) || false;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* Get all keys with a specific content tag as formatted string.
|
|
1259
|
+
*/
|
|
1260
|
+
getTagged(tag) {
|
|
1261
|
+
const entries = [];
|
|
1262
|
+
const keys = this.getSortedKeys();
|
|
1263
|
+
keys.forEach((key) => {
|
|
1264
|
+
if (this.hasTag(key, tag)) {
|
|
1265
|
+
entries.push([key, this.get_value(key)]);
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
return entries.map(([key, value]) => `${key}: ${value}`).join(", ");
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Get array of keys with a specific content tag.
|
|
1272
|
+
*/
|
|
1273
|
+
getKeysByTag(tag) {
|
|
1274
|
+
const keys = this.getSortedKeys();
|
|
1275
|
+
return keys.filter((key) => this.hasTag(key, tag));
|
|
1276
|
+
}
|
|
1277
|
+
// ============================================
|
|
1278
|
+
// System Tag Methods (requires system access level)
|
|
1279
|
+
// ============================================
|
|
1280
|
+
/**
|
|
1281
|
+
* Add a system tag to a key (requires system access).
|
|
1282
|
+
* System tags: 'SystemPrompt', 'LLMRead', 'LLMWrite', 'readonly', 'protected', 'ApplyTemplate'
|
|
1283
|
+
*/
|
|
1284
|
+
systemAddTag(key, tag) {
|
|
1285
|
+
if (!this.hasSystemAccess) {
|
|
1286
|
+
console.warn("MindCache: systemAddTag requires system access level");
|
|
1287
|
+
return false;
|
|
1288
|
+
}
|
|
1289
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1290
|
+
return false;
|
|
1291
|
+
}
|
|
1292
|
+
const entryMap = this.rootMap.get(key);
|
|
1293
|
+
if (!entryMap) {
|
|
1294
|
+
return false;
|
|
1295
|
+
}
|
|
1296
|
+
const attributes = entryMap.get("attributes");
|
|
1297
|
+
const systemTags = attributes?.systemTags || [];
|
|
1298
|
+
if (systemTags.includes(tag)) {
|
|
1299
|
+
return false;
|
|
1300
|
+
}
|
|
1301
|
+
this.doc.transact(() => {
|
|
1302
|
+
const newSystemTags = [...systemTags, tag];
|
|
1303
|
+
const normalizedTags = this.normalizeSystemTags(newSystemTags);
|
|
1304
|
+
entryMap.set("attributes", {
|
|
1305
|
+
...attributes,
|
|
1306
|
+
systemTags: normalizedTags
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
this.notifyGlobalListeners();
|
|
1310
|
+
return true;
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Remove a system tag from a key (requires system access).
|
|
1314
|
+
*/
|
|
1315
|
+
systemRemoveTag(key, tag) {
|
|
1316
|
+
if (!this.hasSystemAccess) {
|
|
1317
|
+
console.warn("MindCache: systemRemoveTag requires system access level");
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1320
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1321
|
+
return false;
|
|
1322
|
+
}
|
|
1323
|
+
const entryMap = this.rootMap.get(key);
|
|
1324
|
+
if (!entryMap) {
|
|
1325
|
+
return false;
|
|
1326
|
+
}
|
|
1327
|
+
const attributes = entryMap.get("attributes");
|
|
1328
|
+
const systemTags = attributes?.systemTags || [];
|
|
1329
|
+
const tagIndex = systemTags.indexOf(tag);
|
|
1330
|
+
if (tagIndex === -1) {
|
|
1331
|
+
return false;
|
|
1332
|
+
}
|
|
1333
|
+
this.doc.transact(() => {
|
|
1334
|
+
const newSystemTags = systemTags.filter((t) => t !== tag);
|
|
1335
|
+
entryMap.set("attributes", {
|
|
1336
|
+
...attributes,
|
|
1337
|
+
systemTags: newSystemTags
|
|
1338
|
+
});
|
|
1339
|
+
});
|
|
1340
|
+
this.notifyGlobalListeners();
|
|
1341
|
+
return true;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Get all system tags for a key (requires system access).
|
|
1345
|
+
*/
|
|
1346
|
+
systemGetTags(key) {
|
|
1347
|
+
if (!this.hasSystemAccess) {
|
|
1348
|
+
console.warn("MindCache: systemGetTags requires system access level");
|
|
1349
|
+
return [];
|
|
1350
|
+
}
|
|
1351
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1352
|
+
return [];
|
|
1353
|
+
}
|
|
1354
|
+
const entryMap = this.rootMap.get(key);
|
|
1355
|
+
if (!entryMap) {
|
|
1356
|
+
return [];
|
|
1357
|
+
}
|
|
1358
|
+
const attributes = entryMap.get("attributes");
|
|
1359
|
+
return attributes?.systemTags || [];
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Check if a key has a specific system tag (requires system access).
|
|
1363
|
+
*/
|
|
1364
|
+
systemHasTag(key, tag) {
|
|
1365
|
+
if (!this.hasSystemAccess) {
|
|
1366
|
+
console.warn("MindCache: systemHasTag requires system access level");
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
const entryMap = this.rootMap.get(key);
|
|
1373
|
+
if (!entryMap) {
|
|
1374
|
+
return false;
|
|
1375
|
+
}
|
|
1376
|
+
const attributes = entryMap.get("attributes");
|
|
1377
|
+
return attributes?.systemTags?.includes(tag) || false;
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Set all system tags for a key at once (requires system access).
|
|
1381
|
+
*/
|
|
1382
|
+
systemSetTags(key, tags) {
|
|
1383
|
+
if (!this.hasSystemAccess) {
|
|
1384
|
+
console.warn("MindCache: systemSetTags requires system access level");
|
|
1385
|
+
return false;
|
|
1386
|
+
}
|
|
1387
|
+
if (key === "$date" || key === "$time" || key === "$version") {
|
|
1388
|
+
return false;
|
|
1389
|
+
}
|
|
1390
|
+
const entryMap = this.rootMap.get(key);
|
|
1391
|
+
if (!entryMap) {
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
this.doc.transact(() => {
|
|
1395
|
+
const attributes = entryMap.get("attributes");
|
|
1396
|
+
entryMap.set("attributes", {
|
|
1397
|
+
...attributes,
|
|
1398
|
+
systemTags: [...tags]
|
|
1399
|
+
});
|
|
1400
|
+
});
|
|
1401
|
+
this.notifyGlobalListeners();
|
|
1402
|
+
return true;
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Get all keys with a specific system tag (requires system access).
|
|
1406
|
+
*/
|
|
1407
|
+
systemGetKeysByTag(tag) {
|
|
1408
|
+
if (!this.hasSystemAccess) {
|
|
1409
|
+
console.warn("MindCache: systemGetKeysByTag requires system access level");
|
|
1410
|
+
return [];
|
|
1411
|
+
}
|
|
1412
|
+
const keys = this.getSortedKeys();
|
|
1413
|
+
return keys.filter((key) => this.systemHasTag(key, tag));
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Helper to get sorted keys (by zIndex).
|
|
1417
|
+
*/
|
|
1418
|
+
getSortedKeys() {
|
|
1419
|
+
const entries = [];
|
|
1420
|
+
for (const [key, val] of this.rootMap) {
|
|
1421
|
+
const entryMap = val;
|
|
1422
|
+
const attributes = entryMap.get("attributes");
|
|
1423
|
+
entries.push({ key, zIndex: attributes?.zIndex ?? 0 });
|
|
1424
|
+
}
|
|
1425
|
+
return entries.sort((a, b) => a.zIndex - b.zIndex).map((e) => e.key);
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Serialize to JSON string.
|
|
1429
|
+
*/
|
|
1430
|
+
toJSON() {
|
|
1431
|
+
return JSON.stringify(this.serialize());
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Deserialize from JSON string.
|
|
1435
|
+
*/
|
|
1436
|
+
fromJSON(jsonString) {
|
|
1437
|
+
try {
|
|
1438
|
+
const data = JSON.parse(jsonString);
|
|
1439
|
+
this.deserialize(data);
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
console.error("MindCache: Failed to deserialize JSON:", error);
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Export to Markdown format.
|
|
1446
|
+
*/
|
|
1447
|
+
toMarkdown() {
|
|
1448
|
+
const now = /* @__PURE__ */ new Date();
|
|
1449
|
+
const lines = [];
|
|
1450
|
+
const appendixEntries = [];
|
|
1451
|
+
let appendixCounter = 0;
|
|
1452
|
+
lines.push("# MindCache STM Export");
|
|
1453
|
+
lines.push("");
|
|
1454
|
+
lines.push(`Export Date: ${now.toISOString().split("T")[0]}`);
|
|
1455
|
+
lines.push("");
|
|
1456
|
+
lines.push("---");
|
|
1457
|
+
lines.push("");
|
|
1458
|
+
lines.push("## STM Entries");
|
|
1459
|
+
lines.push("");
|
|
1460
|
+
const sortedKeys = this.getSortedKeys();
|
|
1461
|
+
sortedKeys.forEach((key) => {
|
|
1462
|
+
const entryMap = this.rootMap.get(key);
|
|
1463
|
+
if (!entryMap) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
const attributes = entryMap.get("attributes");
|
|
1467
|
+
const value = entryMap.get("value");
|
|
1468
|
+
if (attributes?.hardcoded) {
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
lines.push(`### ${key}`);
|
|
1472
|
+
const entryType = attributes?.type || "text";
|
|
1473
|
+
lines.push(`- **Type**: \`${entryType}\``);
|
|
1474
|
+
lines.push(`- **Readonly**: \`${attributes?.readonly ?? false}\``);
|
|
1475
|
+
lines.push(`- **Visible**: \`${attributes?.visible ?? true}\``);
|
|
1476
|
+
lines.push(`- **Template**: \`${attributes?.template ?? false}\``);
|
|
1477
|
+
lines.push(`- **Z-Index**: \`${attributes?.zIndex ?? 0}\``);
|
|
1478
|
+
if (attributes?.contentTags && attributes.contentTags.length > 0) {
|
|
1479
|
+
lines.push(`- **Tags**: \`${attributes.contentTags.join("`, `")}\``);
|
|
1480
|
+
}
|
|
1481
|
+
if (attributes?.contentType) {
|
|
1482
|
+
lines.push(`- **Content Type**: \`${attributes.contentType}\``);
|
|
1483
|
+
}
|
|
1484
|
+
if (entryType === "image" || entryType === "file") {
|
|
1485
|
+
const label = String.fromCharCode(65 + appendixCounter);
|
|
1486
|
+
appendixCounter++;
|
|
1487
|
+
lines.push(`- **Value**: [See Appendix ${label}]`);
|
|
1488
|
+
appendixEntries.push({
|
|
1489
|
+
key,
|
|
1490
|
+
type: entryType,
|
|
1491
|
+
contentType: attributes?.contentType || "application/octet-stream",
|
|
1492
|
+
base64: value,
|
|
1493
|
+
label
|
|
1494
|
+
});
|
|
1495
|
+
} else if (entryType === "json") {
|
|
1496
|
+
lines.push("- **Value**:");
|
|
1497
|
+
lines.push("```json");
|
|
1498
|
+
try {
|
|
1499
|
+
const jsonValue = typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
1500
|
+
lines.push(jsonValue);
|
|
1501
|
+
} catch {
|
|
1502
|
+
lines.push(String(value));
|
|
1503
|
+
}
|
|
1504
|
+
lines.push("```");
|
|
1505
|
+
} else {
|
|
1506
|
+
lines.push(`- **Value**: ${value}`);
|
|
1507
|
+
}
|
|
1508
|
+
lines.push("");
|
|
1509
|
+
});
|
|
1510
|
+
if (appendixEntries.length > 0) {
|
|
1511
|
+
lines.push("---");
|
|
1512
|
+
lines.push("");
|
|
1513
|
+
lines.push("## Appendix: Binary Data");
|
|
1514
|
+
lines.push("");
|
|
1515
|
+
appendixEntries.forEach((entry) => {
|
|
1516
|
+
lines.push(`### Appendix ${entry.label}: ${entry.key}`);
|
|
1517
|
+
lines.push(`- **Type**: \`${entry.type}\``);
|
|
1518
|
+
lines.push(`- **Content Type**: \`${entry.contentType}\``);
|
|
1519
|
+
lines.push("- **Base64 Data**:");
|
|
1520
|
+
lines.push("```");
|
|
1521
|
+
lines.push(entry.base64);
|
|
1522
|
+
lines.push("```");
|
|
1523
|
+
lines.push("");
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
return lines.join("\n");
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Import from Markdown format.
|
|
1530
|
+
*/
|
|
1531
|
+
fromMarkdown(markdown) {
|
|
1532
|
+
const lines = markdown.split("\n");
|
|
1533
|
+
let currentKey = null;
|
|
1534
|
+
let currentAttributes = {};
|
|
1535
|
+
let currentValue = null;
|
|
1536
|
+
let inCodeBlock = false;
|
|
1537
|
+
let codeBlockContent = [];
|
|
1538
|
+
for (const line of lines) {
|
|
1539
|
+
if (line.startsWith("### ") && !line.startsWith("### Appendix")) {
|
|
1540
|
+
if (currentKey && currentValue !== null) {
|
|
1541
|
+
this.set_value(currentKey, currentValue, currentAttributes);
|
|
1542
|
+
}
|
|
1543
|
+
currentKey = line.substring(4).trim();
|
|
1544
|
+
currentAttributes = {};
|
|
1545
|
+
currentValue = null;
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
if (line.startsWith("### Appendix ")) {
|
|
1549
|
+
const match = line.match(/### Appendix ([A-Z]): (.+)/);
|
|
1550
|
+
if (match) {
|
|
1551
|
+
currentKey = match[2];
|
|
1552
|
+
}
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
if (line.startsWith("- **Type**:")) {
|
|
1556
|
+
const type = line.match(/`(.+)`/)?.[1];
|
|
1557
|
+
if (type) {
|
|
1558
|
+
currentAttributes.type = type;
|
|
1559
|
+
}
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
if (line.startsWith("- **Readonly**:")) {
|
|
1563
|
+
currentAttributes.readonly = line.includes("`true`");
|
|
1564
|
+
continue;
|
|
1565
|
+
}
|
|
1566
|
+
if (line.startsWith("- **Visible**:")) {
|
|
1567
|
+
currentAttributes.visible = line.includes("`true`");
|
|
1568
|
+
continue;
|
|
1569
|
+
}
|
|
1570
|
+
if (line.startsWith("- **Template**:")) {
|
|
1571
|
+
currentAttributes.template = line.includes("`true`");
|
|
1572
|
+
continue;
|
|
1573
|
+
}
|
|
1574
|
+
if (line.startsWith("- **Z-Index**:")) {
|
|
1575
|
+
const zIndex = parseInt(line.match(/`(\d+)`/)?.[1] || "0", 10);
|
|
1576
|
+
currentAttributes.zIndex = zIndex;
|
|
1577
|
+
continue;
|
|
1578
|
+
}
|
|
1579
|
+
if (line.startsWith("- **Tags**:")) {
|
|
1580
|
+
const tags = line.match(/`([^`]+)`/g)?.map((t) => t.slice(1, -1)) || [];
|
|
1581
|
+
currentAttributes.contentTags = tags;
|
|
1582
|
+
currentAttributes.tags = tags;
|
|
1583
|
+
continue;
|
|
1584
|
+
}
|
|
1585
|
+
if (line.startsWith("- **Content Type**:")) {
|
|
1586
|
+
currentAttributes.contentType = line.match(/`(.+)`/)?.[1];
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1589
|
+
if (line.startsWith("- **Value**:") && !line.includes("[See Appendix")) {
|
|
1590
|
+
currentValue = line.substring(12).trim();
|
|
1591
|
+
continue;
|
|
1592
|
+
}
|
|
1593
|
+
if (line === "```json" || line === "```") {
|
|
1594
|
+
if (inCodeBlock) {
|
|
1595
|
+
inCodeBlock = false;
|
|
1596
|
+
if (currentKey && codeBlockContent.length > 0) {
|
|
1597
|
+
currentValue = codeBlockContent.join("\n");
|
|
1598
|
+
}
|
|
1599
|
+
codeBlockContent = [];
|
|
1600
|
+
} else {
|
|
1601
|
+
inCodeBlock = true;
|
|
1602
|
+
}
|
|
1603
|
+
continue;
|
|
1604
|
+
}
|
|
1605
|
+
if (inCodeBlock) {
|
|
1606
|
+
codeBlockContent.push(line);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
if (currentKey && currentValue !== null) {
|
|
1610
|
+
this.set_value(currentKey, currentValue, currentAttributes);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
/**
|
|
1614
|
+
* Set base64 binary data.
|
|
1615
|
+
*/
|
|
1616
|
+
set_base64(key, base64Data, contentType, type = "file", attributes) {
|
|
1617
|
+
if (!this.validateContentType(type, contentType)) {
|
|
1618
|
+
throw new Error(`Invalid content type ${contentType} for type ${type}`);
|
|
1619
|
+
}
|
|
1620
|
+
const fileAttributes = {
|
|
1621
|
+
type,
|
|
1622
|
+
contentType,
|
|
1623
|
+
...attributes
|
|
1624
|
+
};
|
|
1625
|
+
this.set_value(key, base64Data, fileAttributes);
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Add an image from base64 data.
|
|
1629
|
+
*/
|
|
1630
|
+
add_image(key, base64Data, contentType = "image/jpeg", attributes) {
|
|
1631
|
+
if (!contentType.startsWith("image/")) {
|
|
1632
|
+
throw new Error(`Invalid image content type: ${contentType}. Must start with 'image/'`);
|
|
1633
|
+
}
|
|
1634
|
+
this.set_base64(key, base64Data, contentType, "image", attributes);
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Get the data URL for an image or file key.
|
|
1638
|
+
*/
|
|
1639
|
+
get_data_url(key) {
|
|
1640
|
+
const entryMap = this.rootMap.get(key);
|
|
1641
|
+
if (!entryMap) {
|
|
1642
|
+
return void 0;
|
|
1643
|
+
}
|
|
1644
|
+
const attributes = entryMap.get("attributes");
|
|
1645
|
+
if (attributes?.type !== "image" && attributes?.type !== "file") {
|
|
1646
|
+
return void 0;
|
|
1647
|
+
}
|
|
1648
|
+
if (!attributes?.contentType) {
|
|
1649
|
+
return void 0;
|
|
1650
|
+
}
|
|
1651
|
+
const value = entryMap.get("value");
|
|
1652
|
+
return this.createDataUrl(value, attributes.contentType);
|
|
1653
|
+
}
|
|
1654
|
+
/**
|
|
1655
|
+
* Get the base64 data for an image or file key.
|
|
1656
|
+
*/
|
|
1657
|
+
get_base64(key) {
|
|
1658
|
+
const entryMap = this.rootMap.get(key);
|
|
1659
|
+
if (!entryMap) {
|
|
1660
|
+
return void 0;
|
|
1661
|
+
}
|
|
1662
|
+
const attributes = entryMap.get("attributes");
|
|
1663
|
+
if (attributes?.type !== "image" && attributes?.type !== "file") {
|
|
1664
|
+
return void 0;
|
|
1665
|
+
}
|
|
1666
|
+
return entryMap.get("value");
|
|
1667
|
+
}
|
|
989
1668
|
// File methods
|
|
990
1669
|
async set_file(key, file, attributes) {
|
|
991
1670
|
const base64 = await this.encodeFileToBase64(file);
|
|
@@ -1306,10 +1985,14 @@ var MindCache = class {
|
|
|
1306
1985
|
const sanitizedKey = this.sanitizeKeyForTool(key);
|
|
1307
1986
|
if (isWritable) {
|
|
1308
1987
|
if (isDocument) {
|
|
1309
|
-
lines.push(
|
|
1988
|
+
lines.push(
|
|
1989
|
+
`${key}: ${displayValue}. Document tools: write_${sanitizedKey}, append_${sanitizedKey}, edit_${sanitizedKey}`
|
|
1990
|
+
);
|
|
1310
1991
|
} else {
|
|
1311
1992
|
const oldValueHint = displayValue ? ` This tool DOES NOT append \u2014 start your response with the old value (${displayValue})` : "";
|
|
1312
|
-
lines.push(
|
|
1993
|
+
lines.push(
|
|
1994
|
+
`${key}: ${displayValue}. You can rewrite "${key}" by using the write_${sanitizedKey} tool.${oldValueHint}`
|
|
1995
|
+
);
|
|
1313
1996
|
}
|
|
1314
1997
|
} else {
|
|
1315
1998
|
lines.push(`${key}: ${displayValue}`);
|