File size: 4,565 Bytes
58cec34
 
2839144
 
d7f0eff
44a0185
d7f0eff
3c7d3b0
9f18430
44a0185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58cec34
9f18430
db0df50
9f18430
db0df50
 
 
 
 
 
 
 
 
 
 
 
 
44a0185
 
 
db0df50
 
 
 
 
 
 
 
3da93f6
 
db0df50
 
3da93f6
44a0185
3da93f6
db0df50
3da93f6
db0df50
 
 
 
 
 
 
 
 
2839144
d7f0eff
db0df50
 
2839144
9f18430
db0df50
 
 
 
 
 
 
d7f0eff
 
 
 
db0df50
 
 
 
d7f0eff
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
#!/usr/bin/env python3
import os
import subprocess
import sys
import time
import json
from pathlib import Path
import signal
import threading
import shutil

def check_and_create_property_json():
    """Проверяет наличие property.json и создает его при необходимости"""
    property_path = Path("/app/agents/property.json")
    
    if not property_path.exists():
        print(f"WARNING: {property_path} не найден, создаем файл...")
        
        property_data = {
            "name": "TEN Agent Example",
            "version": "0.0.1",
            "extensions": ["openai_chatgpt"],
            "description": "A basic voice agent with OpenAI",
            "graphs": [
                {
                    "name": "Voice Agent",
                    "description": "Basic voice agent with OpenAI",
                    "file": "./examples/voice_agent.json"
                },
                {
                    "name": "Chat Agent",
                    "description": "Simple chat agent",
                    "file": "./examples/chat_agent.json"
                }
            ]
        }
        
        # Проверяем и создаем директории
        property_path.parent.mkdir(parents=True, exist_ok=True)
        
        # Записываем файл
        with open(property_path, 'w') as f:
            json.dump(property_data, f, indent=2)
        
        # Создаем пустые файлы графов
        examples_dir = property_path.parent / "examples"
        examples_dir.mkdir(parents=True, exist_ok=True)
        
        with open(examples_dir / "voice_agent.json", 'w') as f:
            f.write('{"nodes":[]}')
        
        with open(examples_dir / "chat_agent.json", 'w') as f:
            f.write('{"nodes":[]}')
        
        print(f"Файл {property_path} создан успешно")

def main():
    processes = []
    try:
        # Пути к исполняемым файлам
        api_binary = Path("/app/server/bin/api")
        playground_dir = Path("/app/playground")
        
        # Проверяем существование файлов
        if not api_binary.exists():
            print(f"ERROR: API binary not found at {api_binary}", file=sys.stderr)
            return 1
        
        if not playground_dir.exists():
            print(f"ERROR: Playground directory not found at {playground_dir}", file=sys.stderr)
            return 1
        
        # Проверяем и создаем property.json
        check_and_create_property_json()
        
        # Запускаем API сервер
        print("Starting TEN-Agent API server on port 8080...")
        api_process = subprocess.Popen([str(api_binary)])
        processes.append(api_process)
        
        # Даем API серверу время на запуск
        time.sleep(3)
        
        # Запускаем Playground UI в режиме dev на порту 7860 (порт Hugging Face)
        print("Starting Playground UI in development mode on port 7860...")
        os.environ["PORT"] = "7860"
        os.environ["AGENT_SERVER_URL"] = "http://localhost:8080"
        os.environ["NEXT_PUBLIC_EDIT_GRAPH_MODE"] = "true"  # Включаем расширенный режим редактирования
        os.environ["NEXT_PUBLIC_DISABLE_CAMERA"] = "true"  # Отключаем запрос на использование камеры
        
        playground_process = subprocess.Popen(
            ["pnpm", "dev"],
            cwd=str(playground_dir),
            env=os.environ
        )
        processes.append(playground_process)
        
        # Ожидаем завершения процессов
        for proc in processes:
            proc.wait()
            
    except KeyboardInterrupt:
        print("Shutting down...")
    except Exception as e:
        print(f"Error: {e}", file=sys.stderr)
    finally:
        # Завершение процессов
        for proc in processes:
            if proc and proc.poll() is None:
                proc.terminate()
                try:
                    proc.wait(timeout=5)
                except subprocess.TimeoutExpired:
                    proc.kill()
    
    return 0

if __name__ == "__main__":
    # Корректная обработка сигналов
    signal.signal(signal.SIGINT, lambda sig, frame: sys.exit(0))
    signal.signal(signal.SIGTERM, lambda sig, frame: sys.exit(0))
    
    sys.exit(main())