/**
 * Dispatch Service
 *
 * This service provides the dispatch operation that combines task assignment
 * with agent notification.
 *
 * Key features:
 * - Dispatch tasks to specific agents (assigns task + sends notification)
 * - Support for priority and restart options
 *
 * @module
 */
import type { Task, ElementId, EntityId, Message, Channel, Timestamp } from '@stoneforge/core';
import type { QuarryAPI } from '@stoneforge/quarry';
import type { AgentEntity } from '../api/orchestrator-api.js';
import type { TaskAssignmentService } from './task-assignment-service.js';
import type { AgentRegistry } from './agent-registry.js';
/**
 * Options for dispatching a task to an agent
 */
export interface DispatchOptions {
    /** Git branch for the task (auto-generated if not provided) */
    branch?: string;
    /** Worktree path for the task (auto-generated if not provided) */
    worktree?: string;
    /** Claude Code session ID */
    sessionId?: string;
    /** Priority level (higher = more urgent). Used for notification message. */
    priority?: number;
    /** Whether to signal the agent to restart its session */
    restart?: boolean;
    /** Whether to mark the task as started immediately */
    markAsStarted?: boolean;
    /** Custom notification message (defaults to standard task assignment message) */
    notificationMessage?: string;
    /** Additional metadata for the notification */
    notificationMetadata?: Record<string, unknown>;
    /** Entity performing the dispatch (for message sender) */
    dispatchedBy?: EntityId;
}
/**
 * Result of a dispatch operation
 */
export interface DispatchResult {
    /** The updated task after assignment */
    task: Task;
    /** The agent the task was dispatched to */
    agent: AgentEntity;
    /** The notification message sent to the agent */
    notification: Message;
    /** The channel the notification was sent to */
    channel: Channel;
    /** Whether this is a new assignment (true) or reassignment (false) */
    isNewAssignment: boolean;
    /** The dispatch timestamp */
    dispatchedAt: Timestamp;
}
/**
 * Message types for agent notifications
 */
export type DispatchMessageType = 'task-assignment' | 'task-reassignment' | 'restart-signal';
/**
 * Metadata structure for dispatch notification messages
 */
export interface DispatchNotificationMetadata {
    type: DispatchMessageType;
    taskId?: ElementId;
    priority?: number;
    restart?: boolean;
    branch?: string;
    worktree?: string;
    sessionId?: string;
    dispatchedAt: Timestamp;
    dispatchedBy?: EntityId;
    [key: string]: unknown;
}
/**
 * Dispatch Service interface for task dispatch operations.
 *
 * The service provides methods for:
 * - Dispatching tasks to specific agents
 * - Sending notifications to agents
 */
export interface DispatchService {
    /**
     * Dispatches a task to a specific agent.
     *
     * This method:
     * 1. Assigns the task to the agent (using TaskAssignmentService)
     * 2. Sends a notification message to the agent's channel
     * 3. Optionally signals the agent to restart
     *
     * @param taskId - The task to dispatch
     * @param agentId - The agent to dispatch to
     * @param options - Dispatch options
     * @returns The dispatch result
     */
    dispatch(taskId: ElementId, agentId: EntityId, options?: DispatchOptions): Promise<DispatchResult>;
    /**
     * Dispatches multiple tasks to the same agent.
     *
     * This is more efficient than calling dispatch() multiple times
     * as it batches the notification.
     *
     * @param taskIds - The tasks to dispatch
     * @param agentId - The agent to dispatch to
     * @param options - Dispatch options
     * @returns Array of dispatch results
     */
    dispatchBatch(taskIds: ElementId[], agentId: EntityId, options?: DispatchOptions): Promise<DispatchResult[]>;
    /**
     * Sends a notification to an agent without assigning a task.
     *
     * Useful for restart signals, status updates, etc.
     *
     * @param agentId - The agent to notify
     * @param messageType - Type of notification
     * @param content - Message content
     * @param metadata - Additional metadata
     * @returns The sent message
     */
    notifyAgent(agentId: EntityId, messageType: DispatchMessageType, content: string, metadata?: Record<string, unknown>): Promise<Message>;
}
/**
 * Implementation of the Dispatch Service.
 */
export declare class DispatchServiceImpl implements DispatchService {
    private readonly api;
    private readonly taskAssignment;
    private readonly agentRegistry;
    constructor(api: QuarryAPI, taskAssignment: TaskAssignmentService, agentRegistry: AgentRegistry);
    dispatch(taskId: ElementId, agentId: EntityId, options?: DispatchOptions): Promise<DispatchResult>;
    dispatchBatch(taskIds: ElementId[], agentId: EntityId, options?: DispatchOptions): Promise<DispatchResult[]>;
    notifyAgent(agentId: EntityId, messageType: DispatchMessageType, content: string, metadata?: Record<string, unknown>): Promise<Message>;
    /**
     * Creates the notification content for a dispatch
     */
    private createNotificationContent;
    /**
     * Sends a notification message to an agent's channel
     */
    private sendNotification;
}
/**
 * Creates a DispatchService instance
 */
export declare function createDispatchService(api: QuarryAPI, taskAssignment: TaskAssignmentService, agentRegistry: AgentRegistry): DispatchService;
//# sourceMappingURL=dispatch-service.d.ts.map