mirror of
https://github.com/cline/cline.git
synced 2025-06-03 03:59:07 +00:00
Fix openrouter message transform for resuming tasks
This commit is contained in:
parent
5f2b66383c
commit
fdcec81814
@ -2,7 +2,7 @@
|
|||||||
"name": "claude-dev",
|
"name": "claude-dev",
|
||||||
"displayName": "Claude Dev",
|
"displayName": "Claude Dev",
|
||||||
"description": "Autonomous coding agent right in your IDE, capable of creating/editing files, executing commands, and more with your permission every step of the way.",
|
"description": "Autonomous coding agent right in your IDE, capable of creating/editing files, executing commands, and more with your permission every step of the way.",
|
||||||
"version": "1.5.11",
|
"version": "1.5.12",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.84.0"
|
"vscode": "^1.84.0"
|
||||||
|
@ -34,23 +34,7 @@ export function convertToOpenAiMessages(
|
|||||||
{ nonToolMessages: [], toolMessages: [] }
|
{ nonToolMessages: [], toolMessages: [] }
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process non-tool messages
|
// Process tool result messages FIRST since they must follow the tool use messages
|
||||||
if (nonToolMessages.length > 0) {
|
|
||||||
openAiMessages.push({
|
|
||||||
role: "user",
|
|
||||||
content: nonToolMessages.map((part) => {
|
|
||||||
if (part.type === "image") {
|
|
||||||
return {
|
|
||||||
type: "image_url",
|
|
||||||
image_url: { url: `data:${part.source.media_type};base64,${part.source.data}` },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { type: "text", text: part.text }
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process tool result messages
|
|
||||||
let toolResultImages: Anthropic.Messages.ImageBlockParam[] = []
|
let toolResultImages: Anthropic.Messages.ImageBlockParam[] = []
|
||||||
toolMessages.forEach((toolMessage) => {
|
toolMessages.forEach((toolMessage) => {
|
||||||
// The Anthropic SDK allows tool results to be a string or an array of text and image blocks, enabling rich and structured content. In contrast, the OpenAI SDK only supports tool results as a single string, so we map the Anthropic tool result parts into one concatenated string to maintain compatibility.
|
// The Anthropic SDK allows tool results to be a string or an array of text and image blocks, enabling rich and structured content. In contrast, the OpenAI SDK only supports tool results as a single string, so we map the Anthropic tool result parts into one concatenated string to maintain compatibility.
|
||||||
@ -90,6 +74,22 @@ export function convertToOpenAiMessages(
|
|||||||
})),
|
})),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process non-tool messages
|
||||||
|
if (nonToolMessages.length > 0) {
|
||||||
|
openAiMessages.push({
|
||||||
|
role: "user",
|
||||||
|
content: nonToolMessages.map((part) => {
|
||||||
|
if (part.type === "image") {
|
||||||
|
return {
|
||||||
|
type: "image_url",
|
||||||
|
image_url: { url: `data:${part.source.media_type};base64,${part.source.data}` },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { type: "text", text: part.text }
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (anthropicMessage.role === "assistant") {
|
} else if (anthropicMessage.role === "assistant") {
|
||||||
const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce<{
|
const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce<{
|
||||||
nonToolMessages: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[]
|
nonToolMessages: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[]
|
||||||
@ -106,7 +106,7 @@ export function convertToOpenAiMessages(
|
|||||||
{ nonToolMessages: [], toolMessages: [] }
|
{ nonToolMessages: [], toolMessages: [] }
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process non-tool messages
|
// Process non-tool messages FIRST
|
||||||
let content: string | undefined
|
let content: string | undefined
|
||||||
if (nonToolMessages.length > 0) {
|
if (nonToolMessages.length > 0) {
|
||||||
content = nonToolMessages
|
content = nonToolMessages
|
||||||
|
Loading…
Reference in New Issue
Block a user