oclaw/runtime/orchestration/session_mapping.py
oliver 4a23b715a2 重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。

Made-with: Cursor
2026-04-25 01:24:23 +08:00

41 lines
1.1 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from oclaw.platform.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"]