mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix(vscode-lm): order text parts before tool calls in assistant messages (#10573)
This commit is contained in:
parent
2ff08b5e5c
commit
ade10e275f
2 changed files with 15 additions and 12 deletions
|
|
@ -143,9 +143,11 @@ describe("convertToVsCodeLmMessages", () => {
|
|||
expect(result).toHaveLength(1)
|
||||
expect(result[0].role).toBe("assistant")
|
||||
expect(result[0].content).toHaveLength(2)
|
||||
const [toolCall, textContent] = result[0].content as [MockLanguageModelToolCallPart, MockLanguageModelTextPart]
|
||||
expect(toolCall.type).toBe("tool_call")
|
||||
// Text must come before tool calls so that tool calls are at the end,
|
||||
// properly followed by user message with tool results
|
||||
const [textContent, toolCall] = result[0].content as [MockLanguageModelTextPart, MockLanguageModelToolCallPart]
|
||||
expect(textContent.type).toBe("text")
|
||||
expect(toolCall.type).toBe("tool_call")
|
||||
})
|
||||
|
||||
it("should handle image blocks with appropriate placeholders", () => {
|
||||
|
|
|
|||
|
|
@ -114,9 +114,18 @@ export function convertToVsCodeLmMessages(
|
|||
{ nonToolMessages: [], toolMessages: [] },
|
||||
)
|
||||
|
||||
// Process tool messages first then non-tool messages
|
||||
// Process non-tool messages first, then tool messages
|
||||
// Tool calls must come at the end so they are properly followed by user message with tool results
|
||||
const contentParts = [
|
||||
// Convert tool messages to ToolCallParts first
|
||||
// Convert non-tool messages to TextParts first
|
||||
...nonToolMessages.map((part) => {
|
||||
if (part.type === "image") {
|
||||
return new vscode.LanguageModelTextPart("[Image generation not supported by VSCode LM API]")
|
||||
}
|
||||
return new vscode.LanguageModelTextPart(part.text)
|
||||
}),
|
||||
|
||||
// Convert tool messages to ToolCallParts after text
|
||||
...toolMessages.map(
|
||||
(toolMessage) =>
|
||||
new vscode.LanguageModelToolCallPart(
|
||||
|
|
@ -125,14 +134,6 @@ export function convertToVsCodeLmMessages(
|
|||
asObjectSafe(toolMessage.input),
|
||||
),
|
||||
),
|
||||
|
||||
// Convert non-tool messages to TextParts after tool messages
|
||||
...nonToolMessages.map((part) => {
|
||||
if (part.type === "image") {
|
||||
return new vscode.LanguageModelTextPart("[Image generation not supported by VSCode LM API]")
|
||||
}
|
||||
return new vscode.LanguageModelTextPart(part.text)
|
||||
}),
|
||||
]
|
||||
|
||||
// Add the assistant message to the list of messages
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue