mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(site/src/pages/AgentsPage): use chat ID as terminal reconnection token (#23926)
The terminal panel in the agents sidebar generated a fresh
`reconnectionToken` via `crypto.randomUUID()` on every mount. Navigating
between chats or reloading the page orphaned the PTY session.
- Use the chat ID (`agentId`) as the reconnection token for
`TerminalPanel`
- Add optional `chatId` prop to `TerminalPanel`, falling back to a
random UUID when not provided
- Thread `agentId` from `AgentChatPageView` to `TerminalPanel`
This mirrors how the dedicated Terminal page persists sessions via a
URL-stored token.
> 🤖 Written by a Coder Agent. Reviewed by a human.
This commit is contained in:
@@ -404,6 +404,7 @@ export const AgentChatPageView: FC<AgentChatPageViewProps> = ({
|
||||
label: "Terminal",
|
||||
content: (
|
||||
<TerminalPanel
|
||||
chatId={agentId}
|
||||
isVisible={
|
||||
shouldShowSidebar && sidebarTabId === "terminal"
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ const meta = {
|
||||
title: "pages/AgentsPage/TerminalPanel",
|
||||
component: TerminalPanel,
|
||||
args: {
|
||||
chatId: "b5a8832c-72db-4679-8393-9a48dff20a20",
|
||||
workspaceAgent: createAgent("ready"),
|
||||
},
|
||||
parameters: {
|
||||
|
||||
@@ -16,12 +16,16 @@ import { WorkspaceTerminalAlerts } from "#/modules/terminal/WorkspaceTerminalAle
|
||||
import { openMaybePortForwardedURL } from "#/utils/portForward";
|
||||
|
||||
interface TerminalPanelProps {
|
||||
/** Used as the reconnection token so the PTY session survives
|
||||
* navigation and page reloads. */
|
||||
chatId: string;
|
||||
isVisible?: boolean;
|
||||
workspace?: TypesGen.Workspace;
|
||||
workspaceAgent?: TypesGen.WorkspaceAgent;
|
||||
}
|
||||
|
||||
export const TerminalPanel: FC<TerminalPanelProps> = ({
|
||||
chatId,
|
||||
isVisible,
|
||||
workspace,
|
||||
workspaceAgent,
|
||||
@@ -29,7 +33,6 @@ export const TerminalPanel: FC<TerminalPanelProps> = ({
|
||||
const { proxy } = useProxy();
|
||||
const { metadata } = useEmbeddedMetadata();
|
||||
const terminalRef = useRef<WorkspaceTerminalHandle>(null);
|
||||
const [reconnectionToken] = useState(() => crypto.randomUUID());
|
||||
const [connectionStatus, setConnectionStatus] =
|
||||
useState<ConnectionStatus>("initializing");
|
||||
const config = useQuery(deploymentConfig());
|
||||
@@ -95,7 +98,7 @@ export const TerminalPanel: FC<TerminalPanelProps> = ({
|
||||
isVisible={isVisible}
|
||||
onStatusChange={setConnectionStatus}
|
||||
onError={handleTerminalError}
|
||||
reconnectionToken={reconnectionToken}
|
||||
reconnectionToken={chatId}
|
||||
baseUrl={terminalConfig.baseUrl}
|
||||
terminalFontFamily={terminalConfig.fontFamily}
|
||||
renderer={terminalConfig.renderer}
|
||||
|
||||
Reference in New Issue
Block a user