diff --git a/src/agents/Agent.ts b/src/agents/Agent.ts index 1c989eb..3da6bc4 100644 --- a/src/agents/Agent.ts +++ b/src/agents/Agent.ts @@ -172,7 +172,7 @@ export default abstract class Agent { if (input.command === command) { const response = callback(); if (response) { - context.onProgress({ type: 'content', content: response.reply.content }); + context.onProgress({ type: 'markdown', content: response.reply.content }); return response; } } diff --git a/src/agents/AgentContext.ts b/src/agents/AgentContext.ts index 1da1d2f..9023238 100644 --- a/src/agents/AgentContext.ts +++ b/src/agents/AgentContext.ts @@ -45,9 +45,15 @@ export type ProgressData = range?: { start: { line: number; character: number }; end: { line: number; character: number } }; } | { + /** Offer a button for the user to execute a command */ type: 'button'; command: { title: string; command: string; tooltip?: string; arguments?: any[] }; } + | { + /** Automatically execute a command */ + type: 'command'; + command: { title: string; command: string; arguments?: any[] }; + } | { /** Represents a tree, such as a file and directory structure, rendered in the chat response */ type: 'fileTree'; diff --git a/src/agents/adapters/AgentProtocolClient.ts b/src/agents/adapters/AgentProtocolClient.ts index 9ece17c..fcf06d2 100644 --- a/src/agents/adapters/AgentProtocolClient.ts +++ b/src/agents/adapters/AgentProtocolClient.ts @@ -23,7 +23,7 @@ export default class AgentProtocolClient extends Agent { override async receiveMessage(input: AgentInputMessage, context: AgentContext): Promise { const promisedStep = this.sendToRemoteAgent(input); - context.onProgress({ type: 'content', content: `Sending to remote agent at ${this.hostUrl}...\n\n` }); + context.onProgress({ type: 'markdown', content: `Sending to remote agent at ${this.hostUrl}...\n\n` }); const [step, content] = await promisedStep; @@ -31,14 +31,14 @@ export default class AgentProtocolClient extends Agent { this.taskId = undefined; } - context.onProgress({ type: 'content', content: content + '\n\n' }); + context.onProgress({ type: 'markdown', content: content + '\n\n' }); const { command } = step.additional_output || {}; if (command) { // TODO: ask_user(question: string) const toolResult = await ToolManager.executeTool(command.name, context, command.args); context.onProgress({ - type: 'content', + type: 'markdown', content: `Executed tool: ${command.name}(${command.args}) with result: ${toolResult}`, }); } diff --git a/src/agents/adapters/CliClient.ts b/src/agents/adapters/CliClient.ts index 66464d5..7eb290b 100644 --- a/src/agents/adapters/CliClient.ts +++ b/src/agents/adapters/CliClient.ts @@ -95,7 +95,7 @@ export class CliClient { logger.info(`Monitoring process ${process.pid}`); // Open the markdown box if (this.wrapOutput) { - context.onProgress({ type: 'content', content: this.wrapOutput + '\n' }); + context.onProgress({ type: 'markdown', content: this.wrapOutput + '\n' }); } return new Promise((resolve, reject) => { @@ -110,7 +110,7 @@ export class CliClient { try { stdout += chunk; - context.onProgress({ type: 'content', content: chunk }); + context.onProgress({ type: 'markdown', content: chunk }); } catch (err) { logger.error('Error formatting output:', err); } @@ -121,7 +121,7 @@ export class CliClient { logger.info('presumably that is the end?'); if (this.wrapOutput) { - context.onProgress({ type: 'content', content: `\n${this.wrapOutput}\n` }); + context.onProgress({ type: 'markdown', content: `\n${this.wrapOutput}\n` }); } removeListeners(); @@ -134,7 +134,7 @@ export class CliClient { stderr += data.toString(); const content = data.toString(); - context.onProgress({ type: 'content', content }); + context.onProgress({ type: 'markdown', content }); } catch (err) { logger.error('Error formatting error:', err); } diff --git a/src/llm/openai/openAiChatRequest.ts b/src/llm/openai/openAiChatRequest.ts index a5a7968..59f3913 100644 --- a/src/llm/openai/openAiChatRequest.ts +++ b/src/llm/openai/openAiChatRequest.ts @@ -98,7 +98,7 @@ export const openAiChatRequest = async ( const content = chunk.choices[0].delta.content; if (content) { buffer += content; - onProgress({ type: 'content', content }); + onProgress({ type: 'markdown', content }); } // TODO: cancellation diff --git a/src/tools/impl/execute_python_code.ts b/src/tools/impl/execute_python_code.ts index c1cc571..9e10125 100644 --- a/src/tools/impl/execute_python_code.ts +++ b/src/tools/impl/execute_python_code.ts @@ -22,11 +22,11 @@ const execute_python_code = async (context: ToolContext, code: string) => { const result = await runPythonInDocker(context, ['-c', `"${code}"`]); content = 'Executed Python code: \n```' + result + '\n```'; - context.onProgress({ type: 'content', content }); + context.onProgress({ type: 'markdown', content }); } catch (err) { content = 'Error executing Python code: \n```' + err + '\n```'; logger.error('Failed to execute python code:', err); - context.onProgress({ type: 'content', content: content }); + context.onProgress({ type: 'markdown', content: content }); } return content; @@ -63,7 +63,7 @@ const executePythonFile = async (context: ToolContext, filename: string, args: s content = `Error executing Python file: ${(error as Error).message}`; } } - context.onProgress({ type: 'content', content }); + context.onProgress({ type: 'markdown', content }); return content; }; diff --git a/src/tools/impl/read_file.ts b/src/tools/impl/read_file.ts index b06f075..905eb34 100644 --- a/src/tools/impl/read_file.ts +++ b/src/tools/impl/read_file.ts @@ -17,9 +17,12 @@ const read_file = async (context: ToolContext, filename: string, encoding?: Buff const contents = await fileStorage.readFile(filePath); context.onProgress({ - type: 'inlineContentReference', - title: `read_file('${path.basename(filePath)}')`, - inlineReference: filePath, + type: 'command', + command: { + title: `read_file('${path.basename(filePath)}')`, + command: TOOL_READ_FILE, + arguments: [filePath], + }, }); return contents.toString(encoding); diff --git a/src/tools/impl/write_file.ts b/src/tools/impl/write_file.ts index 84e7e07..642b365 100644 --- a/src/tools/impl/write_file.ts +++ b/src/tools/impl/write_file.ts @@ -17,9 +17,12 @@ const write_file = async (context: ToolContext, filename: string, contents: stri await fileStorage.saveTextFile(filePath, contents); context.onProgress({ - type: 'inlineContentReference', - title: `write_file(${path.basename(filename)})`, - inlineReference: filePath, + type: 'command', + command: { + title: `write_file('${path.basename(filePath)}')`, + command: TOOL_WRITE_FILE, + arguments: [filePath], + }, }); };