1919 *--------------------------------------------------------------------------------------------*/
2020// Partially copied from https://github.com/microsoft/vscode/blob/a2cab7255c0df424027be05d58e1b7b941f4ea60/src/vs/workbench/contrib/chat/common/chatAgents.ts
2121
22+ import { CommunicationRecordingService } from '@theia/ai-core' ;
2223import {
2324 Agent ,
2425 isLanguageModelStreamResponse ,
@@ -28,7 +29,7 @@ import {
2829 LanguageModelStreamResponsePart ,
2930 PromptTemplate
3031} from '@theia/ai-core/lib/common' ;
31- import { ILogger , isArray } from '@theia/core' ;
32+ import { generateUuid , ILogger , isArray } from '@theia/core' ;
3233import { inject , injectable } from '@theia/core/shared/inversify' ;
3334import { ChatRequestModelImpl , ChatResponseContent , MarkdownChatResponseContentImpl } from './chat-model' ;
3435import { getMessages } from './chat-util' ;
@@ -67,6 +68,9 @@ export class DefaultChatAgent implements ChatAgent {
6768 @inject ( ILogger )
6869 protected logger : ILogger ;
6970
71+ @inject ( CommunicationRecordingService )
72+ protected recordingService : CommunicationRecordingService ;
73+
7074 id : string = 'DefaultChatAgent' ;
7175 name : string = 'Default Chat Agent' ;
7276 description : string = 'The default chat agent provided by Theia.' ;
@@ -95,6 +99,13 @@ export class DefaultChatAgent implements ChatAgent {
9599 locations : ChatAgentLocation [ ] = [ ] ;
96100
97101 async invoke ( request : ChatRequestModelImpl ) : Promise < void > {
102+ this . recordingService . recordRequest ( {
103+ agentId : this . id ,
104+ sessionId : request . session . id ,
105+ timestamp : Date . now ( ) ,
106+ requestId : request . id ,
107+ request : request . request . text
108+ } ) ;
98109 const selector = this . languageModelRequirements . find ( req => req . purpose === 'chat' ) ! ;
99110 const languageModels = await this . languageModelRegistry . selectLanguageModels ( { agent : this . id , ...selector } ) ;
100111 if ( languageModels . length === 0 ) {
@@ -106,6 +117,13 @@ export class DefaultChatAgent implements ChatAgent {
106117 new MarkdownChatResponseContentImpl ( languageModelResponse . text )
107118 ) ;
108119 request . response . complete ( ) ;
120+ this . recordingService . recordResponse ( {
121+ agentId : this . id ,
122+ sessionId : request . session . id ,
123+ timestamp : Date . now ( ) ,
124+ requestId : request . response . requestId ,
125+ response : request . response . response . asString ( )
126+ } ) ;
109127 return ;
110128 }
111129 if ( isLanguageModelStreamResponse ( languageModelResponse ) ) {
@@ -118,6 +136,13 @@ export class DefaultChatAgent implements ChatAgent {
118136 }
119137 }
120138 request . response . complete ( ) ;
139+ this . recordingService . recordResponse ( {
140+ agentId : this . id ,
141+ sessionId : request . session . id ,
142+ timestamp : Date . now ( ) ,
143+ requestId : request . response . requestId ,
144+ response : request . response . response . asString ( )
145+ } ) ;
121146 return ;
122147 }
123148 this . logger . error (
@@ -129,6 +154,13 @@ export class DefaultChatAgent implements ChatAgent {
129154 )
130155 ) ;
131156 request . response . complete ( ) ;
157+ this . recordingService . recordResponse ( {
158+ agentId : this . id ,
159+ sessionId : request . session . id ,
160+ timestamp : Date . now ( ) ,
161+ requestId : request . response . requestId ,
162+ response : request . response . response . asString ( )
163+ } ) ;
132164 }
133165
134166 private parse ( token : LanguageModelStreamResponsePart , previousContent : ChatResponseContent [ ] ) : ChatResponseContent | ChatResponseContent [ ] {
@@ -141,3 +173,37 @@ export class DefaultChatAgent implements ChatAgent {
141173 return new MarkdownChatResponseContentImpl ( token . content ?? '' ) ;
142174 }
143175}
176+
177+ @injectable ( )
178+ export class DummyChatAgent implements ChatAgent {
179+
180+ @inject ( CommunicationRecordingService )
181+ protected recordingService : CommunicationRecordingService ;
182+
183+ id : string = 'DummyChatAgent' ;
184+ name : string = 'Dummy Chat Agent' ;
185+ description : string = 'The dummy chat agent provided by ES.' ;
186+ variables : string [ ] = [ ] ;
187+ promptTemplates : PromptTemplate [ ] = [ ] ;
188+ languageModelRequirements : Omit < LanguageModelSelector , 'agentId' > [ ] = [ ] ;
189+ locations : ChatAgentLocation [ ] = [ ] ;
190+
191+ async invoke ( request ?: ChatRequestModelImpl ) : Promise < void > {
192+ const requestUuid = generateUuid ( ) ;
193+ const sessionId = 'dummy-session' ;
194+ this . recordingService . recordRequest ( {
195+ agentId : this . id ,
196+ sessionId : sessionId ,
197+ timestamp : Date . now ( ) ,
198+ requestId : requestUuid ,
199+ request : 'Dummy request'
200+ } ) ;
201+ this . recordingService . recordResponse ( {
202+ agentId : this . id ,
203+ sessionId : sessionId ,
204+ timestamp : Date . now ( ) ,
205+ requestId : requestUuid ,
206+ response : 'Dummy response'
207+ } ) ;
208+ }
209+ }
0 commit comments