import React, { useState } from 'react' // Helper function to get correct web URL based on avatar URL function getCorrectWebUrl(avatarUrl) { if (!avatarUrl) return 'https://bsky.app' // If avatar is from bsky.app (main Bluesky), use bsky.app if (avatarUrl.includes('cdn.bsky.app') || avatarUrl.includes('bsky.app')) { return 'https://bsky.app' } // If avatar is from syu.is, use web.syu.is if (avatarUrl.includes('bsky.syu.is') || avatarUrl.includes('syu.is')) { return 'https://syu.is' } // Default to bsky.app return 'https://bsky.app' } export default function ChatRecordList({ chatPairs, apiConfig, user = null, agent = null, onRecordDeleted = null }) { const [expandedRecords, setExpandedRecords] = useState(new Set()) const toggleJsonView = (key) => { const newExpanded = new Set(expandedRecords) if (newExpanded.has(key)) { newExpanded.delete(key) } else { newExpanded.add(key) } setExpandedRecords(newExpanded) } 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 === 'syui' && Admin}
{expandedRecords.has(`${chatPair.rkey}-question`) && (
                    {JSON.stringify(chatPair.question, null, 2)}
                  
)}
{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}
{expandedRecords.has(`${chatPair.rkey}-answer`) && (
                    {JSON.stringify(chatPair.answer, null, 2)}
                  
)}
{chatPair.answer.value.text}
)}
))}
) }