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.
@@ -177,6 +177,7 @@ var init_CloudAdapter = __esm({
177
177
  RECONNECT_DELAY = 1e3;
178
178
  MAX_RECONNECT_DELAY = 3e4;
179
179
  CloudAdapter = class {
180
+ // Track if initial sync is complete
180
181
  constructor(config) {
181
182
  this.config = config;
182
183
  if (!config.baseUrl) {
@@ -196,6 +197,7 @@ var init_CloudAdapter = __esm({
196
197
  token = null;
197
198
  handleOnline = null;
198
199
  handleOffline = null;
200
+ _synced = false;
199
201
  /** Browser network status - instantly updated via navigator.onLine */
200
202
  get isOnline() {
201
203
  return this._isOnline;
@@ -378,10 +380,14 @@ var init_CloudAdapter = __esm({
378
380
  const encoder = encoding.createEncoder();
379
381
  const decoder = decoding.createDecoder(new Uint8Array(event.data));
380
382
  if (this.mindcache) {
381
- syncProtocol.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
383
+ const messageType = syncProtocol.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
382
384
  if (encoding.length(encoder) > 0) {
383
385
  this.sendBinary(encoding.toUint8Array(encoder));
384
386
  }
387
+ if (!this._synced && (messageType === 1 || messageType === 2)) {
388
+ this._synced = true;
389
+ this.emit("synced");
390
+ }
385
391
  }
386
392
  }
387
393
  } catch (error) {
@@ -476,7 +482,7 @@ var MindCache = class {
476
482
  _historyOptions = { maxEntries: 100, snapshotInterval: 10 };
477
483
  _historyEnabled = false;
478
484
  constructor(options) {
479
- this.doc = new Y.Doc();
485
+ this.doc = options?.doc || new Y.Doc();
480
486
  this.rootMap = this.doc.getMap("mindcache");
481
487
  this.rootMap.observeDeep((events) => {
482
488
  const keysAffected = /* @__PURE__ */ new Set();
@@ -1598,7 +1604,10 @@ var MindCache = class {
1598
1604
  }
1599
1605
  lines.push("```");
1600
1606
  } else {
1601
- lines.push(`- **Value**: ${value}`);
1607
+ lines.push("- **Value**:");
1608
+ lines.push("```");
1609
+ lines.push(String(value));
1610
+ lines.push("```");
1602
1611
  }
1603
1612
  lines.push("");
1604
1613
  });
@@ -1633,7 +1642,7 @@ var MindCache = class {
1633
1642
  for (const line of lines) {
1634
1643
  if (line.startsWith("### ") && !line.startsWith("### Appendix")) {
1635
1644
  if (currentKey && currentValue !== null) {
1636
- this.set_value(currentKey, currentValue, currentAttributes);
1645
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1637
1646
  }
1638
1647
  currentKey = line.substring(4).trim();
1639
1648
  currentAttributes = {};
@@ -1676,10 +1685,24 @@ var MindCache = class {
1676
1685
  continue;
1677
1686
  }
1678
1687
  if (line.startsWith("- **Value**:") && !line.includes("[See Appendix")) {
1679
- currentValue = line.substring(12).trim();
1688
+ const afterValue = line.substring(12).trim();
1689
+ if (afterValue === "") {
1690
+ currentValue = "";
1691
+ } else if (afterValue === "```" || afterValue === "```json") {
1692
+ inCodeBlock = true;
1693
+ codeBlockContent = [];
1694
+ currentValue = "";
1695
+ } else if (afterValue.startsWith("```")) {
1696
+ inCodeBlock = true;
1697
+ codeBlockContent = [afterValue.substring(3)];
1698
+ currentValue = "";
1699
+ } else {
1700
+ currentValue = afterValue;
1701
+ }
1680
1702
  continue;
1681
1703
  }
1682
- if (line === "```json" || line === "```") {
1704
+ const trimmedLine = line.trim();
1705
+ if (trimmedLine === "```json" || trimmedLine === "```") {
1683
1706
  if (inCodeBlock) {
1684
1707
  inCodeBlock = false;
1685
1708
  if (currentKey && codeBlockContent.length > 0) {
@@ -1688,15 +1711,27 @@ var MindCache = class {
1688
1711
  codeBlockContent = [];
1689
1712
  } else {
1690
1713
  inCodeBlock = true;
1714
+ codeBlockContent = [];
1691
1715
  }
1692
1716
  continue;
1693
1717
  }
1694
1718
  if (inCodeBlock) {
1695
1719
  codeBlockContent.push(line);
1720
+ } else if (currentKey && currentValue !== null) {
1721
+ currentValue += "\n" + line;
1696
1722
  }
1697
1723
  }
1698
1724
  if (currentKey && currentValue !== null) {
1699
- this.set_value(currentKey, currentValue, currentAttributes);
1725
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1726
+ }
1727
+ const hasParsedKeys = lines.some((line) => line.startsWith("### ") && !line.startsWith("### Appendix"));
1728
+ if (!hasParsedKeys && markdown.trim().length > 0) {
1729
+ this.set_value("imported_content", markdown.trim(), {
1730
+ type: "text",
1731
+ systemTags: ["SystemPrompt", "LLMWrite"],
1732
+ // Default assumptions
1733
+ zIndex: 0
1734
+ });
1700
1735
  }
1701
1736
  }
1702
1737
  /**