kailash 0.3.2__py3-none-any.whl → 0.4.1__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 (151) hide show
  1. kailash/__init__.py +33 -1
  2. kailash/access_control/__init__.py +129 -0
  3. kailash/access_control/managers.py +461 -0
  4. kailash/access_control/rule_evaluators.py +467 -0
  5. kailash/access_control_abac.py +825 -0
  6. kailash/config/__init__.py +27 -0
  7. kailash/config/database_config.py +359 -0
  8. kailash/database/__init__.py +28 -0
  9. kailash/database/execution_pipeline.py +499 -0
  10. kailash/middleware/__init__.py +306 -0
  11. kailash/middleware/auth/__init__.py +33 -0
  12. kailash/middleware/auth/access_control.py +436 -0
  13. kailash/middleware/auth/auth_manager.py +422 -0
  14. kailash/middleware/auth/jwt_auth.py +477 -0
  15. kailash/middleware/auth/kailash_jwt_auth.py +616 -0
  16. kailash/middleware/communication/__init__.py +37 -0
  17. kailash/middleware/communication/ai_chat.py +989 -0
  18. kailash/middleware/communication/api_gateway.py +802 -0
  19. kailash/middleware/communication/events.py +470 -0
  20. kailash/middleware/communication/realtime.py +710 -0
  21. kailash/middleware/core/__init__.py +21 -0
  22. kailash/middleware/core/agent_ui.py +890 -0
  23. kailash/middleware/core/schema.py +643 -0
  24. kailash/middleware/core/workflows.py +396 -0
  25. kailash/middleware/database/__init__.py +63 -0
  26. kailash/middleware/database/base.py +113 -0
  27. kailash/middleware/database/base_models.py +525 -0
  28. kailash/middleware/database/enums.py +106 -0
  29. kailash/middleware/database/migrations.py +12 -0
  30. kailash/{api/database.py → middleware/database/models.py} +183 -291
  31. kailash/middleware/database/repositories.py +685 -0
  32. kailash/middleware/database/session_manager.py +19 -0
  33. kailash/middleware/mcp/__init__.py +38 -0
  34. kailash/middleware/mcp/client_integration.py +585 -0
  35. kailash/middleware/mcp/enhanced_server.py +576 -0
  36. kailash/nodes/__init__.py +27 -3
  37. kailash/nodes/admin/__init__.py +42 -0
  38. kailash/nodes/admin/audit_log.py +794 -0
  39. kailash/nodes/admin/permission_check.py +864 -0
  40. kailash/nodes/admin/role_management.py +823 -0
  41. kailash/nodes/admin/security_event.py +1523 -0
  42. kailash/nodes/admin/user_management.py +944 -0
  43. kailash/nodes/ai/a2a.py +24 -7
  44. kailash/nodes/ai/ai_providers.py +248 -40
  45. kailash/nodes/ai/embedding_generator.py +11 -11
  46. kailash/nodes/ai/intelligent_agent_orchestrator.py +99 -11
  47. kailash/nodes/ai/llm_agent.py +436 -5
  48. kailash/nodes/ai/self_organizing.py +85 -10
  49. kailash/nodes/ai/vision_utils.py +148 -0
  50. kailash/nodes/alerts/__init__.py +26 -0
  51. kailash/nodes/alerts/base.py +234 -0
  52. kailash/nodes/alerts/discord.py +499 -0
  53. kailash/nodes/api/auth.py +287 -6
  54. kailash/nodes/api/rest.py +151 -0
  55. kailash/nodes/auth/__init__.py +17 -0
  56. kailash/nodes/auth/directory_integration.py +1228 -0
  57. kailash/nodes/auth/enterprise_auth_provider.py +1328 -0
  58. kailash/nodes/auth/mfa.py +2338 -0
  59. kailash/nodes/auth/risk_assessment.py +872 -0
  60. kailash/nodes/auth/session_management.py +1093 -0
  61. kailash/nodes/auth/sso.py +1040 -0
  62. kailash/nodes/base.py +344 -13
  63. kailash/nodes/base_cycle_aware.py +4 -2
  64. kailash/nodes/base_with_acl.py +1 -1
  65. kailash/nodes/code/python.py +283 -10
  66. kailash/nodes/compliance/__init__.py +9 -0
  67. kailash/nodes/compliance/data_retention.py +1888 -0
  68. kailash/nodes/compliance/gdpr.py +2004 -0
  69. kailash/nodes/data/__init__.py +22 -2
  70. kailash/nodes/data/async_connection.py +469 -0
  71. kailash/nodes/data/async_sql.py +757 -0
  72. kailash/nodes/data/async_vector.py +598 -0
  73. kailash/nodes/data/readers.py +767 -0
  74. kailash/nodes/data/retrieval.py +360 -1
  75. kailash/nodes/data/sharepoint_graph.py +397 -21
  76. kailash/nodes/data/sql.py +94 -5
  77. kailash/nodes/data/streaming.py +68 -8
  78. kailash/nodes/data/vector_db.py +54 -4
  79. kailash/nodes/enterprise/__init__.py +13 -0
  80. kailash/nodes/enterprise/batch_processor.py +741 -0
  81. kailash/nodes/enterprise/data_lineage.py +497 -0
  82. kailash/nodes/logic/convergence.py +31 -9
  83. kailash/nodes/logic/operations.py +14 -3
  84. kailash/nodes/mixins/__init__.py +8 -0
  85. kailash/nodes/mixins/event_emitter.py +201 -0
  86. kailash/nodes/mixins/mcp.py +9 -4
  87. kailash/nodes/mixins/security.py +165 -0
  88. kailash/nodes/monitoring/__init__.py +7 -0
  89. kailash/nodes/monitoring/performance_benchmark.py +2497 -0
  90. kailash/nodes/rag/__init__.py +284 -0
  91. kailash/nodes/rag/advanced.py +1615 -0
  92. kailash/nodes/rag/agentic.py +773 -0
  93. kailash/nodes/rag/conversational.py +999 -0
  94. kailash/nodes/rag/evaluation.py +875 -0
  95. kailash/nodes/rag/federated.py +1188 -0
  96. kailash/nodes/rag/graph.py +721 -0
  97. kailash/nodes/rag/multimodal.py +671 -0
  98. kailash/nodes/rag/optimized.py +933 -0
  99. kailash/nodes/rag/privacy.py +1059 -0
  100. kailash/nodes/rag/query_processing.py +1335 -0
  101. kailash/nodes/rag/realtime.py +764 -0
  102. kailash/nodes/rag/registry.py +547 -0
  103. kailash/nodes/rag/router.py +837 -0
  104. kailash/nodes/rag/similarity.py +1854 -0
  105. kailash/nodes/rag/strategies.py +566 -0
  106. kailash/nodes/rag/workflows.py +575 -0
  107. kailash/nodes/security/__init__.py +19 -0
  108. kailash/nodes/security/abac_evaluator.py +1411 -0
  109. kailash/nodes/security/audit_log.py +103 -0
  110. kailash/nodes/security/behavior_analysis.py +1893 -0
  111. kailash/nodes/security/credential_manager.py +401 -0
  112. kailash/nodes/security/rotating_credentials.py +760 -0
  113. kailash/nodes/security/security_event.py +133 -0
  114. kailash/nodes/security/threat_detection.py +1103 -0
  115. kailash/nodes/testing/__init__.py +9 -0
  116. kailash/nodes/testing/credential_testing.py +499 -0
  117. kailash/nodes/transform/__init__.py +10 -2
  118. kailash/nodes/transform/chunkers.py +592 -1
  119. kailash/nodes/transform/processors.py +484 -14
  120. kailash/nodes/validation.py +321 -0
  121. kailash/runtime/access_controlled.py +1 -1
  122. kailash/runtime/async_local.py +41 -7
  123. kailash/runtime/docker.py +1 -1
  124. kailash/runtime/local.py +474 -55
  125. kailash/runtime/parallel.py +1 -1
  126. kailash/runtime/parallel_cyclic.py +1 -1
  127. kailash/runtime/testing.py +210 -2
  128. kailash/security.py +1 -1
  129. kailash/utils/migrations/__init__.py +25 -0
  130. kailash/utils/migrations/generator.py +433 -0
  131. kailash/utils/migrations/models.py +231 -0
  132. kailash/utils/migrations/runner.py +489 -0
  133. kailash/utils/secure_logging.py +342 -0
  134. kailash/workflow/__init__.py +16 -0
  135. kailash/workflow/cyclic_runner.py +3 -4
  136. kailash/workflow/graph.py +70 -2
  137. kailash/workflow/resilience.py +249 -0
  138. kailash/workflow/templates.py +726 -0
  139. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/METADATA +256 -20
  140. kailash-0.4.1.dist-info/RECORD +227 -0
  141. kailash/api/__init__.py +0 -17
  142. kailash/api/__main__.py +0 -6
  143. kailash/api/studio_secure.py +0 -893
  144. kailash/mcp/__main__.py +0 -13
  145. kailash/mcp/server_new.py +0 -336
  146. kailash/mcp/servers/__init__.py +0 -12
  147. kailash-0.3.2.dist-info/RECORD +0 -136
  148. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/WHEEL +0 -0
  149. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/entry_points.txt +0 -0
  150. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/licenses/LICENSE +0 -0
  151. {kailash-0.3.2.dist-info → kailash-0.4.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,306 @@
1
+ """
2
+ Enterprise Middleware Layer for Kailash SDK
3
+ ===========================================
4
+
5
+ Consolidated enterprise-grade middleware components that provide a comprehensive
6
+ foundation for building production-ready applications with the Kailash SDK.
7
+
8
+ This middleware layer consolidates and enhances existing api/ and mcp/ implementations
9
+ into a unified, enterprise-grade middleware stack built entirely with Kailash SDK
10
+ components, following strict SDK patterns and best practices.
11
+
12
+ Core Design Principles
13
+ ---------------------
14
+ 1. **100% SDK Components**: Every middleware component uses authentic Kailash SDK nodes
15
+ 2. **No Custom Orchestration**: Delegates all execution to SDK runtime engines
16
+ 3. **Event-Driven Architecture**: Real-time communication via comprehensive event streams
17
+ 4. **Enterprise Security**: Multi-tenant isolation with RBAC/ABAC access control
18
+ 5. **Performance Optimized**: Sub-200ms latency with intelligent caching
19
+ 6. **Comprehensive Testing**: 17/17 integration tests passing for production reliability
20
+
21
+ Architecture Overview
22
+ --------------------
23
+ The middleware consists of these interconnected layers:
24
+
25
+ **Agent-UI Communication Layer**:
26
+ - Session management with automatic cleanup
27
+ - Dynamic workflow creation using WorkflowBuilder.from_dict()
28
+ - Real-time execution monitoring and progress tracking
29
+ - Event-driven state synchronization
30
+
31
+ **Real-time Communication Layer**:
32
+ - WebSocket connections for bi-directional communication
33
+ - Server-Sent Events (SSE) for unidirectional streaming
34
+ - Webhook management for external integrations
35
+ - Event filtering and subscription management
36
+
37
+ **API Gateway Layer**:
38
+ - RESTful API endpoints with OpenAPI documentation
39
+ - JWT-based authentication using JWTConfigNode
40
+ - Request/response middleware with comprehensive logging
41
+ - Dynamic schema generation for node discovery
42
+
43
+ **Database Integration Layer**:
44
+ - Repository pattern using AsyncSQLDatabaseNode
45
+ - Audit logging with AuditLogNode for compliance
46
+ - Security event tracking with SecurityEventNode
47
+ - Workflow and execution persistence
48
+
49
+ **AI Chat Integration Layer**:
50
+ - Semantic search using AsyncPostgreSQLVectorNode
51
+ - LLM integration for natural language workflow generation
52
+ - Context-aware conversation management
53
+ - Intent recognition and response generation
54
+
55
+ Key Components
56
+ -------------
57
+
58
+ **Core Middleware**:
59
+ - `AgentUIMiddleware`: Central orchestration hub for frontend communication
60
+ - `RealtimeMiddleware`: Real-time communication management
61
+ - `APIGateway`: RESTful API layer with authentication
62
+ - `EventStream`: Comprehensive event management system
63
+
64
+ **Authentication & Security**:
65
+ - `KailashJWTAuthManager`: JWT token management using SDK security nodes
66
+ - `MiddlewareAccessControlManager`: RBAC/ABAC access control
67
+ - `MiddlewareAuthenticationMiddleware`: Request authentication middleware
68
+
69
+ **AI & Chat Integration**:
70
+ - `AIChatMiddleware`: AI-powered conversation management
71
+ - `WorkflowGenerator`: Natural language to workflow conversion
72
+ - `ChatMessage`: Structured chat message handling
73
+
74
+ **MCP Integration**:
75
+ - `MiddlewareMCPServer`: Enhanced MCP server with caching and metrics
76
+ - `MiddlewareMCPClient`: Robust MCP client with connection management
77
+ - `MCPToolNode`: MCP tool integration as SDK nodes
78
+ - `MCPResourceNode`: MCP resource access as SDK nodes
79
+
80
+ **Database & Persistence**:
81
+ - `MiddlewareWorkflowRepository`: Workflow persistence using SDK nodes
82
+ - `MiddlewareExecutionRepository`: Execution tracking and history
83
+ - `MiddlewareDatabaseManager`: Connection and transaction management
84
+
85
+ **Schema & Discovery**:
86
+ - `NodeSchemaGenerator`: Dynamic schema generation for all SDK nodes
87
+ - `DynamicSchemaRegistry`: Caching and optimization for schema queries
88
+
89
+ Enterprise Features
90
+ ------------------
91
+ - **Multi-tenant Isolation**: Complete session and data isolation
92
+ - **Comprehensive Monitoring**: Built-in metrics, logging, and health checks
93
+ - **Automatic Scaling**: Connection pooling and resource optimization
94
+ - **Security Compliance**: Audit trails, access control, and security events
95
+ - **Developer Experience**: Rich error messages, debugging tools, and documentation
96
+
97
+ Usage Examples
98
+ --------------
99
+
100
+ **Basic Middleware Stack**:
101
+ >>> from kailash.middleware import AgentUIMiddleware, APIGateway
102
+ >>>
103
+ >>> # Create agent-UI middleware with session management
104
+ >>> agent_ui = AgentUIMiddleware(
105
+ ... max_sessions=1000,
106
+ ... session_timeout_minutes=60,
107
+ ... enable_persistence=True
108
+ ... )
109
+ >>>
110
+ >>> # Create API gateway with authentication
111
+ >>> gateway = create_gateway(
112
+ ... title="My Kailash API",
113
+ ... cors_origins=["https://myapp.com"],
114
+ ... enable_docs=True
115
+ ... )
116
+ >>> gateway.agent_ui = agent_ui
117
+
118
+ **Real-time Communication**:
119
+ >>> from kailash.middleware import RealtimeMiddleware, EventStream
120
+ >>>
121
+ >>> # Create real-time middleware with WebSocket support
122
+ >>> realtime = RealtimeMiddleware(agent_ui)
123
+ >>>
124
+ >>> # Subscribe to workflow events
125
+ >>> async def handle_workflow_events(event):
126
+ ... print(f"Workflow {event.workflow_id}: {event.type}")
127
+ >>>
128
+ >>> await realtime.event_stream.subscribe(
129
+ ... "workflow_monitor",
130
+ ... handle_workflow_events
131
+ ... )
132
+
133
+ **AI Chat Integration**:
134
+ >>> from kailash.middleware import AIChatMiddleware
135
+ >>>
136
+ >>> # Create AI chat with semantic search
137
+ >>> ai_chat = AIChatMiddleware(
138
+ ... agent_ui,
139
+ ... enable_vector_search=True,
140
+ ... vector_database_url="postgresql://..."
141
+ ... )
142
+ >>>
143
+ >>> # Start chat session and get workflow suggestions
144
+ >>> session_id = await ai_chat.start_chat_session("user123")
145
+ >>> response = await ai_chat.send_message(
146
+ ... session_id,
147
+ ... "Create a workflow to process CSV data and generate charts"
148
+ ... )
149
+
150
+ **Dynamic Workflow Creation**:
151
+ >>> # Create workflows dynamically from configuration
152
+ >>> workflow_config = {
153
+ ... "name": "data_processing_pipeline",
154
+ ... "nodes": [
155
+ ... {
156
+ ... "id": "csv_reader",
157
+ ... "type": "CSVReaderNode",
158
+ ... "config": {"file_path": "/data/input.csv"}
159
+ ... },
160
+ ... {
161
+ ... "id": "data_processor",
162
+ ... "type": "PythonCodeNode",
163
+ ... "config": {
164
+ ... "name": "data_processor",
165
+ ... "code": "result = {'processed': len(data)}"
166
+ ... }
167
+ ... }
168
+ ... ],
169
+ ... "connections": [
170
+ ... {
171
+ ... "from_node": "csv_reader",
172
+ ... "from_output": "data",
173
+ ... "to_node": "data_processor",
174
+ ... "to_input": "data"
175
+ ... }
176
+ ... ]
177
+ ... }
178
+ >>>
179
+ >>> # Create and execute workflow
180
+ >>> session_id = await agent_ui.create_session("user123")
181
+ >>> workflow_id = await agent_ui.create_dynamic_workflow(
182
+ ... session_id, workflow_config
183
+ ... )
184
+ >>> execution_id = await agent_ui.execute_workflow(
185
+ ... session_id, workflow_id, inputs={}
186
+ ... )
187
+
188
+ Production Deployment
189
+ --------------------
190
+ The middleware is designed for production deployment with:
191
+
192
+ - **Health Checks**: Built-in endpoints for monitoring service health
193
+ - **Metrics Export**: Prometheus-compatible metrics for observability
194
+ - **Graceful Shutdown**: Clean resource cleanup and connection management
195
+ - **Configuration Management**: Environment-based configuration
196
+ - **Logging Integration**: Structured logging with correlation IDs
197
+ - **Error Handling**: Comprehensive error recovery and reporting
198
+
199
+ Version History
200
+ --------------
201
+ - **v1.0.0**: Initial enterprise middleware release
202
+ - Core agent-UI communication
203
+ - Real-time event streaming
204
+ - Dynamic workflow creation
205
+ - JWT authentication integration
206
+ - Comprehensive test coverage (17/17 tests passing)
207
+
208
+ Author: Kailash SDK Team
209
+ License: See LICENSE file
210
+ Documentation: https://docs.kailash.ai/middleware/
211
+ """
212
+
213
+ from .auth.access_control import (
214
+ MiddlewareAccessControlManager,
215
+ MiddlewareAuthenticationMiddleware,
216
+ )
217
+ from .auth.auth_manager import AuthLevel, MiddlewareAuthManager
218
+
219
+ # Authentication & Access Control
220
+ from .auth.jwt_auth import JWTAuthManager
221
+ from .communication.ai_chat import AIChatMiddleware, ChatMessage, WorkflowGenerator
222
+ from .communication.api_gateway import APIGateway, create_gateway
223
+
224
+ # Communication Layer
225
+ from .communication.events import (
226
+ EventFilter,
227
+ EventPriority,
228
+ EventStream,
229
+ EventType,
230
+ NodeEvent,
231
+ UIEvent,
232
+ WorkflowEvent,
233
+ )
234
+ from .communication.realtime import RealtimeMiddleware
235
+
236
+ # Core Middleware Components
237
+ from .core.agent_ui import AgentUIMiddleware
238
+ from .core.schema import DynamicSchemaRegistry, NodeSchemaGenerator
239
+ from .core.workflows import MiddlewareWorkflows, WorkflowBasedMiddleware
240
+
241
+ # Database Layer
242
+ from .database import (
243
+ CustomNodeModel,
244
+ MiddlewareDatabaseManager,
245
+ MiddlewareWorkflowRepository,
246
+ WorkflowExecutionModel,
247
+ WorkflowModel,
248
+ )
249
+ from .mcp.client_integration import (
250
+ MCPClientConfig,
251
+ MCPServerConnection,
252
+ MiddlewareMCPClient,
253
+ )
254
+
255
+ # MCP Integration
256
+ from .mcp.enhanced_server import (
257
+ MCPResourceNode,
258
+ MCPServerConfig,
259
+ MCPToolNode,
260
+ MiddlewareMCPServer,
261
+ )
262
+
263
+ __all__ = [
264
+ # Core Components
265
+ "AgentUIMiddleware",
266
+ "AIChatMiddleware",
267
+ "ChatMessage",
268
+ "WorkflowGenerator",
269
+ "APIGateway",
270
+ "create_gateway",
271
+ "EventStream",
272
+ "EventType",
273
+ "EventPriority",
274
+ "EventFilter",
275
+ "WorkflowEvent",
276
+ "NodeEvent",
277
+ "UIEvent",
278
+ "RealtimeMiddleware",
279
+ "NodeSchemaGenerator",
280
+ "DynamicSchemaRegistry",
281
+ # Authentication & Access Control
282
+ "JWTAuthManager",
283
+ "MiddlewareAuthManager",
284
+ "AuthLevel",
285
+ "MiddlewareAccessControlManager",
286
+ "MiddlewareAuthenticationMiddleware",
287
+ # MCP Integration
288
+ "MiddlewareMCPServer",
289
+ "MCPServerConfig",
290
+ "MCPToolNode",
291
+ "MCPResourceNode",
292
+ "MiddlewareMCPClient",
293
+ "MCPClientConfig",
294
+ "MCPServerConnection",
295
+ # Database Layer
296
+ "WorkflowModel",
297
+ "WorkflowExecutionModel",
298
+ "CustomNodeModel",
299
+ "MiddlewareWorkflowRepository",
300
+ "MiddlewareDatabaseManager",
301
+ # Workflow-based Optimizations
302
+ "MiddlewareWorkflows",
303
+ "WorkflowBasedMiddleware",
304
+ ]
305
+
306
+ __version__ = "1.0.0"
@@ -0,0 +1,33 @@
1
+ """
2
+ Enterprise Authentication and Authorization for Kailash Middleware
3
+
4
+ Provides comprehensive authentication, authorization, and tenant isolation
5
+ capabilities for the Kailash middleware layer.
6
+
7
+ Features:
8
+ - JWT-based authentication with refresh tokens
9
+ - Role-based access control (RBAC)
10
+ - Attribute-based access control (ABAC)
11
+ - Multi-tenant isolation
12
+ - API key authentication
13
+ - OAuth2/OIDC integration
14
+ - Session management
15
+ - Audit logging
16
+ """
17
+
18
+ from .access_control import (
19
+ MiddlewareAccessControlManager,
20
+ MiddlewareAuthenticationMiddleware,
21
+ )
22
+ from .auth_manager import AuthLevel, MiddlewareAuthManager
23
+ from .kailash_jwt_auth import KailashJWTAuthManager
24
+
25
+ __all__ = [
26
+ # Core authentication
27
+ "KailashJWTAuthManager",
28
+ "MiddlewareAuthManager", # Main auth manager using SDK nodes
29
+ "AuthLevel",
30
+ # Authorization & Access Control
31
+ "MiddlewareAccessControlManager",
32
+ "MiddlewareAuthenticationMiddleware",
33
+ ]