@@ -74,6 +74,10 @@ import {
7474 NEW_THREAD_ATTACHMENT_KEY ,
7575 useChatAttachments ,
7676} from '@/hooks/useChatAttachments'
77+ import {
78+ OPENUI_CHAT_ACTION_EVENT ,
79+ isOpenUIChatActionEvent ,
80+ } from '@/lib/openui-actions'
7781
7882import {
7983 Attachment ,
@@ -466,6 +470,11 @@ const ChatInput = memo(function ChatInput({
466470 // processing is complete.
467471 }
468472 }
473+ const handleSendMessageRef = useRef ( handleSendMessage )
474+
475+ useEffect ( ( ) => {
476+ handleSendMessageRef . current = handleSendMessage
477+ } )
469478
470479 useEffect ( ( ) => {
471480 const handleFocusIn = ( ) => {
@@ -1539,6 +1548,24 @@ const ChatInput = memo(function ChatInput({
15391548
15401549 const isStreaming = chatStatus === 'submitted' || chatStatus === 'streaming'
15411550
1551+ useEffect ( ( ) => {
1552+ const handleOpenUIAction = ( event : Event ) => {
1553+ if ( ! isOpenUIChatActionEvent ( event ) ) return
1554+
1555+ const nextPrompt = event . detail . prompt . trim ( )
1556+ if ( ! nextPrompt ) return
1557+
1558+ event . preventDefault ( )
1559+ handleSendMessageRef . current ( nextPrompt )
1560+ }
1561+
1562+ window . addEventListener ( OPENUI_CHAT_ACTION_EVENT , handleOpenUIAction )
1563+
1564+ return ( ) => {
1565+ window . removeEventListener ( OPENUI_CHAT_ACTION_EVENT , handleOpenUIAction )
1566+ }
1567+ } , [ ] )
1568+
15421569 return (
15431570 < div className = "relative" >
15441571 < div className = "relative" >
0 commit comments