tools.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { get, post } from './base'
  2. import type { Collection, CustomCollectionBackend, CustomParamSchema, Tool, ToolCredential } from '@/app/components/tools/types'
  3. export const fetchCollectionList = () => {
  4. return get<Collection[]>('/workspaces/current/tool-providers')
  5. }
  6. export const fetchBuiltInToolList = (collectionName: string) => {
  7. return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
  8. }
  9. export const fetchCustomToolList = (collectionName: string) => {
  10. return get<Tool[]>(`/workspaces/current/tool-provider/api/tools?provider=${collectionName}`)
  11. }
  12. export const fetchBuiltInToolCredentialSchema = (collectionName: string) => {
  13. return get<ToolCredential[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/credentials_schema`)
  14. }
  15. export const updateBuiltInToolCredential = (collectionName: string, credential: Record<string, any>) => {
  16. return post(`/workspaces/current/tool-provider/builtin/${collectionName}/update`, {
  17. body: {
  18. credentials: credential,
  19. },
  20. })
  21. }
  22. export const removeBuiltInToolCredential = (collectionName: string) => {
  23. return post(`/workspaces/current/tool-provider/builtin/${collectionName}/delete`, {
  24. body: {},
  25. })
  26. }
  27. export const parseParamsSchema = (schema: string) => {
  28. return post<{ parameters_schema: CustomParamSchema[]; schema_type: string }>('/workspaces/current/tool-provider/api/schema', {
  29. body: {
  30. schema,
  31. },
  32. })
  33. }
  34. export const fetchCustomCollection = (collectionName: string) => {
  35. return get<CustomCollectionBackend>(`/workspaces/current/tool-provider/api/get?provider=${collectionName}`)
  36. }
  37. export const createCustomCollection = (collection: CustomCollectionBackend) => {
  38. return post('/workspaces/current/tool-provider/api/add', {
  39. body: {
  40. ...collection,
  41. },
  42. })
  43. }
  44. export const updateCustomCollection = (collection: CustomCollectionBackend) => {
  45. return post('/workspaces/current/tool-provider/api/update', {
  46. body: {
  47. ...collection,
  48. },
  49. })
  50. }
  51. export const removeCustomCollection = (collectionName: string) => {
  52. return post('/workspaces/current/tool-provider/api/delete', {
  53. body: {
  54. provider: collectionName,
  55. },
  56. })
  57. }
  58. export const importSchemaFromURL = (url: string) => {
  59. return get('/workspaces/current/tool-provider/api/remote', {
  60. params: {
  61. url,
  62. },
  63. })
  64. }
  65. export const testAPIAvailable = (payload: any) => {
  66. return post('/workspaces/current/tool-provider/api/test/pre', {
  67. body: {
  68. ...payload,
  69. },
  70. })
  71. }