@mastra/core
Version:
87 lines • 3.77 kB
TypeScript
/**
* A structured choice rendered by the host for an `ask_user` prompt.
*
* The label is the value returned to the model when the option is selected. The
* optional description gives the host more context without changing the answer value.
*/
export interface AskUserOption {
label: string;
description?: string;
}
/**
* Controls whether an `ask_user` prompt accepts one choice or multiple choices.
*
* `single_select` is the default for prompts that provide options, preserving the
* original one-answer behavior. `multi_select` tells the host that the user may choose
* more than one option and resume with those selections as an array.
*/
export type AskUserSelectionMode = 'single_select' | 'multi_select';
/**
* Answer shape used to resume a suspended `ask_user` call.
*
* Free-text and single-select prompts resume with a string. Multi-select prompts
* resume with a string array containing each selected option label.
*/
export type AskUserAnswer = string | string[];
/**
* Payload carried by the native `tool-call-suspended` event when `ask_user` pauses.
* Hosts read this to render the question, choices, and selection mode.
*/
export interface AskUserSuspendPayload {
question: string;
options?: AskUserOption[];
selectionMode?: AskUserSelectionMode;
}
/**
* Converts the resume answer into the text returned to the model after `ask_user`
* resumes. Free-text and single-select prompts already produce a single string,
* while multi-select prompts resume with an array of selected labels that must be
* flattened before the tool result is added back into the generation context.
*
* The formatter keeps the model-facing output compact by joining multi-select
* answers with commas, mirroring the single-answer behavior while still preserving
* every selected option in a readable form.
*/
export declare function formatQuestionAnswer(answer: AskUserAnswer): string;
/**
* Built-in, agent-agnostic tool: ask the user a question and wait for their response.
*
* The tool supports three prompt shapes. Omitting `options` asks an open-ended
* free-text question. Providing `options` without `selectionMode` asks the host to
* render a single-select prompt for backwards compatibility. Providing
* `selectionMode: 'multi_select'` lets the host resume with multiple selected option
* labels as a string array.
*
* Pausing uses the agent-native tool suspension primitive: the tool calls
* `suspend({ question, options, selectionMode })`, which makes the agent emit a
* `tool-call-suspended` event and persist run state. The host renders the question,
* collects the user's answer, and continues the run via `agent.resumeStream(answer)`;
* the tool re-runs with `resumeData` set to the answer and returns it to the model.
*
* When executed without an agent `suspend` (e.g. direct invocation outside an agent
* run), the tool returns a readable fallback prompt so the question and choices are
* still surfaced.
*/
export declare const askUserTool: import("..").Tool<{
question: string;
options?: {
label: string;
description?: string | undefined;
}[] | undefined;
selectionMode?: "single_select" | "multi_select" | undefined;
}, unknown, {
question: string;
options?: {
label: string;
description?: string | undefined;
}[] | undefined;
selectionMode?: "single_select" | "multi_select" | undefined;
}, string | string[], import("..").ToolExecutionContext<{
question: string;
options?: {
label: string;
description?: string | undefined;
}[] | undefined;
selectionMode?: "single_select" | "multi_select" | undefined;
}, string | string[], unknown>, "ask_user", unknown>;
//# sourceMappingURL=ask-user.d.ts.map