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 const skills = lines
.filter((line) => line.includes("(")) .filter((line) => line.includes("("))
.map((line) => { .map((line) => {
const match = line.trim().match(/^([^\s]+)\s+([^\s]+)\s+\(([0-9.]+)\)$/); const match = line.trim().match(/^(.+?)\s+(.+?)\s+\(([0-9.]+)\)$/);
if (match) { if (match) {
return { slug: match[1], name: match[2], score: parseFloat(match[3]) }; return { slug: match[1], name: match[2], score: parseFloat(match[3]) };
} }
const parts = line.trim().split(/\s+/); return null;
return { })
slug: parts[0] || "", .filter(Boolean);
name: parts[1] || parts[0] || "",
score: parseFloat(parts[parts.length - 1]?.replace(/[()]/g, "") || "0") || 0,
};
});
return NextResponse.json({ skills }); return NextResponse.json({ skills });
} }
@@ -45,14 +41,14 @@ export async function GET(req: NextRequest) {
const skills = lines const skills = lines
.filter((line) => line.includes("(")) .filter((line) => line.includes("("))
.map((line) => { .map((line) => {
const parts = line.trim().split(/\s+/); const match = line.trim().match(/^(.+?)\s+(.+?)\s+\(([0-9.]+)\)$/);
return { if (match) {
slug: parts[0] || "", return { slug: match[1], name: match[2], score: parseFloat(match[3]) };
name: parts[1] || parts[0] || "", }
score: parseFloat(parts[parts.length - 1]?.replace(/[()]/g, "") || "0") || 0, return null;
};
}) })
.sort((a, b) => b.score - a.score) .filter(Boolean)
.sort((a: any, b: any) => b.score - a.score)
.slice(0, 20); .slice(0, 20);
return NextResponse.json({ skills }); return NextResponse.json({ skills });
} }