@copilotkit/runtime 1.54.1 → 1.55.0-next.7
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/.eslintrc.js +4 -4
- package/CHANGELOG.md +113 -113
- package/dist/_virtual/_rolldown/runtime.mjs +25 -1
- package/dist/agent/index.cjs +643 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +263 -0
- package/dist/agent/index.d.cts.map +1 -0
- package/dist/agent/index.d.mts +263 -0
- package/dist/agent/index.d.mts.map +1 -0
- package/dist/agent/index.mjs +635 -0
- package/dist/agent/index.mjs.map +1 -0
- package/dist/graphql/message-conversion/agui-to-gql.cjs.map +1 -1
- package/dist/graphql/message-conversion/agui-to-gql.mjs.map +1 -1
- package/dist/lib/integrations/nextjs/app-router.cjs +2 -2
- package/dist/lib/integrations/nextjs/app-router.cjs.map +1 -1
- package/dist/lib/integrations/nextjs/app-router.mjs +1 -1
- package/dist/lib/integrations/nextjs/app-router.mjs.map +1 -1
- package/dist/lib/integrations/node-http/index.cjs +2 -3
- package/dist/lib/integrations/node-http/index.cjs.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/dist/lib/integrations/node-http/index.mjs.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.cjs +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts +2 -2
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.cts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts +3 -3
- package/dist/lib/runtime/agent-integrations/langgraph/agent.d.mts.map +1 -1
- package/dist/lib/runtime/agent-integrations/langgraph/agent.mjs +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +7 -5
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts +10 -8
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts +10 -8
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +7 -5
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.cjs +2 -2
- package/dist/lib/runtime/telemetry-agent-runner.cjs.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.cts +2 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.cts.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.mts +2 -1
- package/dist/lib/runtime/telemetry-agent-runner.d.mts.map +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.mjs +1 -1
- package/dist/lib/runtime/telemetry-agent-runner.mjs.map +1 -1
- package/dist/lib/telemetry-client.cjs +1 -1
- package/dist/lib/telemetry-client.mjs +1 -1
- package/dist/package.cjs +21 -4
- package/dist/package.mjs +21 -4
- package/dist/service-adapters/anthropic/anthropic-adapter.d.mts +1 -1
- package/dist/v2/index.cjs +41 -15
- package/dist/v2/index.d.cts +14 -2
- package/dist/v2/index.d.mts +14 -2
- package/dist/v2/index.mjs +13 -4
- package/dist/v2/runtime/endpoints/express-single.cjs +190 -0
- package/dist/v2/runtime/endpoints/express-single.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.d.cts +16 -0
- package/dist/v2/runtime/endpoints/express-single.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.d.mts +16 -0
- package/dist/v2/runtime/endpoints/express-single.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/express-single.mjs +187 -0
- package/dist/v2/runtime/endpoints/express-single.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-utils.cjs +119 -0
- package/dist/v2/runtime/endpoints/express-utils.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express-utils.mjs +117 -0
- package/dist/v2/runtime/endpoints/express-utils.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/express.cjs +217 -0
- package/dist/v2/runtime/endpoints/express.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/express.d.cts +16 -0
- package/dist/v2/runtime/endpoints/express.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/express.d.mts +16 -0
- package/dist/v2/runtime/endpoints/express.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/express.mjs +214 -0
- package/dist/v2/runtime/endpoints/express.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.cjs +141 -0
- package/dist/v2/runtime/endpoints/hono-single.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.d.cts +41 -0
- package/dist/v2/runtime/endpoints/hono-single.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.d.mts +41 -0
- package/dist/v2/runtime/endpoints/hono-single.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/hono-single.mjs +140 -0
- package/dist/v2/runtime/endpoints/hono-single.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono.cjs +248 -0
- package/dist/v2/runtime/endpoints/hono.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/hono.d.cts +164 -0
- package/dist/v2/runtime/endpoints/hono.d.cts.map +1 -0
- package/dist/v2/runtime/endpoints/hono.d.mts +164 -0
- package/dist/v2/runtime/endpoints/hono.d.mts.map +1 -0
- package/dist/v2/runtime/endpoints/hono.mjs +247 -0
- package/dist/v2/runtime/endpoints/hono.mjs.map +1 -0
- package/dist/v2/runtime/endpoints/index.d.cts +5 -0
- package/dist/v2/runtime/endpoints/index.d.mts +5 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.cjs +68 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.cjs.map +1 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.mjs +65 -0
- package/dist/v2/runtime/endpoints/single-route-helpers.mjs.map +1 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +51 -0
- package/dist/v2/runtime/handlers/get-runtime-info.cjs.map +1 -0
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +51 -0
- package/dist/v2/runtime/handlers/get-runtime-info.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-connect.cjs +49 -0
- package/dist/v2/runtime/handlers/handle-connect.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-connect.mjs +49 -0
- package/dist/v2/runtime/handlers/handle-connect.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-run.cjs +61 -0
- package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-run.mjs +61 -0
- package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-stop.cjs +47 -0
- package/dist/v2/runtime/handlers/handle-stop.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-stop.mjs +46 -0
- package/dist/v2/runtime/handlers/handle-stop.mjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-transcribe.cjs +112 -0
- package/dist/v2/runtime/handlers/handle-transcribe.cjs.map +1 -0
- package/dist/v2/runtime/handlers/handle-transcribe.mjs +111 -0
- package/dist/v2/runtime/handlers/handle-transcribe.mjs.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.cjs +26 -0
- package/dist/v2/runtime/handlers/header-utils.cjs.map +1 -0
- package/dist/v2/runtime/handlers/header-utils.mjs +25 -0
- package/dist/v2/runtime/handlers/header-utils.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/connect.cjs +37 -0
- package/dist/v2/runtime/handlers/intelligence/connect.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/connect.mjs +37 -0
- package/dist/v2/runtime/handlers/intelligence/connect.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/run.cjs +89 -0
- package/dist/v2/runtime/handlers/intelligence/run.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/run.mjs +88 -0
- package/dist/v2/runtime/handlers/intelligence/run.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +146 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +145 -0
- package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/threads.cjs +159 -0
- package/dist/v2/runtime/handlers/intelligence/threads.cjs.map +1 -0
- package/dist/v2/runtime/handlers/intelligence/threads.mjs +154 -0
- package/dist/v2/runtime/handlers/intelligence/threads.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +74 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +70 -0
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs +21 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs +20 -0
- package/dist/v2/runtime/handlers/shared/intelligence-utils.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/json-response.cjs +12 -0
- package/dist/v2/runtime/handlers/shared/json-response.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/json-response.mjs +10 -0
- package/dist/v2/runtime/handlers/shared/json-response.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs +20 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs +20 -0
- package/dist/v2/runtime/handlers/shared/resolve-intelligence-user.mjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/sse-response.cjs +69 -0
- package/dist/v2/runtime/handlers/shared/sse-response.cjs.map +1 -0
- package/dist/v2/runtime/handlers/shared/sse-response.mjs +68 -0
- package/dist/v2/runtime/handlers/shared/sse-response.mjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/connect.cjs +18 -0
- package/dist/v2/runtime/handlers/sse/connect.cjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/connect.mjs +18 -0
- package/dist/v2/runtime/handlers/sse/connect.mjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/run.cjs +18 -0
- package/dist/v2/runtime/handlers/sse/run.cjs.map +1 -0
- package/dist/v2/runtime/handlers/sse/run.mjs +18 -0
- package/dist/v2/runtime/handlers/sse/run.mjs.map +1 -0
- package/dist/v2/runtime/index.d.cts +13 -0
- package/dist/v2/runtime/index.d.mts +14 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs +333 -0
- package/dist/v2/runtime/intelligence-platform/client.cjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts +336 -0
- package/dist/v2/runtime/intelligence-platform/client.d.cts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts +336 -0
- package/dist/v2/runtime/intelligence-platform/client.d.mts.map +1 -0
- package/dist/v2/runtime/intelligence-platform/client.mjs +331 -0
- package/dist/v2/runtime/intelligence-platform/client.mjs.map +1 -0
- package/dist/v2/runtime/intelligence-platform/index.d.mts +2 -0
- package/dist/v2/runtime/middleware-sse-parser.cjs +138 -0
- package/dist/v2/runtime/middleware-sse-parser.cjs.map +1 -0
- package/dist/v2/runtime/middleware-sse-parser.d.cts +22 -0
- package/dist/v2/runtime/middleware-sse-parser.d.cts.map +1 -0
- package/dist/v2/runtime/middleware-sse-parser.d.mts +22 -0
- package/dist/v2/runtime/middleware-sse-parser.d.mts.map +1 -0
- package/dist/v2/runtime/middleware-sse-parser.mjs +137 -0
- package/dist/v2/runtime/middleware-sse-parser.mjs.map +1 -0
- package/dist/v2/runtime/middleware.cjs +35 -0
- package/dist/v2/runtime/middleware.cjs.map +1 -0
- package/dist/v2/runtime/middleware.d.cts +32 -0
- package/dist/v2/runtime/middleware.d.cts.map +1 -0
- package/dist/v2/runtime/middleware.d.mts +32 -0
- package/dist/v2/runtime/middleware.d.mts.map +1 -0
- package/dist/v2/runtime/middleware.mjs +33 -0
- package/dist/v2/runtime/middleware.mjs.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.cjs +8 -0
- package/dist/v2/runtime/runner/agent-runner.cjs.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.d.cts +32 -0
- package/dist/v2/runtime/runner/agent-runner.d.cts.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.d.mts +32 -0
- package/dist/v2/runtime/runner/agent-runner.d.mts.map +1 -0
- package/dist/v2/runtime/runner/agent-runner.mjs +7 -0
- package/dist/v2/runtime/runner/agent-runner.mjs.map +1 -0
- package/dist/v2/runtime/runner/in-memory.cjs +223 -0
- package/dist/v2/runtime/runner/in-memory.cjs.map +1 -0
- package/dist/v2/runtime/runner/in-memory.d.cts +15 -0
- package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -0
- package/dist/v2/runtime/runner/in-memory.d.mts +15 -0
- package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -0
- package/dist/v2/runtime/runner/in-memory.mjs +222 -0
- package/dist/v2/runtime/runner/in-memory.mjs.map +1 -0
- package/dist/v2/runtime/runner/index.d.cts +6 -0
- package/dist/v2/runtime/runner/index.d.mts +6 -0
- package/dist/v2/runtime/runner/index.mjs +7 -0
- package/dist/v2/runtime/runner/intelligence.cjs +246 -0
- package/dist/v2/runtime/runner/intelligence.cjs.map +1 -0
- package/dist/v2/runtime/runner/intelligence.d.cts +57 -0
- package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -0
- package/dist/v2/runtime/runner/intelligence.d.mts +57 -0
- package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -0
- package/dist/v2/runtime/runner/intelligence.mjs +245 -0
- package/dist/v2/runtime/runner/intelligence.mjs.map +1 -0
- package/dist/v2/runtime/runtime.cjs +101 -0
- package/dist/v2/runtime/runtime.cjs.map +1 -0
- package/dist/v2/runtime/runtime.d.cts +132 -0
- package/dist/v2/runtime/runtime.d.cts.map +1 -0
- package/dist/v2/runtime/runtime.d.mts +133 -0
- package/dist/v2/runtime/runtime.d.mts.map +1 -0
- package/dist/v2/runtime/runtime.mjs +97 -0
- package/dist/v2/runtime/runtime.mjs.map +1 -0
- package/dist/v2/runtime/telemetry/scarf-client.cjs +32 -0
- package/dist/v2/runtime/telemetry/scarf-client.cjs.map +1 -0
- package/dist/v2/runtime/telemetry/scarf-client.mjs +32 -0
- package/dist/v2/runtime/telemetry/scarf-client.mjs.map +1 -0
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +35 -0
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -0
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +35 -0
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.cjs +8 -0
- package/dist/v2/runtime/transcription-service/transcription-service.cjs.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.cts +15 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.cts.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.mts +15 -0
- package/dist/v2/runtime/transcription-service/transcription-service.d.mts.map +1 -0
- package/dist/v2/runtime/transcription-service/transcription-service.mjs +7 -0
- package/dist/v2/runtime/transcription-service/transcription-service.mjs.map +1 -0
- package/package.json +24 -7
- package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +116 -0
- package/src/agent/__tests__/basic-agent.test.ts +1248 -0
- package/src/agent/__tests__/config-tools-execution.test.ts +516 -0
- package/src/agent/__tests__/mcp-clients.test.ts +260 -0
- package/src/agent/__tests__/property-overrides.test.ts +598 -0
- package/src/agent/__tests__/standard-schema-tools.test.ts +313 -0
- package/src/agent/__tests__/standard-schema-types.test.ts +158 -0
- package/src/agent/__tests__/state-tools.test.ts +436 -0
- package/src/agent/__tests__/test-helpers.ts +178 -0
- package/src/agent/__tests__/utils.test.ts +536 -0
- package/src/agent/__tests__/zod-regression.test.ts +350 -0
- package/src/agent/index.ts +1305 -0
- package/src/graphql/message-conversion/agui-to-gql.test.ts +1 -1
- package/src/graphql/message-conversion/agui-to-gql.ts +1 -1
- package/src/graphql/message-conversion/gql-to-agui.ts +1 -1
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +1 -1
- package/src/lib/integrations/nextjs/app-router.ts +2 -2
- package/src/lib/integrations/node-http/index.ts +2 -2
- package/src/lib/runtime/copilot-runtime.ts +3 -5
- package/src/lib/runtime/telemetry-agent-runner.ts +1 -1
- package/src/service-adapters/conversion.test.ts +1 -1
- package/src/service-adapters/conversion.ts +1 -28
- package/src/v2/index.ts +5 -2
- package/src/v2/runtime/__tests__/cors-credentials.test.ts +320 -0
- package/src/v2/runtime/__tests__/express-abort-signal.test.ts +25 -0
- package/src/v2/runtime/__tests__/express-body-order.test.ts +76 -0
- package/src/v2/runtime/__tests__/express-single-sse.test.ts +122 -0
- package/src/v2/runtime/__tests__/get-runtime-info.test.ts +141 -0
- package/src/v2/runtime/__tests__/handle-connect.test.ts +423 -0
- package/src/v2/runtime/__tests__/handle-run.test.ts +910 -0
- package/src/v2/runtime/__tests__/handle-threads.test.ts +388 -0
- package/src/v2/runtime/__tests__/handle-transcribe.test.ts +301 -0
- package/src/v2/runtime/__tests__/header-utils.test.ts +88 -0
- package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +230 -0
- package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +1030 -0
- package/src/v2/runtime/__tests__/middleware-express.test.ts +206 -0
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +211 -0
- package/src/v2/runtime/__tests__/middleware-single.test.ts +225 -0
- package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +187 -0
- package/src/v2/runtime/__tests__/middleware.test.ts +251 -0
- package/src/v2/runtime/__tests__/routing-express.test.ts +174 -0
- package/src/v2/runtime/__tests__/routing-single-express.test.ts +168 -0
- package/src/v2/runtime/__tests__/routing-single.test.ts +193 -0
- package/src/v2/runtime/__tests__/routing.test.ts +257 -0
- package/src/v2/runtime/__tests__/runtime.test.ts +123 -0
- package/src/v2/runtime/__tests__/telemetry.test.ts +167 -0
- package/src/v2/runtime/__tests__/thread-names.test.ts +188 -0
- package/src/v2/runtime/endpoints/express-single.ts +231 -0
- package/src/v2/runtime/endpoints/express-utils.ts +182 -0
- package/src/v2/runtime/endpoints/express.ts +275 -0
- package/src/v2/runtime/endpoints/hono-single.ts +212 -0
- package/src/v2/runtime/endpoints/hono.ts +314 -0
- package/src/v2/runtime/endpoints/index.ts +4 -0
- package/src/v2/runtime/endpoints/single-route-helpers.ts +125 -0
- package/src/v2/runtime/express.ts +2 -0
- package/src/v2/runtime/handler.ts +3 -0
- package/src/v2/runtime/handlers/get-runtime-info.ts +79 -0
- package/src/v2/runtime/handlers/handle-connect.ts +76 -0
- package/src/v2/runtime/handlers/handle-run.ts +89 -0
- package/src/v2/runtime/handlers/handle-stop.ts +76 -0
- package/src/v2/runtime/handlers/handle-threads.ts +7 -0
- package/src/v2/runtime/handlers/handle-transcribe.ts +256 -0
- package/src/v2/runtime/handlers/header-utils.ts +24 -0
- package/src/v2/runtime/handlers/intelligence/connect.ts +65 -0
- package/src/v2/runtime/handlers/intelligence/run.ts +152 -0
- package/src/v2/runtime/handlers/intelligence/thread-names.ts +246 -0
- package/src/v2/runtime/handlers/intelligence/threads.ts +233 -0
- package/src/v2/runtime/handlers/shared/agent-utils.ts +136 -0
- package/src/v2/runtime/handlers/shared/intelligence-utils.ts +21 -0
- package/src/v2/runtime/handlers/shared/json-response.ts +6 -0
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +25 -0
- package/src/v2/runtime/handlers/shared/sse-response.ts +100 -0
- package/src/v2/runtime/handlers/sse/connect.ts +24 -0
- package/src/v2/runtime/handlers/sse/run.ts +27 -0
- package/src/v2/runtime/index.ts +20 -0
- package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +605 -0
- package/src/v2/runtime/intelligence-platform/client.ts +659 -0
- package/src/v2/runtime/intelligence-platform/index.ts +10 -0
- package/src/v2/runtime/middleware-sse-parser.ts +200 -0
- package/src/v2/runtime/middleware.ts +115 -0
- package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +109 -0
- package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +775 -0
- package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +363 -0
- package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +981 -0
- package/src/v2/runtime/runner/agent-runner.ts +36 -0
- package/src/v2/runtime/runner/in-memory.ts +381 -0
- package/src/v2/runtime/runner/index.ts +4 -0
- package/src/v2/runtime/runner/intelligence.ts +429 -0
- package/src/v2/runtime/runtime.ts +260 -0
- package/src/v2/runtime/telemetry/events.ts +35 -0
- package/src/v2/runtime/telemetry/index.ts +7 -0
- package/src/v2/runtime/telemetry/scarf-client.ts +39 -0
- package/src/v2/runtime/telemetry/telemetry-client.ts +70 -0
- package/src/v2/runtime/transcription-service/transcription-service.ts +11 -0
- package/tsconfig.json +9 -2
- package/tsdown.config.ts +1 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parseSSEResponse } from "../middleware-sse-parser";
|
|
3
|
+
|
|
4
|
+
function buildSSEResponse(events: Record<string, unknown>[]): Response {
|
|
5
|
+
const body = events.map((e) => `data: ${JSON.stringify(e)}\n\n`).join("");
|
|
6
|
+
return new Response(body, {
|
|
7
|
+
status: 200,
|
|
8
|
+
headers: { "content-type": "text/event-stream" },
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("parseSSEResponse", () => {
|
|
13
|
+
it("extracts threadId and runId from RUN_STARTED", async () => {
|
|
14
|
+
const response = buildSSEResponse([
|
|
15
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
16
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
17
|
+
]);
|
|
18
|
+
const result = await parseSSEResponse(response);
|
|
19
|
+
expect(result.threadId).toBe("t-1");
|
|
20
|
+
expect(result.runId).toBe("r-1");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("reconstructs a text message from start/content/end events", async () => {
|
|
24
|
+
const response = buildSSEResponse([
|
|
25
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
26
|
+
{ type: "TEXT_MESSAGE_START", messageId: "m-1", role: "assistant" },
|
|
27
|
+
{ type: "TEXT_MESSAGE_CONTENT", messageId: "m-1", delta: "Hello" },
|
|
28
|
+
{ type: "TEXT_MESSAGE_CONTENT", messageId: "m-1", delta: " world" },
|
|
29
|
+
{ type: "TEXT_MESSAGE_END", messageId: "m-1" },
|
|
30
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
31
|
+
]);
|
|
32
|
+
const result = await parseSSEResponse(response);
|
|
33
|
+
expect(result.messages).toHaveLength(1);
|
|
34
|
+
expect(result.messages[0]).toEqual({
|
|
35
|
+
id: "m-1",
|
|
36
|
+
role: "assistant",
|
|
37
|
+
content: "Hello world",
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("reconstructs tool calls on assistant messages", async () => {
|
|
42
|
+
const response = buildSSEResponse([
|
|
43
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
44
|
+
{ type: "TEXT_MESSAGE_START", messageId: "m-1", role: "assistant" },
|
|
45
|
+
{ type: "TEXT_MESSAGE_END", messageId: "m-1" },
|
|
46
|
+
{
|
|
47
|
+
type: "TOOL_CALL_START",
|
|
48
|
+
toolCallId: "tc-1",
|
|
49
|
+
toolCallName: "get_weather",
|
|
50
|
+
parentMessageId: "m-1",
|
|
51
|
+
},
|
|
52
|
+
{ type: "TOOL_CALL_ARGS", toolCallId: "tc-1", delta: '{"city":"NYC"}' },
|
|
53
|
+
{ type: "TOOL_CALL_END", toolCallId: "tc-1" },
|
|
54
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
55
|
+
]);
|
|
56
|
+
const result = await parseSSEResponse(response);
|
|
57
|
+
expect(result.messages).toHaveLength(1);
|
|
58
|
+
expect(result.messages[0]).toMatchObject({
|
|
59
|
+
id: "m-1",
|
|
60
|
+
role: "assistant",
|
|
61
|
+
toolCalls: [{ id: "tc-1", name: "get_weather", args: '{"city":"NYC"}' }],
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("includes tool result messages", async () => {
|
|
66
|
+
const response = buildSSEResponse([
|
|
67
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
68
|
+
{
|
|
69
|
+
type: "TOOL_CALL_RESULT",
|
|
70
|
+
toolCallId: "tc-1",
|
|
71
|
+
messageId: "m-result",
|
|
72
|
+
role: "tool",
|
|
73
|
+
content: "72F sunny",
|
|
74
|
+
},
|
|
75
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
76
|
+
]);
|
|
77
|
+
const result = await parseSSEResponse(response);
|
|
78
|
+
expect(result.messages).toContainEqual({
|
|
79
|
+
id: "m-result",
|
|
80
|
+
role: "tool",
|
|
81
|
+
content: "72F sunny",
|
|
82
|
+
toolCallId: "tc-1",
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("uses MESSAGES_SNAPSHOT when present", async () => {
|
|
87
|
+
const snapshotMessages = [
|
|
88
|
+
{ id: "u-1", role: "user", content: "hi" },
|
|
89
|
+
{ id: "a-1", role: "assistant", content: "hello" },
|
|
90
|
+
];
|
|
91
|
+
const response = buildSSEResponse([
|
|
92
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
93
|
+
{ type: "MESSAGES_SNAPSHOT", messages: snapshotMessages },
|
|
94
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
95
|
+
]);
|
|
96
|
+
const result = await parseSSEResponse(response);
|
|
97
|
+
expect(result.messages).toEqual(snapshotMessages);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("reconstructs a text message from TEXT_MESSAGE_CHUNK events", async () => {
|
|
101
|
+
const response = buildSSEResponse([
|
|
102
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
103
|
+
{
|
|
104
|
+
type: "TEXT_MESSAGE_CHUNK",
|
|
105
|
+
messageId: "m-1",
|
|
106
|
+
role: "assistant",
|
|
107
|
+
delta: "Hello",
|
|
108
|
+
},
|
|
109
|
+
{ type: "TEXT_MESSAGE_CHUNK", messageId: "m-1", delta: " world" },
|
|
110
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
111
|
+
]);
|
|
112
|
+
const result = await parseSSEResponse(response);
|
|
113
|
+
expect(result.messages).toHaveLength(1);
|
|
114
|
+
expect(result.messages[0]).toEqual({
|
|
115
|
+
id: "m-1",
|
|
116
|
+
role: "assistant",
|
|
117
|
+
content: "Hello world",
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("reconstructs tool calls from TOOL_CALL_CHUNK events", async () => {
|
|
122
|
+
const response = buildSSEResponse([
|
|
123
|
+
{ type: "RUN_STARTED", threadId: "t-1", runId: "r-1" },
|
|
124
|
+
{
|
|
125
|
+
type: "TEXT_MESSAGE_CHUNK",
|
|
126
|
+
messageId: "m-1",
|
|
127
|
+
role: "assistant",
|
|
128
|
+
delta: "",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: "TOOL_CALL_CHUNK",
|
|
132
|
+
toolCallId: "tc-1",
|
|
133
|
+
toolCallName: "getWeather",
|
|
134
|
+
parentMessageId: "m-1",
|
|
135
|
+
delta: '{"loc',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: "TOOL_CALL_CHUNK",
|
|
139
|
+
toolCallId: "tc-1",
|
|
140
|
+
parentMessageId: "m-1",
|
|
141
|
+
delta: 'ation":"SF"}',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: "TOOL_CALL_RESULT",
|
|
145
|
+
toolCallId: "tc-1",
|
|
146
|
+
messageId: "m-result",
|
|
147
|
+
content: "18C",
|
|
148
|
+
},
|
|
149
|
+
{ type: "RUN_FINISHED", threadId: "t-1", runId: "r-1" },
|
|
150
|
+
]);
|
|
151
|
+
const result = await parseSSEResponse(response);
|
|
152
|
+
expect(result.messages).toHaveLength(2);
|
|
153
|
+
expect(result.messages[0]).toMatchObject({
|
|
154
|
+
id: "m-1",
|
|
155
|
+
role: "assistant",
|
|
156
|
+
toolCalls: [
|
|
157
|
+
{ id: "tc-1", name: "getWeather", args: '{"location":"SF"}' },
|
|
158
|
+
],
|
|
159
|
+
});
|
|
160
|
+
expect(result.messages[1]).toEqual({
|
|
161
|
+
id: "m-result",
|
|
162
|
+
role: "tool",
|
|
163
|
+
content: "18C",
|
|
164
|
+
toolCallId: "tc-1",
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("returns empty messages for non-SSE responses", async () => {
|
|
169
|
+
const response = new Response(JSON.stringify({ version: "1.0" }), {
|
|
170
|
+
status: 200,
|
|
171
|
+
headers: { "content-type": "application/json" },
|
|
172
|
+
});
|
|
173
|
+
const result = await parseSSEResponse(response);
|
|
174
|
+
expect(result.messages).toEqual([]);
|
|
175
|
+
expect(result.threadId).toBeUndefined();
|
|
176
|
+
expect(result.runId).toBeUndefined();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("handles empty body gracefully", async () => {
|
|
180
|
+
const response = new Response("", {
|
|
181
|
+
status: 200,
|
|
182
|
+
headers: { "content-type": "text/event-stream" },
|
|
183
|
+
});
|
|
184
|
+
const result = await parseSSEResponse(response);
|
|
185
|
+
expect(result.messages).toEqual([]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { vi, type MockedFunction } from "vitest";
|
|
2
|
+
import { createCopilotEndpoint } from "../endpoints";
|
|
3
|
+
import { CopilotRuntime } from "../runtime";
|
|
4
|
+
import { logger } from "@copilotkit/shared";
|
|
5
|
+
import type { AbstractAgent } from "@ag-ui/client";
|
|
6
|
+
import { WebhookStage } from "../middleware";
|
|
7
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
8
|
+
|
|
9
|
+
const dummyRuntime = (opts: Partial<CopilotRuntime> = {}) => {
|
|
10
|
+
const runtime = new CopilotRuntime({
|
|
11
|
+
agents: { agent: {} as unknown as AbstractAgent },
|
|
12
|
+
...opts,
|
|
13
|
+
});
|
|
14
|
+
return runtime;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe("CopilotEndpoint middleware", () => {
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.restoreAllMocks();
|
|
20
|
+
// restore global fetch if it was mocked
|
|
21
|
+
if (fetchMock) {
|
|
22
|
+
global.fetch = originalFetch;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let originalFetch: typeof fetch;
|
|
27
|
+
let fetchMock: MockedFunction<typeof fetch> | null = null;
|
|
28
|
+
|
|
29
|
+
const setupFetchMock = (beforeUrl: string, afterUrl: string) => {
|
|
30
|
+
originalFetch = global.fetch;
|
|
31
|
+
fetchMock = vi.fn().mockImplementation(async (url: string) => {
|
|
32
|
+
if (url === beforeUrl) {
|
|
33
|
+
const body = {
|
|
34
|
+
headers: { "x-modified": "yes" },
|
|
35
|
+
body: { foo: "bar" },
|
|
36
|
+
};
|
|
37
|
+
return new Response(JSON.stringify(body), {
|
|
38
|
+
status: 200,
|
|
39
|
+
headers: { "content-type": "application/json" },
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (url === afterUrl) {
|
|
43
|
+
return new Response(null, { status: 204 });
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Unexpected fetch URL: ${url}`);
|
|
46
|
+
});
|
|
47
|
+
// Override global fetch for the duration of this test
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
global.fetch = fetchMock as unknown as typeof fetch;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
it("processes request through middleware and handler", async () => {
|
|
54
|
+
const originalRequest = new Request("https://example.com/info");
|
|
55
|
+
const modifiedRequest = new Request("https://example.com/info", {
|
|
56
|
+
headers: { "x-modified": "yes" },
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const before = vi.fn().mockResolvedValue(modifiedRequest);
|
|
60
|
+
const after = vi.fn().mockResolvedValue(undefined);
|
|
61
|
+
|
|
62
|
+
const runtime = dummyRuntime({
|
|
63
|
+
beforeRequestMiddleware: before,
|
|
64
|
+
afterRequestMiddleware: after,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
|
|
68
|
+
const response = await endpoint.fetch(originalRequest);
|
|
69
|
+
|
|
70
|
+
expect(before).toHaveBeenCalledWith({
|
|
71
|
+
runtime,
|
|
72
|
+
request: originalRequest,
|
|
73
|
+
path: expect.any(String),
|
|
74
|
+
});
|
|
75
|
+
await new Promise((r) => setImmediate(r));
|
|
76
|
+
expect(after).toHaveBeenCalledWith(
|
|
77
|
+
expect.objectContaining({
|
|
78
|
+
runtime,
|
|
79
|
+
response: expect.any(Response),
|
|
80
|
+
path: expect.any(String),
|
|
81
|
+
}),
|
|
82
|
+
);
|
|
83
|
+
// The response should contain version info from the /info endpoint
|
|
84
|
+
const body = await response.json();
|
|
85
|
+
expect(body).toHaveProperty("version");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("logs and returns Response error from beforeRequestMiddleware", async () => {
|
|
89
|
+
const errorResponse = new Response("Error", { status: 400 });
|
|
90
|
+
const before = vi.fn().mockRejectedValue(errorResponse);
|
|
91
|
+
const after = vi.fn();
|
|
92
|
+
const runtime = dummyRuntime({
|
|
93
|
+
beforeRequestMiddleware: before,
|
|
94
|
+
afterRequestMiddleware: after,
|
|
95
|
+
});
|
|
96
|
+
const logSpy = vi
|
|
97
|
+
.spyOn(logger, "error")
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
.mockImplementation(() => undefined as any);
|
|
100
|
+
|
|
101
|
+
const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
|
|
102
|
+
const response = await endpoint.fetch(
|
|
103
|
+
new Request("https://example.com/info"),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(response.status).toBe(400);
|
|
107
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
108
|
+
expect.objectContaining({
|
|
109
|
+
err: errorResponse,
|
|
110
|
+
url: "https://example.com/info",
|
|
111
|
+
path: expect.any(String),
|
|
112
|
+
}),
|
|
113
|
+
"Error running before request middleware",
|
|
114
|
+
);
|
|
115
|
+
expect(after).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("logs and returns 500 error from beforeRequestMiddleware", async () => {
|
|
119
|
+
const error = new Error("before");
|
|
120
|
+
const before = vi.fn().mockRejectedValue(error);
|
|
121
|
+
const after = vi.fn();
|
|
122
|
+
const runtime = dummyRuntime({
|
|
123
|
+
beforeRequestMiddleware: before,
|
|
124
|
+
afterRequestMiddleware: after,
|
|
125
|
+
});
|
|
126
|
+
const logSpy = vi
|
|
127
|
+
.spyOn(logger, "error")
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
|
+
.mockImplementation(() => undefined as any);
|
|
130
|
+
|
|
131
|
+
const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
|
|
132
|
+
|
|
133
|
+
const response = await endpoint.fetch(
|
|
134
|
+
new Request("https://example.com/info"),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Hono catches errors and returns them as 500 responses
|
|
138
|
+
expect(response.status).toBe(500);
|
|
139
|
+
|
|
140
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
141
|
+
expect.objectContaining({
|
|
142
|
+
err: error,
|
|
143
|
+
url: "https://example.com/info",
|
|
144
|
+
path: expect.any(String),
|
|
145
|
+
}),
|
|
146
|
+
"Error running before request middleware",
|
|
147
|
+
);
|
|
148
|
+
expect(after).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("logs error from handler", async () => {
|
|
152
|
+
// Create a mock agent that throws an error
|
|
153
|
+
const before = vi.fn();
|
|
154
|
+
const after = vi.fn();
|
|
155
|
+
const errorAgent = {
|
|
156
|
+
clone: () => {
|
|
157
|
+
throw new Error("Agent error");
|
|
158
|
+
},
|
|
159
|
+
} as unknown as AbstractAgent;
|
|
160
|
+
|
|
161
|
+
const runtime = dummyRuntime({
|
|
162
|
+
beforeRequestMiddleware: before,
|
|
163
|
+
afterRequestMiddleware: after,
|
|
164
|
+
agents: { errorAgent },
|
|
165
|
+
});
|
|
166
|
+
const logSpy = vi
|
|
167
|
+
.spyOn(logger, "error")
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
169
|
+
.mockImplementation(() => undefined as any);
|
|
170
|
+
|
|
171
|
+
const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
|
|
172
|
+
|
|
173
|
+
const response = await endpoint.fetch(
|
|
174
|
+
new Request("https://example.com/agent/errorAgent/run", {
|
|
175
|
+
method: "POST",
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
// Hono catches errors and returns them as 500 responses
|
|
180
|
+
expect(response.status).toBe(500);
|
|
181
|
+
|
|
182
|
+
// The actual handler logs the error, not the middleware
|
|
183
|
+
expect(logSpy).toHaveBeenCalled();
|
|
184
|
+
// After middleware is called even on error
|
|
185
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
186
|
+
expect(after).toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("passes parsed messages to afterRequestMiddleware", async () => {
|
|
190
|
+
let receivedParams: Record<string, unknown> = {};
|
|
191
|
+
const after = vi.fn().mockImplementation((params) => {
|
|
192
|
+
receivedParams = params;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const runtime = dummyRuntime({
|
|
196
|
+
afterRequestMiddleware: after,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
|
|
200
|
+
const response = await endpoint.fetch(
|
|
201
|
+
new Request("https://example.com/info"),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
await new Promise((r) => setImmediate(r));
|
|
205
|
+
|
|
206
|
+
expect(response).toBeInstanceOf(Response);
|
|
207
|
+
expect(after).toHaveBeenCalled();
|
|
208
|
+
expect(receivedParams).toHaveProperty("messages");
|
|
209
|
+
expect(receivedParams.messages).toEqual([]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("logs but does not rethrow error from afterRequestMiddleware", async () => {
|
|
213
|
+
const error = new Error("after");
|
|
214
|
+
const before = vi.fn();
|
|
215
|
+
const after = vi.fn().mockRejectedValue(error);
|
|
216
|
+
const runtime = dummyRuntime({
|
|
217
|
+
beforeRequestMiddleware: before,
|
|
218
|
+
afterRequestMiddleware: after,
|
|
219
|
+
});
|
|
220
|
+
const logSpy = vi
|
|
221
|
+
.spyOn(logger, "error")
|
|
222
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
|
+
.mockImplementation(() => undefined as any);
|
|
224
|
+
|
|
225
|
+
const endpoint = createCopilotEndpoint({ runtime, basePath: "/" });
|
|
226
|
+
const response = await endpoint.fetch(
|
|
227
|
+
new Request("https://example.com/info"),
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
await new Promise((r) => setImmediate(r));
|
|
231
|
+
|
|
232
|
+
expect(response).toBeInstanceOf(Response);
|
|
233
|
+
expect(after).toHaveBeenCalledWith(
|
|
234
|
+
expect.objectContaining({
|
|
235
|
+
runtime,
|
|
236
|
+
response: expect.any(Response),
|
|
237
|
+
path: expect.any(String),
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
await new Promise((r) => setImmediate(r));
|
|
242
|
+
|
|
243
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
244
|
+
expect.objectContaining({
|
|
245
|
+
err: error,
|
|
246
|
+
url: "https://example.com/info",
|
|
247
|
+
}),
|
|
248
|
+
"Error running after request middleware",
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import request from "supertest";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import type { AbstractAgent } from "@ag-ui/client";
|
|
5
|
+
import { Observable, of } from "rxjs";
|
|
6
|
+
|
|
7
|
+
import { createCopilotEndpointExpress } from "../express";
|
|
8
|
+
import { CopilotRuntime } from "../runtime";
|
|
9
|
+
|
|
10
|
+
vi.mock("../handlers/handle-run", () => ({
|
|
11
|
+
handleRunAgent: vi
|
|
12
|
+
.fn()
|
|
13
|
+
.mockResolvedValue(new Response(null, { status: 200 })),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
vi.mock("../handlers/handle-connect", () => ({
|
|
17
|
+
handleConnectAgent: vi
|
|
18
|
+
.fn()
|
|
19
|
+
.mockResolvedValue(new Response(null, { status: 200 })),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock("../handlers/handle-stop", () => ({
|
|
23
|
+
handleStopAgent: vi
|
|
24
|
+
.fn()
|
|
25
|
+
.mockResolvedValue(new Response(null, { status: 200 })),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
describe("CopilotEndpointExpress routing", () => {
|
|
29
|
+
const createMockRuntime = () => {
|
|
30
|
+
const createMockAgent = () => {
|
|
31
|
+
const agent: unknown = {
|
|
32
|
+
execute: async () => ({ events: [] }),
|
|
33
|
+
};
|
|
34
|
+
(agent as { clone: () => unknown }).clone = () => createMockAgent();
|
|
35
|
+
return agent as AbstractAgent;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const runner = {
|
|
39
|
+
run: () =>
|
|
40
|
+
new Observable((observer) => {
|
|
41
|
+
observer.next({});
|
|
42
|
+
observer.complete();
|
|
43
|
+
return () => undefined;
|
|
44
|
+
}),
|
|
45
|
+
connect: () => of({}),
|
|
46
|
+
stop: async () => true,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return new CopilotRuntime({
|
|
50
|
+
agents: {
|
|
51
|
+
default: createMockAgent(),
|
|
52
|
+
myAgent: createMockAgent(),
|
|
53
|
+
agent123: createMockAgent(),
|
|
54
|
+
"my-agent": createMockAgent(),
|
|
55
|
+
my_agent: createMockAgent(),
|
|
56
|
+
testAgent: createMockAgent(),
|
|
57
|
+
test: createMockAgent(),
|
|
58
|
+
"test%20agent": createMockAgent(),
|
|
59
|
+
"test agent": createMockAgent(),
|
|
60
|
+
},
|
|
61
|
+
runner,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const createApp = () => {
|
|
66
|
+
const runtime = createMockRuntime();
|
|
67
|
+
const app = express();
|
|
68
|
+
app.use(createCopilotEndpointExpress({ runtime, basePath: "/" }));
|
|
69
|
+
return { app, runtime };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
describe("RunAgent route pattern", () => {
|
|
73
|
+
it("matches simple agent name", async () => {
|
|
74
|
+
const { app } = createApp();
|
|
75
|
+
const response = await request(app)
|
|
76
|
+
.post("/agent/myAgent/run")
|
|
77
|
+
.set("Content-Type", "application/json")
|
|
78
|
+
.send({
|
|
79
|
+
messages: [],
|
|
80
|
+
state: {},
|
|
81
|
+
threadId: "thread-1",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(response.status).not.toBe(404);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("matches hyphenated agent name", async () => {
|
|
88
|
+
const { app } = createApp();
|
|
89
|
+
const response = await request(app)
|
|
90
|
+
.post("/agent/my-agent/run")
|
|
91
|
+
.set("Content-Type", "application/json")
|
|
92
|
+
.send({
|
|
93
|
+
messages: [],
|
|
94
|
+
state: {},
|
|
95
|
+
threadId: "thread-1",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(response.status).not.toBe(404);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("matches underscored agent name", async () => {
|
|
102
|
+
const { app } = createApp();
|
|
103
|
+
const response = await request(app)
|
|
104
|
+
.post("/agent/my_agent/run")
|
|
105
|
+
.set("Content-Type", "application/json")
|
|
106
|
+
.send({
|
|
107
|
+
messages: [],
|
|
108
|
+
state: {},
|
|
109
|
+
threadId: "thread-1",
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(response.status).not.toBe(404);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("returns 404 for empty agent name", async () => {
|
|
116
|
+
const { app } = createApp();
|
|
117
|
+
const response = await request(app)
|
|
118
|
+
.post("/agent//run")
|
|
119
|
+
.set("Content-Type", "application/json")
|
|
120
|
+
.send({
|
|
121
|
+
messages: [],
|
|
122
|
+
state: {},
|
|
123
|
+
threadId: "thread-1",
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(response.status).toBe(404);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("Runtime info route", () => {
|
|
131
|
+
it("returns 200 for /info", async () => {
|
|
132
|
+
const { app } = createApp();
|
|
133
|
+
const response = await request(app).get("/info");
|
|
134
|
+
|
|
135
|
+
expect(response.status).toBe(200);
|
|
136
|
+
expect(response.body).toHaveProperty("version");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("returns 404 for non-info path", async () => {
|
|
140
|
+
const { app } = createApp();
|
|
141
|
+
const response = await request(app).get("/agents");
|
|
142
|
+
|
|
143
|
+
expect(response.status).toBe(404);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("Transcribe route", () => {
|
|
148
|
+
it("matches /transcribe", async () => {
|
|
149
|
+
const { app } = createApp();
|
|
150
|
+
const response = await request(app)
|
|
151
|
+
.post("/transcribe")
|
|
152
|
+
.set("Content-Type", "application/json")
|
|
153
|
+
.send({});
|
|
154
|
+
|
|
155
|
+
expect(response.status).not.toBe(404);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("Unmatched routes", () => {
|
|
160
|
+
it("returns 404 for root path", async () => {
|
|
161
|
+
const { app } = createApp();
|
|
162
|
+
const response = await request(app).get("/");
|
|
163
|
+
|
|
164
|
+
expect(response.status).toBe(404);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("returns 404 for unknown paths", async () => {
|
|
168
|
+
const { app } = createApp();
|
|
169
|
+
const response = await request(app).get("/unknown/path");
|
|
170
|
+
|
|
171
|
+
expect(response.status).toBe(404);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|