Add AI chat functionality with fallback for unconfigured services

Update AIChat component to handle AI service configuration errors and register new API routes for AI chat and title generation.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 33138a67-a89c-47ac-a551-6b983481ce56
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/BDxFKG1
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sirpiglr 2025-12-06 04:00:55 +00:00
parent 834c4bd56e
commit 4fcda7c56a
2 changed files with 22 additions and 6 deletions

View file

@ -101,12 +101,22 @@ export const AIChat: React.FC<AIChatProps> = ({
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',

View file

@ -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;
}