@mastra/core
Version:
84 lines • 4.67 kB
TypeScript
import type { PubSub } from '../../events/pubsub.js';
import type { ChunkType, DataChunkType, StepStartPayload } from '../../stream/types.js';
import type { AgentAbortEventData, AgentErrorEventData, AgentFinishEventData, AgentIterationCompleteEventData, AgentStepFinishEventData, AgentSuspendedEventData } from '../durable/types.js';
/**
* Helper to emit a chunk event to pubsub
*/
export declare function emitChunkEvent<OUTPUT = undefined>(pubsub: PubSub, runId: string, chunk: ChunkType<OUTPUT> | DataChunkType, outputProcessed?: boolean): Promise<void>;
/**
* Announce that the execution with `generation` claimed the run, so the run's
* stream consumers drop what older executions still publish from here on.
*
* Readers only learn a generation from events they see. Without this marker,
* a reader's floor would rise only at the new execution's first event, which
* comes after rehydration and the first model call. Until then, an execution
* that stalled past its claim and resumed keeps publishing: it only learns it
* was superseded at its next heartbeat or step check, so `fencePubSub` doesn't
* stop it yet. Its chunks would reach readers, and its `finish` would end their
* streams before the new execution's answer arrives.
*
* Published on the run's stream topic, not a separate one, so it is ordered
* against the chunks around it and replayed to readers that reconnect from an
* offset. Readers swallow it and never forward it as a chunk. Readers that
* reconnect past it read the claim's generation from storage instead.
*/
export declare function emitOwnershipClaimedEvent(pubsub: PubSub, runId: string, generation: number, supersededFrom?: number): Promise<void>;
/** Mark an execution attempt before it can produce any chunks. */
export declare function emitIterationStartEvent(pubsub: PubSub, runId: string, stepIndex: number): Promise<void>;
/**
* Helper to emit a step start event to pubsub.
* The stream-adapter consumer enqueues this event's `data` verbatim as a
* stream chunk, so it must match the canonical `step-start` `ChunkType` the
* regular (non-durable) engine emits — `{ type, runId, from, payload }`.
* Chunk consumers destructure `chunk.payload` (e.g. the `@mastra/ai-sdk`
* chunk converter), so emitting the fields flat at the top level instead
* crashes every durable `stream()`/`observe()` consumer with
* "Cannot destructure property 'messageId' of 'chunk.payload'".
*/
export declare function emitStepStartEvent(pubsub: PubSub, runId: string, data: {
stepId?: string;
messageId?: string;
startedAt?: StepStartPayload['startedAt'];
modelId?: StepStartPayload['modelId'];
provider?: StepStartPayload['provider'];
request?: StepStartPayload['request'];
warnings?: StepStartPayload['warnings'];
backgroundResultTaskIds?: StepStartPayload['backgroundResultTaskIds'];
}, outputProcessed?: boolean): Promise<void>;
/**
* Build the `step-start` chunk `emitStepStartEvent` publishes, so a producer
* can run it through output processors before publishing it.
*/
export declare function createStepStartChunk(runId: string, data: Parameters<typeof emitStepStartEvent>[2]): Extract<ChunkType, {
type: 'step-start';
}>;
/**
* Publish a `step-start` chunk. `outputProcessed` marks a chunk the producer
* already ran through output processors, so consumers don't run them again.
*/
export declare function publishStepStartChunk(pubsub: PubSub, runId: string, chunk: ChunkType, outputProcessed?: boolean, stepIndex?: number): Promise<void>;
/**
* Helper to emit a step finish event to pubsub
*/
export declare function emitStepFinishEvent(pubsub: PubSub, runId: string, data: AgentStepFinishEventData): Promise<void>;
/**
* Helper to emit a finish event to pubsub
*/
export declare function emitFinishEvent(pubsub: PubSub, runId: string, data: AgentFinishEventData): Promise<void>;
/**
* Helper to emit an error event to pubsub
*/
export declare function emitErrorEvent(pubsub: PubSub, runId: string, error: Error, generation?: number, delivery?: AgentErrorEventData['delivery']): Promise<void>;
/**
* Helper to emit a suspended event to pubsub
*/
export declare function emitSuspendedEvent(pubsub: PubSub, runId: string, data: AgentSuspendedEventData): Promise<void>;
/**
* Helper to emit an abort event to pubsub
*/
export declare function emitAbortEvent(pubsub: PubSub, runId: string, data: AgentAbortEventData): Promise<void>;
/**
* Helper to emit an iteration-complete event to pubsub
*/
export declare function emitIterationCompleteEvent(pubsub: PubSub, runId: string, data: AgentIterationCompleteEventData): Promise<void>;
//# sourceMappingURL=events.d.ts.map