{"version":3,"file":"hono.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotCorsConfig } from \"../core/fetch-cors\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\n\n/**\n * CORS configuration for CopilotKit endpoints.\n * When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.\n */\nexport interface CopilotEndpointCorsConfig {\n  /**\n   * Allowed origin(s) for CORS. Can be:\n   * - A string: exact origin (e.g., \"https://myapp.com\")\n   * - An array: list of allowed origins\n   * - A function: dynamic origin resolution\n   *\n   * Note: When credentials is true, origin cannot be \"*\"\n   */\n  origin:\n    | string\n    | string[]\n    | ((origin: string, c: any) => string | undefined | null);\n  /**\n   * Whether to allow credentials (cookies, HTTP authentication).\n   * When true, origin must be explicitly specified (not \"*\").\n   */\n  credentials?: boolean;\n}\n\ninterface CopilotEndpointParams {\n  runtime: CopilotRuntimeLike;\n  basePath: string;\n\n  /**\n   * Endpoint mode.\n   * - `\"multi-route\"` (default): separate routes for each operation\n   * - `\"single-route\"`: single POST endpoint with JSON envelope dispatch\n   */\n  mode?: \"multi-route\" | \"single-route\";\n\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/** @deprecated Use `createCopilotHonoHandler` instead. */\nexport const createCopilotEndpoint = createCopilotHonoHandler;\n\nexport function createCopilotHonoHandler({\n  runtime,\n  basePath,\n  mode = \"multi-route\",\n  cors: corsConfig,\n  hooks,\n}: CopilotEndpointParams) {\n  const handler = createCopilotRuntimeHandler({\n    runtime,\n    basePath,\n    mode,\n    cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n    hooks,\n  });\n\n  const app = new Hono();\n\n  return app.basePath(basePath).all(\"*\", async (c) => handler(c.req.raw));\n}\n\n/**\n * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.\n */\nexport function toFetchCorsConfig(\n  config: CopilotEndpointCorsConfig,\n): CopilotCorsConfig {\n  const origin = config.origin;\n  return {\n    origin:\n      typeof origin === \"function\"\n        ? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null\n        : origin,\n    credentials: config.credentials,\n  };\n}\n"],"mappings":";;;;;;AAoDA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,SACwB;CACxB,MAAM,UAAU,4BAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACD,CAAC;AAIF,QAFY,IAAI,MAAM,CAEX,SAAS,SAAS,CAAC,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;;;;;AAMzE,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}