History

[codex] Use effect-atom optimistic resources (#531)

* Add remove in-use toasts * Use effect-atom optimistic resources

Rhys Sullivan committed 6 months ago

Commit 50cb48d1 parent 726574517 files · +435 −500Browse files

Unified · Split

17 files
  1. apps/cloud/src/web/shell.tsx +2 −2
  2. apps/local/src/web/shell.tsx +3 −4
  3. packages/plugins/google-discovery/src/react/AddGoogleDiscoverySource.tsx +33 −34
  4. packages/plugins/google-discovery/src/react/atoms.ts +29 −0
  5. packages/plugins/graphql/src/react/AddGraphqlSource.tsx +33 −36
  6. packages/plugins/graphql/src/react/atoms.ts +30 −0
  7. packages/plugins/mcp/src/react/AddMcpSource.tsx +47 −58
  8. packages/plugins/mcp/src/react/atoms.ts +29 −0
  9. packages/plugins/openapi/src/react/AddOpenApiSource.tsx +129 −93
  10. packages/plugins/openapi/src/react/atoms.ts +30 −0
  11. packages/react/src/api/atoms.tsx +47 −15
  12. packages/react/src/api/optimistic.tsx +0 −213
  13. packages/react/src/components/command-palette.tsx +2 −2
  14. packages/react/src/pages/connections.tsx +9 −14
  15. packages/react/src/pages/source-detail.tsx +4 −4
  16. packages/react/src/pages/sources.tsx +7 −20
  17. warden.toml +1 −5
apps/cloud/src/web/shell.tsx+2−2
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from "react"; · 2 unmodified lines
33 import { useAtomValue, useAtomSet } from "@effect/atom-react";
44 import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
55 import * as Exit from "effect/Exit";
6−import { useSourcesWithPending } from "@executor-js/react/api/optimistic";
6+import { sourcesOptimisticAtom } from "@executor-js/react/api/atoms";
77 import { useScope } from "@executor-js/react/api/scope-context";
88 import { Button } from "@executor-js/react/components/button";
99 import { Skeleton } from "@executor-js/react/components/skeleton";
@@ -60,7 +60,7 @@ function NavItem(props: { to: string; label: string; active: boolean; onNavigate · 50 unmodified lines
6060
6161 function SourceList(props: { pathname: string; onNavigate?: () => void }) {
6262 const scopeId = useScope();
63− const sources = useSourcesWithPending(scopeId);
63+ const sources = useAtomValue(sourcesOptimisticAtom(scopeId));
6464
6565 return AsyncResult.match(sources, {
6666 onInitial: () => (
apps/local/src/web/shell.tsx+3−4
@@ -1,9 +1,8 @@
11 import { Link, Outlet, useLocation } from "@tanstack/react-router";
22 import { useCallback, useEffect, useRef, useState } from "react";
3−import { useAtomRefresh } from "@effect/atom-react";
3+import { useAtomRefresh, useAtomValue } from "@effect/atom-react";
44 import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
5−import { sourcesAtom, toolsAtom } from "@executor-js/react/api/atoms";
6−import { useSourcesWithPending } from "@executor-js/react/api/optimistic";
5+import { sourcesAtom, sourcesOptimisticAtom, toolsAtom } from "@executor-js/react/api/atoms";
76 import { useScope, useScopeInfo } from "@executor-js/react/api/scope-context";
87 import { Button } from "@executor-js/react/components/button";
98 import { SourceFavicon } from "@executor-js/react/components/source-favicon";
@@ -261,7 +260,7 @@ function PluginNav(props: { pathname: string; onNavigate?: () => void }) { · 251 unmodified lines
261260
262261 function SourceList(props: { pathname: string; onNavigate?: () => void }) {
263262 const scopeId = useScope();
264− const sources = useSourcesWithPending(scopeId);
263+ const sources = useAtomValue(sourcesOptimisticAtom(scopeId));
265264
266265 return AsyncResult.match(sources, {
267266 onInitial: () => <div className="px-2.5 py-2 text-xs text-muted-foreground">Loading…</div>,
packages/plugins/google-discovery/src/react/AddGoogleDiscoverySource.tsx+33−34
@@ -1,7 +1,8 @@
11 import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22 import { useAtomSet } from "@effect/atom-react";
3+import * as Exit from "effect/Exit";
4+import * as Option from "effect/Option";
35
4−import { usePendingSources } from "@executor-js/react/api/optimistic";
56 import { sourceWriteKeys } from "@executor-js/react/api/reactivity-keys";
67 import { useScope } from "@executor-js/react/api/scope-context";
78 import type { SecretPickerSecret } from "@executor-js/react/plugins/secret-picker";
@@ -44,7 +45,7 @@ import { FloatActions } from "@executor-js/react/components/float-actions"; · 36 unmodified lines
4445 import { Input } from "@executor-js/react/components/input";
4546 import { RadioGroup, RadioGroupItem } from "@executor-js/react/components/radio-group";
4647 import { IOSSpinner, Spinner } from "@executor-js/react/components/spinner";
47−import { addGoogleDiscoverySource, probeGoogleDiscovery } from "./atoms";
48+import { addGoogleDiscoverySourceOptimistic, probeGoogleDiscovery } from "./atoms";
4849 import { GOOGLE_DISCOVERY_OAUTH_POPUP_NAME, googleDiscoveryOAuthStrategy } from "./oauth";
4950 import { googleDiscoveryPresets, type GoogleDiscoveryPreset } from "../sdk/presets";
5051
@@ -203,8 +204,9 @@ export default function AddGoogleDiscoverySource(props: { · 152 unmodified lines
203204
204205 const scopeId = useScope();
205206 const doProbe = useAtomSet(probeGoogleDiscovery, { mode: "promise" });
206− const doAdd = useAtomSet(addGoogleDiscoverySource, { mode: "promise" });
207− const { beginAdd } = usePendingSources();
207+ const doAdd = useAtomSet(addGoogleDiscoverySourceOptimistic(scopeId), {
208+ mode: "promiseExit",
209+ });
208210 const secretList = useSecretPickerSecrets();
209211 const oauth = useOAuthPopupFlow({
210212 popupName: GOOGLE_DISCOVERY_OAUTH_POPUP_NAME,
@@ -326,38 +328,36 @@ export default function AddGoogleDiscoverySource(props: { · 115 unmodified lines
326328 setError(null);
327329 const displayName = identity.name.trim() || probe.name;
328330 const namespace = resolvedNamespace;
329− const placeholder = beginAdd({
330− id: namespace,
331− name: displayName,
332− kind: "google-discovery",
331+ const exit = await doAdd({
332+ params: { scopeId },
333+ payload: {
334+ name: displayName,
335+ discoveryUrl: discoveryUrl.trim(),
336+ namespace,
337+ auth:
338+ authKind === "oauth2" && oauthAuth
339+ ? {
340+ kind: "oauth2" as const,
341+ connectionId: oauthAuth.connectionId,
342+ clientIdSecretId: oauthAuth.clientIdSecretId,
343+ clientSecretSecretId: oauthAuth.clientSecretSecretId,
344+ scopes: oauthAuth.scopes,
345+ }
346+ : { kind: "none" as const },
347+ },
348+ reactivityKeys: [...sourceWriteKeys],
333349 });
334− try {
335− await doAdd({
336− params: { scopeId },
337− payload: {
338− name: displayName,
339− discoveryUrl: discoveryUrl.trim(),
340− namespace,
341− auth:
342− authKind === "oauth2" && oauthAuth
343− ? {
344− kind: "oauth2" as const,
345− connectionId: oauthAuth.connectionId,
346− clientIdSecretId: oauthAuth.clientIdSecretId,
347− clientSecretSecretId: oauthAuth.clientSecretSecretId,
348− scopes: oauthAuth.scopes,
349− }
350− : { kind: "none" as const },
351− },
352− reactivityKeys: [...sourceWriteKeys],
353− });
354− props.onComplete();
355− } catch (e) {
356− setError(e instanceof Error ? e.message : "Failed to add source");
350+ if (Exit.isFailure(exit)) {
351+ const error = Exit.findErrorOption(exit);
352+ setError(
353+ Option.isSome(error) && error.value instanceof Error
354+ ? error.value.message
355+ : "Failed to add source",
356+ );
357357 setAdding(false);
358− } finally {
359− placeholder.done();
358+ return;
360359 }
360+ props.onComplete();
361361 }, [
362362 probe,
363363 doAdd,
@@ -367,7 +367,6 @@ export default function AddGoogleDiscoverySource(props: { · 3 unmodified lines
367367 oauthAuth,
368368 props,
369369 scopeId,
370− beginAdd,
371370 resolvedNamespace,
372371 ]);
373372
packages/plugins/google-discovery/src/react/atoms.ts+29−0
@@ -1,4 +1,7 @@
11 import type { ScopeId } from "@executor-js/sdk/core";
2+import * as Atom from "effect/unstable/reactivity/Atom";
3+import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
4+import { sourcesOptimisticAtom } from "@executor-js/react/api/atoms";
25 import { ReactivityKey } from "@executor-js/react/api/reactivity-keys";
36 import { GoogleDiscoveryClient } from "./client";
47
@@ -25,6 +28,32 @@ export const addGoogleDiscoverySource = GoogleDiscoveryClient.mutation( · 20 unmodified lines
2528 "googleDiscovery",
2629 "addSource",
2730 );
31+export const addGoogleDiscoverySourceOptimistic = Atom.family((scopeId: ScopeId) =>
32+ sourcesOptimisticAtom(scopeId).pipe(
33+ Atom.optimisticFn({
34+ reducer: (current, arg) =>
35+ AsyncResult.map(current, (rows) => {
36+ const id = arg.payload.namespace ?? `pending-${Math.random().toString(36).slice(2)}`;
37+ const source = {
38+ id,
39+ scopeId,
40+ kind: "googleDiscovery",
41+ pluginId: "google-discovery",
42+ name: arg.payload.name,
43+ url: arg.payload.discoveryUrl,
44+ canRemove: false,
45+ canRefresh: false,
46+ canEdit: false,
47+ runtime: false,
48+ };
49+ return [source, ...rows.filter((row) => row.id !== id)].sort((a, b) =>
50+ a.name.localeCompare(b.name),
51+ );
52+ }),
53+ fn: addGoogleDiscoverySource,
54+ }),
55+ ),
56+);
2857 export const updateGoogleDiscoverySource = GoogleDiscoveryClient.mutation(
2958 "googleDiscovery",
3059 "updateSource",
packages/plugins/graphql/src/react/AddGraphqlSource.tsx+33−36
@@ -1,9 +1,10 @@
11 import { useCallback, useState } from "react";
22 import { useAtomSet } from "@effect/atom-react";
3+import * as Exit from "effect/Exit";
4+import * as Option from "effect/Option";
35
46 import { useScope } from "@executor-js/react/api/scope-context";
57 import { sourceWriteKeys } from "@executor-js/react/api/reactivity-keys";
6−import { usePendingSources } from "@executor-js/react/api/optimistic";
78 import {
89 HttpCredentialsEditor,
910 httpCredentialsValid,
@@ -33,7 +34,7 @@ import { · 23 unmodified lines
3334 import { FloatActions } from "@executor-js/react/components/float-actions";
3435 import { Input } from "@executor-js/react/components/input";
3536 import { Spinner } from "@executor-js/react/components/spinner";
36−import { addGraphqlSource } from "./atoms";
37+import { addGraphqlSourceOptimistic } from "./atoms";
3738 import { initialGraphqlCredentials } from "./defaults";
3839 import type { HeaderValue } from "../sdk/types";
3940
@@ -55,8 +56,7 @@ export default function AddGraphqlSource(props: { · 15 unmodified lines
5556 const [tokens, setTokens] = useState<OAuthCompletionPayload | null>(null);
5657
5758 const scopeId = useScope();
58− const doAdd = useAtomSet(addGraphqlSource, { mode: "promise" });
59− const { beginAdd } = usePendingSources();
59+ const doAdd = useAtomSet(addGraphqlSourceOptimistic(scopeId), { mode: "promiseExit" });
6060 const secretList = useSecretPickerSecrets();
6161 const oauth = useOAuthPopupFlow({
6262 popupName: "graphql-oauth",
@@ -112,41 +112,38 @@ export default function AddGraphqlSource(props: { · 49 unmodified lines
112112 const { headers: headerMap, queryParams } = serializeHttpCredentials(credentials);
113113
114114 const { trimmedEndpoint, namespace, displayName } = sourceIdentity();
115− const placeholder = beginAdd({
116− id: namespace,
117− name: displayName,
118− kind: "graphql",
119− url: trimmedEndpoint || undefined,
115+ const exit = await doAdd({
116+ params: { scopeId },
117+ payload: {
118+ endpoint: trimmedEndpoint,
119+ name: displayName,
120+ namespace,
121+ ...(Object.keys(headerMap).length > 0 ? { headers: headerMap } : {}),
122+ ...(Object.keys(queryParams).length > 0
123+ ? { queryParams: queryParams as Record<string, HeaderValue> }
124+ : {}),
125+ ...(authMode === "oauth2" && tokens
126+ ? {
127+ auth: {
128+ kind: "oauth2" as const,
129+ connectionId: tokens.connectionId,
130+ },
131+ }
132+ : {}),
133+ },
134+ reactivityKeys: sourceWriteKeys,
120135 });
121− try {
122− await doAdd({
123− params: { scopeId },
124− payload: {
125− endpoint: trimmedEndpoint,
126− name: identity.name.trim() || undefined,
127− namespace: slugifyNamespace(identity.namespace) || undefined,
128− ...(Object.keys(headerMap).length > 0 ? { headers: headerMap } : {}),
129− ...(Object.keys(queryParams).length > 0
130− ? { queryParams: queryParams as Record<string, HeaderValue> }
131− : {}),
132− ...(authMode === "oauth2" && tokens
133− ? {
134− auth: {
135− kind: "oauth2" as const,
136− connectionId: tokens.connectionId,
137− },
138− }
139− : {}),
140− },
141− reactivityKeys: sourceWriteKeys,
142− });
143− props.onComplete();
144− } catch (e) {
145− setAddError(e instanceof Error ? e.message : "Failed to add source");
136+ if (Exit.isFailure(exit)) {
137+ const error = Exit.findErrorOption(exit);
138+ setAddError(
139+ Option.isSome(error) && error.value instanceof Error
140+ ? error.value.message
141+ : "Failed to add source",
142+ );
146143 setAdding(false);
147− } finally {
148− placeholder.done();
144+ return;
149145 }
146+ props.onComplete();
150147 };
151148
152149 return (
packages/plugins/graphql/src/react/atoms.ts+30−0
@@ -1,4 +1,7 @@
11 import type { ScopeId } from "@executor-js/sdk/core";
2+import * as Atom from "effect/unstable/reactivity/Atom";
3+import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
4+import { sourcesOptimisticAtom } from "@executor-js/react/api/atoms";
25 import { ReactivityKey } from "@executor-js/react/api/reactivity-keys";
36 import { GraphqlClient } from "./client";
47
@@ -19,4 +22,31 @@ export const graphqlSourceAtom = (scopeId: ScopeId, namespace: string) => · 14 unmodified lines
1922
2023 export const addGraphqlSource = GraphqlClient.mutation("graphql", "addSource");
2124
25+export const addGraphqlSourceOptimistic = Atom.family((scopeId: ScopeId) =>
26+ sourcesOptimisticAtom(scopeId).pipe(
27+ Atom.optimisticFn({
28+ reducer: (current, arg) =>
29+ AsyncResult.map(current, (rows) => {
30+ const id = arg.payload.namespace ?? `pending-${Math.random().toString(36).slice(2)}`;
31+ const source = {
32+ id,
33+ scopeId,
34+ kind: "graphql",
35+ pluginId: "graphql",
36+ name: arg.payload.name ?? id,
37+ url: arg.payload.endpoint,
38+ canRemove: false,
39+ canRefresh: false,
40+ canEdit: false,
41+ runtime: false,
42+ };
43+ return [source, ...rows.filter((row) => row.id !== id)].sort((a, b) =>
44+ a.name.localeCompare(b.name),
45+ );
46+ }),
47+ fn: addGraphqlSource,
48+ }),
49+ ),
50+);
51+
2252 export const updateGraphqlSource = GraphqlClient.mutation("graphql", "updateSource");
packages/plugins/mcp/src/react/AddMcpSource.tsx+47−58
@@ -1,5 +1,7 @@
11 import { useReducer, useCallback, useEffect, useRef, useState, type ReactNode } from "react";
22 import { useAtomSet } from "@effect/atom-react";
3+import * as Exit from "effect/Exit";
4+import * as Option from "effect/Option";
35
46 import { useScope } from "@executor-js/react/api/scope-context";
57 import { Button } from "@executor-js/react/components/button";
@@ -49,8 +51,7 @@ import { · 43 unmodified lines
4951
5052 type RemoteAuthMode = "none" | "header" | "oauth2";
5153 import { sourceWriteKeys } from "@executor-js/react/api/reactivity-keys";
52−import { usePendingSources } from "@executor-js/react/api/optimistic";
53−import { probeMcpEndpoint, addMcpSource } from "./atoms";
54+import { probeMcpEndpoint, addMcpSourceOptimistic } from "./atoms";
5455 import { mcpPresets, type McpPreset } from "../sdk/presets";
5556
5657 // ---------------------------------------------------------------------------
@@ -269,8 +270,7 @@ export default function AddMcpSource(props: { · 212 unmodified lines
269270
270271 const scopeId = useScope();
271272 const doProbe = useAtomSet(probeMcpEndpoint, { mode: "promise" });
272− const doAdd = useAtomSet(addMcpSource, { mode: "promise" });
273− const { beginAdd } = usePendingSources();
273+ const doAdd = useAtomSet(addMcpSourceOptimistic(scopeId), { mode: "promiseExit" });
274274 const secretList = useSecretPickerSecrets();
275275 const oauth = useOAuthPopupFlow<OAuthCompletionPayload>({
276276 popupName: "mcp-oauth",
@@ -466,40 +466,33 @@ export default function AddMcpSource(props: { · 189 unmodified lines
466466 };
467467 const displayName = remoteIdentity.name.trim() || probe.serverName || probe.name;
468468 const slugNamespace = slugifyNamespace(remoteIdentity.namespace);
469− const placeholderId = slugNamespace || `pending:${crypto.randomUUID()}`;
470− const placeholder = beginAdd({
471− id: placeholderId,
472− name: displayName,
473− kind: "mcp",
474− url: state.url.trim(),
469+ const exit = await doAdd({
470+ params: { scopeId },
471+ payload: {
472+ transport: "remote" as const,
473+ name: displayName,
474+ namespace: slugNamespace || undefined,
475+ endpoint: state.url.trim(),
476+ auth,
477+ ...(Object.keys(remoteRequestHeaders).length > 0 ? { headers: remoteRequestHeaders } : {}),
478+ ...(Object.keys(credentials.queryParams).length > 0
479+ ? { queryParams: credentials.queryParams }
480+ : {}),
481+ },
482+ reactivityKeys: sourceWriteKeys,
475483 });
476− try {
477− await doAdd({
478− params: { scopeId },
479− payload: {
480− transport: "remote" as const,
481− name: displayName,
482− namespace: slugNamespace || undefined,
483− endpoint: state.url.trim(),
484− auth,
485− ...(Object.keys(remoteRequestHeaders).length > 0
486− ? { headers: remoteRequestHeaders }
487− : {}),
488− ...(Object.keys(credentials.queryParams).length > 0
489− ? { queryParams: credentials.queryParams }
490− : {}),
491− },
492− reactivityKeys: sourceWriteKeys,
493− });
494− props.onComplete();
495− } catch (e) {
484+ if (Exit.isFailure(exit)) {
485+ const error = Exit.findErrorOption(exit);
496486 dispatch({
497487 type: "add-fail",
498− error: e instanceof Error ? e.message : "Failed to add source",
488+ error:
489+ Option.isSome(error) && error.value instanceof Error
490+ ? error.value.message
491+ : "Failed to add source",
499492 });
500− } finally {
501− placeholder.done();
493+ return;
502494 }
495+ props.onComplete();
503496 }, [
504497 probe,
505498 remoteAuthMode,
@@ -512,7 +505,6 @@ export default function AddMcpSource(props: { · 6 unmodified lines
512505 doAdd,
513506 props,
514507 scopeId,
515− beginAdd,
516508 ]);
517509
518510 // ---- Stdio actions ----
@@ -547,33 +539,30 @@ export default function AddMcpSource(props: { · 28 unmodified lines
547539 setStdioError(null);
548540 const displayName = stdioIdentity.name.trim() || cmd;
549541 const slugNamespace = slugifyNamespace(stdioIdentity.namespace);
550− const placeholderId = slugNamespace || `pending:${crypto.randomUUID()}`;
551− const placeholder = beginAdd({
552− id: placeholderId,
553− name: displayName,
554− kind: "mcp",
542+ const exit = await doAdd({
543+ params: { scopeId },
544+ payload: {
545+ transport: "stdio" as const,
546+ name: displayName,
547+ namespace: slugNamespace || undefined,
548+ command: cmd,
549+ args: parseStdioArgs(stdioArgs),
550+ env: parseStdioEnv(stdioEnv),
551+ },
552+ reactivityKeys: sourceWriteKeys,
555553 });
556− try {
557− await doAdd({
558− params: { scopeId },
559− payload: {
560− transport: "stdio" as const,
561− name: displayName,
562− namespace: slugNamespace || undefined,
563− command: cmd,
564− args: parseStdioArgs(stdioArgs),
565− env: parseStdioEnv(stdioEnv),
566− },
567− reactivityKeys: sourceWriteKeys,
568− });
569− props.onComplete();
570− } catch (e) {
571− setStdioError(e instanceof Error ? e.message : "Failed to add source");
554+ if (Exit.isFailure(exit)) {
555+ const error = Exit.findErrorOption(exit);
556+ setStdioError(
557+ Option.isSome(error) && error.value instanceof Error
558+ ? error.value.message
559+ : "Failed to add source",
560+ );
572561 setStdioAdding(false);
573− } finally {
574− placeholder.done();
562+ return;
575563 }
576− }, [stdioCommand, stdioArgs, stdioEnv, stdioIdentity, doAdd, scopeId, props, beginAdd]);
564+ props.onComplete();
565+ }, [stdioCommand, stdioArgs, stdioEnv, stdioIdentity, doAdd, scopeId, props]);
577566
578567 // ---- Render ----
579568
packages/plugins/mcp/src/react/atoms.ts+29−0
@@ -1,4 +1,7 @@
11 import type { ScopeId } from "@executor-js/sdk/core";
2+import * as Atom from "effect/unstable/reactivity/Atom";
3+import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
4+import { sourcesOptimisticAtom } from "@executor-js/react/api/atoms";
25 import { ReactivityKey } from "@executor-js/react/api/reactivity-keys";
36 import { McpClient } from "./client";
47
@@ -19,6 +22,32 @@ export const mcpSourceAtom = (scopeId: ScopeId, namespace: string) => · 14 unmodified lines
1922
2023 export const probeMcpEndpoint = McpClient.mutation("mcp", "probeEndpoint");
2124 export const addMcpSource = McpClient.mutation("mcp", "addSource");
25+export const addMcpSourceOptimistic = Atom.family((scopeId: ScopeId) =>
26+ sourcesOptimisticAtom(scopeId).pipe(
27+ Atom.optimisticFn({
28+ reducer: (current, arg) =>
29+ AsyncResult.map(current, (rows) => {
30+ const id = arg.payload.namespace ?? `pending-${Math.random().toString(36).slice(2)}`;
31+ const source = {
32+ id,
33+ scopeId,
34+ kind: "mcp",
35+ pluginId: "mcp",
36+ name: arg.payload.name ?? id,
37+ ...(arg.payload.transport === "remote" ? { url: arg.payload.endpoint } : {}),
38+ canRemove: false,
39+ canRefresh: false,
40+ canEdit: false,
41+ runtime: false,
42+ };
43+ return [source, ...rows.filter((row) => row.id !== id)].sort((a, b) =>
44+ a.name.localeCompare(b.name),
45+ );
46+ }),
47+ fn: addMcpSource,
48+ }),
49+ ),
50+);
2251 export const removeMcpSource = McpClient.mutation("mcp", "removeSource");
2352 export const refreshMcpSource = McpClient.mutation("mcp", "refreshSource");
2453 export const updateMcpSource = McpClient.mutation("mcp", "updateSource");
packages/plugins/openapi/src/react/AddOpenApiSource.tsx+129−93
@@ -1,6 +1,7 @@
11 import { useCallback, useEffect, useRef, useState } from "react";
22 import { useAtomSet } from "@effect/atom-react";
3−import { Option } from "effect";
3+import * as Exit from "effect/Exit";
4+import * as Option from "effect/Option";
45
56 import { ConnectionId, ScopeId, SecretId } from "@executor-js/sdk/core";
67 import { startOAuth } from "@executor-js/react/api/atoms";
@@ -14,7 +15,6 @@ import { connectionWriteKeys, sourceWriteKeys } from "@executor-js/react/api/rea · 7 unmodified lines
1415 // state without a refresh.
1516 const addSpecWriteKeys = [...sourceWriteKeys, ...connectionWriteKeys] as const;
1617 const bindingWriteKeys = [...sourceWriteKeys, ...connectionWriteKeys] as const;
17−import { usePendingSources } from "@executor-js/react/api/optimistic";
1818 import { HeadersList } from "@executor-js/react/plugins/headers-list";
1919 import {
2020 HttpCredentialsEditor,
@@ -65,7 +65,7 @@ import { SourceFavicon } from "@executor-js/react/components/source-favicon"; · 44 unmodified lines
6565 import { RadioGroup, RadioGroupItem } from "@executor-js/react/components/radio-group";
6666 import { Skeleton } from "@executor-js/react/components/skeleton";
6767 import { IOSSpinner, Spinner } from "@executor-js/react/components/spinner";
68−import { addOpenApiSpec, previewOpenApiSpec, setOpenApiSourceBinding } from "./atoms";
68+import { addOpenApiSpecOptimistic, previewOpenApiSpec, setOpenApiSourceBinding } from "./atoms";
6969 import type { SpecPreview, HeaderPreset, OAuth2Preset } from "../sdk/preview";
7070 import {
7171 headerBindingSlot,
@@ -243,10 +243,9 @@ export default function AddOpenApiSource(props: { · 171 unmodified lines
243243 const scopeId = useScope();
244244 const userScope = useUserScope();
245245 const doPreview = useAtomSet(previewOpenApiSpec, { mode: "promise" });
246− const doAdd = useAtomSet(addOpenApiSpec, { mode: "promise" });
246+ const doAdd = useAtomSet(addOpenApiSpecOptimistic(scopeId), { mode: "promiseExit" });
247247 const doStartOAuth = useAtomSet(startOAuth, { mode: "promise" });
248− const doSetBinding = useAtomSet(setOpenApiSourceBinding, { mode: "promise" });
249− const { beginAdd } = usePendingSources();
248+ const doSetBinding = useAtomSet(setOpenApiSourceBinding, { mode: "promiseExit" });
250249 const secretList = useSecretPickerSecrets();
251250 const oauth = useOAuthPopupFlow<OAuthCompletionPayload>({
252251 popupName: OPENAPI_OAUTH_POPUP_NAME,
@@ -615,109 +614,146 @@ export default function AddOpenApiSource(props: { · 362 unmodified lines
615614 const displayName =
616615 identity.name.trim() ||
617616 (preview ? Option.getOrElse(preview.title, () => namespace) : namespace);
618− const placeholder = beginAdd({
619− id: namespace,
620− name: displayName,
621− kind: "openapi",
622− url: resolvedBaseUrl || undefined,
617+ const exit = await doAdd({
618+ params: { scopeId },
619+ payload: {
620+ spec: specUrl,
621+ specFetchCredentials: serializeHttpCredentials(specFetchCredentials),
622+ name: displayName,
623+ namespace,
624+ baseUrl: resolvedBaseUrl || undefined,
625+ ...(hasHeaders ? { headers: configuredHeaders } : {}),
626+ ...(Object.keys(serializeHttpCredentials(runtimeCredentials).queryParams).length > 0
627+ ? { queryParams: serializeHttpCredentials(runtimeCredentials).queryParams }
628+ : {}),
629+ ...(configuredOAuth2 ? { oauth2: configuredOAuth2 } : {}),
630+ },
631+ reactivityKeys: addSpecWriteKeys,
623632 });
624− try {
625− const result = await doAdd({
633+ if (Exit.isFailure(exit)) {
634+ const error = Exit.findErrorOption(exit);
635+ setAddError(
636+ Option.isSome(error) && error.value instanceof Error
637+ ? error.value.message
638+ : "Failed to add source",
639+ );
640+ setAdding(false);
641+ return;
642+ }
643+
644+ const sourceId = exit.value.namespace;
645+ const sourceScope = ScopeId.make(scopeId);
646+ const bindingScope = ScopeId.make(userScope);
647+
648+ for (const binding of headerBindings) {
649+ const bindingExit = await doSetBinding({
626650 params: { scopeId },
627651 payload: {
628− spec: specUrl,
629− specFetchCredentials: serializeHttpCredentials(specFetchCredentials),
630− name: identity.name.trim() || undefined,
631− namespace: slugifyNamespace(identity.namespace) || undefined,
632− baseUrl: resolvedBaseUrl || undefined,
633− ...(hasHeaders ? { headers: configuredHeaders } : {}),
634− ...(Object.keys(serializeHttpCredentials(runtimeCredentials).queryParams).length > 0
635− ? { queryParams: serializeHttpCredentials(runtimeCredentials).queryParams }
636− : {}),
637− ...(configuredOAuth2 ? { oauth2: configuredOAuth2 } : {}),
652+ sourceId,
653+ sourceScope,
654+ scope: bindingScope,
655+ slot: binding.slot,
656+ value: {
657+ kind: "secret",
658+ secretId: SecretId.make(binding.secretId),
659+ },
638660 },
639− reactivityKeys: addSpecWriteKeys,
661+ reactivityKeys: bindingWriteKeys,
640662 });
641−
642− const sourceId = result.namespace;
643− const sourceScope = ScopeId.make(scopeId);
644− const bindingScope = ScopeId.make(userScope);
645−
646− for (const binding of headerBindings) {
647− await doSetBinding({
648− params: { scopeId },
649− payload: {
650− sourceId,
651− sourceScope,
652− scope: bindingScope,
653− slot: binding.slot,
654− value: {
655− kind: "secret",
656− secretId: SecretId.make(binding.secretId),
657− },
658− },
659− reactivityKeys: bindingWriteKeys,
660− });
663+ if (Exit.isFailure(bindingExit)) {
664+ const error = Exit.findErrorOption(bindingExit);
665+ setAddError(
666+ Option.isSome(error) && error.value instanceof Error
667+ ? error.value.message
668+ : "Failed to add source",
669+ );
670+ setAdding(false);
671+ return;
661672 }
673+ }
662674
663− if (configuredOAuth2 && oauth2ClientIdSecretId) {
664− await doSetBinding({
665− params: { scopeId },
666− payload: {
667− sourceId,
668− sourceScope,
669− scope: bindingScope,
670− slot: configuredOAuth2.clientIdSlot,
671− value: {
672− kind: "secret",
673− secretId: SecretId.make(oauth2ClientIdSecretId),
674− },
675+ if (configuredOAuth2 && oauth2ClientIdSecretId) {
676+ const bindingExit = await doSetBinding({
677+ params: { scopeId },
678+ payload: {
679+ sourceId,
680+ sourceScope,
681+ scope: bindingScope,
682+ slot: configuredOAuth2.clientIdSlot,
683+ value: {
684+ kind: "secret",
685+ secretId: SecretId.make(oauth2ClientIdSecretId),
675686 },
676− reactivityKeys: bindingWriteKeys,
677− });
687+ },
688+ reactivityKeys: bindingWriteKeys,
689+ });
690+ if (Exit.isFailure(bindingExit)) {
691+ const error = Exit.findErrorOption(bindingExit);
692+ setAddError(
693+ Option.isSome(error) && error.value instanceof Error
694+ ? error.value.message
695+ : "Failed to add source",
696+ );
697+ setAdding(false);
698+ return;
678699 }
700+ }
679701
680− if (configuredOAuth2?.clientSecretSlot && oauth2ClientSecretSecretId) {
681− await doSetBinding({
682− params: { scopeId },
683− payload: {
684− sourceId,
685− sourceScope,
686− scope: bindingScope,
687− slot: configuredOAuth2.clientSecretSlot,
688− value: {
689− kind: "secret",
690− secretId: SecretId.make(oauth2ClientSecretSecretId),
691− },
702+ if (configuredOAuth2?.clientSecretSlot && oauth2ClientSecretSecretId) {
703+ const bindingExit = await doSetBinding({
704+ params: { scopeId },
705+ payload: {
706+ sourceId,
707+ sourceScope,
708+ scope: bindingScope,
709+ slot: configuredOAuth2.clientSecretSlot,
710+ value: {
711+ kind: "secret",
712+ secretId: SecretId.make(oauth2ClientSecretSecretId),
692713 },
693− reactivityKeys: bindingWriteKeys,
694− });
714+ },
715+ reactivityKeys: bindingWriteKeys,
716+ });
717+ if (Exit.isFailure(bindingExit)) {
718+ const error = Exit.findErrorOption(bindingExit);
719+ setAddError(
720+ Option.isSome(error) && error.value instanceof Error
721+ ? error.value.message
722+ : "Failed to add source",
723+ );
724+ setAdding(false);
725+ return;
695726 }
727+ }
696728
697− if (configuredOAuth2 && oauth2Auth) {
698− await doSetBinding({
699− params: { scopeId },
700− payload: {
701− sourceId,
702− sourceScope,
703− scope: bindingScope,
704− slot: configuredOAuth2.connectionSlot,
705− value: {
706− kind: "connection",
707− connectionId: ConnectionId.make(oauth2Auth.connectionId),
708− },
729+ if (configuredOAuth2 && oauth2Auth) {
730+ const bindingExit = await doSetBinding({
731+ params: { scopeId },
732+ payload: {
733+ sourceId,
734+ sourceScope,
735+ scope: bindingScope,
736+ slot: configuredOAuth2.connectionSlot,
737+ value: {
738+ kind: "connection",
739+ connectionId: ConnectionId.make(oauth2Auth.connectionId),
709740 },
710− reactivityKeys: bindingWriteKeys,
711− });
741+ },
742+ reactivityKeys: bindingWriteKeys,
743+ });
744+ if (Exit.isFailure(bindingExit)) {
745+ const error = Exit.findErrorOption(bindingExit);
746+ setAddError(
747+ Option.isSome(error) && error.value instanceof Error
748+ ? error.value.message
749+ : "Failed to add source",
750+ );
751+ setAdding(false);
752+ return;
712753 }
713−
714− props.onComplete();
715− } catch (e) {
716− setAddError(e instanceof Error ? e.message : "Failed to add source");
717− setAdding(false);
718− } finally {
719− placeholder.done();
720754 }
755+
756+ props.onComplete();
721757 };
722758
723759 // ---- Render ----
packages/plugins/openapi/src/react/atoms.ts+30−0
@@ -1,4 +1,7 @@
11 import type { ScopeId } from "@executor-js/sdk/core";
2+import * as Atom from "effect/unstable/reactivity/Atom";
3+import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
4+import { sourcesOptimisticAtom } from "@executor-js/react/api/atoms";
25 import { ReactivityKey } from "@executor-js/react/api/reactivity-keys";
36 import { OpenApiClient } from "./client";
47
@@ -32,6 +35,33 @@ export const previewOpenApiSpec = OpenApiClient.mutation("openapi", "previewSpec · 27 unmodified lines
3235
3336 export const addOpenApiSpec = OpenApiClient.mutation("openapi", "addSpec");
3437
38+export const addOpenApiSpecOptimistic = Atom.family((scopeId: ScopeId) =>
39+ sourcesOptimisticAtom(scopeId).pipe(
40+ Atom.optimisticFn({
41+ reducer: (current, arg) =>
42+ AsyncResult.map(current, (rows) => {
43+ const id = arg.payload.namespace ?? `pending-${Math.random().toString(36).slice(2)}`;
44+ const source = {
45+ id,
46+ scopeId,
47+ kind: "openapi",
48+ pluginId: "openapi",
49+ name: arg.payload.name ?? id,
50+ ...(arg.payload.baseUrl ? { url: arg.payload.baseUrl } : {}),
51+ canRemove: false,
52+ canRefresh: false,
53+ canEdit: false,
54+ runtime: false,
55+ };
56+ return [source, ...rows.filter((row) => row.id !== id)].sort((a, b) =>
57+ a.name.localeCompare(b.name),
58+ );
59+ }),
60+ fn: addOpenApiSpec,
61+ }),
62+ ),
63+);
64+
3565 export const updateOpenApiSource = OpenApiClient.mutation("openapi", "updateSource");
3666
3767 export const setOpenApiSourceBinding = OpenApiClient.mutation("openapi", "setSourceBinding");
packages/react/src/api/atoms.tsx+47−15
@@ -55,7 +55,10 @@ export const sourcesAtom = (scopeId: ScopeId) => · 54 unmodified lines
5555
5656 /** Single source by id — derived from the sources list */
5757 export const sourceAtom = (sourceId: string, scopeId: ScopeId) =>
58− Atom.mapResult(sourcesAtom(scopeId), (sources) => sources.find((s) => s.id === sourceId) ?? null);
58+ Atom.mapResult(
59+ sourcesOptimisticAtom(scopeId),
60+ (sources) => sources.find((s) => s.id === sourceId) ?? null,
61+ );
5962
6063 export const secretsAtom = (scopeId: ScopeId) =>
6164 ExecutorApiClient.query("secrets", "list", {
@@ -85,25 +88,14 @@ export const secretUsagesAtom = (scopeId: ScopeId, secretId: SecretId) => · 23 unmodified lines
8588 // Refresh whenever any source / connection / secret changes — adding
8689 // an oauth source pulls in a new connection-secret link and we want
8790 // the usage list to reflect it.
88− reactivityKeys: [
89− ReactivityKey.secrets,
90− ReactivityKey.sources,
91− ReactivityKey.connections,
92− ],
91+ reactivityKeys: [ReactivityKey.secrets, ReactivityKey.sources, ReactivityKey.connections],
9392 });
9493
95−export const connectionUsagesAtom = (
96− scopeId: ScopeId,
97− connectionId: ConnectionId,
98−) =>
94+export const connectionUsagesAtom = (scopeId: ScopeId, connectionId: ConnectionId) =>
9995 ExecutorApiClient.query("connections", "usages", {
10096 params: { scopeId, connectionId },
10197 timeToLive: "30 seconds",
102− reactivityKeys: [
103− ReactivityKey.connections,
104− ReactivityKey.sources,
105− ReactivityKey.secrets,
106− ],
98+ reactivityKeys: [ReactivityKey.connections, ReactivityKey.sources, ReactivityKey.secrets],
10799 });
108100
109101 export const policiesAtom = (scopeId: ScopeId) =>
@@ -153,6 +145,46 @@ export const updatePolicy = ExecutorApiClient.mutation("policies", "update"); · 43 unmodified lines
153145
154146 export const removePolicy = ExecutorApiClient.mutation("policies", "remove");
155147
148+// ---------------------------------------------------------------------------
149+// Sources — optimistic surface.
150+// ---------------------------------------------------------------------------
151+
152+export const sourcesOptimisticAtom = Atom.family((scopeId: ScopeId) =>
153+ Atom.optimistic(sourcesAtom(scopeId)),
154+);
155+
156+export const removeSourceOptimistic = Atom.family((scopeId: ScopeId) =>
157+ sourcesOptimisticAtom(scopeId).pipe(
158+ Atom.optimisticFn({
159+ reducer: (current, arg) =>
160+ AsyncResult.map(current, (rows) =>
161+ rows.filter((source) => source.id !== arg.params.sourceId),
162+ ),
163+ fn: removeSource,
164+ }),
165+ ),
166+);
167+
168+// ---------------------------------------------------------------------------
169+// Connections — optimistic removals.
170+// ---------------------------------------------------------------------------
171+
172+export const connectionsOptimisticAtom = Atom.family((scopeId: ScopeId) =>
173+ Atom.optimistic(connectionsAtom(scopeId)),
174+);
175+
176+export const removeConnectionOptimistic = Atom.family((scopeId: ScopeId) =>
177+ connectionsOptimisticAtom(scopeId).pipe(
178+ Atom.optimisticFn({
179+ reducer: (current, arg) =>
180+ AsyncResult.map(current, (rows) =>
181+ rows.filter((connection) => connection.id !== arg.params.connectionId),
182+ ),
183+ fn: removeConnection,
184+ }),
185+ ),
186+);
187+
156188 // ---------------------------------------------------------------------------
157189 // Secrets — optimistic removals.
158190 // ---------------------------------------------------------------------------
packages/react/src/api/optimistic.tsx+0−213
@@ -1,213 +0,0 @@
1−import * as React from "react";
2−import { useAtomSet, useAtomValue } from "@effect/atom-react";
3−import * as Atom from "effect/unstable/reactivity/Atom";
4−import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
5−import type { ScopeId } from "@executor-js/sdk";
6−
7−import { connectionsAtom, sourcesAtom } from "./atoms";
8−
9−/**
10− * Client-only optimistic-update layer.
11− *
12− * Mutations that add a row return only after the server roundtrip. The
13− * `pendingResourceAtom` family lets a UI insert a placeholder *before* the
14− * mutation resolves so the sidebar/list updates instantly. Once the server
15− * returns and reactivity refetches the canonical list, callers should remove
16− * the placeholder (the dedupe in `mergePending` filters it anyway, but
17− * explicit removal keeps the pending set bounded on errors).
18− *
19− * Resource keys (`"sources"`, `"secrets"`, …) match the strings in
20− * `ReactivityKey` but are intentionally not coupled — pending state is purely
21− * client-side.
22− */
23−
24−export const PendingResource = {
25− sources: "sources",
26− connectionRemovals: "connection-removals",
27−} as const;
28−
29−export interface PendingEntry<T> {
30− readonly id: string;
31− readonly value: T;
32−}
33−
34−const pendingFamily = Atom.family((_resource: string) =>
35− Atom.make<ReadonlyArray<PendingEntry<unknown>>>([]),
36−);
37−
38−const atomFor = <T,>(resource: string) =>
39− pendingFamily(resource) as ReturnType<typeof pendingFamily> & {
40− readonly __t?: T;
41− };
42−
43−export const usePendingResource = <T,>(resource: string) => {
44− const atom = atomFor<T>(resource);
45− const pending = useAtomValue(atom) as ReadonlyArray<PendingEntry<T>>;
46− const setPending = useAtomSet(atom);
47−
48− const add = React.useCallback(
49− (entry: PendingEntry<T>) =>
50− setPending((prev) => [
51− ...(prev as ReadonlyArray<PendingEntry<T>>).filter((p) => p.id !== entry.id),
52− entry,
53− ]),
54− [setPending],
55− );
56−
57− const remove = React.useCallback(
58− (id: string) =>
59− setPending((prev) => (prev as ReadonlyArray<PendingEntry<T>>).filter((p) => p.id !== id)),
60− [setPending],
61− );
62−
63− const clear = React.useCallback(() => setPending([]), [setPending]);
64−
65− return { pending, add, remove, clear };
66−};
67−
68−/**
69− * Merges pending entries with a server-loaded list. Pending entries whose id
70− * already exists on the server are dropped so we never double-render a row
71− * once the canonical version arrives.
72− */
73−export const mergePending = <T, R>(
74− pending: ReadonlyArray<PendingEntry<T>>,
75− server: ReadonlyArray<R>,
76− serverId: (row: R) => string,
77− fromPending: (entry: PendingEntry<T>) => R,
78−): ReadonlyArray<R> => {
79− if (pending.length === 0) return server;
80− const seen = new Set(server.map(serverId));
81− const extras = pending.filter((p) => !seen.has(p.id)).map(fromPending);
82− if (extras.length === 0) return server;
83− return [...extras, ...server];
84−};
85−
86−// ---------------------------------------------------------------------------
87−// Sources — convenience wrappers used by sidebar/list views and add forms.
88−// Pending entries are global (not per-scope) because the user only sees one
89−// scope at a time; this keeps the add-form code free of scope plumbing.
90−// ---------------------------------------------------------------------------
91−
92−export interface PendingSource {
93− readonly name: string;
94− readonly kind: string;
95− readonly url?: string;
96−}
97−
98−/**
99− * Sidebar/list helper. Reads `sourcesAtom(scopeId)` and merges any pending
100− * placeholder rows in, sorting the combined list by name so the placeholder
101− * lands in the same position the canonical row will occupy — no visual jump
102− * when the server confirms.
103− */
104−export const useSourcesWithPending = (scopeId: ScopeId) => {
105− const result = useAtomValue(sourcesAtom(scopeId));
106− const { pending } = usePendingResource<PendingSource>(PendingResource.sources);
107− return React.useMemo(
108− () =>
109− AsyncResult.map(
110− result,
111− (
112− sources: ReadonlyArray<{
113− readonly id: string;
114− readonly name: string;
115− readonly kind: string;
116− readonly url?: string;
117− }>,
118− ) => {
119− const merged = mergePending(
120− pending,
121− sources,
122− (s: { readonly id: string }) => s.id,
123− (p) => ({
124− id: p.id,
125− name: p.value.name,
126− kind: p.value.kind,
127− url: p.value.url,
128− // The placeholder cannot be removed/refreshed/edited until the
129− // server confirms it, so disable those affordances.
130− canRemove: false,
131− canRefresh: false,
132− canEdit: false,
133− }),
134− );
135− return [...merged].sort((a, b) => a.name.localeCompare(b.name));
136− },
137− ),
138− [result, pending],
139− );
140−};
141−
142−/**
143− * Hook for an add form. Returns helpers to push and clear a pending source
144− * placeholder. On submit:
145− * const placeholder = beginAdd({ id: namespace, name, kind });
146− * try { await doAdd(...); } finally { placeholder.done(); }
147− */
148−export const usePendingSources = () => {
149− const { add, remove } = usePendingResource<PendingSource>(PendingResource.sources);
150− return React.useMemo(
151− () => ({
152− beginAdd: (entry: { id: string } & PendingSource) => {
153− add({ id: entry.id, value: { name: entry.name, kind: entry.kind, url: entry.url } });
154− return { done: () => remove(entry.id) };
155− },
156− }),
157− [add, remove],
158− );
159−};
160−
161−// ---------------------------------------------------------------------------
162−// Connections — optimistic removals.
163−// ---------------------------------------------------------------------------
164−
165−interface PendingConnectionRemoval {
166− readonly id: string;
167−}
168−
169−export const useConnectionsWithPendingRemovals = (scopeId: ScopeId) => {
170− const result = useAtomValue(connectionsAtom(scopeId));
171− const { pending, remove } = usePendingResource<PendingConnectionRemoval>(
172− PendingResource.connectionRemovals,
173− );
174−
175− React.useEffect(() => {
176− if (!AsyncResult.isSuccess(result) || pending.length === 0) return;
177−
178− const serverIds = new Set(
179− result.value.map((connection: { readonly id: string }) => connection.id as string),
180− );
181− for (const entry of pending) {
182− if (!serverIds.has(entry.id)) remove(entry.id);
183− }
184− }, [result, pending, remove]);
185−
186− return React.useMemo(
187− () =>
188− AsyncResult.map(result, (connections) => {
189− if (pending.length === 0) return connections;
190− const hiddenIds = new Set(pending.map((entry) => entry.id));
191− return connections.filter(
192− (connection: { readonly id: string }) => !hiddenIds.has(connection.id as string),
193− );
194− }),
195− [result, pending],
196− );
197−};
198−
199−export const usePendingConnectionRemovals = () => {
200− const { add, remove } = usePendingResource<PendingConnectionRemoval>(
201− PendingResource.connectionRemovals,
202− );
203−
204− return React.useMemo(
205− () => ({
206− beginRemove: (id: string) => {
207− add({ id, value: { id } });
208− return { undo: () => remove(id) };
209− },
210− }),
211− [add, remove],
212− );
213−};
packages/react/src/components/command-palette.tsx+2−2
@@ -4,7 +4,7 @@ import { useAtomValue } from "@effect/atom-react"; · 3 unmodified lines
44 import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
55 import { PlusIcon } from "lucide-react";
66 import { SourceFavicon } from "./source-favicon";
7−import { sourcesAtom } from "../api/atoms";
7+import { sourcesOptimisticAtom } from "../api/atoms";
88 import { useScope } from "../hooks/use-scope";
99 import { useSourcePlugins } from "@executor-js/sdk/client";
1010 import {
@@ -32,7 +32,7 @@ export function CommandPalette() { · 21 unmodified lines
3232 const [open, setOpen] = useState(false);
3333 const navigate = useNavigate();
3434 const scopeId = useScope();
35− const sourcesResult = useAtomValue(sourcesAtom(scopeId));
35+ const sourcesResult = useAtomValue(sourcesOptimisticAtom(scopeId));
3636
3737 // Toggle with ⌘K / Ctrl+K
3838 useEffect(() => {
packages/react/src/pages/connections.tsx+9−14
@@ -6,8 +6,11 @@ import * as Option from "effect/Option"; · 5 unmodified lines
66 import { ConnectionId, ConnectionInUseError, type ScopeId } from "@executor-js/sdk";
77 import { toast } from "sonner";
88
9−import { connectionUsagesAtom, removeConnection } from "../api/atoms";
10−import { useConnectionsWithPendingRemovals, usePendingConnectionRemovals } from "../api/optimistic";
9+import {
10+ connectionUsagesAtom,
11+ connectionsOptimisticAtom,
12+ removeConnectionOptimistic,
13+} from "../api/atoms";
1114 import { connectionWriteKeys } from "../api/reactivity-keys";
1215 import { useScope, useScopeStack } from "../hooks/use-scope";
1316 import { Badge } from "../components/badge";
@@ -59,13 +62,8 @@ const connectionScopeLabel = ( · 45 unmodified lines
5962 // don't get a stray "Used by 0" line before any source binds to them.
6063 // ---------------------------------------------------------------------------
6164
62−function ConnectionUsageFooter(props: {
63− scopeId: ScopeId;
64− connectionId: ConnectionId;
65−}) {
66− const usages = useAtomValue(
67− connectionUsagesAtom(props.scopeId, props.connectionId),
68− );
65+function ConnectionUsageFooter(props: { scopeId: ScopeId; connectionId: ConnectionId }) {
66+ const usages = useAtomValue(connectionUsagesAtom(props.scopeId, props.connectionId));
6967 return AsyncResult.match(usages, {
7068 onInitial: () => null,
7169 onFailure: () => null,
@@ -161,18 +159,15 @@ function ConnectionRow(props: { · 89 unmodified lines
161159 export function ConnectionsPage() {
162160 const scopeId = useScope();
163161 const scopeStack = useScopeStack();
164− const connections = useConnectionsWithPendingRemovals(scopeId);
165− const { beginRemove } = usePendingConnectionRemovals();
166− const doRemove = useAtomSet(removeConnection, { mode: "promiseExit" });
162+ const connections = useAtomValue(connectionsOptimisticAtom(scopeId));
163+ const doRemove = useAtomSet(removeConnectionOptimistic(scopeId), { mode: "promiseExit" });
167164
168165 const handleRemove = async (connectionId: string) => {
169− const pending = beginRemove(connectionId);
170166 const exit = await doRemove({
171167 params: { scopeId, connectionId: ConnectionId.make(connectionId) },
172168 reactivityKeys: connectionWriteKeys,
173169 });
174170 if (Exit.isFailure(exit)) {
175− pending.undo();
176171 const error = Exit.findErrorOption(exit);
177172 if (Option.isSome(error) && error.value instanceof ConnectionInUseError) {
178173 const count = error.value.usageCount;
packages/react/src/pages/source-detail.tsx+4−4
@@ -6,9 +6,9 @@ import { effectivePolicyFromSorted } from "@executor-js/sdk"; · 5 unmodified lines
66 import {
77 policiesOptimisticAtom,
88 sourceToolsAtom,
9− sourcesAtom,
9+ sourcesOptimisticAtom,
1010 sourceAtom,
11− removeSource,
11+ removeSourceOptimistic,
1212 refreshSource,
1313 } from "../api/atoms";
1414 import { sourceWriteKeys } from "../api/reactivity-keys";
@@ -29,9 +29,9 @@ export function SourceDetailPage(props: { namespace: string }) { · 14 unmodified lines
2929 const source = useAtomValue(sourceAtom(namespace, scopeId));
3030 const tools = useAtomValue(sourceToolsAtom(namespace, scopeId));
3131 const policies = useAtomValue(policiesOptimisticAtom(scopeId));
32− const refreshSources = useAtomRefresh(sourcesAtom(scopeId));
32+ const refreshSources = useAtomRefresh(sourcesOptimisticAtom(scopeId));
3333 const refreshTools = useAtomRefresh(sourceToolsAtom(namespace, scopeId));
34− const doRemove = useAtomSet(removeSource, { mode: "promise" });
34+ const doRemove = useAtomSet(removeSourceOptimistic(scopeId), { mode: "promise" });
3535 const doRefresh = useAtomSet(refreshSource, { mode: "promise" });
3636 const policyActions = usePolicyActions(scopeId);
3737 const navigate = useNavigate();
packages/react/src/pages/sources.tsx+7−20
@@ -1,16 +1,11 @@
11 import { Suspense, useCallback, useMemo, useState } from "react";
22 import { Link, useNavigate } from "@tanstack/react-router";
3−import { useAtomSet } from "@effect/atom-react";
3+import { useAtomSet, useAtomValue } from "@effect/atom-react";
44 import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
55 import { PlusIcon } from "lucide-react";
66 import type { SourceDetectionResult } from "@executor-js/sdk";
7−import {
8− useSourcePlugins,
9− type SourcePlugin,
10− type SourcePreset,
11−} from "@executor-js/sdk/client";
12−import { detectSource } from "../api/atoms";
13−import { useSourcesWithPending } from "../api/optimistic";
7+import { useSourcePlugins, type SourcePlugin, type SourcePreset } from "@executor-js/sdk/client";
8+import { detectSource, sourcesOptimisticAtom } from "../api/atoms";
149 import { useScope } from "../hooks/use-scope";
1510 import { McpInstallCard } from "../components/mcp-install-card";
1611 import { Button } from "../components/button";
@@ -60,7 +55,7 @@ const bestDetection = ( · 43 unmodified lines
6055
6156 export function SourcesPage() {
6257 const scopeId = useScope();
63− const sources = useSourcesWithPending(scopeId);
58+ const sources = useAtomValue(sourcesOptimisticAtom(scopeId));
6459 const [connectOpen, setConnectOpen] = useState(false);
6560
6661 return (
@@ -228,10 +223,7 @@ function ConnectDialog(props: { open: boolean; onOpenChange: (open: boolean) => · 161 unmodified lines
228223 className="flex-1"
229224 />
230225 {isUrl && (
231− <Button
232− onClick={() => void handleDetect()}
233− disabled={detecting || !query.trim()}
234− >
226+ <Button onClick={() => void handleDetect()} disabled={detecting || !query.trim()}>
235227 {detecting ? "Detecting..." : "Detect"}
236228 </Button>
237229 )}
@@ -256,11 +248,7 @@ function ConnectDialog(props: { open: boolean; onOpenChange: (open: boolean) => · 18 unmodified lines
256248 </div>
257249 </div>
258250
259− <PresetGrid
260− plugins={sourcePlugins}
261− onPick={closeAndReset}
262− searchQuery={presetSearch}
263− />
251+ <PresetGrid plugins={sourcePlugins} onPick={closeAndReset} searchQuery={presetSearch} />
264252 </div>
265253 </DialogContent>
266254 </Dialog>
@@ -324,8 +312,7 @@ function PresetGrid(props: { · 57 unmodified lines
324312 const q = (props.searchQuery ?? "").trim().toLowerCase();
325313 if (q.length === 0) return allPresets;
326314 return allPresets.filter(({ preset, pluginLabel }) => {
327− const corpus =
328− `${preset.name} ${preset.summary ?? ""} ${pluginLabel}`.toLowerCase();
315+ const corpus = `${preset.name} ${preset.summary ?? ""} ${pluginLabel}`.toLowerCase();
329316 return corpus.includes(q);
330317 });
331318 }, [allPresets, props.searchQuery]);
warden.toml+1−5
@@ -61,17 +61,13 @@ paths = [ · 60 unmodified lines
6161 [[skills]]
6262 name = "wrdn-gha-workflows"
6363 remote = "getsentry/warden-skills"
64−paths = [
65− ".github/workflows/**/*.yml",
66− ".github/workflows/**/*.yaml",
67−]
64+paths = [".github/workflows/**/*.yml", ".github/workflows/**/*.yaml"]
6865
6966 # Local skill — no `remote =`, resolved from `.agents/skills/<name>/SKILL.md`.
7067 [[skills]]
7168 name = "wrdn-effect-atom-optimistic"
7269 paths = [
7370 "packages/react/src/api/atoms.tsx",
74− "packages/react/src/api/optimistic.tsx",
7571 "packages/react/src/pages/**/*.tsx",
7672 "packages/react/src/components/**/*.tsx",
7773 ]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t