datarobot-genai 0.2.31__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.
- datarobot_genai/__init__.py +19 -0
- datarobot_genai/core/__init__.py +0 -0
- datarobot_genai/core/agents/__init__.py +43 -0
- datarobot_genai/core/agents/base.py +195 -0
- datarobot_genai/core/chat/__init__.py +19 -0
- datarobot_genai/core/chat/auth.py +146 -0
- datarobot_genai/core/chat/client.py +178 -0
- datarobot_genai/core/chat/responses.py +297 -0
- datarobot_genai/core/cli/__init__.py +18 -0
- datarobot_genai/core/cli/agent_environment.py +47 -0
- datarobot_genai/core/cli/agent_kernel.py +211 -0
- datarobot_genai/core/custom_model.py +141 -0
- datarobot_genai/core/mcp/__init__.py +0 -0
- datarobot_genai/core/mcp/common.py +218 -0
- datarobot_genai/core/telemetry_agent.py +126 -0
- datarobot_genai/core/utils/__init__.py +3 -0
- datarobot_genai/core/utils/auth.py +234 -0
- datarobot_genai/core/utils/urls.py +64 -0
- datarobot_genai/crewai/__init__.py +24 -0
- datarobot_genai/crewai/agent.py +42 -0
- datarobot_genai/crewai/base.py +159 -0
- datarobot_genai/crewai/events.py +117 -0
- datarobot_genai/crewai/mcp.py +59 -0
- datarobot_genai/drmcp/__init__.py +78 -0
- datarobot_genai/drmcp/core/__init__.py +13 -0
- datarobot_genai/drmcp/core/auth.py +165 -0
- datarobot_genai/drmcp/core/clients.py +180 -0
- datarobot_genai/drmcp/core/config.py +364 -0
- datarobot_genai/drmcp/core/config_utils.py +174 -0
- datarobot_genai/drmcp/core/constants.py +18 -0
- datarobot_genai/drmcp/core/credentials.py +190 -0
- datarobot_genai/drmcp/core/dr_mcp_server.py +350 -0
- datarobot_genai/drmcp/core/dr_mcp_server_logo.py +136 -0
- datarobot_genai/drmcp/core/dynamic_prompts/__init__.py +13 -0
- datarobot_genai/drmcp/core/dynamic_prompts/controllers.py +130 -0
- datarobot_genai/drmcp/core/dynamic_prompts/dr_lib.py +70 -0
- datarobot_genai/drmcp/core/dynamic_prompts/register.py +205 -0
- datarobot_genai/drmcp/core/dynamic_prompts/utils.py +33 -0
- datarobot_genai/drmcp/core/dynamic_tools/__init__.py +14 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/__init__.py +0 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/__init__.py +14 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/base.py +72 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/default.py +82 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/drum.py +238 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/config.py +228 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/controllers.py +63 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/metadata.py +162 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/register.py +87 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_agentic_fallback_schema.json +36 -0
- datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_prediction_fallback_schema.json +10 -0
- datarobot_genai/drmcp/core/dynamic_tools/register.py +254 -0
- datarobot_genai/drmcp/core/dynamic_tools/schema.py +532 -0
- datarobot_genai/drmcp/core/exceptions.py +25 -0
- datarobot_genai/drmcp/core/logging.py +98 -0
- datarobot_genai/drmcp/core/mcp_instance.py +515 -0
- datarobot_genai/drmcp/core/memory_management/__init__.py +13 -0
- datarobot_genai/drmcp/core/memory_management/manager.py +820 -0
- datarobot_genai/drmcp/core/memory_management/memory_tools.py +201 -0
- datarobot_genai/drmcp/core/routes.py +439 -0
- datarobot_genai/drmcp/core/routes_utils.py +30 -0
- datarobot_genai/drmcp/core/server_life_cycle.py +107 -0
- datarobot_genai/drmcp/core/telemetry.py +424 -0
- datarobot_genai/drmcp/core/tool_config.py +111 -0
- datarobot_genai/drmcp/core/tool_filter.py +117 -0
- datarobot_genai/drmcp/core/utils.py +138 -0
- datarobot_genai/drmcp/server.py +19 -0
- datarobot_genai/drmcp/test_utils/__init__.py +13 -0
- datarobot_genai/drmcp/test_utils/clients/__init__.py +0 -0
- datarobot_genai/drmcp/test_utils/clients/anthropic.py +68 -0
- datarobot_genai/drmcp/test_utils/clients/base.py +300 -0
- datarobot_genai/drmcp/test_utils/clients/dr_gateway.py +58 -0
- datarobot_genai/drmcp/test_utils/clients/openai.py +68 -0
- datarobot_genai/drmcp/test_utils/elicitation_test_tool.py +89 -0
- datarobot_genai/drmcp/test_utils/integration_mcp_server.py +109 -0
- datarobot_genai/drmcp/test_utils/mcp_utils_ete.py +133 -0
- datarobot_genai/drmcp/test_utils/mcp_utils_integration.py +107 -0
- datarobot_genai/drmcp/test_utils/test_interactive.py +205 -0
- datarobot_genai/drmcp/test_utils/tool_base_ete.py +220 -0
- datarobot_genai/drmcp/test_utils/utils.py +91 -0
- datarobot_genai/drmcp/tools/__init__.py +14 -0
- datarobot_genai/drmcp/tools/clients/__init__.py +14 -0
- datarobot_genai/drmcp/tools/clients/atlassian.py +188 -0
- datarobot_genai/drmcp/tools/clients/confluence.py +584 -0
- datarobot_genai/drmcp/tools/clients/gdrive.py +832 -0
- datarobot_genai/drmcp/tools/clients/jira.py +334 -0
- datarobot_genai/drmcp/tools/clients/microsoft_graph.py +479 -0
- datarobot_genai/drmcp/tools/clients/s3.py +28 -0
- datarobot_genai/drmcp/tools/confluence/__init__.py +14 -0
- datarobot_genai/drmcp/tools/confluence/tools.py +321 -0
- datarobot_genai/drmcp/tools/gdrive/__init__.py +0 -0
- datarobot_genai/drmcp/tools/gdrive/tools.py +347 -0
- datarobot_genai/drmcp/tools/jira/__init__.py +14 -0
- datarobot_genai/drmcp/tools/jira/tools.py +243 -0
- datarobot_genai/drmcp/tools/microsoft_graph/__init__.py +13 -0
- datarobot_genai/drmcp/tools/microsoft_graph/tools.py +198 -0
- datarobot_genai/drmcp/tools/predictive/__init__.py +27 -0
- datarobot_genai/drmcp/tools/predictive/data.py +133 -0
- datarobot_genai/drmcp/tools/predictive/deployment.py +91 -0
- datarobot_genai/drmcp/tools/predictive/deployment_info.py +392 -0
- datarobot_genai/drmcp/tools/predictive/model.py +148 -0
- datarobot_genai/drmcp/tools/predictive/predict.py +254 -0
- datarobot_genai/drmcp/tools/predictive/predict_realtime.py +307 -0
- datarobot_genai/drmcp/tools/predictive/project.py +90 -0
- datarobot_genai/drmcp/tools/predictive/training.py +661 -0
- datarobot_genai/langgraph/__init__.py +0 -0
- datarobot_genai/langgraph/agent.py +341 -0
- datarobot_genai/langgraph/mcp.py +73 -0
- datarobot_genai/llama_index/__init__.py +16 -0
- datarobot_genai/llama_index/agent.py +50 -0
- datarobot_genai/llama_index/base.py +299 -0
- datarobot_genai/llama_index/mcp.py +79 -0
- datarobot_genai/nat/__init__.py +0 -0
- datarobot_genai/nat/agent.py +275 -0
- datarobot_genai/nat/datarobot_auth_provider.py +110 -0
- datarobot_genai/nat/datarobot_llm_clients.py +318 -0
- datarobot_genai/nat/datarobot_llm_providers.py +130 -0
- datarobot_genai/nat/datarobot_mcp_client.py +266 -0
- datarobot_genai/nat/helpers.py +87 -0
- datarobot_genai/py.typed +0 -0
- datarobot_genai-0.2.31.dist-info/METADATA +145 -0
- datarobot_genai-0.2.31.dist-info/RECORD +125 -0
- datarobot_genai-0.2.31.dist-info/WHEEL +4 -0
- datarobot_genai-0.2.31.dist-info/entry_points.txt +5 -0
- datarobot_genai-0.2.31.dist-info/licenses/AUTHORS +2 -0
- datarobot_genai-0.2.31.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Copyright 2025 DataRobot, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Atlassian API client utilities for OAuth and cloud ID management."""
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
from typing import Any
|
|
19
|
+
from typing import Literal
|
|
20
|
+
|
|
21
|
+
import httpx
|
|
22
|
+
from datarobot.auth.datarobot.exceptions import OAuthServiceClientErr
|
|
23
|
+
from fastmcp.exceptions import ToolError
|
|
24
|
+
|
|
25
|
+
from datarobot_genai.drmcp.core.auth import get_access_token
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
# Atlassian Cloud API base URL
|
|
30
|
+
ATLASSIAN_API_BASE = "https://api.atlassian.com"
|
|
31
|
+
|
|
32
|
+
# API endpoint paths
|
|
33
|
+
OAUTH_ACCESSIBLE_RESOURCES_PATH = "/oauth/token/accessible-resources"
|
|
34
|
+
|
|
35
|
+
# Supported Atlassian service types
|
|
36
|
+
AtlassianServiceType = Literal["jira", "confluence"]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def get_atlassian_access_token() -> str | ToolError:
|
|
40
|
+
"""
|
|
41
|
+
Get Atlassian OAuth access token with error handling.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
Access token string on success, ToolError on failure
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
```python
|
|
49
|
+
token = await get_atlassian_access_token()
|
|
50
|
+
if isinstance(token, ToolError):
|
|
51
|
+
# Handle error
|
|
52
|
+
return token
|
|
53
|
+
# Use token
|
|
54
|
+
```
|
|
55
|
+
"""
|
|
56
|
+
try:
|
|
57
|
+
access_token = await get_access_token("atlassian")
|
|
58
|
+
if not access_token:
|
|
59
|
+
logger.warning("Empty access token received")
|
|
60
|
+
return ToolError("Received empty access token. Please complete the OAuth flow.")
|
|
61
|
+
return access_token
|
|
62
|
+
except OAuthServiceClientErr as e:
|
|
63
|
+
logger.error(f"OAuth client error: {e}", exc_info=True)
|
|
64
|
+
return ToolError(
|
|
65
|
+
"Could not obtain access token for Atlassian. Make sure the OAuth "
|
|
66
|
+
"permission was granted for the application to act on your behalf."
|
|
67
|
+
)
|
|
68
|
+
except Exception as e:
|
|
69
|
+
logger.error(f"Unexpected error obtaining access token: {e}", exc_info=True)
|
|
70
|
+
return ToolError("An unexpected error occurred while obtaining access token for Atlassian.")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _find_resource_by_service(
|
|
74
|
+
resources: list[dict[str, Any]], service_type: str
|
|
75
|
+
) -> dict[str, Any] | None:
|
|
76
|
+
"""
|
|
77
|
+
Find a resource that matches the specified service type.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
resources: List of accessible resources from Atlassian API
|
|
81
|
+
service_type: Service type to filter by (e.g., "jira", "confluence")
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
Resource dictionary if found, None otherwise
|
|
86
|
+
"""
|
|
87
|
+
service_lower = service_type.lower()
|
|
88
|
+
for resource in resources:
|
|
89
|
+
if not resource.get("id"):
|
|
90
|
+
continue
|
|
91
|
+
scopes = resource.get("scopes", [])
|
|
92
|
+
if any(service_lower in scope.lower() for scope in scopes):
|
|
93
|
+
return resource
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _find_first_resource_with_id(resources: list[dict[str, Any]]) -> dict[str, Any] | None:
|
|
98
|
+
"""
|
|
99
|
+
Find the first resource that has an ID.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
resources: List of accessible resources from Atlassian API
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
Resource dictionary if found, None otherwise
|
|
107
|
+
"""
|
|
108
|
+
for resource in resources:
|
|
109
|
+
if resource.get("id"):
|
|
110
|
+
return resource
|
|
111
|
+
return None
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
async def get_atlassian_cloud_id(
|
|
115
|
+
client: httpx.AsyncClient,
|
|
116
|
+
service_type: AtlassianServiceType | None = None,
|
|
117
|
+
) -> str:
|
|
118
|
+
"""
|
|
119
|
+
Get the cloud ID for the authenticated Atlassian instance.
|
|
120
|
+
|
|
121
|
+
According to Atlassian OAuth 2.0 documentation, API calls should use:
|
|
122
|
+
https://api.atlassian.com/ex/{service}/{cloudId}/rest/api/3/...
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
client: HTTP client with authentication headers configured
|
|
126
|
+
service_type: Optional service type to filter by (e.g., "jira", "confluence").
|
|
127
|
+
If provided, will prioritize resources matching this service type.
|
|
128
|
+
|
|
129
|
+
Returns
|
|
130
|
+
-------
|
|
131
|
+
Cloud ID string for the Atlassian instance
|
|
132
|
+
|
|
133
|
+
Raises
|
|
134
|
+
------
|
|
135
|
+
ValueError: If cloud ID cannot be retrieved due to:
|
|
136
|
+
- No accessible resources found
|
|
137
|
+
- No cloud ID found in resources
|
|
138
|
+
- Authentication failure (401)
|
|
139
|
+
- HTTP request failure
|
|
140
|
+
|
|
141
|
+
Example:
|
|
142
|
+
```python
|
|
143
|
+
client = httpx.AsyncClient(headers={"Authorization": f"Bearer {token}"})
|
|
144
|
+
cloud_id = await get_atlassian_cloud_id(client, service_type="jira")
|
|
145
|
+
```
|
|
146
|
+
"""
|
|
147
|
+
url = f"{ATLASSIAN_API_BASE}{OAUTH_ACCESSIBLE_RESOURCES_PATH}"
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
response = await client.get(url)
|
|
151
|
+
response.raise_for_status()
|
|
152
|
+
resources = response.json()
|
|
153
|
+
|
|
154
|
+
if not resources:
|
|
155
|
+
raise ValueError(
|
|
156
|
+
"No accessible resources found. Ensure OAuth token has required scopes."
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# If service_type is specified, try to find matching resource
|
|
160
|
+
if service_type:
|
|
161
|
+
resource = _find_resource_by_service(resources, service_type)
|
|
162
|
+
if resource:
|
|
163
|
+
cloud_id = resource["id"]
|
|
164
|
+
logger.debug(f"Using {service_type} cloud ID: {cloud_id}")
|
|
165
|
+
return cloud_id
|
|
166
|
+
logger.warning(
|
|
167
|
+
f"No {service_type} resource found, falling back to first available resource"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Fallback: use the first resource with an ID
|
|
171
|
+
resource = _find_first_resource_with_id(resources)
|
|
172
|
+
if resource:
|
|
173
|
+
cloud_id = resource["id"]
|
|
174
|
+
logger.debug(f"Using cloud ID (fallback): {cloud_id}")
|
|
175
|
+
return cloud_id
|
|
176
|
+
|
|
177
|
+
raise ValueError("No cloud ID found in accessible resources")
|
|
178
|
+
except httpx.HTTPStatusError as e:
|
|
179
|
+
if e.response.status_code == 401:
|
|
180
|
+
raise ValueError(
|
|
181
|
+
"Authentication failed. Token may be expired. "
|
|
182
|
+
"Complete OAuth flow again: GET /oauth/atlassian/authorize"
|
|
183
|
+
) from e
|
|
184
|
+
logger.error(f"HTTP error getting cloud ID: {e.response.status_code}")
|
|
185
|
+
raise ValueError(f"Failed to get Atlassian cloud ID: HTTP {e.response.status_code}") from e
|
|
186
|
+
except httpx.RequestError as e:
|
|
187
|
+
logger.error(f"Request error getting cloud ID: {e}")
|
|
188
|
+
raise ValueError("Failed to get Atlassian cloud ID: Network error") from e
|