
import { AfterRequestMiddleware, BeforeRequestMiddleware } from "./middleware.cjs";
import { CopilotRuntimeLogger } from "../../../lib/logger.cjs";
import { TranscriptionService } from "../transcription-service/transcription-service.cjs";
import { AgentRunner } from "../runner/agent-runner.cjs";
import { CopilotKitIntelligence } from "../intelligence-platform/client.cjs";
import { DebugConfig, MaybePromise, NonEmptyRecord, ResolvedDebugConfig, RuntimeMode } from "@copilotkit/shared";
import { LicenseChecker } from "@copilotkit/license-verifier";
import { AbstractAgent } from "@ag-ui/client";
import { MCPClientConfig } from "@ag-ui/mcp-apps-middleware";
import { A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";

//#region src/v2/runtime/core/runtime.d.ts
declare const VERSION: string;
interface BaseCopilotRuntimeMiddlewareOptions {
  /** If set, middleware only applies to these named agents. Applies to all agents if omitted. */
  agents?: string[];
}
type McpAppsServerConfig = MCPClientConfig & {
  /** Agent to bind this server to. If omitted, the server is available to all agents. */agentId?: string;
};
interface McpAppsConfig {
  /** List of MCP server configurations. */
  servers: McpAppsServerConfig[];
}
interface OpenGenerativeUIOptions extends BaseCopilotRuntimeMiddlewareOptions {}
type OpenGenerativeUIConfig = boolean | OpenGenerativeUIOptions;
interface CopilotRuntimeMiddlewares {
  /**
   * Auto-apply A2UIMiddleware to agents at run time.
   * Pass an object to enable and customise behaviour, or omit to disable.
   */
  a2ui?: BaseCopilotRuntimeMiddlewareOptions & A2UIMiddlewareConfig;
  /** Auto-apply MCPAppsMiddleware to agents at run time. */
  mcpApps?: McpAppsConfig;
  /** Auto-apply OpenGenerativeUIMiddleware to agents at run time. */
  openGenerativeUI?: OpenGenerativeUIConfig;
}
/**
 * Context passed to agent factory functions for per-request agent resolution.
 */
interface AgentFactoryContext {
  /** The incoming HTTP request. */
  request: Request;
}
/**
 * A function that dynamically creates agents on a per-request basis.
 * Useful for multi-tenant scenarios or request-scoped agent configuration.
 */
type AgentsFactory = (ctx: AgentFactoryContext) => MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
/**
 * Agents can be provided as:
 * - A static record of agents
 * - A Promise that resolves to a record of agents
 * - A factory function that receives request context and returns agents (or a Promise of agents)
 */
type AgentsConfig = MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>> | AgentsFactory;
/**
 * Resolve an AgentsConfig value to a concrete record of agents.
 * If the config is a factory function, it is called with the given request context.
 * Otherwise it is awaited directly (static record or Promise).
 */
declare function resolveAgents(agents: AgentsConfig, request?: Request): Promise<Record<string, AbstractAgent>>;
interface BaseCopilotRuntimeOptions extends CopilotRuntimeMiddlewares {
  /**
   * Map of available agents, or a factory function for per-request agent resolution.
   *
   * Static record:
   * ```ts
   * agents: { support: new SupportAgent(), technical: new TechnicalAgent() }
   * ```
   *
   * Factory function (called per-request):
   * ```ts
   * agents: ({ request }) => {
   *   const tenantId = request.headers.get("x-tenant-id");
   *   return { default: createAgentForTenant(tenantId) };
   * }
   * ```
   */
  agents: AgentsConfig;
  /** Optional transcription service for audio processing. */
  transcriptionService?: TranscriptionService;
  /** Optional *before* middleware – callback function or webhook URL. */
  beforeRequestMiddleware?: BeforeRequestMiddleware;
  /** Optional *after* middleware – callback function or webhook URL. */
  afterRequestMiddleware?: AfterRequestMiddleware;
  /** Signed license token for server-side feature verification. Falls back to COPILOTKIT_LICENSE_TOKEN env var. */
  licenseToken?: string;
  /** Enable debug logging for the event pipeline. */
  debug?: DebugConfig;
}
interface CopilotRuntimeUser {
  id: string;
}
type IdentifyUserCallback = (request: Request) => MaybePromise<CopilotRuntimeUser>;
interface CopilotSseRuntimeOptions extends BaseCopilotRuntimeOptions {
  /** The runner to use for running agents in SSE mode. */
  runner?: AgentRunner;
  intelligence?: undefined;
  generateThreadNames?: undefined;
}
interface CopilotIntelligenceRuntimeOptions extends BaseCopilotRuntimeOptions {
  /** Configures Intelligence mode for durable threads and realtime events. */
  intelligence: CopilotKitIntelligence;
  /** Resolves the authenticated user for intelligence requests. */
  identifyUser: IdentifyUserCallback;
  /** Auto-generate short names for newly created threads. */
  generateThreadNames?: boolean;
  /** Max delay (ms) for WebSocket reconnect backoff. @default 10_000 */
  maxReconnectMs?: number;
  /** Max delay (ms) for channel rejoin backoff. @default 30_000 */
  maxRejoinMs?: number;
  /** Lock TTL in seconds. Clamped to a maximum of 3600 (1 hour). @default 20 */
  lockTtlSeconds?: number;
  /** Custom Redis key prefix for the thread lock. */
  lockKeyPrefix?: string;
  /** Interval in seconds at which the runtime renews the thread lock. Clamped to a maximum of 3000 (50 minutes). @default 15 */
  lockHeartbeatIntervalSeconds?: number;
}
type CopilotRuntimeOptions = CopilotSseRuntimeOptions | CopilotIntelligenceRuntimeOptions;
interface CopilotRuntimeLike {
  agents: CopilotRuntimeOptions["agents"];
  transcriptionService: CopilotRuntimeOptions["transcriptionService"];
  beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
  afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
  runner: AgentRunner;
  a2ui: CopilotRuntimeOptions["a2ui"];
  mcpApps: CopilotRuntimeOptions["mcpApps"];
  openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
  intelligence?: CopilotKitIntelligence;
  identifyUser?: IdentifyUserCallback;
  mode: RuntimeMode;
  licenseChecker?: LicenseChecker;
  debug: ResolvedDebugConfig;
  debugLogger?: CopilotRuntimeLogger;
}
interface CopilotSseRuntimeLike extends CopilotRuntimeLike {
  intelligence?: undefined;
  mode: RUNTIME_MODE_SSE;
}
interface CopilotIntelligenceRuntimeLike extends CopilotRuntimeLike {
  intelligence: CopilotKitIntelligence;
  identifyUser: IdentifyUserCallback;
  generateThreadNames: boolean;
  lockTtlSeconds: number;
  lockKeyPrefix?: string;
  lockHeartbeatIntervalSeconds: number;
  mode: RUNTIME_MODE_INTELLIGENCE;
}
declare abstract class BaseCopilotRuntime implements CopilotRuntimeLike {
  agents: CopilotRuntimeOptions["agents"];
  transcriptionService: CopilotRuntimeOptions["transcriptionService"];
  beforeRequestMiddleware: CopilotRuntimeOptions["beforeRequestMiddleware"];
  afterRequestMiddleware: CopilotRuntimeOptions["afterRequestMiddleware"];
  runner: AgentRunner;
  a2ui: CopilotRuntimeOptions["a2ui"];
  mcpApps: CopilotRuntimeOptions["mcpApps"];
  openGenerativeUI: CopilotRuntimeOptions["openGenerativeUI"];
  licenseChecker?: LicenseChecker;
  debug: ResolvedDebugConfig;
  debugLogger?: CopilotRuntimeLogger;
  abstract readonly intelligence?: CopilotKitIntelligence;
  abstract readonly mode: RuntimeMode;
  constructor(options: BaseCopilotRuntimeOptions, runner: AgentRunner);
}
declare class CopilotSseRuntime extends BaseCopilotRuntime implements CopilotSseRuntimeLike {
  readonly intelligence: any;
  readonly mode: "sse";
  constructor(options: CopilotSseRuntimeOptions);
}
declare class CopilotIntelligenceRuntime extends BaseCopilotRuntime implements CopilotIntelligenceRuntimeLike {
  readonly intelligence: CopilotKitIntelligence;
  readonly identifyUser: IdentifyUserCallback;
  readonly generateThreadNames: boolean;
  readonly lockTtlSeconds: number;
  readonly lockKeyPrefix?: string;
  readonly lockHeartbeatIntervalSeconds: number;
  readonly mode: "intelligence";
  /** Maximum allowed lock TTL in seconds (1 hour). */
  static readonly MAX_LOCK_TTL_SECONDS = 3600;
  /** Maximum allowed heartbeat interval in seconds (50 minutes). */
  static readonly MAX_HEARTBEAT_INTERVAL_SECONDS = 3000;
  constructor(options: CopilotIntelligenceRuntimeOptions);
}
declare function isIntelligenceRuntime(runtime: CopilotRuntimeLike): runtime is CopilotIntelligenceRuntimeLike;
/**
 * Compatibility shim that preserves the legacy `CopilotRuntime` entrypoint.
 * New code should prefer `CopilotSseRuntime` or `CopilotIntelligenceRuntime`.
 */
declare class CopilotRuntime implements CopilotRuntimeLike {
  private delegate;
  constructor(options: CopilotRuntimeOptions);
  get agents(): CopilotRuntimeOptions["agents"];
  get transcriptionService(): CopilotRuntimeOptions["transcriptionService"];
  get beforeRequestMiddleware(): CopilotRuntimeOptions["beforeRequestMiddleware"];
  get afterRequestMiddleware(): CopilotRuntimeOptions["afterRequestMiddleware"];
  get runner(): AgentRunner;
  get a2ui(): CopilotRuntimeOptions["a2ui"];
  get mcpApps(): CopilotRuntimeOptions["mcpApps"];
  get openGenerativeUI(): CopilotRuntimeOptions["openGenerativeUI"];
  get intelligence(): CopilotKitIntelligence | undefined;
  get generateThreadNames(): boolean | undefined;
  get identifyUser(): IdentifyUserCallback | undefined;
  get lockTtlSeconds(): number | undefined;
  get lockKeyPrefix(): string | undefined;
  get lockHeartbeatIntervalSeconds(): number | undefined;
  get mode(): RuntimeMode;
  get licenseChecker(): LicenseChecker;
  get debug(): ResolvedDebugConfig;
  get debugLogger(): CopilotRuntimeLogger | undefined;
}
//#endregion
export { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeLike, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, OpenGenerativeUIConfig, OpenGenerativeUIOptions, VERSION, isIntelligenceRuntime, resolveAgents };
//# sourceMappingURL=runtime.d.cts.map