datarobot-genai 0.2.9__tar.gz → 0.2.17__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.9 → datarobot_genai-0.2.17}/PKG-INFO +3 -1
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/pyproject.toml +3 -1
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/openai_llm_mcp_client.py +6 -1
- datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/clients/confluence.py +393 -0
- datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/clients/jira.py +334 -0
- datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/confluence/tools.py +188 -0
- datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/jira/tools.py +243 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/agent.py +20 -7
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_llm_clients.py +45 -12
- datarobot_genai-0.2.17/src/datarobot_genai/nat/helpers.py +87 -0
- datarobot_genai-0.2.9/src/datarobot_genai/drmcp/tools/clients/confluence.py +0 -14
- datarobot_genai-0.2.9/src/datarobot_genai/drmcp/tools/clients/jira.py +0 -102
- datarobot_genai-0.2.9/src/datarobot_genai/drmcp/tools/confluence/tools.py +0 -13
- datarobot_genai-0.2.9/src/datarobot_genai/drmcp/tools/jira/tools.py +0 -58
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/.gitignore +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/AUTHORS +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/LICENSE +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/README.md +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/agents/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/agents/base.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/auth.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/client.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/responses.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/cli/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/cli/agent_environment.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/cli/agent_kernel.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/custom_model.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/mcp/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/mcp/common.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/telemetry_agent.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/utils/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/utils/auth.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/core/utils/urls.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/agent.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/base.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/events.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/mcp.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/auth.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/clients.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/config.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/config_utils.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/constants.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/credentials.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dr_mcp_server.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dr_mcp_server_logo.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/controllers.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/dr_lib.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/register.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/utils.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/base.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/default.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/drum.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/config.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/controllers.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/metadata.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/register.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_agentic_fallback_schema.json +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_prediction_fallback_schema.json +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/register.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/schema.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/exceptions.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/logging.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/mcp_instance.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/mcp_server_tools.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/memory_management/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/memory_management/manager.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/memory_management/memory_tools.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/routes.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/routes_utils.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/server_life_cycle.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/telemetry.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/tool_config.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/tool_filter.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/utils.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/server.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/integration_mcp_server.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/mcp_utils_ete.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/mcp_utils_integration.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/tool_base_ete.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/utils.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/atlassian.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/s3.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/confluence/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/jira/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/data.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/deployment.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/deployment_info.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/model.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/predict.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/predict_realtime.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/project.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/training.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/langgraph/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/langgraph/agent.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/langgraph/mcp.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/agent.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/base.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/mcp.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/__init__.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_auth_provider.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_llm_providers.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_mcp_client.py +0 -0
- {datarobot_genai-0.2.9 → datarobot_genai-0.2.17}/src/datarobot_genai/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datarobot-genai
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.17
|
|
4
4
|
Summary: Generic helpers for GenAI
|
|
5
5
|
Project-URL: Homepage, https://github.com/datarobot-oss/datarobot-genai
|
|
6
6
|
Author: DataRobot, Inc.
|
|
@@ -25,6 +25,8 @@ Requires-Dist: pypdf<7.0.0,>=6.1.3
|
|
|
25
25
|
Requires-Dist: ragas<0.4.0,>=0.3.8
|
|
26
26
|
Requires-Dist: requests<3.0.0,>=2.32.4
|
|
27
27
|
Provides-Extra: crewai
|
|
28
|
+
Requires-Dist: anthropic<1.0.0,~=0.71.0; extra == 'crewai'
|
|
29
|
+
Requires-Dist: azure-ai-inference<2.0.0,>=1.0.0b9; extra == 'crewai'
|
|
28
30
|
Requires-Dist: crewai-tools[mcp]<0.77.0,>=0.69.0; extra == 'crewai'
|
|
29
31
|
Requires-Dist: crewai>=1.1.0; extra == 'crewai'
|
|
30
32
|
Requires-Dist: opentelemetry-instrumentation-crewai<1.0.0,>=0.40.5; extra == 'crewai'
|
|
@@ -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.17"
|
|
8
8
|
description = "Generic helpers for GenAI"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10, <3.13"
|
|
@@ -40,6 +40,8 @@ datarobot_auth_provider = "datarobot_genai.nat.datarobot_auth_provider"
|
|
|
40
40
|
|
|
41
41
|
[project.optional-dependencies]
|
|
42
42
|
crewai = [
|
|
43
|
+
"anthropic~=0.71.0,<1.0.0", # Needed for integration with anthropic endpoints
|
|
44
|
+
"azure-ai-inference>=1.0.0b9,<2.0.0", # Needed for integration with azure endpoints
|
|
43
45
|
"crewai>=1.1.0",
|
|
44
46
|
"crewai-tools[mcp]>=0.69.0,<0.77.0",
|
|
45
47
|
"opentelemetry-instrumentation-crewai>=0.40.5,<1.0.0",
|
|
@@ -95,11 +95,16 @@ class LLMMCPClient:
|
|
|
95
95
|
) -> str:
|
|
96
96
|
"""Call an MCP tool and return the result as a string."""
|
|
97
97
|
result: CallToolResult = await mcp_session.call_tool(tool_name, parameters)
|
|
98
|
-
|
|
98
|
+
content = (
|
|
99
99
|
result.content[0].text
|
|
100
100
|
if result.content and isinstance(result.content[0], TextContent)
|
|
101
101
|
else str(result.content)
|
|
102
102
|
)
|
|
103
|
+
if result.structuredContent is not None:
|
|
104
|
+
structured_content = json.dumps(result.structuredContent)
|
|
105
|
+
else:
|
|
106
|
+
structured_content = ""
|
|
107
|
+
return f"Content: {content}\nStructured content: {structured_content}"
|
|
103
108
|
|
|
104
109
|
async def _process_tool_calls(
|
|
105
110
|
self,
|
|
@@ -0,0 +1,393 @@
|
|
|
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
|
+
"""Async client for interacting with Confluence Cloud REST API.
|
|
16
|
+
|
|
17
|
+
At the moment of creating this client, official Confluence SDK is not supporting async.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import logging
|
|
21
|
+
from http import HTTPStatus
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
import httpx
|
|
25
|
+
from pydantic import BaseModel
|
|
26
|
+
from pydantic import Field
|
|
27
|
+
|
|
28
|
+
from .atlassian import ATLASSIAN_API_BASE
|
|
29
|
+
from .atlassian import get_atlassian_cloud_id
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ConfluenceError(Exception):
|
|
35
|
+
"""Exception for Confluence API errors."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, message: str, status_code: int | None = None) -> None:
|
|
38
|
+
super().__init__(message)
|
|
39
|
+
self.status_code = status_code
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ConfluencePage(BaseModel):
|
|
43
|
+
"""Pydantic model for Confluence page."""
|
|
44
|
+
|
|
45
|
+
page_id: str = Field(..., description="The unique page ID")
|
|
46
|
+
title: str = Field(..., description="Page title")
|
|
47
|
+
space_id: str = Field(..., description="Space ID where the page resides")
|
|
48
|
+
space_key: str | None = Field(None, description="Space key (if available)")
|
|
49
|
+
body: str = Field(..., description="Page content in storage format (HTML-like)")
|
|
50
|
+
|
|
51
|
+
def as_flat_dict(self) -> dict[str, Any]:
|
|
52
|
+
"""Return a flat dictionary representation of the page."""
|
|
53
|
+
return {
|
|
54
|
+
"page_id": self.page_id,
|
|
55
|
+
"title": self.title,
|
|
56
|
+
"space_id": self.space_id,
|
|
57
|
+
"space_key": self.space_key,
|
|
58
|
+
"body": self.body,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ConfluenceComment(BaseModel):
|
|
63
|
+
"""Pydantic model for Confluence comment."""
|
|
64
|
+
|
|
65
|
+
comment_id: str = Field(..., description="The unique comment ID")
|
|
66
|
+
page_id: str = Field(..., description="The page ID where the comment was added")
|
|
67
|
+
body: str = Field(..., description="Comment content in storage format")
|
|
68
|
+
|
|
69
|
+
def as_flat_dict(self) -> dict[str, Any]:
|
|
70
|
+
"""Return a flat dictionary representation of the comment."""
|
|
71
|
+
return {
|
|
72
|
+
"comment_id": self.comment_id,
|
|
73
|
+
"page_id": self.page_id,
|
|
74
|
+
"body": self.body,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class ConfluenceClient:
|
|
79
|
+
"""
|
|
80
|
+
Client for interacting with Confluence API using OAuth access token.
|
|
81
|
+
|
|
82
|
+
At the moment of creating this client, official Confluence SDK is not supporting async.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
EXPAND_FIELDS = "body.storage,space"
|
|
86
|
+
|
|
87
|
+
def __init__(self, access_token: str) -> None:
|
|
88
|
+
"""
|
|
89
|
+
Initialize Confluence client with access token.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
access_token: OAuth access token for Atlassian API
|
|
93
|
+
"""
|
|
94
|
+
self.access_token = access_token
|
|
95
|
+
self._client = httpx.AsyncClient(
|
|
96
|
+
headers={
|
|
97
|
+
"Authorization": f"Bearer {access_token}",
|
|
98
|
+
"Accept": "application/json",
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
},
|
|
101
|
+
timeout=30.0,
|
|
102
|
+
)
|
|
103
|
+
self._cloud_id: str | None = None
|
|
104
|
+
|
|
105
|
+
async def _get_cloud_id(self) -> str:
|
|
106
|
+
"""
|
|
107
|
+
Get the cloud ID for the authenticated Atlassian Confluence instance.
|
|
108
|
+
|
|
109
|
+
According to Atlassian OAuth 2.0 documentation, API calls should use:
|
|
110
|
+
https://api.atlassian.com/ex/confluence/{cloudId}/wiki/rest/api/...
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
Cloud ID string
|
|
115
|
+
|
|
116
|
+
Raises
|
|
117
|
+
------
|
|
118
|
+
ValueError: If cloud ID cannot be retrieved
|
|
119
|
+
"""
|
|
120
|
+
if self._cloud_id:
|
|
121
|
+
return self._cloud_id
|
|
122
|
+
|
|
123
|
+
self._cloud_id = await get_atlassian_cloud_id(self._client, service_type="confluence")
|
|
124
|
+
return self._cloud_id
|
|
125
|
+
|
|
126
|
+
def _parse_response(self, data: dict) -> ConfluencePage:
|
|
127
|
+
"""Parse API response into ConfluencePage."""
|
|
128
|
+
body_content = ""
|
|
129
|
+
body = data.get("body", {})
|
|
130
|
+
if isinstance(body, dict):
|
|
131
|
+
storage = body.get("storage", {})
|
|
132
|
+
if isinstance(storage, dict):
|
|
133
|
+
body_content = storage.get("value", "")
|
|
134
|
+
|
|
135
|
+
space = data.get("space", {})
|
|
136
|
+
space_key = space.get("key") if isinstance(space, dict) else None
|
|
137
|
+
space_id = space.get("id", "") if isinstance(space, dict) else data.get("spaceId", "")
|
|
138
|
+
|
|
139
|
+
return ConfluencePage(
|
|
140
|
+
page_id=str(data.get("id", "")),
|
|
141
|
+
title=data.get("title", ""),
|
|
142
|
+
space_id=str(space_id),
|
|
143
|
+
space_key=space_key,
|
|
144
|
+
body=body_content,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
async def get_page_by_id(self, page_id: str) -> ConfluencePage:
|
|
148
|
+
"""
|
|
149
|
+
Get a Confluence page by its ID.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
page_id: The numeric page ID
|
|
153
|
+
|
|
154
|
+
Returns
|
|
155
|
+
-------
|
|
156
|
+
ConfluencePage with page data
|
|
157
|
+
|
|
158
|
+
Raises
|
|
159
|
+
------
|
|
160
|
+
ConfluenceError: If page is not found
|
|
161
|
+
httpx.HTTPStatusError: If the API request fails
|
|
162
|
+
"""
|
|
163
|
+
cloud_id = await self._get_cloud_id()
|
|
164
|
+
url = f"{ATLASSIAN_API_BASE}/ex/confluence/{cloud_id}/wiki/rest/api/content/{page_id}"
|
|
165
|
+
|
|
166
|
+
response = await self._client.get(url, params={"expand": self.EXPAND_FIELDS})
|
|
167
|
+
|
|
168
|
+
if response.status_code == HTTPStatus.NOT_FOUND:
|
|
169
|
+
raise ConfluenceError(f"Page with ID '{page_id}' not found", status_code=404)
|
|
170
|
+
|
|
171
|
+
response.raise_for_status()
|
|
172
|
+
return self._parse_response(response.json())
|
|
173
|
+
|
|
174
|
+
async def get_page_by_title(self, title: str, space_key: str) -> ConfluencePage:
|
|
175
|
+
"""
|
|
176
|
+
Get a Confluence page by its title within a specific space.
|
|
177
|
+
|
|
178
|
+
Args:
|
|
179
|
+
title: The exact page title
|
|
180
|
+
space_key: The space key where the page resides
|
|
181
|
+
|
|
182
|
+
Returns
|
|
183
|
+
-------
|
|
184
|
+
ConfluencePage with page data
|
|
185
|
+
|
|
186
|
+
Raises
|
|
187
|
+
------
|
|
188
|
+
ConfluenceError: If the page is not found
|
|
189
|
+
httpx.HTTPStatusError: If the API request fails
|
|
190
|
+
"""
|
|
191
|
+
cloud_id = await self._get_cloud_id()
|
|
192
|
+
url = f"{ATLASSIAN_API_BASE}/ex/confluence/{cloud_id}/wiki/rest/api/content"
|
|
193
|
+
|
|
194
|
+
response = await self._client.get(
|
|
195
|
+
url,
|
|
196
|
+
params={
|
|
197
|
+
"title": title,
|
|
198
|
+
"spaceKey": space_key,
|
|
199
|
+
"expand": self.EXPAND_FIELDS,
|
|
200
|
+
},
|
|
201
|
+
)
|
|
202
|
+
response.raise_for_status()
|
|
203
|
+
|
|
204
|
+
data = response.json()
|
|
205
|
+
results = data.get("results", [])
|
|
206
|
+
|
|
207
|
+
if not results:
|
|
208
|
+
raise ConfluenceError(
|
|
209
|
+
f"Page with title '{title}' not found in space '{space_key}'", status_code=404
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
return self._parse_response(results[0])
|
|
213
|
+
|
|
214
|
+
def _extract_error_message(self, response: httpx.Response) -> str:
|
|
215
|
+
"""Extract error message from Confluence API error response."""
|
|
216
|
+
try:
|
|
217
|
+
error_data = response.json()
|
|
218
|
+
# Confluence API returns errors in different formats
|
|
219
|
+
if "message" in error_data:
|
|
220
|
+
return error_data["message"]
|
|
221
|
+
if "errorMessages" in error_data and error_data["errorMessages"]:
|
|
222
|
+
return "; ".join(error_data["errorMessages"])
|
|
223
|
+
if "errors" in error_data:
|
|
224
|
+
errors = error_data["errors"]
|
|
225
|
+
if isinstance(errors, list):
|
|
226
|
+
return "; ".join(str(e) for e in errors)
|
|
227
|
+
if isinstance(errors, dict):
|
|
228
|
+
return "; ".join(f"{k}: {v}" for k, v in errors.items())
|
|
229
|
+
except Exception:
|
|
230
|
+
pass
|
|
231
|
+
return response.text or "Unknown error"
|
|
232
|
+
|
|
233
|
+
async def create_page(
|
|
234
|
+
self,
|
|
235
|
+
space_key: str,
|
|
236
|
+
title: str,
|
|
237
|
+
body_content: str,
|
|
238
|
+
parent_id: int | None = None,
|
|
239
|
+
) -> ConfluencePage:
|
|
240
|
+
"""
|
|
241
|
+
Create a new Confluence page in a specified space.
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
space_key: The key of the Confluence space where the page should live
|
|
245
|
+
title: The title of the new page
|
|
246
|
+
body_content: The content in Confluence Storage Format (XML) or raw text
|
|
247
|
+
parent_id: Optional ID of the parent page for creating a child page
|
|
248
|
+
|
|
249
|
+
Returns
|
|
250
|
+
-------
|
|
251
|
+
ConfluencePage with the created page data
|
|
252
|
+
|
|
253
|
+
Raises
|
|
254
|
+
------
|
|
255
|
+
ConfluenceError: If space not found, parent page not found, duplicate title,
|
|
256
|
+
permission denied, or invalid content
|
|
257
|
+
httpx.HTTPStatusError: If the API request fails with unexpected status
|
|
258
|
+
"""
|
|
259
|
+
cloud_id = await self._get_cloud_id()
|
|
260
|
+
url = f"{ATLASSIAN_API_BASE}/ex/confluence/{cloud_id}/wiki/rest/api/content"
|
|
261
|
+
|
|
262
|
+
payload: dict[str, Any] = {
|
|
263
|
+
"type": "page",
|
|
264
|
+
"title": title,
|
|
265
|
+
"space": {"key": space_key},
|
|
266
|
+
"body": {
|
|
267
|
+
"storage": {
|
|
268
|
+
"value": body_content,
|
|
269
|
+
"representation": "storage",
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if parent_id is not None:
|
|
275
|
+
payload["ancestors"] = [{"id": parent_id}]
|
|
276
|
+
|
|
277
|
+
response = await self._client.post(url, json=payload)
|
|
278
|
+
|
|
279
|
+
if response.status_code == HTTPStatus.NOT_FOUND:
|
|
280
|
+
error_msg = self._extract_error_message(response)
|
|
281
|
+
if parent_id is not None and "ancestor" in error_msg.lower():
|
|
282
|
+
raise ConfluenceError(
|
|
283
|
+
f"Parent page with ID '{parent_id}' not found", status_code=404
|
|
284
|
+
)
|
|
285
|
+
raise ConfluenceError(
|
|
286
|
+
f"Space '{space_key}' not found or resource unavailable: {error_msg}",
|
|
287
|
+
status_code=404,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
if response.status_code == HTTPStatus.CONFLICT:
|
|
291
|
+
raise ConfluenceError(
|
|
292
|
+
f"A page with title '{title}' already exists in space '{space_key}'",
|
|
293
|
+
status_code=409,
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
if response.status_code == HTTPStatus.FORBIDDEN:
|
|
297
|
+
raise ConfluenceError(
|
|
298
|
+
f"Permission denied: you don't have access to create pages in space '{space_key}'",
|
|
299
|
+
status_code=403,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
if response.status_code == HTTPStatus.BAD_REQUEST:
|
|
303
|
+
error_msg = self._extract_error_message(response)
|
|
304
|
+
raise ConfluenceError(f"Invalid request: {error_msg}", status_code=400)
|
|
305
|
+
|
|
306
|
+
if response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
|
|
307
|
+
raise ConfluenceError("Rate limit exceeded. Please try again later.", status_code=429)
|
|
308
|
+
|
|
309
|
+
response.raise_for_status()
|
|
310
|
+
|
|
311
|
+
return self._parse_response(response.json())
|
|
312
|
+
|
|
313
|
+
def _parse_comment_response(self, data: dict, page_id: str) -> ConfluenceComment:
|
|
314
|
+
"""Parse API response into ConfluenceComment."""
|
|
315
|
+
body_content = ""
|
|
316
|
+
body = data.get("body", {})
|
|
317
|
+
if isinstance(body, dict):
|
|
318
|
+
storage = body.get("storage", {})
|
|
319
|
+
if isinstance(storage, dict):
|
|
320
|
+
body_content = storage.get("value", "")
|
|
321
|
+
|
|
322
|
+
return ConfluenceComment(
|
|
323
|
+
comment_id=str(data.get("id", "")),
|
|
324
|
+
page_id=page_id,
|
|
325
|
+
body=body_content,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
async def add_comment(self, page_id: str, comment_body: str) -> ConfluenceComment:
|
|
329
|
+
"""
|
|
330
|
+
Add a comment to a Confluence page.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
page_id: The numeric page ID where the comment will be added
|
|
334
|
+
comment_body: The text content of the comment
|
|
335
|
+
|
|
336
|
+
Returns
|
|
337
|
+
-------
|
|
338
|
+
ConfluenceComment with the created comment data
|
|
339
|
+
|
|
340
|
+
Raises
|
|
341
|
+
------
|
|
342
|
+
ConfluenceError: If page not found, permission denied, or invalid content
|
|
343
|
+
httpx.HTTPStatusError: If the API request fails with unexpected status
|
|
344
|
+
"""
|
|
345
|
+
cloud_id = await self._get_cloud_id()
|
|
346
|
+
url = f"{ATLASSIAN_API_BASE}/ex/confluence/{cloud_id}/wiki/rest/api/content"
|
|
347
|
+
|
|
348
|
+
payload: dict[str, Any] = {
|
|
349
|
+
"type": "comment",
|
|
350
|
+
"container": {"id": page_id, "type": "page"},
|
|
351
|
+
"body": {
|
|
352
|
+
"storage": {
|
|
353
|
+
"value": comment_body,
|
|
354
|
+
"representation": "storage",
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
response = await self._client.post(url, json=payload)
|
|
360
|
+
|
|
361
|
+
if response.status_code == HTTPStatus.NOT_FOUND:
|
|
362
|
+
error_msg = self._extract_error_message(response)
|
|
363
|
+
raise ConfluenceError(
|
|
364
|
+
f"Page with ID '{page_id}' not found: {error_msg}",
|
|
365
|
+
status_code=404,
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
if response.status_code == HTTPStatus.FORBIDDEN:
|
|
369
|
+
raise ConfluenceError(
|
|
370
|
+
f"Permission denied: you don't have access to add comments to page '{page_id}'",
|
|
371
|
+
status_code=403,
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
if response.status_code == HTTPStatus.BAD_REQUEST:
|
|
375
|
+
error_msg = self._extract_error_message(response)
|
|
376
|
+
raise ConfluenceError(f"Invalid request: {error_msg}", status_code=400)
|
|
377
|
+
|
|
378
|
+
if response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
|
|
379
|
+
raise ConfluenceError("Rate limit exceeded. Please try again later.", status_code=429)
|
|
380
|
+
|
|
381
|
+
response.raise_for_status()
|
|
382
|
+
|
|
383
|
+
return self._parse_comment_response(response.json(), page_id)
|
|
384
|
+
|
|
385
|
+
async def __aenter__(self) -> "ConfluenceClient":
|
|
386
|
+
"""Async context manager entry."""
|
|
387
|
+
return self
|
|
388
|
+
|
|
389
|
+
async def __aexit__(
|
|
390
|
+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: Any
|
|
391
|
+
) -> None:
|
|
392
|
+
"""Async context manager exit."""
|
|
393
|
+
await self._client.aclose()
|