-
Notifications
You must be signed in to change notification settings - Fork 48
(feat-redraw)Prepare Icon and other node data resolver for dynamic graphs #656
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f84bfdc
feat(graph): topology node icon resolver
delthazor 782add9
feat(graph): dynamic renderer parity for groups, MCP and A2A
delthazor fbd0bf9
refactor(graph): centralize topology node label predicates
delthazor 47fbfe6
Enums for IconKind
delthazor 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
150 changes: 150 additions & 0 deletions
150
coffeeAGNTCY/coffee_agents/lungo/frontend/src/utils/topologyNodeIcons.test.tsx
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,150 @@ | ||
| /** | ||
| * Copyright AGNTCY Contributors (https://github.com/agntcy) | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| **/ | ||
|
|
||
| import { isValidElement } from "react" | ||
| import { describe, expect, it } from "vitest" | ||
| import { | ||
| resolveTopologyNodeIcon, | ||
| topologyNodeIconKind, | ||
| type TopologyNodeIconInput, | ||
| type TopologyNodeIconKind, | ||
| } from "@/utils/topologyNodeIcons" | ||
|
|
||
| describe("topologyNodeIconKind", () => { | ||
| it.each<{ | ||
| caseName: string | ||
| input: TopologyNodeIconInput | ||
| expected: TopologyNodeIconKind | ||
| }>([ | ||
| { | ||
| caseName: "slug wins over labels (auction supervisor)", | ||
| input: { | ||
| directoryAgentSlug: "auction-supervisor-agent", | ||
| label1: "Weather", | ||
| label2: "MCP Server", | ||
| }, | ||
| expected: "supervisor", | ||
| }, | ||
| { | ||
| caseName: "logistics supervisor slug -> supervisor", | ||
| input: { directoryAgentSlug: "logistics-supervisor-agent" }, | ||
| expected: "supervisor", | ||
| }, | ||
| { | ||
| caseName: "recruiter slug -> recruiter", | ||
| input: { directoryAgentSlug: "recruiter" }, | ||
| expected: "recruiter", | ||
| }, | ||
| { | ||
| caseName: "coffee farm slug -> farm", | ||
| input: { directoryAgentSlug: "colombia-coffee-farm" }, | ||
| expected: "farm", | ||
| }, | ||
| { | ||
| caseName: "tatooine farm slug -> farm", | ||
| input: { directoryAgentSlug: "tatooine-farm-agent" }, | ||
| expected: "farm", | ||
| }, | ||
| { | ||
| caseName: "weather mcp slug -> weatherMcp", | ||
| input: { directoryAgentSlug: "weather-mcp-server" }, | ||
| expected: "weatherMcp", | ||
| }, | ||
| { | ||
| caseName: "payment mcp slug -> paymentMcp", | ||
| input: { directoryAgentSlug: "payment-mcp-server" }, | ||
| expected: "paymentMcp", | ||
| }, | ||
| { | ||
| caseName: "shipping slug -> shipping", | ||
| input: { directoryAgentSlug: "shipping-agent" }, | ||
| expected: "shipping", | ||
| }, | ||
| { | ||
| caseName: "accountant slug -> accountant", | ||
| input: { directoryAgentSlug: "accountant-agent" }, | ||
| expected: "accountant", | ||
| }, | ||
| { | ||
| caseName: "unknown slug falls back to labels", | ||
| input: { directoryAgentSlug: "mystery", label1: "Shipper" }, | ||
| expected: "shipping", | ||
| }, | ||
| { | ||
| caseName: "weather mcp by labels", | ||
| input: { label1: "Weather", label2: "MCP Server" }, | ||
| expected: "weatherMcp", | ||
| }, | ||
| { | ||
| caseName: "payment mcp by labels", | ||
| input: { label1: "Payment", label2: "MCP Server" }, | ||
| expected: "paymentMcp", | ||
| }, | ||
| { | ||
| caseName: "generic mcp by labels -> default", | ||
| input: { label1: "Inventory", label2: "MCP Server" }, | ||
| expected: "default", | ||
| }, | ||
| { | ||
| caseName: "agentic recruiter by labels", | ||
| input: { | ||
| label1: "Agentic Recruiter", | ||
| label2: "Discovery and delegation", | ||
| }, | ||
| expected: "recruiter", | ||
| }, | ||
| { | ||
| caseName: "agntcy agent directory by labels", | ||
| input: { label1: "Directory", label2: "AGNTCY Agent Directory" }, | ||
| expected: "directory", | ||
| }, | ||
| { | ||
| caseName: "coffee farm by labels", | ||
| input: { label1: "Brazil", label2: "Coffee Farm Agent" }, | ||
| expected: "farm", | ||
| }, | ||
| { | ||
| caseName: "auction agent by labels", | ||
| input: { label1: "Auction Agent", label2: "Buyer" }, | ||
| expected: "supervisor", | ||
| }, | ||
| { | ||
| caseName: "logistics buyer by labels", | ||
| input: { label1: "Buyer", label2: "Logistics Agent" }, | ||
| expected: "supervisor", | ||
| }, | ||
| { | ||
| caseName: "shipper by labels", | ||
| input: { label1: "Shipper", label2: "Shipper Agent" }, | ||
| expected: "shipping", | ||
| }, | ||
| { | ||
| caseName: "accountant by labels", | ||
| input: { label1: "Accountant", label2: "Accountant Agent" }, | ||
| expected: "accountant", | ||
| }, | ||
| { | ||
| caseName: "unknown -> default", | ||
| input: { label1: "Mystery", label2: "Thing" }, | ||
| expected: "default", | ||
| }, | ||
| { | ||
| caseName: "empty input -> default", | ||
| input: {}, | ||
| expected: "default", | ||
| }, | ||
| ])("$caseName", ({ input, expected }) => { | ||
| expect(topologyNodeIconKind(input)).toBe(expected) | ||
| }) | ||
| }) | ||
|
|
||
| describe("resolveTopologyNodeIcon", () => { | ||
| it("returns a renderable element for every input", () => { | ||
| expect(isValidElement(resolveTopologyNodeIcon({ label1: "Shipper" }))).toBe( | ||
| true, | ||
| ) | ||
| expect(isValidElement(resolveTopologyNodeIcon({}))).toBe(true) | ||
| }) | ||
| }) |
137 changes: 137 additions & 0 deletions
137
coffeeAGNTCY/coffee_agents/lungo/frontend/src/utils/topologyNodeIcons.tsx
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,137 @@ | ||
| /** | ||
| * Copyright AGNTCY Contributors (https://github.com/agntcy) | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * ----------------------------------------------------------------------------- | ||
| * Presentation-only icon resolver for dynamically rendered topology nodes. | ||
| * | ||
| * Backend topology carries no icon field, so the dynamic renderer derives a | ||
| * branded icon from a node's directory slug (preferred) or its split label, | ||
| * using loose substring matching rather than an exhaustive agent map. This is | ||
| * presentation, not data: if the backend later supplies an icon/type hint, key | ||
| * off that. | ||
| * ----------------------------------------------------------------------------- | ||
| */ | ||
|
|
||
| import React from "react" | ||
| import Air from "@mui/icons-material/Air" | ||
| import Calculate from "@mui/icons-material/Calculate" | ||
| import LocalShipping from "@mui/icons-material/LocalShipping" | ||
| import SmartToy from "@mui/icons-material/SmartToy" | ||
| import { GraphDiscoveryAssetImg } from "@/utils/GraphDiscoveryAssetImg" | ||
| import { | ||
| isDirectoryLabel, | ||
| isRecruiterLabel, | ||
| } from "@/utils/agenticTopologyIdentityUiMap" | ||
| import supervisorIcon from "@/assets/supervisor.png" | ||
| import farmAgentIcon from "@/assets/Grader-Agent.png" | ||
|
|
||
| export interface TopologyNodeIconInput { | ||
| label1?: string | ||
| label2?: string | ||
| directoryAgentSlug?: string | ||
| } | ||
|
|
||
| export type TopologyNodeIconKind = | ||
| | "supervisor" | ||
| | "recruiter" | ||
| | "directory" | ||
| | "farm" | ||
| | "weatherMcp" | ||
| | "paymentMcp" | ||
| | "shipping" | ||
| | "accountant" | ||
| | "default" | ||
|
|
||
| function normalize(value: string | undefined): string { | ||
| return typeof value === "string" ? value.trim().toLowerCase() : "" | ||
| } | ||
|
|
||
| function iconKindFromSlug(slug: string): TopologyNodeIconKind | null { | ||
| if (slug.includes("supervisor")) return "supervisor" | ||
| if (slug.includes("recruiter")) return "recruiter" | ||
| if (slug.includes("farm")) return "farm" | ||
| if (slug.includes("weather")) return "weatherMcp" | ||
| if (slug.includes("payment")) return "paymentMcp" | ||
| if (slug.includes("shipping")) return "shipping" | ||
| if (slug.includes("accountant")) return "accountant" | ||
| return null | ||
| } | ||
|
|
||
| function iconKindFromLabels( | ||
| label1: string, | ||
| label2: string, | ||
| ): TopologyNodeIconKind { | ||
| const combined = `${label1} ${label2}`.trim() | ||
|
|
||
| if (label2 === "mcp server" || label1.endsWith("mcp server")) { | ||
| if (label1.includes("weather")) return "weatherMcp" | ||
|
delthazor marked this conversation as resolved.
Outdated
|
||
| if (label1.includes("payment")) return "paymentMcp" | ||
| return "default" | ||
| } | ||
|
|
||
| if (isRecruiterLabel(combined)) { | ||
| return "recruiter" | ||
| } | ||
|
|
||
| if (label1 === "directory" || isDirectoryLabel(combined)) { | ||
| return "directory" | ||
| } | ||
|
|
||
| if (label2.includes("coffee farm")) return "farm" | ||
| if (label1 === "shipper") return "shipping" | ||
| if (label1 === "accountant") return "accountant" | ||
|
|
||
| if ( | ||
| label1 === "auction agent" || | ||
| (label1 === "auction" && label2.includes("agent")) || | ||
| label1 === "buyer" || | ||
| label2.includes("buyer") || | ||
| label2.includes("logistics agent") || | ||
| combined === "logistics group" | ||
| ) { | ||
| return "supervisor" | ||
| } | ||
|
|
||
| return "default" | ||
| } | ||
|
|
||
| export function topologyNodeIconKind( | ||
| input: TopologyNodeIconInput, | ||
| ): TopologyNodeIconKind { | ||
| const slug = normalize(input.directoryAgentSlug) | ||
| if (slug) { | ||
| const bySlug = iconKindFromSlug(slug) | ||
| if (bySlug) return bySlug | ||
| } | ||
| return iconKindFromLabels(normalize(input.label1), normalize(input.label2)) | ||
| } | ||
|
|
||
| function brandedImg(src: string, alt: string): React.ReactNode { | ||
| return <GraphDiscoveryAssetImg src={src} alt={alt} invertInDarkMode /> | ||
| } | ||
|
|
||
| export function resolveTopologyNodeIcon( | ||
| input: TopologyNodeIconInput, | ||
| ): React.ReactNode { | ||
| switch (topologyNodeIconKind(input)) { | ||
| case "supervisor": | ||
| return brandedImg(supervisorIcon, "Supervisor Icon") | ||
| case "recruiter": | ||
| return brandedImg(supervisorIcon, "Recruiter Icon") | ||
| case "directory": | ||
| return brandedImg(supervisorIcon, "Directory Icon") | ||
| case "farm": | ||
| return brandedImg(farmAgentIcon, "Farm Agent Icon") | ||
| case "weatherMcp": | ||
| return <Air aria-hidden /> | ||
| case "paymentMcp": | ||
| return <Calculate aria-hidden /> | ||
| case "shipping": | ||
| return <LocalShipping aria-hidden /> | ||
| case "accountant": | ||
| return <Calculate aria-hidden /> | ||
| default: | ||
| return <SmartToy aria-hidden /> | ||
| } | ||
| } | ||
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.