Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): align connector access semantics
Miguelon Peluchon20c183c38e5a
diff --git a/control-ui/app/mcp-servers/[name]/edit/page.tsx b/control-ui/app/mcp-servers/[name]/edit/page.tsxindex 2550646dc..e9d1ca7ae 100644--- a/control-ui/app/mcp-servers/[name]/edit/page.tsx+++ b/control-ui/app/mcp-servers/[name]/edit/page.tsx@@ -37,10 +37,11 @@ import type {EgressBinding,EnvSecret,EnvSecretKeyMapping,+ HostResource,McpServerResource,} from '@lib/api'import {- contextNamesForConnector,+ hostOwnedContextNamesForConnector,mergeAccessSummaries,sortAccessPrincipals,} from '@lib/connectorAccess'@@ -118,6 +119,7 @@ export default function EditMcpServerPage() {const [egressStatus, setEgressStatus] = useState<EgressEditorStatus | null>(null)const [contextAccess, setContextAccess] = useState<ContextAccess>(EMPTY_CONTEXT_ACCESS)const [contextNames, setContextNames] = useState<string[]>([])+ const [owningAgents, setOwningAgents] = useState<ContextAccess['agents']>([])const [loadingContexts, setLoadingContexts] = useState(true)const [contextListError, setContextListError] = useState('')const [contextAccessError, setContextAccessError] = useState('')@@ -173,12 +175,25 @@ export default function EditMcpServerPage() {setLoadingContexts(true)setContextListError('')try {- const result = await getContexts()+ const [contextsResult, hostsResult] = await Promise.all([getContexts(), getHosts()])if (cancelled) return- setContextNames(contextNamesForConnector((result.items ?? []) as ContextResource[], name))+ const contexts = (contextsResult.items ?? []) as ContextResource[]+ const hosts = (hostsResult.items ?? []) as HostResource[]+ const nextContextNames = hostOwnedContextNamesForConnector(contexts, hosts, name)+ const contextNameSet = new Set(nextContextNames)+ const agentsById = new Map<string, ContextAccess['agents'][number]>()+ for (const host of hosts) {+ const contextRef = String(host.spec?.contextRef ?? '').trim()+ const id = String(host.metadata?.name ?? '').trim()+ if (!contextNameSet.has(contextRef) || !id) continue+ agentsById.set(id, { id, label: getAgentDisplayName(id, hosts) })+ }+ setContextNames(nextContextNames)+ setOwningAgents(sortAccessPrincipals([...agentsById.values()]))} catch {if (!cancelled) {setContextNames([])+ setOwningAgents([])setContextListError('Agent access data is unavailable. Try again later.')}} finally {@@ -207,42 +222,24 @@ export default function EditMcpServerPage() {// Resolve the AGENTS whose scopes carry this connector, then read their// user/team grants — the same mappings operators manage in Users &// Teams — instead of the legacy scope-centric context sub-resources.- const hostsResult = await Promise.allSettled([getHosts()])- if (cancelled) return-- const hosts = hostsResult[0].status === 'fulfilled' ? (hostsResult[0].value.items ?? []) : []- const contextNameSet = new Set(contextNames)- const owningAgents = [- ...new Set(- hosts- .map(host => {- const ref = String(host.spec?.contextRef ?? '').trim()- return contextNameSet.has(ref) ? String(host.metadata?.name ?? '') : ''- })- .filter(Boolean)- ),- ]-const agentResults = await Promise.all(- owningAgents.map(async agentName => {+ owningAgents.map(async agent => {const [usersResult, teamsResult] = await Promise.allSettled([- getAgentUsers(agentName),- getAgentTeams(agentName),+ getAgentUsers(agent.id),+ getAgentTeams(agent.id),])- return { agentName, usersResult, teamsResult }+ return { agent, usersResult, teamsResult }}))if (cancelled) return- const failed =- hostsResult[0].status === 'rejected' ||- agentResults.some(- result =>- result.usersResult.status === 'rejected' || result.teamsResult.status === 'rejected'- )+ const failed = agentResults.some(+ result =>+ result.usersResult.status === 'rejected' || result.teamsResult.status === 'rejected'+ )setContextAccess(mergeAccessSummaries(- agentResults.map(({ agentName, usersResult, teamsResult }) => ({+ agentResults.map(({ agent, usersResult, teamsResult }) => ({users:usersResult.status === 'fulfilled'? sortAccessPrincipals(@@ -261,12 +258,7 @@ export default function EditMcpServerPage() {}))): [],- agents: [- {- id: agentName,- label: getAgentDisplayName(agentName) || agentName,- },- ],+ agents: [agent],}))))@@ -281,7 +273,7 @@ export default function EditMcpServerPage() {return () => {cancelled = true}- }, [contextNames])+ }, [contextNames, owningAgents])async function handleSave(event: React.FormEvent<HTMLFormElement>) {event.preventDefault()diff --git a/control-ui/app/profile-admin/teams/new/page.tsx b/control-ui/app/profile-admin/teams/new/page.tsxindex e2269cac1..ba104ae91 100644--- a/control-ui/app/profile-admin/teams/new/page.tsx+++ b/control-ui/app/profile-admin/teams/new/page.tsx@@ -13,6 +13,7 @@ import { useToast } from '@components/Toast'import { IconTrash } from '@components/icons'import { Button, Field, TextInput } from '@components/ui'import { CONTROL_ROUTES } from '@constants/routes'+import { accessScopeLabeler } from '@lib/accessScopeLabels'import { getAgentDisplayName } from '@lib/agentName'import {addAdminTeamMember,@@ -129,37 +130,13 @@ export default function CreateTeamPage() {)// Options keep context IDs as values (the write model) but show what the// access means: the owning agent(s), else the stored display name.- const contextOptions = useMemo(- () => {- const resolveLabel = (contextId: string): string => {- const owners = hosts- .map(host => {- const ref = String(- (host.spec as { contextRef?: string } | undefined)?.contextRef || ''- ).trim()- if (ref !== contextId) return ''- return (- String((host.spec as { host?: string } | undefined)?.host || '').trim() ||- String(host.metadata?.name || '')- )- })- .filter(Boolean)- .sort((a, b) => a.localeCompare(b))- if (owners.length > 0) return owners.join(', ')- return (- contextResources- .find(item => contextIdFromResource(item as never) === contextId)- ?.spec?.displayName?.trim() || contextId- )- }- return availableContextIds.map(contextId => ({- value: contextId,- label: resolveLabel(contextId),- }))- },- // eslint-disable-next-line react-hooks/exhaustive-deps- [availableContextIds, contextResources, hosts]- )+ const contextOptions = useMemo(() => {+ const labelFor = accessScopeLabeler(contextResources, hosts)+ return availableContextIds.map(contextId => ({+ value: contextId,+ label: labelFor(contextId).label,+ }))+ }, [availableContextIds, contextResources, hosts])const agentOptions = useMemo(() =>Array.from(new Set(hosts.map(host => hostNameFromResource(host)).filter(Boolean)))diff --git a/control-ui/components/McpServerTable.tsx b/control-ui/components/McpServerTable.tsxindex 895ab115c..e2031a94c 100644--- a/control-ui/components/McpServerTable.tsx+++ b/control-ui/components/McpServerTable.tsx@@ -162,7 +162,11 @@ function ConnectorAgentsGroup({type="button"className="cu-btn cu-btn--icon cu-btn--danger-icon cu-connector-agent-access__remove"disabled={busy}- aria-label={`Remove connector ${connectorName} from agent ${agent.label}`}+ aria-label={+ binding.agents.length > 1+ ? `Remove connector ${connectorName} from agents ${binding.agents.map(a => a.label).join(', ')}`+ : `Remove connector ${connectorName} from agent ${agent.label}`+ }title={binding.agents.length > 1? `Remove from ${binding.agents.map(a => a.label).join(', ')}`diff --git a/control-ui/components/__tests__/ConnectorEditContext.test.tsx b/control-ui/components/__tests__/ConnectorEditContext.test.tsxindex 245556e98..f4421e9d3 100644--- a/control-ui/components/__tests__/ConnectorEditContext.test.tsx+++ b/control-ui/components/__tests__/ConnectorEditContext.test.tsx@@ -42,6 +42,8 @@ vi.mock('../../lib/api', async importOriginal => {getContextTeams: vi.fn(),getContextUsers: vi.fn(),getHosts: vi.fn(),+ getAgentTeams: vi.fn(),+ getAgentUsers: vi.fn(),getMcpServer: vi.fn(),updateMcpServer: vi.fn(),}@@ -67,6 +69,7 @@ describe('connector edit agent access', () => {}),]))+ vi.mocked(api.getHosts).mockResolvedValue({ items: [] })render(<EditMcpServerPage />)@@ -78,7 +81,81 @@ describe('connector edit agent access', () => {await waitFor(() => expect(api.getMcpServer).toHaveBeenCalledWith('search'))expect(api.getContextUsers).not.toHaveBeenCalled()expect(api.getContextTeams).not.toHaveBeenCalled()- expect(api.getHosts).not.toHaveBeenCalled()+ expect(api.getHosts).toHaveBeenCalled()+ })++ it('hides private connector scopes that are not owned by an agent', async () => {+ vi.mocked(api.getMcpServer).mockResolvedValue({+ metadata: { name: 'search' },+ spec: { image: 'example/search:latest' },+ })+ vi.mocked(api.getContexts).mockResolvedValue(+ buildContextList([+ buildContextResource({+ metadata: { name: 'install-private', resourceVersion: 'rv-1' },+ spec: { mcpServers: ['search'] },+ }),+ buildContextResource({+ metadata: { name: 'recipe-private', resourceVersion: 'rv-2' },+ spec: { mcpServers: ['search'] },+ }),+ ])+ )+ vi.mocked(api.getHosts).mockResolvedValue({ items: [] })++ render(<EditMcpServerPage />)++ expect(+ await screen.findByText('No agents have access to this connector yet.')+ ).toBeInTheDocument()+ expect(screen.queryByRole('heading', { name: 'Teams' })).not.toBeInTheDocument()+ expect(screen.queryByRole('heading', { name: 'Users' })).not.toBeInTheDocument()+ expect(api.getAgentUsers).not.toHaveBeenCalled()+ expect(api.getAgentTeams).not.toHaveBeenCalled()+ })++ it('shows access inherited through a host-owned connector scope', async () => {+ vi.mocked(api.getMcpServer).mockResolvedValue({+ metadata: { name: 'search' },+ spec: { image: 'example/search:latest' },+ })+ vi.mocked(api.getContexts).mockResolvedValue(+ buildContextList([+ buildContextResource({+ metadata: { name: 'agent-scope', resourceVersion: 'rv-1' },+ spec: { mcpServers: ['search'] },+ }),+ ])+ )+ vi.mocked(api.getHosts).mockResolvedValue({+ items: [+ {+ metadata: { name: 'agent-alpha' },+ spec: { host: 'Alpha', contextRef: 'agent-scope' },+ },+ ],+ })+ vi.mocked(api.getAgentUsers).mockResolvedValue({+ items: [+ {+ id: 'user-1',+ email: '[email protected]',+ name: 'Ada',+ displayName: 'Ada Lovelace',+ },+ ],+ })+ vi.mocked(api.getAgentTeams).mockResolvedValue({+ items: [{ id: 'team-1', name: 'Research' }],+ })++ render(<EditMcpServerPage />)++ expect(await screen.findByText('Alpha')).toBeInTheDocument()+ expect(screen.getByText('Ada Lovelace')).toBeInTheDocument()+ expect(screen.getByText('Research')).toBeInTheDocument()+ expect(api.getAgentUsers).toHaveBeenCalledWith('agent-alpha')+ expect(api.getAgentTeams).toHaveBeenCalledWith('agent-alpha')})it('keeps credentials and egress usable when the agent access list is unavailable', async () => {diff --git a/control-ui/components/__tests__/McpServerTable.test.tsx b/control-ui/components/__tests__/McpServerTable.test.tsxindex 794b0e08c..816acfb48 100644--- a/control-ui/components/__tests__/McpServerTable.test.tsx+++ b/control-ui/components/__tests__/McpServerTable.test.tsx@@ -458,6 +458,31 @@ describe('McpServerTable — agent membership', () => {)})+ it('names shared-scope removal buttons with every affected agent', () => {+ const sharedBinding: ConnectorAgentBinding = {+ contextRef: 'ctx-shared',+ agents: [+ { id: 'agent-alpha', label: 'Alpha' },+ { id: 'agent-beta', label: 'Beta' },+ ],+ }+ render(+ <McpServerTable+ items={[makeItem({ name: 'airtable-server' })]}+ agentBindingsByConnectorName={{ 'airtable-server': [sharedBinding] }}+ onRemoveFromAgents={vi.fn().mockResolvedValue(undefined)}+ />+ )++ fireEvent.click(screen.getByRole('button', { name: 'Expand connector airtable-server' }))++ expect(+ screen.getAllByRole('button', {+ name: 'Remove connector airtable-server from agents Alpha, Beta',+ })+ ).toHaveLength(2)+ })+it('uses the agent selection modal to give more agents access to the connector', async () => {const onAddToAgents = vi.fn().mockResolvedValue(undefined)const items = [makeItem({ name: 'airtable-server' })]diff --git a/control-ui/lib/__tests__/connectorAccess.test.ts b/control-ui/lib/__tests__/connectorAccess.test.tsindex e932ef823..f26273584 100644--- a/control-ui/lib/__tests__/connectorAccess.test.ts+++ b/control-ui/lib/__tests__/connectorAccess.test.ts@@ -4,6 +4,7 @@ import type { ConnectorAccessSummary } from '../../components/McpServerTable.typimport type { ContextResource } from '../api'import {contextNamesForConnector,+ hostOwnedContextNamesForConnector,mergeAccessSummaries,sortAccessPrincipals,} from '../connectorAccess'@@ -247,3 +248,28 @@ describe('contextNamesForConnector invariants', () => {)})})++describe('hostOwnedContextNamesForConnector', () => {+ it('excludes connector scopes that have no owning host', () => {+ const contexts: ContextResource[] = [+ {+ metadata: { name: 'agent-scope' },+ spec: { contextId: 'agent-scope', mcpServers: ['search'] },+ },+ {+ metadata: { name: 'install-private' },+ spec: { contextId: 'install-private', mcpServers: ['search'] },+ },+ {+ metadata: { name: 'recipe-private' },+ spec: { contextId: 'recipe-private', mcpServers: ['search'] },+ },+ ]+ const hosts = [+ { metadata: { name: 'agent-alpha' }, spec: { contextRef: 'agent-scope' } },+ { metadata: { name: 'agent-with-other-connector' }, spec: { contextRef: 'other-scope' } },+ ]++ expect(hostOwnedContextNamesForConnector(contexts, hosts, 'search')).toEqual(['agent-scope'])+ })+})diff --git a/control-ui/lib/connectorAccess.ts b/control-ui/lib/connectorAccess.tsindex 56da1794f..bbd769b82 100644--- a/control-ui/lib/connectorAccess.ts+++ b/control-ui/lib/connectorAccess.ts@@ -2,7 +2,7 @@ import type {ConnectorAccessPrincipal,ConnectorAccessSummary,} from '../components/McpServerTable.types'-import type { ContextResource } from './api'+import type { ContextResource, HostResource } from './api'function comparePrincipals(left: ConnectorAccessPrincipal,@@ -49,3 +49,24 @@ export function contextNamesForConnector()).sort((left, right) => left.localeCompare(right))}++/**+ * Returns only connector scopes owned by at least one Host. Per-install,+ * workflow-recipe, and other private scopes are intentionally excluded from+ * operator-facing agent access views.+ */+export function hostOwnedContextNamesForConnector(+ contexts: readonly ContextResource[],+ hosts: readonly HostResource[],+ connectorName: string+): string[] {+ const hostContextRefs = new Set(+ hosts+ .filter(host => String(host.metadata?.name ?? '').trim())+ .map(host => String(host.spec?.contextRef ?? '').trim())+ .filter(Boolean)+ )+ return contextNamesForConnector(contexts, connectorName).filter(contextName =>+ hostContextRefs.has(contextName)+ )+}diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex afb8dde75..d93864f72 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.486",+ "version": "0.1.488","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.486",+ "version": "0.1.488","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex f9619f44b..f05b1b829 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.487",+ "version": "0.1.488","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",