Skip to Content
Kokonut UI

AI-01AINew, December 6, 2026

AI Composer

A chat composer that shows what the model will read. Type @ to pull in files, docs, chats and pages as tokens in the message, and watch each one get read when you send.

Install with
lucide-react, motion

Usage

Pass sources for what @ can pull in. With the AI SDK, hand the composer useChat's status and stop: "submitted" and "streaming" turn Send into Stop, "ready" finishes the run, and "error" puts the message back in the box. onSubmit gets the text, the model, the sources mentioned (in the order they appear) and the files.

"use client";

import { useChat } from "@ai-sdk/react";
import AIComposer, { type ComposerSource } from "@/components/kokonutui/ai-composer";

const sources: ComposerSource[] = [
  { id: "readme", label: "README.md", kind: "file", detail: "Repository root", tokens: 1800 },
  { id: "roadmap", label: "Roadmap", kind: "doc", detail: "Doc · Product", tokens: 4200 },
];

export function Chat() {
  const { sendMessage, status, stop } = useChat();
  return (
    <AIComposer
      accept="image/*,.pdf,.md"
      defaultValue=""
      onStop={stop}
      onSubmit={({ text, model, sources, files }) => {
        const transfer = new DataTransfer();
        for (const file of files) transfer.items.add(file);
        sendMessage(
          { text, files: transfer.files },
          { body: { model, sources: sources.map((s) => s.id) } }
        );
      }}
      sources={sources}
      status={status}
      tokenLimit={200_000}
    />
  );
}

Without status, return a promise from onSubmit instead: the run lasts until it settles, signal aborts on Stop, and a rejection puts the message back. With neither, the composer plays a short pretend run.

Details

  • A mention is @ and a source's label, so labels can hold spaces ("@Q4 launch plan"). Backspace takes a whole mention at once.
  • Hovering a chip lights up its words, clicking it selects them, and its × takes them out of the message.
  • Send is drawn as the key that sends. It goes down when you press Enter, reads "New line" while Shift is held, and turns into Stop (or Esc) during a run.
  • ↑ in an empty box brings back the last message.
  • accept, maxFiles and maxFileSize check files as they are picked, dropped or pasted. A file turned away calls onError with a code (accept, max_file_size or max_files), and the bar says why.
  • tokens is a rough size per source. The bar adds them up with the files and the message, and past tokenLimit it says by how much and Send waits.

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

Installation

AI Composer 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-composer.tsx, so the code is yours to change.

npx shadcn@latest add @kokonutui/ai-composer

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

npm install lucide-react motion

Props

sources
ComposerSource[]Default built-in

What @ can pull in: files, docs, past chats and pages.

models
ComposerModel[]Default built-in
defaultModel
stringDefault "Claude Opus 5.5"

Name of the model picked at first.

defaultValue
stringDefault built-in

The message the composer opens with. Pass "" for an empty box.

placeholder
stringDefault "Ask anything. Type @ to add context"
onSubmit
(message: ComposerMessage, options: { signal: AbortSignal }) => unknown

Sends the message. Return a promise to keep the run going until it settles; signal aborts on Stop. If it rejects, the message comes back into the box. Without it (and without status), a short pretend run plays.

status
ComposerStatus

Drives the run from your chat instead of from onSubmit's promise: pass useChat().status. "submitted" and "streaming" show Stop, back to "ready" finishes the run, and "error" puts the message back.

onStop
() => void

Called on Stop (the key, or Esc) during a run.

accept
string

File types to take, as in an input's accept: "image/*,.pdf".

maxFiles
numberDefault 8

Most files one message can carry.

maxFileSize
numberDefault 20 * MB

Largest file, in bytes.

onError
(error: ComposerError) => void

Called when a file is turned away; the bar also says why.

tokenLimit
number

The model's context budget in tokens. Past it, the bar says by how much and Send waits until something is taken out.

className
string

Extra classes for the root element.

ComposerSource

idrequired
string
labelrequired
string

What follows @ in the message, e.g. "pricing-table.tsx".

kindrequired
ComposerSourceKind
detail
string

Second line in the @ menu, e.g. a folder or where the doc lives.

tokens
number

Rough size in tokens, added up in the context bar.

ComposerModel

namerequired
string
description
string

One line under the name in the menu.

ComposerMessage

textrequired
string
modelrequired
string
sourcesrequired
ComposerSource[]

The sources

filesrequired
File[]

Files picked, dropped or pasted in.

ComposerStatus

The same states as the AI SDK's useChat().status, so you can pass it on.

type ComposerStatus = "ready" | "submitted" | "streaming" | "error";

ComposerError

coderequired
"max_files" | "max_file_size" | "accept"
messagerequired
string

ComposerSourceKind

type ComposerSourceKind = "file" | "doc" | "chat" | "web";

Dependencies

NeedsVersionComes from
lucide-react^0.556.0npm, installed by the CLI
motion^12.23.25npm, installed by the CLI
dropdown-menushadcn/ui, added 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.