@@ -175,9 +175,6 @@ export const useAgentStore = create<AgentState>()(
175
175
} ,
176
176
initializeFromProject : ( project : Project ) => {
177
177
if ( project ?. agents && project . agents . length > 0 ) {
178
- // After the selected agent's loaded from session storage,
179
- // we need to check if the selected agent is still in the project.
180
- // If not, we need to set the default agent to the first agent in the project.
181
178
const currentSelectedAgent = get ( ) . selectedAgent ;
182
179
let selectedAgent = currentSelectedAgent ;
183
180
@@ -195,6 +192,13 @@ export const useAgentStore = create<AgentState>()(
195
192
project . agents . find ( ( agent ) => agent . id === selectedAgent )
196
193
?. allowed_apps || [ ] ,
197
194
currentProjectId : project . id ,
195
+ // Clear these when switching projects
196
+ apps : [ ] ,
197
+ appFunctions : [ ] ,
198
+ linkedAccounts : [ ] ,
199
+ selectedApps : [ ] ,
200
+ selectedFunctions : [ ] ,
201
+ selectedLinkedAccountOwnerId : "" ,
198
202
} ) ) ;
199
203
}
200
204
} ,
@@ -229,11 +233,17 @@ export const useAgentStore = create<AgentState>()(
229
233
} ) ,
230
234
onRehydrateStorage : ( ) => ( state ) => {
231
235
// Clear state if project ID doesn't match
232
- if ( state && state . currentProjectId !== state . currentProjectId ) {
236
+ if (
237
+ state &&
238
+ state . currentProjectId !== window . location . pathname . split ( "/" ) [ 2 ]
239
+ ) {
233
240
state . selectedApps = [ ] ;
234
241
state . selectedFunctions = [ ] ;
235
242
state . selectedLinkedAccountOwnerId = "" ;
236
243
state . selectedAgent = "" ;
244
+ state . apps = [ ] ;
245
+ state . appFunctions = [ ] ;
246
+ state . linkedAccounts = [ ] ;
237
247
}
238
248
} ,
239
249
} ,
0 commit comments