Skip to content
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 conversations CRUDS API #5775

Merged
merged 75 commits into from
Jan 2, 2025
Merged

Feat conversations CRUDS API #5775

merged 75 commits into from
Jan 2, 2025

Conversation

tofarr
Copy link
Collaborator

@tofarr tofarr commented Dec 23, 2024

End-user friendly description of the problem this fixes or functionality that this introduces
Backend functionality for searching and paginating through conversations.

  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

Give a summary of what the PR does, explaining any non-trivial design decisions

New Components

  • Added ConversationInfo data model to represent conversation metadata
  • Added ConversationResultSet for paginated search results
  • Added ConversationStatus enum to track conversation states
  • Added search_utils.py with pagination utilities (offset/page_id conversion)

Modified Components

  • Updated conversation store to support search functionality
  • Enhanced middleware and routes to handle conversation search requests

Testing

  • Added unit tests for conversation search functionality
  • Added unit tests for search utilities

Implementation Details

  • Uses base64-encoded offset-based pagination
  • Supports filtering conversations by status and repository
  • Includes conversation metadata like title, last update time, and status

This PR provides the backend foundation for the conversation search feature, enabling users to efficiently browse and find their past conversations.


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:5b56f8c-nikolaik   --name openhands-app-5b56f8c   docker.all-hands.dev/all-hands-ai/openhands:5b56f8c

@@ -121,7 +121,7 @@ def _should_attach(self, request) -> bool:
if request.url.path.startswith('/api/conversation'):
# FIXME: we should be able to use path_params
path_parts = request.url.path.split('/')
if len(path_parts) > 3:
if len(path_parts) > 4:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change? /api/conversations/foo should have 4 parts

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see--we don't need to attach the runtime for these.

Right now I think that's our main auth mechanism, so probably better to leave this as 3? Worth refactoring in the future though

try:
title = conversation.title
if not title:
title = f'Conversation {conversation.conversation_id}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe conversation.conversation_id[:5] as a shortname?

@@ -0,0 +1,57 @@
from datetime import datetime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this utils folder is getting out of hand 😓 probably another thing to refactor in the future

Copy link
Collaborator

@rbren rbren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great!

Copy link
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice feature! I just have a doubt, a simple thing about architecture here:
the event stream and its management is self-contained -ish, enough that it has always been possible, I think, to load in cli the event streams created with an UI.

Give or take that they have ugly names, 😅 but otherwise, there are no major reasons not to work. They're just events.

With the caveat that I haven't looked much in the past couple of weeks, this appears to be the case after the introduction of conversations too. At least I think it works with the default convo.

Is there a reason why managing it from cli wouldn't continue to work, with sessions or with convos alike?
In this PR the server code is not really minimally separated from backend.

Can we keep it possible to add in cli? It doesn't have to be implemented in this PR, of course, but I do think it would be nice to not go against it either: for example, the inverse dependencies mean that one cannot use the methods in utils, even though they're in utils.

All we'd need here, is to keep separate the code that works with the stream and file store, from code that works with the session_manager global or sio etc. What do you think?


from openhands.core.logger import openhands_logger as logger
from openhands.server.routes.settings import ConversationStoreImpl
from openhands.server.shared import config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the functions that import from server in a server module, like its shared.py? IMHO the new callback is only useful for server, right?

@tofarr
Copy link
Collaborator Author

tofarr commented Jan 2, 2025

@enyst - At the moment, this PR leverages the existing functionality where conversation metadata is stored when a conversation is started in web . I just did a quick check, and the same metadata is not being stored for conversations started in CLI mode - I think we should create a second PR to remedy this issue (The first line below was created via CLI, the others via Web)
image

@enyst
Copy link
Collaborator

enyst commented Jan 2, 2025

That's okay, we don't need to create metadata, sure. I just feel like this PR is heading in the opposite direction, when it adds more dependencies to server in the backend. That means we'd first need to untangle them, and then be able to access the file store / data / metadata.

Could we just move the new callback function, for example, if it depends on server, to the server somewhere? It feels like the work with the stream/convo in the backend shouldn't depend on it?

@enyst
Copy link
Collaborator

enyst commented Jan 2, 2025

Ah, too bad it comes at the price of not exposing the get info function. It didn't seem to depend on session_manager anymore, so maybe we can actually reuse it sometime. It doesn't have to be in this PR though. Thank you, this feature will be super useful!

@tofarr tofarr enabled auto-merge (squash) January 2, 2025 21:19
@tofarr tofarr disabled auto-merge January 2, 2025 21:33
@tofarr tofarr enabled auto-merge (squash) January 2, 2025 21:34
@tofarr tofarr disabled auto-merge January 2, 2025 21:36
@tofarr tofarr merged commit 50f821f into main Jan 2, 2025
13 checks passed
@tofarr tofarr deleted the feat-search-conversations branch January 2, 2025 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants