@@ -160,7 +160,7 @@ export class CopilotStudioClient {
160160 * @param emitStartConversationEvent Whether to emit a start conversation event. Defaults to true.
161161 * @returns An async generator yielding the Agent's Activities.
162162 */
163- public async * startConversationAsync ( emitStartConversationEvent : boolean = true ) : AsyncGenerator < Activity > {
163+ public async * startConversationStreaming ( emitStartConversationEvent : boolean = true ) : AsyncGenerator < Activity > {
164164 const uriStart : string = getCopilotStudioConnectionUrl ( this . settings )
165165 const body = { emitStartConversationEvent }
166166
@@ -169,15 +169,46 @@ export class CopilotStudioClient {
169169 yield * this . postRequestAsync ( uriStart , body , 'POST' )
170170 }
171171
172+ /**
173+ * Sends an activity to the Copilot Studio service and retrieves the response activities.
174+ * @param activity The activity to send.
175+ * @param conversationId The ID of the conversation. Defaults to the current conversation ID.
176+ * @returns An async generator yielding the Agent's Activities.
177+ */
178+ public async * sendActivityStreaming ( activity : Activity , conversationId : string = this . conversationId ) : AsyncGenerator < Activity > {
179+ const localConversationId = activity . conversation ?. id ?? conversationId
180+ const uriExecute = getCopilotStudioConnectionUrl ( this . settings , localConversationId )
181+ const qbody : ExecuteTurnRequest = new ExecuteTurnRequest ( activity )
182+
183+ logger . info ( 'Sending activity...' , activity )
184+ yield * this . postRequestAsync ( uriExecute , qbody , 'POST' )
185+ }
186+
187+ /**
188+ * Starts a new conversation with the Copilot Studio service.
189+ * @param emitStartConversationEvent Whether to emit a start conversation event. Defaults to true.
190+ * @returns A promise yielding an array of activities.
191+ * @deprecated Use startConversationStreaming instead.
192+ */
193+ public async startConversationAsync ( emitStartConversationEvent : boolean = true ) : Promise < Activity [ ] > {
194+ const result : Activity [ ] = [ ]
195+ for await ( const value of this . startConversationStreaming ( emitStartConversationEvent ) ) {
196+ result . push ( value )
197+ }
198+ return result
199+ }
200+
172201 /**
173202 * Sends a question to the Copilot Studio service and retrieves the response activities.
174203 * @param question The question to ask.
175204 * @param conversationId The ID of the conversation. Defaults to the current conversation ID.
176- * @returns An async generator yielding the Agent's Activities.
205+ * @returns A promise yielding an array of activities.
206+ * @deprecated Use sendActivityStreaming instead.
177207 */
178- public async * askQuestionAsync ( question : string , conversationId : string = this . conversationId ) : AsyncGenerator < Activity > {
208+ public async askQuestionAsync ( question : string , conversationId ?: string ) : Promise < Activity [ ] > {
209+ const localConversationId = conversationId ?. trim ( ) ? conversationId : this . conversationId
179210 const conversationAccount : ConversationAccount = {
180- id : conversationId
211+ id : localConversationId
181212 }
182213 const activityObj = {
183214 type : 'message' ,
@@ -186,21 +217,25 @@ export class CopilotStudioClient {
186217 }
187218 const activity = Activity . fromObject ( activityObj )
188219
189- yield * this . sendActivity ( activity )
220+ const result : Activity [ ] = [ ]
221+ for await ( const value of this . sendActivityStreaming ( activity , conversationId ) ) {
222+ result . push ( value )
223+ }
224+ return result
190225 }
191226
192227 /**
193228 * Sends an activity to the Copilot Studio service and retrieves the response activities.
194229 * @param activity The activity to send.
195230 * @param conversationId The ID of the conversation. Defaults to the current conversation ID.
196- * @returns An async generator yielding the Agent's Activities.
231+ * @returns A promise yielding an array of activities.
232+ * @deprecated Use sendActivityStreaming instead.
197233 */
198- public async * sendActivity ( activity : Activity , conversationId : string = this . conversationId ) : AsyncGenerator < Activity > {
199- const localConversationId = activity . conversation ?. id ?? conversationId
200- const uriExecute = getCopilotStudioConnectionUrl ( this . settings , localConversationId )
201- const qbody : ExecuteTurnRequest = new ExecuteTurnRequest ( activity )
202-
203- logger . info ( 'Sending activity...' , activity )
204- yield * this . postRequestAsync ( uriExecute , qbody , 'POST' )
234+ public async sendActivity ( activity : Activity , conversationId : string = this . conversationId ) : Promise < Activity [ ] > {
235+ const result : Activity [ ] = [ ]
236+ for await ( const value of this . sendActivityStreaming ( activity , conversationId ) ) {
237+ result . push ( value )
238+ }
239+ return result
205240 }
206241}
0 commit comments