Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

refactor: update visibility logic for ClearChatButton and related hooks to handle mutable sessions (#214)

Govinda Vashishtha810da6c6cd94
diff --git a/packages/trueforge-ui-sdk/src/atoms/ClearChatButton.tsx b/packages/trueforge-ui-sdk/src/atoms/ClearChatButton.tsx
index 5c64052b9..98aac2a82 100644
--- a/packages/trueforge-ui-sdk/src/atoms/ClearChatButton.tsx
+++ b/packages/trueforge-ui-sdk/src/atoms/ClearChatButton.tsx
@@ -5,7 +5,7 @@ import { Icon } from '../icons/Icon.js';
import { useOptionalShellMode } from '../server/ShellModeContext.js';
import { auiButtonClass } from './lib/buttonClasses.js';
-// Resets the current named or draft chat. Hidden on untitled empty drafts.
+// Resets an immutable (named) chat. Hidden while idle or on mutable drafts.
export function ClearChatButton() {
const shell = useOptionalShellMode();
const visible = useChatChromeActionsVisible();
diff --git a/packages/trueforge-ui-sdk/src/hooks/useChatChromeActionsVisible.ts b/packages/trueforge-ui-sdk/src/hooks/useChatChromeActionsVisible.ts
index 84e112cf5..a86ed3e1c 100644
--- a/packages/trueforge-ui-sdk/src/hooks/useChatChromeActionsVisible.ts
+++ b/packages/trueforge-ui-sdk/src/hooks/useChatChromeActionsVisible.ts
@@ -1,10 +1,8 @@
'use client';
-import { useAuiState } from '@assistant-ui/react';
import { useTrueFoundryAgentSpec } from '@truefoundry/assistant-ui-runtime';
import { useOptionalShellMode } from '../server/ShellModeContext.js';
-import { isNewChatView } from '../utils/isNewChatView.js';
// Immutable named-agent title in the thread header.
export function useNamedAgentHeaderVisible(): boolean {
@@ -22,21 +20,10 @@ export function useSaveAgentVisible(): boolean {
return Boolean(agentSpec?.model?.name?.trim());
}
-// Clear chat: after a chat has started (drafts need a model).
-// Named / saved agents keep Clear visible even on an empty welcome thread.
+// Clear chat: only on immutable (named / saved) sessions — same gate as the agent title.
export function useChatChromeActionsVisible(): boolean {
const shell = useOptionalShellMode();
- const { agentSpec } = useTrueFoundryAgentSpec();
- const isEmpty = useAuiState(isNewChatView);
-
- if (shell == null || shell.mode.status !== 'active') return false;
- if (shell.mode.isMutable && !agentSpec?.model?.name?.trim()) return false;
- if (isEmpty) {
- const boundName = shell.mode.agentName ?? shell.mode.agentId;
- const isNamedOrSaved = boundName != null && boundName.length > 0;
- if (!isNamedOrSaved) return false;
- }
- return true;
+ return shell != null && shell.mode.status === 'active' && !shell.mode.isMutable;
}
// True when the thread header has anything to show (title, Save, and/or Clear).
diff --git a/packages/trueforge-ui-sdk/test/atoms/ClearChatButton.test.tsx b/packages/trueforge-ui-sdk/test/atoms/ClearChatButton.test.tsx
index ca82b00f1..b086405b7 100644
--- a/packages/trueforge-ui-sdk/test/atoms/ClearChatButton.test.tsx
+++ b/packages/trueforge-ui-sdk/test/atoms/ClearChatButton.test.tsx
@@ -53,11 +53,11 @@ describe('ClearChatButton', () => {
expect(screen.getByRole('button', { name: 'Clear chat' })).toBeInTheDocument();
});
- it('is hidden on an empty untitled draft', () => {
+ it('is hidden on mutable sessions', () => {
render(
<SlotsProvider>
<ShellModeProvider agentConfig={{ mode: 'AgentComposer' }}>
- <RuntimeHarness messages={[]}>
+ <RuntimeHarness messages={startedMessages}>
<ClearChatButton />
</RuntimeHarness>
</ShellModeProvider>
diff --git a/packages/trueforge-ui-sdk/test/hooks/useChatChromeActionsVisible.test.tsx b/packages/trueforge-ui-sdk/test/hooks/useChatChromeActionsVisible.test.tsx
index 037df803c..d9a5e8085 100644
--- a/packages/trueforge-ui-sdk/test/hooks/useChatChromeActionsVisible.test.tsx
+++ b/packages/trueforge-ui-sdk/test/hooks/useChatChromeActionsVisible.test.tsx
@@ -62,7 +62,7 @@ describe('useChatHeaderContentVisible', () => {
expect(result.current.header).toBe(true);
});
- it('is false on an empty untitled draft with no model', () => {
+ it('hides Clear on mutable sessions even after chat has started', () => {
const { result } = renderHook(
() => ({
named: useNamedAgentHeaderVisible(),
@@ -72,15 +72,12 @@ describe('useChatHeaderContentVisible', () => {
}),
{
wrapper: wrap({
- messages: [],
agentConfig: { mode: 'AgentComposer' },
}),
},
);
expect(result.current.named).toBe(false);
- expect(result.current.save).toBe(false);
expect(result.current.clear).toBe(false);
- expect(result.current.header).toBe(false);
});
});