mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Initial release v0.2.5
This commit is contained in:
commit
bbf66c259b
158 files changed
+37115
No files matched your search
@@ -0,0 +1,109 @@
|
||||
import { useMessages } from '@/hooks/useOpenCode'
|
||||
import { MessagePart } from './MessagePart'
|
||||
import type { MessageWithParts } from '@/api/types'
|
||||
|
||||
interface MessageThreadProps {
|
||||
opcodeUrl: string
|
||||
sessionID: string
|
||||
directory?: string
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
}
|
||||
|
||||
const isMessageStreaming = (msg: MessageWithParts): boolean => {
|
||||
if (msg.info.role !== 'assistant') return false
|
||||
return !('completed' in msg.info.time && msg.info.time.completed)
|
||||
}
|
||||
|
||||
const isMessageThinking = (msg: MessageWithParts): boolean => {
|
||||
if (msg.info.role !== 'assistant') return false
|
||||
return msg.parts.length === 0 && isMessageStreaming(msg)
|
||||
}
|
||||
|
||||
export function MessageThread({ opcodeUrl, sessionID, directory, onFileClick }: MessageThreadProps) {
|
||||
const { data: messages, isLoading, error } = useMessages(opcodeUrl, sessionID, directory)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full text-zinc-500">
|
||||
Loading messages...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full text-red-400">
|
||||
Error loading messages: {error instanceof Error ? error.message : 'Unknown error'}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!messages || messages.length === 0) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-full text-zinc-600">
|
||||
No messages yet. Start a conversation below.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2 p-4">
|
||||
{messages.map((msg) => {
|
||||
const streaming = isMessageStreaming(msg)
|
||||
const thinking = isMessageThinking(msg)
|
||||
|
||||
return (
|
||||
<div
|
||||
key={msg.info.id}
|
||||
className="flex flex-col"
|
||||
>
|
||||
<div
|
||||
className={`w-full rounded-lg p-2 ${
|
||||
msg.info.role === 'user'
|
||||
? 'bg-blue-600/20 border border-blue-600/30'
|
||||
: 'bg-card/50 border border-border'
|
||||
} ${streaming ? 'animate-pulse-subtle' : ''}`}
|
||||
>
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<span className="text-xs font-medium text-zinc-400">
|
||||
{msg.info.role === 'user' ? 'You' : (msg.info.role === 'assistant' && 'modelID' in msg.info ? msg.info.modelID : 'Assistant')}
|
||||
</span>
|
||||
{msg.info.time && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{new Date(msg.info.time.created).toLocaleTimeString()}
|
||||
</span>
|
||||
)}
|
||||
{streaming && (
|
||||
<span className="text-xs text-blue-400 flex items-center gap-1">
|
||||
<span className="animate-pulse">●</span> <span className="shine-loading">Generating...</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{thinking ? (
|
||||
<div className="flex items-center gap-2 text-zinc-500">
|
||||
<span className="animate-pulse">▋</span>
|
||||
<span className="text-sm shine-loading">Thinking...</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{msg.parts.map((part, index) => (
|
||||
<div key={`${msg.info.id}-${part.id}-${index}`}>
|
||||
<MessagePart
|
||||
part={part}
|
||||
role={msg.info.role}
|
||||
allParts={msg.parts}
|
||||
partIndex={index}
|
||||
onFileClick={onFileClick}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user