diff --git a/surfsense_web/components/tool-ui/create-notion-page.tsx b/surfsense_web/components/tool-ui/create-notion-page.tsx index a1cf67109..256d6a7c9 100644 --- a/surfsense_web/components/tool-ui/create-notion-page.tsx +++ b/surfsense_web/components/tool-ui/create-notion-page.tsx @@ -1,7 +1,7 @@ "use client"; import { makeAssistantToolUI } from "@assistant-ui/react"; -import { AlertTriangleIcon, CheckIcon, FileTextIcon, Loader2Icon, PencilIcon, XIcon } from "lucide-react"; +import { AlertTriangleIcon, CheckIcon, Loader2Icon, PencilIcon, XIcon } from "lucide-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -22,7 +22,7 @@ interface InterruptResult { } interface SuccessResult { - status: string; + status: "success"; page_id: string; title: string; url: string; @@ -31,7 +31,12 @@ interface SuccessResult { message?: string; } -type CreateNotionPageResult = InterruptResult | SuccessResult; +interface ErrorResult { + status: "error"; + message: string; +} + +type CreateNotionPageResult = InterruptResult | SuccessResult | ErrorResult; function isInterruptResult(result: unknown): result is InterruptResult { return ( @@ -42,6 +47,15 @@ function isInterruptResult(result: unknown): result is InterruptResult { ); } +function isErrorResult(result: unknown): result is ErrorResult { + return ( + typeof result === "object" && + result !== null && + "status" in result && + (result as ErrorResult).status === "error" + ); +} + function ApprovalCard({ args, interruptData, @@ -49,51 +63,53 @@ function ApprovalCard({ }: { args: Record; interruptData: InterruptResult; - onDecision: (decision: { type: "approve" | "reject" | "edit"; message?: string; edited_action?: { name: string; args: Record } }) => void; + onDecision: (decision: { + type: "approve" | "reject" | "edit"; + message?: string; + edited_action?: { name: string; args: Record }; + }) => void; }) { const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>( interruptData.__decided__ ?? null ); const [isEditing, setIsEditing] = useState(false); const [editedArgs, setEditedArgs] = useState>(args); - + const reviewConfig = interruptData.review_configs[0]; const allowedDecisions = reviewConfig?.allowed_decisions ?? ["approve", "reject"]; const canEdit = allowedDecisions.includes("edit"); return ( -
-
-
- + ? "border border-border bg-card shadow-sm" + : "border-2 border-foreground/20 bg-muted/30 dark:bg-muted/10 shadow-lg animate-pulse-subtle" + }`} + > +
+
+
-

Create Notion Page

-

+

+ Create Notion Page +

+

{isEditing ? "You can edit the arguments below" : "Requires your approval to proceed"}

@@ -111,7 +127,9 @@ function ApprovalCard({ {args.content != null && (

Content

-

{String(args.content)}

+

+ {String(args.content)} +

)}
@@ -121,20 +139,28 @@ function ApprovalCard({ {isEditing && (
-
-