From 6d0c544e18070c4d29c1274e3c8c11d443403688 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Fri, 23 Jan 2026 19:31:16 +0300 Subject: [PATCH] fix: Bun compatibility for build scripts and runtime detection --- package.json | 8 ++++---- packages/ai/CHANGELOG.md | 4 ++++ packages/ai/src/providers/openai-codex-responses.ts | 2 +- packages/ai/src/stream.ts | 4 ++-- packages/ai/src/utils/oauth/openai-codex.ts | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index fcb08556..9099da72 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ ], "scripts": { "clean": "npm run clean --workspaces", - "build": "npm run build -w @mariozechner/pi-tui && npm run build -w @mariozechner/pi-ai && npm run build -w @mariozechner/pi-agent-core && npm run build -w @mariozechner/pi-coding-agent && npm run build -w @mariozechner/pi-mom && npm run build -w @mariozechner/pi-web-ui && npm run build -w @mariozechner/pi", - "dev": "concurrently --names \"ai,agent,coding-agent,mom,web-ui,tui\" --prefix-colors \"cyan,yellow,red,white,green,magenta\" \"npm run dev -w @mariozechner/pi-ai\" \"npm run dev -w @mariozechner/pi-agent-core\" \"npm run dev -w @mariozechner/pi-coding-agent\" \"npm run dev -w @mariozechner/pi-mom\" \"npm run dev -w @mariozechner/pi-web-ui\" \"npm run dev -w @mariozechner/pi-tui\"", - "dev:tsc": "concurrently --names \"ai,web-ui\" --prefix-colors \"cyan,green\" \"npm run dev:tsc -w @mariozechner/pi-ai\" \"npm run dev:tsc -w @mariozechner/pi-web-ui\"", - "check": "biome check --write . && tsgo --noEmit && npm run check -w @mariozechner/pi-web-ui", + "build": "cd packages/tui && npm run build && cd ../ai && npm run build && cd ../agent && npm run build && cd ../coding-agent && npm run build && cd ../mom && npm run build && cd ../web-ui && npm run build && cd ../pods && npm run build", + "dev": "concurrently --names \"ai,agent,coding-agent,mom,web-ui,tui\" --prefix-colors \"cyan,yellow,red,white,green,magenta\" \"cd packages/ai && npm run dev\" \"cd packages/agent && npm run dev\" \"cd packages/coding-agent && npm run dev\" \"cd packages/mom && npm run dev\" \"cd packages/web-ui && npm run dev\" \"cd packages/tui && npm run dev\"", + "dev:tsc": "concurrently --names \"ai,web-ui\" --prefix-colors \"cyan,green\" \"cd packages/ai && npm run dev:tsc\" \"cd packages/web-ui && npm run dev:tsc\"", + "check": "biome check --write . && tsgo --noEmit && cd packages/web-ui && npm run check", "test": "npm run test --workspaces --if-present", "version:patch": "npm version patch -ws --no-git-tag-version && node scripts/sync-versions.js && rm -rf node_modules packages/*/node_modules package-lock.json && npm install", "version:minor": "npm version minor -ws --no-git-tag-version && node scripts/sync-versions.js && rm -rf node_modules packages/*/node_modules package-lock.json && npm install", diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index 7ecdc53a..ebd714b9 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fixed Bun runtime detection for dynamic imports in browser-compatible modules (stream.ts, openai-codex-responses.ts, openai-codex.ts) + ## [0.49.3] - 2026-01-22 ### Added diff --git a/packages/ai/src/providers/openai-codex-responses.ts b/packages/ai/src/providers/openai-codex-responses.ts index abf21a5f..8a823280 100644 --- a/packages/ai/src/providers/openai-codex-responses.ts +++ b/packages/ai/src/providers/openai-codex-responses.ts @@ -1,6 +1,6 @@ // NEVER convert to top-level import - breaks browser/Vite builds (web-ui) let _os: typeof import("node:os") | null = null; -if (typeof process !== "undefined" && process.versions?.node) { +if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) { import("node:os").then((m) => { _os = m; }); diff --git a/packages/ai/src/stream.ts b/packages/ai/src/stream.ts index c3804617..ab71c964 100644 --- a/packages/ai/src/stream.ts +++ b/packages/ai/src/stream.ts @@ -3,8 +3,8 @@ let _existsSync: typeof import("node:fs").existsSync | null = null; let _homedir: typeof import("node:os").homedir | null = null; let _join: typeof import("node:path").join | null = null; -// Eagerly load in Node.js environment only -if (typeof process !== "undefined" && process.versions?.node) { +// Eagerly load in Node.js/Bun environment only +if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) { import("node:fs").then((m) => { _existsSync = m.existsSync; }); diff --git a/packages/ai/src/utils/oauth/openai-codex.ts b/packages/ai/src/utils/oauth/openai-codex.ts index 1d967640..8b0578ab 100644 --- a/packages/ai/src/utils/oauth/openai-codex.ts +++ b/packages/ai/src/utils/oauth/openai-codex.ts @@ -8,7 +8,7 @@ // NEVER convert to top-level imports - breaks browser/Vite builds (web-ui) let _randomBytes: typeof import("node:crypto").randomBytes | null = null; let _http: typeof import("node:http") | null = null; -if (typeof process !== "undefined" && process.versions?.node) { +if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) { import("node:crypto").then((m) => { _randomBytes = m.randomBytes; });