@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;" />
1 lines • 2.39 kB
Source Map (JSON)
{"version":3,"file":"hono-single.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono-single.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\nimport { CopilotEndpointCorsConfig, toFetchCorsConfig } from \"./hono\";\n\ninterface CopilotSingleEndpointParams {\n runtime: CopilotRuntimeLike;\n /**\n * Absolute path at which to mount the single-route endpoint (e.g. \"/api/copilotkit\").\n */\n basePath: string;\n /**\n * Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.\n * To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.\n */\n cors?: CopilotEndpointCorsConfig;\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n}\n\n/** @deprecated Use `createCopilotHonoHandler` with `mode: \"single-route\"` instead. */\nexport function createCopilotEndpointSingleRoute({\n runtime,\n basePath,\n cors: corsConfig,\n hooks,\n}: CopilotSingleEndpointParams) {\n const routePath = normalizePath(basePath);\n\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath: routePath,\n mode: \"single-route\",\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n });\n\n const app = new Hono();\n\n return app.basePath(routePath).all(\"*\", async (c) => handler(c.req.raw));\n}\n\nfunction normalizePath(path: string): string {\n if (!path) {\n throw new Error(\"basePath must be provided for single-route endpoint\");\n }\n\n if (!path.startsWith(\"/\")) {\n return `/${path}`;\n }\n\n if (path.length > 1 && path.endsWith(\"/\")) {\n return path.slice(0, -1);\n }\n\n return path;\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,iCAAiC,EAC/C,SACA,UACA,MAAM,YACN,SAC8B;CAC9B,MAAM,YAAY,cAAc,SAAS;CAEzC,MAAM,UAAU,4BAA4B;EAC1C;EACA,UAAU;EACV,MAAM;EACN,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACD,CAAC;AAIF,QAFY,IAAI,MAAM,CAEX,SAAS,UAAU,CAAC,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;;AAG1E,SAAS,cAAc,MAAsB;AAC3C,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,sDAAsD;AAGxE,KAAI,CAAC,KAAK,WAAW,IAAI,CACvB,QAAO,IAAI;AAGb,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,IAAI,CACvC,QAAO,KAAK,MAAM,GAAG,GAAG;AAG1B,QAAO"}