UNPKG

@mastra/core

Version:
58 lines • 3.42 kB
import type { MastraDBMessage, MessageList } from '../agent/message-list/index.js'; import type { Processor, ProcessInputStepArgs, ProcessInputStepResult } from './index.js'; /** Metadata key that marks the synthetic user turn appended by {@link TrailingAssistantGuard}. */ export declare const TRAILING_ASSISTANT_GUARD_CONTINUATION_KEY = "trailingAssistantGuardContinuation"; /** Whether `message` is the synthetic user turn appended by {@link TrailingAssistantGuard}. */ export declare function isTrailingAssistantGuardContinuation(message: MastraDBMessage): boolean; /** * Drop the guard's synthetic user turn once the step's prompt has been built. It only has * to reach the provider; left in the list it sits between the trailing assistant message * and the reply, so the reply is saved as a separate assistant message (#27520). */ export declare function removeTrailingAssistantGuardContinuations(messageList: MessageList): void; /** * Whether a step needs `TrailingAssistantGuard` attached. * * True when the model as configured rejects a prompt ending on a model turn * (Anthropic 4.6+ assistant prefill, Gemini 3+), or when any input processors are * configured, since a processor may swap `model` mid-step. In the latter case the * attach is speculative: the runner asks {@link TrailingAssistantGuard.appliesTo} * against the final step model before running the guard, and skips it entirely * (no processor span) when the provider does not need it. * * Used both where the `ProcessorRunner` is created for a step and where the * runner assembles its processor list, so an agent with no input processors * still gets a runner and that runner still appends the guard. */ export declare function needsTrailingAssistantGuard(model: unknown, inputProcessors: readonly unknown[]): boolean; /** * Whether the guard can have any effect for `model`. Cheap provider/version * check the runner uses to skip a speculatively attached guard without * recording a processor span for it. */ export declare function trailingAssistantGuardAppliesTo(model: unknown): boolean; /** * Guards against requests that would end on an assistant message for providers * that reject that shape. * * - Anthropic reads a trailing assistant message as response prefill. That is a * legitimate feature outside structured output, so the guard only intervenes when * native structured output (`responseFormat`) is in play, where Anthropic rejects it. * - Gemini 3 and later return 400 "Requests ending with a model turn are not * supported" for any request, structured output or not, so the guard always * intervenes for those models. * * In both cases a short user message is appended so the request ends on a user turn. * Provider and version gating for *attaching* the processor lives at the attach * sites; this class only decides when the appended turn is needed. * * @see https://github.com/mastra-ai/mastra/issues/12800 * @see https://github.com/mastra-ai/mastra/issues/23320 */ export declare class TrailingAssistantGuard implements Processor<'trailing-assistant-guard'> { readonly id: 'trailing-assistant-guard'; readonly name = "Trailing Assistant Guard"; appliesTo(model: unknown): boolean; processInputStep({ messages, messageList, structuredOutput, model, }: ProcessInputStepArgs): ProcessInputStepResult | undefined; } //# sourceMappingURL=trailing-assistant-guard.d.ts.map