zerochat 10.22.0__tar.gz → 10.23.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.22.0
3
+ Version: 10.23.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.22.0"
7
+ version = "10.23.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.22.0
3
+ Version: 10.23.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
@@ -1560,7 +1560,7 @@ def dispatch_browser(method: str, params: dict) -> RpcOutcome:
1560
1560
 
1561
1561
 
1562
1562
 
1563
- SOURCE_BACKEND_VERSION = "10.22.0"
1563
+ SOURCE_BACKEND_VERSION = "10.23.0"
1564
1564
 
1565
1565
 
1566
1566
  def _read_source_version(filename: str) -> str | None:
@@ -2915,12 +2915,20 @@ def open_storage():
2915
2915
 
2916
2916
 
2917
2917
  def normalize_profile_id(name: str, given_id: str | None = None) -> str:
2918
- """Genera o normaliza un identificador único para el perfil general."""
2918
+ """Genera o normaliza un identificador único para el perfil."""
2919
2919
  if given_id and isinstance(given_id, str) and given_id.strip():
2920
2920
  clean = given_id.strip()
2921
2921
  return clean if clean.startswith("profile:") else f"profile:{clean}"
2922
- clean_name = urllib.parse.quote(name.strip())
2923
- return f"profile:general-{clean_name}"
2922
+ clean_name = urllib.parse.quote(name.strip(), safe="-_.!~*'()")
2923
+ return f"profile:{clean_name}"
2924
+
2925
+
2926
+ def _parse_optional_timestamp(value, field_name: str) -> int | None:
2927
+ if value is None:
2928
+ return None
2929
+ if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or value <= 0:
2930
+ raise ValueError(f"{field_name} debe ser una marca de tiempo positiva")
2931
+ return int(value)
2924
2932
 
2925
2933
 
2926
2934
  def validate_profile_payload(record: dict) -> tuple[str, str, str, dict, str | None]:
@@ -2956,7 +2964,7 @@ def validate_profile_payload(record: dict) -> tuple[str, str, str, dict, str | N
2956
2964
 
2957
2965
  def _row_to_profile(row: sqlite3.Row) -> dict:
2958
2966
  """Transforma una fila SQLite en el objeto de perfil del servidor, sin su API key: solo `hasApiKey`.
2959
- La clave la entrega get_general_profile_with_key a quien la usa (el runner o la importación explícita)."""
2967
+ La clave la entrega get_general_profile_with_key al runner o bajo demanda con zerochat/profiles/reveal."""
2960
2968
  try:
2961
2969
  settings = json.loads(row["settings_json"])
2962
2970
  except (json.JSONDecodeError, TypeError):
@@ -3022,9 +3030,11 @@ def get_general_profile_by_name(name: str) -> dict | None:
3022
3030
 
3023
3031
 
3024
3032
  def save_general_profile(record: dict) -> dict:
3025
- """Guarda (crea o actualiza) un perfil de conexión del servidor en SQLite."""
3033
+ """Guarda (crea o actualiza) un perfil en SQLite conservando el updatedAt de origen si se indica."""
3026
3034
  profile_id, name, description, settings, api_key = validate_profile_payload(record)
3027
3035
  now = int(time.time() * 1000)
3036
+ updated_at = _parse_optional_timestamp(record.get("updatedAt"), "updatedAt") or now
3037
+ created_at = _parse_optional_timestamp(record.get("createdAt"), "createdAt") or updated_at
3028
3038
 
3029
3039
  with open_storage() as conn:
3030
3040
  existing = conn.execute("SELECT * FROM profiles WHERE id = ?;", (profile_id,)).fetchone()
@@ -3050,12 +3060,12 @@ def save_general_profile(record: dict) -> dict:
3050
3060
  UPDATE profiles
3051
3061
  SET name = ?, description = ?, settings_json = ?, api_key = ?, version = ?, updated_at = ?
3052
3062
  WHERE id = ?;
3053
- """, (name, description, json.dumps(settings), final_api_key, version, now, profile_id))
3063
+ """, (name, description, json.dumps(settings), final_api_key, version, updated_at, profile_id))
3054
3064
  else:
3055
3065
  conn.execute("""
3056
3066
  INSERT INTO profiles (id, name, description, settings_json, api_key, version, created_at, updated_at)
3057
3067
  VALUES (?, ?, ?, ?, ?, 1, ?, ?);
3058
- """, (profile_id, name, description, json.dumps(settings), obfuscate_secret(api_key or ""), now, now))
3068
+ """, (profile_id, name, description, json.dumps(settings), obfuscate_secret(api_key or ""), created_at, updated_at))
3059
3069
 
3060
3070
  conn.commit()
3061
3071
  saved_row = conn.execute("SELECT * FROM profiles WHERE id = ?;", (profile_id,)).fetchone()
@@ -3526,6 +3536,20 @@ def secret_names(prefix: str) -> set[str]:
3526
3536
  rows = conn.execute("SELECT name FROM secrets WHERE substr(name, 1, ?) = ?;", (len(prefix), prefix)).fetchall()
3527
3537
  return {row["name"] for row in rows}
3528
3538
 
3539
+
3540
+ SERVER_ID_KEY = "system:server_id"
3541
+
3542
+
3543
+ def get_server_id() -> str:
3544
+ """Identificador único y persistente de este servidor en SQLite."""
3545
+ with _STORAGE_LOCK:
3546
+ existing = get_secret(SERVER_ID_KEY)
3547
+ if existing:
3548
+ return existing
3549
+ server_id = str(uuid.uuid4())
3550
+ save_secret(SERVER_ID_KEY, server_id)
3551
+ return server_id
3552
+
3529
3553
  # --- mcp.manager ---
3530
3554
  """Gestor de servicios MCP: descubrimiento en ~/zerochat/services, actualización desde el catálogo, preferencias,
3531
3555
  arranque y parada, y nombres públicos de sus herramientas."""
@@ -4722,8 +4746,8 @@ def _delete_profile(params: dict) -> RpcOutcome:
4722
4746
 
4723
4747
 
4724
4748
  def _reveal_profile(params: dict) -> RpcOutcome:
4725
- """El perfil con su API key, para copiarlo a la interfaz al pulsar el usuario Editar: el único método que devuelve
4726
- una clave guardada en el servidor a la interfaz (docs/M75-apikeys.md), y queda en el registro."""
4749
+ """El perfil con su API key bajo demanda cuando la interfaz ejecuta en el navegador o edita un perfil
4750
+ cuya clave solo está en el servidor (docs/M75-apikeys.md), y deja constancia en el registro."""
4727
4751
  profile_id = params.get("id")
4728
4752
  profile = get_general_profile_with_key(profile_id) if isinstance(profile_id, str) else None
4729
4753
  if profile is None:
@@ -7640,6 +7664,7 @@ def live_state(ctx: SecurityContext, focus_conversation_id: str | None = None) -
7640
7664
  """
7641
7665
  runs, focus_run = list_server_runs(focus_conversation_id)
7642
7666
  return {
7667
+ "serverId": get_server_id(),
7643
7668
  "cwd": str(ctx.workspace_dir),
7644
7669
  "jobs": [{**job.summary(), "last_line": job.last_line()} for job in JOBS.running(ctx.key)],
7645
7670
  "exit_on_close": EXIT_ON_CLOSE,
File without changes
File without changes
File without changes