causal-logic-engine 2.21.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.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: causal-logic-engine
3
+ Version: 2.21.0
4
+ Summary: The official Python SDK for the multi-tenant Causal Logic Engine API.
5
+ Home-page: https://causal-logic-engine.onrender.com
6
+ Author: Ben Denholm
7
+ Author-email: bendenholm1@outlook.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: requests>=2.25.0
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ Sovereign Cognitive API Client.
@@ -0,0 +1,4 @@
1
+ from .client import CausalClient
2
+ from .exceptions import CausalAPIError, AuthenticationError, RateLimitError
3
+
4
+ __all__ = ["CausalClient", "CausalAPIError", "AuthenticationError", "RateLimitError"]
@@ -0,0 +1,97 @@
1
+ import os
2
+ import requests
3
+ from typing import List, Dict, Any, Optional
4
+ from .exceptions import CausalAPIError, AuthenticationError, RateLimitError
5
+
6
+ class AuditResponse:
7
+ """Wraps the strict JSON schema response from the Causal Engine."""
8
+ def __init__(self, data: Dict[str, Any]):
9
+ self.anomaly_detected: bool = data.get("anomaly_detected", False)
10
+ self.issue_summary: str = data.get("issue_summary", "")
11
+ self.severity_level: str = data.get("severity_level", "NONE")
12
+ self.remedy_steps: List[str] = data.get("remedy_steps", [])
13
+ self.sources: List[Dict[str, Any]] = data.get("sources", [])
14
+ self.latency_ms: int = data.get("latency_ms", 0)
15
+
16
+ def __repr__(self):
17
+ return f"<CausalAudit severity={self.severity_level} anomaly={self.anomaly_detected}>"
18
+
19
+ class CausalClient:
20
+ def __init__(self, api_key: str, base_url: str = "https://causal-logic-engine.onrender.com"):
21
+ """Initializes the Sovereign API Client wrapper."""
22
+ self.api_key = api_key.strip()
23
+ self.base_url = base_url.rstrip("/")
24
+
25
+ self.headers = {
26
+ "Content-Type": "application/json",
27
+ "X-Causal-Engine-Key": self.api_key
28
+ }
29
+
30
+ def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
31
+ """Evaluates status codes and handles exceptions professionally."""
32
+ if response.status_code in [200, 201]:
33
+ return response.json()
34
+
35
+ try:
36
+ error_data = response.json()
37
+ detail = error_data.get("detail", "An unhandled API error occurred.")
38
+ except Exception:
39
+ detail = response.text or "An unhandled API error occurred."
40
+
41
+ if response.status_code == 401:
42
+ raise AuthenticationError("Authentication Failed: Invalid or expired API Key.", status_code=401)
43
+ elif response.status_code == 429:
44
+ raise RateLimitError("Quota Exceeded: Your tenant sliding window limit has been hit.", status_code=429)
45
+ else:
46
+ raise CausalAPIError(f"API Error: {detail}", status_code=response.status_code)
47
+
48
+ def query(self, user_query: str, persona_override: Optional[str] = None) -> AuditResponse:
49
+ """
50
+ Executes a headless cognitive query against your isolated database partition.
51
+ Returns a structured AuditResponse object.
52
+ """
53
+ url = f"{self.base_url}/api/document/v1/query"
54
+ payload = {
55
+ "user_query": user_query,
56
+ "persona_override": persona_override
57
+ }
58
+
59
+ response = requests.post(url, headers=self.headers, json=payload)
60
+ json_data = self._handle_response(response)
61
+ return AuditResponse(json_data)
62
+
63
+ def upload_file(self, file_path: str) -> Dict[str, Any]:
64
+ """
65
+ Uploads and indexes a local file (.pdf, .xlsx, .docx, .txt)
66
+ directly into your secure database partition.
67
+ """
68
+ url = f"{self.base_url}/api/document/upload"
69
+ filename = os.path.basename(file_path)
70
+
71
+ with open(file_path, "rb") as f:
72
+ files = {"file": (filename, f, "application/octet-stream")}
73
+ multipart_headers = {"X-Causal-Engine-Key": self.api_key}
74
+ response = requests.post(url, headers=multipart_headers, files=files)
75
+
76
+ return self._handle_response(response)
77
+
78
+ def list_files(self) -> List[Dict[str, Any]]:
79
+ """Lists all active files in your secure workspace registry."""
80
+ url = f"{self.base_url}/api/document/list"
81
+ response = requests.get(url, headers=self.headers)
82
+ data = self._handle_response(response)
83
+ return data.get("documents", [])
84
+
85
+ def execute_mcp_tool(self, tool_name: str, parameters: Dict[str, Any]) -> Dict[str, Any]:
86
+ """
87
+ Model Context Protocol (MCP) Gateway.
88
+ Allows external AI agents (Cursor, Claude) to programmatically invoke UCOS tools.
89
+ """
90
+ url = f"{self.base_url}/api/mcp/execute"
91
+ payload = {
92
+ "tool_name": tool_name,
93
+ "parameters": parameters
94
+ }
95
+
96
+ response = requests.post(url, headers=self.headers, json=payload)
97
+ return self._handle_response(response)
@@ -0,0 +1,14 @@
1
+ class CausalAPIError(Exception):
2
+ """Base exception for all Causal Engine API faults."""
3
+ def __init__(self, message: str, status_code: int = None, details: str = None):
4
+ super().__init__(message)
5
+ self.status_code = status_code
6
+ self.details = details
7
+
8
+ class AuthenticationError(CausalAPIError):
9
+ """Raised when the X-Causal-Engine-Key is invalid or expired."""
10
+ pass
11
+
12
+ class RateLimitError(CausalAPIError):
13
+ """Raised when the workspace exceeds its dynamic tier sliding window limit."""
14
+ pass
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: causal-logic-engine
3
+ Version: 2.21.0
4
+ Summary: The official Python SDK for the multi-tenant Causal Logic Engine API.
5
+ Home-page: https://causal-logic-engine.onrender.com
6
+ Author: Ben Denholm
7
+ Author-email: bendenholm1@outlook.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: requests>=2.25.0
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ Sovereign Cognitive API Client.
@@ -0,0 +1,9 @@
1
+ setup.py
2
+ causal_engine/__init__.py
3
+ causal_engine/client.py
4
+ causal_engine/exceptions.py
5
+ causal_logic_engine.egg-info/PKG-INFO
6
+ causal_logic_engine.egg-info/SOURCES.txt
7
+ causal_logic_engine.egg-info/dependency_links.txt
8
+ causal_logic_engine.egg-info/requires.txt
9
+ causal_logic_engine.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,24 @@
1
+ # causal-engine-sdk/setup.py
2
+ import os
3
+ from setuptools import setup, find_packages
4
+
5
+ setup(
6
+ name="causal-logic-engine", # Changed to be unique
7
+ version="2.21.0", # 🎯 UPGRADED TO UCOS CURRENT ARCHITECTURE
8
+ author="Ben Denholm",
9
+ author_email="bendenholm1@outlook.com",
10
+ description="The official Python SDK for the multi-tenant Causal Logic Engine API.",
11
+ long_description=open("README.md").read() if os.path.exists("README.md") else "Sovereign Cognitive API Client.",
12
+ long_description_content_type="text/markdown",
13
+ url="https://causal-logic-engine.onrender.com",
14
+ packages=find_packages(),
15
+ install_requires=[
16
+ "requests>=2.25.0",
17
+ ],
18
+ classifiers=[
19
+ "Programming Language :: Python :: 3",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Operating System :: OS Independent",
22
+ ],
23
+ python_requires=">=3.8",
24
+ )