88
99app = Flask (__name__ )
1010
11- # 全局变量存储分析器实例
11+ # Global variable to store analyzer instance
1212analyzer = None
1313
1414
1515@app .route ("/" )
1616def index ():
17- """主页面 """
17+ """Main page """
1818 return render_template ("index.html" )
1919
2020
2121@app .route ("/api/list_files" , methods = ["GET" ])
2222def list_files ():
23- """列出可用的JSON文件 """
23+ """List available JSON files """
2424 try :
2525 directory = request .args .get ("directory" , "" )
2626
2727 if not directory :
28- # 默认行为:检查上级目录
28+ # Default behavior: check parent directory
2929 directory = os .path .abspath (".." )
3030
31- # 扩展路径(处理~等符号)
31+ # Expand path (handle ~ and other symbols)
3232 directory = os .path .expanduser (directory )
3333
34- # 转换为绝对路径
34+ # Convert to absolute path
3535 directory = os .path .abspath (directory )
3636
3737 if not os .path .exists (directory ):
38- return jsonify ({"error" : f"目录不存在 : { directory } " }), 404
38+ return jsonify ({"error" : f"Directory does not exist : { directory } " }), 404
3939
4040 if not os .path .isdir (directory ):
41- return jsonify ({"error" : f"路径不是目录 : { directory } " }), 400
41+ return jsonify ({"error" : f"Path is not a directory : { directory } " }), 400
4242
4343 try :
4444 json_files = []
4545 for file in os .listdir (directory ):
4646 if file .endswith (".json" ):
4747 file_path = os .path .join (directory , file )
4848 try :
49- # 获取文件大小和修改时间
49+ # Get file size and modification time
5050 stat = os .stat (file_path )
5151 json_files .append (
5252 {
@@ -61,61 +61,63 @@ def list_files():
6161 {"name" : file , "path" : file_path , "size" : 0 , "modified" : 0 }
6262 )
6363
64- # 按文件名排序
64+ # Sort by filename
6565 json_files .sort (key = lambda x : x ["name" ])
6666
6767 return jsonify (
6868 {
6969 "files" : json_files ,
7070 "directory" : directory ,
71- "message" : f'在目录 " { directory } " 中找到 { len (json_files )} 个JSON文件 ' ,
71+ "message" : f'Found { len (json_files )} JSON files in directory " { directory } " ' ,
7272 }
7373 )
7474 except PermissionError :
75- return jsonify ({"error" : f"没有权限访问目录: { directory } " }), 403
75+ return jsonify (
76+ {"error" : f"No permission to access directory: { directory } " }
77+ ), 403
7678 except Exception as e :
77- return jsonify ({"error" : f"读取目录失败 : { str (e )} " }), 500
79+ return jsonify ({"error" : f"Failed to read directory : { str (e )} " }), 500
7880
7981 except Exception as e :
8082 return jsonify ({"error" : str (e )}), 500
8183
8284
8385@app .route ("/api/load_trace" , methods = ["POST" ])
8486def load_trace ():
85- """加载trace文件 """
87+ """Load trace file """
8688 global analyzer
8789
8890 data = request .get_json ()
8991 file_path = data .get ("file_path" )
9092
9193 if not file_path :
92- return jsonify ({"error" : "请提供文件路径 " }), 400
94+ return jsonify ({"error" : "Please provide file path " }), 400
9395
94- # 如果是相对路径,转换为绝对路径
96+ # If it's a relative path, convert to absolute path
9597 if not os .path .isabs (file_path ):
9698 file_path = os .path .abspath (file_path )
9799
98100 if not os .path .exists (file_path ):
99- return jsonify ({"error" : f"文件不存在 : { file_path } " }), 404
101+ return jsonify ({"error" : f"File does not exist : { file_path } " }), 404
100102
101103 try :
102104 analyzer = TraceAnalyzer (file_path )
103105 return jsonify (
104106 {
105- "message" : "文件加载成功 " ,
107+ "message" : "File loaded successfully " ,
106108 "file_path" : file_path ,
107109 "file_name" : os .path .basename (file_path ),
108110 }
109111 )
110112 except Exception as e :
111- return jsonify ({"error" : f"加载文件失败 : { str (e )} " }), 500
113+ return jsonify ({"error" : f"Failed to load file : { str (e )} " }), 500
112114
113115
114116@app .route ("/api/basic_info" )
115117def get_basic_info ():
116- """获取基本信息 """
118+ """Get basic information """
117119 if not analyzer :
118- return jsonify ({"error" : "请先加载trace文件 " }), 400
120+ return jsonify ({"error" : "Please load trace file first " }), 400
119121
120122 try :
121123 return jsonify (analyzer .get_basic_info ())
@@ -125,9 +127,9 @@ def get_basic_info():
125127
126128@app .route ("/api/performance_summary" )
127129def get_performance_summary ():
128- """获取性能摘要 """
130+ """Get performance summary """
129131 if not analyzer :
130- return jsonify ({"error" : "请先加载trace文件 " }), 400
132+ return jsonify ({"error" : "Please load trace file first " }), 400
131133
132134 try :
133135 return jsonify (analyzer .get_performance_summary ())
@@ -137,9 +139,9 @@ def get_performance_summary():
137139
138140@app .route ("/api/execution_flow" )
139141def get_execution_flow ():
140- """获取执行流程 """
142+ """Get execution flow """
141143 if not analyzer :
142- return jsonify ({"error" : "请先加载trace文件 " }), 400
144+ return jsonify ({"error" : "Please load trace file first " }), 400
143145
144146 try :
145147 return jsonify (analyzer .analyze_conversation_flow ())
@@ -149,9 +151,9 @@ def get_execution_flow():
149151
150152@app .route ("/api/execution_summary" )
151153def get_execution_summary ():
152- """获取执行摘要 """
154+ """Get execution summary """
153155 if not analyzer :
154- return jsonify ({"error" : "请先加载trace文件 " }), 400
156+ return jsonify ({"error" : "Please load trace file first " }), 400
155157
156158 try :
157159 return jsonify (analyzer .get_execution_summary ())
@@ -161,9 +163,9 @@ def get_execution_summary():
161163
162164@app .route ("/api/spans_summary" )
163165def get_spans_summary ():
164- """获取spans摘要 """
166+ """Get spans summary """
165167 if not analyzer :
166- return jsonify ({"error" : "请先加载trace文件 " }), 400
168+ return jsonify ({"error" : "Please load trace file first " }), 400
167169
168170 try :
169171 return jsonify (analyzer .get_spans_summary ())
@@ -173,9 +175,9 @@ def get_spans_summary():
173175
174176@app .route ("/api/step_logs_summary" )
175177def get_step_logs_summary ():
176- """获取步骤日志摘要 """
178+ """Get step logs summary """
177179 if not analyzer :
178- return jsonify ({"error" : "请先加载trace文件 " }), 400
180+ return jsonify ({"error" : "Please load trace file first " }), 400
179181
180182 try :
181183 return jsonify (analyzer .get_step_logs_summary ())
@@ -185,15 +187,15 @@ def get_step_logs_summary():
185187
186188@app .route ("/api/debug/raw_messages" )
187189def get_raw_messages ():
188- """获取原始消息数据用于调试 """
190+ """Get raw message data for debugging """
189191 if not analyzer :
190- return jsonify ({"error" : "请先加载trace文件 " }), 400
192+ return jsonify ({"error" : "Please load trace file first " }), 400
191193
192194 try :
193195 main_history = analyzer .get_main_agent_history ()
194196 browser_sessions = analyzer .get_browser_agent_sessions ()
195197
196- # 获取消息结构概览
198+ # Get message structure overview
197199 main_messages = analyzer .get_main_agent_messages ()
198200 message_structure = []
199201
@@ -220,7 +222,7 @@ def get_raw_messages():
220222 "raw_main_history" : main_history ,
221223 "raw_browser_sessions" : {
222224 k : v for k , v in list (browser_sessions .items ())[:2 ]
223- }, # 只显示前两个会话
225+ }, # Only show first two sessions
224226 }
225227 )
226228 except Exception as e :
0 commit comments