From ecbadfb66e16e2b3fdb18383cd08c4840a40fbe8 Mon Sep 17 00:00:00 2001 From: Nico Arqueros <1622112+nicarq@users.noreply.github.com> Date: Sat, 27 Jul 2024 15:10:56 -0500 Subject: [PATCH] keep workflow activated. helpful to keep the custom system prompt alive --- .gitignore | 1 + .../src/pages/chat/chat-conversation.tsx | 36 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a4b46e383..9a1ebd6bd 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ apps/shinkai-desktop/src-tauri/node_storage apps/shinkai-desktop/src-tauri/bin/ollama-windows-resources/* apps/shinkai-desktop/src-tauri/bin/* +launch.json diff --git a/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx b/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx index 28398434d..a0aec5271 100644 --- a/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx +++ b/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx @@ -280,6 +280,23 @@ const ChatConversation = () => { }, ); + const [firstMessageWorkflow, setFirstMessageWorkflow] = useState<{ + name: string; + version: string; + } | null>(null); + + useEffect(() => { + console.log('data: ', data); + if (data?.pages && data.pages.length > 0 && data.pages[0].length > 0) { + const firstMessage = data.pages[0][0]; + console.log('firstMessage: ', firstMessage); + if (firstMessage.workflowName) { + const [name, version] = firstMessage.workflowName.split(':::'); + setFirstMessageWorkflow({ name, version }); + } + } + }, [data?.pages]); + const isLoadingMessage = useMemo(() => { const lastMessage = data?.pages?.at(-1)?.at(-1); return isJobInbox(inboxId) && lastMessage?.isLocal; @@ -330,8 +347,19 @@ const ChatConversation = () => { setMessageContent(''); // trick to clear the ws stream message if (!auth || data.message.trim() === '') return; fromPreviousMessagesRef.current = false; - const workflowVersion = workflowSelected?.version; - const workflowName = workflowSelected?.name; + + let workflowToUse = workflowSelected; + if (!workflowToUse && firstMessageWorkflow) { + workflowToUse = { + name: firstMessageWorkflow.name, + version: firstMessageWorkflow.version, + description: '', // We don't have this information from the first message + raw: '', // We don't have this information from the first message + }; + } + + const workflowVersion = workflowToUse?.version; + const workflowName = workflowToUse?.name; if (data.file) { await sendTextMessageWithFilesForInbox({ @@ -342,7 +370,7 @@ const ChatConversation = () => { message: data.message, inboxId: inboxId, files: [currentFile], - workflowName: workflowSelected + workflowName: workflowToUse ? `${workflowName}:::${workflowVersion}` : undefined, my_device_encryption_sk: auth.my_device_encryption_sk, @@ -366,7 +394,7 @@ const ChatConversation = () => { parent: '', // Note: we should set the parent if we want to retry or branch out shinkaiIdentity: auth.shinkai_identity, profile: auth.profile, - workflowName: workflowSelected + workflowName: workflowToUse ? `${workflowName}:::${workflowVersion}` : undefined, my_device_encryption_sk: auth.my_device_encryption_sk,