From 432477341c65eba5f4a071ec20699e03cf6d23c6 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 19 Dec 2024 10:32:35 +0700 Subject: [PATCH] fix: new thread isn't automatically created on factory reset --- web/helpers/atoms/Assistant.atom.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/helpers/atoms/Assistant.atom.ts b/web/helpers/atoms/Assistant.atom.ts index cb50a0553..29da581c3 100644 --- a/web/helpers/atoms/Assistant.atom.ts +++ b/web/helpers/atoms/Assistant.atom.ts @@ -4,9 +4,15 @@ import { atomWithStorage } from 'jotai/utils' export const assistantsAtom = atom([]) +export const cachedAssistantAtom = atomWithStorage< + ThreadAssistantInfo | undefined +>('activeAssistant', undefined, undefined, { getOnInit: true }) /** * Get the current active assistant */ -export const activeAssistantAtom = atomWithStorage< - ThreadAssistantInfo | undefined ->('activeAssistant', undefined, undefined, { getOnInit: true }) +export const activeAssistantAtom = atom( + (get) => get(cachedAssistantAtom) ?? get(assistantsAtom)[0], + (_get, set, newAssistant: ThreadAssistantInfo) => { + set(cachedAssistantAtom, newAssistant) + } +)