Assistant is not Deleting a thread on refresh

Hello guys! I am using assistant API to build a helper for the wax blockchain community! Im running into a issue where my threads are not properly deleting when I refresh the webpage. I can get the thread to reset when I hard refresh but I need the thread to reset on a normal refresh. The reason is because when someone calls a function within the chat and if they refresh the browser my assistant thread carries over into the next reload and since I send an auto “hello” on page refresh to simulate the Assistant greeting the user first. The assistant thinks “hello” is the prompt response to the prior function before the refresh. Even gpt4-o is not able to help me fix it, if I could get any assistance on this issue it would be very helpful!

heres my server.js pertaining to the issue.
///…
const deleteThread = async (threadId) => {
try {
const client = axios.create({
baseURL: ‘url’,
headers: {
Authorization: Bearer ${API_KEY}
}
});

const response = await client.delete(`/threads/${threadId}`);
console.log('Thread deleted:', response.data);

} catch (error) {
console.error(‘Error deleting thread:’, error.response ? error.response.data : error.message);
}
};
////…

///…
// In-memory store for conversation state
let conversationState = {};
let currentThreadId = null;

app.post(‘/api/message’, async (req, res) => {
const { message, chatHistory } = req.body;
console.log(‘Received message:’, message);

try {
// Reset conversation state if the message is “reset”
if (message.trim().toLowerCase() === ‘reset’) {
if (currentThreadId) {
await deleteThread(currentThreadId);
currentThreadId = null;
}
conversationState = {};
return res.json({ response: ‘Conversation state has been reset.’ });
}

const { response, threadId } = await getAssistantResponse(message, chatHistory);
currentThreadId = threadId;

let assistantResponse = response;

///…

you need to persist the state in your front end so that even if the browser refreshes it will not default to hello state and will seamlessly continue the thread.

I want the thread to delete and reset when you refresh. It currently does not. The “hello” is by design.

Try creating new threads for each refresh as a temporary fix. Retrieve all the threads eod and clear them. Cheers!