(`${resource}/authorization`, {
method: 'PUT',
body: JSON.stringify({
attempt_id: challenge.attempt_id,
@@ -262,12 +288,11 @@ export function GeminiEnvironments({
onSettled: () => client.invalidateQueries({ queryKey: QUERY_KEY }),
})
- if (inventory.isPending && view === 'import')
+ if (inventory.isPending)
return 正在检测 Gemini 宿主机服务…
- if (inventory.isError && view === 'import')
- return 读取 Gemini 环境失败。
+ if (inventory.isError) return 读取 Gemini 环境失败。
if (!inventory.data?.available)
- return view === 'vm' ? null : (
+ return (
此宿主机尚未启用 Gemini。请先在宿主运行{' '}
deploy/install.sh prepare-gemini,再刷新面板。
@@ -275,30 +300,22 @@ export function GeminiEnvironments({
)
const payloadState = inventory.data.payload_state
const canInstall = payloadState !== 'not_configured'
+ const selectedId = environmentId || createdId
+ const environment = inventory.data.environments.find(
+ (item) => item.id === selectedId
+ )
return (
-
- {view === 'vm' ? (
-
-
Gemini 宿主环境
-
- 导入 Gemini
-
-
+
+ {isImport ? (
+
+ 在宿主机创建环境,不创建虚拟机。必须绑定 IPv4 SOCKS5 代理。已有账号在{' '}
+
+ 虚拟机
+ {' '}
+ 管理。
+
) : null}
-
- 在宿主机创建环境,不创建虚拟机。支持 Google 授权和 Gemini API
- Key,必须绑定 IPv4 SOCKS5 代理。
-
{payloadState === 'install_on_create' ? (
首次创建时自动校验并安装 Gemini 内核和官方 CLI。
) : null}
@@ -308,7 +325,7 @@ export function GeminiEnvironments({
{payloadState === 'invalid' ? (
Gemini 载荷校验失败,请检查安装源及宿主服务日志。
) : null}
- {view === 'import' ? (
+ {isImport ? (
- ) : !inventory.data.environments.length ? (
- 尚无 Gemini 环境。
+ ) : !environment ? (
+
+ Gemini 环境已删除或不可用。
+
) : null}
{operation.isError ? (
{operation.error.message}
) : null}
- {inventory.data.environments.map((environment) => (
-
- {environment.name}
-
- {environment.auth_method === 'api_key' ? 'API Key' : 'Google OAuth'}{' '}
- · 代理 {environment.proxy_id} ·{' '}
- {AUTH_LABELS[environment.auth_state]} ·{' '}
- {environment.runtime_ready ? '运行就绪' : '运行未就绪'} ·{' '}
- {environment.billing_ready ? '计费可用' : '官方计费未核实'}
-
+ {environment ? (
+
+ {isImport ? (
+
{environment.name}
+ ) : null}
{environment.auth_method !== 'api_key' ? (
@@ -522,8 +533,8 @@ export function GeminiEnvironments({
) : null}
-
- ))}
+
+ ) : null}
)
}
diff --git a/web/src/features/import/index.tsx b/web/src/features/import/index.tsx
index 5df4e0b3a..39568d493 100644
--- a/web/src/features/import/index.tsx
+++ b/web/src/features/import/index.tsx
@@ -1,5 +1,6 @@
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
+import { useSearch } from '@tanstack/react-router'
import { VIEW_TITLES } from '@/config/nav'
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import { PageHeader } from '@/components/page-header'
@@ -15,9 +16,18 @@ export function ImportPage() {
const dash = useQuery(dashboardQueryOptions())
const me = useQuery(meQueryOptions())
const isAdmin = me.data?.role === 'admin'
- const [tab, setTab] = useState(() =>
- window.location.hash === '#gemini' ? 'gemini' : 'onboard'
- )
+ const requested = useSearch({
+ from: '/_authenticated/import',
+ select: (search) => search.tab,
+ })
+ const [selected, setSelected] = useState<{
+ requested?: string
+ tab: string
+ }>()
+ const tab =
+ selected && selected.requested === requested
+ ? selected.tab
+ : requested || 'onboard'
return (
setSelected({ requested, tab })}
className='max-w-6xl gap-6'
>
diff --git a/web/src/features/keys/index.tsx b/web/src/features/keys/index.tsx
index 3b14696fc..dc228a94d 100644
--- a/web/src/features/keys/index.tsx
+++ b/web/src/features/keys/index.tsx
@@ -474,6 +474,7 @@ function KeyRow({
}
function scopeText(item: ApiKeyItem): string {
+ if (item.group_type === 'gemini') return 'Gemini · CRAGAnti'
if (item.vm_pool_id) return `账号池 · ${item.vm_pool_name || item.vm_pool_id}`
if (item.group_type === 'anthropic')
return `Anthropic · ${item.allowed_vms?.length || 0} 台`
diff --git a/web/src/features/keys/key-limits-dialog.tsx b/web/src/features/keys/key-limits-dialog.tsx
index 08e6b516c..7c0a4b9cc 100644
--- a/web/src/features/keys/key-limits-dialog.tsx
+++ b/web/src/features/keys/key-limits-dialog.tsx
@@ -160,7 +160,9 @@ export function KeyLimitsDialog({
!(legacyApi && !draft.api_endpoint_id)
: draft.group_type === 'pool'
? !draft.vm_pool_id
- : draft.group_type !== 'all' && draft.allowed_vms.length === 0
+ : draft.group_type !== 'all' &&
+ draft.group_type !== 'gemini' &&
+ draft.allowed_vms.length === 0
return (
) : null}
{!isApi || (legacyApi && !draft.api_endpoint_id) ? (
-
+
@@ -394,6 +403,11 @@ export function KeyLimitsDialog({
+ ) : draft.group_type === 'gemini' ? (
+
+ 仅用于 Gemini 宿主机 OAuth,不使用 VM
+ 或直连渠道。当前载荷尚不支持 Google OAuth 推理。
+
) : draft.group_type === 'all' ? (
all 是最高权限,不再选择 VM。
@@ -497,7 +511,8 @@ function blankDraft(): KeyLimitsDraft {
}
function groupOf(value: string | undefined): KeyGroupType {
- if (value === 'anthropic' || value === 'openai') return value
+ if (value === 'anthropic' || value === 'openai' || value === 'gemini')
+ return value
return 'all'
}
diff --git a/web/src/features/keys/key-payload.test.ts b/web/src/features/keys/key-payload.test.ts
index 1e563231c..a8b671236 100644
--- a/web/src/features/keys/key-payload.test.ts
+++ b/web/src/features/keys/key-payload.test.ts
@@ -19,6 +19,28 @@ const draft: KeyLimitsDraft = {
}
describe('API key limit payload', () => {
+ it('saves Gemini as admin-only OAuth without a VM scope', () => {
+ const gemini = {
+ ...draft,
+ category: 'oauth',
+ group_type: 'gemini',
+ vm_pool_id: '',
+ } as const
+ for (const mode of ['create', 'edit'] as const) {
+ expect(keyLimitsPayload(gemini, mode)).toMatchObject({
+ group_type: 'gemini',
+ category: 'oauth',
+ allowed_vms: [],
+ vm_pool_id: null,
+ })
+ }
+ expect(() =>
+ keyLimitsPayload(gemini, 'create', { isAdmin: false })
+ ).toThrow('只允许管理员')
+ expect(() =>
+ keyLimitsPayload({ ...gemini, category: 'api' }, 'create')
+ ).toThrow('宿主机 OAuth')
+ })
it('keeps request and USD quotas separate', () => {
expect(keyLimitsPayload(draft, 'create')).toEqual({
name: 'ops',
diff --git a/web/src/features/keys/key-payload.ts b/web/src/features/keys/key-payload.ts
index fc9a5a00c..746485902 100644
--- a/web/src/features/keys/key-payload.ts
+++ b/web/src/features/keys/key-payload.ts
@@ -1,4 +1,4 @@
-export type KeyGroupType = 'all' | 'anthropic' | 'openai' | 'pool'
+export type KeyGroupType = 'all' | 'anthropic' | 'openai' | 'gemini' | 'pool'
export const KEY_ALLOWED_MODELS_MAX = 200
@@ -37,7 +37,8 @@ export function parseModelList(text: string): string[] {
}
function groupTypeOf(value: string): KeyGroupType {
- if (value === 'anthropic' || value === 'openai') return value
+ if (value === 'anthropic' || value === 'openai' || value === 'gemini')
+ return value
return 'all'
}
@@ -56,6 +57,9 @@ export function keyLimitsPayload(
rpm: nonNegative(draft.rpm, 'RPM'),
}
const isApi = draft.category === 'api'
+ if (draft.group_type === 'gemini' && (!isAdmin || isApi)) {
+ throw new Error('Gemini 平台只允许管理员创建宿主机 OAuth 密钥')
+ }
// API 直连不经过槽位,只有管理员可以设置
if (isAdmin) body.category = draft.category
if (isAdmin && isApi && draft.api_endpoint_id !== undefined) {
@@ -72,10 +76,15 @@ export function keyLimitsPayload(
} else {
const group_type = groupTypeOf(draft.group_type)
const allowed_vms =
- group_type === 'all'
+ group_type === 'all' || group_type === 'gemini'
? []
: [...new Set(draft.allowed_vms.map((id) => id.trim()).filter(Boolean))]
- if (!isApi && group_type !== 'all' && allowed_vms.length === 0) {
+ if (
+ !isApi &&
+ group_type !== 'all' &&
+ group_type !== 'gemini' &&
+ allowed_vms.length === 0
+ ) {
throw new Error('至少选择一台 VM')
}
body.group_type = group_type
diff --git a/web/src/features/keys/key-stats-dialog.tsx b/web/src/features/keys/key-stats-dialog.tsx
index c242393e2..286c8457f 100644
--- a/web/src/features/keys/key-stats-dialog.tsx
+++ b/web/src/features/keys/key-stats-dialog.tsx
@@ -84,7 +84,9 @@ function StatsBody({ item, vms }: { item: ApiKeyItem; vms: Vm[] }) {
? 'Anthropic'
: item.group_type === 'openai'
? 'OpenAI'
- : '全局'}
+ : item.group_type === 'gemini'
+ ? 'Gemini'
+ : '全局'}
{' · '}近 {usage?.days ?? 30} 天 · 官方价