Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-api): add llm-hooks resource endpoints + namespace (bucket b slice b)
Andy Paviadc67b8b36e84
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 49284f613..d052d9440 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.432",+ "version": "0.1.433","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.432",+ "version": "0.1.433","dependencies": {"@clerum/image-policy": "file:../packages/image-policy","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-api/package.json b/control-api/package.jsonindex 62a5d275c..e2b561351 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.432",+ "version": "0.1.433","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/config.ts b/control-api/src/config.tsindex 033cb2afe..8092e4b78 100644--- a/control-api/src/config.ts+++ b/control-api/src/config.ts@@ -9,6 +9,7 @@ type Config = {contextsNamespace: stringcommunicationChannelsNamespace: stringmcpServersNamespace: string+ llmHooksNamespace: stringsandboxNamespace: stringsandboxUiNamespace: stringsecretsNamespace: string@@ -315,6 +316,7 @@ function intervalMsFromEnv(name: string, defaultValue: number, minValue: number)// services/llmAllowedModelsConfigMap.ts.const HOSTS_NAMESPACE = process.env.CONTROL_API_HOSTS_NAMESPACE || 'mcp-host'const MCP_SERVERS_NAMESPACE = process.env.CONTROL_API_MCP_SERVERS_NAMESPACE || 'mcp-server'+const LLM_HOOKS_NAMESPACE = process.env.CONTROL_API_LLM_HOOKS_NAMESPACE || 'llm-hooks'const SANDBOX_NAMESPACE = process.env.CONTROL_API_SANDBOX_NAMESPACE || 'sandbox-recipes'const SANDBOX_UI_NAMESPACE = process.env.CONTROL_API_SANDBOX_UI_NAMESPACE || 'sandbox-ui'const DEFAULT_MCP_HOST_JWT_MAX_HOST_REFS = 32@@ -491,6 +493,7 @@ export const config: Config = {communicationChannelsNamespace:process.env.CONTROL_API_COMMUNICATION_CHANNELS_NAMESPACE || 'channels',mcpServersNamespace: MCP_SERVERS_NAMESPACE,+ llmHooksNamespace: LLM_HOOKS_NAMESPACE,sandboxNamespace: SANDBOX_NAMESPACE,sandboxUiNamespace: SANDBOX_UI_NAMESPACE,secretsNamespace: process.env.CONTROL_API_SECRETS_NAMESPACE || 'mcp-host',@@ -842,6 +845,7 @@ const NAMESPACE_KEYS: (keyof Config)[] = ['contextsNamespace','communicationChannelsNamespace','mcpServersNamespace',+ 'llmHooksNamespace','sandboxNamespace','sandboxUiNamespace','secretsNamespace',diff --git a/control-api/src/k8s.ts b/control-api/src/k8s.tsindex c50ab23da..027e133ec 100644--- a/control-api/src/k8s.ts+++ b/control-api/src/k8s.ts@@ -183,6 +183,9 @@ export class K8sGateway {contexts: config.contextsNamespace,communicationchannels: config.communicationChannelsNamespace,mcpservers: config.mcpServersNamespace,+ // Installed guardrail LlmHook CRs live in the llm-hooks namespace (§12.1);+ // control-api reads/deletes them, host-context-controller reconciles pods.+ llmhooks: config.llmHooksNamespace,// Design invariant: WorkflowRecipe CRDs always live in sandbox-recipes,// co-located with the workflow coordinator and recipe mcp-host pods.// The mcp-server namespace is reserved for McpServer transport childrendiff --git a/control-api/src/routes/admin/resources.ts b/control-api/src/routes/admin/resources.tsindex 544704dc7..941ae84b1 100644--- a/control-api/src/routes/admin/resources.ts+++ b/control-api/src/routes/admin/resources.ts@@ -228,6 +228,8 @@ const RESOURCE_MAP: Record<string, AdminResourceType> = {'communication-channels': 'communicationchannels',mcpservers: 'mcpservers','mcp-servers': 'mcpservers',+ llmhooks: 'llmhooks',+ 'llm-hooks': 'llmhooks',}function resourceNamespace(plural: AdminResourceType): string {@@ -240,6 +242,8 @@ function resourceNamespace(plural: AdminResourceType): string {return config.communicationChannelsNamespacecase 'mcpservers':return config.mcpServersNamespace+ case 'llmhooks':+ return config.llmHooksNamespace}}@@ -261,6 +265,14 @@ function communicationChannelMatchesConfirmedUser(item: unknown, userId: string)const RESOURCE_PATTERN ='/admin/:resource(hosts|contexts|communication-channels|communicationchannels|mcp-servers|mcpservers)'+// LlmHook guardrail CRs get READ + DELETE only through the generic router.+// Creation/update goes through the org-scoped registry `install-hook` saga+// (registry.ts) so the install-time trust_level + image-allowlist preflight+// cannot be bypassed by a raw POST/PUT — the same reason recipes are not in the+// generic CRUD pattern. This lane powers the control-ui cluster-wide list, the+// per-hook status detail, and uninstall.+const LLMHOOK_PATTERN = '/admin/:resource(llmhooks|llm-hooks)'+/** Resolve the plural type and canonical namespace for a resource route param. */function resolveResource(param: string): { plural: AdminResourceType; ns: string } | null {const plural = RESOURCE_MAP[param]@@ -643,5 +655,48 @@ export function createAdminResourcesRouter(gateway: K8sGateway): Router {registerCommunicationChannelCredentialsRoutes(router, gateway)+ // ── LlmHook guardrail CRs: read + delete only (see LLMHOOK_PATTERN) ──────────+ router.use(LLMHOOK_PATTERN, (req: Request, _res: Response, next: NextFunction) => {+ const resolved = resolveResource(req.params.resource)+ if (resolved) {+ enforceNamespace(resolved.ns)(req, _res, next)+ } else {+ next()+ }+ })++ // Cluster-wide list (control-ui hooks dashboard).+ router.get(+ LLMHOOK_PATTERN,+ asyncHandler(async (req, res) => {+ const { plural, ns } = resolveResource(req.params.resource)!+ const items = await gateway.listResource(plural, ns)+ res.status(200).json({ items })+ })+ )++ // Single hook (status detail / digest drift).+ router.get(+ `${LLMHOOK_PATTERN}/:name`,+ asyncHandler(async (req, res) => {+ const { plural, ns } = resolveResource(req.params.resource)!+ const resource = await gateway.getResource(plural, req.params.name, ns)+ res.status(200).json(resource)+ })+ )++ // Uninstall. Deletes the LlmHook CR; host-context-controller garbage-collects+ // the shared pod once the last referencing hook is gone. Removing the {id}+ // reference from any Host.spec.guardrails.hooks is owned by the install/uninstall+ // saga (registry.ts) alongside the credential-Secret lifecycle.+ router.delete(+ `${LLMHOOK_PATTERN}/:name`,+ asyncHandler(async (req, res) => {+ const { plural, ns } = resolveResource(req.params.resource)!+ const deleted = await gateway.deleteResource(plural, req.params.name, ns)+ res.status(200).json(deleted)+ })+ )+return router}diff --git a/control-api/src/types.ts b/control-api/src/types.tsindex cc33eed1f..58b48e477 100644--- a/control-api/src/types.ts+++ b/control-api/src/types.ts@@ -6,6 +6,7 @@ export type ClerumResourceType =| 'contexts'| 'communicationchannels'| 'mcpservers'+ | 'llmhooks'| 'workflowrecipes'| 'workflowrecipepolicies'| 'sharedfilesystems'