Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: reuse URL-param, track-URL and provider-pin helpers in launch videos

[._.]/ Adam Eivy428b3c700f2e
diff --git a/client/src/components/apps/LaunchVideoPanel.jsx b/client/src/components/apps/LaunchVideoPanel.jsx
index cd9e7ae38f..a9327084f9 100644
--- a/client/src/components/apps/LaunchVideoPanel.jsx
+++ b/client/src/components/apps/LaunchVideoPanel.jsx
@@ -1,15 +1,17 @@
import { useEffect, useRef, useState } from 'react';
-import { Link, useSearchParams } from 'react-router';
+import { Link } from 'react-router';
import { Download } from 'lucide-react';
import Drawer from '../Drawer';
import ProviderModelSelector from '../ProviderModelSelector';
import useProviderModels from '../../hooks/useProviderModels';
import { useAsyncAction } from '../../hooks/useAsyncAction';
+import useUrlParams from '../../hooks/useUrlParams';
import { copyToClipboard } from '../../lib/clipboard';
import socket from '../../services/socket';
import { createAppLaunchVideo, getAppLaunchVideos } from '../../services/apiApps';
import { listPipelineMusicLibrary } from '../../services/apiPipeline';
-import { enabledProcessProviderFilter } from '../../utils/providerTypes';
+import { trackAudioUrl } from '../../services/apiTracks';
+import { enabledProcessProviderFilter } from '../../utils/providers';
import { formatBytes, formatDateTime, formatDurationSec } from '../../utils/formatters';
const inputClass = 'w-full rounded border border-port-border bg-port-bg p-2 text-port-text';
@@ -18,8 +20,8 @@ const videoUrl = video => `/data/videos/${encodeURIComponent(video.filename)}`;
const posterUrl = video => `/data/video-thumbnails/${encodeURIComponent(video.thumbnail)}`;
// The run is an agent task, so it takes the same provider/model/effort pin as
-// every other manual CoS dispatch. Mounted only while the drawer is open, so
-// the provider catalog is fetched on demand.
+// every other manual CoS dispatch. Drawer mounts it only while open, so the
+// provider catalog and music library are fetched on demand.
function LaunchVideoForm({ appId, onQueued }) {
const [tone, setTone] = useState('default');
const [direction, setDirection] = useState('');
@@ -47,14 +49,13 @@ function LaunchVideoForm({ appId, onQueued }) {
const [submit, running] = useAsyncAction(async () => {
if (submitting.current) return;
submitting.current = true;
- setError('');
await createAppLaunchVideo(appId, {
tone, direction, format, targetDurationSec: duration,
...(music ? { musicTrack } : {}),
...(selectedProviderId ? { provider: selectedProviderId } : {}),
...(selectedModel ? { model: selectedModel } : {}),
...(effort ? { effort } : {}),
- }, { silent: true }).then(onQueued, err => setError(err.message)).finally(() => { submitting.current = false; });
+ }, { silent: true }).then(onQueued).finally(() => { submitting.current = false; });
});
return <form className="space-y-4" onSubmit={event => { event.preventDefault(); submit(); }}>
@@ -88,15 +89,16 @@ function LaunchVideoForm({ appId, onQueued }) {
{!!tracks?.length && <ul className="max-h-80 space-y-2 overflow-y-auto">
{tracks.map((track, index) => {
const id = `launch-track-${index}`;
+ const name = track.label || track.filename;
return <li key={track.filename} className={`rounded border p-2 ${musicTrack === track.filename ? 'border-port-accent' : 'border-port-border'}`}>
<label htmlFor={id} className="flex cursor-pointer items-start gap-2">
<input id={id} type="radio" name="launch-track" required value={track.filename} checked={musicTrack === track.filename} onChange={() => setMusicTrack(track.filename)} className="mt-1" />
<span className="min-w-0">
- <span className="block truncate text-port-text">{track.label || track.filename}</span>
+ <span className="block truncate text-port-text">{name}</span>
<span className="block truncate font-mono text-xs text-gray-500">{track.filename} · {formatDateTime(track.updatedAt)} · {formatBytes(track.sizeBytes)}</span>
</span>
</label>
- <audio controls preload="none" className="mt-2 h-8 w-full" src={`/data/music/${encodeURIComponent(track.filename)}`} aria-label={`Preview ${track.label || track.filename}`} />
+ <audio controls preload="none" className="mt-2 h-8 w-full" src={trackAudioUrl(track.filename)} aria-label={`Preview ${name}`} />
</li>;
})}
</ul>}
@@ -107,16 +109,11 @@ function LaunchVideoForm({ appId, onQueued }) {
}
export default function LaunchVideoPanel({ app }) {
- const [search, setSearch] = useSearchParams();
+ const [search, updateParams] = useUrlParams();
const open = search.get('launchVideo') === 'true';
const [videos, setVideos] = useState([]);
const [error, setError] = useState('');
const [queued, setQueued] = useState(false);
- const setParam = (key, value) => setSearch(prev => {
- const next = new URLSearchParams(prev);
- if (value) next.set(key, value); else next.delete(key);
- return next;
- });
// The previewed take lives in the URL so a specific video is linkable.
const selected = videos.find(video => video.id === search.get('video')) ?? videos[0];
@@ -139,7 +136,7 @@ export default function LaunchVideoPanel({ app }) {
return <section className="rounded-lg border border-port-border bg-port-card p-4 space-y-3">
<div className="flex flex-wrap items-center justify-between gap-3">
<h2 className="font-semibold">Launch videos</h2>
- <button type="button" className={buttonClass} onClick={() => { setQueued(false); setParam('launchVideo', 'true'); }}>
+ <button type="button" className={buttonClass} onClick={() => { setQueued(false); updateParams({ launchVideo: 'true' }); }}>
{videos.length ? 'Make another launch video' : 'Make launch video'}
</button>
</div>
@@ -158,15 +155,15 @@ export default function LaunchVideoPanel({ app }) {
</div>}
{videos.length > 1 && <ul aria-label="Launch video takes" className="grid grid-cols-2 gap-2 sm:grid-cols-4 lg:grid-cols-6">
{videos.map(video => <li key={video.id}>
- <button type="button" aria-pressed={video.id === selected?.id} onClick={() => setParam('video', video.id)} className={`w-full overflow-hidden rounded border text-left ${video.id === selected?.id ? 'border-port-accent' : 'border-port-border'}`}>
+ <button type="button" aria-pressed={video.id === selected?.id} onClick={() => updateParams({ video: video.id }, { replace: true })} className={`w-full overflow-hidden rounded border text-left ${video.id === selected?.id ? 'border-port-accent' : 'border-port-border'}`}>
<img src={posterUrl(video)} alt="" loading="lazy" className="aspect-video w-full object-cover" />
<span className="block truncate p-1 text-xs text-port-text-muted">{formatDateTime(video.createdAt)}</span>
</button>
</li>)}
</ul>}
- <Drawer open={open} onClose={() => setParam('launchVideo', null)} title="Make launch video" size="md">
+ <Drawer open={open} onClose={() => updateParams({ launchVideo: null })} title="Make launch video" size="md">
{queued ? <div className="space-y-3"><p>Launch video queued. Closing this drawer leaves the run active.</p><Link className="text-port-accent" to="/cos/agents">Open CoS agents to follow or cancel the run</Link></div>
- : open && <LaunchVideoForm appId={app.id} onQueued={() => setQueued(true)} />}
+ : <LaunchVideoForm appId={app.id} onQueued={() => setQueued(true)} />}
</Drawer>
</section>;
}
diff --git a/client/src/components/apps/tabs/OverviewTab.jsx b/client/src/components/apps/tabs/OverviewTab.jsx
index dcc27cbb4d..c21c81d72a 100644
--- a/client/src/components/apps/tabs/OverviewTab.jsx
+++ b/client/src/components/apps/tabs/OverviewTab.jsx
@@ -124,6 +124,8 @@ export default function OverviewTab({ app, onRefresh }) {
navigate('/apps');
};
+ const launchVideoPath = `/apps/${encodeURIComponent(app.id)}/launch-video`;
+
return (
<div className="space-y-6">
<div className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-port-border bg-port-card p-4">
@@ -132,10 +134,10 @@ export default function OverviewTab({ app, onRefresh }) {
<p className="text-sm text-port-text-muted">Make a short launch video with any agent, then preview and download every take.</p>
</div>
<div className="flex flex-wrap gap-2">
- <Link to={`/apps/${encodeURIComponent(app.id)}/launch-video`} className="inline-flex items-center gap-2 rounded border border-port-border px-3 py-2 text-port-text hover:border-port-accent">
+ <Link to={launchVideoPath} className="inline-flex items-center gap-2 rounded border border-port-border px-3 py-2 text-port-text hover:border-port-accent">
<Clapperboard size={16} aria-hidden="true" />View launch videos
</Link>
- <Link to={`/apps/${encodeURIComponent(app.id)}/launch-video?launchVideo=true`} className="rounded bg-port-accent px-3 py-2 text-white">Make launch video</Link>
+ <Link to={`${launchVideoPath}?launchVideo=true`} className="rounded bg-port-accent px-3 py-2 text-white">Make launch video</Link>
</div>
</div>
{/* Capped width so key/value pairs stay legible. (JIRA config + the sprint
diff --git a/server/routes/apps/launchVideos.js b/server/routes/apps/launchVideos.js
index 2c6e2341bd..bc142ff495 100644
--- a/server/routes/apps/launchVideos.js
+++ b/server/routes/apps/launchVideos.js
@@ -3,7 +3,7 @@ import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
import { asyncHandler, ServerError } from '../../lib/errorHandler.js';
import { appLaunchVideoRequestSchema, validateRequest } from '../../lib/validation.js';
-import { createCosTaskSchema } from '../../lib/cosValidation.js';
+import { pullRequestProviderOverrideSchema } from '../../lib/cosValidation.js';
import { PATHS } from '../../lib/fileUtils.js';
import { PORTOS_API_URL } from '../../lib/portosUrls.js';
import { APP_LAUNCH_VIDEO_PROMPT } from '../../services/taskPromptDefaults/appLaunchVideo.js';
@@ -14,7 +14,7 @@ const router = Router();
// The agent pin shares every manual dispatch's provider/model/effort vocabulary.
// It picks WHO runs the task, so it stays out of the prompt's creative options.
const launchVideoTaskSchema = appLaunchVideoRequestSchema
- .extend(createCosTaskSchema.pick({ provider: true, model: true, effort: true }).shape);
+ .extend(pullRequestProviderOverrideSchema.shape);
// Enough history to browse every recent take without turning the media store
// into an unbounded per-app export.
const LAUNCH_VIDEO_LIST_LIMIT = 50;
@@ -54,8 +54,8 @@ router.get('/:id/launch-videos', loadApp, asyncHandler(async (req, res) => {
const { loadHistory } = await import('../../services/videoGen/history.js');
// Bounded projection of the existing media store, not a new run database.
const videos = (await loadHistory()).filter(item => item.launchVideo?.appId === req.loadedApp.id)
- .slice(0, LAUNCH_VIDEO_LIST_LIMIT).map(({ id, filename, thumbnail, createdAt, durationSec, width, height, launchVideo }) => ({
- id, filename, thumbnail, createdAt, durationSec, width, height, caption: launchVideo.caption,
+ .slice(0, LAUNCH_VIDEO_LIST_LIMIT).map(({ id, filename, thumbnail, createdAt, durationSec, launchVideo }) => ({
+ id, filename, thumbnail, createdAt, durationSec, caption: launchVideo.caption,
}));
res.json({ videos });
}));
diff --git a/server/routes/apps/launchVideos.test.js b/server/routes/apps/launchVideos.test.js
index 04bc79a707..d37e87677b 100644
--- a/server/routes/apps/launchVideos.test.js
+++ b/server/routes/apps/launchVideos.test.js
@@ -64,12 +64,12 @@ describe('user-triggered launch videos', () => {
it('returns a bounded app-only result projection and propagates storage failure', async () => {
loadHistory.mockResolvedValue([
{ id: 'other', launchVideo: { appId: 'other' } },
- ...Array.from({ length: 52 }, (_, n) => ({ id: `video-${n}`, filename: 'example.mp4', thumbnail: 'example.jpg', createdAt: '2026-01-01T00:00:00.000Z', durationSec: 20, width: 1920, height: 1080, prompt: 'not projected', launchVideo: { appId: 'example', caption: 'A clear plan.' } })),
+ ...Array.from({ length: 52 }, (_, n) => ({ id: `video-${n}`, filename: 'example.mp4', thumbnail: 'example.jpg', createdAt: '2026-01-01T00:00:00.000Z', durationSec: 20, prompt: 'not projected', launchVideo: { appId: 'example', caption: 'A clear plan.' } })),
]);
const response = await request(app).get('/api/apps/example/launch-videos');
expect(response.status).toBe(200);
expect(response.body.videos).toHaveLength(50);
- expect(response.body.videos[0]).toEqual({ id: 'video-0', filename: 'example.mp4', thumbnail: 'example.jpg', createdAt: '2026-01-01T00:00:00.000Z', durationSec: 20, width: 1920, height: 1080, caption: 'A clear plan.' });
+ expect(response.body.videos[0]).toEqual({ id: 'video-0', filename: 'example.mp4', thumbnail: 'example.jpg', createdAt: '2026-01-01T00:00:00.000Z', durationSec: 20, caption: 'A clear plan.' });
loadHistory.mockRejectedValue(new Error('Storage unavailable'));
expect((await request(app).get('/api/apps/example/launch-videos')).status).toBe(500);
});