mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-11-23 16:00:40 +00:00
fix(accounts): set API key account names once during import (#770)
Use the optional name from account settings and default unnamed key accounts to 密钥账号. Keep connection fields independent of naming. Co-authored-by: Zyy <zyycn@users.noreply.github.com> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -985,9 +985,7 @@ impl CodexCredentialAdminService {
|
||||
ParsedCodexAuthentication::ApiKey(data) => {
|
||||
let mut prepared = CodexCredentialAdmin.prepare_api_key(
|
||||
account_id,
|
||||
candidate
|
||||
.name
|
||||
.unwrap_or_else(|| "OpenAI API Key".to_owned()),
|
||||
candidate.name.unwrap_or_else(|| "密钥账号".to_owned()),
|
||||
data,
|
||||
)?;
|
||||
prepared.model_access = candidate.model_access;
|
||||
|
||||
@@ -1093,6 +1093,7 @@ async fn api_key_import_export_preserves_target_without_oauth_exchange() {
|
||||
.into_accounts()
|
||||
.pop()
|
||||
.unwrap();
|
||||
assert_eq!(restored.account.name(), "relay");
|
||||
let CodexCredentialData::ApiKey(data) =
|
||||
CodexCredentialCodec::decode_complete(&restored.credential).unwrap()
|
||||
else {
|
||||
@@ -1127,6 +1128,7 @@ async fn messages_api_key_import_export_preserves_protocol_and_rejects_websocket
|
||||
.into_accounts()
|
||||
.pop()
|
||||
.unwrap();
|
||||
assert_eq!(imported.account.name(), "密钥账号");
|
||||
let now = Utc::now();
|
||||
let exported = CodexCredentialAdmin
|
||||
.format_cpr_export(vec![ExportManagedCodexCredential {
|
||||
|
||||
+2
-1
@@ -1708,7 +1708,8 @@ RT-only 使用同一形状,只提交 `refreshToken`。不得把真实 token
|
||||
管理端新建表单留空时省略 `notes`。重新授权不接受 `settings`,凭据刷新保留账号设置
|
||||
|
||||
可选 `name` 与编辑名称使用相同的长度和控制字符约束,仅在单份导入数据解析出一个账号时覆盖名称。
|
||||
省略、`null`、留空或多账号导入均保留导入数据或服务商提供的名称;管理端批量导入不提交 `name`
|
||||
省略、`null`、留空或多账号导入均保留导入数据或服务商提供的名称;管理端批量导入不提交 `name`。
|
||||
API Key 账号未指定名称时默认使用「密钥账号」
|
||||
|
||||
账号列表的每个 item 返回轻量 `groups: [{ id, name, enabled }]`
|
||||
|
||||
|
||||
@@ -139,7 +139,6 @@
|
||||
},
|
||||
"credentials": {
|
||||
"accountName": "Account name",
|
||||
"enterUpstreamName": "Enter the upstream name",
|
||||
"baseUrlHelp": "Enter the API base URL, endpoint paths are appended automatically",
|
||||
"apiPrefix": "API prefix",
|
||||
"apiKeyPlaceholder": "Leave blank to keep the current key",
|
||||
@@ -148,7 +147,6 @@
|
||||
"transportLabel": "Transport",
|
||||
"webSocketHelp": "WS requires upstream support for Responses WebSocket",
|
||||
"messagesTransportHelp": "Messages upstreams use HTTP/SSE",
|
||||
"nameRequired": "Enter an account name",
|
||||
"validation": {
|
||||
"urlLength": "Upstream API URL must not exceed 2,048 characters",
|
||||
"urlFormat": "Enter an HTTP or HTTPS URL without credentials, query parameters, or a fragment",
|
||||
|
||||
@@ -139,7 +139,6 @@
|
||||
},
|
||||
"credentials": {
|
||||
"accountName": "账号名称",
|
||||
"enterUpstreamName": "输入上游名称",
|
||||
"baseUrlHelp": "填写 API 前缀,接口路径会自动追加",
|
||||
"apiPrefix": "API 前缀",
|
||||
"apiKeyPlaceholder": "留空保留当前密钥",
|
||||
@@ -148,7 +147,6 @@
|
||||
"transportLabel": "传输方式",
|
||||
"webSocketHelp": "WS 需要上游支持 Responses WebSocket",
|
||||
"messagesTransportHelp": "Messages 上游使用 HTTP/SSE",
|
||||
"nameRequired": "请输入账号名称",
|
||||
"validation": {
|
||||
"urlLength": "上游 API 地址不能超过 2048 个字符",
|
||||
"urlFormat": "请输入不含认证、查询参数或片段的 HTTP 或 HTTPS 地址",
|
||||
|
||||
@@ -139,7 +139,6 @@
|
||||
},
|
||||
"credentials": {
|
||||
"accountName": "賬號名稱",
|
||||
"enterUpstreamName": "輸入上游名稱",
|
||||
"baseUrlHelp": "填寫 API 前綴,接口路徑會自動追加",
|
||||
"apiPrefix": "API 前綴",
|
||||
"apiKeyPlaceholder": "留空保留當前密鑰",
|
||||
@@ -148,7 +147,6 @@
|
||||
"transportLabel": "傳輸方式",
|
||||
"webSocketHelp": "WS 需要上游支持 Responses WebSocket",
|
||||
"messagesTransportHelp": "Messages 上游使用 HTTP/SSE",
|
||||
"nameRequired": "請輸入賬號名稱",
|
||||
"validation": {
|
||||
"urlLength": "上游 API 地址不能超過 2048 個字符",
|
||||
"urlFormat": "請輸入不含認證、查詢參數或片段的 HTTP 或 HTTPS 地址",
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ZFormItem, ZInput } from '@codex-proxy/ui'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineProps<{ disabled?: boolean, required?: boolean, placeholder?: string }>()
|
||||
const name = defineModel<string>({ required: true })
|
||||
const { t } = useI18n({ useScope: 'global' })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ZFormItem prop="name" :label="t('accounts.credentials.accountName')" :required="required">
|
||||
<ZInput
|
||||
v-model="name"
|
||||
:aria-label="t('accounts.credentials.accountName')"
|
||||
:placeholder="placeholder ?? t('accounts.editor.namePlaceholder')"
|
||||
:disabled="disabled"
|
||||
/>
|
||||
</ZFormItem>
|
||||
</template>
|
||||
@@ -5,7 +5,6 @@ import { ZFormItem, ZInput, ZSwitch, ZTextarea } from '@codex-proxy/ui'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import AccountModelAccessField from '@/components/account/model-access/index.vue'
|
||||
import AccountGroupCheckboxGrid from '@/components/AccountGroupCheckboxGrid.vue'
|
||||
import AccountNameField from './AccountNameField.vue'
|
||||
import AccountProxyField from './AccountProxyField.vue'
|
||||
|
||||
withDefaults(defineProps<{
|
||||
@@ -38,7 +37,14 @@ const selectedGroupIds = defineModel<string[]>('selectedGroupIds', { required: t
|
||||
|
||||
<template>
|
||||
<div class="grid gap-4.5">
|
||||
<AccountNameField v-if="name !== undefined" v-model="name" :disabled="disabled" :placeholder="namePlaceholder" />
|
||||
<ZFormItem v-if="name !== undefined" prop="name" :label="t('accounts.credentials.accountName')">
|
||||
<ZInput
|
||||
v-model="name"
|
||||
:aria-label="t('accounts.credentials.accountName')"
|
||||
:placeholder="namePlaceholder ?? t('accounts.editor.namePlaceholder')"
|
||||
:disabled="disabled"
|
||||
/>
|
||||
</ZFormItem>
|
||||
<slot name="connection" />
|
||||
<AccountModelAccessField v-model="modelAccess" form-prop="modelAccess" :account-id="modelAccountId ?? accountId" :disabled="disabled" :allow-preserve="preserveModelAccess" />
|
||||
<slot name="scheduling">
|
||||
|
||||
@@ -17,7 +17,6 @@ import { useAccountSettingsFormRules } from '../../composables/useAccountSetting
|
||||
import { accountCreateProvider } from '../../utils/accountCreate'
|
||||
import AccountApiKeyFields from '../AccountApiKeyFields.vue'
|
||||
import AccountIdentityCell from '../AccountIdentityCell.vue'
|
||||
import AccountNameField from '../AccountNameField.vue'
|
||||
import AccountImportFields from './AccountImportFields.vue'
|
||||
import AccountOAuthFields from './AccountOAuthFields.vue'
|
||||
import AccountSetupFields from './AccountSetupFields.vue'
|
||||
@@ -186,7 +185,6 @@ async function requestCreate() {
|
||||
@regenerate="emit('generateOauth')"
|
||||
/>
|
||||
<ZForm v-else-if="mode === 'api_key'" ref="formElement" :model="form" :rules="apiKeyRules" scroll-to-error focus-on-error novalidate @submit="requestCreate">
|
||||
<AccountNameField v-model="form.name" required :disabled="busy" :placeholder="t('accounts.credentials.enterUpstreamName')" />
|
||||
<AccountApiKeyFields v-model="form.apiKey" :disabled="busy" />
|
||||
</ZForm>
|
||||
<AccountImportFields
|
||||
|
||||
@@ -2,28 +2,10 @@ import type { FormRules } from '@codex-proxy/ui'
|
||||
import type { ApiKeyAccountForm } from '../utils/upstreamApiKey'
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { accountNameValid } from '../utils/accountName'
|
||||
|
||||
export function useAccountApiKeyFormRules(editing = false) {
|
||||
const { t } = useI18n({ useScope: 'global' })
|
||||
return computed<FormRules<{ apiKey: ApiKeyAccountForm, name: string }>>(() => ({
|
||||
...(!editing
|
||||
? {
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
whitespace: true,
|
||||
trigger: ['blur', 'change'],
|
||||
message: t('accounts.credentials.nameRequired'),
|
||||
},
|
||||
{
|
||||
validator: (_rule: unknown, value: string) => accountNameValid(value),
|
||||
trigger: ['blur', 'change'],
|
||||
message: t('accounts.editor.nameInvalid'),
|
||||
},
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
return computed<FormRules<{ apiKey: ApiKeyAccountForm }>>(() => ({
|
||||
'apiKey.protocol': {
|
||||
required: true,
|
||||
trigger: 'change',
|
||||
|
||||
@@ -76,7 +76,6 @@ export function useAccountOnboarding(options: {
|
||||
data: {
|
||||
provider: 'openai',
|
||||
authentication_kind: 'api_key',
|
||||
name: form.name.trim(),
|
||||
base_url: form.apiKey.base_url.trim(),
|
||||
api_key: form.apiKey.apiKey,
|
||||
protocol: form.apiKey.protocol,
|
||||
|
||||
Reference in New Issue
Block a user