utils.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { ValidatedStatus } from '../key-validator/declarations'
  2. import { updatePluginProviderAIKey, validatePluginProviderKey } from '@/service/common'
  3. export const validatePluginKey = async (pluginType: string, body: any) => {
  4. try {
  5. const res = await validatePluginProviderKey({
  6. url: `/workspaces/current/tool-providers/${pluginType}/credentials-validate`,
  7. body,
  8. })
  9. if (res.result === 'success')
  10. return Promise.resolve({ status: ValidatedStatus.Success })
  11. else
  12. return Promise.resolve({ status: ValidatedStatus.Error, message: res.error })
  13. }
  14. catch (e: any) {
  15. return Promise.resolve({ status: ValidatedStatus.Error, message: e.message })
  16. }
  17. }
  18. export const updatePluginKey = async (pluginType: string, body: any) => {
  19. try {
  20. const res = await updatePluginProviderAIKey({
  21. url: `/workspaces/current/tool-providers/${pluginType}/credentials`,
  22. body,
  23. })
  24. if (res.result === 'success')
  25. return Promise.resolve({ status: ValidatedStatus.Success })
  26. else
  27. return Promise.resolve({ status: ValidatedStatus.Error, message: res.error })
  28. }
  29. catch (e: any) {
  30. return Promise.resolve({ status: ValidatedStatus.Error, message: e.message })
  31. }
  32. }