Skip to content

Commit c016a2f

Browse files
zerone0xclaude
andcommitted
fix(app): add ability to disconnect from providers
Adds a DELETE /auth/:providerID endpoint to the server and exposes disconnect/reconnect functionality in both TUI and Web provider dialogs. Users can now: - See "Connected" status on providers they're logged into - Disconnect from a provider to remove credentials - Reconnect with different credentials if needed This addresses the inability to remove provider credentials that may have been added incorrectly or are no longer needed. Fixes anomalyco#10494 Co-Authored-By: Claude <[email protected]>
1 parent a5c058e commit c016a2f

8 files changed

Lines changed: 1544 additions & 298 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Component } from "solid-js"
2+
import { useDialog } from "@opencode-ai/ui/context/dialog"
3+
import { Dialog } from "@opencode-ai/ui/dialog"
4+
import { List } from "@opencode-ai/ui/list"
5+
import { Icon } from "@opencode-ai/ui/icon"
6+
import { showToast } from "@opencode-ai/ui/toast"
7+
import { useGlobalSDK } from "@/context/global-sdk"
8+
import { DialogConnectProvider } from "./dialog-connect-provider"
9+
import { useLanguage } from "@/context/language"
10+
11+
interface DialogProviderActionProps {
12+
provider: string
13+
providerName: string
14+
}
15+
16+
export const DialogProviderAction: Component<DialogProviderActionProps> = (props) => {
17+
const dialog = useDialog()
18+
const globalSDK = useGlobalSDK()
19+
const language = useLanguage()
20+
21+
const actions = () => [
22+
{
23+
id: "disconnect",
24+
label: language.t("dialog.provider.action.disconnect"),
25+
icon: "close" as const,
26+
},
27+
{
28+
id: "reconnect",
29+
label: language.t("dialog.provider.action.reconnect"),
30+
icon: "plus" as const,
31+
},
32+
]
33+
34+
async function handleSelect(action: { id: string } | undefined) {
35+
if (!action) return
36+
if (action.id === "disconnect") {
37+
await globalSDK.client.auth.remove({ providerID: props.provider })
38+
await globalSDK.client.global.dispose()
39+
dialog.close()
40+
showToast({
41+
variant: "success",
42+
icon: "circle-check",
43+
title: language.t("dialog.provider.toast.disconnected.title", { provider: props.providerName }),
44+
description: language.t("dialog.provider.toast.disconnected.description", { provider: props.providerName }),
45+
})
46+
} else if (action.id === "reconnect") {
47+
dialog.show(() => <DialogConnectProvider provider={props.provider} />)
48+
}
49+
}
50+
51+
return (
52+
<Dialog title={props.providerName}>
53+
<List items={actions} key={(x) => x?.id} onSelect={handleSelect}>
54+
{(item) => (
55+
<div class="px-1.25 w-full flex items-center gap-x-3">
56+
<Icon data-slot="list-item-extra-icon" name={item.icon} />
57+
<span>{item.label}</span>
58+
</div>
59+
)}
60+
</List>
61+
</Dialog>
62+
)
63+
}

‎packages/app/src/components/dialog-select-provider.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Show } from "solid-js"
1+
import { Component, createMemo, Show } from "solid-js"
22
import { useDialog } from "@opencode-ai/ui/context/dialog"
33
import { popularProviders, useProviders } from "@/hooks/use-providers"
44
import { Dialog } from "@opencode-ai/ui/dialog"
@@ -7,12 +7,14 @@ import { Tag } from "@opencode-ai/ui/tag"
77
import { ProviderIcon } from "@opencode-ai/ui/provider-icon"
88
import { IconName } from "@opencode-ai/ui/icons/provider"
99
import { DialogConnectProvider } from "./dialog-connect-provider"
10+
import { DialogProviderAction } from "./dialog-provider-action"
1011
import { useLanguage } from "@/context/language"
1112

1213
export const DialogSelectProvider: Component = () => {
1314
const dialog = useDialog()
1415
const providers = useProviders()
1516
const language = useLanguage()
17+
const connectedSet = createMemo(() => new Set(providers.connected().map((p) => p.id)))
1618

1719
const popularGroup = () => language.t("dialog.provider.group.popular")
1820
const otherGroup = () => language.t("dialog.provider.group.other")
@@ -43,23 +45,30 @@ export const DialogSelectProvider: Component = () => {
4345
}}
4446
onSelect={(x) => {
4547
if (!x) return
46-
dialog.show(() => <DialogConnectProvider provider={x.id} />)
48+
if (connectedSet().has(x.id)) {
49+
dialog.show(() => <DialogProviderAction provider={x.id} providerName={x.name} />)
50+
} else {
51+
dialog.show(() => <DialogConnectProvider provider={x.id} />)
52+
}
4753
}}
4854
>
4955
{(i) => (
5056
<div class="px-1.25 w-full flex items-center gap-x-3">
5157
<ProviderIcon data-slot="list-item-extra-icon" id={i.id as IconName} />
5258
<span>{i.name}</span>
53-
<Show when={i.id === "opencode"}>
59+
<Show when={connectedSet().has(i.id)}>
60+
<Tag class="text-feedback-success-base">{language.t("dialog.provider.tag.connected")}</Tag>
61+
</Show>
62+
<Show when={i.id === "opencode" && !connectedSet().has(i.id)}>
5463
<Tag>{language.t("dialog.provider.tag.recommended")}</Tag>
5564
</Show>
56-
<Show when={i.id === "anthropic"}>
65+
<Show when={i.id === "anthropic" && !connectedSet().has(i.id)}>
5766
<div class="text-14-regular text-text-weak">{language.t("dialog.provider.anthropic.note")}</div>
5867
</Show>
59-
<Show when={i.id === "openai"}>
68+
<Show when={i.id === "openai" && !connectedSet().has(i.id)}>
6069
<div class="text-14-regular text-text-weak">{language.t("dialog.provider.openai.note")}</div>
6170
</Show>
62-
<Show when={i.id.startsWith("github-copilot")}>
71+
<Show when={i.id.startsWith("github-copilot") && !connectedSet().has(i.id)}>
6372
<div class="text-14-regular text-text-weak">{language.t("dialog.provider.copilot.note")}</div>
6473
</Show>
6574
</div>

‎packages/app/src/i18n/en.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ export const dict = {
8787
"dialog.provider.group.popular": "Popular",
8888
"dialog.provider.group.other": "Other",
8989
"dialog.provider.tag.recommended": "Recommended",
90+
"dialog.provider.tag.connected": "Connected",
91+
"dialog.provider.action.disconnect": "Disconnect",
92+
"dialog.provider.action.reconnect": "Reconnect",
93+
"dialog.provider.toast.disconnected.title": "Disconnected from {{provider}}",
94+
"dialog.provider.toast.disconnected.description": "Your {{provider}} credentials have been removed.",
9095
"dialog.provider.anthropic.note": "Connect with Claude Pro/Max or API key",
9196
"dialog.provider.openai.note": "Connect with ChatGPT Pro/Plus or API key",
9297
"dialog.provider.copilot.note": "Connect with Copilot or API key",

‎packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ export function createDialogProviderOptions() {
4444
category: provider.id in PROVIDER_PRIORITY ? "Popular" : "Other",
4545
footer: isConnected ? "Connected" : undefined,
4646
async onSelect() {
47+
// If provider is connected, show disconnect option
48+
if (isConnected) {
49+
const action = await new Promise<"disconnect" | "reconnect" | null>((resolve) => {
50+
dialog.replace(
51+
() => (
52+
<DialogSelect
53+
title={provider.name}
54+
options={[
55+
{ title: "Disconnect", value: "disconnect" as const },
56+
{ title: "Reconnect", value: "reconnect" as const },
57+
]}
58+
onSelect={(option) => resolve(option.value)}
59+
/>
60+
),
61+
() => resolve(null),
62+
)
63+
})
64+
if (action === null) return
65+
if (action === "disconnect") {
66+
await sdk.client.auth.remove({ providerID: provider.id })
67+
await sdk.client.instance.dispose()
68+
await sync.bootstrap()
69+
dialog.clear()
70+
return
71+
}
72+
// action === "reconnect" - fall through to normal connect flow
73+
}
74+
4775
const methods = sync.data.provider_auth[provider.id] ?? [
4876
{
4977
type: "api",

‎packages/opencode/src/server/server.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,36 @@ export namespace Server {
441441
return c.json(true)
442442
},
443443
)
444+
.delete(
445+
"/auth/:providerID",
446+
describeRoute({
447+
summary: "Remove auth credentials",
448+
description: "Remove authentication credentials for a provider",
449+
operationId: "auth.remove",
450+
responses: {
451+
200: {
452+
description: "Successfully removed authentication credentials",
453+
content: {
454+
"application/json": {
455+
schema: resolver(z.boolean()),
456+
},
457+
},
458+
},
459+
...errors(400),
460+
},
461+
}),
462+
validator(
463+
"param",
464+
z.object({
465+
providerID: z.string(),
466+
}),
467+
),
468+
async (c) => {
469+
const providerID = c.req.valid("param").providerID
470+
await Auth.remove(providerID)
471+
return c.json(true)
472+
},
473+
)
444474
.get(
445475
"/event",
446476
describeRoute({

‎packages/sdk/js/src/v2/gen/sdk.gen.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type {
99
AppLogResponses,
1010
AppSkillsResponses,
1111
Auth as Auth3,
12+
AuthRemoveErrors,
13+
AuthRemoveResponses,
1214
AuthSetErrors,
1315
AuthSetResponses,
1416
CommandListResponses,
@@ -3054,6 +3056,36 @@ export class Formatter extends HeyApiClient {
30543056
}
30553057

30563058
export class Auth2 extends HeyApiClient {
3059+
/**
3060+
* Remove auth credentials
3061+
*
3062+
* Remove authentication credentials for a provider
3063+
*/
3064+
public remove<ThrowOnError extends boolean = false>(
3065+
parameters: {
3066+
providerID: string
3067+
directory?: string
3068+
},
3069+
options?: Options<never, ThrowOnError>,
3070+
) {
3071+
const params = buildClientParams(
3072+
[parameters],
3073+
[
3074+
{
3075+
args: [
3076+
{ in: "path", key: "providerID" },
3077+
{ in: "query", key: "directory" },
3078+
],
3079+
},
3080+
],
3081+
)
3082+
return (options?.client ?? this.client).delete<AuthRemoveResponses, AuthRemoveErrors, ThrowOnError>({
3083+
url: "/auth/{providerID}",
3084+
...options,
3085+
...params,
3086+
})
3087+
}
3088+
30573089
/**
30583090
* Set auth credentials
30593091
*

‎packages/sdk/js/src/v2/gen/types.gen.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,6 +4867,35 @@ export type FormatterStatusResponses = {
48674867

48684868
export type FormatterStatusResponse = FormatterStatusResponses[keyof FormatterStatusResponses]
48694869

4870+
export type AuthRemoveData = {
4871+
body?: never
4872+
path: {
4873+
providerID: string
4874+
}
4875+
query?: {
4876+
directory?: string
4877+
}
4878+
url: "/auth/{providerID}"
4879+
}
4880+
4881+
export type AuthRemoveErrors = {
4882+
/**
4883+
* Bad request
4884+
*/
4885+
400: BadRequestError
4886+
}
4887+
4888+
export type AuthRemoveError = AuthRemoveErrors[keyof AuthRemoveErrors]
4889+
4890+
export type AuthRemoveResponses = {
4891+
/**
4892+
* Successfully removed authentication credentials
4893+
*/
4894+
200: boolean
4895+
}
4896+
4897+
export type AuthRemoveResponse = AuthRemoveResponses[keyof AuthRemoveResponses]
4898+
48704899
export type AuthSetData = {
48714900
body?: Auth
48724901
path: {

0 commit comments

Comments
 (0)