ragfly-cli 1.16.0__py3-none-any.whl

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.
ragfly_cli/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "1.16.0"
ragfly_cli/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Permite `python -m ragfly_cli`."""
2
+ from ragfly_cli.cli import app
3
+
4
+ if __name__ == "__main__":
5
+ app()
ragfly_cli/_http.py ADDED
@@ -0,0 +1,67 @@
1
+ """
2
+ Helpers HTTP comunes para todo el cliente.
3
+
4
+ `default_headers()` — Headers que TODA request al backend cloud debe llevar:
5
+ - `Authorization: Bearer <token>` (opcional; solo si token presente)
6
+ - `Content-Type: application/json` (opcional, para writes)
7
+ - `X-Client-Version: <__version__>` (siempre — el backend loggea y, en el
8
+ futuro, puede rechazar versiones incompatibles si ENFORCE_CLIENT_VERSION=true)
9
+
10
+ Para usar:
11
+
12
+ from ragfly_cli._http import default_headers
13
+ headers = default_headers(token=jwt, content_type=True)
14
+ httpx.post(url, headers=headers, json=...)
15
+
16
+ Notas:
17
+ - Si tu request va a un servicio que NO es el backend cloud (ej: LLM externo
18
+ como Anthropic/Google/Ollama), NO uses esta función — usa los headers que
19
+ pida el proveedor.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ from typing import Optional
25
+
26
+
27
+ def default_headers(
28
+ *,
29
+ token: Optional[str] = None,
30
+ content_type: bool = False,
31
+ grupo_override: Optional[str] = None,
32
+ ) -> dict[str, str]:
33
+ """Construye los headers estándar para una request al backend cloud.
34
+
35
+ Args:
36
+ token: JWT (sin "Bearer " prefix). Si None, no agrega Authorization.
37
+ content_type: Si True, agrega Content-Type: application/json (writes).
38
+ grupo_override: Override explícito del grupo activo. Si None, se lee
39
+ de `ClienteConfig.codigo_grupo` (si está seteado).
40
+
41
+ Returns:
42
+ dict de headers listo para pasar a httpx.
43
+
44
+ El header `X-Override-Grupo` se envía cuando hay grupo activo configurado
45
+ o explícito. El backend lo respeta como override de sesión (mismo patrón
46
+ que el dropdown de grupo del frontend web).
47
+ """
48
+ from ragfly_cli import __version__ as _client_version
49
+
50
+ headers: dict[str, str] = {"X-Client-Version": _client_version}
51
+ if token:
52
+ headers["Authorization"] = f"Bearer {token}"
53
+ if content_type:
54
+ headers["Content-Type"] = "application/json"
55
+
56
+ # Resolver grupo activo: explícito > config
57
+ grupo = grupo_override
58
+ if grupo is None:
59
+ try:
60
+ from .config import get_config
61
+ grupo = get_config().codigo_grupo or None
62
+ except Exception:
63
+ grupo = None
64
+ if grupo:
65
+ headers["X-Override-Grupo"] = grupo
66
+
67
+ return headers