The best way to control Claude Code, Codex and more from any computer or phone
fix(web): provider updates no longer pop toasts on launch (#23233)
oliver committed
Oct 22, 2026 at 10:19 UTC
b9aaff46e0e2dd495cdd6513b49bced5587bf6f3
10 files changed
+6
-1589
apps/web/src/components/ProviderUpdateEnvironmentRows.tsx
deleted
-356
@@ -1,356 +0,0 @@
1
-import { CheckIcon } from "lucide-react";
2
-import { type ReactNode, useRef, useState } from "react";
3
-import {
4
- AuthProvidersManageScope,
5
- type EnvironmentId,
6
- type ServerProvider,
7
-} from "@t3tools/contracts";
8
-import {
9
- isAtomCommandInterrupted,
10
- settlePromise,
11
- squashAtomCommandFailure,
12
- type AtomCommandResult,
13
-} from "@t3tools/client-runtime/state/runtime";
14
-
15
-import { cn } from "~/lib/utils";
16
-import { serverEnvironment } from "~/state/server";
17
-import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
18
-import { useAtomCommand } from "~/state/use-atom-command";
19
-import { useLocalEnvironmentUpdateGroups } from "./ProviderUpdateLaunchNotification.environments";
20
-import {
21
- collectProviderUpdateOutcomeSnapshots,
22
- firstRejectedProviderUpdateMessage,
23
- getProviderUpdateProgressToastView,
24
- getProviderUpdateSidebarPillView,
25
- isTerminalProviderUpdatePhase,
26
- resolveEnvironmentUpdateRowStatus,
27
- type LocalEnvironmentUpdateGroup,
28
- type LocalProviderUpdateOutcome,
29
- type ProviderUpdateRowStatus,
30
- type ProviderUpdateRowStatusKind,
31
- type ProviderUpdateToastView,
32
-} from "./ProviderUpdateLaunchNotification.logic";
33
-import { Button } from "./ui/button";
34
-import { Spinner } from "./ui/spinner";
35
-
36
-type ProviderUpdateCommandResult = AtomCommandResult<
37
- { readonly providers: ReadonlyArray<ServerProvider> },
38
- unknown
39
->;
40
-
41
-function toProviderUpdateOutcome(input: {
42
- readonly environmentId: EnvironmentId;
43
- readonly isPrimary: boolean;
44
- readonly target: {
45
- readonly driver: ServerProvider["driver"];
46
- readonly instanceId: ServerProvider["instanceId"];
47
- };
48
- readonly result: ProviderUpdateCommandResult;
49
-}): PromiseSettledResult<LocalProviderUpdateOutcome> {
50
- if (input.result._tag === "Failure") {
51
- if (isAtomCommandInterrupted(input.result)) {
52
- return {
53
- status: "fulfilled",
54
- value: {
55
- environmentId: input.environmentId,
56
- isPrimary: input.isPrimary,
57
- driver: input.target.driver,
58
- instanceId: input.target.instanceId,
59
- provider: null,
60
- },
61
- };
62
- }
63
- const error = squashAtomCommandFailure(input.result);
64
- return {
65
- status: "rejected",
66
- reason: error instanceof Error ? error : new Error("Provider update failed."),
67
- };
68
- }
69
-
70
- const provider =
71
- input.result.value.providers.find(
72
- (candidate) => candidate.instanceId === input.target.instanceId,
73
- ) ?? null;
74
- return {
75
- status: "fulfilled",
76
- value: {
77
- environmentId: input.environmentId,
78
- isPrimary: input.isPrimary,
79
- driver: input.target.driver,
80
- instanceId: input.target.instanceId,
81
- provider,
82
- },
83
- };
84
-}
85
-
86
-// Keep it well beyond the server's own update timeout (5 min) so a legitimately
87
-// slow update (npm installs routinely run tens of seconds) is never cut off and
88
-// left showing a dead, unresponsive Update button.
89
-const PENDING_EXPIRY_MS = 6 * 60_000;
90
-
91
-function rowToneClass(kind: ProviderUpdateRowStatusKind): string {
92
- switch (kind) {
93
- case "failed":
94
- return "text-destructive";
95
- case "unchanged":
96
- return "text-warning";
97
- case "success":
98
- return "text-success";
99
- default:
100
- return "text-muted-foreground";
101
- }
102
-}
103
-
104
-function EnvironmentUpdateRow({
105
- group,
106
- status,
107
- onUpdate,
108
-}: {
109
- readonly group: LocalEnvironmentUpdateGroup;
110
- readonly status: ProviderUpdateRowStatus;
111
- readonly onUpdate: () => void;
112
-}) {
113
- const canManageProviders = useEnvironmentScope(group.environmentId, AuthProvidersManageScope);
114
- let trailing: ReactNode;
115
- switch (status.kind) {
116
- case "loading":
117
- trailing = <Spinner size="md" tone="muted" />;
118
- break;
119
- case "success":
120
- trailing = <CheckIcon aria-hidden="true" className="size-4 text-success" />;
121
- break;
122
- case "failed":
123
- case "unchanged":
124
- trailing = (
125
- <Button size="xs" variant="outline" disabled={!canManageProviders} onClick={onUpdate}>
126
- Retry
127
- </Button>
128
- );
129
- break;
130
- default:
131
- trailing = (
132
- <Button size="xs" variant="outline" disabled={!canManageProviders} onClick={onUpdate}>
133
- Update
134
- </Button>
135
- );
136
- break;
137
- }
138
-
139
- return (
140
- <div className="flex items-center justify-between gap-3 py-0.5">
141
- <div className="flex min-w-0 flex-col">
142
- <span className="truncate font-medium text-foreground">{group.label}</span>
143
- <span className={cn("truncate text-xs", rowToneClass(status.kind))}>{status.text}</span>
144
- {!canManageProviders ? (
145
- <span className="text-xs text-muted-foreground">
146
- This connection cannot manage provider accounts.
147
- </span>
148
- ) : null}
149
- </div>
150
- <div className="shrink-0">{trailing}</div>
151
- </div>
152
- );
153
-}
154
-
155
-export function ProviderUpdateEnvironmentRows({
156
- onInteract,
157
-}: {
158
- readonly onInteract?: () => void;
159
-}) {
160
- const { groups } = useLocalEnvironmentUpdateGroups();
161
- const updateProvider = useAtomCommand(serverEnvironment.updateProvider, {
162
- reportFailure: false,
163
- });
164
- const groupByEnvironment = new Map(groups.map((group) => [group.environmentId, group] as const));
165
-
166
- const [visibleAfterIso] = useState(() => new Date().toISOString());
167
-
168
- // setPendingEnvironments is an async state update, and PENDING_EXPIRY_MS can
169
- // clear the spinner while a request is still in flight, so a rapid
170
- // double-click (or a click after the expiry fires mid- request) would
171
- // otherwise dispatch a second full round of updates. A ref updates
172
- // synchronously, so we can bail before doing any work.
173
- const inFlightEnvironmentsRef = useRef<Set<EnvironmentId>>(new Set());
174
-
175
- // Bumped on each dispatch and captured locally, so an attempt that was
176
- // superseded -- e.g. one that already tripped the expiry safety net and was
177
- // retried -- detects it is no longer current and skips every state write when
178
- // it finally resolves, instead of clobbering the newer attempt's
179
- // spinner/result/error or its in-flight guard.
180
- const requestVersionRef = useRef<Map<EnvironmentId, number>>(new Map());
181
-
182
- const [pendingEnvironments, setPendingEnvironments] = useState<ReadonlySet<EnvironmentId>>(
183
- () => new Set(),
184
- );
185
- const [errorByEnvironment, setErrorByEnvironment] = useState<ReadonlyMap<EnvironmentId, string>>(
186
- () => new Map(),
187
- );
188
- const [resultByEnvironment, setResultByEnvironment] = useState<
189
- ReadonlyMap<EnvironmentId, ProviderUpdateToastView>
190
- >(() => new Map());
191
-
192
- const clearPending = (environmentId: EnvironmentId) => {
193
- setPendingEnvironments((previous) => {
194
- if (!previous.has(environmentId)) {
195
- return previous;
196
- }
197
- const next = new Set(previous);
198
- next.delete(environmentId);
199
- return next;
200
- });
201
- };
202
-
203
- const handleUpdate = async (environmentId: EnvironmentId) => {
204
- if (!readEnvironmentScope(environmentId, AuthProvidersManageScope)) return;
205
- const group = groupByEnvironment.get(environmentId);
206
- if (!group || group.candidates.length === 0) {
207
- return;
208
- }
209
- if (inFlightEnvironmentsRef.current.has(environmentId)) {
210
- return;
211
- }
212
- inFlightEnvironmentsRef.current.add(environmentId);
213
- const requestVersion = (requestVersionRef.current.get(environmentId) ?? 0) + 1;
214
- requestVersionRef.current.set(environmentId, requestVersion);
215
- const isCurrentRequest = () => requestVersionRef.current.get(environmentId) === requestVersion;
216
- onInteract?.();
217
- const providerCount = group.candidates.length;
218
- const targets = group.candidates.map((candidate) => ({
219
- driver: candidate.driver,
220
- instanceId: candidate.instanceId,
221
- }));
222
-
223
- setPendingEnvironments((previous) => new Set(previous).add(environmentId));
224
- setErrorByEnvironment((previous) => {
225
- if (!previous.has(environmentId)) {
226
- return previous;
227
- }
228
- const next = new Map(previous);
229
- next.delete(environmentId);
230
- return next;
231
- });
232
- setResultByEnvironment((previous) => {
233
- if (!previous.has(environmentId)) {
234
- return previous;
235
- }
236
- const next = new Map(previous);
237
- next.delete(environmentId);
238
- return next;
239
- });
240
-
241
- const expiry = setTimeout(() => {
242
- if (!isCurrentRequest()) {
243
- return;
244
- }
245
- inFlightEnvironmentsRef.current.delete(environmentId);
246
- clearPending(environmentId);
247
- setErrorByEnvironment((previous) =>
248
- new Map(previous).set(environmentId, "Update timed out — try again."),
249
- );
250
- }, PENDING_EXPIRY_MS);
251
- const settled = await settlePromise(async () => {
252
- const results = await Promise.all(
253
- targets.map(async (target): Promise<PromiseSettledResult<LocalProviderUpdateOutcome>> => {
254
- try {
255
- const result = await updateProvider({
256
- environmentId,
257
- input: { provider: target.driver, instanceId: target.instanceId },
258
- });
259
- return toProviderUpdateOutcome({
260
- environmentId,
261
- isPrimary: group.isPrimary,
262
- target,
263
- result,
264
- });
265
- } catch (error) {
266
- return {
267
- status: "rejected",
268
- reason: error instanceof Error ? error : new Error("Provider update failed."),
269
- };
270
- }
271
- }),
272
- );
273
- if (!isCurrentRequest()) {
274
- return;
275
- }
276
- setErrorByEnvironment((previous) => {
277
- if (!previous.has(environmentId)) {
278
- return previous;
279
- }
280
- const next = new Map(previous);
281
- next.delete(environmentId);
282
- return next;
283
- });
284
- if (results.length === 0) {
285
- setErrorByEnvironment((previous) =>
286
- new Map(previous).set(
287
- environmentId,
288
- "This environment isn’t connected — try again once it reconnects.",
289
- ),
290
- );
291
- return;
292
- }
293
- const rejectedMessage = firstRejectedProviderUpdateMessage(results);
294
- if (rejectedMessage) {
295
- setErrorByEnvironment((previous) => new Map(previous).set(environmentId, rejectedMessage));
296
- return;
297
- }
298
- const view = getProviderUpdateProgressToastView({
299
- providers: collectProviderUpdateOutcomeSnapshots(results),
300
- providerCount,
301
- });
302
- // A stored view never re-polls, so persisting it would pin the row's
303
- // spinner forever once the pending flag expires. Drop it and let the
304
- // live per-environment provider state (pill) plus the pending expiry
305
- // drive the row, so it self-heals to whatever the backend actually did.
306
- if (isTerminalProviderUpdatePhase(view.phase)) {
307
- setResultByEnvironment((previous) => new Map(previous).set(environmentId, view));
308
- }
309
- });
310
- clearTimeout(expiry);
311
- if (!isCurrentRequest()) return;
312
- if (settled._tag === "Failure") {
313
- const error = squashAtomCommandFailure(settled);
314
- setErrorByEnvironment((previous) =>
315
- new Map(previous).set(
316
- environmentId,
317
- error instanceof Error ? error.message : "Provider update failed.",
318
- ),
319
- );
320
- }
321
- clearPending(environmentId);
322
- inFlightEnvironmentsRef.current.delete(environmentId);
323
- };
324
-
325
- const rows = groups
326
- .map((group) => ({
327
- group,
328
- status: resolveEnvironmentUpdateRowStatus({
329
- group,
330
- error: errorByEnvironment.get(group.environmentId),
331
- result: resultByEnvironment.get(group.environmentId),
332
- pill: getProviderUpdateSidebarPillView(group.candidates, {
333
- visibleAfterIso,
334
- }),
335
- isPending: pendingEnvironments.has(group.environmentId),
336
- }),
337
- }))
338
- .filter(({ group, status }) => group.candidates.length > 0 || status.kind !== "idle");
339
-
340
- if (rows.length === 0) {
341
- return null;
342
- }
343
-
344
- return (
345
- <div className="mt-0.5 flex flex-col gap-1">
346
- {rows.map(({ group, status }) => (
347
- <EnvironmentUpdateRow
348
- key={group.environmentId}
349
- group={group}
350
- status={status}
351
- onUpdate={() => handleUpdate(group.environmentId)}
352
- />
353
- ))}
354
- </div>
355
- );
356
-}
apps/web/src/components/ProviderUpdateLaunchNotification.environments.ts
deleted
-75
@@ -1,75 +0,0 @@
1
-import type { ConnectionCatalogEntry } from "@t3tools/client-runtime/connection";
2
-
3
-import {
4
- useEnvironmentProviders,
5
- useEnvironments,
6
- usePrimaryEnvironmentId,
7
-} from "~/state/environments";
8
-import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
9
-import {
10
- buildLocalEnvironmentUpdateGroups,
11
- deriveEnvironmentDisplayLabel,
12
- type EnvironmentUpdateConnectionState,
13
- type LocalEnvironmentProvidersInput,
14
- type LocalEnvironmentUpdateGroup,
15
-} from "./ProviderUpdateLaunchNotification.logic";
16
-
17
-function isLocalConnectionTarget(target: ConnectionCatalogEntry["target"]): boolean {
18
- return target._tag === "PrimaryConnectionTarget" || isDesktopLocalConnectionTarget(target);
19
-}
20
-
21
-function normalizeConnectionState(phase: string | undefined): EnvironmentUpdateConnectionState {
22
- switch (phase) {
23
- case "connected":
24
- return "ready";
25
- case "connecting":
26
- case "reconnecting":
27
- return "connecting";
28
- case "unsupported":
29
- case "error":
30
- return "error";
31
- case "offline":
32
- return "disconnected";
33
- default:
34
- return "connecting";
35
- }
36
-}
37
-
38
-export function useLocalEnvironmentUpdateGroups(): {
39
- readonly groups: LocalEnvironmentUpdateGroup[];
40
- readonly isAnySettling: boolean;
41
-} {
42
- const { environments } = useEnvironments();
43
- const providersByEnvironment = useEnvironmentProviders();
44
- const primaryEnvironmentId = usePrimaryEnvironmentId();
45
-
46
- const inputs: LocalEnvironmentProvidersInput[] = [];
47
-
48
- for (const environment of environments) {
49
- if (!isLocalConnectionTarget(environment.entry.target)) {
50
- continue;
51
- }
52
-
53
- const isPrimary = environment.environmentId === primaryEnvironmentId;
54
- const serverConfig = environment.serverConfig;
55
-
56
- inputs.push({
57
- environmentId: environment.environmentId,
58
- label: isPrimary
59
- ? deriveEnvironmentDisplayLabel({
60
- isWsl: false,
61
- wslDistro: null,
62
- platformOs: serverConfig?.environment.platform.os,
63
- fallbackLabel: environment.label,
64
- })
65
- : environment.label,
66
- isPrimary,
67
- connectionState: isPrimary ? "ready" : normalizeConnectionState(environment.connection.phase),
68
- providers: providersByEnvironment.get(environment.environmentId) ?? [],
69
- });
70
- }
71
-
72
- inputs.sort((left, right) => Number(right.isPrimary) - Number(left.isPrimary));
73
-
74
- return buildLocalEnvironmentUpdateGroups(inputs);
75
-}
apps/web/src/components/ProviderUpdateLaunchNotification.logic.test.ts
-207
@@ -9,25 +9,13 @@ import * as Cause from "effect/Cause";
9
import { AsyncResult } from "effect/reactivity";
10
11
import {
12
- buildLocalEnvironmentUpdateGroups,
12
canOneClickUpdateProviderCandidate,
14
- collectProviderUpdateOutcomeSnapshots,
15
- collectUpdatedProviderSnapshots,
16
- firstRejectedProviderUpdateMessage,
17
- getProviderUpdateProgressToastView,
13
getProviderUpdateRunToastView,
14
getProviderUpdateSidebarPillView,
15
hasOneClickUpdateProviderCandidate,
16
isProviderUpdateCandidate,
17
isProviderSettingsUpdateCandidate,
23
- providerUpdateNotificationKey,
24
- resolveEnvironmentUpdateRowStatus,
25
- type LocalEnvironmentProvidersInput,
26
- type LocalEnvironmentUpdateGroup,
27
- type LocalProviderUpdateOutcome,
18
type ProviderUpdateCandidate,
29
- type ProviderUpdateSidebarPillView,
30
- type ProviderUpdateToastView,
19
} from "./ProviderUpdateLaunchNotification.logic";
20
21
const checkedAt = "2026-04-23T10:00:00.000Z";
@@ -158,67 +146,6 @@ describe("provider update launch notification logic", () => {
146
expect(canOneClickUpdateProviderCandidate(candidate, [candidate])).toBe(false);
147
});
148
161
- it("keeps the same notification key while the published update version is unchanged", () => {
162
- const first = updateCandidate({
163
- driver: driver("codex"),
164
- version: "1.0.0",
165
- latestVersion: "1.2.0",
166
- });
167
- const second = updateCandidate({
168
- driver: driver("codex"),
169
- version: "1.1.0",
170
- latestVersion: "1.2.0",
171
- });
172
- const nextPublishedVersion = updateCandidate({
173
- driver: driver("codex"),
174
- version: "1.1.0",
175
- latestVersion: "1.3.0",
176
- });
177
-
178
- expect(providerUpdateNotificationKey([first])).toBe(providerUpdateNotificationKey([second]));
179
- expect(providerUpdateNotificationKey([nextPublishedVersion])).not.toBe(
180
- providerUpdateNotificationKey([first]),
181
- );
182
- });
183
-
184
- it("tracks updated provider snapshots by instance instead of collapsing to a sibling driver", () => {
185
- const targetInstanceId = instanceId("codex_personal");
186
- const siblingInstanceId = instanceId("codex");
187
- const updatedPersonal = provider({
188
- driver: driver("codex"),
189
- instanceId: targetInstanceId,
190
- version: "1.1.0",
191
- latestVersion: "1.1.0",
192
- advisoryStatus: "current",
193
- updateState: {
194
- status: "succeeded",
195
- startedAt: checkedAt,
196
- finishedAt: checkedAt,
197
- message: "Provider updated.",
198
- output: null,
199
- },
200
- });
201
- const currentDefaultSibling = provider({
202
- driver: driver("codex"),
203
- instanceId: siblingInstanceId,
204
- version: "1.1.0",
205
- latestVersion: "1.1.0",
206
- advisoryStatus: "current",
207
- updateState: undefined,
208
- });
209
-
210
- expect(
211
- collectUpdatedProviderSnapshots({
212
- results: [
213
- AsyncResult.success({
214
- providers: [updatedPersonal, currentDefaultSibling],
215
- }),
216
- ],
217
- providerInstanceIds: new Set([targetInstanceId]),
218
- }),
219
- ).toEqual([updatedPersonal]);
220
- });
221
-
149
it("shows the active sidebar pill for an update on a non-default instance", () => {
150
const view = getProviderUpdateSidebarPillView([
151
provider({ driver: driver("claudeAgent") }),
@@ -347,140 +274,6 @@ describe("provider update launch notification logic", () => {
274
title: "Claude v1.1.0 update failed",
275
});
276
});
350
-
351
- describe("multi-backend update outcomes", () => {
352
- const terminalState = (
353
- status: "succeeded" | "failed" | "unchanged",
354
- message: string,
355
- ): NonNullable<ServerProvider["updateState"]> => ({
356
- status,
357
- startedAt: checkedAt,
358
- finishedAt: checkedAt,
359
- message,
360
- output: null,
361
- });
362
-
363
- const fulfilledOutcome = (
364
- isPrimary: boolean,
365
- snapshot: ServerProvider | null,
366
- environment = "env",
367
- ): PromiseSettledResult<LocalProviderUpdateOutcome> => ({
368
- status: "fulfilled",
369
- value: {
370
- environmentId: environment as LocalProviderUpdateOutcome["environmentId"],
371
- isPrimary,
372
- driver: snapshot?.driver ?? driver("codex"),
373
- instanceId: snapshot?.instanceId ?? instanceId("codex"),
374
- provider: snapshot,
375
- },
376
- });
377
-
378
- it("surfaces a secondary backend's failed update over the primary's success", () => {
379
- const snapshots = collectProviderUpdateOutcomeSnapshots([
380
- fulfilledOutcome(
381
- true,
382
- provider({
383
- driver: driver("codex"),
384
- updateState: terminalState("succeeded", "Provider updated."),
385
- }),
386
- ),
387
- fulfilledOutcome(
388
- false,
389
- provider({
390
- driver: driver("codex"),
391
- updateState: terminalState("failed", "npm: NotFound"),
392
- }),
393
- ),
394
- ]);
395
-
396
- expect(snapshots).toHaveLength(1);
397
- expect(snapshots[0]?.updateState?.status).toBe("failed");
398
- expect(
399
- getProviderUpdateProgressToastView({ providers: snapshots, providerCount: 1 }),
400
- ).toMatchObject({ phase: "failed" });
401
- });
402
-
403
- it("treats a rejected dispatch as not contributing a snapshot", () => {
404
- const primary = provider({
405
- driver: driver("codex"),
406
- updateState: terminalState("succeeded", "Provider updated."),
407
- });
408
- const results: PromiseSettledResult<LocalProviderUpdateOutcome>[] = [
409
- fulfilledOutcome(true, primary),
410
- { status: "rejected", reason: new Error("WebSocket closed") },
411
- ];
412
-
413
- expect(collectProviderUpdateOutcomeSnapshots(results)).toEqual([primary]);
414
- expect(firstRejectedProviderUpdateMessage(results)).toBe("WebSocket closed");
415
- });
416
- });
417
-
418
- describe("per-environment update grouping", () => {
419
- const environment = (
420
- input: {
421
- readonly environmentId: string;
422
- readonly providers: ReadonlyArray<ServerProvider>;
423
- } & Partial<Omit<LocalEnvironmentProvidersInput, "environmentId" | "providers">>,
424
- ): LocalEnvironmentProvidersInput => ({
425
- environmentId: input.environmentId as EnvironmentId,
426
- label: input.label ?? input.environmentId,
427
- isPrimary: input.isPrimary ?? false,
428
- connectionState: input.connectionState ?? "ready",
429
- providers: input.providers,
430
- });
431
-
432
- it("flags settling while a secondary backend is still connecting", () => {
433
- const result = buildLocalEnvironmentUpdateGroups([
434
- environment({
435
- environmentId: "env-windows",
436
- isPrimary: true,
437
- providers: [provider({ driver: driver("codex") })],
438
- }),
439
- environment({ environmentId: "env-wsl", connectionState: "connecting", providers: [] }),
440
- ]);
441
-
442
- expect(result.isAnySettling).toBe(true);
443
- expect(
444
- result.groups.find((group) => group.environmentId === ("env-wsl" as EnvironmentId))
445
- ?.isSettling,
446
- ).toBe(true);
447
- });
448
- });
449
-
450
- describe("resolveEnvironmentUpdateRowStatus", () => {
451
- const group: LocalEnvironmentUpdateGroup = {
452
- environmentId: "env-wsl" as EnvironmentId,
453
- label: "WSL",
454
- isPrimary: false,
455
- isSettling: false,
456
- candidates: [updateCandidate({ driver: driver("codex"), latestVersion: "1.1.0" })],
457
- providers: [],
458
- };
459
- const succeededResult: ProviderUpdateToastView = {
460
- phase: "succeeded",
461
- type: "success",
462
- title: "Provider updated",
463
- description: "New sessions will use the updated provider.",
464
- };
465
- const successPill: ProviderUpdateSidebarPillView = {
466
- key: "succeeded:codex",
467
- tone: "success",
468
- title: "Codex updated",
469
- description: "New sessions will use the updated provider.",
470
- };
471
-
472
- it("prefers a transport error", () => {
473
- expect(
474
- resolveEnvironmentUpdateRowStatus({
475
- group,
476
- error: "boom",
477
- result: succeededResult,
478
- pill: successPill,
479
- isPending: true,
480
- }),
481
- ).toMatchObject({ kind: "failed", text: "boom" });
482
- });
483
- });
277
});
278
279
it("does not offer incompatible latest versions and restores suggestions after policy relaxation", () => {
apps/web/src/components/ProviderUpdateLaunchNotification.logic.ts
+5
-396
@@ -2,7 +2,6 @@ import {
2
defaultInstanceIdForDriver,
3
PROVIDER_DISPLAY_NAMES,
4
type EnvironmentId,
5
- type ExecutionEnvironmentPlatformOs,
5
type ProviderDriverKind,
6
type ProviderInstanceId,
7
type ServerProvider,
@@ -27,27 +26,6 @@ export type ProviderSettingsUpdateCandidate = ServerProvider & {
26
};
27
};
28
30
-export type ProviderUpdateToastType = "warning" | "loading" | "error" | "success";
31
-export type ProviderUpdateToastPhase = "initial" | "running" | "failed" | "unchanged" | "succeeded";
32
-
33
-export interface ProviderUpdateToastView {
34
- readonly phase: ProviderUpdateToastPhase;
35
- readonly type: ProviderUpdateToastType;
36
- readonly title: string;
37
- readonly description: string;
38
- readonly dismissAfterVisibleMs?: number;
39
-}
40
-
41
-/**
42
- * A non-terminal ("initial"/"running") snapshot never re-polls itself, so
43
- * storing one pins an update row's spinner indefinitely once its pending flag
44
- * expires; such phases must be dropped in favor of the live per-environment
45
- * provider state instead of being persisted.
46
- */
47
-export function isTerminalProviderUpdatePhase(phase: ProviderUpdateToastPhase): boolean {
48
- return phase === "succeeded" || phase === "failed" || phase === "unchanged";
49
-}
50
-
29
export type ProviderUpdateSidebarPillTone = "loading" | "warning" | "error" | "success";
30
31
export interface ProviderUpdateSidebarPillView {
@@ -100,19 +78,6 @@ function dedupeProvidersByDriver<T extends ServerProvider>(providers: ReadonlyAr
78
return [...latestProviderByDriver.values()];
79
}
80
103
-function dedupeProvidersByInstanceId<T extends ServerProvider>(providers: ReadonlyArray<T>): T[] {
104
- const latestProviderByInstanceId = new Map<ProviderInstanceId, T>();
105
-
106
- for (const provider of providers) {
107
- const current = latestProviderByInstanceId.get(provider.instanceId);
108
- if (!current || provider.checkedAt.localeCompare(current.checkedAt) >= 0) {
109
- latestProviderByInstanceId.set(provider.instanceId, provider);
110
- }
111
- }
112
-
113
- return [...latestProviderByInstanceId.values()];
114
-}
115
-
81
function getProviderUpdatedTitle(provider: Pick<ServerProvider, "driver" | "version">): string {
82
const providerName = PROVIDER_DISPLAY_NAMES[provider.driver] ?? provider.driver;
83
return provider.version
@@ -211,19 +176,6 @@ export function canOneClickUpdateProviderCandidate(
176
);
177
}
178
214
-export function providerUpdateNotificationKey(
215
- providers: ReadonlyArray<ProviderUpdateCandidate>,
216
-): string | null {
217
- const parts = dedupeProvidersByDriver(providers)
218
- .map((provider) => {
219
- const advisory = provider.versionAdvisory;
220
- return [provider.driver, advisory.latestVersion].join(":");
221
- })
222
- .toSorted();
223
-
224
- return parts.length > 0 ? parts.join("|") : null;
225
-}
226
-
179
function formatProviderList(providers: ReadonlyArray<Pick<ServerProvider, "driver">>) {
180
const names = providers.map(
181
(provider) => PROVIDER_DISPLAY_NAMES[provider.driver] ?? provider.driver,
@@ -234,126 +186,6 @@ function formatProviderList(providers: ReadonlyArray<Pick<ServerProvider, "drive
186
return `${names.slice(0, -1).join(", ")}, and ${names[names.length - 1]}`;
187
}
188
237
-/**
238
- * Install and provider settings reach only installs the server can update.
239
- * The rest are updated by the app or tool that installed them, so they get
240
- * their own sentence whatever else the notice offers.
241
- */
242
-function describeInitialUpdates(input: {
243
- readonly updateProviders: ReadonlyArray<ProviderUpdateCandidate>;
244
- readonly oneClickProviders: ReadonlyArray<ProviderUpdateCandidate>;
245
-}): string {
246
- const fromSettings = input.updateProviders.filter(
247
- (provider) => provider.versionAdvisory.canUpdate,
248
- );
249
- const manual = input.updateProviders.filter((provider) => !provider.versionAdvisory.canUpdate);
250
- return [
251
- input.oneClickProviders.length > 0
252
- ? "Install the update now or review provider settings."
253
- : fromSettings.length > 0
254
- ? `${formatProviderList(fromSettings)} can be updated from provider settings.`
255
- : null,
256
- manual.length > 0
257
- ? `Update ${formatProviderList(manual)} with the app or tool that installed ${manual.length === 1 ? "it" : "them"}.`
258
- : null,
259
- ]
260
- .filter((sentence) => sentence !== null)
261
- .join(" ");
262
-}
263
-
264
-export function getProviderUpdateInitialToastView(input: {
265
- readonly updateProviders: ReadonlyArray<ProviderUpdateCandidate>;
266
- readonly oneClickProviders: ReadonlyArray<ProviderUpdateCandidate>;
267
-}): ProviderUpdateToastView {
268
- return {
269
- phase: "initial",
270
- type: "warning",
271
- title: getProviderUpdateInitialToastTitle(input.updateProviders),
272
- description: describeInitialUpdates(input),
273
- };
274
-}
275
-
276
-export function shouldShowPrimaryProviderUpdateToast(view: ProviderUpdateToastView): boolean {
277
- return view.phase !== "running";
278
-}
279
-
280
-function getProviderUpdateRunningToastView(providerCount: number): ProviderUpdateToastView {
281
- return {
282
- phase: "running",
283
- type: "loading",
284
- title: providerCount === 1 ? "Updating provider" : "Updating providers",
285
- description: "Running provider update command.",
286
- };
287
-}
288
-
289
-export function getProviderUpdateRejectedToastView(
290
- providerCount: number,
291
- message: string,
292
-): ProviderUpdateToastView {
293
- return {
294
- phase: "failed",
295
- type: "error",
296
- title: providerCount === 1 ? "Provider update failed" : "Provider updates failed",
297
- description: message,
298
- };
299
-}
300
-
301
-export function getProviderUpdateProgressToastView(input: {
302
- readonly providers: ReadonlyArray<ServerProvider>;
303
- readonly providerCount: number;
304
-}): ProviderUpdateToastView {
305
- const providers = dedupeProvidersByDriver(input.providers);
306
- const failedProviders = providers.filter((provider) => provider.updateState?.status === "failed");
307
- if (failedProviders.length > 0) {
308
- return {
309
- phase: "failed",
310
- type: "error",
311
- title: failedProviders.length === 1 ? "Provider update failed" : "Provider updates failed",
312
- description: getFailedProviderUpdateDescription(failedProviders),
313
- };
314
- }
315
-
316
- const unchangedProviders = providers.filter(
317
- (provider) => provider.updateState?.status === "unchanged",
318
- );
319
- if (unchangedProviders.length > 0) {
320
- return {
321
- phase: "unchanged",
322
- type: "warning",
323
- title:
324
- unchangedProviders.length === 1
325
- ? "Provider still needs an update"
326
- : "Providers still need updates",
327
- description: `${formatProviderList(unchangedProviders)} ${
328
- unchangedProviders.length === 1 ? "still appears" : "still appear"
329
- } outdated. Check provider settings for details.`,
330
- };
331
- }
332
-
333
- if (providers.some(isProviderUpdateActive)) {
334
- return getProviderUpdateRunningToastView(input.providerCount);
335
- }
336
-
337
- const hasCompleteProviderSnapshots = providers.length >= input.providerCount;
338
- const allProvidersUpdated =
339
- hasCompleteProviderSnapshots &&
340
- providers.every(
341
- (provider) =>
342
- provider.updateState?.status === "succeeded" || !isProviderUpdateCandidate(provider),
343
- );
344
- if (allProvidersUpdated) {
345
- return {
346
- phase: "succeeded",
347
- type: "success",
348
- title: input.providerCount === 1 ? "Provider updated" : "Provider updates finished",
349
- description: getProviderUpdatedDescription(input.providerCount),
350
- dismissAfterVisibleMs: PROVIDER_UPDATE_SUCCESS_VISIBLE_MS,
351
- };
352
- }
353
-
354
- return getProviderUpdateRunningToastView(input.providerCount);
355
-}
356
-
189
export interface ProviderUpdateRun {
190
readonly environmentId: EnvironmentId;
191
readonly machineLabel: string;
@@ -390,9 +222,11 @@ export function getProviderUpdateRunOutcome(
222
};
223
}
224
393
-export function getProviderUpdateRunToastView(
394
- runs: ReadonlyArray<ProviderUpdateRun>,
395
-): Pick<ProviderUpdateToastView, "type" | "title" | "description"> | null {
225
+export function getProviderUpdateRunToastView(runs: ReadonlyArray<ProviderUpdateRun>): {
226
+ readonly type: "success" | "error";
227
+ readonly title: string;
228
+ readonly description: string;
229
+} | null {
230
const settled = runs
231
.map(getProviderUpdateRunOutcome)
232
.filter((outcome) => outcome.status !== "interrupted");
@@ -421,39 +255,6 @@ export function getProviderUpdateRunToastView(
255
};
256
}
257
424
-export function collectUpdatedProviderSnapshots(input: {
425
- readonly results: ReadonlyArray<
426
- AtomCommandResult<{ readonly providers: ReadonlyArray<ServerProvider> }, unknown>
427
- >;
428
- readonly providerInstanceIds: ReadonlySet<ProviderInstanceId>;
429
-}): ServerProvider[] {
430
- const matchedProviders: ServerProvider[] = [];
431
-
432
- for (const result of input.results) {
433
- if (result._tag === "Failure") {
434
- continue;
435
- }
436
- for (const provider of result.value.providers) {
437
- if (input.providerInstanceIds.has(provider.instanceId)) {
438
- matchedProviders.push(provider);
439
- }
440
- }
441
- }
442
-
443
- return dedupeProvidersByInstanceId(matchedProviders);
444
-}
445
-
446
-export function firstFailedProviderUpdateMessage(
447
- results: ReadonlyArray<AtomCommandResult<unknown, unknown>>,
448
-): string | null {
449
- const failed = results.find((result) => result._tag === "Failure");
450
- if (!failed || failed._tag !== "Failure") {
451
- return null;
452
- }
453
- const error = squashAtomCommandFailure(failed);
454
- return error instanceof Error ? error.message : "Provider update failed.";
455
-}
456
-
258
function getUpdateFinishedAt(provider: ServerProvider): string | null {
259
return provider.updateState?.finishedAt ?? null;
260
}
@@ -630,17 +431,6 @@ export function getProviderUpdateSidebarPillView(
431
);
432
}
433
633
-function getProviderUpdateInitialToastTitle(
634
- providers: ReadonlyArray<ProviderUpdateCandidate>,
635
-): string {
636
- if (providers.length === 1) {
637
- const provider = providers[0]!;
638
- const providerName = PROVIDER_DISPLAY_NAMES[provider.driver] ?? provider.driver;
639
- return `Update Available: ${providerName} ${formatVersion(provider.versionAdvisory.latestVersion)}`;
640
- }
641
- return `Updates Available: ${providers.length} providers`;
642
-}
643
-
434
function getFailedProviderUpdateDescription(providers: ReadonlyArray<ServerProvider>): string {
435
if (providers.length === 1) {
436
const provider = providers[0]!;
@@ -650,184 +440,3 @@ function getFailedProviderUpdateDescription(providers: ReadonlyArray<ServerProvi
440
}
441
return `${formatProviderList(providers)} failed to update. Check provider settings for details.`;
442
}
653
-
654
-export interface LocalProviderUpdateOutcome {
655
- readonly environmentId: EnvironmentId;
656
- readonly isPrimary: boolean;
657
- readonly driver: ProviderDriverKind;
658
- readonly instanceId: ProviderInstanceId;
659
- readonly provider: ServerProvider | null;
660
-}
661
-
662
-const PROVIDER_UPDATE_STATUS_SEVERITY: Record<string, number> = {
663
- succeeded: 1,
664
- queued: 2,
665
- running: 2,
666
- unchanged: 3,
667
- failed: 4,
668
-};
669
-
670
-function providerUpdateOutcomeSeverity(provider: ServerProvider): number {
671
- return PROVIDER_UPDATE_STATUS_SEVERITY[provider.updateState?.status ?? ""] ?? 0;
672
-}
673
-
674
-export function firstRejectedProviderUpdateMessage(
675
- results: ReadonlyArray<PromiseSettledResult<unknown>>,
676
-): string | null {
677
- const rejected = results.find((result) => result.status === "rejected");
678
- if (!rejected) {
679
- return null;
680
- }
681
- return rejected.reason instanceof Error ? rejected.reason.message : "Provider update failed.";
682
-}
683
-
684
-export function collectProviderUpdateOutcomeSnapshots(
685
- results: ReadonlyArray<PromiseSettledResult<LocalProviderUpdateOutcome>>,
686
-): ServerProvider[] {
687
- const worstByDriver = new Map<ProviderDriverKind, ServerProvider>();
688
- for (const result of results) {
689
- if (result.status !== "fulfilled" || result.value.provider === null) {
690
- continue;
691
- }
692
- const provider = result.value.provider;
693
- const current = worstByDriver.get(provider.driver);
694
- if (
695
- !current ||
696
- providerUpdateOutcomeSeverity(provider) > providerUpdateOutcomeSeverity(current)
697
- ) {
698
- worstByDriver.set(provider.driver, provider);
699
- }
700
- }
701
- return [...worstByDriver.values()];
702
-}
703
-
704
-export function deriveEnvironmentDisplayLabel(input: {
705
- readonly isWsl: boolean;
706
- readonly wslDistro: string | null;
707
- readonly platformOs: ExecutionEnvironmentPlatformOs | undefined;
708
- readonly fallbackLabel: string;
709
-}): string {
710
- if (input.isWsl) {
711
- return input.wslDistro ? `WSL · ${input.wslDistro}` : "WSL";
712
- }
713
- switch (input.platformOs) {
714
- case "windows":
715
- return "Windows";
716
- case "darwin":
717
- return "macOS";
718
- case "linux":
719
- return "Linux";
720
- default:
721
- return input.fallbackLabel;
722
- }
723
-}
724
-
725
-export type EnvironmentUpdateConnectionState = "connecting" | "ready" | "disconnected" | "error";
726
-
727
-export interface LocalEnvironmentProvidersInput {
728
- readonly environmentId: EnvironmentId;
729
- readonly label: string;
730
- readonly isPrimary: boolean;
731
- readonly connectionState: EnvironmentUpdateConnectionState;
732
- readonly providers: ReadonlyArray<ServerProvider>;
733
-}
734
-
735
-export interface LocalEnvironmentUpdateGroup {
736
- readonly environmentId: EnvironmentId;
737
- readonly label: string;
738
- readonly isPrimary: boolean;
739
- readonly isSettling: boolean;
740
- readonly candidates: ProviderUpdateCandidate[];
741
- readonly providers: ReadonlyArray<ServerProvider>;
742
-}
743
-
744
-export function buildLocalEnvironmentUpdateGroups(
745
- environments: ReadonlyArray<LocalEnvironmentProvidersInput>,
746
-): { groups: LocalEnvironmentUpdateGroup[]; isAnySettling: boolean } {
747
- const groups = environments.map((environment) => ({
748
- environmentId: environment.environmentId,
749
- label: environment.label,
750
- isPrimary: environment.isPrimary,
751
- isSettling: environment.connectionState === "connecting",
752
- candidates: collectProviderUpdateCandidates(environment.providers).filter((candidate) =>
753
- canOneClickUpdateProviderCandidate(candidate, environment.providers),
754
- ),
755
- providers: environment.providers,
756
- }));
757
- const isAnySettling = environments.some(
758
- (environment) => environment.connectionState === "connecting",
759
- );
760
- return { groups, isAnySettling };
761
-}
762
-
763
-export function environmentGroupsWithUpdates(
764
- groups: ReadonlyArray<LocalEnvironmentUpdateGroup>,
765
-): LocalEnvironmentUpdateGroup[] {
766
- return groups.filter((group) => group.candidates.length > 0);
767
-}
768
-
769
-export function localEnvironmentUpdateNotificationKey(
770
- groups: ReadonlyArray<LocalEnvironmentUpdateGroup>,
771
-): string | null {
772
- const parts = environmentGroupsWithUpdates(groups)
773
- .map((group) => {
774
- const providerParts = group.candidates
775
- .map((candidate) => `${candidate.driver}:${candidate.versionAdvisory.latestVersion}`)
776
- .toSorted()
777
- .join(",");
778
- return `${group.environmentId}=${providerParts}`;
779
- })
780
- .toSorted();
781
- return parts.length > 0 ? parts.join("|") : null;
782
-}
783
-
784
-export type ProviderUpdateRowStatusKind = "idle" | "loading" | "success" | "failed" | "unchanged";
785
-
786
-export interface ProviderUpdateRowStatus {
787
- readonly kind: ProviderUpdateRowStatusKind;
788
- readonly text: string;
789
-}
790
-
791
-function environmentProviderNames(group: LocalEnvironmentUpdateGroup): string {
792
- return group.candidates
793
- .map((candidate) => PROVIDER_DISPLAY_NAMES[candidate.driver] ?? candidate.driver)
794
- .join(", ");
795
-}
796
-
797
-export function resolveEnvironmentUpdateRowStatus(input: {
798
- readonly group: LocalEnvironmentUpdateGroup;
799
- readonly error: string | undefined;
800
- readonly result: ProviderUpdateToastView | undefined;
801
- readonly pill: ProviderUpdateSidebarPillView | null;
802
- readonly isPending: boolean;
803
-}): ProviderUpdateRowStatus {
804
- if (input.error) {
805
- return { kind: "failed", text: input.error };
806
- }
807
- if (input.result) {
808
- switch (input.result.phase) {
809
- case "succeeded":
810
- return { kind: "success", text: "Updated" };
811
- case "failed":
812
- return { kind: "failed", text: input.result.description };
813
- case "unchanged":
814
- return { kind: "unchanged", text: input.result.description };
815
- }
816
- }
817
- if (input.pill) {
818
- switch (input.pill.tone) {
819
- case "success":
820
- return { kind: "success", text: "Updated" };
821
- case "error":
822
- return { kind: "failed", text: input.pill.description };
823
- case "warning":
824
- return { kind: "unchanged", text: input.pill.description };
825
- default:
826
- return { kind: "loading", text: "Updating…" };
827
- }
828
- }
829
- if (input.result || input.isPending) {
830
- return { kind: "loading", text: "Updating…" };
831
- }
832
- return { kind: "idle", text: environmentProviderNames(input.group) };
833
-}
apps/web/src/components/ProviderUpdateLaunchNotification.tsx
deleted
-168
@@ -1,168 +0,0 @@
1
-import { useNavigate } from "@tanstack/react-router";
2
-import { DownloadIcon } from "lucide-react";
3
-import { useEffect, useRef, useState } from "react";
4
-
5
-import { useStableCallback } from "~/hooks/useStableCallback";
6
-import { useEnvironments } from "~/state/environments";
7
-import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal";
8
-import { useDismissedProviderUpdateNotificationKeys } from "../providerUpdateDismissal";
9
-import { ProviderUpdateEnvironmentRows } from "./ProviderUpdateEnvironmentRows";
10
-import { useLocalEnvironmentUpdateGroups } from "./ProviderUpdateLaunchNotification.environments";
11
-import {
12
- collectProviderUpdateCandidates,
13
- environmentGroupsWithUpdates,
14
- getProviderUpdateInitialToastView,
15
- localEnvironmentUpdateNotificationKey,
16
-} from "./ProviderUpdateLaunchNotification.logic";
17
-import { ProviderUpdatePrimaryNotification } from "./ProviderUpdatePrimaryNotification";
18
-import { stackedThreadToast, toastManager } from "./ui/toast";
19
-
20
-function useHasLocalSecondaryEnvironment(): boolean {
21
- const { environments } = useEnvironments();
22
- return environments.some((environment) =>
23
- isDesktopLocalConnectionTarget(environment.entry.target),
24
- );
25
-}
26
-
27
-export function ProviderUpdateLaunchNotification() {
28
- const hasLocalSecondary = useHasLocalSecondaryEnvironment();
29
-
30
- return hasLocalSecondary ? (
31
- <ProviderUpdateEnvironmentsNotification />
32
- ) : (
33
- <ProviderUpdatePrimaryNotification />
34
- );
35
-}
36
-
37
-const seenProviderUpdateNotificationKeys = new Set<string>();
38
-type ProviderUpdateToastId = ReturnType<typeof toastManager.add>;
39
-
40
-// While a local backend (e.g. WSL) is still connecting, defer the popover so it
41
-// reflects every environment. Cap the wait so a stuck or failed backend can't
42
-// suppress the primary's updates indefinitely.
43
-const SETTLING_GRACE_MS = 30_000;
44
-
45
-function ProviderUpdateEnvironmentsNotification() {
46
- const navigate = useNavigate();
47
- const { groups, isAnySettling } = useLocalEnvironmentUpdateGroups();
48
- const { dismissedNotificationKeys, dismissNotificationKey } =
49
- useDismissedProviderUpdateNotificationKeys();
50
-
51
- const activeToastRef = useRef<{
52
- readonly toastId: ProviderUpdateToastId;
53
- readonly key: string;
54
- } | null>(null);
55
- // Whether the user has triggered an update from the current toast. Until they
56
- // do, the prompt is replaced when the available updates change; afterward it
57
- // is kept so in-progress rows are not torn down.
58
- const hasInteractedRef = useRef(false);
59
-
60
- useEffect(() => {
61
- return () => {
62
- if (activeToastRef.current !== null) {
63
- toastManager.close(activeToastRef.current.toastId);
64
- activeToastRef.current = null;
65
- }
66
- };
67
- }, []);
68
-
69
- const updateGroups = environmentGroupsWithUpdates(groups);
70
- const notificationKey = localEnvironmentUpdateNotificationKey(groups);
71
- const candidateUnion = collectProviderUpdateCandidates(
72
- updateGroups.flatMap((group) => group.candidates),
73
- );
74
-
75
- const [settleGraceElapsed, setSettleGraceElapsed] = useState(false);
76
- // The grace period restarts with the next settling phase.
77
- if (!isAnySettling && settleGraceElapsed) {
78
- setSettleGraceElapsed(false);
79
- }
80
- useEffect(() => {
81
- if (!isAnySettling) return;
82
- const timer = setTimeout(() => setSettleGraceElapsed(true), SETTLING_GRACE_MS);
83
- return () => clearTimeout(timer);
84
- }, [isAnySettling]);
85
- const isGated = isAnySettling && !settleGraceElapsed;
86
-
87
- const openProviderSettings = () => {
88
- const active = activeToastRef.current;
89
- if (active !== null) {
90
- toastManager.close(active.toastId);
91
- activeToastRef.current = null;
92
- }
93
- void navigate({ to: "/settings/providers" });
94
- };
95
-
96
- // The toast closes long after the effect that opened it, so it dismisses the key
97
- // the updates have moved to by then.
98
- const dismissPrompt = useStableCallback(() => {
99
- if (notificationKey) {
100
- dismissNotificationKey(notificationKey);
101
- }
102
- activeToastRef.current = null;
103
- });
104
-
105
- useEffect(() => {
106
- const canShowPrompt =
107
- notificationKey !== null &&
108
- !isGated &&
109
- !dismissedNotificationKeys.has(notificationKey) &&
110
- !seenProviderUpdateNotificationKeys.has(notificationKey);
111
-
112
- const active = activeToastRef.current;
113
- if (
114
- active &&
115
- active.key !== notificationKey &&
116
- !hasInteractedRef.current &&
117
- (notificationKey === null || !isGated)
118
- ) {
119
- toastManager.close(active.toastId);
120
- activeToastRef.current = null;
121
- }
122
-
123
- if (!notificationKey || !canShowPrompt || activeToastRef.current !== null) {
124
- return;
125
- }
126
-
127
- seenProviderUpdateNotificationKeys.add(notificationKey);
128
- hasInteractedRef.current = false;
129
-
130
- const toastId = toastManager.add(
131
- stackedThreadToast({
132
- type: "warning",
133
- title: getProviderUpdateInitialToastView({
134
- updateProviders: candidateUnion,
135
- oneClickProviders: candidateUnion,
136
- }).title,
137
- description: (
138
- <ProviderUpdateEnvironmentRows
139
- onInteract={() => {
140
- hasInteractedRef.current = true;
141
- }}
142
- />
143
- ),
144
- timeout: 0,
145
- actionProps: {
146
- children: "Settings",
147
- onClick: openProviderSettings,
148
- },
149
- actionVariant: "outline",
150
- data: {
151
- hideCopyButton: true,
152
- leadingIcon: <DownloadIcon aria-hidden="true" className="size-4 text-success" />,
153
- onClose: dismissPrompt,
154
- },
155
- }),
156
- );
157
- activeToastRef.current = { toastId, key: notificationKey };
158
- }, [
159
- notificationKey,
160
- isGated,
161
- candidateUnion,
162
- dismissedNotificationKeys,
163
- dismissPrompt,
164
- openProviderSettings,
165
- ]);
166
-
167
- return null;
168
-}
apps/web/src/components/ProviderUpdatePrimaryNotification.tsx
deleted
-340
@@ -1,340 +0,0 @@
1
-import { useNavigate } from "@tanstack/react-router";
2
-import { useAtomValue } from "@effect/atom-react";
3
-import { DownloadIcon } from "lucide-react";
4
-import { useEffect, useRef } from "react";
5
-import {
6
- AuthProvidersManageScope,
7
- type ServerProvider,
8
- type ProviderInstanceId,
9
-} from "@t3tools/contracts";
10
-
11
-import { primaryServerProvidersAtom, serverEnvironment } from "../state/server";
12
-import { usePrimaryEnvironment } from "../state/environments";
13
-import { readEnvironmentScope, useEnvironmentScope } from "../state/session";
14
-import { useDismissedProviderUpdateNotificationKeys } from "../providerUpdateDismissal";
15
-import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
16
-import {
17
- canOneClickUpdateProviderCandidate,
18
- collectProviderUpdateCandidates,
19
- collectUpdatedProviderSnapshots,
20
- firstFailedProviderUpdateMessage,
21
- getProviderUpdateInitialToastView,
22
- getProviderUpdateProgressToastView,
23
- getProviderUpdateRejectedToastView,
24
- providerUpdateNotificationKey,
25
- shouldShowPrimaryProviderUpdateToast,
26
- type ProviderUpdateToastView,
27
-} from "./ProviderUpdateLaunchNotification.logic";
28
-import { hiddenToastActionProps, stackedThreadToast, toastManager } from "./ui/toast";
29
-import { useAtomCommand } from "../state/use-atom-command";
30
-
31
-const seenProviderUpdateNotificationKeys = new Set<string>();
32
-type ProviderUpdateToastId = ReturnType<typeof toastManager.add>;
33
-
34
-type ActiveProviderUpdateToast =
35
- | {
36
- readonly kind: "prompt";
37
- readonly key: string;
38
- readonly toastId: ProviderUpdateToastId;
39
- readonly canManageProviders: boolean;
40
- }
41
- | {
42
- readonly kind: "update";
43
- readonly key: string;
44
- readonly providerInstanceIds: ReadonlySet<ProviderInstanceId>;
45
- readonly providerCount: number;
46
- };
47
-
48
-function ProviderUpdateToastIcon({ provider }: { provider: ServerProvider }) {
49
- return (
50
- <span className="relative inline-flex size-4 shrink-0 items-center justify-center">
51
- <ProviderInstanceIcon
52
- driverKind={provider.driver}
53
- displayName={provider.displayName ?? provider.driver}
54
- acpRegistryIconUrl={provider.iconUrl}
55
- iconClassName="size-4"
56
- />
57
- <span className="absolute -right-1 -bottom-1 z-40 inline-flex size-3 items-center justify-center rounded-full bg-popover">
58
- <DownloadIcon aria-hidden="true" className="size-2.5 text-success" strokeWidth={2.5} />
59
- </span>
60
- </span>
61
- );
62
-}
63
-
64
-function addProviderUpdateToast(input: {
65
- readonly view: ProviderUpdateToastView;
66
- readonly openSettings: (toastId: ProviderUpdateToastId) => void;
67
-}) {
68
- if (input.view.type === "loading" || input.view.type === "success") {
69
- return toastManager.add({
70
- type: input.view.type,
71
- title: input.view.title,
72
- description: input.view.description,
73
- timeout: 0,
74
- actionProps: hiddenToastActionProps,
75
- data: {
76
- hideCopyButton: true,
77
- ...(input.view.dismissAfterVisibleMs !== undefined
78
- ? { dismissAfterVisibleMs: input.view.dismissAfterVisibleMs }
79
- : {}),
80
- },
81
- });
82
- }
83
-
84
- let toastId!: ProviderUpdateToastId;
85
- toastId = toastManager.add(
86
- stackedThreadToast({
87
- type: input.view.type,
88
- title: input.view.title,
89
- description: input.view.description,
90
- timeout: 0,
91
- actionProps: {
92
- children: "Settings",
93
- onClick: () => input.openSettings(toastId),
94
- },
95
- actionVariant: "outline",
96
- data: {
97
- hideCopyButton: true,
98
- },
99
- }),
100
- );
101
- return toastId;
102
-}
103
-
104
-export function ProviderUpdatePrimaryNotification() {
105
- const navigate = useNavigate();
106
- const providers = useAtomValue(primaryServerProvidersAtom);
107
- const primaryEnvironment = usePrimaryEnvironment();
108
- const canManageProviders = useEnvironmentScope(
109
- primaryEnvironment?.environmentId ?? null,
110
- AuthProvidersManageScope,
111
- );
112
- const updateProvider = useAtomCommand(serverEnvironment.updateProvider, {
113
- reportFailure: false,
114
- });
115
- const activeToastRef = useRef<ActiveProviderUpdateToast | null>(null);
116
- const { dismissedNotificationKeys, dismissNotificationKey } =
117
- useDismissedProviderUpdateNotificationKeys();
118
-
119
- useEffect(() => {
120
- return () => {
121
- const activeToast = activeToastRef.current;
122
- if (activeToast?.kind === "prompt") {
123
- toastManager.close(activeToast.toastId);
124
- }
125
- activeToastRef.current = null;
126
- };
127
- }, []);
128
-
129
- const updateProviders = collectProviderUpdateCandidates(providers);
130
- const notificationKey = providerUpdateNotificationKey(updateProviders);
131
- const oneClickProviders = updateProviders.filter((provider) =>
132
- canOneClickUpdateProviderCandidate(provider, providers),
133
- );
134
-
135
- const openProviderSettings = (toastId?: ProviderUpdateToastId) => {
136
- const activeToast = activeToastRef.current;
137
- if (toastId !== undefined) {
138
- toastManager.close(toastId);
139
- } else if (activeToast?.kind === "prompt") {
140
- toastManager.close(activeToast.toastId);
141
- }
142
- if (
143
- activeToast &&
144
- (toastId === undefined || (activeToast.kind === "prompt" && activeToast.toastId === toastId))
145
- ) {
146
- activeToastRef.current = null;
147
- }
148
- void navigate({ to: "/settings/providers" });
149
- };
150
-
151
- useEffect(() => {
152
- const activeToast = activeToastRef.current;
153
- if (activeToast?.kind !== "update") {
154
- return;
155
- }
156
-
157
- const activeProviders = providers.filter((provider) =>
158
- activeToast.providerInstanceIds.has(provider.instanceId),
159
- );
160
- const view = getProviderUpdateProgressToastView({
161
- providers: activeProviders,
162
- providerCount: activeToast.providerCount,
163
- });
164
- if (!shouldShowPrimaryProviderUpdateToast(view)) {
165
- return;
166
- }
167
-
168
- addProviderUpdateToast({ view, openSettings: openProviderSettings });
169
- activeToastRef.current = null;
170
- }, [providers, openProviderSettings]);
171
-
172
- useEffect(() => {
173
- const activeToast = activeToastRef.current;
174
- if (activeToast?.kind === "prompt" && activeToast.key !== notificationKey) {
175
- toastManager.close(activeToast.toastId);
176
- activeToastRef.current = null;
177
- }
178
-
179
- const updateExistingPrompt =
180
- activeToast?.kind === "prompt" &&
181
- activeToast.key === notificationKey &&
182
- activeToast.canManageProviders !== canManageProviders;
183
- if (
184
- !notificationKey ||
185
- dismissedNotificationKeys.has(notificationKey) ||
186
- (seenProviderUpdateNotificationKeys.has(notificationKey) && !updateExistingPrompt) ||
187
- (activeToastRef.current && !updateExistingPrompt)
188
- ) {
189
- return;
190
- }
191
-
192
- seenProviderUpdateNotificationKeys.add(notificationKey);
193
-
194
- const initialView = getProviderUpdateInitialToastView({ updateProviders, oneClickProviders });
195
-
196
- let toastId!: ProviderUpdateToastId;
197
- let updateStarted = false;
198
- const openSettings = () => openProviderSettings(toastId);
199
- const dismissPrompt = () => {
200
- dismissNotificationKey(notificationKey);
201
- };
202
-
203
- const runUpdates = () => {
204
- if (
205
- updateStarted ||
206
- oneClickProviders.length === 0 ||
207
- !primaryEnvironment ||
208
- !readEnvironmentScope(primaryEnvironment.environmentId, AuthProvidersManageScope)
209
- ) {
210
- return;
211
- }
212
- updateStarted = true;
213
-
214
- const providerCount = oneClickProviders.length;
215
- const providerInstanceIds = new Set(oneClickProviders.map((provider) => provider.instanceId));
216
- const activeUpdate: ActiveProviderUpdateToast = {
217
- kind: "update",
218
- key: notificationKey,
219
- providerInstanceIds,
220
- providerCount,
221
- };
222
- activeToastRef.current = activeUpdate;
223
-
224
- toastManager.close(toastId);
225
-
226
- void (async () => {
227
- const results = [];
228
- for (const provider of oneClickProviders) {
229
- if (!readEnvironmentScope(primaryEnvironment.environmentId, AuthProvidersManageScope)) {
230
- if (activeToastRef.current === activeUpdate) {
231
- addProviderUpdateToast({
232
- view: getProviderUpdateRejectedToastView(
233
- providerCount,
234
- "This connection cannot manage provider accounts.",
235
- ),
236
- openSettings: openProviderSettings,
237
- });
238
- activeToastRef.current = null;
239
- }
240
- return;
241
- }
242
- results.push(
243
- await updateProvider({
244
- environmentId: primaryEnvironment.environmentId,
245
- input: {
246
- provider: provider.driver,
247
- instanceId: provider.instanceId,
248
- },
249
- }),
250
- );
251
- }
252
-
253
- const activeUpdateToast = activeToastRef.current;
254
- if (activeUpdateToast !== activeUpdate) {
255
- return;
256
- }
257
-
258
- const failedMessage = firstFailedProviderUpdateMessage(results);
259
- if (failedMessage) {
260
- addProviderUpdateToast({
261
- view: getProviderUpdateRejectedToastView(providerCount, failedMessage),
262
- openSettings: openProviderSettings,
263
- });
264
- activeToastRef.current = null;
265
- return;
266
- }
267
-
268
- const updatedProviderSnapshots = collectUpdatedProviderSnapshots({
269
- results,
270
- providerInstanceIds,
271
- });
272
- const view = getProviderUpdateProgressToastView({
273
- providers: updatedProviderSnapshots,
274
- providerCount,
275
- });
276
- if (shouldShowPrimaryProviderUpdateToast(view)) {
277
- addProviderUpdateToast({ view, openSettings: openProviderSettings });
278
- activeToastRef.current = null;
279
- }
280
- })();
281
- };
282
-
283
- const toastOptions = stackedThreadToast({
284
- type: initialView.type,
285
- title: initialView.title,
286
- description: canManageProviders
287
- ? initialView.description
288
- : "This connection cannot manage provider accounts. View provider settings for update details.",
289
- timeout: 0,
290
- actionProps:
291
- oneClickProviders.length > 0
292
- ? {
293
- children: "Update",
294
- disabled: !canManageProviders,
295
- onClick: runUpdates,
296
- }
297
- : {
298
- children: "Settings",
299
- onClick: openSettings,
300
- },
301
- actionVariant: "outline",
302
- data: {
303
- leadingIcon:
304
- updateProviders.length === 1 ? (
305
- <ProviderUpdateToastIcon provider={updateProviders[0]!} />
306
- ) : undefined,
307
- hideCopyButton: true,
308
- onClose: dismissPrompt,
309
- ...(oneClickProviders.length > 0
310
- ? {
311
- secondaryActionProps: {
312
- children: "Settings",
313
- onClick: openSettings,
314
- },
315
- secondaryActionVariant: "outline" as const,
316
- }
317
- : {}),
318
- },
319
- });
320
- if (updateExistingPrompt && activeToast?.kind === "prompt") {
321
- toastId = activeToast.toastId;
322
- toastManager.update(toastId, toastOptions);
323
- } else {
324
- toastId = toastManager.add(toastOptions);
325
- }
326
- activeToastRef.current = { kind: "prompt", key: notificationKey, toastId, canManageProviders };
327
- }, [
328
- canManageProviders,
329
- updateProvider,
330
- dismissNotificationKey,
331
- dismissedNotificationKeys,
332
- notificationKey,
333
- oneClickProviders,
334
- openProviderSettings,
335
- primaryEnvironment,
336
- updateProviders,
337
- ]);
338
-
339
- return null;
340
-}
apps/web/src/components/ui/toast.tsx
+1
-1
@@ -760,7 +760,7 @@ function AnchoredToasts() {
760
);
761
}
762
763
-export { hiddenToastActionProps, stackedThreadToast } from "./toastHelpers";
763
+export { stackedThreadToast } from "./toastHelpers";
764
export type { StackedThreadToastOptions } from "./toastHelpers";
765
766
export {
apps/web/src/components/ui/toastHelpers.ts
-8
@@ -14,14 +14,6 @@ export type StackedThreadToastOptions = {
14
data?: Omit<ThreadToastData, "actionLayout">;
15
};
16
17
-/**
18
- * Defined `actionProps` that hide a previous toast CTA on `toastManager.update`.
19
- * Passing `actionProps: undefined` is a no-op because updates omit undefined keys.
20
- */
21
-export const hiddenToastActionProps = {
22
- children: null,
23
-} as const satisfies Pick<ComponentPropsWithoutRef<"button">, "children">;
24
-
17
export function stackedThreadToast(
18
options: StackedThreadToastOptions,
19
): ToastManagerAddOptions<ThreadToastData> {
apps/web/src/providerUpdateDismissal.ts
deleted
-36
@@ -1,36 +0,0 @@
1
-import * as Schema from "effect/Schema";
2
-
3
-import { useLocalStorage } from "./hooks/useLocalStorage";
4
-
5
-const PROVIDER_UPDATE_DISMISSALS_STORAGE_KEY = "t3code:provider-update-dismissals:v1";
6
-
7
-const ProviderUpdateDismissalsSchema = Schema.Struct({
8
- keys: Schema.Array(Schema.String),
9
-});
10
-
11
-export function useDismissedProviderUpdateNotificationKeys() {
12
- const [dismissals, setDismissals] = useLocalStorage(
13
- PROVIDER_UPDATE_DISMISSALS_STORAGE_KEY,
14
- { keys: [] },
15
- ProviderUpdateDismissalsSchema,
16
- );
17
- const dismissedKeys = dismissals.keys;
18
-
19
- const dismissedKeySet = new Set(dismissedKeys);
20
-
21
- const dismissNotificationKey = (key: string) => {
22
- const trimmedKey = key.trim();
23
- if (trimmedKey.length === 0 || dismissedKeySet.has(trimmedKey)) {
24
- return;
25
- }
26
-
27
- setDismissals({
28
- keys: [...dismissedKeys, trimmedKey],
29
- });
30
- };
31
-
32
- return {
33
- dismissedNotificationKeys: dismissedKeySet,
34
- dismissNotificationKey,
35
- };
36
-}
apps/web/src/routes/__root.tsx
-2
@@ -30,7 +30,6 @@ import { SnapShotCoordinator } from "../components/desktop/SnapShotCoordinator";
30
import { DesktopAppActivationCoordinator } from "../components/desktop/DesktopAppActivationCoordinator";
31
import { DesktopWebLinkCoordinator } from "../components/desktop/DesktopWebLinkCoordinator";
32
import { RunningThreadKeepAlive } from "../components/desktop/RunningThreadKeepAlive";
33
-import { ProviderUpdateLaunchNotification } from "../components/ProviderUpdateLaunchNotification";
33
import { DesktopUpdateLaunchNotice } from "../components/sidebar/updateEverythingRun";
34
import { LegacyThreadMigrationToast } from "../components/LegacyThreadMigrationToast";
35
import { ThreadNotificationCoordinator } from "../components/ThreadNotificationCoordinator";
@@ -254,7 +253,6 @@ function RootRouteView() {
253
{primaryEnvironmentAuthenticated ? (
254
<EventRouter skipInitialBootstrapNavigation={returningFromWelcome} />
255
) : null}
257
- {primaryEnvironmentAuthenticated ? <ProviderUpdateLaunchNotification /> : null}
256
{isElectron ? <DesktopUpdateLaunchNotice /> : null}
257
{appShell}
258
{/* Above the router: a theme draft is judged by walking the app, so the