96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
|
|
# =============================================================================
|
|||
|
|
# 企微IT智能服务台 — 阶段5 自动化 外部客户端工厂
|
|||
|
|
# =============================================================================
|
|||
|
|
# 说明:集中解析各外部系统的配置来源:
|
|||
|
|
# - 优先使用 settings 中的 AUTOMATION_* 环境变量(架构约定)
|
|||
|
|
# - 缺失时回退到既有 system_configs 表配置
|
|||
|
|
# (huorong/lianruan/ragflow 在 app/integrations/*/config.py 中已有 getter)
|
|||
|
|
#
|
|||
|
|
# 为什么有工厂:自动化引擎既能用新加的 AUTOMATION_* 配置,也能复用阶段1-4
|
|||
|
|
# 已落地的集成配置,避免重复维护两套配置源。
|
|||
|
|
# =============================================================================
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
import logging
|
|||
|
|
from typing import Any, Callable, Optional
|
|||
|
|
|
|||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
|
|
|||
|
|
from app.config import settings
|
|||
|
|
|
|||
|
|
logger = logging.getLogger(__name__)
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def build_huorong_client(
|
|||
|
|
db: AsyncSession, audit: Optional[Callable[..., Any]] = None
|
|||
|
|
):
|
|||
|
|
"""构建火绒客户端:settings 优先,否则 system_configs。"""
|
|||
|
|
from app.integrations.huorong.client import HuorongClient
|
|||
|
|
|
|||
|
|
if (
|
|||
|
|
settings.automation_huorong_base_url
|
|||
|
|
and settings.automation_huorong_access_key_id
|
|||
|
|
and settings.automation_huorong_access_key_secret
|
|||
|
|
):
|
|||
|
|
return HuorongClient(
|
|||
|
|
access_key_id=settings.automation_huorong_access_key_id,
|
|||
|
|
access_key_secret=settings.automation_huorong_access_key_secret,
|
|||
|
|
base_url=settings.automation_huorong_base_url,
|
|||
|
|
)
|
|||
|
|
from app.integrations.huorong.config import get_huorong_client
|
|||
|
|
|
|||
|
|
return await get_huorong_client(db)
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def build_lianruan_client(
|
|||
|
|
db: AsyncSession, audit: Optional[Callable[..., Any]] = None
|
|||
|
|
):
|
|||
|
|
"""构建联软客户端:settings 优先,否则 system_configs。"""
|
|||
|
|
from app.integrations.lianruan.client import LianruanClient
|
|||
|
|
|
|||
|
|
if (
|
|||
|
|
settings.automation_lianruan_base_url
|
|||
|
|
and settings.automation_lianruan_api_account
|
|||
|
|
and settings.automation_lianruan_api_password
|
|||
|
|
):
|
|||
|
|
return LianruanClient(
|
|||
|
|
base_url=settings.automation_lianruan_base_url,
|
|||
|
|
api_account=settings.automation_lianruan_api_account,
|
|||
|
|
api_password=settings.automation_lianruan_api_password,
|
|||
|
|
validate_key=settings.automation_lianruan_validate_key,
|
|||
|
|
)
|
|||
|
|
from app.integrations.lianruan.config import get_lianruan_client
|
|||
|
|
|
|||
|
|
return await get_lianruan_client(db)
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def build_ragflow_client(
|
|||
|
|
db: AsyncSession, audit: Optional[Callable[..., Any]] = None
|
|||
|
|
):
|
|||
|
|
"""构建 RAGFlow 客户端:settings 优先,否则 system_configs。"""
|
|||
|
|
from app.integrations.ragflow.client import RagflowClient
|
|||
|
|
|
|||
|
|
if settings.automation_ragflow_base_url and settings.automation_ragflow_api_key:
|
|||
|
|
return RagflowClient(
|
|||
|
|
api_key=settings.automation_ragflow_api_key,
|
|||
|
|
base_url=settings.automation_ragflow_base_url,
|
|||
|
|
)
|
|||
|
|
from app.integrations.ragflow.config import get_ragflow_client
|
|||
|
|
|
|||
|
|
return await get_ragflow_client(db)
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def build_dify_client(audit: Optional[Callable[..., Any]] = None):
|
|||
|
|
"""构建 Dify 客户端(仅 settings)。"""
|
|||
|
|
from app.integrations.dify import get_dify_client
|
|||
|
|
|
|||
|
|
return await get_dify_client(audit=audit)
|
|||
|
|
|
|||
|
|
|
|||
|
|
async def build_ehr_client(audit: Optional[Callable[..., Any]] = None):
|
|||
|
|
"""构建 EHR 客户端(仅 settings)。"""
|
|||
|
|
from app.integrations.ehr import get_ehr_client
|
|||
|
|
|
|||
|
|
return await get_ehr_client(audit=audit)
|