"""Define a separacao entre runtime de atendimento e runtime de geracao de tools.""" from __future__ import annotations from enum import Enum from pydantic import BaseModel from shared.contracts.access_control import AdminPermission from shared.contracts.tool_publication import ServiceName class ModelRuntimeTarget(str, Enum): ATENDIMENTO = "atendimento" TOOL_GENERATION = "tool_generation" class ModelRuntimePurpose(str, Enum): CUSTOMER_RESPONSE = "customer_response" TOOL_GENERATION_AND_VALIDATION = "tool_generation_and_validation" class ModelRuntimeSeparationRule(str, Enum): SEPARATE_CONFIG_KEYS = "separate_config_keys" SEPARATE_CATALOG_TARGETS = "separate_catalog_targets" INDEPENDENT_PUBLICATION = "independent_publication" INDEPENDENT_ROLLBACK = "independent_rollback" NO_IMPLICIT_PROPAGATION = "no_implicit_propagation" class ModelRuntimeSeparationContract(BaseModel): runtime_target: ModelRuntimeTarget config_key: str catalog_runtime_target: ModelRuntimeTarget purpose: ModelRuntimePurpose consumed_by_service: ServiceName description: str read_permission: AdminPermission = AdminPermission.VIEW_SYSTEM write_permission: AdminPermission = AdminPermission.MANAGE_SETTINGS published_independently: bool = True rollback_independently: bool = True cross_target_propagation_allowed: bool = False affects_customer_response: bool = False can_generate_code: bool = False MODEL_RUNTIME_PROFILES: tuple[ModelRuntimeSeparationContract, ...] = ( ModelRuntimeSeparationContract( runtime_target=ModelRuntimeTarget.ATENDIMENTO, config_key="atendimento_runtime_profile", catalog_runtime_target=ModelRuntimeTarget.ATENDIMENTO, purpose=ModelRuntimePurpose.CUSTOMER_RESPONSE, consumed_by_service=ServiceName.PRODUCT, description="Runtime do modelo que responde ao cliente final no fluxo de atendimento.", affects_customer_response=True, can_generate_code=False, ), ModelRuntimeSeparationContract( runtime_target=ModelRuntimeTarget.TOOL_GENERATION, config_key="tool_generation_runtime_profile", catalog_runtime_target=ModelRuntimeTarget.TOOL_GENERATION, purpose=ModelRuntimePurpose.TOOL_GENERATION_AND_VALIDATION, consumed_by_service=ServiceName.ADMIN, description="Runtime do modelo usado para gerar e validar novas tools no contexto administrativo.", affects_customer_response=False, can_generate_code=True, ), ) MODEL_RUNTIME_SEPARATION_RULES: tuple[ModelRuntimeSeparationRule, ...] = ( ModelRuntimeSeparationRule.SEPARATE_CONFIG_KEYS, ModelRuntimeSeparationRule.SEPARATE_CATALOG_TARGETS, ModelRuntimeSeparationRule.INDEPENDENT_PUBLICATION, ModelRuntimeSeparationRule.INDEPENDENT_ROLLBACK, ModelRuntimeSeparationRule.NO_IMPLICIT_PROPAGATION, ) def get_model_runtime_contract(runtime_target: ModelRuntimeTarget | str) -> ModelRuntimeSeparationContract | None: normalized = str(runtime_target or "").strip().lower() for runtime_contract in MODEL_RUNTIME_PROFILES: if runtime_contract.runtime_target.value == normalized: return runtime_contract return None