mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-26 21:39:43 +02:00
refactor: improve UI and functionality for Google Drive and Notion HITL tools
- Updated approval components for Google Drive file creation, deletion, and Notion page updates to enhance user feedback and interaction. - Replaced deprecated icons and streamlined state management for better performance. - Integrated keyboard shortcuts for approving actions, improving accessibility and user experience. - Refactored UI elements for consistency and clarity across approval processes.
This commit is contained in:
parent
804106af11
commit
5fb33b7cff
4 changed files with 680 additions and 893 deletions
|
|
@ -3,15 +3,14 @@
|
||||||
import { makeAssistantToolUI } from "@assistant-ui/react";
|
import { makeAssistantToolUI } from "@assistant-ui/react";
|
||||||
import {
|
import {
|
||||||
AlertTriangleIcon,
|
AlertTriangleIcon,
|
||||||
CheckIcon,
|
CornerDownLeftIcon,
|
||||||
FileIcon,
|
FileIcon,
|
||||||
Loader2Icon,
|
Loader2Icon,
|
||||||
Pen,
|
Pen,
|
||||||
RefreshCwIcon,
|
RefreshCwIcon,
|
||||||
XIcon,
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
|
@ -22,8 +21,11 @@ import {
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { PlateEditor } from "@/components/editor/plate-editor";
|
||||||
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
|
import { useSetAtom } from "jotai";
|
||||||
|
import { openHitlEditPanelAtom } from "@/atoms/chat/hitl-edit-panel.atom";
|
||||||
|
|
||||||
interface GoogleDriveAccount {
|
interface GoogleDriveAccount {
|
||||||
id: number;
|
id: number;
|
||||||
|
|
@ -121,14 +123,8 @@ function ApprovalCard({
|
||||||
const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>(
|
const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>(
|
||||||
interruptData.__decided__ ?? null
|
interruptData.__decided__ ?? null
|
||||||
);
|
);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
||||||
const [editedName, setEditedName] = useState(args.name ?? "");
|
const openHitlEditPanel = useSetAtom(openHitlEditPanelAtom);
|
||||||
const [editedContent, setEditedContent] = useState(args.content ?? "");
|
|
||||||
const [committedArgs, setCommittedArgs] = useState<{
|
|
||||||
name: string;
|
|
||||||
file_type: string;
|
|
||||||
content?: string | null;
|
|
||||||
} | null>(null);
|
|
||||||
|
|
||||||
const accounts = interruptData.context?.accounts ?? [];
|
const accounts = interruptData.context?.accounts ?? [];
|
||||||
|
|
||||||
|
|
@ -142,8 +138,8 @@ function ApprovalCard({
|
||||||
const [parentFolderId, setParentFolderId] = useState<string>("");
|
const [parentFolderId, setParentFolderId] = useState<string>("");
|
||||||
|
|
||||||
const isNameValid = useMemo(
|
const isNameValid = useMemo(
|
||||||
() => (isEditing ? editedName.trim().length > 0 : args.name?.trim().length > 0),
|
() => args.name && typeof args.name === "string" && args.name.trim().length > 0,
|
||||||
[isEditing, editedName, args.name]
|
[args.name]
|
||||||
);
|
);
|
||||||
|
|
||||||
const canApprove = !!selectedAccountId && isNameValid;
|
const canApprove = !!selectedAccountId && isNameValid;
|
||||||
|
|
@ -152,274 +148,219 @@ function ApprovalCard({
|
||||||
const allowedDecisions = reviewConfig?.allowed_decisions ?? ["approve", "reject"];
|
const allowedDecisions = reviewConfig?.allowed_decisions ?? ["approve", "reject"];
|
||||||
const canEdit = allowedDecisions.includes("edit");
|
const canEdit = allowedDecisions.includes("edit");
|
||||||
|
|
||||||
function buildFinalArgs() {
|
const handleApprove = useCallback(() => {
|
||||||
return {
|
if (decided || isPanelOpen || !canApprove) return;
|
||||||
name: isEditing ? editedName : args.name,
|
if (!allowedDecisions.includes("approve")) return;
|
||||||
file_type: selectedFileType,
|
setDecided("approve");
|
||||||
content: isEditing ? editedContent || null : (args.content ?? null),
|
onDecision({
|
||||||
connector_id: selectedAccountId ? Number(selectedAccountId) : null,
|
type: "approve",
|
||||||
parent_folder_id: parentFolderId.trim() || null,
|
edited_action: {
|
||||||
|
name: interruptData.action_requests[0].name,
|
||||||
|
args: {
|
||||||
|
...args,
|
||||||
|
file_type: selectedFileType,
|
||||||
|
connector_id: selectedAccountId ? Number(selectedAccountId) : null,
|
||||||
|
parent_folder_id: parentFolderId.trim() || null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [decided, isPanelOpen, canApprove, allowedDecisions, onDecision, interruptData, args, selectedFileType, selectedAccountId, parentFolderId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
|
||||||
|
handleApprove();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
window.addEventListener("keydown", handler);
|
||||||
|
return () => window.removeEventListener("keydown", handler);
|
||||||
|
}, [handleApprove]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||||
className={`my-4 max-w-full overflow-hidden rounded-xl transition-all duration-300 ${
|
|
||||||
decided
|
|
||||||
? "border border-border bg-card shadow-sm"
|
|
||||||
: "border-2 border-foreground/20 bg-muted/30 dark:bg-muted/10 shadow-lg animate-pulse-subtle"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div
|
<div className="flex items-start justify-between px-5 pt-5 pb-4">
|
||||||
className={`flex items-center gap-3 border-b ${
|
<div>
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/40 dark:bg-muted/20"
|
<p className="text-sm font-semibold text-foreground">
|
||||||
} px-4 py-3`}
|
{decided === "reject"
|
||||||
>
|
? "Google Drive File Rejected"
|
||||||
<div
|
: decided === "approve" || decided === "edit"
|
||||||
className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${
|
? "Google Drive File Approved"
|
||||||
decided ? "bg-muted" : "bg-muted animate-pulse"
|
: "Create Google Drive File"}
|
||||||
}`}
|
</p>
|
||||||
>
|
<p className="text-xs text-muted-foreground mt-0.5">
|
||||||
<AlertTriangleIcon
|
{decided === "reject"
|
||||||
className={`size-4 ${decided ? "text-muted-foreground" : "text-foreground"}`}
|
? "File creation was cancelled"
|
||||||
/>
|
: decided === "edit"
|
||||||
</div>
|
? "File creation is in progress with your changes"
|
||||||
<div className="min-w-0 flex-1">
|
: decided === "approve"
|
||||||
<p className="text-sm font-medium text-foreground">Create Google Drive File</p>
|
? "File creation is in progress"
|
||||||
<p className="truncate text-xs text-muted-foreground">
|
: "Requires your approval to proceed"}
|
||||||
{isEditing ? "You can edit the arguments below" : "Requires your approval to proceed"}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
{!decided && canEdit && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
className="rounded-lg text-muted-foreground -mt-1 -mr-2"
|
||||||
|
onClick={() => {
|
||||||
|
setIsPanelOpen(true);
|
||||||
|
openHitlEditPanel({
|
||||||
|
title: args.name ?? "",
|
||||||
|
content: args.content ?? "",
|
||||||
|
toolName: "Google Drive File",
|
||||||
|
onSave: (newName, newContent) => {
|
||||||
|
setIsPanelOpen(false);
|
||||||
|
setDecided("edit");
|
||||||
|
onDecision({
|
||||||
|
type: "edit",
|
||||||
|
edited_action: {
|
||||||
|
name: interruptData.action_requests[0].name,
|
||||||
|
args: {
|
||||||
|
...args,
|
||||||
|
name: newName,
|
||||||
|
content: newContent,
|
||||||
|
file_type: selectedFileType,
|
||||||
|
connector_id: selectedAccountId ? Number(selectedAccountId) : null,
|
||||||
|
parent_folder_id: parentFolderId.trim() || null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pen className="size-3.5" />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Context section */}
|
{/* Context section */}
|
||||||
{!decided && interruptData.context && (
|
{!decided && interruptData.context && (
|
||||||
<div className="border-b border-border px-4 py-3 bg-muted/30 space-y-3">
|
<>
|
||||||
{interruptData.context.error ? (
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
<div className="px-5 py-4 space-y-4">
|
||||||
) : (
|
{interruptData.context.error ? (
|
||||||
<>
|
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
||||||
{accounts.length > 0 && (
|
) : (
|
||||||
<div className="space-y-1.5">
|
<>
|
||||||
<div className="text-xs font-medium text-muted-foreground">
|
{accounts.length > 0 && (
|
||||||
Google Drive Account <span className="text-destructive">*</span>
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground">
|
||||||
|
Google Drive Account <span className="text-destructive">*</span>
|
||||||
|
</p>
|
||||||
|
<Select value={selectedAccountId} onValueChange={setSelectedAccountId}>
|
||||||
|
<SelectTrigger className="w-full">
|
||||||
|
<SelectValue placeholder="Select an account" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{accounts.map((account) => (
|
||||||
|
<SelectItem key={account.id} value={String(account.id)}>
|
||||||
|
{account.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<Select value={selectedAccountId} onValueChange={setSelectedAccountId}>
|
)}
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground">
|
||||||
|
File Type <span className="text-destructive">*</span>
|
||||||
|
</p>
|
||||||
|
<Select value={selectedFileType} onValueChange={setSelectedFileType}>
|
||||||
<SelectTrigger className="w-full">
|
<SelectTrigger className="w-full">
|
||||||
<SelectValue placeholder="Select an account" />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{accounts.map((account) => (
|
<SelectItem value="google_doc">Google Doc</SelectItem>
|
||||||
<SelectItem key={account.id} value={String(account.id)}>
|
<SelectItem value="google_sheet">Google Sheet</SelectItem>
|
||||||
{account.name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-2">
|
||||||
<div className="text-xs font-medium text-muted-foreground">
|
<p className="text-xs font-medium text-muted-foreground">
|
||||||
File Type <span className="text-destructive">*</span>
|
Parent Folder ID (optional)
|
||||||
|
</p>
|
||||||
|
<Input
|
||||||
|
value={parentFolderId}
|
||||||
|
onChange={(e) => setParentFolderId(e.target.value)}
|
||||||
|
placeholder="Leave blank to create at Drive root"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Paste a Google Drive folder ID to place the file in a specific folder.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Select value={selectedFileType} onValueChange={setSelectedFileType}>
|
|
||||||
<SelectTrigger className="w-full">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="google_doc">Google Doc</SelectItem>
|
|
||||||
<SelectItem value="google_sheet">Google Sheet</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<div className="text-xs font-medium text-muted-foreground">
|
|
||||||
Parent Folder ID (optional)
|
|
||||||
</div>
|
|
||||||
<Input
|
|
||||||
value={parentFolderId}
|
|
||||||
onChange={(e) => setParentFolderId(e.target.value)}
|
|
||||||
placeholder="Leave blank to create at Drive root"
|
|
||||||
/>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Paste a Google Drive folder ID to place the file in a specific folder.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Display mode */}
|
|
||||||
{!isEditing && (
|
|
||||||
<div className="space-y-2 px-4 py-3 bg-card">
|
|
||||||
<div>
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Name</p>
|
|
||||||
<p className="text-sm text-foreground">{committedArgs?.name ?? args.name}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Type</p>
|
|
||||||
<p className="text-sm text-foreground">
|
|
||||||
{FILE_TYPE_LABELS[committedArgs?.file_type ?? args.file_type] ??
|
|
||||||
committedArgs?.file_type ??
|
|
||||||
args.file_type}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{(committedArgs?.content ?? args.content) && (
|
|
||||||
<div>
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">Content</p>
|
|
||||||
<p className="line-clamp-4 text-sm whitespace-pre-wrap text-foreground">
|
|
||||||
{committedArgs?.content ?? args.content}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Edit mode */}
|
|
||||||
{isEditing && !decided && (
|
|
||||||
<div className="space-y-3 px-4 py-3 bg-card">
|
|
||||||
<div>
|
|
||||||
<label
|
|
||||||
htmlFor="gdrive-name"
|
|
||||||
className="text-xs font-medium text-muted-foreground mb-1.5 block"
|
|
||||||
>
|
|
||||||
Name <span className="text-destructive">*</span>
|
|
||||||
</label>
|
|
||||||
<Input
|
|
||||||
id="gdrive-name"
|
|
||||||
value={editedName}
|
|
||||||
onChange={(e) => setEditedName(e.target.value)}
|
|
||||||
placeholder="Enter file name"
|
|
||||||
className={!isNameValid ? "border-destructive" : ""}
|
|
||||||
/>
|
|
||||||
{!isNameValid && <p className="text-xs text-destructive mt-1">Name is required</p>}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label
|
|
||||||
htmlFor="gdrive-content"
|
|
||||||
className="text-xs font-medium text-muted-foreground mb-1.5 block"
|
|
||||||
>
|
|
||||||
{selectedFileType === "google_sheet" ? "Content (CSV)" : "Content (Markdown)"}
|
|
||||||
</label>
|
|
||||||
<Textarea
|
|
||||||
id="gdrive-content"
|
|
||||||
value={editedContent}
|
|
||||||
onChange={(e) => setEditedContent(e.target.value)}
|
|
||||||
placeholder={
|
|
||||||
selectedFileType === "google_sheet"
|
|
||||||
? "Column A,Column B\nValue 1,Value 2"
|
|
||||||
: "# Heading\n\nYour content here..."
|
|
||||||
}
|
|
||||||
rows={6}
|
|
||||||
className="resize-none font-mono text-xs"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Action buttons */}
|
|
||||||
<div
|
|
||||||
className={`flex items-center gap-2 border-t ${
|
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/20 dark:bg-muted/10"
|
|
||||||
} px-4 py-3`}
|
|
||||||
>
|
|
||||||
{decided ? (
|
|
||||||
<p className="flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
||||||
{decided === "approve" || decided === "edit" ? (
|
|
||||||
<>
|
|
||||||
<CheckIcon className="size-3.5 text-green-500" />
|
|
||||||
{decided === "edit" ? "Approved with Changes" : "Approved"}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<XIcon className="size-3.5 text-destructive" />
|
|
||||||
Rejected
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Content preview */}
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 pt-3">
|
||||||
|
{args.name != null && (
|
||||||
|
<p className="text-sm font-medium text-foreground">{args.name}</p>
|
||||||
|
)}
|
||||||
|
{args.file_type && (
|
||||||
|
<p className="text-xs text-muted-foreground mt-0.5">
|
||||||
|
{FILE_TYPE_LABELS[args.file_type] ?? args.file_type}
|
||||||
</p>
|
</p>
|
||||||
) : isEditing ? (
|
)}
|
||||||
<>
|
{args.content != null && (
|
||||||
<Button
|
<div
|
||||||
size="sm"
|
className="mt-2 max-h-[7rem] overflow-hidden text-sm"
|
||||||
onClick={() => {
|
style={{
|
||||||
const finalArgs = buildFinalArgs();
|
maskImage: "linear-gradient(to bottom, black 50%, transparent 100%)",
|
||||||
setCommittedArgs(finalArgs);
|
WebkitMaskImage: "linear-gradient(to bottom, black 50%, transparent 100%)",
|
||||||
setDecided("edit");
|
}}
|
||||||
setIsEditing(false);
|
>
|
||||||
onDecision({
|
<PlateEditor
|
||||||
type: "edit",
|
markdown={String(args.content)}
|
||||||
edited_action: {
|
readOnly
|
||||||
name: interruptData.action_requests[0].name,
|
preset="readonly"
|
||||||
args: finalArgs,
|
editorVariant="none"
|
||||||
},
|
className="h-auto [&_[data-slate-editor]]:!min-h-0 [&_[data-slate-editor]>*:first-child]:!mt-0"
|
||||||
});
|
/>
|
||||||
}}
|
</div>
|
||||||
disabled={!canApprove}
|
)}
|
||||||
>
|
</div>
|
||||||
<CheckIcon />
|
|
||||||
Approve with Changes
|
{/* Action buttons - only shown when pending */}
|
||||||
</Button>
|
{!decided && (
|
||||||
<Button
|
<>
|
||||||
size="sm"
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
variant="outline"
|
<div className="px-5 py-4 flex items-center gap-2">
|
||||||
onClick={() => {
|
|
||||||
setIsEditing(false);
|
|
||||||
setEditedName(args.name ?? "");
|
|
||||||
setEditedContent(args.content ?? "");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{allowedDecisions.includes("approve") && (
|
{allowedDecisions.includes("approve") && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => {
|
className="rounded-lg gap-1.5"
|
||||||
const finalArgs = buildFinalArgs();
|
onClick={handleApprove}
|
||||||
setCommittedArgs(finalArgs);
|
|
||||||
setDecided("approve");
|
|
||||||
onDecision({
|
|
||||||
type: "approve",
|
|
||||||
edited_action: {
|
|
||||||
name: interruptData.action_requests[0].name,
|
|
||||||
args: finalArgs,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
disabled={!canApprove}
|
disabled={!canApprove}
|
||||||
>
|
>
|
||||||
<CheckIcon />
|
|
||||||
Approve
|
Approve
|
||||||
</Button>
|
<CornerDownLeftIcon className="size-3 opacity-60" />
|
||||||
)}
|
|
||||||
{canEdit && (
|
|
||||||
<Button size="sm" variant="outline" onClick={() => setIsEditing(true)}>
|
|
||||||
<Pen />
|
|
||||||
Edit
|
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{allowedDecisions.includes("reject") && (
|
{allowedDecisions.includes("reject") && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="ghost"
|
||||||
|
className="rounded-lg text-muted-foreground"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setDecided("reject");
|
setDecided("reject");
|
||||||
onDecision({ type: "reject", message: "User rejected the action." });
|
onDecision({ type: "reject", message: "User rejected the action." });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<XIcon />
|
|
||||||
Reject
|
Reject
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</>
|
</div>
|
||||||
)}
|
</>
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -455,20 +396,19 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border border-amber-500/50 bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-amber-500/50 px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<div className="flex items-center gap-2">
|
||||||
<AlertTriangleIcon className="size-4 text-amber-500" />
|
<AlertTriangleIcon className="size-4 text-amber-500 shrink-0" />
|
||||||
</div>
|
<p className="text-sm font-semibold text-amber-600 dark:text-amber-400">
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-amber-600 dark:text-amber-400">
|
|
||||||
Additional permissions required
|
Additional permissions required
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-3 px-4 py-3">
|
<div className="mx-5 h-px bg-amber-500/30" />
|
||||||
|
<div className="px-5 py-4 space-y-3">
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
<Button size="sm" onClick={handleReauth} disabled={loading}>
|
<Button size="sm" className="rounded-lg" onClick={handleReauth} disabled={loading}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Loader2Icon className="size-4 animate-spin" />
|
<Loader2Icon className="size-4 animate-spin" />
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -483,16 +423,12 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio
|
||||||
|
|
||||||
function ErrorCard({ result }: { result: ErrorResult }) {
|
function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-destructive/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-destructive/50 px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-destructive/10">
|
<p className="text-sm font-semibold text-destructive">Failed to create Google Drive file</p>
|
||||||
<XIcon className="size-4 text-destructive" />
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-destructive">Failed to create Google Drive file</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="px-4 py-3">
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4">
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -501,18 +437,14 @@ function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
|
|
||||||
function SuccessCard({ result }: { result: SuccessResult }) {
|
function SuccessCard({ result }: { result: SuccessResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-border bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-border px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-green-500/10">
|
<p className="text-sm font-semibold text-foreground">
|
||||||
<CheckIcon className="size-4 text-green-500" />
|
{result.message || "Google Drive file created successfully"}
|
||||||
</div>
|
</p>
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-[.8rem] text-muted-foreground">
|
|
||||||
{result.message || "Google Drive file created successfully"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2 px-4 py-3 text-xs">
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4 space-y-2 text-xs">
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<FileIcon className="size-3.5 text-muted-foreground" />
|
<FileIcon className="size-3.5 text-muted-foreground" />
|
||||||
<span className="font-medium">{result.name}</span>
|
<span className="font-medium">{result.name}</span>
|
||||||
|
|
@ -542,8 +474,8 @@ export const CreateGoogleDriveFileToolUI = makeAssistantToolUI<
|
||||||
render: function CreateGoogleDriveFileUI({ args, result, status }) {
|
render: function CreateGoogleDriveFileUI({ args, result, status }) {
|
||||||
if (status.type === "running") {
|
if (status.type === "running") {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 flex max-w-md items-center gap-3 rounded-xl border border-border bg-card px-4 py-3">
|
<div className="my-4 flex max-w-lg items-center gap-3 rounded-2xl border bg-muted/30 px-5 py-4">
|
||||||
<Loader2Icon className="size-4 animate-spin text-muted-foreground" />
|
<Spinner size="sm" className="text-muted-foreground" />
|
||||||
<p className="text-sm text-muted-foreground">Preparing Google Drive file...</p>
|
<p className="text-sm text-muted-foreground">Preparing Google Drive file...</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,17 @@
|
||||||
import { makeAssistantToolUI } from "@assistant-ui/react";
|
import { makeAssistantToolUI } from "@assistant-ui/react";
|
||||||
import {
|
import {
|
||||||
AlertTriangleIcon,
|
AlertTriangleIcon,
|
||||||
CheckIcon,
|
CornerDownLeftIcon,
|
||||||
InfoIcon,
|
InfoIcon,
|
||||||
Loader2Icon,
|
Loader2Icon,
|
||||||
RefreshCwIcon,
|
RefreshCwIcon,
|
||||||
Trash2Icon,
|
TriangleAlertIcon,
|
||||||
XIcon,
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
|
|
||||||
interface GoogleDriveAccount {
|
interface GoogleDriveAccount {
|
||||||
|
|
@ -157,166 +157,152 @@ function ApprovalCard({
|
||||||
const file = interruptData.context?.file;
|
const file = interruptData.context?.file;
|
||||||
const fileLabel = file?.mime_type ? (MIME_TYPE_LABELS[file.mime_type] ?? "File") : "File";
|
const fileLabel = file?.mime_type ? (MIME_TYPE_LABELS[file.mime_type] ?? "File") : "File";
|
||||||
|
|
||||||
|
const handleApprove = useCallback(() => {
|
||||||
|
if (decided) return;
|
||||||
|
setDecided("approve");
|
||||||
|
onDecision({
|
||||||
|
type: "approve",
|
||||||
|
edited_action: {
|
||||||
|
name: interruptData.action_requests[0].name,
|
||||||
|
args: {
|
||||||
|
file_id: file?.file_id,
|
||||||
|
connector_id: account?.id,
|
||||||
|
delete_from_kb: deleteFromKb,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [decided, onDecision, interruptData, file?.file_id, account?.id, deleteFromKb]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
|
||||||
|
handleApprove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener("keydown", handler);
|
||||||
|
return () => window.removeEventListener("keydown", handler);
|
||||||
|
}, [handleApprove]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||||
className={`my-4 max-w-full overflow-hidden rounded-xl transition-all duration-300 ${
|
|
||||||
decided
|
|
||||||
? "border border-border bg-card shadow-sm"
|
|
||||||
: "border-2 border-foreground/20 bg-muted/30 dark:bg-muted/10 shadow-lg animate-pulse-subtle"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div
|
<div className="flex items-start justify-between px-5 pt-5 pb-4">
|
||||||
className={`flex items-center gap-3 border-b ${
|
<div>
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/40 dark:bg-muted/20"
|
<p className="text-sm font-semibold text-foreground">
|
||||||
} px-4 py-3`}
|
{decided === "reject"
|
||||||
>
|
? "Google Drive File Deletion Rejected"
|
||||||
<div
|
: decided === "approve"
|
||||||
className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${
|
? "Google Drive File Deletion Approved"
|
||||||
decided ? "bg-muted" : "bg-muted animate-pulse"
|
: "Delete Google Drive File"}
|
||||||
}`}
|
</p>
|
||||||
>
|
<p className="text-xs text-muted-foreground mt-0.5">
|
||||||
<AlertTriangleIcon
|
{decided === "reject"
|
||||||
className={`size-4 ${decided ? "text-muted-foreground" : "text-foreground"}`}
|
? "File deletion was cancelled"
|
||||||
/>
|
: decided === "approve"
|
||||||
</div>
|
? "File deletion is in progress"
|
||||||
<div className="min-w-0 flex-1">
|
: "Requires your approval to proceed"}
|
||||||
<p className="text-sm font-medium text-foreground">Delete Google Drive File</p>
|
|
||||||
<p className="truncate text-xs text-muted-foreground">
|
|
||||||
Requires your approval to proceed
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Context — read-only file details */}
|
{/* Context — read-only file details */}
|
||||||
{!decided && interruptData.context && (
|
{!decided && interruptData.context && (
|
||||||
<div className="border-b border-border px-4 py-3 bg-muted/30 space-y-3">
|
<>
|
||||||
{interruptData.context.error ? (
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
<div className="px-5 py-4 space-y-4">
|
||||||
) : (
|
{interruptData.context.error ? (
|
||||||
<>
|
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
||||||
{account && (
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<div className="text-xs font-medium text-muted-foreground">
|
|
||||||
Google Drive Account
|
|
||||||
</div>
|
|
||||||
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
|
||||||
{account.name}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{file && (
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<div className="text-xs font-medium text-muted-foreground">File to Trash</div>
|
|
||||||
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm space-y-0.5">
|
|
||||||
<div className="font-medium">{file.name}</div>
|
|
||||||
<div className="text-xs text-muted-foreground">{fileLabel}</div>
|
|
||||||
{file.web_view_link && (
|
|
||||||
<a
|
|
||||||
href={file.web_view_link}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="text-xs text-primary hover:underline"
|
|
||||||
>
|
|
||||||
Open in Drive
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Trash warning */}
|
|
||||||
{!decided && (
|
|
||||||
<div className="px-4 py-3 border-b border-border bg-muted/20">
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
⚠️ The file will be moved to Google Drive trash. You can restore it from trash within 30
|
|
||||||
days.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Checkbox for deleting from knowledge base */}
|
|
||||||
{!decided && (
|
|
||||||
<div className="px-4 py-3 border-b border-border bg-muted/20">
|
|
||||||
<label className="flex items-start gap-2 cursor-pointer">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={deleteFromKb}
|
|
||||||
onChange={(e) => setDeleteFromKb(e.target.checked)}
|
|
||||||
className="mt-0.5"
|
|
||||||
/>
|
|
||||||
<div className="flex-1">
|
|
||||||
<span className="text-sm text-foreground">Also remove from knowledge base</span>
|
|
||||||
<p className="text-xs text-muted-foreground mt-1">
|
|
||||||
⚠️ This will permanently delete the file from your knowledge base (cannot be undone)
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Action buttons */}
|
|
||||||
<div
|
|
||||||
className={`flex items-center gap-2 border-t ${
|
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/20 dark:bg-muted/10"
|
|
||||||
} px-4 py-3`}
|
|
||||||
>
|
|
||||||
{decided ? (
|
|
||||||
<p className="flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
||||||
{decided === "approve" ? (
|
|
||||||
<>
|
|
||||||
<CheckIcon className="size-3.5 text-green-500" />
|
|
||||||
Approved
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<XIcon className="size-3.5 text-destructive" />
|
{account && (
|
||||||
Rejected
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground">
|
||||||
|
Google Drive Account
|
||||||
|
</p>
|
||||||
|
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
||||||
|
{account.name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{file && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground">File to Trash</p>
|
||||||
|
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm space-y-0.5">
|
||||||
|
<div className="font-medium">{file.name}</div>
|
||||||
|
<div className="text-xs text-muted-foreground">{fileLabel}</div>
|
||||||
|
{file.web_view_link && (
|
||||||
|
<a
|
||||||
|
href={file.web_view_link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-xs text-primary hover:underline"
|
||||||
|
>
|
||||||
|
Open in Drive
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</p>
|
</div>
|
||||||
) : (
|
</>
|
||||||
<>
|
)}
|
||||||
|
|
||||||
|
{/* Trash warning + delete_from_kb toggle */}
|
||||||
|
{!decided && (
|
||||||
|
<>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4 space-y-3">
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
The file will be moved to Google Drive trash. You can restore it from trash within 30 days.
|
||||||
|
</p>
|
||||||
|
<label className="flex items-start gap-2 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={deleteFromKb}
|
||||||
|
onChange={(e) => setDeleteFromKb(e.target.checked)}
|
||||||
|
className="mt-0.5"
|
||||||
|
/>
|
||||||
|
<div className="flex-1">
|
||||||
|
<span className="text-sm text-foreground">Also remove from knowledge base</span>
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
This will permanently delete the file from your knowledge base (cannot be undone)
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Action buttons - only shown when pending */}
|
||||||
|
{!decided && (
|
||||||
|
<>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4 flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="destructive"
|
className="rounded-lg gap-1.5"
|
||||||
onClick={() => {
|
onClick={handleApprove}
|
||||||
setDecided("approve");
|
|
||||||
onDecision({
|
|
||||||
type: "approve",
|
|
||||||
edited_action: {
|
|
||||||
name: interruptData.action_requests[0].name,
|
|
||||||
args: {
|
|
||||||
file_id: file?.file_id,
|
|
||||||
connector_id: account?.id,
|
|
||||||
delete_from_kb: deleteFromKb,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Trash2Icon />
|
Approve
|
||||||
Move to Trash
|
<CornerDownLeftIcon className="size-3 opacity-60" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="ghost"
|
||||||
|
className="rounded-lg text-muted-foreground"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setDecided("reject");
|
setDecided("reject");
|
||||||
onDecision({ type: "reject", message: "User rejected the action." });
|
onDecision({ type: "reject", message: "User rejected the action." });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<XIcon />
|
|
||||||
Reject
|
Reject
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</div>
|
||||||
)}
|
</>
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -352,20 +338,19 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border border-amber-500/50 bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-amber-500/50 px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<div className="flex items-center gap-2">
|
||||||
<AlertTriangleIcon className="size-4 text-amber-500" />
|
<AlertTriangleIcon className="size-4 text-amber-500 shrink-0" />
|
||||||
</div>
|
<p className="text-sm font-semibold text-amber-600 dark:text-amber-400">
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-amber-600 dark:text-amber-400">
|
|
||||||
Additional permissions required
|
Additional permissions required
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-3 px-4 py-3">
|
<div className="mx-5 h-px bg-amber-500/30" />
|
||||||
|
<div className="px-5 py-4 space-y-3">
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
<Button size="sm" onClick={handleReauth} disabled={loading}>
|
<Button size="sm" className="rounded-lg" onClick={handleReauth} disabled={loading}>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Loader2Icon className="size-4 animate-spin" />
|
<Loader2Icon className="size-4 animate-spin" />
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -380,16 +365,12 @@ function InsufficientPermissionsCard({ result }: { result: InsufficientPermissio
|
||||||
|
|
||||||
function WarningCard({ result }: { result: WarningResult }) {
|
function WarningCard({ result }: { result: WarningResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-amber-500/50 px-4 py-3">
|
<div className="flex items-start gap-3 border-b px-5 py-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<TriangleAlertIcon className="size-4 mt-0.5 shrink-0 text-amber-500" />
|
||||||
<AlertTriangleIcon className="size-4 text-amber-500" />
|
<p className="text-sm font-medium text-amber-600 dark:text-amber-500">Partial success</p>
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-amber-600 dark:text-amber-500">Partial success</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2 px-4 py-3">
|
<div className="px-5 py-4 space-y-2">
|
||||||
{result.message && <p className="text-sm text-muted-foreground">{result.message}</p>}
|
{result.message && <p className="text-sm text-muted-foreground">{result.message}</p>}
|
||||||
<p className="text-xs text-amber-600 dark:text-amber-500">{result.warning}</p>
|
<p className="text-xs text-amber-600 dark:text-amber-500">{result.warning}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -399,16 +380,12 @@ function WarningCard({ result }: { result: WarningResult }) {
|
||||||
|
|
||||||
function ErrorCard({ result }: { result: ErrorResult }) {
|
function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-destructive/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-destructive/50 px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-destructive/10">
|
<p className="text-sm font-semibold text-destructive">Failed to delete file</p>
|
||||||
<XIcon className="size-4 text-destructive" />
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-destructive">Failed to delete file</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="px-4 py-3">
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4">
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -417,14 +394,10 @@ function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
|
|
||||||
function NotFoundCard({ result }: { result: NotFoundResult }) {
|
function NotFoundCard({ result }: { result: NotFoundResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-start gap-3 px-4 py-3">
|
<div className="flex items-start gap-3 px-5 py-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<InfoIcon className="size-4 mt-0.5 shrink-0 text-muted-foreground" />
|
||||||
<InfoIcon className="size-4 text-amber-500" />
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1 pt-2">
|
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -432,23 +405,21 @@ function NotFoundCard({ result }: { result: NotFoundResult }) {
|
||||||
|
|
||||||
function SuccessCard({ result }: { result: SuccessResult }) {
|
function SuccessCard({ result }: { result: SuccessResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-border bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-border px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-green-500/10">
|
<p className="text-sm font-semibold text-foreground">
|
||||||
<CheckIcon className="size-4 text-green-500" />
|
{result.message || "File moved to trash successfully"}
|
||||||
</div>
|
</p>
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-[.8rem] text-muted-foreground">
|
|
||||||
{result.message || "File moved to trash successfully"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{result.deleted_from_kb && (
|
{result.deleted_from_kb && (
|
||||||
<div className="px-4 py-3 text-xs">
|
<>
|
||||||
<span className="text-green-600 dark:text-green-500">
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
✓ Also removed from knowledge base
|
<div className="px-5 py-4 text-xs">
|
||||||
</span>
|
<span className="text-green-600 dark:text-green-500">
|
||||||
</div>
|
Also removed from knowledge base
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -462,8 +433,8 @@ export const DeleteGoogleDriveFileToolUI = makeAssistantToolUI<
|
||||||
render: function DeleteGoogleDriveFileUI({ result, status }) {
|
render: function DeleteGoogleDriveFileUI({ result, status }) {
|
||||||
if (status.type === "running") {
|
if (status.type === "running") {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 flex max-w-md items-center gap-3 rounded-xl border border-border bg-card px-4 py-3">
|
<div className="my-4 flex max-w-lg items-center gap-3 rounded-2xl border bg-muted/30 px-5 py-4">
|
||||||
<Loader2Icon className="size-4 animate-spin text-muted-foreground" />
|
<Spinner size="sm" className="text-muted-foreground" />
|
||||||
<p className="text-sm text-muted-foreground">Looking up file in Google Drive...</p>
|
<p className="text-sm text-muted-foreground">Looking up file in Google Drive...</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,10 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { makeAssistantToolUI } from "@assistant-ui/react";
|
import { makeAssistantToolUI } from "@assistant-ui/react";
|
||||||
import {
|
import { CornerDownLeftIcon, InfoIcon, TriangleAlertIcon } from "lucide-react";
|
||||||
AlertTriangleIcon,
|
import { useCallback, useEffect, useState } from "react";
|
||||||
CheckIcon,
|
|
||||||
InfoIcon,
|
|
||||||
Loader2Icon,
|
|
||||||
TriangleAlertIcon,
|
|
||||||
XIcon,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
|
|
||||||
interface InterruptResult {
|
interface InterruptResult {
|
||||||
__interrupt__: true;
|
__interrupt__: true;
|
||||||
|
|
@ -114,11 +108,9 @@ function isWarningResult(result: unknown): result is WarningResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ApprovalCard({
|
function ApprovalCard({
|
||||||
args,
|
|
||||||
interruptData,
|
interruptData,
|
||||||
onDecision,
|
onDecision,
|
||||||
}: {
|
}: {
|
||||||
args: Record<string, unknown>;
|
|
||||||
interruptData: InterruptResult;
|
interruptData: InterruptResult;
|
||||||
onDecision: (decision: {
|
onDecision: (decision: {
|
||||||
type: "approve" | "reject";
|
type: "approve" | "reject";
|
||||||
|
|
@ -134,160 +126,148 @@ function ApprovalCard({
|
||||||
const account = interruptData.context?.account;
|
const account = interruptData.context?.account;
|
||||||
const currentTitle = interruptData.context?.current_title;
|
const currentTitle = interruptData.context?.current_title;
|
||||||
|
|
||||||
|
const handleApprove = useCallback(() => {
|
||||||
|
if (decided) return;
|
||||||
|
setDecided("approve");
|
||||||
|
onDecision({
|
||||||
|
type: "approve",
|
||||||
|
edited_action: {
|
||||||
|
name: interruptData.action_requests[0].name,
|
||||||
|
args: {
|
||||||
|
page_id: interruptData.context?.page_id,
|
||||||
|
connector_id: account?.id,
|
||||||
|
delete_from_kb: deleteFromKb,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [decided, onDecision, interruptData, account?.id, deleteFromKb]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
|
||||||
|
handleApprove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener("keydown", handler);
|
||||||
|
return () => window.removeEventListener("keydown", handler);
|
||||||
|
}, [handleApprove]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||||
className={`my-4 max-w-full overflow-hidden rounded-xl transition-all duration-300 ${
|
{/* Header */}
|
||||||
decided
|
<div className="flex items-start justify-between px-5 pt-5 pb-4">
|
||||||
? "border border-border bg-card shadow-sm"
|
<div>
|
||||||
: "border-2 border-foreground/20 bg-muted/30 dark:bg-muted/10 shadow-lg animate-pulse-subtle"
|
<p className="text-sm font-semibold text-foreground">
|
||||||
}`}
|
{decided === "reject"
|
||||||
>
|
? "Notion Page Deletion Rejected"
|
||||||
<div
|
: decided === "approve"
|
||||||
className={`flex items-center gap-3 border-b ${
|
? "Notion Page Deletion Approved"
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/40 dark:bg-muted/20"
|
: "Delete Notion Page"}
|
||||||
} px-4 py-3`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${
|
|
||||||
decided ? "bg-muted" : "bg-muted animate-pulse"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<AlertTriangleIcon
|
|
||||||
className={`size-4 ${decided ? "text-muted-foreground" : "text-foreground"}`}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className={`text-sm font-medium ${decided ? "text-foreground" : "text-foreground"}`}>
|
|
||||||
Delete Notion Page
|
|
||||||
</p>
|
</p>
|
||||||
<p
|
<p className="text-xs text-muted-foreground mt-0.5">
|
||||||
className={`truncate text-xs ${decided ? "text-muted-foreground" : "text-muted-foreground"}`}
|
{decided === "reject"
|
||||||
>
|
? "Page deletion was cancelled"
|
||||||
Requires your approval to proceed
|
: decided === "approve"
|
||||||
|
? "Page deletion is in progress"
|
||||||
|
: "Requires your approval to proceed"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Context section - READ ONLY account and page info */}
|
{/* Context section — read-only account and page info */}
|
||||||
{!decided && interruptData.context && (
|
{!decided && interruptData.context && (
|
||||||
<div className="border-b border-border px-4 py-3 bg-muted/30 space-y-3">
|
<>
|
||||||
{interruptData.context.error ? (
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
<div className="px-5 py-4 space-y-4">
|
||||||
) : (
|
{interruptData.context.error ? (
|
||||||
<>
|
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
||||||
{account && (
|
|
||||||
<div className="space-y-2">
|
|
||||||
<div className="text-xs font-medium text-muted-foreground">Notion Account</div>
|
|
||||||
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
|
||||||
{account.workspace_icon} {account.workspace_name}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{currentTitle && (
|
|
||||||
<div className="space-y-2">
|
|
||||||
<div className="text-xs font-medium text-muted-foreground">Page to Delete</div>
|
|
||||||
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
|
||||||
📄 {currentTitle}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Checkbox for deleting from knowledge base */}
|
|
||||||
{!decided && (
|
|
||||||
<div className="px-4 py-3 border-t border-border bg-muted/20">
|
|
||||||
<label className="flex items-start gap-2 cursor-pointer">
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
checked={deleteFromKb}
|
|
||||||
onChange={(e) => setDeleteFromKb(e.target.checked)}
|
|
||||||
className="mt-0.5"
|
|
||||||
/>
|
|
||||||
<div className="flex-1">
|
|
||||||
<span className="text-sm text-foreground">Also remove from knowledge base</span>
|
|
||||||
<p className="text-xs text-muted-foreground mt-1">
|
|
||||||
⚠️ This will permanently delete the page from your knowledge base (cannot be undone)
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div
|
|
||||||
className={`flex items-center gap-2 border-t ${
|
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/20 dark:bg-muted/10"
|
|
||||||
} px-4 py-3`}
|
|
||||||
>
|
|
||||||
{decided ? (
|
|
||||||
<p className="flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
||||||
{decided === "approve" ? (
|
|
||||||
<>
|
|
||||||
<CheckIcon className="size-3.5 text-green-500" />
|
|
||||||
Approved
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<XIcon className="size-3.5 text-destructive" />
|
{account && (
|
||||||
Rejected
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground">Notion Account</p>
|
||||||
|
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
||||||
|
{account.workspace_icon} {account.workspace_name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{currentTitle && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-xs font-medium text-muted-foreground">Page to Delete</p>
|
||||||
|
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
||||||
|
📄 {currentTitle}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</p>
|
</div>
|
||||||
) : (
|
</>
|
||||||
<>
|
)}
|
||||||
|
|
||||||
|
{/* delete_from_kb toggle */}
|
||||||
|
{!decided && (
|
||||||
|
<>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4">
|
||||||
|
<label className="flex items-start gap-2 cursor-pointer">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={deleteFromKb}
|
||||||
|
onChange={(e) => setDeleteFromKb(e.target.checked)}
|
||||||
|
className="mt-0.5"
|
||||||
|
/>
|
||||||
|
<div className="flex-1">
|
||||||
|
<span className="text-sm text-foreground">Also remove from knowledge base</span>
|
||||||
|
<p className="text-xs text-muted-foreground mt-1">
|
||||||
|
This will permanently delete the page from your knowledge base (cannot be undone)
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Action buttons - only shown when pending */}
|
||||||
|
{!decided && (
|
||||||
|
<>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4 flex items-center gap-2">
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => {
|
className="rounded-lg gap-1.5"
|
||||||
setDecided("approve");
|
onClick={handleApprove}
|
||||||
onDecision({
|
|
||||||
type: "approve",
|
|
||||||
edited_action: {
|
|
||||||
name: interruptData.action_requests[0].name,
|
|
||||||
args: {
|
|
||||||
page_id: interruptData.context?.page_id,
|
|
||||||
connector_id: account?.id,
|
|
||||||
delete_from_kb: deleteFromKb,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<CheckIcon />
|
|
||||||
Approve
|
Approve
|
||||||
|
<CornerDownLeftIcon className="size-3 opacity-60" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="ghost"
|
||||||
|
className="rounded-lg text-muted-foreground"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setDecided("reject");
|
setDecided("reject");
|
||||||
onDecision({ type: "reject", message: "User rejected the action." });
|
onDecision({ type: "reject", message: "User rejected the action." });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<XIcon />
|
|
||||||
Reject
|
Reject
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</div>
|
||||||
)}
|
</>
|
||||||
</div>
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ErrorCard({ result }: { result: ErrorResult }) {
|
function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-destructive/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-destructive/50 px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-destructive/10">
|
<p className="text-sm font-semibold text-destructive">Failed to delete Notion page</p>
|
||||||
<XIcon className="size-4 text-destructive" />
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-destructive">Failed to delete Notion page</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="px-4 py-3">
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4">
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -296,14 +276,10 @@ function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
|
|
||||||
function InfoCard({ result }: { result: InfoResult }) {
|
function InfoCard({ result }: { result: InfoResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-start gap-3 px-4 py-3">
|
<div className="flex items-start gap-3 px-5 py-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<InfoIcon className="size-4 mt-0.5 shrink-0 text-muted-foreground" />
|
||||||
<InfoIcon className="size-4 text-amber-500" />
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1 pt-2">
|
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -311,16 +287,12 @@ function InfoCard({ result }: { result: InfoResult }) {
|
||||||
|
|
||||||
function WarningCard({ result }: { result: WarningResult }) {
|
function WarningCard({ result }: { result: WarningResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-amber-500/50 px-4 py-3">
|
<div className="flex items-start gap-3 border-b px-5 py-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<TriangleAlertIcon className="size-4 mt-0.5 shrink-0 text-amber-500" />
|
||||||
<TriangleAlertIcon className="size-4 text-amber-500" />
|
<p className="text-sm font-medium text-amber-600 dark:text-amber-500">Partial success</p>
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-amber-600 dark:text-amber-500">Partial success</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2 px-4 py-3 text-xs">
|
<div className="px-5 py-4 space-y-2 text-xs">
|
||||||
<p className="text-sm text-muted-foreground">{result.warning}</p>
|
<p className="text-sm text-muted-foreground">{result.warning}</p>
|
||||||
{result.title && (
|
{result.title && (
|
||||||
<div className="pt-2">
|
<div className="pt-2">
|
||||||
|
|
@ -335,33 +307,31 @@ function WarningCard({ result }: { result: WarningResult }) {
|
||||||
|
|
||||||
function SuccessCard({ result }: { result: SuccessResult }) {
|
function SuccessCard({ result }: { result: SuccessResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-border bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-border px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-green-500/10">
|
<p className="text-sm font-semibold text-foreground">
|
||||||
<CheckIcon className="size-4 text-green-500" />
|
{result.message || "Notion page deleted successfully"}
|
||||||
</div>
|
</p>
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-[.8rem] text-muted-foreground">
|
|
||||||
{result.message || "Notion page deleted successfully"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{(result.deleted_from_kb || result.title) && (
|
{(result.deleted_from_kb || result.title) && (
|
||||||
<div className="space-y-2 px-4 py-3 text-xs">
|
<>
|
||||||
{result.title && (
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
<div>
|
<div className="px-5 py-4 space-y-2 text-xs">
|
||||||
<span className="font-medium text-muted-foreground">Deleted page: </span>
|
{result.title && (
|
||||||
<span>{result.title}</span>
|
<div>
|
||||||
</div>
|
<span className="font-medium text-muted-foreground">Deleted page: </span>
|
||||||
)}
|
<span>{result.title}</span>
|
||||||
{result.deleted_from_kb && (
|
</div>
|
||||||
<div className="pt-1">
|
)}
|
||||||
<span className="text-green-600 dark:text-green-500">
|
{result.deleted_from_kb && (
|
||||||
✓ Also removed from knowledge base
|
<div className="pt-1">
|
||||||
</span>
|
<span className="text-green-600 dark:text-green-500">
|
||||||
</div>
|
Also removed from knowledge base
|
||||||
)}
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -372,11 +342,11 @@ export const DeleteNotionPageToolUI = makeAssistantToolUI<
|
||||||
DeleteNotionPageResult
|
DeleteNotionPageResult
|
||||||
>({
|
>({
|
||||||
toolName: "delete_notion_page",
|
toolName: "delete_notion_page",
|
||||||
render: function DeleteNotionPageUI({ args, result, status }) {
|
render: function DeleteNotionPageUI({ result, status }) {
|
||||||
if (status.type === "running") {
|
if (status.type === "running") {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 flex max-w-md items-center gap-3 rounded-xl border border-border bg-card px-4 py-3">
|
<div className="my-4 flex max-w-lg items-center gap-3 rounded-2xl border bg-muted/30 px-5 py-4">
|
||||||
<Loader2Icon className="size-4 animate-spin text-muted-foreground" />
|
<Spinner size="sm" className="text-muted-foreground" />
|
||||||
<p className="text-sm text-muted-foreground">Deleting Notion page...</p>
|
<p className="text-sm text-muted-foreground">Deleting Notion page...</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -389,7 +359,6 @@ export const DeleteNotionPageToolUI = makeAssistantToolUI<
|
||||||
if (isInterruptResult(result)) {
|
if (isInterruptResult(result)) {
|
||||||
return (
|
return (
|
||||||
<ApprovalCard
|
<ApprovalCard
|
||||||
args={args}
|
|
||||||
interruptData={result}
|
interruptData={result}
|
||||||
onDecision={(decision) => {
|
onDecision={(decision) => {
|
||||||
const event = new CustomEvent("hitl-decision", {
|
const event = new CustomEvent("hitl-decision", {
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,13 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { makeAssistantToolUI } from "@assistant-ui/react";
|
import { makeAssistantToolUI } from "@assistant-ui/react";
|
||||||
import {
|
import { CornerDownLeftIcon, InfoIcon, Pen } from "lucide-react";
|
||||||
AlertTriangleIcon,
|
import { useCallback, useEffect, useState } from "react";
|
||||||
CheckIcon,
|
|
||||||
InfoIcon,
|
|
||||||
Loader2Icon,
|
|
||||||
MaximizeIcon,
|
|
||||||
MinimizeIcon,
|
|
||||||
Pen,
|
|
||||||
XIcon,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { useMemo, useState } from "react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { PlateEditor } from "@/components/editor/plate-editor";
|
||||||
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
|
import { useSetAtom } from "jotai";
|
||||||
|
import { openHitlEditPanelAtom } from "@/atoms/chat/hitl-edit-panel.atom";
|
||||||
|
|
||||||
interface InterruptResult {
|
interface InterruptResult {
|
||||||
__interrupt__: true;
|
__interrupt__: true;
|
||||||
|
|
@ -110,9 +104,8 @@ function ApprovalCard({
|
||||||
const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>(
|
const [decided, setDecided] = useState<"approve" | "reject" | "edit" | null>(
|
||||||
interruptData.__decided__ ?? null
|
interruptData.__decided__ ?? null
|
||||||
);
|
);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
||||||
const [isFullScreen, setIsFullScreen] = useState(false);
|
const openHitlEditPanel = useSetAtom(openHitlEditPanelAtom);
|
||||||
const [editedArgs, setEditedArgs] = useState<Record<string, unknown>>(args);
|
|
||||||
|
|
||||||
const account = interruptData.context?.account;
|
const account = interruptData.context?.account;
|
||||||
const currentTitle = interruptData.context?.current_title;
|
const currentTitle = interruptData.context?.current_title;
|
||||||
|
|
@ -121,79 +114,102 @@ function ApprovalCard({
|
||||||
const allowedDecisions = reviewConfig?.allowed_decisions ?? ["approve", "reject"];
|
const allowedDecisions = reviewConfig?.allowed_decisions ?? ["approve", "reject"];
|
||||||
const canEdit = allowedDecisions.includes("edit");
|
const canEdit = allowedDecisions.includes("edit");
|
||||||
|
|
||||||
|
const handleApprove = useCallback(() => {
|
||||||
|
if (decided || isPanelOpen) return;
|
||||||
|
if (!allowedDecisions.includes("approve")) return;
|
||||||
|
setDecided("approve");
|
||||||
|
onDecision({
|
||||||
|
type: "approve",
|
||||||
|
edited_action: {
|
||||||
|
name: interruptData.action_requests[0].name,
|
||||||
|
args: {
|
||||||
|
page_id: args.page_id,
|
||||||
|
content: args.content,
|
||||||
|
connector_id: account?.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [decided, isPanelOpen, allowedDecisions, onDecision, interruptData, args, account?.id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
|
||||||
|
handleApprove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
window.addEventListener("keydown", handler);
|
||||||
|
return () => window.removeEventListener("keydown", handler);
|
||||||
|
}, [handleApprove]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30 transition-all duration-300">
|
||||||
{/* Backdrop for full-screen mode */}
|
{/* Header */}
|
||||||
{isFullScreen && (
|
<div className="flex items-start justify-between px-5 pt-5 pb-4">
|
||||||
<div
|
<div>
|
||||||
className="fixed inset-0 z-50 bg-black/50 backdrop-blur-sm"
|
<p className="text-sm font-semibold text-foreground">
|
||||||
onClick={() => setIsFullScreen(false)}
|
{decided === "reject"
|
||||||
/>
|
? "Notion Page Update Rejected"
|
||||||
)}
|
: decided === "approve" || decided === "edit"
|
||||||
|
? "Notion Page Update Approved"
|
||||||
<div
|
: "Update Notion Page"}
|
||||||
className={`${
|
</p>
|
||||||
isFullScreen
|
<p className="text-xs text-muted-foreground mt-0.5">
|
||||||
? "fixed left-1/2 top-1/2 z-50 h-[90vh] flex max-h-300 w-[90vw] max-w-350 -translate-x-1/2 -translate-y-1/2 flex-col"
|
{decided === "reject"
|
||||||
: "my-4 max-w-full"
|
? "Page update was cancelled"
|
||||||
} overflow-hidden rounded-xl bg-background shadow-xl transition-all duration-300 ${
|
: decided === "edit"
|
||||||
decided
|
? "Page update is in progress with your changes"
|
||||||
? "border border-border bg-card shadow-sm"
|
: decided === "approve"
|
||||||
: "border-2 border-foreground/20 bg-muted/30 dark:bg-muted/10 shadow-lg animate-pulse-subtle"
|
? "Page update is in progress"
|
||||||
}`}
|
: "Requires your approval to proceed"}
|
||||||
>
|
</p>
|
||||||
<div
|
|
||||||
className={`flex items-center gap-3 border-b ${
|
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/40 dark:bg-muted/20"
|
|
||||||
} px-4 py-3`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={`flex size-9 shrink-0 items-center justify-center rounded-lg ${
|
|
||||||
decided ? "bg-muted" : "bg-muted animate-pulse"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<AlertTriangleIcon
|
|
||||||
className={`size-4 ${decided ? "text-muted-foreground" : "text-foreground"}`}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className={`text-sm font-medium ${decided ? "text-foreground" : "text-foreground"}`}>
|
|
||||||
Update Notion Page
|
|
||||||
</p>
|
|
||||||
<p
|
|
||||||
className={`truncate text-xs ${
|
|
||||||
decided ? "text-muted-foreground" : "text-muted-foreground"
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{isEditing ? "You can edit the arguments below" : "Requires your approval to proceed"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{isEditing && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => setIsFullScreen(!isFullScreen)}
|
|
||||||
className="shrink-0"
|
|
||||||
>
|
|
||||||
{isFullScreen ? (
|
|
||||||
<MinimizeIcon className="size-4" />
|
|
||||||
) : (
|
|
||||||
<MaximizeIcon className="size-4" />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
{!decided && canEdit && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
className="rounded-lg text-muted-foreground -mt-1 -mr-2"
|
||||||
|
onClick={() => {
|
||||||
|
setIsPanelOpen(true);
|
||||||
|
openHitlEditPanel({
|
||||||
|
title: currentTitle ?? "",
|
||||||
|
content: String(args.content ?? ""),
|
||||||
|
toolName: "Notion Page",
|
||||||
|
onSave: (_, newContent) => {
|
||||||
|
setIsPanelOpen(false);
|
||||||
|
setDecided("edit");
|
||||||
|
onDecision({
|
||||||
|
type: "edit",
|
||||||
|
edited_action: {
|
||||||
|
name: interruptData.action_requests[0].name,
|
||||||
|
args: {
|
||||||
|
page_id: args.page_id,
|
||||||
|
content: newContent,
|
||||||
|
connector_id: account?.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pen className="size-3.5" />
|
||||||
|
Edit
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Context section - READ ONLY account and page info */}
|
{/* Context section — read-only account and page info */}
|
||||||
{!decided && interruptData.context && (
|
{!decided && interruptData.context && (
|
||||||
<div className="border-b border-border px-4 py-3 bg-muted/30 space-y-3">
|
<>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4 space-y-4">
|
||||||
{interruptData.context.error ? (
|
{interruptData.context.error ? (
|
||||||
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
<p className="text-sm text-destructive">{interruptData.context.error}</p>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{account && (
|
{account && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="text-xs font-medium text-muted-foreground">Notion Account</div>
|
<p className="text-xs font-medium text-muted-foreground">Notion Account</p>
|
||||||
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
||||||
{account.workspace_name}
|
{account.workspace_name}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -202,7 +218,7 @@ function ApprovalCard({
|
||||||
|
|
||||||
{currentTitle && (
|
{currentTitle && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="text-xs font-medium text-muted-foreground">Current Page</div>
|
<p className="text-xs font-medium text-muted-foreground">Current Page</p>
|
||||||
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
<div className="w-full rounded-md border border-input bg-muted/50 px-3 py-2 text-sm">
|
||||||
📄 {currentTitle}
|
📄 {currentTitle}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -211,168 +227,76 @@ function ApprovalCard({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Display mode - show proposed changes as read-only */}
|
{/* Content preview */}
|
||||||
{!isEditing && (
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 pt-3">
|
||||||
|
{args.content != null ? (
|
||||||
<div
|
<div
|
||||||
className={`space-y-2 px-4 py-3 bg-card ${isFullScreen ? "flex-1 overflow-y-auto" : ""}`}
|
className="max-h-[7rem] overflow-hidden text-sm"
|
||||||
|
style={{
|
||||||
|
maskImage: "linear-gradient(to bottom, black 50%, transparent 100%)",
|
||||||
|
WebkitMaskImage: "linear-gradient(to bottom, black 50%, transparent 100%)",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{args.content != null && (
|
<PlateEditor
|
||||||
<div>
|
markdown={String(args.content)}
|
||||||
<p className="text-xs font-medium text-muted-foreground">New Content</p>
|
readOnly
|
||||||
<p className="line-clamp-4 text-sm whitespace-pre-wrap text-foreground">
|
preset="readonly"
|
||||||
{String(args.content)}
|
editorVariant="none"
|
||||||
</p>
|
className="h-auto [&_[data-slate-editor]]:!min-h-0 [&_[data-slate-editor]>*:first-child]:!mt-0"
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{args.content == null && (
|
|
||||||
<p className="text-sm text-muted-foreground italic">No content update specified</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Edit mode - show editable form fields */}
|
|
||||||
{isEditing && !decided && (
|
|
||||||
<div
|
|
||||||
className={`px-4 py-3 bg-card ${isFullScreen ? "flex-1 flex flex-col overflow-hidden" : ""}`}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
htmlFor="notion-content"
|
|
||||||
className="text-xs font-medium text-muted-foreground mb-1.5 block"
|
|
||||||
>
|
|
||||||
New Content
|
|
||||||
</label>
|
|
||||||
<Textarea
|
|
||||||
id="notion-content"
|
|
||||||
value={String(editedArgs.content ?? "")}
|
|
||||||
onChange={(e) => setEditedArgs({ ...editedArgs, content: e.target.value || null })}
|
|
||||||
placeholder="Enter content to append to the page"
|
|
||||||
rows={isFullScreen ? undefined : 12}
|
|
||||||
className={`resize-none ${isFullScreen ? "flex-1 min-h-0" : ""}`}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-muted-foreground italic pb-3">No content update specified</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Action buttons */}
|
|
||||||
<div
|
|
||||||
className={`flex items-center gap-2 border-t ${
|
|
||||||
decided ? "border-border bg-card" : "border-foreground/15 bg-muted/20 dark:bg-muted/10"
|
|
||||||
} px-4 py-3`}
|
|
||||||
>
|
|
||||||
{decided ? (
|
|
||||||
<p className="flex items-center gap-1.5 text-sm text-muted-foreground">
|
|
||||||
{decided === "approve" || decided === "edit" ? (
|
|
||||||
<>
|
|
||||||
<CheckIcon className="size-3.5 text-green-500" />
|
|
||||||
{decided === "edit" ? "Approved with Changes" : "Approved"}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<XIcon className="size-3.5 text-destructive" />
|
|
||||||
Rejected
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
) : isEditing ? (
|
|
||||||
<>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
onClick={() => {
|
|
||||||
setDecided("edit");
|
|
||||||
setIsEditing(false);
|
|
||||||
setIsFullScreen(false);
|
|
||||||
onDecision({
|
|
||||||
type: "edit",
|
|
||||||
edited_action: {
|
|
||||||
name: interruptData.action_requests[0].name,
|
|
||||||
args: {
|
|
||||||
page_id: args.page_id,
|
|
||||||
content: editedArgs.content,
|
|
||||||
connector_id: account?.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CheckIcon />
|
|
||||||
Approve with Changes
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => {
|
|
||||||
setIsEditing(false);
|
|
||||||
setIsFullScreen(false);
|
|
||||||
setEditedArgs(args); // Reset to original args
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{allowedDecisions.includes("approve") && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
onClick={() => {
|
|
||||||
setDecided("approve");
|
|
||||||
onDecision({
|
|
||||||
type: "approve",
|
|
||||||
edited_action: {
|
|
||||||
name: interruptData.action_requests[0].name,
|
|
||||||
args: {
|
|
||||||
page_id: args.page_id,
|
|
||||||
content: args.content,
|
|
||||||
connector_id: account?.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CheckIcon />
|
|
||||||
Approve
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{canEdit && (
|
|
||||||
<Button size="sm" variant="outline" onClick={() => setIsEditing(true)}>
|
|
||||||
<Pen />
|
|
||||||
Edit
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{allowedDecisions.includes("reject") && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => {
|
|
||||||
setDecided("reject");
|
|
||||||
onDecision({ type: "reject", message: "User rejected the action." });
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<XIcon />
|
|
||||||
Reject
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
|
{/* Action buttons - only shown when pending */}
|
||||||
|
{!decided && (
|
||||||
|
<>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4 flex items-center gap-2">
|
||||||
|
{allowedDecisions.includes("approve") && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
className="rounded-lg gap-1.5"
|
||||||
|
onClick={handleApprove}
|
||||||
|
>
|
||||||
|
Approve
|
||||||
|
<CornerDownLeftIcon className="size-3 opacity-60" />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{allowedDecisions.includes("reject") && (
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
className="rounded-lg text-muted-foreground"
|
||||||
|
onClick={() => {
|
||||||
|
setDecided("reject");
|
||||||
|
onDecision({ type: "reject", message: "User rejected the action." });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ErrorCard({ result }: { result: ErrorResult }) {
|
function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-destructive/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-destructive/50 px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-destructive/10">
|
<p className="text-sm font-semibold text-destructive">Failed to update Notion page</p>
|
||||||
<XIcon className="size-4 text-destructive" />
|
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-sm font-medium text-destructive">Failed to update Notion page</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="px-4 py-3">
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
|
<div className="px-5 py-4">
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -381,14 +305,10 @@ function ErrorCard({ result }: { result: ErrorResult }) {
|
||||||
|
|
||||||
function InfoCard({ result }: { result: InfoResult }) {
|
function InfoCard({ result }: { result: InfoResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-amber-500/50 bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-start gap-3 px-4 py-3">
|
<div className="flex items-start gap-3 px-5 py-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-amber-500/10">
|
<InfoIcon className="size-4 mt-0.5 shrink-0 text-muted-foreground" />
|
||||||
<InfoIcon className="size-4 text-amber-500" />
|
<p className="text-sm text-muted-foreground">{result.message}</p>
|
||||||
</div>
|
|
||||||
<div className="min-w-0 flex-1 pt-2">
|
|
||||||
<p className="text-sm text-muted-foreground">{result.message}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -396,19 +316,14 @@ function InfoCard({ result }: { result: InfoResult }) {
|
||||||
|
|
||||||
function SuccessCard({ result }: { result: SuccessResult }) {
|
function SuccessCard({ result }: { result: SuccessResult }) {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 max-w-md overflow-hidden rounded-xl border border-border bg-card">
|
<div className="my-4 max-w-lg overflow-hidden rounded-2xl border bg-muted/30">
|
||||||
<div className="flex items-center gap-3 border-b border-border px-4 py-3">
|
<div className="px-5 pt-5 pb-4">
|
||||||
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-green-500/10">
|
<p className="text-sm font-semibold text-foreground">
|
||||||
<CheckIcon className="size-4 text-green-500" />
|
{result.message || "Notion page updated successfully"}
|
||||||
</div>
|
</p>
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="text-[.8rem] text-muted-foreground">
|
|
||||||
{result.message || "Notion page updated successfully"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div className="mx-5 h-px bg-border/50" />
|
||||||
<div className="space-y-2 px-4 py-3 text-xs">
|
<div className="px-5 py-4 space-y-2 text-xs">
|
||||||
<div>
|
<div>
|
||||||
<span className="font-medium text-muted-foreground">Title: </span>
|
<span className="font-medium text-muted-foreground">Title: </span>
|
||||||
<span>{result.title}</span>
|
<span>{result.title}</span>
|
||||||
|
|
@ -438,8 +353,8 @@ export const UpdateNotionPageToolUI = makeAssistantToolUI<
|
||||||
render: function UpdateNotionPageUI({ args, result, status }) {
|
render: function UpdateNotionPageUI({ args, result, status }) {
|
||||||
if (status.type === "running") {
|
if (status.type === "running") {
|
||||||
return (
|
return (
|
||||||
<div className="my-4 flex max-w-md items-center gap-3 rounded-xl border border-border bg-card px-4 py-3">
|
<div className="my-4 flex max-w-lg items-center gap-3 rounded-2xl border bg-muted/30 px-5 py-4">
|
||||||
<Loader2Icon className="size-4 animate-spin text-muted-foreground" />
|
<Spinner size="sm" className="text-muted-foreground" />
|
||||||
<p className="text-sm text-muted-foreground">Updating Notion page...</p>
|
<p className="text-sm text-muted-foreground">Updating Notion page...</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue