fix: use full path for clawhub binary in API route
This commit is contained in:
@@ -7,6 +7,7 @@ import path from "path";
|
|||||||
|
|
||||||
const execAsync = promisify(exec);
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
|
const CLAWHUB_BIN = "/usr/bin/clawhub";
|
||||||
const SKILLS_DIR = "/root/.openclaw/workspace/skills";
|
const SKILLS_DIR = "/root/.openclaw/workspace/skills";
|
||||||
|
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
@@ -17,7 +18,7 @@ export async function GET(req: NextRequest) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (action === "search") {
|
if (action === "search") {
|
||||||
const { stdout } = await execAsync(`clawhub search "${q}" 2>&1`);
|
const { stdout } = await execAsync(`${CLAWHUB_BIN} search "${q}" 2>&1`);
|
||||||
const lines = stdout.trim().split("\n");
|
const lines = stdout.trim().split("\n");
|
||||||
const skills = lines
|
const skills = lines
|
||||||
.filter((line) => line.includes("("))
|
.filter((line) => line.includes("("))
|
||||||
@@ -39,7 +40,7 @@ export async function GET(req: NextRequest) {
|
|||||||
if (action === "popular") {
|
if (action === "popular") {
|
||||||
// Get featured/popular - show top skills sorted by score
|
// Get featured/popular - show top skills sorted by score
|
||||||
// Use a common query that returns high-quality skills
|
// Use a common query that returns high-quality skills
|
||||||
const { stdout } = await execAsync(`clawhub search "productivity automation" 2>&1`);
|
const { stdout } = await execAsync(`${CLAWHUB_BIN} search "productivity automation" 2>&1`);
|
||||||
const lines = stdout.trim().split("\n");
|
const lines = stdout.trim().split("\n");
|
||||||
const skills = lines
|
const skills = lines
|
||||||
.filter((line) => line.includes("("))
|
.filter((line) => line.includes("("))
|
||||||
@@ -58,7 +59,7 @@ export async function GET(req: NextRequest) {
|
|||||||
|
|
||||||
if (action === "info") {
|
if (action === "info") {
|
||||||
// Get skill info using inspect
|
// Get skill info using inspect
|
||||||
const { stdout } = await execAsync(`clawhub inspect ${slug} 2>&1`);
|
const { stdout } = await execAsync(`${CLAWHUB_BIN} inspect ${slug} 2>&1`);
|
||||||
return NextResponse.json({ info: stdout });
|
return NextResponse.json({ info: stdout });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
if (action === "install") {
|
if (action === "install") {
|
||||||
const { stdout, stderr } = await execAsync(
|
const { stdout, stderr } = await execAsync(
|
||||||
`cd /root/.openclaw/workspace && clawhub install ${slug} 2>&1`
|
`cd /root/.openclaw/workspace && ${CLAWHUB_BIN} install ${slug} 2>&1`
|
||||||
);
|
);
|
||||||
return NextResponse.json({ output: stdout || stderr || "Installed successfully" });
|
return NextResponse.json({ output: stdout || stderr || "Installed successfully" });
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,7 @@ export async function POST(req: NextRequest) {
|
|||||||
const skillPath = path.join(SKILLS_DIR, slug);
|
const skillPath = path.join(SKILLS_DIR, slug);
|
||||||
|
|
||||||
// Install to temp location for analysis
|
// Install to temp location for analysis
|
||||||
await execAsync(`cd /tmp && rm -rf ${slug} 2>/dev/null; clawhub install ${slug} --dir /tmp/${slug} 2>&1`);
|
await execAsync(`cd /tmp && rm -rf ${slug} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir /tmp/${slug} 2>&1`);
|
||||||
|
|
||||||
// Read the SKILL.md
|
// Read the SKILL.md
|
||||||
const skillMdPath = path.join("/tmp", slug, "SKILL.md");
|
const skillMdPath = path.join("/tmp", slug, "SKILL.md");
|
||||||
@@ -119,7 +120,7 @@ export async function POST(req: NextRequest) {
|
|||||||
const newPath = path.join(SKILLS_DIR, newSlug);
|
const newPath = path.join(SKILLS_DIR, newSlug);
|
||||||
|
|
||||||
// Install original
|
// Install original
|
||||||
await execAsync(`cd /tmp && rm -rf ${slug} 2>/dev/null; clawhub install ${slug} --dir /tmp/${slug} 2>&1`);
|
await execAsync(`cd /tmp && rm -rf ${slug} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir /tmp/${slug} 2>&1`);
|
||||||
|
|
||||||
// Create new version
|
// Create new version
|
||||||
await mkdir(newPath, { recursive: true });
|
await mkdir(newPath, { recursive: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user