Skip to content

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

2.3 KB
Raw Blame
import { PlusCircle } from "@langfuse/icons";
import { IdTableCell } from "@/src/components/design-system/table/components/IdTableCell/IdTableCell";
import { UpsertModelFormDialogController } from "@/src/features/models/components/UpsertModelFormDialog/UpsertModelFormDialogController";

/**
 * Renders the "Provided Model Name" cell shared by the generations and events
 * tables. When the model resolves to a definition it is a plain name; when it
 * does not, the name carries a trailing "add model definition" affordance.
 *
 * Both states render the name through {@link IdTableCell} so typography and
 * vertical alignment stay identical row-to-row — the trailing icon is a
 * `shrink-0` adornment that never shifts the text baseline. The trigger is a
 * `role="button"` and stops click propagation so opening the dialog does not
 * also open the table's peek view.
 */
export function ProvidedModelNameCell({
  modelName,
  modelId,
  projectId,
  usageDetails,
}: {
  modelName: string;
  modelId: string | undefined;
  projectId: string;
  usageDetails: Record<string, number>;
}) {
  // Both states wrap the name in the same inline-flex so the text sits at an
  // identical baseline whether or not the trailing affordance is present.
  if (modelId) {
    return (
      <span className="inline-flex max-w-full min-w-0 items-center">
        <IdTableCell value={modelName} />
      </span>
    );
  }

  const prices =
    Object.keys(usageDetails).length > 0
      ? Object.keys(usageDetails)
          .filter((key) => key !== "total")
          .reduce(
            (acc, key) => {
              acc[key] = 0.000001;
              return acc;
            },
            {} as Record<string, number>,
          )
      : undefined;

  return (
    <UpsertModelFormDialogController
      action="create"
      projectId={projectId}
      prefilledModelData={{ modelName, prices }}
    >
      {({ openDialog }) => (
        <button
          type="button"
          title={`Add a model definition for "${modelName}"`}
          onClick={(e) => {
            e.stopPropagation();
            openDialog();
          }}
          className="inline-flex max-w-full min-w-0 cursor-pointer items-center gap-1 text-left"
        >
          <IdTableCell value={modelName} />
          <PlusCircle size="base" />
        </button>
      )}
    </UpsertModelFormDialogController>
  );
}