Skip to content

Commit 1db2a00

Browse files
fix(openai): preserve optional Responses tool inputs (#7953)
1 parent 0853431 commit 1db2a00

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎apps/sim/providers/openai/utils.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { describe, expect, it } from 'vitest'
66
import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
77
import {
88
buildResponsesInputFromMessages,
9+
convertToolsToResponses,
910
parseResponsesUsage,
1011
toOpenAIModelUsage,
1112
} from '@/providers/openai/utils'
@@ -155,3 +156,28 @@ describe('buildResponsesInputFromMessages', () => {
155156
])
156157
})
157158
})
159+
160+
describe('convertToolsToResponses', () => {
161+
it.each(['wrapped', 'flat'] as const)(
162+
'preserves optional inputs on %s tool definitions without implicit strict normalization',
163+
(shape) => {
164+
const parameters = {
165+
type: 'object',
166+
properties: {
167+
fileId: { type: 'string' },
168+
folderPaths: { type: 'array', items: { type: 'string' } },
169+
offset: { type: 'number' },
170+
},
171+
required: ['fileId'],
172+
}
173+
const tool = { name: 'file_get_content', description: 'Read selected file text', parameters }
174+
const converted = convertToolsToResponses([
175+
shape === 'wrapped' ? { type: 'function', function: tool } : tool,
176+
])
177+
178+
expect(converted).toEqual([{ type: 'function', strict: false, ...tool }])
179+
expect(converted[0].parameters).toBe(parameters)
180+
expect(parameters.required).toEqual(['fileId'])
181+
}
182+
)
183+
})

‎apps/sim/providers/openai/utils.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export async function* iterateResponsesStreamEvents(
140140

141141
export interface ResponsesToolDefinition {
142142
type: 'function'
143+
strict: false
143144
name: string
144145
description?: string
145146
parameters?: Record<string, unknown>
@@ -200,7 +201,8 @@ export function buildResponsesInputFromMessages(
200201
}
201202

202203
/**
203-
* Converts tool definitions to the Responses API format.
204+
* Converts tool definitions without changing their required and optional inputs.
205+
* Responses otherwise attempts strict normalization, which can require optional fields.
204206
*/
205207
export function convertToolsToResponses(
206208
tools: Array<{
@@ -220,6 +222,7 @@ export function convertToolsToResponses(
220222

221223
return {
222224
type: 'function' as const,
225+
strict: false as const,
223226
name,
224227
description: tool.function?.description ?? tool.description,
225228
parameters: tool.function?.parameters ?? tool.parameters,

0 commit comments

Comments
 (0)