The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 02:00 UTC
fix(providers): remove incomplete ChatGPT connections (#29280)
Lakshmi Tanmay committed
Nov 7, 2026 at 16:07 UTC
1b952135a150f180a49f442d3ed66639266d1bf0
17 files changed
+286
-6
apps/mobile/src/features/settings/SettingsProviderAccountsRouteScreen.tsx
+27
-2
@@ -149,6 +149,10 @@ function ProviderAccount({
149
const complete = useAtomCommand(serverEnvironment.completeProviderAuth, options);
150
const cancel = useAtomCommand(serverEnvironment.cancelProviderAuth, options);
151
const logout = useAtomCommand(serverEnvironment.logoutProviderAuth, options);
152
+ const removeMethod = useAtomCommand(serverEnvironment.removeProviderAuthMethod, options);
153
+ const canRemoveMethod = useAtomValue(
154
+ serverEnvironment.removeProviderAuthMethod.permissionAtom(environmentId),
155
+ );
156
// Matches ListRowLayout: large text stacks the action below instead of squeezing the status.
157
const stacked = useWindowDimensions().fontScale >= 1.5;
158
const [pending, setPending] = useState(false);
@@ -260,6 +264,21 @@ function ProviderAccount({
264
id: `method:${method.id}`,
265
title: method.name,
266
}));
267
+ const removableMethods = methods.filter((method) => method.canRemove);
268
+ const removeActions: MenuAction[] = removableMethods.length
269
+ ? [
270
+ {
271
+ id: "remove",
272
+ title: "Remove incomplete connection",
273
+ attributes: { disabled: disabled || active || !canRemoveMethod },
274
+ subactions: removableMethods.map((method) => ({
275
+ id: `remove:${method.id}`,
276
+ title: method.name,
277
+ attributes: { destructive: true, disabled: disabled || active || !canRemoveMethod },
278
+ })),
279
+ },
280
+ ]
281
+ : [];
282
function startSignIn(methodId?: string) {
283
void run(() => start(methodId ? { environmentId, input: { instanceId, methodId } } : target));
284
}
@@ -283,10 +302,16 @@ function ProviderAccount({
302
if (id === "signOut") signOut();
303
// iOS keeps a disabled submenu's children selectable, so sign-in guards here too.
304
else if (signInDisabled) return;
286
- else if (id.startsWith("method:")) startSignIn(id.slice("method:".length));
305
+ else if (id.startsWith("remove:")) {
306
+ if (active || !canRemoveMethod) return;
307
+ const methodId = id.slice("remove:".length);
308
+ if (!removableMethods.some((method) => method.id === methodId)) return;
309
+ void run(() => removeMethod({ environmentId, input: { instanceId, methodId } }));
310
+ } else if (id.startsWith("method:")) startSignIn(id.slice("method:".length));
311
else if (id === "change") startSignIn();
312
}
313
const accountActions: MenuAction[] = [
314
+ ...removeActions,
315
...(canSignIn
316
? [
317
{
@@ -357,7 +382,7 @@ function ProviderAccount({
382
accessibilityRole="button"
383
accessibilityLabel={`Sign in to ${name}`}
384
title="Sign in with"
360
- actions={methodActions}
385
+ actions={[...methodActions, ...removeActions]}
386
onPressAction={({ nativeEvent }) => onMenuAction(nativeEvent.event)}
387
>
388
<ControlPill variant="primary" label="Sign in" accessibilityLabel={`Sign in to ${name}`} />
apps/server/src/auth/RpcAuthorization.ts
+1
@@ -74,6 +74,7 @@ export const RPC_REQUIRED_SCOPES = {
74
[WS_METHODS.chatGptHandoffSubscribe]: AuthProvidersManageScope,
75
[WS_METHODS.providerAuthRespond]: AuthProvidersManageScope,
76
[WS_METHODS.providerAuthCancel]: AuthProvidersManageScope,
77
+ [WS_METHODS.providerAuthRemoveMethod]: AuthProvidersManageScope,
78
[WS_METHODS.providerAuthLogout]: AuthProvidersManageScope,
79
[WS_METHODS.providerAuthSubscribe]: AuthProvidersManageScope,
80
[WS_METHODS.providerInstallStart]: AuthProvidersManageScope,
apps/server/src/observability/RpcInstrumentation.ts
+1
@@ -46,6 +46,7 @@ const RPC_AGGREGATES = {
46
[WS_METHODS.chatGptHandoffSubscribe]: "provider",
47
[WS_METHODS.providerAuthRespond]: "provider",
48
[WS_METHODS.providerAuthCancel]: "provider",
49
+ [WS_METHODS.providerAuthRemoveMethod]: "provider",
50
[WS_METHODS.providerAuthLogout]: "provider",
51
[WS_METHODS.providerAuthSubscribe]: "provider",
52
[WS_METHODS.providerInstallStart]: "provider",
apps/server/src/provider/CodexChatGptAuth.test.ts
+64
@@ -1379,6 +1379,70 @@ it.effect("an expired initial code retains the issued ID for a fresh authorizati
1379
),
1380
);
1381
1382
+it.effect.each([false, true])(
1383
+ "removes only the selected incomplete connection across restart (authenticated: %s)",
1384
+ (authenticated) =>
1385
+ provision(
1386
+ Effect.gen(function* () {
1387
+ const h = yield* makeHarness;
1388
+ if (authenticated) {
1389
+ yield* h.signIn;
1390
+ yield* h.phase("succeeded");
1391
+ }
1392
+ const credentials = yield* h.auth.read;
1393
+ h.setCallbackClientId("oaiapp_failed");
1394
+ h.setCodeError("invalid_grant");
1395
+ yield* h.changeAccount;
1396
+ const failed = yield* h.phase("failed");
1397
+ const methodId = "chatgpt-profile:oaiapp_failed";
1398
+ assert.isTrue(failed.methods!.find((method) => method.id === methodId)?.canRemove);
1399
+ h.setCallbackClientId("oaiapp_other_failed");
1400
+ yield* h.changeAccount;
1401
+ yield* h.phase("failed");
1402
+ const { waiting } = yield* h.startRemote(methodId);
1403
+ const busy = yield* Effect.flip(h.auth.controller.removeMethod!(methodId));
1404
+ assert.include(busy.detail, "Finish or cancel");
1405
+ yield* h.auth.controller.cancel("owner", waiting.flowId!);
1406
+ const removed = yield* h.auth.controller.removeMethod!(methodId);
1407
+ assert.isFalse(removed.methods!.some((method) => method.id === methodId));
1408
+ assert.isTrue(
1409
+ removed.methods!.some((method) => method.id === "chatgpt-profile:oaiapp_other_failed"),
1410
+ );
1411
+ assert.deepEqual(yield* h.auth.read, credentials);
1412
+ h.setCallbackClientId("oaiapp_new_failed");
1413
+ yield* h.changeAccount;
1414
+ const next = yield* h.phase("failed");
1415
+ const profiles = next.methods!.filter((method) => method.id.startsWith("chatgpt-profile:"));
1416
+ assert.strictEqual(new Set(profiles.map((method) => method.name)).size, profiles.length);
1417
+ yield* h.auth.controller.removeMethod!("chatgpt-profile:oaiapp_new_failed");
1418
+ const last = yield* h.auth.controller.removeMethod!("chatgpt-profile:oaiapp_other_failed");
1419
+ assert.strictEqual(
1420
+ last.methods!.filter((method) => method.id.startsWith("chatgpt-profile:")).length,
1421
+ authenticated ? 1 : 0,
1422
+ );
1423
+ const restarted = yield* h.recreateAuth;
1424
+ yield* restarted.controller.refreshMethods!;
1425
+ const state = yield* restarted.controller.subscribe("owner").pipe(Stream.runHead);
1426
+ assert.deepEqual(Option.getOrThrow(state).methods, last.methods);
1427
+ if (authenticated) {
1428
+ assert.isFalse(
1429
+ last.methods!.find((method) => method.id === "chatgpt-profile:oaiapp_test")?.canRemove,
1430
+ );
1431
+ yield* Effect.flip(h.auth.controller.removeMethod!("chatgpt-profile:oaiapp_test"));
1432
+ yield* h.auth.controller.logout(Effect.void);
1433
+ }
1434
+ h.setCodeError(undefined);
1435
+ h.setCallbackClientId("oaiapp_test");
1436
+ yield* h.signIn;
1437
+ yield* h.phase("succeeded");
1438
+ assert.strictEqual(
1439
+ h.authorizationRequests.at(-1)!.searchParams.get("client_id"),
1440
+ authenticated ? "oaiapp_test" : "dynamic_agent_client",
1441
+ );
1442
+ }),
1443
+ ),
1444
+);
1445
+
1446
it.effect("identity-only sign-in requests consent on an explicit retry, then rechecks scopes", () =>
1447
provision(
1448
Effect.gen(function* () {
apps/server/src/provider/CodexChatGptAuth.ts
+49
-1
@@ -387,12 +387,17 @@ export const makeCodexChatGptAuth = Effect.fn("makeCodexChatGptAuth")(function*
387
);
388
const saveRegistration = Effect.fnUntraced(function* (profile: typeof Registration.Type) {
389
const saved = yield* readRegistrations;
390
+ let connectionNumber = saved.profiles.length + 1;
391
+ while (
392
+ saved.profiles.some((entry) => entry.connectionLabel === `Connection ${connectionNumber}`)
393
+ )
394
+ connectionNumber++;
395
profile = {
396
...profile,
397
connectionLabel:
398
saved.profiles.find((entry) => entry.clientId === profile.clientId)?.connectionLabel ??
399
profile.connectionLabel ??
395
- `Connection ${saved.profiles.length + 1}`,
400
+ `Connection ${connectionNumber}`,
401
};
402
yield* encodeRegistration({
403
profiles: [profile, ...saved.profiles.filter((entry) => entry.clientId !== profile.clientId)],
@@ -911,6 +916,7 @@ export const makeCodexChatGptAuth = Effect.fn("makeCodexChatGptAuth")(function*
916
methods: Effect.gen(function* () {
917
const saved = yield* readRegistrations;
918
const active = Option.getOrUndefined(yield* read);
919
+ const sessions = (yield* readSessions).sessions;
920
const current = saved.profiles.find(
921
(profile) => profile.clientId === (active?.clientId ?? saved.lastClientId),
922
);
@@ -933,6 +939,9 @@ export const makeCodexChatGptAuth = Effect.fn("makeCodexChatGptAuth")(function*
939
},
940
...profiles.slice(0, 30).map((profile) => ({
941
id: profileMethodId(profile.clientId),
942
+ canRemove:
943
+ profile.subject === undefined &&
944
+ !sessions.some((session) => session.clientId === profile.clientId),
945
name: `${profile.email ?? "ChatGPT account"} · ${profile.connectionLabel}`,
946
...(profile.email ? { accountEmail: profile.email } : {}),
947
description: "Reuse this account's original sign-in registration.",
@@ -962,6 +971,45 @@ export const makeCodexChatGptAuth = Effect.fn("makeCodexChatGptAuth")(function*
971
context.expiresAt,
972
),
973
),
974
+ removeMethod: Effect.fn("CodexChatGptAuth.removeMethod")(function (methodId) {
975
+ return lock.withPermit(
976
+ withSessionLock(
977
+ Effect.gen(function* () {
978
+ const saved = yield* readRegistrations;
979
+ const profile = saved.profiles.find(
980
+ (entry) => profileMethodId(entry.clientId) === methodId,
981
+ );
982
+ if (
983
+ !profile ||
984
+ profile.subject !== undefined ||
985
+ (yield* readSessions).sessions.some(
986
+ (session) => session.clientId === profile.clientId,
987
+ )
988
+ )
989
+ return yield* failure(
990
+ "removeMethod",
991
+ "Only incomplete ChatGPT connections can be removed.",
992
+ );
993
+ const profiles = saved.profiles.filter((entry) => entry.clientId !== profile.clientId);
994
+ yield* encodeRegistration({
995
+ profiles,
996
+ lastClientId:
997
+ saved.lastClientId === profile.clientId
998
+ ? (profiles[0]?.clientId ?? null)
999
+ : saved.lastClientId,
1000
+ }).pipe(
1001
+ Effect.flatMap((json) => registrationStore.set(new TextEncoder().encode(json))),
1002
+ Effect.mapError(() =>
1003
+ failure(
1004
+ "removeMethod",
1005
+ "Could not remove the saved ChatGPT connection. Try again.",
1006
+ ),
1007
+ ),
1008
+ );
1009
+ }),
1010
+ ),
1011
+ );
1012
+ }),
1013
logout: lock.withPermit(withSessionLock(logout)),
1014
});
1015
const reconnectProfile = Effect.fnUntraced(function* (methodId: string) {
apps/server/src/provider/ProviderAuthService.ts
+19
-1
@@ -51,6 +51,9 @@ export class ProviderAuthService extends Context.Service<
51
input: ProviderAuthTarget & { readonly flowId: string },
52
ownerSessionId: string,
53
) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
54
+ readonly removeMethod: (
55
+ input: ProviderAuthTarget & { readonly methodId: string },
56
+ ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
57
readonly logout: (
58
input: ProviderAuthTarget,
59
) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
@@ -170,7 +173,7 @@ export const makeProviderAuthService = Effect.gen(function* () {
173
174
const checkSharedBinding = Effect.fnUntraced(function* (
175
instanceId: ProviderInstanceId,
173
- operation: "start" | "logout",
176
+ operation: "start" | "logout" | "removeMethod",
177
auth: ProviderAuthController,
178
) {
179
const binding = auth.credentialBinding;
@@ -257,6 +260,21 @@ export const makeProviderAuthService = Effect.gen(function* () {
260
const auth = yield* getController(input.instanceId, "cancel");
261
return yield* auth.cancel(ownerSessionId, input.flowId);
262
}),
263
+ removeMethod: Effect.fn("ProviderAuthService.removeMethod")(function (input) {
264
+ return credentialChanges.withPermit(
265
+ Effect.gen(function* () {
266
+ const auth = yield* getController(input.instanceId, "removeMethod");
267
+ yield* checkSharedBinding(input.instanceId, "removeMethod", auth);
268
+ if (!auth.removeMethod)
269
+ return yield* new ProviderSetupError({
270
+ instanceId: input.instanceId,
271
+ operation: "removeMethod",
272
+ detail: "This provider does not support removing saved sign-in methods.",
273
+ });
274
+ return yield* auth.removeMethod(input.methodId);
275
+ }),
276
+ );
277
+ }),
278
logout: Effect.fn("ProviderAuthService.logout")(function* (input) {
279
return yield* credentialChanges.withPermit(
280
Effect.gen(function* () {
apps/server/src/ws.ts
+1
@@ -2646,6 +2646,7 @@ export const layerWsRpc = (
2646
[WS_METHODS.chatGptHandoffSubscribe]: (input) =>
2647
subscribeChatGptHandoff(input, currentSessionId),
2648
[WS_METHODS.providerAuthCancel]: (input) => providerAuth.cancel(input, currentSessionId),
2649
+ [WS_METHODS.providerAuthRemoveMethod]: (input) => providerAuth.removeMethod(input),
2650
[WS_METHODS.providerAuthLogout]: (input) => providerAuth.logout(input),
2651
[WS_METHODS.providerAuthSubscribe]: (input) =>
2652
providerAuth.subscribe(input, currentSessionId),
apps/web/src/components/settings/ChatGptAccountPicker.tsx
+25
-1
@@ -9,6 +9,7 @@ import {
9
DialogDescription,
10
DialogFooter,
11
} from "../ui/dialog";
12
+import { Button } from "../ui/button";
13
import { ChatGptConnectionButton } from "./ChatGptConnectionButton";
14
15
export function ChatGptAccountPicker({
@@ -16,11 +17,19 @@ export function ChatGptAccountPicker({
17
methods,
18
onClose,
19
onSelect,
20
+ onRemove,
21
+ disabled,
22
+ canRemove,
23
+ error,
24
}: {
25
open: boolean;
26
methods: readonly ProviderAuthMethod[];
27
onClose: () => void;
28
onSelect: (methodId: string) => void;
29
+ onRemove: (methodId: string) => void;
30
+ disabled: boolean;
31
+ canRemove: boolean;
32
+ error: string | null;
33
}) {
34
const profiles = methods.filter((method) => method.id.startsWith("chatgpt-profile:"));
35
const [selection, setSelection] = useState<string | null>(null);
@@ -47,6 +56,7 @@ export function ChatGptAccountPicker({
56
<div className="px-6 pb-6">
57
<RadioGroup
58
aria-label="ChatGPT account to connect"
59
+ disabled={disabled}
60
value={selectedMethodId}
61
onValueChange={(value) => setSelection(value)}
62
>
@@ -65,8 +75,22 @@ export function ChatGptAccountPicker({
75
</label>
76
</RadioGroup>
77
</div>
78
+ {error ? (
79
+ <p role="alert" className="px-6 pb-3 text-sm text-destructive">
80
+ {error}
81
+ </p>
82
+ ) : null}
83
<DialogFooter>
69
- <ChatGptConnectionButton onClick={() => onSelect(selectedMethodId)} />
84
+ {profiles.find((profile) => profile.id === selectedMethodId)?.canRemove ? (
85
+ <Button
86
+ variant="ghost"
87
+ disabled={disabled || !canRemove}
88
+ onClick={() => onRemove(selectedMethodId)}
89
+ >
90
+ Remove connection
91
+ </Button>
92
+ ) : null}
93
+ <ChatGptConnectionButton disabled={disabled} onClick={() => onSelect(selectedMethodId)} />
94
</DialogFooter>
95
</DialogPopup>
96
</Dialog>
apps/web/src/components/settings/CodexSetupSection.tsx
+11
@@ -1,3 +1,4 @@
1
+import { useAtomValue } from "@effect/atom-react";
2
import { AuthProvidersManageScope, ProviderDriverKind } from "@t3tools/contracts";
3
import { readPreparedConnection, useEnvironmentScope } from "../../state/session";
4
import {
@@ -293,6 +294,10 @@ function ManagedCodexSetup({
294
const completeAuth = useAtomCommand(serverEnvironment.completeProviderAuth, options);
295
const cancelAuth = useAtomCommand(serverEnvironment.cancelProviderAuth, options);
296
const logoutAuth = useAtomCommand(serverEnvironment.logoutProviderAuth, options);
297
+ const removeAuthMethod = useAtomCommand(serverEnvironment.removeProviderAuthMethod, options);
298
+ const canRemoveAuthMethod = useAtomValue(
299
+ serverEnvironment.removeProviderAuthMethod.permissionAtom(environmentId),
300
+ );
301
const startInstall = useAtomCommand(serverEnvironment.startProviderInstall, options);
302
const cancelInstall = useAtomCommand(serverEnvironment.cancelProviderInstall, options);
303
const reconnectProfile = useAtomCommand(serverEnvironment.chatGptReconnectProfile, options);
@@ -771,6 +776,12 @@ function ManagedCodexSetup({
776
open={accountPickerOpen}
777
methods={auth?.methods ?? []}
778
onClose={() => setAccountPickerOpen(false)}
779
+ disabled={unavailable || busy}
780
+ canRemove={canRemoveAuthMethod}
781
+ error={error}
782
+ onRemove={(methodId) => {
783
+ void run(() => removeAuthMethod({ environmentId, input: { instanceId, methodId } }));
784
+ }}
785
onSelect={(methodId) => {
786
setAccountPickerOpen(false);
787
void setup(
packages/client-runtime/src/state/commandPermissions.test.ts
+27
@@ -12,6 +12,7 @@ import {
12
AuthOrchestrationOperateScope,
13
AuthOrchestrationReadScope,
14
AuthPreviewOperateScope,
15
+ AuthProvidersManageScope,
16
AuthSettingsWriteScope,
17
AuthSourceControlWriteScope,
18
ThreadId,
@@ -130,6 +131,32 @@ describe("command permissions", () => {
131
),
132
);
133
134
+ it.effect("requires the destination provider grant to remove an incomplete connection", () =>
135
+ Effect.scoped(
136
+ Effect.gen(function* () {
137
+ const registry = yield* setup;
138
+ const remove = createCommandPermissions(runtime, WS_METHODS.providerAuthRemoveMethod);
139
+ registry.set(sessions(env), AsyncResult.success(grant(true)));
140
+ expect(registry.get(remove.permissionAtom(env))).toBe(false);
141
+ expect((yield* remove.authorize(registry, env).pipe(Effect.flip))._tag).toBe(
142
+ "EnvironmentAuthorizationError",
143
+ );
144
+ registry.set(
145
+ sessions(env),
146
+ AsyncResult.success({
147
+ ...grant(false),
148
+ scopes: [AuthProvidersManageScope],
149
+ permissions: [AuthProvidersManageScope],
150
+ }),
151
+ );
152
+ expect(registry.get(remove.permissionAtom(env))).toBe(true);
153
+ yield* remove.authorize(registry, env);
154
+ registry.set(sessions(other), AsyncResult.success(grant(false)));
155
+ expect(registry.get(remove.permissionAtom(other))).toBe(false);
156
+ }),
157
+ ),
158
+ );
159
+
160
it.effect("requires the destination settings grant to run storage cleanup", () =>
161
Effect.scoped(
162
Effect.gen(function* () {
packages/client-runtime/src/state/server.ts
+4
@@ -1269,6 +1269,10 @@ export function createServerEnvironmentAtoms<R, E>(
1269
label: "environment-data:provider:auth-cancel",
1270
tag: WS_METHODS.providerAuthCancel,
1271
}),
1272
+ removeProviderAuthMethod: createEnvironmentRpcCommand(runtime, {
1273
+ label: "environment-data:provider:auth-remove-method",
1274
+ tag: WS_METHODS.providerAuthRemoveMethod,
1275
+ }),
1276
logoutProviderAuth: createEnvironmentRpcCommand(runtime, {
1277
label: "environment-data:provider:auth-logout",
1278
tag: WS_METHODS.providerAuthLogout,
packages/contracts/src/clientRpcPermissions.ts
+2
@@ -5,6 +5,7 @@ import {
5
AuthOrchestrationOperateScope,
6
AuthOrchestrationReadScope,
7
AuthPreviewOperateScope,
8
+ AuthProvidersManageScope,
9
AuthSettingsWriteScope,
10
AuthSourceControlWriteScope,
11
AuthTerminalOperateScope,
@@ -15,6 +16,7 @@ import { WS_METHODS } from "./rpc.ts";
16
17
/** Incremental client enforcement; the server still authorizes every request. */
18
export const CLIENT_GUARDED_RPC_SCOPES = {
19
+ [WS_METHODS.providerAuthRemoveMethod]: AuthProvidersManageScope,
20
[WS_METHODS.previewClose]: AuthPreviewOperateScope,
21
// Stopping a server signals its processes, as closing a terminal does.
22
[WS_METHODS.previewStopLocalServer]: AuthTerminalOperateScope,
packages/contracts/src/providerSetup.ts
+6
@@ -19,6 +19,7 @@ const SetupOperationId = TrimmedNonEmptyString.check(Schema.isMaxLength(128));
19
export const ProviderAuthMethod = Schema.Struct({
20
id: SetupOperationId,
21
accountEmail: Schema.optional(TrimmedNonEmptyString),
22
+ canRemove: Schema.optionalKey(Schema.Boolean),
23
name: TrimmedNonEmptyString,
24
description: Schema.NullOr(Schema.String),
25
type: Schema.Literals(["agent", "terminal", "credentials"]),
@@ -91,6 +92,11 @@ export const ProviderAuthStartInput = Schema.Struct({
92
});
93
export type ProviderAuthStartInput = typeof ProviderAuthStartInput.Type;
94
95
+export const ProviderAuthRemoveMethodInput = Schema.Struct({
96
+ instanceId: ProviderInstanceId,
97
+ methodId: SetupOperationId,
98
+});
99
+
100
export const ProviderAuthRespondInput = Schema.Struct({
101
instanceId: ProviderInstanceId,
102
flowId: SetupOperationId,
packages/contracts/src/rpc.ts
+9
@@ -43,6 +43,7 @@ import {
43
ProviderAuthCompleteInput,
44
ProviderAuthState,
45
ProviderAuthStartInput,
46
+ ProviderAuthRemoveMethodInput,
47
ProviderAuthRespondInput,
48
ProviderInstallCancelInput,
49
ProviderInstallState,
@@ -443,6 +444,7 @@ export const WS_METHODS = {
444
chatGptHandoffSubscribe: "provider.chatgpt.handoff.subscribe",
445
providerAuthRespond: "provider.auth.respond",
446
providerAuthCancel: "provider.auth.cancel",
447
+ providerAuthRemoveMethod: "provider.auth.removeMethod",
448
providerAuthLogout: "provider.auth.logout",
449
providerAuthSubscribe: "provider.auth.subscribe",
450
providerInstallStart: "provider.install.start",
@@ -718,6 +720,12 @@ const WsProviderAuthCancelRpc = Rpc.make(WS_METHODS.providerAuthCancel, {
720
error: ProviderSetupRpcError,
721
});
722
723
+const WsProviderAuthRemoveMethodRpc = Rpc.make(WS_METHODS.providerAuthRemoveMethod, {
724
+ payload: ProviderAuthRemoveMethodInput,
725
+ success: ProviderAuthState,
726
+ error: ProviderSetupRpcError,
727
+});
728
+
729
const WsProviderAuthLogoutRpc = Rpc.make(WS_METHODS.providerAuthLogout, {
730
payload: ProviderSetupInput,
731
success: ProviderAuthState,
@@ -2013,6 +2021,7 @@ export const WsRpcGroup = RpcGroup.make(
2021
WsChatGptHandoffSubscribeRpc,
2022
WsProviderAuthRespondRpc,
2023
WsProviderAuthCancelRpc,
2024
+ WsProviderAuthRemoveMethodRpc,
2025
WsProviderAuthLogoutRpc,
2026
WsProviderAuthSubscribeRpc,
2027
WsProviderInstallStartRpc,
packages/provider-core/src/server/auth.ts
+3
@@ -25,6 +25,9 @@ export interface ProviderAuthController {
25
readonly isChangingCredentials?: Effect.Effect<boolean>;
26
readonly invalidate?: Effect.Effect<void>;
27
readonly refreshMethods?: Effect.Effect<void>;
28
+ readonly removeMethod?: (
29
+ methodId: string,
30
+ ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
31
readonly withAccess?: <A, E, R>(
32
task: Effect.Effect<A, E, R>,
33
) => Effect.Effect<A, E | ProviderSetupError, R | Scope.Scope>;
packages/provider-core/src/server/providerAuthFlow.test.ts
+15
-1
@@ -439,6 +439,7 @@ it.effect("closing the controller scope interrupts and drains its adapter respon
439
it.effect("a failed method refresh keeps the last discovered methods", () =>
440
Effect.gen(function* () {
441
let fail = false;
442
+ let removed = false;
443
const controller = yield* ProviderAuthFlow.make({
444
instanceId,
445
credentialBinding: { owner: "provider", key: "shared-agent" },
@@ -447,10 +448,14 @@ it.effect("a failed method refresh keeps the last discovered methods", () =>
448
? Effect.fail(
449
new ProviderSetupError({ instanceId, operation: "status", detail: "interrupted" }),
450
)
450
- : Effect.succeed([method]),
451
+ : Effect.succeed(removed ? [] : [method]),
452
),
453
authenticate: () => Effect.void,
454
logout: Effect.void,
455
+ removeMethod: () =>
456
+ Effect.sync(() => {
457
+ removed = true;
458
+ }),
459
});
460
yield* controller.refreshMethods!;
461
fail = true;
@@ -460,6 +465,15 @@ it.effect("a failed method refresh keeps the last discovered methods", () =>
465
.pipe(Stream.runHead, Effect.map(Option.getOrThrow));
466
assert.deepEqual(state.methods, [method]);
467
assert.strictEqual(state.message, "interrupted");
468
+ const error = yield* Effect.flip(controller.removeMethod!(method.id));
469
+ assert.isTrue(removed);
470
+ assert.strictEqual(error.detail, "interrupted");
471
+ fail = false;
472
+ yield* controller.refreshMethods!;
473
+ const refreshed = yield* controller
474
+ .subscribe("owner")
475
+ .pipe(Stream.runHead, Effect.map(Option.getOrThrow));
476
+ assert.deepEqual(refreshed.methods, []);
477
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
478
);
479
packages/provider-core/src/server/providerAuthFlow.ts
+22
@@ -69,6 +69,7 @@ export const make = Effect.fn("ProviderAuthFlow.make")(function* (options: {
69
context: ProviderAuthFlowContext,
70
) => Effect.Effect<void, ProviderSetupError, Scope.Scope>;
71
readonly logout: Effect.Effect<void | string, ProviderSetupError>;
72
+ readonly removeMethod?: (methodId: string) => Effect.Effect<void, ProviderSetupError>;
73
readonly timeoutMs?: number;
74
}) {
75
const scope = yield* Scope.Scope;
@@ -177,6 +178,27 @@ export const make = Effect.fn("ProviderAuthFlow.make")(function* (options: {
178
return state;
179
}, Effect.uninterruptible),
180
refreshMethods,
181
+ ...(options.removeMethod
182
+ ? {
183
+ removeMethod: Effect.fn("providerAuthFlow.removeMethod")(function* (methodId: string) {
184
+ return yield* lock.withPermit(
185
+ Effect.gen(function* () {
186
+ if (operation !== "idle")
187
+ return yield* new ProviderSetupError({
188
+ instanceId: options.instanceId,
189
+ operation: "removeMethod",
190
+ detail: "Finish or cancel the existing sign-in first.",
191
+ });
192
+ yield* options.removeMethod!(methodId);
193
+ const methods = yield* options.methods;
194
+ const state = { ...empty, methods };
195
+ yield* SubscriptionRef.set(snapshot, { owner: null, state });
196
+ return state;
197
+ }),
198
+ );
199
+ }, Effect.uninterruptible),
200
+ }
201
+ : {}),
202
invalidate: lock.withPermit(
203
Effect.gen(function* () {
204
if (operation !== "idle") return;