@mastra/core
Version:
48 lines • 2.36 kB
TypeScript
/**
* Pubsub transport for run abort requests.
*
* `abort()` runs in the caller's process, but the run it targets may execute
* in a different process (a load-balanced server replica, or a durable
* execution worker). These helpers carry the abort *intent* over the run's
* control topic so the executing process can flip its own controller and
* unwind gracefully.
*/
import type { PubSub } from '../../events/index.js';
/**
* Ask whichever process is executing `runId` to abort it.
*
* Safe to call from a process that is not running the steps, and safe to call
* when nobody is listening — an unheard request is a no-op, exactly like
* aborting a run that already finished.
*/
export declare function publishAbortRequest(pubsub: PubSub, runId: string): Promise<void>;
/**
* Topic on which the process executing a run acknowledges abort requests that
* carried a `requestId`. Kept apart from the control topic so a requester never
* has to read (or replay) the control history to wait for its own reply.
*/
export declare const abortAckTopic: (runId: string) => string;
/**
* Ask whichever process is executing `runId` to abort it, and wait for that
* process to confirm it applied the request.
*
* Resolves `true` only when an executing process acknowledged the abort, and
* `false` when nobody answered within `timeoutMs` (the run is not executing
* anywhere, its owner died, or its listener is not installed yet). A publish
* failure rejects: the caller cannot claim an abort it never sent.
*
* @internal Used by `@mastra/server`'s run abort route; not a public API.
*/
export declare function requestAcknowledgedAbort(pubsub: PubSub, runId: string, timeoutMs?: number): Promise<boolean>;
/**
* Listen for abort requests targeting `runId`.
*
* `onAbortRequested` returns `false` when there was nothing left to stop (the
* run already ended here); the request is then not acknowledged, so a waiting
* requester does not report a cancellation that never happened.
*
* @returns An unsubscribe function. Callers must invoke it when the run leaves
* this process, otherwise the subscription outlives the work it guards.
*/
export declare function subscribeToAbortRequests(pubsub: PubSub, runId: string, onAbortRequested: () => boolean | void): Promise<() => Promise<void>>;
//# sourceMappingURL=abort-transport.d.ts.map