|  | @@ -1,10 +1,10 @@
 | 
											
												
													
														|  | -from typing import Any, Dict
 |  | 
 | 
											
												
													
														|  | 
 |  | +from typing import Dict, Any
 | 
											
												
													
														|  | 
 |  | +from pydantic import BaseModel
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -from core.helper import encrypter
 |  | 
 | 
											
												
													
														|  |  from core.tools.entities.tool_entities import ToolProviderCredentials
 |  |  from core.tools.entities.tool_entities import ToolProviderCredentials
 | 
											
												
													
														|  |  from core.tools.provider.tool_provider import ToolProviderController
 |  |  from core.tools.provider.tool_provider import ToolProviderController
 | 
											
												
													
														|  | -from pydantic import BaseModel
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +from core.helper import encrypter
 | 
											
												
													
														|  | 
 |  | +from core.helper.tool_provider_cache import ToolProviderCredentialsCacheType, ToolProviderCredentialsCache
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  class ToolConfiguration(BaseModel):
 |  |  class ToolConfiguration(BaseModel):
 | 
											
												
													
														|  |      tenant_id: str
 |  |      tenant_id: str
 | 
											
										
											
												
													
														|  | @@ -63,8 +63,15 @@ class ToolConfiguration(BaseModel):
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |          return a deep copy of credentials with decrypted values
 |  |          return a deep copy of credentials with decrypted values
 | 
											
												
													
														|  |          """
 |  |          """
 | 
											
												
													
														|  | 
 |  | +        cache = ToolProviderCredentialsCache(
 | 
											
												
													
														|  | 
 |  | +            tenant_id=self.tenant_id, 
 | 
											
												
													
														|  | 
 |  | +            identity_id=f'{self.provider_controller.app_type.value}.{self.provider_controller.identity.name}',
 | 
											
												
													
														|  | 
 |  | +            cache_type=ToolProviderCredentialsCacheType.PROVIDER
 | 
											
												
													
														|  | 
 |  | +        )
 | 
											
												
													
														|  | 
 |  | +        cached_credentials = cache.get()
 | 
											
												
													
														|  | 
 |  | +        if cached_credentials:
 | 
											
												
													
														|  | 
 |  | +            return cached_credentials
 | 
											
												
													
														|  |          credentials = self._deep_copy(credentials)
 |  |          credentials = self._deep_copy(credentials)
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |          # get fields need to be decrypted
 |  |          # get fields need to be decrypted
 | 
											
												
													
														|  |          fields = self.provider_controller.get_credentials_schema()
 |  |          fields = self.provider_controller.get_credentials_schema()
 | 
											
												
													
														|  |          for field_name, field in fields.items():
 |  |          for field_name, field in fields.items():
 | 
											
										
											
												
													
														|  | @@ -74,5 +81,6 @@ class ToolConfiguration(BaseModel):
 | 
											
												
													
														|  |                          credentials[field_name] = encrypter.decrypt_token(self.tenant_id, credentials[field_name])
 |  |                          credentials[field_name] = encrypter.decrypt_token(self.tenant_id, credentials[field_name])
 | 
											
												
													
														|  |                      except:
 |  |                      except:
 | 
											
												
													
														|  |                          pass
 |  |                          pass
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        cache.set(credentials)
 | 
											
												
													
														|  |          return credentials
 |  |          return credentials
 |