Problem/Context
When opening image files in the desktop file viewer tabs, the raw base64 string is displayed as text in the code viewer instead of rendering the actual image. The API already returns image files with base64 encoding and proper mime types, but the file viewer doesn't handle this case.
Currently in packages/desktop/src/pages/session.tsx:814-827, all file content is passed directly to the code syntax highlighter:
<Match when={file()}>
{(f) => (
<Dynamic
component={codeComponent}
file={{
name: f().path,
contents: f().content?.content ?? "",
cacheKey: checksum(f().content?.content ?? ""),
}}
overflow="scroll"
class="pb-40"
/>
)}
</Match>
The FileContent type already includes the necessary fields for image detection:
encoding?: "base64" - present when file is binary
mimeType?: string - contains the MIME type (e.g., image/png)
Acceptance Criteria
Implementation Details
Technical Approach
-
Add a conditional check before rendering file content:
- Check if
f().content?.encoding === "base64"
- Check if
f().content?.mimeType?.startsWith("image/")
-
For images, render an <img> element with a data URL:
<img
src={`data:${f().content?.mimeType};base64,${f().content?.content}`}
alt={f().path}
/>
-
Add appropriate styling for image container (centering, max dimensions, overflow scroll)
Code References
| File |
Purpose |
packages/desktop/src/pages/session.tsx:800-832 |
File viewer tabs - where change is needed |
packages/opencode/src/file/index.ts:235-273 |
Backend file reading - shows base64 encoding logic |
packages/sdk/js/src/v2/gen/types.gen.ts:1846-1866 |
FileContent type definition with encoding and mimeType |
packages/ui/src/components/message-part.tsx:127-161 |
Existing image rendering pattern for attachments |
packages/desktop/src/components/prompt-input.tsx |
Image attachment handling (accepted types) |
Reference Implementation
The codebase already handles image rendering in message attachments (packages/ui/src/components/message-part.tsx):
<Show when={file.mime.startsWith("image/") && file.url}>
<img data-slot="user-message-attachment-image" src={file.url} alt={file.filename ?? "attachment"} />
</Show>
A similar pattern using data URLs for base64 images:
// Standard pattern for rendering base64 images
<img src={`data:${mimeType};base64,${base64Content}`} />
Tasks
Problem/Context
When opening image files in the desktop file viewer tabs, the raw base64 string is displayed as text in the code viewer instead of rendering the actual image. The API already returns image files with base64 encoding and proper mime types, but the file viewer doesn't handle this case.
Currently in
packages/desktop/src/pages/session.tsx:814-827, all file content is passed directly to the code syntax highlighter:The
FileContenttype already includes the necessary fields for image detection:encoding?: "base64"- present when file is binarymimeType?: string- contains the MIME type (e.g.,image/png)Acceptance Criteria
Implementation Details
Technical Approach
Add a conditional check before rendering file content:
f().content?.encoding === "base64"f().content?.mimeType?.startsWith("image/")For images, render an
<img>element with a data URL:Add appropriate styling for image container (centering, max dimensions, overflow scroll)
Code References
packages/desktop/src/pages/session.tsx:800-832packages/opencode/src/file/index.ts:235-273packages/sdk/js/src/v2/gen/types.gen.ts:1846-1866FileContenttype definition withencodingandmimeTypepackages/ui/src/components/message-part.tsx:127-161packages/desktop/src/components/prompt-input.tsxReference Implementation
The codebase already handles image rendering in message attachments (
packages/ui/src/components/message-part.tsx):A similar pattern using data URLs for base64 images:
Tasks
encoding === "base64"andmimeType.startsWith("image/"))