File size: 5,461 Bytes
3e62a55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash

# Полное решение для интерфейса TEN Agent
# Создаст все необходимые файлы и скрипты для работы

echo "=== TEN Agent UI Fix ==="

# 1. Создаем временную директорию
TMP_DIR="/tmp/ten-agent"
mkdir -p $TMP_DIR

echo "Временная директория создана: $TMP_DIR"

# 2. Создаем property.json с корректной структурой
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"

# 3. Создаем простейший прокси-сервер на Python
cat > $TMP_DIR/proxy.py << 'EOL'
#!/usr/bin/env python3
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"
    }
]

# Данные для API дизайнера
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"