Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Toast message to warn users if Developer Profile is not selected"
}
4 changes: 4 additions & 0 deletions packages/amazonq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
"amazonQChatPairProgramming": {
"type": "boolean",
"default": false
},
"amazonQSelectDeveloperProfile": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion packages/amazonq/test/e2e/inline/inline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Amazon Q Inline', async function () {
.query({
metricName: 'codewhisperer_userTriggerDecision',
})
.map((e) => collectionUtil.partialClone(e, 3, ['credentialStartUrl'], '[omitted]'))
.map((e) => collectionUtil.partialClone(e, 3, ['credentialStartUrl'], { replacement: '[omitted]' }))
}

for (const [name, invokeCompletion] of [
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/auth/sso/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function addLoggingMiddleware(client: SSOOIDCClient) {
args.input as unknown as Record<string, unknown>,
3,
['clientSecret', 'accessToken', 'refreshToken'],
'[omitted]'
{ replacement: '[omitted]' }
)
getLogger().debug('API request (%s %s): %O', hostname, path, input)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ function addLoggingMiddleware(client: SSOOIDCClient) {
result.output as unknown as Record<string, unknown>,
3,
['clientSecret', 'accessToken', 'refreshToken'],
'[omitted]'
{ replacement: '[omitted]' }
)
getLogger().debug('API response (%s %s): %O', hostname, path, output)
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/codewhisperer/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import { SecurityIssueTreeViewProvider } from './service/securityIssueTreeViewPr
import { setContext } from '../shared/vscode/setContext'
import { syncSecurityIssueWebview } from './views/securityIssue/securityIssueWebview'
import { detectCommentAboveLine } from '../shared/utilities/commentUtils'
import { notifySelectDeveloperProfile } from './region/utils'

let localize: nls.LocalizeFunc

Expand Down Expand Up @@ -380,6 +381,10 @@ export async function activate(context: ExtContext): Promise<void> {
await auth.notifySessionConfiguration()
}
}

if (auth.requireProfileSelection()) {
await notifySelectDeveloperProfile()
}
},
{ emit: false, functionId: { name: 'activateCwCore' } }
)
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/codewhisperer/commands/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const firstStartUpSource = ExtStartUpSources.firstStartUp
export const cwEllipsesMenu = 'ellipsesMenu'
/** Indicates a CodeWhisperer command was executed from the command palette */
export const commandPalette = 'commandPalette'
/** Indicates a CodeWhisperer command was executed as a result of a toast message interaction */
export const toastMessage = 'toastMessage'

/**
* Indicates what caused the CodeWhisperer command to be executed, since a command can be executed from different "sources"
Expand All @@ -35,3 +37,4 @@ export type CodeWhispererSource =
| typeof firstStartUpSource
| typeof cwEllipsesMenu
| typeof commandPalette
| typeof toastMessage
49 changes: 49 additions & 0 deletions packages/core/src/codewhisperer/region/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()
import { AmazonQPromptSettings } from '../../shared/settings'
import { telemetry } from '../../shared/telemetry/telemetry'
import vscode from 'vscode'
import { selectRegionProfileCommand } from '../commands/basicCommands'
import { placeholder } from '../../shared/vscode/commands2'
import { toastMessage } from '../commands/types'

/**
* Creates a toast message telling the user they need to select a Developer Profile
*/
export async function notifySelectDeveloperProfile() {
const suppressId = 'amazonQSelectDeveloperProfile'
const settings = AmazonQPromptSettings.instance
const shouldShow = settings.isPromptEnabled(suppressId)
if (!shouldShow) {
return
}

const message = localize(
'aws.amazonq.profile.mustSelectMessage',
'You must select a Q Developer Profile for Amazon Q features to work.'
)
const selectProfile = 'Select Profile'
const dontShowAgain = 'Dont Show Again'

await telemetry.toolkit_showNotification.run(async () => {
telemetry.record({ id: 'mustSelectDeveloperProfileMessage' })
void vscode.window.showWarningMessage(message, selectProfile, dontShowAgain).then(async (resp) => {
await telemetry.toolkit_invokeAction.run(async () => {
if (resp === selectProfile) {
// Show Profile
telemetry.record({ action: 'select' })
void selectRegionProfileCommand.execute(placeholder, toastMessage)
} else if (resp === dontShowAgain) {
telemetry.record({ action: 'dontShowAgain' })
await settings.disablePrompt(suppressId)
} else {
telemetry.record({ action: 'ignore' })
}
})
})
})
}
1 change: 1 addition & 0 deletions packages/core/src/codewhisperer/util/authUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { withTelemetryContext } from '../../shared/telemetry/util'
import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands'
import { throttle } from 'lodash'
import { RegionProfileManager } from '../region/regionProfileManager'

/** Backwards compatibility for connections w pre-chat scopes */
export const codeWhispererCoreScopes = [...scopesCodeWhispererCore]
export const codeWhispererChatScopes = [...codeWhispererCoreScopes, ...scopesCodeWhispererChat]
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/shared/settings-amazonq.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const amazonqSettings = {
"amazonQLspManifestMessage": {},
"amazonQWorkspaceLspManifestMessage": {},
"amazonQChatDisclaimer": {},
"amazonQChatPairProgramming": {}
"amazonQChatPairProgramming": {},
"amazonQSelectDeveloperProfile": {}
},
"amazonQ.showCodeWithReferences": {},
"amazonQ.allowFeatureDevelopmentToRunCodeAndTests": {},
Expand Down
21 changes: 17 additions & 4 deletions packages/core/src/shared/utilities/collectionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isWeb } from '../extensionGlobals'
import { inspect as nodeInspect } from 'util'
import { AsyncCollection, toCollection } from './asyncCollection'
import { SharedProp, AccumulableKeys, Coalesce, isNonNullable } from './tsUtils'
import { truncate } from './textUtilities'

export function union<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
const result = new Set<T>()
Expand Down Expand Up @@ -304,26 +305,38 @@ export function assign<T extends Record<any, any>, U extends Partial<T>>(data: T
* @param depth
* @param omitKeys Omit properties matching these names (at any depth).
* @param replacement Replacement for object whose fields extend beyond `depth`, and properties matching `omitKeys`.
* @param maxStringLength truncates string values that exceed this threshold (includes values in nested arrays)
*/
export function partialClone(obj: any, depth: number = 3, omitKeys: string[] = [], replacement?: any): any {
export function partialClone(
obj: any,
depth: number = 3,
omitKeys: string[] = [],
options?: {
replacement?: any
maxStringLength?: number
}
): any {
// Base case: If input is not an object or has no children, return it.
if (typeof obj !== 'object' || obj === null || 0 === Object.getOwnPropertyNames(obj).length) {
if (typeof obj === 'string' && options?.maxStringLength) {
return truncate(obj, options?.maxStringLength, '...')
}
return obj
}

// Create a new object of the same type as the input object.
const clonedObj = Array.isArray(obj) ? [] : {}

if (depth === 0) {
return replacement ? replacement : clonedObj
return options?.replacement ? options.replacement : clonedObj
}

// Recursively clone properties of the input object
for (const key in obj) {
if (omitKeys.includes(key)) {
;(clonedObj as any)[key] = replacement ? replacement : Array.isArray(obj) ? [] : {}
;(clonedObj as any)[key] = options?.replacement ? options.replacement : Array.isArray(obj) ? [] : {}
} else if (Object.prototype.hasOwnProperty.call(obj, key)) {
;(clonedObj as any)[key] = partialClone(obj[key], depth - 1, omitKeys, replacement)
;(clonedObj as any)[key] = partialClone(obj[key], depth - 1, omitKeys, options)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/utilities/textUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { default as stripAnsi } from 'strip-ansi'
import { getLogger } from '../logger/logger'

/**
* Truncates string `s` if it exceeds `n` chars.
* Truncates string `s` if it has or exceeds `n` chars.
*
* If `n` is negative, truncates at start instead of end.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/vscode/commands2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ async function runCommand<T extends Callback>(fn: T, info: CommandInfo<T>): Prom

logger.debug(
`command: running ${label} with arguments: %O`,
partialClone(args, 3, ['clientSecret', 'accessToken', 'refreshToken', 'tooltip'], '[omitted]')
partialClone(args, 3, ['clientSecret', 'accessToken', 'refreshToken', 'tooltip'], { replacement: '[omitted]' })
)

try {
Expand Down
91 changes: 58 additions & 33 deletions packages/core/src/test/shared/utilities/collectionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,10 @@ describe('CollectionUtils', async function () {
})

describe('partialClone', function () {
it('omits properties by depth', function () {
const testObj = {
let multipleTypedObj: object

before(async function () {
multipleTypedObj = {
a: 34234234234,
b: '123456789',
c: new Date(2023, 1, 1),
Expand All @@ -724,57 +726,80 @@ describe('CollectionUtils', async function () {
throw Error()
},
}
})

assert.deepStrictEqual(partialClone(testObj, 1), {
...testObj,
it('omits properties by depth', function () {
assert.deepStrictEqual(partialClone(multipleTypedObj, 1), {
...multipleTypedObj,
d: {},
e: {},
})
assert.deepStrictEqual(partialClone(testObj, 0, [], '[replaced]'), '[replaced]')
assert.deepStrictEqual(partialClone(testObj, 1, [], '[replaced]'), {
...testObj,
assert.deepStrictEqual(partialClone(multipleTypedObj, 0, [], { replacement: '[replaced]' }), '[replaced]')
assert.deepStrictEqual(partialClone(multipleTypedObj, 1, [], { replacement: '[replaced]' }), {
...multipleTypedObj,
d: '[replaced]',
e: '[replaced]',
})
assert.deepStrictEqual(partialClone(testObj, 3), {
...testObj,
assert.deepStrictEqual(partialClone(multipleTypedObj, 3), {
...multipleTypedObj,
d: { d1: { d2: {} } },
})
assert.deepStrictEqual(partialClone(testObj, 4), testObj)
assert.deepStrictEqual(partialClone(multipleTypedObj, 4), multipleTypedObj)
})

it('omits properties by name', function () {
const testObj = {
a: 34234234234,
b: '123456789',
c: new Date(2023, 1, 1),
d: { d1: { d2: { d3: 'deep' } } },
assert.deepStrictEqual(partialClone(multipleTypedObj, 2, ['c', 'e2'], { replacement: '[replaced]' }), {
...multipleTypedObj,
c: '[replaced]',
d: { d1: '[replaced]' },
e: {
e1: '[replaced]',
e2: '[replaced]',
},
})
assert.deepStrictEqual(partialClone(multipleTypedObj, 3, ['c', 'e2'], { replacement: '[replaced]' }), {
...multipleTypedObj,
c: '[replaced]',
d: { d1: { d2: '[replaced]' } },
e: {
e1: [4, 3, 7],
e2: 'loooooooooo \n nnnnnnnnnnn \n gggggggg \n string',
e2: '[replaced]',
},
f: () => {
throw Error()
})
})

it('truncates properties by maxLength', function () {
const testObj = {
strValue: '1',
boolValue: true,
longString: '11111',
nestedObj: {
nestedObjAgain: {
longNestedStr: '11111',
shortNestedStr: '11',
},
},
nestedObj2: {
functionValue: (_: unknown) => {},
},
nestedObj3: {
myArray: ['1', '11111', '1'],
},
objInArray: [{ shortString: '11', longString: '11111' }],
}

assert.deepStrictEqual(partialClone(testObj, 2, ['c', 'e2'], '[omitted]'), {
assert.deepStrictEqual(partialClone(testObj, 5, [], { maxStringLength: 2 }), {
...testObj,
c: '[omitted]',
d: { d1: '[omitted]' },
e: {
e1: '[omitted]',
e2: '[omitted]',
longString: '11...',
nestedObj: {
nestedObjAgain: {
longNestedStr: '11...',
shortNestedStr: '11',
},
},
})
assert.deepStrictEqual(partialClone(testObj, 3, ['c', 'e2'], '[omitted]'), {
...testObj,
c: '[omitted]',
d: { d1: { d2: '[omitted]' } },
e: {
e1: [4, 3, 7],
e2: '[omitted]',
nestedObj3: {
myArray: ['1', '11...', '1'],
},
objInArray: [{ shortString: '11', longString: '11...' }],
})
})
})
Expand Down