Skip to content

Commit

Permalink
updated progress types
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbion committed Mar 12, 2024
1 parent 8830b01 commit 2dfc56b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/agents/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/agents/AgentContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions src/agents/adapters/AgentProtocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ export default class AgentProtocolClient extends Agent {
override async receiveMessage(input: AgentInputMessage, context: AgentContext): Promise<AgentResponse> {
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;

if (step.is_last) {
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}`,
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/agents/adapters/CliClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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);
}
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/llm/openai/openAiChatRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/tools/impl/execute_python_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};

Expand Down
9 changes: 6 additions & 3 deletions src/tools/impl/read_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/tools/impl/write_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
});
};

Expand Down

0 comments on commit 2dfc56b

Please sign in to comment.