Skip to content

Commit 4c3a932

Browse files
nicoalbaneseclaude
andauthored
fix(devtools): use explicit env flag for dev mode detection (#12694)
## Summary - Replace path-based `/dist/` check with an explicit `AI_SDK_DEVTOOLS_DEV` env flag for dev mode detection - Prevents false positives in monorepos (NX, Turborepo) where `/dist/` paths are common in the workspace - The `dev:api` script now sets `AI_SDK_DEVTOOLS_DEV=true` automatically; production mode is the default when the flag is unset 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 87ef786 commit 4c3a932

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/devtools': patch
3+
---
4+
5+
Use explicit AI_SDK_DEVTOOLS_DEV env flag for dev mode detection

packages/devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"scripts": {
2828
"dev": "concurrently -k \"pnpm dev:api\" \"pnpm dev:client\"",
29-
"dev:api": "tsx src/viewer/server.ts",
29+
"dev:api": "AI_SDK_DEVTOOLS_DEV=true tsx src/viewer/server.ts",
3030
"dev:client": "vite",
3131
"example": "tsx examples/basic/index.ts",
3232
"start": "node dist/viewer/server.js",

packages/devtools/src/viewer/server.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ const broadcastToClients = (event: string, data: Record<string, unknown>) => {
3636

3737
const __dirname = path.dirname(fileURLToPath(import.meta.url));
3838

39-
// Determine if we're running from source (tsx) or built (dist)
40-
// We're in dev mode if NOT running from the dist folder
41-
const isDevMode =
42-
!__dirname.includes('/dist/') || process.env.NODE_ENV === 'development';
43-
const projectRoot = isDevMode
44-
? path.resolve(__dirname, '../..')
45-
: path.resolve(__dirname, '../..');
39+
// Determine whether to use the dev-mode Vite proxy or serve the built client.
40+
//
41+
// We rely exclusively on an explicit env flag to avoid false positives in
42+
// monorepos where /dist paths are common.
43+
//
44+
// AI_SDK_DEVTOOLS_DEV=true → use dev mode (Vite proxy)
45+
// AI_SDK_DEVTOOLS_DEV=false → use production mode (serve built client)
46+
//
47+
// If the flag is unset, default to production mode.
48+
const devEnv = process.env.AI_SDK_DEVTOOLS_DEV;
49+
const isDevMode = devEnv !== undefined && devEnv !== 'false' && devEnv !== '0';
50+
// __dirname points at packages/devtools/src/viewer, so ../.. is the package root.
51+
const projectRoot = path.resolve(__dirname, '../..');
4652

4753
// Client directory: dist/client in both cases
4854
const clientDir = path.join(projectRoot, 'dist/client');

0 commit comments

Comments
 (0)