Changesets · Branches · Tags · Compare
| Changeset | 6a75d4a25a1b8eabe48d69e5120eabecf563edeadb5230191fb33da1d400f548 |
|---|---|
| Author | Kai Wu <wukaixingxp@gmail.com> · 2025-06-27 09:35 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-06-27 09:35 -07:00 |
| Parents | e3d542597aad, 280dc5ce026e |
49 files changed
added .continue/rules/new-protocol-message.md +35 −0
| @@ -0,0 +1,35 @@ | ||
| 1 | +--- | |
| 2 | +name: New protocol message | |
| 3 | +description: Create a new protocol message from core/gui/ide to core/gui/ide | |
| 4 | +--- | |
| 5 | + | |
| 6 | +Create a new protocol message by taking the following steps: | |
| 7 | + | |
| 8 | +## 1. Define the message type | |
| 9 | + | |
| 10 | +Add your new message type definition to the appropriate file in the `protocol/` directory with correct TypeScript typing. | |
| 11 | + | |
| 12 | +## 2. Check for duplicates | |
| 13 | + | |
| 14 | +Verify that no existing message type already provides the same functionality. | |
| 15 | + | |
| 16 | +## 3. Add to passThrough (if webview ↔ core) | |
| 17 | + | |
| 18 | +If your message is between webview and core, add it to `core/protocol/passThrough.ts`. | |
| 19 | + | |
| 20 | +## 4. Add to IntelliJ constants (if webview ↔ core) | |
| 21 | + | |
| 22 | +If your message is between webview and core, add it to `extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt`. | |
| 23 | + | |
| 24 | +## 5. Implement the message handler | |
| 25 | + | |
| 26 | +Implement the message in the appropriate location: | |
| 27 | + | |
| 28 | +- **Messages to core**: `core/core.ts` | |
| 29 | +- **Messages to GUI**: `useWebviewListener` hook | |
| 30 | +- **Messages to VS Code IDE**: `VsCodeMessenger.ts` | |
| 31 | +- **Messages to JetBrains IDE**: `IdeProtocolClient.kt` | |
| 32 | + | |
| 33 | +## 6. Test the implementation | |
| 34 | + | |
| 35 | +Verify that your message works correctly in both VS Code and JetBrains IDEs if applicable. |
added .continue/rules/overeager.md +5 −0
| @@ -0,0 +1,5 @@ | ||
| 1 | +--- | |
| 2 | +name: Don't be overeager | |
| 3 | +--- | |
| 4 | + | |
| 5 | +Avoid over-eagerly adding new features. You should solve the problem at hand and then can propose further work. |
modified .github/workflows/main.yaml +8 −0
| @@ -104,6 +104,14 @@ | ||
| 104 | 104 | path: gui/node_modules |
| 105 | 105 | key: ${{ runner.os }}-node-${{ hashFiles('gui/package-lock.json') }} |
| 106 | 106 | |
| 107 | + - name: Build packages (Windows) | |
| 108 | + run: ./scripts/build-packages.ps1 | |
| 109 | + if: matrix.os == 'windows-latest' | |
| 110 | + | |
| 111 | + - name: Build packages (Unix) | |
| 112 | + run: ./scripts/build-packages.sh | |
| 113 | + if: matrix.os != 'windows-latest' | |
| 114 | + | |
| 107 | 115 | - name: Install extension Dependencies |
| 108 | 116 | run: | |
| 109 | 117 | cd extensions/vscode |
modified .github/workflows/preview.yaml +8 −0
| @@ -99,6 +99,14 @@ | ||
| 99 | 99 | path: gui/node_modules |
| 100 | 100 | key: ${{ runner.os }}-node-${{ hashFiles('gui/package-lock.json') }} |
| 101 | 101 | |
| 102 | + - name: Build packages (Windows) | |
| 103 | + run: ./scripts/build-packages.ps1 | |
| 104 | + if: matrix.os == 'windows-latest' | |
| 105 | + | |
| 106 | + - name: Build packages (Unix) | |
| 107 | + run: ./scripts/build-packages.sh | |
| 108 | + if: matrix.os != 'windows-latest' | |
| 109 | + | |
| 102 | 110 | - name: Install extension Dependencies |
| 103 | 111 | run: | |
| 104 | 112 | cd extensions/vscode |
modified .vscode/tasks.json +3 −0
| @@ -103,6 +103,9 @@ | ||
| 103 | 103 | "clear": true |
| 104 | 104 | }, |
| 105 | 105 | "options": { |
| 106 | + "env": { | |
| 107 | + "SKIP_INSTALLS": "true" | |
| 108 | + }, | |
| 106 | 109 | "cwd": "${workspaceFolder}/extensions/vscode" |
| 107 | 110 | } |
| 108 | 111 | }, |
modified binary/build.js +26 −144
| @@ -3,13 +3,13 @@ | ||
| 3 | 3 | const path = require("path"); |
| 4 | 4 | const ncp = require("ncp").ncp; |
| 5 | 5 | const { rimrafSync } = require("rimraf"); |
| 6 | -const { | |
| 7 | - validateFilesPresent, | |
| 8 | - execCmdSync, | |
| 9 | - autodetectPlatformAndArch, | |
| 10 | -} = require("../scripts/util"); | |
| 11 | -const { downloadRipgrep } = require("./utils/ripgrep"); | |
| 6 | +const { validateFilesPresent } = require("../scripts/util"); | |
| 12 | 7 | const { ALL_TARGETS, TARGET_TO_LANCEDB } = require("./utils/targets"); |
| 8 | +const { fork } = require("child_process"); | |
| 9 | +const { | |
| 10 | + installAndCopyNodeModules, | |
| 11 | +} = require("../extensions/vscode/scripts/install-copy-nodemodule"); | |
| 12 | +const { bundleBinary } = require("./utils/bundle-binary"); | |
| 13 | 13 | |
| 14 | 14 | const bin = path.join(__dirname, "bin"); |
| 15 | 15 | const out = path.join(__dirname, "out"); |
| @@ -29,8 +29,6 @@ | ||
| 29 | 29 | const esbuildOutputFile = "out/index.js"; |
| 30 | 30 | let targets = [...ALL_TARGETS]; |
| 31 | 31 | |
| 32 | -const [currentPlatform, currentArch] = autodetectPlatformAndArch(); | |
| 33 | - | |
| 34 | 32 | const assetBackups = [ |
| 35 | 33 | "node_modules/win-ca/lib/crypt32-ia32.node.bak", |
| 36 | 34 | "node_modules/win-ca/lib/crypt32-x64.node.bak", |
| @@ -78,85 +76,6 @@ | ||
| 78 | 76 | }); |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | -async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { | |
| 82 | - console.log(`Copying ${packageName} to ${toCopy}`); | |
| 83 | - // This is a way to install only one package without npm trying to install all the dependencies | |
| 84 | - // Create a temporary directory for installing the package | |
| 85 | - const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); | |
| 86 | - const tempDir = path.join( | |
| 87 | - __dirname, | |
| 88 | - "tmp", | |
| 89 | - `continue-node_modules-${adjustedName}`, | |
| 90 | - ); | |
| 91 | - const currentDir = process.cwd(); | |
| 92 | - | |
| 93 | - // // Remove the dir we will be copying to | |
| 94 | - // rimrafSync(`node_modules/${toCopy}`); | |
| 95 | - | |
| 96 | - // // Ensure the temporary directory exists | |
| 97 | - fs.mkdirSync(tempDir, { recursive: true }); | |
| 98 | - | |
| 99 | - try { | |
| 100 | - // Move to the temporary directory | |
| 101 | - process.chdir(tempDir); | |
| 102 | - | |
| 103 | - // Initialize a new package.json and install the package | |
| 104 | - execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`); | |
| 105 | - | |
| 106 | - console.log( | |
| 107 | - `Contents of: ${packageName}`, | |
| 108 | - fs.readdirSync(path.join(tempDir, "node_modules", toCopy)), | |
| 109 | - ); | |
| 110 | - | |
| 111 | - // Without this it seems the file isn't completely written to disk | |
| 112 | - await new Promise((resolve) => setTimeout(resolve, 2000)); | |
| 113 | - | |
| 114 | - // Copy the installed package back to the current directory | |
| 115 | - await new Promise((resolve, reject) => { | |
| 116 | - ncp( | |
| 117 | - path.join(tempDir, "node_modules", toCopy), | |
| 118 | - path.join(currentDir, "node_modules", toCopy), | |
| 119 | - { dereference: true }, | |
| 120 | - (error) => { | |
| 121 | - if (error) { | |
| 122 | - console.error( | |
| 123 | - `[error] Error copying ${packageName} package`, | |
| 124 | - error, | |
| 125 | - ); | |
| 126 | - reject(error); | |
| 127 | - } else { | |
| 128 | - resolve(); | |
| 129 | - } | |
| 130 | - }, | |
| 131 | - ); | |
| 132 | - }); | |
| 133 | - } finally { | |
| 134 | - // Clean up the temporary directory | |
| 135 | - // rimrafSync(tempDir); | |
| 136 | - | |
| 137 | - // Return to the original directory | |
| 138 | - process.chdir(currentDir); | |
| 139 | - } | |
| 140 | -} | |
| 141 | - | |
| 142 | -/** | |
| 143 | - * Downloads and installs ripgrep binaries for the specified target | |
| 144 | - * | |
| 145 | - * @param {string} target - Target platform-arch (e.g., 'darwin-x64') | |
| 146 | - * @param {string} targetDir - Directory to install ripgrep to | |
| 147 | - * @returns {Promise<void>} | |
| 148 | - */ | |
| 149 | -async function downloadRipgrepForTarget(target, targetDir) { | |
| 150 | - console.log(`[info] Downloading ripgrep for ${target}...`); | |
| 151 | - try { | |
| 152 | - await downloadRipgrep(target, targetDir); | |
| 153 | - console.log(`[info] Successfully installed ripgrep for ${target}`); | |
| 154 | - } catch (error) { | |
| 155 | - console.error(`[error] Failed to download ripgrep for ${target}:`, error); | |
| 156 | - throw error; | |
| 157 | - } | |
| 158 | -} | |
| 159 | - | |
| 160 | 79 | (async () => { |
| 161 | 80 | if (esbuildOnly) { |
| 162 | 81 | await buildWithEsbuild(); |
| @@ -181,16 +100,21 @@ | ||
| 181 | 100 | ), |
| 182 | 101 | ); |
| 183 | 102 | |
| 184 | - console.log("[info] Downloading prebuilt lancedb..."); | |
| 103 | + const copyLanceDBPromises = []; | |
| 185 | 104 | for (const target of targets) { |
| 186 | - if (TARGET_TO_LANCEDB[target]) { | |
| 187 | - console.log(`[info] Downloading for ${target}...`); | |
| 188 | - await installNodeModuleInTempDirAndCopyToCurrent( | |
| 189 | - TARGET_TO_LANCEDB[target], | |
| 190 | - "@lancedb", | |
| 191 | - ); | |
| 105 | + if (!TARGET_TO_LANCEDB[target]) { | |
| 106 | + continue; | |
| 192 | 107 | } |
| 108 | + console.log(`[info] Downloading for ${target}...`); | |
| 109 | + copyLanceDBPromises.push( | |
| 110 | + installAndCopyNodeModules(TARGET_TO_LANCEDB[target], "@lancedb"), | |
| 111 | + ); | |
| 193 | 112 | } |
| 113 | + await Promise.all(copyLanceDBPromises).catch(() => { | |
| 114 | + console.error("[error] Failed to copy LanceDB"); | |
| 115 | + process.exit(1); | |
| 116 | + }); | |
| 117 | + console.log("[info] Copied all LanceDB"); | |
| 194 | 118 | |
| 195 | 119 | // tree-sitter-wasm |
| 196 | 120 | const treeSitterWasmsDir = path.join(out, "tree-sitter-wasms"); |
| @@ -252,59 +176,16 @@ | ||
| 252 | 176 | "out/llamaTokenizerWorkerPool.mjs", |
| 253 | 177 | ); |
| 254 | 178 | |
| 179 | + const buildBinaryPromises = []; | |
| 255 | 180 | console.log("[info] Building binaries with pkg..."); |
| 256 | 181 | for (const target of targets) { |
| 257 | - const targetDir = `bin/${target}`; | |
| 258 | - fs.mkdirSync(targetDir, { recursive: true }); | |
| 259 | - console.log(`[info] Building ${target}...`); | |
| 260 | - execCmdSync( | |
| 261 | - `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${target} --out-path ${targetDir}`, | |
| 262 | - ); | |
| 263 | - | |
| 264 | - // Download and unzip prebuilt sqlite3 binary for the target | |
| 265 | - console.log("[info] Downloading node-sqlite3"); | |
| 266 | - | |
| 267 | - const downloadUrl = | |
| 268 | - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 | |
| 269 | - target === "win32-arm64" | |
| 270 | - ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" | |
| 271 | - : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ | |
| 272 | - target | |
| 273 | - }.tar.gz`; | |
| 274 | - | |
| 275 | - execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`); | |
| 276 | - execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); | |
| 277 | - | |
| 278 | - // Copy to build directory for testing | |
| 279 | - try { | |
| 280 | - const [platform, arch] = target.split("-"); | |
| 281 | - if (platform === currentPlatform && arch === currentArch) { | |
| 282 | - fs.copyFileSync( | |
| 283 | - `${targetDir}/build/Release/node_sqlite3.node`, | |
| 284 | - `build/node_sqlite3.node`, | |
| 285 | - ); | |
| 286 | - } | |
| 287 | - } catch (error) { | |
| 288 | - console.log("[warn] Could not copy node_sqlite to build"); | |
| 289 | - console.log(error); | |
| 290 | - } | |
| 291 | - | |
| 292 | - fs.unlinkSync(`${targetDir}/build.tar.gz`); | |
| 293 | - | |
| 294 | - // copy @lancedb to bin folders | |
| 295 | - console.log("[info] Copying @lancedb files to bin"); | |
| 296 | - fs.copyFileSync( | |
| 297 | - `node_modules/${TARGET_TO_LANCEDB[target]}/index.node`, | |
| 298 | - `${targetDir}/index.node`, | |
| 299 | - ); | |
| 300 | - | |
| 301 | - // Download and install ripgrep for the target | |
| 302 | - await downloadRipgrepForTarget(target, targetDir); | |
| 303 | - | |
| 304 | - // Informs the `continue-binary` of where to look for node_sqlite3.node | |
| 305 | - // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found | |
| 306 | - fs.writeFileSync(`${targetDir}/package.json`, ""); | |
| 182 | + buildBinaryPromises.push(bundleBinary(target)); | |
| 307 | 183 | } |
| 184 | + await Promise.all(buildBinaryPromises).catch(() => { | |
| 185 | + console.error("[error] Failed to build binaries"); | |
| 186 | + process.exit(1); | |
| 187 | + }); | |
| 188 | + console.log("[info] All binaries built"); | |
| 308 | 189 | |
| 309 | 190 | // Cleanup - this is needed when running locally |
| 310 | 191 | fs.rmSync("out/package.json"); |
| @@ -331,4 +212,5 @@ | ||
| 331 | 212 | validateFilesPresent(pathsToVerify); |
| 332 | 213 | |
| 333 | 214 | console.log("[info] Done!"); |
| 215 | + process.exit(0); | |
| 334 | 216 | })(); |
modified binary/package-lock.json +2 −4
| @@ -53,9 +53,9 @@ | ||
| 53 | 53 | "@aws-sdk/credential-providers": "^3.778.0", |
| 54 | 54 | "@continuedev/config-types": "^1.0.13", |
| 55 | 55 | "@continuedev/config-yaml": "file:../packages/config-yaml", |
| 56 | - "@continuedev/fetch": "^1.0.13", | |
| 56 | + "@continuedev/fetch": "^1.0.14", | |
| 57 | 57 | "@continuedev/llm-info": "^1.0.8", |
| 58 | - "@continuedev/openai-adapters": "^1.0.32", | |
| 58 | + "@continuedev/openai-adapters": "file:../packages/openai-adapters", | |
| 59 | 59 | "@modelcontextprotocol/sdk": "^1.12.0", |
| 60 | 60 | "@mozilla/readability": "^0.5.0", |
| 61 | 61 | "@octokit/rest": "^20.1.1", |
| @@ -106,7 +106,6 @@ | ||
| 106 | 106 | "sqlite3": "^5.1.7", |
| 107 | 107 | "system-ca": "^1.0.3", |
| 108 | 108 | "tar": "^7.4.3", |
| 109 | - "tree-sitter-structured-text": "^0.0.1", | |
| 110 | 109 | "tree-sitter-wasms": "^0.1.11", |
| 111 | 110 | "uuid": "^9.0.1", |
| 112 | 111 | "vectordb": "^0.4.20", |
| @@ -145,7 +144,6 @@ | ||
| 145 | 144 | "myers-diff": "^2.1.0", |
| 146 | 145 | "onnxruntime-common": "1.14.0", |
| 147 | 146 | "onnxruntime-web": "1.14.0", |
| 148 | - "tree-sitter-cli": "^0.22.5", | |
| 149 | 147 | "ts-jest": "^29.1.1", |
| 150 | 148 | "typescript": "^5.6.3", |
| 151 | 149 | "vitest": "^3.1.4" |
added binary/utils/bundle-binary.js +103 −0
| @@ -0,0 +1,103 @@ | ||
| 1 | +/** | |
| 2 | + * @file Builds the binary for the specified target. It is also intended to run as a child process. | |
| 3 | + */ | |
| 4 | + | |
| 5 | +const { | |
| 6 | + execCmdSync, | |
| 7 | + autodetectPlatformAndArch, | |
| 8 | +} = require("../../scripts/util"); | |
| 9 | +const { downloadRipgrep } = require("./ripgrep"); | |
| 10 | +const { TARGET_TO_LANCEDB } = require("../utils/targets"); | |
| 11 | +const fs = require("fs"); | |
| 12 | +const { | |
| 13 | + downloadSqlite, | |
| 14 | +} = require("../../extensions/vscode/scripts/download-copy-sqlite-esbuild"); | |
| 15 | +const { fork } = require("child_process"); | |
| 16 | + | |
| 17 | +async function downloadNodeSqlite(target, targetDir) { | |
| 18 | + const [currentPlatform, currentArch] = autodetectPlatformAndArch(); | |
| 19 | + | |
| 20 | + // Download and unzip prebuilt sqlite3 binary for the target | |
| 21 | + console.log("[info] Downloading node-sqlite3"); | |
| 22 | + | |
| 23 | + await downloadSqlite(target, `${targetDir}/build.tar.gz`); | |
| 24 | + | |
| 25 | + execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); | |
| 26 | + | |
| 27 | + // Copy to build directory for testing | |
| 28 | + try { | |
| 29 | + const [platform, arch] = target.split("-"); | |
| 30 | + if (platform === currentPlatform && arch === currentArch) { | |
| 31 | + fs.copyFileSync( | |
| 32 | + `${targetDir}/build/Release/node_sqlite3.node`, | |
| 33 | + `build/node_sqlite3.node`, | |
| 34 | + ); | |
| 35 | + } | |
| 36 | + } catch (error) { | |
| 37 | + console.log("[warn] Could not copy node_sqlite to build"); | |
| 38 | + console.log(error); | |
| 39 | + } | |
| 40 | + fs.unlinkSync(`${targetDir}/build.tar.gz`); | |
| 41 | +} | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * @param {string} target the platform to build for | |
| 45 | + */ | |
| 46 | +async function bundleForBinary(target) { | |
| 47 | + const targetDir = `bin/${target}`; | |
| 48 | + fs.mkdirSync(targetDir, { recursive: true }); | |
| 49 | + console.log(`[info] Building ${target}...`); | |
| 50 | + execCmdSync( | |
| 51 | + `npx pkg --no-bytecode --public-packages "*" --public --compress GZip pkgJson/${target} --out-path ${targetDir}`, | |
| 52 | + ); | |
| 53 | + | |
| 54 | + // copy @lancedb to bin folders | |
| 55 | + console.log("[info] Copying @lancedb files to bin"); | |
| 56 | + fs.copyFileSync( | |
| 57 | + `node_modules/${TARGET_TO_LANCEDB[target]}/index.node`, | |
| 58 | + `${targetDir}/index.node`, | |
| 59 | + ); | |
| 60 | + | |
| 61 | + const downloadPromises = []; | |
| 62 | + downloadPromises.push(downloadRipgrep(target, targetDir)); | |
| 63 | + downloadPromises.push(downloadNodeSqlite(target, targetDir)); | |
| 64 | + await Promise.all(downloadPromises); | |
| 65 | + | |
| 66 | + // Informs the `continue-binary` of where to look for node_sqlite3.node | |
| 67 | + // https://www.npmjs.com/package/bindings#:~:text=The%20searching%20for,file%20is%20found | |
| 68 | + fs.writeFileSync(`${targetDir}/package.json`, ""); | |
| 69 | +} | |
| 70 | + | |
| 71 | +process.on("message", (msg) => { | |
| 72 | + bundleForBinary(msg.payload.target) | |
| 73 | + .then(() => process.send({ done: true })) | |
| 74 | + .catch((error) => { | |
| 75 | + console.error(error); // show the error in the parent process | |
| 76 | + process.send({ error: true }); | |
| 77 | + }); | |
| 78 | +}); | |
| 79 | + | |
| 80 | +/** | |
| 81 | + * @param {string} target the platform to bundle for | |
| 82 | + */ | |
| 83 | +async function bundleBinary(target) { | |
| 84 | + const child = fork(__filename, { stdio: "inherit" }); | |
| 85 | + child.send({ | |
| 86 | + payload: { | |
| 87 | + target, | |
| 88 | + }, | |
| 89 | + }); | |
| 90 | + return new Promise((resolve, reject) => { | |
| 91 | + child.on("message", (msg) => { | |
| 92 | + if (msg.error) { | |
| 93 | + reject(); | |
| 94 | + } else { | |
| 95 | + resolve(); | |
| 96 | + } | |
| 97 | + }); | |
| 98 | + }); | |
| 99 | +} | |
| 100 | + | |
| 101 | +module.exports = { | |
| 102 | + bundleBinary, | |
| 103 | +}; |
modified core/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified core/package.json +1 −1
| @@ -53,7 +53,7 @@ | ||
| 53 | 53 | "@continuedev/config-yaml": "file:../packages/config-yaml", |
| 54 | 54 | "@continuedev/fetch": "^1.0.14", |
| 55 | 55 | "@continuedev/llm-info": "^1.0.8", |
| 56 | - "@continuedev/openai-adapters": "1.0.42", | |
| 56 | + "@continuedev/openai-adapters": "file:../packages/openai-adapters", | |
| 57 | 57 | "@modelcontextprotocol/sdk": "^1.12.0", |
| 58 | 58 | "@mozilla/readability": "^0.5.0", |
| 59 | 59 | "@octokit/rest": "^20.1.1", |
added core/rules.md +10 −0
| @@ -0,0 +1,10 @@ | ||
| 1 | +# `core` rules | |
| 2 | + | |
| 3 | +Whenever a new protocol message is added to the `protocol/` directory, check the following: | |
| 4 | + | |
| 5 | +- It's type is defined correctly | |
| 6 | +- If it is a message from webview to core or vice versa: | |
| 7 | + - It has been added to `core/protocol/passThrough.ts` | |
| 8 | + - It has been added to `extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt` | |
| 9 | +- It is implemented in either `core/core.ts` (for messages to the core), in a `useWebviewListener` (for messages to the gui), or in `VsCodeMessenger.ts` for VS Code or `IdeProtocolClient.kt` for JetBriains (for messages to the IDE). | |
| 10 | +- It does not duplicate functionality from another message type that already exists. |
modified extensions/vscode/.gitignore +1 −0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | exe |
| 10 | 10 | bin |
| 11 | 11 | assets |
| 12 | +tmp | |
| 12 | 13 | |
| 13 | 14 | gui/** |
| 14 | 15 |
modified extensions/vscode/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
added extensions/vscode/scripts/download-copy-sqlite-esbuild.js +191 −0
| @@ -0,0 +1,191 @@ | ||
| 1 | +const { fork } = require("child_process"); | |
| 2 | +const fs = require("fs"); | |
| 3 | +const https = require("https"); | |
| 4 | +const path = require("path"); | |
| 5 | + | |
| 6 | +const { rimrafSync } = require("rimraf"); | |
| 7 | + | |
| 8 | +const { execCmdSync } = require("../../../scripts/util"); | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * download a file using nodejs http | |
| 12 | + * @param {string} url | |
| 13 | + * @param {string} outputPath | |
| 14 | + * @param {number} maxRedirects | |
| 15 | + */ | |
| 16 | +async function downloadFile(url, outputPath, maxRedirects = 5) { | |
| 17 | + return new Promise((resolve, reject) => { | |
| 18 | + const downloadWithRedirects = (currentUrl, redirectCount = 0) => { | |
| 19 | + if (redirectCount > maxRedirects) { | |
| 20 | + return reject(new Error(`Too many redirects (${maxRedirects})`)); | |
| 21 | + } | |
| 22 | + | |
| 23 | + const request = https.get(currentUrl, (response) => { | |
| 24 | + if ( | |
| 25 | + response.statusCode >= 300 && | |
| 26 | + response.statusCode < 400 && | |
| 27 | + response.headers.location | |
| 28 | + ) { | |
| 29 | + return downloadWithRedirects( | |
| 30 | + response.headers.location, | |
| 31 | + redirectCount + 1, | |
| 32 | + ); | |
| 33 | + } | |
| 34 | + | |
| 35 | + if (response.statusCode !== 200) { | |
| 36 | + return reject( | |
| 37 | + new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`), | |
| 38 | + ); | |
| 39 | + } | |
| 40 | + | |
| 41 | + const outputDir = path.dirname(outputPath); | |
| 42 | + if (!fs.existsSync(outputDir)) { | |
| 43 | + fs.mkdirSync(outputDir, { recursive: true }); | |
| 44 | + } | |
| 45 | + | |
| 46 | + const writeStream = fs.createWriteStream(outputPath); | |
| 47 | + | |
| 48 | + const totalSize = parseInt(response.headers["content-length"], 10); | |
| 49 | + let downloadedSize = 0; | |
| 50 | + | |
| 51 | + response.on("data", (chunk) => { | |
| 52 | + downloadedSize += chunk.length; | |
| 53 | + if (totalSize) { | |
| 54 | + const percent = ((downloadedSize / totalSize) * 100).toFixed(1); | |
| 55 | + process.stdout.write( | |
| 56 | + `\rDownloading: ${percent}% (${downloadedSize}/${totalSize} bytes)`, | |
| 57 | + ); | |
| 58 | + } | |
| 59 | + }); | |
| 60 | + | |
| 61 | + response.pipe(writeStream); | |
| 62 | + | |
| 63 | + writeStream.on("finish", () => { | |
| 64 | + console.log(`\nDownload completed: ${outputPath}`); | |
| 65 | + resolve(outputPath); | |
| 66 | + }); | |
| 67 | + | |
| 68 | + writeStream.on("error", reject); | |
| 69 | + response.on("error", reject); | |
| 70 | + }); | |
| 71 | + | |
| 72 | + request.on("error", reject); | |
| 73 | + request.setTimeout(30000, () => { | |
| 74 | + request.destroy(); | |
| 75 | + reject(new Error("Request timeout")); | |
| 76 | + }); | |
| 77 | + }; | |
| 78 | + | |
| 79 | + downloadWithRedirects(url); | |
| 80 | + }); | |
| 81 | +} | |
| 82 | + | |
| 83 | +/** | |
| 84 | + * | |
| 85 | + * @param {string} target platform specific target | |
| 86 | + * @param {string} targetDir the directory to download into | |
| 87 | + */ | |
| 88 | +async function downloadSqlite(target, targetDir) { | |
| 89 | + const downloadUrl = | |
| 90 | + // node-sqlite3 doesn't have a pre-built binary for win32-arm64 | |
| 91 | + target === "win32-arm64" | |
| 92 | + ? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz" | |
| 93 | + : `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${ | |
| 94 | + target | |
| 95 | + }.tar.gz`; | |
| 96 | + await downloadFile(downloadUrl, targetDir); | |
| 97 | +} | |
| 98 | + | |
| 99 | +async function installAndCopySqlite(target) { | |
| 100 | + // Replace the installed with pre-built | |
| 101 | + console.log("[info] Downloading pre-built sqlite3 binary"); | |
| 102 | + rimrafSync("../../core/node_modules/sqlite3/build"); | |
| 103 | + await downloadSqlite(target, "../../core/node_modules/sqlite3/build.tar.gz"); | |
| 104 | + execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz"); | |
| 105 | + fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz"); | |
| 106 | +} | |
| 107 | + | |
| 108 | +async function installAndCopyEsbuild(target) { | |
| 109 | + // Download and unzip esbuild | |
| 110 | + console.log("[info] Downloading pre-built esbuild binary"); | |
| 111 | + rimrafSync("node_modules/@esbuild"); | |
| 112 | + fs.mkdirSync("node_modules/@esbuild", { recursive: true }); | |
| 113 | + await downloadFile( | |
| 114 | + `https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`, | |
| 115 | + "node_modules/@esbuild/esbuild.zip", | |
| 116 | + ); | |
| 117 | + execCmdSync("cd node_modules/@esbuild && unzip esbuild.zip"); | |
| 118 | + fs.unlinkSync("node_modules/@esbuild/esbuild.zip"); | |
| 119 | +} | |
| 120 | + | |
| 121 | +process.on("message", (msg) => { | |
| 122 | + const { operation, target } = msg.payload; | |
| 123 | + if (operation === "sqlite") { | |
| 124 | + installAndCopySqlite(target) | |
| 125 | + .then(() => process.send({ done: true })) | |
| 126 | + .catch((error) => { | |
| 127 | + console.error(error); // show the error in the parent process | |
| 128 | + process.send({ error: true }); | |
| 129 | + }); | |
| 130 | + } | |
| 131 | + if (operation === "esbuild") { | |
| 132 | + installAndCopyEsbuild(target) | |
| 133 | + .then(() => process.send({ done: true })) | |
| 134 | + .catch((error) => { | |
| 135 | + console.error(error); // show the error in the parent process | |
| 136 | + process.send({ error: true }); | |
| 137 | + }); | |
| 138 | + } | |
| 139 | +}); | |
| 140 | + | |
| 141 | +/** | |
| 142 | + * @param {string} target the platform to build for | |
| 143 | + */ | |
| 144 | +async function copySqlite(target) { | |
| 145 | + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); | |
| 146 | + child.send({ | |
| 147 | + payload: { | |
| 148 | + operation: "sqlite", | |
| 149 | + target, | |
| 150 | + }, | |
| 151 | + }); | |
| 152 | + | |
| 153 | + return new Promise((resolve, reject) => { | |
| 154 | + child.on("message", (msg) => { | |
| 155 | + if (msg.error) { | |
| 156 | + reject(); | |
| 157 | + } else { | |
| 158 | + resolve(); | |
| 159 | + } | |
| 160 | + }); | |
| 161 | + }); | |
| 162 | +} | |
| 163 | + | |
| 164 | +/** | |
| 165 | + * @param {string} target the platform to build for | |
| 166 | + */ | |
| 167 | +async function copyEsbuild(target) { | |
| 168 | + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); | |
| 169 | + child.send({ | |
| 170 | + payload: { | |
| 171 | + operation: "esbuild", | |
| 172 | + target, | |
| 173 | + }, | |
| 174 | + }); | |
| 175 | + | |
| 176 | + return new Promise((resolve, reject) => { | |
| 177 | + child.on("message", (msg) => { | |
| 178 | + if (msg.error) { | |
| 179 | + reject(); | |
| 180 | + } else { | |
| 181 | + resolve(); | |
| 182 | + } | |
| 183 | + }); | |
| 184 | + }); | |
| 185 | +} | |
| 186 | + | |
| 187 | +module.exports = { | |
| 188 | + downloadSqlite, | |
| 189 | + copySqlite, | |
| 190 | + copyEsbuild, | |
| 191 | +}; |
modified extensions/vscode/scripts/esbuild.js +2 −1
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | const fs = require("fs"); |
| 2 | + | |
| 2 | 3 | const { writeBuildTimestamp } = require("./utils"); |
| 3 | 4 | |
| 4 | 5 | const esbuild = require("esbuild"); |
| @@ -49,7 +50,7 @@ | ||
| 49 | 50 | ], |
| 50 | 51 | }; |
| 51 | 52 | |
| 52 | -(async () => { | |
| 53 | +void (async () => { | |
| 53 | 54 | // Create .buildTimestamp.js before starting the first build |
| 54 | 55 | writeBuildTimestamp(); |
| 55 | 56 | // Bundles the extension into one file |
added extensions/vscode/scripts/generate-copy-config.js +126 −0
| @@ -0,0 +1,126 @@ | ||
| 1 | +/** | |
| 2 | + * @file Generate config.yaml file from template. Also intended to run as a child process. | |
| 3 | + */ | |
| 4 | + | |
| 5 | +const { fork } = require("child_process"); | |
| 6 | +const fs = require("fs"); | |
| 7 | +const path = require("path"); | |
| 8 | + | |
| 9 | +const { execCmdSync } = require("../../../scripts/util"); | |
| 10 | + | |
| 11 | +const { continueDir } = require("./utils"); | |
| 12 | + | |
| 13 | +async function generateConfigYamlSchema() { | |
| 14 | + process.chdir(path.join(continueDir, "packages", "config-yaml")); | |
| 15 | + execCmdSync("npm install"); | |
| 16 | + execCmdSync("npm run build"); | |
| 17 | + execCmdSync("npm run generate-schema"); | |
| 18 | + fs.copyFileSync( | |
| 19 | + path.join("schema", "config-yaml-schema.json"), | |
| 20 | + path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"), | |
| 21 | + ); | |
| 22 | + console.log("[info] Generated config.yaml schema"); | |
| 23 | +} | |
| 24 | + | |
| 25 | +async function copyConfigSchema() { | |
| 26 | + process.chdir(path.join(continueDir, "extensions", "vscode")); | |
| 27 | + // Modify and copy for .continuerc.json | |
| 28 | + const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8")); | |
| 29 | + schema.$defs.SerializedContinueConfig.properties.mergeBehavior = { | |
| 30 | + type: "string", | |
| 31 | + enum: ["merge", "overwrite"], | |
| 32 | + default: "merge", | |
| 33 | + title: "Merge behavior", | |
| 34 | + markdownDescription: | |
| 35 | + "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json.", | |
| 36 | + "x-intellij-html-description": | |
| 37 | + "<p>If set to <code>merge</code>, <code>.continuerc.json</code> will be applied on top of <code>config.json</code> (arrays and objects are merged). If set to <code>overwrite</code>, then every top-level property of <code>.continuerc.json</code> will overwrite that property from <code>config.json</code>.</p>", | |
| 38 | + }; | |
| 39 | + fs.writeFileSync("continue_rc_schema.json", JSON.stringify(schema, null, 2)); | |
| 40 | + | |
| 41 | + // Copy config schemas to intellij | |
| 42 | + fs.copyFileSync( | |
| 43 | + "config_schema.json", | |
| 44 | + path.join( | |
| 45 | + "..", | |
| 46 | + "intellij", | |
| 47 | + "src", | |
| 48 | + "main", | |
| 49 | + "resources", | |
| 50 | + "config_schema.json", | |
| 51 | + ), | |
| 52 | + ); | |
| 53 | + fs.copyFileSync( | |
| 54 | + "continue_rc_schema.json", | |
| 55 | + path.join( | |
| 56 | + "..", | |
| 57 | + "intellij", | |
| 58 | + "src", | |
| 59 | + "main", | |
| 60 | + "resources", | |
| 61 | + "continue_rc_schema.json", | |
| 62 | + ), | |
| 63 | + ); | |
| 64 | +} | |
| 65 | + | |
| 66 | +process.on("message", (msg) => { | |
| 67 | + const { operation } = msg.payload; | |
| 68 | + if (operation === "generate") { | |
| 69 | + generateConfigYamlSchema() | |
| 70 | + .then(() => process.send({ done: true })) | |
| 71 | + .catch((error) => { | |
| 72 | + console.error(error); // show the error in the parent process | |
| 73 | + process.send({ error: true }); | |
| 74 | + }); | |
| 75 | + } | |
| 76 | + if (operation === "copy") { | |
| 77 | + copyConfigSchema() | |
| 78 | + .then(() => process.send({ done: true })) | |
| 79 | + .catch((error) => { | |
| 80 | + console.error(error); // show the error in the parent process | |
| 81 | + process.send({ error: true }); | |
| 82 | + }); | |
| 83 | + } | |
| 84 | +}); | |
| 85 | + | |
| 86 | +async function generateAndCopyConfigYamlSchema() { | |
| 87 | + // Generate and copy over config-yaml-schema.json | |
| 88 | + const generateConfigYamlChild = fork( | |
| 89 | + path.join(__dirname, "generate-copy-config.js"), | |
| 90 | + { | |
| 91 | + stdio: "inherit", | |
| 92 | + }, | |
| 93 | + ); | |
| 94 | + generateConfigYamlChild.send({ payload: { operation: "generate" } }); | |
| 95 | + | |
| 96 | + await new Promise((resolve, reject) => { | |
| 97 | + generateConfigYamlChild.on("message", (msg) => { | |
| 98 | + if (msg.error) { | |
| 99 | + reject(); | |
| 100 | + } | |
| 101 | + resolve(); | |
| 102 | + }); | |
| 103 | + }); | |
| 104 | + | |
| 105 | + // Copy config schemas to intellij | |
| 106 | + const copyConfigSchemaChild = fork( | |
| 107 | + path.join(__dirname, "generate-copy-config.js"), | |
| 108 | + { | |
| 109 | + stdio: "inherit", | |
| 110 | + }, | |
| 111 | + ); | |
| 112 | + copyConfigSchemaChild.send({ payload: { operation: "copy" } }); | |
| 113 | + | |
| 114 | + await new Promise((resolve, reject) => { | |
| 115 | + copyConfigSchemaChild.on("message", (msg) => { | |
| 116 | + if (msg.error) { | |
| 117 | + reject(); | |
| 118 | + } | |
| 119 | + resolve(); | |
| 120 | + }); | |
| 121 | + }); | |
| 122 | +} | |
| 123 | + | |
| 124 | +module.exports = { | |
| 125 | + generateAndCopyConfigYamlSchema, | |
| 126 | +}; |
added extensions/vscode/scripts/install-copy-nodemodule.js +113 −0
| @@ -0,0 +1,113 @@ | ||
| 1 | +/** | |
| 2 | + * @file Copy lancedb to the current directory. It is also intended to run as a child process. | |
| 3 | + */ | |
| 4 | + | |
| 5 | +const { fork } = require("child_process"); | |
| 6 | +const fs = require("fs"); | |
| 7 | +const path = require("path"); | |
| 8 | + | |
| 9 | +const ncp = require("ncp").ncp; | |
| 10 | + | |
| 11 | +const { execCmdSync } = require("../../../scripts/util"); | |
| 12 | + | |
| 13 | +async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { | |
| 14 | + console.log(`Copying ${packageName} to ${toCopy}`); | |
| 15 | + // This is a way to install only one package without npm trying to install all the dependencies | |
| 16 | + // Create a temporary directory for installing the package | |
| 17 | + const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); | |
| 18 | + const currentDir = process.cwd(); | |
| 19 | + const tempDir = path.join( | |
| 20 | + currentDir, | |
| 21 | + "tmp", | |
| 22 | + `continue-node_modules-${adjustedName}`, | |
| 23 | + ); | |
| 24 | + | |
| 25 | + // // Remove the dir we will be copying to | |
| 26 | + // rimrafSync(`node_modules/${toCopy}`); | |
| 27 | + | |
| 28 | + // // Ensure the temporary directory exists | |
| 29 | + fs.mkdirSync(tempDir, { recursive: true }); | |
| 30 | + | |
| 31 | + try { | |
| 32 | + // Move to the temporary directory | |
| 33 | + process.chdir(tempDir); | |
| 34 | + | |
| 35 | + // Initialize a new package.json and install the package | |
| 36 | + execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`); | |
| 37 | + | |
| 38 | + console.log( | |
| 39 | + `Contents of: ${packageName}`, | |
| 40 | + fs.readdirSync(path.join(tempDir, "node_modules", toCopy)), | |
| 41 | + ); | |
| 42 | + | |
| 43 | + // Without this it seems the file isn't completely written to disk | |
| 44 | + await new Promise((resolve) => setTimeout(resolve, 2000)); | |
| 45 | + | |
| 46 | + // Copy the installed package back to the current directory | |
| 47 | + await new Promise((resolve, reject) => { | |
| 48 | + ncp( | |
| 49 | + path.join(tempDir, "node_modules", toCopy), | |
| 50 | + path.join(currentDir, "node_modules", toCopy), | |
| 51 | + { dereference: true }, | |
| 52 | + (error) => { | |
| 53 | + if (error) { | |
| 54 | + console.error( | |
| 55 | + `[error] Error copying ${packageName} package`, | |
| 56 | + error, | |
| 57 | + ); | |
| 58 | + reject(error); | |
| 59 | + } else { | |
| 60 | + resolve(); | |
| 61 | + } | |
| 62 | + }, | |
| 63 | + ); | |
| 64 | + }); | |
| 65 | + } finally { | |
| 66 | + // Clean up the temporary directory | |
| 67 | + // rimrafSync(tempDir); | |
| 68 | + | |
| 69 | + // Return to the original directory | |
| 70 | + process.chdir(currentDir); | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 74 | +process.on("message", (msg) => { | |
| 75 | + installNodeModuleInTempDirAndCopyToCurrent( | |
| 76 | + msg.payload.packageName, | |
| 77 | + msg.payload.toCopy, | |
| 78 | + ) | |
| 79 | + .then(() => process.send({ done: true })) | |
| 80 | + .catch((error) => { | |
| 81 | + console.error(error); // show the error in the parent process | |
| 82 | + process.send({ error: true }); | |
| 83 | + }); | |
| 84 | +}); | |
| 85 | + | |
| 86 | +/** | |
| 87 | + * invoke a child process to install a node module into temporary directory and copy it over into node modules | |
| 88 | + * @param {string} packageName the module to install and copy | |
| 89 | + * @param {string} toCopy directory to copy into inside node modules | |
| 90 | + */ | |
| 91 | +async function installAndCopyNodeModules(packageName, toCopy) { | |
| 92 | + const child = fork(__filename, { stdio: "inherit", cwd: process.cwd() }); | |
| 93 | + child.send({ | |
| 94 | + payload: { | |
| 95 | + packageName, | |
| 96 | + toCopy, | |
| 97 | + }, | |
| 98 | + }); | |
| 99 | + | |
| 100 | + return new Promise((resolve, reject) => { | |
| 101 | + child.on("message", (msg) => { | |
| 102 | + if (msg.error) { | |
| 103 | + reject(); | |
| 104 | + } else { | |
| 105 | + resolve(); | |
| 106 | + } | |
| 107 | + }); | |
| 108 | + }); | |
| 109 | +} | |
| 110 | + | |
| 111 | +module.exports = { | |
| 112 | + installAndCopyNodeModules, | |
| 113 | +}; |
added extensions/vscode/scripts/npm-install.js +79 −0
| @@ -0,0 +1,79 @@ | ||
| 1 | +/** | |
| 2 | + * @file Install node modules for the VS Code extension and gui. This is also intended to run as a child process. | |
| 3 | + */ | |
| 4 | + | |
| 5 | +const { fork } = require("child_process"); | |
| 6 | +const path = require("path"); | |
| 7 | + | |
| 8 | +const { execCmdSync } = require("../../../scripts/util"); | |
| 9 | + | |
| 10 | +const { continueDir } = require("./utils"); | |
| 11 | + | |
| 12 | +async function installNodeModulesInGui() { | |
| 13 | + process.chdir(path.join(continueDir, "gui")); | |
| 14 | + execCmdSync("npm install"); | |
| 15 | + console.log("[info] npm install in gui completed"); | |
| 16 | +} | |
| 17 | + | |
| 18 | +async function installNodeModulesInVscode() { | |
| 19 | + process.chdir(path.join(continueDir, "extensions", "vscode")); | |
| 20 | + execCmdSync("npm install"); | |
| 21 | + console.log("[info] npm install in extensions/vscode completed"); | |
| 22 | +} | |
| 23 | + | |
| 24 | +process.on("message", (msg) => { | |
| 25 | + const { targetDir } = msg.payload; | |
| 26 | + if (targetDir === "gui") { | |
| 27 | + installNodeModulesInGui() | |
| 28 | + .then(() => process.send({ done: true })) | |
| 29 | + .catch((error) => { | |
| 30 | + console.error(error); // show the error in the parent process | |
| 31 | + process.send({ error: true }); | |
| 32 | + }); | |
| 33 | + } else if (targetDir === "vscode") { | |
| 34 | + installNodeModulesInVscode() | |
| 35 | + .then(() => process.send({ done: true })) | |
| 36 | + .catch((error) => { | |
| 37 | + console.error(error); // show the error in the parent process | |
| 38 | + process.send({ error: true }); | |
| 39 | + }); | |
| 40 | + } | |
| 41 | +}); | |
| 42 | + | |
| 43 | +async function npmInstall() { | |
| 44 | + const installVscodeChild = fork(__filename, { | |
| 45 | + stdio: "inherit", | |
| 46 | + }); | |
| 47 | + installVscodeChild.send({ payload: { targetDir: "vscode" } }); | |
| 48 | + | |
| 49 | + const installGuiChild = fork(__filename, { | |
| 50 | + stdio: "inherit", | |
| 51 | + }); | |
| 52 | + installGuiChild.send({ payload: { targetDir: "gui" } }); | |
| 53 | + | |
| 54 | + await Promise.all([ | |
| 55 | + new Promise((resolve, reject) => { | |
| 56 | + installVscodeChild.on("message", (msg) => { | |
| 57 | + if (msg.error) { | |
| 58 | + reject(); | |
| 59 | + } | |
| 60 | + resolve(); | |
| 61 | + }); | |
| 62 | + }), | |
| 63 | + new Promise((resolve, reject) => { | |
| 64 | + installGuiChild.on("message", (msg) => { | |
| 65 | + if (msg.error) { | |
| 66 | + reject(); | |
| 67 | + } | |
| 68 | + resolve(); | |
| 69 | + }); | |
| 70 | + }), | |
| 71 | + ]).catch((error) => { | |
| 72 | + console.error(error); | |
| 73 | + process.exit(1); | |
| 74 | + }); | |
| 75 | +} | |
| 76 | + | |
| 77 | +module.exports = { | |
| 78 | + npmInstall, | |
| 79 | +}; |
modified extensions/vscode/scripts/prepackage.js +37 −137
| @@ -10,11 +10,11 @@ | ||
| 10 | 10 | autodetectPlatformAndArch, |
| 11 | 11 | } = require("../../../scripts/util/index"); |
| 12 | 12 | |
| 13 | -const { | |
| 14 | - copyConfigSchema, | |
| 15 | - writeBuildTimestamp, | |
| 16 | - generateConfigYamlSchema, | |
| 17 | -} = require("./utils"); | |
| 13 | +const { copySqlite, copyEsbuild } = require("./download-copy-sqlite-esbuild"); | |
| 14 | +const { generateAndCopyConfigYamlSchema } = require("./generate-copy-config"); | |
| 15 | +const { installAndCopyNodeModules } = require("./install-copy-nodemodule"); | |
| 16 | +const { npmInstall } = require("./npm-install"); | |
| 17 | +const { writeBuildTimestamp, continueDir } = require("./utils"); | |
| 18 | 18 | |
| 19 | 19 | // Clear folders that will be packaged to ensure clean slate |
| 20 | 20 | rimrafSync(path.join(__dirname, "..", "bin")); |
| @@ -27,6 +27,8 @@ | ||
| 27 | 27 | fs.mkdirSync(guiDist, { recursive: true }); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | +const skipInstalls = process.env.SKIP_INSTALLS === "true"; | |
| 31 | + | |
| 30 | 32 | // Get the target to package for |
| 31 | 33 | let target = undefined; |
| 32 | 34 | const args = process.argv; |
| @@ -36,10 +38,10 @@ | ||
| 36 | 38 | |
| 37 | 39 | let os; |
| 38 | 40 | let arch; |
| 39 | -if (!target) { | |
| 40 | - [os, arch] = autodetectPlatformAndArch(); | |
| 41 | -} else { | |
| 41 | +if (target) { | |
| 42 | 42 | [os, arch] = target.split("-"); |
| 43 | +} else { | |
| 44 | + [os, arch] = autodetectPlatformAndArch(); | |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | if (os === "alpine") { |
| @@ -67,28 +69,14 @@ | ||
| 67 | 69 | void (async () => { |
| 68 | 70 | console.log("[info] Packaging extension for target ", target); |
| 69 | 71 | |
| 70 | - // Generate and copy over config-yaml-schema.json | |
| 71 | - generateConfigYamlSchema(); | |
| 72 | - | |
| 73 | - // Copy config schemas to intellij | |
| 74 | - copyConfigSchema(); | |
| 75 | - | |
| 76 | - if (!process.cwd().endsWith("vscode")) { | |
| 77 | - // This is sometimes run from root dir instead (e.g. in VS Code tasks) | |
| 78 | - process.chdir("extensions/vscode"); | |
| 79 | - } | |
| 80 | - | |
| 81 | 72 | // Make sure we have an initial timestamp file |
| 82 | 73 | writeBuildTimestamp(); |
| 83 | 74 | |
| 84 | - // Install node_modules // | |
| 85 | - execCmdSync("npm install"); | |
| 86 | - console.log("[info] npm install in extensions/vscode completed"); | |
| 87 | - | |
| 88 | - process.chdir("../../gui"); | |
| 75 | + if (!skipInstalls) { | |
| 76 | + await Promise.all([generateAndCopyConfigYamlSchema(), npmInstall()]); | |
| 77 | + } | |
| 89 | 78 | |
| 90 | - execCmdSync("npm install"); | |
| 91 | - console.log("[info] npm install in gui completed"); | |
| 79 | + process.chdir(path.join(continueDir, "gui")); | |
| 92 | 80 | |
| 93 | 81 | if (isInGitHubAction) { |
| 94 | 82 | execCmdSync("npm run build"); |
| @@ -280,122 +268,32 @@ | ||
| 280 | 268 | ); |
| 281 | 269 | }); |
| 282 | 270 | |
| 283 | - async function installNodeModuleInTempDirAndCopyToCurrent( | |
| 284 | - packageName, | |
| 285 | - toCopy, | |
| 286 | - ) { | |
| 287 | - console.log(`Copying ${packageName} to ${toCopy}`); | |
| 288 | - // This is a way to install only one package without npm trying to install all the dependencies | |
| 289 | - // Create a temporary directory for installing the package | |
| 290 | - const adjustedName = packageName.replace(/@/g, "").replace("/", "-"); | |
| 291 | - | |
| 292 | - const tempDir = `/tmp/continue-node_modules-${adjustedName}`; | |
| 293 | - const currentDir = process.cwd(); | |
| 294 | - | |
| 295 | - // Remove the dir we will be copying to | |
| 296 | - rimrafSync(`node_modules/${toCopy}`); | |
| 297 | - | |
| 298 | - // Ensure the temporary directory exists | |
| 299 | - fs.mkdirSync(tempDir, { recursive: true }); | |
| 300 | - | |
| 301 | - try { | |
| 302 | - // Move to the temporary directory | |
| 303 | - process.chdir(tempDir); | |
| 304 | - | |
| 305 | - // Initialize a new package.json and install the package | |
| 306 | - execCmdSync(`npm init -y && npm i -f ${packageName} --no-save`); | |
| 307 | - | |
| 271 | + if (!skipInstalls) { | |
| 272 | + // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries | |
| 273 | + // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions | |
| 274 | + if (isArmTarget) { | |
| 275 | + // lancedb binary | |
| 276 | + const packageToInstall = { | |
| 277 | + "darwin-arm64": "@lancedb/vectordb-darwin-arm64", | |
| 278 | + "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu", | |
| 279 | + "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc", | |
| 280 | + }[target]; | |
| 308 | 281 | console.log( |
| 309 | - `Contents of: ${packageName}`, | |
| 310 | - fs.readdirSync(path.join(tempDir, "node_modules", toCopy)), | |
| 282 | + "[info] Downloading pre-built lancedb binary: " + packageToInstall, | |
| 311 | 283 | ); |
| 312 | 284 | |
| 313 | - // Without this it seems the file isn't completely written to disk | |
| 314 | - // Ideally we validate file integrity in the validation at the end | |
| 315 | - await new Promise((resolve) => setTimeout(resolve, 2000)); | |
| 316 | - | |
| 317 | - // Copy the installed package back to the current directory | |
| 318 | - await new Promise((resolve, reject) => { | |
| 319 | - ncp( | |
| 320 | - path.join(tempDir, "node_modules", toCopy), | |
| 321 | - path.join(currentDir, "node_modules", toCopy), | |
| 322 | - { dereference: true }, | |
| 323 | - (error) => { | |
| 324 | - if (error) { | |
| 325 | - console.error( | |
| 326 | - `[error] Error copying ${packageName} package`, | |
| 327 | - error, | |
| 328 | - ); | |
| 329 | - reject(error); | |
| 330 | - } else { | |
| 331 | - resolve(); | |
| 332 | - } | |
| 333 | - }, | |
| 334 | - ); | |
| 335 | - }); | |
| 336 | - } finally { | |
| 337 | - // Clean up the temporary directory | |
| 338 | - // rimrafSync(tempDir); | |
| 339 | - | |
| 340 | - // Return to the original directory | |
| 341 | - process.chdir(currentDir); | |
| 285 | + await Promise.all([ | |
| 286 | + copyEsbuild(target), | |
| 287 | + copySqlite(target), | |
| 288 | + installAndCopyNodeModules(packageToInstall, "@lancedb"), | |
| 289 | + ]); | |
| 290 | + } else { | |
| 291 | + // Download esbuild from npm in tmp and copy over | |
| 292 | + console.log("[info] npm installing esbuild binary"); | |
| 293 | + await installAndCopyNodeModules("esbuild@0.17.19", "@esbuild"); | |
| 342 | 294 | } |
| 343 | 295 | } |
| 344 | 296 | |
| 345 | - // GitHub Actions doesn't support ARM, so we need to download pre-saved binaries | |
| 346 | - // 02/07/25 - the above comment is out of date, there is now support for ARM runners on GitHub Actions | |
| 347 | - if (isArmTarget) { | |
| 348 | - // lancedb binary | |
| 349 | - const packageToInstall = { | |
| 350 | - "darwin-arm64": "@lancedb/vectordb-darwin-arm64", | |
| 351 | - "linux-arm64": "@lancedb/vectordb-linux-arm64-gnu", | |
| 352 | - "win32-arm64": "@lancedb/vectordb-win32-arm64-msvc", | |
| 353 | - }[target]; | |
| 354 | - console.log( | |
| 355 | - "[info] Downloading pre-built lancedb binary: " + packageToInstall, | |
| 356 | - ); | |
| 357 | - | |
| 358 | - await installNodeModuleInTempDirAndCopyToCurrent( | |
| 359 | - packageToInstall, | |
| 360 | - "@lancedb", | |
| 361 | - ); | |
| 362 | - | |
| 363 | - // Replace the installed with pre-built | |
| 364 | - console.log("[info] Downloading pre-built sqlite3 binary"); | |
| 365 | - rimrafSync("../../core/node_modules/sqlite3/build"); | |
| 366 | - const downloadUrl = { | |
| 367 | - "darwin-arm64": | |
| 368 | - "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz", | |
| 369 | - "linux-arm64": | |
| 370 | - "https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz", | |
| 371 | - // node-sqlite3 doesn't have a pre-built binary for win32-arm64 | |
| 372 | - "win32-arm64": | |
| 373 | - "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz", | |
| 374 | - }[target]; | |
| 375 | - execCmdSync( | |
| 376 | - `curl -L -o ../../core/node_modules/sqlite3/build.tar.gz ${downloadUrl}`, | |
| 377 | - ); | |
| 378 | - execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz"); | |
| 379 | - fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz"); | |
| 380 | - | |
| 381 | - // Download and unzip esbuild | |
| 382 | - console.log("[info] Downloading pre-built esbuild binary"); | |
| 383 | - rimrafSync("node_modules/@esbuild"); | |
| 384 | - fs.mkdirSync("node_modules/@esbuild", { recursive: true }); | |
| 385 | - execCmdSync( | |
| 386 | - `curl -o node_modules/@esbuild/esbuild.zip https://continue-server-binaries.s3.us-west-1.amazonaws.com/${target}/esbuild.zip`, | |
| 387 | - ); | |
| 388 | - execCmdSync(`cd node_modules/@esbuild && unzip esbuild.zip`); | |
| 389 | - fs.unlinkSync("node_modules/@esbuild/esbuild.zip"); | |
| 390 | - } else { | |
| 391 | - // Download esbuild from npm in tmp and copy over | |
| 392 | - console.log("npm installing esbuild binary"); | |
| 393 | - await installNodeModuleInTempDirAndCopyToCurrent( | |
| 394 | - "esbuild@0.17.19", | |
| 395 | - "@esbuild", | |
| 396 | - ); | |
| 397 | - } | |
| 398 | - | |
| 399 | 297 | console.log("[info] Copying sqlite node binding from core"); |
| 400 | 298 | await new Promise((resolve, reject) => { |
| 401 | 299 | ncp( |
| @@ -465,7 +363,7 @@ | ||
| 465 | 363 | ); |
| 466 | 364 | |
| 467 | 365 | // delete esbuild/bin because platform-specific @esbuild is downloaded |
| 468 | - fs.rmdirSync(`out/node_modules/esbuild/bin`, { recursive: true }); | |
| 366 | + fs.rmSync(`out/node_modules/esbuild/bin`, { recursive: true }); | |
| 469 | 367 | |
| 470 | 368 | console.log(`[info] Copied ${NODE_MODULES_TO_COPY.join(", ")}`); |
| 471 | 369 | |
| @@ -534,4 +432,6 @@ | ||
| 534 | 432 | `out/node_modules/@lancedb/vectordb-${target}${isWinTarget ? "-msvc" : ""}${isLinuxTarget ? "-gnu" : ""}/index.node`, |
| 535 | 433 | `out/node_modules/esbuild/lib/main.js`, |
| 536 | 434 | ]); |
| 435 | + | |
| 436 | + process.exit(0); | |
| 537 | 437 | })(); |
modified extensions/vscode/scripts/utils.js +6 −79
| @@ -1,67 +1,12 @@ | ||
| 1 | 1 | const fs = require("fs"); |
| 2 | -const ncp = require("ncp").ncp; | |
| 3 | 2 | const path = require("path"); |
| 4 | -const { rimrafSync } = require("rimraf"); | |
| 5 | -const { | |
| 6 | - validateFilesPresent, | |
| 7 | - execCmdSync, | |
| 8 | - autodetectPlatformAndArch, | |
| 9 | -} = require("../../../scripts/util/index"); | |
| 10 | 3 | |
| 11 | -const continueDir = path.join(__dirname, "..", "..", ".."); | |
| 4 | +const ncp = require("ncp").ncp; | |
| 5 | +const { rimrafSync } = require("rimraf"); | |
| 12 | 6 | |
| 13 | -function generateConfigYamlSchema() { | |
| 14 | - process.chdir(path.join(continueDir, "packages", "config-yaml")); | |
| 15 | - execCmdSync("npm install"); | |
| 16 | - execCmdSync("npm run build"); | |
| 17 | - execCmdSync("npm run generate-schema"); | |
| 18 | - fs.copyFileSync( | |
| 19 | - path.join("schema", "config-yaml-schema.json"), | |
| 20 | - path.join(continueDir, "extensions", "vscode", "config-yaml-schema.json"), | |
| 21 | - ); | |
| 22 | - console.log("[info] Generated config.yaml schema"); | |
| 23 | -} | |
| 7 | +const { execCmdSync } = require("../../../scripts/util/index"); | |
| 24 | 8 | |
| 25 | -function copyConfigSchema() { | |
| 26 | - process.chdir(path.join(continueDir, "extensions", "vscode")); | |
| 27 | - // Modify and copy for .continuerc.json | |
| 28 | - const schema = JSON.parse(fs.readFileSync("config_schema.json", "utf8")); | |
| 29 | - schema.$defs.SerializedContinueConfig.properties.mergeBehavior = { | |
| 30 | - type: "string", | |
| 31 | - enum: ["merge", "overwrite"], | |
| 32 | - default: "merge", | |
| 33 | - title: "Merge behavior", | |
| 34 | - markdownDescription: | |
| 35 | - "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json.", | |
| 36 | - "x-intellij-html-description": | |
| 37 | - "<p>If set to <code>merge</code>, <code>.continuerc.json</code> will be applied on top of <code>config.json</code> (arrays and objects are merged). If set to <code>overwrite</code>, then every top-level property of <code>.continuerc.json</code> will overwrite that property from <code>config.json</code>.</p>", | |
| 38 | - }; | |
| 39 | - fs.writeFileSync("continue_rc_schema.json", JSON.stringify(schema, null, 2)); | |
| 40 | - | |
| 41 | - // Copy config schemas to intellij | |
| 42 | - fs.copyFileSync( | |
| 43 | - "config_schema.json", | |
| 44 | - path.join( | |
| 45 | - "..", | |
| 46 | - "intellij", | |
| 47 | - "src", | |
| 48 | - "main", | |
| 49 | - "resources", | |
| 50 | - "config_schema.json", | |
| 51 | - ), | |
| 52 | - ); | |
| 53 | - fs.copyFileSync( | |
| 54 | - "continue_rc_schema.json", | |
| 55 | - path.join( | |
| 56 | - "..", | |
| 57 | - "intellij", | |
| 58 | - "src", | |
| 59 | - "main", | |
| 60 | - "resources", | |
| 61 | - "continue_rc_schema.json", | |
| 62 | - ), | |
| 63 | - ); | |
| 64 | -} | |
| 9 | +const continueDir = path.join(__dirname, "..", "..", ".."); | |
| 65 | 10 | |
| 66 | 11 | function copyTokenizers() { |
| 67 | 12 | fs.copyFileSync( |
| @@ -77,22 +22,6 @@ | ||
| 77 | 22 | console.log("[info] Copied llamaTokenizer"); |
| 78 | 23 | } |
| 79 | 24 | |
| 80 | -function installNodeModules() { | |
| 81 | - // Make sure we are in the right directory | |
| 82 | - if (!process.cwd().endsWith("vscode")) { | |
| 83 | - process.chdir(path.join(continueDir, "extensions", "vscode")); | |
| 84 | - } | |
| 85 | - | |
| 86 | - // Install node_modules // | |
| 87 | - execCmdSync("npm install"); | |
| 88 | - console.log("[info] npm install in extensions/vscode completed"); | |
| 89 | - | |
| 90 | - process.chdir(path.join(continueDir, "gui")); | |
| 91 | - | |
| 92 | - execCmdSync("npm install"); | |
| 93 | - console.log("[info] npm install in gui completed"); | |
| 94 | -} | |
| 95 | - | |
| 96 | 25 | async function buildGui(isGhAction) { |
| 97 | 26 | // Make sure we are in the right directory |
| 98 | 27 | if (!process.cwd().endsWith("gui")) { |
| @@ -536,15 +465,13 @@ | ||
| 536 | 465 | // in the build |
| 537 | 466 | function writeBuildTimestamp() { |
| 538 | 467 | fs.writeFileSync( |
| 539 | - "src/.buildTimestamp.ts", | |
| 468 | + path.join(continueDir, "extensions/vscode", "src/.buildTimestamp.ts"), | |
| 540 | 469 | `export default "${new Date().toISOString()}";\n`, |
| 541 | 470 | ); |
| 542 | 471 | } |
| 543 | 472 | |
| 544 | 473 | module.exports = { |
| 545 | - generateConfigYamlSchema, | |
| 546 | - copyConfigSchema, | |
| 547 | - installNodeModules, | |
| 474 | + continueDir, | |
| 548 | 475 | buildGui, |
| 549 | 476 | copyOnnxRuntimeFromNodeModules, |
| 550 | 477 | copyTreeSitterWasms, |
modified gui/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified gui/src/components/StyledMarkdownPreview/StepContainerPreToolbar/index.tsx +15 −13
| @@ -11,8 +11,10 @@ | ||
| 11 | 11 | import { useIdeMessengerRequest } from "../../../hooks/useIdeMessengerRequest"; |
| 12 | 12 | import { useWebviewListener } from "../../../hooks/useWebviewListener"; |
| 13 | 13 | import { useAppSelector } from "../../../redux/hooks"; |
| 14 | -import { selectCurrentToolCallApplyState } from "../../../redux/selectors/selectCurrentToolCall"; | |
| 15 | -import { selectApplyStateByStreamId } from "../../../redux/slices/sessionSlice"; | |
| 14 | +import { | |
| 15 | + selectApplyStateByStreamId, | |
| 16 | + selectApplyStateByToolCallId, | |
| 17 | +} from "../../../redux/slices/sessionSlice"; | |
| 16 | 18 | import { getFontSize } from "../../../util"; |
| 17 | 19 | import Spinner from "../../gui/Spinner"; |
| 18 | 20 | import { isTerminalCodeBlock } from "../utils"; |
| @@ -54,6 +56,7 @@ | ||
| 54 | 56 | codeBlockIndex: number; // To track which codeblock we are applying |
| 55 | 57 | isLastCodeblock: boolean; |
| 56 | 58 | codeBlockStreamId: string; |
| 59 | + forceToolCallId?: string; // If this is defined, we will use this streamId instead of the one from the codeBlock | |
| 57 | 60 | range?: string; |
| 58 | 61 | children: any; |
| 59 | 62 | expanded?: boolean; |
| @@ -68,6 +71,7 @@ | ||
| 68 | 71 | codeBlockIndex, |
| 69 | 72 | isLastCodeblock, |
| 70 | 73 | codeBlockStreamId, |
| 74 | + forceToolCallId, | |
| 71 | 75 | range, |
| 72 | 76 | children, |
| 73 | 77 | expanded, |
| @@ -99,8 +103,8 @@ | ||
| 99 | 103 | const applyState = useAppSelector((state) => |
| 100 | 104 | selectApplyStateByStreamId(state, codeBlockStreamId), |
| 101 | 105 | ); |
| 102 | - const currentToolCallApplyState = useAppSelector( | |
| 103 | - selectCurrentToolCallApplyState, | |
| 106 | + const toolCallApplyState = useAppSelector((state) => | |
| 107 | + selectApplyStateByToolCallId(state, forceToolCallId), | |
| 104 | 108 | ); |
| 105 | 109 | |
| 106 | 110 | /** |
| @@ -147,7 +151,7 @@ | ||
| 147 | 151 | setRelativeFilepathUri(resolvedUri); |
| 148 | 152 | } |
| 149 | 153 | }; |
| 150 | - getRelativeFilepathUri(); | |
| 154 | + void getRelativeFilepathUri(); | |
| 151 | 155 | }, [relativeFilepath, ideMessenger.ide]); |
| 152 | 156 | |
| 153 | 157 | async function getFileUriToApplyTo() { |
| @@ -173,7 +177,7 @@ | ||
| 173 | 177 | async function onClickApply() { |
| 174 | 178 | const fileUri = await getFileUriToApplyTo(); |
| 175 | 179 | if (!fileUri) { |
| 176 | - ideMessenger.ide.showToast( | |
| 180 | + void ideMessenger.ide.showToast( | |
| 177 | 181 | "error", |
| 178 | 182 | "Could not resolve filepath to apply changes", |
| 179 | 183 | ); |
| @@ -188,7 +192,7 @@ | ||
| 188 | 192 | }); |
| 189 | 193 | |
| 190 | 194 | setAppliedFileUri(fileUri); |
| 191 | - refreshFileExists(); | |
| 195 | + void refreshFileExists(); | |
| 192 | 196 | } |
| 193 | 197 | |
| 194 | 198 | function onClickInsertAtCursor() { |
| @@ -198,7 +202,7 @@ | ||
| 198 | 202 | async function handleDiffAction(action: "accept" | "reject") { |
| 199 | 203 | const filepath = await getFileUriToApplyTo(); |
| 200 | 204 | if (!filepath) { |
| 201 | - ideMessenger.ide.showToast( | |
| 205 | + void ideMessenger.ide.showToast( | |
| 202 | 206 | "error", |
| 203 | 207 | `Could not resolve filepath to ${action} changes`, |
| 204 | 208 | ); |
| @@ -233,10 +237,7 @@ | ||
| 233 | 237 | } |
| 234 | 238 | |
| 235 | 239 | const renderActionButtons = () => { |
| 236 | - const isPendingToolCall = | |
| 237 | - currentToolCallApplyState && | |
| 238 | - currentToolCallApplyState.streamId === applyState?.streamId && | |
| 239 | - currentToolCallApplyState.status === "not-started"; | |
| 240 | + const isPendingToolCall = toolCallApplyState?.status === "not-started"; | |
| 240 | 241 | |
| 241 | 242 | if (isGeneratingCodeBlock || isPendingToolCall) { |
| 242 | 243 | const numLines = codeBlockContent.split("\n").length; |
| @@ -271,7 +272,7 @@ | ||
| 271 | 272 | return ( |
| 272 | 273 | <ApplyActions |
| 273 | 274 | disableManualApply={disableManualApply} |
| 274 | - applyState={applyState} | |
| 275 | + applyState={toolCallApplyState ?? applyState} | |
| 275 | 276 | onClickApply={onClickApply} |
| 276 | 277 | onClickAccept={() => handleDiffAction("accept")} |
| 277 | 278 | onClickReject={() => handleDiffAction("reject")} |
| @@ -293,6 +294,7 @@ | ||
| 293 | 294 | <ToolbarDiv isExpanded={isExpanded} className="find-widget-skip gap-3"> |
| 294 | 295 | <div className="max-w-[50% flex flex-row items-center"> |
| 295 | 296 | <ChevronDownIcon |
| 297 | + data-testid="toggle-codeblock" | |
| 296 | 298 | onClick={() => setIsExpanded(!isExpanded)} |
| 297 | 299 | className={`text-lightgray h-3.5 w-3.5 flex-shrink-0 cursor-pointer hover:brightness-125 ${ |
| 298 | 300 | isExpanded ? "rotate-0" : "-rotate-90" |
modified gui/src/components/StyledMarkdownPreview/index.tsx +4 −9
| @@ -126,7 +126,7 @@ | ||
| 126 | 126 | itemIndex?: number; |
| 127 | 127 | useParentBackgroundColor?: boolean; |
| 128 | 128 | disableManualApply?: boolean; |
| 129 | - forceStreamId?: string; | |
| 129 | + toolCallId?: string; | |
| 130 | 130 | expandCodeblocks?: boolean; |
| 131 | 131 | } |
| 132 | 132 | |
| @@ -196,11 +196,6 @@ | ||
| 196 | 196 | const itemIndexRef = useUpdatingRef(props.itemIndex); |
| 197 | 197 | |
| 198 | 198 | const codeblockStreamIds = useRef<string[]>([]); |
| 199 | - useEffect(() => { | |
| 200 | - if (props.forceStreamId) { | |
| 201 | - codeblockStreamIds.current = [props.forceStreamId]; | |
| 202 | - } | |
| 203 | - }, [props.forceStreamId, codeblockStreamIds]); | |
| 204 | 199 | |
| 205 | 200 | const [reactContent, setMarkdownSource] = useRemark({ |
| 206 | 201 | remarkPlugins: [ |
| @@ -295,8 +290,7 @@ | ||
| 295 | 290 | const isLastCodeblock = preChildProps["data-islastcodeblock"]; |
| 296 | 291 | |
| 297 | 292 | if (codeblockStreamIds.current[codeBlockIndex] === undefined) { |
| 298 | - codeblockStreamIds.current[codeBlockIndex] = | |
| 299 | - props.forceStreamId ?? uuidv4(); | |
| 293 | + codeblockStreamIds.current[codeBlockIndex] = uuidv4(); | |
| 300 | 294 | } |
| 301 | 295 | |
| 302 | 296 | return ( |
| @@ -308,7 +302,8 @@ | ||
| 308 | 302 | relativeFilepath={relativeFilePath} |
| 309 | 303 | isLastCodeblock={isLastCodeblock} |
| 310 | 304 | range={range} |
| 311 | - codeBlockStreamId={codeblockStreamIds.current[codeBlockIndex]} | |
| 305 | + codeBlockStreamId={codeblockStreamIds.current[codeBlockIndex]} // ignored if toolCallId stream state is found | |
| 306 | + forceToolCallId={props.toolCallId} | |
| 312 | 307 | expanded={props.expandCodeblocks} |
| 313 | 308 | disableManualApply={props.disableManualApply} |
| 314 | 309 | > |
modified gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +4 −1
| @@ -330,7 +330,10 @@ | ||
| 330 | 330 | ], |
| 331 | 331 | editorProps: { |
| 332 | 332 | attributes: { |
| 333 | - class: "outline-none overflow-hidden", | |
| 333 | + "data-testid": props.isMainInput | |
| 334 | + ? "editor-input-main" | |
| 335 | + : `editor-input-${props.inputId}`, | |
| 336 | + class: "ProseMirror outline-none overflow-hidden", | |
| 334 | 337 | style: `font-size: ${getFontSize()}px;`, |
| 335 | 338 | }, |
| 336 | 339 | }, |
modified gui/src/context/MockIdeMessenger.ts +111 −70
| @@ -1,7 +1,6 @@ | ||
| 1 | -import { IDE, PromptLog } from "core"; | |
| 1 | +import { ChatMessage, IDE, PromptLog } from "core"; | |
| 2 | 2 | import { AuthType } from "core/control-plane/AuthTypes"; |
| 3 | 3 | import { |
| 4 | - FromIdeProtocol, | |
| 5 | 4 | FromWebviewProtocol, |
| 6 | 5 | ToCoreProtocol, |
| 7 | 6 | ToWebviewProtocol, |
| @@ -13,73 +12,83 @@ | ||
| 13 | 12 | GeneratorYieldType, |
| 14 | 13 | WebviewSingleProtocolMessage, |
| 15 | 14 | } from "core/protocol/util"; |
| 16 | -import { ChatMessage } from "../redux/store"; | |
| 17 | 15 | import { IIdeMessenger } from "./IdeMessenger"; |
| 18 | 16 | |
| 19 | -async function defaultMockHandleMessage<T extends keyof FromWebviewProtocol>( | |
| 20 | - messageType: T, | |
| 21 | - data: FromWebviewProtocol[T][0], | |
| 22 | -): Promise<FromWebviewProtocol[T][1]> { | |
| 23 | - function returnFor<K extends keyof FromWebviewProtocol>( | |
| 24 | - _: K, | |
| 25 | - value: FromWebviewProtocol[K][1], | |
| 26 | - ): FromWebviewProtocol[T][1] { | |
| 27 | - return value as unknown as FromWebviewProtocol[T][1]; | |
| 28 | - } | |
| 17 | +type MockResponses = Partial<{ | |
| 18 | + [K in keyof FromWebviewProtocol]: FromWebviewProtocol[K][1]; | |
| 19 | +}>; | |
| 29 | 20 | |
| 30 | - switch (messageType) { | |
| 31 | - case "history/list": | |
| 32 | - return returnFor("history/list", [ | |
| 33 | - { | |
| 34 | - title: "Session 1", | |
| 35 | - sessionId: "session-1", | |
| 36 | - dateCreated: new Date().toString(), | |
| 37 | - workspaceDirectory: "/tmp", | |
| 38 | - }, | |
| 39 | - ]); | |
| 40 | - case "getControlPlaneSessionInfo": | |
| 41 | - return returnFor("getControlPlaneSessionInfo", { | |
| 42 | - AUTH_TYPE: AuthType.WorkOsStaging, | |
| 43 | - accessToken: "", | |
| 44 | - account: { | |
| 45 | - label: "", | |
| 46 | - id: "", | |
| 47 | - }, | |
| 48 | - }); | |
| 49 | - case "config/getSerializedProfileInfo": | |
| 50 | - return returnFor("config/getSerializedProfileInfo", { | |
| 51 | - organizations: [], | |
| 52 | - profileId: "test-profile", | |
| 53 | - result: { | |
| 54 | - config: undefined, | |
| 55 | - errors: [], | |
| 56 | - configLoadInterrupted: false, | |
| 57 | - }, | |
| 58 | - selectedOrgId: "local", | |
| 59 | - }); | |
| 60 | - default: | |
| 61 | - throw new Error(`Unknown message type ${messageType}`); | |
| 62 | - } | |
| 63 | -} | |
| 21 | +const DEFAULT_MOCK_CORE_RESPONSES: MockResponses = { | |
| 22 | + fileExists: true, | |
| 23 | + getCurrentFile: { | |
| 24 | + isUntitled: false, | |
| 25 | + contents: "Current file contents", | |
| 26 | + path: "file:///Users/user/workspace1/current_file.py", | |
| 27 | + }, | |
| 28 | + "controlPlane/getFreeTrialStatus": { | |
| 29 | + autocompleteLimit: 1000, | |
| 30 | + optedInToFreeTrial: false, | |
| 31 | + chatLimit: 1000, | |
| 32 | + autocompleteCount: 0, | |
| 33 | + chatCount: 0, | |
| 34 | + }, | |
| 35 | + getWorkspaceDirs: [ | |
| 36 | + "file:///Users/user/workspace1", | |
| 37 | + "file:///Users/user/workspace2", | |
| 38 | + ], | |
| 39 | + "history/list": [ | |
| 40 | + { | |
| 41 | + title: "Session 1", | |
| 42 | + sessionId: "session-1", | |
| 43 | + dateCreated: new Date().toString(), | |
| 44 | + workspaceDirectory: "/tmp", | |
| 45 | + }, | |
| 46 | + ], | |
| 47 | + "history/save": undefined, | |
| 48 | + getControlPlaneSessionInfo: { | |
| 49 | + AUTH_TYPE: AuthType.WorkOsStaging, | |
| 50 | + accessToken: "", | |
| 51 | + account: { | |
| 52 | + label: "", | |
| 53 | + id: "", | |
| 54 | + }, | |
| 55 | + }, | |
| 56 | + "config/getSerializedProfileInfo": { | |
| 57 | + organizations: [], | |
| 58 | + profileId: "test-profile", | |
| 59 | + result: { | |
| 60 | + config: undefined, | |
| 61 | + errors: [], | |
| 62 | + configLoadInterrupted: false, | |
| 63 | + }, | |
| 64 | + selectedOrgId: "local", | |
| 65 | + }, | |
| 66 | + "chatDescriber/describe": "Session summary", | |
| 67 | + applyToFile: undefined, | |
| 68 | + acceptDiff: undefined, | |
| 69 | +}; | |
| 64 | 70 | |
| 71 | +const DEFAULT_CHAT_RESPONSE: ChatMessage[] = [ | |
| 72 | + { | |
| 73 | + role: "assistant", | |
| 74 | + content: "This is a test", | |
| 75 | + }, | |
| 76 | +]; | |
| 65 | 77 | export class MockIdeMessenger implements IIdeMessenger { |
| 66 | 78 | ide: IDE; |
| 67 | - private messageHandlers: Map< | |
| 68 | - keyof FromIdeProtocol, | |
| 69 | - Array<(data: any) => void> | |
| 70 | - > = new Map(); | |
| 71 | 79 | |
| 72 | 80 | constructor() { |
| 73 | 81 | this.ide = new MessageIde( |
| 74 | - (messageType, data) => { | |
| 75 | - throw new Error("Not implemented"); | |
| 82 | + async (messageType, data) => { | |
| 83 | + const response = await this.request.bind(this)(messageType, data); | |
| 84 | + if (response.status === "error") { | |
| 85 | + throw new Error(response.error); | |
| 86 | + } else { | |
| 87 | + return response.content; | |
| 88 | + } | |
| 76 | 89 | }, |
| 77 | 90 | (messageType, callback) => { |
| 78 | - // Store the callback in our handlers map | |
| 79 | - if (!this.messageHandlers.has(messageType)) { | |
| 80 | - this.messageHandlers.set(messageType, []); | |
| 81 | - } | |
| 82 | - this.messageHandlers.get(messageType)?.push(callback); | |
| 91 | + return; | |
| 83 | 92 | }, |
| 84 | 93 | ); |
| 85 | 94 | } |
| @@ -109,16 +118,38 @@ | ||
| 109 | 118 | ); |
| 110 | 119 | } |
| 111 | 120 | |
| 112 | - async *llmStreamChat( | |
| 113 | - msg: ToCoreProtocol["llm/streamChat"][0], | |
| 114 | - cancelToken: AbortSignal, | |
| 115 | - ): AsyncGenerator<ChatMessage[], PromptLog | undefined> { | |
| 116 | - yield [ | |
| 121 | + responses: MockResponses = { ...DEFAULT_MOCK_CORE_RESPONSES }; | |
| 122 | + chatResponse: ChatMessage[] = DEFAULT_CHAT_RESPONSE; | |
| 123 | + chatStreamDelay: number = 0; | |
| 124 | + setChatResponseText(text: string): void { | |
| 125 | + this.chatResponse = [ | |
| 117 | 126 | { |
| 118 | 127 | role: "assistant", |
| 119 | - content: "This is a test", | |
| 128 | + content: text, | |
| 120 | 129 | }, |
| 121 | 130 | ]; |
| 131 | + } | |
| 132 | + | |
| 133 | + async *llmStreamChat( | |
| 134 | + msg: ToCoreProtocol["llm/streamChat"][0], | |
| 135 | + cancelToken: AbortSignal, | |
| 136 | + ): AsyncGenerator<ChatMessage[], PromptLog | undefined> { | |
| 137 | + for (const response of this.chatResponse) { | |
| 138 | + if (cancelToken.aborted) { | |
| 139 | + console.log("MockIdeMessenger: Stream aborted"); | |
| 140 | + return undefined; | |
| 141 | + } | |
| 142 | + console.log( | |
| 143 | + "MockIdeMessenger: Yielding chunk", | |
| 144 | + JSON.stringify(response, null, 2), | |
| 145 | + ); | |
| 146 | + yield [response]; | |
| 147 | + if (this.chatStreamDelay > 0) { | |
| 148 | + await new Promise((resolve) => | |
| 149 | + setTimeout(resolve, this.chatStreamDelay), | |
| 150 | + ); | |
| 151 | + } | |
| 152 | + } | |
| 122 | 153 | return undefined; |
| 123 | 154 | } |
| 124 | 155 | |
| @@ -133,12 +164,16 @@ | ||
| 133 | 164 | messageType: T, |
| 134 | 165 | data: FromWebviewProtocol[T][0], |
| 135 | 166 | ): Promise<WebviewSingleProtocolMessage<T>> { |
| 136 | - const content = await defaultMockHandleMessage(messageType, data); | |
| 137 | - return { | |
| 138 | - status: "success", | |
| 139 | - content, | |
| 140 | - done: true, | |
| 141 | - }; | |
| 167 | + if (messageType in this.responses) { | |
| 168 | + const content = this.responses[messageType]; | |
| 169 | + return { | |
| 170 | + status: "success", | |
| 171 | + content, | |
| 172 | + done: true, | |
| 173 | + }; | |
| 174 | + } | |
| 175 | + console.error(messageType); | |
| 176 | + throw new Error("MockIdeMessenger: No response defined for " + messageType); | |
| 142 | 177 | } |
| 143 | 178 | |
| 144 | 179 | respond<T extends keyof ToWebviewProtocol>( |
| @@ -157,4 +192,10 @@ | ||
| 157 | 192 | > { |
| 158 | 193 | return undefined; |
| 159 | 194 | } |
| 195 | + | |
| 196 | + resetMocks(): void { | |
| 197 | + this.responses = { ...DEFAULT_MOCK_CORE_RESPONSES }; | |
| 198 | + this.chatResponse = DEFAULT_CHAT_RESPONSE; | |
| 199 | + this.chatStreamDelay = 0; | |
| 200 | + } | |
| 160 | 201 | } |
modified gui/src/hooks/ParallelListeners.tsx +38 −18
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | import { |
| 21 | 21 | acceptToolCall, |
| 22 | 22 | addContextItemsAtIndex, |
| 23 | + selectCurrentToolCall, | |
| 23 | 24 | setHasReasoningEnabled, |
| 24 | 25 | updateApplyState, |
| 25 | 26 | } from "../redux/slices/sessionSlice"; |
| @@ -244,6 +245,10 @@ | ||
| 244 | 245 | dispatch(updateIndexingStatus(data)); |
| 245 | 246 | }); |
| 246 | 247 | |
| 248 | + const autoAcceptEditToolDiffs = useAppSelector( | |
| 249 | + (store) => store.config.config.ui?.autoAcceptEditToolDiffs, | |
| 250 | + ); | |
| 251 | + const currentToolCall = useAppSelector(selectCurrentToolCall); | |
| 247 | 252 | useWebviewListener( |
| 248 | 253 | "updateApplyState", |
| 249 | 254 | async (state) => { |
| @@ -259,30 +264,45 @@ | ||
| 259 | 264 | |
| 260 | 265 | // Handle apply status updates that are associated with current tool call |
| 261 | 266 | if ( |
| 262 | - state.status === "closed" && | |
| 263 | 267 | currentToolCallApplyState && |
| 264 | 268 | currentToolCallApplyState.streamId === state.streamId |
| 265 | 269 | ) { |
| 266 | - // const output: ContextItem = { | |
| 267 | - // name: "Edit tool output", | |
| 268 | - // content: "Completed edit", | |
| 269 | - // description: "", | |
| 270 | - // }; | |
| 271 | - dispatch( | |
| 272 | - acceptToolCall({ | |
| 273 | - toolCallId: currentToolCallApplyState.toolCallId!, | |
| 274 | - }), | |
| 275 | - ); | |
| 276 | - // dispatch(setToolCallOutput([])); | |
| 277 | - void dispatch( | |
| 278 | - streamResponseAfterToolCall({ | |
| 279 | - toolCallId: currentToolCallApplyState.toolCallId!, | |
| 280 | - }), | |
| 281 | - ); | |
| 270 | + if (state.status === "done" && autoAcceptEditToolDiffs) { | |
| 271 | + console.log("AUTO ACCEPTED"); | |
| 272 | + ideMessenger.post("acceptDiff", { | |
| 273 | + streamId: state.streamId, | |
| 274 | + filepath: state.filepath, | |
| 275 | + }); | |
| 276 | + } | |
| 277 | + if (state.status === "closed") { | |
| 278 | + if (currentToolCall?.status !== "canceled") { | |
| 279 | + dispatch( | |
| 280 | + acceptToolCall({ | |
| 281 | + toolCallId: currentToolCallApplyState.toolCallId!, | |
| 282 | + }), | |
| 283 | + ); | |
| 284 | + } | |
| 285 | + // const output: ContextItem = { | |
| 286 | + // name: "Edit tool output", | |
| 287 | + // content: "Completed edit", | |
| 288 | + // description: "", | |
| 289 | + // }; | |
| 290 | + // dispatch(setToolCallOutput([])); | |
| 291 | + void dispatch( | |
| 292 | + streamResponseAfterToolCall({ | |
| 293 | + toolCallId: currentToolCallApplyState.toolCallId!, | |
| 294 | + }), | |
| 295 | + ); | |
| 296 | + } | |
| 282 | 297 | } |
| 283 | 298 | } |
| 284 | 299 | }, |
| 285 | - [currentToolCallApplyState, history], | |
| 300 | + [ | |
| 301 | + currentToolCall, | |
| 302 | + currentToolCallApplyState, | |
| 303 | + autoAcceptEditToolDiffs, | |
| 304 | + ideMessenger, | |
| 305 | + ], | |
| 286 | 306 | ); |
| 287 | 307 | |
| 288 | 308 | useEffect(() => { |
deleted gui/src/pages/gui/Chat.test.tsx +0 −161
| @@ -1,161 +0,0 @@ | ||
| 1 | -import { screen, waitFor } from "@testing-library/dom"; | |
| 2 | -import { act } from "@testing-library/react"; | |
| 3 | -import { renderWithProviders } from "../../util/test/render"; | |
| 4 | -import { Chat } from "./Chat"; | |
| 5 | - | |
| 6 | -describe("Chat page test", () => { | |
| 7 | - it("should render input box", async () => { | |
| 8 | - await renderWithProviders(<Chat />); | |
| 9 | - expect(await screen.findByTestId("continue-input-box")).toBeInTheDocument(); | |
| 10 | - }); | |
| 11 | - | |
| 12 | - it("should be able to toggle modes", async () => { | |
| 13 | - await renderWithProviders(<Chat />); | |
| 14 | - expect(screen.getByText("Chat")).toBeInTheDocument(); | |
| 15 | - | |
| 16 | - // Simulate cmd+. keyboard shortcut to toggle modes | |
| 17 | - act(() => { | |
| 18 | - document.dispatchEvent( | |
| 19 | - new KeyboardEvent("keydown", { | |
| 20 | - key: ".", | |
| 21 | - metaKey: true, // cmd key on Mac | |
| 22 | - }), | |
| 23 | - ); | |
| 24 | - }); | |
| 25 | - | |
| 26 | - // Check that it switched to Agent mode | |
| 27 | - expect(await screen.findByText("Agent")).toBeInTheDocument(); | |
| 28 | - | |
| 29 | - act(() => { | |
| 30 | - document.dispatchEvent( | |
| 31 | - new KeyboardEvent("keydown", { | |
| 32 | - key: ".", | |
| 33 | - metaKey: true, // cmd key on Mac | |
| 34 | - }), | |
| 35 | - ); | |
| 36 | - }); | |
| 37 | - | |
| 38 | - // Check that it switched back to Chat mode | |
| 39 | - expect(await screen.findByText("Chat")).toBeInTheDocument(); | |
| 40 | - }); | |
| 41 | - | |
| 42 | - it.skip("should send a message and receive a response", async () => { | |
| 43 | - const { user, container } = await renderWithProviders(<Chat />); | |
| 44 | - const inputBox = await waitFor(() => | |
| 45 | - container.querySelector(".ProseMirror")!.querySelector("p"), | |
| 46 | - ); | |
| 47 | - expect(inputBox).toBeDefined(); | |
| 48 | - | |
| 49 | - const sendButton = await screen.findByTestId("submit-input-button"); | |
| 50 | - | |
| 51 | - await act(async () => { | |
| 52 | - // Focus input box | |
| 53 | - inputBox!.focus(); | |
| 54 | - | |
| 55 | - // Type message | |
| 56 | - await user.type(inputBox!, "Hello, world!"); | |
| 57 | - | |
| 58 | - sendButton.click(); | |
| 59 | - }); | |
| 60 | - expect(await screen.findByText("Hello, world!")).toBeInTheDocument(); | |
| 61 | - }); | |
| 62 | - | |
| 63 | - it("should handle apply updates and display the accept / reject all buttons", async () => { | |
| 64 | - const { ideMessenger } = await renderWithProviders(<Chat />); | |
| 65 | - | |
| 66 | - // Use queryByText which returns null when element isn't found | |
| 67 | - const acceptAllButton = screen.queryByText("Accept All"); | |
| 68 | - const rejectAllButton = screen.queryByText("Reject All"); | |
| 69 | - | |
| 70 | - // Assert that the buttons don't exist | |
| 71 | - expect(acceptAllButton).not.toBeInTheDocument(); | |
| 72 | - expect(rejectAllButton).not.toBeInTheDocument(); | |
| 73 | - | |
| 74 | - for (let i = 0; i < 5; i++) { | |
| 75 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 76 | - status: "streaming", | |
| 77 | - streamId: `12345`, | |
| 78 | - }); | |
| 79 | - } | |
| 80 | - | |
| 81 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 82 | - status: "done", | |
| 83 | - streamId: "12345", | |
| 84 | - }); | |
| 85 | - | |
| 86 | - // Wait for the buttons to appear | |
| 87 | - await waitFor(() => { | |
| 88 | - expect( | |
| 89 | - screen.getByTestId("accept-reject-all-buttons"), | |
| 90 | - ).toBeInTheDocument(); | |
| 91 | - }); | |
| 92 | - | |
| 93 | - // IDE sends back message that it is done | |
| 94 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 95 | - status: "closed", | |
| 96 | - streamId: "12345", | |
| 97 | - }); | |
| 98 | - | |
| 99 | - // Wait for the buttons to disappear | |
| 100 | - await waitFor(() => { | |
| 101 | - expect( | |
| 102 | - screen.queryByTestId("edit-accept-button"), | |
| 103 | - ).not.toBeInTheDocument(); | |
| 104 | - expect( | |
| 105 | - screen.queryByTestId("edit-reject-button"), | |
| 106 | - ).not.toBeInTheDocument(); | |
| 107 | - }); | |
| 108 | - }); | |
| 109 | - | |
| 110 | - it("should show apply cancellation", async () => { | |
| 111 | - const { ideMessenger } = await renderWithProviders(<Chat />); | |
| 112 | - | |
| 113 | - // Spy on the request method of ideMessenger | |
| 114 | - const messengerPostSpy = vi.spyOn(ideMessenger, "post"); | |
| 115 | - | |
| 116 | - for (let i = 0; i < 5; i++) { | |
| 117 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 118 | - status: "streaming", | |
| 119 | - streamId: `12345`, | |
| 120 | - }); | |
| 121 | - } | |
| 122 | - | |
| 123 | - // Wait for applying toolbar to appear | |
| 124 | - await waitFor(() => { | |
| 125 | - const cancelApplyButton = screen.getByTestId( | |
| 126 | - "notch-applying-cancel-button", | |
| 127 | - ); | |
| 128 | - const applyingText = screen.getByTestId("notch-applying-text"); | |
| 129 | - | |
| 130 | - expect(cancelApplyButton).toBeInTheDocument(); | |
| 131 | - expect(applyingText).toBeInTheDocument(); | |
| 132 | - }); | |
| 133 | - | |
| 134 | - const cancelApplyButton = screen.getByTestId( | |
| 135 | - "notch-applying-cancel-button", | |
| 136 | - ); | |
| 137 | - cancelApplyButton.click(); | |
| 138 | - | |
| 139 | - // Verify that rejectDiff message has been posted to ideMessenger | |
| 140 | - expect(messengerPostSpy).toHaveBeenCalledWith("rejectDiff", {}); | |
| 141 | - | |
| 142 | - // Now simulate the IDE sending back a message that the apply state is closed | |
| 143 | - ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 144 | - status: "closed", | |
| 145 | - streamId: "12345", | |
| 146 | - }); | |
| 147 | - | |
| 148 | - await waitFor(() => { | |
| 149 | - const cancelApplyButton = screen.queryByTestId( | |
| 150 | - "notch-applying-cancel-button", | |
| 151 | - ); | |
| 152 | - const applyingText = screen.queryByTestId("notch-applying-text"); | |
| 153 | - | |
| 154 | - expect(cancelApplyButton).not.toBeInTheDocument(); | |
| 155 | - expect(applyingText).not.toBeInTheDocument(); | |
| 156 | - }); | |
| 157 | - | |
| 158 | - // Cleanup spy | |
| 159 | - messengerPostSpy.mockRestore(); | |
| 160 | - }); | |
| 161 | -}); |
modified gui/src/pages/gui/Chat.tsx +5 −5
| @@ -42,12 +42,12 @@ | ||
| 42 | 42 | setDialogMessage, |
| 43 | 43 | setShowDialog, |
| 44 | 44 | } from "../../redux/slices/uiSlice"; |
| 45 | -import { cancelStream } from "../../redux/thunks/cancelStream"; | |
| 46 | 45 | import { streamEditThunk } from "../../redux/thunks/edit"; |
| 47 | 46 | import { loadLastSession } from "../../redux/thunks/session"; |
| 48 | 47 | import { streamResponseThunk } from "../../redux/thunks/streamResponse"; |
| 49 | 48 | import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; |
| 50 | 49 | |
| 50 | +import { cancelStream } from "../../redux/thunks/cancelStream"; | |
| 51 | 51 | import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; |
| 52 | 52 | import { EmptyChatBody } from "./EmptyChatBody"; |
| 53 | 53 | import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; |
| @@ -125,14 +125,14 @@ | ||
| 125 | 125 | |
| 126 | 126 | useEffect(() => { |
| 127 | 127 | // Cmd + Backspace to delete current step |
| 128 | - const listener = (e: any) => { | |
| 128 | + const listener = (e: KeyboardEvent) => { | |
| 129 | 129 | if ( |
| 130 | 130 | e.key === "Backspace" && |
| 131 | 131 | (jetbrains ? e.altKey : isMetaEquivalentKeyPressed(e)) && |
| 132 | 132 | !e.shiftKey |
| 133 | 133 | ) { |
| 134 | - dispatch(cancelStream()); | |
| 135 | - ideMessenger.post("rejectDiff", {}); // just always cancel, if not in applying won't matter | |
| 134 | + void dispatch(cancelStream()); | |
| 135 | + if (isInEdit) ideMessenger.post("rejectDiff", {}); | |
| 136 | 136 | } |
| 137 | 137 | }; |
| 138 | 138 | window.addEventListener("keydown", listener); |
| @@ -140,7 +140,7 @@ | ||
| 140 | 140 | return () => { |
| 141 | 141 | window.removeEventListener("keydown", listener); |
| 142 | 142 | }; |
| 143 | - }, [isStreaming, jetbrains]); | |
| 143 | + }, [isStreaming, jetbrains, isInEdit]); | |
| 144 | 144 | |
| 145 | 145 | const { widget, highlights } = useFindWidget( |
| 146 | 146 | stepsDivRef, |
modified gui/src/pages/gui/ToolCallDiv/EditFile.tsx +1 −26
| @@ -1,12 +1,5 @@ | ||
| 1 | 1 | import { getMarkdownLanguageTagForFile } from "core/util"; |
| 2 | -import { useEffect } from "react"; | |
| 3 | -import { v4 as uuidv4 } from "uuid"; | |
| 4 | 2 | import StyledMarkdownPreview from "../../../components/StyledMarkdownPreview"; |
| 5 | -import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; | |
| 6 | -import { | |
| 7 | - selectApplyStateByToolCallId, | |
| 8 | - updateApplyState, | |
| 9 | -} from "../../../redux/slices/sessionSlice"; | |
| 10 | 3 | |
| 11 | 4 | type EditToolCallProps = { |
| 12 | 5 | relativeFilePath: string; |
| @@ -16,24 +9,6 @@ | ||
| 16 | 9 | }; |
| 17 | 10 | |
| 18 | 11 | export function EditFile(props: EditToolCallProps) { |
| 19 | - const dispatch = useAppDispatch(); | |
| 20 | - | |
| 21 | - const applyState = useAppSelector((state) => | |
| 22 | - selectApplyStateByToolCallId(state, props.toolCallId), | |
| 23 | - ); | |
| 24 | - | |
| 25 | - useEffect(() => { | |
| 26 | - if (!applyState) { | |
| 27 | - dispatch( | |
| 28 | - updateApplyState({ | |
| 29 | - streamId: uuidv4(), | |
| 30 | - toolCallId: props.toolCallId, | |
| 31 | - status: "not-started", | |
| 32 | - }), | |
| 33 | - ); | |
| 34 | - } | |
| 35 | - }, [applyState, props.toolCallId]); | |
| 36 | - | |
| 37 | 12 | if (!props.relativeFilePath || !props.changes) { |
| 38 | 13 | return null; |
| 39 | 14 | } |
| @@ -45,7 +20,7 @@ | ||
| 45 | 20 | isRenderingInStepContainer |
| 46 | 21 | disableManualApply |
| 47 | 22 | source={src} |
| 48 | - forceStreamId={applyState?.streamId} | |
| 23 | + toolCallId={props.toolCallId} | |
| 49 | 24 | expandCodeblocks={false} |
| 50 | 25 | itemIndex={props.historyIndex} |
| 51 | 26 | /> |
added gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx +80 −0
| @@ -0,0 +1,80 @@ | ||
| 1 | +import { act } from "@testing-library/react"; | |
| 2 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 3 | +import { | |
| 4 | + getElementByTestId, | |
| 5 | + verifyNotPresentByTestId, | |
| 6 | + verifyNotPresentByText, | |
| 7 | +} from "../../../util/test/utils"; | |
| 8 | +import { Chat } from "../Chat"; | |
| 9 | + | |
| 10 | +test("Chat apply scenarios: handle apply updates and display the accept / reject all buttons", async () => { | |
| 11 | + const { ideMessenger } = await renderWithProviders(<Chat />); | |
| 12 | + | |
| 13 | + // Use queryByText which returns null when element isn't found | |
| 14 | + await verifyNotPresentByText("Accept All"); | |
| 15 | + await verifyNotPresentByText("Reject All"); | |
| 16 | + | |
| 17 | + for (let i = 0; i < 5; i++) { | |
| 18 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 19 | + status: "streaming", | |
| 20 | + streamId: `12345`, | |
| 21 | + }); | |
| 22 | + } | |
| 23 | + | |
| 24 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 25 | + status: "done", | |
| 26 | + streamId: "12345", | |
| 27 | + }); | |
| 28 | + | |
| 29 | + // Wait for the buttons to appear | |
| 30 | + await getElementByTestId("accept-reject-all-buttons"); | |
| 31 | + | |
| 32 | + // IDE sends back message that it is done | |
| 33 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 34 | + status: "closed", | |
| 35 | + streamId: "12345", | |
| 36 | + }); | |
| 37 | + | |
| 38 | + // Wait for the buttons to disappear | |
| 39 | + await verifyNotPresentByTestId("edit-accept-button"); | |
| 40 | + await verifyNotPresentByTestId("edit-reject-button"); | |
| 41 | +}); | |
| 42 | + | |
| 43 | +test("Chat apply scenarios: show apply cancellation", async () => { | |
| 44 | + const { ideMessenger } = await renderWithProviders(<Chat />); | |
| 45 | + | |
| 46 | + // Spy on the request method of ideMessenger | |
| 47 | + const messengerPostSpy = vi.spyOn(ideMessenger, "post"); | |
| 48 | + | |
| 49 | + for (let i = 0; i < 5; i++) { | |
| 50 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 51 | + status: "streaming", | |
| 52 | + streamId: `12345`, | |
| 53 | + }); | |
| 54 | + } | |
| 55 | + | |
| 56 | + // Wait for applying toolbar to appear | |
| 57 | + await getElementByTestId("notch-applying-text"); | |
| 58 | + | |
| 59 | + await act(async () => { | |
| 60 | + const cancelApplyButton = await getElementByTestId( | |
| 61 | + "notch-applying-cancel-button", | |
| 62 | + ); | |
| 63 | + cancelApplyButton.click(); | |
| 64 | + }); | |
| 65 | + | |
| 66 | + // Verify that rejectDiff message has been posted to ideMessenger | |
| 67 | + expect(messengerPostSpy).toHaveBeenCalledWith("rejectDiff", {}); | |
| 68 | + | |
| 69 | + // Now simulate the IDE sending back a message that the apply state is closed | |
| 70 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 71 | + status: "closed", | |
| 72 | + streamId: "12345", | |
| 73 | + }); | |
| 74 | + | |
| 75 | + await verifyNotPresentByTestId("notch-applying-text"); | |
| 76 | + await verifyNotPresentByTestId("notch-applying-cancel-button"); | |
| 77 | + | |
| 78 | + // Cleanup spy | |
| 79 | + messengerPostSpy.mockRestore(); | |
| 80 | +}); |
added gui/src/pages/gui/chat-tests/Chat.test.tsx +61 −0
| @@ -0,0 +1,61 @@ | ||
| 1 | +import { act } from "@testing-library/react"; | |
| 2 | +import { addAndSelectMockLlm } from "../../../util/test/config"; | |
| 3 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 4 | +import { | |
| 5 | + getElementByTestId, | |
| 6 | + getElementByText, | |
| 7 | + sendInputWithMockedResponse, | |
| 8 | +} from "../../../util/test/utils"; | |
| 9 | +import { Chat } from "../Chat"; | |
| 10 | + | |
| 11 | +test("should render input box", async () => { | |
| 12 | + await renderWithProviders(<Chat />); | |
| 13 | + await getElementByTestId("continue-input-box"); | |
| 14 | +}); | |
| 15 | + | |
| 16 | +test("should be able to toggle modes", async () => { | |
| 17 | + await renderWithProviders(<Chat />); | |
| 18 | + await getElementByText("Chat"); | |
| 19 | + | |
| 20 | + // Simulate cmd+. keyboard shortcut to toggle modes | |
| 21 | + act(() => { | |
| 22 | + document.dispatchEvent( | |
| 23 | + new KeyboardEvent("keydown", { | |
| 24 | + key: ".", | |
| 25 | + metaKey: true, // cmd key on Mac | |
| 26 | + }), | |
| 27 | + ); | |
| 28 | + }); | |
| 29 | + | |
| 30 | + // Check that it switched to Agent mode | |
| 31 | + await getElementByText("Agent"); | |
| 32 | + | |
| 33 | + act(() => { | |
| 34 | + document.dispatchEvent( | |
| 35 | + new KeyboardEvent("keydown", { | |
| 36 | + key: ".", | |
| 37 | + metaKey: true, // cmd key on Mac | |
| 38 | + }), | |
| 39 | + ); | |
| 40 | + }); | |
| 41 | + | |
| 42 | + await getElementByText("Chat"); | |
| 43 | +}); | |
| 44 | + | |
| 45 | +test("should send a message and receive a response", async () => { | |
| 46 | + const { ideMessenger, store } = await renderWithProviders(<Chat />); | |
| 47 | + | |
| 48 | + // First add and select the mock LLM | |
| 49 | + await act(async () => { | |
| 50 | + addAndSelectMockLlm(store, ideMessenger); | |
| 51 | + }); | |
| 52 | + | |
| 53 | + const CONTENT = "Expected response"; | |
| 54 | + const INPUT = "User input"; | |
| 55 | + | |
| 56 | + await sendInputWithMockedResponse(ideMessenger, INPUT, [ | |
| 57 | + { role: "assistant", content: CONTENT }, | |
| 58 | + ]); | |
| 59 | + | |
| 60 | + await getElementByText(CONTENT); | |
| 61 | +}); |
added gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +231 −0
| @@ -0,0 +1,231 @@ | ||
| 1 | +import { BuiltInToolNames } from "core/tools/builtIn"; | |
| 2 | +import { | |
| 3 | + addAndSelectMockLlm, | |
| 4 | + triggerConfigUpdate, | |
| 5 | +} from "../../../util/test/config"; | |
| 6 | +import { renderWithProviders } from "../../../util/test/render"; | |
| 7 | +import { Chat } from "../Chat"; | |
| 8 | + | |
| 9 | +import { waitFor } from "@testing-library/dom"; | |
| 10 | +import { ChatMessage } from "core"; | |
| 11 | +import { toggleToolSetting } from "../../../redux/slices/uiSlice"; | |
| 12 | +import { | |
| 13 | + getElementByTestId, | |
| 14 | + getElementByText, | |
| 15 | + sendInputWithMockedResponse, | |
| 16 | + verifyNotPresentByTestId, | |
| 17 | +} from "../../../util/test/utils"; | |
| 18 | + | |
| 19 | +const EDIT_WORKSPACE_DIR = "file:///workspace"; | |
| 20 | +const EDIT_FILEPATH = "test.txt"; | |
| 21 | +const EDIT_FILE_URI = `${EDIT_WORKSPACE_DIR}/${EDIT_FILEPATH}`; | |
| 22 | +const EDIT_CHANGES = "New content"; | |
| 23 | +const EDIT_TOOL_CALL_ID = "known-id"; | |
| 24 | +const EDIT_MESSAGES: ChatMessage[] = [ | |
| 25 | + { | |
| 26 | + role: "assistant", | |
| 27 | + content: "", | |
| 28 | + toolCalls: [ | |
| 29 | + { | |
| 30 | + id: EDIT_TOOL_CALL_ID, | |
| 31 | + function: { | |
| 32 | + name: BuiltInToolNames.EditExistingFile, | |
| 33 | + arguments: JSON.stringify({ | |
| 34 | + filepath: EDIT_FILEPATH, | |
| 35 | + changes: EDIT_CHANGES, | |
| 36 | + }), | |
| 37 | + }, | |
| 38 | + }, | |
| 39 | + ], | |
| 40 | + }, | |
| 41 | +]; | |
| 42 | + | |
| 43 | +const POST_EDIT_RESPONSE = "Edit applied successfully"; | |
| 44 | +beforeEach(() => { | |
| 45 | + vi.clearAllMocks(); | |
| 46 | +}); | |
| 47 | + | |
| 48 | +test("Edit run with ask first policy and no auto apply", async () => { | |
| 49 | + // Setup | |
| 50 | + const { ideMessenger, store, user } = await renderWithProviders(<Chat />); | |
| 51 | + | |
| 52 | + ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; | |
| 53 | + const messengerPostSpy = vi.spyOn(ideMessenger, "post"); | |
| 54 | + | |
| 55 | + addAndSelectMockLlm(store, ideMessenger); | |
| 56 | + | |
| 57 | + // Send the input that will respond with an edit tool call | |
| 58 | + await sendInputWithMockedResponse( | |
| 59 | + ideMessenger, | |
| 60 | + "Edit this file", | |
| 61 | + EDIT_MESSAGES, | |
| 62 | + ); | |
| 63 | + | |
| 64 | + // Toggle the codeblock and make sure the changes show | |
| 65 | + const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); | |
| 66 | + | |
| 67 | + await user.click(toggleCodeblockChevron); | |
| 68 | + await getElementByText(EDIT_CHANGES); | |
| 69 | + | |
| 70 | + // Pending tool call - find and click the accept button | |
| 71 | + const acceptToolCallButton = await getElementByTestId( | |
| 72 | + "accept-tool-call-button", | |
| 73 | + ); | |
| 74 | + await user.click(acceptToolCallButton); | |
| 75 | + | |
| 76 | + // Tool call, check that applyToFile was called for edit | |
| 77 | + await waitFor(() => { | |
| 78 | + expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", { | |
| 79 | + streamId: expect.any(String), | |
| 80 | + filepath: EDIT_FILE_URI, | |
| 81 | + text: EDIT_CHANGES, | |
| 82 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 83 | + }); | |
| 84 | + }); | |
| 85 | + | |
| 86 | + // Extract stream ID and initiate mock streaming | |
| 87 | + const streamId = messengerPostSpy.mock.calls.find( | |
| 88 | + (call) => call[0] === "applyToFile", | |
| 89 | + )?.[1]?.streamId; | |
| 90 | + expect(streamId).toBeDefined(); | |
| 91 | + | |
| 92 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 93 | + status: "streaming", | |
| 94 | + streamId, | |
| 95 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 96 | + filepath: EDIT_FILE_URI, | |
| 97 | + }); | |
| 98 | + | |
| 99 | + // Mid stream, should show applying in notch | |
| 100 | + await getElementByTestId("notch-applying-text"); | |
| 101 | + await getElementByTestId("notch-applying-cancel-button"); | |
| 102 | + | |
| 103 | + // Close the stream | |
| 104 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 105 | + status: "done", | |
| 106 | + streamId, | |
| 107 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 108 | + filepath: EDIT_FILE_URI, | |
| 109 | + }); | |
| 110 | + | |
| 111 | + // Verify accept/reject buttons are present | |
| 112 | + const acceptButton = await getElementByTestId("edit-accept-button"); | |
| 113 | + await getElementByTestId("edit-reject-button"); | |
| 114 | + | |
| 115 | + // Accept the changes, which should trigger a response after the tool call | |
| 116 | + await user.click(acceptButton); | |
| 117 | + | |
| 118 | + expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", { | |
| 119 | + streamId, | |
| 120 | + filepath: EDIT_FILE_URI, | |
| 121 | + }); | |
| 122 | + | |
| 123 | + ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); | |
| 124 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 125 | + status: "closed", | |
| 126 | + streamId, | |
| 127 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 128 | + filepath: EDIT_FILE_URI, | |
| 129 | + }); | |
| 130 | + | |
| 131 | + await verifyNotPresentByTestId("edit-accept-button"); | |
| 132 | + await verifyNotPresentByTestId("edit-reject-button"); | |
| 133 | + | |
| 134 | + await getElementByText(POST_EDIT_RESPONSE); | |
| 135 | +}); | |
| 136 | + | |
| 137 | +test("Edit run with no policy and yolo mode", async () => { | |
| 138 | + // Setup | |
| 139 | + const { ideMessenger, store, user } = await renderWithProviders(<Chat />); | |
| 140 | + | |
| 141 | + ideMessenger.responses["getWorkspaceDirs"] = [EDIT_WORKSPACE_DIR]; | |
| 142 | + const messengerPostSpy = vi.spyOn(ideMessenger, "post"); | |
| 143 | + | |
| 144 | + addAndSelectMockLlm(store, ideMessenger); | |
| 145 | + | |
| 146 | + // Enable automatic edit and yolo mode | |
| 147 | + store.dispatch(toggleToolSetting(BuiltInToolNames.EditExistingFile)); | |
| 148 | + triggerConfigUpdate({ | |
| 149 | + store, | |
| 150 | + ideMessenger, | |
| 151 | + editConfig: (current) => { | |
| 152 | + current.ui = { | |
| 153 | + ...current.ui, | |
| 154 | + autoAcceptEditToolDiffs: true, // Enable auto-accept for edit tool diffs | |
| 155 | + }; | |
| 156 | + return current; | |
| 157 | + }, | |
| 158 | + }); | |
| 159 | + expect(store.getState().config.config.ui?.autoAcceptEditToolDiffs).toBe(true); | |
| 160 | + | |
| 161 | + // Send the input that will respond with an edit tool call | |
| 162 | + await sendInputWithMockedResponse( | |
| 163 | + ideMessenger, | |
| 164 | + "Edit this file", | |
| 165 | + EDIT_MESSAGES, | |
| 166 | + ); | |
| 167 | + | |
| 168 | + // Toggle the codeblock and make sure the changes show | |
| 169 | + const toggleCodeblockChevron = await getElementByTestId("toggle-codeblock"); | |
| 170 | + | |
| 171 | + await user.click(toggleCodeblockChevron); | |
| 172 | + await getElementByText(EDIT_CHANGES); | |
| 173 | + | |
| 174 | + // Make sure there's no pending tool call | |
| 175 | + verifyNotPresentByTestId("accept-tool-call-button"); | |
| 176 | + // Tool call, check that applyToFile was called for edit | |
| 177 | + await waitFor(() => { | |
| 178 | + expect(messengerPostSpy).toHaveBeenCalledWith("applyToFile", { | |
| 179 | + streamId: expect.any(String), | |
| 180 | + filepath: EDIT_FILE_URI, | |
| 181 | + text: EDIT_CHANGES, | |
| 182 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 183 | + }); | |
| 184 | + }); | |
| 185 | + | |
| 186 | + // Extract stream ID and initiate mock streaming | |
| 187 | + const streamId = messengerPostSpy.mock.calls.find( | |
| 188 | + (call) => call[0] === "applyToFile", | |
| 189 | + )?.[1]?.streamId; | |
| 190 | + expect(streamId).toBeDefined(); | |
| 191 | + | |
| 192 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 193 | + status: "streaming", | |
| 194 | + streamId, | |
| 195 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 196 | + filepath: EDIT_FILE_URI, | |
| 197 | + }); | |
| 198 | + | |
| 199 | + // Mid stream, should show applying in notch | |
| 200 | + await getElementByTestId("notch-applying-text"); | |
| 201 | + await getElementByTestId("notch-applying-cancel-button"); | |
| 202 | + | |
| 203 | + // Close the stream | |
| 204 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 205 | + status: "done", | |
| 206 | + streamId, | |
| 207 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 208 | + filepath: EDIT_FILE_URI, | |
| 209 | + }); | |
| 210 | + | |
| 211 | + await waitFor(() => { | |
| 212 | + expect(messengerPostSpy).toHaveBeenCalledWith("acceptDiff", { | |
| 213 | + streamId, | |
| 214 | + filepath: EDIT_FILE_URI, | |
| 215 | + }); | |
| 216 | + }); | |
| 217 | + | |
| 218 | + // Close the stream, ensure response is shown and diff buttons are not present | |
| 219 | + ideMessenger.setChatResponseText(POST_EDIT_RESPONSE); | |
| 220 | + ideMessenger.mockMessageToWebview("updateApplyState", { | |
| 221 | + status: "closed", | |
| 222 | + streamId, | |
| 223 | + toolCallId: EDIT_TOOL_CALL_ID, | |
| 224 | + filepath: EDIT_FILE_URI, | |
| 225 | + }); | |
| 226 | + | |
| 227 | + await verifyNotPresentByTestId("edit-accept-button"); | |
| 228 | + await verifyNotPresentByTestId("edit-reject-button"); | |
| 229 | + | |
| 230 | + await getElementByText(POST_EDIT_RESPONSE); | |
| 231 | +}); |
modified gui/src/redux/slices/sessionSlice.ts +3 −1
| @@ -657,7 +657,9 @@ | ||
| 657 | 657 | (state: RootState, toolCallId?: string) => toolCallId, |
| 658 | 658 | ], |
| 659 | 659 | (states, toolCallId) => { |
| 660 | - return states.find((state) => state.toolCallId === toolCallId); | |
| 660 | + if (toolCallId) { | |
| 661 | + return states.find((state) => state.toolCallId === toolCallId); | |
| 662 | + } | |
| 661 | 663 | }, |
| 662 | 664 | ); |
| 663 | 665 |
modified gui/src/redux/store.ts +0 −5
| @@ -23,11 +23,6 @@ | ||
| 23 | 23 | import tabsReducer from "./slices/tabsSlice"; |
| 24 | 24 | import uiReducer from "./slices/uiSlice"; |
| 25 | 25 | |
| 26 | -export interface ChatMessage { | |
| 27 | - role: "system" | "user" | "assistant"; | |
| 28 | - content: string; | |
| 29 | -} | |
| 30 | - | |
| 31 | 26 | const rootReducer = combineReducers({ |
| 32 | 27 | session: sessionReducer, |
| 33 | 28 | ui: uiReducer, |
modified gui/src/redux/thunks/callCurrentTool.ts +2 −7
| @@ -19,7 +19,6 @@ | ||
| 19 | 19 | async (_, { dispatch, extra, getState }) => { |
| 20 | 20 | const state = getState(); |
| 21 | 21 | const toolCallState = selectCurrentToolCall(state); |
| 22 | - | |
| 23 | 22 | if (!toolCallState) { |
| 24 | 23 | return; |
| 25 | 24 | } |
| @@ -61,19 +60,15 @@ | ||
| 61 | 60 | ) { |
| 62 | 61 | // Tool is called on client side |
| 63 | 62 | const { |
| 64 | - output: clientToolOuput, | |
| 63 | + output: clientToolOutput, | |
| 65 | 64 | respondImmediately, |
| 66 | 65 | errorMessage: clientToolError, |
| 67 | 66 | } = await callClientTool(toolCallState, { |
| 68 | 67 | dispatch, |
| 69 | 68 | ideMessenger: extra.ideMessenger, |
| 70 | - streamId: state.session.codeBlockApplyStates.states.find( | |
| 71 | - (state) => | |
| 72 | - state.toolCallId && state.toolCallId === toolCallState.toolCallId, | |
| 73 | - )?.streamId, | |
| 74 | 69 | getState, |
| 75 | 70 | }); |
| 76 | - output = clientToolOuput; | |
| 71 | + output = clientToolOutput; | |
| 77 | 72 | errorMessage = clientToolError; |
| 78 | 73 | streamResponse = respondImmediately; |
| 79 | 74 | } else { |
modified gui/src/redux/thunks/edit.ts +3 −0
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | import { |
| 18 | 18 | newSession, |
| 19 | 19 | setActive, |
| 20 | + setInactive, | |
| 20 | 21 | setIsInEdit, |
| 21 | 22 | setMainEditorContentTrigger, |
| 22 | 23 | setMode, |
| @@ -61,6 +62,8 @@ | ||
| 61 | 62 | range: codeToEdit[0] as RangeInFileWithContents, |
| 62 | 63 | }); |
| 63 | 64 | |
| 65 | + dispatch(setInactive()); | |
| 66 | + | |
| 64 | 67 | if (response.status === "error") { |
| 65 | 68 | throw new Error(response.error); |
| 66 | 69 | } |
modified gui/src/redux/thunks/streamNormalInput.ts +6 −0
| @@ -8,6 +8,8 @@ | ||
| 8 | 8 | import { |
| 9 | 9 | abortStream, |
| 10 | 10 | addPromptCompletionPair, |
| 11 | + setActive, | |
| 12 | + setInactive, | |
| 11 | 13 | setToolGenerated, |
| 12 | 14 | streamUpdate, |
| 13 | 15 | } from "../slices/sessionSlice"; |
| @@ -53,6 +55,8 @@ | ||
| 53 | 55 | }; |
| 54 | 56 | } |
| 55 | 57 | |
| 58 | + dispatch(setActive()); | |
| 59 | + | |
| 56 | 60 | // Send request |
| 57 | 61 | const gen = extra.ideMessenger.llmStreamChat( |
| 58 | 62 | { |
| @@ -76,6 +80,8 @@ | ||
| 76 | 80 | next = await gen.next(); |
| 77 | 81 | } |
| 78 | 82 | |
| 83 | + dispatch(setInactive()); | |
| 84 | + | |
| 79 | 85 | // Attach prompt log and end thinking for reasoning models |
| 80 | 86 | if (next.done && next.value) { |
| 81 | 87 | dispatch(addPromptCompletionPair([next.value])); |
modified gui/src/redux/thunks/streamResponseAfterToolCall.ts +1 −7
| @@ -4,11 +4,7 @@ | ||
| 4 | 4 | import { renderContextItems } from "core/util/messageContent"; |
| 5 | 5 | import { getBaseSystemMessage } from "../../util"; |
| 6 | 6 | import { selectSelectedChatModel } from "../slices/configSlice"; |
| 7 | -import { | |
| 8 | - addContextItemsAtIndex, | |
| 9 | - setActive, | |
| 10 | - streamUpdate, | |
| 11 | -} from "../slices/sessionSlice"; | |
| 7 | +import { addContextItemsAtIndex, streamUpdate } from "../slices/sessionSlice"; | |
| 12 | 8 | import { ThunkApiType } from "../store"; |
| 13 | 9 | import { findToolCall } from "../util"; |
| 14 | 10 | import { resetStateForNewMessage } from "./resetStateForNewMessage"; |
| @@ -63,8 +59,6 @@ | ||
| 63 | 59 | }), |
| 64 | 60 | ); |
| 65 | 61 | |
| 66 | - dispatch(setActive()); | |
| 67 | - | |
| 68 | 62 | const updatedHistory = getState().session.history; |
| 69 | 63 | const messageMode = getState().session.mode; |
| 70 | 64 |
modified gui/src/redux/thunks/streamThunkWrapper.tsx +0 −2
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | import { createAsyncThunk } from "@reduxjs/toolkit"; |
| 2 | 2 | import StreamErrorDialog from "../../pages/gui/StreamError"; |
| 3 | -import { setInactive } from "../slices/sessionSlice"; | |
| 4 | 3 | import { setDialogMessage, setShowDialog } from "../slices/uiSlice"; |
| 5 | 4 | import { ThunkApiType } from "../store"; |
| 6 | 5 | import { cancelStream } from "./cancelStream"; |
| @@ -22,7 +21,6 @@ | ||
| 22 | 21 | }), |
| 23 | 22 | ); |
| 24 | 23 | } |
| 25 | - dispatch(setInactive()); | |
| 26 | 24 | } catch (e) { |
| 27 | 25 | dispatch(cancelStream()); |
| 28 | 26 | dispatch(setDialogMessage(<StreamErrorDialog error={e} />)); |
modified gui/src/util/clientTools/callClientTool.ts +0 −1
| @@ -8,7 +8,6 @@ | ||
| 8 | 8 | getState: () => RootState; |
| 9 | 9 | dispatch: AppThunkDispatch; |
| 10 | 10 | ideMessenger: IIdeMessenger; |
| 11 | - streamId?: string; | |
| 12 | 11 | } |
| 13 | 12 | |
| 14 | 13 | export interface ClientToolOutput { |
modified gui/src/util/clientTools/editImpl.ts +5 −24
| @@ -1,14 +1,11 @@ | ||
| 1 | 1 | import { resolveRelativePathInDir } from "core/util/ideUtils"; |
| 2 | +import { v4 as uuid } from "uuid"; | |
| 2 | 3 | import { ClientToolImpl } from "./callClientTool"; |
| 3 | - | |
| 4 | 4 | export const editToolImpl: ClientToolImpl = async ( |
| 5 | 5 | args, |
| 6 | 6 | toolCallId, |
| 7 | 7 | extras, |
| 8 | 8 | ) => { |
| 9 | - if (!extras.streamId) { | |
| 10 | - throw new Error("Invalid apply state"); | |
| 11 | - } | |
| 12 | 9 | const firstUriMatch = await resolveRelativePathInDir( |
| 13 | 10 | args.filepath, |
| 14 | 11 | extras.ideMessenger.ide, |
| @@ -16,30 +13,14 @@ | ||
| 16 | 13 | if (!firstUriMatch) { |
| 17 | 14 | throw new Error(`${args.filepath} does not exist`); |
| 18 | 15 | } |
| 19 | - const apply = await extras.ideMessenger.request("applyToFile", { | |
| 20 | - streamId: extras.streamId, | |
| 16 | + const streamId = uuid(); | |
| 17 | + extras.ideMessenger.post("applyToFile", { | |
| 18 | + streamId, | |
| 21 | 19 | text: args.changes, |
| 22 | 20 | toolCallId, |
| 23 | 21 | filepath: firstUriMatch, |
| 24 | 22 | }); |
| 25 | - if (apply.status === "error") { | |
| 26 | - throw new Error(apply.error); | |
| 27 | - } | |
| 28 | - const state = extras.getState(); | |
| 29 | - const autoAccept = !!state.config.config.ui?.autoAcceptEditToolDiffs; | |
| 30 | - if (autoAccept) { | |
| 31 | - const out = await extras.ideMessenger.request("acceptDiff", { | |
| 32 | - streamId: extras.streamId, | |
| 33 | - filepath: firstUriMatch, | |
| 34 | - }); | |
| 35 | - if (out.status === "error") { | |
| 36 | - throw new Error(out.error); | |
| 37 | - } | |
| 38 | - return { | |
| 39 | - respondImmediately: true, | |
| 40 | - output: undefined, // TODO - feed edit results back to model (also in parallel listeners) | |
| 41 | - }; | |
| 42 | - } | |
| 23 | + | |
| 43 | 24 | return { |
| 44 | 25 | respondImmediately: false, |
| 45 | 26 | output: undefined, // No immediate output. |
modified gui/src/util/index.ts +5 −5
| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | import { MessageModes, ModelDescription } from "core"; |
| 2 | 2 | import { ProfileDescription } from "core/config/ProfileLifecycleManager"; |
| 3 | -import _ from "lodash"; | |
| 4 | -import { KeyboardEvent } from "react"; | |
| 5 | -import { getLocalStorage } from "./localStorage"; | |
| 6 | 3 | import { |
| 7 | - DEFAULT_CHAT_SYSTEM_MESSAGE, | |
| 8 | 4 | DEFAULT_AGENT_SYSTEM_MESSAGE, |
| 5 | + DEFAULT_CHAT_SYSTEM_MESSAGE, | |
| 9 | 6 | } from "core/llm/constructMessages"; |
| 7 | +import _ from "lodash"; | |
| 8 | +import { KeyboardEvent as ReactKeyboardEvent } from "react"; | |
| 9 | +import { getLocalStorage } from "./localStorage"; | |
| 10 | 10 | |
| 11 | 11 | export type Platform = "mac" | "linux" | "windows" | "unknown"; |
| 12 | 12 | |
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | export function isMetaEquivalentKeyPressed({ |
| 27 | 27 | metaKey, |
| 28 | 28 | ctrlKey, |
| 29 | -}: KeyboardEvent): boolean { | |
| 29 | +}: KeyboardEvent | ReactKeyboardEvent): boolean { | |
| 30 | 30 | const platform = getPlatform(); |
| 31 | 31 | switch (platform) { |
| 32 | 32 | case "mac": |
added gui/src/util/test/config.ts +67 −0
| @@ -0,0 +1,67 @@ | ||
| 1 | +import { EnhancedStore } from "@reduxjs/toolkit"; | |
| 2 | +import { BrowserSerializedContinueConfig, ModelDescription } from "core"; | |
| 3 | +import { SerializedOrgWithProfiles } from "core/config/ProfileLifecycleManager"; | |
| 4 | +import { copyOf } from "core/util"; | |
| 5 | +import { MockIdeMessenger } from "../../context/MockIdeMessenger"; | |
| 6 | + | |
| 7 | +interface TestConfigUpdateParams { | |
| 8 | + store: EnhancedStore; | |
| 9 | + ideMessenger: MockIdeMessenger; | |
| 10 | + newProfileId?: string; | |
| 11 | + newOrgId?: string; | |
| 12 | + newOrgs?: SerializedOrgWithProfiles[]; | |
| 13 | + editConfig?: ( | |
| 14 | + current: BrowserSerializedContinueConfig, | |
| 15 | + ) => BrowserSerializedContinueConfig; | |
| 16 | +} | |
| 17 | + | |
| 18 | +export function triggerConfigUpdate({ | |
| 19 | + store, | |
| 20 | + ideMessenger, | |
| 21 | + editConfig, | |
| 22 | + newOrgs, | |
| 23 | + newOrgId, | |
| 24 | + newProfileId, | |
| 25 | +}: TestConfigUpdateParams) { | |
| 26 | + const state = store.getState(); | |
| 27 | + ideMessenger.mockMessageToWebview("configUpdate", { | |
| 28 | + organizations: newOrgs ?? state.profiles.organizations, | |
| 29 | + selectedOrgId: newOrgId ?? state.profiles.selectedOrganizationId, | |
| 30 | + profileId: newProfileId ?? state.profiles.selectedProfileId, | |
| 31 | + result: { | |
| 32 | + config: editConfig | |
| 33 | + ? editConfig(copyOf(state.config.config)) | |
| 34 | + : state.config.config, | |
| 35 | + configLoadInterrupted: false, | |
| 36 | + errors: [], | |
| 37 | + }, | |
| 38 | + }); | |
| 39 | +} | |
| 40 | + | |
| 41 | +export function addAndSelectChatModel( | |
| 42 | + store: EnhancedStore, | |
| 43 | + ideMessenger: MockIdeMessenger, | |
| 44 | + llmDesc: ModelDescription, | |
| 45 | +) { | |
| 46 | + triggerConfigUpdate({ | |
| 47 | + store, | |
| 48 | + ideMessenger, | |
| 49 | + editConfig(current) { | |
| 50 | + current.modelsByRole.chat.push(llmDesc); | |
| 51 | + current.selectedModelByRole.chat = llmDesc; | |
| 52 | + return current; | |
| 53 | + }, | |
| 54 | + }); | |
| 55 | +} | |
| 56 | + | |
| 57 | +export function addAndSelectMockLlm( | |
| 58 | + store: EnhancedStore, | |
| 59 | + ideMessenger: MockIdeMessenger, | |
| 60 | +) { | |
| 61 | + addAndSelectChatModel(store, ideMessenger, { | |
| 62 | + model: "mock", | |
| 63 | + provider: "mock", | |
| 64 | + title: "Mock LLM", | |
| 65 | + underlyingProviderName: "mock", | |
| 66 | + }); | |
| 67 | +} |
added gui/src/util/test/utils.ts +102 −0
| @@ -0,0 +1,102 @@ | ||
| 1 | +import { screen, waitFor } from "@testing-library/dom"; | |
| 2 | +import { act } from "@testing-library/react"; | |
| 3 | +import { Editor } from "@tiptap/core"; | |
| 4 | +import { ChatMessage } from "core"; | |
| 5 | +import { MockIdeMessenger } from "../../context/MockIdeMessenger"; | |
| 6 | + | |
| 7 | +function logDomText() { | |
| 8 | + const bodyText = document.body.innerHTML; | |
| 9 | + const parser = new DOMParser(); | |
| 10 | + const doc = parser.parseFromString(bodyText, "text/html"); | |
| 11 | + let cleaned = doc.body.textContent ?? ""; | |
| 12 | + cleaned = cleaned?.replace( | |
| 13 | + "No resultsAaModelsRulesDocsPromptsToolsMCPCreate your first assistant", | |
| 14 | + "", | |
| 15 | + ); | |
| 16 | + cleaned = cleaned?.replace( | |
| 17 | + "Alt⏎ Active file⏎ Enter⏎Log in to access a free trial of theModels Add-OnLog in to Continue HubOr, configure your own models", | |
| 18 | + "", | |
| 19 | + ); | |
| 20 | + cleaned = cleaned.replaceAll("Select model", ""); | |
| 21 | + cleaned = cleaned.replaceAll("Mock LLM", ""); | |
| 22 | + cleaned = cleaned.replaceAll(/^Chat|Chat$/g, ""); | |
| 23 | + console.log(cleaned || "No body content"); | |
| 24 | +} | |
| 25 | + | |
| 26 | +export function logAllTestIds() { | |
| 27 | + const elements = document.querySelectorAll("*"); | |
| 28 | + | |
| 29 | + const testIds = Array.from(elements) | |
| 30 | + .map((el) => Array.from(el.attributes)) | |
| 31 | + .flat() | |
| 32 | + .filter((a) => a.name === "data-testid") | |
| 33 | + .map((a) => a.value); | |
| 34 | + console.log("Available test ids", testIds); | |
| 35 | +} | |
| 36 | +export async function getElementByTestId(testId: string): Promise<HTMLElement> { | |
| 37 | + try { | |
| 38 | + const testIdElement = await waitFor(() => screen.findByTestId(testId)); | |
| 39 | + expect(testIdElement).toBeInTheDocument(); | |
| 40 | + return testIdElement; | |
| 41 | + } catch (e) { | |
| 42 | + logAllTestIds(); | |
| 43 | + throw new Error(`Element with testId "${testId}" not found`); | |
| 44 | + } | |
| 45 | +} | |
| 46 | + | |
| 47 | +export async function verifyNotPresentByTestId(testId: string): Promise<void> { | |
| 48 | + const element = await waitFor(() => screen.queryByTestId(testId)); | |
| 49 | + expect(element).not.toBeInTheDocument(); | |
| 50 | +} | |
| 51 | + | |
| 52 | +export async function verifyNotPresentByText(text: string): Promise<void> { | |
| 53 | + const element = screen.queryByText(text); | |
| 54 | + expect(element).not.toBeInTheDocument(); | |
| 55 | +} | |
| 56 | + | |
| 57 | +export async function getElementByText(text: string): Promise<HTMLElement> { | |
| 58 | + try { | |
| 59 | + const textElement = await waitFor(() => screen.findByText(text)); | |
| 60 | + expect(textElement).toBeInTheDocument(); | |
| 61 | + return textElement; | |
| 62 | + } catch (e) { | |
| 63 | + logDomText(); | |
| 64 | + throw new Error(`Element with text "${text}" not found.`); | |
| 65 | + } | |
| 66 | +} | |
| 67 | + | |
| 68 | +export async function getMainEditor(): Promise<Editor> { | |
| 69 | + const editorElement = await getElementByTestId("editor-input-main"); | |
| 70 | + if ("editor" in editorElement) { | |
| 71 | + return editorElement.editor as Editor; | |
| 72 | + } else { | |
| 73 | + throw new Error("Main editor not found within editor container"); | |
| 74 | + } | |
| 75 | +} | |
| 76 | + | |
| 77 | +export async function sendInputWithMockedResponse( | |
| 78 | + ideMessenger: MockIdeMessenger, | |
| 79 | + input: string, | |
| 80 | + response: ChatMessage[], | |
| 81 | +): Promise<void> { | |
| 82 | + // Setup the mock response before any actions | |
| 83 | + ideMessenger.chatResponse = response; | |
| 84 | + | |
| 85 | + // Wait for the editor to be in the document | |
| 86 | + const editor = await getMainEditor(); | |
| 87 | + | |
| 88 | + // Find the submit button | |
| 89 | + const sendButton = await getElementByTestId("submit-input-button"); | |
| 90 | + | |
| 91 | + // Insert content into the editor | |
| 92 | + await act(async () => { | |
| 93 | + editor.commands.insertContent(input); | |
| 94 | + }); | |
| 95 | + | |
| 96 | + await getElementByText(input); | |
| 97 | + | |
| 98 | + // Click the send button | |
| 99 | + await act(async () => { | |
| 100 | + sendButton.click(); | |
| 101 | + }); | |
| 102 | +} |
modified gui/vite.config.ts +13 −0
| @@ -32,5 +32,18 @@ | ||
| 32 | 32 | globals: true, |
| 33 | 33 | environment: "jsdom", |
| 34 | 34 | setupFiles: "./src/util/test/setupTests.ts", |
| 35 | + onConsoleLog(log, type) { | |
| 36 | + if (type === "stderr") { | |
| 37 | + if ( | |
| 38 | + [ | |
| 39 | + "contentEditable", | |
| 40 | + "An update to Chat inside a test was not wrapped in act", | |
| 41 | + ].some((text) => log.includes(text)) | |
| 42 | + ) { | |
| 43 | + return false; | |
| 44 | + } | |
| 45 | + } | |
| 46 | + return true; | |
| 47 | + }, | |
| 35 | 48 | }, |
| 36 | 49 | }); |
modified packages/config-yaml/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
added scripts/build-packages.ps1 +13 −0
| @@ -0,0 +1,13 @@ | ||
| 1 | +Push-Location packages | |
| 2 | + | |
| 3 | +Push-Location "openai-adapters" | |
| 4 | +npm ci | |
| 5 | +npm run build | |
| 6 | +Pop-Location | |
| 7 | + | |
| 8 | +Push-Location "config-yaml" | |
| 9 | +npm ci | |
| 10 | +npm run build | |
| 11 | +Pop-Location | |
| 12 | + | |
| 13 | +Pop-Location | |
| No newline at the end of the file |
added scripts/build-packages.sh +13 −0
| @@ -0,0 +1,13 @@ | ||
| 1 | +# Build @continuedev packages for monorepo style linking | |
| 2 | + | |
| 3 | +cd packages | |
| 4 | +cd openai-adapters | |
| 5 | + | |
| 6 | +npm ci | |
| 7 | +npm run build | |
| 8 | + | |
| 9 | +cd .. | |
| 10 | +cd config-yaml | |
| 11 | + | |
| 12 | +npm ci | |
| 13 | +npm run build |
modified scripts/install-dependencies.sh +1 −1
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | # This does way too many things inline but is the common denominator between many of the scripts |
| 58 | 58 | npm install |
| 59 | 59 | npm link @continuedev/core |
| 60 | -npm run prepackage | |
| 60 | +# npm run prepackage # not required since npm run package has prescript of prepackage | |
| 61 | 61 | npm run package |
| 62 | 62 | popd |
| 63 | 63 |