@mastra/core
Version:
47 lines • 2.41 kB
TypeScript
/**
* Auto-resume system-message injection.
*
* When `autoResumeSuspendedTools` is on, both the non-durable and durable
* agentic loops scan the latest assistant message for suspended-tool /
* pending-approval markers and append a directive to the system prompt
* teaching the model how to construct `resumeData` and resume the tool.
*
* The two loops used to inline this logic, which is how the durable path
* silently lost the system-message rewrite (Bug 2). Centralising it here
* is the fix.
*/
import type { LanguageModelV2Prompt } from '../../_types/@ai-sdk_provider-v5/dist/index.d.ts';
import type { MastraDBMessage } from '../../agent/message-list/index.js';
/**
* Returns the list of suspended (or pending-approval) tool descriptors from the
* most recent assistant message, or an empty array if none are pending.
*
* Looks at `message.content.metadata.suspendedTools`,
* `message.content.metadata.pendingToolApprovals`, and any
* `data-tool-call-suspended` / `data-tool-call-approval` parts whose `resumed`
* flag is falsy.
*/
export declare function extractSuspendedToolsFromMessages(messages: ReadonlyArray<MastraDBMessage>): Array<Record<string, unknown>>;
/**
* Build the suffix to append to the leading system message when there are
* suspended tools to auto-resume. Returns `null` when there are none, so
* callers can skip the rewrite entirely.
*/
export declare function buildAutoResumeSystemMessageSuffix(suspendedTools: ReadonlyArray<Record<string, unknown>>): string | null;
/**
* Append `suffix` to the first system message in `inputMessages`, returning a
* new array. No-ops (returns the input unchanged) when `suffix` is null or
* there is no leading system message.
*/
export declare function appendSuffixToLeadingSystemMessage(inputMessages: LanguageModelV2Prompt, suffix: string | null): LanguageModelV2Prompt;
/**
* Convenience wrapper: scan `messages` for suspended tools, and if any are
* present, append the auto-resume directive to the leading system message.
* Pass-through when `autoResume` is false or no suspended tools are found.
*/
export declare function applyAutoResumeSystemMessage({ autoResume, inputMessages, messages, }: {
autoResume: boolean | undefined;
inputMessages: LanguageModelV2Prompt;
messages: ReadonlyArray<MastraDBMessage>;
}): LanguageModelV2Prompt;
//# sourceMappingURL=auto-resume-system-message.d.ts.map