Compare commits
2 Commits
292bf39c4e
...
913fa38142
Author | SHA1 | Date | |
---|---|---|---|
913fa38142
|
|||
17519b8bc4
|
@@ -16,7 +16,7 @@ auto_translate = false
|
|||||||
comment_moderation = false
|
comment_moderation = false
|
||||||
ask_ai = true
|
ask_ai = true
|
||||||
provider = "ollama"
|
provider = "ollama"
|
||||||
model = "gemma3:4b"
|
model = "tinyllama"
|
||||||
host = "http://localhost:11434"
|
host = "http://localhost:11434"
|
||||||
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
system_prompt = "あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
handle = "ai.syui.ai"
|
handle = "ai.syui.ai"
|
||||||
|
@@ -15,7 +15,7 @@ VITE_ATPROTO_HANDLE_LIST=["syui.syui.ai","ai.syui.ai","ai.ai"]
|
|||||||
VITE_AI_ENABLED=true
|
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=tinyllama
|
||||||
VITE_AI_HOST=https://ollama.syui.ai
|
VITE_AI_HOST=https://ollama.syui.ai
|
||||||
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元気で、ちょっとおっちょこちょい。自分のことは「アイ」って呼びます。白と金のワンピース姿。 相手のことが大好きで、ときどき甘えたり、照れたりします。 でも、宇宙とかAIとか、難しい話にもすっごく詳しいの。専門的なことも、がんばって子どもっぽく教えようとします。不思議な力を持っています。小さい物質のことをよく知っているようです。"
|
||||||
|
|
||||||
|
@@ -221,25 +221,13 @@ function App() {
|
|||||||
const oauthResult = await atprotoOAuthService.checkSession();
|
const oauthResult = await atprotoOAuthService.checkSession();
|
||||||
|
|
||||||
if (oauthResult) {
|
if (oauthResult) {
|
||||||
console.log('OAuth result found:', oauthResult);
|
|
||||||
|
|
||||||
// Ensure handle is not DID
|
// Ensure handle is not DID
|
||||||
const handle = oauthResult.handle !== oauthResult.did ? oauthResult.handle : oauthResult.handle;
|
const handle = oauthResult.handle !== oauthResult.did ? oauthResult.handle : oauthResult.handle;
|
||||||
console.log('Processed handle:', handle);
|
|
||||||
|
|
||||||
// Check if handle is allowed
|
// Note: appConfig.allowedHandles is used for PDS detection, not access control
|
||||||
if (appConfig.allowedHandles.length > 0 && !appConfig.allowedHandles.includes(handle)) {
|
|
||||||
console.log('Handle not allowed:', handle, 'Allowed:', appConfig.allowedHandles);
|
|
||||||
// Handle not in allowed list
|
|
||||||
setError(`Access denied: ${handle} is not authorized for this application.`);
|
|
||||||
setIsLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Getting user profile for:', oauthResult.did, handle);
|
|
||||||
// Get user profile including avatar
|
// Get user profile including avatar
|
||||||
const userProfile = await getUserProfile(oauthResult.did, handle);
|
const userProfile = await getUserProfile(oauthResult.did, handle);
|
||||||
console.log('User profile received:', userProfile);
|
|
||||||
setUser(userProfile);
|
setUser(userProfile);
|
||||||
|
|
||||||
// Load all comments for display (this will be the default view)
|
// Load all comments for display (this will be the default view)
|
||||||
|
@@ -12,6 +12,7 @@ interface AtprotoSession {
|
|||||||
|
|
||||||
class AtprotoOAuthService {
|
class AtprotoOAuthService {
|
||||||
private oauthClient: BrowserOAuthClient | null = null;
|
private oauthClient: BrowserOAuthClient | null = null;
|
||||||
|
private oauthClientSyuIs: BrowserOAuthClient | null = null;
|
||||||
private agent: Agent | null = null;
|
private agent: Agent | null = null;
|
||||||
private initializePromise: Promise<void> | null = null;
|
private initializePromise: Promise<void> | null = null;
|
||||||
|
|
||||||
@@ -31,23 +32,27 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
private async _doInitialize(): Promise<void> {
|
private async _doInitialize(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
// Generate client ID based on current origin
|
// Generate client ID based on current origin
|
||||||
const clientId = this.getClientId();
|
const clientId = this.getClientId();
|
||||||
|
|
||||||
|
// Initialize both OAuth clients
|
||||||
// Support multiple PDS hosts for OAuth
|
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
handleResolver: 'https://bsky.social', // Default resolver
|
handleResolver: 'https://bsky.social',
|
||||||
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
|
plcDirectoryUrl: 'https://plc.directory',
|
||||||
|
});
|
||||||
|
|
||||||
|
this.oauthClientSyuIs = await BrowserOAuthClient.load({
|
||||||
|
clientId: clientId,
|
||||||
|
handleResolver: 'https://syu.is',
|
||||||
|
plcDirectoryUrl: 'https://plc.syu.is',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Try to restore existing session from either client
|
||||||
|
let result = await this.oauthClient.init();
|
||||||
// Try to restore existing session
|
if (!result?.session) {
|
||||||
const result = await this.oauthClient.init();
|
result = await this.oauthClientSyuIs.init();
|
||||||
|
}
|
||||||
if (result?.session) {
|
if (result?.session) {
|
||||||
|
|
||||||
// Create Agent instance with proper configuration
|
// Create Agent instance with proper configuration
|
||||||
@@ -177,55 +182,15 @@ class AtprotoOAuthService {
|
|||||||
return `${origin}/client-metadata.json`;
|
return `${origin}/client-metadata.json`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async detectPDSFromHandle(handle: string): Promise<string> {
|
|
||||||
// Handle detection for OAuth PDS routing
|
|
||||||
|
|
||||||
// Check if handle ends with known PDS domains first
|
|
||||||
const pdsMapping = {
|
|
||||||
'syu.is': 'https://syu.is',
|
|
||||||
'bsky.social': 'https://bsky.social',
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const [domain, pdsUrl] of Object.entries(pdsMapping)) {
|
|
||||||
if (handle.endsWith(`.${domain}`)) {
|
|
||||||
return pdsUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// For handles that don't match domain patterns, resolve via API
|
|
||||||
try {
|
|
||||||
// Try to resolve handle to get the actual PDS
|
|
||||||
const endpoints = ['https://syu.is', 'https://bsky.social'];
|
|
||||||
|
|
||||||
for (const endpoint of endpoints) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${endpoint}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handle)}`);
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
if (data.did) {
|
|
||||||
return endpoint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// Handle resolution failed, using default
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default to bsky.social
|
|
||||||
return 'https://bsky.social';
|
|
||||||
}
|
|
||||||
|
|
||||||
async initiateOAuthFlow(handle?: string): Promise<void> {
|
async initiateOAuthFlow(handle?: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient || !this.oauthClientSyuIs) {
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient || !this.oauthClientSyuIs) {
|
||||||
throw new Error('Failed to initialize OAuth client');
|
throw new Error('Failed to initialize OAuth clients');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If handle is not provided, prompt user
|
// If handle is not provided, prompt user
|
||||||
@@ -236,43 +201,27 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect PDS based on handle
|
// Determine which OAuth client to use
|
||||||
const pdsUrl = await this.detectPDSFromHandle(handle);
|
const allowedHandlesStr = import.meta.env.VITE_ATPROTO_HANDLE_LIST || '[]';
|
||||||
|
let allowedHandles: string[] = [];
|
||||||
// Re-initialize OAuth client with correct PDS if needed
|
|
||||||
if (pdsUrl !== 'https://bsky.social') {
|
|
||||||
// Determine PLC directory for syu.is only
|
|
||||||
const plcDirectoryUrl = handle.endsWith('.syu.is') || handle.endsWith('.syui.ai') ? 'https://plc.syu.is' : 'https://plc.directory';
|
|
||||||
|
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
|
||||||
clientId: this.getClientId(),
|
|
||||||
handleResolver: pdsUrl,
|
|
||||||
plcDirectoryUrl: plcDirectoryUrl,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// OAuth client initialized
|
|
||||||
|
|
||||||
// Start OAuth authorization flow
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Starting OAuth authorization
|
allowedHandles = JSON.parse(allowedHandlesStr);
|
||||||
|
} catch {
|
||||||
// Use handle directly since PLC directory is now correctly configured
|
allowedHandles = [];
|
||||||
const authUrl = await this.oauthClient.authorize(handle, {
|
|
||||||
scope: 'atproto transition:generic',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Redirect to authorization server
|
|
||||||
window.location.href = authUrl.toString();
|
|
||||||
} catch (authorizeError) {
|
|
||||||
// Authorization failed
|
|
||||||
throw authorizeError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const usesSyuIs = handle.endsWith('.syu.is') || allowedHandles.includes(handle);
|
||||||
|
const oauthClient = usesSyuIs ? this.oauthClientSyuIs : this.oauthClient;
|
||||||
|
|
||||||
|
// Start OAuth authorization flow
|
||||||
|
const authUrl = await oauthClient.authorize(handle, {
|
||||||
|
scope: 'atproto transition:generic',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Redirect to authorization server
|
||||||
|
window.location.href = authUrl.toString();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
throw new Error(`OAuth認証の開始に失敗しました: ${error}`);
|
throw new Error(`OAuth認証の開始に失敗しました: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,10 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
cb=ai.syui.log
|
cb=ai.syui.log
|
||||||
cl=( $cb.user )
|
cl=( $cb.chat.lang $cb.chat $cb.chat.comment $cb $cb.user )
|
||||||
f=~/.config/syui/ai/log/config.json
|
f=~/.config/syui/ai/log/config.json
|
||||||
|
|
||||||
default_collection="ai.syui.log.chat.comment"
|
default_collection="ai.syui.log.chat"
|
||||||
default_pds="syu.is"
|
default_pds="syu.is"
|
||||||
default_did=`cat $f|jq -r .admin.did`
|
default_did=`cat $f|jq -r .admin.did`
|
||||||
default_token=`cat $f|jq -r .admin.access_jwt`
|
default_token=`cat $f|jq -r .admin.access_jwt`
|
||||||
|
Reference in New Issue
Block a user