@blank-utils/llm 0.3.9 → 0.3.11

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.
@@ -1101,7 +1101,7 @@ ${newText}` : newText);
1101
1101
  }
1102
1102
 
1103
1103
  // src/react/components.tsx
1104
- import { RotateCcw, ChevronDown } from "lucide-react";
1104
+ import { RotateCcw, ChevronDown, AlertCircleIcon } from "lucide-react";
1105
1105
  import { clsx } from "clsx";
1106
1106
  import { twMerge } from "tailwind-merge";
1107
1107
  import { Streamdown } from "streamdown";
@@ -1113,10 +1113,39 @@ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1113
1113
  function cn(...inputs) {
1114
1114
  return twMerge(clsx(inputs));
1115
1115
  }
1116
+ var CustomMermaidError = ({ error, retry }) => /* @__PURE__ */ jsxs3("div", { className: "rounded-lg border border-red-500/20 bg-red-500/10 p-4 my-4 font-sans", children: [
1117
+ /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-2", children: [
1118
+ /* @__PURE__ */ jsx3("span", { className: "text-xl", children: /* @__PURE__ */ jsx3(AlertCircleIcon, { className: "text-red-500" }) }),
1119
+ /* @__PURE__ */ jsx3("p", { className: "font-semibold text-red-500 text-sm", children: "Failed to render Mermaid diagram" })
1120
+ ] }),
1121
+ /* @__PURE__ */ jsx3("div", { className: "mt-2 text-red-400/80 text-xs overflow-x-auto whitespace-pre-wrap font-mono", children: error }),
1122
+ /* @__PURE__ */ jsx3(
1123
+ "button",
1124
+ {
1125
+ onClick: retry,
1126
+ className: "mt-3 rounded bg-red-500/20 px-3 py-1.5 text-red-500 text-xs font-medium hover:bg-red-500/30 transition-colors",
1127
+ children: "Try Again"
1128
+ }
1129
+ )
1130
+ ] });
1131
+ var streamdownControls = {
1132
+ mermaid: {
1133
+ fullscreen: true,
1134
+ download: true,
1135
+ copy: true,
1136
+ panZoom: true
1137
+ }
1138
+ };
1116
1139
  var DEFAULT_SYSTEM_PROMPT = `You are a helpful AI assistant.
1117
1140
  - You can use full Markdown (bold, italic, headers, lists).
1118
1141
  - You can use Code Blocks with language syntax highlighting.
1119
- - You can use Mermaid diagrams (\`\`\`mermaid ... \`\`\`).
1142
+ - You can use Mermaid diagrams to visualize structured data, processes, and architectures.
1143
+ - IMPORTANT: ALWAYS use exactly \`\`\`mermaid as the language tag. NEVER use \`\`\`mer, \`\`\`mmd, etc.
1144
+ - For example:
1145
+ \`\`\`mermaid
1146
+ graph TD
1147
+ A --> B
1148
+ \`\`\`
1120
1149
  - You can use LaTeX math ($$ ... $$).`;
1121
1150
  var ALL_MODELS = { ...WEBLLM_MODELS, ...TRANSFORMERS_MODELS };
1122
1151
  function isVisionModel2(modelId) {
@@ -1246,6 +1275,14 @@ function Chat({
1246
1275
  const messagesEndRef = useRef3(null);
1247
1276
  const abortRef = useRef3(false);
1248
1277
  const isProcessingRef = useRef3(false);
1278
+ const mermaidOptions = useMemo2(() => ({
1279
+ errorComponent: CustomMermaidError,
1280
+ config: {
1281
+ theme: theme === "dark" ? "dark" : "default",
1282
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
1283
+ securityLevel: "strict"
1284
+ }
1285
+ }), [theme]);
1249
1286
  useEffect3(() => {
1250
1287
  messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
1251
1288
  }, [messages, streamingText, isGenerating]);
@@ -1402,9 +1439,42 @@ function Chat({
1402
1439
  ] }),
1403
1440
  messages.map((msg, i) => /* @__PURE__ */ jsx3("div", { className: cn("flex flex-col max-w-[85%]", msg.role === "user" ? "self-end" : "self-start w-full"), children: msg.role === "user" ? /* @__PURE__ */ jsxs3("div", { className: "bg-zinc-100 dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 px-5 py-3.5 rounded-[24px] rounded-br-[8px] sm:px-6 shadow-sm border border-zinc-200 dark:border-zinc-700/50", children: [
1404
1441
  msg.images && msg.images.length > 0 && /* @__PURE__ */ jsx3("div", { className: "flex flex-wrap gap-2 mb-3 mt-1", children: msg.images.map((img) => /* @__PURE__ */ jsx3("img", { src: img.dataUrl, className: "w-24 h-24 object-cover rounded-xl border border-zinc-200 dark:border-zinc-700 shadow-sm", alt: "attachment" }, img.id)) }),
1405
- /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none", children: /* @__PURE__ */ jsx3(Streamdown, { plugins: { code, mermaid, math }, components: markdownComponents, animated: true, isAnimating: false, children: msg.content }) })
1406
- ] }) : /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none px-2 w-full min-w-0", children: /* @__PURE__ */ jsx3(Streamdown, { plugins: { code, mermaid, math }, components: markdownComponents, animated: true, isAnimating: false, children: msg.content }) }) }, i)),
1407
- streamingText && /* @__PURE__ */ jsx3("div", { className: "flex flex-col self-start w-full max-w-[85%]", children: /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none px-2 w-full min-w-0", children: /* @__PURE__ */ jsx3(Streamdown, { plugins: { code, mermaid, math }, components: markdownComponents, animated: true, isAnimating: isGenerating, children: streamingText }) }) }),
1442
+ /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none", children: /* @__PURE__ */ jsx3(
1443
+ Streamdown,
1444
+ {
1445
+ plugins: { code, mermaid, math },
1446
+ components: markdownComponents,
1447
+ animated: true,
1448
+ isAnimating: false,
1449
+ mermaid: mermaidOptions,
1450
+ controls: streamdownControls,
1451
+ children: msg.content
1452
+ }
1453
+ ) })
1454
+ ] }) : /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none px-2 w-full min-w-0", children: /* @__PURE__ */ jsx3(
1455
+ Streamdown,
1456
+ {
1457
+ plugins: { code, mermaid, math },
1458
+ components: markdownComponents,
1459
+ animated: true,
1460
+ isAnimating: false,
1461
+ mermaid: mermaidOptions,
1462
+ controls: streamdownControls,
1463
+ children: msg.content
1464
+ }
1465
+ ) }) }, i)),
1466
+ streamingText && /* @__PURE__ */ jsx3("div", { className: "flex flex-col self-start w-full max-w-[85%]", children: /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none px-2 w-full min-w-0", children: /* @__PURE__ */ jsx3(
1467
+ Streamdown,
1468
+ {
1469
+ plugins: { code, mermaid, math },
1470
+ components: markdownComponents,
1471
+ animated: true,
1472
+ isAnimating: isGenerating,
1473
+ mermaid: mermaidOptions,
1474
+ controls: streamdownControls,
1475
+ children: streamingText
1476
+ }
1477
+ ) }) }),
1408
1478
  /* @__PURE__ */ jsx3("div", { ref: messagesEndRef, className: "h-4" })
1409
1479
  ] }),
1410
1480
  /* @__PURE__ */ jsx3("div", { className: "p-4 bg-white/80 dark:bg-zinc-950/80 backdrop-blur-xl border-t border-zinc-100 dark:border-zinc-800/80", children: /* @__PURE__ */ jsx3(
package/dist/index.css CHANGED
@@ -2559,6 +2559,9 @@ video {
2559
2559
  .whitespace-nowrap {
2560
2560
  white-space: nowrap;
2561
2561
  }
2562
+ .whitespace-pre-wrap {
2563
+ white-space: pre-wrap;
2564
+ }
2562
2565
  .break-all {
2563
2566
  word-break: break-all;
2564
2567
  }
@@ -2631,6 +2634,9 @@ video {
2631
2634
  --tw-border-opacity: 1;
2632
2635
  border-color: rgb(254 202 202 / var(--tw-border-opacity, 1));
2633
2636
  }
2637
+ .border-red-500\/20 {
2638
+ border-color: rgb(239 68 68 / 0.2);
2639
+ }
2634
2640
  .border-zinc-100 {
2635
2641
  --tw-border-opacity: 1;
2636
2642
  border-color: rgb(244 244 245 / var(--tw-border-opacity, 1));
@@ -2684,6 +2690,12 @@ video {
2684
2690
  --tw-bg-opacity: 1;
2685
2691
  background-color: rgb(239 68 68 / var(--tw-bg-opacity, 1));
2686
2692
  }
2693
+ .bg-red-500\/10 {
2694
+ background-color: rgb(239 68 68 / 0.1);
2695
+ }
2696
+ .bg-red-500\/20 {
2697
+ background-color: rgb(239 68 68 / 0.2);
2698
+ }
2687
2699
  .bg-transparent {
2688
2700
  background-color: transparent;
2689
2701
  }
@@ -2842,6 +2854,16 @@ video {
2842
2854
  "Courier New",
2843
2855
  monospace;
2844
2856
  }
2857
+ .font-sans {
2858
+ font-family:
2859
+ ui-sans-serif,
2860
+ system-ui,
2861
+ sans-serif,
2862
+ "Apple Color Emoji",
2863
+ "Segoe UI Emoji",
2864
+ "Segoe UI Symbol",
2865
+ "Noto Color Emoji";
2866
+ }
2845
2867
  .text-2xl {
2846
2868
  font-size: 1.5rem;
2847
2869
  line-height: 2rem;
@@ -2926,6 +2948,13 @@ video {
2926
2948
  --tw-text-opacity: 1;
2927
2949
  color: rgb(37 99 235 / var(--tw-text-opacity, 1));
2928
2950
  }
2951
+ .text-red-400\/80 {
2952
+ color: rgb(248 113 113 / 0.8);
2953
+ }
2954
+ .text-red-500 {
2955
+ --tw-text-opacity: 1;
2956
+ color: rgb(239 68 68 / var(--tw-text-opacity, 1));
2957
+ }
2929
2958
  .text-red-600 {
2930
2959
  --tw-text-opacity: 1;
2931
2960
  color: rgb(220 38 38 / var(--tw-text-opacity, 1));
@@ -3236,6 +3265,9 @@ video {
3236
3265
  --tw-bg-opacity: 1;
3237
3266
  background-color: rgb(254 242 242 / var(--tw-bg-opacity, 1));
3238
3267
  }
3268
+ .hover\:bg-red-500\/30:hover {
3269
+ background-color: rgb(239 68 68 / 0.3);
3270
+ }
3239
3271
  .hover\:bg-zinc-200:hover {
3240
3272
  --tw-bg-opacity: 1;
3241
3273
  background-color: rgb(228 228 231 / var(--tw-bg-opacity, 1));
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-35TEFO6H.js";
29
+ } from "./chunk-D3AYWZX2.js";
30
30
  export {
31
31
  Chat,
32
32
  ChatInput,
@@ -2559,6 +2559,9 @@ video {
2559
2559
  .whitespace-nowrap {
2560
2560
  white-space: nowrap;
2561
2561
  }
2562
+ .whitespace-pre-wrap {
2563
+ white-space: pre-wrap;
2564
+ }
2562
2565
  .break-all {
2563
2566
  word-break: break-all;
2564
2567
  }
@@ -2631,6 +2634,9 @@ video {
2631
2634
  --tw-border-opacity: 1;
2632
2635
  border-color: rgb(254 202 202 / var(--tw-border-opacity, 1));
2633
2636
  }
2637
+ .border-red-500\/20 {
2638
+ border-color: rgb(239 68 68 / 0.2);
2639
+ }
2634
2640
  .border-zinc-100 {
2635
2641
  --tw-border-opacity: 1;
2636
2642
  border-color: rgb(244 244 245 / var(--tw-border-opacity, 1));
@@ -2684,6 +2690,12 @@ video {
2684
2690
  --tw-bg-opacity: 1;
2685
2691
  background-color: rgb(239 68 68 / var(--tw-bg-opacity, 1));
2686
2692
  }
2693
+ .bg-red-500\/10 {
2694
+ background-color: rgb(239 68 68 / 0.1);
2695
+ }
2696
+ .bg-red-500\/20 {
2697
+ background-color: rgb(239 68 68 / 0.2);
2698
+ }
2687
2699
  .bg-transparent {
2688
2700
  background-color: transparent;
2689
2701
  }
@@ -2842,6 +2854,16 @@ video {
2842
2854
  "Courier New",
2843
2855
  monospace;
2844
2856
  }
2857
+ .font-sans {
2858
+ font-family:
2859
+ ui-sans-serif,
2860
+ system-ui,
2861
+ sans-serif,
2862
+ "Apple Color Emoji",
2863
+ "Segoe UI Emoji",
2864
+ "Segoe UI Symbol",
2865
+ "Noto Color Emoji";
2866
+ }
2845
2867
  .text-2xl {
2846
2868
  font-size: 1.5rem;
2847
2869
  line-height: 2rem;
@@ -2926,6 +2948,13 @@ video {
2926
2948
  --tw-text-opacity: 1;
2927
2949
  color: rgb(37 99 235 / var(--tw-text-opacity, 1));
2928
2950
  }
2951
+ .text-red-400\/80 {
2952
+ color: rgb(248 113 113 / 0.8);
2953
+ }
2954
+ .text-red-500 {
2955
+ --tw-text-opacity: 1;
2956
+ color: rgb(239 68 68 / var(--tw-text-opacity, 1));
2957
+ }
2929
2958
  .text-red-600 {
2930
2959
  --tw-text-opacity: 1;
2931
2960
  color: rgb(220 38 38 / var(--tw-text-opacity, 1));
@@ -3236,6 +3265,9 @@ video {
3236
3265
  --tw-bg-opacity: 1;
3237
3266
  background-color: rgb(254 242 242 / var(--tw-bg-opacity, 1));
3238
3267
  }
3268
+ .hover\:bg-red-500\/30:hover {
3269
+ background-color: rgb(239 68 68 / 0.3);
3270
+ }
3239
3271
  .hover\:bg-zinc-200:hover {
3240
3272
  --tw-bg-opacity: 1;
3241
3273
  background-color: rgb(228 228 231 / var(--tw-bg-opacity, 1));
@@ -9,7 +9,7 @@ import {
9
9
  useCompletion,
10
10
  useLLM,
11
11
  useStream
12
- } from "../chunk-35TEFO6H.js";
12
+ } from "../chunk-D3AYWZX2.js";
13
13
  export {
14
14
  Chat,
15
15
  ChatApp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blank-utils/llm",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "description": "Run LLMs directly in your browser with WebGPU acceleration. Supports React hooks and eager background loading.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",