Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep Assistant activity visible while streaming

rcourtman0f2e7f5c16e2
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
index 9ce35378f2..e2026f50ff 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
@@ -651,6 +651,36 @@ describe('MessageItem', () => {
expect(screen.queryByText('Thinking...')).not.toBeInTheDocument();
});
+ it('keeps transcript workflow activity visible before streamed content', () => {
+ render(() => (
+ <MessageItem
+ message={makeMessage({
+ role: 'assistant',
+ content: 'Partial answer',
+ isStreaming: true,
+ pendingTools: [],
+ streamEvents: [
+ {
+ type: 'workflow_status',
+ workflowStatus: {
+ phase: 'provider_start',
+ message: 'Sent request to OpenRouter; waiting for the first token.',
+ },
+ },
+ { type: 'content', content: 'Partial answer' },
+ ],
+ })}
+ {...makeHandlers()}
+ />
+ ));
+
+ expect(
+ screen.getByText('Sent request to OpenRouter; waiting for the first token.'),
+ ).toBeInTheDocument();
+ expect(screen.getByText('Partial answer')).toBeInTheDocument();
+ expect(screen.queryByText('Thinking...')).not.toBeInTheDocument();
+ });
+
it('does not show cursor when streaming but there are pending tools', () => {
const { container } = render(() => (
<MessageItem
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
index 9a12967ff9..216ef2e918 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -1248,7 +1248,7 @@ describe('useChat', () => {
dispose();
});
- it('replaces rapid workflow progress immediately as one live status', async () => {
+ it('coalesces same workflow activity and appends later phases as visible progress', async () => {
const { getFireEvent } = setupWithEventCapture();
const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
@@ -1315,6 +1315,12 @@ describe('useChat', () => {
}),
);
expect(assistant.streamEvents).toEqual([
+ expect.objectContaining({
+ type: 'workflow_status',
+ workflowStatus: expect.objectContaining({
+ message: 'Built compact inventory context for the model.',
+ }),
+ }),
expect.objectContaining({
type: 'workflow_status',
workflowStatus: expect.objectContaining({
@@ -1326,7 +1332,7 @@ describe('useChat', () => {
dispose();
});
- it('clears workflow progress when visible answer content starts streaming', async () => {
+ it('keeps workflow progress visible when answer content starts streaming', async () => {
const { getFireEvent } = setupWithEventCapture();
const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
@@ -1345,11 +1351,14 @@ describe('useChat', () => {
const assistant = chat.messages().find((m) => m.role === 'assistant')!;
expect(assistant.content).toBe('Here is the answer.');
expect(assistant.workflowStatus).toBeUndefined();
- expect(assistant.streamEvents?.map((event) => event.type)).toEqual(['content']);
+ expect(assistant.streamEvents?.map((event) => event.type)).toEqual([
+ 'workflow_status',
+ 'content',
+ ]);
dispose();
});
- it('clears workflow progress when a governed tool block starts', async () => {
+ it('keeps workflow progress visible when a governed tool block starts', async () => {
const { getFireEvent } = setupWithEventCapture();
const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
@@ -1368,11 +1377,14 @@ describe('useChat', () => {
const assistant = chat.messages().find((m) => m.role === 'assistant')!;
expect(assistant.workflowStatus).toBeUndefined();
expect(assistant.pendingTools).toHaveLength(1);
- expect(assistant.streamEvents?.map((event) => event.type)).toEqual(['pending_tool']);
+ expect(assistant.streamEvents?.map((event) => event.type)).toEqual([
+ 'workflow_status',
+ 'pending_tool',
+ ]);
dispose();
});
- it('keeps late workflow progress live after typed tool evidence as one current activity row', async () => {
+ it('keeps late workflow progress live after typed tool evidence in chronological order', async () => {
const { getFireEvent } = setupWithEventCapture();
const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
@@ -1413,10 +1425,11 @@ describe('useChat', () => {
}),
);
expect(assistant.streamEvents?.map((event) => event.type)).toEqual([
+ 'workflow_status',
'tool',
'workflow_status',
]);
- expect(assistant.streamEvents?.[1]).toEqual(
+ expect(assistant.streamEvents?.[2]).toEqual(
expect.objectContaining({
workflowStatus: expect.objectContaining({
phase: 'model_thinking',
@@ -1941,13 +1954,20 @@ describe('useChat', () => {
dispose();
});
- it('done event removes unresolved interactive stream rows', async () => {
+ it('done event removes unresolved interactive rows but keeps visible workflow activity', async () => {
const { getFireEvent } = setupWithEventCapture();
const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
await chat.sendMessage('hi');
const fire = getFireEvent();
+ fire({
+ type: 'workflow_state',
+ data: {
+ phase: 'provider_start',
+ message: 'Sent request to OpenRouter; waiting for the first token.',
+ },
+ });
fire({ type: 'content', data: 'partial response' });
fire({ type: 'tool_start', data: { id: 'tool-1', name: 'pulse_read', input: '{}' } });
fire({
@@ -1975,7 +1995,10 @@ describe('useChat', () => {
expect(assistant.pendingTools).toEqual([]);
expect(assistant.pendingApprovals).toEqual([]);
expect(assistant.pendingQuestions).toEqual([]);
- expect(assistant.streamEvents?.map((event) => event.type)).toEqual(['content']);
+ expect(assistant.streamEvents?.map((event) => event.type)).toEqual([
+ 'workflow_status',
+ 'content',
+ ]);
dispose();
});
@@ -1996,13 +2019,20 @@ describe('useChat', () => {
dispose();
});
- it('error event removes unresolved interactive stream rows', async () => {
+ it('error event removes unresolved interactive rows but keeps visible workflow activity', async () => {
const { getFireEvent } = setupWithEventCapture();
const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
await chat.sendMessage('hi');
const fire = getFireEvent();
+ fire({
+ type: 'workflow_state',
+ data: {
+ phase: 'provider_start',
+ message: 'Sent request to OpenRouter; waiting for the first token.',
+ },
+ });
fire({ type: 'content', data: 'partial response' });
fire({ type: 'tool_start', data: { id: 'tool-1', name: 'pulse_read', input: '{}' } });
fire({
@@ -2031,7 +2061,10 @@ describe('useChat', () => {
expect(assistant.pendingTools).toEqual([]);
expect(assistant.pendingApprovals).toEqual([]);
expect(assistant.pendingQuestions).toEqual([]);
- expect(assistant.streamEvents?.map((event) => event.type)).toEqual(['content']);
+ expect(assistant.streamEvents?.map((event) => event.type)).toEqual([
+ 'workflow_status',
+ 'content',
+ ]);
dispose();
});
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index 8be9b3c5b9..87573cd8b0 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -166,10 +166,7 @@ export function useChat(options: UseChatOptions = {}) {
if (!events) return events;
return events.filter(
(event) =>
- event.type !== 'pending_tool' &&
- event.type !== 'approval' &&
- event.type !== 'question' &&
- event.type !== 'workflow_status',
+ event.type !== 'pending_tool' && event.type !== 'approval' && event.type !== 'question',
);
};
@@ -313,30 +310,55 @@ export function useChat(options: UseChatOptions = {}) {
};
};
- const streamEventsWithoutWorkflowStatus = (
- events: StreamDisplayEvent[] | undefined,
- ): StreamDisplayEvent[] | undefined =>
- events?.filter((event) => event.type !== 'workflow_status');
-
- const withClearedWorkflowStatusEvent = (msg: ChatMessage): ChatMessage => {
- const streamEvents = streamEventsWithoutWorkflowStatus(msg.streamEvents);
- if (streamEvents === msg.streamEvents) return msg;
- return { ...msg, streamEvents };
+ const shouldCoalesceWorkflowStatusEvents = (previous?: WorkflowStatus, next?: WorkflowStatus) => {
+ if (!previous || !next) return false;
+ return (
+ (previous.phase || '') === (next.phase || '') &&
+ (previous.state || '') === (next.state || '') &&
+ (previous.tool || '') === (next.tool || '') &&
+ (previous.attempt || 0) === (next.attempt || 0) &&
+ (previous.maxAttempts || 0) === (next.maxAttempts || 0) &&
+ (previous.retryAfterMs || 0) === (next.retryAfterMs || 0)
+ );
};
- const withWorkflowStatusEvent = (msg: ChatMessage, workflowStatus: WorkflowStatus): ChatMessage =>
- addStreamEvent(
- {
- ...msg,
- streamEvents: streamEventsWithoutWorkflowStatus(msg.streamEvents) || [],
- },
+ const withWorkflowStatusEvent = (
+ msg: ChatMessage,
+ workflowStatus: WorkflowStatus,
+ ): ChatMessage => {
+ const events = msg.streamEvents || [];
+ const now = Date.now();
+ const nextEvent = withStreamEventTiming(
{
type: 'workflow_status',
workflowStatus,
startedAt: workflowStatus.startedAt,
updatedAt: workflowStatus.startedAt,
},
+ now,
);
+ const last = events[events.length - 1];
+
+ if (last?.type === 'workflow_status') {
+ if (workflowStatusesMatch(last.workflowStatus, workflowStatus)) {
+ return msg;
+ }
+ if (shouldCoalesceWorkflowStatusEvents(last.workflowStatus, workflowStatus)) {
+ return {
+ ...msg,
+ streamEvents: [
+ ...events.slice(0, -1),
+ {
+ ...nextEvent,
+ startedAt: last.startedAt || nextEvent.startedAt,
+ },
+ ],
+ };
+ }
+ }
+
+ return addStreamEvent(msg, nextEvent);
+ };
const normalizePendingToolStatus = (phase?: string): PendingTool['status'] => {
const normalized = (phase || 'running').trim().toLowerCase();
@@ -454,7 +476,7 @@ export function useChat(options: UseChatOptions = {}) {
return {
...msg,
streamEvents: replacePendingToolStreamEvents(
- streamEventsWithoutWorkflowStatus(msg.streamEvents) || [],
+ msg.streamEvents || [],
resolvedTool,
matchesTool,
now,
@@ -533,12 +555,7 @@ export function useChat(options: UseChatOptions = {}) {
return {
...msg,
streamEvents: resolvedTool
- ? replacePendingToolStreamEvents(
- streamEventsWithoutWorkflowStatus(msg.streamEvents) || [],
- resolvedTool,
- matchesTool,
- now,
- )
+ ? replacePendingToolStreamEvents(msg.streamEvents || [], resolvedTool, matchesTool, now)
: msg.streamEvents,
workflowStatus: undefined,
pendingTools: updatedPendingTools,
@@ -932,10 +949,9 @@ export function useChat(options: UseChatOptions = {}) {
)
: msg;
if (!visible.text) return baseMsg;
- const clearedMsg = withClearedWorkflowStatusEvent(baseMsg);
// Add to streamEvents for chronological display
const now = Date.now();
- const updated = addStreamEvent(clearedMsg, {
+ const updated = addStreamEvent(baseMsg, {
type: 'content',
content: visible.text,
startedAt: now,
@@ -943,7 +959,7 @@ export function useChat(options: UseChatOptions = {}) {
});
return {
...updated,
- content: appendMessageContent(clearedMsg, visible.text),
+ content: appendMessageContent(baseMsg, visible.text),
workflowStatus: undefined,
};
}
@@ -952,8 +968,7 @@ export function useChat(options: UseChatOptions = {}) {
const thinking = extractText(event.data);
if (!thinking) return msg;
const now = Date.now();
- const clearedMsg = withClearedWorkflowStatusEvent(msg);
- const updated = addStreamEvent(clearedMsg, {
+ const updated = addStreamEvent(msg, {
type: 'thinking',
thinking,
startedAt: now,
@@ -1018,7 +1033,7 @@ export function useChat(options: UseChatOptions = {}) {
pendingTools: (msg.pendingTools || []).filter(
(tool) => !matchesTool(tool, tool.id),
),
- streamEvents: (streamEventsWithoutWorkflowStatus(msg.streamEvents) || []).filter(
+ streamEvents: (msg.streamEvents || []).filter(
(streamEvent) =>
streamEvent.type !== 'pending_tool' ||
!matchesTool(streamEvent.pendingTool, streamEvent.toolId),
@@ -1037,7 +1052,7 @@ export function useChat(options: UseChatOptions = {}) {
success: boolean;
};
const pendingTools = msg.pendingTools || [];
- const events = streamEventsWithoutWorkflowStatus(msg.streamEvents) || [];
+ const events = msg.streamEvents || [];
const normalizedEndName = normalizeChatToolName(data.name || '');
@@ -1229,7 +1244,7 @@ export function useChat(options: UseChatOptions = {}) {
}
// Add to streamEvents for chronological display
- const updated = addStreamEvent(withClearedWorkflowStatusEvent(msg), {
+ const updated = addStreamEvent(msg, {
type: 'approval',
approval,
});
@@ -1268,7 +1283,7 @@ export function useChat(options: UseChatOptions = {}) {
};
// Add to streamEvents for chronological display
- const updated = addStreamEvent(withClearedWorkflowStatusEvent(msg), {
+ const updated = addStreamEvent(msg, {
type: 'question',
question: pendingQuestion,
});
@@ -1282,7 +1297,6 @@ export function useChat(options: UseChatOptions = {}) {
case 'done': {
const completedAt = new Date();
- const terminalMsg = withClearedWorkflowStatusEvent(msg);
const pendingText = suppressedRawContentMessageIds.has(assistantId)
? ''
: flushPendingAssistantOutputText(outputArtifactStateFor(assistantId));
@@ -1290,15 +1304,15 @@ export function useChat(options: UseChatOptions = {}) {
clearOutputArtifactState(assistantId);
const flushedMsg = pendingText
? {
- ...addStreamEvent(terminalMsg, {
+ ...addStreamEvent(msg, {
type: 'content',
content: pendingText,
startedAt: Date.now(),
updatedAt: Date.now(),
}),
- content: appendMessageContent(terminalMsg, pendingText),
+ content: appendMessageContent(msg, pendingText),
}
- : terminalMsg;
+ : msg;
const tokens = extractTokens(event.data);
const completedModel = extractCompletedModel(event.data);
if (tokens && (tokens.input > 0 || tokens.output > 0)) {
@@ -1333,19 +1347,16 @@ export function useChat(options: UseChatOptions = {}) {
case 'error': {
clearSuppressedOutputBoundary(assistantId);
const errorMsg = extractErrorMessage(event.data);
- const terminalMsg = withClearedWorkflowStatusEvent(msg);
// Keep any content streamed before the failure; surface the error
// as a distinct, recoverable block rather than overwriting the answer.
return {
- ...terminalMsg,
+ ...msg,
isStreaming: false,
completedAt: new Date(),
pendingTools: [],
pendingApprovals: [],
pendingQuestions: [],
- streamEvents: streamEventsWithoutUnresolvedInteractiveRows(
- terminalMsg.streamEvents,
- ),
+ streamEvents: streamEventsWithoutUnresolvedInteractiveRows(msg.streamEvents),
workflowStatus: undefined,
error: errorMsg || 'Request failed',
};