fix: proper parsing of clawhub output with multi-word names

This commit is contained in:
2026-03-24 16:15:42 +01:00
parent af340f69de
commit 2c047af9bd
+11 -15
View File
@@ -23,17 +23,13 @@ export async function GET(req: NextRequest) {
const skills = lines
.filter((line) => line.includes("("))
.map((line) => {
const match = line.trim().match(/^([^\s]+)\s+([^\s]+)\s+\(([0-9.]+)\)$/);
const match = line.trim().match(/^(.+?)\s+(.+?)\s+\(([0-9.]+)\)$/);
if (match) {
return { slug: match[1], name: match[2], score: parseFloat(match[3]) };
}
const parts = line.trim().split(/\s+/);
return {
slug: parts[0] || "",
name: parts[1] || parts[0] || "",
score: parseFloat(parts[parts.length - 1]?.replace(/[()]/g, "") || "0") || 0,
};
});
return null;
})
.filter(Boolean);
return NextResponse.json({ skills });
}
@@ -45,14 +41,14 @@ export async function GET(req: NextRequest) {
const skills = lines
.filter((line) => line.includes("("))
.map((line) => {
const parts = line.trim().split(/\s+/);
return {
slug: parts[0] || "",
name: parts[1] || parts[0] || "",
score: parseFloat(parts[parts.length - 1]?.replace(/[()]/g, "") || "0") || 0,
};
const match = line.trim().match(/^(.+?)\s+(.+?)\s+\(([0-9.]+)\)$/);
if (match) {
return { slug: match[1], name: match[2], score: parseFloat(match[3]) };
}
return null;
})
.sort((a, b) => b.score - a.score)
.filter(Boolean)
.sort((a: any, b: any) => b.score - a.score)
.slice(0, 20);
return NextResponse.json({ skills });
}