Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

Improve agent activity timing and tool UI

Abi Raja3ba5a28d6612
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 5f0b16c4..f799b205 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -84,6 +84,7 @@ function App() {
const wsRef = useRef<WebSocket>(null);
const lastThinkingEventIdRef = useRef<Record<number, string>>({});
const lastAssistantEventIdRef = useRef<Record<number, string>>({});
+ const lastToolEventIdRef = useRef<Record<number, string>>({});
const showSelectAndEditFeature =
settings.generatedCodeConfig === Stack.HTML_TAILWIND ||
@@ -213,6 +214,7 @@ function App() {
lastThinkingEventIdRef.current = {};
lastAssistantEventIdRef.current = {};
+ lastToolEventIdRef.current = {};
generateCode(wsRef, updatedParams, {
onChange: (token, variantIndex) => {
@@ -244,6 +246,14 @@ function App() {
endedAt: Date.now(),
});
}
+ const lastTool = lastToolEventIdRef.current[variantIndex];
+ if (lastTool) {
+ finishAgentEvent(commit.hash, variantIndex, lastTool, {
+ status: "error",
+ endedAt: Date.now(),
+ });
+ delete lastToolEventIdRef.current[variantIndex];
+ }
},
onVariantCount: (count) => {
console.log(`Backend is using ${count} variants`);
@@ -295,6 +305,7 @@ function App() {
input: data?.input,
startedAt: Date.now(),
});
+ lastToolEventIdRef.current[variantIndex] = eventId;
},
onToolResult: (data, variantIndex, eventId) => {
if (!eventId) return;
@@ -303,6 +314,9 @@ function App() {
output: data?.output,
endedAt: Date.now(),
});
+ if (lastToolEventIdRef.current[variantIndex] === eventId) {
+ delete lastToolEventIdRef.current[variantIndex];
+ }
},
onCancel: () => {
cancelCodeGenerationAndReset(commit);
@@ -310,6 +324,7 @@ function App() {
onComplete: () => {
const lastThinking = lastThinkingEventIdRef.current;
const lastAssistant = lastAssistantEventIdRef.current;
+ const lastTool = lastToolEventIdRef.current;
Object.keys(lastThinking).forEach((key) => {
const idx = Number(key);
finishAgentEvent(commit.hash, idx, lastThinking[idx], {
@@ -324,6 +339,13 @@ function App() {
endedAt: Date.now(),
});
});
+ Object.keys(lastTool).forEach((key) => {
+ const idx = Number(key);
+ finishAgentEvent(commit.hash, idx, lastTool[idx], {
+ status: "complete",
+ endedAt: Date.now(),
+ });
+ });
setAppState(AppState.CODE_READY);
},
});
diff --git a/frontend/src/components/agent/AgentActivity.tsx b/frontend/src/components/agent/AgentActivity.tsx
index ebf47b01..3a3dc896 100644
--- a/frontend/src/components/agent/AgentActivity.tsx
+++ b/frontend/src/components/agent/AgentActivity.tsx
@@ -25,22 +25,36 @@ function getPreview(text: string): string {
return `${cleaned.slice(0, 140)}...`;
}
+function isFiniteNumber(value: unknown): value is number {
+ return typeof value === "number" && Number.isFinite(value);
+}
+
+function formatDurationMs(milliseconds: number): string {
+ const seconds = Math.max(1, Math.round(milliseconds / 1000));
+ if (seconds < 60) return `${seconds}s`;
+ const minutes = Math.floor(seconds / 60);
+ const remainingSeconds = seconds % 60;
+ if (minutes < 60) return `${minutes}m ${remainingSeconds}s`;
+ const hours = Math.floor(minutes / 60);
+ const remainingMinutes = minutes % 60;
+ return `${hours}h ${remainingMinutes}m`;
+}
+
function formatDuration(startedAt?: number, endedAt?: number): string {
- if (!startedAt || !endedAt) return "";
- const seconds = Math.max(1, Math.round((endedAt - startedAt) / 1000));
- return `${seconds}s`;
+ if (!isFiniteNumber(startedAt) || !isFiniteNumber(endedAt)) return "";
+ return formatDurationMs(endedAt - startedAt);
}
function formatTotalDuration(events: AgentEvent[]): string {
if (events.length === 0) return "";
const now = Date.now();
- const totalMs = events.reduce((sum, event) => {
- const end = event.endedAt ?? now;
+ const totalMs = events.reduce((acc, event) => {
+ if (!isFiniteNumber(event.startedAt)) return acc;
+ const end = isFiniteNumber(event.endedAt) ? event.endedAt : now;
const duration = Math.max(0, end - event.startedAt);
- return sum + duration;
+ return acc + duration;
}, 0);
- const seconds = Math.max(1, Math.round(totalMs / 1000));
- return `${seconds}s`;
+ return totalMs > 0 ? formatDurationMs(totalMs) : "";
}
function getStatusTone(status: AgentEventStatus) {
@@ -115,6 +129,30 @@ function getEventTitle(event: AgentEvent): string {
return "Activity";
}
+function getToolSummary(event: AgentEvent): string | null {
+ if (event.type !== "tool") return null;
+ const output = event.output as any;
+ if (output?.error) {
+ return `Error: ${output.error}`;
+ }
+ if (event.toolName === "create_file") {
+ const path = output?.path ?? "index.html";
+ const length = output?.contentLength;
+ return length ? `Created ${path} · ${length} chars` : `Created ${path}`;
+ }
+ if (event.toolName === "edit_file") {
+ const edits = Array.isArray(output?.edits) ? output.edits.length : 0;
+ return edits ? `${edits} edit${edits > 1 ? "s" : ""} applied` : "Edits applied";
+ }
+ if (event.toolName === "generate_images") {
+ const images = Array.isArray(output?.images) ? output.images.length : 0;
+ return images
+ ? `${images} image${images > 1 ? "s" : ""} generated`
+ : "Images generated";
+ }
+ return "Tool completed";
+}
+
function renderToolDetails(event: AgentEvent) {
if (!event.input && !event.output) return null;
@@ -136,50 +174,146 @@ function renderToolDetails(event: AgentEvent) {
);
};
+ const output = event.output as any;
+ const hasError = Boolean(output?.error);
const images =
- event.output && Array.isArray((event.output as any).images)
- ? ((event.output as any).images as Array<any>)
- : null;
+ output && Array.isArray(output.images) ? (output.images as Array<any>) : null;
+ const edits =
+ output && Array.isArray(output.edits) ? (output.edits as Array<any>) : null;
return (
<div className="text-sm text-gray-700 dark:text-gray-200">
- {event.input && (
- <div>
- <div className="text-xs uppercase tracking-wide text-gray-400">
- Input
+ {hasError && (
+ <div className="rounded-md border border-red-200 dark:border-red-700 bg-red-50 dark:bg-red-900/30 p-3">
+ <div className="text-xs uppercase tracking-wide text-red-500">Error</div>
+ <div className="mt-1 text-sm text-red-700 dark:text-red-200">
+ {output?.error}
</div>
- {renderJson(event.input)}
+ {event.input && (
+ <div className="mt-2">
+ <div className="text-xs uppercase tracking-wide text-red-400">
+ Input
+ </div>
+ {renderJson(event.input)}
+ </div>
+ )}
</div>
)}
- {event.output && (
- <div className="mt-3">
- <div className="text-xs uppercase tracking-wide text-gray-400">
- Output
+ {event.toolName === "create_file" && !hasError && (
+ <div className="rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900/60 p-3">
+ <div className="flex items-center justify-between">
+ <div className="text-xs uppercase tracking-wide text-gray-400">
+ File
+ </div>
+ {output?.contentLength && (
+ <div className="text-xs text-gray-500">
+ {output.contentLength} characters
+ </div>
+ )}
+ </div>
+ <div className="mt-1 text-sm font-medium text-gray-800 dark:text-gray-100">
+ {output?.path ?? "index.html"}
</div>
- {images ? (
- <div className="mt-2 space-y-2">
- {images.map((item, index) => (
- <div
- key={`${item.prompt}-${index}`}
- className="flex items-start justify-between gap-3 rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900/60 p-2"
- >
- <div>
- <div className="text-xs text-gray-500">Prompt</div>
- <div className="text-sm text-gray-700 dark:text-gray-100">
- {item.prompt}
- </div>
+ {output?.preview && (
+ <pre className="mt-2 rounded bg-gray-50 dark:bg-gray-800 p-2 text-xs text-gray-700 dark:text-gray-200 line-clamp-4 overflow-hidden">
+ {output.preview}
+ </pre>
+ )}
+ </div>
+ )}
+
+ {event.toolName === "edit_file" && edits && !hasError && (
+ <div className="space-y-2">
+ {edits.map((edit, index) => (
+ <div
+ key={`${edit.old_text}-${index}`}
+ className="rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900/60 p-3"
+ >
+ <div className="text-xs uppercase tracking-wide text-gray-400">
+ Edit {index + 1}
+ </div>
+ <div className="mt-2 grid gap-2">
+ <div>
+ <div className="text-xs text-gray-500">Old</div>
+ <div className="mt-1 rounded bg-red-50 dark:bg-red-900/30 p-2 text-xs font-mono text-red-700 dark:text-red-200 break-all">
+ {edit.old_text}
</div>
- <div className="text-xs text-gray-500">
- {item.status === "ok" ? "✓" : "⚠"}
+ </div>
+ <div>
+ <div className="text-xs text-gray-500">New</div>
+ <div className="mt-1 rounded bg-emerald-50 dark:bg-emerald-900/30 p-2 text-xs font-mono text-emerald-700 dark:text-emerald-200 break-all">
+ {edit.new_text}
</div>
</div>
- ))}
+ </div>
+ {edit.replaced !== undefined && (
+ <div className="mt-2 text-xs text-gray-500">
+ Replaced {edit.replaced} time{edit.replaced === 1 ? "" : "s"}
+ </div>
+ )}
</div>
- ) : (
- renderJson(event.output)
- )}
+ ))}
</div>
)}
+
+ {event.toolName === "generate_images" && images && !hasError && (
+ <div className="space-y-2">
+ {images.map((item, index) => (
+ <div
+ key={`${item.prompt}-${index}`}
+ className="flex items-start gap-3 rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900/60 p-3"
+ >
+ {item.url ? (
+ <img
+ src={item.url}
+ alt={item.prompt || `Generated image ${index + 1}`}
+ className="h-16 w-16 rounded-md object-cover border border-gray-200 dark:border-gray-700"
+ loading="lazy"
+ />
+ ) : (
+ <div className="h-16 w-16 rounded-md bg-gray-100 dark:bg-gray-800 flex items-center justify-center text-xs text-gray-400">
+ N/A
+ </div>
+ )}
+ <div className="flex-1">
+ <div className="text-xs text-gray-500">Prompt</div>
+ <div className="text-sm text-gray-700 dark:text-gray-100">
+ {item.prompt}
+ </div>
+ {item.url && (
+ <div className="text-xs text-gray-500 mt-1 truncate">
+ {item.url}
+ </div>
+ )}
+ </div>
+ <div className="text-xs text-gray-500">
+ {item.status === "ok" ? "✓" : "⚠"}
+ </div>
+ </div>
+ ))}
+ </div>
+ )}
+
+ {!event.toolName && !hasError && (
+ <>
+ {event.input && (
+ <div>
+ <div className="text-xs uppercase tracking-wide text-gray-400">
+ Input
+ </div>
+ {renderJson(event.input)}
+ </div>
+ )}
+ {event.output && (
+ <div className="mt-3">
+ <div className="text-xs uppercase tracking-wide text-gray-400">
+ Output
+ </div>
+ {renderJson(event.output)}
+ </div>
+ )}
+ </>
+ )}
</div>
);
}
@@ -202,6 +336,7 @@ function AgentEventCard({
const isExpanded =
(event.type !== "thinking" && event.status === "running") || expanded;
const preview = useMemo(() => getPreview(event.content || ""), [event.content]);
+ const toolSummary = useMemo(() => getToolSummary(event), [event]);
return (
<div
@@ -236,10 +371,10 @@ function AgentEventCard({
{event.type === "tool" && renderToolDetails(event)}
</div>
) : (
- preview &&
- event.type !== "thinking" && (
+ event.type !== "thinking" &&
+ (event.type === "tool" ? toolSummary : preview) && (
<div className="px-3 pb-2 text-xs text-gray-500 dark:text-gray-400">
- {preview}
+ {event.type === "tool" ? toolSummary : preview}
</div>
)
)}
@@ -259,6 +394,8 @@ function AgentActivity() {
const lastAssistantId = [...events]
.reverse()
.find((event) => event.type === "assistant")?.id;
+ const hasRunning = events.some((event) => event.status === "running");
+ const totalDuration = formatTotalDuration(events);
const isLatestCommit = head === latestCommitHash;
if (!isLatestCommit || events.length === 0) {
@@ -272,7 +409,7 @@ function AgentActivity() {
Agent activity
</div>
<div className="text-xs font-semibold text-gray-700 dark:text-gray-200">
- Total time {formatTotalDuration(events)}
+ {hasRunning ? "Time so far" : "Total time"} {totalDuration || "--"}
</div>
</div>
{events.map((event) => (