Skip to content

Commit 3b88a39

Browse files
refactor(web): provider settings and Codex setup run as explicit flows
Provider settings copied props into editable rows from effects, the ACP registry search reported its loading state up to the dialog through effects, and Codex setup continued "install, then sign in, then open the page" by watching shared install and auth phases in effects. Watching shared phases meant an update could sign in while the previous runtime's state was still reported, and a sign-in started from another client could open a browser page here. - Codex setup: Install and Sign in now await their own operation (matched by operation id / flow id) through waitForQuerySettled, under an AbortController that Cancel, a new attempt, and unmount abort. - ACP registry: the dialog owns useAcpRegistrySearch, so loading and preparing state are read directly; debounce uses useDeadlinePassed. - ACP registry icons: one shared load per icon URL via an atom family. - t3 command row: state loads from an atom; install/uninstall refresh it. - Command arguments and environment rows reconcile their draft during render (reconcileRowsDraft) instead of in an effect. - Accent color picker: drags preview and commit once on release; keyboard, hex input and Clear commit immediately. The 120ms debounce timer is gone. Effects kept: Codex setup's provider refresh after sign-in succeeds (the server does not refresh the snapshot itself), handoff transfer, auto-start, desktop callback cancellation, plus a new unmount abort. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 87ea18c commit 3b88a39

15 files changed

Lines changed: 798 additions & 430 deletions

‎apps/web/src/components/settings/AcpRegistryIcon.tsx‎

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { useEffect, useId, useState } from "react";
1+
import { useAtomValue } from "@effect/atom-react";
2+
import * as Effect from "effect/Effect";
3+
import * as Option from "effect/Option";
4+
import { AsyncResult, Atom } from "effect/reactivity";
5+
import { useId, useState } from "react";
26
import {
37
resolveOfficialAcpRegistryIconUrl,
48
officialAcpRegistryIconUrlForAgentId,
@@ -66,6 +70,33 @@ export function loadCachedAcpRegistryIcon(iconUrl: string): Promise<Blob> {
6670
return load;
6771
}
6872

73+
// Falls back to the raw allowlisted CDN URL when the validating fetch fails: the
74+
// CDN serves no CORS headers, so the fetch is often blocked cross-origin while
75+
// native <img> loading still works. The object URL is shared per agent and
76+
// revoked when the last icon unmounts.
77+
const acpRegistryIconSourceAtom = Atom.family((iconUrl: string) =>
78+
Atom.make((get) => {
79+
let disposed = false;
80+
let objectUrl: string | null = null;
81+
get.addFinalizer(() => {
82+
disposed = true;
83+
if (objectUrl !== null) URL.revokeObjectURL(objectUrl);
84+
});
85+
return Effect.promise(() =>
86+
loadCachedAcpRegistryIcon(iconUrl).then(
87+
(blob) => {
88+
if (disposed) return iconUrl;
89+
objectUrl = URL.createObjectURL(blob);
90+
return objectUrl;
91+
},
92+
() => iconUrl,
93+
),
94+
);
95+
}).pipe(Atom.withLabel(`acp-registry-icon:${iconUrl}`)),
96+
);
97+
98+
const NO_ICON_SOURCE_ATOM = Atom.make(AsyncResult.initial<string>());
99+
69100
export function AcpRegistryAgentIcon({
70101
icon,
71102
className,
@@ -77,37 +108,18 @@ export function AcpRegistryAgentIcon({
77108
}) {
78109
const colorFilterId = useId();
79110
const iconUrl = resolveOfficialAcpRegistryIconUrl(icon);
111+
// Render only after the load pipeline resolves, so the fallback icon does
112+
// not flash a broken image.
113+
const source = Option.getOrNull(
114+
AsyncResult.value(
115+
useAtomValue(iconUrl === null ? NO_ICON_SOURCE_ATOM : acpRegistryIconSourceAtom(iconUrl)),
116+
),
117+
);
80118
const [image, setImage] = useState<{
81-
readonly iconUrl: string;
82119
readonly source: string;
83-
readonly status: "loading" | "loaded" | "failed";
120+
readonly status: "loaded" | "failed";
84121
} | null>(null);
85-
const currentImage = image?.iconUrl === iconUrl ? image : null;
86-
// The CDN lacks CORS headers; native img loading can succeed after a validating fetch fails.
87-
const source = currentImage?.source ?? null;
88-
const status = currentImage?.status ?? "loading";
89-
90-
useEffect(() => {
91-
if (iconUrl === null) return;
92-
let active = true;
93-
let objectUrl: string | null = null;
94-
void loadCachedAcpRegistryIcon(iconUrl)
95-
.then((blob) => {
96-
if (!active) return;
97-
objectUrl = URL.createObjectURL(blob);
98-
setImage({ iconUrl, source: objectUrl, status: "loading" });
99-
})
100-
.catch(() => {
101-
if (!active) return;
102-
setImage((current) =>
103-
current?.iconUrl === iconUrl ? current : { iconUrl, source: iconUrl, status: "loading" },
104-
);
105-
});
106-
return () => {
107-
active = false;
108-
if (objectUrl !== null) URL.revokeObjectURL(objectUrl);
109-
};
110-
}, [iconUrl]);
122+
const status = source !== null && image?.source === source ? image.status : "loading";
111123

112124
return (
113125
<span
@@ -144,17 +156,8 @@ export function AcpRegistryAgentIcon({
144156
decoding="async"
145157
referrerPolicy="no-referrer"
146158
src={source}
147-
onError={() => {
148-
if (iconUrl === null) return;
149-
setImage((current) =>
150-
current?.iconUrl === iconUrl && current.source !== source
151-
? current
152-
: { iconUrl, source, status: "failed" },
153-
);
154-
}}
155-
onLoad={() => {
156-
if (iconUrl !== null) setImage({ iconUrl, source, status: "loaded" });
157-
}}
159+
onError={() => setImage({ source, status: "failed" })}
160+
onLoad={() => setImage({ source, status: "loaded" })}
158161
/>
159162
) : null}
160163
</span>

‎apps/web/src/components/settings/AcpRegistrySearchStep.browser.test.tsx‎

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EnvironmentId, ProviderDriverKind, type AcpRegistrySearchAgent } from "
22
import { expect, it, vi } from "vite-plus/test";
33
import { page } from "vite-plus/test/browser";
44

5-
import { act, render } from "../../../test/render";
5+
import { render } from "../../../test/render";
66

77
const state = vi.hoisted(() => ({
88
result: null as { readonly agents: ReadonlyArray<AcpRegistrySearchAgent> } | null,
@@ -46,7 +46,7 @@ vi.mock(import("../../state/use-atom-command"), async (original) => ({
4646
useAtomCommand: (() => state.prepare) as never,
4747
}));
4848

49-
import { AcpRegistrySearchStep } from "./AcpRegistrySearchStep";
49+
import { AcpRegistrySearchStep, useAcpRegistrySearch } from "./AcpRegistrySearchStep";
5050

5151
const environmentId = EnvironmentId.make("remote-device");
5252
const gemini: AcpRegistrySearchAgent = {
@@ -63,15 +63,20 @@ const gemini: AcpRegistrySearchAgent = {
6363
integrity: "registry",
6464
};
6565

66-
function step(options?: {
66+
function Step({
67+
configured = false,
68+
onPrepared = vi.fn(),
69+
}: {
6770
readonly configured?: boolean;
6871
readonly onPrepared?: (agent: AcpRegistrySearchAgent) => void;
6972
}) {
73+
const registry = useAcpRegistrySearch(environmentId, true);
7074
return (
7175
<AcpRegistrySearchStep
7276
environmentId={environmentId}
77+
registry={registry}
7378
providerInstances={
74-
options?.configured
79+
configured
7580
? {
7681
acpRegistry_gemini: {
7782
driver: ProviderDriverKind.make("acpRegistry"),
@@ -80,20 +85,12 @@ function step(options?: {
8085
}
8186
: {}
8287
}
83-
onPrepared={options?.onPrepared ?? vi.fn()}
88+
onPrepared={onPrepared}
8489
onManualConfiguration={vi.fn()}
8590
/>
8691
);
8792
}
8893

89-
function deferred<T>() {
90-
let resolve!: (value: T) => void;
91-
const promise = new Promise<T>((done) => {
92-
resolve = done;
93-
});
94-
return { promise, resolve };
95-
}
96-
9794
function setup() {
9895
state.canManage = true;
9996
state.result = null;
@@ -111,31 +108,11 @@ it("rechecks the grant before preparing an agent", async () => {
111108
setup();
112109
state.result = { agents: [gemini] };
113110
const onPrepared = vi.fn();
114-
await using _screen = await render(step({ onPrepared }));
111+
await using _screen = await render(<Step onPrepared={onPrepared} />);
115112
state.canManage = false;
116113

117114
await page.getByRole("button", { name: "Add Gemini CLI" }).click();
118115

119116
expect(state.prepare).not.toHaveBeenCalled();
120117
expect(onPrepared).not.toHaveBeenCalled();
121118
});
122-
123-
it("ignores prepare completion after unmount", async () => {
124-
setup();
125-
const pending = deferred<unknown>();
126-
state.prepare.mockReturnValueOnce(pending.promise);
127-
state.result = { agents: [gemini] };
128-
const onPrepared = vi.fn();
129-
await using screen = await render(step({ onPrepared }));
130-
131-
await page.getByRole("button", { name: "Add Gemini CLI" }).click();
132-
await screen.unmount();
133-
await act(async () =>
134-
pending.resolve({
135-
_tag: "Success",
136-
value: { agentId: "gemini", version: "1.2.3", distribution: "npx", prepared: true },
137-
}),
138-
);
139-
140-
expect(onPrepared).not.toHaveBeenCalled();
141-
});

0 commit comments

Comments
 (0)