Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: update use-acp to version 0.2.4 and better ACP loading state UI (#6815)

Myles Scolnick0025f3b89e06
diff --git a/frontend/package.json b/frontend/package.json
index 58cbb38822..1f383482fb 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -164,7 +164,7 @@
"thememirror": "^2.0.1",
"timestring": "^7.0.0",
"typescript-memoize": "^1.1.1",
- "use-acp": "^0.2.3",
+ "use-acp": "0.2.4",
"use-resize-observer": "^9.1.0",
"vega-lite": "^5.23.0",
"vega-loader": "^4.5.3",
diff --git a/frontend/src/components/chat/acp/__tests__/state.test.ts b/frontend/src/components/chat/acp/__tests__/state.test.ts
index ae14397460..10740c62c4 100644
--- a/frontend/src/components/chat/acp/__tests__/state.test.ts
+++ b/frontend/src/components/chat/acp/__tests__/state.test.ts
@@ -171,6 +171,62 @@ describe("state utility functions", () => {
`);
});
+ it("should clear externalAgentSessionId when switching between different agents", () => {
+ // Start with a Claude session that has an active external session ID
+ const claudeSession: AgentSession = {
+ agentId: "claude",
+ tabId: "tab_claude" as TabId,
+ title: "Claude session",
+ createdAt: 1_735_689_600_000,
+ lastUsedAt: 1_735_689_600_000,
+ externalAgentSessionId: "claude-session-123" as ExternalAgentSessionId,
+ };
+ const initialState: AgentSessionState = {
+ sessions: [claudeSession],
+ activeTabId: claudeSession.tabId,
+ };
+
+ // Switch to Gemini
+ const newState = addSession(initialState, { agentId: "gemini" });
+
+ // Should create a new Gemini session with null externalAgentSessionId
+ // and remove the Claude session (MAX_SESSIONS = 1)
+ expect(newState.sessions).toHaveLength(1);
+ expect(newState.sessions[0].agentId).toBe("gemini");
+ expect(newState.sessions[0].externalAgentSessionId).toBe(null);
+
+ // The active tab should be the new Gemini session
+ expect(newState.activeTabId).toBe(newState.sessions[0].tabId);
+ });
+
+ it("should clear externalAgentSessionId when switching from Gemini to Claude", () => {
+ // Start with a Gemini session that has an active external session ID
+ const geminiSession: AgentSession = {
+ agentId: "gemini",
+ tabId: "tab_gemini" as TabId,
+ title: "Gemini session",
+ createdAt: 1_735_689_600_000,
+ lastUsedAt: 1_735_689_600_000,
+ externalAgentSessionId: "gemini-session-456" as ExternalAgentSessionId,
+ };
+ const initialState: AgentSessionState = {
+ sessions: [geminiSession],
+ activeTabId: geminiSession.tabId,
+ };
+
+ // Switch to Claude
+ const newState = addSession(initialState, { agentId: "claude" });
+
+ // Should create a new Claude session with null externalAgentSessionId
+ // and remove the Gemini session (MAX_SESSIONS = 1)
+ expect(newState.sessions).toHaveLength(1);
+ expect(newState.sessions[0].agentId).toBe("claude");
+ expect(newState.sessions[0].externalAgentSessionId).toBe(null);
+
+ // The active tab should be the new Claude session
+ expect(newState.activeTabId).toBe(newState.sessions[0].tabId);
+ });
+
it("should not mutate original state", () => {
const initialState: AgentSessionState = {
sessions: [],
diff --git a/frontend/src/components/chat/acp/agent-panel.tsx b/frontend/src/components/chat/acp/agent-panel.tsx
index 468f3fe0ac..552b31808c 100644
--- a/frontend/src/components/chat/acp/agent-panel.tsx
+++ b/frontend/src/components/chat/acp/agent-panel.tsx
@@ -62,12 +62,14 @@ import {
SelectTrigger,
} from "@/components/ui/select";
import { toast } from "@/components/ui/use-toast";
+import { DelayMount } from "@/components/utils/delay-mount";
import { useRequestClient } from "@/core/network/requests";
import { filenameAtom } from "@/core/saving/file-state";
import { store } from "@/core/state/jotai";
import { Functions } from "@/utils/functions";
import { Paths } from "@/utils/paths";
import { FileAttachmentPill } from "../chat-components";
+import { ReadyToChatBlock } from "./blocks";
import {
convertFilesToResourceLinks,
parseContextFromPrompt,
@@ -548,6 +550,52 @@ const ChatContent = memo<ChatContentProps>(
}
}, [notifications.length, isScrolledToBottom, scrollToBottom]);
+ const renderThread = () => {
+ if (hasNotifications) {
+ return (
+ <AgentThread
+ isConnected={connectionState.status === "connected"}
+ notifications={notifications}
+ onRetryConnection={onRetryConnection}
+ onRetryLastAction={onRetryLastAction}
+ />
+ );
+ }
+
+ const isConnected = connectionState.status === "connected";
+ if (isConnected) {
+ return <ReadyToChatBlock />;
+ }
+
+ return (
+ <div className="flex items-center justify-center h-full min-h-[200px] flex-col">
+ <PanelEmptyState
+ title="Waiting for agent"
+ description="Your AI agent will appear here when active"
+ icon={<BotMessageSquareIcon />}
+ />
+ {isDisconnected && agentId && (
+ <AgentDocs
+ className="border-t pt-6 px-5"
+ title="Make sure you're connected to an agent"
+ description="Run this command in your terminal:"
+ agents={[agentId]}
+ />
+ )}
+ {isDisconnected && (
+ <Button
+ variant="outline"
+ onClick={onRetryConnection}
+ type="button"
+ className="mt-4"
+ >
+ Retry
+ </Button>
+ )}
+ </div>
+ );
+ };
+
return (
<div className="flex-1 flex flex-col overflow-hidden flex-shrink-0 relative">
{pendingPermission && (
@@ -569,43 +617,7 @@ const ChatContent = memo<ChatContentProps>(
Session ID: {sessionId}
</div>
)}
- {hasNotifications ? (
- <div className="space-y-2">
- <AgentThread
- isConnected={connectionState.status === "connected"}
- notifications={notifications}
- onRetryConnection={onRetryConnection}
- onRetryLastAction={onRetryLastAction}
- onDismissError={onDismissError}
- />
- </div>
- ) : (
- <div className="flex items-center justify-center h-full min-h-[200px] flex-col">
- <PanelEmptyState
- title="Waiting for agent"
- description="Your AI agent will appear here when active"
- icon={<BotMessageSquareIcon />}
- />
- {isDisconnected && agentId && (
- <AgentDocs
- className="border-t pt-6 px-5"
- title="Make sure you're connected to an agent"
- description="Run this command in your terminal:"
- agents={[agentId]}
- />
- )}
- {isDisconnected && (
- <Button
- variant="outline"
- onClick={onRetryConnection}
- type="button"
- className="mt-4"
- >
- Retry
- </Button>
- )}
- </div>
- )}
+ {renderThread()}
</div>
<ScrollToBottomButton
@@ -671,6 +683,7 @@ const AgentPanel: React.FC = () => {
const {
connect,
disconnect,
+ setActiveSessionId,
connectionState,
notifications,
pendingPermission,
@@ -695,6 +708,8 @@ const AgentPanel: React.FC = () => {
// Auto-connect to agent when we have an active session, but only once per session
useEffect(() => {
+ setActiveSessionId(null);
+
if (wsUrl === NO_WS_SET) {
return;
}
@@ -702,7 +717,9 @@ const AgentPanel: React.FC = () => {
logger.debug("Auto-connecting to agent", {
sessionId: activeSessionId,
});
- connect();
+ void connect().catch((error) => {
+ logger.error("Failed to connect to agent", { error });
+ });
return () => {
// We don't want to disconnect so users can switch between different
@@ -712,15 +729,13 @@ const AgentPanel: React.FC = () => {
}, [wsUrl]);
const handleNewSession = useEvent(async () => {
- if (isCreatingNewSession.current) {
- return;
- }
if (!agent) {
return;
}
// If there is an active session, we should stop it
if (activeSessionId) {
+ setActiveSessionId(null);
await agent.cancel({ sessionId: activeSessionId }).catch((error) => {
logger.error("Failed to cancel active session", { error });
});
@@ -969,6 +984,92 @@ const AgentPanel: React.FC = () => {
);
}
+ const renderBody = () => {
+ const isConnecting = connectionState.status === "connecting";
+ const delay = 200; // ms
+ if (isConnecting) {
+ return (
+ <DelayMount milliseconds={delay}>
+ <div className="flex items-center justify-center h-full min-h-[200px] flex-col">
+ <Spinner size="medium" className="text-primary" />
+ <span className="text-sm text-muted-foreground">
+ Connecting to the agent...
+ </span>
+ </div>
+ </DelayMount>
+ );
+ }
+
+ const isLoadingSession =
+ tabLastActiveSessionId == null && connectionState.status === "connected";
+ if (isLoadingSession) {
+ return (
+ <DelayMount milliseconds={delay}>
+ <div className="flex items-center justify-center h-full min-h-[200px] flex-col">
+ <Spinner size="medium" className="text-primary" />
+ <span className="text-sm text-muted-foreground">
+ Creating a new session...
+ </span>
+ </div>
+ </DelayMount>
+ );
+ }
+
+ return (
+ <>
+ <ChatContent
+ key={activeSessionId}
+ agentId={selectedTab?.agentId}
+ sessionId={selectedTab?.externalAgentSessionId ?? null}
+ hasNotifications={hasNotifications}
+ connectionState={connectionState}
+ notifications={notifications}
+ pendingPermission={pendingPermission}
+ onResolvePermission={(option) => {
+ logger.debug("Resolving permission request", {
+ sessionId: activeSessionId,
+ option,
+ });
+ resolvePermission(option);
+ }}
+ onRetryConnection={handleManualConnect}
+ />
+
+ <LoadingIndicator
+ isLoading={isLoading}
+ isRequestingPermission={!!pendingPermission}
+ onStop={handleStop}
+ />
+
+ {files && files.length > 0 && (
+ <div className="flex flex-row gap-1 flex-wrap p-3 border-t">
+ {files.map((file) => (
+ <FileAttachmentPill
+ file={file}
+ key={file.name}
+ onRemove={() => handleRemoveFile(file)}
+ />
+ ))}
+ </div>
+ )}
+
+ <PromptArea
+ isLoading={isLoading}
+ activeSessionId={activeSessionId}
+ promptValue={promptValue}
+ onPromptValueChange={setPromptValue}
+ onPromptSubmit={handlePromptSubmit}
+ onAddFiles={handleAddFiles}
+ onStop={handleStop}
+ fileInputRef={fileInputRef}
+ commands={availableCommands}
+ sessionMode={sessionMode}
+ onModeChange={handleModeChange}
+ />
+ </>
+ );
+ };
+
return (
<div className="flex flex-col flex-1 overflow-hidden mo-agent-panel">
<AgentPanelHeader
@@ -982,54 +1083,7 @@ const AgentPanel: React.FC = () => {
/>
<SessionTabs />
- <ChatContent
- agentId={selectedTab?.agentId}
- sessionId={activeSessionId}
- hasNotifications={hasNotifications}
- connectionState={connectionState}
- notifications={notifications}
- pendingPermission={pendingPermission}
- onResolvePermission={(option) => {
- logger.debug("Resolving permission request", {
- sessionId: activeSessionId,
- option,
- });
- resolvePermission(option);
- }}
- onRetryConnection={handleManualConnect}
- />
-
- <LoadingIndicator
- isLoading={isLoading}
- isRequestingPermission={!!pendingPermission}
- onStop={handleStop}
- />
-
- {files && files.length > 0 && (
- <div className="flex flex-row gap-1 flex-wrap p-3 border-t">
- {files.map((file) => (
- <FileAttachmentPill
- file={file}
- key={file.name}
- onRemove={() => handleRemoveFile(file)}
- />
- ))}
- </div>
- )}
-
- <PromptArea
- isLoading={isLoading}
- activeSessionId={activeSessionId}
- promptValue={promptValue}
- onPromptValueChange={setPromptValue}
- onPromptSubmit={handlePromptSubmit}
- onAddFiles={handleAddFiles}
- onStop={handleStop}
- fileInputRef={fileInputRef}
- commands={availableCommands}
- sessionMode={sessionMode}
- onModeChange={handleModeChange}
- />
+ {renderBody()}
</div>
);
};
diff --git a/frontend/src/components/chat/acp/blocks.tsx b/frontend/src/components/chat/acp/blocks.tsx
index 72ad9df2a9..4b49279539 100644
--- a/frontend/src/components/chat/acp/blocks.tsx
+++ b/frontend/src/components/chat/acp/blocks.tsx
@@ -6,6 +6,7 @@ import type {
} from "@zed-industries/agent-client-protocol";
import { capitalize } from "lodash-es";
import {
+ BotMessageSquareIcon,
FileAudio2Icon,
FileIcon,
FileImageIcon,
@@ -114,16 +115,37 @@ export const ErrorBlock = (props: {
);
};
+export const ReadyToChatBlock = () => {
+ return (
+ <div className="flex-1 flex items-center justify-center h-full min-h-[200px] flex-col">
+ <div className="text-center space-y-3">
+ <div className="w-12 h-12 mx-auto rounded-full bg-[var(--blue-3)] flex items-center justify-center">
+ <BotMessageSquareIcon className="h-6 w-6 text-[var(--blue-10)]" />
+ </div>
+ <div>
+ <h3 className="text-lg font-medium text-foreground mb-1">
+ Agent is connected
+ </h3>
+ <p className="text-sm text-muted-foreground">
+ You can start chatting with your agent now
+ </p>
+ </div>
+ </div>
+ </div>
+ );
+};
+
export const ConnectionChangeBlock = (props: {
data: ConnectionChangeNotificationEvent["data"];
isConnected: boolean;
onRetry?: () => void;
timestamp?: number;
+ isOnlyBlock: boolean;
}) => {
const { status } = props.data;
- if (props.isConnected) {
- return null;
+ if (props.isConnected && props.isOnlyBlock) {
+ return <ReadyToChatBlock />;
}
const getStatusConfig = () => {
diff --git a/frontend/src/components/chat/acp/thread.tsx b/frontend/src/components/chat/acp/thread.tsx
index 205d4f9ac1..eda5b4145a 100644
--- a/frontend/src/components/chat/acp/thread.tsx
+++ b/frontend/src/components/chat/acp/thread.tsx
@@ -5,6 +5,7 @@ import { groupNotifications } from "use-acp";
import {
ConnectionChangeBlock,
ErrorBlock,
+ ReadyToChatBlock,
SessionNotificationsBlock,
} from "./blocks";
@@ -30,7 +31,15 @@ export const AgentThread = ({
let combinedNotifications = groupNotifications(notifications);
// Filter out all connection changes unless it is the last one
+ // Filter out available_commands_update
combinedNotifications = combinedNotifications.filter((group, index) => {
+ if (
+ isSessionNotificationGroup(group) &&
+ group[0].data.update.sessionUpdate === "available_commands_update"
+ ) {
+ return false;
+ }
+
const isLast = index === combinedNotifications.length - 1;
if (isLast) {
return true;
@@ -66,6 +75,7 @@ export const AgentThread = ({
key={lastConnectionChange.id}
data={lastConnectionChange.data}
isConnected={isConnected}
+ isOnlyBlock={combinedNotifications.length === 1}
onRetry={onRetryConnection}
timestamp={lastConnectionChange.timestamp}
/>
@@ -87,12 +97,13 @@ export const AgentThread = ({
};
return (
- <div className="flex flex-col gap-4 px-2 pb-10">
+ <div className="flex flex-col gap-4 px-2 pb-10 flex-1">
{combinedNotifications.map((notification) => (
<React.Fragment key={notification[0].id}>
{renderNotification(notification)}
</React.Fragment>
))}
+ {combinedNotifications.length === 0 && <ReadyToChatBlock />}
</div>
);
};
diff --git a/frontend/src/components/chat/markdown-renderer.css b/frontend/src/components/chat/markdown-renderer.css
index 880ae37ffd..f9509269b9 100644
--- a/frontend/src/components/chat/markdown-renderer.css
+++ b/frontend/src/components/chat/markdown-renderer.css
@@ -33,6 +33,7 @@
code {
font-size: inherit !important;
+ white-space: pre-wrap;
}
li.task-list-item {
diff --git a/frontend/src/components/utils/delay-mount.tsx b/frontend/src/components/utils/delay-mount.tsx
index 9f0a71d306..71c7b0dd32 100644
--- a/frontend/src/components/utils/delay-mount.tsx
+++ b/frontend/src/components/utils/delay-mount.tsx
@@ -76,6 +76,8 @@ export const DelayMount = ({
const shouldShow = visibility && !hasBeenVisible ? false : mounted;
return (
- <div ref={visibility ? ref : null}>{shouldShow ? children : fallback}</div>
+ <div ref={visibility ? ref : null} className="contents">
+ {shouldShow ? children : fallback}
+ </div>
);
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index fd4df2ebf0..ba1ce248a1 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -478,8 +478,8 @@ importers:
specifier: ^1.1.1
version: 1.1.1
use-acp:
- specifier: ^0.2.3
+ specifier: 0.2.4
use-resize-observer:
specifier: ^9.1.0
@@ -9638,8 +9638,8 @@ packages:
resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==}
- resolution: {integrity: sha512-bcnKK82iJctyk+gp/8AgGnbd7WoteU2fVa+GDAJSZuOoze6zN3CiqCYBCTUnpyJKmfzQrSL3okUblt0FITArBw==}
+ resolution: {integrity: sha512-PLXxQy5wRsDj1djnPX2lInGzld5FIWkpXblLBrkdmEYITg+hFSawwYLCM800kB9omgSjU1+iJSYb7wqN6VxzYg==}
peerDependencies:
react: ^19.1.0
react-dom: ^19.1.0
@@ -21192,7 +21192,7 @@ snapshots:
querystringify: 2.2.0
requires-port: 1.0.0
dependencies:
'@zed-industries/agent-client-protocol': 0.3.1
react: 19.1.1