@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,601 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { CopilotKitIntelligence } from "../client";
|
|
3
|
-
|
|
4
|
-
const fetchMock = vi.fn();
|
|
5
|
-
globalThis.fetch = fetchMock;
|
|
6
|
-
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
7
|
-
|
|
8
|
-
function jsonResponse(body: unknown, status = 200) {
|
|
9
|
-
return Promise.resolve({
|
|
10
|
-
ok: status >= 200 && status < 300,
|
|
11
|
-
status,
|
|
12
|
-
statusText: status === 200 ? "OK" : "Error",
|
|
13
|
-
json: () => Promise.resolve(body),
|
|
14
|
-
text: () => Promise.resolve(JSON.stringify(body)),
|
|
15
|
-
} as Response);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function emptyResponse(status = 204) {
|
|
19
|
-
return Promise.resolve({
|
|
20
|
-
ok: status >= 200 && status < 300,
|
|
21
|
-
status,
|
|
22
|
-
statusText: "No Content",
|
|
23
|
-
json: () => Promise.resolve(null),
|
|
24
|
-
text: () => Promise.resolve(""),
|
|
25
|
-
} as Response);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
describe("CopilotKitIntelligence", () => {
|
|
29
|
-
let client: CopilotKitIntelligence;
|
|
30
|
-
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
fetchMock.mockReset();
|
|
33
|
-
consoleErrorSpy.mockClear();
|
|
34
|
-
client = new CopilotKitIntelligence({
|
|
35
|
-
apiUrl: "https://api.example.com",
|
|
36
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
37
|
-
apiKey: "test-key",
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("strips trailing slash from apiUrl", async () => {
|
|
42
|
-
const c = new CopilotKitIntelligence({
|
|
43
|
-
apiUrl: "https://api.example.com/",
|
|
44
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
45
|
-
apiKey: "k",
|
|
46
|
-
});
|
|
47
|
-
fetchMock.mockReturnValue(jsonResponse({ threads: [], joinCode: "" }));
|
|
48
|
-
await c.listThreads({ userId: "u", agentId: "a" });
|
|
49
|
-
expect(fetchMock.mock.calls[0][0]).toMatch(
|
|
50
|
-
/^https:\/\/api\.example\.com\/api/,
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("derives runner and client websocket URLs from a single intelligence websocket URL", () => {
|
|
55
|
-
const c = new CopilotKitIntelligence({
|
|
56
|
-
apiUrl: "https://api.example.com",
|
|
57
|
-
wsUrl: "wss://ws.example.com",
|
|
58
|
-
apiKey: "k",
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(c.ɵgetRunnerWsUrl()).toBe("wss://ws.example.com/runner");
|
|
62
|
-
expect(c.ɵgetClientWsUrl()).toBe("wss://ws.example.com/client");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("sends Bearer authorization header", async () => {
|
|
66
|
-
fetchMock.mockReturnValue(jsonResponse({ threads: [], joinCode: "" }));
|
|
67
|
-
await client.listThreads({ userId: "u", agentId: "a" });
|
|
68
|
-
const headers = fetchMock.mock.calls[0][1].headers;
|
|
69
|
-
expect(headers.Authorization).toBe("Bearer test-key");
|
|
70
|
-
expect(headers["Content-Type"]).toBe("application/json");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("throws on non-ok response", async () => {
|
|
74
|
-
fetchMock.mockReturnValue(jsonResponse({ error: "nope" }, 403));
|
|
75
|
-
await expect(
|
|
76
|
-
client.listThreads({ userId: "u", agentId: "a" }),
|
|
77
|
-
).rejects.toThrow(/403/);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("listThreads", () => {
|
|
81
|
-
it("sends GET with userId and agentId query params", async () => {
|
|
82
|
-
const payload = {
|
|
83
|
-
threads: [
|
|
84
|
-
{
|
|
85
|
-
id: "t-1",
|
|
86
|
-
name: "Thread",
|
|
87
|
-
lastRunAt: "2026-01-01",
|
|
88
|
-
lastUpdatedAt: "2026-01-01",
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
joinCode: "jc-list",
|
|
92
|
-
};
|
|
93
|
-
fetchMock.mockReturnValue(jsonResponse(payload));
|
|
94
|
-
|
|
95
|
-
const result = await client.listThreads({
|
|
96
|
-
userId: "user-1",
|
|
97
|
-
agentId: "agent-1",
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
expect(result).toEqual(payload);
|
|
101
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
102
|
-
expect(url).toBe(
|
|
103
|
-
"https://api.example.com/api/threads?userId=user-1&agentId=agent-1",
|
|
104
|
-
);
|
|
105
|
-
expect(opts.method).toBe("GET");
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe("subscribeToThreads", () => {
|
|
110
|
-
it("sends POST with userId and returns the join token", async () => {
|
|
111
|
-
fetchMock.mockReturnValue(jsonResponse({ joinToken: "jt-subscribe" }));
|
|
112
|
-
|
|
113
|
-
const result = await client.ɵsubscribeToThreads({
|
|
114
|
-
userId: "user-1",
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
expect(result).toEqual({ joinToken: "jt-subscribe" });
|
|
118
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
119
|
-
expect(url).toBe("https://api.example.com/api/threads/subscribe");
|
|
120
|
-
expect(opts.method).toBe("POST");
|
|
121
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
122
|
-
userId: "user-1",
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("updateThread", () => {
|
|
128
|
-
it("sends PATCH with userId, agentId, and updates in body", async () => {
|
|
129
|
-
const thread = {
|
|
130
|
-
id: "t-1",
|
|
131
|
-
name: "Renamed",
|
|
132
|
-
lastRunAt: "2026-01-01",
|
|
133
|
-
lastUpdatedAt: "2026-01-02",
|
|
134
|
-
};
|
|
135
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
136
|
-
|
|
137
|
-
const result = await client.updateThread({
|
|
138
|
-
threadId: "t-1",
|
|
139
|
-
userId: "user-1",
|
|
140
|
-
agentId: "agent-1",
|
|
141
|
-
updates: { name: "Renamed" },
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
expect(result).toEqual(thread);
|
|
145
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
146
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1");
|
|
147
|
-
expect(opts.method).toBe("PATCH");
|
|
148
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
149
|
-
userId: "user-1",
|
|
150
|
-
agentId: "agent-1",
|
|
151
|
-
name: "Renamed",
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("encodes threadId in the URL", async () => {
|
|
156
|
-
fetchMock.mockReturnValue(jsonResponse({}));
|
|
157
|
-
await client.updateThread({
|
|
158
|
-
threadId: "id/with spaces",
|
|
159
|
-
userId: "u",
|
|
160
|
-
agentId: "a",
|
|
161
|
-
updates: {},
|
|
162
|
-
});
|
|
163
|
-
expect(fetchMock.mock.calls[0][0]).toContain(
|
|
164
|
-
"/threads/id%2Fwith%20spaces",
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("fires onThreadUpdated with the returned thread", async () => {
|
|
169
|
-
const onThreadUpdated = vi.fn();
|
|
170
|
-
client = new CopilotKitIntelligence({
|
|
171
|
-
apiUrl: "https://api.example.com",
|
|
172
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
173
|
-
apiKey: "test-key",
|
|
174
|
-
onThreadUpdated,
|
|
175
|
-
});
|
|
176
|
-
const thread = { id: "t-1", name: "Renamed" };
|
|
177
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
178
|
-
|
|
179
|
-
await client.updateThread({
|
|
180
|
-
threadId: "t-1",
|
|
181
|
-
userId: "user-1",
|
|
182
|
-
agentId: "agent-1",
|
|
183
|
-
updates: { name: "Renamed" },
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
expect(onThreadUpdated).toHaveBeenCalledWith(thread);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe("createThread", () => {
|
|
191
|
-
it("sends POST to create endpoint with thread bootstrap payload", async () => {
|
|
192
|
-
const thread = {
|
|
193
|
-
id: "t-1",
|
|
194
|
-
name: null,
|
|
195
|
-
lastRunAt: "2026-01-01",
|
|
196
|
-
lastUpdatedAt: "2026-01-02",
|
|
197
|
-
};
|
|
198
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
199
|
-
|
|
200
|
-
const result = await client.createThread({
|
|
201
|
-
threadId: "t-1",
|
|
202
|
-
userId: "user-1",
|
|
203
|
-
agentId: "agent-1",
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
expect(result).toEqual(thread);
|
|
207
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
208
|
-
expect(url).toBe("https://api.example.com/api/threads");
|
|
209
|
-
expect(opts.method).toBe("POST");
|
|
210
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
211
|
-
threadId: "t-1",
|
|
212
|
-
userId: "user-1",
|
|
213
|
-
agentId: "agent-1",
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("fires onThreadCreated with the returned thread", async () => {
|
|
218
|
-
const onThreadCreated = vi.fn();
|
|
219
|
-
client = new CopilotKitIntelligence({
|
|
220
|
-
apiUrl: "https://api.example.com",
|
|
221
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
222
|
-
apiKey: "test-key",
|
|
223
|
-
onThreadCreated,
|
|
224
|
-
});
|
|
225
|
-
const thread = { id: "t-1", name: null };
|
|
226
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
227
|
-
|
|
228
|
-
await client.createThread({
|
|
229
|
-
threadId: "t-1",
|
|
230
|
-
userId: "user-1",
|
|
231
|
-
agentId: "agent-1",
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
expect(onThreadCreated).toHaveBeenCalledWith(thread);
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
describe("getThread", () => {
|
|
239
|
-
it("sends GET to thread endpoint and unwraps the thread payload", async () => {
|
|
240
|
-
const thread = {
|
|
241
|
-
id: "t-1",
|
|
242
|
-
name: "Thread",
|
|
243
|
-
createdAt: "2026-01-01",
|
|
244
|
-
updatedAt: "2026-01-02",
|
|
245
|
-
};
|
|
246
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
247
|
-
|
|
248
|
-
const result = await client.getThread({ threadId: "t-1" });
|
|
249
|
-
|
|
250
|
-
expect(result).toEqual(thread);
|
|
251
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
252
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1");
|
|
253
|
-
expect(opts.method).toBe("GET");
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
describe("getThreadMessages", () => {
|
|
258
|
-
it("sends GET to thread messages endpoint and returns the durable transcript", async () => {
|
|
259
|
-
const payload = {
|
|
260
|
-
messages: [
|
|
261
|
-
{
|
|
262
|
-
id: "m-1",
|
|
263
|
-
role: "user",
|
|
264
|
-
content: "Persisted",
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
};
|
|
268
|
-
fetchMock.mockReturnValue(jsonResponse(payload));
|
|
269
|
-
|
|
270
|
-
const result = await client.getThreadMessages({ threadId: "t-1" });
|
|
271
|
-
|
|
272
|
-
expect(result).toEqual(payload);
|
|
273
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
274
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1/messages");
|
|
275
|
-
expect(opts.method).toBe("GET");
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
describe("archiveThread", () => {
|
|
280
|
-
it("patches the thread with archived=true", async () => {
|
|
281
|
-
fetchMock.mockReturnValue(
|
|
282
|
-
jsonResponse({
|
|
283
|
-
thread: { id: "t-1", name: "Archived", archived: true },
|
|
284
|
-
}),
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
await client.archiveThread({
|
|
288
|
-
threadId: "t-1",
|
|
289
|
-
userId: "user-1",
|
|
290
|
-
agentId: "agent-1",
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
294
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1");
|
|
295
|
-
expect(opts.method).toBe("PATCH");
|
|
296
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
297
|
-
userId: "user-1",
|
|
298
|
-
agentId: "agent-1",
|
|
299
|
-
archived: true,
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
it("fires onThreadUpdated after archiving", async () => {
|
|
304
|
-
const onThreadUpdated = vi.fn();
|
|
305
|
-
client = new CopilotKitIntelligence({
|
|
306
|
-
apiUrl: "https://api.example.com",
|
|
307
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
308
|
-
apiKey: "test-key",
|
|
309
|
-
onThreadUpdated,
|
|
310
|
-
});
|
|
311
|
-
const thread = { id: "t-1", name: "Archived", archived: true };
|
|
312
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
313
|
-
|
|
314
|
-
await client.archiveThread({
|
|
315
|
-
threadId: "t-1",
|
|
316
|
-
userId: "user-1",
|
|
317
|
-
agentId: "agent-1",
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
expect(onThreadUpdated).toHaveBeenCalledWith(thread);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
describe("deleteThread", () => {
|
|
325
|
-
it("sends DELETE with an audit reason in the body", async () => {
|
|
326
|
-
fetchMock.mockReturnValue(jsonResponse(undefined));
|
|
327
|
-
|
|
328
|
-
await client.deleteThread({
|
|
329
|
-
threadId: "t-1",
|
|
330
|
-
userId: "user-1",
|
|
331
|
-
agentId: "agent-1",
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
335
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1");
|
|
336
|
-
expect(opts.method).toBe("DELETE");
|
|
337
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
338
|
-
reason:
|
|
339
|
-
"Deleted via CopilotKit runtime (userId=user-1, agentId=agent-1)",
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it("fires onThreadDeleted with the successful delete payload", async () => {
|
|
344
|
-
const onThreadDeleted = vi.fn();
|
|
345
|
-
client = new CopilotKitIntelligence({
|
|
346
|
-
apiUrl: "https://api.example.com",
|
|
347
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
348
|
-
apiKey: "test-key",
|
|
349
|
-
onThreadDeleted,
|
|
350
|
-
});
|
|
351
|
-
fetchMock.mockReturnValue(jsonResponse(undefined));
|
|
352
|
-
|
|
353
|
-
await client.deleteThread({
|
|
354
|
-
threadId: "t-1",
|
|
355
|
-
userId: "user-1",
|
|
356
|
-
agentId: "agent-1",
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
expect(onThreadDeleted).toHaveBeenCalledWith({
|
|
360
|
-
threadId: "t-1",
|
|
361
|
-
userId: "user-1",
|
|
362
|
-
agentId: "agent-1",
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it("swallows lifecycle callback errors after a successful request", async () => {
|
|
367
|
-
client = new CopilotKitIntelligence({
|
|
368
|
-
apiUrl: "https://api.example.com",
|
|
369
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
370
|
-
apiKey: "test-key",
|
|
371
|
-
onThreadDeleted: () => {
|
|
372
|
-
throw new Error("callback exploded");
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
fetchMock.mockReturnValue(jsonResponse(undefined));
|
|
376
|
-
|
|
377
|
-
await expect(
|
|
378
|
-
client.deleteThread({
|
|
379
|
-
threadId: "t-1",
|
|
380
|
-
userId: "user-1",
|
|
381
|
-
agentId: "agent-1",
|
|
382
|
-
}),
|
|
383
|
-
).resolves.toBeUndefined();
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
describe("acquireThreadLock", () => {
|
|
388
|
-
it("sends POST to lock endpoint and returns canonical run credentials", async () => {
|
|
389
|
-
fetchMock.mockReturnValue(
|
|
390
|
-
jsonResponse({
|
|
391
|
-
threadId: "t-1",
|
|
392
|
-
runId: "r-1",
|
|
393
|
-
joinToken: "jt-lock",
|
|
394
|
-
}),
|
|
395
|
-
);
|
|
396
|
-
|
|
397
|
-
const result = await client.ɵacquireThreadLock({
|
|
398
|
-
threadId: "t-1",
|
|
399
|
-
runId: "r-1",
|
|
400
|
-
userId: "user-1",
|
|
401
|
-
agentId: "agent-1",
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
expect(result).toEqual({
|
|
405
|
-
threadId: "t-1",
|
|
406
|
-
runId: "r-1",
|
|
407
|
-
joinToken: "jt-lock",
|
|
408
|
-
});
|
|
409
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
410
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1/lock");
|
|
411
|
-
expect(opts.method).toBe("POST");
|
|
412
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
413
|
-
runId: "r-1",
|
|
414
|
-
userId: "user-1",
|
|
415
|
-
agentId: "agent-1",
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
it("throws when lock is denied", async () => {
|
|
420
|
-
fetchMock.mockReturnValue(jsonResponse("Thread is locked", 409));
|
|
421
|
-
await expect(
|
|
422
|
-
client.ɵacquireThreadLock({
|
|
423
|
-
threadId: "t-1",
|
|
424
|
-
runId: "r-1",
|
|
425
|
-
userId: "user-1",
|
|
426
|
-
agentId: "agent-1",
|
|
427
|
-
}),
|
|
428
|
-
).rejects.toThrow(/409/);
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
it("sends compare-delete cleanup to the lock endpoint", async () => {
|
|
432
|
-
fetchMock.mockReturnValue(emptyResponse());
|
|
433
|
-
|
|
434
|
-
await client.ɵcleanupThreadLock({
|
|
435
|
-
threadId: "t-1",
|
|
436
|
-
runId: "r-1",
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
440
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1/lock");
|
|
441
|
-
expect(opts.method).toBe("DELETE");
|
|
442
|
-
expect(JSON.parse(opts.body)).toEqual({ runId: "r-1" });
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
describe("getActiveJoinCode", () => {
|
|
447
|
-
it("sends GET to join-code endpoint with userId query param and returns thread connection credentials", async () => {
|
|
448
|
-
fetchMock.mockReturnValue(
|
|
449
|
-
jsonResponse({ joinToken: "jt-active", joinCode: "jc-active" }),
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
const result = await client.ɵgetActiveJoinCode({
|
|
453
|
-
threadId: "t-1",
|
|
454
|
-
userId: "user-1",
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
expect(result).toEqual({ joinToken: "jt-active", joinCode: "jc-active" });
|
|
458
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
459
|
-
expect(url).toBe(
|
|
460
|
-
"https://api.example.com/api/threads/t-1/join-code?userId=user-1",
|
|
461
|
-
);
|
|
462
|
-
expect(opts.method).toBe("GET");
|
|
463
|
-
expect(opts.body).toBeUndefined();
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it("throws when no active join code exists", async () => {
|
|
467
|
-
fetchMock.mockReturnValue(jsonResponse("Not found", 404));
|
|
468
|
-
await expect(
|
|
469
|
-
client.ɵgetActiveJoinCode({ threadId: "t-1", userId: "user-1" }),
|
|
470
|
-
).rejects.toThrow(/404/);
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
describe("multi-listener subscriptions", () => {
|
|
475
|
-
it("supports multiple onThreadCreated listeners", async () => {
|
|
476
|
-
const listener1 = vi.fn();
|
|
477
|
-
const listener2 = vi.fn();
|
|
478
|
-
client.onThreadCreated(listener1);
|
|
479
|
-
client.onThreadCreated(listener2);
|
|
480
|
-
|
|
481
|
-
const thread = { id: "t-1", name: null };
|
|
482
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
483
|
-
|
|
484
|
-
await client.createThread({
|
|
485
|
-
threadId: "t-1",
|
|
486
|
-
userId: "user-1",
|
|
487
|
-
agentId: "agent-1",
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
expect(listener1).toHaveBeenCalledWith(thread);
|
|
491
|
-
expect(listener2).toHaveBeenCalledWith(thread);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it("unsubscribe removes a specific listener", async () => {
|
|
495
|
-
const listener1 = vi.fn();
|
|
496
|
-
const listener2 = vi.fn();
|
|
497
|
-
const unsub1 = client.onThreadCreated(listener1);
|
|
498
|
-
client.onThreadCreated(listener2);
|
|
499
|
-
|
|
500
|
-
unsub1();
|
|
501
|
-
|
|
502
|
-
const thread = { id: "t-1", name: null };
|
|
503
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
504
|
-
|
|
505
|
-
await client.createThread({
|
|
506
|
-
threadId: "t-1",
|
|
507
|
-
userId: "user-1",
|
|
508
|
-
agentId: "agent-1",
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
expect(listener1).not.toHaveBeenCalled();
|
|
512
|
-
expect(listener2).toHaveBeenCalledWith(thread);
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
it("config callback and runtime listener both fire", async () => {
|
|
516
|
-
const configCb = vi.fn();
|
|
517
|
-
const runtimeCb = vi.fn();
|
|
518
|
-
client = new CopilotKitIntelligence({
|
|
519
|
-
apiUrl: "https://api.example.com",
|
|
520
|
-
wsUrl: "wss://ws.example.com/socket",
|
|
521
|
-
apiKey: "test-key",
|
|
522
|
-
onThreadUpdated: configCb,
|
|
523
|
-
});
|
|
524
|
-
client.onThreadUpdated(runtimeCb);
|
|
525
|
-
|
|
526
|
-
const thread = { id: "t-1", name: "Updated" };
|
|
527
|
-
fetchMock.mockReturnValue(jsonResponse({ thread }));
|
|
528
|
-
|
|
529
|
-
await client.updateThread({
|
|
530
|
-
threadId: "t-1",
|
|
531
|
-
userId: "user-1",
|
|
532
|
-
agentId: "agent-1",
|
|
533
|
-
updates: { name: "Updated" },
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
expect(configCb).toHaveBeenCalledWith(thread);
|
|
537
|
-
expect(runtimeCb).toHaveBeenCalledWith(thread);
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
it("one failing listener does not prevent others from running", async () => {
|
|
541
|
-
const failingCb = vi.fn(() => {
|
|
542
|
-
throw new Error("boom");
|
|
543
|
-
});
|
|
544
|
-
const healthyCb = vi.fn();
|
|
545
|
-
client.onThreadDeleted(failingCb);
|
|
546
|
-
client.onThreadDeleted(healthyCb);
|
|
547
|
-
|
|
548
|
-
fetchMock.mockReturnValue(jsonResponse(undefined));
|
|
549
|
-
|
|
550
|
-
await client.deleteThread({
|
|
551
|
-
threadId: "t-1",
|
|
552
|
-
userId: "user-1",
|
|
553
|
-
agentId: "agent-1",
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
expect(failingCb).toHaveBeenCalled();
|
|
557
|
-
expect(healthyCb).toHaveBeenCalledWith({
|
|
558
|
-
threadId: "t-1",
|
|
559
|
-
userId: "user-1",
|
|
560
|
-
agentId: "agent-1",
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
describe("connectThread", () => {
|
|
566
|
-
it("returns null on 204", async () => {
|
|
567
|
-
fetchMock.mockReturnValue(emptyResponse());
|
|
568
|
-
|
|
569
|
-
const result = await client.ɵconnectThread({
|
|
570
|
-
threadId: "t-1",
|
|
571
|
-
userId: "user-1",
|
|
572
|
-
agentId: "agent-1",
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
expect(result).toBeNull();
|
|
576
|
-
const [url, opts] = fetchMock.mock.calls[0];
|
|
577
|
-
expect(url).toBe("https://api.example.com/api/threads/t-1/connect");
|
|
578
|
-
expect(opts.method).toBe("POST");
|
|
579
|
-
expect(JSON.parse(opts.body)).toEqual({
|
|
580
|
-
userId: "user-1",
|
|
581
|
-
agentId: "agent-1",
|
|
582
|
-
});
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
it("returns credentials-only connect response", async () => {
|
|
586
|
-
const payload = {
|
|
587
|
-
threadId: "t-1",
|
|
588
|
-
joinToken: "jt-connect",
|
|
589
|
-
};
|
|
590
|
-
fetchMock.mockReturnValue(jsonResponse(payload));
|
|
591
|
-
|
|
592
|
-
const result = await client.ɵconnectThread({
|
|
593
|
-
threadId: "t-1",
|
|
594
|
-
userId: "user-1",
|
|
595
|
-
agentId: "agent-1",
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
expect(result).toEqual(payload);
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
});
|