@copilotkit/runtime 1.55.0-next.8 → 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 +28 -0
- 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 +25 -23
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +25 -23
- 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
|
@@ -6,240 +6,154 @@ import type {
|
|
|
6
6
|
Router,
|
|
7
7
|
} from "express";
|
|
8
8
|
import cors from "cors";
|
|
9
|
+
import type { CorsOptions } from "cors";
|
|
10
|
+
import type { CopilotRuntimeLike } from "../core/runtime";
|
|
11
|
+
import { createCopilotRuntimeHandler } from "../core/fetch-handler";
|
|
12
|
+
import { createExpressNodeHandler } from "./express-fetch-bridge";
|
|
13
|
+
import type { CopilotRuntimeHooks } from "../core/hooks";
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
import { telemetry } from "../telemetry";
|
|
12
|
-
import { handleRunAgent } from "../handlers/handle-run";
|
|
13
|
-
import { handleConnectAgent } from "../handlers/handle-connect";
|
|
14
|
-
import { handleStopAgent } from "../handlers/handle-stop";
|
|
15
|
-
import { handleGetRuntimeInfo } from "../handlers/get-runtime-info";
|
|
16
|
-
import { handleTranscribe } from "../handlers/handle-transcribe";
|
|
17
|
-
import {
|
|
18
|
-
handleListThreads,
|
|
19
|
-
handleSubscribeToThreads,
|
|
20
|
-
handleUpdateThread,
|
|
21
|
-
handleArchiveThread,
|
|
22
|
-
handleDeleteThread,
|
|
23
|
-
} from "../handlers/handle-threads";
|
|
24
|
-
import { logger, getLicenseWarningHeader } from "@copilotkit/shared";
|
|
25
|
-
import {
|
|
26
|
-
callBeforeRequestMiddleware,
|
|
27
|
-
callAfterRequestMiddleware,
|
|
28
|
-
} from "../middleware";
|
|
29
|
-
import {
|
|
30
|
-
createFetchRequestFromExpress,
|
|
31
|
-
sendFetchResponse,
|
|
32
|
-
} from "./express-utils";
|
|
33
|
-
|
|
34
|
-
interface CopilotExpressEndpointParams {
|
|
15
|
+
export interface CopilotExpressEndpointParams {
|
|
35
16
|
runtime: CopilotRuntimeLike;
|
|
36
17
|
basePath: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Endpoint mode.
|
|
21
|
+
* - `"multi-route"` (default): separate routes for each operation
|
|
22
|
+
* - `"single-route"`: single POST endpoint with JSON envelope dispatch
|
|
23
|
+
*/
|
|
24
|
+
mode?: "multi-route" | "single-route";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* CORS configuration for the Express router.
|
|
28
|
+
* - `true` (default): permissive CORS (`origin: "*"`, all methods, all headers).
|
|
29
|
+
* - `false`: no CORS middleware is applied — handle it yourself.
|
|
30
|
+
* - object: passed directly to the Express `cors()` middleware.
|
|
31
|
+
*/
|
|
32
|
+
cors?: boolean | CorsOptions;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Lifecycle hooks for request processing.
|
|
36
|
+
*/
|
|
37
|
+
hooks?: CopilotRuntimeHooks;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Creates an Express router that serves the CopilotKit runtime.
|
|
42
|
+
*
|
|
43
|
+
* In **multi-route** mode (default) the router exposes:
|
|
44
|
+
* - `GET {basePath}/info` — runtime info
|
|
45
|
+
* - `POST {basePath}/agent/:agentId/run` — start an agent run
|
|
46
|
+
* - `POST {basePath}/agent/:agentId/connect` — connect to an agent run
|
|
47
|
+
* - `POST {basePath}/agent/:agentId/stop/:threadId` — stop an agent run
|
|
48
|
+
* - `POST {basePath}/transcribe` — transcribe audio
|
|
49
|
+
*
|
|
50
|
+
* In **single-route** mode a single `POST {basePath}` endpoint accepts a JSON
|
|
51
|
+
* envelope `{ method, params, body }` and dispatches to the appropriate handler.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import express from "express";
|
|
56
|
+
* import { CopilotRuntime } from "@copilotkit/runtime/v2";
|
|
57
|
+
* import { createCopilotExpressHandler } from "@copilotkit/runtime/v2/express";
|
|
58
|
+
*
|
|
59
|
+
* const runtime = new CopilotRuntime({
|
|
60
|
+
* agents: { default: new BuiltInAgent({ model: "openai/gpt-4o-mini" }) },
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const app = express();
|
|
64
|
+
* app.use(createCopilotExpressHandler({
|
|
65
|
+
* runtime,
|
|
66
|
+
* basePath: "/api/copilotkit",
|
|
67
|
+
* cors: true,
|
|
68
|
+
* }));
|
|
69
|
+
* app.listen(4000);
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Single-route mode with lifecycle hooks
|
|
73
|
+
* ```typescript
|
|
74
|
+
* app.use(createCopilotExpressHandler({
|
|
75
|
+
* runtime,
|
|
76
|
+
* basePath: "/api/copilotkit",
|
|
77
|
+
* mode: "single-route",
|
|
78
|
+
* hooks: {
|
|
79
|
+
* onRequest: ({ request }) => {
|
|
80
|
+
* if (!request.headers.get("authorization")) {
|
|
81
|
+
* throw new Response("Unauthorized", { status: 401 });
|
|
82
|
+
* }
|
|
83
|
+
* },
|
|
84
|
+
* },
|
|
85
|
+
* }));
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
/** @deprecated Use `createCopilotExpressHandler` instead. */
|
|
89
|
+
export { createCopilotExpressHandler as createCopilotEndpointExpress };
|
|
90
|
+
|
|
91
|
+
export function createCopilotExpressHandler({
|
|
40
92
|
runtime,
|
|
41
93
|
basePath,
|
|
94
|
+
mode = "multi-route",
|
|
95
|
+
cors: corsOption = true,
|
|
96
|
+
hooks,
|
|
42
97
|
}: CopilotExpressEndpointParams): Router {
|
|
43
|
-
const router = express.Router();
|
|
44
98
|
const normalizedBase = normalizeBasePath(basePath);
|
|
45
99
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
endpointsAmount: 0,
|
|
53
|
-
agentsAmount: Object.keys(agents).length,
|
|
54
|
-
"cloud.api_key_provided": false,
|
|
55
|
-
});
|
|
56
|
-
})
|
|
57
|
-
.catch(() => {
|
|
58
|
-
// Silently fail - telemetry should not break the application
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
router.use(
|
|
62
|
-
cors({
|
|
63
|
-
origin: "*",
|
|
64
|
-
methods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH", "OPTIONS"],
|
|
65
|
-
allowedHeaders: ["*"],
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
router.post(
|
|
70
|
-
joinPath(normalizedBase, "/agent/:agentId/run"),
|
|
71
|
-
createRouteHandler(runtime, async ({ request, req }) => {
|
|
72
|
-
const agentId = req.params.agentId as string;
|
|
73
|
-
return handleRunAgent({ runtime, request, agentId });
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
router.post(
|
|
78
|
-
joinPath(normalizedBase, "/agent/:agentId/connect"),
|
|
79
|
-
createRouteHandler(runtime, async ({ request, req }) => {
|
|
80
|
-
const agentId = req.params.agentId as string;
|
|
81
|
-
return handleConnectAgent({ runtime, request, agentId });
|
|
82
|
-
}),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
router.post(
|
|
86
|
-
joinPath(normalizedBase, "/agent/:agentId/stop/:threadId"),
|
|
87
|
-
createRouteHandler(runtime, async ({ request, req }) => {
|
|
88
|
-
const agentId = req.params.agentId as string;
|
|
89
|
-
const threadId = req.params.threadId as string;
|
|
90
|
-
return handleStopAgent({ runtime, request, agentId, threadId });
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
router.get(
|
|
95
|
-
joinPath(normalizedBase, "/info"),
|
|
96
|
-
createRouteHandler(runtime, async ({ request }) => {
|
|
97
|
-
return handleGetRuntimeInfo({ runtime, request });
|
|
98
|
-
}),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
router.post(
|
|
102
|
-
joinPath(normalizedBase, "/transcribe"),
|
|
103
|
-
createRouteHandler(runtime, async ({ request }) => {
|
|
104
|
-
return handleTranscribe({ runtime, request });
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
router.get(
|
|
109
|
-
joinPath(normalizedBase, "/threads"),
|
|
110
|
-
createRouteHandler(runtime, async ({ request }) => {
|
|
111
|
-
return handleListThreads({ runtime, request });
|
|
112
|
-
}),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
router.post(
|
|
116
|
-
joinPath(normalizedBase, "/threads/subscribe"),
|
|
117
|
-
createRouteHandler(runtime, async ({ request }) => {
|
|
118
|
-
return handleSubscribeToThreads({ runtime, request });
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
router.patch(
|
|
123
|
-
joinPath(normalizedBase, "/threads/:threadId"),
|
|
124
|
-
createRouteHandler(runtime, async ({ request, req }) => {
|
|
125
|
-
const threadId = req.params.threadId as string;
|
|
126
|
-
return handleUpdateThread({ runtime, request, threadId });
|
|
127
|
-
}),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
router.post(
|
|
131
|
-
joinPath(normalizedBase, "/threads/:threadId/archive"),
|
|
132
|
-
createRouteHandler(runtime, async ({ request, req }) => {
|
|
133
|
-
const threadId = req.params.threadId as string;
|
|
134
|
-
return handleArchiveThread({ runtime, request, threadId });
|
|
135
|
-
}),
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
router.delete(
|
|
139
|
-
joinPath(normalizedBase, "/threads/:threadId"),
|
|
140
|
-
createRouteHandler(runtime, async ({ request, req }) => {
|
|
141
|
-
const threadId = req.params.threadId as string;
|
|
142
|
-
return handleDeleteThread({ runtime, request, threadId });
|
|
143
|
-
}),
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
router.use(joinPath(normalizedBase, "*"), (req, res) => {
|
|
147
|
-
res.status(404).json({ error: "Not found" });
|
|
100
|
+
const handler = createCopilotRuntimeHandler({
|
|
101
|
+
runtime,
|
|
102
|
+
basePath: normalizedBase,
|
|
103
|
+
mode,
|
|
104
|
+
cors: false, // CORS is handled at the Express middleware layer
|
|
105
|
+
hooks,
|
|
148
106
|
});
|
|
149
107
|
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
type RouteHandlerContext = {
|
|
154
|
-
request: Request;
|
|
155
|
-
req: ExpressRequest;
|
|
156
|
-
};
|
|
108
|
+
const nodeHandler = createExpressNodeHandler(handler);
|
|
157
109
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function createRouteHandler(
|
|
161
|
-
runtime: CopilotRuntimeLike,
|
|
162
|
-
factory: RouteHandlerFactory,
|
|
163
|
-
) {
|
|
164
|
-
return async (
|
|
110
|
+
const expressHandler = async (
|
|
165
111
|
req: ExpressRequest,
|
|
166
112
|
res: ExpressResponse,
|
|
167
113
|
next: NextFunction,
|
|
168
114
|
) => {
|
|
169
|
-
const path = req.originalUrl ?? req.path;
|
|
170
|
-
let request = createFetchRequestFromExpress(req);
|
|
171
|
-
|
|
172
|
-
const warning = getLicenseWarningHeader(runtime.licenseChecker);
|
|
173
|
-
if (warning) res.setHeader(warning.key, warning.value);
|
|
174
|
-
|
|
175
115
|
try {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
path,
|
|
180
|
-
});
|
|
181
|
-
if (maybeModifiedRequest) {
|
|
182
|
-
request = maybeModifiedRequest;
|
|
183
|
-
}
|
|
184
|
-
} catch (error) {
|
|
185
|
-
logger.error(
|
|
186
|
-
{ err: error, url: request.url, path },
|
|
187
|
-
"Error running before request middleware",
|
|
188
|
-
);
|
|
189
|
-
if (error instanceof Response) {
|
|
190
|
-
try {
|
|
191
|
-
await sendFetchResponse(res, error);
|
|
192
|
-
} catch (streamError) {
|
|
193
|
-
next(streamError);
|
|
194
|
-
}
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
next(error);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
const response = await factory({ request, req });
|
|
203
|
-
const responseForMiddleware = response.clone();
|
|
204
|
-
await sendFetchResponse(res, response);
|
|
205
|
-
callAfterRequestMiddleware({
|
|
206
|
-
runtime,
|
|
207
|
-
response: responseForMiddleware,
|
|
208
|
-
path,
|
|
209
|
-
}).catch((error) => {
|
|
210
|
-
logger.error(
|
|
211
|
-
{ err: error, url: req.originalUrl ?? req.url, path },
|
|
212
|
-
"Error running after request middleware",
|
|
213
|
-
);
|
|
214
|
-
});
|
|
215
|
-
} catch (error) {
|
|
216
|
-
if (error instanceof Response) {
|
|
217
|
-
const errorResponseForMiddleware = error.clone();
|
|
218
|
-
try {
|
|
219
|
-
await sendFetchResponse(res, error);
|
|
220
|
-
} catch (streamError) {
|
|
221
|
-
next(streamError);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
callAfterRequestMiddleware({
|
|
225
|
-
runtime,
|
|
226
|
-
response: errorResponseForMiddleware,
|
|
227
|
-
path,
|
|
228
|
-
}).catch((mwError) => {
|
|
229
|
-
logger.error(
|
|
230
|
-
{ err: mwError, url: req.originalUrl ?? req.url, path },
|
|
231
|
-
"Error running after request middleware",
|
|
232
|
-
);
|
|
233
|
-
});
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
logger.error(
|
|
237
|
-
{ err: error, url: request.url, path },
|
|
238
|
-
"Error running request handler",
|
|
239
|
-
);
|
|
240
|
-
next(error);
|
|
116
|
+
await nodeHandler(req, res);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
next(err);
|
|
241
119
|
}
|
|
242
120
|
};
|
|
121
|
+
|
|
122
|
+
const router = express.Router();
|
|
123
|
+
|
|
124
|
+
// CORS middleware
|
|
125
|
+
if (corsOption) {
|
|
126
|
+
const corsConfig: CorsOptions =
|
|
127
|
+
corsOption === true
|
|
128
|
+
? {
|
|
129
|
+
origin: "*",
|
|
130
|
+
methods: [
|
|
131
|
+
"GET",
|
|
132
|
+
"HEAD",
|
|
133
|
+
"PUT",
|
|
134
|
+
"POST",
|
|
135
|
+
"DELETE",
|
|
136
|
+
"PATCH",
|
|
137
|
+
"OPTIONS",
|
|
138
|
+
],
|
|
139
|
+
allowedHeaders: ["*"],
|
|
140
|
+
}
|
|
141
|
+
: corsOption;
|
|
142
|
+
router.use(cors(corsConfig));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Route mounting
|
|
146
|
+
if (mode === "single-route") {
|
|
147
|
+
router.post(normalizedBase, expressHandler);
|
|
148
|
+
router.options(normalizedBase, expressHandler);
|
|
149
|
+
} else if (normalizedBase === "/") {
|
|
150
|
+
router.all("*", expressHandler);
|
|
151
|
+
} else {
|
|
152
|
+
router.all(`${normalizedBase}/*`, expressHandler);
|
|
153
|
+
router.all(normalizedBase, expressHandler);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return router;
|
|
243
157
|
}
|
|
244
158
|
|
|
245
159
|
function normalizeBasePath(path: string): string {
|
|
@@ -257,19 +171,3 @@ function normalizeBasePath(path: string): string {
|
|
|
257
171
|
|
|
258
172
|
return path;
|
|
259
173
|
}
|
|
260
|
-
|
|
261
|
-
function joinPath(basePath: string, suffix: string): string {
|
|
262
|
-
if (basePath === "/") {
|
|
263
|
-
return suffix.startsWith("/") ? suffix : `/${suffix}`;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (!suffix) {
|
|
267
|
-
return basePath;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (suffix === "*") {
|
|
271
|
-
return `${basePath}/*`;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return `${basePath}${suffix.startsWith("/") ? suffix : `/${suffix}`}`;
|
|
275
|
-
}
|
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { handleConnectAgent } from "../handlers/handle-connect";
|
|
7
|
-
import { handleStopAgent } from "../handlers/handle-stop";
|
|
8
|
-
import { handleGetRuntimeInfo } from "../handlers/get-runtime-info";
|
|
9
|
-
import { handleTranscribe } from "../handlers/handle-transcribe";
|
|
10
|
-
import { logger } from "@copilotkit/shared";
|
|
11
|
-
import {
|
|
12
|
-
callBeforeRequestMiddleware,
|
|
13
|
-
callAfterRequestMiddleware,
|
|
14
|
-
} from "../middleware";
|
|
15
|
-
import {
|
|
16
|
-
createJsonRequest,
|
|
17
|
-
expectString,
|
|
18
|
-
MethodCall,
|
|
19
|
-
parseMethodCall,
|
|
20
|
-
} from "./single-route-helpers";
|
|
21
|
-
|
|
22
|
-
import { CopilotEndpointCorsConfig } from "./hono";
|
|
2
|
+
import type { CopilotRuntimeLike } from "../core/runtime";
|
|
3
|
+
import { createCopilotRuntimeHandler } from "../core/fetch-handler";
|
|
4
|
+
import type { CopilotRuntimeHooks } from "../core/hooks";
|
|
5
|
+
import { CopilotEndpointCorsConfig, toFetchCorsConfig } from "./hono";
|
|
23
6
|
|
|
24
7
|
interface CopilotSingleEndpointParams {
|
|
25
8
|
runtime: CopilotRuntimeLike;
|
|
@@ -32,167 +15,32 @@ interface CopilotSingleEndpointParams {
|
|
|
32
15
|
* To support HTTP-only cookies, provide cors config with credentials: true and explicit origin.
|
|
33
16
|
*/
|
|
34
17
|
cors?: CopilotEndpointCorsConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Lifecycle hooks for request processing.
|
|
20
|
+
*/
|
|
21
|
+
hooks?: CopilotRuntimeHooks;
|
|
35
22
|
}
|
|
36
23
|
|
|
37
|
-
|
|
38
|
-
Variables: {
|
|
39
|
-
modifiedRequest?: Request;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
24
|
+
/** @deprecated Use `createCopilotHonoHandler` with `mode: "single-route"` instead. */
|
|
43
25
|
export function createCopilotEndpointSingleRoute({
|
|
44
26
|
runtime,
|
|
45
27
|
basePath,
|
|
46
28
|
cors: corsConfig,
|
|
29
|
+
hooks,
|
|
47
30
|
}: CopilotSingleEndpointParams) {
|
|
48
|
-
const app = new Hono<CopilotEndpointContext>();
|
|
49
31
|
const routePath = normalizePath(basePath);
|
|
50
32
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"GET",
|
|
59
|
-
"HEAD",
|
|
60
|
-
"PUT",
|
|
61
|
-
"POST",
|
|
62
|
-
"DELETE",
|
|
63
|
-
"PATCH",
|
|
64
|
-
"OPTIONS",
|
|
65
|
-
],
|
|
66
|
-
allowHeaders: ["*"],
|
|
67
|
-
credentials: corsConfig?.credentials ?? false,
|
|
68
|
-
}),
|
|
69
|
-
)
|
|
70
|
-
.use("*", async (c, next) => {
|
|
71
|
-
const request = c.req.raw;
|
|
72
|
-
const path = c.req.path;
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const maybeModifiedRequest = await callBeforeRequestMiddleware({
|
|
76
|
-
runtime,
|
|
77
|
-
request,
|
|
78
|
-
path,
|
|
79
|
-
});
|
|
80
|
-
if (maybeModifiedRequest) {
|
|
81
|
-
c.set("modifiedRequest", maybeModifiedRequest);
|
|
82
|
-
}
|
|
83
|
-
} catch (error) {
|
|
84
|
-
logger.error(
|
|
85
|
-
{ err: error, url: request.url, path },
|
|
86
|
-
"Error running before request middleware",
|
|
87
|
-
);
|
|
88
|
-
if (error instanceof Response) {
|
|
89
|
-
return error;
|
|
90
|
-
}
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
await next();
|
|
95
|
-
})
|
|
96
|
-
.use("*", async (c, next) => {
|
|
97
|
-
await next();
|
|
98
|
-
|
|
99
|
-
const response = c.res.clone();
|
|
100
|
-
const path = c.req.path;
|
|
101
|
-
|
|
102
|
-
callAfterRequestMiddleware({
|
|
103
|
-
runtime,
|
|
104
|
-
response,
|
|
105
|
-
path,
|
|
106
|
-
}).catch((error) => {
|
|
107
|
-
logger.error(
|
|
108
|
-
{ err: error, url: c.req.url, path },
|
|
109
|
-
"Error running after request middleware",
|
|
110
|
-
);
|
|
111
|
-
});
|
|
112
|
-
})
|
|
113
|
-
.post("/", async (c) => {
|
|
114
|
-
const request = c.get("modifiedRequest") || c.req.raw;
|
|
33
|
+
const handler = createCopilotRuntimeHandler({
|
|
34
|
+
runtime,
|
|
35
|
+
basePath: routePath,
|
|
36
|
+
mode: "single-route",
|
|
37
|
+
cors: corsConfig ? toFetchCorsConfig(corsConfig) : true,
|
|
38
|
+
hooks,
|
|
39
|
+
});
|
|
115
40
|
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
methodCall = await parseMethodCall(request);
|
|
119
|
-
} catch (error) {
|
|
120
|
-
if (error instanceof Response) {
|
|
121
|
-
logger.warn({ url: request.url }, "Invalid single-route payload");
|
|
122
|
-
return error;
|
|
123
|
-
}
|
|
124
|
-
logger.warn(
|
|
125
|
-
{ err: error, url: request.url },
|
|
126
|
-
"Invalid single-route payload",
|
|
127
|
-
);
|
|
128
|
-
return c.json(
|
|
129
|
-
{
|
|
130
|
-
error: "invalid_request",
|
|
131
|
-
message:
|
|
132
|
-
error instanceof Error
|
|
133
|
-
? error.message
|
|
134
|
-
: "Invalid request payload",
|
|
135
|
-
},
|
|
136
|
-
400,
|
|
137
|
-
);
|
|
138
|
-
}
|
|
41
|
+
const app = new Hono();
|
|
139
42
|
|
|
140
|
-
|
|
141
|
-
switch (methodCall.method) {
|
|
142
|
-
case "agent/run": {
|
|
143
|
-
const agentId = expectString(methodCall.params, "agentId");
|
|
144
|
-
const handlerRequest = createJsonRequest(request, methodCall.body);
|
|
145
|
-
return await handleRunAgent({
|
|
146
|
-
runtime,
|
|
147
|
-
request: handlerRequest,
|
|
148
|
-
agentId,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
case "agent/connect": {
|
|
152
|
-
const agentId = expectString(methodCall.params, "agentId");
|
|
153
|
-
const handlerRequest = createJsonRequest(request, methodCall.body);
|
|
154
|
-
return await handleConnectAgent({
|
|
155
|
-
runtime,
|
|
156
|
-
request: handlerRequest,
|
|
157
|
-
agentId,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
case "agent/stop": {
|
|
161
|
-
const agentId = expectString(methodCall.params, "agentId");
|
|
162
|
-
const threadId = expectString(methodCall.params, "threadId");
|
|
163
|
-
return await handleStopAgent({
|
|
164
|
-
runtime,
|
|
165
|
-
request,
|
|
166
|
-
agentId,
|
|
167
|
-
threadId,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
case "info": {
|
|
171
|
-
return await handleGetRuntimeInfo({ runtime, request });
|
|
172
|
-
}
|
|
173
|
-
case "transcribe": {
|
|
174
|
-
const handlerRequest = createJsonRequest(request, methodCall.body);
|
|
175
|
-
return await handleTranscribe({ runtime, request: handlerRequest });
|
|
176
|
-
}
|
|
177
|
-
default: {
|
|
178
|
-
const exhaustiveCheck: never = methodCall.method;
|
|
179
|
-
return exhaustiveCheck;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
if (error instanceof Response) {
|
|
184
|
-
return error;
|
|
185
|
-
}
|
|
186
|
-
logger.error(
|
|
187
|
-
{ err: error, url: request.url, method: methodCall.method },
|
|
188
|
-
"Error running single-route handler",
|
|
189
|
-
);
|
|
190
|
-
throw error;
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
.notFound((c) => {
|
|
194
|
-
return c.json({ error: "Not found" }, 404);
|
|
195
|
-
});
|
|
43
|
+
return app.basePath(routePath).all("*", async (c) => handler(c.req.raw));
|
|
196
44
|
}
|
|
197
45
|
|
|
198
46
|
function normalizePath(path: string): string {
|