alita-sdk 0.3.376__py3-none-any.whl → 0.3.435__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.

Potentially problematic release.


This version of alita-sdk might be problematic. Click here for more details.

Files changed (60) hide show
  1. alita_sdk/configurations/bitbucket.py +95 -0
  2. alita_sdk/configurations/confluence.py +96 -1
  3. alita_sdk/configurations/gitlab.py +79 -0
  4. alita_sdk/configurations/jira.py +103 -0
  5. alita_sdk/configurations/testrail.py +88 -0
  6. alita_sdk/configurations/xray.py +93 -0
  7. alita_sdk/configurations/zephyr_enterprise.py +93 -0
  8. alita_sdk/configurations/zephyr_essential.py +75 -0
  9. alita_sdk/runtime/clients/client.py +9 -4
  10. alita_sdk/runtime/clients/mcp_discovery.py +342 -0
  11. alita_sdk/runtime/clients/mcp_manager.py +262 -0
  12. alita_sdk/runtime/clients/sandbox_client.py +8 -0
  13. alita_sdk/runtime/langchain/assistant.py +41 -38
  14. alita_sdk/runtime/langchain/constants.py +5 -1
  15. alita_sdk/runtime/langchain/document_loaders/AlitaDocxMammothLoader.py +315 -3
  16. alita_sdk/runtime/langchain/document_loaders/AlitaJSONLoader.py +4 -1
  17. alita_sdk/runtime/langchain/document_loaders/constants.py +28 -12
  18. alita_sdk/runtime/langchain/langraph_agent.py +91 -27
  19. alita_sdk/runtime/langchain/utils.py +24 -4
  20. alita_sdk/runtime/models/mcp_models.py +57 -0
  21. alita_sdk/runtime/toolkits/__init__.py +24 -0
  22. alita_sdk/runtime/toolkits/application.py +8 -1
  23. alita_sdk/runtime/toolkits/mcp.py +787 -0
  24. alita_sdk/runtime/toolkits/tools.py +98 -50
  25. alita_sdk/runtime/tools/__init__.py +7 -2
  26. alita_sdk/runtime/tools/application.py +7 -0
  27. alita_sdk/runtime/tools/function.py +20 -28
  28. alita_sdk/runtime/tools/graph.py +10 -4
  29. alita_sdk/runtime/tools/image_generation.py +104 -8
  30. alita_sdk/runtime/tools/llm.py +146 -114
  31. alita_sdk/runtime/tools/mcp_inspect_tool.py +284 -0
  32. alita_sdk/runtime/tools/mcp_server_tool.py +79 -10
  33. alita_sdk/runtime/tools/sandbox.py +166 -63
  34. alita_sdk/runtime/tools/vectorstore.py +3 -2
  35. alita_sdk/runtime/tools/vectorstore_base.py +4 -3
  36. alita_sdk/runtime/utils/streamlit.py +34 -3
  37. alita_sdk/runtime/utils/toolkit_utils.py +5 -2
  38. alita_sdk/runtime/utils/utils.py +1 -0
  39. alita_sdk/tools/__init__.py +48 -31
  40. alita_sdk/tools/ado/work_item/ado_wrapper.py +17 -8
  41. alita_sdk/tools/base_indexer_toolkit.py +75 -66
  42. alita_sdk/tools/chunkers/sematic/proposal_chunker.py +1 -1
  43. alita_sdk/tools/code_indexer_toolkit.py +13 -3
  44. alita_sdk/tools/confluence/api_wrapper.py +29 -7
  45. alita_sdk/tools/confluence/loader.py +10 -0
  46. alita_sdk/tools/elitea_base.py +7 -7
  47. alita_sdk/tools/gitlab/api_wrapper.py +11 -7
  48. alita_sdk/tools/jira/api_wrapper.py +1 -1
  49. alita_sdk/tools/openapi/__init__.py +10 -1
  50. alita_sdk/tools/qtest/api_wrapper.py +522 -74
  51. alita_sdk/tools/sharepoint/api_wrapper.py +104 -33
  52. alita_sdk/tools/sharepoint/authorization_helper.py +175 -1
  53. alita_sdk/tools/sharepoint/utils.py +8 -2
  54. alita_sdk/tools/utils/content_parser.py +27 -16
  55. alita_sdk/tools/vector_adapters/VectorStoreAdapter.py +19 -6
  56. {alita_sdk-0.3.376.dist-info → alita_sdk-0.3.435.dist-info}/METADATA +1 -1
  57. {alita_sdk-0.3.376.dist-info → alita_sdk-0.3.435.dist-info}/RECORD +60 -55
  58. {alita_sdk-0.3.376.dist-info → alita_sdk-0.3.435.dist-info}/WHEEL +0 -0
  59. {alita_sdk-0.3.376.dist-info → alita_sdk-0.3.435.dist-info}/licenses/LICENSE +0 -0
  60. {alita_sdk-0.3.376.dist-info → alita_sdk-0.3.435.dist-info}/top_level.txt +0 -0
@@ -18,3 +18,78 @@ class ZephyrEssentialConfiguration(BaseModel):
18
18
  )
19
19
  base_url: Optional[str] = Field(description="Zephyr Essential API Base URL", default=None)
20
20
  token: SecretStr = Field(description="Zephyr Essential API Token")
21
+
22
+ @staticmethod
23
+ def check_connection(settings: dict) -> str | None:
24
+ """
25
+ Check the connection to Zephyr Essential (Zephyr Scale).
26
+
27
+ Args:
28
+ settings: Dictionary containing Zephyr Essential configuration
29
+ - base_url: Zephyr Essential API Base URL (optional, defaults to Zephyr Scale Cloud API)
30
+ - token: Zephyr Essential API Token (required)
31
+
32
+ Returns:
33
+ None if connection successful, error message string if failed
34
+ """
35
+ import requests
36
+
37
+ # Get base_url or use default
38
+ base_url = settings.get("base_url")
39
+ if base_url:
40
+ base_url = base_url.strip().rstrip("/")
41
+ # Validate URL format if provided
42
+ if not base_url.startswith(("http://", "https://")):
43
+ return "Zephyr Essential URL must start with http:// or https://"
44
+ else:
45
+ # Default to Zephyr Scale Cloud API
46
+ base_url = "https://api.zephyrscale.smartbear.com/v2"
47
+
48
+ # Validate token
49
+ token = settings.get("token")
50
+ if not token:
51
+ return "Zephyr Essential API token is required"
52
+
53
+ # Extract token value if it's a SecretStr
54
+ token_value = token.get_secret_value() if hasattr(token, 'get_secret_value') else token
55
+
56
+ if not token_value or not str(token_value).strip():
57
+ return "Zephyr Essential API token cannot be empty"
58
+
59
+ # Test connection using /projects endpoint (requires authentication)
60
+ test_url = f"{base_url}/projects"
61
+
62
+ headers = {
63
+ "Authorization": f"Bearer {str(token_value).strip()}"
64
+ }
65
+
66
+ try:
67
+ response = requests.get(
68
+ test_url,
69
+ headers=headers,
70
+ timeout=10
71
+ )
72
+
73
+ # Check response status
74
+ if response.status_code == 200:
75
+ # Successfully connected and authenticated
76
+ return None
77
+ elif response.status_code == 401:
78
+ return "Authentication failed: invalid API token"
79
+ elif response.status_code == 403:
80
+ return "Access forbidden: token lacks required permissions"
81
+ elif response.status_code == 404:
82
+ return "Zephyr Essential API endpoint not found: verify the API URL"
83
+ else:
84
+ return f"Zephyr Essential API returned status code {response.status_code}"
85
+
86
+ except requests.exceptions.SSLError as e:
87
+ return f"SSL certificate verification failed: {str(e)}"
88
+ except requests.exceptions.ConnectionError:
89
+ return f"Cannot connect to Zephyr Essential at {base_url}: connection refused"
90
+ except requests.exceptions.Timeout:
91
+ return f"Connection to Zephyr Essential at {base_url} timed out"
92
+ except requests.exceptions.RequestException as e:
93
+ return f"Error connecting to Zephyr Essential: {str(e)}"
94
+ except Exception as e:
95
+ return f"Unexpected error: {str(e)}"
@@ -568,19 +568,22 @@ class AlitaClient:
568
568
  def predict_agent(self, llm: ChatOpenAI, instructions: str = "You are a helpful assistant.",
569
569
  tools: Optional[list] = None, chat_history: Optional[List[Any]] = None,
570
570
  memory=None, runtime='langchain', variables: Optional[list] = None,
571
- store: Optional[BaseStore] = None):
571
+ store: Optional[BaseStore] = None, debug_mode: Optional[bool] = False):
572
572
  """
573
573
  Create a predict-type agent with minimal configuration.
574
574
 
575
575
  Args:
576
576
  llm: The LLM to use
577
577
  instructions: System instructions for the agent
578
- tools: Optional list of tools to provide to the agent
578
+ tools: Optional list of tool configurations (not tool instances) to provide to the agent.
579
+ Tool configs will be processed through get_tools() to create tool instances.
580
+ Each tool config should have 'type', 'settings', etc.
579
581
  chat_history: Optional chat history
580
582
  memory: Optional memory/checkpointer
581
583
  runtime: Runtime type (default: 'langchain')
582
584
  variables: Optional list of variables for the agent
583
585
  store: Optional store for memory
586
+ debug_mode: Enable debug mode for cases when assistant can be initialized without tools
584
587
 
585
588
  Returns:
586
589
  Runnable agent ready for execution
@@ -594,13 +597,15 @@ class AlitaClient:
594
597
 
595
598
  # Create a minimal data structure for predict agent
596
599
  # All LLM settings are taken from the passed client instance
600
+ # Note: 'tools' here are tool CONFIGURATIONS, not tool instances
601
+ # They will be converted to tool instances by LangChainAssistant via get_tools()
597
602
  agent_data = {
598
603
  'instructions': instructions,
599
- 'tools': tools, # Tools are handled separately in predict agents
604
+ 'tools': tools, # Tool configs that will be processed by get_tools()
600
605
  'variables': variables
601
606
  }
602
607
  return LangChainAssistant(self, agent_data, llm,
603
- chat_history, "predict", memory=memory, store=store).runnable()
608
+ chat_history, "predict", memory=memory, store=store, debug_mode=debug_mode).runnable()
604
609
 
605
610
  def test_toolkit_tool(self, toolkit_config: dict, tool_name: str, tool_params: dict = None,
606
611
  runtime_config: dict = None, llm_model: str = None,
@@ -0,0 +1,342 @@
1
+ """
2
+ Dynamic MCP Server Discovery Client.
3
+ Implements the MCP protocol for discovering tools from remote servers.
4
+ """
5
+
6
+ import asyncio
7
+ import json
8
+ import logging
9
+ import time
10
+ from dataclasses import dataclass, field
11
+ from typing import Dict, List, Optional, Any, Set
12
+ from urllib.parse import urlparse
13
+ import aiohttp
14
+ from datetime import datetime, timedelta
15
+
16
+ from ..models.mcp_models import McpConnectionConfig, McpToolMetadata
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+
21
+ @dataclass
22
+ class McpServerInfo:
23
+ """Information about an MCP server."""
24
+ name: str
25
+ url: str
26
+ headers: Optional[Dict[str, str]] = None
27
+ last_discovery: Optional[datetime] = None
28
+ tools: List[McpToolMetadata] = field(default_factory=list)
29
+ status: str = "unknown" # unknown, online, offline, error
30
+ error: Optional[str] = None
31
+
32
+
33
+ class McpDiscoveryClient:
34
+ """
35
+ Client for dynamically discovering tools from MCP servers.
36
+ Implements the MCP protocol for tool discovery.
37
+ """
38
+
39
+ def __init__(
40
+ self,
41
+ discovery_interval: int = 300, # 5 minutes
42
+ request_timeout: int = 30,
43
+ max_retries: int = 3,
44
+ cache_ttl: int = 600 # 10 minutes
45
+ ):
46
+ self.discovery_interval = discovery_interval
47
+ self.request_timeout = request_timeout
48
+ self.max_retries = max_retries
49
+ self.cache_ttl = cache_ttl
50
+
51
+ # Server registry
52
+ self.servers: Dict[str, McpServerInfo] = {}
53
+ self.session: Optional[aiohttp.ClientSession] = None
54
+
55
+ # Discovery state
56
+ self._discovery_task: Optional[asyncio.Task] = None
57
+ self._running = False
58
+
59
+ async def __aenter__(self):
60
+ """Async context manager entry."""
61
+ await self.start()
62
+ return self
63
+
64
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
65
+ """Async context manager exit."""
66
+ await self.stop()
67
+
68
+ async def start(self):
69
+ """Start the discovery client."""
70
+ if self._running:
71
+ return
72
+
73
+ self.session = aiohttp.ClientSession(
74
+ timeout=aiohttp.ClientTimeout(total=self.request_timeout)
75
+ )
76
+ self._running = True
77
+
78
+ # Start background discovery task
79
+ self._discovery_task = asyncio.create_task(self._discovery_loop())
80
+ logger.info("MCP Discovery Client started")
81
+
82
+ async def stop(self):
83
+ """Stop the discovery client."""
84
+ if not self._running:
85
+ return
86
+
87
+ self._running = False
88
+
89
+ if self._discovery_task:
90
+ self._discovery_task.cancel()
91
+ try:
92
+ await self._discovery_task
93
+ except asyncio.CancelledError:
94
+ pass
95
+
96
+ if self.session:
97
+ await self.session.close()
98
+
99
+ logger.info("MCP Discovery Client stopped")
100
+
101
+ def add_server(self, server_name: str, connection_config: McpConnectionConfig):
102
+ """Add an MCP server to discovery."""
103
+ server_info = McpServerInfo(
104
+ name=server_name,
105
+ url=connection_config.url,
106
+ headers=connection_config.headers
107
+ )
108
+ self.servers[server_name] = server_info
109
+ logger.info(f"Added MCP server for discovery: {server_name} at {connection_config.url}")
110
+
111
+ def remove_server(self, server_name: str):
112
+ """Remove an MCP server from discovery."""
113
+ if server_name in self.servers:
114
+ del self.servers[server_name]
115
+ logger.info(f"Removed MCP server from discovery: {server_name}")
116
+
117
+ async def discover_server_tools(self, server_name: str, force: bool = False) -> List[McpToolMetadata]:
118
+ """Discover tools from a specific MCP server."""
119
+ if server_name not in self.servers:
120
+ raise ValueError(f"Server {server_name} not registered for discovery")
121
+
122
+ server_info = self.servers[server_name]
123
+
124
+ # Check cache unless force refresh
125
+ if not force and self._is_cache_valid(server_info):
126
+ logger.debug(f"Using cached tools for server {server_name}")
127
+ return server_info.tools
128
+
129
+ try:
130
+ tools = await self._fetch_server_tools(server_info)
131
+ server_info.tools = tools
132
+ server_info.last_discovery = datetime.now()
133
+ server_info.status = "online"
134
+ server_info.error = None
135
+
136
+ logger.info(f"Discovered {len(tools)} tools from server {server_name}")
137
+ return tools
138
+
139
+ except Exception as e:
140
+ error_msg = f"Failed to discover tools from {server_name}: {e}"
141
+ logger.error(error_msg)
142
+ server_info.status = "error"
143
+ server_info.error = str(e)
144
+ return []
145
+
146
+ async def get_all_tools(self) -> Dict[str, List[McpToolMetadata]]:
147
+ """Get all discovered tools from all servers."""
148
+ all_tools = {}
149
+
150
+ for server_name in self.servers:
151
+ tools = await self.discover_server_tools(server_name)
152
+ all_tools[server_name] = tools
153
+
154
+ return all_tools
155
+
156
+ def get_server_status(self, server_name: str) -> Optional[McpServerInfo]:
157
+ """Get status information for a server."""
158
+ return self.servers.get(server_name)
159
+
160
+ def get_all_server_status(self) -> Dict[str, McpServerInfo]:
161
+ """Get status information for all servers."""
162
+ return self.servers.copy()
163
+
164
+ async def _discovery_loop(self):
165
+ """Background task for periodic tool discovery."""
166
+ while self._running:
167
+ try:
168
+ await self._perform_discovery()
169
+ await asyncio.sleep(self.discovery_interval)
170
+ except asyncio.CancelledError:
171
+ break
172
+ except Exception as e:
173
+ logger.error(f"Error in discovery loop: {e}")
174
+ await asyncio.sleep(60) # Wait before retrying
175
+
176
+ async def _perform_discovery(self):
177
+ """Perform discovery on all registered servers."""
178
+ if not self.servers:
179
+ return
180
+
181
+ discovery_tasks = [
182
+ self.discover_server_tools(server_name)
183
+ for server_name in self.servers
184
+ ]
185
+
186
+ results = await asyncio.gather(*discovery_tasks, return_exceptions=True)
187
+
188
+ # Log any errors
189
+ for i, result in enumerate(results):
190
+ if isinstance(result, Exception):
191
+ server_name = list(self.servers.keys())[i]
192
+ logger.error(f"Discovery failed for server {server_name}: {result}")
193
+
194
+ async def _fetch_server_tools(self, server_info: McpServerInfo) -> List[McpToolMetadata]:
195
+ """Fetch tools from an MCP server using HTTP requests."""
196
+ if not self.session:
197
+ raise RuntimeError("Discovery client not started")
198
+
199
+ # MCP protocol: list_tools request
200
+ mcp_request = {
201
+ "jsonrpc": "2.0",
202
+ "id": f"discover_{int(time.time())}",
203
+ "method": "tools/list",
204
+ "params": {}
205
+ }
206
+
207
+ headers = {"Content-Type": "application/json"}
208
+ if server_info.headers:
209
+ headers.update(server_info.headers)
210
+
211
+ async with self.session.post(
212
+ server_info.url,
213
+ json=mcp_request,
214
+ headers=headers
215
+ ) as response:
216
+
217
+ if response.status != 200:
218
+ raise Exception(f"HTTP {response.status}: {await response.text()}")
219
+
220
+ data = await response.json()
221
+
222
+ if "error" in data:
223
+ raise Exception(f"MCP Error: {data['error']}")
224
+
225
+ # Parse MCP response
226
+ tools_data = data.get("result", {}).get("tools", [])
227
+ tools = []
228
+
229
+ for tool_data in tools_data:
230
+ try:
231
+ tool_metadata = McpToolMetadata(
232
+ name=tool_data.get("name", ""),
233
+ description=tool_data.get("description", ""),
234
+ server=server_info.name,
235
+ input_schema=tool_data.get("inputSchema", {}),
236
+ enabled=True
237
+ )
238
+ tools.append(tool_metadata)
239
+ except Exception as e:
240
+ logger.warning(f"Failed to parse tool from {server_info.name}: {e}")
241
+
242
+ return tools
243
+
244
+ def _is_cache_valid(self, server_info: McpServerInfo) -> bool:
245
+ """Check if cached tools are still valid."""
246
+ if not server_info.last_discovery:
247
+ return False
248
+
249
+ cache_age = datetime.now() - server_info.last_discovery
250
+ return cache_age.total_seconds() < self.cache_ttl
251
+
252
+
253
+ class McpDiscoveryService:
254
+ """
255
+ High-level service for managing MCP server discovery.
256
+ Integrates with the existing toolkit system.
257
+ """
258
+
259
+ def __init__(self, discovery_client: Optional[McpDiscoveryClient] = None):
260
+ self.client = discovery_client or McpDiscoveryClient()
261
+ self._started = False
262
+
263
+ async def start(self):
264
+ """Start the discovery service."""
265
+ if not self._started:
266
+ await self.client.start()
267
+ self._started = True
268
+
269
+ async def stop(self):
270
+ """Stop the discovery service."""
271
+ if self._started:
272
+ await self.client.stop()
273
+ self._started = False
274
+
275
+ async def register_server(self, server_name: str, connection_config: McpConnectionConfig):
276
+ """Register an MCP server for discovery."""
277
+ self.client.add_server(server_name, connection_config)
278
+
279
+ # Perform immediate discovery
280
+ await self.client.discover_server_tools(server_name, force=True)
281
+
282
+ def unregister_server(self, server_name: str):
283
+ """Unregister an MCP server."""
284
+ self.client.remove_server(server_name)
285
+
286
+ async def get_server_tools(self, server_name: str) -> List[McpToolMetadata]:
287
+ """Get tools from a specific server."""
288
+ return await self.client.discover_server_tools(server_name)
289
+
290
+ async def get_all_available_tools(self) -> Dict[str, List[McpToolMetadata]]:
291
+ """Get all available tools from all registered servers."""
292
+ return await self.client.get_all_tools()
293
+
294
+ def get_server_health(self) -> Dict[str, Dict[str, Any]]:
295
+ """Get health status of all servers."""
296
+ status_info = {}
297
+
298
+ for name, server_info in self.client.get_all_server_status().items():
299
+ status_info[name] = {
300
+ "status": server_info.status,
301
+ "url": server_info.url,
302
+ "last_discovery": server_info.last_discovery.isoformat() if server_info.last_discovery else None,
303
+ "tool_count": len(server_info.tools),
304
+ "error": server_info.error
305
+ }
306
+
307
+ return status_info
308
+
309
+ async def refresh_server(self, server_name: str):
310
+ """Force refresh tools from a specific server."""
311
+ await self.client.discover_server_tools(server_name, force=True)
312
+
313
+ async def refresh_all_servers(self):
314
+ """Force refresh tools from all servers."""
315
+ for server_name in self.client.servers:
316
+ await self.client.discover_server_tools(server_name, force=True)
317
+
318
+
319
+ # Global discovery service instance
320
+ _discovery_service: Optional[McpDiscoveryService] = None
321
+
322
+
323
+ def get_discovery_service() -> McpDiscoveryService:
324
+ """Get the global MCP discovery service instance."""
325
+ global _discovery_service
326
+ if _discovery_service is None:
327
+ _discovery_service = McpDiscoveryService()
328
+ return _discovery_service
329
+
330
+
331
+ async def init_discovery_service():
332
+ """Initialize the global discovery service."""
333
+ service = get_discovery_service()
334
+ await service.start()
335
+
336
+
337
+ async def shutdown_discovery_service():
338
+ """Shutdown the global discovery service."""
339
+ global _discovery_service
340
+ if _discovery_service:
341
+ await _discovery_service.stop()
342
+ _discovery_service = None