import { d as SDCPN } from "../sdcpn-CayOVwJM.js";
import { r as WorkerLike } from "../environment-Cg8b3IqY.js";
import { i as InitialMarking, t as EngineFrame } from "../internal-frame-DSPOSuKI.js";

//#region src/simulation/worker/create-simulation-worker.d.ts
/** Dynamically import and instantiate the simulation worker (inlined as blob URL). */
declare function createSimulationWorker(): Promise<WorkerLike>;
//#endregion
//#region src/simulation/worker/frame-payload.d.ts
/**
 * Worker protocol representation for a full frame payload.
 *
 * Time is attached by the run controller, not stored in `EngineFrame`.
 */
type SimulationFramePayload = {
  time: number;
  frame: EngineFrame;
};
//#endregion
//#region src/simulation/worker/messages.d.ts
/**
 * Initialize the simulation with SDCPN definition and configuration.
 * This compiles user code and creates the SimulationInstance in the worker.
 */
type InitMessage = {
  type: "init"; /** The SDCPN definition to simulate */
  sdcpn: SDCPN; /** Initial token distribution. JSON-serializable. */
  initialMarking: InitialMarking; /** Parameter values (overrides SDCPN defaults) */
  parameterValues: Record<string, string>; /** Random seed for deterministic stochastic behavior */
  seed: number; /** Time step for simulation advancement */
  dt: number; /** Maximum simulation time (immutable once set). Null means no limit. */
  maxTime: number | null; /** Maximum frames the worker can compute ahead before waiting for ack (backpressure) */
  maxFramesAhead?: number; /** Number of frames to compute in each batch before checking for messages */
  batchSize?: number;
};
/**
 * Start or resume computing frames.
 */
type StartMessage = {
  type: "start";
};
/**
 * Pause computation (retains simulation state).
 */
type PauseMessage = {
  type: "pause";
};
/**
 * Stop and discard the simulation entirely.
 */
type StopMessage = {
  type: "stop";
};
/**
 * Update backpressure configuration at runtime.
 */
type SetBackpressureMessage = {
  type: "setBackpressure"; /** Maximum frames the worker can compute ahead before waiting for ack */
  maxFramesAhead?: number; /** Number of frames to compute in each batch before checking for messages */
  batchSize?: number;
};
/**
 * Acknowledge receipt of frames up to a given number.
 * Used for backpressure to prevent worker from computing too far ahead.
 */
type AckMessage = {
  type: "ack"; /** The frame number that has been received by main thread */
  frameNumber: number;
};
/**
 * Union of all messages that can be sent from main thread to worker.
 */
type ToWorkerMessage = InitMessage | StartMessage | PauseMessage | StopMessage | SetBackpressureMessage | AckMessage;
/**
 * Worker has successfully initialized the simulation.
 */
type ReadyMessage = {
  type: "ready"; /** Number of frames in initial state (typically 1) */
  initialFrameCount: number;
};
/**
 * A new frame has been computed.
 */
type FrameMessage = {
  type: "frame";
  frame: SimulationFramePayload;
};
/**
 * Multiple frames computed (batch optimization).
 */
type FramesMessage = {
  type: "frames";
  frames: SimulationFramePayload[];
};
/**
 * Simulation has completed.
 */
type CompleteMessage = {
  type: "complete";
  reason: "deadlock" | "maxTime"; /** Final frame number */
  frameNumber: number;
};
/**
 * An error occurred in the worker.
 */
type ErrorMessage = {
  type: "error";
  message: string; /** ID of the SDCPN item that caused the error (if applicable) */
  itemId: string | null;
};
/**
 * Worker is paused and waiting.
 */
type PausedMessage = {
  type: "paused"; /** Current frame number when paused */
  frameNumber: number;
};
/**
 * Union of all messages that can be sent from worker to main thread.
 */
type ToMainMessage = ReadyMessage | FrameMessage | FramesMessage | CompleteMessage | ErrorMessage | PausedMessage;
//#endregion
export { type AckMessage, type CompleteMessage, type ErrorMessage, type FrameMessage, type FramesMessage, type InitMessage, type PauseMessage, type PausedMessage, type ReadyMessage, type SetBackpressureMessage, type StartMessage, type StopMessage, type ToMainMessage, type ToWorkerMessage, createSimulationWorker };
//# sourceMappingURL=simulation.d.d.ts.map