import vm from 'node:vm';
import { SourceMapConsumer } from 'source-map';
import { coresdk } from '@temporalio/proto';
import type { StackTraceFileLocation } from '@temporalio/workflow';
import { type SinkCall } from '@temporalio/workflow/lib/sinks';
import * as internals from '@temporalio/workflow/lib/worker-interface';
import { Activator } from '@temporalio/workflow/lib/internals';
import { Workflow } from './interface';
import { WorkflowBundleWithSourceMapAndFilename } from './workflow-worker-thread/input';
import '@temporalio/workflow/lib/global-attributes';
export declare function setUnhandledRejectionHandler(getWorkflowByRunId: (runId: string) => BaseVMWorkflow | undefined): void;
/**
 * Inject global objects as well as console.[log|...] into a vm context.
 */
export declare function injectGlobals(context: vm.Context): void;
/**
 * Global handlers for overriding stack trace preparation and promise hooks
 */
export declare class GlobalHandlers {
    currentStackTrace: StackTraceFileLocation[] | undefined;
    bundleFilenameToSourceMapConsumer: Map<string, SourceMapConsumer>;
    origPrepareStackTrace: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
    private stopPromiseHook;
    promiseHookInstalled: boolean;
    installed: boolean;
    addWorkflowBundle(workflowBundle: WorkflowBundleWithSourceMapAndFilename): Promise<void>;
    removeWorkflowBundle(workflowBundle: WorkflowBundleWithSourceMapAndFilename): void;
    /**
     * Set the global hooks, this method is idempotent
     */
    install(): void;
    /**
     * Unset all installed global hooks
     *
     * This method is not called anywhere since we typically install the hooks in a separate thread which is cleaned up
     * after worker shutdown. Is debug mode we don't clean these up but that should be insignificant.
     */
    uninstall(): void;
    private overridePrepareStackTrace;
    private setPromiseHook;
}
export declare const globalHandlers: GlobalHandlers;
export type WorkflowModule = typeof internals;
/**
 * A Workflow implementation using Node.js' built-in `vm` module.
 */
export declare abstract class BaseVMWorkflow implements Workflow {
    readonly runId: string;
    protected context: vm.Context | undefined;
    protected activator: Activator;
    readonly workflowModule: WorkflowModule;
    unhandledRejection: unknown;
    constructor(runId: string, context: vm.Context | undefined, activator: Activator, workflowModule: WorkflowModule);
    /**
     * Send request to the Workflow runtime's worker-interface
     */
    getAndResetSinkCalls(): Promise<SinkCall[]>;
    /**
     * Send request to the Workflow runtime's worker-interface
     *
     * In order to properly work around Bun's lack of support for `microtaskMode: afterEvaluate` it is important to
     * immediately schedule a task after each call into the `workflowModule`. This task ensures that any microtasks
     * from a specific workflow will execute while the vm is still setup for said workflow.
     * This is why there are `if (isBun) await new Promise(setImmediate)` scattered throughout this function.
     */
    activate(activation: coresdk.workflow_activation.IWorkflowActivation): Promise<coresdk.workflow_completion.IWorkflowActivationCompletion>;
    private activateQueries;
    /**
     * If called (by an external unhandledRejection handler), activations will fail with provided error.
     */
    setUnhandledRejection(err: unknown): void;
    /**
     * Call into the Workflow context to attempt to unblock any blocked conditions and microtasks.
     *
     * This is performed in a loop, going in and out of the VM, allowing microtasks to be processed
     * between each iteration of the outer loop, until there are no more conditions to unblock.
     */
    protected tryUnblockConditionsAndMicrotasks(): void;
    /**
     * Same as `tryUnblockConditionsAndMicrotasks`, but not relying on `microtaskMode: afterEvaluate`.
     *
     * Instead of relying on microtasks being flushed by `microtaskMode`, await a `Promise` to give a chance for
     * the microtasks to settle.
     */
    protected tryUnblockConditionsAndMicrotasksWithManualFlush(): Promise<void>;
    /**
     * Do not use this Workflow instance after this method has been called.
     */
    abstract dispose(): Promise<void>;
}
