diff --git a/apps/shinkai-visor/src/components/inbox/inbox.tsx b/apps/shinkai-visor/src/components/inbox/inbox.tsx
index 808cdb1f0..f5d94e51d 100644
--- a/apps/shinkai-visor/src/components/inbox/inbox.tsx
+++ b/apps/shinkai-visor/src/components/inbox/inbox.tsx
@@ -126,30 +126,6 @@ export const Inbox = () => {
}
};
- const retrySendMessage = (message: ChatConversationMessage) => {
- console.log('retrySendMessage');
- if (!auth) return;
- const jobId = extractJobIdFromInbox(decodedInboxId);
- sendMessageToJob({
- nodeAddress: auth.node_address,
- jobId,
- // message: 'what is html in 1 one line',
- message: 'what is css in 3 words',
- files_inbox: '',
- parent:
- '57b61385ac57ccdbc3447a8175b7442d7a2fe9aafcbf5203dc9e719411f6db7d',
- // parent:
- // '530f2a9a6107e9918a88f74e69aab8ed12e81aa07cc92569bf2fdac4e463f047',
- shinkaiIdentity: auth.shinkai_identity,
- profile: auth.profile,
- 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,
- profile_encryption_sk: auth.profile_encryption_sk,
- profile_identity_sk: auth.profile_identity_sk,
- });
- };
-
useEffect(() => {
const chatContainerElement = chatContainerRef.current;
if (!chatContainerElement) return;
@@ -260,7 +236,7 @@ export const Inbox = () => {
-
+
);
@@ -295,16 +271,70 @@ export const Inbox = () => {
);
};
-function ChatMessages({ messages }: { messages: ChatConversationMessage[] }) {
- console.log(messages, 'messages');
- const [mainThread, setMainThread] = useState([]);
+function ChatMessages({
+ initialMessages,
+}: {
+ initialMessages: ChatConversationMessage[];
+}) {
+ const auth = useAuth((state) => state.auth);
+ const { inboxId } = useParams<{ inboxId: string }>();
+
+ const { mutateAsync: sendMessageToJob, isPending: isSendingMessageToJob } =
+ useSendMessageToJob();
+
+ console.log(initialMessages, 'messages');
+ const [activeThread, setActiveThread] = useState(
+ [],
+ );
+ const messagesRef = useRef([]);
+ console.log(messagesRef, 'messagesRef');
+ const buildActiveThread = useCallback(
+ (messages: ChatConversationMessage[]) => {
+ const thread = [];
+ let currentMessage = messages.find((m) => m.parentHash === 'root'); // Start from root
+
+ while (currentMessage) {
+ thread.push(currentMessage);
+ currentMessage = messages.find(
+ (message) => message.parentHash === currentMessage?.hash,
+ );
+ }
+
+ return thread;
+ },
+ [],
+ );
useEffect(() => {
- // TODO: get main thread
- setMainThread(messages);
- }, [messages]);
+ const thread = buildActiveThread(initialMessages);
+ setActiveThread(thread);
+ }, [initialMessages, buildActiveThread]);
+
+ const regenerateLastMessage = () => {
+ const content = activeThread.at(-2)?.content;
+ const parentHash = activeThread.at(-3)?.hash;
+ console.log(content, parentHash, 'activeThread');
+ console.log('retrySendMessage');
+ if (!auth) return;
+ const decodedInboxId = decodeURIComponent(inboxId);
+ const jobId = extractJobIdFromInbox(decodedInboxId);
+ sendMessageToJob({
+ nodeAddress: auth.node_address,
+ jobId,
+ message: content!,
+ files_inbox: '',
+ parent: parentHash!,
+ shinkaiIdentity: auth.shinkai_identity,
+ profile: auth.profile,
+ 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,
+ profile_encryption_sk: auth.profile_encryption_sk,
+ profile_identity_sk: auth.profile_identity_sk,
+ });
+ };
- return mainThread.map((message, index) => {
+ return activeThread.map((message, index) => {
return (
-
- {message.isLocal && (
-
- )}
+
);
});
diff --git a/apps/shinkai-visor/src/components/message/message.tsx b/apps/shinkai-visor/src/components/message/message.tsx
index 77eb5a0ff..0f35028d7 100644
--- a/apps/shinkai-visor/src/components/message/message.tsx
+++ b/apps/shinkai-visor/src/components/message/message.tsx
@@ -3,10 +3,12 @@ import {
Avatar,
AvatarFallback,
AvatarImage,
+ buttonVariants,
CopyToClipboardIcon,
MarkdownPreview,
} from '@shinkai_network/shinkai-ui';
import { cn } from '@shinkai_network/shinkai-ui/utils';
+import { RotateCcw } from 'lucide-react';
import React from 'react';
import shinkaiMiniLogo from '../../assets/icons/shinkai-min.svg';
@@ -17,6 +19,8 @@ import { FileList } from '../file-list/file-list';
type MessageProps = {
message: ChatConversationMessage;
+ isLastMessage?: boolean;
+ regenerateLastMessage: () => void;
};
const copyToClipboard = (content: string) => {
sendMessage({
@@ -25,7 +29,11 @@ const copyToClipboard = (content: string) => {
});
};
-export const Message = ({ message }: MessageProps) => {
+export const Message = ({
+ message,
+ isLastMessage,
+ regenerateLastMessage,
+}: MessageProps) => {
const openMarkdownLink = (
event: React.MouseEvent,
url?: string,
@@ -81,6 +89,15 @@ export const Message = ({ message }: MessageProps) => {
}}
source={message.content}
/>
+ {isLastMessage && (
+
+ )}
{!!message.fileInbox?.files?.length && (