AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
refactor(server-utils): split aiUtils out of agentAiUtils (#15486)
Abdul609e22e0dc19
diff --git a/brain/knowledge/ai-intelligence/ai-agents.md b/brain/knowledge/ai-intelligence/ai-agents.mdindex 49063ac4d7f..ada33e12d83 100644--- a/brain/knowledge/ai-intelligence/ai-agents.md+++ b/brain/knowledge/ai-intelligence/ai-agents.md@@ -53,7 +53,7 @@ A flow step type (the `run_agent` action of `@activepieces/piece-ai`) that runs- **A piece action's output is stringified into the tool result at the producer, so that is the only place it can be shortened with its shape intact.** `formatPieceActionRunResult` JSON-stringifies the whole output into one text blob; past that point a consumer trying to fit it in context can only cut a prefix, and the prefix of a Gmail search is DKIM headers. A five-email search reached the model as 2KB of `Received:` lines with every subject gone, while two rounds of improving the *worker's* array-finding heuristic changed nothing, because there was no array left to find. Shrink where the data is still structured, and measure the wrapped form so JSON escaping is counted rather than guessed.- **A test run of an agent step waits three hours before it admits nothing answered.** `AGENT_STEP_TIMEOUT_MS` is 3h and the same value is used whether or not `stepNameToTest` is set, so if the job never reaches a worker — a version-skewed worker idling by design is the usual cause — testing the step looks like a hang and eventually fails with `The agent did not report a result before this step timed out`. Check for a running, version-matched worker before debugging the step's config.- **In `agents.ts` the enums must stay above the schemas that use them.** A TS enum compiles to a hoisted `var` plus a deferred IIFE, so a schema evaluating `z.literal(AgentToolType.PIECE)` at module load before the enum block has run reads `undefined`. `tsc` catches it (`TS2450: Enum used before its declaration`), but only if you build — it is easy to introduce while reordering the file to satisfy the "exported types and constants at the end" convention.-- **Reasoning cannot be *disabled* on a reasoning-native endpoint, and the managed catalogue is full of models nobody chose.** `buildProviderOptions` (`server/utils/src/agent-ai-utils.ts`) expresses `disableThinking` as `reasoning: { enabled: false }` on the `ACTIVEPIECES`/`OPENROUTER` branch, and `prepareStep` sets `disableThinking` for the first step *and the whole discovery phase*. OpenRouter forwards the flag, and Gemini 3.x, GPT-6 Astra and Claude Fable 5.1 reject it outright: `Reasoning is mandatory for this endpoint and cannot be disabled.` The step dies before its first token. Four things this taught, in order of how easy each is to get wrong:+- **Reasoning cannot be *disabled* on a reasoning-native endpoint, and the managed catalogue is full of models nobody chose.** `buildProviderOptions` (`server/utils/src/agent-provider-options.ts`) expresses `disableThinking` as `reasoning: { enabled: false }` on the `ACTIVEPIECES`/`OPENROUTER` branch, and `prepareStep` sets `disableThinking` for the first step *and the whole discovery phase*. OpenRouter forwards the flag, and Gemini 3.x, GPT-6 Astra and Claude Fable 5.1 reject it outright: `Reasoning is mandatory for this endpoint and cannot be disabled.` The step dies before its first token. Four things this taught, in order of how easy each is to get wrong:- **Swapping in `{ effort: 'minimal' }` unconditionally is a regression, not a fix.** OpenRouter maps `minimal` to `low` for Anthropic, which is 20% of `max_tokens`, so the *thinking-disabled* first step on the Fast tier would get a bigger reasoning allowance (7,400) than its thinking-*enabled* step asks for (5,000). Every default tier is Anthropic, so that degrades every working customer to fix the broken ones. The suppression is gated on `aiProviderUtils.isCuratedChatModelId` instead: a model we picked keeps `{ enabled: false }`, anything else gets `{ effort: 'minimal' }`.- **`getCuratedChatModels` returns `undefined` for `ACTIVEPIECES` on purpose, so the managed provider serves the entire live OpenRouter catalogue.** Every failing model in the incident (`google/gemini-3.8-flash`, `openai/gpt-6-astra`, `openai/gpt-6-astra-pro`, `anthropic/claude-fable-5.1`) is absent from `ALLOWED_CHAT_MODELS_BY_PROVIDER`. Only a React `.filter()` narrows the picker to the three tiers; `modelName` is a free `z.string()` server-side and `agent-config-rpc` uses it verbatim for `FLOW_STEP` and `AGENT`. Hiding is not denying.- **The curated list is a guess about capability, so the code learns.** A rejection calls `noteReasoningIsMandatory`, which records the id **only if it is curated** so a caller-supplied model id cannot grow the set, and the existing one-shot `shouldRetryStream` re-issues the turn with a minimal budget. `gemini-3.7-flash` is curated *and* reasoning-native, which is exactly the case the list alone would miss.@@ -81,7 +81,7 @@ Paths verified 2026-07-17. An earlier version pointed at `packages/core/shared/s- **A knowledge base uploaded through the UI is not searchable.** Nothing in the upload path generates chunk embeddings; `knowledge-base.controller.ts` only *accepts* an embedding on a chunk. Chunks land with `embedding IS NULL`, and search filters those out, so the result is an empty answer rather than an error.- **`knowledge_base_chunk` is created by a migration that records itself as run even when pgvector is absent.** A database that gains pgvector later never gets the table, because the migration is already marked complete. Deleting its row from `migrations` replays it safely, since the DDL is `CREATE TABLE IF NOT EXISTS`.-- **Embeddings are stored at a fixed 768 dimensions, and most models do not return that.** `text-embedding-3-small` answers 1536, and the `dimensions` provider option is namespaced under `openai`, so the OpenRouter and managed paths never see it. `agentAiUtils.toStorageEmbedding` truncates and re-normalises instead, which is what the option does server-side and works whatever the provider returns. This only holds for Matryoshka-trained models — adding a model that is not one will truncate badly and silently.+- **Embeddings are stored at a fixed 768 dimensions, and most models do not return that.** `text-embedding-3-small` answers 1536, and the `dimensions` provider option is namespaced under `openai`, so the OpenRouter and managed paths never see it. `aiUtils.toStorageEmbedding` truncates and re-normalises instead, which is what the option does server-side and works whatever the provider returns. This only holds for Matryoshka-trained models — adding a model that is not one will truncate badly and silently.- **Saving a saved agent publishes it.** `POST /v1/agents/:id` sets `goLive: true` unless the body says otherwise, so an ordinary save copies the draft over the published snapshot. There is no separate publish step in the UI, deliberately: two versions with no history means nobody can say which one a linked flow runs. The consequence is easy to trip over in tests and callers — anything that needs `draft` to differ from `published` has to write the row directly (`db.update('agent', id, { draft })`) or pass `goLive: false`, which is what the Test tab uses to stage a change it can run without shipping it. A test that edited the draft through the API to prove "a flow runs the published copy" was quietly moving the copy it was asserting about, and it only started failing when the save-publishes change merged from another branch.- **`ap_add_agent_tools` will save a tool with no connection pinned.** `connectionExternalId` is optional, so a tool the AI adds without one carries no `predefinedInput.auth` for good. The visible symptom is a connection picker card on *every* conversation with that agent, which reads as the card being broken or the credential expiring — it is neither. The agent has nothing to use, so it asks, and the answer only ever lands on the run (`__store_selected_connection` writes a map the agent tool set does not read), so the next conversation asks again. Fixing the card is the wrong end: pin a connection when the tool is created, and write a chosen or repaired one back into `draft.tools` via `editDraftTools`.diff --git a/brain/knowledge/engineering/ci-pr-review-hygiene.md b/brain/knowledge/engineering/ci-pr-review-hygiene.mdindex 1bd42b62ee9..a063440f67d 100644--- a/brain/knowledge/engineering/ci-pr-review-hygiene.md+++ b/brain/knowledge/engineering/ci-pr-review-hygiene.md@@ -38,6 +38,8 @@ Enforcement is the **`Codeowners review` repository ruleset** (active on the def- **`redis-memory-server` compiles Redis from source during `bun install`, so its version must stay pinned.** It is in `trustedDependencies`, and with no version configured it defaults to `stable` — whatever `download.redis.io/redis-stable.tar.gz` points at today. When that moved to Redis 8.10.0 (2026-07-29), the bundled module tree (redisearch, redistimeseries, LibMR) started failing to build on runners and took `bun install` down across every branch: 8.10.0 vendors the module sources into the tarball and changes the default make goal to `build`, which compiles every module under `modules/*/src` regardless of `BUILD_WITH_MODULES`. It reads as flakiness because `ci.yml` caches `~/.bun/install/cache` but not the compiled binary, so each run recompiles and only sometimes survives. Root `package.json` pins `redisMemoryServer.version` to **8.8.1**, the newest release that still builds core-only — treat it as a ceiling, bump it deliberately, and never go back to `stable`.- **`validate-publishable-packages` compares against npm, not against `main`, so touching a published piece without bumping it fails CI on its own.** The error is `[packagePrePublishValidation] package version not incremented, path=packages/pieces/community/<piece>, version=X`. Editing *any* file in a published package is enough — a one-line change to the AI piece's model factory tripped it while `@activepieces/piece-ai` sat at `0.9.0` on npm. Check with `curl -s https://registry.npmjs.org/@activepieces/piece-<name> | jq -r ."dist-tags".latest`, and follow the piece's own history for the size of the bump: capability additions have gone minor, fixes patch. **The version lives in two files** — `package.json` *and* `bun.lock`, which records each workspace's version — so bump then `bun install`, or the lockfile check fails instead. Distinct from the merge-drift trap below: this one fires before any merge, and only for packages that are actually published.- **Standalone `prettier --check` disagrees with the `prettier/prettier` eslint rule in this repo, so it is a false guide — run `eslint` on the file.** From `packages/web`, `../../node_modules/.bin/eslint 'src/path/to/file.ts'` reproduces CI exactly and `--fix` resolves it. Standalone prettier flags files that are clean on `main` and that CI passes, whether invoked through `npx` or the pinned 2.8.4 with `--config .prettierrc` — so "prettier says it's unformatted" proves nothing, and chasing it wastes the time the eslint run would have taken. Only `packages/web` is prettier-enforced: the server and `packages/core/*` are 4-space, semicolon-free, and running prettier over them would rewrite the file wholesale.+- **`@activepieces/server-utils` has no `lint` script, so nothing in `packages/server/utils` is ever linted.** It is the only workspace under `packages/server/*` or `packages/core/*` missing one, and `turbo run lint` therefore skips it entirely — a green repo-wide lint says nothing about that package. Dead imports accumulate there unnoticed: `agent-ai-utils.ts` carried two unused ones for long enough that the split which finally surfaced them looked like it had caused them. Lint it by hand with `npx eslint 'packages/server/utils/src/**/*.ts'` (with the 8GB heap below) when you touch it, and expect pre-existing errors that are not yours.+- **Linting a single server test file OOMs node at its default heap — pass `NODE_OPTIONS=--max-old-space-size=8192`.** `npx eslint packages/server/api/test/.../<file>.test.ts` on one file died with `FATAL ERROR: Reached heap limit` after ~23s at 2GB, because the type-aware config loads the whole `packages/server/api` program regardless of how few files you name. It reads as a broken lint setup, not as a memory ceiling. The same run with an 8GB heap finishes and reports normally.- **`bun install` on a recent bun adds `"configVersion": 0` to `bun.lock`, which is not on `main`.** It rides along in any commit that touches the lockfile and reads as an unrelated change; drop the line and re-run `bun install --frozen-lockfile` to confirm the lockfile is still consistent without it. **You do not have to run `bun install` to get it** — a bare `npx vitest run <file>` in `packages/web` was enough to rewrite the lockfile with `configVersion` *plus* every workspace version already bumped in the branch, so `git status` after any verification run is worth a glance before committing.- **A version bump that merges cleanly can still be wrong — check what `main`'s number *means*, not whether it conflicts.** Two branches bumping the same package to the same number do not conflict, so git takes it silently; but if `main`'s copy of `0.5.0` is another PR's content and yours adds further exports on top, you ship new exports under an already-published version and nothing catches it. Seen merging [#15001](https://github.com/activepieces/activepieces/pull/15001) after the six-providers PR landed: `core-piece-types` and `pieces-framework` auto-merged at `0.5.0` / `0.37.0` and both needed a further bump. Only a *conflicting* version (like `core/shared` `0.140.0` vs `0.141.0`) forces you to think; the clean ones are the dangerous ones. After any merge, re-check every package you bumped against `git show origin/main:<pkg>/package.json`. The reverse also happens: when review makes you *delete* code, the bump it justified can become dead — after acting on review, `git diff origin/main...HEAD -- <pkg>/src` and drop the bump if it is empty. On #15001 two packages ended up byte-identical to `main` while still carrying a bump, which is noise at best and a version collision at worst.diff --git a/brain/knowledge/flows-execution/chat.md b/brain/knowledge/flows-execution/chat.mdindex 06aa2931fa4..fcdf6d9e0f8 100644--- a/brain/knowledge/flows-execution/chat.md+++ b/brain/knowledge/flows-execution/chat.md@@ -54,7 +54,8 @@ Entry point: `agentModule`, the Fastify plugin registered in `packages/server/ap- `packages/server/api/src/app/ee/agent/` — the API module: controllers, service, helpers, approval gate, compaction, rollout, console sync, billing (`chat-usage-tracker.ts`, `chat-tool-billing.ts`), memory (`agent-memory-ai.ts`, `user-memory-entity.ts`), entities, plus `tools/`, `mcp/`, `prompt/`, `history/` subdirs- `packages/server/worker/src/lib/execute/jobs/ee/agent/` — where the LLM loop actually runs: `execute-agent-run.ts` job handler (+ the three liveness timers + `streamChunksToClient` idle watchdog), `run-agent-turn.ts` DI streaming loop, `agent-worker-tools.ts` tool defs-- `packages/server/utils/src/agent-ai-utils.ts` — the AI-utils bag: `createChatModel` per provider, `supportsWebSearch`/`buildWebSearchTools`, `collapseStaleToolOutputs` history hygiene+- `packages/server/utils/src/ai-utils.ts` — the provider-agnostic half: `createModel` per provider, `createEmbeddingModel`/`toStorageEmbedding`, `supportsWebSearch`/`buildWebSearchTools`+- `packages/server/utils/src/agent-ai-utils.ts` — what is genuinely agent-shaped: `collapseStaleToolOutputs` history hygiene, the `onStepEnd` content handling- `packages/core/shared/src/lib/ee/agent/` — shared zod schemas and types, `tool-phases.ts` gating, `tool-classification.ts`, `chat-visibility.ts`- `packages/server/api/src/assets/prompts/` — system prompt + project-context markdown and the on-demand `guides/`; agent-eval fixtures live in `packages/server/worker/test/lib/agent-eval/`- `packages/web/src/app/routes/chat-with-ai/` — the chat page, chat box, conversation list, and `components/` cardsdiff --git a/packages/server/api/src/app/ee/agent/agent-helpers.ts b/packages/server/api/src/app/ee/agent/agent-helpers.tsindex f0e6be56256..b8a5cbd016b 100644--- a/packages/server/api/src/app/ee/agent/agent-helpers.ts+++ b/packages/server/api/src/app/ee/agent/agent-helpers.ts@@ -1,6 +1,6 @@import { ExecuteAgentRunJobData } from '@activepieces/core-execution'import { ActivepiecesError, AIProviderName, apId, ErrorCode, isNil, ProviderOutcomeReporter, spreadIfDefined, tryCatch, unique } from '@activepieces/core-utils'-import { agentAiUtils } from '@activepieces/server-utils'+import { aiUtils } from '@activepieces/server-utils'import { AgentConfig, AgentConversation, AgentConversationStatus, AI_PROVIDER_ENTITY_TYPES, GetAgentMemoryResponse, GetProviderConfigResponse, Project, ProjectType, UserMemory } from '@activepieces/shared'import { SharedV3ProviderOptions } from '@ai-sdk/provider'import { EmbeddingModel, LanguageModel } from 'ai'@@ -158,7 +158,7 @@ async function resolveTierModel({ platformId, tierId, provider, providerConfigIdconst providerConfig = await resolveRunProvider({ platformId, scope, log, ...spreadIfDefined('provider', provider), ...spreadIfDefined('providerConfigId', providerConfigId) })const modelId = agentModelResolution.resolveModelIdForProvider({ provider: providerConfig.provider, selectedModel: tierId, config: providerConfig.config, modelScope: providerConfig.modelScope, modelIds: providerConfig.modelIds })return {- model: agentAiUtils.createChatModel({+ model: aiUtils.createModel({provider: providerConfig.provider,auth: providerConfig.auth,config: providerConfig.config,@@ -177,7 +177,7 @@ async function resolveFastModel({ platformId, provider, providerConfigId, scope,async function resolveEmbeddingModel({ platformId, provider, providerConfigId, scope, log }: { platformId: string, provider?: AIProviderName, providerConfigId?: string, scope: ProviderScope, log: FastifyBaseLogger }): Promise<{ model: EmbeddingModel, providerOptions: SharedV3ProviderOptions }> {const providerConfig = await resolveRunProvider({ platformId, scope, log, ...spreadIfDefined('provider', provider), ...spreadIfDefined('providerConfigId', providerConfigId) })- return agentAiUtils.createEmbeddingModel({+ return aiUtils.createEmbeddingModel({provider: providerConfig.provider,auth: providerConfig.auth,config: providerConfig.config,diff --git a/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts b/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.tsindex 3f8d7a89229..8ea04b9a3ea 100644--- a/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts+++ b/packages/server/api/src/app/ee/agent/rpc/agent-config-rpc.ts@@ -1,5 +1,5 @@import { ActivepiecesError, ErrorCode, isNil, spreadIfDefined, tryCatch } from '@activepieces/core-utils'-import { agentAiUtils } from '@activepieces/server-utils'+import { agentAiUtils, aiUtils } from '@activepieces/server-utils'import { AgentConfigResponse, AgentConversationStatus, AgentRunSource, GetAgentConfigRequest, GetEnabledAiToolsResponse, PersistedAgentMessage, PersistedAgentPartType, PersistedAgentRole } from '@activepieces/shared'import { ModelMessage } from 'ai'import { FastifyBaseLogger } from 'fastify'@@ -97,7 +97,7 @@ export const agentConfigRpc = (log: FastifyBaseLogger) => ({const fetchAvailable = !dryRun// Tavily takes precedence over native LLM search; native is only the no-Tavily fallback.const tavilySearchAvailable = !isNil(aiTools.webSearch)- const webSearchAvailable = fetchAvailable && (tavilySearchAvailable || agentAiUtils.supportsWebSearch(providerConfig.provider))+ const webSearchAvailable = fetchAvailable && (tavilySearchAvailable || aiUtils.supportsWebSearch(providerConfig.provider))const lockResult = await agentHelpers.conversationRepo().createQueryBuilder()@@ -199,7 +199,7 @@ export const agentConfigRpc = (log: FastifyBaseLogger) => ({const willCompact = agentCompaction.shouldCompact({ estimatedTokens, provider: providerConfig.provider, messageCount: llmHistory.length })log.debug({ estimatedTokens, willCompact, messageCount: llmHistory.length, systemPromptLength: systemPromptText.length }, '[agentRpc#getAgentConfig] Compaction decision')if (willCompact) {- const model = agentAiUtils.createChatModel({+ const model = aiUtils.createModel({provider: providerConfig.provider,auth: providerConfig.auth as Record<string, unknown>,config: providerConfig.config as Record<string, unknown>,diff --git a/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts b/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.tsindex f7d8b40c184..834bb4a6f4c 100644--- a/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts+++ b/packages/server/api/src/app/ee/agent/rpc/tool-execution-rpc.ts@@ -1,5 +1,5 @@import { ActivepiecesError, ErrorCode, isNil, spreadIfDefined, tryCatch } from '@activepieces/core-utils'-import { agentAiUtils } from '@activepieces/server-utils'+import { aiUtils } from '@activepieces/server-utils'import { AGENT_SELF_EDIT_TOOLS, AGENT_SURFACE_TOOLS, AgentActionOutcome, AgentRunSource, agentToolClassification, ExecuteAgentToolRequest, ExecuteAgentToolResponse, ExecuteFlowToolRequest, ExecuteFlowToolResponse, ExecuteKnowledgeBaseToolRequest, ExecuteKnowledgeBaseToolResponse, ExecutePieceToolRequest, ExecutePieceToolResponse, FlowActionType, flowStructureUtil } from '@activepieces/shared'import { embed } from 'ai'import { FastifyBaseLogger } from 'fastify'@@ -80,7 +80,7 @@ export const toolExecutionRpc = (log: FastifyBaseLogger) => ({const results = await knowledgeBaseService(log).search({projectId,knowledgeBaseFileIds: [input.knowledgeBaseFileId],- queryEmbedding: agentAiUtils.toStorageEmbedding(embedding),+ queryEmbedding: aiUtils.toStorageEmbedding(embedding),limit: KNOWLEDGE_BASE_SEARCH_LIMIT,similarityThreshold: KNOWLEDGE_BASE_SIMILARITY_THRESHOLD,})diff --git a/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts b/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.tsindex 0a44291b14b..e72faef3da8 100644--- a/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts+++ b/packages/server/api/test/unit/app/ee/agent/agent-fast-model-provider.test.ts@@ -15,7 +15,7 @@ vi.mock('../../../../../src/app/ai/ai-provider-service', () => ({vi.mock('@activepieces/server-utils', async (importOriginal) => ({...(await importOriginal<Record<string, unknown>>()),- agentAiUtils: { createChatModel: (args: unknown) => args },+ aiUtils: { createModel: (args: unknown) => args },}))const { agentHelpers } = await import('../../../../../src/app/ee/agent/agent-helpers')diff --git a/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts b/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.tsindex aba7978db11..2f0c97a5bb8 100644--- a/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts+++ b/packages/server/api/test/unit/app/ee/agent/agent-rpc-handlers.test.ts@@ -95,7 +95,7 @@ vi.mock('../../../../../src/app/mcp/mcp-server-builder', async (importOriginal)vi.mock('@activepieces/server-utils', async (importOriginal) => ({...(await importOriginal<Record<string, unknown>>()),- agentAiUtils: { createChatModel: () => ({}), toStorageEmbedding: (embedding: number[]) => embedding.slice(0, 768) },+ aiUtils: { createModel: () => ({}), toStorageEmbedding: (embedding: number[]) => embedding.slice(0, 768) },}))type QueryBuilderMock = {diff --git a/packages/server/utils/src/agent-ai-utils.ts b/packages/server/utils/src/agent-ai-utils.tsindex ce98c0f5e24..90368d5db5b 100644--- a/packages/server/utils/src/agent-ai-utils.ts+++ b/packages/server/utils/src/agent-ai-utils.ts@@ -1,28 +1,10 @@-import { AIProviderName, isNil, observedProviderFetch, ProviderOutcomeReporter, spreadIfDefined } from '@activepieces/core-utils';-import { createLanguageModel } from '@activepieces/ai-providers';-import { AI_PROVIDER_CAPABILITIES, AIWebSearchMode, aiProviderUtils, BaseAIProviderAuthConfig, agentPersistenceUtils, agentToolClassification, CloudflareGatewayProviderConfig, PersistedAgentPart, PersistedAgentPartType, PersistedToolCallStatus, splitCloudflareGatewayModelId } from '@activepieces/shared';-import { createAnthropic } from '@ai-sdk/anthropic'-import { createAzure } from '@ai-sdk/azure'-import { createGoogleGenerativeAI } from '@ai-sdk/google'-import { createOpenAI } from '@ai-sdk/openai'-import { createOpenAICompatible } from '@ai-sdk/openai-compatible'-import { SharedV3ProviderOptions } from '@ai-sdk/provider'-import { createOpenRouter, OpenRouterChatSettings } from '@openrouter/ai-sdk-provider'+import { AIProviderName, isNil, spreadIfDefined } from '@activepieces/core-utils';+import { agentPersistenceUtils, agentToolClassification, PersistedAgentPart, PersistedAgentPartType, PersistedToolCallStatus } from '@activepieces/shared';import { agentProviderOptions } from './agent-provider-options'-import { EmbeddingModel, LanguageModel, ModelMessage, SystemModelMessage, TelemetryOptions, ToolSet } from 'ai'+import { ModelMessage, TelemetryOptions } from 'ai'import { createEvlogIntegration } from 'evlog/ai'import { wideEvent } from './wide-event'-const MAX_WEB_SEARCH_RESULTS = 5-export const EMBEDDING_DIMENSIONS = 768-const OPENAI_EMBEDDING_PROVIDER_OPTIONS: SharedV3ProviderOptions = {- openai: { dimensions: EMBEDDING_DIMENSIONS },-}--const OPENROUTER_EMBEDDING_PROVIDER_OPTIONS: SharedV3ProviderOptions = {- openrouter: { dimensions: EMBEDDING_DIMENSIONS },- openai: { dimensions: EMBEDDING_DIMENSIONS },-}const KEEP_RECENT_TOOL_RESULTS = 6const COLLAPSE_OUTPUT_OVER_CHARS = 600@@ -31,130 +13,6 @@ const COLLAPSE_OUTPUT_OVER_CHARS = 600const SCHEMA_TOOL_NAMES = new Set(['ap_get_piece_props', 'ap_prepare_action'])const CHARS_PER_TOKEN_ESTIMATE = 4-// OpenAI is absent on purpose: its web search needs the Responses API, which breaks legacy BYOK models.-// Which providers support web search (and how) is declared in AI_PROVIDER_CAPABILITIES; the native-// tool builders below stay here because they need the provider SDKs.-const NATIVE_WEB_SEARCH_TOOLS: Partial<Record<AIProviderName, (auth: BaseAIProviderAuthConfig) => ToolSet>> = {- [AIProviderName.ANTHROPIC]: ({ apiKey }) => ({ web_search: createAnthropic({ apiKey }).tools.webSearch_20250305({ maxUses: MAX_WEB_SEARCH_RESULTS }) }),- [AIProviderName.GOOGLE]: ({ apiKey }) => ({ google_search: createGoogleGenerativeAI({ apiKey }).tools.googleSearch({}) }),-}--function supportsWebSearch(provider: AIProviderName): boolean {- return AI_PROVIDER_CAPABILITIES[provider].webSearch !== undefined-}--function buildWebSearchTools({ provider, auth }: {- provider: AIProviderName- auth: Record<string, unknown>-}): ToolSet {- return NATIVE_WEB_SEARCH_TOOLS[provider]?.(auth as BaseAIProviderAuthConfig) ?? {}-}--function webSearchModeOf(provider: AIProviderName): AIWebSearchMode | undefined {- return AI_PROVIDER_CAPABILITIES[provider].webSearch-}--function openRouterModelSettings(provider: AIProviderName, webSearchEnabled: boolean): OpenRouterChatSettings | undefined {- if (!webSearchEnabled || AI_PROVIDER_CAPABILITIES[provider].webSearch !== 'plugin') {- return undefined- }- return { plugins: [{ id: 'web', max_results: MAX_WEB_SEARCH_RESULTS }] }-}--function createChatModel({ provider, auth, config, modelId, metadata, webSearchEnabled = false, onOutcome }: {- provider: AIProviderName- auth: Record<string, unknown>- config: Record<string, unknown>- modelId: string- metadata?: ChatModelMetadata- webSearchEnabled?: boolean- onOutcome?: ProviderOutcomeReporter-}): LanguageModel {- if (provider === AIProviderName.CLOUDFLARE_GATEWAY) {- const { apiKey } = auth as BaseAIProviderAuthConfig- const { accountId, gatewayId } = config as CloudflareGatewayProviderConfig- const { model: actualModelId } = splitCloudflareGatewayModelId(modelId)- return createOpenAICompatible({- name: 'cloudflare',- baseURL: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/compat`,- headers: { 'cf-aig-authorization': `Bearer ${apiKey}` },- ...spreadIfDefined('fetch', observedProviderFetch(onOutcome)),- }).chatModel(actualModelId)- }- return createLanguageModel({- provider,- auth,- config,- modelId,- options: {- openRouterSettings: openRouterModelSettings(provider, webSearchEnabled),- mistralViaOpenRouter: true,- ...spreadIfDefined('extraHeaders', managedProviderMetadataHeaders({ provider, metadata })),- ...spreadIfDefined('onOutcome', onOutcome),- },- })-}--function readStringField(source: Record<string, unknown>, key: string): string {- const value = source[key]- return typeof value === 'string' ? value : ''-}--function toStorageEmbedding(embedding: number[]): number[] {- if (embedding.length < EMBEDDING_DIMENSIONS) {- throw new Error(`This embedding model returns ${embedding.length} dimensions, fewer than the ${EMBEDDING_DIMENSIONS} a knowledge base stores`)- }- const truncated = embedding.slice(0, EMBEDDING_DIMENSIONS)- const magnitude = Math.sqrt(truncated.reduce((sum, value) => sum + value * value, 0))- return magnitude === 0 ? truncated : truncated.map((value) => value / magnitude)-}--function createEmbeddingModel({ provider, auth, config, onOutcome }: {- provider: AIProviderName- auth: Record<string, unknown>- config: Record<string, unknown>- onOutcome?: ProviderOutcomeReporter-}): { model: EmbeddingModel, providerOptions: SharedV3ProviderOptions } {- const embeddingModelId = AI_PROVIDER_CAPABILITIES[provider].defaultEmbeddingModel- if (isNil(embeddingModelId)) {- throw new Error(`Provider ${provider} does not support knowledge base search`)- }- const apiKey = readStringField(auth, 'apiKey')- const fetch = observedProviderFetch(onOutcome)- switch (provider) {- case AIProviderName.OPENAI:- return { model: createOpenAI({ apiKey, ...spreadIfDefined('fetch', fetch) }).embeddingModel(embeddingModelId), providerOptions: OPENAI_EMBEDDING_PROVIDER_OPTIONS }- case AIProviderName.GOOGLE:- return { model: createGoogleGenerativeAI({ apiKey, ...spreadIfDefined('fetch', fetch) }).textEmbeddingModel(embeddingModelId), providerOptions: {} }- case AIProviderName.AZURE: {- const resourceName = readStringField(config, 'resourceName')- const apiVersion = readStringField(config, 'apiVersion')- return {- model: createAzure({ resourceName, apiKey, ...spreadIfDefined('apiVersion', apiVersion || undefined), ...spreadIfDefined('fetch', fetch) }).embeddingModel(embeddingModelId),- providerOptions: OPENAI_EMBEDDING_PROVIDER_OPTIONS,- }- }- case AIProviderName.ACTIVEPIECES:- case AIProviderName.OPENROUTER:- return { model: createOpenRouter({ apiKey, ...spreadIfDefined('fetch', fetch) }).textEmbeddingModel(embeddingModelId), providerOptions: OPENROUTER_EMBEDDING_PROVIDER_OPTIONS }- default:- throw new Error(`Provider ${provider} does not support knowledge base search`)- }-}--function managedProviderMetadataHeaders({ provider, metadata }: {- provider: AIProviderName- metadata?: ChatModelMetadata-}): Record<string, string> | undefined {- if (isNil(metadata) || provider !== AIProviderName.ACTIVEPIECES) {- return undefined- }- return {- 'x-ap-platform-id': metadata.platformId,- 'x-ap-conversation-id': metadata.conversationId,- ...spreadIfDefined('x-ap-run-id', metadata.runId),- }-}/*** Strips for ALL providers (not just non-thinking ones) because Anthropic rejects@@ -527,12 +385,6 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {}export const agentAiUtils = {- createChatModel,- createEmbeddingModel,- toStorageEmbedding,- supportsWebSearch,- buildWebSearchTools,- webSearchModeOf,stripThinkingBlocks,sanitizeTruncatedAssistantTail,collectStepMessages,@@ -546,11 +398,3 @@ export const agentAiUtils = {}export type { ContentPartLike }--type ChatModelMetadata = {- platformId: string- conversationId: string- runId?: string-}--export type { ChatModelMetadata }diff --git a/packages/server/utils/src/ai-utils.ts b/packages/server/utils/src/ai-utils.tsnew file mode 100644index 00000000000..5b5ef09e582--- /dev/null+++ b/packages/server/utils/src/ai-utils.ts@@ -0,0 +1,164 @@+import { AIProviderName, isNil, observedProviderFetch, ProviderOutcomeReporter, spreadIfDefined } from '@activepieces/core-utils';+import { createLanguageModel } from '@activepieces/ai-providers';+import { AI_PROVIDER_CAPABILITIES, AIWebSearchMode, BaseAIProviderAuthConfig, CloudflareGatewayProviderConfig, splitCloudflareGatewayModelId } from '@activepieces/shared';+import { createAnthropic } from '@ai-sdk/anthropic'+import { createAzure } from '@ai-sdk/azure'+import { createGoogleGenerativeAI } from '@ai-sdk/google'+import { createOpenAI } from '@ai-sdk/openai'+import { createOpenAICompatible } from '@ai-sdk/openai-compatible'+import { SharedV3ProviderOptions } from '@ai-sdk/provider'+import { createOpenRouter, OpenRouterChatSettings } from '@openrouter/ai-sdk-provider'+import { EmbeddingModel, LanguageModel, ToolSet } from 'ai'++const MAX_WEB_SEARCH_RESULTS = 5+// OpenAI is absent on purpose: its web search needs the Responses API, which breaks legacy BYOK models.+// Which providers support web search (and how) is declared in AI_PROVIDER_CAPABILITIES; the native+// tool builders below stay here because they need the provider SDKs.+const NATIVE_WEB_SEARCH_TOOLS: Partial<Record<AIProviderName, (auth: BaseAIProviderAuthConfig) => ToolSet>> = {+ [AIProviderName.ANTHROPIC]: ({ apiKey }) => ({ web_search: createAnthropic({ apiKey }).tools.webSearch_20250305({ maxUses: MAX_WEB_SEARCH_RESULTS }) }),+ [AIProviderName.GOOGLE]: ({ apiKey }) => ({ google_search: createGoogleGenerativeAI({ apiKey }).tools.googleSearch({}) }),+}++function supportsWebSearch(provider: AIProviderName): boolean {+ return AI_PROVIDER_CAPABILITIES[provider].webSearch !== undefined+}++function buildWebSearchTools({ provider, auth }: {+ provider: AIProviderName+ auth: Record<string, unknown>+}): ToolSet {+ return NATIVE_WEB_SEARCH_TOOLS[provider]?.(auth as BaseAIProviderAuthConfig) ?? {}+}++function webSearchModeOf(provider: AIProviderName): AIWebSearchMode | undefined {+ return AI_PROVIDER_CAPABILITIES[provider].webSearch+}++function openRouterModelSettings(provider: AIProviderName, webSearchEnabled: boolean): OpenRouterChatSettings | undefined {+ if (!webSearchEnabled || AI_PROVIDER_CAPABILITIES[provider].webSearch !== 'plugin') {+ return undefined+ }+ return { plugins: [{ id: 'web', max_results: MAX_WEB_SEARCH_RESULTS }] }+}++function createModel({ provider, auth, config, modelId, metadata, webSearchEnabled = false, onOutcome }: {+ provider: AIProviderName+ auth: Record<string, unknown>+ config: Record<string, unknown>+ modelId: string+ metadata?: ChatModelMetadata+ webSearchEnabled?: boolean+ onOutcome?: ProviderOutcomeReporter+}): LanguageModel {+ if (provider === AIProviderName.CLOUDFLARE_GATEWAY) {+ const { apiKey } = auth as BaseAIProviderAuthConfig+ const { accountId, gatewayId } = config as CloudflareGatewayProviderConfig+ const { model: actualModelId } = splitCloudflareGatewayModelId(modelId)+ return createOpenAICompatible({+ name: 'cloudflare',+ baseURL: `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/compat`,+ headers: { 'cf-aig-authorization': `Bearer ${apiKey}` },+ ...spreadIfDefined('fetch', observedProviderFetch(onOutcome)),+ }).chatModel(actualModelId)+ }+ return createLanguageModel({+ provider,+ auth,+ config,+ modelId,+ options: {+ openRouterSettings: openRouterModelSettings(provider, webSearchEnabled),+ mistralViaOpenRouter: true,+ ...spreadIfDefined('extraHeaders', managedProviderMetadataHeaders({ provider, metadata })),+ ...spreadIfDefined('onOutcome', onOutcome),+ },+ })+}++function readStringField(source: Record<string, unknown>, key: string): string {+ const value = source[key]+ return typeof value === 'string' ? value : ''+}++function toStorageEmbedding(embedding: number[]): number[] {+ if (embedding.length < EMBEDDING_DIMENSIONS) {+ throw new Error(`This embedding model returns ${embedding.length} dimensions, fewer than the ${EMBEDDING_DIMENSIONS} a knowledge base stores`)+ }+ const truncated = embedding.slice(0, EMBEDDING_DIMENSIONS)+ const magnitude = Math.sqrt(truncated.reduce((sum, value) => sum + value * value, 0))+ return magnitude === 0 ? truncated : truncated.map((value) => value / magnitude)+}++function createEmbeddingModel({ provider, auth, config, onOutcome }: {+ provider: AIProviderName+ auth: Record<string, unknown>+ config: Record<string, unknown>+ onOutcome?: ProviderOutcomeReporter+}): { model: EmbeddingModel, providerOptions: SharedV3ProviderOptions } {+ const embeddingModelId = AI_PROVIDER_CAPABILITIES[provider].defaultEmbeddingModel+ if (isNil(embeddingModelId)) {+ throw new Error(`Provider ${provider} does not support knowledge base search`)+ }+ const apiKey = readStringField(auth, 'apiKey')+ const fetch = observedProviderFetch(onOutcome)+ switch (provider) {+ case AIProviderName.OPENAI:+ return { model: createOpenAI({ apiKey, ...spreadIfDefined('fetch', fetch) }).embeddingModel(embeddingModelId), providerOptions: OPENAI_EMBEDDING_PROVIDER_OPTIONS }+ case AIProviderName.GOOGLE:+ return { model: createGoogleGenerativeAI({ apiKey, ...spreadIfDefined('fetch', fetch) }).textEmbeddingModel(embeddingModelId), providerOptions: {} }+ case AIProviderName.AZURE: {+ const resourceName = readStringField(config, 'resourceName')+ const apiVersion = readStringField(config, 'apiVersion')+ return {+ model: createAzure({ resourceName, apiKey, ...spreadIfDefined('apiVersion', apiVersion || undefined), ...spreadIfDefined('fetch', fetch) }).embeddingModel(embeddingModelId),+ providerOptions: OPENAI_EMBEDDING_PROVIDER_OPTIONS,+ }+ }+ case AIProviderName.ACTIVEPIECES:+ case AIProviderName.OPENROUTER:+ return { model: createOpenRouter({ apiKey, ...spreadIfDefined('fetch', fetch) }).textEmbeddingModel(embeddingModelId), providerOptions: OPENROUTER_EMBEDDING_PROVIDER_OPTIONS }+ default:+ throw new Error(`Provider ${provider} does not support knowledge base search`)+ }+}++function managedProviderMetadataHeaders({ provider, metadata }: {+ provider: AIProviderName+ metadata?: ChatModelMetadata+}): Record<string, string> | undefined {+ if (isNil(metadata) || provider !== AIProviderName.ACTIVEPIECES) {+ return undefined+ }+ return {+ 'x-ap-platform-id': metadata.platformId,+ 'x-ap-conversation-id': metadata.conversationId,+ ...spreadIfDefined('x-ap-run-id', metadata.runId),+ }+}++export const EMBEDDING_DIMENSIONS = 768+const OPENAI_EMBEDDING_PROVIDER_OPTIONS: SharedV3ProviderOptions = {+ openai: { dimensions: EMBEDDING_DIMENSIONS },+}++const OPENROUTER_EMBEDDING_PROVIDER_OPTIONS: SharedV3ProviderOptions = {+ openrouter: { dimensions: EMBEDDING_DIMENSIONS },+ openai: { dimensions: EMBEDDING_DIMENSIONS },+}++export const aiUtils = {+ createModel,+ createEmbeddingModel,+ toStorageEmbedding,+ supportsWebSearch,+ buildWebSearchTools,+ webSearchModeOf,+}++type ChatModelMetadata = {+ platformId: string+ conversationId: string+ runId?: string+}++export type { ChatModelMetadata }diff --git a/packages/server/utils/src/index.ts b/packages/server/utils/src/index.tsindex e455f3de31d..1525db91b91 100644--- a/packages/server/utils/src/index.ts+++ b/packages/server/utils/src/index.ts@@ -27,6 +27,6 @@ export { safeHttp } from './safe-http'export type { SsrfAgents } from './safe-http'export { DEFAULT_MCP_MAX_RESPONSE_BYTES, DEFAULT_MCP_TIMEOUT_MS, mcpTransport } from './mcp-transport'export { systemUsage } from './system-usage'-export { EMBEDDING_DIMENSIONS } from './agent-ai-utils'export { agentAiUtils } from './agent-ai-utils'export type { ContentPartLike } from './agent-ai-utils'+export { aiUtils, EMBEDDING_DIMENSIONS } from './ai-utils'diff --git a/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-agent-run.ts b/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-agent-run.tsindex 29b757954dc..93cf70418e0 100644--- a/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-agent-run.ts+++ b/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-agent-run.ts@@ -1,5 +1,5 @@import { AIProviderName, ErrorCode, formatPieceError, isNil, isObject, spreadIfDefined, tryCatch, tryCatchSync } from '@activepieces/core-utils'-import { agentAiUtils } from '@activepieces/server-utils'+import { agentAiUtils, aiUtils } from '@activepieces/server-utils'import { AgentEvent, AgentEventType, AgentKnowledgeBaseTool, AgentMcpTool, AgentOutputField, AgentPhase, AgentPieceTool, AgentResult, AgentRunSource, AgentTool, AgentToolType, aiProviderUtils, EngineResponseStatus, ExecuteAgentRunJobData, MAX_AGENT_TURN_WALL_CLOCK_MS, PersistedAgentMessage, PersistedAgentPart, PersistedAgentPartType, PersistedAgentRole, ResolvedAgentFlowTool, WorkerJobType } from '@activepieces/shared'import { createUIMessageStream, generateText, ModelMessage, streamText, ToolSet, toUIMessageStream } from 'ai'import { FireAndForgetJobResult, JobContext, JobHandler, JobResultKind } from '../../../types'@@ -113,17 +113,17 @@ export const executeAgentRunJob: JobHandler<ExecuteAgentRunJobData, FireAndForge// nowhere to mark the turn. A run that can rewrite a saved agent does without it and// reads through ap_fetch_url or Tavily instead, both of which mark.const untrackedSearchWouldBeat = config.agentsAvailable- && agentAiUtils.webSearchModeOf(provider) === 'plugin'+ && aiUtils.webSearchModeOf(provider) === 'plugin'const webSearchActive = !dryRun&& !tavilySearchActive&& !untrackedSearchWouldBeat- && agentAiUtils.supportsWebSearch(provider)- const model = agentAiUtils.createChatModel({+ && aiUtils.supportsWebSearch(provider)+ const model = aiUtils.createModel({provider, auth: config.auth, config: config.providerConfig, modelId: config.modelId,metadata: { platformId, conversationId, runId },webSearchEnabled: webSearchActive,})- const fastModel = agentAiUtils.createChatModel({+ const fastModel = aiUtils.createModel({provider, auth: config.auth, config: config.providerConfig, modelId: config.fastModelId,})@@ -188,7 +188,7 @@ export const executeAgentRunJob: JobHandler<ExecuteAgentRunJobData, FireAndForgeconst webTools: ToolSet = dryRun ? {} : {...agentWorkerTools.createWebTools({ taintState }),...(aiTools.webSearch ? agentWorkerTools.createSearchTools({ webSearch: aiTools.webSearch, taintState }) : {}),- ...(webSearchActive ? agentWorkerTools.wrapToolsWithTaint({ tools: agentAiUtils.buildWebSearchTools({ provider, auth: config.auth }), taintState }) : {}),+ ...(webSearchActive ? agentWorkerTools.wrapToolsWithTaint({ tools: aiUtils.buildWebSearchTools({ provider, auth: config.auth }), taintState }) : {}),...(aiTools.webScraping ? agentWorkerTools.createScrapeTools({ scraping: aiTools.webScraping, taintState }) : {}),...(aiTools.imageGeneration && !discoveryOnly ? agentWorkerTools.createImageTools({imageGeneration: aiTools.imageGeneration,@@ -816,7 +816,7 @@ async function streamChunksToClient({ result, ctx, userId, conversationId, runId}async function generateTitleIfFirstTurn({ model, userMessage, previousUiMessages, log, conversationId, abortSignal }: {- model: ReturnType<typeof agentAiUtils.createChatModel>+ model: ReturnType<typeof aiUtils.createModel>userMessage: stringpreviousUiMessages: unknown[]log: JobContext['log']diff --git a/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-personalization-research.ts b/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-personalization-research.tsindex e5f755c85ab..002e0fa2495 100644--- a/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-personalization-research.ts+++ b/packages/server/worker/src/lib/execute/jobs/ee/agent/execute-personalization-research.ts@@ -1,5 +1,5 @@import { AIProviderName, isNil, tryCatch } from '@activepieces/core-utils'-import { agentAiUtils } from '@activepieces/server-utils'+import { aiUtils } from '@activepieces/server-utils'import { EngineResponseStatus, ExecutePersonalizationResearchJobData, WorkerJobType } from '@activepieces/shared'import { FireAndForgetJobResult, JobContext, JobHandler, JobResultKind } from '../../../types'import { runPrefillLookup } from './personalization-enrichment'@@ -75,7 +75,7 @@ async function runResearch({ data, config, progress, log }: {log: JobContext['log']}): Promise<ResearchOutput | null> {const provider = config.provider as AIProviderName- const fastModel = agentAiUtils.createChatModel({+ const fastModel = aiUtils.createModel({provider, auth: config.auth, config: config.providerConfig, modelId: config.fastModelId,})diff --git a/packages/server/worker/src/lib/execute/jobs/ee/agent/personalization-generate.ts b/packages/server/worker/src/lib/execute/jobs/ee/agent/personalization-generate.tsindex d63708b1e73..2f42aac8491 100644--- a/packages/server/worker/src/lib/execute/jobs/ee/agent/personalization-generate.ts+++ b/packages/server/worker/src/lib/execute/jobs/ee/agent/personalization-generate.ts@@ -1,5 +1,5 @@import { AIProviderName, isNil, tryCatch } from '@activepieces/core-utils'-import { agentAiUtils } from '@activepieces/server-utils'+import { aiUtils } from '@activepieces/server-utils'import { generateObject, generateText, LanguageModel, stepCountIs } from 'ai'import { z } from 'zod'import { JobContext } from '../../../types'@@ -18,11 +18,11 @@ export async function fallbackResearch({ provider, auth, providerConfig, fastModlog: JobContext['log']}): Promise<string> {const groundworkBlock = groundwork.length > 0 ? groundwork : '(no grounding facts could be gathered)'- if (!agentAiUtils.supportsWebSearch(provider)) {+ if (!aiUtils.supportsWebSearch(provider)) {return groundworkBlock}- const model = agentAiUtils.createChatModel({ provider, auth, config: providerConfig, modelId: fastModelId, webSearchEnabled: true })- const nativeTools = agentAiUtils.buildWebSearchTools({ provider, auth })+ const model = aiUtils.createModel({ provider, auth, config: providerConfig, modelId: fastModelId, webSearchEnabled: true })+ const nativeTools = aiUtils.buildWebSearchTools({ provider, auth })const { data, error } = await tryCatch(() => generateText({model,abortSignal: AbortSignal.timeout(FALLBACK_RESEARCH_TIMEOUT_MS),diff --git a/packages/server/worker/test/lib/agent-eval/core/llm-judge.ts b/packages/server/worker/test/lib/agent-eval/core/llm-judge.tsindex bd6030fbeea..18d0ad5e7a6 100644--- a/packages/server/worker/test/lib/agent-eval/core/llm-judge.ts+++ b/packages/server/worker/test/lib/agent-eval/core/llm-judge.ts@@ -1,4 +1,4 @@-import { agentAiUtils } from '@activepieces/server-utils'+import { aiUtils } from '@activepieces/server-utils'import { AIProviderName } from '@activepieces/core-utils';import { generateText } from 'ai'@@ -9,7 +9,7 @@ function createJudge({ provider, modelId, auth }: {modelId: stringauth: Record<string, unknown>}): { judge: (params: { dimension: string, rubric: string, transcript: string }) => Promise<JudgeVerdict> } {- const model = agentAiUtils.createChatModel({ provider, auth, config: {}, modelId })+ const model = aiUtils.createModel({ provider, auth, config: {}, modelId })const judge = async ({ dimension, rubric, transcript }: { dimension: string, rubric: string, transcript: string }): Promise<JudgeVerdict> => {const { text } = await generateText({diff --git a/packages/server/worker/test/lib/agent-eval/core/runner.ts b/packages/server/worker/test/lib/agent-eval/core/runner.tsindex f819a0b9dfa..64f0ecdfd03 100644--- a/packages/server/worker/test/lib/agent-eval/core/runner.ts+++ b/packages/server/worker/test/lib/agent-eval/core/runner.ts@@ -1,4 +1,4 @@-import { agentAiUtils } from '@activepieces/server-utils'+import { aiUtils } from '@activepieces/server-utils'import { tryCatch } from '@activepieces/core-utils';import { AgentPhase, PersistedAgentPartType } from '@activepieces/shared';import { hasToolCall, isLoopFinished, ModelMessage, ToolSet } from 'ai'@@ -107,7 +107,7 @@ async function runTurn({ fixture, systemPrompt, guides, auth }: { fixture: ChatEconst replay = replayExecutor.create({ recordedToolCalls: fixture.recordedToolCalls })const phaseState: { phase: AgentPhase } = { phase: 'discovery' }const tools = buildEvalToolSet({ replay, guides: guides ?? evalPrompts.loadGuides(), phaseState })- const model = agentAiUtils.createChatModel({ provider: fixture.model.provider, auth, config: {}, modelId: fixture.model.modelId })+ const model = aiUtils.createModel({ provider: fixture.model.provider, auth, config: {}, modelId: fixture.model.modelId })const messages: ModelMessage[] = [...fixture.initialMessages,...fixture.userTurns.map((content) => ({ role: 'user' as const, content })),