diff --git a/admin/app/controllers/chats_controller.ts b/admin/app/controllers/chats_controller.ts index 9d412bc..f6ad4d7 100644 --- a/admin/app/controllers/chats_controller.ts +++ b/admin/app/controllers/chats_controller.ts @@ -4,12 +4,19 @@ import { ChatService } from '#services/chat_service' import { createSessionSchema, updateSessionSchema, addMessageSchema } from '#validators/chat' import { parseBoolean } from '../utils/misc.js' import KVStore from '#models/kv_store' +import { SystemService } from '#services/system_service' +import { SERVICE_NAMES } from '../../constants/service_names.js' @inject() export default class ChatsController { - constructor(private chatService: ChatService) {} + constructor(private chatService: ChatService, private systemService: SystemService) {} - async inertia({ inertia }: HttpContext) { + async inertia({ inertia, response }: HttpContext) { + const aiAssistantInstalled = await this.systemService.checkServiceInstalled(SERVICE_NAMES.OLLAMA) + if (!aiAssistantInstalled) { + return response.status(404).json({ error: 'AI Assistant service not installed' }) + } + const chatSuggestionsEnabled = await KVStore.getValue('chat.suggestionsEnabled') return inertia.render('chat', { settings: { diff --git a/admin/app/services/system_service.ts b/admin/app/services/system_service.ts index c302dc3..3ca2744 100644 --- a/admin/app/services/system_service.ts +++ b/admin/app/services/system_service.ts @@ -20,6 +20,11 @@ export class SystemService { constructor(private dockerService: DockerService) {} + async checkServiceInstalled(serviceName: string): Promise { + const services = await this.getServices({ installedOnly: true }); + return services.some(service => service.service_name === serviceName); + } + async getInternetStatus(): Promise { const DEFAULT_TEST_URL = 'https://1.1.1.1/cdn-cgi/trace' const MAX_ATTEMPTS = 3 diff --git a/admin/inertia/layouts/AppLayout.tsx b/admin/inertia/layouts/AppLayout.tsx index 1b2359a..d740058 100644 --- a/admin/inertia/layouts/AppLayout.tsx +++ b/admin/inertia/layouts/AppLayout.tsx @@ -2,9 +2,12 @@ import { useState } from 'react' import Footer from '~/components/Footer' import ChatButton from '~/components/chat/ChatButton' import ChatModal from '~/components/chat/ChatModal' +import useServiceInstalledStatus from '~/hooks/useServiceInstalledStatus' +import { SERVICE_NAMES } from '../../constants/service_names' export default function AppLayout({ children }: { children: React.ReactNode }) { const [isChatOpen, setIsChatOpen] = useState(false) + const aiAssistantInstalled = useServiceInstalledStatus(SERVICE_NAMES.OLLAMA) return (
@@ -19,8 +22,12 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {
{children}
) }