From b27f377319ad7709677e167cacec8aa380d62c0f Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Thu, 11 Dec 2025 12:00:17 +1000 Subject: [PATCH] fix(playground): update tool health status on successful execution When a tool is marked as BROKEN but executes successfully in the playground, update its health status to HEALTHY. This ensures stale health check data doesn't persist when tools are working. Also fixes noImplicitAnyLet lint error by refactoring to const. --- .../app/api/tools/execute/[...slug]/route.ts | 50 +++++++++++-------- apps/web/src/app/tool/[...slug]/page.tsx | 24 ++++----- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/apps/web/src/app/api/tools/execute/[...slug]/route.ts b/apps/web/src/app/api/tools/execute/[...slug]/route.ts index 7f001d1..ee34d5c 100644 --- a/apps/web/src/app/api/tools/execute/[...slug]/route.ts +++ b/apps/web/src/app/api/tools/execute/[...slug]/route.ts @@ -69,27 +69,21 @@ export async function POST( // Fetch tool from database with package relation // Support both ID-based lookup and packageName/exportName lookup - let tool; - - if (slug.length === 1) { - // Single slug - treat as tool ID - tool = await prisma.tool.findUnique({ - where: { id: slug[0] || '' }, - include: { package: true }, - }); - } else { - // Multiple slugs - treat as packageName/exportName - const packageName = decodeURIComponent(slug.slice(0, -1).join('/')); - const exportName = decodeURIComponent(slug[slug.length - 1] || ''); - - tool = await prisma.tool.findFirst({ - where: { - package: { npmPackageName: packageName }, - exportName: exportName, - }, - include: { package: true }, - }); - } + const tool = + slug.length === 1 + ? // Single slug - treat as tool ID + await prisma.tool.findUnique({ + where: { id: slug[0] || '' }, + include: { package: true }, + }) + : // Multiple slugs - treat as packageName/exportName + await prisma.tool.findFirst({ + where: { + package: { npmPackageName: decodeURIComponent(slug.slice(0, -1).join('/')) }, + exportName: decodeURIComponent(slug[slug.length - 1] || ''), + }, + include: { package: true }, + }); if (!tool) { return NextResponse.json({ error: 'Tool not found' }, { status: 404 }); @@ -153,6 +147,20 @@ export async function POST( }, }); + // Update tool health status on successful execution + // This ensures tools marked as BROKEN get updated when they actually work + if (tool.importHealth === 'BROKEN' || tool.executionHealth === 'BROKEN') { + await prisma.tool.update({ + where: { id: tool.id }, + data: { + importHealth: 'HEALTHY', + executionHealth: 'HEALTHY', + healthCheckError: null, + lastHealthCheck: new Date(), + }, + }); + } + // Create token usage record await prisma.tokenUsage.create({ data: { diff --git a/apps/web/src/app/tool/[...slug]/page.tsx b/apps/web/src/app/tool/[...slug]/page.tsx index 2c4d348..c744874 100644 --- a/apps/web/src/app/tool/[...slug]/page.tsx +++ b/apps/web/src/app/tool/[...slug]/page.tsx @@ -325,18 +325,6 @@ console.log(result.text);`} - {/* README */} - {pkg.npmReadme && ( - - - README - - - - - - )} - {/* AI Agent Information */} {tool.aiAgent && ( @@ -415,6 +403,18 @@ console.log(result.text);`} )} + + {/* README */} + {pkg.npmReadme && ( + + + README + + + + + + )} {/* Right column - Sidebar */}