import type { ToolDefinition } from "@sheason/pi-coding-agent";
import type { HubAgentAdapter } from "../agent/hub-agent-adapter.js";
import type { HubAuthIdentity } from "../auth/token-store.js";
import type { PeerConfigSnapshot } from "../config-aggregation/types.js";
import type { McpRuntimeStatus } from "../mcp/types.js";
import type { PeerRegistry } from "../peers/peer-registry.js";
import type { RegisteredPeer } from "../peers/peer-types.js";
import type { HubSessionService } from "../session/hub-session-service.js";
import type { HubSessionEvent } from "../session/session-events.js";
import type { SourceRuntimeStatus } from "../sources/source-types.js";
import type { HubLogSink } from "../tui/hub-log.js";
import type { LiveRenderEvent, PublicOrgSnapshot, SessionMutateMcpServerAck, ToolCallAckPayload, ToolCallErrorPayload, ToolCallRequestPayload, ToolCallResultPayload, ToolCallUpdatePayload } from "./protocol.js";
export declare function shouldCompressCrdtPayload(byteLength: number): boolean;
/**
 * Per-agent view of what the transport needs from `HubAgentRuntime` (keeps `socket-hub` free of
 * a runtime import cycle with `HubAgentRuntime` importing this module).
 */
export interface HubAgentSocketBinding {
    sessionService: HubSessionService;
    peerRegistry: PeerRegistry;
    tools: ToolDefinition[];
    agentAdapter: HubAgentAdapter | undefined;
}
export interface HubAgentSocketMetadata {
    parentId?: string;
    kind?: "root" | "child" | "guest";
    lifecycle?: "persistent" | "temporary";
    name?: string;
    description?: string;
}
export interface SocketHubServerSourceMutators {
    pause: (name: string) => Promise<void>;
    restart: (name: string) => Promise<void>;
    remove: (name: string) => Promise<void>;
}
export interface SocketHubServerMcpMutators {
    pauseServer: (agentId: string, name: string) => Promise<SessionMutateMcpServerAck>;
    restartServer: (agentId: string, name: string) => Promise<SessionMutateMcpServerAck>;
    removeServer: (agentId: string, name: string) => Promise<SessionMutateMcpServerAck>;
}
export interface SocketHubServerCrdtCompactThresholds {
    idleChangeCount: number;
    activeChangeCount: number;
}
export interface SocketHubServerAddress {
    host: string;
    port: number;
}
export interface SocketHubServerOptions {
    host: string;
    port: number;
}
export interface SocketHubServerToolCallEvent<TPayload> {
    peer: RegisteredPeer;
    payload: TPayload;
}
export interface SocketHubServerDeps {
    getDefaultAgentId: () => string;
    getAgentIds: () => string[];
    getAgentRuntime: (agentId: string) => HubAgentSocketBinding | undefined;
    ensureAgentStarted?: (agentId: string) => Promise<HubAgentSocketBinding | undefined>;
    getAgentMetadata?: (agentId: string) => HubAgentSocketMetadata | undefined;
    getPublicOrgSnapshot?: () => PublicOrgSnapshot;
    authenticateToken: (token: string) => HubAuthIdentity | undefined | Promise<HubAuthIdentity | undefined>;
    isAgentInScope: (identity: HubAuthIdentity, targetAgentId: string) => boolean;
    getHttpSessionService: () => HubSessionService;
    /** Subscribe to all agents' `HubSessionService` event streams and update the CRDT view model. */
    subscribeAllAgentSessionEvents: (onEvent: (agentId: string, event: HubSessionEvent) => void) => () => void;
    getSourceStatuses: (agentId: string) => SourceRuntimeStatus[];
    getSourceMessageTargetAgentIds?: (boundAgentId: string, sourceName: string, requestedAgentId?: string) => string[];
    sourceMutators: SocketHubServerSourceMutators;
    getMcpServerStatuses: (agentId: string) => McpRuntimeStatus[];
    getMcpConfigError: (agentId: string) => string | undefined;
    onPeerConfigSnapshot?: (agentId: string, peerId: string, snapshot: PeerConfigSnapshot) => void;
    onPeerConfigRemoved?: (agentId: string, peerId: string) => void;
    mcpMutators: SocketHubServerMcpMutators;
    crdtCompactThresholds?: SocketHubServerCrdtCompactThresholds;
    logs?: HubLogSink;
    webUiDistDir?: string;
}
export declare class SocketHubServer {
    private readonly deps;
    private httpServer;
    private io;
    private address;
    private readonly imagePayloadCache;
    private readonly socketAgentIds;
    private readonly socketIdentities;
    private readonly socketClientKinds;
    private readonly socketHostIds;
    private readonly viewDocuments;
    private readonly viewImagesByAgentId;
    private readonly crdtSyncStatesBySocketId;
    private readonly initialCrdtSyncTimersBySocketId;
    /**
     * Per-agent throttle so a burst of mutations only triggers one compaction check per
     * {@link CRDT_COMPACT_THROTTLE_MS}. The check itself is O(1) (`view.getChangeCount()` is a
     * cached counter), but `compactHistory()` rewrites Automerge state and is far more expensive,
     * so we batch decisions instead of checking on every mutation.
     */
    private readonly compactCheckTimersByAgentId;
    private unsubscribeSessionEvents;
    private readonly toolCallAckListeners;
    private readonly toolCallUpdateListeners;
    private readonly toolCallResultListeners;
    private readonly toolCallErrorListeners;
    constructor(deps: SocketHubServerDeps);
    private log;
    private logPeerMcpSnapshotErrors;
    start(options: SocketHubServerOptions): Promise<SocketHubServerAddress>;
    stop(): Promise<void>;
    disconnectAgentPeers(agentId: string): number;
    disconnectToken(tokenId: string): number;
    deliverGuestAgentMessage(fromAgentId: string, toAgentId: string, message: string, options?: {
        messageId?: string;
        responseIds?: string[];
    }): number;
    initializeViewDocumentsForAgents(agentIds: string[]): void;
    refreshAgentListViews(): void;
    initializeViewDocumentForAgent(agentId: string, options?: {
        syncAgentList?: boolean;
    }): void;
    private getBoundRuntime;
    private handleConnection;
    private handleSourceMessage;
    private broadcastPeerListForAgent;
    private resolveToolCallPeerForSocket;
    private rememberViewImages;
    private getViewDocument;
    private getCrdtCompactThresholds;
    private getConnectedCrdtSocketsForAgent;
    private hasConnectedCrdtPeerForAgent;
    /**
     * Throttled trigger for {@link maybeCompactCrdtHistoryForAgent}: a burst of mutations only
     * incurs one check per {@link CRDT_COMPACT_THROTTLE_MS} window. We use a leading-edge timer
     * (set on the first mutation, run later) so quiet periods do not keep retiring the timer.
     */
    private scheduleCompactCheckForAgent;
    private clearCrdtSyncStatesForSockets;
    private maybeCompactCrdtHistoryForAgent;
    private syncAgentListToAllViewDocuments;
    private updateAgentMetadataInView;
    private updateAgentSummaryInView;
    private updateAgentPreviewInView;
    private scheduleCrdtFanoutForAllAgents;
    private resetCrdtSyncForSocket;
    private emitPendingCrdtSyncToSocket;
    private scheduleCrdtFanoutForAgent;
    private flushCrdtFanoutForAgent;
    private emitSessionEventForAgent;
    private getBoundSessionEventViewAgentIds;
    private logSocketFanout;
    broadcastLiveEvent(agentId: string, event: LiveRenderEvent): void;
    sendToolCallRequest(agentId: string, peerId: string, payload: ToolCallRequestPayload): void;
    onToolCallAck(listener: (event: SocketHubServerToolCallEvent<ToolCallAckPayload>) => void): () => void;
    onToolCallUpdate(listener: (event: SocketHubServerToolCallEvent<ToolCallUpdatePayload>) => void): () => void;
    onToolCallResult(listener: (event: SocketHubServerToolCallEvent<ToolCallResultPayload>) => void): () => void;
    onToolCallError(listener: (event: SocketHubServerToolCallEvent<ToolCallErrorPayload>) => void): () => void;
    private emitToolCallAck;
    private emitToolCallUpdate;
    private emitToolCallResult;
    private emitToolCallError;
    private getRegisteredPeerForSocket;
    private registeredPeerFromSocketForAction;
    private registeredClientFromSocketForAction;
    private registeredPeerFromSocketForSources;
    private registeredPeerFromSocketForSourceMutate;
    private registeredPeerFromSocketForMcpGet;
    private registeredPeerFromSocketForSkillGet;
    private registeredPeerFromSocketForMcpMutate;
    private getAdapterForSocketAction;
    private handleSimpleAction;
    private handleSetModel;
    private handleSetThinkingLevel;
    private handleInvokeCommand;
}
/**
 * Single default-agent layout, matching pre-multi-agent `SocketHubServer` construction for tests
 * and focused harnesses.
 */
export declare function createMainOnlySocketHubServer(sessionService: HubSessionService, peerRegistry: PeerRegistry, getHubToolNames: () => string[], getAgentAdapter: () => HubAgentAdapter | undefined, getSourceStatuses?: SocketHubServerDeps["getSourceStatuses"], sourceMutators?: SocketHubServerSourceMutators, getMcpServerStatuses?: () => McpRuntimeStatus[], getMcpConfigError?: () => string | undefined, mcpMutators?: SocketHubServerMcpMutators, webUiDistDir?: string, logs?: HubLogSink): SocketHubServer;
//# sourceMappingURL=socket-hub-server.d.ts.map