Repository navigation
fix(pi): hand pi-ai its provider modules, so a bundled host can sign in - #330
Merged
Merged
Conversation
…in (#328) pi-ai loads its sign-in flows and Bedrock through a computed path. A host bundled into one file has no such files beside it, so every pi sign-in, OAuth turn and Bedrock call failed with Cannot find module. Before pi first reaches a provider (sessions, model listing, login, catalog), OAR now makes the two calls pi's own standalone binary makes, through literal dynamic imports a bundler follows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er fails Lookout's single-file build of #330: esbuild renamed npm undici's Agent to Agent4, so the dispatcher undici creates itself read as the host's own and the proxy plane was skipped; it is now judged by class too. A host that leaves Bedrock out of its bundle made the whole hand-over fail and cached the failure; each module is now handed over on its own, a failure warns once and is retried. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
xxchan
added a commit
that referenced
this pull request
Oct 10, 2026
Release OAR and CLI 0.54.1. This PR changes only the two package version fields. **Fixed: a host bundled into one file can sign in to pi's providers** (#328, #330) - pi-ai loads its sign-in flows and its Bedrock implementation through a computed path, so that a browser bundler does not follow them into Node-only code. A host bundled into one file (a Node single executable, such as Ferry's daemon) has no such files beside it, so every pi sign-in, every turn on an OAuth credential and every Bedrock call failed with "Cannot find module". - Before pi first reaches a provider (session open, `piListModels`, `createPiProviderAuth`, `createPiModelCatalog`), OAR now makes the two calls pi's own standalone binary makes: `registerBunOAuthFlows()` and `setBedrockProviderModule(bedrockProviderModule)`. The imports are literal, so a bundler follows them, and dynamic, so a host that never uses pi does not load them. A bundled host needs no pi dependency of its own for this. - Each hand-over is best effort. A host that leaves Bedrock out of its bundle (its AWS SDK adds about 1.4 MB) keeps every sign-in, gets one `OAR_PI_MODULES` process warning, and Bedrock loads pi's own way. A failed hand-over is tried again on the next call. - photon still reads `photon_rs_bg.wasm` from its own directory, so a single-file host ships that file beside it or embeds it. **Fixed: pi's proxy plane in a bundled host** (#330) - OAR recognized undici's own default dispatcher by its class name `Agent`. A bundler can rename that class (esbuild made it `Agent4` in a single-file host), so OAR took it for the host's own dispatcher and skipped the proxy plane: pi's requests ignored `HTTPS_PROXY`, with an `OAR_PI_PROXY_PLANE` warning. It is now recognized by class as well. **Behavior changes** - New process warning code `OAR_PI_MODULES`, only when a pi-ai module cannot be handed over. - Using pi now loads pi-ai's sign-in flows and Bedrock module (with its AWS SDK, about 60 to 140 ms) once per process, the first time pi reaches a provider. Validation: #330 passed all 17 checks on its final head, and its merged tree differs from its CI tree only in the version fields from the 0.54.0 release. Lookout bundled main and the PR with a small host into one CommonJS file each, run from an empty directory with fake credentials and no network: on main every sign-in flow and Bedrock failed with "Cannot find module" and pi's requests bypassed `HTTPS_PROXY`; on the PR all loaded and requests went through the proxy, with no warning. With Bedrock left out of the bundle, the sign-in flows still loaded and one warning was printed. A host that never uses pi loaded none of these modules. After this PR passes CI and merges, tag its exact squash commit as `v0.54.1` to trigger npm trusted publishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[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.
Closes #328.
What happened: a host bundled into one file (Ferry's daemon is a Node 24 single executable, one rolldown bundle with no
node_modulesbeside it) could not sign in to any pi provider. pi-ai 1.1.0 loads its sign-in flows (auth/oauth/load.js) and Bedrock (api/bedrock-converse-stream.lazy.js) through a computed path, so that a browser bundler does not follow them into Node-only code. A bundle keeps those as run-time imports of files beside it, so every pi sign-in, every turn on an OAuth credential (its refresh loads the same flow) and every Bedrock call failed with "Cannot find module".Change:
runtimes/pi/static-modules.tsmakes the two calls pi's own standalone binary makes (pi-coding-agent/dist/bun/runtime-setup.js):registerBunOAuthFlows()(@earendil-works/pi-ai/bun-oauth) andsetBedrockProviderModule(bedrockProviderModule)(@earendil-works/pi-ai/compatand/bedrock-provider). OAR runs pi in-process on Node only, so the browser reason does not apply. They run once per process, before pi first reaches a provider: at the same three points that already set up pi's HTTP proxy plane (session open,piListModels, and the facade runtime behindcreatePiProviderAuthandcreatePiModelCatalog), now onepreparePi(). The imports are literal, so a bundler follows them, and dynamic, so a host that never touches pi does not pay for them (Bedrock's AWS SDK takes about 60 to 140 ms to load). A bundled host no longer needs its own pi dependency for this.Also, from Lookout's single-file build:
Agent. In the bundle esbuild renamed npm undici'sAgenttoAgent4(more same-named classes once the pi-ai modules joined), so the Agent undici creates itself read as the host's own dispatcher, and pi's requests skippedHTTPS_PROXYwith anOAR_PI_PROXY_PLANEwarning. It is now judged by class too (instanceof undici.Agent); Node's own bundled undici is never bundled, so its name check stays.OAR_PI_MODULESwarning says what failed, and the next call tries again.Not included: a host-facing self-check export (Ferry keeps its own
__selftest modules). photon readsphoton_rs_bg.wasmfrom its own directory, so a single-file host still ships that file;docs/runtimes/pi.mdsays so.Caveat:
setBedrockProviderModulecomes from pi-ai'scompatentry, which pi marks as temporary. When pi removes it, follow pi's replacement.Tests:
tests/pi/pi-static-modules.test.tsbundles a small host (tests/fixtures/pi-bundled-host.ts) into one ESM file with esbuild, runs it from an empty directory, and checks every sign-in flow: all eight fail to load without the registration and all load with it. It also checks that Bedrock's implementation is in the bundle.tests/pi/pi-http-bundled.test.ts(a renamed Agent still counts as stock; fails without the change) andtests/pi/pi-static-modules-partial.test.ts(a missing Bedrock module warns once, is retried and leaves the sign-in flows handed over). The pi and provider tests, lint and typecheck pass.🤖 Generated with Claude Code