chore: add facades refactor: core module export refactor: inference plugin - deprecate function registering (#537) * refactor: revamp inference plugin as class - deprecate function registering * refactor: monitoring plugin - deprecate service registering (#538) refactor: revamp inference plugin as class - deprecate function registering chore: update import refactor: plugin revamp - model management chore: update build steps and remove experimental plugins refactor: remove pluggable electron chore: add sorting for conversations chore: build plugins for testing chore: consistent plugin directory name chore: docs chore: fix CI chore: update conversation prefix
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { currentConversationAtom } from '@helpers/atoms/Conversation.atom'
|
|
import { activeModelAtom } from '@helpers/atoms/Model.atom'
|
|
import { useAtomValue } from 'jotai'
|
|
import { useEffect, useState } from 'react'
|
|
import { useGetDownloadedModels } from './useGetDownloadedModels'
|
|
import { Model } from '@janhq/core/lib/types'
|
|
|
|
export default function useGetInputState() {
|
|
const [inputState, setInputState] = useState<InputType>('loading')
|
|
const currentConvo = useAtomValue(currentConversationAtom)
|
|
const activeModel = useAtomValue(activeModelAtom)
|
|
const { downloadedModels } = useGetDownloadedModels()
|
|
|
|
const handleInputState = (
|
|
convo: Conversation | undefined,
|
|
currentModel: Model | undefined,
|
|
models: Model[]
|
|
) => {
|
|
if (convo == null) return
|
|
if (currentModel == null) {
|
|
setInputState('loading')
|
|
return
|
|
}
|
|
|
|
// check if convo model id is in downloaded models
|
|
const isModelAvailable = downloadedModels.some(
|
|
(model) => model._id === convo.modelId
|
|
)
|
|
|
|
if (!isModelAvailable) {
|
|
// can't find model in downloaded models
|
|
setInputState('model-not-found')
|
|
return
|
|
}
|
|
|
|
if (convo.modelId !== currentModel._id) {
|
|
// in case convo model and active model is different,
|
|
// ask user to init the required model
|
|
setInputState('model-mismatch')
|
|
return
|
|
}
|
|
|
|
setInputState('available')
|
|
}
|
|
|
|
useEffect(() => {
|
|
handleInputState(currentConvo, activeModel, downloadedModels)
|
|
}, [currentConvo, activeModel, downloadedModels])
|
|
|
|
return { inputState, currentConvo }
|
|
}
|
|
|
|
type InputType = 'available' | 'loading' | 'model-mismatch' | 'model-not-found'
|