zerochat 10.2.0__tar.gz → 10.3.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.
Potentially problematic release.
This version of zerochat might be problematic. Click here for more details.
- {zerochat-10.2.0/zerochat.egg-info → zerochat-10.3.0}/PKG-INFO +1 -1
- {zerochat-10.2.0 → zerochat-10.3.0}/pyproject.toml +1 -1
- {zerochat-10.2.0 → zerochat-10.3.0/zerochat.egg-info}/PKG-INFO +1 -1
- {zerochat-10.2.0 → zerochat-10.3.0}/zerochat.py +55 -18
- {zerochat-10.2.0 → zerochat-10.3.0}/LICENSE +0 -0
- {zerochat-10.2.0 → zerochat-10.3.0}/README.md +0 -0
- {zerochat-10.2.0 → zerochat-10.3.0}/setup.cfg +0 -0
- {zerochat-10.2.0 → zerochat-10.3.0}/zerochat.egg-info/SOURCES.txt +0 -0
- {zerochat-10.2.0 → zerochat-10.3.0}/zerochat.egg-info/dependency_links.txt +0 -0
- {zerochat-10.2.0 → zerochat-10.3.0}/zerochat.egg-info/entry_points.txt +0 -0
- {zerochat-10.2.0 → zerochat-10.3.0}/zerochat.egg-info/top_level.txt +0 -0
|
@@ -53,7 +53,7 @@ import zlib
|
|
|
53
53
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
54
54
|
from pathlib import Path
|
|
55
55
|
|
|
56
|
-
SOURCE_BACKEND_VERSION = "10.
|
|
56
|
+
SOURCE_BACKEND_VERSION = "10.3.0"
|
|
57
57
|
|
|
58
58
|
def _read_source_version(filename: str) -> str | None:
|
|
59
59
|
"""Lee la versión de un archivo del repositorio cuando se ejecuta desde fuentes."""
|
|
@@ -3597,7 +3597,7 @@ def validate_profile_payload(record: dict) -> tuple[str, str, str, dict, str | N
|
|
|
3597
3597
|
|
|
3598
3598
|
|
|
3599
3599
|
def _row_to_profile(row: sqlite3.Row) -> dict:
|
|
3600
|
-
"""Transforma una fila SQLite en el objeto de perfil
|
|
3600
|
+
"""Transforma una fila SQLite en el objeto de perfil del servidor."""
|
|
3601
3601
|
try:
|
|
3602
3602
|
settings = json.loads(row["settings_json"])
|
|
3603
3603
|
except (json.JSONDecodeError, TypeError):
|
|
@@ -3618,14 +3618,14 @@ def _row_to_profile(row: sqlite3.Row) -> dict:
|
|
|
3618
3618
|
|
|
3619
3619
|
|
|
3620
3620
|
def list_general_profiles() -> list[dict]:
|
|
3621
|
-
"""Lista todos los perfiles de conexión
|
|
3621
|
+
"""Lista todos los perfiles de conexión del servidor almacenados en SQLite."""
|
|
3622
3622
|
with open_storage() as conn:
|
|
3623
3623
|
rows = conn.execute("SELECT * FROM profiles ORDER BY name COLLATE NOCASE ASC;").fetchall()
|
|
3624
3624
|
return [_row_to_profile(row) for row in rows]
|
|
3625
3625
|
|
|
3626
3626
|
|
|
3627
3627
|
def get_general_profile(profile_id: str) -> dict | None:
|
|
3628
|
-
"""Recupera un perfil
|
|
3628
|
+
"""Recupera un perfil de servidor por su identificador único."""
|
|
3629
3629
|
if not profile_id or not isinstance(profile_id, str) or not profile_id.strip():
|
|
3630
3630
|
return None
|
|
3631
3631
|
clean_id = normalize_profile_id("", profile_id)
|
|
@@ -3635,7 +3635,7 @@ def get_general_profile(profile_id: str) -> dict | None:
|
|
|
3635
3635
|
|
|
3636
3636
|
|
|
3637
3637
|
def get_general_profile_by_name(name: str) -> dict | None:
|
|
3638
|
-
"""Recupera un perfil
|
|
3638
|
+
"""Recupera un perfil de servidor por su nombre."""
|
|
3639
3639
|
if not name or not isinstance(name, str) or not name.strip():
|
|
3640
3640
|
return None
|
|
3641
3641
|
clean = name.strip()
|
|
@@ -3650,7 +3650,7 @@ def get_general_profile_by_name(name: str) -> dict | None:
|
|
|
3650
3650
|
|
|
3651
3651
|
|
|
3652
3652
|
def save_general_profile(record: dict) -> dict:
|
|
3653
|
-
"""Guarda (crea o actualiza) un perfil de conexión
|
|
3653
|
+
"""Guarda (crea o actualiza) un perfil de conexión del servidor en SQLite."""
|
|
3654
3654
|
profile_id, name, description, settings, api_key = validate_profile_payload(record)
|
|
3655
3655
|
now = int(time.time() * 1000)
|
|
3656
3656
|
|
|
@@ -3669,7 +3669,7 @@ def save_general_profile(record: dict) -> dict:
|
|
|
3669
3669
|
(name, profile_id)
|
|
3670
3670
|
).fetchone()
|
|
3671
3671
|
if same_name:
|
|
3672
|
-
raise ValueError(f"Ya existe un perfil
|
|
3672
|
+
raise ValueError(f"Ya existe un perfil con el nombre '{name}' en el servidor")
|
|
3673
3673
|
|
|
3674
3674
|
if existing:
|
|
3675
3675
|
version = existing["version"] + 1
|
|
@@ -3740,6 +3740,8 @@ def _row_to_conversation_header(row: sqlite3.Row) -> dict:
|
|
|
3740
3740
|
header["extra"] = extra
|
|
3741
3741
|
if "profile_id" in extra:
|
|
3742
3742
|
header["profileId"] = extra["profile_id"]
|
|
3743
|
+
if "server_run" in extra:
|
|
3744
|
+
header["serverRun"] = bool(extra["server_run"])
|
|
3743
3745
|
return header
|
|
3744
3746
|
|
|
3745
3747
|
|
|
@@ -3801,6 +3803,8 @@ def save_conversation(session_meta: dict, messages: list[dict] | None = None) ->
|
|
|
3801
3803
|
profile_id = session_meta.get("profileId")
|
|
3802
3804
|
if profile_id and isinstance(profile_id, str) and profile_id.strip():
|
|
3803
3805
|
extra["profile_id"] = profile_id.strip()
|
|
3806
|
+
if session_meta.get("serverRun") is not None:
|
|
3807
|
+
extra["server_run"] = bool(session_meta.get("serverRun"))
|
|
3804
3808
|
|
|
3805
3809
|
extra_json = json.dumps(extra, ensure_ascii=False) if extra else "{}"
|
|
3806
3810
|
|
|
@@ -3836,6 +3840,28 @@ def save_conversation(session_meta: dict, messages: list[dict] | None = None) ->
|
|
|
3836
3840
|
return _row_to_conversation_header(row)
|
|
3837
3841
|
|
|
3838
3842
|
|
|
3843
|
+
def mark_conversation_server_run(session_id: str, profile_name: str | None = None) -> bool:
|
|
3844
|
+
"""Marca la conversación en SQLite como ejecutada en servidor asociándole el perfil."""
|
|
3845
|
+
try:
|
|
3846
|
+
clean_id = _validate_conversation_id(session_id)
|
|
3847
|
+
except (ValueError, TypeError):
|
|
3848
|
+
return False
|
|
3849
|
+
try:
|
|
3850
|
+
with open_storage() as conn:
|
|
3851
|
+
row = conn.execute("SELECT extra_json FROM conversations WHERE id = ?;", (clean_id,)).fetchone()
|
|
3852
|
+
if not row:
|
|
3853
|
+
return False
|
|
3854
|
+
cur_extra = json.loads(row["extra_json"]) if row["extra_json"] else {}
|
|
3855
|
+
cur_extra["server_run"] = True
|
|
3856
|
+
if profile_name:
|
|
3857
|
+
cur_extra["profile_id"] = str(profile_name).strip()
|
|
3858
|
+
conn.execute("UPDATE conversations SET extra_json = ? WHERE id = ?;", (json.dumps(cur_extra, ensure_ascii=False), clean_id))
|
|
3859
|
+
conn.commit()
|
|
3860
|
+
return True
|
|
3861
|
+
except (sqlite3.Error, OSError, json.JSONDecodeError):
|
|
3862
|
+
return False
|
|
3863
|
+
|
|
3864
|
+
|
|
3839
3865
|
def rename_conversation(session_id: str, new_title: str) -> bool:
|
|
3840
3866
|
"""Renombra una conversación existente en SQLite."""
|
|
3841
3867
|
clean_id = _validate_conversation_id(session_id)
|
|
@@ -5164,8 +5190,8 @@ RUN_EXIT_TIMEOUT = 2
|
|
|
5164
5190
|
RUN_EXIT_SETUP = 3
|
|
5165
5191
|
# Argumentos no válidos, en cualquier modo: argparse usaría 2, que con --prompt es plazo agotado.
|
|
5166
5192
|
RUN_EXIT_ARGS = 4
|
|
5167
|
-
# Perfil
|
|
5168
|
-
DEFAULT_RUN_PROFILE = "
|
|
5193
|
+
# Perfil por defecto de --prompt cuando no se indica --profile.
|
|
5194
|
+
DEFAULT_RUN_PROFILE = "local"
|
|
5169
5195
|
# Formato de --export según la extensión del fichero; la interfaz genera el contenido con ChatExport.
|
|
5170
5196
|
RUN_EXPORT_FORMATS = {".md": "markdown", ".json": "json", ".html": "html"}
|
|
5171
5197
|
# Cuerpo HTTP admitido mientras se espera la exportación: el JSON y el HTML llevan las imágenes incrustadas.
|
|
@@ -5349,7 +5375,7 @@ def start_server_run(params: dict) -> dict:
|
|
|
5349
5375
|
raise ValueError("profile requerido.")
|
|
5350
5376
|
profile_entry = get_general_profile(profile) or get_general_profile_by_name(profile)
|
|
5351
5377
|
if not profile_entry:
|
|
5352
|
-
raise ValueError(f"Perfil
|
|
5378
|
+
raise ValueError(f"Perfil del servidor '{profile}' no encontrado.")
|
|
5353
5379
|
profile_name = profile_entry.get("name", profile.strip())
|
|
5354
5380
|
|
|
5355
5381
|
state_path = get_run_state_path(clean_conv_id)
|
|
@@ -5383,6 +5409,8 @@ def start_server_run(params: dict) -> dict:
|
|
|
5383
5409
|
env["ZEROCHAT_RUN_SECURITY"] = json.dumps(tool_security, ensure_ascii=False)
|
|
5384
5410
|
|
|
5385
5411
|
now = int(time.time() * 1000)
|
|
5412
|
+
mark_conversation_server_run(clean_conv_id, profile_name)
|
|
5413
|
+
|
|
5386
5414
|
proc = subprocess.Popen(
|
|
5387
5415
|
cmd,
|
|
5388
5416
|
stdin=subprocess.DEVNULL,
|
|
@@ -5432,13 +5460,14 @@ class RunSession:
|
|
|
5432
5460
|
"""Estado de la ejecución: prompt, opciones, último progreso, exportación, resultado y motivo de un final sin él."""
|
|
5433
5461
|
def __init__(self, prompt: str | None = None, profile: str | None = None, export_path: Path | None = None, keep_page: bool = False,
|
|
5434
5462
|
allow_dangerous_tools: bool = False, conversation_id: str | None = None, run_id: str | None = None,
|
|
5435
|
-
tool_security: dict | None = None):
|
|
5463
|
+
tool_security: dict | None = None, profile_data: dict | None = None):
|
|
5436
5464
|
env_run_id = os.environ.get("ZEROCHAT_RUN_ID", "").strip()
|
|
5437
5465
|
self.run_id = run_id.strip() if (run_id and isinstance(run_id, str) and run_id.strip()) else (env_run_id or secrets.token_urlsafe(24))
|
|
5438
5466
|
self.conversation_id = conversation_id
|
|
5439
5467
|
self.prompt = prompt
|
|
5440
|
-
# Perfil (nombre o id) que la interfaz usa solo en esta ejecución; por defecto,
|
|
5468
|
+
# Perfil (nombre o id) que la interfaz usa solo en esta ejecución; por defecto, local del servidor.
|
|
5441
5469
|
self.profile = profile
|
|
5470
|
+
self.profile_data = profile_data
|
|
5442
5471
|
# Fichero donde se escribe la conversación exportada (formato por su extensión); None, sin exportar.
|
|
5443
5472
|
self.export_path = export_path
|
|
5444
5473
|
self.exported = False
|
|
@@ -5533,6 +5562,7 @@ def dispatch_run(method: str, params: dict) -> tuple[dict | None, dict | None, s
|
|
|
5533
5562
|
session.touch()
|
|
5534
5563
|
export_format = RUN_EXPORT_FORMATS[session.export_path.suffix.lower()] if session.export_path else None
|
|
5535
5564
|
return {"prompt": session.prompt, "conversation_id": session.conversation_id, "profile": session.profile,
|
|
5565
|
+
"profile_data": session.profile_data,
|
|
5536
5566
|
"export": export_format, "keep_page": session.keep_page,
|
|
5537
5567
|
"allow_dangerous_tools": session.allow_dangerous_tools, "tool_security": session.tool_security}, None, ""
|
|
5538
5568
|
if method == "zerochat/run/progress":
|
|
@@ -5765,29 +5795,34 @@ def run_session_from_args(parser: ZeroChatArgumentParser, args) -> RunSession |
|
|
|
5765
5795
|
parser.error("--headless solo se usa con --browser (--prompt y --conversation ya se ejecutan sin ventana con el Chromium de Playwright)")
|
|
5766
5796
|
if args.keep_page and (not args.browser or args.headless):
|
|
5767
5797
|
parser.error("--keep-page necesita la ventana del navegador del usuario (--browser sin --headless)")
|
|
5798
|
+
profile_data = None
|
|
5768
5799
|
if args.profile is not None:
|
|
5769
5800
|
clean_profile = args.profile.strip()
|
|
5770
5801
|
if not clean_profile:
|
|
5771
5802
|
parser.error("--profile no puede estar vacío")
|
|
5772
5803
|
general_match = get_general_profile_by_name(clean_profile) or get_general_profile(clean_profile)
|
|
5773
5804
|
profile_name = general_match["name"] if general_match else clean_profile
|
|
5805
|
+
profile_data = general_match
|
|
5774
5806
|
elif conversation_id:
|
|
5775
5807
|
conv_profile = conv.get("profileId") if conv else None
|
|
5776
5808
|
if conv_profile:
|
|
5777
5809
|
match = get_general_profile_by_name(conv_profile) or get_general_profile(conv_profile)
|
|
5778
5810
|
if not match:
|
|
5779
|
-
parser.error(f"no existe el perfil
|
|
5811
|
+
parser.error(f"no existe el perfil '{conv_profile}' en el servidor; créalo o indica uno con --profile")
|
|
5780
5812
|
profile_name = match["name"]
|
|
5813
|
+
profile_data = match
|
|
5781
5814
|
else:
|
|
5782
5815
|
default_match = get_general_profile_by_name(DEFAULT_RUN_PROFILE)
|
|
5783
5816
|
if default_match is None:
|
|
5784
|
-
parser.error(f"no existe el perfil
|
|
5817
|
+
parser.error(f"no existe el perfil por defecto '{DEFAULT_RUN_PROFILE}' en el servidor; créalo o indica uno con --profile")
|
|
5785
5818
|
profile_name = default_match["name"]
|
|
5819
|
+
profile_data = default_match
|
|
5786
5820
|
else:
|
|
5787
5821
|
default_match = get_general_profile_by_name(DEFAULT_RUN_PROFILE)
|
|
5788
5822
|
if default_match is None:
|
|
5789
|
-
parser.error(f"no existe el perfil
|
|
5823
|
+
parser.error(f"no existe el perfil por defecto '{DEFAULT_RUN_PROFILE}' en el servidor; créalo o indica uno con --profile")
|
|
5790
5824
|
profile_name = default_match["name"]
|
|
5825
|
+
profile_data = default_match
|
|
5791
5826
|
export_path = None
|
|
5792
5827
|
if args.export is not None:
|
|
5793
5828
|
export_path = Path(args.export).expanduser().absolute()
|
|
@@ -5795,7 +5830,9 @@ def run_session_from_args(parser: ZeroChatArgumentParser, args) -> RunSession |
|
|
|
5795
5830
|
parser.error(f"--export necesita una de estas extensiones: {', '.join(RUN_EXPORT_FORMATS)}")
|
|
5796
5831
|
if not export_path.parent.is_dir():
|
|
5797
5832
|
parser.error(f"--export: no existe el directorio {export_path.parent}")
|
|
5798
|
-
|
|
5833
|
+
if conversation_id:
|
|
5834
|
+
mark_conversation_server_run(conversation_id, profile_name)
|
|
5835
|
+
return RunSession(prompt, profile_name, export_path, args.keep_page, args.allow_dangerous_tools, conversation_id=conversation_id, profile_data=profile_data)
|
|
5799
5836
|
|
|
5800
5837
|
|
|
5801
5838
|
def redirect_log(args):
|
|
@@ -6008,9 +6045,9 @@ def main():
|
|
|
6008
6045
|
if getattr(args, "list_profiles", False):
|
|
6009
6046
|
profiles = list_general_profiles()
|
|
6010
6047
|
if not profiles:
|
|
6011
|
-
print("No hay perfiles de conexión
|
|
6048
|
+
print("No hay perfiles de conexión almacenados en el servidor local.")
|
|
6012
6049
|
else:
|
|
6013
|
-
print("Perfiles de conexión
|
|
6050
|
+
print("Perfiles de conexión del servidor local:")
|
|
6014
6051
|
for p in profiles:
|
|
6015
6052
|
settings = p.get("settings", {})
|
|
6016
6053
|
model = settings.get("model") or "sin modelo"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|