diff --git a/app/components/Stream.tsx b/app/components/Stream.tsx index 271506d..346c547 100644 --- a/app/components/Stream.tsx +++ b/app/components/Stream.tsx @@ -1,10 +1,10 @@ import { cn } from '@coinbase/onchainkit/theme'; -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import { useTransactionCount } from 'wagmi'; import { AGENT_WALLET_ADDRESS, DEFAULT_PROMPT } from '../constants'; import useChat from '../hooks/useChat'; import type { AgentMessage, StreamEntry } from '../types'; -import { generateUUID, markdownToPlainText } from '../utils'; +import { markdownToPlainText } from '../utils'; import StreamItem from './StreamItem'; type StreamProps = { @@ -16,9 +16,6 @@ export default function Stream({ className }: StreamProps) { const [isThinking, setIsThinking] = useState(true); const [loadingDots, setLoadingDots] = useState(''); const bottomRef = useRef(null); - const conversationId = useMemo(() => { - return generateUUID(); - }, []); const handleSuccess = useCallback((messages: AgentMessage[]) => { let message = messages.find((res) => res.event === 'agent'); @@ -42,7 +39,6 @@ export default function Stream({ className }: StreamProps) { const { postChat, isLoading } = useChat({ onSuccess: handleSuccess, - conversationId, }); // enables live stream of agent thoughts diff --git a/app/hooks/useChat.ts b/app/hooks/useChat.ts index 652e3d9..3a3caaa 100644 --- a/app/hooks/useChat.ts +++ b/app/hooks/useChat.ts @@ -1,6 +1,7 @@ import { useCallback, useState } from 'react'; import { API_URL } from '../config'; import type { AgentMessage } from '../types'; +import { generateUUID } from '../utils'; type UseChatResponse = { messages?: AgentMessage[]; @@ -30,7 +31,10 @@ export default function useChat({ headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ input, conversation_id: conversationId }), + body: JSON.stringify({ + input, + conversation_id: conversationId || generateUUID(), + }), }); if (!response.ok) {