diff --git a/app/aws-lsp-codewhisperer-runtimes/webpack.config.js b/app/aws-lsp-codewhisperer-runtimes/webpack.config.js index 162ce3f7f1..0611d76a4d 100644 --- a/app/aws-lsp-codewhisperer-runtimes/webpack.config.js +++ b/app/aws-lsp-codewhisperer-runtimes/webpack.config.js @@ -83,6 +83,11 @@ const webworkerConfig = { fs: path.resolve(__dirname, 'src/mock-fs.js'), child_process: false, vm: false, + dns: false, + zlib: false, + net: false, + tls: false, + http2: false, }, extensions: ['.ts', '.tsx', '.js', '.jsx'], }, diff --git a/package-lock.json b/package-lock.json index 949c64e1a7..208f9bf51b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10931,7 +10931,6 @@ "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true, "license": "MIT" }, "node_modules/atomic-sleep": { @@ -10994,6 +10993,16 @@ "resolved": "client/vscode", "link": true }, + "node_modules/axios": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz", + "integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/b4a": { "version": "1.6.7", "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.7.tgz", @@ -12242,7 +12251,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" @@ -13232,7 +13240,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.4.0" @@ -13909,7 +13916,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "dev": true, "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -15263,7 +15269,6 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", - "dev": true, "license": "MIT", "dependencies": { "asynckit": "^0.4.0", @@ -21289,7 +21294,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "dev": true, "license": "MIT" }, "node_modules/psl": { @@ -26539,6 +26543,7 @@ "adm-zip": "^0.5.10", "archiver": "^7.0.1", "aws-sdk": "^2.1403.0", + "axios": "^1.9.0", "chokidar": "^4.0.3", "deepmerge": "^4.3.1", "diff": "^7.0.0", diff --git a/server/aws-lsp-codewhisperer/package.json b/server/aws-lsp-codewhisperer/package.json index 30816edd0f..8bed7503f7 100644 --- a/server/aws-lsp-codewhisperer/package.json +++ b/server/aws-lsp-codewhisperer/package.json @@ -39,6 +39,7 @@ "adm-zip": "^0.5.10", "archiver": "^7.0.1", "aws-sdk": "^2.1403.0", + "axios": "^1.9.0", "chokidar": "^4.0.3", "deepmerge": "^4.3.1", "diff": "^7.0.0", diff --git a/server/aws-lsp-codewhisperer/src/language-server/inline-completion/codeWhispererServer.ts b/server/aws-lsp-codewhisperer/src/language-server/inline-completion/codeWhispererServer.ts index 24d92bb258..cc2b6ed375 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/inline-completion/codeWhispererServer.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/inline-completion/codeWhispererServer.ts @@ -49,7 +49,7 @@ import { getOrThrowBaseTokenServiceManager } from '../../shared/amazonQServiceMa import { AmazonQWorkspaceConfig } from '../../shared/amazonQServiceManager/configurationUtils' import { hasConnectionExpired } from '../../shared/utils' import { getOrThrowBaseIAMServiceManager } from '../../shared/amazonQServiceManager/AmazonQIAMServiceManager' -// import { WorkspaceFolderManager } from '../workspaceContext/workspaceFolderManager' +import { WorkspaceFolderManager } from '../workspaceContext/workspaceFolderManager' import path = require('path') import { getRelativePath } from '../workspaceContext/util' import { UserWrittenCodeTracker } from '../../shared/userWrittenCodeTracker' @@ -346,8 +346,10 @@ export const CodewhispererServerFactory = const maxResults = isAutomaticLspTriggerKind ? 1 : 5 const selectionRange = params.context.selectedCompletionInfo?.range const fileContext = getFileContext({ textDocument, inferredLanguageId, position: params.position }) - // const workspaceFolder = WorkspaceFolderManager.getInstance()?.getWorkspaceFolder(params.textDocument.uri) - // const workspaceId = WorkspaceFolderManager.getInstance()?.getWorkspaceId(workspaceFolder) + const workspaceState = WorkspaceFolderManager.getInstance()?.getWorkspaceState() + const workspaceId = workspaceState?.webSocketClient?.isConnected() + ? workspaceState.workspaceId + : undefined // TODO: Can we get this derived from a keyboard event in the future? // This picks the last non-whitespace character, if any, before the cursor const triggerCharacter = fileContext.leftFileContent.trim().at(-1) ?? '' @@ -450,7 +452,7 @@ export const CodewhispererServerFactory = .slice(0, CONTEXT_CHARACTERS_LIMIT) .replaceAll('\r\n', '\n'), }, - // workspaceId: workspaceId, + ...(workspaceId ? { workspaceId: workspaceId } : {}), }) .then(async suggestionResponse => { return processSuggestionResponse(suggestionResponse, newSession, true, selectionRange) diff --git a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/util.ts b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/util.ts index 8216484735..b8de43723b 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/util.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/util.ts @@ -1,10 +1,10 @@ import { CredentialsProvider, WorkspaceFolder } from '@aws/language-server-runtimes/server-interface' import { CreateUploadUrlResponse } from '../../client/token/codewhispererbearertokenclient' -import got from 'got' import { URI } from 'vscode-uri' import * as fs from 'fs' import * as crypto from 'crypto' import * as path from 'path' +import axios from 'axios' export const findWorkspaceRootFolder = ( fileUri: string, @@ -47,10 +47,7 @@ export const uploadArtifactToS3 = async (content: Buffer, resp: CreateUploadUrlR 'x-amz-server-side-encryption-context': Buffer.from(encryptionContext, 'utf8').toString('base64'), }) } - await got.put(resp.uploadUrl, { - body: content, - headers: headersObj, - }) + await axios.put(resp.uploadUrl, { body: content, headers: headersObj }) } export const isDirectory = (path: string): boolean => {