Skip to content

Commit 9f805be

Browse files
authored
feat(sagemaker): disable Q signout on SMUS aws#6850
## Problem In Sagemaker Unified Studio(SMUS), user shouldnt be allowed to sign out of Q Chat extension as per business requirement. In addition to that, Q Chat Introduction message should display Q Free Tier is only supported with the upcoming SMUS release ## Solution 1. `isSageMaker` is used to identify if it is SageMaker AI (CodeEditor) which comes from [here](https://github.com/aws/sagemaker-code-editor/blob/main/patched-vscode/product.json#L2-L3) as shared by Sagemaker team. Since SageMaker Unified Studio also uses the same repository/branch for CodeEditor we required a new environment variable `SERVICE_NAME` to differentiate SMUS case. 2. Read `SERVICE_NAME` and set a new vscode env context variable `aws.isSagemakerStudio` to control visibility of Sign out label 3. Sign out option to users is controlled at two places: - VS Code command palette - Quick pick UI action - Both the sign out options are disabled based on the SMUS flag 4. Similarly Q Chat Introduction message in WebView is modified for SMUS case alone
1 parent e26ab78 commit 9f805be

File tree

14 files changed

+127
-21
lines changed

14 files changed

+127
-21
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "SageMaker Unified Studio: Disable Sign out"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "SageMaker Unified Studio: Update Q Chat Introduction message"
4+
}

packages/amazonq/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@
359359
},
360360
{
361361
"command": "aws.amazonq.signout",
362-
"when": "(view == aws.amazonq.AmazonQChatView) && aws.codewhisperer.connected",
362+
"when": "(view == aws.amazonq.AmazonQChatView) && aws.codewhisperer.connected && !aws.isSageMakerUnifiedStudio",
363363
"group": "2_amazonQ@4"
364364
},
365365
{
@@ -635,7 +635,7 @@
635635
"title": "%AWS.command.codewhisperer.signout%",
636636
"category": "%AWS.amazonq.title%",
637637
"icon": "$(debug-disconnect)",
638-
"enablement": "aws.codewhisperer.connected"
638+
"enablement": "aws.codewhisperer.connected && !aws.isSageMakerUnifiedStudio"
639639
},
640640
{
641641
"command": "aws.amazonq.learnMore",

packages/amazonq/src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
setupUninstallHandler,
3333
maybeShowMinVscodeWarning,
3434
Experiments,
35+
isSageMaker,
3536
} from 'aws-core-vscode/shared'
3637
import { ExtStartUpSources } from 'aws-core-vscode/telemetry'
3738
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
@@ -146,6 +147,9 @@ export async function activateAmazonQCommon(context: vscode.ExtensionContext, is
146147
// Hide the Amazon Q tree in toolkit explorer
147148
await setContext('aws.toolkit.amazonq.dismissed', true)
148149

150+
// set context var to check if its SageMaker Unified Studio or not
151+
await setContext('aws.isSageMakerUnifiedStudio', isSageMaker('SMUS'))
152+
149153
// reload webviews
150154
await vscode.commands.executeCommand('workbench.action.webview.reloadWebviewAction')
151155

packages/core/src/amazonq/webview/generators/webViewContent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class WebViewContentGenerator {
8383
const disclaimerAcknowledged = globals.globalState.tryGet('aws.amazonq.disclaimerAcknowledged', Boolean, false)
8484

8585
const welcomeLoadCount = globals.globalState.tryGet('aws.amazonq.welcomeChatShowCount', Number, 0)
86+
const isSMUS = isSageMaker('SMUS')
8687

8788
return `
8889
<script type="text/javascript" src="${javascriptEntrypoint.toString()}" defer onload="init()"></script>
@@ -91,7 +92,7 @@ export class WebViewContentGenerator {
9192
const init = () => {
9293
createMynahUI(acquireVsCodeApi(), ${
9394
(await AuthUtil.instance.getChatAuthState()).amazonQ === 'connected'
94-
},${featureConfigsString},${welcomeLoadCount},${disclaimerAcknowledged},${disabledCommandsString});
95+
},${featureConfigsString},${welcomeLoadCount},${disclaimerAcknowledged},${disabledCommandsString},${isSMUS});
9596
}
9697
</script>
9798
`

packages/core/src/amazonq/webview/ui/main.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export const createMynahUI = (
4747
featureConfigsSerialized: [string, FeatureContext][],
4848
welcomeCount: number,
4949
disclaimerAcknowledged: boolean,
50-
disabledCommands?: string[]
50+
disabledCommands?: string[],
51+
isSMUS?: boolean
5152
) => {
5253
let disclaimerCardActive = !disclaimerAcknowledged
5354
// eslint-disable-next-line prefer-const
@@ -624,7 +625,7 @@ export const createMynahUI = (
624625
tabsStorage.updateTabTypeFromUnknown(tabID, 'cwc')
625626
mynahUI?.updateTabDefaults({
626627
store: {
627-
...tabDataGenerator.getTabData('cwc', true),
628+
...tabDataGenerator.getTabData('cwc', true, undefined, isSMUS),
628629
tabHeaderDetails: void 0,
629630
compactMode: false,
630631
tabBackground: false,
@@ -931,15 +932,15 @@ export const createMynahUI = (
931932
store: {
932933
...(showWelcomePage()
933934
? welcomeScreenTabData(tabDataGenerator).store
934-
: tabDataGenerator.getTabData('cwc', true)),
935+
: tabDataGenerator.getTabData('cwc', true, undefined, isSMUS)),
935936
...(disclaimerCardActive ? { promptInputStickyCard: disclaimerCard } : {}),
936937
},
937938
},
938939
},
939940
defaults: {
940941
store: showWelcomePage()
941942
? welcomeScreenTabData(tabDataGenerator).store
942-
: tabDataGenerator.getTabData('cwc', true),
943+
: tabDataGenerator.getTabData('cwc', true, undefined, isSMUS),
943944
},
944945
config: {
945946
maxTabs: 10,

packages/core/src/amazonq/webview/ui/tabs/constants.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import { TabType } from '../storages/tabsStorage'
66
import { QuickActionCommandGroup } from '@aws/mynah-ui'
77
import { userGuideURL } from '../texts/constants'
88

9+
const qChatIntroMessage = `Hi, I'm Amazon Q. I can answer your software development questions.
10+
Ask me to explain, debug, or optimize your code.
11+
You can enter \`/\` to see a list of quick actions. Use \`@\` to add saved prompts, files, folders, or your entire workspace as context.`
12+
13+
export const qChatIntroMessageForSMUS = `Hi, I'm Amazon Q. I can answer your software development questions.\n\
14+
Ask me to explain, debug, or optimize your code.\n\
15+
You can enter \`/\` to see a list of quick actions. Use \`@\` to add saved prompts, files, folders, or your entire workspace as context.
16+
You are now using Q free tier.\n\
17+
`
18+
919
export type TabTypeData = {
1020
title: string
1121
placeholder: string
@@ -26,9 +36,7 @@ export const workspaceCommand: QuickActionCommandGroup = {
2636
export const commonTabData: TabTypeData = {
2737
title: 'Chat',
2838
placeholder: 'Ask a question. Use @ to add context, / for quick actions',
29-
welcome: `Hi, I'm Amazon Q. I can answer your software development questions.
30-
Ask me to explain, debug, or optimize your code.
31-
You can enter \`/\` to see a list of quick actions. Use \`@\` to add saved prompts, files, folders, or your entire workspace as context.`,
39+
welcome: qChatIntroMessage,
3240
contextCommands: [workspaceCommand],
3341
}
3442

packages/core/src/amazonq/webview/ui/tabs/generator.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ChatItemType, MynahUIDataModel, QuickActionCommandGroup } from '@aws/my
77
import { TabType } from '../storages/tabsStorage'
88
import { FollowUpGenerator } from '../followUps/generator'
99
import { QuickActionGenerator } from '../quickActions/generator'
10-
import { TabTypeDataMap } from './constants'
10+
import { qChatIntroMessageForSMUS, TabTypeDataMap } from './constants'
1111
import { agentWalkthroughDataModel } from '../walkthrough/agent'
1212
import { FeatureContext } from '../../../../shared/featureConfig'
1313

@@ -39,7 +39,12 @@ export class TabDataGenerator {
3939
this.highlightCommand = props.commandHighlight
4040
}
4141

42-
public getTabData(tabType: TabType, needWelcomeMessages: boolean, taskName?: string): MynahUIDataModel {
42+
public getTabData(
43+
tabType: TabType,
44+
needWelcomeMessages: boolean,
45+
taskName?: string,
46+
isSMUS?: boolean
47+
): MynahUIDataModel {
4348
if (tabType === 'agentWalkthrough') {
4449
return agentWalkthroughDataModel
4550
}
@@ -59,7 +64,7 @@ export class TabDataGenerator {
5964
? [
6065
{
6166
type: ChatItemType.ANSWER,
62-
body: TabTypeDataMap[tabType].welcome,
67+
body: isSMUS ? qChatIntroMessageForSMUS : TabTypeDataMap[tabType].welcome,
6368
},
6469
{
6570
type: ChatItemType.ANSWER,

packages/core/src/codewhisperer/ui/statusBarMenu.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Commands } from '../../shared/vscode/commands2'
3030
import { createExitButton } from '../../shared/ui/buttons'
3131
import { telemetry } from '../../shared/telemetry/telemetry'
3232
import { getLogger } from '../../shared/logger/logger'
33+
import { isSageMaker } from '../../shared/extensionUtilities'
3334

3435
function getAmazonQCodeWhispererNodes() {
3536
const autoTriggerEnabled = CodeSuggestionsState.instance.isSuggestionsEnabled()
@@ -92,7 +93,9 @@ export function getQuickPickItems(): DataQuickPickItem<string>[] {
9293
// Add settings and signout
9394
createSeparator(),
9495
createSettingsNode(),
95-
...(AuthUtil.instance.isConnected() && !hasVendedIamCredentials() ? [createSignout()] : []),
96+
...(AuthUtil.instance.isConnected() && !(hasVendedIamCredentials() || isSageMaker('SMUS'))
97+
? [createSignout()]
98+
: []),
9699
]
97100

98101
return children

packages/core/src/extension.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import globals, { initialize, isWeb } from './shared/extensionGlobals'
1717
import { join } from 'path'
1818
import { Commands } from './shared/vscode/commands2'
1919
import { endpointsFileUrl, githubCreateIssueUrl, githubUrl } from './shared/constants'
20-
import { getIdeProperties, aboutExtension, getDocUrl } from './shared/extensionUtilities'
20+
import { getIdeProperties, aboutExtension, getDocUrl, isSageMaker } from './shared/extensionUtilities'
2121
import { logAndShowError, logAndShowWebviewError } from './shared/utilities/logAndShowUtils'
2222
import { telemetry } from './shared/telemetry/telemetry'
2323
import { openUrl } from './shared/utilities/vsCodeUtils'
@@ -54,6 +54,7 @@ import { AWSClientBuilderV3 } from './shared/awsClientBuilderV3'
5454
import { setupUninstallHandler } from './shared/handleUninstall'
5555
import { maybeShowMinVscodeWarning } from './shared/extensionStartup'
5656
import { getLogger } from './shared/logger/logger'
57+
import { setContext } from './shared/vscode/setContext'
5758

5859
disableAwsSdkWarning()
5960

@@ -118,6 +119,9 @@ export async function activateCommon(
118119
// telemetry
119120
await activateTelemetry(context, globals.awsContext, Settings.instance, 'AWS Toolkit For VS Code')
120121

122+
// set context var to identify if its SageMaker Unified Studio or not
123+
await setContext('aws.isSageMakerUnifiedStudio', isSageMaker('SMUS'))
124+
121125
// Create this now, but don't call vscode.window.registerUriHandler() until after all
122126
// Toolkit services have a chance to register their path handlers. #4105
123127
globals.uriHandler = new UriHandler()

0 commit comments

Comments
 (0)