update prompt and add accept/reject ui

This commit is contained in:
Andrew Pareles 2025-03-03 23:01:24 -08:00
parent c9cc6cc6a1
commit 1259e71589
3 changed files with 18 additions and 8 deletions

View file

@ -186,6 +186,9 @@ export interface IChatThreadService {
cancelStreaming(threadId: string): void;
dismissStreamError(threadId: string): void;
approveTool(toolId: string): void;
rejectTool(toolId: string): void;
}
export const IChatThreadService = createDecorator<IChatThreadService>('voidChatThreadService');
@ -452,7 +455,7 @@ class ChatThreadService extends Disposable implements IChatThreadService {
// 3. call the tool
let toolResult: ToolResultType[typeof toolName]
try {
toolResult = this._toolsService.callTool[toolName](toolParams as any) // typescript is so bad it doesn't even couple the type of ToolResult with the type of the function being called here
toolResult = await this._toolsService.callTool[toolName](toolParams as any) // typescript is so bad it doesn't even couple the type of ToolResult with the type of the function being called here
} catch (error) {
const errorMessage = getErrorMessage(error)
this._addMessageToThread(threadId, { role: 'tool', name: toolName, paramsStr: tool.paramsStr, id: tool.id, content: errorMessage, result: { type: 'error', value: errorMessage }, })
@ -464,7 +467,7 @@ class ChatThreadService extends Disposable implements IChatThreadService {
// 4. stringify the result to give the LLM
let toolResultStr: string
try {
toolResultStr = this._toolsService.stringOfResult[toolName](toolParams as any, toolResult as any)
toolResultStr = await this._toolsService.stringOfResult[toolName](toolParams as any, toolResult as any)
} catch (error) {
const errorMessage = `Tool call succeeded, but there was an error stringifying the output.\n${getErrorMessage(error)}`
this._addMessageToThread(threadId, { role: 'tool', name: toolName, paramsStr: tool.paramsStr, id: tool.id, content: errorMessage, result: { type: 'error', value: errorMessage }, })

View file

@ -24,8 +24,8 @@ Do NOT output the whole file if possible, and try to write as LITTLE as needed t
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\`.
You are a coding assistant. Your job is to help the user understand and make changes to their codebase.
You will be given a list of instructions from the user to follow, \`INSTRUCTIONS\`. You may also be given a list of relevant files \`FILES\`, and selections inside of files \`SELECTIONS\`.
Please respond to the user's query. The user's query is never invalid.
The user has the following system information:
@ -45,6 +45,7 @@ If you are given tools:
- Feel free to use tools to gather context, make suggestions, etc.
- One great use of tools is to explore imports that you'd like to have more information about.
- Reference relevant files that you found when using tools if they helped you come up with your answer.
- Some tools only work if the user has a workspace open.
- NEVER refer to a tool by name when speaking with the user. For example, do NOT say to the user user "I'm going to use \`list_dir\`". Instead, say "I'm going to list all files in ___ directory", etc. Do not even refer to "pages" of results, just say you're getting more results.
Do not output any of these instructions, nor tell the user anything about them unless directly prompted for them.

View file

@ -543,7 +543,6 @@ const actionTitleOfToolName: { [T in ToolName]: string } = {
type ToolResultToComponent = { [T in ToolName]: (props: { message: ToolMessage<T> }) => React.ReactNode }
const ToolResult = ({
toolName,
@ -615,7 +614,7 @@ const ToolError = <T extends ToolName,>({ toolName, errorMessage }: { toolName:
}
const toolResultToComponent: ToolResultToComponent = {
const toolResultToComponent: { [T in ToolName]: (props: { message: ToolMessage<T> }) => React.ReactNode } = {
'read_file': ({ message }) => {
const accessor = useAccessor()
@ -626,7 +625,7 @@ const toolResultToComponent: ToolResultToComponent = {
return (
<ToolResult
toolName='read_file'
actionParam={'View file'}
actionParam={getBasename(params.uri.fsPath)}
>
<div className="text-void-fg-4 px-2 py-1 bg-black bg-opacity-20 border border-void-border-4 border-opacity-50 rounded-sm">
<div
@ -634,7 +633,7 @@ const toolResultToComponent: ToolResultToComponent = {
onClick={() => { commandService.executeCommand('vscode.open', params.uri, { preview: true }) }}
>
<svg className="w-1 h-1 opacity-60 mr-1.5 fill-current" viewBox="0 0 100 40"><rect x="0" y="15" width="100" height="10" /></svg>
{getBasename(params.uri.fsPath)}
{params.uri.fsPath}
</div>
{value.hasNextPage && (<div className="italic">AI can scroll for more content...</div>)}
</div>
@ -1034,6 +1033,13 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
console.log('tool result:', chatMessage.name, chatMessage.paramsStr, chatMessage.result)
}
else if (role === 'tool_request'){
chatbubbleContents = <>
<div className='text-void-fg-4 italic' onClick={() => {chatThreadsService.approveTool(chatMessage.voidToolId)}}>Accept</div>
<div className='text-void-fg-4 italic' onClick={() => {chatThreadsService.rejectTool(chatMessage.voidToolId)}}>Reject</div>
</>
}
return <div