fix: correct 9 inaccurate type hints

- get_password_hash() -> str | None (not bool, returns hash or None)
- parse_cookie() -> str | None (not None, returns cookie value)
- Session.__init__ session_id: str (not int, uuid hex)
- Session.__init__ project_id: str (not int)
- Session.__init__ **kwargs (remove incorrect dict annotation)
- Session.load() remove -> None (returns Session | None)
- import_cli_session session_id: str (not int)
- sync_session_start session_id: str (not int)
- sync_session_usage session_id: str (not int)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nathan Esquenazi
2026-04-04 23:54:58 -07:00
parent 4d333acbbc
commit 74fcd2e0ab
3 changed files with 9 additions and 9 deletions

View File

@@ -57,7 +57,7 @@ def _hash_password(password):
return dk.hex() return dk.hex()
def get_password_hash() -> bool: def get_password_hash() -> str | None:
"""Return the active password hash, or None if auth is disabled. """Return the active password hash, or None if auth is disabled.
Priority: env var > settings.json.""" Priority: env var > settings.json."""
env_pw = os.getenv('HERMES_WEBUI_PASSWORD', '').strip() env_pw = os.getenv('HERMES_WEBUI_PASSWORD', '').strip()
@@ -110,7 +110,7 @@ def invalidate_session(cookie_value) -> None:
_sessions.pop(token, None) _sessions.pop(token, None)
def parse_cookie(handler) -> None: def parse_cookie(handler) -> str | None:
"""Extract the auth cookie from the request headers.""" """Extract the auth cookie from the request headers."""
cookie_header = handler.headers.get('Cookie', '') cookie_header = handler.headers.get('Cookie', '')
if not cookie_header: if not cookie_header:

View File

@@ -34,13 +34,13 @@ def _write_session_index():
class Session: class Session:
def __init__(self, session_id: int=None, title: str='Untitled', def __init__(self, session_id: str=None, title: str='Untitled',
workspace=str(DEFAULT_WORKSPACE), model=DEFAULT_MODEL, workspace=str(DEFAULT_WORKSPACE), model=DEFAULT_MODEL,
messages=None, created_at=None, updated_at=None, messages=None, created_at=None, updated_at=None,
tool_calls=None, pinned: bool=False, archived: bool=False, tool_calls=None, pinned: bool=False, archived: bool=False,
project_id: int=None, profile=None, project_id: str=None, profile=None,
input_tokens: int=0, output_tokens: int=0, estimated_cost=None, input_tokens: int=0, output_tokens: int=0, estimated_cost=None,
**kwargs: dict): **kwargs):
self.session_id = session_id or uuid.uuid4().hex[:12] self.session_id = session_id or uuid.uuid4().hex[:12]
self.title = title self.title = title
self.workspace = str(Path(workspace).expanduser().resolve()) self.workspace = str(Path(workspace).expanduser().resolve())
@@ -70,7 +70,7 @@ class Session:
_write_session_index() _write_session_index()
@classmethod @classmethod
def load(cls, sid) -> None: def load(cls, sid):
p = SESSION_DIR / f'{sid}.json' p = SESSION_DIR / f'{sid}.json'
if not p.exists(): if not p.exists():
return None return None
@@ -194,7 +194,7 @@ def save_projects(projects) -> None:
PROJECTS_FILE.write_text(json.dumps(projects, ensure_ascii=False, indent=2), encoding='utf-8') PROJECTS_FILE.write_text(json.dumps(projects, ensure_ascii=False, indent=2), encoding='utf-8')
def import_cli_session(session_id: int, title: str, messages, model: str='unknown', profile=None): def import_cli_session(session_id: str, title: str, messages, model: str='unknown', profile=None):
"""Create a new WebUI session populated with CLI messages. """Create a new WebUI session populated with CLI messages.
Returns the Session object. Returns the Session object.
""" """

View File

@@ -43,7 +43,7 @@ def _get_state_db():
return None return None
def sync_session_start(session_id: int, model=None) -> None: def sync_session_start(session_id: str, model=None) -> None:
"""Register a WebUI session in state.db (idempotent). """Register a WebUI session in state.db (idempotent).
Called when a session's first message is sent. Called when a session's first message is sent.
""" """
@@ -65,7 +65,7 @@ def sync_session_start(session_id: int, model=None) -> None:
pass pass
def sync_session_usage(session_id: int, input_tokens: int=0, output_tokens: int=0, def sync_session_usage(session_id: str, input_tokens: int=0, output_tokens: int=0,
estimated_cost=None, model=None, title: str=None) -> None: estimated_cost=None, model=None, title: str=None) -> None:
"""Update token usage and title for a WebUI session in state.db. """Update token usage and title for a WebUI session in state.db.
Called after each turn completes. Uses absolute=True to set totals Called after each turn completes. Uses absolute=True to set totals