forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorMessage.tsx
More file actions
63 lines (56 loc) · 1.74 KB
/
Copy pathErrorMessage.tsx
File metadata and controls
63 lines (56 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { ErrorMessageProps } from "../props";
import { useChatContext } from "../ChatContext";
import { Markdown } from "../Markdown";
import { useState } from "react";
import { copyToClipboard } from "@copilotkit/shared";
export const ErrorMessage = (props: ErrorMessageProps) => {
const { icons, labels } = useChatContext();
const { error, onRegenerate, onCopy, isCurrentMessage } = props;
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
const content = error.message;
if (!content) return;
const success = await copyToClipboard(content);
if (success) {
setCopied(true);
if (onCopy) onCopy(content);
setTimeout(() => setCopied(false), 2000);
}
};
const handleRegenerate = () => {
if (onRegenerate) onRegenerate();
};
console.log(error);
return (
<div
data-testid="copilot-error-banner"
className="copilotKitMessage copilotKitAssistantMessage"
>
<Markdown content={error.message} />
<div
className={`copilotKitMessageControls ${isCurrentMessage ? "currentMessage" : ""}`}
>
<button
className="copilotKitMessageControlButton"
onClick={handleRegenerate}
aria-label={labels.regenerateResponse}
title={labels.regenerateResponse}
>
{icons.regenerateIcon}
</button>
<button
className="copilotKitMessageControlButton"
onClick={handleCopy}
aria-label={labels.copyToClipboard}
title={labels.copyToClipboard}
>
{copied ? (
<span style={{ fontSize: "10px", fontWeight: "bold" }}>✓</span>
) : (
icons.copyIcon
)}
</button>
</div>
</div>
);
};