Repository navigation
fix(core): keep winston out of the published browser build by splitting the logger by platform - #813
Merged
kalenkevich merged 2 commits intoSep 9, 2026
Conversation
`core/src/utils/logger.ts` imported `winston`, and the browser entry point reaches that module through `common.ts`. The published web build is transpile-only, so esbuild passes the specifier through unchanged and `core/dist/web/utils/logger.js` shipped `import * as winston from "winston"`, which no browser bundler can resolve. Split the logger by platform instead. `utils/logger.ts` now writes through `console`, so it works in both runtimes, and the winston implementation moves unchanged into the new `utils/logger_node.ts`. The Node entry point installs it through the existing `setLogger` seam. winston stays a `core` dependency and stays the logger on Node: the class body in `logger_node.ts` is byte-for-byte the one that was in `logger.ts`, so Node output is unchanged down to the ANSI colour codes. Only the browser build stops naming the package. `load_artifacts_tool.ts` and `vertex_ai_search_tool.ts` held `const logger = getLogger()` at module scope. `installNodeLogger()` runs after `index.ts` evaluates its re-exports, so those two modules would have captured the console logger for the process lifetime, out of reach of `setLogLevel()`. Both now log through the `logger` facade that the other importers already use. Part of: #611 Related: #607
This was referenced Aug 26, 2026
kalenkevich
reviewed
Sep 9, 2026
|
|
||
| this.logger.log(level.toString(), messages.join(' ')); | ||
| const timestamp = new Date().toISOString(); | ||
| const line = `${LogLevel[level]}: [ADK] ${timestamp} ${messages.join(' ')}`; |
Collaborator
There was a problem hiding this comment.
we need to support color as well
Collaborator
Author
There was a problem hiding this comment.
Done in e353c41. The new BrowserLogger colours the level with a %c CSS directive, which browser dev consoles render (winston still colours the Node side with ANSI).
Collaborator
There was a problem hiding this comment.
I think it make sense to create BrowserLogger and installBrowserLogger util function in the same manner you did for Node env.
Collaborator
Author
There was a problem hiding this comment.
Added in e353c41. BrowserLogger and installBrowserLogger() now live in core/src/utils/logger_browser.ts, wired into index_web.ts — the same split as WinstonLogger / installNodeLogger on Node.
…entry Mirror the Node logger split: a dedicated BrowserLogger class plus an installBrowserLogger() wired into index_web.ts, in the same manner as WinstonLogger / installNodeLogger. The browser logger colours the level with a %c CSS directive, which browser dev consoles render.
kalenkevich
approved these changes
Sep 9, 2026
Merged
AmaadMartin
pushed a commit
that referenced
this pull request
Sep 10, 2026
… platform Rebasing onto main brought in #813, which keeps winston out of the browser build by splitting the logger into logger_node (winston) and logger_browser (console). The browser entry installs logger_browser and never imports winston, so this PR's winston->shim alias and winston_shim.ts are dead code and are removed. node_build_test now reads utils/logger_node.js, where winston lives after the split, instead of utils/logger.js.
7 tasks done
AmaadMartin
added a commit
that referenced
this pull request
Sep 10, 2026
* Fix: make dist/web parseable and free of the Node createRequire banner Two defects in the browser build output, both invisible to the existing suite because it runs against src rather than the built artifacts. 1. `models/apigee_llm.js` did not parse. The browser target named chrome58/safari11, which predate native async generators, so esbuild downlevelled `yield* super.generateContentAsync(...)` into an __asyncGenerator closure and emitted `super` inside it. Raising the target to chrome63/safari12 keeps async generators native. This was a hard blocker: LlmAgent -> models/registry -> apigee_llm, so no browser consumer could avoid it, and no bundler configuration can parse invalid syntax. 2. Every file in dist/web carried the Node `createRequire` banner, because the banner was gated on `format === 'esm'` and the web build is also ESM. 187 files imported `module`; none ever called require(). Bundling dist/web/agents/llm_agent.js for the browser goes from 86 errors to 21, and dist/web/index_web.js from 346 to 198. The remainder is winston and node:async_hooks, tracked separately. Adds a regression test over the build output, which is currently unguarded. Verified it fails without this change, reporting all 198 bannered files and naming models/apigee_llm.js as unparseable. Fixes #608 Fixes #609 Part of #607 * test: bundle and execute the compiled web output, not just parse it Addresses review feedback asking for a test that loads compiled ADK and checks it actually works. Parsing is necessary but not sufficient: it would not catch output that bundles and then throws on import, or a primitive that is broken once compiled for the browser. This bundles entry points from dist/web with --platform=browser and runs them — constructing a FunctionTool, checking the declaration a model would receive, and executing it. The entry-point list is short because most of dist/web still cannot be bundled: the barrel pulls skills/loader (node:fs, node:path) and the logger pulls winston. agents/llm_agent.js and runner/runner.js are the two worth adding next and are one dependency away each. Verified all three new tests fail against an unpatched build. * Fix: make the whole web build bundle and run in a browser Follows review feedback asking that the entire ADK TS web bundle be tested, not a subset. Getting there needed the remaining two defects fixed rather than deferred. Bundle the web target always. esbuild rejects `alias` unless bundling, so the existing node:async_hooks shim never reached published output -- `npm run build` does not pass --bundle. Bundling the web target makes the alias mechanism work, and the emitted filename now follows the entry so package.json's "browser" field still resolves. Add a browser stand-in for winston. utils/logger.ts pulls winston into every module that logs, and winston needs os/fs/util/zlib/http. The shim implements only the surface logger.ts uses and writes to the console, which is what a browser transport does. Keep Node-only modules out of the web barrel. index.ts already holds the Node-only exports and index_web.ts is common.ts alone, so common.ts is meant to be the browser-safe surface -- but exports reaching node:fs, node:dns, adm-zip, google-auth-library and @google-cloud/vertexai had leaked into it. Those move to index.ts alongside the ones already there. The set was derived by bundling all 199 source modules for the browser and recording which reach a Node-only dependency, not chosen by hand. core/dist/web/index_web.js now bundles for --platform=browser with zero errors, down from 346. The bundle imports and drives the public API: LlmAgent, ParallelAgent, SequentialAgent, LoopAgent, FunctionTool, Runner, InMemorySessionService and BaseLlm are all present and working. The Node public API is unchanged -- 206 exports from dist/esm/index.js before and after, verified by diffing the resolved export lists. Mutation check: reverting only the common.ts hunk makes the bundle step fail with 173 unresolved Node imports, vitest exits 1 and reports the file as failed. * test: run ADK in a real headless browser, and ship a self-contained web bundle Replaces the synthetic bundle test with the real thing, per review. tests/integration/build_setup/web_app/ is a small chat page -- message list, prompt input, send button -- that imports core/dist/web/index_web.js directly, with no build step of its own. web_app_test.ts drives it in headless Chromium with Playwright: types a message, clicks send, and asserts the user message and the agent reply both render, then runs a second turn on the same session. The model is a BaseLlm subclass returning a canned response, matching the mock in the existing build_setup fixtures. Page errors and console errors fail the test, so a DOM or module-loading failure surfaces instead of passing silently. Making that possible meant the web target had to become genuinely self-contained. It was bundled but kept `packages: 'external'`, so the output still imported '@google/genai', 'zod' and friends as bare specifiers, which a browser cannot resolve. The web target now bundles its dependencies; Node keeps packages external as before. 972 KB. Splits the build-output tests as requested: web_build_test.ts covers dist/web only, and the Node ESM/CJS assertions move to node_build_test.ts. Drops the assertions that re-bundled dist/web inside the test -- the shipped artifact is already a bundle, and the browser test now exercises it directly. Adds playwright-chromium and a CI step to install the browser. * fix: drop the winston browser shim now that main splits the logger by platform Rebasing onto main brought in #813, which keeps winston out of the browser build by splitting the logger into logger_node (winston) and logger_browser (console). The browser entry installs logger_browser and never imports winston, so this PR's winston->shim alias and winston_shim.ts are dead code and are removed. node_build_test now reads utils/logger_node.js, where winston lives after the split, instead of utils/logger.js. --------- Co-authored-by: Amaad Martin <[email protected]>
prasanna8585
pushed a commit
to prasanna8585/adk-js
that referenced
this pull request
Nov 10, 2026
…ng the logger by platform (google#813) * fix(core): keep winston out of the published browser build `core/src/utils/logger.ts` imported `winston`, and the browser entry point reaches that module through `common.ts`. The published web build is transpile-only, so esbuild passes the specifier through unchanged and `core/dist/web/utils/logger.js` shipped `import * as winston from "winston"`, which no browser bundler can resolve. Split the logger by platform instead. `utils/logger.ts` now writes through `console`, so it works in both runtimes, and the winston implementation moves unchanged into the new `utils/logger_node.ts`. The Node entry point installs it through the existing `setLogger` seam. winston stays a `core` dependency and stays the logger on Node: the class body in `logger_node.ts` is byte-for-byte the one that was in `logger.ts`, so Node output is unchanged down to the ANSI colour codes. Only the browser build stops naming the package. `load_artifacts_tool.ts` and `vertex_ai_search_tool.ts` held `const logger = getLogger()` at module scope. `installNodeLogger()` runs after `index.ts` evaluates its re-exports, so those two modules would have captured the console logger for the process lifetime, out of reach of `setLogLevel()`. Both now log through the `logger` facade that the other importers already use. Part of: google#611 Related: google#607 * fix(core): add a colour-aware BrowserLogger installed by the browser entry Mirror the Node logger split: a dedicated BrowserLogger class plus an installBrowserLogger() wired into index_web.ts, in the same manner as WinstonLogger / installNodeLogger. The browser logger colours the level with a %c CSS directive, which browser dev consoles render. --------- Co-authored-by: Amaad Martin <[email protected]>
prasanna8585
pushed a commit
to prasanna8585/adk-js
that referenced
this pull request
Nov 10, 2026
* Fix: make dist/web parseable and free of the Node createRequire banner Two defects in the browser build output, both invisible to the existing suite because it runs against src rather than the built artifacts. 1. `models/apigee_llm.js` did not parse. The browser target named chrome58/safari11, which predate native async generators, so esbuild downlevelled `yield* super.generateContentAsync(...)` into an __asyncGenerator closure and emitted `super` inside it. Raising the target to chrome63/safari12 keeps async generators native. This was a hard blocker: LlmAgent -> models/registry -> apigee_llm, so no browser consumer could avoid it, and no bundler configuration can parse invalid syntax. 2. Every file in dist/web carried the Node `createRequire` banner, because the banner was gated on `format === 'esm'` and the web build is also ESM. 187 files imported `module`; none ever called require(). Bundling dist/web/agents/llm_agent.js for the browser goes from 86 errors to 21, and dist/web/index_web.js from 346 to 198. The remainder is winston and node:async_hooks, tracked separately. Adds a regression test over the build output, which is currently unguarded. Verified it fails without this change, reporting all 198 bannered files and naming models/apigee_llm.js as unparseable. Fixes google#608 Fixes google#609 Part of google#607 * test: bundle and execute the compiled web output, not just parse it Addresses review feedback asking for a test that loads compiled ADK and checks it actually works. Parsing is necessary but not sufficient: it would not catch output that bundles and then throws on import, or a primitive that is broken once compiled for the browser. This bundles entry points from dist/web with --platform=browser and runs them — constructing a FunctionTool, checking the declaration a model would receive, and executing it. The entry-point list is short because most of dist/web still cannot be bundled: the barrel pulls skills/loader (node:fs, node:path) and the logger pulls winston. agents/llm_agent.js and runner/runner.js are the two worth adding next and are one dependency away each. Verified all three new tests fail against an unpatched build. * Fix: make the whole web build bundle and run in a browser Follows review feedback asking that the entire ADK TS web bundle be tested, not a subset. Getting there needed the remaining two defects fixed rather than deferred. Bundle the web target always. esbuild rejects `alias` unless bundling, so the existing node:async_hooks shim never reached published output -- `npm run build` does not pass --bundle. Bundling the web target makes the alias mechanism work, and the emitted filename now follows the entry so package.json's "browser" field still resolves. Add a browser stand-in for winston. utils/logger.ts pulls winston into every module that logs, and winston needs os/fs/util/zlib/http. The shim implements only the surface logger.ts uses and writes to the console, which is what a browser transport does. Keep Node-only modules out of the web barrel. index.ts already holds the Node-only exports and index_web.ts is common.ts alone, so common.ts is meant to be the browser-safe surface -- but exports reaching node:fs, node:dns, adm-zip, google-auth-library and @google-cloud/vertexai had leaked into it. Those move to index.ts alongside the ones already there. The set was derived by bundling all 199 source modules for the browser and recording which reach a Node-only dependency, not chosen by hand. core/dist/web/index_web.js now bundles for --platform=browser with zero errors, down from 346. The bundle imports and drives the public API: LlmAgent, ParallelAgent, SequentialAgent, LoopAgent, FunctionTool, Runner, InMemorySessionService and BaseLlm are all present and working. The Node public API is unchanged -- 206 exports from dist/esm/index.js before and after, verified by diffing the resolved export lists. Mutation check: reverting only the common.ts hunk makes the bundle step fail with 173 unresolved Node imports, vitest exits 1 and reports the file as failed. * test: run ADK in a real headless browser, and ship a self-contained web bundle Replaces the synthetic bundle test with the real thing, per review. tests/integration/build_setup/web_app/ is a small chat page -- message list, prompt input, send button -- that imports core/dist/web/index_web.js directly, with no build step of its own. web_app_test.ts drives it in headless Chromium with Playwright: types a message, clicks send, and asserts the user message and the agent reply both render, then runs a second turn on the same session. The model is a BaseLlm subclass returning a canned response, matching the mock in the existing build_setup fixtures. Page errors and console errors fail the test, so a DOM or module-loading failure surfaces instead of passing silently. Making that possible meant the web target had to become genuinely self-contained. It was bundled but kept `packages: 'external'`, so the output still imported '@google/genai', 'zod' and friends as bare specifiers, which a browser cannot resolve. The web target now bundles its dependencies; Node keeps packages external as before. 972 KB. Splits the build-output tests as requested: web_build_test.ts covers dist/web only, and the Node ESM/CJS assertions move to node_build_test.ts. Drops the assertions that re-bundled dist/web inside the test -- the shipped artifact is already a bundle, and the browser test now exercises it directly. Adds playwright-chromium and a CI step to install the browser. * fix: drop the winston browser shim now that main splits the logger by platform Rebasing onto main brought in google#813, which keeps winston out of the browser build by splitting the logger into logger_node (winston) and logger_browser (console). The browser entry installs logger_browser and never imports winston, so this PR's winston->shim alias and winston_shim.ts are dead code and are removed. node_build_test now reads utils/logger_node.js, where winston lives after the split, instead of utils/logger.js. --------- Co-authored-by: Amaad Martin <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
Part of: Web build leaks Node-only deps: the async_hooks shim is gated behind --bundle (never applied), and winston has no shim #611
Related: Tracking: @google/adk cannot be bundled for the browser (5 build-level defects) #607, perf(core): make winston an optional peer, ~26 fewer packages on install #785
Problem:
core/src/utils/logger.tsimportswinston, and the browser entry point reaches that module throughcommon.ts(which re-exportsLogLevel,getLogger,setLogLevel,setLogger). The published web build is transpile-only, so esbuild passes the specifier through unchanged.core/dist/web/utils/logger.jstherefore shipsimport * as winston from "winston", which no browser bundler can resolve.Solution: split the logger by platform.
utils/logger.tsnow writes throughconsole, so it works in both runtimes and names no package at all.utils/logger_node.ts, unchanged — the class body is byte-for-byte the one that was inlogger.ts; only the class name differs (SimpleLogger→WinstonLogger).core/src/index.ts(the Node entry point) installs it through the existingsetLoggerseam.core/package.jsonis untouched:"winston": "^3.19.0"stays independencies.An esbuild
aliascannot solve this: esbuild rejectsaliaswithoutbundle, and the published web build does not bundle. So theplatform === 'browser' && bundlegate and the rest ofcore/build.jsare left as they are.Call-site change:
load_artifacts_tool.tsandvertex_ai_search_tool.tsheldconst logger = getLogger()at module scope.installNodeLogger()runs afterindex.tsevaluates its re-exports, so those two modules would have captured the console logger for the process lifetime, out of reach ofsetLogLevel(). Both now log through theloggerfacade that the other importers already use. That is the only call-site change here.Behaviour notes
@google/adk/a2a,@google/adk/tools/mcp,@google/adk/artifacts/gcsand@google/adk/telemetry/gcpdeliberately do not evaluate the main barrel, so they do not runinstallNodeLogger(). A consumer importing only a sub-path on Node gets the console logger rather than winston. Both emit the same line —LEVEL: [ADK] <ISO timestamp> <message>— so the only observable difference is winston's ANSI colouring. I left this alone rather than sprinkling install calls across five modules, which would also let a late sub-path import clobber a user'ssetLogger(). Happy to wire the sub-paths up in a follow-up if you'd prefer them to match.resetLogger()now installs the console logger on Node too. It is internal: it is not exported fromindex.ts,common.tsorindex_web.ts, and only core's own tests call it.dist/esm/utils/logger.jswould get the console logger, but theexportsmap does not expose that path.dist/webstill contains an emittedutils/logger_node.js, and it still nameswinston. It is an orphan — nothing in thedist/webgraph imports it (measured below). Excluding it from the transpile-only build would hide the day a*_node.tsmodule does become reachable, so the build is left alone. Note it is technically fetchable via the./dist/web/*export wildcard, but only by explicitly deep-importing a_nodefile.logger.log(level, ...)on Node still throws inside winston, because it passes the numeric enum value as the level name. That is pre-existing behaviour, preserved here and pinned bylogger_node_test.ts. The console logger emits normally.common.tsis untouched and no symbol is added or removed.Testing Plan
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
vitest run --project unit:core— 233 files, 3456 tests, all passing.The four files this PR touches:
logger_test.ts,logger_node_test.ts,logger_node_wiring_test.ts,tool_logging_test.ts— 30 passed.logger_test.tsgains the consoleSimpleLoggercases and abrowser safetyblock. That block reads both sources:logger.tsmust contain noimport, andlogger_node.tsmust still importwinston— so the first assertion cannot be satisfied by deleting the dependency, which is what makes this different from Fix: replace winston with a console logger in core to unbreak the web build #617 at the test level.logger_node_test.ts(new) captures the Console transport output and checks the line format, the colorized level, level gating and argument joining.logger_node_wiring_test.ts(new) imports@google/adkand asserts the entry point installed the winston logger.tool_logging_test.ts(new) drivesLoadArtifactsToolandVertexAiSearchToolagainst real in-memory session and artifact services, no mocks.npm run lint,npm run format:check— clean.tsc --noEmitreports the same 4 pre-existing errors on this branch and onmain(allCannot find module '@google/adk-devtools', an unbuilt workspace package), with an identical breakdown.Evidence 1 — winston leaves the browser graph
Bundling the browser entry point lists every bare specifier a browser bundler would have to resolve. Same command on
mainand on this branch:Both reach 193 modules. The external lists are identical except for one entry:
main@google-cloud/vertexai, @google/genai, @opentelemetry/api, adm-zip, google-auth-library, js-yaml, jsonpath-plus, lodash-es, node:async_hooks, node:buffer, node:crypto, node:dns/promises, node:fs/promises, node:net, node:os, node:path, uuid, **winston**, zod, zod-to-json-schema, zod/v4@google-cloud/vertexai, @google/genai, @opentelemetry/api, adm-zip, google-auth-library, js-yaml, jsonpath-plus, lodash-es, node:async_hooks, node:buffer, node:crypto, node:dns/promises, node:fs/promises, node:net, node:os, node:path, uuid, zod, zod-to-json-schema, zod/v4winstonis the single-variable difference. The remainingnode:specifiers are the other half of #611 and are out of scope here.Walking the published
dist/weboutput afternpm run buildconfirms the same on the shipped artifact:Evidence 2 — winston stays on Node
The active logger on Node is still winston:
And Node output is unchanged. The same script on
mainand on this branch, timestamps normalized,diffclean — including winston's ANSI colour codes:dist/esm,dist/cjsanddist/webstill mirrorcore/srcfile for file, as before.Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.