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 56b43e265..600aae983 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 @@ -86,7 +86,7 @@ def create_delete_google_drive_file_tool( } logger.info( - f"Requesting approval for trashing Google Drive file: '{file_name}' (file_id={file_id}, delete_from_kb={delete_from_kb})" + f"Requesting approval for deleting Google Drive file: '{file_name}' (file_id={file_id}, delete_from_kb={delete_from_kb})" ) approval = interrupt( { @@ -157,7 +157,7 @@ def create_delete_google_drive_file_tool( } logger.info( - f"Trashing Google Drive file: file_id='{final_file_id}', connector={final_connector_id}" + f"Deleting Google Drive file: file_id='{final_file_id}', connector={final_connector_id}" ) client = GoogleDriveClient(session=db_session, connector_id=connector.id) try: @@ -174,7 +174,7 @@ def create_delete_google_drive_file_tool( } raise - logger.info(f"Google Drive file trashed: file_id={final_file_id}") + logger.info(f"Google Drive file deleted (moved to trash): file_id={final_file_id}") trash_result: dict[str, Any] = { "status": "success", @@ -219,7 +219,7 @@ def create_delete_google_drive_file_tool( if isinstance(e, GraphInterrupt): raise - logger.error(f"Error trashing Google Drive file: {e}", exc_info=True) + logger.error(f"Error deleting Google Drive file: {e}", exc_info=True) return { "status": "error", "message": "Something went wrong while trashing the file. Please try again.", diff --git a/surfsense_backend/app/agents/new_chat/tools/registry.py b/surfsense_backend/app/agents/new_chat/tools/registry.py index 565de01ab..01342e920 100644 --- a/surfsense_backend/app/agents/new_chat/tools/registry.py +++ b/surfsense_backend/app/agents/new_chat/tools/registry.py @@ -297,7 +297,7 @@ BUILTIN_TOOLS: list[ToolDefinition] = [ requires=["db_session", "search_space_id", "user_id"], ), # ========================================================================= - # GOOGLE DRIVE TOOLS - create files, trash files + # GOOGLE DRIVE TOOLS - create files, delete files # ========================================================================= ToolDefinition( name="create_google_drive_file", diff --git a/surfsense_web/components/tool-ui/google-drive/create-file.tsx b/surfsense_web/components/tool-ui/google-drive/create-file.tsx index 548347587..b56abf18b 100644 --- a/surfsense_web/components/tool-ui/google-drive/create-file.tsx +++ b/surfsense_web/components/tool-ui/google-drive/create-file.tsx @@ -12,6 +12,7 @@ import { } from "lucide-react"; import { useParams } from "next/navigation"; import { useMemo, useState } from "react"; +import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { @@ -426,10 +427,17 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio url.searchParams.set("space_id", searchSpaceId); url.searchParams.set("return_url", window.location.pathname); const response = await authenticatedFetch(url.toString()); + if (!response.ok) { + const data = await response.json().catch(() => ({})); + toast.error(data.detail ?? "Failed to initiate re-authentication. Please try again."); + return; + } const data = await response.json(); if (data.auth_url) { window.location.href = data.auth_url; } + } catch { + toast.error("Failed to initiate re-authentication. Please try again."); } finally { setLoading(false); } diff --git a/surfsense_web/components/tool-ui/google-drive/trash-file.tsx b/surfsense_web/components/tool-ui/google-drive/trash-file.tsx index 0c1ca981c..ee4c94d51 100644 --- a/surfsense_web/components/tool-ui/google-drive/trash-file.tsx +++ b/surfsense_web/components/tool-ui/google-drive/trash-file.tsx @@ -12,6 +12,7 @@ import { } from "lucide-react"; import { useParams } from "next/navigation"; import { useState } from "react"; +import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { authenticatedFetch } from "@/lib/auth-utils"; @@ -334,10 +335,17 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio url.searchParams.set("space_id", searchSpaceId); url.searchParams.set("return_url", window.location.pathname); const response = await authenticatedFetch(url.toString()); + if (!response.ok) { + const data = await response.json().catch(() => ({})); + toast.error(data.detail ?? "Failed to initiate re-authentication. Please try again."); + return; + } const data = await response.json(); if (data.auth_url) { window.location.href = data.auth_url; } + } catch { + toast.error("Failed to initiate re-authentication. Please try again."); } finally { setLoading(false); }