Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/session/messageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ export class MessageHandler {
{ id: 'mcp', name: 'mcp', description: '打开 MCP 服务器管理' },
{ id: 'model', name: 'model', description: '切换 AI 模型' },
{ id: 'status', name: 'status', description: '查看当前状态' },
{ id: 'login', name: 'login', description: 'SSO 登录/登出' }
{ id: 'login', name: 'login', description: 'SSO 登录/登出' },
{ id: 'clear', name: 'clear', description: '清除对话历史并重置会话' }
];

const allCommands = [...sdkCommands, ...localCommands];
Expand Down
22 changes: 13 additions & 9 deletions webview/src/components/ChatApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,23 @@ export const ChatApp: React.FC<ChatAppProps> = ({ vscode }) => {
return () => window.removeEventListener('message', handleMessage);
}, []);

const handleClearChat = useCallback(() => {
if (stateRef.current.isStreaming) return;

vscode.postMessage({
command: 'clearChat'
});
}, [vscode]);

const handleSendMessage = useCallback((text: string, images?: Array<{ data: string; mediaType: string; }>, force: boolean = false) => {
const trimmedText = text.trim();
if (!trimmedText && (!images || images.length === 0)) return;

// Intercept local slash commands — open dialogs instead of sending to agent
if (trimmedText === '/clear') {
handleClearChat();
return;
}
if (trimmedText === '/config') {
dispatch({ type: 'SHOW_DIALOG', payload: { type: 'config', data: stateRef.current.configurationData || {} } });
vscode.postMessage({ command: 'getConfiguration' });
Expand Down Expand Up @@ -387,15 +399,7 @@ export const ChatApp: React.FC<ChatAppProps> = ({ vscode }) => {
images: images,
force: force
});
}, [vscode]);

const handleClearChat = useCallback(() => {
if (state.isStreaming) return;

vscode.postMessage({
command: 'clearChat'
});
}, [state.isStreaming, vscode]);
}, [vscode, handleClearChat]);

const handleAbortMessage = useCallback(() => {
if (!state.isStreaming) return;
Expand Down
2 changes: 1 addition & 1 deletion webview/src/components/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export const MessageInput = forwardRef<{ focus: () => void }, MessageInputProps>
range.deleteContents();

// Local commands (config/plugin/mcp) open dialog directly without inserting text
const localCommands = ['config', 'plugin', 'mcp', 'model', 'status', 'login'];
const localCommands = ['config', 'plugin', 'mcp', 'model', 'status', 'login', 'clear'];
if (localCommands.includes(command.name)) {
// Restore cursor after removing the slash
selection.removeAllRanges();
Expand Down