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.

Show Assistant route startup immediately

rcourtman6555e172f25a
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 015ae13b3f..642681338c 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -208,8 +208,8 @@ describe('useChat', () => {
pendingTools: [],
workflowStatusHistory: [],
workflowStatus: {
- phase: 'request_send',
- message: 'Sending prompt.',
+ phase: 'request_wait',
+ message: 'Assistant is starting the response.',
},
});
expect(mockCreateSession).not.toHaveBeenCalled();
@@ -224,7 +224,7 @@ describe('useChat', () => {
dispose();
});
- it('promotes a quiet sent prompt to a local waiting status before backend activity arrives', async () => {
+ it('starts a quiet sent prompt with local waiting status before backend activity arrives', async () => {
vi.useFakeTimers();
vi.setSystemTime(1_000);
let resolveChat!: () => void;
@@ -241,23 +241,23 @@ describe('useChat', () => {
role: 'assistant',
isStreaming: true,
workflowStatus: {
- phase: 'request_send',
- message: 'Sending prompt.',
+ phase: 'request_wait',
+ message: 'Assistant is starting the response.',
startedAt: 1_000,
},
});
await vi.advanceTimersByTimeAsync(899);
expect(chat.messages()[1].workflowStatus).toMatchObject({
- phase: 'request_send',
- message: 'Sending prompt.',
+ phase: 'request_wait',
+ message: 'Assistant is starting the response.',
});
await vi.advanceTimersByTimeAsync(1);
expect(chat.messages()[1]).toMatchObject({
workflowStatus: {
phase: 'request_wait',
- message: 'Waiting for assistant.',
+ message: 'Assistant is starting the response.',
startedAt: 1_000,
},
streamEvents: [
@@ -265,7 +265,7 @@ describe('useChat', () => {
type: 'workflow_status',
workflowStatus: expect.objectContaining({
phase: 'request_wait',
- message: 'Waiting for assistant.',
+ message: 'Assistant is starting the response.',
}),
}),
],
@@ -361,8 +361,8 @@ describe('useChat', () => {
isStreaming: true,
workflowStatusHistory: [],
workflowStatus: {
- phase: 'request_send',
- message: 'Sending prompt to OpenRouter.',
+ phase: 'request_wait',
+ message: 'OpenRouter is starting the response.',
provider: 'openrouter',
model: 'openrouter:qwen/qwen3.7-plus',
},
@@ -376,8 +376,8 @@ describe('useChat', () => {
expect.objectContaining({
type: 'workflow_status',
workflowStatus: expect.objectContaining({
- phase: 'request_send',
- message: 'Sending prompt to OpenRouter.',
+ phase: 'request_wait',
+ message: 'OpenRouter is starting the response.',
provider: 'openrouter',
model: 'openrouter:qwen/qwen3.7-plus',
}),
@@ -389,7 +389,7 @@ describe('useChat', () => {
dispose();
});
- it('promotes a quiet selected route to provider startup progress', async () => {
+ it('starts a quiet selected route with provider startup progress', async () => {
vi.useFakeTimers();
vi.setSystemTime(2_000);
let resolveChat!: () => void;
@@ -404,8 +404,6 @@ describe('useChat', () => {
);
const result = chat.sendMessage('hello');
- await vi.advanceTimersByTimeAsync(900);
-
const assistant = chat.messages()[1];
expect(assistant.workflowStatus).toMatchObject({
phase: 'request_wait',
@@ -1404,7 +1402,7 @@ describe('useChat', () => {
const assistant = chat.messages().find((m) => m.role === 'assistant')!;
expect(assistant.model).toBe('openrouter:openai/gpt-4o-mini');
- expect(assistant.workflowStatus?.phase).toBe('request_send');
+ expect(assistant.workflowStatus?.phase).toBe('request_wait');
expect(assistant.streamEvents).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
@@ -1497,7 +1495,7 @@ describe('useChat', () => {
const assistant = chat.messages().find((m) => m.role === 'assistant')!;
expect(assistant.model).toBe('openrouter:openai/gpt-4o-mini');
- expect(assistant.workflowStatus?.phase).toBe('request_send');
+ expect(assistant.workflowStatus?.phase).toBe('request_wait');
expect(assistant.streamEvents).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
@@ -1763,8 +1761,8 @@ describe('useChat', () => {
expect.objectContaining({
type: 'workflow_status',
workflowStatus: expect.objectContaining({
- phase: 'request_send',
- message: 'Sending prompt to OpenRouter.',
+ phase: 'request_wait',
+ message: 'OpenRouter is starting the response.',
provider: 'openrouter',
model: 'openrouter:qwen/qwen3.7-plus',
}),
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index 719e3734cc..91540b8ee4 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -35,7 +35,6 @@ import type {
const generateId = () => Math.random().toString(36).substring(2, 9);
type AssistantInterruption = NonNullable<ChatMessage['interruption']>;
const WORKFLOW_STATUS_HISTORY_LIMIT = 8;
-const LOCAL_ASSISTANT_WAIT_STATUS_DELAY_MS = 900;
const messageModelCameFromRouteSwitch = (message: ChatMessage, modelRoute: string): boolean =>
Boolean(
@@ -85,20 +84,7 @@ const routeProviderLabel = (modelRoute?: string) => {
return provider ? getAIProviderDisplayName(provider) : '';
};
-const createInitialAssistantWorkflowStatus = (
- modelRoute?: string,
- startedAt = Date.now(),
-): WorkflowStatus => {
- const providerLabel = routeProviderLabel(modelRoute);
- return {
- phase: 'request_send',
- message: providerLabel ? `Sending prompt to ${providerLabel}.` : 'Sending prompt.',
- ...routeAwareWorkflowStatusFields(modelRoute),
- startedAt,
- };
-};
-
-const createLocalAssistantWaitWorkflowStatus = (
+const createAssistantRouteStartWorkflowStatus = (
modelRoute?: string,
startedAt = Date.now(),
): WorkflowStatus => {
@@ -107,7 +93,7 @@ const createLocalAssistantWaitWorkflowStatus = (
phase: 'request_wait',
message: providerLabel
? `${providerLabel} is starting the response.`
- : 'Waiting for assistant.',
+ : 'Assistant is starting the response.',
...routeAwareWorkflowStatusFields(modelRoute),
startedAt,
};
@@ -179,13 +165,6 @@ export function useChat(options: UseChatOptions = {}) {
let abortControllerRef: AbortController | null = null;
let activeRequestId = 0;
let pendingBackendAbort: Promise<void> | null = null;
- let localAssistantWaitStatusTimer: ReturnType<typeof setTimeout> | undefined;
-
- const clearLocalAssistantWaitStatusTimer = () => {
- if (localAssistantWaitStatusTimer === undefined) return;
- clearTimeout(localAssistantWaitStatusTimer);
- localAssistantWaitStatusTimer = undefined;
- };
let isDrainingQueuedFollowUps = false;
const suppressedRawContentMessageIds = new Set<string>();
const outputArtifactStreamStates = new Map<string, AssistantOutputArtifactStreamState>();
@@ -335,7 +314,6 @@ export function useChat(options: UseChatOptions = {}) {
abortControllerRef.abort();
abortControllerRef = null;
}
- clearLocalAssistantWaitStatusTimer();
activeRequestId += 1;
setMessages((prev) =>
@@ -1872,7 +1850,10 @@ export function useChat(options: UseChatOptions = {}) {
};
const assistantId = generateId();
- const initialWorkflowStatus = createInitialAssistantWorkflowStatus(requestModel, turnStartedAt);
+ const initialWorkflowStatus = createAssistantRouteStartWorkflowStatus(
+ requestModel,
+ turnStartedAt,
+ );
const initialStreamEvents: StreamDisplayEvent[] = [
...(requestModel
? [
@@ -1932,31 +1913,9 @@ export function useChat(options: UseChatOptions = {}) {
abortControllerRef = abortController;
let visibleTurnCompleted = false;
- const promoteLocalWaitStatus = () => {
- localAssistantWaitStatusTimer = undefined;
- if (requestId !== activeRequestId) return;
- const waitStatus = createLocalAssistantWaitWorkflowStatus(requestModel, turnStartedAt);
- setMessages((prev) =>
- prev.map((msg) => {
- if (msg.id !== assistantId) return msg;
- if (msg.isStreaming === false) return msg;
- if (msg.workflowStatus?.phase !== 'request_send') return msg;
- const updated = withWorkflowStatusEvent(msg, waitStatus);
- return { ...updated, workflowStatus: waitStatus };
- }),
- );
- };
-
- clearLocalAssistantWaitStatusTimer();
- localAssistantWaitStatusTimer = setTimeout(
- promoteLocalWaitStatus,
- LOCAL_ASSISTANT_WAIT_STATUS_DELAY_MS,
- );
-
const completeVisibleTurn = () => {
if (requestId !== activeRequestId || visibleTurnCompleted) return;
visibleTurnCompleted = true;
- clearLocalAssistantWaitStatusTimer();
abortControllerRef = null;
setIsLoading(false);
if (options?.drainAfter !== false) {
@@ -1972,9 +1931,6 @@ export function useChat(options: UseChatOptions = {}) {
currentSessionId || undefined,
requestModel || undefined,
(event: StreamEvent) => {
- if (event.type !== 'session') {
- clearLocalAssistantWaitStatusTimer();
- }
processEvent(assistantId, requestId, event);
},
abortController.signal,