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.4 KB
Raw Blame
import { getBuiltinPortalAction } from '@lobechat/builtin-tools/portals';
import type { BuiltinPortalTitle } from '@lobechat/types';
import isEqual from 'fast-deep-equal';

import { useChatStore } from '@/store/chat';
import { chatPortalSelectors, dbMessageSelectors } from '@/store/chat/selectors';

import HeaderChrome from '../components/Header';
import Title from './Title';

/**
 * ToolUI portal header: the generic back/close chrome plus the tool's title and,
 * when a tool registers them, header right-actions (e.g. prev/next nav).
 */
const Header = ({ onClose }: { onClose?: () => void }) => {
  const [toolUIIdentifier = '', messageId] = useChatStore((s) => [
    chatPortalSelectors.toolUIIdentifier(s),
    chatPortalSelectors.toolMessageId(s),
  ]);
  const params = useChatStore(chatPortalSelectors.toolUIParams, isEqual);
  const message = useChatStore(dbMessageSelectors.getDbMessageById(messageId || ''), isEqual);

  const Actions = getBuiltinPortalAction(toolUIIdentifier) as BuiltinPortalTitle | undefined;

  return (
    <HeaderChrome
      title={<Title />}
      rightExtra={
        Actions ? (
          <Actions
            apiName={message?.plugin?.apiName}
            identifier={toolUIIdentifier}
            messageId={messageId || ''}
            params={params}
          />
        ) : undefined
      }
      onClose={onClose}
    />
  );
};

export default Header;