From e1c24bd2e605ad1d5e9337da3648de448f28f532 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Sun, 11 Oct 2026 19:16:21 -0300 Subject: [PATCH] =?UTF-8?q?refactor(scripts):=20simplifica=20l=C3=B3gica?= =?UTF-8?q?=20de=20inicializa=C3=A7=C3=A3o=20e=20adapta=20encerramento=20d?= =?UTF-8?q?e=20chat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplifica o script de inicialização removendo detecção complexa de venv e lógica de fallback, mantendo apenas o fluxo essencial de verificação e instalação de dependências. Adapta a interface de encerramento de chat para não aguardar resposta do servidor, considerando que o mesmo é desligado após o término da conversa. --- .gitignore | 0 LICENSE | 0 README.md | 0 RULES.md | 0 app.py | 0 config.json | 0 contexto.json | 0 iniciar.bat | 0 iniciar.sh | 40 +++++++++------------------------------- perfil_ia.json | 0 perfil_user.json | 0 proibidos.json | 0 requirements.txt | 0 templates/chat.html | 15 +++++++-------- 14 files changed, 16 insertions(+), 39 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 RULES.md mode change 100644 => 100755 app.py mode change 100644 => 100755 config.json mode change 100644 => 100755 contexto.json mode change 100644 => 100755 iniciar.bat mode change 100644 => 100755 perfil_ia.json mode change 100644 => 100755 perfil_user.json mode change 100644 => 100755 proibidos.json mode change 100644 => 100755 requirements.txt mode change 100644 => 100755 templates/chat.html diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/RULES.md b/RULES.md old mode 100644 new mode 100755 diff --git a/app.py b/app.py old mode 100644 new mode 100755 diff --git a/config.json b/config.json old mode 100644 new mode 100755 diff --git a/contexto.json b/contexto.json old mode 100644 new mode 100755 diff --git a/iniciar.bat b/iniciar.bat old mode 100644 new mode 100755 diff --git a/iniciar.sh b/iniciar.sh index 47770a2..57d16d9 100755 --- a/iniciar.sh +++ b/iniciar.sh @@ -1,5 +1,4 @@ #!/bin/bash -set -e DIR="$(cd "$(dirname "$0")" && pwd)" @@ -21,42 +20,21 @@ if [ -z "$PYTHON" ]; then fi VENV_DIR="$DIR/venv" -VENV_OK=false -# Verifica se o venv existe e e funcional -if [ -f "$VENV_DIR/bin/activate" ]; then - source "$VENV_DIR/bin/activate" 2>/dev/null || true - if $PYTHON -c "import flask" 2>/dev/null; then - VENV_OK=true - fi -fi - -if [ "$VENV_OK" = true ]; then +# Verifica se o venv e funcional +if [ -f "$VENV_DIR/bin/activate" ] && $PYTHON -c "import flask" 2>/dev/null; then echo "[1/3] Ambiente virtual funcional." + source "$VENV_DIR/bin/activate" else - # Verifica se podemos criar venv - if $PYTHON -m venv --help &>/dev/null 2>&1; then - if $PYTHON -m venv "$VENV_DIR" 2>/dev/null; then - source "$VENV_DIR/bin/activate" - echo "[1/4] Ambiente virtual criado." - echo "[2/4] Instalando dependencias..." - pip install --upgrade pip -q 2>/dev/null || true - pip install -r "$DIR/requirements.txt" -q - echo "[3/4] Dependencias instaladas." - VENV_OK=true - fi - fi -fi - -if [ "$VENV_OK" = false ]; then - echo "[!] Ambiente virtual indisponivel (sem python3-venv ou permissao negada)." - echo "[1/2] Instalando dependencias globalmente..." - $PYTHON -m pip install -r "$DIR/requirements.txt" -q 2>/dev/null || \ - $PYTHON -m pip install -r "$DIR/requirements.txt" -q --break-system-packages 2>/dev/null || { + echo "[1/2] Instalando dependencias..." + $PYTHON -m pip install --upgrade pip -q 2>/dev/null || true + $PYTHON -m pip install -r "$DIR/requirements.txt" -q --break-system-packages 2>/dev/null || \ + $PYTHON -m pip install -r "$DIR/requirements.txt" -q 2>/dev/null || { echo "[!] Erro ao instalar dependencias." + echo " Tente: pip install -r requirements.txt" exit 1 } - echo "[2/2] Dependencias instaladas globalmente." + echo "[2/2] Dependencias instaladas." fi echo "[4/4] Iniciando aplicacao Flask..." diff --git a/perfil_ia.json b/perfil_ia.json old mode 100644 new mode 100755 diff --git a/perfil_user.json b/perfil_user.json old mode 100644 new mode 100755 diff --git a/proibidos.json b/proibidos.json old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 diff --git a/templates/chat.html b/templates/chat.html old mode 100644 new mode 100755 index b1cec11..77ef9e3 --- a/templates/chat.html +++ b/templates/chat.html @@ -960,16 +960,15 @@ async function clearChat() { async function endChat() { appendMessage('user', '/encerrar'); try { - const res = await fetch('/end', { method: 'POST' }); - const data = await res.json(); - chatEl.innerHTML = ''; - appendMessage('ai', data.reply || 'Chat encerrado. Recarregue a página para começar novamente.'); - input.value = ''; - input.disabled = true; - sendBtn.disabled = true; + await fetch('/end', { method: 'POST' }); } catch (err) { - appendMessage('system', 'Erro ao encerrar.'); + // servidor encerrado - esperado } + chatEl.innerHTML = ''; + appendMessage('ai', 'Chat encerrado. Recarregue a página ou inicie o servidor novamente.'); + input.value = ''; + input.disabled = true; + sendBtn.disabled = true; } input.focus();