mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 03:29:25 +01:00
fix: hide chat button and page unless AI Assistant installed
This commit is contained in:
parent
18e55c747a
commit
5de3c5f261
|
|
@ -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, response }: HttpContext) {
|
||||
const aiAssistantInstalled = await this.systemService.checkServiceInstalled(SERVICE_NAMES.OLLAMA)
|
||||
if (!aiAssistantInstalled) {
|
||||
return response.status(404).json({ error: 'AI Assistant service not installed' })
|
||||
}
|
||||
|
||||
async inertia({ inertia }: HttpContext) {
|
||||
const chatSuggestionsEnabled = await KVStore.getValue('chat.suggestionsEnabled')
|
||||
return inertia.render('chat', {
|
||||
settings: {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user