fix(coding-agent): emit the Bedrock provider into the CLI bundle - #1085
Closed
pmclaugh wants to merge 1 commit into
Closed
fix(coding-agent): emit the Bedrock provider into the CLI bundle#1085pmclaugh wants to merge 1 commit into
pmclaugh wants to merge 1 commit into
Conversation
Contributor
|
Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1158, authored independently from We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1158 and is being closed. The complete review stack is #1158–#1165. It is being left unmerged for human review after CI and review-bot findings are cleared. |
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.
Bedrock provider is missing from the CLI bundle
Summary
The published
bin(dist/bundle/cli.js) cannot use any Bedrock model. The firstrequest fails with:
dist/built unbundled works fine, and the compiled Bun binary works, so this onlyaffects npm/node installs -- which is every
npm i -g prime-agentuser.Root cause
packages/ai/src/providers/register-builtins.tsloads nine providers lazily. Eight usea literal specifier that esbuild resolves and emits as a chunk:
Bedrock deliberately goes through a variable specifier so browser bundles do not pull
in the AWS SDK:
esbuild cannot resolve a variable specifier, so it emits no chunk and no warning. At
runtime the import still resolves relative to the emitted chunk directory, to a file
that was never written.
Confirmed by building at
a18809e0: chunks appear for all eight literal-specifierproviders and
dist/bundle/amazon-bedrock.jsis absent.The indirection itself is correct and load-bearing -- removing it (making the specifier
literal) makes
npm run checkfail, because the AWS SDK then enters the browser smokebuild and
@smithy/node-http-handlercannot resolvenode:http. So the provider muststay invisible to static analysis, and the bundler has to be told about it explicitly.
Fix
Declare the provider as a second bundle entry named after the specifier the runtime
uses, so the file lands exactly where the import looks.
splitting: truekeeps it alazily loaded chunk, so the AWS SDK is still only read when a Bedrock model is used.
The entry imports only pi-ai's public
./bedrock-providerexport and re-exports the twonames
loadBedrockProviderModule()destructures.packages/aiis untouched.Because esbuild cannot verify this emission,
scripts/bundle.mjsnow asserts theartifact exists and fails the build otherwise -- the original failure mode was a silent
omission that only surfaced at runtime for one provider.
Verification
dist/bundle/amazon-bedrock.jsemitted (679 KB) and exportsstreamBedrockandstreamSimpleBedrockas functions.closure of
cli.js(2 files, 4 KB eager).cli.jsunchanged in name, size and0755mode.npm run checkpasses, including the browser smoke build.bundle is missing .../amazon-bedrock.js, and the new test fails.Tests
packages/coding-agent/test/bundle-bedrock-entry.test.tsasserts the coupling betweenthe runtime specifier in
register-builtins.tsand the entry names inbundle.mjs,and that the entry bundles to a provider-shaped module. Nothing in the type system
relates those two files, which is why this broke silently.
Note
Emit the Bedrock provider as a separate chunk in the CLI bundle
streamBedrockandstreamSimpleBedrock, allowing the bundler to emit anamazon-bedrock.jschunk resolvable by the runtime dynamic import.cliandamazon-bedrock) and adds a post-build guard that throws ifdist/bundle/amazon-bedrock.jswas not emitted.Macroscope summarized 68e1ed1.