Aiden Cline 3 mesi fa
parent
commit
5385995398

+ 3 - 1
packages/opencode/src/session/message-v2.ts

@@ -515,8 +515,10 @@ export namespace MessageV2 {
                 state: "output-available",
                 toolCallId: part.callID,
                 input: part.state.input,
+                // For compacted results, use plain string so SDK serializes as text type
+                // For normal results, pass object so toModelOutput can convert attachments to media parts
                 output: part.state.time.compacted
-                  ? { output: "[Old tool result content cleared]", attachments: undefined }
+                  ? "[Old tool result content cleared]"
                   : { output: part.state.output, attachments: part.state.attachments },
                 callProviderMetadata: part.metadata,
               })

+ 6 - 2
packages/opencode/src/session/prompt.ts

@@ -716,7 +716,9 @@ export namespace SessionPrompt {
           )
           return result
         },
-        toModelOutput(result: { output: string; attachments?: MessageV2.FilePart[] }) {
+        toModelOutput(result: string | { output: string; attachments?: MessageV2.FilePart[] }) {
+          // Handle compacted results (plain string)
+          if (typeof result === "string") return { type: "text", value: result }
           if (!result.attachments?.length) return { type: "text", value: result.output }
           return {
             type: "content",
@@ -814,7 +816,9 @@ export namespace SessionPrompt {
           content: result.content, // directly return content to preserve ordering when outputting to model
         }
       }
-      item.toModelOutput = (result: { output: string; attachments?: MessageV2.FilePart[] }) => {
+      item.toModelOutput = (result: string | { output: string; attachments?: MessageV2.FilePart[] }) => {
+        // Handle compacted results (plain string)
+        if (typeof result === "string") return { type: "text", value: result }
         if (!result.attachments?.length) return { type: "text", value: result.output }
         return {
           type: "content",