From 58ad02a79b9103b3e7084c2565cda60fc563fda3 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 21 Apr 2025 22:46:23 -0400 Subject: [PATCH 1/3] feat: add button click event --- package-lock.json | 29 +++++++++++++---------- packages/amazonq/src/lsp/chat/messages.ts | 28 +++++++++++++++++++++- packages/core/package.json | 4 ++-- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 77bfc670449..e7f94a7b052 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10842,15 +10842,16 @@ } }, "node_modules/@aws/language-server-runtimes": { - "version": "0.2.58", - "resolved": "https://registry.npmjs.org/@aws/language-server-runtimes/-/language-server-runtimes-0.2.58.tgz", - "integrity": "sha512-gb1oLKACFpmDKkzSdDAqMdpo63m+Kul4B/uVNNO1IFN4+wEP7zPVgmd1dLDPlLKHrxsAEQDxoYDaYVyQ+yJKqQ==", + "version": "0.2.70", + "resolved": "https://registry.npmjs.org/@aws/language-server-runtimes/-/language-server-runtimes-0.2.70.tgz", + "integrity": "sha512-fC7Z1LVe2ZYaYBpkOzFxvYFaRnallMt7SzPC8u9wyMUTVnNEyhcegF+aA5g44dmAFOWO+XapHoDO4FoQXXs+rg==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@apidevtools/json-schema-ref-parser": "^11.9.3", "@aws-crypto/sha256-js": "^5.2.0", "@aws-sdk/client-cognito-identity": "^3.758.0", - "@aws/language-server-runtimes-types": "^0.1.13", + "@aws/language-server-runtimes-types": "^0.1.21", "@opentelemetry/api": "^1.9.0", "@opentelemetry/resources": "^1.30.1", "@opentelemetry/sdk-metrics": "^1.30.1", @@ -10864,7 +10865,7 @@ "aws-sdk": "^2.1692.0", "axios": "^1.8.4", "hpagent": "^1.2.0", - "jose": "^6.0.10", + "jose": "^5.9.6", "mac-ca": "^3.1.1", "rxjs": "^7.8.2", "vscode-languageserver": "^9.0.1", @@ -10876,10 +10877,11 @@ } }, "node_modules/@aws/language-server-runtimes-types": { - "version": "0.1.19", - "resolved": "https://registry.npmjs.org/@aws/language-server-runtimes-types/-/language-server-runtimes-types-0.1.19.tgz", - "integrity": "sha512-c81J3G3N6JP5A6g70xTpK/XPS1YWwviQBn307Rk3S5fSiALT8INeHM+IPDg9AuONU6w378RJjzQy3+PE0gJvsw==", + "version": "0.1.21", + "resolved": "https://registry.npmjs.org/@aws/language-server-runtimes-types/-/language-server-runtimes-types-0.1.21.tgz", + "integrity": "sha512-03C3dz4MvMyKg4UAgHMNNw675OQJkDq+7TPXUPaiasqPF946ywTDD9xoNPaVOQI+YTtC7Re4vhPRfBzyad3MOg==", "dev": true, + "license": "Apache-2.0", "dependencies": { "vscode-languageserver-textdocument": "^1.0.12", "vscode-languageserver-types": "^3.17.5" @@ -11902,10 +11904,11 @@ } }, "node_modules/@aws/language-server-runtimes/node_modules/jose": { - "version": "6.0.10", - "resolved": "https://registry.npmjs.org/jose/-/jose-6.0.10.tgz", - "integrity": "sha512-skIAxZqcMkOrSwjJvplIPYrlXGpxTPnro2/QWTDCxAdWQrSTV5/KqspMWmi5WAx5+ULswASJiZ0a+1B/Lxt9cw==", + "version": "5.10.0", + "resolved": "https://registry.npmjs.org/jose/-/jose-5.10.0.tgz", + "integrity": "sha512-s+3Al/p9g32Iq+oqXxkW//7jk2Vig6FF1CFqzVXoTUXt2qz89YWbL+OwS17NFYEvxC35n0FKeGO2LGYSxeM2Gg==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/sponsors/panva" } @@ -26805,8 +26808,8 @@ "@aws-sdk/types": "^3.13.1", "@aws/chat-client": "^0.1.4", "@aws/chat-client-ui-types": "^0.1.22", - "@aws/language-server-runtimes": "^0.2.58", - "@aws/language-server-runtimes-types": "^0.1.13", + "@aws/language-server-runtimes": "^0.2.70", + "@aws/language-server-runtimes-types": "^0.1.21", "@cspotcode/source-map-support": "^0.8.1", "@sinonjs/fake-timers": "^10.0.2", "@types/adm-zip": "^0.4.34", diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index 2f17d6a8bfa..d544b743be7 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -42,6 +42,8 @@ import { LINK_CLICK_NOTIFICATION_METHOD, LinkClickParams, INFO_LINK_CLICK_NOTIFICATION_METHOD, + buttonClickRequestType, + ButtonClickResult, } from '@aws/language-server-runtimes/protocol' import { v4 as uuidv4 } from 'uuid' import * as vscode from 'vscode' @@ -281,6 +283,17 @@ export function registerMessageListeners( languageClient.sendNotification(followUpClickNotificationType.method, message.params) } break + case buttonClickRequestType.method: + const buttonResult = await languageClient.sendRequest( + buttonClickRequestType.method, + message.params + ) + if (!buttonResult.success) { + languageClient.error( + `[VSCode Client] Failed to execute action associated with button with reason: ${buttonResult.failureReason}` + ) + } + break default: if (isServerEvent(message.command)) { languageClient.sendNotification(message.command, message.params) @@ -459,9 +472,22 @@ async function handleCompleteResult( tabId: string, disposable: Disposable ) { - const decryptedMessage = + const decryptedMessage = ( typeof result === 'string' && encryptionKey ? await decodeRequest(result, encryptionKey) : result + ) as any + decryptedMessage.additionalMessages[0].buttons = [ + { + id: 'reject-shell-command', + text: 'Reject', + icon: 'cancel', + }, + { + id: 'run-shell-command', + text: 'Run', + icon: 'play', + }, + ] void provider.webview?.postMessage({ command: chatRequestType.method, params: decryptedMessage, diff --git a/packages/core/package.json b/packages/core/package.json index 98f24feae81..7a94d48161d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -443,8 +443,8 @@ "@aws-sdk/types": "^3.13.1", "@aws/chat-client": "^0.1.4", "@aws/chat-client-ui-types": "^0.1.22", - "@aws/language-server-runtimes": "^0.2.58", - "@aws/language-server-runtimes-types": "^0.1.13", + "@aws/language-server-runtimes": "^0.2.70", + "@aws/language-server-runtimes-types": "^0.1.21", "@cspotcode/source-map-support": "^0.8.1", "@sinonjs/fake-timers": "^10.0.2", "@types/adm-zip": "^0.4.34", From 9fe9de77e13833bcce8bf96053b7dd446955b406 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 21 Apr 2025 22:55:35 -0400 Subject: [PATCH 2/3] fix: avoid hardcoded buttons for testing --- packages/amazonq/src/lsp/chat/messages.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index d544b743be7..9356f7ab1e9 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -472,22 +472,8 @@ async function handleCompleteResult( tabId: string, disposable: Disposable ) { - const decryptedMessage = ( + const decryptedMessage = typeof result === 'string' && encryptionKey ? await decodeRequest(result, encryptionKey) : result - ) as any - - decryptedMessage.additionalMessages[0].buttons = [ - { - id: 'reject-shell-command', - text: 'Reject', - icon: 'cancel', - }, - { - id: 'run-shell-command', - text: 'Run', - icon: 'play', - }, - ] void provider.webview?.postMessage({ command: chatRequestType.method, params: decryptedMessage, From e164550bb6ea4386135ca8cbe1946b7bf55ba841 Mon Sep 17 00:00:00 2001 From: hkobew Date: Tue, 22 Apr 2025 08:26:20 -0400 Subject: [PATCH 3/3] fix: fix lint error --- packages/amazonq/src/lsp/chat/messages.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index 05358ace6a8..d655c67c284 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -306,7 +306,7 @@ export function registerMessageListeners( languageClient.sendNotification(followUpClickNotificationType.method, message.params) } break - case buttonClickRequestType.method: + case buttonClickRequestType.method: { const buttonResult = await languageClient.sendRequest( buttonClickRequestType.method, message.params @@ -317,6 +317,7 @@ export function registerMessageListeners( ) } break + } default: if (isServerEvent(message.command)) { languageClient.sendNotification(message.command, message.params)