fix: hide chat button and page unless AI Assistant installed

This commit is contained in:
Jake Turner 2026-02-03 17:03:00 -08:00 committed by Jake Turner
parent 18e55c747a
commit 5de3c5f261
3 changed files with 23 additions and 4 deletions

View File

@ -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: {

View File

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

View File

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