test ai-blog

This commit is contained in:
2025-07-15 17:32:20 +09:00
parent 75f108e7b8
commit 0110773592
73 changed files with 9000 additions and 30 deletions

View File

@@ -13,6 +13,7 @@ export function useAdminData() {
})
const [langRecords, setLangRecords] = useState([])
const [commentRecords, setCommentRecords] = useState([])
const [chatRecords, setChatRecords] = useState([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
@@ -30,15 +31,55 @@ export function useAdminData() {
const profile = await atproto.getProfile(apiConfig.bsky, did)
// Load all data in parallel
const [records, lang, comment] = await Promise.all([
const [records, lang, comment, chat] = await Promise.all([
collections.getBase(apiConfig.pds, did, env.collection),
collections.getLang(apiConfig.pds, did, env.collection),
collections.getComment(apiConfig.pds, did, env.collection)
collections.getComment(apiConfig.pds, did, env.collection),
collections.getChat(apiConfig.pds, did, env.collection)
])
// Process chat records into question-answer pairs
const chatPairs = []
const recordMap = new Map()
// First pass: organize records by base rkey
chat.forEach(record => {
const rkey = record.uri.split('/').pop()
const baseRkey = rkey.replace('-answer', '')
if (!recordMap.has(baseRkey)) {
recordMap.set(baseRkey, { question: null, answer: null })
}
if (record.value.type === 'question') {
recordMap.get(baseRkey).question = record
} else if (record.value.type === 'answer') {
recordMap.get(baseRkey).answer = record
}
})
// Second pass: create chat pairs
recordMap.forEach((pair, rkey) => {
if (pair.question) {
chatPairs.push({
rkey,
question: pair.question,
answer: pair.answer,
createdAt: pair.question.value.createdAt
})
}
})
// Sort by creation time (newest first)
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
console.log('useAdminData: raw chat records:', chat.length)
console.log('useAdminData: processed chat pairs:', chatPairs.length, chatPairs)
setAdminData({ did, profile, records, apiConfig })
setLangRecords(lang)
setCommentRecords(comment)
setChatRecords(chatPairs)
} catch (err) {
// Silently fail - no error logging or retry attempts
setError('silent_failure')
@@ -51,6 +92,7 @@ export function useAdminData() {
adminData,
langRecords,
commentRecords,
chatRecords,
loading,
error,
refresh: loadAdminData

View File

@@ -24,13 +24,52 @@ export function useUserData(adminData) {
env.collection
)
// 2. Get chat records from ai.syui.log.chat
// 2. Get chat records from ai.syui.log.chat and process into pairs
const chatRecords = await collections.getChat(
adminData.apiConfig.pds,
adminData.did,
env.collection
)
setChatRecords(chatRecords)
console.log('useUserData: raw chatRecords:', chatRecords.length, chatRecords)
// Process chat records into question-answer pairs
const chatPairs = []
const recordMap = new Map()
// First pass: organize records by base rkey
chatRecords.forEach(record => {
const rkey = record.uri.split('/').pop()
const baseRkey = rkey.replace('-answer', '')
if (!recordMap.has(baseRkey)) {
recordMap.set(baseRkey, { question: null, answer: null })
}
if (record.value.type === 'question') {
recordMap.get(baseRkey).question = record
} else if (record.value.type === 'answer') {
recordMap.get(baseRkey).answer = record
}
})
// Second pass: create chat pairs
recordMap.forEach((pair, rkey) => {
if (pair.question) {
chatPairs.push({
rkey,
question: pair.question,
answer: pair.answer,
createdAt: pair.question.value.createdAt
})
}
})
// Sort by creation time (newest first)
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
console.log('useUserData: processed chatPairs:', chatPairs.length, chatPairs)
setChatRecords(chatPairs)
// 3. Get base collection records which contain user comments
const baseRecords = await collections.getBase(