veriact 0.1.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.
veriact/__init__.py ADDED
@@ -0,0 +1,32 @@
1
+ """Veriact : sachez ce que votre IA a vraiment fait."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from veriact._client import Veriact
6
+ from veriact._errors import (
7
+ APIConnectionError,
8
+ AuthenticationError,
9
+ InvalidRequestError,
10
+ NotFoundError,
11
+ QuotaExceededError,
12
+ RateLimitError,
13
+ VeriactError,
14
+ )
15
+ from veriact._types import Action, Check
16
+
17
+ # Anciens noms (avant le renommage du paquet en « veriact »).
18
+ AIProof = Veriact
19
+ AIProofError = VeriactError
20
+
21
+ __all__ = [
22
+ "APIConnectionError",
23
+ "Action",
24
+ "AuthenticationError",
25
+ "Check",
26
+ "InvalidRequestError",
27
+ "NotFoundError",
28
+ "QuotaExceededError",
29
+ "RateLimitError",
30
+ "Veriact",
31
+ "VeriactError",
32
+ ]
veriact/_client.py ADDED
@@ -0,0 +1,161 @@
1
+ import os
2
+ import time
3
+ from collections.abc import Iterator
4
+ from datetime import datetime
5
+ from typing import Any
6
+
7
+ import httpx
8
+
9
+ from veriact import __version__
10
+ from veriact._errors import APIConnectionError, RateLimitError, error_for
11
+ from veriact._types import Action
12
+
13
+ DEFAULT_BASE_URL = "https://api.veriact.io"
14
+
15
+
16
+ class Veriact:
17
+ """Client de l'API Veriact.
18
+
19
+ >>> client = Veriact() # lit VERIACT_API_KEY et VERIACT_BASE_URL
20
+ >>> action = client.verify(text="J'ai remboursé 50 € à Marie Dupont.")
21
+ >>> print(action.verdict_label)
22
+ """
23
+
24
+ def __init__(
25
+ self,
26
+ api_key: str | None = None,
27
+ *,
28
+ base_url: str | None = None,
29
+ timeout: float = 30.0,
30
+ max_retries: int = 2,
31
+ transport: httpx.BaseTransport | None = None,
32
+ ) -> None:
33
+ # AIPROOF_* : anciens noms, encore acceptés.
34
+ key = api_key or os.environ.get("VERIACT_API_KEY") or os.environ.get("AIPROOF_API_KEY")
35
+ if not key:
36
+ raise ValueError("Clé API manquante : passez api_key ou définissez VERIACT_API_KEY.")
37
+ self._max_retries = max_retries
38
+ self._http = httpx.Client(
39
+ base_url=(
40
+ base_url
41
+ or os.environ.get("VERIACT_BASE_URL")
42
+ or os.environ.get("AIPROOF_BASE_URL")
43
+ or DEFAULT_BASE_URL
44
+ ),
45
+ headers={
46
+ "Authorization": f"Bearer {key}",
47
+ "User-Agent": f"veriact-python/{__version__}",
48
+ },
49
+ timeout=timeout,
50
+ transport=transport,
51
+ )
52
+
53
+ # ------------------------------------------------------------------ bas niveau
54
+
55
+ def _request(self, method: str, path: str, **kwargs: Any) -> Any:
56
+ for attempt in range(self._max_retries + 1):
57
+ try:
58
+ response = self._http.request(method, path, **kwargs)
59
+ except httpx.HTTPError as exc:
60
+ if attempt < self._max_retries:
61
+ time.sleep(2**attempt)
62
+ continue
63
+ raise APIConnectionError("Le service Veriact est injoignable.") from exc
64
+ if response.status_code < 400:
65
+ return response.json()
66
+ payload = response.json() if response.content else None
67
+ error = error_for(response.status_code, payload)
68
+ retryable = response.status_code == 429 or response.status_code >= 500
69
+ if retryable and attempt < self._max_retries:
70
+ wait = error.retry_after if isinstance(error, RateLimitError) else None
71
+ time.sleep(min(wait or 2**attempt, 30))
72
+ continue
73
+ raise error
74
+ raise AssertionError("inaccessible") # pragma: no cover
75
+
76
+ # ------------------------------------------------------------------ actions
77
+
78
+ def submit(
79
+ self,
80
+ *,
81
+ text: str | None = None,
82
+ claim: dict[str, Any] | None = None,
83
+ tool_log: dict[str, Any] | None = None,
84
+ agent: str | None = None,
85
+ connector_id: str | None = None,
86
+ idempotency_key: str | None = None,
87
+ ) -> Action:
88
+ """Envoie une action à vérifier. Donnez UNE source : text, claim ou tool_log."""
89
+ sources = {"text": text, "structured": claim, "tool_log": tool_log}
90
+ given = [k for k, v in sources.items() if v is not None]
91
+ if len(given) != 1:
92
+ raise ValueError("Donnez exactement une source : text, claim ou tool_log.")
93
+ body: dict[str, Any] = {"source_type": given[0]}
94
+ body[
95
+ "text" if given[0] == "text" else "claim" if given[0] == "structured" else "tool_log"
96
+ ] = sources[given[0]]
97
+ for name, value in (
98
+ ("agent", agent),
99
+ ("connector_id", connector_id),
100
+ ("idempotency_key", idempotency_key),
101
+ ):
102
+ if value is not None:
103
+ body[name] = value
104
+ return Action.from_json(self._request("POST", "/v1/actions", json=body))
105
+
106
+ def get(self, action_id: str) -> Action:
107
+ return Action.from_json(self._request("GET", f"/v1/actions/{action_id}"))
108
+
109
+ def reverify(self, action_id: str) -> Action:
110
+ return Action.from_json(self._request("POST", f"/v1/actions/{action_id}/reverify"))
111
+
112
+ def wait(self, action_id: str, *, timeout: float = 60.0, interval: float = 1.0) -> Action:
113
+ """Attend la première vérification. Au-delà du délai, renvoie l'action « En attente »."""
114
+ deadline = time.monotonic() + timeout
115
+ action = self.get(action_id)
116
+ while action.status != "checked" and time.monotonic() < deadline:
117
+ time.sleep(interval)
118
+ action = self.get(action_id)
119
+ return action
120
+
121
+ def verify(self, *, timeout: float = 60.0, **kwargs: Any) -> Action:
122
+ """Envoie une action et attend son verdict (raccourci de submit + wait)."""
123
+ action = self.submit(**kwargs)
124
+ return (
125
+ action if action.status == "checked" else self.wait(action.action_id, timeout=timeout)
126
+ )
127
+
128
+ def list(
129
+ self,
130
+ *,
131
+ agent: str | None = None,
132
+ verdict: str | None = None,
133
+ since: datetime | None = None,
134
+ until: datetime | None = None,
135
+ page_size: int = 50,
136
+ ) -> Iterator[Action]:
137
+ """Parcourt les actions, de la plus récente à la plus ancienne (pagination incluse)."""
138
+ params: dict[str, Any] = {"limit": page_size}
139
+ for name, value in (("agent", agent), ("verdict", verdict)):
140
+ if value:
141
+ params[name] = value
142
+ if since:
143
+ params["since"] = since.isoformat()
144
+ if until:
145
+ params["until"] = until.isoformat()
146
+ while True:
147
+ page = self._request("GET", "/v1/actions", params=params)
148
+ for item in page["data"]:
149
+ yield Action.from_json(item)
150
+ if not page.get("next_cursor"):
151
+ return
152
+ params["cursor"] = page["next_cursor"]
153
+
154
+ def close(self) -> None:
155
+ self._http.close()
156
+
157
+ def __enter__(self) -> "Veriact":
158
+ return self
159
+
160
+ def __exit__(self, *_: object) -> None:
161
+ self.close()
veriact/_errors.py ADDED
@@ -0,0 +1,69 @@
1
+ from typing import Any
2
+
3
+
4
+ class VeriactError(Exception):
5
+ """Erreur renvoyée par l'API Veriact (format {code, message, details})."""
6
+
7
+ def __init__(
8
+ self,
9
+ message: str,
10
+ *,
11
+ status: int | None = None,
12
+ code: str | None = None,
13
+ details: Any = None,
14
+ ) -> None:
15
+ super().__init__(message)
16
+ self.message = message
17
+ self.status = status
18
+ self.code = code
19
+ self.details = details
20
+
21
+ def __str__(self) -> str:
22
+ prefix = f"[{self.status} {self.code}] " if self.status else ""
23
+ return prefix + self.message
24
+
25
+
26
+ class AuthenticationError(VeriactError):
27
+ """Clé API manquante, invalide ou révoquée (401)."""
28
+
29
+
30
+ class QuotaExceededError(VeriactError):
31
+ """Quota de l'offre atteint (402). Voir details["upgrade_url"]."""
32
+
33
+
34
+ class NotFoundError(VeriactError):
35
+ """Action ou connecteur introuvable (404)."""
36
+
37
+
38
+ class InvalidRequestError(VeriactError):
39
+ """Requête invalide (422). Voir details pour les champs concernés."""
40
+
41
+
42
+ class RateLimitError(VeriactError):
43
+ """Trop de requêtes (429)."""
44
+
45
+ @property
46
+ def retry_after(self) -> int | None:
47
+ if isinstance(self.details, dict) and "retry_after" in self.details:
48
+ return int(self.details["retry_after"])
49
+ return None
50
+
51
+
52
+ class APIConnectionError(VeriactError):
53
+ """Le service Veriact est injoignable."""
54
+
55
+
56
+ _BY_STATUS: dict[int, type[VeriactError]] = {
57
+ 401: AuthenticationError,
58
+ 402: QuotaExceededError,
59
+ 404: NotFoundError,
60
+ 422: InvalidRequestError,
61
+ 429: RateLimitError,
62
+ }
63
+
64
+
65
+ def error_for(status: int, payload: Any) -> VeriactError:
66
+ error = payload.get("error", {}) if isinstance(payload, dict) else {}
67
+ message = error.get("message") or f"Erreur HTTP {status}."
68
+ cls = _BY_STATUS.get(status, VeriactError)
69
+ return cls(message, status=status, code=error.get("code"), details=error.get("details"))
veriact/_types.py ADDED
@@ -0,0 +1,68 @@
1
+ from dataclasses import dataclass, field
2
+ from datetime import datetime
3
+ from typing import Any, Literal
4
+
5
+ Verdict = Literal["verified", "mismatch", "not_found", "pending"]
6
+
7
+ VERDICT_LABELS: dict[str, str] = {
8
+ "verified": "Vérifié",
9
+ "mismatch": "Écart",
10
+ "not_found": "Introuvable",
11
+ "pending": "En attente",
12
+ }
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class Check:
17
+ name: str
18
+ label: str
19
+ status: Literal["passed", "failed", "skipped"]
20
+ explanation: str
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class Action:
25
+ """Une action vérifiée (ou en cours de vérification) et sa preuve."""
26
+
27
+ action_id: str
28
+ status: Literal["queued", "checked"]
29
+ verdict: Verdict
30
+ summary: str | None
31
+ checks: list[Check]
32
+ evidence: dict[str, Any] | None
33
+ checked_at: datetime | None
34
+ agent: str | None
35
+ created_at: datetime
36
+ raw: dict[str, Any] = field(repr=False, compare=False)
37
+
38
+ @property
39
+ def verdict_label(self) -> str:
40
+ """Libellé français du verdict : Vérifié, Écart, Introuvable, En attente."""
41
+ return VERDICT_LABELS[self.verdict]
42
+
43
+ @property
44
+ def is_verified(self) -> bool:
45
+ return self.verdict == "verified"
46
+
47
+ @classmethod
48
+ def from_json(cls, data: dict[str, Any]) -> "Action":
49
+ def stamp(value: str | None) -> datetime | None:
50
+ return datetime.fromisoformat(value.replace("Z", "+00:00")) if value else None
51
+
52
+ created = stamp(data["created_at"])
53
+ assert created is not None # noqa: S101 - toujours fourni par l'API
54
+ return cls(
55
+ action_id=data["action_id"],
56
+ status=data["status"],
57
+ verdict=data["verdict"],
58
+ summary=data.get("summary"),
59
+ checks=[
60
+ Check(c["name"], c["label"], c["status"], c["explanation"])
61
+ for c in data.get("checks", [])
62
+ ],
63
+ evidence=data.get("evidence"),
64
+ checked_at=stamp(data.get("checked_at")),
65
+ agent=data.get("agent"),
66
+ created_at=created,
67
+ raw=data,
68
+ )
veriact/py.typed ADDED
File without changes
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.5
2
+ Name: veriact
3
+ Version: 0.1.0
4
+ Summary: SDK Python de Veriact : sachez ce que votre IA a vraiment fait.
5
+ Project-URL: Homepage, https://veriact.io
6
+ Project-URL: Documentation, https://app.veriact.io/cles-api
7
+ Author-email: Veriact <contact@veriact.io>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: AI agents,HubSpot,MCP,Salesforce,Stripe,agents IA,verification
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Natural Language :: French
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: httpx>=0.27
21
+ Description-Content-Type: text/markdown
22
+
23
+ # SDK Python Veriact
24
+
25
+ Sachez ce que votre IA a vraiment fait : envoyez l'action annoncée par votre agent,
26
+ Veriact la vérifie dans votre logiciel (lecture seule) et rend un verdict avec la preuve.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install veriact
32
+ ```
33
+
34
+ Créez une clé dans le tableau de bord (**Clés API**), puis :
35
+
36
+ ```bash
37
+ export VERIACT_API_KEY=aip_...
38
+ # Facultatif : https://api.veriact.io par défaut
39
+ # export VERIACT_BASE_URL=https://api.veriact.io
40
+ ```
41
+
42
+ ## En 5 lignes
43
+
44
+ ```python
45
+ from veriact import Veriact
46
+
47
+ client = Veriact()
48
+ action = client.verify(text="J'ai remboursé 50 € à Marie Dupont.")
49
+ print(action.verdict_label, "·", action.summary)
50
+ ```
51
+
52
+ `verify()` envoie l'action puis attend la première vérification (60 s par défaut).
53
+ Si le délai est dépassé, l'action est renvoyée « En attente » : relisez-la plus tard avec
54
+ `client.get(action.action_id)`.
55
+
56
+ ## Les trois façons d'envoyer une action
57
+
58
+ ```python
59
+ # 1. Log d'appel d'outil : le plus fiable
60
+ client.submit(
61
+ tool_log={
62
+ "tool": "stripe.refunds.create",
63
+ "input": {"amount": 5000, "currency": "eur"},
64
+ "output": {"id": "re_123"},
65
+ }
66
+ )
67
+
68
+ # 2. Claim structurée
69
+ client.submit(
70
+ claim={
71
+ "action_type": "refund_created",
72
+ "amount": "50",
73
+ "currency": "EUR",
74
+ "target": {"email": "marie.dupont@exemple.fr"},
75
+ }
76
+ )
77
+
78
+ # 3. Texte libre de l'IA (analysé par Veriact, jamais exécuté)
79
+ client.submit(text="J'ai remboursé 50 € à Marie Dupont.", agent="Agent support")
80
+ ```
81
+
82
+ Renvoyer la même action (ou passer `idempotency_key=`) ne la compte pas deux fois.
83
+
84
+ ## Verdicts
85
+
86
+ | Valeur | Libellé | Sens |
87
+ |---|---|---|
88
+ | `verified` | Vérifié | L'action a eu lieu, avec les bonnes valeurs |
89
+ | `mismatch` | Écart | Trouvée, mais une valeur ou le destinataire diffère |
90
+ | `not_found` | Introuvable | Aucune trace dans le logiciel |
91
+ | `pending` | En attente | Vérification pas terminée, ou claim incomplète |
92
+
93
+ ## Erreurs
94
+
95
+ Toutes héritent de `VeriactError` (`status`, `code`, `message` en français, `details`) :
96
+ `AuthenticationError` (401), `QuotaExceededError` (402, avec `details["upgrade_url"]`),
97
+ `NotFoundError` (404), `InvalidRequestError` (422), `RateLimitError` (429, `retry_after`),
98
+ `APIConnectionError`. Les 429 et erreurs serveur sont réessayées automatiquement.
99
+
100
+ ## Sans code : serveur MCP
101
+
102
+ Vos agents IA (Claude, ChatGPT, Copilot Studio, n8n, Cursor, OpenAI Agents SDK, LangChain…)
103
+ peuvent aussi vérifier eux-mêmes leurs actions grâce au serveur MCP de Veriact :
104
+ `https://api.veriact.io/mcp`, avec la même clé API. La configuration prête à copier se trouve
105
+ dans le tableau de bord, page **Clés API**.
106
+
107
+ ## Licence
108
+
109
+ MIT
@@ -0,0 +1,9 @@
1
+ veriact/__init__.py,sha256=PLG8H3SJPT60IKf43Gueg3Sd6yAoweq5KvFlw6-IdZE,681
2
+ veriact/_client.py,sha256=5Z7zAQOYIgUtTkTWhgwOn17yw4N_pqxGqfAksRctFrE,6157
3
+ veriact/_errors.py,sha256=6au3pzax6jdc9CPUR2xC88FgkaiM5Hlu5p7xFubX8_s,1917
4
+ veriact/_types.py,sha256=VlKirjXgjnlobhjEs3mx5QIKMWy5DrtM93D1S5kWU5I,2040
5
+ veriact/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ veriact-0.1.0.dist-info/METADATA,sha256=EJNmGRfZY2ShHjYEWaNoN8ntpf1iKprszY0cSXAopVs,3509
7
+ veriact-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
8
+ veriact-0.1.0.dist-info/licenses/LICENSE,sha256=6zv1IJFSjIcDDlHnL-6kfu9brW920Wt-doMIVFayR7Q,1064
9
+ veriact-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Veriact
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.