@mastra/core
Version:
68 lines • 3.82 kB
TypeScript
import type { ChunkType, MastraStepResult, StepFinishPayload, StepStartPayload } from '../../stream/types.js';
import type { AgentFinishEventData } from '../durable/types.js';
import type { ResponseMessagesDiff } from './response-messages.js';
/**
* The shape of the step events a run publishes on its stream topic
* (`agent.stream.<runId>`), built from the loop's in-process chunks.
*
* The in-process chunks are made for the caller: a `step-finish` holds the
* whole prompt and every earlier step, so publishing it as-is makes each event
* grow with the run, and the topic log (stored in full on Redis) grow with the
* square of the step count. Readers of the topic (`observe()`, reconnecting
* clients, DurableAgent streams) only need what is built here, which matches
* what DurableAgent publishes. Every field is picked explicitly, so new fields
* on the in-process chunks stay off the topic unless they are added here.
*/
type StepMetadataField = 'id' | 'timestamp' | 'modelId' | 'model' | 'modelMetadata' | 'headers' | 'providerMetadata';
/** A `step-finish` payload as published on a run's stream topic. */
export interface AgentStreamStepFinishPayload {
id?: string;
messageId?: string;
providerMetadata?: StepFinishPayload['providerMetadata'];
stepResult: StepFinishPayload['stepResult'];
metadata: Partial<Record<StepMetadataField, unknown>>;
/** `steps` holds only the current step's tripwire, which readers check on the last step. */
output: {
usage: StepFinishPayload['output']['usage'];
steps?: [{
tripwire: NonNullable<MastraStepResult['tripwire']>;
}];
};
/** The finished step's content, which readers can't rebuild without the run's messages. */
_durableStepContent?: MastraStepResult['content'];
/**
* The run's response messages so far (`step.response.messages`), as the part
* that changed since the producer's previous step-finish. Readers rebuild the
* list (see `response-messages.ts`). It replaces the full list
* (`_durableResponseMessages`), so a reader that can't rebuild it reports no
* messages rather than a partial list.
*/
_durableResponseMessagesDiff?: ResponseMessagesDiff;
/** The whole list, from producers that don't send diffs (DurableAgent and EventedAgent). */
_durableResponseMessages?: NonNullable<StepFinishPayload['messages']>['nonUser'];
}
/** The `step-start` data to publish: everything but the provider request and prompt. */
export declare function toStreamStepStart(payload: StepStartPayload): {
stepId?: string | undefined;
messageId: string | undefined;
startedAt: number | undefined;
modelId: string | undefined;
provider: string | undefined;
warnings: import("../../_types/@ai-sdk_provider@2.0.5/dist/index.js").LanguageModelV2CallWarning[] | undefined;
backgroundResultTaskIds?: string[] | undefined;
};
/**
* The `step-finish` payload to publish. Of the steps so far, only the last
* one's tripwire is kept: readers check it to tell a rejected step.
*
* @param content The finished step's content, when the publisher can read it
* from the run's messages. Readers otherwise fall back to their own messages.
* @param responseMessages The step's response messages, from `diffResponseMessages`.
*/
export declare function toStreamStepFinish(payload: StepFinishPayload<any, any>, content: MastraStepResult<any>['content'] | undefined, responseMessages: ResponseMessagesDiff | undefined): AgentStreamStepFinishPayload;
/** The `finish` data to publish: the run's result, with each step stripped of its prompt and messages. */
export declare function toStreamFinish(payload: Extract<ChunkType<any>, {
type: 'finish';
}>['payload']): AgentFinishEventData;
export {};
//# sourceMappingURL=wire.d.ts.map