@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,516 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { BasicAgent, defineTool } from "../index";
|
|
4
|
+
import { EventType, type RunAgentInput } from "@ag-ui/client";
|
|
5
|
+
import { streamText } from "ai";
|
|
6
|
+
import {
|
|
7
|
+
mockStreamTextResponse,
|
|
8
|
+
toolCallStreamingStart,
|
|
9
|
+
toolCall,
|
|
10
|
+
toolResult,
|
|
11
|
+
finish,
|
|
12
|
+
collectEvents,
|
|
13
|
+
} from "./test-helpers";
|
|
14
|
+
|
|
15
|
+
// Mock the ai module
|
|
16
|
+
vi.mock("ai", () => ({
|
|
17
|
+
streamText: vi.fn(),
|
|
18
|
+
tool: vi.fn((config) => config),
|
|
19
|
+
stepCountIs: vi.fn((count: number) => ({ type: "stepCount", count })),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
// Mock the SDK clients
|
|
23
|
+
vi.mock("@ai-sdk/openai", () => ({
|
|
24
|
+
createOpenAI: vi.fn(() => (modelId: string) => ({
|
|
25
|
+
modelId,
|
|
26
|
+
provider: "openai",
|
|
27
|
+
})),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
describe("Config Tools Server-Side Execution", () => {
|
|
31
|
+
const originalEnv = process.env;
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
vi.clearAllMocks();
|
|
35
|
+
process.env = { ...originalEnv };
|
|
36
|
+
process.env.OPENAI_API_KEY = "test-key";
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
process.env = originalEnv;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("Tool Definition with Execute", () => {
|
|
44
|
+
it("should pass execute function to streamText tools", async () => {
|
|
45
|
+
const executeFn = vi.fn().mockResolvedValue({ result: "executed" });
|
|
46
|
+
|
|
47
|
+
const weatherTool = defineTool({
|
|
48
|
+
name: "getWeather",
|
|
49
|
+
description: "Get weather for a city",
|
|
50
|
+
parameters: z.object({
|
|
51
|
+
city: z.string().describe("The city name"),
|
|
52
|
+
}),
|
|
53
|
+
execute: executeFn,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const agent = new BasicAgent({
|
|
57
|
+
model: "openai/gpt-4o",
|
|
58
|
+
tools: [weatherTool],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
vi.mocked(streamText).mockReturnValue(
|
|
62
|
+
mockStreamTextResponse([finish()]) as any,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const input: RunAgentInput = {
|
|
66
|
+
threadId: "thread1",
|
|
67
|
+
runId: "run1",
|
|
68
|
+
messages: [],
|
|
69
|
+
tools: [],
|
|
70
|
+
context: [],
|
|
71
|
+
state: {},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
await collectEvents(agent["run"](input));
|
|
75
|
+
|
|
76
|
+
// Verify streamText was called with tools that have execute functions
|
|
77
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
78
|
+
expect(callArgs.tools).toHaveProperty("getWeather");
|
|
79
|
+
expect(callArgs.tools.getWeather).toHaveProperty("execute");
|
|
80
|
+
expect(typeof callArgs.tools.getWeather.execute).toBe("function");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should include all tool properties in the Vercel AI SDK tool", async () => {
|
|
84
|
+
const executeFn = vi.fn().mockResolvedValue({ temperature: 72 });
|
|
85
|
+
|
|
86
|
+
const weatherTool = defineTool({
|
|
87
|
+
name: "getWeather",
|
|
88
|
+
description: "Get weather for a city",
|
|
89
|
+
parameters: z.object({
|
|
90
|
+
city: z.string(),
|
|
91
|
+
units: z.enum(["celsius", "fahrenheit"]).optional(),
|
|
92
|
+
}),
|
|
93
|
+
execute: executeFn,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const agent = new BasicAgent({
|
|
97
|
+
model: "openai/gpt-4o",
|
|
98
|
+
tools: [weatherTool],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
vi.mocked(streamText).mockReturnValue(
|
|
102
|
+
mockStreamTextResponse([finish()]) as any,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const input: RunAgentInput = {
|
|
106
|
+
threadId: "thread1",
|
|
107
|
+
runId: "run1",
|
|
108
|
+
messages: [],
|
|
109
|
+
tools: [],
|
|
110
|
+
context: [],
|
|
111
|
+
state: {},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
await collectEvents(agent["run"](input));
|
|
115
|
+
|
|
116
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
117
|
+
const tool = callArgs.tools.getWeather;
|
|
118
|
+
|
|
119
|
+
expect(tool.description).toBe("Get weather for a city");
|
|
120
|
+
expect(tool.inputSchema).toBeDefined();
|
|
121
|
+
expect(tool.execute).toBe(executeFn);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should handle multiple config tools with execute functions", async () => {
|
|
125
|
+
const weatherExecute = vi.fn().mockResolvedValue({ temp: 72 });
|
|
126
|
+
const searchExecute = vi.fn().mockResolvedValue({ results: [] });
|
|
127
|
+
|
|
128
|
+
const weatherTool = defineTool({
|
|
129
|
+
name: "getWeather",
|
|
130
|
+
description: "Get weather",
|
|
131
|
+
parameters: z.object({ city: z.string() }),
|
|
132
|
+
execute: weatherExecute,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const searchTool = defineTool({
|
|
136
|
+
name: "search",
|
|
137
|
+
description: "Search the web",
|
|
138
|
+
parameters: z.object({ query: z.string() }),
|
|
139
|
+
execute: searchExecute,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const agent = new BasicAgent({
|
|
143
|
+
model: "openai/gpt-4o",
|
|
144
|
+
tools: [weatherTool, searchTool],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
vi.mocked(streamText).mockReturnValue(
|
|
148
|
+
mockStreamTextResponse([finish()]) as any,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const input: RunAgentInput = {
|
|
152
|
+
threadId: "thread1",
|
|
153
|
+
runId: "run1",
|
|
154
|
+
messages: [],
|
|
155
|
+
tools: [],
|
|
156
|
+
context: [],
|
|
157
|
+
state: {},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
await collectEvents(agent["run"](input));
|
|
161
|
+
|
|
162
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
163
|
+
|
|
164
|
+
expect(callArgs.tools.getWeather.execute).toBe(weatherExecute);
|
|
165
|
+
expect(callArgs.tools.search.execute).toBe(searchExecute);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("Config Tools vs Input Tools", () => {
|
|
170
|
+
it("config tools should have execute, input tools should not", async () => {
|
|
171
|
+
const configExecute = vi.fn().mockResolvedValue({ result: "server" });
|
|
172
|
+
|
|
173
|
+
const configTool = defineTool({
|
|
174
|
+
name: "serverTool",
|
|
175
|
+
description: "Runs on server",
|
|
176
|
+
parameters: z.object({ data: z.string() }),
|
|
177
|
+
execute: configExecute,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const agent = new BasicAgent({
|
|
181
|
+
model: "openai/gpt-4o",
|
|
182
|
+
tools: [configTool],
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
vi.mocked(streamText).mockReturnValue(
|
|
186
|
+
mockStreamTextResponse([finish()]) as any,
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const input: RunAgentInput = {
|
|
190
|
+
threadId: "thread1",
|
|
191
|
+
runId: "run1",
|
|
192
|
+
messages: [],
|
|
193
|
+
tools: [
|
|
194
|
+
{
|
|
195
|
+
name: "clientTool",
|
|
196
|
+
description: "Runs on client",
|
|
197
|
+
parameters: {
|
|
198
|
+
type: "object",
|
|
199
|
+
properties: { input: { type: "string" } },
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
context: [],
|
|
204
|
+
state: {},
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
await collectEvents(agent["run"](input));
|
|
208
|
+
|
|
209
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
210
|
+
|
|
211
|
+
// Config tool has execute
|
|
212
|
+
expect(callArgs.tools.serverTool.execute).toBe(configExecute);
|
|
213
|
+
|
|
214
|
+
// Input tool does NOT have execute (client-side execution)
|
|
215
|
+
expect(callArgs.tools.clientTool.execute).toBeUndefined();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("Execute Function Invocation", () => {
|
|
220
|
+
it("execute function can be called with correct arguments", async () => {
|
|
221
|
+
const executeFn = vi
|
|
222
|
+
.fn()
|
|
223
|
+
.mockResolvedValue({ weather: "sunny", temp: 72 });
|
|
224
|
+
|
|
225
|
+
const weatherTool = defineTool({
|
|
226
|
+
name: "getWeather",
|
|
227
|
+
description: "Get weather",
|
|
228
|
+
parameters: z.object({
|
|
229
|
+
city: z.string(),
|
|
230
|
+
units: z.enum(["celsius", "fahrenheit"]),
|
|
231
|
+
}),
|
|
232
|
+
execute: executeFn,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const agent = new BasicAgent({
|
|
236
|
+
model: "openai/gpt-4o",
|
|
237
|
+
tools: [weatherTool],
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
vi.mocked(streamText).mockReturnValue(
|
|
241
|
+
mockStreamTextResponse([finish()]) as any,
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const input: RunAgentInput = {
|
|
245
|
+
threadId: "thread1",
|
|
246
|
+
runId: "run1",
|
|
247
|
+
messages: [],
|
|
248
|
+
tools: [],
|
|
249
|
+
context: [],
|
|
250
|
+
state: {},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
await collectEvents(agent["run"](input));
|
|
254
|
+
|
|
255
|
+
// Get the execute function that was passed to streamText
|
|
256
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
257
|
+
const passedExecute = callArgs.tools.getWeather.execute;
|
|
258
|
+
|
|
259
|
+
// Manually invoke it to verify it works correctly
|
|
260
|
+
const result = await passedExecute({
|
|
261
|
+
city: "New York",
|
|
262
|
+
units: "fahrenheit",
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
expect(executeFn).toHaveBeenCalledWith({
|
|
266
|
+
city: "New York",
|
|
267
|
+
units: "fahrenheit",
|
|
268
|
+
});
|
|
269
|
+
expect(result).toEqual({ weather: "sunny", temp: 72 });
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("execute function errors are propagated", async () => {
|
|
273
|
+
const executeFn = vi.fn().mockRejectedValue(new Error("API unavailable"));
|
|
274
|
+
|
|
275
|
+
const failingTool = defineTool({
|
|
276
|
+
name: "failingTool",
|
|
277
|
+
description: "A tool that fails",
|
|
278
|
+
parameters: z.object({}),
|
|
279
|
+
execute: executeFn,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const agent = new BasicAgent({
|
|
283
|
+
model: "openai/gpt-4o",
|
|
284
|
+
tools: [failingTool],
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
vi.mocked(streamText).mockReturnValue(
|
|
288
|
+
mockStreamTextResponse([finish()]) as any,
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const input: RunAgentInput = {
|
|
292
|
+
threadId: "thread1",
|
|
293
|
+
runId: "run1",
|
|
294
|
+
messages: [],
|
|
295
|
+
tools: [],
|
|
296
|
+
context: [],
|
|
297
|
+
state: {},
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
await collectEvents(agent["run"](input));
|
|
301
|
+
|
|
302
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
303
|
+
const passedExecute = callArgs.tools.failingTool.execute;
|
|
304
|
+
|
|
305
|
+
await expect(passedExecute({})).rejects.toThrow("API unavailable");
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe("Built-in State Tools Still Work", () => {
|
|
310
|
+
it("AGUISendStateSnapshot should have execute alongside config tools", async () => {
|
|
311
|
+
const configExecute = vi.fn().mockResolvedValue({});
|
|
312
|
+
|
|
313
|
+
const configTool = defineTool({
|
|
314
|
+
name: "myTool",
|
|
315
|
+
description: "My tool",
|
|
316
|
+
parameters: z.object({}),
|
|
317
|
+
execute: configExecute,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const agent = new BasicAgent({
|
|
321
|
+
model: "openai/gpt-4o",
|
|
322
|
+
tools: [configTool],
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
vi.mocked(streamText).mockReturnValue(
|
|
326
|
+
mockStreamTextResponse([finish()]) as any,
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
const input: RunAgentInput = {
|
|
330
|
+
threadId: "thread1",
|
|
331
|
+
runId: "run1",
|
|
332
|
+
messages: [],
|
|
333
|
+
tools: [],
|
|
334
|
+
context: [],
|
|
335
|
+
state: { value: 1 },
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
await collectEvents(agent["run"](input));
|
|
339
|
+
|
|
340
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
341
|
+
|
|
342
|
+
// Both config tool and state tools should have execute
|
|
343
|
+
expect(callArgs.tools.myTool.execute).toBe(configExecute);
|
|
344
|
+
expect(callArgs.tools.AGUISendStateSnapshot.execute).toBeDefined();
|
|
345
|
+
expect(callArgs.tools.AGUISendStateDelta.execute).toBeDefined();
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
describe("Message ID Generation", () => {
|
|
350
|
+
it("should use messageId from text-start event", async () => {
|
|
351
|
+
const executeFn = vi.fn().mockResolvedValue({ result: "ok" });
|
|
352
|
+
|
|
353
|
+
const tool = defineTool({
|
|
354
|
+
name: "myTool",
|
|
355
|
+
description: "My tool",
|
|
356
|
+
parameters: z.object({}),
|
|
357
|
+
execute: executeFn,
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
const agent = new BasicAgent({
|
|
361
|
+
model: "openai/gpt-4o",
|
|
362
|
+
tools: [tool],
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
vi.mocked(streamText).mockReturnValue(
|
|
366
|
+
mockStreamTextResponse([
|
|
367
|
+
{ type: "text-start", id: "msg-1" },
|
|
368
|
+
{ type: "text-delta", text: "Before " },
|
|
369
|
+
{ type: "text-delta", text: "tool" },
|
|
370
|
+
toolCallStreamingStart("call1", "myTool"),
|
|
371
|
+
toolCall("call1", "myTool"),
|
|
372
|
+
toolResult("call1", "myTool", { result: "ok" }),
|
|
373
|
+
{ type: "text-start", id: "msg-2" },
|
|
374
|
+
{ type: "text-delta", text: "After " },
|
|
375
|
+
{ type: "text-delta", text: "tool" },
|
|
376
|
+
finish(),
|
|
377
|
+
]) as any,
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
const input: RunAgentInput = {
|
|
381
|
+
threadId: "thread1",
|
|
382
|
+
runId: "run1",
|
|
383
|
+
messages: [],
|
|
384
|
+
tools: [],
|
|
385
|
+
context: [],
|
|
386
|
+
state: {},
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const events = await collectEvents(agent["run"](input));
|
|
390
|
+
|
|
391
|
+
const textEvents = events.filter(
|
|
392
|
+
(e: any) => e.type === EventType.TEXT_MESSAGE_CHUNK,
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
// First two text chunks should have messageId from first text-start
|
|
396
|
+
expect(textEvents[0].messageId).toBe("msg-1");
|
|
397
|
+
expect(textEvents[1].messageId).toBe("msg-1");
|
|
398
|
+
|
|
399
|
+
// After tool result, text chunks should have messageId from second text-start
|
|
400
|
+
expect(textEvents[2].messageId).toBe("msg-2");
|
|
401
|
+
expect(textEvents[3].messageId).toBe("msg-2");
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
describe("Multi-Step Execution (maxSteps)", () => {
|
|
406
|
+
it("should pass stopWhen with stepCountIs when maxSteps is configured", async () => {
|
|
407
|
+
const executeFn = vi.fn().mockResolvedValue({ result: "ok" });
|
|
408
|
+
|
|
409
|
+
const tool = defineTool({
|
|
410
|
+
name: "myTool",
|
|
411
|
+
description: "My tool",
|
|
412
|
+
parameters: z.object({}),
|
|
413
|
+
execute: executeFn,
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
const agent = new BasicAgent({
|
|
417
|
+
model: "openai/gpt-4o",
|
|
418
|
+
maxSteps: 5,
|
|
419
|
+
tools: [tool],
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
vi.mocked(streamText).mockReturnValue(
|
|
423
|
+
mockStreamTextResponse([finish()]) as any,
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
const input: RunAgentInput = {
|
|
427
|
+
threadId: "thread1",
|
|
428
|
+
runId: "run1",
|
|
429
|
+
messages: [],
|
|
430
|
+
tools: [],
|
|
431
|
+
context: [],
|
|
432
|
+
state: {},
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
await collectEvents(agent["run"](input));
|
|
436
|
+
|
|
437
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
438
|
+
|
|
439
|
+
// stopWhen should be set with stepCountIs(5)
|
|
440
|
+
expect(callArgs.stopWhen).toEqual({ type: "stepCount", count: 5 });
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
it("should not set stopWhen when maxSteps is not configured", async () => {
|
|
444
|
+
const executeFn = vi.fn().mockResolvedValue({ result: "ok" });
|
|
445
|
+
|
|
446
|
+
const tool = defineTool({
|
|
447
|
+
name: "myTool",
|
|
448
|
+
description: "My tool",
|
|
449
|
+
parameters: z.object({}),
|
|
450
|
+
execute: executeFn,
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
const agent = new BasicAgent({
|
|
454
|
+
model: "openai/gpt-4o",
|
|
455
|
+
// maxSteps not set
|
|
456
|
+
tools: [tool],
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
vi.mocked(streamText).mockReturnValue(
|
|
460
|
+
mockStreamTextResponse([finish()]) as any,
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
const input: RunAgentInput = {
|
|
464
|
+
threadId: "thread1",
|
|
465
|
+
runId: "run1",
|
|
466
|
+
messages: [],
|
|
467
|
+
tools: [],
|
|
468
|
+
context: [],
|
|
469
|
+
state: {},
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
await collectEvents(agent["run"](input));
|
|
473
|
+
|
|
474
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
475
|
+
|
|
476
|
+
// stopWhen should be undefined (defaults to stepCountIs(1) in SDK)
|
|
477
|
+
expect(callArgs.stopWhen).toBeUndefined();
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it("should allow high maxSteps for complex tool chains", async () => {
|
|
481
|
+
const executeFn = vi.fn().mockResolvedValue({});
|
|
482
|
+
|
|
483
|
+
const tool = defineTool({
|
|
484
|
+
name: "chainTool",
|
|
485
|
+
description: "Tool for chaining",
|
|
486
|
+
parameters: z.object({}),
|
|
487
|
+
execute: executeFn,
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
const agent = new BasicAgent({
|
|
491
|
+
model: "openai/gpt-4o",
|
|
492
|
+
maxSteps: 10,
|
|
493
|
+
tools: [tool],
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
vi.mocked(streamText).mockReturnValue(
|
|
497
|
+
mockStreamTextResponse([finish()]) as any,
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
const input: RunAgentInput = {
|
|
501
|
+
threadId: "thread1",
|
|
502
|
+
runId: "run1",
|
|
503
|
+
messages: [],
|
|
504
|
+
tools: [],
|
|
505
|
+
context: [],
|
|
506
|
+
state: {},
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
await collectEvents(agent["run"](input));
|
|
510
|
+
|
|
511
|
+
const callArgs = vi.mocked(streamText).mock.calls[0][0];
|
|
512
|
+
|
|
513
|
+
expect(callArgs.stopWhen).toEqual({ type: "stepCount", count: 10 });
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
});
|