Spaces:
Running

taskpilot / script.js
Destiny369963's picture
Replace handleUserMessage with this: async handleUserMessage(message, files = []) {
53806cf verified
Raw History Blame Contribute Delete
46.9 kB
// Import necessary React features const { useState, useEffect, useRef, createContext, useContext } = React; // Interfaces (documentation objects, not used at runtime) const ChatMessage = { id: '', role: 'user', // or 'agent' text: '', timestamp: '', workflowStepId: undefined }; const UploadedFile = { id: '', name: '', size: 0, type: '', textPreview: undefined }; const WorkflowStep = { id: '', title: '', description: '', status: 'pending', // 'pending' | 'in_progress' | 'done' | 'skipped' relatedFiles: [] }; const AgentWorkflow = { id: '', name: '', steps: [] }; const PolicyState = { // These values now match what the agent actually uses detailLevel: 'medium', // 'concise' | 'medium' | 'detailed' tone: 'neutral', // 'concise' | 'neutral' | 'detailed' preferredWorkflowTemplates: [], recentSuccessRate: 0.85 }; const AgentTurn = { responseMessage: '', steps: [], reasoningTrace: '', policyState: PolicyState }; // TaskPilotAgent Class class TaskPilotAgent { constructor() { this.policyState = { ...PolicyState }; this.workflows = []; this.workflowTemplates = { shopify: { id: 'shopify', name: 'Take a Shopify store live', steps: [ { id: 's1', title: 'Configure domain settings', description: 'Set up custom domain for the store', status: 'pending', relatedFiles: [] }, { id: 's2', title: 'Add payment gateways', description: 'Configure accepted payment methods', status: 'pending', relatedFiles: [] }, { id: 's3', title: 'Set up shipping zones', description: 'Define shipping regions and rates', status: 'pending', relatedFiles: [] }, { id: 's4', title: 'Review tax settings', description: 'Configure tax calculations for products', status: 'pending', relatedFiles: [] }, { id: 's5', title: 'Launch store', description: 'Remove password protection and go live', status: 'pending', relatedFiles: [] } ] }, website: { id: 'website', name: 'Create a simple marketing website', steps: [ { id: 'w1', title: 'Define target audience', description: 'Identify key demographics and personas', status: 'pending', relatedFiles: [] }, { id: 'w2', title: 'Create site map', description: 'Plan website structure and navigation', status: 'pending', relatedFiles: [] }, { id: 'w3', title: 'Design homepage layout', description: 'Create wireframes for key landing page', status: 'pending', relatedFiles: [] }, { id: 'w4', title: 'Develop core pages', description: 'Build About, Services, and Contact pages', status: 'pending', relatedFiles: [] }, { id: 'w5', title: 'Test and launch', description: 'Perform QA testing and deploy to production', status: 'pending', relatedFiles: [] } ] }, 'ux-review': { id: 'ux-review', name: 'Review and improve a page’s UI/UX', steps: [ { id: 'u1', title: 'Heuristic evaluation', description: 'Assess against UX best practices', status: 'pending', relatedFiles: [] }, { id: 'u2', title: 'User flow analysis', description: 'Map current navigation paths', status: 'pending', relatedFiles: [] }, { id: 'u3', title: 'Accessibility check', description: 'Verify WCAG compliance standards', status: 'pending', relatedFiles: [] }, { id: 'u4', title: 'Performance audit', description: 'Analyze loading times and optimizations', status: 'pending', relatedFiles: [] }, { id: 'u5', title: 'Implement improvements', description: 'Apply recommended changes to interface', status: 'pending', relatedFiles: [] } ] } }; } _getActiveWorkflow() { return this.workflows.length > 0 ? this.workflows[0] : null; } _getNextStep() { const wf = this._getActiveWorkflow(); if (!wf) return null; return ( wf.steps.find((s) => s.status === 'in_progress' || s.status === 'pending') || wf.steps[0] || null ); } async handleUserMessage(message, files = []) { // Mock AI processing delay await new Promise((resolve) => setTimeout(resolve, 800)); const lower = message.toLowerCase(); // Base response / reasoning let response = "I've received your message. How can I assist you further?"; let reasoning = "Processed user input"; if (lower.includes("hello") || lower.includes("hi")) { response = "Hello! I'm TaskPilot, your AI task assistant. How can I help you today?"; reasoning = "Greeting detected, provided welcome message"; } else if (lower.includes("help")) { response = "I can help you manage workflows, track tasks, and provide insights. Try asking me to start a workflow or analyze a task."; reasoning = "Help request detected, provided assistance options"; } else if (files.length > 0) { response = `I see you've uploaded ${files.length} file(s). I can analyze these to help with your tasks.`; reasoning = "Files detected in message, acknowledged attachment"; } // Update policy based on message content if (message.length > 100) { this.policyState.detailLevel = "detailed"; reasoning += ". User provided detailed input, increasing detail level."; } else if (message.length < 20) { this.policyState.detailLevel = "concise"; reasoning += ". User provided brief input, setting concise mode."; } const activeWorkflow = this._getActiveWorkflow(); return { responseMessage: response, steps: activeWorkflow ? [...activeWorkflow.steps] : [], reasoningTrace: reasoning, policyState: { ...this.policyState } }; } startWorkflow(templateId, userInputs = {}) { const template = this.workflowTemplates[templateId]; if (!template) { throw new Error(`Template ${templateId} not found`); } const verificationMode = userInputs.verificationMode || 'checklist'; // Customize steps based on user inputs (simple example for Shopify store name) const customizedSteps = template.steps.map((step) => { let description = step.description; if (templateId === 'shopify' && userInputs.storeName) { description = description.replace('store', `${userInputs.storeName} store`); } // Simple "verify" overlay depending on mode if (verificationMode === 'checklist-plus') { description = `${description} (Verify: confirm this is fully complete before marking done.)`; } return { ...step, description, status: 'pending' }; }); const workflow = { id: `wf-${Date.now()}`, name: template.name, steps: customizedSteps }; this.workflows = [workflow]; return workflow; } updateStepStatus(stepId, status) { for (const workflow of this.workflows) { const step = workflow.steps.find((s) => s.id === stepId); if (step) { step.status = status; break; } } // Update policy based on completion const allSteps = this.workflows.flatMap((wf) => wf.steps); const completedSteps = allSteps.filter((s) => s.status === 'done').length; const totalSteps = allSteps.length; if (totalSteps > 0) { this.policyState.recentSuccessRate = completedSteps / totalSteps; } return this.workflows.length > 0 ? [...this.workflows[0].steps] : []; } handleFeedback(isPositive) { const activeWorkflow = this._getActiveWorkflow(); if (isPositive) { // Increase preference for current template if (activeWorkflow) { const currentTemplate = activeWorkflow.name; if (!this.policyState.preferredWorkflowTemplates.includes(currentTemplate)) { this.policyState.preferredWorkflowTemplates.push(currentTemplate); } } // Adjust tone to be more detailed this.policyState.tone = 'detailed'; } else { // Decrease preference for current template if (activeWorkflow) { const currentTemplate = activeWorkflow.name; this.policyState.preferredWorkflowTemplates = this.policyState.preferredWorkflowTemplates.filter((t) => t !== currentTemplate); } // Adjust tone to be more concise this.policyState.tone = 'concise'; } } } // Create agent instance const agentInstance = new TaskPilotAgent(); // Context for sharing agent between components (unused for now but kept for future) const AgentContext = createContext(); // Chat Panel Component const ChatPanel = ({ messages, onSendMessage, onFeedback }) => { const [inputText, setInputText] = useState(''); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSubmit = (e) => { e.preventDefault(); if (inputText.trim()) { onSendMessage(inputText); setInputText(''); } }; return React.createElement( 'div', { className: 'flex flex-col h-full' }, React.createElement( 'div', { className: 'p-4 border-b border-slate-800' }, React.createElement('h2', { className: 'text-xl font-bold text-primary-400' }, 'TaskPilot Chat'), React.createElement( 'p', { className: 'text-sm text-slate-400' }, 'Your AI task assistant' ) ), React.createElement( 'div', { className: 'flex-1 overflow-y-auto p-4 space-y-4' }, messages.map((msg) => React.createElement( 'div', { key: msg.id, className: `p-4 rounded-lg max-w-[80%] ${ msg.role === 'user' ? 'bg-slate-800 ml-auto' : 'bg-slate-700 mr-auto' }` }, React.createElement( 'div', { className: 'flex items-start gap-2' }, msg.role === 'agent' && React.createElement( 'div', { className: 'mt-1 flex-shrink-0 w-6 h-6 rounded-full bg-primary-500 flex items-center justify-center' }, React.createElement('i', { 'data-feather': 'cpu', className: 'w-4 h-4' }) ), React.createElement( 'div', { className: 'flex-1' }, React.createElement( 'p', { className: 'whitespace-pre-wrap' }, msg.text ), msg.role === 'agent' && React.createElement( 'div', { className: 'flex gap-2 mt-2' }, React.createElement( 'button', { onClick: () => onFeedback(true), className: 'p-1 text-slate-400 hover:text-green-400 transition-colors', title: 'Helpful' }, React.createElement('i', { 'data-feather': 'thumbs-up' }) ), React.createElement( 'button', { onClick: () => onFeedback(false), className: 'p-1 text-slate-400 hover:text-red-400 transition-colors', title: 'Not helpful' }, React.createElement('i', { 'data-feather': 'thumbs-down' }) ) ) ) ) ) ), React.createElement('div', { ref: messagesEndRef }) ), React.createElement( 'form', { onSubmit: handleSubmit, className: 'p-4 border-t border-slate-800' }, React.createElement( 'div', { className: 'flex gap-2' }, React.createElement('textarea', { value: inputText, onChange: (e) => setInputText(e.target.value), placeholder: 'Message TaskPilot...', className: 'flex-1 bg-slate-800 border border-slate-700 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500 resize-none', rows: '2' }), React.createElement( 'button', { type: 'submit', className: 'bg-primary-600 hover:bg-primary-700 text-white rounded-lg px-4 py-2 font-medium transition-colors flex items-center gap-2' }, React.createElement('i', { 'data-feather': 'send' }), 'Send' ) ) ) ); }; // Workflow Panel Component with Target > Task > Verify dropdowns const WorkflowPanel = ({ workflows, onStartWorkflow, onUpdateStepStatus }) => { const [target, setTarget] = useState(''); const [taskType, setTaskType] = useState(''); const [verificationMode, setVerificationMode] = useState('checklist'); const [userInputs, setUserInputs] = useState({}); const currentWorkflow = workflows.length > 0 ? workflows[0] : null; const targets = [ { id: 'ecom', label: 'E-commerce store (Shopify, etc.)' }, { id: 'website', label: 'Website / Marketing site' }, { id: 'ux', label: 'UI / UX & product screen' }, { id: 'general', label: 'General workflow' } ]; const taskTypes = [ { id: 'launch', label: 'Launch / Go live' }, { id: 'create', label: 'Create / Build' }, { id: 'review', label: 'Review / Improve' } ]; const verificationModes = [ { id: 'checklist', label: 'Checklist only' }, { id: 'checklist-plus', label: 'Checklist + self-verification notes' } ]; const getTemplateIdFromSelection = (targetId, taskId) => { // Very simple mapping: you can expand this later if (targetId === 'ecom' && taskId === 'launch') return 'shopify'; if (targetId === 'website' && (taskId === 'launch' || taskId === 'create')) return 'website'; if (targetId === 'ux' && taskId === 'review') return 'ux-review'; // Reasonable fallbacks if (targetId === 'website') return 'website'; if (targetId === 'ux') return 'ux-review'; if (targetId === 'ecom') return 'shopify'; // Default return 'website'; }; const handleStartWorkflowClick = () => { if (!target || !taskType) return; const templateId = getTemplateIdFromSelection(target, taskType); const extendedInputs = { ...userInputs, target, taskType, verificationMode }; onStartWorkflow(templateId, extendedInputs); setUserInputs({}); }; return React.createElement( 'div', { className: 'flex flex-col h-full' }, React.createElement( 'div', { className: 'p-4 border-b border-slate-800' }, React.createElement('h2', { className: 'text-xl font-bold text-primary-400' }, 'Workflows'), React.createElement( 'p', { className: 'text-sm text-slate-400' }, 'Target → Task → Verify' ) ), !currentWorkflow ? React.createElement( 'div', { className: 'p-4 space-y-4' }, // Target selector React.createElement( 'div', null, React.createElement( 'label', { className: 'block text-sm font-medium mb-2' }, 'Target Area' ), React.createElement( 'select', { value: target, onChange: (e) => setTarget(e.target.value), className: 'w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500' }, React.createElement( 'option', { value: '' }, 'Choose a target...' ), targets.map((t) => React.createElement( 'option', { key: t.id, value: t.id }, t.label ) ) ) ), // Task selector React.createElement( 'div', null, React.createElement( 'label', { className: 'block text-sm font-medium mb-2' }, 'Task Type' ), React.createElement( 'select', { value: taskType, onChange: (e) => setTaskType(e.target.value), className: 'w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500' }, React.createElement( 'option', { value: '' }, 'Choose a task...' ), taskTypes.map((t) => React.createElement( 'option', { key: t.id, value: t.id }, t.label ) ) ) ), // Verification selector React.createElement( 'div', null, React.createElement( 'label', { className: 'block text-sm font-medium mb-2' }, 'Verification Mode' ), React.createElement( 'select', { value: verificationMode, onChange: (e) => setVerificationMode(e.target.value), className: 'w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500' }, verificationModes.map((v) => React.createElement( 'option', { key: v.id, value: v.id }, v.label ) ) ) ), // Conditional Shopify store name input target === 'ecom' && taskType === 'launch' && React.createElement( 'div', null, React.createElement( 'label', { className: 'block text-sm font-medium mb-2' }, 'Store Name' ), React.createElement('input', { type: 'text', value: userInputs.storeName || '', onChange: (e) => setUserInputs({ ...userInputs, storeName: e.target.value }), placeholder: 'Enter store name', className: 'w-full bg-slate-800 border border-slate-700 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500' }) ), React.createElement( 'button', { onClick: handleStartWorkflowClick, disabled: !target || !taskType, className: `w-full py-2 px-4 rounded-lg font-medium transition-colors ${ target && taskType ? 'bg-primary-600 hover:bg-primary-700 text-white' : 'bg-slate-800 text-slate-500 cursor-not-allowed' }` }, 'Start Workflow' ) ) : React.createElement( 'div', { className: 'flex-1 overflow-y-auto' }, React.createElement( 'div', { className: 'p-4 border-b border-slate-800' }, React.createElement( 'div', { className: 'flex justify-between items-center' }, React.createElement('h3', { className: 'font-semibold' }, currentWorkflow.name), React.createElement( 'span', { className: 'text-xs bg-slate-800 px-2 py-1 rounded' }, `${currentWorkflow.steps.filter((s) => s.status === 'done').length}/${ currentWorkflow.steps.length } completed` ) ) ), React.createElement( 'div', { className: 'p-4 space-y-4' }, currentWorkflow.steps.map((step) => React.createElement( 'div', { key: step.id, className: 'step-card bg-slate-800 rounded-lg p-4 border border-slate-700' }, React.createElement( 'div', { className: 'flex justify-between items-start' }, React.createElement( 'div', null, React.createElement( 'h4', { className: 'font-medium' }, step.title ), React.createElement( 'p', { className: 'text-sm text-slate-400 mt-1' }, step.description ) ), React.createElement( 'span', { className: `px-2 py-1 rounded-full text-xs font-medium capitalize ${ step.status === 'pending' ? 'status-pending' : step.status === 'in_progress' ? 'status-in-progress' : step.status === 'done' ? 'status-done' : 'status-skipped' }` }, step.status.replace('_', ' ') ) ), React.createElement( 'div', { className: 'flex gap-2 mt-3' }, step.status === 'pending' && React.createElement( 'button', { onClick: () => onUpdateStepStatus(step.id, 'in_progress'), className: 'text-xs bg-blue-600 hover:bg-blue-700 text-white px-2 py-1 rounded transition-colors' }, 'Start' ), (step.status === 'pending' || step.status === 'in_progress') && React.createElement( 'button', { onClick: () => onUpdateStepStatus(step.id, 'done'), className: 'text-xs bg-green-600 hover:bg-green-700 text-white px-2 py-1 rounded transition-colors' }, 'Mark Done' ), step.status === 'pending' && React.createElement( 'button', { onClick: () => onUpdateStepStatus(step.id, 'skipped'), className: 'text-xs bg-slate-700 hover:bg-slate-600 text-white px-2 py-1 rounded transition-colors' }, 'Skip' ) ) ) ) ) ) ); }; // Files Inspector Panel Component const FilesInspectorPanel = ({ files, onFileUpload, onRemoveFile, policyState, reasoningTrace }) => { const fileInputRef = useRef(null); const handleFileChange = (e) => { const newFiles = Array.from(e.target.files); onFileUpload(newFiles); }; const triggerFileInput = () => { fileInputRef.current.click(); }; return React.createElement( 'div', { className: 'flex flex-col h-full' }, React.createElement( 'div', { className: 'p-4 border-b border-slate-800' }, React.createElement( 'h2', { className: 'text-xl font-bold text-primary-400' }, 'Files & Inspector' ), React.createElement( 'p', { className: 'text-sm text-slate-400' }, 'Manage attachments and view insights' ) ), React.createElement( 'div', { className: 'p-4 border-b border-slate-800' }, React.createElement( 'button', { onClick: triggerFileInput, className: 'w-full py-2 px-4 bg-slate-800 hover:bg-slate-700 border border-dashed border-slate-600 rounded-lg flex flex-col items-center justify-center gap-2 transition-colors' }, React.createElement('i', { 'data-feather': 'upload', className: 'text-slate-400' }), React.createElement( 'span', { className: 'text-sm' }, 'Drag & drop files or click to browse' ), React.createElement('input', { type: 'file', ref: fileInputRef, onChange: handleFileChange, multiple: true, className: 'hidden' }) ) ), React.createElement( 'div', { className: 'flex-1 overflow-y-auto p-4 space-y-4' }, React.createElement( 'div', null, React.createElement( 'h3', { className: 'font-medium mb-2' }, `Uploaded Files (${files.length})` ), files.length === 0 ? React.createElement( 'p', { className: 'text-sm text-slate-500 italic' }, 'No files uploaded yet' ) : React.createElement( 'div', { className: 'space-y-2' }, files.map((file) => React.createElement( 'div', { key: file.id, className: 'bg-slate-800 rounded-lg p-3 border border-slate-700' }, React.createElement( 'div', { className: 'flex justify-between' }, React.createElement( 'div', { className: 'flex items-center gap-2' }, React.createElement('i', { 'data-feather': 'file-text', className: 'text-slate-400' }), React.createElement( 'div', null, React.createElement( 'p', { className: 'text-sm font-medium truncate max-w-[160px]' }, file.name ), React.createElement( 'p', { className: 'text-xs text-slate-500' }, `${(file.size / 1024).toFixed(1)} KB` ) ) ), React.createElement( 'button', { onClick: () => onRemoveFile(file.id), className: 'text-slate-500 hover:text-red-400' }, React.createElement('i', { 'data-feather': 'x' }) ) ), file.textPreview && React.createElement( 'div', { className: 'mt-2 text-xs bg-slate-900 p-2 rounded file-preview' }, React.createElement( 'pre', { className: 'whitespace-pre-wrap' }, file.textPreview ) ) ) ) ) ), React.createElement( 'div', null, React.createElement( 'h3', { className: 'font-medium mb-2' }, 'Policy State' ), React.createElement( 'div', { className: 'bg-slate-800 rounded-lg p-3 border border-slate-700' }, React.createElement( 'pre', { className: 'text-xs overflow-x-auto' }, JSON.stringify(policyState, null, 2) ) ) ), React.createElement( 'div', null, React.createElement( 'h3', { className: 'font-medium mb-2' }, 'Reasoning Trace' ), React.createElement( 'div', { className: 'bg-slate-800 rounded-lg p-3 border border-slate-700' }, React.createElement( 'p', { className: 'text-sm' }, reasoningTrace || 'No reasoning trace available' ) ) ) ) ); }; // Main App Component const App = () => { const [messages, setMessages] = useState([ { id: '1', role: 'agent', text: "Hello! I'm TaskPilot, your AI task agent. I can help you manage workflows, track tasks, and provide insights. Use the Target / Task / Verify selectors to get started, or just tell me what you’re trying to do.", timestamp: new Date().toISOString() } ]); const [files, setFiles] = useState([]); const [workflows, setWorkflows] = useState([]); const [policyState, setPolicyState] = useState(agentInstance.policyState); const [reasoningTrace, setReasoningTrace] = useState(''); const handleStartWorkflow = (templateId, userInputs) => { try { const workflow = agentInstance.startWorkflow(templateId, userInputs); setWorkflows([workflow]); // Add notification message const templateNames = { shopify: 'Shopify Store Launch', website: 'Marketing Website Creation', 'ux-review': 'UI/UX Review' }; const message = { id: `msg-${Date.now()}`, role: 'agent', text: `I've started the "${templateNames[templateId] || workflow.name}" workflow for you. You can track and update each step in the middle panel.`, timestamp: new Date().toISOString() }; setMessages((prev) => [...prev, message]); } catch (error) { console.error('Error starting workflow:', error); } }; const handleSendMessage = async (text) => { // Add user message const userMessage = { id: `msg-${Date.now()}`, role: 'user', text: text, timestamp: new Date().toISOString() }; setMessages((prev) => [...prev, userMessage]); // Auto-detect workflows from natural language if none is active const lower = text.toLowerCase(); const hasActiveWorkflow = workflows.length > 0; if (!hasActiveWorkflow) { if (lower.includes('shopify')) { handleStartWorkflow('shopify', { target: 'ecom', taskType: 'launch', verificationMode: 'checklist' }); } else if (lower.includes('website') || lower.includes('landing page')) { handleStartWorkflow('website', { target: 'website', taskType: 'create', verificationMode: 'checklist' }); } else if (lower.includes('ux') || lower.includes('ui') || lower.includes('user experience')) { handleStartWorkflow('ux-review', { target: 'ux', taskType: 'review', verificationMode: 'checklist' }); } } // Get agent response const turn = await agentInstance.handleUserMessage(text, files); // Add agent message const agentMessage = { id: `msg-${Date.now() + 1}`, role: 'agent', text: turn.responseMessage, timestamp: new Date().toISOString() }; setMessages((prev) => [...prev, agentMessage]); setPolicyState(turn.policyState); setReasoningTrace(turn.reasoningTrace); }; const handleUpdateStepStatus = (stepId, status) => { const updatedSteps = agentInstance.updateStepStatus(stepId, status); setWorkflows((prev) => prev.length > 0 ? [{ ...prev[0], steps: updatedSteps }] : [] ); setPolicyState({ ...agentInstance.policyState }); }; const handleFeedback = (isPositive) => { agentInstance.handleFeedback(isPositive); setPolicyState({ ...agentInstance.policyState }); // Add confirmation message const message = { id: `msg-${Date.now()}`, role: 'agent', text: isPositive ? "Thanks for the feedback! I'll continue providing responses like this." : "Thanks for the feedback. I'll adjust my approach accordingly.", timestamp: new Date().toISOString() }; setMessages((prev) => [...prev, message]); }; const handleFileUpload = (newFiles) => { const processedFiles = newFiles.map((file) => { const reader = new FileReader(); let textPreview = ''; // For text files, read content preview if (file.type.startsWith('text/') || file.name.endsWith('.json')) { reader.onload = (e) => { textPreview = e.target.result.substring(0, 200); setFiles((prev) => prev.map((f) => f.name === file.name ? { ...f, textPreview } : f ) ); }; reader.readAsText(file); } return { id: `file-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, name: file.name, size: file.size, type: file.type, textPreview }; }); setFiles((prev) => [...prev, ...processedFiles]); }; const handleRemoveFile = (fileId) => { setFiles((prev) => prev.filter((file) => file.id !== fileId)); }; useEffect(() => { feather.replace(); }, [messages, files, workflows]); return React.createElement( AgentContext.Provider, { value: agentInstance }, React.createElement( 'div', { className: 'flex flex-col h-screen' }, // Header React.createElement( 'header', { className: 'bg-slate-800 border-b border-slate-700 p-4' }, React.createElement( 'div', { className: 'flex items-center justify-between' }, React.createElement( 'div', { className: 'flex items-center gap-3' }, React.createElement( 'div', { className: 'w-10 h-10 rounded-lg bg-gradient-to-br from-primary-500 to-secondary-500 flex items-center justify-center' }, React.createElement('i', { 'data-feather': 'cpu', className: 'text-white' }) ), React.createElement( 'div', null, React.createElement( 'h1', { className: 'text-xl font-bold' }, 'TaskPilot' ), React.createElement( 'p', { className: 'text-xs text-slate-400' }, 'Your Personal AI Task Agent' ) ) ), React.createElement( 'div', { className: 'flex items-center gap-2' }, React.createElement( 'span', { className: 'px-2 py-1 bg-slate-700 text-xs rounded-full' }, 'MetaEvolver' ), React.createElement( 'span', { className: 'px-2 py-1 bg-slate-700 text-xs rounded-full' }, 'AutoLoop' ) ) ) ), // Main Content React.createElement( 'div', { className: 'flex flex-1 overflow-hidden' }, // Chat Panel - Left React.createElement( 'div', { className: 'w-1/3 panel-border flex flex-col' }, React.createElement(ChatPanel, { messages: messages, onSendMessage: handleSendMessage, onFeedback: handleFeedback }) ), // Workflow Panel - Middle React.createElement( 'div', { className: 'w-1/3 panel-border flex flex-col' }, React.createElement(WorkflowPanel, { workflows: workflows, onStartWorkflow: handleStartWorkflow, onUpdateStepStatus: handleUpdateStepStatus }) ), // Files & Inspector Panel - Right React.createElement( 'div', { className: 'w-1/3 flex flex-col' }, React.createElement(FilesInspectorPanel, { files: files, onFileUpload: handleFileUpload, onRemoveFile: handleRemoveFile, policyState: policyState, reasoningTrace: reasoningTrace }) ) ) ) ); }; // Render the app const root = ReactDOM.createRoot(document.getElementById('root')); root.render(React.createElement(App));
// Import necessary React features
const { useState, useEffect, useRef, createContext, useContext } = React;
// Interfaces (documentation objects, not used at runtime)
const ChatMessage = {
id: '',
role: 'user', // or 'agent'
text: '',
timestamp: '',
workflowStepId: undefined
};
const UploadedFile = {
id: '',
name: '',
size: 0,
type: '',
textPreview: undefined
};
const WorkflowStep = {
id: '',
title: '',
description: '',
status: 'pending', // 'pending' | 'in_progress' | 'done' | 'skipped'
relatedFiles: []
};
const AgentWorkflow = {
id: '',
name: '',
steps: []
};
const PolicyState = {
// These values now match what the agent actually uses
detailLevel: 'medium', // 'concise' | 'medium' | 'detailed'
tone: 'neutral', // 'concise' | 'neutral' | 'detailed'
preferredWorkflowTemplates: [],
recentSuccessRate: 0.85
};
const AgentTurn = {
responseMessage: '',
steps: [],
reasoningTrace: '',
policyState: PolicyState
};
// TaskPilotAgent Class
class TaskPilotAgent {
constructor() {
this.policyState = { ...PolicyState };
this.workflows = [];
this.workflowTemplates = {
shopify: {
id: 'shopify',
name: 'Take a Shopify store live',
steps: [
{ id: 's1', title: 'Configure domain settings', description: 'Set up custom domain for the store', status: 'pending', relatedFiles: [] },
{ id: 's2', title: 'Add payment gateways', description: 'Configure accepted payment methods', status: 'pending', relatedFiles: [] },
{ id: 's3', title: 'Set up shipping zones', description: 'Define shipping regions and rates', status: 'pending', relatedFiles: [] },
{ id: 's4', title: 'Review tax settings', description: 'Configure tax calculations for products', status: 'pending', relatedFiles: [] },
{ id: 's5', title: 'Launch store', description: 'Remove password protection and go live', status: 'pending', relatedFiles: [] }
]
},
website: {
id: 'website',
name: 'Create a simple marketing website',
steps: [
{ id: 'w1', title: 'Define target audience', description: 'Identify key demographics and personas', status: 'pending', relatedFiles: [] },
{ id: 'w2', title: 'Create site map', description: 'Plan website structure and navigation', status: 'pending', relatedFiles: [] },
{ id: 'w3', title: 'Design homepage layout', description: 'Create wireframes for key landing page', status: 'pending', relatedFiles: [] },
{ id: 'w4', title: 'Develop core pages', description: 'Build About, Services, and Contact pages', status: 'pending', relatedFiles: [] },
{ id: 'w5', title: 'Test and launch', description: 'Perform QA testing and deploy to production', status: 'pending', relatedFiles: [] }
]
},
'ux-review': {
id: 'ux-review',
name: 'Review and improve a page’s UI/UX',
steps: [
{ id: 'u1', title: 'Heuristic evaluation', description: 'Assess against UX best practices', status: 'pending', relatedFiles: [] },
{ id: 'u2', title: 'User flow analysis', description: 'Map current navigation paths', status: 'pending', relatedFiles: [] },
{ id: 'u3', title: 'Accessibility check', description: 'Verify WCAG compliance standards', status: 'pending', relatedFiles: [] },
{ id: 'u4', title: 'Performance audit', description: 'Analyze loading times and optimizations', status: 'pending', relatedFiles: [] },
{ id: 'u5', title: 'Implement improvements', description: 'Apply recommended changes to interface', status: 'pending', relatedFiles: [] }
]
}
};
}
_getActiveWorkflow() {
return this.workflows.length > 0 ? this.workflows[0] : null;
}
_getNextStep() {
const wf = this._getActiveWorkflow();
if (!wf) return null;
return (