import { UIMessage, StreamTextOnFinishCallback, ToolSet } from 'ai'; import { Agent, AgentContext } from './index.js'; import { Connection, WSMessage } from 'partyserver'; import 'cloudflare:workers'; import '@modelcontextprotocol/sdk/client/index.js'; import '@modelcontextprotocol/sdk/types.js'; import './client-CAtMwErD.js'; import 'zod'; import '@modelcontextprotocol/sdk/shared/protocol.js'; import '@modelcontextprotocol/sdk/client/sse.js'; import '@modelcontextprotocol/sdk/client/streamableHttp.js'; import './mcp/do-oauth-client-provider.js'; import '@modelcontextprotocol/sdk/client/auth.js'; import '@modelcontextprotocol/sdk/shared/auth.js'; import './observability/index.js'; import './ai-types.js'; /** * Extension of Agent with built-in chat capabilities * @template Env Environment type containing bindings */ declare class AIChatAgent extends Agent { /** * Map of message `id`s to `AbortController`s * useful to propagate request cancellation signals for any external calls made by the agent */ private _chatMessageAbortControllers; /** Array of chat messages for the current conversation */ messages: UIMessage[]; constructor(ctx: AgentContext, env: Env); private _broadcastChatMessage; onMessage(connection: Connection, message: WSMessage): Promise; onRequest(request: Request): Promise; private _tryCatchChat; /** * Handle incoming chat messages and generate a response * @param onFinish Callback to be called when the response is finished * @param options.signal A signal to pass to any child requests which can be used to cancel them * @param uiMessageOnFinish Callback to be called when UI message stream is finished * @returns Response to send to the client or undefined */ onChatMessage(onFinish: StreamTextOnFinishCallback, options?: { abortSignal: AbortSignal | undefined; }, uiMessageOnFinish?: (messages: UIMessage[]) => Promise): Promise; /** * Save messages on the server side and trigger AI response * @param messages Chat messages to save */ saveMessages(messages: UIMessage[]): Promise; persistMessages(messages: UIMessage[], excludeBroadcastIds?: string[]): Promise; private _messagesNotAlreadyInAgent; private _reply; /** * For the given message id, look up its associated AbortController * If the AbortController does not exist, create and store one in memory * * returns the AbortSignal associated with the AbortController */ private _getAbortSignal; /** * Remove an abort controller from the cache of pending message responses */ private _removeAbortController; /** * Propagate an abort signal for any requests associated with the given message id */ private _cancelChatRequest; /** * Abort all pending requests and clear the cache of AbortControllers */ private _destroyAbortControllers; /** * When the DO is destroyed, cancel all pending requests */ destroy(): Promise; } export { AIChatAgent };