import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from '../_workflow-serde.js';
import type { WorkflowRunStatus } from '#compiled/@workflow/world/index.js';
import { type CancelRunOptions, type StopSleepOptions, type StopSleepResult } from './runs.js';
/** @internal */
export declare function getReturnValuePollIntervalMs(): number;
/** @internal */
export declare function getReturnValueWaitTimeoutMs(): number;
/** @internal */
export declare function getReturnValueMaxLongPolls(): number;
/**
 * Whether `await run.returnValue` may use the World's long poll
 * (`runs.waitForTerminalStatus`) instead of interval-polling `runs.get`.
 *
 * Default **ON** wherever the World implements the method; a World that does
 * not is already on the interval path with nothing to switch off. Reads
 * `process.env.WORKFLOW_RETURN_VALUE_LONG_POLL` lazily; an explicit `'0'` /
 * `'false'` is the kill switch, restoring the fixed-interval poll exactly as
 * it behaved before the fast path existed.
 *
 * @internal
 */
export declare function isReturnValueLongPollEnabled(): boolean;
/**
 * A `ReadableStream` extended with workflow-specific helpers.
 */
export type WorkflowReadableStream<R = any> = ReadableStream<R> & {
    /**
     * Returns the tail index (index of the last known chunk, 0-based) of the
     * underlying workflow stream. Useful for resolving a negative `startIndex`
     * into an absolute position, for example, when building reconnection
     * endpoints that need to inform the client where the stream starts.
     *
     * Returns `-1` when no chunks have been written yet.
     */
    getTailIndex(): Promise<number>;
};
/**
 * Options for configuring a workflow's readable stream.
 */
export interface WorkflowReadableStreamOptions {
    /**
     * An optional namespace to distinguish between multiple streams associated
     * with the same workflow run.
     */
    namespace?: string;
    /**
     * The index number of the starting chunk to begin reading the stream from.
     * Negative values start from the end (e.g. -3 reads the last 3 chunks).
     */
    startIndex?: number;
    /**
     * Any asynchronous operations to complete before pausing or terminating the
     * execution environment
     * (i.e. using [`waitUntil()`](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil) or similar).
     */
    ops?: Promise<any>[];
    /**
     * The global object to use for hydrating types from the global scope.
     *
     * Defaults to {@link [`globalThis`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/globalThis)}.
     */
    global?: Record<string, any>;
}
/**
 * Options for configuring a writable onto a workflow run's stream.
 */
export interface WorkflowRunWritableStreamOptions {
    /**
     * An optional namespace to distinguish between multiple streams associated
     * with the same workflow run.
     */
    namespace?: string;
    /**
     * Any asynchronous operations to complete before pausing or terminating the
     * execution environment
     * (i.e. using [`waitUntil()`](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil) or similar).
     *
     * Writes are acknowledged on buffer entry, so a caller that needs them
     * durable before the environment goes away should pass an array here and
     * await it after releasing the writer lock.
     */
    ops?: Promise<any>[];
    /**
     * The global object to use for reducing types from the global scope.
     *
     * Defaults to {@link [`globalThis`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/globalThis)}.
     */
    global?: Record<string, any>;
}
/**
 * A handler class for a workflow run.
 */
export declare class Run<TResult> {
    #private;
    static [WORKFLOW_SERIALIZE](instance: Run<unknown>): {
        runId: string;
        resilientStart: boolean;
    };
    static [WORKFLOW_DESERIALIZE](data: {
        runId: string;
        resilientStart?: boolean;
    }): Run<unknown>;
    /**
     * The ID of the workflow run.
     */
    runId: string;
    constructor(runId: string, opts?: {
        resilientStart?: boolean;
    });
    /**
     * Interrupts pending `sleep()` calls, resuming the workflow early.
     *
     * @param options - Optional settings to target specific sleep calls by correlation ID.
     *   If not provided, all pending sleep calls will be interrupted.
     * @returns A {@link StopSleepResult} object containing the number of sleep calls that were interrupted.
     */
    wakeUp(options?: StopSleepOptions): Promise<StopSleepResult>;
    /**
     * Cancels the workflow run.
     *
     * @param options - Optional cancellation settings. `cancelReason` records a
     *   free-text reason (max 512 chars) on the run_cancelled event, surfaced in
     *   the run detail view.
     */
    cancel(options?: CancelRunOptions): Promise<void>;
    /**
     * Whether the workflow run exists.
     */
    get exists(): Promise<boolean>;
    /**
     * The status of the workflow run.
     */
    get status(): Promise<WorkflowRunStatus>;
    /**
     * The return value of the workflow run.
     * Polls the workflow return value until the workflow run completes.
     */
    get returnValue(): Promise<TResult>;
    /**
     * The name of the workflow.
     */
    get workflowName(): Promise<string>;
    /**
     * The timestamp when the workflow run was created.
     */
    get createdAt(): Promise<Date>;
    /**
     * The timestamp when the workflow run started execution.
     * Returns undefined if the workflow has not started yet.
     */
    get startedAt(): Promise<Date | undefined>;
    /**
     * The timestamp when the workflow run completed.
     * Returns undefined if the workflow has not completed yet.
     */
    get completedAt(): Promise<Date | undefined>;
    /**
     * The readable stream of the workflow run.
     */
    get readable(): WorkflowReadableStream;
    /**
     * Retrieves the workflow run's default readable stream, which reads chunks
     * written to the corresponding writable stream {@link getWritable}.
     *
     * The returned stream has an additional {@link WorkflowReadableStream.getTailIndex | getTailIndex()}
     * helper that returns the index of the last known chunk. This is useful when
     * building reconnection endpoints that need to inform clients where the
     * stream starts.
     *
     * @param options - The options for the readable stream.
     * @returns A `WorkflowReadableStream` for the workflow run.
     */
    getReadable<R = any>(options?: WorkflowReadableStreamOptions): WorkflowReadableStream<R>;
    /** The writable stream of the workflow run. */
    get writable(): WritableStream;
    /**
     * Returns a writable that appends to this run's stream.
     *
     * Initialization is deferred until the first write. The run must already
     * exist. The writable may be forwarded through `start()` and into steps, but
     * grants no read access or additional authorization.
     *
     * @remarks
     * `writer.close()` closes the shared stream. Contributors should call
     * `releaseLock()`, which also drains pending writes.
     *
     * @param options - The writable stream options.
     */
    getWritable<W = any>(options?: WorkflowRunWritableStreamOptions): WritableStream<W>;
}
/**
 * Retrieves a `Run` object for a given run ID.
 *
 * @param runId - The workflow run ID obtained from {@link start}.
 * @returns A `Run` object.
 * @throws WorkflowRunNotFoundError if the run ID is not found.
 */
export declare function getRun<TResult>(runId: string): Run<TResult>;
//# sourceMappingURL=run.d.ts.map