AI Redact - React Component | Kokonut UI
AI Redact
Masks names, emails, card numbers and keys as placeholders before a prompt is sent, then fills the real values back into the reply.
Install with
npm install ai-redact
Open in
npx shadcn@latest add https://kokonutui.com/r/ai-redact.json```
Names, emails, numbers and keys are swapped for placeholders before anything leaves the browser. Replies are filled back in here.
Draft a reply to Dana Whitfield (dana.whitfield@acme.co, +1 415 555 0132) confirming the refund to card 4242 4242 4242 4242. The charge failed with key sk_live_51Hx9aQ2vT8eLm, what does that error mean?
```plaintext
PERSON_1
EMAIL_1
PHONE_1
CARD_1
SECRET_1
5 items will be masked. Click one to send it as is.
Usage
Pass respond to answer with your model. It gets the masked message, with placeholders like PERSON_1 and EMAIL_1 in place of the real values, and returns the reply, a Promise of it, or a stream of deltas. Placeholders the model writes back stay as chips while the reply streams, then the real values are filled in on this side once it ends. A throw shows the error's message as the reply. Pass names from your CRM so people are masked too; emails, phone numbers, cards and API keys are found by pattern.
"use client";
import AIRedact from "@/components/kokonutui/ai-redact";
export function SupportComposer({ contacts }: { contacts: string[] }) {
return (
<AIRedact
defaultValue=""
names={contacts}
respond={async function* (masked, signal) {
const res = await fetch("/api/reply", {
method: "POST",
body: JSON.stringify({ prompt: masked }),
signal,
});
if (!(res.ok && res.body)) {
throw new Error("Couldn't reach the model. Try again.");
}
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
while (true) {
const { done, value } = await reader.read();
if (done) return;
yield value;
}
}}
/>
);
}
On the server, stream with streamText(...).toTextStreamResponse() and tell the model to keep placeholders exactly as written. The real values never leave the browser.
Answered by a stream. Press send.
Names, emails, numbers and keys are swapped for placeholders before anything leaves the browser. Replies are filled back in here.
Reply to Tomás Reyes (tomas@lumen.io): he was invoiced twice for March and wants the extra one voided.
PERSON_1
EMAIL_1
2 items will be masked. Click one to send it as is.
Installation
AI Redact is a free, open-source React component in the Kokonut UI AI collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/ai-redact.tsx, so the code is yours to change.
npx shadcn@latest add @kokonutui/ai-redact
Or add it by hand: install its packages, then copy the source from above into components/kokonutui/ai-redact.tsx.
npm install lucide-react motion
Props
title:string(Default: "Support assistant")defaultValue:string(Default: "demo data")
Text already in the composer when it mounts.names:string[](Default: "demo data")
Names to mask, e.g. contacts from your CRM. Regexes cover the rest.respond:(masked: string, signal: AbortSignal) => Reply(Default: "demo data")
Answers the masked prompt. It only ever sees placeholders likeEMAIL_1; any it writes back are filled in on this side. Return the reply, a Promise of it, or a stream of text deltas.className:string
Extra classes for the root element.
Reply
A reply: the text, a Promise of it, or a stream of text deltas.
type Reply = string | Promise<string> | AsyncIterable<string>;
Dependencies
| Needs | Version | Comes from |
|---|---|---|
lucide-react |
^0.556.0 |
npm, installed by the CLI |
motion |
^12.23.25 |
npm, installed by the CLI |
cn from lib/utils.ts |
shadcn init | |
| React | 19 |
Your app |
| Tailwind CSS | 4 |
Your app |
No provider, font or global CSS to set up: the file works as soon as it lands.