Skip to content

Commit

Permalink
Feat: User id should be a str (Because it will probably be a UUID) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr authored Jan 14, 2025
1 parent 6b2e3f9 commit e21cbf6
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions openhands/server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from openhands.core.logger import openhands_logger as logger


def get_user_id(request: Request) -> int:
return getattr(request.state, 'github_user_id', 0)
def get_user_id(request: Request) -> str | None:
return getattr(request.state, 'github_user_id', None)


def get_sid_from_token(token: str, jwt_secret: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions openhands/server/routes/manage_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async def _get_conversation_info(


def _create_conversation_update_callback(
user_id: int, conversation_id: str
user_id: str | None, conversation_id: str
) -> Callable:
def callback(*args, **kwargs):
call_async_from_sync(
Expand All @@ -235,7 +235,7 @@ def callback(*args, **kwargs):
return callback


async def _update_timestamp_for_conversation(user_id: int, conversation_id: str):
async def _update_timestamp_for_conversation(user_id: str, conversation_id: str):
conversation_store = await ConversationStoreImpl.get_instance(config, user_id)
conversation = await conversation_store.get_metadata(conversation_id)
conversation.last_updated_at = datetime.now(timezone.utc)
Expand Down
4 changes: 2 additions & 2 deletions openhands/server/session/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async def attach_to_conversation(self, sid: str) -> Conversation | None:
return c

async def join_conversation(
self, sid: str, connection_id: str, settings: Settings, user_id: int | None
self, sid: str, connection_id: str, settings: Settings, user_id: str | None
):
logger.info(f'join_conversation:{sid}:{connection_id}')
await self.sio.enter_room(connection_id, ROOM_KEY.format(sid=sid))
Expand Down Expand Up @@ -343,7 +343,7 @@ async def _has_remote_connections(self, sid: str) -> bool:
self._has_remote_connections_flags.pop(sid, None)

async def maybe_start_agent_loop(
self, sid: str, settings: Settings, user_id: int | None
self, sid: str, settings: Settings, user_id: str | None
) -> EventStream:
logger.info(f'maybe_start_agent_loop:{sid}')
session: Session | None = None
Expand Down
4 changes: 2 additions & 2 deletions openhands/server/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class Session:
loop: asyncio.AbstractEventLoop
config: AppConfig
file_store: FileStore
user_id: int | None
user_id: str | None

def __init__(
self,
sid: str,
config: AppConfig,
file_store: FileStore,
sio: socketio.AsyncServer | None,
user_id: int | None = None,
user_id: str | None = None,
):
self.sid = sid
self.sio = sio
Expand Down
2 changes: 1 addition & 1 deletion openhands/storage/conversation/conversation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ async def search(
@classmethod
@abstractmethod
async def get_instance(
cls, config: AppConfig, user_id: int | None
cls, config: AppConfig, user_id: str | None
) -> ConversationStore:
"""Get a store for the user represented by the token given"""
2 changes: 1 addition & 1 deletion openhands/storage/conversation/file_conversation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_conversation_metadata_filename(self, conversation_id: str) -> str:

@classmethod
async def get_instance(
cls, config: AppConfig, user_id: int | None
cls, config: AppConfig, user_id: str | None
) -> FileConversationStore:
file_store = get_file_store(config.file_store, config.file_store_path)
return FileConversationStore(file_store)
Expand Down
2 changes: 1 addition & 1 deletion openhands/storage/data_models/conversation_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@dataclass
class ConversationMetadata:
conversation_id: str
github_user_id: int
github_user_id: str | None
selected_repository: str | None
title: str | None = None
last_updated_at: datetime | None = None
Expand Down
2 changes: 1 addition & 1 deletion openhands/storage/settings/file_settings_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def store(self, settings: Settings):

@classmethod
async def get_instance(
cls, config: AppConfig, user_id: int | None
cls, config: AppConfig, user_id: str | None
) -> FileSettingsStore:
file_store = get_file_store(config.file_store, config.file_store_path)
return FileSettingsStore(file_store)
2 changes: 1 addition & 1 deletion openhands/storage/settings/settings_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ async def store(self, settings: Settings):
@classmethod
@abstractmethod
async def get_instance(
cls, config: AppConfig, user_id: int | None
cls, config: AppConfig, user_id: str | None
) -> SettingsStore:
"""Get a store for the user represented by the token given"""
2 changes: 1 addition & 1 deletion tests/unit/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _patch_store():
'title': 'Some Conversation',
'selected_repository': 'foobar',
'conversation_id': 'some_conversation_id',
'github_user_id': 12345,
'github_user_id': '12345',
'created_at': '2025-01-01T00:00:00',
'last_updated_at': '2025-01-01T00:01:00',
}
Expand Down

0 comments on commit e21cbf6

Please sign in to comment.