Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(chat): show live generation progress for tool calls (#4703)

Harsh Kumar60678326bd13
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx
index 22e03d444..47c528343 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/chat-message-list.tsx
@@ -94,14 +94,17 @@ export function ChatMessageList({
{(() => {
const visibleMessages = messages.filter((m) => {
if (m.role !== "assistant") return true;
- if (m.content === "Processing..." && !m.contentBlocks?.length) return false;
- if (!m.content && !m.contentBlocks?.length && !isSteeredAssistantMessage(m)) return false;
+ if (m.content === "Processing..." && !m.contentBlocks?.length && !m.stoppedByUser) return false;
+ if (!m.content && !m.contentBlocks?.length && !isSteeredAssistantMessage(m) && !m.stoppedByUser) return false;
return true;
});
const renderItems = buildCollapsedSteerRenderItems(visibleMessages, {
canCollapseSteerWork: !isLoading && !isStreaming && !activeSourceFooterMessageId,
});
+ const activeAssistantMessageId =
+ activeSourceFooterMessageId ??
+ [...visibleMessages].reverse().find((candidate) => candidate.role === "assistant")?.id;
return renderItems.map((item) => {
if (item.type === "collapsed-steer-work") {
@@ -131,7 +134,7 @@ export function ChatMessageList({
const isActiveStreamingAssistantMessage =
message.role === "assistant" &&
(isLoading || isStreaming) &&
- message.id === activeSourceFooterMessageId;
+ message.id === activeAssistantMessageId;
const shouldShowMessageActionBar =
canShowMessageActions && !isActiveStreamingAssistantMessage;
const nextAssistant = visibleMessages
@@ -201,7 +204,7 @@ export function ChatMessageList({
"relative rounded-xl text-sm overflow-hidden max-w-full transition-all",
message.role === "user"
? "bg-muted/60 text-foreground px-4 py-3"
- : "bg-background text-foreground py-1",
+ : "bg-background text-foreground py-1 w-full",
canEditMessage && editingMessageId !== message.id && "cursor-text",
editingMessageId === message.id && message.role === "user" && "w-full"
)}
@@ -264,6 +267,7 @@ export function ChatMessageList({
) : (
<MessageContent
message={message}
+ isGenerating={isActiveStreamingAssistantMessage}
deferSourceFooter={
suppressSourceFooters ||
citationPlan.deferredMessageIds.has(message.id) ||
@@ -279,7 +283,12 @@ export function ChatMessageList({
{!hideSupersededSteerBody && shouldShowMessageActionBar ? (
<>
{editingMessageId !== message.id && (
- <div className="flex items-center gap-0.5 self-end mt-1 opacity-0 group-hover/message:opacity-100 group-focus-within/message:opacity-100 transition-all duration-200">
+ <div
+ className={cn(
+ "flex items-center gap-0.5 mt-1 opacity-0 group-hover/message:opacity-100 group-focus-within/message:opacity-100 transition-all duration-200",
+ message.role === "assistant" ? "self-start" : "self-end"
+ )}
+ >
<button
onClick={() => onCopyMessage(message)}
className="p-1 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground"
@@ -411,8 +420,8 @@ export function ChatMessageList({
exit={{ opacity: 0, y: -5 }}
transition={{ duration: 0.15 }}
className={cn(
- "w-fit ml-auto",
- loaderPhase === "streaming"
+ "w-fit self-start",
+ loaderPhase === "streaming" || loaderPhase === "analyzing"
? "px-2 py-1"
: "px-3 py-2 border border-border/50"
)}
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-foreground-events.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-foreground-events.ts
index 898b01a68..590f825f7 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-foreground-events.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-foreground-events.ts
@@ -334,6 +334,7 @@ export function usePiForegroundEvents({
toolName: stringValue(data.toolName, "unknown"),
args: isRecord(data.args) ? data.args : {},
isRunning: true,
+ startedAtMs: Date.now(),
};
// Add tool block (text before it is already its own block)
piContentBlocksRef.current.push({ type: "tool", toolCall });
@@ -356,6 +357,7 @@ export function usePiForegroundEvents({
block.toolCall.isRunning = false;
block.toolCall.result = truncated;
block.toolCall.isError = data.isError === true;
+ block.toolCall.endedAtMs = Date.now();
}
}
const contentBlocks = [...piContentBlocksRef.current];
@@ -752,7 +754,18 @@ export function usePiForegroundEvents({
contentBlocks.push({ type: "text", text: content });
}
return prev.map((m) => m.id === msgId
- ? { ...m, content, contentBlocks, ...(emptyResponseRetryPrompt ? { retryPrompt: emptyResponseRetryPrompt } : {}) }
+ ? {
+ ...m,
+ content,
+ contentBlocks,
+ ...(wasStoppedByUser
+ ? {
+ workDurationMs: Math.max(1, Date.now() - m.timestamp),
+ stoppedByUser: true,
+ }
+ : {}),
+ ...(emptyResponseRetryPrompt ? { retryPrompt: emptyResponseRetryPrompt } : {}),
+ }
: m);
});
if (!isPipeWatch) {
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-live-send.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-live-send.ts
index 039d89be8..cbbba17f7 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-live-send.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-live-send.ts
@@ -12,22 +12,26 @@ import type { PiSendTransportOptions } from "@/components/chat/standalone/hooks/
export function usePiLiveSendControls({
abortControllerRef,
activePipeExecution,
+ cancelStreamingMessageRender,
piActiveStopRequestedRef,
piContentBlocksRef,
piMessageIdRef,
piSessionIdRef,
piStreamingTextRef,
+ setMessages,
setIsLoading,
setIsStreaming,
}: Pick<
PiSendTransportOptions,
| "abortControllerRef"
| "activePipeExecution"
+ | "cancelStreamingMessageRender"
| "piActiveStopRequestedRef"
| "piContentBlocksRef"
| "piMessageIdRef"
| "piSessionIdRef"
| "piStreamingTextRef"
+ | "setMessages"
| "setIsLoading"
| "setIsStreaming"
>) {
@@ -45,6 +49,48 @@ export function usePiLiveSendControls({
const handleStop = async () => {
if (!activePipeExecution) {
piActiveStopRequestedRef.current = true;
+ cancelStreamingMessageRender();
+ const stoppedAtMs = Date.now();
+ const stoppedMessageId = piMessageIdRef.current;
+ const stoppedText = piStreamingTextRef.current;
+ const stoppedBlocks = [...piContentBlocksRef.current];
+
+ if (stoppedMessageId) {
+ setMessages((prev) => prev.map((message) => {
+ if (message.id !== stoppedMessageId || message.role !== "assistant") return message;
+
+ const contentBlocks = (stoppedBlocks.length > 0 ? stoppedBlocks : (message.contentBlocks ?? []))
+ .map((block) => {
+ if (block.type === "tool") {
+ return {
+ ...block,
+ toolCall: {
+ ...block.toolCall,
+ isRunning: false,
+ endedAtMs: block.toolCall.endedAtMs ?? stoppedAtMs,
+ },
+ };
+ }
+ if (block.type === "thinking") {
+ return {
+ ...block,
+ isThinking: false,
+ durationMs: block.durationMs ?? Math.max(1, stoppedAtMs - message.timestamp),
+ };
+ }
+ return block;
+ });
+ const content = stoppedText || (message.content === "Processing..." ? "" : message.content);
+
+ return {
+ ...message,
+ content,
+ ...(contentBlocks.length > 0 ? { contentBlocks } : {}),
+ workDurationMs: Math.max(1, stoppedAtMs - message.timestamp),
+ stoppedByUser: true,
+ };
+ }));
+ }
}
let stopAction;
try {
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-send-transport.ts b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-send-transport.ts
index eaedd0e58..cc5b1e126 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-send-transport.ts
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/hooks/use-pi-send-transport.ts
@@ -81,11 +81,13 @@ export function usePiSendTransport(options: PiSendTransportOptions) {
const { handleStop, openConnectionSetup } = usePiLiveSendControls({
abortControllerRef,
activePipeExecution,
+ cancelStreamingMessageRender,
piActiveStopRequestedRef,
piContentBlocksRef,
piMessageIdRef,
piSessionIdRef,
piStreamingTextRef,
+ setMessages,
setIsLoading,
setIsStreaming,
});
diff --git a/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx b/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx
index 5db183f52..0601eb371 100644
--- a/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/standalone/message-content.tsx
@@ -6,7 +6,7 @@
import * as React from "react";
import { useEffect, useRef, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
-import { Calendar, ChevronDown, ChevronUp, Plug, RefreshCw } from "lucide-react";
+import { Calendar, ChevronDown, ChevronRight, ChevronUp, Plug, RefreshCw } from "lucide-react";
import { SourceCitationFooter } from "@/components/chat/source-citation-footer";
import { MarkdownBlock } from "@/components/chat/markdown-block";
import { getFaviconUrl } from "@/components/rewind/timeline/favicon-utils";
@@ -15,7 +15,7 @@ import { useSettings } from "@/lib/hooks/use-settings";
import { useFeedbackStore } from "@/lib/stores/feedback-store";
import { cn } from "@/lib/utils";
import type { Message, ToolCall, ContentBlock } from "@/lib/chat/types";
-import { formatWorkDuration } from "@/lib/chat/message-rendering";
+import { formatDurationParts, formatStoppedWorkDuration, formatWorkDuration } from "@/lib/chat/message-rendering";
import {
classifyCurl,
endpointFamily,
@@ -135,10 +135,12 @@ export function GridDissolveLoader({
className={cn(
"transition-colors duration-100",
on
- ? phase === "streaming"
+ ? phase === "streaming" || phase === "analyzing"
? "bg-foreground/40"
: "bg-foreground"
- : "bg-border/30"
+ : phase === "streaming" || phase === "analyzing"
+ ? "bg-border/20"
+ : "bg-border/30"
)}
style={{ width: 5, height: 5 }}
/>
@@ -877,90 +879,184 @@ function collapseHiddenWorkGroups(grouped: GroupedBlock[], hideThinkingBlocks: b
return out;
}
-// Build natural-language summary of completed tool calls
-function buildToolSummary(toolCalls: ToolCall[]): string {
- const counts: Record<string, number> = {};
- for (const tc of toolCalls) {
- const action = tc.toolName === "bash" ? "ran" : tc.toolName === "read" ? "read" : tc.toolName === "edit" ? "edited" : tc.toolName === "write" ? "wrote" : tc.toolName === "grep" ? "searched" : tc.toolName;
- counts[action] = (counts[action] || 0) + 1;
+function toolCallRenderKey(toolCall: ToolCall, index: number): string {
+ return `${toolCall.id || toolCall.toolName || "tool"}:${index}`;
+}
+
+function toolWorkStartedAt(toolCalls: ToolCall[], fallbackStartedAtMs?: number): number | undefined {
+ const starts = toolCalls
+ .map((toolCall) => toolCall.startedAtMs)
+ .filter((startedAtMs): startedAtMs is number => typeof startedAtMs === "number" && Number.isFinite(startedAtMs));
+ if (starts.length > 0) return Math.min(...starts);
+ return fallbackStartedAtMs;
+}
+
+function toolWorkEndedAt(toolCalls: ToolCall[]): number | undefined {
+ const ends = toolCalls
+ .map((toolCall) => toolCall.endedAtMs)
+ .filter((endedAtMs): endedAtMs is number => typeof endedAtMs === "number" && Number.isFinite(endedAtMs));
+ if (ends.length > 0) return Math.max(...ends);
+ return undefined;
+}
+
+function formatRunningWorkDuration(startedAtMs: number): string {
+ const durationMs = Date.now() - startedAtMs;
+ return durationMs >= 1000 ? `Working for ${formatDurationParts(durationMs)}` : "Working";
+}
+
+function completedWorkSummaryFromRunning(runningSummary: string): string {
+ const prefix = "Working for ";
+ if (runningSummary.startsWith(prefix)) {
+ return `Worked for ${runningSummary.slice(prefix.length)}`;
}
- const parts = Object.entries(counts).map(([action, count]) => {
- if (action === "read") return `read ${count} file${count > 1 ? "s" : ""}`;
- if (action === "edited") return `edited ${count} file${count > 1 ? "s" : ""}`;
- if (action === "wrote") return `wrote ${count} file${count > 1 ? "s" : ""}`;
- if (action === "ran") return `ran ${count} command${count > 1 ? "s" : ""}`;
- if (action === "searched") return `${count} search${count > 1 ? "es" : ""}`;
- return `${count} ${action}`;
- });
- return parts.join(", ");
+ return "Worked";
}
-function toolCallRenderKey(toolCall: ToolCall, index: number): string {
- return `${toolCall.id || toolCall.toolName || "tool"}:${index}`;
+function WorkSummaryText({
+ text,
+ animateRunningDuration,
+}: {
+ text: string;
+ animateRunningDuration: boolean;
+}) {
+ const prefix = "Working";
+
+ if (!animateRunningDuration || !text.startsWith(prefix)) {
+ return <>{text}</>;
+ }
+
+ const durationSuffix = text.slice(prefix.length);
+
+ return (
+ <>
+ {prefix}
+ <AnimatePresence initial={false}>
+ {durationSuffix && (
+ <motion.span
+ key="running-duration"
+ initial={{ opacity: 0, y: 2 }}
+ animate={{ opacity: 1, y: 0 }}
+ exit={{ opacity: 0, y: -2 }}
+ transition={{ duration: 0.16, ease: "easeOut" }}
+ className="inline-block whitespace-pre"
+ >
+ {durationSuffix}
+ </motion.span>
+ )}
+ </AnimatePresence>
+ </>
+ );
+}
+
+function WorkStatusHeader({ label }: { label: string }) {
+ return (
+ <div className="w-full min-w-0">
+ <div className="py-1 text-xs font-mono text-foreground/50">
+ {label}
+ </div>
+ <div className="w-full min-w-full border-t border-border/50" />
+ </div>
+ );
}
function ToolCallGroup({
toolCalls,
defaultExpanded = false,
+ isGenerating = false,
+ preferSummaryOverride = false,
summaryOverride,
- hideCount = false,
+ workStartedAtMs,
}: {
toolCalls: ToolCall[];
defaultExpanded?: boolean;
+ isGenerating?: boolean;
+ preferSummaryOverride?: boolean;
summaryOverride?: string;
- hideCount?: boolean;
+ workStartedAtMs?: number;
}) {
const [manualExpand, setManualExpand] = useState<boolean | null>(null);
+ const [runningSummary, setRunningSummary] = useState("Working");
+ const [completedLiveSummary, setCompletedLiveSummary] = useState<string | null>(null);
+ const wasWorkingRef = useRef(false);
- const hasRunning = toolCalls.some((tc) => tc.isRunning);
+ const hasRunningTool = toolCalls.some((tc) => tc.isRunning);
+ const isWorking = hasRunningTool || isGenerating;
const hasError = toolCalls.some((tc) => tc.isError);
- const allDone = !hasRunning;
- const doneCount = toolCalls.filter((tc) => !tc.isRunning).length;
+ const allDone = !isWorking;
const total = toolCalls.length;
- const summary = allDone ? (summaryOverride || buildToolSummary(toolCalls)) : "";
+ const startedAtMs = toolWorkStartedAt(toolCalls, workStartedAtMs);
+ const endedAtMs = allDone ? toolWorkEndedAt(toolCalls) : undefined;
+ const completedDurationMs = startedAtMs && endedAtMs ? Math.max(1, endedAtMs - startedAtMs) : undefined;
+ const justCompletedSummary = !isWorking && wasWorkingRef.current
+ ? completedWorkSummaryFromRunning(runningSummary)
+ : null;
+ const summary = allDone
+ ? (
+ preferSummaryOverride && summaryOverride
+ ? summaryOverride
+ : justCompletedSummary ||
+ completedLiveSummary ||
+ (completedDurationMs ? formatWorkDuration(completedDurationMs) : (summaryOverride || "Worked"))
+ )
+ : "";
+
+ useEffect(() => {
+ if (!isWorking || !startedAtMs) {
+ setRunningSummary("Working");
+ return;
+ }
+ const updateSummary = () => setRunningSummary(formatRunningWorkDuration(startedAtMs));
+ updateSummary();
+ const id = window.setInterval(updateSummary, 1000);
+ return () => window.clearInterval(id);
+ }, [isWorking, startedAtMs]);
+
+ useEffect(() => {
+ if (isWorking) {
+ wasWorkingRef.current = true;
+ setCompletedLiveSummary(null);
+ return;
+ }
+ if (wasWorkingRef.current) {
+ setCompletedLiveSummary(completedWorkSummaryFromRunning(runningSummary));
+ wasWorkingRef.current = false;
+ }
+ }, [isWorking, runningSummary]);
// Auto-expand while running, auto-collapse when done (user can override).
// `defaultExpanded` keeps the group open even when done — used for
// messages whose entire output is tool calls (typical pipe-runs)
// where the tool result is the whole story.
- const isExpanded = manualExpand !== null ? manualExpand : (hasRunning || defaultExpanded);
+ const isExpanded = manualExpand !== null ? manualExpand : (hasRunningTool || defaultExpanded);
return (
- <div className="w-full min-w-0">
- {/* Header bar — clickable to toggle */}
- <button
- onClick={() => setManualExpand(isExpanded ? false : true)}
- className="w-full flex items-center gap-2 py-1 text-left min-w-0 group"
- >
- {/* Status indicator */}
- {!hideCount && hasRunning && (
- <span className="flex-shrink-0 text-xs font-mono text-foreground/40">
- <motion.span
- className="inline-block"
- animate={{ opacity: [1, 1, 0.3, 0.3, 1] }}
- transition={{ duration: 1, repeat: Infinity, times: [0, 0.25, 0.25, 0.75, 0.75], ease: "linear" }}
- >
- [{doneCount}/{total}]
- </motion.span>
+ <div className="w-full min-w-0 self-stretch">
+ <div className="mb-2 w-full min-w-full">
+ {/* Header bar — clickable to toggle */}
+ <button
+ onClick={() => setManualExpand(isExpanded ? false : true)}
+ className="w-full flex items-center gap-1.5 py-1 text-left min-w-0 group cursor-pointer"
+ >
+ {/* Summary text */}
+ <span className="truncate text-xs font-mono text-foreground/50 group-hover:text-foreground/80 transition-colors duration-150">
+ <WorkSummaryText
+ text={isWorking ? runningSummary : summary || `${total} steps`}
+ animateRunningDuration={isWorking}
+ />
+ {hasError && allDone && (
+ <span className="ml-1.5 text-foreground/30">· {toolCalls.filter(tc => tc.isError).length} failed</span>
+ )}
</span>
- )}
- {/* Summary text */}
- <span className="truncate flex-1 text-xs font-mono text-foreground/50 group-hover:text-foreground/80 transition-colors duration-150">
- {hasRunning
- ? friendlyToolLabel(toolCalls.find((tc) => tc.isRunning)!)
- : summary || `${total} steps`
- }
- {hasError && allDone && (
- <span className="ml-1.5 text-foreground/30">· {toolCalls.filter(tc => tc.isError).length} failed</span>
+ {/* Expand chevron */}
+ {isExpanded ? (
+ <ChevronDown className="h-3.5 w-3.5 flex-shrink-0 text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150" />
+ ) : (
+ <ChevronRight className="h-3.5 w-3.5 flex-shrink-0 text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150" />
)}
- </span>
-
- {/* Expand chevron */}
- <span className="flex-shrink-0 text-[10px] font-mono text-foreground/30 group-hover:text-foreground/60 transition-colors duration-150">
- {isExpanded ? "▾" : "▸"}
- </span>
- </button>
+ </button>
+ <div className="w-full min-w-full border-t border-border/50" />
+ </div>
{/* Expanded rail view */}
<AnimatePresence>
@@ -997,12 +1093,14 @@ function ToolCallGroup({
// Renders message content with interleaved text and tool call blocks
export function MessageContent({
message,
+ isGenerating = false,
deferSourceFooter = false,
onImageClick,
onRetry,
onOpenViewerPath,
}: {
message: Message;
+ isGenerating?: boolean;
deferSourceFooter?: boolean;
onImageClick?: (images: string[], index: number) => void;
onRetry?: (prompt: string) => void;
@@ -1145,8 +1243,13 @@ export function MessageContent({
// and the chat panel reads as empty even though there's real
// content to see.
const hasText = grouped.some((g) => g.type === "text");
+ const stoppedSummary = message.stoppedByUser
+ ? formatStoppedWorkDuration(message.workDurationMs)
+ : undefined;
+ const hasWorkStatusGroup = displayGroups.some((g) => g.type === "tool-group" || g.type === "work-group");
return (
<div className="space-y-2 min-w-0 w-full overflow-hidden">
+ {stoppedSummary && !hasWorkStatusGroup ? <WorkStatusHeader label={stoppedSummary} /> : null}
{displayGroups.map((group) => {
if (group.type === "text") {
return (
@@ -1177,7 +1280,17 @@ export function MessageContent({
return <ThinkingBlock key={`thinking-${group.key}`} text={group.text} isThinking={group.isThinking} durationMs={group.durationMs} />;
}
if (group.type === "tool-group") {
- return <ToolCallGroup key={`tools-${group.key}`} toolCalls={group.toolCalls} defaultExpanded={!hasText} />;
+ return (
+ <ToolCallGroup
+ key={`tools-${group.key}`}
+ toolCalls={group.toolCalls}
+ defaultExpanded={!hasText}
+ isGenerating={isGenerating && !message.workDurationMs}
+ preferSummaryOverride={Boolean(stoppedSummary)}
+ summaryOverride={stoppedSummary || (message.workDurationMs ? formatWorkDuration(message.workDurationMs) : undefined)}
+ workStartedAtMs={message.timestamp}
+ />
+ );
}
if (group.type === "work-group") {
// Fall back to message-level workDurationMs when the
@@ -1190,8 +1303,10 @@ export function MessageContent({
key={`work-${group.key}`}
toolCalls={group.toolCalls}
defaultExpanded={!hasText}
- summaryOverride={formatWorkDuration(durationMs)}
- hideCount={hasText}
+ isGenerating={isGenerating && !message.workDurationMs}
+ preferSummaryOverride={Boolean(stoppedSummary)}
+ summaryOverride={stoppedSummary || formatWorkDuration(durationMs)}
+ workStartedAtMs={message.timestamp}
/>
);
}
@@ -1210,24 +1325,30 @@ export function MessageContent({
const displayText = !isUser && message.content.startsWith("Error: ")
? message.content.slice("Error: ".length)
: message.content;
+ const stoppedSummary = !isUser && message.stoppedByUser
+ ? formatStoppedWorkDuration(message.workDurationMs)
+ : undefined;
return (
- <div className="space-y-2">
+ <div className="space-y-2 min-w-0 w-full">
{attachmentsRow}
- <MarkdownBlock
- text={displayText}
- isUser={isUser}
- onOpenViewerPath={onOpenViewerPath}
- renderSpecialCodeBlock={(language, content) => {
- if (language === "mermaid") {
- return <MermaidDiagramBlock chart={content} />;
- }
- if (language === "app-stats") {
- return <AppStatsBlock content={content} />;
- }
- return null;
- }}
- />
+ {stoppedSummary ? <WorkStatusHeader label={stoppedSummary} /> : null}
+ {displayText ? (
+ <MarkdownBlock
+ text={displayText}
+ isUser={isUser}
+ onOpenViewerPath={onOpenViewerPath}
+ renderSpecialCodeBlock={(language, content) => {
+ if (language === "mermaid") {
+ return <MermaidDiagramBlock chart={content} />;
+ }
+ if (language === "app-stats") {
+ return <AppStatsBlock content={content} />;
+ }
+ return null;
+ }}
+ />
+ ) : null}
{sourceFooter}
{retryCta}
</div>
diff --git a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
index d0a734630..3961e418e 100644
--- a/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
+++ b/apps/screenpipe-app-tauri/components/hooks/use-chat-conversations.ts
@@ -704,6 +704,8 @@ export function useChatConversations(opts: UseChatConversationsOpts) {
...(m.provider ? { provider: m.provider } : {}),
...(m.interruptedBySteer ? { interruptedBySteer: true } : {}),
...(m.steeredResponse ? { steeredResponse: true } : {}),
+ ...(m.workDurationMs ? { workDurationMs: m.workDurationMs } : {}),
+ ...(m.stoppedByUser ? { stoppedByUser: true } : {}),
};
}),
createdAt: existing?.createdAt ?? Date.now(),
@@ -1200,6 +1202,8 @@ export function useChatConversations(opts: UseChatConversationsOpts) {
...((m as any).provider ? { provider: (m as any).provider } : {}),
...((m as any).interruptedBySteer ? { interruptedBySteer: true } : {}),
...((m as any).steeredResponse ? { steeredResponse: true } : {}),
+ ...((m as any).workDurationMs ? { workDurationMs: (m as any).workDurationMs } : {}),
+ ...((m as any).stoppedByUser ? { stoppedByUser: true } : {}),
}));
// Make sure a record exists, then seed messages and mark hydrated.
if (!store.sessions[conv.id]) {
@@ -1377,6 +1381,8 @@ export function useChatConversations(opts: UseChatConversationsOpts) {
...(m.provider ? { provider: m.provider } : {}),
...(m.interruptedBySteer ? { interruptedBySteer: true } : {}),
...(m.steeredResponse ? { steeredResponse: true } : {}),
+ ...(m.workDurationMs ? { workDurationMs: m.workDurationMs } : {}),
+ ...(m.stoppedByUser ? { stoppedByUser: true } : {}),
};
}),
createdAt,
diff --git a/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts b/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts
index fdf0d3502..1c16338dd 100644
--- a/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts
+++ b/apps/screenpipe-app-tauri/lib/chat/__tests__/message-rendering.test.ts
@@ -7,6 +7,8 @@ import type { Message } from "../types";
import {
buildCollapsedSteerRenderItems,
collapsedSteerWorkDuration,
+ formatDurationParts,
+ formatStoppedWorkDuration,
formatWorkDuration,
getMessageIntentLabel,
hasRenderableAssistantBody,
@@ -25,8 +27,13 @@ function message(overrides: Partial<Message> & Pick<Message, "id" | "role">): Me
describe("message rendering helpers", () => {
it("formats work duration labels", () => {
expect(formatWorkDuration(0)).toBe("Worked");
- expect(formatWorkDuration(1_000)).toBe("Worked for <1 min");
- expect(formatWorkDuration(90_000)).toBe("Worked for 2 mins");
+ expect(formatWorkDuration(1_000)).toBe("Worked for 1s");
+ expect(formatWorkDuration(18_000)).toBe("Worked for 18s");
+ expect(formatWorkDuration(61_000)).toBe("Worked for 1 min 1 sec");
+ expect(formatWorkDuration(100_000)).toBe("Worked for 1 min 40 sec");
+ expect(formatDurationParts(60_000)).toBe("1 min");
+ expect(formatStoppedWorkDuration()).toBe("You stopped");
+ expect(formatStoppedWorkDuration(68_000)).toBe("You stopped after 1 min 8 sec");
});
it("detects placeholder titles and steered assistant messages", () => {
@@ -41,6 +48,7 @@ describe("message rendering helpers", () => {
it("treats assistant content blocks as renderable body", () => {
expect(hasRenderableAssistantBody(message({ id: "a1", role: "assistant", content: "Processing..." }))).toBe(false);
+ expect(hasRenderableAssistantBody(message({ id: "a-stopped", role: "assistant", stoppedByUser: true }))).toBe(true);
expect(
hasRenderableAssistantBody(
message({
@@ -101,6 +109,6 @@ describe("message rendering helpers", () => {
{ canCollapseSteerWork: true }
).filter((renderItem) => renderItem.type === "collapsed-steer-work");
- expect(collapsedSteerWorkDuration(item)).toBe("Worked for 1 min");
+ expect(collapsedSteerWorkDuration(item)).toBe("Worked for 1 min 15 sec");
});
});
diff --git a/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts b/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts
index 8e722f967..ff8efd748 100644
--- a/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts
+++ b/apps/screenpipe-app-tauri/lib/chat/message-rendering.ts
@@ -4,12 +4,25 @@
import type { Message } from "@/lib/chat/types";
+export function formatDurationParts(durationMs: number): string {
+ const totalSeconds = Math.max(1, Math.floor(durationMs / 1000));
+ if (totalSeconds < 60) return `${totalSeconds}s`;
+
+ const minutes = Math.floor(totalSeconds / 60);
+ const seconds = totalSeconds % 60;
+ const minutePart = `${minutes} min`;
+ if (seconds === 0) return minutePart;
+ return `${minutePart} ${seconds} sec`;
+}
+
export function formatWorkDuration(durationMs: number): string {
if (!durationMs || durationMs <= 0) return "Worked";
- const seconds = Math.max(1, Math.round(durationMs / 1000));
- if (seconds < 60) return "Worked for <1 min";
- const minutes = Math.max(1, Math.round(seconds / 60));
- return `Worked for ${minutes} min${minutes === 1 ? "" : "s"}`;
+ return `Worked for ${formatDurationParts(durationMs)}`;
+}
+
+export function formatStoppedWorkDuration(durationMs?: number): string {
+ if (!durationMs || durationMs <= 0) return "You stopped";
+ return `You stopped after ${formatDurationParts(durationMs)}`;
}
export function getMessageIntentLabel(message: Message): string | null {
@@ -31,6 +44,7 @@ export function isSteeredAssistantMessage(message: Message): boolean {
export function hasRenderableAssistantBody(message: Message): boolean {
if (message.role !== "assistant") return false;
+ if (message.stoppedByUser) return true;
if (message.content && message.content !== "Processing...") return true;
return Boolean(message.contentBlocks?.length);
}
@@ -161,9 +175,5 @@ export function collapsedSteerWorkDuration(item: Extract<ChatRenderItem, { type:
.filter((timestamp) => Number.isFinite(timestamp));
if (timestamps.length < 2) return "Worked";
const durationMs = Math.max(...timestamps) - Math.min(...timestamps);
- if (durationMs <= 0) return "Worked";
- const seconds = Math.max(1, Math.round(durationMs / 1000));
- if (seconds < 60) return `Worked for ${seconds}s`;
- const minutes = Math.max(1, Math.round(seconds / 60));
- return `Worked for ${minutes} min${minutes === 1 ? "" : "s"}`;
+ return formatWorkDuration(durationMs);
}
diff --git a/apps/screenpipe-app-tauri/lib/chat/types.ts b/apps/screenpipe-app-tauri/lib/chat/types.ts
index d18209b85..f1852de3f 100644
--- a/apps/screenpipe-app-tauri/lib/chat/types.ts
+++ b/apps/screenpipe-app-tauri/lib/chat/types.ts
@@ -20,6 +20,8 @@ export interface ToolCall {
result?: string;
isError?: boolean;
isRunning: boolean;
+ startedAtMs?: number;
+ endedAtMs?: number;
}
export type ContentBlock =
@@ -45,6 +47,7 @@ export interface Message {
interruptedBySteer?: boolean;
steeredResponse?: boolean;
workDurationMs?: number;
+ stoppedByUser?: boolean;
}
export type QueuedDisplayPayload = {
diff --git a/apps/screenpipe-app-tauri/lib/events/pipe-watch-writer.ts b/apps/screenpipe-app-tauri/lib/events/pipe-watch-writer.ts
index 3aadb3fbc..957773242 100644
--- a/apps/screenpipe-app-tauri/lib/events/pipe-watch-writer.ts
+++ b/apps/screenpipe-app-tauri/lib/events/pipe-watch-writer.ts
@@ -242,6 +242,7 @@ function apply(sid: string, payload: AgentInnerEvent): void {
toolName: (payload as any).toolName || "unknown",
args: (payload as any).args || {},
isRunning: true,
+ startedAtMs: Date.now(),
};
const blocks = [
...((cur.contentBlocks as any[]) ?? []),
@@ -276,6 +277,7 @@ function apply(sid: string, payload: AgentInnerEvent): void {
isRunning: false,
result: truncated,
isError: (payload as any).isError,
+ endedAtMs: Date.now(),
},
}
: b,
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index e1e429fe5..bd962b075 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -113,6 +113,7 @@ export interface ChatMessage {
}>;
interruptedBySteer?: boolean;
steeredResponse?: boolean;
+ stoppedByUser?: boolean;
/** Wall-clock work duration for coalesced assistant messages (pipe
* runs). Used by the chat renderer as a fallback when no thinking
* blocks contributed a duration, so the work-group can still show
diff --git a/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts b/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts
index a7f56e0ca..16089b483 100644
--- a/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts
+++ b/apps/screenpipe-app-tauri/lib/pipe-ndjson-to-chat.ts
@@ -231,7 +231,7 @@ export function parsePipeNdjsonToMessages(raw: string, pipeName?: string): ChatM
const messages: ChatMessage[] = [];
let currentText = "";
let currentBlocks: any[] = [];
- let currentToolCall: { name: string; input: string } | null = null;
+ let currentToolCall: { name: string; input: string; startedAtMs: number } | null = null;
let inAssistantTurn = false;
let workFirstTs: number | null = null;
let workLastTs: number | null = null;
@@ -348,14 +348,24 @@ export function parsePipeNdjsonToMessages(raw: string, pipeName?: string): ChatM
if (toolName === "unknown" && ae.partial?.content) {
for (const c of ae.partial.content) { if (c.type === "toolCall" && c.name) { toolName = c.name; break; } }
}
- currentToolCall = { name: toolName, input: "" };
+ currentToolCall = { name: toolName, input: "", startedAtMs: ts };
} else if (ae.type === "toolcall_delta" && ae.delta && currentToolCall) currentToolCall.input += ae.delta;
else if (ae.type === "toolcall_end") {
let args: Record<string, any> = {};
const rawInput = currentToolCall?.input || "";
if (rawInput) { try { args = JSON.parse(rawInput); } catch { args = { raw: rawInput }; } }
let toolName = currentToolCall?.name || "unknown";
- currentBlocks.push({ type: "tool", toolCall: { id: `pipe-tool-${messageCounter}-${currentBlocks.length}`, toolName, args, isRunning: false } });
+ currentBlocks.push({
+ type: "tool",
+ toolCall: {
+ id: `pipe-tool-${messageCounter}-${currentBlocks.length}`,
+ toolName,
+ args,
+ isRunning: false,
+ startedAtMs: currentToolCall?.startedAtMs ?? ts,
+ endedAtMs: ts,
+ },
+ });
currentToolCall = null;
}
continue;
@@ -372,7 +382,15 @@ export function parsePipeNdjsonToMessages(raw: string, pipeName?: string): ChatM
currentText = extractText(content);
for (const block of content) {
if (block.type === "toolCall") {
- currentBlocks.push({ type: "tool", toolCall: { id: block.id || `pipe-tool-${messageCounter}-${currentBlocks.length}`, toolName: block.name || "unknown", args: block.arguments || {}, isRunning: false } });
+ currentBlocks.push({
+ type: "tool",
+ toolCall: {
+ id: block.id || `pipe-tool-${messageCounter}-${currentBlocks.length}`,
+ toolName: block.name || "unknown",
+ args: block.arguments || {},
+ isRunning: false,
+ },
+ });
}
}
}
diff --git a/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts b/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts
index 58d3bf73f..bb1a6eaf1 100644
--- a/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts
+++ b/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts
@@ -609,6 +609,7 @@ function applyEventToSessionContent(sid: string, payload: PiInnerEvent) {
toolName: (payload as any).toolName || "unknown",
args: (payload as any).args || {},
isRunning: true,
+ startedAtMs: Date.now(),
};
const blocks = [...((cur.contentBlocks as any[]) ?? []), { type: "tool", toolCall: tool }];
store.actions.setStreaming(sid, { contentBlocks: blocks });
@@ -641,6 +642,7 @@ function applyEventToSessionContent(sid: string, payload: PiInnerEvent) {
isRunning: false,
result: truncated,
isError: (payload as any).isError,
+ endedAtMs: Date.now(),
},
}
: b
@@ -827,6 +829,8 @@ async function persistBackgroundSession(sid: string): Promise<void> {
...(m.provider ? { provider: m.provider } : {}),
...(m.interruptedBySteer ? { interruptedBySteer: true } : {}),
...(m.steeredResponse ? { steeredResponse: true } : {}),
+ ...(m.workDurationMs ? { workDurationMs: m.workDurationMs } : {}),
+ ...(m.stoppedByUser ? { stoppedByUser: true } : {}),
};
}),
createdAt: existing?.createdAt ?? Date.now(),