Skip to content

Commit f85331d

Browse files
committed
refactor: improve type definitions and add example prompts in App component
1 parent e909eba commit f85331d

1 file changed

Lines changed: 46 additions & 9 deletions

File tree

frontend/components/App.tsx

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import { Input } from "@/components/ui/input";
1414
import { Loader2, Copy, Settings } from "lucide-react";
1515

1616
type WorkflowResult = {
17-
workflow?: any;
17+
workflow?: Record<string, unknown>;
1818
keywords?: string[];
19-
searchResults?: any[];
20-
nodes?: any[];
19+
searchResults?: unknown[];
20+
nodes?: unknown[];
2121
[key: string]: unknown;
2222
};
2323

24-
function parseSSEMessage(chunk: string): { event: string; data: any } | null {
24+
function parseSSEMessage(chunk: string): { event: string; data: unknown } | null {
2525
const lines = chunk.split("\n").filter((line) => line.trim() !== "");
2626
let event = "message"; // Default event type
2727
let data = "";
@@ -194,24 +194,28 @@ function App() {
194194
const parsed = parseSSEMessage(message);
195195
if (parsed) {
196196
if (parsed.event === "progress") {
197-
const { step, status, message } = parsed.data;
198-
setProgressMessage(message || `Processing step: ${step}...`);
197+
// Type guard for progress event
198+
const data = parsed.data as { step?: string; status?: string; message?: string };
199+
const { step, status, message: progressMsg } = data;
200+
setProgressMessage(progressMsg || (step ? `Processing step: ${step}...` : "Processing..."));
199201
// Update step index when a step is completed
200-
if (status === "completed") {
202+
if (step && status === "completed") {
201203
const stepIndex = generationSteps.indexOf(step);
202204
if (stepIndex > currentStepIndex) {
203205
// Ensure we only move forward
204206
setCurrentStepIndex(stepIndex);
205207
}
206208
}
207209
} else if (parsed.event === "result") {
208-
setFinalResult(parsed.data);
210+
setFinalResult(parsed.data as WorkflowResult);
209211
setProgressMessage("Workflow generated successfully!");
210212
setCurrentStepIndex(generationSteps.length); // Mark all steps as done
211213
setIsLoading(false); // Set loading false on final result
212214
} else if (parsed.event === "error") {
215+
// Type guard for error event
216+
const data = parsed.data as { error?: string };
213217
setError(
214-
parsed.data.error ||
218+
data.error ||
215219
"An unknown error occurred during generation.",
216220
);
217221
setProgressMessage(null); // Clear progress on error
@@ -337,7 +341,40 @@ function App() {
337341

338342
{/* Prompt Input Section */}
339343
<div className="p-6 space-y-6">
344+
{/* Example Prompts */}
340345
<div>
346+
{/* Example prompts array */}
347+
{(() => {
348+
const examples = [
349+
"Create a workflow to send weekly reports from Google Sheets to Slack",
350+
"Monitor a Gmail inbox and save attachments to Dropbox",
351+
"Post a daily summary of new GitHub issues to Microsoft Teams",
352+
"Sync new Airtable records to a Notion database",
353+
"Send an SMS via Twilio when a Stripe payment is received",
354+
"Backup files from Google Drive to AWS S3 every Friday",
355+
"Alert me on Telegram when a website is down",
356+
"Extract data from incoming emails and add to Google Sheets"
357+
];
358+
return (
359+
<div className="mb-4">
360+
<div className="text-xs text-gray-500 dark:text-gray-400 mb-2">
361+
Example prompts:
362+
</div>
363+
<div className="flex flex-wrap gap-2">
364+
{examples.map((ex) => (
365+
<button
366+
key={ex}
367+
type="button"
368+
onClick={() => setPrompt(ex)}
369+
className="px-3 py-1 rounded-full bg-blue-50 dark:bg-blue-900 text-blue-700 dark:text-blue-200 text-xs hover:bg-blue-100 dark:hover:bg-blue-800 border border-blue-100 dark:border-blue-800 transition"
370+
>
371+
{ex}
372+
</button>
373+
))}
374+
</div>
375+
</div>
376+
);
377+
})()}
341378
<label
342379
htmlFor="prompt"
343380
className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2"

0 commit comments

Comments
 (0)