Found while working on #189 (R2).
docs/deployment.md now shows a hand-written Cloudflare Worker that imports KVStore from @lousho/build-ai-agent/kv (Node-free; src/deploy/kv.test.ts guards it) and createAgent from the package root. The root entry is not Node-free. Bundling the built dist/index.mjs with esbuild (--platform=browser, external: ai, zod, @opentelemetry/api) fails with:
Could not resolve "async_hooks"
Could not resolve "crypto"
Could not resolve "fs/promises"
Could not resolve "http"
Could not resolve "net"
Could not resolve "stream"
The generated Worker (lousho build --target cloudflare-worker) works only because workerNodeShimPlugin() (src/deploy/bundle.ts) redirects those imports. A user's own Worker has no such shim. Nobody has tested whether Wrangler's nodejs_compat flag covers all of them.
Possible directions (needs a decision):
- a Worker-safe entry point (for example
@lousho/build-ai-agent/worker) that exports createAgent without the Node-only modules, or
- documenting the
nodejs_compat flag with a tested wrangler.toml, or
- shipping the shim as a plugin users can add to their own build.
Until then, the deployment page's hand-written Worker example type-checks but has not been shown to bundle.
Found while working on #189 (R2).
docs/deployment.mdnow shows a hand-written Cloudflare Worker that importsKVStorefrom@lousho/build-ai-agent/kv(Node-free;src/deploy/kv.test.tsguards it) andcreateAgentfrom the package root. The root entry is not Node-free. Bundling the builtdist/index.mjswith esbuild (--platform=browser,external: ai, zod, @opentelemetry/api) fails with:The generated Worker (
lousho build --target cloudflare-worker) works only becauseworkerNodeShimPlugin()(src/deploy/bundle.ts) redirects those imports. A user's own Worker has no such shim. Nobody has tested whether Wrangler'snodejs_compatflag covers all of them.Possible directions (needs a decision):
@lousho/build-ai-agent/worker) that exportscreateAgentwithout the Node-only modules, ornodejs_compatflag with a testedwrangler.toml, orUntil then, the deployment page's hand-written Worker example type-checks but has not been shown to bundle.