"use client"; import type { ToolCallMessagePartProps } from "@assistant-ui/react"; import { CornerDownLeftIcon } from "lucide-react"; import { useCallback, useEffect, useState } from "react"; import { TextShimmerLoader } from "@/components/prompt-kit/loader"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { useHitlPhase } from "@/hooks/use-hitl-phase"; interface InterruptResult { __interrupt__: true; __decided__?: "approve" | "reject"; __completed__?: boolean; action_requests: Array<{ name: string; args: Record; }>; review_configs: Array<{ action_name: string; allowed_decisions: Array<"approve" | "reject">; }>; interrupt_type?: string; context?: { workspace?: { id: number; organization_name: string }; issue?: { id: string; identifier: string; title: string; state?: string; document_id?: number; indexed_at?: string; }; error?: string; }; } interface SuccessResult { status: "success"; deleted_from_kb?: boolean; message?: string; } interface ErrorResult { status: "error"; message: string; } interface NotFoundResult { status: "not_found"; message: string; } interface WarningResult { status: "success"; warning: string; message?: string; } interface AuthErrorResult { status: "auth_error"; message: string; connector_id?: number; connector_type: string; } type DeleteLinearIssueResult = | InterruptResult | SuccessResult | ErrorResult | NotFoundResult | WarningResult | AuthErrorResult; 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 isNotFoundResult(result: unknown): result is NotFoundResult { return ( typeof result === "object" && result !== null && "status" in result && (result as NotFoundResult).status === "not_found" ); } function isWarningResult(result: unknown): result is WarningResult { return ( typeof result === "object" && result !== null && "status" in result && (result as WarningResult).status === "success" && "warning" in result && typeof (result as WarningResult).warning === "string" ); } function isAuthErrorResult(result: unknown): result is AuthErrorResult { return ( typeof result === "object" && result !== null && "status" in result && (result as AuthErrorResult).status === "auth_error" ); } function ApprovalCard({ interruptData, onDecision, }: { interruptData: InterruptResult; onDecision: (decision: { type: "approve" | "reject"; message?: string; edited_action?: { name: string; args: Record }; }) => void; }) { const { phase, setProcessing, setRejected } = useHitlPhase(interruptData); const [deleteFromKb, setDeleteFromKb] = useState(false); const context = interruptData.context; const issue = context?.issue; const handleApprove = useCallback(() => { if (phase !== "pending") return; setProcessing(); onDecision({ type: "approve", edited_action: { name: interruptData.action_requests[0].name, args: { issue_id: issue?.id, connector_id: context?.workspace?.id, delete_from_kb: deleteFromKb, }, }, }); }, [ phase, setProcessing, onDecision, interruptData, issue?.id, context?.workspace?.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 (
{/* Header */}

{phase === "rejected" ? "Linear Issue Deletion Rejected" : phase === "processing" || phase === "complete" ? "Linear Issue Deletion Approved" : "Delete Linear Issue"}

{phase === "processing" ? ( ) : phase === "complete" ? (

Issue deleted

) : phase === "rejected" ? (

Issue deletion was cancelled

) : (

Requires your approval to proceed

)}
{/* Context section — workspace + issue info (visible in pending, processing, complete) */} {phase !== "rejected" && context && ( <>
{context.error ? (

{context.error}

) : ( <> {context.workspace && (

Linear Account

{context.workspace.organization_name}
)} {issue && (

Issue to Archive

{issue.identifier}: {issue.title}
{issue.state && (
{issue.state}
)}
)} )}
)} {/* delete_from_kb toggle */} {phase === "pending" && ( <>
setDeleteFromKb(v === true)} className="shrink-0" />
)} {/* Action buttons - only shown when pending */} {phase === "pending" && ( <>
)}
); } function AuthErrorCard({ result }: { result: AuthErrorResult }) { return (

Linear authentication expired

{result.message}

); } function ErrorCard({ result }: { result: ErrorResult }) { return (

Failed to delete Linear issue

{result.message}

); } function NotFoundCard({ result }: { result: NotFoundResult }) { return (

Issue not found

{result.message}

); } function WarningCard({ result }: { result: WarningResult }) { return (

Partial success

{result.warning}

); } function SuccessCard({ result }: { result: SuccessResult }) { return (

{result.message || "Linear issue archived successfully"}

{result.deleted_from_kb && ( <>
Also removed from knowledge base
)}
); } export const DeleteLinearIssueToolUI = ({ result }: ToolCallMessagePartProps<{ issue_ref: string; delete_from_kb?: boolean }, DeleteLinearIssueResult>) => { if (!result) return null; if (isInterruptResult(result)) { return ( { const event = new CustomEvent("hitl-decision", { detail: { decisions: [decision] }, }); window.dispatchEvent(event); }} /> ); } if ( typeof result === "object" && result !== null && "status" in result && (result as { status: string }).status === "rejected" ) { return null; } if (isNotFoundResult(result)) return ; if (isAuthErrorResult(result)) return ; if (isWarningResult(result)) return ; if (isErrorResult(result)) return ; return ; };