export const INITIAL_CONTROL_PLANE_SESSION_SNAPSHOT = {
    sessions: [],
    activeSession: null,
    runtimeContext: undefined,
    modelOptions: undefined,
    pendingApproval: null,
    pendingDirectShellConfirmation: undefined,
    loading: false,
    submitting: false,
    approvalResolving: false,
    running: false,
    cancelling: false,
    streamConnected: false,
    recentEditDiffs: [],
    commandResults: [],
    commandResultExpanded: false,
};
/**
 * Owns the cli-v2 render snapshot and subscription mechanics.
 *
 * This class must stay generic: no API calls, no domain policy, no event
 * interpretation. Workflow controllers produce patches; this state object is
 * the single mutable source of truth consumed by Ink components.
 */
export class ControlPlaneSessionState {
    onChanged;
    listeners = new Set();
    snapshotValue = INITIAL_CONTROL_PLANE_SESSION_SNAPSHOT;
    constructor(onChanged) {
        this.onChanged = onChanged;
    }
    getSnapshot = () => this.snapshotValue;
    subscribe = (listener) => {
        this.listeners.add(listener);
        return () => {
            this.listeners.delete(listener);
        };
    };
    patch(next) {
        const patch = typeof next === 'function' ? next(this.snapshotValue) : next;
        this.snapshotValue = {
            ...this.snapshotValue,
            ...patch,
        };
        this.onChanged?.();
        this.listeners.forEach((listener) => listener());
    }
    requireWorkspaceId() {
        const workspaceId = this.snapshotValue.workspaceId;
        if (!workspaceId) {
            throw new Error('Control-plane workspace is not loaded.');
        }
        return workspaceId;
    }
    requireActiveSessionId() {
        const sessionId = this.snapshotValue.activeSessionId;
        if (!sessionId) {
            throw new Error('No active control-plane session is selected.');
        }
        return sessionId;
    }
    isActiveSessionAddress(workspaceId, sessionId) {
        return this.snapshotValue.workspaceId === workspaceId && this.snapshotValue.activeSessionId === sessionId;
    }
}
//# sourceMappingURL=control-plane-session-state.js.map