aps-agent/server/agent_core/session_focus.py

32 lines
916 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================================
# 会话焦点(moduleId: core-session-focus, 可重生 ✅)
# 记住「刚查过的订单」等指代,支持「把这个订单排产」。
# ============================================================
from __future__ import annotations
import threading
from typing import Any
_lock = threading.Lock()
_focus: dict[str, dict[str, Any]] = {}
def set_focus(session_id: str, **kwargs: Any) -> None:
if not session_id:
return
with _lock:
cur = _focus.setdefault(session_id, {})
for k, v in kwargs.items():
if v is not None and v != "":
cur[k] = v
def get_focus(session_id: str) -> dict[str, Any]:
with _lock:
return dict(_focus.get(session_id) or {})
def get_last_order_no(session_id: str) -> str | None:
f = get_focus(session_id)
return f.get("orderNo") or None