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