feat(hub): add data dashboard and AI chat with session history
Add /dashboard with daily PnL overview and loss alerts. Extend AI coach chat with history sidebar, delete/switch sessions, message copy, and trading vs general bot modes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,7 +6,13 @@ from typing import Callable
|
||||
from fastapi import APIRouter, File, Form, HTTPException, UploadFile
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from hub_ai.chat import get_chat_state, send_chat_message, start_new_chat
|
||||
from hub_ai.chat import (
|
||||
get_chat_state,
|
||||
remove_chat_session,
|
||||
send_chat_message,
|
||||
start_new_chat,
|
||||
switch_chat_session,
|
||||
)
|
||||
from hub_ai.client import model_label
|
||||
from hub_ai.config import trading_day_reset_hour
|
||||
from hub_ai.context import build_daily_context
|
||||
@@ -27,6 +33,11 @@ class SummaryGenerateBody(BaseModel):
|
||||
|
||||
class ChatNewBody(BaseModel):
|
||||
trading_day: str = ""
|
||||
bot_mode: str = "trading"
|
||||
|
||||
|
||||
class ChatSwitchBody(BaseModel):
|
||||
session_id: str = Field(..., min_length=1)
|
||||
|
||||
|
||||
def create_hub_ai_router(*, load_all_exchanges: Callable[[], list]) -> APIRouter:
|
||||
@@ -91,7 +102,21 @@ def create_hub_ai_router(*, load_all_exchanges: Callable[[], list]) -> APIRouter
|
||||
@router.post("/chat/new")
|
||||
def api_ai_chat_new(body: ChatNewBody = ChatNewBody()):
|
||||
day = _day(body.trading_day)
|
||||
return start_new_chat(trading_day=day)
|
||||
return start_new_chat(trading_day=day, bot_mode=body.bot_mode or "trading")
|
||||
|
||||
@router.post("/chat/switch")
|
||||
def api_ai_chat_switch(body: ChatSwitchBody):
|
||||
try:
|
||||
return switch_chat_session(body.session_id.strip())
|
||||
except KeyError:
|
||||
raise HTTPException(status_code=404, detail="会话不存在")
|
||||
|
||||
@router.delete("/chat/session/{session_id}")
|
||||
def api_ai_chat_delete(session_id: str):
|
||||
result = remove_chat_session(session_id.strip())
|
||||
if not result.get("ok"):
|
||||
raise HTTPException(status_code=404, detail="会话不存在")
|
||||
return result
|
||||
|
||||
@router.post("/chat/send")
|
||||
async def api_ai_chat_send(
|
||||
|
||||
Reference in New Issue
Block a user