mindcache 3.4.2 → 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.mjs CHANGED
@@ -178,6 +178,7 @@ var init_CloudAdapter = __esm({
178
178
  RECONNECT_DELAY = 1e3;
179
179
  MAX_RECONNECT_DELAY = 3e4;
180
180
  CloudAdapter = class {
181
+ // Track if initial sync is complete
181
182
  constructor(config) {
182
183
  this.config = config;
183
184
  if (!config.baseUrl) {
@@ -197,6 +198,7 @@ var init_CloudAdapter = __esm({
197
198
  token = null;
198
199
  handleOnline = null;
199
200
  handleOffline = null;
201
+ _synced = false;
200
202
  /** Browser network status - instantly updated via navigator.onLine */
201
203
  get isOnline() {
202
204
  return this._isOnline;
@@ -379,10 +381,14 @@ var init_CloudAdapter = __esm({
379
381
  const encoder = encoding.createEncoder();
380
382
  const decoder = decoding.createDecoder(new Uint8Array(event.data));
381
383
  if (this.mindcache) {
382
- syncProtocol.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
384
+ const messageType = syncProtocol.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
383
385
  if (encoding.length(encoder) > 0) {
384
386
  this.sendBinary(encoding.toUint8Array(encoder));
385
387
  }
388
+ if (!this._synced && (messageType === 1 || messageType === 2)) {
389
+ this._synced = true;
390
+ this.emit("synced");
391
+ }
386
392
  }
387
393
  }
388
394
  } catch (error) {
@@ -489,7 +495,7 @@ var MindCache = class {
489
495
  _historyOptions = { maxEntries: 100, snapshotInterval: 10 };
490
496
  _historyEnabled = false;
491
497
  constructor(options) {
492
- this.doc = new Y.Doc();
498
+ this.doc = options?.doc || new Y.Doc();
493
499
  this.rootMap = this.doc.getMap("mindcache");
494
500
  this.rootMap.observeDeep((events) => {
495
501
  const keysAffected = /* @__PURE__ */ new Set();
@@ -1611,7 +1617,10 @@ var MindCache = class {
1611
1617
  }
1612
1618
  lines.push("```");
1613
1619
  } else {
1614
- lines.push(`- **Value**: ${value}`);
1620
+ lines.push("- **Value**:");
1621
+ lines.push("```");
1622
+ lines.push(String(value));
1623
+ lines.push("```");
1615
1624
  }
1616
1625
  lines.push("");
1617
1626
  });
@@ -1646,7 +1655,7 @@ var MindCache = class {
1646
1655
  for (const line of lines) {
1647
1656
  if (line.startsWith("### ") && !line.startsWith("### Appendix")) {
1648
1657
  if (currentKey && currentValue !== null) {
1649
- this.set_value(currentKey, currentValue, currentAttributes);
1658
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1650
1659
  }
1651
1660
  currentKey = line.substring(4).trim();
1652
1661
  currentAttributes = {};
@@ -1689,10 +1698,24 @@ var MindCache = class {
1689
1698
  continue;
1690
1699
  }
1691
1700
  if (line.startsWith("- **Value**:") && !line.includes("[See Appendix")) {
1692
- currentValue = line.substring(12).trim();
1701
+ const afterValue = line.substring(12).trim();
1702
+ if (afterValue === "") {
1703
+ currentValue = "";
1704
+ } else if (afterValue === "```" || afterValue === "```json") {
1705
+ inCodeBlock = true;
1706
+ codeBlockContent = [];
1707
+ currentValue = "";
1708
+ } else if (afterValue.startsWith("```")) {
1709
+ inCodeBlock = true;
1710
+ codeBlockContent = [afterValue.substring(3)];
1711
+ currentValue = "";
1712
+ } else {
1713
+ currentValue = afterValue;
1714
+ }
1693
1715
  continue;
1694
1716
  }
1695
- if (line === "```json" || line === "```") {
1717
+ const trimmedLine = line.trim();
1718
+ if (trimmedLine === "```json" || trimmedLine === "```") {
1696
1719
  if (inCodeBlock) {
1697
1720
  inCodeBlock = false;
1698
1721
  if (currentKey && codeBlockContent.length > 0) {
@@ -1701,15 +1724,27 @@ var MindCache = class {
1701
1724
  codeBlockContent = [];
1702
1725
  } else {
1703
1726
  inCodeBlock = true;
1727
+ codeBlockContent = [];
1704
1728
  }
1705
1729
  continue;
1706
1730
  }
1707
1731
  if (inCodeBlock) {
1708
1732
  codeBlockContent.push(line);
1733
+ } else if (currentKey && currentValue !== null) {
1734
+ currentValue += "\n" + line;
1709
1735
  }
1710
1736
  }
1711
1737
  if (currentKey && currentValue !== null) {
1712
- this.set_value(currentKey, currentValue, currentAttributes);
1738
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1739
+ }
1740
+ const hasParsedKeys = lines.some((line) => line.startsWith("### ") && !line.startsWith("### Appendix"));
1741
+ if (!hasParsedKeys && markdown.trim().length > 0) {
1742
+ this.set_value("imported_content", markdown.trim(), {
1743
+ type: "text",
1744
+ systemTags: ["SystemPrompt", "LLMWrite"],
1745
+ // Default assumptions
1746
+ zIndex: 0
1747
+ });
1713
1748
  }
1714
1749
  }
1715
1750
  /**