Răsfoiți Sursa

Fix openrouter message transform for resuming tasks

Saoud Rizwan 1 an în urmă
părinte
comite
fdcec81814
2 a modificat fișierele cu 19 adăugiri și 19 ștergeri
  1. 1 1
      package.json
  2. 18 18
      src/utils/openai-format.ts

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
   "name": "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.",
-  "version": "1.5.11",
+  "version": "1.5.12",
   "icon": "icon.png",
   "engines": {
     "vscode": "^1.84.0"

+ 18 - 18
src/utils/openai-format.ts

@@ -34,23 +34,7 @@ export function convertToOpenAiMessages(
 					{ nonToolMessages: [], toolMessages: [] }
 				)
 
-				// 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 }
-						}),
-					})
-				}
-
-				// Process tool result messages
+				// Process tool result messages FIRST since they must follow the tool use messages
 				let toolResultImages: Anthropic.Messages.ImageBlockParam[] = []
 				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.
@@ -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") {
 				const { nonToolMessages, toolMessages } = anthropicMessage.content.reduce<{
 					nonToolMessages: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[]
@@ -106,7 +106,7 @@ export function convertToOpenAiMessages(
 					{ nonToolMessages: [], toolMessages: [] }
 				)
 
-				// Process non-tool messages
+				// Process non-tool messages FIRST
 				let content: string | undefined
 				if (nonToolMessages.length > 0) {
 					content = nonToolMessages