This commit is contained in:
Andrew Pareles 2025-04-30 13:58:51 -07:00
parent cbae8d5ec2
commit f13279e84a
3 changed files with 7 additions and 80 deletions

View file

@ -138,36 +138,6 @@ export const IconLoading = ({ className = '' }: { className?: string }) => {
}
export const IconTrash = ({
size,
className = '',
onClick
}: {
size: number,
className?: string,
onClick?: (event: React.MouseEvent<SVGElement, MouseEvent>) => void
}) => {
return (
<svg
className={className}
// These props are necessary to prevent the icon from being 'transparent'.
stroke="currentColor"
fill="currentColor"
strokeWidth="0"
viewBox="0 0 16 16"
width={size}
height={size}
xmlns="http://www.w3.org/2000/svg"
onClick={onClick}
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M10 3h3v1h-1v9l-1 1H4l-1-1V4H2V3h3V2a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v1zM9 2H6v1h3V2zM4 13h7V4H4v9zm2-8H5v7h1V5zm1 0h1v7H7V5zm2 0h1v7H9V5z"
/>
</svg>
);
};
const getChatBubbleId = (threadId: string, messageIdx: number) => `${threadId}-${messageIdx}`;

View file

@ -6,10 +6,8 @@
import React from "react";
import { useAccessor, useChatThreadsState } from '../util/services.js';
import { ISidebarStateService } from '../../../sidebarStateService.js';
import { IconX, IconTrash } from './SidebarChat.js';
import { IconX } from './SidebarChat.js';
const X_ICON_SIZE = 16
const TRASH_ICON_SIZE = 14
const truncate = (s: string) => {
let len = s.length
@ -30,7 +28,9 @@ export const SidebarThreadSelector = () => {
const { allThreads } = threadsState
// sorted by most recent to least recent
const sortedThreadIds = chatThreadsService.getSortedThreadIdsByTime().filter(threadId => allThreads![threadId].messages.length !== 0)
const sortedThreadIds = Object.keys(allThreads ?? {})
.sort((threadId1, threadId2) => allThreads![threadId1].lastModified > allThreads![threadId2].lastModified ? -1 : 1)
.filter(threadId => allThreads![threadId].messages.length !== 0)
return (
<div className="flex p-2 flex-col gap-y-1 max-h-[400px] overflow-y-auto">
@ -45,7 +45,7 @@ export const SidebarThreadSelector = () => {
onClick={() => sidebarStateService.setState({ isHistoryOpen: false })}
>
<IconX
size={X_ICON_SIZE}
size={16}
className="p-[1px] stroke-[2] opacity-80 text-void-fg-3 hover:brightness-95"
/>
</button>
@ -110,16 +110,6 @@ export const SidebarThreadSelector = () => {
>
<div className='truncate'>{`${firstMsg}`}</div>
<div>{`\u00A0(${numMessages})`}</div>
<IconTrash
size={TRASH_ICON_SIZE}
className='ml-auto'
onClick={(e) => {
// Prevent the click event from bubbling up to the parent button
// to prevent the deleted thread from being switched to.
e.stopPropagation();
chatThreadsService.deleteThreadById(pastThread.id);
}}
/>
</button>
</li>
);

View file

@ -12,7 +12,7 @@ import { URI } from '../../../../base/common/uri.js';
import { Emitter, Event } from '../../../../base/common/event.js';
import { IRange } from '../../../../editor/common/core/range.js';
import { ILLMMessageService } from './llmMessageService.js';
import { chat_userMessageContent, chat_systemMessage, chat_userMessageContentWithAllFilesToo, chat_selectionsString } from '../browser/prompt/prompts.js';
import { chat_userMessageContent, chat_systemMessage, chat_userMessageContentWithAllFilesToo as chat_userMessageContentWithAllFiles, chat_selectionsString } from '../browser/prompt/prompts.js';
import { InternalToolInfo, IToolsService, ToolCallReturnType, ToolFns, ToolName, voidTools } from './toolsService.js';
import { toLLMChatMessage } from './llmMessageTypes.js';
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
@ -153,11 +153,9 @@ export interface IChatThreadService {
onDidChangeCurrentThread: Event<void>;
onDidChangeStreamState: Event<{ threadId: string }>
getSortedThreadIdsByTime: () => string[]
getCurrentThread(): ChatThreads[string];
openNewThread(): void;
switchToThread(threadId: string): void;
deleteThreadById(threadId: string): void;
// you can edit multiple messages
// the one you're currently editing is "focused", and we add items to that one when you press cmd+L.
@ -247,33 +245,6 @@ class ChatThreadService extends Disposable implements IChatThreadService {
);
}
public deleteThreadById(threadId: string): void {
const { allThreads, currentThreadId } = this.state
if (!(threadId in allThreads)) {
console.error('Void: Tried deleting thread with id that does not exist.')
return
}
// If we're on the thread we're about to delete, switch away from it
if (threadId === currentThreadId) {
const switchToThreadId = this.getSortedThreadIdsByTime().find(id => id !== threadId)
if (switchToThreadId !== undefined) {
this.switchToThread(switchToThreadId)
}
else {
this.openNewThread()
}
}
// Delete the thread ID
const newAllThreads = { ...allThreads }
delete newAllThreads[threadId]
this._storeAllThreads(newAllThreads)
this._setState({ allThreads: newAllThreads, }, false)
}
// this should be the only place this.state = ... appears besides constructor
private _setState(state: Partial<ThreadsState>, affectsCurrent: boolean) {
@ -360,7 +331,7 @@ class ChatThreadService extends Disposable implements IChatThreadService {
const instructions = userMessage
const userMessageContent = await chat_userMessageContent(instructions, currSelns)
const selectionsStr = await chat_selectionsString(prevSelns, currSelns, this._voidFileService)
const userMessageFullContent = chat_userMessageContentWithAllFilesToo(userMessageContent, selectionsStr)
const userMessageFullContent = chat_userMessageContentWithAllFiles(userMessageContent, selectionsStr)
const userHistoryElt: ChatMessage = { role: 'user', content: userMessageContent, displayContent: instructions, selections: currSelns, state: defaultMessageState }
this._addMessageToThread(threadId, userHistoryElt)
@ -536,10 +507,6 @@ class ChatThreadService extends Disposable implements IChatThreadService {
this._setState({ allThreads: newThreads, currentThreadId: newThread.id }, true)
}
getSortedThreadIdsByTime() {
const allThreads = this.state.allThreads
return Object.keys(allThreads ?? {}).sort((threadId1, threadId2) => allThreads[threadId1].lastModified > allThreads[threadId2].lastModified ? -1 : 1)
}
_addMessageToThread(threadId: string, message: ChatMessage) {
const { allThreads } = this.state