From cf93721bad93a56ad2c7700485e09581ef5c1a67 Mon Sep 17 00:00:00 2001 From: syui Date: Thu, 26 Jun 2025 19:47:24 +0900 Subject: [PATCH] fix social-app uri --- my-blog/static/js/ask-ai.js | 36 ++++++++++++++++++++--------- my-blog/templates/base.html | 20 ++++++++++++++++ oauth/src/App.jsx | 20 ++++++++++++++++ oauth/src/components/RecordList.jsx | 4 ++-- oauth/src/utils/pds.js | 4 ++-- 5 files changed, 69 insertions(+), 15 deletions(-) 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 = '
Loading profiles...
'; 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() {
${avatarElement}
${profile.value.author.displayName || profile.value.author.handle} ${adminBadge}
- +
${profile.value.text}
@@ -255,7 +269,7 @@ function addUserMessage(question) {
${userAvatar}
${userDisplay}
- +
${question}
@@ -318,7 +332,7 @@ function showInitialGreeting() {
${avatarElement}
${aiProfileData.displayName}
- +
Hello! I'm an AI assistant trained on this blog's content. I can answer questions about the articles, provide insights, and help you understand the topics discussed here. What would you like to know?
@@ -345,7 +359,7 @@ function showAIIntroduction() {
${avatarElement}
${aiProfileData.displayName}
- +
Hello! I'm an AI assistant trained on this blog's content. I can answer questions about the articles, provide insights, and help you understand the topics discussed here. What would you like to know?
@@ -361,7 +375,7 @@ function showAIIntroduction() {
${avatarElement}
${aiProfileData.displayName}
- +
Please atproto oauth login
@@ -404,7 +418,7 @@ function handleAIResponse(responseData) {
${avatarElement}
${aiProfile.displayName}
- +
${responseData.answer}
diff --git a/my-blog/templates/base.html b/my-blog/templates/base.html index bdae79a..d666b2b 100644 --- a/my-blog/templates/base.html +++ b/my-blog/templates/base.html @@ -92,6 +92,26 @@

© {{ 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 +}