File tree Expand file tree Collapse file tree 4 files changed +17
-8
lines changed
amazonq/src/inlineChat/provider
codewhispererChat/clients/chat/v0 Expand file tree Collapse file tree 4 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ export class InlineChatProvider {
143143 private async generateResponse (
144144 triggerPayload : TriggerPayload & { projectContextQueryLatencyMs ?: number } ,
145145 triggerID : string
146- ) {
146+ ) : Promise < GenerateAssistantResponseCommandOutput | undefined > {
147147 const triggerEvent = this . triggerEventsStorage . getTriggerEvent ( triggerID )
148148 if ( triggerEvent === undefined ) {
149149 return
@@ -182,7 +182,18 @@ export class InlineChatProvider {
182182 let response : GenerateAssistantResponseCommandOutput | undefined = undefined
183183 session . createNewTokenSource ( )
184184 try {
185- response = await session . chatSso ( request )
185+ if ( AuthUtil . instance . isSsoSession ( ) ) {
186+ response = await session . chatSso ( request )
187+ } else {
188+ // Call sendMessage because Q Developer Streaming Client does not have generateAssistantResponse
189+ const { sendMessageResponse, ...rest } = await session . chatIam ( request )
190+ // Convert sendMessageCommandOutput to GenerateAssistantResponseCommandOutput
191+ response = {
192+ generateAssistantResponseResponse : sendMessageResponse ,
193+ conversationId : session . sessionIdentifier ,
194+ ...rest
195+ }
196+ }
186197 getLogger ( ) . info (
187198 `response to tab: ${ tabID } conversationID: ${ session . sessionIdentifier } requestID: ${ response . $metadata . requestId } metadata: %O` ,
188199 response . $metadata
Original file line number Diff line number Diff line change @@ -197,8 +197,8 @@ export class AuthUtil implements IAuthProvider {
197197 }
198198
199199 async getToken ( ) {
200- if ( this . isSsoSession ( ) ) {
201- const token = ( await this . session ! . getCredential ( ) ) . credential
200+ if ( this . session ) {
201+ const token = ( await this . session . getCredential ( ) ) . credential
202202 if ( typeof token !== 'string' ) {
203203 throw new ToolkitError ( 'Cannot get token with IAM session' )
204204 }
Original file line number Diff line number Diff line change @@ -41,7 +41,6 @@ export class ChatSession {
4141 }
4242 async chatIam ( chatRequest : SendMessageRequest ) : Promise < SendMessageCommandOutput > {
4343 const client = await createQDeveloperStreamingClient ( )
44-
4544 const response = await client . sendMessage ( chatRequest )
4645 if ( ! response . sendMessageResponse ) {
4746 throw new ToolkitError (
Original file line number Diff line number Diff line change @@ -6,13 +6,12 @@ import { QDeveloperStreaming } from '@amzn/amazon-q-developer-streaming-client'
66import { getCodewhispererConfig } from '../../codewhisperer/client/codewhisperer'
77import { getUserAgent } from '../telemetry/util'
88import { ConfiguredRetryStrategy } from '@smithy/util-retry'
9+ import { AuthUtil } from '../../codewhisperer'
910
1011// Create a client for featureDev streaming based off of aws sdk v3
1112export async function createQDeveloperStreamingClient ( ) : Promise < QDeveloperStreaming > {
12- throw new Error ( 'Do not call this function until IAM is supported by LSP identity server' )
13-
1413 const cwsprConfig = getCodewhispererConfig ( )
15- const credentials = undefined
14+ const credentials = await AuthUtil . instance . getIamCredential ( )
1615 const streamingClient = new QDeveloperStreaming ( {
1716 region : cwsprConfig . region ,
1817 endpoint : cwsprConfig . endpoint ,
You can’t perform that action at this time.
0 commit comments