-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathAssistantInput.tsx
More file actions
73 lines (68 loc) · 2.09 KB
/
AssistantInput.tsx
File metadata and controls
73 lines (68 loc) · 2.09 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
64
65
66
67
68
69
70
71
72
73
import React, { useCallback } from "react";
import { Markdown } from "../Markdown";
import { Container, Box } from "@radix-ui/themes";
import { ToolCall } from "../../services/refact";
import { ToolContent } from "./ToolsContent";
import { fallbackCopying } from "../../utils/fallbackCopying";
import { telemetryApi } from "../../services/refact/telemetry";
import { LikeButton } from "./LikeButton";
type ChatInputProps = {
message: string | null;
toolCalls?: ToolCall[] | null;
isLast?: boolean;
};
export const AssistantInput: React.FC<ChatInputProps> = ({
message,
toolCalls,
isLast,
}) => {
const [sendTelemetryEvent] =
telemetryApi.useLazySendTelemetryChatEventQuery();
const handleCopy = useCallback(
(text: string) => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (window.navigator?.clipboard?.writeText) {
void window.navigator.clipboard
.writeText(text)
.catch(() => {
// eslint-disable-next-line no-console
console.log("failed to copy to clipboard");
void sendTelemetryEvent({
scope: `codeBlockCopyToClipboard`,
success: false,
error_message:
"window.navigator?.clipboard?.writeText: failed to copy to clipboard",
});
})
.then(() => {
void sendTelemetryEvent({
scope: `codeBlockCopyToClipboard`,
success: true,
error_message: "",
});
});
} else {
fallbackCopying(text);
void sendTelemetryEvent({
scope: `codeBlockCopyToClipboard`,
success: true,
error_message: "",
});
}
},
[sendTelemetryEvent],
);
return (
<Container position="relative">
{message && (
<Box py="4">
<Markdown canHaveInteractiveElements={true} onCopyClick={handleCopy}>
{message}
</Markdown>
</Box>
)}
{toolCalls && <ToolContent toolCalls={toolCalls} />}
{isLast && <LikeButton />}
</Container>
);
};