gateway/modules/services/__init__.py
2025-09-30 18:30:33 +02:00

86 lines
3.3 KiB
Python

from typing import Any
from modules.datamodels.datamodelUam import User
from modules.datamodels.datamodelChat import ChatWorkflow
class PublicService:
"""Lightweight proxy exposing only public callable attributes of a target.
- Hides names starting with '_'
- Optionally restricts to callables only
- Optional name_filter predicate for allow-list patterns
"""
def __init__(self, target: Any, functions_only: bool = True, name_filter=None):
self._target = target
self._functions_only = functions_only
self._name_filter = name_filter
def __getattr__(self, name: str):
if name.startswith('_'):
raise AttributeError(f"'{type(self._target).__name__}' attribute '{name}' is private")
if self._name_filter and not self._name_filter(name):
raise AttributeError(f"'{name}' not exposed by policy")
attr = getattr(self._target, name)
if self._functions_only and not callable(attr):
raise AttributeError(f"'{name}' is not a function")
return attr
def __dir__(self):
names = [
n for n in dir(self._target)
if not n.startswith('_')
and (not self._functions_only or callable(getattr(self._target, n, None)))
and (self._name_filter(n) if self._name_filter else True)
]
return sorted(names)
class Services:
def __init__(self, user: User, workflow: ChatWorkflow = None):
self.user: User = user
self.workflow: ChatWorkflow = workflow
# Initialize interfaces
from modules.interfaces.interfaceDbChatObjects import getInterface as getChatInterface
self.interfaceDbChat = getChatInterface(user)
from modules.interfaces.interfaceDbAppObjects import getInterface as getAppInterface
self.interfaceDbApp = getAppInterface(user)
from modules.interfaces.interfaceDbComponentObjects import getInterface as getComponentInterface
self.interfaceDbComponent = getComponentInterface(user)
# Initialize service packages
from .serviceExtraction.mainServiceExtraction import ExtractionService
self.extraction = PublicService(ExtractionService(self))
from .serviceGeneration.mainServiceGeneration import GenerationService
self.generation = PublicService(GenerationService(self))
from .serviceNeutralization.mainServiceNeutralization import NeutralizationService
self.neutralization = PublicService(NeutralizationService(self))
from .serviceSharepoint.mainServiceSharepoint import SharepointService
self.sharepoint = PublicService(SharepointService(self))
from .serviceAi.mainServiceAi import AiService
self.ai = PublicService(AiService(self))
from .serviceTicket.mainServiceTicket import TicketService
self.ticket = PublicService(TicketService(self))
from .serviceWorkflow.mainServiceWorkflow import WorkflowService
self.workflow = PublicService(WorkflowService(self))
from .serviceUtils.mainServiceUtils import UtilsService
self.utils = PublicService(UtilsService(self))
def getInterface(user: User, workflow: ChatWorkflow) -> Services:
return Services(user, workflow)