Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

adapt(control-ui): re-graft in-place agent rename onto dev's host-detail tabs

Diego Zacariasdcd3015a85fa
diff --git a/control-ui/app/hosts/[name]/page.tsx b/control-ui/app/hosts/[name]/page.tsx
index ca656ac01..f1f528128 100644
--- a/control-ui/app/hosts/[name]/page.tsx
+++ b/control-ui/app/hosts/[name]/page.tsx
@@ -13,18 +13,7 @@ import { HostIdentityTab } from '../../../components/HostIdentityTab'
import { LlmProviderConfig } from '../../../components/LlmProviderConfig'
import { IconRobot } from '../../../components/Sidebar/icons'
import { IconCheck, IconPencil, IconX } from '../../../components/icons'
-import {
- apiGet,
- apiSend,
- getAdminTeamAgents,
- getAdminUserAgents,
- getAgentTeams,
- getAgentUsers,
- getHost,
- getHostDetailBundle,
- updateAdminTeamAgents,
- updateAdminUserAgents,
-} from '../../../lib/api'
+import { apiSend, getHost, getHostDetailBundle } from '../../../lib/api'
import { useLlmAllowedModels } from '../../../lib/hooks/useLlmAllowedModels'
import { FIRST_PARTY_CHANNEL_WORKFLOW_CONTROL_SCOPES } from '../../../lib/hostWorkflowControl'
import {
@@ -45,7 +34,7 @@ import {
validateLlmPolicy,
validateLlmSecretData,
} from '../../../lib/llm'
-import type { ChannelResource, HostTab } from './types'
+import type { HostTab } from './types'
const TAB_LABELS: Record<HostTab, string> = {
details: 'Overview',
@@ -151,7 +140,6 @@ export default function HostDetailsPage() {
const [availableContexts, setAvailableContexts] = useState<string[]>([])
const [availableSecrets, setAvailableSecrets] = useState<string[]>([])
- const hasPendingRename = hostNameDraft.trim() && hostNameDraft.trim() !== routeName
const providerModelOptions = useMemo(
() => getModelOptions(allowedCatalog, providerDraft),
[allowedCatalog, providerDraft]
@@ -365,155 +353,6 @@ export default function HostDetailsPage() {
: {}),
}
- if (nextHostName !== routeName) {
- let createdNewHost = false
- const updatedChannels: Array<{ name: string; previousSpec: ChannelResource['spec'] }> = []
- const previousUserAgentNamesById = new Map<string, string[]>()
- const previousTeamAgentNamesById = new Map<string, string[]>()
- try {
- await apiSend('POST', '/api/v1/admin/hosts', {
- metadata: { name: nextHostName },
- spec: nextSpec,
- })
- createdNewHost = true
-
- const channels = (await apiGet('/api/v1/admin/communication-channels')) as {
- items?: ChannelResource[]
- }
- for (const channel of channels.items || []) {
- if (String(channel.spec?.hostRef || '').trim() !== routeName) continue
- const channelName = String(channel.metadata?.name || '').trim()
- if (!channelName) continue
- await apiSend(
- 'PUT',
- `/api/v1/admin/communication-channels/${encodeURIComponent(channelName)}`,
- {
- spec: {
- ...(channel.spec || {}),
- hostRef: nextHostName,
- },
- }
- )
- updatedChannels.push({ name: channelName, previousSpec: channel.spec })
- }
-
- // Fetch the freshest user/team access lists so a grant/revoke done
- // in the Access tab right before this rename still applies here.
- const [usersAccessSnapshot, teamsAccessSnapshot] = await Promise.all([
- getAgentUsers(routeName),
- getAgentTeams(routeName),
- ])
- const renameUsersWithAccess = Array.isArray(usersAccessSnapshot.items)
- ? usersAccessSnapshot.items
- : []
- const renameTeamsWithAccess = Array.isArray(teamsAccessSnapshot.items)
- ? teamsAccessSnapshot.items
- : []
-
- for (const user of renameUsersWithAccess) {
- const userAccess = await getAdminUserAgents(user.id)
- const previousAgentNames = (userAccess.agentNames || [])
- .map(String)
- .map(v => v.trim())
- .filter(Boolean)
- previousUserAgentNamesById.set(user.id, previousAgentNames)
- const nextAgentNames = Array.from(
- new Set(previousAgentNames.map(name => (name === routeName ? nextHostName : name)))
- )
- await updateAdminUserAgents(user.id, nextAgentNames, [
- ...(userAccess.agentNames || []),
- ...(userAccess.deletedAgentNames || []),
- ])
- }
-
- for (const team of renameTeamsWithAccess) {
- const teamAccess = await getAdminTeamAgents(team.id)
- const previousAgentNames = (teamAccess.agentNames || [])
- .map(String)
- .map(v => v.trim())
- .filter(Boolean)
- previousTeamAgentNamesById.set(team.id, previousAgentNames)
- const nextAgentNames = Array.from(
- new Set(previousAgentNames.map(name => (name === routeName ? nextHostName : name)))
- )
- await updateAdminTeamAgents(team.id, nextAgentNames, [
- ...(teamAccess.agentNames || []),
- ...(teamAccess.deletedAgentNames || []),
- ])
- }
-
- await apiSend('DELETE', `/api/v1/admin/hosts/${encodeURIComponent(routeName)}`)
- showToast('Agent renamed and updated.', { tone: 'success' })
- router.replace(CONTROL_ROUTES.agents.detail(nextHostName))
- return true
- } catch (renameError) {
- const rollbackErrors: string[] = []
- if (createdNewHost) {
- for (const [teamId, previousAgentNames] of Array.from(
- previousTeamAgentNamesById.entries()
- ).reverse()) {
- try {
- const current = await getAdminTeamAgents(teamId)
- await updateAdminTeamAgents(teamId, previousAgentNames, [
- ...(current.agentNames || []),
- ...(current.deletedAgentNames || []),
- ])
- } catch (rollbackError) {
- const rollbackMessage =
- rollbackError instanceof Error ? rollbackError.message : 'unknown rollback error'
- rollbackErrors.push(`team ${teamId}: ${rollbackMessage}`)
- }
- }
- for (const [userId, previousAgentNames] of Array.from(
- previousUserAgentNamesById.entries()
- ).reverse()) {
- try {
- const current = await getAdminUserAgents(userId)
- await updateAdminUserAgents(userId, previousAgentNames, [
- ...(current.agentNames || []),
- ...(current.deletedAgentNames || []),
- ])
- } catch (rollbackError) {
- const rollbackMessage =
- rollbackError instanceof Error ? rollbackError.message : 'unknown rollback error'
- rollbackErrors.push(`member ${userId}: ${rollbackMessage}`)
- }
- }
- for (const channel of [...updatedChannels].reverse()) {
- try {
- await apiSend(
- 'PUT',
- `/api/v1/admin/communication-channels/${encodeURIComponent(channel.name)}`,
- {
- spec: {
- ...(channel.previousSpec || {}),
- hostRef: routeName,
- },
- }
- )
- } catch (rollbackError) {
- const rollbackMessage =
- rollbackError instanceof Error ? rollbackError.message : 'unknown rollback error'
- rollbackErrors.push(`channel ${channel.name}: ${rollbackMessage}`)
- }
- }
- try {
- await apiSend('DELETE', `/api/v1/admin/hosts/${encodeURIComponent(nextHostName)}`)
- } catch (rollbackError) {
- const rollbackMessage =
- rollbackError instanceof Error ? rollbackError.message : 'unknown rollback error'
- rollbackErrors.push(`agent ${nextHostName}: ${rollbackMessage}`)
- }
- }
- if (rollbackErrors.length > 0) {
- const renameMessage =
- renameError instanceof Error ? renameError.message : 'Failed to rename agent'
- throw new Error(`${renameMessage} (rollback issues: ${rollbackErrors.join('; ')})`)
- }
- throw renameError
- }
- }
-
const formResourceVersion = formResourceVersionRef.current
await apiSend('PUT', `/api/v1/admin/hosts/${encodeURIComponent(routeName)}`, {
// AP-6: carry the resourceVersion captured at form load so the API
@@ -749,13 +588,6 @@ export default function HostDetailsPage() {
backLabel="Back to agents"
error={error}
icon={<IconRobot />}
- notice={
- hasPendingRename ? (
- <div className="cu-banner cu-banner--warning">
- Save agent rename before changing user or team access.
- </div>
- ) : null
- }
onBack={() => router.push(CONTROL_ROUTES.agents.root)}
onTabChange={selectTab}
subtitle="Configuration and access for this agent."
@@ -837,16 +669,29 @@ export default function HostDetailsPage() {
<div className="cu-form-stack">
<div className="cu-field">
<label htmlFor="host-name">Name</label>
+ {editingOverview ? (
+ <>
+ <input id="host-name" value={hostNameDraft} readOnly />
+ <span className="cu-field__hint">
+ This is the agent identifier, not editable.
+ </span>
+ </>
+ ) : (
+ <div className="cu-field__readonly">{hostNameDraft}</div>
+ )}
+ </div>
+ <div className="cu-field">
+ <label htmlFor="host-display">Display name</label>
{editingOverview ? (
<input
- id="host-name"
- value={hostNameDraft}
- onChange={e => setHostNameDraft(e.target.value)}
+ id="host-display"
+ value={hostDisplayDraft}
+ onChange={e => setHostDisplayDraft(e.target.value)}
disabled={busy}
autoFocus
/>
) : (
- <div className="cu-field__readonly">{hostNameDraft}</div>
+ <div className="cu-field__readonly">{hostDisplayDraft}</div>
)}
</div>
<div className="cu-field" style={{ marginBottom: 0 }}>
@@ -1175,9 +1020,7 @@ export default function HostDetailsPage() {
{activeTab === 'identity' && <HostIdentityTab hostName={routeName} />}
- {activeTab === 'access' && (
- <HostAccessTab hasPendingRename={hasPendingRename} hostName={routeName} />
- )}
+ {activeTab === 'access' && <HostAccessTab hostName={routeName} />}
</div>
{showDeleteAgentConfirm && (
<div
diff --git a/control-ui/app/hosts/[name]/types.ts b/control-ui/app/hosts/[name]/types.ts
index 60fe27328..c5bddc7e7 100644
--- a/control-ui/app/hosts/[name]/types.ts
+++ b/control-ui/app/hosts/[name]/types.ts
@@ -1,10 +1,5 @@
import type { HostTab } from '@constants/hostDetails'
-export type ChannelResource = {
- metadata?: { name?: string; namespace?: string }
- spec?: Record<string, unknown> & { hostRef?: string }
-}
-
export type SecretResource = {
name?: string
metadata?: { name?: string }
diff --git a/control-ui/components/HostAccessTab/index.tsx b/control-ui/components/HostAccessTab/index.tsx
index 682a61b05..8e4a1e9e0 100644
--- a/control-ui/components/HostAccessTab/index.tsx
+++ b/control-ui/components/HostAccessTab/index.tsx
@@ -31,16 +31,12 @@ const ACCESS_SUB_TABS: { key: AccessSubTab; label: string }[] = [
{ key: 'teams', label: 'Teams' },
]
-export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccessTabProps) {
+export function HostAccessTab({ hostName }: HostAccessTabProps) {
const router = useRouter()
const { confirm, confirmDialog } = useConfirmDialog()
const { showToast } = useToast()
const mountedRef = useRef(true)
const loadRequestId = useRef(0)
- // Guarded by the parent when there's an unsaved rename. Surface a single
- // derived flag so the grant/revoke handlers, the Add buttons, the modal
- // inputs, and the confirm/submit controls all stay in sync.
- const mutationDisabled = hasPendingRename
const [subTab, setSubTab] = useState<AccessSubTab>('members')
const [allUsers, setAllUsers] = useState<AccessUserRow[]>([])
@@ -134,7 +130,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
async function grantUserAccess() {
if (selectedUserIdsToGrant.length === 0) return
- if (mutationDisabled) return
setBusy(true)
setError('')
try {
@@ -168,7 +163,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
}
async function revokeUserAccess(userId: string) {
- if (mutationDisabled) return
const user = usersWithAccess.find(item => item.id === userId)
const shouldRevoke = await confirm({
title: 'Revoke Member Access',
@@ -203,7 +197,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
async function grantTeamAccess() {
if (selectedTeamIdsToGrant.length === 0) return
- if (mutationDisabled) return
setBusy(true)
setError('')
try {
@@ -237,7 +230,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
}
async function revokeTeamAccess(teamId: string) {
- if (mutationDisabled) return
const team = teamsWithAccess.find(item => item.id === teamId)
const shouldRevoke = await confirm({
title: 'Revoke Team Access',
@@ -282,12 +274,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
</div>
) : null}
- {mutationDisabled ? (
- <div className="cu-banner cu-banner--warning" style={{ marginBottom: '0.75rem' }}>
- Save the agent rename before changing member or team access.
- </div>
- ) : null}
-
<TabBar<AccessSubTab>
activeValue={subTab}
ariaLabel="Access type"
@@ -304,7 +290,7 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
onClick={() => setShowAddUser(true)}
- disabled={busy || mutationDisabled}
+ disabled={busy}
>
Add member
</button>
@@ -313,7 +299,7 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
onClick={() => setShowAddTeam(true)}
- disabled={busy || mutationDisabled}
+ disabled={busy}
>
Add team
</button>
@@ -366,7 +352,7 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
type="button"
className="cu-btn cu-btn--icon cu-btn--danger-icon"
onClick={() => void revokeUserAccess(user.id)}
- disabled={busy || mutationDisabled}
+ disabled={busy}
title="Revoke"
aria-label="Revoke member access"
>
@@ -401,7 +387,7 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
type="button"
className="cu-btn cu-btn--icon cu-btn--danger-icon"
onClick={() => void revokeTeamAccess(team.id)}
- disabled={busy || mutationDisabled}
+ disabled={busy}
title="Revoke"
aria-label="Revoke team access"
>
@@ -420,7 +406,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
{showAddUser ? (
<AccessGrantModal
busy={busy}
- disabled={mutationDisabled}
emptyLabel="No available members."
id="agent-member-picker"
label="Members"
@@ -444,7 +429,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
{showAddTeam ? (
<AccessGrantModal
busy={busy}
- disabled={mutationDisabled}
emptyLabel="No available teams."
id="agent-team-picker"
label="Teams"
@@ -472,7 +456,6 @@ export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccess
type AccessGrantModalProps = {
busy: boolean
- disabled?: boolean
emptyLabel: string
id: string
label: string
@@ -491,7 +474,6 @@ type AccessGrantModalProps = {
function AccessGrantModal({
busy,
- disabled = false,
emptyLabel,
id,
label,
@@ -507,7 +489,7 @@ function AccessGrantModal({
titleId,
value,
}: AccessGrantModalProps) {
- const blocked = busy || disabled
+ const blocked = busy
return (
<div
style={{
@@ -546,12 +528,6 @@ function AccessGrantModal({
</button>
</div>
- {disabled ? (
- <p className="cu-banner cu-banner--warning" role="alert">
- Save the agent rename before changing member or team access.
- </p>
- ) : null}
-
<div className="cu-field">
<label htmlFor={id}>{label}</label>
<SelectionDropdown
diff --git a/control-ui/components/HostAccessTab/types.ts b/control-ui/components/HostAccessTab/types.ts
index bc4e8b5a6..1d1f4247d 100644
--- a/control-ui/components/HostAccessTab/types.ts
+++ b/control-ui/components/HostAccessTab/types.ts
@@ -17,10 +17,5 @@ export type AccessTeamDirectoryRow = AccessTeamRow & {
}
export type HostAccessTabProps = {
- // True when the parent has a pending rename. Mirrors the
- // `hasPendingRename` from the host detail page so this extracted tab can
- // honour the "Save agent rename before changing user or team access"
- // warning without having to thread extra state through the parent.
- hasPendingRename?: boolean
hostName: string
}
diff --git a/control-ui/components/__tests__/HostAccessTab.test.tsx b/control-ui/components/__tests__/HostAccessTab.test.tsx
index 143df6efe..4c141216d 100644
--- a/control-ui/components/__tests__/HostAccessTab.test.tsx
+++ b/control-ui/components/__tests__/HostAccessTab.test.tsx
@@ -1,8 +1,8 @@
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render as rtlRender, screen, waitFor } from '@testing-library/react'
-import { HostAccessTab } from '../HostAccessTab'
import * as api from '@lib/api'
+import { HostAccessTab } from '../HostAccessTab'
import { ToastProvider } from '../Toast'
const replaceMock = vi.fn()
@@ -76,7 +76,9 @@ describe('HostAccessTab — extracted access behavior', () => {
await waitFor(() => {
expect(screen.getByText('Alice')).toBeInTheDocument()
})
- expect(screen.getByText('Grant or revoke which members can use this agent.')).toBeInTheDocument()
+ expect(
+ screen.getByText('Grant or revoke which members can use this agent.')
+ ).toBeInTheDocument()
expect(screen.getByRole('button', { name: /Add member/i })).toBeEnabled()
})
@@ -88,32 +90,14 @@ describe('HostAccessTab — extracted access behavior', () => {
fireEvent.click(screen.getByRole('tab', { name: 'Teams' }))
await waitFor(() => {
- expect(screen.getByText('Grant or revoke team-level access to this agent.')).toBeInTheDocument()
+ expect(
+ screen.getByText('Grant or revoke team-level access to this agent.')
+ ).toBeInTheDocument()
})
expect(screen.getByRole('button', { name: /Add team/i })).toBeEnabled()
expect(screen.getByText('No teams have access yet.')).toBeInTheDocument()
})
- it('disables every mutation control when a rename is pending', async () => {
- render(<HostAccessTab hasPendingRename hostName="foo" />)
-
- await waitFor(() => {
- expect(screen.getByText('Alice')).toBeInTheDocument()
- })
-
- // Banner explaining the gate is rendered above the section.
- expect(
- screen.getByText(/Save the agent rename before changing member or team access/i)
- ).toBeInTheDocument()
-
- expect(screen.getByRole('button', { name: /Add member/i })).toBeDisabled()
- expect(screen.getByRole('button', { name: /Revoke member access/i })).toBeDisabled()
-
- // Teams sub-tab is gated too.
- fireEvent.click(screen.getByRole('tab', { name: 'Teams' }))
- expect(screen.getByRole('button', { name: /Add team/i })).toBeDisabled()
- })
-
it('grants member access end-to-end after Add member modal submission', async () => {
;(api.getAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
agentNames: [],
@@ -128,45 +112,18 @@ describe('HostAccessTab — extracted access behavior', () => {
fireEvent.click(screen.getByRole('button', { name: /Add member/i }))
// Pick Bob from the modal.
- const dialog = await waitFor(() =>
- screen.getByRole('dialog', { name: /Add member/i })
- )
+ const dialog = await waitFor(() => screen.getByRole('dialog', { name: /Add member/i }))
fireEvent.click(screen.getByRole('option', { name: 'Bob' }))
// The submit "Add member" lives inside the dialog; the section also has
// a button of the same name, so scope the click to the dialog.
- fireEvent.click(
- dialog.querySelector('button.cu-btn--primary') as HTMLButtonElement
- )
+ fireEvent.click(dialog.querySelector('button.cu-btn--primary') as HTMLButtonElement)
await waitFor(() => {
- expect(api.updateAdminUserAgents).toHaveBeenCalledWith(
- 'u2',
- ['foo'],
- expect.any(Array)
- )
+ expect(api.updateAdminUserAgents).toHaveBeenCalledWith('u2', ['foo'], expect.any(Array))
})
})
- it('refuses to grant member access when a rename is pending', async () => {
- ;(api.getAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
- agentNames: [],
- deletedAgentNames: [],
- })
-
- render(<HostAccessTab hasPendingRename hostName="foo" />)
-
- await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument())
-
- // The Add button itself is disabled, but a stale modal shouldn't be able
- // to bypass the guard either — verify the handler short-circuits by
- // poking it directly through the disabled Add control.
- const addBtn = screen.getByRole('button', { name: /Add member/i })
- expect(addBtn).toBeDisabled()
- // The dialog should not even be reachable.
- expect(screen.queryByRole('dialog', { name: /Add member/i })).not.toBeInTheDocument()
- })
-
it('revokes member access after confirm dialog approval', async () => {
;(api.getAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
agentNames: ['foo'],
@@ -185,11 +142,7 @@ describe('HostAccessTab — extracted access behavior', () => {
fireEvent.click(confirmDialog.querySelector('button.cu-btn--danger') as HTMLButtonElement)
await waitFor(() => {
- expect(api.updateAdminUserAgents).toHaveBeenCalledWith(
- 'u1',
- [],
- expect.any(Array)
- )
+ expect(api.updateAdminUserAgents).toHaveBeenCalledWith('u1', [], expect.any(Array))
})
})
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 53006c687..3a0499606 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.422",
+ "version": "0.1.423",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.422",
+ "version": "0.1.423",
"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.json
index ead94c7aa..ce4545600 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.422",
+ "version": "0.1.423",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",