import * as fs from "fs";
import type { SubagentConfiguration } from "../utils/subagentParser.js";
import type { Message, Usage } from "../types/index.js";
import { AIManager } from "./aiManager.js";
import { MessageManager } from "./messageManager.js";
import { ToolManager } from "./toolManager.js";
import { UserMessageParams, type AgentToolBlockUpdateParams } from "../utils/messageOperations.js";
import { Container } from "../utils/container.js";
import type { PermissionMode } from "../types/permissions.js";
export interface SubagentManagerCallbacks {
    /** Triggered when subagent adds user message */
    onSubagentUserMessageAdded?: (subagentId: string, params: UserMessageParams) => void;
    /** Triggered when subagent creates assistant message */
    onSubagentAssistantMessageAdded?: (subagentId: string) => void;
    /** Triggered during subagent content streaming updates */
    onSubagentAssistantContentUpdated?: (subagentId: string, chunk: string, accumulated: string) => void;
    /** Triggered during subagent reasoning streaming updates */
    onSubagentAssistantReasoningUpdated?: (subagentId: string, chunk: string, accumulated: string) => void;
    /** Triggered when subagent tool block is updated */
    onSubagentToolBlockUpdated?: (subagentId: string, params: AgentToolBlockUpdateParams) => void;
    /** Triggered when subagent messages change */
    onSubagentMessagesChange?: (subagentId: string, messages: Message[]) => void;
    /** Triggered when subagent latest total tokens change */
    onSubagentLatestTotalTokensChange?: (subagentId: string, tokens: number) => void;
}
export interface SubagentInstance {
    subagentId: string;
    configuration: SubagentConfiguration;
    aiManager: AIManager;
    messageManager: MessageManager;
    toolManager: ToolManager;
    status: "initializing" | "active" | "completed" | "error" | "aborted";
    messages: Message[];
    lastTools: string[];
    subagentType: string;
    description: string;
    allowedTools?: string[];
    backgroundTaskId?: string;
    onUpdate?: () => void;
    model?: string;
    logStream?: fs.WriteStream;
}
export interface SubagentManagerOptions {
    workdir: string;
    callbacks?: SubagentManagerCallbacks;
    onUsageAdded?: (usage: Usage) => void;
    stream: boolean;
}
export declare class SubagentManager {
    private instances;
    private subagentPermissionManagers;
    private cachedConfigurations;
    private workdir;
    private callbacks?;
    private onUsageAdded?;
    private container;
    private stream;
    constructor(container: Container, options: SubagentManagerOptions);
    private get configurationService();
    /**
     * Initialize the SubagentManager by loading and caching configurations
     */
    initialize(): Promise<void>;
    /**
     * Sync parent permission rules to all running subagents
     */
    private syncPermissionRulesToSubagents;
    /**
     * Load all available subagent configurations and cache them
     */
    loadConfigurations(): Promise<SubagentConfiguration[]>;
    /**
     * Get cached configurations synchronously (must call loadConfigurations first)
     */
    getConfigurations(): SubagentConfiguration[];
    /**
     * Find subagent by exact name match
     */
    findSubagent(name: string): Promise<SubagentConfiguration | null>;
    /**
     * Create a new subagent instance with isolated managers
     */
    createInstance(configuration: SubagentConfiguration, parameters: {
        description: string;
        prompt: string;
        subagent_type: string;
        allowedTools?: string[];
        model?: string;
        stream?: boolean;
        permissionModeOverride?: PermissionMode;
    }, runInBackground?: boolean, onUpdate?: () => void): Promise<SubagentInstance>;
    /**
     * Execute agent using subagent instance
     *
     * IMPORTANT: This method automatically filters out the Agent tool from allowedTools
     * to prevent subagents from spawning other subagents (infinite recursion protection)
     */
    executeAgent(instance: SubagentInstance, prompt: string, abortSignal?: AbortSignal, runInBackground?: boolean): Promise<string>;
    backgroundInstance(subagentId: string): Promise<string>;
    private internalExecute;
    /**
     * Get instance by subagent ID
     */
    getInstance(subagentId: string): SubagentInstance | null;
    /**
     * Update instance status
     */
    updateInstanceStatus(subagentId: string, status: SubagentInstance["status"]): void;
    /**
     * Add message to instance
     */
    addMessageToInstance(subagentId: string, message: Message): void;
    /**
     * Clean up completed, errored, or aborted instances
     */
    cleanupInstance(subagentId: string): void;
    /**
     * Get all active instances
     */
    getActiveInstances(): SubagentInstance[];
    /**
     * Clean up all instances (for session end)
     */
    cleanup(): void;
    /**
     * Create subagent callbacks for a specific subagent ID
     * Extracted to reuse in both create and restore flows
     */
    private createSubagentCallbacks;
}
//# sourceMappingURL=subagentManager.d.ts.map