fix: normalize tool schemas for VS Code LM API to fix error 400 (#10221)

This commit is contained in:
Hannes Rudolph 2025-12-19 17:36:59 -07:00 • committed by GitHub
parent f7adc4b1cf
commit 5c798a9877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -336,6 +336,7 @@ describe("VsCodeLmHandler", () => {
}
// Verify sendRequest was called with tools in options
// Note: normalizeToolSchema adds additionalProperties: false for JSON Schema 2020-12 compliance
expect(mockLanguageModelChat.sendRequest).toHaveBeenCalledWith(
expect.any(Array),
expect.objectContaining({
@ -348,6 +349,7 @@ describe("VsCodeLmHandler", () => {
properties: {
operation: { type: "string" },
},
additionalProperties: false,
},
},
],

View file

@ -6,6 +6,7 @@ import { type ModelInfo, openAiModelInfoSaneDefaults } from "@roo-code/types"
import type { ApiHandlerOptions } from "../../shared/api"
import { SELECTOR_SEPARATOR, stringifyVsCodeLmModelSelector } from "../../shared/vsCodeSelectorUtils"
import { normalizeToolSchema } from "../../utils/json-schema"
import { ApiStream } from "../transform/stream"
import { convertToVsCodeLmMessages, extractTextCountFromMessage } from "../transform/vscode-lm-format"
@ -15,6 +16,8 @@ import type { SingleCompletionHandler, ApiHandlerCreateMessageMetadata } from ".
/**
* Converts OpenAI-format tools to VSCode Language Model tools.
* Normalizes the JSON Schema to draft 2020-12 compliant format required by
* GitHub Copilot's backend, converting type: ["T", "null"] to anyOf format.
* @param tools Array of OpenAI ChatCompletionTool definitions
* @returns Array of VSCode LanguageModelChatTool definitions
*/
@ -24,7 +27,9 @@ function convertToVsCodeLmTools(tools: OpenAI.Chat.ChatCompletionTool[]): vscode
.map((tool) => ({
name: tool.function.name,
description: tool.function.description || "",
inputSchema: tool.function.parameters as Record<string, unknown> | undefined,
inputSchema: tool.function.parameters
? normalizeToolSchema(tool.function.parameters as Record<string, unknown>)
: undefined,
}))
}