Skip to Content
Kokonut UI

AI-23AINew, October 21, 2026

AI Inline Edit

Select text in a document and ask AI to rewrite it. The edit streams in place as a word-level diff you accept, discard or try again.

Install with
lucide-react, motion

Usage

Pass your document as paragraphs and a rewrite that calls your model. It gets the selected text and the instruction, and returns the new text, a Promise of it, or a stream of deltas such as the AI SDK's textStream. The bar works until the text is complete, then writes the changes into the sentence. Stop aborts the signal, and a throw shows the error's message in the bar. onChange gets every paragraph once a rewrite is accepted.

"use client";

import AIInlineEdit from "@/components/kokonutui/ai-inline-edit";

export function Editor({ doc, save }: { doc: string[]; save: (doc: string[]) => void }) {
  return (
    <AIInlineEdit
      onChange={save}
      paragraphs={doc}
      rewrite={async function* (text, instruction, attempt, signal) {
        const res = await fetch("/api/rewrite", {
          method: "POST",
          body: JSON.stringify({ text, instruction, attempt }),
          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;
        }
      }}
      title="Billing launch update"
    />
  );
}
// app/api/rewrite/route.ts
import { anthropic } from "@ai-sdk/anthropic";
import { streamText } from "ai";

export async function POST(req: Request) {
  const { text, instruction, attempt } = await req.json();
  const result = streamText({
    model: anthropic("claude-sonnet-5-5"),
    temperature: attempt > 0 ? 1 : 0.3,
    system: "Rewrite the text as asked. Reply with the new text only.",
    prompt: `${instruction}:\n\n${text}`,
    abortSignal: req.signal,
  });
  return result.toTextStreamResponse();
}

PROSlash Command Menu and more like it are in Kokonut UI Pro

Installation

AI Inline Edit 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-inline-edit.tsx, so the code is yours to change.

npx shadcn@latest add @kokonutui/ai-inline-edit

Or add it by hand: install its packages, then copy the source from Copy code above into components/kokonutui/ai-inline-edit.tsx.

npm install lucide-react motion

Props

title
stringDefault "Billing launch update"
paragraphs
string[]Default demo data

The document, one string per paragraph. Read once, on mount.

rewrite
(text: string, instruction: string, attempt: number, signal: AbortSignal) => RewriteDefault demo data

Rewrites the selected text. Return the text, a Promise of it, or a stream of deltas (like the AI SDK's textStream); the bar shows it working until the text is complete, then writes the changes in. attempt counts up with each Try again, so you can ask for a different take. signal aborts when the person presses Stop. Throw and the bar shows the error's message.

onChange
(paragraphs: string[]) => void

Called with every paragraph once a rewrite is accepted.

className
string

Extra classes for the root element.

Rewrite

A rewrite: the text, a Promise of it, or a stream of text deltas.

type Rewrite = string | Promise<string> | AsyncIterable<string>;

Dependencies

NeedsVersionComes from
lucide-react^0.556.0npm, installed by the CLI
motion^12.23.25npm, installed by the CLI
cn from lib/utils.tsshadcn init
React19Your app
Tailwind CSS4Your app

No provider, font or global CSS to set up: the file works as soon as it lands.