import { M as MessageStatus, R as RuntimeStatus, T as ToolCallStatus } from '../types-ajANVzf7.js';
import '../agent-CW9XbmG_.js';
import 'zod';
import '../errors-C-so0M4t.js';
import '../types-BxggH0Yh.js';
import '../errors-CmVvczxZ.js';

/**
 * @witqq/agent-sdk/chat/state
 *
 * Validated state machines for runtime, message, and tool-call lifecycles.
 * Generic StateMachine<S> with declarative transition maps.
 */

/** Map of allowed transitions: current state → set of valid next states */
type TransitionMap<S extends string> = Readonly<Record<S, readonly S[]>>;
/**
 * Generic validated state machine.
 * Enforces that every transition is declared in the transition map.
 * Throws ChatError(INVALID_TRANSITION) on illegal moves.
 */
declare class StateMachine<S extends string> {
    readonly initial: S;
    readonly transitions: TransitionMap<S>;
    private _current;
    constructor(initial: S, transitions: TransitionMap<S>);
    /** Current state */
    get current(): S;
    /**
     * Check whether transitioning to `next` is allowed from current state
     * @param next - Target state to check
     * @returns True if transition is allowed
     */
    canTransition(next: S): boolean;
    /**
     * Transition to `next` state.
     * @throws ChatError(INVALID_TRANSITION) if the transition is not allowed
     */
    transition(next: S): void;
    /** Reset to initial state */
    reset(): void;
}
/** Allowed transitions for RuntimeStatus (idle → streaming/disposed, etc.) */
declare const RUNTIME_TRANSITIONS: TransitionMap<RuntimeStatus>;
/** Allowed transitions for MessageStatus (pending → streaming → complete, etc.) */
declare const MESSAGE_TRANSITIONS: TransitionMap<MessageStatus>;
/** Allowed transitions for ToolCallStatus (pending → running → complete, etc.) */
declare const TOOL_CALL_TRANSITIONS: TransitionMap<ToolCallStatus>;
/** Create a RuntimeStatus state machine starting at "idle" */
declare function createRuntimeStateMachine(): StateMachine<RuntimeStatus>;
/** Create a MessageStatus state machine starting at "pending" */
declare function createMessageStateMachine(): StateMachine<MessageStatus>;
/** Create a ToolCallStatus state machine starting at "pending" */
declare function createToolCallStateMachine(): StateMachine<ToolCallStatus>;
/**
 * Guards against concurrent send() calls in a chat runtime.
 * acquire() before work, release() after (use try/finally).
 * Throws ChatError(REENTRANCY) if already acquired.
 */
declare class ChatReentrancyGuard {
    private _acquired;
    /** Whether the guard is currently held */
    get isAcquired(): boolean;
    /**
     * Acquire the guard. Throws if already acquired.
     * @throws ChatError with code REENTRANCY
     */
    acquire(): void;
    /** Release the guard. Safe to call even if not acquired. */
    release(): void;
}
/**
 * Abort controller with external signal linking.
 * Wraps an AbortController and optionally links an external AbortSignal
 * so aborting either side cancels the operation.
 */
declare class ChatAbortController {
    private readonly _controller;
    private readonly _onExternalAbort?;
    private readonly _externalSignal?;
    constructor(externalSignal?: AbortSignal);
    /** The AbortSignal for this controller */
    get signal(): AbortSignal;
    /** Whether the operation has been aborted */
    get isAborted(): boolean;
    /**
     * Abort the operation.
     * @param reason - Optional abort reason
     */
    abort(reason?: unknown): void;
    /** Clean up external signal listener to prevent memory leaks */
    dispose(): void;
}

export { ChatAbortController, ChatReentrancyGuard, MESSAGE_TRANSITIONS, RUNTIME_TRANSITIONS, StateMachine, TOOL_CALL_TRANSITIONS, type TransitionMap, createMessageStateMachine, createRuntimeStateMachine, createToolCallStateMachine };
