Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

671 B
Raw Blame
import { useState } from 'react';

/**
 * The agent the switcher reopens when the reader comes back to "Agents": the one last on screen,
 * however it got there — picked in the switcher or opened from the onboarding link — else the
 * first of `agentKeys` (the one that learned the most).
 */
export const useAgentToReopen = (value: string, agentKeys: string[]) => {
  const [lastAgent, setLastAgent] = useState<string>();
  // Adjusting state during render: whichever agent is on screen becomes the remembered one.
  if (value !== 'mine' && value !== lastAgent) setLastAgent(value);
  return lastAgent && agentKeys.includes(lastAgent) ? lastAgent : agentKeys[0];
};