@copilotkit/runtime 1.62.2 → 1.63.0
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.mjs +15 -1
- package/dist/agent/converters/aisdk.d.cts +1 -1
- package/dist/agent/converters/tanstack.d.cts +1 -1
- package/dist/agent/index.d.cts +1 -1
- package/dist/channels/dist/index.d.cts +10 -0
- package/dist/channels/dist/index.d.cts.map +1 -0
- package/dist/channels/dist/index.d.mts +10 -0
- package/dist/channels/dist/index.d.mts.map +1 -0
- package/dist/graphql/inputs/action.input.d.cts +1 -1
- package/dist/graphql/inputs/agent-session.input.d.cts +1 -1
- package/dist/graphql/inputs/agent-state.input.d.cts +1 -1
- package/dist/graphql/inputs/extensions.input.d.cts +1 -1
- package/dist/graphql/inputs/forwarded-parameters.input.d.cts +1 -1
- package/dist/graphql/inputs/message.input.d.cts +1 -1
- package/dist/graphql/types/base/index.d.cts +1 -1
- package/dist/graphql/types/converted/index.d.cts +1 -1
- package/dist/graphql/types/copilot-response.type.d.cts +1 -1
- package/dist/graphql/types/enums.d.cts +1 -1
- package/dist/graphql/types/extensions-response.type.d.cts +1 -1
- package/dist/graphql/types/message-status.type.d.cts +1 -1
- package/dist/graphql/types/response-status.type.d.cts +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/langgraph.d.cts +1 -1
- package/dist/lib/cloud/index.d.cts +1 -1
- package/dist/lib/index.d.cts +1 -1
- package/dist/lib/integrations/index.d.cts +1 -1
- package/dist/lib/integrations/nest/index.d.cts +1 -1
- package/dist/lib/integrations/nextjs/app-router.d.cts +1 -1
- package/dist/lib/integrations/nextjs/pages-router.d.cts +1 -1
- package/dist/lib/integrations/node-express/index.d.cts +1 -1
- package/dist/lib/integrations/node-http/index.d.cts +1 -1
- package/dist/lib/integrations/shared.d.cts +1 -1
- package/dist/lib/logger.d.cts +1 -1
- package/dist/lib/observability.d.cts +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/consts.d.cts +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/index.d.cts +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +1 -1
- package/dist/lib/runtime/mcp-tools-utils.d.cts +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.cts +1 -1
- package/dist/lib/runtime/types.d.cts +1 -1
- package/dist/lib/telemetry-client.mjs +1 -1
- package/dist/package.cjs +5 -1
- package/dist/{package.mjs → runtime/package.mjs} +6 -2
- package/dist/runtime/package.mjs.map +1 -0
- package/dist/service-adapters/anthropic/anthropic-adapter.d.cts +1 -1
- package/dist/service-adapters/bedrock/bedrock-adapter.d.cts +1 -1
- package/dist/service-adapters/empty/empty-adapter.d.cts +1 -1
- package/dist/service-adapters/events.d.cts +1 -1
- package/dist/service-adapters/experimental/ollama/ollama-adapter.d.cts +1 -1
- package/dist/service-adapters/google/google-genai-adapter.d.cts +1 -1
- package/dist/service-adapters/groq/groq-adapter.d.cts +1 -1
- package/dist/service-adapters/index.d.cts +1 -1
- package/dist/service-adapters/langchain/langchain-adapter.d.cts +1 -1
- package/dist/service-adapters/langchain/langserve.d.cts +1 -1
- package/dist/service-adapters/langchain/types.d.cts +1 -1
- package/dist/service-adapters/openai/openai-adapter.d.cts +1 -1
- package/dist/service-adapters/openai/openai-assistant-adapter.d.cts +1 -1
- package/dist/service-adapters/service-adapter.d.cts +1 -1
- package/dist/service-adapters/shared/error-utils.d.cts +1 -1
- package/dist/service-adapters/shared/sdk-client-utils.d.cts +1 -1
- package/dist/service-adapters/unify/unify-adapter.d.cts +1 -1
- package/dist/utils/failed-response-status-reasons.d.cts +1 -1
- package/dist/v2/express.d.cts +3 -3
- package/dist/v2/express.d.mts +2 -2
- package/dist/v2/hono.d.cts +3 -3
- package/dist/v2/hono.d.mts +2 -2
- package/dist/v2/index.d.cts +7 -6
- package/dist/v2/index.d.mts +6 -5
- package/dist/v2/node.d.cts +1 -1
- package/dist/v2/runtime/core/channel-activation-config.cjs +93 -0
- package/dist/v2/runtime/core/channel-activation-config.cjs.map +1 -0
- package/dist/v2/runtime/core/channel-activation-config.d.cts +34 -0
- package/dist/v2/runtime/core/channel-activation-config.d.cts.map +1 -0
- package/dist/v2/runtime/core/channel-activation-config.d.mts +34 -0
- package/dist/v2/runtime/core/channel-activation-config.d.mts.map +1 -0
- package/dist/v2/runtime/core/channel-activation-config.mjs +91 -0
- package/dist/v2/runtime/core/channel-activation-config.mjs.map +1 -0
- package/dist/v2/runtime/core/channel-manager.cjs +444 -0
- package/dist/v2/runtime/core/channel-manager.cjs.map +1 -0
- package/dist/v2/runtime/core/channel-manager.d.cts +90 -0
- package/dist/v2/runtime/core/channel-manager.d.cts.map +1 -0
- package/dist/v2/runtime/core/channel-manager.d.mts +90 -0
- package/dist/v2/runtime/core/channel-manager.d.mts.map +1 -0
- package/dist/v2/runtime/core/channel-manager.mjs +443 -0
- package/dist/v2/runtime/core/channel-manager.mjs.map +1 -0
- package/dist/v2/runtime/core/debug-event-bus.d.cts +1 -1
- package/dist/v2/runtime/core/fetch-cors.d.cts +1 -1
- package/dist/v2/runtime/core/fetch-handler.cjs +98 -2
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.cts +60 -4
- package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.d.mts +59 -3
- package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -1
- package/dist/v2/runtime/core/fetch-handler.mjs +98 -2
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.cjs +18 -0
- package/dist/v2/runtime/core/fetch-router.cjs.map +1 -1
- package/dist/v2/runtime/core/fetch-router.mjs +18 -0
- package/dist/v2/runtime/core/fetch-router.mjs.map +1 -1
- package/dist/v2/runtime/core/hooks.cjs.map +1 -1
- package/dist/v2/runtime/core/hooks.d.cts +11 -1
- package/dist/v2/runtime/core/hooks.d.cts.map +1 -1
- package/dist/v2/runtime/core/hooks.d.mts +10 -0
- package/dist/v2/runtime/core/hooks.d.mts.map +1 -1
- package/dist/v2/runtime/core/hooks.mjs.map +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.d.cts +1 -1
- package/dist/v2/runtime/core/middleware.d.cts +1 -1
- package/dist/v2/runtime/core/runtime.cjs +29 -1
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts +95 -26
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts +94 -25
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +30 -2
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.cts +1 -1
- package/dist/v2/runtime/endpoints/express.cjs +10 -5
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.cts +30 -4
- package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.mts +29 -3
- package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express.mjs +10 -5
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.d.cts +1 -1
- package/dist/v2/runtime/endpoints/hono.cjs +7 -3
- package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.cts +30 -16
- package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.mts +29 -15
- package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/hono.mjs +7 -3
- package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/index.d.cts +3 -3
- package/dist/v2/runtime/endpoints/index.d.mts +2 -2
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts +1 -1
- package/dist/v2/runtime/endpoints/node.cjs +12 -1
- package/dist/v2/runtime/endpoints/node.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/node.d.cts +22 -2
- package/dist/v2/runtime/endpoints/node.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/node.d.mts +21 -1
- package/dist/v2/runtime/endpoints/node.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/node.mjs +12 -1
- package/dist/v2/runtime/endpoints/node.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/single-route-helpers.cjs +1 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/single-route-helpers.mjs +1 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.mjs.map +1 -1
- package/dist/v2/runtime/express.d.cts +2 -2
- package/dist/v2/runtime/express.d.mts +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +1 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +1 -0
- package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +2 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +2 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-suggest.cjs +83 -0
- package/dist/v2/runtime/handlers/handle-suggest.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-suggest.mjs +82 -0
- package/dist/v2/runtime/handlers/handle-suggest.mjs.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.cjs +169 -9
- package/dist/v2/runtime/handlers/header-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/header-utils.d.cts +54 -0
- package/dist/v2/runtime/handlers/header-utils.d.cts.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.d.mts +54 -0
- package/dist/v2/runtime/handlers/header-utils.d.mts.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.mjs +168 -9
- package/dist/v2/runtime/handlers/header-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/memories.cjs +209 -0
- package/dist/v2/runtime/handlers/intelligence/memories.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/memories.mjs +204 -0
- package/dist/v2/runtime/handlers/intelligence/memories.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +18 -5
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +18 -5
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.cjs +4 -4
- package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/sse-response.mjs +4 -4
- package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs +2 -2
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs +3 -3
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/v2/runtime/hono.d.cts +2 -2
- package/dist/v2/runtime/hono.d.mts +1 -1
- package/dist/v2/runtime/index.d.cts +6 -5
- package/dist/v2/runtime/index.d.cts.map +1 -1
- package/dist/v2/runtime/index.d.mts +5 -4
- package/dist/v2/runtime/index.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs +71 -2
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +113 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +112 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +71 -2
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/node.d.cts +1 -1
- package/dist/v2/runtime/runner/agent-runner.d.cts +1 -1
- package/dist/v2/runtime/runner/in-memory.cjs +35 -19
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.cts +13 -1
- package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.d.mts +12 -0
- package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
- package/dist/v2/runtime/runner/in-memory.mjs +35 -19
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
- package/dist/v2/runtime/runner/index.d.cts +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +1 -1
- package/dist/v2/runtime/transcription-service/transcription-service.d.cts +1 -1
- package/package.json +9 -3
- package/dist/package.mjs.map +0 -1
|
@@ -5,15 +5,18 @@ import express from "express";
|
|
|
5
5
|
import cors from "cors";
|
|
6
6
|
|
|
7
7
|
//#region src/v2/runtime/endpoints/express.ts
|
|
8
|
-
function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route", cors: corsOption = true, hooks }) {
|
|
8
|
+
function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route", cors: corsOption = true, hooks, activateChannels, __channelEngine }) {
|
|
9
9
|
const normalizedBase = normalizeBasePath(basePath);
|
|
10
|
-
const
|
|
10
|
+
const handler = createCopilotRuntimeHandler({
|
|
11
11
|
runtime,
|
|
12
12
|
basePath: normalizedBase,
|
|
13
13
|
mode,
|
|
14
14
|
cors: false,
|
|
15
|
-
hooks
|
|
16
|
-
|
|
15
|
+
hooks,
|
|
16
|
+
activateChannels,
|
|
17
|
+
__channelEngine
|
|
18
|
+
});
|
|
19
|
+
const nodeHandler = createExpressNodeHandler(handler);
|
|
17
20
|
const expressHandler = async (req, res, next) => {
|
|
18
21
|
try {
|
|
19
22
|
await nodeHandler(req, res);
|
|
@@ -43,7 +46,9 @@ function createCopilotExpressHandler({ runtime, basePath, mode = "multi-route",
|
|
|
43
46
|
router.options(normalizedBase, expressHandler);
|
|
44
47
|
} else if (normalizedBase === "/") router.all(/.*/, expressHandler);
|
|
45
48
|
else router.all(new RegExp(`^${escapeRegExp(normalizedBase)}(\\/.*)?$`), expressHandler);
|
|
46
|
-
|
|
49
|
+
const exposedRouter = router;
|
|
50
|
+
exposedRouter.channels = handler.channels;
|
|
51
|
+
return exposedRouter;
|
|
47
52
|
}
|
|
48
53
|
function escapeRegExp(s) {
|
|
49
54
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"sourcesContent":["import express from \"express\";\nimport type {\n Request as ExpressRequest,\n Response as ExpressResponse,\n NextFunction,\n Router,\n} from \"express\";\nimport cors from \"cors\";\nimport type { CorsOptions } from \"cors\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport { createExpressNodeHandler } from \"./express-fetch-bridge\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\n\nexport interface CopilotExpressEndpointParams {\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 * CORS configuration for the Express router.\n * - `true` (default): permissive CORS (`origin: \"*\"`, all methods, all headers).\n * - `false`: no CORS middleware is applied — handle it yourself.\n * - object: passed directly to the Express `cors()` middleware.\n */\n cors?: boolean | CorsOptions;\n\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n}\n\n/**\n * Creates an Express router that serves the CopilotKit runtime.\n *\n * In **multi-route** mode (default) the router exposes:\n * - `GET {basePath}/info` — runtime info\n * - `POST {basePath}/agent/:agentId/run` — start an agent run\n * - `POST {basePath}/agent/:agentId/connect` — connect to an agent run\n * - `POST {basePath}/agent/:agentId/stop/:threadId` — stop an agent run\n * - `POST {basePath}/transcribe` — transcribe audio\n *\n * In **single-route** mode a single `POST {basePath}` endpoint accepts a JSON\n * envelope `{ method, params, body }` and dispatches to the appropriate handler.\n *\n * @example\n * ```typescript\n * import express from \"express\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotExpressHandler } from \"@copilotkit/runtime/v2/express\";\n *\n * const runtime = new CopilotRuntime({\n * agents: { default: new BuiltInAgent({ model: \"openai/gpt-4o-mini\" }) },\n * });\n *\n * const app = express();\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * }));\n * app.listen(4000);\n * ```\n *\n * @example Single-route mode with lifecycle hooks\n * ```typescript\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * mode: \"single-route\",\n * hooks: {\n * onRequest: ({ request }) => {\n * if (!request.headers.get(\"authorization\")) {\n * throw new Response(\"Unauthorized\", { status: 401 });\n * }\n * },\n * },\n * }));\n * ```\n */\n/** @deprecated Use `createCopilotExpressHandler` instead. */\nexport { createCopilotExpressHandler as createCopilotEndpointExpress };\n\nexport function createCopilotExpressHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsOption = true,\n hooks,\n}: CopilotExpressEndpointParams):
|
|
1
|
+
{"version":3,"file":"express.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/express.ts"],"sourcesContent":["import express from \"express\";\nimport type {\n Request as ExpressRequest,\n Response as ExpressResponse,\n NextFunction,\n Router,\n} from \"express\";\nimport cors from \"cors\";\nimport type { CorsOptions } from \"cors\";\nimport type { CopilotRuntimeLike } from \"../core/runtime\";\nimport { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\nimport { createExpressNodeHandler } from \"./express-fetch-bridge\";\nimport type { CopilotRuntimeHooks } from \"../core/hooks\";\n\n/**\n * An Express {@link Router} that may also carry an optional\n * {@link ChannelsControl} surface. Express's Router is a request-scoped\n * middleware object, not a long-running process owner — Node\n * (`createCopilotNodeListener`) is the lifecycle-owning surface for\n * `.channels`. It is attached here too, best-effort, for callers that mount\n * the router directly and want to observe/stop managed Channel activation\n * without also standing up a Node listener.\n */\nexport type CopilotExpressRouter = Router & { channels?: ChannelsControl };\n\nexport interface CopilotExpressEndpointParams {\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 * CORS configuration for the Express router.\n * - `true` (default): permissive CORS (`origin: \"*\"`, all methods, all headers).\n * - `false`: no CORS middleware is applied — handle it yourself.\n * - object: passed directly to the Express `cors()` middleware.\n */\n cors?: boolean | CorsOptions;\n\n /**\n * Lifecycle hooks for request processing.\n */\n hooks?: CopilotRuntimeHooks;\n\n /**\n * Whether the underlying handler activates the runtime's declared managed\n * Channels at creation time. Defaults to `true`. See\n * `CopilotRuntimeHandlerOptions.activateChannels`.\n */\n activateChannels?: boolean;\n\n /**\n * @internal Test seam: inject a fake Channel activation engine. Forwarded\n * to `createCopilotRuntimeHandler`. Not part of the public API.\n */\n __channelEngine?: ActivateChannelEngine;\n}\n\n/**\n * Creates an Express router that serves the CopilotKit runtime.\n *\n * In **multi-route** mode (default) the router exposes:\n * - `GET {basePath}/info` — runtime info\n * - `POST {basePath}/agent/:agentId/run` — start an agent run\n * - `POST {basePath}/agent/:agentId/connect` — connect to an agent run\n * - `POST {basePath}/agent/:agentId/stop/:threadId` — stop an agent run\n * - `POST {basePath}/transcribe` — transcribe audio\n *\n * In **single-route** mode a single `POST {basePath}` endpoint accepts a JSON\n * envelope `{ method, params, body }` and dispatches to the appropriate handler.\n *\n * @example\n * ```typescript\n * import express from \"express\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotExpressHandler } from \"@copilotkit/runtime/v2/express\";\n *\n * const runtime = new CopilotRuntime({\n * agents: { default: new BuiltInAgent({ model: \"openai/gpt-4o-mini\" }) },\n * });\n *\n * const app = express();\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * }));\n * app.listen(4000);\n * ```\n *\n * @example Single-route mode with lifecycle hooks\n * ```typescript\n * app.use(createCopilotExpressHandler({\n * runtime,\n * basePath: \"/api/copilotkit\",\n * mode: \"single-route\",\n * hooks: {\n * onRequest: ({ request }) => {\n * if (!request.headers.get(\"authorization\")) {\n * throw new Response(\"Unauthorized\", { status: 401 });\n * }\n * },\n * },\n * }));\n * ```\n */\n/** @deprecated Use `createCopilotExpressHandler` instead. */\nexport { createCopilotExpressHandler as createCopilotEndpointExpress };\n\nexport function createCopilotExpressHandler({\n runtime,\n basePath,\n mode = \"multi-route\",\n cors: corsOption = true,\n hooks,\n activateChannels,\n __channelEngine,\n}: CopilotExpressEndpointParams): CopilotExpressRouter {\n const normalizedBase = normalizeBasePath(basePath);\n\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath: normalizedBase,\n mode,\n cors: false, // CORS is handled at the Express middleware layer\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const nodeHandler = createExpressNodeHandler(handler);\n\n const expressHandler = async (\n req: ExpressRequest,\n res: ExpressResponse,\n next: NextFunction,\n ) => {\n try {\n await nodeHandler(req, res);\n } catch (err) {\n next(err);\n }\n };\n\n const router = express.Router();\n\n // CORS middleware\n if (corsOption) {\n const corsConfig: CorsOptions =\n corsOption === true\n ? {\n origin: \"*\",\n methods: [\n \"GET\",\n \"HEAD\",\n \"PUT\",\n \"POST\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n ],\n allowedHeaders: [\"*\"],\n }\n : corsOption;\n router.use(cors(corsConfig));\n }\n\n // Route mounting\n if (mode === \"single-route\") {\n router.post(normalizedBase, expressHandler);\n router.options(normalizedBase, expressHandler);\n } else if (normalizedBase === \"/\") {\n router.all(/.*/, expressHandler);\n } else {\n router.all(\n new RegExp(`^${escapeRegExp(normalizedBase)}(\\\\/.*)?$`),\n expressHandler,\n );\n }\n\n const exposedRouter: CopilotExpressRouter = router;\n exposedRouter.channels = handler.channels;\n return exposedRouter;\n}\n\nfunction escapeRegExp(s: string): string {\n return s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction normalizeBasePath(path: string): string {\n if (!path) {\n throw new Error(\"basePath must be provided for Express 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":";;;;;;;AAsHA,SAAgB,4BAA4B,EAC1C,SACA,UACA,OAAO,eACP,MAAM,aAAa,MACnB,OACA,kBACA,mBACqD;CACrD,MAAM,iBAAiB,kBAAkB,SAAS;CAElD,MAAM,UAAU,4BAA4B;EAC1C;EACA,UAAU;EACV;EACA,MAAM;EACN;EACA;EACA;EACD,CAAC;CAEF,MAAM,cAAc,yBAAyB,QAAQ;CAErD,MAAM,iBAAiB,OACrB,KACA,KACA,SACG;AACH,MAAI;AACF,SAAM,YAAY,KAAK,IAAI;WACpB,KAAK;AACZ,QAAK,IAAI;;;CAIb,MAAM,SAAS,QAAQ,QAAQ;AAG/B,KAAI,YAAY;EACd,MAAM,aACJ,eAAe,OACX;GACE,QAAQ;GACR,SAAS;IACP;IACA;IACA;IACA;IACA;IACA;IACA;IACD;GACD,gBAAgB,CAAC,IAAI;GACtB,GACD;AACN,SAAO,IAAI,KAAK,WAAW,CAAC;;AAI9B,KAAI,SAAS,gBAAgB;AAC3B,SAAO,KAAK,gBAAgB,eAAe;AAC3C,SAAO,QAAQ,gBAAgB,eAAe;YACrC,mBAAmB,IAC5B,QAAO,IAAI,MAAM,eAAe;KAEhC,QAAO,IACL,IAAI,OAAO,IAAI,aAAa,eAAe,CAAC,WAAW,EACvD,eACD;CAGH,MAAM,gBAAsC;AAC5C,eAAc,WAAW,QAAQ;AACjC,QAAO;;AAGT,SAAS,aAAa,GAAmB;AACvC,QAAO,EAAE,QAAQ,uBAAuB,OAAO;;AAGjD,SAAS,kBAAkB,MAAsB;AAC/C,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,iDAAiD;AAGnE,KAAI,CAAC,KAAK,WAAW,IAAI,CACvB,QAAO,IAAI;AAGb,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,IAAI,CACvC,QAAO,KAAK,MAAM,GAAG,GAAG;AAG1B,QAAO"}
|
|
@@ -6,15 +6,19 @@ let hono = require("hono");
|
|
|
6
6
|
//#region src/v2/runtime/endpoints/hono.ts
|
|
7
7
|
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
8
8
|
const createCopilotEndpoint = createCopilotHonoHandler;
|
|
9
|
-
function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks }) {
|
|
9
|
+
function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks, activateChannels, __channelEngine }) {
|
|
10
10
|
const handler = require_fetch_handler.createCopilotRuntimeHandler({
|
|
11
11
|
runtime,
|
|
12
12
|
basePath,
|
|
13
13
|
mode,
|
|
14
14
|
cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
|
|
15
|
-
hooks
|
|
15
|
+
hooks,
|
|
16
|
+
activateChannels,
|
|
17
|
+
__channelEngine
|
|
16
18
|
});
|
|
17
|
-
|
|
19
|
+
const scopedApp = new hono.Hono().basePath(basePath).all("*", async (c) => handler(c.req.raw));
|
|
20
|
+
scopedApp.channels = handler.channels;
|
|
21
|
+
return scopedApp;
|
|
18
22
|
}
|
|
19
23
|
/**
|
|
20
24
|
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.cjs","names":["createCopilotRuntimeHandler","Hono"],"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
|
|
1
|
+
{"version":3,"file":"hono.cjs","names":["createCopilotRuntimeHandler","Hono"],"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\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\n\n/**\n * A Hono app that may also carry an optional {@link ChannelsControl} surface.\n * Hono's app object is request-scoped routing config, not a long-running\n * process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning\n * surface for `.channels`. It is attached here too, best-effort, for callers\n * that mount the Hono app directly and want to observe/stop managed Channel\n * activation without also standing up a Node listener.\n */\nexport type CopilotHonoApp = Hono & { channels?: ChannelsControl };\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 /**\n * Whether the underlying handler activates the runtime's declared managed\n * Channels at creation time. Defaults to `true`. See\n * `CopilotRuntimeHandlerOptions.activateChannels`.\n */\n activateChannels?: boolean;\n\n /**\n * @internal Test seam: inject a fake Channel activation engine. Forwarded\n * to `createCopilotRuntimeHandler`. Not part of the public API.\n */\n __channelEngine?: ActivateChannelEngine;\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 activateChannels,\n __channelEngine,\n}: CopilotEndpointParams): CopilotHonoApp {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const app = new Hono();\n\n const scopedApp: CopilotHonoApp = app\n .basePath(basePath)\n .all(\"*\", async (c) => handler(c.req.raw));\n scopedApp.channels = handler.channels;\n return scopedApp;\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":";;;;;;;AA+EA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,OACA,kBACA,mBACwC;CACxC,MAAM,UAAUA,kDAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACA;EACA;EACD,CAAC;CAIF,MAAM,YAFM,IAAIC,WAAM,CAGnB,SAAS,SAAS,CAClB,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,WAAU,WAAW,QAAQ;AAC7B,QAAO;;;;;AAMT,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
require("reflect-metadata");
|
|
2
2
|
import { CopilotRuntimeLike } from "../core/runtime.cjs";
|
|
3
3
|
import { CopilotCorsConfig } from "../core/fetch-cors.cjs";
|
|
4
4
|
import { CopilotRuntimeHooks } from "../core/hooks.cjs";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
|
+
import { ActivateChannelEngine, ChannelsControl } from "../core/channel-manager.cjs";
|
|
6
|
+
import { Hono } from "hono";
|
|
8
7
|
|
|
9
8
|
//#region src/v2/runtime/endpoints/hono.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A Hono app that may also carry an optional {@link ChannelsControl} surface.
|
|
11
|
+
* Hono's app object is request-scoped routing config, not a long-running
|
|
12
|
+
* process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning
|
|
13
|
+
* surface for `.channels`. It is attached here too, best-effort, for callers
|
|
14
|
+
* that mount the Hono app directly and want to observe/stop managed Channel
|
|
15
|
+
* activation without also standing up a Node listener.
|
|
16
|
+
*/
|
|
17
|
+
type CopilotHonoApp = Hono & {
|
|
18
|
+
channels?: ChannelsControl;
|
|
19
|
+
};
|
|
10
20
|
/**
|
|
11
21
|
* CORS configuration for CopilotKit endpoints.
|
|
12
22
|
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
|
|
@@ -45,6 +55,17 @@ interface CopilotEndpointParams {
|
|
|
45
55
|
* Lifecycle hooks for request processing.
|
|
46
56
|
*/
|
|
47
57
|
hooks?: CopilotRuntimeHooks;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the underlying handler activates the runtime's declared managed
|
|
60
|
+
* Channels at creation time. Defaults to `true`. See
|
|
61
|
+
* `CopilotRuntimeHandlerOptions.activateChannels`.
|
|
62
|
+
*/
|
|
63
|
+
activateChannels?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal Test seam: inject a fake Channel activation engine. Forwarded
|
|
66
|
+
* to `createCopilotRuntimeHandler`. Not part of the public API.
|
|
67
|
+
*/
|
|
68
|
+
__channelEngine?: ActivateChannelEngine;
|
|
48
69
|
}
|
|
49
70
|
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
50
71
|
declare const createCopilotEndpoint: typeof createCopilotHonoHandler;
|
|
@@ -53,21 +74,14 @@ declare function createCopilotHonoHandler({
|
|
|
53
74
|
basePath,
|
|
54
75
|
mode,
|
|
55
76
|
cors: corsConfig,
|
|
56
|
-
hooks
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
input: {};
|
|
61
|
-
output: {};
|
|
62
|
-
outputFormat: string;
|
|
63
|
-
status: hono_utils_http_status0.StatusCode;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
}, string, `${string}/*`>;
|
|
77
|
+
hooks,
|
|
78
|
+
activateChannels,
|
|
79
|
+
__channelEngine
|
|
80
|
+
}: CopilotEndpointParams): CopilotHonoApp;
|
|
67
81
|
/**
|
|
68
82
|
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
69
83
|
*/
|
|
70
84
|
declare function toFetchCorsConfig(config: CopilotEndpointCorsConfig): CopilotCorsConfig;
|
|
71
85
|
//#endregion
|
|
72
|
-
export { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
|
|
86
|
+
export { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
|
|
73
87
|
//# sourceMappingURL=hono.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hono.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;AAkBA;;;;;;KAAY,cAAA,GAAiB,IAAA;EAAS,QAAA,GAAW,eAAA;AAAA;AAMjD;;;;AAAA,UAAiB,yBAAA;EAYT;;;;;AAMP;;;EATC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAuBf;;;;EAlBP,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAaA;;;;;EANA,IAAA;EAuBkB;;;AAGpB;EApBE,IAAA,GAAO,yBAAA;;;;EAIP,KAAA,GAAQ,mBAAA;EAkB8B;;;;;EAXtC,gBAAA;EAgBA;;;;EAVA,eAAA,GAAkB,qBAAA;AAAA;;cAGP,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,qBAAA,GAAwB,cAAA;;;;iBAuBX,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
|
|
@@ -2,11 +2,21 @@ import "reflect-metadata";
|
|
|
2
2
|
import { CopilotRuntimeLike } from "../core/runtime.mjs";
|
|
3
3
|
import { CopilotCorsConfig } from "../core/fetch-cors.mjs";
|
|
4
4
|
import { CopilotRuntimeHooks } from "../core/hooks.mjs";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
|
+
import { ActivateChannelEngine, ChannelsControl } from "../core/channel-manager.mjs";
|
|
6
|
+
import { Hono } from "hono";
|
|
8
7
|
|
|
9
8
|
//#region src/v2/runtime/endpoints/hono.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A Hono app that may also carry an optional {@link ChannelsControl} surface.
|
|
11
|
+
* Hono's app object is request-scoped routing config, not a long-running
|
|
12
|
+
* process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning
|
|
13
|
+
* surface for `.channels`. It is attached here too, best-effort, for callers
|
|
14
|
+
* that mount the Hono app directly and want to observe/stop managed Channel
|
|
15
|
+
* activation without also standing up a Node listener.
|
|
16
|
+
*/
|
|
17
|
+
type CopilotHonoApp = Hono & {
|
|
18
|
+
channels?: ChannelsControl;
|
|
19
|
+
};
|
|
10
20
|
/**
|
|
11
21
|
* CORS configuration for CopilotKit endpoints.
|
|
12
22
|
* When using credentials (e.g., HTTP-only cookies), you must specify an explicit origin.
|
|
@@ -45,6 +55,17 @@ interface CopilotEndpointParams {
|
|
|
45
55
|
* Lifecycle hooks for request processing.
|
|
46
56
|
*/
|
|
47
57
|
hooks?: CopilotRuntimeHooks;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the underlying handler activates the runtime's declared managed
|
|
60
|
+
* Channels at creation time. Defaults to `true`. See
|
|
61
|
+
* `CopilotRuntimeHandlerOptions.activateChannels`.
|
|
62
|
+
*/
|
|
63
|
+
activateChannels?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* @internal Test seam: inject a fake Channel activation engine. Forwarded
|
|
66
|
+
* to `createCopilotRuntimeHandler`. Not part of the public API.
|
|
67
|
+
*/
|
|
68
|
+
__channelEngine?: ActivateChannelEngine;
|
|
48
69
|
}
|
|
49
70
|
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
50
71
|
declare const createCopilotEndpoint: typeof createCopilotHonoHandler;
|
|
@@ -53,21 +74,14 @@ declare function createCopilotHonoHandler({
|
|
|
53
74
|
basePath,
|
|
54
75
|
mode,
|
|
55
76
|
cors: corsConfig,
|
|
56
|
-
hooks
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
input: {};
|
|
61
|
-
output: {};
|
|
62
|
-
outputFormat: string;
|
|
63
|
-
status: hono_utils_http_status0.StatusCode;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
}, string, `${string}/*`>;
|
|
77
|
+
hooks,
|
|
78
|
+
activateChannels,
|
|
79
|
+
__channelEngine
|
|
80
|
+
}: CopilotEndpointParams): CopilotHonoApp;
|
|
67
81
|
/**
|
|
68
82
|
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
69
83
|
*/
|
|
70
84
|
declare function toFetchCorsConfig(config: CopilotEndpointCorsConfig): CopilotCorsConfig;
|
|
71
85
|
//#endregion
|
|
72
|
-
export { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
|
|
86
|
+
export { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
|
|
73
87
|
//# sourceMappingURL=hono.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hono.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"mappings":";;;;;;;;;;AAkBA;;;;;;KAAY,cAAA,GAAiB,IAAA;EAAS,QAAA,GAAW,eAAA;AAAA;AAMjD;;;;AAAA,UAAiB,yBAAA;EAYT;;;;;AAMP;;;EATC,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAuBf;;;;EAlBP,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EAaA;;;;;EANA,IAAA;EAuBkB;;;AAGpB;EApBE,IAAA,GAAO,yBAAA;;;;EAIP,KAAA,GAAQ,mBAAA;EAkB8B;;;;;EAXtC,gBAAA;EAgBA;;;;EAVA,eAAA,GAAkB,qBAAA;AAAA;;cAGP,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,gBAAA;EACA;AAAA,GACC,qBAAA,GAAwB,cAAA;;;;iBAuBX,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
|
|
@@ -5,15 +5,19 @@ import { Hono } from "hono";
|
|
|
5
5
|
//#region src/v2/runtime/endpoints/hono.ts
|
|
6
6
|
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
7
7
|
const createCopilotEndpoint = createCopilotHonoHandler;
|
|
8
|
-
function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks }) {
|
|
8
|
+
function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks, activateChannels, __channelEngine }) {
|
|
9
9
|
const handler = createCopilotRuntimeHandler({
|
|
10
10
|
runtime,
|
|
11
11
|
basePath,
|
|
12
12
|
mode,
|
|
13
13
|
cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
|
|
14
|
-
hooks
|
|
14
|
+
hooks,
|
|
15
|
+
activateChannels,
|
|
16
|
+
__channelEngine
|
|
15
17
|
});
|
|
16
|
-
|
|
18
|
+
const scopedApp = new Hono().basePath(basePath).all("*", async (c) => handler(c.req.raw));
|
|
19
|
+
scopedApp.channels = handler.channels;
|
|
20
|
+
return scopedApp;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
19
23
|
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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
|
|
1
|
+
{"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\";\nimport type {\n ActivateChannelEngine,\n ChannelsControl,\n} from \"../core/channel-manager\";\n\n/**\n * A Hono app that may also carry an optional {@link ChannelsControl} surface.\n * Hono's app object is request-scoped routing config, not a long-running\n * process owner — Node (`createCopilotNodeListener`) is the lifecycle-owning\n * surface for `.channels`. It is attached here too, best-effort, for callers\n * that mount the Hono app directly and want to observe/stop managed Channel\n * activation without also standing up a Node listener.\n */\nexport type CopilotHonoApp = Hono & { channels?: ChannelsControl };\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 /**\n * Whether the underlying handler activates the runtime's declared managed\n * Channels at creation time. Defaults to `true`. See\n * `CopilotRuntimeHandlerOptions.activateChannels`.\n */\n activateChannels?: boolean;\n\n /**\n * @internal Test seam: inject a fake Channel activation engine. Forwarded\n * to `createCopilotRuntimeHandler`. Not part of the public API.\n */\n __channelEngine?: ActivateChannelEngine;\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 activateChannels,\n __channelEngine,\n}: CopilotEndpointParams): CopilotHonoApp {\n const handler = createCopilotRuntimeHandler({\n runtime,\n basePath,\n mode,\n cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,\n hooks,\n activateChannels,\n __channelEngine,\n });\n\n const app = new Hono();\n\n const scopedApp: CopilotHonoApp = app\n .basePath(basePath)\n .all(\"*\", async (c) => handler(c.req.raw));\n scopedApp.channels = handler.channels;\n return scopedApp;\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":";;;;;;AA+EA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,OACA,kBACA,mBACwC;CACxC,MAAM,UAAU,4BAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACA;EACA;EACD,CAAC;CAIF,MAAM,YAFM,IAAI,MAAM,CAGnB,SAAS,SAAS,CAClB,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;AAC5C,WAAU,WAAW,QAAQ;AAC7B,QAAO;;;;;AAMT,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.cjs";
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.cjs";
|
|
3
3
|
import { createCopilotEndpointSingleRoute } from "./hono-single.cjs";
|
|
4
|
-
import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./express.cjs";
|
|
4
|
+
import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./express.cjs";
|
|
5
5
|
import { createCopilotEndpointSingleRouteExpress } from "./express-single.cjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.mjs";
|
|
2
|
+
import { CopilotEndpointCorsConfig, CopilotHonoApp, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.mjs";
|
|
3
3
|
import { createCopilotEndpointSingleRoute } from "./hono-single.mjs";
|
|
4
|
-
import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./express.mjs";
|
|
4
|
+
import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./express.mjs";
|
|
5
5
|
import { createCopilotEndpointSingleRouteExpress } from "./express-single.mjs";
|
|
@@ -7,6 +7,11 @@ const require_node_fetch_handler = require('./node-fetch-handler.cjs');
|
|
|
7
7
|
* Convenience wrapper for creating a Node.js HTTP request listener
|
|
8
8
|
* from CopilotKit runtime handler options.
|
|
9
9
|
*
|
|
10
|
+
* When the runtime declares managed Channels (and activation was not opted
|
|
11
|
+
* out of via `activateChannels: false`), the returned listener exposes
|
|
12
|
+
* `.channels` — the same {@link ChannelsControl} surface the underlying
|
|
13
|
+
* fetch handler activates at creation time.
|
|
14
|
+
*
|
|
10
15
|
* @example
|
|
11
16
|
* ```typescript
|
|
12
17
|
* import { createServer } from "node:http";
|
|
@@ -19,10 +24,16 @@ const require_node_fetch_handler = require('./node-fetch-handler.cjs');
|
|
|
19
24
|
* cors: true,
|
|
20
25
|
* });
|
|
21
26
|
* createServer(listener).listen(3000);
|
|
27
|
+
*
|
|
28
|
+
* // Optional: observe/stop managed Channel activation.
|
|
29
|
+
* await listener.channels?.ready();
|
|
22
30
|
* ```
|
|
23
31
|
*/
|
|
24
32
|
function createCopilotNodeListener(options) {
|
|
25
|
-
|
|
33
|
+
const handler = require_fetch_handler.createCopilotRuntimeHandler(options);
|
|
34
|
+
const listener = require_node_fetch_handler.createCopilotNodeHandler(handler);
|
|
35
|
+
listener.channels = handler.channels;
|
|
36
|
+
return listener;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.cjs","names":["
|
|
1
|
+
{"version":3,"file":"node.cjs","names":["createCopilotRuntimeHandler","createCopilotNodeHandler"],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop managed\n * Channel activation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface the underlying\n * fetch handler activates at creation time.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n *\n * // Optional: observe/stop managed Channel activation.\n * await listener.channels?.ready();\n * ```\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n return listener;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAUA,kDAA4B,QAAQ;CACpD,MAAM,WAAgCC,oDAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,QAAO"}
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
import { ChannelsControl } from "../core/channel-manager.cjs";
|
|
2
3
|
import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.cjs";
|
|
3
4
|
import { NodeFetchHandler } from "./node-fetch-handler.cjs";
|
|
4
5
|
|
|
5
6
|
//#region src/v2/runtime/endpoints/node.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* A Node.js HTTP request listener that is also a callable object carrying an
|
|
9
|
+
* optional {@link ChannelsControl} surface, mirroring
|
|
10
|
+
* `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
|
|
11
|
+
* lifecycle-owning entry point for the runtime, so it is the surface that
|
|
12
|
+
* exposes `.channels` for callers that need to observe or stop managed
|
|
13
|
+
* Channel activation.
|
|
14
|
+
*/
|
|
15
|
+
type NodeCopilotListener = NodeFetchHandler & {
|
|
16
|
+
channels?: ChannelsControl;
|
|
17
|
+
};
|
|
6
18
|
/**
|
|
7
19
|
* Convenience wrapper for creating a Node.js HTTP request listener
|
|
8
20
|
* from CopilotKit runtime handler options.
|
|
9
21
|
*
|
|
22
|
+
* When the runtime declares managed Channels (and activation was not opted
|
|
23
|
+
* out of via `activateChannels: false`), the returned listener exposes
|
|
24
|
+
* `.channels` — the same {@link ChannelsControl} surface the underlying
|
|
25
|
+
* fetch handler activates at creation time.
|
|
26
|
+
*
|
|
10
27
|
* @example
|
|
11
28
|
* ```typescript
|
|
12
29
|
* import { createServer } from "node:http";
|
|
@@ -19,9 +36,12 @@ import { NodeFetchHandler } from "./node-fetch-handler.cjs";
|
|
|
19
36
|
* cors: true,
|
|
20
37
|
* });
|
|
21
38
|
* createServer(listener).listen(3000);
|
|
39
|
+
*
|
|
40
|
+
* // Optional: observe/stop managed Channel activation.
|
|
41
|
+
* await listener.channels?.ready();
|
|
22
42
|
* ```
|
|
23
43
|
*/
|
|
24
|
-
declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions):
|
|
44
|
+
declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
|
|
25
45
|
//#endregion
|
|
26
46
|
export { createCopilotNodeListener };
|
|
27
47
|
//# sourceMappingURL=node.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;AAcA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AA6Bb;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import { ChannelsControl } from "../core/channel-manager.mjs";
|
|
2
3
|
import { CopilotRuntimeHandlerOptions } from "../core/fetch-handler.mjs";
|
|
3
4
|
import { NodeFetchHandler } from "./node-fetch-handler.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/v2/runtime/endpoints/node.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* A Node.js HTTP request listener that is also a callable object carrying an
|
|
9
|
+
* optional {@link ChannelsControl} surface, mirroring
|
|
10
|
+
* `CopilotRuntimeFetchHandler.channels`. Node is the long-running,
|
|
11
|
+
* lifecycle-owning entry point for the runtime, so it is the surface that
|
|
12
|
+
* exposes `.channels` for callers that need to observe or stop managed
|
|
13
|
+
* Channel activation.
|
|
14
|
+
*/
|
|
15
|
+
type NodeCopilotListener = NodeFetchHandler & {
|
|
16
|
+
channels?: ChannelsControl;
|
|
17
|
+
};
|
|
6
18
|
/**
|
|
7
19
|
* Convenience wrapper for creating a Node.js HTTP request listener
|
|
8
20
|
* from CopilotKit runtime handler options.
|
|
9
21
|
*
|
|
22
|
+
* When the runtime declares managed Channels (and activation was not opted
|
|
23
|
+
* out of via `activateChannels: false`), the returned listener exposes
|
|
24
|
+
* `.channels` — the same {@link ChannelsControl} surface the underlying
|
|
25
|
+
* fetch handler activates at creation time.
|
|
26
|
+
*
|
|
10
27
|
* @example
|
|
11
28
|
* ```typescript
|
|
12
29
|
* import { createServer } from "node:http";
|
|
@@ -19,9 +36,12 @@ import { NodeFetchHandler } from "./node-fetch-handler.mjs";
|
|
|
19
36
|
* cors: true,
|
|
20
37
|
* });
|
|
21
38
|
* createServer(listener).listen(3000);
|
|
39
|
+
*
|
|
40
|
+
* // Optional: observe/stop managed Channel activation.
|
|
41
|
+
* await listener.channels?.ready();
|
|
22
42
|
* ```
|
|
23
43
|
*/
|
|
24
|
-
declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions):
|
|
44
|
+
declare function createCopilotNodeListener(options: CopilotRuntimeHandlerOptions): NodeCopilotListener;
|
|
25
45
|
//#endregion
|
|
26
46
|
export { createCopilotNodeListener };
|
|
27
47
|
//# sourceMappingURL=node.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"mappings":";;;;;;;;AAcA;;;;;;KAAY,mBAAA,GAAsB,gBAAA;EAChC,QAAA,GAAW,eAAA;AAAA;AA6Bb;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iBAAgB,yBAAA,CACd,OAAA,EAAS,4BAAA,GACR,mBAAA"}
|
|
@@ -7,6 +7,11 @@ import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
|
|
|
7
7
|
* Convenience wrapper for creating a Node.js HTTP request listener
|
|
8
8
|
* from CopilotKit runtime handler options.
|
|
9
9
|
*
|
|
10
|
+
* When the runtime declares managed Channels (and activation was not opted
|
|
11
|
+
* out of via `activateChannels: false`), the returned listener exposes
|
|
12
|
+
* `.channels` — the same {@link ChannelsControl} surface the underlying
|
|
13
|
+
* fetch handler activates at creation time.
|
|
14
|
+
*
|
|
10
15
|
* @example
|
|
11
16
|
* ```typescript
|
|
12
17
|
* import { createServer } from "node:http";
|
|
@@ -19,10 +24,16 @@ import { createCopilotNodeHandler } from "./node-fetch-handler.mjs";
|
|
|
19
24
|
* cors: true,
|
|
20
25
|
* });
|
|
21
26
|
* createServer(listener).listen(3000);
|
|
27
|
+
*
|
|
28
|
+
* // Optional: observe/stop managed Channel activation.
|
|
29
|
+
* await listener.channels?.ready();
|
|
22
30
|
* ```
|
|
23
31
|
*/
|
|
24
32
|
function createCopilotNodeListener(options) {
|
|
25
|
-
|
|
33
|
+
const handler = createCopilotRuntimeHandler(options);
|
|
34
|
+
const listener = createCopilotNodeHandler(handler);
|
|
35
|
+
listener.channels = handler.channels;
|
|
36
|
+
return listener;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n * ```\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n):
|
|
1
|
+
{"version":3,"file":"node.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/node.ts"],"sourcesContent":["import { createCopilotRuntimeHandler } from \"../core/fetch-handler\";\nimport type { CopilotRuntimeHandlerOptions } from \"../core/fetch-handler\";\nimport type { ChannelsControl } from \"../core/channel-manager\";\nimport { createCopilotNodeHandler } from \"./node-fetch-handler\";\nimport type { NodeFetchHandler } from \"./node-fetch-handler\";\n\n/**\n * A Node.js HTTP request listener that is also a callable object carrying an\n * optional {@link ChannelsControl} surface, mirroring\n * `CopilotRuntimeFetchHandler.channels`. Node is the long-running,\n * lifecycle-owning entry point for the runtime, so it is the surface that\n * exposes `.channels` for callers that need to observe or stop managed\n * Channel activation.\n */\nexport type NodeCopilotListener = NodeFetchHandler & {\n channels?: ChannelsControl;\n};\n\n/**\n * Convenience wrapper for creating a Node.js HTTP request listener\n * from CopilotKit runtime handler options.\n *\n * When the runtime declares managed Channels (and activation was not opted\n * out of via `activateChannels: false`), the returned listener exposes\n * `.channels` — the same {@link ChannelsControl} surface the underlying\n * fetch handler activates at creation time.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { CopilotRuntime } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeListener } from \"@copilotkit/runtime/v2/node\";\n *\n * const listener = createCopilotNodeListener({\n * runtime: new CopilotRuntime({ agents: { ... } }),\n * basePath: \"/api/copilotkit\",\n * cors: true,\n * });\n * createServer(listener).listen(3000);\n *\n * // Optional: observe/stop managed Channel activation.\n * await listener.channels?.ready();\n * ```\n */\nexport function createCopilotNodeListener(\n options: CopilotRuntimeHandlerOptions,\n): NodeCopilotListener {\n const handler = createCopilotRuntimeHandler(options);\n const listener: NodeCopilotListener = createCopilotNodeHandler(handler);\n listener.channels = handler.channels;\n return listener;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,0BACd,SACqB;CACrB,MAAM,UAAU,4BAA4B,QAAQ;CACpD,MAAM,WAAgC,yBAAyB,QAAQ;AACvE,UAAS,WAAW,QAAQ;AAC5B,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-route-helpers.cjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/single-route-helpers.ts"],"sourcesContent":["const METHOD_NAMES = [\n \"agent/run\",\n \"agent/connect\",\n \"agent/stop\",\n \"info\",\n \"transcribe\",\n] as const;\n\nexport type EndpointMethod = (typeof METHOD_NAMES)[number];\n\ninterface JsonEnvelope {\n method?: string;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport interface MethodCall {\n method: EndpointMethod;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport async function parseMethodCall(request: Request): Promise<MethodCall> {\n const contentType = request.headers.get(\"content-type\") || \"\";\n\n if (!contentType.includes(\"application/json\")) {\n throw createResponseError(\n \"Single-route endpoint expects JSON payloads\",\n 415,\n );\n }\n\n let jsonEnvelope: JsonEnvelope;\n try {\n jsonEnvelope = (await request.clone().json()) as JsonEnvelope;\n } catch {\n throw createResponseError(\"Invalid JSON payload\", 400);\n }\n\n const method = validateMethod(jsonEnvelope.method);\n\n return {\n method,\n params: jsonEnvelope.params,\n body: jsonEnvelope.body,\n };\n}\n\nexport function expectString(\n params: Record<string, unknown> | undefined,\n key: string,\n): string {\n const value = params?.[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n\n throw createResponseError(`Missing or invalid parameter '${key}'`, 400);\n}\n\nexport function createJsonRequest(base: Request, body: unknown): Request {\n if (body === undefined || body === null) {\n throw createResponseError(\"Missing request body for JSON handler\", 400);\n }\n\n const headers = new Headers(base.headers);\n headers.set(\"content-type\", \"application/json\");\n headers.delete(\"content-length\");\n\n const serializedBody = serializeJsonBody(body);\n\n return new Request(base.url, {\n method: \"POST\",\n headers,\n body: serializedBody,\n signal: base.signal,\n });\n}\n\nexport function createResponseError(message: string, status: number): Response {\n return new Response(\n JSON.stringify({\n error: \"invalid_request\",\n message,\n }),\n {\n status,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n}\n\nfunction validateMethod(method: string | undefined): EndpointMethod {\n if (!method) {\n throw createResponseError(\"Missing method field\", 400);\n }\n\n if ((METHOD_NAMES as readonly string[]).includes(method)) {\n return method as EndpointMethod;\n }\n\n throw createResponseError(`Unsupported method '${method}'`, 400);\n}\n\nfunction serializeJsonBody(body: unknown): BodyInit {\n if (typeof body === \"string\") {\n return body;\n }\n\n if (\n body instanceof Blob ||\n body instanceof ArrayBuffer ||\n body instanceof Uint8Array\n ) {\n // Uint8Array<ArrayBufferLike> is a valid fetch body at runtime, but the\n // DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return body as BodyInit;\n }\n\n if (body instanceof FormData || body instanceof URLSearchParams) {\n return body;\n }\n\n return JSON.stringify(body);\n}\n"],"mappings":";;;AAAA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACD;AAgBD,eAAsB,gBAAgB,SAAuC;AAG3E,KAAI,EAFgB,QAAQ,QAAQ,IAAI,eAAe,IAAI,IAE1C,SAAS,mBAAmB,CAC3C,OAAM,oBACJ,+CACA,IACD;CAGH,IAAI;AACJ,KAAI;AACF,iBAAgB,MAAM,QAAQ,OAAO,CAAC,MAAM;SACtC;AACN,QAAM,oBAAoB,wBAAwB,IAAI;;AAKxD,QAAO;EACL,QAHa,eAAe,aAAa,OAAO;EAIhD,QAAQ,aAAa;EACrB,MAAM,aAAa;EACpB;;AAGH,SAAgB,aACd,QACA,KACQ;CACR,MAAM,QAAQ,SAAS;AACvB,KAAI,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,SAAS,EACrD,QAAO;AAGT,OAAM,oBAAoB,iCAAiC,IAAI,IAAI,IAAI;;AAGzE,SAAgB,kBAAkB,MAAe,MAAwB;AACvE,KAAI,SAAS,UAAa,SAAS,KACjC,OAAM,oBAAoB,yCAAyC,IAAI;CAGzE,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,SAAQ,IAAI,gBAAgB,mBAAmB;AAC/C,SAAQ,OAAO,iBAAiB;CAEhC,MAAM,iBAAiB,kBAAkB,KAAK;AAE9C,QAAO,IAAI,QAAQ,KAAK,KAAK;EAC3B,QAAQ;EACR;EACA,MAAM;EACN,QAAQ,KAAK;EACd,CAAC;;AAGJ,SAAgB,oBAAoB,SAAiB,QAA0B;AAC7E,QAAO,IAAI,SACT,KAAK,UAAU;EACb,OAAO;EACP;EACD,CAAC,EACF;EACE;EACA,SAAS,EACP,gBAAgB,oBACjB;EACF,CACF;;AAGH,SAAS,eAAe,QAA4C;AAClE,KAAI,CAAC,OACH,OAAM,oBAAoB,wBAAwB,IAAI;AAGxD,KAAK,aAAmC,SAAS,OAAO,CACtD,QAAO;AAGT,OAAM,oBAAoB,uBAAuB,OAAO,IAAI,IAAI;;AAGlE,SAAS,kBAAkB,MAAyB;AAClD,KAAI,OAAO,SAAS,SAClB,QAAO;AAGT,KACE,gBAAgB,QAChB,gBAAgB,eAChB,gBAAgB,WAIhB,QAAO;AAGT,KAAI,gBAAgB,YAAY,gBAAgB,gBAC9C,QAAO;AAGT,QAAO,KAAK,UAAU,KAAK"}
|
|
1
|
+
{"version":3,"file":"single-route-helpers.cjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/single-route-helpers.ts"],"sourcesContent":["const METHOD_NAMES = [\n \"agent/run\",\n \"agent/suggest\",\n \"agent/connect\",\n \"agent/stop\",\n \"info\",\n \"transcribe\",\n] as const;\n\nexport type EndpointMethod = (typeof METHOD_NAMES)[number];\n\ninterface JsonEnvelope {\n method?: string;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport interface MethodCall {\n method: EndpointMethod;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport async function parseMethodCall(request: Request): Promise<MethodCall> {\n const contentType = request.headers.get(\"content-type\") || \"\";\n\n if (!contentType.includes(\"application/json\")) {\n throw createResponseError(\n \"Single-route endpoint expects JSON payloads\",\n 415,\n );\n }\n\n let jsonEnvelope: JsonEnvelope;\n try {\n jsonEnvelope = (await request.clone().json()) as JsonEnvelope;\n } catch {\n throw createResponseError(\"Invalid JSON payload\", 400);\n }\n\n const method = validateMethod(jsonEnvelope.method);\n\n return {\n method,\n params: jsonEnvelope.params,\n body: jsonEnvelope.body,\n };\n}\n\nexport function expectString(\n params: Record<string, unknown> | undefined,\n key: string,\n): string {\n const value = params?.[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n\n throw createResponseError(`Missing or invalid parameter '${key}'`, 400);\n}\n\nexport function createJsonRequest(base: Request, body: unknown): Request {\n if (body === undefined || body === null) {\n throw createResponseError(\"Missing request body for JSON handler\", 400);\n }\n\n const headers = new Headers(base.headers);\n headers.set(\"content-type\", \"application/json\");\n headers.delete(\"content-length\");\n\n const serializedBody = serializeJsonBody(body);\n\n return new Request(base.url, {\n method: \"POST\",\n headers,\n body: serializedBody,\n signal: base.signal,\n });\n}\n\nexport function createResponseError(message: string, status: number): Response {\n return new Response(\n JSON.stringify({\n error: \"invalid_request\",\n message,\n }),\n {\n status,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n}\n\nfunction validateMethod(method: string | undefined): EndpointMethod {\n if (!method) {\n throw createResponseError(\"Missing method field\", 400);\n }\n\n if ((METHOD_NAMES as readonly string[]).includes(method)) {\n return method as EndpointMethod;\n }\n\n throw createResponseError(`Unsupported method '${method}'`, 400);\n}\n\nfunction serializeJsonBody(body: unknown): BodyInit {\n if (typeof body === \"string\") {\n return body;\n }\n\n if (\n body instanceof Blob ||\n body instanceof ArrayBuffer ||\n body instanceof Uint8Array\n ) {\n // Uint8Array<ArrayBufferLike> is a valid fetch body at runtime, but the\n // DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return body as BodyInit;\n }\n\n if (body instanceof FormData || body instanceof URLSearchParams) {\n return body;\n }\n\n return JSON.stringify(body);\n}\n"],"mappings":";;;AAAA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACD;AAgBD,eAAsB,gBAAgB,SAAuC;AAG3E,KAAI,EAFgB,QAAQ,QAAQ,IAAI,eAAe,IAAI,IAE1C,SAAS,mBAAmB,CAC3C,OAAM,oBACJ,+CACA,IACD;CAGH,IAAI;AACJ,KAAI;AACF,iBAAgB,MAAM,QAAQ,OAAO,CAAC,MAAM;SACtC;AACN,QAAM,oBAAoB,wBAAwB,IAAI;;AAKxD,QAAO;EACL,QAHa,eAAe,aAAa,OAAO;EAIhD,QAAQ,aAAa;EACrB,MAAM,aAAa;EACpB;;AAGH,SAAgB,aACd,QACA,KACQ;CACR,MAAM,QAAQ,SAAS;AACvB,KAAI,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,SAAS,EACrD,QAAO;AAGT,OAAM,oBAAoB,iCAAiC,IAAI,IAAI,IAAI;;AAGzE,SAAgB,kBAAkB,MAAe,MAAwB;AACvE,KAAI,SAAS,UAAa,SAAS,KACjC,OAAM,oBAAoB,yCAAyC,IAAI;CAGzE,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,SAAQ,IAAI,gBAAgB,mBAAmB;AAC/C,SAAQ,OAAO,iBAAiB;CAEhC,MAAM,iBAAiB,kBAAkB,KAAK;AAE9C,QAAO,IAAI,QAAQ,KAAK,KAAK;EAC3B,QAAQ;EACR;EACA,MAAM;EACN,QAAQ,KAAK;EACd,CAAC;;AAGJ,SAAgB,oBAAoB,SAAiB,QAA0B;AAC7E,QAAO,IAAI,SACT,KAAK,UAAU;EACb,OAAO;EACP;EACD,CAAC,EACF;EACE;EACA,SAAS,EACP,gBAAgB,oBACjB;EACF,CACF;;AAGH,SAAS,eAAe,QAA4C;AAClE,KAAI,CAAC,OACH,OAAM,oBAAoB,wBAAwB,IAAI;AAGxD,KAAK,aAAmC,SAAS,OAAO,CACtD,QAAO;AAGT,OAAM,oBAAoB,uBAAuB,OAAO,IAAI,IAAI;;AAGlE,SAAS,kBAAkB,MAAyB;AAClD,KAAI,OAAO,SAAS,SAClB,QAAO;AAGT,KACE,gBAAgB,QAChB,gBAAgB,eAChB,gBAAgB,WAIhB,QAAO;AAGT,KAAI,gBAAgB,YAAY,gBAAgB,gBAC9C,QAAO;AAGT,QAAO,KAAK,UAAU,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-route-helpers.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/single-route-helpers.ts"],"sourcesContent":["const METHOD_NAMES = [\n \"agent/run\",\n \"agent/connect\",\n \"agent/stop\",\n \"info\",\n \"transcribe\",\n] as const;\n\nexport type EndpointMethod = (typeof METHOD_NAMES)[number];\n\ninterface JsonEnvelope {\n method?: string;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport interface MethodCall {\n method: EndpointMethod;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport async function parseMethodCall(request: Request): Promise<MethodCall> {\n const contentType = request.headers.get(\"content-type\") || \"\";\n\n if (!contentType.includes(\"application/json\")) {\n throw createResponseError(\n \"Single-route endpoint expects JSON payloads\",\n 415,\n );\n }\n\n let jsonEnvelope: JsonEnvelope;\n try {\n jsonEnvelope = (await request.clone().json()) as JsonEnvelope;\n } catch {\n throw createResponseError(\"Invalid JSON payload\", 400);\n }\n\n const method = validateMethod(jsonEnvelope.method);\n\n return {\n method,\n params: jsonEnvelope.params,\n body: jsonEnvelope.body,\n };\n}\n\nexport function expectString(\n params: Record<string, unknown> | undefined,\n key: string,\n): string {\n const value = params?.[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n\n throw createResponseError(`Missing or invalid parameter '${key}'`, 400);\n}\n\nexport function createJsonRequest(base: Request, body: unknown): Request {\n if (body === undefined || body === null) {\n throw createResponseError(\"Missing request body for JSON handler\", 400);\n }\n\n const headers = new Headers(base.headers);\n headers.set(\"content-type\", \"application/json\");\n headers.delete(\"content-length\");\n\n const serializedBody = serializeJsonBody(body);\n\n return new Request(base.url, {\n method: \"POST\",\n headers,\n body: serializedBody,\n signal: base.signal,\n });\n}\n\nexport function createResponseError(message: string, status: number): Response {\n return new Response(\n JSON.stringify({\n error: \"invalid_request\",\n message,\n }),\n {\n status,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n}\n\nfunction validateMethod(method: string | undefined): EndpointMethod {\n if (!method) {\n throw createResponseError(\"Missing method field\", 400);\n }\n\n if ((METHOD_NAMES as readonly string[]).includes(method)) {\n return method as EndpointMethod;\n }\n\n throw createResponseError(`Unsupported method '${method}'`, 400);\n}\n\nfunction serializeJsonBody(body: unknown): BodyInit {\n if (typeof body === \"string\") {\n return body;\n }\n\n if (\n body instanceof Blob ||\n body instanceof ArrayBuffer ||\n body instanceof Uint8Array\n ) {\n // Uint8Array<ArrayBufferLike> is a valid fetch body at runtime, but the\n // DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return body as BodyInit;\n }\n\n if (body instanceof FormData || body instanceof URLSearchParams) {\n return body;\n }\n\n return JSON.stringify(body);\n}\n"],"mappings":";;AAAA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACD;AAgBD,eAAsB,gBAAgB,SAAuC;AAG3E,KAAI,EAFgB,QAAQ,QAAQ,IAAI,eAAe,IAAI,IAE1C,SAAS,mBAAmB,CAC3C,OAAM,oBACJ,+CACA,IACD;CAGH,IAAI;AACJ,KAAI;AACF,iBAAgB,MAAM,QAAQ,OAAO,CAAC,MAAM;SACtC;AACN,QAAM,oBAAoB,wBAAwB,IAAI;;AAKxD,QAAO;EACL,QAHa,eAAe,aAAa,OAAO;EAIhD,QAAQ,aAAa;EACrB,MAAM,aAAa;EACpB;;AAGH,SAAgB,aACd,QACA,KACQ;CACR,MAAM,QAAQ,SAAS;AACvB,KAAI,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,SAAS,EACrD,QAAO;AAGT,OAAM,oBAAoB,iCAAiC,IAAI,IAAI,IAAI;;AAGzE,SAAgB,kBAAkB,MAAe,MAAwB;AACvE,KAAI,SAAS,UAAa,SAAS,KACjC,OAAM,oBAAoB,yCAAyC,IAAI;CAGzE,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,SAAQ,IAAI,gBAAgB,mBAAmB;AAC/C,SAAQ,OAAO,iBAAiB;CAEhC,MAAM,iBAAiB,kBAAkB,KAAK;AAE9C,QAAO,IAAI,QAAQ,KAAK,KAAK;EAC3B,QAAQ;EACR;EACA,MAAM;EACN,QAAQ,KAAK;EACd,CAAC;;AAGJ,SAAgB,oBAAoB,SAAiB,QAA0B;AAC7E,QAAO,IAAI,SACT,KAAK,UAAU;EACb,OAAO;EACP;EACD,CAAC,EACF;EACE;EACA,SAAS,EACP,gBAAgB,oBACjB;EACF,CACF;;AAGH,SAAS,eAAe,QAA4C;AAClE,KAAI,CAAC,OACH,OAAM,oBAAoB,wBAAwB,IAAI;AAGxD,KAAK,aAAmC,SAAS,OAAO,CACtD,QAAO;AAGT,OAAM,oBAAoB,uBAAuB,OAAO,IAAI,IAAI;;AAGlE,SAAS,kBAAkB,MAAyB;AAClD,KAAI,OAAO,SAAS,SAClB,QAAO;AAGT,KACE,gBAAgB,QAChB,gBAAgB,eAChB,gBAAgB,WAIhB,QAAO;AAGT,KAAI,gBAAgB,YAAY,gBAAgB,gBAC9C,QAAO;AAGT,QAAO,KAAK,UAAU,KAAK"}
|
|
1
|
+
{"version":3,"file":"single-route-helpers.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/single-route-helpers.ts"],"sourcesContent":["const METHOD_NAMES = [\n \"agent/run\",\n \"agent/suggest\",\n \"agent/connect\",\n \"agent/stop\",\n \"info\",\n \"transcribe\",\n] as const;\n\nexport type EndpointMethod = (typeof METHOD_NAMES)[number];\n\ninterface JsonEnvelope {\n method?: string;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport interface MethodCall {\n method: EndpointMethod;\n params?: Record<string, unknown>;\n body?: unknown;\n}\n\nexport async function parseMethodCall(request: Request): Promise<MethodCall> {\n const contentType = request.headers.get(\"content-type\") || \"\";\n\n if (!contentType.includes(\"application/json\")) {\n throw createResponseError(\n \"Single-route endpoint expects JSON payloads\",\n 415,\n );\n }\n\n let jsonEnvelope: JsonEnvelope;\n try {\n jsonEnvelope = (await request.clone().json()) as JsonEnvelope;\n } catch {\n throw createResponseError(\"Invalid JSON payload\", 400);\n }\n\n const method = validateMethod(jsonEnvelope.method);\n\n return {\n method,\n params: jsonEnvelope.params,\n body: jsonEnvelope.body,\n };\n}\n\nexport function expectString(\n params: Record<string, unknown> | undefined,\n key: string,\n): string {\n const value = params?.[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n\n throw createResponseError(`Missing or invalid parameter '${key}'`, 400);\n}\n\nexport function createJsonRequest(base: Request, body: unknown): Request {\n if (body === undefined || body === null) {\n throw createResponseError(\"Missing request body for JSON handler\", 400);\n }\n\n const headers = new Headers(base.headers);\n headers.set(\"content-type\", \"application/json\");\n headers.delete(\"content-length\");\n\n const serializedBody = serializeJsonBody(body);\n\n return new Request(base.url, {\n method: \"POST\",\n headers,\n body: serializedBody,\n signal: base.signal,\n });\n}\n\nexport function createResponseError(message: string, status: number): Response {\n return new Response(\n JSON.stringify({\n error: \"invalid_request\",\n message,\n }),\n {\n status,\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n}\n\nfunction validateMethod(method: string | undefined): EndpointMethod {\n if (!method) {\n throw createResponseError(\"Missing method field\", 400);\n }\n\n if ((METHOD_NAMES as readonly string[]).includes(method)) {\n return method as EndpointMethod;\n }\n\n throw createResponseError(`Unsupported method '${method}'`, 400);\n}\n\nfunction serializeJsonBody(body: unknown): BodyInit {\n if (typeof body === \"string\") {\n return body;\n }\n\n if (\n body instanceof Blob ||\n body instanceof ArrayBuffer ||\n body instanceof Uint8Array\n ) {\n // Uint8Array<ArrayBufferLike> is a valid fetch body at runtime, but the\n // DOM lib's BodyInit only admits ArrayBuffer-backed views.\n return body as BodyInit;\n }\n\n if (body instanceof FormData || body instanceof URLSearchParams) {\n return body;\n }\n\n return JSON.stringify(body);\n}\n"],"mappings":";;AAAA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACD;AAgBD,eAAsB,gBAAgB,SAAuC;AAG3E,KAAI,EAFgB,QAAQ,QAAQ,IAAI,eAAe,IAAI,IAE1C,SAAS,mBAAmB,CAC3C,OAAM,oBACJ,+CACA,IACD;CAGH,IAAI;AACJ,KAAI;AACF,iBAAgB,MAAM,QAAQ,OAAO,CAAC,MAAM;SACtC;AACN,QAAM,oBAAoB,wBAAwB,IAAI;;AAKxD,QAAO;EACL,QAHa,eAAe,aAAa,OAAO;EAIhD,QAAQ,aAAa;EACrB,MAAM,aAAa;EACpB;;AAGH,SAAgB,aACd,QACA,KACQ;CACR,MAAM,QAAQ,SAAS;AACvB,KAAI,OAAO,UAAU,YAAY,MAAM,MAAM,CAAC,SAAS,EACrD,QAAO;AAGT,OAAM,oBAAoB,iCAAiC,IAAI,IAAI,IAAI;;AAGzE,SAAgB,kBAAkB,MAAe,MAAwB;AACvE,KAAI,SAAS,UAAa,SAAS,KACjC,OAAM,oBAAoB,yCAAyC,IAAI;CAGzE,MAAM,UAAU,IAAI,QAAQ,KAAK,QAAQ;AACzC,SAAQ,IAAI,gBAAgB,mBAAmB;AAC/C,SAAQ,OAAO,iBAAiB;CAEhC,MAAM,iBAAiB,kBAAkB,KAAK;AAE9C,QAAO,IAAI,QAAQ,KAAK,KAAK;EAC3B,QAAQ;EACR;EACA,MAAM;EACN,QAAQ,KAAK;EACd,CAAC;;AAGJ,SAAgB,oBAAoB,SAAiB,QAA0B;AAC7E,QAAO,IAAI,SACT,KAAK,UAAU;EACb,OAAO;EACP;EACD,CAAC,EACF;EACE;EACA,SAAS,EACP,gBAAgB,oBACjB;EACF,CACF;;AAGH,SAAS,eAAe,QAA4C;AAClE,KAAI,CAAC,OACH,OAAM,oBAAoB,wBAAwB,IAAI;AAGxD,KAAK,aAAmC,SAAS,OAAO,CACtD,QAAO;AAGT,OAAM,oBAAoB,uBAAuB,OAAO,IAAI,IAAI;;AAGlE,SAAS,kBAAkB,MAAyB;AAClD,KAAI,OAAO,SAAS,SAClB,QAAO;AAGT,KACE,gBAAgB,QAChB,gBAAgB,eAChB,gBAAgB,WAIhB,QAAO;AAGT,KAAI,gBAAgB,YAAY,gBAAgB,gBAC9C,QAAO;AAGT,QAAO,KAAK,UAAU,KAAK"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./endpoints/express.cjs";
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
import { CopilotExpressEndpointParams, CopilotExpressRouter, createCopilotExpressHandler } from "./endpoints/express.cjs";
|
|
3
3
|
import { createCopilotEndpointSingleRouteExpress } from "./endpoints/express-single.cjs";
|