一、html需求详述 新建templateHtml.py来生成html文件 1.1 顶部导航栏
内容:
标题区域
筛选条件区域
1.2 主体内容区域
功能: 流程图可视化展示
1.2.1 节点交互
交互行为:
1.2.2 边交互
交互行为:
1.3 右侧详情面板
显示模式:
二、数据交互规范 新建templateData.py来获取接口数据 2.1 HTTP 接口
Base URL: http://www.bai.com
2.1.1 获取 Trace 列表
接口: GET /api/traces?status=running&limit=20
用途: 获取 trace_id 列表,顶部 title 显示选中 trace 的 task
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| status | string | 否 | 过滤状态:running / completed / failed |
| mode | string | 否 | 过滤模式:call / agent |
| limit | int | 否 | 返回数量(默认 50,最大 100)|
响应数据: ```typescript interface TraceListResponse { traces: Array<{ trace_id: string; mode: string; // "agent" | "call" task: string; // 任务描述,用于顶部标题显示 status: string; // "running" | "completed" | "failed" total_messages: number; total_tokens: number; total_cost: number; current_goal_id: string; created_at: string; }>; total: number; } ```
html使用:
trace.task2.1.2 获取 GoalTree 数据(渲染流程节点)
接口: GET /api/traces/{trace_id}
用途: 获取完整的 GoalTree 数据,根据 goal_tree.goals 渲染流程节点
响应数据: ```typescript interface TraceDetailResponse { trace_id: string; mode: string; task: string; status: string; total_messages: number; total_tokens: number; total_cost: number; created_at: string; completed_at: string | null;
// GoalTree 数据 - 用于渲染流程节点 goal_tree: { mission: string; current_id: string | null; goals: Array<{ id: string; // Goal 唯一 ID parent_id: string | null; // 父节点 ID(用于构建层级) branch_id: string | null; // 所属分支(null=主线) type: string; // "normal" | "explore_start" | "explore_merge" description: string; // 目标描述 reason: string; // 创建理由 status: string; // "pending" | "in_progress" | "completed" | "abandoned" summary: string | null; // 完成时的总结
// 统计数据(用于边的显示)
self_stats: {
message_count: number;
total_tokens: number;
total_cost: number;
preview: string | null; // 工具调用摘要,如 "read → edit × 2"
};
cumulative_stats: {
message_count: number;
total_tokens: number;
total_cost: number;
preview: string | null;
};
// 分支相关(仅 explore 类型)
branch_ids?: string[]; // explore_start 关联的分支
explore_start_id?: string; // explore_merge 关联的 explore_start
merge_summary?: string;
selected_branch?: string;
}>;
};
// 分支元数据(用于分支节点显示) branches: Record; } ```
html使用:
goal_tree.goals 数组,每个 Goal 对象渲染为一个流程节点parent_id 构建父子关系type 字段区分普通节点、分支开始、分支汇合status 字段设置节点样式(进行中/已完成/待处理)self_stats 或 cumulative_stats 显示边上的统计信息接口: GET /api/traces/{trace_id}/messages?goal_id={goal_id}
用途: 获取指定 Goal 关联的所有 Messages,用于渲染流程节点之间的边的详细执行内容
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| goal_id | string | 否 | 过滤指定 Goal 的 Messages |
| branch_id | string | 否 | 过滤指定分支的所有 Messages |
响应数据: ```typescript interface MessagesResponse { messages: Array<{ message_id: string; role: string; // "assistant" | "tool" sequence: number; // 全局顺序 goal_id: string; // 关联的 Goal ID branch_id: string | null;
// assistant 消息
description?: string;
content?: {
text: string;
tool_calls?: Array<{
id: string;
name: string; // 工具名称
arguments: any;
}>;
};
// tool 消息
tool_call_id?: string;
// 统计信息
tokens: number | null;
cost: number | null;
created_at: string;
}>; total: number; } ```
html使用:
接口: GET /api/traces/{trace_id}/branches/{branch_id}
用途: 展开分支时,按需加载分支内的详细 GoalTree
响应数据: ```typescript interface BranchDetailResponse { id: string; explore_start_id: string; description: string; status: string; summary: string | null; goal_tree: { mission: string; currentid: string | null; goals: Array<{/ 同 5.1.2 的 Goal 结构 _/}>; }; cumulative_stats: { message_count: number; total_tokens: number; total_cost: number; preview: string | null; }; } ```
连接地址: ws://43.106.118.91:8000/api/traces/{trace_id}/watch?since_event_id=0
查询参数:
| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| since_event_id | int | 0 | 从哪个事件 ID 开始。0 = 补发所有历史 |
事件类型:
连接后推送完整 GoalTree,前端据此初始化流程图。
```typescript interface ConnectedEvent { event: 'connected'; trace_id: string; current_event_id: number; goaltree: {/ 同 5.1.2 _/}; } ```
```typescript interface GoalAddedEvent { event: 'goal_added'; eventid: number; goal: {/ Goal 对象 _/}; parent_id: string | null; } ```
前端处理: 插入新节点,重新生成 DAG
```typescript interface GoalUpdatedEvent { event: 'goal_updated'; event_id: number; goal_id: string; updates: { status?: string; summary?: string; }; affected_goals: Array<{ goal_id: string; status?: string; summary?: string; cumulativestats?: {/ 统计数据 _/}; }>; } ```
前端处理: 更新节点状态和统计数据,更新边的显示
```typescript interface MessageAddedEvent { event: 'message_added'; eventid: number; message: {/ Message 对象 _/}; affected_goals: Array<{ goal_id: string; selfstats?: {/ 统计数据 _/}; cumulativestats?: {/ 统计数据 _/}; }>; affected_branches?: Array<{ branch_id: string; explore_start_id: string; cumulativestats: {/ 统计数据 _/}; }>; } ```
前端处理: 更新相关节点和边的统计数据
```typescript interface TraceCompletedEvent { event: 'trace_completed'; event_id: number; trace_id: string; total_messages: number; total_tokens: number; total_cost: number; } ```
前端处理: 标记任务完成,关闭 WebSocket
```typescript interface BranchStartedEvent { event: 'branch_started'; event_id: number; explore_startid: string; branch: {/ Branch 对象 _/}; } ```
```typescript interface BranchCompletedEvent { event: 'branch_completed'; event_id: number; explore_start_id: string; branch_id: string; summary: string; cumulativestats: {/ 统计数据 _/}; last_message: any; } ```
初始化流程:
GET /api/traces?status=running&limit=20 获取 trace 列表trace.taskGET /api/traces/{trace_id} 获取 GoalTree 数据goal_tree.goals 渲染流程节点ws://43.106.118.91:8000/api/traces/{trace_id}/watch 进行实时更新节点交互流程:
边交互流程:
GET /api/traces/{trace_id}/messages?goal_id={goal_id} 获取该 Goal 的 Messages三、交互细节
3.1 节点点击交互流程
3.2 边点击交互流程