Skip to content

Commit

Permalink
Merge pull request #443 from solliancenet/jdh-agent-selection-stickiness
Browse files Browse the repository at this point in the history
Make the agent selection sticky across chat sessions
  • Loading branch information
ciprianjichici authored Jan 13, 2024
2 parents 9180fc4 + c8d6d1c commit 75c91dc
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 75c91dc

Please sign in to comment.