-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclawapi-ui.py
More file actions
executable file
·81 lines (65 loc) · 1.97 KB
/
clawapi-ui.py
File metadata and controls
executable file
·81 lines (65 loc) · 1.97 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""
FreeClaw - 智能入口
自动检测环境并选择合适的界面
"""
import sys
import os
def is_interactive_terminal():
"""检测是否在交互式终端"""
return sys.stdin.isatty() and sys.stdout.isatty()
def has_full_tty():
"""检测是否支持完整 TTY(Textual 需要)"""
try:
import termios
termios.tcgetattr(sys.stdin)
return True
except:
return False
def main():
# 检测环境
if len(sys.argv) > 1:
# 有命令行参数:使用 CLI 模式
print("Using CLI mode...")
from clawapi import main as cli_main
cli_main()
elif has_full_tty():
# 完整 TTY:使用 Textual TUI
print("Starting Textual TUI...")
import time
time.sleep(0.5)
from clawapi_tui import FreeClawTUI
app = FreeClawTUI()
app.run()
elif is_interactive_terminal():
# 受限终端:使用 Rich 菜单
print("Starting Rich TUI...")
import time
time.sleep(0.5)
from clawapi_rich import FreeClawRichTUI
tui = FreeClawRichTUI()
tui.run()
else:
# 非交互环境(QQ/飞书):对话式接口
# 这个模式下,应该由 AI 助手调用,而不是用户直接运行
# 返回一个提示,告诉 AI 如何使用
print("""
FreeClaw - Conversational Interface
This tool is designed to be called by AI assistants in chat environments (QQ/Feishu).
For AI assistants:
Use the Python API directly:
from lib.config_manager import FreeClawConfigManager
manager = FreeClawConfigManager()
# List providers
providers = manager.list_providers()
# List channels
channels = manager.list_channels()
# Add provider
manager.add_provider(name, url, key)
# Set primary model
manager.set_primary_model(model_id)
For interactive UI, run from SSH terminal:
python3 clawapi-tui.py
""")
if __name__ == "__main__":
main()