import { AgentStatus, type AgentTags } from '../types/organization/agent.js'; import { DATABASE_LIFECYCLE_TAG_OPERATIONS } from './index.js'; export type AgentLifecycleTagSource = { status?: AgentStatus | string; tags?: AgentTags; }; /** * Whether an agent list shows Native DB opted in for provisioning. * * Coarse registration check for product advertising (Clark tools/prompts, * UI Databases entry): an active agent must publish `ensure_database` and * serve at least one profile. Profile-key resolution, engine support, and * managed-IAM admission stay on the server at ensure/dispatch time — this * helper does not re-encode that surface. * * Agents without a confirmed active status are excluded (fail closed). */ export function hasEditLifecycleCapability(agents: readonly AgentLifecycleTagSource[] | undefined): boolean { if (!agents || agents.length === 0) { return false; } return agents.some((agent) => { if (agent.status === undefined || (agent.status !== AgentStatus.ACTIVE && agent.status !== 'Active')) { return false; } const operations = agent.tags?.[DATABASE_LIFECYCLE_TAG_OPERATIONS] ?? []; if (!operations.includes('ensure_database')) { return false; } return (agent.tags?.profile ?? []).length > 0; }); }