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.

1.8 KB
Raw Blame
import {
  DropdownMenuPopup,
  DropdownMenuPortal,
  DropdownMenuPositioner,
  stopPropagation,
} from '@lobehub/ui';
import { memo, type ReactNode } from 'react';

import type { EnabledProviderWithModels } from '@/types/aiProvider';

import { PanelContent } from './components/PanelContent';
import { styles } from './styles';

interface ModelSwitchSubmenuPopupProps {
  /** Muted text shown after the active model's name, e.g. its reasoning effort */
  activeSecondaryText?: string;
  enabledList?: EnabledProviderWithModels[];
  model?: string;
  notice?: ReactNode;
  onModelChange?: (params: { model: string; provider: string }) => Promise<void>;
  /** Called with `false` once a row is picked, so the host can close its whole menu. */
  onOpenChange?: (open: boolean) => void;
  provider?: string;
}

/**
 * The model panel mounted as a nested submenu instead of its own dropdown, for
 * hosts that fold model selection into a larger menu (chat input model + effort).
 * The caller supplies the `DropdownMenuSubmenuRoot` and its trigger row.
 */
export const ModelSwitchSubmenuPopup = memo<ModelSwitchSubmenuPopupProps>(
  ({ activeSecondaryText, enabledList, model, notice, onModelChange, onOpenChange, provider }) => (
    <DropdownMenuPortal>
      <DropdownMenuPositioner alignOffset={-4} anchor={null} placement="right" sideOffset={8}>
        <DropdownMenuPopup className={styles.container} onKeyDown={stopPropagation}>
          <PanelContent
            activeSecondaryText={activeSecondaryText}
            enabledList={enabledList}
            model={model}
            notice={notice}
            provider={provider}
            onModelChange={onModelChange}
            onOpenChange={onOpenChange}
          />
        </DropdownMenuPopup>
      </DropdownMenuPositioner>
    </DropdownMenuPortal>
  ),
);

ModelSwitchSubmenuPopup.displayName = 'ModelSwitchSubmenuPopup';