v0.2.0: CRM/ERP 系统升级 - 清理 .gitignore 并移除误提交的 venv/env/db 文件
- 更新 .gitignore:全面覆盖环境变量、数据库、日志、缓存、上传文件 - 移除误跟踪的 server/venv/、crm_data.db、.env 文件 - 新增 server/.env.example 模板 - 新增合同管理、利润核算、AI教练等功能模块 - 新增 Playwright e2e 测试套件 - 前后端多项功能升级和 bug 修复
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
AI 教练引擎路由 —— /api/ai-coaching
|
||||
Dify 回调 + SSE 通知流
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import uuid
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from app.api.deps import get_current_user
|
||||
from app.db.database import get_db
|
||||
from app.schemas.auth import CurrentUserPayload
|
||||
from app.schemas.response import ok
|
||||
from app.services import ai_coaching_service as svc
|
||||
|
||||
router = APIRouter(prefix="/ai-coaching", tags=["AI教练引擎"])
|
||||
|
||||
|
||||
@router.post("/dify-callback/{sales_log_id}", summary="Dify Workflow 回调端点")
|
||||
async def dify_coaching_callback(
|
||||
sales_log_id: uuid.UUID,
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> dict:
|
||||
"""接收 Dify Workflow 的异步回调,写回教练反馈"""
|
||||
import json
|
||||
body = await request.json()
|
||||
await svc.handle_dify_coaching_callback(db, sales_log_id, body)
|
||||
return ok(message="教练反馈已回写")
|
||||
|
||||
|
||||
@router.get("/notifications/stream", summary="SSE 通知流")
|
||||
async def sse_notifications(
|
||||
current_user: CurrentUserPayload = Depends(get_current_user),
|
||||
):
|
||||
"""Server-Sent Events 推送通知(AI 教练反馈、系统通知等)"""
|
||||
return StreamingResponse(
|
||||
svc.sse_notification_generator(current_user.user_id),
|
||||
media_type="text/event-stream",
|
||||
headers={
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user