Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerStatus.ts

186 lines5.7 KB

1import type {
2 ServerProvider,
3 ServerProviderVersionAdvisory,
4 ServerProviderCompatibilityAdvisory,
5} from "@t3tools/contracts";
6​
7export const PROVIDER_STATUS_STYLES = {
8 disabled: {
9 dot: "bg-muted-foreground/50",
10 },
11 error: {
12 dot: "bg-destructive",
13 },
14 neutral: {
15 dot: "bg-muted-foreground",
16 },
17 ready: {
18 dot: "bg-success",
19 },
20 warning: {
21 dot: "bg-warning",
22 },
23} as const;
24​
25export type ProviderStatusKey = keyof typeof PROVIDER_STATUS_STYLES;
26​
27// Antigravity's local health check verifies installation, not Google sign-in.
28// API-key and Agent Platform warnings still need attention.
29function isAntigravitySignInUnchecked(provider: ServerProvider): boolean {
30 return (
31 provider.driver === "antigravity" &&
32 provider.installed &&
33 provider.status === "warning" &&
34 provider.auth.status === "unknown" &&
35 (provider.auth.type === undefined ||
36 provider.auth.type === "oauth-personal" ||
37 provider.auth.type === "oauth-business")
38 );
40​
41export function getProviderStatusKey(provider: ServerProvider | undefined): ProviderStatusKey {
42 if (provider && !provider.enabled) return "disabled";
43 if (provider && isAntigravitySignInUnchecked(provider)) return "neutral";
44 return provider?.status ?? "warning";
46​
47export function getProviderSummary(provider: ServerProvider | undefined) {
48 if (!provider) {
49 return {
50 headline: "Checking provider status",
51 detail: "Waiting for the server to report installation and authentication details.",
52 };
53 }
54 if (!provider.enabled || provider.status === "disabled") {
55 return {
56 headline: "Disabled",
57 detail:
58 provider.message ?? "This provider is installed but disabled for new sessions in T3 Code.",
59 };
60 }
61 if (!provider.installed) {
62 return {
63 headline: "Not found",
64 detail: provider.message ?? "CLI not detected on PATH.",
65 };
66 }
67 if (provider.auth.status === "unauthenticated") {
68 const authLabel = provider.auth.label ?? provider.auth.type;
69 return {
70 headline: authLabel ? `Not authenticated · ${authLabel}` : "Not authenticated",
71 detail: provider.message ?? null,
72 };
73 }
74 if (isAntigravitySignInUnchecked(provider)) {
75 return {
76 headline: "Installed · Sign-in not checked",
77 detail: provider.message ?? null,
78 };
79 }
80 if (provider.status === "warning") {
81 return {
82 headline: "Needs attention",
83 detail:
84 provider.message ?? "The provider is installed, but the server could not fully verify it.",
85 };
86 }
87 if (provider.status === "error") {
88 return {
89 headline: "Unavailable",
90 detail: provider.message ?? "The provider failed its startup checks.",
91 };
92 }
93 if (provider.auth.status === "authenticated") {
94 const authLabel = provider.auth.label ?? provider.auth.type;
95 return {
96 headline: authLabel ? `Authenticated · ${authLabel}` : "Authenticated",
97 detail: provider.message ?? null,
98 };
99 }
100 return {
101 headline: "Available",
102 detail: provider.message ?? null,
103 };
105​
106export function getProviderVersionLabel(version: string | null | undefined) {
107 if (!version) return null;
108 // Antigravity reports a release tag such as `agy_acp_server_20260818_01_RC01`.
109 const antigravity = /^agy_acp_server_(\d{4})(\d{2})(\d{2})_\d+(?:_(\w+))?$/.exec(version);
110 if (antigravity) {
111 const [, year, month, day, candidate] = antigravity;
112 return `${year}-${month}-${day}${candidate ? ` ${candidate}` : ""}`;
113 }
114 return /^\d/.test(version) ? `v${version}` : version;
116​
117const COMPATIBILITY_TITLES = {
118 graceful: "Limited support",
119 unsupported: "Unsupported version",
120 broken: "Known broken version",
121} as const;
122​
123export function getProviderVersionAdvisoryPresentation(
124 advisory: ServerProviderVersionAdvisory | undefined,
125 compatibility?: ServerProviderCompatibilityAdvisory | undefined,
126 showCompatibility = true,
127): {
128 readonly title: string;
129 readonly detail: string;
130 readonly updateCommand: string | null;
131 readonly emphasis: "normal" | "strong";
132 readonly targetVersion: string | null;
133} | null {
134 const latestIsIncompatible =
135 compatibility?.latestVersionStatus === "broken" ||
136 compatibility?.latestVersionStatus === "unsupported";
137 if (
138 showCompatibility &&
139 compatibility &&
140 (compatibility.status === "graceful" ||
141 compatibility.status === "unsupported" ||
142 compatibility.status === "broken")
143 ) {
144 const targetVersion = compatibility.recommendedVersion;
145 const recommendation = getProviderVersionLabel(targetVersion) ?? compatibility.recommendedRange;
146 // An installed version that is already the package's latest cannot be fixed by
147 // updating it, e.g. when the recommendation needs a different package.
148 const isAlreadyLatest = advisory?.status === "current";
149 return {
150 title: COMPATIBILITY_TITLES[compatibility.status],
151 detail:
152 compatibility.message ??
153 (recommendation ? `Use ${recommendation} for full support.` : "Update for full support."),
154 updateCommand:
155 targetVersion || latestIsIncompatible || isAlreadyLatest
156 ? null
157 : (advisory?.updateCommand ?? null),
158 emphasis: compatibility.status === "graceful" ? "normal" : "strong",
159 targetVersion,
160 };
161 }
162 if (
163 !advisory ||
164 advisory.status === "current" ||
165 advisory.status === "unknown" ||
166 latestIsIncompatible
167 ) {
168 return null;
169 }
170​
171 const label = "Update available";
172 const version = advisory.latestVersion;
173 const versionLabel = getProviderVersionLabel(version);
174​
175 return {
176 title: label,
177 detail:
178 advisory.message ??
179 (versionLabel
180 ? `${label}: install ${versionLabel}.`
181 : `${label}: install the latest provider version.`),
182 updateCommand: advisory.updateCommand,
183 emphasis: "normal" as const,
184 targetVersion: null,
185 };