|
|
|
|
| import fs from "fs/promises";
|
| import { getCliPrimaryConfigPath } from "@/shared/services/cliRuntime";
|
| import { getRuntimePorts } from "@/lib/runtime/ports";
|
|
|
| const { apiPort } = getRuntimePorts();
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| export async function checkToolConfigStatus(
|
| toolId: string,
|
| _configPathOverride?: string
|
| ): Promise<"configured" | "not_configured" | "not_installed" | "unknown" | "other"> {
|
| try {
|
| const configPath = _configPathOverride ?? getCliPrimaryConfigPath(toolId);
|
| if (!configPath) return "unknown";
|
|
|
| const content = await fs.readFile(configPath, "utf-8");
|
|
|
|
|
| if (toolId === "codex") {
|
| const lower = content.toLowerCase();
|
| const hasOmniRoute =
|
| lower.includes("omniroute") ||
|
| lower.includes(`localhost:${apiPort}`) ||
|
| lower.includes(`127.0.0.1:${apiPort}`);
|
| if (!hasOmniRoute) return "not_configured";
|
|
|
|
|
| try {
|
| const authPath = configPath.replace(/config\.toml$/, "auth.json");
|
| const authContent = await fs.readFile(authPath, "utf-8");
|
| const auth = JSON.parse(authContent) as Record<string, unknown>;
|
| const apiKey = (auth?.OPENAI_API_KEY as string) || "";
|
| if (!apiKey || apiKey.includes("****") || apiKey.length < 20) {
|
| return "not_configured";
|
| }
|
| } catch {
|
| return "not_configured";
|
| }
|
|
|
| return "configured";
|
| }
|
|
|
| if (toolId === "hermes") {
|
| const lower = content.toLowerCase();
|
| const hasOmniRoute =
|
| lower.includes("omniroute") ||
|
| lower.includes(`localhost:${apiPort}`) ||
|
| lower.includes(`127.0.0.1:${apiPort}`);
|
| return hasOmniRoute ? "configured" : "not_configured";
|
| }
|
|
|
| const config = JSON.parse(content) as Record<string, unknown>;
|
|
|
|
|
| switch (toolId) {
|
| case "claude":
|
| return (config?.env as Record<string, unknown>)?.ANTHROPIC_BASE_URL
|
| ? "configured"
|
| : "not_configured";
|
| case "qwen": {
|
|
|
| const mp = config?.modelProviders;
|
| if (!mp) return "not_configured";
|
| const qwenConfigStr = JSON.stringify(mp).toLowerCase();
|
| return qwenConfigStr.includes("omniroute") ||
|
| qwenConfigStr.includes(`localhost:${apiPort}`) ||
|
| qwenConfigStr.includes(`127.0.0.1:${apiPort}`)
|
| ? "configured"
|
| : "not_configured";
|
| }
|
| case "droid":
|
| case "openclaw":
|
| case "cline":
|
| case "kilo": {
|
|
|
| const configStr = JSON.stringify(config).toLowerCase();
|
| if (
|
| configStr.includes("omniroute") ||
|
| configStr.includes("sk_omniroute") ||
|
| configStr.includes(`localhost:${apiPort}`) ||
|
| configStr.includes(`127.0.0.1:${apiPort}`)
|
| ) {
|
| return "configured";
|
| }
|
|
|
|
|
| if (
|
| toolId === "cline" &&
|
| ((config.actModeApiProvider === "openai" || config.planModeApiProvider === "openai") &&
|
| ((config.openAiBaseUrl as string) || "").trim().length > 0)
|
| ) {
|
| return "configured";
|
| }
|
| return "not_configured";
|
| }
|
| default:
|
| return "unknown";
|
| }
|
| } catch {
|
| return "not_configured";
|
| }
|
| }
|
|
|