diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 0fb7ad22..8e27d714 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -671,15 +671,31 @@ export namespace SessionPrompt { result, ) - const output = result.content - .filter((x: any) => x.type === "text") - .map((x: any) => x.text) - .join("\n\n") + const textParts: string[] = [] + const attachments: MessageV2.FilePart[] = [] + + for (const item of result.content) { + if (item.type === "text") { + textParts.push(item.text) + } else if (item.type === "image") { + attachments.push({ + id: Identifier.ascending("part"), + sessionID: input.sessionID, + messageID: input.processor.message.id, + type: "file", + mime: item.mimeType, + url: `data:${item.mimeType};base64,${item.data}`, + }) + } + // Add support for other types if needed + } return { title: "", metadata: result.metadata ?? {}, - output, + output: textParts.join("\n\n"), + attachments, + content: result.content, // directly return content to preserve ordering when outputting to model } } item.toModelOutput = (result) => {