diff --git a/client/components/ai/AIChat.tsx b/client/components/ai/AIChat.tsx index 898523aa..bcc2563e 100644 --- a/client/components/ai/AIChat.tsx +++ b/client/components/ai/AIChat.tsx @@ -101,12 +101,22 @@ export const AIChat: React.FC = ({ try { const history = messages.filter(m => m.role !== 'model' || messages.indexOf(m) > 0); - const response = await runChat( - content, - history, - currentPersona.systemInstruction, - currentPersona.tools - ); + let response: string; + try { + response = await runChat( + content, + history, + currentPersona.systemInstruction, + currentPersona.tools + ); + } catch (err) { + const errorMessage = err instanceof Error ? err.message : 'Unknown error'; + if (errorMessage.includes('AI service not configured') || errorMessage.includes('not configured')) { + response = "The AI service is currently being set up. Please check back soon, or contact the administrator to configure the Gemini API key."; + } else { + throw err; + } + } const modelMessage: ChatMessageType = { role: 'model', diff --git a/server/index.ts b/server/index.ts index acc43283..e746ff25 100644 --- a/server/index.ts +++ b/server/index.ts @@ -7,6 +7,8 @@ import { emailService } from "./email"; import { randomUUID, createHash, createVerify, randomBytes } from "crypto"; import blogIndexHandler from "../api/blog/index"; import blogSlugHandler from "../api/blog/[slug]"; +import aiChatHandler from "../api/ai/chat"; +import aiTitleHandler from "../api/ai/title"; // Discord Interactions Handler const handleDiscordInteractions = async ( @@ -7104,5 +7106,9 @@ export function createServer() { return blogSlugHandler(req, res); }); + // AI Chat API routes + app.post("/api/ai/chat", aiChatHandler); + app.post("/api/ai/title", aiTitleHandler); + return app; }