confirmation-request.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use client";
  2. import {
  3. Confirmation,
  4. ConfirmationAccepted,
  5. ConfirmationAction,
  6. ConfirmationActions,
  7. ConfirmationRejected,
  8. ConfirmationRequest,
  9. ConfirmationTitle,
  10. } from "@/components/ai-elements/confirmation";
  11. import { CheckIcon, XIcon } from "lucide-react";
  12. import { nanoid } from "nanoid";
  13. const handleReject = () => {
  14. // In production, call respondToConfirmationRequest with approved: false
  15. };
  16. const handleApprove = () => {
  17. // In production, call respondToConfirmationRequest with approved: true
  18. };
  19. const Example = () => (
  20. <div className="w-full max-w-2xl">
  21. <Confirmation approval={{ id: nanoid() }} state="approval-requested">
  22. <ConfirmationTitle>
  23. <ConfirmationRequest>
  24. This tool wants to execute a query on the production database:
  25. <code className="mt-2 block rounded bg-muted p-2 text-sm">
  26. SELECT * FROM users WHERE role = &apos;admin&apos;
  27. </code>
  28. </ConfirmationRequest>
  29. <ConfirmationAccepted>
  30. <CheckIcon className="size-4 text-green-600 dark:text-green-400" />
  31. <span>You approved this tool execution</span>
  32. </ConfirmationAccepted>
  33. <ConfirmationRejected>
  34. <XIcon className="size-4 text-destructive" />
  35. <span>You rejected this tool execution</span>
  36. </ConfirmationRejected>
  37. </ConfirmationTitle>
  38. <ConfirmationActions>
  39. <ConfirmationAction onClick={handleReject} variant="outline">
  40. Reject
  41. </ConfirmationAction>
  42. <ConfirmationAction onClick={handleApprove} variant="default">
  43. Approve
  44. </ConfirmationAction>
  45. </ConfirmationActions>
  46. </Confirmation>
  47. </div>
  48. );
  49. export default Example;