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