mindcache 3.7.0 → 3.8.1

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
@@ -530,18 +530,23 @@ var MarkdownSerializer = class {
530
530
  /**
531
531
  * Export MindCache data to Markdown format.
532
532
  */
533
- static toMarkdown(mc) {
533
+ static toMarkdown(mc, options) {
534
534
  const now = /* @__PURE__ */ new Date();
535
535
  const lines = [];
536
536
  const appendixEntries = [];
537
537
  let appendixCounter = 0;
538
- lines.push("# MindCache STM Export");
538
+ const name = options?.name || "MindCache Export";
539
+ lines.push(`# ${name}`);
539
540
  lines.push("");
541
+ if (options?.description) {
542
+ lines.push(options.description);
543
+ lines.push("");
544
+ }
540
545
  lines.push(`Export Date: ${now.toISOString().split("T")[0]}`);
541
546
  lines.push("");
542
547
  lines.push("---");
543
548
  lines.push("");
544
- lines.push("## STM Entries");
549
+ lines.push("## Keys & Values");
545
550
  lines.push("");
546
551
  const sortedKeys = mc.getSortedKeys();
547
552
  sortedKeys.forEach((key) => {
@@ -549,9 +554,17 @@ var MarkdownSerializer = class {
549
554
  const value = mc.get_value(key);
550
555
  lines.push(`### ${key}`);
551
556
  const entryType = attributes?.type || "text";
552
- lines.push(`- **Type**: \`${entryType}\``);
553
- lines.push(`- **System Tags**: \`${attributes?.systemTags?.join(", ") || "none"}\``);
554
- lines.push(`- **Z-Index**: \`${attributes?.zIndex ?? 0}\``);
557
+ if (entryType !== "text") {
558
+ lines.push(`- **Type**: \`${entryType}\``);
559
+ }
560
+ const systemTags = attributes?.systemTags;
561
+ if (systemTags && systemTags.length > 0) {
562
+ lines.push(`- **System Tags**: \`${systemTags.join(", ")}\``);
563
+ }
564
+ const zIndex = attributes?.zIndex ?? 0;
565
+ if (zIndex !== 0) {
566
+ lines.push(`- **Z-Index**: \`${zIndex}\``);
567
+ }
555
568
  if (attributes?.contentTags && attributes.contentTags.length > 0) {
556
569
  lines.push(`- **Tags**: \`${attributes.contentTags.join("`, `")}\``);
557
570
  }
@@ -730,7 +743,7 @@ var MarkdownSerializer = class {
730
743
  mc.set_value(currentKey, currentValue.trim(), currentAttributes);
731
744
  }
732
745
  const hasParsedKeys = lines.some((line) => line.startsWith("### ") && !line.startsWith("### Appendix"));
733
- const isSTMExport = markdown.includes("# MindCache STM Export") || markdown.includes("## STM Entries");
746
+ const isSTMExport = markdown.includes("# MindCache STM Export") || markdown.includes("## STM Entries") || markdown.includes("## Keys & Values") || markdown.includes("# MindCache Export");
734
747
  if (!hasParsedKeys && !isSTMExport && markdown.trim().length > 0) {
735
748
  mc.set_value("imported_content", markdown.trim(), {
736
749
  type: "text",
@@ -858,7 +871,7 @@ var MarkdownSerializer = class {
858
871
  }
859
872
  saveEntry();
860
873
  const hasParsedKeys = lines.some((line) => line.startsWith("### ") && !line.startsWith("### Appendix"));
861
- const isSTMExport = markdown.includes("# MindCache STM Export") || markdown.includes("## STM Entries");
874
+ const isSTMExport = markdown.includes("# MindCache STM Export") || markdown.includes("## STM Entries") || markdown.includes("## Keys & Values") || markdown.includes("# MindCache Export");
862
875
  if (!hasParsedKeys && !isSTMExport && markdown.trim().length > 0) {
863
876
  result["imported_content"] = {
864
877
  value: markdown.trim(),
@@ -1589,7 +1602,7 @@ var MindCache = class {
1589
1602
  listeners = {};
1590
1603
  globalListeners = [];
1591
1604
  // Metadata
1592
- version = "3.6.0";
1605
+ version = "3.8.0";
1593
1606
  // Internal flag to prevent sync loops when receiving remote updates
1594
1607
  // (Less critical with Yjs but kept for API compat)
1595
1608
  normalizeSystemTags(tags) {
@@ -2684,9 +2697,10 @@ var MindCache = class {
2684
2697
  }
2685
2698
  /**
2686
2699
  * Export to Markdown format.
2700
+ * @param options Optional name and description for the export
2687
2701
  */
2688
- toMarkdown() {
2689
- return MarkdownSerializer.toMarkdown(this);
2702
+ toMarkdown(options) {
2703
+ return MarkdownSerializer.toMarkdown(this, options);
2690
2704
  }
2691
2705
  /**
2692
2706
  * Import from Markdown format.
@@ -3613,6 +3627,7 @@ function useClientChat(options = {}) {
3613
3627
  setStatus("loading");
3614
3628
  setError(null);
3615
3629
  setStreamingContent("");
3630
+ let accumulatedText = "";
3616
3631
  try {
3617
3632
  const model = context.getModel();
3618
3633
  const finalSystemPrompt = systemPrompt || mc.get_system_prompt();
@@ -3623,7 +3638,6 @@ function useClientChat(options = {}) {
3623
3638
  }));
3624
3639
  setStatus("streaming");
3625
3640
  const parts = [];
3626
- let accumulatedText = "";
3627
3641
  const result = await streamText({
3628
3642
  model,
3629
3643
  system: finalSystemPrompt,
@@ -3656,22 +3670,20 @@ function useClientChat(options = {}) {
3656
3670
  }
3657
3671
  }
3658
3672
  }
3659
- if (step.text) {
3660
- accumulatedText += step.text;
3661
- }
3662
3673
  }
3663
3674
  });
3664
3675
  for await (const chunk of result.textStream) {
3665
3676
  accumulatedText += chunk;
3666
3677
  setStreamingContent(accumulatedText);
3667
3678
  }
3668
- if (accumulatedText) {
3669
- parts.unshift({ type: "text", text: accumulatedText });
3679
+ const finalText = await result.text;
3680
+ if (finalText) {
3681
+ parts.unshift({ type: "text", text: finalText });
3670
3682
  }
3671
3683
  const assistantMessage = {
3672
3684
  id: generateId(),
3673
3685
  role: "assistant",
3674
- content: accumulatedText,
3686
+ content: finalText,
3675
3687
  parts: parts.length > 0 ? parts : void 0,
3676
3688
  createdAt: /* @__PURE__ */ new Date()
3677
3689
  };
@@ -3680,12 +3692,14 @@ function useClientChat(options = {}) {
3680
3692
  setStatus("idle");
3681
3693
  onFinish?.(assistantMessage);
3682
3694
  } catch (err) {
3683
- if (err.name === "AbortError") {
3684
- if (streamingContent) {
3695
+ const errorMessage = err instanceof Error ? err.message : String(err);
3696
+ const isAborted = err.name === "AbortError" || errorMessage.includes("aborted") || errorMessage.includes("No output generated");
3697
+ if (isAborted) {
3698
+ if (accumulatedText) {
3685
3699
  const partialMessage = {
3686
3700
  id: generateId(),
3687
3701
  role: "assistant",
3688
- content: streamingContent + " [stopped]",
3702
+ content: accumulatedText + " [stopped]",
3689
3703
  createdAt: /* @__PURE__ */ new Date()
3690
3704
  };
3691
3705
  setMessages((prev) => [...prev, partialMessage]);