fix: refresh upstream catalog facts without invalidating saved credentials

This commit is contained in:
Agent Workbench Dev
2026-11-06 20:23:47 +08:00
parent 6917603d21
commit ae5123c569
3 changed files with 108 additions and 7 deletions
+8 -4
View File
@@ -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',
+3 -3
View File
@@ -37,10 +37,10 @@ export function catalogModel(item, config = {}) {
const efforts = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'].filter(value => supported(caps.effort?.[value]) === 'supported');
const modes = ['disabled', 'enabled', 'adaptive'].filter(value => supported(caps.thinking?.types?.[value]) === 'supported');
const features = Object.fromEntries(['thinking', 'effort', 'pdf_input', 'structured_outputs', 'server_tools', 'code_execution', 'batch', 'citations', 'context_management'].map(key => [key, supported(caps[key])]));
return { id, name: field(item.display_name ?? item.name ?? id), owner: field(item.owned_by ?? item.provider, 100),
return { id, name: field(item.display_name ?? item.displayName ?? item.name ?? id), owner: field(item.owned_by ?? item.provider, 100),
lifecycle: ['active', 'deprecated', 'retired'].includes(item.lifecycle) ? item.lifecycle : null,
contextLimit: positive(item.context_length ?? item.max_input_tokens ?? item.context_window),
maxOutputTokens: positive(item.max_output_tokens ?? item.max_tokens ?? item.top_provider?.max_completion_tokens),
contextLimit: positive(item.context_length ?? item.max_input_tokens ?? item.context_window ?? item.inputTokenLimit),
maxOutputTokens: positive(item.max_output_tokens ?? item.max_tokens ?? item.top_provider?.max_completion_tokens ?? item.outputTokenLimit),
capabilityDeclarations: declarations, features, efforts, modes, parameters,
metadataSource: 'upstream-model-list' };
}