diff --git a/my-blog/static/js/ask-ai.js b/my-blog/static/js/ask-ai.js index 3bb0796..ced9614 100644 --- a/my-blog/static/js/ask-ai.js +++ b/my-blog/static/js/ask-ai.js @@ -5,6 +5,24 @@ // Global variables for AI functionality let aiProfileData = null; +// Get config from window or use defaults +const OAUTH_PDS = window.OAUTH_CONFIG?.pds || 'syu.is'; +const ADMIN_HANDLE = window.OAUTH_CONFIG?.admin || 'ai.syui.ai'; +const OAUTH_COLLECTION = window.OAUTH_CONFIG?.collection || 'ai.syui.log'; + +// Listen for AI profile data from OAuth app +window.addEventListener('aiProfileLoaded', function(event) { + console.log('AI profile received from OAuth app:', event.detail); + aiProfileData = event.detail; + updateAskAIButton(); +}); + +// Check if AI profile data is already available +if (window.aiProfileData) { + console.log('AI profile already available:', window.aiProfileData); + aiProfileData = window.aiProfileData; +} + // Original functions from working implementation function toggleAskAI() { const panel = document.getElementById('askAiPanel'); @@ -129,11 +147,7 @@ async function loadAndShowProfiles() { chatHistory.innerHTML = '
'; try { - const ADMIN_HANDLE = 'ai.syui.ai'; - const OAUTH_COLLECTION = 'ai.syui.log'; - const ATPROTO_PDS = 'syu.is'; - - const response = await fetch(`https://${ATPROTO_PDS}/xrpc/com.atproto.repo.listRecords?repo=${ADMIN_HANDLE}&collection=${OAUTH_COLLECTION}&limit=100`); + const response = await fetch(`https://${OAUTH_PDS}/xrpc/com.atproto.repo.listRecords?repo=${ADMIN_HANDLE}&collection=${OAUTH_COLLECTION}&limit=100`); if (!response.ok) { throw new Error('Failed to fetch profiles'); @@ -174,7 +188,7 @@ async function loadAndShowProfiles() {© {{ config.author }}
+ diff --git a/oauth/src/App.jsx b/oauth/src/App.jsx index 490a4b8..cd37e9a 100644 --- a/oauth/src/App.jsx +++ b/oauth/src/App.jsx @@ -87,6 +87,26 @@ export default function App() { fetchUserChatRecords() }, [user, agent]) + // Expose AI profile data to blog's ask-ai.js + useEffect(() => { + if (adminData?.profile) { + console.log('AI profile loaded:', adminData.profile) + + // Make AI profile data available globally for ask-ai.js + window.aiProfileData = { + did: adminData.did, + handle: adminData.profile.handle, + displayName: adminData.profile.displayName, + avatar: adminData.profile.avatar + } + + // Dispatch event to notify ask-ai.js + window.dispatchEvent(new CustomEvent('aiProfileLoaded', { + detail: window.aiProfileData + })) + } + }, [adminData]) + // Event listeners for blog communication useEffect(() => { // Clear OAuth completion flag once app is loaded diff --git a/oauth/src/components/RecordList.jsx b/oauth/src/components/RecordList.jsx index d4233e0..452fdb6 100644 --- a/oauth/src/components/RecordList.jsx +++ b/oauth/src/components/RecordList.jsx @@ -13,7 +13,7 @@ function getCorrectWebUrl(avatarUrl) { // If avatar is from syu.is, use web.syu.is if (avatarUrl.includes('bsky.syu.is') || avatarUrl.includes('syu.is')) { - return 'https://web.syu.is' + return 'https://syu.is' } // Default to bsky.app @@ -151,4 +151,4 @@ export default function RecordList({ title, records, apiConfig, showTitle = true ))} ) -} \ No newline at end of file +} diff --git a/oauth/src/utils/pds.js b/oauth/src/utils/pds.js index 88f0122..f03cfd1 100644 --- a/oauth/src/utils/pds.js +++ b/oauth/src/utils/pds.js @@ -10,7 +10,7 @@ export function getApiConfig(pds) { pds: `https://${env.pds}`, bsky: `https://bsky.${env.pds}`, plc: `https://plc.${env.pds}`, - web: `https://web.${env.pds}` + web: `https://${env.pds}` } } return { @@ -36,4 +36,4 @@ export async function getPdsFromHandle(handle) { .then(res => res.json()) return data.didDoc?.service?.[0]?.serviceEndpoint || initialPds -} \ No newline at end of file +}