From 6f0a093869298255ce22600d78daaa3af613b934 Mon Sep 17 00:00:00 2001 From: Waleed Date: Sat, 24 Jan 2026 18:50:37 -0800 Subject: [PATCH] fix(llm): update router and llm_chat tool to call providers routes (#2986) * fix(llm): update router and llm_chat tool to call providers routes * updated failing tests --- .../handlers/evaluator/evaluator-handler.ts | 8 +++----- apps/sim/executor/handlers/router/router-handler.ts | 10 +++------- packages/testing/src/mocks/executor.mock.ts | 13 +++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/sim/executor/handlers/evaluator/evaluator-handler.ts b/apps/sim/executor/handlers/evaluator/evaluator-handler.ts index 9cc03cb39..b383bdce0 100644 --- a/apps/sim/executor/handlers/evaluator/evaluator-handler.ts +++ b/apps/sim/executor/handlers/evaluator/evaluator-handler.ts @@ -4,9 +4,9 @@ import { createLogger } from '@sim/logger' import { eq } from 'drizzle-orm' import { refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils' import type { BlockOutput } from '@/blocks/types' -import { BlockType, DEFAULTS, EVALUATOR, HTTP } from '@/executor/constants' +import { BlockType, DEFAULTS, EVALUATOR } from '@/executor/constants' import type { BlockHandler, ExecutionContext } from '@/executor/types' -import { buildAPIUrl, extractAPIErrorMessage } from '@/executor/utils/http' +import { buildAPIUrl, buildAuthHeaders, extractAPIErrorMessage } from '@/executor/utils/http' import { isJSONString, parseJSON, stringifyJSON } from '@/executor/utils/json' import { validateModelProvider } from '@/executor/utils/permission-check' import { calculateCost, getProviderFromModel } from '@/providers/utils' @@ -143,9 +143,7 @@ export class EvaluatorBlockHandler implements BlockHandler { const response = await fetch(url.toString(), { method: 'POST', - headers: { - 'Content-Type': HTTP.CONTENT_TYPE.JSON, - }, + headers: await buildAuthHeaders(), body: stringifyJSON(providerRequest), }) diff --git a/apps/sim/executor/handlers/router/router-handler.ts b/apps/sim/executor/handlers/router/router-handler.ts index eb5cf85ae..12acf6c4c 100644 --- a/apps/sim/executor/handlers/router/router-handler.ts +++ b/apps/sim/executor/handlers/router/router-handler.ts @@ -9,12 +9,12 @@ import type { BlockOutput } from '@/blocks/types' import { BlockType, DEFAULTS, - HTTP, isAgentBlockType, isRouterV2BlockType, ROUTER, } from '@/executor/constants' import type { BlockHandler, ExecutionContext } from '@/executor/types' +import { buildAuthHeaders } from '@/executor/utils/http' import { validateModelProvider } from '@/executor/utils/permission-check' import { calculateCost, getProviderFromModel } from '@/providers/utils' import type { SerializedBlock } from '@/serializer/types' @@ -118,9 +118,7 @@ export class RouterBlockHandler implements BlockHandler { const response = await fetch(url.toString(), { method: 'POST', - headers: { - 'Content-Type': HTTP.CONTENT_TYPE.JSON, - }, + headers: await buildAuthHeaders(), body: JSON.stringify(providerRequest), }) @@ -277,9 +275,7 @@ export class RouterBlockHandler implements BlockHandler { const response = await fetch(url.toString(), { method: 'POST', - headers: { - 'Content-Type': HTTP.CONTENT_TYPE.JSON, - }, + headers: await buildAuthHeaders(), body: JSON.stringify(providerRequest), }) diff --git a/packages/testing/src/mocks/executor.mock.ts b/packages/testing/src/mocks/executor.mock.ts index 8256a9e97..8698c258b 100644 --- a/packages/testing/src/mocks/executor.mock.ts +++ b/packages/testing/src/mocks/executor.mock.ts @@ -71,6 +71,19 @@ vi.mock('@/executor/path') vi.mock('@/executor/resolver', () => ({ InputResolver: vi.fn(), })) +vi.mock('@/executor/utils/http', () => ({ + buildAuthHeaders: vi.fn().mockResolvedValue({ 'Content-Type': 'application/json' }), + buildAPIUrl: vi.fn((path: string) => new URL(path, 'http://localhost:3000')), + extractAPIErrorMessage: vi.fn(async (response: Response) => { + const defaultMessage = `API request failed with status ${response.status}` + try { + const errorData = await response.json() + return errorData.error || defaultMessage + } catch { + return defaultMessage + } + }), +})) // Specific block utilities vi.mock('@/blocks/blocks/router')