@copilotkit/runtime 1.57.3 → 1.58.0-canary.thread-id-propagation
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/dist/lib/observability.d.cts +1 -1
- package/dist/lib/observability.d.cts.map +1 -1
- package/dist/lib/observability.d.mts +1 -1
- package/dist/lib/observability.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.cjs +2 -0
- package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
- package/dist/lib/runtime/copilot-runtime.mjs +2 -0
- package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
- package/dist/package.cjs +5 -8
- package/dist/package.mjs +5 -8
- package/dist/v2/runtime/core/runtime.cjs +4 -1
- package/dist/v2/runtime/core/runtime.cjs.map +1 -1
- package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
- package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
- package/dist/v2/runtime/core/runtime.mjs +4 -1
- package/dist/v2/runtime/core/runtime.mjs.map +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.cjs +1 -1
- package/dist/v2/runtime/handlers/get-runtime-info.mjs +1 -1
- package/dist/v2/runtime/handlers/handle-connect.cjs +1 -1
- package/dist/v2/runtime/handlers/handle-connect.mjs +1 -1
- package/dist/v2/runtime/handlers/handle-run.cjs +1 -1
- package/dist/v2/runtime/handlers/handle-run.mjs +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs +1 -1
- package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.cjs +22 -6
- package/dist/v2/runtime/telemetry/telemetry-client.cjs.map +1 -1
- package/dist/v2/runtime/telemetry/telemetry-client.mjs +27 -11
- package/dist/v2/runtime/telemetry/telemetry-client.mjs.map +1 -1
- package/package.json +9 -19
- package/skills/runtime/SKILL.md +98 -0
- package/skills/runtime/references/agent-runners-custom.md +161 -0
- package/skills/runtime/references/agent-runners-in-memory.md +64 -0
- package/skills/runtime/references/agent-runners-sqlite.md +90 -0
- package/skills/runtime/references/agent-runners.md +304 -0
- package/skills/runtime/references/built-in-agent-factory-modes.md +232 -0
- package/skills/runtime/references/built-in-agent-helper-utilities.md +123 -0
- package/skills/runtime/references/built-in-agent-model-identifiers.md +59 -0
- package/skills/runtime/references/built-in-agent.md +523 -0
- package/skills/runtime/references/intelligence-mode.md +336 -0
- package/skills/runtime/references/middleware.md +376 -0
- package/skills/runtime/references/server-side-tools.md +414 -0
- package/skills/runtime/references/setup-endpoint.md +503 -0
- package/skills/runtime/references/transcription.md +287 -0
- package/skills/runtime/references/wiring-a2a.md +40 -0
- package/skills/runtime/references/wiring-adk.md +45 -0
- package/skills/runtime/references/wiring-ag2.md +41 -0
- package/skills/runtime/references/wiring-agno.md +39 -0
- package/skills/runtime/references/wiring-aws-strands.md +59 -0
- package/skills/runtime/references/wiring-crewai-crews.md +51 -0
- package/skills/runtime/references/wiring-crewai-flows.md +45 -0
- package/skills/runtime/references/wiring-external-agents.md +348 -0
- package/skills/runtime/references/wiring-langgraph.md +50 -0
- package/skills/runtime/references/wiring-llamaindex.md +39 -0
- package/skills/runtime/references/wiring-mastra.md +70 -0
- package/skills/runtime/references/wiring-mcp-apps-middleware.md +68 -0
- package/skills/runtime/references/wiring-ms-agent-framework.md +41 -0
- package/skills/runtime/references/wiring-pydantic-ai.md +45 -0
- package/CHANGELOG.md +0 -3624
- package/__snapshots__/schema/schema.graphql +0 -371
- package/dist/v2/runtime/telemetry/scarf-client.cjs +0 -32
- package/dist/v2/runtime/telemetry/scarf-client.cjs.map +0 -1
- package/dist/v2/runtime/telemetry/scarf-client.mjs +0 -32
- package/dist/v2/runtime/telemetry/scarf-client.mjs.map +0 -1
- package/scripts/generate-gql-schema.ts +0 -16
- package/src/agent/__tests__/agent-test-helpers.ts +0 -476
- package/src/agent/__tests__/agent.test.ts +0 -593
- package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +0 -116
- package/src/agent/__tests__/basic-agent.test.ts +0 -1698
- package/src/agent/__tests__/capabilities.test.ts +0 -81
- package/src/agent/__tests__/config-tools-execution.test.ts +0 -516
- package/src/agent/__tests__/converter-aisdk.test.ts +0 -692
- package/src/agent/__tests__/converter-custom.test.ts +0 -319
- package/src/agent/__tests__/converter-tanstack-input.test.ts +0 -211
- package/src/agent/__tests__/converter-tanstack.test.ts +0 -594
- package/src/agent/__tests__/mcp-clients.test.ts +0 -246
- package/src/agent/__tests__/mcp-servers-integration.test.ts +0 -373
- package/src/agent/__tests__/multimodal-tanstack.test.ts +0 -284
- package/src/agent/__tests__/multimodal.test.ts +0 -176
- package/src/agent/__tests__/property-overrides.test.ts +0 -598
- package/src/agent/__tests__/provider-id-collision.test.ts +0 -195
- package/src/agent/__tests__/standard-schema-tools.test.ts +0 -313
- package/src/agent/__tests__/standard-schema-types.test.ts +0 -158
- package/src/agent/__tests__/state-tools.test.ts +0 -436
- package/src/agent/__tests__/test-helpers.ts +0 -197
- package/src/agent/__tests__/utils.test.ts +0 -536
- package/src/agent/__tests__/zod-regression.test.ts +0 -350
- package/src/agent/converters/aisdk.ts +0 -326
- package/src/agent/converters/index.ts +0 -7
- package/src/agent/converters/tanstack.ts +0 -451
- package/src/agent/index.ts +0 -1743
- package/src/agents/langgraph/__tests__/event-source.test.ts +0 -256
- package/src/agents/langgraph/event-source.ts +0 -365
- package/src/agents/langgraph/events.ts +0 -394
- package/src/graphql/inputs/action.input.ts +0 -16
- package/src/graphql/inputs/agent-session.input.ts +0 -13
- package/src/graphql/inputs/agent-state.input.ts +0 -13
- package/src/graphql/inputs/cloud-guardrails.input.ts +0 -16
- package/src/graphql/inputs/cloud.input.ts +0 -8
- package/src/graphql/inputs/context-property.input.ts +0 -10
- package/src/graphql/inputs/copilot-context.input.ts +0 -10
- package/src/graphql/inputs/custom-property.input.ts +0 -15
- package/src/graphql/inputs/extensions.input.ts +0 -21
- package/src/graphql/inputs/forwarded-parameters.input.ts +0 -22
- package/src/graphql/inputs/frontend.input.ts +0 -14
- package/src/graphql/inputs/generate-copilot-response.input.ts +0 -59
- package/src/graphql/inputs/load-agent-state.input.ts +0 -10
- package/src/graphql/inputs/message.input.ts +0 -110
- package/src/graphql/inputs/meta-event.input.ts +0 -18
- package/src/graphql/message-conversion/agui-to-gql.test.ts +0 -1384
- package/src/graphql/message-conversion/agui-to-gql.ts +0 -384
- package/src/graphql/message-conversion/gql-to-agui.test.ts +0 -1653
- package/src/graphql/message-conversion/gql-to-agui.ts +0 -297
- package/src/graphql/message-conversion/index.ts +0 -2
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +0 -561
- package/src/graphql/resolvers/__tests__/resolve-message-id.test.ts +0 -25
- package/src/graphql/resolvers/copilot.resolver.ts +0 -785
- package/src/graphql/resolvers/resolve-message-id.ts +0 -14
- package/src/graphql/resolvers/state.resolver.ts +0 -30
- package/src/graphql/types/agents-response.type.ts +0 -19
- package/src/graphql/types/base/index.ts +0 -10
- package/src/graphql/types/converted/index.ts +0 -183
- package/src/graphql/types/copilot-response.type.ts +0 -141
- package/src/graphql/types/enums.ts +0 -38
- package/src/graphql/types/extensions-response.type.ts +0 -23
- package/src/graphql/types/guardrails-result.type.ts +0 -20
- package/src/graphql/types/load-agent-state-response.type.ts +0 -17
- package/src/graphql/types/message-status.type.ts +0 -48
- package/src/graphql/types/meta-events.type.ts +0 -78
- package/src/graphql/types/response-status.type.ts +0 -77
- package/src/index.ts +0 -3
- package/src/langgraph.ts +0 -1
- package/src/lib/__tests__/telemetry-disclosure.test.ts +0 -55
- package/src/lib/cloud/index.ts +0 -4
- package/src/lib/error-messages.ts +0 -211
- package/src/lib/index.ts +0 -52
- package/src/lib/integrations/index.ts +0 -6
- package/src/lib/integrations/nest/index.ts +0 -21
- package/src/lib/integrations/nextjs/app-router.ts +0 -47
- package/src/lib/integrations/nextjs/pages-router.ts +0 -45
- package/src/lib/integrations/node-express/index.ts +0 -21
- package/src/lib/integrations/node-http/__tests__/request-duck-type.test.ts +0 -66
- package/src/lib/integrations/node-http/index.ts +0 -187
- package/src/lib/integrations/node-http/request-handler.ts +0 -128
- package/src/lib/integrations/shared.ts +0 -112
- package/src/lib/logger.ts +0 -31
- package/src/lib/observability.ts +0 -167
- package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +0 -183
- package/src/lib/runtime/__tests__/handle-service-adapter.test.ts +0 -108
- package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +0 -499
- package/src/lib/runtime/__tests__/on-after-request.test.ts +0 -122
- package/src/lib/runtime/__tests__/retry-utils.test.ts +0 -137
- package/src/lib/runtime/__tests__/v1-agent-factory.test.ts +0 -109
- package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts +0 -345
- package/src/lib/runtime/agent-integrations/langgraph/__tests__/run-message-filtering.test.ts +0 -156
- package/src/lib/runtime/agent-integrations/langgraph/agent.ts +0 -263
- package/src/lib/runtime/agent-integrations/langgraph/consts.ts +0 -37
- package/src/lib/runtime/agent-integrations/langgraph/index.ts +0 -2
- package/src/lib/runtime/copilot-runtime.ts +0 -863
- package/src/lib/runtime/mcp-tools-utils.ts +0 -313
- package/src/lib/runtime/retry-utils.ts +0 -141
- package/src/lib/runtime/telemetry-agent-runner.ts +0 -151
- package/src/lib/runtime/types.ts +0 -48
- package/src/lib/runtime/utils.ts +0 -93
- package/src/lib/streaming.ts +0 -220
- package/src/lib/telemetry-client.ts +0 -66
- package/src/lib/telemetry-disclosure.ts +0 -53
- package/src/service-adapters/anthropic/anthropic-adapter.ts +0 -532
- package/src/service-adapters/anthropic/utils.ts +0 -219
- package/src/service-adapters/bedrock/bedrock-adapter.ts +0 -73
- package/src/service-adapters/conversion.test.ts +0 -56
- package/src/service-adapters/conversion.ts +0 -69
- package/src/service-adapters/empty/empty-adapter.ts +0 -38
- package/src/service-adapters/events.ts +0 -337
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +0 -84
- package/src/service-adapters/google/google-genai-adapter.test.ts +0 -151
- package/src/service-adapters/google/google-genai-adapter.ts +0 -95
- package/src/service-adapters/groq/groq-adapter.ts +0 -229
- package/src/service-adapters/index.ts +0 -18
- package/src/service-adapters/langchain/langchain-adapter.ts +0 -113
- package/src/service-adapters/langchain/langserve.ts +0 -88
- package/src/service-adapters/langchain/types.ts +0 -20
- package/src/service-adapters/langchain/utils.ts +0 -330
- package/src/service-adapters/openai/__tests__/openai-v5-compat.test.ts +0 -177
- package/src/service-adapters/openai/openai-adapter.ts +0 -324
- package/src/service-adapters/openai/openai-assistant-adapter.ts +0 -385
- package/src/service-adapters/openai/utils.ts +0 -305
- package/src/service-adapters/service-adapter.ts +0 -50
- package/src/service-adapters/shared/error-utils.ts +0 -64
- package/src/service-adapters/shared/index.ts +0 -2
- package/src/service-adapters/shared/sdk-client-utils.ts +0 -19
- package/src/service-adapters/unify/unify-adapter.ts +0 -165
- package/src/utils/failed-response-status-reasons.ts +0 -70
- package/src/utils/index.ts +0 -1
- package/src/v2/express.ts +0 -1
- package/src/v2/hono.ts +0 -1
- package/src/v2/index.ts +0 -5
- package/src/v2/node.ts +0 -1
- package/src/v2/runtime/__tests__/agents-factory.test.ts +0 -136
- package/src/v2/runtime/__tests__/backward-compat.test.ts +0 -261
- package/src/v2/runtime/__tests__/code-review-fixes.test.ts +0 -500
- package/src/v2/runtime/__tests__/cors-credentials.test.ts +0 -320
- package/src/v2/runtime/__tests__/debug-sse-response.test.ts +0 -302
- package/src/v2/runtime/__tests__/express-adapter.test.ts +0 -188
- package/src/v2/runtime/__tests__/express-body-order.test.ts +0 -76
- package/src/v2/runtime/__tests__/express-fetch-bridge.test.ts +0 -344
- package/src/v2/runtime/__tests__/express-single-sse.test.ts +0 -122
- package/src/v2/runtime/__tests__/express-single-telemetry.integration.test.ts +0 -65
- package/src/v2/runtime/__tests__/express-telemetry.integration.test.ts +0 -101
- package/src/v2/runtime/__tests__/fetch-cors.test.ts +0 -205
- package/src/v2/runtime/__tests__/fetch-handler-validation.test.ts +0 -440
- package/src/v2/runtime/__tests__/fetch-handler.test.ts +0 -456
- package/src/v2/runtime/__tests__/fetch-router.test.ts +0 -276
- package/src/v2/runtime/__tests__/get-runtime-info.test.ts +0 -335
- package/src/v2/runtime/__tests__/handle-connect.test.ts +0 -585
- package/src/v2/runtime/__tests__/handle-run.test.ts +0 -1388
- package/src/v2/runtime/__tests__/handle-threads.test.ts +0 -930
- package/src/v2/runtime/__tests__/handle-transcribe.test.ts +0 -301
- package/src/v2/runtime/__tests__/header-utils.test.ts +0 -88
- package/src/v2/runtime/__tests__/hono-adapter.test.ts +0 -150
- package/src/v2/runtime/__tests__/hono-single-telemetry.integration.test.ts +0 -46
- package/src/v2/runtime/__tests__/hono-telemetry.integration.test.ts +0 -99
- package/src/v2/runtime/__tests__/hooks-edge-cases.test.ts +0 -457
- package/src/v2/runtime/__tests__/hooks.test.ts +0 -557
- package/src/v2/runtime/__tests__/in-process-agent-runner-messages.test.ts +0 -230
- package/src/v2/runtime/__tests__/in-process-agent-runner.test.ts +0 -1030
- package/src/v2/runtime/__tests__/integration/bun/bun-servers.integration.test.ts +0 -27
- package/src/v2/runtime/__tests__/integration/bun/elysia-multi.ts +0 -32
- package/src/v2/runtime/__tests__/integration/bun/elysia-single.ts +0 -33
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-multi.ts +0 -25
- package/src/v2/runtime/__tests__/integration/bun/hono-bun-single.ts +0 -32
- package/src/v2/runtime/__tests__/integration/helpers/create-test-runtime.ts +0 -15
- package/src/v2/runtime/__tests__/integration/helpers/sse-reader.ts +0 -45
- package/src/v2/runtime/__tests__/integration/helpers/test-agent.ts +0 -58
- package/src/v2/runtime/__tests__/integration/node-servers.integration.test.ts +0 -58
- package/src/v2/runtime/__tests__/integration/servers/express-multi.ts +0 -35
- package/src/v2/runtime/__tests__/integration/servers/express-single.ts +0 -36
- package/src/v2/runtime/__tests__/integration/servers/fetch-direct.ts +0 -39
- package/src/v2/runtime/__tests__/integration/servers/hono-multi.ts +0 -30
- package/src/v2/runtime/__tests__/integration/servers/hono-single.ts +0 -37
- package/src/v2/runtime/__tests__/integration/servers/node-multi.ts +0 -45
- package/src/v2/runtime/__tests__/integration/servers/node-single.ts +0 -46
- package/src/v2/runtime/__tests__/integration/servers/types.ts +0 -18
- package/src/v2/runtime/__tests__/integration/suites/debug-events.suite.ts +0 -253
- package/src/v2/runtime/__tests__/integration/suites/multi-endpoint.suite.ts +0 -358
- package/src/v2/runtime/__tests__/integration/suites/single-endpoint.suite.ts +0 -363
- package/src/v2/runtime/__tests__/intelligence-run-telemetry.test.ts +0 -194
- package/src/v2/runtime/__tests__/mcp-apps-middleware-integration.test.ts +0 -275
- package/src/v2/runtime/__tests__/middleware-express.test.ts +0 -208
- package/src/v2/runtime/__tests__/middleware-single-express.test.ts +0 -213
- package/src/v2/runtime/__tests__/middleware-single.test.ts +0 -225
- package/src/v2/runtime/__tests__/middleware-sse-parser.test.ts +0 -237
- package/src/v2/runtime/__tests__/middleware.test.ts +0 -250
- package/src/v2/runtime/__tests__/node-fetch-handler.test.ts +0 -157
- package/src/v2/runtime/__tests__/open-generative-ui-middleware.e2e.test.ts +0 -728
- package/src/v2/runtime/__tests__/router-edge-cases.test.ts +0 -217
- package/src/v2/runtime/__tests__/routing-express.test.ts +0 -174
- package/src/v2/runtime/__tests__/routing-single-express.test.ts +0 -168
- package/src/v2/runtime/__tests__/routing-single.test.ts +0 -193
- package/src/v2/runtime/__tests__/routing.test.ts +0 -257
- package/src/v2/runtime/__tests__/runtime.test.ts +0 -234
- package/src/v2/runtime/__tests__/sse-response-telemetry.test.ts +0 -108
- package/src/v2/runtime/__tests__/telemetry.test.ts +0 -167
- package/src/v2/runtime/__tests__/thread-names.test.ts +0 -188
- package/src/v2/runtime/core/__tests__/debug-event-bus.test.ts +0 -156
- package/src/v2/runtime/core/debug-event-bus.ts +0 -45
- package/src/v2/runtime/core/fetch-cors.ts +0 -136
- package/src/v2/runtime/core/fetch-handler.ts +0 -492
- package/src/v2/runtime/core/fetch-router.ts +0 -203
- package/src/v2/runtime/core/hooks.ts +0 -160
- package/src/v2/runtime/core/middleware-sse-parser.ts +0 -210
- package/src/v2/runtime/core/middleware.ts +0 -115
- package/src/v2/runtime/core/runtime.ts +0 -432
- package/src/v2/runtime/endpoints/express-fetch-bridge.ts +0 -137
- package/src/v2/runtime/endpoints/express-single.ts +0 -54
- package/src/v2/runtime/endpoints/express.ts +0 -179
- package/src/v2/runtime/endpoints/hono-single.ts +0 -60
- package/src/v2/runtime/endpoints/hono.ts +0 -89
- package/src/v2/runtime/endpoints/index.ts +0 -4
- package/src/v2/runtime/endpoints/node-fetch-handler.ts +0 -48
- package/src/v2/runtime/endpoints/node.ts +0 -28
- package/src/v2/runtime/endpoints/single-route-helpers.ts +0 -125
- package/src/v2/runtime/express.ts +0 -2
- package/src/v2/runtime/handlers/__tests__/handle-debug-events.test.ts +0 -176
- package/src/v2/runtime/handlers/get-runtime-info.ts +0 -101
- package/src/v2/runtime/handlers/handle-connect.ts +0 -80
- package/src/v2/runtime/handlers/handle-debug-events.ts +0 -52
- package/src/v2/runtime/handlers/handle-run.ts +0 -111
- package/src/v2/runtime/handlers/handle-stop.ts +0 -77
- package/src/v2/runtime/handlers/handle-threads.ts +0 -11
- package/src/v2/runtime/handlers/handle-transcribe.ts +0 -269
- package/src/v2/runtime/handlers/header-utils.ts +0 -24
- package/src/v2/runtime/handlers/intelligence/connect.ts +0 -102
- package/src/v2/runtime/handlers/intelligence/run.ts +0 -351
- package/src/v2/runtime/handlers/intelligence/thread-names.ts +0 -246
- package/src/v2/runtime/handlers/intelligence/threads.ts +0 -420
- package/src/v2/runtime/handlers/shared/agent-utils.ts +0 -154
- package/src/v2/runtime/handlers/shared/intelligence-utils.ts +0 -41
- package/src/v2/runtime/handlers/shared/json-response.ts +0 -9
- package/src/v2/runtime/handlers/shared/resolve-intelligence-user.ts +0 -28
- package/src/v2/runtime/handlers/shared/sse-response.ts +0 -215
- package/src/v2/runtime/handlers/sse/__tests__/sse-connect-agent-id.test.ts +0 -71
- package/src/v2/runtime/handlers/sse/connect.ts +0 -30
- package/src/v2/runtime/handlers/sse/run.ts +0 -40
- package/src/v2/runtime/hono.ts +0 -2
- package/src/v2/runtime/index.ts +0 -51
- package/src/v2/runtime/intelligence-platform/__tests__/client.test.ts +0 -601
- package/src/v2/runtime/intelligence-platform/__tests__/intelligence-mcp-helper.test.ts +0 -246
- package/src/v2/runtime/intelligence-platform/client.ts +0 -818
- package/src/v2/runtime/intelligence-platform/index.ts +0 -10
- package/src/v2/runtime/node.ts +0 -6
- package/src/v2/runtime/open-generative-ui-middleware.ts +0 -373
- package/src/v2/runtime/runner/__tests__/finalize-events.test.ts +0 -109
- package/src/v2/runtime/runner/__tests__/in-memory-runner.e2e.test.ts +0 -775
- package/src/v2/runtime/runner/__tests__/in-memory-runner.test.ts +0 -777
- package/src/v2/runtime/runner/__tests__/intelligence-runner.test.ts +0 -1039
- package/src/v2/runtime/runner/agent-runner.ts +0 -35
- package/src/v2/runtime/runner/in-memory.ts +0 -467
- package/src/v2/runtime/runner/index.ts +0 -4
- package/src/v2/runtime/runner/intelligence.ts +0 -498
- package/src/v2/runtime/telemetry/__tests__/instance-created.test.ts +0 -96
- package/src/v2/runtime/telemetry/events.ts +0 -35
- package/src/v2/runtime/telemetry/index.ts +0 -7
- package/src/v2/runtime/telemetry/instance-created.ts +0 -44
- package/src/v2/runtime/telemetry/scarf-client.ts +0 -39
- package/src/v2/runtime/telemetry/telemetry-client.ts +0 -70
- package/src/v2/runtime/transcription-service/transcription-service.ts +0 -11
- package/tests/global.d.ts +0 -1
- package/tests/service-adapters/anthropic/allowlist-approach.test.ts +0 -259
- package/tests/service-adapters/anthropic/anthropic-adapter-language-model.test.ts +0 -101
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +0 -645
- package/tests/service-adapters/anthropic/utils-token-trimming.test.ts +0 -301
- package/tests/service-adapters/groq/groq-adapter-language-model.test.ts +0 -102
- package/tests/service-adapters/openai/allowlist-approach.test.ts +0 -294
- package/tests/service-adapters/openai/openai-adapter-language-model.test.ts +0 -122
- package/tests/service-adapters/openai/openai-adapter.test.ts +0 -291
- package/tests/service-adapters/shared/sdk-client-utils.test.ts +0 -36
- package/tests/setup.vitest.ts +0 -8
- package/tests/tsconfig.json +0 -10
- package/tsconfig.json +0 -20
- package/tsdown.config.ts +0 -45
- package/typedoc.json +0 -4
- package/vitest.config.mjs +0 -13
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import type { AddressInfo } from "node:net";
|
|
3
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
-
|
|
5
|
-
import { createCopilotEndpointSingleRouteExpress } from "../express";
|
|
6
|
-
import { CopilotRuntime } from "../core/runtime";
|
|
7
|
-
import { InMemoryAgentRunner } from "../runner/in-memory";
|
|
8
|
-
|
|
9
|
-
const buildRuntime = () => {
|
|
10
|
-
const fakeAgent = {
|
|
11
|
-
clone: () => ({
|
|
12
|
-
setMessages: () => undefined,
|
|
13
|
-
setState: () => undefined,
|
|
14
|
-
threadId: "thread",
|
|
15
|
-
runAgent: async (
|
|
16
|
-
input: { runId: string },
|
|
17
|
-
{ onEvent }: { onEvent: (payload: { event: unknown }) => void },
|
|
18
|
-
) => {
|
|
19
|
-
onEvent({
|
|
20
|
-
event: {
|
|
21
|
-
type: "RUN_STARTED",
|
|
22
|
-
runId: input.runId,
|
|
23
|
-
input: { runId: input.runId },
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
onEvent({ event: { type: "TEXT_MESSAGE_START", messageId: "m1" } });
|
|
27
|
-
onEvent({
|
|
28
|
-
event: {
|
|
29
|
-
type: "TEXT_MESSAGE_CONTENT",
|
|
30
|
-
messageId: "m1",
|
|
31
|
-
delta: "hello",
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
onEvent({ event: { type: "TEXT_MESSAGE_END", messageId: "m1" } });
|
|
35
|
-
onEvent({ event: { type: "RUN_FINISHED", runId: input.runId } });
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return new CopilotRuntime({
|
|
41
|
-
agents: { default: fakeAgent },
|
|
42
|
-
runner: new InMemoryAgentRunner(),
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
async function readStreamText(
|
|
47
|
-
stream: ReadableStream<Uint8Array>,
|
|
48
|
-
): Promise<string> {
|
|
49
|
-
const reader = stream.getReader();
|
|
50
|
-
const decoder = new TextDecoder();
|
|
51
|
-
let output = "";
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < 20; i += 1) {
|
|
54
|
-
const { done, value } = await reader.read();
|
|
55
|
-
if (done) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
if (value) {
|
|
59
|
-
output += decoder.decode(value, { stream: true });
|
|
60
|
-
if (output.includes("RUN_FINISHED")) {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
await reader.cancel();
|
|
67
|
-
output += decoder.decode();
|
|
68
|
-
return output;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe("Express single-route SSE streaming", () => {
|
|
72
|
-
let server: ReturnType<express.Express["listen"]> | undefined;
|
|
73
|
-
|
|
74
|
-
afterEach(() => {
|
|
75
|
-
if (server) {
|
|
76
|
-
server.close();
|
|
77
|
-
server = undefined;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("streams SSE events for single-route run requests", async () => {
|
|
82
|
-
const runtime = buildRuntime();
|
|
83
|
-
const app = express();
|
|
84
|
-
app.use(
|
|
85
|
-
createCopilotEndpointSingleRouteExpress({ runtime, basePath: "/" }),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
server = app.listen(0);
|
|
89
|
-
const { port } = server.address() as AddressInfo;
|
|
90
|
-
|
|
91
|
-
const response = await fetch(`http://localhost:${port}/`, {
|
|
92
|
-
method: "POST",
|
|
93
|
-
headers: {
|
|
94
|
-
"Content-Type": "application/json",
|
|
95
|
-
Accept: "text/event-stream",
|
|
96
|
-
},
|
|
97
|
-
body: JSON.stringify({
|
|
98
|
-
method: "agent/run",
|
|
99
|
-
params: { agentId: "default" },
|
|
100
|
-
body: {
|
|
101
|
-
threadId: "thread",
|
|
102
|
-
runId: "run-1",
|
|
103
|
-
messages: [],
|
|
104
|
-
state: {},
|
|
105
|
-
tools: [],
|
|
106
|
-
context: [],
|
|
107
|
-
forwardedProps: {},
|
|
108
|
-
},
|
|
109
|
-
}),
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(response.status).toBe(200);
|
|
113
|
-
expect(response.headers.get("content-type")).toContain("text/event-stream");
|
|
114
|
-
expect(response.body).toBeTruthy();
|
|
115
|
-
|
|
116
|
-
const payload = await readStreamText(response.body!);
|
|
117
|
-
expect(payload).toContain("data:");
|
|
118
|
-
expect(payload).toContain("RUN_STARTED");
|
|
119
|
-
expect(payload).toContain("TEXT_MESSAGE_CONTENT");
|
|
120
|
-
expect(payload).toContain("RUN_FINISHED");
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration test: Express single-route adapter (deprecated convenience
|
|
3
|
-
* wrapper) + telemetry. This adapter delegates to createCopilotExpressHandler
|
|
4
|
-
* with mode: "single-route".
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
7
|
-
import type { AbstractAgent } from "@ag-ui/client";
|
|
8
|
-
import { Observable, of } from "rxjs";
|
|
9
|
-
|
|
10
|
-
import { telemetry } from "../telemetry";
|
|
11
|
-
import { createCopilotEndpointSingleRouteExpress } from "../endpoints/express-single";
|
|
12
|
-
import { CopilotRuntime } from "../core/runtime";
|
|
13
|
-
|
|
14
|
-
function makeAgent(): AbstractAgent {
|
|
15
|
-
const a: unknown = { execute: async () => ({ events: [] }) };
|
|
16
|
-
(a as { clone: () => unknown }).clone = () => makeAgent();
|
|
17
|
-
return a as AbstractAgent;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function makeRuntime() {
|
|
21
|
-
const runner = {
|
|
22
|
-
run: () =>
|
|
23
|
-
new Observable((observer) => {
|
|
24
|
-
observer.next({});
|
|
25
|
-
observer.complete();
|
|
26
|
-
return () => undefined;
|
|
27
|
-
}),
|
|
28
|
-
connect: () => of({}),
|
|
29
|
-
stop: async () => true,
|
|
30
|
-
};
|
|
31
|
-
return new CopilotRuntime({
|
|
32
|
-
agents: { default: makeAgent() },
|
|
33
|
-
runner,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe("Express single-route adapter — telemetry firing (integration)", () => {
|
|
38
|
-
let captureSpy: ReturnType<typeof vi.spyOn>;
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
captureSpy = vi.spyOn(telemetry, "capture").mockResolvedValue(undefined);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
captureSpy.mockRestore();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("fires instance_created on handler creation", async () => {
|
|
49
|
-
const runtime = makeRuntime();
|
|
50
|
-
createCopilotEndpointSingleRouteExpress({
|
|
51
|
-
runtime,
|
|
52
|
-
basePath: "/api/copilotkit",
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
await vi.waitFor(() => {
|
|
56
|
-
expect(captureSpy).toHaveBeenCalledWith(
|
|
57
|
-
"oss.runtime.instance_created",
|
|
58
|
-
expect.objectContaining({
|
|
59
|
-
agentsAmount: 1,
|
|
60
|
-
"cloud.api_key_provided": false,
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration test: Express adapter + telemetry.
|
|
3
|
-
*/
|
|
4
|
-
import express from "express";
|
|
5
|
-
import request from "supertest";
|
|
6
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
7
|
-
import type { AbstractAgent } from "@ag-ui/client";
|
|
8
|
-
import { Observable, of } from "rxjs";
|
|
9
|
-
|
|
10
|
-
import { telemetry } from "../telemetry";
|
|
11
|
-
import { createCopilotExpressHandler } from "../endpoints/express";
|
|
12
|
-
import { CopilotRuntime } from "../core/runtime";
|
|
13
|
-
|
|
14
|
-
function makeAgent(): AbstractAgent {
|
|
15
|
-
const a: unknown = { execute: async () => ({ events: [] }) };
|
|
16
|
-
(a as { clone: () => unknown }).clone = () => makeAgent();
|
|
17
|
-
return a as AbstractAgent;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function makeRuntime() {
|
|
21
|
-
const runner = {
|
|
22
|
-
run: () =>
|
|
23
|
-
new Observable((observer) => {
|
|
24
|
-
observer.next({});
|
|
25
|
-
observer.complete();
|
|
26
|
-
return () => undefined;
|
|
27
|
-
}),
|
|
28
|
-
connect: () => of({}),
|
|
29
|
-
stop: async () => true,
|
|
30
|
-
};
|
|
31
|
-
return new CopilotRuntime({
|
|
32
|
-
agents: { default: makeAgent() },
|
|
33
|
-
runner,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe("Express adapter — telemetry firing (integration)", () => {
|
|
38
|
-
let captureSpy: ReturnType<typeof vi.spyOn>;
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
captureSpy = vi.spyOn(telemetry, "capture").mockResolvedValue(undefined);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
captureSpy.mockRestore();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("fires instance_created on handler creation (multi-route)", async () => {
|
|
49
|
-
const runtime = makeRuntime();
|
|
50
|
-
createCopilotExpressHandler({ runtime, basePath: "/" });
|
|
51
|
-
|
|
52
|
-
await vi.waitFor(() => {
|
|
53
|
-
expect(captureSpy).toHaveBeenCalledWith(
|
|
54
|
-
"oss.runtime.instance_created",
|
|
55
|
-
expect.objectContaining({
|
|
56
|
-
agentsAmount: 1,
|
|
57
|
-
"cloud.api_key_provided": false,
|
|
58
|
-
}),
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("fires copilot_request_created when a real HTTP request hits the handler", async () => {
|
|
64
|
-
const runtime = makeRuntime();
|
|
65
|
-
const app = express();
|
|
66
|
-
app.use(createCopilotExpressHandler({ runtime, basePath: "/" }));
|
|
67
|
-
|
|
68
|
-
await request(app)
|
|
69
|
-
.post("/agent/default/run")
|
|
70
|
-
.set("Content-Type", "application/json")
|
|
71
|
-
.send({ messages: [], state: {}, threadId: "t1" });
|
|
72
|
-
|
|
73
|
-
expect(captureSpy).toHaveBeenCalledWith(
|
|
74
|
-
"oss.runtime.copilot_request_created",
|
|
75
|
-
expect.objectContaining({
|
|
76
|
-
requestType: "run",
|
|
77
|
-
"cloud.api_key_provided": false,
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("includes cloud.public_api_key on request when header is present", async () => {
|
|
83
|
-
const runtime = makeRuntime();
|
|
84
|
-
const app = express();
|
|
85
|
-
app.use(createCopilotExpressHandler({ runtime, basePath: "/" }));
|
|
86
|
-
|
|
87
|
-
await request(app)
|
|
88
|
-
.post("/agent/default/run")
|
|
89
|
-
.set("Content-Type", "application/json")
|
|
90
|
-
.set("x-copilotcloud-public-api-key", "ck_pub_test_xyz")
|
|
91
|
-
.send({ messages: [], state: {}, threadId: "t1" });
|
|
92
|
-
|
|
93
|
-
expect(captureSpy).toHaveBeenCalledWith(
|
|
94
|
-
"oss.runtime.copilot_request_created",
|
|
95
|
-
expect.objectContaining({
|
|
96
|
-
"cloud.api_key_provided": true,
|
|
97
|
-
"cloud.public_api_key": "ck_pub_test_xyz",
|
|
98
|
-
}),
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { handleCors, addCorsHeaders } from "../core/fetch-cors";
|
|
3
|
-
import type { CopilotCorsConfig } from "../core/fetch-cors";
|
|
4
|
-
|
|
5
|
-
describe("fetch-cors", () => {
|
|
6
|
-
describe("handleCors (preflight)", () => {
|
|
7
|
-
it("returns null for non-OPTIONS requests", () => {
|
|
8
|
-
const request = new Request("http://localhost/api", { method: "GET" });
|
|
9
|
-
expect(handleCors(request, {})).toBeNull();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("returns null for POST requests", () => {
|
|
13
|
-
const request = new Request("http://localhost/api", { method: "POST" });
|
|
14
|
-
expect(handleCors(request, {})).toBeNull();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("returns 204 for OPTIONS requests", () => {
|
|
18
|
-
const request = new Request("http://localhost/api", {
|
|
19
|
-
method: "OPTIONS",
|
|
20
|
-
});
|
|
21
|
-
const response = handleCors(request, {});
|
|
22
|
-
expect(response).not.toBeNull();
|
|
23
|
-
expect(response!.status).toBe(204);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("adds permissive CORS headers with empty config (cors: true equivalent)", () => {
|
|
27
|
-
const request = new Request("http://localhost/api", {
|
|
28
|
-
method: "OPTIONS",
|
|
29
|
-
});
|
|
30
|
-
const response = handleCors(request, {})!;
|
|
31
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
32
|
-
expect(response.headers.get("Access-Control-Allow-Methods")).toContain(
|
|
33
|
-
"GET",
|
|
34
|
-
);
|
|
35
|
-
expect(response.headers.get("Access-Control-Allow-Methods")).toContain(
|
|
36
|
-
"POST",
|
|
37
|
-
);
|
|
38
|
-
expect(response.headers.get("Access-Control-Allow-Headers")).toBe("*");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("reflects custom origin string", () => {
|
|
42
|
-
const request = new Request("http://localhost/api", {
|
|
43
|
-
method: "OPTIONS",
|
|
44
|
-
headers: { Origin: "https://myapp.com" },
|
|
45
|
-
});
|
|
46
|
-
const config: CopilotCorsConfig = { origin: "https://myapp.com" };
|
|
47
|
-
const response = handleCors(request, config)!;
|
|
48
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe(
|
|
49
|
-
"https://myapp.com",
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("reflects request origin when in allowed array", () => {
|
|
54
|
-
const request = new Request("http://localhost/api", {
|
|
55
|
-
method: "OPTIONS",
|
|
56
|
-
headers: { Origin: "https://b.com" },
|
|
57
|
-
});
|
|
58
|
-
const config: CopilotCorsConfig = {
|
|
59
|
-
origin: ["https://a.com", "https://b.com"],
|
|
60
|
-
};
|
|
61
|
-
const response = handleCors(request, config)!;
|
|
62
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe(
|
|
63
|
-
"https://b.com",
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("does not set origin when request origin is not in allowed array", () => {
|
|
68
|
-
const request = new Request("http://localhost/api", {
|
|
69
|
-
method: "OPTIONS",
|
|
70
|
-
headers: { Origin: "https://c.com" },
|
|
71
|
-
});
|
|
72
|
-
const config: CopilotCorsConfig = {
|
|
73
|
-
origin: ["https://a.com", "https://b.com"],
|
|
74
|
-
};
|
|
75
|
-
const response = handleCors(request, config)!;
|
|
76
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBeNull();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("uses origin function to resolve", () => {
|
|
80
|
-
const request = new Request("http://localhost/api", {
|
|
81
|
-
method: "OPTIONS",
|
|
82
|
-
headers: { Origin: "https://dynamic.com" },
|
|
83
|
-
});
|
|
84
|
-
const config: CopilotCorsConfig = {
|
|
85
|
-
origin: (origin: string) => (origin.endsWith(".com") ? origin : null),
|
|
86
|
-
};
|
|
87
|
-
const response = handleCors(request, config)!;
|
|
88
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe(
|
|
89
|
-
"https://dynamic.com",
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("sets credentials header when configured", () => {
|
|
94
|
-
const request = new Request("http://localhost/api", {
|
|
95
|
-
method: "OPTIONS",
|
|
96
|
-
headers: { Origin: "https://myapp.com" },
|
|
97
|
-
});
|
|
98
|
-
const config: CopilotCorsConfig = {
|
|
99
|
-
origin: "https://myapp.com",
|
|
100
|
-
credentials: true,
|
|
101
|
-
};
|
|
102
|
-
const response = handleCors(request, config)!;
|
|
103
|
-
expect(response.headers.get("Access-Control-Allow-Credentials")).toBe(
|
|
104
|
-
"true",
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("sets custom allowMethods", () => {
|
|
109
|
-
const request = new Request("http://localhost/api", {
|
|
110
|
-
method: "OPTIONS",
|
|
111
|
-
});
|
|
112
|
-
const config: CopilotCorsConfig = { allowMethods: ["GET", "POST"] };
|
|
113
|
-
const response = handleCors(request, config)!;
|
|
114
|
-
expect(response.headers.get("Access-Control-Allow-Methods")).toBe(
|
|
115
|
-
"GET, POST",
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("sets custom allowHeaders", () => {
|
|
120
|
-
const request = new Request("http://localhost/api", {
|
|
121
|
-
method: "OPTIONS",
|
|
122
|
-
});
|
|
123
|
-
const config: CopilotCorsConfig = {
|
|
124
|
-
allowHeaders: ["Content-Type", "Authorization"],
|
|
125
|
-
};
|
|
126
|
-
const response = handleCors(request, config)!;
|
|
127
|
-
expect(response.headers.get("Access-Control-Allow-Headers")).toBe(
|
|
128
|
-
"Content-Type, Authorization",
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("sets maxAge header", () => {
|
|
133
|
-
const request = new Request("http://localhost/api", {
|
|
134
|
-
method: "OPTIONS",
|
|
135
|
-
});
|
|
136
|
-
const config: CopilotCorsConfig = { maxAge: 86400 };
|
|
137
|
-
const response = handleCors(request, config)!;
|
|
138
|
-
expect(response.headers.get("Access-Control-Max-Age")).toBe("86400");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("auto-resolves wildcard to request origin when credentials enabled", () => {
|
|
142
|
-
const request = new Request("http://localhost/api", {
|
|
143
|
-
method: "OPTIONS",
|
|
144
|
-
headers: { Origin: "https://example.com" },
|
|
145
|
-
});
|
|
146
|
-
const config: CopilotCorsConfig = { origin: "*", credentials: true };
|
|
147
|
-
const response = handleCors(request, config)!;
|
|
148
|
-
// Per Fetch spec, wildcard + credentials is invalid. We auto-resolve
|
|
149
|
-
// the wildcard to the actual request origin when credentials are enabled.
|
|
150
|
-
expect(response.headers.get("Access-Control-Allow-Origin")).toBe(
|
|
151
|
-
"https://example.com",
|
|
152
|
-
);
|
|
153
|
-
expect(response.headers.get("Access-Control-Allow-Credentials")).toBe(
|
|
154
|
-
"true",
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe("addCorsHeaders (response decoration)", () => {
|
|
160
|
-
it("adds CORS headers to an existing response", () => {
|
|
161
|
-
const response = new Response(JSON.stringify({ ok: true }), {
|
|
162
|
-
status: 200,
|
|
163
|
-
headers: { "Content-Type": "application/json" },
|
|
164
|
-
});
|
|
165
|
-
const config: CopilotCorsConfig = {};
|
|
166
|
-
const result = addCorsHeaders(response, config, null);
|
|
167
|
-
expect(result.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
168
|
-
expect(result.headers.get("Content-Type")).toBe("application/json");
|
|
169
|
-
expect(result.status).toBe(200);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("adds CORS headers to error responses", () => {
|
|
173
|
-
const response = new Response("Not found", { status: 404 });
|
|
174
|
-
const config: CopilotCorsConfig = {};
|
|
175
|
-
const result = addCorsHeaders(response, config, null);
|
|
176
|
-
expect(result.headers.get("Access-Control-Allow-Origin")).toBe("*");
|
|
177
|
-
expect(result.status).toBe(404);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("sets exposeHeaders", () => {
|
|
181
|
-
const response = new Response(null, { status: 200 });
|
|
182
|
-
const config: CopilotCorsConfig = {
|
|
183
|
-
exposeHeaders: ["X-Request-Id", "X-Custom"],
|
|
184
|
-
};
|
|
185
|
-
const result = addCorsHeaders(response, config, null);
|
|
186
|
-
expect(result.headers.get("Access-Control-Expose-Headers")).toBe(
|
|
187
|
-
"X-Request-Id, X-Custom",
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("adds Vary: Origin when origin is not wildcard", () => {
|
|
192
|
-
const response = new Response(null, { status: 200 });
|
|
193
|
-
const config: CopilotCorsConfig = { origin: "https://myapp.com" };
|
|
194
|
-
const result = addCorsHeaders(response, config, "https://myapp.com");
|
|
195
|
-
expect(result.headers.get("Vary")).toContain("Origin");
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("does not add Vary when origin is wildcard", () => {
|
|
199
|
-
const response = new Response(null, { status: 200 });
|
|
200
|
-
const config: CopilotCorsConfig = {};
|
|
201
|
-
const result = addCorsHeaders(response, config, null);
|
|
202
|
-
expect(result.headers.get("Vary")).toBeNull();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|