File size: 1,395 Bytes
cd8bd0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use server";

import { NextResponse } from "next/server";
import { requireCliToolsAuth } from "@/lib/api/requireCliToolsAuth";
import {
  CLI_TOOL_IDS,
  getCliPrimaryConfigPath,
  getCliRuntimeStatus,
} from "@/shared/services/cliRuntime";

export async function GET(request, { params }) {
  const authError = await requireCliToolsAuth(request);
  if (authError) return authError;

  try {
    const { toolId } = await params;
    const normalizedToolId = String(toolId || "")
      .trim()
      .toLowerCase();

    if (!CLI_TOOL_IDS.includes(normalizedToolId)) {
      return NextResponse.json({ error: "Unsupported CLI tool" }, { status: 404 });
    }

    const runtime = await getCliRuntimeStatus(normalizedToolId);
    return NextResponse.json({
      ...runtime,
      toolId: normalizedToolId,
      configPath: getCliPrimaryConfigPath(normalizedToolId),
      message:
        runtime.reason === "not_required"
          ? "This integration is guide-based and does not require a local CLI binary"
          : runtime.installed && runtime.runnable
            ? "CLI detected and runnable"
            : runtime.installed
              ? "CLI detected but not runnable"
              : "CLI not detected",
    });
  } catch (error) {
    console.log("Error checking CLI runtime:", error);
    return NextResponse.json({ error: "Failed to check CLI runtime" }, { status: 500 });
  }
}