@copilotkitnext/runtime 1.51.4 → 1.51.5-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/endpoints/express-single.cjs +187 -0
- package/dist/endpoints/express-single.cjs.map +1 -0
- package/dist/endpoints/express-single.d.cts +15 -0
- package/dist/endpoints/express-single.d.cts.map +1 -0
- package/dist/endpoints/express-single.d.mts +15 -0
- package/dist/endpoints/express-single.d.mts.map +1 -0
- package/dist/endpoints/express-single.mjs +184 -0
- package/dist/endpoints/express-single.mjs.map +1 -0
- package/dist/endpoints/express-utils.cjs +118 -0
- package/dist/endpoints/express-utils.cjs.map +1 -0
- package/dist/endpoints/express-utils.mjs +116 -0
- package/dist/endpoints/express-utils.mjs.map +1 -0
- package/dist/endpoints/express.cjs +165 -0
- package/dist/endpoints/express.cjs.map +1 -0
- package/dist/endpoints/express.d.cts +15 -0
- package/dist/endpoints/express.d.cts.map +1 -0
- package/dist/endpoints/express.d.mts +15 -0
- package/dist/endpoints/express.d.mts.map +1 -0
- package/dist/endpoints/express.mjs +162 -0
- package/dist/endpoints/express.mjs.map +1 -0
- package/dist/endpoints/hono-single.cjs +140 -0
- package/dist/endpoints/hono-single.cjs.map +1 -0
- package/dist/endpoints/hono-single.d.cts +31 -0
- package/dist/endpoints/hono-single.d.cts.map +1 -0
- package/dist/endpoints/hono-single.d.mts +31 -0
- package/dist/endpoints/hono-single.d.mts.map +1 -0
- package/dist/endpoints/hono-single.mjs +139 -0
- package/dist/endpoints/hono-single.mjs.map +1 -0
- package/dist/endpoints/hono.cjs +152 -0
- package/dist/endpoints/hono.cjs.map +1 -0
- package/dist/endpoints/hono.d.cts +47 -0
- package/dist/endpoints/hono.d.cts.map +1 -0
- package/dist/endpoints/hono.d.mts +47 -0
- package/dist/endpoints/hono.d.mts.map +1 -0
- package/dist/endpoints/hono.mjs +151 -0
- package/dist/endpoints/hono.mjs.map +1 -0
- package/dist/endpoints/index.cjs +2 -0
- package/dist/endpoints/index.d.mts +2 -0
- package/dist/endpoints/index.mjs +4 -0
- package/dist/endpoints/single-route-helpers.cjs +67 -0
- package/dist/endpoints/single-route-helpers.cjs.map +1 -0
- package/dist/endpoints/single-route-helpers.mjs +64 -0
- package/dist/endpoints/single-route-helpers.mjs.map +1 -0
- package/dist/express.cjs +6 -0
- package/dist/express.d.cts +3 -0
- package/dist/express.d.mts +3 -19
- package/dist/express.mjs +3 -477
- package/dist/handlers/get-runtime-info.cjs +36 -0
- package/dist/handlers/get-runtime-info.cjs.map +1 -0
- package/dist/handlers/get-runtime-info.mjs +36 -0
- package/dist/handlers/get-runtime-info.mjs.map +1 -0
- package/dist/handlers/handle-connect.cjs +102 -0
- package/dist/handlers/handle-connect.cjs.map +1 -0
- package/dist/handlers/handle-connect.mjs +101 -0
- package/dist/handlers/handle-connect.mjs.map +1 -0
- package/dist/handlers/handle-run.cjs +114 -0
- package/dist/handlers/handle-run.cjs.map +1 -0
- package/dist/handlers/handle-run.mjs +113 -0
- package/dist/handlers/handle-run.mjs.map +1 -0
- package/dist/handlers/handle-stop.cjs +46 -0
- package/dist/handlers/handle-stop.cjs.map +1 -0
- package/dist/handlers/handle-stop.mjs +45 -0
- package/dist/handlers/handle-stop.mjs.map +1 -0
- package/dist/handlers/handle-transcribe.cjs +111 -0
- package/dist/handlers/handle-transcribe.cjs.map +1 -0
- package/dist/handlers/handle-transcribe.mjs +110 -0
- package/dist/handlers/handle-transcribe.mjs.map +1 -0
- package/dist/handlers/header-utils.cjs +25 -0
- package/dist/handlers/header-utils.cjs.map +1 -0
- package/dist/handlers/header-utils.mjs +24 -0
- package/dist/handlers/header-utils.mjs.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +9 -139
- package/dist/index.mjs +10 -335
- package/dist/middleware.cjs +29 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +24 -0
- package/dist/middleware.d.cts.map +1 -0
- package/dist/middleware.d.mts +24 -0
- package/dist/middleware.d.mts.map +1 -0
- package/dist/middleware.mjs +27 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/runner/agent-runner.cjs +7 -0
- package/dist/runner/agent-runner.cjs.map +1 -0
- package/dist/runner/agent-runner.d.cts +28 -0
- package/dist/runner/agent-runner.d.cts.map +1 -0
- package/dist/runner/agent-runner.d.mts +28 -0
- package/dist/runner/agent-runner.d.mts.map +1 -0
- package/dist/runner/agent-runner.mjs +6 -0
- package/dist/runner/agent-runner.mjs.map +1 -0
- package/dist/runner/in-memory.cjs +230 -0
- package/dist/runner/in-memory.cjs.map +1 -0
- package/dist/runner/in-memory.d.cts +14 -0
- package/dist/runner/in-memory.d.cts.map +1 -0
- package/dist/runner/in-memory.d.mts +14 -0
- package/dist/runner/in-memory.d.mts.map +1 -0
- package/dist/runner/in-memory.mjs +229 -0
- package/dist/runner/in-memory.mjs.map +1 -0
- package/dist/runner/index.cjs +4 -0
- package/dist/runner/index.d.cts +4 -0
- package/dist/runner/index.d.mts +4 -0
- package/dist/runner/index.mjs +5 -0
- package/dist/runtime.cjs +27 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +43 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.mts +43 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +26 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/transcription-service/transcription-service.cjs +7 -0
- package/dist/transcription-service/transcription-service.cjs.map +1 -0
- package/dist/transcription-service/transcription-service.d.cts +14 -0
- package/dist/transcription-service/transcription-service.d.cts.map +1 -0
- package/dist/transcription-service/transcription-service.d.mts +14 -0
- package/dist/transcription-service/transcription-service.d.mts.map +1 -0
- package/dist/transcription-service/transcription-service.mjs +6 -0
- package/dist/transcription-service/transcription-service.mjs.map +1 -0
- package/package.json +25 -22
- package/tsdown.config.ts +16 -0
- package/dist/chunk-5GKH3W25.mjs +0 -1054
- package/dist/chunk-5GKH3W25.mjs.map +0 -1
- package/dist/express.d.ts +0 -19
- package/dist/express.js +0 -1292
- package/dist/express.js.map +0 -1
- package/dist/express.mjs.map +0 -1
- package/dist/index.d.ts +0 -139
- package/dist/index.js +0 -1387
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/runtime-BsuyYT2l.d.mts +0 -98
- package/dist/runtime-BsuyYT2l.d.ts +0 -98
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono-single.cjs","names":["Hono","callBeforeRequestMiddleware","parseMethodCall","expectString","handleRunAgent","createJsonRequest","handleConnectAgent","handleStopAgent","handleGetRuntimeInfo","handleTranscribe"],"sources":["../../src/endpoints/hono-single.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport { cors } from \"hono/cors\";\n\nimport { CopilotRuntime } from \"../runtime\";\nimport { handleRunAgent } from \"../handlers/handle-run\";\nimport { handleConnectAgent } from \"../handlers/handle-connect\";\nimport { handleStopAgent } from \"../handlers/handle-stop\";\nimport { handleGetRuntimeInfo } from \"../handlers/get-runtime-info\";\nimport { handleTranscribe } from \"../handlers/handle-transcribe\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport {\n callBeforeRequestMiddleware,\n callAfterRequestMiddleware,\n} from \"../middleware\";\nimport {\n createJsonRequest,\n expectString,\n MethodCall,\n parseMethodCall,\n} from \"./single-route-helpers\";\n\nimport { CopilotEndpointCorsConfig } from \"./hono\";\n\ninterface CopilotSingleEndpointParams {\n runtime: CopilotRuntime;\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\ntype CopilotEndpointContext = {\n Variables: {\n modifiedRequest?: Request;\n };\n};\n\nexport function createCopilotEndpointSingleRoute({\n runtime,\n basePath,\n cors: corsConfig,\n}: CopilotSingleEndpointParams) {\n const app = new Hono<CopilotEndpointContext>();\n const routePath = normalizePath(basePath);\n\n return app\n .basePath(routePath)\n .use(\n \"*\",\n cors({\n origin: corsConfig?.origin ?? \"*\",\n allowMethods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowHeaders: [\"*\"],\n credentials: corsConfig?.credentials ?? false,\n }),\n )\n .use(\"*\", async (c, next) => {\n const request = c.req.raw;\n const path = c.req.path;\n\n try {\n const maybeModifiedRequest = await callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n });\n if (maybeModifiedRequest) {\n c.set(\"modifiedRequest\", maybeModifiedRequest);\n }\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path },\n \"Error running before request middleware\",\n );\n if (error instanceof Response) {\n return error;\n }\n throw error;\n }\n\n await next();\n })\n .use(\"*\", async (c, next) => {\n await next();\n\n const response = c.res;\n const path = c.req.path;\n\n callAfterRequestMiddleware({\n runtime,\n response,\n path,\n }).catch((error) => {\n logger.error(\n { err: error, url: c.req.url, path },\n \"Error running after request middleware\",\n );\n });\n })\n .post(\"/\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n let methodCall: MethodCall;\n try {\n methodCall = await parseMethodCall(request);\n } catch (error) {\n if (error instanceof Response) {\n logger.warn({ url: request.url }, \"Invalid single-route payload\");\n return error;\n }\n logger.warn(\n { err: error, url: request.url },\n \"Invalid single-route payload\",\n );\n return c.json(\n {\n error: \"invalid_request\",\n message:\n error instanceof Error\n ? error.message\n : \"Invalid request payload\",\n },\n 400,\n );\n }\n\n try {\n switch (methodCall.method) {\n case \"agent/run\": {\n const agentId = expectString(methodCall.params, \"agentId\");\n const handlerRequest = createJsonRequest(request, methodCall.body);\n return await handleRunAgent({\n runtime,\n request: handlerRequest,\n agentId,\n });\n }\n case \"agent/connect\": {\n const agentId = expectString(methodCall.params, \"agentId\");\n const handlerRequest = createJsonRequest(request, methodCall.body);\n return await handleConnectAgent({\n runtime,\n request: handlerRequest,\n agentId,\n });\n }\n case \"agent/stop\": {\n const agentId = expectString(methodCall.params, \"agentId\");\n const threadId = expectString(methodCall.params, \"threadId\");\n return await handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n });\n }\n case \"info\": {\n return await handleGetRuntimeInfo({ runtime, request });\n }\n case \"transcribe\": {\n const handlerRequest = createJsonRequest(request, methodCall.body);\n return await handleTranscribe({ runtime, request: handlerRequest });\n }\n default: {\n const exhaustiveCheck: never = methodCall.method;\n return exhaustiveCheck;\n }\n }\n } catch (error) {\n if (error instanceof Response) {\n return error;\n }\n logger.error(\n { err: error, url: request.url, method: methodCall.method },\n \"Error running single-route handler\",\n );\n throw error;\n }\n })\n .notFound((c) => {\n return c.json({ error: \"Not found\" }, 404);\n });\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":";;;;;;;;;;;;;AA0CA,SAAgB,iCAAiC,EAC/C,SACA,UACA,MAAM,cACwB;CAC9B,MAAM,MAAM,IAAIA,WAA8B;CAC9C,MAAM,YAAY,cAAc,SAAS;AAEzC,QAAO,IACJ,SAAS,UAAU,CACnB,IACC,yBACK;EACH,QAAQ,YAAY,UAAU;EAC9B,cAAc;GACZ;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,cAAc,CAAC,IAAI;EACnB,aAAa,YAAY,eAAe;EACzC,CAAC,CACH,CACA,IAAI,KAAK,OAAO,GAAG,SAAS;EAC3B,MAAM,UAAU,EAAE,IAAI;EACtB,MAAM,OAAO,E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mB;MAC9B;MACA,SAHqBD,+CAAkB,SAAS,WAAW,KAAK;MAIhE;MACD,CAAC;;IAEJ,KAAK,aAGH,QAAO,MAAME,oCAAgB;KAC3B;KACA;KACA,SALcJ,0CAAa,WAAW,QAAQ,UAAU;KAMxD,UALeA,0CAAa,WAAW,QAAQ,WAAW;KAM3D,CAAC;IAEJ,KAAK,OACH,QAAO,MAAMK,8CAAqB;KAAE;KAAS;KAAS,CAAC;IAEzD,KAAK,aAEH,QAAO,MAAMC,2CAAiB;KAAE;KAAS,SADlBJ,+CAAkB,SAAS,WAAW,KAAK;KACA,CAAC;IAErE,QAEE,QAD+B,WAAW;;WAIvC,OAAO;AACd,OAAI,iBAAiB,SACnB,QAAO;AAET,iCAAO,MACL;IAAE,KAAK;IAAO,KAAK,QAAQ;IAAK,QAAQ,WAAW;IAAQ,EAC3D,qCACD;AACD,SAAM;;GAER,CACD,UAAU,MAAM;AACf,SAAO,EAAE,KAAK,EAAE,OAAO,aAAa,EAAE,IAAI;GAC1C;;AAGN,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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CopilotRuntime } from "../runtime.cjs";
|
|
2
|
+
import { CopilotEndpointCorsConfig } from "./hono.cjs";
|
|
3
|
+
import * as hono_types0 from "hono/types";
|
|
4
|
+
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
|
+
|
|
6
|
+
//#region src/endpoints/hono-single.d.ts
|
|
7
|
+
interface CopilotSingleEndpointParams {
|
|
8
|
+
runtime: CopilotRuntime;
|
|
9
|
+
/**
|
|
10
|
+
* Absolute path at which to mount the single-route endpoint (e.g. "/api/copilotkit").
|
|
11
|
+
*/
|
|
12
|
+
basePath: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
15
|
+
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
16
|
+
*/
|
|
17
|
+
cors?: CopilotEndpointCorsConfig;
|
|
18
|
+
}
|
|
19
|
+
type CopilotEndpointContext = {
|
|
20
|
+
Variables: {
|
|
21
|
+
modifiedRequest?: Request;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
declare function createCopilotEndpointSingleRoute({
|
|
25
|
+
runtime,
|
|
26
|
+
basePath,
|
|
27
|
+
cors: corsConfig
|
|
28
|
+
}: CopilotSingleEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, hono_types0.BlankSchema, string, string>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createCopilotEndpointSingleRoute };
|
|
31
|
+
//# sourceMappingURL=hono-single.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono-single.d.cts","names":[],"sources":["../../src/endpoints/hono-single.ts"],"mappings":";;;;;;UAuBU,2BAAA;EACR,OAAA,EAAS,cAAA;;;AAHwC;EAOjD,QAAA;;;;;EAKA,IAAA,GAAO,yBAAA;AAAA;AAAA,KAGJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,gCAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,2BAAA,GAA2B,eAAA,CAAA,QAAA,CAAA,sBAAA,EAAA,WAAA,CAAA,WAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CopilotRuntime } from "../runtime.mjs";
|
|
2
|
+
import { CopilotEndpointCorsConfig } from "./hono.mjs";
|
|
3
|
+
import * as hono_types0 from "hono/types";
|
|
4
|
+
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
|
+
|
|
6
|
+
//#region src/endpoints/hono-single.d.ts
|
|
7
|
+
interface CopilotSingleEndpointParams {
|
|
8
|
+
runtime: CopilotRuntime;
|
|
9
|
+
/**
|
|
10
|
+
* Absolute path at which to mount the single-route endpoint (e.g. "/api/copilotkit").
|
|
11
|
+
*/
|
|
12
|
+
basePath: string;
|
|
13
|
+
/**
|
|
14
|
+
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
15
|
+
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
16
|
+
*/
|
|
17
|
+
cors?: CopilotEndpointCorsConfig;
|
|
18
|
+
}
|
|
19
|
+
type CopilotEndpointContext = {
|
|
20
|
+
Variables: {
|
|
21
|
+
modifiedRequest?: Request;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
declare function createCopilotEndpointSingleRoute({
|
|
25
|
+
runtime,
|
|
26
|
+
basePath,
|
|
27
|
+
cors: corsConfig
|
|
28
|
+
}: CopilotSingleEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, hono_types0.BlankSchema, string, string>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createCopilotEndpointSingleRoute };
|
|
31
|
+
//# sourceMappingURL=hono-single.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono-single.d.mts","names":[],"sources":["../../src/endpoints/hono-single.ts"],"mappings":";;;;;;UAuBU,2BAAA;EACR,OAAA,EAAS,cAAA;;;AAHwC;EAOjD,QAAA;;;;;EAKA,IAAA,GAAO,yBAAA;AAAA;AAAA,KAGJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,gCAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,2BAAA,GAA2B,eAAA,CAAA,QAAA,CAAA,sBAAA,EAAA,WAAA,CAAA,WAAA"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { handleRunAgent } from "../handlers/handle-run.mjs";
|
|
2
|
+
import { handleGetRuntimeInfo } from "../handlers/get-runtime-info.mjs";
|
|
3
|
+
import { handleTranscribe } from "../handlers/handle-transcribe.mjs";
|
|
4
|
+
import { callAfterRequestMiddleware, callBeforeRequestMiddleware } from "../middleware.mjs";
|
|
5
|
+
import { handleConnectAgent } from "../handlers/handle-connect.mjs";
|
|
6
|
+
import { handleStopAgent } from "../handlers/handle-stop.mjs";
|
|
7
|
+
import { createJsonRequest, expectString, parseMethodCall } from "./single-route-helpers.mjs";
|
|
8
|
+
import { logger } from "@copilotkitnext/shared";
|
|
9
|
+
import { Hono } from "hono";
|
|
10
|
+
import { cors } from "hono/cors";
|
|
11
|
+
|
|
12
|
+
//#region src/endpoints/hono-single.ts
|
|
13
|
+
function createCopilotEndpointSingleRoute({ runtime, basePath, cors: corsConfig }) {
|
|
14
|
+
const app = new Hono();
|
|
15
|
+
const routePath = normalizePath(basePath);
|
|
16
|
+
return app.basePath(routePath).use("*", cors({
|
|
17
|
+
origin: corsConfig?.origin ?? "*",
|
|
18
|
+
allowMethods: [
|
|
19
|
+
"GET",
|
|
20
|
+
"HEAD",
|
|
21
|
+
"PUT",
|
|
22
|
+
"POST",
|
|
23
|
+
"DELETE",
|
|
24
|
+
"PATCH",
|
|
25
|
+
"OPTIONS"
|
|
26
|
+
],
|
|
27
|
+
allowHeaders: ["*"],
|
|
28
|
+
credentials: corsConfig?.credentials ?? false
|
|
29
|
+
})).use("*", async (c, next) => {
|
|
30
|
+
const request = c.req.raw;
|
|
31
|
+
const path = c.req.path;
|
|
32
|
+
try {
|
|
33
|
+
const maybeModifiedRequest = await callBeforeRequestMiddleware({
|
|
34
|
+
runtime,
|
|
35
|
+
request,
|
|
36
|
+
path
|
|
37
|
+
});
|
|
38
|
+
if (maybeModifiedRequest) c.set("modifiedRequest", maybeModifiedRequest);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
logger.error({
|
|
41
|
+
err: error,
|
|
42
|
+
url: request.url,
|
|
43
|
+
path
|
|
44
|
+
}, "Error running before request middleware");
|
|
45
|
+
if (error instanceof Response) return error;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
await next();
|
|
49
|
+
}).use("*", async (c, next) => {
|
|
50
|
+
await next();
|
|
51
|
+
const response = c.res;
|
|
52
|
+
const path = c.req.path;
|
|
53
|
+
callAfterRequestMiddleware({
|
|
54
|
+
runtime,
|
|
55
|
+
response,
|
|
56
|
+
path
|
|
57
|
+
}).catch((error) => {
|
|
58
|
+
logger.error({
|
|
59
|
+
err: error,
|
|
60
|
+
url: c.req.url,
|
|
61
|
+
path
|
|
62
|
+
}, "Error running after request middleware");
|
|
63
|
+
});
|
|
64
|
+
}).post("/", async (c) => {
|
|
65
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
66
|
+
let methodCall;
|
|
67
|
+
try {
|
|
68
|
+
methodCall = await parseMethodCall(request);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error instanceof Response) {
|
|
71
|
+
logger.warn({ url: request.url }, "Invalid single-route payload");
|
|
72
|
+
return error;
|
|
73
|
+
}
|
|
74
|
+
logger.warn({
|
|
75
|
+
err: error,
|
|
76
|
+
url: request.url
|
|
77
|
+
}, "Invalid single-route payload");
|
|
78
|
+
return c.json({
|
|
79
|
+
error: "invalid_request",
|
|
80
|
+
message: error instanceof Error ? error.message : "Invalid request payload"
|
|
81
|
+
}, 400);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
switch (methodCall.method) {
|
|
85
|
+
case "agent/run": {
|
|
86
|
+
const agentId = expectString(methodCall.params, "agentId");
|
|
87
|
+
return await handleRunAgent({
|
|
88
|
+
runtime,
|
|
89
|
+
request: createJsonRequest(request, methodCall.body),
|
|
90
|
+
agentId
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
case "agent/connect": {
|
|
94
|
+
const agentId = expectString(methodCall.params, "agentId");
|
|
95
|
+
return await handleConnectAgent({
|
|
96
|
+
runtime,
|
|
97
|
+
request: createJsonRequest(request, methodCall.body),
|
|
98
|
+
agentId
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
case "agent/stop": return await handleStopAgent({
|
|
102
|
+
runtime,
|
|
103
|
+
request,
|
|
104
|
+
agentId: expectString(methodCall.params, "agentId"),
|
|
105
|
+
threadId: expectString(methodCall.params, "threadId")
|
|
106
|
+
});
|
|
107
|
+
case "info": return await handleGetRuntimeInfo({
|
|
108
|
+
runtime,
|
|
109
|
+
request
|
|
110
|
+
});
|
|
111
|
+
case "transcribe": return await handleTranscribe({
|
|
112
|
+
runtime,
|
|
113
|
+
request: createJsonRequest(request, methodCall.body)
|
|
114
|
+
});
|
|
115
|
+
default: return methodCall.method;
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error instanceof Response) return error;
|
|
119
|
+
logger.error({
|
|
120
|
+
err: error,
|
|
121
|
+
url: request.url,
|
|
122
|
+
method: methodCall.method
|
|
123
|
+
}, "Error running single-route handler");
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}).notFound((c) => {
|
|
127
|
+
return c.json({ error: "Not found" }, 404);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function normalizePath(path) {
|
|
131
|
+
if (!path) throw new Error("basePath must be provided for single-route endpoint");
|
|
132
|
+
if (!path.startsWith("/")) return `/${path}`;
|
|
133
|
+
if (path.length > 1 && path.endsWith("/")) return path.slice(0, -1);
|
|
134
|
+
return path;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
export { createCopilotEndpointSingleRoute };
|
|
139
|
+
//# sourceMappingURL=hono-single.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono-single.mjs","names":[],"sources":["../../src/endpoints/hono-single.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport { cors } from \"hono/cors\";\n\nimport { CopilotRuntime } from \"../runtime\";\nimport { handleRunAgent } from \"../handlers/handle-run\";\nimport { handleConnectAgent } from \"../handlers/handle-connect\";\nimport { handleStopAgent } from \"../handlers/handle-stop\";\nimport { handleGetRuntimeInfo } from \"../handlers/get-runtime-info\";\nimport { handleTranscribe } from \"../handlers/handle-transcribe\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport {\n callBeforeRequestMiddleware,\n callAfterRequestMiddleware,\n} from \"../middleware\";\nimport {\n createJsonRequest,\n expectString,\n MethodCall,\n parseMethodCall,\n} from \"./single-route-helpers\";\n\nimport { CopilotEndpointCorsConfig } from \"./hono\";\n\ninterface CopilotSingleEndpointParams {\n runtime: CopilotRuntime;\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\ntype CopilotEndpointContext = {\n Variables: {\n modifiedRequest?: Request;\n };\n};\n\nexport function createCopilotEndpointSingleRoute({\n runtime,\n basePath,\n cors: corsConfig,\n}: CopilotSingleEndpointParams) {\n const app = new Hono<CopilotEndpointContext>();\n const routePath = normalizePath(basePath);\n\n return app\n .basePath(routePath)\n .use(\n \"*\",\n cors({\n origin: corsConfig?.origin ?? \"*\",\n allowMethods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowHeaders: [\"*\"],\n credentials: corsConfig?.credentials ?? false,\n }),\n )\n .use(\"*\", async (c, next) => {\n const request = c.req.raw;\n const path = c.req.path;\n\n try {\n const maybeModifiedRequest = await callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n });\n if (maybeModifiedRequest) {\n c.set(\"modifiedRequest\", maybeModifiedRequest);\n }\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path },\n \"Error running before request middleware\",\n );\n if (error instanceof Response) {\n return error;\n }\n throw error;\n }\n\n await next();\n })\n .use(\"*\", async (c, next) => {\n await next();\n\n const response = c.res;\n const path = c.req.path;\n\n callAfterRequestMiddleware({\n runtime,\n response,\n path,\n }).catch((error) => {\n logger.error(\n { err: error, url: c.req.url, path },\n \"Error running after request middleware\",\n );\n });\n })\n .post(\"/\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n let methodCall: MethodCall;\n try {\n methodCall = await parseMethodCall(request);\n } catch (error) {\n if (error instanceof Response) {\n logger.warn({ url: request.url }, \"Invalid single-route payload\");\n return error;\n }\n logger.warn(\n { err: error, url: request.url },\n \"Invalid single-route payload\",\n );\n return c.json(\n {\n error: \"invalid_request\",\n message:\n error instanceof Error\n ? error.message\n : \"Invalid request payload\",\n },\n 400,\n );\n }\n\n try {\n switch (methodCall.method) {\n case \"agent/run\": {\n const agentId = expectString(methodCall.params, \"agentId\");\n const handlerRequest = createJsonRequest(request, methodCall.body);\n return await handleRunAgent({\n runtime,\n request: handlerRequest,\n agentId,\n });\n }\n case \"agent/connect\": {\n const agentId = expectString(methodCall.params, \"agentId\");\n const handlerRequest = createJsonRequest(request, methodCall.body);\n return await handleConnectAgent({\n runtime,\n request: handlerRequest,\n agentId,\n });\n }\n case \"agent/stop\": {\n const agentId = expectString(methodCall.params, \"agentId\");\n const threadId = expectString(methodCall.params, \"threadId\");\n return await handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n });\n }\n case \"info\": {\n return await handleGetRuntimeInfo({ runtime, request });\n }\n case \"transcribe\": {\n const handlerRequest = createJsonRequest(request, methodCall.body);\n return await handleTranscribe({ runtime, request: handlerRequest });\n }\n default: {\n const exhaustiveCheck: never = methodCall.method;\n return exhaustiveCheck;\n }\n }\n } catch (error) {\n if (error instanceof Response) {\n return error;\n }\n logger.error(\n { err: error, url: request.url, method: methodCall.method },\n \"Error running single-route handler\",\n );\n throw error;\n }\n })\n .notFound((c) => {\n return c.json({ error: \"Not found\" }, 404);\n });\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":";;;;;;;;;;;;AA0CA,SAAgB,iCAAiC,EAC/C,SACA,UACA,MAAM,cACwB;CAC9B,MAAM,MAAM,IAAI,MAA8B;CAC9C,MAAM,YAAY,cAAc,SAAS;AAEzC,QAAO,IACJ,SAAS,UAAU,CACnB,IACC,KACA,KAAK;EACH,QAAQ,YAAY,UAAU;EAC9B,cAAc;GACZ;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,cAAc,CAAC,IAAI;EACnB,aAAa,YAAY,eAAe;EACzC,CAAC,CACH,CACA,IAAI,KAAK,OAAO,GAAG,SAAS;EAC3B,MAAM,UAAU,EAAE,IAAI;EACtB,MAAM,OAAO,EAAE,IAAI;AAEnB,MAAI;GACF,MAAM,uBAAuB,MAAM,4BAA4B;IAC7D;IACA;IACA;IACD,CAAC;AACF,OAAI,qBACF,GAAE,IAAI,mBAAmB,qBAAqB;WAEzC,OAAO;AACd,UAAO,MACL;IAAE,KAAK;IAAO,KAAK,QAAQ;IAAK;IAAM,EACtC,0CACD;AACD,OAAI,iBAAiB,SACnB,QAAO;AAET,SAAM;;AAGR,QAAM,MAAM;GACZ,CACD,IAAI,KAAK,OAAO,GAAG,SAAS;AAC3B,QAAM,MAAM;EAEZ,MAAM,WAAW,EAAE;EACnB,MAAM,OAAO,EAAE,IAAI;AAEnB,6BAA2B;GACzB;GACA;GACA;GACD,CAAC,CAAC,OAAO,UAAU;AAClB,UAAO,MACL;IAAE,KAAK;IAAO,KAAK,EAAE,IAAI;IAAK;IAAM,EACpC,yCACD;IACD;GACF,CACD,KAAK,KAAK,OAAO,MAAM;EACtB,MAAM,UAAU,EAAE,IAAI,kBAAkB,IAAI,EAAE,IAAI;EAElD,IAAI;AACJ,MAAI;AACF,gBAAa,MAAM,gBAAgB,QAAQ;WACpC,OA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AC,KAAK,WAAW,IAAI,CACvB,QAAO,IAAI;AAGb,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,IAAI,CACvC,QAAO,KAAK,MAAM,GAAG,GAAG;AAG1B,QAAO"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_handle_run = require('../handlers/handle-run.cjs');
|
|
3
|
+
const require_get_runtime_info = require('../handlers/get-runtime-info.cjs');
|
|
4
|
+
const require_handle_transcribe = require('../handlers/handle-transcribe.cjs');
|
|
5
|
+
const require_middleware = require('../middleware.cjs');
|
|
6
|
+
const require_handle_connect = require('../handlers/handle-connect.cjs');
|
|
7
|
+
const require_handle_stop = require('../handlers/handle-stop.cjs');
|
|
8
|
+
let _copilotkitnext_shared = require("@copilotkitnext/shared");
|
|
9
|
+
let hono = require("hono");
|
|
10
|
+
let hono_cors = require("hono/cors");
|
|
11
|
+
|
|
12
|
+
//#region src/endpoints/hono.ts
|
|
13
|
+
function createCopilotEndpoint({ runtime, basePath, cors: corsConfig }) {
|
|
14
|
+
return new hono.Hono().basePath(basePath).use("*", (0, hono_cors.cors)({
|
|
15
|
+
origin: corsConfig?.origin ?? "*",
|
|
16
|
+
allowMethods: [
|
|
17
|
+
"GET",
|
|
18
|
+
"HEAD",
|
|
19
|
+
"PUT",
|
|
20
|
+
"POST",
|
|
21
|
+
"DELETE",
|
|
22
|
+
"PATCH",
|
|
23
|
+
"OPTIONS"
|
|
24
|
+
],
|
|
25
|
+
allowHeaders: ["*"],
|
|
26
|
+
credentials: corsConfig?.credentials ?? false
|
|
27
|
+
})).use("*", async (c, next) => {
|
|
28
|
+
const request = c.req.raw;
|
|
29
|
+
const path = c.req.path;
|
|
30
|
+
try {
|
|
31
|
+
const maybeModifiedRequest = await require_middleware.callBeforeRequestMiddleware({
|
|
32
|
+
runtime,
|
|
33
|
+
request,
|
|
34
|
+
path
|
|
35
|
+
});
|
|
36
|
+
if (maybeModifiedRequest) c.set("modifiedRequest", maybeModifiedRequest);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
_copilotkitnext_shared.logger.error({
|
|
39
|
+
err: error,
|
|
40
|
+
url: request.url,
|
|
41
|
+
path
|
|
42
|
+
}, "Error running before request middleware");
|
|
43
|
+
if (error instanceof Response) return error;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
await next();
|
|
47
|
+
}).use("*", async (c, next) => {
|
|
48
|
+
await next();
|
|
49
|
+
const response = c.res;
|
|
50
|
+
const path = c.req.path;
|
|
51
|
+
require_middleware.callAfterRequestMiddleware({
|
|
52
|
+
runtime,
|
|
53
|
+
response,
|
|
54
|
+
path
|
|
55
|
+
}).catch((error) => {
|
|
56
|
+
_copilotkitnext_shared.logger.error({
|
|
57
|
+
err: error,
|
|
58
|
+
url: c.req.url,
|
|
59
|
+
path
|
|
60
|
+
}, "Error running after request middleware");
|
|
61
|
+
});
|
|
62
|
+
}).post("/agent/:agentId/run", async (c) => {
|
|
63
|
+
const agentId = c.req.param("agentId");
|
|
64
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
65
|
+
try {
|
|
66
|
+
return await require_handle_run.handleRunAgent({
|
|
67
|
+
runtime,
|
|
68
|
+
request,
|
|
69
|
+
agentId
|
|
70
|
+
});
|
|
71
|
+
} catch (error) {
|
|
72
|
+
_copilotkitnext_shared.logger.error({
|
|
73
|
+
err: error,
|
|
74
|
+
url: request.url,
|
|
75
|
+
path: c.req.path
|
|
76
|
+
}, "Error running request handler");
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}).post("/agent/:agentId/connect", async (c) => {
|
|
80
|
+
const agentId = c.req.param("agentId");
|
|
81
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
82
|
+
try {
|
|
83
|
+
return await require_handle_connect.handleConnectAgent({
|
|
84
|
+
runtime,
|
|
85
|
+
request,
|
|
86
|
+
agentId
|
|
87
|
+
});
|
|
88
|
+
} catch (error) {
|
|
89
|
+
_copilotkitnext_shared.logger.error({
|
|
90
|
+
err: error,
|
|
91
|
+
url: request.url,
|
|
92
|
+
path: c.req.path
|
|
93
|
+
}, "Error running request handler");
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}).post("/agent/:agentId/stop/:threadId", async (c) => {
|
|
97
|
+
const agentId = c.req.param("agentId");
|
|
98
|
+
const threadId = c.req.param("threadId");
|
|
99
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
100
|
+
try {
|
|
101
|
+
return await require_handle_stop.handleStopAgent({
|
|
102
|
+
runtime,
|
|
103
|
+
request,
|
|
104
|
+
agentId,
|
|
105
|
+
threadId
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
_copilotkitnext_shared.logger.error({
|
|
109
|
+
err: error,
|
|
110
|
+
url: request.url,
|
|
111
|
+
path: c.req.path
|
|
112
|
+
}, "Error running request handler");
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}).get("/info", async (c) => {
|
|
116
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
117
|
+
try {
|
|
118
|
+
return await require_get_runtime_info.handleGetRuntimeInfo({
|
|
119
|
+
runtime,
|
|
120
|
+
request
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
_copilotkitnext_shared.logger.error({
|
|
124
|
+
err: error,
|
|
125
|
+
url: request.url,
|
|
126
|
+
path: c.req.path
|
|
127
|
+
}, "Error running request handler");
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}).post("/transcribe", async (c) => {
|
|
131
|
+
const request = c.get("modifiedRequest") || c.req.raw;
|
|
132
|
+
try {
|
|
133
|
+
return await require_handle_transcribe.handleTranscribe({
|
|
134
|
+
runtime,
|
|
135
|
+
request
|
|
136
|
+
});
|
|
137
|
+
} catch (error) {
|
|
138
|
+
_copilotkitnext_shared.logger.error({
|
|
139
|
+
err: error,
|
|
140
|
+
url: request.url,
|
|
141
|
+
path: c.req.path
|
|
142
|
+
}, "Error running request handler");
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}).notFound((c) => {
|
|
146
|
+
return c.json({ error: "Not found" }, 404);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.createCopilotEndpoint = createCopilotEndpoint;
|
|
152
|
+
//# sourceMappingURL=hono.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.cjs","names":["Hono","callBeforeRequestMiddleware","handleRunAgent","handleConnectAgent","handleStopAgent","handleGetRuntimeInfo","handleTranscribe"],"sources":["../../src/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport { cors } from \"hono/cors\";\nimport { CopilotRuntime } from \"../runtime\";\nimport { handleRunAgent } from \"../handlers/handle-run\";\nimport { handleGetRuntimeInfo } from \"../handlers/get-runtime-info\";\nimport { handleTranscribe } from \"../handlers/handle-transcribe\";\nimport { logger } from \"@copilotkitnext/shared\";\nimport {\n callBeforeRequestMiddleware,\n callAfterRequestMiddleware,\n} from \"../middleware\";\nimport { handleConnectAgent } from \"../handlers/handle-connect\";\nimport { handleStopAgent } from \"../handlers/handle-stop\";\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: CopilotRuntime;\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\n// Define the context variables type\ntype CopilotEndpointContext = {\n Variables: {\n modifiedRequest?: Request;\n };\n};\n\nexport function createCopilotEndpoint({\n runtime,\n basePath,\n cors: corsConfig,\n}: CopilotEndpointParams) {\n const app = new Hono<CopilotEndpointContext>();\n\n return app\n .basePath(basePath)\n .use(\n \"*\",\n cors({\n origin: corsConfig?.origin ?? \"*\",\n allowMethods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowHeaders: [\"*\"],\n credentials: corsConfig?.credentials ?? false,\n }),\n )\n .use(\"*\", async (c, next) => {\n const request = c.req.raw;\n const path = c.req.path;\n\n try {\n const maybeModifiedRequest = await callBeforeRequestMiddleware({\n runtime,\n request,\n path,\n });\n if (maybeModifiedRequest) {\n c.set(\"modifiedRequest\", maybeModifiedRequest);\n }\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path },\n \"Error running before request middleware\",\n );\n if (error instanceof Response) {\n return error;\n }\n throw error;\n }\n\n await next();\n })\n .use(\"*\", async (c, next) => {\n await next();\n\n const response = c.res;\n const path = c.req.path;\n\n // Non-blocking after middleware\n callAfterRequestMiddleware({\n runtime,\n response,\n path,\n }).catch((error) => {\n logger.error(\n { err: error, url: c.req.url, path },\n \"Error running after request middleware\",\n );\n });\n })\n .post(\"/agent/:agentId/run\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleRunAgent({\n runtime,\n request,\n agentId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/agent/:agentId/connect\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleConnectAgent({\n runtime,\n request,\n agentId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n\n .post(\"/agent/:agentId/stop/:threadId\", async (c) => {\n const agentId = c.req.param(\"agentId\");\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleStopAgent({\n runtime,\n request,\n agentId,\n threadId,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .get(\"/info\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleGetRuntimeInfo({\n runtime,\n request,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .post(\"/transcribe\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleTranscribe({\n runtime,\n request,\n });\n } catch (error) {\n logger.error(\n { err: error, url: request.url, path: c.req.path },\n \"Error running request handler\",\n );\n throw error;\n }\n })\n .notFound((c) => {\n return c.json({ error: \"Not found\" }, 404);\n });\n\n // return app;\n}\n"],"mappings":";;;;;;;;;;;;AAuDA,SAAgB,sBAAsB,EACpC,SACA,UACA,MAAM,cACkB;AAGxB,QAFY,IAAIA,WAA8B,CAG3C,SAAS,SAAS,CAClB,IACC,yBACK;EACH,QAAQ,YAAY,UAAU;EAC9B,cAAc;GACZ;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,cAAc,CAAC,IAAI;EACnB,aAAa,YAAY,eAAe;EACzC,CAAC,CACH,CACA,IAAI,KAAK,OAAO,GAAG,SAAS;EAC3B,MAAM,UAAU,EAAE,IAAI;EACtB,MAAM,OAAO,EAAE,IAAI;AAEnB,MAAI;GACF,MAAM,uBAAuB,MAAMC,+CAA4B;IAC7D;IACA;IACA;IACD,CAAC;AACF,OAAI,qBACF,GAAE,IAAI,mBA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AI;AACF,UAAO,MAAMC,oCAAgB;IAC3B;IACA;IACA;IACA;IACD,CAAC;WACK,OAAO;AACd,iCAAO,MACL;IAAE,KAAK;IAAO,KAAK,QAAQ;IAAK,MAAM,EAAE,IAAI;IAAM,EAClD,gCACD;AACD,SAAM;;GAER,CACD,IAAI,SAAS,OAAO,MAAM;EACzB,MAAM,UAAU,EAAE,IAAI,kBAAkB,IAAI,EAAE,IAAI;AAElD,MAAI;AACF,UAAO,MAAMC,8CAAqB;IAChC;IACA;IACD,CAAC;WACK,OAAO;AACd,iCAAO,MACL;IAAE,KAAK;IAAO,KAAK,QAAQ;IAAK,MAAM,EAAE,IAAI;IAAM,EAClD,gCACD;AACD,SAAM;;GAER,CACD,KAAK,eAAe,OAAO,MAAM;EAChC,MAAM,UAAU,EAAE,IAAI,kBAAkB,IAAI,EAAE,IAAI;AAElD,MAAI;AACF,UAAO,MAAMC,2CAAiB;IAC5B;IACA;IACD,CAAC;WACK,OAAO;AACd,iCAAO,MACL;IAAE,KAAK;IAAO,KAAK,QAAQ;IAAK,MAAM,EAAE,IAAI;IAAM,EAClD,gCACD;AACD,SAAM;;GAER,CACD,UAAU,MAAM;AACf,SAAO,EAAE,KAAK,EAAE,OAAO,aAAa,EAAE,IAAI;GAC1C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CopilotRuntime } from "../runtime.cjs";
|
|
2
|
+
import * as hono_types0 from "hono/types";
|
|
3
|
+
import * as hono_hono_base0 from "hono/hono-base";
|
|
4
|
+
|
|
5
|
+
//#region src/endpoints/hono.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* CORS configuration for CopilotKit endpoints.
|
|
8
|
+
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
|
|
9
|
+
*/
|
|
10
|
+
interface CopilotEndpointCorsConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Allowed origin(s) for CORS. Can be:
|
|
13
|
+
* - A string: exact origin (e.g., "https://myapp.com")
|
|
14
|
+
* - An array: list of allowed origins
|
|
15
|
+
* - A function: dynamic origin resolution
|
|
16
|
+
*
|
|
17
|
+
* Note: When credentials is true, origin cannot be "*"
|
|
18
|
+
*/
|
|
19
|
+
origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
|
|
20
|
+
/**
|
|
21
|
+
* Whether to allow credentials (cookies, HTTP authentication).
|
|
22
|
+
* When true, origin must be explicitly specified (not "*").
|
|
23
|
+
*/
|
|
24
|
+
credentials?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface CopilotEndpointParams {
|
|
27
|
+
runtime: CopilotRuntime;
|
|
28
|
+
basePath: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
31
|
+
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
32
|
+
*/
|
|
33
|
+
cors?: CopilotEndpointCorsConfig;
|
|
34
|
+
}
|
|
35
|
+
type CopilotEndpointContext = {
|
|
36
|
+
Variables: {
|
|
37
|
+
modifiedRequest?: Request;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
declare function createCopilotEndpoint({
|
|
41
|
+
runtime,
|
|
42
|
+
basePath,
|
|
43
|
+
cors: corsConfig
|
|
44
|
+
}: CopilotEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, hono_types0.BlankSchema, string, `${string}/transcribe`>;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { CopilotEndpointCorsConfig, createCopilotEndpoint };
|
|
47
|
+
//# sourceMappingURL=hono.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.d.cts","names":[],"sources":["../../src/endpoints/hono.ts"],"mappings":";;;;;;;;;UAkBiB,yBAAA;EAAyB;;;;;;;;EASxC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAQd;;;;EAHR,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,cAAA;EACT,QAAA;EAKgC;;AAAA;;EAAhC,IAAA,GAAO,yBAAA;AAAA;AAAA,KAIJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,qBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,qBAAA,GAAqB,eAAA,CAAA,QAAA,CAAA,sBAAA,EAAA,WAAA,CAAA,WAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CopilotRuntime } from "../runtime.mjs";
|
|
2
|
+
import * as hono_types0 from "hono/types";
|
|
3
|
+
import * as hono_hono_base0 from "hono/hono-base";
|
|
4
|
+
|
|
5
|
+
//#region src/endpoints/hono.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* CORS configuration for CopilotKit endpoints.
|
|
8
|
+
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
|
|
9
|
+
*/
|
|
10
|
+
interface CopilotEndpointCorsConfig {
|
|
11
|
+
/**
|
|
12
|
+
* Allowed origin(s) for CORS. Can be:
|
|
13
|
+
* - A string: exact origin (e.g., "https://myapp.com")
|
|
14
|
+
* - An array: list of allowed origins
|
|
15
|
+
* - A function: dynamic origin resolution
|
|
16
|
+
*
|
|
17
|
+
* Note: When credentials is true, origin cannot be "*"
|
|
18
|
+
*/
|
|
19
|
+
origin: string | string[] | ((origin: string, c: any) => string | undefined | null);
|
|
20
|
+
/**
|
|
21
|
+
* Whether to allow credentials (cookies, HTTP authentication).
|
|
22
|
+
* When true, origin must be explicitly specified (not "*").
|
|
23
|
+
*/
|
|
24
|
+
credentials?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface CopilotEndpointParams {
|
|
27
|
+
runtime: CopilotRuntime;
|
|
28
|
+
basePath: string;
|
|
29
|
+
/**
|
|
30
|
+
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
31
|
+
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
32
|
+
*/
|
|
33
|
+
cors?: CopilotEndpointCorsConfig;
|
|
34
|
+
}
|
|
35
|
+
type CopilotEndpointContext = {
|
|
36
|
+
Variables: {
|
|
37
|
+
modifiedRequest?: Request;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
declare function createCopilotEndpoint({
|
|
41
|
+
runtime,
|
|
42
|
+
basePath,
|
|
43
|
+
cors: corsConfig
|
|
44
|
+
}: CopilotEndpointParams): hono_hono_base0.HonoBase<CopilotEndpointContext, hono_types0.BlankSchema, string, `${string}/transcribe`>;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { CopilotEndpointCorsConfig, createCopilotEndpoint };
|
|
47
|
+
//# sourceMappingURL=hono.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hono.d.mts","names":[],"sources":["../../src/endpoints/hono.ts"],"mappings":";;;;;;;;;UAkBiB,yBAAA;EAAyB;;;;;;;;EASxC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAQd;;;;EAHR,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,cAAA;EACT,QAAA;EAKgC;;AAAA;;EAAhC,IAAA,GAAO,yBAAA;AAAA;AAAA,KAIJ,sBAAA;EACH,SAAA;IACE,eAAA,GAAkB,OAAA;EAAA;AAAA;AAAA,iBAIN,qBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA,EAAM;AAAA,GACL,qBAAA,GAAqB,eAAA,CAAA,QAAA,CAAA,sBAAA,EAAA,WAAA,CAAA,WAAA"}
|