fix: refresh upstream catalog facts without invalidating saved credentials
This commit is contained in:
@@ -120,12 +120,16 @@ export class ModelCatalog {
|
||||
if (value.binding && !owner) throw fail('原凭据来源已变化,请核对源连接。', 409);
|
||||
const ids = [], added = [], existing = [];
|
||||
for (const model of selected) {
|
||||
// A catalog refresh never overwrites a user's edited parameters or
|
||||
// capability declarations. Existing members remain explicit conflicts.
|
||||
// Refresh upstream facts separately from user settings. Changing the
|
||||
// credential-bound connection revision would invalidate its saved key;
|
||||
// frozen runs already retain their original upstreamModel object.
|
||||
const prior = owner && hub.state.connections.find(connection => connection.model === model.id && credentialScope(connection) === credentialScope(value.connection)
|
||||
&& (connection.id === owner?.id || connection.credentialSource?.connectionId === owner?.id));
|
||||
if (prior) { ids.push(prior.id); existing.push(prior.id); continue; }
|
||||
const upstreamModel = { ...model, fetchedAt: value.preview.fetchedAt, endpoint: value.connection.baseUrl };
|
||||
const upstreamModel = structuredClone({ ...model, fetchedAt: value.preview.fetchedAt, endpoint: value.connection.baseUrl });
|
||||
if (prior) {
|
||||
prior.upstreamModel = upstreamModel;
|
||||
hub.save(); ids.push(prior.id); existing.push(prior.id); continue;
|
||||
}
|
||||
const profile = hub.upsert({ name: value.connection.name + ' · ' + model.id, model: model.id,
|
||||
protocol: value.connection.protocol, baseUrl: value.connection.baseUrl, brand: value.connection.brand, messagesAuth: value.connection.messagesAuth,
|
||||
requiresKey: value.connection.requiresKey, concurrency: value.connection.concurrency, parameterProfile: value.connection.parameterProfile ?? 'auto',
|
||||
|
||||
Reference in New Issue
Block a user