-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It1: Start moving to async chat messages
- Loading branch information
1 parent
8c40196
commit bd4d93f
Showing
6 changed files
with
146 additions
and
54 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
extensions/codestory/src/completions/providers/aideAgentProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
import { getUserId } from '../../utilities/uniqueId'; | ||
|
||
export class AideAgentSessionProvider implements vscode.Disposable { | ||
private aideAgent: vscode.AideSessionAgent; | ||
|
||
private sessionId: string | undefined; | ||
private stream: vscode.ChatResponseStream | undefined; | ||
private eventQueue: vscode.ChatRequest[] = []; | ||
private processingEvents: Map<string, boolean> = new Map(); | ||
|
||
constructor() { | ||
this.aideAgent = vscode.aideAgent.createChatParticipant('aide', { | ||
newSession: this.newSession.bind(this), | ||
handleEvent: this.handleEvent.bind(this), | ||
}); | ||
this.aideAgent.iconPath = vscode.Uri.joinPath( | ||
vscode.extensions.getExtension('codestory-ghost.codestoryai')?.extensionUri ?? vscode.Uri.parse(''), | ||
'assets', | ||
'aide-agent.png' | ||
); | ||
this.aideAgent.requester = { | ||
name: getUserId(), | ||
icon: vscode.Uri.joinPath( | ||
vscode.extensions.getExtension('codestory-ghost.codestoryai')?.extensionUri ?? vscode.Uri.parse(''), | ||
'assets', | ||
'aide-user.png' | ||
) | ||
}; | ||
this.aideAgent.supportIssueReporting = false; | ||
this.aideAgent.welcomeMessageProvider = { | ||
provideWelcomeMessage: async () => { | ||
return [ | ||
'Hi, I\'m **Aide**, your personal coding assistant! I can find, understand, explain, debug or write code for you.', | ||
]; | ||
} | ||
}; | ||
} | ||
|
||
private newSession(sessionId: string, stream: vscode.ChatResponseStream): void { | ||
this.sessionId = sessionId; | ||
this.stream = stream; | ||
} | ||
|
||
private async handleEvent(event: vscode.ChatRequest, token: vscode.CancellationToken): Promise<void> { | ||
this.eventQueue.push(event); | ||
if (this.sessionId && !this.processingEvents.has(this.sessionId)) { | ||
this.processingEvents.set(this.sessionId, true); | ||
this.processEvent(event); | ||
} | ||
} | ||
|
||
private async processEvent(event: vscode.ChatRequest): Promise<void> { | ||
await this.generateResponse(event); | ||
if (this.sessionId) { | ||
this.processingEvents.delete(this.sessionId); | ||
} | ||
} | ||
|
||
private async generateResponse(event: vscode.ChatRequest) { | ||
// Simulate processing time | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
this.stream?.markdown('Hello, world! Thanks for telling me ' + event.prompt); | ||
} | ||
|
||
dispose() { | ||
this.aideAgent.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters