feat: add use tools
parent
d3a9747bbd
commit
91b3aec292
@ -0,0 +1,55 @@
|
||||
import { get } from './base'
|
||||
import type {
|
||||
Tool,
|
||||
} from '@/app/components/tools/types'
|
||||
import type { ToolWithProvider } from '@/app/components/workflow/types'
|
||||
import {
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {
|
||||
useQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
const NAME_SPACE = 'tools'
|
||||
|
||||
export const useAllBuiltInTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: [NAME_SPACE, 'builtIn'],
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/builtin'),
|
||||
})
|
||||
}
|
||||
|
||||
const useAllCustomToolsKey = [NAME_SPACE, 'customTools']
|
||||
export const useAllCustomTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: useAllCustomToolsKey,
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/api'),
|
||||
})
|
||||
}
|
||||
|
||||
export const useInvalidateAllCustomTools = () => {
|
||||
const queryClient = useQueryClient()
|
||||
return {
|
||||
invalidate: () => {
|
||||
queryClient.invalidateQueries(
|
||||
{
|
||||
queryKey: useAllCustomToolsKey,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const useAllWorkflowTools = () => {
|
||||
return useQuery<ToolWithProvider[]>({
|
||||
queryKey: [NAME_SPACE, 'workflowTools'],
|
||||
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/workflow'),
|
||||
})
|
||||
}
|
||||
|
||||
export const useBuiltInTools = (collectionName: string) => {
|
||||
return useQuery({
|
||||
queryKey: [NAME_SPACE, 'builtIn', collectionName],
|
||||
queryFn: () => get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`),
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue