gleitzeit 0.0.5__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.
Files changed (78) hide show
  1. gleitzeit/__init__.py +19 -0
  2. gleitzeit/api/__init__.py +7 -0
  3. gleitzeit/api/client.py +242 -0
  4. gleitzeit/api/main.py +862 -0
  5. gleitzeit/api/requirements.txt +5 -0
  6. gleitzeit/api/run_server.py +22 -0
  7. gleitzeit/cli/__init__.py +8 -0
  8. gleitzeit/cli/commands/__init__.py +10 -0
  9. gleitzeit/cli/commands/dev.py +234 -0
  10. gleitzeit/cli/commands/status.py +95 -0
  11. gleitzeit/cli/commands/submit.py +141 -0
  12. gleitzeit/cli/config.py +349 -0
  13. gleitzeit/cli/gleitzeit_cli.py +1035 -0
  14. gleitzeit/cli/main.py +301 -0
  15. gleitzeit/cli/main_minimal.py +159 -0
  16. gleitzeit/cli/workflow.py +355 -0
  17. gleitzeit/client.py +1250 -0
  18. gleitzeit/common/__init__.py +20 -0
  19. gleitzeit/common/circuit_breaker.py +259 -0
  20. gleitzeit/common/health_monitor.py +372 -0
  21. gleitzeit/common/load_balancer.py +328 -0
  22. gleitzeit/common/metrics.py +261 -0
  23. gleitzeit/common/shutdown.py +107 -0
  24. gleitzeit/core/__init__.py +30 -0
  25. gleitzeit/core/batch_processor.py +399 -0
  26. gleitzeit/core/dependency_tracker.py +249 -0
  27. gleitzeit/core/error_formatter.py +324 -0
  28. gleitzeit/core/error_handler.py +376 -0
  29. gleitzeit/core/errors.py +643 -0
  30. gleitzeit/core/events.py +517 -0
  31. gleitzeit/core/execution_engine.py +1149 -0
  32. gleitzeit/core/jsonrpc.py +437 -0
  33. gleitzeit/core/models.py +444 -0
  34. gleitzeit/core/protocol.py +380 -0
  35. gleitzeit/core/retry_manager.py +268 -0
  36. gleitzeit/core/scheduler.py +273 -0
  37. gleitzeit/core/workflow_loader.py +379 -0
  38. gleitzeit/core/workflow_manager.py +677 -0
  39. gleitzeit/execution/__init__.py +3 -0
  40. gleitzeit/execution/docker_executor.py +683 -0
  41. gleitzeit/hub/__init__.py +26 -0
  42. gleitzeit/hub/base.py +615 -0
  43. gleitzeit/hub/configs.py +157 -0
  44. gleitzeit/hub/docker_hub.py +445 -0
  45. gleitzeit/hub/mcp_hub.py +672 -0
  46. gleitzeit/hub/ollama_hub.py +515 -0
  47. gleitzeit/hub/resource_manager.py +476 -0
  48. gleitzeit/integrations/__init__.py +1 -0
  49. gleitzeit/orchestration/__init__.py +3 -0
  50. gleitzeit/orchestration/ollama_pool.py +463 -0
  51. gleitzeit/persistence/__init__.py +1 -0
  52. gleitzeit/persistence/base.py +229 -0
  53. gleitzeit/persistence/factory.py +392 -0
  54. gleitzeit/persistence/redis_backend.py +518 -0
  55. gleitzeit/persistence/sqlite_backend.py +506 -0
  56. gleitzeit/persistence/unified_persistence.py +598 -0
  57. gleitzeit/persistence/unified_redis.py +1081 -0
  58. gleitzeit/persistence/unified_sql_backend.py +1255 -0
  59. gleitzeit/persistence/unified_sqlalchemy.py +1269 -0
  60. gleitzeit/protocols/__init__.py +9 -0
  61. gleitzeit/protocols/llm_protocol.py +405 -0
  62. gleitzeit/protocols/mcp_protocol.py +249 -0
  63. gleitzeit/protocols/python_protocol.py +122 -0
  64. gleitzeit/providers/__init__.py +23 -0
  65. gleitzeit/providers/base.py +656 -0
  66. gleitzeit/providers/mcp_hub_provider.py +269 -0
  67. gleitzeit/providers/ollama_provider.py +351 -0
  68. gleitzeit/providers/python_provider.py +367 -0
  69. gleitzeit/registry.py +520 -0
  70. gleitzeit/task_queue/__init__.py +8 -0
  71. gleitzeit/task_queue/dependency_resolver.py +428 -0
  72. gleitzeit/task_queue/task_queue.py +521 -0
  73. gleitzeit-0.0.5.dist-info/METADATA +750 -0
  74. gleitzeit-0.0.5.dist-info/RECORD +78 -0
  75. gleitzeit-0.0.5.dist-info/WHEEL +5 -0
  76. gleitzeit-0.0.5.dist-info/entry_points.txt +3 -0
  77. gleitzeit-0.0.5.dist-info/licenses/LICENSE +21 -0
  78. gleitzeit-0.0.5.dist-info/top_level.txt +1 -0
gleitzeit/__init__.py ADDED
@@ -0,0 +1,19 @@
1
+ """Gleitzeit - Protocol-based workflow orchestration system for LLM and task automation"""
2
+
3
+ __version__ = "0.0.5"
4
+
5
+ from gleitzeit.core.models import Task, Workflow, TaskResult, WorkflowExecution
6
+ from gleitzeit.core.execution_engine import ExecutionEngine
7
+ from gleitzeit.client import GleitzeitClient, ClientMode
8
+ from gleitzeit.client import GleitzeitClient as Client
9
+
10
+ __all__ = [
11
+ "Client",
12
+ "ClientMode",
13
+ "Task",
14
+ "Workflow",
15
+ "TaskResult",
16
+ "WorkflowExecution",
17
+ "ExecutionEngine",
18
+ "GleitzeitClient",
19
+ ]
@@ -0,0 +1,7 @@
1
+ """
2
+ Gleitzeit REST API module
3
+ """
4
+
5
+ from .main import app
6
+
7
+ __all__ = ["app"]
@@ -0,0 +1,242 @@
1
+ """
2
+ Gleitzeit API Client
3
+
4
+ Python client for interacting with the Gleitzeit REST API.
5
+ """
6
+
7
+ import asyncio
8
+ import json
9
+ from typing import Dict, Any, List, Optional
10
+ from pathlib import Path
11
+
12
+ import aiohttp
13
+ from pydantic import BaseModel
14
+
15
+
16
+ class GleitzeitAPIClient:
17
+ """Async client for Gleitzeit REST API"""
18
+
19
+ def __init__(self, base_url: str = "http://localhost:8000"):
20
+ self.base_url = base_url.rstrip("/")
21
+ self.session: Optional[aiohttp.ClientSession] = None
22
+
23
+ async def __aenter__(self):
24
+ self.session = aiohttp.ClientSession()
25
+ return self
26
+
27
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
28
+ if self.session:
29
+ await self.session.close()
30
+
31
+ async def _request(self, method: str, endpoint: str, **kwargs) -> Dict[str, Any]:
32
+ """Make HTTP request to API"""
33
+ if not self.session:
34
+ raise RuntimeError("Client session not initialized. Use 'async with' context manager.")
35
+
36
+ url = f"{self.base_url}{endpoint}"
37
+ async with self.session.request(method, url, **kwargs) as response:
38
+ if response.status >= 400:
39
+ error_text = await response.text()
40
+ raise Exception(f"API error ({response.status}): {error_text}")
41
+ return await response.json()
42
+
43
+ # System endpoints
44
+
45
+ async def get_status(self) -> Dict[str, Any]:
46
+ """Get system status"""
47
+ return await self._request("GET", "/status")
48
+
49
+ async def health_check(self) -> Dict[str, Any]:
50
+ """Check API health"""
51
+ return await self._request("GET", "/health")
52
+
53
+ async def list_providers(self) -> List[Dict[str, Any]]:
54
+ """List all registered providers"""
55
+ result = await self._request("GET", "/providers")
56
+ return result["providers"]
57
+
58
+ async def list_protocols(self) -> List[str]:
59
+ """List all registered protocols"""
60
+ result = await self._request("GET", "/protocols")
61
+ return result["protocols"]
62
+
63
+ # Workflow endpoints
64
+
65
+ async def submit_workflow(self, workflow: Dict[str, Any]) -> Dict[str, Any]:
66
+ """Submit a workflow for execution"""
67
+ return await self._request("POST", "/workflows", json=workflow)
68
+
69
+ async def get_workflow_status(self, workflow_id: str) -> Dict[str, Any]:
70
+ """Get workflow status"""
71
+ return await self._request("GET", f"/workflows/{workflow_id}")
72
+
73
+ async def cancel_workflow(self, workflow_id: str) -> Dict[str, Any]:
74
+ """Cancel a running workflow"""
75
+ return await self._request("DELETE", f"/workflows/{workflow_id}")
76
+
77
+ async def upload_workflow_file(self, file_path: str, execute: bool = True) -> Dict[str, Any]:
78
+ """Upload and optionally execute a workflow file"""
79
+ with open(file_path, 'rb') as f:
80
+ data = aiohttp.FormData()
81
+ data.add_field('file', f, filename=Path(file_path).name)
82
+ return await self._request(
83
+ "POST",
84
+ f"/workflows/upload?execute={str(execute).lower()}",
85
+ data=data
86
+ )
87
+
88
+ # Task endpoints
89
+
90
+ async def execute_task(self, task: Dict[str, Any]) -> Dict[str, Any]:
91
+ """Execute a single task"""
92
+ return await self._request("POST", "/tasks", json=task)
93
+
94
+ async def get_task_status(self, task_id: str) -> Dict[str, Any]:
95
+ """Get task status"""
96
+ return await self._request("GET", f"/tasks/{task_id}")
97
+
98
+ # Convenience endpoints
99
+
100
+ async def execute_python(self, code: str, timeout: int = 30) -> Dict[str, Any]:
101
+ """Execute Python code directly"""
102
+ return await self._request("POST", "/execute/python", json={
103
+ "code": code,
104
+ "timeout": timeout
105
+ })
106
+
107
+ async def chat(self, message: str, model: str = "llama3.2:latest",
108
+ temperature: float = 0.7, session_id: Optional[str] = None) -> Dict[str, Any]:
109
+ """Chat with LLM"""
110
+ return await self._request("POST", "/chat", json={
111
+ "message": message,
112
+ "model": model,
113
+ "temperature": temperature,
114
+ "session_id": session_id
115
+ })
116
+
117
+ async def batch_process(self, directory: str, pattern: str = "*",
118
+ prompt: str = "Analyze this file",
119
+ model: str = "llama3.2:latest",
120
+ max_concurrent: int = 5) -> Dict[str, Any]:
121
+ """Process files in batch"""
122
+ return await self._request("POST", "/batch", json={
123
+ "directory": directory,
124
+ "pattern": pattern,
125
+ "prompt": prompt,
126
+ "model": model,
127
+ "max_concurrent": max_concurrent
128
+ })
129
+
130
+ # Template endpoints
131
+
132
+ async def execute_template(self, template_type: str, params: Dict[str, Any]) -> Dict[str, Any]:
133
+ """Execute a workflow template"""
134
+ return await self._request("POST", f"/templates/{template_type}", json=params)
135
+
136
+ async def research(self, topic: str, depth: str = "medium", max_steps: int = 5) -> Dict[str, Any]:
137
+ """Execute research template"""
138
+ return await self.execute_template("research", {
139
+ "topic": topic,
140
+ "depth": depth,
141
+ "max_steps": max_steps
142
+ })
143
+
144
+ async def generate_code(self, task: str, language: str = "python") -> Dict[str, Any]:
145
+ """Execute code generation template"""
146
+ return await self.execute_template("code", {
147
+ "task": task,
148
+ "language": language
149
+ })
150
+
151
+ async def analyze(self, content: str, question: Optional[str] = None) -> Dict[str, Any]:
152
+ """Execute analysis template"""
153
+ params = {"content": content}
154
+ if question:
155
+ params["question"] = question
156
+ return await self.execute_template("analyze", params)
157
+
158
+
159
+ # Synchronous wrapper for convenience
160
+ class GleitzeitAPIClientSync:
161
+ """Synchronous wrapper for the API client"""
162
+
163
+ def __init__(self, base_url: str = "http://localhost:8000"):
164
+ self.async_client = GleitzeitAPIClient(base_url)
165
+
166
+ def _run_async(self, coro):
167
+ """Run async coroutine synchronously"""
168
+ loop = asyncio.get_event_loop()
169
+ if loop.is_running():
170
+ # If loop is already running (e.g., in Jupyter), create new task
171
+ import nest_asyncio
172
+ nest_asyncio.apply()
173
+ return loop.run_until_complete(coro)
174
+
175
+ def get_status(self) -> Dict[str, Any]:
176
+ async def _get():
177
+ async with self.async_client as client:
178
+ return await client.get_status()
179
+ return self._run_async(_get())
180
+
181
+ def submit_workflow(self, workflow: Dict[str, Any]) -> Dict[str, Any]:
182
+ async def _submit():
183
+ async with self.async_client as client:
184
+ return await client.submit_workflow(workflow)
185
+ return self._run_async(_submit())
186
+
187
+ def execute_python(self, code: str, timeout: int = 30) -> Dict[str, Any]:
188
+ async def _exec():
189
+ async with self.async_client as client:
190
+ return await client.execute_python(code, timeout)
191
+ return self._run_async(_exec())
192
+
193
+ def chat(self, message: str, model: str = "llama3.2:latest") -> Dict[str, Any]:
194
+ async def _chat():
195
+ async with self.async_client as client:
196
+ return await client.chat(message, model)
197
+ return self._run_async(_chat())
198
+
199
+ def research(self, topic: str, depth: str = "medium") -> Dict[str, Any]:
200
+ async def _research():
201
+ async with self.async_client as client:
202
+ return await client.research(topic, depth)
203
+ return self._run_async(_research())
204
+
205
+
206
+ # Example usage
207
+ if __name__ == "__main__":
208
+ async def main():
209
+ # Example async usage
210
+ async with GleitzeitAPIClient() as client:
211
+ # Check status
212
+ status = await client.get_status()
213
+ print(f"System status: {status['status']}")
214
+
215
+ # Execute Python code
216
+ result = await client.execute_python("print('Hello from API!'); result = 2 + 2")
217
+ print(f"Python result: {result}")
218
+
219
+ # Chat with LLM
220
+ chat_result = await client.chat("What is workflow orchestration?")
221
+ print(f"Chat response: {chat_result['response'][:200]}...")
222
+
223
+ # Submit a workflow
224
+ workflow = {
225
+ "name": "Test Workflow",
226
+ "description": "API test workflow",
227
+ "tasks": [
228
+ {
229
+ "name": "Calculate",
230
+ "protocol": "python/v1",
231
+ "method": "python/execute",
232
+ "params": {
233
+ "code": "result = 10 * 20"
234
+ }
235
+ }
236
+ ]
237
+ }
238
+ workflow_result = await client.submit_workflow(workflow)
239
+ print(f"Workflow submitted: {workflow_result['workflow_id']}")
240
+
241
+ # Run example
242
+ asyncio.run(main())