Skip to content

Commit 807c414

Browse files
committed
Remove unnecessary transformToolParams function
Tool definitions already comply with OpenAI Structured Outputs spec: - All tools already have strict: true - All tools already have additionalProperties: false - All properties are already in required arrays - Optional properties already use union types with null The transformation adds unnecessary complexity and potential bugs without providing any benefit.
1 parent 230592f commit 807c414

File tree

1 file changed

+2
-53
lines changed

1 file changed

+2
-53
lines changed

src/api/providers/openai-native.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -190,57 +190,6 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
190190
reasoningEffort: ReasoningEffortExtended | undefined,
191191
metadata?: ApiHandlerCreateMessageMetadata,
192192
): any {
193-
// Helper to transform tool definitions to be compatible with OpenAI Structured Outputs (strict: true)
194-
// This ensures all properties are required (with nullable types if needed) and additionalProperties: false
195-
const transformToolParams = (params: any): any => {
196-
if (!params || typeof params !== "object" || params.type !== "object") {
197-
return params
198-
}
199-
200-
const newParams = { ...params }
201-
newParams.additionalProperties = false
202-
newParams.required = [...(newParams.required || [])]
203-
204-
if (newParams.properties) {
205-
const newProps = { ...newParams.properties }
206-
207-
for (const key of Object.keys(newProps)) {
208-
// Recursively transform nested objects
209-
if (newProps[key].type === "object") {
210-
newProps[key] = transformToolParams(newProps[key])
211-
} else if (newProps[key].type === "array" && newProps[key].items) {
212-
if (newProps[key].items.type === "object") {
213-
newProps[key] = {
214-
...newProps[key],
215-
items: transformToolParams(newProps[key].items),
216-
}
217-
}
218-
}
219-
220-
// Ensure property is in required list for strict mode
221-
if (!newParams.required.includes(key)) {
222-
newParams.required.push(key)
223-
224-
// Make optional properties nullable
225-
const prop = newProps[key]
226-
if (prop.type) {
227-
if (Array.isArray(prop.type)) {
228-
if (!prop.type.includes("null")) {
229-
newProps[key] = { ...prop, type: [...prop.type, "null"] }
230-
}
231-
} else if (prop.type !== "null") {
232-
newProps[key] = { ...prop, type: [prop.type, "null"] }
233-
}
234-
} else if (prop.anyOf || prop.oneOf) {
235-
// Handle complex types if necessary, but keeping simple for now
236-
}
237-
}
238-
}
239-
newParams.properties = newProps
240-
}
241-
return newParams
242-
}
243-
244193
// Build a request body for the OpenAI Responses API.
245194
// Ensure we explicitly pass max_output_tokens based on Roo's reserved model response calculation
246195
// so requests do not default to very large limits (e.g., 120k).
@@ -317,8 +266,8 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
317266
type: "function",
318267
name: tool.function.name,
319268
description: tool.function.description,
320-
parameters: transformToolParams(tool.function.parameters),
321-
strict: true, // Now safe to enforce strict mode
269+
parameters: tool.function.parameters,
270+
strict: true,
322271
})),
323272
}),
324273
...(metadata?.tool_choice && { tool_choice: metadata.tool_choice }),

0 commit comments

Comments
 (0)