/**
 * Agent Role Definition Types
 *
 * This module defines the types for agent role definitions, which store
 * system prompts and behavioral configurations for agents.
 *
 * Role definitions allow agents to be configured with:
 * - System prompts stored as Documents
 * - Behavioral hooks for startup, task assignment, and stuck scenarios
 *
 * The system prompt is stored as a Document element, allowing versioning
 * and easy editing. The role definition references this document via its ID.
 */
// ============================================================================
// Type Guards
// ============================================================================
/**
 * Type guard for AgentBehaviors
 */
export function isAgentBehaviors(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    const obj = value;
    // All fields are optional strings
    const optionalStringFields = ['onStartup', 'onTaskAssigned', 'onStuck', 'onHandoff', 'onError'];
    for (const field of optionalStringFields) {
        if (obj[field] !== undefined && typeof obj[field] !== 'string') {
            return false;
        }
    }
    return true;
}
/**
 * Type guard for DirectorRoleDefinition
 */
export function isDirectorRoleDefinition(value) {
    if (!isBaseRoleDefinition(value)) {
        return false;
    }
    return value.role === 'director';
}
/**
 * Type guard for WorkerRoleDefinition
 */
export function isWorkerRoleDefinition(value) {
    if (!isBaseRoleDefinition(value)) {
        return false;
    }
    const def = value;
    if (def.role !== 'worker') {
        return false;
    }
    // workerMode is optional, but if present must be valid
    if (def.workerMode !== undefined && def.workerMode !== 'ephemeral' && def.workerMode !== 'persistent') {
        return false;
    }
    return true;
}
/**
 * Type guard for StewardRoleDefinition
 */
export function isStewardRoleDefinition(value) {
    if (!isBaseRoleDefinition(value)) {
        return false;
    }
    const def = value;
    if (def.role !== 'steward') {
        return false;
    }
    // stewardFocus is optional, but if present must be valid
    const validFoci = ['merge', 'docs', 'recovery', 'custom'];
    if (def.stewardFocus !== undefined && !validFoci.includes(def.stewardFocus)) {
        return false;
    }
    return true;
}
/**
 * Type guard for any AgentRoleDefinition
 */
export function isAgentRoleDefinition(value) {
    return isDirectorRoleDefinition(value) || isWorkerRoleDefinition(value) || isStewardRoleDefinition(value);
}
/**
 * Type guard for base role definition structure
 */
function isBaseRoleDefinition(value) {
    if (typeof value !== 'object' || value === null) {
        return false;
    }
    const obj = value;
    // Required fields
    if (typeof obj.role !== 'string')
        return false;
    if (typeof obj.name !== 'string')
        return false;
    if (typeof obj.systemPromptRef !== 'string')
        return false;
    if (typeof obj.createdAt !== 'string')
        return false;
    if (typeof obj.createdBy !== 'string')
        return false;
    if (typeof obj.updatedAt !== 'string')
        return false;
    // Optional fields
    if (obj.maxConcurrentTasks !== undefined && typeof obj.maxConcurrentTasks !== 'number')
        return false;
    if (obj.description !== undefined && typeof obj.description !== 'string')
        return false;
    if (obj.behaviors !== undefined && !isAgentBehaviors(obj.behaviors))
        return false;
    if (obj.tags !== undefined && !Array.isArray(obj.tags))
        return false;
    return true;
}
// ============================================================================
// Constants
// ============================================================================
/**
 * Tags used to identify role definition documents
 */
export const ROLE_DEFINITION_TAGS = {
    /** Main tag for all role definition documents */
    ROLE_DEFINITION: 'role-definition',
    /** Tag prefix for role type (e.g., 'role:director') */
    ROLE_PREFIX: 'role:',
    /** Tag prefix for agent prompt documents */
    AGENT_PROMPT: 'agent-prompt',
};
/**
 * Generates tags for a role definition document
 */
export function generateRoleDefinitionTags(role, additionalTags) {
    const tags = [
        ROLE_DEFINITION_TAGS.ROLE_DEFINITION,
        ROLE_DEFINITION_TAGS.AGENT_PROMPT,
        `${ROLE_DEFINITION_TAGS.ROLE_PREFIX}${role}`,
    ];
    if (additionalTags) {
        tags.push(...additionalTags);
    }
    return tags;
}
//# sourceMappingURL=role-definition.js.map