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.

896 B
Raw Blame
export interface PendingOverlayDispatch {
  agentId: string;
  captureIds: string[];
  dispatchId: string;
  modelId?: string;
  prompt: string;
  provider?: string;
}

interface CanConsumePendingOverlayDispatchParams {
  agentId?: string | null;
  isAgentConfigLoading: boolean;
  messagesInit: boolean;
  pendingDispatch: PendingOverlayDispatch | null;
  routeAgentId?: string | null;
  topicId?: string | null;
}

export const canConsumePendingOverlayDispatch = ({
  agentId,
  isAgentConfigLoading,
  messagesInit,
  pendingDispatch,
  routeAgentId,
  topicId,
}: CanConsumePendingOverlayDispatchParams) => {
  if (!pendingDispatch || !agentId) return false;
  if (pendingDispatch.agentId !== agentId) return false;
  if (routeAgentId && routeAgentId !== agentId) return false;

  const isNewConversation = !topicId;

  return !isAgentConfigLoading && (isNewConversation || messagesInit);
};