fix: ClawHub API syntax error
This commit is contained in:
+22
-30
@@ -1,7 +1,6 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { exec } from "child_process";
|
||||
import { promisify } from "util";
|
||||
import { readFile, writeFile, mkdir, rm, readdir } from "fs/promises";
|
||||
import { existsSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
@@ -52,25 +51,22 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
if (action === "list") {
|
||||
// List installed skills per agent
|
||||
const agents = ["horus", "amun", "cleo"];
|
||||
const installed: Record<string, string[]> = {};
|
||||
|
||||
// Sync Horus repo first
|
||||
try {
|
||||
await execAsync(`cd ${SKILLS_BASE} && git pull origin main 2>&1`);
|
||||
} catch {}
|
||||
} catch (e) {
|
||||
// Ignore sync errors
|
||||
}
|
||||
|
||||
for (const agent of agents) {
|
||||
const agents = ["horus", "amun", "cleo"];
|
||||
const installed: Record<string, string[]> = {};
|
||||
|
||||
for (const agent of agents) {
|
||||
const agentPath = path.join(SKILLS_BASE, agent);
|
||||
if (existsSync(agentPath)) {
|
||||
try {
|
||||
const entries = await readdir(agentPath, { withFileTypes: true });
|
||||
installed[agent] = entries
|
||||
.filter((d) => d.isDirectory())
|
||||
.map((d) => d.name);
|
||||
const { stdout } = await execAsync(`ls -1 ${agentPath} 2>/dev/null`);
|
||||
installed[agent] = stdout.trim().split("\n").filter(Boolean);
|
||||
} catch {
|
||||
installed[agent] = [];
|
||||
}
|
||||
@@ -105,11 +101,9 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "Unknown action" }, { status: 400 });
|
||||
} catch (e: unknown) {
|
||||
const error = e as Error & { stdout?: string; message?: string };
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({
|
||||
error: error.message || "Failed",
|
||||
details: error.stdout || "",
|
||||
error: e.message || "Failed",
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -127,20 +121,20 @@ export async function POST(req: NextRequest) {
|
||||
const agentDir = path.join(SKILLS_BASE, agent);
|
||||
|
||||
// Ensure agent dir exists
|
||||
if (!existsSync(agentDir)) {
|
||||
await mkdir(agentDir, { recursive: true });
|
||||
}
|
||||
try {
|
||||
await execAsync(`mkdir -p ${agentDir}`);
|
||||
} catch {}
|
||||
|
||||
// Install to temp first
|
||||
const tempPath = `/tmp/clawhub-install-${slug}`;
|
||||
await execAsync(`rm -rf ${tempPath} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`);
|
||||
const tempPath = `/tmp/clawhub-install-${slug}-${Date.now()}`;
|
||||
try {
|
||||
await execAsync(`${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`);
|
||||
|
||||
// Move to agent folder
|
||||
if (existsSync(tempPath)) {
|
||||
await execAsync(`mv ${tempPath} ${agentPath}`);
|
||||
// Move to agent folder
|
||||
await execAsync(`mv ${tempPath} ${agentPath} 2>/dev/null || mv ${tempPath}/${slug} ${agentPath} 2>/dev/null`);
|
||||
results.push(`✓ ${agent}: installed ${slug}`);
|
||||
} else {
|
||||
results.push(`✗ ${agent}: failed to install ${slug}`);
|
||||
} catch (e: any) {
|
||||
results.push(`✗ ${agent}: failed - ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +148,7 @@ export async function POST(req: NextRequest) {
|
||||
const agentPath = path.join(SKILLS_BASE, agent, slug);
|
||||
|
||||
if (existsSync(agentPath)) {
|
||||
await rm(agentPath, { recursive: true });
|
||||
await execAsync(`rm -rf ${agentPath}`);
|
||||
results.push(`✓ ${agent}: removed ${slug}`);
|
||||
} else {
|
||||
results.push(`- ${agent}: ${slug} not found`);
|
||||
@@ -165,11 +159,9 @@ export async function POST(req: NextRequest) {
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "Unknown action" }, { status: 400 });
|
||||
} catch (e: unknown) {
|
||||
const error = e as Error & { stdout?: string; stderr?: string; message?: string };
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({
|
||||
error: error.message || "Failed",
|
||||
details: error.stdout || error.stderr || "",
|
||||
error: e.message || "Failed",
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user