Skip to content

Commit

Permalink
Merge pull request #226 from CatchTheTornado/feat_224_pre_visit_inquiry
Browse files Browse the repository at this point in the history
[fix] agent finish message
  • Loading branch information
pkarw authored Dec 1, 2024
2 parents 851f379 + 062c344 commit d14e04e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export function Chat() {
<AlertDialogHeader>
<AlertDialogTitle>The agent has finished. Do you want to clear the context and start New Chat?</AlertDialogTitle>
<AlertDialogDescription>
{chatContext.agentContext?.agentFinishMessage}
{chatContext.agentFinishMessage}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
Expand Down
8 changes: 7 additions & 1 deletion src/contexts/chat-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -178,6 +179,7 @@ export const ChatContext = createContext<ChatContextType>({
sendMessages: (msg: CreateMessagesEnvelope, includeExistingMessagesAsContext: boolean = true) => {},
chatOpen: false,
agentFinishedDialogOpen: false,
agentFinishMessage: '',
setChatOpen: (value: boolean) => {},
isStreaming: false,
isCrossChecking: false,
Expand Down Expand Up @@ -226,6 +228,7 @@ export const ChatContextProvider: React.FC<PropsWithChildren> = ({ children }) =
const [agentContext, setAgentContext] = useState<AgentContext | null>(null);

const [agentFinishedDialogOpen, setAgentFinishedDialogOpen] = useState(false);
const [agentFinishMessage, setAgentFinishMessage] = useState('');


const dbContext = useContext(DatabaseContext);
Expand Down Expand Up @@ -362,6 +365,7 @@ export const ChatContextProvider: React.FC<PropsWithChildren> = ({ children }) =
const startAgent = (agentContext: AgentContext, prompt: string, initialMessages: MessageEx[] = []) => {
newChat();
setAgentContext(agentContext);
setAgentFinishMessage(agentContext.agentFinishMessage ? agentContext.agentFinishMessage : '');
sendMessages({
messages: [...initialMessages, {
role: 'user',
Expand Down Expand Up @@ -420,6 +424,7 @@ export const ChatContextProvider: React.FC<PropsWithChildren> = ({ 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();
Expand Down Expand Up @@ -657,7 +662,8 @@ export const ChatContextProvider: React.FC<PropsWithChildren> = ({ children }) =
newChat,
downloadMessage,
agentFinishedDialogOpen,
setAgentFinishedDialogOpen
setAgentFinishedDialogOpen,
agentFinishMessage
}

return (
Expand Down

0 comments on commit d14e04e

Please sign in to comment.