Browse Source

fix(studio): fix ChatBar dropping assistant responses on every interaction

The agent endpoint returns the response text in `data.response` and
the full session history in `data.session.messages`. The ChatBar was
replacing its entire message list with session history on every call,
but session messages don't include the latest assistant response —
so the reply was silently dropped every time.

Fix: always append `data.response` as an assistant message instead
of replacing with session history. Session restore only happens on
first panel open when ChatBar is empty.
Ma 7 months ago
parent
commit
367891c365
1 changed files with 5 additions and 10 deletions
  1. 5 10
      packages/studio/src/components/ChatBar.tsx

+ 5 - 10
packages/studio/src/components/ChatBar.tsx

@@ -279,10 +279,10 @@ export function ChatPanel({ open, onClose, t, sse, activeBookId }: {
         currentStage: data.session?.currentExecution?.stageLabel ?? data.session?.currentExecution?.status,
         pendingSummary: data.session?.pendingDecision?.summary,
       });
-      const restored = coerceSharedSessionMessages(data.session?.messages ?? []);
-      if (restored.length > 0) {
-        setMessages(restored);
-      }
+      setMessages((current) => {
+        if (current.length > 0) return current;
+        return coerceSharedSessionMessages(data.session?.messages ?? []);
+      });
     }).catch(() => {
       // keep local empty state on session fetch failures
     });
@@ -394,15 +394,10 @@ export function ChatPanel({ open, onClose, t, sse, activeBookId }: {
           currentStage: data.session.currentExecution?.stageLabel ?? data.session.currentExecution?.status,
           pendingSummary: data.session.pendingDecision?.summary,
         });
-        const restored = coerceSharedSessionMessages(data.session.messages ?? []);
-        if (restored.length > 0) {
-          setMessages(restored);
-          return;
-        }
       }
       setMessages((prev) => [...prev, {
         role: "assistant",
-        content: data.response ?? data.error ?? "Acknowledged.",
+        content: data.response ?? "Acknowledged.",
         timestamp: Date.now(),
       }]);
     } catch (e) {