@@ -6,7 +6,7 @@ import { useChat } from '@ai-sdk/react';
66import { AssistantRuntime } from '@assistant-ui/react' ;
77import { useAISDKRuntime } from '@assistant-ui/react-ai-sdk' ;
88import { toast } from '@openops/components/ui' ;
9- import { flowHelper } from '@openops/shared' ;
9+ import { flowHelper , FlowVersion } from '@openops/shared' ;
1010import { getFrontendToolDefinitions } from '@openops/ui-kit' ;
1111import { useQuery , useQueryClient } from '@tanstack/react-query' ;
1212import { DefaultChatTransport , ToolSet , UIMessage } from 'ai' ;
@@ -135,14 +135,10 @@ export const useAssistantChat = ({
135135 stepDetails &&
136136 flowId
137137 ) {
138- const stepId =
139- flowHelper . getStep ( context . flowVersion , context . selectedStep ) ?. id ??
140- context . selectedStep ;
141-
142138 return await aiChatApi . open (
143139 flowId ,
144140 getBlockName ( stepDetails ) ,
145- stepId ,
141+ getStepId ( context . flowVersion , context . selectedStep ) ,
146142 getActionName ( stepDetails ) ,
147143 ) ;
148144 }
@@ -337,7 +333,16 @@ export const useAssistantChat = ({
337333 chatMode === ChatMode . StepSettings
338334 ) {
339335 await aiChatApi . delete ( oldChatId ) ;
336+
337+ const conversation = await aiChatApi . open (
338+ context . flowVersion . flowId ,
339+ getBlockName ( stepDetails ) ,
340+ getStepId ( context . flowVersion , context . selectedStep ) ,
341+ getActionName ( stepDetails ) ,
342+ ) ;
343+
340344 chat . setMessages ( [ ] ) ;
345+ onChatIdChange ( conversation . chatId ) ;
341346 } else {
342347 onChatIdChange ( null ) ;
343348 }
@@ -351,7 +356,7 @@ export const useAssistantChat = ({
351356 `There was an error canceling the current run and invalidating queries while creating a new chat: ${ error } ` ,
352357 ) ;
353358 }
354- } , [ chatId , chat , getBuilderState , chatMode , onChatIdChange ] ) ;
359+ } , [ chatId , chat , getBuilderState , chatMode , stepDetails , onChatIdChange ] ) ;
355360
356361 return {
357362 runtime,
@@ -363,3 +368,7 @@ export const useAssistantChat = ({
363368 chatStatus : chat . status ,
364369 } ;
365370} ;
371+
372+ const getStepId = ( flowVersion : FlowVersion , selectedStep : string ) => {
373+ return flowHelper . getStep ( flowVersion , selectedStep ) ?. id ?? selectedStep ;
374+ } ;
0 commit comments