Skip to content

Commit 946b6ad

Browse files
authored
feat: add initialInput prop to AIChatContainer (#278)
1 parent 0b6c622 commit 946b6ad

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/components/AIChat/AIChatContainer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface AIChatContainerProps
2525
components?: Partial<AIChatComponents>
2626
toolCallApproval?: ToolCallApprovalProps
2727
children?: ReactNode
28+
initialInput?: string
2829
}
2930

3031
interface AIChatComponents {
@@ -41,6 +42,7 @@ export function AIChatContainer({
4142
components,
4243
toolCallApproval,
4344
children,
45+
initialInput,
4446
}: AIChatContainerProps) {
4547
return (
4648
<AIChatContext.Provider
@@ -52,6 +54,7 @@ export function AIChatContainer({
5254
onModelChange: modelSelector?.onModelChange,
5355
availableModels: modelSelector?.availableModels,
5456
toolCallApproval,
57+
initialInput,
5558
}}
5659
>
5760
<div className={cn('flex h-full min-h-0 max-w-3xl flex-col', className)}>

src/components/AIChat/AIChatMessageComposer.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ export function AIChatMessageComposer({
7272
className,
7373
components,
7474
}: AIChatMessageComposerProps) {
75-
const [message, setMessage] = useState('')
75+
const {
76+
onSendMessage,
77+
isLoading,
78+
model,
79+
onModelChange,
80+
availableModels,
81+
initialInput,
82+
} = useAIChat()
83+
const [message, setMessage] = useState(initialInput || '')
7684
const [isFocused, setIsFocused] = useState(false)
77-
const { onSendMessage, isLoading, model, onModelChange, availableModels } =
78-
useAIChat()
7985
const textareaRef = useRef<HTMLTextAreaElement>(null)
8086

8187
const adjustHeight = () => {
@@ -90,6 +96,13 @@ export function AIChatMessageComposer({
9096
adjustHeight()
9197
}, [message])
9298

99+
// Set initial input only once when component mounts with an initialInput
100+
useEffect(() => {
101+
if (initialInput) {
102+
setMessage(initialInput)
103+
}
104+
}, [])
105+
93106
const handleSubmit = (e?: React.FormEvent) => {
94107
e?.preventDefault()
95108
if (message.trim() && onSendMessage && !isLoading) {

src/components/AIChat/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface AIChatContextValue {
7878
onModelChange?: (model: string) => void
7979
availableModels?: { label: string; value: string }[]
8080
toolCallApproval?: ToolCallApprovalProps
81+
initialInput?: string
8182
}
8283

8384
export interface BasePartProps {

0 commit comments

Comments
 (0)