aios shell support /connect command , connect to a agent though tunnel easy.
This commit is contained in:
@@ -14,11 +14,11 @@ class ResourceLocation:
|
||||
pass
|
||||
|
||||
class UserConfigItem:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self,desc:str=None) -> None:
|
||||
self.default_value = None
|
||||
self.is_optional = False
|
||||
self.item_type = "str"
|
||||
self.desc = None
|
||||
self.desc = desc
|
||||
self.value = None
|
||||
self.user_set = False
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class TelegramTunnel(AgentTunnel):
|
||||
logger.warning(f"tunnel {self.tunnel_id} is already started")
|
||||
return False
|
||||
self.is_start = True
|
||||
logger.warning(f"tunnel {self.tunnel_id} is starting...")
|
||||
logger.info(f"tunnel {self.tunnel_id} is starting...")
|
||||
|
||||
self.bot = Bot(self.tg_token)
|
||||
self.update_queue = asyncio.Queue()
|
||||
@@ -92,7 +92,7 @@ class TelegramTunnel(AgentTunnel):
|
||||
update_id += 1
|
||||
|
||||
asyncio.create_task(_run_app())
|
||||
logger.warning(f"tunnel {self.tunnel_id} started.")
|
||||
logger.info(f"tunnel {self.tunnel_id} started.")
|
||||
return True
|
||||
|
||||
async def close(self) -> None:
|
||||
|
||||
@@ -13,20 +13,47 @@ class AgentTunnel(ABC):
|
||||
def register_loader(cls,tunnel_type:str,loader:Coroutine) -> None:
|
||||
cls._all_loader[tunnel_type] = loader
|
||||
|
||||
|
||||
@classmethod
|
||||
async def load_all_tunnels_from_config(cls,config:dict) -> None:
|
||||
for tunnel_config in config:
|
||||
for tunnel_id,tunnel_config in config.items():
|
||||
loader = cls._all_loader.get(tunnel_config["type"])
|
||||
tid = tunnel_config.get("tunnel_id")
|
||||
if tid is not None:
|
||||
if tunnel_id != tid:
|
||||
logger.warning(f"load tunnel {tunnel_id} error,{tunnel_id} != {tid} in config!")
|
||||
continue
|
||||
else:
|
||||
tunnel_config["tunnel_id"] = tunnel_id
|
||||
|
||||
if loader is not None:
|
||||
tunnel = await loader(tunnel_config)
|
||||
if tunnel is not None:
|
||||
cls._all_tunnels[tunnel.tunnel_id] = tunnel
|
||||
cls._all_tunnels[tunnel_id] = tunnel
|
||||
tunnel.connect_to(AIBus.get_default_bus(),tunnel.target_id)
|
||||
await tunnel.start()
|
||||
else:
|
||||
logger.error(f"load tunnel {tunnel_config['tunnel_id']} failed")
|
||||
logger.error(f"load tunnel {tunnel_id} failed")
|
||||
else:
|
||||
logger.error(f"load tunnel {tunnel_config['type']} failed,loader not found")
|
||||
logger.error(f"load tunnel {tunnel_id} failed,loader not found")
|
||||
|
||||
@classmethod
|
||||
async def load_tunnel_from_config(cls,tunnel_config:dict):
|
||||
loader = cls._all_loader.get(tunnel_config["type"])
|
||||
if loader is not None:
|
||||
tunnel = await loader(tunnel_config)
|
||||
if tunnel is not None:
|
||||
cls._all_tunnels[tunnel.tunnel_id] = tunnel
|
||||
tunnel.connect_to(AIBus.get_default_bus(),tunnel.target_id)
|
||||
await tunnel.start()
|
||||
return True
|
||||
else:
|
||||
logger.error(f"load tunnel {tunnel_config['tunnel_id']} failed")
|
||||
else:
|
||||
logger.error(f"load tunnel {tunnel_config['type']} failed,loader not found")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
Reference in New Issue
Block a user