{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-input",
  "title": "Text Input",
  "description": "Message composer with inline send button that injects the message into the conversation and sends it to the bot.",
  "dependencies": [
    "@pipecat-ai/client-js@^1.14.0",
    "@pipecat-ai/client-react@^1.9.0",
    "lucide-react@^1.41.0"
  ],
  "registryDependencies": [
    "input-group"
  ],
  "files": [
    {
      "path": "src/components/text-input.tsx",
      "content": "\"use client\";\n\nimport type { SendTextOptions, TransportState } from \"@pipecat-ai/client-js\";\nimport {\n  useConversationContext,\n  usePipecatClient,\n  usePipecatClientTransportState,\n} from \"@pipecat-ai/client-react\";\nimport { Loader2Icon, SendIcon } from \"lucide-react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport {\n  InputGroup,\n  InputGroupAddon,\n  InputGroupButton,\n  InputGroupInput,\n  InputGroupTextarea,\n} from \"@/components/ui/input-group\";\n\nexport interface TextInputViewProps {\n  /** Called with the trimmed message when the user sends. */\n  onSend?: (message: string) => Promise<void> | void;\n  /** Disable the composer entirely. */\n  disabled?: boolean;\n  /** Use a textarea; Enter still sends, Shift+Enter inserts a newline. */\n  multiline?: boolean;\n  placeholder?: string;\n  /** Accessible name for the input. */\n  \"aria-label\"?: string;\n  /** Content for the send button. Defaults to a send icon. */\n  buttonContent?: React.ReactNode;\n  /** Side the send button sits on in multiline mode. */\n  buttonPosition?: \"left\" | \"right\";\n  /** Overrides merged onto the send button (variant, size, …). */\n  buttonProps?: Partial<React.ComponentProps<typeof InputGroupButton>>;\n  /** Classes for the InputGroup root. */\n  className?: string;\n}\n\n/** Enter sends unless composing with an IME. Successful sends clear the draft; failures preserve it. */\nexport function TextInputView({\n  onSend,\n  disabled = false,\n  multiline = false,\n  placeholder = \"Type message…\",\n  \"aria-label\": ariaLabel = \"Message\",\n  buttonContent,\n  buttonPosition = \"right\",\n  buttonProps,\n  className,\n}: TextInputViewProps) {\n  const [message, setMessage] = useState(\"\");\n  const [isSending, setIsSending] = useState(false);\n  const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n\n  // The input is disabled while a send is in flight, which drops focus.\n  // Restore it once the send settles (success or failure) — after the\n  // re-render that re-enables the input, hence the effect.\n  const wasSending = useRef(false);\n  useEffect(() => {\n    if (wasSending.current && !isSending) inputRef.current?.focus();\n    wasSending.current = isSending;\n  }, [isSending]);\n\n  const handleSend = useCallback(async () => {\n    const text = message.trim();\n    if (!text || isSending) return;\n    setIsSending(true);\n    try {\n      await onSend?.(text);\n      // Clear only on success so a failed send keeps the draft.\n      setMessage(\"\");\n    } catch (error) {\n      console.error(\"TextInput: send failed\", error);\n    } finally {\n      setIsSending(false);\n    }\n  }, [message, onSend, isSending]);\n\n  const handleKeyDown = (\n    e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>,\n  ) => {\n    if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n      e.preventDefault();\n      void handleSend();\n    }\n  };\n\n  const canSend = !disabled && !isSending && message.trim().length > 0;\n\n  const inputProps = {\n    placeholder,\n    \"aria-label\": ariaLabel,\n    value: message,\n    onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>\n      setMessage(e.target.value),\n    onKeyDown: handleKeyDown,\n    disabled: disabled || isSending,\n  };\n\n  return (\n    <InputGroup data-slot=\"text-input\" className={className}>\n      {multiline ? (\n        <InputGroupTextarea\n          ref={inputRef as React.Ref<HTMLTextAreaElement>}\n          {...inputProps}\n        />\n      ) : (\n        <InputGroupInput\n          ref={inputRef as React.Ref<HTMLInputElement>}\n          {...inputProps}\n        />\n      )}\n      <InputGroupAddon\n        align={multiline ? \"block-end\" : \"inline-end\"}\n        // The primitive's block-end addon is justify-start; flip it for the\n        // (default) right-hand send button.\n        className={\n          multiline && buttonPosition === \"right\" ? \"justify-end\" : undefined\n        }\n      >\n        <InputGroupButton\n          onClick={() => void handleSend()}\n          disabled={!canSend}\n          aria-label=\"Send message\"\n          aria-busy={isSending || undefined}\n          size={buttonContent ? \"xs\" : \"icon-xs\"}\n          {...buttonProps}\n        >\n          {isSending ? (\n            <Loader2Icon className=\"animate-spin\" />\n          ) : (\n            (buttonContent ?? <SendIcon />)\n          )}\n        </InputGroupButton>\n      </InputGroupAddon>\n    </InputGroup>\n  );\n}\n\nconst CONNECTED_STATES: TransportState[] = [\"connected\", \"ready\"];\n\nexport interface TextInputProps extends Omit<\n  TextInputViewProps,\n  \"onSend\" | \"disabled\"\n> {\n  /** Options forwarded to client.sendText(). */\n  sendTextOptions?: SendTextOptions;\n  /** Placeholder shown while disconnected. */\n  disconnectedPlaceholder?: string;\n  /** Skip injecting the sent message into the local conversation store. */\n  noInject?: boolean;\n  /** Called after a message is successfully sent. */\n  onSent?: (message: string) => void;\n  /** Disable the composer even while connected. */\n  disabled?: boolean;\n}\n\n/** Requires PipecatClientProvider. Adds optimistic conversation text and sends it through the client. */\nexport function TextInput({\n  sendTextOptions,\n  disconnectedPlaceholder = \"Connect to send\",\n  noInject = false,\n  onSent,\n  disabled,\n  placeholder,\n  ...props\n}: TextInputProps) {\n  const client = usePipecatClient();\n  const transportState = usePipecatClientTransportState();\n  const isConnected = CONNECTED_STATES.includes(transportState);\n  const { injectMessage } = useConversationContext();\n\n  const handleSend = useCallback(\n    async (message: string) => {\n      if (!isConnected || !client) return;\n\n      if (!noInject) {\n        injectMessage({\n          role: \"user\",\n          parts: [\n            { text: message, final: true, createdAt: new Date().toISOString() },\n          ],\n        });\n      }\n\n      await client.sendText(message, sendTextOptions);\n      onSent?.(message);\n    },\n    [isConnected, client, injectMessage, noInject, onSent, sendTextOptions],\n  );\n\n  return (\n    <TextInputView\n      onSend={handleSend}\n      disabled={disabled || !isConnected}\n      placeholder={isConnected ? placeholder : disconnectedPlaceholder}\n      {...props}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/pipecat/text-input.tsx"
    }
  ],
  "docs": "Render inside a PipecatClientProvider. Disabled until connected; Enter sends, Shift+Enter adds a newline in multiline mode.",
  "categories": [
    "voice"
  ],
  "type": "registry:component"
}