@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,15 @@
|
|
|
1
|
+
import { CopilotRuntime } from "../../../core/runtime";
|
|
2
|
+
import { createFakeAgent, createTestRunner } from "./test-agent";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a CopilotRuntime configured with a fake agent for testing.
|
|
6
|
+
* No API keys required.
|
|
7
|
+
*/
|
|
8
|
+
export function createTestRuntime(
|
|
9
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
10
|
+
) {
|
|
11
|
+
return new CopilotRuntime({
|
|
12
|
+
agents: { default: createFakeAgent(opts) as any },
|
|
13
|
+
runner: createTestRunner(),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read an SSE response stream to a string.
|
|
3
|
+
* Stops when RUN_FINISHED is seen or after maxChunks reads.
|
|
4
|
+
*/
|
|
5
|
+
export async function readSSEStream(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
stream: ReadableStream<any>,
|
|
8
|
+
opts: { maxChunks?: number } = {},
|
|
9
|
+
): Promise<string> {
|
|
10
|
+
const reader = stream.getReader();
|
|
11
|
+
const decoder = new TextDecoder();
|
|
12
|
+
let output = "";
|
|
13
|
+
const maxChunks = opts.maxChunks ?? 30;
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < maxChunks; i++) {
|
|
16
|
+
const { done, value } = await reader.read();
|
|
17
|
+
if (done) break;
|
|
18
|
+
if (value) {
|
|
19
|
+
// The stream may emit strings (direct fetch handler) or Uint8Array (real HTTP)
|
|
20
|
+
output +=
|
|
21
|
+
typeof value === "string"
|
|
22
|
+
? value
|
|
23
|
+
: decoder.decode(value, { stream: true });
|
|
24
|
+
if (output.includes("RUN_FINISHED")) break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await reader.cancel();
|
|
29
|
+
output += decoder.decode();
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extract event type names from an SSE payload string.
|
|
35
|
+
* Matches "type":"EVENT_NAME" patterns in the data lines.
|
|
36
|
+
*/
|
|
37
|
+
export function extractEventTypes(ssePayload: string): string[] {
|
|
38
|
+
const types: string[] = [];
|
|
39
|
+
for (const line of ssePayload.split("\n")) {
|
|
40
|
+
if (!line.startsWith("data:")) continue;
|
|
41
|
+
const match = line.match(/"type"\s*:\s*"([^"]+)"/);
|
|
42
|
+
if (match?.[1]) types.push(match[1]);
|
|
43
|
+
}
|
|
44
|
+
return types;
|
|
45
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { InMemoryAgentRunner } from "../../../runner/in-memory";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a fake agent that emits a deterministic sequence of AG-UI events.
|
|
5
|
+
* Requires no API keys — purely in-memory.
|
|
6
|
+
*/
|
|
7
|
+
export function createFakeAgent(
|
|
8
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
9
|
+
) {
|
|
10
|
+
return {
|
|
11
|
+
clone: () => {
|
|
12
|
+
const instance = {
|
|
13
|
+
setMessages: () => undefined,
|
|
14
|
+
setState: () => undefined,
|
|
15
|
+
threadId: "thread",
|
|
16
|
+
headers: {},
|
|
17
|
+
runAgent: async (
|
|
18
|
+
input: { runId: string },
|
|
19
|
+
{ onEvent }: { onEvent: (payload: { event: unknown }) => void },
|
|
20
|
+
) => {
|
|
21
|
+
// Capture headers if requested
|
|
22
|
+
if (opts.capturedHeaders) {
|
|
23
|
+
opts.capturedHeaders.push({ ...instance.headers });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onEvent({
|
|
27
|
+
event: {
|
|
28
|
+
type: "RUN_STARTED",
|
|
29
|
+
runId: input.runId,
|
|
30
|
+
input: { runId: input.runId },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
onEvent({
|
|
34
|
+
event: { type: "TEXT_MESSAGE_START", messageId: "m1" },
|
|
35
|
+
});
|
|
36
|
+
onEvent({
|
|
37
|
+
event: {
|
|
38
|
+
type: "TEXT_MESSAGE_CONTENT",
|
|
39
|
+
messageId: "m1",
|
|
40
|
+
delta: "Hello from test",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
onEvent({
|
|
44
|
+
event: { type: "TEXT_MESSAGE_END", messageId: "m1" },
|
|
45
|
+
});
|
|
46
|
+
onEvent({
|
|
47
|
+
event: { type: "RUN_FINISHED", runId: input.runId },
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
return instance;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createTestRunner() {
|
|
57
|
+
return new InMemoryAgentRunner();
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for all Node.js-compatible server runtimes.
|
|
3
|
+
*
|
|
4
|
+
* Runs the same multi-endpoint and single-endpoint test suites against:
|
|
5
|
+
* - Express (multi + single)
|
|
6
|
+
* - Hono via @hono/node-server (multi + single)
|
|
7
|
+
* - Raw Node.js http (multi + single)
|
|
8
|
+
* - Direct fetch handler — no HTTP server (multi + single)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { multiEndpointSuite } from "./suites/multi-endpoint.suite";
|
|
12
|
+
import { singleEndpointSuite } from "./suites/single-endpoint.suite";
|
|
13
|
+
|
|
14
|
+
// Server factories
|
|
15
|
+
import { createExpressMultiServer } from "./servers/express-multi";
|
|
16
|
+
import { createExpressSingleServer } from "./servers/express-single";
|
|
17
|
+
import { createHonoMultiServer } from "./servers/hono-multi";
|
|
18
|
+
import { createHonoSingleServer } from "./servers/hono-single";
|
|
19
|
+
import { createNodeMultiServer } from "./servers/node-multi";
|
|
20
|
+
import { createNodeSingleServer } from "./servers/node-single";
|
|
21
|
+
import { createFetchDirectHandler } from "./servers/fetch-direct";
|
|
22
|
+
|
|
23
|
+
// ─── Multi-Endpoint ──────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
multiEndpointSuite("Express", createExpressMultiServer);
|
|
26
|
+
multiEndpointSuite("Hono", createHonoMultiServer);
|
|
27
|
+
multiEndpointSuite("Node", createNodeMultiServer);
|
|
28
|
+
multiEndpointSuite("Fetch", (opts) =>
|
|
29
|
+
Promise.resolve(createFetchDirectHandler("multi-route", opts)),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// ─── Single-Endpoint ─────────────────────────────────────────────────
|
|
33
|
+
|
|
34
|
+
singleEndpointSuite("Express", createExpressSingleServer);
|
|
35
|
+
singleEndpointSuite("Hono", createHonoSingleServer);
|
|
36
|
+
singleEndpointSuite("Node", createNodeSingleServer);
|
|
37
|
+
singleEndpointSuite("Fetch", (opts) =>
|
|
38
|
+
Promise.resolve(createFetchDirectHandler("single-route", opts)),
|
|
39
|
+
);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import { createCopilotExpressHandler } from "../../../endpoints/express";
|
|
4
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
5
|
+
import type { ServerHandle } from "./types";
|
|
6
|
+
|
|
7
|
+
const BASE_PATH = "/api/copilotkit";
|
|
8
|
+
|
|
9
|
+
export async function createExpressMultiServer(
|
|
10
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
11
|
+
): Promise<ServerHandle> {
|
|
12
|
+
const runtime = createTestRuntime(opts);
|
|
13
|
+
const app = express();
|
|
14
|
+
app.use(
|
|
15
|
+
createCopilotExpressHandler({
|
|
16
|
+
runtime,
|
|
17
|
+
basePath: BASE_PATH,
|
|
18
|
+
cors: true,
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const server = app.listen(0, () => {
|
|
24
|
+
const { port } = server.address() as AddressInfo;
|
|
25
|
+
resolve({
|
|
26
|
+
baseUrl: `http://localhost:${port}`,
|
|
27
|
+
basePath: BASE_PATH,
|
|
28
|
+
close: () =>
|
|
29
|
+
new Promise<void>((res, rej) =>
|
|
30
|
+
server.close((err) => (err ? rej(err) : res())),
|
|
31
|
+
),
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import { createCopilotExpressHandler } from "../../../endpoints/express";
|
|
4
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
5
|
+
import type { ServerHandle } from "./types";
|
|
6
|
+
|
|
7
|
+
const BASE_PATH = "/api/copilotkit";
|
|
8
|
+
|
|
9
|
+
export async function createExpressSingleServer(
|
|
10
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
11
|
+
): Promise<ServerHandle> {
|
|
12
|
+
const runtime = createTestRuntime(opts);
|
|
13
|
+
const app = express();
|
|
14
|
+
app.use(
|
|
15
|
+
createCopilotExpressHandler({
|
|
16
|
+
runtime,
|
|
17
|
+
basePath: BASE_PATH,
|
|
18
|
+
mode: "single-route",
|
|
19
|
+
cors: true,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const server = app.listen(0, () => {
|
|
25
|
+
const { port } = server.address() as AddressInfo;
|
|
26
|
+
resolve({
|
|
27
|
+
baseUrl: `http://localhost:${port}`,
|
|
28
|
+
basePath: BASE_PATH,
|
|
29
|
+
close: () =>
|
|
30
|
+
new Promise<void>((res, rej) =>
|
|
31
|
+
server.close((err) => (err ? rej(err) : res())),
|
|
32
|
+
),
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createCopilotRuntimeHandler } from "../../../core/fetch-handler";
|
|
2
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
3
|
+
import type { ServerHandle } from "./types";
|
|
4
|
+
|
|
5
|
+
const BASE_PATH = "/api/copilotkit";
|
|
6
|
+
const SYNTHETIC_ORIGIN = "http://localhost";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a "server" that invokes the fetch handler directly — no HTTP server.
|
|
10
|
+
* This tests the core fetch handler in isolation.
|
|
11
|
+
*
|
|
12
|
+
* We monkey-patch `globalThis.fetch` for the duration of the test so that
|
|
13
|
+
* standard `fetch(url)` calls route through the handler. Instead, the returned
|
|
14
|
+
* ServerHandle has a `baseUrl` that test suites can use, and the suites use
|
|
15
|
+
* normal `fetch()` which goes over the network for real servers. For the direct
|
|
16
|
+
* handler, callers should use `fetchDirect` exported alongside the factory.
|
|
17
|
+
*/
|
|
18
|
+
export function createFetchDirectHandler(
|
|
19
|
+
mode: "multi-route" | "single-route",
|
|
20
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
21
|
+
): ServerHandle & { handler: (request: Request) => Promise<Response> } {
|
|
22
|
+
const runtime = createTestRuntime(opts);
|
|
23
|
+
|
|
24
|
+
const handler = createCopilotRuntimeHandler({
|
|
25
|
+
runtime,
|
|
26
|
+
basePath: BASE_PATH,
|
|
27
|
+
mode,
|
|
28
|
+
cors: true,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
baseUrl: SYNTHETIC_ORIGIN,
|
|
33
|
+
basePath: BASE_PATH,
|
|
34
|
+
handler,
|
|
35
|
+
close: async () => {
|
|
36
|
+
/* no-op — no server to close */
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { serve } from "@hono/node-server";
|
|
3
|
+
import type { AddressInfo } from "node:net";
|
|
4
|
+
import { createCopilotHonoHandler } from "../../../endpoints/hono";
|
|
5
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
6
|
+
import type { ServerHandle } from "./types";
|
|
7
|
+
|
|
8
|
+
const BASE_PATH = "/api/copilotkit";
|
|
9
|
+
|
|
10
|
+
export async function createHonoMultiServer(
|
|
11
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
12
|
+
): Promise<ServerHandle> {
|
|
13
|
+
const runtime = createTestRuntime(opts);
|
|
14
|
+
const app = new Hono();
|
|
15
|
+
app.route("/", createCopilotHonoHandler({ runtime, basePath: BASE_PATH }));
|
|
16
|
+
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const server = serve({ fetch: app.fetch, port: 0 }, () => {
|
|
19
|
+
const { port } = server.address() as AddressInfo;
|
|
20
|
+
resolve({
|
|
21
|
+
baseUrl: `http://localhost:${port}`,
|
|
22
|
+
basePath: BASE_PATH,
|
|
23
|
+
close: () =>
|
|
24
|
+
new Promise<void>((res, rej) =>
|
|
25
|
+
server.close((err) => (err ? rej(err) : res())),
|
|
26
|
+
),
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { serve } from "@hono/node-server";
|
|
3
|
+
import type { AddressInfo } from "node:net";
|
|
4
|
+
import { createCopilotHonoHandler } from "../../../endpoints/hono";
|
|
5
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
6
|
+
import type { ServerHandle } from "./types";
|
|
7
|
+
|
|
8
|
+
const BASE_PATH = "/api/copilotkit";
|
|
9
|
+
|
|
10
|
+
export async function createHonoSingleServer(
|
|
11
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
12
|
+
): Promise<ServerHandle> {
|
|
13
|
+
const runtime = createTestRuntime(opts);
|
|
14
|
+
const app = new Hono();
|
|
15
|
+
app.route(
|
|
16
|
+
"/",
|
|
17
|
+
createCopilotHonoHandler({
|
|
18
|
+
runtime,
|
|
19
|
+
basePath: BASE_PATH,
|
|
20
|
+
mode: "single-route",
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
const server = serve({ fetch: app.fetch, port: 0 }, () => {
|
|
26
|
+
const { port } = server.address() as AddressInfo;
|
|
27
|
+
resolve({
|
|
28
|
+
baseUrl: `http://localhost:${port}`,
|
|
29
|
+
basePath: BASE_PATH,
|
|
30
|
+
close: () =>
|
|
31
|
+
new Promise<void>((res, rej) =>
|
|
32
|
+
server.close((err) => (err ? rej(err) : res())),
|
|
33
|
+
),
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import { createCopilotRuntimeHandler } from "../../../core/fetch-handler";
|
|
4
|
+
import { createCopilotNodeHandler } from "../../../endpoints/node-fetch-handler";
|
|
5
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
6
|
+
import type { ServerHandle } from "./types";
|
|
7
|
+
|
|
8
|
+
const BASE_PATH = "/api/copilotkit";
|
|
9
|
+
|
|
10
|
+
export async function createNodeMultiServer(
|
|
11
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
12
|
+
): Promise<ServerHandle> {
|
|
13
|
+
const runtime = createTestRuntime(opts);
|
|
14
|
+
|
|
15
|
+
const handler = createCopilotRuntimeHandler({
|
|
16
|
+
runtime,
|
|
17
|
+
basePath: BASE_PATH,
|
|
18
|
+
cors: true,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const nodeHandler = createCopilotNodeHandler(handler);
|
|
22
|
+
|
|
23
|
+
const server = createServer(async (req, res) => {
|
|
24
|
+
const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
|
25
|
+
if (url.pathname.startsWith(BASE_PATH)) {
|
|
26
|
+
return nodeHandler(req, res);
|
|
27
|
+
}
|
|
28
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
29
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
server.listen(0, () => {
|
|
34
|
+
const { port } = server.address() as AddressInfo;
|
|
35
|
+
resolve({
|
|
36
|
+
baseUrl: `http://localhost:${port}`,
|
|
37
|
+
basePath: BASE_PATH,
|
|
38
|
+
close: () =>
|
|
39
|
+
new Promise<void>((res, rej) =>
|
|
40
|
+
server.close((err) => (err ? rej(err) : res())),
|
|
41
|
+
),
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import { createCopilotRuntimeHandler } from "../../../core/fetch-handler";
|
|
4
|
+
import { createCopilotNodeHandler } from "../../../endpoints/node-fetch-handler";
|
|
5
|
+
import { createTestRuntime } from "../helpers/create-test-runtime";
|
|
6
|
+
import type { ServerHandle } from "./types";
|
|
7
|
+
|
|
8
|
+
const BASE_PATH = "/api/copilotkit";
|
|
9
|
+
|
|
10
|
+
export async function createNodeSingleServer(
|
|
11
|
+
opts: { capturedHeaders?: Record<string, string>[] } = {},
|
|
12
|
+
): Promise<ServerHandle> {
|
|
13
|
+
const runtime = createTestRuntime(opts);
|
|
14
|
+
|
|
15
|
+
const handler = createCopilotRuntimeHandler({
|
|
16
|
+
runtime,
|
|
17
|
+
basePath: BASE_PATH,
|
|
18
|
+
mode: "single-route",
|
|
19
|
+
cors: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const nodeHandler = createCopilotNodeHandler(handler);
|
|
23
|
+
|
|
24
|
+
const server = createServer(async (req, res) => {
|
|
25
|
+
const url = new URL(req.url ?? "/", `http://${req.headers.host}`);
|
|
26
|
+
if (url.pathname.startsWith(BASE_PATH)) {
|
|
27
|
+
return nodeHandler(req, res);
|
|
28
|
+
}
|
|
29
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
30
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
server.listen(0, () => {
|
|
35
|
+
const { port } = server.address() as AddressInfo;
|
|
36
|
+
resolve({
|
|
37
|
+
baseUrl: `http://localhost:${port}`,
|
|
38
|
+
basePath: BASE_PATH,
|
|
39
|
+
close: () =>
|
|
40
|
+
new Promise<void>((res, rej) =>
|
|
41
|
+
server.close((err) => (err ? rej(err) : res())),
|
|
42
|
+
),
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ServerHandle {
|
|
2
|
+
/** Base URL, e.g. "http://localhost:54321" */
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** CopilotKit basePath, e.g. "/api/copilotkit" */
|
|
5
|
+
basePath: string;
|
|
6
|
+
/** Shut down the server */
|
|
7
|
+
close: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type ServerFactory = (opts?: {
|
|
11
|
+
capturedHeaders?: Record<string, string>[];
|
|
12
|
+
}) => Promise<ServerHandle>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A request function compatible with both real HTTP and direct fetch handler invocation.
|
|
16
|
+
* For real servers this is just global `fetch`. For direct fetch handlers it calls the handler directly.
|
|
17
|
+
*/
|
|
18
|
+
export type RequestFn = typeof fetch;
|