From 75ef9d552825f48147005323aac866918cf22615 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Fri, 7 Mar 2025 23:59:58 -0800 Subject: [PATCH] rm id and add tool_use_id --- .../void/browser/autocompleteService.ts | 2 - .../contrib/void/browser/chatThreadService.ts | 4 +- .../react/src/sidebar-tsx/SidebarChat.tsx | 7 +++- .../contrib/void/browser/toolsService.ts | 3 +- .../llmMessage/preprocessLLMMessages.ts | 39 ++++++++++++------- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/autocompleteService.ts b/src/vs/workbench/contrib/void/browser/autocompleteService.ts index 12d83d2c..8d219f1c 100644 --- a/src/vs/workbench/contrib/void/browser/autocompleteService.ts +++ b/src/vs/workbench/contrib/void/browser/autocompleteService.ts @@ -769,8 +769,6 @@ export class AutocompleteService extends Disposable implements IAutocompleteServ - // console.log('B') - // create a new autocompletion and add it to cache const newAutocompletion: Autocompletion = { id: this._autocompletionId++, diff --git a/src/vs/workbench/contrib/void/browser/chatThreadService.ts b/src/vs/workbench/contrib/void/browser/chatThreadService.ts index ad130a16..afd62eda 100644 --- a/src/vs/workbench/contrib/void/browser/chatThreadService.ts +++ b/src/vs/workbench/contrib/void/browser/chatThreadService.ts @@ -547,9 +547,9 @@ class ChatThreadService extends Disposable implements IChatThreadService { if (llmCancelToken === null) break this._setStreamState(threadId, { streamingToken: llmCancelToken }) - console.log('awaiting agentloop') + console.log('awaiting agentloop...') await awaitable - console.log('done') + console.log('done with agentloop!') } } diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index 30cefbb3..cc9d779e 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -1231,7 +1231,9 @@ const toolNameToComponent: { [T in ToolName]: { const { params } = toolRequest return } onClick={() => { commandService.executeCommand('vscode.open', params.uri, { preview: true }) }} - /> + > + + }, resultWrapper: ({ toolMessage }) => { const accessor = useAccessor() @@ -1392,6 +1394,9 @@ export const SidebarChat = () => { // send message to LLM const userMessage = textAreaRef.current?.value ?? '' + + // getModelCapabilities() // TODO!!! check if can go into agent mode + await chatThreadsService.addUserMessageAndStreamResponse({ userMessage, chatMode: 'agent' }) setSelections([]) // clear staging diff --git a/src/vs/workbench/contrib/void/browser/toolsService.ts b/src/vs/workbench/contrib/void/browser/toolsService.ts index a598c254..fe8dc41c 100644 --- a/src/vs/workbench/contrib/void/browser/toolsService.ts +++ b/src/vs/workbench/contrib/void/browser/toolsService.ts @@ -376,6 +376,7 @@ export class ToolsService implements IToolsService { const uri = validateURI(uriStr) const changeDescription = validateStr('changeDescription', changeDescriptionUnknown) + console.log('done validating!!!') return { uri, changeDescription } }, @@ -453,8 +454,6 @@ export class ToolsService implements IToolsService { from: 'ClickApply', type: 'searchReplace', }) ?? [] - console.log('B') - await p return {} }, diff --git a/src/vs/workbench/contrib/void/electron-main/llmMessage/preprocessLLMMessages.ts b/src/vs/workbench/contrib/void/electron-main/llmMessage/preprocessLLMMessages.ts index 514e3125..6ff7906e 100644 --- a/src/vs/workbench/contrib/void/electron-main/llmMessage/preprocessLLMMessages.ts +++ b/src/vs/workbench/contrib/void/electron-main/llmMessage/preprocessLLMMessages.ts @@ -166,8 +166,7 @@ type PrepareMessagesToolsOpenAI = ( }[] } | { role: 'tool', - id: string; // old val - tool_call_id: string; // new val + tool_call_id: string; content: string; } )[] @@ -199,9 +198,8 @@ const prepareMessages_tools_openai = ({ messages }: { messages: InternalLLMChatM // add the tool newMessages.push({ role: 'tool', - id: currMsg.id, - content: currMsg.content || EMPTY_TOOL_CONTENT, tool_call_id: currMsg.id, + content: currMsg.content || EMPTY_TOOL_CONTENT, }) } return { messages: newMessages } @@ -344,16 +342,31 @@ const prepareMessages_anthropicContent = ({ messages, supportsAnthropicReasoning const prepareMessages_noEmptyMessage = ({ messages }: { messages: PrepareMessagesTools }): { messages: PrepareMessagesTools } => { for (const currMsg of messages) { - if (currMsg.role === 'assistant' || currMsg.role === 'user') { - if (typeof currMsg.content === 'string') { - currMsg.content = currMsg.content || EMPTY_MESSAGE + // don't do this for tools + if (currMsg.role === 'tool') continue + + // don't do this for assistant or user messages that have tool_calls or tool_results + const oai = currMsg as PrepareMessagesToolsOpenAI[0] + if (oai.role === 'assistant') { + if (oai.tool_calls) continue + } + const anth = currMsg as PrepareMessagesToolsAnthropic[0] + if (anth.role === 'assistant' || anth.role === 'user') { + if (typeof anth.content !== 'string') { + const hasContent = anth.content.find(c => c.type === 'tool_use' || c.type === 'tool_result') + if (hasContent) continue } - else { - for (const c of currMsg.content) { - if (c.type === 'text') c.text = c.text || EMPTY_MESSAGE - else if (c.type === 'tool_use') { } - else if (c.type === 'tool_result') { } - } + } + + + if (typeof currMsg.content === 'string') { + currMsg.content = currMsg.content || EMPTY_MESSAGE + } + else { + for (const c of currMsg.content) { + if (c.type === 'text') c.text = c.text || EMPTY_MESSAGE + else if (c.type === 'tool_use') { } + else if (c.type === 'tool_result') { } } }