Skip to content

Commit 8bd5d41

Browse files
authored
v0.5.70: router fix, anthropic agent response format adherence
2 parents c12931b + ac91d78 commit 8bd5d41

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
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

apps/sim/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"@a2a-js/sdk": "0.3.7",
27-
"@anthropic-ai/sdk": "^0.39.0",
27+
"@anthropic-ai/sdk": "0.71.2",
2828
"@aws-sdk/client-bedrock-runtime": "3.940.0",
2929
"@aws-sdk/client-dynamodb": "3.940.0",
3030
"@aws-sdk/client-rds-data": "3.940.0",

apps/sim/providers/anthropic/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Anthropic from '@anthropic-ai/sdk'
2+
import { transformJSONSchema } from '@anthropic-ai/sdk/lib/transform-json-schema'
23
import { createLogger } from '@sim/logger'
34
import type { StreamingExecution } from '@/executor/types'
45
import { MAX_TOOL_ITERATIONS } from '@/providers'
@@ -185,13 +186,10 @@ export const anthropicProvider: ProviderConfig = {
185186
const schema = request.responseFormat.schema || request.responseFormat
186187

187188
if (useNativeStructuredOutputs) {
188-
const schemaWithConstraints = {
189-
...schema,
190-
additionalProperties: false,
191-
}
189+
const transformedSchema = transformJSONSchema(schema)
192190
payload.output_format = {
193191
type: 'json_schema',
194-
schema: schemaWithConstraints,
192+
schema: transformedSchema,
195193
}
196194
logger.info(`Using native structured outputs for model: ${modelId}`)
197195
} else {

bun.lock

Lines changed: 22 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)