tools.ts 3.1 KB

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