@llamaindex/ui
Version:
A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications
1,293 lines (1,284 loc) • 98.4 kB
JavaScript
'use strict';
var chunk24LJTUUZ_js = require('./chunk-24LJTUUZ.js');
var chunkJGFWFKJW_js = require('./chunk-JGFWFKJW.js');
var chunk2VL3DN2S_js = require('./chunk-2VL3DN2S.js');
var chunkF5BHRYDH_js = require('./chunk-F5BHRYDH.js');
var chunkQYXTD7XU_js = require('./chunk-QYXTD7XU.js');
var chunkH5EM4XHA_js = require('./chunk-H5EM4XHA.js');
var chunkSJGLR4O2_js = require('./chunk-SJGLR4O2.js');
var chunkOLGUSX5G_js = require('./chunk-OLGUSX5G.js');
var chunkSSZSQOGN_js = require('./chunk-SSZSQOGN.js');
var chunkHK7TFVDA_js = require('./chunk-HK7TFVDA.js');
var chunk4E3IDRQJ_js = require('./chunk-4E3IDRQJ.js');
var React = require('react');
var uuid = require('uuid');
var jsxRuntime = require('react/jsx-runtime');
var lucideReact = require('lucide-react');
var ReactMarkdown = require('react-markdown');
require('katex/dist/katex.min.css');
var rehypeKatex = require('rehype-katex');
var remarkGfm = require('remark-gfm');
var remarkMath = require('remark-math');
var hljs = require('highlight.js');
require('highlight.js/styles/github.min.css');
var zustand = require('zustand');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespace(React);
var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
var rehypeKatex__default = /*#__PURE__*/_interopDefault(rehypeKatex);
var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
var remarkMath__default = /*#__PURE__*/_interopDefault(remarkMath);
var hljs__default = /*#__PURE__*/_interopDefault(hljs);
// src/chat/components/message-parts/types.ts
var TextPartType = "text";
var ArtifactPartType = "data-artifact";
var EventPartType = "data-event";
var SourcesPartType = "data-sources";
var SuggestionPartType = "data-suggested_questions";
// src/chat/components/message-parts/utils.ts
function getParts(message, type) {
return message.parts.filter((part) => part.type === type);
}
// src/chat/components/canvas/artifacts.ts
function isEqualArtifact(a, b) {
return a.type === b.type && a.created_at === b.created_at;
}
function extractArtifactsFromAllMessages(messages) {
return messages.flatMap(extractArtifactsFromMessage).sort((a, b) => a.created_at - b.created_at);
}
function extractArtifactsFromMessage(message) {
return getParts(message, ArtifactPartType).map((part) => part.data);
}
// src/chat/components/chat.interface.ts
var MessageRole = {
System: "system",
User: "user",
Assistant: "assistant"
};
var chatContext = React.createContext(null);
var ChatProvider = chatContext.Provider;
var useChatUI = () => {
const context = React.useContext(chatContext);
if (!context) {
throw new Error("useChatUI must be used within a ChatProvider");
}
return context;
};
var ChatCanvasContext = React.createContext(
void 0
);
function ChatCanvasProvider({
children,
autoOpenCanvas = true
}) {
const { messages, isLoading, setMessages } = useChatUI();
const [isCanvasOpen, setIsCanvasOpen] = React.useState(false);
const [displayedArtifact, setDisplayedArtifact] = React.useState();
const allArtifacts = React.useMemo(
() => extractArtifactsFromAllMessages(messages),
[messages]
);
const artifactsFromLastMessage = React.useMemo(() => {
const lastMessage = messages[messages.length - 1];
if (!lastMessage) return [];
const artifacts = extractArtifactsFromMessage(lastMessage);
return artifacts;
}, [messages]);
React.useEffect(() => {
if (artifactsFromLastMessage.length > 0 && isLoading && autoOpenCanvas) {
setIsCanvasOpen(true);
setDisplayedArtifact(
artifactsFromLastMessage[artifactsFromLastMessage.length - 1]
);
}
}, [artifactsFromLastMessage, isCanvasOpen, isLoading, autoOpenCanvas]);
const openArtifactInCanvas = (artifact) => {
setDisplayedArtifact(artifact);
setIsCanvasOpen(true);
};
const getArtifactsByType = (type) => {
return allArtifacts.filter((a) => a.type === type);
};
const getArtifactVersion = (artifact) => {
const allArtifactsByCurrentType = getArtifactsByType(artifact.type);
const versionNumber = allArtifactsByCurrentType.findIndex((a) => isEqualArtifact(a, artifact)) + 1;
return {
versionNumber,
isLatest: versionNumber === allArtifactsByCurrentType.length
};
};
const restoreArtifact = (artifact) => {
if (!setMessages) return;
const newArtifact = chunk4E3IDRQJ_js.__spreadProps(chunk4E3IDRQJ_js.__spreadValues({}, artifact), {
created_at: Date.now()
});
const newMessages = [
...messages,
{
id: `restore-msg-${Date.now()}`,
role: MessageRole.User,
parts: [
{
type: TextPartType,
text: `Restore to ${artifact.type} version ${getArtifactVersion(artifact).versionNumber}`
}
]
},
{
id: `restore-success-${Date.now()}`,
role: MessageRole.Assistant,
parts: [
{
type: TextPartType,
text: `Successfully restored to ${artifact.type} version ${getArtifactVersion(artifact).versionNumber}`
},
{
type: ArtifactPartType,
data: newArtifact
}
]
}
];
setMessages(newMessages);
openArtifactInCanvas(newArtifact);
};
const updateArtifact = (artifact, data) => {
if (!setMessages) return;
const newArtifact = {
created_at: Date.now(),
type: artifact.type,
data
};
if (!newArtifact) return;
const newMessages = [
...messages,
{
id: uuid.v4(),
role: MessageRole.User,
parts: [
{
type: TextPartType,
text: `Update content for ${artifact.type} artifact version ${getArtifactVersion(artifact).versionNumber}`
}
]
},
{
id: uuid.v4(),
role: MessageRole.Assistant,
parts: [
{
type: TextPartType,
text: `Updated content for ${artifact.type} artifact version ${getArtifactVersion(artifact).versionNumber}`
},
{
type: ArtifactPartType,
data: newArtifact
}
]
}
];
setMessages(newMessages);
openArtifactInCanvas(newArtifact);
};
const closeCanvas = () => {
setIsCanvasOpen(false);
setDisplayedArtifact(void 0);
};
return /* @__PURE__ */ jsxRuntime.jsx(
ChatCanvasContext.Provider,
{
value: {
allArtifacts,
getArtifactsByType,
displayedArtifact,
isCanvasOpen,
openArtifactInCanvas,
closeCanvas,
getArtifactVersion,
restoreArtifact,
updateArtifact
},
children
}
);
}
function useChatCanvas() {
const context = React.useContext(ChatCanvasContext);
if (context === void 0) {
throw new Error("useChatCanvas must be used within a ChatCanvasProvider");
}
return context;
}
var chatInputContext = React.createContext(null);
var ChatInputProvider = chatInputContext.Provider;
var useChatInput = () => {
const context = React.useContext(chatInputContext);
if (!context) {
throw new Error("useChatInput must be used within a ChatInputProvider");
}
return context;
};
function ChatInput(props) {
var _a;
const { input, setInput, sendMessage, isLoading } = useChatUI();
const isDisabled = isLoading || !input.trim();
const [isComposing, setIsComposing] = React.useState(false);
const submit = async () => {
var _a2, _b;
const userMessage = {
id: uuid.v4(),
role: MessageRole.User,
parts: [
{ type: TextPartType, text: input },
...(_a2 = props.attachments) != null ? _a2 : []
]
};
setInput("");
(_b = props.resetUploadedFiles) == null ? void 0 : _b.call(props);
await sendMessage(userMessage);
};
const handleSubmit = async (e) => {
e.preventDefault();
await submit();
};
const handleKeyDown = async (e) => {
if (isDisabled) return;
if (e.key === "Enter" && !e.shiftKey && !isComposing) {
e.preventDefault();
await submit();
}
};
const children = (_a = props.children) != null ? _a : /* @__PURE__ */ jsxRuntime.jsx(ChatInputForm, {});
return /* @__PURE__ */ jsxRuntime.jsx(
ChatInputProvider,
{
value: {
isDisabled,
handleKeyDown,
handleSubmit,
isComposing,
setIsComposing
},
children: /* @__PURE__ */ jsxRuntime.jsx(
"div",
{
className: chunkHK7TFVDA_js.cn(
"bg-background flex shrink-0 flex-col gap-4 p-4 pt-0",
props.className
),
children
}
)
}
);
}
function ChatInputForm(props) {
var _a;
const { handleSubmit } = useChatInput();
const children = (_a = props.children) != null ? _a : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
/* @__PURE__ */ jsxRuntime.jsx(ChatInputField, {}),
/* @__PURE__ */ jsxRuntime.jsx(ChatInputSubmit, {})
] });
return /* @__PURE__ */ jsxRuntime.jsx(
"form",
{
onSubmit: handleSubmit,
className: chunkHK7TFVDA_js.cn("relative flex gap-2", props.className),
children
}
);
}
function ChatInputField(props) {
var _a;
const { input, setInput } = useChatUI();
const { handleKeyDown, setIsComposing } = useChatInput();
const textareaRef = React.useRef(null);
const handleInputChange = (e) => {
setInput(e.target.value);
if (textareaRef.current) {
textareaRef.current.style.height = "auto";
let newHeight = Math.max(textareaRef.current.scrollHeight, 100);
if (textareaRef.current.scrollHeight > 80) {
newHeight += 40;
}
textareaRef.current.style.height = `${newHeight}px`;
}
};
return /* @__PURE__ */ jsxRuntime.jsx(
chunkF5BHRYDH_js.Textarea,
{
ref: textareaRef,
name: "input",
placeholder: (_a = props.placeholder) != null ? _a : "Type a message...",
className: chunkHK7TFVDA_js.cn(
"bg-secondary h-[100px] max-h-[400px] min-h-0 flex-1 resize-none overflow-y-auto rounded-2xl p-4",
props.className
),
value: input,
onChange: handleInputChange,
onKeyDown: handleKeyDown,
onCompositionStart: () => setIsComposing(true),
onCompositionEnd: () => {
setTimeout(() => setIsComposing(false), 100);
},
spellCheck: false
}
);
}
function ChatInputUpload(props) {
var _a, _b;
const { isLoading } = useChatUI();
return /* @__PURE__ */ jsxRuntime.jsx(
chunkOLGUSX5G_js.FileUploader,
{
title: props.multiple ? "Upload Files" : "Upload File",
description: props.multiple ? "Attach multiple files" : "Attach a file",
multiple: (_a = props.multiple) != null ? _a : true,
allowedFileTypes: props.allowedFileTypes,
maxFileSizeBytes: ((_b = props.maxFileSizeMB) != null ? _b : 50) * 1024 * 1024,
onSuccess: async (uploaded) => {
var _a2;
await ((_a2 = props.onSuccess) == null ? void 0 : _a2.call(props, uploaded.map((u) => u.file)));
},
isProcessing: isLoading,
trigger: /* @__PURE__ */ jsxRuntime.jsx(
chunkSSZSQOGN_js.Button,
{
type: "button",
variant: "secondary",
size: "icon",
className: chunkHK7TFVDA_js.cn(
"absolute bottom-2 left-2 rounded-full",
props.className
),
children: "+"
}
)
}
);
}
function ChatInputSubmit(props) {
var _a, _b;
const { stop, isLoading } = useChatUI();
const { isDisabled } = useChatInput();
if (stop && isLoading) {
return /* @__PURE__ */ jsxRuntime.jsx(
chunkSSZSQOGN_js.Button,
{
type: "button",
size: "icon",
onClick: stop,
className: "absolute bottom-2 right-2 rounded-full",
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Square, { className: "size-3", fill: "white", stroke: "white" })
}
);
}
return /* @__PURE__ */ jsxRuntime.jsx(
chunkSSZSQOGN_js.Button,
{
type: "submit",
size: "icon",
disabled: (_a = props.disabled) != null ? _a : isDisabled,
className: chunkHK7TFVDA_js.cn("absolute bottom-2 right-2 rounded-full", props.className),
children: (_b = props.children) != null ? _b : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Send, { className: "size-4" })
}
);
}
ChatInput.Form = ChatInputForm;
ChatInput.Field = ChatInputField;
ChatInput.Upload = ChatInputUpload;
ChatInput.Submit = ChatInputSubmit;
var chat_input_default = ChatInput;
function useCopyToClipboard({
timeout = 2e3
}) {
const [isCopied, setIsCopied] = React__namespace.useState(false);
const copyToClipboard = (value) => {
var _a;
if (typeof window === "undefined" || !((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
return;
}
if (!value) {
return;
}
navigator.clipboard.writeText(value).then(() => {
setIsCopied(true);
setTimeout(() => {
setIsCopied(false);
}, timeout);
});
};
return { isCopied, copyToClipboard };
}
var chatMessageContext = React.createContext(
null
);
var ChatMessageProvider = chatMessageContext.Provider;
var useChatMessage = () => {
const context = React.useContext(chatMessageContext);
if (!context)
throw new Error("useChatMessage must be used within a ChatMessageProvider");
return context;
};
function ChatEvent({
event,
className,
renderData
}) {
const [isDataOpen, setIsDataOpen] = React.useState(false);
const getStatusIcon = () => {
switch (event.status) {
case "pending":
return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 animate-spin text-yellow-500" });
case "success":
return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCircle, { className: "h-4 w-4 text-green-500" });
case "error":
return /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XCircle, { className: "h-4 w-4 text-red-500" });
}
};
const getStatusColor = () => {
switch (event.status) {
case "pending":
return "border-yellow-400";
case "success":
return "border-green-400";
case "error":
return "border-red-400";
}
};
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunkHK7TFVDA_js.cn("border-l-2 py-2 pl-4", getStatusColor(), className), children: [
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "chat-event-header flex items-start justify-between", children: [
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
/* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-medium", children: event.title }),
event.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground mt-1 text-xs", children: event.description })
] }),
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ml-2 flex items-center space-x-1", children: [
getStatusIcon(),
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs capitalize", children: event.status })
] })
] }),
event.data && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "chat-event-data mt-3", children: /* @__PURE__ */ jsxRuntime.jsxs(chunk24LJTUUZ_js.Collapsible, { open: isDataOpen, onOpenChange: setIsDataOpen, children: [
/* @__PURE__ */ jsxRuntime.jsx(chunk24LJTUUZ_js.CollapsibleTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(chunkSSZSQOGN_js.Button, { variant: "ghost", size: "sm", className: "h-6 px-2 text-xs", children: [
isDataOpen ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: "mr-1 h-3 w-3" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { className: "mr-1 h-3 w-3" }),
isDataOpen ? "Hide data" : "Show data"
] }) }),
/* @__PURE__ */ jsxRuntime.jsx(chunk24LJTUUZ_js.CollapsibleContent, { children: renderData ? renderData(event.data) : /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "bg-muted mt-2 max-h-40 overflow-auto rounded p-2 text-xs", children: JSON.stringify(event.data, null, 2) }) })
] }) })
] });
}
function SourceNumberButton({
index,
className
}) {
return /* @__PURE__ */ jsxRuntime.jsx(
"span",
{
className: chunkHK7TFVDA_js.cn(
"inline-flex h-5 w-5 items-center justify-center rounded-full bg-gray-100 text-xs text-black",
className
),
children: index + 1
}
);
}
var DocxIcon = ({
width = 40,
height = 40,
className
}) => {
return /* @__PURE__ */ jsxRuntime.jsxs(
"svg",
{
width,
height,
viewBox: "-4 0 64 64",
xmlns: "http://www.w3.org/2000/svg",
className,
children: [
/* @__PURE__ */ jsxRuntime.jsxs("g", { fillRule: "evenodd", children: [
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "m5.11 0a5.07 5.07 0 0 0 -5.11 5v53.88a5.07 5.07 0 0 0 5.11 5.12h45.78a5.07 5.07 0 0 0 5.11-5.12v-38.6l-18.94-20.28z",
fill: "#107cad"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "m56 20.35v1h-12.82s-6.31-1.26-6.13-6.71c0 0 .21 5.71 6 5.71z",
fill: "#084968"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "m37.07 0v14.56a5.78 5.78 0 0 0 6.11 5.79h12.82z",
fill: "#90d0fe",
opacity: ".5"
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "m14.24 53.86h-3a1.08 1.08 0 0 1 -1.08-1.08v-9.85a1.08 1.08 0 0 1 1.08-1.08h3a6 6 0 1 1 0 12zm0-10.67h-2.61v9.34h2.61a4.41 4.41 0 0 0 4.61-4.66 4.38 4.38 0 0 0 -4.61-4.68zm14.42 10.89a5.86 5.86 0 0 1 -6-6.21 6 6 0 1 1 11.92 0 5.87 5.87 0 0 1 -5.92 6.21zm0-11.09c-2.7 0-4.41 2.07-4.41 4.88s1.71 4.88 4.41 4.88 4.41-2.09 4.41-4.88-1.72-4.87-4.41-4.87zm18.45.38a.75.75 0 0 1 .2.52.71.71 0 0 1 -.7.72.64.64 0 0 1 -.51-.24 4.06 4.06 0 0 0 -3-1.38 4.61 4.61 0 0 0 -4.63 4.88 4.63 4.63 0 0 0 4.63 4.88 4 4 0 0 0 3-1.37.7.7 0 0 1 .51-.24.72.72 0 0 1 .7.74.78.78 0 0 1 -.2.51 5.33 5.33 0 0 1 -4 1.69 6.22 6.22 0 0 1 0-12.43 5.26 5.26 0 0 1 4 1.72z",
fill: "#ffffff"
}
)
]
}
);
};
var PDFIcon = ({
className,
width = 40,
height = 40
}) => {
return /* @__PURE__ */ jsxRuntime.jsx(
"svg",
{
width,
height,
version: "1.1",
id: "Layer_1",
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
viewBox: "0 0 309.267 309.267",
className,
children: /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#E2574C" },
d: "M38.658,0h164.23l87.049,86.711v203.227c0,10.679-8.659,19.329-19.329,19.329H38.658\n c-10.67,0-19.329-8.65-19.329-19.329V19.329C19.329,8.65,27.989,0,38.658,0z"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#B53629" },
d: "M289.658,86.981h-67.372c-10.67,0-19.329-8.659-19.329-19.329V0.193L289.658,86.981z"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#FFFFFF" },
d: "M217.434,146.544c3.238,0,4.823-2.822,4.823-5.557c0-2.832-1.653-5.567-4.823-5.567h-18.44\n c-3.605,0-5.615,2.986-5.615,6.282v45.317c0,4.04,2.3,6.282,5.412,6.282c3.093,0,5.403-2.242,5.403-6.282v-12.438h11.153\n c3.46,0,5.19-2.832,5.19-5.644c0-2.754-1.73-5.49-5.19-5.49h-11.153v-16.903C204.194,146.544,217.434,146.544,217.434,146.544z\n M155.107,135.42h-13.492c-3.663,0-6.263,2.513-6.263,6.243v45.395c0,4.629,3.74,6.079,6.417,6.079h14.159\n c16.758,0,27.824-11.027,27.824-28.047C183.743,147.095,173.325,135.42,155.107,135.42z M155.755,181.946h-8.225v-35.334h7.413\n c11.221,0,16.101,7.529,16.101,17.918C171.044,174.253,166.25,181.946,155.755,181.946z M106.33,135.42H92.964\n c-3.779,0-5.886,2.493-5.886,6.282v45.317c0,4.04,2.416,6.282,5.663,6.282s5.663-2.242,5.663-6.282v-13.231h8.379\n c10.341,0,18.875-7.326,18.875-19.107C125.659,143.152,117.425,135.42,106.33,135.42z M106.108,163.158h-7.703v-17.097h7.703\n c4.755,0,7.78,3.711,7.78,8.553C113.878,159.447,110.863,163.158,106.108,163.158z"
}
)
] })
}
);
};
var SheetIcon = () => /* @__PURE__ */ jsxRuntime.jsxs(
"svg",
{
width: "49px",
height: "67px",
viewBox: "0 0 49 67",
version: "1.1",
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
children: [
/* @__PURE__ */ jsxRuntime.jsx("title", { children: "Sheets-icon" }),
/* @__PURE__ */ jsxRuntime.jsx("desc", { children: "Created with Sketch." }),
/* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "M29.5833333,0 L4.4375,0 C1.996875,0 0,1.996875 0,4.4375 L0,60.6458333 C0,63.0864583 1.996875,65.0833333 4.4375,65.0833333 L42.8958333,65.0833333 C45.3364583,65.0833333 47.3333333,63.0864583 47.3333333,60.6458333 L47.3333333,17.75 L29.5833333,0 Z",
id: "path-1"
}
),
/* @__PURE__ */ jsxRuntime.jsxs(
"linearGradient",
{
x1: "50.0053945%",
y1: "8.58610612%",
x2: "50.0053945%",
y2: "100.013939%",
id: "linearGradient-7",
children: [
/* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "#263238", stopOpacity: "0.2", offset: "0%" }),
/* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "#263238", stopOpacity: "0.02", offset: "100%" })
]
}
),
/* @__PURE__ */ jsxRuntime.jsxs(
"radialGradient",
{
cx: "3.16804688%",
cy: "2.71744318%",
fx: "3.16804688%",
fy: "2.71744318%",
r: "161.248516%",
gradientTransform: "translate(0.031680,0.027174),scale(1.000000,0.727273),translate(-0.031680,-0.027174)",
id: "radialGradient-16",
children: [
/* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "#FFFFFF", stopOpacity: "0.1", offset: "0%" }),
/* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "#FFFFFF", stopOpacity: "0", offset: "100%" })
]
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsx("g", { id: "Page-1", stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ jsxRuntime.jsx(
"g",
{
id: "Consumer-Apps-Sheets-Large-VD-R8-",
transform: "translate(-451.000000, -451.000000)",
children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Hero", transform: "translate(0.000000, 63.000000)", children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Personal", transform: "translate(277.000000, 299.000000)", children: /* @__PURE__ */ jsxRuntime.jsx("g", { id: "Sheets-icon", transform: "translate(174.833333, 89.958333)", children: /* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Group", children: [
/* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Clipped", children: [
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: "mask-2", fill: "white", children: /* @__PURE__ */ jsxRuntime.jsx("use", { xlinkHref: "#path-1" }) }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "M29.5833333,0 L4.4375,0 C1.996875,0 0,1.996875 0,4.4375 L0,60.6458333 C0,63.0864583 1.996875,65.0833333 4.4375,65.0833333 L42.8958333,65.0833333 C45.3364583,65.0833333 47.3333333,63.0864583 47.3333333,60.6458333 L47.3333333,17.75 L36.9791667,10.3541667 L29.5833333,0 Z",
id: "Path",
fill: "#0F9D58",
fillRule: "nonzero",
mask: "url(#mask-2)"
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Clipped", children: [
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: "mask-4", fill: "white", children: /* @__PURE__ */ jsxRuntime.jsx("use", { xlinkHref: "#path-1" }) }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "M11.8333333,31.8020833 L11.8333333,53.25 L35.5,53.25 L35.5,31.8020833 L11.8333333,31.8020833 Z M22.1875,50.2916667 L14.7916667,50.2916667 L14.7916667,46.59375 L22.1875,46.59375 L22.1875,50.2916667 Z M22.1875,44.375 L14.7916667,44.375 L14.7916667,40.6770833 L22.1875,40.6770833 L22.1875,44.375 Z M22.1875,38.4583333 L14.7916667,38.4583333 L14.7916667,34.7604167 L22.1875,34.7604167 L22.1875,38.4583333 Z M32.5416667,50.2916667 L25.1458333,50.2916667 L25.1458333,46.59375 L32.5416667,46.59375 L32.5416667,50.2916667 Z M32.5416667,44.375 L25.1458333,44.375 L25.1458333,40.6770833 L32.5416667,40.6770833 L32.5416667,44.375 Z M32.5416667,38.4583333 L25.1458333,38.4583333 L25.1458333,34.7604167 L32.5416667,34.7604167 L32.5416667,38.4583333 Z",
id: "Shape",
fill: "#F1F1F1",
fillRule: "nonzero",
mask: "url(#mask-4)"
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Clipped", children: [
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: "mask-6", fill: "white", children: /* @__PURE__ */ jsxRuntime.jsx("use", { xlinkHref: "#path-1" }) }),
/* @__PURE__ */ jsxRuntime.jsx(
"polygon",
{
id: "Path",
fill: "url(#linearGradient-7)",
fillRule: "nonzero",
mask: "url(#mask-6)",
points: "30.8813021 16.4520313 47.3333333 32.9003646 47.3333333 17.75"
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Clipped", children: [
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: "mask-9", fill: "white", children: /* @__PURE__ */ jsxRuntime.jsx("use", { xlinkHref: "#path-1" }) }),
/* @__PURE__ */ jsxRuntime.jsx("g", { id: "Group", mask: "url(#mask-9)", children: /* @__PURE__ */ jsxRuntime.jsx("g", { transform: "translate(26.625000, -2.958333)", children: /* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "M2.95833333,2.95833333 L2.95833333,16.2708333 C2.95833333,18.7225521 4.94411458,20.7083333 7.39583333,20.7083333 L20.7083333,20.7083333 L2.95833333,2.95833333 Z",
id: "Path",
fill: "#87CEAC",
fillRule: "nonzero"
}
) }) })
] }),
/* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Clipped", children: [
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: "mask-11", fill: "white", children: /* @__PURE__ */ jsxRuntime.jsx("use", { xlinkHref: "#path-1" }) }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "M4.4375,0 C1.996875,0 0,1.996875 0,4.4375 L0,4.80729167 C0,2.36666667 1.996875,0.369791667 4.4375,0.369791667 L29.5833333,0.369791667 L29.5833333,0 L4.4375,0 Z",
id: "Path",
fillOpacity: "0.2",
fill: "#FFFFFF",
fillRule: "nonzero",
mask: "url(#mask-11)"
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsxs("g", { id: "Clipped", children: [
/* @__PURE__ */ jsxRuntime.jsx("mask", { id: "mask-13", fill: "white", children: /* @__PURE__ */ jsxRuntime.jsx("use", { xlinkHref: "#path-1" }) }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
d: "M42.8958333,64.7135417 L4.4375,64.7135417 C1.996875,64.7135417 0,62.7166667 0,60.2760417 L0,60.6458333 C0,63.0864583 1.996875,65.0833333 4.4375,65.0833333 L42.8958333,65.0833333 C45.3364583,65.0833333 47.3333333,63.0864583 47.3333333,60.6458333 L47.3333333,25.1666667 L42.8958333,21.0208333 L42.8958333,64.7135417 Z",
id: "Path",
fill: "url(#radialGradient-16)",
fillRule: "nonzero",
mask: "url(#mask-13)"
}
)
] })
] }) }) }) })
}
) })
]
}
);
var TxtIcon = ({
className,
width = 40,
height = 40
}) => {
return /* @__PURE__ */ jsxRuntime.jsxs(
"svg",
{
width,
height,
version: "1.1",
id: "Layer_1",
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
viewBox: "0 0 512 512",
className,
children: [
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#E2E5E7" },
d: "M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#B0B7BD" },
d: "M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"
}
),
/* @__PURE__ */ jsxRuntime.jsx("polygon", { style: { fill: "#CAD1D8" }, points: "480,224 384,128 480,128 " }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#576D7E" },
d: "M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16V416z"
}
),
/* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#FFFFFF" },
d: "M132.784,311.472H110.4c-11.136,0-11.136-16.368,0-16.368h60.512c11.392,0,11.392,16.368,0,16.368h-21.248v64.592c0,11.12-16.896,11.392-16.896,0v-64.592H132.784z"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#FFFFFF" },
d: "M224.416,326.176l22.272-27.888c6.656-8.688,19.568,2.432,12.288,10.752c-7.68,9.088-15.728,18.944-23.424,29.024l26.112,32.496c7.024,9.6-7.04,18.816-13.952,9.344l-23.536-30.192l-23.152,30.832c-6.528,9.328-20.992-1.152-13.68-9.856l25.696-32.624c-8.048-10.096-15.856-19.936-23.664-29.024c-8.064-9.6,6.912-19.44,12.784-10.48L224.416,326.176z"
}
),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#FFFFFF" },
d: "M298.288,311.472H275.92c-11.136,0-11.136-16.368,0-16.368h60.496c11.392,0,11.392,16.368,0,16.368h-21.232v64.592c0,11.12-16.896,11.392-16.896,0V311.472z"
}
)
] }),
/* @__PURE__ */ jsxRuntime.jsx(
"path",
{
style: { fill: "#CAD1D8" },
d: "M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"
}
)
]
}
);
};
function DocumentInfo({
document: document2,
className,
onRemove,
startIndex = 0
}) {
var _a;
const { openArtifactInCanvas } = useChatCanvas();
const { url, sources } = document2;
const urlParts = url.split("/");
const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url;
const fileExt = (_a = fileName == null ? void 0 : fileName.split(".").pop()) != null ? _a : "";
const previewFile = {
name: fileName,
type: fileExt
};
const DocumentDetail = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `bg-secondary rounded-lg p-2 ${className}`, children: [
/* @__PURE__ */ jsxRuntime.jsx(
DocumentPreviewCard,
{
className: "cursor-pointer",
file: previewFile,
onRemove
}
),
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex max-w-60 flex-wrap space-x-2 px-2", children: sources.map((node, index) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(SourceInfo, { node, index: startIndex + index }) }, node.id)) })
] });
if (url.endsWith(".pdf")) {
return /* @__PURE__ */ jsxRuntime.jsx(
"div",
{
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
openArtifactInCanvas({
type: "document" /* Document */,
created_at: Date.now(),
data: {
url
}
});
},
children: DocumentDetail
}
);
}
return /* @__PURE__ */ jsxRuntime.jsx("div", { onClick: () => window.open(url, "_blank"), children: DocumentDetail });
}
function SourceInfo({ node, index }) {
if (!node) return /* @__PURE__ */ jsxRuntime.jsx(SourceNumberButton, { index });
return /* @__PURE__ */ jsxRuntime.jsxs(chunkJGFWFKJW_js.HoverCard, { openDelay: 100, closeDelay: 100, children: [
/* @__PURE__ */ jsxRuntime.jsx(
chunkJGFWFKJW_js.HoverCardTrigger,
{
className: "cursor-default",
onClick: (e) => {
e.preventDefault();
e.stopPropagation();
},
children: /* @__PURE__ */ jsxRuntime.jsx(
SourceNumberButton,
{
index,
className: "hover:bg-primary hover:text-white"
}
)
}
),
/* @__PURE__ */ jsxRuntime.jsx(
chunkJGFWFKJW_js.HoverCardContent,
{
className: "w-[400px]",
onClick: (e) => e.stopPropagation(),
children: /* @__PURE__ */ jsxRuntime.jsx(NodeInfo, { nodeInfo: node })
}
)
] });
}
function NodeInfo({ nodeInfo }) {
var _a, _b, _c, _d;
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 1e3 });
const pageNumber = (
// XXX: page_label is used in Python, but page_number is used by Typescript
(_d = (_c = (_a = nodeInfo.metadata) == null ? void 0 : _a.page_number) != null ? _c : (_b = nodeInfo.metadata) == null ? void 0 : _b.page_label) != null ? _d : null
);
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: pageNumber ? `On page ${pageNumber}:` : "Node content:" }),
nodeInfo.text && /* @__PURE__ */ jsxRuntime.jsx(
chunkSSZSQOGN_js.Button,
{
onClick: (e) => {
e.stopPropagation();
copyToClipboard(nodeInfo.text);
},
size: "icon",
variant: "ghost",
className: "h-3 w-3 shrink-0",
children: isCopied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "h-4 w-4" })
}
)
] }),
nodeInfo.text && /* @__PURE__ */ jsxRuntime.jsxs("pre", { className: "max-h-[200px] overflow-auto whitespace-pre-line", children: [
"\u201C",
nodeInfo.text,
"\u201D"
] })
] });
}
var FileIconMap = {
csv: /* @__PURE__ */ jsxRuntime.jsx(SheetIcon, {}),
pdf: /* @__PURE__ */ jsxRuntime.jsx(PDFIcon, {}),
docx: /* @__PURE__ */ jsxRuntime.jsx(DocxIcon, {}),
txt: /* @__PURE__ */ jsxRuntime.jsx(TxtIcon, {})
};
function DocumentPreviewCard(props) {
var _a;
const { onRemove, file, className } = props;
return /* @__PURE__ */ jsxRuntime.jsxs(
"div",
{
className: chunkHK7TFVDA_js.cn(
"bg-secondary relative w-60 max-w-60 rounded-lg p-2 text-sm",
className
),
children: [
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2", children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-md", children: (_a = FileIconMap[file.type]) != null ? _a : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.FileIcon, {}) }),
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "overflow-hidden", children: [
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "truncate font-semibold", children: [
file.name,
" ",
file.size ? `(${inKB(file.size)} KB)` : ""
] }),
file.type && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-token-text-tertiary flex items-center gap-2 truncate", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
file.type.toUpperCase(),
" File"
] }) })
] })
] }),
onRemove && /* @__PURE__ */ jsxRuntime.jsx(
"div",
{
className: chunkHK7TFVDA_js.cn(
"absolute -right-2 -top-2 z-10 h-6 w-6 rounded-full bg-gray-500 text-white"
),
children: /* @__PURE__ */ jsxRuntime.jsx(
lucideReact.XCircleIcon,
{
className: "h-6 w-6 rounded-full bg-gray-500 text-white",
onClick: (e) => {
e.stopPropagation();
onRemove();
}
}
)
}
)
]
}
);
}
function inKB(size) {
return Math.round(size / 1024 * 10) / 10;
}
function preprocessSourceNodes(nodes) {
const processedNodes = nodes.map((node) => {
if (node.url) {
node.url = node.url.replace(/\/$/, "");
}
return node;
});
return processedNodes;
}
function ChatSources({
data,
className
}) {
const documents = React.useMemo(() => {
const nodesByUrl = {};
data.nodes.filter((node) => node.url).forEach((node) => {
var _a, _b;
const key = (_a = node.url) != null ? _a : "";
(_b = nodesByUrl[key]) != null ? _b : nodesByUrl[key] = [];
nodesByUrl[key].push(node);
});
return Object.entries(nodesByUrl).map(([url, sources]) => ({
url,
sources
}));
}, [data.nodes]);
if (documents.length === 0) return null;
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: chunkHK7TFVDA_js.cn("space-y-2 text-sm", className), children: [
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-lg font-semibold", children: "Sources:" }),
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-3", children: documents.map((document2, index) => {
const startIndex = documents.slice(0, index).reduce((acc, doc) => acc + doc.sources.length, 0);
return /* @__PURE__ */ jsxRuntime.jsx(
DocumentInfo,
{
document: document2,
startIndex
},
document2.url
);
}) })
] });
}
function Citation({ index }) {
return /* @__PURE__ */ jsxRuntime.jsx(SourceNumberButton, { index });
}
var programmingLanguages = {
javascript: ".js",
python: ".py",
java: ".java",
c: ".c",
cpp: ".cpp",
"c++": ".cpp",
"c#": ".cs",
ruby: ".rb",
php: ".php",
swift: ".swift",
"objective-c": ".m",
kotlin: ".kt",
typescript: ".ts",
go: ".go",
perl: ".pl",
rust: ".rs",
scala: ".scala",
haskell: ".hs",
lua: ".lua",
shell: ".sh",
sql: ".sql",
html: ".html",
css: ".css"
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
};
var generateRandomString = (length, lowercase = false) => {
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789";
let result = "";
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return lowercase ? result.toLowerCase() : result;
};
var LANGUAGE_ALIASES = {
ts: "typescript",
tsx: "typescript",
js: "javascript",
jsx: "javascript",
py: "python",
sh: "shell",
bash: "shell",
md: "markdown",
yml: "yaml"
};
var CodeBlock = React.memo((props) => {
var _a;
const {
language,
value,
className,
headerClassName,
codeClassName,
showHeader = true
} = props;
const { isCopied, copyToClipboard } = useCopyToClipboard({ timeout: 2e3 });
const codeRef = React.useRef(null);
React.useEffect(() => {
if (codeRef.current && codeRef.current.dataset.highlighted !== "yes") {
hljs__default.default.highlightElement(codeRef.current);
}
}, [language, value]);
const downloadAsFile = () => {
if (typeof window === "undefined") {
return;
}
const fileExtension = programmingLanguages[language] || ".file";
const suggestedFileName = `file-${generateRandomString(
3,
true
)}${fileExtension}`;
const fileName = window.prompt("Enter file name", suggestedFileName);
if (!fileName) {
return;
}
const blob = new Blob([value], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.download = fileName;
link.href = url;
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
const onCopy = () => {
if (isCopied) return;
copyToClipboard(value);
};
return /* @__PURE__ */ jsxRuntime.jsxs(
"div",
{
className: chunkHK7TFVDA_js.cn(
"codeblock border-border relative w-full rounded-lg border bg-secondary pt-2",
className
),
children: [
showHeader && /* @__PURE__ */ jsxRuntime.jsxs(
"div",
{
className: chunkHK7TFVDA_js.cn(
"flex w-full items-center justify-between px-3",
headerClassName
),
children: [
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs lowercase", children: language }),
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center space-x-1", children: [
/* @__PURE__ */ jsxRuntime.jsxs(
chunkSSZSQOGN_js.Button,
{
variant: "ghost",
onClick: downloadAsFile,
size: "icon",
className: "size-8",
children: [
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Download, { className: "size-4" }),
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Download" })
]
}
),
/* @__PURE__ */ jsxRuntime.jsxs(
chunkSSZSQOGN_js.Button,
{
variant: "ghost",
size: "icon",
onClick: onCopy,
className: "size-8",
children: [
isCopied ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Copy, { className: "size-4" }),
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Copy code" })
]
}
)
] })
]
}
),
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "m-0 max-w-full overflow-x-auto rounded-b-lg text-[13px] leading-6", children: /* @__PURE__ */ jsxRuntime.jsx(
"code",
{
ref: codeRef,
className: chunkHK7TFVDA_js.cn(
`language-${(_a = LANGUAGE_ALIASES[language]) != null ? _a : language} font-mono`,
codeClassName
),
children: value
}
) })
]
}
);
});
CodeBlock.displayName = "CodeBlock";
var MemoizedReactMarkdown = React.memo(
ReactMarkdown__default.default,
(prevProps, nextProps) => prevProps.children === nextProps.children
);
var preprocessLaTeX = (content) => {
const codeBlockPlaceholders = [];
const inlineCodePlaceholders = [];
let processedContent = content.replace(/```[\s\S]*?```/g, (match) => {
const placeholder = `__CODE_BLOCK_${codeBlockPlaceholders.length}__`;
codeBlockPlaceholders.push(match);
return placeholder;
});
processedContent = processedContent.replace(/`[^`\n]+`/g, (match) => {
const placeholder = `__INLINE_CODE_${inlineCodePlaceholders.length}__`;
inlineCodePlaceholders.push(match);
return placeholder;
});
const blockProcessedContent = processedContent.replace(
/\\\[([\s\S]*?)\\\]/g,
(_, equation) => `$$${equation}$$`
);
let inlineProcessedContent = blockProcessedContent.replace(
/\\\(([\s\S]*?)\\\)/g,
(_, equation) => `$${equation}$`
);
codeBlockPlaceholders.forEach((codeBlock, index) => {
inlineProcessedContent = inlineProcessedContent.replace(
`__CODE_BLOCK_${index}__`,
codeBlock
);
});
inlineCodePlaceholders.forEach((inlineCode, index) => {
inlineProcessedContent = inlineProcessedContent.replace(
`__INLINE_CODE_${index}__`,
inlineCode
);
});
return inlineProcessedContent;
};
var preprocessMedia = (content) => {
return content.replace(/(sandbox|attachment|snt):/g, "");
};
var preprocessCitations = (input) => {
let content = input;
const idToIndexRegex = /\[citation:([^\]]+)\]/g;
content = content.replace(idToIndexRegex, (match, citationId) => {
const trimmedId = citationId.trim();
return `[citation:${trimmedId}](javascript:void(0))`;
});
const incompleteRegex = /\[citation:[^\]]*$/g;
content = content.replace(incompleteRegex, "");
return content;
};
var preprocessContent = (content) => {
return preprocessCitations(preprocessLaTeX(preprocessMedia(content)));
};
function combineComponent(component, fallback) {
return (props) => (component == null ? void 0 : component(props)) || fallback(props);
}
function Markdown({
content,
sources,
backend,
citationComponent: CitationComponent,
className: customClassName,
components,
languageRenderers
}) {
const processedContent = preprocessContent(content);
return /* @__PURE__ */ jsxRuntime.jsx(
"div",
{
className: chunkHK7TFVDA_js.cn(
"prose dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 custom-markdown break-words",
customClassName
),
children: /* @__PURE__ */ jsxRuntime.jsx(
MemoizedReactMarkdown,
{
remarkPlugins: [remarkGfm__default.default, remarkMath__default.default],
rehypePlugins: [rehypeKatex__default.default],
components: chunk4E3IDRQJ_js.__spreadProps(chunk4E3IDRQJ_js.__spreadValues({}, components), {
h1: combineComponent(components == null ? void 0 : components.h1, ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "mt-0 mb-3 text-xl font-semibold", children })),
h2: combineComponent(components == null ? void 0 : components.h2, ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "mt-4 mb-2 text-lg font-semibold", children })),
h3: combineComponent(components == null ? void 0 : components.h3, ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "mt-3 mb-2 text-base font-semibold", children })),
h4: combineComponent(components == null ? void 0 : components.h4, ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h4", { className: "mt-3 mb-1 text-base font-medium", children })),
h5: combineComponent(components == null ? void 0 : components.h5, ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h5", { className: "mt-2 mb-1 text-sm font-medium", children })),
h6: combineComponent(components == null ? void 0 : components.h6, ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h6", { className: "mt-2 mb-1 text-sm", children })),
p: combineComponent(components == null ? void 0 : components.p, ({ children }) => {
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-2 last:mb-0 leading-7", children });
}),
ul: (_a) => {
var _b = _a, { children, className } = _b, rest = chunk4E3IDRQJ_js.__objRest(_b, ["children", "className"]);
const isTaskList = className == null ? void 0 : className.includes("contains-task-list");
return /* @__PURE__ */ jsxRuntime.jsx(
"ul",
chunk4E3IDRQJ_js.__spreadProps(chunk4E3IDRQJ_js.__spreadValues({}, rest), {
className: chunkHK7TFVDA_js.cn(
"my-2 space-y-1",
isTaskList ? "ml-0 list-none" : "ml-5 list-disc"
),
children
})
);
},
ol: (_c) => {
var _d = _c, { children } = _d, rest = chunk4E3IDRQJ_js.__objRest(_d, ["children"]);
return /* @__PURE__ */ jsxRuntime.jsx("ol", chunk4E3IDRQJ_js.__spreadProps(chunk4E3IDRQJ_js.__spreadValues({}, rest), { className: "my-2 ml-5 list-decimal space-y-1", children }));
},
li: (_e) => {
var _f = _e, { children, className } = _f, rest = chunk4E3IDRQJ_js.__objRest(_f, ["children", "className"]);
const isTaskItem = className == null ? void 0 : className.includes("task-list-item");
return /* @__PURE__ */ jsxRuntime.jsx(
"li",
chunk4E3IDRQJ_js.__spreadProps(chunk4E3IDRQJ_js.__spreadValues({}, rest), {