@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;" />
31 lines (29 loc) • 1.06 kB
JavaScript
import "reflect-metadata";
import { createCopilotRuntimeHandler } from "../core/fetch-handler.mjs";
import { Hono } from "hono";
//#region src/v2/runtime/endpoints/hono.ts
/** @deprecated Use `createCopilotHonoHandler` instead. */
const createCopilotEndpoint = createCopilotHonoHandler;
function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks }) {
const handler = createCopilotRuntimeHandler({
runtime,
basePath,
mode,
cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
hooks
});
return new Hono().basePath(basePath).all("*", async (c) => handler(c.req.raw));
}
/**
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
*/
function toFetchCorsConfig(config) {
const origin = config.origin;
return {
origin: typeof origin === "function" ? (reqOrigin) => origin(reqOrigin, void 0) ?? null : origin,
credentials: config.credentials
};
}
//#endregion
export { createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
//# sourceMappingURL=hono.mjs.map