mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
feat(accounts): 按账号自动同步上游分组名称与备注
This commit is contained in:
1 parent
a95c9e2631
commit
03aa05fd9f
26 files changed
+433
-162
No files matched your search
@@ -53,6 +53,9 @@
|
||||
v-model:name="form.name"
|
||||
v-model:notes="form.notes"
|
||||
:source="upstreamGroupSource"
|
||||
allow-auto
|
||||
:auto="upstreamGroupSyncEnabled"
|
||||
@update:auto="setUpstreamGroupSync"
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
@@ -63,6 +66,9 @@
|
||||
:placeholder="t('admin.accounts.enterAccountName')"
|
||||
data-tour="account-form-name"
|
||||
/>
|
||||
<p v-if="form.type === 'apikey' && upstreamGroupSyncEnabled" class="input-hint">
|
||||
{{ t('admin.accounts.upstreamBilling.autoSyncGroupHint') }}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">{{ t('admin.accounts.notes') }}</label>
|
||||
@@ -4433,7 +4439,15 @@ const accountCategory = ref<'oauth-based' | 'apikey' | 'bedrock' | 'service_acco
|
||||
const addMethod = ref<AddMethod>('oauth') // For oauth-based: 'oauth' or 'setup-token'
|
||||
const apiKeyBaseUrl = ref('https://api.anthropic.com')
|
||||
const apiKeyValue = ref('')
|
||||
const upstreamGroupSyncEnabled = ref(false)
|
||||
function setUpstreamGroupSync(enabled: boolean) {
|
||||
upstreamGroupSyncEnabled.value = enabled
|
||||
if (enabled) upstreamBillingAutoProbeEnabled.value = true
|
||||
}
|
||||
const upstreamBillingAutoProbeEnabled = ref(true)
|
||||
watch(upstreamBillingAutoProbeEnabled, (enabled) => {
|
||||
if (!enabled) upstreamGroupSyncEnabled.value = false
|
||||
})
|
||||
|
||||
// ── 国产供应商(Kimi / Zhipu / DeepSeek)账号类型、API 协议与端点 ──
|
||||
// 多协议供应商(国产厂商与走通用表单的供应商)的接入模式;OpenCode 用 openCodeAccountMode。
|
||||
@@ -5687,6 +5701,7 @@ const resetForm = () => {
|
||||
apiKeyValue.value = ''
|
||||
upstreamRequestIdHeader.value = ''
|
||||
upstreamBillingAutoProbeEnabled.value = true
|
||||
upstreamGroupSyncEnabled.value = false
|
||||
editQuotaLimit.value = null
|
||||
editQuotaDailyLimit.value = null
|
||||
editQuotaWeeklyLimit.value = null
|
||||
@@ -6285,6 +6300,7 @@ const handleSubmit = async () => {
|
||||
group_ids: form.group_ids,
|
||||
extra: withUpstreamRequestIdHeader(extra),
|
||||
upstream_billing_probe_enabled: upstreamBillingAutoProbeEnabled.value,
|
||||
upstream_billing_group_sync_enabled: upstreamGroupSyncEnabled.value,
|
||||
auto_pause_on_expired: autoPauseOnExpired.value
|
||||
})
|
||||
}
|
||||
@@ -6416,6 +6432,7 @@ const createAccountAndFinish = async (
|
||||
// 上游倍率探测对全部 API-key 平台开放(antigravity upstream 走本 helper);
|
||||
// 非 apikey 类型(bedrock/oauth)不传,后端不动作。
|
||||
upstream_billing_probe_enabled: type === 'apikey' ? upstreamBillingAutoProbeEnabled.value : undefined,
|
||||
upstream_billing_group_sync_enabled: type === 'apikey' ? upstreamGroupSyncEnabled.value : undefined,
|
||||
auto_pause_on_expired: autoPauseOnExpired.value
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,9 +19,15 @@
|
||||
v-model:name="form.name"
|
||||
v-model:notes="form.notes"
|
||||
:source="upstreamGroupSource"
|
||||
:allow-auto="account.type === 'apikey'"
|
||||
:auto="upstreamGroupSyncEnabled"
|
||||
@update:auto="setUpstreamGroupSync"
|
||||
/>
|
||||
</div>
|
||||
<input v-model="form.name" type="text" required class="input" data-tour="edit-account-form-name" />
|
||||
<p v-if="account.type === 'apikey' && upstreamGroupSyncEnabled" class="input-hint">
|
||||
{{ t('admin.accounts.upstreamBilling.autoSyncGroupHint') }}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">{{ t('admin.accounts.notes') }}</label>
|
||||
@@ -4119,6 +4125,11 @@ const autoPause7dDisabled = ref(false)
|
||||
const autoResetCreditEnabled = ref(false)
|
||||
const autoResetCredit5hThreshold = ref(100)
|
||||
const autoResetCredit7dThreshold = ref(100)
|
||||
const upstreamGroupSyncEnabled = ref(false)
|
||||
function setUpstreamGroupSync(enabled: boolean) {
|
||||
upstreamGroupSyncEnabled.value = enabled
|
||||
if (enabled) upstreamBillingAutoProbeEnabled.value = true
|
||||
}
|
||||
const upstreamBillingAutoProbeEnabled = ref(false)
|
||||
const upstreamBillingRateSyncEnabled = ref(false)
|
||||
const mixedScheduling = ref(false) // For antigravity accounts: enable mixed scheduling
|
||||
@@ -4569,6 +4580,7 @@ const handleUpstreamBillingAutoProbeChange = (enabled: boolean) => {
|
||||
upstreamBillingAutoProbeEnabled.value = enabled
|
||||
if (!enabled) {
|
||||
upstreamBillingRateSyncEnabled.value = false
|
||||
upstreamGroupSyncEnabled.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4701,6 +4713,8 @@ const syncFormFromAccount = (newAccount: Account | null) => {
|
||||
autoResetCredit7dThreshold.value =
|
||||
typeof extra?.auto_reset_credit_7d_threshold === 'number' ? extra.auto_reset_credit_7d_threshold * 100 : 100
|
||||
upstreamBillingAutoProbeEnabled.value = extra?.upstream_billing_probe_enabled === true
|
||||
upstreamGroupSyncEnabled.value =
|
||||
upstreamBillingAutoProbeEnabled.value && extra?.upstream_billing_group_sync_enabled === true
|
||||
upstreamBillingRateSyncEnabled.value =
|
||||
upstreamBillingAutoProbeEnabled.value && extra?.upstream_billing_rate_sync_enabled === true
|
||||
|
||||
@@ -5720,6 +5734,9 @@ const handleSubmit = async () => {
|
||||
}
|
||||
updatePayload.auto_pause_on_expired = autoPauseOnExpired.value
|
||||
if (props.account.type === 'apikey') {
|
||||
if (form.name === props.account.name) delete updatePayload.name
|
||||
if (form.notes === (props.account.notes || '')) delete updatePayload.notes
|
||||
updatePayload.upstream_billing_group_sync_enabled = upstreamGroupSyncEnabled.value
|
||||
updatePayload.upstream_billing_probe_enabled = upstreamBillingAutoProbeEnabled.value
|
||||
updatePayload.upstream_billing_rate_sync_enabled = upstreamBillingRateSyncEnabled.value
|
||||
if (upstreamBillingRateSyncEnabled.value) {
|
||||
@@ -6397,6 +6414,7 @@ const handleSubmit = async () => {
|
||||
if (props.account.type === 'apikey') {
|
||||
delete newExtra.upstream_billing_probe_enabled
|
||||
delete newExtra.upstream_billing_rate_sync_enabled
|
||||
delete newExtra.upstream_billing_group_sync_enabled
|
||||
}
|
||||
// Total quota
|
||||
if (editQuotaLimit.value != null && editQuotaLimit.value > 0) {
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
<template>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-xs text-blue-600 hover:underline disabled:cursor-not-allowed disabled:opacity-50 dark:text-blue-400"
|
||||
:disabled="!source || loading"
|
||||
:title="!source ? t('admin.accounts.upstreamBilling.groupCredentials') : undefined"
|
||||
@click="sync"
|
||||
>
|
||||
<Icon name="refresh" size="xs" :class="{ 'animate-spin': loading }" />
|
||||
{{ t('admin.accounts.upstreamBilling.syncGroup') }}
|
||||
</button>
|
||||
<div class="flex flex-wrap items-center gap-x-4 gap-y-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 text-xs text-blue-600 hover:underline disabled:cursor-not-allowed disabled:opacity-50 dark:text-blue-400"
|
||||
:disabled="!source || loading"
|
||||
:title="!source ? t('admin.accounts.upstreamBilling.groupCredentials') : undefined"
|
||||
@click="sync"
|
||||
>
|
||||
<Icon name="refresh" size="xs" :class="{ 'animate-spin': loading }" />
|
||||
{{ t('admin.accounts.upstreamBilling.syncGroup') }}
|
||||
</button>
|
||||
<label v-if="allowAuto" class="inline-flex items-center gap-2 text-xs text-gray-700 dark:text-gray-200"
|
||||
:title="t('admin.accounts.upstreamBilling.autoSyncGroupHint')">
|
||||
{{ t('admin.accounts.upstreamBilling.autoSyncGroup') }}
|
||||
<Toggle v-model="auto" data-testid="upstream-billing-group-sync"
|
||||
:aria-label="t('admin.accounts.upstreamBilling.autoSyncGroup')" />
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -17,9 +25,11 @@ import { useI18n } from 'vue-i18n'
|
||||
import { adminAPI } from '@/api/admin'
|
||||
import type { UpstreamGroupSource } from '@/api/admin/accounts'
|
||||
import Icon from '@/components/icons/Icon.vue'
|
||||
import Toggle from '@/components/common/Toggle.vue'
|
||||
import { useAppStore } from '@/stores/app'
|
||||
|
||||
const props = defineProps<{ source: UpstreamGroupSource | null }>()
|
||||
const props = defineProps<{ source: UpstreamGroupSource | null; allowAuto?: boolean }>()
|
||||
const auto = defineModel<boolean>('auto', { default: false })
|
||||
const name = defineModel<string>('name', { required: true })
|
||||
const notes = defineModel<string>('notes', { required: true })
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -241,6 +241,26 @@ describe('CreateAccountModal OpenAI long-context billing', () => {
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('creates an API key account with group sync only after opt-in', async () => {
|
||||
const wrapper = mountModal()
|
||||
await selectButtonByText(wrapper, 'OpenAI')
|
||||
await selectButtonByText(wrapper, 'API Key')
|
||||
await wrapper.get('[data-tour="account-form-name"]').setValue('local')
|
||||
await wrapper.get('form input[type="password"]').setValue('synthetic-key')
|
||||
const group = wrapper.get('[data-testid="upstream-billing-group-sync"]')
|
||||
const probe = wrapper.get('[data-testid="upstream-billing-auto-probe"]')
|
||||
expect(group.attributes('aria-checked')).toBe('false')
|
||||
await probe.trigger('click')
|
||||
await group.trigger('click')
|
||||
expect(probe.attributes('aria-checked')).toBe('true')
|
||||
await wrapper.get('#create-account-form').trigger('submit.prevent')
|
||||
await flushPromises()
|
||||
expect(createAccountMock.mock.calls[0]?.[0]).toMatchObject({
|
||||
upstream_billing_group_sync_enabled: true, upstream_billing_probe_enabled: true
|
||||
})
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('can create a passthrough account with model filtering enabled', async () => {
|
||||
const wrapper = mountModal()
|
||||
await selectButtonByText(wrapper, 'OpenAI')
|
||||
|
||||
@@ -1361,6 +1361,26 @@ describe('EditAccountModal', () => {
|
||||
expect(updateAccountMock.mock.calls[0]?.[1]?.upstream_billing_probe_enabled).toBe(true)
|
||||
})
|
||||
|
||||
it('opts into group sync independently and clears it when probing stops', async () => {
|
||||
const account = buildAccount()
|
||||
updateAccountMock.mockResolvedValue(account)
|
||||
const wrapper = mountModal(account)
|
||||
const group = wrapper.get('[data-testid="upstream-billing-group-sync"]')
|
||||
const probe = wrapper.get('[data-testid="upstream-billing-auto-probe"]')
|
||||
const rate = wrapper.get('[data-testid="upstream-billing-rate-sync"]')
|
||||
expect(group.attributes('aria-checked')).toBe('false')
|
||||
await group.trigger('click')
|
||||
expect(probe.attributes('aria-checked')).toBe('true')
|
||||
expect(rate.attributes('aria-checked')).toBe('false')
|
||||
await wrapper.get('form').trigger('submit.prevent')
|
||||
expect(updateAccountMock.mock.lastCall?.[1]).toMatchObject({
|
||||
upstream_billing_group_sync_enabled: true, upstream_billing_rate_sync_enabled: false
|
||||
})
|
||||
await probe.trigger('click')
|
||||
expect(group.attributes('aria-checked')).toBe('false')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('enabling rate sync also enables probing and stops submitting a manual rate', async () => {
|
||||
const account = buildAccount()
|
||||
updateAccountMock.mockReset()
|
||||
|
||||
@@ -336,6 +336,8 @@ export default {
|
||||
}
|
||||
},
|
||||
upstreamBilling: {
|
||||
autoSyncGroup: 'Auto-sync upstream group name and notes',
|
||||
autoSyncGroupHint: 'A successful probe replaces the local name and notes with any text the upstream provides. Account rate sync is controlled separately.',
|
||||
syncGroup: 'Sync upstream group name and notes',
|
||||
saveGroup: 'Sync and save upstream group name and notes',
|
||||
groupCredentials: 'Enter the upstream URL and API key. Re-enter the key after changing the URL or proxy.',
|
||||
|
||||
@@ -182,6 +182,8 @@ export default {
|
||||
}
|
||||
},
|
||||
upstreamBilling: {
|
||||
autoSyncGroup: '自动同步上游分组名称与备注',
|
||||
autoSyncGroupHint: '成功探测后,上游提供的名称和描述会覆盖本地名称与备注。账号倍率由单独的开关控制。',
|
||||
syncGroup: '同步上游分组名称与备注',
|
||||
saveGroup: '同步并保存上游分组名称与备注',
|
||||
groupCredentials: '请填写上游地址和 API Key。更换地址或代理后需重新输入密钥。',
|
||||
|
||||
@@ -1284,6 +1284,7 @@ export interface Account {
|
||||
model_rate_limits?: Record<string, { rate_limited_at: string; rate_limit_reset_at: string }>
|
||||
antigravity_credits_overages?: Record<string, { activated_at: string; active_until: string }>
|
||||
upstream_billing_probe_enabled?: boolean
|
||||
upstream_billing_group_sync_enabled?: boolean
|
||||
upstream_billing_rate_sync_enabled?: boolean
|
||||
upstream_billing_probe?: UpstreamBillingProbeSnapshot
|
||||
codex_reset_credit_snapshot?: {
|
||||
@@ -1620,6 +1621,7 @@ export interface CreateAccountRequest {
|
||||
expires_at?: number | null
|
||||
auto_pause_on_expired?: boolean
|
||||
upstream_billing_probe_enabled?: boolean
|
||||
upstream_billing_group_sync_enabled?: boolean
|
||||
confirm_mixed_channel_risk?: boolean
|
||||
}
|
||||
|
||||
@@ -1640,6 +1642,7 @@ export interface UpdateAccountRequest {
|
||||
expires_at?: number | null
|
||||
auto_pause_on_expired?: boolean
|
||||
upstream_billing_probe_enabled?: boolean
|
||||
upstream_billing_group_sync_enabled?: boolean
|
||||
upstream_billing_rate_sync_enabled?: boolean
|
||||
confirm_mixed_channel_risk?: boolean
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user