fix(credentials): save resident keys without replacing live credentials
This commit is contained in:
@@ -50,7 +50,7 @@ export class CredentialVault {
|
||||
}
|
||||
view(hub) { return { supported: process.platform === 'win32', storage: 'windows-user-dpapi', revision: this.state.revision, unavailable: this.blocked,
|
||||
connections: hub.connections().map(connection => ({ id: connection.id, name: connection.name, revision: connection.revision, ...this.status(connection) })),
|
||||
scope: '仅处理用户明确新填或确认导入的凭据;不会提取原内存连接。密文与连接登记在同一SQLite事务提交。' }; }
|
||||
scope: '处理新填、确认导入或明确选择保存的当前连接凭据;当前 Key 在工作台内部加密,不回传给调用方。密文与连接登记在同一SQLite事务提交。' }; }
|
||||
prepare(connection, explicitKey, credentialRevision) {
|
||||
if (this.blocked) throw credentialError('原保存登记无法核对;请保留原数据并修复登记后保存。');
|
||||
if (typeof explicitKey !== 'string' || !explicitKey.trim() || explicitKey.length > 16000) throw credentialError('加密保存需要重新填写API Key。', 'CREDENTIAL_INPUT_REQUIRED', 400);
|
||||
|
||||
@@ -176,7 +176,14 @@ export class ModelHub {
|
||||
if (input.revision !== connection.revision) throw error('模型连接已修改,请刷新凭据保存页面。', 409);
|
||||
return this.editRegistry(() => {
|
||||
const vault = this.vault(), previous = vault.state.entries[connection.id];
|
||||
if (input.action === 'save') {
|
||||
if (input.action === 'save-current') {
|
||||
const resident = this.credential(connection);
|
||||
if (!resident?.key) throw error('当前连接没有可保存的 Key,请先在模型连接中填写。');
|
||||
// This explicit user action stays inside the provider. Preserve the
|
||||
// resident object and revision so frozen requests and cache affinity
|
||||
// do not change; no credential is sent back to the caller.
|
||||
vault.stage(connection.id, vault.prepare(connection, resident.key, resident.revision ?? 1));
|
||||
} else if (input.action === 'save') {
|
||||
const revision = (this.credential(connection)?.revision ?? 0) + 1, record = vault.prepare(connection, input.apiKey, revision);
|
||||
if (connection.id === legacyId) { this.provider.setKey(input.apiKey); this.provider.legacyCredentialRevision = revision; }
|
||||
else this.provider.credentials.set(connection.id, { key: input.apiKey.trim(), revision });
|
||||
|
||||
Reference in New Issue
Block a user