@integrity-labs/agt-cli 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/agt.js CHANGED
@@ -32,7 +32,7 @@ import {
32
32
  resolveChannels,
33
33
  serializeManifestForSlackCli,
34
34
  setActiveTeam
35
- } from "../chunk-AMB6FJLZ.js";
35
+ } from "../chunk-LPYH2O7U.js";
36
36
 
37
37
  // src/bin/agt.ts
38
38
  import { join as join11 } from "path";
@@ -3411,7 +3411,7 @@ async function acpxCloseCommand(agent2, _opts, cmd) {
3411
3411
  import { execSync } from "child_process";
3412
3412
  import chalk19 from "chalk";
3413
3413
  import ora15 from "ora";
3414
- var cliVersion = true ? "0.9.2" : "dev";
3414
+ var cliVersion = true ? "0.9.4" : "dev";
3415
3415
  async function fetchLatestVersion() {
3416
3416
  const host2 = AGT_HOST;
3417
3417
  if (!host2) return null;
@@ -3527,7 +3527,7 @@ async function checkForUpdateOnStartup() {
3527
3527
  }
3528
3528
 
3529
3529
  // src/bin/agt.ts
3530
- var cliVersion2 = true ? "0.9.2" : "dev";
3530
+ var cliVersion2 = true ? "0.9.4" : "dev";
3531
3531
  var program = new Command();
3532
3532
  program.name("agt").description("Augmented CLI \u2014 agent provisioning and management").version(cliVersion2).option("--json", "Emit machine-readable JSON output (suppress spinners and colors)").option("--skip-update-check", "Skip the automatic update check on startup");
3533
3533
  program.hook("preAction", (thisCommand) => {
@@ -2677,6 +2677,10 @@ function requireHost() {
2677
2677
 
2678
2678
  // src/lib/api-client.ts
2679
2679
  var cachedExchange = null;
2680
+ var exchangeInFlight = null;
2681
+ function invalidateExchange() {
2682
+ cachedExchange = null;
2683
+ }
2680
2684
  async function exchangeApiKey(rawKey, retried = false) {
2681
2685
  if (cachedExchange && Date.now() < cachedExchange.expiresAt - 6e4) {
2682
2686
  return {
@@ -2689,6 +2693,17 @@ async function exchangeApiKey(rawKey, retried = false) {
2689
2693
  supabaseAnonKey: cachedExchange.supabaseAnonKey
2690
2694
  };
2691
2695
  }
2696
+ if (exchangeInFlight) {
2697
+ return exchangeInFlight;
2698
+ }
2699
+ exchangeInFlight = doExchange(rawKey, retried);
2700
+ try {
2701
+ return await exchangeInFlight;
2702
+ } finally {
2703
+ exchangeInFlight = null;
2704
+ }
2705
+ }
2706
+ async function doExchange(rawKey, retried) {
2692
2707
  const res = await fetch(`${requireHost()}/host/exchange`, {
2693
2708
  method: "POST",
2694
2709
  headers: { "Content-Type": "application/json" },
@@ -2701,7 +2716,7 @@ async function exchangeApiKey(rawKey, retried = false) {
2701
2716
  reloadFromShellProfile();
2702
2717
  const freshKey = getApiKey();
2703
2718
  if (freshKey && freshKey !== rawKey) {
2704
- return exchangeApiKey(freshKey, true);
2719
+ return doExchange(freshKey, true);
2705
2720
  }
2706
2721
  }
2707
2722
  const host = requireHost();
@@ -2764,6 +2779,22 @@ var ApiError = class extends Error {
2764
2779
  this.name = "ApiError";
2765
2780
  }
2766
2781
  };
2782
+ async function fetchWithRetry(path, method, body) {
2783
+ const headers = await buildHeaders();
2784
+ const url = `${requireHost()}${path}`;
2785
+ const init = {
2786
+ method,
2787
+ headers,
2788
+ body: body !== void 0 ? JSON.stringify(body) : void 0
2789
+ };
2790
+ const res = await fetch(url, init);
2791
+ if (res.status === 401) {
2792
+ invalidateExchange();
2793
+ const freshHeaders = await buildHeaders();
2794
+ return fetch(url, { ...init, headers: freshHeaders });
2795
+ }
2796
+ return res;
2797
+ }
2767
2798
  async function handleResponse(res) {
2768
2799
  const body = await res.json().catch(() => ({}));
2769
2800
  if (!res.ok) {
@@ -2773,40 +2804,23 @@ async function handleResponse(res) {
2773
2804
  }
2774
2805
  var api = {
2775
2806
  async get(path) {
2776
- const headers = await buildHeaders();
2777
- const res = await fetch(`${requireHost()}${path}`, { method: "GET", headers });
2807
+ const res = await fetchWithRetry(path, "GET");
2778
2808
  return handleResponse(res);
2779
2809
  },
2780
2810
  async post(path, body) {
2781
- const headers = await buildHeaders();
2782
- const res = await fetch(`${requireHost()}${path}`, {
2783
- method: "POST",
2784
- headers,
2785
- body: body !== void 0 ? JSON.stringify(body) : void 0
2786
- });
2811
+ const res = await fetchWithRetry(path, "POST", body);
2787
2812
  return handleResponse(res);
2788
2813
  },
2789
2814
  async patch(path, body) {
2790
- const headers = await buildHeaders();
2791
- const res = await fetch(`${requireHost()}${path}`, {
2792
- method: "PATCH",
2793
- headers,
2794
- body: body !== void 0 ? JSON.stringify(body) : void 0
2795
- });
2815
+ const res = await fetchWithRetry(path, "PATCH", body);
2796
2816
  return handleResponse(res);
2797
2817
  },
2798
2818
  async put(path, body) {
2799
- const headers = await buildHeaders();
2800
- const res = await fetch(`${requireHost()}${path}`, {
2801
- method: "PUT",
2802
- headers,
2803
- body: body !== void 0 ? JSON.stringify(body) : void 0
2804
- });
2819
+ const res = await fetchWithRetry(path, "PUT", body);
2805
2820
  return handleResponse(res);
2806
2821
  },
2807
2822
  async del(path) {
2808
- const headers = await buildHeaders();
2809
- const res = await fetch(`${requireHost()}${path}`, { method: "DELETE", headers });
2823
+ const res = await fetchWithRetry(path, "DELETE");
2810
2824
  return handleResponse(res);
2811
2825
  }
2812
2826
  };
@@ -4716,4 +4730,4 @@ export {
4716
4730
  detectDrift,
4717
4731
  provision
4718
4732
  };
4719
- //# sourceMappingURL=chunk-AMB6FJLZ.js.map
4733
+ //# sourceMappingURL=chunk-LPYH2O7U.js.map