Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Enhance AI Chat Components with New Icons and Improved File Handling

Salman-Ahamed11ff1538604e
diff --git a/packages/app/src/react/features/ai-chat/components/common/icons.tsx b/packages/app/src/react/features/ai-chat/components/common/icons.tsx
index 16f755a5..33539d15 100644
--- a/packages/app/src/react/features/ai-chat/components/common/icons.tsx
+++ b/packages/app/src/react/features/ai-chat/components/common/icons.tsx
@@ -5,3 +5,38 @@ export const CloseIcon = ({ className }: { className?: string }) => (
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
</svg>
);
+
+export const AttachmentIcon = ({ className }: { className?: string }) => (
+ <svg
+ className={cn('w-[17px] h-4', className)}
+ viewBox="0 0 17 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ role="img"
+ aria-hidden="true"
+ >
+ <path
+ d="M16.2056 8.33749L10.9576 13.5854C8.73264 15.8096 5.12529 15.8096 2.90114 13.5854C0.676184 11.3605 0.676184 7.75312 2.90114 5.52816L6.55545 1.87466C8.03339 0.395946 10.4291 0.395946 11.907 1.87466C13.3849 3.35176 13.3849 5.74832 11.907 7.22623L8.34251 10.7907C7.59626 11.5369 6.3871 11.5369 5.64086 10.7907C4.89462 10.0444 4.89462 8.83526 5.64086 8.08902L9.00457 4.72527"
+ stroke="currentColor"
+ strokeWidth="1.24776"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </svg>
+);
+
+export const SendIcon = ({ className }: { className?: string }) => (
+ <svg
+ className={cn('size-4', className)}
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ role="img"
+ aria-hidden="true"
+ >
+ <path
+ d="M14.733 0.20215C15.0283 0.420508 15.1833 0.797956 15.1278 1.1754L13.2561 14.1521C13.2123 14.4547 13.0397 14.7199 12.7882 14.8696C12.5367 15.0193 12.2355 15.038 11.9694 14.9195L8.47174 13.3692L6.4685 15.6806C6.20822 15.9832 5.7988 16.083 5.43909 15.9333C5.07939 15.7836 4.84543 15.4124 4.84543 15.0006V12.3928C4.84543 12.268 4.8893 12.1495 4.96826 12.059L9.86963 6.35362C10.0392 6.1571 10.0334 5.85452 9.85793 5.66735C9.68246 5.48019 9.39879 5.46771 9.21455 5.64552L3.26623 11.2823L0.683947 9.90351C0.373956 9.73818 0.175094 9.40752 0.16632 9.03943C0.157547 8.67134 0.338862 8.32821 0.637156 8.14416L13.7387 0.158478C14.0516 -0.0318057 14.4376 -0.0130893 14.733 0.20215Z"
+ fill="currentColor"
+ />
+ </svg>
+);
\ No newline at end of file
diff --git a/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx b/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx
index 7591cde9..c93e1d88 100644
--- a/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx
+++ b/packages/app/src/react/features/ai-chat/components/footer/attachment-button.tsx
@@ -1,57 +1,71 @@
import { Tooltip, TooltipContent, TooltipTrigger } from '@src/react/shared/components/ui/tooltip';
-import { FC } from 'react';
+import { ChangeEvent, FC, RefObject, useCallback } from 'react';
+import { AttachmentIcon } from '@react/features/ai-chat/components/common/icons';
+import { CHAT_ACCEPTED_FILE_TYPES } from '@react/features/ai-chat/constants';
import { FILE_LIMITS } from '@react/features/ai-chat/utils/file';
-interface AttachmentButtonProps {
- onClick: () => void;
- fileAttachmentDisabled: boolean;
+interface IProps {
+ fileInputRef: RefObject<HTMLInputElement | null>;
+ onFilesAdd: (files: File[]) => void; // eslint-disable-line no-unused-vars
+ isDisabled: boolean;
isMaxFilesUploaded: boolean;
}
-export const AttachmentButton: FC<AttachmentButtonProps> = ({
- onClick,
- fileAttachmentDisabled,
- isMaxFilesUploaded,
-}) => {
+export const AttachmentButton: FC<IProps> = (props) => {
+ const { fileInputRef, onFilesAdd, isDisabled, isMaxFilesUploaded } = props;
+
+ const fileChange = useCallback(
+ (e: ChangeEvent<HTMLInputElement>) => {
+ if (!e.target.files?.length) return;
+ onFilesAdd(Array.from(e.target.files));
+ },
+ [onFilesAdd],
+ );
+
+ const handleClick = () => {
+ if (fileInputRef?.current) {
+ fileInputRef.current.value = '';
+ fileInputRef.current.click();
+ }
+ };
+
const button = (
<button
- onClick={onClick}
- disabled={fileAttachmentDisabled}
- className="text-gray-500 hover:text-gray-700 mr-2 transition-colors"
+ type="button"
+ onClick={handleClick}
+ disabled={isDisabled || isMaxFilesUploaded}
+ className="text-gray-500 hover:text-gray-700 mr-2 transition-colors disabled:text-gray-300 disabled:cursor-not-allowed"
title={!isMaxFilesUploaded ? 'Attach file' : undefined}
aria-label="Attach file"
>
- <svg
- width="17"
- height="16"
- viewBox="0 0 17 16"
- fill="none"
- xmlns="http://www.w3.org/2000/svg"
- role="img"
- aria-hidden="true"
- >
- <path
- d="M16.2056 8.33749L10.9576 13.5854C8.73264 15.8096 5.12529 15.8096 2.90114 13.5854C0.676184 11.3605 0.676184 7.75312 2.90114 5.52816L6.55545 1.87466C8.03339 0.395946 10.4291 0.395946 11.907 1.87466C13.3849 3.35176 13.3849 5.74832 11.907 7.22623L8.34251 10.7907C7.59626 11.5369 6.3871 11.5369 5.64086 10.7907C4.89462 10.0444 4.89462 8.83526 5.64086 8.08902L9.00457 4.72527"
- stroke="#424242"
- strokeWidth="1.24776"
- strokeLinecap="round"
- strokeLinejoin="round"
- />
- </svg>
+ <AttachmentIcon />
</button>
);
- return isMaxFilesUploaded ? (
- <Tooltip>
- <TooltipTrigger asChild>
- {button}
- </TooltipTrigger>
- <TooltipContent side="top">
- <p>{`You can only attach ${FILE_LIMITS.MAX_ATTACHED_FILES} files`}</p>
- </TooltipContent>
- </Tooltip>
- ) : (
- button
+ return (
+ <>
+ {/* Hidden file input for file selection */}
+ <input
+ type="file"
+ ref={fileInputRef}
+ onChange={fileChange}
+ accept={CHAT_ACCEPTED_FILE_TYPES.input}
+ className="hidden"
+ multiple
+ aria-label="File attachment input"
+ onClick={(e) => e.stopPropagation()}
+ />
+ {isMaxFilesUploaded ? (
+ <Tooltip>
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
+ <TooltipContent side="top">
+ <p>{`You can only attach ${FILE_LIMITS.MAX_ATTACHED_FILES} files`}</p>
+ </TooltipContent>
+ </Tooltip>
+ ) : (
+ button
+ )}
+ </>
);
};
diff --git a/packages/app/src/react/features/ai-chat/components/footer/error-toast.tsx b/packages/app/src/react/features/ai-chat/components/footer/error-toast.tsx
index 0cd7b161..e24b8712 100644
--- a/packages/app/src/react/features/ai-chat/components/footer/error-toast.tsx
+++ b/packages/app/src/react/features/ai-chat/components/footer/error-toast.tsx
@@ -2,12 +2,12 @@ import { FC } from 'react';
import { FaCircleExclamation } from 'react-icons/fa6';
import { CloseIcon } from '../common/icons';
-interface ErrorToastProps {
+interface IProps {
message: string;
onClose: () => void;
}
-export const ErrorToast: FC<ErrorToastProps> = ({ message, onClose }) => (
+export const ErrorToast: FC<IProps> = ({ message, onClose }) => (
<div className="bg-[#FEFBED] border border-solid border-[#FAEBA8] flex items-center justify-between w-full min-h-[42px] rounded-md p-3">
<div className="flex items-center gap-1.5">
<div className="flex-shrink-0">
diff --git a/packages/app/src/react/features/ai-chat/components/footer/input.tsx b/packages/app/src/react/features/ai-chat/components/footer/input.tsx
index 7aa83f1d..7d74eb13 100644
--- a/packages/app/src/react/features/ai-chat/components/footer/input.tsx
+++ b/packages/app/src/react/features/ai-chat/components/footer/input.tsx
@@ -1,18 +1,9 @@
-import {
- ChangeEvent,
- KeyboardEvent,
- useCallback,
- useEffect,
- useImperativeHandle,
- useRef,
- useState,
-} from 'react';
+import { ChangeEvent, KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react';
import '../../styles/index.css';
import { AttachmentButton, SendButton } from '@react/features/ai-chat/components';
-import { CHAT_ACCEPTED_FILE_TYPES } from '@react/features/ai-chat/constants';
import { useChatStores, useClipboardPaste } from '@react/features/ai-chat/hooks';
-import { createFileFromText } from '@react/features/ai-chat/utils';
+import { adjustTextareaHeight, createFileFromText } from '@react/features/ai-chat/utils';
import {
forceScrollToBottomImmediate,
scrollManager,
@@ -21,98 +12,28 @@ import { MAX_CHAT_MESSAGE_LENGTH } from '@react/shared/constants';
import { cn } from '@react/shared/utils/general';
import { FileItemPreview } from '@src/react/features/ai-chat/components/common/FileItemPreview';
-const TEXTAREA_MAX_HEIGHT = 160;
const LARGE_TEXT_THRESHOLD = 4000;
export const ChatInput = () => {
const { ref: allRefs, files: filesData, chat, agent } = useChatStores();
const [message, setMessage] = useState('');
- const inputRef = useRef<HTMLTextAreaElement>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
+ // Use inputRef from context (chatbot pattern - no useImperativeHandle needed)
+ const inputRef = allRefs?.input;
+
const { isChatCreating } = chat || {};
const { isStreaming, sendMessage, stopStreaming } = chat || {};
- const {
- attachments: files,
- status: uploadStatus,
- process: addFiles,
- remove: removeFile,
- clear: clearFiles,
- uploading,
- } = filesData || {};
+ const { attachments, status, process, remove, clear, uploading } = filesData || {};
const maxLength = MAX_CHAT_MESSAGE_LENGTH;
- const isMaxFilesUploaded = files.length >= 10;
+ const isMaxFilesUploaded = attachments.length >= 10;
const isDisabled = isChatCreating || agent.isLoading.agent;
- const handleFileChange = useCallback(
- (e: ChangeEvent<HTMLInputElement>) => {
- if (!e.target.files?.length) return;
- addFiles(Array.from(e.target.files));
- },
- [addFiles],
- );
-
- // Debounce ref for textarea height adjustment
- const heightAdjustmentTimerRef = useRef<NodeJS.Timeout | null>(null);
-
- /**
- * Adjusts textarea height based on content
- * This is an expensive operation, so we debounce it
- */
- const adjustTextareaHeight = useCallback(() => {
- const textarea = inputRef.current;
- if (!textarea) return;
-
- textarea.style.height = 'auto';
- const newHeight = Math.min(textarea.scrollHeight, TEXTAREA_MAX_HEIGHT);
- textarea.style.height = `${newHeight}px`;
- textarea.style.overflowY = newHeight === TEXTAREA_MAX_HEIGHT ? 'auto' : 'hidden';
- }, []);
-
- /**
- * Debounced version of textarea height adjustment
- * Improves typing performance by batching height calculations
- * Delay: 100ms (feels instant but reduces calculations by ~90%)
- */
- const debouncedAdjustHeight = useCallback(() => {
- // Clear existing timer
- if (heightAdjustmentTimerRef.current) {
- clearTimeout(heightAdjustmentTimerRef.current);
- }
-
- // Schedule new adjustment
- heightAdjustmentTimerRef.current = setTimeout(() => {
- adjustTextareaHeight();
- heightAdjustmentTimerRef.current = null;
- }, 100);
- }, [adjustTextareaHeight]);
-
- useImperativeHandle(
- allRefs?.input,
- () => ({
- focus: () => inputRef.current?.focus(),
- getValue: () => message,
- setValue: (content: string) => setMessage(content.slice(0, maxLength)),
- }),
- [maxLength, message],
- );
-
- /**
- * Adjust height when message changes (debounced for performance)
- * Also cleanup timer on unmount
- */
+ // Adjust textarea height when message changes (chatbot pattern)
useEffect(() => {
- debouncedAdjustHeight();
-
- // Cleanup function to clear pending timers
- return () => {
- if (heightAdjustmentTimerRef.current) {
- clearTimeout(heightAdjustmentTimerRef.current);
- heightAdjustmentTimerRef.current = null;
- }
- };
- }, [message, debouncedAdjustHeight]);
+ adjustTextareaHeight(inputRef?.current ?? null);
+ }, [message, inputRef]);
const handleChange = useCallback(
(e: ChangeEvent<HTMLTextAreaElement>) => {
@@ -126,63 +47,39 @@ export const ChatInput = () => {
if (isStreaming) return stopStreaming();
const trimmedMessage = message.trim();
- if (trimmedMessage.length > 0 || files.length > 0) {
- // sendMessage(trimmedMessage, files);
+ if (trimmedMessage.length > 0 || attachments.length > 0) {
sendMessage(trimmedMessage);
setMessage('');
- clearFiles();
+ clear();
- // Clear any pending debounced height adjustments
- if (heightAdjustmentTimerRef.current) {
- clearTimeout(heightAdjustmentTimerRef.current);
- heightAdjustmentTimerRef.current = null;
- }
-
- // Immediately adjust height after clearing message (no debounce needed)
- requestAnimationFrame(() => adjustTextareaHeight());
+ // Reset textarea height after clearing message
+ requestAnimationFrame(() => adjustTextareaHeight(inputRef?.current ?? null));
- if (fileInputRef.current) {
- fileInputRef.current.value = '';
- }
- // Professional scroll to bottom after sending message
- // Ensure scroll manager is initialized with the chat container
- let chatContainer = document.querySelector('[data-chat-container]') as HTMLElement;
+ if (fileInputRef.current) fileInputRef.current.value = '';
+ let container: HTMLElement = document.querySelector('[data-chat-container]');
+ if (!container) container = document.querySelector('.overflow-auto');
+ if (!container) container = document.querySelector('.scroll-smooth');
- // Fallback: try to find container by class
- if (!chatContainer) {
- chatContainer = document.querySelector('.overflow-auto') as HTMLElement;
- }
-
- // Fallback: try to find container by scroll-smooth class
- if (!chatContainer) {
- chatContainer = document.querySelector('.scroll-smooth') as HTMLElement;
- }
-
- if (chatContainer) {
- scrollManager.init(chatContainer);
+ if (container) {
+ scrollManager.init(container);
} else {
- // Try to use existing container if any
const existingContainer = scrollManager.getContainer();
- if (!existingContainer) {
- return; // No container available, skip scroll
- }
+ if (!existingContainer) return;
}
- // Reset cooldown to ensure user-initiated scrolls always work
scrollManager.resetForceScrollCooldown();
- // Add a small delay to ensure the message is added to DOM first
setTimeout(() => {
forceScrollToBottomImmediate({ behavior: 'smooth', delay: 0 });
- }, 150); // 150ms delay to ensure DOM is updated
+ }, 150);
}
- }, [message, files, isStreaming, isDisabled, adjustTextareaHeight]); // eslint-disable-line react-hooks/exhaustive-deps
+ }, [isStreaming, stopStreaming, message, attachments.length, sendMessage, clear, inputRef]);
const handleKeyDown = useCallback(
(e: KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
- !isStreaming && handleSubmit();
+ if (!isStreaming) handleSubmit();
}
},
[handleSubmit, isStreaming],
@@ -190,113 +87,89 @@ export const ChatInput = () => {
const handleRemoveFile = useCallback(
(index: number): void => {
- removeFile(index);
- if (fileInputRef.current) {
- fileInputRef.current.value = '';
- }
+ remove(index);
+ if (fileInputRef.current) fileInputRef.current.value = '';
},
- [removeFile],
+ [remove],
);
- const handleAttachmentClick = useCallback(() => {
- if (fileInputRef.current) {
- fileInputRef.current.value = '';
- fileInputRef.current.click();
- }
- }, []);
-
- // useClipboardPaste hook to handle paste events
- // it will handle file drops and large text paste
- // it will convert large text to file and drop it
- // it will handle file drops and large text paste
useClipboardPaste({
- onFilePaste: addFiles,
+ onFilePaste: process,
targetRef: inputRef,
largeTextThreshold: LARGE_TEXT_THRESHOLD,
- onLargeTextPaste: (text) => {
- const file = createFileFromText(text);
- addFiles([file.file]);
- },
+ onLargeTextPaste: (text) => process([createFileFromText(text).file]),
});
const isMaxLengthReached = message.length === maxLength;
- const canSubmit = !isDisabled && (message.trim().length > 0 || isStreaming || files.length > 0);
+ const canSubmit =
+ !isDisabled && (message.trim().length > 0 || isStreaming || attachments.length > 0);
- const handleContainerClick = () => inputRef.current?.focus();
+ const handleContainerClick = () => inputRef?.current?.focus();
return (
<div
- className="w-full bg-white border border-solid border-[#e5e5e5] rounded-lg py-1 mt-2.5 text-sm flex flex-col items-start justify-center cursor-text"
onClick={handleContainerClick}
+ className="w-full bg-white border border-solid border-[#e5e5e5] rounded-lg py-1 mt-2.5 text-sm flex flex-col items-start justify-center cursor-text"
>
- {files.length > 0 && (
+ {attachments.length > 0 && (
<div
- className="flex flex-nowrap gap-2 w-full h-full px-2.5 py-5 overflow-x-auto"
role="list"
aria-label="Attached files"
+ className="flex flex-nowrap gap-2 w-full h-full px-2.5 py-5 overflow-x-auto"
>
- {files.map((file, index) => (
+ {attachments.map((file, index) => (
<FileItemPreview
key={`${file.id}`}
attachment={file}
onRemove={() => handleRemoveFile(index)}
- isUploading={uploadStatus[file.name]?.status === 'uploading'}
+ isUploading={status[file.name]?.status === 'uploading'}
/>
))}
</div>
)}
<div
- className="rounded-lg py-1 px-2.5 flex items-center text-sm w-full min-h-[60px] cursor-text"
onClick={handleContainerClick}
+ className="rounded-lg py-1 px-2.5 flex items-center text-sm w-full min-h-[60px] cursor-text"
>
- <input
- type="file"
- accept={CHAT_ACCEPTED_FILE_TYPES.input}
- className="hidden"
- ref={fileInputRef}
- onChange={handleFileChange}
- multiple
- aria-label="File attachment input"
- onClick={(e) => e.stopPropagation()}
- />
<textarea
rows={1}
ref={inputRef}
value={message}
+ maxLength={maxLength}
onChange={handleChange}
onKeyDown={handleKeyDown}
- maxLength={maxLength}
- placeholder={`Message ${agent.data?.name || ''}...`}
- className="bg-white border-none outline-none ring-0 focus:outline-none focus:border-none flex-1 max-h-36 resize-none ph-no-capture text-[16px] font-[400] text-gray-900 placeholder:text-gray-500 placeholder:text-[16px] placeholder:font-[400]"
aria-label="Message input"
onClick={(e) => e.stopPropagation()}
+ placeholder={`Message ${agent.data?.name || ''}...`}
+ className="bg-white border-none outline-none ring-0 focus:outline-none focus:border-none flex-1 max-h-36 resize-none ph-no-capture text-[16px] font-[400] text-gray-900 placeholder:text-gray-500 placeholder:text-[16px] placeholder:font-[400]"
/>
<div
+ aria-live="polite"
+ onClick={(e) => e.stopPropagation()}
className={cn(
'text-xs mr-2 w-[75px] text-right flex-shrink-0',
isMaxLengthReached ? 'text-red-500' : 'text-gray-500',
)}
- aria-live="polite"
- onClick={(e) => e.stopPropagation()}
>
{message.length}/{maxLength}
</div>
<div onClick={(e) => e.stopPropagation()}>
<AttachmentButton
- onClick={handleAttachmentClick}
- fileAttachmentDisabled={isMaxFilesUploaded || isDisabled || isStreaming}
+ onFilesAdd={process}
+ fileInputRef={fileInputRef}
+ isDisabled={isDisabled || isStreaming}
isMaxFilesUploaded={isMaxFilesUploaded}
/>
</div>
<div onClick={(e) => e.stopPropagation()}>
<SendButton
+ onClick={handleSubmit}
isStreaming={isStreaming}
disabled={!canSubmit || uploading}
- onClick={handleSubmit}
/>
</div>
</div>
diff --git a/packages/app/src/react/features/ai-chat/components/footer/scroll-to-bottom-button.tsx b/packages/app/src/react/features/ai-chat/components/footer/scroll-to-bottom-button.tsx
index 5ee796ff..a2d592b9 100644
--- a/packages/app/src/react/features/ai-chat/components/footer/scroll-to-bottom-button.tsx
+++ b/packages/app/src/react/features/ai-chat/components/footer/scroll-to-bottom-button.tsx
@@ -1,9 +1,9 @@
import { ButtonHTMLAttributes, DetailedHTMLProps, FC } from 'react';
import { FaArrowDown } from 'react-icons/fa6';
-type IButtonProps = DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
+type IProps = DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;
-export const ScrollToBottomButton: FC<IButtonProps> = ({ onClick }) => (
+export const ScrollToBottomButton: FC<IProps> = ({ onClick }) => (
<div className="w-full max-w-4xl flex justify-center items-center absolute -top-5 z-10">
<button
className="bg-white border border-solid border-black border-opacity-10 text-gray-900 rounded-full p-2 shadow-lg hover:bg-gray-50 transition-colors duration-200"
diff --git a/packages/app/src/react/features/ai-chat/components/footer/send-button.tsx b/packages/app/src/react/features/ai-chat/components/footer/send-button.tsx
index 9f75f7a3..ba84b3bf 100644
--- a/packages/app/src/react/features/ai-chat/components/footer/send-button.tsx
+++ b/packages/app/src/react/features/ai-chat/components/footer/send-button.tsx
@@ -1,6 +1,7 @@
import { FC } from 'react';
import { FaStop } from 'react-icons/fa6';
+import { SendIcon } from '@react/features/ai-chat/components/common/icons';
import { Button } from '@react/shared/components/ui/newDesign/button';
import { cn } from '@src/react/shared/utils/general';
@@ -20,25 +21,6 @@ export const SendButton: FC<SendButtonProps> = ({ isStreaming, disabled, onClick
'h-[40px] w-[40px] rounded-lg px-0 py-0',
isStreaming ? 'chat-stop' : 'chat-send',
)}
- Icon={
- isStreaming ? (
- <FaStop fontSize={14} />
- ) : (
- <svg
- width="16"
- height="16"
- viewBox="0 0 16 16"
- fill="none"
- xmlns="http://www.w3.org/2000/svg"
- role="img"
- aria-hidden="true"
- >
- <path
- d="M14.733 0.20215C15.0283 0.420508 15.1833 0.797956 15.1278 1.1754L13.2561 14.1521C13.2123 14.4547 13.0397 14.7199 12.7882 14.8696C12.5367 15.0193 12.2355 15.038 11.9694 14.9195L8.47174 13.3692L6.4685 15.6806C6.20822 15.9832 5.7988 16.083 5.43909 15.9333C5.07939 15.7836 4.84543 15.4124 4.84543 15.0006V12.3928C4.84543 12.268 4.8893 12.1495 4.96826 12.059L9.86963 6.35362C10.0392 6.1571 10.0334 5.85452 9.85793 5.66735C9.68246 5.48019 9.39879 5.46771 9.21455 5.64552L3.26623 11.2823L0.683947 9.90351C0.373956 9.73818 0.175094 9.40752 0.16632 9.03943C0.157547 8.67134 0.338862 8.32821 0.637156 8.14416L13.7387 0.158478C14.0516 -0.0318057 14.4376 -0.0130893 14.733 0.20215Z"
- fill="white"
- />
- </svg>
- )
- }
+ Icon={isStreaming ? <FaStop fontSize={14} /> : <SendIcon className="text-white" />}
/>
);
diff --git a/packages/app/src/react/features/ai-chat/contexts/chat.tsx b/packages/app/src/react/features/ai-chat/contexts/chat.tsx
index 24717b47..8c887e85 100644
--- a/packages/app/src/react/features/ai-chat/contexts/chat.tsx
+++ b/packages/app/src/react/features/ai-chat/contexts/chat.tsx
@@ -1,11 +1,14 @@
/* eslint-disable no-unused-vars */
import { IFileUpload, IMessage } from '@react/features/ai-chat/types/chat';
-import { ChatInputRef } from '@react/features/ai-chat/types/chat.types';
import { AgentDetails, AgentSettings } from '@react/shared/types/agent-data.types';
-import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react';
+import { createContext, Dispatch, RefObject, SetStateAction } from 'react';
export interface IChatContext {
- ref: { input?: MutableRefObject<ChatInputRef>; container?: MutableRefObject<HTMLDivElement> };
+ /** Refs for input textarea and chat container (chatbot pattern - direct element refs) */
+ ref: {
+ input?: RefObject<HTMLTextAreaElement | null>;
+ container?: RefObject<HTMLDivElement | null>;
+ };
agent: {
data?: AgentDetails;
settings?: AgentSettings;
diff --git a/packages/app/src/react/features/ai-chat/contexts/index.tsx b/packages/app/src/react/features/ai-chat/contexts/index.tsx
index 4df27072..bd793ecf 100644
--- a/packages/app/src/react/features/ai-chat/contexts/index.tsx
+++ b/packages/app/src/react/features/ai-chat/contexts/index.tsx
@@ -6,7 +6,7 @@ import {
} from '@react/features/ai-chat/hooks';
import { useChatState } from '@react/features/ai-chat/hooks/use-chat-state';
import { useFileUpload } from '@react/features/ai-chat/hooks/use-file-upload';
-import { ChatInputRef, IChildren } from '@react/features/ai-chat/types/chat.types';
+import { IChildren } from '@react/features/ai-chat/types/chat.types';
import { useAgent } from '@react/shared/hooks/agent';
import { Observability } from '@shared/observability';
import { EVENTS } from '@shared/posthog/constants/events';
@@ -18,7 +18,8 @@ export const ChatContextProvider: FC<IChildren> = ({ children }) => {
const params = useParams<{ agentId: string }>();
const agentId = params?.agentId;
- const inputRef = useRef<ChatInputRef>(null);
+ // Direct element refs (chatbot pattern - no useImperativeHandle needed)
+ const inputRef = useRef<HTMLTextAreaElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
const navigate = useNavigate();
diff --git a/packages/app/src/react/features/ai-chat/types/chat.types.ts b/packages/app/src/react/features/ai-chat/types/chat.types.ts
index 2af19ec8..0a2bfa61 100644
--- a/packages/app/src/react/features/ai-chat/types/chat.types.ts
+++ b/packages/app/src/react/features/ai-chat/types/chat.types.ts
@@ -182,8 +182,3 @@ export interface IAPIConfig {
retry?: { attempts: number; delay: number }; // Retry configuration
}
-export interface ChatInputRef {
- focus: () => void;
- getValue: () => string;
- setValue: (content: string) => void;
-}
diff --git a/packages/app/src/react/features/ai-chat/utils/index.ts b/packages/app/src/react/features/ai-chat/utils/index.ts
index 2f4d3130..ae3ee3fb 100644
--- a/packages/app/src/react/features/ai-chat/utils/index.ts
+++ b/packages/app/src/react/features/ai-chat/utils/index.ts
@@ -1,5 +1,25 @@
import { IMessageFile } from '@react/features/ai-chat/types/chat.types';
+/** Default max height for textarea auto-resize (in pixels) */
+const DEFAULT_TEXTAREA_MAX_HEIGHT = 160;
+
+/**
+ * Adjusts textarea height based on its content
+ * @param textarea - The textarea element to adjust
+ * @param maxHeight - Maximum height in pixels (defaults to 160)
+ */
+export const adjustTextareaHeight = (
+ textarea: HTMLTextAreaElement | null,
+ maxHeight: number = DEFAULT_TEXTAREA_MAX_HEIGHT,
+): void => {
+ if (!textarea) return;
+
+ textarea.style.height = 'auto';
+ const newHeight = Math.min(textarea.scrollHeight, maxHeight);
+ textarea.style.height = `${newHeight}px`;
+ textarea.style.overflowY = newHeight === maxHeight ? 'auto' : 'hidden';
+};
+
export const createFileFromText = (content: string): IMessageFile => {
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
const name = `text-${timestamp}.txt`;