| 335 | } |
| 336 | |
| 337 | export function useRetainedPersona( |
| 338 | sourcePersona: AgentPersona | undefined, |
| 339 | profileIdentityKey: string, |
| 340 | ) { |
| 341 | const [retainedPersona, setRetainedPersona] = React.useState<{ |
| 342 | key: string; |
| 343 | persona: AgentPersona; |
| 344 | } | null>(null); |
| 345 | |
| 346 | React.useEffect(() => { |
| 347 | if (!sourcePersona) return; |
| 348 | setRetainedPersona({ key: profileIdentityKey, persona: sourcePersona }); |
| 349 | }, [profileIdentityKey, sourcePersona]); |
| 350 | |
| 351 | return ( |
| 352 | sourcePersona ?? |
| 353 | (retainedPersona?.key === profileIdentityKey |
| 354 | ? retainedPersona.persona |
| 355 | : undefined) |
| 356 | ); |
| 357 | } |