|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
echo "=== TEN Agent UI Fix ===" |
|
|
|
|
|
TMP_DIR="/tmp/ten-agent" |
|
mkdir -p $TMP_DIR |
|
|
|
echo "Временная директория создана: $TMP_DIR" |
|
|
|
|
|
cat > $TMP_DIR/property.json << 'EOL' |
|
{ |
|
"_ten": {}, |
|
"name": "TEN Agent Example", |
|
"version": "0.0.1", |
|
"extensions": ["openai_chatgpt"], |
|
"description": "A basic voice agent with OpenAI", |
|
"predefined_graphs": [ |
|
{ |
|
"name": "Voice Agent", |
|
"description": "Basic voice agent with OpenAI", |
|
"file": "voice_agent.json" |
|
}, |
|
{ |
|
"name": "Chat Agent", |
|
"description": "Simple chat agent", |
|
"file": "chat_agent.json" |
|
} |
|
], |
|
"graphs": [ |
|
{ |
|
"name": "Voice Agent", |
|
"description": "Basic voice agent with OpenAI", |
|
"file": "voice_agent.json" |
|
}, |
|
{ |
|
"name": "Chat Agent", |
|
"description": "Simple chat agent", |
|
"file": "chat_agent.json" |
|
} |
|
] |
|
} |
|
EOL |
|
|
|
echo "Создан property.json" |
|
|
|
|
|
cat > $TMP_DIR/proxy.py << 'EOL' |
|
|
|
import http.server |
|
import socketserver |
|
import json |
|
|
|
PORT = 9090 |
|
|
|
|
|
GRAPHS_DATA = [ |
|
{ |
|
"name": "Voice Agent", |
|
"description": "Voice Agent with OpenAI", |
|
"file": "voice_agent.json", |
|
"id": "voice_agent", |
|
"package": "default" |
|
}, |
|
{ |
|
"name": "Chat Agent", |
|
"description": "Chat Agent", |
|
"file": "chat_agent.json", |
|
"id": "chat_agent", |
|
"package": "default" |
|
} |
|
] |
|
|
|
|
|
DESIGNER_DATA = { |
|
"success": True, |
|
"packages": [ |
|
{ |
|
"name": "default", |
|
"description": "Default package", |
|
"graphs": [ |
|
{ |
|
"name": "Voice Agent", |
|
"description": "Voice Agent with OpenAI", |
|
"file": "voice_agent.json", |
|
"id": "voice_agent", |
|
"package": "default" |
|
}, |
|
{ |
|
"name": "Chat Agent", |
|
"description": "Chat Agent", |
|
"file": "chat_agent.json", |
|
"id": "chat_agent", |
|
"package": "default" |
|
} |
|
] |
|
} |
|
] |
|
} |
|
|
|
class SimpleHTTPRequestHandler(http.server.BaseHTTPRequestHandler): |
|
def do_GET(self): |
|
print(f"GET request: {self.path}") |
|
if self.path == "/graphs": |
|
self._send_json(GRAPHS_DATA) |
|
elif self.path.startswith("/api/designer/") or self.path.startswith("/api/dev/"): |
|
self._send_json(DESIGNER_DATA) |
|
else: |
|
self._send_json({"status": "ok"}) |
|
|
|
def do_POST(self): |
|
print(f"POST request: {self.path}") |
|
if self.path.startswith("/api/designer/") or self.path.startswith("/api/dev/"): |
|
self._send_json({"success": True}) |
|
else: |
|
self._send_json({"status": "ok"}) |
|
|
|
def do_OPTIONS(self): |
|
self.send_response(200) |
|
self.send_header('Access-Control-Allow-Origin', '*') |
|
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') |
|
self.send_header('Access-Control-Allow-Headers', 'Content-Type') |
|
self.end_headers() |
|
|
|
def _send_json(self, data): |
|
self.send_response(200) |
|
self.send_header('Content-type', 'application/json') |
|
self.send_header('Access-Control-Allow-Origin', '*') |
|
self.end_headers() |
|
self.wfile.write(json.dumps(data).encode()) |
|
|
|
print(f"Starting proxy server on port {PORT}...") |
|
with socketserver.TCPServer(("", PORT), SimpleHTTPRequestHandler) as httpd: |
|
print(f"Server running at http://localhost:{PORT}") |
|
httpd.serve_forever() |
|
EOL |
|
|
|
chmod +x $TMP_DIR/proxy.py |
|
echo "Создан proxy.py" |
|
|
|
# 4. Создаем скрипт запуска |
|
cat > $TMP_DIR/start.sh << 'EOL' |
|
#!/bin/bash |
|
|
|
# Запускаем прокси-сервер в фоне |
|
python3 /tmp/ten-agent/proxy.py & |
|
PROXY_PID=$! |
|
echo "Proxy server started with PID $PROXY_PID" |
|
|
|
# Записываем PID в файл |
|
echo $PROXY_PID > /tmp/ten-agent/proxy.pid |
|
|
|
# Устанавливаем переменные окружения для UI |
|
export PORT=7860 |
|
export AGENT_SERVER_URL="http://localhost:9090" |
|
export NEXT_PUBLIC_DEV_MODE="false" |
|
export NEXT_PUBLIC_API_BASE_URL="/api/agents" |
|
export NEXT_PUBLIC_DESIGNER_API_URL="http://localhost:9090" |
|
export NEXT_PUBLIC_EDIT_GRAPH_MODE="true" |
|
export NEXT_PUBLIC_DISABLE_CAMERA="true" |
|
|
|
# Запускаем UI |
|
cd /app/playground && pnpm dev |
|
EOL |
|
|
|
chmod +x $TMP_DIR/start.sh |
|
echo "Создан start.sh" |
|
|
|
# 5. Запускаем прокси-сервер в фоне |
|
python3 $TMP_DIR/proxy.py & |
|
PROXY_PID=$! |
|
echo "Прокси-сервер запущен с PID $PROXY_PID" |
|
echo $PROXY_PID > $TMP_DIR/proxy.pid |
|
|
|
echo "=== Настройка успешно завершена ===" |
|
echo "Для запуска полного решения выполните: bash $TMP_DIR/start.sh" |
|
echo "Для проверки запроса к прокси выполните: curl http://localhost:9090/graphs" |