Skip to content

Commit 6f0a093

Browse files
authored
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
1 parent bcf6dc8 commit 6f0a093

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

apps/sim/executor/handlers/evaluator/evaluator-handler.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { createLogger } from '@sim/logger'
44
import { eq } from 'drizzle-orm'
55
import { refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils'
66
import type { BlockOutput } from '@/blocks/types'
7-
import { BlockType, DEFAULTS, EVALUATOR, HTTP } from '@/executor/constants'
7+
import { BlockType, DEFAULTS, EVALUATOR } from '@/executor/constants'
88
import type { BlockHandler, ExecutionContext } from '@/executor/types'
9-
import { buildAPIUrl, extractAPIErrorMessage } from '@/executor/utils/http'
9+
import { buildAPIUrl, buildAuthHeaders, extractAPIErrorMessage } from '@/executor/utils/http'
1010
import { isJSONString, parseJSON, stringifyJSON } from '@/executor/utils/json'
1111
import { validateModelProvider } from '@/executor/utils/permission-check'
1212
import { calculateCost, getProviderFromModel } from '@/providers/utils'
@@ -143,9 +143,7 @@ export class EvaluatorBlockHandler implements BlockHandler {
143143

144144
const response = await fetch(url.toString(), {
145145
method: 'POST',
146-
headers: {
147-
'Content-Type': HTTP.CONTENT_TYPE.JSON,
148-
},
146+
headers: await buildAuthHeaders(),
149147
body: stringifyJSON(providerRequest),
150148
})
151149

apps/sim/executor/handlers/router/router-handler.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import type { BlockOutput } from '@/blocks/types'
99
import {
1010
BlockType,
1111
DEFAULTS,
12-
HTTP,
1312
isAgentBlockType,
1413
isRouterV2BlockType,
1514
ROUTER,
1615
} from '@/executor/constants'
1716
import type { BlockHandler, ExecutionContext } from '@/executor/types'
17+
import { buildAuthHeaders } from '@/executor/utils/http'
1818
import { validateModelProvider } from '@/executor/utils/permission-check'
1919
import { calculateCost, getProviderFromModel } from '@/providers/utils'
2020
import type { SerializedBlock } from '@/serializer/types'
@@ -118,9 +118,7 @@ export class RouterBlockHandler implements BlockHandler {
118118

119119
const response = await fetch(url.toString(), {
120120
method: 'POST',
121-
headers: {
122-
'Content-Type': HTTP.CONTENT_TYPE.JSON,
123-
},
121+
headers: await buildAuthHeaders(),
124122
body: JSON.stringify(providerRequest),
125123
})
126124

@@ -277,9 +275,7 @@ export class RouterBlockHandler implements BlockHandler {
277275

278276
const response = await fetch(url.toString(), {
279277
method: 'POST',
280-
headers: {
281-
'Content-Type': HTTP.CONTENT_TYPE.JSON,
282-
},
278+
headers: await buildAuthHeaders(),
283279
body: JSON.stringify(providerRequest),
284280
})
285281

packages/testing/src/mocks/executor.mock.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ vi.mock('@/executor/path')
7171
vi.mock('@/executor/resolver', () => ({
7272
InputResolver: vi.fn(),
7373
}))
74+
vi.mock('@/executor/utils/http', () => ({
75+
buildAuthHeaders: vi.fn().mockResolvedValue({ 'Content-Type': 'application/json' }),
76+
buildAPIUrl: vi.fn((path: string) => new URL(path, 'http://localhost:3000')),
77+
extractAPIErrorMessage: vi.fn(async (response: Response) => {
78+
const defaultMessage = `API request failed with status ${response.status}`
79+
try {
80+
const errorData = await response.json()
81+
return errorData.error || defaultMessage
82+
} catch {
83+
return defaultMessage
84+
}
85+
}),
86+
}))
7487

7588
// Specific block utilities
7689
vi.mock('@/blocks/blocks/router')

0 commit comments

Comments
 (0)