From 856d2583181952e9020b526843cd5f0057777bc2 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 20 Feb 2026 19:41:29 +0200 Subject: [PATCH] fix bugs and pattern inconsistencies in google drive tools --- .../agents/new_chat/tools/google_drive/create_file.py | 4 ++++ .../agents/new_chat/tools/google_drive/trash_file.py | 10 ++++++++++ .../app/services/google_drive/tool_metadata_service.py | 2 ++ 3 files changed, 16 insertions(+) diff --git a/surfsense_backend/app/agents/new_chat/tools/google_drive/create_file.py b/surfsense_backend/app/agents/new_chat/tools/google_drive/create_file.py index 0995852a8..df7c103f1 100644 --- a/surfsense_backend/app/agents/new_chat/tools/google_drive/create_file.py +++ b/surfsense_backend/app/agents/new_chat/tools/google_drive/create_file.py @@ -76,6 +76,9 @@ def create_create_google_drive_file_tool( logger.error(f"Failed to fetch creation context: {context['error']}") return {"status": "error", "message": context["error"]} + logger.info( + f"Requesting approval for creating Google Drive file: name='{name}', type='{file_type}'" + ) approval = interrupt( { "type": "google_drive_file_creation", @@ -97,6 +100,7 @@ def create_create_google_drive_file_tool( decisions = decisions_raw if isinstance(decisions_raw, list) else [decisions_raw] decisions = [d for d in decisions if isinstance(d, dict)] if not decisions: + logger.warning("No approval decision received") return {"status": "error", "message": "No approval decision received"} decision = decisions[0] diff --git a/surfsense_backend/app/agents/new_chat/tools/google_drive/trash_file.py b/surfsense_backend/app/agents/new_chat/tools/google_drive/trash_file.py index 376fdab6c..a6ce43eb2 100644 --- a/surfsense_backend/app/agents/new_chat/tools/google_drive/trash_file.py +++ b/surfsense_backend/app/agents/new_chat/tools/google_drive/trash_file.py @@ -70,6 +70,15 @@ def create_trash_google_drive_file_tool( file_id = file["file_id"] connector_id_from_context = context["account"]["id"] + if not file_id: + return { + "status": "error", + "message": "File ID is missing from the indexed document. Please re-index the file and try again.", + } + + logger.info( + f"Requesting approval for trashing Google Drive file: '{file_name}' (file_id={file_id})" + ) approval = interrupt( { "type": "google_drive_file_trash", @@ -88,6 +97,7 @@ def create_trash_google_drive_file_tool( decisions = decisions_raw if isinstance(decisions_raw, list) else [decisions_raw] decisions = [d for d in decisions if isinstance(d, dict)] if not decisions: + logger.warning("No approval decision received") return {"status": "error", "message": "No approval decision received"} decision = decisions[0] diff --git a/surfsense_backend/app/services/google_drive/tool_metadata_service.py b/surfsense_backend/app/services/google_drive/tool_metadata_service.py index d7b0a01c3..8bc60ecbc 100644 --- a/surfsense_backend/app/services/google_drive/tool_metadata_service.py +++ b/surfsense_backend/app/services/google_drive/tool_metadata_service.py @@ -112,6 +112,8 @@ class GoogleDriveToolMetadataService: and_( SearchSourceConnector.id == document.connector_id, SearchSourceConnector.user_id == user_id, + SearchSourceConnector.connector_type + == SearchSourceConnectorType.GOOGLE_DRIVE_CONNECTOR, ) ) )