zerochat 10.19.0__tar.gz → 10.20.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zerochat
3
- Version: 10.19.0
3
+ Version: 10.20.0
4
4
  Summary: Private local web client for AI models, tools and MCP services
5
5
  Author: Alberto Alday
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "zerochat"
7
- version = "10.19.0"
7
+ version = "10.20.0"
8
8
  description = "Private local web client for AI models, tools and MCP services"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zerochat
3
- Version: 10.19.0
3
+ Version: 10.20.0
4
4
  Summary: Private local web client for AI models, tools and MCP services
5
5
  Author: Alberto Alday
6
6
  License-Expression: MIT
@@ -58,7 +58,7 @@ import zlib
58
58
  from collections.abc import Iterator
59
59
  from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
60
60
  from pathlib import Path
61
- from typing import Callable
61
+ from typing import Callable, IO
62
62
  from urllib.parse import urlencode
63
63
 
64
64
  # --- core.limits ---
@@ -1473,7 +1473,7 @@ def dispatch_browser(method: str, params: dict) -> RpcOutcome:
1473
1473
 
1474
1474
 
1475
1475
 
1476
- SOURCE_BACKEND_VERSION = "10.19.0"
1476
+ SOURCE_BACKEND_VERSION = "10.20.0"
1477
1477
 
1478
1478
 
1479
1479
  def _read_source_version(filename: str) -> str | None:
@@ -7348,7 +7348,26 @@ class ConsoleControl:
7348
7348
 
7349
7349
 
7350
7350
 
7351
- def run_supervisor(server: ThreadingHTTPServer, session: RunSession, runner_proc: subprocess.Popen | None = None, browser_proc: subprocess.Popen | None = None):
7351
+ # Final de la salida de error del runner que acompaña al motivo de un final sin resultado.
7352
+ RUNNER_ERROR_TAIL_BYTES = 2000
7353
+
7354
+
7355
+ def runner_exit_reason(proc: subprocess.Popen, stderr_log: IO[bytes] | None) -> str:
7356
+ """Por qué terminó el runner sin resultado: su código de salida y el final de su salida de error."""
7357
+ tail = ""
7358
+ if stderr_log is not None:
7359
+ try:
7360
+ size = stderr_log.seek(0, os.SEEK_END)
7361
+ stderr_log.seek(max(0, size - RUNNER_ERROR_TAIL_BYTES))
7362
+ tail = stderr_log.read().decode("utf-8", "replace").strip()
7363
+ except (OSError, ValueError):
7364
+ tail = ""
7365
+ reason = f"El runner de Node.js terminó con el código {proc.returncode} sin resultado"
7366
+ return f"{reason}: {tail}" if tail else f"{reason}."
7367
+
7368
+
7369
+ def run_supervisor(server: ThreadingHTTPServer, session: RunSession, runner_proc: subprocess.Popen | None = None,
7370
+ browser_proc: subprocess.Popen | None = None, runner_log: IO[bytes] | None = None):
7352
7371
  """Detiene el servidor al recibir el resultado, si termina el runner propio o al agotar los plazos."""
7353
7372
  proc = runner_proc if runner_proc is not None else browser_proc
7354
7373
  deadline = time.monotonic() + RUN_TOTAL_TIMEOUT
@@ -7357,6 +7376,8 @@ def run_supervisor(server: ThreadingHTTPServer, session: RunSession, runner_proc
7357
7376
  if _SERVER_SHUTTING_DOWN.is_set():
7358
7377
  return
7359
7378
  if proc is not None and proc.poll() is not None and not session.finished.wait(0.2):
7379
+ if runner_proc is not None:
7380
+ session.stop_reason = runner_exit_reason(runner_proc, runner_log)
7360
7381
  break
7361
7382
  if time.monotonic() >= deadline + session.waited_seconds():
7362
7383
  session.stop_reason = f"Plazo total agotado ({RUN_TOTAL_TIMEOUT:.0f}s, sin contar las esperas)."
@@ -7397,8 +7418,9 @@ def _runner_cache_file() -> Path:
7397
7418
  return cache_dir / "modules.json"
7398
7419
 
7399
7420
 
7400
- def launch_node_runner(url: str) -> subprocess.Popen | None:
7401
- """Abre el runner de Node.js sin ventana en segundo plano con el modelo de permisos de Node.
7421
+ def launch_node_runner(url: str) -> tuple[subprocess.Popen, IO[bytes]] | None:
7422
+ """Abre el runner de Node.js sin ventana en segundo plano con el modelo de permisos de Node; devuelve el proceso
7423
+ y su salida de error, en un fichero temporal sin nombre, para explicar un final sin resultado (runner_exit_reason).
7402
7424
 
7403
7425
  El cargador (runner_loader.py) descarga los módulos de la interfaz de url y solo puede leer y escribir su caché.
7404
7426
  Hereda el entorno de quien lanza zerochat (NODE_EXTRA_CA_CERTS, TZ, LANG...): ejecuta código propio, no el del
@@ -7417,13 +7439,15 @@ def launch_node_runner(url: str) -> subprocess.Popen | None:
7417
7439
  cmd = [node, "--permission", f"--allow-fs-read={cache_dir}", f"--allow-fs-write={cache_dir}",
7418
7440
  "-e", RUNNER_LOADER_SCRIPT, str(cache_file), url]
7419
7441
  try:
7420
- return subprocess.Popen(
7442
+ stderr_log = tempfile.TemporaryFile() # noqa: SIM115 - vive lo que la ejecución; se cierra al salir
7443
+ proc = subprocess.Popen(
7421
7444
  cmd,
7422
7445
  stdin=subprocess.DEVNULL,
7423
7446
  stdout=subprocess.DEVNULL,
7424
- stderr=subprocess.DEVNULL,
7447
+ stderr=stderr_log,
7425
7448
  start_new_session=True,
7426
7449
  )
7450
+ return proc, stderr_log
7427
7451
  except OSError as error:
7428
7452
  run_error(f"No se pudo iniciar el proceso de Node.js ({error}).")
7429
7453
  return None
@@ -8920,6 +8944,13 @@ class ZeroChatServerHandler(BaseHTTPRequestHandler):
8920
8944
  # Silenciar logs ruidosos por defecto
8921
8945
  pass
8922
8946
 
8947
+
8948
+ class ZeroChatHTTPServer(ThreadingHTTPServer):
8949
+ """Servidor del backend con una cola de conexiones amplia: la interfaz en desarrollo y el runner de Node piden
8950
+ decenas de módulos a la vez, y con la cola de 5 por defecto macOS descarta las que sobran (el cliente agota el
8951
+ plazo de conexión) y Windows las reinicia."""
8952
+ request_queue_size = 128
8953
+
8923
8954
  # --- cli.main ---
8924
8955
  """Punto de entrada de zerochat: argumentos de la línea de órdenes, arranque del servidor, interfaz, ejecución desatendida y cierre."""
8925
8956
 
@@ -9153,7 +9184,7 @@ def open_server(args, local_ui: bool) -> ThreadingHTTPServer:
9153
9184
  port = args.port if args.port is not None else int(os.environ.get("ZEROCHAT_PORT", DEFAULT_PORT))
9154
9185
  set_active_address(host, port)
9155
9186
  try:
9156
- return ThreadingHTTPServer((host, port), ZeroChatServerHandler)
9187
+ return ZeroChatHTTPServer((host, port), ZeroChatServerHandler)
9157
9188
  except OSError as exc:
9158
9189
  if not current_run_session():
9159
9190
  raise
@@ -9163,7 +9194,7 @@ def open_server(args, local_ui: bool) -> ThreadingHTTPServer:
9163
9194
  sys.exit(RUN_EXIT_SETUP)
9164
9195
  # Otro zerochat (u otro programa) usa el puerto por defecto: la ejecución usa uno libre.
9165
9196
  try:
9166
- server = ThreadingHTTPServer((host, 0), ZeroChatServerHandler)
9197
+ server = ZeroChatHTTPServer((host, 0), ZeroChatServerHandler)
9167
9198
  except OSError as retry_exc:
9168
9199
  run_error(f"No se pudo escuchar en {host}: {retry_exc}")
9169
9200
  sys.exit(RUN_EXIT_SETUP)
@@ -9232,12 +9263,13 @@ def start_interface(args, parser, server: ThreadingHTTPServer, ui_url: str):
9232
9263
  return None
9233
9264
  if not args.browser:
9234
9265
  session.runner_token = issue_runner_token(session.run_id, session.conversation_id or session.new_conversation_id)
9235
- runner_proc = launch_node_runner(launch_url(ui_url, token=session.runner_token))
9236
- if runner_proc is None:
9266
+ runner = launch_node_runner(launch_url(ui_url, token=session.runner_token))
9267
+ if runner is None:
9237
9268
  server.server_close()
9238
9269
  mute_console()
9239
9270
  sys.exit(RUN_EXIT_SETUP)
9240
- threading.Thread(target=run_supervisor, args=(server, session, runner_proc), daemon=True).start()
9271
+ runner_proc, runner_log = runner
9272
+ threading.Thread(target=run_supervisor, args=(server, session, runner_proc, None, runner_log), daemon=True).start()
9241
9273
  return runner_proc
9242
9274
  target_url = launch_url(ui_url)
9243
9275
  headless_browser = launch_headless_browser(target_url) if args.headless else None
File without changes
File without changes
File without changes