Open History to see the last commit
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 );
39}
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";
45}
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 };
104}
105
106export function getProviderVersionLabel(version: string | null | undefined) {
107 if (!version) return null;
108 const antigravity = /^agy_acp_server_(\d{4})(\d{2})(\d{2})_\d+(?:_(\w+))?$/.exec(version);
109 if (antigravity) {
110 const [, year, month, day, candidate] = antigravity;
111 return `${year}-${month}-${day}${candidate ? ` ${candidate}` : ""}`;
112 }
113 return /^\d/.test(version) ? `v${version}` : version;
114}
115
116const COMPATIBILITY_TITLES = {
117 graceful: "Limited support",
118 unsupported: "Unsupported version",
119 broken: "Known broken version",
120} as const;
121
122export function getProviderVersionAdvisoryPresentation(
123 advisory: ServerProviderVersionAdvisory | undefined,
124 compatibility?: ServerProviderCompatibilityAdvisory | undefined,
125 showCompatibility = true,
126): {
127 readonly title: string;
128 readonly detail: string;
129 readonly updateCommand: string | null;
130 readonly emphasis: "normal" | "strong";
131 readonly targetVersion: string | null;
132} | null {
133 const latestIsIncompatible =
134 compatibility?.latestVersionStatus === "broken" ||
135 compatibility?.latestVersionStatus === "unsupported";
136 if (
137 showCompatibility &&
138 compatibility &&
139 (compatibility.status === "graceful" ||
140 compatibility.status === "unsupported" ||
141 compatibility.status === "broken")
142 ) {
143 const targetVersion = compatibility.recommendedVersion;
144 const recommendation = getProviderVersionLabel(targetVersion) ?? compatibility.recommendedRange;
145 // Latest package versions cannot be updated into recommendations requiring another package.
146 const isAlreadyLatest = advisory?.status === "current";
147 return {
148 title: COMPATIBILITY_TITLES[compatibility.status],
149 detail:
150 compatibility.message ??
151 (recommendation ? `Use ${recommendation} for full support.` : "Update for full support."),
152 updateCommand:
153 targetVersion || latestIsIncompatible || isAlreadyLatest
154 ? null
155 : (advisory?.updateCommand ?? null),
156 emphasis: compatibility.status === "graceful" ? "normal" : "strong",
157 targetVersion,
158 };
159 }
160 if (
161 !advisory ||
162 advisory.status === "current" ||
163 advisory.status === "unknown" ||
164 latestIsIncompatible
165 ) {
166 return null;
167 }
168
169 const label = "Update available";
170 const version = advisory.latestVersion;
171 const versionLabel = getProviderVersionLabel(version);
172
173 return {
174 title: label,
175 detail:
176 advisory.message ??
177 (versionLabel
178 ? `${label}: install ${versionLabel}.`
179 : `${label}: install the latest provider version.`),
180 updateCommand: advisory.updateCommand,
181 emphasis: "normal" as const,
182 targetVersion: null,
183 };
184}