Phase 5: Add Timeline View feature

- Add backend API endpoints for timeline data:
  - GET /api/v1/projects/{id}/timeline
  - GET /api/v1/projects/{id}/timeline/summary
  - GET /api/v1/entities/{id}/timeline

- Add database methods for timeline queries in db_manager.py

- Add frontend timeline view:
  - New sidebar button for timeline view
  - Timeline panel with date-grouped events
  - Visual distinction between mentions and relations
  - Entity filter dropdown
  - Statistics cards
  - Interactive event cards

- Update STATUS.md with Phase 5 progress
- Add view switching functions (switchView, switchKBTab)
- Add knowledge base loading functions
This commit is contained in:
OpenClaw Bot
2026-02-19 12:06:14 +08:00
parent 1f4fe5a33e
commit bc07aab4bb
5 changed files with 819 additions and 11 deletions

View File

@@ -1265,3 +1265,72 @@ async def search_entities(project_id: str, q: str):
db = get_db_manager()
entities = db.search_entities(project_id, q)
return [{"id": e.id, "name": e.name, "type": e.type, "definition": e.definition} for e in entities]
# ==================== Phase 5: 时间线视图 API ====================
@app.get("/api/v1/projects/{project_id}/timeline")
async def get_project_timeline(
project_id: str,
entity_id: str = None,
start_date: str = None,
end_date: str = None
):
"""获取项目时间线 - 按时间顺序的实体提及和关系事件"""
if not DB_AVAILABLE:
raise HTTPException(status_code=500, detail="Database not available")
db = get_db_manager()
project = db.get_project(project_id)
if not project:
raise HTTPException(status_code=404, detail="Project not found")
timeline = db.get_project_timeline(project_id, entity_id, start_date, end_date)
return {
"project_id": project_id,
"events": timeline,
"total_count": len(timeline)
}
@app.get("/api/v1/projects/{project_id}/timeline/summary")
async def get_timeline_summary(project_id: str):
"""获取项目时间线摘要统计"""
if not DB_AVAILABLE:
raise HTTPException(status_code=500, detail="Database not available")
db = get_db_manager()
project = db.get_project(project_id)
if not project:
raise HTTPException(status_code=404, detail="Project not found")
summary = db.get_entity_timeline_summary(project_id)
return {
"project_id": project_id,
"project_name": project.name,
**summary
}
@app.get("/api/v1/entities/{entity_id}/timeline")
async def get_entity_timeline(entity_id: str):
"""获取单个实体的时间线"""
if not DB_AVAILABLE:
raise HTTPException(status_code=500, detail="Database not available")
db = get_db_manager()
entity = db.get_entity(entity_id)
if not entity:
raise HTTPException(status_code=404, detail="Entity not found")
timeline = db.get_project_timeline(entity.project_id, entity_id)
return {
"entity_id": entity_id,
"entity_name": entity.name,
"entity_type": entity.type,
"events": timeline,
"total_count": len(timeline)
}