From 062c3448887926eadb2e5f44f63ea0aef46dc054 Mon Sep 17 00:00:00 2001 From: Piotr Karwatka Date: Sun, 1 Dec 2024 18:08:23 +0100 Subject: [PATCH] [fix] agent finish message --- src/components/chat.tsx | 2 +- src/contexts/chat-context.tsx | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/chat.tsx b/src/components/chat.tsx index b22a49e..86748c6 100644 --- a/src/components/chat.tsx +++ b/src/components/chat.tsx @@ -225,7 +225,7 @@ export function Chat() { The agent has finished. Do you want to clear the context and start New Chat? - {chatContext.agentContext?.agentFinishMessage} + {chatContext.agentFinishMessage} diff --git a/src/contexts/chat-context.tsx b/src/contexts/chat-context.tsx index f0b076a..91ec857 100644 --- a/src/contexts/chat-context.tsx +++ b/src/contexts/chat-context.tsx @@ -133,6 +133,7 @@ export type ChatContextType = { sendMessages: (msg: CreateMessagesEnvelope, includeExistingMessagesAsContext?: boolean) => void; autoCheck: (messages: MessageEx[], providerName?: string, modelName?: string) => void; agentFinishedDialogOpen: boolean; + agentFinishMessage: string; chatOpen: boolean, setChatOpen: (value: boolean) => void; chatCustomPromptVisible: boolean; @@ -178,6 +179,7 @@ export const ChatContext = createContext({ sendMessages: (msg: CreateMessagesEnvelope, includeExistingMessagesAsContext: boolean = true) => {}, chatOpen: false, agentFinishedDialogOpen: false, + agentFinishMessage: '', setChatOpen: (value: boolean) => {}, isStreaming: false, isCrossChecking: false, @@ -226,6 +228,7 @@ export const ChatContextProvider: React.FC = ({ children }) = const [agentContext, setAgentContext] = useState(null); const [agentFinishedDialogOpen, setAgentFinishedDialogOpen] = useState(false); + const [agentFinishMessage, setAgentFinishMessage] = useState(''); const dbContext = useContext(DatabaseContext); @@ -362,6 +365,7 @@ export const ChatContextProvider: React.FC = ({ children }) = const startAgent = (agentContext: AgentContext, prompt: string, initialMessages: MessageEx[] = []) => { newChat(); setAgentContext(agentContext); + setAgentFinishMessage(agentContext.agentFinishMessage ? agentContext.agentFinishMessage : ''); sendMessages({ messages: [...initialMessages, { role: 'user', @@ -420,6 +424,7 @@ export const ChatContextProvider: React.FC = ({ children }) = const processMessageAction = (jsonObject: MessageAction, resultMessage: MessageEx) => { if (agentContext?.onMessageAction) agentContext.onMessageAction(jsonObject, resultMessage); if (jsonObject.type === 'agentExit') { + if (agentContext?.agentFinishMessage) setAgentFinishMessage(agentContext?.agentFinishMessage); if (agentContext?.onAgentFinished) agentContext.onAgentFinished(jsonObject, resultMessage); if (agentContext?.agentFinishDialog) setAgentFinishedDialogOpen(true); stopAgent(); @@ -657,7 +662,8 @@ export const ChatContextProvider: React.FC = ({ children }) = newChat, downloadMessage, agentFinishedDialogOpen, - setAgentFinishedDialogOpen + setAgentFinishedDialogOpen, + agentFinishMessage } return (