-
{field().title}
+ return (
+
+
+ !options().some((option) => option.value === item))
+ .map((value) => ({ value, label: value, description: undefined })),
+ ]}
+ >
+ {(option) => (
+
+ setFormStore("picked", (picked) =>
+ checked ? [...picked, option.value] : picked.filter((item) => item !== option.value),
+ )
+ }
+ >
+ {option.label}
+
+ )}
+
+
+
+
+
+
+ {(error) => {error()}
}
+
+
+
+ )
+ }}
+
+
0)}
+ >
+
option.value === answer(field())))
- }
+ value={formStore.customOn ? "custom" : formStore.choice}
onChange={(value) => {
- const option = field().options?.[Number(value)]
-
- if (option) {
- if (custom()) setFormStore("customText", answer(field()) ?? "")
- setFormStore("customOn", false)
- setFormStore("value", field().key, option.value)
-
- return
- }
-
- setFormStore("customOn", true)
- setFormStore("value", field().key, formStore.customText)
+ if (value === "custom") return setFormStore({ customOn: true, error: undefined })
+ setFormStore({ customOn: false, choice: value, error: undefined })
}}
>
-
- {(option, index) => (
-
+
+ {(option) => (
+
)}
-
-
-
- queueMicrotask(() => input.focus())}
- type="text"
- label={language.t("ui.messagePart.option.typeOwnAnswer")}
- hideLabel
- placeholder={field().placeholder ?? language.t("ui.question.custom.placeholder")}
- value={answer(field()) ?? ""}
- onChange={(value) => setFormStore("value", field().key, value)}
- />
-
+
+
+
+
+ queueMicrotask(() => input.focus())}
+ type="text"
+ label={language.t("ui.messagePart.option.typeOwnAnswer")}
+ hideLabel
+ placeholder={text()?.placeholder ?? language.t("ui.question.custom.placeholder")}
+ value={formStore.customText}
+ onChange={(value) => setFormStore("customText", value)}
+ />
+
+
+
+
+
+
+
+
-
- >
- )}
-
-
-
-
{select()?.title}
-
-
x.value}
- current={select()?.options?.find((x) => x.value === answer(select()!))}
- onSelect={(value) => {
- if (!value) return
- const field = select()
-
- if (!field) return
-
- const nextValue = {
- ...formStore.value,
- [field.key]: value.value,
- }
-
- setFormStore("value", field.key, value.value)
- void next(item()!.index, nextValue)
- }}
- >
- {(option) => (
-
-
-
{option.label}
-
{option.description}
-
- )}
-
-
-
-
-
-
+
+
+
+
+
+
+ {(error) => (
+
+ {error()}
+
+ )}
+
+
+ )}
+
)
}
@@ -938,33 +1063,37 @@ function ProviderConnection(props: {
function MethodSelection() {
return (
-
-
- {language.t("provider.connect.selectMethod", { provider: provider().name })}
-
-
-
- {(item, index) => {
- const details = () => methodDetails(item)
+
+
+ {(item, index) => (
+
+ )}
+
+
+ )
+ }
- return (
-
- )
- }}
-
-
+ function CommandView() {
+ return (
+
+
+ {(output) => (
+
+ {output()}
+
+ )}
+
+
{language.t("provider.connect.command.waiting")}
)
}
@@ -1173,13 +1302,10 @@ function ProviderConnection(props: {
const addAccount = () => {
setState({ adding: true, direct: false, confirming: undefined })
- // Go signs in through the Console, which would add a Console account, so Go adds a key instead.
- const index =
- props.provider === "opencode-go" ? keyIndex() : !isConsole && controller.methods().length === 1 ? 0 : -1
-
- if (index === -1) return
+ // Like the TUI: a lone method starts directly, several show the method list.
+ if (controller.methods().length !== 1) return
setState("direct", true)
- void controller.auth.select(index)
+ void controller.auth.select(0)
}
const activateAccount = async (account: ProviderAccount) => {
@@ -1190,19 +1316,43 @@ function ProviderConnection(props: {
}
const removeAccount = async (account: ProviderAccount) => {
+ const final = accounts().length === 1
setState({ switching: account.id, confirming: undefined })
await accountActions.remove({
integrationID: props.provider,
provider: provider().name,
account,
- final: accounts().length === 1,
+ final,
})
setState("switching", undefined)
+
+ // Removing the last account disconnects the integration, so the dialog is done, as in the TUI.
+ if (final && accounts().length === 0) dialog.close()
+ }
+
+ // A connection that needs a fresh sign-in either has its own link or signs in again.
+ const selectAccount = (account: ProviderAccount) => {
+ const url = account.status?.url
+
+ if (url) return void platform.openExternal(url)
+
+ if (account.status) return addAccount()
+ void activateAccount(account)
}
function AccountsView() {
return (
+
{language.t("dialog.provider.accounts.connected")}
@@ -1246,12 +1396,23 @@ function ProviderConnection(props: {
aria-checked={activeAccount() === account.id}
class="flex min-h-9 min-w-0 flex-1 items-center gap-2 px-3 text-left text-[13px] leading-5 tracking-[-0.04px] focus-visible:outline-none"
disabled={state.switching !== undefined}
- onClick={() => void activateAccount(account)}
+ onClick={() => selectAccount(account)}
>
{account.label}
+
+ {(status) => (
+
+ {language.t("dialog.provider.signInRequired")}
+
+ )}
+
@@ -1288,48 +1449,6 @@ function ProviderConnection(props: {
-
-
- )
- }
-
- function ConsoleIntro() {
- return (
-
-
{language.t("provider.connect.console.intro")}
-
-
-
- {language.t("provider.connect.console.serviceAccount")}
-
-
-
)
}
@@ -1581,14 +1700,16 @@ function ProviderConnection(props: {
-
-
-
{language.t("provider.connect.status.inProgress")}
+
+
+ {language.t("dialog.provider.environmentOnly")}
+
+
@@ -1600,6 +1721,9 @@ function ProviderConnection(props: {
+
+
+
diff --git a/packages/app/src/providers/credentials/dialog.tsx b/packages/app/src/providers/credentials/dialog.tsx
deleted file mode 100644
index cb9fa699c48..00000000000
--- a/packages/app/src/providers/credentials/dialog.tsx
+++ /dev/null
@@ -1,291 +0,0 @@
-import { Button } from "@opencode/ui/button"
-import { useDialog } from "@opencode/ui/context/dialog"
-import { Icon } from "@opencode/ui/icon"
-import { IconButton } from "@opencode/ui/icon-button"
-import { useMutation } from "@tanstack/solid-query"
-import { TextField } from "@opencode/ui/text-field"
-import { showToast } from "@/shell/notifications/toast"
-import { batch, For } from "solid-js"
-import { createStore, produce } from "solid-js/store"
-import { ExternalLink } from "@/runtime/platform/external-link"
-import { useData } from "@/runtime/server/current"
-import { useLanguage } from "@/runtime/i18n/language"
-import { type FormState, headerRow, modelRow, validateCustomProvider } from "./form"
-import { CustomManagedProviderIcon } from "@/providers/models/provider-group"
-
-export function CustomProviderForm(props: { autofocus?: boolean } = {}) {
- const dialog = useDialog()
- const data = useData()
- const language = useLanguage()
-
- const [form, setForm] = createStore
({
- providerID: "",
- name: "",
- baseURL: "",
- apiKey: "",
- models: [modelRow()],
- headers: [headerRow()],
- err: {},
- })
-
- const addModel = () => {
- setForm(
- "models",
- produce((rows) => {
- rows.push(modelRow())
- }),
- )
- }
-
- const removeModel = (index: number) => {
- if (form.models.length <= 1) return
- setForm(
- "models",
- produce((rows) => {
- rows.splice(index, 1)
- }),
- )
- }
-
- const addHeader = () => {
- setForm(
- "headers",
- produce((rows) => {
- rows.push(headerRow())
- }),
- )
- }
-
- const removeHeader = (index: number) => {
- if (form.headers.length <= 1) return
- setForm(
- "headers",
- produce((rows) => {
- rows.splice(index, 1)
- }),
- )
- }
-
- const setField = (key: "providerID" | "name" | "baseURL" | "apiKey", value: string) => {
- setForm(key, value)
-
- if (key === "apiKey") return
- setForm("err", key, undefined)
- }
-
- const setModel = (index: number, key: "id" | "name", value: string) => {
- batch(() => {
- setForm("models", index, key, value)
- setForm("models", index, "err", key, undefined)
- })
- }
-
- const setHeader = (index: number, key: "key" | "value", value: string) => {
- batch(() => {
- setForm("headers", index, key, value)
- setForm("headers", index, "err", key, undefined)
- })
- }
-
- const validate = () => {
- const output = validateCustomProvider({
- form,
- t: language.t,
- // TODO: Restore disabled-provider validation when V2 exposes config reads.
- disabledProviders: [],
- existingProviderIDs: new Set((data.location.provider.list() ?? []).map((provider) => provider.id)),
- })
-
- batch(() => {
- setForm("err", output.err)
- output.models.forEach((err, index) => setForm("models", index, "err", err))
- output.headers.forEach((err, index) => setForm("headers", index, "err", err))
- })
-
- return output.result
- }
-
- const saveMutation = useMutation(() => ({
- mutationFn: async (result: NonNullable>): Promise => {
- // TODO: Restore custom providers when V2 exposes config and arbitrary credential APIs.
- throw new Error(language.t("provider.custom.unavailable"))
- },
- onSuccess: (result) => {
- dialog.close()
- showToast({
- variant: "success",
- icon: "circle-check",
- title: language.t("provider.connect.toast.connected.title", { provider: result.name }),
- description: language.t("provider.connect.toast.connected.description", { provider: result.name }),
- })
- },
- onError: (err) => {
- const message = err instanceof Error ? err.message : String(err)
- showToast({ title: language.t("common.requestFailed"), description: message })
- },
- }))
-
- const save = (e: SubmitEvent) => {
- e.preventDefault()
-
- if (saveMutation.isPending) return
-
- const result = validate()
-
- if (!result) return
- saveMutation.mutate(result)
- }
-
- return (
-
-
-
-
{language.t("provider.custom.title")}
-
-
-
-
- )
-}
diff --git a/packages/app/src/providers/credentials/form.test.ts b/packages/app/src/providers/credentials/form.test.ts
deleted file mode 100644
index c3769b77528..00000000000
--- a/packages/app/src/providers/credentials/form.test.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import { describe, expect, test } from "bun:test"
-import { validateCustomProvider } from "./form"
-
-const t = (key: string) => key
-
-describe("validateCustomProvider", () => {
- test("builds trimmed config payload", () => {
- const result = validateCustomProvider({
- form: {
- providerID: "custom-provider",
- name: " Custom Provider ",
- baseURL: "https://api.example.com ",
- apiKey: " {env: CUSTOM_PROVIDER_KEY} ",
- models: [{ row: "m0", id: " model-a ", name: " Model A ", err: {} }],
- headers: [
- { row: "h0", key: " X-Test ", value: " enabled ", err: {} },
- { row: "h1", key: "", value: "", err: {} },
- ],
- err: {},
- },
- t,
- disabledProviders: [],
- existingProviderIDs: new Set(),
- })
-
- expect(result.result).toEqual({
- providerID: "custom-provider",
- name: "Custom Provider",
- key: undefined,
- config: {
- npm: "@ai-sdk/openai-compatible",
- name: "Custom Provider",
- env: ["CUSTOM_PROVIDER_KEY"],
- options: {
- baseURL: "https://api.example.com",
- headers: {
- "X-Test": "enabled",
- },
- },
- models: {
- "model-a": { name: "Model A" },
- },
- },
- })
- })
-
- test("flags duplicate rows and allows reconnecting disabled providers", () => {
- const result = validateCustomProvider({
- form: {
- providerID: "custom-provider",
- name: "Provider",
- baseURL: "https://api.example.com",
- apiKey: "secret",
- models: [
- { row: "m0", id: "model-a", name: "Model A", err: {} },
- { row: "m1", id: "model-a", name: "Model A 2", err: {} },
- ],
- headers: [
- { row: "h0", key: "Authorization", value: "one", err: {} },
- { row: "h1", key: "authorization", value: "two", err: {} },
- ],
- err: {},
- },
- t,
- disabledProviders: ["custom-provider"],
- existingProviderIDs: new Set(["custom-provider"]),
- })
-
- expect(result.result).toBeUndefined()
- expect(result.err.providerID).toBeUndefined()
- expect(result.models[1]).toEqual({
- id: "provider.custom.error.duplicate",
- name: undefined,
- })
- expect(result.headers[1]).toEqual({
- key: "provider.custom.error.duplicate",
- value: undefined,
- })
- })
-})
diff --git a/packages/app/src/providers/credentials/form.ts b/packages/app/src/providers/credentials/form.ts
deleted file mode 100644
index 2baa6358354..00000000000
--- a/packages/app/src/providers/credentials/form.ts
+++ /dev/null
@@ -1,176 +0,0 @@
-const PROVIDER_ID = /^[a-z0-9][a-z0-9-_]*$/
-
-const OPENAI_COMPATIBLE = "@ai-sdk/openai-compatible"
-
-type Translator = (key: string, vars?: Record) => string
-
-export type ModelErr = {
- id?: string
- name?: string
-}
-
-export type HeaderErr = {
- key?: string
- value?: string
-}
-
-export type ModelRow = {
- row: string
- id: string
- name: string
- err: ModelErr
-}
-
-export type HeaderRow = {
- row: string
- key: string
- value: string
- err: HeaderErr
-}
-
-export type FormState = {
- providerID: string
- name: string
- baseURL: string
- apiKey: string
- models: ModelRow[]
- headers: HeaderRow[]
- err: {
- providerID?: string
- name?: string
- baseURL?: string
- }
-}
-
-type ValidateArgs = {
- form: FormState
- t: Translator
- disabledProviders: string[]
- existingProviderIDs: Set
-}
-
-export function validateCustomProvider(input: ValidateArgs) {
- const providerID = input.form.providerID.trim()
- const name = input.form.name.trim()
- const baseURL = input.form.baseURL.trim()
- const apiKey = input.form.apiKey.trim()
-
- const env = apiKey.match(/^\{env:([^}]+)\}$/)?.[1]?.trim()
- const key = apiKey && !env ? apiKey : undefined
-
- const idError = !providerID
- ? input.t("provider.custom.error.providerID.required")
- : !PROVIDER_ID.test(providerID)
- ? input.t("provider.custom.error.providerID.format")
- : undefined
-
- const nameError = !name ? input.t("provider.custom.error.name.required") : undefined
-
- const urlError = !baseURL
- ? input.t("provider.custom.error.baseURL.required")
- : !/^https?:\/\//.test(baseURL)
- ? input.t("provider.custom.error.baseURL.format")
- : undefined
-
- const disabled = input.disabledProviders.includes(providerID)
-
- const existsError = idError
- ? undefined
- : input.existingProviderIDs.has(providerID) && !disabled
- ? input.t("provider.custom.error.providerID.exists")
- : undefined
-
- const seenModels = new Set()
-
- const models = input.form.models.map((m) => {
- const id = m.id.trim()
-
- const idError = !id
- ? input.t("provider.custom.error.required")
- : seenModels.has(id)
- ? input.t("provider.custom.error.duplicate")
- : (() => {
- seenModels.add(id)
-
- return undefined
- })()
-
- const nameError = !m.name.trim() ? input.t("provider.custom.error.required") : undefined
-
- return { id: idError, name: nameError }
- })
-
- const modelsValid = models.every((m) => !m.id && !m.name)
- const modelConfig = Object.fromEntries(input.form.models.map((m) => [m.id.trim(), { name: m.name.trim() }]))
-
- const seenHeaders = new Set()
-
- const headers = input.form.headers.map((h) => {
- const key = h.key.trim()
- const value = h.value.trim()
-
- if (!key && !value) return {}
-
- const keyError = !key
- ? input.t("provider.custom.error.required")
- : seenHeaders.has(key.toLowerCase())
- ? input.t("provider.custom.error.duplicate")
- : (() => {
- seenHeaders.add(key.toLowerCase())
-
- return undefined
- })()
-
- const valueError = !value ? input.t("provider.custom.error.required") : undefined
-
- return { key: keyError, value: valueError }
- })
-
- const headersValid = headers.every((h) => !h.key && !h.value)
-
- const headerConfig = Object.fromEntries(
- input.form.headers
- .map((h) => ({ key: h.key.trim(), value: h.value.trim() }))
- .filter((h) => !!h.key && !!h.value)
- .map((h) => [h.key, h.value]),
- )
-
- const err = {
- providerID: idError ?? existsError,
- name: nameError,
- baseURL: urlError,
- }
-
- const ok = !idError && !existsError && !nameError && !urlError && modelsValid && headersValid
-
- if (!ok) return { err, models, headers }
-
- return {
- err,
- models,
- headers,
- result: {
- providerID,
- name,
- key,
- config: {
- npm: OPENAI_COMPATIBLE,
- name,
- ...(env ? { env: [env] } : {}),
- options: {
- baseURL,
- ...(Object.keys(headerConfig).length ? { headers: headerConfig } : {}),
- },
- models: modelConfig,
- },
- },
- }
-}
-
-let row = 0
-
-const nextRow = () => `row-${row++}`
-
-export const modelRow = (): ModelRow => ({ row: nextRow(), id: "", name: "", err: {} })
-
-export const headerRow = (): HeaderRow => ({ row: nextRow(), key: "", value: "", err: {} })
diff --git a/packages/app/src/providers/models/select-dialog.stories.tsx b/packages/app/src/providers/models/select-dialog.stories.tsx
index 3701ddc242f..088bcc794a3 100644
--- a/packages/app/src/providers/models/select-dialog.stories.tsx
+++ b/packages/app/src/providers/models/select-dialog.stories.tsx
@@ -65,6 +65,7 @@ function SelectorStory(props: { plan: boolean }) {
chatgptPlan={props.plan}
select={(item) => setCurrent(item.id)}
onManage={() => undefined}
+ onConnect={() => undefined}
onClose={() => undefined}
/>
diff --git a/packages/app/src/providers/models/select-dialog.tsx b/packages/app/src/providers/models/select-dialog.tsx
index 929f4385f35..c293f6ba3cb 100644
--- a/packages/app/src/providers/models/select-dialog.tsx
+++ b/packages/app/src/providers/models/select-dialog.tsx
@@ -51,6 +51,8 @@ const modelKey = (model: ModelItem) => `${model.provider.id}:${model.id}`
const manageKey = "action:manage"
+const connectKey = "action:connect"
+
const sortModelGroups = (a: { category: string; items: ModelItem[] }, b: { category: string; items: ModelItem[] }) => {
const aIndex = popularProviders.indexOf(a.category)
const bIndex = popularProviders.indexOf(b.category)
@@ -259,7 +261,6 @@ type ModelSelectorTrigger = (props: ModelSelectorTriggerProps) => JSX.Element
export function ModelSelectorPopover(props: {
provider?: string
model?: ModelState
- unpaid?: boolean
trigger: ModelSelectorTrigger
onClose?: () => void
}) {
@@ -291,7 +292,7 @@ export function ModelSelectorPopover(props: {
const connect = async () => {
const { DialogConnectProvider } = await import("@/providers/connect/dialog")
- void dialog.show(() =>