confirmation.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Derived from vercel/ai-elements (skills/ai-elements/scripts/confirmation.tsx).
  3. * Copyright 2023 Vercel, Inc. Licensed under Apache-2.0.
  4. * Modified by ZCode: local integration, formatting and adaptations.
  5. * See THIRD-PARTY-NOTICES.md in the repository root for license and provenance.
  6. */
  7. "use client";
  8. import {
  9. Confirmation,
  10. ConfirmationAccepted,
  11. ConfirmationAction,
  12. ConfirmationActions,
  13. ConfirmationRejected,
  14. ConfirmationRequest,
  15. ConfirmationTitle,
  16. } from "@/components/ai-elements/confirmation";
  17. import { CheckIcon, XIcon } from "lucide-react";
  18. import { nanoid } from "nanoid";
  19. const handleReject = () => {
  20. // In production, call respondToConfirmationRequest with approved: false
  21. };
  22. const handleApprove = () => {
  23. // In production, call respondToConfirmationRequest with approved: true
  24. };
  25. const Example = () => (
  26. <div className="w-full max-w-2xl">
  27. <Confirmation approval={{ id: nanoid() }} state="approval-requested">
  28. <ConfirmationTitle>
  29. <ConfirmationRequest>
  30. This tool wants to delete the file{" "}
  31. <code className="inline rounded bg-muted px-1.5 py-0.5 text-sm">/tmp/example.txt</code>.
  32. Do you approve this action?
  33. </ConfirmationRequest>
  34. <ConfirmationAccepted>
  35. <CheckIcon className="size-4 text-green-600 dark:text-green-400" />
  36. <span>You approved this tool execution</span>
  37. </ConfirmationAccepted>
  38. <ConfirmationRejected>
  39. <XIcon className="size-4 text-destructive" />
  40. <span>You rejected this tool execution</span>
  41. </ConfirmationRejected>
  42. </ConfirmationTitle>
  43. <ConfirmationActions>
  44. <ConfirmationAction onClick={handleReject} variant="outline">
  45. Reject
  46. </ConfirmationAction>
  47. <ConfirmationAction onClick={handleApprove} variant="default">
  48. Approve
  49. </ConfirmationAction>
  50. </ConfirmationActions>
  51. </Confirmation>
  52. </div>
  53. );
  54. export default Example;