Skip to content

Commit fac1d0d

Browse files
yueny2020laileni-aws
authored andcommitted
Merging Na Changes PR:6948 into mega
1 parent 7404226 commit fac1d0d

File tree

4 files changed

+85
-29
lines changed

4 files changed

+85
-29
lines changed

packages/core/src/amazonq/webview/ui/apps/cwChatConnector.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,10 @@ export class Connector extends BaseConnector {
314314

315315
if (
316316
!this.onChatAnswerUpdated ||
317-
!(['accept-code-diff', 'confirm-tool-use'].includes(action.id) || action.id.startsWith('reject-code-diff'))
317+
!(
318+
['accept-code-diff', 'run-shell-command', 'reject-shell-command'].includes(action.id) ||
319+
action.id.startsWith('reject-code-diff')
320+
)
318321
) {
319322
return
320323
}
@@ -341,17 +344,23 @@ export class Connector extends BaseConnector {
341344
answer.body = ' '
342345
}
343346
break
344-
case 'confirm-tool-use':
345-
answer.buttons = [
346-
{
347-
keepCardAfterClick: true,
348-
text: 'Confirmed',
349-
id: 'confirmed-tool-use',
347+
case 'run-shell-command':
348+
if (answer.header) {
349+
answer.header.status = {
350+
icon: 'ok' as MynahIconsType,
351+
text: 'Accepted',
350352
status: 'success',
351-
position: 'outside',
352-
disabled: true,
353-
},
354-
]
353+
}
354+
}
355+
break
356+
case 'reject-shell-command':
357+
if (answer.header) {
358+
answer.header.status = {
359+
icon: 'cancel' as MynahIconsType,
360+
text: 'Rejected',
361+
status: 'error',
362+
}
363+
}
355364
break
356365
default:
357366
break

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,30 @@ export class ChatController {
817817
}
818818
}
819819

820+
private async rejectShellCommand(message: CustomFormActionMessage) {
821+
const triggerId = randomUUID()
822+
this.triggerEventsStorage.addTriggerEvent({
823+
id: triggerId,
824+
tabID: message.tabID,
825+
message: undefined,
826+
type: 'chat_message',
827+
context: undefined,
828+
})
829+
await this.generateStaticTextResponse('reject-shell-command', triggerId)
830+
}
831+
820832
private async processCustomFormAction(message: CustomFormActionMessage) {
821833
switch (message.action.id) {
822834
case 'submit-create-prompt':
823835
await this.handleCreatePrompt(message)
824836
break
825-
case 'confirm-tool-use':
837+
case 'run-shell-command':
826838
case 'generic-tool-execution':
827839
await this.processToolUseMessage(message)
828840
break
841+
case 'reject-shell-command':
842+
await this.rejectShellCommand(message)
843+
break
829844
case 'tool-unavailable':
830845
await this.processUnavailableToolUseMessage(message)
831846
break

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

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ import { Change } from 'diff'
5050
import { FsWriteParams } from '../../../tools/fsWrite'
5151
import { AsyncEventProgressMessage } from '../../../../amazonq/commons/connector/connectorMessages'
5252

53-
export type StaticTextResponseType = 'quick-action-help' | 'onboarding-help' | 'transform' | 'help'
53+
export type StaticTextResponseType =
54+
| 'quick-action-help'
55+
| 'onboarding-help'
56+
| 'transform'
57+
| 'help'
58+
| 'reject-shell-command'
5459

5560
export type MessengerResponseType = {
5661
$metadata: { requestId?: string; httpStatusCode?: number }
@@ -242,10 +247,11 @@ export class Messenger {
242247
const chatStream = new ChatStream(this, tabID, triggerID, toolUse, validation, changeList)
243248
await ToolUtils.queueDescription(tool, chatStream)
244249

250+
const actionId =
251+
tool.type === ToolType.ExecuteBash ? 'run-shell-command' : 'generic-tool-execution'
252+
245253
this.dispatcher.sendCustomFormActionMessage(
246-
new CustomFormActionMessage(tabID, {
247-
id: 'generic-tool-execution',
248-
})
254+
new CustomFormActionMessage(tabID, { id: actionId })
249255
)
250256
} else {
251257
// TODO: Handle the error
@@ -450,12 +456,28 @@ export class Messenger {
450456
) {
451457
const buttons: ChatItemButton[] = []
452458
let fileList: ChatItemContent['fileList'] = undefined
453-
if (validation.requiresAcceptance && toolUse?.name === ToolType.ExecuteBash) {
454-
buttons.push({
455-
id: 'confirm-tool-use',
456-
text: 'Confirm',
457-
status: 'info',
458-
})
459+
let shellCommandHeader = undefined
460+
if (toolUse?.name === ToolType.ExecuteBash && message.startsWith('```shell')) {
461+
if (validation.requiresAcceptance) {
462+
buttons.push({
463+
id: 'run-shell-command',
464+
text: 'Run',
465+
status: 'main',
466+
icon: 'play' as MynahIconsType,
467+
})
468+
buttons.push({
469+
id: 'reject-shell-command',
470+
text: 'Reject',
471+
status: 'clear',
472+
icon: 'cancel' as MynahIconsType,
473+
})
474+
}
475+
476+
shellCommandHeader = {
477+
icon: 'code-block' as MynahIconsType,
478+
body: 'shell',
479+
buttons: buttons,
480+
}
459481

460482
if (validation.warning) {
461483
message = validation.warning + message
@@ -514,16 +536,23 @@ export class Messenger {
514536
codeBlockLanguage: undefined,
515537
contextList: undefined,
516538
canBeVoted: false,
517-
buttons: toolUse?.name === ToolType.FsWrite ? undefined : buttons,
518-
fullWidth: toolUse?.name === ToolType.FsWrite,
519-
padding: !(toolUse?.name === ToolType.FsWrite),
539+
buttons:
540+
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
541+
? undefined
542+
: buttons,
543+
fullWidth: toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash,
544+
padding: !(toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash),
520545
header:
521546
toolUse?.name === ToolType.FsWrite
522547
? { icon: 'code-block' as MynahIconsType, buttons: buttons, fileList: fileList }
523-
: undefined,
548+
: toolUse?.name === ToolType.ExecuteBash
549+
? shellCommandHeader
550+
: undefined,
524551
codeBlockActions:
525-
// eslint-disable-next-line unicorn/no-null, prettier/prettier
526-
toolUse?.name === ToolType.FsWrite ? { 'insert-to-cursor': null, copy: null } : undefined,
552+
toolUse?.name === ToolType.FsWrite || toolUse?.name === ToolType.ExecuteBash
553+
? // eslint-disable-next-line unicorn/no-null
554+
{ 'insert-to-cursor': null, copy: null }
555+
: undefined,
527556
},
528557
tabID
529558
)
@@ -575,6 +604,10 @@ export class Messenger {
575604
]
576605
followUpsHeader = 'Try Examples:'
577606
break
607+
case 'reject-shell-command':
608+
// need to update the string later
609+
message = 'The shell command execution rejected. Abort.'
610+
break
578611
}
579612

580613
this.dispatcher.sendChatMessage(

packages/core/src/codewhispererChat/tools/executeBash.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ export class ExecuteBash {
327327
}
328328

329329
public queueDescription(updates: Writable): void {
330-
updates.write(`I will run the following shell command:\n`)
331330
updates.write('```shell\n' + this.command + '\n```')
332331
updates.end()
333332
}

0 commit comments

Comments
 (0)