Skip to content

Commit 242bdc8

Browse files
Fix CLI new chat handling (#1591)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Fixes OPS-2979
1 parent a9df4f8 commit 242bdc8

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

packages/react-ui/src/app/features/ai/lib/assistant-ui-chat-hook.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useChat } from '@ai-sdk/react';
66
import { AssistantRuntime } from '@assistant-ui/react';
77
import { useAISDKRuntime } from '@assistant-ui/react-ai-sdk';
88
import { toast } from '@openops/components/ui';
9-
import { flowHelper } from '@openops/shared';
9+
import { flowHelper, FlowVersion } from '@openops/shared';
1010
import { getFrontendToolDefinitions } from '@openops/ui-kit';
1111
import { useQuery, useQueryClient } from '@tanstack/react-query';
1212
import { 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

Comments
 (0)