Skip to content

Commit 9dbe490

Browse files
committed
Add limited IAM support for inline chat
1 parent 424a1af commit 9dbe490

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

packages/amazonq/src/inlineChat/provider/inlineChatProvider.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff 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

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

packages/core/src/codewhispererChat/clients/chat/v0/chat.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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(

packages/core/src/shared/clients/qDeveloperChatClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import { QDeveloperStreaming } from '@amzn/amazon-q-developer-streaming-client'
66
import { getCodewhispererConfig } from '../../codewhisperer/client/codewhisperer'
77
import { getUserAgent } from '../telemetry/util'
88
import { ConfiguredRetryStrategy } from '@smithy/util-retry'
9+
import { AuthUtil } from '../../codewhisperer'
910

1011
// Create a client for featureDev streaming based off of aws sdk v3
1112
export 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,

0 commit comments

Comments
 (0)