55 parseBlockFromToolMessage ,
66} from "@/components/agent-chat/chat-blocks/utils" ;
77import HomeScreen from "@/components/agent-chat/chat-screens/home-screen" ;
8- import ProjectScreen from "@/components/agent-chat/chat-screens/project-screen" ;
98import { type ChatUpload } from "@/components/agent-chat/input/chat-input-bar" ;
109import QuickPillButtons from "@/components/agent-chat/input/quick-pill-buttons" ;
1110import { AgentChatLayout } from "@/components/agent-chat/layouts/agent-chat-layouts" ;
@@ -23,7 +22,7 @@ import type {
2322import { fetchWorkflowRunStatus } from "@/lib/workflow/fetch-workflow-run-status" ;
2423import { AIMessage } from "@langchain/core/messages" ;
2524import { ViewModeEnum } from "@pulse-editor/shared-utils" ;
26- import { useContext , useEffect , useMemo , useRef , useState } from "react" ;
25+ import { useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
2726import { AgentChatPanelLayout } from "./layouts/agent-chat-panel-layout" ;
2827import RunningTasksPanel from "./panels/running-tasks-panel" ;
2928
@@ -83,7 +82,9 @@ export default function AgentChat({
8382 workflowBuilds,
8483 saveWorkflowBuild,
8584 activeInterrupt,
85+ activeQAForm,
8686 resume,
87+ resumeQAForm,
8788 } = useChatContext ( ) ;
8889
8990 const { allowed : agentChatAllowed , isLoading : isLoadingAccess } =
@@ -611,10 +612,31 @@ export default function AgentChat({
611612 const isEmptyConversation =
612613 messages . length === 0 && ! isLoading && ! isLoadingSession ;
613614
614- const emptyState = activeProject ? (
615- < ProjectScreen onSend = { handleSend } project = { activeProject } />
616- ) : (
617- < HomeScreen onSend = { handleSend } projects = { projects ?? [ ] } />
615+ const [ isOnboardingAnalyzing , setIsOnboardingAnalyzing ] = useState ( false ) ;
616+
617+ const handleOnboardingComplete = useCallback (
618+ ( analysis : import ( "@/lib/types" ) . ProjectAnalysisInfo ) => {
619+ setIsOnboardingAnalyzing ( false ) ;
620+ editorContext ?. setEditorStates ( ( prev ) => ( {
621+ ...prev ,
622+ projectsInfo : prev . projectsInfo ?. map ( ( p ) =>
623+ p . id === activeProject ?. id
624+ ? { ...p , projectAnalysis : analysis }
625+ : p ,
626+ ) ,
627+ } ) ) ;
628+ } ,
629+ [ editorContext , activeProject ?. id ] ,
630+ ) ;
631+
632+ const emptyState = (
633+ < HomeScreen
634+ onSend = { handleSend }
635+ projects = { projects ?? [ ] }
636+ activeProject = { activeProject }
637+ onOnboardingComplete = { handleOnboardingComplete }
638+ onAnalyzingChange = { setIsOnboardingAnalyzing }
639+ />
618640 ) ;
619641
620642 // Build a map of tool_call_id -> tool name from AIMessages
@@ -675,6 +697,7 @@ export default function AgentChat({
675697 const inlinedTaskIds = new Set < string > ( ) ;
676698
677699 const messageList : ChatBlockData [ ] = [ ] ;
700+ const messageSourceMap = new Map < number , typeof messages [ number ] > ( ) ;
678701 for ( let i = 0 ; i < messages . length ; i ++ ) {
679702 const msg = messages [ i ] ;
680703 const isHuman = msg . _getType ( ) === "human" ;
@@ -790,7 +813,49 @@ export default function AgentChat({
790813 isTerminatingTask : workflowTask
791814 ? terminatingTaskIds ?. has ( workflowTask . taskId )
792815 : undefined ,
816+ chosenSuggestion : msg . additional_kwargs ?. chosenSuggestion as
817+ | string
818+ | undefined ,
793819 } ) ;
820+ messageSourceMap . set ( messageList . length - 1 , msg ) ;
821+ }
822+ }
823+
824+ // Append active interrupt / QA form blocks so they render at the bottom
825+ if ( activeInterrupt ) {
826+ messageList . push ( {
827+ type : "interrupt" ,
828+ interrupt : activeInterrupt ,
829+ onReply : resume ,
830+ isLoading,
831+ } ) ;
832+ }
833+ if ( activeQAForm ) {
834+ messageList . push ( {
835+ type : "qa-form" ,
836+ form : activeQAForm ,
837+ onSubmit : resumeQAForm ,
838+ isLoading,
839+ } ) ;
840+ }
841+
842+ // Attach suggestion click handler to the last AI message only
843+ if ( ! isLoading && ! activeInterrupt && ! activeQAForm ) {
844+ for ( let i = messageList . length - 1 ; i >= 0 ; i -- ) {
845+ if ( messageList [ i ] . type === "ai-message" ) {
846+ const sourceMsg = messageSourceMap . get ( i ) ;
847+ ( messageList [ i ] as any ) . onSuggestionClick = ( text : string ) => {
848+ // Persist chosen suggestion into the AI message's additional_kwargs
849+ if ( sourceMsg ) {
850+ sourceMsg . additional_kwargs = {
851+ ...sourceMsg . additional_kwargs ,
852+ chosenSuggestion : text ,
853+ } ;
854+ }
855+ handleSend ( text ) ;
856+ } ;
857+ break ;
858+ }
794859 }
795860 }
796861
@@ -870,6 +935,7 @@ export default function AgentChat({
870935 onOpenTasks : ( ) => setIsTasksOpen ( true ) ,
871936 onNewChat : handleNewChat ,
872937 onShare : ( ) => setShareSessionId ( currentSessionIdRef . current ) ,
938+ hideInput : isEmptyConversation && isOnboardingAnalyzing ,
873939 } ;
874940
875941 if ( isPage ) {
0 commit comments