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.

3.6 KB
Raw Blame
'use client';

import type { BuiltinInspectorProps } from '@lobechat/types';
import { cx, Icon } from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import { CheckCircle2, CircleAlert } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { highlightTextStyles, inspectorTextStyles, shinyTextStyles } from '@/styles';

import type {
  DeclareSelfFeedbackIntentParams,
  DeclareSelfFeedbackIntentState,
} from '../../../types';

const getIntentLabelKey = (data?: Partial<DeclareSelfFeedbackIntentParams>) => {
  if (data?.kind === 'memory' && data.action === 'write') {
    return 'builtins.lobe-self-feedback-intent.inspector.memory.write';
  }

  if (data?.kind === 'skill' && data.action === 'create') {
    return 'builtins.lobe-self-feedback-intent.inspector.skill.create';
  }

  if (data?.kind === 'skill' && data.action === 'refine') {
    return 'builtins.lobe-self-feedback-intent.inspector.skill.refine';
  }

  if (data?.kind === 'skill' && data.action === 'consolidate') {
    return 'builtins.lobe-self-feedback-intent.inspector.skill.consolidate';
  }

  if (data?.kind === 'gap' && data.action === 'proposal') {
    return 'builtins.lobe-self-feedback-intent.inspector.gap.proposal';
  }

  return 'builtins.lobe-self-feedback-intent.apiName.declareSelfFeedbackIntent';
};

const styles = stylex.create({
  iconAccepted: { flexShrink: 0, color: cssVar.colorSuccess },
  iconRejected: { flexShrink: 0, color: cssVar.colorWarning },
  meta: { flexShrink: 0, fontSize: '12px', color: cssVar.colorTextTertiary },
  summary: {
    overflow: 'hidden',
    minWidth: '0',
    maxWidth: '320px',
    textOverflow: 'ellipsis',
    whiteSpace: 'nowrap',
  },
});

export const DeclareSelfFeedbackIntentInspector = memo<
  BuiltinInspectorProps<DeclareSelfFeedbackIntentParams, DeclareSelfFeedbackIntentState>
>(({ args, partialArgs, isArgumentsStreaming, isLoading, pluginState }) => {
  const { t } = useTranslation('plugin');

  const data = args ?? partialArgs;
  const summary = data?.summary;
  const hasContext = Boolean(summary || data?.kind || data?.action);
  const title = t(getIntentLabelKey(data));

  if (isArgumentsStreaming && !hasContext) {
    return (
      <div className={inspectorTextStyles.root}>
        <span className={shinyTextStyles.shinyText}>{title}</span>
      </div>
    );
  }

  const isSettled = !isArgumentsStreaming && !isLoading && !!pluginState;

  return (
    <div className={inspectorTextStyles.root} style={{ flexWrap: 'wrap', gap: 4 }}>
      <span className={cx((isArgumentsStreaming || isLoading) && shinyTextStyles.shinyText)}>
        {title}
      </span>
      {summary && (
        <span className={cx(stylex.props(styles.summary).className, highlightTextStyles.primary)}>
          {summary}
        </span>
      )}
      {isSettled &&
        pluginState &&
        (pluginState.accepted ? (
          <Icon
            className={stylex.props(styles.iconAccepted).className}
            icon={CheckCircle2}
            size={14}
          />
        ) : (
          <>
            <Icon
              className={stylex.props(styles.iconRejected).className}
              icon={CircleAlert}
              size={14}
            />
            <span {...stylex.props(styles.meta)}>
              {t('builtins.lobe-self-feedback-intent.inspector.rejected')}
            </span>
          </>
        ))}
    </div>
  );
});

DeclareSelfFeedbackIntentInspector.displayName = 'DeclareSelfFeedbackIntentInspector';

export default DeclareSelfFeedbackIntentInspector;