@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
|
@@ -0,0 +1,372 @@
|
|
|
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
|
+
|
|
6
|
+
/* ------------------------------------------------------------------------------------------------
|
|
7
|
+
* Helpers
|
|
8
|
+
* --------------------------------------------------------------------------------------------- */
|
|
9
|
+
|
|
10
|
+
const createMockAgent = () => {
|
|
11
|
+
const agent: unknown = {
|
|
12
|
+
execute: vi.fn().mockResolvedValue({ events: [] }),
|
|
13
|
+
};
|
|
14
|
+
(agent as { clone: () => unknown }).clone = () => createMockAgent();
|
|
15
|
+
return agent as AbstractAgent;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const createRuntime = (
|
|
19
|
+
agents: Record<string, AbstractAgent> = { default: createMockAgent() },
|
|
20
|
+
) => new CopilotRuntime({ agents });
|
|
21
|
+
|
|
22
|
+
const post = (url: string, body?: unknown) =>
|
|
23
|
+
new Request(url, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: { "Content-Type": "application/json" },
|
|
26
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/* ------------------------------------------------------------------------------------------------
|
|
30
|
+
* Single-route: malformed JSON
|
|
31
|
+
* --------------------------------------------------------------------------------------------- */
|
|
32
|
+
|
|
33
|
+
describe("fetch-handler validation — single-route malformed input", () => {
|
|
34
|
+
const runtime = createRuntime();
|
|
35
|
+
const handler = createCopilotRuntimeHandler({
|
|
36
|
+
runtime,
|
|
37
|
+
basePath: "/api",
|
|
38
|
+
mode: "single-route",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("returns 400 for completely invalid JSON body", async () => {
|
|
42
|
+
const request = new Request("http://localhost/api", {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: { "Content-Type": "application/json" },
|
|
45
|
+
body: "not valid json{{{",
|
|
46
|
+
});
|
|
47
|
+
const response = await handler(request);
|
|
48
|
+
expect(response.status).toBe(400);
|
|
49
|
+
const body = await response.json();
|
|
50
|
+
expect(body).toHaveProperty("error");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("returns 400 for empty string body", async () => {
|
|
54
|
+
const request = new Request("http://localhost/api", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: "",
|
|
58
|
+
});
|
|
59
|
+
const response = await handler(request);
|
|
60
|
+
expect(response.status).toBe(400);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("returns 415 for no Content-Type header", async () => {
|
|
64
|
+
const request = new Request("http://localhost/api", {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: JSON.stringify({ method: "info" }),
|
|
67
|
+
});
|
|
68
|
+
const response = await handler(request);
|
|
69
|
+
expect(response.status).toBe(415);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("returns 415 for text/plain Content-Type", async () => {
|
|
73
|
+
const request = new Request("http://localhost/api", {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: { "Content-Type": "text/plain" },
|
|
76
|
+
body: JSON.stringify({ method: "info" }),
|
|
77
|
+
});
|
|
78
|
+
const response = await handler(request);
|
|
79
|
+
expect(response.status).toBe(415);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("accepts application/json with charset", async () => {
|
|
83
|
+
const request = new Request("http://localhost/api", {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: { "Content-Type": "application/json; charset=utf-8" },
|
|
86
|
+
body: JSON.stringify({ method: "info" }),
|
|
87
|
+
});
|
|
88
|
+
const response = await handler(request);
|
|
89
|
+
expect(response.status).toBe(200);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("returns 400 when method is null", async () => {
|
|
93
|
+
const response = await handler(
|
|
94
|
+
post("http://localhost/api", { method: null }),
|
|
95
|
+
);
|
|
96
|
+
expect(response.status).toBe(400);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("returns 400 when method is a number", async () => {
|
|
100
|
+
const response = await handler(
|
|
101
|
+
post("http://localhost/api", { method: 42 }),
|
|
102
|
+
);
|
|
103
|
+
expect(response.status).toBe(400);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("returns 400 when method is wrong case (INFO vs info)", async () => {
|
|
107
|
+
const response = await handler(
|
|
108
|
+
post("http://localhost/api", { method: "INFO" }),
|
|
109
|
+
);
|
|
110
|
+
expect(response.status).toBe(400);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("returns 400 for typo in method name", async () => {
|
|
114
|
+
const response = await handler(
|
|
115
|
+
post("http://localhost/api", { method: "agent/rn" }),
|
|
116
|
+
);
|
|
117
|
+
expect(response.status).toBe(400);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/* ------------------------------------------------------------------------------------------------
|
|
122
|
+
* Single-route: missing required params
|
|
123
|
+
* --------------------------------------------------------------------------------------------- */
|
|
124
|
+
|
|
125
|
+
describe("fetch-handler validation — single-route missing params", () => {
|
|
126
|
+
const runtime = createRuntime();
|
|
127
|
+
const handler = createCopilotRuntimeHandler({
|
|
128
|
+
runtime,
|
|
129
|
+
basePath: "/api",
|
|
130
|
+
mode: "single-route",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("returns 400 for agent/run without agentId param", async () => {
|
|
134
|
+
const response = await handler(
|
|
135
|
+
post("http://localhost/api", {
|
|
136
|
+
method: "agent/run",
|
|
137
|
+
params: {},
|
|
138
|
+
body: { threadId: "t1", runId: "r1" },
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
expect(response.status).toBe(400);
|
|
142
|
+
const body = await response.json();
|
|
143
|
+
expect(body.message).toContain("agentId");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("returns 400 for agent/run with empty agentId", async () => {
|
|
147
|
+
const response = await handler(
|
|
148
|
+
post("http://localhost/api", {
|
|
149
|
+
method: "agent/run",
|
|
150
|
+
params: { agentId: "" },
|
|
151
|
+
body: { threadId: "t1", runId: "r1" },
|
|
152
|
+
}),
|
|
153
|
+
);
|
|
154
|
+
expect(response.status).toBe(400);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("returns 400 for agent/run with whitespace-only agentId", async () => {
|
|
158
|
+
const response = await handler(
|
|
159
|
+
post("http://localhost/api", {
|
|
160
|
+
method: "agent/run",
|
|
161
|
+
params: { agentId: " " },
|
|
162
|
+
body: { threadId: "t1", runId: "r1" },
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
expect(response.status).toBe(400);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("returns 400 for agent/run with no params at all", async () => {
|
|
169
|
+
const response = await handler(
|
|
170
|
+
post("http://localhost/api", {
|
|
171
|
+
method: "agent/run",
|
|
172
|
+
body: { threadId: "t1", runId: "r1" },
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
expect(response.status).toBe(400);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("returns 400 for agent/connect without agentId param", async () => {
|
|
179
|
+
const response = await handler(
|
|
180
|
+
post("http://localhost/api", {
|
|
181
|
+
method: "agent/connect",
|
|
182
|
+
params: {},
|
|
183
|
+
body: { threadId: "t1", runId: "r1" },
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
expect(response.status).toBe(400);
|
|
187
|
+
const body = await response.json();
|
|
188
|
+
expect(body.message).toContain("agentId");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("returns 400 for agent/stop without agentId param", async () => {
|
|
192
|
+
const response = await handler(
|
|
193
|
+
post("http://localhost/api", {
|
|
194
|
+
method: "agent/stop",
|
|
195
|
+
params: { threadId: "t1" },
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
expect(response.status).toBe(400);
|
|
199
|
+
const body = await response.json();
|
|
200
|
+
expect(body.message).toContain("agentId");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("returns 400 for agent/stop without threadId param", async () => {
|
|
204
|
+
const response = await handler(
|
|
205
|
+
post("http://localhost/api", {
|
|
206
|
+
method: "agent/stop",
|
|
207
|
+
params: { agentId: "default" },
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
expect(response.status).toBe(400);
|
|
211
|
+
const body = await response.json();
|
|
212
|
+
expect(body.message).toContain("threadId");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("returns 400 for agent/stop with no params", async () => {
|
|
216
|
+
const response = await handler(
|
|
217
|
+
post("http://localhost/api", { method: "agent/stop" }),
|
|
218
|
+
);
|
|
219
|
+
expect(response.status).toBe(400);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("returns 400 for agent/run with non-string agentId", async () => {
|
|
223
|
+
const response = await handler(
|
|
224
|
+
post("http://localhost/api", {
|
|
225
|
+
method: "agent/run",
|
|
226
|
+
params: { agentId: 123 },
|
|
227
|
+
body: { threadId: "t1", runId: "r1" },
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
expect(response.status).toBe(400);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("info method works without params", async () => {
|
|
234
|
+
const response = await handler(
|
|
235
|
+
post("http://localhost/api", { method: "info" }),
|
|
236
|
+
);
|
|
237
|
+
expect(response.status).toBe(200);
|
|
238
|
+
const body = await response.json();
|
|
239
|
+
expect(body).toHaveProperty("version");
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("transcribe method without body returns 400 (body required for transcribe)", async () => {
|
|
243
|
+
const response = await handler(
|
|
244
|
+
post("http://localhost/api", { method: "transcribe" }),
|
|
245
|
+
);
|
|
246
|
+
// In single-route mode, transcribe requires a body via createJsonRequest
|
|
247
|
+
expect(response.status).toBe(400);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("transcribe method with body dispatches correctly", async () => {
|
|
251
|
+
const response = await handler(
|
|
252
|
+
post("http://localhost/api", {
|
|
253
|
+
method: "transcribe",
|
|
254
|
+
body: { audio: "data" },
|
|
255
|
+
}),
|
|
256
|
+
);
|
|
257
|
+
// Route matched — not a param validation error
|
|
258
|
+
expect(response.status).not.toBe(400);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
/* ------------------------------------------------------------------------------------------------
|
|
263
|
+
* Multi-route: edge cases
|
|
264
|
+
* --------------------------------------------------------------------------------------------- */
|
|
265
|
+
|
|
266
|
+
describe("fetch-handler validation — multi-route edge cases", () => {
|
|
267
|
+
const runtime = createRuntime();
|
|
268
|
+
|
|
269
|
+
it("handles request with no body on a POST route gracefully", async () => {
|
|
270
|
+
const handler = createCopilotRuntimeHandler({
|
|
271
|
+
runtime,
|
|
272
|
+
basePath: "/api",
|
|
273
|
+
});
|
|
274
|
+
const request = new Request("http://localhost/api/agent/default/run", {
|
|
275
|
+
method: "POST",
|
|
276
|
+
headers: { "Content-Type": "application/json" },
|
|
277
|
+
});
|
|
278
|
+
const response = await handler(request);
|
|
279
|
+
// Should not crash — may return 400 or 500 but not a Node crash
|
|
280
|
+
expect(response).toBeInstanceOf(Response);
|
|
281
|
+
expect(response.status).toBeGreaterThanOrEqual(400);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("CORS headers present on error responses too", async () => {
|
|
285
|
+
const handler = createCopilotRuntimeHandler({
|
|
286
|
+
runtime,
|
|
287
|
+
basePath: "/api",
|
|
288
|
+
cors: true,
|
|
289
|
+
});
|
|
290
|
+
const response = await handler(
|
|
291
|
+
new Request("http://localhost/api/unknown", { method: "GET" }),
|
|
292
|
+
);
|
|
293
|
+
expect(response.status).toBe(404);
|
|
294
|
+
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("CORS headers present on 405 responses", async () => {
|
|
298
|
+
const handler = createCopilotRuntimeHandler({
|
|
299
|
+
runtime,
|
|
300
|
+
basePath: "/api",
|
|
301
|
+
cors: true,
|
|
302
|
+
});
|
|
303
|
+
const response = await handler(
|
|
304
|
+
new Request("http://localhost/api/info", { method: "POST" }),
|
|
305
|
+
);
|
|
306
|
+
expect(response.status).toBe(405);
|
|
307
|
+
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("CORS headers present on 500 error responses", async () => {
|
|
311
|
+
const agent: unknown = {
|
|
312
|
+
execute: vi.fn().mockRejectedValue(new Error("boom")),
|
|
313
|
+
clone: () => agent,
|
|
314
|
+
};
|
|
315
|
+
const errorRuntime = createRuntime({ default: agent as AbstractAgent });
|
|
316
|
+
const handler = createCopilotRuntimeHandler({
|
|
317
|
+
runtime: errorRuntime,
|
|
318
|
+
basePath: "/api",
|
|
319
|
+
cors: true,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const response = await handler(
|
|
323
|
+
post("http://localhost/api/agent/default/run", {
|
|
324
|
+
threadId: "t1",
|
|
325
|
+
runId: "r1",
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
expect(response).toBeInstanceOf(Response);
|
|
329
|
+
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("error response does not leak error details to clients", async () => {
|
|
333
|
+
const handler = createCopilotRuntimeHandler({
|
|
334
|
+
runtime,
|
|
335
|
+
basePath: "/api",
|
|
336
|
+
hooks: {
|
|
337
|
+
onRequest: () => {
|
|
338
|
+
throw new Error("sensitive internal detail: /home/user/db.sqlite");
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const response = await handler(
|
|
344
|
+
new Request("http://localhost/api/info", { method: "GET" }),
|
|
345
|
+
);
|
|
346
|
+
expect(response.status).toBe(500);
|
|
347
|
+
const body = await response.json();
|
|
348
|
+
expect(body.error).toBe("internal_error");
|
|
349
|
+
// Error message should NOT be exposed to the client
|
|
350
|
+
expect(body.message).toBeUndefined();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("error response returns internal_error for non-Error throws", async () => {
|
|
354
|
+
const handler = createCopilotRuntimeHandler({
|
|
355
|
+
runtime,
|
|
356
|
+
basePath: "/api",
|
|
357
|
+
hooks: {
|
|
358
|
+
onRequest: () => {
|
|
359
|
+
throw "string error";
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const response = await handler(
|
|
365
|
+
new Request("http://localhost/api/info", { method: "GET" }),
|
|
366
|
+
);
|
|
367
|
+
expect(response.status).toBe(500);
|
|
368
|
+
const body = await response.json();
|
|
369
|
+
expect(body.error).toBe("internal_error");
|
|
370
|
+
expect(body.message).toBeUndefined();
|
|
371
|
+
});
|
|
372
|
+
});
|