"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var host_exports = {};
__export(host_exports, {
  applyLayeredEnvironmentLoading: () => applyLayeredEnvironmentLoading,
  buildDextoBillingUrl: () => buildDextoBillingUrl,
  canUseDextoProvider: () => canUseDextoProvider,
  captureAnalytics: () => captureAnalytics,
  ensureDextoApiKeyForAuthToken: () => ensureDextoApiKeyForAuthToken,
  getProviderDisplayName: () => getProviderDisplayName,
  getProviderInstructions: () => getProviderInstructions,
  getTuiRuntimeServices: () => getTuiRuntimeServices,
  isUsingDextoCredits: () => isUsingDextoCredits,
  isValidApiKeyFormat: () => isValidApiKeyFormat,
  loadAuth: () => loadAuth,
  openDextoBillingPage: () => openDextoBillingPage,
  performDeviceCodeLogin: () => performDeviceCodeLogin,
  persistDeviceApiKeyLoginResult: () => persistDeviceApiKeyLoginResult,
  registerGracefulShutdown: () => registerGracefulShutdown,
  removeAuth: () => removeAuth,
  removeDextoApiKeyFromEnv: () => removeDextoApiKeyFromEnv,
  setTuiRuntimeServices: () => setTuiRuntimeServices,
  storeAuth: () => storeAuth
});
module.exports = __toCommonJS(host_exports);
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);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  applyLayeredEnvironmentLoading,
  buildDextoBillingUrl,
  canUseDextoProvider,
  captureAnalytics,
  ensureDextoApiKeyForAuthToken,
  getProviderDisplayName,
  getProviderInstructions,
  getTuiRuntimeServices,
  isUsingDextoCredits,
  isValidApiKeyFormat,
  loadAuth,
  openDextoBillingPage,
  performDeviceCodeLogin,
  persistDeviceApiKeyLoginResult,
  registerGracefulShutdown,
  removeAuth,
  removeDextoApiKeyFromEnv,
  setTuiRuntimeServices,
  storeAuth
});
