fix(initialization): fall back to stored apiKey when test-connecting an existing model
Direct regression from the previous credential subresource refactor: the edit-mode ModelEditorDialog stopped binding apiKey into formData (the field now lives in <CredentialResource>), so "Test connection" sent apiKey="" and every upstream call (DeepSeek / lkeap / OpenAI etc.) 401'd. Fix in the backend so the frontend stays simple: - ModelTestRequest gains an optional ModelID field. - New fillSecretsFromStoredModel helper: when ModelID is set AND a secret field on the request is empty, copy it from the stored (decrypted) model. Non-empty request values still win, so users typing a new key to verify it before saving behave the same as before. - The four test entrypoints (chat / embedding / rerank / asr) call the helper right after ShouldBindJSON. Frontend: ModelEditorDialog.testConnection forwards modelId when isEdit is true. The four API client signatures accept the optional field. WebSearch and MCP are unaffected: WebSearch already has a TestProviderByID ID-based path, MCP has no standalone raw test endpoint.
This commit is contained in:
@@ -284,6 +284,9 @@ export function checkRemoteModel(modelConfig: {
|
||||
baseUrl: string;
|
||||
apiKey?: string;
|
||||
provider?: string;
|
||||
// 编辑已存在模型时传 modelId,后端会自动从存储中带出 apiKey
|
||||
// (前端不再回显明文密钥,所以测试连接必须用这个回填路径)
|
||||
modelId?: string;
|
||||
} & BaseModelTestPayload): Promise<{
|
||||
available: boolean;
|
||||
message?: string;
|
||||
@@ -308,6 +311,7 @@ export function testEmbeddingModel(modelConfig: {
|
||||
apiKey?: string;
|
||||
dimension?: number;
|
||||
provider?: string;
|
||||
modelId?: string;
|
||||
} & BaseModelTestPayload): Promise<{ available: boolean; message?: string; dimension?: number }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
post('/api/v1/initialization/embedding/test', modelConfig)
|
||||
@@ -327,6 +331,7 @@ export function checkRerankModel(modelConfig: {
|
||||
baseUrl: string;
|
||||
apiKey?: string;
|
||||
provider?: string;
|
||||
modelId?: string;
|
||||
} & BaseModelTestPayload): Promise<{
|
||||
available: boolean;
|
||||
message?: string;
|
||||
@@ -349,6 +354,7 @@ export function checkASRModel(modelConfig: {
|
||||
baseUrl: string;
|
||||
apiKey?: string;
|
||||
provider?: string;
|
||||
modelId?: string;
|
||||
} & BaseModelTestPayload): Promise<{
|
||||
available: boolean;
|
||||
message?: string;
|
||||
|
||||
@@ -951,6 +951,13 @@ const checkRemoteAPI = async () => {
|
||||
: {}
|
||||
|
||||
// 根据模型类型调用不同的校验接口
|
||||
// 编辑模式下 apiKey 由 <CredentialResource> 独立管理、不在 formData 里。
|
||||
// 把 modelId 透传给后端,让它在 apiKey 为空时自动用存储的解密值兜底,
|
||||
// 避免出现"测试连接没带 apiKey 直接失败"的情况。
|
||||
const idPayload = isEdit.value && props.modelData?.id
|
||||
? { modelId: props.modelData.id as string }
|
||||
: {}
|
||||
|
||||
switch (props.modelType) {
|
||||
case 'chat':
|
||||
// 对话模型(KnowledgeQA)
|
||||
@@ -959,6 +966,7 @@ const checkRemoteAPI = async () => {
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || '',
|
||||
provider: formData.value.provider,
|
||||
...idPayload,
|
||||
...headerPayload,
|
||||
})
|
||||
break
|
||||
@@ -972,6 +980,7 @@ const checkRemoteAPI = async () => {
|
||||
apiKey: formData.value.apiKey || '',
|
||||
dimension: formData.value.dimension,
|
||||
provider: formData.value.provider,
|
||||
...idPayload,
|
||||
...headerPayload,
|
||||
})
|
||||
// 如果测试成功且返回了维度,自动填充
|
||||
@@ -988,6 +997,7 @@ const checkRemoteAPI = async () => {
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || '',
|
||||
provider: formData.value.provider,
|
||||
...idPayload,
|
||||
...headerPayload,
|
||||
})
|
||||
break
|
||||
@@ -1000,6 +1010,7 @@ const checkRemoteAPI = async () => {
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || '',
|
||||
provider: formData.value.provider,
|
||||
...idPayload,
|
||||
...headerPayload,
|
||||
})
|
||||
break
|
||||
@@ -1011,6 +1022,7 @@ const checkRemoteAPI = async () => {
|
||||
baseUrl: formData.value.baseUrl,
|
||||
apiKey: formData.value.apiKey || '',
|
||||
provider: formData.value.provider,
|
||||
...idPayload,
|
||||
...headerPayload,
|
||||
})
|
||||
break
|
||||
|
||||
@@ -658,7 +658,7 @@ const stepTitles = computed(() => [
|
||||
t('datasource.prereqMemberBrief')) }}</div>
|
||||
<div class="ds-prereq-item-desc">{{ t(`datasource.prereqStep3Desc_${form.type}`,
|
||||
t('datasource.prereqMemberDesc'))
|
||||
}}</div>
|
||||
}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<a :href="currentDef.permissionPageUrl" target="_blank" rel="noopener" class="doc-link ds-prereq-link">
|
||||
|
||||
Reference in New Issue
Block a user