import React from 'react' export default function ChatRecordList({ chatPairs, apiConfig, user = null, agent = null, onRecordDeleted = null }) { if (!chatPairs || chatPairs.length === 0) { return (

チャット履歴がありません

) } const handleDelete = async (chatPair) => { if (!user || !agent || !chatPair.question?.uri) return const confirmed = window.confirm('この会話を削除しますか?') if (!confirmed) return try { // Delete question record if (chatPair.question?.uri) { const questionUriParts = chatPair.question.uri.split('/') await agent.api.com.atproto.repo.deleteRecord({ repo: questionUriParts[2], collection: questionUriParts[3], rkey: questionUriParts[4] }) } // Delete answer record if exists if (chatPair.answer?.uri) { const answerUriParts = chatPair.answer.uri.split('/') await agent.api.com.atproto.repo.deleteRecord({ repo: answerUriParts[2], collection: answerUriParts[3], rkey: answerUriParts[4] }) } if (onRecordDeleted) { onRecordDeleted() } } catch (error) { alert(`削除に失敗しました: ${error.message}`) } } const canDelete = (chatPair) => { return user && agent && chatPair.question?.uri && chatPair.question.value.author?.did === user.did } return (
{chatPairs.map((chatPair, i) => (
{/* Question */} {chatPair.question && (
{chatPair.question.value.author?.avatar ? ( {`${chatPair.question.value.author.displayName ) : (
{(chatPair.question.value.author?.displayName || chatPair.question.value.author?.handle || '?').charAt(0).toUpperCase()}
)}
{chatPair.question.value.author?.displayName || chatPair.question.value.author?.handle}
@{chatPair.question.value.author?.handle}
{new Date(chatPair.question.value.createdAt).toLocaleString()}
{canDelete(chatPair) && (
)}
{chatPair.question.value.text}
)} {/* Answer */} {chatPair.answer && (
{chatPair.answer.value.author?.avatar ? ( {`${chatPair.answer.value.author.displayName ) : (
{(chatPair.answer.value.author?.displayName || chatPair.answer.value.author?.handle || 'AI').charAt(0).toUpperCase()}
)}
{chatPair.answer.value.author?.displayName || chatPair.answer.value.author?.handle}
@{chatPair.answer.value.author?.handle}
{new Date(chatPair.answer.value.createdAt).toLocaleString()}
{chatPair.answer.value.text}
)} {/* Post metadata */} {chatPair.question?.value.post?.url && (
{chatPair.question.value.post.url}
)}
))}
) }