ganesh-vilje commited on
Commit
a5c898f
·
1 Parent(s): 3fa92e6

feat: Add pipeline components metadata and fix sort orders

Browse files

- Added tools[], component_count, and components[] to pipelines_history
- Pipelines now load from S3 to extract component/tool details
- Pipelines sorted by most recent first (updated_at/created_at desc)
- GET /sessions now returns newest sessions first (sorted by last_activity)
- Each pipeline now shows: tools list, component count, full component details
- Implements requested pipeline metadata enhancement

Files changed (1) hide show
  1. api_routes_v2.py +43 -1
api_routes_v2.py CHANGED
@@ -884,6 +884,12 @@ async def get_all_sessions(
884
  "total_messages": len(session.get("conversation_history", [])),
885
  "pipeline_executions_count": len(session.get("pipeline_executions", []))
886
  })
 
 
 
 
 
 
887
 
888
  return {
889
  "sessions": sessions_with_stats,
@@ -930,6 +936,42 @@ async def get_session_history(
930
  formatted_history.append(msg_copy)
931
 
932
  s = session_manager.get_session(session_id) or {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
933
 
934
  # Return with session_id included
935
  return {
@@ -938,7 +980,7 @@ async def get_session_history(
938
  "count": len(formatted_history),
939
  "limit": limit,
940
  "chat_name": s.get("chat_name"), # CHANGE
941
- "pipelines_history": s.get("pipelines_history", []) # CHANGE
942
  }
943
 
944
  except Exception as e:
 
884
  "total_messages": len(session.get("conversation_history", [])),
885
  "pipeline_executions_count": len(session.get("pipeline_executions", []))
886
  })
887
+
888
+ # Sort by most recent activity first
889
+ sessions_with_stats.sort(
890
+ key=lambda s: s.get("last_activity") or s.get("created_at") or "",
891
+ reverse=True
892
+ )
893
 
894
  return {
895
  "sessions": sessions_with_stats,
 
936
  formatted_history.append(msg_copy)
937
 
938
  s = session_manager.get_session(session_id) or {}
939
+
940
+ # Enhanced pipelines_history with component metadata, sorted by most recent first
941
+ pipelines_hist = s.get("pipelines_history", [])
942
+ enhanced_pipelines = []
943
+ for pipeline_meta in pipelines_hist:
944
+ enhanced_pipe = pipeline_meta.copy()
945
+ # Load pipeline definition from S3 to get components/tools
946
+ pipeline_s3_key = pipeline_meta.get("pipeline_s3_key")
947
+ if pipeline_s3_key:
948
+ try:
949
+ resp = s3.get_object(Bucket=S3_BUCKET, Key=pipeline_s3_key)
950
+ pipeline_def = json.loads(resp["Body"].read().decode("utf-8"))
951
+
952
+ # Extract tools/components
953
+ components = pipeline_def.get("components") or pipeline_def.get("pipeline_steps", [])
954
+ tools_list = [comp.get("tool_name", "unknown") for comp in components]
955
+
956
+ enhanced_pipe["tools"] = tools_list
957
+ enhanced_pipe["component_count"] = len(components)
958
+ enhanced_pipe["components"] = components # Full component details
959
+ except Exception as e:
960
+ print(f"Warning: Failed to load pipeline {pipeline_s3_key}: {e}")
961
+ enhanced_pipe["tools"] = []
962
+ enhanced_pipe["component_count"] = 0
963
+ enhanced_pipe["components"] = []
964
+ else:
965
+ enhanced_pipe["tools"] = []
966
+ enhanced_pipe["component_count"] = 0
967
+ enhanced_pipe["components"] = []
968
+ enhanced_pipelines.append(enhanced_pipe)
969
+
970
+ # Ensure sorting by most recent first (updated_at or created_at)
971
+ enhanced_pipelines.sort(
972
+ key=lambda p: p.get("updated_at") or p.get("created_at") or "",
973
+ reverse=True
974
+ )
975
 
976
  # Return with session_id included
977
  return {
 
980
  "count": len(formatted_history),
981
  "limit": limit,
982
  "chat_name": s.get("chat_name"), # CHANGE
983
+ "pipelines_history": enhanced_pipelines # CHANGE: enhanced with components
984
  }
985
 
986
  except Exception as e: