Compare commits
4 Commits
test-oauth
...
fcab7c7f83
Author | SHA1 | Date | |
---|---|---|---|
fcab7c7f83
|
|||
51e4a492bc
|
|||
9ed35a6a1e
|
|||
74e1014e77
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ my-blog/templates/oauth-assets.html
|
|||||||
cloudflared-config.yml
|
cloudflared-config.yml
|
||||||
.config
|
.config
|
||||||
oauth-server-example
|
oauth-server-example
|
||||||
|
atproto
|
||||||
|
@@ -17,7 +17,7 @@ comment_moderation = false
|
|||||||
ask_ai = true
|
ask_ai = true
|
||||||
provider = "ollama"
|
provider = "ollama"
|
||||||
model = "gemma3:4b"
|
model = "gemma3:4b"
|
||||||
host = "https://localhost:11434"
|
host = "http://localhost:11434"
|
||||||
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
handle = "ai.syui.ai"
|
handle = "ai.syui.ai"
|
||||||
#num_predict = 200
|
#num_predict = 200
|
||||||
|
@@ -16,5 +16,5 @@ VITE_AI_ENABLED=true
|
|||||||
VITE_AI_ASK_AI=true
|
VITE_AI_ASK_AI=true
|
||||||
VITE_AI_PROVIDER=ollama
|
VITE_AI_PROVIDER=ollama
|
||||||
VITE_AI_MODEL=gemma3:4b
|
VITE_AI_MODEL=gemma3:4b
|
||||||
VITE_AI_HOST=https://localhost:11434
|
VITE_AI_HOST=http://localhost:11434
|
||||||
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
|
@@ -1213,8 +1213,8 @@ function App() {
|
|||||||
|
|
||||||
// Extract content based on format
|
// Extract content based on format
|
||||||
const contentText = isNewFormat ? value.text : (value.content || value.body || '');
|
const contentText = isNewFormat ? value.text : (value.content || value.body || '');
|
||||||
// For AI comments, always use the loaded AI profile instead of record.value.author
|
// Use the author from the record if available, otherwise fall back to AI profile
|
||||||
const authorInfo = aiProfile;
|
const authorInfo = value.author || aiProfile;
|
||||||
const postInfo = isNewFormat ? value.post : null;
|
const postInfo = isNewFormat ? value.post : null;
|
||||||
const contentType = value.type || 'unknown';
|
const contentType = value.type || 'unknown';
|
||||||
const createdAt = value.createdAt || value.generated_at || '';
|
const createdAt = value.createdAt || value.generated_at || '';
|
||||||
|
@@ -38,10 +38,13 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
|
|
||||||
// Support multiple PDS hosts for OAuth
|
// Support multiple PDS hosts for OAuth
|
||||||
|
console.log('[OAuth Debug] Initializing OAuth client with default settings');
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
handleResolver: 'https://bsky.social', // Default resolver
|
handleResolver: 'https://bsky.social', // Default resolver
|
||||||
|
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
|
||||||
});
|
});
|
||||||
|
console.log('[OAuth Debug] OAuth client initialized with defaults');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -115,23 +118,24 @@ class AtprotoOAuthService {
|
|||||||
// Create Agent directly with session (per official docs)
|
// Create Agent directly with session (per official docs)
|
||||||
try {
|
try {
|
||||||
this.agent = new Agent(session);
|
this.agent = new Agent(session);
|
||||||
|
console.log('[OAuth Debug] Agent created successfully with session');
|
||||||
|
|
||||||
// Check if agent has session info after creation
|
// Check if agent has session info after creation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (this.agent.session) {
|
if (this.agent.session) {
|
||||||
|
console.log('[OAuth Debug] Agent has session:', this.agent.session);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log('[OAuth Debug] Failed to create agent with session:', err);
|
||||||
// Fallback to dpopFetch method
|
// Fallback to dpopFetch method
|
||||||
|
try {
|
||||||
this.agent = new Agent({
|
this.agent = new Agent({
|
||||||
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
||||||
fetch: session.dpopFetch
|
fetch: session.dpopFetch
|
||||||
});
|
});
|
||||||
|
console.log('[OAuth Debug] Agent created with dpopFetch fallback');
|
||||||
|
} catch (fallbackErr) {
|
||||||
|
console.error('[OAuth Debug] Failed to create agent with fallback:', fallbackErr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store basic session info
|
// Store basic session info
|
||||||
@@ -273,21 +277,30 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
// Detect PDS based on handle
|
// Detect PDS based on handle
|
||||||
const pdsUrl = await this.detectPDSFromHandle(handle);
|
const pdsUrl = await this.detectPDSFromHandle(handle);
|
||||||
// Starting OAuth flow
|
console.log('[OAuth Debug] Detected PDS for handle', handle, ':', pdsUrl);
|
||||||
|
|
||||||
|
|
||||||
// Always re-initialize OAuth client with detected PDS
|
// Always re-initialize OAuth client with detected PDS
|
||||||
// Re-initializing OAuth client
|
console.log('[OAuth Debug] Re-initializing OAuth client');
|
||||||
|
|
||||||
// Clear existing client to force fresh initialization
|
// Clear existing client to force fresh initialization
|
||||||
this.oauthClient = null;
|
this.oauthClient = null;
|
||||||
this.initializePromise = null;
|
this.initializePromise = null;
|
||||||
|
|
||||||
|
// Determine PLC directory based on input handle, not environment PDS
|
||||||
|
let plcDirectoryUrl = 'https://plc.directory'; // Default to Bluesky PLC
|
||||||
|
if (handle.endsWith('.syu.is') || handle.endsWith('.syui.ai')) {
|
||||||
|
plcDirectoryUrl = 'https://plc.syu.is';
|
||||||
|
}
|
||||||
|
console.log('[OAuth Debug] Using PLC directory:', plcDirectoryUrl);
|
||||||
|
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: this.getClientId(),
|
clientId: this.getClientId(),
|
||||||
handleResolver: pdsUrl,
|
handleResolver: pdsUrl,
|
||||||
|
plcDirectoryUrl: plcDirectoryUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('[OAuth Debug] OAuth client re-initialized successfully');
|
||||||
|
|
||||||
// OAuth client initialized
|
// OAuth client initialized
|
||||||
|
|
||||||
// Start OAuth authorization flow
|
// Start OAuth authorization flow
|
||||||
@@ -296,22 +309,8 @@ class AtprotoOAuthService {
|
|||||||
try {
|
try {
|
||||||
// Starting OAuth authorization
|
// Starting OAuth authorization
|
||||||
|
|
||||||
// Try to authorize with DID instead of handle for syu.is PDS only
|
// Use handle directly since PLC directory is now correctly configured
|
||||||
let authTarget = handle;
|
const authUrl = await this.oauthClient.authorize(handle, {
|
||||||
if (pdsUrl === 'https://syu.is') {
|
|
||||||
try {
|
|
||||||
const resolveResponse = await fetch(`${pdsUrl}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handle)}`);
|
|
||||||
if (resolveResponse.ok) {
|
|
||||||
const resolveData = await resolveResponse.json();
|
|
||||||
authTarget = resolveData.did;
|
|
||||||
// Using DID for syu.is OAuth workaround
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// Could not resolve to DID, using handle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const authUrl = await this.oauthClient.authorize(authTarget, {
|
|
||||||
scope: 'atproto transition:generic',
|
scope: 'atproto transition:generic',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -379,27 +378,30 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
async checkSession(): Promise<{ did: string; handle: string } | null> {
|
async checkSession(): Promise<{ did: string; handle: string } | null> {
|
||||||
try {
|
try {
|
||||||
|
console.log('[OAuth Debug] Checking session...');
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
|
console.log('[OAuth Debug] No OAuth client, initializing...');
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
|
console.log('[OAuth Debug] Failed to initialize OAuth client');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const result = await this.oauthClient.init();
|
const result = await this.oauthClient.init();
|
||||||
|
console.log('[OAuth Debug] OAuth init result:', !!result?.session);
|
||||||
|
|
||||||
if (result?.session) {
|
if (result?.session) {
|
||||||
|
console.log('[OAuth Debug] Session found, processing...');
|
||||||
// Use the common session processing method
|
// Use the common session processing method
|
||||||
return this.processSession(result.session);
|
const sessionData = await this.processSession(result.session);
|
||||||
|
console.log('[OAuth Debug] Processed session data:', sessionData);
|
||||||
|
return sessionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[OAuth Debug] No session found');
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user