async function saveApiKey(token) {
  if (!token || typeof token !== "string") throw new Error("token is required");
  return window.windowsAppBridge.saveApiKey(token);
}

async function persistApp(app) {
  if (!app || typeof app !== "object") throw new Error("App payload must be an object");
  if (!app.id) throw new Error("app.id is required");
  return window.windowsAppBridge.persistApp(app);
}

async function listApps() {
  return window.windowsAppBridge.listApps();
}

async function syncApp(appId) {
  if (!appId) throw new Error("appId is required");
  return window.windowsAppBridge.syncApp(appId);
}

async function runOpencodeTask(appId, taskName, args = []) {
  if (!appId) throw new Error("appId is required");
  if (!taskName) throw new Error("taskName is required");
  return window.windowsAppBridge.runOpencodeTask(appId, taskName, args);
}

if (window.windowsAppBridge) {
  window.windowsAppBridge.saveApiKey = saveApiKey;
  window.windowsAppBridge.persistApp = persistApp;
  window.windowsAppBridge.listApps = listApps;
  window.windowsAppBridge.syncApp = syncApp;
  window.windowsAppBridge.runOpencodeTask = runOpencodeTask;
}
