Skip to content

Conversation

@ahusseinali
Copy link
Contributor

Problem

AmazonQ

  • IAM users didn't have access to Q Chat (Free Tier)
  • Sagemaker IAM users weren't automatically logged in using their Sagemaker studio credentials.
  • For Sagemaker users, login screen was disabled & users didn't have access to chat or code completion.
  • Sagemaker Pro Tier users code completion was broken & didn't generate any recommendations even after successful login.
  • Q Icon hides from Activity Bar when Toolkit extension is installed

Solution

  • Add new Q Developer Client to enable Free tier chat.
  • Terminate all the conditions that used to force chat to get disabled for IAM users
  • Terminate the conditions that used to hide login screen for Sagemaker users
  • Login Sagemaker IAM users automatically using their environment credentials (Free tier)
  • Allow Sagemaker SSO pro tier users to login using the login screen.

License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ahusseinali ahusseinali requested review from a team as code owners October 24, 2024 18:37
@github-actions
Copy link

This pull request modifies code in src/ but no tests were added/updated. Confirm whether tests should be added or ensure the PR description explains why tests are not required.

@ahusseinali ahusseinali changed the title Enable Free Tier users to access Q Chat with auto-login for Sagemaker Free Tier IAM users & login screen for Sagemaker Pro tier users feat(AmazonQ): Enable Free Tier users to access Q Chat with auto-login for Sagemaker Free Tier IAM users & login screen for Sagemaker Pro tier users Oct 24, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a large change here and it is not clear what triggered it. Are you able to extract this related change to an isolated commit so we can better understand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what triggerred it either, but I believe it's the dependencies of the new Q developer client I added in src.gen

Copy link
Contributor

Choose a reason for hiding this comment

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

That new generated client won't result in new package-lock.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point I'm clueless as to why the package.json file was changed. But I see many of the dependencies added there are also part of the newly added client package-lock.json. this is why I suspected they're related.

I inspected the dependencies added / changed further and they're only relevant to the new client code

@ahusseinali ahusseinali changed the title feat(AmazonQ): Enable Free Tier users to access Q Chat with auto-login for Sagemaker Free Tier IAM users & login screen for Sagemaker Pro tier users feat(amazonq): Enable Free Tier users to access Q Chat with auto-login for Sagemaker Free Tier IAM users & login screen for Sagemaker Pro tier users Oct 24, 2024
@@ -0,0 +1,91 @@
{
"name": "@amzn/amazon-q-developer-streaming-client",
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this package? Why can we not use src.gen/@amzn/codewhisperer-streaming?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed offline, this client supports Sigv4 credentials instead of bearer token. this is mandatory to support both IAM and SSO users.

The instructions to generate these clients will be updated in the same quip doc referenced in this .md file
I updated the wording to reflect the new changes


export async function initialize(loginManager: LoginManager): Promise<void> {
if (isAmazonQ() && isSageMaker()) {
const result = (await vscode.commands.executeCommand('sagemaker.parseCookies')) as SagemakerCookie
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this command come from? Is it already registered in VSC by sagemaker? If so add a comment to mention this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, this command is registered in Sagemaker code editor. I'll add a comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets make a new sagemaker folder in src/shared/sagemaker for all custom sagemaker code so that it is contained within a single place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a big refactor that I'd rather defer to a later followup to reduce risk

Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a long-term approach. The Toolkit/Q extensions already have an api to accept connections. If needed, they can be enhanced to accept tokens/credentials, so the caller (SM in this case) can inject credentials into the extension.


if (isSageMaker()) {
return isIamConnection(conn)
return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes))
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 use amazonQScopes? Does sagemaker SSO auth allow for the complete Q scope set?

Suggested change
return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes))
return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, amazonQScopes))

It is code smell that we have these scope subsets, so it is easy to confuse which one needs to be used/checked. We have plans to fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it doesn't, but tackling the scopes is a separate issue that I'll address later on. For now, if user login with their SSO credentials, they will go through the normal login flow which appends the full set of credentials for them. I can omit the scope check from here though as it doesn't make a difference for Sagemaker users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, I'll simplify the condition and put in a separate function for readability. it ignores any scope checking as we're handling deactivating features not supported by sagemaker in a separate change

Comment on lines 445 to 447
if (!isSsoConnection(conn)) {
throw new ToolkitError(`Connection "${conn.id}" is not a valid type: ${conn.type}`)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of deleting this you can add the check

if (!isSsoConnection(conn) && !isSageMaker()) { ... }

Copy link
Contributor Author

@ahusseinali ahusseinali Oct 25, 2024

Choose a reason for hiding this comment

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

but this change is not just for Sagemaker, the new client enables chat for both Sso and Iam connections, so this restriction no longer applies with this change

Copy link
Contributor

@hayemaxi hayemaxi Oct 28, 2024

Choose a reason for hiding this comment

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

but this change is not just for Sagemaker

But this isn't a supported feature yet in all of the code yet right? That is a big product change to the Q extension. AFAIK there is no way to get IAM credentials outside of sagemaker. Until it's supported throughout we should still have these sanity checks. Also, for a change that big I would expect unit or integ test updates/additions if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, will adjust it now

@hayemaxi hayemaxi changed the title feat(amazonq): Enable Free Tier users to access Q Chat with auto-login for Sagemaker Free Tier IAM users & login screen for Sagemaker Pro tier users feat(sagemaker): free tier Q Chat with auto-login for iam users and login option for pro tier users Oct 24, 2024
Copy link
Contributor

@hayemaxi hayemaxi left a comment

Choose a reason for hiding this comment

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

lgtm pending team approval

page: number = 0,
isSM: boolean = isSageMaker(),
retry: boolean = false
generate: boolean = isIamConnection(AuthUtil.instance.conn)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should no longer be a single function for both IAM and bearer token code path. The number of if-else is too much to comprehend. Not a blocker for this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do lots of regression testing post merge

Copy link
Contributor

Choose a reason for hiding this comment

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

Test /dev and /transform

message: generateAssistantResponseResponse,
}
} else {
const { $metadata, sendMessageResponse } = await session.chatIam(request as SendMessageRequest)
Copy link

Choose a reason for hiding this comment

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

source="IDE"
we need to set the request for the right routing in Q Dev

message: sendMessageResponse,
}
}
this.telemetryHelper.recordEnterFocusConversation(triggerEvent.tabID)
Copy link

@bhadrip bhadrip Oct 28, 2024

Choose a reason for hiding this comment

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

what kind of telemetry or error mechanism we can use to understand customers facing issues with the chat window ?

// The command `sagemaker.parseCookies` is registered in VS Code Sagemaker environment.
const result = (await vscode.commands.executeCommand('sagemaker.parseCookies')) as SagemakerCookie
if (result.authMode !== 'Sso') {
initializeCredentialsProviderManager()
Copy link

Choose a reason for hiding this comment

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

how does this refactor affect toolkit ? In sagemaker studio sso mode, toolkit will still work in IAM mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The higher level condition is scoped to amazonq, so it shouldn't impact aws toolkit

Copy link

@bhadrip bhadrip left a comment

Choose a reason for hiding this comment

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

how do we handle graceful failure of features that are not supported in free tier IAM mode

Copy link

@bhadrip bhadrip left a comment

Choose a reason for hiding this comment

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

are there no unit tests for the changes ?

@justinmk3
Copy link
Contributor

please add a src.gen/@amzn/.gitignore file that will avoid mistakes like 972e2ad in the future.

@ahusseinali
Copy link
Contributor Author

are there no unit tests for the changes ?

All the files I touched didn't have unit tests related to the changes. I plan to improve the coverage of this package as the code paths (especially for auth and API calls) are very critical

@ahusseinali
Copy link
Contributor Author

please add a src.gen/@amzn/.gitignore file that will avoid mistakes like 972e2ad in the future.

Added rule

@hayemaxi
Copy link
Contributor

CI is failing:

Error: src/inlineChat/provider/inlineChatProvider.ts(123,38): error TS2339: Property 'chat' does not exist on type 'ChatSession'.
Error: src/inlineChat/provider/inlineChatProvider.ts(125,102): error TS18048: 'response' is possibly 'undefined'.
Error: src/inlineChat/provider/inlineChatProvider.ts(126,21): error TS18048: 'response' is possibly 'undefined'.

another PR merged to master is using old function chat which is replaced in this PR by chatSso and chatIam. The logic will need to be updated to determine which one to call.

Copy link

@gogakoreli gogakoreli left a comment

Choose a reason for hiding this comment

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

Verified in Sagemaker

@hayemaxi hayemaxi merged commit ffae386 into aws:master Oct 29, 2024
25 checks passed
hayemaxi added a commit that referenced this pull request Oct 29, 2024
…rs and login option for pro tier users" (#5884)

Reverts #5858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants