feat(provider): support additive provider key lifecycle management

Add `addToLive` parameter to add_provider so callers can opt out of
writing to the live config (e.g. when duplicating an inactive provider).
Add `originalId` parameter to update_provider to support provider key
renames — the old key is removed from live config before the new one
is written.

Frontend: ProviderForm now exposes provider-key input for openclaw app
type, and EditProviderDialog forwards originalId on save. Deep-link
import passes addToLive=true to preserve existing behavior.
This commit is contained in:
YoVinchen
2026-03-28 01:49:07 +08:00
parent eaf83f4fbe
commit e9ead2841d
13 changed files with 282 additions and 53 deletions
+13 -5
View File
@@ -533,8 +533,14 @@ function App() {
}
};
const handleEditProvider = async (provider: Provider) => {
await updateProvider(provider);
const handleEditProvider = async ({
provider,
originalId,
}: {
provider: Provider;
originalId?: string;
}) => {
await updateProvider(provider, originalId);
setEditingProvider(null);
};
@@ -571,7 +577,7 @@ function App() {
setConfirmAction(null);
};
const generateUniqueOpencodeKey = (
const generateUniqueProviderCopyKey = (
originalKey: string,
existingKeys: string[],
): string => {
@@ -594,6 +600,7 @@ function App() {
const duplicatedProvider: Omit<Provider, "id" | "createdAt"> & {
providerKey?: string;
addToLive?: boolean;
} = {
name: `${provider.name} copy`,
settingsConfig: JSON.parse(JSON.stringify(provider.settingsConfig)), // 深拷贝
@@ -607,12 +614,13 @@ function App() {
iconColor: provider.iconColor,
};
if (activeApp === "opencode") {
if (activeApp === "opencode" || activeApp === "openclaw") {
const existingKeys = Object.keys(providers);
duplicatedProvider.providerKey = generateUniqueOpencodeKey(
duplicatedProvider.providerKey = generateUniqueProviderCopyKey(
provider.id,
existingKeys,
);
duplicatedProvider.addToLive = false;
}
if (provider.sortIndex !== undefined) {