fix: follow active Telegram transcript after rotation
This commit is contained in:
@@ -14,6 +14,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
@@ -29,6 +30,8 @@ WORKSPACE = Path("/root/.openclaw/workspace")
|
||||
MEMORY_DIR = WORKSPACE / "memory"
|
||||
SOURCES_PATH = MEMORY_DIR / "session_sources.json"
|
||||
STATE_PATH = MEMORY_DIR / "session_ingest_state.json"
|
||||
SESSIONS_DIR = Path("/root/.openclaw/agents/main/sessions")
|
||||
SESSIONS_INDEX = SESSIONS_DIR / "sessions.json"
|
||||
|
||||
|
||||
def _local_tz():
|
||||
@@ -91,6 +94,24 @@ class Source:
|
||||
transcript_path: Path
|
||||
|
||||
|
||||
def _extract_chat_id(label: str) -> Optional[str]:
|
||||
match = re.match(r"^[a-zA-Z0-9_-]+:(\d+)$", (label or "").strip())
|
||||
return match.group(1) if match else None
|
||||
|
||||
|
||||
def _discover_transcript_for_label(label: str) -> Optional[Path]:
|
||||
chat_id = _extract_chat_id(label)
|
||||
if not chat_id:
|
||||
return None
|
||||
index = _load_json(SESSIONS_INDEX, {})
|
||||
direct = index.get(f"agent:main:telegram:direct:{chat_id}") if isinstance(index, dict) else None
|
||||
session_file = direct.get("sessionFile") if isinstance(direct, dict) else None
|
||||
if not isinstance(session_file, str):
|
||||
return None
|
||||
path = Path(session_file)
|
||||
return path if path.exists() else None
|
||||
|
||||
|
||||
def _load_sources() -> List[Source]:
|
||||
"""
|
||||
Sources file format:
|
||||
@@ -109,7 +130,8 @@ def _load_sources() -> List[Source]:
|
||||
p = item.get("path")
|
||||
if not isinstance(p, str) or not p:
|
||||
continue
|
||||
sources.append(Source(label=label, transcript_path=Path(p)))
|
||||
transcript_path = _discover_transcript_for_label(label) or Path(p)
|
||||
sources.append(Source(label=label, transcript_path=transcript_path))
|
||||
return sources
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user