fix(chat): show loading when run from console and when sending in app (#228)
This commit is contained in:
committed by
GitHub
Unverified
parent
95a4c0234a
commit
bf62639573
@@ -110,7 +110,7 @@ export function Chat() {
|
|||||||
{/* Messages Area */}
|
{/* Messages Area */}
|
||||||
<div className="flex-1 overflow-y-auto px-4 py-4">
|
<div className="flex-1 overflow-y-auto px-4 py-4">
|
||||||
<div className="max-w-4xl mx-auto space-y-4">
|
<div className="max-w-4xl mx-auto space-y-4">
|
||||||
{loading ? (
|
{loading && !sending ? (
|
||||||
<div className="flex h-full items-center justify-center py-20">
|
<div className="flex h-full items-center justify-center py-20">
|
||||||
<LoadingSpinner size="lg" />
|
<LoadingSpinner size="lg" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1305,7 +1305,11 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
|||||||
handleChatEvent: (event: Record<string, unknown>) => {
|
handleChatEvent: (event: Record<string, unknown>) => {
|
||||||
const runId = String(event.runId || '');
|
const runId = String(event.runId || '');
|
||||||
const eventState = String(event.state || '');
|
const eventState = String(event.state || '');
|
||||||
const { activeRunId } = get();
|
const eventSessionKey = event.sessionKey != null ? String(event.sessionKey) : null;
|
||||||
|
const { activeRunId, currentSessionKey } = get();
|
||||||
|
|
||||||
|
// Only process events for the current session (when sessionKey is present)
|
||||||
|
if (eventSessionKey != null && eventSessionKey !== currentSessionKey) return;
|
||||||
|
|
||||||
// Only process events for the active run (or if no active run set)
|
// Only process events for the active run (or if no active run set)
|
||||||
if (activeRunId && runId && runId !== activeRunId) return;
|
if (activeRunId && runId && runId !== activeRunId) return;
|
||||||
@@ -1332,9 +1336,23 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
|||||||
|| resolvedState === 'error' || resolvedState === 'aborted';
|
|| resolvedState === 'error' || resolvedState === 'aborted';
|
||||||
if (hasUsefulData) {
|
if (hasUsefulData) {
|
||||||
clearHistoryPoll();
|
clearHistoryPoll();
|
||||||
|
// Adopt run started from another client (e.g. console at 127.0.0.1:18789):
|
||||||
|
// show loading/streaming in the app when this session has an active run.
|
||||||
|
const { sending } = get();
|
||||||
|
if (!sending && runId) {
|
||||||
|
set({ sending: true, activeRunId: runId, error: null });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (resolvedState) {
|
switch (resolvedState) {
|
||||||
|
case 'started': {
|
||||||
|
// Run just started (e.g. from console); show loading immediately.
|
||||||
|
const { sending: currentSending } = get();
|
||||||
|
if (!currentSending && runId) {
|
||||||
|
set({ sending: true, activeRunId: runId, error: null });
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'delta': {
|
case 'delta': {
|
||||||
// If we're receiving new deltas, the Gateway has recovered from any
|
// If we're receiving new deltas, the Gateway has recovered from any
|
||||||
// prior error — cancel the error finalization timer and clear the
|
// prior error — cancel the error finalization timer and clear the
|
||||||
|
|||||||
@@ -94,6 +94,21 @@ export const useGatewayStore = create<GatewayState>((set, get) => ({
|
|||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When a run starts (e.g. user clicked Send on console), show loading in the app immediately.
|
||||||
|
const runId = p.runId ?? data.runId;
|
||||||
|
const sessionKey = p.sessionKey ?? data.sessionKey;
|
||||||
|
if (phase === 'started' && runId != null && sessionKey != null) {
|
||||||
|
import('./chat')
|
||||||
|
.then(({ useChatStore }) => {
|
||||||
|
useChatStore.getState().handleChatEvent({
|
||||||
|
state: 'started',
|
||||||
|
runId,
|
||||||
|
sessionKey,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
// When the agent run completes, reload history to get the final response.
|
// When the agent run completes, reload history to get the final response.
|
||||||
if (phase === 'completed' || phase === 'done' || phase === 'finished' || phase === 'end') {
|
if (phase === 'completed' || phase === 'done' || phase === 'finished' || phase === 'end') {
|
||||||
import('./chat')
|
import('./chat')
|
||||||
|
|||||||
Reference in New Issue
Block a user