mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
feat: 支持Gemini-Api接入
This commit is contained in:
@@ -477,6 +477,37 @@
|
||||
<i class="fas fa-check text-xs text-white"></i>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label
|
||||
class="group relative flex cursor-pointer items-center rounded-md border p-2 transition-all"
|
||||
:class="[
|
||||
form.platform === 'gemini-api'
|
||||
? 'border-amber-500 bg-amber-50 dark:border-amber-400 dark:bg-amber-900/30'
|
||||
: 'border-gray-300 bg-white hover:border-amber-400 hover:bg-amber-50/50 dark:border-gray-600 dark:bg-gray-700 dark:hover:border-amber-500 dark:hover:bg-amber-900/20'
|
||||
]"
|
||||
>
|
||||
<input
|
||||
v-model="form.platform"
|
||||
class="sr-only"
|
||||
type="radio"
|
||||
value="gemini-api"
|
||||
/>
|
||||
<div class="flex items-center gap-2">
|
||||
<i class="fas fa-key text-sm text-amber-600 dark:text-amber-400"></i>
|
||||
<div>
|
||||
<span class="block text-xs font-medium text-gray-900 dark:text-gray-100"
|
||||
>Gemini API</span
|
||||
>
|
||||
<span class="text-xs text-gray-500 dark:text-gray-400">API Key</span>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="form.platform === 'gemini-api'"
|
||||
class="absolute right-1 top-1 flex h-4 w-4 items-center justify-center rounded-full bg-amber-500"
|
||||
>
|
||||
<i class="fas fa-check text-xs text-white"></i>
|
||||
</div>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<!-- Droid 子选项 -->
|
||||
@@ -519,7 +550,8 @@
|
||||
form.platform !== 'ccr' &&
|
||||
form.platform !== 'bedrock' &&
|
||||
form.platform !== 'azure_openai' &&
|
||||
form.platform !== 'openai-responses'
|
||||
form.platform !== 'openai-responses' &&
|
||||
form.platform !== 'gemini-api'
|
||||
"
|
||||
>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
@@ -641,8 +673,8 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- 到期时间 - 仅在创建账户时显示,编辑时使用独立的过期时间编辑弹窗 -->
|
||||
<div v-if="!isEdit">
|
||||
<!-- 到期时间 - 仅在创建账户时显示,编辑时使用独立的过期时间编辑弹窗,Gemini API 不需要 -->
|
||||
<div v-if="!isEdit && form.platform !== 'gemini-api'">
|
||||
<label class="mb-2 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
>到期时间 (可选)</label
|
||||
>
|
||||
@@ -1483,6 +1515,63 @@
|
||||
<input v-model.number="form.rateLimitDuration" type="hidden" value="60" />
|
||||
</div>
|
||||
|
||||
<!-- Gemini API 配置 -->
|
||||
<div v-if="form.platform === 'gemini-api' && !isEdit" class="space-y-4">
|
||||
<div>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
>API 基础地址 *</label
|
||||
>
|
||||
<input
|
||||
v-model="form.baseUrl"
|
||||
class="form-input w-full border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:placeholder-gray-400"
|
||||
placeholder="https://generativelanguage.googleapis.com"
|
||||
required
|
||||
type="url"
|
||||
/>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
填写 API 基础地址(可包含路径前缀),系统会自动拼接
|
||||
<code class="rounded bg-gray-100 px-1 dark:bg-gray-600"
|
||||
>/v1beta/models/{model}:generateContent</code
|
||||
>
|
||||
</p>
|
||||
<p class="mt-0.5 text-xs text-gray-400 dark:text-gray-500">
|
||||
官方:
|
||||
<code class="rounded bg-gray-100 px-1 dark:bg-gray-600"
|
||||
>https://generativelanguage.googleapis.com</code
|
||||
>
|
||||
| 上游为 CRS:
|
||||
<code class="rounded bg-gray-100 px-1 dark:bg-gray-600"
|
||||
>https://your-crs.com/gemini</code
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
>API 密钥 *</label
|
||||
>
|
||||
<div class="relative">
|
||||
<input
|
||||
v-model="form.apiKey"
|
||||
class="form-input w-full border-gray-300 pr-10 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:placeholder-gray-400"
|
||||
placeholder="AIzaSy..."
|
||||
required
|
||||
:type="showApiKey ? 'text' : 'password'"
|
||||
/>
|
||||
<button
|
||||
class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-400"
|
||||
type="button"
|
||||
@click="showApiKey = !showApiKey"
|
||||
>
|
||||
<i :class="showApiKey ? 'fas fa-eye-slash' : 'fas fa-eye'" />
|
||||
</button>
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
从 Google AI Studio 获取的 API 密钥
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Claude 订阅类型选择 -->
|
||||
<div v-if="form.platform === 'claude'">
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
@@ -1905,7 +1994,8 @@
|
||||
form.platform !== 'ccr' &&
|
||||
form.platform !== 'bedrock' &&
|
||||
form.platform !== 'azure_openai' &&
|
||||
form.platform !== 'openai-responses'
|
||||
form.platform !== 'openai-responses' &&
|
||||
form.platform !== 'gemini-api'
|
||||
"
|
||||
class="btn btn-primary flex-1 px-6 py-3 font-semibold"
|
||||
:disabled="loading"
|
||||
@@ -2926,6 +3016,59 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Gemini API 特定字段(编辑模式)-->
|
||||
<div v-if="form.platform === 'gemini-api'" class="space-y-4">
|
||||
<div>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
>API 基础地址</label
|
||||
>
|
||||
<input
|
||||
v-model="form.baseUrl"
|
||||
class="form-input w-full border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200"
|
||||
placeholder="https://generativelanguage.googleapis.com"
|
||||
type="url"
|
||||
/>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
填写 API 基础地址(可包含路径前缀),系统会自动拼接
|
||||
<code class="rounded bg-gray-100 px-1 dark:bg-gray-600"
|
||||
>/v1beta/models/{model}:generateContent</code
|
||||
>
|
||||
</p>
|
||||
<p class="mt-0.5 text-xs text-gray-400 dark:text-gray-500">
|
||||
官方:
|
||||
<code class="rounded bg-gray-100 px-1 dark:bg-gray-600"
|
||||
>https://generativelanguage.googleapis.com</code
|
||||
>
|
||||
| 上游为 CRS:
|
||||
<code class="rounded bg-gray-100 px-1 dark:bg-gray-600"
|
||||
>https://your-crs.com/gemini</code
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="mb-3 block text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
>API 密钥</label
|
||||
>
|
||||
<div class="relative">
|
||||
<input
|
||||
v-model="form.apiKey"
|
||||
class="form-input w-full border-gray-300 pr-10 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200"
|
||||
placeholder="留空表示不更新"
|
||||
:type="showApiKey ? 'text' : 'password'"
|
||||
/>
|
||||
<button
|
||||
class="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-400"
|
||||
type="button"
|
||||
@click="showApiKey = !showApiKey"
|
||||
>
|
||||
<i :class="showApiKey ? 'fas fa-eye-slash' : 'fas fa-eye'" />
|
||||
</button>
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">留空表示不更新 API Key</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bedrock 特定字段(编辑模式)-->
|
||||
<div v-if="form.platform === 'bedrock'" class="space-y-4">
|
||||
<div>
|
||||
@@ -3410,7 +3553,7 @@ const determinePlatformGroup = (platform) => {
|
||||
return 'claude'
|
||||
} else if (['openai', 'openai-responses', 'azure_openai'].includes(platform)) {
|
||||
return 'openai'
|
||||
} else if (platform === 'gemini') {
|
||||
} else if (['gemini', 'gemini-api'].includes(platform)) {
|
||||
return 'gemini'
|
||||
} else if (platform === 'droid') {
|
||||
return 'droid'
|
||||
@@ -4333,10 +4476,19 @@ const createAccount = async () => {
|
||||
}
|
||||
// Claude Console、CCR、OpenAI-Responses 等其他平台不需要 Token 验证
|
||||
} else if (form.value.addType === 'apikey') {
|
||||
const apiKeys = parseApiKeysInput(form.value.apiKeysInput)
|
||||
if (apiKeys.length === 0) {
|
||||
errors.value.apiKeys = '请至少填写一个 API Key'
|
||||
hasError = true
|
||||
// Gemini API 使用单个 apiKey 字段
|
||||
if (form.value.platform === 'gemini-api') {
|
||||
if (!form.value.apiKey || form.value.apiKey.trim() === '') {
|
||||
errors.value.apiKey = '请填写 API Key'
|
||||
hasError = true
|
||||
}
|
||||
} else {
|
||||
// 其他平台(如 Droid)使用多 API Key 输入
|
||||
const apiKeys = parseApiKeysInput(form.value.apiKeysInput)
|
||||
if (apiKeys.length === 0) {
|
||||
errors.value.apiKeys = '请至少填写一个 API Key'
|
||||
hasError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4500,6 +4652,14 @@ const createAccount = async () => {
|
||||
data.rateLimitDuration = 60 // 默认值60,不从用户输入获取
|
||||
data.dailyQuota = form.value.dailyQuota || 0
|
||||
data.quotaResetTime = form.value.quotaResetTime || '00:00'
|
||||
} else if (form.value.platform === 'gemini-api') {
|
||||
// Gemini API 账户特定数据
|
||||
data.baseUrl = form.value.baseUrl || 'https://generativelanguage.googleapis.com'
|
||||
data.apiKey = form.value.apiKey
|
||||
data.priority = form.value.priority || 50
|
||||
data.supportedModels = Array.isArray(form.value.supportedModels)
|
||||
? form.value.supportedModels
|
||||
: []
|
||||
} else if (form.value.platform === 'bedrock') {
|
||||
// Bedrock 账户特定数据 - 构造 awsCredentials 对象
|
||||
data.awsCredentials = {
|
||||
@@ -4545,6 +4705,8 @@ const createAccount = async () => {
|
||||
result = await accountsStore.createAzureOpenAIAccount(data)
|
||||
} else if (form.value.platform === 'gemini') {
|
||||
result = await accountsStore.createGeminiAccount(data)
|
||||
} else if (form.value.platform === 'gemini-api') {
|
||||
result = await accountsStore.createGeminiApiAccount(data)
|
||||
} else {
|
||||
throw new Error(`不支持的平台: ${form.value.platform}`)
|
||||
}
|
||||
@@ -4851,6 +5013,19 @@ const updateAccount = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Gemini API 特定更新
|
||||
if (props.account.platform === 'gemini-api') {
|
||||
data.baseUrl = form.value.baseUrl || 'https://generativelanguage.googleapis.com'
|
||||
// 只有当有新的 API Key 时才更新
|
||||
if (form.value.apiKey && form.value.apiKey.trim()) {
|
||||
data.apiKey = form.value.apiKey
|
||||
}
|
||||
data.priority = form.value.priority || 50
|
||||
data.supportedModels = Array.isArray(form.value.supportedModels)
|
||||
? form.value.supportedModels
|
||||
: []
|
||||
}
|
||||
|
||||
if (props.account.platform === 'claude') {
|
||||
await accountsStore.updateClaudeAccount(props.account.id, data)
|
||||
} else if (props.account.platform === 'claude-console') {
|
||||
@@ -4865,6 +5040,8 @@ const updateAccount = async () => {
|
||||
await accountsStore.updateAzureOpenAIAccount(props.account.id, data)
|
||||
} else if (props.account.platform === 'gemini') {
|
||||
await accountsStore.updateGeminiAccount(props.account.id, data)
|
||||
} else if (props.account.platform === 'gemini-api') {
|
||||
await accountsStore.updateGeminiApiAccount(props.account.id, data)
|
||||
} else if (props.account.platform === 'droid') {
|
||||
await accountsStore.updateDroidAccount(props.account.id, data)
|
||||
} else {
|
||||
@@ -4986,6 +5163,10 @@ const filteredGroups = computed(() => {
|
||||
else if (form.value.platform === 'openai-responses') {
|
||||
platformFilter = 'openai'
|
||||
}
|
||||
// Gemini-API 使用 Gemini 分组
|
||||
else if (form.value.platform === 'gemini-api') {
|
||||
platformFilter = 'gemini'
|
||||
}
|
||||
return groups.value.filter((g) => g.platform === platformFilter)
|
||||
})
|
||||
|
||||
@@ -5064,6 +5245,9 @@ watch(
|
||||
} else if (newPlatform === 'openai') {
|
||||
// 切换到 OpenAI 时,使用 OAuth 作为默认方式
|
||||
form.value.addType = 'oauth'
|
||||
} else if (newPlatform === 'gemini-api' || newPlatform === 'azure_openai') {
|
||||
// 切换到 Gemini API 或 Azure OpenAI 时,使用 apikey 模式(直接创建,不需要 OAuth 流程)
|
||||
form.value.addType = 'apikey'
|
||||
}
|
||||
|
||||
// 平台变化时,清空分组选择
|
||||
|
||||
@@ -353,6 +353,7 @@ const platformLabelMap = {
|
||||
openai: 'OpenAI',
|
||||
'openai-responses': 'OpenAI Responses',
|
||||
gemini: 'Gemini',
|
||||
'gemini-api': 'Gemini API',
|
||||
droid: 'Droid'
|
||||
}
|
||||
|
||||
|
||||
@@ -1012,6 +1012,7 @@ const refreshAccounts = async () => {
|
||||
claudeData,
|
||||
claudeConsoleData,
|
||||
geminiData,
|
||||
geminiApiData,
|
||||
openaiData,
|
||||
openaiResponsesData,
|
||||
bedrockData,
|
||||
@@ -1021,6 +1022,7 @@ const refreshAccounts = async () => {
|
||||
apiClient.get('/admin/claude-accounts'),
|
||||
apiClient.get('/admin/claude-console-accounts'),
|
||||
apiClient.get('/admin/gemini-accounts'),
|
||||
apiClient.get('/admin/gemini-api-accounts'),
|
||||
apiClient.get('/admin/openai-accounts'),
|
||||
apiClient.get('/admin/openai-responses-accounts'),
|
||||
apiClient.get('/admin/bedrock-accounts'),
|
||||
@@ -1053,13 +1055,31 @@ const refreshAccounts = async () => {
|
||||
|
||||
localAccounts.value.claude = claudeAccounts
|
||||
|
||||
// 合并 Gemini OAuth 和 Gemini API 账号
|
||||
const geminiAccounts = []
|
||||
|
||||
if (geminiData.success) {
|
||||
localAccounts.value.gemini = (geminiData.data || []).map((account) => ({
|
||||
...account,
|
||||
isDedicated: account.accountType === 'dedicated'
|
||||
}))
|
||||
;(geminiData.data || []).forEach((account) => {
|
||||
geminiAccounts.push({
|
||||
...account,
|
||||
platform: 'gemini',
|
||||
isDedicated: account.accountType === 'dedicated'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (geminiApiData.success) {
|
||||
;(geminiApiData.data || []).forEach((account) => {
|
||||
geminiAccounts.push({
|
||||
...account,
|
||||
platform: 'gemini-api',
|
||||
isDedicated: account.accountType === 'dedicated'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
localAccounts.value.gemini = geminiAccounts
|
||||
|
||||
// 合并 OpenAI 和 OpenAI-Responses 账号
|
||||
const openaiAccounts = []
|
||||
|
||||
@@ -1159,6 +1179,25 @@ onMounted(async () => {
|
||||
|
||||
// 初始化账号数据
|
||||
if (props.accounts) {
|
||||
// 合并 Gemini OAuth 和 Gemini API 账号
|
||||
const geminiAccounts = []
|
||||
if (props.accounts.gemini) {
|
||||
props.accounts.gemini.forEach((account) => {
|
||||
geminiAccounts.push({
|
||||
...account,
|
||||
platform: 'gemini'
|
||||
})
|
||||
})
|
||||
}
|
||||
if (props.accounts.geminiApi) {
|
||||
props.accounts.geminiApi.forEach((account) => {
|
||||
geminiAccounts.push({
|
||||
...account,
|
||||
platform: 'gemini-api'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 合并 OpenAI 和 OpenAI-Responses 账号
|
||||
const openaiAccounts = []
|
||||
if (props.accounts.openai) {
|
||||
@@ -1180,7 +1219,7 @@ onMounted(async () => {
|
||||
|
||||
localAccounts.value = {
|
||||
claude: props.accounts.claude || [],
|
||||
gemini: props.accounts.gemini || [],
|
||||
gemini: geminiAccounts,
|
||||
openai: openaiAccounts,
|
||||
bedrock: props.accounts.bedrock || [],
|
||||
droid: (props.accounts.droid || []).map((account) => ({
|
||||
|
||||
@@ -128,7 +128,9 @@
|
||||
? 'OpenAI 专属账号'
|
||||
: platform === 'droid'
|
||||
? 'Droid 专属账号'
|
||||
: 'OAuth 专属账号'
|
||||
: platform === 'gemini'
|
||||
? 'Gemini OAuth 专属账号'
|
||||
: 'OAuth 专属账号'
|
||||
}}
|
||||
</div>
|
||||
<div
|
||||
@@ -239,6 +241,45 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Gemini-API 账号(仅 Gemini) -->
|
||||
<div v-if="platform === 'gemini' && filteredGeminiApiAccounts.length > 0">
|
||||
<div
|
||||
class="bg-gray-50 px-4 py-2 text-xs font-semibold text-gray-500 dark:bg-gray-700 dark:text-gray-400"
|
||||
>
|
||||
Gemini-API 专属账号
|
||||
</div>
|
||||
<div
|
||||
v-for="account in filteredGeminiApiAccounts"
|
||||
:key="account.id"
|
||||
class="cursor-pointer px-4 py-2 transition-colors hover:bg-gray-50 dark:hover:bg-gray-700"
|
||||
:class="{
|
||||
'bg-blue-50 dark:bg-blue-900/20': modelValue === `api:${account.id}`
|
||||
}"
|
||||
@click="selectAccount(`api:${account.id}`)"
|
||||
>
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<span class="text-gray-700 dark:text-gray-300">{{ account.name }}</span>
|
||||
<span
|
||||
class="ml-2 rounded-full px-2 py-0.5 text-xs"
|
||||
:class="
|
||||
account.isActive === 'true' || account.isActive === true
|
||||
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
|
||||
: account.status === 'rate_limited'
|
||||
? 'bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400'
|
||||
: 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400'
|
||||
"
|
||||
>
|
||||
{{ getAccountStatusText(account) }}
|
||||
</span>
|
||||
</div>
|
||||
<span class="text-xs text-gray-400 dark:text-gray-500">
|
||||
{{ formatDate(account.createdAt) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 无搜索结果 -->
|
||||
<div
|
||||
v-if="searchQuery && !hasResults"
|
||||
@@ -341,6 +382,13 @@ const selectedLabel = computed(() => {
|
||||
return account ? `${account.name} (${getAccountStatusText(account)})` : ''
|
||||
}
|
||||
|
||||
// Gemini-API 账号
|
||||
if (props.modelValue.startsWith('api:')) {
|
||||
const accountId = props.modelValue.substring(4)
|
||||
const account = props.accounts.find((a) => a.id === accountId && a.platform === 'gemini-api')
|
||||
return account ? `${account.name} (${getAccountStatusText(account)})` : ''
|
||||
}
|
||||
|
||||
// OAuth 账号
|
||||
const account = props.accounts.find((a) => a.id === props.modelValue)
|
||||
return account ? `${account.name} (${getAccountStatusText(account)})` : ''
|
||||
@@ -421,10 +469,14 @@ const filteredOAuthAccounts = computed(() => {
|
||||
accounts = sortedAccounts.value.filter((a) => a.platform === 'openai')
|
||||
} else if (props.platform === 'droid') {
|
||||
accounts = sortedAccounts.value.filter((a) => a.platform === 'droid')
|
||||
} else if (props.platform === 'gemini') {
|
||||
// 对于 Gemini,只显示 OAuth 类型的账号(排除 gemini-api)
|
||||
accounts = sortedAccounts.value.filter((a) => a.platform === 'gemini')
|
||||
} else {
|
||||
// 其他平台显示所有非特殊类型的账号
|
||||
accounts = sortedAccounts.value.filter(
|
||||
(a) => !['claude-oauth', 'claude-console', 'openai-responses'].includes(a.platform)
|
||||
(a) =>
|
||||
!['claude-oauth', 'claude-console', 'openai-responses', 'gemini-api'].includes(a.platform)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -464,13 +516,28 @@ const filteredOpenAIResponsesAccounts = computed(() => {
|
||||
return accounts
|
||||
})
|
||||
|
||||
// 过滤的 Gemini-API 账号
|
||||
const filteredGeminiApiAccounts = computed(() => {
|
||||
if (props.platform !== 'gemini') return []
|
||||
|
||||
let accounts = sortedAccounts.value.filter((a) => a.platform === 'gemini-api')
|
||||
|
||||
if (searchQuery.value) {
|
||||
const query = searchQuery.value.toLowerCase()
|
||||
accounts = accounts.filter((account) => account.name.toLowerCase().includes(query))
|
||||
}
|
||||
|
||||
return accounts
|
||||
})
|
||||
|
||||
// 是否有搜索结果
|
||||
const hasResults = computed(() => {
|
||||
return (
|
||||
filteredGroups.value.length > 0 ||
|
||||
filteredOAuthAccounts.value.length > 0 ||
|
||||
filteredConsoleAccounts.value.length > 0 ||
|
||||
filteredOpenAIResponsesAccounts.value.length > 0
|
||||
filteredOpenAIResponsesAccounts.value.length > 0 ||
|
||||
filteredGeminiApiAccounts.value.length > 0
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -374,6 +374,26 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建Gemini API账户
|
||||
const createGeminiApiAccount = async (data) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await apiClient.post('/admin/gemini-api-accounts', data)
|
||||
if (response.success) {
|
||||
await fetchGeminiAccounts()
|
||||
return response.data
|
||||
} else {
|
||||
throw new Error(response.message || '创建Gemini API账户失败')
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.message
|
||||
throw err
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 更新Claude账户
|
||||
const updateClaudeAccount = async (id, data) => {
|
||||
loading.value = true
|
||||
@@ -514,6 +534,26 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 更新Gemini API账户
|
||||
const updateGeminiApiAccount = async (id, data) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await apiClient.put(`/admin/gemini-api-accounts/${id}`, data)
|
||||
if (response.success) {
|
||||
await fetchGeminiAccounts()
|
||||
return response
|
||||
} else {
|
||||
throw new Error(response.message || '更新Gemini API账户失败')
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.message
|
||||
throw err
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 切换账户状态
|
||||
const toggleAccount = async (platform, id) => {
|
||||
loading.value = true
|
||||
@@ -858,6 +898,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
updateDroidAccount,
|
||||
createAzureOpenAIAccount,
|
||||
createOpenAIResponsesAccount,
|
||||
createGeminiApiAccount,
|
||||
updateClaudeAccount,
|
||||
updateClaudeConsoleAccount,
|
||||
updateBedrockAccount,
|
||||
@@ -865,6 +906,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
updateOpenAIAccount,
|
||||
updateAzureOpenAIAccount,
|
||||
updateOpenAIResponsesAccount,
|
||||
updateGeminiApiAccount,
|
||||
toggleAccount,
|
||||
deleteAccount,
|
||||
refreshClaudeToken,
|
||||
|
||||
@@ -572,6 +572,19 @@
|
||||
<span>x{{ getDroidApiKeyCount(account) }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="account.platform === 'gemini-api'"
|
||||
class="flex items-center gap-1.5 rounded-lg border border-amber-200 bg-gradient-to-r from-amber-100 to-yellow-100 px-2.5 py-1 dark:border-amber-700 dark:from-amber-900/20 dark:to-yellow-900/20"
|
||||
>
|
||||
<i class="fas fa-robot text-xs text-amber-700 dark:text-amber-400" />
|
||||
<span class="text-xs font-semibold text-amber-800 dark:text-amber-300"
|
||||
>Gemini-API</span
|
||||
>
|
||||
<span class="mx-1 h-4 w-px bg-amber-300 dark:bg-amber-600" />
|
||||
<span class="text-xs font-medium text-amber-700 dark:text-amber-400"
|
||||
>API Key</span
|
||||
>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="flex items-center gap-1.5 rounded-lg border border-gray-200 bg-gradient-to-r from-gray-100 to-gray-200 px-2.5 py-1"
|
||||
@@ -725,7 +738,8 @@
|
||||
account.platform === 'openai-responses' ||
|
||||
account.platform === 'azure_openai' ||
|
||||
account.platform === 'ccr' ||
|
||||
account.platform === 'droid'
|
||||
account.platform === 'droid' ||
|
||||
account.platform === 'gemini-api'
|
||||
"
|
||||
class="flex items-center gap-2"
|
||||
>
|
||||
@@ -1832,7 +1846,8 @@ const supportedUsagePlatforms = [
|
||||
'openai',
|
||||
'openai-responses',
|
||||
'gemini',
|
||||
'droid'
|
||||
'droid',
|
||||
'gemini-api'
|
||||
]
|
||||
|
||||
// 过期时间编辑弹窗状态
|
||||
@@ -1859,6 +1874,7 @@ const platformOptions = ref([
|
||||
{ value: 'claude', label: 'Claude', icon: 'fa-brain' },
|
||||
{ value: 'claude-console', label: 'Claude Console', icon: 'fa-terminal' },
|
||||
{ value: 'gemini', label: 'Gemini', icon: 'fab fa-google' },
|
||||
{ value: 'gemini-api', label: 'Gemini API', icon: 'fa-key' },
|
||||
{ value: 'openai', label: 'OpenAi', icon: 'fa-openai' },
|
||||
{ value: 'azure_openai', label: 'Azure OpenAI', icon: 'fab fa-microsoft' },
|
||||
{ value: 'bedrock', label: 'Bedrock', icon: 'fab fa-aws' },
|
||||
@@ -2189,7 +2205,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
apiClient.get('/admin/azure-openai-accounts', { params }),
|
||||
apiClient.get('/admin/openai-responses-accounts', { params }),
|
||||
apiClient.get('/admin/ccr-accounts', { params }),
|
||||
apiClient.get('/admin/droid-accounts', { params })
|
||||
apiClient.get('/admin/droid-accounts', { params }),
|
||||
apiClient.get('/admin/gemini-api-accounts', { params })
|
||||
)
|
||||
} else {
|
||||
// 只请求指定平台,其他平台设为null占位
|
||||
@@ -2204,7 +2221,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'claude-console':
|
||||
@@ -2217,7 +2235,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'bedrock':
|
||||
@@ -2230,7 +2249,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'gemini':
|
||||
@@ -2243,7 +2263,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'openai':
|
||||
@@ -2256,7 +2277,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'azure_openai':
|
||||
@@ -2269,7 +2291,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
apiClient.get('/admin/azure-openai-accounts', { params }),
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'openai-responses':
|
||||
@@ -2282,7 +2305,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
apiClient.get('/admin/openai-responses-accounts', { params }),
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'ccr':
|
||||
@@ -2295,7 +2319,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
apiClient.get('/admin/ccr-accounts', { params }),
|
||||
Promise.resolve({ success: true, data: [] }) // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'droid':
|
||||
@@ -2308,7 +2333,22 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }), // azure 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
apiClient.get('/admin/droid-accounts', { params })
|
||||
apiClient.get('/admin/droid-accounts', { params }),
|
||||
Promise.resolve({ success: true, data: [] }) // gemini-api 占位
|
||||
)
|
||||
break
|
||||
case 'gemini-api':
|
||||
requests.push(
|
||||
Promise.resolve({ success: true, data: [] }), // claude 占位
|
||||
Promise.resolve({ success: true, data: [] }), // claude-console 占位
|
||||
Promise.resolve({ success: true, data: [] }), // bedrock 占位
|
||||
Promise.resolve({ success: true, data: [] }), // gemini 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // azure-openai 占位
|
||||
Promise.resolve({ success: true, data: [] }), // openai-responses 占位
|
||||
Promise.resolve({ success: true, data: [] }), // ccr 占位
|
||||
Promise.resolve({ success: true, data: [] }), // droid 占位
|
||||
apiClient.get('/admin/gemini-api-accounts', { params })
|
||||
)
|
||||
break
|
||||
default:
|
||||
@@ -2322,6 +2362,7 @@ const loadAccounts = async (forceReload = false) => {
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] }),
|
||||
Promise.resolve({ success: true, data: [] })
|
||||
)
|
||||
break
|
||||
@@ -2343,7 +2384,8 @@ const loadAccounts = async (forceReload = false) => {
|
||||
azureOpenaiData,
|
||||
openaiResponsesData,
|
||||
ccrData,
|
||||
droidData
|
||||
droidData,
|
||||
geminiApiData
|
||||
] = await Promise.all(requests)
|
||||
|
||||
const allAccounts = []
|
||||
@@ -2449,6 +2491,20 @@ const loadAccounts = async (forceReload = false) => {
|
||||
allAccounts.push(...droidAccounts)
|
||||
}
|
||||
|
||||
// Gemini API 账户
|
||||
if (geminiApiData && geminiApiData.success) {
|
||||
const geminiApiAccounts = (geminiApiData.data || []).map((acc) => {
|
||||
// 计算每个Gemini-API账户绑定的API Key数量
|
||||
// Gemini-API账户使用 api: 前缀
|
||||
const boundApiKeysCount = apiKeys.value.filter(
|
||||
(key) => key.geminiAccountId === `api:${acc.id}`
|
||||
).length
|
||||
// 后端已经包含了groupInfos,直接使用
|
||||
return { ...acc, platform: 'gemini-api', boundApiKeysCount }
|
||||
})
|
||||
allAccounts.push(...geminiApiAccounts)
|
||||
}
|
||||
|
||||
// 根据分组筛选器过滤账户
|
||||
let filteredAccounts = allAccounts
|
||||
if (groupFilter.value !== 'all') {
|
||||
@@ -2788,7 +2844,8 @@ const getBoundApiKeysForAccount = (account) => {
|
||||
key.geminiAccountId === accountId ||
|
||||
key.openaiAccountId === accountId ||
|
||||
key.azureOpenaiAccountId === accountId ||
|
||||
key.openaiAccountId === `responses:${accountId}`
|
||||
key.openaiAccountId === `responses:${accountId}` ||
|
||||
key.geminiAccountId === `api:${accountId}`
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -2813,6 +2870,8 @@ const resolveAccountDeleteEndpoint = (account) => {
|
||||
return `/admin/gemini-accounts/${account.id}`
|
||||
case 'droid':
|
||||
return `/admin/droid-accounts/${account.id}`
|
||||
case 'gemini-api':
|
||||
return `/admin/gemini-api-accounts/${account.id}`
|
||||
default:
|
||||
return null
|
||||
}
|
||||
@@ -2993,6 +3052,8 @@ const resetAccountStatus = async (account) => {
|
||||
endpoint = `/admin/ccr-accounts/${account.id}/reset-status`
|
||||
} else if (account.platform === 'droid') {
|
||||
endpoint = `/admin/droid-accounts/${account.id}/reset-status`
|
||||
} else if (account.platform === 'gemini-api') {
|
||||
endpoint = `/admin/gemini-api-accounts/${account.id}/reset-status`
|
||||
} else {
|
||||
showToast('不支持的账户类型', 'error')
|
||||
account.isResetting = false
|
||||
@@ -3041,6 +3102,8 @@ const toggleSchedulable = async (account) => {
|
||||
endpoint = `/admin/ccr-accounts/${account.id}/toggle-schedulable`
|
||||
} else if (account.platform === 'droid') {
|
||||
endpoint = `/admin/droid-accounts/${account.id}/toggle-schedulable`
|
||||
} else if (account.platform === 'gemini-api') {
|
||||
endpoint = `/admin/gemini-api-accounts/${account.id}/toggle-schedulable`
|
||||
} else {
|
||||
showToast('该账户类型暂不支持调度控制', 'warning')
|
||||
return
|
||||
|
||||
@@ -2287,6 +2287,7 @@ const loadAccounts = async () => {
|
||||
claudeData,
|
||||
claudeConsoleData,
|
||||
geminiData,
|
||||
geminiApiData,
|
||||
openaiData,
|
||||
openaiResponsesData,
|
||||
bedrockData,
|
||||
@@ -2296,6 +2297,7 @@ const loadAccounts = async () => {
|
||||
apiClient.get('/admin/claude-accounts'),
|
||||
apiClient.get('/admin/claude-console-accounts'),
|
||||
apiClient.get('/admin/gemini-accounts'),
|
||||
apiClient.get('/admin/gemini-api-accounts'), // 加载 Gemini-API 账号
|
||||
apiClient.get('/admin/openai-accounts'),
|
||||
apiClient.get('/admin/openai-responses-accounts'), // 加载 OpenAI-Responses 账号
|
||||
apiClient.get('/admin/bedrock-accounts'),
|
||||
@@ -2328,13 +2330,31 @@ const loadAccounts = async () => {
|
||||
|
||||
accounts.value.claude = claudeAccounts
|
||||
|
||||
// 合并 Gemini OAuth 和 Gemini API 账户
|
||||
const geminiAccounts = []
|
||||
|
||||
if (geminiData.success) {
|
||||
accounts.value.gemini = (geminiData.data || []).map((account) => ({
|
||||
...account,
|
||||
isDedicated: account.accountType === 'dedicated'
|
||||
}))
|
||||
;(geminiData.data || []).forEach((account) => {
|
||||
geminiAccounts.push({
|
||||
...account,
|
||||
platform: 'gemini',
|
||||
isDedicated: account.accountType === 'dedicated'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (geminiApiData.success) {
|
||||
;(geminiApiData.data || []).forEach((account) => {
|
||||
geminiAccounts.push({
|
||||
...account,
|
||||
platform: 'gemini-api',
|
||||
isDedicated: account.accountType === 'dedicated'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
accounts.value.gemini = geminiAccounts
|
||||
|
||||
if (openaiData.success) {
|
||||
accounts.value.openai = (openaiData.data || []).map((account) => ({
|
||||
...account,
|
||||
@@ -2501,6 +2521,19 @@ const getBoundAccountName = (accountId) => {
|
||||
return `${claudeAccount.name}`
|
||||
}
|
||||
|
||||
// 处理 api: 前缀的 Gemini-API 账户
|
||||
if (accountId.startsWith('api:')) {
|
||||
const realAccountId = accountId.replace('api:', '')
|
||||
const geminiApiAccount = accounts.value.gemini.find(
|
||||
(acc) => acc.id === realAccountId && acc.platform === 'gemini-api'
|
||||
)
|
||||
if (geminiApiAccount) {
|
||||
return `${geminiApiAccount.name}`
|
||||
}
|
||||
// 如果找不到,返回ID的前8位
|
||||
return `${realAccountId.substring(0, 8)}`
|
||||
}
|
||||
|
||||
// 从Gemini账户列表中查找
|
||||
const geminiAccount = accounts.value.gemini.find((acc) => acc.id === accountId)
|
||||
if (geminiAccount) {
|
||||
@@ -2583,7 +2616,23 @@ const getGeminiBindingInfo = (key) => {
|
||||
if (key.geminiAccountId.startsWith('group:')) {
|
||||
return info
|
||||
}
|
||||
// 检查账户是否存在
|
||||
|
||||
// 处理 api: 前缀的 Gemini-API 账户
|
||||
if (key.geminiAccountId.startsWith('api:')) {
|
||||
const realAccountId = key.geminiAccountId.replace('api:', '')
|
||||
const account = accounts.value.gemini.find(
|
||||
(acc) => acc.id === realAccountId && acc.platform === 'gemini-api'
|
||||
)
|
||||
if (!account) {
|
||||
return `⚠️ ${info} (账户不存在)`
|
||||
}
|
||||
if (account.accountType === 'dedicated') {
|
||||
return `🔒 API专属-${info}`
|
||||
}
|
||||
return `API-${info}`
|
||||
}
|
||||
|
||||
// 检查 Gemini OAuth 账户是否存在
|
||||
const account = accounts.value.gemini.find((acc) => acc.id === key.geminiAccountId)
|
||||
if (!account) {
|
||||
return `⚠️ ${info} (账户不存在)`
|
||||
|
||||
Reference in New Issue
Block a user