mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Feat: User id should be a str (Because it will probably be a UUID) (#6251)
This commit is contained in:
parent
6b2e3f938f
commit
e21cbf67ee
@ -5,8 +5,8 @@ from jwt.exceptions import InvalidTokenError
|
||||
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:
|
||||
|
||||
@ -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(
|
||||
@ -235,7 +235,7 @@ def _create_conversation_update_callback(
|
||||
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)
|
||||
|
||||
@ -204,7 +204,7 @@ class SessionManager:
|
||||
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))
|
||||
@ -343,7 +343,7 @@ class SessionManager:
|
||||
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
|
||||
|
||||
@ -37,7 +37,7 @@ class Session:
|
||||
loop: asyncio.AbstractEventLoop
|
||||
config: AppConfig
|
||||
file_store: FileStore
|
||||
user_id: int | None
|
||||
user_id: str | None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -45,7 +45,7 @@ class Session:
|
||||
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
|
||||
|
||||
@ -41,6 +41,6 @@ class ConversationStore(ABC):
|
||||
@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"""
|
||||
|
||||
@ -92,7 +92,7 @@ class FileConversationStore(ConversationStore):
|
||||
|
||||
@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)
|
||||
|
||||
@ -5,7 +5,7 @@ from datetime import datetime, timezone
|
||||
@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
|
||||
|
||||
@ -31,7 +31,7 @@ class FileSettingsStore(SettingsStore):
|
||||
|
||||
@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)
|
||||
|
||||
@ -22,6 +22,6 @@ class SettingsStore(ABC):
|
||||
@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"""
|
||||
|
||||
@ -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',
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user