@copilotkit/runtime 1.55.0-next.9 → 1.55.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/CHANGELOG.md +24 -2
- package/dist/agent/index.cjs +101 -12
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts.map +1 -1
- package/dist/agent/index.d.mts.map +1 -1
- package/dist/agent/index.mjs +102 -13
- package/dist/agent/index.mjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +4 -841
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts +4 -841
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +3 -2
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +3 -3
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +3 -2
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/package.cjs +70 -47
- package/dist/package.mjs +70 -47
- package/dist/v2/express.cjs +8 -0
- package/dist/v2/express.d.cts +5 -0
- package/dist/v2/express.d.mts +5 -0
- package/dist/v2/express.mjs +5 -0
- package/dist/v2/hono.cjs +9 -0
- package/dist/v2/hono.d.cts +5 -0
- package/dist/v2/hono.d.mts +5 -0
- package/dist/v2/hono.mjs +5 -0
- package/dist/v2/index.cjs +8 -3
- package/dist/v2/index.d.cts +8 -5
- package/dist/v2/index.d.mts +8 -5
- package/dist/v2/index.mjs +5 -4
- package/dist/v2/node.cjs +8 -0
- package/dist/v2/node.d.cts +5 -0
- package/dist/v2/node.d.mts +5 -0
- package/dist/v2/node.mjs +5 -0
- package/dist/v2/runtime/core/fetch-cors.cjs +72 -0
- package/dist/v2/runtime/core/fetch-cors.cjs.map +1 -0
- package/dist/v2/runtime/core/fetch-cors.d.cts +20 -0
- package/dist/v2/runtime/core/fetch-cors.d.cts.map +1 -0
- package/dist/v2/runtime/core/fetch-cors.d.mts +20 -0
- package/dist/v2/runtime/core/fetch-cors.d.mts.map +1 -0
- package/dist/v2/runtime/core/fetch-cors.mjs +70 -0
- package/dist/v2/runtime/core/fetch-cors.mjs.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.cjs +232 -0
- package/dist/v2/runtime/core/fetch-handler.cjs.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.d.cts +40 -0
- package/dist/v2/runtime/core/fetch-handler.d.cts.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.d.mts +40 -0
- package/dist/v2/runtime/core/fetch-handler.d.mts.map +1 -0
- package/dist/v2/runtime/core/fetch-handler.mjs +231 -0
- package/dist/v2/runtime/core/fetch-handler.mjs.map +1 -0
- package/dist/v2/runtime/core/fetch-router.cjs +68 -0
- package/dist/v2/runtime/core/fetch-router.cjs.map +1 -0
- package/dist/v2/runtime/core/fetch-router.mjs +67 -0
- package/dist/v2/runtime/core/fetch-router.mjs.map +1 -0
- package/dist/v2/runtime/core/hooks.cjs +29 -0
- package/dist/v2/runtime/core/hooks.cjs.map +1 -0
- package/dist/v2/runtime/core/hooks.d.cts +78 -0
- package/dist/v2/runtime/core/hooks.d.cts.map +1 -0
- package/dist/v2/runtime/core/hooks.d.mts +78 -0
- package/dist/v2/runtime/core/hooks.d.mts.map +1 -0
- package/dist/v2/runtime/core/hooks.mjs +25 -0
- package/dist/v2/runtime/core/hooks.mjs.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.cjs → core/middleware-sse-parser.cjs} +2 -2
- package/dist/v2/runtime/core/middleware-sse-parser.cjs.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.d.cts → core/middleware-sse-parser.d.cts} +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.d.cts.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.d.mts → core/middleware-sse-parser.d.mts} +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.d.mts.map +1 -0
- package/dist/v2/runtime/{middleware-sse-parser.mjs → core/middleware-sse-parser.mjs} +1 -1
- package/dist/v2/runtime/core/middleware-sse-parser.mjs.map +1 -0
- package/dist/v2/runtime/{middleware.cjs → core/middleware.cjs} +2 -2
- package/dist/v2/runtime/core/middleware.cjs.map +1 -0
- package/dist/v2/runtime/{middleware.d.cts → core/middleware.d.cts} +1 -1
- package/dist/v2/runtime/core/middleware.d.cts.map +1 -0
- package/dist/v2/runtime/{middleware.d.mts → core/middleware.d.mts} +1 -1
- package/dist/v2/runtime/core/middleware.d.mts.map +1 -0
- package/dist/v2/runtime/{middleware.mjs → core/middleware.mjs} +1 -1
- package/dist/v2/runtime/core/middleware.mjs.map +1 -0
- package/dist/v2/runtime/{runtime.cjs → core/runtime.cjs} +35 -10
- package/dist/v2/runtime/core/runtime.cjs.map +1 -0
- package/dist/v2/runtime/{runtime.d.cts → core/runtime.d.cts} +41 -7
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -0
- package/dist/v2/runtime/{runtime.d.mts → core/runtime.d.mts} +42 -8
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -0
- package/dist/v2/runtime/{runtime.mjs → core/runtime.mjs} +36 -11
- package/dist/v2/runtime/core/runtime.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs +83 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs +82 -0
- package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.cjs +35 -181
- package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.cts +35 -2
- package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.d.mts +35 -2
- package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express-single.mjs +35 -178
- package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.cjs +41 -195
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.cts +26 -4
- package/dist/v2/runtime/endpoints/express.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/express.d.mts +26 -4
- package/dist/v2/runtime/endpoints/express.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/express.mjs +41 -195
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.cjs +11 -123
- package/dist/v2/runtime/endpoints/hono-single.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.d.cts +14 -11
- package/dist/v2/runtime/endpoints/hono-single.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.d.mts +14 -11
- package/dist/v2/runtime/endpoints/hono-single.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/hono-single.mjs +11 -123
- package/dist/v2/runtime/endpoints/hono-single.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono.cjs +23 -237
- package/dist/v2/runtime/endpoints/hono.cjs.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.cts +29 -120
- package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -1
- package/dist/v2/runtime/endpoints/hono.d.mts +29 -120
- package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -1
- package/dist/v2/runtime/endpoints/hono.mjs +22 -238
- package/dist/v2/runtime/endpoints/hono.mjs.map +1 -1
- package/dist/v2/runtime/endpoints/index.d.cts +2 -2
- package/dist/v2/runtime/endpoints/index.d.mts +2 -2
- package/dist/v2/runtime/endpoints/node-fetch-handler.cjs +26 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts +12 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.mts +12 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.mjs +24 -0
- package/dist/v2/runtime/endpoints/node-fetch-handler.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/node.cjs +30 -0
- package/dist/v2/runtime/endpoints/node.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/node.d.cts +27 -0
- package/dist/v2/runtime/endpoints/node.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/node.d.mts +27 -0
- package/dist/v2/runtime/endpoints/node.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/node.mjs +30 -0
- package/dist/v2/runtime/endpoints/node.mjs.map +1 -0
- package/dist/v2/runtime/express.d.cts +3 -0
- package/dist/v2/runtime/express.d.mts +3 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +2 -1
- package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +2 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +6 -3
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +6 -3
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.cjs +6 -3
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +6 -3
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-transcribe.cjs.map +1 -1
- package/dist/v2/runtime/handlers/handle-transcribe.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs +22 -1
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs +22 -1
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +1 -1
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +21 -6
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +21 -6
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/json-response.cjs +4 -1
- package/dist/v2/runtime/handlers/shared/json-response.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/json-response.mjs +4 -1
- package/dist/v2/runtime/handlers/shared/json-response.mjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -1
- package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -1
- package/dist/v2/runtime/hono.d.cts +3 -0
- package/dist/v2/runtime/hono.d.mts +3 -0
- package/dist/v2/runtime/index.d.cts +16 -4
- package/dist/v2/runtime/index.d.cts.map +1 -0
- package/dist/v2/runtime/index.d.mts +16 -4
- package/dist/v2/runtime/index.d.mts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs +10 -1
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.cts +22 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.d.mts +22 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs +10 -1
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/v2/runtime/node.d.cts +3 -0
- package/dist/v2/runtime/node.d.mts +3 -0
- package/dist/v2/runtime/open-generative-ui-middleware.cjs +282 -0
- package/dist/v2/runtime/open-generative-ui-middleware.cjs.map +1 -0
- package/dist/v2/runtime/open-generative-ui-middleware.mjs +280 -0
- package/dist/v2/runtime/open-generative-ui-middleware.mjs.map +1 -0
- package/dist/v2/runtime/runner/intelligence.cjs +4 -4
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.cts +6 -2
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.d.mts +6 -2
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/v2/runtime/runner/intelligence.mjs +4 -4
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +37 -0
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +36 -0
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/utils.cjs +15 -0
- package/dist/v2/runtime/telemetry/utils.cjs.map +1 -0
- package/dist/v2/runtime/telemetry/utils.mjs +14 -0
- package/dist/v2/runtime/telemetry/utils.mjs.map +1 -0
- package/package.json +81 -48
- package/src/agent/__tests__/multimodal.test.ts +176 -0
- package/src/agent/index.ts +130 -19
- package/src/lib/runtime/agent-integrations/langgraph/agent.ts +3 -3
- package/src/lib/runtime/copilot-runtime.ts +1 -0
- package/src/v2/express.ts +1 -0
- package/src/v2/hono.ts +1 -0
- package/src/v2/node.ts +1 -0
- package/src/v2/runtime/__tests__/backward-compat.test.ts +261 -0
- package/src/v2/runtime/__tests__/code-review-fixes.test.ts +500 -0
- package/src/v2/runtime/__tests__/cors-credentials.test.ts +2 -2
- package/src/v2/runtime/__tests__/express-adapter.test.ts +188 -0
- package/src/v2/runtime/__tests__/express-body-order.test.ts +1 -1
- package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +344 -0
- package/src/v2/runtime/__tests__/express-single-sse.test.ts +1 -1
- package/src/v2/runtime/__tests__/fetch-cors.test.ts +205 -0
- package/src/v2/runtime/__tests__/fetch-handler-validation.test.ts +372 -0
- package/src/v2/runtime/__tests__/fetch-handler.test.ts +456 -0
- package/src/v2/runtime/__tests__/fetch-router.test.ts +132 -0
- package/src/v2/runtime/__tests__/get-runtime-info.test.ts +4 -1
- package/src/v2/runtime/__tests__/handle-connect.test.ts +15 -13
- package/src/v2/runtime/__tests__/handle-run.test.ts +21 -17
- package/src/v2/runtime/__tests__/handle-threads.test.ts +1 -1
- package/src/v2/runtime/__tests__/handle-transcribe.test.ts +1 -1
- package/src/v2/runtime/__tests__/hono-adapter.test.ts +150 -0
- package/src/v2/runtime/__tests__/hooks-edge-cases.test.ts +457 -0
- package/src/v2/runtime/__tests__/hooks.test.ts +557 -0
- package/src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.ts +27 -0
- package/src/v2/runtime/__tests__/integration/bun/elysia-multi.ts +32 -0
- package/src/v2/runtime/__tests__/integration/bun/elysia-single.ts +33 -0
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-multi.ts +25 -0
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-single.ts +32 -0
- package/src/v2/runtime/__tests__/integration/helpers/create-test-runtime.ts +15 -0
- package/src/v2/runtime/__tests__/integration/helpers/sse-reader.ts +45 -0
- package/src/v2/runtime/__tests__/integration/helpers/test-agent.ts +58 -0
- package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +39 -0
- package/src/v2/runtime/__tests__/integration/servers/express-multi.ts +35 -0
- package/src/v2/runtime/__tests__/integration/servers/express-single.ts +36 -0
- package/src/v2/runtime/__tests__/integration/servers/fetch-direct.ts +39 -0
- package/src/v2/runtime/__tests__/integration/servers/hono-multi.ts +30 -0
- package/src/v2/runtime/__tests__/integration/servers/hono-single.ts +37 -0
- package/src/v2/runtime/__tests__/integration/servers/node-multi.ts +45 -0
- package/src/v2/runtime/__tests__/integration/servers/node-single.ts +46 -0
- package/src/v2/runtime/__tests__/integration/servers/types.ts +18 -0
- package/src/v2/runtime/__tests__/integration/suites/multi-endpoint.suite.ts +358 -0
- package/src/v2/runtime/__tests__/integration/suites/single-endpoint.suite.ts +363 -0
- package/src/v2/runtime/__tests__/middleware-express.test.ts +1 -1
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +1 -1
- package/src/v2/runtime/__tests__/middleware-single.test.ts +1 -1
- package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +1 -1
- package/src/v2/runtime/__tests__/middleware.test.ts +1 -2
- package/src/v2/runtime/__tests__/node-fetch-handler.test.ts +157 -0
- package/src/v2/runtime/__tests__/open-generative-ui-middleware.e2e.test.ts +728 -0
- package/src/v2/runtime/__tests__/router-edge-cases.test.ts +217 -0
- package/src/v2/runtime/__tests__/routing-express.test.ts +1 -1
- package/src/v2/runtime/__tests__/routing-single-express.test.ts +1 -1
- package/src/v2/runtime/__tests__/routing-single.test.ts +1 -1
- package/src/v2/runtime/__tests__/routing.test.ts +1 -1
- package/src/v2/runtime/__tests__/runtime.test.ts +110 -1
- package/src/v2/runtime/__tests__/telemetry.test.ts +62 -1
- package/src/v2/runtime/core/fetch-cors.ts +136 -0
- package/src/v2/runtime/core/fetch-handler.ts +415 -0
- package/src/v2/runtime/core/fetch-router.ts +112 -0
- package/src/v2/runtime/core/hooks.ts +151 -0
- package/src/v2/runtime/{runtime.ts → core/runtime.ts} +79 -10
- package/src/v2/runtime/endpoints/express-fetch-bridge.ts +137 -0
- package/src/v2/runtime/endpoints/express-single.ts +42 -219
- package/src/v2/runtime/endpoints/express.ts +128 -230
- package/src/v2/runtime/endpoints/hono-single.ts +19 -171
- package/src/v2/runtime/endpoints/hono.ts +45 -270
- package/src/v2/runtime/endpoints/node-fetch-handler.ts +48 -0
- package/src/v2/runtime/endpoints/node.ts +28 -0
- package/src/v2/runtime/handlers/get-runtime-info.ts +3 -2
- package/src/v2/runtime/handlers/handle-connect.ts +7 -4
- package/src/v2/runtime/handlers/handle-run.ts +7 -4
- package/src/v2/runtime/handlers/handle-stop.ts +1 -1
- package/src/v2/runtime/handlers/handle-transcribe.ts +1 -1
- package/src/v2/runtime/handlers/intelligence/connect.ts +1 -1
- package/src/v2/runtime/handlers/intelligence/run.ts +31 -1
- package/src/v2/runtime/handlers/intelligence/thread-names.ts +2 -2
- package/src/v2/runtime/handlers/intelligence/threads.ts +1 -1
- package/src/v2/runtime/handlers/shared/agent-utils.ts +29 -10
- package/src/v2/runtime/handlers/shared/json-response.ts +4 -1
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +1 -1
- package/src/v2/runtime/handlers/sse/connect.ts +1 -1
- package/src/v2/runtime/handlers/sse/run.ts +1 -1
- package/src/v2/runtime/hono.ts +2 -0
- package/src/v2/runtime/index.ts +27 -1
- package/src/v2/runtime/intelligence-platform/client.ts +50 -1
- package/src/v2/runtime/node.ts +6 -0
- package/src/v2/runtime/open-generative-ui-middleware.ts +373 -0
- package/src/v2/runtime/runner/intelligence.ts +14 -4
- package/src/v2/runtime/telemetry/telemetry-client.ts +56 -0
- package/src/v2/runtime/telemetry/utils.ts +15 -0
- package/tsdown.config.ts +8 -1
- package/vitest.config.mjs +2 -5
- package/.eslintrc.js +0 -7
- package/dist/v2/runtime/endpoints/express-utils.cjs +0 -119
- package/dist/v2/runtime/endpoints/express-utils.cjs.map +0 -1
- package/dist/v2/runtime/endpoints/express-utils.mjs +0 -117
- package/dist/v2/runtime/endpoints/express-utils.mjs.map +0 -1
- package/dist/v2/runtime/handlers/intelligence/threads.cjs +0 -159
- package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +0 -1
- package/dist/v2/runtime/handlers/intelligence/threads.mjs +0 -154
- package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.cjs.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.d.cts.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.d.mts.map +0 -1
- package/dist/v2/runtime/middleware-sse-parser.mjs.map +0 -1
- package/dist/v2/runtime/middleware.cjs.map +0 -1
- package/dist/v2/runtime/middleware.d.cts.map +0 -1
- package/dist/v2/runtime/middleware.d.mts.map +0 -1
- package/dist/v2/runtime/middleware.mjs.map +0 -1
- package/dist/v2/runtime/runtime.cjs.map +0 -1
- package/dist/v2/runtime/runtime.d.cts.map +0 -1
- package/dist/v2/runtime/runtime.d.mts.map +0 -1
- package/dist/v2/runtime/runtime.mjs.map +0 -1
- package/src/v2/runtime/__tests__/express-abort-signal.test.ts +0 -25
- package/src/v2/runtime/endpoints/express-utils.ts +0 -182
- package/src/v2/runtime/handler.ts +0 -3
- /package/src/v2/runtime/{middleware-sse-parser.ts → core/middleware-sse-parser.ts} +0 -0
- /package/src/v2/runtime/{middleware.ts → core/middleware.ts} +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import { CopilotRuntimeLike } from "../runtime.mjs";
|
|
2
|
+
import { CopilotRuntimeLike } from "../core/runtime.mjs";
|
|
3
|
+
import { CopilotCorsConfig } from "../core/fetch-cors.mjs";
|
|
4
|
+
import { CopilotRuntimeHooks } from "../core/hooks.mjs";
|
|
5
|
+
import * as hono_types0 from "hono/types";
|
|
3
6
|
import * as hono_utils_http_status0 from "hono/utils/http-status";
|
|
4
7
|
import * as hono_hono_base0 from "hono/hono-base";
|
|
5
8
|
|
|
@@ -27,138 +30,44 @@ interface CopilotEndpointCorsConfig {
|
|
|
27
30
|
interface CopilotEndpointParams {
|
|
28
31
|
runtime: CopilotRuntimeLike;
|
|
29
32
|
basePath: string;
|
|
33
|
+
/**
|
|
34
|
+
* Endpoint mode.
|
|
35
|
+
* - `"multi-route"` (default): separate routes for each operation
|
|
36
|
+
* - `"single-route"`: single POST endpoint with JSON envelope dispatch
|
|
37
|
+
*/
|
|
38
|
+
mode?: "multi-route" | "single-route";
|
|
30
39
|
/**
|
|
31
40
|
* Optional CORS configuration. When not provided, defaults to allowing all origins without credentials.
|
|
32
41
|
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
33
42
|
*/
|
|
34
43
|
cors?: CopilotEndpointCorsConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Lifecycle hooks for request processing.
|
|
46
|
+
*/
|
|
47
|
+
hooks?: CopilotRuntimeHooks;
|
|
35
48
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
declare function createCopilotEndpoint({
|
|
49
|
+
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
50
|
+
declare const createCopilotEndpoint: typeof createCopilotHonoHandler;
|
|
51
|
+
declare function createCopilotHonoHandler({
|
|
42
52
|
runtime,
|
|
43
53
|
basePath,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
agentId: string;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
output: {};
|
|
54
|
-
outputFormat: string;
|
|
55
|
-
status: hono_utils_http_status0.StatusCode;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
} & {
|
|
59
|
-
[x: `${string}/agent/:agentId/connect`]: {
|
|
60
|
-
$post: {
|
|
61
|
-
input: {
|
|
62
|
-
param: {
|
|
63
|
-
agentId: string;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
output: {};
|
|
67
|
-
outputFormat: string;
|
|
68
|
-
status: hono_utils_http_status0.StatusCode;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
} & {
|
|
72
|
-
[x: `${string}/agent/:agentId/stop/:threadId`]: {
|
|
73
|
-
$post: {
|
|
74
|
-
input: {
|
|
75
|
-
param: {
|
|
76
|
-
agentId: string;
|
|
77
|
-
} & {
|
|
78
|
-
threadId: string;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
output: {};
|
|
82
|
-
outputFormat: string;
|
|
83
|
-
status: hono_utils_http_status0.StatusCode;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
} & {
|
|
87
|
-
[x: `${string}/info`]: {
|
|
88
|
-
$get: {
|
|
89
|
-
input: {};
|
|
90
|
-
output: {};
|
|
91
|
-
outputFormat: string;
|
|
92
|
-
status: hono_utils_http_status0.StatusCode;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
} & {
|
|
96
|
-
[x: `${string}/transcribe`]: {
|
|
97
|
-
$post: {
|
|
54
|
+
mode,
|
|
55
|
+
cors: corsConfig,
|
|
56
|
+
hooks
|
|
57
|
+
}: CopilotEndpointParams): hono_hono_base0.HonoBase<hono_types0.BlankEnv, {
|
|
58
|
+
[x: `${string}/*`]: {
|
|
59
|
+
$all: {
|
|
98
60
|
input: {};
|
|
99
61
|
output: {};
|
|
100
62
|
outputFormat: string;
|
|
101
63
|
status: hono_utils_http_status0.StatusCode;
|
|
102
64
|
};
|
|
103
65
|
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
outputFormat: string;
|
|
110
|
-
status: hono_utils_http_status0.StatusCode;
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
} & {
|
|
114
|
-
[x: `${string}/threads/subscribe`]: {
|
|
115
|
-
$post: {
|
|
116
|
-
input: {};
|
|
117
|
-
output: {};
|
|
118
|
-
outputFormat: string;
|
|
119
|
-
status: hono_utils_http_status0.StatusCode;
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
} & {
|
|
123
|
-
[x: `${string}/threads/:threadId`]: {
|
|
124
|
-
$patch: {
|
|
125
|
-
input: {
|
|
126
|
-
param: {
|
|
127
|
-
threadId: string;
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
|
-
output: {};
|
|
131
|
-
outputFormat: string;
|
|
132
|
-
status: hono_utils_http_status0.StatusCode;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
} & {
|
|
136
|
-
[x: `${string}/threads/:threadId/archive`]: {
|
|
137
|
-
$post: {
|
|
138
|
-
input: {
|
|
139
|
-
param: {
|
|
140
|
-
threadId: string;
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
output: {};
|
|
144
|
-
outputFormat: string;
|
|
145
|
-
status: hono_utils_http_status0.StatusCode;
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
} & {
|
|
149
|
-
[x: `${string}/threads/:threadId`]: {
|
|
150
|
-
$delete: {
|
|
151
|
-
input: {
|
|
152
|
-
param: {
|
|
153
|
-
threadId: string;
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
output: {};
|
|
157
|
-
outputFormat: string;
|
|
158
|
-
status: hono_utils_http_status0.StatusCode;
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
}, string, `${string}/threads/:threadId`>;
|
|
66
|
+
}, string, `${string}/*`>;
|
|
67
|
+
/**
|
|
68
|
+
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
69
|
+
*/
|
|
70
|
+
declare function toFetchCorsConfig(config: CopilotEndpointCorsConfig): CopilotCorsConfig;
|
|
162
71
|
//#endregion
|
|
163
|
-
export { CopilotEndpointCorsConfig, createCopilotEndpoint };
|
|
72
|
+
export { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
|
|
164
73
|
//# 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":";;;;;;;;;;;;;UAUiB,yBAAA;EAAA;;;;;;;;EASf,MAAA,wBAGM,MAAA,UAAgB,CAAA;EAKX;AACZ;;;EADC,WAAA;AAAA;AAAA,UAGQ,qBAAA;EACR,OAAA,EAAS,kBAAA;EACT,QAAA;EADA;;;;;EAQA,IAAA;EAUA;;;;EAJA,IAAA,GAAO,yBAAA;EAOoD;;;EAH3D,KAAA,GAAQ,mBAAA;AAAA;;cAGG,qBAAA,SAAqB,wBAAA;AAAA,iBAElB,wBAAA,CAAA;EACd,OAAA;EACA,QAAA;EACA,IAAA;EACA,IAAA,EAAM,UAAA;EACN;AAAA,GACC,qBAAA,mBAAqB,QAAA,CAAA,WAAA,CAAA,QAAA;EAAA;;;;;cAAA,uBAAA,CAAA,UAAA;IAAA;EAAA;AAAA;;;;iBAiBR,iBAAA,CACd,MAAA,EAAQ,yBAAA,GACP,iBAAA"}
|
|
@@ -1,247 +1,31 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import
|
|
3
|
-
import { handleRunAgent } from "../handlers/handle-run.mjs";
|
|
4
|
-
import { handleGetRuntimeInfo } from "../handlers/get-runtime-info.mjs";
|
|
5
|
-
import { handleTranscribe } from "../handlers/handle-transcribe.mjs";
|
|
6
|
-
import { callAfterRequestMiddleware, callBeforeRequestMiddleware } from "../middleware.mjs";
|
|
7
|
-
import { handleConnectAgent } from "../handlers/handle-connect.mjs";
|
|
8
|
-
import { handleStopAgent } from "../handlers/handle-stop.mjs";
|
|
9
|
-
import { handleArchiveThread, handleDeleteThread, handleListThreads, handleSubscribeToThreads, handleUpdateThread } from "../handlers/intelligence/threads.mjs";
|
|
10
|
-
import { getLicenseWarningHeader, logger } from "@copilotkit/shared";
|
|
2
|
+
import { createCopilotRuntimeHandler } from "../core/fetch-handler.mjs";
|
|
11
3
|
import { Hono } from "hono";
|
|
12
|
-
import { cors } from "hono/cors";
|
|
13
4
|
|
|
14
5
|
//#region src/v2/runtime/endpoints/hono.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
}).catch(() => {});
|
|
26
|
-
return app.basePath(basePath).use("*", cors({
|
|
27
|
-
origin: corsConfig?.origin ?? "*",
|
|
28
|
-
allowMethods: [
|
|
29
|
-
"GET",
|
|
30
|
-
"HEAD",
|
|
31
|
-
"PUT",
|
|
32
|
-
"POST",
|
|
33
|
-
"DELETE",
|
|
34
|
-
"PATCH",
|
|
35
|
-
"OPTIONS"
|
|
36
|
-
],
|
|
37
|
-
allowHeaders: ["*"],
|
|
38
|
-
credentials: corsConfig?.credentials ?? false
|
|
39
|
-
})).use("*", async (c, next) => {
|
|
40
|
-
const request = c.req.raw;
|
|
41
|
-
const path = c.req.path;
|
|
42
|
-
try {
|
|
43
|
-
const maybeModifiedRequest = await callBeforeRequestMiddleware({
|
|
44
|
-
runtime,
|
|
45
|
-
request,
|
|
46
|
-
path
|
|
47
|
-
});
|
|
48
|
-
if (maybeModifiedRequest) c.set("modifiedRequest", maybeModifiedRequest);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
logger.error({
|
|
51
|
-
err: error,
|
|
52
|
-
url: request.url,
|
|
53
|
-
path
|
|
54
|
-
}, "Error running before request middleware");
|
|
55
|
-
if (error instanceof Response) return error;
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
const warning = getLicenseWarningHeader(runtime.licenseChecker);
|
|
59
|
-
if (warning) c.header(warning.key, warning.value);
|
|
60
|
-
await next();
|
|
61
|
-
}).use("*", async (c, next) => {
|
|
62
|
-
await next();
|
|
63
|
-
const response = c.res.clone();
|
|
64
|
-
const path = c.req.path;
|
|
65
|
-
callAfterRequestMiddleware({
|
|
66
|
-
runtime,
|
|
67
|
-
response,
|
|
68
|
-
path
|
|
69
|
-
}).catch((error) => {
|
|
70
|
-
logger.error({
|
|
71
|
-
err: error,
|
|
72
|
-
url: c.req.url,
|
|
73
|
-
path
|
|
74
|
-
}, "Error running after request middleware");
|
|
75
|
-
});
|
|
76
|
-
}).post("/agent/:agentId/run", async (c) => {
|
|
77
|
-
const agentId = c.req.param("agentId");
|
|
78
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
79
|
-
try {
|
|
80
|
-
return await handleRunAgent({
|
|
81
|
-
runtime,
|
|
82
|
-
request,
|
|
83
|
-
agentId
|
|
84
|
-
});
|
|
85
|
-
} catch (error) {
|
|
86
|
-
logger.error({
|
|
87
|
-
err: error,
|
|
88
|
-
url: request.url,
|
|
89
|
-
path: c.req.path
|
|
90
|
-
}, "Error running request handler");
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
}).post("/agent/:agentId/connect", async (c) => {
|
|
94
|
-
const agentId = c.req.param("agentId");
|
|
95
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
96
|
-
try {
|
|
97
|
-
return await handleConnectAgent({
|
|
98
|
-
runtime,
|
|
99
|
-
request,
|
|
100
|
-
agentId
|
|
101
|
-
});
|
|
102
|
-
} catch (error) {
|
|
103
|
-
logger.error({
|
|
104
|
-
err: error,
|
|
105
|
-
url: request.url,
|
|
106
|
-
path: c.req.path
|
|
107
|
-
}, "Error running request handler");
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
}).post("/agent/:agentId/stop/:threadId", async (c) => {
|
|
111
|
-
const agentId = c.req.param("agentId");
|
|
112
|
-
const threadId = c.req.param("threadId");
|
|
113
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
114
|
-
try {
|
|
115
|
-
return await handleStopAgent({
|
|
116
|
-
runtime,
|
|
117
|
-
request,
|
|
118
|
-
agentId,
|
|
119
|
-
threadId
|
|
120
|
-
});
|
|
121
|
-
} catch (error) {
|
|
122
|
-
logger.error({
|
|
123
|
-
err: error,
|
|
124
|
-
url: request.url,
|
|
125
|
-
path: c.req.path
|
|
126
|
-
}, "Error running request handler");
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}).get("/info", async (c) => {
|
|
130
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
131
|
-
try {
|
|
132
|
-
return await handleGetRuntimeInfo({
|
|
133
|
-
runtime,
|
|
134
|
-
request
|
|
135
|
-
});
|
|
136
|
-
} catch (error) {
|
|
137
|
-
logger.error({
|
|
138
|
-
err: error,
|
|
139
|
-
url: request.url,
|
|
140
|
-
path: c.req.path
|
|
141
|
-
}, "Error running request handler");
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
}).post("/transcribe", async (c) => {
|
|
145
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
146
|
-
try {
|
|
147
|
-
return await handleTranscribe({
|
|
148
|
-
runtime,
|
|
149
|
-
request
|
|
150
|
-
});
|
|
151
|
-
} catch (error) {
|
|
152
|
-
logger.error({
|
|
153
|
-
err: error,
|
|
154
|
-
url: request.url,
|
|
155
|
-
path: c.req.path
|
|
156
|
-
}, "Error running request handler");
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
}).get("/threads", async (c) => {
|
|
160
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
161
|
-
try {
|
|
162
|
-
return await handleListThreads({
|
|
163
|
-
runtime,
|
|
164
|
-
request
|
|
165
|
-
});
|
|
166
|
-
} catch (error) {
|
|
167
|
-
logger.error({
|
|
168
|
-
err: error,
|
|
169
|
-
url: request.url,
|
|
170
|
-
path: c.req.path
|
|
171
|
-
}, "Error running request handler");
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
}).post("/threads/subscribe", async (c) => {
|
|
175
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
176
|
-
try {
|
|
177
|
-
return await handleSubscribeToThreads({
|
|
178
|
-
runtime,
|
|
179
|
-
request
|
|
180
|
-
});
|
|
181
|
-
} catch (error) {
|
|
182
|
-
logger.error({
|
|
183
|
-
err: error,
|
|
184
|
-
url: request.url,
|
|
185
|
-
path: c.req.path
|
|
186
|
-
}, "Error running request handler");
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
}).patch("/threads/:threadId", async (c) => {
|
|
190
|
-
const threadId = c.req.param("threadId");
|
|
191
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
192
|
-
try {
|
|
193
|
-
return await handleUpdateThread({
|
|
194
|
-
runtime,
|
|
195
|
-
request,
|
|
196
|
-
threadId
|
|
197
|
-
});
|
|
198
|
-
} catch (error) {
|
|
199
|
-
logger.error({
|
|
200
|
-
err: error,
|
|
201
|
-
url: request.url,
|
|
202
|
-
path: c.req.path
|
|
203
|
-
}, "Error running request handler");
|
|
204
|
-
throw error;
|
|
205
|
-
}
|
|
206
|
-
}).post("/threads/:threadId/archive", async (c) => {
|
|
207
|
-
const threadId = c.req.param("threadId");
|
|
208
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
209
|
-
try {
|
|
210
|
-
return await handleArchiveThread({
|
|
211
|
-
runtime,
|
|
212
|
-
request,
|
|
213
|
-
threadId
|
|
214
|
-
});
|
|
215
|
-
} catch (error) {
|
|
216
|
-
logger.error({
|
|
217
|
-
err: error,
|
|
218
|
-
url: request.url,
|
|
219
|
-
path: c.req.path
|
|
220
|
-
}, "Error running request handler");
|
|
221
|
-
throw error;
|
|
222
|
-
}
|
|
223
|
-
}).delete("/threads/:threadId", async (c) => {
|
|
224
|
-
const threadId = c.req.param("threadId");
|
|
225
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
226
|
-
try {
|
|
227
|
-
return await handleDeleteThread({
|
|
228
|
-
runtime,
|
|
229
|
-
request,
|
|
230
|
-
threadId
|
|
231
|
-
});
|
|
232
|
-
} catch (error) {
|
|
233
|
-
logger.error({
|
|
234
|
-
err: error,
|
|
235
|
-
url: request.url,
|
|
236
|
-
path: c.req.path
|
|
237
|
-
}, "Error running request handler");
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
}).notFound((c) => {
|
|
241
|
-
return c.json({ error: "Not found" }, 404);
|
|
6
|
+
/** @deprecated Use `createCopilotHonoHandler` instead. */
|
|
7
|
+
const createCopilotEndpoint = createCopilotHonoHandler;
|
|
8
|
+
function createCopilotHonoHandler({ runtime, basePath, mode = "multi-route", cors: corsConfig, hooks }) {
|
|
9
|
+
const handler = createCopilotRuntimeHandler({
|
|
10
|
+
runtime,
|
|
11
|
+
basePath,
|
|
12
|
+
mode,
|
|
13
|
+
cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
|
|
14
|
+
hooks
|
|
242
15
|
});
|
|
16
|
+
return new Hono().basePath(basePath).all("*", async (c) => handler(c.req.raw));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.
|
|
20
|
+
*/
|
|
21
|
+
function toFetchCorsConfig(config) {
|
|
22
|
+
const origin = config.origin;
|
|
23
|
+
return {
|
|
24
|
+
origin: typeof origin === "function" ? (reqOrigin) => origin(reqOrigin, void 0) ?? null : origin,
|
|
25
|
+
credentials: config.credentials
|
|
26
|
+
};
|
|
243
27
|
}
|
|
244
28
|
|
|
245
29
|
//#endregion
|
|
246
|
-
export { createCopilotEndpoint };
|
|
30
|
+
export { createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig };
|
|
247
31
|
//# sourceMappingURL=hono.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/hono.ts"],"sourcesContent":["import { Hono } from \"hono\";\nimport { cors } from \"hono/cors\";\nimport { CopilotRuntimeLike } from \"../runtime\";\nimport { telemetry } from \"../telemetry\";\nimport { handleRunAgent } from \"../handlers/handle-run\";\nimport { handleGetRuntimeInfo } from \"../handlers/get-runtime-info\";\nimport { handleTranscribe } from \"../handlers/handle-transcribe\";\nimport { logger, getLicenseWarningHeader } from \"@copilotkit/shared\";\nimport {\n callBeforeRequestMiddleware,\n callAfterRequestMiddleware,\n} from \"../middleware\";\nimport { handleConnectAgent } from \"../handlers/handle-connect\";\nimport { handleStopAgent } from \"../handlers/handle-stop\";\nimport {\n handleListThreads,\n handleSubscribeToThreads,\n handleUpdateThread,\n handleArchiveThread,\n handleDeleteThread,\n} from \"../handlers/handle-threads\";\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 * 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 // Fire instance_created telemetry - resolve agents if needed\n Promise.resolve(runtime.agents)\n .then((agents) => {\n telemetry.capture(\"oss.runtime.instance_created\", {\n actionsAmount: 0,\n endpointTypes: [],\n endpointsAmount: 0,\n agentsAmount: Object.keys(agents).length,\n \"cloud.api_key_provided\": false,\n });\n })\n .catch(() => {\n // Silently fail - telemetry should not break the application\n });\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 const warning = getLicenseWarningHeader(runtime.licenseChecker);\n if (warning) c.header(warning.key, warning.value);\n\n await next();\n })\n .use(\"*\", async (c, next) => {\n await next();\n\n const response = c.res.clone();\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 .get(\"/threads\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleListThreads({ runtime, request });\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(\"/threads/subscribe\", async (c) => {\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleSubscribeToThreads({ runtime, request });\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 .patch(\"/threads/:threadId\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleUpdateThread({ runtime, request, threadId });\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(\"/threads/:threadId/archive\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleArchiveThread({ runtime, request, threadId });\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 .delete(\"/threads/:threadId\", async (c) => {\n const threadId = c.req.param(\"threadId\");\n const request = c.get(\"modifiedRequest\") || c.req.raw;\n\n try {\n return await handleDeleteThread({ runtime, request, threadId });\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":"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"}
|
|
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 return app.basePath(basePath).all(\"*\", async (c) => handler(c.req.raw));\n}\n\n/**\n * Convert Hono-specific CORS config to the fetch handler's CopilotCorsConfig.\n */\nexport function toFetchCorsConfig(\n config: CopilotEndpointCorsConfig,\n): CopilotCorsConfig {\n const origin = config.origin;\n return {\n origin:\n typeof origin === \"function\"\n ? (reqOrigin: string) => origin(reqOrigin, undefined) ?? null\n : origin,\n credentials: config.credentials,\n };\n}\n"],"mappings":";;;;;;AAoDA,MAAa,wBAAwB;AAErC,SAAgB,yBAAyB,EACvC,SACA,UACA,OAAO,eACP,MAAM,YACN,SACwB;CACxB,MAAM,UAAU,4BAA4B;EAC1C;EACA;EACA;EACA,MAAM,aAAa,kBAAkB,WAAW,GAAG;EACnD;EACD,CAAC;AAIF,QAFY,IAAI,MAAM,CAEX,SAAS,SAAS,CAAC,IAAI,KAAK,OAAO,MAAM,QAAQ,EAAE,IAAI,IAAI,CAAC;;;;;AAMzE,SAAgB,kBACd,QACmB;CACnB,MAAM,SAAS,OAAO;AACtB,QAAO;EACL,QACE,OAAO,WAAW,cACb,cAAsB,OAAO,WAAW,OAAU,IAAI,OACvD;EACN,aAAa,OAAO;EACrB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { CopilotEndpointCorsConfig, createCopilotEndpoint } from "./hono.cjs";
|
|
2
|
+
import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.cjs";
|
|
3
3
|
import { createCopilotEndpointSingleRoute } from "./hono-single.cjs";
|
|
4
|
-
import {
|
|
4
|
+
import { CopilotExpressEndpointParams, 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 } from "./hono.mjs";
|
|
2
|
+
import { CopilotEndpointCorsConfig, createCopilotEndpoint, createCopilotHonoHandler, toFetchCorsConfig } from "./hono.mjs";
|
|
3
3
|
import { createCopilotEndpointSingleRoute } from "./hono-single.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { CopilotExpressEndpointParams, createCopilotExpressHandler } from "./express.mjs";
|
|
5
5
|
import { createCopilotEndpointSingleRouteExpress } from "./express-single.mjs";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _copilotkit_shared = require("@copilotkit/shared");
|
|
4
|
+
let _remix_run_node_fetch_server = require("@remix-run/node-fetch-server");
|
|
5
|
+
|
|
6
|
+
//#region src/v2/runtime/endpoints/node-fetch-handler.ts
|
|
7
|
+
function createCopilotNodeHandler(handler) {
|
|
8
|
+
return async (req, res) => {
|
|
9
|
+
try {
|
|
10
|
+
await (0, _remix_run_node_fetch_server.sendResponse)(res, await handler((0, _remix_run_node_fetch_server.createRequest)(req, res)));
|
|
11
|
+
} catch (err) {
|
|
12
|
+
_copilotkit_shared.logger.error({ err }, "Error in Node fetch handler");
|
|
13
|
+
if (!res.headersSent) {
|
|
14
|
+
res.statusCode = 500;
|
|
15
|
+
res.end("Internal Server Error");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
21
|
+
const createNodeFetchHandler = createCopilotNodeHandler;
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.createCopilotNodeHandler = createCopilotNodeHandler;
|
|
25
|
+
exports.createNodeFetchHandler = createNodeFetchHandler;
|
|
26
|
+
//# sourceMappingURL=node-fetch-handler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.cjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/v2/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { createRequest, sendResponse } from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const fetchReq = createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n/** @deprecated Use `createCopilotNodeHandler` instead. */\nexport const createNodeFetchHandler = createCopilotNodeHandler;\n"],"mappings":";;;;;;AA4BA,SAAgB,yBACd,SACkB;AAClB,QAAO,OAAO,KAAsB,QAAwB;AAC1D,MAAI;AAGF,wDAAmB,KADF,MAAM,wDADQ,KAAK,IAAI,CACA,CACP;WAC1B,KAAc;AACrB,6BAAO,MAAM,EAAE,KAAK,EAAE,8BAA8B;AACpD,OAAI,CAAC,IAAI,aAAa;AACpB,QAAI,aAAa;AACjB,QAAI,IAAI,wBAAwB;;;;;;AAOxC,MAAa,yBAAyB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
import { CopilotRuntimeFetchHandler } from "../core/fetch-handler.cjs";
|
|
3
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
|
|
5
|
+
//#region src/v2/runtime/endpoints/node-fetch-handler.d.ts
|
|
6
|
+
type NodeFetchHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
7
|
+
declare function createCopilotNodeHandler(handler: CopilotRuntimeFetchHandler): NodeFetchHandler;
|
|
8
|
+
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
9
|
+
declare const createNodeFetchHandler: typeof createCopilotNodeHandler;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { NodeFetchHandler, createCopilotNodeHandler, createNodeFetchHandler };
|
|
12
|
+
//# sourceMappingURL=node-fetch-handler.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.d.cts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node-fetch-handler.ts"],"mappings":";;;;;KAuBY,gBAAA,IACV,GAAA,EAAK,eAAA,EACL,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,iBAEW,wBAAA,CACd,OAAA,EAAS,0BAAA,GACR,gBAAA;;cAiBU,sBAAA,SAAsB,wBAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { CopilotRuntimeFetchHandler } from "../core/fetch-handler.mjs";
|
|
3
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
|
|
5
|
+
//#region src/v2/runtime/endpoints/node-fetch-handler.d.ts
|
|
6
|
+
type NodeFetchHandler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
7
|
+
declare function createCopilotNodeHandler(handler: CopilotRuntimeFetchHandler): NodeFetchHandler;
|
|
8
|
+
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
9
|
+
declare const createNodeFetchHandler: typeof createCopilotNodeHandler;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { NodeFetchHandler, createCopilotNodeHandler, createNodeFetchHandler };
|
|
12
|
+
//# sourceMappingURL=node-fetch-handler.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.d.mts","names":[],"sources":["../../../../src/v2/runtime/endpoints/node-fetch-handler.ts"],"mappings":";;;;;KAuBY,gBAAA,IACV,GAAA,EAAK,eAAA,EACL,GAAA,EAAK,cAAA,KACF,OAAA;AAAA,iBAEW,wBAAA,CACd,OAAA,EAAS,0BAAA,GACR,gBAAA;;cAiBU,sBAAA,SAAsB,wBAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { logger } from "@copilotkit/shared";
|
|
3
|
+
import { createRequest, sendResponse } from "@remix-run/node-fetch-server";
|
|
4
|
+
|
|
5
|
+
//#region src/v2/runtime/endpoints/node-fetch-handler.ts
|
|
6
|
+
function createCopilotNodeHandler(handler) {
|
|
7
|
+
return async (req, res) => {
|
|
8
|
+
try {
|
|
9
|
+
await sendResponse(res, await handler(createRequest(req, res)));
|
|
10
|
+
} catch (err) {
|
|
11
|
+
logger.error({ err }, "Error in Node fetch handler");
|
|
12
|
+
if (!res.headersSent) {
|
|
13
|
+
res.statusCode = 500;
|
|
14
|
+
res.end("Internal Server Error");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** @deprecated Use `createCopilotNodeHandler` instead. */
|
|
20
|
+
const createNodeFetchHandler = createCopilotNodeHandler;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createCopilotNodeHandler, createNodeFetchHandler };
|
|
24
|
+
//# sourceMappingURL=node-fetch-handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-fetch-handler.mjs","names":[],"sources":["../../../../src/v2/runtime/endpoints/node-fetch-handler.ts"],"sourcesContent":["/**\n * Generic Node ↔ Fetch bridge for CopilotKit runtime.\n *\n * Wraps a `CopilotRuntimeFetchHandler` as a Node HTTP handler using\n * `@remix-run/node-fetch-server` for reliable streaming and conversion.\n *\n * @example\n * ```typescript\n * import { createServer } from \"node:http\";\n * import { createCopilotRuntimeHandler } from \"@copilotkit/runtime/v2\";\n * import { createCopilotNodeHandler } from \"@copilotkit/runtime/v2/node\";\n *\n * const handler = createCopilotRuntimeHandler({ runtime, basePath: \"/api/copilotkit\", cors: true });\n * const nodeHandler = createCopilotNodeHandler(handler);\n * createServer(nodeHandler).listen(3000);\n * ```\n */\n\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { createRequest, sendResponse } from \"@remix-run/node-fetch-server\";\nimport type { CopilotRuntimeFetchHandler } from \"../core/fetch-handler\";\nimport { logger } from \"@copilotkit/shared\";\n\nexport type NodeFetchHandler = (\n req: IncomingMessage,\n res: ServerResponse,\n) => Promise<void>;\n\nexport function createCopilotNodeHandler(\n handler: CopilotRuntimeFetchHandler,\n): NodeFetchHandler {\n return async (req: IncomingMessage, res: ServerResponse) => {\n try {\n const fetchReq = createRequest(req, res);\n const fetchRes = await handler(fetchReq);\n await sendResponse(res, fetchRes);\n } catch (err: unknown) {\n logger.error({ err }, \"Error in Node fetch handler\");\n if (!res.headersSent) {\n res.statusCode = 500;\n res.end(\"Internal Server Error\");\n }\n }\n };\n}\n\n/** @deprecated Use `createCopilotNodeHandler` instead. */\nexport const createNodeFetchHandler = createCopilotNodeHandler;\n"],"mappings":";;;;;AA4BA,SAAgB,yBACd,SACkB;AAClB,QAAO,OAAO,KAAsB,QAAwB;AAC1D,MAAI;AAGF,SAAM,aAAa,KADF,MAAM,QADN,cAAc,KAAK,IAAI,CACA,CACP;WAC1B,KAAc;AACrB,UAAO,MAAM,EAAE,KAAK,EAAE,8BAA8B;AACpD,OAAI,CAAC,IAAI,aAAa;AACpB,QAAI,aAAa;AACjB,QAAI,IAAI,wBAAwB;;;;;;AAOxC,MAAa,yBAAyB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require("reflect-metadata");
|
|
2
|
+
const require_fetch_handler = require('../core/fetch-handler.cjs');
|
|
3
|
+
const require_node_fetch_handler = require('./node-fetch-handler.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/v2/runtime/endpoints/node.ts
|
|
6
|
+
/**
|
|
7
|
+
* Convenience wrapper for creating a Node.js HTTP request listener
|
|
8
|
+
* from CopilotKit runtime handler options.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createServer } from "node:http";
|
|
13
|
+
* import { CopilotRuntime } from "@copilotkit/runtime/v2";
|
|
14
|
+
* import { createCopilotNodeListener } from "@copilotkit/runtime/v2/node";
|
|
15
|
+
*
|
|
16
|
+
* const listener = createCopilotNodeListener({
|
|
17
|
+
* runtime: new CopilotRuntime({ agents: { ... } }),
|
|
18
|
+
* basePath: "/api/copilotkit",
|
|
19
|
+
* cors: true,
|
|
20
|
+
* });
|
|
21
|
+
* createServer(listener).listen(3000);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function createCopilotNodeListener(options) {
|
|
25
|
+
return require_node_fetch_handler.createCopilotNodeHandler(require_fetch_handler.createCopilotRuntimeHandler(options));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.createCopilotNodeListener = createCopilotNodeListener;
|
|
30
|
+
//# sourceMappingURL=node.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.cjs","names":["createCopilotNodeHandler","createCopilotRuntimeHandler"],"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): NodeFetchHandler {\n const handler = createCopilotRuntimeHandler(options);\n return createCopilotNodeHandler(handler);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,0BACd,SACkB;AAElB,QAAOA,oDADSC,kDAA4B,QAAQ,CACZ"}
|