@copilotkit/runtime 1.54.1 → 1.55.0-next.8
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 +125 -113
- package/dist/_virtual/_rolldown/runtime.mjs +25 -1
- package/dist/agent/index.cjs +654 -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 +646 -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 +24 -7
- package/src/agent/__tests__/ai-sdk-v6-compat.test.ts +116 -0
- package/src/agent/__tests__/basic-agent.test.ts +1698 -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 +193 -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 +1329 -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,981 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
AbstractAgent,
|
|
4
|
+
BaseEvent,
|
|
5
|
+
EventType,
|
|
6
|
+
RunAgentInput,
|
|
7
|
+
RunStartedEvent,
|
|
8
|
+
RunFinishedEvent,
|
|
9
|
+
RunErrorEvent,
|
|
10
|
+
TextMessageStartEvent,
|
|
11
|
+
TextMessageContentEvent,
|
|
12
|
+
TextMessageEndEvent,
|
|
13
|
+
} from "@ag-ui/client";
|
|
14
|
+
import { EMPTY, firstValueFrom } from "rxjs";
|
|
15
|
+
import { toArray } from "rxjs/operators";
|
|
16
|
+
import {
|
|
17
|
+
MockChannel,
|
|
18
|
+
MockSocket,
|
|
19
|
+
} from "../../../../../../core/src/__tests__/test-utils";
|
|
20
|
+
|
|
21
|
+
let mockChannels: MockChannel[] = [];
|
|
22
|
+
let mockSockets: MockSocket[] = [];
|
|
23
|
+
|
|
24
|
+
class MockSocketImpl extends MockSocket {
|
|
25
|
+
constructor(url: string, opts?: any) {
|
|
26
|
+
super(url, opts);
|
|
27
|
+
mockSockets.push(this);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
channel(topic: string, params: Record<string, any> = {}): MockChannel {
|
|
31
|
+
const ch = super.channel(topic, params);
|
|
32
|
+
mockChannels.push(ch);
|
|
33
|
+
return ch;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
vi.mock("phoenix", () => ({
|
|
38
|
+
Socket: MockSocketImpl,
|
|
39
|
+
Channel: MockChannel,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
vi.mock("ws", () => ({ default: class MockWebSocket {} }));
|
|
43
|
+
|
|
44
|
+
class MockAgent extends AbstractAgent {
|
|
45
|
+
aborted = false;
|
|
46
|
+
private events: BaseEvent[];
|
|
47
|
+
|
|
48
|
+
constructor(events: BaseEvent[] = []) {
|
|
49
|
+
super();
|
|
50
|
+
this.events = events;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async runAgent(
|
|
54
|
+
_input: RunAgentInput,
|
|
55
|
+
subscriber?: { onEvent?: (arg: { event: BaseEvent }) => void },
|
|
56
|
+
): Promise<void> {
|
|
57
|
+
for (const event of this.events) {
|
|
58
|
+
subscriber?.onEvent?.({ event });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
abortRun(): void {
|
|
63
|
+
this.aborted = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
clone(): AbstractAgent {
|
|
67
|
+
return new MockAgent(this.events);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected run(): ReturnType<AbstractAgent["run"]> {
|
|
71
|
+
return EMPTY;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
protected connect(): ReturnType<AbstractAgent["connect"]> {
|
|
75
|
+
return EMPTY;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
class ThrowingMockAgent extends AbstractAgent {
|
|
80
|
+
aborted = false;
|
|
81
|
+
private errorMessage: string;
|
|
82
|
+
|
|
83
|
+
constructor(errorMessage = "Agent exploded") {
|
|
84
|
+
super();
|
|
85
|
+
this.errorMessage = errorMessage;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async runAgent(): Promise<void> {
|
|
89
|
+
throw new Error(this.errorMessage);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
abortRun(): void {
|
|
93
|
+
this.aborted = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
clone(): AbstractAgent {
|
|
97
|
+
return new ThrowingMockAgent(this.errorMessage);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
protected run(): ReturnType<AbstractAgent["run"]> {
|
|
101
|
+
return EMPTY;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
protected connect(): ReturnType<AbstractAgent["connect"]> {
|
|
105
|
+
return EMPTY;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* An agent whose runAgent() blocks until abortRun() is called,
|
|
111
|
+
* then rejects — simulating how a real agent's AbortController
|
|
112
|
+
* would cause in-flight work to fail on abort.
|
|
113
|
+
*/
|
|
114
|
+
class BlockingMockAgent extends AbstractAgent {
|
|
115
|
+
aborted = false;
|
|
116
|
+
private rejectFn: ((reason: Error) => void) | null = null;
|
|
117
|
+
|
|
118
|
+
async runAgent(): Promise<void> {
|
|
119
|
+
return new Promise<void>((_resolve, reject) => {
|
|
120
|
+
this.rejectFn = reject;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
abortRun(): void {
|
|
125
|
+
this.aborted = true;
|
|
126
|
+
this.rejectFn?.(new Error("Aborted"));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
clone(): AbstractAgent {
|
|
130
|
+
return new BlockingMockAgent();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected run(): ReturnType<AbstractAgent["run"]> {
|
|
134
|
+
return EMPTY;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
protected connect(): ReturnType<AbstractAgent["connect"]> {
|
|
138
|
+
return EMPTY;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function createRunInput(
|
|
143
|
+
overrides: Partial<RunAgentInput> & { threadId: string; runId: string },
|
|
144
|
+
): RunAgentInput {
|
|
145
|
+
return {
|
|
146
|
+
messages: [],
|
|
147
|
+
tools: [],
|
|
148
|
+
context: [],
|
|
149
|
+
state: {},
|
|
150
|
+
forwardedProps: undefined,
|
|
151
|
+
...overrides,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function collectEvents(
|
|
156
|
+
observable: ReturnType<
|
|
157
|
+
import("../intelligence").IntelligenceAgentRunner["run"]
|
|
158
|
+
>,
|
|
159
|
+
) {
|
|
160
|
+
return firstValueFrom(observable.pipe(toArray()));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Must come after vi.mock so phoenix/ws are mocked when the module is loaded.
|
|
164
|
+
const { IntelligenceAgentRunner } = await import("../intelligence");
|
|
165
|
+
|
|
166
|
+
describe("IntelligenceAgentRunner", () => {
|
|
167
|
+
let runner: InstanceType<typeof IntelligenceAgentRunner>;
|
|
168
|
+
|
|
169
|
+
beforeEach(() => {
|
|
170
|
+
mockChannels = [];
|
|
171
|
+
mockSockets = [];
|
|
172
|
+
runner = new IntelligenceAgentRunner({ url: "ws://localhost:4000/runner" });
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("passes Phoenix authToken to the runner socket when configured", () => {
|
|
176
|
+
runner = new IntelligenceAgentRunner({
|
|
177
|
+
url: "ws://localhost:4000/runner",
|
|
178
|
+
authToken: "cpk_test_key",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const threadId = "t-auth";
|
|
182
|
+
const input = createRunInput({ threadId, runId: "r-auth" });
|
|
183
|
+
const agent = new MockAgent();
|
|
184
|
+
|
|
185
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
186
|
+
|
|
187
|
+
expect(mockSockets[0]?.opts).toMatchObject({
|
|
188
|
+
authToken: "cpk_test_key",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
sub.unsubscribe();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("run", () => {
|
|
195
|
+
it("calls runAgent() and completes the Observable (events go to channel only)", async () => {
|
|
196
|
+
const threadId = "t-1";
|
|
197
|
+
const input = createRunInput({ threadId, runId: "r-1" });
|
|
198
|
+
|
|
199
|
+
const agentEvents: BaseEvent[] = [
|
|
200
|
+
{
|
|
201
|
+
type: EventType.RUN_STARTED,
|
|
202
|
+
threadId,
|
|
203
|
+
runId: "r-1",
|
|
204
|
+
} as RunStartedEvent,
|
|
205
|
+
{
|
|
206
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
207
|
+
messageId: "msg-1",
|
|
208
|
+
role: "assistant",
|
|
209
|
+
} as TextMessageStartEvent,
|
|
210
|
+
{
|
|
211
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
212
|
+
messageId: "msg-1",
|
|
213
|
+
delta: "Hello",
|
|
214
|
+
} as TextMessageContentEvent,
|
|
215
|
+
{
|
|
216
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
217
|
+
messageId: "msg-1",
|
|
218
|
+
} as TextMessageEndEvent,
|
|
219
|
+
{
|
|
220
|
+
type: EventType.RUN_FINISHED,
|
|
221
|
+
threadId,
|
|
222
|
+
runId: "r-1",
|
|
223
|
+
} as RunFinishedEvent,
|
|
224
|
+
];
|
|
225
|
+
const agent = new MockAgent(agentEvents);
|
|
226
|
+
|
|
227
|
+
const eventsPromise = collectEvents(
|
|
228
|
+
runner.run({ threadId, agent, input }),
|
|
229
|
+
);
|
|
230
|
+
const ch = mockChannels[0];
|
|
231
|
+
ch.triggerJoin("ok");
|
|
232
|
+
|
|
233
|
+
const events = await eventsPromise;
|
|
234
|
+
|
|
235
|
+
// Agent events are NOT emitted to the Observable — only to the channel.
|
|
236
|
+
// The Observable only receives finalization events (none needed here).
|
|
237
|
+
expect(events).toHaveLength(0);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("pushes agent events to the Phoenix channel", async () => {
|
|
241
|
+
const threadId = "t-push";
|
|
242
|
+
const input = createRunInput({ threadId, runId: "r-push" });
|
|
243
|
+
|
|
244
|
+
const agentEvents: BaseEvent[] = [
|
|
245
|
+
{
|
|
246
|
+
type: EventType.RUN_STARTED,
|
|
247
|
+
threadId,
|
|
248
|
+
runId: "r-push",
|
|
249
|
+
} as RunStartedEvent,
|
|
250
|
+
{
|
|
251
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
252
|
+
messageId: "msg-1",
|
|
253
|
+
delta: "hi",
|
|
254
|
+
} as TextMessageContentEvent,
|
|
255
|
+
{
|
|
256
|
+
type: EventType.RUN_FINISHED,
|
|
257
|
+
threadId,
|
|
258
|
+
runId: "r-push",
|
|
259
|
+
} as RunFinishedEvent,
|
|
260
|
+
];
|
|
261
|
+
const agent = new MockAgent(agentEvents);
|
|
262
|
+
|
|
263
|
+
const eventsPromise = collectEvents(
|
|
264
|
+
runner.run({ threadId, agent, input }),
|
|
265
|
+
);
|
|
266
|
+
const ch = mockChannels[0];
|
|
267
|
+
ch.triggerJoin("ok");
|
|
268
|
+
|
|
269
|
+
await eventsPromise;
|
|
270
|
+
|
|
271
|
+
// Agent events should be pushed to the ingestion channel under "event".
|
|
272
|
+
expect(ch.pushLog.every((p) => p.event === "event")).toBe(true);
|
|
273
|
+
const payloadTypes = ch.pushLog.map((p) => p.payload.type);
|
|
274
|
+
expect(payloadTypes).toContain(EventType.RUN_STARTED);
|
|
275
|
+
expect(payloadTypes).toContain(EventType.TEXT_MESSAGE_CONTENT);
|
|
276
|
+
expect(payloadTypes).toContain(EventType.RUN_FINISHED);
|
|
277
|
+
expect(ch.pushLog[0].payload).toMatchObject({
|
|
278
|
+
thread_id: threadId,
|
|
279
|
+
run_id: "r-push",
|
|
280
|
+
});
|
|
281
|
+
expect(ch.pushLog[0].payload.metadata.cpki_event_id).toEqual(
|
|
282
|
+
expect.any(String),
|
|
283
|
+
);
|
|
284
|
+
expect(ch.pushLog[0].payload.metadata.cpki_event_seq).toBe(1);
|
|
285
|
+
expect(ch.pushLog[1].payload.metadata.cpki_event_seq).toBe(2);
|
|
286
|
+
expect(ch.pushLog[2].payload.metadata.cpki_event_seq).toBe(3);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("rewrites RUN_STARTED input.messages to the unseen persisted subset", async () => {
|
|
290
|
+
const threadId = "t-persisted-input";
|
|
291
|
+
const input = createRunInput({
|
|
292
|
+
threadId,
|
|
293
|
+
runId: "r-persisted-input",
|
|
294
|
+
messages: [
|
|
295
|
+
{
|
|
296
|
+
id: "msg-existing",
|
|
297
|
+
role: "user",
|
|
298
|
+
content: "Existing",
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
id: "msg-new",
|
|
302
|
+
role: "user",
|
|
303
|
+
content: "New",
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const agent = new MockAgent([
|
|
309
|
+
{
|
|
310
|
+
type: EventType.RUN_STARTED,
|
|
311
|
+
threadId,
|
|
312
|
+
runId: "r-persisted-input",
|
|
313
|
+
input,
|
|
314
|
+
} as RunStartedEvent,
|
|
315
|
+
{
|
|
316
|
+
type: EventType.RUN_FINISHED,
|
|
317
|
+
threadId,
|
|
318
|
+
runId: "r-persisted-input",
|
|
319
|
+
} as RunFinishedEvent,
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
const eventsPromise = collectEvents(
|
|
323
|
+
runner.run({
|
|
324
|
+
threadId,
|
|
325
|
+
agent,
|
|
326
|
+
input,
|
|
327
|
+
persistedInputMessages: [
|
|
328
|
+
{
|
|
329
|
+
id: "msg-new",
|
|
330
|
+
role: "user",
|
|
331
|
+
content: "New",
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
}),
|
|
335
|
+
);
|
|
336
|
+
const ch = mockChannels[0];
|
|
337
|
+
ch.triggerJoin("ok");
|
|
338
|
+
|
|
339
|
+
await eventsPromise;
|
|
340
|
+
|
|
341
|
+
expect(ch.pushLog[0].payload.type).toBe(EventType.RUN_STARTED);
|
|
342
|
+
expect(ch.pushLog[0].payload.input.messages).toEqual([
|
|
343
|
+
{
|
|
344
|
+
id: "msg-new",
|
|
345
|
+
role: "user",
|
|
346
|
+
content: "New",
|
|
347
|
+
},
|
|
348
|
+
]);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("synthesizes RUN_STARTED before other events when the agent omits it", async () => {
|
|
352
|
+
const threadId = "t-synth-run-started";
|
|
353
|
+
const input = createRunInput({
|
|
354
|
+
threadId,
|
|
355
|
+
runId: "r-synth-run-started",
|
|
356
|
+
messages: [
|
|
357
|
+
{
|
|
358
|
+
id: "msg-new",
|
|
359
|
+
role: "user",
|
|
360
|
+
content: "Persist me",
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const agent = new MockAgent([
|
|
366
|
+
{
|
|
367
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
368
|
+
messageId: "msg-1",
|
|
369
|
+
delta: "hello",
|
|
370
|
+
} as TextMessageContentEvent,
|
|
371
|
+
{
|
|
372
|
+
type: EventType.RUN_FINISHED,
|
|
373
|
+
threadId,
|
|
374
|
+
runId: "r-synth-run-started",
|
|
375
|
+
} as RunFinishedEvent,
|
|
376
|
+
]);
|
|
377
|
+
|
|
378
|
+
const eventsPromise = collectEvents(
|
|
379
|
+
runner.run({
|
|
380
|
+
threadId,
|
|
381
|
+
agent,
|
|
382
|
+
input,
|
|
383
|
+
persistedInputMessages: input.messages,
|
|
384
|
+
}),
|
|
385
|
+
);
|
|
386
|
+
const ch = mockChannels[0];
|
|
387
|
+
ch.triggerJoin("ok");
|
|
388
|
+
|
|
389
|
+
await eventsPromise;
|
|
390
|
+
|
|
391
|
+
expect(ch.pushLog[0].payload.type).toBe(EventType.RUN_STARTED);
|
|
392
|
+
expect(ch.pushLog[0].payload.input.messages).toEqual(input.messages);
|
|
393
|
+
expect(ch.pushLog[1].payload.type).toBe(EventType.TEXT_MESSAGE_CONTENT);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("does not push any CUSTOM run event to the channel", async () => {
|
|
397
|
+
const threadId = "t-no-custom";
|
|
398
|
+
const input = createRunInput({ threadId, runId: "r-no-custom" });
|
|
399
|
+
|
|
400
|
+
const agentEvents: BaseEvent[] = [
|
|
401
|
+
{
|
|
402
|
+
type: EventType.RUN_STARTED,
|
|
403
|
+
threadId,
|
|
404
|
+
runId: "r-no-custom",
|
|
405
|
+
} as RunStartedEvent,
|
|
406
|
+
{
|
|
407
|
+
type: EventType.RUN_FINISHED,
|
|
408
|
+
threadId,
|
|
409
|
+
runId: "r-no-custom",
|
|
410
|
+
} as RunFinishedEvent,
|
|
411
|
+
];
|
|
412
|
+
const agent = new MockAgent(agentEvents);
|
|
413
|
+
|
|
414
|
+
const eventsPromise = collectEvents(
|
|
415
|
+
runner.run({ threadId, agent, input }),
|
|
416
|
+
);
|
|
417
|
+
const ch = mockChannels[0];
|
|
418
|
+
ch.triggerJoin("ok");
|
|
419
|
+
|
|
420
|
+
await eventsPromise;
|
|
421
|
+
|
|
422
|
+
const customRunPush = ch.pushLog.find(
|
|
423
|
+
(p) => p.event === EventType.CUSTOM && p.payload?.name === "run",
|
|
424
|
+
);
|
|
425
|
+
expect(customRunPush).toBeUndefined();
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("pushes RUN_ERROR to the channel when agent throws", async () => {
|
|
429
|
+
const threadId = "t-err";
|
|
430
|
+
const input = createRunInput({ threadId, runId: "r-err" });
|
|
431
|
+
const agent = new ThrowingMockAgent("Something went wrong");
|
|
432
|
+
|
|
433
|
+
const eventsPromise = collectEvents(
|
|
434
|
+
runner.run({ threadId, agent, input }),
|
|
435
|
+
);
|
|
436
|
+
const ch = mockChannels[0];
|
|
437
|
+
ch.triggerJoin("ok");
|
|
438
|
+
|
|
439
|
+
await eventsPromise;
|
|
440
|
+
|
|
441
|
+
const errorPush = ch.pushLog.find(
|
|
442
|
+
(p) => p.payload?.type === EventType.RUN_ERROR,
|
|
443
|
+
);
|
|
444
|
+
expect(errorPush).toBeDefined();
|
|
445
|
+
expect(errorPush!.payload.message).toBe("Something went wrong");
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it("finalizes open message streams before completing", async () => {
|
|
449
|
+
const threadId = "t-finalize";
|
|
450
|
+
const input = createRunInput({ threadId, runId: "r-fin" });
|
|
451
|
+
|
|
452
|
+
// Emit an unclosed text message, then RUN_FINISHED.
|
|
453
|
+
const agentEvents: BaseEvent[] = [
|
|
454
|
+
{
|
|
455
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
456
|
+
messageId: "open-msg",
|
|
457
|
+
role: "assistant",
|
|
458
|
+
} as BaseEvent,
|
|
459
|
+
{ type: EventType.RUN_FINISHED, threadId, runId: "r-fin" } as BaseEvent,
|
|
460
|
+
];
|
|
461
|
+
const agent = new MockAgent(agentEvents);
|
|
462
|
+
|
|
463
|
+
const eventsPromise = collectEvents(
|
|
464
|
+
runner.run({ threadId, agent, input }),
|
|
465
|
+
);
|
|
466
|
+
const ch = mockChannels[0];
|
|
467
|
+
ch.triggerJoin("ok");
|
|
468
|
+
|
|
469
|
+
await eventsPromise;
|
|
470
|
+
|
|
471
|
+
// finalizeRunEvents appends TEXT_MESSAGE_END for the unclosed message.
|
|
472
|
+
// Verify the channel received both agent and finalization events.
|
|
473
|
+
const chPayloadTypes = ch.pushLog.map((p) => p.payload.type);
|
|
474
|
+
expect(chPayloadTypes).toContain(EventType.RUN_STARTED);
|
|
475
|
+
expect(chPayloadTypes).toContain(EventType.TEXT_MESSAGE_START);
|
|
476
|
+
expect(chPayloadTypes).toContain(EventType.TEXT_MESSAGE_END);
|
|
477
|
+
expect(ch.pushLog.map((p) => p.payload.metadata.cpki_event_seq)).toEqual([
|
|
478
|
+
1, 2, 3, 4,
|
|
479
|
+
]);
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it("preserves runner event order with increasing cpki_event_seq", async () => {
|
|
483
|
+
const threadId = "t-seq";
|
|
484
|
+
const input = createRunInput({ threadId, runId: "r-seq" });
|
|
485
|
+
|
|
486
|
+
const agent = new MockAgent([
|
|
487
|
+
{
|
|
488
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
489
|
+
messageId: "msg-1",
|
|
490
|
+
delta: "first",
|
|
491
|
+
} as TextMessageContentEvent,
|
|
492
|
+
{
|
|
493
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
494
|
+
messageId: "msg-1",
|
|
495
|
+
delta: "second",
|
|
496
|
+
} as TextMessageContentEvent,
|
|
497
|
+
{
|
|
498
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
499
|
+
messageId: "msg-1",
|
|
500
|
+
delta: "third",
|
|
501
|
+
} as TextMessageContentEvent,
|
|
502
|
+
]);
|
|
503
|
+
|
|
504
|
+
const eventsPromise = collectEvents(
|
|
505
|
+
runner.run({ threadId, agent, input }),
|
|
506
|
+
);
|
|
507
|
+
const ch = mockChannels[0];
|
|
508
|
+
ch.triggerJoin("ok");
|
|
509
|
+
|
|
510
|
+
await eventsPromise;
|
|
511
|
+
|
|
512
|
+
expect(
|
|
513
|
+
ch.pushLog.map((entry) => entry.payload.metadata.cpki_event_seq),
|
|
514
|
+
).toEqual([1, 2, 3, 4, 5]);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it("throws when the thread is already running", () => {
|
|
518
|
+
const threadId = "t-dup";
|
|
519
|
+
const input = createRunInput({ threadId, runId: "r-dup" });
|
|
520
|
+
const agent = new MockAgent();
|
|
521
|
+
|
|
522
|
+
// Start a run and subscribe so the Observable body executes.
|
|
523
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
524
|
+
|
|
525
|
+
expect(() => runner.run({ threadId, agent, input })).toThrow(
|
|
526
|
+
"Thread already running",
|
|
527
|
+
);
|
|
528
|
+
sub.unsubscribe();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it("emits RUN_ERROR and completes when channel join fails", async () => {
|
|
532
|
+
const threadId = "t-join-err";
|
|
533
|
+
const input = createRunInput({ threadId, runId: "r-join-err" });
|
|
534
|
+
const agent = new MockAgent();
|
|
535
|
+
|
|
536
|
+
const eventsPromise = collectEvents(
|
|
537
|
+
runner.run({ threadId, agent, input }),
|
|
538
|
+
);
|
|
539
|
+
const ch = mockChannels[0];
|
|
540
|
+
|
|
541
|
+
ch.triggerJoin("error", { reason: "unauthorized" });
|
|
542
|
+
|
|
543
|
+
const events = await eventsPromise;
|
|
544
|
+
|
|
545
|
+
expect(events).toHaveLength(1);
|
|
546
|
+
expect(events[0].type).toBe(EventType.RUN_ERROR);
|
|
547
|
+
expect((events[0] as RunErrorEvent).message).toContain("unauthorized");
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("emits RUN_ERROR and completes when channel join times out", async () => {
|
|
551
|
+
const threadId = "t-join-timeout";
|
|
552
|
+
const input = createRunInput({ threadId, runId: "r-join-timeout" });
|
|
553
|
+
const agent = new MockAgent();
|
|
554
|
+
|
|
555
|
+
const eventsPromise = collectEvents(
|
|
556
|
+
runner.run({ threadId, agent, input }),
|
|
557
|
+
);
|
|
558
|
+
const ch = mockChannels[0];
|
|
559
|
+
|
|
560
|
+
ch.triggerJoin("timeout");
|
|
561
|
+
|
|
562
|
+
const events = await eventsPromise;
|
|
563
|
+
|
|
564
|
+
expect(events).toHaveLength(1);
|
|
565
|
+
expect(events[0].type).toBe(EventType.RUN_ERROR);
|
|
566
|
+
expect((events[0] as RunErrorEvent).message).toBe(
|
|
567
|
+
"Timed out joining channel",
|
|
568
|
+
);
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
describe("run with joinCode", () => {
|
|
573
|
+
it("uses joinCode for the channel topic when provided", async () => {
|
|
574
|
+
const threadId = "t-jc";
|
|
575
|
+
const joinCode = "join-abc-123";
|
|
576
|
+
const input = createRunInput({ threadId, runId: "r-jc" });
|
|
577
|
+
const agent = new MockAgent([
|
|
578
|
+
{
|
|
579
|
+
type: EventType.RUN_FINISHED,
|
|
580
|
+
threadId,
|
|
581
|
+
runId: "r-jc",
|
|
582
|
+
} as RunFinishedEvent,
|
|
583
|
+
]);
|
|
584
|
+
|
|
585
|
+
const eventsPromise = collectEvents(
|
|
586
|
+
runner.run({ threadId, agent, input, joinCode }),
|
|
587
|
+
);
|
|
588
|
+
const ch = mockChannels[0];
|
|
589
|
+
expect(ch.topic).toBe(`ingestion:${joinCode}`);
|
|
590
|
+
ch.triggerJoin("ok");
|
|
591
|
+
await eventsPromise;
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it("falls back to threadId when joinCode is not provided", async () => {
|
|
595
|
+
const threadId = "t-no-jc";
|
|
596
|
+
const input = createRunInput({ threadId, runId: "r-no-jc" });
|
|
597
|
+
const agent = new MockAgent([
|
|
598
|
+
{
|
|
599
|
+
type: EventType.RUN_FINISHED,
|
|
600
|
+
threadId,
|
|
601
|
+
runId: "r-no-jc",
|
|
602
|
+
} as RunFinishedEvent,
|
|
603
|
+
]);
|
|
604
|
+
|
|
605
|
+
const eventsPromise = collectEvents(
|
|
606
|
+
runner.run({ threadId, agent, input }),
|
|
607
|
+
);
|
|
608
|
+
const ch = mockChannels[0];
|
|
609
|
+
expect(ch.topic).toBe(`ingestion:${threadId}`);
|
|
610
|
+
ch.triggerJoin("ok");
|
|
611
|
+
await eventsPromise;
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
describe("connect", () => {
|
|
616
|
+
it("forwards thread channel events and completes on RUN_FINISHED", async () => {
|
|
617
|
+
const threadId = "t-connect";
|
|
618
|
+
|
|
619
|
+
const eventsPromise = collectEvents(runner.connect({ threadId }));
|
|
620
|
+
const ch = mockChannels[0];
|
|
621
|
+
ch.triggerJoin("ok");
|
|
622
|
+
|
|
623
|
+
ch.serverPush("ag_ui_event", {
|
|
624
|
+
type: EventType.RUN_STARTED,
|
|
625
|
+
threadId,
|
|
626
|
+
runId: "r-hist",
|
|
627
|
+
} as BaseEvent);
|
|
628
|
+
ch.serverPush("ag_ui_event", {
|
|
629
|
+
type: EventType.RUN_FINISHED,
|
|
630
|
+
threadId,
|
|
631
|
+
runId: "r-hist",
|
|
632
|
+
} as BaseEvent);
|
|
633
|
+
|
|
634
|
+
const events = await eventsPromise;
|
|
635
|
+
|
|
636
|
+
expect(events.map((e) => e.type)).toEqual([
|
|
637
|
+
EventType.RUN_STARTED,
|
|
638
|
+
EventType.RUN_FINISHED,
|
|
639
|
+
]);
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it("does not push a CUSTOM connect event after joining", () => {
|
|
643
|
+
const threadId = "t-connect-no-push";
|
|
644
|
+
const sub = runner.connect({ threadId }).subscribe();
|
|
645
|
+
const ch = mockChannels[0];
|
|
646
|
+
ch.triggerJoin("ok");
|
|
647
|
+
|
|
648
|
+
expect(ch.pushLog).toHaveLength(0);
|
|
649
|
+
sub.unsubscribe();
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it("joins the thread topic when joinCode is provided", () => {
|
|
653
|
+
const threadId = "t-connect-jc";
|
|
654
|
+
const sub = runner
|
|
655
|
+
.connect({ threadId, joinCode: "join-connect-456" })
|
|
656
|
+
.subscribe();
|
|
657
|
+
const ch = mockChannels[0];
|
|
658
|
+
|
|
659
|
+
expect(ch.topic).toBe(`thread:${threadId}`);
|
|
660
|
+
sub.unsubscribe();
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it("joins the thread topic when joinCode is not provided", () => {
|
|
664
|
+
const threadId = "t-connect-no-jc";
|
|
665
|
+
const sub = runner.connect({ threadId }).subscribe();
|
|
666
|
+
const ch = mockChannels[0];
|
|
667
|
+
|
|
668
|
+
expect(ch.topic).toBe(`thread:${threadId}`);
|
|
669
|
+
sub.unsubscribe();
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
it("errors the observable on channel join failure", async () => {
|
|
673
|
+
let error: Error | null = null;
|
|
674
|
+
const promise = new Promise<void>((resolve) => {
|
|
675
|
+
runner.connect({ threadId: "t-connect-err" }).subscribe({
|
|
676
|
+
error: (err) => {
|
|
677
|
+
error = err;
|
|
678
|
+
resolve();
|
|
679
|
+
},
|
|
680
|
+
complete: () => resolve(),
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
const ch = mockChannels[0];
|
|
684
|
+
ch.triggerJoin("error", { reason: "unauthorized" });
|
|
685
|
+
|
|
686
|
+
await promise;
|
|
687
|
+
expect(error).toBeInstanceOf(Error);
|
|
688
|
+
expect(error!.message).toContain("Failed to join channel");
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it("errors the observable on channel join timeout", async () => {
|
|
692
|
+
let error: Error | null = null;
|
|
693
|
+
const promise = new Promise<void>((resolve) => {
|
|
694
|
+
runner.connect({ threadId: "t-connect-timeout" }).subscribe({
|
|
695
|
+
error: (err) => {
|
|
696
|
+
error = err;
|
|
697
|
+
resolve();
|
|
698
|
+
},
|
|
699
|
+
complete: () => resolve(),
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
const ch = mockChannels[0];
|
|
703
|
+
ch.triggerJoin("timeout");
|
|
704
|
+
|
|
705
|
+
await promise;
|
|
706
|
+
expect(error).toBeInstanceOf(Error);
|
|
707
|
+
expect(error!.message).toBe("Timed out joining channel");
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
describe("isRunning", () => {
|
|
712
|
+
it("returns false for unknown threads", async () => {
|
|
713
|
+
expect(await runner.isRunning({ threadId: "nope" })).toBe(false);
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
it("returns true while a run is active", async () => {
|
|
717
|
+
const threadId = "t-running";
|
|
718
|
+
const input = createRunInput({ threadId, runId: "r-running" });
|
|
719
|
+
const agent = new MockAgent();
|
|
720
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
721
|
+
|
|
722
|
+
expect(await runner.isRunning({ threadId })).toBe(true);
|
|
723
|
+
sub.unsubscribe();
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
it("returns false after a run completes", async () => {
|
|
727
|
+
const threadId = "t-done";
|
|
728
|
+
const input = createRunInput({ threadId, runId: "r-done" });
|
|
729
|
+
|
|
730
|
+
const agentEvents: BaseEvent[] = [
|
|
731
|
+
{
|
|
732
|
+
type: EventType.RUN_FINISHED,
|
|
733
|
+
threadId,
|
|
734
|
+
runId: "r-done",
|
|
735
|
+
} as RunFinishedEvent,
|
|
736
|
+
];
|
|
737
|
+
const agent = new MockAgent(agentEvents);
|
|
738
|
+
|
|
739
|
+
const eventsPromise = collectEvents(
|
|
740
|
+
runner.run({ threadId, agent, input }),
|
|
741
|
+
);
|
|
742
|
+
const ch = mockChannels[0];
|
|
743
|
+
ch.triggerJoin("ok");
|
|
744
|
+
await eventsPromise;
|
|
745
|
+
|
|
746
|
+
expect(await runner.isRunning({ threadId })).toBe(false);
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
describe("stop", () => {
|
|
751
|
+
it("calls abortRun on the agent directly, no CUSTOM stop push", async () => {
|
|
752
|
+
const threadId = "t-stop";
|
|
753
|
+
const input = createRunInput({ threadId, runId: "r-stop" });
|
|
754
|
+
const agent = new MockAgent();
|
|
755
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
756
|
+
|
|
757
|
+
const result = await runner.stop({ threadId });
|
|
758
|
+
|
|
759
|
+
expect(result).toBe(true);
|
|
760
|
+
expect(agent.aborted).toBe(true);
|
|
761
|
+
|
|
762
|
+
const ch = mockChannels[0];
|
|
763
|
+
const stopPush = ch.pushLog.find((p) => p.payload?.name === "stop");
|
|
764
|
+
expect(stopPush).toBeUndefined();
|
|
765
|
+
sub.unsubscribe();
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it("returns false when the thread is not running", async () => {
|
|
769
|
+
expect(await runner.stop({ threadId: "nope" })).toBe(false);
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
it("returns false when stop has already been requested", async () => {
|
|
773
|
+
const threadId = "t-stop-twice";
|
|
774
|
+
const input = createRunInput({ threadId, runId: "r-stop2" });
|
|
775
|
+
const agent = new MockAgent();
|
|
776
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
777
|
+
|
|
778
|
+
expect(await runner.stop({ threadId })).toBe(true);
|
|
779
|
+
expect(await runner.stop({ threadId })).toBe(false);
|
|
780
|
+
sub.unsubscribe();
|
|
781
|
+
});
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
describe("cleanup", () => {
|
|
785
|
+
it("leaves the channel and disconnects the socket after the run completes", async () => {
|
|
786
|
+
const threadId = "t-cleanup";
|
|
787
|
+
const input = createRunInput({ threadId, runId: "r-cleanup" });
|
|
788
|
+
|
|
789
|
+
const agentEvents: BaseEvent[] = [
|
|
790
|
+
{
|
|
791
|
+
type: EventType.RUN_FINISHED,
|
|
792
|
+
threadId,
|
|
793
|
+
runId: "r-cleanup",
|
|
794
|
+
} as RunFinishedEvent,
|
|
795
|
+
];
|
|
796
|
+
const agent = new MockAgent(agentEvents);
|
|
797
|
+
|
|
798
|
+
const eventsPromise = collectEvents(
|
|
799
|
+
runner.run({ threadId, agent, input }),
|
|
800
|
+
);
|
|
801
|
+
const ch = mockChannels[0];
|
|
802
|
+
ch.triggerJoin("ok");
|
|
803
|
+
await eventsPromise;
|
|
804
|
+
|
|
805
|
+
expect(ch.left).toBe(true);
|
|
806
|
+
// Per-run socket should also be disconnected.
|
|
807
|
+
// mockSockets[0] is the socket created for this run.
|
|
808
|
+
expect(mockSockets[0].disconnected).toBe(true);
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
it("leaves the channel and disconnects the socket after a join failure", async () => {
|
|
812
|
+
const threadId = "t-cleanup-err";
|
|
813
|
+
const input = createRunInput({ threadId, runId: "r-cleanup-err" });
|
|
814
|
+
const agent = new MockAgent();
|
|
815
|
+
|
|
816
|
+
const eventsPromise = collectEvents(
|
|
817
|
+
runner.run({ threadId, agent, input }),
|
|
818
|
+
);
|
|
819
|
+
const ch = mockChannels[0];
|
|
820
|
+
ch.triggerJoin("error", { reason: "denied" });
|
|
821
|
+
await eventsPromise;
|
|
822
|
+
|
|
823
|
+
expect(ch.left).toBe(true);
|
|
824
|
+
expect(mockSockets[0].disconnected).toBe(true);
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
describe("per-run socket isolation", () => {
|
|
829
|
+
it("creates a separate socket for each run", () => {
|
|
830
|
+
const agent = new MockAgent();
|
|
831
|
+
const sub1 = runner
|
|
832
|
+
.run({
|
|
833
|
+
threadId: "t-iso-1",
|
|
834
|
+
agent,
|
|
835
|
+
input: createRunInput({ threadId: "t-iso-1", runId: "r-1" }),
|
|
836
|
+
})
|
|
837
|
+
.subscribe();
|
|
838
|
+
const sub2 = runner
|
|
839
|
+
.run({
|
|
840
|
+
threadId: "t-iso-2",
|
|
841
|
+
agent,
|
|
842
|
+
input: createRunInput({ threadId: "t-iso-2", runId: "r-2" }),
|
|
843
|
+
})
|
|
844
|
+
.subscribe();
|
|
845
|
+
|
|
846
|
+
// Each run should create its own socket (no shared socket).
|
|
847
|
+
expect(mockSockets.length).toBe(2);
|
|
848
|
+
expect(mockSockets[0]).not.toBe(mockSockets[1]);
|
|
849
|
+
|
|
850
|
+
sub1.unsubscribe();
|
|
851
|
+
sub2.unsubscribe();
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
it("disconnecting one run's socket does not affect another", async () => {
|
|
855
|
+
const agent1 = new MockAgent([
|
|
856
|
+
{
|
|
857
|
+
type: EventType.RUN_FINISHED,
|
|
858
|
+
threadId: "t-a",
|
|
859
|
+
runId: "r-a",
|
|
860
|
+
} as RunFinishedEvent,
|
|
861
|
+
]);
|
|
862
|
+
const agent2 = new MockAgent();
|
|
863
|
+
|
|
864
|
+
// Start two runs
|
|
865
|
+
const promise1 = collectEvents(
|
|
866
|
+
runner.run({
|
|
867
|
+
threadId: "t-a",
|
|
868
|
+
agent: agent1,
|
|
869
|
+
input: createRunInput({ threadId: "t-a", runId: "r-a" }),
|
|
870
|
+
}),
|
|
871
|
+
);
|
|
872
|
+
const sub2 = runner
|
|
873
|
+
.run({
|
|
874
|
+
threadId: "t-b",
|
|
875
|
+
agent: agent2,
|
|
876
|
+
input: createRunInput({ threadId: "t-b", runId: "r-b" }),
|
|
877
|
+
})
|
|
878
|
+
.subscribe();
|
|
879
|
+
|
|
880
|
+
// Complete run 1
|
|
881
|
+
mockChannels[0].triggerJoin("ok");
|
|
882
|
+
await promise1;
|
|
883
|
+
|
|
884
|
+
// Run 1's socket is disconnected, run 2's socket is untouched.
|
|
885
|
+
expect(mockSockets[0].disconnected).toBe(true);
|
|
886
|
+
expect(mockSockets[1].disconnected).toBe(false);
|
|
887
|
+
|
|
888
|
+
sub2.unsubscribe();
|
|
889
|
+
});
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
describe("socket error exhaustion", () => {
|
|
893
|
+
it("does not abort the agent on a single socket error", () => {
|
|
894
|
+
const threadId = "t-single-err";
|
|
895
|
+
const input = createRunInput({ threadId, runId: "r-single-err" });
|
|
896
|
+
const agent = new BlockingMockAgent();
|
|
897
|
+
|
|
898
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
899
|
+
const socket = mockSockets[0];
|
|
900
|
+
mockChannels[0].triggerJoin("ok");
|
|
901
|
+
|
|
902
|
+
socket.triggerError(new Error("network blip"));
|
|
903
|
+
|
|
904
|
+
expect(agent.aborted).toBe(false);
|
|
905
|
+
sub.unsubscribe();
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
it("aborts the agent after 5 consecutive socket errors", async () => {
|
|
909
|
+
const threadId = "t-exhaust";
|
|
910
|
+
const input = createRunInput({ threadId, runId: "r-exhaust" });
|
|
911
|
+
const agent = new BlockingMockAgent();
|
|
912
|
+
|
|
913
|
+
const eventsPromise = collectEvents(
|
|
914
|
+
runner.run({ threadId, agent, input }),
|
|
915
|
+
);
|
|
916
|
+
const socket = mockSockets[0];
|
|
917
|
+
mockChannels[0].triggerJoin("ok");
|
|
918
|
+
|
|
919
|
+
// Fire 5 consecutive errors — should trigger abortRun()
|
|
920
|
+
for (let i = 0; i < 5; i++) {
|
|
921
|
+
socket.triggerError(new Error("connection lost"));
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// The abort causes runAgent() to reject, which cascades through
|
|
925
|
+
// catchError → finalize → removeThread → Observable completes.
|
|
926
|
+
await eventsPromise;
|
|
927
|
+
|
|
928
|
+
expect(agent.aborted).toBe(true);
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
it("resets the error counter on successful reconnection", () => {
|
|
932
|
+
const threadId = "t-reset";
|
|
933
|
+
const input = createRunInput({ threadId, runId: "r-reset" });
|
|
934
|
+
const agent = new BlockingMockAgent();
|
|
935
|
+
|
|
936
|
+
const sub = runner.run({ threadId, agent, input }).subscribe();
|
|
937
|
+
const socket = mockSockets[0];
|
|
938
|
+
mockChannels[0].triggerJoin("ok");
|
|
939
|
+
|
|
940
|
+
// 4 errors (just below threshold)
|
|
941
|
+
for (let i = 0; i < 4; i++) {
|
|
942
|
+
socket.triggerError();
|
|
943
|
+
}
|
|
944
|
+
expect(agent.aborted).toBe(false);
|
|
945
|
+
|
|
946
|
+
// Successful reconnect resets the counter
|
|
947
|
+
socket.triggerOpen();
|
|
948
|
+
|
|
949
|
+
// 4 more errors — still below threshold because counter was reset
|
|
950
|
+
for (let i = 0; i < 4; i++) {
|
|
951
|
+
socket.triggerError();
|
|
952
|
+
}
|
|
953
|
+
expect(agent.aborted).toBe(false);
|
|
954
|
+
|
|
955
|
+
sub.unsubscribe();
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
it("fully cleans up after socket error exhaustion", async () => {
|
|
959
|
+
const threadId = "t-exhaust-cleanup";
|
|
960
|
+
const input = createRunInput({ threadId, runId: "r-exhaust-cleanup" });
|
|
961
|
+
const agent = new BlockingMockAgent();
|
|
962
|
+
|
|
963
|
+
const eventsPromise = collectEvents(
|
|
964
|
+
runner.run({ threadId, agent, input }),
|
|
965
|
+
);
|
|
966
|
+
const socket = mockSockets[0];
|
|
967
|
+
const ch = mockChannels[0];
|
|
968
|
+
ch.triggerJoin("ok");
|
|
969
|
+
|
|
970
|
+
for (let i = 0; i < 5; i++) {
|
|
971
|
+
socket.triggerError();
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
await eventsPromise;
|
|
975
|
+
|
|
976
|
+
expect(ch.left).toBe(true);
|
|
977
|
+
expect(socket.disconnected).toBe(true);
|
|
978
|
+
expect(await runner.isRunning({ threadId })).toBe(false);
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
});
|