-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Add button to export trajectory on chat panel (#6378)
- Loading branch information
Showing
11 changed files
with
184 additions
and
0 deletions.
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}', | ||
}, | ||
) |