tools.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { get, post } from './base'
  2. import type {
  3. Collection,
  4. CustomCollectionBackend,
  5. CustomParamSchema,
  6. Tool,
  7. ToolCredential,
  8. WorkflowToolProviderRequest,
  9. WorkflowToolProviderResponse,
  10. } from '@/app/components/tools/types'
  11. import type { ToolWithProvider } from '@/app/components/workflow/types'
  12. import type { Label } from '@/app/components/tools/labels/constant'
  13. export const fetchCollectionList = () => {
  14. return get<Collection[]>('/workspaces/current/tool-providers')
  15. }
  16. export const fetchBuiltInToolList = (collectionName: string) => {
  17. return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
  18. }
  19. export const fetchCustomToolList = (collectionName: string) => {
  20. return get<Tool[]>(`/workspaces/current/tool-provider/api/tools?provider=${collectionName}`)
  21. }
  22. export const fetchModelToolList = (collectionName: string) => {
  23. return get<Tool[]>(`/workspaces/current/tool-provider/model/tools?provider=${collectionName}`)
  24. }
  25. export const fetchWorkflowToolList = (appID: string) => {
  26. return get<Tool[]>(`/workspaces/current/tool-provider/workflow/tools?workflow_tool_id=${appID}`)
  27. }
  28. export const fetchBuiltInToolCredentialSchema = (collectionName: string) => {
  29. return get<ToolCredential[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/credentials_schema`)
  30. }
  31. export const fetchBuiltInToolCredential = (collectionName: string) => {
  32. return get<ToolCredential[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/credentials`)
  33. }
  34. export const updateBuiltInToolCredential = (collectionName: string, credential: Record<string, any>) => {
  35. return post(`/workspaces/current/tool-provider/builtin/${collectionName}/update`, {
  36. body: {
  37. credentials: credential,
  38. },
  39. })
  40. }
  41. export const removeBuiltInToolCredential = (collectionName: string) => {
  42. return post(`/workspaces/current/tool-provider/builtin/${collectionName}/delete`, {
  43. body: {},
  44. })
  45. }
  46. export const parseParamsSchema = (schema: string) => {
  47. return post<{ parameters_schema: CustomParamSchema[]; schema_type: string }>('/workspaces/current/tool-provider/api/schema', {
  48. body: {
  49. schema,
  50. },
  51. })
  52. }
  53. export const fetchCustomCollection = (collectionName: string) => {
  54. return get<CustomCollectionBackend>(`/workspaces/current/tool-provider/api/get?provider=${collectionName}`)
  55. }
  56. export const createCustomCollection = (collection: CustomCollectionBackend) => {
  57. return post('/workspaces/current/tool-provider/api/add', {
  58. body: {
  59. ...collection,
  60. },
  61. })
  62. }
  63. export const updateCustomCollection = (collection: CustomCollectionBackend) => {
  64. return post('/workspaces/current/tool-provider/api/update', {
  65. body: {
  66. ...collection,
  67. },
  68. })
  69. }
  70. export const removeCustomCollection = (collectionName: string) => {
  71. return post('/workspaces/current/tool-provider/api/delete', {
  72. body: {
  73. provider: collectionName,
  74. },
  75. })
  76. }
  77. export const importSchemaFromURL = (url: string) => {
  78. return get('/workspaces/current/tool-provider/api/remote', {
  79. params: {
  80. url,
  81. },
  82. })
  83. }
  84. export const testAPIAvailable = (payload: any) => {
  85. return post('/workspaces/current/tool-provider/api/test/pre', {
  86. body: {
  87. ...payload,
  88. },
  89. })
  90. }
  91. export const fetchAllBuiltInTools = () => {
  92. return get<ToolWithProvider[]>('/workspaces/current/tools/builtin')
  93. }
  94. export const fetchAllCustomTools = () => {
  95. return get<ToolWithProvider[]>('/workspaces/current/tools/api')
  96. }
  97. export const fetchAllWorkflowTools = () => {
  98. return get<ToolWithProvider[]>('/workspaces/current/tools/workflow')
  99. }
  100. export const fetchLabelList = () => {
  101. return get<Label[]>('/workspaces/current/tool-labels')
  102. }
  103. export const createWorkflowToolProvider = (payload: WorkflowToolProviderRequest & { workflow_app_id: string }) => {
  104. return post('/workspaces/current/tool-provider/workflow/create', {
  105. body: { ...payload },
  106. })
  107. }
  108. export const saveWorkflowToolProvider = (payload: WorkflowToolProviderRequest & Partial<{
  109. workflow_app_id: string
  110. workflow_tool_id: string
  111. }>) => {
  112. return post('/workspaces/current/tool-provider/workflow/update', {
  113. body: { ...payload },
  114. })
  115. }
  116. export const fetchWorkflowToolDetailByAppID = (appID: string) => {
  117. return get<WorkflowToolProviderResponse>(`/workspaces/current/tool-provider/workflow/get?workflow_app_id=${appID}`)
  118. }
  119. export const fetchWorkflowToolDetail = (toolID: string) => {
  120. return get<WorkflowToolProviderResponse>(`/workspaces/current/tool-provider/workflow/get?workflow_tool_id=${toolID}`)
  121. }
  122. export const deleteWorkflowTool = (toolID: string) => {
  123. return post('/workspaces/current/tool-provider/workflow/delete', {
  124. body: {
  125. workflow_tool_id: toolID,
  126. },
  127. })
  128. }