Skip to content

Commit d9d948d

Browse files
authored
Merge pull request #22 from All-Hands-AI/fix/trajectory-viewer-crashes-and-routing
Fix trajectory visualizer bugs: null checking and routing
2 parents 106ce82 + 49a90e1 commit d9d948d

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

src/App.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,21 +295,20 @@ const App: React.FC<{ router?: boolean }> = ({ router = true }) => {
295295
// Check if it's an array (OpenHands trajectory format)
296296
if (Array.isArray(data)) {
297297
// Check if it has OpenHands specific fields
298-
if (data.length > 0 &&
299-
(('action' in data[0] && 'source' in data[0]) ||
298+
if (data.length > 0 &&
299+
(('action' in data[0] && 'source' in data[0]) ||
300300
('observation' in data[0] && 'source' in data[0]))) {
301-
console.log('Detected OpenHands trajectory format');
302-
303-
// Convert to JSONL format for the JsonlViewer
304-
const jsonlContent = JSON.stringify({ history: data });
301+
console.log('Detected OpenHands trajectory format - using trajectory viewer');
302+
303+
// Return as trajectory data for the trajectory viewer
305304
return {
306305
content: {
307-
jsonlContent,
308-
fileType: 'jsonl'
306+
trajectoryData: data,
307+
fileType: 'trajectory'
309308
}
310309
};
311310
}
312-
311+
313312
// For other array formats
314313
return {
315314
content: {
@@ -334,14 +333,13 @@ const App: React.FC<{ router?: boolean }> = ({ router = true }) => {
334333

335334
// Check if it has history array (trajectory-visualizer format)
336335
if (data.history && Array.isArray(data.history)) {
337-
console.log('Detected history array format');
338-
339-
// Already in the right format, just convert to JSONL
340-
const jsonlContent = JSON.stringify(data);
336+
console.log('Detected history array format - using trajectory viewer');
337+
338+
// Return the history array for the trajectory viewer
341339
return {
342340
content: {
343-
jsonlContent,
344-
fileType: 'jsonl'
341+
trajectoryData: data.history,
342+
fileType: 'trajectory'
345343
}
346344
};
347345
}

src/components/RunDetails.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import RunDetailsSkeleton from './loading/RunDetailsSkeleton';
55
import ArtifactDetails from './artifacts/ArtifactDetails';
66
import RunHeader from './header/RunHeader';
77
import JsonlViewer from '../components/jsonl-viewer/JsonlViewer';
8+
import TrajectoryList from './share/trajectory-list';
89

910
interface RunDetailsProps {
1011
owner: string;
@@ -107,6 +108,17 @@ const RunDetails: React.FC<RunDetailsProps> = ({ owner, repo, run, initialConten
107108
);
108109
}
109110

111+
// Check if we're dealing with trajectory data
112+
if (artifactContent?.content?.fileType === 'trajectory' && artifactContent?.content?.trajectoryData) {
113+
console.log('Rendering Trajectory viewer with', artifactContent.content.trajectoryData.length, 'items');
114+
115+
return (
116+
<div className="flex flex-col h-full">
117+
<TrajectoryList trajectory={artifactContent.content.trajectoryData} />
118+
</div>
119+
);
120+
}
121+
110122
return (
111123
<div className="flex flex-col h-full overflow-hidden">
112124
{/* Main Content */}

src/components/share/trajectory-list-items/agent-state-change.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export const AgentStateChangeComponent: React.FC<AgentStateChangeProps> = ({ sta
1111
let stateText = '';
1212
let thought = '';
1313

14-
if ('args' in state) {
15-
stateText = state.args.agent_state;
16-
thought = state.args.thought;
17-
} else if ('extras' in state) {
18-
stateText = state.extras.agent_state;
14+
if ('args' in state && state.args) {
15+
stateText = state.args.agent_state || '';
16+
thought = state.args.thought || '';
17+
} else if ('extras' in state && state.extras) {
18+
stateText = state.extras.agent_state || '';
1919
}
2020

2121
return (

src/components/share/trajectory-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const TrajectoryList: React.FC<TrajectoryListProps> = ({ trajectory }) =>
5959
return (
6060
<div className="flex flex-col h-full">
6161
{/* Trajectory Items List */}
62-
<div className="flex-1 border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 shadow-sm overflow-hidden">
62+
<div className="flex flex-col h-full border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-800 shadow-sm">
6363
<div className="px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center">
6464
<h3 className="text-lg font-medium text-gray-900 dark:text-white">
6565
Trajectory Items ({filteredTrajectory.length} items)

src/components/upload/UploadTrajectory.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ export const UploadTrajectory: React.FC<UploadTrajectoryProps> = ({
1818
// Check if it's an array (OpenHands trajectory format)
1919
if (Array.isArray(content)) {
2020
// Check if it has OpenHands specific fields
21-
if (content.length > 0 &&
22-
(('action' in content[0] && 'source' in content[0]) ||
21+
if (content.length > 0 &&
22+
(('action' in content[0] && 'source' in content[0]) ||
2323
('observation' in content[0] && 'source' in content[0]))) {
24-
console.log('Detected OpenHands trajectory format');
25-
26-
// Convert to JSONL format for the JsonlViewer
27-
const jsonlContent = JSON.stringify({ history: content });
28-
return {
29-
jsonlContent,
30-
fileType: 'jsonl'
31-
};
24+
console.log('Detected OpenHands trajectory format - using trajectory viewer');
25+
26+
// Return the content directly for the trajectory viewer
27+
return content;
3228
}
3329
return content;
3430
}
@@ -43,14 +39,10 @@ export const UploadTrajectory: React.FC<UploadTrajectoryProps> = ({
4339

4440
// Check if it has history array (trajectory-visualizer format)
4541
if (content.history && Array.isArray(content.history)) {
46-
console.log('Detected history array format');
47-
48-
// Already in the right format, just convert to JSONL
49-
const jsonlContent = JSON.stringify(content);
50-
return {
51-
jsonlContent,
52-
fileType: 'jsonl'
53-
};
42+
console.log('Detected history array format - using trajectory viewer');
43+
44+
// Return the history array for the trajectory viewer
45+
return content.history;
5446
}
5547

5648
// If it's not in a recognized format, return as is and let the converter handle it

0 commit comments

Comments
 (0)