From 43c6c784abff99ab2b7f9969f95e22974d20b875 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 12 Feb 2026 19:22:45 +0200 Subject: [PATCH] Add update notion page UI component --- .../components/tool-ui/update-notion-page.tsx | 572 ++++++++++++++++++ 1 file changed, 572 insertions(+) create mode 100644 surfsense_web/components/tool-ui/update-notion-page.tsx diff --git a/surfsense_web/components/tool-ui/update-notion-page.tsx b/surfsense_web/components/tool-ui/update-notion-page.tsx new file mode 100644 index 000000000..671509077 --- /dev/null +++ b/surfsense_web/components/tool-ui/update-notion-page.tsx @@ -0,0 +1,572 @@ +"use client"; + +import { makeAssistantToolUI } from "@assistant-ui/react"; +import { + AlertTriangleIcon, + CheckIcon, + Loader2Icon, + Maximize2Icon, + PencilIcon, + XIcon, +} from "lucide-react"; +import { useMemo, useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; + +interface InterruptResult { + __interrupt__: true; + __decided__?: "approve" | "reject" | "edit"; + action_requests: Array<{ + name: string; + args: Record; + description?: string; + }>; + review_configs: Array<{ + action_name: string; + allowed_decisions: Array<"approve" | "edit" | "reject">; + }>; + interrupt_type?: string; + message?: string; + context?: { + account?: { + id: number; + name: string; + workspace_id: string | null; + workspace_name: string; + workspace_icon: string; + }; + page_id?: string; + current_title?: string; + current_content?: string; + document_id?: number; + indexed_at?: string; + error?: string; + }; +} + +interface SuccessResult { + status: "success"; + page_id: string; + title: string; + url: string; + message?: string; +} + +interface ErrorResult { + status: "error"; + message: string; +} + +type UpdateNotionPageResult = InterruptResult | SuccessResult | ErrorResult; + +function isInterruptResult(result: unknown): result is InterruptResult { + return ( + typeof result === "object" && + result !== null && + "__interrupt__" in result && + (result as InterruptResult).__interrupt__ === true + ); +} + +function isErrorResult(result: unknown): result is ErrorResult { + return ( + typeof result === "object" && + result !== null && + "status" in result && + (result as ErrorResult).status === "error" + ); +} + +function PageContextDisplay({ + account, + currentTitle, + currentContent, +}: { + account?: { + id: number; + name: string; + workspace_id: string | null; + workspace_name: string; + workspace_icon: string; + }; + currentTitle?: string; + currentContent?: string; +}) { + return ( + <> + {account && ( +
+
Notion Account
+
+ {account.workspace_name} +
+
+ )} + + {currentTitle && ( +
+
Current Page Title
+
+ {currentTitle} +
+
+ )} + + {currentContent && ( +
+
+ Current Content (first 200 chars) +
+
+ {currentContent.slice(0, 200)} + {currentContent.length > 200 && "..."} +
+
+ )} + + ); +} + +function EditFormFields({ + editedArgs, + setEditedArgs, + isTitleValid, + idPrefix = "", + rows = 8, +}: { + editedArgs: Record; + setEditedArgs: (args: Record) => void; + isTitleValid: boolean; + idPrefix?: string; + rows?: number; +}) { + return ( + <> +
+ + setEditedArgs({ ...editedArgs, title: e.target.value })} + placeholder="Enter page title" + className={!isTitleValid ? "border-destructive" : ""} + /> + {!isTitleValid && ( +

Title is required and cannot be empty

+ )} +
+
+ +