Skip to content

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

TypeScript

fix(control-ui): consolidate agent detail actions

Josué19bb9d7f3b6d
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 8b0a34275..493206f21 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -8875,8 +8875,23 @@ td.cu-registry-description {
gap: var(--cu-space-2);
}
+.cu-identity-panel__local-actions {
+ display: inline-flex;
+ justify-content: flex-end;
+ gap: var(--cu-space-2);
+ padding: var(--cu-space-3) var(--cu-space-5) 0;
+}
+
.cu-identity-tabs {
- margin-block: 0;
+ margin: 0;
+ padding: var(--cu-space-2) var(--cu-space-5) 0;
+ background: var(--cu-bg-elevated);
+ border-bottom: 1px solid var(--cu-border-subtle);
+}
+
+.cu-identity-tabs .cu-tab[data-active='true'] {
+ background: var(--cu-surface);
+ border-bottom-color: var(--cu-surface);
}
.cu-identity-section {
@@ -8885,10 +8900,10 @@ td.cu-registry-description {
grid-template-rows: auto auto minmax(0, 1fr);
flex: 1;
min-height: 0;
- border: 1px solid var(--cu-border-subtle);
- border-radius: var(--cu-radius-sm);
- background: var(--cu-bg-elevated);
- padding: var(--cu-space-4);
+ border: 0;
+ border-radius: 0;
+ background: var(--cu-surface);
+ padding: var(--cu-space-5);
}
.cu-identity-section__header {
@@ -8945,6 +8960,12 @@ td.cu-registry-description {
flex-direction: column;
flex: 1;
min-height: 0;
+ gap: 0;
+ background: var(--cu-bg-elevated);
+}
+
+.cu-agent-detail-scroll:has(> .cu-identity-panel) {
+ padding: 0;
}
.cu-markdown-editor {
diff --git a/control-ui/app/hosts/[name]/page.tsx b/control-ui/app/hosts/[name]/page.tsx
index 8d595cd46..60c6859ae 100644
--- a/control-ui/app/hosts/[name]/page.tsx
+++ b/control-ui/app/hosts/[name]/page.tsx
@@ -193,6 +193,7 @@ export default function HostDetailsPage() {
const [showDeleteAgentConfirm, setShowDeleteAgentConfirm] = useState(false)
const [deletingAgent, setDeletingAgent] = useState(false)
const [deleteAgentDialogError, setDeleteAgentDialogError] = useState('')
+ const [sectionActions, setSectionActions] = useState<React.ReactNode>(null)
const [hostNameDraft, setHostNameDraft] = useState(routeName)
const [hostDisplayDraft, setHostDisplayDraft] = useState('')
@@ -393,6 +394,10 @@ export default function HostDetailsPage() {
router.replace(hostTabHref(tab))
}
+ const handleSectionActionsChange = useCallback((actions: React.ReactNode | null) => {
+ setSectionActions(actions)
+ }, [])
+
useEffect(() => {
mountedRef.current = true
return () => {
@@ -1050,21 +1055,49 @@ export default function HostDetailsPage() {
subtitle="Configuration and access for this agent."
tabAriaLabel="Agent sections"
tabClassName="cu-tabs--compact"
- contentClassName={activeTab === 'advanced' ? 'cu-agent-detail-card' : undefined}
+ contentClassName={
+ activeTab === 'advanced' || activeTab === 'identity' ? 'cu-agent-detail-card' : undefined
+ }
tabs={HOST_TABS.map(tab => ({
value: tab,
label: TAB_LABELS[tab],
href: hostTabHref(tab),
}))}
title={`Agent: ${routeName}`}
- titleActions={
- <AgentActionsMenu
- busy={busy || deletingAgent}
- onDelete={() => {
- setDeleteAgentDialogError('')
- setShowDeleteAgentConfirm(true)
- }}
- />
+ actions={
+ <>
+ {activeTab === 'model' && !editingModel ? (
+ <button
+ type="button"
+ className="cu-btn cu-btn--ghost cu-btn--sm"
+ onClick={() => {
+ setError('')
+ setEditingModel(true)
+ }}
+ disabled={busy}
+ >
+ Edit
+ </button>
+ ) : null}
+ {activeTab === 'connectors' ? (
+ <button
+ type="button"
+ className="cu-btn cu-btn--primary cu-btn--sm"
+ onClick={() => void openAddConnectorDialog()}
+ disabled={busy || !agentContext}
+ >
+ Add connector
+ </button>
+ ) : null}
+ {sectionActions}
+ <AgentActionsMenu
+ busy={busy || deletingAgent}
+ onDelete={() => {
+ setDeleteAgentDialogError('')
+ setShowDeleteAgentConfirm(true)
+ }}
+ />
+ </>
}
>
<div className="cu-agent-detail-scroll">
@@ -1107,21 +1140,6 @@ export default function HostDetailsPage() {
Provider, current model, allowed models, fallback policy, and credentials for this
agent.
</p>
- <div className="cu-agent-detail-heading__actions">
- {!editingModel ? (
- <button
- type="button"
- className="cu-btn cu-btn--ghost cu-btn--sm"
- onClick={() => {
- setError('')
- setEditingModel(true)
- }}
- disabled={busy}
- >
- Edit
- </button>
- ) : null}
- </div>
</div>
<div className="cu-form-stack cu-form-stack--wide">
@@ -1302,6 +1320,7 @@ export default function HostDetailsPage() {
initialTools={approvalToolsData}
onSaveApprovalTools={persistApprovalTools}
onSaveGuardrails={persistGuardrails}
+ onActionsChange={handleSectionActionsChange}
/>
)}
@@ -1311,16 +1330,6 @@ export default function HostDetailsPage() {
<p className="cu-muted" style={{ fontSize: '0.875rem', margin: 0 }}>
Connectors available to this agent.
</p>
- <div className="cu-agent-detail-heading__actions">
- <button
- type="button"
- className="cu-btn cu-btn--primary cu-btn--sm"
- onClick={() => void openAddConnectorDialog()}
- disabled={busy || !agentContext}
- >
- Add connector
- </button>
- </div>
</div>
<TableViewport className="cu-table-wrap">
<DataTable className="eft-table cu-table cu-table--header-band cu-table--static-rows cu-agent-connectors-table">
@@ -1474,9 +1483,13 @@ export default function HostDetailsPage() {
</div>
)}
- {activeTab === 'identity' && <HostIdentityTab hostName={routeName} />}
+ {activeTab === 'identity' && (
+ <HostIdentityTab hostName={routeName} onActionsChange={handleSectionActionsChange} />
+ )}
- {activeTab === 'access' && <HostAccessTab hostName={routeName} />}
+ {activeTab === 'access' && (
+ <HostAccessTab hostName={routeName} onActionsChange={handleSectionActionsChange} />
+ )}
</div>
{showDeleteAgentConfirm && (
<div
diff --git a/control-ui/components/HostAccessTab/index.tsx b/control-ui/components/HostAccessTab/index.tsx
index c554b3c64..cfd9ec990 100644
--- a/control-ui/components/HostAccessTab/index.tsx
+++ b/control-ui/components/HostAccessTab/index.tsx
@@ -39,7 +39,7 @@ const ACCESS_SUB_TABS: { key: AccessSubTab; label: string }[] = [
{ key: 'teams', label: 'Teams' },
]
-export function HostAccessTab({ hostName }: HostAccessTabProps) {
+export function HostAccessTab({ hostName, onActionsChange }: HostAccessTabProps) {
const router = useRouter()
const { confirm, confirmDialog } = useConfirmDialog()
const { showToast } = useToast()
@@ -326,6 +326,21 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
? 'Grant or revoke which members can use this agent.'
: 'Grant or revoke team-level access to this agent.'
+ useEffect(() => {
+ if (!onActionsChange) return
+ onActionsChange(
+ <button
+ type="button"
+ className="cu-btn cu-btn--primary cu-btn--sm"
+ onClick={() => (subTab === 'members' ? setShowAddUser(true) : setShowAddTeam(true))}
+ disabled={busy}
+ >
+ {subTab === 'members' ? 'Add member' : 'Add team'}
+ </button>
+ )
+ return () => onActionsChange(null)
+ }, [busy, onActionsChange, subTab])
+
return (
<section className="cu-access-tab" aria-label="Access">
{error ? (
@@ -345,25 +360,16 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
<div className="cu-access-section">
<div className="cu-access-section__header">
<p className="cu-muted cu-access-section__description">{subTabDescription}</p>
- {subTab === 'members' ? (
- <button
- type="button"
- className="cu-btn cu-btn--primary cu-btn--sm"
- onClick={() => setShowAddUser(true)}
- disabled={busy}
- >
- Add member
- </button>
- ) : (
+ {!onActionsChange ? (
<button
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
- onClick={() => setShowAddTeam(true)}
+ onClick={() => (subTab === 'members' ? setShowAddUser(true) : setShowAddTeam(true))}
disabled={busy}
>
- Add team
+ {subTab === 'members' ? 'Add member' : 'Add team'}
</button>
- )}
+ ) : null}
</div>
<TableViewport className="cu-table-wrap">
diff --git a/control-ui/components/HostAccessTab/types.ts b/control-ui/components/HostAccessTab/types.ts
index 1d1f4247d..84df2fd8d 100644
--- a/control-ui/components/HostAccessTab/types.ts
+++ b/control-ui/components/HostAccessTab/types.ts
@@ -1,3 +1,5 @@
+import type { ReactNode } from 'react'
+
export type AccessSubTab = 'members' | 'teams'
export type AccessUserRow = {
@@ -18,4 +20,5 @@ export type AccessTeamDirectoryRow = AccessTeamRow & {
export type HostAccessTabProps = {
hostName: string
+ onActionsChange?: (actions: ReactNode | null) => void
}
diff --git a/control-ui/components/HostAdvancedTab/index.tsx b/control-ui/components/HostAdvancedTab/index.tsx
index 38d642d99..2e8c151ce 100644
--- a/control-ui/components/HostAdvancedTab/index.tsx
+++ b/control-ui/components/HostAdvancedTab/index.tsx
@@ -1,11 +1,14 @@
'use client'
-import React, { useState } from 'react'
+import React, { useEffect, useState } from 'react'
+import { useRouter } from 'next/navigation'
import { DataTable, TableViewport } from '@clerum/frontend-components'
import { HostApprovalSection } from '@components/HostApprovalSection'
import { HostEnvTable } from '@components/HostEnvTable'
import { HostGuardrailsSection } from '@components/HostGuardrailsSection'
import { TabBar } from '@components/TabBar'
+import { GUARDRAIL_ENTRY_TYPE } from '@constants/marketplaceEntryTypes'
+import { CONTROL_ROUTES } from '@constants/routes'
import type { AdvancedSubTab, HostAdvancedTabProps } from './types'
const ADVANCED_SUB_TABS: { key: AdvancedSubTab; label: string }[] = [
@@ -24,9 +27,28 @@ export function HostAdvancedTab({
initialTools,
onSaveApprovalTools,
onSaveGuardrails,
+ onActionsChange,
}: HostAdvancedTabProps) {
+ const router = useRouter()
const [subTab, setSubTab] = useState<AdvancedSubTab>(DEFAULT_SUB_TAB)
+ useEffect(() => {
+ if (!onActionsChange || subTab !== 'hooks') return
+ onActionsChange(
+ <button
+ type="button"
+ className="cu-btn cu-btn--primary cu-btn--sm"
+ onClick={() =>
+ router.push(CONTROL_ROUTES.marketplace.orgEntriesFiltered({ type: GUARDRAIL_ENTRY_TYPE }))
+ }
+ disabled={busy}
+ >
+ Add hook
+ </button>
+ )
+ return () => onActionsChange(null)
+ }, [busy, onActionsChange, router, subTab])
+
return (
<section className="cu-advanced-tab" aria-label="Advanced">
<TabBar<AdvancedSubTab>
@@ -51,6 +73,7 @@ export function HostAdvancedTab({
}
initialGuardrails={initialGuardrails}
onSave={onSaveGuardrails}
+ showAddAction={false}
/>
))}
@@ -67,7 +90,7 @@ export function HostAdvancedTab({
/>
))}
- {subTab === 'env' && <HostEnvTable hostRef={hostName} />}
+ {subTab === 'env' && <HostEnvTable hostRef={hostName} onActionsChange={onActionsChange} />}
</div>
</section>
)
diff --git a/control-ui/components/HostAdvancedTab/types.ts b/control-ui/components/HostAdvancedTab/types.ts
index e793d009a..5e5753a13 100644
--- a/control-ui/components/HostAdvancedTab/types.ts
+++ b/control-ui/components/HostAdvancedTab/types.ts
@@ -1,3 +1,4 @@
+import type { ReactNode } from 'react'
import type { HostApprovalSectionProps } from '../HostApprovalSection/types'
import type { HostGuardrailsSectionProps } from '../HostGuardrailsSection/types'
@@ -11,4 +12,5 @@ export type HostAdvancedTabProps = {
onSaveApprovalTools: HostApprovalSectionProps['onSave']
initialGuardrails: HostGuardrailsSectionProps['initialGuardrails']
onSaveGuardrails: HostGuardrailsSectionProps['onSave']
+ onActionsChange?: (actions: ReactNode | null) => void
}
diff --git a/control-ui/components/HostEnvTable.tsx b/control-ui/components/HostEnvTable.tsx
index 235ce859e..0d8aee888 100644
--- a/control-ui/components/HostEnvTable.tsx
+++ b/control-ui/components/HostEnvTable.tsx
@@ -1,6 +1,7 @@
'use client'
-import React, { useEffect, useMemo, useState } from 'react'
+import React, { useCallback, useEffect, useMemo, useState } from 'react'
+import type { ReactNode } from 'react'
import { DataTable } from '@clerum/frontend-components'
import {
HostEnvEntry,
@@ -43,7 +44,13 @@ function validateKey(name: string): string | null {
return null
}
-export function HostEnvTable({ hostRef }: { hostRef: string }) {
+export function HostEnvTable({
+ hostRef,
+ onActionsChange,
+}: {
+ hostRef: string
+ onActionsChange?: (actions: ReactNode | null) => void
+}) {
const { showToast } = useToast()
const { confirm, confirmDialog } = useConfirmDialog()
const [items, setItems] = useState<HostEnvEntry[]>([])
@@ -69,34 +76,60 @@ export function HostEnvTable({ hostRef }: { hostRef: string }) {
const sortedItems = useMemo(() => [...items].sort((a, b) => a.key.localeCompare(b.key)), [items])
- async function load(opts: { refresh?: boolean } = {}) {
- if (opts.refresh) setRefreshing(true)
- else setLoading(true)
- setError('')
- try {
- const res = await listHostEnv(hostRef)
- setItems(res.items || [])
- } catch (err) {
- setError(err instanceof Error ? err.message : String(err))
- } finally {
- setLoading(false)
- setRefreshing(false)
- }
- }
+ const load = useCallback(
+ async (opts: { refresh?: boolean } = {}) => {
+ if (opts.refresh) setRefreshing(true)
+ else setLoading(true)
+ setError('')
+ try {
+ const res = await listHostEnv(hostRef)
+ setItems(res.items || [])
+ } catch (err) {
+ setError(err instanceof Error ? err.message : String(err))
+ } finally {
+ setLoading(false)
+ setRefreshing(false)
+ }
+ },
+ [hostRef]
+ )
useEffect(() => {
void load()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hostRef])
- function openCreate() {
+ const openCreate = useCallback(() => {
setEditingKey(null)
setKeyDraft('')
setValueDraft('')
setSecretDraft(false)
setKeyDraftError(null)
setOpen(true)
- }
+ }, [])
+
+ useEffect(() => {
+ if (!onActionsChange) return
+ onActionsChange(
+ <>
+ <button
+ type="button"
+ className="cu-btn cu-btn--icon cu-btn--toolbar"
+ onClick={() => void load({ refresh: true })}
+ disabled={refreshing}
+ aria-label={
+ refreshing ? 'Refreshing environment variables' : 'Refresh environment variables'
+ }
+ >
+ <IconRefresh className={refreshing ? 'cu-spin' : undefined} />
+ </button>
+ <button type="button" className="cu-btn cu-btn--primary cu-btn--sm" onClick={openCreate}>
+ Add variable
+ </button>
+ </>
+ )
+ return () => onActionsChange(null)
+ }, [load, onActionsChange, openCreate, refreshing])
function openEdit(entry: HostEnvEntry) {
setEditingKey(entry.key)
@@ -189,36 +222,13 @@ export function HostEnvTable({ hostRef }: { hostRef: string }) {
return (
<section className="cu-host-env-tab">
- <div
- style={{
- display: 'flex',
- justifyContent: 'space-between',
- alignItems: 'center',
- gap: '0.5rem',
- }}
- >
+ <div className="cu-host-env-tab__header">
<div>
<p className="cu-muted" style={{ margin: 0, fontSize: '0.85rem' }}>
Operator-managed env vars for this Host. Applied within ~1 second; no pod restart.
Provider keys live in the LLM Secrets tab.
</p>
</div>
- <div style={{ display: 'flex', gap: '0.5rem' }}>
- <button
- type="button"
- className="cu-btn cu-btn--icon cu-btn--toolbar"
- onClick={() => load({ refresh: true })}
- disabled={refreshing}
- aria-label={
- refreshing ? 'Refreshing environment variables' : 'Refresh environment variables'
- }
- >
- <IconRefresh className={refreshing ? 'cu-spin' : undefined} />
- </button>
- <button type="button" className="cu-btn cu-btn--primary" onClick={openCreate}>
- + Add variable
- </button>
- </div>
</div>
{error ? <div className="cu-banner cu-banner--error">{error}</div> : null}
diff --git a/control-ui/components/HostGuardrailsSection/index.tsx b/control-ui/components/HostGuardrailsSection/index.tsx
index 42a76e754..6c80c646a 100644
--- a/control-ui/components/HostGuardrailsSection/index.tsx
+++ b/control-ui/components/HostGuardrailsSection/index.tsx
@@ -11,13 +11,6 @@ import { CONTROL_ROUTES } from '@constants/routes'
import { GUARDRAIL_PHASES, GUARDRAIL_PHASE_LABELS } from './constants'
import type { GuardrailHookRow, HostGuardrails, HostGuardrailsSectionProps } from './types'
-// Add hook lands on the org marketplace entries list, narrowed to guardrail
-// hooks — the unfiltered list mixes in every connector and plugin the org has
-// published, which is not what someone adding a hook is looking for.
-const ADD_HOOK_ROUTE = CONTROL_ROUTES.marketplace.orgEntriesFiltered({
- type: GUARDRAIL_ENTRY_TYPE,
-})
-
// Every field this section does not edit rides along untouched — dropping
// `builtins` or `limits` here would silently wipe them from the Host spec.
function withHooks(
@@ -27,11 +20,14 @@ function withHooks(
return { ...source, hooks }
}
+const ADD_HOOK_ROUTE = CONTROL_ROUTES.marketplace.orgEntriesFiltered({ type: GUARDRAIL_ENTRY_TYPE })
+
export function HostGuardrailsSection({
initialGuardrails,
onSave,
busy,
canWrite,
+ showAddAction = true,
}: HostGuardrailsSectionProps) {
const router = useRouter()
const { confirm, confirmDialog } = useConfirmDialog()
@@ -94,7 +90,7 @@ export function HostGuardrailsSection({
<p className="cu-muted cu-access-section__description">
Guardrail hooks installed on the cluster and referenced by this agent.
</p>
- {canWrite ? (
+ {canWrite && showAddAction ? (
<button
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
diff --git a/control-ui/components/HostGuardrailsSection/types.ts b/control-ui/components/HostGuardrailsSection/types.ts
index 4b0a51b91..93cfce88b 100644
--- a/control-ui/components/HostGuardrailsSection/types.ts
+++ b/control-ui/components/HostGuardrailsSection/types.ts
@@ -45,4 +45,5 @@ export interface HostGuardrailsSectionProps {
onSave: (next: HostGuardrails) => Promise<void>
busy: boolean
canWrite: boolean
+ showAddAction?: boolean
}
diff --git a/control-ui/components/HostIdentityTab/index.tsx b/control-ui/components/HostIdentityTab/index.tsx
index 07713d72d..bd5f68670 100644
--- a/control-ui/components/HostIdentityTab/index.tsx
+++ b/control-ui/components/HostIdentityTab/index.tsx
@@ -1,6 +1,7 @@
'use client'
import React, { useCallback, useEffect, useRef, useState } from 'react'
+import { useConfirmDialog } from '@components/ConfirmDialog'
import { MarkdownEditor } from '@components/MarkdownEditor'
import { TabBar } from '@components/TabBar'
import { useToast } from '@components/Toast'
@@ -13,7 +14,12 @@ import {
IDENTITY_FIELDS,
IDENTITY_FIELD_ORDER,
} from './constants'
-import type { HostIdentityTabState, IdentityFieldKey, IdentityFields } from './types'
+import type {
+ HostIdentityTabProps,
+ HostIdentityTabState,
+ IdentityFieldKey,
+ IdentityFields,
+} from './types'
function fieldBytes(value: string): number {
return new TextEncoder().encode(value).length
@@ -28,8 +34,9 @@ function fieldsFromPayload(payload: IdentityFields): IdentityFields {
}
}
-export function HostIdentityTab({ hostName }: { hostName: string }) {
+export function HostIdentityTab({ hostName, onActionsChange }: HostIdentityTabProps) {
const { showToast } = useToast()
+ const { confirm, confirmDialog } = useConfirmDialog()
const loadRequestId = useRef(0)
const [state, setState] = useState<HostIdentityTabState>({
activeField: 'identity',
@@ -82,10 +89,6 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
}
}, [loadIdentityFiles])
- function setActiveField(key: IdentityFieldKey) {
- setState(prev => ({ ...prev, activeField: key }))
- }
-
function setField(key: IdentityFieldKey, value: string) {
setState(prev => ({
...prev,
@@ -93,16 +96,16 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
}))
}
- function discardEdits() {
+ const discardEdits = useCallback(() => {
setState(prev => ({
...prev,
fields: { ...prev.initial },
error: prev.reloadHint ? prev.error : '',
}))
- }
+ }, [])
- async function saveActiveField() {
- if (!activeDirty || activeTooLarge || state.reloadHint) return
+ const saveActiveField = useCallback(async (): Promise<boolean> => {
+ if (!activeDirty || activeTooLarge || state.reloadHint) return false
setState(prev => ({ ...prev, error: '', saving: true }))
try {
@@ -120,6 +123,7 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
saving: false,
}))
showToast('Identity files saved.', { tone: 'success' })
+ return true
} catch (error) {
const err = error as { message?: string; status?: number }
const isConflict = err.status === 409 || /409/.test(err.message ?? '')
@@ -133,8 +137,72 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
saving: false,
}))
showToast(message, { tone: 'error' })
+ return false
}
- }
+ }, [activeDirty, activeTooLarge, hostName, showToast, state])
+
+ const setActiveField = useCallback(
+ async (key: IdentityFieldKey) => {
+ if (key === state.activeField) return
+ if (!anyDirty) {
+ setState(prev => ({ ...prev, activeField: key }))
+ return
+ }
+
+ const shouldSave = await confirm({
+ cancelLabel: 'Discard all',
+ confirmLabel: 'Save',
+ message: 'Save or discard your identity edits before changing files.',
+ title: 'Unsaved identity edits',
+ })
+ if (shouldSave) {
+ if (!(await saveActiveField())) return
+ } else {
+ discardEdits()
+ }
+ setState(prev => ({ ...prev, activeField: key }))
+ },
+ [anyDirty, confirm, discardEdits, saveActiveField, state.activeField]
+ )
+
+ useEffect(() => {
+ if (!onActionsChange) return
+ onActionsChange(
+ anyDirty ? (
+ <>
+ <Button
+ disabled={!activeDirty || activeTooLarge || state.saving || state.reloadHint}
+ onClick={() => void saveActiveField()}
+ size="sm"
+ type="button"
+ variant="primary"
+ >
+ <IconCheck width={14} height={14} />
+ {state.saving ? 'Saving' : 'Save'}
+ </Button>
+ <Button
+ disabled={state.saving}
+ onClick={discardEdits}
+ size="sm"
+ type="button"
+ variant="ghost"
+ >
+ Discard all
+ </Button>
+ </>
+ ) : null
+ )
+ return () => onActionsChange(null)
+ }, [
+ activeDirty,
+ activeTooLarge,
+ anyDirty,
+ discardEdits,
+ onActionsChange,
+ saveActiveField,
+ state.reloadHint,
+ state.saving,
+ ])
if (state.loading) {
return (
@@ -150,11 +218,8 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
return (
<section className="cu-identity-panel" aria-label="Admin-managed identity files">
- <div className="cu-identity-panel__intro">
- <p className="cu-muted cu-muted-note--compact">
- Admin-managed identity files are readable by the agent but blocked from agent writes.
- </p>
- <div aria-hidden={!anyDirty} className="cu-identity-dirty-actions" data-hidden={!anyDirty}>
+ {!onActionsChange && anyDirty ? (
+ <div className="cu-identity-panel__local-actions">
<Button
disabled={!activeDirty || activeTooLarge || state.saving || state.reloadHint}
onClick={() => void saveActiveField()}
@@ -175,8 +240,7 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
Discard all
</Button>
</div>
- </div>
-
+ ) : null}
{state.error && state.reloadHint ? (
<div className="cu-banner cu-banner--error">
{state.error}
@@ -229,6 +293,7 @@ export function HostIdentityTab({ hostName }: { hostName: string }) {
</div>
</div>
</div>
+ {confirmDialog}
</section>
)
}
diff --git a/control-ui/components/HostIdentityTab/types.ts b/control-ui/components/HostIdentityTab/types.ts
index 6dfd3b141..3772588df 100644
--- a/control-ui/components/HostIdentityTab/types.ts
+++ b/control-ui/components/HostIdentityTab/types.ts
@@ -1,3 +1,5 @@
+import type { ReactNode } from 'react'
+
export type IdentityFieldKey = 'identity' | 'soul' | 'agents' | 'user'
export type IdentityFields = Record<IdentityFieldKey, string>
@@ -21,3 +23,8 @@ export type HostIdentityTabState = {
resourceVersion: string
saving: boolean
}
+
+export type HostIdentityTabProps = {
+ hostName: string
+ onActionsChange?: (actions: ReactNode | null) => void
+}
diff --git a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
index 94698937b..9c52f0cfa 100644
--- a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
+++ b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
@@ -123,7 +123,7 @@ describe('HostDetailsPage identity integration', () => {
mockParams = { name: 'foo', tab: 'identity' }
const { container } = render(<HostDetailsPage />)
expect(await screen.findByTestId('identity-tab')).toHaveTextContent('Identity editor for foo')
- expect(container.querySelector('.cu-agent-detail-card')).toBeNull()
+ expect(container.querySelector('.cu-agent-detail-card')).not.toBeNull()
})
it('renders the agent detail tabs in order', async () => {
diff --git a/control-ui/components/__tests__/HostIdentityTab.test.tsx b/control-ui/components/__tests__/HostIdentityTab.test.tsx
index 44ec10d1a..7c1f8ab86 100644
--- a/control-ui/components/__tests__/HostIdentityTab.test.tsx
+++ b/control-ui/components/__tests__/HostIdentityTab.test.tsx
@@ -1,6 +1,6 @@
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import * as api from '../../lib/api'
import { HostIdentityTab } from '../HostIdentityTab'
import { ToastProvider } from '../Toast'
@@ -125,7 +125,7 @@ describe('HostIdentityTab', () => {
await waitFor(() => expect(screen.getByText(/^Identity files saved\.?$/i)).toBeInTheDocument())
})
- it('discards pending edits across identity files', async () => {
+ it('requires discarding or saving before changing identity files', async () => {
;(api.getHostPersonalization as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
agents: 'agents old',
identity: 'identity old',
@@ -137,12 +137,11 @@ describe('HostIdentityTab', () => {
const identityEditor = await findMarkdownEditor(/Identity markdown/i)
fireEvent.change(identityEditor, { target: { value: 'identity new' } })
fireEvent.click(screen.getByRole('tab', { name: 'Soul' }))
- fireEvent.change(await findMarkdownEditor(/Soul markdown/i), {
- target: { value: 'soul new' },
- })
- expect(screen.getByText(/unsaved edits/i)).toBeInTheDocument()
- fireEvent.click(screen.getByRole('button', { name: /discard/i }))
+ const dialog = screen.getByRole('alertdialog', { name: /unsaved identity edits/i })
+ expect(dialog).toBeInTheDocument()
+ expect(screen.getByText(/save or discard your identity edits/i)).toBeInTheDocument()
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Discard all' }))
await expectMarkdownEditorValue(/Soul markdown/i, 'soul old')
fireEvent.click(screen.getByRole('tab', { name: 'Identity' }))
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index aa2b00df1..9390c527d 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.584",
+ "version": "0.1.585",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.584",
+ "version": "0.1.585",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 88a4656f9..f076f6434 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.584",
+ "version": "0.1.585",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",