import type { TracingOptions } from '@mastra/core/observability'; import type { RequestContext } from '@mastra/core/request-context'; import type { Body, RouteResponse } from '../route-types.generated.js'; import type { ClientOptions, WorkflowRunResult, StreamVNextChunkType, TimeTravelParams } from '../types.js'; import { BaseResource } from './base.js'; type WorkflowStartParams = Omit, 'inputData' | 'requestContext'> & { inputData: Record; requestContext?: RequestContext | Record; }; type WorkflowResumeParams = Omit, 'resumeData' | 'requestContext'> & { resumeData?: Record; requestContext?: RequestContext | Record; }; export declare class Run extends BaseResource { private workflowId; readonly runId: string; constructor(options: ClientOptions, workflowId: string, runId: string); private createChunkTransformStream; /** * Cancels a specific workflow run by its ID * @returns Promise containing a success message * @deprecated Use `cancel()` instead */ cancelRun(): Promise>; /** * Cancels a workflow run. * * This method aborts any running steps and updates the workflow status to 'canceled' . * It works for both actively running workflows and suspended/waiting workflows. * * ## How cancellation works * * When called, the workflow will: * 1. **Trigger the abort signal** - Uses the standard Web API AbortSignal to notify running steps * 2. **Prevent subsequent steps** - No further steps will be executed * * ## Abort signal behavior * * Steps that check the `abortSignal` parameter can respond to cancellation: * - Steps can listen to the 'abort' event: `abortSignal.addEventListener('abort', callback)` * - Steps can check if already aborted: `if (abortSignal.aborted) { ... }` * - Useful for canceling timeouts, network requests, or long-running operations * * **Note:** Steps must actively check the abort signal to be canceled mid-execution. * Steps that don't check the signal will run to completion, but subsequent steps won't execute. * * @returns Promise that resolves with `{ message: 'Workflow run canceled' }` when cancellation succeeds * @throws {HTTPException} 400 - If workflow ID or run ID is missing * @throws {HTTPException} 404 - If workflow or workflow run is not found * * @example * ```typescript * const run = await workflow.createRun({ runId: 'run-123' }); * await run.cancel(); * // Returns: { message: 'Workflow run canceled' } * ``` * * @example * ```typescript * // Example of a step that responds to cancellation * const step = createStep({ * id: 'long-running-step', * execute: async ({ inputData, abortSignal, abort }) => { * const timeout = new Promise((resolve) => { * const timer = setTimeout(() => resolve('done'), 10000); * * // Clean up if canceled * abortSignal.addEventListener('abort', () => { * clearTimeout(timer); * resolve('canceled'); * }); * }); * * const result = await timeout; * * // Check if aborted after async operation * if (abortSignal.aborted) { * return abort(); // Stop execution * } * * return { result }; * } * }); * ``` */ cancel(): Promise>; /** * Starts a workflow run synchronously without waiting for the workflow to complete * @param params - Object containing the inputData, initialState and requestContext * @returns Promise containing success message */ start(params: WorkflowStartParams): Promise>; /** * Resumes a suspended workflow step synchronously without waiting for the workflow to complete * @param params - Object containing the step, resumeData and requestContext * @returns Promise containing success message */ resume({ step, resumeData, tracingOptions, perStep, forEachIndex, ...rest }: WorkflowResumeParams): Promise>; /** * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete * @param params - Object containing the inputData, initialState and requestContext * @returns Promise containing the workflow execution results */ startAsync(params: Omit, 'requestContext'> & { requestContext?: RequestContext | Record; }): Promise; /** * Starts a workflow run and returns a stream * @param params - Object containing the inputData, initialState and requestContext * @returns Promise containing the workflow execution results */ stream(params: { inputData: Record; initialState?: Record; requestContext?: RequestContext | Record; tracingOptions?: TracingOptions; resourceId?: string; perStep?: boolean; closeOnSuspend?: boolean; }): Promise>; /** * Observe (reconnect to) an existing workflow stream. * Use this to resume receiving events after a disconnection. * * @param params.offset - Optional position to resume from (0-based). If omitted, replays all events. * @returns Promise containing a ReadableStream of workflow events * * @example * ```typescript * // Reconnect to a workflow stream from a specific position * const stream = await run.observe({ offset: 42 }); * * for await (const event of stream) { * console.log('Received:', event); * } * ``` */ observe(params?: { offset?: number; }): Promise>; /** * Observes workflow stream for a workflow run * @deprecated Use `observe()` instead for better control over replay position * @returns Promise containing the workflow execution results */ observeStream(): Promise>; /** * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete * @param params - Object containing the step, resumeData and requestContext * @returns Promise containing the workflow resume results */ resumeAsync(params: Omit, 'requestContext'> & { requestContext?: RequestContext | Record; }): Promise; /** * Resumes a suspended workflow step without waiting for the workflow to complete (fire-and-forget) * and returns immediately with the runId. The workflow continues executing in the background. * * Use this when you want to dispatch a resume and return immediately (e.g. an HTTP handler that * never needs the resolved result inline). For Inngest-backed workflows this also avoids the * `getRunOutput()` polling race that `resumeAsync()` can hit. * * TODO(v2): in Mastra v2 this fire-and-forget behavior should become the behavior of * `resumeAsync()` (to mirror `start`/`resume` fire-and-forget semantics), and this method * should be removed. Kept as a separate method in v1 to avoid a breaking contract change. * * @param params - Object containing the step, resumeData and requestContext * @returns Promise containing the runId of the resumed workflow run */ resumeNoWait(params: WorkflowResumeParams): Promise>; /** * Resumes a suspended workflow step that uses stream asynchronously and returns a promise that resolves when the workflow is complete * @param params - Object containing the step, resumeData and requestContext * @returns Promise containing the workflow resume results */ resumeStream(params: { step?: string | string[]; resumeData?: Record; requestContext?: RequestContext | Record; tracingOptions?: TracingOptions; perStep?: boolean; forEachIndex?: number; }): Promise>; /** * Restarts an active workflow run synchronously without waiting for the workflow to complete * @param params - Object containing the requestContext * @returns Promise containing success message */ restart(params: Omit, 'requestContext'> & { requestContext?: RequestContext | Record; }): Promise>; /** * Restarts an active workflow run asynchronously * @param params - optional object containing the requestContext * @returns Promise containing the workflow restart results */ restartAsync(params?: Omit, 'requestContext'> & { requestContext?: RequestContext | Record; }): Promise; /** * Time travels a workflow run synchronously without waiting for the workflow to complete * @param params - Object containing the step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions * @returns Promise containing success message */ timeTravel({ requestContext: paramsRequestContext, ...params }: TimeTravelParams): Promise>; /** * Time travels a workflow run asynchronously * @param params - Object containing the step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions * @returns Promise containing the workflow time travel results */ timeTravelAsync({ requestContext: paramsRequestContext, ...params }: TimeTravelParams): Promise; /** * Time travels a workflow run and returns a stream * @param params - Object containing the step, inputData, resumeData, initialState, context, nestedStepsContext, requestContext and tracingOptions * @returns Promise containing the workflow execution results */ timeTravelStream({ requestContext: paramsRequestContext, ...params }: TimeTravelParams): Promise>; } export {}; //# sourceMappingURL=run.d.ts.map