diff --git a/src/locales/en-US/apikeys.ts b/src/locales/en-US/apikeys.ts index c70c703c..528689dc 100644 --- a/src/locales/en-US/apikeys.ts +++ b/src/locales/en-US/apikeys.ts @@ -19,7 +19,9 @@ export default { 'apikeys.models.selected': 'Allowed models', 'apikeys.models.noModelsFound': 'No models found', 'apikeys.accessScope.all': 'All', - 'apikeys.accessScope.management': 'Management APIs', + 'apikeys.accessScope.management': 'Platform Management', 'apikeys.accessScope.inference': 'Inference APIs', - 'apikeys.access.permissions': 'Access Permissions' + 'apikeys.access.permissions': 'Access Permissions', + 'apikeys.type.auto': 'Auto-generated', + 'apikeys.type.custom': 'Custom' }; diff --git a/src/locales/ja-JP/apikeys.ts b/src/locales/ja-JP/apikeys.ts index 76aa923b..6fd244c7 100644 --- a/src/locales/ja-JP/apikeys.ts +++ b/src/locales/ja-JP/apikeys.ts @@ -19,9 +19,11 @@ export default { 'apikeys.models.selected': 'Allowed models', 'apikeys.models.noModelsFound': 'No models found', 'apikeys.accessScope.all': 'All', - 'apikeys.accessScope.management': 'Management APIs', + 'apikeys.accessScope.management': 'Platform Management', 'apikeys.accessScope.inference': 'Inference APIs', - 'apikeys.access.permissions': 'Access Permissions' + 'apikeys.access.permissions': 'Access Permissions', + 'apikeys.type.auto': 'Auto-generated', + 'apikeys.type.custom': 'Custom' }; // ========== To-Do: Translate Keys (Remove After Translation) ========== diff --git a/src/locales/ru-RU/apikeys.ts b/src/locales/ru-RU/apikeys.ts index dcfb78c5..4c829bc5 100644 --- a/src/locales/ru-RU/apikeys.ts +++ b/src/locales/ru-RU/apikeys.ts @@ -19,9 +19,11 @@ export default { 'apikeys.models.selected': 'Разрешенные модели', 'apikeys.models.noModelsFound': 'Модели не найдены', 'apikeys.accessScope.all': 'All', - 'apikeys.accessScope.management': 'Management APIs', + 'apikeys.accessScope.management': 'Platform Management', 'apikeys.accessScope.inference': 'Inference APIs', - 'apikeys.access.permissions': 'Access Permissions' + 'apikeys.access.permissions': 'Access Permissions', + 'apikeys.type.auto': 'Auto-generated', + 'apikeys.type.custom': 'Custom' }; // ========== To-Do: Translate Keys (Remove After Translation) ========== diff --git a/src/locales/tr-TR/apikeys.ts b/src/locales/tr-TR/apikeys.ts index fcdad199..30499244 100644 --- a/src/locales/tr-TR/apikeys.ts +++ b/src/locales/tr-TR/apikeys.ts @@ -19,7 +19,9 @@ export default { 'apikeys.models.selected': 'İzin verilen modeller', 'apikeys.models.noModelsFound': 'Model bulunamadı', 'apikeys.accessScope.all': 'All', - 'apikeys.accessScope.management': 'Management APIs', + 'apikeys.accessScope.management': 'Platform Management', 'apikeys.accessScope.inference': 'Inference APIs', - 'apikeys.access.permissions': 'Access Permissions' + 'apikeys.access.permissions': 'Access Permissions', + 'apikeys.type.auto': 'Auto-generated', + 'apikeys.type.custom': 'Custom' }; diff --git a/src/locales/zh-CN/apikeys.ts b/src/locales/zh-CN/apikeys.ts index 20ed9fee..4d52fd1a 100644 --- a/src/locales/zh-CN/apikeys.ts +++ b/src/locales/zh-CN/apikeys.ts @@ -18,7 +18,9 @@ export default { 'apikeys.models.selected': '指定模型', 'apikeys.models.noModelsFound': '未找到模型', 'apikeys.accessScope.all': '全部', - 'apikeys.accessScope.management': '管理接口', + 'apikeys.accessScope.management': '平台管理', 'apikeys.accessScope.inference': '推理接口', - 'apikeys.access.permissions': '访问权限' + 'apikeys.access.permissions': '访问权限', + 'apikeys.type.auto': '自动生成', + 'apikeys.type.custom': '自定义' }; diff --git a/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx b/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx index 3323c574..f04aca3b 100644 --- a/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx +++ b/src/pages/api-keys/components/add-apikey-modal/allow-models.tsx @@ -32,13 +32,12 @@ const AllowModelsForm: React.FC<{ const [modelList, setModelList] = useState<{ key: string; title: string }[]>( [] ); - const [queryParams, setQueryParams] = useState({ - page: -1 - }); const getModelList = async () => { try { - const res = await queryMyModels(queryParams); + const res = await queryMyModels({ + page: -1 + }); const options = res.items.map((item) => item.name); if (action === PageAction.EDIT && currentData) { const list = new Set([ @@ -57,6 +56,11 @@ const AllowModelsForm: React.FC<{ const handleAllowTypeChange = (e: any) => { const value = e.target.value; onValuesChange?.({ allowed_type: value }, form.getFieldsValue()); + if (value === 'management') { + form.setFieldsValue({ scope: ['management'] }); + } else { + form.setFieldsValue({ scope: ['inference'] }); + } }; useEffect(() => { @@ -66,7 +70,7 @@ const AllowModelsForm: React.FC<{ return (
- + - {action === PageAction.CREATE && ( - name="custom"> - - - )} - - name="scope" - normalize={(value) => (value ? [value] : [])} - getValueProps={(value) => ({ - value: Array.isArray(value) ? value[0] : value - })} - > - - + name="expires_in" rules={[ @@ -102,6 +71,63 @@ const APIKeyForm: React.FC<{ label={intl.formatMessage({ id: 'common.table.description' })} > + {action === PageAction.CREATE && ( + <> + name="key_type" initialValue="auto"> + + + {keyType === 'custom' && ( + + name="custom" + rules={[ + { + required: true, + message: intl.formatMessage( + { id: 'common.form.rule.input' }, + { + name: intl.formatMessage({ + id: 'apikeys.table.key' + }) + } + ) + } + ]} + > + + + )} + + )} + + name="scope" + hidden + normalize={(value) => (value ? [value] : [])} + getValueProps={(value) => ({ + value: Array.isArray(value) ? value[0] : value + })} + > + + = ({ const handleOnOk = async (formdata: FormData) => { try { - console.log('formdata=========', formdata); setLoading(true); const data = { ..._.omit(formdata, ['allowed_type']), allowed_model_names: - formdata.allowed_type === 'all' + formdata.allowed_type === 'all' || + formdata.allowed_type === 'management' ? [] : formdata.allowed_model_names || [] }; @@ -183,9 +183,12 @@ const AddModal: React.FC = ({ form.setFieldsValue({ name: currentData.name, description: currentData.description, + scope: currentData.scope, allowed_type: currentData.allowed_model_names?.length ? 'custom' - : 'all', + : currentData.scope?.includes('management') + ? 'management' + : 'all', expires_in: parseExpireValue(currentData as ListItem), allowed_model_names: currentData.allowed_model_names || [] }); @@ -269,7 +272,7 @@ const AddModal: React.FC = ({ onFinish={handleOnOk} preserve={false} initialValues={{ - scope: ['*'] + scope: ['inference'] }} > {!showKey && ( diff --git a/src/pages/api-keys/config/index.ts b/src/pages/api-keys/config/index.ts index 972ea8de..f45a66b3 100644 --- a/src/pages/api-keys/config/index.ts +++ b/src/pages/api-keys/config/index.ts @@ -27,18 +27,13 @@ export const expirationOptions = [ export const accessScopeOptions = [ { - label: 'apikeys.accessScope.all', - value: '*', - locale: true - }, - { - label: 'apikeys.accessScope.management', + label: 'management', value: 'management', description: 'v2/', locale: true }, { - label: 'apikeys.accessScope.inference', + label: 'inference', value: 'inference', description: 'v1/', locale: true diff --git a/src/pages/api-keys/config/types.ts b/src/pages/api-keys/config/types.ts index 1a4a49d5..c4dabe5d 100644 --- a/src/pages/api-keys/config/types.ts +++ b/src/pages/api-keys/config/types.ts @@ -13,7 +13,8 @@ export interface ListItem { export interface FormData { name: string; - allowed_type: 'all' | 'custom'; + allowed_type: 'all' | 'custom' | 'management'; + key_type: 'auto' | 'custom'; description: string; allowed_model_names: string[]; expires_in: number | null; diff --git a/src/pages/api-keys/hooks/use-keys-columns.tsx b/src/pages/api-keys/hooks/use-keys-columns.tsx index dc652d6f..bd4b5abd 100644 --- a/src/pages/api-keys/hooks/use-keys-columns.tsx +++ b/src/pages/api-keys/hooks/use-keys-columns.tsx @@ -110,27 +110,13 @@ const useModelsColumns = ({ showTitle: false }, render: (text: string[], record: ListItem) => ( -
- APIs: - {renderAPIs(record)} - - {intl.formatMessage({ id: 'models.title' })}: - - - - {text?.length - ? text?.join(', ') - : intl.formatMessage({ id: 'common.select.option' })} - - -
+ + {record.scope?.[0] === 'management' + ? intl.formatMessage({ id: 'apikeys.accessScope.management' }) + : record.allowed_model_names?.length + ? record.allowed_model_names.join(', ') + : intl.formatMessage({ id: 'apikeys.models.all' })} + ) }, {