diff --git a/public/config.json b/public/config.json index 08ee20d..a458cd5 100644 --- a/public/config.json +++ b/public/config.json @@ -2,6 +2,10 @@ "title": "syui.ai", "did": "did:plc:vzsvtbtbnwn22xjqhcu3vd6y", "handle": "syui.syui.ai", + "bot": { + "did": "did:plc:6qyecktefllvenje24fcxnie", + "handle": "ai.syui.ai" + }, "collection": "ai.syui.log.post", "network": "syu.is", "color": "#EF454A", diff --git a/src/mcp/mod.rs b/src/mcp/mod.rs index e3b5ab7..d8382d7 100644 --- a/src/mcp/mod.rs +++ b/src/mcp/mod.rs @@ -223,14 +223,16 @@ fn handle_chat_save(params: ChatSaveParams) -> Result { }); // Get user DID from token.json - let user_did = token::load_session() - .map(|s| s.did) - .unwrap_or_else(|_| "did:plc:unknown".to_string()); + let user_did = match token::load_session() { + Ok(s) => s.did, + Err(_) => return Err(anyhow::anyhow!("User not logged in. Run: ailog login -p ")), + }; // Get bot DID from bot.json - let bot_did = token::load_bot_session() - .map(|s| s.did) - .unwrap_or_else(|_| "did:plc:6qyecktefllvenje24fcxnie".to_string()); + let bot_did = match token::load_bot_session() { + Ok(s) => s.did, + Err(_) => return Err(anyhow::anyhow!("Bot not logged in. Run: ailog login -p --bot")), + }; // Reset session if new_thread requested if params.new_thread { @@ -278,9 +280,10 @@ fn handle_chat_list() -> Result { .to_string() }); - let user_did = token::load_session() - .map(|s| s.did) - .unwrap_or_else(|_| "did:plc:unknown".to_string()); + let user_did = match token::load_session() { + Ok(s) => s.did, + Err(_) => return Err(anyhow::anyhow!("User not logged in. Run: ailog login -p ")), + }; let collection_dir = std::path::Path::new(&output_dir) .join(&user_did) diff --git a/src/web/main.ts b/src/web/main.ts index 4e38266..4e8cad9 100644 --- a/src/web/main.ts +++ b/src/web/main.ts @@ -230,13 +230,17 @@ async function render(route: Route): Promise { } else if (route.type === 'chat') { // Chat list page - show threads started by this user - const aiDid = 'did:plc:6qyecktefllvenje24fcxnie' // ai.syui.ai - const aiHandle = 'ai.syui.ai' + if (!config.bot) { + html += `
Bot not configured in config.json
` + html += `` + } else { + const botDid = config.bot.did + const botHandle = config.bot.handle // Load messages and profiles in parallel - const [chatMessages, aiProfile, pds] = await Promise.all([ - getChatMessages(did, aiDid, 'ai.syui.log.chat'), - getProfile(aiDid, false), + const [chatMessages, botProfile, pds] = await Promise.all([ + getChatMessages(did, botDid, 'ai.syui.log.chat'), + getProfile(botDid, false), getPds(did) ]) @@ -254,18 +258,23 @@ async function render(route: Route): Promise { langList = Array.from(chatLangs) html += renderLangSelector(langList) - html += `
${renderChatListPage(chatMessages, did, handle, aiDid, aiHandle, profile, aiProfile, pds || undefined)}
` + html += `
${renderChatListPage(chatMessages, did, handle, botDid, botHandle, profile, botProfile, pds || undefined)}
` html += `` + } } else if (route.type === 'chat-thread' && route.rkey) { // Chat thread page - show full conversation - const aiDid = 'did:plc:6qyecktefllvenje24fcxnie' // ai.syui.ai - const aiHandle = 'ai.syui.ai' + if (!config.bot) { + html += `
Bot not configured in config.json
` + html += `` + } else { + const botDid = config.bot.did + const botHandle = config.bot.handle // Load messages and profiles in parallel - const [chatMessages, aiProfile, pds] = await Promise.all([ - getChatMessages(did, aiDid, 'ai.syui.log.chat'), - getProfile(aiDid, false), + const [chatMessages, botProfile, pds] = await Promise.all([ + getChatMessages(did, botDid, 'ai.syui.log.chat'), + getProfile(botDid, false), getPds(did) ]) @@ -283,8 +292,9 @@ async function render(route: Route): Promise { langList = Array.from(chatLangs) html += renderLangSelector(langList) - html += `
${renderChatThreadPage(chatMessages, route.rkey, did, handle, aiDid, aiHandle, profile, aiProfile, pds || undefined)}
` + html += `
${renderChatThreadPage(chatMessages, route.rkey, did, handle, botDid, botHandle, profile, botProfile, pds || undefined)}
` html += `` + } } else { // User page: compact collection buttons + posts diff --git a/src/web/types.ts b/src/web/types.ts index b2ac46a..f9e9ddd 100644 --- a/src/web/types.ts +++ b/src/web/types.ts @@ -1,8 +1,14 @@ // Config types +export interface BotConfig { + did: string + handle: string +} + export interface AppConfig { title: string did?: string handle: string + bot?: BotConfig collection: string network: string color: string