tools.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 fetchModelToolList = (collectionName: string) => {
  13. return get<Tool[]>(`/workspaces/current/tool-provider/model/tools?provider=${collectionName}`)
  14. }
  15. export const fetchBuiltInToolCredentialSchema = (collectionName: string) => {
  16. return get<ToolCredential[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/credentials_schema`)
  17. }
  18. export const updateBuiltInToolCredential = (collectionName: string, credential: Record<string, any>) => {
  19. return post(`/workspaces/current/tool-provider/builtin/${collectionName}/update`, {
  20. body: {
  21. credentials: credential,
  22. },
  23. })
  24. }
  25. export const removeBuiltInToolCredential = (collectionName: string) => {
  26. return post(`/workspaces/current/tool-provider/builtin/${collectionName}/delete`, {
  27. body: {},
  28. })
  29. }
  30. export const parseParamsSchema = (schema: string) => {
  31. return post<{ parameters_schema: CustomParamSchema[]; schema_type: string }>('/workspaces/current/tool-provider/api/schema', {
  32. body: {
  33. schema,
  34. },
  35. })
  36. }
  37. export const fetchCustomCollection = (collectionName: string) => {
  38. return get<CustomCollectionBackend>(`/workspaces/current/tool-provider/api/get?provider=${collectionName}`)
  39. }
  40. export const createCustomCollection = (collection: CustomCollectionBackend) => {
  41. return post('/workspaces/current/tool-provider/api/add', {
  42. body: {
  43. ...collection,
  44. },
  45. })
  46. }
  47. export const updateCustomCollection = (collection: CustomCollectionBackend) => {
  48. return post('/workspaces/current/tool-provider/api/update', {
  49. body: {
  50. ...collection,
  51. },
  52. })
  53. }
  54. export const removeCustomCollection = (collectionName: string) => {
  55. return post('/workspaces/current/tool-provider/api/delete', {
  56. body: {
  57. provider: collectionName,
  58. },
  59. })
  60. }
  61. export const importSchemaFromURL = (url: string) => {
  62. return get('/workspaces/current/tool-provider/api/remote', {
  63. params: {
  64. url,
  65. },
  66. })
  67. }
  68. export const testAPIAvailable = (payload: any) => {
  69. return post('/workspaces/current/tool-provider/api/test/pre', {
  70. body: {
  71. ...payload,
  72. },
  73. })
  74. }