@hanzo/ui

Composer

import { Composer, ASK, GAP, MEASURE, measure, ROUND, useUpload } from '@hanzo/ui/chat'

The stacked composer

A field over a toolbar, the send control at the end of it.

Enter to send
export function Stacked() {
  const [draft, setDraft] = useState('')
  return <Composer value={draft} onChange={setDraft} onSend={() => setDraft('')} hint="Enter to send" />
}

With context pills under the frame

A coding composer.

export function Coding() {
  const [draft, setDraft] = useState('')
  const [repo, setRepo] = useState({ owner: 'hanzo-inc', name: 'cloud' })
  const [branch, setBranch] = useState('main')
  return (
    <YStack width="100%" maxW={768} pt={260}>
      <Composer
        value={draft}
        onChange={setDraft}
        onSend={() => setDraft('')}
        placeholder="Describe a task or ask a question"
        pills={
          <>
            <ChipSelect name="Environment" label="Default" onChange={() => {}} items={[{ id: 'd', label: 'Default' }]} />
            <RepoSelect value={repo} onChange={setRepo} load={async () => ({ repos: [repo] })} />
            <BranchSelect value={branch} onChange={setBranch} load={async () => ({ branches: ['main', 'dev'] })} />
          </>
        }
      />
    </YStack>
  )
}

Busy

The send mark becomes Stop while a turn is in flight.

export function Busy() {
  return <Composer value="" busy onChange={() => {}} onSend={() => {}} onStop={() => {}} />
}

Types

export interface Carried {
  id: string
  label: string
  icon?: ReactNode
  onRemove: () => void
}
export interface ComposerProps extends Stack {
  value: string
  onChange: (value: string) => void
  /** The draft is submitted. Clearing `value` is the host's job. */
  onSend: () => void
  /** Called instead of `onSend` while `busy`. Absent, busy only disables send. */
  onStop?: () => void
  /** A turn is in flight: send becomes stop. */
  busy?: boolean
  disabled?: boolean
  /** Whether send is lit. Default: the draft has words. */
  ready?: boolean
  placeholder?: string
  /** The field's accessible name, independent of the placeholder. */
  label?: string
  /** Row floor for the field. It grows with the draft from here. */
  rows?: number
  /** Ceiling for that growth, px. Past it the field scrolls. Unset, ten lines on a laptop and six on a phone. */
  maxHeight?: number
  /** The field's own props — a ref, a testid, a paste handler. */
  field?: FieldProps
  /** A word at the end of the tool row, before the controls: a status. */
  hint?: string
  /** Account usage and context, a word under the frame; null hides a host-provided control. */
  status?: ReactNode
  /** The tool row's start, after `+` and what the draft carries. */
  children?: ReactNode
  /** Above the frame, at its width: what the draft is sent with, a banner. */
  head?: ReactNode
  /** Under the frame, at the row's start, as words: where a run goes, which repository, which branch. */
  pills?: ReactNode
  /** What the draft carries, as chips after `+`. */
  carried?: readonly Carried[]
  /** The `+` menu. Absent, there is none. */
  plus?: PlusProps
  /** `/` lists these (the skills) above the frame. */
  slash?: Shelf
  /** `@` lists these (the plugins) above the frame. */
  at?: Shelf
  /** The commands ✦ and ⌘K open. */
  commands?: readonly Command[]
  /** Under the frame, at the row's start. Hidden where the person hid chips. */
  chips?: readonly Chip[]
  /** The model, drawn where the person turned the model selector on. Null where the next send names none (steering a run). */
  mind?: Mind | null
  /** The effort, one in force. Null where the next send takes none (steering a run). */
  effort?: Modes | null
  limits?: PauseSource | null
  /** A model the plan does not grant was chosen: the way to the plan that does. */
  onUpgrade?: (model: string) => void
  /** The mode, as the pill at the row's end. */
  mode?: Modes | null
  /** Dictation into the draft (@hanzo/voice `useVoice` + `useDictation`). */
  voice?: Machine
  /** The language dictation listens in, null for Auto, and how to change it. */
  language?: string | null
  onLanguage?: (id: string | null) => void
  /** A spoken conversation (@hanzo/voice `useTalk`): the row's last place while the draft is empty. */
  talk?: Machine
  /** Above the frame, nearest it: the person's suggestions, at every width. */
  starters?: ReactNode
  /** Centred just above the frame: what every message is sent under. */
  note?: ReactNode
  /** At the reading column's width (`measure`), centred: the composer under a thread, so its edges are the text's. Absent, the width of what holds it. */
  column?: boolean
  /** A conversation nothing keeps (a private chat): the frame drops its ground and its drop and keeps its edge, dashed — the one cue, so nothing above the composer has to say it. */
  forgetful?: boolean
  /** A phone: every control is 36px and every word under the frame as tall, each row evenly set. Absent, the viewport decides. */
  narrow?: boolean
  /** This surface's answer where the person left an axis on Auto. */
  defaults?: Composing
}

Exports

ComposerASKGAPMEASUREmeasureROUNDuseUploadtype Carriedtype ComposerProps