@copilotkit/runtime
Version:
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
87 lines (86 loc) • 3.31 kB
text/typescript
require("reflect-metadata");
import { CopilotRuntimeLike } from "../core/runtime.cjs";
import { CopilotCorsConfig } from "../core/fetch-cors.cjs";
import { CopilotRuntimeHooks } from "../core/hooks.cjs";
import { ActivateChannelEngine, ChannelsControl } from "../core/channel-manager.cjs";
import { Hono } from "hono";
//#region src/v2/runtime/endpoints/hono.d.ts
/**
* A Hono app that may also carry an optional {@link ChannelsControl} surface.
* Hono's app object is request-scoped routing config, not a long-running
* process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning
* surface for `.channels`. It is attached here too, best-effort, for callers
* that mount the Hono app directly and want to observe/stop managed Channel
* activation without also standing up a Node listener.
*/
type CopilotHonoApp = Hono & {
channels?: ChannelsControl;
};
/**
* CORS configuration for CopilotKit endpoints.
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
*/
interface CopilotEndpointCorsConfig {
/**
* Allowed origin(s) for CORS. Can be:
* - A string: exact origin (e.g., "https://myapp.com")
* - An array: list of allowed origins
* - A function: dynamic origin resolution
*
* Note: When credentials is true, origin cannot be "*"
*/
origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
/**
* Whether to allow credentials (cookies, HTTP authentication).
* When true, origin must be explicitly specified (not "*").
*/
credentials?: boolean;
}
interface CopilotEndpointParams {
runtime: CopilotRuntimeLike;
basePath: string;
/**
* Endpoint mode.
* - `"multi-route"` (default): separate routes for each operation
* - `"single-route"`: single POST endpoint with JSON envelope dispatch
*/
mode?: "multi-route" | "single-route";
/**
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
*/
cors?: CopilotEndpointCorsConfig;
/**
* Lifecycle hooks for request processing.
*/
hooks?: CopilotRuntimeHooks;
/**
* Whether the underlying handler activates the runtime's declared managed
* Channels at creation time. Defaults to `true`. See
* `CopilotRuntimeHandlerOptions.activateChannels`.
*/
activateChannels?: boolean;
/**
* @internal Test seam: inject a fake Channel activation engine. Forwarded
* to `createCopilotRuntimeHandler`. Not part of the public API.
*/
__channelEngine?: ActivateChannelEngine;
}
/** @deprecated Use `createCopilotHonoHandler` instead. */
declare const createCopilotEndpoint: typeof createCopilotHonoHandler;
declare function createCopilotHonoHandler({
runtime,
basePath,
mode,
cors: corsConfig,
hooks,
activateChannels,
__channelEngine
}: CopilotEndpointParams): CopilotHonoApp;
/**
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
*/
declare function toFetchCorsConfig(config: CopilotEndpointCorsConfig): CopilotCorsConfig;
//#endregion
export { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
//# sourceMappingURL=hono.d.cts.map