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.
This commit is contained in:
Ajax Davis 2025-12-11 12:00:17 +10:00
parent 2a16218871
commit b27f377319
2 changed files with 41 additions and 33 deletions

View file

@ -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: {

View file

@ -325,18 +325,6 @@ console.log(result.text);`}
</CardContent>
</Card>
{/* README */}
{pkg.npmReadme && (
<Card>
<CardHeader>
<CardTitle>README</CardTitle>
</CardHeader>
<CardContent>
<Markdown content={pkg.npmReadme} />
</CardContent>
</Card>
)}
{/* AI Agent Information */}
{tool.aiAgent && (
<Card>
@ -415,6 +403,18 @@ console.log(result.text);`}
</CardContent>
</Card>
)}
{/* README */}
{pkg.npmReadme && (
<Card>
<CardHeader>
<CardTitle>README</CardTitle>
</CardHeader>
<CardContent>
<Markdown content={pkg.npmReadme} />
</CardContent>
</Card>
)}
</div>
{/* Right column - Sidebar */}