let runtimeServices = {};
function setTuiRuntimeServices(adapter) {
  runtimeServices = { ...adapter };
}
function getTuiRuntimeServices() {
  return runtimeServices;
}
function missingHostMethod(methodName) {
  return new Error(`TUI runtime services missing required method: ${methodName}`);
}
function registerGracefulShutdown(getAgent, options) {
  runtimeServices.registerGracefulShutdown?.(getAgent, options);
}
function captureAnalytics(event, properties) {
  runtimeServices.capture?.(event, properties);
}
async function applyLayeredEnvironmentLoading() {
  if (runtimeServices.applyLayeredEnvironmentLoading) {
    await runtimeServices.applyLayeredEnvironmentLoading();
  }
}
function getProviderDisplayName(provider) {
  return runtimeServices.getProviderDisplayName?.(provider) ?? String(provider);
}
function isValidApiKeyFormat(apiKey, provider) {
  return runtimeServices.isValidApiKeyFormat?.(apiKey, provider) ?? apiKey.trim().length > 0;
}
function getProviderInstructions(provider) {
  return runtimeServices.getProviderInstructions?.(provider) ?? null;
}
async function performDeviceCodeLogin(options) {
  if (!runtimeServices.performDeviceCodeLogin) {
    throw missingHostMethod("performDeviceCodeLogin");
  }
  return runtimeServices.performDeviceCodeLogin(options);
}
async function persistDeviceApiKeyLoginResult(result) {
  if (!runtimeServices.persistDeviceApiKeyLoginResult) {
    throw missingHostMethod("persistDeviceApiKeyLoginResult");
  }
  return runtimeServices.persistDeviceApiKeyLoginResult(result);
}
async function ensureDextoApiKeyForAuthToken(authToken, options) {
  if (!runtimeServices.ensureDextoApiKeyForAuthToken) {
    throw missingHostMethod("ensureDextoApiKeyForAuthToken");
  }
  return runtimeServices.ensureDextoApiKeyForAuthToken(authToken, options);
}
async function loadAuth() {
  if (!runtimeServices.loadAuth) {
    throw missingHostMethod("loadAuth");
  }
  return runtimeServices.loadAuth();
}
async function storeAuth(config) {
  if (!runtimeServices.storeAuth) {
    throw missingHostMethod("storeAuth");
  }
  await runtimeServices.storeAuth(config);
}
async function removeAuth() {
  if (!runtimeServices.removeAuth) {
    throw missingHostMethod("removeAuth");
  }
  await runtimeServices.removeAuth();
}
async function removeDextoApiKeyFromEnv(options) {
  if (!runtimeServices.removeDextoApiKeyFromEnv) {
    throw missingHostMethod("removeDextoApiKeyFromEnv");
  }
  return runtimeServices.removeDextoApiKeyFromEnv(options);
}
async function isUsingDextoCredits() {
  if (!runtimeServices.isUsingDextoCredits) {
    throw missingHostMethod("isUsingDextoCredits");
  }
  return runtimeServices.isUsingDextoCredits();
}
async function canUseDextoProvider() {
  if (!runtimeServices.canUseDextoProvider) {
    throw missingHostMethod("canUseDextoProvider");
  }
  return runtimeServices.canUseDextoProvider();
}
function buildDextoBillingUrl(options) {
  if (!runtimeServices.buildDextoBillingUrl) {
    throw missingHostMethod("buildDextoBillingUrl");
  }
  return runtimeServices.buildDextoBillingUrl(options);
}
async function openDextoBillingPage(options) {
  if (!runtimeServices.openDextoBillingPage) {
    throw missingHostMethod("openDextoBillingPage");
  }
  return runtimeServices.openDextoBillingPage(options);
}
export {
  applyLayeredEnvironmentLoading,
  buildDextoBillingUrl,
  canUseDextoProvider,
  captureAnalytics,
  ensureDextoApiKeyForAuthToken,
  getProviderDisplayName,
  getProviderInstructions,
  getTuiRuntimeServices,
  isUsingDextoCredits,
  isValidApiKeyFormat,
  loadAuth,
  openDextoBillingPage,
  performDeviceCodeLogin,
  persistDeviceApiKeyLoginResult,
  registerGracefulShutdown,
  removeAuth,
  removeDextoApiKeyFromEnv,
  setTuiRuntimeServices,
  storeAuth
};
