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.
@@ -136,6 +136,8 @@ interface MindCacheOptions {
136
136
  history?: HistoryOptions;
137
137
  /** Access level for tag operations. 'system' allows managing system tags. */
138
138
  accessLevel?: AccessLevel;
139
+ /** Optional existing Y.Doc instance (for server-side hydration) */
140
+ doc?: Y.Doc;
139
141
  }
140
142
  type ConnectionState$1 = 'disconnected' | 'connecting' | 'connected' | 'error';
141
143
  declare class MindCache {
@@ -528,6 +530,7 @@ declare class CloudAdapter {
528
530
  private token;
529
531
  private handleOnline;
530
532
  private handleOffline;
533
+ private _synced;
531
534
  constructor(config: CloudConfig);
532
535
  /** Browser network status - instantly updated via navigator.onLine */
533
536
  get isOnline(): boolean;
@@ -549,4 +552,4 @@ declare class CloudAdapter {
549
552
  private scheduleReconnect;
550
553
  }
551
554
 
552
- export { type AccessLevel as A, CloudAdapter as C, DEFAULT_KEY_ATTRIBUTES as D, type GlobalListener as G, type HistoryEntry as H, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SystemTag as S, type MindCacheOptions as a, type KeyType as b, type STM as c, type STMEntry as d, type HistoryOptions as e, type MindCacheCloudOptions as f, type MindCacheIndexedDBOptions as g, SystemTagHelpers as h, type CloudConfig as i, type ConnectionState as j, type CloudAdapterEvents as k, type SetOperation as l, type DeleteOperation as m, type ClearOperation as n };
555
+ export { type AccessLevel as A, type CloudConfig as C, type DeleteOperation as D, type GlobalListener as G, type HistoryEntry as H, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type MindCacheOptions as e, type KeyType as f, type SystemTag as g, type STM as h, type STMEntry as i, type HistoryOptions as j, type MindCacheCloudOptions as k, type MindCacheIndexedDBOptions as l, DEFAULT_KEY_ATTRIBUTES as m, SystemTagHelpers as n };
@@ -136,6 +136,8 @@ interface MindCacheOptions {
136
136
  history?: HistoryOptions;
137
137
  /** Access level for tag operations. 'system' allows managing system tags. */
138
138
  accessLevel?: AccessLevel;
139
+ /** Optional existing Y.Doc instance (for server-side hydration) */
140
+ doc?: Y.Doc;
139
141
  }
140
142
  type ConnectionState$1 = 'disconnected' | 'connecting' | 'connected' | 'error';
141
143
  declare class MindCache {
@@ -528,6 +530,7 @@ declare class CloudAdapter {
528
530
  private token;
529
531
  private handleOnline;
530
532
  private handleOffline;
533
+ private _synced;
531
534
  constructor(config: CloudConfig);
532
535
  /** Browser network status - instantly updated via navigator.onLine */
533
536
  get isOnline(): boolean;
@@ -549,4 +552,4 @@ declare class CloudAdapter {
549
552
  private scheduleReconnect;
550
553
  }
551
554
 
552
- export { type AccessLevel as A, CloudAdapter as C, DEFAULT_KEY_ATTRIBUTES as D, type GlobalListener as G, type HistoryEntry as H, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SystemTag as S, type MindCacheOptions as a, type KeyType as b, type STM as c, type STMEntry as d, type HistoryOptions as e, type MindCacheCloudOptions as f, type MindCacheIndexedDBOptions as g, SystemTagHelpers as h, type CloudConfig as i, type ConnectionState as j, type CloudAdapterEvents as k, type SetOperation as l, type DeleteOperation as m, type ClearOperation as n };
555
+ export { type AccessLevel as A, type CloudConfig as C, type DeleteOperation as D, type GlobalListener as G, type HistoryEntry as H, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type MindCacheOptions as e, type KeyType as f, type SystemTag as g, type STM as h, type STMEntry as i, type HistoryOptions as j, type MindCacheCloudOptions as k, type MindCacheIndexedDBOptions as l, DEFAULT_KEY_ATTRIBUTES as m, SystemTagHelpers as n };
@@ -1,5 +1,5 @@
1
- import { M as MindCache, i as CloudConfig, C as CloudAdapter } from '../CloudAdapter-D2xxVv4E.mjs';
2
- export { n as ClearOperation, k as CloudAdapterEvents, j as ConnectionState, m as DeleteOperation, O as Operation, l as SetOperation } from '../CloudAdapter-D2xxVv4E.mjs';
1
+ import { M as MindCache, C as CloudConfig, a as CloudAdapter } from '../CloudAdapter-CJS3Sh4f.mjs';
2
+ export { d as ClearOperation, c as CloudAdapterEvents, b as ConnectionState, D as DeleteOperation, O as Operation, S as SetOperation } from '../CloudAdapter-CJS3Sh4f.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { M as MindCache, i as CloudConfig, C as CloudAdapter } from '../CloudAdapter-D2xxVv4E.js';
2
- export { n as ClearOperation, k as CloudAdapterEvents, j as ConnectionState, m as DeleteOperation, O as Operation, l as SetOperation } from '../CloudAdapter-D2xxVv4E.js';
1
+ import { M as MindCache, C as CloudConfig, a as CloudAdapter } from '../CloudAdapter-CJS3Sh4f.js';
2
+ export { d as ClearOperation, c as CloudAdapterEvents, b as ConnectionState, D as DeleteOperation, O as Operation, S as SetOperation } from '../CloudAdapter-CJS3Sh4f.js';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -205,6 +205,7 @@ var init_CloudAdapter = __esm({
205
205
  RECONNECT_DELAY = 1e3;
206
206
  MAX_RECONNECT_DELAY = 3e4;
207
207
  exports.CloudAdapter = class {
208
+ // Track if initial sync is complete
208
209
  constructor(config) {
209
210
  this.config = config;
210
211
  if (!config.baseUrl) {
@@ -224,6 +225,7 @@ var init_CloudAdapter = __esm({
224
225
  token = null;
225
226
  handleOnline = null;
226
227
  handleOffline = null;
228
+ _synced = false;
227
229
  /** Browser network status - instantly updated via navigator.onLine */
228
230
  get isOnline() {
229
231
  return this._isOnline;
@@ -406,10 +408,14 @@ var init_CloudAdapter = __esm({
406
408
  const encoder = encoding__namespace.createEncoder();
407
409
  const decoder = decoding__namespace.createDecoder(new Uint8Array(event.data));
408
410
  if (this.mindcache) {
409
- syncProtocol__namespace.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
411
+ const messageType = syncProtocol__namespace.readSyncMessage(decoder, encoder, this.mindcache.doc, this);
410
412
  if (encoding__namespace.length(encoder) > 0) {
411
413
  this.sendBinary(encoding__namespace.toUint8Array(encoder));
412
414
  }
415
+ if (!this._synced && (messageType === 1 || messageType === 2)) {
416
+ this._synced = true;
417
+ this.emit("synced");
418
+ }
413
419
  }
414
420
  }
415
421
  } catch (error) {
@@ -504,7 +510,7 @@ var MindCache = class {
504
510
  _historyOptions = { maxEntries: 100, snapshotInterval: 10 };
505
511
  _historyEnabled = false;
506
512
  constructor(options) {
507
- this.doc = new Y__namespace.Doc();
513
+ this.doc = options?.doc || new Y__namespace.Doc();
508
514
  this.rootMap = this.doc.getMap("mindcache");
509
515
  this.rootMap.observeDeep((events) => {
510
516
  const keysAffected = /* @__PURE__ */ new Set();
@@ -1626,7 +1632,10 @@ var MindCache = class {
1626
1632
  }
1627
1633
  lines.push("```");
1628
1634
  } else {
1629
- lines.push(`- **Value**: ${value}`);
1635
+ lines.push("- **Value**:");
1636
+ lines.push("```");
1637
+ lines.push(String(value));
1638
+ lines.push("```");
1630
1639
  }
1631
1640
  lines.push("");
1632
1641
  });
@@ -1661,7 +1670,7 @@ var MindCache = class {
1661
1670
  for (const line of lines) {
1662
1671
  if (line.startsWith("### ") && !line.startsWith("### Appendix")) {
1663
1672
  if (currentKey && currentValue !== null) {
1664
- this.set_value(currentKey, currentValue, currentAttributes);
1673
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1665
1674
  }
1666
1675
  currentKey = line.substring(4).trim();
1667
1676
  currentAttributes = {};
@@ -1704,10 +1713,24 @@ var MindCache = class {
1704
1713
  continue;
1705
1714
  }
1706
1715
  if (line.startsWith("- **Value**:") && !line.includes("[See Appendix")) {
1707
- currentValue = line.substring(12).trim();
1716
+ const afterValue = line.substring(12).trim();
1717
+ if (afterValue === "") {
1718
+ currentValue = "";
1719
+ } else if (afterValue === "```" || afterValue === "```json") {
1720
+ inCodeBlock = true;
1721
+ codeBlockContent = [];
1722
+ currentValue = "";
1723
+ } else if (afterValue.startsWith("```")) {
1724
+ inCodeBlock = true;
1725
+ codeBlockContent = [afterValue.substring(3)];
1726
+ currentValue = "";
1727
+ } else {
1728
+ currentValue = afterValue;
1729
+ }
1708
1730
  continue;
1709
1731
  }
1710
- if (line === "```json" || line === "```") {
1732
+ const trimmedLine = line.trim();
1733
+ if (trimmedLine === "```json" || trimmedLine === "```") {
1711
1734
  if (inCodeBlock) {
1712
1735
  inCodeBlock = false;
1713
1736
  if (currentKey && codeBlockContent.length > 0) {
@@ -1716,15 +1739,27 @@ var MindCache = class {
1716
1739
  codeBlockContent = [];
1717
1740
  } else {
1718
1741
  inCodeBlock = true;
1742
+ codeBlockContent = [];
1719
1743
  }
1720
1744
  continue;
1721
1745
  }
1722
1746
  if (inCodeBlock) {
1723
1747
  codeBlockContent.push(line);
1748
+ } else if (currentKey && currentValue !== null) {
1749
+ currentValue += "\n" + line;
1724
1750
  }
1725
1751
  }
1726
1752
  if (currentKey && currentValue !== null) {
1727
- this.set_value(currentKey, currentValue, currentAttributes);
1753
+ this.set_value(currentKey, currentValue.trim(), currentAttributes);
1754
+ }
1755
+ const hasParsedKeys = lines.some((line) => line.startsWith("### ") && !line.startsWith("### Appendix"));
1756
+ if (!hasParsedKeys && markdown.trim().length > 0) {
1757
+ this.set_value("imported_content", markdown.trim(), {
1758
+ type: "text",
1759
+ systemTags: ["SystemPrompt", "LLMWrite"],
1760
+ // Default assumptions
1761
+ zIndex: 0
1762
+ });
1728
1763
  }
1729
1764
  }
1730
1765
  /**