From 9282f6805475a8e117a3830d7193e0d02d937d8e Mon Sep 17 00:00:00 2001 From: Paul Ccari <46382556+paulclindo@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:55:45 -0500 Subject: [PATCH] fix: send workflow when upload files (#388) * fix: upload files workflowName * fixes * more fixes --- .../src/pages/chat/chat-conversation.tsx | 52 ++++++++++++++----- apps/shinkai-desktop/src/pages/create-job.tsx | 7 ++- libs/shinkai-message-ts/src/api/methods.ts | 3 +- .../src/lib/mutations/createJob/index.ts | 1 + .../sendMesssageWithFilesToInbox/index.ts | 2 + .../sendMesssageWithFilesToInbox/types.ts | 1 + .../src/lib/query-provider.tsx | 2 +- 7 files changed, 51 insertions(+), 17 deletions(-) diff --git a/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx b/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx index f7fd2f0da..28398434d 100644 --- a/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx +++ b/apps/shinkai-desktop/src/pages/chat/chat-conversation.tsx @@ -234,7 +234,10 @@ const ChatConversation = () => { }, }); - const { file } = chatForm.watch(); + const currentFile = useWatch({ + control: chatForm.control, + name: 'file', + }); const { data, @@ -327,6 +330,9 @@ 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; + if (data.file) { await sendTextMessageWithFilesForInbox({ nodeAddress: auth?.node_address ?? '', @@ -335,7 +341,10 @@ const ChatConversation = () => { receiver: auth.shinkai_identity, message: data.message, inboxId: inboxId, - files: [file], + files: [currentFile], + workflowName: workflowSelected + ? `${workflowName}:::${workflowVersion}` + : undefined, my_device_encryption_sk: auth.my_device_encryption_sk, my_device_identity_sk: auth.my_device_identity_sk, node_encryption_pk: auth.node_encryption_pk, @@ -348,8 +357,7 @@ const ChatConversation = () => { if (isJobInbox(inboxId)) { const jobId = extractJobIdFromInbox(inboxId); - const workflowVersion = workflowSelected?.version; - const workflowName = workflowSelected?.name; + await sendMessageToJob({ nodeAddress: auth.node_address, jobId: jobId, @@ -390,6 +398,7 @@ const ChatConversation = () => { useEffect(() => { chatForm.reset(); + setWorkflowSelected(undefined); }, [chatForm, inboxId]); const isLimitReachedErrorLastMessage = useMemo(() => { @@ -402,6 +411,18 @@ const ChatConversation = () => { return errorCode === ErrorCodes.ShinkaiBackendInferenceLimitReached; }, [data?.pages]); + const isWorkflowSelectedAndFilesPresent = + workflowSelected && currentFile !== undefined; + + useEffect(() => { + if (isWorkflowSelectedAndFilesPresent) { + chatForm.setValue( + 'message', + `${formatWorkflowName(workflowSelected.name)} - ${workflowSelected.description}`, + ); + } + }, [chatForm, isWorkflowSelectedAndFilesPresent, workflowSelected]); + return (
@@ -482,7 +503,7 @@ const ChatConversation = () => { autoFocus bottomAddons={ } - disabled={isLoadingMessage} + disabled={ + isLoadingMessage || + isWorkflowSelectedAndFilesPresent + } // isLoading={isLoadingMessage} onChange={field.onChange} onSubmit={chatForm.handleSubmit(onSubmit)} @@ -522,9 +546,9 @@ const ChatConversation = () => { @@ -544,23 +568,23 @@ const ChatConversation = () => {
)} - {file && ( + {currentFile && (
- {getFileExt(file?.name) && - fileIconMap[getFileExt(file?.name)] ? ( + {getFileExt(currentFile?.name) && + fileIconMap[getFileExt(currentFile?.name)] ? ( ) : ( )}
- {file?.name} + {currentFile?.name} - {size(file?.size)} + {size(currentFile?.size)}