Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

2.5 KB
Raw Blame
import { Card } from "@/src/components/ui/card";
import { AnnotationForm } from "@/src/features/scores/components/AnnotationForm";
import type { ScoreTarget } from "@/src/features/scores/types";
import {
  type AnnotationQueueItem,
  type ScoreDomain,
  isPresent,
  type ScoreConfigDomain,
} from "@langfuse/shared";
import { TriangleAlertIcon } from "@langfuse/icons";
import { useSession } from "next-auth/react";
import { type WithStringifiedMetadata } from "@/src/utils/clientSideDomainTypes";

interface AnnotationDrawerSectionProps {
  item: AnnotationQueueItem & {
    parentTraceId?: string | null;
    lockedByUser: { name: string | null | undefined } | null;
  };
  scoreTarget: ScoreTarget;
  scores: WithStringifiedMetadata<ScoreDomain>[];
  configs: ScoreConfigDomain[];
  environment?: string;
  isV4: boolean;
}

export const AnnotationDrawerSection: React.FC<
  AnnotationDrawerSectionProps
> = ({ item, scoreTarget, scores, configs, environment, isV4 }) => {
  const session = useSession();

  const isLockedByOtherUser = item.lockedByUserId !== session.data?.user?.id;

  const hasNonAnnotationScores = scores.some(
    (score) => score.source !== "ANNOTATION",
  );

  return (
    <Card className="col-span-2 flex h-full flex-col overflow-y-auto border-none p-3 [--annotation-surface:var(--card)]">
      <AnnotationForm
        key={"annotation-drawer-content" + item.objectId}
        scoreTarget={scoreTarget}
        serverScores={scores}
        configSelection={{ mode: "fixed", configs }}
        scoreMetadata={{
          projectId: item.projectId,
          queueId: item.queueId,
          environment,
        }}
        analyticsData={{
          type: scoreTarget.type,
          source: "AnnotationQueue",
          isV4,
        }}
        actionButtons={
          isLockedByOtherUser && isPresent(item.lockedByUser?.name) ? (
            <div className="border-dark-red bg-light-red flex items-center justify-center rounded-sm border p-1">
              <TriangleAlertIcon
                size="base"
                __rawClassName="text-dark-red mr-1"
              />
              <span className="text-dark-red text-xs">
                Currently edited by {item.lockedByUser.name}
              </span>
            </div>
          ) : undefined
        }
      />
      {hasNonAnnotationScores && (
        <div className="text-muted-foreground mt-4 text-xs">
          API and eval scores visible when toggling on the detailed view. Add
          manual annotations above.
        </div>
      )}
    </Card>
  );
};