All files / src/components/tools MetadataCard.tsx

81.81% Statements 9/11
83.33% Branches 5/6
100% Functions 2/2
81.81% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                3x     3x     3x 2x       1x 1x 1x                 3x   3x                  
import type { JSX } from "react";
import { CornerDownRight } from "lucide-react";
import type { ToolCardProps } from "./ToolCardProps.js";
import { ICON_SM } from "../../utils/iconSize.js";
import styles from "./toolCards.module.scss";
 
/** Extracts a human-readable summary from metadata tool args. */
function getSummary(tool: string, args: unknown): string {
  Iif (args === null || args === undefined || typeof args !== "object") {
    return "";
  }
  const a = args as Record<string, unknown>;
 
  // report_intent: show the intent value
  if (typeof a.intent === "string") {
    return a.intent;
  }
 
  // Generic: show first string value
  for (const value of Object.values(a)) {
    if (typeof value === "string") {
      return value;
    }
  }
 
  return tool;
}
 
/** Renders a metadata/intent tool call as a minimal inline annotation. */
export function MetadataCard({ tool, args }: ToolCardProps): JSX.Element {
  const summary = getSummary(tool, args);
 
  return (
    <div className={styles.metadata} data-testid="tool-card-metadata">
      <span className={styles.metadataPrefix}>
        <CornerDownRight size={ICON_SM} />
      </span>
      {summary}
    </div>
  );
}