Skip to content

Commit 78a936c

Browse files
authored
refactor: streamline Chat component and introduce useStreamingChat hook (#141)
This update refactors the Chat component by removing unused state and logic, consolidating streaming functionality into a new custom hook, `useStreamingChat`. The new hook manages stream events, error handling, and user messages more efficiently, improving code readability and maintainability. Additionally, tests for the useStreamingChat hook have been added to ensure its functionality and reliability. Visually there are no changes. Closes #87
1 parent ce3d5c3 commit 78a936c

File tree

9 files changed

+2071
-884
lines changed

9 files changed

+2071
-884
lines changed

src/components/BotMessage.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Bot, Copy, Download } from 'lucide-react'
22
import { toast } from 'sonner'
33
import { useState } from 'react'
44
import { cn } from '@/lib/utils'
5-
import type { Message } from '@/mcp/client'
5+
import type { AssistantStreamEvent } from '@/hooks/useStreamingChat'
66
import { formatTimestamp } from '@/lib/utils'
77
import { MarkdownContent } from '@/components/MarkdownContent'
88
import { copyToClipboard } from '@/lib/utils/clipboard'
@@ -12,14 +12,14 @@ import {
1212
createAnnotatedFileUrl,
1313
} from '@/lib/utils/code-interpreter'
1414

15+
interface Message extends Omit<AssistantStreamEvent, 'type'> {
16+
timestamp: string
17+
status: string
18+
}
19+
1520
export interface BotMessageProps {
1621
message: Message
17-
fileAnnotations?: Array<{
18-
type: string
19-
container_id: string
20-
file_id: string
21-
filename: string
22-
}>
22+
fileAnnotations?: AssistantStreamEvent['fileAnnotations']
2323
}
2424

2525
export function BotMessage({ message, fileAnnotations = [] }: BotMessageProps) {
@@ -75,7 +75,6 @@ export function BotMessage({ message, fileAnnotations = [] }: BotMessageProps) {
7575
<MarkdownContent content={message.content} />
7676
</div>
7777

78-
{/* Image Gallery */}
7978
{imageFiles.length > 0 && (
8079
<div className="mt-4 space-y-3">
8180
{imageFiles.map((annotation) => {
@@ -130,7 +129,6 @@ export function BotMessage({ message, fileAnnotations = [] }: BotMessageProps) {
130129
</div>
131130
)}
132131

133-
{/* Other Files */}
134132
{otherFiles.length > 0 && (
135133
<div className="mt-4 space-y-2">
136134
<p className="text-xs text-gray-500 dark:text-gray-400 font-medium">

0 commit comments

Comments
 (0)