import { Stream } from "../StreamTools.cjs";
import { IInngestExecution } from "./InngestExecution.cjs";
import { Context, StepOptions } from "../../types.cjs";
import { Inngest } from "../Inngest.cjs";

//#region src/components/execution/als.d.ts

/**
 * Note - this structure can be used by other libraries, so cannot have breaking changes.
 */
interface AsyncContext {
  /**
   * The Inngest App that is currently being used to execute the function.
   *
   * If this is defined, we are in the context of an Inngest function execution,
   * or a possible one.
   */
  app: Inngest.Like;
  /**
   * Details of the current function execution context. If this doesn't exist,
   * then we're not currently in a function execution context.
   */
  execution?: {
    /**
     * The execution instance that is currently running the function.
     */
    instance: IInngestExecution;
    /**
     * The `ctx` object that has been passed in to this function execution,
     * including values such as `step` and `event`.
     */
    ctx: Context.Any;
    /**
     * If present, this indicates we are currently executing a `step.run()` step's
     * callback. Useful to understand whether we are in the context of a step
     * execution or within the main function body.
     */
    executingStep?: StepOptions & {
      hashedId?: string;
    };
    /**
     * If present, indicates the parallel mode that should be applied to steps
     * created within this context. Set by `group.parallel()`.
     */
    parallelMode?: "race";
    /**
     * The stream tools instance for this execution context. Used by the
     * `stream` singleton to push/pipe SSE data to the client.
     */
    stream?: Stream;
    /**
     * If present, indicates the variant callback is executing within an
     * experiment. Set by `group.experiment()`. Any `step.*()` call within
     * this context will include these fields in `OutgoingOp.opts`.
     */
    experimentContext?: {
      experimentStepID: string;
      experimentName: string;
      variant: string;
      selectionStrategy: string;
    };
    /**
     * A mutable tracker used to detect whether any step tool was invoked
     * during a variant callback. Set by `group.experiment()`, flipped by
     * `createTool` in `InngestStepTools.ts`.
     */
    experimentStepTracker?: {
      found: boolean;
    };
    /**
     * If true, we are inside the `select()` callback of
     * `group.experiment()`. Any `step.*()` call here would create a
     * nested step, which is not allowed.
     */
    insideExperimentSelect?: boolean;
  };
}
/**
 * Retrieve the async context for the current execution.
 */
declare const getAsyncCtx: () => Promise<AsyncContext | undefined>;
//#endregion
export { AsyncContext, getAsyncCtx };
//# sourceMappingURL=als.d.cts.map