@copilotkit/runtime 1.55.0-next.9 → 1.55.1-next.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 +31 -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
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { createCopilotRuntimeHandler } from "../core/fetch-handler";
|
|
3
|
+
import { CopilotRuntime } from "../core/runtime";
|
|
4
|
+
import type { AbstractAgent } from "@ag-ui/client";
|
|
5
|
+
import type { CopilotRuntimeHooks } from "../core/hooks";
|
|
6
|
+
|
|
7
|
+
/* ------------------------------------------------------------------------------------------------
|
|
8
|
+
* Helpers
|
|
9
|
+
* --------------------------------------------------------------------------------------------- */
|
|
10
|
+
|
|
11
|
+
const createMockAgent = () => {
|
|
12
|
+
const agent: unknown = {
|
|
13
|
+
execute: vi.fn().mockResolvedValue({ events: [] }),
|
|
14
|
+
};
|
|
15
|
+
(agent as { clone: () => unknown }).clone = () => createMockAgent();
|
|
16
|
+
return agent as AbstractAgent;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const createRuntime = (opts?: Partial<CopilotRuntime>) =>
|
|
20
|
+
new CopilotRuntime({
|
|
21
|
+
agents: { default: createMockAgent() },
|
|
22
|
+
...opts,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const get = (url: string) => new Request(url, { method: "GET" });
|
|
26
|
+
|
|
27
|
+
const post = (url: string, body?: unknown) =>
|
|
28
|
+
new Request(url, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: { "Content-Type": "application/json" },
|
|
31
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/* ------------------------------------------------------------------------------------------------
|
|
35
|
+
* onRequest hook
|
|
36
|
+
* --------------------------------------------------------------------------------------------- */
|
|
37
|
+
|
|
38
|
+
describe("hooks — onRequest", () => {
|
|
39
|
+
it("is called for every request with correct context", async () => {
|
|
40
|
+
const onRequest = vi.fn();
|
|
41
|
+
const runtime = createRuntime();
|
|
42
|
+
const handler = createCopilotRuntimeHandler({
|
|
43
|
+
runtime,
|
|
44
|
+
basePath: "/api",
|
|
45
|
+
hooks: { onRequest },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await handler(get("http://localhost/api/info"));
|
|
49
|
+
|
|
50
|
+
expect(onRequest).toHaveBeenCalledWith(
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
request: expect.any(Request),
|
|
53
|
+
path: "/api/info",
|
|
54
|
+
runtime,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("returning a modified Request replaces the original", async () => {
|
|
60
|
+
const runtime = createRuntime();
|
|
61
|
+
const handler = createCopilotRuntimeHandler({
|
|
62
|
+
runtime,
|
|
63
|
+
basePath: "/api",
|
|
64
|
+
hooks: {
|
|
65
|
+
onRequest: ({ request }) => {
|
|
66
|
+
const headers = new Headers(request.headers);
|
|
67
|
+
headers.set("x-custom", "injected");
|
|
68
|
+
return new Request(request, { headers });
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
74
|
+
expect(response.status).toBe(200);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("returning void continues with original Request", async () => {
|
|
78
|
+
const runtime = createRuntime();
|
|
79
|
+
const handler = createCopilotRuntimeHandler({
|
|
80
|
+
runtime,
|
|
81
|
+
basePath: "/api",
|
|
82
|
+
hooks: {
|
|
83
|
+
onRequest: () => {
|
|
84
|
+
// void — no-op
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
90
|
+
expect(response.status).toBe(200);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("throwing a Response short-circuits", async () => {
|
|
94
|
+
const runtime = createRuntime();
|
|
95
|
+
const handler = createCopilotRuntimeHandler({
|
|
96
|
+
runtime,
|
|
97
|
+
basePath: "/api",
|
|
98
|
+
hooks: {
|
|
99
|
+
onRequest: () => {
|
|
100
|
+
throw new Response("Unauthorized", { status: 401 });
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
106
|
+
expect(response.status).toBe(401);
|
|
107
|
+
expect(await response.text()).toBe("Unauthorized");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("throwing a non-Response error triggers onError", async () => {
|
|
111
|
+
const onError = vi
|
|
112
|
+
.fn()
|
|
113
|
+
.mockReturnValue(new Response("Custom error", { status: 503 }));
|
|
114
|
+
const runtime = createRuntime();
|
|
115
|
+
const handler = createCopilotRuntimeHandler({
|
|
116
|
+
runtime,
|
|
117
|
+
basePath: "/api",
|
|
118
|
+
hooks: {
|
|
119
|
+
onRequest: () => {
|
|
120
|
+
throw new Error("Something broke");
|
|
121
|
+
},
|
|
122
|
+
onError,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
127
|
+
expect(response.status).toBe(503);
|
|
128
|
+
expect(onError).toHaveBeenCalledWith(
|
|
129
|
+
expect.objectContaining({
|
|
130
|
+
error: expect.any(Error),
|
|
131
|
+
}),
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
/* ------------------------------------------------------------------------------------------------
|
|
137
|
+
* onBeforeHandler hook
|
|
138
|
+
* --------------------------------------------------------------------------------------------- */
|
|
139
|
+
|
|
140
|
+
describe("hooks — onBeforeHandler", () => {
|
|
141
|
+
it("is called after routing with route info", async () => {
|
|
142
|
+
const onBeforeHandler = vi.fn();
|
|
143
|
+
const runtime = createRuntime();
|
|
144
|
+
const handler = createCopilotRuntimeHandler({
|
|
145
|
+
runtime,
|
|
146
|
+
basePath: "/api",
|
|
147
|
+
hooks: { onBeforeHandler },
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
await handler(get("http://localhost/api/info"));
|
|
151
|
+
|
|
152
|
+
expect(onBeforeHandler).toHaveBeenCalledWith(
|
|
153
|
+
expect.objectContaining({
|
|
154
|
+
route: { method: "info" },
|
|
155
|
+
request: expect.any(Request),
|
|
156
|
+
path: "/api/info",
|
|
157
|
+
runtime,
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("receives agentId in route info for agent routes", async () => {
|
|
163
|
+
const onBeforeHandler = vi.fn();
|
|
164
|
+
const runtime = createRuntime();
|
|
165
|
+
const handler = createCopilotRuntimeHandler({
|
|
166
|
+
runtime,
|
|
167
|
+
basePath: "/api",
|
|
168
|
+
hooks: { onBeforeHandler },
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
await handler(
|
|
172
|
+
post("http://localhost/api/agent/default/run", {
|
|
173
|
+
threadId: "t1",
|
|
174
|
+
runId: "r1",
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
expect(onBeforeHandler).toHaveBeenCalledWith(
|
|
179
|
+
expect.objectContaining({
|
|
180
|
+
route: expect.objectContaining({
|
|
181
|
+
method: "agent/run",
|
|
182
|
+
agentId: "default",
|
|
183
|
+
}),
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("is NOT called when routing returns 404", async () => {
|
|
189
|
+
const onBeforeHandler = vi.fn();
|
|
190
|
+
const runtime = createRuntime();
|
|
191
|
+
const handler = createCopilotRuntimeHandler({
|
|
192
|
+
runtime,
|
|
193
|
+
basePath: "/api",
|
|
194
|
+
hooks: { onBeforeHandler },
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const response = await handler(get("http://localhost/api/unknown"));
|
|
198
|
+
expect(response.status).toBe(404);
|
|
199
|
+
expect(onBeforeHandler).not.toHaveBeenCalled();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("throwing a Response short-circuits before handler", async () => {
|
|
203
|
+
const runtime = createRuntime();
|
|
204
|
+
const handler = createCopilotRuntimeHandler({
|
|
205
|
+
runtime,
|
|
206
|
+
basePath: "/api",
|
|
207
|
+
hooks: {
|
|
208
|
+
onBeforeHandler: () => {
|
|
209
|
+
throw new Response("Blocked", { status: 403 });
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
215
|
+
expect(response.status).toBe(403);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("returning a modified Request is passed to the handler", async () => {
|
|
219
|
+
const runtime = createRuntime();
|
|
220
|
+
const receivedHeaders: string[] = [];
|
|
221
|
+
const handler = createCopilotRuntimeHandler({
|
|
222
|
+
runtime,
|
|
223
|
+
basePath: "/api",
|
|
224
|
+
hooks: {
|
|
225
|
+
onBeforeHandler: ({ request }) => {
|
|
226
|
+
const headers = new Headers(request.headers);
|
|
227
|
+
headers.set("x-before-handler", "modified");
|
|
228
|
+
return new Request(request, { headers });
|
|
229
|
+
},
|
|
230
|
+
onResponse: ({ response }) => {
|
|
231
|
+
// If we got a successful response, the handler was dispatched
|
|
232
|
+
// with the modified request
|
|
233
|
+
receivedHeaders.push("onResponse-called");
|
|
234
|
+
return response;
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
240
|
+
expect(response.status).toBe(200);
|
|
241
|
+
expect(receivedHeaders).toContain("onResponse-called");
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
/* ------------------------------------------------------------------------------------------------
|
|
246
|
+
* onResponse hook
|
|
247
|
+
* --------------------------------------------------------------------------------------------- */
|
|
248
|
+
|
|
249
|
+
describe("hooks — onResponse", () => {
|
|
250
|
+
it("is called with the response and route info", async () => {
|
|
251
|
+
const onResponse = vi.fn();
|
|
252
|
+
const runtime = createRuntime();
|
|
253
|
+
const handler = createCopilotRuntimeHandler({
|
|
254
|
+
runtime,
|
|
255
|
+
basePath: "/api",
|
|
256
|
+
hooks: { onResponse },
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await handler(get("http://localhost/api/info"));
|
|
260
|
+
|
|
261
|
+
expect(onResponse).toHaveBeenCalledWith(
|
|
262
|
+
expect.objectContaining({
|
|
263
|
+
response: expect.any(Response),
|
|
264
|
+
route: { method: "info" },
|
|
265
|
+
request: expect.any(Request),
|
|
266
|
+
runtime,
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("returning a modified Response replaces the original", async () => {
|
|
272
|
+
const runtime = createRuntime();
|
|
273
|
+
const handler = createCopilotRuntimeHandler({
|
|
274
|
+
runtime,
|
|
275
|
+
basePath: "/api",
|
|
276
|
+
hooks: {
|
|
277
|
+
onResponse: ({ response }) => {
|
|
278
|
+
const headers = new Headers(response.headers);
|
|
279
|
+
headers.set("x-custom-header", "hello");
|
|
280
|
+
return new Response(response.body, {
|
|
281
|
+
status: response.status,
|
|
282
|
+
headers,
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
289
|
+
expect(response.headers.get("x-custom-header")).toBe("hello");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("returning void continues with original Response", async () => {
|
|
293
|
+
const runtime = createRuntime();
|
|
294
|
+
const handler = createCopilotRuntimeHandler({
|
|
295
|
+
runtime,
|
|
296
|
+
basePath: "/api",
|
|
297
|
+
hooks: {
|
|
298
|
+
onResponse: () => {
|
|
299
|
+
// void — no-op
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
305
|
+
expect(response.status).toBe(200);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("is called for error responses from handlers too", async () => {
|
|
309
|
+
const onResponse = vi.fn();
|
|
310
|
+
const runtime = createRuntime();
|
|
311
|
+
const handler = createCopilotRuntimeHandler({
|
|
312
|
+
runtime,
|
|
313
|
+
basePath: "/api",
|
|
314
|
+
hooks: {
|
|
315
|
+
onBeforeHandler: () => {
|
|
316
|
+
throw new Response("Forbidden", { status: 403 });
|
|
317
|
+
},
|
|
318
|
+
onResponse,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
323
|
+
expect(response.status).toBe(403);
|
|
324
|
+
expect(onResponse).toHaveBeenCalledWith(
|
|
325
|
+
expect.objectContaining({
|
|
326
|
+
response: expect.any(Response),
|
|
327
|
+
}),
|
|
328
|
+
);
|
|
329
|
+
// The thrown Response (403) should be passed to onResponse
|
|
330
|
+
const calledWith = onResponse.mock.calls[0][0];
|
|
331
|
+
expect(calledWith.response.status).toBe(403);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
/* ------------------------------------------------------------------------------------------------
|
|
336
|
+
* onError hook
|
|
337
|
+
* --------------------------------------------------------------------------------------------- */
|
|
338
|
+
|
|
339
|
+
describe("hooks — onError", () => {
|
|
340
|
+
it("is called with error context", async () => {
|
|
341
|
+
const onError = vi.fn();
|
|
342
|
+
const runtime = createRuntime();
|
|
343
|
+
const handler = createCopilotRuntimeHandler({
|
|
344
|
+
runtime,
|
|
345
|
+
basePath: "/api",
|
|
346
|
+
hooks: {
|
|
347
|
+
onRequest: () => {
|
|
348
|
+
throw new Error("test error");
|
|
349
|
+
},
|
|
350
|
+
onError,
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
await handler(get("http://localhost/api/info"));
|
|
355
|
+
|
|
356
|
+
expect(onError).toHaveBeenCalledWith(
|
|
357
|
+
expect.objectContaining({
|
|
358
|
+
error: expect.any(Error),
|
|
359
|
+
request: expect.any(Request),
|
|
360
|
+
path: "/api/info",
|
|
361
|
+
runtime,
|
|
362
|
+
}),
|
|
363
|
+
);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("returning a Response overrides the default error response", async () => {
|
|
367
|
+
const runtime = createRuntime();
|
|
368
|
+
const handler = createCopilotRuntimeHandler({
|
|
369
|
+
runtime,
|
|
370
|
+
basePath: "/api",
|
|
371
|
+
hooks: {
|
|
372
|
+
onRequest: () => {
|
|
373
|
+
throw new Error("test error");
|
|
374
|
+
},
|
|
375
|
+
onError: () =>
|
|
376
|
+
new Response(JSON.stringify({ custom: true }), { status: 503 }),
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
381
|
+
expect(response.status).toBe(503);
|
|
382
|
+
const body = await response.json();
|
|
383
|
+
expect(body).toEqual({ custom: true });
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("returning void uses default JSON error response", async () => {
|
|
387
|
+
const runtime = createRuntime();
|
|
388
|
+
const handler = createCopilotRuntimeHandler({
|
|
389
|
+
runtime,
|
|
390
|
+
basePath: "/api",
|
|
391
|
+
hooks: {
|
|
392
|
+
onRequest: () => {
|
|
393
|
+
throw new Error("test error");
|
|
394
|
+
},
|
|
395
|
+
onError: () => {
|
|
396
|
+
// void — use default
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const response = await handler(get("http://localhost/api/info"));
|
|
402
|
+
expect(response.status).toBe(500);
|
|
403
|
+
const body = await response.json();
|
|
404
|
+
expect(body).toHaveProperty("error", "internal_error");
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("route is present when error occurs after routing", async () => {
|
|
408
|
+
const onError = vi.fn();
|
|
409
|
+
const runtime = createRuntime();
|
|
410
|
+
const handler = createCopilotRuntimeHandler({
|
|
411
|
+
runtime,
|
|
412
|
+
basePath: "/api",
|
|
413
|
+
hooks: {
|
|
414
|
+
onBeforeHandler: () => {
|
|
415
|
+
throw new Error("post-routing error");
|
|
416
|
+
},
|
|
417
|
+
onError,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
await handler(get("http://localhost/api/info"));
|
|
422
|
+
|
|
423
|
+
expect(onError).toHaveBeenCalledWith(
|
|
424
|
+
expect.objectContaining({
|
|
425
|
+
error: expect.any(Error),
|
|
426
|
+
route: expect.objectContaining({
|
|
427
|
+
method: "info",
|
|
428
|
+
}),
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
/* ------------------------------------------------------------------------------------------------
|
|
435
|
+
* Composition with legacy middleware
|
|
436
|
+
* --------------------------------------------------------------------------------------------- */
|
|
437
|
+
|
|
438
|
+
describe("hooks — composition with legacy middleware", () => {
|
|
439
|
+
it("hooks.onRequest runs before runtime.beforeRequestMiddleware", async () => {
|
|
440
|
+
const order: string[] = [];
|
|
441
|
+
|
|
442
|
+
const beforeRequestMiddleware = vi.fn().mockImplementation(() => {
|
|
443
|
+
order.push("legacy-before");
|
|
444
|
+
});
|
|
445
|
+
const onRequest = vi.fn().mockImplementation(() => {
|
|
446
|
+
order.push("hook-onRequest");
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const runtime = createRuntime({ beforeRequestMiddleware });
|
|
450
|
+
const handler = createCopilotRuntimeHandler({
|
|
451
|
+
runtime,
|
|
452
|
+
basePath: "/api",
|
|
453
|
+
hooks: { onRequest },
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
await handler(get("http://localhost/api/info"));
|
|
457
|
+
|
|
458
|
+
expect(order).toEqual(["hook-onRequest", "legacy-before"]);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("runtime.afterRequestMiddleware runs after hooks.onResponse", async () => {
|
|
462
|
+
const order: string[] = [];
|
|
463
|
+
|
|
464
|
+
const afterRequestMiddleware = vi.fn().mockImplementation(() => {
|
|
465
|
+
order.push("legacy-after");
|
|
466
|
+
});
|
|
467
|
+
const onResponse = vi.fn().mockImplementation(() => {
|
|
468
|
+
order.push("hook-onResponse");
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
const runtime = createRuntime({ afterRequestMiddleware });
|
|
472
|
+
const handler = createCopilotRuntimeHandler({
|
|
473
|
+
runtime,
|
|
474
|
+
basePath: "/api",
|
|
475
|
+
hooks: { onResponse },
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
await handler(get("http://localhost/api/info"));
|
|
479
|
+
|
|
480
|
+
// afterRequestMiddleware is fire-and-forget, give it a tick
|
|
481
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
482
|
+
|
|
483
|
+
expect(order).toEqual(["hook-onResponse", "legacy-after"]);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it("full pipeline execution order", async () => {
|
|
487
|
+
const order: string[] = [];
|
|
488
|
+
|
|
489
|
+
const beforeRequestMiddleware = vi.fn().mockImplementation(() => {
|
|
490
|
+
order.push("legacy-before");
|
|
491
|
+
});
|
|
492
|
+
const afterRequestMiddleware = vi.fn().mockImplementation(() => {
|
|
493
|
+
order.push("legacy-after");
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
const hooks: CopilotRuntimeHooks = {
|
|
497
|
+
onRequest: () => {
|
|
498
|
+
order.push("onRequest");
|
|
499
|
+
},
|
|
500
|
+
onBeforeHandler: () => {
|
|
501
|
+
order.push("onBeforeHandler");
|
|
502
|
+
},
|
|
503
|
+
onResponse: () => {
|
|
504
|
+
order.push("onResponse");
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const runtime = createRuntime({
|
|
509
|
+
beforeRequestMiddleware,
|
|
510
|
+
afterRequestMiddleware,
|
|
511
|
+
});
|
|
512
|
+
const handler = createCopilotRuntimeHandler({
|
|
513
|
+
runtime,
|
|
514
|
+
basePath: "/api",
|
|
515
|
+
hooks,
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
await handler(get("http://localhost/api/info"));
|
|
519
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
520
|
+
|
|
521
|
+
expect(order).toEqual([
|
|
522
|
+
"onRequest",
|
|
523
|
+
"legacy-before",
|
|
524
|
+
"onBeforeHandler",
|
|
525
|
+
"onResponse",
|
|
526
|
+
"legacy-after",
|
|
527
|
+
]);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
it("request modifications from hooks are visible to legacy middleware", async () => {
|
|
531
|
+
let legacySawCustomHeader = false;
|
|
532
|
+
|
|
533
|
+
const beforeRequestMiddleware = vi
|
|
534
|
+
.fn()
|
|
535
|
+
.mockImplementation(({ request }: { request: Request }) => {
|
|
536
|
+
legacySawCustomHeader = request.headers.get("x-from-hook") === "hello";
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
const runtime = createRuntime({ beforeRequestMiddleware });
|
|
540
|
+
const handler = createCopilotRuntimeHandler({
|
|
541
|
+
runtime,
|
|
542
|
+
basePath: "/api",
|
|
543
|
+
hooks: {
|
|
544
|
+
onRequest: ({ request }) => {
|
|
545
|
+
const headers = new Headers(request.headers);
|
|
546
|
+
headers.set("x-from-hook", "hello");
|
|
547
|
+
return new Request(request, { headers });
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
await handler(get("http://localhost/api/info"));
|
|
553
|
+
|
|
554
|
+
expect(beforeRequestMiddleware).toHaveBeenCalled();
|
|
555
|
+
expect(legacySawCustomHeader).toBe(true);
|
|
556
|
+
});
|
|
557
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for Bun-based server runtimes.
|
|
3
|
+
*
|
|
4
|
+
* Run with: bun test packages/runtime/src/v2/runtime/__tests__/integration/bun/
|
|
5
|
+
*
|
|
6
|
+
* Tests:
|
|
7
|
+
* - Elysia (multi + single)
|
|
8
|
+
* - Hono via Bun.serve (multi + single)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { multiEndpointSuite } from "../suites/multi-endpoint.suite";
|
|
12
|
+
import { singleEndpointSuite } from "../suites/single-endpoint.suite";
|
|
13
|
+
|
|
14
|
+
import { createElysiaMultiServer } from "./elysia-multi";
|
|
15
|
+
import { createElysiaSingleServer } from "./elysia-single";
|
|
16
|
+
import { createHonoBunMultiServer } from "./hono-bun-multi";
|
|
17
|
+
import { createHonoBunSingleServer } from "./hono-bun-single";
|
|
18
|
+
|
|
19
|
+
// ─── Multi-Endpoint ──────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
multiEndpointSuite("Elysia", createElysiaMultiServer);
|
|
22
|
+
multiEndpointSuite("Hono (Bun)", createHonoBunMultiServer);
|
|
23
|
+
|
|
24
|
+
// ─── Single-Endpoint ─────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
singleEndpointSuite("Elysia", createElysiaSingleServer);
|
|
27
|
+
singleEndpointSuite("Hono (Bun)", createHonoBunSingleServer);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Elysia } from "elysia";
|
|
2
|
+
import { createCopilotRuntimeHandler } from "../../../core/fetch-handler";
|
|
3
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
4
|
+
import type { ServerHandle } from "../servers/types";
|
|
5
|
+
|
|
6
|
+
const BASE_PATH = "/api/copilotkit";
|
|
7
|
+
|
|
8
|
+
export async function createElysiaMultiServer(
|
|
9
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
10
|
+
): Promise<ServerHandle> {
|
|
11
|
+
const runtime = createTestRuntime(opts);
|
|
12
|
+
const handler = createCopilotRuntimeHandler({
|
|
13
|
+
runtime,
|
|
14
|
+
basePath: BASE_PATH,
|
|
15
|
+
cors: true,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const app = new Elysia()
|
|
19
|
+
.all(`${BASE_PATH}/*`, ({ request }) => handler(request))
|
|
20
|
+
.all(BASE_PATH, ({ request }) => handler(request));
|
|
21
|
+
|
|
22
|
+
const server = app.listen(0);
|
|
23
|
+
const port = server.server!.port;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
baseUrl: `http://localhost:${port}`,
|
|
27
|
+
basePath: BASE_PATH,
|
|
28
|
+
close: async () => {
|
|
29
|
+
server.stop();
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Elysia } from "elysia";
|
|
2
|
+
import { createCopilotRuntimeHandler } from "../../../core/fetch-handler";
|
|
3
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
4
|
+
import type { ServerHandle } from "../servers/types";
|
|
5
|
+
|
|
6
|
+
const BASE_PATH = "/api/copilotkit";
|
|
7
|
+
|
|
8
|
+
export async function createElysiaSingleServer(
|
|
9
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
10
|
+
): Promise<ServerHandle> {
|
|
11
|
+
const runtime = createTestRuntime(opts);
|
|
12
|
+
const handler = createCopilotRuntimeHandler({
|
|
13
|
+
runtime,
|
|
14
|
+
basePath: BASE_PATH,
|
|
15
|
+
mode: "single-route",
|
|
16
|
+
cors: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const app = new Elysia()
|
|
20
|
+
.all(`${BASE_PATH}/*`, ({ request }) => handler(request))
|
|
21
|
+
.all(BASE_PATH, ({ request }) => handler(request));
|
|
22
|
+
|
|
23
|
+
const server = app.listen(0);
|
|
24
|
+
const port = server.server!.port;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
baseUrl: `http://localhost:${port}`,
|
|
28
|
+
basePath: BASE_PATH,
|
|
29
|
+
close: async () => {
|
|
30
|
+
server.stop();
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { createCopilotHonoHandler } from "../../../endpoints/hono";
|
|
3
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
4
|
+
import type { ServerHandle } from "../servers/types";
|
|
5
|
+
|
|
6
|
+
const BASE_PATH = "/api/copilotkit";
|
|
7
|
+
|
|
8
|
+
export async function createHonoBunMultiServer(
|
|
9
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
10
|
+
): Promise<ServerHandle> {
|
|
11
|
+
const runtime = createTestRuntime(opts);
|
|
12
|
+
const app = new Hono();
|
|
13
|
+
app.route("/", createCopilotHonoHandler({ runtime, basePath: BASE_PATH }));
|
|
14
|
+
|
|
15
|
+
const server = Bun.serve({ fetch: app.fetch, port: 0 });
|
|
16
|
+
const port = server.port;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
baseUrl: `http://localhost:${port}`,
|
|
20
|
+
basePath: BASE_PATH,
|
|
21
|
+
close: async () => {
|
|
22
|
+
server.stop();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { createCopilotHonoHandler } from "../../../endpoints/hono";
|
|
3
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
4
|
+
import type { ServerHandle } from "../servers/types";
|
|
5
|
+
|
|
6
|
+
const BASE_PATH = "/api/copilotkit";
|
|
7
|
+
|
|
8
|
+
export async function createHonoBunSingleServer(
|
|
9
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
10
|
+
): Promise<ServerHandle> {
|
|
11
|
+
const runtime = createTestRuntime(opts);
|
|
12
|
+
const app = new Hono();
|
|
13
|
+
app.route(
|
|
14
|
+
"/",
|
|
15
|
+
createCopilotHonoHandler({
|
|
16
|
+
runtime,
|
|
17
|
+
basePath: BASE_PATH,
|
|
18
|
+
mode: "single-route",
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const server = Bun.serve({ fetch: app.fetch, port: 0 });
|
|
23
|
+
const port = server.port;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
baseUrl: `http://localhost:${port}`,
|
|
27
|
+
basePath: BASE_PATH,
|
|
28
|
+
close: async () => {
|
|
29
|
+
server.stop();
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|