@blank-utils/llm 0.3.8 → 0.3.10

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,32 +1101,41 @@ ${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";
1108
- import { createCodePlugin } from "@streamdown/code";
1109
- import { createMermaidPlugin } from "@streamdown/mermaid";
1110
- import { createMathPlugin } from "@streamdown/math";
1108
+ import { code } from "@streamdown/code";
1109
+ import { mermaid } from "@streamdown/mermaid";
1110
+ import { math } from "@streamdown/math";
1111
1111
  import "streamdown/styles.css";
1112
1112
  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 codePlugin = createCodePlugin({
1117
- themes: ["github-light", "github-dark"]
1118
- });
1119
- var mermaidPlugin = createMermaidPlugin({
1120
- config: {
1121
- theme: "base",
1122
- themeVariables: {
1123
- fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace'
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"
1124
1128
  }
1129
+ )
1130
+ ] });
1131
+ var streamdownControls = {
1132
+ mermaid: {
1133
+ fullscreen: true,
1134
+ download: true,
1135
+ copy: true,
1136
+ panZoom: true
1125
1137
  }
1126
- });
1127
- var mathPlugin = createMathPlugin({
1128
- singleDollarTextMath: false
1129
- });
1138
+ };
1130
1139
  var DEFAULT_SYSTEM_PROMPT = `You are a helpful AI assistant.
1131
1140
  - You can use full Markdown (bold, italic, headers, lists).
1132
1141
  - You can use Code Blocks with language syntax highlighting.
@@ -1260,6 +1269,14 @@ function Chat({
1260
1269
  const messagesEndRef = useRef3(null);
1261
1270
  const abortRef = useRef3(false);
1262
1271
  const isProcessingRef = useRef3(false);
1272
+ const mermaidOptions = useMemo2(() => ({
1273
+ errorComponent: CustomMermaidError,
1274
+ config: {
1275
+ theme: theme === "dark" ? "dark" : "default",
1276
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
1277
+ securityLevel: "strict"
1278
+ }
1279
+ }), [theme]);
1263
1280
  useEffect3(() => {
1264
1281
  messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
1265
1282
  }, [messages, streamingText, isGenerating]);
@@ -1416,9 +1433,42 @@ function Chat({
1416
1433
  ] }),
1417
1434
  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: [
1418
1435
  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)) }),
1419
- /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none", children: /* @__PURE__ */ jsx3(Streamdown, { plugins: { code: codePlugin, mermaid: mermaidPlugin, math: mathPlugin }, components: markdownComponents, animated: true, isAnimating: false, children: msg.content }) })
1420
- ] }) : /* @__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: codePlugin, mermaid: mermaidPlugin, math: mathPlugin }, components: markdownComponents, animated: true, isAnimating: false, children: msg.content }) }) }, i)),
1421
- 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: codePlugin, mermaid: mermaidPlugin, math: mathPlugin }, components: markdownComponents, animated: true, isAnimating: isGenerating, children: streamingText }) }) }),
1436
+ /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none", children: /* @__PURE__ */ jsx3(
1437
+ Streamdown,
1438
+ {
1439
+ plugins: { code, mermaid, math },
1440
+ components: markdownComponents,
1441
+ animated: true,
1442
+ isAnimating: false,
1443
+ mermaid: mermaidOptions,
1444
+ controls: streamdownControls,
1445
+ children: msg.content
1446
+ }
1447
+ ) })
1448
+ ] }) : /* @__PURE__ */ jsx3("div", { className: "prose prose-sm dark:prose-invert max-w-none px-2 w-full min-w-0", children: /* @__PURE__ */ jsx3(
1449
+ Streamdown,
1450
+ {
1451
+ plugins: { code, mermaid, math },
1452
+ components: markdownComponents,
1453
+ animated: true,
1454
+ isAnimating: false,
1455
+ mermaid: mermaidOptions,
1456
+ controls: streamdownControls,
1457
+ children: msg.content
1458
+ }
1459
+ ) }) }, i)),
1460
+ 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(
1461
+ Streamdown,
1462
+ {
1463
+ plugins: { code, mermaid, math },
1464
+ components: markdownComponents,
1465
+ animated: true,
1466
+ isAnimating: isGenerating,
1467
+ mermaid: mermaidOptions,
1468
+ controls: streamdownControls,
1469
+ children: streamingText
1470
+ }
1471
+ ) }) }),
1422
1472
  /* @__PURE__ */ jsx3("div", { ref: messagesEndRef, className: "h-4" })
1423
1473
  ] }),
1424
1474
  /* @__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(