import { PartySocket } from 'partysocket'; import { usePartySocket } from 'partysocket/react'; import { MCPServersState, Agent } from './index.js'; import { StreamOptions } from './client.js'; import { Method, RPCMethod } from './serializable.js'; import 'cloudflare:workers'; import '@modelcontextprotocol/sdk/client/index.js'; import '@modelcontextprotocol/sdk/types.js'; import 'partyserver'; import './client-CAtMwErD.js'; import 'zod'; import '@modelcontextprotocol/sdk/shared/protocol.js'; import 'ai'; 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'; /** * Options for the useAgent hook * @template State Type of the Agent's state */ type UseAgentOptions = Omit[0], "party" | "room"> & { /** Name of the agent to connect to */ agent: string; /** Name of the specific Agent instance */ name?: string; /** Called when the Agent's state is updated */ onStateUpdate?: (state: State, source: "server" | "client") => void; /** Called when MCP server state is updated */ onMcpUpdate?: (mcpServers: MCPServersState) => void; }; type AllOptional = T extends [infer A, ...infer R] ? undefined extends A ? AllOptional : false : true; type RPCMethods = { [K in keyof T as T[K] extends RPCMethod ? K : never]: RPCMethod; }; type OptionalParametersMethod = AllOptional> extends true ? T : never; type AgentMethods = Omit, keyof Agent>; type OptionalAgentMethods = { [K in keyof AgentMethods as AgentMethods[K] extends OptionalParametersMethod[K]> ? K : never]: OptionalParametersMethod[K]>; }; type RequiredAgentMethods = Omit, keyof OptionalAgentMethods>; type AgentPromiseReturnType> = ReturnType[K]> extends Promise ? ReturnType[K]> : Promise[K]>>; type OptionalArgsAgentMethodCall = >(method: K, args?: Parameters[K]>, streamOptions?: StreamOptions) => AgentPromiseReturnType; type RequiredArgsAgentMethodCall = >(method: K, args: Parameters[K]>, streamOptions?: StreamOptions) => AgentPromiseReturnType; type AgentMethodCall = OptionalArgsAgentMethodCall & RequiredArgsAgentMethodCall; type UntypedAgentMethodCall = (method: string, args?: unknown[], streamOptions?: StreamOptions) => Promise; type AgentStub = { [K in keyof AgentMethods]: (...args: Parameters[K]>) => AgentPromiseReturnType, K>; }; type UntypedAgentStub = Record; /** * React hook for connecting to an Agent * @template State Type of the Agent's state * @template Agent Type of the Agent * @param options Connection options * @returns WebSocket connection with setState and call methods */ declare function useAgent(options: UseAgentOptions): PartySocket & { agent: string; name: string; setState: (state: State) => void; call: UntypedAgentMethodCall; stub: UntypedAgentStub; }; declare function useAgent(options: UseAgentOptions): PartySocket & { agent: string; name: string; setState: (state: State) => void; call: AgentMethodCall; stub: AgentStub; }; export { type UseAgentOptions, useAgent };