新增 Tlon 渠道扩展,支持在 Yuxi 平台中集成 Tlon/Urbit 去中心化通讯平台。 包含以下功能模块: - tlon_api: Tlon API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - sse_client: SSE 客户端 - outbound: 外发消息管理 - send: 消息发送 - security: 安全校验 - auth: 认证管理 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - approval: 审批流程 - channel_mgmt: 频道管理 - channel_ops: 频道操作 - contacts: 联系人管理 - discovery: 服务发现 - doctor: 健康诊断 - expose: 服务暴露 - gallery: 图库管理 - history: 历史记录 - hooks: 钩子管理 - media: 媒体资源处理 - notebook: 笔记本功能 - settings_store: 设置存储 - setup: 初始化设置 - story: 故事功能 - targets: 目标管理 - cite_parser: 引用解析 - utils: 工具函数 - types: 类型定义
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
from yuxi.channel.extensions.tlon.utils import is_valid_ship
|
|
|
|
|
|
class TlonSetupWizard:
|
|
steps = [
|
|
{
|
|
"id": "ship",
|
|
"label": "Ship name",
|
|
"placeholder": "~sampel-palnet",
|
|
"validate": "normalize_ship → must be valid ship name",
|
|
},
|
|
{
|
|
"id": "url",
|
|
"label": "Ship URL",
|
|
"placeholder": "https://your-ship-host",
|
|
"validate": "validate_urbit_base_url → http/https protocol, no credentials",
|
|
},
|
|
{
|
|
"id": "code",
|
|
"label": "Login code",
|
|
"placeholder": "lidlut-tabwed-pillex-ridrup",
|
|
"validate": "required, non-empty string",
|
|
},
|
|
]
|
|
|
|
def setup_wizard_steps(self) -> list:
|
|
return self.steps
|
|
|
|
def validate_wizard_input(self, step_key: str, value: str) -> str | None:
|
|
if step_key == "ship":
|
|
if not is_valid_ship(value):
|
|
return "Invalid ship name format (expected ~name-name)"
|
|
elif step_key == "url":
|
|
if not value.startswith(("http://", "https://")):
|
|
return "URL must start with http:// or https://"
|
|
elif step_key == "code":
|
|
if not value or not value.strip():
|
|
return "Login code is required"
|
|
return None
|
|
|
|
async def finalize(self, config: dict) -> dict:
|
|
result = dict(config)
|
|
|
|
ship_url = result.get("url", "")
|
|
private_ranges = ["127.", "10.", "192.168.", "172.16.", "172.17.",
|
|
"172.18.", "172.19.", "172.20.", "172.21.", "172.22.",
|
|
"172.23.", "172.24.", "172.25.", "172.26.", "172.27.",
|
|
"172.28.", "172.29.", "172.30.", "172.31.", "localhost"]
|
|
|
|
from urllib.parse import urlparse
|
|
parsed = urlparse(ship_url)
|
|
hostname = parsed.hostname or ""
|
|
is_private = any(hostname.startswith(prefix) for prefix in private_ranges)
|
|
if is_private:
|
|
result.setdefault("network", {})["dangerouslyAllowPrivateNetwork"] = True
|
|
|
|
result.setdefault("groupChannels", [])
|
|
result.setdefault("dmAllowlist", [])
|
|
result.setdefault("groupInviteAllowlist", [])
|
|
result.setdefault("autoDiscoverChannels", True)
|
|
result.setdefault("showModelSignature", False)
|
|
result.setdefault("autoAcceptDmInvites", False)
|
|
result.setdefault("autoAcceptGroupInvites", False)
|
|
result.setdefault("ownerShip", result.get("ship", ""))
|
|
result.setdefault("defaultAuthorizedShips", [])
|
|
result.setdefault("authorization", {"channelRules": {}})
|
|
|
|
return result |