feat(hub): render AI summary account breakdown as icon table

Replace pipe-separated account lines with a structured table from stats_snapshot, including exchange icons and position remarks.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-07 00:28:24 +08:00
parent 8417784dd8
commit a5f5239be9
6 changed files with 195 additions and 7 deletions
+22
View File
@@ -271,6 +271,28 @@ def format_context_text(payload: dict) -> str:
return "\n".join(lines).strip()
def format_account_remark(ac: dict) -> str:
"""分户表格备注:持仓摘要或关注点。"""
positions = ac.get("positions") or []
if not positions:
issues = ac.get("issues") or []
if issues:
return "".join(str(x) for x in issues[:2])
return ""
parts: list[str] = []
for p in positions[:3]:
if not isinstance(p, dict):
continue
sym = p.get("symbol") or "?"
side = p.get("side") or "?"
contracts = p.get("contracts") if p.get("contracts") is not None else p.get("size")
upnl = _position_float_pnl(p)
parts.append(f"持仓: {sym} {side} 张数{contracts} 浮盈亏{upnl:.4f}U")
if len(positions) > 3:
parts.append(f"另有{len(positions) - 3}")
return "".join(parts) if parts else ""
def format_chat_context_brief(payload: dict, max_chars: int = 2500) -> str:
text = format_context_text(payload)
if len(text) <= max_chars:
+1 -1
View File
@@ -19,7 +19,7 @@ SUMMARY_SYSTEM = """
- **当前持仓浮盈亏(U)**:…(仅汇总已监控且有数据的账户)
**2. 分户明细**
每个账户一行:账户名 | 状态(已监控/未监控/连接异常) | 当日平仓盈亏 | 笔数 | 当前浮盈亏 | 备注
中控页面会自动渲染分户表格,本节不要输出 pipe 分隔行或 Markdown 表格;可写一句「见下表」或直接留空。
**3. 需关注**
仅有依据时列出(如:某户当日亏损最大、浮亏偏大、Flask/Agent 异常、有持仓但无本地监控等);若无则写「无」。
+3 -1
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
from typing import Any
from hub_ai.client import generate_text, model_label
from hub_ai.context import build_daily_context
from hub_ai.context import build_daily_context, format_account_remark
from hub_ai.prompts import SUMMARY_SYSTEM, build_summary_user_prompt
from hub_ai.store import append_summary, get_latest_summary, list_summaries
@@ -38,11 +38,13 @@ def generate_daily_summary(
"totals": ctx.get("totals"),
"by_account": {
str(ac.get("key") or ac.get("id")): {
"key": ac.get("key"),
"name": ac.get("name"),
"status": ac.get("status"),
"pnl_u": (ac.get("trade_stats") or {}).get("total_pnl_u"),
"closed_count": (ac.get("trade_stats") or {}).get("closed_count"),
"float_pnl_u": ac.get("float_pnl_u"),
"remark": format_account_remark(ac),
"issues": ac.get("issues") or [],
}
for ac in ctx.get("accounts") or []