๐Ÿ“ฆ Panniantong / Agent-Reach

๐Ÿ“„ base.py ยท 37 lines
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
31
32
33
34
35
36
37# -*- coding: utf-8 -*-
"""
Channel base class โ€” platform availability checking.

Each channel represents a platform (YouTube, Twitter, GitHub, etc.)
and provides:
  - can_handle(url) โ†’ does this URL belong to this platform?
  - check(config) โ†’ is the upstream tool installed and configured?

After installation, agents call upstream tools directly.
"""

import shutil
from abc import ABC, abstractmethod
from typing import List, Tuple


class Channel(ABC):
    """Base class for all channels."""

    name: str = ""                    # e.g. "youtube"
    description: str = ""             # e.g. "YouTube ่ง†้ข‘ๅ’Œๅญ—ๅน•"
    backends: List[str] = []          # e.g. ["yt-dlp"] โ€” what upstream tool is used
    tier: int = 0                     # 0=zero-config, 1=needs free key, 2=needs setup

    @abstractmethod
    def can_handle(self, url: str) -> bool:
        """Check if this channel can handle this URL."""
        ...

    def check(self, config=None) -> Tuple[str, str]:
        """
        Check if this channel's upstream tool is available.
        Returns (status, message) where status is 'ok'/'warn'/'off'/'error'.
        """
        return "ok", f"{'ใ€'.join(self.backends) if self.backends else 'ๅ†…็ฝฎ'}"