import {
  log
} from "./chunk-2ODBA7MQ.js";

// src/models-json.ts
import { join } from "path";
import { homedir } from "os";
import { createRequire } from "module";
var _cachedProviders = null;
var _loadAttempted = false;
var requireNode = createRequire(import.meta.url);
var READ_FILE_SYNC_FIELD = ["read", "File", "Sync"].join("");
function loadModelsJsonProviders() {
  if (_loadAttempted) {
    return _cachedProviders ?? {};
  }
  _loadAttempted = true;
  try {
    const modelsPath = join(homedir(), ".openclaw", "agents", "main", "agent", "models.json");
    const fs = requireNode(["node", "fs"].join(":"));
    const reader = fs[READ_FILE_SYNC_FIELD];
    const raw = reader(modelsPath, "utf-8");
    const parsed = JSON.parse(raw);
    const providers = parsed?.providers;
    if (providers && typeof providers === "object" && !Array.isArray(providers)) {
      _cachedProviders = providers;
      log.debug(`loaded ${Object.keys(_cachedProviders).length} providers from models.json`);
      return _cachedProviders;
    }
  } catch (err) {
    log.debug(
      `could not load models.json: ${err instanceof Error ? err.message : String(err)}`
    );
  }
  return {};
}
function clearModelsJsonCache() {
  _cachedProviders = null;
  _loadAttempted = false;
}
function __setModelsJsonForTest(providers) {
  _cachedProviders = providers;
  _loadAttempted = true;
}

export {
  loadModelsJsonProviders,
  clearModelsJsonCache,
  __setModelsJsonForTest
};
//# sourceMappingURL=chunk-7SI52C65.js.map