# Prompt Input

The field a person writes a message in, with a button that sends it or stops the reply.

Source: [prompt-input.tsx](https://github.com/jakejarvis/jarvis-ui/blob/main/src/components/ui/prompt-input.tsx)

```tsx
"use client";

import * as React from "react";

import {
  PromptInput,
  PromptInputAttach,
  PromptInputAttachments,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
  type PromptInputStatus,
} from "@/components/ui/prompt-input";

export default function PromptInputChat() {
  const [status, setStatus] = React.useState<PromptInputStatus>("ready");
  const reply = React.useRef<ReturnType<typeof setTimeout>>(undefined);

  React.useEffect(() => () => clearTimeout(reply.current), []);

  function send() {
    setStatus("submitted");
    reply.current = setTimeout(() => {
      setStatus("streaming");
      reply.current = setTimeout(() => setStatus("ready"), 3000);
    }, 800);
  }

  function stop() {
    clearTimeout(reply.current);
    setStatus("ready");
  }

  return (
    <PromptInput status={status} onSubmit={send} onStop={stop} className="max-w-md">
      <PromptInputAttachments />
      <PromptInputTextarea placeholder="Ask anything…" />
      <PromptInputActions>
        <PromptInputAttach />
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

## Installation

Add the registry, once per project:

```bash
npx shadcn@latest registry add @jarvis=https://ui.jarv.is/r/{name}.json
```

Then add the component:

```bash
npx shadcn@latest add @jarvis/prompt-input
```

## Usage

```tsx
"use client";

import {
  PromptInput,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

export function Composer({ onSend }: { onSend: (text: string) => void }) {
  return (
    <PromptInput onSubmit={({ text }) => onSend(text)}>
      <PromptInputTextarea placeholder="Ask anything…" />
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

Enter sends the message and Shift+Enter starts a new line, except while an input method is
composing text. On a touch screen, where there's no Shift key to hold, Enter starts a new line and
the submit button sends the message. Set `submitShortcut="mod+enter"` on `PromptInputTextarea` to
make Enter start a new line everywhere and Command+Enter or Control+Enter send.

The field clears when the message is sent, and nothing is sent while it's empty. After the submit
button sends a message, focus returns to the field for the next one.

`PromptInputActions` holds the controls below the field. Each one sits at the start of the row, or
at its end with `align="end"`, so a field with controls on both sides has two.

The field's accessible name is "Message" unless a `<label>`, a [`FieldLabel`](https://ui.jarv.is/components/field.md),
`aria-label` or `aria-labelledby` labels it.

`status` takes the same values the AI SDK and TanStack AI use for a reply's progress, so you can
pass either library's `useChat` `status` straight through: `submitted` once the message is sent,
`streaming` while the reply arrives, then `ready`, or `error` if it failed. Nothing can be sent
while the status is `submitted` or `streaming`.

With `onStop`, the submit button becomes a stop button while a reply is on its way. It stays
pending while a promise returned by `onStop` settles. It ignores the second click of a double-click
on the submit button, so sending a message can't immediately stop its reply. Without `onStop`, the
submit button shows a [Spinner](https://ui.jarv.is/components/spinner.md) until the reply is done. The submit button's
`children` and `aria-label` set what it shows and its accessible name while it sends, and
`stopIcon` and `stopLabel` set them while it stops.

**AI SDK**

```tsx
"use client";

import { useChat } from "@ai-sdk/react";

import {
  PromptInput,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

export function ChatInput() {
  const { sendMessage, status, stop } = useChat();

  return (
    <PromptInput status={status} onSubmit={({ text }) => sendMessage({ text })} onStop={stop}>
      <PromptInputTextarea placeholder="Ask anything…" />
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

**TanStack AI**

```tsx
"use client";

import { fetchServerSentEvents, useChat } from "@tanstack/ai-react";

import {
  PromptInput,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

export function ChatInput({ threadId }: { threadId: string }) {
  const { sendMessage, status, stop } = useChat({
    connection: fetchServerSentEvents("/api/chat"),
    threadId,
  });

  return (
    <PromptInput status={status} onSubmit={({ text }) => sendMessage(text)} onStop={stop}>
      <PromptInputTextarea placeholder="Ask anything…" />
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

Return a promise from `onSubmit` to keep the submit button pending until the promise settles. If it
rejects, the message is restored to the field through `onValueChange`, unless the person has started
typing a new one.

## Composition

- `PromptInput`
  - `PromptInputAttachments`
  - `PromptInputTextarea`
  - `PromptInputActions`
    - `PromptInputAttach`
    - `PromptInputButton`
    - `PromptInputUsage`
    - `PromptInputSubmit`

## Examples

### With a model picker

`PromptInputButton` is a ghost icon [Input Group](https://ui.jarv.is/components/input-group.md) button that's disabled
along with the field. The attach and submit buttons are built on it. A [Select](https://ui.jarv.is/components/select.md)
trigger in `PromptInputActions` drops its background and shadow so it sits flat beside the buttons.

```tsx
import {
  PromptInput,
  PromptInputAttach,
  PromptInputAttachments,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";
import { Select, SelectContent, SelectItem, SelectTrigger } from "@/components/ui/select";

const models = {
  fast: "Fast",
  balanced: "Balanced",
  thorough: "Thorough",
};

export default function PromptInputWithModel() {
  return (
    <PromptInput className="max-w-md">
      <PromptInputAttachments />
      <PromptInputTextarea placeholder="Describe the change…" />
      <PromptInputActions>
        <PromptInputAttach />
        <Select items={models} defaultValue="balanced">
          <SelectTrigger size="sm" aria-label="Model" />
          <SelectContent>
            {Object.entries(models).map(([value, label]) => (
              <SelectItem key={value} value={value}>
                {label}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

The field shows its hover tint only while the pointer isn't over one of its controls, and its focus
ring only while the textarea has focus, so each control keeps its own hover and focus states.

### With usage

`PromptInputUsage` shows how much of the model's context the conversation has used, as a half-circle
[Gauge](https://ui.jarv.is/components/gauge.md) and a percentage. The gauge uses the `brand` color, then turns to the
warning color at 75% and the destructive color at 90%. It's a meter rather than a button, so
pressing it does nothing. Its [Tooltip](https://ui.jarv.is/components/tooltip.md) shows `value` and `max` in tokens, and
opens on hover, on focus and on tap on a touch screen. Screen readers announce "Context used" with
the percentage and the counts, such as "64%, 128K of 200K tokens". `label` changes the tooltip,
`aria-label` the accessible name, and `aria-valuetext` the announced value.

```tsx
import {
  PromptInput,
  PromptInputAttach,
  PromptInputAttachments,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
  PromptInputUsage,
} from "@/components/ui/prompt-input";
import { Select, SelectContent, SelectItem, SelectTrigger } from "@/components/ui/select";

const models = {
  fast: "Fast",
  balanced: "Balanced",
  thorough: "Thorough",
};

export default function PromptInputWithUsage() {
  return (
    <PromptInput className="max-w-md">
      <PromptInputAttachments />
      <PromptInputTextarea placeholder="Describe the change…" />
      <PromptInputActions>
        <PromptInputAttach />
        <Select items={models} defaultValue="balanced">
          <SelectTrigger size="sm" aria-label="Model" />
          <SelectContent>
            {Object.entries(models).map(([value, label]) => (
              <SelectItem key={value} value={value}>
                {label}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputUsage value={128_400} max={200_000} />
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

### With attachments

A Prompt Input accepts files only when it contains `PromptInputAttachments`. That part lists the
attached files above the text, each with a remove button, and renders nothing while there are none.
With it, files dropped on or pasted into the field are attached, excluding folders, and
`PromptInputAttach` opens a file picker. Without it, `PromptInputAttach` is disabled. A paste that
also holds text, such as cells copied from a spreadsheet, pastes the text instead.

Removing a file moves focus to the next file's remove button, or the previous one's, or to the field
once none are left. `onSubmit` receives the files as `files`, an array of `File`s, and a message can
be sent with files and no text. The files and text both clear when the message is sent.

`PromptInputAttachments` takes `accept`, `maxFiles` and `maxSize` to limit which files are accepted,
as a [File Input](https://ui.jarv.is/components/file-input.md) does. `onFileReject` is called for each rejected file,
with a `PromptInputFileRejectReason`. `PromptInputAttach` is disabled once `maxFiles` files are
attached. To control the files, use `files`, `defaultFiles` and `onFilesChange` on `PromptInput`,
the way `value` controls the text. `onFilesChange` receives `PromptInputFilesChangeEventDetails`.

```tsx
"use client";

import {
  PromptInput,
  PromptInputAttach,
  PromptInputAttachments,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

const files = [
  new File(["%PDF-1.7"], "q3-report.pdf", { type: "application/pdf" }),
  new File(["# Launch notes"], "launch-notes.md", { type: "text/markdown" }),
];

export default function PromptInputWithAttachments() {
  return (
    <PromptInput defaultFiles={files} className="max-w-md">
      <PromptInputAttachments accept="image/*,.pdf,.md,.txt" maxFiles={4} maxSize={10_000_000} />
      <PromptInputTextarea placeholder="Ask about these files…" />
      <PromptInputActions>
        <PromptInputAttach />
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

### Adaptive layout

With `layout="adaptive"`, the actions sit beside a message that fits on one line, with the start
actions before it and the end actions after it. Once the message wraps or has a line break, it takes
the full width and the actions move below it, as in the stacked layout. Focus moves in the same
order in both: the field, then the start actions, then the end actions.

```tsx
import {
  PromptInput,
  PromptInputActions,
  PromptInputAttach,
  PromptInputAttachments,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

export default function PromptInputAdaptive() {
  return (
    <PromptInput layout="adaptive" className="max-w-md">
      <PromptInputAttachments />
      <PromptInputTextarea placeholder="Message…" />
      <PromptInputActions>
        <PromptInputAttach />
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

The field starts at one line in this layout. Setting `--prompt-input-min-rows` above 1 keeps the
actions below it.

### Height

The field grows with the message, then scrolls. Set `--prompt-input-min-rows` and
`--prompt-input-max-rows` in `PromptInput`'s `className` to change how many lines it shows. They
default to 2 and 8, and you can set them per breakpoint. The field never grows past half the
viewport's height, so the actions stay in view above a software keyboard.

```tsx
import {
  PromptInput,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

export function Composer() {
  return (
    <PromptInput className="[--prompt-input-max-rows:4] md:[--prompt-input-max-rows:12]">
      <PromptInputTextarea placeholder="Ask anything…" />
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

### With a character limit

`submitDisabled` stops Enter and the submit button from sending the message, but leaves the field
editable. Use it for a rule your app checks, such as a length limit or files that are still
uploading. `disabled` disables the field too.

```tsx
"use client";

import * as React from "react";

import {
  PromptInput,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";
import { cn } from "@/lib/utils";

const limit = 280;

export default function PromptInputCharacterLimit() {
  const [value, setValue] = React.useState("");
  const remaining = limit - value.length;

  return (
    <PromptInput
      value={value}
      onValueChange={setValue}
      submitDisabled={remaining < 0}
      className="max-w-md"
    >
      <PromptInputTextarea placeholder="Write a post…" />
      <PromptInputActions align="end">
        <span
          className={cn(
            "px-1 text-xs text-muted-foreground tabular-nums",
            remaining < 0 && "text-destructive",
          )}
        >
          {remaining}
        </span>
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

### Custom controls

[`usePromptInput`](#usepromptinput) reads the Prompt Input that your component renders in, so a
control of your own can read and change the message. This
[Dropdown Menu](https://ui.jarv.is/components/dropdown-menu.md) fills the field with a template.

```tsx
"use client";

import { LayoutTemplateIcon } from "lucide-react";

import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
  PromptInput,
  PromptInputActions,
  PromptInputButton,
  PromptInputSubmit,
  PromptInputTextarea,
  usePromptInput,
} from "@/components/ui/prompt-input";

const templates = [
  { label: "Summarize", text: "Summarize the key points of " },
  { label: "Explain", text: "Explain how this works, step by step: " },
  { label: "Draft a reply", text: "Draft a short, friendly reply to " },
];

function TemplateMenu() {
  const { setValue } = usePromptInput();

  return (
    <DropdownMenu>
      <DropdownMenuTrigger render={<PromptInputButton aria-label="Templates" />}>
        <LayoutTemplateIcon />
      </DropdownMenuTrigger>
      <DropdownMenuContent>
        {templates.map((template) => (
          <DropdownMenuItem key={template.label} onClick={() => setValue(template.text)}>
            {template.label}
          </DropdownMenuItem>
        ))}
      </DropdownMenuContent>
    </DropdownMenu>
  );
}

export default function PromptInputTemplates() {
  return (
    <PromptInput className="max-w-md">
      <PromptInputTextarea placeholder="Ask anything…" />
      <PromptInputActions>
        <TemplateMenu />
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

### Disabled

`disabled` disables the field and every `PromptInputButton` in it, including the submit button, and
removes them from the tab order. The whole field dims once, so its controls don't dim any further.

```tsx
import {
  PromptInput,
  PromptInputAttach,
  PromptInputAttachments,
  PromptInputActions,
  PromptInputSubmit,
  PromptInputTextarea,
} from "@/components/ui/prompt-input";

export default function PromptInputDisabled() {
  return (
    <PromptInput disabled defaultValue="Summarize this week’s incidents" className="max-w-md">
      <PromptInputAttachments />
      <PromptInputTextarea />
      <PromptInputActions>
        <PromptInputAttach />
      </PromptInputActions>
      <PromptInputActions align="end">
        <PromptInputSubmit />
      </PromptInputActions>
    </PromptInput>
  );
}
```

## Props

`PromptInput` renders a `<form>`, which `render` replaces. It leaves out the form's `action`,
`method`, `encType` and `target`, since it passes the message to `onSubmit` rather than submitting
the form. Enter and the submit button send the message by submitting that form, so `render` has to
render a form too, and a Prompt Input can't sit inside another form.

| Part | Extends |
| --- | --- |
| `PromptInput` | `<form>` |
| `PromptInputAttachments` | [`FileInputList`](https://ui.jarv.is/components/file-input.md) |
| `PromptInputTextarea` | [`InputGroupTextarea`](https://ui.jarv.is/components/input-group.md) |
| `PromptInputActions` | `<div>` |
| `PromptInputButton` | [`InputGroupButton`](https://ui.jarv.is/components/input-group.md) |
| `PromptInputAttach` | `PromptInputButton` |
| `PromptInputSubmit` | `PromptInputButton` |
| `PromptInputUsage` | `<span>` |

Base UI's [styling](https://base-ui.com/react/handbook/styling) and [composition](https://base-ui.com/react/handbook/composition) guides say more about `className`, `style` and `render`.

### PromptInput

| Prop                   | Type                                                                                    | Default     | Description                                                                                                                                                                                                                                                                        |
| ---------------------- | --------------------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value?`               | `string`                                                                                | —           | The message being written, when it's controlled.                                                                                                                                                                                                                                   |
| `defaultValue?`        | `string`                                                                                | `""`        | The initial message, when `value` isn't controlled.                                                                                                                                                                                                                                |
| `onValueChange?`       | `((value: string, eventDetails: PromptInputChangeEventDetails) => void)`                | —           | Called when the message changes: as someone types, when it's sent, and when its form resets. Calling `eventDetails.cancel()` keeps the current message.                                                                                                                            |
| `onSubmit?`            | `((message: PromptInputMessage, event: React.SubmitEvent<HTMLFormElement>) => unknown)` | —           | Called with the message when it's sent by the submit button or Enter, unless it's empty or a reply is on its way. The field clears when the message is sent. Return a promise to keep the submit button pending until it settles. If the promise rejects, the message is restored. |
| `status?`              | `"error" \| "ready" \| "streaming" \| "submitted"`                                      | `"ready"`   | The reply's progress, with the same values the AI SDK and TanStack AI use: `submitted` once the message is sent, `streaming` while the reply arrives, then `ready`, or `error` if it failed. Nothing can be sent while the status is `submitted` or `streaming`.                   |
| `onStop?`              | `(() => unknown)`                                                                       | —           | Called to stop the reply. With it, the submit button becomes a stop button while the status is `submitted` or `streaming`. Return a promise to keep the stop button pending until it settles.                                                                                      |
| `disabled?`            | `boolean`                                                                               | `false`     | Whether the field and its buttons are disabled.                                                                                                                                                                                                                                    |
| `submitDisabled?`      | `boolean`                                                                               | `false`     | Whether sending is blocked while the field stays editable, such as while files upload. Enter and the submit button both respect it.                                                                                                                                                |
| `layout?`              | `"adaptive" \| "stacked"`                                                               | `"stacked"` | Where the actions sit. With `"stacked"`, they sit in a row below the message. With `"adaptive"`, they sit beside a message that fits on one line, and move below it once it wraps or has a line break.                                                                             |
| `pendingAnnouncement?` | `string`                                                                                | `"Sending"` | What screen readers announce once a message has been sending for a second. Pass an empty string to announce nothing.                                                                                                                                                               |
| `files?`               | `File[]`                                                                                | —           | The files attached to the message, when they're controlled. A `PromptInputAttachments` lets users attach them.                                                                                                                                                                     |
| `defaultFiles?`        | `File[]`                                                                                | —           | The initial attached files, when `files` isn't controlled. A form reset restores them.                                                                                                                                                                                             |
| `onFilesChange?`       | `((files: File[], eventDetails: PromptInputFilesChangeEventDetails) => void)`           | —           | Called with all the attached files after one is added or removed, and when the message is sent. Calling `eventDetails.cancel()` keeps the previous files.                                                                                                                          |
| `className?`           | `string`                                                                                | —           | CSS class applied to the element.                                                                                                                                                                                                                                                  |
| `style?`               | `React.CSSProperties`                                                                   | —           | Style applied to the element.                                                                                                                                                                                                                                                      |
| `render?`              | `ComponentRenderFn<HTMLProps, {}> \| React.ReactElement`                                | —           | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.                                                                                          |

### PromptInputAttachments

| Prop            | Type                                                          | Default                                                        | Description                                                                                                                                                                               |
| --------------- | ------------------------------------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `children?`     | `((file: File, index: number) => React.ReactNode)`            | `(file) => <FileInputItem file={file} className="max-w-60" />` | Renders each file, usually as a `FileInputItem`.                                                                                                                                          |
| `accept?`       | `string`                                                      | —                                                              | The file types to accept, as for a file input: extensions such as `.pdf`, or types such as `image/*`.                                                                                     |
| `maxFiles?`     | `number`                                                      | —                                                              | The maximum number of files a message can have. Once it's reached, `PromptInputAttach` is disabled.                                                                                       |
| `maxSize?`      | `number`                                                      | —                                                              | The maximum file size, in bytes.                                                                                                                                                          |
| `onFileReject?` | `((file: File, reason: PromptInputFileRejectReason) => void)` | —                                                              | Called for each rejected file, with the reason: its `type`, its `size`, or the file `count`.                                                                                              |
| `className?`    | `string`                                                      | —                                                              | CSS class applied to the element.                                                                                                                                                         |
| `style?`        | `React.CSSProperties`                                         | —                                                              | Style applied to the element.                                                                                                                                                             |
| `render?`       | `ComponentRenderFn<HTMLProps, {}> \| React.ReactElement`      | —                                                              | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |

### PromptInputTextarea

| Prop              | Type                                                                    | Default   | Description                                                                                                                                                                                                                                                                                                           |
| ----------------- | ----------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `submitShortcut?` | `"enter" \| "mod+enter"`                                                | `"enter"` | The keys that send the message. With `"enter"`, Enter sends and Shift+Enter starts a new line, except on a touch screen, where Enter starts a new line and the submit button sends. With `"mod+enter"`, Enter starts a new line and Command or Control+Enter sends. Neither sends while an input method is composing. |
| `className?`      | `string`                                                                | —         | CSS class applied to the element.                                                                                                                                                                                                                                                                                     |
| `style?`          | `React.CSSProperties`                                                   | —         | Style applied to the element.                                                                                                                                                                                                                                                                                         |
| `render?`         | `ComponentRenderFn<HTMLProps, FieldControlState> \| React.ReactElement` | —         | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.                                                                                                                             |

### PromptInputActions

| Prop         | Type                                                     | Default   | Description                                                                                                                                                                               |
| ------------ | -------------------------------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `align?`     | `"end" \| "start"`                                       | `"start"` | The side the actions sit on: the start or end of the row below the message, or beside a one-line message in the adaptive layout.                                                          |
| `className?` | `string`                                                 | —         | CSS class applied to the element.                                                                                                                                                         |
| `style?`     | `React.CSSProperties`                                    | —         | Style applied to the element.                                                                                                                                                             |
| `render?`    | `ComponentRenderFn<HTMLProps, {}> \| React.ReactElement` | —         | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |

### PromptInputButton

| Prop                     | Type                                                                                | Default     | Description                                                                                                                                                                               |
| ------------------------ | ----------------------------------------------------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nativeButton?`          | `boolean`                                                                           | `true`      | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).         |
| `focusableWhenDisabled?` | `boolean`                                                                           | `false`     | Whether the button should be focusable when disabled.                                                                                                                                     |
| `variant?`               | `"destructive" \| "ghost" \| "link" \| "outline" \| "primary" \| "secondary"`       | `"ghost"`   |                                                                                                                                                                                           |
| `size?`                  | `"icon-sm" \| "icon-xs" \| "sm" \| "xs"`                                            | `"icon-sm"` | The height: `xs` 20px or `sm` 24px. The `icon-` sizes are squares of the same heights.                                                                                                    |
| `type?`                  | `"button" \| "reset" \| "submit"`                                                   | `"button"`  |                                                                                                                                                                                           |
| `className?`             | `string \| ((state: ButtonState) => string \| undefined)`                           | —           | CSS class applied to the element, or a function that returns a class based on the component's state.                                                                                      |
| `style?`                 | `React.CSSProperties \| ((state: ButtonState) => React.CSSProperties \| undefined)` | —           | Style applied to the element, or a function that returns a style object based on the component's state.                                                                                   |
| `render?`                | `ComponentRenderFn<HTMLProps, ButtonState> \| React.ReactElement`                   | —           | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |

### PromptInputAttach

| Prop                     | Type                                                                                | Default     | Description                                                                                                                                                                               |
| ------------------------ | ----------------------------------------------------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nativeButton?`          | `boolean`                                                                           | `true`      | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).         |
| `focusableWhenDisabled?` | `boolean`                                                                           | `false`     | Whether the button should be focusable when disabled.                                                                                                                                     |
| `variant?`               | `"destructive" \| "ghost" \| "link" \| "outline" \| "primary" \| "secondary"`       | `"ghost"`   |                                                                                                                                                                                           |
| `size?`                  | `"icon-sm" \| "icon-xs" \| "sm" \| "xs"`                                            | `"icon-sm"` | The height: `xs` 20px or `sm` 24px. The `icon-` sizes are squares of the same heights.                                                                                                    |
| `type?`                  | `"button" \| "reset" \| "submit"`                                                   | `"button"`  |                                                                                                                                                                                           |
| `className?`             | `string \| ((state: ButtonState) => string \| undefined)`                           | —           | CSS class applied to the element, or a function that returns a class based on the component's state.                                                                                      |
| `style?`                 | `React.CSSProperties \| ((state: ButtonState) => React.CSSProperties \| undefined)` | —           | Style applied to the element, or a function that returns a style object based on the component's state.                                                                                   |
| `render?`                | `ComponentRenderFn<HTMLProps, ButtonState> \| React.ReactElement`                   | —           | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |

### PromptInputSubmit

| Prop                     | Type                                                                                | Default                                          | Description                                                                                                                                                                               |
| ------------------------ | ----------------------------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `nativeButton?`          | `boolean`                                                                           | `true`                                           | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).         |
| `focusableWhenDisabled?` | `boolean`                                                                           | `false`                                          | Whether the button should be focusable when disabled.                                                                                                                                     |
| `variant?`               | `"destructive" \| "ghost" \| "link" \| "outline" \| "primary" \| "secondary"`       | `"primary"`                                      |                                                                                                                                                                                           |
| `size?`                  | `"icon-sm" \| "icon-xs" \| "sm" \| "xs"`                                            | `"icon-sm"`                                      | The height: `xs` 20px or `sm` 24px. The `icon-` sizes are squares of the same heights.                                                                                                    |
| `pendingAnnouncement?`   | `string`                                                                            | `"Stopping"`                                     | What screen readers announce when the promise from `onStop` hasn't settled after a second. Pass an empty string to announce nothing.                                                      |
| `stopLabel?`             | `string`                                                                            | `"Stop"`                                         | The button's accessible name while it stops the reply, in place of `aria-label`.                                                                                                          |
| `stopIcon?`              | `React.ReactNode`                                                                   | `<SquareIcon className="size-3 fill-current" />` | What the button shows while it stops the reply, in place of `children`.                                                                                                                   |
| `className?`             | `string \| ((state: ButtonState) => string \| undefined)`                           | —                                                | CSS class applied to the element, or a function that returns a class based on the component's state.                                                                                      |
| `style?`                 | `React.CSSProperties \| ((state: ButtonState) => React.CSSProperties \| undefined)` | —                                                | Style applied to the element, or a function that returns a style object based on the component's state.                                                                                   |
| `render?`                | `ComponentRenderFn<HTMLProps, ButtonState> \| React.ReactElement`                   | —                                                | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |

### PromptInputUsage

| Prop         | Type                  | Default   | Description                                                                                                                                  |
| ------------ | --------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`      | `number`              | —         | How much of the context the conversation has used, such as a count of tokens.                                                                |
| `max`        | `number`              | —         | The maximum the context can hold, such as the model's context window.                                                                        |
| `label?`     | `React.ReactNode`     | —         | The tooltip's content. Without it, the tooltip shows `value` and `max` in tokens.                                                            |
| `locale?`    | `string`              | `"en-US"` | The BCP 47 locale used to format the token counts. It's fixed rather than the browser's, so the server and the browser render the same text. |
| `className?` | `string`              | —         | CSS class applied to the element.                                                                                                            |
| `style?`     | `React.CSSProperties` | —         | Style applied to the element.                                                                                                                |

### usePromptInput

`usePromptInput()` reads the `PromptInput` that your component renders in, and returns its state:

| Value       | Type                                               | Description                                                                   |
| ----------- | -------------------------------------------------- | ----------------------------------------------------------------------------- |
| `value`     | `string`                                           | The message being written.                                                    |
| `setValue`  | `(value: string) => void`                          | Replaces the message, as typing does. `onValueChange` gets the reason `none`. |
| `files`     | `File[]`                                           | The files attached to the message.                                            |
| `setFiles`  | `(files: File[]) => void`                          | Replaces the attached files. `onFilesChange` gets the reason `none`.          |
| `status`    | `"error" \| "ready" \| "streaming" \| "submitted"` | The reply's progress, as passed to `status`.                                  |
| `empty`     | `boolean`                                          | Whether the message has no text and no files.                                 |
| `canSubmit` | `boolean`                                          | Whether Enter or the submit button would send the message now.                |
| `submit`    | `() => void`                                       | Sends the message as the submit button does, if it can be sent.               |
| `disabled`  | `boolean`                                          | Whether the field and its buttons are disabled.                               |
