datarobot-genai 0.2.13__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.
Files changed (117) hide show
  1. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/PKG-INFO +1 -1
  2. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/pyproject.toml +1 -1
  3. datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/clients/confluence.py +393 -0
  4. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/jira.py +119 -5
  5. datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/confluence/tools.py +188 -0
  6. datarobot_genai-0.2.17/src/datarobot_genai/drmcp/tools/jira/tools.py +243 -0
  7. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/agent.py +20 -7
  8. datarobot_genai-0.2.17/src/datarobot_genai/nat/helpers.py +87 -0
  9. datarobot_genai-0.2.13/src/datarobot_genai/drmcp/tools/clients/confluence.py +0 -196
  10. datarobot_genai-0.2.13/src/datarobot_genai/drmcp/tools/confluence/tools.py +0 -81
  11. datarobot_genai-0.2.13/src/datarobot_genai/drmcp/tools/jira/tools.py +0 -101
  12. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/.gitignore +0 -0
  13. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/AUTHORS +0 -0
  14. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/LICENSE +0 -0
  15. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/README.md +0 -0
  16. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/__init__.py +0 -0
  17. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/__init__.py +0 -0
  18. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/agents/__init__.py +0 -0
  19. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/agents/base.py +0 -0
  20. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/__init__.py +0 -0
  21. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/auth.py +0 -0
  22. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/client.py +0 -0
  23. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/chat/responses.py +0 -0
  24. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/cli/__init__.py +0 -0
  25. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/cli/agent_environment.py +0 -0
  26. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/cli/agent_kernel.py +0 -0
  27. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/custom_model.py +0 -0
  28. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/mcp/__init__.py +0 -0
  29. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/mcp/common.py +0 -0
  30. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/telemetry_agent.py +0 -0
  31. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/utils/__init__.py +0 -0
  32. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/utils/auth.py +0 -0
  33. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/core/utils/urls.py +0 -0
  34. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/__init__.py +0 -0
  35. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/agent.py +0 -0
  36. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/base.py +0 -0
  37. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/events.py +0 -0
  38. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/crewai/mcp.py +0 -0
  39. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/__init__.py +0 -0
  40. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/__init__.py +0 -0
  41. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/auth.py +0 -0
  42. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/clients.py +0 -0
  43. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/config.py +0 -0
  44. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/config_utils.py +0 -0
  45. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/constants.py +0 -0
  46. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/credentials.py +0 -0
  47. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dr_mcp_server.py +0 -0
  48. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dr_mcp_server_logo.py +0 -0
  49. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/__init__.py +0 -0
  50. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/controllers.py +0 -0
  51. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/dr_lib.py +0 -0
  52. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/register.py +0 -0
  53. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_prompts/utils.py +0 -0
  54. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/__init__.py +0 -0
  55. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/__init__.py +0 -0
  56. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/__init__.py +0 -0
  57. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/base.py +0 -0
  58. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/default.py +0 -0
  59. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/adapters/drum.py +0 -0
  60. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/config.py +0 -0
  61. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/controllers.py +0 -0
  62. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/metadata.py +0 -0
  63. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/register.py +0 -0
  64. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_agentic_fallback_schema.json +0 -0
  65. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/deployment/schemas/drum_prediction_fallback_schema.json +0 -0
  66. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/register.py +0 -0
  67. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/dynamic_tools/schema.py +0 -0
  68. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/exceptions.py +0 -0
  69. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/logging.py +0 -0
  70. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/mcp_instance.py +0 -0
  71. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/mcp_server_tools.py +0 -0
  72. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/memory_management/__init__.py +0 -0
  73. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/memory_management/manager.py +0 -0
  74. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/memory_management/memory_tools.py +0 -0
  75. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/routes.py +0 -0
  76. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/routes_utils.py +0 -0
  77. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/server_life_cycle.py +0 -0
  78. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/telemetry.py +0 -0
  79. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/tool_config.py +0 -0
  80. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/tool_filter.py +0 -0
  81. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/core/utils.py +0 -0
  82. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/server.py +0 -0
  83. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/__init__.py +0 -0
  84. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/integration_mcp_server.py +0 -0
  85. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/mcp_utils_ete.py +0 -0
  86. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/mcp_utils_integration.py +0 -0
  87. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/openai_llm_mcp_client.py +0 -0
  88. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/tool_base_ete.py +0 -0
  89. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/test_utils/utils.py +0 -0
  90. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/__init__.py +0 -0
  91. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/__init__.py +0 -0
  92. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/atlassian.py +0 -0
  93. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/clients/s3.py +0 -0
  94. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/confluence/__init__.py +0 -0
  95. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/jira/__init__.py +0 -0
  96. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/__init__.py +0 -0
  97. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/data.py +0 -0
  98. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/deployment.py +0 -0
  99. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/deployment_info.py +0 -0
  100. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/model.py +0 -0
  101. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/predict.py +0 -0
  102. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/predict_realtime.py +0 -0
  103. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/project.py +0 -0
  104. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/drmcp/tools/predictive/training.py +0 -0
  105. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/langgraph/__init__.py +0 -0
  106. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/langgraph/agent.py +0 -0
  107. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/langgraph/mcp.py +0 -0
  108. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/__init__.py +0 -0
  109. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/agent.py +0 -0
  110. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/base.py +0 -0
  111. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/llama_index/mcp.py +0 -0
  112. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/__init__.py +0 -0
  113. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_auth_provider.py +0 -0
  114. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_llm_clients.py +0 -0
  115. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_llm_providers.py +0 -0
  116. {datarobot_genai-0.2.13 → datarobot_genai-0.2.17}/src/datarobot_genai/nat/datarobot_mcp_client.py +0 -0
  117. {datarobot_genai-0.2.13 → 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.13
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.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "datarobot-genai"
7
- version = "0.2.13"
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"
@@ -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()
@@ -25,6 +25,18 @@ from .atlassian import get_atlassian_cloud_id
25
25
 
26
26
  logger = logging.getLogger(__name__)
27
27
 
28
+ RESPONSE_JIRA_ISSUE_FIELDS = {
29
+ "id",
30
+ "key",
31
+ "summary",
32
+ "status",
33
+ "reporter",
34
+ "assignee",
35
+ "created",
36
+ "updated",
37
+ }
38
+ RESPONSE_JIRA_ISSUE_FIELDS_STR = ",".join(RESPONSE_JIRA_ISSUE_FIELDS)
39
+
28
40
 
29
41
  class _IssuePerson(BaseModel):
30
42
  email_address: str = Field(alias="emailAddress")
@@ -107,10 +119,41 @@ class JiraClient:
107
119
  self._cloud_id = await get_atlassian_cloud_id(self._client, service_type="jira")
108
120
  return self._cloud_id
109
121
 
110
- async def _get_full_url(self, url: str) -> str:
122
+ async def _get_full_url(self, path: str) -> str:
111
123
  """Return URL for Jira API."""
112
124
  cloud_id = await self._get_cloud_id()
113
- return f"{ATLASSIAN_API_BASE}/ex/jira/{cloud_id}/rest/api/3/{url}"
125
+ return f"{ATLASSIAN_API_BASE}/ex/jira/{cloud_id}/rest/api/3/{path}"
126
+
127
+ async def search_jira_issues(self, jql_query: str, max_results: int) -> list[Issue]:
128
+ """
129
+ Search Jira issues using JQL (Jira Query Language).
130
+
131
+ Args:
132
+ jql_query: JQL Query
133
+ max_results: Maximum number of issues to return
134
+
135
+ Returns
136
+ -------
137
+ List of Jira issues
138
+
139
+ Raises
140
+ ------
141
+ httpx.HTTPStatusError: If the API request fails
142
+ """
143
+ url = await self._get_full_url("search/jql")
144
+ response = await self._client.post(
145
+ url,
146
+ json={
147
+ "jql": jql_query,
148
+ "fields": list(RESPONSE_JIRA_ISSUE_FIELDS),
149
+ "maxResults": max_results,
150
+ },
151
+ )
152
+
153
+ response.raise_for_status()
154
+ raw_issues = response.json().get("issues", [])
155
+ issues = [Issue(**issue) for issue in raw_issues]
156
+ return issues
114
157
 
115
158
  async def get_jira_issue(self, issue_key: str) -> Issue:
116
159
  """
@@ -128,9 +171,7 @@ class JiraClient:
128
171
  httpx.HTTPStatusError: If the API request fails
129
172
  """
130
173
  url = await self._get_full_url(f"issue/{issue_key}")
131
- response = await self._client.get(
132
- url, params={"fields": "id,key,summary,status,reporter,assignee,created,updated"}
133
- )
174
+ response = await self._client.get(url, params={"fields": RESPONSE_JIRA_ISSUE_FIELDS_STR})
134
175
 
135
176
  if response.status_code == HTTPStatus.NOT_FOUND:
136
177
  raise ValueError(f"{issue_key} not found")
@@ -209,6 +250,79 @@ class JiraClient:
209
250
  jsoned = response.json()
210
251
  return jsoned["key"]
211
252
 
253
+ async def update_jira_issue(self, issue_key: str, fields: dict[str, Any]) -> list[str]:
254
+ """
255
+ Update Jira issue.
256
+
257
+ Args:
258
+ issue_key: The key of the Jira issue, e.g., 'PROJ-123'
259
+ fields: A dictionary of field names and their new values
260
+ e.g., {'description': 'New content'}
261
+
262
+ Returns
263
+ -------
264
+ List of updated fields
265
+
266
+ Raises
267
+ ------
268
+ httpx.HTTPStatusError: If the API request fails
269
+ """
270
+ url = await self._get_full_url(f"issue/{issue_key}")
271
+ payload = {"fields": fields}
272
+
273
+ response = await self._client.put(url, json=payload)
274
+
275
+ response.raise_for_status()
276
+ return list(fields.keys())
277
+
278
+ async def get_available_jira_transitions(self, issue_key: str) -> dict[str, str]:
279
+ """
280
+ Get Available Jira Transitions.
281
+
282
+ Args:
283
+ issue_key: The key of the Jira issue, e.g., 'PROJ-123'
284
+
285
+ Returns
286
+ -------
287
+ Dictionary where key is the transition name and value is the transition ID
288
+
289
+ Raises
290
+ ------
291
+ httpx.HTTPStatusError: If the API request fails
292
+ """
293
+ url = await self._get_full_url(f"issue/{issue_key}/transitions")
294
+ response = await self._client.get(url)
295
+ response.raise_for_status()
296
+ jsoned = response.json()
297
+ transitions = {
298
+ transition["name"]: transition["id"] for transition in jsoned.get("transitions", [])
299
+ }
300
+ return transitions
301
+
302
+ async def transition_jira_issue(self, issue_key: str, transition_id: str) -> None:
303
+ """
304
+ Transition Jira issue.
305
+
306
+ Args:
307
+ issue_key: The key of the Jira issue, e.g., 'PROJ-123'
308
+ transition_id: Id of target transitionm e.g. '123'.
309
+ Can be obtained from `get_available_jira_transitions`.
310
+
311
+ Returns
312
+ -------
313
+ Nothing
314
+
315
+ Raises
316
+ ------
317
+ httpx.HTTPStatusError: If the API request fails
318
+ """
319
+ url = await self._get_full_url(f"issue/{issue_key}")
320
+ payload = {"transition": {"id": transition_id}}
321
+
322
+ response = await self._client.post(url, json=payload)
323
+
324
+ response.raise_for_status()
325
+
212
326
  async def __aenter__(self) -> "JiraClient":
213
327
  """Async context manager entry."""
214
328
  return self