@hanzo/ui

Chat

import { Chat } from '@hanzo/ui/chat'

No examples yet.

Types

export interface Turn {
  id: string
  role: Role
  /**
   * What was said — a string, or the wire's parts.
   *
   * This was `string` alone, which is the same mistake `Role` made one field
   * over: a completion's content is `string | ContentPart[]` (text beside an
   * image), so a turn holding an attachment could not be handed to this at all.
   * Narrowing the wire in a component fed BY the wire just relocates the
   * mismatch to every caller. `words` flattens it to prose; `Parts` draws it.
   */
  content?: Said
}
export interface ChatProps extends Omit<ThreadProps, 'children' | 'ref'> {
  /** The conversation, oldest first. */
  messages: Turn[]
  /** A turn is arriving: the last one carries the caret and the composer stops. */
  streaming?: boolean
  /**
   * Send the draft. The composer clears itself once this is called.
   *
   * Named `send`, not `onSend`, and the distinction is the reason this component
   * is usable at all. A leaf control announces an event that happened TO it, so
   * `Composer` takes `onSend`. This is a container handed a whole conversation,
   * and the thing it is handed is a hook result whose actions are verbs —
   * `useChat` answers `{ messages, streaming, send, stop }`. Spelling these
   * `onSend`/`onStop` meant `<Chat {...useChat(…)} />` did not typecheck, which
   * is the ONE call this exists to make work.
   */
  send: (text: string) => void
  /** End the turn in flight. Absent, the composer offers no stop. */
  stop?: () => void
  /**
   * Render a turn's body. Defaults to `Parts` for a list and the words for a
   * string.
   *
   * A surface with a markdown pipeline passes it here — the plugin set is
   * per-surface (nine plugins, one plugin, or a regex under a bundle ceiling
   * that cannot afford a parser), so this package ships none and renders the
   * words plainly until someone says otherwise. The usual form hands the
   * pipeline to `Parts` rather than replacing it:
   * `body={(t) => <Parts parts={t.content as MessagePart[]} prose={md} />}`.
   */
  body?: (turn: Turn) => ReactNode
  /** Shown instead of the thread while nothing has been said. */
  empty?: ReactNode
  /**
   * While nothing has been said, `empty` and the composer sit together in the
   * middle of the height, the free space split evenly above and below them.
   * Once a turn exists the thread takes the height and the composer docks under
   * it.
   *
   * The space is two spacers around the pair, not margins on it. With a `head`
   * or `foot` the composer is a shell around its frame, and a margin passed in
   * `composer` lands on the frame inside that shell, where it moves nothing.
   * The spacers shrink to nothing when the pair is taller than the window, so
   * the heading is never pushed above the top.
   */
  center?: boolean
  /** The composer's own props — placeholder, hint, the send control, the field. */
  composer?: Partial<ComposerProps>
  /**
   * Route files dropped ANYWHERE in the window.
   *
   * Present, the surface lights a full-window overlay on a file drag and hands
   * the dropped files here — the same window-level drop `@hanzo/chat` runs, off
   * the one `useFileDrop` primitive, so a host gets "drop on any part of the
   * interface" without writing a listener. Absent, the window is left untouched
   * (the hook is disabled), because a drop with nowhere to go should not
   * swallow the browser's own behaviour.
   */
  onFiles?: (files: File[]) => void
}

Exports

Chattype ChatPropstype Turn