From ac4c3f2ad34b5d1566bbd6190be59f041eed1e4c Mon Sep 17 00:00:00 2001 From: syui Date: Fri, 13 Jun 2025 15:31:32 +0900 Subject: [PATCH] fix --- oauth/.env.production | 2 +- oauth/src/components/AIChat.tsx | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/oauth/.env.production b/oauth/.env.production index 4c59f4c..311e92a 100644 --- a/oauth/.env.production +++ b/oauth/.env.production @@ -21,4 +21,4 @@ VITE_AI_PROVIDER=ollama VITE_AI_MODEL=gemma3:4b VITE_AI_HOST=https://ollama.syui.ai VITE_AI_SYSTEM_PROMPT="You are a helpful AI assistant trained on this blog's content. You can answer questions about the articles, provide insights, and help users understand the topics discussed." -VITE_AI_DID=did:plc:uqzpqmrjnptsxezjx4xuh2mn +VITE_AI_DID=did:plc:4hqjfn7m6n5hno3doamuhgef diff --git a/oauth/src/components/AIChat.tsx b/oauth/src/components/AIChat.tsx index 74eb99a..e03a21d 100644 --- a/oauth/src/components/AIChat.tsx +++ b/oauth/src/components/AIChat.tsx @@ -28,12 +28,18 @@ export const AIChat: React.FC = ({ user, isEnabled }) => { // Fetch AI profile on load useEffect(() => { const fetchAIProfile = async () => { - if (!aiConfig.aiDid) return; + if (!aiConfig.aiDid) { + console.log('No AI DID configured'); + return; + } try { + // Try with agent first const agent = atprotoOAuthService.getAgent(); if (agent) { + console.log('Fetching AI profile with agent for DID:', aiConfig.aiDid); const profile = await agent.getProfile({ actor: aiConfig.aiDid }); + console.log('AI profile fetched successfully:', profile.data); setAiProfile({ did: aiConfig.aiDid, handle: profile.data.handle || 'ai-assistant', @@ -41,9 +47,26 @@ export const AIChat: React.FC = ({ user, isEnabled }) => { avatar: profile.data.avatar || null, description: profile.data.description || null }); + return; + } + + // Fallback to public API + console.log('No agent available, trying public API for AI profile'); + const response = await fetch(`https://public.api.bsky.app/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(aiConfig.aiDid)}`); + if (response.ok) { + const profileData = await response.json(); + console.log('AI profile fetched via public API:', profileData); + setAiProfile({ + did: aiConfig.aiDid, + handle: profileData.handle || 'ai-assistant', + displayName: profileData.displayName || 'AI Assistant', + avatar: profileData.avatar || null, + description: profileData.description || null + }); + return; } } catch (error) { - console.log('Failed to fetch AI profile, using defaults'); + console.log('Failed to fetch AI profile, using defaults:', error); setAiProfile({ did: aiConfig.aiDid, handle: 'ai-assistant', @@ -187,6 +210,7 @@ ${chatHistoryText ? `履歴: ${chatHistoryText}` : ''} } // 4. Immediately dispatch event to update UI + console.log('Dispatching AI response with profile:', aiProfile); window.dispatchEvent(new CustomEvent('aiResponseReceived', { detail: { answer: aiAnswer,