safentic 1.0.3__tar.gz → 1.0.4__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.
- {safentic-1.0.3/safentic.egg-info → safentic-1.0.4}/PKG-INFO +1 -1
- {safentic-1.0.3 → safentic-1.0.4}/safentic/__init__.py +1 -1
- {safentic-1.0.3 → safentic-1.0.4}/safentic/layer.py +16 -10
- {safentic-1.0.3 → safentic-1.0.4/safentic.egg-info}/PKG-INFO +1 -1
- {safentic-1.0.3 → safentic-1.0.4}/setup.py +1 -1
- {safentic-1.0.3 → safentic-1.0.4}/MANIFEST.in +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/README.md +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/requirements.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/LICENSE.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/config.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/engine.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/helper/__init__.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/helper/auth.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/logger/__init__.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/logger/audit.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/policies/.gitkeep +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/policies/__init__.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/policies/example_policy.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/policies/policy.yaml +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/policy.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/verifiers/__init__.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic/verifiers/sentence_verifier.py +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic.egg-info/SOURCES.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic.egg-info/dependency_links.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic.egg-info/requires.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/safentic.egg-info/top_level.txt +0 -0
- {safentic-1.0.3 → safentic-1.0.4}/setup.cfg +0 -0
@@ -6,23 +6,30 @@ class SafenticError(Exception):
|
|
6
6
|
"""Raised when Safentic blocks an action."""
|
7
7
|
pass
|
8
8
|
|
9
|
+
class InvalidAPIKeyError(Exception):
|
10
|
+
"""Raised when an invalid API key is used."""
|
11
|
+
pass
|
9
12
|
|
10
|
-
class SafetyLayer
|
13
|
+
class SafetyLayer:
|
11
14
|
"""
|
12
15
|
Safentic runtime enforcement wrapper for agent actions.
|
13
|
-
|
14
|
-
Example:
|
15
|
-
safety.protect("send_email", {"body": "..."})
|
16
|
-
# Raises SafenticError if blocked
|
16
|
+
Requires a valid API key to function.
|
17
17
|
"""
|
18
18
|
|
19
|
-
def __init__(self, api_key="", agent_id="", enforcer: PolicyEnforcer = None, raise_on_block: bool = True):
|
19
|
+
def __init__(self, api_key: str = "", agent_id: str = "", enforcer: PolicyEnforcer = None, raise_on_block: bool = True):
|
20
|
+
if not api_key:
|
21
|
+
raise InvalidAPIKeyError("Missing API key")
|
22
|
+
|
23
|
+
validation_response = validate_api_key(api_key)
|
24
|
+
if not validation_response or validation_response.get("status") != "valid":
|
25
|
+
raise InvalidAPIKeyError("Invalid or unauthorized API key")
|
26
|
+
|
27
|
+
self.api_key = api_key
|
20
28
|
self.agent_id = agent_id
|
21
29
|
self.raise_on_block = raise_on_block
|
22
30
|
self.logger = AuditLogger()
|
23
31
|
|
24
32
|
self.enforcer = enforcer or PolicyEnforcer()
|
25
|
-
self.api_key = validate_api_key(api_key)
|
26
33
|
self.enforcer.reset(agent_id)
|
27
34
|
|
28
35
|
def protect(self, tool_name: str, tool_args: dict) -> dict:
|
@@ -30,7 +37,7 @@ class SafetyLayer():
|
|
30
37
|
Checks whether a tool action is allowed.
|
31
38
|
Raises SafenticError if blocked (default), or returns result if raise_on_block=False.
|
32
39
|
"""
|
33
|
-
|
40
|
+
|
34
41
|
result = self.enforcer.enforce(self.agent_id, tool_name, tool_args)
|
35
42
|
|
36
43
|
# Log structured event
|
@@ -41,10 +48,9 @@ class SafetyLayer():
|
|
41
48
|
reason=result["reason"] if not result["allowed"] else None
|
42
49
|
)
|
43
50
|
|
44
|
-
# Raise or return based on outcome and config
|
45
51
|
if not result["allowed"]:
|
46
52
|
if self.raise_on_block:
|
47
53
|
raise SafenticError(result["reason"])
|
48
54
|
return result
|
49
55
|
|
50
|
-
return result
|
56
|
+
return result
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|