-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) Add button to export trajectory on chat panel #6378
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d9a1bae
chore(deps): Revert vite upgrade
li-boxuan f78ae99
Merge branch 'boxuanli/revert-vite-upgrade' into boxuanli/dump-traj-json
li-boxuan 8926636
Add export button
li-boxuan 09ed0f6
Merge remote-tracking branch 'upstream/main' into boxuanli/dump-traj-…
li-boxuan fc687ce
Complete E2E functionality
li-boxuan 71d146a
Code cleanup
li-boxuan 5d4b927
Fix linting
li-boxuan 79f9df8
Clean up
li-boxuan 587859d
Use event_to_trajectory which is less verbose
li-boxuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
frontend/src/components/features/export/export-actions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import ExportIcon from "#/icons/export.svg?react"; | ||
import { ExportActionButton } from "#/components/shared/buttons/export-action-button"; | ||
|
||
interface ExportActionsProps { | ||
onExportTrajectory: () => void; | ||
} | ||
|
||
export function ExportActions({ onExportTrajectory }: ExportActionsProps) { | ||
return ( | ||
<div data-testid="export-actions" className="flex gap-1"> | ||
<ExportActionButton | ||
onClick={onExportTrajectory} | ||
icon={<ExportIcon width={15} height={15} />} | ||
/> | ||
</div> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
frontend/src/components/shared/buttons/export-action-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
interface ExportActionButtonProps { | ||
onClick: () => void; | ||
icon: React.ReactNode; | ||
} | ||
|
||
export function ExportActionButton({ onClick, icon }: ExportActionButtonProps) { | ||
return ( | ||
<button | ||
type="button" | ||
onClick={onClick} | ||
className="button-base p-1 hover:bg-neutral-500" | ||
title="Export trajectory" | ||
> | ||
{icon} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import OpenHands from "#/api/open-hands"; | ||
|
||
export const useGetTrajectory = () => | ||
useMutation({ | ||
mutationFn: (cid: string) => OpenHands.getTrajectory(cid), | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from fastapi import APIRouter, Request | ||
from fastapi.responses import JSONResponse | ||
|
||
from openhands.core.logger import openhands_logger as logger | ||
from openhands.events.serialization import event_to_trajectory | ||
from openhands.events.stream import AsyncEventStreamWrapper | ||
|
||
app = APIRouter(prefix='/api/conversations/{conversation_id}') | ||
|
||
|
||
@app.get('/trajectory') | ||
async def get_trajectory(request: Request): | ||
"""Get trajectory. | ||
|
||
This function retrieves the current trajectory and returns it. | ||
|
||
Args: | ||
request (Request): The incoming request object. | ||
|
||
Returns: | ||
JSONResponse: A JSON response containing the trajectory as a list of | ||
events. | ||
""" | ||
try: | ||
async_stream = AsyncEventStreamWrapper( | ||
request.state.conversation.event_stream, filter_hidden=True | ||
) | ||
trajectory = [] | ||
async for event in async_stream: | ||
trajectory.append(event_to_trajectory(event)) | ||
return JSONResponse(status_code=200, content={'trajectory': trajectory}) | ||
except Exception as e: | ||
logger.error(f'Error getting trajectory: {e}', exc_info=True) | ||
return JSONResponse( | ||
status_code=500, | ||
content={ | ||
'trajectory': None, | ||
'error': f'Error getting trajectory: {e}', | ||
}, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to comment on a closed PR, I was just thinking:
hidden=True
will probably hides commands like clone the selected repo, the one performed automatically when the user selects it from the home page. Is that intended?Cc: @li-boxuan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I don't think that's intended. Actually I wasn't even aware of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't try it, I was thinking what does it take to restore the runtime environment, and with UI, the agent history is replayed over a workspace which... starts with a repo (if the user chose a repo). The initial command to clone the repo is 'hidden', as in hidden from the agent, so it's not in history. And it's not in traj.
So if I have a traj, I want to replay, I need to start with a repo that was cloned the same way 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that sounds legitimate! Created an issue to track this: #6749 will get to this once I got a chance