{
  "schemaVersion": 1,
  "target": "react",
  "name": "prompt-composer",
  "version": "0.3.0",
  "category": "agent",
  "title": "Prompt Composer",
  "description": "An agent-native prompt box with a soft border beam: Enter sends, Shift+Enter adds a line, a round Send turns into Stop during a run, and you opt into mentions, attachments, and mode, model, and permission selectors.",
  "tags": [
    "agent",
    "chat",
    "input",
    "prompt",
    "composer"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [
    {
      "name": "dropdown-menu",
      "version": "0.2.1"
    }
  ],
  "docsPath": "/components/prompt-composer",
  "props": [
    {
      "name": "onSubmit",
      "type": "(prompt: string, context: { files, mode?, model?, permission? }) => void | Promise<void>",
      "description": "Receives the trimmed prompt and the toolbar choices; the field and attachments clear when it resolves."
    },
    {
      "name": "onStop",
      "type": "() => void",
      "description": "Shown as a round Stop button while status is running."
    },
    {
      "name": "status",
      "type": "\"idle\" | \"submitting\" | \"running\"",
      "default": "\"idle\"",
      "description": "Disables sending while busy. Running brightens the beam and says \"Agent is working\"."
    },
    {
      "name": "beam",
      "type": "boolean",
      "default": "true",
      "description": "A faint multi-hue light on the border. It rests still, travels while focused or running, and stays still with reduced motion."
    },
    {
      "name": "mentions",
      "type": "boolean | { options?, onSelect? }",
      "description": "Adds an @ button. true inserts \"@\"; with options it opens a menu and inserts \"@label\" at the caret."
    },
    {
      "name": "attachments",
      "type": "boolean | { accept?, multiple?, maxFiles?, files?, defaultFiles?, onChange? }",
      "description": "Adds a file button, drag and drop, and paste, with removable chips (image thumbnails). Controlled with files and onChange."
    },
    {
      "name": "mode",
      "type": "boolean | { options?, value?, defaultValue?, onChange?, label? }",
      "description": "Adds a mode selector. true offers Agent, Ask, and Plan (defaultModes)."
    },
    {
      "name": "model",
      "type": "boolean | { options?, value?, defaultValue?, onChange?, label? }",
      "description": "Adds a model selector. true offers Auto, Fast, and Thorough (defaultModels)."
    },
    {
      "name": "permissions",
      "type": "boolean | { options?, value?, defaultValue?, onChange?, label? }",
      "description": "Adds a permission selector. true offers Ask every time, Auto-approve edits, and Full access (defaultPermissions)."
    },
    {
      "name": "placeholder / label / maxLength / defaultValue",
      "type": "string / string / number / string",
      "description": "Field text, accessible label, character limit (a counter appears near the limit), and starting text."
    }
  ],
  "accessibility": [
    "The field has an accessible label and a hint describing Enter and Shift+Enter; while running, a live region says the agent is working.",
    "Enter does not send while an input method is composing text.",
    "Icon buttons are named (Mention, Attach files, Send, Stop, Remove file name). Selectors are Base UI menus with radio items, named like \"Mode: Agent\", and work with arrow keys, Enter, and Escape.",
    "Send shows a busy state while submitting; Stop replaces it during a run.",
    "The border beam is decorative and hidden from assistive technology; with reduced motion it is a still gradient and other transitions are removed."
  ],
  "states": [
    "idle",
    "focused",
    "submitting",
    "running"
  ],
  "files": [
    {
      "path": "agent/prompt-composer.tsx",
      "content": "\"use client\";\n\nimport { Menu as BaseMenu } from \"@base-ui/react/menu\";\nimport {\n  type ClipboardEvent,\n  type DragEvent,\n  type FormEvent,\n  type KeyboardEvent,\n  type ReactNode,\n  type RefObject,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger } from \"../ui/dropdown-menu\";\n\nexport type ComposerStatus = \"idle\" | \"submitting\" | \"running\";\n\n/** One choice in a toolbar selector or the mention menu. */\nexport interface ComposerOption {\n  value: string;\n  label: string;\n  description?: string;\n  /** A 16px glyph shown in the menu and, for the selected option, on the toolbar button. */\n  icon?: ReactNode;\n}\n\n/** A toolbar selector. Pass `value` with `onChange` to control it, or `defaultValue` to let it hold its own state. */\nexport interface ComposerSelect {\n  /** The choices. Defaults to the built-in list for that selector. */\n  options?: ComposerOption[];\n  value?: string;\n  defaultValue?: string;\n  onChange?: (value: string) => void;\n  /** Names the selector for screen readers and heads its menu, e.g. \"Mode\". */\n  label?: string;\n}\n\nexport interface ComposerAttachments {\n  /** File types the picker offers, as in `<input accept>`. */\n  accept?: string;\n  multiple?: boolean;\n  maxFiles?: number;\n  /** Selected files. Pass with `onChange` to control them. */\n  files?: File[];\n  defaultFiles?: File[];\n  onChange?: (files: File[]) => void;\n}\n\nexport interface ComposerMentions {\n  /** People, files, or tools to mention. Without options the button inserts \"@\" and focuses the field. */\n  options?: ComposerOption[];\n  /** Called after a mention is inserted. */\n  onSelect?: (option: ComposerOption) => void;\n}\n\n/** Everything chosen in the toolbar, passed to `onSubmit` with the prompt. */\nexport interface ComposerSubmitContext {\n  files: File[];\n  mode?: string;\n  model?: string;\n  permission?: string;\n}\n\nexport interface PromptComposerProps {\n  /** Called with the trimmed prompt and the toolbar choices. The field and attachments clear when it resolves. */\n  onSubmit: (prompt: string, context: ComposerSubmitContext) => void | Promise<void>;\n  /** Shown as a Stop button while the agent is running. */\n  onStop?: () => void;\n  status?: ComposerStatus;\n  placeholder?: string;\n  /** Accessible label for the field. */\n  label?: string;\n  maxLength?: number;\n  defaultValue?: string;\n  className?: string;\n  /** A slow multi-hue light along the border, brighter while focused or running. Static with reduced motion. */\n  beam?: boolean;\n  /** Adds an \"@\" button. `true` inserts \"@\"; pass options for a mention menu. */\n  mentions?: boolean | ComposerMentions;\n  /** Adds a file button, drag and drop, and paste, with removable chips. */\n  attachments?: boolean | ComposerAttachments;\n  /** Adds a mode selector. `true` offers Agent, Ask, and Plan. */\n  mode?: boolean | ComposerSelect;\n  /** Adds a model selector. `true` offers Auto, Fast, and Thorough. */\n  model?: boolean | ComposerSelect;\n  /** Adds a permission selector. `true` offers Ask every time, Auto-approve edits, and Full access. */\n  permissions?: boolean | ComposerSelect;\n}\n\nconst ease = \"ease-[cubic-bezier(0.23,1,0.32,1)]\";\nconst stroke = { fill: \"none\", stroke: \"currentColor\", strokeWidth: 1.5, strokeLinecap: \"round\", strokeLinejoin: \"round\" } as const;\n\nexport const defaultModes: ComposerOption[] = [\n  {\n    value: \"agent\",\n    label: \"Agent\",\n    description: \"Plans, edits files, and runs tools\",\n    icon: (\n      <svg viewBox=\"0 0 16 16\" {...stroke}>\n        <path d=\"M5.25 10.75c-1.5 0-2.5-1.1-2.5-2.75s1-2.75 2.5-2.75c2.5 0 3 5.5 5.5 5.5 1.5 0 2.5-1.1 2.5-2.75s-1-2.75-2.5-2.75c-2.5 0-3 5.5-5.5 5.5Z\" />\n      </svg>\n    ),\n  },\n  {\n    value: \"ask\",\n    label: \"Ask\",\n    description: \"Answers questions without changing anything\",\n    icon: (\n      <svg viewBox=\"0 0 16 16\" {...stroke}>\n        <path d=\"M3 4.25c0-.83.67-1.5 1.5-1.5h7c.83 0 1.5.67 1.5 1.5v5c0 .83-.67 1.5-1.5 1.5H7.5L4.75 13v-2.25h-.25c-.83 0-1.5-.67-1.5-1.5z\" />\n      </svg>\n    ),\n  },\n  {\n    value: \"plan\",\n    label: \"Plan\",\n    description: \"Writes a plan for you to review first\",\n    icon: (\n      <svg viewBox=\"0 0 16 16\" {...stroke}>\n        <path d=\"M6.5 4.5h6.25M6.5 8h6.25M6.5 11.5h6.25M3.25 4.5h.5M3.25 8h.5M3.25 11.5h.5\" />\n      </svg>\n    ),\n  },\n];\n\nexport const defaultModels: ComposerOption[] = [\n  { value: \"auto\", label: \"Auto\", description: \"Picks a model for each task\" },\n  { value: \"fast\", label: \"Fast\", description: \"Quick answers for small edits\" },\n  { value: \"thorough\", label: \"Thorough\", description: \"Slower, for larger changes\" },\n];\n\nexport const defaultPermissions: ComposerOption[] = [\n  { value: \"ask\", label: \"Ask every time\", description: \"Approve each edit and command\" },\n  { value: \"auto-edits\", label: \"Auto-approve edits\", description: \"Edits apply; commands still ask\" },\n  { value: \"full\", label: \"Full access\", description: \"Runs edits and commands without asking\" },\n];\n\n/**\n * A prompt box for agents: Enter sends, Shift+Enter adds a line, and Stop replaces Send while a\n * run is active. Opt into mentions, attachments, and mode, model, and permission selectors.\n */\nexport function PromptComposer({\n  onSubmit,\n  onStop,\n  status = \"idle\",\n  placeholder = \"Ask the agent to do something…\",\n  label = \"Message the agent\",\n  maxLength = 4000,\n  defaultValue = \"\",\n  className,\n  beam = true,\n  mentions,\n  attachments,\n  mode,\n  model,\n  permissions,\n}: PromptComposerProps) {\n  const [value, setValue] = useState(defaultValue);\n  const [dragging, setDragging] = useState(false);\n  const id = useId();\n  const fieldRef = useRef<HTMLTextAreaElement>(null);\n  const fileRef = useRef<HTMLInputElement>(null);\n\n  const attach = attachments ? (attachments === true ? {} : attachments) : null;\n  const mention = mentions ? (mentions === true ? {} : mentions) : null;\n  const modeSelect = useSelect(mode, defaultModes, \"Mode\");\n  const modelSelect = useSelect(model, defaultModels, \"Model\");\n  const permissionSelect = useSelect(permissions, defaultPermissions, \"Permissions\");\n  const [files, setFiles] = useControllable(attach?.files, attach?.defaultFiles ?? [], attach?.onChange);\n\n  const busy = status !== \"idle\";\n  const running = status === \"running\";\n  const canSend = value.trim().length > 0 && !busy;\n  const nearLimit = value.length > maxLength * 0.9;\n\n  async function submit(event?: FormEvent) {\n    event?.preventDefault();\n    if (!canSend) return;\n    const prompt = value.trim();\n    await onSubmit(prompt, { files, mode: modeSelect?.value, model: modelSelect?.value, permission: permissionSelect?.value });\n    setValue(\"\");\n    if (attach) setFiles([]);\n  }\n\n  function onKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {\n    // Ignore Enter while an input method is composing text (e.g. Japanese, Chinese).\n    if (event.key === \"Enter\" && !event.shiftKey && !event.nativeEvent.isComposing) {\n      event.preventDefault();\n      void submit();\n    }\n  }\n\n  function addFiles(list: FileList | File[]) {\n    if (!attach) return;\n    const incoming = [...list].filter((file) => accepts(attach.accept, file));\n    if (incoming.length === 0) return;\n    const next = attach.multiple === false ? incoming.slice(0, 1) : [...files, ...incoming];\n    setFiles(attach.maxFiles ? next.slice(0, attach.maxFiles) : next);\n  }\n\n  function removeFile(index: number) {\n    setFiles(files.filter((_, i) => i !== index));\n    fieldRef.current?.focus();\n  }\n\n  function insertAtCaret(text: string) {\n    const field = fieldRef.current;\n    const start = field?.selectionStart ?? value.length;\n    const end = field?.selectionEnd ?? value.length;\n    const before = value.slice(0, start);\n    const spacer = before && !/\\s$/.test(before) ? \" \" : \"\";\n    const next = `${before}${spacer}${text}${value.slice(end)}`.slice(0, maxLength);\n    setValue(next);\n    const caret = Math.min(start + spacer.length + text.length, next.length);\n    requestAnimationFrame(() => {\n      field?.focus();\n      field?.setSelectionRange(caret, caret);\n    });\n  }\n\n  function onPaste(event: ClipboardEvent<HTMLTextAreaElement>) {\n    if (attach && event.clipboardData.files.length > 0) {\n      event.preventDefault();\n      addFiles(event.clipboardData.files);\n    }\n  }\n\n  const dragProps = attach\n    ? {\n        onDragOver: (event: DragEvent) => {\n          if (!event.dataTransfer.types.includes(\"Files\")) return;\n          event.preventDefault();\n          setDragging(true);\n        },\n        onDragLeave: (event: DragEvent) => {\n          if (!event.currentTarget.contains(event.relatedTarget as Node | null)) setDragging(false);\n        },\n        onDrop: (event: DragEvent) => {\n          event.preventDefault();\n          setDragging(false);\n          addFiles(event.dataTransfer.files);\n        },\n      }\n    : {};\n\n  const showTopRow = Boolean(mention) || files.length > 0;\n\n  return (\n    <form\n      onSubmit={submit}\n      data-status={status}\n      data-dragging={dragging || undefined}\n      {...dragProps}\n      className={[\n        \"group/composer relative isolate rounded-2xl border border-zinc-950/10 bg-white p-2 shadow-[0_1px_2px_rgb(0_0_0/0.04)]\",\n        \"transition-[border-color,box-shadow] duration-150 ease-out motion-reduce:transition-none\",\n        \"hover:border-zinc-950/15 focus-within:border-zinc-950/20\",\n        \"dark:border-white/10 dark:bg-black dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)] dark:hover:border-white/15 dark:focus-within:border-white/20\",\n        \"data-[dragging]:border-sky-500/60 dark:data-[dragging]:border-sky-400/60\",\n        beam ? \"\" : \"focus-within:shadow-[0_0_0_3px_rgb(14_165_233/0.16)] dark:focus-within:shadow-[0_0_0_3px_rgb(56_189_248/0.18)]\",\n        className,\n      ]\n        .filter(Boolean)\n        .join(\" \")}\n    >\n      {beam ? <BorderBeam /> : null}\n      <label htmlFor={id} className=\"sr-only\">\n        {label}\n      </label>\n\n      {showTopRow ? (\n        <div className=\"flex flex-wrap items-center gap-1.5 px-0.5 pt-0.5\">\n          {mention ? <MentionButton mention={mention} fieldRef={fieldRef} onInsert={insertAtCaret} disabled={busy && !running} /> : null}\n          {files.length > 0 ? (\n            <ul aria-label=\"Attachments\" className=\"contents\">\n              {files.map((file, index) => (\n                <FileChip key={`${file.name}-${file.size}-${file.lastModified}-${index}`} file={file} onRemove={() => removeFile(index)} />\n              ))}\n            </ul>\n          ) : null}\n        </div>\n      ) : null}\n\n      <textarea\n        ref={fieldRef}\n        id={id}\n        value={value}\n        onChange={(event) => setValue(event.target.value)}\n        onKeyDown={onKeyDown}\n        onPaste={onPaste}\n        placeholder={placeholder}\n        maxLength={maxLength}\n        rows={1}\n        aria-describedby={`${id}-hint`}\n        className=\"block max-h-48 min-h-12 w-full resize-none bg-transparent px-2.5 pt-2.5 pb-1 text-sm leading-relaxed text-zinc-950 [field-sizing:content] placeholder:text-zinc-500 focus:outline-none dark:text-white dark:placeholder:text-zinc-500\"\n      />\n      <p id={`${id}-hint`} className=\"sr-only\">\n        Enter to send, Shift+Enter for a new line.\n      </p>\n\n      <div className=\"flex items-end justify-between gap-2\">\n        <div className=\"flex min-w-0 flex-wrap items-center gap-1 sm:gap-1.5\">\n          {attach ? (\n            <>\n              <input\n                ref={fileRef}\n                type=\"file\"\n                hidden\n                tabIndex={-1}\n                accept={attach.accept}\n                multiple={attach.multiple !== false}\n                onChange={(event) => {\n                  if (event.target.files) addFiles(event.target.files);\n                  event.target.value = \"\";\n                }}\n              />\n              <button type=\"button\" aria-label=\"Attach files\" onClick={() => fileRef.current?.click()} className={iconButton}>\n                <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" {...stroke} className=\"size-4\">\n                  <path d=\"m13.1 7.6-4.85 4.85a3.1 3.1 0 0 1-4.4-4.4l4.95-4.95a2.05 2.05 0 0 1 2.9 2.9L6.85 10.85a1 1 0 0 1-1.42-1.42L9.9 4.96\" />\n                </svg>\n              </button>\n            </>\n          ) : null}\n          {modeSelect ? <SelectPill select={modeSelect} /> : null}\n          {modelSelect ? <SelectPill select={modelSelect} /> : null}\n          {permissionSelect ? <SelectPill select={permissionSelect} glyph={<ShieldGlyph value={permissionSelect.value} />} compact /> : null}\n        </div>\n\n        <div className=\"flex shrink-0 items-center gap-2\">\n          {nearLimit ? (\n            <span className=\"font-mono text-xs text-amber-700 tabular-nums dark:text-amber-400\">{maxLength - value.length} left</span>\n          ) : null}\n          <span role=\"status\" className=\"sr-only text-xs text-sky-700 sm:not-sr-only dark:text-sky-400\">\n            {running ? (\n              <span key=\"running\" className={`transition-opacity duration-200 ${ease} starting:opacity-0 motion-reduce:transition-none`}>\n                Agent is working\n              </span>\n            ) : null}\n          </span>\n          {running && onStop ? (\n            <button key=\"stop\" type=\"button\" aria-label=\"Stop\" onClick={onStop} className={roundButton}>\n              <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"currentColor\" className={`size-3.5 ${swap}`}>\n                <rect x=\"4\" y=\"4\" width=\"8\" height=\"8\" rx=\"1.75\" />\n              </svg>\n            </button>\n          ) : (\n            <button\n              key=\"send\"\n              type=\"submit\"\n              aria-label=\"Send\"\n              aria-busy={status === \"submitting\" || undefined}\n              disabled={!canSend && status !== \"submitting\"}\n              onClick={(event) => status === \"submitting\" && event.preventDefault()}\n              className={roundButton}\n            >\n              {status === \"submitting\" ? (\n                <svg key=\"busy\" aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" className={`size-4 motion-safe:animate-spin ${swap}`}>\n                  <circle cx=\"8\" cy=\"8\" r=\"6\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"1.5\" />\n                  <path d=\"M14 8a6 6 0 0 0-6-6\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n                </svg>\n              ) : (\n                <svg key=\"arrow\" aria-hidden=\"true\" viewBox=\"0 0 16 16\" {...stroke} strokeWidth={1.75} className={`size-4 ${swap}`}>\n                  <path d=\"M8 12.75v-9.5M3.75 7.5 8 3.25l4.25 4.25\" />\n                </svg>\n              )}\n            </button>\n          )}\n        </div>\n      </div>\n    </form>\n  );\n}\n\nconst swap = `transition-[opacity,scale] duration-200 ${ease} starting:opacity-0 motion-safe:starting:scale-75 motion-reduce:transition-none`;\n\nconst iconButton = [\n  \"inline-flex size-8 shrink-0 items-center justify-center rounded-full text-zinc-500\",\n  \"transition-[background-color,color,scale] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.94] motion-reduce:transition-none\",\n  \"hover:bg-zinc-950/[0.05] hover:text-zinc-950 dark:hover:bg-white/[0.08] dark:hover:text-white\",\n  \"data-[popup-open]:bg-zinc-950/[0.06] data-[popup-open]:text-zinc-950 dark:data-[popup-open]:bg-white/[0.09] dark:data-[popup-open]:text-white\",\n  \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500 disabled:pointer-events-none disabled:opacity-45\",\n].join(\" \");\n\nconst pill = [\n  \"inline-flex h-8 min-w-0 items-center gap-1 rounded-full border border-zinc-950/10 pr-1.5 pl-2.5 text-[13px] font-medium text-zinc-700 select-none sm:gap-1.5 sm:pr-2 sm:pl-3\",\n  \"has-[>[data-glyph]]:pl-2 sm:has-[>[data-glyph]]:pl-2.5 [&_svg]:size-4 [&_svg]:shrink-0\",\n  \"transition-[background-color,border-color,color,scale] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.97] motion-reduce:transition-none\",\n  \"hover:border-zinc-950/15 hover:bg-zinc-950/[0.04] hover:text-zinc-950\",\n  \"data-[popup-open]:border-zinc-950/15 data-[popup-open]:bg-zinc-950/[0.06] data-[popup-open]:text-zinc-950\",\n  \"dark:border-white/10 dark:text-zinc-300 dark:hover:border-white/20 dark:hover:bg-white/[0.06] dark:hover:text-white\",\n  \"dark:data-[popup-open]:border-white/20 dark:data-[popup-open]:bg-white/[0.09] dark:data-[popup-open]:text-white\",\n  \"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n].join(\" \");\n\nconst roundButton = [\n  \"relative inline-flex size-8 shrink-0 items-center justify-center rounded-full\",\n  \"bg-zinc-950 text-white shadow-[inset_0_1px_0_rgb(255_255_255/0.12),0_1px_2px_rgb(0_0_0/0.2)] hover:bg-zinc-800\",\n  \"dark:bg-white dark:text-black dark:shadow-[inset_0_-1px_0_rgb(0_0_0/0.12)] dark:hover:bg-zinc-200\",\n  \"transition-[background-color,color,scale] duration-150 ease-out active:duration-100 motion-safe:active:scale-[0.94] motion-reduce:transition-none\",\n  \"disabled:bg-zinc-950/[0.06] disabled:text-zinc-400 disabled:shadow-none dark:disabled:bg-white/[0.08] dark:disabled:text-zinc-500\",\n  \"aria-busy:cursor-progress focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500\",\n].join(\" \");\n\n/**\n * A soft light that travels along the border. A conic gradient turns behind a mask that keeps\n * only the 1px ring, so only transform animates. It rests still and faint, and moves while the\n * field has focus or the agent works. Reduced motion leaves it as a still gradient.\n */\nfunction BorderBeam() {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={[\n        \"pointer-events-none absolute -inset-px -z-10 overflow-hidden rounded-[inherit] p-px\",\n        \"[mask:linear-gradient(#000_0_0)_content-box_exclude,linear-gradient(#000_0_0)]\",\n        \"opacity-45 transition-opacity duration-300 ease-out motion-reduce:transition-none dark:opacity-55\",\n        \"group-hover/composer:opacity-70 group-focus-within/composer:opacity-100 group-data-[status=running]/composer:opacity-100\",\n      ].join(\" \")}\n    >\n      <span\n        className={[\n          \"absolute top-1/2 left-1/2 aspect-square w-[max(150%,40rem)] -translate-x-1/2 -translate-y-1/2\",\n          \"bg-[conic-gradient(from_200deg,transparent_0deg,rgb(248_113_113/0.9)_28deg,rgb(251_191_36/0.85)_62deg,transparent_104deg,transparent_180deg,rgb(167_139_250/0.9)_208deg,rgb(45_212_191/0.85)_244deg,transparent_286deg)]\",\n          \"animate-spin [animation-duration:9s] [animation-play-state:paused] motion-reduce:animate-none\",\n          \"group-focus-within/composer:[animation-play-state:running] group-data-[status=running]/composer:[animation-play-state:running]\",\n        ].join(\" \")}\n      />\n    </span>\n  );\n}\n\ntype ResolvedSelect = ComposerSelect & { options: ComposerOption[]; value: string; setValue: (value: string) => void; label: string };\n\nfunction useSelect(config: boolean | ComposerSelect | undefined, defaults: ComposerOption[], fallbackLabel: string): ResolvedSelect | null {\n  const resolved = config ? (config === true ? { options: defaults } : config) : null;\n  const options = resolved?.options ?? defaults;\n  const [value, setValue] = useControllable(resolved?.value, resolved?.defaultValue ?? options[0]?.value ?? \"\", resolved?.onChange);\n  if (!resolved || options.length === 0) return null;\n  return { ...resolved, options, value, setValue, label: resolved.label ?? fallbackLabel };\n}\n\nfunction useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (value: T) => void) {\n  const [inner, setInner] = useState(defaultValue);\n  const current = value === undefined ? inner : value;\n  function set(next: T) {\n    if (value === undefined) setInner(next);\n    onChange?.(next);\n  }\n  return [current, set] as const;\n}\n\n/** A pill that opens a menu of radio choices. Its name reads as \"Mode: Agent\". */\nfunction SelectPill({ select, glyph, compact = false }: { select: ResolvedSelect; glyph?: ReactNode; compact?: boolean }) {\n  const current = select.options.find((option) => option.value === select.value) ?? select.options[0]!;\n  const leading = glyph ?? current.icon;\n\n  return (\n    <DropdownMenu>\n      <DropdownMenuTrigger aria-label={`${select.label}: ${current.label}`} className={pill}>\n        {leading ? (\n          <span data-glyph aria-hidden=\"true\" className=\"inline-flex text-zinc-500 dark:text-zinc-400\">\n            {leading}\n          </span>\n        ) : null}\n        <span className={`truncate ${compact ? \"hidden sm:inline\" : \"\"} max-w-[10rem]`}>{current.label}</span>\n        <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" {...stroke} className=\"size-3.5! text-zinc-400 dark:text-zinc-500\">\n          <path d=\"m5 6.5 3 3 3-3\" />\n        </svg>\n      </DropdownMenuTrigger>\n      <DropdownMenuContent side=\"top\" align=\"start\" sideOffset={8} className=\"w-64\">\n        <DropdownMenuGroup>\n          <DropdownMenuLabel>{select.label}</DropdownMenuLabel>\n          <BaseMenu.RadioGroup value={select.value} onValueChange={(next: string) => select.setValue(next)}>\n            {select.options.map((option) => (\n              <BaseMenu.RadioItem\n                key={option.value}\n                value={option.value}\n                closeOnClick\n                className={[\n                  \"flex cursor-default items-start gap-2.5 rounded-md px-2 py-1.5 text-sm outline-none select-none\",\n                  \"text-zinc-700 data-[highlighted]:bg-zinc-950/[0.05] data-[highlighted]:text-zinc-950\",\n                  \"dark:text-zinc-300 dark:data-[highlighted]:bg-white/[0.08] dark:data-[highlighted]:text-white\",\n                  \"data-[disabled]:pointer-events-none data-[disabled]:opacity-45\",\n                ].join(\" \")}\n              >\n                {option.icon ? (\n                  <span aria-hidden=\"true\" className=\"mt-0.5 inline-flex text-zinc-500 [&_svg]:size-4 [&_svg]:shrink-0\">\n                    {option.icon}\n                  </span>\n                ) : null}\n                <span className=\"grid min-w-0 flex-1\">\n                  <span className=\"font-medium\">{option.label}</span>\n                  {option.description ? <span className=\"text-xs text-zinc-500\">{option.description}</span> : null}\n                </span>\n                <BaseMenu.RadioItemIndicator className=\"mt-0.5 inline-flex text-zinc-950 dark:text-white\">\n                  <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" {...stroke} className=\"size-4\">\n                    <path d=\"m3.75 8.25 2.75 2.75 5.75-6\" />\n                  </svg>\n                </BaseMenu.RadioItemIndicator>\n              </BaseMenu.RadioItem>\n            ))}\n          </BaseMenu.RadioGroup>\n        </DropdownMenuGroup>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  );\n}\n\n/** A shield: open while every action asks, half filled for edits, filled for full access. */\nfunction ShieldGlyph({ value }: { value: string }) {\n  return (\n    <svg viewBox=\"0 0 16 16\" {...stroke}>\n      <path d=\"M8 2.25 3.25 4v3.6c0 2.9 2 5 4.75 6.15 2.75-1.15 4.75-3.25 4.75-6.15V4z\" />\n      {value === \"full\" ? (\n        <path d=\"M8 4.1 4.9 5.25v2.4c0 2 1.3 3.5 3.1 4.4 1.8-.9 3.1-2.4 3.1-4.4v-2.4z\" fill=\"currentColor\" stroke=\"none\" />\n      ) : value !== \"ask\" ? (\n        <path d=\"M8 4.1v7.95c-1.8-.9-3.1-2.4-3.1-4.4v-2.4z\" fill=\"currentColor\" stroke=\"none\" />\n      ) : null}\n    </svg>\n  );\n}\n\nfunction MentionButton({\n  mention,\n  fieldRef,\n  onInsert,\n  disabled,\n}: {\n  mention: ComposerMentions;\n  fieldRef: RefObject<HTMLTextAreaElement | null>;\n  onInsert: (text: string) => void;\n  disabled: boolean;\n}) {\n  const glyph = (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" {...stroke} className=\"size-4\">\n      <circle cx=\"8\" cy=\"8\" r=\"2.5\" />\n      <path d=\"M10.5 8v.9a1.85 1.85 0 0 0 3.7 0V8A6.2 6.2 0 1 0 11.8 13\" />\n    </svg>\n  );\n  const button = `${iconButton} border border-zinc-950/10 dark:border-white/10`;\n\n  if (!mention.options || mention.options.length === 0) {\n    return (\n      <button type=\"button\" aria-label=\"Mention\" disabled={disabled} onClick={() => onInsert(\"@\")} className={button}>\n        {glyph}\n      </button>\n    );\n  }\n\n  return (\n    <DropdownMenu>\n      <DropdownMenuTrigger aria-label=\"Mention\" disabled={disabled} className={button}>\n        {glyph}\n      </DropdownMenuTrigger>\n      <DropdownMenuContent side=\"top\" align=\"start\" sideOffset={8} finalFocus={fieldRef} className=\"w-64\">\n        <DropdownMenuGroup>\n          <DropdownMenuLabel>Mention</DropdownMenuLabel>\n          {mention.options.map((option) => (\n            <DropdownMenuItem\n              key={option.value}\n              onClick={() => {\n                onInsert(`@${option.label} `);\n                mention.onSelect?.(option);\n              }}\n              className=\"h-auto min-h-8 py-1.5\"\n            >\n              {option.icon ?? null}\n              <span className=\"grid min-w-0\">\n                <span className=\"truncate\">{option.label}</span>\n                {option.description ? <span className=\"truncate text-xs text-zinc-500\">{option.description}</span> : null}\n              </span>\n            </DropdownMenuItem>\n          ))}\n        </DropdownMenuGroup>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  );\n}\n\nfunction FileChip({ file, onRemove }: { file: File; onRemove: () => void }) {\n  const [thumbnail, setThumbnail] = useState<string | null>(null);\n\n  useEffect(() => {\n    if (!file.type.startsWith(\"image/\")) return;\n    const url = URL.createObjectURL(file);\n    setThumbnail(url);\n    return () => URL.revokeObjectURL(url);\n  }, [file]);\n\n  const extension = file.name.match(/\\.([a-z0-9]{1,5})$/i)?.[1]?.toLowerCase() ?? \"\";\n\n  return (\n    <li\n      className={[\n        \"flex h-8 max-w-56 min-w-0 items-center gap-2 rounded-lg border border-zinc-950/10 pr-1 pl-1 text-xs dark:border-white/10\",\n        `transition-[opacity,scale] duration-200 ${ease} starting:opacity-0 motion-safe:starting:scale-95 motion-reduce:transition-none`,\n      ].join(\" \")}\n    >\n      {thumbnail ? (\n        <img src={thumbnail} alt=\"\" className=\"size-6 shrink-0 rounded-md object-cover\" />\n      ) : (\n        <span aria-hidden=\"true\" className=\"grid h-6 min-w-6 shrink-0 place-items-center rounded-md bg-zinc-950/[0.05] px-1 font-mono text-[9px] font-medium text-zinc-600 dark:bg-white/[0.08] dark:text-zinc-400\">\n          {extension || \"file\"}\n        </span>\n      )}\n      <span className=\"min-w-0 truncate font-medium text-zinc-700 dark:text-zinc-300\">{file.name}</span>\n      <span className=\"shrink-0 font-mono text-[11px] text-zinc-500 tabular-nums\">{formatSize(file.size)}</span>\n      <button\n        type=\"button\"\n        aria-label={`Remove ${file.name}`}\n        onClick={onRemove}\n        className={[\n          \"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-zinc-500\",\n          \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n          \"hover:bg-zinc-950/[0.05] hover:text-zinc-950 dark:hover:bg-white/[0.08] dark:hover:text-white\",\n          \"focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-sky-500\",\n        ].join(\" \")}\n      >\n        <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" {...stroke} className=\"size-3.5\">\n          <path d=\"M4.75 4.75l6.5 6.5M11.25 4.75l-6.5 6.5\" />\n        </svg>\n      </button>\n    </li>\n  );\n}\n\nfunction accepts(accept: string | undefined, file: File) {\n  if (!accept) return true;\n  return accept.split(\",\").some((rule) => {\n    const pattern = rule.trim().toLowerCase();\n    if (!pattern) return false;\n    if (pattern.startsWith(\".\")) return file.name.toLowerCase().endsWith(pattern);\n    if (pattern.endsWith(\"/*\")) return file.type.startsWith(pattern.slice(0, -1));\n    return file.type === pattern;\n  });\n}\n\nfunction formatSize(bytes: number): string {\n  if (bytes < 1024) return `${bytes} B`;\n  if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;\n  return `${(bytes / 1024 / 1024).toFixed(1)} MB`;\n}\n"
    }
  ],
  "example": {
    "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { type ComposerStatus, PromptComposer } from \"@/components/shaken/agent/prompt-composer\";\n\nexport default function PromptComposerExample() {\n  const [status, setStatus] = useState<ComposerStatus>(\"idle\");\n  const [last, setLast] = useState<string | null>(null);\n\n  async function send(prompt: string, { mode, files }: { mode?: string; files: File[] }) {\n    setStatus(\"submitting\");\n    await new Promise((resolve) => setTimeout(resolve, 500)); // your API call\n    setLast(`${prompt} (${mode}, ${files.length} files)`);\n    setStatus(\"running\");\n  }\n\n  return (\n    <div className=\"grid w-full max-w-lg gap-2\">\n      <PromptComposer\n        placeholder=\"Build anything…\"\n        onSubmit={send}\n        onStop={() => setStatus(\"idle\")}\n        status={status}\n        mentions={{ options: [{ value: \"docs\", label: \"docs\" }, { value: \"api\", label: \"api\" }] }}\n        attachments\n        mode\n        model\n      />\n      {last ? <p className=\"text-xs text-zinc-500\">Sent: {last}</p> : null}\n    </div>\n  );\n}\n"
  }
}
