ocerebro 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/dashboard/standalone_server.py +38 -0
- package/src/mcp/server.py +38 -14
package/package.json
CHANGED
package/pyproject.toml
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Servidor standalone do Dashboard do OCerebro - roda como processo separado"""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
# Adiciona project root ao path
|
|
7
|
+
project_root = Path(__file__).parent.parent.parent
|
|
8
|
+
sys.path.insert(0, str(project_root))
|
|
9
|
+
|
|
10
|
+
from src.dashboard.server import DashboardServer
|
|
11
|
+
from src.mcp.server import CerebroMCP
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
"""Inicia o servidor standalone"""
|
|
15
|
+
port = int(sys.argv[1]) if len(sys.argv) > 1 else 7999
|
|
16
|
+
|
|
17
|
+
# Inicializa componentes
|
|
18
|
+
mcp = CerebroMCP()
|
|
19
|
+
|
|
20
|
+
dashboard = DashboardServer(
|
|
21
|
+
cerebro_path=mcp.cerebro_path,
|
|
22
|
+
metadata_db=mcp.metadata_db,
|
|
23
|
+
embeddings_db=mcp.embeddings_db,
|
|
24
|
+
entities_db=mcp.entities_db
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
if dashboard.start(port):
|
|
28
|
+
print(f"Dashboard rodando em http://localhost:{port}")
|
|
29
|
+
# Mantém vivo
|
|
30
|
+
import time
|
|
31
|
+
while True:
|
|
32
|
+
time.sleep(3600) # Dorme por 1 hora, loop infinito
|
|
33
|
+
else:
|
|
34
|
+
print(f"Falha ao iniciar dashboard na porta {port}")
|
|
35
|
+
sys.exit(1)
|
|
36
|
+
|
|
37
|
+
if __name__ == "__main__":
|
|
38
|
+
main()
|
package/src/mcp/server.py
CHANGED
|
@@ -898,26 +898,50 @@ Uma chamada por memória. O sistema salva e indexa automaticamente.
|
|
|
898
898
|
def _cerebro_dashboard(self, args: Dict[str, Any]) -> str:
|
|
899
899
|
"""Abre o dashboard visual do OCerebro no browser"""
|
|
900
900
|
try:
|
|
901
|
-
|
|
901
|
+
import subprocess
|
|
902
|
+
import sys
|
|
902
903
|
|
|
903
904
|
port = args.get("port", 7999)
|
|
904
905
|
|
|
905
|
-
#
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
906
|
+
# Verifica se já está rodando
|
|
907
|
+
import socket
|
|
908
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
909
|
+
sock.settimeout(1)
|
|
910
|
+
result = sock.connect_ex(('127.0.0.1', port))
|
|
911
|
+
sock.close()
|
|
912
|
+
is_running = result == 0
|
|
913
|
+
|
|
914
|
+
if not is_running:
|
|
915
|
+
# Inicia como processo separado (persiste após o MCP terminar)
|
|
916
|
+
server_script = Path(__file__).parent.parent / "dashboard" / "standalone_server.py"
|
|
917
|
+
if not server_script.exists():
|
|
918
|
+
return "⚠️ Erro: standalone_server.py não encontrado."
|
|
919
|
+
|
|
920
|
+
# Inicia processo em background
|
|
921
|
+
subprocess.Popen(
|
|
922
|
+
[sys.executable, str(server_script), str(port)],
|
|
923
|
+
cwd=str(Path(__file__).parent.parent.parent),
|
|
924
|
+
stdout=subprocess.DEVNULL,
|
|
925
|
+
stderr=subprocess.DEVNULL,
|
|
926
|
+
start_new_session=True # Desacoplado do processo pai
|
|
927
|
+
)
|
|
912
928
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
929
|
+
# Aguarda servidor estar pronto (até 5s)
|
|
930
|
+
import time
|
|
931
|
+
for _ in range(50):
|
|
932
|
+
time.sleep(0.1)
|
|
933
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
934
|
+
sock.settimeout(1)
|
|
935
|
+
result = sock.connect_ex(('127.0.0.1', port))
|
|
936
|
+
sock.close()
|
|
937
|
+
if result == 0:
|
|
938
|
+
break
|
|
939
|
+
else:
|
|
940
|
+
return "⚠️ Servidor não iniciou em 5 segundos."
|
|
918
941
|
|
|
919
942
|
# Abre browser
|
|
920
|
-
|
|
943
|
+
import webbrowser
|
|
944
|
+
webbrowser.open(f"http://localhost:{port}")
|
|
921
945
|
|
|
922
946
|
return f"✅ Dashboard aberto em http://localhost:{port}"
|
|
923
947
|
except ImportError as e:
|