Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prepare-resources": "node scripts/download-python-embed.js",
"test": "npm run test:py && npm run test:node",
"test:py": "node scripts/run-pytests.mjs",
"test:node": "node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs src/shared/types/assetLibrary.test.ts src/areas/generate/assetLibraryProjection.test.ts src/areas/generate/assetLibraryService.test.ts src/areas/generate/assetLibraryUi.test.ts src/areas/library/libraryView.test.ts src/areas/library/gridWindow.test.ts src/areas/generate/orcaSlicerLink.test.ts src/shared/utils/agentStream.test.ts src/shared/thumbnails/assetThumbnailQueue.test.ts src/shared/thumbnails/assetThumbnailStore.test.ts src/shared/components/agent/clientTools.test.ts src/shared/components/agent/agentContext.test.ts src/shared/utils/ollamaHealth.test.ts src/shared/utils/notification.test.ts src/shared/utils/agentConversations.test.ts electron/main/artifact-registry-service.test.ts electron/main/asset-thumbnail-cache.test.ts electron/main/extension-path-guard.test.ts electron/main/storage-directory-guard.test.ts electron/main/storage-ownership.test.ts electron/main/startup-error.test.ts electron/main/api-port.test.ts electron/main/agent-conversations.test.ts electron/preload/artifact-registry-preload.test.ts src/shared/stores/meshHistory.test.ts src/areas/generate/meshEditPanel.test.ts src/areas/generate/sculpt/SculptMesh.test.ts src/areas/generate/sculpt/SculptMesh.perf.test.ts src/areas/generate/sculpt/sculptLogic.test.ts src/shared/pages/pageRegistry.test.ts src/areas/workflows/workflowRunRecord.test.ts && node --test electron/main/*.test.mjs src/**/*.test.mjs",
"test:node": "node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs src/shared/types/assetLibrary.test.ts src/areas/generate/assetLibraryProjection.test.ts src/areas/generate/assetLibraryService.test.ts src/areas/generate/assetLibraryUi.test.ts src/areas/library/libraryView.test.ts src/areas/library/gridWindow.test.ts src/areas/generate/orcaSlicerLink.test.ts src/shared/utils/agentStream.test.ts src/shared/thumbnails/assetThumbnailQueue.test.ts src/shared/thumbnails/assetThumbnailStore.test.ts src/shared/components/agent/clientTools.test.ts src/shared/components/agent/agentContext.test.ts src/shared/utils/ollamaHealth.test.ts src/shared/utils/notification.test.ts src/shared/utils/agentConversations.test.ts electron/main/artifact-registry-service.test.ts electron/main/asset-thumbnail-cache.test.ts electron/main/extension-path-guard.test.ts electron/main/storage-directory-guard.test.ts electron/main/storage-ownership.test.ts electron/main/startup-error.test.ts electron/main/api-port.test.ts electron/main/agent-conversations.test.ts electron/preload/artifact-registry-preload.test.ts src/shared/stores/meshHistory.test.ts src/areas/generate/meshEditPanel.test.ts src/areas/generate/sculpt/SculptMesh.test.ts src/areas/generate/sculpt/SculptMesh.perf.test.ts src/areas/generate/sculpt/sculptLogic.test.ts src/shared/pages/pageRegistry.test.ts src/shared/pages/startPage.test.ts src/areas/home/recents.test.ts src/areas/workflows/workflowRunRecord.test.ts && node --test electron/main/*.test.mjs src/**/*.test.mjs",
"package": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false npm run build && npm run prepare-resources && electron-builder",
"package:mac": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false npm run build && npm run prepare-resources && electron-builder --mac --arm64",
"lint": "eslint ."
Expand Down
15 changes: 3 additions & 12 deletions src/areas/generate/GeneratePage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useState, useRef, useCallback, useEffect, useMemo } from 'react'
import type { ReactNode } from 'react'
import { useAppStore, DEFAULT_LIGHT_SETTINGS } from '@shared/stores/appStore'
import type { GenerationJob, LightSettings, PointLight } from '@shared/stores/appStore'
import type { LightSettings, PointLight } from '@shared/stores/appStore'
import { showImportedMesh } from '@shared/utils/meshJob'
import { redoDepth, undoDepth } from '@shared/stores/meshHistory'
import { useApi } from '@shared/hooks/useApi'
import { ColorPicker } from '@shared/components/ui'
Expand Down Expand Up @@ -872,17 +873,7 @@ export default function GeneratePage(): JSX.Element {
setImporting(true)
try {
const { url } = await importMesh(filePath)
const job: GenerationJob = {
id: `import-${Date.now()}`,
imageFile: '',
status: 'done',
progress: 100,
outputUrl: url,
originalOutputUrl: url,
createdAt: Date.now(),
}
setCurrentJob(job)
pushMeshUrl(url)
showImportedMesh(url)
} finally {
setImporting(false)
}
Expand Down
31 changes: 26 additions & 5 deletions src/areas/generate/components/WorkflowPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useWaitButton } from '@areas/workflows/useWaitButton'
import { buildAllWorkflowExtensions, getWorkflowExtension } from '@areas/workflows/mockExtensions'
import { validateWorkflowPreflight } from '@areas/workflows/preflight'
import { mimeFromPath } from '@areas/workflows/nodes/imageUtils'
import { SUPPORTED_IMAGE_TYPES, useImageHandoff } from '@shared/utils/imageInput'
import type { WorkflowExtension } from '@areas/workflows/mockExtensions'
import type { Workflow, WFNode, WFEdge, ParamSchema } from '@shared/types/electron.d'
import { PICKER_LABELS, openParamPicker, resolvePickerIntent } from '@shared/utils/paramPicker'
Expand All @@ -28,8 +29,6 @@ const TYPE_COLOR: Record<string, string> = {
text: '#fbbf24',
}

const SUPPORTED_IMAGE_TYPES = new Set(['image/jpeg', 'image/png', 'image/webp'])

// ─── Helpers ──────────────────────────────────────────────────────────────────

function topoSortNodes(nodes: Workflow['nodes'], edges: Workflow['edges']): WFNode[] {
Expand Down Expand Up @@ -155,6 +154,12 @@ function WorkflowDropdown({ workflows, value, onChange }: {

type PatchFn = (nodeId: string, patch: Record<string, unknown>) => void

/** The image node params for a file on disk: its path and an inline preview. */
async function readImageParams(path: string): Promise<{ filePath: string, preview: string }> {
const base64 = await window.electron.fs.readFileBase64(path)
return { filePath: path, preview: `data:${mimeFromPath(path)};base64,${base64}` }
}

function ImageParamRow({ nodeId, nodes, onPatch }: { nodeId: string; nodes: FlowNode[]; onPatch: PatchFn }) {
const node = nodes.find((n) => n.id === nodeId)
const data = node?.data as { params: Record<string, unknown> } | undefined
Expand All @@ -166,10 +171,9 @@ function ImageParamRow({ nodeId, nodes, onPatch }: { nodeId: string; nodes: Flow
const request = ++loadRequest.current
if (!path) return
try {
const base64 = await window.electron.fs.readFileBase64(path)
const image = await readImageParams(path)
if (request !== loadRequest.current) return
const src = `data:${mimeFromPath(path)};base64,${base64}`
onPatch(nodeId, { params: { ...(data?.params ?? {}), filePath: path, preview: src } })
onPatch(nodeId, { params: { ...(data?.params ?? {}), ...image } })
} catch {
if (request === loadRequest.current) showToast('Unable to load the selected image')
}
Expand Down Expand Up @@ -519,6 +523,23 @@ function EmbeddedCanvas({ workflow, allExtensions }: {
&& (n.data as { showInGenerate?: boolean }).showInGenerate === true,
)

// An image handed over by another page (Home) goes into the first image input
// shown here, exactly as if it had been browsed in this panel.
const pendingImage = useImageHandoff((s) => s.pendingPath)
useEffect(() => {
const path = useImageHandoff.getState().take()
if (!path) return
const target = paramNodes.find((n) => n.type === 'imageNode')
if (!target) {
showToast('This workflow has no image input. Pick a workflow with one.')
return
}
readImageParams(path)
.then((image) => patchNode(target.id, { params: { ...(target.data.params ?? {}), ...image } }))
.catch(() => showToast('Unable to load the selected image'))
// eslint-disable-next-line react-hooks/exhaustive-deps -- runs when an image is handed over; nodes are read at that point
}, [pendingImage])

const handleGenerate = useCallback(() => {
if (firstPreflightIssue) {
showToast(firstPreflightIssue)
Expand Down
211 changes: 211 additions & 0 deletions src/areas/home/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useAppStore } from '@shared/stores/appStore'
import { useNavStore } from '@shared/stores/navStore'
import { useApi } from '@shared/hooks/useApi'
import { droppedImagePath, useImageHandoff } from '@shared/utils/imageInput'
import { showImportedMesh } from '@shared/utils/meshJob'
import { requestLibraryThumbnails } from '@shared/thumbnails/assetThumbnailService'
import type { ProjectedAssetLibraryEntry } from '@areas/generate/assetLibraryProjection'
import { getDefaultAssetLibraryService } from '@areas/generate/assetLibraryService'
import { openAssetLibraryEntry } from '@areas/generate/assetLibraryUi'
import { Thumbnail } from '@areas/library/LibraryGrid'
import ModlyLogo from '@shared/components/ui/ModlyLogo'
import { formatRelativeDate, selectRecentAssets } from './recents'

function Icon({ d, size = 16 }: { d: string, size?: number }): JSX.Element {
return (
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d={d} />
</svg>
)
}

const ICONS = {
upload: 'M12 16V4m0 0-4.5 4.5M12 4l4.5 4.5M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3',
workflow: 'M4 5h5v5H4zM15 14h5v5h-5zM9 7.5h3.5a2 2 0 0 1 2 2V14',
mesh: 'M12 2 3 7v10l9 5 9-5V7zM3 7l9 5 9-5M12 12v10',
library: 'M4 4h6.5v6.5H4zM13.5 4H20v6.5h-6.5zM4 13.5h6.5V20H4zM13.5 13.5H20V20h-6.5z',
}

function SectionHeader({ title, action }: { title: string, action?: { label: string, onClick: () => void } }): JSX.Element {
return (
<div className="mb-3 flex items-baseline justify-between">
<h2 className="text-[13px] font-semibold text-zinc-200">{title}</h2>
{action && (
<button type="button" onClick={action.onClick} className="text-xs font-medium text-zinc-500 transition-colors hover:text-zinc-200">
{action.label}
</button>
)}
</div>
)
}

function QuickAction({ icon, label, detail, busy, onClick }: { icon: string, label: string, detail: string, busy?: boolean, onClick: () => void }): JSX.Element {
return (
<button
type="button"
onClick={onClick}
disabled={busy}
className="group flex min-w-0 flex-1 items-center gap-3 rounded-xl border border-zinc-800 bg-zinc-900/50 px-4 py-3 text-left transition-colors hover:border-zinc-700 hover:bg-zinc-900 disabled:cursor-wait disabled:opacity-60"
>
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-zinc-800/80 text-zinc-400 transition-colors group-hover:text-accent-light">
<Icon d={icon} />
</span>
<span className="min-w-0">
<span className="block truncate text-[13px] font-medium text-zinc-200">{busy ? 'Importing…' : label}</span>
<span className="block truncate text-[11px] text-zinc-500">{detail}</span>
</span>
</button>
)
}

function DropZone({ onImage }: { onImage: (path: string) => void }): JSX.Element {
const [dragging, setDragging] = useState(false)
return (
<button
type="button"
onClick={() => { void window.electron.fs.selectImage().then((path) => { if (path) onImage(path) }) }}
onDragOver={(event) => { event.preventDefault(); setDragging(true) }}
onDragLeave={() => setDragging(false)}
onDrop={(event) => {
event.preventDefault()
setDragging(false)
const path = droppedImagePath(event.dataTransfer.files[0])
if (path) onImage(path)
}}
className={`flex w-full flex-col items-center justify-center gap-3 rounded-2xl border-2 border-dashed px-6 py-10 text-center transition-colors
${dragging ? 'border-accent bg-accent/10' : 'border-zinc-800 bg-zinc-900/30 hover:border-zinc-700 hover:bg-zinc-900/60'}`}
>
<span className={`flex h-12 w-12 items-center justify-center rounded-2xl ${dragging ? 'bg-accent/20 text-accent-light' : 'bg-zinc-800/80 text-zinc-400'}`}>
<Icon d={ICONS.upload} size={22} />
</span>
<span>
<span className="block text-[15px] font-medium text-zinc-100">Drop an image to generate a 3D model</span>
<span className="mt-1 block text-xs text-zinc-500">or click to choose a file · PNG, JPG, WEBP</span>
</span>
</button>
)
}

function RecentAsset({ entry, opening, onOpen }: { entry: ProjectedAssetLibraryEntry, opening: boolean, onOpen: () => void }): JSX.Element {
const date = formatRelativeDate(entry.updatedAt ?? entry.createdAt)
return (
<button type="button" onClick={onOpen} title={`${entry.workspacePath}\nOpen in Generate`} className="group min-w-0 text-left">
<div className="relative aspect-square w-full overflow-hidden rounded-xl border border-zinc-800 bg-zinc-900 transition-colors group-hover:border-zinc-600 group-focus-visible:border-accent-light">
<Thumbnail entry={entry} iconSize={28} />
{opening && (
<div className="absolute inset-0 flex items-center justify-center bg-zinc-950/60">
<span className="h-5 w-5 animate-spin rounded-full border-2 border-white/25 border-t-white" aria-hidden="true" />
</div>
)}
</div>
<p className="mt-2 truncate text-[12.5px] font-medium text-zinc-200">{entry.displayName}</p>
{date && <p className="truncate text-[11px] text-zinc-500">{date}</p>}
</button>
)
}

function Empty({ text }: { text: string }): JSX.Element {
return (
<div className="rounded-xl border border-zinc-800/80 bg-zinc-900/30 px-4 py-5">
<p className="text-xs text-zinc-500">{text}</p>
</div>
)
}

export default function HomePage(): JSX.Element {
const navigate = useNavStore((s) => s.navigate)
const showError = useAppStore((s) => s.showError)
const { importMesh } = useApi()
const service = useMemo(() => getDefaultAssetLibraryService(), [])

const [assets, setAssets] = useState<ProjectedAssetLibraryEntry[]>([])
const [assetsLoaded, setAssetsLoaded] = useState(false)
const [openingId, setOpeningId] = useState<string | null>(null)
const [importing, setImporting] = useState(false)

const loadAssets = useCallback(async () => {
try {
const result = await service.list()
if (!result.success) return
const recent = selectRecentAssets(result.entries)
setAssets(recent)
// Render only the thumbnails this page shows.
void requestLibraryThumbnails(recent)
} finally {
setAssetsLoaded(true)
}
}, [service])

useEffect(() => { void loadAssets() }, [loadAssets])

async function openAsset(entry: ProjectedAssetLibraryEntry) {
if (openingId) return
setOpeningId(entry.id)
try {
const result = await openAssetLibraryEntry(service, entry)
if (!result.success) {
showError(result.message)
return
}
const { setCurrentJob, pushMeshUrl } = useAppStore.getState()
setCurrentJob(result.selection.job)
pushMeshUrl(result.selection.historyUrl)
navigate('generate')
} catch (err) {
showError(err instanceof Error ? err.message : String(err))
} finally {
setOpeningId(null)
}
}

async function importFromDisk() {
const filePath = await window.electron.fs.selectMeshFile()
if (!filePath) return
setImporting(true)
try {
const { url } = await importMesh(filePath)
showImportedMesh(url)
navigate('generate')
} catch (err) {
showError(err instanceof Error ? err.message : 'Could not import the mesh.')
} finally {
setImporting(false)
}
}

const returning = assets.length > 0

return (
<div className="mx-auto flex min-h-full w-full max-w-4xl flex-col justify-center gap-10 px-7 py-12">
<header className="flex flex-col items-center text-center">
<ModlyLogo size={56} className="mb-5" />
<h1 className="text-[28px] font-semibold tracking-tight text-zinc-50">{returning ? 'Welcome back' : 'Welcome to Modly'}</h1>
</header>

<div className="flex flex-col gap-3">
<DropZone onImage={(path) => { useImageHandoff.getState().offer(path); navigate('generate') }} />
<div className="flex flex-col gap-3 sm:flex-row">
<QuickAction icon={ICONS.workflow} label="Open a workflow" detail="Build or run a node pipeline" onClick={() => navigate('workflows')} />
<QuickAction icon={ICONS.mesh} label="Import a mesh" detail="GLB, OBJ, STL, PLY" busy={importing} onClick={() => { void importFromDisk() }} />
<QuickAction icon={ICONS.library} label="Browse the library" detail="Everything you've made" onClick={() => navigate('library')} />
</div>
</div>

<section>
<SectionHeader title="Recent creations" action={assets.length > 0 ? { label: 'See all', onClick: () => navigate('library') } : undefined} />
{assets.length > 0 ? (
<div className="grid grid-cols-3 gap-4 lg:grid-cols-6">
{assets.map((entry) => (
<RecentAsset key={entry.id} entry={entry} opening={openingId === entry.id} onOpen={() => { void openAsset(entry) }} />
))}
</div>
) : assetsLoaded ? (
<Empty text="The meshes you generate or import will show up here." />
) : (
<div className="h-24" aria-hidden="true" />
)}
</section>
</div>
)
}
44 changes: 44 additions & 0 deletions src/areas/home/recents.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import assert from 'node:assert/strict'
import test from 'node:test'

import type { AssetLibraryEntry } from '../../shared/types/assetLibrary'
import { projectAssetLibraryEntry, type ProjectedAssetLibraryEntry } from '../generate/assetLibraryProjection'
import { formatRelativeDate, selectRecentAssets } from './recents'

function entry(name: string, overrides: Partial<AssetLibraryEntry> = {}): ProjectedAssetLibraryEntry {
return projectAssetLibraryEntry({
id: `library:${name}`,
workspacePath: `Workflows/run/${name}`,
displayName: name,
sourceScope: 'workflows',
capability: 'mesh',
state: 'ready',
previewKind: '3d-model',
warnings: [],
openable: true,
...overrides,
})
}

test('recent assets are the newest openable ones, newest first, capped', () => {
const entries = [
entry('old.glb', { createdAt: '2026-01-01T00:00:00.000Z' }),
entry('new.glb', { createdAt: '2026-03-01T00:00:00.000Z' }),
entry('mid.glb', { createdAt: '2026-02-01T00:00:00.000Z' }),
entry('locked.glb', { createdAt: '2026-04-01T00:00:00.000Z', state: 'unsafe', openable: false }),
entry('notes.txt', { createdAt: '2026-05-01T00:00:00.000Z', previewKind: 'text', openable: false }),
]
assert.deepEqual(selectRecentAssets(entries).map((e) => e.displayName), ['new.glb', 'mid.glb', 'old.glb'])
assert.deepEqual(selectRecentAssets(entries, 2).map((e) => e.displayName), ['new.glb', 'mid.glb'])
assert.deepEqual(selectRecentAssets([]), [])
})

test('formatRelativeDate reads ISO dates relative to now', () => {
const now = Date.parse('2026-11-14T12:00:00.000Z')
// English whatever the OS language, like the rest of the UI.
assert.equal(formatRelativeDate('2026-11-14T11:55:00.000Z', now), '5 minutes ago')
assert.equal(formatRelativeDate('2026-11-13T12:00:00.000Z', now), 'yesterday')
assert.equal(formatRelativeDate('2026-11-14T11:59:50.000Z', now), 'this minute')
assert.equal(formatRelativeDate('nope', now), null)
assert.equal(formatRelativeDate(undefined, now), null)
})
Loading
Loading