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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions apps/web/src/components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface NavProps {
fixed?: boolean;
/** 'topbar' (default) or the Webflow floating 'rail'. */
variant?: 'topbar' | 'rail';
/** Collapse the floating rail to its 56px icon dock initially. */
defaultCollapsed?: boolean;
}

const NAV_LINKS = [
Expand Down Expand Up @@ -138,8 +140,9 @@ function RailNav({
pathname,
rightSlot,
subtitle,
}: Pick<NavProps, 'rightSlot' | 'subtitle'> & { pathname: string }) {
const [collapsed, setCollapsed] = useState(false);
defaultCollapsed = false,
}: Pick<NavProps, 'rightSlot' | 'subtitle' | 'defaultCollapsed'> & { pathname: string }) {
const [collapsed, setCollapsed] = useState(defaultCollapsed);

useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
Expand All @@ -159,11 +162,11 @@ function RailNav({
aria-label="Primary"
>
<div className="uvai-rail-header">
<Link href="/" className="uvai-rail-brand">
<Link href="/" className="uvai-rail-brand" aria-label="UVAI Home">
<span className="uvai-rail-brand-mark">
<Film size={18} aria-hidden="true" />
</span>
<span className="text-lg">UVAI</span>
<span className="uvai-rail-brand-text text-lg">UVAI</span>
</Link>
<button
type="button"
Expand Down Expand Up @@ -215,12 +218,25 @@ function RailNav({
* Top bar (default) or Webflow floating rail. Obsidian default with a Webflow-style
* theme bar (light/dark + high contrast).
*/
export default function Nav({ rightSlot, subtitle, fixed = false, variant = 'topbar' }: NavProps) {
export default function Nav({
rightSlot,
subtitle,
fixed = false,
variant = 'topbar',
defaultCollapsed = false,
}: NavProps) {
const pathname = usePathname();
const [mobileOpen, setMobileOpen] = useState(false);

if (variant === 'rail') {
return <RailNav pathname={pathname} rightSlot={rightSlot} subtitle={subtitle} />;
return (
<RailNav
pathname={pathname}
rightSlot={rightSlot}
subtitle={subtitle}
defaultCollapsed={defaultCollapsed}
/>
);
}

return (
Expand Down
209 changes: 150 additions & 59 deletions apps/web/src/components/OneLoopStudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ import {
chaptersFromPack,
sopStepsFromPack,
} from '@/lib/emit-app-builder-sandbox';
import {
registerStudioWebMcpTools,
type StudioWebMcpPackSnapshot,
} from '@/lib/webmcp-studio-tools';

const FIXTURE = 'https://www.youtube.com/watch?v=auJzb1D-fag';

Expand All @@ -133,6 +137,14 @@ function getYouTubeId(url: string) {
return extractYouTubeId(url) || '';
}

function safeYouTubeWatchHref(rawId: string): string | null {
const match = /^[A-Za-z0-9_-]{6,20}$/.exec(rawId);
if (!match) return null;
const watchUrl = new URL('https://www.youtube.com/watch');
watchUrl.searchParams.set('v', match[0]);
return watchUrl.toString();
}

function toSpecBranch(videoId: string, stepId: string): string {
const slug = `${videoId || 'video'}-${stepId}`
.toLowerCase()
Expand Down Expand Up @@ -531,6 +543,7 @@ export default function OneLoopStudio({
}, [transcriptWorking]);

const videoId = useMemo(() => getYouTubeId(url || selected?.url || ''), [url, selected?.url]);
const watchHref = useMemo(() => safeYouTubeWatchHref(videoId), [videoId]);
// Destructure at the hook call so render reads booleans + a callback ref,
// not properties of an object that also carries refs (react-hooks/refs).
const { containerRef, ready: playerReady, failed: playerFailed, seekTo } =
Expand Down Expand Up @@ -912,19 +925,80 @@ export default function OneLoopStudio({
? selected.transcript.trim().split(/\s+/).length
: 0;

const webMcpSnapshot: StudioWebMcpPackSnapshot = useMemo(
() => ({
videoId: selected?.videoPack?.videoId ?? (videoId || null),
packId: selected?.videoPack?.packId ?? null,
sourceUrl: selected?.videoPack?.sourceUrl ?? (url.trim() || null),
sourceHash: selected?.videoPack?.sourceHash ?? null,
busy: transcriptWorking,
transcriptWordCount,
chapterCount: shellChapters.length,
actionCount: selected?.videoPack?.pack.action_items?.length ?? 0,
toolCount: packFormation.tools.length,
artifactCount: packFormation.artifacts.length,
}),
[
selected?.videoPack,
videoId,
url,
transcriptWorking,
transcriptWordCount,
shellChapters.length,
packFormation.tools.length,
packFormation.artifacts.length,
],
);
const webMcpSnapshotRef = useRef<StudioWebMcpPackSnapshot>(webMcpSnapshot);
const webMcpRunRef = useRef(runAnalysis);

useEffect(() => {
webMcpSnapshotRef.current = webMcpSnapshot;
}, [webMcpSnapshot]);

useEffect(() => {
webMcpRunRef.current = runAnalysis;
});

useEffect(() => {
const controller = new AbortController();
void registerStudioWebMcpTools(
{
getSnapshot: () => webMcpSnapshotRef.current,
onLoadUrl: (watchUrl, runImmediately) => {
setUrl(watchUrl);
if (runImmediately) {
void webMcpRunRef.current(watchUrl);
}
},
},
{ signal: controller.signal },
);
return () => {
controller.abort();
};
}, []);

return (
<div className="template-studio flex min-h-screen flex-col text-[var(--uvai-ink)]">
<Nav rightSlot={<StudioAuthNavLink />} />
<Nav variant="rail" defaultCollapsed rightSlot={<StudioAuthNavLink />} />

<StudioIdeShell
toolbar={
<>
<form onSubmit={analyze} className="flex min-w-0 flex-1 items-center gap-2" data-testid="studio-ide-url-form">
<form
onSubmit={analyze}
toolname="run_studio_video_analysis"
tooldescription="Extract transcript, numbered chapters, events, and runnable deliverables from a YouTube video URL in UVAI Studio"
className="flex min-w-0 flex-1 items-center gap-2"
data-testid="studio-ide-url-form"
>
<label className="sr-only" htmlFor="youtube-url">
YouTube URL
</label>
<input
id="youtube-url"
name="youtubeUrl"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder={FIXTURE}
Expand Down Expand Up @@ -1085,14 +1159,16 @@ export default function OneLoopStudio({
>
Retry player
</button>
<a
href={`https://www.youtube.com/watch?v=${videoId}`}
target="_blank"
rel="noreferrer"
className="uvai-btn"
>
Open on YouTube
</a>
{watchHref ? (
<a
href={watchHref}
target="_blank"
rel="noreferrer"
className="uvai-btn"
>
Open on YouTube
</a>
) : null}
</div>
) : null}
</div>
Expand All @@ -1104,57 +1180,72 @@ export default function OneLoopStudio({
</div>
)}
</div>
<ol
data-testid="studio-extraction-steps"
aria-label="Extraction progress"
className="studio-steps"
>
{(
[
{ id: 'pack', label: 'Pack' },
{ id: 'captions', label: 'Captions' },
{ id: 'transcript', label: 'Transcript' },
{ id: 'events', label: 'Events' },
{ id: 'ready', label: 'Ready' },
] as const
).map((step, idx) => {
const activeIdx =
transcriptStage.id === 'ready'
? 4
: transcriptStage.id === 'events'
? 3
: transcriptStage.id === 'transcript'
? 2
: transcriptStage.id === 'captions'
? 1
: 0;
const isDone =
!transcriptWorking &&
selected?.status !== 'failed' &&
Boolean(selected?.videoPack || selected?.transcript?.trim());
const isFailed = selected?.status === 'failed';
const stepState = isDone
? 'done'
: isFailed
? idx < activeIdx
? 'done'
: idx === activeIdx
? 'failed'
: 'idle'
: transcriptWorking
<div className="studio-steps-bar flex items-center justify-between gap-2">
<ol
data-testid="studio-extraction-steps"
aria-label="Extraction progress"
className="studio-steps min-w-0 flex-1"
>
{(
[
{ id: 'pack', label: 'Pack' },
{ id: 'captions', label: 'Captions' },
{ id: 'transcript', label: 'Transcript' },
{ id: 'events', label: 'Events' },
{ id: 'ready', label: 'Ready' },
] as const
).map((step, idx) => {
const activeIdx =
transcriptStage.id === 'ready'
? 4
: transcriptStage.id === 'events'
? 3
: transcriptStage.id === 'transcript'
? 2
: transcriptStage.id === 'captions'
? 1
: 0;
const isDone =
!transcriptWorking &&
selected?.status !== 'failed' &&
Boolean(selected?.videoPack || selected?.transcript?.trim());
const isFailed = selected?.status === 'failed';
const stepState = isDone
? 'done'
: isFailed
? idx < activeIdx
? 'done'
: idx === activeIdx
? 'active'
? 'failed'
: 'idle'
: 'idle';
return (
<li key={step.id} data-state={stepState} data-step={step.id}>
{step.label}
</li>
);
})}
</ol>
: transcriptWorking
? idx < activeIdx
? 'done'
: idx === activeIdx
? 'active'
: 'idle'
: 'idle';
return (
<li key={step.id} data-state={stepState} data-step={step.id}>
{step.label}
</li>
);
})}
</ol>
{watchHref ? (
<a
href={watchHref}
target="_blank"
rel="noreferrer"
aria-label="Trouble with this video? Watch it directly on YouTube"
title="Trouble with this video? Watch it directly on YouTube"
data-testid="studio-watch-on-youtube"
className="shrink-0 text-[11px] font-medium text-[var(--uvai-ink-soft)] underline-offset-2 hover:text-[var(--uvai-ink)] hover:underline"
>
YouTube ↗
</a>
) : null}
</div>
<div className="flex flex-col gap-3">
{selected?.videoPack ? (
<div className="uvai-card studio-pack-card p-4">
Expand Down Expand Up @@ -1255,9 +1346,9 @@ export default function OneLoopStudio({
}
chatPane={
<StudioIdeChat
videoId={selected?.videoPack?.videoId ?? videoId ?? null}
videoId={selected?.videoPack?.videoId ?? (videoId || null)}
packId={selected?.videoPack?.packId ?? null}
disabled={busy}
disabled={transcriptWorking}
/>
}
outputPane={
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/components/__tests__/Nav.template.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,22 @@ describe('Nav template routing semantics', () => {
expect(document.documentElement.dataset.contrast).toBe('normal');
expect(contrast.getAttribute('aria-pressed')).toBe('false');
});

it('supports Webflow floating rail defaultCollapsed with visible brand mark and ⌘/ toggle', () => {
usePathnameMock.mockReturnValue('/studio');
render(<Nav variant="rail" defaultCollapsed />);

const nav = screen.getByRole('navigation', { name: 'Primary' });
expect(nav.dataset.collapsed).toBe('true');
expect(screen.getByRole('link', { name: 'UVAI Home' }).getAttribute('href')).toBe('/');

const expand = screen.getByRole('button', { name: 'Expand sidebar' });
expect(expand.getAttribute('aria-expanded')).toBe('false');
fireEvent.click(expand);
expect(nav.dataset.collapsed).toBe('false');
expect(screen.getByRole('button', { name: 'Collapse sidebar' }).getAttribute('aria-expanded')).toBe('true');

fireEvent.keyDown(window, { key: '/', metaKey: true });
expect(nav.dataset.collapsed).toBe('true');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,13 @@ describe('StudioIdeChat plan interview chaining', () => {
expect(secondBody.planIntent).toBe(true);
expect(secondBody.planInterview).toEqual({ useCase: 'Build a safety checklist from the video' });
});

it('shows active extraction status instead of idle prompt while a video run is in progress', () => {
render(<StudioIdeChat videoId="6TrjBFW6EKg" packId={null} disabled />);
expect(screen.getByText('Extracting Video Pack…')).toBeTruthy();
expect(screen.queryByText('Run a video to start chatting')).toBeNull();
const input = screen.getByTestId('studio-ide-chat-input') as HTMLTextAreaElement;
expect(input.placeholder).toBe('Extracting video pack…');
expect(input.disabled).toBe(true);
});
});
9 changes: 8 additions & 1 deletion apps/web/src/components/home/HomePasteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export default function HomePasteForm() {
};

return (
<form onSubmit={onSubmit} className="home-composer-surface mx-auto w-full max-w-2xl" data-mode={mode}>
<form
onSubmit={onSubmit}
toolname="extract_youtube_video_pack"
tooldescription="Open UVAI Studio and extract a structured Video Pack, transcript, chapters, and agent workflow from a YouTube URL"
Comment thread
vercel[bot] marked this conversation as resolved.
Resolved
className="home-composer-surface mx-auto w-full max-w-2xl"
data-mode={mode}
>
<div className="home-composer-modes" role="group" aria-label="Focus">
{MODES.map((item) => (
<button
Expand All @@ -51,6 +57,7 @@ export default function HomePasteForm() {
<Link2 size={18} aria-hidden="true" className="template-source-icon" />
<input
id="home-youtube-url"
name="youtubeUrl"
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="https://www.youtube.com/watch?v=auJzb1D-fag"
Expand Down
Loading
Loading