import { Workflow, type Client } from '@botpress/client';
import { z } from '@botpress/sdk';
import { BotClient } from '@botpress/sdk/dist/bot';
import { WorkflowDefinitions, WorkflowOutputs } from '../_types/workflows';
import { Autonomous } from '../runtime/autonomous';
import { TrackedState } from '../runtime/index';
export type WorkflowStepContext = {
    output?: unknown;
    attempts: number;
    maxAttempts?: number;
    startedAt: string;
    finishedAt?: string;
    steps?: Record<string, WorkflowStepContext>;
    mapTotal?: number;
    error?: {
        message: string;
        stack?: string;
        failedAt: string;
        maxAttemptsReached: boolean;
    };
};
declare const StepSymbol: unique symbol;
type StepExecutionSignal = {
    [StepSymbol]: true;
};
export declare function isStepSignal(e: unknown): e is StepExecutionSignal;
export declare function createStepSignal(): StepExecutionSignal;
/**
 * Base class for all workflow instances
 */
export declare class BaseWorkflowInstance<TName extends keyof WorkflowDefinitions> {
    readonly id: string;
    readonly name: TName;
    readonly key?: string | undefined;
    readonly input: WorkflowDefinitions[TName]['input'];
    readonly createdAt: Date;
    readonly updatedAt: Date;
    readonly client: BotClient<any>;
    readonly workflow: Workflow;
    constructor(workflow: Workflow, client: BotClient<any>);
    get tags(): Record<string, string | undefined>;
    set tags(value: Record<string, string | undefined>);
    static readonly Primitive: "workflow_instance";
    static load<TName extends keyof WorkflowDefinitions>(props: {
        id: string;
        workflow?: Workflow;
    }): Promise<BaseWorkflowInstance<TName>>;
    /**
     * Executes the workflow with the provided autonomous engine configuration.
     * Workflows always run in "worker" mode (no chat capabilities).
     */
    execute(props: Autonomous.Props): Promise<import("llmz").ExecutionResult>;
    /**
     * Cancel the workflow execution.
     * Note: This should be called from within a proper bot handler context.
     * If calling from a conversation handler, ensure TrackedTags.loadAll() has been called.
     */
    cancel(): Promise<void>;
    /**
     * Extend the workflow timeout by setting a new timeout.
     * This is useful for long-running workflows that need more time to complete.
     *
     * @param options - Either `{ in: string }` for relative duration or `{ at: string }` for absolute ISO timestamp
     * @returns A promise that resolves when the timeout is updated (can be awaited or not)
     * @example
     * // Relative timeout (duration from now):
     * workflow.setTimeout({ in: '30m' })  // Timeout in 30 minutes
     * workflow.setTimeout({ in: '6 hours' })  // Timeout in 6 hours
     *
     * // Absolute timeout (ISO timestamp):
     * workflow.setTimeout({ at: '2024-12-25T00:00:00Z' })
     *
     * // Optionally await if you need to ensure the update completes:
     * await workflow.setTimeout({ in: '1h' })
     */
    setTimeout(options: {
        in: string;
    } | {
        at: string;
    }): Promise<void>;
    /**
     * Fail the workflow with an error reason.
     * This immediately interrupts the workflow handler and marks the workflow as failed.
     * Can only be called from within a workflow handler.
     *
     * @param reason - The error reason for the failure
     * @throws Never returns - always throws to interrupt the handler
     * @example
     * workflow.fail('Invalid input data')
     */
    fail(reason: string): never;
    /**
     * Complete the workflow early with the given output.
     * This immediately interrupts the workflow handler and marks the workflow as completed.
     * Can only be called from within a workflow handler.
     *
     * @param output - The workflow output (typed according to workflow definition)
     * @throws Never returns - always throws to interrupt the handler
     * @example
     * workflow.complete({ result: 'success', data: processedData })
     */
    complete(output: WorkflowOutputs[TName]): never;
    /**
     * Provide data in response to a workflow data request (instance method).
     * Call this method from a conversation handler when you receive a WorkflowDataRequestEvent.
     * @param request - The name of the request being responded to
     * @param data - The data to provide to the workflow
     * @example
     * if (type === 'workflow_request') {
     *   await workflow.provide('topic', { topic: "Hello" });
     * }
     */
    provide<TRequest extends keyof WorkflowDefinitions[TName]['requests'] & string>(request: TRequest, data: WorkflowDefinitions[TName]['requests'][TRequest]): Promise<void>;
    /**
     * Returns a string representation for console.log
     */
    toString(): string;
    /**
     * Returns a JSON representation for serialization
     */
    toJSON(): any;
}
export declare function createWorkflowExecutionState(client: Client, workflowId: string): TrackedState<import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodObject<{
    executionCount: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
    revision: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
    steps: import("@bpinternal/zui").ZodRecord<import("@bpinternal/zui").ZodString, z.ZodType<WorkflowStepContext>>;
}, "strip", {
    executionCount: number;
    revision: number;
    steps: Record<string, WorkflowStepContext>;
}, {
    steps: Record<string, WorkflowStepContext>;
    executionCount?: number | undefined;
    revision?: number | undefined;
}>>>;
export {};
//# sourceMappingURL=workflow-instance.d.ts.map