Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/amazonq/src/inlineChat/provider/inlineChatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ChatTriggerType,
EditorContextExtractor,
PromptMessage,
TriggerEvent,
TriggerEventsStorage,
TriggerPayload,
triggerPayloadToChatRequest,
Expand All @@ -30,6 +31,7 @@ import { extractAuthFollowUp } from 'aws-core-vscode/amazonq'
import { InlineChatParams, InlineChatResult } from '@aws/language-server-runtimes-types'
import { decryptResponse, encryptRequest } from '../../lsp/encryption'
import { getCursorState } from '../../lsp/utils'
import { CwsprChatTriggerInteraction, telemetry } from 'aws-core-vscode/telemetry'

export class InlineChatProvider {
private readonly editorContextExtractor: EditorContextExtractor
Expand Down Expand Up @@ -68,7 +70,34 @@ export class InlineChatProvider {
}
}

private getTriggerInteractionFromTriggerEvent(triggerEvent: TriggerEvent | undefined): CwsprChatTriggerInteraction {
switch (triggerEvent?.type) {
case 'editor_context_command':
return triggerEvent.command?.triggerType === 'keybinding' ? 'hotkeys' : 'contextMenu'
case 'follow_up':
case 'chat_message':
default:
return 'click'
}
}

public async processPromptMessageLSP(message: PromptMessage): Promise<InlineChatResult> {
const triggerInteraction = this.getTriggerInteractionFromTriggerEvent(
this.triggerEventsStorage.getLastTriggerEventByTabID(message.tabID)
)
if (!AuthUtil.instance.isSsoSession()) {
telemetry.amazonq_messageResponseError.emit({
result: 'Failed',
cwsprChatConversationType: 'Chat',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this to inlineChat instead of generic Chat ?

Copy link
Author

@yuxianrz yuxianrz Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I didn't change that is in aws-toolkit-common, cwprChatConversationType is defined as such:

{
"name": "cwsprChatConversationType",
"type": "string",
"allowedValues": [
"Chat",
"Assign",
"Transform",
"AgenticChat",
"AgenticChatWithToolUse"
],
"description": "Identifies the type of conversation"
},

Chat might be the most suitable value here. If I can make a PR to change this type in commonDefinition, I will add inlineChat and change the code here as well.

cwsprChatRequestLength: message.message?.length ?? 0,
cwsprChatResponseCode: 401,
cwsprChatTriggerInteraction: triggerInteraction,
reason: 'AuthenticationError',
reasonDesc: 'Inline chat requires SSO authentication, but current session is not',
})
throw new ToolkitError('Inline chat is only available with SSO authentication')
}

// TODO: handle partial responses.
getLogger().info('Making inline chat request with message %O', message)
const params = this.getCurrentEditorParams(message.message ?? '')
Expand All @@ -83,6 +112,23 @@ export class InlineChatProvider {

// TODO: remove in favor of LSP implementation.
public async processPromptMessage(message: PromptMessage) {
const triggerInteraction = this.getTriggerInteractionFromTriggerEvent(
this.triggerEventsStorage.getLastTriggerEventByTabID(message.tabID)
)
if (!AuthUtil.instance.isSsoSession()) {
telemetry.amazonq_messageResponseError.emit({
result: 'Failed',
cwsprChatConversationType: 'Chat',
cwsprChatRequestLength: message.message?.length ?? 0,
cwsprChatResponseCode: 401,
cwsprChatTriggerInteraction: triggerInteraction,
reason: 'AuthenticationError',
reasonDesc: 'Inline chat requires SSO authentication, but current session is not',
credentialStartUrl: AuthUtil.instance.connection?.startUrl,
})
throw new ToolkitError('Inline chat is only available with SSO authentication')
}

return this.editorContextExtractor
.extractContextForTrigger('ChatMessage')
.then((context) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codewhispererChat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export { ChatTriggerType, PromptMessage, TriggerPayload } from './controllers/ch
export { UserIntentRecognizer } from './controllers/chat/userIntent/userIntentRecognizer'
export { EditorContextExtractor } from './editor/context/extractor'
export { ChatSessionStorage } from './storages/chatSession'
export { TriggerEventsStorage } from './storages/triggerEvents'
export { TriggerEventsStorage, TriggerEvent } from './storages/triggerEvents'
export { ReferenceLogController } from './view/messages/referenceLogController'
export { extractLanguageNameFromFile } from './editor/context/file/languages'
16 changes: 14 additions & 2 deletions packages/core/src/login/webview/vue/amazonq/backend_amazonq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { builderIdStartUrl } from '../../../../auth/sso/constants'
import { RegionProfile, vsCodeState } from '../../../../codewhisperer/models/model'
import { randomUUID } from '../../../../shared/crypto'
import globals from '../../../../shared/extensionGlobals'
import { telemetry } from '../../../../shared/telemetry/telemetry'
import { CredentialType, telemetry } from '../../../../shared/telemetry/telemetry'
import { ProfileSwitchIntent } from '../../../../codewhisperer/region/regionProfileManager'

const className = 'AmazonQLoginWebview'
Expand Down Expand Up @@ -204,6 +204,15 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
// Defining separate auth function to emit telemetry before returning from this method
await globals.globalState.update('recentIamKeys', { accessKey: accessKey })
await globals.globalState.update('recentRoleArn', { roleArn: roleArn })
let credentialsType: CredentialType | undefined
if (!sessionToken && !roleArn) {
credentialsType = 'staticProfile'
} else if (roleArn) {
credentialsType = 'assumeRoleProfile'
} else {
credentialsType = 'staticSessionProfile'
}

const runAuth = async (): Promise<AuthError | undefined> => {
try {
await AuthUtil.instance.loginIam({ accessKey, secretKey, sessionToken, roleArn })
Expand All @@ -224,7 +233,10 @@ export class AmazonQLoginWebview extends CommonAuthWebview {
const result = await runAuth()
this.storeMetricMetadata({
credentialSourceId: 'sharedCredentials',
authEnabledFeatures: 'codewhisperer',
featureId: 'codewhisperer',
credentialType: credentialsType,
isReAuth: false,
isAggregated: false,
...this.getResultForMetrics(result),
})
this.emitAuthMetric()
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/login/webview/vue/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ export default defineComponent({
}
}
} else if (this.selectedLoginOption === LoginOption.IAM_CREDENTIAL) {
// Emit telemetry when IAM Credentials option is selected and Continue is clicked
void client.emitUiClick('auth_credentialsOption')

this.stage = 'AWS_PROFILE'
this.$nextTick(() => document.getElementById('profileName')!.focus())
}
Expand Down
Loading