@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
68 lines • 2.26 kB
TypeScript
/**
* Helper functions for evented workflow execution.
*/
import { TripWire } from '../../agent/trip-wire.js';
/**
* Interface for tripwire chunks in the stream.
* These chunks are emitted when a processor triggers a tripwire.
*/
export interface TripwireChunk {
type: 'tripwire';
payload: {
reason: string;
retry?: boolean;
metadata?: unknown;
processorId?: string;
};
}
/**
* Type guard to check if a chunk is a tripwire chunk.
* @param chunk - The chunk to check
* @returns True if the chunk is a TripwireChunk
*/
export declare function isTripwireChunk(chunk: unknown): chunk is TripwireChunk;
/**
* Creates a TripWire error from a tripwire chunk.
* @param chunk - The tripwire chunk from the stream
* @returns A TripWire error instance
*/
export declare function createTripWireFromChunk(chunk: TripwireChunk): TripWire;
/**
* Extracts text delta from a stream chunk, handling V1 vs V2 differences.
*
* V1 (AI SDK v4): Uses `chunk.textDelta` for raw text
* V2 (AI SDK v5): Uses `chunk.payload.text` for normalized text
*
* @param chunk - The stream chunk
* @param isV2Model - Whether this is a V2 model (uses normalized payload)
* @returns The text delta string, or undefined if not a text-delta chunk
*/
export declare function getTextDeltaFromChunk(chunk: {
type: string;
textDelta?: string;
payload?: {
text?: string;
};
}, isV2Model: boolean): string | undefined;
/**
* Parameters for resolving the current workflow state.
*/
export interface ResolveStateParams {
/** State from a step result (highest priority). Uses `any` to accommodate various StepResult types. */
stepResult?: unknown;
/** State from all step results */
stepResults?: {
__state?: Record<string, unknown>;
};
/** State passed directly */
state?: Record<string, unknown>;
}
/**
* Resolves the current workflow state from multiple potential sources.
* Priority order: stepResult.__state > stepResults.__state > state > empty object
*
* @param params - The state sources to check
* @returns The resolved state object
*/
export declare function resolveCurrentState(params: ResolveStateParams): Record<string, unknown>;
//# sourceMappingURL=helpers.d.ts.map