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;
|
||||
|
||||
Reference in New Issue
Block a user