veriact 0.1.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.
- veriact-0.1.0/.gitignore +33 -0
- veriact-0.1.0/LICENSE +21 -0
- veriact-0.1.0/PKG-INFO +109 -0
- veriact-0.1.0/README.md +87 -0
- veriact-0.1.0/examples/verifier_une_action.py +5 -0
- veriact-0.1.0/pyproject.toml +53 -0
- veriact-0.1.0/src/veriact/__init__.py +32 -0
- veriact-0.1.0/src/veriact/_client.py +161 -0
- veriact-0.1.0/src/veriact/_errors.py +69 -0
- veriact-0.1.0/src/veriact/_types.py +68 -0
- veriact-0.1.0/src/veriact/py.typed +0 -0
- veriact-0.1.0/tests/test_client.py +144 -0
- veriact-0.1.0/uv.lock +561 -0
veriact-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Secrets
|
|
2
|
+
.env
|
|
3
|
+
.env.*
|
|
4
|
+
!.env.example
|
|
5
|
+
|
|
6
|
+
# Python
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[cod]
|
|
9
|
+
.venv/
|
|
10
|
+
.pytest_cache/
|
|
11
|
+
.mypy_cache/
|
|
12
|
+
.ruff_cache/
|
|
13
|
+
.coverage
|
|
14
|
+
htmlcov/
|
|
15
|
+
|
|
16
|
+
# Node
|
|
17
|
+
node_modules/
|
|
18
|
+
.next/
|
|
19
|
+
dist/
|
|
20
|
+
.astro/
|
|
21
|
+
coverage/
|
|
22
|
+
*.tsbuildinfo
|
|
23
|
+
next-env.d.ts
|
|
24
|
+
|
|
25
|
+
# Supabase local
|
|
26
|
+
supabase/.temp/
|
|
27
|
+
supabase/.branches/
|
|
28
|
+
|
|
29
|
+
# OS / IDE
|
|
30
|
+
.DS_Store
|
|
31
|
+
Thumbs.db
|
|
32
|
+
.vscode/
|
|
33
|
+
.idea/
|
veriact-0.1.0/LICENSE
ADDED
|
@@ -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.
|
veriact-0.1.0/PKG-INFO
ADDED
|
@@ -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
|
veriact-0.1.0/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# SDK Python Veriact
|
|
2
|
+
|
|
3
|
+
Sachez ce que votre IA a vraiment fait : envoyez l'action annoncée par votre agent,
|
|
4
|
+
Veriact la vérifie dans votre logiciel (lecture seule) et rend un verdict avec la preuve.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install veriact
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Créez une clé dans le tableau de bord (**Clés API**), puis :
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
export VERIACT_API_KEY=aip_...
|
|
16
|
+
# Facultatif : https://api.veriact.io par défaut
|
|
17
|
+
# export VERIACT_BASE_URL=https://api.veriact.io
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## En 5 lignes
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from veriact import Veriact
|
|
24
|
+
|
|
25
|
+
client = Veriact()
|
|
26
|
+
action = client.verify(text="J'ai remboursé 50 € à Marie Dupont.")
|
|
27
|
+
print(action.verdict_label, "·", action.summary)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`verify()` envoie l'action puis attend la première vérification (60 s par défaut).
|
|
31
|
+
Si le délai est dépassé, l'action est renvoyée « En attente » : relisez-la plus tard avec
|
|
32
|
+
`client.get(action.action_id)`.
|
|
33
|
+
|
|
34
|
+
## Les trois façons d'envoyer une action
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
# 1. Log d'appel d'outil : le plus fiable
|
|
38
|
+
client.submit(
|
|
39
|
+
tool_log={
|
|
40
|
+
"tool": "stripe.refunds.create",
|
|
41
|
+
"input": {"amount": 5000, "currency": "eur"},
|
|
42
|
+
"output": {"id": "re_123"},
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# 2. Claim structurée
|
|
47
|
+
client.submit(
|
|
48
|
+
claim={
|
|
49
|
+
"action_type": "refund_created",
|
|
50
|
+
"amount": "50",
|
|
51
|
+
"currency": "EUR",
|
|
52
|
+
"target": {"email": "marie.dupont@exemple.fr"},
|
|
53
|
+
}
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# 3. Texte libre de l'IA (analysé par Veriact, jamais exécuté)
|
|
57
|
+
client.submit(text="J'ai remboursé 50 € à Marie Dupont.", agent="Agent support")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Renvoyer la même action (ou passer `idempotency_key=`) ne la compte pas deux fois.
|
|
61
|
+
|
|
62
|
+
## Verdicts
|
|
63
|
+
|
|
64
|
+
| Valeur | Libellé | Sens |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `verified` | Vérifié | L'action a eu lieu, avec les bonnes valeurs |
|
|
67
|
+
| `mismatch` | Écart | Trouvée, mais une valeur ou le destinataire diffère |
|
|
68
|
+
| `not_found` | Introuvable | Aucune trace dans le logiciel |
|
|
69
|
+
| `pending` | En attente | Vérification pas terminée, ou claim incomplète |
|
|
70
|
+
|
|
71
|
+
## Erreurs
|
|
72
|
+
|
|
73
|
+
Toutes héritent de `VeriactError` (`status`, `code`, `message` en français, `details`) :
|
|
74
|
+
`AuthenticationError` (401), `QuotaExceededError` (402, avec `details["upgrade_url"]`),
|
|
75
|
+
`NotFoundError` (404), `InvalidRequestError` (422), `RateLimitError` (429, `retry_after`),
|
|
76
|
+
`APIConnectionError`. Les 429 et erreurs serveur sont réessayées automatiquement.
|
|
77
|
+
|
|
78
|
+
## Sans code : serveur MCP
|
|
79
|
+
|
|
80
|
+
Vos agents IA (Claude, ChatGPT, Copilot Studio, n8n, Cursor, OpenAI Agents SDK, LangChain…)
|
|
81
|
+
peuvent aussi vérifier eux-mêmes leurs actions grâce au serveur MCP de Veriact :
|
|
82
|
+
`https://api.veriact.io/mcp`, avec la même clé API. La configuration prête à copier se trouve
|
|
83
|
+
dans le tableau de bord, page **Clés API**.
|
|
84
|
+
|
|
85
|
+
## Licence
|
|
86
|
+
|
|
87
|
+
MIT
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "veriact"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "SDK Python de Veriact : sachez ce que votre IA a vraiment fait."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = ["httpx>=0.27"]
|
|
8
|
+
license = "MIT"
|
|
9
|
+
license-files = ["LICENSE"]
|
|
10
|
+
authors = [{ name = "Veriact", email = "contact@veriact.io" }]
|
|
11
|
+
keywords = ["agents IA", "AI agents", "verification", "MCP", "Stripe", "HubSpot", "Salesforce"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 4 - Beta",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Natural Language :: French",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Topic :: Software Development :: Libraries",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://veriact.io"
|
|
25
|
+
Documentation = "https://app.veriact.io/cles-api"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling>=1.25"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.targets.wheel]
|
|
32
|
+
packages = ["src/veriact"]
|
|
33
|
+
|
|
34
|
+
[dependency-groups]
|
|
35
|
+
dev = ["pytest>=8.3", "ruff>=0.6", "mypy>=1.11"]
|
|
36
|
+
|
|
37
|
+
[tool.ruff]
|
|
38
|
+
line-length = 100
|
|
39
|
+
target-version = "py310"
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
select = ["E", "F", "W", "I", "B", "UP", "N", "S", "RUF", "SIM"]
|
|
43
|
+
ignore = ["RUF001", "RUF002", "RUF003"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint.per-file-ignores]
|
|
46
|
+
"tests/**" = ["S101", "S105", "S106"]
|
|
47
|
+
|
|
48
|
+
[tool.mypy]
|
|
49
|
+
strict = true
|
|
50
|
+
python_version = "3.10"
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
testpaths = ["tests"]
|
|
@@ -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
|
+
]
|
|
@@ -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()
|
|
@@ -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"))
|
|
@@ -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
|
+
)
|
|
File without changes
|