alita-sdk 0.3.405__py3-none-any.whl → 0.3.406__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

@@ -156,11 +156,28 @@ class SharepointApiWrapper(NonCodeIndexerToolkit):
156
156
  self._client.load(file).execute_query()
157
157
 
158
158
  file_content = file.read()
159
+ file_name = file.name
159
160
  self._client.execute_query()
160
161
  except Exception as e:
161
- logging.error(f"Failed to load file from SharePoint: {e}. Path: {path}. Please, double check file name and path.")
162
- return ToolException("File not found. Please, check file name and path.")
163
- return parse_file_content(file_name=file.name,
162
+ # attempt to get via graph api
163
+ try:
164
+ # attempt to get files via graph api
165
+ from .authorization_helper import SharepointAuthorizationHelper
166
+ auth_helper = SharepointAuthorizationHelper(
167
+ client_id=self.client_id,
168
+ client_secret=self.client_secret.get_secret_value(),
169
+ tenant="", # optional for graph api
170
+ scope="", # optional for graph api
171
+ token_json="", # optional for graph api
172
+ )
173
+ file_content = auth_helper.get_file_content(self.site_url, path)
174
+ file_name = path.split('/')[-1]
175
+ except Exception as graph_e:
176
+ logging.error(f"Failed to load file from SharePoint via base api: {e}. Path: {path}. Please, double check file name and path.")
177
+ logging.error(f"Failed to load file from SharePoint via graph api: {graph_e}. Path: {path}. Please, double check file name and path.")
178
+ return ToolException(f"File not found. Please, check file name and path: {e} and {graph_e}")
179
+ #
180
+ return parse_file_content(file_name=file_name,
164
181
  file_content=file_content,
165
182
  is_capture_image=is_capture_image,
166
183
  page_number=page_number,
@@ -1,5 +1,5 @@
1
1
  from datetime import datetime, timezone
2
- from urllib.parse import urlparse
2
+ from urllib.parse import unquote, urlparse
3
3
 
4
4
  import jwt
5
5
  import requests
@@ -117,6 +117,7 @@ class SharepointAuthorizationHelper:
117
117
  if "value" not in drives_json or not drives_json["value"]:
118
118
  raise KeyError("'value' missing or empty in drives response")
119
119
  drive_id = drives_json["value"][0].get("id")
120
+ drive_path = unquote(urlparse(drives_json["value"][0].get("webUrl")).path)
120
121
  if not drive_id:
121
122
  raise KeyError("'id' missing in drive object")
122
123
  #
@@ -137,9 +138,12 @@ class SharepointAuthorizationHelper:
137
138
  #
138
139
  result = []
139
140
  for file in files_json["value"]:
141
+ file_name = file.get('name', '')
142
+ parts = [drive_path.strip('/'), folder_name.strip('/') if folder_name else '', file_name.strip('/')]
143
+ #
140
144
  temp_props = {
141
- 'Name': file.get('name'),
142
- 'Path': file.get('webUrl'),
145
+ 'Name': file_name,
146
+ 'Path': '/'.join([part for part in parts if part]),
143
147
  'Created': file.get('createdDateTime'),
144
148
  'Modified': file.get('lastModifiedDateTime'),
145
149
  'Link': file.get('webUrl'),
@@ -154,3 +158,28 @@ class SharepointAuthorizationHelper:
154
158
  return result
155
159
  except Exception as e:
156
160
  raise RuntimeError(f"Error in get_files_list: {e}")
161
+
162
+ def get_file_content(self, site_url: str, path: str):
163
+ try:
164
+ access_token, site_id = self.generate_token_and_site_id(site_url)
165
+ headers = {"Authorization": f"Bearer {access_token}"}
166
+ drives_url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives"
167
+ drives_response = requests.get(drives_url, headers=headers)
168
+ if drives_response.status_code != 200:
169
+ raise RuntimeError(f"Failed to get drives: {drives_response.status_code} {drives_response.text}")
170
+ drives_json = drives_response.json()
171
+ if "value" not in drives_json or not drives_json["value"]:
172
+ raise KeyError("'value' missing or empty in drives response")
173
+ drive_id = drives_json["value"][0].get("id")
174
+ if not drive_id:
175
+ raise KeyError("'id' missing in drive object")
176
+ #
177
+ # Build the endpoint for file content
178
+ url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/root:/{path}:/content"
179
+ response = requests.get(url, headers=headers)
180
+ if response.status_code != 200:
181
+ raise RuntimeError(f"Failed to get files list: {response.status_code} {response.text}")
182
+ #
183
+ return response.content
184
+ except Exception as e:
185
+ raise RuntimeError(f"Error in get_files_list: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alita_sdk
3
- Version: 0.3.405
3
+ Version: 0.3.406
4
4
  Summary: SDK for building langchain agents using resources from Alita
5
5
  Author-email: Artem Rozumenko <artyom.rozumenko@gmail.com>, Mikalai Biazruchka <mikalai_biazruchka@epam.com>, Roman Mitusov <roman_mitusov@epam.com>, Ivan Krakhmaliuk <lifedj27@gmail.com>, Artem Dubrovskiy <ad13box@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -317,8 +317,8 @@ alita_sdk/tools/servicenow/__init__.py,sha256=ziEt2juPrGFyB98ZXbGf25v6gZo4UJTHsz
317
317
  alita_sdk/tools/servicenow/api_wrapper.py,sha256=WpH-bBLGFdhehs4g-K-WAkNuaD1CSrwsDpdgB3RG53s,6120
318
318
  alita_sdk/tools/servicenow/servicenow_client.py,sha256=Rdqfu-ll-qbnclMzChLZBsfXRDzgoX_FdeI2WLApWxc,3269
319
319
  alita_sdk/tools/sharepoint/__init__.py,sha256=5z2iSmm-0kbHKf70wN6OOgS4Px7tOzwkIpHXz0Vrbj4,4045
320
- alita_sdk/tools/sharepoint/api_wrapper.py,sha256=xUQOlJBHha0bmzkz00GVgzUnAsE28saGkRYHqXTj7Ac,13105
321
- alita_sdk/tools/sharepoint/authorization_helper.py,sha256=WfkSZh28gfB2aOlWk1T4mHjc0PBW5SPwLzVVTPr_dkM,7476
320
+ alita_sdk/tools/sharepoint/api_wrapper.py,sha256=d8B0I4C9x8qt1dvmLjsfYnas98T_gXueJAWrNykZP0U,14075
321
+ alita_sdk/tools/sharepoint/authorization_helper.py,sha256=-wNPxkKcg42o5Z3tkmzIr6rrrCMkA-Og2j6GbDjq7yU,9166
322
322
  alita_sdk/tools/sharepoint/utils.py,sha256=fZ1YzAu5CTjKSZeslowpOPH974902S8vCp1Wu7L44LM,446
323
323
  alita_sdk/tools/slack/__init__.py,sha256=YiPAoRc6y6uVpfHl0K1Qi-flcyPlWFIMVcVbhicGWXY,3990
324
324
  alita_sdk/tools/slack/api_wrapper.py,sha256=5VrV7iSGno8ZcDzEHdGPNhInhtODGPPvAzoZ9W9iQWE,14009
@@ -353,8 +353,8 @@ alita_sdk/tools/zephyr_scale/api_wrapper.py,sha256=kT0TbmMvuKhDUZc0i7KO18O38JM9S
353
353
  alita_sdk/tools/zephyr_squad/__init__.py,sha256=0ne8XLJEQSLOWfzd2HdnqOYmQlUliKHbBED5kW_Vias,2895
354
354
  alita_sdk/tools/zephyr_squad/api_wrapper.py,sha256=kmw_xol8YIYFplBLWTqP_VKPRhL_1ItDD0_vXTe_UuI,14906
355
355
  alita_sdk/tools/zephyr_squad/zephyr_squad_cloud_client.py,sha256=R371waHsms4sllHCbijKYs90C-9Yu0sSR3N4SUfQOgU,5066
356
- alita_sdk-0.3.405.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
357
- alita_sdk-0.3.405.dist-info/METADATA,sha256=zNo9z-qhfD29QynTObDSSd-1sgmJKEdTLqdM_NdmCCI,19071
358
- alita_sdk-0.3.405.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
359
- alita_sdk-0.3.405.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
360
- alita_sdk-0.3.405.dist-info/RECORD,,
356
+ alita_sdk-0.3.406.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
357
+ alita_sdk-0.3.406.dist-info/METADATA,sha256=qKUH3FgZr8aK9zs2JOuh5VCEoRswwX5frgyDYb2Vszo,19071
358
+ alita_sdk-0.3.406.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
359
+ alita_sdk-0.3.406.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
360
+ alita_sdk-0.3.406.dist-info/RECORD,,