@copilotkit/runtime 1.54.1 → 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 +113 -113
- 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 +24 -7
- 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,363 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { InMemoryAgentRunner } from "../in-memory";
|
|
3
|
+
import {
|
|
4
|
+
AbstractAgent,
|
|
5
|
+
BaseEvent,
|
|
6
|
+
EventType,
|
|
7
|
+
Message,
|
|
8
|
+
RunAgentInput,
|
|
9
|
+
RunErrorEvent,
|
|
10
|
+
RunStartedEvent,
|
|
11
|
+
TextMessageContentEvent,
|
|
12
|
+
TextMessageEndEvent,
|
|
13
|
+
TextMessageStartEvent,
|
|
14
|
+
ToolCallResultEvent,
|
|
15
|
+
} from "@ag-ui/client";
|
|
16
|
+
import { EMPTY, firstValueFrom } from "rxjs";
|
|
17
|
+
import { toArray } from "rxjs/operators";
|
|
18
|
+
|
|
19
|
+
const stripTerminalEvents = (events: BaseEvent[]) =>
|
|
20
|
+
events.filter(
|
|
21
|
+
(event) =>
|
|
22
|
+
event.type !== EventType.RUN_FINISHED &&
|
|
23
|
+
event.type !== EventType.RUN_ERROR,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
class TestAgent extends AbstractAgent {
|
|
27
|
+
constructor(
|
|
28
|
+
private readonly events: BaseEvent[] = [],
|
|
29
|
+
private readonly emitDefaultRunStarted = true,
|
|
30
|
+
) {
|
|
31
|
+
super();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async runAgent(
|
|
35
|
+
input: RunAgentInput,
|
|
36
|
+
options: {
|
|
37
|
+
onEvent: (event: { event: BaseEvent }) => void;
|
|
38
|
+
onNewMessage?: (args: { message: Message }) => void;
|
|
39
|
+
onRunStartedEvent?: () => void;
|
|
40
|
+
},
|
|
41
|
+
): Promise<void> {
|
|
42
|
+
if (this.emitDefaultRunStarted) {
|
|
43
|
+
const runStarted: RunStartedEvent = {
|
|
44
|
+
type: EventType.RUN_STARTED,
|
|
45
|
+
threadId: input.threadId,
|
|
46
|
+
runId: input.runId,
|
|
47
|
+
};
|
|
48
|
+
options.onEvent({ event: runStarted });
|
|
49
|
+
options.onRunStartedEvent?.();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const event of this.events) {
|
|
53
|
+
options.onEvent({ event });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
clone(): AbstractAgent {
|
|
58
|
+
return new TestAgent(this.events, this.emitDefaultRunStarted);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected run(): ReturnType<AbstractAgent["run"]> {
|
|
62
|
+
return EMPTY;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected connect(): ReturnType<AbstractAgent["connect"]> {
|
|
66
|
+
return EMPTY;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class ThrowingAgent extends AbstractAgent {
|
|
71
|
+
constructor(private readonly error: Error) {
|
|
72
|
+
super();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async runAgent(): Promise<void> {
|
|
76
|
+
throw this.error;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
clone(): AbstractAgent {
|
|
80
|
+
return new ThrowingAgent(this.error);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected run(): ReturnType<AbstractAgent["run"]> {
|
|
84
|
+
return EMPTY;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
protected connect(): ReturnType<AbstractAgent["connect"]> {
|
|
88
|
+
return EMPTY;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
describe("InMemoryAgentRunner", () => {
|
|
93
|
+
let runner: InMemoryAgentRunner;
|
|
94
|
+
|
|
95
|
+
beforeEach(() => {
|
|
96
|
+
runner = new InMemoryAgentRunner();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("RunStarted payload", () => {
|
|
100
|
+
it("emits RUN_STARTED before agent events", async () => {
|
|
101
|
+
const threadId = "in-memory-basic";
|
|
102
|
+
const agent = new TestAgent([
|
|
103
|
+
{
|
|
104
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
105
|
+
messageId: "msg-1",
|
|
106
|
+
role: "assistant",
|
|
107
|
+
} as TextMessageStartEvent,
|
|
108
|
+
{
|
|
109
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
110
|
+
messageId: "msg-1",
|
|
111
|
+
delta: "Hello",
|
|
112
|
+
} as TextMessageContentEvent,
|
|
113
|
+
{
|
|
114
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
115
|
+
messageId: "msg-1",
|
|
116
|
+
} as TextMessageEndEvent,
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
const events = await firstValueFrom(
|
|
120
|
+
runner
|
|
121
|
+
.run({
|
|
122
|
+
threadId,
|
|
123
|
+
agent,
|
|
124
|
+
input: { threadId, runId: "run-1", messages: [], state: {} },
|
|
125
|
+
})
|
|
126
|
+
.pipe(toArray()),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const nonTerminalEvents = stripTerminalEvents(events);
|
|
130
|
+
expect(nonTerminalEvents).toHaveLength(4);
|
|
131
|
+
expect(nonTerminalEvents[0].type).toBe(EventType.RUN_STARTED);
|
|
132
|
+
const compacted = nonTerminalEvents.slice(1);
|
|
133
|
+
expect(compacted[0].type).toBe(EventType.TEXT_MESSAGE_START);
|
|
134
|
+
expect(compacted[1].type).toBe(EventType.TEXT_MESSAGE_CONTENT);
|
|
135
|
+
expect((compacted[1] as TextMessageContentEvent).delta).toBe("Hello");
|
|
136
|
+
expect(compacted[2].type).toBe(EventType.TEXT_MESSAGE_END);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("attaches only new messages to the RUN_STARTED input", async () => {
|
|
140
|
+
const threadId = "in-memory-new-messages";
|
|
141
|
+
const existing: Message = {
|
|
142
|
+
id: "existing-msg",
|
|
143
|
+
role: "user",
|
|
144
|
+
content: "Hi",
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
await firstValueFrom(
|
|
148
|
+
runner
|
|
149
|
+
.run({
|
|
150
|
+
threadId,
|
|
151
|
+
agent: new TestAgent(),
|
|
152
|
+
input: {
|
|
153
|
+
threadId,
|
|
154
|
+
runId: "run-0",
|
|
155
|
+
messages: [existing],
|
|
156
|
+
state: {},
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
.pipe(toArray()),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const newMessage: Message = {
|
|
163
|
+
id: "new-msg",
|
|
164
|
+
role: "user",
|
|
165
|
+
content: "Follow up",
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const secondRun = await firstValueFrom(
|
|
169
|
+
runner
|
|
170
|
+
.run({
|
|
171
|
+
threadId,
|
|
172
|
+
agent: new TestAgent(),
|
|
173
|
+
input: {
|
|
174
|
+
threadId,
|
|
175
|
+
runId: "run-1",
|
|
176
|
+
messages: [existing, newMessage],
|
|
177
|
+
state: { counter: 1 },
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
.pipe(toArray()),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
const runStarted = secondRun[0] as RunStartedEvent;
|
|
184
|
+
expect(runStarted.input?.messages?.map((m) => m.id)).toEqual(["new-msg"]);
|
|
185
|
+
expect(runStarted.input?.state).toEqual({ counter: 1 });
|
|
186
|
+
|
|
187
|
+
const connectEvents = await firstValueFrom(
|
|
188
|
+
runner.connect({ threadId }).pipe(toArray()),
|
|
189
|
+
);
|
|
190
|
+
const latestRunStarted = connectEvents
|
|
191
|
+
.filter(
|
|
192
|
+
(event): event is RunStartedEvent =>
|
|
193
|
+
event.type === EventType.RUN_STARTED,
|
|
194
|
+
)
|
|
195
|
+
.pop();
|
|
196
|
+
expect(latestRunStarted?.input?.messages?.map((m) => m.id)).toEqual([
|
|
197
|
+
"new-msg",
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("preserves agent-provided RUN_STARTED input", async () => {
|
|
202
|
+
const threadId = "in-memory-agent-input";
|
|
203
|
+
const providedInput: RunAgentInput = {
|
|
204
|
+
threadId,
|
|
205
|
+
runId: "run-preserve",
|
|
206
|
+
messages: [],
|
|
207
|
+
state: { fromAgent: true },
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const agent = new TestAgent(
|
|
211
|
+
[
|
|
212
|
+
{
|
|
213
|
+
type: EventType.RUN_STARTED,
|
|
214
|
+
threadId,
|
|
215
|
+
runId: "run-preserve",
|
|
216
|
+
input: providedInput,
|
|
217
|
+
} as RunStartedEvent,
|
|
218
|
+
],
|
|
219
|
+
false,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const events = await firstValueFrom(
|
|
223
|
+
runner
|
|
224
|
+
.run({
|
|
225
|
+
threadId,
|
|
226
|
+
agent,
|
|
227
|
+
input: {
|
|
228
|
+
threadId,
|
|
229
|
+
runId: "run-preserve",
|
|
230
|
+
messages: [{ id: "extra", role: "user", content: "hi" }],
|
|
231
|
+
state: {},
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
.pipe(toArray()),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const nonTerminalEvents = stripTerminalEvents(events);
|
|
238
|
+
expect(nonTerminalEvents).toHaveLength(1);
|
|
239
|
+
const runStarted = nonTerminalEvents[0] as RunStartedEvent;
|
|
240
|
+
expect(runStarted.input).toBe(providedInput);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("Event propagation", () => {
|
|
245
|
+
it("replays agent events for new connections", async () => {
|
|
246
|
+
const threadId = "in-memory-replay";
|
|
247
|
+
const agent = new TestAgent([
|
|
248
|
+
{
|
|
249
|
+
type: EventType.TEXT_MESSAGE_START,
|
|
250
|
+
messageId: "msg-1",
|
|
251
|
+
role: "assistant",
|
|
252
|
+
} as TextMessageStartEvent,
|
|
253
|
+
{
|
|
254
|
+
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
255
|
+
messageId: "msg-1",
|
|
256
|
+
delta: "Hello",
|
|
257
|
+
} as TextMessageContentEvent,
|
|
258
|
+
{
|
|
259
|
+
type: EventType.TEXT_MESSAGE_END,
|
|
260
|
+
messageId: "msg-1",
|
|
261
|
+
} as TextMessageEndEvent,
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
await firstValueFrom(
|
|
265
|
+
runner
|
|
266
|
+
.run({
|
|
267
|
+
threadId,
|
|
268
|
+
agent,
|
|
269
|
+
input: { threadId, runId: "run-1", messages: [], state: {} },
|
|
270
|
+
})
|
|
271
|
+
.pipe(toArray()),
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
const connectEvents = await firstValueFrom(
|
|
275
|
+
runner.connect({ threadId }).pipe(toArray()),
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const nonTerminalEvents = stripTerminalEvents(connectEvents);
|
|
279
|
+
expect(nonTerminalEvents).toHaveLength(4);
|
|
280
|
+
expect(nonTerminalEvents[0].type).toBe(EventType.RUN_STARTED);
|
|
281
|
+
expect(nonTerminalEvents.slice(1).map((event) => event.type)).toEqual([
|
|
282
|
+
EventType.TEXT_MESSAGE_START,
|
|
283
|
+
EventType.TEXT_MESSAGE_CONTENT,
|
|
284
|
+
EventType.TEXT_MESSAGE_END,
|
|
285
|
+
]);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("keeps agent-generated tool results", async () => {
|
|
289
|
+
const threadId = "in-memory-tool-results";
|
|
290
|
+
const agent = new TestAgent([
|
|
291
|
+
{
|
|
292
|
+
type: EventType.TOOL_CALL_RESULT,
|
|
293
|
+
messageId: "tool-msg",
|
|
294
|
+
toolCallId: "tool-call",
|
|
295
|
+
content: "42",
|
|
296
|
+
role: "tool",
|
|
297
|
+
} as ToolCallResultEvent,
|
|
298
|
+
]);
|
|
299
|
+
|
|
300
|
+
const events = await firstValueFrom(
|
|
301
|
+
runner
|
|
302
|
+
.run({
|
|
303
|
+
threadId,
|
|
304
|
+
agent,
|
|
305
|
+
input: { threadId, runId: "run-1", messages: [], state: {} },
|
|
306
|
+
})
|
|
307
|
+
.pipe(toArray()),
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const nonTerminalEvents = stripTerminalEvents(events);
|
|
311
|
+
expect(nonTerminalEvents).toHaveLength(2);
|
|
312
|
+
const [, toolResult] = nonTerminalEvents;
|
|
313
|
+
expect(toolResult.type).toBe(EventType.TOOL_CALL_RESULT);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe("Error propagation", () => {
|
|
318
|
+
it("propagates the agent error message into the RUN_ERROR event", async () => {
|
|
319
|
+
const threadId = "in-memory-error-propagation";
|
|
320
|
+
const httpError = new Error("HTTP 401: Unauthorized");
|
|
321
|
+
const agent = new ThrowingAgent(httpError);
|
|
322
|
+
|
|
323
|
+
const events = await firstValueFrom(
|
|
324
|
+
runner
|
|
325
|
+
.run({
|
|
326
|
+
threadId,
|
|
327
|
+
agent,
|
|
328
|
+
input: { threadId, runId: "run-err", messages: [], state: {} },
|
|
329
|
+
})
|
|
330
|
+
.pipe(toArray()),
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const errorEvent = events.find(
|
|
334
|
+
(event): event is RunErrorEvent => event.type === EventType.RUN_ERROR,
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
expect(errorEvent).toBeDefined();
|
|
338
|
+
expect(errorEvent!.message).toBe("HTTP 401: Unauthorized");
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it("propagates non-HTTP error messages into the RUN_ERROR event", async () => {
|
|
342
|
+
const threadId = "in-memory-error-generic";
|
|
343
|
+
const agent = new ThrowingAgent(new Error("Connection refused"));
|
|
344
|
+
|
|
345
|
+
const events = await firstValueFrom(
|
|
346
|
+
runner
|
|
347
|
+
.run({
|
|
348
|
+
threadId,
|
|
349
|
+
agent,
|
|
350
|
+
input: { threadId, runId: "run-err-2", messages: [], state: {} },
|
|
351
|
+
})
|
|
352
|
+
.pipe(toArray()),
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
const errorEvent = events.find(
|
|
356
|
+
(event): event is RunErrorEvent => event.type === EventType.RUN_ERROR,
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
expect(errorEvent).toBeDefined();
|
|
360
|
+
expect(errorEvent!.message).toBe("Connection refused");
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|