user_entities.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from enum import Enum
  2. from typing import Optional
  3. from pydantic import BaseModel
  4. from core.tools.entities.common_entities import I18nObject
  5. from core.tools.entities.tool_entities import ToolProviderCredentials
  6. from core.tools.tool.tool import ToolParameter
  7. class UserTool(BaseModel):
  8. author: str
  9. name: str # identifier
  10. label: I18nObject # label
  11. description: I18nObject
  12. parameters: Optional[list[ToolParameter]]
  13. class UserToolProvider(BaseModel):
  14. class ProviderType(Enum):
  15. BUILTIN = "builtin"
  16. APP = "app"
  17. API = "api"
  18. id: str
  19. author: str
  20. name: str # identifier
  21. description: I18nObject
  22. icon: str
  23. label: I18nObject # label
  24. type: ProviderType
  25. masked_credentials: dict = None
  26. original_credentials: dict = None
  27. is_team_authorization: bool = False
  28. allow_delete: bool = True
  29. tools: list[UserTool] = None
  30. def to_dict(self) -> dict:
  31. return {
  32. 'id': self.id,
  33. 'author': self.author,
  34. 'name': self.name,
  35. 'description': self.description.to_dict(),
  36. 'icon': self.icon,
  37. 'label': self.label.to_dict(),
  38. 'type': self.type.value,
  39. 'team_credentials': self.masked_credentials,
  40. 'is_team_authorization': self.is_team_authorization,
  41. 'allow_delete': self.allow_delete,
  42. 'tools': self.tools
  43. }
  44. class UserToolProviderCredentials(BaseModel):
  45. credentials: dict[str, ToolProviderCredentials]