From 4d3a9707cad467819fdcea62ee65c3cf31e8278a Mon Sep 17 00:00:00 2001 From: joelhulen Date: Fri, 12 Jan 2024 18:00:03 -0500 Subject: [PATCH] Make the agent selection sticky across chat sessions - default to first agent if none previously selected --- src/ui/UserPortal/stores/appStore.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ui/UserPortal/stores/appStore.ts b/src/ui/UserPortal/stores/appStore.ts index 175e696cae..43665f1025 100644 --- a/src/ui/UserPortal/stores/appStore.ts +++ b/src/ui/UserPortal/stores/appStore.ts @@ -12,6 +12,7 @@ export const useAppStore = defineStore('app', { isSidebarClosed: false as boolean, agents: [] as Agent[], selectedAgents: new Map(), + lastSelectedAgent: null as Agent | null, }), getters: {}, @@ -112,10 +113,21 @@ export const useAppStore = defineStore('app', { }, getSessionAgent(session: Session) { - return this.selectedAgents.get(session.id); + var selectedAgent = this.selectedAgents.get(session.id); + if (!selectedAgent) { + if (this.lastSelectedAgent) { + // Default to the last selected agent to make the selection "sticky" across sessions. + selectedAgent = this.lastSelectedAgent; + } else { + // Default to the first agent in the list. + selectedAgent = this.agents[0]; + } + } + return selectedAgent; }, setSessionAgent(session: Session, agent: Agent) { + this.lastSelectedAgent = agent; return this.selectedAgents.set(session.id, agent); },