import {
  jsonOk,
  routeWrap
} from "./chunk-KKJ5D3II.js";
import {
  resolveContainerProvider
} from "./chunk-ZKZME3DE.js";
import {
  getConfig
} from "./chunk-2MAQ6JFL.js";

// src/handlers/providers.ts
var LOCAL_PROVIDERS = ["docker", "apple-container", "podman"];
var CLOUD_PROVIDERS = ["sprites", "e2b", "vercel", "daytona", "fly", "modal"];
var CLOUD_KEY_MAP = {
  sprites: "SPRITE_TOKEN",
  e2b: "E2B_API_KEY",
  vercel: "VERCEL_TOKEN",
  daytona: "DAYTONA_API_KEY",
  fly: "FLY_API_TOKEN",
  modal: "MODAL_TOKEN_ID"
};
async function checkLocalProvider(name) {
  try {
    const provider = await resolveContainerProvider(name);
    if (provider.checkAvailability) {
      return await provider.checkAvailability();
    }
    return { available: true };
  } catch {
    return { available: false, message: `Provider "${name}" could not be loaded` };
  }
}
function checkCloudProvider(name) {
  const envVar = CLOUD_KEY_MAP[name];
  if (!envVar) return { available: true };
  if (process.env[envVar]) return { available: true };
  if (name === "sprites") {
    const config = getConfig();
    if (config.spriteToken) return { available: true };
  }
  return {
    available: true,
    message: `${envVar} not found in env or settings. Provide via vault_ids at session creation.`
  };
}
async function handleGetProviderStatus(request) {
  return routeWrap(request, async () => {
    const results = {};
    const localChecks = LOCAL_PROVIDERS.map(async (name) => {
      results[name] = await checkLocalProvider(name);
    });
    for (const name of CLOUD_PROVIDERS) {
      results[name] = checkCloudProvider(name);
    }
    await Promise.allSettled(localChecks);
    return jsonOk({ data: results });
  });
}

export {
  handleGetProviderStatus
};
