-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathmessage-card.tsx
More file actions
103 lines (93 loc) · 2.93 KB
/
message-card.tsx
File metadata and controls
103 lines (93 loc) · 2.93 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { cn } from "@heroui/react";
import { memo } from "react";
import Tools from "./message-entry-container/tools/tools";
import { AssistantMessageContainer } from "./message-entry-container/assistant";
import { UserMessageContainer } from "./message-entry-container/user";
import { ToolCallPrepareMessageContainer } from "./message-entry-container/toolcall-prepare";
import { UnknownEntryMessageContainer } from "./message-entry-container/unknown-entry";
import { DisplayMessage } from "../stores/types";
// Constants
export const STYLES = {
container: {
base: "flex! flex-row! gap-2!",
assistant: "",
indicator: "",
},
messageWrapper: {
base: "max-w-full! flex! flex-col! gap-4!",
assistant: "max-w-full!",
user: "max-w-[70%]!",
indicator: "w-full!",
},
messageBox: {
base: cn(),
assistant: "px-3 pt-3 pb-1 my-2 border! border-transparent!",
user: "px-3 py-2 bg-gray-100 dark:!bg-default-200 self-end my-2",
indicator: "px-3",
},
attachment: {
content: "max-w-[300px]! !bg-default-100 dark:!bg-default-100",
text: "!text-tiny !text-default-400",
},
} as const;
// Types
interface MessageCardProps {
message: DisplayMessage;
prevAttachment?: string;
animated?: boolean;
}
export const MessageCard = memo(({ message, prevAttachment, animated }: MessageCardProps) => {
const isStale = message.status === "stale";
const isPreparing = message.status === "streaming";
const returnComponent = () => {
if (message.type === "toolCall") {
return (
<div className="chat-message-entry rnd-cancel">
<Tools
messageId={message.id}
functionName={message.toolName || "Unknown Tool Name"}
message={message.toolResult ?? ""}
error={message.toolError ?? ""}
preparing={isPreparing}
animated={animated ?? false}
/>
</div>
);
}
if (message.type === "assistant") {
return (
<AssistantMessageContainer
message={message.content}
reasoning={message.reasoning}
messageId={message.id}
animated={animated ?? false}
prevAttachment={prevAttachment ?? ""}
stale={isStale}
preparing={isPreparing}
/>
);
}
if (message.type === "toolCallPrepare") {
return (
<ToolCallPrepareMessageContainer
functionName={message.toolName || "Unknown Tool Name"}
stale={isStale}
preparing={isPreparing}
/>
);
}
if (message.type === "user") {
return (
<UserMessageContainer
content={message.content}
attachment={message.selectedText ?? ""}
stale={isStale}
messageId={message.id}
/>
);
}
return <UnknownEntryMessageContainer message={`Error: Unknown message: ${JSON.stringify(message)}`} />;
};
return <>{returnComponent()}</>;
});
MessageCard.displayName = "MessageCard";