Skip to content

Commit 200ef60

Browse files
Claudehotlong
andauthored
Fix AI SDK package resolution in Vercel deployment
Resolves the "Cannot find package '@ai-sdk/gateway'" error by: 1. Added @ai-sdk/* packages as optional peer dependencies in service-ai - These are only needed when specific env vars are set - Marked as optional to avoid installation errors when not needed 2. Added @ai-sdk/* packages as dependencies in studio app - Required for LLM auto-detection feature in production 3. Updated esbuild external list to exclude @ai-sdk packages - Prevents bundling so dynamic imports work correctly - Allows runtime resolution from node_modules 4. Updated build-vercel.sh to copy @ai-sdk packages - Copies packages from monorepo to local node_modules - Required for Vercel's pnpm workspace resolution 5. Updated vercel.json includeFiles to bundle @ai-sdk packages - Ensures packages are included in serverless function This allows the AI service to gracefully detect and load LLM providers based on environment variables without build-time bundling issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f482e30 commit 200ef60

5 files changed

Lines changed: 41 additions & 1 deletion

File tree

apps/studio/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"preview": "vite preview"
1818
},
1919
"dependencies": {
20+
"@ai-sdk/anthropic": "^3.0.144",
21+
"@ai-sdk/gateway": "^3.0.144",
22+
"@ai-sdk/google": "^3.0.144",
23+
"@ai-sdk/openai": "^3.0.144",
2024
"@ai-sdk/react": "^3.0.144",
2125
"@hono/node-server": "^1.19.11",
2226
"@objectstack/client": "workspace:*",

apps/studio/scripts/build-vercel.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ if [ -d "../../node_modules/@libsql" ]; then
6161
else
6262
echo "[build-vercel] ⚠ @libsql not found (skipped)"
6363
fi
64+
# Copy the @ai-sdk scope (dynamically loaded provider packages)
65+
if [ -d "../../node_modules/@ai-sdk" ]; then
66+
mkdir -p "node_modules/@ai-sdk"
67+
for pkg in ../../node_modules/@ai-sdk/*/; do
68+
pkgname="$(basename "$pkg")"
69+
cp -rL "$pkg" "node_modules/@ai-sdk/$pkgname"
70+
done
71+
echo "[build-vercel] ✓ Copied @ai-sdk/*"
72+
else
73+
echo "[build-vercel] ⚠ @ai-sdk not found (skipped)"
74+
fi
6475

6576
# 4. Copy Vite build output to public/ for static file serving
6677
rm -rf public

apps/studio/scripts/bundle-api.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import { build } from 'esbuild';
1818
const EXTERNAL = [
1919
'@libsql/client',
2020
'better-sqlite3',
21+
// AI SDK provider packages — dynamically imported based on env vars
22+
'@ai-sdk/anthropic',
23+
'@ai-sdk/gateway',
24+
'@ai-sdk/google',
25+
'@ai-sdk/openai',
2126
// Optional knex database drivers — never used at runtime, but knex requires() them
2227
'pg',
2328
'pg-native',

apps/studio/vercel.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"api/**/*.js": {
1414
"memory": 1024,
1515
"maxDuration": 300,
16-
"includeFiles": "{node_modules/@libsql,node_modules/better-sqlite3}/**"
16+
"includeFiles": "{node_modules/@libsql,node_modules/better-sqlite3,node_modules/@ai-sdk}/**"
1717
}
1818
},
1919
"headers": [

packages/services/service-ai/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@
2323
"@objectstack/spec": "workspace:*",
2424
"ai": "^6.0.0"
2525
},
26+
"peerDependencies": {
27+
"@ai-sdk/anthropic": "^3.0.0",
28+
"@ai-sdk/gateway": "^3.0.0",
29+
"@ai-sdk/google": "^3.0.0",
30+
"@ai-sdk/openai": "^3.0.0"
31+
},
32+
"peerDependenciesMeta": {
33+
"@ai-sdk/anthropic": {
34+
"optional": true
35+
},
36+
"@ai-sdk/gateway": {
37+
"optional": true
38+
},
39+
"@ai-sdk/google": {
40+
"optional": true
41+
},
42+
"@ai-sdk/openai": {
43+
"optional": true
44+
}
45+
},
2646
"devDependencies": {
2747
"@types/node": "^25.5.0",
2848
"typescript": "^6.0.2",

0 commit comments

Comments
 (0)