mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-06 02:47:56 +00:00
fix: normalize tool schemas for VS Code LM API to fix error 400 (#10221)
This commit is contained in:
parent
f7adc4b1cf
commit
5c798a9877
2 changed files with 8 additions and 1 deletions
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue