
import { MessageInput } from "../../graphql/inputs/message.input.cjs";
import { Message as Message$1 } from "../../graphql/types/converted/index.cjs";
import { CopilotServiceAdapter } from "../../service-adapters/service-adapter.cjs";
import { RemoteChainParameters } from "../../service-adapters/langchain/langserve.cjs";
import "../../service-adapters/index.cjs";
import { AgentRunner } from "../../v2/runtime/runner/agent-runner.cjs";
import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotRuntime as CopilotRuntime$1, CopilotRuntimeOptions } from "../../v2/runtime/core/runtime.cjs";
import "../../v2/runtime/index.cjs";
import { CopilotKitEndpoint, EndpointDefinition, EndpointType, LangGraphPlatformEndpoint } from "./types.cjs";
import { CopilotObservabilityConfig } from "../observability.cjs";
import { MCPClient, MCPEndpointConfig } from "./mcp-tools-utils.cjs";
import { Action, CopilotErrorHandler, DebugConfig, Parameter, PartialBy } from "@copilotkit/shared";
import { AbstractAgent } from "@ag-ui/client";

//#region src/lib/runtime/copilot-runtime.d.ts
type CreateMCPClientFunction = (config: MCPEndpointConfig) => Promise<MCPClient>;
type ActionsConfiguration<T extends Parameter[] | [] = []> = Action<T>[] | ((ctx: {
  properties: any;
  url?: string;
}) => Action<T>[]);
interface OnBeforeRequestOptions {
  threadId?: string;
  runId?: string;
  inputMessages: Message$1[];
  properties: any;
  url?: string;
}
type OnBeforeRequestHandler = (options: OnBeforeRequestOptions) => void | Promise<void>;
interface OnAfterRequestOptions {
  threadId: string;
  runId?: string;
  inputMessages: Message$1[];
  outputMessages: Message$1[];
  properties: any;
  url?: string;
}
type OnAfterRequestHandler = (options: OnAfterRequestOptions) => void | Promise<void>;
interface OnStopGenerationOptions {
  threadId: string;
  runId?: string;
  url?: string;
  agentName?: string;
  lastMessage: MessageInput;
}
type OnStopGenerationHandler = (options: OnStopGenerationOptions) => void | Promise<void>;
interface Middleware {
  /**
   * A function that is called before the request is processed.
   */
  /**
   * @deprecated This middleware hook is deprecated and will be removed in a future version.
   * Use updated middleware integration methods in CopilotRuntimeVNext instead.
   */
  onBeforeRequest?: OnBeforeRequestHandler;
  /**
   * A function that is called after the request is processed.
   */
  /**
   * @deprecated This middleware hook is deprecated and will be removed in a future version.
   * Use updated middleware integration methods in CopilotRuntimeVNext instead.
   */
  onAfterRequest?: OnAfterRequestHandler;
}
interface CopilotRuntimeConstructorParams_BASE<T extends Parameter[] | [] = []> {
  /**
   * Middleware to be used by the runtime.
   *
   * ```ts
   * onBeforeRequest: (options: {
   *   threadId?: string;
   *   runId?: string;
   *   inputMessages: Message[];
   *   properties: any;
   * }) => void | Promise<void>;
   * ```
   *
   * ```ts
   * onAfterRequest: (options: {
   *   threadId?: string;
   *   runId?: string;
   *   inputMessages: Message[];
   *   outputMessages: Message[];
   *   properties: any;
   * }) => void | Promise<void>;
   * ```
   */
  /**
   * @deprecated This middleware hook is deprecated and will be removed in a future version.
   * Use updated middleware integration methods in CopilotRuntimeVNext instead.
   */
  middleware?: Middleware;
  actions?: ActionsConfiguration<T>;
  remoteActions?: CopilotKitEndpoint[];
  remoteEndpoints?: EndpointDefinition[];
  langserve?: RemoteChainParameters[];
  /**
   * Optional agent runner to use for SSE runtime.
   */
  runner?: AgentRunner;
  agents?: Record<string, AbstractAgent>;
  delegateAgentProcessingToServiceAdapter?: boolean;
  /**
   * Configuration for LLM request/response logging.
   * Requires publicApiKey from CopilotKit component to be set:
   *
   * ```tsx
   * <CopilotKit publicApiKey="ck_pub_..." />
   * ```
   *
   * Example logging config:
   * ```ts
   * logging: {
   *   enabled: true, // Enable or disable logging
   *   progressive: true, // Set to false for buffered logging
   *   logger: {
   *     logRequest: (data) => langfuse.trace({ name: "LLM Request", input: data }),
   *     logResponse: (data) => langfuse.trace({ name: "LLM Response", output: data }),
   *     logError: (errorData) => langfuse.trace({ name: "LLM Error", metadata: errorData }),
   *   },
   * }
   * ```
   */
  observability_c?: CopilotObservabilityConfig;
  /**
   * Configuration for connecting to Model Context Protocol (MCP) servers.
   * Allows fetching and using tools defined on external MCP-compliant servers.
   * Requires providing the `createMCPClient` function during instantiation.
   * @experimental
   */
  mcpServers?: MCPEndpointConfig[];
  /**
   * A function that creates an MCP client instance for a given endpoint configuration.
   * This function is responsible for using the appropriate MCP client library
   * (e.g., `@copilotkit/runtime`, `ai`) to establish a connection.
   * Required if `mcpServers` is provided.
   *
   * ```typescript
   * import { experimental_createMCPClient } from "ai"; // Import from vercel ai library
   * // ...
   * const runtime = new CopilotRuntime({
   *   mcpServers: [{ endpoint: "..." }],
   *   async createMCPClient(config) {
   *     return await experimental_createMCPClient({
   *       transport: {
   *         type: "sse",
   *         url: config.endpoint,
   *         headers: config.apiKey
   *           ? { Authorization: `Bearer ${config.apiKey}` }
   *           : undefined,
   *       },
   *     });
   *   }
   * });
   * ```
   */
  createMCPClient?: CreateMCPClientFunction;
  /**
   * Optional error handler for comprehensive debugging and observability.
   *
   * **Requires publicApiKey**: Error handling only works when requests include a valid publicApiKey.
   * This is a premium Copilot Cloud feature.
   *
   * @param errorEvent - Structured error event with rich debugging context
   *
   * @example
   * ```typescript
   * const runtime = new CopilotRuntime({
   *   onError: (errorEvent) => {
   *     debugDashboard.capture(errorEvent);
   *   }
   * });
   * ```
   */
  onError?: CopilotErrorHandler;
  onStopGeneration?: OnStopGenerationHandler;
  /**
   * Enable debug logging for the runtime event pipeline.
   * Pass `true` for full output, or an object for granular control:
   *
   * ```ts
   * const runtime = new CopilotRuntime({
   *   debug: true,
   *   // or: debug: { events: true, lifecycle: true, verbose: false }
   * });
   * ```
   */
  debug?: DebugConfig;
}
interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> extends Omit<CopilotRuntimeConstructorParams_BASE<T>, "agents">, Omit<CopilotRuntimeOptions, "agents" | "transcriptionService"> {
  /**
   * TODO: un-omit `transcriptionService` above once it's supported
   *
   * This satisfies...
   *  – the optional constraint in `CopilotRuntimeConstructorParams_BASE`
   *  – the `MaybePromise<NonEmptyRecord<T>>` constraint in `CopilotRuntimeOptionsVNext`
   *  – the `Record<string, AbstractAgent>` constraint in `both
   */
  agents?: AgentsConfig;
}
/**
 * Central runtime object passed to all request handlers.
 */
declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
  params?: CopilotRuntimeConstructorParams<T>;
  private observability?;
  private mcpToolsCache;
  private runtimeArgs;
  private _instance;
  constructor(params?: CopilotRuntimeConstructorParams<T> & PartialBy<CopilotRuntimeOptions, "agents">);
  get instance(): CopilotRuntime$1;
  private assignEndpointsToAgents;
  handleServiceAdapter(serviceAdapter: CopilotServiceAdapter): void;
  private getToolsFromActions;
  private assignToolsToAgents;
  private createOnBeforeRequestHandler;
  private createOnAfterRequestHandler;
  /**
   * Log LLM request if observability is enabled
   */
  private logObservabilityBeforeRequest;
  /**
   * Log final LLM response after request completes
   */
  private logObservabilityAfterRequest;
  private getToolsFromMCP;
}
declare function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): CopilotKitEndpoint;
declare function langGraphPlatformEndpoint(config: Omit<LangGraphPlatformEndpoint, "type">): LangGraphPlatformEndpoint;
declare function resolveEndpointType(endpoint: EndpointDefinition): EndpointType;
//#endregion
export { CopilotRuntime, CopilotRuntimeConstructorParams_BASE, copilotKitEndpoint, langGraphPlatformEndpoint, resolveEndpointType };
//# sourceMappingURL=copilot-runtime.d.cts.map