feat(gui): Duplicate existing model instances (#32)

(fixes Allow Instance Duplication
Fixes #32)
This commit is contained in:
2026-07-20 11:41:28 +05:30
parent a8b2d425a1
commit 264a5ea0fe
9 changed files with 222 additions and 123 deletions

View File

@@ -62,6 +62,50 @@ export class ProviderManager {
};
}
static duplicate(id: string): ModelProviderInstance | null {
const db = getDb();
const source = db
.prepare("SELECT * FROM provider_instances WHERE id = ?")
.get(id) as DbRow | undefined;
if (!source) return null;
const newId = "provider-" + Date.now();
const newName = `${source.name} (Copy)`;
const activeCount = db
.prepare(
"SELECT COUNT(*) as count FROM provider_instances WHERE isActive = 1 AND type = ?",
)
.get(source.type) as { count: number };
const isActive = activeCount.count === 0 ? 1 : 0;
db.prepare(
`INSERT INTO provider_instances (id, name, providerName, apiKey, isActive, modelName, type, maxContext, endpointUrl)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
).run(
newId,
newName,
source.providerName,
source.apiKey,
isActive,
source.modelName,
source.type,
source.maxContext,
source.endpointUrl,
);
return {
id: newId,
name: newName,
providerName: source.providerName,
apiKey: source.apiKey,
isActive: isActive === 1,
modelName: source.modelName || undefined,
type: source.type as "generative" | "embedding",
maxContext: source.maxContext,
endpointUrl: source.endpointUrl || undefined,
};
}
static delete(id: string): void {
const db = getDb();
const provider = db