Skip to content

Commit

Permalink
Make the agent selection sticky across chat sessions - default to fir…
Browse files Browse the repository at this point in the history
…st agent if none previously selected
  • Loading branch information
joelhulen committed Jan 12, 2024
1 parent d15460d commit 4d3a970
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ui/UserPortal/stores/appStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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);
},

Expand Down

0 comments on commit 4d3a970

Please sign in to comment.