oclaw/runtime/orchestration/session_mapping.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

41 lines
1.1 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from svc.persistence.sqlite_store import SqliteStore
@dataclass(frozen=True)
class SessionMapResult:
session_id: str
scope: str # "group" | "dm"
def get_or_create_session_for_wecom(
store: SqliteStore,
*,
tenant_id: str,
user_id: str,
external_user_id: str,
external_chat_id: str,
is_group: bool,
) -> SessionMapResult:
"""Group: session per chat_id; DM: session per user_id.
We store mapping under (tenant, channel, external_chat_id, external_user_id) to keep it simple.
"""
scope = "group" if bool(is_group) else "dm"
# For DM, external_chat_id is often contact id; we still keep it as provided.
title = f"wecom:{scope}:{external_chat_id[:8]}"
sid = store.get_or_create_channel_session(
tenant_id=tenant_id,
channel="wecom",
external_chat_id=external_chat_id,
external_user_id=external_user_id,
session_title=title,
)
return SessionMapResult(session_id=sid, scope=scope)
__all__ = ["SessionMapResult", "get_or_create_session_for_wecom"]