tools.ts 4.8 KB

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