Skip to content

Commit

Permalink
Basic Agent Handler Method
Browse files Browse the repository at this point in the history
  • Loading branch information
samyakkkk committed Mar 14, 2024
1 parent 2c4f530 commit 9b1265f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
53 changes: 50 additions & 3 deletions vscode/src/utilities/commanddash-integration/dart-cli-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as child_process from 'child_process';
import { EventEmitter } from 'events';
import { integer } from 'vscode-languageclient';
import { Task } from './task';

export class DartCLIClient {
Expand Down Expand Up @@ -160,7 +159,7 @@ export async function testTaskWithSideOperation() {
const client = new DartCLIClient();
client.onProcessOperation('operation_data_kind', (message)=>{
const operationData = { value: "unique_value" };
client.sendOperationResponse('operation_data_kind', operationData);
task.sendStepResponse(message,operationData);
});
const task = client.newTask();

Expand All @@ -182,7 +181,7 @@ export async function testTaskWithSteps() {
// Handle client side steps during task processing.
task.onProcessStep('step_data_kind', (message) => {
/// any complex interaction to come up with response data.
const additionalData = { value: "unique_value_2" };
const additionalData = { value: "unique_value" };

// Respond back to CLI in every case. Either with data if required or just a confirmation.
client.sendStepResponse(message.id, 'step_data_kind', additionalData);
Expand All @@ -198,4 +197,52 @@ export async function testTaskWithSteps() {
} catch (error) {
console.error("Processing error: ", error);
}
}

export async function handleAgents() {
const client = new DartCLIClient();
const task = client.newTask();

task.onProcessStep('append_to_chat', (message)=>{
console.log(`append to chat:\n${message}`);
task.sendStepResponse(message, {'result': 'success'});
});
try {
/// Request the client to process the task and handle result or error
const response = await task.run({ kind: "agent-execute", data: {
"authdetails": {
"type": "gemini",
"key": "AIzaSyCUgTsTlr_zgfM7eElSYC488j7msF2b948",
"githubToken": ""
},
"inputs": [
{
"id": "736841542",
"type": "string_input",
"value":
"Where do you think AI is heading in the field of programming? Give a short answer."
}
],
"outputs": [
{"id": "90611917", "type": "default_output"}
],
"steps": [
{
"type": "prompt_query",
"query": "736841542",
"post_process": {"type": "raw"},

Check warning on line 233 in vscode/src/utilities/commanddash-integration/dart-cli-client.ts

View workflow job for this annotation

GitHub Actions / lint

Object Literal Property name `post_process` must match one of the following formats: camelCase
"output": "90611917"
},
{
"type": "append_to_chat",
"message": "<90611917>",
}
]
}
});
console.log("Processing completed: ", response);
} catch (error) {
console.error("Processing error: ", error);
}

}
4 changes: 4 additions & 0 deletions vscode/src/utilities/commanddash-integration/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class Task {
this.handlers.set(eventName, handler);
this.dartClient.eventEmitter.on(eventName, handler);
}

public sendStepResponse(message: any, response: any): any{
this.dartClient.sendStepResponse(message.id, message.params['kind'], response);
}

public async run(params: any = {}): Promise<any> {
try {
Expand Down

0 comments on commit 9b1265f

Please sign in to comment.