Added a `mentionMatching.ts` utility to normalize agent mention filtering across the codebase, fixing the handling of handles containing underscores. Updated `AgentMentionPopup`, `ChatView`, and `QuickChatFAB` to use the new utility, with corresponding tests added including a new `mentionMatching.te Fusion-Task-Id: FN-3809
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { useMemo } from "react";
|
|
import { AgentAvatar } from "./AgentAvatar";
|
|
import "./AgentMentionPopup.css";
|
|
import type { Agent } from "@fusion/core";
|
|
import { matchesAgentMentionFilter } from "./mentionMatching";
|
|
|
|
interface AgentMentionPopupProps {
|
|
/** List of agents to show */
|
|
agents: Agent[];
|
|
/** Current search filter text (the text typed after @) */
|
|
filter: string;
|
|
/** Currently highlighted index for keyboard navigation */
|
|
highlightedIndex: number;
|
|
/** Whether popup is visible */
|
|
visible: boolean;
|
|
/** Callback when an agent is selected */
|
|
onSelect: (agent: Agent) => void;
|
|
/** Positioning anchor: "above" | "below" the input */
|
|
position?: "above" | "below";
|
|
}
|
|
|
|
export function AgentMentionPopup({
|
|
agents,
|
|
filter,
|
|
highlightedIndex,
|
|
visible,
|
|
onSelect,
|
|
position = "below",
|
|
}: AgentMentionPopupProps) {
|
|
const filteredAgents = useMemo(() => agents.filter((agent) => matchesAgentMentionFilter(agent.name, filter)), [agents, filter]);
|
|
|
|
if (!visible) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={`agent-mention-popup agent-mention-popup--${position}`}
|
|
data-testid="agent-mention-popup"
|
|
role="listbox"
|
|
aria-label="Agent mention suggestions"
|
|
>
|
|
{filteredAgents.length === 0 ? (
|
|
<div className="agent-mention-empty">No agents found</div>
|
|
) : (
|
|
filteredAgents.map((agent, index) => (
|
|
<button
|
|
key={agent.id}
|
|
type="button"
|
|
className={`agent-mention-item${index === highlightedIndex ? " agent-mention-item--highlighted" : ""}`}
|
|
data-testid={`agent-mention-item-${agent.id}`}
|
|
onMouseDown={(event) => event.preventDefault()}
|
|
onClick={() => onSelect(agent)}
|
|
role="option"
|
|
aria-selected={index === highlightedIndex}
|
|
>
|
|
<AgentAvatar agent={agent} size={20} />
|
|
<span className="agent-mention-name">{agent.name}</span>
|
|
<span className="agent-mention-role">{agent.role}</span>
|
|
</button>
|
|
))
|
|
)}
|
|
</div>
|
|
);
|
|
}
|