Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(gfs): render a 1 MB-capped row thumbnail for image files
Miguelon Peluchon42825f516b4f
diff --git a/control-ui/app/constants/gfsFileThumbnail.ts b/control-ui/app/constants/gfsFileThumbnail.tsnew file mode 100644index 000000000..1d339a6df--- /dev/null+++ b/control-ui/app/constants/gfsFileThumbnail.ts@@ -0,0 +1 @@+export const GFS_FILE_THUMBNAIL_MAX_BYTES = 1 * 1024 * 1024diff --git a/control-ui/app/globals.css b/control-ui/app/globals.cssindex 87f1ebffa..a18d23115 100644--- a/control-ui/app/globals.css+++ b/control-ui/app/globals.css@@ -11524,6 +11524,16 @@ button.cu-gfs-tree__button:focus-visible,display: grid;place-items: center;color: var(--cu-text-muted);+ overflow: hidden;+ border-radius: var(--cu-radius-sm);+}++.cu-gfs-file-thumbnail {+ width: 100%;+ height: 100%;+ display: block;+ object-fit: cover;+ border-radius: var(--cu-radius-sm);}.cu-gfs-list__meta {diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsxindex 14fcad116..44bb8248f 100644--- a/control-ui/components/GfsBrowser.tsx+++ b/control-ui/components/GfsBrowser.tsx@@ -2,6 +2,7 @@import React, { useCallback, useEffect, useRef, useState } from 'react'import { FileUploadModal } from '@components/FileUploadModal'+import { GfsFileThumbnail } from '@components/GfsFileThumbnail'import { GfsImagePreview } from '@components/GfsImagePreview'import { GfsMarkdownPreview } from '@components/GfsMarkdownPreview'import { GfsVideoPreview } from '@components/GfsVideoPreview'@@ -643,7 +644,11 @@ export function GfsBrowser(): React.JSX.Element {{child.kind === 'directory' ? (<IconFolder />) : gfsImagePreviewMimeType(child.name) ? (- <IconImage />+ <GfsFileThumbnail+ byteLength={child.bytes}+ fileName={child.name}+ rid={child.rid}+ />) : isGfsVideoFile(child.name) ? (<IconVideo />) : isGfsDocumentFile(child.name) ? (diff --git a/control-ui/components/GfsFileThumbnail/index.tsx b/control-ui/components/GfsFileThumbnail/index.tsxnew file mode 100644index 000000000..bc582e3f2--- /dev/null+++ b/control-ui/components/GfsFileThumbnail/index.tsx@@ -0,0 +1,70 @@+'use client'++import { useEffect, useState } from 'react'+import { IconImage } from '@components/Sidebar/icons'+import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'+import { gfsFetchFileBlob } from '@lib/api'+import type { GfsFileThumbnailProps } from './types'++/**+ * Tiny row-level thumbnail. Pulls the image blob through the existing+ * GFS proxy path, builds an object URL, and renders it inside the+ * row's existing 1.5rem icon slot. Falls back to the inline image+ * glyph when the row is over-budget or the blob fetch/load fails.+ */+export function GfsFileThumbnail({+ byteLength,+ fileName,+ rid,+}: GfsFileThumbnailProps): React.JSX.Element {+ const shouldSkip = byteLength > GFS_FILE_THUMBNAIL_MAX_BYTES+ const [src, setSrc] = useState<string | null>(null)+ const [failed, setFailed] = useState(shouldSkip)++ useEffect(() => {+ if (shouldSkip) {+ setFailed(true)+ setSrc(null)+ return+ }+ let cancelled = false+ let objectUrl: string | null = null++ async function load(): Promise<void> {+ try {+ const blob = await gfsFetchFileBlob(rid)+ if (cancelled) return+ if (blob.size > GFS_FILE_THUMBNAIL_MAX_BYTES) {+ setFailed(true)+ return+ }+ objectUrl = URL.createObjectURL(blob)+ setSrc(objectUrl)+ } catch {+ if (!cancelled) setFailed(true)+ }+ }++ void load()+ return () => {+ cancelled = true+ if (objectUrl) URL.revokeObjectURL(objectUrl)+ }+ }, [rid, shouldSkip])++ if (failed || !src) {+ return <IconImage />+ }++ return (+ <img+ alt={`Thumbnail of ${fileName}`}+ className="cu-gfs-file-thumbnail"+ decoding="async"+ loading="lazy"+ src={src}+ />+ )+}++export type { GfsFileThumbnailProps } from './types'diff --git a/control-ui/components/GfsFileThumbnail/types.ts b/control-ui/components/GfsFileThumbnail/types.tsnew file mode 100644index 000000000..c35afb951--- /dev/null+++ b/control-ui/components/GfsFileThumbnail/types.ts@@ -0,0 +1,5 @@+export interface GfsFileThumbnailProps {+ byteLength: number+ fileName: string+ rid: string+}diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsxindex 93b9d46b8..0638291a8 100644--- a/control-ui/components/__tests__/GfsBrowser.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx@@ -541,7 +541,13 @@ describe('GfsBrowser', () => {await within(dialog).findByRole('img', { name: 'Preview of avatar.PNG' })).toHaveAttribute('src', 'blob:gfs-image-preview')expect(mockGfsFetchFileBlob).toHaveBeenCalledWith('r2')- expect((mockCreateObjectUrl.mock.calls[0]?.[0] as Blob).type).toBe('image/png')+ // Preview modal wraps the fetched blob with the original MIME type so+ // the dialog <img> loads as that media type; the row thumbnail uses+ // the raw blob so it appears first in the createObjectURL log.+ const previewCall = mockCreateObjectUrl.mock.calls.find(+ call => (call[0] as Blob).type === 'image/png'+ )+ expect(previewCall?.[0]).toBeDefined()const closeButton = within(dialog).getByRole('button', { name: /close image preview/i })fireEvent.click(closeButton)@@ -563,7 +569,9 @@ describe('GfsBrowser', () => {items: [child('diagram.svg', 'file', 4)],nextCursor: null,})- mockGfsFetchFileBlob.mockRejectedValueOnce(new Error('preview unavailable'))+ // Both the row thumbnail and the preview modal hit gfsFetchFileBlob+ // for the same file; reject both so the preview can show its error.+ mockGfsFetchFileBlob.mockRejectedValue(new Error('preview unavailable'))renderBrowser()fireEvent.click(await screen.findByRole('button', { name: 'diagram.svg' }))diff --git a/control-ui/components/__tests__/GfsFileThumbnail.test.tsx b/control-ui/components/__tests__/GfsFileThumbnail.test.tsxnew file mode 100644index 000000000..22207fbd9--- /dev/null+++ b/control-ui/components/__tests__/GfsFileThumbnail.test.tsx@@ -0,0 +1,78 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { render, screen, waitFor } from '@testing-library/react'+import { GfsFileThumbnail } from '../GfsFileThumbnail'+import { ToastProvider } from '../Toast'++const mockGfsFetchFileBlob = vi.fn()+const mockCreateObjectUrl = vi.fn(() => 'blob:gfs-thumbnail')+const mockRevokeObjectUrl = vi.fn()++vi.mock('@lib/api', () => ({+ gfsFetchFileBlob: (...args: unknown[]) => mockGfsFetchFileBlob(...args),+}))++function renderThumb(props: Parameters<typeof GfsFileThumbnail>[0]) {+ return render(+ <ToastProvider>+ <GfsFileThumbnail {...props} />+ </ToastProvider>+ )+}++describe('GfsFileThumbnail', () => {+ beforeEach(() => {+ mockGfsFetchFileBlob.mockReset()+ mockCreateObjectUrl.mockReset()+ mockCreateObjectUrl.mockReturnValue('blob:gfs-thumbnail')+ mockRevokeObjectUrl.mockReset()+ Object.defineProperty(URL, 'createObjectURL', {+ configurable: true,+ value: mockCreateObjectUrl,+ })+ Object.defineProperty(URL, 'revokeObjectURL', {+ configurable: true,+ value: mockRevokeObjectUrl,+ })+ })++ afterEach(() => {+ vi.restoreAllMocks()+ })++ it('renders the inline image glyph for files larger than the thumbnail budget', () => {+ renderThumb({+ byteLength: 2 * 1024 * 1024,+ fileName: 'big.png',+ rid: 'r-big',+ })+ expect(screen.queryByRole('img')).toBeNull()+ expect(mockGfsFetchFileBlob).not.toHaveBeenCalled()+ })++ it('renders an <img> with the resolved blob URL once the proxy returns the bytes', async () => {+ mockGfsFetchFileBlob.mockResolvedValueOnce(new Blob(['fake-image-bytes']))+ renderThumb({+ byteLength: 64 * 1024,+ fileName: 'logo.png',+ rid: 'r-logo',+ })++ const img = await screen.findByAltText('Thumbnail of logo.png')+ expect(img.tagName).toBe('IMG')+ expect(img).toHaveAttribute('src', 'blob:gfs-thumbnail')+ expect(mockCreateObjectUrl).toHaveBeenCalledTimes(1)+ })++ it('falls back to the image glyph when the proxy fetch rejects', async () => {+ mockGfsFetchFileBlob.mockRejectedValueOnce(new Error('boom'))+ renderThumb({+ byteLength: 64 * 1024,+ fileName: 'logo.png',+ rid: 'r-logo',+ })++ await waitFor(() => expect(mockGfsFetchFileBlob).toHaveBeenCalledTimes(1))+ expect(screen.queryByRole('img')).toBeNull()+ expect(mockCreateObjectUrl).not.toHaveBeenCalled()+ })+})diff --git a/control-ui/lib/gfsFileThumbnail.ts b/control-ui/lib/gfsFileThumbnail.tsnew file mode 100644index 000000000..1d63ce88e--- /dev/null+++ b/control-ui/lib/gfsFileThumbnail.ts@@ -0,0 +1,21 @@+import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'++/**+ * Decide whether a row entry should render a small inline thumbnail+ * (currently image files only, and small enough to fetch cheaply).+ *+ * `bytes` is the metadata-declared size from the GFS listing. We use+ * the metadata size first so we can skip the request entirely when the+ * file is already known to be larger than the thumbnail budget; the+ * resolved blob is re-checked after fetch so oversized files don't+ * sneak through on stale metadata.+ */+export function shouldRenderGfsFileThumbnail(opts: {+ isImage: boolean+ bytes: number+ maxBytes?: number+}): boolean {+ if (!opts.isImage) return false+ const budget = opts.maxBytes ?? GFS_FILE_THUMBNAIL_MAX_BYTES+ return opts.bytes <= budget+}diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex f82798ed4..285ef880b 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.443",+ "version": "0.1.444","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.443",+ "version": "0.1.444","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 930743b63..e63ae6c3c 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.443",+ "version": "0.1.444","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/desktop-app/ui/src/components/GfsFileIcon/index.tsx b/desktop-app/ui/src/components/GfsFileIcon/index.tsxindex 17b4e9bb8..7025dcdd2 100644--- a/desktop-app/ui/src/components/GfsFileIcon/index.tsx+++ b/desktop-app/ui/src/components/GfsFileIcon/index.tsx@@ -1,3 +1,4 @@+import { GfsFileThumbnail } from '@components/GfsFileThumbnail'import {IconAttachFile,IconDocumentText,@@ -11,8 +12,18 @@ import type { GfsFileIconProps } from './types'export type { GfsFileIconProps } from './types'-export function GfsFileIcon({ name, ...iconProps }: GfsFileIconProps) {- if (gfsImagePreviewMimeType(name)) return <IconImage {...iconProps} />+export function GfsFileIcon({ name, bytes, rid, ...iconProps }: GfsFileIconProps) {+ if (gfsImagePreviewMimeType(name)) {+ // Render the inline image thumbnail whenever we have a rid; the+ // component itself decides whether to fetch bytes or short-circuit+ // to the static icon when the file is over the thumbnail budget.+ if (rid !== undefined) {+ return (+ <GfsFileThumbnail byteLength={bytes ?? Number.MAX_SAFE_INTEGER} fileName={name} rid={rid} />+ )+ }+ return <IconImage {...iconProps} />+ }if (isGfsVideoFile(name)) return <IconVideo {...iconProps} />if (isGfsDocumentFile(name)) return <IconDocumentText {...iconProps} />return <IconAttachFile {...iconProps} />diff --git a/desktop-app/ui/src/components/GfsFileIcon/types.ts b/desktop-app/ui/src/components/GfsFileIcon/types.tsindex 0a6e92c7b..2230a59d7 100644--- a/desktop-app/ui/src/components/GfsFileIcon/types.ts+++ b/desktop-app/ui/src/components/GfsFileIcon/types.ts@@ -2,4 +2,20 @@ import type { SVGProps } from 'react'export type GfsFileIconProps = {name: string-} & SVGProps<SVGSVGElement>+} & (+ | {+ /**+ * Provide `bytes` + `rid` to render an inline image thumbnail+ * (still shown as a 24×24 square, just painted with the actual+ * image bytes instead of the image glyph). Missing either field+ * falls back to the static image glyph.+ */+ bytes: number+ rid: string+ }+ | {+ bytes?: never+ rid?: never+ }+) &+ SVGProps<SVGSVGElement>diff --git a/desktop-app/ui/src/components/GfsFileThumbnail/index.tsx b/desktop-app/ui/src/components/GfsFileThumbnail/index.tsxnew file mode 100644index 000000000..cc46a6c68--- /dev/null+++ b/desktop-app/ui/src/components/GfsFileThumbnail/index.tsx@@ -0,0 +1,63 @@+import { useEffect, useState } from 'react'+import { IconImage } from '@components/SidebarNav/icons'+import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'+import type { GfsFileThumbnailProps } from './types'++/**+ * Tiny row-level thumbnail. Pulls the image blob through the existing+ * GFS download path, builds an object URL, and renders it inside the+ * row's existing icon slot. Falls back to the inline image glyph when+ * the row is over-budget or the blob fetch/load fails.+ */+export function GfsFileThumbnail({ byteLength, fileName, rid }: GfsFileThumbnailProps) {+ const shouldSkip = byteLength > GFS_FILE_THUMBNAIL_MAX_BYTES+ const [src, setSrc] = useState<string | null>(null)+ const [failed, setFailed] = useState(shouldSkip)++ useEffect(() => {+ if (shouldSkip) {+ setFailed(true)+ setSrc(null)+ return+ }+ let cancelled = false+ let objectUrl: string | null = null++ const load = async () => {+ try {+ const { bytes } = await window.clerum.gfs.download(rid)+ if (cancelled) return+ if (bytes.byteLength > GFS_FILE_THUMBNAIL_MAX_BYTES) {+ setFailed(true)+ return+ }+ objectUrl = URL.createObjectURL(new Blob([bytes]))+ setSrc(objectUrl)+ } catch {+ if (!cancelled) setFailed(true)+ }+ }++ void load()+ return () => {+ cancelled = true+ if (objectUrl) URL.revokeObjectURL(objectUrl)+ }+ }, [rid, shouldSkip])++ if (failed || !src) {+ return <IconImage />+ }++ return (+ <img+ alt={`Thumbnail of ${fileName}`}+ className="da-gfs-file-thumbnail"+ decoding="async"+ loading="lazy"+ src={src}+ />+ )+}++export type { GfsFileThumbnailProps } from './types'diff --git a/desktop-app/ui/src/components/GfsFileThumbnail/types.ts b/desktop-app/ui/src/components/GfsFileThumbnail/types.tsnew file mode 100644index 000000000..1f6b5fd80--- /dev/null+++ b/desktop-app/ui/src/components/GfsFileThumbnail/types.ts@@ -0,0 +1,5 @@+export type GfsFileThumbnailProps = {+ byteLength: number+ fileName: string+ rid: string+}diff --git a/desktop-app/ui/src/components/__tests__/GfsFileThumbnail.test.tsx b/desktop-app/ui/src/components/__tests__/GfsFileThumbnail.test.tsxnew file mode 100644index 000000000..137ed2b75--- /dev/null+++ b/desktop-app/ui/src/components/__tests__/GfsFileThumbnail.test.tsx@@ -0,0 +1,82 @@+// @vitest-environment jsdom+// @vitest-environment jsdom+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { cleanup, render, screen, waitFor } from '@testing-library/react'+import { GfsFileThumbnail } from '../GfsFileThumbnail'++const mockDownload = vi.fn()+const mockCreateObjectUrl = vi.fn(() => 'blob:gfs-thumbnail')+const mockRevokeObjectUrl = vi.fn()++function renderThumb(props: Parameters<typeof GfsFileThumbnail>[0]) {+ return render(<GfsFileThumbnail {...props} />)+}++describe('GfsFileThumbnail', () => {+ beforeEach(() => {+ mockDownload.mockReset()+ mockCreateObjectUrl.mockReset()+ mockCreateObjectUrl.mockReturnValue('blob:gfs-thumbnail')+ mockRevokeObjectUrl.mockReset()+ Object.defineProperty(URL, 'createObjectURL', {+ configurable: true,+ value: mockCreateObjectUrl,+ })+ Object.defineProperty(URL, 'revokeObjectURL', {+ configurable: true,+ value: mockRevokeObjectUrl,+ })+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: { gfs: { download: mockDownload } },+ })+ })++ afterEach(async () => {+ cleanup()+ await new Promise(resolve => setTimeout(resolve, 0))+ vi.restoreAllMocks()+ })++ it('renders the inline image glyph when the file exceeds the thumbnail budget', () => {+ renderThumb({+ byteLength: 2 * 1024 * 1024,+ fileName: 'big.png',+ rid: 'r-big',+ })+ expect(screen.queryByRole('img')).toBeNull()+ expect(mockDownload).not.toHaveBeenCalled()+ })++ it('renders an <img> with the resolved blob URL once the download returns', async () => {+ mockDownload.mockResolvedValueOnce({ bytes: new Uint8Array([1, 2, 3, 4]).buffer })+ renderThumb({+ byteLength: 64 * 1024,+ fileName: 'logo.png',+ rid: 'r-logo',+ })++ const img = await screen.findByAltText('Thumbnail of logo.png')+ expect(img.tagName).toBe('IMG')+ expect(img.getAttribute('src')).toBe('blob:gfs-thumbnail')+ expect(mockCreateObjectUrl).toHaveBeenCalledTimes(1)+ })++ it('falls back to the image glyph when the download rejects', async () => {+ let rejectDownload: (() => void) | undefined+ const slowDownload = new Promise<{ bytes: ArrayBuffer }>((_, reject) => {+ rejectDownload = () => reject(new Error('boom'))+ })+ mockDownload.mockReturnValueOnce(slowDownload)+ renderThumb({+ byteLength: 64 * 1024,+ fileName: 'logo.png',+ rid: 'r-logo',+ })++ await waitFor(() => expect(mockDownload).toHaveBeenCalledTimes(1))+ rejectDownload?.()+ await waitFor(() => expect(mockCreateObjectUrl).not.toHaveBeenCalled())+ expect(screen.queryByAltText('Thumbnail of logo.png')).toBeNull()+ })+})diff --git a/desktop-app/ui/src/constants/gfsFileThumbnail.ts b/desktop-app/ui/src/constants/gfsFileThumbnail.tsnew file mode 100644index 000000000..1d339a6df--- /dev/null+++ b/desktop-app/ui/src/constants/gfsFileThumbnail.ts@@ -0,0 +1 @@+export const GFS_FILE_THUMBNAIL_MAX_BYTES = 1 * 1024 * 1024diff --git a/desktop-app/ui/src/lib/gfsFileThumbnail.ts b/desktop-app/ui/src/lib/gfsFileThumbnail.tsnew file mode 100644index 000000000..17df48fbc--- /dev/null+++ b/desktop-app/ui/src/lib/gfsFileThumbnail.ts@@ -0,0 +1,19 @@+import { GFS_FILE_THUMBNAIL_MAX_BYTES } from '@constants/gfsFileThumbnail'++/**+ * Decide whether a row entry should render a small inline thumbnail+ * (currently image files only, and small enough to fetch cheaply).+ *+ * `bytes` is the metadata-declared size from the GFS listing. We use+ * the metadata size first so we can skip the request entirely when the+ * file is already known to be larger than the thumbnail budget.+ */+export function shouldRenderGfsFileThumbnail(opts: {+ isImage: boolean+ bytes: number+ maxBytes?: number+}): boolean {+ if (!opts.isImage) return false+ const budget = opts.maxBytes ?? GFS_FILE_THUMBNAIL_MAX_BYTES+ return opts.bytes <= budget+}diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsxindex b7662d652..27d440904 100644--- a/desktop-app/ui/src/pages/FilesPage.tsx+++ b/desktop-app/ui/src/pages/FilesPage.tsx@@ -705,7 +705,11 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:) : currentIsFile ? (<div className="da-gfs-current-file"><span className="da-gfs-current-file__icon" aria-hidden="true">- {currentIsFile ? <GfsFileIcon name={current.name} /> : <IconAttachFile />}+ {currentIsFile ? (+ <GfsFileIcon name={current.name} bytes={current.bytes} rid={current.rid} />+ ) : (+ <IconAttachFile />+ )}</span><div className="da-gfs-current-file__copy"><div className="da-gfs-current-file__title-row">@@ -783,7 +787,11 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:{resource.kind === 'directory' ? (<IconContexts />) : (- <GfsFileIcon name={resource.name} />+ <GfsFileIcon+ name={resource.name}+ bytes={resource.bytes}+ rid={resource.rid}+ />)}</span><span className="da-gfs-list__identity da-grid__cell">@@ -934,7 +942,11 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:className={`da-gfs-manage-dialog__icon${currentIsFolder ? ' da-gfs-manage-dialog__icon--folder' : ''}`}aria-hidden="true">- {currentIsFolder ? <IconContexts /> : <GfsFileIcon name={current.name} />}+ {currentIsFolder ? (+ <IconContexts />+ ) : (+ <GfsFileIcon name={current.name} bytes={current.bytes} rid={current.rid} />+ )}</span><span className="da-gfs-manage-dialog__heading">{renameOpen ? (diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex 81a6e9805..4f161c7e7 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -13464,13 +13464,21 @@ pre {width: var(--space-5);height: var(--space-5);color: var(--text-muted);+ overflow: hidden;}-.da-gfs-list__icon svg {+.da-gfs-list__icon svg,+.da-gfs-list__icon .da-gfs-file-thumbnail {width: 100%;height: 100%;}+.da-gfs-file-thumbnail {+ display: block;+ object-fit: cover;+ border-radius: var(--radius-sm);+}+.da-gfs-list__identity {display: grid;gap: var(--space-0-5);