diff --git a/src/vs/workbench/contrib/void/browser/chatThreadService.ts b/src/vs/workbench/contrib/void/browser/chatThreadService.ts index dab3e62e..22c99c67 100644 --- a/src/vs/workbench/contrib/void/browser/chatThreadService.ts +++ b/src/vs/workbench/contrib/void/browser/chatThreadService.ts @@ -14,7 +14,7 @@ import { IRange } from '../../../../editor/common/core/range.js'; import { ILLMMessageService } from '../common/llmMessageService.js'; import { IModelService } from '../../../../editor/common/services/model.js'; import { chat_userMessage, chat_systemMessage } from './prompt/prompts.js'; -import { InternalToolInfo, IToolsService, ToolFns, ToolName, voidTools } from '../common/toolsService.js'; +import { InternalToolInfo, IToolsService, ToolCallReturnType, ToolFns, ToolName, voidTools } from '../common/toolsService.js'; import { toLLMChatMessage } from '../common/llmMessageTypes.js'; import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js'; @@ -43,6 +43,15 @@ export type StagingInfo = { const defaultStaging: StagingInfo = { isBeingEdited: false, selections: [] } +type ToolMessage = { + role: 'tool'; + name: T; // internal use + params: string; // internal use + id: string; // apis require this tool use id + content: string; // result + result: ToolCallReturnType; // text message of result +} + // WARNING: changing this format is a big deal!!!!!! need to migrate old format to new format on users' computers so people don't get errors. export type ChatMessage = @@ -60,14 +69,7 @@ export type ChatMessage = role: 'assistant'; content: string | null; // content received from LLM - allowed to be '', will be replaced with (empty) displayContent: string | null; // content displayed to user (this is the same as content for now) - allowed to be '', will be ignored - } | { - role: 'tool'; - name: string; // internal use - params: string; // internal use - id: string; // apis require this tool use id - content: string; // result - displayContent: string; // text message of result - } + } | ToolMessage // a 'thread' means a chat message history export type ChatThreads = { @@ -323,8 +325,9 @@ class ChatThreadService extends Disposable implements IChatThreadService { onText: ({ fullText }) => { this._setStreamState(threadId, { messageSoFar: fullText }) }, - onFinalMessage: async ({ fullText, toolCalls }) => { - toolCalls = toolCalls?.filter(tool => tool.name in this._toolsService.toolFns) + onFinalMessage: async ({ fullText, toolCalls: toolCalls_ }) => { + // make sure all tool names are valid so we can cast to ToolName below + const toolCalls = toolCalls_?.filter(tool => tool.name in this._toolsService.toolFns) console.log('FINAL MESSAGE', fullText, toolCalls) @@ -357,7 +360,7 @@ class ChatThreadService extends Disposable implements IChatThreadService { break } - this._addMessageToThread(threadId, { role: 'tool', name: tool.name, params: tool.params, id: tool.id, content: toolResultStr, displayContent: toolResultStr, }) + this._addMessageToThread(threadId, { role: 'tool', name: toolName, params: tool.params, id: tool.id, content: toolResultStr, result: toolResult, }) shouldContinue = true } diff --git a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts index 88e9144d..2b840f83 100644 --- a/src/vs/workbench/contrib/void/browser/prompt/prompts.ts +++ b/src/vs/workbench/contrib/void/browser/prompt/prompts.ts @@ -18,7 +18,7 @@ export const tripleTick = ['```', '```'] export const chat_systemMessage = (workspaces: string[]) => `\ You are a coding assistant. You are given a list of instructions to follow \`INSTRUCTIONS\`, and optionally a list of relevant files \`FILES\`, and selections inside of files \`SELECTIONS\`. -Please respond to the user's query. +Please respond to the user's query. The user's query is never invalid. The user has the following system information: - ${os} @@ -26,8 +26,8 @@ The user has the following system information: In the case that the user asks you to make changes to code, you should make sure to return CODE BLOCKS of the changes, as well as explanations and descriptions of the changes. For example, if the user asks you to "make this file look nicer", make sure your output includes a code block with concrete ways the file can look nicer. - - Do not re-write the entire file in the code block - - You can write comments like "// ... existing code" to indicate existing code + - Do not re-write the entire file in the code block. + - You can write comments like "// ... existing code" to indicate existing code. - Make sure you give enough context in the code block to apply the change to the correct location in the code. You're allowed to ask for more context. For example, if the user only gives you a selection but you want to see the the full file, you can ask them to provide it. diff --git a/src/vs/workbench/contrib/void/common/toolsService.ts b/src/vs/workbench/contrib/void/common/toolsService.ts index 2dde2219..07733c86 100644 --- a/src/vs/workbench/contrib/void/common/toolsService.ts +++ b/src/vs/workbench/contrib/void/common/toolsService.ts @@ -81,14 +81,14 @@ export type ToolParamsObj = { [paramName in ToolParamNames - = T extends 'read_file' ? Promise - : T extends 'list_dir' ? Promise - : T extends 'pathname_search' ? Promise - : T extends 'search' ? Promise + = T extends 'read_file' ? string + : T extends 'list_dir' ? string + : T extends 'pathname_search' ? string | URI[] + : T extends 'search' ? string | URI[] : never -export type ToolFns = { [T in ToolName]: (p: string) => ToolCallReturnType } -export type ToolResultToString = { [T in ToolName]: (result: Awaited>) => string } +export type ToolFns = { [T in ToolName]: (p: string) => Promise> } +export type ToolResultToString = { [T in ToolName]: (result: ToolCallReturnType) => string } async function generateDirectoryTreeMd(fileService: IFileService, rootURI: URI): Promise {