Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/custom-endpoint-console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### English

- Console: "Add account" offers a Custom API form — base URL, key, the upstream protocol (OpenAI, Anthropic, Responses or auto), and an optional model list.

### 中文

- 控制台:「添加账号」新增「自定义 API」表单 —— Base URL、密钥、上游协议(OpenAI、Anthropic、Responses 或自动)以及可选的模型列表。
92 changes: 88 additions & 4 deletions frontend/src/components/AddAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const labelKeys: Record<string, string> = {
'minimaxcode-global': 'accountTypeMiniMaxCodeGlobal',
'opencode-go': 'accountTypeOpenCode',
'opencode-zen': 'accountTypeOpenCode',
'custom-api': 'accountTypeCustomAPI',
}

const hintKeys: Record<string, string> = {
Expand All @@ -100,6 +101,7 @@ const hintKeys: Record<string, string> = {
'minimaxcode-global': 'accountTypeMiniMaxCodeGlobalHint',
'opencode-go': 'accountTypeOpenCodeGoHint',
'opencode-zen': 'accountTypeOpenCodeZenHint',
'custom-api': 'accountTypeCustomAPIHint',
}

async function loadProviderOptions(): Promise<ProviderOption[]> {
Expand Down Expand Up @@ -162,6 +164,10 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
const [zhipuOrganization, setZhipuOrganization] = useState('')
const [zhipuProject, setZhipuProject] = useState('')
const [doubaoCookies, setDoubaoCookies] = useState('')
const [customBaseURL, setCustomBaseURL] = useState('')
const [customKey, setCustomKey] = useState('')
const [customProtocol, setCustomProtocol] = useState<'openai' | 'anthropic' | 'responses'>('openai')
const [customModels, setCustomModels] = useState('')
const [phase, setPhase] = useState<Phase>('idle')
const [message, setMessage] = useState('')
const [authUrl, setAuthUrl] = useState('')
Expand Down Expand Up @@ -269,6 +275,10 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
setZhipuOrganization('')
setZhipuProject('')
setDoubaoCookies('')
setCustomBaseURL('')
setCustomKey('')
setCustomProtocol('openai')
setCustomModels('')
setAdvancedOpen(false)
setPhase('idle')
setMessage('')
Expand Down Expand Up @@ -451,6 +461,41 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
}
}

async function runCustom() {
const baseURL = customBaseURL.trim().replace(/\/+$/, '')
if (!baseURL) { setMessage(t('customBaseURLRequired')); return }
if (!activeOption) { setMessage(t('accountTypeHint')); return }
setMessage('')
try {
setPhase('busy')
const options = accountOptions()
const models = customModels
.split(/[\n,]/)
.map((model) => model.trim())
.filter(Boolean)
await importAccount({
format: 'custom-api-v1',
api_key: customKey.trim(),
base_url: baseURL,
protocol: customProtocol,
models,
name: name.trim() || t('accountTypeCustomAPI'),
enabled: true,
provider: activeOption.provider,
region: activeOption.region,
max_inflight: options.max_inflight,
priority: options.priority,
})
setPhase('done')
setMessage(t('wizardAccountReady'))
onAdded()
window.setTimeout(finishAndClose, 700)
} catch (error) {
setPhase('idle')
setMessage(error instanceof Error ? error.message : String(error))
}
}

async function runDoubao() {
const cookie = doubaoCookies.trim()
if (!cookie) { setMessage(t('doubaoCookieRequired')); return }
Expand Down Expand Up @@ -591,6 +636,7 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
const tabPending = (key: TabKey) => busy && tab === key
const isZhipu = activeOption?.provider === 'zhipu'
const isDoubao = activeOption?.provider === 'doubaowork'
const isCustom = activeOption?.provider === 'custom'
const methodOptions = [
activeOption?.descriptor.capabilities?.browser_login !== false
? { value: 'browser' as const, label: t('tabBrowser') }
Expand Down Expand Up @@ -784,7 +830,40 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
</div>
) : null}

{isZhipu || isDoubao ? null : (
{isCustom ? (
<div className="mt-4 flex flex-col gap-4">
<p className="rounded-lg bg-surface-secondary/45 px-3.5 py-3 text-caption leading-5 text-muted">{t('customEndpointLead')}</p>
<FormRow label={t('customBaseURL')}>
<Input value={customBaseURL} onChange={(event) => setCustomBaseURL(event.target.value)} placeholder={t('customBaseURLPh')} aria-label={t('customBaseURL')} disabled={busy} autoFocus />
</FormRow>
<FormRow label={t('customAPIKey')}>
<Input type="password" value={customKey} onChange={(event) => setCustomKey(event.target.value)} placeholder={t('customAPIKeyPh')} aria-label={t('customAPIKey')} disabled={busy} />
</FormRow>
<div className="space-y-2">
<span className="text-body font-medium text-muted">{t('customProtocol')}</span>
<OptionTiles
ariaLabel={t('customProtocol')}
columns={3}
value={customProtocol}
onChange={(next) => { if (!busy) setCustomProtocol(next) }}
options={[
{ value: 'openai', label: t('customProtocolOpenAI'), hint: t('customProtocolOpenAIHint'), disabled: busy },
{ value: 'anthropic', label: t('customProtocolAnthropic'), hint: t('customProtocolAnthropicHint'), disabled: busy },
{ value: 'responses', label: t('customProtocolResponses'), hint: t('customProtocolResponsesHint'), disabled: busy },
]}
/>
</div>
<FormRow label={t('customModels')}>
<TextArea className="min-h-20 font-mono text-caption leading-5" value={customModels} onChange={(event) => setCustomModels(event.target.value)} placeholder={t('customModelsPh')} aria-label={t('customModels')} disabled={busy} />
</FormRow>
<p className="-mt-2 text-caption leading-5 text-muted">{t('customModelsHint')}</p>
{message ? (
<p className="flex items-center gap-2 rounded-lg bg-surface-secondary px-3 py-2 text-caption">{isDone ? <CheckCircle size={14} className="shrink-0 text-success" /> : null}<span className={isDone ? 'font-medium text-foreground' : 'text-muted'}>{message}</span></p>
) : null}
</div>
) : null}

{isZhipu || isDoubao || isCustom ? null : (
<>
<FilterToggle
className="mt-3"
Expand Down Expand Up @@ -931,17 +1010,22 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
{isDone ? <><CheckCircle size={15} />{t('wizardAccountReady')}</> : <><Key size={15} />{t('doubaoImport')}</>}
</Button>
) : null}
{step === 'login' && !isZhipu && !isDoubao && tab === 'browser' ? (
{step === 'login' && isCustom ? (
<Button isPending={phase === 'busy'} onPress={() => void runCustom()} isDisabled={isDone}>
{isDone ? <><CheckCircle size={15} />{t('wizardAccountReady')}</> : <><Key size={15} />{t('customCreate')}</>}
</Button>
) : null}
{step === 'login' && !isZhipu && !isDoubao && !isCustom && tab === 'browser' ? (
<Button isPending={tabPending('browser')} onPress={() => void runBrowser()} isDisabled={isDone}>
{isDone ? <><CheckCircle size={15} />{t('wizardAccountReady')}</> : <><ShieldCheck size={15} />{t('wizardStartBrowser')}</>}
</Button>
) : null}
{step === 'login' && !isZhipu && !isDoubao && tab === 'pat' ? (
{step === 'login' && !isZhipu && !isDoubao && !isCustom && tab === 'pat' ? (
<Button isPending={tabPending('pat')} onPress={() => void runPat()} isDisabled={isDone}>
{isDone ? <><CheckCircle size={15} />{t('patDone')}</> : <><Key size={15} />{t('wizardCreateAndLogin')}</>}
</Button>
) : null}
{step === 'login' && !isZhipu && !isDoubao && tab === 'import' ? (
{step === 'login' && !isZhipu && !isDoubao && !isCustom && tab === 'import' ? (
<Button isPending={tabPending('import')} onPress={() => void runImport()} isDisabled={isDone}>
{isDone ? <><CheckCircle size={15} />{t('accountImported')}</> : <><FileCode size={15} />{t('importCredential')}</>}
</Button>
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/components/CustomMark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type Props = {
size?: number
className?: string
}

// Socket-and-plug mark for the custom endpoint tiles: one endpoint, any
// upstream. Decorative; the provider name sits next to it.
export function CustomMark({ size = 16, className = '' }: Props) {
return (
<svg
width={size}
height={size}
viewBox="0 0 24 24"
className={`block shrink-0 text-foreground ${className}`.trim()}
aria-hidden="true"
>
<g
fill="none"
stroke="currentColor"
strokeWidth="1.8"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M9 3.2v3.4M15 3.2v3.4M7.4 6.6h9.2a2.2 2.2 0 0 1 2.2 2.2v2.6a2.2 2.2 0 0 1-2.2 2.2H7.4a2.2 2.2 0 0 1-2.2-2.2V8.8a2.2 2.2 0 0 1 2.2-2.2Z" />
<path d="M12 13.6v7.2" />
</g>
</svg>
)
}
4 changes: 4 additions & 0 deletions frontend/src/components/ProviderMark.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommandMark } from '@/components/CommandMark'
import { CodeArtsMark } from '@/components/CodeArtsMark'
import { CodexMark } from '@/components/CodexMark'
import { CustomMark } from '@/components/CustomMark'
import { DevinMark } from '@/components/DevinMark'
import { DoubaoworkMark } from '@/components/DoubaoworkMark'
import { KiroMark } from '@/components/KiroMark'
Expand Down Expand Up @@ -65,5 +66,8 @@ export function ProviderMark({ provider, size = 16, className = '' }: Props) {
if (id === 'opencode') {
return <OpenCodeMark size={size} className={className} />
}
if (id === 'custom') {
return <CustomMark size={size} className={className} />
}
return <QoderMark size={size} className={className} />
}
38 changes: 38 additions & 0 deletions frontend/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,25 @@ export const messages: Record<Lang, Dict> = {
accountTypeOpenCodeGoHint: 'Experimental. Paste an OpenCode API key. This account calls the Go subscription gateway.',
accountTypeOpenCodeZen: 'OpenCode Zen',
accountTypeOpenCodeZenHint: 'Experimental. Paste an OpenCode API key. This account calls the Zen pay-as-you-go gateway.',
accountTypeCustomAPI: 'Custom API',
accountTypeCustomAPIHint: 'Any endpoint that speaks OpenAI, Anthropic, or Responses. Paste a base URL and key; calls go straight to it.',
customEndpointLead: 'One account is one endpoint. Enter the API root, not a full /chat/completions path, plus the key it expects. Local servers such as Ollama can leave the key empty.',
customBaseURL: 'Base URL',
customBaseURLPh: 'https://api.example.com/v1',
customBaseURLRequired: 'Base URL is required',
customAPIKey: 'API Key',
customAPIKeyPh: 'sk-…',
customProtocol: 'Upstream protocol',
customProtocolOpenAI: 'OpenAI',
customProtocolOpenAIHint: 'Chat Completions',
customProtocolAnthropic: 'Anthropic',
customProtocolAnthropicHint: 'Messages',
customProtocolResponses: 'Responses',
customProtocolResponsesHint: 'Responses API',
customModels: 'Models (optional)',
customModelsPh: 'gpt-4o, claude-sonnet-4',
customModelsHint: 'When set, this list replaces the endpoint catalog. Separate ids with commas or newlines.',
customCreate: 'Add endpoint',
accountTypeCodexGlobal: 'Codex',
accountTypeCodexGlobalHint: 'OpenAI Codex via Codex CLI OAuth, Sign in with ChatGPT, or an imported credential',
accountTypeZhipuCN: 'Zhipu GLM',
Expand Down Expand Up @@ -2308,6 +2327,25 @@ export const messages: Record<Lang, Dict> = {
accountTypeOpenCodeGoHint: '实验性。粘贴 OpenCode API Key。此账号走 Go 订阅网关。',
accountTypeOpenCodeZen: 'OpenCode Zen',
accountTypeOpenCodeZenHint: '实验性。粘贴 OpenCode API Key。此账号走 Zen 按量网关。',
accountTypeCustomAPI: '自定义 API',
accountTypeCustomAPIHint: '任何 OpenAI / Anthropic / Responses 兼容端点。填写 Base URL 和密钥,请求直连该地址。',
customEndpointLead: '一个账号就是一个端点。填 API 根地址(不要带 /chat/completions 这类完整路径)和它要求的密钥;Ollama 等本地服务可留空。',
customBaseURL: 'Base URL',
customBaseURLPh: 'https://api.example.com/v1',
customBaseURLRequired: '请填写 Base URL',
customAPIKey: 'API Key',
customAPIKeyPh: 'sk-…',
customProtocol: '上游协议',
customProtocolOpenAI: 'OpenAI',
customProtocolOpenAIHint: 'Chat Completions',
customProtocolAnthropic: 'Anthropic',
customProtocolAnthropicHint: 'Messages',
customProtocolResponses: 'Responses',
customProtocolResponsesHint: 'Responses API',
customModels: '模型(可选)',
customModelsPh: 'gpt-4o, claude-sonnet-4',
customModelsHint: '填写后以此列表为准,不再请求 /models;用逗号或换行分隔。',
customCreate: '添加端点',
accountTypeCodexGlobal: 'Codex',
accountTypeCodexGlobalHint: 'OpenAI Codex:Codex CLI OAuth、Sign in with ChatGPT,或导入凭证',
accountTypeZhipuCN: '智谱 GLM',
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export function isOpenCodeProvider(provider?: string) {
return String(provider || '').toLowerCase() === 'opencode'
}

export function isCustomProvider(provider?: string) {
return String(provider || '').toLowerCase() === 'custom'
}

export function isMetaProvider(provider?: string) {
const value = String(provider || '').toLowerCase()
return value === 'meta' || value === 'muse'
Expand All @@ -68,6 +72,7 @@ export function accountProviderFamilyLabel(
if (isDoubaoworkProvider(providerID)) return 'Doubao Work'
if (isMiniMaxCodeProvider(providerID)) return 'MiniMax Code'
if (isOpenCodeProvider(providerID)) return 'OpenCode'
if (isCustomProvider(providerID)) return 'Custom API'
if (isMetaProvider(providerID)) return 'Muse (Meta)'
if (isQoderProvider(providerID)) return 'Qoder'
return provider || t('account')
Expand Down Expand Up @@ -113,6 +118,9 @@ export function accountProviderLabel(
if (isOpenCodeProvider(providerID)) {
return regionID === 'zen' ? t('accountTypeOpenCodeZen') : t('accountTypeOpenCodeGo')
}
if (isCustomProvider(providerID)) {
return t('accountTypeCustomAPI')
}
if (isMetaProvider(providerID)) {
return t('accountTypeMetaGlobal')
}
Expand Down

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions internal/webui/static/assets/AccountsPage-CGNcw8Xy.js

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions internal/webui/static/assets/AccountsPage-Us88hnPK.js

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading