{"version":3,"file":"AIMessageComposer.mjs","names":[],"sources":["../../../../../src/plugins/AIComponents/AIMessageComposer/AIMessageComposer.tsx"],"sourcesContent":["import {\n  type ComponentPropsWithoutRef,\n  createContext,\n  type CSSProperties,\n  type ReactNode,\n  useCallback,\n  useContext,\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react';\nimport type React from 'react';\nimport { customAlphabet } from 'nanoid';\nimport clsx from 'clsx';\nimport { StateStore } from '@stream-io/state-store';\n\nimport { useComponentContextIcons } from '../../../context/useComponentContextIcons';\nimport { useTranslationContext } from '../../../context/TranslationContext';\nimport { useStateStore } from '../../../store';\nimport { useStableCallback } from '../../../utils/useStableCallback';\nimport { useStableId } from '../../../components/UtilityComponents/useStableId';\nimport { AttachmentPreview } from './AttachmentPreview';\nimport { ChatOptions as ChatOptionsBase, type ChatOptionsProps } from './ChatOptions';\nimport { useSpeechToText, type UseSpeechToTextOptions } from './hooks/useSpeechToText';\nimport { useIsomorphicLayoutEffect } from '../utils';\nimport { ThemeScopeProvider, useAIThemeScopeClassName } from '../themeScope';\nimport type {\n  AIConversationController,\n  AIConversationControllerState,\n} from '../Conversation/controller/AIConversationController';\nimport { isAIConversationAnswering } from '../Conversation/controller/types';\nimport {\n  type AIMessageComposerStore,\n  initialAIMessageComposerState as initialStoreState,\n} from './store';\n\nexport type { AIMessageComposerStore } from './store';\n\nconst nanoId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 15);\n\n// Visually hidden but still focusable: the native file input is the keyboard target and the\n// label is the pointer target.\nconst visuallyHiddenInputStyle: CSSProperties = {\n  border: 0,\n  clip: 'rect(0, 0, 0, 0)',\n  height: '1px',\n  margin: '-1px',\n  overflow: 'hidden',\n  padding: 0,\n  position: 'absolute',\n  whiteSpace: 'nowrap',\n  width: '1px',\n};\n\nconst FileInput = ({\n  className,\n  labelProps,\n  style,\n  ...restProps\n}: ComponentPropsWithoutRef<'input'> & {\n  labelProps?: ComponentPropsWithoutRef<'label'>;\n}) => {\n  const { disabled } = useIsDisabled();\n  const { t } = useTranslationContext();\n  const { IconPlus } = useComponentContextIcons();\n  return (\n    <WithStableId>\n      {({ id }) => (\n        <>\n          <input\n            aria-label={t('fileUpload.uploadButton.fileUpload.ariaLabel', 'File upload')}\n            className={clsx('str-chat__ai-message-composer__file-input', className)}\n            id={id}\n            multiple\n            style={{ ...visuallyHiddenInputStyle, ...style }}\n            type='file'\n            {...restProps}\n            disabled={disabled}\n          />\n          <label\n            className='str-chat__ai-message-composer__round-button'\n            htmlFor={id}\n            {...labelProps}\n          >\n            <IconPlus />\n          </label>\n        </>\n      )}\n    </WithStableId>\n  );\n};\n\nconst WithStableId = ({\n  children,\n}: {\n  children?: ReactNode | (({ id }: { id: string }) => ReactNode);\n}) => {\n  // SSR/hydration-safe on React 18+ (React.useId), client-only ID on React 17\n  const id = `file-input-${useStableId()}`;\n\n  return <>{typeof children === 'function' ? children({ id }) : children}</>;\n};\n\nFileInput.WithStableId = WithStableId;\n\nconst AIMessageComposerContext = createContext<StateStore<AIMessageComposerStore>>(\n  new StateStore<AIMessageComposerStore>(initialStoreState),\n);\n\nexport const useAIMessageComposerContext = () => useContext(AIMessageComposerContext);\n\n// The conversation the composer writes in, if it was given one.\nconst AIMessageComposerConversationContext = createContext<\n  AIConversationController | undefined\n>(undefined);\n\nconst statusSelector = ({ status }: AIConversationControllerState) => ({ status });\n\n// Whether the agent of the composer's conversation is answering. `false` without a conversation.\nconst useIsAnswering = (conversation: AIConversationController | undefined) => {\n  const { status } = useStateStore(conversation?.state, statusSelector) ?? {};\n  return !!status && isAIConversationAnswering(status);\n};\n\nconst isEditingSelector = (currentState: AIMessageComposerStore) => ({\n  isEditing: !!currentState.isEditing,\n});\n\nexport const useAttachments = () => {\n  const store = useAIMessageComposerContext();\n\n  const removeAttachment = useCallback(\n    (idOrFile: string | File) => {\n      store.next((currentState) => ({\n        ...currentState,\n        attachments: currentState.attachments.filter((attachment) => {\n          if (typeof idOrFile === 'string') {\n            return attachment.id !== idOrFile;\n          }\n\n          return attachment.file !== idOrFile;\n        }),\n      }));\n    },\n    [store],\n  );\n\n  const updateAttachments = useCallback(\n    (\n      idsOrAttachments: (string | AIMessageComposerStore['attachments'][number])[],\n      update: (\n        attachment: AIMessageComposerStore['attachments'][number],\n      ) => AIMessageComposerStore['attachments'][number],\n    ) => {\n      store.next((currentState) => {\n        let hasChanges = false;\n        const newAttachments = [...currentState.attachments];\n\n        for (const idOrAttachment of idsOrAttachments) {\n          const attachmentIndex =\n            typeof idOrAttachment === 'string'\n              ? currentState.attachments.findIndex((a) => a.id === idOrAttachment)\n              : currentState.attachments.indexOf(idOrAttachment);\n\n          if (attachmentIndex === -1) {\n            continue;\n          }\n\n          const currentAttachment = currentState.attachments[attachmentIndex];\n          if (!currentAttachment) continue;\n\n          const updatedAttachment = update(currentAttachment);\n\n          if (updatedAttachment !== currentAttachment) {\n            newAttachments[attachmentIndex] = updatedAttachment;\n            hasChanges = true;\n          }\n        }\n\n        if (!hasChanges) {\n          return currentState;\n        }\n\n        return {\n          ...currentState,\n          attachments: newAttachments,\n        };\n      });\n    },\n    [store],\n  );\n\n  const selector = useCallback(\n    (currentState: AIMessageComposerStore) => ({\n      attachments: currentState.attachments,\n    }),\n    [],\n  );\n\n  const { attachments } = useStateStore(store, selector);\n\n  return useMemo(\n    () => ({ attachments, removeAttachment, updateAttachments }),\n    [attachments, removeAttachment, updateAttachments],\n  );\n};\n\nexport const useText = () => {\n  const store = useAIMessageComposerContext();\n\n  const selector = useCallback(\n    (currentState: AIMessageComposerStore) => ({\n      text: currentState.text,\n    }),\n    [],\n  );\n\n  const setText = useCallback(\n    (text: string) => {\n      store.next((currentState) => {\n        if (currentState.text === text) {\n          return currentState;\n        }\n\n        return {\n          ...currentState,\n          text,\n        };\n      });\n    },\n    [store],\n  );\n\n  const { text } = useStateStore(store, selector);\n\n  return { setText, text };\n};\n\nexport const useIsDisabled = () => {\n  const store = useAIMessageComposerContext();\n  const selector = useCallback(\n    (currentState: AIMessageComposerStore) => ({\n      disabled: currentState.disabled,\n    }),\n    [],\n  );\n\n  const setDisabled = useCallback(\n    (disabled: boolean) => store.partialNext({ disabled }),\n    [store],\n  );\n\n  const { disabled } = useStateStore(store, selector);\n  return { disabled, setDisabled };\n};\n\n/**\n * How the composer arranges its parts.\n *\n * - `stacked`: one part under another, such as the text above a row of `Actions`.\n * - `inline`: the text and the controls side by side on one line, the controls at the end of\n *   it as the text grows. The attachment previews keep a full-width row above them.\n */\nexport type AIMessageComposerLayout = 'stacked' | 'inline';\n\ntype AIMessageComposerProps = ComponentPropsWithoutRef<'form'> & {\n  /**\n   * The conversation the person writes in. The composer shows its `composer` store, and\n   * submitting sends what the person wrote through it (`conversation.send`), unless `onSubmit`\n   * calls `event.preventDefault()`. Meanwhile `SubmitButton` turns into a `StopButton`, and\n   * while the person edits a message the composer says so, with a button that cancels it.\n   */\n  conversation?: AIConversationController;\n  /**\n   * How the composer arranges its parts: one under another, or the text and the controls on\n   * one line, which suits a composer whose only control is the send button.\n   *\n   * @default 'stacked'\n   */\n  layout?: AIMessageComposerLayout;\n  /**\n   * Clears the file input named `attachments` (see `nameMapping`) after each selection, so the same\n   * file can be selected again.\n   *\n   * @default true\n   */\n  resetAttachmentsOnSelect?: boolean;\n  nameMapping?: {\n    message?: string;\n    attachments?: string;\n  };\n\n  /** Disables the composer. */\n  disabled?: boolean;\n};\n\ninterface AIMessageComposer {\n  (props: AIMessageComposerProps): React.JSX.Element;\n  FileInput: typeof FileInput;\n  TextInput: typeof TextInput;\n  SpeechToTextButton: typeof SpeechToTextButton;\n  SubmitButton: typeof SubmitButton;\n  StopButton: typeof StopButton;\n  Actions: typeof Actions;\n  ModelSelect: typeof ModelSelect;\n  AttachmentPreview: typeof AttachmentPreview;\n  ChatOptions: typeof ChatOptions;\n}\n\nexport const AIMessageComposer: AIMessageComposer = ({\n  children,\n  className,\n  conversation,\n  disabled,\n  layout = 'stacked',\n  nameMapping,\n  onChange,\n  onReset,\n  onSubmit,\n  resetAttachmentsOnSelect = true,\n  ...restProps\n}) => {\n  const themeScopeClassName = useAIThemeScopeClassName();\n  const [ownStore] = useState(\n    () => new StateStore<AIMessageComposerStore>(initialStoreState),\n  );\n  const stateStore = conversation?.composer ?? ownStore;\n\n  useEffect(() => {\n    stateStore.partialNext({ disabled });\n  }, [disabled, stateStore]);\n\n  const handleChange = useStableCallback((e: React.ChangeEvent<HTMLFormElement>) => {\n    onChange?.(e);\n\n    const inputElement = e.target as unknown as HTMLInputElement;\n\n    const messageName = nameMapping?.message ?? 'message';\n    const attachmentsName = nameMapping?.attachments ?? 'attachments';\n\n    const files = inputElement.name === attachmentsName ? inputElement.files : null;\n    const text = inputElement.name === messageName ? inputElement.value : null;\n\n    stateStore.next((currentState) => {\n      const newState = { ...currentState };\n\n      if (files && files.length > 0) {\n        const newFiles = Array.from(files).map(\n          (file) =>\n            ({\n              file,\n              id: nanoId(),\n            }) satisfies AIMessageComposerStore['attachments'][number],\n        );\n\n        newState.attachments = newState.attachments.concat(newFiles);\n      }\n\n      if (text !== null) {\n        newState.text = text;\n      }\n\n      if (\n        newState.attachments !== currentState.attachments ||\n        newState.text !== currentState.text\n      ) {\n        return newState;\n      }\n\n      return currentState;\n    });\n\n    if (\n      resetAttachmentsOnSelect &&\n      inputElement.type === 'file' &&\n      inputElement.name === attachmentsName\n    ) {\n      inputElement.value = '';\n    }\n  });\n\n  const handleReset = useStableCallback((e: React.FormEvent<HTMLFormElement>) => {\n    onReset?.(e);\n    // a reset clears the draft but must not re-enable a composer disabled via props, and the\n    // chat option stays picked\n    stateStore.next((currentState) => ({\n      ...initialStoreState,\n      chatOption: currentState.chatOption,\n      disabled,\n    }));\n  });\n\n  const handleSubmit = useStableCallback((e: FormSubmitEvent) => {\n    onSubmit?.(e);\n    if (!conversation || e.defaultPrevented) return;\n    e.preventDefault();\n    // Enter while the agent answers doesn't send: the send button is a stop button meanwhile.\n    if (isAIConversationAnswering(conversation.state.getLatestValue().status)) return;\n    const { attachments, chatOption, custom, text } = stateStore.getLatestValue();\n    if (text.trim() === '' && attachments.length === 0) return;\n    conversation.send({\n      attachments: attachments.map(({ file }) => file),\n      chatOption: chatOption ?? undefined,\n      custom,\n      text,\n    });\n    stateStore.partialNext({ attachments: [], text: '' });\n  });\n\n  return (\n    <ThemeScopeProvider>\n      <AIMessageComposerContext.Provider value={stateStore}>\n        <AIMessageComposerConversationContext.Provider value={conversation}>\n          <form\n            className={clsx(\n              themeScopeClassName,\n              'str-chat__ai-message-composer__form',\n              layout === 'inline' && 'str-chat__ai-message-composer__form--inline',\n              className,\n            )}\n            onChange={handleChange}\n            onReset={handleReset}\n            onSubmit={handleSubmit}\n            {...restProps}\n          >\n            <EditingIndicator />\n            {children}\n          </form>\n        </AIMessageComposerConversationContext.Provider>\n      </AIMessageComposerContext.Provider>\n    </ThemeScopeProvider>\n  );\n};\n\ntype FormSubmitEvent = Parameters<\n  NonNullable<ComponentPropsWithoutRef<'form'>['onSubmit']>\n>[0];\n\nconst noop = () => undefined;\n\n/**\n * Says the person is editing a message they sent, with a button that cancels it, while the\n * composer's store says they are (`isEditing`).\n */\nconst EditingIndicator = () => {\n  const store = useAIMessageComposerContext();\n  const conversation = useContext(AIMessageComposerConversationContext);\n  const { isEditing } = useStateStore(store, isEditingSelector);\n  const { t } = useTranslationContext();\n  const { IconEdit, IconXmarkSmall } = useComponentContextIcons();\n  if (!isEditing) return null;\n  const cancel = () => {\n    conversation?.cancelEditing();\n    if (store.getLatestValue().isEditing)\n      store.partialNext({ isEditing: false, text: '' });\n  };\n  return (\n    <div className='str-chat__ai-message-composer__editing'>\n      <span className='str-chat__ai-chat-options__chip'>\n        <span className='str-chat__ai-chat-options__chip-icon'>\n          <IconEdit />\n        </span>\n        <span className='str-chat__ai-chat-options__chip-title'>\n          {t('aiComponents.messageComposer.editing.text', 'Editing')}\n        </span>\n        <button\n          aria-label={t(\n            'aiComponents.messageComposer.cancelEditing.ariaLabel',\n            'Cancel editing',\n          )}\n          className='str-chat__ai-chat-options__chip-remove'\n          onClick={cancel}\n          type='button'\n        >\n          <IconXmarkSmall />\n        </button>\n      </span>\n    </div>\n  );\n};\n\nconst useHasMounted = () => {\n  const [hasMounted, setHasMounted] = useState(false);\n  useEffect(() => setHasMounted(true), []);\n  return hasMounted;\n};\n\n/** The tallest the text input grows to, in pixels, before it scrolls. */\nconst TEXT_INPUT_MAX_HEIGHT = 200;\n\n/** Makes a text input as tall as its lines, measured from one line so it shrinks again too. */\nconst fitToLines = (element: HTMLTextAreaElement) => {\n  element.style.height = 'auto';\n  element.style.height = `${Math.min(element.scrollHeight, TEXT_INPUT_MAX_HEIGHT)}px`;\n};\n\n/**\n * Where the message is written. It takes several lines and grows with them, up to a limit:\n * Enter sends, Shift+Enter starts a new line, and Enter while an input method is still composing\n * a character does neither.\n */\nconst TextInput = ({ onKeyDown, ...props }: ComponentPropsWithoutRef<'textarea'>) => {\n  const { text } = useText();\n  const { disabled } = useIsDisabled();\n  const { t } = useTranslationContext();\n  const ref = useRef<HTMLTextAreaElement>(null);\n  const { isEditing } = useStateStore(useAIMessageComposerContext(), isEditingSelector);\n\n  // Editing a message puts its text here: the person goes on writing at its end.\n  useEffect(() => {\n    const element = ref.current;\n    if (!isEditing || !element) return;\n    element.focus();\n    element.setSelectionRange(element.value.length, element.value.length);\n  }, [isEditing]);\n\n  // Sized to its lines: each time the text changes, and each time its width does, which wraps\n  // them differently (a resized window, or a composer first laid out while hidden).\n  useIsomorphicLayoutEffect(() => {\n    const element = ref.current;\n    if (element) fitToLines(element);\n  }, [text]);\n\n  useEffect(() => {\n    const element = ref.current;\n    if (!element || typeof ResizeObserver === 'undefined') return;\n    let width = element.clientWidth;\n    const observer = new ResizeObserver(() => {\n      if (element.clientWidth === width) return;\n      width = element.clientWidth;\n      fitToLines(element);\n    });\n    observer.observe(element);\n    return () => observer.disconnect();\n  }, []);\n\n  const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n    onKeyDown?.(event);\n    if (\n      event.defaultPrevented ||\n      event.key !== 'Enter' ||\n      event.shiftKey ||\n      event.nativeEvent.isComposing\n    ) {\n      return;\n    }\n    event.preventDefault();\n    event.currentTarget.form?.requestSubmit();\n  };\n\n  return (\n    <textarea\n      autoComplete='off'\n      className='str-chat__ai-message-composer__text-input'\n      name='message'\n      // A controlled input needs an onChange (`defaultValue` stops working once the input is\n      // dirty); changes are handled at the form level.\n      onChange={noop}\n      placeholder={t(\n        'aiComponents.messageComposer.textInput.placeholder',\n        'Ask a question...',\n      )}\n      ref={ref}\n      rows={1}\n      value={text}\n      {...props}\n      disabled={disabled}\n      onKeyDown={handleKeyDown}\n    />\n  );\n};\n\nconst SpeechToTextButton = ({\n  options,\n  ...restProps\n}: ComponentPropsWithoutRef<'button'> & {\n  options?: UseSpeechToTextOptions;\n}) => {\n  const { setText } = useText();\n  const { disabled } = useIsDisabled();\n  const { t } = useTranslationContext();\n  const { IconMicrophoneSolid } = useComponentContextIcons();\n  const hasMounted = useHasMounted();\n\n  // stable identities: the recognizer is only re-created when a primitive option changes\n  const onTranscript = useStableCallback((text: string) => {\n    setText(text);\n    options?.onTranscript?.(text);\n  });\n  const onError = useStableCallback((error: string) => {\n    if (options?.onError) {\n      options.onError(error);\n    } else {\n      console.error(error);\n    }\n  });\n\n  const { isListening, isSupported, startListening, stopListening } = useSpeechToText({\n    ...options,\n    onError,\n    onTranscript,\n  });\n\n  // Render nothing without the Web Speech API. Support is only known in the\n  // browser, so wait for mount to keep the server and hydration markup equal.\n  if (!hasMounted || !isSupported) return null;\n\n  return (\n    <button\n      aria-label={t(\n        'aiComponents.messageComposer.speechToText.ariaLabel',\n        'Start voice input',\n      )}\n      aria-pressed={isListening}\n      className='str-chat__ai-message-composer__round-button'\n      onClick={() => {\n        if (isListening) {\n          stopListening();\n        } else {\n          startListening();\n        }\n      }}\n      type='button'\n      {...restProps}\n      disabled={disabled}\n    >\n      <IconMicrophoneSolid />\n    </button>\n  );\n};\n\n/**\n * Sends the message. In a composer with a `conversation`, a `StopButton` takes its place while\n * the agent answers.\n */\nconst SubmitButton = ({\n  active,\n  ...restProps\n}: ComponentPropsWithoutRef<'button'> & { active?: boolean }) => {\n  const { disabled } = useIsDisabled();\n  const { t } = useTranslationContext();\n  const { IconSend } = useComponentContextIcons();\n  const conversation = useContext(AIMessageComposerConversationContext);\n  const isAnswering = useIsAnswering(conversation);\n  if (isAnswering) return <StopButton />;\n  return (\n    <button\n      aria-label={t('messageComposer.sendButton.send.ariaLabel', 'Send')}\n      className={clsx(\n        'str-chat__ai-message-composer__round-button',\n        active && 'str-chat__ai-message-composer__round-button--active',\n      )}\n      type='submit'\n      {...restProps}\n      disabled={disabled}\n    >\n      <IconSend />\n    </button>\n  );\n};\n\n/**\n * Stops a reply the agent is still writing: shown in place of the `SubmitButton` while one is.\n * Unlike the composer's other controls it does not follow the composer's `disabled`, since a\n * composer is often disabled exactly while a reply is being written, which is when it is needed.\n * In a composer with a `conversation` it stops the conversation's reply, unless `onClick` calls\n * `event.preventDefault()`.\n */\nconst StopButton = ({\n  children,\n  onClick,\n  ...restProps\n}: ComponentPropsWithoutRef<'button'>) => {\n  const { t } = useTranslationContext();\n  const { IconStopFill } = useComponentContextIcons();\n  const conversation = useContext(AIMessageComposerConversationContext);\n  const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\n    onClick?.(event);\n    if (!event.defaultPrevented) conversation?.stop();\n  };\n  return (\n    <button\n      aria-label={t(\n        'messageComposer.stopAiGeneration.stopAiGeneration.ariaLabel',\n        'Stop AI Generation',\n      )}\n      className='str-chat__ai-message-composer__round-button str-chat__ai-message-composer__round-button--stop'\n      type='button'\n      {...restProps}\n      onClick={handleClick}\n    >\n      {children ?? <IconStopFill />}\n    </button>\n  );\n};\n\n/**\n * A row for the composer's controls, such as the file picker, dictation and the send button,\n * lined up at its end. In the `stacked` layout it goes under the text.\n */\nconst Actions = ({ className, ...restProps }: ComponentPropsWithoutRef<'div'>) => (\n  <div\n    className={clsx('str-chat__ai-message-composer__actions', className)}\n    {...restProps}\n  />\n);\n\nconst chatOptionSelector = (currentState: AIMessageComposerStore) => ({\n  chatOption: currentState.chatOption,\n});\n\n// Follows the composer's disabled state unless told otherwise, and keeps the picked option in\n// the composer's store (`chatOption`), where a conversation finds it when the message is sent.\nconst ChatOptions = ({\n  defaultSelectedId,\n  onSelectedChange,\n  options,\n  selectedId,\n  ...props\n}: ChatOptionsProps) => {\n  const store = useAIMessageComposerContext();\n  const { disabled } = useIsDisabled();\n  const { chatOption } = useStateStore(store, chatOptionSelector);\n  // Picked before anything is: the default, or the controlled option, which the store takes.\n  const isControlled = selectedId !== undefined;\n  const seededId = isControlled ? selectedId : (defaultSelectedId ?? null);\n  const shownId =\n    isControlled || chatOption === undefined ? seededId : (chatOption?.id ?? null);\n  useIsomorphicLayoutEffect(() => {\n    const current = store.getLatestValue().chatOption;\n    if (!isControlled && current !== undefined) return;\n    const option = options.find((item) => item.id === seededId) ?? null;\n    // By id: an app's options can be new objects on every render.\n    if (current === undefined || (current?.id ?? null) !== (option?.id ?? null)) {\n      store.partialNext({ chatOption: option });\n    }\n  }, [isControlled, options, seededId, store]);\n\n  return (\n    <ChatOptionsBase\n      {...props}\n      disabled={props.disabled ?? disabled}\n      onSelectedChange={(option) => {\n        if (!isControlled) store.partialNext({ chatOption: option });\n        onSelectedChange?.(option);\n      }}\n      options={options}\n      selectedId={isControlled ? selectedId : shownId}\n    />\n  );\n};\n\nconst availableModels = [\n  { label: 'GPT-4o mini', platform: 'openai', value: 'gpt-4o-mini' },\n  { label: 'GPT-4o', platform: 'openai', value: 'gpt-4o' },\n] as const;\n\nconst [defaultModel] = availableModels;\n\nconst defaultPlatformModel = `${defaultModel.platform}|${defaultModel.value}`;\n\nconst ModelSelect = (\n  props: ComponentPropsWithoutRef<'select'> & { options?: ReactNode },\n) => {\n  const {\n    options = (\n      <>\n        {availableModels.map((model) => (\n          <option key={model.value} value={`${model.platform}|${model.value}`}>\n            {model.label}\n          </option>\n        ))}\n      </>\n    ),\n    ...restProps\n  } = props;\n\n  const { disabled } = useIsDisabled();\n  return (\n    <select\n      className='str-chat__ai-message-composer__select'\n      defaultValue={defaultPlatformModel}\n      {...restProps}\n      disabled={disabled}\n    >\n      {options}\n    </select>\n  );\n};\n\nAIMessageComposer.FileInput = FileInput;\nAIMessageComposer.TextInput = TextInput;\nAIMessageComposer.SpeechToTextButton = SpeechToTextButton;\nAIMessageComposer.SubmitButton = SubmitButton;\nAIMessageComposer.StopButton = StopButton;\nAIMessageComposer.Actions = Actions;\nAIMessageComposer.ModelSelect = ModelSelect;\nAIMessageComposer.AttachmentPreview = AttachmentPreview;\nAIMessageComposer.ChatOptions = ChatOptions;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,IAAM,SAAS,eAAe,wCAAwC,EAAE;AAIxE,IAAM,2BAA0C;CAC9C,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,SAAS;CACT,UAAU;CACV,YAAY;CACZ,OAAO;AACT;AAEA,IAAM,aAAa,EACjB,WACA,YACA,OACA,GAAG,gBAGC;CACJ,MAAM,EAAE,aAAa,cAAc;CACnC,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,aAAa,yBAAyB;CAC9C,OACE,oBAAC,cAAD,EAAA,WACI,EAAE,SACF,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,SAAD;EACE,cAAY,EAAE,gDAAgD,aAAa;EAC3E,WAAW,KAAK,6CAA6C,SAAS;EAClE;EACJ,UAAA;EACA,OAAO;GAAE,GAAG;GAA0B,GAAG;EAAM;EAC/C,MAAK;EACL,GAAI;EACM;CACX,CAAA,GACD,oBAAC,SAAD;EACE,WAAU;EACV,SAAS;EACT,GAAI;YAEJ,oBAAC,UAAD,CAAW,CAAA;CACN,CAAA,CACP,EAAA,CAAA,EAEQ,CAAA;AAElB;AAEA,IAAM,gBAAgB,EACpB,eAGI;CAEJ,MAAM,KAAK,cAAc,YAAY;CAErC,OAAO,oB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