@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,253 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
2
|
-
import type { ServerHandle } from "../servers/types";
|
|
3
|
-
import { readSSEStream } from "../helpers/sse-reader";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Envelope shape returned in the debug SSE stream.
|
|
7
|
-
*/
|
|
8
|
-
interface DebugEnvelope {
|
|
9
|
-
timestamp: number;
|
|
10
|
-
agentId: string;
|
|
11
|
-
threadId: string;
|
|
12
|
-
runId: string;
|
|
13
|
-
event: { type: string; [key: string]: unknown };
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Parse debug envelopes from SSE payload text.
|
|
18
|
-
* Each `data:` line contains a JSON DebugEventEnvelope.
|
|
19
|
-
*/
|
|
20
|
-
function parseDebugEnvelopes(ssePayload: string): DebugEnvelope[] {
|
|
21
|
-
const envelopes: DebugEnvelope[] = [];
|
|
22
|
-
for (const line of ssePayload.split("\n")) {
|
|
23
|
-
if (!line.startsWith("data:")) continue;
|
|
24
|
-
const json = line.slice("data:".length).trim();
|
|
25
|
-
if (!json) continue;
|
|
26
|
-
try {
|
|
27
|
-
envelopes.push(JSON.parse(json));
|
|
28
|
-
} catch {
|
|
29
|
-
// skip malformed lines
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return envelopes;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Read from a long-lived debug SSE stream until we see a RUN_FINISHED envelope
|
|
37
|
-
* or a timeout elapses. Returns the raw text accumulated.
|
|
38
|
-
*
|
|
39
|
-
* IMPORTANT: The debug SSE stream is long-lived and never closes on its own.
|
|
40
|
-
* We MUST use a timeout to stop reading, and cancel the reader afterwards.
|
|
41
|
-
*/
|
|
42
|
-
async function readDebugStream(
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
stream: ReadableStream<any>,
|
|
45
|
-
opts: { waitMs?: number } = {},
|
|
46
|
-
): Promise<string> {
|
|
47
|
-
const waitMs = opts.waitMs ?? 4_000;
|
|
48
|
-
const reader = stream.getReader();
|
|
49
|
-
const decoder = new TextDecoder();
|
|
50
|
-
let output = "";
|
|
51
|
-
let stopped = false;
|
|
52
|
-
|
|
53
|
-
const timer = setTimeout(() => {
|
|
54
|
-
stopped = true;
|
|
55
|
-
reader.cancel().catch(() => {});
|
|
56
|
-
}, waitMs);
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
while (!stopped) {
|
|
60
|
-
const result = await reader.read().catch(() => ({
|
|
61
|
-
done: true as const,
|
|
62
|
-
value: undefined,
|
|
63
|
-
}));
|
|
64
|
-
if (result.done) break;
|
|
65
|
-
if (result.value) {
|
|
66
|
-
output +=
|
|
67
|
-
typeof result.value === "string"
|
|
68
|
-
? result.value
|
|
69
|
-
: decoder.decode(result.value as Uint8Array, { stream: true });
|
|
70
|
-
if (output.includes("RUN_FINISHED")) {
|
|
71
|
-
stopped = true;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} finally {
|
|
77
|
-
clearTimeout(timer);
|
|
78
|
-
// Do NOT await reader.cancel() — on tee'd streams (created by response.clone()
|
|
79
|
-
// inside the fetch handler), awaiting cancel hangs indefinitely because the
|
|
80
|
-
// other tee branch is never consumed.
|
|
81
|
-
reader.cancel().catch(() => {});
|
|
82
|
-
output += decoder.decode();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return output;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Shared debug-events integration test suite.
|
|
90
|
-
*
|
|
91
|
-
* @param name Display name, e.g. "Express"
|
|
92
|
-
* @param factory Creates & starts the server; returns a handle
|
|
93
|
-
*/
|
|
94
|
-
export function debugEventsSuite(
|
|
95
|
-
name: string,
|
|
96
|
-
factory: (opts?: {
|
|
97
|
-
capturedHeaders?: Record<string, string>[];
|
|
98
|
-
}) => Promise<ServerHandle & { handler?: (r: Request) => Promise<Response> }>,
|
|
99
|
-
) {
|
|
100
|
-
describe(`[${name}] Debug Events`, () => {
|
|
101
|
-
let handle: ServerHandle & { handler?: (r: Request) => Promise<Response> };
|
|
102
|
-
let doFetch: (
|
|
103
|
-
input: RequestInfo | URL,
|
|
104
|
-
init?: RequestInit,
|
|
105
|
-
) => Promise<Response>;
|
|
106
|
-
|
|
107
|
-
beforeAll(async () => {
|
|
108
|
-
handle = await factory();
|
|
109
|
-
doFetch = handle.handler
|
|
110
|
-
? (input, init) =>
|
|
111
|
-
handle.handler!(
|
|
112
|
-
new Request(
|
|
113
|
-
typeof input === "string" || input instanceof URL
|
|
114
|
-
? input
|
|
115
|
-
: input,
|
|
116
|
-
init,
|
|
117
|
-
),
|
|
118
|
-
)
|
|
119
|
-
: fetch;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
afterAll(async () => {
|
|
123
|
-
await handle?.close();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const url = (path: string) => `${handle.baseUrl}${handle.basePath}${path}`;
|
|
127
|
-
|
|
128
|
-
// ─── SSE Format + Events + Envelope Structure ────────────────────
|
|
129
|
-
// Combined into a single test to avoid orphaned debug-stream subscribers
|
|
130
|
-
// across tests (the debug SSE endpoint is long-lived and its cleanup
|
|
131
|
-
// depends on the request signal being aborted).
|
|
132
|
-
|
|
133
|
-
it("streams debug event envelopes with correct structure during an agent run", async () => {
|
|
134
|
-
const controller = new AbortController();
|
|
135
|
-
|
|
136
|
-
// Start the debug stream. For real HTTP servers, fetch blocks until
|
|
137
|
-
// the first chunk arrives, so we also start the agent run concurrently.
|
|
138
|
-
const debugFetchPromise = doFetch(url("/cpk-debug-events"), {
|
|
139
|
-
signal: controller.signal,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Give the subscription a tick to register
|
|
143
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
144
|
-
|
|
145
|
-
// Trigger an agent run. We start it AND begin consuming its stream
|
|
146
|
-
// concurrently with reading the debug stream.
|
|
147
|
-
const runRes = await doFetch(url("/agent/default/run"), {
|
|
148
|
-
method: "POST",
|
|
149
|
-
headers: { "Content-Type": "application/json" },
|
|
150
|
-
body: JSON.stringify({
|
|
151
|
-
threadId: "t-debug-1",
|
|
152
|
-
runId: "r-debug-1",
|
|
153
|
-
messages: [],
|
|
154
|
-
state: {},
|
|
155
|
-
tools: [],
|
|
156
|
-
context: [],
|
|
157
|
-
forwardedProps: {},
|
|
158
|
-
}),
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Consume the run stream and the debug stream concurrently.
|
|
162
|
-
// Both are needed: the debug stream blocks until events arrive,
|
|
163
|
-
// and the run stream must be consumed to avoid backpressure.
|
|
164
|
-
const [debugRes, runPayload] = await Promise.all([
|
|
165
|
-
debugFetchPromise,
|
|
166
|
-
readSSEStream(runRes.body!),
|
|
167
|
-
]);
|
|
168
|
-
|
|
169
|
-
// ── SSE response format ──
|
|
170
|
-
expect(debugRes.status).toBe(200);
|
|
171
|
-
expect(debugRes.headers.get("content-type")).toContain(
|
|
172
|
-
"text/event-stream",
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// Run completed — events should be buffered in the debug stream.
|
|
176
|
-
expect(runPayload).toContain("RUN_FINISHED");
|
|
177
|
-
|
|
178
|
-
// Read the debug stream (events are already in the buffer)
|
|
179
|
-
const debugPayload = await readDebugStream(debugRes.body!, {
|
|
180
|
-
waitMs: 4_000,
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const envelopes = parseDebugEnvelopes(debugPayload);
|
|
184
|
-
|
|
185
|
-
// ── Events flow through ──
|
|
186
|
-
expect(envelopes.length).toBeGreaterThan(0);
|
|
187
|
-
|
|
188
|
-
const eventTypes = envelopes.map((e) => e.event.type);
|
|
189
|
-
expect(eventTypes).toContain("RUN_STARTED");
|
|
190
|
-
expect(eventTypes).toContain("RUN_FINISHED");
|
|
191
|
-
|
|
192
|
-
// ── Envelope structure ──
|
|
193
|
-
for (const envelope of envelopes) {
|
|
194
|
-
expect(typeof envelope.timestamp).toBe("number");
|
|
195
|
-
expect(envelope.timestamp).toBeGreaterThan(0);
|
|
196
|
-
expect(envelope.agentId).toBe("default");
|
|
197
|
-
expect(typeof envelope.threadId).toBe("string");
|
|
198
|
-
expect(typeof envelope.runId).toBe("string");
|
|
199
|
-
expect(envelope.event).toBeDefined();
|
|
200
|
-
expect(typeof envelope.event.type).toBe("string");
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Full event sequence
|
|
204
|
-
expect(eventTypes).toContain("TEXT_MESSAGE_START");
|
|
205
|
-
expect(eventTypes).toContain("TEXT_MESSAGE_CONTENT");
|
|
206
|
-
expect(eventTypes).toContain("TEXT_MESSAGE_END");
|
|
207
|
-
|
|
208
|
-
// Clean up: abort the request so the debug subscriber is removed
|
|
209
|
-
controller.abort();
|
|
210
|
-
}, 15_000);
|
|
211
|
-
|
|
212
|
-
// Regression guard for agentId forwarding on /connect lives in a
|
|
213
|
-
// dedicated unit test (sse-connect-agent-id.test.ts) — driving /connect
|
|
214
|
-
// through the integration runtime doesn't emit events in a
|
|
215
|
-
// test-friendly way, so the unit test feeds a synthetic observable
|
|
216
|
-
// into handleSseConnect and asserts the envelope carries the route
|
|
217
|
-
// agentId rather than the literal string "connect".
|
|
218
|
-
|
|
219
|
-
// ─── HTTP Method Validation ──────────────────────────────────────
|
|
220
|
-
|
|
221
|
-
it("POST /cpk-debug-events returns 405", async () => {
|
|
222
|
-
const res = await doFetch(url("/cpk-debug-events"), { method: "POST" });
|
|
223
|
-
expect(res.status).toBe(405);
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Production guard test -- only needs the fetch-direct handler since
|
|
230
|
-
* it doesn't require a real server. Tests that NODE_ENV=production
|
|
231
|
-
* returns 404 for the debug-events endpoint.
|
|
232
|
-
*/
|
|
233
|
-
export function debugEventsProductionGuardSuite(
|
|
234
|
-
createHandler: () => { handler: (r: Request) => Promise<Response> },
|
|
235
|
-
baseUrl: string,
|
|
236
|
-
basePath: string,
|
|
237
|
-
) {
|
|
238
|
-
describe("[Fetch] Debug Events – production guard", () => {
|
|
239
|
-
it("returns 404 when NODE_ENV=production", async () => {
|
|
240
|
-
const originalEnv = process.env.NODE_ENV;
|
|
241
|
-
try {
|
|
242
|
-
process.env.NODE_ENV = "production";
|
|
243
|
-
const { handler } = createHandler();
|
|
244
|
-
const res = await handler(
|
|
245
|
-
new Request(`${baseUrl}${basePath}/cpk-debug-events`),
|
|
246
|
-
);
|
|
247
|
-
expect(res.status).toBe(404);
|
|
248
|
-
} finally {
|
|
249
|
-
process.env.NODE_ENV = originalEnv;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
}
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|
2
|
-
import type { ServerHandle } from "../servers/types";
|
|
3
|
-
import { readSSEStream, extractEventTypes } from "../helpers/sse-reader";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Shared multi-endpoint test suite.
|
|
7
|
-
*
|
|
8
|
-
* @param name Display name, e.g. "Express"
|
|
9
|
-
* @param factory Creates & starts the server; returns a handle
|
|
10
|
-
* @param requestFn Optional custom fetch function (for direct handler tests)
|
|
11
|
-
*/
|
|
12
|
-
export function multiEndpointSuite(
|
|
13
|
-
name: string,
|
|
14
|
-
factory: (opts?: {
|
|
15
|
-
capturedHeaders?: Record<string, string>[];
|
|
16
|
-
}) => Promise<ServerHandle & { handler?: (r: Request) => Promise<Response> }>,
|
|
17
|
-
requestFn?: (
|
|
18
|
-
input: RequestInfo | URL,
|
|
19
|
-
init?: RequestInit,
|
|
20
|
-
) => Promise<Response>,
|
|
21
|
-
) {
|
|
22
|
-
describe(`[${name}] Multi-Endpoint`, () => {
|
|
23
|
-
let handle: ServerHandle & { handler?: (r: Request) => Promise<Response> };
|
|
24
|
-
let doFetch: (
|
|
25
|
-
input: RequestInfo | URL,
|
|
26
|
-
init?: RequestInit,
|
|
27
|
-
) => Promise<Response>;
|
|
28
|
-
|
|
29
|
-
beforeAll(async () => {
|
|
30
|
-
handle = await factory();
|
|
31
|
-
doFetch =
|
|
32
|
-
requestFn ??
|
|
33
|
-
(handle.handler
|
|
34
|
-
? (input, init) =>
|
|
35
|
-
handle.handler!(
|
|
36
|
-
new Request(
|
|
37
|
-
typeof input === "string" || input instanceof URL
|
|
38
|
-
? input
|
|
39
|
-
: input,
|
|
40
|
-
init,
|
|
41
|
-
),
|
|
42
|
-
)
|
|
43
|
-
: fetch);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
afterAll(async () => {
|
|
47
|
-
await handle?.close();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const url = (path: string) => `${handle.baseUrl}${handle.basePath}${path}`;
|
|
51
|
-
|
|
52
|
-
// ─── Info Endpoint ───────────────────────────────────────────────
|
|
53
|
-
|
|
54
|
-
describe("Info endpoint", () => {
|
|
55
|
-
it("GET /info returns 200", async () => {
|
|
56
|
-
const res = await doFetch(url("/info"));
|
|
57
|
-
expect(res.status).toBe(200);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("GET /info returns version, agents, and audioFileTranscriptionEnabled", async () => {
|
|
61
|
-
const res = await doFetch(url("/info"));
|
|
62
|
-
const body = await res.json();
|
|
63
|
-
expect(body).toHaveProperty("version");
|
|
64
|
-
expect(typeof body.version).toBe("string");
|
|
65
|
-
expect(body).toHaveProperty("agents");
|
|
66
|
-
expect(body.agents).toHaveProperty("default");
|
|
67
|
-
expect(body).toHaveProperty("audioFileTranscriptionEnabled", false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("GET /info agents.default has name field", async () => {
|
|
71
|
-
const res = await doFetch(url("/info"));
|
|
72
|
-
const body = await res.json();
|
|
73
|
-
expect(body.agents.default).toHaveProperty("name");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// ─── Agent Run ───────────────────────────────────────────────────
|
|
78
|
-
|
|
79
|
-
describe("Agent Run", () => {
|
|
80
|
-
it("POST /agent/default/run returns SSE stream", async () => {
|
|
81
|
-
const res = await doFetch(url("/agent/default/run"), {
|
|
82
|
-
method: "POST",
|
|
83
|
-
headers: { "Content-Type": "application/json" },
|
|
84
|
-
body: JSON.stringify({
|
|
85
|
-
threadId: "t-run-1",
|
|
86
|
-
runId: "r-run-1",
|
|
87
|
-
messages: [],
|
|
88
|
-
state: {},
|
|
89
|
-
tools: [],
|
|
90
|
-
context: [],
|
|
91
|
-
forwardedProps: {},
|
|
92
|
-
}),
|
|
93
|
-
});
|
|
94
|
-
expect(res.status).toBe(200);
|
|
95
|
-
expect(res.headers.get("content-type")).toContain("text/event-stream");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("SSE stream contains correct event sequence", async () => {
|
|
99
|
-
const res = await doFetch(url("/agent/default/run"), {
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: { "Content-Type": "application/json" },
|
|
102
|
-
body: JSON.stringify({
|
|
103
|
-
threadId: "t-run-2",
|
|
104
|
-
runId: "r-run-2",
|
|
105
|
-
messages: [],
|
|
106
|
-
state: {},
|
|
107
|
-
tools: [],
|
|
108
|
-
context: [],
|
|
109
|
-
forwardedProps: {},
|
|
110
|
-
}),
|
|
111
|
-
});
|
|
112
|
-
const payload = await readSSEStream(res.body!);
|
|
113
|
-
const types = extractEventTypes(payload);
|
|
114
|
-
|
|
115
|
-
expect(types).toContain("RUN_STARTED");
|
|
116
|
-
expect(types).toContain("TEXT_MESSAGE_START");
|
|
117
|
-
expect(types).toContain("TEXT_MESSAGE_CONTENT");
|
|
118
|
-
expect(types).toContain("TEXT_MESSAGE_END");
|
|
119
|
-
expect(types).toContain("RUN_FINISHED");
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("SSE stream TEXT_MESSAGE_CONTENT contains expected delta", async () => {
|
|
123
|
-
const res = await doFetch(url("/agent/default/run"), {
|
|
124
|
-
method: "POST",
|
|
125
|
-
headers: { "Content-Type": "application/json" },
|
|
126
|
-
body: JSON.stringify({
|
|
127
|
-
threadId: "t-run-3",
|
|
128
|
-
runId: "r-run-3",
|
|
129
|
-
messages: [],
|
|
130
|
-
state: {},
|
|
131
|
-
tools: [],
|
|
132
|
-
context: [],
|
|
133
|
-
forwardedProps: {},
|
|
134
|
-
}),
|
|
135
|
-
});
|
|
136
|
-
const payload = await readSSEStream(res.body!);
|
|
137
|
-
expect(payload).toContain("Hello from test");
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("returns 404 for unknown agent", async () => {
|
|
141
|
-
const res = await doFetch(url("/agent/nonexistent/run"), {
|
|
142
|
-
method: "POST",
|
|
143
|
-
headers: { "Content-Type": "application/json" },
|
|
144
|
-
body: JSON.stringify({
|
|
145
|
-
threadId: "t-404",
|
|
146
|
-
runId: "r-404",
|
|
147
|
-
messages: [],
|
|
148
|
-
state: {},
|
|
149
|
-
tools: [],
|
|
150
|
-
context: [],
|
|
151
|
-
forwardedProps: {},
|
|
152
|
-
}),
|
|
153
|
-
});
|
|
154
|
-
expect(res.status).toBe(404);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// ─── Agent Connect ───────────────────────────────────────────────
|
|
159
|
-
|
|
160
|
-
describe("Agent Connect", () => {
|
|
161
|
-
it("POST /agent/default/connect returns SSE stream", async () => {
|
|
162
|
-
const res = await doFetch(url("/agent/default/connect"), {
|
|
163
|
-
method: "POST",
|
|
164
|
-
headers: { "Content-Type": "application/json" },
|
|
165
|
-
body: JSON.stringify({
|
|
166
|
-
threadId: "t-conn-1",
|
|
167
|
-
runId: "r-conn-1",
|
|
168
|
-
messages: [],
|
|
169
|
-
state: {},
|
|
170
|
-
tools: [],
|
|
171
|
-
context: [],
|
|
172
|
-
forwardedProps: {},
|
|
173
|
-
}),
|
|
174
|
-
});
|
|
175
|
-
expect(res.status).toBe(200);
|
|
176
|
-
expect(res.headers.get("content-type")).toContain("text/event-stream");
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("returns 404 for unknown agent", async () => {
|
|
180
|
-
const res = await doFetch(url("/agent/nonexistent/connect"), {
|
|
181
|
-
method: "POST",
|
|
182
|
-
headers: { "Content-Type": "application/json" },
|
|
183
|
-
body: JSON.stringify({
|
|
184
|
-
threadId: "t-conn-404",
|
|
185
|
-
runId: "r-conn-404",
|
|
186
|
-
messages: [],
|
|
187
|
-
state: {},
|
|
188
|
-
tools: [],
|
|
189
|
-
context: [],
|
|
190
|
-
forwardedProps: {},
|
|
191
|
-
}),
|
|
192
|
-
});
|
|
193
|
-
expect(res.status).toBe(404);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// ─── Agent Stop ──────────────────────────────────────────────────
|
|
198
|
-
|
|
199
|
-
describe("Agent Stop", () => {
|
|
200
|
-
it("POST /agent/default/stop/:threadId returns JSON", async () => {
|
|
201
|
-
const res = await doFetch(url("/agent/default/stop/thread-1"), {
|
|
202
|
-
method: "POST",
|
|
203
|
-
headers: { "Content-Type": "application/json" },
|
|
204
|
-
});
|
|
205
|
-
expect(res.status).toBe(200);
|
|
206
|
-
const body = await res.json();
|
|
207
|
-
expect(body).toHaveProperty("stopped");
|
|
208
|
-
expect(typeof body.stopped).toBe("boolean");
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("returns 404 for unknown agent", async () => {
|
|
212
|
-
const res = await doFetch(url("/agent/nonexistent/stop/thread-1"), {
|
|
213
|
-
method: "POST",
|
|
214
|
-
headers: { "Content-Type": "application/json" },
|
|
215
|
-
});
|
|
216
|
-
expect(res.status).toBe(404);
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// ─── Transcribe ──────────────────────────────────────────────────
|
|
221
|
-
|
|
222
|
-
describe("Transcribe", () => {
|
|
223
|
-
it("POST /transcribe returns 503 without transcription service", async () => {
|
|
224
|
-
const res = await doFetch(url("/transcribe"), {
|
|
225
|
-
method: "POST",
|
|
226
|
-
headers: { "Content-Type": "application/json" },
|
|
227
|
-
body: JSON.stringify({}),
|
|
228
|
-
});
|
|
229
|
-
expect(res.status).toBe(503);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
// ─── CORS ────────────────────────────────────────────────────────
|
|
234
|
-
|
|
235
|
-
describe("CORS", () => {
|
|
236
|
-
it("OPTIONS preflight returns Access-Control-Allow-Origin", async () => {
|
|
237
|
-
const res = await doFetch(url("/info"), {
|
|
238
|
-
method: "OPTIONS",
|
|
239
|
-
headers: {
|
|
240
|
-
Origin: "https://example.com",
|
|
241
|
-
"Access-Control-Request-Method": "GET",
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
expect(res.headers.get("access-control-allow-origin")).toBe("*");
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("GET /info response includes CORS headers", async () => {
|
|
248
|
-
const res = await doFetch(url("/info"), {
|
|
249
|
-
headers: { Origin: "https://example.com" },
|
|
250
|
-
});
|
|
251
|
-
expect(res.headers.get("access-control-allow-origin")).toBe("*");
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
// ─── HTTP Method Validation ──────────────────────────────────────
|
|
256
|
-
|
|
257
|
-
describe("HTTP Method Validation", () => {
|
|
258
|
-
it("POST /info returns 405", async () => {
|
|
259
|
-
const res = await doFetch(url("/info"), { method: "POST" });
|
|
260
|
-
expect(res.status).toBe(405);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("GET /agent/default/run returns 405", async () => {
|
|
264
|
-
const res = await doFetch(url("/agent/default/run"));
|
|
265
|
-
expect(res.status).toBe(405);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// ─── 404 Handling ────────────────────────────────────────────────
|
|
270
|
-
|
|
271
|
-
describe("404 Handling", () => {
|
|
272
|
-
it("GET /nonexistent returns 404", async () => {
|
|
273
|
-
const res = await doFetch(url("/nonexistent"));
|
|
274
|
-
expect(res.status).toBe(404);
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
// ─── Header Forwarding ───────────────────────────────────────────
|
|
279
|
-
|
|
280
|
-
describe("Header Forwarding", () => {
|
|
281
|
-
it("forwards Authorization header to agent", async () => {
|
|
282
|
-
const captured: Record<string, string>[] = [];
|
|
283
|
-
const h = await factory({ capturedHeaders: captured });
|
|
284
|
-
const localFetch =
|
|
285
|
-
requestFn ??
|
|
286
|
-
((h as any).handler
|
|
287
|
-
? (input: any, init: any) =>
|
|
288
|
-
(h as any).handler(new Request(input, init))
|
|
289
|
-
: fetch);
|
|
290
|
-
|
|
291
|
-
try {
|
|
292
|
-
const res = await localFetch(
|
|
293
|
-
`${h.baseUrl}${h.basePath}/agent/default/run`,
|
|
294
|
-
{
|
|
295
|
-
method: "POST",
|
|
296
|
-
headers: {
|
|
297
|
-
"Content-Type": "application/json",
|
|
298
|
-
Authorization: "Bearer test-token",
|
|
299
|
-
},
|
|
300
|
-
body: JSON.stringify({
|
|
301
|
-
threadId: "t-hdr-1",
|
|
302
|
-
runId: "r-hdr-1",
|
|
303
|
-
messages: [],
|
|
304
|
-
state: {},
|
|
305
|
-
tools: [],
|
|
306
|
-
context: [],
|
|
307
|
-
forwardedProps: {},
|
|
308
|
-
}),
|
|
309
|
-
},
|
|
310
|
-
);
|
|
311
|
-
if (res.body) await readSSEStream(res.body);
|
|
312
|
-
expect(captured.length).toBeGreaterThan(0);
|
|
313
|
-
expect(captured[0]!.authorization).toBe("Bearer test-token");
|
|
314
|
-
} finally {
|
|
315
|
-
await h.close();
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it("forwards x-custom headers to agent", async () => {
|
|
320
|
-
const captured: Record<string, string>[] = [];
|
|
321
|
-
const h = await factory({ capturedHeaders: captured });
|
|
322
|
-
const localFetch =
|
|
323
|
-
requestFn ??
|
|
324
|
-
((h as any).handler
|
|
325
|
-
? (input: any, init: any) =>
|
|
326
|
-
(h as any).handler(new Request(input, init))
|
|
327
|
-
: fetch);
|
|
328
|
-
|
|
329
|
-
try {
|
|
330
|
-
const res = await localFetch(
|
|
331
|
-
`${h.baseUrl}${h.basePath}/agent/default/run`,
|
|
332
|
-
{
|
|
333
|
-
method: "POST",
|
|
334
|
-
headers: {
|
|
335
|
-
"Content-Type": "application/json",
|
|
336
|
-
"X-Custom-Value": "my-value",
|
|
337
|
-
},
|
|
338
|
-
body: JSON.stringify({
|
|
339
|
-
threadId: "t-hdr-2",
|
|
340
|
-
runId: "r-hdr-2",
|
|
341
|
-
messages: [],
|
|
342
|
-
state: {},
|
|
343
|
-
tools: [],
|
|
344
|
-
context: [],
|
|
345
|
-
forwardedProps: {},
|
|
346
|
-
}),
|
|
347
|
-
},
|
|
348
|
-
);
|
|
349
|
-
if (res.body) await readSSEStream(res.body);
|
|
350
|
-
expect(captured.length).toBeGreaterThan(0);
|
|
351
|
-
expect(captured[0]!["x-custom-value"]).toBe("my-value");
|
|
352
|
-
} finally {
|
|
353
|
-
await h.close();
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
}
|