/**
 * Agent Registry Service
 *
 * This service provides agent registration and management functionality.
 * It allows registering agents with roles (director, worker, steward) and
 * querying agents by various criteria.
 *
 * Key features:
 * - Register agents with specific roles
 * - Query agents by role, status, and other filters
 * - Track agent session status
 * - Manage agent metadata
 * - Create dedicated channels for agent messaging (TB-O7a)
 *
 * @module
 */
import type { EntityId, Channel, ChannelId } from '@stoneforge/core';
import type { QuarryAPI } from '@stoneforge/quarry';
import type { AgentRole, AgentMetadata, AgentFilter, RegisterDirectorInput, RegisterWorkerInput, RegisterStewardInput } from '../types/index.js';
import { type AgentEntity, isAgentEntity, getAgentMetadata } from '../api/orchestrator-api.js';
export type { AgentEntity };
export { isAgentEntity, getAgentMetadata };
/**
 * Generates the channel name for an agent based on agent name
 * Channel names follow the pattern: agent-{agentName}
 */
export declare function generateAgentChannelName(agentName: string): string;
/**
 * Parses an agent name from a channel name
 * Returns null if the name doesn't match the agent channel pattern
 */
export declare function parseAgentChannelName(channelName: string): string | null;
/**
 * Generic agent registration input
 */
export type RegisterAgentInput = (RegisterDirectorInput & {
    role: 'director';
}) | (RegisterWorkerInput & {
    role: 'worker';
}) | (RegisterStewardInput & {
    role: 'steward';
});
/**
 * Agent Registry interface for managing agents in the orchestration system.
 *
 * The registry provides methods for:
 * - Registering agents with specific roles
 * - Querying agents by various criteria
 * - Managing agent session status
 */
export interface AgentRegistry {
    /**
     * Registers a new agent with the given parameters.
     * This is a convenience method that dispatches to the appropriate
     * role-specific registration method.
     */
    registerAgent(input: RegisterAgentInput): Promise<AgentEntity>;
    /**
     * Registers a Director agent.
     * There should typically be only one Director per workspace.
     */
    registerDirector(input: RegisterDirectorInput): Promise<AgentEntity>;
    /**
     * Registers a Worker agent.
     * Workers can be ephemeral (short-lived, task-specific) or persistent (long-lived).
     */
    registerWorker(input: RegisterWorkerInput): Promise<AgentEntity>;
    /**
     * Registers a Steward agent.
     * Stewards perform support tasks like merging branches and scanning documentation.
     */
    registerSteward(input: RegisterStewardInput): Promise<AgentEntity>;
    /**
     * Gets an agent by ID
     */
    getAgent(entityId: EntityId): Promise<AgentEntity | undefined>;
    /**
     * Gets an agent by name
     */
    getAgentByName(name: string): Promise<AgentEntity | undefined>;
    /**
     * Lists agents matching the filter
     */
    listAgents(filter?: AgentFilter): Promise<AgentEntity[]>;
    /**
     * Gets all agents with a specific role
     */
    getAgentsByRole(role: AgentRole): Promise<AgentEntity[]>;
    /**
     * Gets available workers (idle or with capacity for more tasks)
     */
    getAvailableWorkers(): Promise<AgentEntity[]>;
    /**
     * Gets all stewards
     */
    getStewards(): Promise<AgentEntity[]>;
    /**
     * Gets the Director agent (there should be only one per workspace)
     */
    getDirector(): Promise<AgentEntity | undefined>;
    /**
     * Updates an agent's session status
     */
    updateAgentSession(entityId: EntityId, sessionId: string | undefined, status: 'idle' | 'running' | 'suspended' | 'terminated'): Promise<AgentEntity>;
    /**
     * Updates an agent's metadata
     */
    updateAgentMetadata(entityId: EntityId, updates: Partial<AgentMetadata>): Promise<AgentEntity>;
    /**
     * Updates an agent's properties (e.g., name)
     */
    updateAgent(entityId: EntityId, updates: {
        name?: string;
    }): Promise<AgentEntity>;
    /**
     * Deletes an agent and its associated channel
     */
    deleteAgent(entityId: EntityId): Promise<void>;
    /**
     * Gets the dedicated channel for an agent.
     * Each agent has a channel named `agent-{agentId}` for receiving messages.
     *
     * @param agentId - The entity ID of the agent
     * @returns The agent's channel, or undefined if not found
     */
    getAgentChannel(agentId: EntityId): Promise<Channel | undefined>;
    /**
     * Gets the channel ID for an agent from its metadata.
     * This is faster than getAgentChannel() when you only need the ID.
     *
     * @param agentId - The entity ID of the agent
     * @returns The channel ID, or undefined if the agent has no channel
     */
    getAgentChannelId(agentId: EntityId): Promise<ChannelId | undefined>;
}
/**
 * Implementation of the Agent Registry service.
 *
 * This implementation uses the QuarryAPI for storage operations,
 * storing agent information as Entity elements with specialized metadata.
 */
export declare class AgentRegistryImpl implements AgentRegistry {
    private readonly api;
    constructor(api: QuarryAPI);
    registerAgent(input: RegisterAgentInput): Promise<AgentEntity>;
    registerDirector(input: RegisterDirectorInput): Promise<AgentEntity>;
    registerWorker(input: RegisterWorkerInput): Promise<AgentEntity>;
    registerSteward(input: RegisterStewardInput): Promise<AgentEntity>;
    getAgent(entityId: EntityId): Promise<AgentEntity | undefined>;
    getAgentByName(name: string): Promise<AgentEntity | undefined>;
    listAgents(filter?: AgentFilter): Promise<AgentEntity[]>;
    getAgentsByRole(role: AgentRole): Promise<AgentEntity[]>;
    getAvailableWorkers(): Promise<AgentEntity[]>;
    getStewards(): Promise<AgentEntity[]>;
    getDirector(): Promise<AgentEntity | undefined>;
    updateAgentSession(entityId: EntityId, sessionId: string | undefined, status: 'idle' | 'running' | 'suspended' | 'terminated'): Promise<AgentEntity>;
    updateAgentMetadata(entityId: EntityId, updates: Partial<AgentMetadata>): Promise<AgentEntity>;
    updateAgent(entityId: EntityId, updates: {
        name?: string;
    }): Promise<AgentEntity>;
    deleteAgent(entityId: EntityId): Promise<void>;
    getAgentChannel(agentId: EntityId): Promise<Channel | undefined>;
    getAgentChannelId(agentId: EntityId): Promise<ChannelId | undefined>;
    /**
     * Creates an IdGeneratorConfig with a collision checker that queries the
     * database for existing element IDs. Without this, generateId() has no way
     * to detect that a truncated hash already exists, leading to
     * SQLITE_CONSTRAINT_PRIMARYKEY errors on INSERT.
     */
    private getIdGeneratorConfig;
    /**
     * Creates an agent entity, its channel, and links them via metadata.
     * Rolls back on partial failure to prevent orphaned resources.
     */
    private registerAgentWithRollback;
    /**
     * Creates a dedicated channel for an agent and updates the agent's metadata
     * with the channel ID.
     *
     * @param agentName - The name of the agent (used for channel naming)
     * @param agentId - The ID of the agent entity (used for membership)
     * @param createdBy - The entity that created the agent (will be a channel member)
     * @returns The created channel
     */
    private createAgentChannel;
    private applyFilters;
}
/**
 * Creates an AgentRegistry instance
 */
export declare function createAgentRegistry(api: QuarryAPI): AgentRegistry;
//# sourceMappingURL=agent-registry.d.ts.map