@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,137 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { fetchWithRetry, parseRetryAfter, RETRY_CONFIG } from "../retry-utils";
|
|
3
|
-
|
|
4
|
-
function responseWithRetryAfter(
|
|
5
|
-
headerValue: string | null,
|
|
6
|
-
status = 429,
|
|
7
|
-
): Response {
|
|
8
|
-
const headers = new Headers();
|
|
9
|
-
if (headerValue !== null) headers.set("Retry-After", headerValue);
|
|
10
|
-
return new Response(null, { status, headers });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe("parseRetryAfter", () => {
|
|
14
|
-
it("returns undefined when the Retry-After header is absent", () => {
|
|
15
|
-
expect(parseRetryAfter(responseWithRetryAfter(null))).toBeUndefined();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("parses integer seconds into milliseconds", () => {
|
|
19
|
-
expect(parseRetryAfter(responseWithRetryAfter("5"))).toBe(5000);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("treats zero seconds as zero delay", () => {
|
|
23
|
-
expect(parseRetryAfter(responseWithRetryAfter("0"))).toBe(0);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("clamps a negative numeric value to zero", () => {
|
|
27
|
-
// `-1` fails the `seconds >= 0` guard and falls through to Date.parse,
|
|
28
|
-
// which interprets it as a year-in-the-past timestamp; the past-date
|
|
29
|
-
// branch then clamps to 0. The behavior is lenient rather than strict.
|
|
30
|
-
expect(parseRetryAfter(responseWithRetryAfter("-1"))).toBe(0);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("parses an HTTP-date in the future as the delta to now", () => {
|
|
34
|
-
const now = Date.parse("2026-04-22T12:00:00Z");
|
|
35
|
-
vi.useFakeTimers();
|
|
36
|
-
vi.setSystemTime(now);
|
|
37
|
-
try {
|
|
38
|
-
const future = new Date(now + 30_000).toUTCString();
|
|
39
|
-
expect(parseRetryAfter(responseWithRetryAfter(future))).toBe(30_000);
|
|
40
|
-
} finally {
|
|
41
|
-
vi.useRealTimers();
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("clamps an HTTP-date in the past to zero", () => {
|
|
46
|
-
const now = Date.parse("2026-04-22T12:00:00Z");
|
|
47
|
-
vi.useFakeTimers();
|
|
48
|
-
vi.setSystemTime(now);
|
|
49
|
-
try {
|
|
50
|
-
const past = new Date(now - 60_000).toUTCString();
|
|
51
|
-
expect(parseRetryAfter(responseWithRetryAfter(past))).toBe(0);
|
|
52
|
-
} finally {
|
|
53
|
-
vi.useRealTimers();
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("returns undefined for unparseable values", () => {
|
|
58
|
-
expect(parseRetryAfter(responseWithRetryAfter("soon"))).toBeUndefined();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("fetchWithRetry Retry-After handling (#3637)", () => {
|
|
63
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
vi.useFakeTimers();
|
|
67
|
-
fetchMock = vi.fn();
|
|
68
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
afterEach(() => {
|
|
72
|
-
vi.useRealTimers();
|
|
73
|
-
vi.unstubAllGlobals();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("honors Retry-After within the allowed maximum on 429", async () => {
|
|
77
|
-
fetchMock
|
|
78
|
-
.mockResolvedValueOnce(responseWithRetryAfter("2"))
|
|
79
|
-
.mockResolvedValueOnce(new Response("ok", { status: 200 }));
|
|
80
|
-
|
|
81
|
-
const promise = fetchWithRetry("https://example.com", {});
|
|
82
|
-
await vi.advanceTimersByTimeAsync(1999);
|
|
83
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
84
|
-
await vi.advanceTimersByTimeAsync(1);
|
|
85
|
-
const response = await promise;
|
|
86
|
-
|
|
87
|
-
expect(response.status).toBe(200);
|
|
88
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("throws when Retry-After exceeds maxRetryAfterSeconds", async () => {
|
|
92
|
-
const excessive = RETRY_CONFIG.maxRetryAfterSeconds + 1;
|
|
93
|
-
fetchMock.mockResolvedValue(responseWithRetryAfter(String(excessive)));
|
|
94
|
-
|
|
95
|
-
// The oversized-Retry-After branch throws before sleeping, and the
|
|
96
|
-
// resulting Error doesn't match any retryable pattern, so the loop
|
|
97
|
-
// breaks out without consuming the remaining attempts.
|
|
98
|
-
await expect(fetchWithRetry("https://example.com", {})).rejects.toThrow(
|
|
99
|
-
new RegExp(
|
|
100
|
-
`Retry-After of ${excessive}s.*exceeds the maximum of ${RETRY_CONFIG.maxRetryAfterSeconds}s`,
|
|
101
|
-
),
|
|
102
|
-
);
|
|
103
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("falls back to exponential backoff when Retry-After is missing on 429", async () => {
|
|
107
|
-
fetchMock
|
|
108
|
-
.mockResolvedValueOnce(new Response(null, { status: 429 }))
|
|
109
|
-
.mockResolvedValueOnce(new Response("ok", { status: 200 }));
|
|
110
|
-
|
|
111
|
-
const promise = fetchWithRetry("https://example.com", {});
|
|
112
|
-
// calculateDelay(0) === RETRY_CONFIG.baseDelayMs
|
|
113
|
-
await vi.advanceTimersByTimeAsync(RETRY_CONFIG.baseDelayMs - 1);
|
|
114
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
115
|
-
await vi.advanceTimersByTimeAsync(1);
|
|
116
|
-
const response = await promise;
|
|
117
|
-
|
|
118
|
-
expect(response.status).toBe(200);
|
|
119
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("ignores Retry-After on non-429 retryable responses (e.g. 503)", async () => {
|
|
123
|
-
const longRetryAfter = String(RETRY_CONFIG.maxRetryAfterSeconds + 600);
|
|
124
|
-
fetchMock
|
|
125
|
-
.mockResolvedValueOnce(responseWithRetryAfter(longRetryAfter, 503))
|
|
126
|
-
.mockResolvedValueOnce(new Response("ok", { status: 200 }));
|
|
127
|
-
|
|
128
|
-
const promise = fetchWithRetry("https://example.com", {});
|
|
129
|
-
// Exponential backoff applies, not the header value — otherwise this
|
|
130
|
-
// would wait 10 minutes and the test would time out.
|
|
131
|
-
await vi.advanceTimersByTimeAsync(RETRY_CONFIG.baseDelayMs);
|
|
132
|
-
const response = await promise;
|
|
133
|
-
|
|
134
|
-
expect(response.status).toBe(200);
|
|
135
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { HttpAgent } from "@ag-ui/client";
|
|
3
|
-
import { CopilotRuntime } from "../copilot-runtime";
|
|
4
|
-
import {
|
|
5
|
-
resolveAgents,
|
|
6
|
-
type AgentsConfig,
|
|
7
|
-
} from "../../../v2/runtime/core/runtime";
|
|
8
|
-
|
|
9
|
-
function createMockAgent(name = "test") {
|
|
10
|
-
return new HttpAgent({ url: `https://example.com/${name}` });
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createMockRequest(headers?: Record<string, string>) {
|
|
14
|
-
return new Request("https://example.com/agent/test/run", {
|
|
15
|
-
method: "POST",
|
|
16
|
-
headers: { "Content-Type": "application/json", ...headers },
|
|
17
|
-
body: JSON.stringify({ threadId: "thread-1", messages: [], state: {} }),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe("V1 CopilotRuntime with agent factory function", () => {
|
|
22
|
-
it("preserves factory function through constructor (does not spread to {})", () => {
|
|
23
|
-
const factory = vi.fn().mockReturnValue({
|
|
24
|
-
default: createMockAgent("default"),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const runtime = new CopilotRuntime({ agents: factory });
|
|
28
|
-
|
|
29
|
-
// The V2 instance should receive a function (factory), not an empty object.
|
|
30
|
-
// Before the fix, spreading a function produced {}, losing all agents.
|
|
31
|
-
const v2Agents = runtime.instance.agents;
|
|
32
|
-
expect(typeof v2Agents).toBe("function");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("factory function resolves agents on each request", async () => {
|
|
36
|
-
const agentA = createMockAgent("tenant-a");
|
|
37
|
-
const agentB = createMockAgent("tenant-b");
|
|
38
|
-
|
|
39
|
-
const factory: AgentsConfig = ({ request }) => {
|
|
40
|
-
const tenantId = request.headers.get("x-tenant-id");
|
|
41
|
-
if (tenantId === "a") return { default: agentA };
|
|
42
|
-
return { default: agentB };
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const runtime = new CopilotRuntime({ agents: factory });
|
|
46
|
-
const v2Agents = runtime.instance.agents;
|
|
47
|
-
|
|
48
|
-
const requestA = createMockRequest({ "x-tenant-id": "a" });
|
|
49
|
-
const resolvedA = await resolveAgents(v2Agents, requestA);
|
|
50
|
-
expect(resolvedA.default).toBe(agentA);
|
|
51
|
-
|
|
52
|
-
const requestB = createMockRequest({ "x-tenant-id": "b" });
|
|
53
|
-
const resolvedB = await resolveAgents(v2Agents, requestB);
|
|
54
|
-
expect(resolvedB.default).toBe(agentB);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("merges endpoint agents with factory-resolved agents", async () => {
|
|
58
|
-
const factoryAgent = createMockAgent("factory-agent");
|
|
59
|
-
const factory = vi.fn().mockReturnValue({
|
|
60
|
-
dynamic: factoryAgent,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Use remoteEndpoints to generate endpoint agents that should be merged
|
|
64
|
-
const runtime = new CopilotRuntime({
|
|
65
|
-
agents: factory,
|
|
66
|
-
remoteEndpoints: [
|
|
67
|
-
{
|
|
68
|
-
url: "https://example.com/endpoint",
|
|
69
|
-
onBeforeRequest: undefined,
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const v2Agents = runtime.instance.agents;
|
|
75
|
-
expect(typeof v2Agents).toBe("function");
|
|
76
|
-
|
|
77
|
-
const request = createMockRequest();
|
|
78
|
-
const resolved = await resolveAgents(v2Agents, request);
|
|
79
|
-
|
|
80
|
-
// Factory agent should be present
|
|
81
|
-
expect(resolved.dynamic).toBe(factoryAgent);
|
|
82
|
-
// Factory should have been called with request context
|
|
83
|
-
expect(factory).toHaveBeenCalledWith({ request });
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("static agents record still works after fix", async () => {
|
|
87
|
-
const agent = createMockAgent("static");
|
|
88
|
-
|
|
89
|
-
const runtime = new CopilotRuntime({
|
|
90
|
-
agents: { myAgent: agent },
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const v2Agents = runtime.instance.agents;
|
|
94
|
-
const resolved = await resolveAgents(v2Agents);
|
|
95
|
-
expect(resolved.myAgent).toBe(agent);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("promised agents record still works after fix", async () => {
|
|
99
|
-
const agent = createMockAgent("promised");
|
|
100
|
-
|
|
101
|
-
const runtime = new CopilotRuntime({
|
|
102
|
-
agents: Promise.resolve({ myAgent: agent }),
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const v2Agents = runtime.instance.agents;
|
|
106
|
-
const resolved = await resolveAgents(v2Agents);
|
|
107
|
-
expect(resolved.myAgent).toBe(agent);
|
|
108
|
-
});
|
|
109
|
-
});
|
package/src/lib/runtime/agent-integrations/langgraph/__tests__/dispatch-event-filtering.test.ts
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
import { EventType } from "@ag-ui/client";
|
|
2
|
-
import { LangGraphAgent } from "../agent";
|
|
3
|
-
import { CustomEventNames } from "../consts";
|
|
4
|
-
import { vi } from "vitest";
|
|
5
|
-
|
|
6
|
-
function createAgent() {
|
|
7
|
-
const agent = new LangGraphAgent({
|
|
8
|
-
graphId: "test-graph",
|
|
9
|
-
url: "http://localhost:8000",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const events: any[] = [];
|
|
13
|
-
(agent as any).subscriber = { next: (e: any) => events.push(e) };
|
|
14
|
-
(agent as any).activeRun = {
|
|
15
|
-
id: "run-1",
|
|
16
|
-
threadId: "thread-1",
|
|
17
|
-
hasFunctionStreaming: false,
|
|
18
|
-
};
|
|
19
|
-
(agent as any).messagesInProcess = {};
|
|
20
|
-
|
|
21
|
-
return { agent, events };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function makeTextEvent(
|
|
25
|
-
type: EventType,
|
|
26
|
-
metadata: Record<string, any>,
|
|
27
|
-
messageId = "msg-1",
|
|
28
|
-
) {
|
|
29
|
-
return {
|
|
30
|
-
type,
|
|
31
|
-
messageId,
|
|
32
|
-
...(type === EventType.TEXT_MESSAGE_CONTENT ? { delta: "hello" } : {}),
|
|
33
|
-
...(type === EventType.TEXT_MESSAGE_START ? { role: "assistant" } : {}),
|
|
34
|
-
rawEvent: { metadata },
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function makeCustomEvent(name: string, value: any) {
|
|
39
|
-
return {
|
|
40
|
-
type: EventType.CUSTOM,
|
|
41
|
-
name,
|
|
42
|
-
value,
|
|
43
|
-
} as any;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Mock the parent class's langGraphDefaultMergeState for a single test,
|
|
48
|
-
* using vi.spyOn for automatic cleanup.
|
|
49
|
-
*/
|
|
50
|
-
function withMockedParentMerge(agent: LangGraphAgent, returnValue: any) {
|
|
51
|
-
const parentProto = Object.getPrototypeOf(Object.getPrototypeOf(agent));
|
|
52
|
-
return vi
|
|
53
|
-
.spyOn(parentProto, "langGraphDefaultMergeState")
|
|
54
|
-
.mockReturnValue(returnValue);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
describe("dispatchEvent emit-messages filtering", () => {
|
|
58
|
-
it("suppresses message events when copilotkit:emit-messages is false", () => {
|
|
59
|
-
const { agent, events } = createAgent();
|
|
60
|
-
|
|
61
|
-
const result = agent.dispatchEvent(
|
|
62
|
-
makeTextEvent(EventType.TEXT_MESSAGE_START, {
|
|
63
|
-
"copilotkit:emit-messages": false,
|
|
64
|
-
}) as any,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
expect(result).toBe(false);
|
|
68
|
-
expect(events).toHaveLength(0);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("passes message events when copilotkit:emit-messages is true", () => {
|
|
72
|
-
const { agent, events } = createAgent();
|
|
73
|
-
|
|
74
|
-
const result = agent.dispatchEvent(
|
|
75
|
-
makeTextEvent(EventType.TEXT_MESSAGE_START, {
|
|
76
|
-
"copilotkit:emit-messages": true,
|
|
77
|
-
}) as any,
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
expect(result).toBe(true);
|
|
81
|
-
expect(events).toHaveLength(1);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("clears messagesInProcess when suppressing message events", () => {
|
|
85
|
-
const { agent } = createAgent();
|
|
86
|
-
|
|
87
|
-
// Simulate parent class having set a stale message record
|
|
88
|
-
(agent as any).messagesInProcess["run-1"] = {
|
|
89
|
-
id: "msg-1",
|
|
90
|
-
toolCallId: null,
|
|
91
|
-
toolCallName: null,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
agent.dispatchEvent(
|
|
95
|
-
makeTextEvent(EventType.TEXT_MESSAGE_START, {
|
|
96
|
-
"copilotkit:emit-messages": false,
|
|
97
|
-
}) as any,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
expect((agent as any).messagesInProcess["run-1"]).toBeNull();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("does NOT clear messagesInProcess when emit-messages is true", () => {
|
|
104
|
-
const { agent } = createAgent();
|
|
105
|
-
|
|
106
|
-
const staleRecord = {
|
|
107
|
-
id: "msg-1",
|
|
108
|
-
toolCallId: null,
|
|
109
|
-
toolCallName: null,
|
|
110
|
-
};
|
|
111
|
-
(agent as any).messagesInProcess["run-1"] = staleRecord;
|
|
112
|
-
|
|
113
|
-
agent.dispatchEvent(
|
|
114
|
-
makeTextEvent(EventType.TEXT_MESSAGE_CONTENT, {
|
|
115
|
-
"copilotkit:emit-messages": true,
|
|
116
|
-
}) as any,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Record should still be there (not cleared)
|
|
120
|
-
expect((agent as any).messagesInProcess["run-1"]).toBe(staleRecord);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("clears messagesInProcess on TEXT_MESSAGE_END suppression (the cross-node leak scenario)", () => {
|
|
124
|
-
const { agent } = createAgent();
|
|
125
|
-
|
|
126
|
-
// Orchestrator node set a message in progress, then its events get suppressed.
|
|
127
|
-
// The END event must also clear the tracking state.
|
|
128
|
-
(agent as any).messagesInProcess["run-1"] = {
|
|
129
|
-
id: "msg-orchestrator",
|
|
130
|
-
toolCallId: null,
|
|
131
|
-
toolCallName: null,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
agent.dispatchEvent(
|
|
135
|
-
makeTextEvent(
|
|
136
|
-
EventType.TEXT_MESSAGE_END,
|
|
137
|
-
{ "copilotkit:emit-messages": false },
|
|
138
|
-
"msg-orchestrator",
|
|
139
|
-
) as any,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
expect((agent as any).messagesInProcess["run-1"]).toBeNull();
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe("dispatchEvent emit-tool-calls filtering", () => {
|
|
147
|
-
it("suppresses tool events when copilotkit:emit-tool-calls is false", () => {
|
|
148
|
-
const { agent, events } = createAgent();
|
|
149
|
-
|
|
150
|
-
const result = agent.dispatchEvent({
|
|
151
|
-
type: EventType.TOOL_CALL_START,
|
|
152
|
-
toolCallId: "tc-1",
|
|
153
|
-
toolCallName: "search",
|
|
154
|
-
parentMessageId: "msg-1",
|
|
155
|
-
rawEvent: { metadata: { "copilotkit:emit-tool-calls": false } },
|
|
156
|
-
} as any);
|
|
157
|
-
|
|
158
|
-
expect(result).toBe(false);
|
|
159
|
-
expect(events).toHaveLength(0);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("passes tool events when copilotkit:emit-tool-calls is true", () => {
|
|
163
|
-
const { agent, events } = createAgent();
|
|
164
|
-
|
|
165
|
-
const result = agent.dispatchEvent({
|
|
166
|
-
type: EventType.TOOL_CALL_START,
|
|
167
|
-
toolCallId: "tc-1",
|
|
168
|
-
toolCallName: "search",
|
|
169
|
-
parentMessageId: "msg-1",
|
|
170
|
-
rawEvent: { metadata: { "copilotkit:emit-tool-calls": true } },
|
|
171
|
-
} as any);
|
|
172
|
-
|
|
173
|
-
expect(result).toBe(true);
|
|
174
|
-
expect(events).toHaveLength(1);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// ---------- CopilotKit custom event dispatch ----------
|
|
179
|
-
|
|
180
|
-
describe("dispatchEvent custom CopilotKit events", () => {
|
|
181
|
-
it("manually_emit_message produces TextMessage event sequence", () => {
|
|
182
|
-
const { agent, events } = createAgent();
|
|
183
|
-
|
|
184
|
-
const result = agent.dispatchEvent(
|
|
185
|
-
makeCustomEvent(CustomEventNames.CopilotKitManuallyEmitMessage, {
|
|
186
|
-
message_id: "msg-manual-1",
|
|
187
|
-
message: "Hello from agent",
|
|
188
|
-
role: "assistant",
|
|
189
|
-
}),
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
expect(result).toBe(true);
|
|
193
|
-
expect(events).toHaveLength(3);
|
|
194
|
-
expect(events[0].type).toBe(EventType.TEXT_MESSAGE_START);
|
|
195
|
-
expect(events[0].messageId).toBe("msg-manual-1");
|
|
196
|
-
expect(events[0].role).toBe("assistant");
|
|
197
|
-
expect(events[1].type).toBe(EventType.TEXT_MESSAGE_CONTENT);
|
|
198
|
-
expect(events[1].delta).toBe("Hello from agent");
|
|
199
|
-
expect(events[2].type).toBe(EventType.TEXT_MESSAGE_END);
|
|
200
|
-
expect(events[2].messageId).toBe("msg-manual-1");
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("manually_emit_tool_call produces ToolCall event sequence", () => {
|
|
204
|
-
const { agent, events } = createAgent();
|
|
205
|
-
|
|
206
|
-
const result = agent.dispatchEvent(
|
|
207
|
-
makeCustomEvent(CustomEventNames.CopilotKitManuallyEmitToolCall, {
|
|
208
|
-
id: "tc-manual-1",
|
|
209
|
-
name: "SearchTool",
|
|
210
|
-
args: { query: "test" },
|
|
211
|
-
}),
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
expect(result).toBe(true);
|
|
215
|
-
expect(events).toHaveLength(3);
|
|
216
|
-
expect(events[0].type).toBe(EventType.TOOL_CALL_START);
|
|
217
|
-
expect(events[0].toolCallId).toBe("tc-manual-1");
|
|
218
|
-
expect(events[0].toolCallName).toBe("SearchTool");
|
|
219
|
-
expect(events[1].type).toBe(EventType.TOOL_CALL_ARGS);
|
|
220
|
-
expect(events[1].toolCallId).toBe("tc-manual-1");
|
|
221
|
-
expect(events[1].delta).toEqual({ query: "test" });
|
|
222
|
-
expect(events[2].type).toBe(EventType.TOOL_CALL_END);
|
|
223
|
-
expect(events[2].toolCallId).toBe("tc-manual-1");
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("manually_emit_state produces StateSnapshot event", () => {
|
|
227
|
-
const { agent, events } = createAgent();
|
|
228
|
-
|
|
229
|
-
// Mock getStateSnapshot since it depends on thread state
|
|
230
|
-
(agent as any).getStateSnapshot = (state: any) => ({
|
|
231
|
-
values: state.values,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
const result = agent.dispatchEvent(
|
|
235
|
-
makeCustomEvent(
|
|
236
|
-
CustomEventNames.CopilotKitManuallyEmitIntermediateState,
|
|
237
|
-
{
|
|
238
|
-
progress: 75,
|
|
239
|
-
},
|
|
240
|
-
),
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
expect(result).toBe(true);
|
|
244
|
-
expect((agent as any).activeRun.manuallyEmittedState).toEqual({
|
|
245
|
-
progress: 75,
|
|
246
|
-
});
|
|
247
|
-
const snapshotEvents = events.filter(
|
|
248
|
-
(e) => e.type === EventType.STATE_SNAPSHOT,
|
|
249
|
-
);
|
|
250
|
-
expect(snapshotEvents.length).toBeGreaterThanOrEqual(1);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("copilotkit_exit produces Exit custom event", () => {
|
|
254
|
-
const { agent, events } = createAgent();
|
|
255
|
-
|
|
256
|
-
const result = agent.dispatchEvent(
|
|
257
|
-
makeCustomEvent(CustomEventNames.CopilotKitExit, {}),
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
expect(result).toBe(true);
|
|
261
|
-
expect(events).toHaveLength(1);
|
|
262
|
-
expect(events[0].type).toBe(EventType.CUSTOM);
|
|
263
|
-
// "Exit" is the hardcoded downstream name in agent.ts — not a constant,
|
|
264
|
-
// because it's the value the frontend listens for, not an internal enum.
|
|
265
|
-
expect(events[0].name).toBe("Exit");
|
|
266
|
-
expect(events[0].value).toBe(true);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("events without rawEvent pass through to subscriber", () => {
|
|
270
|
-
const { agent, events } = createAgent();
|
|
271
|
-
|
|
272
|
-
const result = agent.dispatchEvent({
|
|
273
|
-
type: EventType.TEXT_MESSAGE_START,
|
|
274
|
-
messageId: "msg-no-raw",
|
|
275
|
-
role: "assistant",
|
|
276
|
-
} as any);
|
|
277
|
-
|
|
278
|
-
expect(result).toBe(true);
|
|
279
|
-
expect(events).toHaveLength(1);
|
|
280
|
-
expect(events[0].messageId).toBe("msg-no-raw");
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
// ---------- langGraphDefaultMergeState ----------
|
|
285
|
-
|
|
286
|
-
describe("langGraphDefaultMergeState", () => {
|
|
287
|
-
afterEach(() => {
|
|
288
|
-
vi.restoreAllMocks();
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it("merges copilotkit actions from ag-ui tools", () => {
|
|
292
|
-
const { agent } = createAgent();
|
|
293
|
-
const tools = [{ name: "tool1" }, { name: "tool2" }];
|
|
294
|
-
|
|
295
|
-
withMockedParentMerge(agent, {
|
|
296
|
-
"ag-ui": { tools, context: [] },
|
|
297
|
-
tools: [],
|
|
298
|
-
messages: [],
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
const result = agent.langGraphDefaultMergeState({} as any, [], {} as any);
|
|
302
|
-
expect(result.copilotkit).toBeDefined();
|
|
303
|
-
expect(result.copilotkit.actions).toEqual(expect.arrayContaining(tools));
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it("merges copilotkit context from ag-ui", () => {
|
|
307
|
-
const { agent } = createAgent();
|
|
308
|
-
const context = [{ description: "user info", value: "test" }];
|
|
309
|
-
|
|
310
|
-
withMockedParentMerge(agent, {
|
|
311
|
-
"ag-ui": { tools: [], context },
|
|
312
|
-
tools: [],
|
|
313
|
-
messages: [],
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
const result = agent.langGraphDefaultMergeState({} as any, [], {} as any);
|
|
317
|
-
expect(result.copilotkit.context).toEqual(context);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it("handles missing ag-ui key without crashing", () => {
|
|
321
|
-
const { agent } = createAgent();
|
|
322
|
-
|
|
323
|
-
withMockedParentMerge(agent, { messages: [] });
|
|
324
|
-
|
|
325
|
-
const result = agent.langGraphDefaultMergeState({} as any, [], {} as any);
|
|
326
|
-
expect(result.copilotkit).toBeDefined();
|
|
327
|
-
expect(result.copilotkit.actions).toEqual([]);
|
|
328
|
-
expect(result.copilotkit.context).toEqual([]);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("deduplicates tools from returnedTools and ag-ui tools", () => {
|
|
332
|
-
const { agent } = createAgent();
|
|
333
|
-
const tool = { name: "SharedTool", id: "shared-1" };
|
|
334
|
-
|
|
335
|
-
withMockedParentMerge(agent, {
|
|
336
|
-
"ag-ui": { tools: [tool], context: [] },
|
|
337
|
-
tools: [tool],
|
|
338
|
-
messages: [],
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
const result = agent.langGraphDefaultMergeState({} as any, [], {} as any);
|
|
342
|
-
expect(result.copilotkit.actions).toHaveLength(1);
|
|
343
|
-
expect(result.copilotkit.actions[0].name).toBe("SharedTool");
|
|
344
|
-
});
|
|
345
|
-
});
|