File size: 1,955 Bytes
a070805
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { AcpAuthStatus } from "#/hooks/query/use-acp-auth-status";

/**
 * Resolved display state for the ACP auth banner.
 *
 * - ``"signed-in"`` — the host-login probe confirmed a session (native backend).
 * - ``"checking"`` — the first probe is still in flight.
 * - ``"configured"`` — the probe can't confirm a login (e.g. a container with no
 *   interactive CLI, or a cloud backend where the probe doesn't run), but a
 *   credential for the provider exists in the active backend's secret store.
 * - ``"none"`` — no confirmed login and no stored credential; show nothing.
 */
export type AcpAuthDisplay = "signed-in" | "checking" | "configured" | "none";

interface AcpAuthDisplayInput {
  /** Result of the host-login probe (only meaningful on a native backend). */
  status: AcpAuthStatus;
  /** True while the first probe for this provider is in flight. */
  isChecking: boolean;
  /**
   * Whether a credential for the provider exists in the active backend's secret
   * store. Unlike {@link status}, this signal is available on Docker and cloud
   * backends, so it can convey an accurate state where the probe goes silent.
   */
  credentialsConfigured: boolean;
}

/**
 * Decide what the ACP auth banner should show, given the (host-only) login
 * probe and the backend-truthful "a credential is stored" signal.
 *
 * Precedence preserves the existing banner behavior — a probe-confirmed login
 * wins, then the in-flight spinner — and only adds ``"configured"`` in the gap
 * that previously rendered nothing. A stored credential never reports as
 * ``"signed-in"``: only the probe can confirm an actual host login. See #1244.
 */
export function resolveAcpAuthDisplay({
  status,
  isChecking,
  credentialsConfigured,
}: AcpAuthDisplayInput): AcpAuthDisplay {
  if (status === "authenticated") return "signed-in";
  if (isChecking) return "checking";
  if (credentialsConfigured) return "configured";
  return "none";
}