refactor(core): 重构核心模块结构并更新导入路径 - 将配置相关的设置从 app.core.config 移除 - 将常量定义从 app.core.constants 移除 - 将数据库相关功能从 app.core.database 移除 - 将基础数据库模型从 app.core.db_base 移除 - 将敏感信息掩码功能从 app.core.masking 移除 - 将中间件定义从 app.core.middleware 移除 - 将操作保护功能从 app.core.operation_guard 移除 - 将分页工具从 app.core.pagination 移除 - 将请求上下文管理从 app.core.request_context 移除 - 将调度器功能从 app.core.scheduler 移除 - 将安全认证逻辑从 app.core.security 移除 - 将任务队列相关功能从 app.core.task_queue 移除 - 将时间工具从 app.core.time 移除 - 更新 alembic 配置中的 Base 模型导入路径 - 更新各模块中对重构后组件的引用路径 ```
82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import ApiPrincipal, require_api_key, require_operations_enabled
|
|
from app.modules.audit.constants import AuditSource
|
|
from app.modules.ai_agent.schemas import (
|
|
AIAskRequest,
|
|
AIAskResponse,
|
|
DraftPolicyRequest,
|
|
InvestmentResearchRequest,
|
|
OpenClawToolInvokeRequest,
|
|
)
|
|
from app.modules.ai_agent.service import AIService
|
|
|
|
router = APIRouter(dependencies=[Depends(require_api_key)])
|
|
|
|
|
|
@router.post("/ask", response_model=AIAskResponse)
|
|
def ask(
|
|
payload: AIAskRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).ask(
|
|
payload.prompt,
|
|
payload.context,
|
|
actor=principal.actor,
|
|
source=AuditSource.API,
|
|
)
|
|
|
|
|
|
@router.get("/provider-health")
|
|
def provider_health(
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).provider_health(actor=principal.actor)
|
|
|
|
|
|
@router.post("/openclaw/tools/invoke")
|
|
def invoke_openclaw_tool(
|
|
payload: OpenClawToolInvokeRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
require_operations_enabled()
|
|
return AIService(db).invoke_openclaw_tool(
|
|
tool=payload.tool,
|
|
action=payload.action,
|
|
args=payload.args,
|
|
session_key=payload.session_key,
|
|
actor=principal.actor,
|
|
)
|
|
|
|
|
|
@router.post("/draft-policy", response_model=AIAskResponse)
|
|
def draft_policy(
|
|
payload: DraftPolicyRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).draft_policy(
|
|
title=payload.title,
|
|
policy_type=payload.policy_type,
|
|
requirements=payload.requirements,
|
|
actor=principal.actor,
|
|
)
|
|
|
|
|
|
@router.post("/investment-research", response_model=AIAskResponse)
|
|
def investment_research(
|
|
payload: InvestmentResearchRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).draft_investment_research(
|
|
symbol_or_topic=payload.symbol_or_topic,
|
|
risk_preference=payload.risk_preference,
|
|
actor=principal.actor,
|
|
)
|