Spaces:
Running

Destiny369963 commited on
Commit
b6a1fe0
·
verified ·
1 Parent(s): a2730b6

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 }
};
}

1 file changed +80 -34
script.js+80-34