Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-ui): rename to Installed Guardrails, add per-guardrail detail + add-hook
Andy Paviabb9636990788
diff --git a/control-ui/app/constants/routes.ts b/control-ui/app/constants/routes.tsindex fe268c24a..7fc587356 100644--- a/control-ui/app/constants/routes.ts+++ b/control-ui/app/constants/routes.ts@@ -63,6 +63,7 @@ export const CONTROL_ROUTES = {globalFileSystem: '/global-file-system',guardrails: {root: '/guardrails',+ detail: (name: string) => `/guardrails/${segment(name)}`,},llmModels: {root: '/llm-models',diff --git a/control-ui/app/guardrails/[name]/page.tsx b/control-ui/app/guardrails/[name]/page.tsxnew file mode 100644index 000000000..26f4466ff--- /dev/null+++ b/control-ui/app/guardrails/[name]/page.tsx@@ -0,0 +1,289 @@+'use client'++import React, { useEffect, useMemo, useState } from 'react'+import { useParams, useRouter } from 'next/navigation'+import { CONTROL_ROUTES } from '../../../app/constants/routes'+import { useConfirmDialog } from '../../../components/ConfirmDialog'+import { DashboardLayout } from '../../../components/DashboardLayout'+import { useToast } from '../../../components/Toast'+import { Button, FormSection } from '../../../components/ui'+import { deleteLlmHook, getHosts, getLlmHook, isSilentApiError } from '../../../lib/api'+import type { HostResource, LlmHookResource, LlmHookStatus } from '../../../lib/api'++type HookTarget = {+ image?: { ref?: string; port?: number }+ service?: { name?: string; namespace?: string; port?: number }+ remote?: { baseUrl?: string }+}+type HookSpec = {+ target?: HookTarget+ path?: string+ lifecyclePoints?: string[]+ order?: number+ failMode?: string+ capabilities?: string[]+}++function describeTarget(t?: HookTarget): { kind: string; value: string } {+ if (t?.image?.ref) return { kind: 'Target image', value: t.image.ref }+ if (t?.service?.name) {+ const ns = t.service.namespace ? `${t.service.namespace}/` : ''+ const port = t.service.port ? `:${t.service.port}` : ''+ return { kind: 'Target service', value: `${ns}${t.service.name}${port}` }+ }+ if (t?.remote?.baseUrl) return { kind: 'Target remote', value: t.remote.baseUrl }+ return { kind: 'Target', value: '—' }+}++// Host.spec.guardrails.hooks phase keys.+const HOST_HOOK_PHASES = [+ 'preToolUse',+ 'preCall',+ 'moderate',+ 'postCallSuccess',+ 'postToolUse',+ 'onError',+] as const+const PHASE_LABEL: Record<string, string> = {+ preToolUse: 'Pre-tool use',+ postToolUse: 'Post-tool use',+ preCall: 'Pre-call',+ moderate: 'Moderate',+ postCallSuccess: 'Post-call success',+ onError: 'On error',+}++/** Agents (Hosts) that reference this guardrail, with the phases each uses it in. */+function agentsUsingHook(+ hosts: HostResource[],+ hookName: string+): Array<{ name: string; phases: string[] }> {+ const out: Array<{ name: string; phases: string[] }> = []+ for (const h of hosts) {+ const hooks = (+ h.spec as { guardrails?: { hooks?: Record<string, Array<{ id?: string }>> } } | undefined+ )?.guardrails?.hooks+ if (!hooks) continue+ const phases = HOST_HOOK_PHASES.filter(phase => {+ const refs = hooks[phase]+ return Array.isArray(refs) && refs.some(r => r?.id === hookName)+ })+ if (phases.length > 0) out.push({ name: h.metadata?.name || 'unknown', phases: [...phases] })+ }+ return out.sort((a, b) => a.name.localeCompare(b.name))+}++function StatusBadge({ status }: { status?: LlmHookStatus }) {+ const ready = status?.conditions?.find(c => c.type === 'Ready' && c.status === 'True')+ const failing = status?.conditions?.find(c => c.status === 'False')+ const state = ready+ ? 'ready'+ : failing+ ? 'error'+ : status?.conditions?.length+ ? 'pending'+ : 'unknown'+ const label =+ state === 'ready'+ ? 'Ready'+ : state === 'error'+ ? 'Error'+ : state === 'pending'+ ? 'Pending'+ : 'Unknown'+ return (+ <span+ className={`cu-connector-badge cu-connector-badge--status-${state}`}+ title={failing?.message}+ >+ {label}+ </span>+ )+}++function Row({ label, children }: { label: string; children: React.ReactNode }) {+ return (+ <div className="cu-summary-list__row">+ <span>{label}</span>+ <span>{children}</span>+ </div>+ )+}++export default function GuardrailDetailPage() {+ const params = useParams<{ name: string }>()+ const name = decodeURIComponent(String(params?.name ?? ''))+ const router = useRouter()+ const { showToast } = useToast()+ const { confirm, confirmDialog } = useConfirmDialog()+ const [hook, setHook] = useState<LlmHookResource | null>(null)+ const [hosts, setHosts] = useState<HostResource[]>([])+ const [loading, setLoading] = useState(true)+ const [error, setError] = useState('')+ const [uninstalling, setUninstalling] = useState(false)++ async function load() {+ setLoading(true)+ setError('')+ try {+ const [h, hostResult] = await Promise.all([getLlmHook(name), getHosts()])+ setHook(h)+ setHosts((hostResult.items ?? []) as HostResource[])+ } catch (e) {+ if (isSilentApiError(e)) return+ setError(e instanceof Error ? e.message : 'Failed to load guardrail')+ } finally {+ setLoading(false)+ }+ }++ useEffect(() => {+ if (name) void load()+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [name])++ const spec = (hook?.spec ?? {}) as HookSpec+ const target = describeTarget(spec.target)+ const agents = useMemo(() => agentsUsingHook(hosts, name), [hosts, name])++ async function handleUninstall() {+ const ok = await confirm({+ title: 'Uninstall Guardrail',+ message: `Uninstall guardrail ${name}? This removes the LlmHook and its deployment.`,+ confirmLabel: 'Uninstall',+ tone: 'danger',+ })+ if (!ok) return+ setUninstalling(true)+ try {+ await deleteLlmHook(name)+ showToast(`Guardrail ${name} uninstalled.`, { tone: 'success' })+ router.push(CONTROL_ROUTES.guardrails.root)+ } catch (e) {+ if (!isSilentApiError(e)) {+ setError(e instanceof Error ? e.message : 'Failed to uninstall guardrail')+ }+ setUninstalling(false)+ }+ }++ return (+ <DashboardLayout>+ <div style={{ marginBottom: 'var(--cu-space-2)' }}>+ <Button+ variant="ghost"+ size="sm"+ onClick={() => router.push(CONTROL_ROUTES.guardrails.root)}+ >+ ← Installed Guardrails+ </Button>+ </div>++ {error ? (+ <div className="cu-banner cu-banner--error" role="alert">+ {error}+ </div>+ ) : null}++ {loading && !hook ? (+ <div className="cu-card">+ <div className="cu-card__body cu-muted">Loading guardrail…</div>+ </div>+ ) : !hook ? (+ <div className="cu-empty">Guardrail not found.</div>+ ) : (+ <>+ <FormSection title={name} description="Installed guardrail hook.">+ <div className="cu-summary-list">+ <Row label="Status">+ <StatusBadge status={hook.status} />+ </Row>+ <Row label={target.kind}>+ <strong className="cu-expandable-field__code">{target.value}</strong>+ </Row>+ <Row label="Path">{spec.path || '/'}</Row>+ <Row label="Lifecycle points">{(spec.lifecyclePoints || []).join(', ') || '—'}</Row>+ <Row label="Fail mode">{spec.failMode || '—'}</Row>+ <Row label="Capabilities">+ {spec.capabilities && spec.capabilities.length > 0 ? (+ <span className="cu-expandable-tags">+ {spec.capabilities.map(c => (+ <span key={c} className="cu-registry-tag">+ {c}+ </span>+ ))}+ </span>+ ) : (+ <span className="cu-muted">None declared</span>+ )}+ </Row>+ <Row label="Observed digest">+ <strong className="cu-expandable-field__code">+ {hook.status?.observedDigest || '—'}+ </strong>+ </Row>+ <Row label="Ready replicas">+ {typeof hook.status?.readyReplicas === 'number' ? hook.status.readyReplicas : '—'}+ </Row>+ </div>+ <div style={{ marginTop: 'var(--cu-space-3)' }}>+ <Button variant="danger" size="sm" onClick={handleUninstall} disabled={uninstalling}>+ {uninstalling ? 'Uninstalling…' : 'Uninstall'}+ </Button>+ </div>+ </FormSection>++ <FormSection+ title={`Agents using this guardrail (${agents.length})`}+ description="Agents whose guardrails reference this hook, and the lifecycle phases they use it in."+ >+ {agents.length === 0 ? (+ <div className="cu-empty">No agents reference this guardrail.</div>+ ) : (+ <div className="cu-table-wrap">+ <table className="cu-table cu-table--header-band">+ <thead>+ <tr>+ <th>Agent</th>+ <th>Phases</th>+ </tr>+ </thead>+ <tbody>+ {agents.map(a => (+ <tr+ key={a.name}+ className="cu-table__row cu-table__row--clickable"+ role="button"+ tabIndex={0}+ onClick={() => router.push(CONTROL_ROUTES.agents.tab(a.name, 'guardrails'))}+ onKeyDown={e => {+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault()+ router.push(CONTROL_ROUTES.agents.tab(a.name, 'guardrails'))+ }+ }}+ aria-label={`Open agent ${a.name} guardrails`}+ >+ <td>{a.name}</td>+ <td>+ <span className="cu-expandable-tags">+ {a.phases.map(p => (+ <span key={p} className="cu-registry-tag">+ {PHASE_LABEL[p] || p}+ </span>+ ))}+ </span>+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ )}+ </FormSection>+ </>+ )}+ {confirmDialog}+ </DashboardLayout>+ )+}diff --git a/control-ui/components/GuardrailHooksTable.tsx b/control-ui/components/GuardrailHooksTable.tsxindex 7208ab3ba..193e56d80 100644--- a/control-ui/components/GuardrailHooksTable.tsx+++ b/control-ui/components/GuardrailHooksTable.tsx@@ -1,6 +1,8 @@'use client'-import React, { Fragment, useMemo, useState } from 'react'+import React, { useMemo, useState } from 'react'+import { useRouter } from 'next/navigation'+import { CONTROL_ROUTES } from '@constants/routes'import type { LlmHookStatus } from '../lib/api'import type {GuardrailHooksTableProps,@@ -16,7 +18,7 @@ import { TablePanelHeader } from './TablePanelHeader'import { IconChevronRight, IconRefresh, IconX } from './icons'const HOOK_COLUMNS: TableHeaderColumn[] = [- { key: 'expand', ariaLabel: 'Expand hook' },+ { key: 'open', ariaLabel: 'Open guardrail' },{ key: 'name', label: 'Name' },{ key: 'lifecycle', label: 'Lifecycle' },{ key: 'order', label: 'Order' },@@ -78,8 +80,8 @@ export function GuardrailHooksTable({refreshing,loading,}: GuardrailHooksTableProps) {+ const router = useRouter()const [searchQuery, setSearchQuery] = useState('')- const [expandedKeys, setExpandedKeys] = useState<Set<string>>(new Set())const rows = useMemo(() =>@@ -119,13 +121,8 @@ export function GuardrailHooksTable({return () => clearInterval(id)}, [onRefresh])- function toggleExpanded(key: string) {- setExpandedKeys(current => {- const next = new Set(current)- if (next.has(key)) next.delete(key)- else next.add(key)- return next- })+ function openDetail(name: string) {+ router.push(CONTROL_ROUTES.guardrails.detail(name))}const isInitialLoad = loading && items.length === 0@@ -136,7 +133,9 @@ export function GuardrailHooksTable({title={<><IconShield />- {isInitialLoad ? 'Guardrail Hooks' : `Guardrail Hooks (${filteredRows.length})`}+ {isInitialLoad+ ? 'Installed Guardrails'+ : `Installed Guardrails (${filteredRows.length})`}</>}subtitle="Installed LLM guardrail hooks across the cluster."@@ -145,8 +144,8 @@ export function GuardrailHooksTable({<SectionSearchInputvalue={searchQuery}onChange={setSearchQuery}- placeholder="Search hooks"- ariaLabel="Search guardrail hooks"+ placeholder="Search guardrails"+ ariaLabel="Search installed guardrails"disabled={isInitialLoad}/>{onRefresh ? (@@ -155,7 +154,7 @@ export function GuardrailHooksTable({className="cu-btn cu-btn--icon cu-btn--toolbar"onClick={() => void onRefresh()}disabled={refreshing || isInitialLoad}- aria-label={refreshing ? 'Refreshing...' : 'Reload guardrail hooks'}+ aria-label={refreshing ? 'Refreshing...' : 'Reload installed guardrails'}><IconRefreshclassName={refreshing ? 'cu-spin' : undefined}@@ -180,7 +179,7 @@ export function GuardrailHooksTable({</div>) : filteredRows.length === 0 ? (<div className="cu-empty">- {normalizedSearch ? 'No hooks match this search.' : 'No guardrail hooks installed.'}+ {normalizedSearch ? 'No guardrails match this search.' : 'No guardrails installed.'}</div>) : (<div className="cu-table-wrap cu-guardrails-table-wrap">@@ -191,132 +190,71 @@ export function GuardrailHooksTable({<tbody>{filteredRows.map(({ key, name, item }) => {const spec = (item.spec || {}) as LlmHookSpecView- const expanded = expandedKeys.has(key)const lifecycle = (spec.lifecyclePoints || []).join(', ')- const target = describeTarget(spec.target)return (- <Fragment key={key}>- <tr- className="cu-table__row cu-table__row--clickable cu-expandable-row"- role="button"- onClick={() => toggleExpanded(key)}- onKeyDown={event => {- if (event.key === 'Enter' || event.key === ' ') {- event.preventDefault()- toggleExpanded(key)- }- }}- tabIndex={0}- aria-expanded={expanded}- aria-controls={`hook-details-${key}`}- aria-label={`${expanded ? 'Collapse' : 'Expand'} hook ${name}`}+ <tr+ key={key}+ className="cu-table__row cu-table__row--clickable"+ role="button"+ onClick={() => openDetail(name)}+ onKeyDown={event => {+ if (event.key === 'Enter' || event.key === ' ') {+ event.preventDefault()+ openDetail(name)+ }+ }}+ tabIndex={0}+ aria-label={`View guardrail ${name}`}+ >+ <td className="cu-expandable-row__chevron" aria-hidden="true">+ <IconChevronRight width={18} height={18} />+ </td>+ <td>+ <span className="cu-expandable-row__name">{name}</span>+ </td>+ <td>{lifecycle ? lifecycle : <span className="cu-muted">—</span>}</td>+ <td>+ {typeof spec.order === 'number' ? (+ spec.order+ ) : (+ <span className="cu-muted">—</span>+ )}+ </td>+ <td>+ <FailModeBadge failMode={spec.failMode} />+ </td>+ <td>+ <StatusBadge status={item.status} />+ </td>+ <td+ className="cu-table__cell-actions"+ onClick={event => event.stopPropagation()}+ onKeyDown={event => event.stopPropagation()}>- <td className="cu-expandable-row__chevron" aria-hidden="true">- <IconChevronRight- className={expanded ? 'is-expanded' : undefined}- width={18}- height={18}- />- </td>- <td>- <span className="cu-expandable-row__name">{name}</span>- </td>- <td>{lifecycle ? lifecycle : <span className="cu-muted">—</span>}</td>- <td>- {typeof spec.order === 'number' ? (- spec.order- ) : (- <span className="cu-muted">—</span>- )}- </td>- <td>- <FailModeBadge failMode={spec.failMode} />- </td>- <td>- <StatusBadge status={item.status} />- </td>- <td- className="cu-table__cell-actions"- onClick={event => event.stopPropagation()}- onKeyDown={event => event.stopPropagation()}- >- <div className="cu-table-actions">- {onUninstall ? (- <button- type="button"- className="cu-btn cu-btn--icon cu-btn--danger-icon"- onClick={() => void onUninstall({ name })}- disabled={uninstallingKey === key}- aria-label={- uninstallingKey === key- ? 'Uninstalling...'- : `Uninstall hook ${name}`- }- title={- uninstallingKey === key- ? 'Uninstalling...'- : `Uninstall hook ${name}`- }- >- <IconX width={16} height={16} />- </button>- ) : null}- </div>- </td>- </tr>- {expanded ? (- <tr id={`hook-details-${key}`} className="cu-expandable-detail-row">- <td colSpan={HOOK_COLUMNS.length}>- <div className="cu-expandable-detail cu-connector-detail">- <div className="cu-expandable-detail__fields">- <div className="cu-expandable-field cu-expandable-field--wide">- <span className="cu-expandable-field__label">Target</span>- <span className="cu-expandable-field__code">{target || '—'}</span>- </div>- <div className="cu-expandable-field">- <span className="cu-expandable-field__label">Path</span>- <span className="cu-expandable-field__code">- {spec.path || '/'}- </span>- </div>- <div className="cu-expandable-field cu-expandable-field--wide">- <span className="cu-expandable-field__label">Capabilities</span>- {spec.capabilities && spec.capabilities.length > 0 ? (- <div className="cu-expandable-tags">- {spec.capabilities.map(capability => (- <span key={capability} className="cu-registry-tag">- {capability}- </span>- ))}- </div>- ) : (- <span className="cu-muted">None declared</span>- )}- </div>- <div className="cu-expandable-field">- <span className="cu-expandable-field__label">Observed digest</span>- <span className="cu-expandable-field__code">- {item.status?.observedDigest || '—'}- </span>- </div>- <div className="cu-expandable-field">- <span className="cu-expandable-field__label">Ready replicas</span>- <span>- {typeof item.status?.readyReplicas === 'number'- ? item.status.readyReplicas- : '—'}- </span>- </div>- <div className="cu-expandable-field">- <span className="cu-expandable-field__label">Last reconciled</span>- <span>{item.status?.lastReconciled || '—'}</span>- </div>- </div>- </div>- </td>- </tr>- ) : null}- </Fragment>+ <div className="cu-table-actions">+ {onUninstall ? (+ <button+ type="button"+ className="cu-btn cu-btn--icon cu-btn--danger-icon"+ onClick={() => void onUninstall({ name })}+ disabled={uninstallingKey === key}+ aria-label={+ uninstallingKey === key+ ? 'Uninstalling...'+ : `Uninstall guardrail ${name}`+ }+ title={+ uninstallingKey === key+ ? 'Uninstalling...'+ : `Uninstall guardrail ${name}`+ }+ >+ <IconX width={16} height={16} />+ </button>+ ) : null}+ </div>+ </td>+ </tr>)})}</tbody>diff --git a/control-ui/components/HostGuardrailsSection/index.tsx b/control-ui/components/HostGuardrailsSection/index.tsxindex dce71281a..35ce08bcd 100644--- a/control-ui/components/HostGuardrailsSection/index.tsx+++ b/control-ui/components/HostGuardrailsSection/index.tsx@@ -1,6 +1,8 @@'use client'import React, { useMemo, useState } from 'react'+import { useRouter } from 'next/navigation'+import { CONTROL_ROUTES } from '@constants/routes'import { IconX } from '../icons'import { Button, SelectInput, TextInput } from '../ui'import { GUARDRAIL_BUILTIN_OPTIONS, GUARDRAIL_PHASES, GUARDRAIL_PHASE_LABELS } from './constants'@@ -28,6 +30,7 @@ export function HostGuardrailsSection({canWrite,defaultEditing = false,}: HostGuardrailsSectionProps) {+ const router = useRouter()const [editing, setEditing] = useState(defaultEditing)const [draft, setDraft] = useState<HostGuardrails>(() => cloneGuardrails(initialGuardrails))@@ -97,9 +100,10 @@ export function HostGuardrailsSection({return (<div className="cu-host-approval-section"><p className="cu-muted cu-host-approval-section__description">- Installed guardrail hooks referenced by this agent, plus built-in guardrails. Remove a hook- reference or add a built-in. Manage installed hooks cluster-wide from the Guardrails- section.+ Installed guardrail hooks referenced by this agent, plus built-in guardrails. Use{' '}+ <strong>Add hook</strong> to install a guardrail from the Marketplace onto this agent, add a+ built-in, or remove a hook reference. Manage installed guardrails cluster-wide from the+ Installed Guardrails section.</p><div className="cu-host-approval-section__content">@@ -170,14 +174,24 @@ export function HostGuardrailsSection({</button></>) : canWrite ? (- <button- type="button"- className="cu-btn cu-btn--ghost cu-btn--sm"- onClick={() => setEditing(true)}- disabled={busy}- >- Edit- </button>+ <>+ <button+ type="button"+ className="cu-btn cu-btn--primary cu-btn--sm"+ onClick={() => router.push(CONTROL_ROUTES.marketplace.orgEntries)}+ disabled={busy}+ >+ Add hook+ </button>+ <button+ type="button"+ className="cu-btn cu-btn--ghost cu-btn--sm"+ onClick={() => setEditing(true)}+ disabled={busy}+ >+ Edit+ </button>+ </>) : null}</div></div>diff --git a/control-ui/components/Sidebar/constants.tsx b/control-ui/components/Sidebar/constants.tsxindex 7a5aca3b8..e9e7dc63d 100644--- a/control-ui/components/Sidebar/constants.tsx+++ b/control-ui/components/Sidebar/constants.tsx@@ -34,7 +34,7 @@ export const SIDEBAR_TABS: Record<SidebarTab, SidebarItem> = {},contexts: { label: 'Contexts', href: CONTROL_ROUTES.contexts.root, icon: <IconGroupWork /> },guardrails: {- label: 'Guardrails',+ label: 'Installed Guardrails',href: CONTROL_ROUTES.guardrails.root,icon: <IconShield />,},diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 2dab034a7..8e700c39e 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.393",+ "version": "0.1.394","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.393",+ "version": "0.1.394","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex dd8c70fc9..215e8522f 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.393",+ "version": "0.1.394","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",