Commit ·
ac3d272
1
Parent(s): 73b1ed7
Improve job approval UX with tabs, job URL, and message ordering
Browse files- Add tabbed panel for switching between Script and Logs views
- Show specific job URL from tool output (not generic jobs page link)
- Fix message ordering so final assistant response appears below approval box
- Persist logs in approval messages so users can access previous job logs
- Add View Script/View Logs buttons on completed approval cards
- Show job status and failure indicators in approval flow
- Panel tabs only clear on new job, not during approval continuation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Files changed (4)
1234567894 unmodified lines141516171819206 unmodified lines2728293031323334353637383940414243444579 unmodified lines1251261271281291301311321331341356 unmodified lines14214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317446 unmodified lines221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251import { useState, useCallback, useEffect } from 'react';import { Box, Typography, Button, TextField, IconButton } from '@mui/material';import SendIcon from '@mui/icons-material/Send';import OpenInNewIcon from '@mui/icons-material/OpenInNew';import CheckCircleIcon from '@mui/icons-material/CheckCircle';import CancelIcon from '@mui/icons-material/Cancel';import { useAgentStore } from '@/store/agentStore';import { useLayoutStore } from '@/store/layoutStore';import { useSessionStore } from '@/store/sessionStore';4 unmodified lines}export default function ApprovalFlow({ message }: ApprovalFlowProps) {const { setPanelContent, updateMessage } = useAgentStore();const { setRightPanelOpen, setLeftSidebarOpen } = useLayoutStore();const { activeSessionId } = useSessionStore();const [currentIndex, setCurrentIndex] = useState(0);6 unmodified linesconst { batch, status } = approvalData;// Extract logs from toolOutput if availablelet logsContent = '';let showLogsButton = false;if (message.toolOutput && message.toolOutput.includes('**Logs:**')) {const parts = message.toolOutput.split('**Logs:**');if (parts.length > 1) {const logsPart = parts[1].trim();const codeBlockMatch = logsPart.match(/```([\s\S]*?)```/);if (codeBlockMatch) {logsContent = codeBlockMatch[1].trim();showLogsButton = true;}}}79 unmodified linesconst getToolDescription = (toolName: string, args: any) => {if (toolName === 'hf_jobs') {return (<Typography variant="body2" sx={{ color: 'var(--muted-text)', flex: 1 }}>The agent wants to execute <Box component="span" sx={{ color: 'var(--accent-yellow)', fontWeight: 500 }}>hf_jobs</Box> on{' '}<Box component="span" sx={{ fontWeight: 500, color: 'var(--text)' }}>{args.hardware_flavor || 'default'}</Box> with a timeout of{' '}<Box component="span" sx={{ fontWeight: 500, color: 'var(--text)' }}>{args.timeout || '30m'}</Box></Typography>);}return (6 unmodified linesconst showCode = () => {const args = currentTool.arguments as any;if (currentTool.tool === 'hf_jobs' && args.script) {setPanelContent({title: 'Compute Job Script',content: args.script,language: 'python',parameters: args});setRightPanelOpen(true);setLeftSidebarOpen(false);} else {setPanelContent({title: `Tool: ${currentTool.tool}`,content: JSON.stringify(args, null, 2),language: 'json',parameters: args});setRightPanelOpen(true);setLeftSidebarOpen(false);}};const handleViewLogs = (e: React.MouseEvent) => {e.stopPropagation();setPanelContent({title: 'Job Logs',content: logsContent,language: 'text'});setRightPanelOpen(true);setLeftSidebarOpen(false);};46 unmodified lines<OpenInNewIcon sx={{ fontSize: 16, color: 'var(--muted-text)', opacity: 0.7 }} /></Box>{containsPushToHub && (<Typography variant="caption" sx={{ color: 'var(--accent-green)', fontSize: '0.75rem', opacity: 0.8, px: 0.5 }}>We've detected the result will be pushed to hub.</Typography>)}{showLogsButton && (<Buttonvariant="outlined"size="small"startIcon={<OpenInNewIcon />}onClick={handleViewLogs}sx={{alignSelf: 'flex-start',textTransform: 'none',borderColor: 'rgba(255,255,255,0.1)',color: 'var(--accent-primary)','&:hover': {borderColor: 'var(--accent-primary)',bgcolor: 'rgba(255,255,255,0.03)'}}}>View Logs</Button>)}{status === 'pending' && (123456789104 unmodified lines151617181920216 unmodified lines28293031323334353637383940414243444546474849505152535455565758596061626364656667686970717279 unmodified lines1521531541551561571581591601611621631646 unmodified lines17117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923046 unmodified lines277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400import { useState, useCallback, useEffect } from 'react';import { Box, Typography, Button, TextField, IconButton, Link } from '@mui/material';import SendIcon from '@mui/icons-material/Send';import OpenInNewIcon from '@mui/icons-material/OpenInNew';import CheckCircleIcon from '@mui/icons-material/CheckCircle';import CancelIcon from '@mui/icons-material/Cancel';import LaunchIcon from '@mui/icons-material/Launch';import { useAgentStore } from '@/store/agentStore';import { useLayoutStore } from '@/store/layoutStore';import { useSessionStore } from '@/store/sessionStore';4 unmodified lines}export default function ApprovalFlow({ message }: ApprovalFlowProps) {const { setPanelContent, setPanelTab, setActivePanelTab, clearPanelTabs, updateMessage } = useAgentStore();const { setRightPanelOpen, setLeftSidebarOpen } = useLayoutStore();const { activeSessionId } = useSessionStore();const [currentIndex, setCurrentIndex] = useState(0);6 unmodified linesconst { batch, status } = approvalData;// Parse toolOutput to extract job info (URL, status, logs)let logsContent = '';let showLogsButton = false;let jobUrl = '';let jobId = '';let jobStatus = '';let jobFailed = false;if (message.toolOutput) {// Extract job URL: **View at:** https://...const urlMatch = message.toolOutput.match(/\*\*View at:\*\*\s*(https:\/\/[^\s\n]+)/);if (urlMatch) {jobUrl = urlMatch[1];}// Extract job ID: **Job ID:** ...const idMatch = message.toolOutput.match(/\*\*Job ID:\*\*\s*([^\s\n]+)/);if (idMatch) {jobId = idMatch[1];}// Extract job status: **Final Status:** ...const statusMatch = message.toolOutput.match(/\*\*Final Status:\*\*\s*([^\n]+)/);if (statusMatch) {jobStatus = statusMatch[1].trim();jobFailed = jobStatus.toLowerCase().includes('error') || jobStatus.toLowerCase().includes('failed');}// Extract logsif (message.toolOutput.includes('**Logs:**')) {const parts = message.toolOutput.split('**Logs:**');if (parts.length > 1) {const logsPart = parts[1].trim();const codeBlockMatch = logsPart.match(/```([\s\S]*?)```/);if (codeBlockMatch) {logsContent = codeBlockMatch[1].trim();showLogsButton = true;}}}}79 unmodified linesconst getToolDescription = (toolName: string, args: any) => {if (toolName === 'hf_jobs') {return (<Box sx={{ flex: 1 }}><Typography variant="body2" sx={{ color: 'var(--muted-text)' }}>The agent wants to execute <Box component="span" sx={{ color: 'var(--accent-yellow)', fontWeight: 500 }}>hf_jobs</Box> on{' '}<Box component="span" sx={{ fontWeight: 500, color: 'var(--text)' }}>{args.hardware_flavor || 'default'}</Box> with a timeout of{' '}<Box component="span" sx={{ fontWeight: 500, color: 'var(--text)' }}>{args.timeout || '30m'}</Box></Typography></Box>);}return (6 unmodified linesconst showCode = () => {const args = currentTool.arguments as any;if (currentTool.tool === 'hf_jobs' && args.script) {// Clear existing tabs and set up script tab (and logs if available)clearPanelTabs();setPanelTab({id: 'script',title: 'Script',content: args.script,language: 'python',parameters: args});// If logs are available (job completed), also add logs tabif (logsContent) {setPanelTab({id: 'logs',title: 'Logs',content: logsContent,language: 'text'});}setActivePanelTab('script');setRightPanelOpen(true);setLeftSidebarOpen(false);} else {setPanelContent({title: `Tool: ${currentTool.tool}`,content: JSON.stringify(args, null, 2),language: 'json',parameters: args});setRightPanelOpen(true);setLeftSidebarOpen(false);}};const handleViewLogs = (e: React.MouseEvent) => {e.stopPropagation();const args = currentTool.arguments as any;// Set up both tabs so user can switch between script and logsclearPanelTabs();if (currentTool.tool === 'hf_jobs' && args.script) {setPanelTab({id: 'script',title: 'Script',content: args.script,language: 'python',parameters: args});}setPanelTab({id: 'logs',title: 'Logs',content: logsContent,language: 'text'});setActivePanelTab('logs');setRightPanelOpen(true);setLeftSidebarOpen(false);};46 unmodified lines<OpenInNewIcon sx={{ fontSize: 16, color: 'var(--muted-text)', opacity: 0.7 }} /></Box>{currentTool.tool === 'hf_jobs' && (<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>{/* Show specific job URL if available (after execution), otherwise generic link */}{jobUrl ? (<Linkhref={jobUrl}target="_blank"rel="noopener noreferrer"sx={{display: 'flex',alignItems: 'center',gap: 0.5,color: 'var(--accent-primary)',fontSize: '0.8rem',textDecoration: 'none',opacity: 0.9,'&:hover': {opacity: 1,textDecoration: 'underline',}}}><LaunchIcon sx={{ fontSize: 14 }} />View job{jobId ? ` (${jobId.substring(0, 8)}...)` : ''} on Hugging Face</Link>) : (<Linkhref="https://huggingface.co/settings/jobs"target="_blank"rel="noopener noreferrer"sx={{display: 'flex',alignItems: 'center',gap: 0.5,color: 'var(--muted-text)',fontSize: '0.8rem',textDecoration: 'none',opacity: 0.7,'&:hover': {opacity: 1,textDecoration: 'underline',}}}><LaunchIcon sx={{ fontSize: 14 }} />View all jobs on Hugging Face</Link>)}{/* Show job status if available */}{jobStatus && (<Typographyvariant="caption"sx={{color: jobFailed ? 'var(--accent-red)' : 'var(--accent-green)',fontSize: '0.75rem',fontWeight: 500,}}>Status: {jobStatus}</Typography>)}</Box>)}{containsPushToHub && (<Typography variant="caption" sx={{ color: 'var(--accent-green)', fontSize: '0.75rem', opacity: 0.8, px: 0.5 }}>We've detected the result will be pushed to hub.</Typography>)}{/* Show script/logs buttons for completed jobs */}{status !== 'pending' && currentTool.tool === 'hf_jobs' && (args.script || showLogsButton) && (<Box sx={{ display: 'flex', gap: 1, flexWrap: 'wrap' }}>{args.script && (<Buttonvariant="outlined"size="small"startIcon={<OpenInNewIcon />}onClick={showCode}sx={{textTransform: 'none',borderColor: 'rgba(255,255,255,0.1)',color: 'var(--muted-text)',fontSize: '0.75rem',py: 0.5,'&:hover': {borderColor: 'var(--accent-primary)',color: 'var(--accent-primary)',bgcolor: 'rgba(255,255,255,0.03)'}}}>View Script</Button>)}{showLogsButton && (<Buttonvariant="outlined"size="small"startIcon={<OpenInNewIcon />}onClick={handleViewLogs}sx={{textTransform: 'none',borderColor: 'rgba(255,255,255,0.1)',color: 'var(--accent-primary)',fontSize: '0.75rem',py: 0.5,'&:hover': {borderColor: 'var(--accent-primary)',bgcolor: 'rgba(255,255,255,0.03)'}}}>View Logs</Button>)}</Box>)}{status === 'pending' && (
1234567891 unmodified line1112131415161718192021222324252627282930313233343536373839404142434445464748491 unmodified line51525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116import { useRef, useEffect, useMemo } from 'react';import { Box, Typography, IconButton } from '@mui/material';import CloseIcon from '@mui/icons-material/Close';import RadioButtonUncheckedIcon from '@mui/icons-material/RadioButtonUnchecked';import CheckCircleIcon from '@mui/icons-material/CheckCircle';import PlayCircleOutlineIcon from '@mui/icons-material/PlayCircleOutline';import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';import { useAgentStore } from '@/store/agentStore';1 unmodified lineimport { processLogs } from '@/utils/logProcessor';export default function CodePanel() {const { panelContent, plan } = useAgentStore();const { setRightPanelOpen } = useLayoutStore();const scrollRef = useRef<HTMLDivElement>(null);const displayContent = useMemo(() => {if (!panelContent?.content) return '';// Apply log processing only for text/logs, not for code/jsonif (!panelContent.language || panelContent.language === 'text') {return processLogs(panelContent.content);}return panelContent.content;}, [panelContent?.content, panelContent?.language]);useEffect(() => {if (scrollRef.current) {scrollRef.current.scrollTop = scrollRef.current.scrollHeight;}}, [displayContent]);return (<Box sx={{ height: '100%', display: 'flex', flexDirection: 'column', bgcolor: 'var(--panel)' }}>{/* Header - Fixed 60px to align */}<Box sx={{height: '60px',display: 'flex',alignItems: 'center',justifyContent: 'space-between',px: 2,borderBottom: '1px solid rgba(255,255,255,0.03)'}}><Typography variant="caption" sx={{ fontWeight: 600, color: 'var(--muted-text)', textTransform: 'uppercase', letterSpacing: '0.05em' }}>{panelContent?.title || 'Code Panel'}</Typography><IconButton size="small" onClick={() => setRightPanelOpen(false)} sx={{ color: 'var(--muted-text)' }}><CloseIcon fontSize="small" /></IconButton>1 unmodified line{/* Main Content Area */}<Box sx={{ flex: 1, overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>{!panelContent ? (<Box sx={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', p: 4 }}><Typography variant="body2" color="text.secondary" sx={{ opacity: 0.5 }}>NO DATA LOADED</Typography></Box>) : (<Box sx={{ flex: 1, overflow: 'hidden', p: 2 }}><Boxref={scrollRef}className="code-panel"sx={{background: '#0A0B0C',borderRadius: 'var(--radius-md)',padding: '18px',border: '1px solid rgba(255,255,255,0.03)',fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", monospace',fontSize: '13px',lineHeight: 1.55,height: '100%',overflow: 'auto',}}>{panelContent.content ? (panelContent.language === 'python' ? (<SyntaxHighlighterlanguage="python"style={vscDarkPlus}customStyle={{margin: 0,padding: 0,background: 'transparent',fontSize: '13px',fontFamily: 'inherit',}}wrapLines={true}wrapLongLines={true}>{displayContent}</SyntaxHighlighter>) : (<Box component="pre" sx={{m: 0,fontFamily: 'inherit',color: 'var(--text)',whiteSpace: 'pre-wrap',wordBreak: 'break-all'}}><code>{displayContent}</code></Box>)) : (<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', opacity: 0.5 }}><Typography variant="caption">NO CONTENT TO DISPLAY</Typography></Box>)}</Box></Box>)}</Box>12345678910111 unmodified line13141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394951 unmodified line979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162import { useRef, useEffect, useMemo } from 'react';import { Box, Typography, IconButton, Tabs, Tab } from '@mui/material';import CloseIcon from '@mui/icons-material/Close';import RadioButtonUncheckedIcon from '@mui/icons-material/RadioButtonUnchecked';import CheckCircleIcon from '@mui/icons-material/CheckCircle';import PlayCircleOutlineIcon from '@mui/icons-material/PlayCircleOutline';import CodeIcon from '@mui/icons-material/Code';import TerminalIcon from '@mui/icons-material/Terminal';import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';import { useAgentStore } from '@/store/agentStore';1 unmodified lineimport { processLogs } from '@/utils/logProcessor';export default function CodePanel() {const { panelContent, panelTabs, activePanelTab, setActivePanelTab, plan } = useAgentStore();const { setRightPanelOpen } = useLayoutStore();const scrollRef = useRef<HTMLDivElement>(null);// Get the active tab content, or fall back to panelContent for backwards compatibilityconst activeTab = panelTabs.find(t => t.id === activePanelTab);const currentContent = activeTab || panelContent;const displayContent = useMemo(() => {if (!currentContent?.content) return '';// Apply log processing only for text/logs, not for code/jsonif (!currentContent.language || currentContent.language === 'text') {return processLogs(currentContent.content);}return currentContent.content;}, [currentContent?.content, currentContent?.language]);useEffect(() => {// Auto-scroll only for logs tabif (scrollRef.current && activePanelTab === 'logs') {scrollRef.current.scrollTop = scrollRef.current.scrollHeight;}}, [displayContent, activePanelTab]);const hasTabs = panelTabs.length > 0;return (<Box sx={{ height: '100%', display: 'flex', flexDirection: 'column', bgcolor: 'var(--panel)' }}>{/* Header - Fixed 60px to align */}<Box sx={{height: '60px',display: 'flex',alignItems: 'center',justifyContent: 'space-between',px: 2,borderBottom: '1px solid rgba(255,255,255,0.03)'}}>{hasTabs ? (<Tabsvalue={activePanelTab || panelTabs[0]?.id}onChange={(_, newValue) => setActivePanelTab(newValue)}sx={{minHeight: 36,'& .MuiTabs-indicator': {backgroundColor: 'var(--accent-primary)',},'& .MuiTab-root': {minHeight: 36,minWidth: 'auto',px: 2,py: 0.5,fontSize: '0.75rem',fontWeight: 600,textTransform: 'uppercase',letterSpacing: '0.05em',color: 'var(--muted-text)','&.Mui-selected': {color: 'var(--text)',},},}}>{panelTabs.map((tab) => (<Tabkey={tab.id}value={tab.id}label={tab.title}icon={tab.id === 'script' ? <CodeIcon sx={{ fontSize: 16 }} /> : <TerminalIcon sx={{ fontSize: 16 }} />}iconPosition="start"/>))}</Tabs>) : (<Typography variant="caption" sx={{ fontWeight: 600, color: 'var(--muted-text)', textTransform: 'uppercase', letterSpacing: '0.05em' }}>{currentContent?.title || 'Code Panel'}</Typography>)}<IconButton size="small" onClick={() => setRightPanelOpen(false)} sx={{ color: 'var(--muted-text)' }}><CloseIcon fontSize="small" /></IconButton>1 unmodified line{/* Main Content Area */}<Box sx={{ flex: 1, overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>{!currentContent ? (<Box sx={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', p: 4 }}><Typography variant="body2" color="text.secondary" sx={{ opacity: 0.5 }}>NO DATA LOADED</Typography></Box>) : (<Box sx={{ flex: 1, overflow: 'hidden', p: 2 }}><Boxref={scrollRef}className="code-panel"sx={{background: '#0A0B0C',borderRadius: 'var(--radius-md)',padding: '18px',border: '1px solid rgba(255,255,255,0.03)',fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", monospace',fontSize: '13px',lineHeight: 1.55,height: '100%',overflow: 'auto',}}>{currentContent.content ? (currentContent.language === 'python' ? (<SyntaxHighlighterlanguage="python"style={vscDarkPlus}customStyle={{margin: 0,padding: 0,background: 'transparent',fontSize: '13px',fontFamily: 'inherit',}}wrapLines={true}wrapLongLines={true}>{displayContent}</SyntaxHighlighter>) : (<Box component="pre" sx={{m: 0,fontFamily: 'inherit',color: 'var(--text)',whiteSpace: 'pre-wrap',wordBreak: 'break-all'}}><code>{displayContent}</code></Box>)) : (<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%', opacity: 0.5 }}><Typography variant="caption">NO CONTENT TO DISPLAY</Typography></Box>)}</Box></Box>)}</Box>
33 unmodified lines34353637383918 unmodified lines58596061626351 unmodified lines11511611711811912012112212312412512612712812913013113213313413513613737 unmodified lines17517617717817918018118218318418518618718818919019119219319419519619719819920020120220315 unmodified lines2192202212222232242256 unmodified lines23223323423523623723833 unmodified linesupdateTraceLog,clearTraceLogs,setPanelContent,setPlan,setCurrentTurnMessageId,updateCurrentTurnTrace,18 unmodified linescase 'processing':setProcessing(true);clearTraceLogs();setCurrentTurnMessageId(null); // Start a new turnbreak;51 unmodified lines// Auto-expand Right Panel for specific toolsif (toolName === 'hf_jobs' && (args.operation === 'run' || args.operation === 'scheduled run') && args.script) {setPanelContent({title: 'Compute Job Script',content: args.script,language: 'python'});setRightPanelOpen(true);setLeftSidebarOpen(false);} else if (toolName === 'hf_repo_files' && args.operation === 'upload' && args.content) {setPanelContent({title: `File Upload: ${args.path || 'unnamed'} `,content: args.content,parameters: args,language: args.path?.endsWith('.py') ? 'python' : undefined});setRightPanelOpen(true);setLeftSidebarOpen(false);}console.log('Tool call:', toolName, args);break;37 unmodified linesconst log = (event.data?.log as string) || '';if (toolName === 'hf_jobs') {const currentPanel = useAgentStore.getState().panelContent;// If we are already showing logs, append// If we are showing "Compute Job Script", overwrite/switch to logs// Otherwise, initializelet newContent = log;if (currentPanel?.title === 'Job Logs') {newContent = currentPanel.content + '\n' + log;} else if (currentPanel?.title === 'Compute Job Script') {// We were showing the script, now logs start.// Maybe we want to clear and start showing logs.newContent = '--- Starting execution ---\n' + log;}setPanelContent({title: 'Job Logs',content: newContent,language: 'text'});if (!useLayoutStore.getState().isRightPanelOpen) {setRightPanelOpen(true);}}break;15 unmodified linestool_call_id: string;}>;const count = (event.data?.count as number) || 0;// Create a persistent message for the approval requestconst message: Message = {id: `msg_approval_${Date.now()}`,6 unmodified lines}};addMessage(sessionId, message);// We don't set pendingApprovals in the global store anymore as the message handles the UIsetPendingApprovals(null);setProcessing(false);33 unmodified lines34353637383940414218 unmodified lines616263646566676851 unmodified lines12012112212312412512612712812913013113213313413513613713813914014114214314414514614714837 unmodified lines18618718818919019119219319419519619719819920020120220320420520620720820921021115 unmodified lines2272282292302312322336 unmodified lines24024124224324424524624724824933 unmodified linesupdateTraceLog,clearTraceLogs,setPanelContent,setPanelTab,setActivePanelTab,clearPanelTabs,setPlan,setCurrentTurnMessageId,updateCurrentTurnTrace,18 unmodified linescase 'processing':setProcessing(true);clearTraceLogs();// Don't clear panel tabs here - they should persist during approval flow// Tabs will be cleared when a new tool_call sets up new contentsetCurrentTurnMessageId(null); // Start a new turnbreak;51 unmodified lines// Auto-expand Right Panel for specific toolsif (toolName === 'hf_jobs' && (args.operation === 'run' || args.operation === 'scheduled run') && args.script) {// Clear any existing tabs from previous jobs before setting new scriptclearPanelTabs();// Use tab system for jobs - add script tab immediatelysetPanelTab({id: 'script',title: 'Script',content: args.script,language: 'python',parameters: args});setActivePanelTab('script');setRightPanelOpen(true);setLeftSidebarOpen(false);} else if (toolName === 'hf_repo_files' && args.operation === 'upload' && args.content) {setPanelContent({title: `File Upload: ${args.path || 'unnamed'}`,content: args.content,parameters: args,language: args.path?.endsWith('.py') ? 'python' : undefined});setRightPanelOpen(true);setLeftSidebarOpen(false);}console.log('Tool call:', toolName, args);break;37 unmodified linesconst log = (event.data?.log as string) || '';if (toolName === 'hf_jobs') {const currentTabs = useAgentStore.getState().panelTabs;const logsTab = currentTabs.find(t => t.id === 'logs');// Append to existing logs tab or create new oneconst newContent = logsTab? logsTab.content + '\n' + log: '--- Job execution started ---\n' + log;setPanelTab({id: 'logs',title: 'Logs',content: newContent,language: 'text'});// Auto-switch to logs tab when logs start streamingsetActivePanelTab('logs');if (!useLayoutStore.getState().isRightPanelOpen) {setRightPanelOpen(true);}}break;15 unmodified linestool_call_id: string;}>;const count = (event.data?.count as number) || 0;// Create a persistent message for the approval requestconst message: Message = {id: `msg_approval_${Date.now()}`,6 unmodified lines}};addMessage(sessionId, message);// Clear currentTurnMessageId so subsequent assistant_message events create a new message below the approvalsetCurrentTurnMessageId(null);// We don't set pendingApprovals in the global store anymore as the message handles the UIsetPendingApprovals(null);setProcessing(false);
6 unmodified lines7891011124 unmodified lines17181920212211 unmodified lines3435363738398 unmodified lines48495051525385 unmodified lines1391401411421431446 unmodified linesstatus: 'pending' | 'in_progress' | 'completed';}interface AgentStore {// State per session (keyed by session ID)messagesBySession: Record<string, Message[]>;4 unmodified lineserror: string | null;traceLogs: TraceLog[];panelContent: { title: string; content: string; language?: string; parameters?: any } | null;plan: PlanItem[];currentTurnMessageId: string | null; // Track the current turn's assistant message11 unmodified linesupdateTraceLog: (toolName: string, updates: Partial<TraceLog>) => void;clearTraceLogs: () => void;setPanelContent: (content: { title: string; content: string; language?: string; parameters?: any } | null) => void;setPlan: (plan: PlanItem[]) => void;setCurrentTurnMessageId: (id: string | null) => void;updateCurrentTurnTrace: (sessionId: string) => void;8 unmodified lineserror: null,traceLogs: [],panelContent: null,plan: [],currentTurnMessageId: null,85 unmodified linesset({ panelContent: content });},setPlan: (plan: PlanItem[]) => {set({ plan });},6 unmodified lines78910111213141516171819204 unmodified lines252627282930313211 unmodified lines4445464748495051528 unmodified lines616263646566676885 unmodified lines1541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851866 unmodified linesstatus: 'pending' | 'in_progress' | 'completed';}interface PanelTab {id: string;title: string;content: string;language?: string;parameters?: any;}interface AgentStore {// State per session (keyed by session ID)messagesBySession: Record<string, Message[]>;4 unmodified lineserror: string | null;traceLogs: TraceLog[];panelContent: { title: string; content: string; language?: string; parameters?: any } | null;panelTabs: PanelTab[];activePanelTab: string | null;plan: PlanItem[];currentTurnMessageId: string | null; // Track the current turn's assistant message11 unmodified linesupdateTraceLog: (toolName: string, updates: Partial<TraceLog>) => void;clearTraceLogs: () => void;setPanelContent: (content: { title: string; content: string; language?: string; parameters?: any } | null) => void;setPanelTab: (tab: PanelTab) => void;setActivePanelTab: (tabId: string) => void;clearPanelTabs: () => void;setPlan: (plan: PlanItem[]) => void;setCurrentTurnMessageId: (id: string | null) => void;updateCurrentTurnTrace: (sessionId: string) => void;8 unmodified lineserror: null,traceLogs: [],panelContent: null,panelTabs: [],activePanelTab: null,plan: [],currentTurnMessageId: null,85 unmodified linesset({ panelContent: content });},setPanelTab: (tab: PanelTab) => {set((state) => {const existingIndex = state.panelTabs.findIndex(t => t.id === tab.id);let newTabs: PanelTab[];if (existingIndex >= 0) {// Update existing tabnewTabs = [...state.panelTabs];newTabs[existingIndex] = tab;} else {// Add new tabnewTabs = [...state.panelTabs, tab];}return {panelTabs: newTabs,activePanelTab: state.activePanelTab || tab.id, // Auto-select first tab};});},setActivePanelTab: (tabId: string) => {set({ activePanelTab: tabId });},clearPanelTabs: () => {set({ panelTabs: [], activePanelTab: null });},setPlan: (plan: PlanItem[]) => {set({ plan });},
frontend/src/components/Chat/ApprovalFlow.tsx+196-47
frontend/src/components/CodePanel/CodePanel.tsx+117-71
frontend/src/hooks/useAgentWebSocket.ts+44-33
frontend/src/store/agentStore.ts+42