Skip to content

Project NOMAD is an offline-first knowledge and education server. Wikipedia, thousands of books, courses, maps, and optional local AI, all running on hardware you own with no internet required.

TypeScript

fix: hide chat button and page unless AI Assistant installed

Jake Turner5de3c5f26178
diff --git a/admin/app/controllers/chats_controller.ts b/admin/app/controllers/chats_controller.ts
index 9d412bc7..f6ad4d7c 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 c302dc33..3ca27446 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<boolean> {
+ const services = await this.getServices({ installedOnly: true });
+ return services.some(service => service.service_name === serviceName);
+ }
+
async getInternetStatus(): Promise<boolean> {
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 1b2359a0..d740058f 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 (
<div className="min-h-screen flex flex-col">
@@ -19,8 +22,12 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {
<div className="flex-1 w-full bg-desert">{children}</div>
<Footer />
- <ChatButton onClick={() => setIsChatOpen(true)} />
- <ChatModal open={isChatOpen} onClose={() => setIsChatOpen(false)} />
+ {aiAssistantInstalled && (
+ <>
+ <ChatButton onClick={() => setIsChatOpen(true)} />
+ <ChatModal open={isChatOpen} onClose={() => setIsChatOpen(false)} />
+ </>
+ )}
</div>
)
}