-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Agents list #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Agents list #109
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "agents.title": "Agents", | ||
| "agents.loading": "Loading agents, please wait...", | ||
| "agents.error.loading": "Error loading agents", | ||
| "agents.card.status.active": "Active", | ||
| "agents.card.status.inactive": "Inactive", | ||
| "agents.empty.title": "No agents yet", | ||
| "agents.empty.description": "Agents will appear here once they're registered with the gateway." | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "agents.title": "Agentes", | ||
| "agents.loading": "Cargando agentes, por favor espere...", | ||
| "agents.error.loading": "Error al cargar los agentes", | ||
| "agents.card.status.active": "Activo", | ||
| "agents.card.status.inactive": "Inactivo", | ||
| "agents.empty.title": "Aún no hay agentes", | ||
| "agents.empty.description": "Los agentes aparecerán aquí una vez que se registren en la puerta de enlace." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "agents.title": "Agentes", | ||
| "agents.loading": "Carregando agentes, aguarde...", | ||
| "agents.error.loading": "Erro ao carregar os agentes", | ||
| "agents.card.status.active": "Ativo", | ||
| "agents.card.status.inactive": "Inativo", | ||
| "agents.empty.title": "Ainda não há agentes", | ||
| "agents.empty.description": "Os agentes aparecerão aqui assim que forem registrados no gateway." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { screen, waitFor } from "@testing-library/react"; | ||
| import { http, HttpResponse } from "msw"; | ||
| import { server } from "@/test/mocks/server"; | ||
| import { Agents } from "./Agents"; | ||
| import { renderWithProviders } from "@/test/test-utils"; | ||
| import type { A2AAgentRead } from "@/generated/types"; | ||
|
|
||
| type Agent = NonNullable<A2AAgentRead>; | ||
|
|
||
| function createMockAgent(id: number, overrides: Partial<Agent> = {}): Agent { | ||
| return { | ||
| id: `agent-${id}`, | ||
| name: `Agent ${id}`, | ||
| slug: `agent-${id}`, | ||
| description: `Description for agent ${id}`, | ||
| endpointUrl: `http://localhost/agents/${id}`, | ||
| agentType: "generic", | ||
| protocolVersion: "1.0", | ||
| capabilities: {}, | ||
| config: {}, | ||
| enabled: true, | ||
| reachable: true, | ||
| createdAt: new Date().toISOString(), | ||
| updatedAt: new Date().toISOString(), | ||
| lastInteraction: null, | ||
| tags: [], | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("Agents", () => { | ||
| it("renders loading state initially", async () => { | ||
| let resolveRequest: () => void; | ||
| const requestGate = new Promise<void>((resolve) => { | ||
| resolveRequest = resolve; | ||
| }); | ||
|
|
||
| server.use( | ||
| http.get("/api/a2a", async () => { | ||
| await requestGate; | ||
| return HttpResponse.json([]); | ||
| }), | ||
| ); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| const status = screen.getByRole("status"); | ||
| expect(status).toBeInTheDocument(); | ||
| expect(status).toHaveAttribute("aria-live", "polite"); | ||
| expect(status).toHaveAttribute("aria-busy", "true"); | ||
| expect(screen.getByText("Loading agents, please wait...")).toBeInTheDocument(); | ||
|
|
||
| resolveRequest!(); | ||
| await waitFor(() => { | ||
| expect(screen.getByText("No agents yet")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it("displays error message when the API call fails", async () => { | ||
| server.use( | ||
| http.get("/api/a2a", () => | ||
| HttpResponse.json({ detail: "Failed to fetch agents" }, { status: 500 }), | ||
| ), | ||
| ); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByRole("alert")).toBeInTheDocument(); | ||
| }); | ||
| expect(screen.getByText("Error loading agents")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows an empty state when there are no agents", async () => { | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json([]))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("No agents yet")).toBeInTheDocument(); | ||
| }); | ||
| expect( | ||
| screen.getByText("Agents will appear here once they're registered with the gateway."), | ||
| ).toBeInTheDocument(); | ||
| expect(document.querySelectorAll('[data-slot="card"]')).toHaveLength(0); | ||
| }); | ||
|
|
||
| it("renders a card per agent with its name and description", async () => { | ||
| const mockAgents = [createMockAgent(1), createMockAgent(2)]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("Agent 1")).toBeInTheDocument(); | ||
| }); | ||
| expect(screen.getByText("Agent 2")).toBeInTheDocument(); | ||
| expect(screen.getByText("Description for agent 1")).toBeInTheDocument(); | ||
| expect(document.querySelectorAll('[data-slot="card"]')).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("omits the description when an agent has none", async () => { | ||
| const mockAgents = [createMockAgent(1, { description: "" })]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("Agent 1")).toBeInTheDocument(); | ||
| }); | ||
| expect(screen.queryByText("Description for agent 1")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows an active status indicator when the agent is enabled and reachable", async () => { | ||
| const mockAgents = [createMockAgent(1, { enabled: true, reachable: true })]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| expect(await screen.findByRole("img", { name: "Active" })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows an inactive status indicator when the agent is disabled or unreachable", async () => { | ||
| const mockAgents = [createMockAgent(1, { enabled: false, reachable: true })]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| expect(await screen.findByRole("img", { name: "Inactive" })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders tag chips for an agent's tags", async () => { | ||
| const mockAgents = [ | ||
| createMockAgent(1, { tags: [{ label: "billing" }, { label: "internal" }] }), | ||
| ]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("billing")).toBeInTheDocument(); | ||
| }); | ||
| expect(screen.getByText("internal")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("caps visible tags at 8 and shows a +N overflow chip", async () => { | ||
| const mockAgents = [ | ||
| createMockAgent(1, { | ||
| tags: Array.from({ length: 10 }, (_, i) => ({ label: `tag-${i + 1}` })), | ||
| }), | ||
| ]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("tag-1")).toBeInTheDocument(); | ||
| }); | ||
| expect(screen.getByText("tag-8")).toBeInTheDocument(); | ||
| expect(screen.queryByText("tag-9")).not.toBeInTheDocument(); | ||
| expect(screen.getByText("+2")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders without tags when the field is omitted entirely", async () => { | ||
| const agent = createMockAgent(1); | ||
| delete (agent as Partial<Agent>).tags; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json([agent]))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("Agent 1")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it("ignores null entries returned by the API", async () => { | ||
| const mockAgents: (Agent | null)[] = [createMockAgent(1), null]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("Agent 1")).toBeInTheDocument(); | ||
| }); | ||
| expect(document.querySelectorAll('[data-slot="card"]')).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("treats a non-array response as an empty list instead of crashing", async () => { | ||
| // The shape a broken/legacy backend response would take — guards the | ||
| // Array.isArray fallback rather than assuming `data` is always an array. | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json({ agents: [] }))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("No agents yet")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| it("requests the list with include_inactive=true so disabled agents stay listed", async () => { | ||
| let requestedUrl: URL | undefined; | ||
| server.use( | ||
| http.get("/api/a2a", ({ request }) => { | ||
| requestedUrl = new URL(request.url); | ||
| return HttpResponse.json([]); | ||
| }), | ||
| ); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("No agents yet")).toBeInTheDocument(); | ||
| }); | ||
| expect(requestedUrl?.searchParams.get("include_inactive")).toBe("true"); | ||
| expect(requestedUrl?.searchParams.get("limit")).toBe("0"); | ||
| }); | ||
|
|
||
| it("uses correct grid layout classes", async () => { | ||
| const mockAgents = [createMockAgent(1)]; | ||
| server.use(http.get("/api/a2a", () => HttpResponse.json(mockAgents))); | ||
|
|
||
| renderWithProviders(<Agents />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText("Agent 1")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| const gridContainer = screen.getByText("Agent 1").closest('[data-slot="card"]')?.parentElement; | ||
| expect(gridContainer).toBeInTheDocument(); | ||
| expect(gridContainer).toHaveClass("grid"); | ||
| expect(gridContainer).toHaveClass("grid-cols-1"); | ||
| expect(gridContainer).toHaveClass("lg:grid-cols-2"); | ||
| expect(gridContainer).toHaveClass("2xl:grid-cols-3"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change "gateway" to "server" (moving away from using that terminology other than the product being an AI Gateway). Request applies to all copy (i18N)