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 ready: {
15 dot: "bg-success",
16 },
17 warning: {
18 dot: "bg-warning",
19 },
20} as const;
21
22export type ProviderStatusKey = keyof typeof PROVIDER_STATUS_STYLES;
23
24export function getProviderSummary(provider: ServerProvider | undefined) {
25 if (!provider) {
26 return {
27 headline: "Checking provider status",
28 detail: "Waiting for the server to report installation and authentication details.",
29 };
30 }
31 if (!provider.enabled || provider.status === "disabled") {
32 return {
33 headline: "Disabled",
34 detail:
35 provider.message ?? "This provider is installed but disabled for new sessions in T3 Code.",
36 };
37 }
38 if (!provider.installed) {
39 return {
40 headline: "Not found",
41 detail: provider.message ?? "CLI not detected on PATH.",
42 };
43 }
44 if (provider.auth.status === "unauthenticated") {
45 const authLabel = provider.auth.label ?? provider.auth.type;
46 return {
47 headline: authLabel ? `Not authenticated · ${authLabel}` : "Not authenticated",
48 detail: provider.message ?? null,
49 };
50 }
51 if (provider.status === "warning") {
52 return {
53 headline: "Needs attention",
54 detail:
55 provider.message ?? "The provider is installed, but the server could not fully verify it.",
56 };
57 }
58 if (provider.status === "error") {
59 return {
60 headline: "Unavailable",
61 detail: provider.message ?? "The provider failed its startup checks.",
62 };
63 }
64 if (provider.auth.status === "authenticated") {
65 const authLabel = provider.auth.label ?? provider.auth.type;
66 return {
67 headline: authLabel ? `Authenticated · ${authLabel}` : "Authenticated",
68 detail: provider.message ?? null,
69 };
70 }
71 return {
72 headline: "Available",
73 detail: provider.message ?? null,
74 };
75}
76
77export function getProviderVersionLabel(version: string | null | undefined) {
78 if (!version) return null;
79 // Antigravity reports a release tag such as `agy_acp_server_20260818_01_RC01`.
80 const antigravity = /^agy_acp_server_(\d{4})(\d{2})(\d{2})_\d+(?:_(\w+))?$/.exec(version);
81 if (antigravity) {
82 const [, year, month, day, candidate] = antigravity;
83 return `${year}-${month}-${day}${candidate ? ` ${candidate}` : ""}`;
84 }
85 return /^\d/.test(version) ? `v${version}` : version;
86}
87
88const COMPATIBILITY_TITLES = {
89 graceful: "Limited support",
90 unsupported: "Unsupported version",
91 broken: "Known broken version",
92} as const;
93
94export function getProviderVersionAdvisoryPresentation(
95 advisory: ServerProviderVersionAdvisory | undefined,
96 compatibility?: ServerProviderCompatibilityAdvisory | undefined,
97 showCompatibility = true,
98): {
99 readonly title: string;
100 readonly detail: string;
101 readonly updateCommand: string | null;
102 readonly emphasis: "normal" | "strong";
103 readonly targetVersion: string | null;
104} | null {
105 const latestIsIncompatible =
106 compatibility?.latestVersionStatus === "broken" ||
107 compatibility?.latestVersionStatus === "unsupported";
108 if (
109 showCompatibility &&
110 compatibility &&
111 (compatibility.status === "graceful" ||
112 compatibility.status === "unsupported" ||
113 compatibility.status === "broken")
114 ) {
115 const targetVersion = compatibility.recommendedVersion;
116 const recommendation = getProviderVersionLabel(targetVersion) ?? compatibility.recommendedRange;
117 return {
118 title: COMPATIBILITY_TITLES[compatibility.status],
119 detail:
120 compatibility.message ??
121 (recommendation ? `Use ${recommendation} for full support.` : "Update for full support."),
122 updateCommand:
123 targetVersion || latestIsIncompatible ? null : (advisory?.updateCommand ?? null),
124 emphasis: compatibility.status === "graceful" ? "normal" : "strong",
125 targetVersion,
126 };
127 }
128 if (
129 !advisory ||
130 advisory.status === "current" ||
131 advisory.status === "unknown" ||
132 latestIsIncompatible
133 ) {
134 return null;
135 }
136
137 const label = "Update available";
138 const version = advisory.latestVersion;
139 const versionLabel = getProviderVersionLabel(version);
140
141 return {
142 title: label,
143 detail:
144 advisory.message ??
145 (versionLabel
146 ? `${label}: install ${versionLabel}.`
147 : `${label}: install the latest provider version.`),
148 updateCommand: advisory.updateCommand,
149 emphasis: "normal" as const,
150 targetVersion: null,
151 };
152}