Skip to content
Merged
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
17 changes: 17 additions & 0 deletions changelog/unreleased/doubaowork-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### English

- Add a Doubao Work (豆包工作) provider (`doubaowork`) that turns a Doubao Work subscription into OpenAI-compatible models on the gateway, with per-account model catalogs, quota, and read-only check-in status.
- Add accounts by pasting a web-session Cookie from a logged-in doubao.com session; the server validates it on import. The gateway runs headless, so there is no browser or desktop-client auto-login.
- Chat encodes full history, tool definitions, and structured-output requirements into a single upstream request and streams the reply back as OpenAI deltas; tool-call replies tolerate fenced, extended, and truncated JSON.
- Doubao Work images are not supported on this route (the upload endpoint needs a client-side signature), so image parts are rejected with a clear message rather than silently dropped.
- Check-in status is read-only: it shows whether you checked in today and the streak, but never issues a claim request, because a failed claim consumes that day's reward with no way to recover.
- Risk-control/verification errors are treated as request errors so the gateway does not switch accounts or cool the account on them.

### 中文

- 新增豆包工作(Doubao Work)供应商 `doubaowork`,把豆包工作订阅变成网关上一组 OpenAI 兼容模型,支持按账号的模型目录、额度与只读签到状态。
- 通过粘贴已登录 doubao.com 网页会话的 Cookie 添加账号,服务端在导入时校验。网关跑在无头环境,没有浏览器或客户端自动登录。
- 对话会把完整历史、工具定义和结构化输出要求编码成单条上游请求,并把回复转成 OpenAI 增量流;工具调用回复容忍 Markdown 围栏、前后解释文字和截断 JSON。
- 该路径暂不支持豆包工作图片(上传入口需要前端生成的签名),图片会以明确提示拒绝,而不是被静默丢弃。
- 签到状态只读:显示今天是否已签、连续天数,但绝不发领取请求——领取失败会消耗当天额度且无法补救。
- 风控/验证码错误按请求错误处理,网关不会因此切换账号或冷却账号。
11 changes: 11 additions & 0 deletions frontend/scripts/accountImportDetect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ function run(name: string, fn: () => void) {
}
}

run('format doubaowork-cookie-v1 → doubaowork cn', () => {
const result = detectImportBundle({
format: 'doubaowork-cookie-v1',
cookie: 'sessionid=abc',
})
assert.equal(result.provider, 'doubaowork')
assert.equal(result.format, 'doubaowork-cookie-v1')
assert.equal(result.confidence, 'high')
assert.equal(result.batchImportSupported, false)
})

run('format workbuddy-accounts → workbuddy cn', () => {
const result = detectImportBundle({
format: 'workbuddy-accounts',
Expand Down
Binary file added frontend/src/assets/doubaowork-mark.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 57 additions & 5 deletions frontend/src/components/AddAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const labelKeys: Record<string, string> = {
'qwenwork-cn': 'accountTypeQwenworkCN',
'kimi-cn': 'accountTypeKimiCN',
'codearts-cn-north-4': 'accountTypeCodeArtsCN',
'doubaowork-cn': 'accountTypeDoubaoworkCN',
'kiro-us-east-1': 'accountTypeKiroUS',
'kiro-eu-central-1': 'accountTypeKiroEU',
'meta-global': 'accountTypeMetaGlobal',
Expand All @@ -88,6 +89,7 @@ const hintKeys: Record<string, string> = {
'qwenwork-cn': 'accountTypeQwenworkCNHint',
'kimi-cn': 'accountTypeKimiCNHint',
'codearts-cn-north-4': 'accountTypeCodeArtsCNHint',
'doubaowork-cn': 'accountTypeDoubaoworkCNHint',
'kiro-us-east-1': 'accountTypeKiroUSHint',
'kiro-eu-central-1': 'accountTypeKiroEUHint',
'meta-global': 'accountTypeMetaGlobalHint',
Expand Down Expand Up @@ -154,6 +156,7 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
const [zhipuKey, setZhipuKey] = useState('')
const [zhipuOrganization, setZhipuOrganization] = useState('')
const [zhipuProject, setZhipuProject] = useState('')
const [doubaoCookies, setDoubaoCookies] = useState('')
const [phase, setPhase] = useState<Phase>('idle')
const [message, setMessage] = useState('')
const [authUrl, setAuthUrl] = useState('')
Expand Down Expand Up @@ -270,6 +273,7 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
setZhipuKey('')
setZhipuOrganization('')
setZhipuProject('')
setDoubaoCookies('')
setAdvancedOpen(false)
setPhase('idle')
setMessage('')
Expand Down Expand Up @@ -328,7 +332,7 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
if (busy || !typesReady) return
const option = providerOptions.find((item) => item.id === next)
setAccountType(next)
setTab(option?.provider === 'zhipu' ? 'pat' : 'browser')
setTab(option?.provider === 'zhipu' || option?.provider === 'doubaowork' ? 'pat' : 'browser')
setDropSystemPrompt(option?.provider !== 'trae' && option?.provider !== 'kimi' && option?.provider !== 'codearts')
setMessage('')
setStep('login')
Expand Down Expand Up @@ -455,6 +459,36 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
}
}

async function runDoubao() {
const cookie = doubaoCookies.trim()
if (!cookie) { setMessage(t('doubaoCookieRequired')); return }
if (!activeOption) { setMessage(t('accountTypeHint')); return }
setMessage('')
try {
setPhase('busy')
const options = accountOptions()
await importAccount({
format: 'doubaowork-cookie-v1',
cookie,
name: name.trim() || t('accountTypeDoubaoworkCN'),
enabled: true,
provider: activeOption.provider,
region: activeOption.region,
max_inflight: options.max_inflight,
priority: options.priority,
drop_system_prompt: options.drop_system_prompt,
proxy_url: options.proxy_url,
})
setPhase('done')
setMessage(t('wizardAccountReady'))
onAdded()
window.setTimeout(finishAndClose, 900)
} catch (error) {
setPhase('idle')
setMessage(error instanceof Error ? error.message : String(error))
}
}

async function runImport() {
setMessage('')
let bundle: any
Expand Down Expand Up @@ -570,6 +604,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 methodOptions = [
activeOption?.descriptor.capabilities?.browser_login !== false
? { value: 'browser' as const, label: t('tabBrowser') }
Expand Down Expand Up @@ -773,7 +808,19 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
</div>
) : null}

{isZhipu ? null : (
{isDoubao ? (
<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('doubaoCookieLead')}</p>
<FormRow label={t('doubaoCookieLabel')}>
<TextArea className="min-h-28 font-mono text-caption leading-5" value={doubaoCookies} onChange={(event) => setDoubaoCookies(event.target.value)} placeholder={t('doubaoCookiePh')} aria-label={t('doubaoCookieLabel')} disabled={busy} />
</FormRow>
{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 ? null : (
<>
<FilterToggle
className="mt-3"
Expand Down Expand Up @@ -915,17 +962,22 @@ export function AddAccountModal({ isOpen, onClose, onAdded }: Props) {
{isDone ? <><CheckCircle size={15} />{t('wizardAccountReady')}</> : <><Key size={15} />{t('zhipuCreate')}</>}
</Button>
) : null}
{step === 'login' && !isZhipu && tab === 'browser' ? (
{step === 'login' && isDoubao ? (
<Button isPending={phase === 'busy'} onPress={() => void runDoubao()} isDisabled={isDone}>
{isDone ? <><CheckCircle size={15} />{t('wizardAccountReady')}</> : <><Key size={15} />{t('doubaoImport')}</>}
</Button>
) : null}
{step === 'login' && !isZhipu && !isDoubao && 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 && tab === 'pat' ? (
{step === 'login' && !isZhipu && !isDoubao && 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 && tab === 'import' ? (
{step === 'login' && !isZhipu && !isDoubao && 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
20 changes: 20 additions & 0 deletions frontend/src/components/DoubaoworkMark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import doubaoworkMark from '@/assets/doubaowork-mark.webp'

type Props = {
size?: number
className?: string
}

// Doubao Work mark: the official Doubao Work logo raster.
export function DoubaoworkMark({ size = 16, className = '' }: Props) {
return (
<img
src={doubaoworkMark}
alt=""
width={size}
height={size}
className={`block shrink-0 ${className}`.trim()}
draggable={false}
/>
)
}
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 { CodexMark } from '@/components/CodexMark'
import { DevinMark } from '@/components/DevinMark'
import { DoubaoworkMark } from '@/components/DoubaoworkMark'
import { KiroMark } from '@/components/KiroMark'
import { KimiMark } from '@/components/KimiMark'
import { MuseMark } from '@/components/MuseMark'
Expand Down Expand Up @@ -49,5 +50,8 @@ export function ProviderMark({ provider, size = 16, className = '' }: Props) {
if (id === 'meta' || id === 'muse') {
return <MuseMark size={size} className={className} />
}
if (id === 'doubaowork') {
return <DoubaoworkMark size={size} className={className} />
}
return <QoderMark size={size} className={className} />
}
26 changes: 21 additions & 5 deletions frontend/src/components/account/AccountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,21 @@ export function AccountCard({

{authPanelOpen && account.enabled ? (
<section ref={authRef} className="grid gap-3 bg-surface-secondary/55 px-3 py-3">
{account.provider === 'doubaowork' ? (
<div>
<div className="text-caption font-medium text-muted">{t('doubaoCookieLabel')}</div>
<p className="mt-1.5 text-caption leading-5 text-muted">{t('doubaoCookieLead')}</p>
<div className="mt-2.5 flex flex-col gap-2 sm:flex-row">
<TextField className="flex-1" type="password" value={pat} onChange={onPatChange}>
<Label className="sr-only">{t('doubaoCookieLabel')}</Label>
<Input placeholder={t('doubaoCookiePh')} aria-label={t('doubaoCookieLabel')} />
</TextField>
<Button size="sm" variant="secondary" isPending={busyKind === 'pat'} onPress={onPatLogin}><Key size={14} />{t('doubaoSaveCookie')}</Button>
</div>
{note ? <p className="mt-1 text-caption text-muted">{note}</p> : null}
</div>
) : (
<>
<div>
<div className="text-caption font-medium text-muted">{t('oauthDeviceFlow')}</div>
<p className="mt-1.5 text-caption leading-5 text-muted">{account.provider === 'codex' ? t('wizardCodexBrowserLead') : t('qoderLoginHint')}</p>
Expand Down Expand Up @@ -446,19 +461,20 @@ export function AccountCard({
{note ? <p className="mt-1 text-muted">{note}</p> : null}
</div>
) : null}
</>
)}
</section>
) : null}

{onCheckin ? (
<div className="flex items-start justify-between gap-3 border-t border-separator px-4 py-2 text-caption text-muted">
<div className="flex items-start justify-between gap-2 border-t border-separator px-4 py-2 text-caption text-muted">
<Tooltip>
<Tooltip.Trigger>
<span className="flex cursor-help flex-wrap items-center gap-2">
<span className="font-medium">{t('lastCheckin')}</span>
<span className={checkinStatus === 'error' ? 'text-danger' : ''}>{t(checkinLabel)}</span>
{!checkedInCurrentDay ? (
<span className="inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-warning/15 px-1.5 py-px text-caption font-medium text-warning">
<span className="size-1.5 rounded-full bg-warning" aria-hidden />
<span className="whitespace-nowrap rounded-full bg-warning/15 px-1.5 py-px font-medium text-warning">
{t('checkinPending')}
</span>
) : null}
Expand All @@ -468,7 +484,7 @@ export function AccountCard({
</Tooltip>
<Tooltip>
<Tooltip.Trigger>
<span className="flex cursor-help items-center gap-1.5">
<span className="flex shrink-0 cursor-help items-center gap-1.5 whitespace-nowrap">
<span className="font-medium">{t('autoCheckin')}</span>
<span className="mono text-caption text-foreground/55">{account.checkin_time || checkinDefaultTime}</span>
<CompactSwitch isSelected={Boolean(account.auto_checkin)} isDisabled={Boolean(busyKind)} ariaLabel={t('autoCheckin')} onChange={(selected) => onToggleAutoCheckin?.(selected)} />
Expand All @@ -479,7 +495,7 @@ export function AccountCard({
</div>
) : null}

<Card.Footer className="flex flex-wrap items-center gap-1.5 bg-surface-secondary px-4 py-2">
<Card.Footer className="flex flex-wrap items-center gap-1 bg-surface-secondary px-2 py-2">
{onRefresh ? (
<Tooltip>
<Tooltip.Trigger>
Expand Down
20 changes: 18 additions & 2 deletions frontend/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const messages: Record<Lang, Dict> = {
routesHint: 'OpenAI / Anthropic-compatible routes',
clientConfig: 'Client configuration',
clientConfigHint: 'Use the same console key as Bearer token',
providerPrefixHint: 'Pin a provider with a qoder/, workbuddy/, trae/, devin/, command/, codex/, zhipu/, qwenwork/, kimi/, codearts/, kiro/, or meta/ model prefix. A named API key can also limit which providers are listed and routed. Bare IDs follow the cross-provider pool setting on System.',
providerPrefixHint: 'Pin a provider with a qoder/, workbuddy/, trae/, devin/, command/, codex/, zhipu/, qwenwork/, kimi/, codearts/, kiro/, meta/, or doubaowork/ model prefix. A named API key can also limit which providers are listed and routed. Bare IDs follow the cross-provider pool setting on System.',
authentication: 'Authentication',
curlExample: 'curl example',
quickTestHint: 'Send a real request through the selected account',
Expand Down Expand Up @@ -819,6 +819,14 @@ export const messages: Record<Lang, Dict> = {
accountTypeKimiCNHint: 'Kimi Code China subscription via device-code sign-in against auth.kimi.com. Uses the same OAuth client as the official CLI, so the login you already completed with Kimi Code can be pasted in as its credential JSON.',
accountTypeCodeArtsCN: 'CodeArts (码道)',
accountTypeCodeArtsCNHint: 'Huawei Cloud CodeArts Agent via OAuth PKCE against codearts.huaweicloud.com. The console opens the authorization page; a pasted 127.0.0.1 callback URL also completes the login when the browser cannot reach this host.',
accountTypeDoubaoworkCN: 'Doubao Work (豆包工作)',
accountTypeDoubaoworkCNHint: 'Doubao Work subscription via a pasted web-session Cookie. Copy the Cookie from a logged-in doubao.com session in your own browser; the server validates it on import. There is no browser or client auto-login because the gateway runs headless.',
doubaoCookieLead: 'Log in to www.doubao.com in your browser, open developer tools → Network, refresh, open any doubao.com request, and copy the full Cookie request header. Paste it below; the account is validated and created immediately.',
doubaoCookieLabel: 'Cookie',
doubaoCookiePh: 'sessionid=...; sessionid_ss=...',
doubaoCookieRequired: 'Paste the Doubao Work Cookie first.',
doubaoImport: 'Add Doubao Work account',
doubaoSaveCookie: 'Save Cookie',
accountTypeKiroUS: 'Kiro (US East)',
accountTypeKiroUSHint: 'Personal Kiro login. Paste a Builder ID, Identity Center, or social credential JSON, or a ksk_ key. Chat goes to the Kiro runtime in us-east-1. Experimental.',
accountTypeKiroEU: 'Kiro (EU Central)',
Expand Down Expand Up @@ -1009,7 +1017,7 @@ export const messages: Record<Lang, Dict> = {
routesHint: 'OpenAI / Anthropic 兼容端点',
clientConfig: '客户端配置',
clientConfigHint: '使用与控制台相同的密钥作为 Bearer Token',
providerPrefixHint: '用 qoder/、workbuddy/、trae/、devin/、command/、codex/、zhipu/、qwenwork/、kimi/、codearts/、kiro/ 或 meta/ 前缀指定供应商。客户端 API 密钥也可以限制可见和可调度的供应商。不带前缀时是否跨供应商,由系统设置里的模型池决定。',
providerPrefixHint: '用 qoder/、workbuddy/、trae/、devin/、command/、codex/、zhipu/、qwenwork/、kimi/、codearts/、kiro/、meta/ 或 doubaowork/ 前缀指定供应商。客户端 API 密钥也可以限制可见和可调度的供应商。不带前缀时是否跨供应商,由系统设置里的模型池决定。',
authentication: '认证方式',
curlExample: 'curl 示例',
quickTestHint: '通过所选账号发送一条真实请求',
Expand Down Expand Up @@ -1815,6 +1823,14 @@ export const messages: Record<Lang, Dict> = {
accountTypeKimiCNHint: 'Kimi Code 中国区订阅,走 auth.kimi.com 的设备码授权,与官方 CLI 使用同一个 OAuth 客户端。已在本机登录 Kimi Code 的,可直接粘贴它的凭证 JSON 导入。',
accountTypeCodeArtsCN: 'CodeArts(码道)',
accountTypeCodeArtsCNHint: '华为云码道,走 codearts.huaweicloud.com 的 OAuth PKCE 授权。控制台打开授权页;浏览器回不到本机时,也可以粘贴 127.0.0.1 回调地址完成登录。',
accountTypeDoubaoworkCN: '豆包工作(Doubao Work)',
accountTypeDoubaoworkCNHint: '豆包工作订阅,通过粘贴网页会话 Cookie 接入。在你自己的浏览器登录 www.doubao.com 后复制 Cookie,服务端在导入时验证。网关跑在无头环境,没有浏览器或客户端自动登录。',
doubaoCookieLead: '在你自己的浏览器登录 www.doubao.com,打开开发者工具 → Network,刷新页面,点开任意 doubao.com 请求,复制完整的 Cookie 请求头粘贴到下面。导入时会即时校验并创建账号。',
doubaoCookieLabel: 'Cookie',
doubaoCookiePh: 'sessionid=...; sessionid_ss=...',
doubaoCookieRequired: '请先粘贴豆包工作的 Cookie。',
doubaoImport: '添加豆包工作账号',
doubaoSaveCookie: '保存 Cookie',
accountTypeKiroUS: 'Kiro(美东)',
accountTypeKiroUSHint: '个人 Kiro 登录。粘贴 Builder ID、Identity Center 或社交登录的凭证 JSON,也可以粘贴 ksk_ 密钥。聊天走 us-east-1 的 Kiro 运行时。实验性接入。',
accountTypeKiroEU: 'Kiro(欧洲中部)',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/accountImportDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const FORMAT_TO_PROVIDER: Record<string, string> = {
'meta-oauth-v1': 'meta',
'meta-key-v1': 'meta',
'kiro-oauth-v1': 'kiro',
'doubaowork-cookie-v1': 'doubaowork',
}

const CN_DOMAIN_MARKERS = ['codebuddy.cn', 'workbuddy.cn']
Expand Down
Loading
Loading