datarobot-genai 0.2.29__py3-none-any.whl → 0.2.30__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.
@@ -33,7 +33,17 @@ from datarobot_genai.drmcp.core.auth import get_access_token
33
33
 
34
34
  logger = logging.getLogger(__name__)
35
35
 
36
- SUPPORTED_FIELDS = {"id", "name", "size", "mimeType", "webViewLink", "createdTime", "modifiedTime"}
36
+ SUPPORTED_FIELDS = {
37
+ "id",
38
+ "name",
39
+ "size",
40
+ "mimeType",
41
+ "webViewLink",
42
+ "createdTime",
43
+ "modifiedTime",
44
+ "starred",
45
+ "trashed",
46
+ }
37
47
  SUPPORTED_FIELDS_STR = ",".join(SUPPORTED_FIELDS)
38
48
  DEFAULT_FIELDS = f"nextPageToken,files({SUPPORTED_FIELDS_STR})"
39
49
  GOOGLE_DRIVE_FOLDER_MIME = "application/vnd.google-apps.folder"
@@ -119,6 +129,8 @@ class GoogleDriveFile(BaseModel):
119
129
  web_view_link: Annotated[str | None, Field(alias="webViewLink")] = None
120
130
  created_time: Annotated[str | None, Field(alias="createdTime")] = None
121
131
  modified_time: Annotated[str | None, Field(alias="modifiedTime")] = None
132
+ starred: bool | None = None
133
+ trashed: bool | None = None
122
134
 
123
135
  model_config = ConfigDict(populate_by_name=True)
124
136
 
@@ -133,8 +145,31 @@ class GoogleDriveFile(BaseModel):
133
145
  web_view_link=data.get("webViewLink"),
134
146
  created_time=data.get("createdTime"),
135
147
  modified_time=data.get("modifiedTime"),
148
+ starred=data.get("starred"),
149
+ trashed=data.get("trashed"),
136
150
  )
137
151
 
152
+ def as_flat_dict(self) -> dict[str, Any]:
153
+ """Return a flat dictionary representation of the file."""
154
+ result: dict[str, Any] = {
155
+ "id": self.id,
156
+ "name": self.name,
157
+ "mimeType": self.mime_type,
158
+ }
159
+ if self.size is not None:
160
+ result["size"] = self.size
161
+ if self.web_view_link is not None:
162
+ result["webViewLink"] = self.web_view_link
163
+ if self.created_time is not None:
164
+ result["createdTime"] = self.created_time
165
+ if self.modified_time is not None:
166
+ result["modifiedTime"] = self.modified_time
167
+ if self.starred is not None:
168
+ result["starred"] = self.starred
169
+ if self.trashed is not None:
170
+ result["trashed"] = self.trashed
171
+ return result
172
+
138
173
 
139
174
  class PaginatedResult(BaseModel):
140
175
  """Result of a paginated API call."""
@@ -440,6 +475,66 @@ class GoogleDriveClient:
440
475
  response.raise_for_status()
441
476
  return GoogleDriveFile.from_api_response(response.json())
442
477
 
478
+ async def update_file_metadata(
479
+ self,
480
+ file_id: str,
481
+ new_name: str | None = None,
482
+ starred: bool | None = None,
483
+ trashed: bool | None = None,
484
+ ) -> GoogleDriveFile:
485
+ """Update file metadata in Google Drive.
486
+
487
+ Args:
488
+ file_id: The ID of the file to update.
489
+ new_name: A new name to rename the file. Must not be empty or whitespace.
490
+ starred: Set to True to star the file or False to unstar it.
491
+ trashed: Set to True to trash the file or False to restore it.
492
+
493
+ Returns
494
+ -------
495
+ GoogleDriveFile with updated metadata.
496
+
497
+ Raises
498
+ ------
499
+ GoogleDriveError: If no update fields are provided, file is not found,
500
+ access is denied, or the request is invalid.
501
+ """
502
+ if new_name is None and starred is None and trashed is None:
503
+ raise GoogleDriveError(
504
+ "At least one of new_name, starred, or trashed must be provided."
505
+ )
506
+
507
+ if new_name is not None and not new_name.strip():
508
+ raise GoogleDriveError("new_name cannot be empty or whitespace.")
509
+
510
+ body: dict[str, Any] = {}
511
+ if new_name is not None:
512
+ body["name"] = new_name
513
+ if starred is not None:
514
+ body["starred"] = starred
515
+ if trashed is not None:
516
+ body["trashed"] = trashed
517
+
518
+ response = await self._client.patch(
519
+ f"/{file_id}",
520
+ json=body,
521
+ params={"fields": SUPPORTED_FIELDS_STR, "supportsAllDrives": "true"},
522
+ )
523
+
524
+ if response.status_code == 404:
525
+ raise GoogleDriveError(f"File with ID '{file_id}' not found.")
526
+ if response.status_code == 403:
527
+ raise GoogleDriveError(
528
+ f"Permission denied: you don't have permission to update file '{file_id}'."
529
+ )
530
+ if response.status_code == 400:
531
+ raise GoogleDriveError("Bad request: invalid parameters for file update.")
532
+ if response.status_code == 429:
533
+ raise GoogleDriveError("Rate limit exceeded. Please try again later.")
534
+
535
+ response.raise_for_status()
536
+ return GoogleDriveFile.from_api_response(response.json())
537
+
443
538
  async def _export_workspace_file(self, file_id: str, export_mime_type: str) -> str:
444
539
  """Export a Google Workspace file to the specified format.
445
540
 
@@ -164,7 +164,6 @@ async def gdrive_read_content(
164
164
  f"An unexpected error occurred while reading Google Drive file content: {str(e)}"
165
165
  )
166
166
 
167
- # Provide helpful context about the conversion
168
167
  export_info = ""
169
168
  if file_content.was_exported:
170
169
  export_info = f" (exported from {file_content.original_mime_type})"
@@ -252,7 +251,6 @@ async def gdrive_create_file(
252
251
  logger.error(f"Unexpected error creating Google Drive file: {e}")
253
252
  raise ToolError(f"An unexpected error occurred while creating Google Drive file: {str(e)}")
254
253
 
255
- # Build response message
256
254
  file_type = "folder" if mime_type == GOOGLE_DRIVE_FOLDER_MIME else "file"
257
255
  content_info = ""
258
256
  if initial_content and mime_type != GOOGLE_DRIVE_FOLDER_MIME:
@@ -260,11 +258,90 @@ async def gdrive_create_file(
260
258
 
261
259
  return ToolResult(
262
260
  content=f"Successfully created {file_type} '{created_file.name}'{content_info}.",
263
- structured_content={
264
- "id": created_file.id,
265
- "name": created_file.name,
266
- "mimeType": created_file.mime_type,
267
- "webViewLink": created_file.web_view_link,
268
- "createdTime": created_file.created_time,
269
- },
261
+ structured_content=created_file.as_flat_dict(),
262
+ )
263
+
264
+
265
+ @dr_mcp_tool(
266
+ tags={"google", "gdrive", "update", "metadata", "rename", "star", "trash"}, enabled=False
267
+ )
268
+ async def gdrive_update_metadata(
269
+ *,
270
+ file_id: Annotated[str, "The ID of the file or folder to update."],
271
+ new_name: Annotated[str | None, "A new name to rename the file."] = None,
272
+ starred: Annotated[bool | None, "Set to True to star the file or False to unstar it."] = None,
273
+ trash: Annotated[bool | None, "Set to True to trash the file or False to restore it."] = None,
274
+ ) -> ToolResult:
275
+ """
276
+ Update non-content metadata fields of a Google Drive file or folder.
277
+
278
+ This tool allows you to:
279
+ - Rename files and folders by setting new_name
280
+ - Star or unstar files (per-user preference) with starred
281
+ - Move files to trash or restore them with trash
282
+
283
+ Usage:
284
+ - Rename: gdrive_update_metadata(file_id="1ABC...", new_name="New Name.txt")
285
+ - Star: gdrive_update_metadata(file_id="1ABC...", starred=True)
286
+ - Unstar: gdrive_update_metadata(file_id="1ABC...", starred=False)
287
+ - Trash: gdrive_update_metadata(file_id="1ABC...", trash=True)
288
+ - Restore: gdrive_update_metadata(file_id="1ABC...", trash=False)
289
+ - Multiple: gdrive_update_metadata(file_id="1ABC...", new_name="New.txt", starred=True)
290
+
291
+ Note:
292
+ - At least one of new_name, starred, or trash must be provided.
293
+ - Starring is per-user: starring a shared file only affects your view.
294
+ - Trashing a folder trashes all contents recursively.
295
+ - Trashing requires permissions (owner for My Drive, organizer for Shared Drives).
296
+ """
297
+ if not file_id or not file_id.strip():
298
+ raise ToolError("Argument validation error: 'file_id' cannot be empty.")
299
+
300
+ if new_name is None and starred is None and trash is None:
301
+ raise ToolError(
302
+ "Argument validation error: at least one of 'new_name', 'starred', or 'trash' "
303
+ "must be provided."
304
+ )
305
+
306
+ if new_name is not None and not new_name.strip():
307
+ raise ToolError("Argument validation error: 'new_name' cannot be empty or whitespace.")
308
+
309
+ access_token = await get_gdrive_access_token()
310
+ if isinstance(access_token, ToolError):
311
+ raise access_token
312
+
313
+ try:
314
+ async with GoogleDriveClient(access_token) as client:
315
+ updated_file = await client.update_file_metadata(
316
+ file_id=file_id,
317
+ new_name=new_name,
318
+ starred=starred,
319
+ trashed=trash,
320
+ )
321
+ except GoogleDriveError as e:
322
+ logger.error(f"Google Drive error updating file metadata: {e}")
323
+ raise ToolError(str(e))
324
+ except Exception as e:
325
+ logger.error(f"Unexpected error updating Google Drive file metadata: {e}")
326
+ raise ToolError(
327
+ f"An unexpected error occurred while updating Google Drive file metadata: {str(e)}"
328
+ )
329
+
330
+ changes: list[str] = []
331
+ if new_name is not None:
332
+ changes.append(f"renamed to '{new_name}'")
333
+ if starred is True:
334
+ changes.append("starred")
335
+ elif starred is False:
336
+ changes.append("unstarred")
337
+ if trash is True:
338
+ changes.append("moved to trash")
339
+ elif trash is False:
340
+ changes.append("restored from trash")
341
+
342
+ changes_description = ", ".join(changes)
343
+
344
+ return ToolResult(
345
+ content=f"Successfully updated file '{updated_file.name}': {changes_description}.",
346
+ structured_content=updated_file.as_flat_dict(),
270
347
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datarobot-genai
3
- Version: 0.2.29
3
+ Version: 0.2.30
4
4
  Summary: Generic helpers for GenAI
5
5
  Project-URL: Homepage, https://github.com/datarobot-oss/datarobot-genai
6
6
  Author: DataRobot, Inc.
@@ -78,14 +78,14 @@ datarobot_genai/drmcp/tools/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosH
78
78
  datarobot_genai/drmcp/tools/clients/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
79
79
  datarobot_genai/drmcp/tools/clients/atlassian.py,sha256=__M_uz7FrcbKCYRzeMn24DCEYD6OmFx_LuywHCxgXsA,6472
80
80
  datarobot_genai/drmcp/tools/clients/confluence.py,sha256=h_G0By_kDnJeWDT_d-IREsaZ5-0xB5GoLXOqblYP5MA,20706
81
- datarobot_genai/drmcp/tools/clients/gdrive.py,sha256=8GztWTdpJ7Ir3NIvIoOHPzDscoR1Ui7Ct2IiKmuUzIc,26012
81
+ datarobot_genai/drmcp/tools/clients/gdrive.py,sha256=Sonc8g52z8gDeaIGxh2GkoWYbtveCBGfDU0z3m4iSRU,29292
82
82
  datarobot_genai/drmcp/tools/clients/jira.py,sha256=Rm91JAyrNIqxu66-9rU1YqoRXVnWbEy-Ahvy6f6HlVg,9823
83
83
  datarobot_genai/drmcp/tools/clients/microsoft_graph.py,sha256=PASGThDPE8zkBZqach8lurJL1y47DWUPLwvf9N6uLGM,19234
84
84
  datarobot_genai/drmcp/tools/clients/s3.py,sha256=GmwzvurFdNfvxOooA8g5S4osRysHYU0S9ypg_177Glg,953
85
85
  datarobot_genai/drmcp/tools/confluence/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
86
86
  datarobot_genai/drmcp/tools/confluence/tools.py,sha256=_-ws65WLK8KZP_mKkf4yJ7ZunR8qdyoiMwHQX47MSMw,12362
87
87
  datarobot_genai/drmcp/tools/gdrive/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
88
- datarobot_genai/drmcp/tools/gdrive/tools.py,sha256=G8LlnGEINZqV83Q-b3ZliWkDjouhbozDam3w6GfA7s0,10711
88
+ datarobot_genai/drmcp/tools/gdrive/tools.py,sha256=jSKz0TuqAdHFitUZ-BW8NDl31Aq4VGpWa0yWSksLi00,13887
89
89
  datarobot_genai/drmcp/tools/jira/__init__.py,sha256=0kq9vMkF7EBsS6lkEdiLibmUrghTQqosHbZ5k-V9a5g,578
90
90
  datarobot_genai/drmcp/tools/jira/tools.py,sha256=dfkqTU2HH-7n44hX80ODFacKq0p0LOchFcZtIIKFNMM,9687
91
91
  datarobot_genai/drmcp/tools/microsoft_graph/__init__.py,sha256=CuOaMt1AJo7cHx_GuhO3s_aqxZas_wlDsoBorBsvbeU,577
@@ -113,9 +113,9 @@ datarobot_genai/nat/datarobot_llm_clients.py,sha256=-_q_KlKOVQecIYJd8YRiYnS4ZNaz
113
113
  datarobot_genai/nat/datarobot_llm_providers.py,sha256=aDoQcTeGI-odqydPXEX9OGGNFbzAtpqzTvHHEkmJuEQ,4963
114
114
  datarobot_genai/nat/datarobot_mcp_client.py,sha256=jL8sXb8g4gvt0VYgB2tfMGsMjpB1GV2XIbN0iv_LxVU,10701
115
115
  datarobot_genai/nat/helpers.py,sha256=Q7E3ADZdtFfS8E6OQPyw2wgA6laQ58N3bhLj5CBWwJs,3265
116
- datarobot_genai-0.2.29.dist-info/METADATA,sha256=lFk85PaEbHw_waws2INyPqFxo92s43jFp4vFyz8HHdc,6301
117
- datarobot_genai-0.2.29.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
118
- datarobot_genai-0.2.29.dist-info/entry_points.txt,sha256=jEW3WxDZ8XIK9-ISmTyt5DbmBb047rFlzQuhY09rGrM,284
119
- datarobot_genai-0.2.29.dist-info/licenses/AUTHORS,sha256=isJGUXdjq1U7XZ_B_9AH8Qf0u4eX0XyQifJZ_Sxm4sA,80
120
- datarobot_genai-0.2.29.dist-info/licenses/LICENSE,sha256=U2_VkLIktQoa60Nf6Tbt7E4RMlfhFSjWjcJJfVC-YCE,11341
121
- datarobot_genai-0.2.29.dist-info/RECORD,,
116
+ datarobot_genai-0.2.30.dist-info/METADATA,sha256=OfWIH55TShkE_jPNSKFx04ZceCEYP-qFCHyr31sHD6U,6301
117
+ datarobot_genai-0.2.30.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
118
+ datarobot_genai-0.2.30.dist-info/entry_points.txt,sha256=jEW3WxDZ8XIK9-ISmTyt5DbmBb047rFlzQuhY09rGrM,284
119
+ datarobot_genai-0.2.30.dist-info/licenses/AUTHORS,sha256=isJGUXdjq1U7XZ_B_9AH8Qf0u4eX0XyQifJZ_Sxm4sA,80
120
+ datarobot_genai-0.2.30.dist-info/licenses/LICENSE,sha256=U2_VkLIktQoa60Nf6Tbt7E4RMlfhFSjWjcJJfVC-YCE,11341
121
+ datarobot_genai-0.2.30.dist-info/RECORD,,