diff --git a/api/routers/agent.py b/api/routers/agent.py index 3eeb2a73..055b76bf 100644 --- a/api/routers/agent.py +++ b/api/routers/agent.py @@ -1,12 +1,15 @@ """ Agent chat endpoint — runs an Ollama-powered tool-use loop against Modly's API. """ +import json import re import uuid import httpx from fastapi import APIRouter from pydantic import BaseModel +import services.generator_registry as reg_module + router = APIRouter(prefix="/agent", tags=["agent"]) MODLY_API = "http://localhost:8765" @@ -408,6 +411,60 @@ def _extract_thinking(msg: dict) -> tuple[str, str | None]: return content, thinking +def _read_glb_modly_extras(glb_path) -> dict | None: + """Parse a GLB's leading JSON chunk and return asset.extras.modly, if present. + Used only as a fallback for assets that predate the .tags.json sidecar.""" + try: + with open(glb_path, "rb") as f: + header = f.read(12) + if len(header) < 12 or header[0:4] != b"glTF": + return None + chunk_header = f.read(8) + if len(chunk_header) < 8 or chunk_header[4:8] != b"JSON": + return None + chunk_length = int.from_bytes(chunk_header[0:4], "little") + doc = json.loads(f.read(chunk_length)) + return (doc.get("asset") or {}).get("extras", {}).get("modly") + except Exception: + return None + + +def _load_asset_meta(workspace_rel_path: str) -> dict | None: + """Resolve name/project/tags/lineage for the model currently in the viewer. + + Reads the .tags.json sidecar when present, falling back to the GLB's own + embedded extras.modly for name/project/tags. Lineage (derived_from) is only + ever written to the sidecar, so an asset with no sidecar has none to report. + """ + workspace_dir = reg_module.WORKSPACE_DIR.resolve() + abs_path = (workspace_dir / workspace_rel_path).resolve() + if not str(abs_path).startswith(str(workspace_dir)): + return None # escapes the workspace — refuse to read + + sidecar_path = abs_path.with_suffix(".tags.json") + if sidecar_path.exists(): + try: + data = json.loads(sidecar_path.read_text(encoding="utf-8")) + return { + "name": data.get("name"), + "project": data.get("project"), + "tags": data.get("tags") or [], + "derived_from": data.get("derived_from"), + } + except Exception: + pass # malformed sidecar — fall through to the GLB fallback + + modly = _read_glb_modly_extras(abs_path) + if modly: + return { + "name": modly.get("name"), + "project": modly.get("project"), + "tags": modly.get("tags") or [], + "derived_from": None, + } + return None + + @router.get("/models") async def list_ollama_models(ollama_url: str = "http://localhost:11434"): async with httpx.AsyncClient(timeout=5.0) as client: @@ -431,6 +488,30 @@ async def agent_chat(request: AgentChatRequest): ctx_lines.append(f"Current mesh path: {request.context['currentMeshPath']}") if request.context.get("meshTriangles"): ctx_lines.append(f"Current mesh triangles: {request.context['meshTriangles']:,}") + if request.context.get("currentClipName"): + ctx_lines.append(f"Current animation clip: {request.context['currentClipName']}") + if request.context.get("availableClips"): + ctx_lines.append(f"Available animation clips: {', '.join(request.context['availableClips'])}") + + mesh_path = request.context.get("currentMeshPath") + meta = _load_asset_meta(mesh_path) if mesh_path else None + if meta: + if meta.get("name"): + ctx_lines.append(f"Model name: {meta['name']}") + if meta.get("project"): + ctx_lines.append(f"Project: {meta['project']}") + if meta.get("tags"): + ctx_lines.append(f"Tags: {', '.join(meta['tags'])}") + derived = meta.get("derived_from") + if derived: + parent = derived.get("parent") or {} + root = derived.get("root") or {} + parent_label = parent.get("name") or parent.get("path") + root_label = root.get("name") or root.get("path") + if parent_label == root_label: + ctx_lines.append(f"Derived from: {parent_label}") + else: + ctx_lines.append(f"Derived from: {parent_label} (originally: {root_label})") if ctx_lines: messages.append({ "role": "system", diff --git a/electron/main/artifact-registry-service.test.ts b/electron/main/artifact-registry-service.test.ts index 882120d4..90c1ef1a 100644 --- a/electron/main/artifact-registry-service.test.ts +++ b/electron/main/artifact-registry-service.test.ts @@ -10,6 +10,7 @@ import { normalizeWorkspaceAssetPath, openWorkspaceAssetLibraryEntry, readWorkspaceAssetLibraryEntry, + readWorkspaceAssetLibraryThumbnail, registerWorkspaceAssetLibraryIpcHandlers, } from './artifact-registry-service.ts' @@ -198,6 +199,116 @@ test('fails closed for unsafe, self, missing, and mismatched sourceWorkspacePath assert.equal(!mismatched.success && mismatched.error.code, 'not-openable') })) +test('reads a sibling .thumb.png for GLB assets and stays silent when one is missing', () => withWorkspace(async (workspaceDir) => { + await mkdir(path.join(workspaceDir, 'Exports/props'), { recursive: true }) + await writeFile(path.join(workspaceDir, 'Exports/props/hero.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.thumb.png'), 'fake-png-bytes') + await writeFile(path.join(workspaceDir, 'Exports/props/no-thumb.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/static.ply'), 'ply') + + const withThumb = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb' }) + assert.equal(withThumb.success, true) + assert.equal(withThumb.success && withThumb.dataUrl, `data:image/png;base64,${Buffer.from('fake-png-bytes').toString('base64')}`) + + const withoutThumb = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/no-thumb.glb' }) + assert.equal(withoutThumb.success, false) + + const nonMesh = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/static.ply' }) + assert.equal(nonMesh.success, false) + + const unsafe = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: '../secret.glb' }) + assert.equal(unsafe.success, false) +})) + +test('attaches preview clip metadata to the thumbnail response when a manifest exists', () => withWorkspace(async (workspaceDir) => { + await mkdir(path.join(workspaceDir, 'Exports/props'), { recursive: true }) + await writeFile(path.join(workspaceDir, 'Exports/props/hero.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.thumb.png'), 'fake-png-bytes') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.preview-idle.webp'), 'fake-idle-webp') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.preview-walk.webp'), 'fake-walk-webp') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.previews.json'), JSON.stringify([ + { clip: 'idle', file: 'hero.preview-idle.webp', duration: 1.5 }, + { clip: 'walk', file: 'hero.preview-walk.webp', duration: 0.8 }, + ])) + + const withThumb = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb' }) + assert.equal(withThumb.success, true) + assert.deepEqual(withThumb.success && withThumb.previews, [ + { clip: 'idle', duration: 1.5 }, + { clip: 'walk', duration: 0.8 }, + ]) +})) + +test('fetches a specific preview clip WebP by name over the same thumbnail request', () => withWorkspace(async (workspaceDir) => { + await mkdir(path.join(workspaceDir, 'Exports/props'), { recursive: true }) + await writeFile(path.join(workspaceDir, 'Exports/props/hero.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.preview-walk.webp'), 'fake-walk-webp') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.previews.json'), JSON.stringify([ + { clip: 'walk', file: 'hero.preview-walk.webp', duration: 0.8 }, + ])) + + const clip = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb', previewClip: 'walk' }) + assert.equal(clip.success, true) + assert.equal(clip.success && clip.dataUrl, `data:image/webp;base64,${Buffer.from('fake-walk-webp').toString('base64')}`) + + const unknownClip = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb', previewClip: 'sprint' }) + assert.equal(unknownClip.success, false) +})) + +test('thumbnail response carries no previews field when no manifest exists, and stays silent on a malformed one', () => withWorkspace(async (workspaceDir) => { + await mkdir(path.join(workspaceDir, 'Exports/props'), { recursive: true }) + await writeFile(path.join(workspaceDir, 'Exports/props/hero.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.thumb.png'), 'fake-png-bytes') + await writeFile(path.join(workspaceDir, 'Exports/props/broken.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/props/broken.thumb.png'), 'fake-png-bytes') + await writeFile(path.join(workspaceDir, 'Exports/props/broken.previews.json'), 'not valid json{') + + const noManifest = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb' }) + assert.equal(noManifest.success, true) + assert.equal(noManifest.success && noManifest.previews, undefined) + + const malformedManifest = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/broken.glb' }) + assert.equal(malformedManifest.success, true) + assert.equal(malformedManifest.success && malformedManifest.previews, undefined) +})) + +test('rejects a preview manifest entry that tries to escape the asset directory via its file field', () => withWorkspace(async (workspaceDir) => { + await mkdir(path.join(workspaceDir, 'Exports/props'), { recursive: true }) + await writeFile(path.join(workspaceDir, 'Exports/props/hero.glb'), 'glb') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.thumb.png'), 'fake-png-bytes') + await writeFile(path.join(workspaceDir, 'secret.webp'), 'top-secret-bytes') + await writeFile(path.join(workspaceDir, 'Exports/props/hero.previews.json'), JSON.stringify([ + { clip: 'escape-relative', file: '../../secret.webp', duration: 1 }, + { clip: 'escape-absolute', file: '/etc/passwd', duration: 1 }, + { clip: 'wrong-extension', file: 'hero.glb', duration: 1 }, + ])) + + // The manifest lists the clip in its metadata (harmless — it's just a name), + // but every attempt to actually fetch the referenced file must fail closed. + const listed = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb' }) + assert.equal(listed.success, true) + assert.equal(listed.success && listed.previews?.length, 3) + + const relative = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb', previewClip: 'escape-relative' }) + assert.equal(relative.success, false) + const absolute = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb', previewClip: 'escape-absolute' }) + assert.equal(absolute.success, false) + const wrongExtension = await readWorkspaceAssetLibraryThumbnail({ workspaceDir, workspacePath: 'Exports/props/hero.glb', previewClip: 'wrong-extension' }) + assert.equal(wrongExtension.success, false) +})) + +test('IPC thumbnail handler forwards previewClip from payload', async () => { + const handlers = new Map Promise>() + registerWorkspaceAssetLibraryIpcHandlers({ + ipcMain: { handle: (channel, handler) => handlers.set(channel, handler) }, + getWorkspaceDir: () => '/tmp/modly-workspace', + }) + + const result = await handlers.get('workspace:library:thumbnail')?.({}, { workspacePath: 'Exports/hero.glb', previewClip: 'walk' }) + // No such workspace/file in this test, so it must fail closed rather than throw. + assert.equal((result as { success: boolean }).success, false) +}) + test('IPC read and open handlers forward sourceWorkspacePath without trusting malformed payloads', async () => { const handlers = new Map Promise>() registerWorkspaceAssetLibraryIpcHandlers({ @@ -224,7 +335,12 @@ test('registers workspace library IPC handlers with structured results', async ( assert.equal(typeof handlers.get('workspace:library:list'), 'function') assert.equal(typeof handlers.get('workspace:library:read'), 'function') assert.equal(typeof handlers.get('workspace:library:open'), 'function') + assert.equal(typeof handlers.get('workspace:library:thumbnail'), 'function') const result = await handlers.get('workspace:library:read')?.({}, { workspacePath: '../escape.glb' }) assert.equal(typeof (result as { success?: unknown }).success, 'boolean') assert.equal((result as { success: boolean, error?: { code: string } }).error?.code, 'unsafe-path') + const thumbnail = await handlers.get('workspace:library:thumbnail')?.({}, { workspacePath: '../escape.glb' }) + assert.equal((thumbnail as { success: boolean }).success, false) + const missingPayload = await handlers.get('workspace:library:thumbnail')?.({}, {}) + assert.equal((missingPayload as { success: boolean }).success, false) }) diff --git a/electron/main/artifact-registry-service.ts b/electron/main/artifact-registry-service.ts index 3c26de73..b634aab1 100644 --- a/electron/main/artifact-registry-service.ts +++ b/electron/main/artifact-registry-service.ts @@ -8,10 +8,12 @@ import type { AssetLibraryError, AssetLibraryListResult, AssetLibraryOpenResult, + AssetLibraryPreviewClip, AssetLibraryPreviewKind, AssetLibraryPreviewPayload, AssetLibraryReadResult, AssetLibrarySourceScope, + AssetLibraryThumbnailResult, } from '../../src/shared/types/assetLibrary' import type { ArtifactProvenance } from '../../src/shared/types/artifacts' @@ -51,6 +53,11 @@ export interface WorkspaceAssetLibraryReadRequest extends WorkspaceAssetLibraryR sourceWorkspacePath?: string } +export interface WorkspaceAssetLibraryThumbnailRequest extends WorkspaceAssetLibraryRequest { + workspacePath: string + previewClip?: string +} + interface AssetLibraryMetadata { sourceWorkspacePath?: string manifestWorkspacePath?: string @@ -342,12 +349,131 @@ export async function openWorkspaceAssetLibraryEntry(request: WorkspaceAssetLibr return { success: true, entry: read.entry } } -function readPayloadRequest(payload: unknown): { workspacePath?: string, sourceWorkspacePath?: string } { +function previewManifestAbsolutePathFor(absolutePath: string): string { + return absolutePath.replace(/\.(glb|gltf)$/i, '.previews.json') +} + +interface AssetLibraryPreviewManifestEntry { + clip: string + file: string + duration: number +} + +function parsePreviewManifestList(raw: unknown): unknown[] { + if (Array.isArray(raw)) return raw + if (typeof raw === 'object' && raw !== null) { + const container = raw as Record + if (Array.isArray(container.previews)) return container.previews + if (Array.isArray(container.clips)) return container.clips + } + return [] +} + +function parsePreviewManifestEntry(raw: unknown): AssetLibraryPreviewManifestEntry | null { + if (typeof raw !== 'object' || raw === null) return null + const candidate = raw as Record + const clip = stringField(candidate.clip) + const file = stringField(candidate.file) + const duration = typeof candidate.duration === 'number' && Number.isFinite(candidate.duration) ? candidate.duration : undefined + if (!clip || !file || duration === undefined) return null + return { clip, file, duration } +} + +// The preview manifest and its clips are generated by a separate pipeline (not +// thumbs.py) and may not exist yet, or may be malformed mid-write — both are +// normal, silent conditions handled the same way a missing thumbnail is. +async function readPreviewManifestEntries(absolutePath: string): Promise { + let parsed: unknown + try { + parsed = JSON.parse(await readFile(previewManifestAbsolutePathFor(absolutePath), 'utf8')) + } catch { + return [] + } + return parsePreviewManifestList(parsed) + .map(parsePreviewManifestEntry) + .filter((entry): entry is AssetLibraryPreviewManifestEntry => entry !== null) +} + +async function readAssetLibraryPreviewClips(absolutePath: string): Promise { + const entries = await readPreviewManifestEntries(absolutePath) + return entries.map(({ clip, duration }) => ({ clip, duration })) +} + +/** + * Resolves a manifest-listed clip name to a safe absolute WebP path. The + * manifest's `file` is trusted only as a filename — any directory component is + * discarded via `basename` — and the reconstructed sibling workspace path is + * re-validated through the same `normalizeWorkspaceAssetPath` guard every + * other workspace library read uses, so a stale or malformed manifest can + * never point outside the asset's own directory. + */ +async function resolvePreviewClipAbsolutePath( + workspaceDir: string, + workspacePath: string, + absolutePath: string, + previewClip: string, +): Promise { + const entries = await readPreviewManifestEntries(absolutePath) + const match = entries.find((entry) => entry.clip === previewClip) + if (!match) return null + const fileName = basename(match.file) + if (extensionOf(fileName) !== 'webp') return null + const siblingWorkspacePath = [...workspacePath.split('/').slice(0, -1), fileName].join('/') + let normalized: NormalizedWorkspaceAssetPath + try { + normalized = normalizeWorkspaceAssetPath(workspaceDir, siblingWorkspacePath) + } catch { + return null + } + try { + await stat(normalized.absolutePath) + } catch { + return null + } + return normalized.absolutePath +} + +// Thumbnails are pre-rendered beside their source mesh (see thumbs.py): a +// `.glb` asset may have a sibling `.thumb.png`. Missing files are +// a normal, silent condition, never surfaced as an AssetLibraryError. +// +// The same request also serves looping preview clips generated by a separate +// pipeline as `.preview-.webp`, listed in a sibling +// `.previews.json` manifest. Passing `previewClip` fetches that clip's +// WebP instead of the static thumbnail; omitting it fetches the static +// thumbnail as before and, when a manifest exists, attaches the clip list so +// the UI can offer hover-to-animate without a second round trip to discover +// it. No manifest yet (the common case until the preview pipeline lands) is +// indistinguishable from today's behavior. +export async function readWorkspaceAssetLibraryThumbnail(request: WorkspaceAssetLibraryThumbnailRequest): Promise { + try { + const normalized = normalizeWorkspaceAssetPath(request.workspaceDir, request.workspacePath) + if (!isGlbOrGltf(normalized.workspacePath)) return { success: false } + + if (request.previewClip) { + const clipAbsolutePath = await resolvePreviewClipAbsolutePath(request.workspaceDir, normalized.workspacePath, normalized.absolutePath, request.previewClip) + if (!clipAbsolutePath) return { success: false } + const buffer = await readFile(clipAbsolutePath) + return { success: true, dataUrl: `data:image/webp;base64,${buffer.toString('base64')}` } + } + + const thumbnailAbsolutePath = normalized.absolutePath.replace(/\.(glb|gltf)$/i, '.thumb.png') + const buffer = await readFile(thumbnailAbsolutePath) + const dataUrl = `data:image/png;base64,${buffer.toString('base64')}` + const previews = await readAssetLibraryPreviewClips(normalized.absolutePath) + return previews.length > 0 ? { success: true, dataUrl, previews } : { success: true, dataUrl } + } catch { + return { success: false } + } +} + +function readPayloadRequest(payload: unknown): { workspacePath?: string, sourceWorkspacePath?: string, previewClip?: string } { if (typeof payload !== 'object' || payload === null) return {} - const values = payload as { workspacePath?: unknown, sourceWorkspacePath?: unknown } + const values = payload as { workspacePath?: unknown, sourceWorkspacePath?: unknown, previewClip?: unknown } return { workspacePath: typeof values.workspacePath === 'string' ? values.workspacePath : undefined, sourceWorkspacePath: typeof values.sourceWorkspacePath === 'string' ? values.sourceWorkspacePath : undefined, + previewClip: typeof values.previewClip === 'string' ? values.previewClip : undefined, } } @@ -363,4 +489,9 @@ export function registerWorkspaceAssetLibraryIpcHandlers(deps: WorkspaceAssetLib if (!workspacePath) return { success: false, error: libraryError('invalid-request', 'workspacePath is required.') } return openWorkspaceAssetLibraryEntry({ workspaceDir: deps.getWorkspaceDir(), workspacePath, sourceWorkspacePath }) }) + deps.ipcMain.handle('workspace:library:thumbnail', async (_event, payload) => { + const { workspacePath, previewClip } = readPayloadRequest(payload) + if (!workspacePath) return { success: false } + return readWorkspaceAssetLibraryThumbnail({ workspaceDir: deps.getWorkspaceDir(), workspacePath, previewClip }) + }) } diff --git a/electron/main/index.ts b/electron/main/index.ts index 8cf9c810..388ae4a4 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,5 +1,6 @@ import { app, BrowserWindow, shell, session } from 'electron' import { join } from 'path' +import { readFileSync, writeFileSync } from 'fs' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { setupIpcHandlers } from './ipc-handlers' import { PythonBridge } from './python-bridge' @@ -16,6 +17,37 @@ let pythonBridge: PythonBridge | null = null process.stdout?.on('error', () => {}) process.stderr?.on('error', () => {}) +// UI zoom: Ctrl/Cmd with + / - / 0 scales the whole window like a browser, +// clamped to a sane range and persisted across restarts. This is done at the +// Chromium level (not CSS) so pointer math in the 3D viewport stays correct. +const ZOOM_MIN = -2 +const ZOOM_MAX = 4 + +function zoomFilePath(): string { + return join(app.getPath('userData'), 'ui-zoom.json') +} + +function loadZoomLevel(): number { + try { + const saved = JSON.parse(readFileSync(zoomFilePath(), 'utf-8')) as { level?: number } + return typeof saved.level === 'number' ? saved.level : 0 + } catch { + return 0 + } +} + +function saveZoomLevel(level: number): void { + try { + writeFileSync(zoomFilePath(), JSON.stringify({ level }), 'utf-8') + } catch (err) { + logger.error(`Failed to persist UI zoom level: ${err}`) + } +} + +function clampZoomLevel(level: number): number { + return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, level)) +} + function createWindow(): void { mainWindow = new BrowserWindow({ width: 1280, @@ -57,6 +89,33 @@ function createWindow(): void { event.preventDefault() app.quit() } + + const isZoomChord = input.type === 'keyDown' && (input.control || input.meta) && !input.alt + if (!isZoomChord) return + + const wc = mainWindow?.webContents + if (!wc) return + + if (input.key === '+' || input.key === '=') { + event.preventDefault() + const level = clampZoomLevel(wc.getZoomLevel() + 0.5) + wc.setZoomLevel(level) + saveZoomLevel(level) + } else if (input.key === '-' || input.key === '_') { + event.preventDefault() + const level = clampZoomLevel(wc.getZoomLevel() - 0.5) + wc.setZoomLevel(level) + saveZoomLevel(level) + } else if (input.key === '0') { + event.preventDefault() + wc.setZoomLevel(0) + saveZoomLevel(0) + } + }) + + mainWindow.webContents.on('did-finish-load', () => { + const level = loadZoomLevel() + if (level) mainWindow?.webContents.setZoomLevel(level) }) mainWindow.webContents.setWindowOpenHandler((details) => { diff --git a/electron/main/ipc-handlers.ts b/electron/main/ipc-handlers.ts index 14fc984a..6af973d9 100644 --- a/electron/main/ipc-handlers.ts +++ b/electron/main/ipc-handlers.ts @@ -1395,7 +1395,7 @@ export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGe }) // Run a process extension in an isolated worker thread - ipcMain.handle('extensions:runProcess', async (_, extensionId: string, input: { filePath?: string; text?: string; texts?: (string | undefined)[]; nodeId?: string }, params: Record) => { + ipcMain.handle('extensions:runProcess', async (_, extensionId: string, input: { filePath?: string; text?: string; texts?: (string | undefined)[]; nodeId?: string; sourceAssetPath?: string }, params: Record) => { const userData = app.getPath('userData') const { extensionsDir, workspaceDir } = getSettings(userData) diff --git a/electron/main/process-runner.ts b/electron/main/process-runner.ts index b31a62e4..c0f08223 100644 --- a/electron/main/process-runner.ts +++ b/electron/main/process-runner.ts @@ -52,6 +52,9 @@ export interface ProcessInput { /** Per-slot texts for multi-text-input nodes (index = target handle slot). */ texts?: (string | undefined)[] nodeId?: string + /** Absolute path of the existing workspace asset this input was sourced from + * (if any) — threaded through the run so mesh-exporter can record lineage. */ + sourceAssetPath?: string } export interface ProcessResult { diff --git a/electron/preload/artifact-registry-preload.test.ts b/electron/preload/artifact-registry-preload.test.ts index 511589e4..5f0f66c4 100644 --- a/electron/preload/artifact-registry-preload.test.ts +++ b/electron/preload/artifact-registry-preload.test.ts @@ -24,6 +24,8 @@ test('preload exposes scoped workspace library list/read/open methods', async () workspacePath: 'Workflows/checkpoints/hero.landmarks.v1.json', sourceWorkspacePath: 'Workflows/checkpoints/hero.glb', }) + await api.workspace.library.thumbnail({ workspacePath: 'Exports/hero.glb' }) + await api.workspace.library.thumbnail({ workspacePath: 'Exports/hero.glb', previewClip: 'walk' }) assert.deepEqual(calls, [ { channel: 'workspace:library:list', payload: undefined }, @@ -41,5 +43,7 @@ test('preload exposes scoped workspace library list/read/open methods', async () sourceWorkspacePath: 'Workflows/checkpoints/hero.glb', }, }, + { channel: 'workspace:library:thumbnail', payload: { workspacePath: 'Exports/hero.glb' } }, + { channel: 'workspace:library:thumbnail', payload: { workspacePath: 'Exports/hero.glb', previewClip: 'walk' } }, ]) }) diff --git a/electron/preload/electron-api.ts b/electron/preload/electron-api.ts index 4f351b49..433e2094 100644 --- a/electron/preload/electron-api.ts +++ b/electron/preload/electron-api.ts @@ -4,6 +4,8 @@ import type { AssetLibraryOpenResult, AssetLibraryReadRequest, AssetLibraryReadResult, + AssetLibraryThumbnailRequest, + AssetLibraryThumbnailResult, } from '../../src/shared/types/assetLibrary' export interface IpcRendererLike { @@ -189,6 +191,7 @@ export function createElectronApi(ipcRenderer: IpcRendererLike, webFrame: WebFra list: (): Promise => ipcRenderer.invoke('workspace:library:list') as Promise, read: (request: AssetLibraryReadRequest): Promise => ipcRenderer.invoke('workspace:library:read', request) as Promise, open: (request: AssetLibraryOpenRequest): Promise => ipcRenderer.invoke('workspace:library:open', request) as Promise, + thumbnail: (request: AssetLibraryThumbnailRequest): Promise => ipcRenderer.invoke('workspace:library:thumbnail', request) as Promise, }, }, @@ -230,7 +233,7 @@ export function createElectronApi(ipcRenderer: IpcRendererLike, webFrame: WebFra runProcess: ( extensionId: string, - input: { filePath?: string; text?: string; texts?: (string | undefined)[]; nodeId?: string }, + input: { filePath?: string; text?: string; texts?: (string | undefined)[]; nodeId?: string; sourceAssetPath?: string }, params: Record, ): Promise<{ success: boolean; result?: { filePath?: string; text?: string }; error?: string }> => ipcRenderer.invoke('extensions:runProcess', extensionId, input, params) as Promise<{ success: boolean; result?: { filePath?: string; text?: string }; error?: string }>, diff --git a/package-lock.json b/package-lock.json index 1f336a2b..944bd257 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "modly", - "version": "0.3.5", + "version": "0.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "modly", - "version": "0.3.5", + "version": "0.4.1", "dependencies": { "@electron-toolkit/utils": "^4.0.0", "@mkkellogg/gaussian-splats-3d": "^0.4.7", @@ -25,6 +25,7 @@ "zustand": "^5.0.3" }, "devDependencies": { + "@eslint/js": "^9.39.4", "@types/node": "^22.10.1", "@types/react": "^18.3.17", "@types/react-dom": "^18.3.5", @@ -37,9 +38,12 @@ "electron-builder": "^24.13.3", "electron-vite": "^2.3.0", "eslint": "^9.17.0", + "eslint-plugin-react-hooks": "^7.1.1", + "globals": "^17.6.0", "postcss": "^8.4.49", "tailwindcss": "^3.4.17", "typescript": "^5.7.2", + "typescript-eslint": "^8.61.1", "vite": "^5.4.0" } }, @@ -1193,6 +1197,19 @@ "concat-map": "0.0.1" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/eslintrc/node_modules/minimatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.3.tgz", @@ -1206,10 +1223,11 @@ } }, "node_modules/@eslint/js": { - "version": "9.39.3", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.3.tgz", - "integrity": "sha512-1B1VkCq6FuUNlQvlBYb+1jDu/gV297TIs/OeiaSR9l1H27SVW55ONE1e1Vp16NqP683+xEGzxYtv4XCiDPaQiw==", + "version": "9.39.5", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.5.tgz", + "integrity": "sha512-QywQuszQh77pIXCsq998c8hbhSTI/azTty1Z6N53dmAudKHhy573j3yvRLsX2BSp8YpLtoCEG8E9DJe+8zUh4A==", "dev": true, + "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, @@ -2470,6 +2488,301 @@ "@types/node": "*" } }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.65.0.tgz", + "integrity": "sha512-IEgob78X12rHpUmtcwFsXhZdVGJtwTVP8FiCLZkR6GlYVrl2PcuB+KhCE5BlVC/eQpQnu8WXRtkHZuPar+gCRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/regexpp": "^4.12.2", + "@typescript-eslint/scope-manager": "8.65.0", + "@typescript-eslint/type-utils": "8.65.0", + "@typescript-eslint/utils": "8.65.0", + "@typescript-eslint/visitor-keys": "8.65.0", + "ignore": "^7.0.5", + "natural-compare": "^1.4.0", + "ts-api-utils": "^2.5.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^8.65.0", + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.6.tgz", + "integrity": "sha512-BAg6QkE8W+TuQLrrw0Ugr7HegXduRuuj8/ti2kSOc+jz1dmx8/WNcjr6XGnq5YpDWxFwwaavqD0+jIUOKelTsw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.65.0.tgz", + "integrity": "sha512-CZ4nMxWwgu1HEEFNkeaCptra9QCtkmKdgf3sWh1rl1trIhmxLilgTV4cwcbQ4wemnT4sWQN8CaKOmdYx+g2gMA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/scope-manager": "8.65.0", + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/typescript-estree": "8.65.0", + "@typescript-eslint/visitor-keys": "8.65.0", + "debug": "^4.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/project-service": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.65.0.tgz", + "integrity": "sha512-SxnPhbTsGahizDgbu7oqFH/xVtzIqMd/s+WtnSxNxJZJpLbdT5IPdzg8EZxO3+PoKahXmwJLeNQOpKJb3/bi7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/tsconfig-utils": "^8.65.0", + "@typescript-eslint/types": "^8.65.0", + "debug": "^4.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.65.0.tgz", + "integrity": "sha512-Esbl8OSYiVxBokYgWPf7VVWg/BE798wXhimnn9ML9Pt5qoDf8bfQlgjlKXR/k98+AcNzlLKYrpCcrcuZ9DZLgg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/visitor-keys": "8.65.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/tsconfig-utils": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.65.0.tgz", + "integrity": "sha512-j6GzGqCiRdA7Qhur2VVmKZAkBLfnHFQfx4TaJGL9RMveZqCo48jSHHO0DTgizEnGhtWnqmbtCUSrqSkdiY/0Hg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.65.0.tgz", + "integrity": "sha512-YjaZ7PRI5qY7ax2L3PbvX0rRyGtipAReCWs0mhhDBHjH/vl0g0BonaGXrKdKpMbIIsMIwDgbk/xzkBTyAltS5g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/typescript-estree": "8.65.0", + "@typescript-eslint/utils": "8.65.0", + "debug": "^4.4.3", + "ts-api-utils": "^2.5.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.65.0.tgz", + "integrity": "sha512-JSSwWNy+H0E/01jJEM+hrX6N0OFDzFzeIhHFSAS01tlVaevpG8cFyYRPhS5yjGOvBUx3sqQHVMjCL1CAZZMxBg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.65.0.tgz", + "integrity": "sha512-JboAE2swaYt4tb1fHhHTABE2K+OLy09XfcTbhnk4Pw96f9dd2e9iYsJ28gBggHlo5z5x1rkyWvcPoTuNTd4oGg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.65.0", + "@typescript-eslint/tsconfig-utils": "8.65.0", + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/visitor-keys": "8.65.0", + "debug": "^4.4.3", + "minimatch": "^10.2.2", + "semver": "^7.7.3", + "tinyglobby": "^0.2.15", + "ts-api-utils": "^2.5.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/brace-expansion": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.8.tgz", + "integrity": "sha512-JZyDyq3D4AUifKTPOB7DELf6XsB3WdPuNxCtob1vFXPsSXhdAiHBWJ/tJ8HAc9aH84BK+5JFZLNkJKx3G9kzQg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "10.2.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", + "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.8" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.65.0.tgz", + "integrity": "sha512-gXiwIHsYreboxeJucHKPvgwl7dXt50mF8s1/c00cP/WoVTyWKFdtfhRWwZiXYFU5H2O8vVoSLNrexFZjYS/SGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.9.1", + "@typescript-eslint/scope-manager": "8.65.0", + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/typescript-estree": "8.65.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.65.0.tgz", + "integrity": "sha512-8C71BQkGjiMmXtop7pHVJu1l2NNShFdkCyD6a2ezzs5vU/L3LRtb69EtcteFwz0mYMPzIgOw0n6OV4VBUWZd7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.65.0", + "eslint-visitor-keys": "^5.0.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/visitor-keys/node_modules/eslint-visitor-keys": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", + "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=24" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/@use-gesture/core": { "version": "10.3.1", "resolved": "https://registry.npmjs.org/@use-gesture/core/-/core-10.3.1.tgz", @@ -5137,6 +5450,26 @@ } } }, + "node_modules/eslint-plugin-react-hooks": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-7.1.1.tgz", + "integrity": "sha512-f2I7Gw6JbvCexzIInuSbZpfdQ44D7iqdWX01FKLvrPgqxoE7oMj8clOfto8U6vYiz4yd5oKu39rRSVOe1zRu0g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/core": "^7.24.4", + "@babel/parser": "^7.24.4", + "hermes-parser": "^0.25.1", + "zod": "^3.25.0 || ^4.0.0", + "zod-validation-error": "^3.5.0 || ^4.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 || ^10.0.0" + } + }, "node_modules/eslint-scope": { "version": "8.4.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz", @@ -5165,6 +5498,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/@eslint/js": { + "version": "9.39.3", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.3.tgz", + "integrity": "sha512-1B1VkCq6FuUNlQvlBYb+1jDu/gV297TIs/OeiaSR9l1H27SVW55ONE1e1Vp16NqP683+xEGzxYtv4XCiDPaQiw==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + } + }, "node_modules/eslint/node_modules/brace-expansion": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", @@ -5716,10 +6062,11 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "17.8.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.8.0.tgz", + "integrity": "sha512-Zz/LMDZScFmkakeL2cTHzf+PbWKdpU3uclqkZT7TjDG58j5WPt0PpA+n9uPI24fZtlw07q0OtEi84K+umsRzqQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=18" }, @@ -5845,6 +6192,23 @@ "node": ">= 0.4" } }, + "node_modules/hermes-estree": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.25.1.tgz", + "integrity": "sha512-0wUoCcLp+5Ev5pDW2OriHC2MJCbwLwuRx+gAqMTOkGKJJiBCLjtrvy4PWUGn6MIVefecRpzoOZ/UV6iGdOr+Cw==", + "dev": true, + "license": "MIT" + }, + "node_modules/hermes-parser": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.25.1.tgz", + "integrity": "sha512-6pEjquH3rqaI6cYAXYPcz9MS4rY6R4ngRgrgfDshRptUZIc3lw0MCIJIGDj9++mfySOuPTHB4nrSW99BCvOPIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "hermes-estree": "0.25.1" + } + }, "node_modules/hls.js": { "version": "1.6.15", "resolved": "https://registry.npmjs.org/hls.js/-/hls.js-1.6.15.tgz", @@ -8314,6 +8678,19 @@ "utf8-byte-length": "^1.0.1" } }, + "node_modules/ts-api-utils": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz", + "integrity": "sha512-OJ/ibxhPlqrMM0UiNHJ/0CKQkoKF243/AEmplt3qpRgkW8VG7IfOS41h7V8TjITqdByHzrjcS/2si+y4lIh8NA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.12" + }, + "peerDependencies": { + "typescript": ">=4.8.4" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", @@ -8392,6 +8769,30 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.65.0.tgz", + "integrity": "sha512-/ggrHAwyjENDusvyxbuqxAC2dTnZg/Z8F+fgQtYIz+L6n/9HfSlEZcFGV/NsMNa6CkGk0xUjUAFwC0vHOflvIA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/eslint-plugin": "8.65.0", + "@typescript-eslint/parser": "8.65.0", + "@typescript-eslint/typescript-estree": "8.65.0", + "@typescript-eslint/utils": "8.65.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, "node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", @@ -9168,6 +9569,29 @@ "node": ">= 10" } }, + "node_modules/zod": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz", + "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-validation-error": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/zod-validation-error/-/zod-validation-error-4.0.2.tgz", + "integrity": "sha512-Q6/nZLe6jxuU80qb/4uJ4t5v2VEZ44lzQjPDhYJNztRQ4wyWc6VF3D3Kb/fAuPetZQnhS3hnajCf9CsWesghLQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "zod": "^3.25.0 || ^4.0.0" + } + }, "node_modules/zustand": { "version": "5.0.11", "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.11.tgz", diff --git a/src/areas/generate/GeneratePage.tsx b/src/areas/generate/GeneratePage.tsx index a6dbe4f3..e8aeae2d 100644 --- a/src/areas/generate/GeneratePage.tsx +++ b/src/areas/generate/GeneratePage.tsx @@ -9,24 +9,57 @@ import Viewer3D from './components/Viewer3D' import WorkflowPanel from './components/WorkflowPanel' import { getDefaultAssetLibraryService } from './assetLibraryService' import { resolveAssetLibraryOpenTarget, type ProjectedAssetLibraryEntry } from './assetLibraryProjection' +import type { AssetLibraryPreviewClip } from '../../shared/types/assetLibrary' import { ASSET_LIBRARY_SORT_OPTIONS, buildAssetLibraryOpenRequest, + clampAssetLibraryPanelHeight, + clampAssetLibraryPanelWidth, createAssetLibraryOpenJob, describeAssetLibraryOpenability, filterAssetLibraryScopeGroups, getDefaultAssetLibraryCollapsedSectionKeys, + getStoredAssetLibraryPanelHeight, + getStoredAssetLibraryPanelWidth, isAssetLibraryEntryOpenable, + isAssetLibrarySectionExpanded, resolveOpenPanelAfterLibrarySelection, + storeAssetLibraryPanelHeight, + storeAssetLibraryPanelWidth, toggleAssetLibrarySectionKey, type AssetLibrarySortMode, type GenerateOpenPanel, } from './assetLibraryUi' const MIN_WIDTH = 220 -const MAX_WIDTH = 520 +const MAX_WIDTH = 900 const DEFAULT_WIDTH = 320 +const PANEL_WIDTH_STORAGE_KEY = 'modly-panel-width' + +function clampPanelWidth(width: number): number { + return Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, width)) +} + +/** Reads the user's saved Generate panel width, falling back to the default when unset, invalid, or unreadable. */ +function getStoredPanelWidth(): number { + try { + const raw = Number(localStorage.getItem(PANEL_WIDTH_STORAGE_KEY)) + return Number.isFinite(raw) && raw > 0 ? clampPanelWidth(raw) : DEFAULT_WIDTH + } catch { + return DEFAULT_WIDTH + } +} + +/** Persists the Generate panel width so it survives app restarts. */ +function storePanelWidth(width: number): void { + try { + localStorage.setItem(PANEL_WIDTH_STORAGE_KEY, String(width)) + } catch { + // Ignore quota/private-mode failures — the panel just won't remember its size. + } +} + // --------------------------------------------------------------------------- // Export dropdown // --------------------------------------------------------------------------- @@ -359,6 +392,10 @@ function AssetLibraryToggleButton({ ) } +// A stable empty-array reference for entries with no preview manifest yet, so +// rows don't see a fresh `[]` identity on every parent re-render. +const EMPTY_PREVIEW_CLIPS: AssetLibraryPreviewClip[] = [] + function AssetLibraryPopover({ entries, selectedEntryId, @@ -368,13 +405,20 @@ function AssetLibraryPopover({ searchQuery, sortMode, collapsedSectionKeys, - onSelectEntry, + thumbnails, + previews, + panelWidth, + panelHeight, + onActivateEntry, onSearchQueryChange, onSortModeChange, onToggleSection, onOpenSelected, + onFetchPreviewFrame, onRefresh, onClose, + onResizeMouseDown, + onResizeHeightMouseDown, }: { entries: ProjectedAssetLibraryEntry[] selectedEntryId: string | null @@ -384,13 +428,23 @@ function AssetLibraryPopover({ searchQuery: string sortMode: AssetLibrarySortMode collapsedSectionKeys: string[] - onSelectEntry: (entryId: string) => void + /** Data URLs keyed by workspacePath, populated lazily as thumbnails load. */ + thumbnails: Record + /** Preview clip metadata keyed by workspacePath; empty until a preview manifest exists for that asset. */ + previews: Record + panelWidth: number + panelHeight: number + /** A row click both selects and, when the entry is openable, opens it immediately — no second confirming click. */ + onActivateEntry: (entryId: string) => void onSearchQueryChange: (value: string) => void onSortModeChange: (value: AssetLibrarySortMode) => void onToggleSection: (sectionKey: string) => void onOpenSelected: () => void + onFetchPreviewFrame: (workspacePath: string, clip: string) => Promise onRefresh: () => void onClose: () => void + onResizeMouseDown: (event: React.MouseEvent) => void + onResizeHeightMouseDown: (event: React.MouseEvent) => void }) { const scopeGroups = filterAssetLibraryScopeGroups(entries, searchQuery, sortMode) const visibleEntryIds = new Set(scopeGroups.flatMap((scopeGroup) => scopeGroup.entryGroups.flatMap((group) => group.entries.map((entry) => entry.id)))) @@ -398,6 +452,7 @@ function AssetLibraryPopover({ ? entries.find((entry) => entry.id === selectedEntryId) ?? null : null const normalizedSearchQuery = searchQuery.trim() + const hasActiveSearch = normalizedSearchQuery.length > 0 const openDisabled = !selectedEntry || !isAssetLibraryEntryOpenable(selectedEntry) || loading || opening const selectedMessage = selectedEntry ? describeAssetLibraryOpenability(selectedEntry) @@ -409,9 +464,10 @@ function AssetLibraryPopover({
-
+

Workspace library

Select a workspace asset and open the supported source in Generate.

@@ -425,16 +481,34 @@ function AssetLibraryPopover({
+ {/* Resize handle — drag to widen/narrow the library panel; size is persisted. */} +
+ + {/* Resize handle — drag to grow/shrink the library panel; size is persisted. */} +
+ -
+
onSearchQueryChange(event.target.value)} placeholder="Search by name, path, scope, or capability" - className="bg-zinc-800 border border-zinc-700 rounded-lg px-2.5 py-1.5 text-xs text-zinc-200 w-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-400" + className="appearance-none bg-zinc-800 border border-zinc-700 rounded-lg px-2.5 py-1.5 text-xs text-zinc-200 w-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-400" />
@@ -462,15 +536,15 @@ function AssetLibraryPopover({
{loading ? ( -

Loading workspace assets…

+

Loading workspace assets…

) : scopeGroups.length === 0 && !normalizedSearchQuery ? ( -

No workspace assets are indexed yet.

+

No workspace assets are indexed yet.

) : scopeGroups.length === 0 ? ( -

{`No workspace assets match “${normalizedSearchQuery}”.`}

+

{`No workspace assets match “${normalizedSearchQuery}”.`}

) : ( -
+
{scopeGroups.map((scopeGroup) => { - const scopeExpanded = !collapsedSectionKeys.includes(scopeGroup.sectionKey) + const scopeExpanded = isAssetLibrarySectionExpanded(collapsedSectionKeys, scopeGroup.sectionKey, hasActiveSearch) const scopeRegionId = `asset-library-${scopeGroup.sectionKey.replace(/[^a-z0-9-]+/gi, '-')}` return (
@@ -479,7 +553,8 @@ function AssetLibraryPopover({ aria-expanded={scopeExpanded} aria-controls={scopeRegionId} onClick={() => onToggleSection(scopeGroup.sectionKey)} - className="flex w-full items-center justify-between gap-2 px-3 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-400" + disabled={hasActiveSearch} + className="flex w-full items-center justify-between gap-2 px-3 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-400 disabled:opacity-50 disabled:pointer-events-none" > {scopeGroup.sourceScopeLabel} {scopeExpanded ? 'Hide' : 'Show'} @@ -487,7 +562,7 @@ function AssetLibraryPopover({ {scopeExpanded && (
{scopeGroup.entryGroups.map((group) => { - const capabilityExpanded = !collapsedSectionKeys.includes(group.sectionKey) + const capabilityExpanded = isAssetLibrarySectionExpanded(collapsedSectionKeys, group.sectionKey, hasActiveSearch) const capabilityRegionId = `asset-library-${group.sectionKey.replace(/[^a-z0-9-]+/gi, '-')}` return (
@@ -496,34 +571,26 @@ function AssetLibraryPopover({ aria-expanded={capabilityExpanded} aria-controls={capabilityRegionId} onClick={() => onToggleSection(group.sectionKey)} - className="flex w-full items-center justify-between gap-2 px-4 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-400" + disabled={hasActiveSearch} + className="flex w-full items-center justify-between gap-2 px-4 py-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-400 disabled:opacity-50 disabled:pointer-events-none" > {group.capabilityLabel} {capabilityExpanded ? 'Hide' : 'Show'} {capabilityExpanded && (
- {group.entries.map((entry) => { - const selected = entry.id === selectedEntryId - return ( - - ) - })} + {group.entries.map((entry) => ( + onActivateEntry(entry.id)} + onFetchPreviewFrame={onFetchPreviewFrame} + /> + ))}
)}
@@ -537,7 +604,7 @@ function AssetLibraryPopover({
)} -
+

{selectedMessage}

{error &&

{error}

}
@@ -547,7 +614,7 @@ function AssetLibraryPopover({ onClick={onOpenSelected} disabled={openDisabled} aria-label="Open selected asset" - className="px-3 py-2 bg-violet-600 hover:bg-violet-500 disabled:bg-zinc-700 disabled:text-zinc-500 text-white text-xs rounded-lg transition-colors font-medium" + className="shrink-0 px-3 py-2 bg-violet-600 hover:bg-violet-500 disabled:bg-zinc-700 disabled:text-zinc-500 text-white text-xs rounded-lg transition-colors font-medium" > {opening ? 'Opening…' : 'Open selected asset'} @@ -555,13 +622,129 @@ function AssetLibraryPopover({ ) } +/** + * One Library row. A click both selects and (when openable) opens the asset — + * the "Open selected asset" button stays as a secondary affordance, not the + * only path. Hovering swaps the static thumbnail for a looping preview clip, + * lazily fetched over the same thumbnail IPC call, when one exists; with no + * preview manifest yet, `previewClips` is empty and the row behaves exactly + * as it did before — no extra fetches, no hover swap, no cycle control. + */ +function AssetLibraryEntryRow({ + entry, + selected, + disabled, + thumbnailDataUrl, + previewClips, + onActivate, + onFetchPreviewFrame, +}: { + entry: ProjectedAssetLibraryEntry + selected: boolean + disabled: boolean + thumbnailDataUrl: string | undefined + previewClips: AssetLibraryPreviewClip[] + onActivate: () => void + onFetchPreviewFrame: (workspacePath: string, clip: string) => Promise +}) { + const [hovered, setHovered] = useState(false) + const [clipIndex, setClipIndex] = useState(0) + const [previewFrames, setPreviewFrames] = useState>({}) + const mountedRef = useRef(true) + useEffect(() => () => { mountedRef.current = false }, []) + + const activeClip = previewClips.length > 0 ? previewClips[clipIndex % previewClips.length] : undefined + const activeFrameUrl = activeClip ? previewFrames[activeClip.clip] : undefined + + // Lazy, hover-triggered, and cached per clip for this row's lifetime — a + // second hover (or cycling back to a clip already seen) never re-fetches. + useEffect(() => { + if (!hovered || !activeClip || previewFrames[activeClip.clip]) return + void onFetchPreviewFrame(entry.workspacePath, activeClip.clip).then((dataUrl) => { + if (mountedRef.current && dataUrl) { + setPreviewFrames((current) => ({ ...current, [activeClip.clip]: dataUrl })) + } + }) + }, [hovered, activeClip, entry.workspacePath, previewFrames, onFetchPreviewFrame]) + + function cycleClip(step: 1 | -1, event: React.MouseEvent | React.KeyboardEvent) { + event.preventDefault() + event.stopPropagation() + setClipIndex((current) => (current + step + previewClips.length) % previewClips.length) + } + + function handleCycleKeyDown(step: 1 | -1, event: React.KeyboardEvent) { + if (event.key !== 'Enter' && event.key !== ' ') return + cycleClip(step, event) + } + + const displayedThumbnailUrl = hovered && activeFrameUrl ? activeFrameUrl : thumbnailDataUrl + + return ( + + ) +} + // --------------------------------------------------------------------------- // GeneratePage // --------------------------------------------------------------------------- export default function GeneratePage(): JSX.Element { const [unloadStatus, setUnloadStatus] = useState<'idle' | 'done'>('idle') - const [panelWidth, setPanelWidth] = useState(DEFAULT_WIDTH) + const [panelWidth, setPanelWidth] = useState(() => getStoredPanelWidth()) const [openPanel, setOpenPanel] = useState(null) const [decimating, setDecimating] = useState(false) const [smoothing, setSmoothing] = useState(false) @@ -575,8 +758,14 @@ export default function GeneratePage(): JSX.Element { const [librarySearchQuery, setLibrarySearchQuery] = useState('') const [librarySortMode, setLibrarySortMode] = useState('type') const [libraryCollapsedSectionKeys, setLibraryCollapsedSectionKeys] = useState(() => getDefaultAssetLibraryCollapsedSectionKeys()) + const [libraryThumbnails, setLibraryThumbnails] = useState>({}) + const [libraryPreviews, setLibraryPreviews] = useState>({}) + const [libraryPanelWidth, setLibraryPanelWidth] = useState(() => getStoredAssetLibraryPanelWidth()) + const [libraryPanelHeight, setLibraryPanelHeight] = useState(() => getStoredAssetLibraryPanelHeight()) const [gizmoMode, setGizmoMode] = useState<'translate' | 'rotate' | 'scale' | null>(null) const dragging = useRef(false) + const libraryPanelDragging = useRef(false) + const libraryPanelHeightDragging = useRef(false) // Populated by Viewer3D — undoes the latest live gizmo transform, if any. const gizmoUndoRef = useRef<(() => boolean) | null>(null) @@ -640,6 +829,21 @@ export default function GeneratePage(): JSX.Element { // eslint-disable-next-line react-hooks/exhaustive-deps -- lazy-load guarded by loaded/loading flags }, [openPanel, libraryLoaded, libraryLoading]) + // Persist the library panel's width so a manual resize survives app restarts. + useEffect(() => { + storeAssetLibraryPanelWidth(libraryPanelWidth) + }, [libraryPanelWidth]) + + // Persist the library panel's height so a manual resize survives app restarts. + useEffect(() => { + storeAssetLibraryPanelHeight(libraryPanelHeight) + }, [libraryPanelHeight]) + + // Persist the generate options panel's width so a manual resize survives app restarts. + useEffect(() => { + storePanelWidth(panelWidth) + }, [panelWidth]) + async function handleUnloadAll() { await window.electron.model.unloadAll() setUnloadStatus('done') @@ -710,6 +914,7 @@ export default function GeneratePage(): JSX.Element { ? current : result.entries.find(isAssetLibraryEntryOpenable)?.id ?? result.entries[0]?.id ?? null) setLibraryLoaded(true) + void loadLibraryThumbnails(result.entries) } catch (err) { setLibraryLoaded(false) setLibraryEntries([]) @@ -720,21 +925,61 @@ export default function GeneratePage(): JSX.Element { } } - async function handleOpenSelectedLibraryEntry() { - const selectedEntry = libraryEntries.find((entry) => entry.id === librarySelectedEntryId) ?? null - if (!selectedEntry) { + // Thumbnails are best-effort: only .glb/.gltf entries can have a rendered + // .thumb.png, and a missing one is silently skipped rather than surfaced. + // The same request also carries preview clip metadata when a preview + // manifest exists for that asset — most entries won't have one yet, and + // those are simply absent from libraryPreviews. + async function loadLibraryThumbnails(entries: ProjectedAssetLibraryEntry[]) { + type ThumbnailFetchResult = { workspacePath: string, dataUrl: string | null, previews: AssetLibraryPreviewClip[] } + const candidates = entries.filter((entry) => entry.previewKind === '3d-model') + const results: ThumbnailFetchResult[] = await Promise.all(candidates.map(async (entry) => { + const result = await assetLibraryService.thumbnail({ workspacePath: entry.workspacePath }) + return { + workspacePath: entry.workspacePath, + dataUrl: result.success ? result.dataUrl : null, + previews: result.success ? result.previews ?? [] : [], + } + })) + setLibraryThumbnails(Object.fromEntries( + results + .filter((result): result is ThumbnailFetchResult & { dataUrl: string } => result.dataUrl !== null) + .map((result) => [result.workspacePath, result.dataUrl]), + )) + setLibraryPreviews(Object.fromEntries( + results.filter((result) => result.previews.length > 0).map((result) => [result.workspacePath, result.previews]), + )) + } + + // Fetches one looping preview clip's WebP, lazily, over the same thumbnail + // IPC call the static thumbnails use. A miss (clip removed, file unreadable) + // resolves to null rather than throwing, so a row can just keep its static + // thumbnail. + const fetchLibraryPreviewFrame = useCallback(async (workspacePath: string, clip: string): Promise => { + try { + const result = await assetLibraryService.thumbnail({ workspacePath, previewClip: clip }) + return result.success ? result.dataUrl : null + } catch { + return null + } + }, [assetLibraryService]) + + // Shared by both the "Open selected asset" button and a direct row click — + // a row activation selects first, then opens through this same path. + async function openLibraryEntry(entry: ProjectedAssetLibraryEntry | null) { + if (!entry) { setLibraryError('Select an asset before opening it in Generate.') return } - if (!isAssetLibraryEntryOpenable(selectedEntry)) { - setLibraryError(describeAssetLibraryOpenability(selectedEntry)) + if (!isAssetLibraryEntryOpenable(entry)) { + setLibraryError(describeAssetLibraryOpenability(entry)) return } setLibraryOpening(true) setLibraryError(null) try { - const result = await assetLibraryService.open(buildAssetLibraryOpenRequest(selectedEntry)) + const result = await assetLibraryService.open(buildAssetLibraryOpenRequest(entry)) if (!result.success) { setLibraryError(result.error.message) return @@ -745,7 +990,7 @@ export default function GeneratePage(): JSX.Element { setLibraryError(describeAssetLibraryOpenability(result.entry)) return } - setLibraryEntries((currentEntries) => currentEntries.map((entry) => entry.id === result.entry.id ? result.entry : entry)) + setLibraryEntries((currentEntries) => currentEntries.map((candidate) => candidate.id === result.entry.id ? result.entry : candidate)) setLibrarySelectedEntryId(result.entry.id) setCurrentJob(selection.job) pushMeshUrl(selection.historyUrl) @@ -757,6 +1002,21 @@ export default function GeneratePage(): JSX.Element { } } + async function handleOpenSelectedLibraryEntry() { + const selectedEntry = libraryEntries.find((entry) => entry.id === librarySelectedEntryId) ?? null + await openLibraryEntry(selectedEntry) + } + + // A single click on a row both selects and opens it — no second click on + // "Open selected asset" required. Non-openable entries still get selected, + // surfacing the same "why not" message they always have. + async function handleActivateLibraryEntry(entryId: string) { + setLibraryError(null) + setLibrarySelectedEntryId(entryId) + const entry = libraryEntries.find((candidate) => candidate.id === entryId) ?? null + await openLibraryEntry(entry) + } + async function handleSmooth(iterations: number) { if (!currentJob?.outputUrl) return setSmoothing(true) @@ -795,7 +1055,7 @@ export default function GeneratePage(): JSX.Element { const onMouseMove = (ev: MouseEvent) => { if (!dragging.current) return - setPanelWidth((w) => Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, w + ev.movementX))) + setPanelWidth((w) => clampPanelWidth(w + ev.movementX)) } const onMouseUp = () => { dragging.current = false @@ -806,16 +1066,54 @@ export default function GeneratePage(): JSX.Element { window.addEventListener('mouseup', onMouseUp) }, []) + const onLibraryPanelResizeMouseDown = useCallback((e: React.MouseEvent) => { + e.preventDefault() + libraryPanelDragging.current = true + + const onMouseMove = (ev: MouseEvent) => { + if (!libraryPanelDragging.current) return + setLibraryPanelWidth((w) => clampAssetLibraryPanelWidth(w + ev.movementX)) + } + const onMouseUp = () => { + libraryPanelDragging.current = false + window.removeEventListener('mousemove', onMouseMove) + window.removeEventListener('mouseup', onMouseUp) + } + window.addEventListener('mousemove', onMouseMove) + window.addEventListener('mouseup', onMouseUp) + }, []) + + const onLibraryPanelResizeHeightMouseDown = useCallback((e: React.MouseEvent) => { + e.preventDefault() + libraryPanelHeightDragging.current = true + + const onMouseMove = (ev: MouseEvent) => { + if (!libraryPanelHeightDragging.current) return + setLibraryPanelHeight((h) => clampAssetLibraryPanelHeight(h + ev.movementY)) + } + const onMouseUp = () => { + libraryPanelHeightDragging.current = false + window.removeEventListener('mousemove', onMouseMove) + window.removeEventListener('mouseup', onMouseUp) + } + window.addEventListener('mousemove', onMouseMove) + window.addEventListener('mouseup', onMouseUp) + }, []) + return ( <>
- {/* Resize handle */} + {/* Resize handle — drag to widen/narrow the generate options panel; size is persisted. */}
@@ -929,16 +1227,20 @@ export default function GeneratePage(): JSX.Element { searchQuery={librarySearchQuery} sortMode={librarySortMode} collapsedSectionKeys={libraryCollapsedSectionKeys} - onSelectEntry={(entryId) => { - setLibraryError(null) - setLibrarySelectedEntryId(entryId) - }} + thumbnails={libraryThumbnails} + previews={libraryPreviews} + panelWidth={libraryPanelWidth} + panelHeight={libraryPanelHeight} + onActivateEntry={(entryId) => { void handleActivateLibraryEntry(entryId) }} onSearchQueryChange={setLibrarySearchQuery} onSortModeChange={setLibrarySortMode} onToggleSection={(sectionKey) => setLibraryCollapsedSectionKeys((current) => toggleAssetLibrarySectionKey(current, sectionKey))} onOpenSelected={() => { void handleOpenSelectedLibraryEntry() }} + onFetchPreviewFrame={fetchLibraryPreviewFrame} onRefresh={() => { void loadLibraryEntries() }} onClose={() => setOpenPanel(null)} + onResizeMouseDown={onLibraryPanelResizeMouseDown} + onResizeHeightMouseDown={onLibraryPanelResizeHeightMouseDown} /> )}
diff --git a/src/areas/generate/assetLibraryService.test.ts b/src/areas/generate/assetLibraryService.test.ts index 9e7938c4..6a2bda1c 100644 --- a/src/areas/generate/assetLibraryService.test.ts +++ b/src/areas/generate/assetLibraryService.test.ts @@ -50,6 +50,7 @@ test('renderer service delegates safe IPC calls and normalizes returned entries' }), read: async () => ({ success: false, error: { code: 'missing', message: 'Missing' } }), open: async (request) => { openRequest = request; return { success: false, error: { code: 'missing', message: 'Missing' } } }, + thumbnail: async () => ({ success: false }), }) const result = await service.list() @@ -58,3 +59,38 @@ test('renderer service delegates safe IPC calls and normalizes returned entries' await service.open({ workspacePath: 'Workflows/hero.landmarks.v1.json', sourceWorkspacePath: 'Workflows/hero.glb' }) assert.deepEqual(openRequest, { workspacePath: 'Workflows/hero.landmarks.v1.json', sourceWorkspacePath: 'Workflows/hero.glb' }) }) + +test('renderer service validates thumbnail requests before IPC and never surfaces an error', async () => { + let invoked = false + const service = createAssetLibraryService({ + list: async () => ({ success: true, entries: [] }), + read: async () => ({ success: false, error: { code: 'unexpected', message: 'should not run' } }), + open: async () => ({ success: false, error: { code: 'unexpected', message: 'should not run' } }), + thumbnail: async () => { invoked = true; return { success: true, dataUrl: 'data:image/png;base64,ok' } }, + }) + + const unsafe = await service.thumbnail({ workspacePath: '../escape.glb' }) + assert.deepEqual(unsafe, { success: false }) + assert.equal(invoked, false) + + const safe = await service.thumbnail({ workspacePath: 'Exports/hero.glb' }) + assert.deepEqual(safe, { success: true, dataUrl: 'data:image/png;base64,ok' }) + assert.equal(invoked, true) +}) + +test('renderer service forwards previewClip through to the thumbnail IPC call unchanged', async () => { + let receivedRequest: unknown = null + const service = createAssetLibraryService({ + list: async () => ({ success: true, entries: [] }), + read: async () => ({ success: false, error: { code: 'read-failed', message: 'should not run' } }), + open: async () => ({ success: false, error: { code: 'read-failed', message: 'should not run' } }), + thumbnail: async (request) => { + receivedRequest = request + return { success: true, dataUrl: 'data:image/webp;base64,ok', previews: [{ clip: 'walk', duration: 0.8 }] } + }, + }) + + const result = await service.thumbnail({ workspacePath: 'Exports/hero.glb', previewClip: 'walk' }) + assert.deepEqual(receivedRequest, { workspacePath: 'Exports/hero.glb', previewClip: 'walk' }) + assert.deepEqual(result, { success: true, dataUrl: 'data:image/webp;base64,ok', previews: [{ clip: 'walk', duration: 0.8 }] }) +}) diff --git a/src/areas/generate/assetLibraryService.ts b/src/areas/generate/assetLibraryService.ts index 38738579..5c18d49d 100644 --- a/src/areas/generate/assetLibraryService.ts +++ b/src/areas/generate/assetLibraryService.ts @@ -5,6 +5,8 @@ import type { AssetLibraryOpenResult, AssetLibraryReadRequest, AssetLibraryReadResult, + AssetLibraryThumbnailRequest, + AssetLibraryThumbnailResult, } from '../../shared/types/assetLibrary' import { projectAssetLibraryEntry, type ProjectedAssetLibraryEntry } from './assetLibraryProjection' @@ -12,6 +14,7 @@ export interface AssetLibraryPreloadApi { list: () => Promise read: (request: AssetLibraryReadRequest) => Promise open: (request: AssetLibraryOpenRequest) => Promise + thumbnail: (request: AssetLibraryThumbnailRequest) => Promise } export type ProjectedAssetLibraryListResult = @@ -60,6 +63,12 @@ export function createAssetLibraryService(api: AssetLibraryPreloadApi) { if (!result.success) return result return { success: true, entry: projectAssetLibraryEntry(result.entry) } }, + // A missing/invalid thumbnail is never an error the UI needs to show — the + // Library list just falls back to its text-only row. + async thumbnail(request: AssetLibraryThumbnailRequest): Promise { + if (validateWorkspacePath(request.workspacePath)) return { success: false } + return api.thumbnail(request) + }, } } diff --git a/src/areas/generate/assetLibraryUi.test.ts b/src/areas/generate/assetLibraryUi.test.ts index e6b9fbca..70013acc 100644 --- a/src/areas/generate/assetLibraryUi.test.ts +++ b/src/areas/generate/assetLibraryUi.test.ts @@ -3,12 +3,19 @@ import test from 'node:test' import { buildAssetLibraryOpenRequest, + clampAssetLibraryPanelHeight, + clampAssetLibraryPanelWidth, createAssetLibraryOpenJob, describeAssetLibraryOpenability, filterAssetLibraryScopeGroups, getDefaultAssetLibraryCollapsedSectionKeys, + getStoredAssetLibraryPanelHeight, + getStoredAssetLibraryPanelWidth, isAssetLibraryEntryOpenable, + isAssetLibrarySectionExpanded, resolveOpenPanelAfterLibrarySelection, + storeAssetLibraryPanelHeight, + storeAssetLibraryPanelWidth, toggleAssetLibrarySectionKey, type AssetLibrarySortMode, type GenerateOpenPanel, @@ -123,3 +130,40 @@ test('builds linked-source open requests and import jobs for safe sidecars', () assert.equal(selection?.historyUrl, '/workspace/Workflows/run/hero.glb') assert.equal(selection?.job.outputUrl, '/workspace/Workflows/run/hero.glb') }) + +test('Library panel width clamps to sane bounds and degrades silently without a localStorage', () => { + assert.equal(clampAssetLibraryPanelWidth(0), 380) + assert.equal(clampAssetLibraryPanelWidth(9999), 960) + assert.equal(clampAssetLibraryPanelWidth(700), 700) + // A prior session's narrow, dragged-down width must clamp back up to the new floor. + assert.equal(clampAssetLibraryPanelWidth(280), 380) + // node --test has no `localStorage` global — both helpers must fall back rather than throw. + assert.equal(getStoredAssetLibraryPanelWidth(), 640) + assert.doesNotThrow(() => storeAssetLibraryPanelWidth(700)) +}) + +test('Library panel height clamps to sane bounds and degrades silently without a localStorage', () => { + assert.equal(clampAssetLibraryPanelHeight(0), 280) + assert.equal(clampAssetLibraryPanelHeight(9999), 1000) + assert.equal(clampAssetLibraryPanelHeight(500), 500) + // node --test has no `localStorage` global — both helpers must fall back rather than throw. + assert.equal(getStoredAssetLibraryPanelHeight(), 860) + assert.doesNotThrow(() => storeAssetLibraryPanelHeight(500)) +}) + +test('a live search always shows matched sections, and clearing it falls back to the untouched collapsed-key state', () => { + const collapsed = ['scope:workflows', 'capability:workflows:mesh'] + + // Nothing typed yet: rendering follows the real collapsed-key list. + assert.equal(isAssetLibrarySectionExpanded(collapsed, 'scope:workflows', false), false) + assert.equal(isAssetLibrarySectionExpanded(collapsed, 'scope:exports', false), true) + + // A live search forces every visible (already-filtered-to-matches) section open, + // regardless of what's actually in collapsedSectionKeys. + assert.equal(isAssetLibrarySectionExpanded(collapsed, 'scope:workflows', true), true) + assert.equal(isAssetLibrarySectionExpanded(collapsed, 'capability:workflows:mesh', true), true) + + // Clearing the query (hasActiveSearch: false) restores exactly the prior state — + // collapsedSectionKeys was never mutated by the search itself. + assert.equal(isAssetLibrarySectionExpanded(collapsed, 'scope:workflows', false), false) +}) diff --git a/src/areas/generate/assetLibraryUi.ts b/src/areas/generate/assetLibraryUi.ts index 5e83e65a..03355e78 100644 --- a/src/areas/generate/assetLibraryUi.ts +++ b/src/areas/generate/assetLibraryUi.ts @@ -68,6 +68,21 @@ export function toggleAssetLibrarySectionKey(currentKeys: string[], sectionKey: : [...currentKeys, sectionKey] } +/** + * A section renders expanded either because the user left it expanded, or + * because a live search matched into it — search always wins so results are + * visible without clicking through "Show" first. Clearing the query falls + * straight back through to the untouched `collapsedSectionKeys`, so whatever + * was collapsed before searching stays collapsed after. + */ +export function isAssetLibrarySectionExpanded( + collapsedSectionKeys: string[], + sectionKey: string, + hasActiveSearch: boolean, +): boolean { + return hasActiveSearch || !collapsedSectionKeys.includes(sectionKey) +} + export function buildAssetLibraryOpenRequest(entry: ProjectedAssetLibraryEntry): AssetLibraryOpenRequest { const target = resolveAssetLibraryOpenTarget(entry) return target.kind === 'linked-source' @@ -168,6 +183,69 @@ export function resolveOpenPanelAfterLibrarySelection(currentPanel: GenerateOpen return currentPanel === 'library' ? 'library' : currentPanel } +// Wide enough that a 40px thumbnail, a readable name, its full workspace path, +// and its type badge all sit on one row without truncating for typical asset +// names — narrow (~280px) made the panel unusable even at full height. Raising +// the minimum (not just the default) also repairs the shape for anyone who +// already dragged a prior session's panel down toward the old, cramped floor. +export const ASSET_LIBRARY_PANEL_MIN_WIDTH = 380 +export const ASSET_LIBRARY_PANEL_MAX_WIDTH = 960 +export const ASSET_LIBRARY_PANEL_DEFAULT_WIDTH = 640 + +const ASSET_LIBRARY_PANEL_WIDTH_STORAGE_KEY = 'modly-library-panel-width' + +export function clampAssetLibraryPanelWidth(width: number): number { + return Math.min(ASSET_LIBRARY_PANEL_MAX_WIDTH, Math.max(ASSET_LIBRARY_PANEL_MIN_WIDTH, width)) +} + +/** Reads the user's saved Library panel width, falling back to the default when unset, invalid, or unreadable. */ +export function getStoredAssetLibraryPanelWidth(): number { + try { + const raw = Number(localStorage.getItem(ASSET_LIBRARY_PANEL_WIDTH_STORAGE_KEY)) + return Number.isFinite(raw) && raw > 0 ? clampAssetLibraryPanelWidth(raw) : ASSET_LIBRARY_PANEL_DEFAULT_WIDTH + } catch { + return ASSET_LIBRARY_PANEL_DEFAULT_WIDTH + } +} + +/** Persists the Library panel width so it survives app restarts. */ +export function storeAssetLibraryPanelWidth(width: number): void { + try { + localStorage.setItem(ASSET_LIBRARY_PANEL_WIDTH_STORAGE_KEY, String(width)) + } catch { + // Ignore quota/private-mode failures — the panel just won't remember its size. + } +} + +export const ASSET_LIBRARY_PANEL_MIN_HEIGHT = 280 +export const ASSET_LIBRARY_PANEL_MAX_HEIGHT = 1000 +export const ASSET_LIBRARY_PANEL_DEFAULT_HEIGHT = 860 + +const ASSET_LIBRARY_PANEL_HEIGHT_STORAGE_KEY = 'modly-library-panel-height' + +export function clampAssetLibraryPanelHeight(height: number): number { + return Math.min(ASSET_LIBRARY_PANEL_MAX_HEIGHT, Math.max(ASSET_LIBRARY_PANEL_MIN_HEIGHT, height)) +} + +/** Reads the user's saved Library panel height, falling back to the default when unset, invalid, or unreadable. */ +export function getStoredAssetLibraryPanelHeight(): number { + try { + const raw = Number(localStorage.getItem(ASSET_LIBRARY_PANEL_HEIGHT_STORAGE_KEY)) + return Number.isFinite(raw) && raw > 0 ? clampAssetLibraryPanelHeight(raw) : ASSET_LIBRARY_PANEL_DEFAULT_HEIGHT + } catch { + return ASSET_LIBRARY_PANEL_DEFAULT_HEIGHT + } +} + +/** Persists the Library panel height so it survives app restarts. */ +export function storeAssetLibraryPanelHeight(height: number): void { + try { + localStorage.setItem(ASSET_LIBRARY_PANEL_HEIGHT_STORAGE_KEY, String(height)) + } catch { + // Ignore quota/private-mode failures — the panel just won't remember its size. + } +} + function sortAssetLibraryEntries( entries: ProjectedAssetLibraryEntry[], sortMode: AssetLibrarySortMode, diff --git a/src/areas/generate/components/ChatPanel.tsx b/src/areas/generate/components/ChatPanel.tsx index 7618f75d..f9e49a2f 100644 --- a/src/areas/generate/components/ChatPanel.tsx +++ b/src/areas/generate/components/ChatPanel.tsx @@ -269,6 +269,8 @@ export default function ChatPanel(): JSX.Element { const updateCurrentJob = useAppStore((s) => s.updateCurrentJob) const pushMeshUrl = useAppStore((s) => s.pushMeshUrl) const undoMesh = useAppStore((s) => s.undoMesh) + const motionClips = useAppStore((s) => s.motionClips) + const activeClipIndex = useAppStore((s) => s.activeClipIndex) const workflows = useWorkflowsStore((s) => s.workflows) const saveWorkflow = useWorkflowsStore((s) => s.save) @@ -329,6 +331,10 @@ export default function ChatPanel(): JSX.Element { const ctx: Record = {} if (currentJob?.outputUrl) ctx.currentMeshPath = currentJob.outputUrl.replace('/workspace/', '') if (meshStats?.triangles) ctx.meshTriangles = meshStats.triangles + if (motionClips.length > 0) { + ctx.currentClipName = motionClips[Math.min(activeClipIndex, motionClips.length - 1)]?.name + ctx.availableClips = motionClips.map((c) => c.name) + } if (workflows.length > 0) ctx.workflows = workflows.map((w) => ({ id: w.id, name: w.name })) if (allExtensions.length > 0) ctx.extensions = allExtensions.map((e) => ({ id: e.id, name: e.name, input: e.input, output: e.output, diff --git a/src/areas/generate/components/MotionBar.tsx b/src/areas/generate/components/MotionBar.tsx new file mode 100644 index 00000000..293f2435 --- /dev/null +++ b/src/areas/generate/components/MotionBar.tsx @@ -0,0 +1,48 @@ +export interface MotionClip { + name: string +} + +interface MotionBarProps { + clips: MotionClip[] + activeIndex: number + onChange: (index: number) => void +} + +function clipLabel(clip: MotionClip, index: number): string { + return clip.name || `Motion ${index + 1}` +} + +/** Bottom-left overlay for scrubbing a rigged model's animation clips. */ +export function MotionBar({ clips, activeIndex, onChange }: MotionBarProps): JSX.Element | null { + if (clips.length === 0) return null + + if (clips.length === 1) { + return ( +
+ Playing + {clipLabel(clips[0], 0)} +
+ ) + } + + return ( +
+ Motion + + +
+ ) +} diff --git a/src/areas/generate/components/Viewer3D.tsx b/src/areas/generate/components/Viewer3D.tsx index 8cff822f..37927964 100644 --- a/src/areas/generate/components/Viewer3D.tsx +++ b/src/areas/generate/components/Viewer3D.tsx @@ -16,6 +16,7 @@ import SplatViewer, { type SplatViewerHandle } from './SplatViewer' import { useGeneration } from '@shared/hooks/useGeneration' import { useAppStore } from '@shared/stores/appStore' import { ViewerToolbar, type ViewMode } from './ViewerToolbar' +import { MotionBar, type MotionClip } from './MotionBar' import type { LightSettings } from '@shared/stores/appStore' import { DEFAULT_LIGHT_SETTINGS } from '@shared/stores/appStore' @@ -142,16 +143,67 @@ interface MeshModelProps { onStats: (stats: { vertices: number; triangles: number }) => void onSelect: () => void onObject: (obj: THREE.Object3D | null) => void + onClips: (clips: MotionClip[]) => void + clipIndex: number } -function MeshModel({ url, jobId, viewMode, selected, onStats, onSelect, onObject }: MeshModelProps): JSX.Element { +function MeshModel({ url, jobId, viewMode, selected, onStats, onSelect, onObject, onClips, clipIndex }: MeshModelProps): JSX.Element { const extension = url.split('?')[0]?.split('.').pop()?.toLowerCase() - const common = { url, jobId, viewMode, selected, onStats, onSelect, onObject } + const common = { url, jobId, viewMode, selected, onStats, onSelect, onObject, onClips, clipIndex } return extension === 'obj' ? : } function GltfMeshModel(props: MeshModelProps): JSX.Element { - const { scene } = useGLTF(props.url) + const gltf = useGLTF(props.url) + const { scene, animations } = gltf + const mixerRef = useRef(null) + const actionRef = useRef(null) + const { onClips, clipIndex } = props + + // Rigged models arrive with one or more clips; without a mixer they render + // frozen in bind pose, which reads as "the rig failed". The mixer lives for + // as long as this model does — clip switches below reuse it. + useEffect(() => { + if (!animations?.length) { + mixerRef.current = null + actionRef.current = null + return + } + const mixer = new THREE.AnimationMixer(scene) + mixerRef.current = mixer + return () => { + mixer.stopAllAction() + mixer.uncacheRoot(scene) + mixerRef.current = null + actionRef.current = null + } + }, [scene, animations]) + + // Tell the viewer which clips are available so it can render the motion bar. + useEffect(() => { + onClips(animations?.map((clip) => ({ name: clip.name })) ?? []) + // eslint-disable-next-line react-hooks/exhaustive-deps -- onClips is a stable callback + }, [animations]) + + // Switch to the selected clip, cross-fading so playback never hard-cuts. + useEffect(() => { + const mixer = mixerRef.current + if (!mixer || !animations?.length) return + const clip = animations[Math.min(clipIndex, animations.length - 1)] + const next = mixer.clipAction(clip) + next.reset().setLoop(THREE.LoopRepeat, Infinity) + const prev = actionRef.current + if (prev && prev !== next) { + prev.fadeOut(0.25) + next.fadeIn(0.25).play() + } else { + next.play() + } + actionRef.current = next + }, [animations, clipIndex]) + + useFrame((_state, delta) => mixerRef.current?.update(delta)) + return } @@ -815,6 +867,21 @@ export default function Viewer3D({ lightSettings = DEFAULT_LIGHT_SETTINGS, gizmo const [viewMode, setViewMode] = useState('solid') const [autoRotate, setAutoRotate] = useState(false) + const [clips, setClipsState] = useState([]) + const [activeClipIndex, setActiveClipIndexState] = useState(0) + const setStoreMotionClips = useAppStore((s) => s.setMotionClips) + const setStoreActiveClipIndex = useAppStore((s) => s.setActiveClipIndex) + // Mirror into appStore alongside the local state that actually drives + // playback, so sibling panels (e.g. ChatPanel) can read the current clip + // without this component handing over playback control. + const setClips = useCallback((c: MotionClip[]) => { + setClipsState(c) + setStoreMotionClips(c) + }, [setStoreMotionClips]) + const setActiveClipIndex = useCallback((i: number) => { + setActiveClipIndexState(i) + setStoreActiveClipIndex(i) + }, [setStoreActiveClipIndex]) const selected = useAppStore((s) => s.meshSelected) const setSelected = useAppStore((s) => s.setMeshSelected) const canvasRef = useRef(null) @@ -848,6 +915,8 @@ export default function Viewer3D({ lightSettings = DEFAULT_LIGHT_SETTINGS, gizmo setSelected(false) setViewMode('solid') setStoreMeshStats(null) + setClips([]) + setActiveClipIndex(0) // eslint-disable-next-line react-hooks/exhaustive-deps -- reset only when the model changes; setters are stable }, [modelUrl]) @@ -997,6 +1066,8 @@ export default function Viewer3D({ lightSettings = DEFAULT_LIGHT_SETTINGS, gizmo onStats={setStoreMeshStats} onSelect={() => setSelected(true)} onObject={setMeshObject} + onClips={setClips} + clipIndex={activeClipIndex} /> @@ -1043,12 +1114,15 @@ export default function Viewer3D({ lightSettings = DEFAULT_LIGHT_SETTINGS, gizmo /> )} - {/* Bottom-left stats overlay */} - {meshStats && ( -
-

- {meshStats.triangles.toLocaleString()} tri • {meshStats.vertices.toLocaleString()} verts -

+ {/* Bottom-left overlays — mesh stats and the motion bar */} + {(meshStats || clips.length > 0) && ( +
+ {meshStats && ( +

+ {meshStats.triangles.toLocaleString()} tri • {meshStats.vertices.toLocaleString()} verts +

+ )} +
)} diff --git a/src/areas/generate/components/WorkflowPanel.tsx b/src/areas/generate/components/WorkflowPanel.tsx index ffc774c7..dc7dc660 100644 --- a/src/areas/generate/components/WorkflowPanel.tsx +++ b/src/areas/generate/components/WorkflowPanel.tsx @@ -59,6 +59,50 @@ function mimeFromPath(p: string): string { return 'image/png' } +// ─── Tag suggestions ────────────────────────────────────────────────────────── + +const TAG_STOPWORDS = new Set([ + 'a', 'an', 'the', 'of', 'for', 'and', 'or', 'to', 'in', 'on', 'my', 'this', 'is', 'with', +]) + +const FIXED_TAG_VOCAB = [ + 'prop', 'character', 'creature', 'environment', 'weapon', + 'furniture', 'hero-asset', 'background', 'low-poly', 'stylized', 'realistic', +] + +const MAX_TAG_SUGGESTIONS = 10 + +/** Slugified words pulled from the typed name/project, plus a small fixed vocabulary — capped and deduped. */ +function suggestedTags(modelName: string, project: string): string[] { + const fromFields = `${modelName} ${project}` + .toLowerCase() + .split(/[^a-z0-9]+/) + .filter((word) => word.length > 1 && !TAG_STOPWORDS.has(word)) + + const seen = new Set() + const suggestions: string[] = [] + for (const tag of [...fromFields, ...FIXED_TAG_VOCAB]) { + if (!tag || seen.has(tag)) continue + seen.add(tag) + suggestions.push(tag) + if (suggestions.length >= MAX_TAG_SUGGESTIONS) break + } + return suggestions +} + +function parseTags(value: string): string[] { + return value.split(',').map((s) => s.trim()).filter(Boolean) +} + +/** Appends a tag to the comma-separated value, or removes it if already present. */ +function toggleTag(value: string, tag: string): string { + const tags = parseTags(value) + const i = tags.indexOf(tag) + if (i >= 0) tags.splice(i, 1) + else tags.push(tag) + return tags.join(', ') +} + // ─── Param field ────────────────────────────────────────────────────────────── const inputCls = 'w-full bg-zinc-800 border border-zinc-700/80 rounded-md px-2 py-1 text-[11px] text-zinc-200 focus:outline-none focus:border-accent/60' @@ -116,6 +160,17 @@ function ParamField({ param, value, onChange }: { value: number | string onChange: (v: number | string) => void }) { + if (param.multiline) { + return ( +