export const PARENT_AGENT_ID_LABEL = "paseo.parent-agent-id"; const OPEN_AGENT_TAB_LABEL_PREFIX = "paseo.open-agent-tab."; export function getOpenAgentTabLabel(clientId: string): string { return `${OPEN_AGENT_TAB_LABEL_PREFIX}${clientId}`; } export function isOpenAgentTabLabel(label: string): boolean { return label.startsWith(OPEN_AGENT_TAB_LABEL_PREFIX); } export interface AgentLabelSource { labels?: Record | null; } export function getParentAgentIdFromLabels(labels: Record | null | undefined) { const parentAgentId = labels?.[PARENT_AGENT_ID_LABEL]; return typeof parentAgentId === "string" && parentAgentId.trim().length > 0 ? parentAgentId.trim() : null; } export function isDelegatedAgent(agent: AgentLabelSource): boolean { return getParentAgentIdFromLabels(agent.labels) !== null; } export function hasOpenAgentTab(labels: Record | null | undefined): boolean { return Object.entries(labels ?? {}).some( ([label, value]) => isOpenAgentTabLabel(label) && value === "true", ); }