"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

)}