Files
wehub-resource-sync 1443d3fdf9
Ruff Format Check / Ruff Format & Lint (push) Failing after 7m39s
Deploy VitePress site to Pages / build (push) Failing after 9m11s
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:32:26 +08:00

28 lines
808 B
Python

from __future__ import annotations
from collections.abc import Mapping
def extract_thread_id(value: object, fallback: str | None = None) -> str | None:
"""从规范化事件结构中提取 thread_id。
只读取当前对象和一层稳定容器字段,避免递归扫描把未规范化的内部结构误判为路由依据。
"""
if not isinstance(value, Mapping):
return fallback
for source in (
value,
value.get("configurable"),
value.get("metadata"),
value.get("stream_event"),
value.get("meta"),
):
if not isinstance(source, Mapping):
continue
thread_id = source.get("thread_id")
if isinstance(thread_id, str) and thread_id.strip():
return thread_id.strip()
return fallback