Spaces:
Running
async handleUserMessage(message, files = []) {
Browse files// Mock AI processing delay
await new Promise((resolve) => setTimeout(resolve, 400));
const lower = message.toLowerCase();
let response = "";
let reasoning = "Processed user input";
const activeWorkflow = this._getActiveWorkflow();
const nextStep = this._getNextStep();
const hasFiles = files && files.length > 0;
const wantsAnalysis =
(lower.includes("analyze") || lower.includes("analyse") || lower.includes("review file")) &&
hasFiles;
// 1) File analysis mode
if (wantsAnalysis) {
reasoning = "User asked for file analysis; generating structured summary.";
const fileSummaries = files.map((f, idx) => {
const snippet = (f.textPreview || "")
.replace(/\s+/g, " ")
.trim()
.slice(0, 180);
let typeHint = "generic file";
if (f.name.endsWith(".json")) typeHint = "JSON config or data file";
else if (f.name.endsWith(".csv")) typeHint = "tabular data (CSV)";
else if (f.name.endsWith(".html") || f.name.endsWith(".htm")) typeHint = "HTML/markup file";
else if (f.name.endsWith(".txt") || f.type.startsWith("text/")) typeHint = "text document";
return `File ${idx + 1}: **${f.name}** (${typeHint}, ${(f.size / 1024).toFixed(
1
)} KB)` +
(snippet
? `\n Preview: "${snippet}${f.textPreview && f.textPreview.length > 180 ? "..." : ""}"`
: "\n Preview: (no text preview available)");
});
response =
`Here’s what I can see from the uploaded file(s):\n\n` +
fileSummaries.join("\n\n") +
`\n\nTell me what you want to *do* with this (e.g., "use this as copy for my homepage", "find UX issues", "extract product list").`;
// Add workflow context if there is one
if (activeWorkflow && nextStep) {
response += `\n\nCurrent workflow: "${activeWorkflow.name}". Suggested link: apply this file to **${nextStep.title}** (${nextStep.description}).`;
reasoning += " | Attached analysis to current workflow step.";
}
return {
responseMessage: response,
steps: activeWorkflow ? [...activeWorkflow.steps] : [],
reasoningTrace: reasoning,
policyState: { ...this.policyState }
};
}
// 2) Normal conversational / workflow guidance mode
if (lower.includes("hello") || lower.includes("hi ")) {
response = "Hello 👋 I'm TaskPilot. Tell me what you’re trying to get done, or use the Target / Task / Verify selectors in the middle panel.";
reasoning = "Greeting detected, provided welcome message.";
} else if (lower.includes("help")) {
response =
"I can walk you through launches, builds, and reviews.\n\n" +
"Options:\n" +
"• Use the middle panel to select Target → Task → Verify.\n" +
"• Or just say something like \"launch my Shopify store\" or \"review this page’s UX\".";
reasoning = "Help request detected, explained control surface.";
} else if (activeWorkflow && nextStep) {
response =
`We’re currently running: **${activeWorkflow.name}**.\n` +
`Next step is **${nextStep.title}**:\n${nextStep.description}\n\n` +
`Tell me when you're ready and I’ll break this step into micro-actions.`;
reasoning =
"Active workflow detected; responded with next actionable step instead of generic text.";
} else {
response =
"Got it. I’ve logged your message.\n\n" +
"If this is a multi-step job, either:\n" +
"• Use the middle panel to pick Target → Task → Verify, or\n" +
"• Say something like \"launch my Shopify store\" / \"create a simple website\" / \"review the UX of this page\".";
reasoning = "No specific intent recognised beyond general message; nudged user to structured workflows.";
}
// Update policy based on message length
if (message.length > 100) {
this.policyState.detailLevel = "detailed";
reasoning += " | Long input, set detailLevel=detailed.";
} else if (message.length < 20) {
this.policyState.detailLevel = "concise";
reasoning += " | Short input, set detailLevel=concise.";
} else {
this.policyState.detailLevel = "medium";
}
return {
responseMessage: response,
steps: activeWorkflow ? [...activeWorkflow.steps] : [],
reasoningTrace: reasoning,
policyState: { ...this.policyState }
};
}
102 unmodified lines1031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551563 unmodified lines160161162163164165166167102 unmodified linesnull);}async handleUserMessage(message, files = []) {// Mock AI processing delayawait new Promise((resolve) => setTimeout(resolve, 800));const lower = message.toLowerCase();// Base response / reasoninglet response = "I've received your message. How can I assist you further?";let reasoning = 'Processed user input';// Very simple intent detectionif (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. You can use the selectors to choose a Target, Task, and Verification mode, then I’ll guide you step by step.";reasoning = 'Help request detected, provided assistance options';} else {response = "Got it. I'll align this with your current workflows where possible.";reasoning = 'General message handled';}// If files are present, acknowledge them explicitlyif (files.length > 0) {const fileNames = files.map((f) => f.name).join(', ');response += `\n\nI see you've uploaded ${files.length} file(s): ${fileNames}. I'll treat these as context while we work.`;reasoning += ' | Files detected and listed as available context';}// If there is an active workflow, surface its next stepconst activeWorkflow = this._getActiveWorkflow();const nextStep = this._getNextStep();if (activeWorkflow && nextStep) {response += `\n\nCurrent workflow: "${activeWorkflow.name}". Next step: ${nextStep.title} – ${nextStep.description}`;reasoning += ' | Included guidance from active workflow';}// Update policy based on message lengthif (message.length > 100) {this.policyState.detailLevel = 'detailed';reasoning += ' | User provided detailed input, switching to detailed mode';} else if (message.length < 20) {this.policyState.detailLevel = 'concise';reasoning += ' | User provided brief input, switching to concise mode';} else {this.policyState.detailLevel = 'medium';}return {3 unmodified linespolicyState: { ...this.policyState }};}startWorkflow(templateId, userInputs = {}) {const template = this.workflowTemplates[templateId];if (!template) {throw new Error(`Template ${templateId} not found`);102 unmodified lines1031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022033 unmodified lines207208209210211212213102 unmodified linesnull);}async handleUserMessage(message, files = []) {// Mock AI processing delayawait new Promise((resolve) => setTimeout(resolve, 400));const lower = message.toLowerCase();let response = "";let reasoning = "Processed user input";const activeWorkflow = this._getActiveWorkflow();const nextStep = this._getNextStep();const hasFiles = files && files.length > 0;const wantsAnalysis =(lower.includes("analyze") || lower.includes("analyse") || lower.includes("review file")) &&hasFiles;// 1) File analysis modeif (wantsAnalysis) {reasoning = "User asked for file analysis; generating structured summary.";const fileSummaries = files.map((f, idx) => {const snippet = (f.textPreview || "").replace(/\s+/g, " ").trim().slice(0, 180);let typeHint = "generic file";if (f.name.endsWith(".json")) typeHint = "JSON config or data file";else if (f.name.endsWith(".csv")) typeHint = "tabular data (CSV)";else if (f.name.endsWith(".html") || f.name.endsWith(".htm")) typeHint = "HTML/markup file";else if (f.name.endsWith(".txt") || f.type.startsWith("text/")) typeHint = "text document";return `File ${idx + 1}: **${f.name}** (${typeHint}, ${(f.size / 1024).toFixed(1)} KB)` +(snippet? `\n Preview: "${snippet}${f.textPreview && f.textPreview.length > 180 ? "..." : ""}"`: "\n Preview: (no text preview available)");});response =`Here’s what I can see from the uploaded file(s):\n\n` +fileSummaries.join("\n\n") +`\n\nTell me what you want to *do* with this (e.g., "use this as copy for my homepage", "find UX issues", "extract product list").`;// Add workflow context if there is oneif (activeWorkflow && nextStep) {response += `\n\nCurrent workflow: "${activeWorkflow.name}". Suggested link: apply this file to **${nextStep.title}** (${nextStep.description}).`;reasoning += " | Attached analysis to current workflow step.";}return {responseMessage: response,steps: activeWorkflow ? [...activeWorkflow.steps] : [],reasoningTrace: reasoning,policyState: { ...this.policyState }};}// 2) Normal conversational / workflow guidance modeif (lower.includes("hello") || lower.includes("hi ")) {response = "Hello 👋 I'm TaskPilot. Tell me what you’re trying to get done, or use the Target / Task / Verify selectors in the middle panel.";reasoning = "Greeting detected, provided welcome message.";} else if (lower.includes("help")) {response ="I can walk you through launches, builds, and reviews.\n\n" +"Options:\n" +"• Use the middle panel to select Target → Task → Verify.\n" +"• Or just say something like \"launch my Shopify store\" or \"review this page’s UX\".";reasoning = "Help request detected, explained control surface.";} else if (activeWorkflow && nextStep) {response =`We’re currently running: **${activeWorkflow.name}**.\n` +`Next step is **${nextStep.title}**:\n${nextStep.description}\n\n` +`Tell me when you're ready and I’ll break this step into micro-actions.`;reasoning ="Active workflow detected; responded with next actionable step instead of generic text.";} else {response ="Got it. I’ve logged your message.\n\n" +"If this is a multi-step job, either:\n" +"• Use the middle panel to pick Target → Task → Verify, or\n" +"• Say something like \"launch my Shopify store\" / \"create a simple website\" / \"review the UX of this page\".";reasoning = "No specific intent recognised beyond general message; nudged user to structured workflows.";}// Update policy based on message lengthif (message.length > 100) {this.policyState.detailLevel = "detailed";reasoning += " | Long input, set detailLevel=detailed.";} else if (message.length < 20) {this.policyState.detailLevel = "concise";reasoning += " | Short input, set detailLevel=concise.";} else {this.policyState.detailLevel = "medium";}return {3 unmodified linespolicyState: { ...this.policyState }};}startWorkflow(templateId, userInputs = {}) {const template = this.workflowTemplates[templateId];if (!template) {throw new Error(`Template ${templateId} not found`);