Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/sim/providers/openai/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { describe, expect, it } from 'vitest'
import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
import {
buildResponsesInputFromMessages,
convertToolsToResponses,
parseResponsesUsage,
toOpenAIModelUsage,
} from '@/providers/openai/utils'
Expand Down Expand Up @@ -155,3 +156,28 @@ describe('buildResponsesInputFromMessages', () => {
])
})
})

describe('convertToolsToResponses', () => {
it.each(['wrapped', 'flat'] as const)(
'preserves optional inputs on %s tool definitions without implicit strict normalization',
(shape) => {
const parameters = {
type: 'object',
properties: {
fileId: { type: 'string' },
folderPaths: { type: 'array', items: { type: 'string' } },
offset: { type: 'number' },
},
required: ['fileId'],
}
const tool = { name: 'file_get_content', description: 'Read selected file text', parameters }
const converted = convertToolsToResponses([
shape === 'wrapped' ? { type: 'function', function: tool } : tool,
])

expect(converted).toEqual([{ type: 'function', strict: false, ...tool }])
expect(converted[0].parameters).toBe(parameters)
expect(parameters.required).toEqual(['fileId'])
}
)
})
5 changes: 4 additions & 1 deletion apps/sim/providers/openai/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export async function* iterateResponsesStreamEvents(

export interface ResponsesToolDefinition {
type: 'function'
strict: false
name: string
description?: string
parameters?: Record<string, unknown>
Expand Down Expand Up @@ -200,7 +201,8 @@ export function buildResponsesInputFromMessages(
}

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

return {
type: 'function' as const,
strict: false as const,
name,
description: tool.function?.description ?? tool.description,
parameters: tool.function?.parameters ?? tool.parameters,
Expand Down
Loading