eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
138 lines • 5.12 kB
TypeScript
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';
/**
* 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 that need to be performed before the execution
* environment is paused / terminated
* (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>;
}
/**
* 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 it is completed.
*/
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>;
}
/**
* 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