feat: download ADK Web assets dynamically and serve from shared folder#427
feat: download ADK Web assets dynamically and serve from shared folder#427kalenkevich wants to merge 2 commits into
Conversation
- Remove pre-compiled `dev/src/browser` assets from git tracking to keep the repository source tree clean. - Update `dev/build.js` to automatically download and cache `v1.0.0` release assets from GitHub, and extract them directly into `dist/browser`. - Modify the static path in `AdkApiServer` (`dev/src/server/adk_api_server.ts`) to serve `/dev-ui` from `../../browser` relative to target compiled outputs, enabling both ESM and CommonJS distributions to share a single `dist/browser` directory. - Update `.gitignore` to ignore the local `dev/.cache/` folder and untrack the old `dev/src/browser/` folder.
| ) { | ||
| // Follow redirect | ||
| downloadFile(response.headers.location, dest) | ||
| .then(resolve) |
There was a problem hiding this comment.
Call response.resume() before recursing/returning here to ensure the redirected response stream is fully consumed and socket resources are released.
| ); | ||
| } else { | ||
| execSync(`unzip -o "${zipPath}" -d "${destDir}"`); | ||
| } |
There was a problem hiding this comment.
Since adm-zip was recently added to the core workspace dependencies, we can use it here as a platform-independent JS library for unzipping, instead of spawning child processes for unzip (which might be missing on minimal Linux environments) or powershell (which can have execution policies block it):
import AdmZip from 'adm-zip';
function unzipFile(zipPath, destDir) {
const zip = new AdmZip(zipPath);
zip.extractAllTo(destDir, true);
}Make sure to add adm-zip to the dev package dependencies/devDependencies too.
| } | ||
| const url = `https://github.com/google/adk-web/releases/download/${ADK_WEB_VERSION}/adk-web-browser.zip`; | ||
| await downloadFile(url, zipCachePath); | ||
| console.log( |
There was a problem hiding this comment.
To prevent corrupt cache files if the download gets interrupted mid-way (which would skip downloads and fail during unzipping on subsequent runs), consider downloading to a temporary file (e.g. zipCachePath + '.tmp') and renaming it to zipCachePath only after completion.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Problem:
dev/src/browser) bloats the codebase, clutters git history, and is error-prone to maintain.dist/esm/browseranddist/cjs/browsertargets duplicates the assets (~5MB each), resulting in unnecessary package bloat for@google/adk-devtools.Solution:
downloadFile) and extractor (ensureBrowserAssets) indev/build.jsto dynamically fetch the ADK Web UI releasev1.0.0from GitHub and cache the zip locally indev/.cache/.dist/browserinside the build output. ModifiedAdkApiServer(dev/src/server/adk_api_server.ts) to serve/dev-uifrom../../browserrelative to the compiled server files, allowing both ESM and CommonJS targets to sharedist/browserand saving 50% of package asset space.dev/src/browserdirectory and addeddev/.cache/to.gitignore.Testing Plan
Unit Tests:
Summary of passed npm test results:
Ran the full devtools unit test suite:
npx vitest run dev/testManual End-to-End (E2E) Tests:
Tested by running a clean build setup from scratch:
npm run clean:allto deletenode_modulesand alldist/folders.npm install.npm run build.dist/browser/contains all Web UI files, and that nodev/src/browser/folder was created in the source tree.npm run buildagain. Output correctly skipped the download/extraction (runs instantly) becausedist/browser/.versionmatches.npx vitest run tests/integration/adk_web/webui_test.ts) which verify/dev-uiserves the correct html containing<app-root>: Passed (2/2 tests).Checklist
Additional context
This is a follow-up optimization of the ADK Web UI serving architecture. It keeps binary-compiled assets out of source control and reduces the published npm package size by sharing a single output directory.