forked from trpc-group/trpc-agent-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_repair.py
More file actions
30 lines (23 loc) · 1.08 KB
/
Copy path_repair.py
File metadata and controls
30 lines (23 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
#
# Copyright (C) 2026 Tencent. All rights reserved.
#
# tRPC-Agent-Python is licensed under Apache-2.0.
"""This file is used to repair channels."""
from typing import Callable
from typing import Dict
from nanobot.channels.manager import ChannelManager
from trpc_agent_sdk.log import logger
_channels_to_repair: Dict[str, Callable[[str, ChannelManager], None]] = {}
def register_channel_repair(channel_name: str, repair_func: Callable[[str, ChannelManager], None]) -> None:
"""Register a channel to be repaired."""
_channels_to_repair[channel_name] = repair_func
def repair_channels(channel_manager: ChannelManager) -> None:
"""Repair all channels."""
for name, repair_func in _channels_to_repair.items():
try:
logger.debug(f"Repairing channel {name}...")
repair_func(name, channel_manager)
logger.debug(f"Channel {name} repaired successfully.")
except Exception as e:
logger.error(f"Failed to repair channel {name}: {e}")