datarobot-genai 0.2.31__tar.gz → 0.2.41__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.
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/PKG-INFO +1 -1
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/pyproject.toml +2 -1
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/cli/agent_kernel.py +4 -1
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/utils/auth.py +188 -31
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/exceptions.py +0 -4
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/logging.py +2 -2
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/clients/base.py +1 -1
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/mcp_utils_ete.py +20 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/gdrive.py +91 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/microsoft_graph.py +171 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/confluence/tools.py +43 -89
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/gdrive/tools.py +115 -58
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/jira/tools.py +15 -33
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/microsoft_graph/tools.py +152 -20
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/data.py +5 -5
- datarobot_genai-0.2.41/src/datarobot_genai/drmcp/tools/predictive/deployment.py +97 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/deployment_info.py +100 -107
- datarobot_genai-0.2.41/src/datarobot_genai/drmcp/tools/predictive/model.py +183 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/project.py +2 -2
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/training.py +52 -24
- datarobot_genai-0.2.31/src/datarobot_genai/drmcp/tools/predictive/deployment.py +0 -91
- datarobot_genai-0.2.31/src/datarobot_genai/drmcp/tools/predictive/model.py +0 -148
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/.gitignore +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/AUTHORS +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/LICENSE +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/README.md +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/agents/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/agents/base.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/chat/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/chat/auth.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/chat/client.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/chat/responses.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/cli/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/cli/agent_environment.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/custom_model.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/mcp/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/mcp/common.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/telemetry_agent.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/utils/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/utils/urls.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/crewai/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/crewai/agent.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/crewai/base.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/crewai/events.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/crewai/mcp.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/auth.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/clients.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/config.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/config_utils.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/constants.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/credentials.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dr_mcp_server.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dr_mcp_server_logo.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_prompts/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_prompts/controllers.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_prompts/dr_lib.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_prompts/register.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_prompts/utils.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/base.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/default.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/drum.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/config.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/controllers.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/metadata.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/register.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_agentic_fallback_schema.json +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_prediction_fallback_schema.json +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/register.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/dynamic_tools/schema.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/mcp_instance.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/memory_management/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/memory_management/manager.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/memory_management/memory_tools.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/routes.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/routes_utils.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/server_life_cycle.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/telemetry.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/tool_config.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/tool_filter.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/core/utils.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/server.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/clients/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/clients/anthropic.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/clients/dr_gateway.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/clients/openai.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/elicitation_test_tool.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/integration_mcp_server.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/mcp_utils_integration.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/test_interactive.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/tool_base_ete.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/test_utils/utils.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/atlassian.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/confluence.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/jira.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/s3.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/confluence/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/gdrive/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/jira/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/microsoft_graph/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/predict.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/predictive/predict_realtime.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/langgraph/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/langgraph/agent.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/langgraph/mcp.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/llama_index/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/llama_index/agent.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/llama_index/base.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/llama_index/mcp.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/__init__.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/agent.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/datarobot_auth_provider.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/datarobot_llm_clients.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/datarobot_llm_providers.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/datarobot_mcp_client.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/nat/helpers.py +0 -0
- {datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/py.typed +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "datarobot-genai"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.41"
|
|
8
8
|
description = "Generic helpers for GenAI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10, <3.13"
|
|
@@ -130,6 +130,7 @@ dev = [
|
|
|
130
130
|
"pytest-asyncio>=0.23.5",
|
|
131
131
|
"responses>=0.25.8",
|
|
132
132
|
"ipdb>=0.13.13",
|
|
133
|
+
"aioresponses>=0.7.8",
|
|
133
134
|
]
|
|
134
135
|
|
|
135
136
|
|
{datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/core/cli/agent_kernel.py
RENAMED
|
@@ -107,7 +107,10 @@ class AgentKernel:
|
|
|
107
107
|
stream: bool = False,
|
|
108
108
|
config: Any | None = None,
|
|
109
109
|
) -> ChatCompletion | Stream[ChatCompletionChunk]:
|
|
110
|
-
|
|
110
|
+
if config is not None:
|
|
111
|
+
chat_api_url = f"http://localhost:{config.local_dev_port}"
|
|
112
|
+
else:
|
|
113
|
+
chat_api_url = self.base_url
|
|
111
114
|
print(chat_api_url)
|
|
112
115
|
|
|
113
116
|
return self._do_chat_completion(chat_api_url, user_prompt, completion_json, stream=stream)
|
|
@@ -12,13 +12,19 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import logging
|
|
15
|
+
import os
|
|
15
16
|
import warnings
|
|
17
|
+
from collections.abc import Sequence
|
|
16
18
|
from typing import Any
|
|
19
|
+
from typing import Protocol
|
|
17
20
|
|
|
21
|
+
import aiohttp
|
|
18
22
|
import jwt
|
|
19
|
-
from datarobot.auth.datarobot.oauth import AsyncOAuth as
|
|
23
|
+
from datarobot.auth.datarobot.oauth import AsyncOAuth as DatarobotOAuthClient
|
|
24
|
+
from datarobot.auth.exceptions import OAuthProviderNotFound
|
|
25
|
+
from datarobot.auth.exceptions import OAuthValidationErr
|
|
20
26
|
from datarobot.auth.identity import Identity
|
|
21
|
-
from datarobot.auth.oauth import
|
|
27
|
+
from datarobot.auth.oauth import OAuthToken
|
|
22
28
|
from datarobot.auth.session import AuthCtx
|
|
23
29
|
from datarobot.core.config import DataRobotAppFrameworkBaseSettings
|
|
24
30
|
from datarobot.models.genai.agent.auth import ToolAuth
|
|
@@ -183,52 +189,203 @@ class AuthContextHeaderHandler:
|
|
|
183
189
|
return None
|
|
184
190
|
|
|
185
191
|
|
|
192
|
+
# --- OAuth Token Provider Implementation ---
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
class TokenRetriever(Protocol):
|
|
196
|
+
"""Protocol for OAuth token retrievers."""
|
|
197
|
+
|
|
198
|
+
def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
|
|
199
|
+
"""Filter identities to only those valid for this retriever implementation."""
|
|
200
|
+
...
|
|
201
|
+
|
|
202
|
+
async def refresh_access_token(self, identity: Identity) -> OAuthToken:
|
|
203
|
+
"""Refresh the access token for the given identity ID.
|
|
204
|
+
|
|
205
|
+
Parameters
|
|
206
|
+
----------
|
|
207
|
+
identity_id : str
|
|
208
|
+
The provider identity ID to refresh the token for.
|
|
209
|
+
|
|
210
|
+
Returns
|
|
211
|
+
-------
|
|
212
|
+
OAuthToken
|
|
213
|
+
The refreshed OAuth token.
|
|
214
|
+
"""
|
|
215
|
+
...
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class DatarobotTokenRetriever:
|
|
219
|
+
"""Retrieves OAuth tokens using the DataRobot platform."""
|
|
220
|
+
|
|
221
|
+
def __init__(self) -> None:
|
|
222
|
+
self._client = DatarobotOAuthClient()
|
|
223
|
+
|
|
224
|
+
def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
|
|
225
|
+
"""Filter oauth2 identities to only those with provider_identity_id.
|
|
226
|
+
|
|
227
|
+
The `provider_identity_id` is required in order to identify the provider
|
|
228
|
+
and retrieve the access token from DataRobot OAuth Providers service.
|
|
229
|
+
"""
|
|
230
|
+
return [i for i in identities if i.type == "oauth2" and i.provider_identity_id]
|
|
231
|
+
|
|
232
|
+
async def refresh_access_token(self, identity: Identity) -> OAuthToken:
|
|
233
|
+
"""Refresh the access token using DataRobot's OAuth client."""
|
|
234
|
+
return await self._client.refresh_access_token(identity_id=identity.provider_identity_id)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class AuthlibTokenRetriever:
|
|
238
|
+
"""Retrieves OAuth tokens from a generic Authlib-based endpoint."""
|
|
239
|
+
|
|
240
|
+
def __init__(self, application_endpoint: str) -> None:
|
|
241
|
+
if not application_endpoint:
|
|
242
|
+
raise ValueError("AuthlibTokenRetriever requires 'application_endpoint'.")
|
|
243
|
+
self.application_endpoint = application_endpoint.rstrip("/")
|
|
244
|
+
|
|
245
|
+
def filter_identities(self, identities: Sequence[Identity]) -> list[Identity]:
|
|
246
|
+
"""Filter identities to only OAuth2 identities."""
|
|
247
|
+
return [i for i in identities if i.type == "oauth2" and i.provider_identity_id is None]
|
|
248
|
+
|
|
249
|
+
async def refresh_access_token(self, identity: Identity) -> OAuthToken:
|
|
250
|
+
"""Retrieve an OAuth token via an HTTP POST request.
|
|
251
|
+
|
|
252
|
+
Parameters
|
|
253
|
+
----------
|
|
254
|
+
identity : Identity
|
|
255
|
+
The identity to retrieve the token for.
|
|
256
|
+
|
|
257
|
+
Returns
|
|
258
|
+
-------
|
|
259
|
+
OAuthToken
|
|
260
|
+
The retrieved OAuth token.
|
|
261
|
+
"""
|
|
262
|
+
api_token = os.environ.get("DATAROBOT_API_TOKEN")
|
|
263
|
+
if not api_token:
|
|
264
|
+
raise ValueError("DATAROBOT_API_TOKEN environment variable is required but not set.")
|
|
265
|
+
|
|
266
|
+
token_url = f"{self.application_endpoint}/oauth/token/"
|
|
267
|
+
headers = {"Authorization": f"Bearer {api_token}"}
|
|
268
|
+
payload = {"identity_id": identity.id}
|
|
269
|
+
timeout = aiohttp.ClientTimeout(total=30)
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
273
|
+
async with session.post(token_url, headers=headers, json=payload) as response:
|
|
274
|
+
response.raise_for_status()
|
|
275
|
+
data = await response.json()
|
|
276
|
+
logger.debug(f"Retrieved access token from {token_url}")
|
|
277
|
+
return OAuthToken(**data)
|
|
278
|
+
except aiohttp.ClientError as e:
|
|
279
|
+
logger.error(f"Error retrieving token from {token_url}: {e}")
|
|
280
|
+
raise
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
class OAuthConfig(BaseModel):
|
|
284
|
+
"""Configuration extracted from AuthCtx metadata for OAuth operations."""
|
|
285
|
+
|
|
286
|
+
implementation: str = "datarobot"
|
|
287
|
+
application_endpoint: str | None = None
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
def from_auth_ctx(cls, auth_ctx: AuthCtx) -> "OAuthConfig":
|
|
291
|
+
metadata = auth_ctx.metadata or {}
|
|
292
|
+
return cls(
|
|
293
|
+
implementation=metadata.get("oauth_implementation", "datarobot"),
|
|
294
|
+
application_endpoint=metadata.get("application_endpoint"),
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def create_token_retriever(config: OAuthConfig) -> TokenRetriever:
|
|
299
|
+
"""Create a token retriever based on the OAuth configuration.
|
|
300
|
+
|
|
301
|
+
Parameters
|
|
302
|
+
----------
|
|
303
|
+
config : OAuthConfig
|
|
304
|
+
The OAuth configuration specifying implementation type and endpoints.
|
|
305
|
+
|
|
306
|
+
Returns
|
|
307
|
+
-------
|
|
308
|
+
TokenRetriever
|
|
309
|
+
The configured token retriever instance.
|
|
310
|
+
"""
|
|
311
|
+
if config.implementation == "datarobot":
|
|
312
|
+
return DatarobotTokenRetriever()
|
|
313
|
+
|
|
314
|
+
if config.implementation == "authlib":
|
|
315
|
+
if not config.application_endpoint:
|
|
316
|
+
raise ValueError("Required 'application_endpoint' not found in metadata.")
|
|
317
|
+
return AuthlibTokenRetriever(config.application_endpoint)
|
|
318
|
+
|
|
319
|
+
raise ValueError(
|
|
320
|
+
f"Unsupported OAuth implementation: '{config.implementation}'. "
|
|
321
|
+
f"Supported values: datarobot, authlib."
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
|
|
186
325
|
class AsyncOAuthTokenProvider:
|
|
187
|
-
"""
|
|
326
|
+
"""Provides OAuth tokens for authorized users.
|
|
327
|
+
|
|
328
|
+
This class manages OAuth token retrieval for users with multiple identity providers.
|
|
329
|
+
It uses either DataRobot or Authlib as the OAuth token storage and refresh backend
|
|
330
|
+
based on the auth context metadata.
|
|
331
|
+
"""
|
|
188
332
|
|
|
189
333
|
def __init__(self, auth_ctx: AuthCtx) -> None:
|
|
334
|
+
"""Initialize the provider with an authorization context.
|
|
335
|
+
|
|
336
|
+
Parameters
|
|
337
|
+
----------
|
|
338
|
+
auth_ctx : AuthCtx
|
|
339
|
+
The authorization context containing user identities and metadata.
|
|
340
|
+
"""
|
|
190
341
|
self.auth_ctx = auth_ctx
|
|
191
|
-
|
|
342
|
+
config = OAuthConfig.from_auth_ctx(auth_ctx)
|
|
343
|
+
self._retriever = create_token_retriever(config)
|
|
192
344
|
|
|
193
345
|
def _get_identity(self, provider_type: str | None) -> Identity:
|
|
194
|
-
"""
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
raise ValueError("No identities found in authorization context.")
|
|
346
|
+
"""Get identity from auth context, filtered by provider_type if specified."""
|
|
347
|
+
oauth_identities = self._retriever.filter_identities(self.auth_ctx.identities)
|
|
348
|
+
if not oauth_identities:
|
|
349
|
+
raise OAuthProviderNotFound("No OAuth provider found.")
|
|
199
350
|
|
|
200
351
|
if provider_type is None:
|
|
201
|
-
if len(
|
|
202
|
-
raise
|
|
203
|
-
"Multiple
|
|
352
|
+
if len(oauth_identities) > 1:
|
|
353
|
+
raise OAuthValidationErr(
|
|
354
|
+
"Multiple OAuth providers found. Specify 'provider_type' parameter."
|
|
204
355
|
)
|
|
205
|
-
return
|
|
206
|
-
|
|
207
|
-
identity = next((id for id in identities if id.provider_type == provider_type), None)
|
|
356
|
+
return oauth_identities[0]
|
|
208
357
|
|
|
358
|
+
identity = next((i for i in oauth_identities if i.provider_type == provider_type), None)
|
|
209
359
|
if identity is None:
|
|
210
|
-
raise
|
|
211
|
-
|
|
360
|
+
raise OAuthValidationErr(f"No identity found for provider '{provider_type}'.")
|
|
212
361
|
return identity
|
|
213
362
|
|
|
214
363
|
async def get_token(self, auth_type: ToolAuth, provider_type: str | None = None) -> str:
|
|
215
|
-
"""Get OAuth access token
|
|
364
|
+
"""Get an OAuth access token for the specified auth type and provider.
|
|
365
|
+
|
|
366
|
+
Parameters
|
|
367
|
+
----------
|
|
368
|
+
auth_type : ToolAuth
|
|
369
|
+
Authentication type (only OBO is supported).
|
|
370
|
+
provider_type : str, optional
|
|
371
|
+
The specific provider to use (e.g., 'google'). Required if multiple
|
|
372
|
+
identities are available.
|
|
373
|
+
|
|
374
|
+
Returns
|
|
375
|
+
-------
|
|
376
|
+
str
|
|
377
|
+
The retrieved OAuth access token.
|
|
378
|
+
|
|
379
|
+
Raises
|
|
380
|
+
------
|
|
381
|
+
ValueError
|
|
382
|
+
If the auth type is unsupported or if a suitable identity cannot be found.
|
|
383
|
+
"""
|
|
216
384
|
if auth_type != ToolAuth.OBO:
|
|
217
385
|
raise ValueError(
|
|
218
|
-
f"Unsupported auth type: {auth_type}. Only
|
|
386
|
+
f"Unsupported auth type: {auth_type}. Only OBO (on-behalf-of) is supported."
|
|
219
387
|
)
|
|
220
388
|
|
|
221
389
|
identity = self._get_identity(provider_type)
|
|
222
|
-
token_data = await self.
|
|
223
|
-
identity_id=identity.provider_identity_id
|
|
224
|
-
)
|
|
390
|
+
token_data = await self._retriever.refresh_access_token(identity)
|
|
225
391
|
return token_data.access_token
|
|
226
|
-
|
|
227
|
-
def _create_oauth_client(self) -> AsyncOAuthComponent:
|
|
228
|
-
"""Create either DataRobot or Authlib OAuth client based on
|
|
229
|
-
authorization context.
|
|
230
|
-
|
|
231
|
-
Note: at the moment, only DataRobot OAuth client is supported.
|
|
232
|
-
"""
|
|
233
|
-
logger.debug("Using DataRobot OAuth client")
|
|
234
|
-
return DatarobotAsyncOAuthClient()
|
|
@@ -20,7 +20,7 @@ from collections.abc import Callable
|
|
|
20
20
|
from typing import Any
|
|
21
21
|
from typing import TypeVar
|
|
22
22
|
|
|
23
|
-
from .exceptions import
|
|
23
|
+
from fastmcp.exceptions import ToolError
|
|
24
24
|
|
|
25
25
|
# Secret patterns to redact from logs
|
|
26
26
|
SECRET_PATTERNS = [
|
|
@@ -93,6 +93,6 @@ def log_execution(func: F) -> F:
|
|
|
93
93
|
return result
|
|
94
94
|
except Exception as e:
|
|
95
95
|
error_msg = _log_error(logger, func.__name__, e, args=args, kwargs=kwargs)
|
|
96
|
-
raise
|
|
96
|
+
raise ToolError(error_msg)
|
|
97
97
|
|
|
98
98
|
return wrapper # type: ignore[return-value]
|
|
@@ -27,7 +27,7 @@ from mcp.types import ListToolsResult
|
|
|
27
27
|
from mcp.types import TextContent
|
|
28
28
|
from openai.types.chat.chat_completion import ChatCompletion
|
|
29
29
|
|
|
30
|
-
from
|
|
30
|
+
from datarobot_genai.drmcp.test_utils.utils import save_response_to_file
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
class ToolCall:
|
|
@@ -68,6 +68,26 @@ def get_openai_llm_client_config() -> dict[str, str]:
|
|
|
68
68
|
return config
|
|
69
69
|
|
|
70
70
|
|
|
71
|
+
def get_dr_llm_gateway_client_config() -> dict[str, str]:
|
|
72
|
+
"""Get DataRobot LLM Gateway client configuration."""
|
|
73
|
+
datarobot_api_token = os.environ.get("DATAROBOT_API_TOKEN")
|
|
74
|
+
datarobot_endpoint = os.environ.get("DATAROBOT_ENDPOINT")
|
|
75
|
+
save_llm_responses = os.environ.get("SAVE_LLM_RESPONSES", "false").lower() == "true"
|
|
76
|
+
|
|
77
|
+
if not datarobot_api_token:
|
|
78
|
+
raise ValueError("Missing required environment variable: DATAROBOT_API_TOKEN")
|
|
79
|
+
|
|
80
|
+
config: dict[str, str] = {
|
|
81
|
+
"datarobot_api_token": datarobot_api_token,
|
|
82
|
+
"save_llm_responses": str(save_llm_responses),
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if datarobot_endpoint:
|
|
86
|
+
config["datarobot_endpoint"] = datarobot_endpoint
|
|
87
|
+
|
|
88
|
+
return config
|
|
89
|
+
|
|
90
|
+
|
|
71
91
|
def get_headers() -> dict[str, str]:
|
|
72
92
|
# When the MCP server is deployed in DataRobot, we have to include the API token in headers for
|
|
73
93
|
# authentication.
|
{datarobot_genai-0.2.31 → datarobot_genai-0.2.41}/src/datarobot_genai/drmcp/tools/clients/gdrive.py
RENAMED
|
@@ -20,6 +20,7 @@ import logging
|
|
|
20
20
|
import uuid
|
|
21
21
|
from typing import Annotated
|
|
22
22
|
from typing import Any
|
|
23
|
+
from typing import Literal
|
|
23
24
|
|
|
24
25
|
import httpx
|
|
25
26
|
from datarobot.auth.datarobot.exceptions import OAuthServiceClientErr
|
|
@@ -821,6 +822,96 @@ class GoogleDriveClient:
|
|
|
821
822
|
headers={"Content-Type": f"multipart/related; boundary={boundary}"},
|
|
822
823
|
)
|
|
823
824
|
|
|
825
|
+
async def manage_access(
|
|
826
|
+
self,
|
|
827
|
+
*,
|
|
828
|
+
file_id: str,
|
|
829
|
+
action: Literal["add", "update", "remove"],
|
|
830
|
+
role: Literal["reader", "commenter", "writer", "fileOrganizer", "organizer", "owner"]
|
|
831
|
+
| None = None,
|
|
832
|
+
email_address: str | None = None,
|
|
833
|
+
permission_id: str | None = None,
|
|
834
|
+
transfer_ownership: bool = False,
|
|
835
|
+
) -> str:
|
|
836
|
+
"""Manage access permissions for a Google Drive file or folder.
|
|
837
|
+
|
|
838
|
+
Adds, updates, or removes sharing permissions on an existing Google Drive
|
|
839
|
+
file or folder using the Google Drive Permissions API.
|
|
840
|
+
|
|
841
|
+
This method supports granting access to users or groups, changing access
|
|
842
|
+
roles, and revoking permissions. Ownership transfer is supported for files
|
|
843
|
+
in "My Drive" when explicitly requested.
|
|
844
|
+
|
|
845
|
+
Args:
|
|
846
|
+
file_id: The ID of the Google Drive file or folder whose permissions
|
|
847
|
+
are being managed.
|
|
848
|
+
action: The permission operation to perform.
|
|
849
|
+
role: The access role to assign or update. Valid values include
|
|
850
|
+
Required for "add" and "update" actions.
|
|
851
|
+
email_address: The email address of the user or group to grant access to.
|
|
852
|
+
Required for the "add" action.
|
|
853
|
+
permission_id: The ID of the permission to update or remove.
|
|
854
|
+
Required for "update" and "remove" actions.
|
|
855
|
+
transfer_ownership: Whether to transfer ownership of the file.
|
|
856
|
+
Only applicable when action="update" and role="owner".
|
|
857
|
+
|
|
858
|
+
Returns
|
|
859
|
+
-------
|
|
860
|
+
Permission id.
|
|
861
|
+
For "add" its newly added permission.
|
|
862
|
+
For "update"/"remove" its previous permission.
|
|
863
|
+
|
|
864
|
+
Raises
|
|
865
|
+
------
|
|
866
|
+
GoogleDriveError: If the permission operation fails (invalid arguments,
|
|
867
|
+
insufficient permissions, resource not found, ownership transfer
|
|
868
|
+
not allowed, rate limited, etc.).
|
|
869
|
+
"""
|
|
870
|
+
if not file_id.strip():
|
|
871
|
+
raise GoogleDriveError("Argument validation error: 'file_id' cannot be empty.")
|
|
872
|
+
|
|
873
|
+
if action == "add" and not email_address:
|
|
874
|
+
raise GoogleDriveError("'email_address' is required for action 'add'.")
|
|
875
|
+
|
|
876
|
+
if action in ("update", "remove") and not permission_id:
|
|
877
|
+
raise GoogleDriveError("'permission_id' is required for action 'update' or 'remove'.")
|
|
878
|
+
|
|
879
|
+
if action != "remove" and not role:
|
|
880
|
+
raise GoogleDriveError("'role' is required for action 'add' or 'update'.")
|
|
881
|
+
|
|
882
|
+
if action == "add":
|
|
883
|
+
response = await self._client.post(
|
|
884
|
+
url=f"/{file_id}/permissions",
|
|
885
|
+
json={
|
|
886
|
+
"type": "user",
|
|
887
|
+
"role": role,
|
|
888
|
+
"emailAddress": email_address,
|
|
889
|
+
},
|
|
890
|
+
params={"sendNotificationEmail": False, "supportsAllDrives": True},
|
|
891
|
+
)
|
|
892
|
+
|
|
893
|
+
elif action == "update":
|
|
894
|
+
response = await self._client.patch(
|
|
895
|
+
url=f"/{file_id}/permissions/{permission_id}",
|
|
896
|
+
json={"role": role},
|
|
897
|
+
params={"transferOwnership": transfer_ownership, "supportsAllDrives": True},
|
|
898
|
+
)
|
|
899
|
+
|
|
900
|
+
elif action == "remove":
|
|
901
|
+
response = await self._client.delete(url=f"/{file_id}/permissions/{permission_id}")
|
|
902
|
+
|
|
903
|
+
else:
|
|
904
|
+
raise GoogleDriveError(f"Invalid action '{action}'")
|
|
905
|
+
|
|
906
|
+
if response.status_code not in (200, 201, 204):
|
|
907
|
+
raise GoogleDriveError(f"Drive API error {response.status_code}: {response.text}")
|
|
908
|
+
|
|
909
|
+
if action == "add":
|
|
910
|
+
return response.json()["id"]
|
|
911
|
+
|
|
912
|
+
# Cannot be null here because of above validators
|
|
913
|
+
return permission_id # type: ignore
|
|
914
|
+
|
|
824
915
|
async def __aenter__(self) -> "GoogleDriveClient":
|
|
825
916
|
"""Async context manager entry."""
|
|
826
917
|
return self
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
import logging
|
|
18
18
|
from typing import Any
|
|
19
|
+
from typing import Literal
|
|
20
|
+
from urllib.parse import quote
|
|
19
21
|
|
|
20
22
|
import httpx
|
|
21
23
|
from datarobot.auth.datarobot.exceptions import OAuthServiceClientErr
|
|
@@ -415,6 +417,175 @@ class MicrosoftGraphClient:
|
|
|
415
417
|
|
|
416
418
|
return base_resource
|
|
417
419
|
|
|
420
|
+
async def get_personal_drive_id(self) -> str:
|
|
421
|
+
"""Get the current user's personal OneDrive drive ID.
|
|
422
|
+
|
|
423
|
+
Returns
|
|
424
|
+
-------
|
|
425
|
+
The drive ID string for the user's personal OneDrive.
|
|
426
|
+
|
|
427
|
+
Raises
|
|
428
|
+
------
|
|
429
|
+
MicrosoftGraphError: If the drive cannot be retrieved.
|
|
430
|
+
"""
|
|
431
|
+
try:
|
|
432
|
+
response = await self._client.get(f"{GRAPH_API_BASE}/me/drive")
|
|
433
|
+
response.raise_for_status()
|
|
434
|
+
data = response.json()
|
|
435
|
+
return data["id"]
|
|
436
|
+
except httpx.HTTPStatusError as e:
|
|
437
|
+
status_code = e.response.status_code
|
|
438
|
+
if status_code == 401:
|
|
439
|
+
raise MicrosoftGraphError(
|
|
440
|
+
"Authentication failed. Access token may be expired or invalid."
|
|
441
|
+
) from e
|
|
442
|
+
if status_code == 403:
|
|
443
|
+
raise MicrosoftGraphError(
|
|
444
|
+
"Permission denied: cannot access personal OneDrive. "
|
|
445
|
+
"Requires Files.Read or Files.ReadWrite permission."
|
|
446
|
+
) from e
|
|
447
|
+
raise MicrosoftGraphError(f"Failed to get personal OneDrive: HTTP {status_code}") from e
|
|
448
|
+
|
|
449
|
+
async def create_file(
|
|
450
|
+
self,
|
|
451
|
+
drive_id: str,
|
|
452
|
+
file_name: str,
|
|
453
|
+
content: str,
|
|
454
|
+
parent_folder_id: str = "root",
|
|
455
|
+
conflict_behavior: str = "rename",
|
|
456
|
+
) -> MicrosoftGraphItem:
|
|
457
|
+
"""Create a text file in a drive (SharePoint document library or OneDrive).
|
|
458
|
+
|
|
459
|
+
Uses Microsoft Graph's simple upload endpoint for files < 4MB.
|
|
460
|
+
Files are created as text/plain content.
|
|
461
|
+
|
|
462
|
+
Args:
|
|
463
|
+
drive_id: The ID of the drive (document library) where the file will be created.
|
|
464
|
+
file_name: The name of the file to create (e.g., 'report.txt').
|
|
465
|
+
content: The text content to store in the file.
|
|
466
|
+
parent_folder_id: ID of the parent folder. Defaults to "root" (drive root folder).
|
|
467
|
+
conflict_behavior: How to handle name conflicts. Options:
|
|
468
|
+
- "rename" (default): Auto-renames to 'filename (1).txt', etc.
|
|
469
|
+
- "fail": Returns 409 Conflict error
|
|
470
|
+
- "replace": Overwrites existing file
|
|
471
|
+
|
|
472
|
+
Returns
|
|
473
|
+
-------
|
|
474
|
+
MicrosoftGraphItem representing the created file.
|
|
475
|
+
|
|
476
|
+
Raises
|
|
477
|
+
------
|
|
478
|
+
MicrosoftGraphError: If file creation fails.
|
|
479
|
+
"""
|
|
480
|
+
if not drive_id or not drive_id.strip():
|
|
481
|
+
raise MicrosoftGraphError("drive_id cannot be empty")
|
|
482
|
+
if not file_name or not file_name.strip():
|
|
483
|
+
raise MicrosoftGraphError("file_name cannot be empty")
|
|
484
|
+
|
|
485
|
+
# URL encode the filename for path-based addressing
|
|
486
|
+
encoded_name = quote(file_name, safe="")
|
|
487
|
+
|
|
488
|
+
# Simple upload endpoint for files < 4MB
|
|
489
|
+
# Reference: https://learn.microsoft.com/en-us/graph/api/driveitem-put-content
|
|
490
|
+
upload_url = (
|
|
491
|
+
f"{GRAPH_API_BASE}/drives/{drive_id}/items/{parent_folder_id}:/{encoded_name}:/content"
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
try:
|
|
495
|
+
response = await self._client.put(
|
|
496
|
+
upload_url,
|
|
497
|
+
content=content.encode("utf-8"),
|
|
498
|
+
headers={"Content-Type": "text/plain"},
|
|
499
|
+
params={"@microsoft.graph.conflictBehavior": conflict_behavior},
|
|
500
|
+
)
|
|
501
|
+
response.raise_for_status()
|
|
502
|
+
except httpx.HTTPStatusError as e:
|
|
503
|
+
raise self._handle_create_file_error(e, drive_id, file_name, parent_folder_id) from e
|
|
504
|
+
|
|
505
|
+
return MicrosoftGraphItem.from_api_response(response.json())
|
|
506
|
+
|
|
507
|
+
def _handle_create_file_error(
|
|
508
|
+
self,
|
|
509
|
+
error: httpx.HTTPStatusError,
|
|
510
|
+
drive_id: str,
|
|
511
|
+
file_name: str,
|
|
512
|
+
parent_folder_id: str,
|
|
513
|
+
) -> MicrosoftGraphError:
|
|
514
|
+
"""Handle HTTP errors for file creation and return appropriate MicrosoftGraphError."""
|
|
515
|
+
status_code = error.response.status_code
|
|
516
|
+
error_msg = f"Failed to create file: HTTP {status_code}"
|
|
517
|
+
|
|
518
|
+
if status_code == 400:
|
|
519
|
+
try:
|
|
520
|
+
error_data = error.response.json()
|
|
521
|
+
api_message = error_data.get("error", {}).get("message", "Invalid request")
|
|
522
|
+
error_msg = f"Bad request creating file: {api_message}"
|
|
523
|
+
except Exception:
|
|
524
|
+
error_msg = "Bad request: invalid parameters for file creation."
|
|
525
|
+
elif status_code == 401:
|
|
526
|
+
error_msg = "Authentication failed. Access token may be expired or invalid."
|
|
527
|
+
elif status_code == 403:
|
|
528
|
+
error_msg = (
|
|
529
|
+
f"Permission denied: you don't have permission to create files in drive "
|
|
530
|
+
f"'{drive_id}'. Requires Files.ReadWrite.All permission."
|
|
531
|
+
)
|
|
532
|
+
elif status_code == 404:
|
|
533
|
+
error_msg = (
|
|
534
|
+
f"Parent folder '{parent_folder_id}' not found in drive '{drive_id}'."
|
|
535
|
+
if parent_folder_id != "root"
|
|
536
|
+
else f"Drive '{drive_id}' not found."
|
|
537
|
+
)
|
|
538
|
+
elif status_code == 409:
|
|
539
|
+
error_msg = f"File '{file_name}' already exists and conflict behavior is set to 'fail'."
|
|
540
|
+
elif status_code == 429:
|
|
541
|
+
error_msg = "Rate limit exceeded. Please try again later."
|
|
542
|
+
|
|
543
|
+
return MicrosoftGraphError(error_msg)
|
|
544
|
+
|
|
545
|
+
async def share_item(
|
|
546
|
+
self,
|
|
547
|
+
file_id: str,
|
|
548
|
+
document_library_id: str,
|
|
549
|
+
recipient_emails: list[str],
|
|
550
|
+
role: Literal["read", "write"],
|
|
551
|
+
send_invitation: bool,
|
|
552
|
+
) -> None:
|
|
553
|
+
"""
|
|
554
|
+
Share sharepoint / ondrive item using Microsoft Graph API.
|
|
555
|
+
Under the hood all resources in sharepoint/onedrive
|
|
556
|
+
in MS Graph API are treated as 'driveItem'.
|
|
557
|
+
|
|
558
|
+
Args:
|
|
559
|
+
file_id: The ID of the file or folder to share.
|
|
560
|
+
document_library_id: The ID of the document library containing the item.
|
|
561
|
+
recipient_emails: A list of email addresses to invite.
|
|
562
|
+
role: The role to assign.
|
|
563
|
+
send_invitation: Flag determining if recipients should be notified
|
|
564
|
+
|
|
565
|
+
Returns
|
|
566
|
+
-------
|
|
567
|
+
None
|
|
568
|
+
|
|
569
|
+
Raises
|
|
570
|
+
------
|
|
571
|
+
MicrosoftGraphError: If sharing fails
|
|
572
|
+
"""
|
|
573
|
+
graph_url = f"{GRAPH_API_BASE}/drives/{document_library_id}/items/{file_id}/invite"
|
|
574
|
+
|
|
575
|
+
payload = {
|
|
576
|
+
"recipients": [{"email": email} for email in recipient_emails],
|
|
577
|
+
"requireSignIn": True,
|
|
578
|
+
"sendInvitation": send_invitation,
|
|
579
|
+
"roles": [role],
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
response = await self._client.post(url=graph_url, json=payload)
|
|
583
|
+
|
|
584
|
+
if response.status_code not in (200, 201):
|
|
585
|
+
raise MicrosoftGraphError(
|
|
586
|
+
f"Microsoft Graph API error {response.status_code}: {response.text}"
|
|
587
|
+
)
|
|
588
|
+
|
|
418
589
|
async def __aenter__(self) -> "MicrosoftGraphClient":
|
|
419
590
|
"""Async context manager entry."""
|
|
420
591
|
return self
|