import type { UIMessageStreamOptions as UIMessageStreamOptionsV5 } from './_types/@internal_ai-sdk-v5/dist/index.d.ts';
import type { UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6/dist/index.d.ts';
import type { AgentExecutionOptions } from '@mastra/core/agent';
import type { Mastra } from '@mastra/core/mastra';
import { registerApiRoute } from '@mastra/core/server';
import type { SupportedUIMessage, V5UIMessage, V5UIMessageStream, V6UIMessage, V6UIMessageStream } from './public-types.js';
/**
 * Scans a v6 UIMessage array for an 'approval-responded' tool part in the
 * last trailing assistant message only. When found, splits the composite
 * approvalId ("${runId}::${toolCallId}") to recover the runId needed for
 * resumeStream.
 *
 * Only the last trailing assistant message is inspected so that approval
 * responses from earlier turns are never re-processed.
 *
 * Returns null when no approval response is present (normal chat turn).
 */
export declare function extractV6NativeApproval(messages: V6UIMessage[]): {
    resumeData: Record<string, unknown>;
    runId: string;
} | null;
export type ChatStreamHandlerParams<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = AgentExecutionOptions<OUTPUT> & {
    messages: UI_MESSAGE[];
    resumeData?: Record<string, any>;
    /** The trigger for the request - sent by AI SDK's useChat hook */
    trigger?: 'submit-message' | 'regenerate-message';
};
/**
 * Extracted from the second parameter of `Mastra.getAgentById` so the type
 * stays in sync with core automatically.
 */
export type AgentVersionOptions = NonNullable<Parameters<Mastra['getAgentById']>[1]>;
export type ChatStreamHandlerOptions<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = {
    mastra: Mastra;
    agentId: string;
    agentVersion?: AgentVersionOptions;
    params: ChatStreamHandlerParams<UI_MESSAGE, OUTPUT>;
    defaultOptions?: AgentExecutionOptions<OUTPUT>;
    version?: 'v5' | 'v6';
    sendStart?: boolean;
    sendFinish?: boolean;
    sendReasoning?: boolean;
    sendSources?: boolean;
    onError?: (error: unknown) => string;
    messageMetadata?: UI_MESSAGE extends V6UIMessage ? UIMessageStreamOptionsV6<UI_MESSAGE>['messageMetadata'] : UI_MESSAGE extends V5UIMessage ? UIMessageStreamOptionsV5<UI_MESSAGE>['messageMetadata'] : never;
};
type ChatStreamHandlerOptionsV5<UI_MESSAGE extends V5UIMessage = V5UIMessage, OUTPUT = undefined> = Omit<ChatStreamHandlerOptions<UI_MESSAGE, OUTPUT>, 'version' | 'messageMetadata'> & {
    version?: 'v5';
    messageMetadata?: UIMessageStreamOptionsV5<UI_MESSAGE>['messageMetadata'];
};
type ChatStreamHandlerOptionsV6<UI_MESSAGE extends V6UIMessage = V6UIMessage, OUTPUT = undefined> = Omit<ChatStreamHandlerOptions<UI_MESSAGE, OUTPUT>, 'version' | 'messageMetadata'> & {
    version: 'v6';
    messageMetadata?: UIMessageStreamOptionsV6<UI_MESSAGE>['messageMetadata'];
};
/**
 * Framework-agnostic handler for streaming agent chat in AI SDK-compatible format.
 * Use this function directly when you need to handle chat streaming outside of Hono or Mastra's own apiRoutes feature.
 *
 * @example
 * ```ts
 * // Next.js App Router
 * import { handleChatStream } from '@mastra/ai-sdk';
 * import { createUIMessageStreamResponse } from 'ai';
 * import { mastra } from '@/src/mastra';
 *
 * export async function POST(req: Request) {
 *   const params = await req.json();
 *   const stream = await handleChatStream({
 *     mastra,
 *     agentId: 'weatherAgent',
 *     params,
 *   });
 *   return createUIMessageStreamResponse({ stream });
 * }
 * ```
 */
export declare function handleChatStream<UI_MESSAGE extends V5UIMessage = V5UIMessage, OUTPUT = undefined>(options: ChatStreamHandlerOptionsV5<UI_MESSAGE, OUTPUT>): Promise<V5UIMessageStream<UI_MESSAGE>>;
export declare function handleChatStream<UI_MESSAGE extends V6UIMessage = V6UIMessage, OUTPUT = undefined>(options: ChatStreamHandlerOptionsV6<UI_MESSAGE, OUTPUT>): Promise<V6UIMessageStream<UI_MESSAGE>>;
export type chatRouteOptions<OUTPUT = undefined> = {
    defaultOptions?: AgentExecutionOptions<OUTPUT>;
    version?: 'v5' | 'v6';
    agentVersion?: AgentVersionOptions;
} & ({
    path: `${string}:agentId${string}`;
    agent?: never;
} | {
    path: string;
    agent: string;
}) & {
    sendStart?: boolean;
    sendFinish?: boolean;
    sendReasoning?: boolean;
    sendSources?: boolean;
};
/**
 * Creates a chat route handler for streaming agent conversations using the AI SDK format.
 *
 * This function registers an HTTP POST endpoint that accepts messages, executes an agent, and streams the response back to the client in AI SDK-compatible format.
 *
 * @param {chatRouteOptions} options - Configuration options for the chat route
 * @param {string} [options.path='/chat/:agentId'] - The route path. Include `:agentId` for dynamic routing
 * @param {string} [options.agent] - Fixed agent ID when not using dynamic routing
 * @param {AgentExecutionOptions} [options.defaultOptions] - Default options passed to agent execution
 * @param {boolean} [options.sendStart=true] - Whether to send start events in the stream
 * @param {boolean} [options.sendFinish=true] - Whether to send finish events in the stream
 * @param {boolean} [options.sendReasoning=false] - Whether to include reasoning steps in the stream
 * @param {boolean} [options.sendSources=false] - Whether to include source citations in the stream
 *
 * @returns {ReturnType<typeof registerApiRoute>} A registered API route handler
 *
 * @throws {Error} When path doesn't include `:agentId` and no fixed agent is specified
 * @throws {Error} When agent ID is missing at runtime
 * @throws {Error} When specified agent is not found in Mastra instance
 *
 * @example
 * // Dynamic agent routing
 * chatRoute({
 *   path: '/chat/:agentId',
 * });
 *
 * @example
 * // Fixed agent with custom path
 * chatRoute({
 *   path: '/api/support-chat',
 *   agent: 'support-agent',
 *   defaultOptions: {
 *     maxSteps: 5,
 *   },
 * });
 *
 * @remarks
 * - The route handler expects a JSON body with a `messages` array
 * - Messages should follow the format: `{ role: 'user' | 'assistant' | 'system', content: string }`
 * - The response is a Server-Sent Events (SSE) stream compatible with AI SDK v5
 * - If both `agent` and `:agentId` are present, a warning is logged and the fixed `agent` takes precedence
 * - Request context from the incoming request overrides `defaultOptions.requestContext` if both are present
 */
export declare function chatRoute<OUTPUT = undefined>({ path, agent, defaultOptions, version, agentVersion, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
export {};
//# sourceMappingURL=chat-route.d.ts.map