refactor: centralize cron session metadata keys

This commit is contained in:
chengyongru
2026-06-12 11:43:23 +08:00
parent 0e3a57b371
commit d9d481bc15
18 changed files with 116 additions and 62 deletions
+12
View File
@@ -0,0 +1,12 @@
"""Shared session key constants and helpers."""
from __future__ import annotations
UNIFIED_SESSION_KEY = "unified:default"
def session_key_for_channel(channel: str, chat_id: str, *, unified_session: bool = False) -> str:
"""Return the session key for a channel/chat pair."""
if unified_session:
return UNIFIED_SESSION_KEY
return f"{channel}:{chat_id}"
+2 -1
View File
@@ -14,6 +14,7 @@ from typing import Any
from loguru import logger
from nanobot.config.paths import get_legacy_sessions_dir
from nanobot.session.metadata import SESSION_ROUTING_METADATA_KEY
from nanobot.utils.helpers import (
ensure_dir,
estimate_message_tokens,
@@ -36,7 +37,7 @@ _FORK_VOLATILE_METADATA_KEYS = {
"pending_user_turn",
"runtime_checkpoint",
"thread_goal",
"_routing_context",
SESSION_ROUTING_METADATA_KEY,
"title",
"title_user_edited",
}
+3
View File
@@ -0,0 +1,3 @@
"""Shared session metadata keys."""
SESSION_ROUTING_METADATA_KEY = "_routing_context"
+1 -2
View File
@@ -7,8 +7,7 @@ from typing import Any, Mapping
from nanobot.bus.events import InboundMessage
from nanobot.cron.automation import is_automation_turn
from nanobot.session.manager import Session
SESSION_ROUTING_METADATA_KEY = "_routing_context"
from nanobot.session.metadata import SESSION_ROUTING_METADATA_KEY
_ROUTING_METADATA_KEYS = {
"chat_type",