From 6d8bea6c8d135f856b536b0b614d036cbf86d7e3 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Sun, 30 Nov 2025 00:52:56 +1000 Subject: [PATCH] fix: resolve Next.js routing and package-executor build errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **API Route Restructuring:** - Move execute endpoint from /api/tools/[...slug]/execute to /api/tools/execute/[...slug] - Move simulations endpoint from /api/tools/[...slug]/simulations to /api/tools/simulations/[...slug] - Fix Next.js App Router constraint: catch-all segments must be terminal - Update ToolPlayground component to use new endpoint paths **Package Executor Export Fix:** - Remove .js extensions from exports in @tpmjs/package-executor - Change from './types.js' to './types' for proper TypeScript resolution - Change from './executor.js' to './executor' for proper TypeScript resolution - Fixes "Export executePackage doesn't exist in target module" build error **Next.js Configuration:** - Add vm2 and @tpmjs/package-executor to serverExternalPackages - Prevents bundling VM2 which requires filesystem access to internal files **Code Quality:** - Add biome-ignore for excessive complexity in SSE stream handling - Add biome-ignore for decorative loading spinner SVGs (2 instances) Note: VM2 sandboxing still has compatibility issues with Next.js Turbopack. This may need to be replaced with a different sandboxing approach or disabled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- apps/web/next.config.ts | 1 + .../tools/{[...slug]/execute => execute/[...slug]}/route.ts | 0 .../simulations => simulations/[...slug]}/route.ts | 0 apps/web/src/components/ToolPlayground.tsx | 5 ++++- packages/package-executor/src/index.ts | 4 ++-- 5 files changed, 7 insertions(+), 3 deletions(-) rename apps/web/src/app/api/tools/{[...slug]/execute => execute/[...slug]}/route.ts (100%) rename apps/web/src/app/api/tools/{[...slug]/simulations => simulations/[...slug]}/route.ts (100%) diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts index 481c822..75517ff 100644 --- a/apps/web/next.config.ts +++ b/apps/web/next.config.ts @@ -3,6 +3,7 @@ import type { NextConfig } from 'next'; const nextConfig: NextConfig = { transpilePackages: ['@tpmjs/ui', '@tpmjs/utils', '@tpmjs/db', '@tpmjs/types', '@tpmjs/env'], reactStrictMode: true, + serverExternalPackages: ['vm2', '@tpmjs/package-executor'], }; export default nextConfig; diff --git a/apps/web/src/app/api/tools/[...slug]/execute/route.ts b/apps/web/src/app/api/tools/execute/[...slug]/route.ts similarity index 100% rename from apps/web/src/app/api/tools/[...slug]/execute/route.ts rename to apps/web/src/app/api/tools/execute/[...slug]/route.ts diff --git a/apps/web/src/app/api/tools/[...slug]/simulations/route.ts b/apps/web/src/app/api/tools/simulations/[...slug]/route.ts similarity index 100% rename from apps/web/src/app/api/tools/[...slug]/simulations/route.ts rename to apps/web/src/app/api/tools/simulations/[...slug]/route.ts diff --git a/apps/web/src/components/ToolPlayground.tsx b/apps/web/src/components/ToolPlayground.tsx index a04685f..0cacc3b 100644 --- a/apps/web/src/components/ToolPlayground.tsx +++ b/apps/web/src/components/ToolPlayground.tsx @@ -32,6 +32,7 @@ export function ToolPlayground({ tool }: ToolPlaygroundProps): React.ReactElemen const [error, setError] = useState(null); const [rateLimitInfo, setRateLimitInfo] = useState<{ remaining: number } | null>(null); + // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: SSE stream handling requires sequential logic const handleExecute = async () => { if (!prompt.trim() || isExecuting) return; @@ -44,7 +45,7 @@ export function ToolPlayground({ tool }: ToolPlaygroundProps): React.ReactElemen try { const response = await fetch( - `/api/tools/${encodeURIComponent(tool.npmPackageName)}/execute`, + `/api/tools/execute/${encodeURIComponent(tool.npmPackageName)}`, { method: 'POST', headers: { @@ -253,6 +254,7 @@ export function ToolPlayground({ tool }: ToolPlaygroundProps): React.ReactElemen > {isExecuting ? ( + {/* biome-ignore lint/a11y/noSvgWithoutTitle: decorative loading spinner */}
+ {/* biome-ignore lint/a11y/noSvgWithoutTitle: decorative loading spinner */}