177 lines
9.5 KiB
JavaScript
177 lines
9.5 KiB
JavaScript
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
const require_CopilotChatConfigurationProvider = require('../../providers/CopilotChatConfigurationProvider.cjs');
|
|
const require_button = require('../ui/button.cjs');
|
|
const require_tooltip = require('../ui/tooltip.cjs');
|
|
const require_slots = require('../../lib/slots.cjs');
|
|
const require_useKatexStyles = require('../../hooks/useKatexStyles.cjs');
|
|
const require_CopilotChatToolCallsView = require('./CopilotChatToolCallsView.cjs');
|
|
let react = require("react");
|
|
let tailwind_merge = require("tailwind-merge");
|
|
let lucide_react = require("lucide-react");
|
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
let streamdown = require("streamdown");
|
|
|
|
//#region src/components/chat/CopilotChatAssistantMessage.tsx
|
|
function CopilotChatAssistantMessage({ message, messages, isRunning, onThumbsUp, onThumbsDown, onReadAloud, onRegenerate, additionalToolbarItems, toolbarVisible = true, markdownRenderer, toolbar, copyButton, thumbsUpButton, thumbsDownButton, readAloudButton, regenerateButton, toolCallsView, children, className, ...props }) {
|
|
require_useKatexStyles.useKatexStyles();
|
|
const boundMarkdownRenderer = require_slots.renderSlot(markdownRenderer, CopilotChatAssistantMessage.MarkdownRenderer, { content: message.content || "" });
|
|
const boundCopyButton = require_slots.renderSlot(copyButton, CopilotChatAssistantMessage.CopyButton, { onClick: async () => {
|
|
if (message.content) try {
|
|
await navigator.clipboard.writeText(message.content);
|
|
} catch (err) {
|
|
console.error("Failed to copy message:", err);
|
|
}
|
|
} });
|
|
const boundThumbsUpButton = require_slots.renderSlot(thumbsUpButton, CopilotChatAssistantMessage.ThumbsUpButton, { onClick: onThumbsUp });
|
|
const boundThumbsDownButton = require_slots.renderSlot(thumbsDownButton, CopilotChatAssistantMessage.ThumbsDownButton, { onClick: onThumbsDown });
|
|
const boundReadAloudButton = require_slots.renderSlot(readAloudButton, CopilotChatAssistantMessage.ReadAloudButton, { onClick: onReadAloud });
|
|
const boundRegenerateButton = require_slots.renderSlot(regenerateButton, CopilotChatAssistantMessage.RegenerateButton, { onClick: onRegenerate });
|
|
const boundToolbar = require_slots.renderSlot(toolbar, CopilotChatAssistantMessage.Toolbar, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
className: "cpk:flex cpk:items-center cpk:gap-1",
|
|
children: [
|
|
boundCopyButton,
|
|
(onThumbsUp || thumbsUpButton) && boundThumbsUpButton,
|
|
(onThumbsDown || thumbsDownButton) && boundThumbsDownButton,
|
|
(onReadAloud || readAloudButton) && boundReadAloudButton,
|
|
(onRegenerate || regenerateButton) && boundRegenerateButton,
|
|
additionalToolbarItems
|
|
]
|
|
}) });
|
|
const boundToolCallsView = require_slots.renderSlot(toolCallsView, require_CopilotChatToolCallsView.default, {
|
|
message,
|
|
messages
|
|
});
|
|
const hasContent = !!(message.content && message.content.trim().length > 0);
|
|
const isLatestAssistantMessage = message.role === "assistant" && messages?.[messages.length - 1]?.id === message.id;
|
|
const shouldShowToolbar = toolbarVisible && hasContent && !(isRunning && isLatestAssistantMessage);
|
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
"data-copilotkit": true,
|
|
style: { display: "contents" },
|
|
children: children({
|
|
markdownRenderer: boundMarkdownRenderer,
|
|
toolbar: boundToolbar,
|
|
toolCallsView: boundToolCallsView,
|
|
copyButton: boundCopyButton,
|
|
thumbsUpButton: boundThumbsUpButton,
|
|
thumbsDownButton: boundThumbsDownButton,
|
|
readAloudButton: boundReadAloudButton,
|
|
regenerateButton: boundRegenerateButton,
|
|
message,
|
|
messages,
|
|
isRunning,
|
|
onThumbsUp,
|
|
onThumbsDown,
|
|
onReadAloud,
|
|
onRegenerate,
|
|
additionalToolbarItems,
|
|
toolbarVisible: shouldShowToolbar
|
|
})
|
|
});
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
"data-copilotkit": true,
|
|
"data-testid": "copilot-assistant-message",
|
|
className: (0, tailwind_merge.twMerge)("copilotKitMessage copilotKitAssistantMessage", className),
|
|
...props,
|
|
"data-message-id": message.id,
|
|
children: [
|
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
className: "cpk:prose cpk:max-w-full cpk:break-words cpk:dark:prose-invert",
|
|
children: boundMarkdownRenderer
|
|
}),
|
|
boundToolCallsView,
|
|
shouldShowToolbar && boundToolbar
|
|
]
|
|
});
|
|
}
|
|
(function(_CopilotChatAssistantMessage) {
|
|
_CopilotChatAssistantMessage.MarkdownRenderer = ({ content, className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(streamdown.Streamdown, {
|
|
className,
|
|
...props,
|
|
children: content ?? ""
|
|
});
|
|
_CopilotChatAssistantMessage.Toolbar = ({ className, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
"data-testid": "copilot-assistant-toolbar",
|
|
className: (0, tailwind_merge.twMerge)("cpk:w-full cpk:bg-transparent cpk:flex cpk:items-center cpk:-ml-[5px] cpk:-mt-[0px]", className),
|
|
...props
|
|
});
|
|
const ToolbarButton = _CopilotChatAssistantMessage.ToolbarButton = ({ title, children, ...props }) => {
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_tooltip.TooltipTrigger, {
|
|
asChild: true,
|
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_button.Button, {
|
|
type: "button",
|
|
variant: "assistantMessageToolbarButton",
|
|
"aria-label": title,
|
|
...props,
|
|
children
|
|
})
|
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_tooltip.TooltipContent, {
|
|
side: "bottom",
|
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: title })
|
|
})] });
|
|
};
|
|
_CopilotChatAssistantMessage.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
const labels = require_CopilotChatConfigurationProvider.useCopilotChatConfiguration()?.labels ?? require_CopilotChatConfigurationProvider.CopilotChatDefaultLabels;
|
|
const [copied, setCopied] = (0, react.useState)(false);
|
|
const handleClick = (event) => {
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2e3);
|
|
if (onClick) onClick(event);
|
|
};
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
"data-testid": "copilot-copy-button",
|
|
title: title || labels.assistantMessageToolbarCopyMessageLabel,
|
|
onClick: handleClick,
|
|
className,
|
|
...props,
|
|
children: copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Check, { className: "cpk:size-[18px]" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, { className: "cpk:size-[18px]" })
|
|
});
|
|
};
|
|
_CopilotChatAssistantMessage.ThumbsUpButton = ({ title, ...props }) => {
|
|
const labels = require_CopilotChatConfigurationProvider.useCopilotChatConfiguration()?.labels ?? require_CopilotChatConfigurationProvider.CopilotChatDefaultLabels;
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
"data-testid": "copilot-thumbs-up-button",
|
|
title: title || labels.assistantMessageToolbarThumbsUpLabel,
|
|
...props,
|
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ThumbsUp, { className: "cpk:size-[18px]" })
|
|
});
|
|
};
|
|
_CopilotChatAssistantMessage.ThumbsDownButton = ({ title, ...props }) => {
|
|
const labels = require_CopilotChatConfigurationProvider.useCopilotChatConfiguration()?.labels ?? require_CopilotChatConfigurationProvider.CopilotChatDefaultLabels;
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
"data-testid": "copilot-thumbs-down-button",
|
|
title: title || labels.assistantMessageToolbarThumbsDownLabel,
|
|
...props,
|
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ThumbsDown, { className: "cpk:size-[18px]" })
|
|
});
|
|
};
|
|
_CopilotChatAssistantMessage.ReadAloudButton = ({ title, ...props }) => {
|
|
const labels = require_CopilotChatConfigurationProvider.useCopilotChatConfiguration()?.labels ?? require_CopilotChatConfigurationProvider.CopilotChatDefaultLabels;
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
"data-testid": "copilot-read-aloud-button",
|
|
title: title || labels.assistantMessageToolbarReadAloudLabel,
|
|
...props,
|
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Volume2, { className: "cpk:size-[20px]" })
|
|
});
|
|
};
|
|
_CopilotChatAssistantMessage.RegenerateButton = ({ title, ...props }) => {
|
|
const labels = require_CopilotChatConfigurationProvider.useCopilotChatConfiguration()?.labels ?? require_CopilotChatConfigurationProvider.CopilotChatDefaultLabels;
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ToolbarButton, {
|
|
"data-testid": "copilot-regenerate-button",
|
|
title: title || labels.assistantMessageToolbarRegenerateLabel,
|
|
...props,
|
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.RefreshCw, { className: "cpk:size-[18px]" })
|
|
});
|
|
};
|
|
})(CopilotChatAssistantMessage || (CopilotChatAssistantMessage = {}));
|
|
CopilotChatAssistantMessage.MarkdownRenderer.displayName = "CopilotChatAssistantMessage.MarkdownRenderer";
|
|
CopilotChatAssistantMessage.Toolbar.displayName = "CopilotChatAssistantMessage.Toolbar";
|
|
CopilotChatAssistantMessage.CopyButton.displayName = "CopilotChatAssistantMessage.CopyButton";
|
|
CopilotChatAssistantMessage.ThumbsUpButton.displayName = "CopilotChatAssistantMessage.ThumbsUpButton";
|
|
CopilotChatAssistantMessage.ThumbsDownButton.displayName = "CopilotChatAssistantMessage.ThumbsDownButton";
|
|
CopilotChatAssistantMessage.ReadAloudButton.displayName = "CopilotChatAssistantMessage.ReadAloudButton";
|
|
CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistantMessage.RegenerateButton";
|
|
var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
|
|
//#endregion
|
|
exports.default = CopilotChatAssistantMessage_default;
|
|
//# sourceMappingURL=CopilotChatAssistantMessage.cjs.map
|