Skip to content

Commit 25fa38f

Browse files
ahusseinalihayemaxi
authored andcommitted
Address review comments
1 parent 1bb97f3 commit 25fa38f

File tree

9 files changed

+54
-51
lines changed

9 files changed

+54
-51
lines changed

docs/build.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
# Build
22

3-
The AmazonQ features rely on the `codewhisperer-streaming` service, who's client
4-
is generated from the service's smithy models and placed in
5-
`src.gen/@amzn/codewhisperer-streaming` (For more
6-
information about this client and how it is generated, please see this
3+
The AmazonQ features rely on the `codewhisperer-streaming` service, to support both Sigv4 and Bearer token modes of this service,
4+
two clients are generated from the service's smithy models and placed in
5+
`src.gen/@amzn/amazon-q-developer-streaming-client` and `src.gen/@amzn/codewhisperer-streaming` respectively (For more
6+
information about these clients and how they are generated, please see this
77
[quip document](https://quip-amazon.com/2dAWAvTIYXXr/Build-instructions-for-AWS-CodeWhisperer-Streaming-Typescript-client)).
88

9+
## @amzn/amazon-q-developer-streaming client
10+
11+
This client is a standalone npm project in typescript, and it is added to
12+
the project as a workspace in the project's root `package.json` with the line `"workspaces": [ ..., "src.gen/@amzn/amazon-q-developer-streaming" ]`.
13+
The client may be manually built using `npm run build -w @amzn/amazon-q-developer-streaming"`.
14+
The `generateClients` run script ensures that this dependency is
15+
built before the toolkit project itself. Workspaces are automatically ready to
16+
be imported in the root toolkit project by their declared package.json name,
17+
(`@amzn/amazon-q-developer-streaming` in this case).
18+
19+
## @amzn/codewhisperer-streaming client
20+
921
This client is a standalone npm project in typescript, and it is added to
1022
the project as a workspace in the project's root `package.json` with the line `"workspaces": [ ..., "src.gen/@amzn/codewhisperer-streaming" ]`.
1123
The client may be manually built using `npm run build -w @amzn/codewhisperer-streaming"`.

packages/core/src/auth/activation.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,18 @@ import { Auth } from './auth'
88
import { LoginManager } from './deprecated/loginManager'
99
import { fromString } from './providers/credentials'
1010
import { getLogger } from '../shared/logger'
11-
import { ExtensionUse } from './utils'
11+
import { ExtensionUse, initializeCredentialsProviderManager } from './utils'
1212
import { isAmazonQ, isCloud9, isSageMaker } from '../shared/extensionUtilities'
1313
import { isInDevEnv } from '../shared/vscode/env'
1414
import { isWeb } from '../shared/extensionGlobals'
15-
import { CredentialsProviderManager } from './providers/credentialsProviderManager'
16-
import { SharedCredentialsProviderFactory } from './providers/sharedCredentialsProviderFactory'
17-
import { Ec2CredentialsProvider } from './providers/ec2CredentialsProvider'
18-
import { EcsCredentialsProvider } from './providers/ecsCredentialsProvider'
19-
import { EnvVarsCredentialsProvider } from './providers/envVarsCredentialsProvider'
2015

2116
interface SagemakerCookie {
22-
authMode?: string
17+
authMode?: 'Sso' | 'Iam'
2318
}
2419

2520
export async function initialize(loginManager: LoginManager): Promise<void> {
2621
if (isAmazonQ() && isSageMaker()) {
22+
// The command `sagemaker.parseCookies` is registered in VS Code Sagemaker environment.
2723
const result = (await vscode.commands.executeCommand('sagemaker.parseCookies')) as SagemakerCookie
2824
if (result.authMode !== 'Sso') {
2925
initializeCredentialsProviderManager()
@@ -41,12 +37,6 @@ export async function initialize(loginManager: LoginManager): Promise<void> {
4137
await showManageConnectionsOnStartup()
4238
}
4339

44-
function initializeCredentialsProviderManager() {
45-
const manager = CredentialsProviderManager.getInstance()
46-
manager.addProviderFactory(new SharedCredentialsProviderFactory())
47-
manager.addProviders(new Ec2CredentialsProvider(), new EcsCredentialsProvider(), new EnvVarsCredentialsProvider())
48-
}
49-
5040
/**
5141
* Show the Manage Connections page when the extension starts up, if it should be shown.
5242
*/

packages/core/src/auth/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ import { ExtStartUpSources } from '../shared/telemetry'
5252
import { CommonAuthWebview } from '../login/webview/vue/backend'
5353
import { AuthSource } from '../login/webview/util'
5454
import { setContext } from '../shared/vscode/setContext'
55+
import { CredentialsProviderManager } from './providers/credentialsProviderManager'
56+
import { SharedCredentialsProviderFactory } from './providers/sharedCredentialsProviderFactory'
57+
import { Ec2CredentialsProvider } from './providers/ec2CredentialsProvider'
58+
import { EcsCredentialsProvider } from './providers/ecsCredentialsProvider'
59+
import { EnvVarsCredentialsProvider } from './providers/envVarsCredentialsProvider'
5560

5661
// iam-only excludes Builder ID and IAM Identity Center from the list of valid connections
5762
// TODO: Understand if "iam" should include these from the list at all
@@ -731,3 +736,9 @@ export function getAuthFormIdsFromConnection(conn?: Connection): AuthFormId[] {
731736

732737
return authIds
733738
}
739+
740+
export function initializeCredentialsProviderManager() {
741+
const manager = CredentialsProviderManager.getInstance()
742+
manager.addProviderFactory(new SharedCredentialsProviderFactory())
743+
manager.addProviders(new Ec2CredentialsProvider(), new EcsCredentialsProvider(), new EnvVarsCredentialsProvider())
744+
}

packages/core/src/codewhisperer/service/recommendationHandler.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { application } from '../util/codeWhispererApplication'
4343
import { openUrl } from '../../shared/utilities/vsCodeUtils'
4444
import { indent } from '../../shared/utilities/textUtilities'
4545
import path from 'path'
46+
import { isIamConnection } from '../../auth/connection'
4647

4748
/**
4849
* This class is for getRecommendation/listRecommendation API calls and its states
@@ -157,7 +158,8 @@ export class RecommendationHandler {
157158
config: ConfigurationEntry,
158159
autoTriggerType?: CodewhispererAutomatedTriggerType,
159160
pagination: boolean = true,
160-
page: number = 0
161+
page: number = 0,
162+
generate: boolean = isIamConnection(AuthUtil.instance.conn)
161163
): Promise<GetRecommendationsResponse> {
162164
let invocationResult: 'Succeeded' | 'Failed' = 'Failed'
163165
let errorMessage: string | undefined = undefined
@@ -184,7 +186,7 @@ export class RecommendationHandler {
184186
).language
185187
session.taskType = await this.getTaskTypeFromEditorFileName(editor.document.fileName)
186188

187-
if (pagination) {
189+
if (pagination && !generate) {
188190
if (page === 0) {
189191
session.requestContext = await EditorContext.buildListRecommendationRequest(
190192
editor as vscode.TextEditor,
@@ -238,9 +240,10 @@ export class RecommendationHandler {
238240
startTime = performance.now()
239241
this.lastInvocationTime = startTime
240242
const mappedReq = runtimeLanguageContext.mapToRuntimeLanguage(request)
241-
const codewhispererPromise = pagination
242-
? client.listRecommendations(mappedReq)
243-
: client.generateRecommendations(mappedReq)
243+
const codewhispererPromise =
244+
pagination && !generate
245+
? client.listRecommendations(mappedReq)
246+
: client.generateRecommendations(mappedReq)
244247
const resp = await this.getServerResponse(triggerType, config.isManualTriggerEnabled, codewhispererPromise)
245248
TelemetryHelper.instance.setSdkApiCallEndTime()
246249
latency = startTime !== 0 ? performance.now() - startTime : 0
@@ -332,7 +335,8 @@ export class RecommendationHandler {
332335
config,
333336
autoTriggerType,
334337
pagination,
335-
page
338+
page,
339+
true
336340
)
337341
}
338342
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as localizedText from '../../shared/localizedText'
88
import { Auth } from '../../auth/auth'
99
import { ToolkitError, isNetworkError, tryRun } from '../../shared/errors'
1010
import { getSecondaryAuth, setScopes } from '../../auth/secondaryAuth'
11-
import { isAmazonQ, isCloud9, isSageMaker } from '../../shared/extensionUtilities'
11+
import { isCloud9, isSageMaker } from '../../shared/extensionUtilities'
1212
import { AmazonQPromptSettings } from '../../shared/settings'
1313
import {
1414
scopesCodeWhispererCore,
@@ -50,6 +50,9 @@ export const codeWhispererCoreScopes = [...scopesCodeWhispererCore]
5050
export const codeWhispererChatScopes = [...codeWhispererCoreScopes, ...scopesCodeWhispererChat]
5151
export const amazonQScopes = [...codeWhispererChatScopes, ...scopesGumby, ...scopesFeatureDev]
5252

53+
function isValidSageMakerConnection(conn?: Connection) {
54+
return isIamConnection(conn) || isSsoConnection(conn)
55+
}
5356
/**
5457
* "Core" are the CW scopes that existed before the addition of new scopes
5558
* for Amazon Q.
@@ -59,25 +62,19 @@ export const isValidCodeWhispererCoreConnection = (conn?: Connection): conn is C
5962
return isIamConnection(conn)
6063
}
6164

62-
if (isSageMaker()) {
63-
return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes))
64-
}
65-
6665
return (
66+
isValidSageMakerConnection(conn) ||
6767
(isCloud9('codecatalyst') && isIamConnection(conn)) ||
6868
(isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes))
6969
)
7070
}
7171
/** Superset that includes all of CodeWhisperer + Amazon Q */
7272
export const isValidAmazonQConnection = (conn?: Connection): conn is Connection => {
73-
if (isSageMaker() && isAmazonQ()) {
74-
return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, amazonQScopes))
75-
}
76-
7773
return (
78-
(isSsoConnection(conn) || isBuilderIdConnection(conn)) &&
79-
isValidCodeWhispererCoreConnection(conn) &&
80-
hasScopes(conn, amazonQScopes)
74+
isValidSageMakerConnection(conn) ||
75+
((isSsoConnection(conn) || isBuilderIdConnection(conn)) &&
76+
isValidCodeWhispererCoreConnection(conn) &&
77+
hasScopes(conn, amazonQScopes))
8178
)
8279
}
8380

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { EditorContextCommand } from '../../commands/registerCommands'
3535
import { PromptsGenerator } from './prompts/promptsGenerator'
3636
import { TriggerEventsStorage } from '../../storages/triggerEvents'
3737
import { SendMessageRequest } from '@amzn/amazon-q-developer-streaming-client'
38-
import { CodeWhispererStreamingServiceException, __MetadataBearer } from '@amzn/codewhisperer-streaming'
38+
import { CodeWhispererStreamingServiceException } from '@amzn/codewhisperer-streaming'
3939
import { UserIntentRecognizer } from './userIntent/userIntentRecognizer'
4040
import { CWCTelemetryHelper, recordTelemetryChatRunCommand } from './telemetryHelper'
4141
import { CodeWhispererTracker } from '../../../codewhisperer/tracker/codewhispererTracker'

packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
ChatResponseStream as cwChatResponseStream,
1919
CodeWhispererStreamingServiceException,
2020
SupplementaryWebLink,
21-
__MetadataBearer,
2221
} from '@amzn/codewhisperer-streaming'
2322
import { ChatMessage, ErrorMessage, FollowUp, Suggestion } from '../../../view/connector/connector'
2423
import { ChatSession } from '../../../clients/chat/v0/chat'
@@ -39,7 +38,8 @@ import { extractAuthFollowUp } from '../../../../amazonq/util/authUtils'
3938

4039
export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
4140

42-
export type MessengerResponseType = __MetadataBearer & {
41+
export type MessengerResponseType = {
42+
$metadata: { requestId?: string; httpStatusCode?: number }
4343
message?: AsyncIterable<cwChatResponseStream | qdevChatResponseStream>
4444
}
4545

packages/core/src/extensionNode.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import * as nls from 'vscode-nls'
99
import * as codecatalyst from './codecatalyst/activation'
1010
import { activate as activateAwsExplorer } from './awsexplorer/activation'
1111
import { activate as activateCloudWatchLogs } from './awsService/cloudWatchLogs/activation'
12-
import { CredentialsProviderManager } from './auth/providers/credentialsProviderManager'
13-
import { SharedCredentialsProviderFactory } from './auth/providers/sharedCredentialsProviderFactory'
1412
import { activate as activateSchemas } from './eventSchemas/activation'
1513
import { activate as activateLambda } from './lambda/activation'
1614
import { activate as activateCloudFormationTemplateRegistry } from './shared/cloudformation/activation'
@@ -39,9 +37,6 @@ import { activate as activateDev } from './dev/activation'
3937
import { activate as activateApplicationComposer } from './applicationcomposer/activation'
4038
import { activate as activateRedshift } from './awsService/redshift/activation'
4139
import { activate as activateIamPolicyChecks } from './awsService/accessanalyzer/activation'
42-
import { Ec2CredentialsProvider } from './auth/providers/ec2CredentialsProvider'
43-
import { EnvVarsCredentialsProvider } from './auth/providers/envVarsCredentialsProvider'
44-
import { EcsCredentialsProvider } from './auth/providers/ecsCredentialsProvider'
4540
import { SchemaService } from './shared/schemas'
4641
import { AwsResourceManager } from './dynamicResources/awsResourceManager'
4742
import globals from './shared/extensionGlobals'
@@ -55,7 +50,7 @@ import { learnMoreAmazonQCommand, qExtensionPageCommand, dismissQTree } from './
5550
import { AuthUtil, codeWhispererCoreScopes, isPreviousQUser } from './codewhisperer/util/authUtil'
5651
import { installAmazonQExtension } from './codewhisperer/commands/basicCommands'
5752
import { isExtensionInstalled, VSCODE_EXTENSION_ID } from './shared/utilities'
58-
import { ExtensionUse } from './auth/utils'
53+
import { ExtensionUse, initializeCredentialsProviderManager } from './auth/utils'
5954
import { ExtStartUpSources } from './shared/telemetry'
6055
import { activate as activateThreatComposerEditor } from './threatComposer/activation'
6156
import { isSsoConnection, hasScopes } from './auth/connection'
@@ -310,12 +305,6 @@ async function handleAmazonQInstall() {
310305
})
311306
}
312307

313-
function initializeCredentialsProviderManager() {
314-
const manager = CredentialsProviderManager.getInstance()
315-
manager.addProviderFactory(new SharedCredentialsProviderFactory())
316-
manager.addProviders(new Ec2CredentialsProvider(), new EcsCredentialsProvider(), new EnvVarsCredentialsProvider())
317-
}
318-
319308
function recordToolkitInitialization(activationStartedOn: number, settingsValid: boolean, logger?: Logger) {
320309
try {
321310
const activationFinishedOn = Date.now()

packages/toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@
709709
{
710710
"id": "aws.amazonq.codewhisperer",
711711
"name": "%AWS.amazonq.codewhisperer.title%",
712-
"when": "!isCloud9 && !isSageMaker && !aws.toolkit.amazonq.dismissed && !aws.explorer.showAuthView"
712+
"when": "!isCloud9 && !aws.isSageMaker && !aws.toolkit.amazonq.dismissed && !aws.explorer.showAuthView"
713713
},
714714
{
715715
"id": "aws.explorer",

0 commit comments

Comments
 (0)