import { z } from "zod"; export const AGENT_INTERACTION_PERMISSION_KEYS = [ "canAssignTasksToAgents", "canReceiveAssignmentsFromAgents", "canAssignTasksToHumans", "canMentionAgents", "canReceiveMentionsFromAgents", "canCommentOnOtherTasks", "canReceiveCommentsFromAgents", "canEditOtherTasks", "canReceiveTaskEditsFromAgents", "canConfigureOtherAgents", "canReceiveConfigurationChangesFromAgents", ] as const; export type AgentInteractionPermissionKey = (typeof AGENT_INTERACTION_PERMISSION_KEYS)[number]; export type AgentInteractionPermissions = Partial>; export type AgentInteractionPermissionsPatch = Partial>; const shape = Object.fromEntries(AGENT_INTERACTION_PERMISSION_KEYS.map(key => [key, z.boolean().optional()])) as Record>; const patchShape = Object.fromEntries(AGENT_INTERACTION_PERMISSION_KEYS.map(key => [key, z.boolean().nullable().optional()])) as Record>>; export const agentInteractionPermissionsSchema = z.object(shape).strict(); export const updateAgentInteractionPermissionsSchema = z.object(patchShape).strict() .refine(value => Object.keys(value).length > 0, "Provide at least one interaction permission"); export function resolveAgentInteractionPermissions(value: unknown): Record { const record = value && typeof value === "object" && !Array.isArray(value) ? value as Record : {}; return Object.fromEntries(AGENT_INTERACTION_PERMISSION_KEYS.map(key => [key, record[key] !== false])) as Record; } export interface AgentInteractionPermissionsState { agentId: string; companyId: string; overrides: AgentInteractionPermissions; effective: Record; }