jan/web/hooks/useGetAssistants.ts
NamH 86e693b250
refactor: model plugin to follow new specs (#682)
* refactor: model plugin to follow new specs

Signed-off-by: James <james@jan.ai>

* chore: rebase main

chore: rebase main

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
2023-11-29 11:36:59 +07:00

36 lines
746 B
TypeScript

import { useEffect, useState } from 'react'
import { Assistant, PluginType } from '@janhq/core'
import { AssistantPlugin } from '@janhq/core/lib/plugins'
import { pluginManager } from '@/plugin/PluginManager'
const getAssistants = async (): Promise<Assistant[]> => {
return (
pluginManager.get<AssistantPlugin>(PluginType.Assistant)?.getAssistants() ??
[]
)
}
/**
* Hooks for get assistants
*
* @returns assistants
*/
export default function useGetAssistants() {
const [assistants, setAssistants] = useState<Assistant[]>([])
useEffect(() => {
getAssistants()
.then((data) => {
setAssistants(data)
})
.catch((err) => {
console.error(err)
})
}, [])
return { assistants }
}